peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0008-linux-user-Add-support-for-btrfs-ioctls-used-to-mana.patch

Daniel P. Berrangé dc03f3
From d62c16ff35a17743c2a0f8ebfb39f84064afcb3c Mon Sep 17 00:00:00 2001
Daniel P. Berrangé dc03f3
From: Filip Bozuta <Filip.Bozuta@syrmia.com>
Daniel P. Berrangé dc03f3
Date: Thu, 3 Sep 2020 01:27:00 +0200
Daniel P. Berrangé dc03f3
Subject: [PATCH 8/9] linux-user: Add support for btrfs ioctls used to manage
Daniel P. Berrangé dc03f3
 quota
Daniel P. Berrangé dc03f3
MIME-Version: 1.0
Daniel P. Berrangé dc03f3
Content-Type: text/plain; charset=UTF-8
Daniel P. Berrangé dc03f3
Content-Transfer-Encoding: 8bit
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
This patch implements functionality for following ioctls:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_QUOTA_CTL - Enabling/Disabling quota support
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Enable or disable quota support for a btrfs filesystem. Quota
Daniel P. Berrangé dc03f3
    support is enabled or disabled using the ioctls third argument
Daniel P. Berrangé dc03f3
    which represents a pointer to a following type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_ioctl_quota_ctl_args {
Daniel P. Berrangé dc03f3
	__u64 cmd;
Daniel P. Berrangé dc03f3
	__u64 status;
Daniel P. Berrangé dc03f3
    };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Before calling this ioctl, the 'cmd' field should be filled
Daniel P. Berrangé dc03f3
    with one of the values 'BTRFS_QUOTA_CTL_ENABLE' (enabling quota)
Daniel P. Berrangé dc03f3
    'BTRFS_QUOTA_CTL_DISABLE' (disabling quota).
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_QGROUP_CREATE - Creating/Removing a subvolume quota group
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Create or remove a subvolume quota group. The subvolume quota
Daniel P. Berrangé dc03f3
    group is created or removed using the ioctl's third argument which
Daniel P. Berrangé dc03f3
    represents a pointer to a following type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_ioctl_qgroup_create_args {
Daniel P. Berrangé dc03f3
	__u64 create;
Daniel P. Berrangé dc03f3
	__u64 qgroupid;
Daniel P. Berrangé dc03f3
    };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Before calling this ioctl, the 'create' field should be filled
Daniel P. Berrangé dc03f3
    with the aproppriate value depending on if the user wants to
Daniel P. Berrangé dc03f3
    create or remove a quota group (0 for removing, everything else
Daniel P. Berrangé dc03f3
    for creating). Also, the 'qgroupid' field should be filled with
Daniel P. Berrangé dc03f3
    the value for the quota group id that is to be created.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_QGROUP_ASSIGN - Asigning or removing a quota group as child group
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Asign or remove a quota group as child quota group of another
Daniel P. Berrangé dc03f3
    group in the btrfs filesystem. The asignment is done using the
Daniel P. Berrangé dc03f3
    ioctl's third argument which represents a pointert to a following type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_ioctl_qgroup_assign_args {
Daniel P. Berrangé dc03f3
	__u64 assign;
Daniel P. Berrangé dc03f3
	__u64 src;
Daniel P. Berrangé dc03f3
	__u64 dst;
Daniel P. Berrangé dc03f3
    };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Before calling this ioctl, the 'assign' field should be filled with
Daniel P. Berrangé dc03f3
    the aproppriate value depending on if the user wants to asign or remove
Daniel P. Berrangé dc03f3
    a quota group as a child quota group of another group (0 for removing,
Daniel P. Berrangé dc03f3
    everythin else for asigning). Also, the 'src' and 'dst' fields should
Daniel P. Berrangé dc03f3
    be filled with the aproppriate quota group id values depending on which
Daniel P. Berrangé dc03f3
    quota group needs to asigned or removed as child quota group of another
Daniel P. Berrangé dc03f3
    group ('src' gets asigned or removed as child group of 'dst').
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_QGROUP_LIMIT - Limiting the size of a quota group
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Limit the size of a quota group. The size of the quota group is limited
Daniel P. Berrangé dc03f3
    with the ioctls third argument which represents a pointer to a following
