All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: util-linux@vger.kernel.org
Cc: Petr Vorel <pvorel@suse.cz>
Subject: [PATCH 2/2] libmount: return tab entry for default node
Date: Thu, 23 Feb 2017 15:04:44 +0100	[thread overview]
Message-ID: <20170223140444.17916-2-pvorel@suse.cz> (raw)
In-Reply-To: <20170223140444.17916-1-pvorel@suse.cz>

This is useful for lsblk.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Hope it didn't break fsck, which uses btrfs_get_default_subvol_id() as well.
---
 libmount/src/tab.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/libmount/src/tab.c b/libmount/src/tab.c
index 8cf11814f..2865fd92a 100644
--- a/libmount/src/tab.c
+++ b/libmount/src/tab.c
@@ -936,6 +936,8 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
  * The 2nd, 3rd and 4th iterations are not performed when the @tb cache is not
  * set (see mnt_table_set_cache()).
  *
+ * For btrfs returns tab entry for default id.
+ *
  * Note that NULL is a valid source path; it will be replaced with "none". The
  * "none" is used in /proc/{mounts,self/mountinfo} for pseudo filesystems.
  *
@@ -958,9 +960,34 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
 
 	/* native paths */
 	mnt_reset_iter(&itr, direction);
+
 	while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
-		if (mnt_fs_streq_srcpath(fs, path))
+
+		if (mnt_fs_streq_srcpath(fs, path)) {
+#ifdef HAVE_BTRFS_SUPPORT
+			if (mnt_fs_is_btrfs(fs)) {
+				uint64_t default_id = btrfs_get_default_subvol_id(mnt_fs_get_target(fs));
+				uint64_t subvol_id;
+				char *val;
+				size_t len;
+
+				if (default_id == UINT64_MAX) {
+					DBG(TAB, ul_debug("not found btrfs volume setting"));
+					return fs;
+				}
+
+				if (mnt_fs_get_option(fs, "subvolid", &val, &len) == 0) {
+					if (mnt_parse_offset(val, len, &subvol_id)) {
+						DBG(TAB, ul_debugobj(tb, "failed to parse subvolid="));
+						continue;
+					}
+					if (subvol_id != default_id)
+						continue;
+				}
+			}
+#endif /* HAVE_BTRFS_SUPPORT */
 			return fs;
+		}
 		if (mnt_fs_get_tag(fs, NULL, NULL) == 0)
 			ntags++;
 	}
-- 
2.11.0


  reply	other threads:[~2017-02-23 14:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-23 14:04 [PATCH 1/2] libmount: add mnt_fs_is_btrfs() Petr Vorel
2017-02-23 14:04 ` Petr Vorel [this message]
2017-02-23 15:12 ` Karel Zak
2017-02-23 18:15   ` Petr Vorel

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=20170223140444.17916-2-pvorel@suse.cz \
    --to=pvorel@suse.cz \
    --cc=util-linux@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.