dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0004-linux-user-Add-support-for-btrfs-ioctls-used-to-mani.patch

Daniel P. Berrangé dc03f3
From ead1cdc1e4bb9fa4d09ca4d8af94c2687e7f5d36 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:26:56 +0200
Daniel P. Berrangé dc03f3
Subject: [PATCH 4/9] linux-user: Add support for btrfs ioctls used to
Daniel P. Berrangé dc03f3
 manipulate with devices
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_SCAN_DEV - Scanning device for a btrfs filesystem
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Scan a device for a btrfs filesystem. The device that is to
Daniel P. Berrangé dc03f3
    be scanned is passed in the ioctl's third argument which
Daniel P. Berrangé dc03f3
    represents a pointer to a 'struct ioc_vol_args' (which was
Daniel P. Berrangé dc03f3
    mentioned in a previous patch). Before calling this ioctl,
Daniel P. Berrangé dc03f3
    the name field of this structure should be filled with the
Daniel P. Berrangé dc03f3
    aproppriate name value which represents a path for the device.
Daniel P. Berrangé dc03f3
    If the device contains a btrfs filesystem, the ioctl returns 0,
Daniel P. Berrangé dc03f3
    otherwise a negative value is returned.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_ADD_DEV - Adding a device to a btrfs filesystem
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Add a device to a btrfs filesystem. The device that is to be
Daniel P. Berrangé dc03f3
    added is passed in the ioctl's third argument which represents
Daniel P. Berrangé dc03f3
    a pointer to a 'struct ioc_vol_args' (which was mentioned in
Daniel P. Berrangé dc03f3
    a previous patch). Before calling this ioctl, the name field of
Daniel P. Berrangé dc03f3
    this structure should be filled with the aproppriate name value
Daniel P. Berrangé dc03f3
    which represents a path for the device.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_RM_DEV - Removing a device from a btrfs filesystem
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Remove a device from a btrfs filesystem. The device that is to be
Daniel P. Berrangé dc03f3
    removed is passed in the ioctl's third argument which represents
Daniel P. Berrangé dc03f3
    a pointer to a 'struct ioc_vol_args' (which was mentioned in
Daniel P. Berrangé dc03f3
    a previous patch). Before calling this ioctl, the name field of
Daniel P. Berrangé dc03f3
    this structure should be filled with the aproppriate name value
Daniel P. Berrangé dc03f3
    which represents a path for the device.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_DEV_INFO - Getting information about a device
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Obtain information for device in a btrfs filesystem. The information
Daniel P. Berrangé dc03f3
    is gathered in the ioctl's third argument which represents a pointer
Daniel P. Berrangé dc03f3
    to a following structure type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_ioctl_dev_info_args {
Daniel P. Berrangé dc03f3
	__u64 devid;				/* in/out */
Daniel P. Berrangé dc03f3
	__u8 uuid[BTRFS_UUID_SIZE];		/* in/out */
Daniel P. Berrangé dc03f3
	__u64 bytes_used;			/* out */
Daniel P. Berrangé dc03f3
	__u64 total_bytes;			/* out */
Daniel P. Berrangé dc03f3
	__u64 unused[379];			/* pad to 4k */
Daniel P. Berrangé dc03f3
	__u8 path[BTRFS_DEVICE_PATH_NAME_MAX];	/* out */
Daniel P. Berrangé dc03f3
    };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Before calling this ioctl, field "devid" should be set with the id value
Daniel P. Berrangé dc03f3
    for the device for which the information is to be obtained. If this field
Daniel P. Berrangé dc03f3
    is not aproppriately set, the errno ENODEV ("No such device") is returned.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_GET_DEV_STATS - Getting device statistics
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Obtain stats informatin for device in a btrfs filesystem. The information
Daniel P. Berrangé dc03f3
    is gathered in the ioctl's third argument which represents a pointer to
Daniel P. Berrangé dc03f3
    a following structure type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_ioctl_get_dev_stats {
Daniel P. Berrangé dc03f3
	__u64 devid;				/* in */
Daniel P. Berrangé dc03f3
	__u64 nr_items;				/* in/out */
Daniel P. Berrangé dc03f3
	__u64 flags;				/* in/out */
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
	/* out values: */
Daniel P. Berrangé dc03f3
	__u64 values[BTRFS_DEV_STAT_VALUES_MAX];
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
	/*
Daniel P. Berrangé dc03f3
	 * This pads the struct to 1032 bytes. It was originally meant to pad to
Daniel P. Berrangé dc03f3
	 * 1024 bytes, but when adding the flags field, the padding calculation
Daniel P. Berrangé dc03f3
	 * was not adjusted.
Daniel P. Berrangé dc03f3
	 */
Daniel P. Berrangé dc03f3
	__u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX];
