All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] libmount: add mnt_fs_is_btrfs()
@ 2017-02-23 14:04 Petr Vorel
  2017-02-23 14:04 ` [PATCH 2/2] libmount: return tab entry for default node Petr Vorel
  2017-02-23 15:12 ` [PATCH 1/2] libmount: add mnt_fs_is_btrfs() Karel Zak
  0 siblings, 2 replies; 4+ messages in thread
From: Petr Vorel @ 2017-02-23 14:04 UTC (permalink / raw)
  To: util-linux; +Cc: Petr Vorel

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
I exported mnt_fs_is_btrfs() even it's not necessary for second patch as I
consider useful to have it available. I'd like to have
btrfs_get_default_subvol_id() exported as well.
---
 libmount/docs/libmount-sections.txt |  1 +
 libmount/src/fs.c                   | 11 +++++++++++
 libmount/src/libmount.h.in          |  1 +
 libmount/src/libmount.sym           |  7 ++++++-
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/libmount/docs/libmount-sections.txt b/libmount/docs/libmount-sections.txt
index 78d89cae7..65f774c2c 100644
--- a/libmount/docs/libmount-sections.txt
+++ b/libmount/docs/libmount-sections.txt
@@ -209,6 +209,7 @@ mnt_fs_get_usedsize
 mnt_fs_get_userdata
 mnt_fs_get_user_options
 mnt_fs_get_vfs_options
+mnt_fs_is_btrfs
 mnt_fs_is_kernel
 mnt_fs_is_netfs
 mnt_fs_is_pseudofs
