Linux-bcache Archive mirror
 help / color / mirror / Atom feed
From: Xiaole He <hexiaole1994@126.com>
To: linux-bcache@vger.kernel.org
Cc: Xiaole He <hexiaole1994@126.com>, Xiaole He <hexiaole@kylinos.cn>
Subject: [PATCH] bcache-tools: fix incorrect id to find cache dev
Date: Sat, 29 Oct 2022 17:24:14 +0800	[thread overview]
Message-ID: <20221029092414.38548-1-hexiaole1994@126.com> (raw)

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


                 reply	other threads:[~2022-10-29 14:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221029092414.38548-1-hexiaole1994@126.com \
    --to=hexiaole1994@126.com \
    --cc=hexiaole@kylinos.cn \
    --cc=linux-bcache@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).