Skip to contentSkip to conversation

zloop fixes

PATCH In review Christoph Hellwig 3 participants 10 messages Oct 29 – Oct 30

Subsystems (2)
lore
Share & tools
lore

Christoph Hellwig

author reviewer
#0 lore raw

Hi all,

this series has misc fixes for zloop.

Diffstat:

 zloop.c |   80 ++++++++++++++++++++++++++++++----------------------------------
 1 file changed, 38 insertions(+), 42 deletions(-)
author reviewer
#1 lore raw

PATCH 1/4 zloop: remove a duplicate call to zloop_get_block_size

The sequential zone path has two calls to zloop_get_block_size, one conditional on not having a block size, and one unconditionally.

Remove the latter as the block size only needs to be queried once.

Fixes eb0570c7df23 ("block: new zoned loop block device driver")
---
 drivers/block/zloop.c | 2 --
 1 file changed, 2 deletions(-)
drivers/block/zloop.c +0 -2
index 9145e0f98d56..71f7685efb13 100644
@@ -1183,8 +1183,6 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 			return ret;
 	}
 
-	zloop_get_block_size(zlo, zone);
-
 	mutex_lock(&zone->lock);
 	ret = zloop_update_seq_zone(zlo, zone_no);
 	mutex_unlock(&zone->lock);
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] zloop: remove a duplicate call to zloop_get_block_size

Quoted 7 lines · Christoph Hellwig

The sequential zone path has two calls to zloop_get_block_size, one conditional on not having a block size, and one unconditionally.

Remove the latter as the block size only needs to be queried once.

Fixes eb0570c7df23 ("block: new zoned loop block device driver")
Signature · 2 lines
Damien Le Moal
Western Digital Research
author reviewer
#3 lore raw

PATCH 2/4 zloop: share more code for opening a zone backing file

In reply to Christoph Hellwig

Use a common path for opening and querying the block size.

---
 drivers/block/zloop.c | 65 +++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 39 deletions(-)
drivers/block/zloop.c +26 -39
index 71f7685efb13..3dc484e3c700 100644
@@ -1107,8 +1107,6 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 {
 	struct zloop_zone *zone = &zlo->zones[zone_no];
 	int oflags = O_RDWR;
-	struct kstat stat;
-	sector_t file_sectors;
 	int ret;
 
 	mutex_init(&zone->lock);
@@ -1122,27 +1120,33 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 	if (!opts->buffered_io)
 		oflags |= O_DIRECT;
 
+	zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/%s-%06u",
+				zlo->base_dir, zlo->id,
+				zone_no < zlo->nr_conv_zones ? "cnv" : "seq",
+				zone_no);
+	if (IS_ERR(zone->file)) {
+		pr_err("Failed to open zone %u file %s/%u/%s-%06u (err=%ld)",
+		       zone_no, zlo->base_dir, zlo->id,
+		       zone_no < zlo->nr_conv_zones ? "cnv" : "seq",
+		       zone_no, PTR_ERR(zone->file));
+		return PTR_ERR(zone->file);
+	}
+
+	if (zlo->block_size) {
+		ret = zloop_get_block_size(zlo, zone);
+		if (ret)
+			return ret;
+	}
+
 	if (zone_no < zlo->nr_conv_zones) {
+		sector_t file_sectors;
+		struct kstat stat;
+
 		/* Conventional zone file. */
 		set_bit(ZLOOP_ZONE_CONV, &zone->flags);
 		zone->cond = BLK_ZONE_COND_NOT_WP;
 		zone->wp = U64_MAX;
 
-		zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/cnv-%06u",
-					zlo->base_dir, zlo->id, zone_no);
-		if (IS_ERR(zone->file)) {
-			pr_err("Failed to open zone %u file %s/%u/cnv-%06u (err=%ld)",
-			       zone_no, zlo->base_dir, zlo->id, zone_no,
-			       PTR_ERR(zone->file));
-			return PTR_ERR(zone->file);
-		}
-
-		if (!zlo->block_size) {
-			ret = zloop_get_block_size(zlo, zone);
-			if (ret)
-				return ret;
-		}
-
 		ret = vfs_getattr(&zone->file->f_path, &stat, STATX_SIZE, 0);
 		if (ret < 0) {
 			pr_err("Failed to get zone %u file stat\n", zone_no);
@@ -1163,30 +1167,13 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 			       zone_no, ret);
 			return ret;
 		}
