Skip to contentSkip to conversation

bcache-tools: fix incorrect id to find cache dev

PATCH New Xiaole He 1 participant 1 message Oct 29, 2022 bcache (block layer cache)

lore
Share & tools
lore

Xiaole He

author
#0 lore raw

PATCH 1/1 bcache-tools: fix incorrect id to find cache dev

In function 'show_bdevs_detail' of 'show.c', the code traverse all bcache dev collected, then call 'cset_to_devname' for backing dev to get the name of the related cache dev into 'attachdev':

/* show.c begin */
...
INIT_LIST_HEAD(&head);
...
ret = list_bdevs(&head);
...

list_for_each_entry_safe(devs, n, &head, dev_list) {
    ...
    char attachdev[30];

    if (strlen(devs->attachuuid) == 36) {
        cset_to_devname(&head, devs->cset, attachdev);

...
/* show.c end */

/* lib.c begin */
int cset_to_devname(struct list_head *head, char *cset, char *devname)
...
/* lib.c end */

'cset_to_devname' scan all cache dev from the first argument 'head', and

 copy the name of the cache dev that matches against the second argument

'cset' into the third argument 'devname'.

But in above code, the passed second argument is the 'cset' of the backing dev itself, rather than the 'cset' of the cache dev.

This patch fix this error, call the 'cset_to_devname' with the second argument of 'devs->attachuuid', rather than 'devs->cset'. Otherwise, if the backing dev of the bcache is the first device in 'head', then the 'attachdev' can be a untouched status because the 'cset_to_devname' can not match any the 'cset' of cache dev with a 'cset' from backing dev, so
the 'printf' for 'attachdev' can be nonsense.

---
 show.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
show.c +1 -1
index abd068e..f69fd10 100644
@@ -73,7 +73,7 @@ int show_bdevs_detail(void)
 		char attachdev[30];
 
 		if (strlen(devs->attachuuid) == 36) {
-			cset_to_devname(&head, devs->cset, attachdev);
+			cset_to_devname(&head, devs->attachuuid, attachdev);
 		} else if (devs->version == BCACHE_SB_VERSION_CDEV
 			   || devs->version == BCACHE_SB_VERSION_CDEV_WITH_UUID
 			   || devs->version ==
Signature · 1 line
2.27.0