libbtrfsutil: add support for IOC_SNAP_DESTROY_V2

Add new ioctl and helpers to allow extended arguments to be passed to
subvolume deletion ioctl.  The parent_fs argument should be a mount
point.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Marcos Paulo de Souza 2020-02-07 10:10:26 -03:00 committed by David Sterba
parent f9fb36787a
commit 672e398eed
3 changed files with 33 additions and 1 deletions

View File

@ -36,12 +36,14 @@ struct btrfs_ioctl_vol_args {
#define BTRFS_DEVICE_PATH_NAME_MAX 1024
#define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3)
#define BTRFS_SUBVOL_SPEC_BY_ID (1ULL << 4)
#define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \
(BTRFS_SUBVOL_CREATE_ASYNC | \
BTRFS_SUBVOL_RDONLY | \
BTRFS_SUBVOL_QGROUP_INHERIT | \
BTRFS_DEVICE_SPEC_BY_ID)
BTRFS_DEVICE_SPEC_BY_ID | \
BTRFS_SUBVOL_SPEC_BY_ID)
#define BTRFS_FSID_SIZE 16
#define BTRFS_UUID_SIZE 16
@ -120,6 +122,7 @@ struct btrfs_ioctl_vol_args_v2 {
union {
char name[BTRFS_SUBVOL_NAME_MAX + 1];
__u64 devid;
__u64 subvolid;
};
};
@ -942,5 +945,7 @@ enum btrfs_err_code {
struct btrfs_ioctl_get_subvol_rootref_args)
#define BTRFS_IOC_INO_LOOKUP_USER _IOWR(BTRFS_IOCTL_MAGIC, 62, \
struct btrfs_ioctl_ino_lookup_user_args)
#define BTRFS_IOC_SNAP_DESTROY_V2 _IOW(BTRFS_IOCTL_MAGIC, 63, \
struct btrfs_ioctl_vol_args_v2)
#endif /* _LINUX_BTRFS_H */

View File

@ -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.
* @fd: File descriptor of the subvolume's parent directory.
* @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 fd,
uint64_t subvolid);
struct btrfs_util_subvolume_iterator;
/**

View File

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