Skip to content

Commit dabb99e

Browse files
damien-lemoalgregkh
authored andcommitted
f2fs: Fix use of number of devices
commit 0916878 upstream. For a single device mount using a zoned block device, the zone information for the device is stored in the sbi->devs single entry array and sbi->s_ndevs is set to 1. This differs from a single device mount using a regular block device which does not allocate sbi->devs and sets sbi->s_ndevs to 0. However, sbi->s_devs == 0 condition is used throughout the code to differentiate a single device mount from a multi-device mount where sbi->s_ndevs is always larger than 1. This results in problems with single zoned block device volumes as these are treated as multi-device mounts but do not have the start_blk and end_blk information set. One of the problem observed is skipping of zone discard issuing resulting in write commands being issued to full zones or unaligned to a zone write pointer. Fix this problem by simply treating the cases sbi->s_ndevs == 0 (single regular block device mount) and sbi->s_ndevs == 1 (single zoned block device mount) in the same manner. This is done by introducing the helper function f2fs_is_multi_device() and using this helper in place of direct tests of sbi->s_ndevs value, improving code readability. Fixes: 7bb3a37 ("f2fs: Fix zoned block device support") Cc: <stable@vger.kernel.org> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d82e3d5 commit dabb99e

5 files changed

Lines changed: 32 additions & 15 deletions

File tree

‎fs/f2fs/data.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,14 @@ struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
220220
struct block_device *bdev = sbi->sb->s_bdev;
221221
int i;
222222

223-
for (i = 0; i < sbi->s_ndevs; i++) {
224-
if (FDEV(i).start_blk <= blk_addr &&
225-
FDEV(i).end_blk >= blk_addr) {
226-
blk_addr -= FDEV(i).start_blk;
227-
bdev = FDEV(i).bdev;
228-
break;
223+
if (f2fs_is_multi_device(sbi)) {
224+
for (i = 0; i < sbi->s_ndevs; i++) {
225+
if (FDEV(i).start_blk <= blk_addr &&
226+
FDEV(i).end_blk >= blk_addr) {
227+
blk_addr -= FDEV(i).start_blk;
228+
bdev = FDEV(i).bdev;
229+
break;
230+
}
229231
}
230232
}
231233
if (bio) {
@@ -239,6 +241,9 @@ int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr)
239241
{
240242
int i;
241243

244+
if (!f2fs_is_multi_device(sbi))
245+
return 0;
246+
242247
for (i = 0; i < sbi->s_ndevs; i++)
243248
if (FDEV(i).start_blk <= blkaddr && FDEV(i).end_blk >= blkaddr)
244249
return i;

‎fs/f2fs/f2fs.h‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,17 @@ static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
13661366
}
13671367
#endif
13681368

1369+
/*
1370+
* Test if the mounted volume is a multi-device volume.
1371+
* - For a single regular disk volume, sbi->s_ndevs is 0.
1372+
* - For a single zoned disk volume, sbi->s_ndevs is 1.
1373+
* - For a multi-device volume, sbi->s_ndevs is always 2 or more.
1374+
*/
1375+
static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi)
1376+
{
1377+
return sbi->s_ndevs > 1;
1378+
}
1379+
13691380
/* For write statistics. Suppose sector size is 512 bytes,
13701381
* and the return value is in kbytes. s is of struct f2fs_sb_info.
13711382
*/
@@ -3615,7 +3626,7 @@ static inline bool f2fs_force_buffered_io(struct inode *inode,
36153626

36163627
if (f2fs_post_read_required(inode))
36173628
return true;
3618-
if (sbi->s_ndevs)
3629+
if (f2fs_is_multi_device(sbi))
36193630
return true;
36203631
/*
36213632
* for blkzoned device, fallback direct IO to buffered IO, so

‎fs/f2fs/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,7 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)
25732573
sizeof(range)))
25742574
return -EFAULT;
25752575

2576-
if (sbi->s_ndevs <= 1 || sbi->s_ndevs - 1 <= range.dev_num ||
2576+
if (!f2fs_is_multi_device(sbi) || sbi->s_ndevs - 1 <= range.dev_num ||
25772577
__is_large_section(sbi)) {
25782578
f2fs_msg(sbi->sb, KERN_WARNING,
25792579
"Can't flush %u in %d for segs_per_sec %u != 1\n",

‎fs/f2fs/gc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ void f2fs_build_gc_manager(struct f2fs_sb_info *sbi)
13461346
sbi->gc_pin_file_threshold = DEF_GC_FAILED_PINNED_FILES;
13471347

13481348
/* give warm/cold data area from slower device */
1349-
if (sbi->s_ndevs && !__is_large_section(sbi))
1349+
if (f2fs_is_multi_device(sbi) && !__is_large_section(sbi))
13501350
SIT_I(sbi)->last_victim[ALLOC_NEXT] =
13511351
GET_SEGNO(sbi, FDEV(0).end_blk) + 1;
13521352
}

‎fs/f2fs/segment.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static int submit_flush_wait(struct f2fs_sb_info *sbi, nid_t ino)
580580
int ret = 0;
581581
int i;
582582

583-
if (!sbi->s_ndevs)
583+
if (!f2fs_is_multi_device(sbi))
584584
return __submit_flush_wait(sbi, sbi->sb->s_bdev);
585585

586586
for (i = 0; i < sbi->s_ndevs; i++) {
@@ -648,7 +648,8 @@ int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino)
648648
return ret;
649649
}
650650

651-
if (atomic_inc_return(&fcc->queued_flush) == 1 || sbi->s_ndevs > 1) {
651+
if (atomic_inc_return(&fcc->queued_flush) == 1 ||
652+
f2fs_is_multi_device(sbi)) {
652653
ret = submit_flush_wait(sbi, ino);
653654
atomic_dec(&fcc->queued_flush);
654655

@@ -754,7 +755,7 @@ int f2fs_flush_device_cache(struct f2fs_sb_info *sbi)
754755
{
755756
int ret = 0, i;
756757

757-
if (!sbi->s_ndevs)
758+
if (!f2fs_is_multi_device(sbi))
758759
return 0;
759760

760761
for (i = 1; i < sbi->s_ndevs; i++) {
@@ -1369,7 +1370,7 @@ static int __queue_discard_cmd(struct f2fs_sb_info *sbi,
13691370

13701371
trace_f2fs_queue_discard(bdev, blkstart, blklen);
13711372

1372-
if (sbi->s_ndevs) {
1373+
if (f2fs_is_multi_device(sbi)) {
13731374
int devi = f2fs_target_device_index(sbi, blkstart);
13741375

13751376
blkstart -= FDEV(devi).start_blk;
@@ -1732,7 +1733,7 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
17321733
block_t lblkstart = blkstart;
17331734
int devi = 0;
17341735

1735-
if (sbi->s_ndevs) {
1736+
if (f2fs_is_multi_device(sbi)) {
17361737
devi = f2fs_target_device_index(sbi, blkstart);
17371738
blkstart -= FDEV(devi).start_blk;
17381739
}
@@ -3089,7 +3090,7 @@ static void update_device_state(struct f2fs_io_info *fio)
30893090
struct f2fs_sb_info *sbi = fio->sbi;
30903091
unsigned int devidx;
30913092

3092-
if (!sbi->s_ndevs)
3093+
if (!f2fs_is_multi_device(sbi))
30933094
return;
30943095

30953096
devidx = f2fs_target_device_index(sbi, fio->new_blkaddr);

0 commit comments

Comments
 (0)