Daniel P. Berrangé dc03f3
    type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_ioctl_qgroup_limit_args {
Daniel P. Berrangé dc03f3
	__u64	qgroupid;
Daniel P. Berrangé dc03f3
	struct btrfs_qgroup_limit lim;
Daniel P. Berrangé dc03f3
    };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Before calling this ioctl, the 'qgroup' id field should be filled with
Daniel P. Berrangé dc03f3
    aproppriate value of the quota group id for which the size is to be
Daniel P. Berrangé dc03f3
    limited. The second field is of following type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_qgroup_limit {
Daniel P. Berrangé dc03f3
	__u64	flags;
Daniel P. Berrangé dc03f3
	__u64	max_rfer;
Daniel P. Berrangé dc03f3
	__u64	max_excl;
Daniel P. Berrangé dc03f3
	__u64	rsv_rfer;
Daniel P. Berrangé dc03f3
	__u64	rsv_excl;
Daniel P. Berrangé dc03f3
    };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    The 'max_rfer' field should be filled with the size to which the quota
Daniel P. Berrangé dc03f3
    group should be limited. The 'flags' field can be used for passing
Daniel P. Berrangé dc03f3
    additional options and can have values which can be found on:
Daniel P. Berrangé dc03f3
    https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/btrfs.h#L67
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_QUOTA_RESCAN_STATUS - Checking status of running rescan operation
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Check status of a running rescan operation. The status is checked using
Daniel P. Berrangé dc03f3
    the ioctl's third argument which represents a pointer to a following type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_ioctl_quota_rescan_args {
Daniel P. Berrangé dc03f3
        __u64   flags;
Daniel P. Berrangé dc03f3
        __u64   progress;
Daniel P. Berrangé dc03f3
        __u64   reserved[6];
Daniel P. Berrangé dc03f3
    };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    If there is a rescan operation running, 'flags' field is set to 1, and
Daniel P. Berrangé dc03f3
    'progress' field is set to aproppriate value which represents the progress
Daniel P. Berrangé dc03f3
    of the operation.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_QUOTA_RESCAN - Starting a rescan operation
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Start ar rescan operation to Trash all quota groups and scan the metadata
Daniel P. Berrangé dc03f3
    again with the current config. Before calling this ioctl,
Daniel P. Berrangé dc03f3
    BTRFS_IOC_QUOTA_RESCAN_STATUS sould be run to check if there is already a
Daniel P. Berrangé dc03f3
    rescan operation runing. After that ioctl call, the received
Daniel P. Berrangé dc03f3
    'struct btrfs_ioctl_quota_rescan_args' should be than passed as this ioctls
Daniel P. Berrangé dc03f3
    third argument.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_QUOTA_RESCAN_WAIT - Waiting for a rescan operation to finish
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Wait until a rescan operation is finished (if there is a rescan operation
Daniel P. Berrangé dc03f3
    running). The third ioctls argument is ignored.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
Implementation notes:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Almost all of the ioctls in this patch use structure types as third arguments.
Daniel P. Berrangé dc03f3
    That is the reason why aproppriate thunk definitions were added in file
Daniel P. Berrangé dc03f3
    'syscall_types.h'.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Daniel P. Berrangé dc03f3
Tested-by: Daniel P. Berrangé <berrange@redhat.com>
Daniel P. Berrangé dc03f3
Message-Id: <20200823195014.116226-8-Filip.Bozuta@syrmia.com>
Daniel P. Berrangé dc03f3
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Daniel P. Berrangé dc03f3
---
Daniel P. Berrangé dc03f3
 linux-user/ioctls.h        | 27 +++++++++++++++++++++++++++
Daniel P. Berrangé dc03f3
 linux-user/syscall_defs.h  |  7 +++++++
Daniel P. Berrangé dc03f3
 linux-user/syscall_types.h | 29 +++++++++++++++++++++++++++++
Daniel P. Berrangé dc03f3
 3 files changed, 63 insertions(+)
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
Daniel P. Berrangé dc03f3
index 728880b9f3..882bfb3e88 100644
Daniel P. Berrangé dc03f3
--- a/linux-user/ioctls.h
Daniel P. Berrangé dc03f3
+++ b/linux-user/ioctls.h
Daniel P. Berrangé dc03f3
@@ -227,6 +227,33 @@
Daniel P. Berrangé dc03f3
      IOCTL(BTRFS_IOC_LOGICAL_INO, IOC_RW,
Daniel P. Berrangé dc03f3
            MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_logical_ino_args)))