Daniel P. Berrangé dc03f3
    };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Before calling this ioctl, field "devid" should be set with the id value
Daniel P. Berrangé dc03f3
    for the device for which the information is to be obtained. If this field
Daniel P. Berrangé dc03f3
    is not aproppriately set, the errno ENODEV ("No such device") is returned.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_FORGET_DEV - Remove unmounted devices
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Search and remove all stale devices (devices which are not mounted).
Daniel P. Berrangé dc03f3
    The third ioctl argument is a pointer to a 'struct btrfs_ioctl_vol_args'.
Daniel P. Berrangé dc03f3
    The ioctl call will release all unmounted devices which match the path
Daniel P. Berrangé dc03f3
    which is specified in the "name" field of the structure. If an empty
Daniel P. Berrangé dc03f3
    path ("") is specified, all unmounted devices will be released.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
Implementation notes:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Ioctls BTRFS_IOC_DEV_INFO and BTRFS_IOC_GET_DEV_STATS use types
Daniel P. Berrangé dc03f3
    'struct btrfs_ioctl_dev_info_args' and ' struct btrfs_ioctl_get_dev_stats'
Daniel P. Berrangé dc03f3
    as third argument types. That is the reason why corresponding structure
Daniel P. Berrangé dc03f3
    definitions were added in file 'linux-user/syscall_types.h'.
Daniel P. Berrangé dc03f3
    Since the thunk type for 'struct ioc_vol_args' was already added in a
Daniel P. Berrangé dc03f3
    previous patch, the rest of the implementation was straightforward.
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-4-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        | 24 ++++++++++++++++++++++++
Daniel P. Berrangé dc03f3
 linux-user/syscall_defs.h  |  6 ++++++
Daniel P. Berrangé dc03f3
 linux-user/syscall_types.h | 24 +++++++++++++++++++++++-
Daniel P. Berrangé dc03f3
 3 files changed, 53 insertions(+), 1 deletion(-)
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 f33a99f8b6..55a6cbeca5 100644
Daniel P. Berrangé dc03f3
--- a/linux-user/ioctls.h
Daniel P. Berrangé dc03f3
+++ b/linux-user/ioctls.h
Daniel P. Berrangé dc03f3
@@ -178,6 +178,22 @@
Daniel P. Berrangé dc03f3
      IOCTL(BTRFS_IOC_SNAP_CREATE, IOC_W,
Daniel P. Berrangé dc03f3
            MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args)))
Daniel P. Berrangé dc03f3
 #endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_SCAN_DEV
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_SCAN_DEV, IOC_W,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_FORGET_DEV
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_FORGET_DEV, IOC_W,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_ADD_DEV
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_ADD_DEV, IOC_W,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_RM_DEV
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_RM_DEV, IOC_W,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
 #ifdef BTRFS_IOC_SUBVOL_CREATE
Daniel P. Berrangé dc03f3
      IOCTL(BTRFS_IOC_SUBVOL_CREATE, IOC_W,
Daniel P. Berrangé dc03f3
            MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args)))
Daniel P. Berrangé dc03f3
@@ -192,6 +208,14 @@
Daniel P. Berrangé dc03f3
 #ifdef BTRFS_IOC_SUBVOL_SETFLAGS
Daniel P. Berrangé dc03f3
      IOCTL(BTRFS_IOC_SUBVOL_SETFLAGS, IOC_W, MK_PTR(TYPE_ULONGLONG))
Daniel P. Berrangé dc03f3
 #endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_DEV_INFO
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_DEV_INFO, IOC_RW,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_dev_info_args)))
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
+#endif
Daniel P. Berrangé dc03f3
 #ifdef BTRFS_IOC_GET_SUBVOL_INFO
Daniel P. Berrangé dc03f3
      IOCTL(BTRFS_IOC_GET_SUBVOL_INFO, IOC_R,
Daniel P. Berrangé dc03f3
            MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_subvol_info_args)))
