[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/4] linux-user: Add support for a group of btrfs ioctls used
From: |
Laurent Vivier |
Subject: |
Re: [PATCH 1/4] linux-user: Add support for a group of btrfs ioctls used for subvolumes |
Date: |
Wed, 29 Jul 2020 17:47:37 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 |
Le 09/07/2020 à 17:52, Filip Bozuta a écrit :
> This patch implements functionality of following ioctls:
>
> BTRFS_IOC_SUBVOL_CREATE - Creating a btrfs subvolume
>
> Create a btrfs subvolume. The subvolume is created using the ioctl's
> third argument which represents a pointer to a following structure
> type:
>
> struct btrfs_ioctl_vol_args {
> __s64 fd;
> char name[BTRFS_PATH_NAME_MAX + 1];
> };
>
> Before calling this ioctl, the fields of this structure should be filled
> with aproppriate values. The fd field represents the file descriptor
> value of the subvolume and the name field represents the subvolume
> path.
>
> BTRFS_IOC_SUBVOL_GETFLAGS - Getting subvolume flags
>
> Read the flags of the btrfs subvolume. The flags are read using
> the ioctl's third argument that is a pointer of __u64 (unsigned long).
> The third argument represents a bit mask that can be composed of following
> values:
> BTRFS_SUBVOL_RDONLY (1ULL << 1)
> BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)
> BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3)
> BTRFS_SUBVOL_SPEC_BY_ID (1ULL << 4)
>
> BTRFS_IOC_SUBVOL_SETFLAGS - Setting subvolume flags
>
> Set the flags of the btrfs subvolume. The flags are set using the
> ioctl's third argument that is a pointer of __u64 (unsigned long).
> The third argument represents a bit mask that can be composed of same
> values as in the case of previous ioctl (BTRFS_IOC_SUBVOL_GETFLAGS).
>
> BTRFS_IOC_SUBVOL_GETINFO - Getting subvolume information
>
> Read information about the subvolume. The subvolume information is
> returned in the ioctl's third argument which represents a pointer to
> a following structure type:
>
> struct btrfs_ioctl_get_subvol_info_args {
> /* Id of this subvolume */
> __u64 treeid;
>
> /* Name of this subvolume, used to get the real name at mount point */
> char name[BTRFS_VOL_NAME_MAX + 1];
>
> /*
> * Id of the subvolume which contains this subvolume.
> * Zero for top-level subvolume or a deleted subvolume.
> */
> __u64 parent_id;
>
> /*
> * Inode number of the directory which contains this subvolume.
> * Zero for top-level subvolume or a deleted subvolume
> */
> __u64 dirid;
>
> /* Latest transaction id of this subvolume */
> __u64 generation;
>
> /* Flags of this subvolume */
> __u64 flags;
>
> /* UUID of this subvolume */
> __u8 uuid[BTRFS_UUID_SIZE];
>
> /*
> * UUID of the subvolume of which this subvolume is a snapshot.
> * All zero for a non-snapshot subvolume.
> */
> __u8 parent_uuid[BTRFS_UUID_SIZE];
>
> /*
> * UUID of the subvolume from which this subvolume was received.
> * All zero for non-received subvolume.
> */
> __u8 received_uuid[BTRFS_UUID_SIZE];
>
> /* Transaction id indicating when change/create/send/receive happened */
> __u64 ctransid;
> __u64 otransid;
> __u64 stransid;
> __u64 rtransid;
> /* Time corresponding to c/o/s/rtransid */
> struct btrfs_ioctl_timespec ctime;
> struct btrfs_ioctl_timespec otime;
> struct btrfs_ioctl_timespec stime;
> struct btrfs_ioctl_timespec rtime;
>
> /* Must be zero */
> __u64 reserved[8];
> };
>
> All of the fields of this structure are filled after the ioctl call.
>
> Implementation notes:
>
> Ioctls BTRFS_IOC_SUBVOL_CREATE and BTRFS_IOC_SUBVOL_GETINFO have structure
> types as third arguments. That is the reason why a corresponding
> definition
> are added in file 'linux-user/syscall_types.h'.
>
> The line '#include <linux/btrfs.h>' is added in file
> 'linux-user/syscall.c' to
> recognise preprocessor definitions for these ioctls. Since the file
> "linux/btrfs.h"
> was added in the kernel version 3.9, it is enwrapped in an #ifdef
> statement
> with parameter CONFIG_BTRFS which is defined in 'configure' if the
> header file is present.
>
> Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
> ---
> configure | 9 +++++++++
> linux-user/ioctls.h | 15 +++++++++++++++
> linux-user/syscall.c | 3 +++
> linux-user/syscall_defs.h | 10 ++++++++++
> linux-user/syscall_types.h | 28 ++++++++++++++++++++++++++++
> 5 files changed, 65 insertions(+)
>
> diff --git a/configure b/configure
> index b969dee675..8b3b214031 100755
> --- a/configure
> +++ b/configure
> @@ -4945,6 +4945,12 @@ if check_include sys/kcov.h ; then
> kcov=yes
> fi
>
> +# check for btrfs filesystem support (kernel must be 3.9+)
> +btrfs=no
> +if check_include linux/btrfs.h ; then
> + btrfs=yes
> +fi
> +
> # If we're making warnings fatal, apply this to Sphinx runs as well
> sphinx_werror=""
> if test "$werror" = "yes"; then
> @@ -7057,6 +7063,9 @@ fi
> if test "$kcov" = "yes" ; then
> echo "CONFIG_KCOV=y" >> $config_host_mak
> fi
> +if test "$btrfs" = "yes" ; then
> + echo "CONFIG_BTRFS=y" >> $config_host_mak
> +fi
> if test "$inotify" = "yes" ; then
> echo "CONFIG_INOTIFY=y" >> $config_host_mak
> fi
> diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
> index 0defa1d8c1..544184ff95 100644
> --- a/linux-user/ioctls.h
> +++ b/linux-user/ioctls.h
> @@ -174,6 +174,21 @@
> IOCTL(FS_IOC32_GETVERSION, IOC_R, MK_PTR(TYPE_INT))
> IOCTL(FS_IOC32_SETVERSION, IOC_W, MK_PTR(TYPE_INT))
>
> +#ifdef BTRFS_IOC_SUBVOL_CREATE
> + IOCTL(BTRFS_IOC_SUBVOL_CREATE, IOC_W,
> + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args)))
> +#endif
> +#ifdef BTRFS_IOC_SUBVOL_GETFLAGS
> + IOCTL(BTRFS_IOC_SUBVOL_GETFLAGS, IOC_R, MK_PTR(TYPE_ULONGLONG))
> +#endif
> +#ifdef BTRFS_IOC_SUBVOL_SETFLAGS
> + IOCTL(BTRFS_IOC_SUBVOL_SETFLAGS, IOC_W, MK_PTR(TYPE_ULONGLONG))
> +#endif
> +#ifdef BTRFS_IOC_GET_SUBVOL_INFO
> + IOCTL(BTRFS_IOC_GET_SUBVOL_INFO, IOC_R,
> + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_subvol_info_args)))
> +#endif
> +
> #ifdef CONFIG_USBFS
> /* USB ioctls */
> IOCTL(USBDEVFS_CONTROL, IOC_RW,
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 05f03919ff..4a65b28999 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -112,6 +112,9 @@
> #include <linux/if_alg.h>
> #include <linux/rtc.h>
> #include <sound/asound.h>
> +#ifdef CONFIG_BTRFS
> +#include <linux/btrfs.h>
> +#endif
> #include "linux_loop.h"
> #include "uname.h"
>
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index 152ec637cb..c11bcc6ba9 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -967,6 +967,16 @@ struct target_rtc_pll_info {
> #define TARGET_FS_IOC32_GETVERSION TARGET_IOR('v', 1, int)
> #define TARGET_FS_IOC32_SETVERSION TARGET_IOW('v', 2, int)
>
> +/* btrfs ioctls */
> +#define TARGET_BTRFS_IOC_SUBVOL_CREATE
> TARGET_IOW(BTRFS_IOCTL_MAGIC, \
> + 14, struct
> btrfs_ioctl_vol_args)
> +#define TARGET_BTRFS_IOC_SUBVOL_GETFLAGS
> TARGET_IOR(BTRFS_IOCTL_MAGIC, \
> + 25, abi_ullong)
> +#define TARGET_BTRFS_IOC_SUBVOL_SETFLAGS
> TARGET_IOW(BTRFS_IOCTL_MAGIC, \
> + 26, abi_ullong)
> +#define TARGET_BTRFS_IOC_GET_SUBVOL_INFO
> TARGET_IOR(BTRFS_IOCTL_MAGIC, \
> + 60, struct
> btrfs_ioctl_get_subvol_info_args)
I think you should use TARGET_IOWU() and TARGET_IORU() that compute the
size of the structure according to the STRUCT_ definitions rather than
to the host structure definition.
With that changed:
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Thanks,
Laurent