linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bcache-tools: fix incorrect id to find cache dev
@ 2022-10-29  9:24 Xiaole He
  0 siblings, 0 replies; only message in thread
From: Xiaole He @ 2022-10-29  9:24 UTC (permalink / raw)
  To: linux-bcache; +Cc: Xiaole He, Xiaole He

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.

Signed-off-by: Xiaole He <hexiaole@kylinos.cn>
---
 show.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/show.c b/show.c
index abd068e..f69fd10 100644
--- a/show.c
+++ b/show.c
@@ -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 ==
-- 
2.27.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-29 14:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-29  9:24 [PATCH] bcache-tools: fix incorrect id to find cache dev Xiaole He

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).