bcache patches for Linux v5.16 (first wave)
Subsystems (2)
cover bcache patches for Linux v5.16 (first wave)
Hi Jens,
This is the first wave bcache series for Linux v5.16. In this merge window, there is no large change set submitted, most of the patches are code clean up from Chao, Christoph and me. This time we have a new contributor Feng who provides a useful bug fix for dirty data size calculation during cache detaching.
Please take them and thanks in advance.
Coly Li
---
Chao Yu (1):
bcache: fix error info in register_bcache()
Christoph Hellwig (4):
bcache: remove the cache_dev_name field from struct cache
bcache: remove the backing_dev_name field from struct cached_dev
bcache: use bvec_kmap_local in bch_data_verify
bcache: remove bch_crc64_update
Coly Li (1):
bcache: reserve never used bits from bkey.high
Ding Senjie (1):
md: bcache: Fix spelling of 'acquire'
Lin Feng (1):
bcache: move calc_cached_dev_sectors to proper place on backing device
detach
drivers/md/bcache/bcache.h | 4 --- drivers/md/bcache/btree.c | 2 +- drivers/md/bcache/debug.c | 15 ++++---- drivers/md/bcache/io.c | 16 ++++----- drivers/md/bcache/request.c | 6 ++-- drivers/md/bcache/super.c | 72 ++++++++++++++++++------------------- drivers/md/bcache/sysfs.c | 2 +- drivers/md/bcache/util.h | 8 ----- include/uapi/linux/bcache.h | 4 +-- 9 files changed, 57 insertions(+), 72 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/8 md: bcache: Fix spelling of 'acquire'
From: Ding Senjie <[email protected]>
acqurie -> acquire
--- drivers/md/bcache/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +1 -1
@@ -2746,7 +2746,7 @@ static int bcache_reboot(struct notifier_block *n, unsigned long code, void *x)* The reason bch_register_lock is not held to call * bch_cache_set_stop() and bcache_device_stop() is to * avoid potential deadlock during reboot, because cache -* set or bcache device stopping process will acqurie +* set or bcache device stopping process will acquire * bch_register_lock too. * * We are safe here because bcache_is_reboot sets to
Signature · 1 line
2.31.1
PATCH 2/8 bcache: reserve never used bits from bkey.high
In reply to Coly LiThere sre 3 bits in member high of struct bkey are never used, and no plan to support them in future,
- HEADER_SIZE, start at bit 58, length 2 bits
- KEY_PINNED, start at bit 55, length 1 bit
No any kernel code, or user space tool references or accesses the three bits. Therefore it is possible and feasible to reserve the valuable bits from bkey.high. They can be used in future for other purpose.
--- include/uapi/linux/bcache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/uapi/linux/bcache.h +2 -2
@@ -43,9 +43,9 @@ static inline void SET_##name(struct bkey *k, unsigned int i, __u64 v) \#define KEY_MAX_U64S 8 KEY_FIELD(KEY_PTRS, high, 60, 3) -KEY_FIELD(HEADER_SIZE, high, 58, 2) +KEY_FIELD(__PAD0, high, 58, 2) KEY_FIELD(KEY_CSUM, high, 56, 2) -KEY_FIELD(KEY_PINNED, high, 55, 1) +KEY_FIELD(__PAD1, high, 55, 1) KEY_FIELD(KEY_DIRTY, high, 36, 1)KEY_FIELD (KEY_SIZE , high,20 ,KEY_SIZE_BITS )
Signature · 1 line
2.31.1
PATCH 3/8 bcache: fix error info in register_bcache()
In reply to Coly LiFrom: Chao Yu <[email protected]>
In register_bcache(), there are several cases we didn't set correct error info (return value and/or error message):
- if kzalloc() fails, it needs to return ENOMEM and print "cannot allocate memory";
- if register_cache() fails, it's better to propagate its return value rather than using default EINVAL.
--- drivers/md/bcache/super.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/md/bcache/super.c +10 -3
@@ -2613,8 +2613,11 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,if (SB_IS_BDEV (sb)) {struct cached_dev *dc =kzalloc (sizeof (*dc),GFP_KERNEL ); -if (!dc) +if (!dc) { + ret = -ENOMEM ; + err ="cannot allocate memory" ; goto out_put_sb_page; + }mutex_lock (&bch_register_lock); ret =register_bdev (sb, sb_disk, bdev, dc);
@@ -2625,11 +2628,15 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, }else {struct cache *ca =kzalloc (sizeof (*ca),GFP_KERNEL ); -if (!ca) +if (!ca) { + ret = -ENOMEM ; + err ="cannot allocate memory" ; goto out_put_sb_page; + }/* blkdev_put() will be called in bch_cache_release() */ -if (register_cache (sb, sb_disk, bdev, ca) !=0 ) + ret =register_cache (sb, sb_disk, bdev, ca); +if (ret) goto out_free_sb; }
Signature · 1 line
2.31.1
PATCH 4/8 bcache: move calc_cached_dev_sectors to proper place on backing device detach
In reply to Coly LiFrom: Lin Feng <[email protected]>
Calculation of cache_set's cached sectors is done by travelling cached_devs list as shown below:
static void calc_cached_dev_sectors(struct cache_set *c) {
...
list_for_each_entry(dc, &c->cached_devs, list)
sectors += bdev_sectors(dc->bdev);
c->cached_dev_sectors = sectors;
}But cached_dev won't be unlinked from c->cached_devs list until we call following list_move(&dc->list, &uncached_devices),
so previous fix in 'commit 46010141da6677b81cc77f9b47f8ac62bd1cbfd3 ("bcache: recal cached_dev_sectors on detach")' is wrong, now we move it to its right place.
--- drivers/md/bcache/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +1 -1
@@ -1153,9 +1153,9 @@ static void cached_dev_detach_finish(struct work_struct *w)mutex_lock (&bch_register_lock); -calc_cached_dev_sectors (dc->disk.c);bcache_device_detach (&dc->disk);list_move (&dc->list, &uncached_devices); +calc_cached_dev_sectors (dc->disk.c);clear_bit (BCACHE_DEV_DETACHING , &dc->disk.flags);clear_bit (BCACHE_DEV_UNLINK_DONE , &dc->disk.flags);
Signature · 1 line
2.31.1
PATCH 5/8 bcache: remove the cache_dev_name field from struct cache
In reply to Coly LiFrom: Christoph Hellwig <[email protected]>
Just use the %pg format specifier to print the name directly.
--- drivers/md/bcache/bcache.h | 2 -- drivers/md/bcache/io.c | 8 ++++---- drivers/md/bcache/super.c | 7 +++---- 3 files changed, 7 insertions(+), 10 deletions(-)
drivers/md/bcache/bcache.h +0 -2
@@ -470,8 +470,6 @@ struct cache {atomic_long_t meta_sectors_written;atomic_long_t btree_sectors_written;atomic_long_t sectors_written; - -char cache_dev_name[BDEVNAME_SIZE ]; };struct gc_stat {
drivers/md/bcache/io.c +4 -4
@@ -123,13 +123,13 @@ void bch_count_io_errors(struct cache *ca, errors >>=IO_ERROR_SHIFT ;if (errors < ca->set->error_limit) -pr_err ("%s: IO error on %s%s\n" , - ca->cache_dev_name, m, +pr_err ("%pg: IO error on %s%s\n" , + ca->bdev, m, is_read ?", recovering." :"." );else bch_cache_set_error (ca->set, -"%s: too many IO errors %s\n" , - ca->cache_dev_name, m); +"%pg: too many IO errors %s\n" , + ca->bdev, m); } }
drivers/md/bcache/super.c +3 -4
@@ -2334,7 +2334,7 @@ static int cache_alloc(struct cache *ca) err_free:module_put (THIS_MODULE );if (err) -pr_notice ("error %s: %s\n" , ca->cache_dev_name, err); +pr_notice ("error %pg: %s\n" , ca->bdev, err);return ret; }
@@ -2344,7 +2344,6 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk,const char *err =NULL ;/* must be set for any error case */ int ret =0 ; -bdevname (bdev, ca->cache_dev_name);memcpy (&ca->sb, sb,sizeof (struct cache_sb )); ca->bdev = bdev; ca->bdev->bd_holder = ca;
@@ -2386,14 +2385,14 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, goto out; } -pr_info ("registered cache device %s\n" , ca->cache_dev_name); +pr_info ("registered cache device %pg\n" , ca->bdev); out:kobject_put (&ca->kobj); err:if (err) -pr_notice ("error %s: %s\n" , ca->cache_dev_name, err); +pr_notice ("error %pg: %s\n" , ca->bdev, err);return ret; }
Signature · 1 line
2.31.1
PATCH 6/8 bcache: remove the backing_dev_name field from struct cached_dev
In reply to Coly LiFrom: Christoph Hellwig <[email protected]>
Just use the %pg format specifier to print the name directly.
--- drivers/md/bcache/bcache.h | 2 -- drivers/md/bcache/debug.c | 4 ++-- drivers/md/bcache/io.c | 8 +++---- drivers/md/bcache/request.c | 4 ++-- drivers/md/bcache/super.c | 48 ++++++++++++++++--------------------- drivers/md/bcache/sysfs.c | 2 +- 6 files changed, 29 insertions(+), 39 deletions(-)
drivers/md/bcache/bcache.h +0 -2
@@ -395,8 +395,6 @@ struct cached_dev {atomic_t io_errors;unsigned int error_limit;unsigned int offline_seconds; - -char backing_dev_name[BDEVNAME_SIZE ]; };enum alloc_reserve {
drivers/md/bcache/debug.c +2 -2
@@ -137,8 +137,8 @@ void bch_data_verify(struct cached_dev *dc, struct bio *bio) p2 + bv.bv_offset, bv.bv_len), dc->disk.c, -"verify failed at dev %s sector %llu" , - dc->backing_dev_name, +"verify failed at dev %pg sector %llu" , + dc->bdev, (uint64_t) bio->bi_iter.bi_sector);kunmap_atomic (p1);
drivers/md/bcache/io.c +4 -4
@@ -65,15 +65,15 @@ void bch_count_backing_io_errors(struct cached_dev *dc, struct bio *bio)* we shouldn't count failed REQ_RAHEAD bio to dc->io_errors. */ if (bio->bi_opf &REQ_RAHEAD ) { -pr_warn_ratelimited ("%s: Read-ahead I/O failed on backing device, ignore\n" , - dc->backing_dev_name); +pr_warn_ratelimited ("%pg: Read-ahead I/O failed on backing device, ignore\n" , + dc->bdev);return ; } errors =atomic_add_return (1 , &dc->io_errors);if (errors < dc->error_limit) -pr_err ("%s: IO error on backing device, unrecoverable\n" , - dc->backing_dev_name); +pr_err ("%pg: IO error on backing device, unrecoverable\n" , + dc->bdev);else bch_cached_dev_error (dc); }
drivers/md/bcache/request.c +2 -2
@@ -651,8 +651,8 @@ static void backing_request_endio(struct bio *bio)*/ if (unlikely (s->iop.writeback && bio->bi_opf &REQ_PREFLUSH )) { -pr_err ("Can't flush %s: returned bi_status %i\n" , - dc->backing_dev_name, bio->bi_status); +pr_err ("Can't flush %pg: returned bi_status %i\n" , + dc->bdev, bio->bi_status); }else {/* set to orig_bio->bi_status in bio_complete() */ s->iop.status = bio->bi_status;
drivers/md/bcache/super.c +20 -28
139 lines not on this page · raw message
drivers/md/bcache/sysfs.c +1 -1
@@ -271,7 +271,7 @@ SHOW(__bch_cached_dev) }if (attr == &sysfs_backing_dev_name) { -snprintf (buf,BDEVNAME_SIZE +1 ,"%s" , dc->backing_dev_name); +snprintf (buf,BDEVNAME_SIZE +1 ,"%pg" , dc->bdev);strcat (buf,"\n" );return strlen (buf); }
Signature · 1 line
2.31.1
PATCH 7/8 bcache: use bvec_kmap_local in bch_data_verify
In reply to Coly LiFrom: Christoph Hellwig <[email protected]>
Using local kmaps slightly reduces the chances to stray writes, and the bvec interface cleans up the code a little bit.
Also switch from page_address to bvec_kmap_local for cbv to be on the safe side and to avoid pointlessly poking into bvec internals.
--- drivers/md/bcache/debug.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/md/bcache/debug.c +5 -6
@@ -127,21 +127,20 @@ void bch_data_verify(struct cached_dev *dc, struct bio *bio) citer.bi_size =UINT_MAX ;bio_for_each_segment (bv, bio, iter) { -void *p1 =kmap_atomic (bv.bv_page); +void *p1 =bvec_kmap_local (&bv);void *p2; cbv =bio_iter_iovec (check, citer); - p2 =page_address (cbv.bv_page); + p2 =bvec_kmap_local (&cbv); -cache_set_err_on (memcmp (p1 + bv.bv_offset, - p2 + bv.bv_offset, - bv.bv_len), +cache_set_err_on (memcmp (p1, p2, bv.bv_len), dc->disk.c,"verify failed at dev %pg sector %llu" , dc->bdev, (uint64_t ) bio->bi_iter.bi_sector); -kunmap_atomic (p1); +kunmap_local (p2); +kunmap_local (p1);bio_advance_iter (check, &citer, bv.bv_len); }
Signature · 1 line
2.31.1
PATCH 8/8 bcache: remove bch_crc64_update
In reply to Coly LiFrom: Christoph Hellwig <[email protected]>
bch_crc64_update is an entirely pointless wrapper around crc64_be.
--- drivers/md/bcache/btree.c | 2 +- drivers/md/bcache/request.c | 2 +- drivers/md/bcache/util.h | 8 -------- 3 files changed, 2 insertions(+), 10 deletions(-)
drivers/md/bcache/btree.c +1 -1
@@ -141,7 +141,7 @@ static uint64_t btree_csum_set(struct btree *b, struct bset *i)uint64_t crc = b->key.ptr[0 ];void *data = (void *) i +8 , *end =bset_bkey_last (i); - crc =bch_crc64_update (crc, data, end - data); + crc =crc64_be (crc, data, end - data);return crc ^0xffffffffffffffffULL ; }
drivers/md/bcache/request.c +1 -1
@@ -46,7 +46,7 @@ static void bio_csum(struct bio *bio, struct bkey *k)bio_for_each_segment (bv, bio, iter) {void *d =kmap (bv.bv_page) + bv.bv_offset; - csum =bch_crc64_update (csum, d, bv.bv_len); + csum =crc64_be (csum, d, bv.bv_len);kunmap (bv.bv_page); }
drivers/md/bcache/util.h +0 -8
@@ -550,14 +550,6 @@ static inline uint64_t bch_crc64(const void *p, size_t len)return crc ^0xffffffffffffffffULL ; } -static inline uint64_t bch_crc64_update (uint64_t crc, -const void *p, -size_t len) -{ - crc =crc64_be (crc, p, len); -return crc; -} -/* * A stepwise-linear pseudo-exponential. This returns 1 << (x >> * frac_bits), with the less-significant bits filled in by linear
Signature · 1 line
2.31.1
Quoted 9 lines · Coly Li
This is the first wave bcache series for Linux v5.16. In this merge window, there is no large change set submitted, most of the patches are code clean up from Chao, Christoph and me. This time we have a new contributor Feng who provides a useful bug fix for dirty data size calculation during cache detaching.
Please take them and thanks in advance.
[...]
Applied, thanks!
[1/8] md: bcache: Fix spelling of 'acquire'
commit: a307e2abfc22880a3026bc2f2a997402b7c2d833
[2/8] bcache: reserve never used bits from bkey.high
commit: 0a2b3e363566c4cc8792d37c5e73b9d9295e075c
[3/8] bcache: fix error info in register_bcache()
commit: d55f7cb2e5c053010d2b527494da9bbb722a78ba
[4/8] bcache: move calc_cached_dev_sectors to proper place on backing device detach
commit: 0259d4498ba48454749ecfb9c81e892cdb8d1a32
[5/8] bcache: remove the cache_dev_name field from struct cache
commit: 7e84c2150731faec088ebfe33459f61d118b2497
[6/8] bcache: remove the backing_dev_name field from struct cached_dev
commit: 0f5cd7815f7f4bb1dd340a9aeb9b9d6a7c7eec22
[7/8] bcache: use bvec_kmap_local in bch_data_verify
commit: 00387bd21dac98f9e793294c895768d9e5441f82
[8/8] bcache: remove bch_crc64_update
commit: 39fa7a95552cc851029267b97c1317f1dea61cadBest regards,
Signature · 1 line
Jens Axboe