diff --git a/libmount/src/fs.c b/libmount/src/fs.c
index 1c4ba1aab..e1bb9cde4 100644
--- a/libmount/src/fs.c
+++ b/libmount/src/fs.c
@@ -616,6 +616,17 @@ int mnt_fs_is_netfs(struct libmnt_fs *fs)
 }
 
 /**
+ * mnt_fs_is_btrfs:
+ * @fs: filesystem
+ *
+ * Returns: 1 if the filesystem is a btrfs fs type
+ */
+int mnt_fs_is_btrfs(struct libmnt_fs *fs)
+{
+	return !strcmp(fs->fstype, "btrfs");
+}
+
+/**
  * mnt_fs_get_fstype:
  * @fs: fstab/mtab/mountinfo entry pointer
  *
diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in
index f191a52fe..7196430ef 100644
--- a/libmount/src/libmount.h.in
+++ b/libmount/src/libmount.h.in
@@ -411,6 +411,7 @@ extern int mnt_fs_match_fstype(struct libmnt_fs *fs, const char *types);
 extern int mnt_fs_match_options(struct libmnt_fs *fs, const char *options);
 extern int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file);
 
+extern int mnt_fs_is_btrfs(struct libmnt_fs *fs);
 extern int mnt_fs_is_kernel(struct libmnt_fs *fs);
 extern int mnt_fs_is_swaparea(struct libmnt_fs *fs);
 extern int mnt_fs_is_netfs(struct libmnt_fs *fs);
diff --git a/libmount/src/libmount.sym b/libmount/src/libmount.sym
index f0210c240..72c9caa78 100644
--- a/libmount/src/libmount.sym
+++ b/libmount/src/libmount.sym
@@ -4,7 +4,7 @@
  *
  * Version info can't enforce this since we never change the SONAME.
  *
- * Copyright (C) 2011-2014 Karel Zak <kzak@redhat.com> 
+ * Copyright (C) 2011-2014 Karel Zak <kzak@redhat.com>
  */
 MOUNT_2.19 {
 global:
@@ -315,3 +315,8 @@ MOUNT_2.28 {
 	mnt_table_find_target_with_option;
 	mnt_fs_set_priority;
 } MOUNT_2.26;
+
+MOUNT_2.30 {
+global:
+	mnt_fs_is_btrfs;
+} MOUNT_2.28;
-- 
2.11.0


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

* [PATCH 2/2] libmount: return tab entry for default node
  2017-02-23 14:04 [PATCH 1/2] libmount: add mnt_fs_is_btrfs() Petr Vorel
@ 2017-02-23 14:04 ` Petr Vorel
  2017-02-23 15:12 ` [PATCH 1/2] libmount: add mnt_fs_is_btrfs() Karel Zak
  1 sibling, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2017-02-23 14:04 UTC (permalink / raw)
  To: util-linux; +Cc: Petr Vorel

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


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

* Re: [PATCH 1/2] libmount: add mnt_fs_is_btrfs()
  2017-02-23 14:04 [PATCH 1/2] libmount: add mnt_fs_is_btrfs() Petr Vorel
  2017-02-23 14:04 ` [PATCH 2/2] libmount: return tab entry for default node Petr Vorel
@ 2017-02-23 15:12 ` Karel Zak
  2017-02-23 18:15   ` Petr Vorel
  1 sibling, 1 reply; 4+ messages in thread
From: Karel Zak @ 2017-02-23 15:12 UTC (permalink / raw)
  To: Petr Vorel; +Cc: util-linux

On Thu, Feb 23, 2017 at 03:04:43PM +0100, Petr Vorel wrote:
>  libmount/docs/libmount-sections.txt |  1 +
>  libmount/src/fs.c                   | 11 +++++++++++
>  libmount/src/libmount.h.in          |  1 +
>  libmount/src/libmount.sym           |  7 ++++++-
>  4 files changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/libmount/docs/libmount-sections.txt b/libmount/docs/libmount-sections.txt
> index 78d89cae7..65f774c2c 100644
> --- a/libmount/docs/libmount-sections.txt
> +++ b/libmount/docs/libmount-sections.txt
> @@ -209,6 +209,7 @@ mnt_fs_get_usedsize
>  mnt_fs_get_userdata
>  mnt_fs_get_user_options
>  mnt_fs_get_vfs_options
> +mnt_fs_is_btrfs
>  mnt_fs_is_kernel
>  mnt_fs_is_netfs
>  mnt_fs_is_pseudofs
> diff --git a/libmount/src/fs.c b/libmount/src/fs.c
> index 1c4ba1aab..e1bb9cde4 100644
> --- a/libmount/src/fs.c
> +++ b/libmount/src/fs.c
> @@ -616,6 +616,17 @@ int mnt_fs_is_netfs(struct libmnt_fs *fs)
>  }
>  
>  /**
> + * mnt_fs_is_btrfs:
> + * @fs: filesystem
> + *
> + * Returns: 1 if the filesystem is a btrfs fs type
> + */
> +int mnt_fs_is_btrfs(struct libmnt_fs *fs)
> +{
> +	return !strcmp(fs->fstype, "btrfs");
> +}

 ???

 What's wrong with 

   strcmp(mnt_fs_get_fstype(fs, "btrfs"))

 why we need FS specific function exported by API?

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

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

* Re: [PATCH 1/2] libmount: add mnt_fs_is_btrfs()
  2017-02-23 15:12 ` [PATCH 1/2] libmount: add mnt_fs_is_btrfs() Karel Zak
@ 2017-02-23 18:15   ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2017-02-23 18:15 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

Hi Karel,

>  What's wrong with 

>    strcmp(mnt_fs_get_fstype(fs, "btrfs"))

>  why we need FS specific function exported by API?

I'm sorry I mixed two things. I thought that it could be useful for the others (with
btrfs_get_default_subvol_id()) as IMHO there is no btrfs C library atm [1].

Please forget on that, I'll post just v2 with just second patch.


Kind regards,
Petr

[1] https://btrfs.wiki.kernel.org/index.php/Project_ideas#Provide_a_library_covering_.27btrfs.27_functionality

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

end of thread, other threads:[~2017-02-23 18:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-23 14:04 [PATCH 1/2] libmount: add mnt_fs_is_btrfs() Petr Vorel
2017-02-23 14:04 ` [PATCH 2/2] libmount: return tab entry for default node Petr Vorel
2017-02-23 15:12 ` [PATCH 1/2] libmount: add mnt_fs_is_btrfs() Karel Zak
2017-02-23 18:15   ` Petr Vorel

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.