dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0006-linux-user-Add-support-for-a-group-of-btrfs-inode-io.patch

Daniel P. Berrangé dc03f3
From 79116330e3eea392dec9a1f38fddf3449ad0195a 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:58 +0200
Daniel P. Berrangé dc03f3
Subject: [PATCH 6/9] linux-user: Add support for a group of btrfs inode ioctls
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 of following ioctls:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_INO_LOOKUP - Reading tree root id and path
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Read tree root id and path for a given file or directory.
Daniel P. Berrangé dc03f3
    The name and tree root id are returned in an ioctl's third
Daniel P. Berrangé dc03f3
    argument that represents a pointer to a following type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_ioctl_ino_lookup_args {
Daniel P. Berrangé dc03f3
	__u64 treeid;
Daniel P. Berrangé dc03f3
	__u64 objectid;
Daniel P. Berrangé dc03f3
	char name[BTRFS_INO_LOOKUP_PATH_MAX];
Daniel P. Berrangé dc03f3
    };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Before calling this ioctl, field 'objectid' should be filled
Daniel P. Berrangé dc03f3
    with the object id value for which the tree id and path are
Daniel P. Berrangé dc03f3
    to be read. Value 'BTRFS_FIRST_FREE_OBJECTID' represents the
Daniel P. Berrangé dc03f3
    object id for the first available btrfs object (directory or
Daniel P. Berrangé dc03f3
    file).
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_INO_PATHS - Reading paths to all files
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    Read path to all files with a certain inode number. The paths
Daniel P. Berrangé dc03f3
    are returned in the ioctl's third argument which represents
Daniel P. Berrangé dc03f3
    a pointer to a following type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
    struct btrfs_ioctl_ino_path_args {
Daniel P. Berrangé dc03f3
	__u64				inum;		/* in */
Daniel P. Berrangé dc03f3
	__u64				size;		/* in */
Daniel P. Berrangé dc03f3
	__u64				reserved[4];
Daniel P. Berrangé dc03f3
	/* struct btrfs_data_container	*fspath;	   out */
Daniel P. Berrangé dc03f3
	__u64				fspath;		/* out */
Daniel P. Berrangé dc03f3
     };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
     Before calling this ioctl, the 'inum' and 'size' field should
Daniel P. Berrangé dc03f3
     be filled with the aproppriate inode number and size of the
Daniel P. Berrangé dc03f3
     directory where file paths should be looked for. For now, the
Daniel P. Berrangé dc03f3
     paths are returned in an '__u64' (unsigned long long) value
Daniel P. Berrangé dc03f3
     'fspath'.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_LOGICAL_INO - Reading inode numbers
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
     Read inode numbers for files on a certain logical adress. The
Daniel P. Berrangé dc03f3
     inode numbers are returned in 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_logical_ino_args {
Daniel P. Berrangé dc03f3
	__u64				logical;	/* in */
Daniel P. Berrangé dc03f3
	__u64				size;		/* in */
Daniel P. Berrangé dc03f3
	__u64				reserved[3];	/* must be 0 for now */
Daniel P. Berrangé dc03f3
	__u64				flags;		/* in, v2 only */
Daniel P. Berrangé dc03f3
	/* struct btrfs_data_container	*inodes;	out   */
Daniel P. Berrangé dc03f3
	__u64				inodes;
Daniel P. Berrangé dc03f3
     };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
     Before calling this ioctl, the 'logical' and 'size' field should
Daniel P. Berrangé dc03f3
     be filled with the aproppriate logical adress and size of where
Daniel P. Berrangé dc03f3
     the inode numbers of files should be looked for. For now, the
Daniel P. Berrangé dc03f3
     inode numbers are returned in an '__u64' (unsigned long long)
Daniel P. Berrangé dc03f3
     value 'inodes'.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_LOGICAL_INO_V2 - Reading inode numbers
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
     Same as the above mentioned ioctl except that it allows passing
Daniel P. Berrangé dc03f3
     a flags 'BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET'.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
BTRFS_IOC_INO_LOOKUP_USER - Reading subvolume name and path
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
     Read name and path of a subvolume. The tree root id and
Daniel P. Berrangé dc03f3
     path are read in an ioctl's third argument which represents a
Daniel P. Berrangé dc03f3
     pointer to a following type:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
     struct btrfs_ioctl_ino_lookup_user_args {
Daniel P. Berrangé dc03f3
	/* in, inode number containing the subvolume of 'subvolid' */
Daniel P. Berrangé dc03f3
	__u64 dirid;
Daniel P. Berrangé dc03f3
	/* in */
Daniel P. Berrangé dc03f3
	__u64 treeid;
Daniel P. Berrangé dc03f3
	/* out, name of the subvolume of 'treeid' */
Daniel P. Berrangé dc03f3
	char name[BTRFS_VOL_NAME_MAX + 1];
Daniel P. Berrangé dc03f3
	/*
Daniel P. Berrangé dc03f3
	 * out, constructed path from the directory with which the ioctl is
Daniel P. Berrangé dc03f3
	 * called to dirid
Daniel P. Berrangé dc03f3
	 */
Daniel P. Berrangé dc03f3
	char path[BTRFS_INO_LOOKUP_USER_PATH_MAX];
Daniel P. Berrangé dc03f3
     };
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
     Before calling this ioctl, the 'dirid' and 'treeid' field should
