Skip to contentSkip to conversation

bcache patches for Linux v5.16 (first wave)

PATCH Applied Coly Li 2 participants 10 messages Oct 20, 2021

Subsystems (2)
lore
Share & tools
lore

Coly Li

author
#0 lore raw

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
author
#1 lore raw

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
index 185246a0d855..ab64b7762b6e 100644
@@ -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
author
#2 lore raw

PATCH 2/8 bcache: reserve never used bits from bkey.high

In reply to Coly Li

There 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
index cf7399f03b71..97413586195b 100644
@@ -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
author
#3 lore raw

PATCH 3/8 bcache: fix error info in register_bcache()

In reply to Coly Li

From: 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
index ab64b7762b6e..6bc5ee42a059 100644
@@ -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
author
#4 lore raw

PATCH 4/8 bcache: move calc_cached_dev_sectors to proper place on backing device detach

In reply to Coly Li

From: 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
index 6bc5ee42a059..05877177b768 100644
@@ -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
author
#5 lore raw

PATCH 5/8 bcache: remove the cache_dev_name field from struct cache

In reply to Coly Li

From: 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
index 5fc989a6d452..47ff9ecea2e2 100644
@@ -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
index e4388fe3ab7e..564357de7640 100644
@@ -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
index 05877177b768..01e6b0bce9c0 100644
@@ -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
author
#6 lore raw

PATCH 6/8 bcache: remove the backing_dev_name field from struct cached_dev

In reply to Coly Li

From: 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
index 47ff9ecea2e2..941685409c68 100644
@@ -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
index 116edda845c3..e803cad864be 100644
@@ -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
index 564357de7640..9c6f9ec55b72 100644
@@ -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
index 6d1de889baeb..64ce5788f80c 100644
@@ -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
index 05ac1d6fbbf3..1f0dce30fa75 100644
@@ -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
author
#7 lore raw

PATCH 7/8 bcache: use bvec_kmap_local in bch_data_verify

In reply to Coly Li

From: 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
index e803cad864be..6230dfdd9286 100644
@@ -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
author
#8 lore raw

PATCH 8/8 bcache: remove bch_crc64_update

In reply to Coly Li

From: 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
index 183a58c89377..88c573eeb598 100644
@@ -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
index 64ce5788f80c..3f10f8248304 100644
@@ -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
index bca4a7c97da7..50d1dc69d970 100644
@@ -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
maintainer Applied
#9 lore raw
In reply to Coly Li
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: 39fa7a95552cc851029267b97c1317f1dea61cad

Best regards,

Signature · 1 line
Jens Axboe