dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0009-linux-user-Add-support-for-btrfs-ioctls-used-to-scru.patch

Daniel P. Berrangé dc03f3
From 5695918e7c599f21fd6913a61160c482a0e41639 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:01 +0200
Daniel P. Berrangé dc03f3
Subject: [PATCH 9/9] linux-user: Add support for btrfs ioctls used to scrub a
Daniel P. Berrangé dc03f3
 filesystem
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_SCRUB - Starting a btrfs filesystem scrub
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Start a btrfs filesystem scrub. The third ioctls argument
Daniel P. Berrangé dc03f3
    is a pointer to a following type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_ioctl_scrub_args {
Daniel P. Berrangé dc03f3
	__u64 devid;				/* in */
Daniel P. Berrangé dc03f3
	__u64 start;				/* in */
Daniel P. Berrangé dc03f3
	__u64 end;				/* in */
Daniel P. Berrangé dc03f3
	__u64 flags;				/* in */
Daniel P. Berrangé dc03f3
	struct btrfs_scrub_progress progress;	/* out */
Daniel P. Berrangé dc03f3
	/* pad to 1k */
Daniel P. Berrangé dc03f3
	__u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
Daniel P. Berrangé dc03f3
    };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Before calling this ioctl, field 'devid' should be filled
Daniel P. Berrangé dc03f3
    with value that represents the device id of the btrfs filesystem
Daniel P. Berrangé dc03f3
    for which the scrub is to be started.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_SCRUB_CANCEL - Canceling scrub of a btrfs filesystem
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Cancel a btrfs filesystem scrub if it is running. The third
Daniel P. Berrangé dc03f3
    ioctls argument is ignored.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_SCRUB_PROGRESS - Getting status of a running scrub
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Read the status of a running btrfs filesystem scrub. The third
Daniel P. Berrangé dc03f3
    ioctls argument is a pointer to the above mentioned
Daniel P. Berrangé dc03f3
    'struct btrfs_ioctl_scrub_args'. Similarly as with 'BTRFS_IOC_SCRUB',
Daniel P. Berrangé dc03f3
    the 'devid' field should be filled with value that represents the
Daniel P. Berrangé dc03f3
    id of the btrfs device for which the scrub has started. The status
Daniel P. Berrangé dc03f3
    of a running scrub is returned in the field 'progress' which is
Daniel P. Berrangé dc03f3
    of type 'struct btrfs_scrub_progress' and its definition can be
Daniel P. Berrangé dc03f3
    found at:
Daniel P. Berrangé dc03f3
    https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/btrfs.h#L150
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
Implementation nots:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Ioctls in this patch use type 'struct btrfs_ioctl_scrub_args' as their
Daniel P. Berrangé dc03f3
    third argument. That is the reason why an aproppriate thunk type
Daniel P. Berrangé dc03f3
    definition is added in file '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-9-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        | 11 +++++++++++
Daniel P. Berrangé dc03f3
 linux-user/syscall_defs.h  |  3 +++
Daniel P. Berrangé dc03f3
 linux-user/syscall_types.h | 29 +++++++++++++++++++++++++++++
Daniel P. Berrangé dc03f3
 3 files changed, 43 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 882bfb3e88..e3bfe78774 100644
Daniel P. Berrangé dc03f3
--- a/linux-user/ioctls.h
Daniel P. Berrangé dc03f3
+++ b/linux-user/ioctls.h
Daniel P. Berrangé dc03f3
@@ -215,6 +215,17 @@
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_SCRUB
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_SCRUB, IOC_RW,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_scrub_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_SCRUB_CANCEL
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_SCRUB_CANCEL, 0, TYPE_NULL)
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_SCRUB_PROGRESS
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_SCRUB_PROGRESS, IOC_RW,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_scrub_args)))
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
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
Daniel P. Berrangé dc03f3
index 10a7f91016..969377d622 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
@@ -982,6 +982,9 @@ struct target_rtc_pll_info {
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_SCRUB                  TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 27)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_SCRUB_CANCEL           TARGET_IO(BTRFS_IOCTL_MAGIC, 28)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_SCRUB_PROGRESS         TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 29)
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
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
Daniel P. Berrangé dc03f3
index d9b7106a69..789723cfb9 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
@@ -421,6 +421,35 @@ STRUCT(btrfs_ioctl_ino_lookup_user_args,
Daniel P. Berrangé dc03f3
        MK_ARRAY(TYPE_CHAR, BTRFS_INO_LOOKUP_USER_PATH_MAX)) /* path */
Daniel P. Berrangé dc03f3
 #endif
Daniel P. Berrangé dc03f3
 
Daniel P. Berrangé dc03f3
+#if defined(BTRFS_IOC_SCRUB) || defined(BTRFS_IOC_SCRUB_PROGRESS)
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_scrub_progress,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* data_extents_scrubbed */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* tree_extents_scrubbed */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* data_bytes_scrubbed */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* tree_bytes_scrubbed */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* read_errors */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* csum_errors */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* verify_errors */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* no_csum */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* csum_discards */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* super_errors */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* malloc_errors */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* uncorrectable_errors */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* corrected_er */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* last_physical */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG) /* unverified_errors */
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_scrub_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* devid */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* start */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* end */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* flags */
Daniel P. Berrangé dc03f3
+       MK_STRUCT(STRUCT_btrfs_scrub_progress), /* progress */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_ULONGLONG,
Daniel P. Berrangé dc03f3
+                (1024 - 32 -
Daniel P. Berrangé dc03f3
+                 sizeof(struct btrfs_scrub_progress)) / 8)) /* unused */
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
-- 
Daniel P. Berrangé dc03f3
2.26.2
Daniel P. Berrangé dc03f3