linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] bcache-tools: recover the missing sb.csum for showing bcache device super block
@ 2021-01-03 16:24 Coly Li
  2021-01-03 16:24 ` [PATCH 2/3] bcache-tools: only call to_cache_sb() for bcache device in may_add_item() Coly Li
  2021-01-03 16:24 ` [PATCH 3/3] bcache-tools: improve column alignment for "bcache show -m" output Coly Li
  0 siblings, 2 replies; 3+ messages in thread
From: Coly Li @ 2021-01-03 16:24 UTC (permalink / raw)
  To: linux-bcache; +Cc: linux-block, Coly Li

Commit 2891723d7075 ("bcache-tools: define separated super block for
in-memory and on-disk format") does following change in detail_base(),
         strcpy(base->name, devname);
         base->magic = "ok";
         base->first_sector = SB_SECTOR;
 -       base->csum = sb.csum;
         base->version = sb.version;
because sb (in type struct cache_sb) doesn't have csum of the on-disk
super block anymore. The aftermath is base.csum was missing, and the
"show" command always display sb.csum as 0.

This patch recovers the csum value setting for base.csum, then command
"bcache show -d" may display the correct super block check sum.

Fixes: 2891723d7075 ("bcache-tools: define separated super block for in-memory and on-disk format")
Signed-off-by: Coly Li <colyli@suse.de>
---
 lib.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib.c b/lib.c
index b005eb5..340ddf3 100644
--- a/lib.c
+++ b/lib.c
@@ -487,6 +487,7 @@ int detail_dev(char *devname, struct bdev *bd, struct cdev *cd, int *type)
 	    sb.version == BCACHE_SB_VERSION_BDEV_WITH_OFFSET ||
 	    sb.version == BCACHE_SB_VERSION_BDEV_WITH_FEATURES) {
 		detail_base(devname, sb, &bd->base);
+		bd->base.csum = expected_csum;
 		bd->first_sector = BDEV_DATA_START_DEFAULT;
 		bd->cache_mode = BDEV_CACHE_MODE(&sb);
 		bd->cache_state = BDEV_STATE(&sb);
@@ -494,6 +495,7 @@ int detail_dev(char *devname, struct bdev *bd, struct cdev *cd, int *type)
 		   sb.version == BCACHE_SB_VERSION_CDEV_WITH_UUID ||
 		   sb.version == BCACHE_SB_VERSION_CDEV_WITH_FEATURES) {
 		detail_base(devname, sb, &cd->base);
+		cd->base.csum = expected_csum;
 		cd->first_sector = sb.bucket_size * sb.first_bucket;
 		cd->cache_sectors =
 		    sb.bucket_size * (sb.nbuckets - sb.first_bucket);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/3] bcache-tools: only call to_cache_sb() for bcache device in may_add_item()
  2021-01-03 16:24 [PATCH 1/3] bcache-tools: recover the missing sb.csum for showing bcache device super block Coly Li
@ 2021-01-03 16:24 ` Coly Li
  2021-01-03 16:24 ` [PATCH 3/3] bcache-tools: improve column alignment for "bcache show -m" output Coly Li
  1 sibling, 0 replies; 3+ messages in thread
From: Coly Li @ 2021-01-03 16:24 UTC (permalink / raw)
  To: linux-bcache; +Cc: linux-block, Coly Li

to_cache_sb() will print an error message "Unsupported super block
version" if the super block version is invalid. For non-bcache devices,
it is unnecessary to check version number and print bogus error messages.

This patch checks bcache_magic earlier in may_add_item(), and only calls
to_cache_sb() if the magic string matched. Then the non-bcache devices
can be skipped, and no more bogus error message observed.

Signed-off-by: Coly Li <colyli@suse.de>
---
 lib.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib.c b/lib.c
index 340ddf3..b8487db 100644
--- a/lib.c
+++ b/lib.c
@@ -343,32 +343,31 @@ int may_add_item(char *devname, struct list_head *head)
 {
 	struct cache_sb_disk sb_disk;
 	struct cache_sb sb;
+	char dev[512];
+	struct dev *tmp;
+	int ret;
 
 	if (strcmp(devname, ".") == 0 || strcmp(devname, "..") == 0)
 		return 0;
-	char dev[261];
 
 	sprintf(dev, "/dev/%s", devname);
 	int fd = open(dev, O_RDONLY);
-
 	if (fd == -1)
 		return 0;
+
 	if (pread(fd, &sb_disk, sizeof(sb_disk), SB_START) != sizeof(sb_disk)) {
 		close(fd);
 		return 0;
 	}
 
-	to_cache_sb(&sb, &sb_disk);
-
-	if (memcmp(sb.magic, bcache_magic, 16)) {
+	if (memcmp(sb_disk.magic, bcache_magic, 16)) {
 		close(fd);
 		return 0;
 	}
-	struct dev *tmp;
-	int ret;
 
-	tmp = (struct dev *) malloc(DEVLEN);
+	to_cache_sb(&sb, &sb_disk);
 
+	tmp = (struct dev *) malloc(DEVLEN);
 	tmp->csum = le64_to_cpu(sb_disk.csum);
 	ret = detail_base(dev, sb, tmp);
 	if (ret != 0) {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 3/3] bcache-tools: improve column alignment for "bcache show -m" output
  2021-01-03 16:24 [PATCH 1/3] bcache-tools: recover the missing sb.csum for showing bcache device super block Coly Li
  2021-01-03 16:24 ` [PATCH 2/3] bcache-tools: only call to_cache_sb() for bcache device in may_add_item() Coly Li
@ 2021-01-03 16:24 ` Coly Li
  1 sibling, 0 replies; 3+ messages in thread
From: Coly Li @ 2021-01-03 16:24 UTC (permalink / raw)
  To: linux-bcache; +Cc: linux-block, Coly Li

This patch improves the output column alignment for command
"bcache show -m". The changes are adding missing '\t' in printf
format strings.

Signed-off-by: Coly Li <colyli@suse.de>
---
 bcache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bcache.c b/bcache.c
index a0c5a67..234702b 100644
--- a/bcache.c
+++ b/bcache.c
@@ -195,7 +195,7 @@ int show_bdevs_detail(void)
 		fprintf(stderr, "Failed to list devices\n");
 		return ret;
 	}
-	printf("Name\t\tUuid\t\t\t\t\tCset_Uuid\t\t\t\tType\t\tState");
+	printf("Name\t\tUuid\t\t\t\t\tCset_Uuid\t\t\t\tType\t\t\tState");
 	printf("\t\t\tBname\t\tAttachToDev\tAttachToCset\n");
 	list_for_each_entry_safe(devs, n, &head, dev_list) {
 		printf("%s\t%s\t%s\t%lu", devs->name, devs->uuid,
@@ -217,7 +217,7 @@ int show_bdevs_detail(void)
 			printf(" (unknown)");
 			break;
 		}
-		printf("\t%-16s", devs->state);
+		printf("\t\t%-16s", devs->state);
 		printf("\t%-16s", devs->bname);
 		char attachdev[30];
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-03 16:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-03 16:24 [PATCH 1/3] bcache-tools: recover the missing sb.csum for showing bcache device super block Coly Li
2021-01-03 16:24 ` [PATCH 2/3] bcache-tools: only call to_cache_sb() for bcache device in may_add_item() Coly Li
2021-01-03 16:24 ` [PATCH 3/3] bcache-tools: improve column alignment for "bcache show -m" output Coly Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).