Skip to content

Commit ff419b6

Browse files
committed
Merge tag 'exfat-for-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat
Pull exfat updates from Namjae Jeon: - don't clear MediaFailure and VolumeDirty bit in volume flags if these were already set before mounting - write multiple dirty buffers at once in sync mode - remove unneeded EXFAT_SB_DIRTY bit set * tag 'exfat-for-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat: exfat: retain 'VolumeFlags' properly exfat: optimize exfat_zeroed_cluster() exfat: add error check when updating dir-entries exfat: write multiple sectors at once exfat: remove EXFAT_SB_DIRTY flag
2 parents 9f45717 + 7018ec6 commit ff419b6

File tree

10 files changed

+121
-116
lines changed

10 files changed

+121
-116
lines changed

fs/exfat/balloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int exfat_set_bitmap(struct inode *inode, unsigned int clu)
158158
b = BITMAP_OFFSET_BIT_IN_SECTOR(sb, ent_idx);
159159

160160
set_bit_le(b, sbi->vol_amap[i]->b_data);
161-
exfat_update_bh(sb, sbi->vol_amap[i], IS_DIRSYNC(inode));
161+
exfat_update_bh(sbi->vol_amap[i], IS_DIRSYNC(inode));
162162
return 0;
163163
}
164164

@@ -180,7 +180,7 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu)
180180
b = BITMAP_OFFSET_BIT_IN_SECTOR(sb, ent_idx);
181181

182182
clear_bit_le(b, sbi->vol_amap[i]->b_data);
183-
exfat_update_bh(sb, sbi->vol_amap[i], IS_DIRSYNC(inode));
183+
exfat_update_bh(sbi->vol_amap[i], IS_DIRSYNC(inode));
184184

185185
if (opts->discard) {
186186
int ret_discard;

fs/exfat/dir.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir,
470470
&ep->dentry.file.access_date,
471471
NULL);
472472

473-
exfat_update_bh(sb, bh, IS_DIRSYNC(inode));
473+
exfat_update_bh(bh, IS_DIRSYNC(inode));
474474
brelse(bh);
475475

476476
ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh, &sector);
@@ -480,7 +480,7 @@ int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir,
480480
exfat_init_stream_entry(ep,
481481
(type == TYPE_FILE) ? ALLOC_FAT_CHAIN : ALLOC_NO_FAT_CHAIN,
482482
start_clu, size);
483-
exfat_update_bh(sb, bh, IS_DIRSYNC(inode));
483+
exfat_update_bh(bh, IS_DIRSYNC(inode));
484484
brelse(bh);
485485

486486
return 0;
@@ -516,7 +516,7 @@ int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir,
516516
}
517517

518518
fep->dentry.file.checksum = cpu_to_le16(chksum);
519-
exfat_update_bh(sb, fbh, IS_DIRSYNC(inode));
519+
exfat_update_bh(fbh, IS_DIRSYNC(inode));
520520
release_fbh:
521521
brelse(fbh);
522522
return ret;
@@ -538,7 +538,7 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir,
538538
return -EIO;
539539

540540
ep->dentry.file.num_ext = (unsigned char)(num_entries - 1);
541-
exfat_update_bh(sb, bh, sync);
541+
exfat_update_bh(bh, sync);
542542
brelse(bh);
543543

544544
ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh, &sector);
@@ -547,7 +547,7 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir,
547547

548548
ep->dentry.stream.name_len = p_uniname->name_len;
549549
ep->dentry.stream.name_hash = cpu_to_le16(p_uniname->name_hash);
550-
exfat_update_bh(sb, bh, sync);
550+
exfat_update_bh(bh, sync);
551551
brelse(bh);
552552

553553
for (i = EXFAT_FIRST_CLUSTER; i < num_entries; i++) {
@@ -556,7 +556,7 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir,
556556
return -EIO;
557557

558558
exfat_init_name_entry(ep, uniname);
559-
exfat_update_bh(sb, bh, sync);
559+
exfat_update_bh(bh, sync);
560560
brelse(bh);
561561
uniname += EXFAT_FILE_NAME_LEN;
562562
}
@@ -580,7 +580,7 @@ int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir,
580580
return -EIO;
581581

