From: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org
Cc: Marcos Paulo de Souza <mpdesouza@suse.com>
Subject: [PATCHv2 3/4] libbtrfsutil: Introduce btrfs_util_delete_subvolume_by_id_fd
Date: Fri, 7 Feb 2020 10:10:27 -0300 [thread overview]
Message-ID: <20200207131028.9977-4-marcos.souza.org@gmail.com> (raw)
In-Reply-To: <20200207131028.9977-1-marcos.souza.org@gmail.com>
From: Marcos Paulo de Souza <mpdesouza@suse.com>
This new function will use the new BTRFS_IOC_SNAP_DESTROY_V2 to delete a
subvolume using it's id. The parent_fs argument should be a mount point.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
libbtrfsutil/btrfsutil.h | 11 +++++++++++
libbtrfsutil/subvolume.c | 16 ++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/libbtrfsutil/btrfsutil.h b/libbtrfsutil/btrfsutil.h
index 0442af6e..c4cab2e0 100644
--- a/libbtrfsutil/btrfsutil.h
+++ b/libbtrfsutil/btrfsutil.h
@@ -488,6 +488,17 @@ enum btrfs_util_error btrfs_util_delete_subvolume_fd(int parent_fd,
const char *name,
int flags);
+/**
+ * btrfs_util_delete_subvolume_by_id_fd() - Delete a subvolume or snapshot using
+ * subvolume id.
+ * @path: Path of the subvolume to delete.
+ * @subvolid: Subvolume id of the subvolume or snapshot to be deleted.
+ *
+ * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure.
+ */
+enum btrfs_util_error btrfs_util_delete_subvolume_by_id_fd(int parent_fd,
+ uint64_t subvolid);
+
struct btrfs_util_subvolume_iterator;
/**
diff --git a/libbtrfsutil/subvolume.c b/libbtrfsutil/subvolume.c
index 3f8343a2..204a837b 100644
--- a/libbtrfsutil/subvolume.c
+++ b/libbtrfsutil/subvolume.c
@@ -1290,6 +1290,22 @@ PUBLIC enum btrfs_util_error btrfs_util_delete_subvolume_fd(int parent_fd,
return BTRFS_UTIL_OK;
}
+PUBLIC enum btrfs_util_error btrfs_util_delete_subvolume_by_id_fd(int parent_fd,
+ uint64_t subvolid)
+{
+ struct btrfs_ioctl_vol_args_v2 args = {};
+ int ret;
+
+ args.flags = BTRFS_SUBVOL_SPEC_BY_ID;
+ args.subvolid = subvolid;
+
+ ret = ioctl(parent_fd, BTRFS_IOC_SNAP_DESTROY_V2, &args);
+ if (ret == -1)
+ return BTRFS_UTIL_ERROR_SNAP_DESTROY_FAILED;
+
+ return BTRFS_UTIL_OK;
+}
+
PUBLIC void btrfs_util_destroy_subvolume_iterator(struct btrfs_util_subvolume_iterator *iter)
{
if (iter) {
--
2.24.0
next prev parent reply other threads:[~2020-02-07 13:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-07 13:10 [PATCHv2 0/4] btrfs-progs: Add BTRFS_IOC_SNAP_DESTROY_V2 support Marcos Paulo de Souza
2020-02-07 13:10 ` [PATCHv2 1/4] btrfs-progs: add IOC_SNAP_DESTROY_V2 to ioctl.h Marcos Paulo de Souza
2020-02-07 13:10 ` [PATCHv2 2/4] libbtrfsutil: " Marcos Paulo de Souza
2020-02-07 13:10 ` Marcos Paulo de Souza [this message]
2020-02-07 13:10 ` [PATCHv2 4/4] cmds: subvolume: Add --subvolid argument to subvol_delete Marcos Paulo de Souza
2020-03-03 18:34 ` [PATCHv2 0/4] btrfs-progs: Add BTRFS_IOC_SNAP_DESTROY_V2 support David Sterba
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=20200207131028.9977-4-marcos.souza.org@gmail.com \
--to=marcos.souza.org@gmail.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=mpdesouza@suse.com \
--cc=wqu@suse.com \
/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