Daniel P. Berrangé dc03f3
     be filled with aproppriate values which represent the inode number
Daniel P. Berrangé dc03f3
     of the directory that contains the subvolume and treeid of the
Daniel P. Berrangé dc03f3
     subvolume.
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
Implementation notes:
Daniel P. Berrangé dc03f3
Daniel P. Berrangé dc03f3
     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-6-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        | 20 ++++++++++++++++++++
Daniel P. Berrangé dc03f3
 linux-user/syscall_defs.h  |  5 +++++
Daniel P. Berrangé dc03f3
 linux-user/syscall_types.h | 32 ++++++++++++++++++++++++++++++++
Daniel P. Berrangé dc03f3
 3 files changed, 57 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 50fae1e33b..169f98f7a3 100644
Daniel P. Berrangé dc03f3
--- a/linux-user/ioctls.h
Daniel P. Berrangé dc03f3
+++ b/linux-user/ioctls.h
Daniel P. Berrangé dc03f3
@@ -202,6 +202,10 @@
Daniel P. Berrangé dc03f3
      IOCTL(BTRFS_IOC_SNAP_DESTROY, 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_INO_LOOKUP
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_INO_LOOKUP, IOC_RW,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_lookup_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
 #ifdef BTRFS_IOC_SUBVOL_GETFLAGS
Daniel P. Berrangé dc03f3
      IOCTL(BTRFS_IOC_SUBVOL_GETFLAGS, IOC_R, MK_PTR(TYPE_ULONGLONG))
Daniel P. Berrangé dc03f3
 #endif
Daniel P. Berrangé dc03f3
@@ -212,6 +216,14 @@
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_INO_PATHS
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_INO_PATHS, IOC_RW,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_path_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_LOGICAL_INO
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_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
@@ -228,10 +240,18 @@
Daniel P. Berrangé dc03f3
      IOCTL(BTRFS_IOC_GET_SUPPORTED_FEATURES, IOC_R,
Daniel P. Berrangé dc03f3
            MK_PTR(MK_ARRAY(MK_STRUCT(STRUCT_btrfs_ioctl_feature_flags), 3)))
Daniel P. Berrangé dc03f3
 #endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_LOGICAL_INO_V2
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_LOGICAL_INO_V2, 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_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
 #endif
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_INO_LOOKUP_USER
Daniel P. Berrangé dc03f3
+     IOCTL(BTRFS_IOC_INO_LOOKUP_USER, IOC_RW,
Daniel P. Berrangé dc03f3
+           MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_lookup_user_args)))
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
 
Daniel P. Berrangé dc03f3
 #ifdef CONFIG_USBFS
Daniel P. Berrangé dc03f3
   /* USB ioctls */
Daniel P. Berrangé dc03f3
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
Daniel P. Berrangé dc03f3
index 44811fdcbb..a6a9454b85 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
@@ -975,16 +975,21 @@ struct target_rtc_pll_info {
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_INO_LOOKUP             TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 18)
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_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_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
 #define TARGET_BTRFS_IOC_GET_SUPPORTED_FEATURES TARGET_IORU(BTRFS_IOCTL_MAGIC, 57)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_LOGICAL_INO_V2         TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 59)
Daniel P. Berrangé dc03f3
 #define TARGET_BTRFS_IOC_GET_SUBVOL_INFO        TARGET_IORU(BTRFS_IOCTL_MAGIC, 60)
Daniel P. Berrangé dc03f3
+#define TARGET_BTRFS_IOC_INO_LOOKUP_USER        TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 62)
Daniel P. Berrangé dc03f3
 
Daniel P. Berrangé dc03f3
 /* usb ioctls */
Daniel P. Berrangé dc03f3
 #define TARGET_USBDEVFS_CONTROL TARGET_IOWRU('U', 0)
Daniel P. Berrangé dc03f3
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
Daniel P. Berrangé dc03f3
index 925054cfd4..b84e14235f 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
@@ -389,6 +389,38 @@ 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_INO_LOOKUP
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_ino_lookup_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* treeid */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* objectid */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_CHAR, BTRFS_INO_LOOKUP_PATH_MAX)) /* name */
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_INO_PATHS
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_ino_path_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* inum */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* size */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_ULONGLONG, 4), /* reserved */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG) /* fspath */
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
+#if defined(BTRFS_IOC_LOGICAL_INO) || defined(BTRFS_IOC_LOGICAL_INO_V2)
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_logical_ino_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* logical */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* size */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_ULONGLONG, 3), /* reserved */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* flags */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG) /* inodes */
Daniel P. Berrangé dc03f3
+#endif
Daniel P. Berrangé dc03f3
+
Daniel P. Berrangé dc03f3
+#ifdef BTRFS_IOC_INO_LOOKUP_USER
Daniel P. Berrangé dc03f3
+STRUCT(btrfs_ioctl_ino_lookup_user_args,
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* dirid */
Daniel P. Berrangé dc03f3
+       TYPE_ULONGLONG, /* treeid */
Daniel P. Berrangé dc03f3
+       MK_ARRAY(TYPE_CHAR, BTRFS_VOL_NAME_MAX + 1), /* name */
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
 #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