[Libguestfs] [PATCH 1/3] mllib: add checking for btrfs subvolume

Maxim Perevedentsev
2016-07-07T15:04:14Z

This is needed to skip btrfs subvolumes from output
of list_filesystems where device is needed.
---
 mllib/common_utils.ml  | 10 ++++++++++
 mllib/common_utils.mli |  3 +++
 2 files changed, 13 insertions(+)

diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 77b9acd..30fc5cd 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -922,3 +922,13 @@ let inspect_mount_root g ?mount_opts_fn root
 let inspect_mount_root_ro    inspect_mount_root ~mount_opts_fn:(fun _ ->
"ro")
+
+let is_btrfs_subvolume g fs +  let device = g#mountable_device fs in
+  let subvol +    try
+      g#mountable_subvolume fs
+    with Guestfs.Error msg as exn ->
+      if g#last_errno () = Guestfs.Errno.errno_EINVAL then ""
+      else raise exn in
+  device <> "" && subvol <> ""
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index 5b0b9bb..d2ed30c 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -330,3 +330,6 @@ val inspect_mount_root : Guestfs.guestfs ->
?mount_opts_fn:(string -> string) ->
 val inspect_mount_root_ro : Guestfs.guestfs -> string -> unit
 (** Like [inspect_mount_root], but mounting every mount point as
     read-only. *)
+
+val is_btrfs_subvolume : Guestfs.guestfs -> string -> bool
+(** Checks if a filesystem is a btrfs subvolume. *)
--
1.8.3.1