btrfs_subvolume_get_default is for getting the default subvolume of a btrfs filesystem.
Signed-off-by: Hu Tao <[email protected]> --- daemon/btrfs.c | 38 ++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 9 +++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/daemon/btrfs.c b/daemon/btrfs.c index 754fdcd..471cfbd 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -545,6 +545,44 @@ do_btrfs_subvolume_set_default (int64_t id, const char *fs) return 0; } +int64_t +do_btrfs_subvolume_get_default (const char *mountpoint) +{ + const size_t MAX_ARGS = 64; + const char *argv[MAX_ARGS]; + size_t i = 0; + CLEANUP_FREE char *fs_buf = NULL; + CLEANUP_FREE char *err = NULL; + CLEANUP_FREE char *out = NULL; + int r; + int64_t ret; + + fs_buf = sysroot_path (mountpoint); + if (fs_buf == NULL) { + reply_with_perror ("malloc"); + return -1; + } + + ADD_ARG (argv, i, str_btrfs); + ADD_ARG (argv, i, "subvolume"); + ADD_ARG (argv, i, "get-default"); + ADD_ARG (argv, i, fs_buf); + ADD_ARG (argv, i, NULL); + + r = commandv (&out, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", mountpoint, err); + return -1; + } + r = xstrtol (out + 2, NULL, 10, &ret, NULL); + if (r != LONGINT_OK) { + reply_with_error ("%s: could not parse subvolume id: %s.", argv[0], out); + return -1; + } + + return ret; +} + int do_btrfs_filesystem_sync (const char *fs) { diff --git a/generator/actions.ml b/generator/actions.ml index a35fe50..2dcf938 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -12026,6 +12026,15 @@ Set readahead (in 512-byte sectors) for the device. This uses the L<blockdev(8)> command." }; + { defaults with + name = "btrfs_subvolume_get_default"; + style = RInt64 "id", [Pathname "mountpoint"], []; + proc_nr = Some 425; + optional = Some "btrfs"; camel_name = "BTRFSSubvolumeGetDefault"; + shortdesc = "get the default subvolume or snapshot of a filesystem"; + longdesc = "\ +Get the default subvolume or snapshot of a filesystem mounted at C<mountpoint>." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 9524ef4..5e4a522 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -424 +425 -- 1.9.3 _______________________________________________ Libguestfs mailing list [email protected] https://www.redhat.com/mailman/listinfo/libguestfs