Daniel P. Berrangé dc03f3
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
Daniel P. Berrangé dc03f3
index a945e12547..4c7bfa0391 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
@@ -969,12 +969,18 @@ struct target_rtc_pll_info {
Daniel P. Berrangé dc03f3
 
Daniel P. Berrangé dc03f3
 /* btrfs ioctls */
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_SNAP_CREATE            TARGET_IOWU(BTRFS_IOCTL_MAGIC, 1)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_SCAN_DEV               TARGET_IOWU(BTRFS_IOCTL_MAGIC, 4)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_FORGET_DEV             TARGET_IOWU(BTRFS_IOCTL_MAGIC, 5)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_ADD_DEV                TARGET_IOWU(BTRFS_IOCTL_MAGIC, 10)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_RM_DEV                 TARGET_IOWU(BTRFS_IOCTL_MAGIC, 11)
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_SUBVOL_CREATE          TARGET_IOWU(BTRFS_IOCTL_MAGIC, 14)
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_SNAP_DESTROY           TARGET_IOWU(BTRFS_IOCTL_MAGIC, 15)
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_SUBVOL_GETFLAGS        TARGET_IOR(BTRFS_IOCTL_MAGIC, 25,\
Daniel P. Berrangé dc03f3
                                                            abi_ullong)
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_SUBVOL_SETFLAGS        TARGET_IOW(BTRFS_IOCTL_MAGIC, 26,\
Daniel P. Berrangé dc03f3
                                                            abi_ullong)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_DEV_INFO               TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 30)
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_SUBVOL_INFO        TARGET_IORU(BTRFS_IOCTL_MAGIC, 60)
Daniel P. Berrangé dc03f3
 
Daniel P. Berrangé dc03f3
 /* usb ioctls */
Daniel P. Berrangé dc03f3
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
Daniel P. Berrangé dc03f3
index 038cd7869b..ea6898979b 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
@@ -355,7 +355,9 @@ STRUCT(blkpg_partition,
Daniel P. Berrangé dc03f3
        MK_ARRAY(TYPE_CHAR, BLKPG_VOLNAMELTH)) /* volname */
Daniel P. Berrangé dc03f3
 
Daniel P. Berrangé dc03f3
 #if defined(BTRFS_IOC_SUBVOL_CREATE) || defined(BTRFS_IOC_SNAP_CREATE) || \
Daniel P. Berrangé dc03f3
-    defined(BTRFS_IOC_SNAP_DESTROY)
Daniel P. Berrangé dc03f3
+    defined(BTRFS_IOC_SNAP_DESTROY)  || defined(BTRFS_IOC_SCAN_DEV)  || \
Daniel P. Berrangé dc03f3
+    defined(BTRFS_IOC_FORGET_DEV)    || defined(BTRFS_IOC_ADD_DEV) || \
Daniel P. Berrangé dc03f3
+    defined(BTRFS_IOC_RM_DEV)        || defined(BTRFS_IOC_DEV_INFO)
Daniel P. Berrangé dc03f3
 STRUCT(btrfs_ioctl_vol_args,
Daniel P. Berrangé dc03f3
        TYPE_LONGLONG, /* fd */
Daniel P. Berrangé dc03f3
        MK_ARRAY(TYPE_CHAR, BTRFS_PATH_NAME_MAX + 1)) /* name */
Daniel P. Berrangé dc03f3
@@ -387,6 +389,26 @@ STRUCT(btrfs_ioctl_get_subvol_info_args,
Daniel P. Berrangé dc03f3
        MK_ARRAY(TYPE_ULONGLONG, 8)) /* reserved */
Daniel P. Berrangé dc03f3
 #endif
Daniel P. Berrangé dc03f3
 
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_DEV_INFO
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_dev_info_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* devid */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_CHAR, BTRFS_UUID_SIZE), /* uuid */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* bytes_used */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* total_bytes */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_ULONGLONG, 379), /* unused */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_CHAR, BTRFS_DEVICE_PATH_NAME_MAX)) /* path */
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_GET_DEV_STATS
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_get_dev_stats,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* devid */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* nr_items */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* flags */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_ULONGLONG, BTRFS_DEV_STAT_VALUES_MAX), /* values */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_ULONGLONG,
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(rtc_time,
Daniel P. Berrangé dc03f3
        TYPE_INT, /* tm_sec */
Daniel P. Berrangé dc03f3
        TYPE_INT, /* tm_min */
Daniel P. Berrangé dc03f3
-- 
Daniel P. Berrangé dc03f3
2.26.2
Daniel P. Berrangé dc03f3