-
-		return 0;
-	}
-
-	/* Sequential zone file. */
-	zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/seq-%06u",
-					 zlo->base_dir, zlo->id, zone_no);
-	if (IS_ERR(zone->file)) {
-		pr_err("Failed to open zone %u file %s/%u/seq-%06u (err=%ld)",
-		       zone_no, zlo->base_dir, zlo->id, zone_no,
-		       PTR_ERR(zone->file));
-		return PTR_ERR(zone->file);
-	}
-
-	if (!zlo->block_size) {
-		ret = zloop_get_block_size(zlo, zone);
-		if (ret)
-			return ret;
+	} else {
+		/* Sequential zone file. */
+		mutex_lock(&zone->lock);
+		ret = zloop_update_seq_zone(zlo, zone_no);
+		mutex_unlock(&zone->lock);
 	}
 
-	mutex_lock(&zone->lock);
-	ret = zloop_update_seq_zone(zlo, zone_no);
-	mutex_unlock(&zone->lock);
-
 	return ret;
 }
 
Signature · 1 line
2.53.0
maintainer
#4 lore raw

Re: [PATCH 2/4] zloop: share more code for opening a zone backing file

Quoted 27 lines · Christoph Hellwig

Use a common path for opening and querying the block size.

---
 drivers/block/zloop.c | 65 +++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 39 deletions(-)
drivers/block/zloop.c +3 -2
index 71f7685efb13..3dc484e3c700 100644
@@ -1107,8 +1107,6 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 {
 	struct zloop_zone *zone = &zlo->zones[zone_no];
 	int oflags = O_RDWR;
-	struct kstat stat;
-	sector_t file_sectors;
 	int ret;
 
 	mutex_init(&zone->lock);
@@ -1122,27 +1120,33 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 	if (!opts->buffered_io)
 		oflags |= O_DIRECT;
 
+	zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/%s-%06u",
+				zlo->base_dir, zlo->id,
+				zone_no < zlo->nr_conv_zones ? "cnv" : "seq",

drivers/block/zloop.c static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts, · line 1135

Quoted 10 lines
drivers/block/zloop.c +10 -0
+				zone_no);
+	if (IS_ERR(zone->file)) {
+		pr_err("Failed to open zone %u file %s/%u/%s-%06u (err=%ld)",
+		       zone_no, zlo->base_dir, zlo->id,
+		       zone_no < zlo->nr_conv_zones ? "cnv" : "seq",
+		       zone_no, PTR_ERR(zone->file));
+		return PTR_ERR(zone->file);
+	}
+
+	if (zlo->block_size) {

Shouldn't this be:

	if (!zlo->block_size) {

?

Not a huge problem, but no need to repeatedly get the block size for all zones. Other than that, this is a nice cleanup!

Quoted 68 lines
drivers/block/zloop.c +13 -37
+		ret = zloop_get_block_size(zlo, zone);
+		if (ret)
+			return ret;
+	}
+
 	if (zone_no < zlo->nr_conv_zones) {
+		sector_t file_sectors;
+		struct kstat stat;
+
 		/* Conventional zone file. */
 		set_bit(ZLOOP_ZONE_CONV, &zone->flags);
 		zone->cond = BLK_ZONE_COND_NOT_WP;
 		zone->wp = U64_MAX;
 
-		zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/cnv-%06u",
-					zlo->base_dir, zlo->id, zone_no);
-		if (IS_ERR(zone->file)) {
-			pr_err("Failed to open zone %u file %s/%u/cnv-%06u (err=%ld)",
-			       zone_no, zlo->base_dir, zlo->id, zone_no,
-			       PTR_ERR(zone->file));
-			return PTR_ERR(zone->file);
-		}
-
-		if (!zlo->block_size) {
-			ret = zloop_get_block_size(zlo, zone);
-			if (ret)
-				return ret;
-		}
-
 		ret = vfs_getattr(&zone->file->f_path, &stat, STATX_SIZE, 0);
 		if (ret < 0) {
 			pr_err("Failed to get zone %u file stat\n", zone_no);
@@ -1163,30 +1167,13 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 			       zone_no, ret);
 			return ret;
 		}
-
-		return 0;
-	}
-
-	/* Sequential zone file. */
-	zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/seq-%06u",
-					 zlo->base_dir, zlo->id, zone_no);
-	if (IS_ERR(zone->file)) {
-		pr_err("Failed to open zone %u file %s/%u/seq-%06u (err=%ld)",
-		       zone_no, zlo->base_dir, zlo->id, zone_no,
-		       PTR_ERR(zone->file));
-		return PTR_ERR(zone->file);
-	}
-
-	if (!zlo->block_size) {
-		ret = zloop_get_block_size(zlo, zone);
-		if (ret)
-			return ret;
+	} else {
+		/* Sequential zone file. */
+		mutex_lock(&zone->lock);
+		ret = zloop_update_seq_zone(zlo, zone_no);
+		mutex_unlock(&zone->lock);
 	}
 
