virtiofsd: Add support for FUSE_SYNCFS request
Subsystems (2)
v2 cover virtiofsd: Add support for FUSE_SYNCFS request
FUSE_SYNCFS allows the client to flush the host page cache. This isn't available in upstream linux yet, but the following tree can be used to test:
https://gitlab.com/gkurz/linux/-/tree/virtio-fs-sync
v2: - based on new version of FUSE_SYNCFS
https://listman.redhat.com/archives/virtio-fs/2021-April/msg00166.html
- propagate syncfs() errors to client (Vivek)
Greg Kurz (2):
Update linux headers to 5.12-rc8 + FUSE_SYNCFS
virtiofsd: Add support for FUSE_SYNCFS request
include/standard-headers/drm/drm_fourcc.h | 23 ++++- include/standard-headers/linux/ethtool.h | 54 ++++++----- include/standard-headers/linux/fuse.h | 13 ++- include/standard-headers/linux/input.h | 2 +- .../standard-headers/rdma/vmw_pvrdma-abi.h | 7 ++ linux-headers/asm-generic/unistd.h | 4 +- linux-headers/asm-mips/unistd_n32.h | 1 + linux-headers/asm-mips/unistd_n64.h | 1 + linux-headers/asm-mips/unistd_o32.h | 1 + linux-headers/asm-powerpc/kvm.h | 2 + linux-headers/asm-powerpc/unistd_32.h | 1 + linux-headers/asm-powerpc/unistd_64.h | 1 + linux-headers/asm-s390/unistd_32.h | 1 + linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 1 + linux-headers/asm-x86/unistd_32.h | 1 + linux-headers/asm-x86/unistd_64.h | 1 + linux-headers/asm-x86/unistd_x32.h | 1 + linux-headers/linux/kvm.h | 89 +++++++++++++++++++ linux-headers/linux/vfio.h | 27 ++++++ tools/virtiofsd/fuse_lowlevel.c | 19 ++++ tools/virtiofsd/fuse_lowlevel.h | 13 +++ tools/virtiofsd/passthrough_ll.c | 29 ++++++ tools/virtiofsd/passthrough_seccomp.c | 1 + 24 files changed, 267 insertions(+), 27 deletions(-)
Signature · 1 line
2.26.3
PATCH v2 1/2 Update linux headers to 5.12-rc8 + FUSE_SYNCFS
NOT YET IN UPSTREAM LINUX. DO NOT MERGE.
--- include/standard-headers/drm/drm_fourcc.h | 23 ++++- include/standard-headers/linux/ethtool.h | 54 ++++++----- include/standard-headers/linux/fuse.h | 13 ++- include/standard-headers/linux/input.h | 2 +- .../standard-headers/rdma/vmw_pvrdma-abi.h | 7 ++ linux-headers/asm-generic/unistd.h | 4 +- linux-headers/asm-mips/unistd_n32.h | 1 + linux-headers/asm-mips/unistd_n64.h | 1 + linux-headers/asm-mips/unistd_o32.h | 1 + linux-headers/asm-powerpc/kvm.h | 2 + linux-headers/asm-powerpc/unistd_32.h | 1 + linux-headers/asm-powerpc/unistd_64.h | 1 + linux-headers/asm-s390/unistd_32.h | 1 + linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 1 + linux-headers/asm-x86/unistd_32.h | 1 + linux-headers/asm-x86/unistd_64.h | 1 + linux-headers/asm-x86/unistd_x32.h | 1 + linux-headers/linux/kvm.h | 89 +++++++++++++++++++ linux-headers/linux/vfio.h | 27 ++++++ 20 files changed, 205 insertions(+), 27 deletions(-)
include/standard-headers/drm/drm_fourcc.h +21 -2
@@ -526,6 +526,25 @@ extern "C" {*/ #define I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS fourcc_mod_code(INTEL, 7) +/* +* Intel Color Control Surface with Clear Color (CCS) for Gen-12 render +* compression. +* +* The main surface is Y-tiled and is at plane index 0 whereas CCS is linear +* and at index 1. The clear color is stored at index 2, and the pitch should +* be ignored. The clear color structure is 256 bits. The first 128 bits +* represents Raw Clear Color Red, Green, Blue and Alpha color each represented +* by 32 bits. The raw clear color is consumed by the 3d engine and generates +* the converted clear color of size 64 bits. The first 32 bits store the Lower +* Converted Clear Color value and the next 32 bits store the Higher Converted +* Clear Color value when applicable. The Converted Clear Color values are +* consumed by the DE. The last 64 bits are used to store Color Discard Enable +* and Depth Clear Value Valid which are ignored by the DE. A CCS cache line +* corresponds to an area of 4x1 tiles in the main surface. The main surface +* pitch is required to be a multiple of 4 tile widths. +*/ +#define I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC fourcc_mod_code(INTEL, 8) +/* * Tiled, NV12MT, grouped in 64 (pixels) x 32 (lines) -sized macroblocks *
@@ -1035,9 +1054,9 @@ drm_fourcc_canonicalize_nvidia_format_mod(uint64_t modifier)* Not all combinations are valid, and different SoCs may support different * combinations of layout and options. */ -#define __fourcc_mod_amlogic_layout_mask 0xf +#define __fourcc_mod_amlogic_layout_mask 0xff#define __fourcc_mod_amlogic_options_shift 8 -#define __fourcc_mod_amlogic_options_mask 0xf +#define __fourcc_mod_amlogic_options_mask 0xff#define DRM_FORMAT_MOD_AMLOGIC_FBC (__layout, __options) \ fourcc_mod_code(AMLOGIC, \
include/standard-headers/linux/ethtool.h +33 -21
169 lines not on this page · raw message
include/standard-headers/linux/fuse.h +11 -2
@@ -179,6 +179,9 @@* 7.33 * - add FUSE_HANDLE_KILLPRIV_V2, FUSE_WRITE_KILL_SUIDGID, FATTR_KILL_SUIDGID * - add FUSE_OPEN_KILL_SUIDGID +* +* 7.34 +* - add FUSE_SYNCFS */ #ifndef _LINUX_FUSE_H
@@ -210,7 +213,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 33 +#define FUSE_KERNEL_MINOR_VERSION 34/** The node ID of the root inode */ #define FUSE_ROOT_ID 1
@@ -495,6 +498,7 @@ enum fuse_opcode {FUSE_COPY_FILE_RANGE =47 ,FUSE_SETUPMAPPING =48 ,FUSE_REMOVEMAPPING =49 , +FUSE_SYNCFS =50 ,/* CUSE specific operations */ CUSE_INIT = 4096,
@@ -899,7 +903,8 @@ struct fuse_notify_retrieve_in { };/* Device ioctls: */ -#define FUSE_DEV_IOC_CLONE _IOR(229, 0, uint32_t) +#define FUSE_DEV_IOC_MAGIC 229 +#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)struct fuse_lseek_in {uint64_t fh;
@@ -952,4 +957,8 @@ struct fuse_removemapping_one {#define FUSE_REMOVEMAPPING_MAX_ENTRY \ (PAGE_SIZE / sizeof(struct fuse_removemapping_one)) +struct fuse_syncfs_in { +uint64_t flags; +}; +#endif /* _LINUX_FUSE_H */
include/standard-headers/linux/input.h +1 -1
@@ -81,7 +81,7 @@ struct input_id {* in units per radian. * When INPUT_PROP_ACCELEROMETER is set the resolution changes. * The main axes (ABS_X, ABS_Y, ABS_Z) are then reported in -* in units per g (units/g) and in units per degree per second +* units per g (units/g) and in units per degree per second * (units/deg/s) for rotational axes (ABS_RX, ABS_RY, ABS_RZ). */ struct input_absinfo {
include/standard-headers/rdma/vmw_pvrdma-abi.h +7 -0
@@ -133,6 +133,13 @@ enum pvrdma_wc_flags { PVRDMA_WC_FLAGS_MAX = PVRDMA_WC_WITH_NETWORK_HDR_TYPE, }; +enum pvrdma_network_type { +PVRDMA_NETWORK_IB , +PVRDMA_NETWORK_ROCE_V1 =PVRDMA_NETWORK_IB , +PVRDMA_NETWORK_IPV4 , +PVRDMA_NETWORK_IPV6 +}; +struct pvrdma_alloc_ucontext_resp {uint32_t qp_tab_size;uint32_t reserved;
linux-headers/asm-generic/unistd.h +3 -1
@@ -861,9 +861,11 @@ __SYSCALL(__NR_faccessat2, sys_faccessat2) __SYSCALL(__NR_process_madvise, sys_process_madvise)#define __NR_epoll_pwait2 441 __SC_COMP(__NR_epoll_pwait2, sys_epoll_pwait2, compat_sys_epoll_pwait2) +#define __NR_mount_setattr 442 +__SYSCALL(__NR_mount_setattr, sys_mount_setattr)#undef __NR_syscalls -#define __NR_syscalls 442 +#define __NR_syscalls 443/* * 32 bit systems traditionally used different
linux-headers/asm-mips/unistd_n32.h +1 -0
@@ -371,6 +371,7 @@#define __NR_faccessat2 (__NR_Linux + 439)#define __NR_process_madvise (__NR_Linux + 440)#define __NR_epoll_pwait2 (__NR_Linux + 441) +#define __NR_mount_setattr (__NR_Linux + 442)#endif /* _ASM_MIPS_UNISTD_N32_H */
linux-headers/asm-mips/unistd_n64.h +1 -0
@@ -347,6 +347,7 @@#define __NR_faccessat2 (__NR_Linux + 439)#define __NR_process_madvise (__NR_Linux + 440)#define __NR_epoll_pwait2 (__NR_Linux + 441) +#define __NR_mount_setattr (__NR_Linux + 442)#endif /* _ASM_MIPS_UNISTD_N64_H */
linux-headers/asm-mips/unistd_o32.h +1 -0
@@ -417,6 +417,7 @@#define __NR_faccessat2 (__NR_Linux + 439)#define __NR_process_madvise (__NR_Linux + 440)#define __NR_epoll_pwait2 (__NR_Linux + 441) +#define __NR_mount_setattr (__NR_Linux + 442)#endif /* _ASM_MIPS_UNISTD_O32_H */
linux-headers/asm-powerpc/kvm.h +2 -0
@@ -644,6 +644,8 @@ struct kvm_ppc_cpu_char {#define KVM_REG_PPC_MMCR3 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc1)#define KVM_REG_PPC_SIER2 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc2)#define KVM_REG_PPC_SIER3 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc3) +#define KVM_REG_PPC_DAWR1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc4) +#define KVM_REG_PPC_DAWRX1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc5)/* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs
linux-headers/asm-powerpc/unistd_32.h +1 -0
@@ -424,6 +424,7 @@#define __NR_faccessat2 439#define __NR_process_madvise 440#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442#endif /* _ASM_POWERPC_UNISTD_32_H */
linux-headers/asm-powerpc/unistd_64.h +1 -0
@@ -396,6 +396,7 @@#define __NR_faccessat2 439#define __NR_process_madvise 440#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442#endif /* _ASM_POWERPC_UNISTD_64_H */
linux-headers/asm-s390/unistd_32.h +1 -0
@@ -414,5 +414,6 @@#define __NR_faccessat2 439#define __NR_process_madvise 440#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442#endif /* _ASM_S390_UNISTD_32_H */
linux-headers/asm-s390/unistd_64.h +1 -0
@@ -362,5 +362,6 @@#define __NR_faccessat2 439#define __NR_process_madvise 440#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442#endif /* _ASM_S390_UNISTD_64_H */
linux-headers/asm-x86/kvm.h +1 -0
@@ -112,6 +112,7 @@ struct kvm_ioapic_state {#define KVM_NR_IRQCHIPS 3#define KVM_RUN_X86_SMM (1 << 0) +#define KVM_RUN_X86_BUS_LOCK (1 << 1)/* for KVM_GET_REGS and KVM_SET_REGS */ struct kvm_regs {
linux-headers/asm-x86/unistd_32.h +1 -0
@@ -432,6 +432,7 @@#define __NR_faccessat2 439#define __NR_process_madvise 440#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442#endif /* _ASM_X86_UNISTD_32_H */
linux-headers/asm-x86/unistd_64.h +1 -0
@@ -354,6 +354,7 @@#define __NR_faccessat2 439#define __NR_process_madvise 440#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442#endif /* _ASM_X86_UNISTD_64_H */
linux-headers/asm-x86/unistd_x32.h +1 -0
@@ -307,6 +307,7 @@#define __NR_faccessat2 (__X32_SYSCALL_BIT + 439)#define __NR_process_madvise (__X32_SYSCALL_BIT + 440)#define __NR_epoll_pwait2 (__X32_SYSCALL_BIT + 441) +#define __NR_mount_setattr (__X32_SYSCALL_BIT + 442)#define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)#define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)#define __NR_ioctl (__X32_SYSCALL_BIT + 514)
linux-headers/linux/kvm.h +89 -0
147 lines not on this page · raw message
linux-headers/linux/vfio.h +27 -0
@@ -46,6 +46,12 @@*/ #define VFIO_NOIOMMU_IOMMU 8 +/* Supports VFIO_DMA_UNMAP_FLAG_ALL */ +#define VFIO_UNMAP_ALL 9 + +/* Supports the vaddr flag for DMA map and unmap */ +#define VFIO_UPDATE_VADDR 10 +/* * The IOCTL interface is designed for extensibility by embedding the * structure length (argsz) and flags into structures passed between
@@ -1074,12 +1080,22 @@ struct vfio_iommu_type1_info_dma_avail {* * Map process virtual addresses to IO virtual addresses using the * provided struct vfio_dma_map. Caller sets argsz. READ &/ WRITE required. +* +* If flags & VFIO_DMA_MAP_FLAG_VADDR, update the base vaddr for iova, and +* unblock translation of host virtual addresses in the iova range. The vaddr +* must have previously been invalidated with VFIO_DMA_UNMAP_FLAG_VADDR. To +* maintain memory consistency within the user application, the updated vaddr +* must address the same memory object as originally mapped. Failure to do so +* will result in user memory corruption and/or device misbehavior. iova and +* size must match those in the original MAP_DMA call. Protection is not +* changed, and the READ & WRITE flags must be 0. */ struct vfio_iommu_type1_dma_map {__u32 argsz;__u32 flags;#define VFIO_DMA_MAP_FLAG_READ (1 << 0)/* readable from device */ #define VFIO_DMA_MAP_FLAG_WRITE (1 << 1)/* writable from device */ +#define VFIO_DMA_MAP_FLAG_VADDR (1 << 2)__u64 vaddr;/* Process virtual address */ __u64 iova;/* IO virtual address */ __u64 size;/* Size of mapping (bytes) */
@@ -1102,6 +1118,7 @@ struct vfio_bitmap {* field. No guarantee is made to the user that arbitrary unmaps of iova * or size different from those used in the original mapping call will * succeed. +* * VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP should be set to get the dirty bitmap * before unmapping IO virtual addresses. When this flag is set, the user must * provide a struct vfio_bitmap in data[]. User must provide zero-allocated
@@ -1111,11 +1128,21 @@ struct vfio_bitmap {* indicates that the page at that offset from iova is dirty. A Bitmap of the * pages in the range of unmapped size is returned in the user-provided * vfio_bitmap.data. +* +* If flags & VFIO_DMA_UNMAP_FLAG_ALL, unmap all addresses. iova and size +* must be 0. This cannot be combined with the get-dirty-bitmap flag. +* +* If flags & VFIO_DMA_UNMAP_FLAG_VADDR, do not unmap, but invalidate host +* virtual addresses in the iova range. Tasks that attempt to translate an +* iova's vaddr will block. DMA to already-mapped pages continues. This +* cannot be combined with the get-dirty-bitmap flag. */ struct vfio_iommu_type1_dma_unmap {__u32 argsz;__u32 flags;#define VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP (1 << 0) +#define VFIO_DMA_UNMAP_FLAG_ALL (1 << 1) +#define VFIO_DMA_UNMAP_FLAG_VADDR (1 << 2)__u64 iova;/* IO virtual address */ __u64 size;/* Size of mapping (bytes) */ __u8 data[];
Signature · 1 line
2.26.3
PATCH v2 2/2 virtiofsd: Add support for FUSE_SYNCFS request
In reply to Greg KurzHonor the expected behavior of syncfs() to synchronously flush all data and metadata on linux systems.
Flushing is done with syncfs(). This is suboptimal as it will also flush writes performed by any other process on the same file system, and thus add an unbounded time penalty to syncfs(). This may be optimized in the future, but enforce correctness first.
--- tools/virtiofsd/fuse_lowlevel.c | 19 ++++++++++++++++++ tools/virtiofsd/fuse_lowlevel.h | 13 ++++++++++++ tools/virtiofsd/passthrough_ll.c | 29 +++++++++++++++++++++++++++ tools/virtiofsd/passthrough_seccomp.c | 1 + 4 files changed, 62 insertions(+)
tools/virtiofsd/fuse_lowlevel.c +19 -0
@@ -1870,6 +1870,24 @@ static void do_lseek(fuse_req_t req, fuse_ino_t nodeid, } } +static void do_syncfs (fuse_req_t req,fuse_ino_t nodeid, +struct fuse_mbuf_iter *iter) +{ +struct fuse_syncfs_in *arg; + + arg =fuse_mbuf_iter_advance (iter,sizeof (*arg)); +if (!arg) { +fuse_reply_err (req,EINVAL ); +return ; + } + +if (req->se->op.syncfs) { + req->se->op.syncfs (req, arg->flags); + }else { +fuse_reply_err (req,ENOSYS ); + } +} +static void do_init (fuse_req_t req,fuse_ino_t nodeid,struct fuse_mbuf_iter *iter) {
@@ -2267,6 +2285,7 @@ static struct { [FUSE_RENAME2] = { do_rename2, "RENAME2" }, [FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" }, [FUSE_LSEEK] = { do_lseek, "LSEEK" }, + [FUSE_SYNCFS] = { do_syncfs, "SYNCFS" }, };#define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))
tools/virtiofsd/fuse_lowlevel.h +13 -0
@@ -1225,6 +1225,19 @@ struct fuse_lowlevel_ops {*/ void (*lseek)(fuse_req_t req,fuse_ino_t ino,off_t off,int whence,struct fuse_file_info *fi); + +/** +* Synchronize file system content +* +* If this request is answered with an error code of ENOSYS, +* this is treated as success and future calls to syncfs() will +* succeed automatically without being sent to the filesystem +* process. +* +* @param req request handle +* @param flags not used yet +*/ +void (*syncfs)(fuse_req_t req,uint64_t flags); };/**
tools/virtiofsd/passthrough_ll.c +29 -0
@@ -3124,6 +3124,34 @@ static void lo_lseek(fuse_req_t req, fuse_ino_t ino, off_t off, int whence, } } +static void lo_syncfs (fuse_req_t req,uint64_t flags) +{ +struct lo_data *lo =lo_data (req); +int fd, ret; + +/* No flags supported yet */ +if (flags) { +fuse_reply_err (req,EINVAL ); +return ; + } + + fd =lo_inode_open (lo, &lo->root,O_RDONLY ); +if (fd <0 ) { +fuse_reply_err (req, errno); +return ; + } + +/* +* FIXME: this is suboptimal because it will also flush unrelated +* writes not coming from the client. This can dramatically +* increase the time spent in syncfs() if some process is +* writing lots of data on the same filesystem as virtiofsd. +*/ + ret =syncfs (fd); +fuse_reply_err (req, ret <0 ? errno :0 ); +close (fd); +} +static void lo_destroy (void *userdata) {struct lo_data *lo = (struct lo_data *)userdata;
@@ -3184,6 +3212,7 @@ static struct fuse_lowlevel_ops lo_oper = { .copy_file_range = lo_copy_file_range, #endif .lseek = lo_lseek, + .syncfs = lo_syncfs, .destroy = lo_destroy, };
tools/virtiofsd/passthrough_seccomp.c +1 -0
@@ -107,6 +107,7 @@ static const int syscall_allowlist[] = {SCMP_SYS (set_robust_list),SCMP_SYS (setxattr),SCMP_SYS (symlinkat), +SCMP_SYS (syncfs),SCMP_SYS (time),/* Rarely needed, except on static builds */ SCMP_SYS (tgkill), SCMP_SYS(unlinkat),
Signature · 1 line
2.26.3
Quoted 99 lines · Greg Kurz
Honor the expected behavior of
syncfs()to synchronously flush all data and metadata on linux systems.Flushing is done with
syncfs(). This is suboptimal as it will also flush writes performed by any other process on the same file system, and thus add an unbounded time penalty tosyncfs(). This may be optimized in the future, but enforce correctness first.Signed-off-by Greg Kurz <[email protected]>--- tools/virtiofsd/fuse_lowlevel.c | 19 ++++++++++++++++++ tools/virtiofsd/fuse_lowlevel.h | 13 ++++++++++++ tools/virtiofsd/passthrough_ll.c | 29 +++++++++++++++++++++++++++ tools/virtiofsd/passthrough_seccomp.c | 1 + 4 files changed, 62 insertions(+)tools/virtiofsd/fuse_lowlevel.c +19
-0@@ -1870,6 +1870,24 @@ static void do_lseek(fuse_req_t req, fuse_ino_t nodeid, } } +static void do_syncfs (fuse_req_t req,fuse_ino_t nodeid, +struct fuse_mbuf_iter *iter) +{ +struct fuse_syncfs_in *arg; + + arg =fuse_mbuf_iter_advance (iter,sizeof (*arg)); +if (!arg) { +fuse_reply_err (req,EINVAL ); +return ; + } + +if (req->se->op.syncfs) { + req->se->op.syncfs (req, arg->flags); + }else { +fuse_reply_err (req,ENOSYS ); + } +} +static void do_init (fuse_req_t req,fuse_ino_t nodeid,struct fuse_mbuf_iter *iter) {@@ -2267,6 +2285,7 @@ static struct { [FUSE_RENAME2] = { do_rename2, "RENAME2" }, [FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" }, [FUSE_LSEEK] = { do_lseek, "LSEEK" }, + [FUSE_SYNCFS] = { do_syncfs, "SYNCFS" }, };#define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))tools/virtiofsd/fuse_lowlevel.h +13
-0@@ -1225,6 +1225,19 @@ struct fuse_lowlevel_ops {*/ void (*lseek)(fuse_req_t req,fuse_ino_t ino,off_t off,int whence,struct fuse_file_info *fi); + +/** +* Synchronize file system content +* +* If this request is answered with an error code of ENOSYS, +* this is treated as success and future calls to syncfs() will +* succeed automatically without being sent to the filesystem +* process. +* +* @param req request handle +* @param flags not used yet +*/ +void (*syncfs)(fuse_req_t req,uint64_t flags); };/** tools/virtiofsd/passthrough_ll.c +14
-0@@ -3124,6 +3124,34 @@ static void lo_lseek(fuse_req_t req, fuse_ino_t ino, off_t off, int whence, } } +static void lo_syncfs (fuse_req_t req,uint64_t flags) +{ +struct lo_data *lo =lo_data (req); +int fd, ret; + +/* No flags supported yet */ +if (flags) { +fuse_reply_err (req,EINVAL ); +return ; + } + + fd =lo_inode_open (lo, &lo->root,O_RDONLY ); +if (fd <0 ) { +fuse_reply_err (req, errno);
tools/virtiofsd/passthrough_ll.c static void lo_lseek(fuse_req_t req, fuse_ino_t ino, off_t off, int whence, · line 3150
Quoted 10 lines
tools/virtiofsd/passthrough_ll.c +10
-0+return ; + } + +/* +* FIXME: this is suboptimal because it will also flush unrelated +* writes not coming from the client. This can dramatically +* increase the time spent in syncfs() if some process is +* writing lots of data on the same filesystem as virtiofsd. +*/ + ret =syncfs (fd);
Hi Greg,
As we discussed in the community call that this works only if there are no other filesystems mounted as submounts under exported directory.
We proably need to find a way to call syncfs() on all the filesystems which are submounts of exported directory. Might not be easy at all.
Just mentioning it here so that we have a note about the limitation of current patch.
Vivek
Quoted 30 lines
tools/virtiofsd/passthrough_ll.c +5
-0+fuse_reply_err (req, ret <0 ? errno :0 ); +close (fd); +} +static void lo_destroy (void *userdata) {struct lo_data *lo = (struct lo_data *)userdata;@@ -3184,6 +3212,7 @@ static struct fuse_lowlevel_ops lo_oper = { .copy_file_range = lo_copy_file_range, #endif .lseek = lo_lseek, + .syncfs = lo_syncfs, .destroy = lo_destroy, };tools/virtiofsd/passthrough_seccomp.c +1
-0@@ -107,6 +107,7 @@ static const int syscall_allowlist[] = {SCMP_SYS (set_robust_list),SCMP_SYS (setxattr),SCMP_SYS (symlinkat), +SCMP_SYS (syncfs),SCMP_SYS (time),/* Rarely needed, except on static builds */ SCMP_SYS (tgkill), SCMP_SYS(unlinkat),Signature · 1 line
2.26.3
Quoted 104 lines · On Wed, 5 May 2021 14:52:42 -0400 Vivek Goyal <[email protected]> wrote:
Quoted 103 lines · Greg Kurz
Honor the expected behavior of
syncfs()to synchronously flush all data and metadata on linux systems.Flushing is done with
syncfs(). This is suboptimal as it will also flush writes performed by any other process on the same file system, and thus add an unbounded time penalty tosyncfs(). This may be optimized in the future, but enforce correctness first.Signed-off-by Greg Kurz <[email protected]>--- tools/virtiofsd/fuse_lowlevel.c | 19 ++++++++++++++++++ tools/virtiofsd/fuse_lowlevel.h | 13 ++++++++++++ tools/virtiofsd/passthrough_ll.c | 29 +++++++++++++++++++++++++++ tools/virtiofsd/passthrough_seccomp.c | 1 + 4 files changed, 62 insertions(+)tools/virtiofsd/fuse_lowlevel.c +19
-0@@ -1870,6 +1870,24 @@ static void do_lseek(fuse_req_t req, fuse_ino_t nodeid, } } +static void do_syncfs (fuse_req_t req,fuse_ino_t nodeid, +struct fuse_mbuf_iter *iter) +{ +struct fuse_syncfs_in *arg; + + arg =fuse_mbuf_iter_advance (iter,sizeof (*arg)); +if (!arg) { +fuse_reply_err (req,EINVAL ); +return ; + } + +if (req->se->op.syncfs) { + req->se->op.syncfs (req, arg->flags); + }else { +fuse_reply_err (req,ENOSYS ); + } +} +static void do_init (fuse_req_t req,fuse_ino_t nodeid,struct fuse_mbuf_iter *iter) {@@ -2267,6 +2285,7 @@ static struct { [FUSE_RENAME2] = { do_rename2, "RENAME2" }, [FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" }, [FUSE_LSEEK] = { do_lseek, "LSEEK" }, + [FUSE_SYNCFS] = { do_syncfs, "SYNCFS" }, };#define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))tools/virtiofsd/fuse_lowlevel.h +13
-0@@ -1225,6 +1225,19 @@ struct fuse_lowlevel_ops {*/ void (*lseek)(fuse_req_t req,fuse_ino_t ino,off_t off,int whence,struct fuse_file_info *fi); + +/** +* Synchronize file system content +* +* If this request is answered with an error code of ENOSYS, +* this is treated as success and future calls to syncfs() will +* succeed automatically without being sent to the filesystem +* process. +* +* @param req request handle +* @param flags not used yet +*/ +void (*syncfs)(fuse_req_t req,uint64_t flags); };/** tools/virtiofsd/passthrough_ll.c +18
-0@@ -3124,6 +3124,34 @@ static void lo_lseek(fuse_req_t req, fuse_ino_t ino, off_t off, int whence, } } +static void lo_syncfs (fuse_req_t req,uint64_t flags) +{ +struct lo_data *lo =lo_data (req); +int fd, ret; + +/* No flags supported yet */ +if (flags) { +fuse_reply_err (req,EINVAL ); +return ; + } + + fd =lo_inode_open (lo, &lo->root,O_RDONLY ); +if (fd <0 ) { +fuse_reply_err (req, errno); +return ; + } + +/*
Quoted 9 lines
tools/virtiofsd/passthrough_ll.c static void lo_lseek(fuse_req_t req, fuse_ino_t ino, off_t off, int whence, · line 3150
Quoted 6 lines
tools/virtiofsd/passthrough_ll.c +6
-0+* FIXME: this is suboptimal because it will also flush unrelated +* writes not coming from the client. This can dramatically +* increase the time spent in syncfs() if some process is +* writing lots of data on the same filesystem as virtiofsd. +*/ + ret =syncfs (fd);Hi Greg,
Hi Vivek,
Quoted 6 lines
As we discussed in the community call that this works only if there are no other filesystems mounted as submounts under exported directory.
We proably need to find a way to call
syncfs()on all the filesystems which are submounts of exported directory. Might not be easy at all.
I must confess I didn't investigate this case. I'll start looking.
Quoted 3 lines
Just mentioning it here so that we have a note about the limitation of current patch.
Sure. I'll add a note for that.
Quoted 33 lines
Vivek
Quoted 30 lines
tools/virtiofsd/passthrough_ll.c +5
-0+fuse_reply_err (req, ret <0 ? errno :0 ); +close (fd); +} +static void lo_destroy (void *userdata) {struct lo_data *lo = (struct lo_data *)userdata;@@ -3184,6 +3212,7 @@ static struct fuse_lowlevel_ops lo_oper = { .copy_file_range = lo_copy_file_range, #endif .lseek = lo_lseek, + .syncfs = lo_syncfs, .destroy = lo_destroy, };tools/virtiofsd/passthrough_seccomp.c +1
-0@@ -107,6 +107,7 @@ static const int syscall_allowlist[] = {SCMP_SYS (set_robust_list),SCMP_SYS (setxattr),SCMP_SYS (symlinkat), +SCMP_SYS (syncfs),SCMP_SYS (time),/* Rarely needed, except on static builds */ SCMP_SYS (tgkill), SCMP_SYS(unlinkat),Signature · 1 line
2.26.3
Quoted 3 lines · * Greg Kurz ([email protected]) wrote:
FUSE_SYNCFSallows the client to flush the host page cache. This isn't available in upstream linux yet, but the following tree can be used to test:
That looks OK to me; but we'll need to wait until syncfs lands in the upstream kernel; we've got bitten before by stuff changing before it actaully lands in the kernel.
Dave
Quoted 39 lines
https://gitlab.com/gkurz/linux/-/tree/virtio-fs-sync
v2: - based on new version of
FUSE_SYNCFS
https://listman.redhat.com/archives/virtio-fs/2021-April/msg00166.html
- propagatesyncfs()errors to client (Vivek)Greg Kurz (2):
Update linux headers to 5.12-rc8 +FUSE_SYNCFS
virtiofsd: Add support forFUSE_SYNCFSrequestinclude/standard-headers/drm/drm_fourcc.h | 23 ++++- include/standard-headers/linux/ethtool.h | 54 ++++++----- include/standard-headers/linux/fuse.h | 13 ++- include/standard-headers/linux/input.h | 2 +- .../standard-headers/rdma/vmw_pvrdma-abi.h | 7 ++ linux-headers/asm-generic/unistd.h | 4 +- linux-headers/asm-mips/unistd_n32.h | 1 + linux-headers/asm-mips/unistd_n64.h | 1 + linux-headers/asm-mips/unistd_o32.h | 1 + linux-headers/asm-powerpc/kvm.h | 2 + linux-headers/asm-powerpc/unistd_32.h | 1 + linux-headers/asm-powerpc/unistd_64.h | 1 + linux-headers/asm-s390/unistd_32.h | 1 + linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 1 + linux-headers/asm-x86/unistd_32.h | 1 + linux-headers/asm-x86/unistd_64.h | 1 + linux-headers/asm-x86/unistd_x32.h | 1 + linux-headers/linux/kvm.h | 89 +++++++++++++++++++ linux-headers/linux/vfio.h | 27 ++++++ tools/virtiofsd/fuse_lowlevel.c | 19 ++++ tools/virtiofsd/fuse_lowlevel.h | 13 +++ tools/virtiofsd/passthrough_ll.c | 29 ++++++ tools/virtiofsd/passthrough_seccomp.c | 1 + 24 files changed, 267 insertions(+), 27 deletions(-)Signature · 1 line
2.26.3
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 9 lines · On Tue, 27 Apr 2021 12:28:13 +0100 "Dr. David Alan Gilbert"…
Quoted 3 lines · * Greg Kurz ([email protected]) wrote:
FUSE_SYNCFSallows the client to flush the host page cache. This isn't available in upstream linux yet, but the following tree can be used to test:That looks OK to me; but we'll need to wait until syncfs lands in the upstream kernel; we've got bitten before by stuff changing before it actaully lands in the kernel.
Sure ! I'll repost an updated series when this happens.
Thanks for the feedback.
--
Greg
Quoted 41 lines
Dave
Quoted 39 lines
https://gitlab.com/gkurz/linux/-/tree/virtio-fs-sync
v2: - based on new version of
FUSE_SYNCFS
https://listman.redhat.com/archives/virtio-fs/2021-April/msg00166.html
- propagatesyncfs()errors to client (Vivek)Greg Kurz (2):
Update linux headers to 5.12-rc8 +FUSE_SYNCFS
virtiofsd: Add support forFUSE_SYNCFSrequestinclude/standard-headers/drm/drm_fourcc.h | 23 ++++- include/standard-headers/linux/ethtool.h | 54 ++++++----- include/standard-headers/linux/fuse.h | 13 ++- include/standard-headers/linux/input.h | 2 +- .../standard-headers/rdma/vmw_pvrdma-abi.h | 7 ++ linux-headers/asm-generic/unistd.h | 4 +- linux-headers/asm-mips/unistd_n32.h | 1 + linux-headers/asm-mips/unistd_n64.h | 1 + linux-headers/asm-mips/unistd_o32.h | 1 + linux-headers/asm-powerpc/kvm.h | 2 + linux-headers/asm-powerpc/unistd_32.h | 1 + linux-headers/asm-powerpc/unistd_64.h | 1 + linux-headers/asm-s390/unistd_32.h | 1 + linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 1 + linux-headers/asm-x86/unistd_32.h | 1 + linux-headers/asm-x86/unistd_64.h | 1 + linux-headers/asm-x86/unistd_x32.h | 1 + linux-headers/linux/kvm.h | 89 +++++++++++++++++++ linux-headers/linux/vfio.h | 27 ++++++ tools/virtiofsd/fuse_lowlevel.c | 19 ++++ tools/virtiofsd/fuse_lowlevel.h | 13 +++ tools/virtiofsd/passthrough_ll.c | 29 ++++++ tools/virtiofsd/passthrough_seccomp.c | 1 + 24 files changed, 267 insertions(+), 27 deletions(-)Signature · 1 line
2.26.3