582582
exfat_set_entry_type(ep, TYPE_DELETED);
583-
exfat_update_bh(sb, bh, IS_DIRSYNC(inode));
583+
exfat_update_bh(bh, IS_DIRSYNC(inode));
584584
brelse(bh);
585585
}
586586

@@ -604,16 +604,20 @@ void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es)
604604
es->modified = true;
605605
}
606606

607-
void exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
607+
int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
608608
{
609-
int i;
609+
int i, err = 0;
610610

611-
for (i = 0; i < es->num_bh; i++) {
612-
if (es->modified)
613-
exfat_update_bh(es->sb, es->bh[i], sync);
614-
brelse(es->bh[i]);
615-
}
611+
if (es->modified)
612+
err = exfat_update_bhs(es->bh, es->num_bh, sync);
613+
614+
for (i = 0; i < es->num_bh; i++)
615+
if (err)
616+
bforget(es->bh[i]);
617+
else
618+
brelse(es->bh[i]);
616619
kfree(es);
620+
return err;
617621
}
618622

619623
static int exfat_walk_fat_chain(struct super_block *sb,

fs/exfat/exfat_fs.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#define EXFAT_SUPER_MAGIC 0x2011BAB0UL
1414
#define EXFAT_ROOT_INO 1
1515

16-
#define EXFAT_SB_DIRTY 0
17-
1816
#define EXFAT_CLUSTERS_UNTRACKED (~0u)
1917

2018
/*
@@ -226,7 +224,8 @@ struct exfat_sb_info {
226224
unsigned int num_FAT_sectors; /* num of FAT sectors */
227225
unsigned int root_dir; /* root dir cluster */
228226
unsigned int dentries_per_clu; /* num of dentries per cluster */
229-
unsigned int vol_flag; /* volume dirty flag */
227+
unsigned int vol_flags; /* volume flags */
228+
unsigned int vol_flags_persistent; /* volume flags to retain */
230229
struct buffer_head *boot_bh; /* buffer_head of BOOT sector */
231230

232231
unsigned int map_clu; /* allocation bitmap start cluster */
@@ -238,7 +237,6 @@ struct exfat_sb_info {
238237
unsigned int clu_srch_ptr; /* cluster search pointer */
239238
unsigned int used_clusters; /* number of used clusters */
240239

241-
unsigned long s_state;
242240
struct mutex s_lock; /* superblock lock */
243241
struct exfat_mount_options options;
244242
struct nls_table *nls_io; /* Charset used for input and display */
@@ -383,7 +381,8 @@ static inline int exfat_sector_to_cluster(struct exfat_sb_info *sbi,
383381
}
384382

385383
/* super.c */
386-
int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flag);
384+
int exfat_set_volume_dirty(struct super_block *sb);
385+
int exfat_clear_volume_dirty(struct super_block *sb);
387386

388387
/* fatent.c */
389388
#define exfat_get_next_cluster(sb, pclu) exfat_ent_get(sb, *(pclu), pclu)
@@ -463,7 +462,7 @@ struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
463462
int num);
464463
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
465464
struct exfat_chain *p_dir, int entry, unsigned int type);
466-
void exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync);
465+
int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync);
467466
int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir);
468467

469468
/* inode.c */
@@ -515,7 +514,8 @@ void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
515514
u8 *tz, __le16 *time, __le16 *date, u8 *time_cs);
516515
u16 exfat_calc_chksum16(void *data, int len, u16 chksum, int type);
517516
u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type);
518-
void exfat_update_bh(struct super_block *sb, struct buffer_head *bh, int sync);
517+
void exfat_update_bh(struct buffer_head *bh, int sync);
518+
int exfat_update_bhs(struct buffer_head **bhs, int nr_bhs, int sync);
519519
void exfat_chain_set(struct exfat_chain *ec, unsigned int dir,
520520
unsigned int size, unsigned char flags);
521521
void exfat_chain_dup(struct exfat_chain *dup, struct exfat_chain *ec);

fs/exfat/exfat_raw.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
#define EXFAT_MAX_FILE_LEN 255
1616

17-
#define VOL_CLEAN 0x0000
18-
#define VOL_DIRTY 0x0002
19-
#define ERR_MEDIUM 0x0004
17+
#define VOLUME_DIRTY 0x0002
18+
#define MEDIA_FAILURE 0x0004
2019

2120
#define EXFAT_EOF_CLUSTER 0xFFFFFFFFu
2221
#define EXFAT_BAD_CLUSTER 0xFFFFFFF7u