Daniel P. Berrangé dc03f3
 #endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_QUOTA_CTL
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_QUOTA_CTL, IOC_RW,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_quota_ctl_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_QGROUP_ASSIGN
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_QGROUP_ASSIGN, IOC_W,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_qgroup_assign_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_QGROUP_CREATE
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_QGROUP_CREATE, IOC_W,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_qgroup_create_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_QGROUP_LIMIT
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_QGROUP_LIMIT, IOC_R,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_qgroup_limit_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_QUOTA_RESCAN
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_QUOTA_RESCAN, IOC_W,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_quota_rescan_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_QUOTA_RESCAN_STATUS
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_QUOTA_RESCAN_STATUS, IOC_R,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_quota_rescan_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_QUOTA_RESCAN_WAIT
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_QUOTA_RESCAN_WAIT, 0, TYPE_NULL)
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
 #ifdef BTRFS_IOC_GET_DEV_STATS
Daniel P. Berrangé dc03f3
      IOCTL(BTRFS_IOC_GET_DEV_STATS, IOC_RW,
Daniel P. Berrangé dc03f3
            MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_dev_stats)))
Daniel P. Berrangé dc03f3
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
Daniel P. Berrangé dc03f3
index 1d0bfb5479..10a7f91016 100644
Daniel P. Berrangé dc03f3
--- a/linux-user/syscall_defs.h
Daniel P. Berrangé dc03f3
+++ b/linux-user/syscall_defs.h
Daniel P. Berrangé dc03f3
@@ -985,6 +985,13 @@ struct target_rtc_pll_info {
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_DEV_INFO               TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 30)
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_INO_PATHS              TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 35)
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_LOGICAL_INO            TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 36)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_QUOTA_CTL              TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 40)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_QGROUP_ASSIGN          TARGET_IOWU(BTRFS_IOCTL_MAGIC, 41)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_QGROUP_CREATE          TARGET_IOWU(BTRFS_IOCTL_MAGIC, 42)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_QGROUP_LIMIT           TARGET_IORU(BTRFS_IOCTL_MAGIC, 43)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_QUOTA_RESCAN           TARGET_IOWU(BTRFS_IOCTL_MAGIC, 44)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_QUOTA_RESCAN_STATUS    TARGET_IORU(BTRFS_IOCTL_MAGIC, 45)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_QUOTA_RESCAN_WAIT      TARGET_IO(BTRFS_IOCTL_MAGIC, 46)
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_GET_DEV_STATS          TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 52)
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_GET_FEATURES           TARGET_IORU(BTRFS_IOCTL_MAGIC, 57)
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_SET_FEATURES           TARGET_IOWU(BTRFS_IOCTL_MAGIC, 57)
Daniel P. Berrangé dc03f3
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
Daniel P. Berrangé dc03f3
index 5566d101c2..d9b7106a69 100644
Daniel P. Berrangé dc03f3
--- a/linux-user/syscall_types.h
Daniel P. Berrangé dc03f3
+++ b/linux-user/syscall_types.h
Daniel P. Berrangé dc03f3
@@ -454,6 +454,35 @@ STRUCT(btrfs_ioctl_get_dev_stats,
Daniel P. Berrangé dc03f3
                 128 - 2 - BTRFS_DEV_STAT_VALUES_MAX)) /* unused */
Daniel P. Berrangé dc03f3
 #endif
Daniel P. Berrangé dc03f3
 
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_quota_ctl_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* cmd */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG) /* status */
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_quota_rescan_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* flags */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* progress */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_ULONGLONG, 6)) /* reserved */
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_qgroup_assign_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* assign */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* src */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG) /* dst */
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_qgroup_create_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* create */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG) /* qgroupid */
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_qgroup_limit,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* flags */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* max_rfer */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* max_excl */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* rsv_rfer */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG) /* rsv_excl */
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_qgroup_limit_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* qgroupid */
Daniel P. Berrangé dc03f3
+       MK_STRUCT(STRUCT_btrfs_qgroup_limit)) /* lim */
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
 STRUCT(btrfs_ioctl_feature_flags,
Daniel P. Berrangé dc03f3
        TYPE_ULONGLONG, /* compat_flags */
Daniel P. Berrangé dc03f3
        TYPE_ULONGLONG, /* compat_ro_flags */
Daniel P. Berrangé dc03f3
-- 
Daniel P. Berrangé dc03f3
2.26.2
Daniel P. Berrangé dc03f3