-	mutex_lock(&zone->lock);
-	ret = zloop_update_seq_zone(zlo, zone_no);
-	mutex_unlock(&zone->lock);
-
 	return ret;
 }
 
Signature · 2 lines
Damien Le Moal
Western Digital Research
author reviewer
#5 lore raw

PATCH 3/4 zloop: fput file after failed zone init

In reply to Christoph Hellwig

Clean up after failure in zloop_init_zone, as the caller only cleans up the zones before the current one.

Fixes eb0570c7df23 ("block: new zoned loop block device driver")
---
 drivers/block/zloop.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/block/zloop.c +10 -4
index 3dc484e3c700..f0aca9d43851 100644
@@ -1135,7 +1135,7 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 	if (zlo->block_size) {
 		ret = zloop_get_block_size(zlo, zone);
 		if (ret)
-			return ret;
+			goto out_fput;
 	}
 
 	if (zone_no < zlo->nr_conv_zones) {
@@ -1150,14 +1150,14 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 		ret = vfs_getattr(&zone->file->f_path, &stat, STATX_SIZE, 0);
 		if (ret < 0) {
 			pr_err("Failed to get zone %u file stat\n", zone_no);
-			return ret;
+			goto out_fput;
 		}
 		file_sectors = stat.size >> SECTOR_SHIFT;
 
 		if (restore && file_sectors != zlo->zone_size) {
 			pr_err("Invalid conventional zone %u file size (%llu sectors != %llu)\n",
 			       zone_no, file_sectors, zlo->zone_capacity);
-			return ret;
+			goto out_fput;
 		}
 
 		ret = vfs_truncate(&zone->file->f_path,
@@ -1165,15 +1165,21 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 		if (ret < 0) {
 			pr_err("Failed to truncate zone %u file (err=%d)\n",
 			       zone_no, ret);
-			return ret;
+			goto out_fput;
 		}
 	} else {
 		/* Sequential zone file. */
 		mutex_lock(&zone->lock);
 		ret = zloop_update_seq_zone(zlo, zone_no);
 		mutex_unlock(&zone->lock);
+		if (ret)
+			goto out_fput;
 	}
 
+	return 0;
+
+out_fput:
+	fput(zone->file);
 	return ret;
 }
 
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] zloop: fput file after failed zone init

Quoted 5 lines · Christoph Hellwig

Clean up after failure in zloop_init_zone, as the caller only cleans up the zones before the current one.

Fixes eb0570c7df23 ("block: new zoned loop block device driver")
Signature · 2 lines
Damien Le Moal
Western Digital Research
author reviewer
#7 lore raw

PATCH 4/4 zloop: check that the zone backing file support ->{read,write}_iter

In reply to Christoph Hellwig

I/O to backing files requires support for iter based read/write, so check for that upfront instead of dereferencing a NULL pointer later.

Fixes eb0570c7df23 ("block: new zoned loop block device driver")
---
 drivers/block/zloop.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/block/zloop.c +5 -0
index f0aca9d43851..65634a39b0bf 100644
@@ -1132,6 +1132,11 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 		return PTR_ERR(zone->file);
 	}
 
+	if (!zone->file->f_op->read_iter || !zone->file->f_op->write_iter) {
+		ret = -EINVAL;
+		goto out_fput;
+	}
+
 	if (zlo->block_size) {
 		ret = zloop_get_block_size(zlo, zone);
 		if (ret)
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] zloop: check that the zone backing file support ->{read,write}_iter

Quoted 6 lines · Christoph Hellwig

I/O to backing files requires support for iter based read/write, so check for that upfront instead of dereferencing a NULL pointer later.

Fixes eb0570c7df23 ("block: new zoned loop block device driver")
Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer Applied
#9 lore raw
In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

this series has misc fixes for zloop.

Diffstat:

 zloop.c |   80 ++++++++++++++++++++++++++++++----------------------------------
 1 file changed, 38 insertions(+), 42 deletions(-)

Applied, thanks!

[1/4] zloop: remove a duplicate call to zloop_get_block_size

      commit: 0835f4909553e78a97d1ac59ed6eb776b4f78c92
[2/4] zloop: share more code for opening a zone backing file
      commit: 5e9929e2f03c79574e76605e1a82509575db2d30
[3/4] zloop: fput file after failed zone init
      commit: 134ffb0755626c91af82fc7debc8b6f75f1f777e
[4/4] zloop: check that the zone backing file support ->{read,write}_iter
      commit: 0c10f8a1a7ae1502ea4ea7e13f222df89c28adf4

Best regards,

Signature · 1 line
Jens Axboe