fs/exfat/fatent.c

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int exfat_ent_set(struct super_block *sb, unsigned int loc,
7575

7676
fat_entry = (__le32 *)&(bh->b_data[off]);
7777
*fat_entry = cpu_to_le32(content);
78-
exfat_update_bh(sb, bh, sb->s_flags & SB_SYNCHRONOUS);
78+
exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS);
7979
exfat_mirror_bh(sb, sec, bh);
8080
brelse(bh);
8181
return 0;
@@ -174,7 +174,6 @@ int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
174174
return -EIO;
175175
}
176176

177-
set_bit(EXFAT_SB_DIRTY, &sbi->s_state);
178177
clu = p_chain->dir;
179178

180179
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
@@ -230,21 +229,6 @@ int exfat_find_last_cluster(struct super_block *sb, struct exfat_chain *p_chain,
230229
return 0;
231230
}
232231

233-
static inline int exfat_sync_bhs(struct buffer_head **bhs, int nr_bhs)
234-
{
235-
int i, err = 0;
236-
237-
for (i = 0; i < nr_bhs; i++)
238-
write_dirty_buffer(bhs[i], 0);
239-
240-
for (i = 0; i < nr_bhs; i++) {
241-
wait_on_buffer(bhs[i]);
242-
if (!err && !buffer_uptodate(bhs[i]))
243-
err = -EIO;
244-
}
245-
return err;
246-
}
247-
248232
int exfat_zeroed_cluster(struct inode *dir, unsigned int clu)
249233
{
250234
struct super_block *sb = dir->i_sb;
@@ -266,41 +250,23 @@ int exfat_zeroed_cluster(struct inode *dir, unsigned int clu)
266250
}
267251

268252
/* Zeroing the unused blocks on this cluster */
269-
n = 0;
270253
while (blknr < last_blknr) {
271-
bhs[n] = sb_getblk(sb, blknr);
272-
if (!bhs[n]) {
273-
err = -ENOMEM;
274-
goto release_bhs;
275-
}
276-
memset(bhs[n]->b_data, 0, sb->s_blocksize);
277-
exfat_update_bh(sb, bhs[n], 0);
278-
279-
n++;
280-
blknr++;
281-
282-
if (n == nr_bhs) {
283-
if (IS_DIRSYNC(dir)) {
284-
err = exfat_sync_bhs(bhs, n);
285-
if (err)
286-
goto release_bhs;
254+
for (n = 0; n < nr_bhs && blknr < last_blknr; n++, blknr++) {
255+
bhs[n] = sb_getblk(sb, blknr);
256+
if (!bhs[n]) {
257+
err = -ENOMEM;
258+
goto release_bhs;
287259
}
288-
289-
for (i = 0; i < n; i++)
290-
brelse(bhs[i]);
291-
n = 0;
260+
memset(bhs[n]->b_data, 0, sb->s_blocksize);
292261
}
293-
}
294262

295-
if (IS_DIRSYNC(dir)) {
296-
err = exfat_sync_bhs(bhs, n);
263+
err = exfat_update_bhs(bhs, n, IS_DIRSYNC(dir));
297264
if (err)
298265
goto release_bhs;
299-
}
300-
301-
for (i = 0; i < n; i++)
302-
brelse(bhs[i]);
303266

267+
for (i = 0; i < n; i++)
268+
brelse(bhs[i]);
269+
}
304270
return 0;
305271

306272
release_bhs:
@@ -358,8 +324,6 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
358324
}
359325
}
360326

361-
set_bit(EXFAT_SB_DIRTY, &sbi->s_state);
362-
363327
p_chain->dir = EXFAT_EOF_CLUSTER;
364328

365329
while ((new_clu = exfat_find_free_bitmap(sb, hint_clu)) !=

fs/exfat/file.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
106106
if (ei->type != TYPE_FILE && ei->type != TYPE_DIR)
107107
return -EPERM;
108108

109-
exfat_set_vol_flags(sb, VOL_DIRTY);
109+
exfat_set_volume_dirty(sb);
110110

111111
num_clusters_new = EXFAT_B_TO_CLU_ROUND_UP(i_size_read(inode), sbi);
112112
num_clusters_phys =
@@ -154,6 +154,7 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
154154
struct timespec64 ts;
155155
struct exfat_dentry *ep, *ep2;
156156
struct exfat_entry_set_cache *es;
157+
int err;
157158

158159
es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry,
159160
ES_ALL_ENTRIES);
@@ -188,7 +189,9 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
188189
}
189190

190191
exfat_update_dir_chksum_with_entry_set(es);
191-
exfat_free_dentry_set(es, inode_needs_sync(inode));
192+
err = exfat_free_dentry_set(es, inode_needs_sync(inode));
193+
if (err)
194+
return err;
192195
}
193196

194197
/* cut off from the FAT chain */
@@ -217,7 +220,7 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
217220
if (exfat_free_cluster(inode, &clu))
218221
return -EIO;
219222

220-
exfat_set_vol_flags(sb, VOL_CLEAN);
223+
exfat_clear_volume_dirty(sb);
221224

222225
return 0;
223226
}

fs/exfat/inode.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static int __exfat_write_inode(struct inode *inode, int sync)
3939
if (is_dir && ei->dir.dir == sbi->root_dir && ei->entry == -1)
4040
return 0;
4141

42-
exfat_set_vol_flags(sb, VOL_DIRTY);
42+
exfat_set_volume_dirty(sb);
4343

4444
/* get the directory entry of given file or directory */
4545
es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES);
@@ -77,8 +77,7 @@ static int __exfat_write_inode(struct inode *inode, int sync)
7777
ep2->dentry.stream.size = ep2->dentry.stream.valid_size;
7878

7979
exfat_update_dir_chksum_with_entry_set(es);
80-
exfat_free_dentry_set(es, sync);
81-
return 0;
80+
return exfat_free_dentry_set(es, sync);
8281
}
8382

8483
int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)
@@ -168,7 +167,7 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
168167
}
169168

170169
if (*clu == EXFAT_EOF_CLUSTER) {
171-
exfat_set_vol_flags(sb, VOL_DIRTY);
170+
exfat_set_volume_dirty(sb);
172171

173172
new_clu.dir = (last_clu == EXFAT_EOF_CLUSTER) ?
174173
EXFAT_EOF_CLUSTER : last_clu + 1;
@@ -222,6 +221,7 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
222221
if (ei->dir.dir != DIR_DELETED && modified) {
223222
struct exfat_dentry *ep;
224223
struct exfat_entry_set_cache *es;
224+
int err;
225225

226226
es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry,
227227
ES_ALL_ENTRIES);
@@ -240,8 +240,9 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
240240
ep->dentry.stream.valid_size;
241241

242242
exfat_update_dir_chksum_with_entry_set(es);
243-
exfat_free_dentry_set(es, inode_needs_sync(inode));
244-
243+
err = exfat_free_dentry_set(es, inode_needs_sync(inode));
244+
if (err)
245+
return err;
245246
} /* end of if != DIR_DELETED */
246247

247248
inode->i_blocks +=

fs/exfat/misc.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,34 @@ u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type)
163163
return chksum;
164164
}
165165

166-
void exfat_update_bh(struct super_block *sb, struct buffer_head *bh, int sync)
166+
void exfat_update_bh(struct buffer_head *bh, int sync)
167167
{
168-
set_bit(EXFAT_SB_DIRTY, &EXFAT_SB(sb)->s_state);
169168
set_buffer_uptodate(bh);
170169
mark_buffer_dirty(bh);
171170

172171
if (sync)
173172
sync_dirty_buffer(bh);
174173
}
175174

175+
int exfat_update_bhs(struct buffer_head **bhs, int nr_bhs, int sync)
176+
{
177+
int i, err = 0;
178+
179+
for (i = 0; i < nr_bhs; i++) {
180+
set_buffer_uptodate(bhs[i]);
181+
mark_buffer_dirty(bhs[i]);
182+
if (sync)
183+
write_dirty_buffer(bhs[i], 0);
184+
}
185+
186+
for (i = 0; i < nr_bhs && sync; i++) {
187+
wait_on_buffer(bhs[i]);
188+
if (!err && !buffer_uptodate(bhs[i]))
189+
err = -EIO;
190+
}
191+
return err;
192+
}
193+
176194
void exfat_chain_set(struct exfat_chain *ec, unsigned int dir,
177195
unsigned int size, unsigned char flags)
178196
{

0 commit comments

Comments
 (0)