Description for this pull request:
- Improve write performance with dirsync mount option. - Improve lookup performance. - Add support for FITRIM ioctl. - Fix a bug with discard option. -----BEGIN PGP SIGNATURE----- iQJMBAABCgA2FiEE6NzKS6Uv/XAAGHgyZwv7A1FEIQgFAmCIADwYHG5hbWphZS5q ZW9uQHNhbXN1bmcuY29tAAoJEGcL+wNRRCEIalwP/jepL2Y7B8FOhMH1R4whbY6x 5fFlG608tR7jxUEMpAfMTcFC2+5nKpHN1keoHV8SXdJz2esd1ZUknaok5CIVQFYX I7TTOWn/genJ6nVmHeTLZLAxAWznSlIqRdeuSnDMLMKSLDn7noW5l+vzgYy5dnaF SzICtNXJqA7D7PcMIwTtfszcSEwmt1aLiRZZabZ+y0xSF2ha0mRB6B3hCx9sDXh5 iVVbSn10lk6ULENYcjaUZhF1Dt9Lv4pOZ9drr8bVfRmWBeWspB/X4/TgO+Mf/xP8 5el7OL965ofUaaCmhyfDMrWCBffeFbf0K8sUM/psiAUuKTugKvlZniZ0RB8zLEvZ Bn2yvr+walpdkVNBbv3qi32/4xAx5ng90rSdqX3bvY3Zq1UDW49MIIZOh6uQCNnD 9ravgGoU2ujVcUQUKEU01dj1ora83IKQ7WuxcGXQOt/xNFMRG1FmiKgS7aj2HgMM ax9pjZZY4H8ZUZOC2hpph+x6Kc+ZQDqzR6+0qbWM2/hlLgIURDXTqVe3m1DCuvDI c2rvtpVtpYGz+HTZW+krUzc4kOAfUsS98D+7bLS5X/f4x4e5FxQDGyXaCNUI0OCr ed8kHmHQsKvbIui4RHgZvZylj2xO34arSuMURL41ifuT9jFoQVxPcGluXNvbdcu8 yOyqeaqwgh5AJzXPVsRv =igtQ -----END PGP SIGNATURE----- Merge tag 'exfat-for-5.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat Pull exfat updates from Namjae Jeon: - Improve write performance with dirsync mount option - Improve lookup performance - Add support for FITRIM ioctl - Fix a bug with discard option * tag 'exfat-for-5.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat: exfat: speed up iterate/lookup by fixing start point of traversing cluster chain exfat: improve write performance when dirsync enabled exfat: add support ioctl and FITRIM function exfat: introduce bitmap_lock for cluster bitmap access exfat: fix erroneous discard when clear cluster bit
This commit is contained in:
commit
8ae8932c6a
@ -141,11 +141,7 @@ void exfat_free_bitmap(struct exfat_sb_info *sbi)
|
|||||||
kfree(sbi->vol_amap);
|
kfree(sbi->vol_amap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
int exfat_set_bitmap(struct inode *inode, unsigned int clu, bool sync)
|
||||||
* If the value of "clu" is 0, it means cluster 2 which is the first cluster of
|
|
||||||
* the cluster heap.
|
|
||||||
*/
|
|
||||||
int exfat_set_bitmap(struct inode *inode, unsigned int clu)
|
|
||||||
{
|
{
|
||||||
int i, b;
|
int i, b;
|
||||||
unsigned int ent_idx;
|
unsigned int ent_idx;
|
||||||
@ -158,14 +154,10 @@ int exfat_set_bitmap(struct inode *inode, unsigned int clu)
|
|||||||
b = BITMAP_OFFSET_BIT_IN_SECTOR(sb, ent_idx);
|
b = BITMAP_OFFSET_BIT_IN_SECTOR(sb, ent_idx);
|
||||||
|
|
||||||
set_bit_le(b, sbi->vol_amap[i]->b_data);
|
set_bit_le(b, sbi->vol_amap[i]->b_data);
|
||||||
exfat_update_bh(sbi->vol_amap[i], IS_DIRSYNC(inode));
|
exfat_update_bh(sbi->vol_amap[i], sync);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* If the value of "clu" is 0, it means cluster 2 which is the first cluster of
|
|
||||||
* the cluster heap.
|
|
||||||
*/
|
|
||||||
void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
|
void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
|
||||||
{
|
{
|
||||||
int i, b;
|
int i, b;
|
||||||
@ -186,8 +178,7 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
|
|||||||
int ret_discard;
|
int ret_discard;
|
||||||
|
|
||||||
ret_discard = sb_issue_discard(sb,
|
ret_discard = sb_issue_discard(sb,
|
||||||
exfat_cluster_to_sector(sbi, clu +
|
exfat_cluster_to_sector(sbi, clu),
|
||||||
EXFAT_RESERVED_CLUSTERS),
|
|
||||||
(1 << sbi->sect_per_clus_bits), GFP_NOFS, 0);
|
(1 << sbi->sect_per_clus_bits), GFP_NOFS, 0);
|
||||||
|
|
||||||
if (ret_discard == -EOPNOTSUPP) {
|
if (ret_discard == -EOPNOTSUPP) {
|
||||||
@ -273,3 +264,83 @@ int exfat_count_used_clusters(struct super_block *sb, unsigned int *ret_count)
|
|||||||
*ret_count = count;
|
*ret_count = count;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int exfat_trim_fs(struct inode *inode, struct fstrim_range *range)
|
||||||
|
{
|
||||||
|
unsigned int trim_begin, trim_end, count, next_free_clu;
|
||||||
|
u64 clu_start, clu_end, trim_minlen, trimmed_total = 0;
|
||||||
|
struct super_block *sb = inode->i_sb;
|
||||||
|
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
clu_start = max_t(u64, range->start >> sbi->cluster_size_bits,
|
||||||
|
EXFAT_FIRST_CLUSTER);
|
||||||
|
clu_end = clu_start + (range->len >> sbi->cluster_size_bits) - 1;
|
||||||
|
trim_minlen = range->minlen >> sbi->cluster_size_bits;
|
||||||
|
|
||||||
|
if (clu_start >= sbi->num_clusters || range->len < sbi->cluster_size)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (clu_end >= sbi->num_clusters)
|
||||||
|
clu_end = sbi->num_clusters - 1;
|
||||||
|
|
||||||
|
mutex_lock(&sbi->bitmap_lock);
|
||||||
|
|
||||||
|
trim_begin = trim_end = exfat_find_free_bitmap(sb, clu_start);
|
||||||
|
if (trim_begin == EXFAT_EOF_CLUSTER)
|
||||||
|
goto unlock;
|
||||||
|
|
||||||
|
next_free_clu = exfat_find_free_bitmap(sb, trim_end + 1);
|
||||||
|
if (next_free_clu == EXFAT_EOF_CLUSTER)
|
||||||
|
goto unlock;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (next_free_clu == trim_end + 1) {
|
||||||
|
/* extend trim range for continuous free cluster */
|
||||||
|
trim_end++;
|
||||||
|
} else {
|
||||||
|
/* trim current range if it's larger than trim_minlen */
|
||||||
|
count = trim_end - trim_begin + 1;
|
||||||
|
if (count >= trim_minlen) {
|
||||||
|
err = sb_issue_discard(sb,
|
||||||
|
exfat_cluster_to_sector(sbi, trim_begin),
|
||||||
|
count * sbi->sect_per_clus, GFP_NOFS, 0);
|
||||||
|
if (err)
|
||||||
|
goto unlock;
|
||||||
|
|
||||||
|
trimmed_total += count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set next start point of the free hole */
|
||||||
|
trim_begin = trim_end = next_free_clu;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next_free_clu >= clu_end)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (fatal_signal_pending(current)) {
|
||||||
|
err = -ERESTARTSYS;
|
||||||
|
goto unlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
next_free_clu = exfat_find_free_bitmap(sb, next_free_clu + 1);
|
||||||
|
} while (next_free_clu != EXFAT_EOF_CLUSTER &&
|
||||||
|
next_free_clu > trim_end);
|
||||||
|
|
||||||
|
/* try to trim remainder */
|
||||||
|
count = trim_end - trim_begin + 1;
|
||||||
|
if (count >= trim_minlen) {
|
||||||
|
err = sb_issue_discard(sb, exfat_cluster_to_sector(sbi, trim_begin),
|
||||||
|
count * sbi->sect_per_clus, GFP_NOFS, 0);
|
||||||
|
if (err)
|
||||||
|
goto unlock;
|
||||||
|
|
||||||
|
trimmed_total += count;
|
||||||
|
}
|
||||||
|
|
||||||
|
unlock:
|
||||||
|
mutex_unlock(&sbi->bitmap_lock);
|
||||||
|
range->len = trimmed_total << sbi->cluster_size_bits;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
#include <linux/compat.h>
|
||||||
#include <linux/bio.h>
|
#include <linux/bio.h>
|
||||||
#include <linux/buffer_head.h>
|
#include <linux/buffer_head.h>
|
||||||
|
|
||||||
@ -146,7 +147,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
|
|||||||
0);
|
0);
|
||||||
|
|
||||||
*uni_name.name = 0x0;
|
*uni_name.name = 0x0;
|
||||||
exfat_get_uniname_from_ext_entry(sb, &dir, dentry,
|
exfat_get_uniname_from_ext_entry(sb, &clu, i,
|
||||||
uni_name.name);
|
uni_name.name);
|
||||||
exfat_utf16_to_nls(sb, &uni_name,
|
exfat_utf16_to_nls(sb, &uni_name,
|
||||||
dir_entry->namebuf.lfn,
|
dir_entry->namebuf.lfn,
|
||||||
@ -306,6 +307,10 @@ const struct file_operations exfat_dir_operations = {
|
|||||||
.llseek = generic_file_llseek,
|
.llseek = generic_file_llseek,
|
||||||
.read = generic_read_dir,
|
.read = generic_read_dir,
|
||||||
.iterate = exfat_iterate,
|
.iterate = exfat_iterate,
|
||||||
|
.unlocked_ioctl = exfat_ioctl,
|
||||||
|
#ifdef CONFIG_COMPAT
|
||||||
|
.compat_ioctl = exfat_compat_ioctl,
|
||||||
|
#endif
|
||||||
.fsync = exfat_file_fsync,
|
.fsync = exfat_file_fsync,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -315,7 +320,7 @@ int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu)
|
|||||||
|
|
||||||
exfat_chain_set(clu, EXFAT_EOF_CLUSTER, 0, ALLOC_NO_FAT_CHAIN);
|
exfat_chain_set(clu, EXFAT_EOF_CLUSTER, 0, ALLOC_NO_FAT_CHAIN);
|
||||||
|
|
||||||
ret = exfat_alloc_cluster(inode, 1, clu);
|
ret = exfat_alloc_cluster(inode, 1, clu, IS_DIRSYNC(inode));
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -906,14 +911,19 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return values:
|
* @ei: inode info of parent directory
|
||||||
* >= 0 : return dir entiry position with the name in dir
|
* @p_dir: directory structure of parent directory
|
||||||
* -ENOENT : entry with the name does not exist
|
* @num_entries:entry size of p_uniname
|
||||||
* -EIO : I/O error
|
* @hint_opt: If p_uniname is found, filled with optimized dir/entry
|
||||||
|
* for traversing cluster chain.
|
||||||
|
* @return:
|
||||||
|
* >= 0: file directory entry position where the name exists
|
||||||
|
* -ENOENT: entry with the name does not exist
|
||||||
|
* -EIO: I/O error
|
||||||
*/
|
*/
|
||||||
int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
|
int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
|
||||||
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
|
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
|
||||||
int num_entries, unsigned int type)
|
int num_entries, unsigned int type, struct exfat_hint *hint_opt)
|
||||||
{
|
{
|
||||||
int i, rewind = 0, dentry = 0, end_eidx = 0, num_ext = 0, len;
|
int i, rewind = 0, dentry = 0, end_eidx = 0, num_ext = 0, len;
|
||||||
int order, step, name_len = 0;
|
int order, step, name_len = 0;
|
||||||
@ -990,6 +1000,8 @@ rewind:
|
|||||||
|
|
||||||
if (entry_type == TYPE_FILE || entry_type == TYPE_DIR) {
|
if (entry_type == TYPE_FILE || entry_type == TYPE_DIR) {
|
||||||
step = DIRENT_STEP_FILE;
|
step = DIRENT_STEP_FILE;
|
||||||
|
hint_opt->clu = clu.dir;
|
||||||
|
hint_opt->eidx = i;
|
||||||
if (type == TYPE_ALL || type == entry_type) {
|
if (type == TYPE_ALL || type == entry_type) {
|
||||||
num_ext = ep->dentry.file.num_ext;
|
num_ext = ep->dentry.file.num_ext;
|
||||||
step = DIRENT_STEP_STRM;
|
step = DIRENT_STEP_STRM;
|
||||||
|
@ -238,6 +238,7 @@ struct exfat_sb_info {
|
|||||||
unsigned int used_clusters; /* number of used clusters */
|
unsigned int used_clusters; /* number of used clusters */
|
||||||
|
|
||||||
struct mutex s_lock; /* superblock lock */
|
struct mutex s_lock; /* superblock lock */
|
||||||
|
struct mutex bitmap_lock; /* bitmap lock */
|
||||||
struct exfat_mount_options options;
|
struct exfat_mount_options options;
|
||||||
struct nls_table *nls_io; /* Charset used for input and display */
|
struct nls_table *nls_io; /* Charset used for input and display */
|
||||||
struct ratelimit_state ratelimit;
|
struct ratelimit_state ratelimit;
|
||||||
@ -388,7 +389,7 @@ int exfat_clear_volume_dirty(struct super_block *sb);
|
|||||||
#define exfat_get_next_cluster(sb, pclu) exfat_ent_get(sb, *(pclu), pclu)
|
#define exfat_get_next_cluster(sb, pclu) exfat_ent_get(sb, *(pclu), pclu)
|
||||||
|
|
||||||
int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
||||||
struct exfat_chain *p_chain);
|
struct exfat_chain *p_chain, bool sync_bmap);
|
||||||
int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain);
|
int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain);
|
||||||
int exfat_ent_get(struct super_block *sb, unsigned int loc,
|
int exfat_ent_get(struct super_block *sb, unsigned int loc,
|
||||||
unsigned int *content);
|
unsigned int *content);
|
||||||
@ -407,10 +408,11 @@ int exfat_count_num_clusters(struct super_block *sb,
|
|||||||
/* balloc.c */
|
/* balloc.c */
|
||||||
int exfat_load_bitmap(struct super_block *sb);
|
int exfat_load_bitmap(struct super_block *sb);
|
||||||
void exfat_free_bitmap(struct exfat_sb_info *sbi);
|
void exfat_free_bitmap(struct exfat_sb_info *sbi);
|
||||||
int exfat_set_bitmap(struct inode *inode, unsigned int clu);
|
int exfat_set_bitmap(struct inode *inode, unsigned int clu, bool sync);
|
||||||
void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync);
|
void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync);
|
||||||
unsigned int exfat_find_free_bitmap(struct super_block *sb, unsigned int clu);
|
unsigned int exfat_find_free_bitmap(struct super_block *sb, unsigned int clu);
|
||||||
int exfat_count_used_clusters(struct super_block *sb, unsigned int *ret_count);
|
int exfat_count_used_clusters(struct super_block *sb, unsigned int *ret_count);
|
||||||
|
int exfat_trim_fs(struct inode *inode, struct fstrim_range *range);
|
||||||
|
|
||||||
/* file.c */
|
/* file.c */
|
||||||
extern const struct file_operations exfat_file_operations;
|
extern const struct file_operations exfat_file_operations;
|
||||||
@ -422,6 +424,9 @@ int exfat_getattr(struct user_namespace *mnt_userns, const struct path *path,
|
|||||||
struct kstat *stat, unsigned int request_mask,
|
struct kstat *stat, unsigned int request_mask,
|
||||||
unsigned int query_flags);
|
unsigned int query_flags);
|
||||||
int exfat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
|
int exfat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
|
||||||
|
long exfat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
|
||||||
|
long exfat_compat_ioctl(struct file *filp, unsigned int cmd,
|
||||||
|
unsigned long arg);
|
||||||
|
|
||||||
/* namei.c */
|
/* namei.c */
|
||||||
extern const struct dentry_operations exfat_dentry_ops;
|
extern const struct dentry_operations exfat_dentry_ops;
|
||||||
@ -452,7 +457,7 @@ void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es);
|
|||||||
int exfat_calc_num_entries(struct exfat_uni_name *p_uniname);
|
int exfat_calc_num_entries(struct exfat_uni_name *p_uniname);
|
||||||
int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
|
int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
|
||||||
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
|
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
|
||||||
int num_entries, unsigned int type);
|
int num_entries, unsigned int type, struct exfat_hint *hint_opt);
|
||||||
int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu);
|
int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu);
|
||||||
int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir,
|
int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir,
|
||||||
int entry, sector_t *sector, int *offset);
|
int entry, sector_t *sector, int *offset);
|
||||||
|
@ -151,13 +151,14 @@ int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
/* This function must be called with bitmap_lock held */
|
||||||
|
static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
||||||
{
|
{
|
||||||
unsigned int num_clusters = 0;
|
|
||||||
unsigned int clu;
|
|
||||||
struct super_block *sb = inode->i_sb;
|
struct super_block *sb = inode->i_sb;
|
||||||
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
||||||
int cur_cmap_i, next_cmap_i;
|
int cur_cmap_i, next_cmap_i;
|
||||||
|
unsigned int num_clusters = 0;
|
||||||
|
unsigned int clu;
|
||||||
|
|
||||||
/* invalid cluster number */
|
/* invalid cluster number */
|
||||||
if (p_chain->dir == EXFAT_FREE_CLUSTER ||
|
if (p_chain->dir == EXFAT_FREE_CLUSTER ||
|
||||||
@ -230,6 +231,17 @@ dec_used_clus:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
mutex_lock(&EXFAT_SB(inode->i_sb)->bitmap_lock);
|
||||||
|
ret = __exfat_free_cluster(inode, p_chain);
|
||||||
|
mutex_unlock(&EXFAT_SB(inode->i_sb)->bitmap_lock);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int exfat_find_last_cluster(struct super_block *sb, struct exfat_chain *p_chain,
|
int exfat_find_last_cluster(struct super_block *sb, struct exfat_chain *p_chain,
|
||||||
unsigned int *ret_clu)
|
unsigned int *ret_clu)
|
||||||
{
|
{
|
||||||
@ -308,7 +320,7 @@ release_bhs:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
||||||
struct exfat_chain *p_chain)
|
struct exfat_chain *p_chain, bool sync_bmap)
|
||||||
{
|
{
|
||||||
int ret = -ENOSPC;
|
int ret = -ENOSPC;
|
||||||
unsigned int num_clusters = 0, total_cnt;
|
unsigned int num_clusters = 0, total_cnt;
|
||||||
@ -328,6 +340,8 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||||||
if (num_alloc > total_cnt - sbi->used_clusters)
|
if (num_alloc > total_cnt - sbi->used_clusters)
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
|
|
||||||
|
mutex_lock(&sbi->bitmap_lock);
|
||||||
|
|
||||||
hint_clu = p_chain->dir;
|
hint_clu = p_chain->dir;
|
||||||
/* find new cluster */
|
/* find new cluster */
|
||||||
if (hint_clu == EXFAT_EOF_CLUSTER) {
|
if (hint_clu == EXFAT_EOF_CLUSTER) {
|
||||||
@ -338,8 +352,10 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
hint_clu = exfat_find_free_bitmap(sb, sbi->clu_srch_ptr);
|
hint_clu = exfat_find_free_bitmap(sb, sbi->clu_srch_ptr);
|
||||||
if (hint_clu == EXFAT_EOF_CLUSTER)
|
if (hint_clu == EXFAT_EOF_CLUSTER) {
|
||||||
return -ENOSPC;
|
ret = -ENOSPC;
|
||||||
|
goto unlock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check cluster validation */
|
/* check cluster validation */
|
||||||
@ -349,8 +365,10 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||||||
hint_clu = EXFAT_FIRST_CLUSTER;
|
hint_clu = EXFAT_FIRST_CLUSTER;
|
||||||
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
||||||
if (exfat_chain_cont_cluster(sb, p_chain->dir,
|
if (exfat_chain_cont_cluster(sb, p_chain->dir,
|
||||||
num_clusters))
|
num_clusters)) {
|
||||||
return -EIO;
|
ret = -EIO;
|
||||||
|
goto unlock;
|
||||||
|
}
|
||||||
p_chain->flags = ALLOC_FAT_CHAIN;
|
p_chain->flags = ALLOC_FAT_CHAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -370,7 +388,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* update allocation bitmap */
|
/* update allocation bitmap */
|
||||||
if (exfat_set_bitmap(inode, new_clu)) {
|
if (exfat_set_bitmap(inode, new_clu, sync_bmap)) {
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto free_cluster;
|
goto free_cluster;
|
||||||
}
|
}
|
||||||
@ -400,6 +418,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||||||
sbi->used_clusters += num_clusters;
|
sbi->used_clusters += num_clusters;
|
||||||
|
|
||||||
p_chain->size += num_clusters;
|
p_chain->size += num_clusters;
|
||||||
|
mutex_unlock(&sbi->bitmap_lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,7 +438,9 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||||||
}
|
}
|
||||||
free_cluster:
|
free_cluster:
|
||||||
if (num_clusters)
|
if (num_clusters)
|
||||||
exfat_free_cluster(inode, p_chain);
|
__exfat_free_cluster(inode, p_chain);
|
||||||
|
unlock:
|
||||||
|
mutex_unlock(&sbi->bitmap_lock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
#include <linux/compat.h>
|
||||||
#include <linux/cred.h>
|
#include <linux/cred.h>
|
||||||
#include <linux/buffer_head.h>
|
#include <linux/buffer_head.h>
|
||||||
#include <linux/blkdev.h>
|
#include <linux/blkdev.h>
|
||||||
@ -350,6 +351,54 @@ out:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int exfat_ioctl_fitrim(struct inode *inode, unsigned long arg)
|
||||||
|
{
|
||||||
|
struct request_queue *q = bdev_get_queue(inode->i_sb->s_bdev);
|
||||||
|
struct fstrim_range range;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
|
return -EPERM;
|
||||||
|
|
||||||
|
if (!blk_queue_discard(q))
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
|
if (copy_from_user(&range, (struct fstrim_range __user *)arg, sizeof(range)))
|
||||||
|
return -EFAULT;
|
||||||
|
|
||||||
|
range.minlen = max_t(unsigned int, range.minlen,
|
||||||
|
q->limits.discard_granularity);
|
||||||
|
|
||||||
|
ret = exfat_trim_fs(inode, &range);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (copy_to_user((struct fstrim_range __user *)arg, &range, sizeof(range)))
|
||||||
|
return -EFAULT;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
long exfat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
||||||
|
{
|
||||||
|
struct inode *inode = file_inode(filp);
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case FITRIM:
|
||||||
|
return exfat_ioctl_fitrim(inode, arg);
|
||||||
|
default:
|
||||||
|
return -ENOTTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_COMPAT
|
||||||
|
long exfat_compat_ioctl(struct file *filp, unsigned int cmd,
|
||||||
|
unsigned long arg)
|
||||||
|
{
|
||||||
|
return exfat_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
|
int exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
|
||||||
{
|
{
|
||||||
struct inode *inode = filp->f_mapping->host;
|
struct inode *inode = filp->f_mapping->host;
|
||||||
@ -370,6 +419,10 @@ const struct file_operations exfat_file_operations = {
|
|||||||
.llseek = generic_file_llseek,
|
.llseek = generic_file_llseek,
|
||||||
.read_iter = generic_file_read_iter,
|
.read_iter = generic_file_read_iter,
|
||||||
.write_iter = generic_file_write_iter,
|
.write_iter = generic_file_write_iter,
|
||||||
|
.unlocked_ioctl = exfat_ioctl,
|
||||||
|
#ifdef CONFIG_COMPAT
|
||||||
|
.compat_ioctl = exfat_compat_ioctl,
|
||||||
|
#endif
|
||||||
.mmap = generic_file_mmap,
|
.mmap = generic_file_mmap,
|
||||||
.fsync = exfat_file_fsync,
|
.fsync = exfat_file_fsync,
|
||||||
.splice_read = generic_file_splice_read,
|
.splice_read = generic_file_splice_read,
|
||||||
|
@ -179,7 +179,8 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
|
|||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = exfat_alloc_cluster(inode, num_to_be_allocated, &new_clu);
|
ret = exfat_alloc_cluster(inode, num_to_be_allocated, &new_clu,
|
||||||
|
inode_needs_sync(inode));
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ static int exfat_find_empty_entry(struct inode *inode,
|
|||||||
exfat_chain_set(&clu, last_clu + 1, 0, p_dir->flags);
|
exfat_chain_set(&clu, last_clu + 1, 0, p_dir->flags);
|
||||||
|
|
||||||
/* allocate a cluster */
|
/* allocate a cluster */
|
||||||
ret = exfat_alloc_cluster(inode, 1, &clu);
|
ret = exfat_alloc_cluster(inode, 1, &clu, IS_DIRSYNC(inode));
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -596,6 +596,8 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
|
|||||||
struct exfat_inode_info *ei = EXFAT_I(dir);
|
struct exfat_inode_info *ei = EXFAT_I(dir);
|
||||||
struct exfat_dentry *ep, *ep2;
|
struct exfat_dentry *ep, *ep2;
|
||||||
struct exfat_entry_set_cache *es;
|
struct exfat_entry_set_cache *es;
|
||||||
|
/* for optimized dir & entry to prevent long traverse of cluster chain */
|
||||||
|
struct exfat_hint hint_opt;
|
||||||
|
|
||||||
if (qname->len == 0)
|
if (qname->len == 0)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
@ -619,7 +621,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
|
|||||||
|
|
||||||
/* search the file name for directories */
|
/* search the file name for directories */
|
||||||
dentry = exfat_find_dir_entry(sb, ei, &cdir, &uni_name,
|
dentry = exfat_find_dir_entry(sb, ei, &cdir, &uni_name,
|
||||||
num_entries, TYPE_ALL);
|
num_entries, TYPE_ALL, &hint_opt);
|
||||||
|
|
||||||
if (dentry < 0)
|
if (dentry < 0)
|
||||||
return dentry; /* -error value */
|
return dentry; /* -error value */
|
||||||
@ -628,6 +630,11 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
|
|||||||
info->entry = dentry;
|
info->entry = dentry;
|
||||||
info->num_subdirs = 0;
|
info->num_subdirs = 0;
|
||||||
|
|
||||||
|
/* adjust cdir to the optimized value */
|
||||||
|
cdir.dir = hint_opt.clu;
|
||||||
|
if (cdir.flags & ALLOC_NO_FAT_CHAIN)
|
||||||
|
cdir.size -= dentry / sbi->dentries_per_clu;
|
||||||
|
dentry = hint_opt.eidx;
|
||||||
es = exfat_get_dentry_set(sb, &cdir, dentry, ES_2_ENTRIES);
|
es = exfat_get_dentry_set(sb, &cdir, dentry, ES_2_ENTRIES);
|
||||||
if (!es)
|
if (!es)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -752,6 +752,7 @@ static int exfat_init_fs_context(struct fs_context *fc)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
mutex_init(&sbi->s_lock);
|
mutex_init(&sbi->s_lock);
|
||||||
|
mutex_init(&sbi->bitmap_lock);
|
||||||
ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
|
ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
|
||||||
DEFAULT_RATELIMIT_BURST);
|
DEFAULT_RATELIMIT_BURST);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user