zloop fixes
Subsystems (2)
Christoph Hellwig
reviewerHi all,
this series fixes a bad bug and a few minor issues in the new zloop code queued up for 7.1.
Diffstat:
zloop.c | 123 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 59 insertions(+), 64 deletions(-)
Christoph Hellwig
reviewerPATCH 1/6 zloop: fix write pointer calculation in zloop_forget_cache
The write pointer is absolute and in sector units, so we need to convert it to a relative byte address first.
--- drivers/block/zloop.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/block/zloop.c +11 -2
@@ -1401,8 +1401,17 @@ static void zloop_forget_cache(struct zloop_device *zlo) zlo->disk->part0, ret);continue ; } -if (old_wp < zone->wp) -zloop_truncate (file, old_wp); + +if (old_wp > zone->wp) +continue ; +/* +* This should not happen, if we recored a full zone, it can't +* be active. +*/ +if (WARN_ON_ONCE (old_wp ==ULLONG_MAX )) +continue ; + +zloop_truncate (file, (old_wp - zone->start) <<SECTOR_SHIFT ); } }
Signature · 1 line
2.53.0
Re: [PATCH 1/6] zloop: fix write pointer calculation in zloop_forget_cache
Quoted 5 lines · Christoph Hellwig
The write pointer is absolute and in sector units, so we need to convert it to a relative byte address first.
Fixes c505448748f7 ("zloop: forget write cache on force removal")Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
Signature · 2 lines
Damien Le Moal Western Digital Research
Christoph Hellwig
reviewerPATCH 2/6 zloop: use vfs_truncate
In reply to Christoph HellwigWhile vfs_truncate does various extra checks that we don't really need, it is always better to use a VFS helper rather than open coding the logic.
--- drivers/block/zloop.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/block/zloop.c +2 -15
@@ -1363,20 +1363,6 @@ static int zloop_ctl_add(struct zloop_options *opts)return ret; } -static void zloop_truncate (struct file *file,loff_t pos) -{ -struct mnt_idmap *idmap =file_mnt_idmap (file); -struct dentry *dentry =file_dentry (file); -struct iattr newattrs; - - newattrs.ia_size = pos; - newattrs.ia_valid =ATTR_SIZE ; - -inode_lock (dentry->d_inode); -notify_change (idmap, dentry, &newattrs,NULL ); -inode_unlock (dentry->d_inode); -} -static void zloop_forget_cache (struct zloop_device *zlo) {unsigned int i;
@@ -1411,7 +1397,8 @@ static void zloop_forget_cache(struct zloop_device *zlo)if (WARN_ON_ONCE (old_wp ==ULLONG_MAX ))continue ; -zloop_truncate (file, (old_wp - zone->start) <<SECTOR_SHIFT ); +vfs_truncate (&file->f_path, + (old_wp - zone->start) <<SECTOR_SHIFT ); } }
Signature · 1 line
2.53.0
Re: [PATCH 2/6] zloop: use vfs_truncate
Quoted 5 lines · Christoph Hellwig
While
vfs_truncatedoes various extra checks that we don't really need, it is always better to use a VFS helper rather than open coding the logic.Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
Signature · 2 lines
Damien Le Moal Western Digital Research
Christoph Hellwig
reviewerPATCH 3/6 zloop: improve the unaligned write pointer warning
In reply to Christoph HellwigUse the IS_ALIGNED helper and avoid extra conversions, and tell the user what the unaligned size is.
--- drivers/block/zloop.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/zloop.c +3 -3
@@ -313,9 +313,9 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)return -EINVAL ; } -if (file_sectors & ((zlo->block_size >>SECTOR_SHIFT ) -1 )) { -pr_err ("Zone %u file size not aligned to block size %u\n" , - zone_no, zlo->block_size); +if (!IS_ALIGNED (stat.size, zlo->block_size)) { +pr_err ("Zone %u file size (%llu) not aligned to block size %u\n" , + zone_no, stat.size, zlo->block_size);return -EINVAL ; }
Signature · 1 line
2.53.0
Re: [PATCH 3/6] zloop: improve the unaligned write pointer warning
Quoted 4 lines · Christoph Hellwig
Use the
IS_ALIGNEDhelper and avoid extra conversions, and tell the user what the unaligned size is.Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
Signature · 2 lines
Damien Le Moal Western Digital Research
Christoph Hellwig
reviewerPATCH 4/6 zloop: set RQF_QUIET when completing requests on deleted devices
In reply to Christoph HellwigReduce the dmesg spam for tests that involve device deletion.
--- drivers/block/zloop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/block/zloop.c +3 -1
@@ -891,8 +891,10 @@ static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,struct zloop_cmd *cmd =blk_mq_rq_to_pdu (rq);struct zloop_device *zlo = rq->q->queuedata; -if (data_race (READ_ONCE (zlo->state)) == Zlo_deleting) +if (data_race (READ_ONCE (zlo->state)) == Zlo_deleting) { + rq->rq_flags |=RQF_QUIET ;return BLK_STS_IOERR ; + }/* * If we need to strongly order zone append operations, set the request
Signature · 1 line
2.53.0
Re: [PATCH 4/6] zloop: set RQF_QUIET when completing requests on deleted devices
Quoted 3 lines · Christoph Hellwig
Reduce the dmesg spam for tests that involve device deletion.
Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
Signature · 2 lines
Damien Le Moal Western Digital Research
Christoph Hellwig
reviewerPATCH 5/6 zloop: factor out zloop_mark_{full,empty} helpers
In reply to Christoph HellwigMove a few chunks of duplicated code into helpers.
--- drivers/block/zloop.c | 48 +++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 22 deletions(-)
drivers/block/zloop.c +26 -22
@@ -288,6 +288,24 @@ static bool zloop_do_open_zone(struct zloop_device *zlo, } } +static void zloop_mark_full (struct zloop_device *zlo,struct zloop_zone *zone) +{ +lockdep_assert_held (&zone->wp_lock); + +zloop_lru_remove_open_zone (zlo, zone); + zone->cond =BLK_ZONE_COND_FULL ; + zone->wp =ULLONG_MAX ; +} + +static void zloop_mark_empty (struct zloop_device *zlo,struct zloop_zone *zone) +{ +lockdep_assert_held (&zone->wp_lock); + +zloop_lru_remove_open_zone (zlo, zone); + zone->cond =BLK_ZONE_COND_EMPTY ; + zone->wp = zone->start; +} +static int zloop_update_seq_zone (struct zloop_device *zlo,unsigned int zone_no) {struct zloop_zone *zone = &zlo->zones[zone_no];
@@ -321,13 +339,9 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)spin_lock_irqsave (&zone->wp_lock, flags);if (!file_sectors) { -zloop_lru_remove_open_zone (zlo, zone); - zone->cond =BLK_ZONE_COND_EMPTY ; - zone->wp = zone->start; +zloop_mark_empty (zlo, zone); }else if (file_sectors == zlo->zone_capacity) { -zloop_lru_remove_open_zone (zlo, zone); - zone->cond =BLK_ZONE_COND_FULL ; - zone->wp =ULLONG_MAX ; +zloop_mark_full (zlo, zone); }else {if (zone->cond !=BLK_ZONE_COND_IMP_OPEN && zone->cond !=BLK_ZONE_COND_EXP_OPEN )
@@ -429,9 +443,7 @@ static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no) }spin_lock_irqsave (&zone->wp_lock, flags); -zloop_lru_remove_open_zone (zlo, zone); - zone->cond =BLK_ZONE_COND_EMPTY ; - zone->wp = zone->start; +zloop_mark_empty (zlo, zone);clear_bit (ZLOOP_ZONE_SEQ_ERROR , &zone->flags);spin_unlock_irqrestore (&zone->wp_lock, flags);
@@ -477,9 +489,7 @@ static int zloop_finish_zone(struct zloop_device *zlo, unsigned int zone_no) }spin_lock_irqsave (&zone->wp_lock, flags); -zloop_lru_remove_open_zone (zlo, zone); - zone->cond =BLK_ZONE_COND_FULL ; - zone->wp =ULLONG_MAX ; +zloop_mark_full (zlo, zone);clear_bit (ZLOOP_ZONE_SEQ_ERROR , &zone->flags);spin_unlock_irqrestore (&zone->wp_lock, flags);
@@ -616,11 +626,8 @@ static int zloop_seq_write_prep(struct zloop_cmd *cmd)*/ if (!is_append || !zlo->ordered_zone_append) { zone->wp += nr_sectors; -if (zone->wp == zone_end) { -zloop_lru_remove_open_zone (zlo, zone); - zone->cond =BLK_ZONE_COND_FULL ; - zone->wp =ULLONG_MAX ; - } +if (zone->wp == zone_end) +zloop_mark_full (zlo, zone); } out_unlock:spin_unlock_irqrestore (&zone->wp_lock, flags);
@@ -873,11 +880,8 @@ static bool zloop_set_zone_append_sector(struct request *rq) rq->__sector = zone->wp; zone->wp +=blk_rq_sectors (rq); -if (zone->wp >= zone_end) { -zloop_lru_remove_open_zone (zlo, zone); - zone->cond =BLK_ZONE_COND_FULL ; - zone->wp =ULLONG_MAX ; - } +if (zone->wp >= zone_end) +zloop_mark_full (zlo, zone);spin_unlock_irqrestore (&zone->wp_lock, flags);
Signature · 1 line
2.53.0
Re: [PATCH 5/6] zloop: factor out zloop_mark_{full,empty} helpers
Quoted 3 lines · Christoph Hellwig
Move a few chunks of duplicated code into helpers.
Signed-off-by Christoph Hellwig <[email protected]>
Nice cleanup !
Signature · 2 lines
Damien Le Moal Western Digital Research
Christoph Hellwig
reviewerPATCH 6/6 zloop: remove irq-safe locking
In reply to Christoph HellwigAll of zloop runs in user context, so drop the irq-safe locking.
--- drivers/block/zloop.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-)
drivers/block/zloop.c +15 -22
@@ -311,7 +311,6 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)struct zloop_zone *zone = &zlo->zones[zone_no];struct kstat stat;sector_t file_sectors; -unsigned long flags;int ret;lockdep_assert_held (&zone->lock);
@@ -337,7 +336,7 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)return -EINVAL ; } -spin_lock_irqsave (&zone->wp_lock, flags); +spin_lock (&zone->wp_lock);if (!file_sectors) {zloop_mark_empty (zlo, zone); }else if (file_sectors == zlo->zone_capacity) {
@@ -348,7 +347,7 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no) zone->cond =BLK_ZONE_COND_CLOSED ; zone->wp = zone->start + file_sectors; } -spin_unlock_irqrestore (&zone->wp_lock, flags); +spin_unlock (&zone->wp_lock);return 0 ; }
@@ -381,7 +380,6 @@ static int zloop_open_zone(struct zloop_device *zlo, unsigned int zone_no)static int zloop_close_zone (struct zloop_device *zlo,unsigned int zone_no) {struct zloop_zone *zone = &zlo->zones[zone_no]; -unsigned long flags;int ret =0 ;if (test_bit (ZLOOP_ZONE_CONV , &zone->flags))
@@ -400,13 +398,13 @@ static int zloop_close_zone(struct zloop_device *zlo, unsigned int zone_no)break ;case BLK_ZONE_COND_IMP_OPEN :case BLK_ZONE_COND_EXP_OPEN : -spin_lock_irqsave (&zone->wp_lock, flags); +spin_lock (&zone->wp_lock);zloop_lru_remove_open_zone (zlo, zone);if (zone->wp == zone->start) zone->cond =BLK_ZONE_COND_EMPTY ;else zone->cond =BLK_ZONE_COND_CLOSED ; -spin_unlock_irqrestore (&zone->wp_lock, flags); +spin_unlock (&zone->wp_lock);break ;case BLK_ZONE_COND_EMPTY :case BLK_ZONE_COND_FULL :
@@ -424,7 +422,6 @@ static int zloop_close_zone(struct zloop_device *zlo, unsigned int zone_no)static int zloop_reset_zone (struct zloop_device *zlo,unsigned int zone_no) {struct zloop_zone *zone = &zlo->zones[zone_no]; -unsigned long flags;int ret =0 ;if (test_bit (ZLOOP_ZONE_CONV , &zone->flags))
@@ -442,10 +439,10 @@ static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no) goto unlock; } -spin_lock_irqsave (&zone->wp_lock, flags); +spin_lock (&zone->wp_lock);zloop_mark_empty (zlo, zone);clear_bit (ZLOOP_ZONE_SEQ_ERROR , &zone->flags); -spin_unlock_irqrestore (&zone->wp_lock, flags); +spin_unlock (&zone->wp_lock); unlock:mutex_unlock (&zone->lock);
@@ -470,7 +467,6 @@ static int zloop_reset_all_zones(struct zloop_device *zlo)static int zloop_finish_zone (struct zloop_device *zlo,unsigned int zone_no) {struct zloop_zone *zone = &zlo->zones[zone_no]; -unsigned long flags;int ret =0 ;if (test_bit (ZLOOP_ZONE_CONV , &zone->flags))
@@ -488,10 +484,10 @@ static int zloop_finish_zone(struct zloop_device *zlo, unsigned int zone_no) goto unlock; } -spin_lock_irqsave (&zone->wp_lock, flags); +spin_lock (&zone->wp_lock);zloop_mark_full (zlo, zone);clear_bit (ZLOOP_ZONE_SEQ_ERROR , &zone->flags); -spin_unlock_irqrestore (&zone->wp_lock, flags); +spin_unlock (&zone->wp_lock); unlock:mutex_unlock (&zone->lock);
@@ -581,10 +577,9 @@ static int zloop_seq_write_prep(struct zloop_cmd *cmd)bool is_append =req_op (rq) ==REQ_OP_ZONE_APPEND ;struct zloop_zone *zone = &zlo->zones[zone_no];sector_t zone_end = zone->start + zlo->zone_capacity; -unsigned long flags;int ret =0 ; -spin_lock_irqsave (&zone->wp_lock, flags); +spin_lock (&zone->wp_lock);/* * Zone append operations always go at the current write pointer, but
@@ -630,7 +625,7 @@ static int zloop_seq_write_prep(struct zloop_cmd *cmd)zloop_mark_full (zlo, zone); } out_unlock: -spin_unlock_irqrestore (&zone->wp_lock, flags); +spin_unlock (&zone->wp_lock);return ret; }
@@ -868,13 +863,12 @@ static bool zloop_set_zone_append_sector(struct request *rq)struct zloop_zone *zone = &zlo->zones[zone_no];sector_t zone_end = zone->start + zlo->zone_capacity;sector_t nr_sectors =blk_rq_sectors (rq); -unsigned long flags; -spin_lock_irqsave (&zone->wp_lock, flags); +spin_lock (&zone->wp_lock);if (zone->cond ==BLK_ZONE_COND_FULL || zone->wp + nr_sectors > zone_end) { -spin_unlock_irqrestore (&zone->wp_lock, flags); +spin_unlock (&zone->wp_lock);return false; }
@@ -883,7 +877,7 @@ static bool zloop_set_zone_append_sector(struct request *rq)if (zone->wp >= zone_end)zloop_mark_full (zlo, zone); -spin_unlock_irqrestore (&zone->wp_lock, flags); +spin_unlock (&zone->wp_lock);return true; }
@@ -944,7 +938,6 @@ static int zloop_report_zones(struct gendisk *disk, sector_t sector,struct zloop_device *zlo = disk->private_data;struct blk_zone blkz = {};unsigned int first, i; -unsigned long flags;int ret; first =disk_zone_no (disk, sector);
@@ -968,9 +961,9 @@ static int zloop_report_zones(struct gendisk *disk, sector_t sector, blkz.start = zone->start; blkz.len = zlo->zone_size; -spin_lock_irqsave (&zone->wp_lock, flags); +spin_lock (&zone->wp_lock); blkz.wp = zone->wp; -spin_unlock_irqrestore (&zone->wp_lock, flags); +spin_unlock (&zone->wp_lock); blkz.cond = zone->cond;if (test_bit (ZLOOP_ZONE_CONV , &zone->flags)) { blkz.type =BLK_ZONE_TYPE_CONVENTIONAL ;
Signature · 1 line
2.53.0
Re: [PATCH 6/6] zloop: remove irq-safe locking
Quoted 3 lines · Christoph Hellwig
All of zloop runs in user context, so drop the irq-safe locking.
Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
Signature · 2 lines
Damien Le Moal Western Digital Research
Johannes Thumshirn
Reviewed-byQuoted 9 lines · Christoph Hellwig
Hi all,
this series fixes a bad bug and a few minor issues in the new zloop code queued up for 7.1.
Diffstat:
zloop.c | 123 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 59 insertions(+), 64 deletions(-)
Looks good,
Quoted 8 lines · Christoph Hellwig
this series fixes a bad bug and a few minor issues in the new zloop code queued up for 7.1.
Diffstat:
zloop.c | 123 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 59 insertions(+), 64 deletions(-)[...]
Applied, thanks!
[1/6] zloop: fix write pointer calculation in zloop_forget_cache
commit: 32be3c01c3b8e948a4326ab7e76c1c63dd3e27bc
[2/6] zloop: use vfs_truncate
commit: 14e0077911e3d5e11e94417861e700cbb521a107
[3/6] zloop: improve the unaligned write pointer warning
commit: 6466b211f797ae88073b5826dd764a6a98b67edb
[4/6] zloop: set RQF_QUIET when completing requests on deleted devices
commit: 5b680d7afc4a2fefa0b4f584462c7540de56e2e4
[5/6] zloop: factor out zloop_mark_{full,empty} helpers
commit: ec5c045f6cc879637cb52c9902d5fb7d419bdf47
[6/6] zloop: remove irq-safe locking
commit: 64b437c4a96ae088d46c7d9930c35e77ee1b5b21Best regards,
Signature · 1 line
Jens Axboe