* [PATCH v2 1/9] f2fs: Add missing break in switch-case
2016-10-28 8:44 [PATCH v2 0/9] f2fs: Zoned block device support Damien Le Moal
@ 2016-10-28 8:44 ` Damien Le Moal
2016-10-28 8:45 ` [PATCH v2 2/9] f2fs: Use generic zoned block device terminology Damien Le Moal
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2016-10-28 8:44 UTC (permalink / raw)
To: jaegeuk, yuchao0
Cc: linux-fsdevel, linux-f2fs-devel, Hannes Reinecke, Shaun Tancheff,
Damien Le Moal
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
fs/f2fs/super.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 6132b4c..f6379f5 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -420,6 +420,7 @@ static int parse_options(struct super_block *sb, char *options)
break;
case Opt_nodiscard:
clear_opt(sbi, DISCARD);
+ break;
case Opt_noheap:
set_opt(sbi, NOHEAP);
break;
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 2/9] f2fs: Use generic zoned block device terminology
2016-10-28 8:44 [PATCH v2 0/9] f2fs: Zoned block device support Damien Le Moal
2016-10-28 8:44 ` [PATCH v2 1/9] f2fs: Add missing break in switch-case Damien Le Moal
@ 2016-10-28 8:45 ` Damien Le Moal
2016-10-28 8:45 ` [PATCH v2 3/9] f2fs: Check zoned block feature for host-managed zoned block devices Damien Le Moal
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2016-10-28 8:45 UTC (permalink / raw)
To: jaegeuk, yuchao0
Cc: linux-fsdevel, linux-f2fs-devel, Hannes Reinecke, Shaun Tancheff,
Damien Le Moal
SMR stands for "Shingled Magnetic Recording" which makes sense
only for hard disk drives (spinning rust). The ZBC/ZAC standards
enable management of SMR disks, but solid state drives may also
support those standards. So rename the HMSMR feature to BLKZONED
to avoid a HDD centric terminology. For the same reason, rename
f2fs_sb_mounted_hmsmr to f2fs_sb_mounted_blkzoned.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
fs/f2fs/data.c | 2 +-
fs/f2fs/f2fs.h | 6 +++---
fs/f2fs/super.c | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 9ae194f..803f30f 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -110,7 +110,7 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi,
{
if (!is_read_io(bio_op(bio))) {
atomic_inc(&sbi->nr_wb_bios);
- if (f2fs_sb_mounted_hmsmr(sbi->sb) &&
+ if (f2fs_sb_mounted_blkzoned(sbi->sb) &&
current->plug && (type == DATA || type == NODE))
blk_finish_plug(current->plug);
}
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 9e8de18..2fc771a 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -103,7 +103,7 @@ struct f2fs_mount_info {
};
#define F2FS_FEATURE_ENCRYPT 0x0001
-#define F2FS_FEATURE_HMSMR 0x0002
+#define F2FS_FEATURE_BLKZONED 0x0002
#define F2FS_HAS_FEATURE(sb, mask) \
((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -2412,9 +2412,9 @@ static inline int f2fs_sb_has_crypto(struct super_block *sb)
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT);
}
-static inline int f2fs_sb_mounted_hmsmr(struct super_block *sb)
+static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb)
{
- return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_HMSMR);
+ return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED);
}
static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index f6379f5..a83df29 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -975,7 +975,7 @@ static void default_options(struct f2fs_sb_info *sbi)
set_opt(sbi, EXTENT_CACHE);
sbi->sb->s_flags |= MS_LAZYTIME;
set_opt(sbi, FLUSH_MERGE);
- if (f2fs_sb_mounted_hmsmr(sbi->sb)) {
+ if (f2fs_sb_mounted_blkzoned(sbi->sb)) {
set_opt_mode(sbi, F2FS_MOUNT_LFS);
set_opt(sbi, DISCARD);
} else {
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 3/9] f2fs: Check zoned block feature for host-managed zoned block devices
2016-10-28 8:44 [PATCH v2 0/9] f2fs: Zoned block device support Damien Le Moal
2016-10-28 8:44 ` [PATCH v2 1/9] f2fs: Add missing break in switch-case Damien Le Moal
2016-10-28 8:45 ` [PATCH v2 2/9] f2fs: Use generic zoned block device terminology Damien Le Moal
@ 2016-10-28 8:45 ` Damien Le Moal
2016-10-28 8:45 ` [PATCH v2 4/9] f2fs: Suppress discard warning message for " Damien Le Moal
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2016-10-28 8:45 UTC (permalink / raw)
To: jaegeuk, yuchao0
Cc: linux-fsdevel, linux-f2fs-devel, Hannes Reinecke, Shaun Tancheff,
Damien Le Moal
The F2FS_FEATURE_BLKZONED feature indicates that the drive was formatted
with zone alignment optimization. This is optional for host-aware
devices, but mandatory for host-managed zoned block devices.
So check that the feature is set in this latter case.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
fs/f2fs/super.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index a83df29..c6e9b94 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1642,6 +1642,26 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
sb->s_fs_info = sbi;
sbi->raw_super = raw_super;
+ /*
+ * The BLKZONED feature indicates that the drive was formatted with
+ * zone alignment optimization. This is optional for host-aware
+ * devices, but mandatory for host-managed zoned block devices.
+ */
+#ifndef CONFIG_BLK_DEV_ZONED
+ if (f2fs_sb_mounted_blkzoned(sb)) {
+ f2fs_msg(sb, KERN_ERR,
+ "Zoned block device support is not enabled\n");
+ goto free_sb_buf;
+ }
+#else
+ if (bdev_zoned_model(sb->s_bdev) == BLK_ZONED_HM &&
+ !f2fs_sb_mounted_blkzoned(sb)) {
+ f2fs_msg(sb, KERN_ERR,
+ "Zoned block device feature not enabled\n");
+ goto free_sb_buf;
+ }
+#endif
+
default_options(sbi);
/* parse mount options */
options = kstrdup((const char *)data, GFP_KERNEL);
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 4/9] f2fs: Suppress discard warning message for zoned block devices
2016-10-28 8:44 [PATCH v2 0/9] f2fs: Zoned block device support Damien Le Moal
` (2 preceding siblings ...)
2016-10-28 8:45 ` [PATCH v2 3/9] f2fs: Check zoned block feature for host-managed zoned block devices Damien Le Moal
@ 2016-10-28 8:45 ` Damien Le Moal
2016-10-28 8:45 ` [PATCH v2 5/9] f2fs: Always enable discard for zoned blocks devices Damien Le Moal
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2016-10-28 8:45 UTC (permalink / raw)
To: jaegeuk, yuchao0
Cc: linux-fsdevel, linux-f2fs-devel, Hannes Reinecke, Shaun Tancheff,
Damien Le Moal
For zoned block devices, discard is replaced by zone reset. So
do not warn if the device does not supports discard.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
fs/f2fs/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index c6e9b94..2313234 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -412,7 +412,7 @@ static int parse_options(struct super_block *sb, char *options)
q = bdev_get_queue(sb->s_bdev);
if (blk_queue_discard(q)) {
set_opt(sbi, DISCARD);
- } else {
+ } else if (!f2fs_sb_mounted_blkzoned(sb)) {
f2fs_msg(sb, KERN_WARNING,
"mounting with \"discard\" option, but "
"the device does not support discard");
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 5/9] f2fs: Always enable discard for zoned blocks devices
2016-10-28 8:44 [PATCH v2 0/9] f2fs: Zoned block device support Damien Le Moal
` (3 preceding siblings ...)
2016-10-28 8:45 ` [PATCH v2 4/9] f2fs: Suppress discard warning message for " Damien Le Moal
@ 2016-10-28 8:45 ` Damien Le Moal
2016-10-28 8:45 ` [PATCH v2 6/9] f2fs: Do not allow adaptive mode for host-managed zoned block devices Damien Le Moal
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2016-10-28 8:45 UTC (permalink / raw)
To: jaegeuk, yuchao0
Cc: linux-fsdevel, linux-f2fs-devel, Hannes Reinecke, Shaun Tancheff,
Damien Le Moal
Zone write pointer reset acts as discard for zoned block
devices. So if the zoned block device feature is enabled,
always declare that discard is enabled, even if the device
does not actually support the command.
For the same reason, prevent the use the "nodicard" mount
option.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
fs/f2fs/f2fs.h | 14 +++++++-------
fs/f2fs/super.c | 5 +++++
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 2fc771a..beb2093 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1105,13 +1105,6 @@ static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
spin_unlock(&sbi->cp_lock);
}
-static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
-{
- struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
-
- return blk_queue_discard(q);
-}
-
static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
{
down_read(&sbi->cp_rwsem);
@@ -2417,6 +2410,13 @@ static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb)
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED);
}
+static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
+{
+ struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
+
+ return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb);
+}
+
static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
{
clear_opt(sbi, ADAPTIVE);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 2313234..2c8a12e 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -419,6 +419,11 @@ static int parse_options(struct super_block *sb, char *options)
}
break;
case Opt_nodiscard:
+ if (f2fs_sb_mounted_blkzoned(sb)) {
+ f2fs_msg(sb, KERN_WARNING,
+ "discard is required for zoned block devices");
+ return -EINVAL;
+ }
clear_opt(sbi, DISCARD);
break;
case Opt_noheap:
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 6/9] f2fs: Do not allow adaptive mode for host-managed zoned block devices
2016-10-28 8:44 [PATCH v2 0/9] f2fs: Zoned block device support Damien Le Moal
` (4 preceding siblings ...)
2016-10-28 8:45 ` [PATCH v2 5/9] f2fs: Always enable discard for zoned blocks devices Damien Le Moal
@ 2016-10-28 8:45 ` Damien Le Moal
2016-10-28 8:45 ` [PATCH v2 7/9] f2fs: Cache zoned block devices zone type Damien Le Moal
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2016-10-28 8:45 UTC (permalink / raw)
To: jaegeuk, yuchao0
Cc: linux-fsdevel, linux-f2fs-devel, Hannes Reinecke, Shaun Tancheff,
Damien Le Moal
The LFS mode is mandatory for host-managed zoned block devices as
update in place optimizations are not possible for segments in
sequential zones.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
fs/f2fs/super.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 2c8a12e..58fd69d 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -518,6 +518,13 @@ static int parse_options(struct super_block *sb, char *options)
return -ENOMEM;
if (strlen(name) == 8 &&
!strncmp(name, "adaptive", 8)) {
+ if (f2fs_sb_mounted_blkzoned(sb)) {
+ f2fs_msg(sb, KERN_WARNING,
+ "adaptive mode is not allowed with "
+ "zoned block device feature");
+ kfree(name);
+ return -EINVAL;
+ }
set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE);
} else if (strlen(name) == 3 &&
!strncmp(name, "lfs", 3)) {
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 7/9] f2fs: Cache zoned block devices zone type
2016-10-28 8:44 [PATCH v2 0/9] f2fs: Zoned block device support Damien Le Moal
` (5 preceding siblings ...)
2016-10-28 8:45 ` [PATCH v2 6/9] f2fs: Do not allow adaptive mode for host-managed zoned block devices Damien Le Moal
@ 2016-10-28 8:45 ` Damien Le Moal
2016-10-28 8:45 ` [PATCH v2 8/9] f2fs: Reset sequential zones on zoned block devices Damien Le Moal
2016-10-28 8:45 ` [PATCH v2 9/9] f2fs: Trace reset zone events Damien Le Moal
8 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2016-10-28 8:45 UTC (permalink / raw)
To: jaegeuk, yuchao0
Cc: linux-fsdevel, linux-f2fs-devel, Hannes Reinecke, Shaun Tancheff,
Damien Le Moal
With the zoned block device feature enabled, section discard
need to do a zone reset for sections contained in sequential
zones, and a regular discard (if supported) for sections
stored in conventional zones. Avoid the need for a costly
report zones to obtain a section zone type when discarding it
by caching the types of the device zones in the super block
information. This cache is initialized at mount time for mounts
with the zoned block device feature enabled.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
fs/f2fs/f2fs.h | 18 +++++++++++++++
fs/f2fs/super.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index beb2093..a1a074d 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -750,6 +750,14 @@ struct f2fs_sb_info {
u8 key_prefix[F2FS_KEY_DESC_PREFIX_SIZE];
u8 key_prefix_size;
#endif
+
+#ifdef CONFIG_BLK_DEV_ZONED
+ unsigned int nr_blkz; /* Total number of zones */
+ unsigned int blocks_per_blkz; /* F2FS blocks per zone */
+ unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */
+ u8 *blkz_type; /* Array of zones type */
+#endif
+
/* for node-related operations */
struct f2fs_nm_info *nm_info; /* node manager */
struct inode *node_inode; /* cache node blocks */
@@ -2410,6 +2418,16 @@ static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb)
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED);
}
+#ifdef CONFIG_BLK_DEV_ZONED
+static inline int get_blkz_type(struct f2fs_sb_info *sbi,
+ block_t blkaddr)
+{
+ unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz;
+
+ return sbi->blkz_type[zno];
+}
+#endif
+
static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
{
struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 58fd69d..2b7880d 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1515,6 +1515,65 @@ static int init_percpu_info(struct f2fs_sb_info *sbi)
GFP_KERNEL);
}
+#ifdef CONFIG_BLK_DEV_ZONED
+static int init_blkz_info(struct f2fs_sb_info *sbi)
+{
+ struct block_device *bdev = sbi->sb->s_bdev;
+ sector_t nr_sectors = bdev->bd_part->nr_sects;
+ sector_t sector = 0;
+ struct blk_zone *zones;
+ unsigned int i, nr_zones;
+ unsigned int n = 0;
+ int err = -EIO;
+
+ if (!f2fs_sb_mounted_blkzoned(sbi->sb))
+ return 0;
+
+ sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_size(bdev));
+ sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz);
+ sbi->nr_blkz = SECTOR_TO_BLOCK(nr_sectors) >>
+ sbi->log_blocks_per_blkz;
+ if (nr_sectors & (bdev_zone_size(bdev) - 1))
+ sbi->nr_blkz++;
+
+ sbi->blkz_type = kmalloc(sbi->nr_blkz, GFP_KERNEL);
+ if (!sbi->blkz_type)
+ return -ENOMEM;
+
+#define F2FS_REPORT_NR_ZONES 4096
+
+ zones = kcalloc(F2FS_REPORT_NR_ZONES, sizeof(struct blk_zone),
+ GFP_KERNEL);
+ if (!zones)
+ return -ENOMEM;
+
+ /* Get block zones type */
+ while (zones && sector < nr_sectors) {
+
+ nr_zones = F2FS_REPORT_NR_ZONES;
+ err = blkdev_report_zones(bdev, sector,
+ zones, &nr_zones,
+ GFP_KERNEL);
+ if (err)
+ break;
+ if (!nr_zones) {
+ err = -EIO;
+ break;
+ }
+
+ for (i = 0; i < nr_zones; i++) {
+ sbi->blkz_type[n] = zones[i].type;
+ sector += zones[i].len;
+ n++;
+ }
+ }
+
+ kfree(zones);
+
+ return err;
+}
+#endif
+
/*
* Read f2fs raw super block.
* Because we have two copies of super block, so read both of them
@@ -1761,6 +1820,15 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
init_ino_entry_info(sbi);
+#ifdef CONFIG_BLK_DEV_ZONED
+ err = init_blkz_info(sbi);
+ if (err) {
+ f2fs_msg(sb, KERN_ERR,
+ "Failed to initialize F2FS blkzone information");
+ goto free_blkz;
+ }
+#endif
+
/* setup f2fs internal modules */
err = build_segment_manager(sbi);
if (err) {
@@ -1932,6 +2000,10 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
destroy_node_manager(sbi);
free_sm:
destroy_segment_manager(sbi);
+#ifdef CONFIG_BLK_DEV_ZONED
+free_blkz:
+ kfree(sbi->blkz_type);
+#endif
kfree(sbi->ckpt);
free_meta_inode:
make_bad_inode(sbi->meta_inode);
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 8/9] f2fs: Reset sequential zones on zoned block devices
2016-10-28 8:44 [PATCH v2 0/9] f2fs: Zoned block device support Damien Le Moal
` (6 preceding siblings ...)
2016-10-28 8:45 ` [PATCH v2 7/9] f2fs: Cache zoned block devices zone type Damien Le Moal
@ 2016-10-28 8:45 ` Damien Le Moal
2016-10-28 8:45 ` [PATCH v2 9/9] f2fs: Trace reset zone events Damien Le Moal
8 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2016-10-28 8:45 UTC (permalink / raw)
To: jaegeuk, yuchao0
Cc: linux-fsdevel, linux-f2fs-devel, Hannes Reinecke, Shaun Tancheff,
Damien Le Moal
When a zoned block device is mounted, discarding sections
contained in sequential zones must reset the zone write pointer.
For sections contained in conventional zones, the regular discard
is used if the drive supports it.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
fs/f2fs/segment.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 57 insertions(+), 8 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index fc886f0..ee66e08 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -16,6 +16,7 @@
#include <linux/kthread.h>
#include <linux/swap.h>
#include <linux/timer.h>
+#include <linux/timer.h>
#include "f2fs.h"
#include "segment.h"
@@ -633,15 +634,19 @@ static void f2fs_submit_bio_wait_endio(struct bio *bio)
}
/* this function is copied from blkdev_issue_discard from block/blk-lib.c */
-int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi, sector_t sector,
- sector_t nr_sects, gfp_t gfp_mask, unsigned long flags)
+static int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi,
+ block_t blkstart, block_t blklen)
{
struct block_device *bdev = sbi->sb->s_bdev;
struct bio *bio = NULL;
int err;
- err = __blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, flags,
- &bio);
+ trace_f2fs_issue_discard(sbi->sb, blkstart, blklen);
+
+ err = __blkdev_issue_discard(bdev,
+ SECTOR_FROM_BLOCK(blkstart),
+ SECTOR_FROM_BLOCK(blklen),
+ GFP_NOFS, 0, &bio);
if (!err && bio) {
struct bio_entry *be = __add_bio_entry(sbi, bio);
@@ -654,11 +659,50 @@ int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi, sector_t sector,
return err;
}
+#ifdef CONFIG_BLK_DEV_ZONED
+static int f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
+ block_t blkstart, block_t blklen)
+{
+ sector_t sector = SECTOR_FROM_BLOCK(blkstart);
+ sector_t nr_sects = SECTOR_FROM_BLOCK(blklen);
+ struct block_device *bdev = sbi->sb->s_bdev;
+
+ if (nr_sects != bdev_zone_size(bdev)) {
+ f2fs_msg(sbi->sb, KERN_INFO,
+ "Unaligned discard attempted (sector %llu + %llu)",
+ (unsigned long long)sector,
+ (unsigned long long)nr_sects);
+ return -EIO;
+ }
+
+ /*
+ * We need to know the type of the zone: for conventional zones,
+ * use regular discard if the drive supports it. For sequential
+ * zones, reset the zone write pointer.
+ */
+ switch (get_blkz_type(sbi, blkstart)) {
+
+ case BLK_ZONE_TYPE_CONVENTIONAL:
+ if (!blk_queue_discard(bdev_get_queue(bdev)))
+ return 0;
+ return __f2fs_issue_discard_async(sbi, blkstart,
+ blklen);
+
+ case BLK_ZONE_TYPE_SEQWRITE_REQ:
+ case BLK_ZONE_TYPE_SEQWRITE_PREF:
+ return blkdev_reset_zones(bdev, sector,
+ nr_sects, GFP_NOFS);
+
+ default:
+ /* Unknown zone type: broken device ? */
+ return -EIO;
+ }
+}
+#endif
+
static int f2fs_issue_discard(struct f2fs_sb_info *sbi,
block_t blkstart, block_t blklen)
{
- sector_t start = SECTOR_FROM_BLOCK(blkstart);
- sector_t len = SECTOR_FROM_BLOCK(blklen);
struct seg_entry *se;
unsigned int offset;
block_t i;
@@ -670,8 +714,13 @@ static int f2fs_issue_discard(struct f2fs_sb_info *sbi,
if (!f2fs_test_and_set_bit(offset, se->discard_map))
sbi->discard_blks--;
}
- trace_f2fs_issue_discard(sbi->sb, blkstart, blklen);
- return __f2fs_issue_discard_async(sbi, start, len, GFP_NOFS, 0);
+
+#ifdef CONFIG_BLK_DEV_ZONED
+ if (f2fs_sb_mounted_blkzoned(sbi->sb))
+ return f2fs_issue_discard_zone(sbi, blkstart, blklen);
+#endif
+
+ return __f2fs_issue_discard_async(sbi, blkstart, blklen);
}
static void __add_discard_entry(struct f2fs_sb_info *sbi,
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 9/9] f2fs: Trace reset zone events
2016-10-28 8:44 [PATCH v2 0/9] f2fs: Zoned block device support Damien Le Moal
` (7 preceding siblings ...)
2016-10-28 8:45 ` [PATCH v2 8/9] f2fs: Reset sequential zones on zoned block devices Damien Le Moal
@ 2016-10-28 8:45 ` Damien Le Moal
8 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2016-10-28 8:45 UTC (permalink / raw)
To: jaegeuk, yuchao0
Cc: linux-fsdevel, linux-f2fs-devel, Hannes Reinecke, Shaun Tancheff,
Damien Le Moal
Similarly to the regular discard, trace zone reset events.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
fs/f2fs/segment.c | 1 +
include/trace/events/f2fs.h | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index ee66e08..125045d 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -690,6 +690,7 @@ static int f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
case BLK_ZONE_TYPE_SEQWRITE_REQ:
case BLK_ZONE_TYPE_SEQWRITE_PREF:
+ trace_f2fs_issue_reset_zone(sbi->sb, blkstart);
return blkdev_reset_zones(bdev, sector,
nr_sects, GFP_NOFS);
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index 903a091..a2193e3 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -1113,6 +1113,27 @@ TRACE_EVENT(f2fs_issue_discard,
(unsigned long long)__entry->blklen)
);
+TRACE_EVENT(f2fs_issue_reset_zone,
+
+ TP_PROTO(struct super_block *sb, block_t blkstart),
+
+ TP_ARGS(sb, blkstart),
+
+ TP_STRUCT__entry(
+ __field(dev_t, dev)
+ __field(block_t, blkstart)
+ ),
+
+ TP_fast_assign(
+ __entry->dev = sb->s_dev;
+ __entry->blkstart = blkstart;
+ ),
+
+ TP_printk("dev = (%d,%d), reset zone at block = 0x%llx",
+ show_dev(__entry),
+ (unsigned long long)__entry->blkstart)
+);
+
TRACE_EVENT(f2fs_issue_flush,
TP_PROTO(struct super_block *sb, unsigned int nobarrier,
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread