[PATCHv2,3/4] libbtrfsutil: Introduce btrfs_util_delete_subvolume_by_id_fd
diff mbox series

Message ID 20200207131028.9977-4-marcos.souza.org@gmail.com
State New
Headers show
Series
  • btrfs-progs: Add BTRFS_IOC_SNAP_DESTROY_V2 support
Related show

Commit Message

Marcos Paulo de Souza Feb. 7, 2020, 1:10 p.m. UTC
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(+)

Patch
diff mbox series

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) {