NFS/NFSD: add NFSv42 COPY operation support
Subsystems (5)
RFC PATCH 1/11 vfs: pull btrfs clone API to vfs layer
In reply to a message not in the archiveNow that a few file systems are adding clone functionality, namingly btrfs, NFS (later in the series) and XFS (ttp://oss.sgi.com/archives/xfs/2015-06/msg00407.html), it makes sense to pull the ioctl to common code.
Add vfs_file_clone_range() helper and .clone_range file operation interface to allow underlying filesystems to clone between regular files.
The change in do_vfs_ioctl() is defered to next patch where btrfs .clone_range is added, just so that we don't break btrfs CLONE ioctl with this patch.
--- fs/ioctl.c | 24 ++++++++++++++++++++++++ fs/read_write.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 4 ++++ include/uapi/linux/fs.h | 9 +++++++++ 4 files changed, 82 insertions(+)
fs/ioctl.c +24 -0
@@ -215,6 +215,30 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)return error; } +static long ioctl_file_clone (struct file *dst_file,unsigned long srcfd, +u64 off,u64 olen,u64 destoff) +{ +struct fd src_file =fdget (srcfd); +int ret; + +if (!src_file.file) +return -EBADF ; + ret =vfs_file_clone_range (src_file.file, dst_file, off, olen, destoff); + +fdput (src_file); +return ret; +} + +static long ioctl_file_clone_range (struct file *file,void __user *argp) +{ +struct file_clone_range args; + +if (copy_from_user (&args, argp,sizeof (args))) +return -EFAULT ; +return ioctl_file_clone (file, args.src_fd, args.src_offset, + args.src_length, args.dest_offset); +} +#ifdef CONFIG_BLOCK static inline sector_t logical_to_blk (struct inode *inode,loff_t offset)
fs/read_write.c +45 -0
54 lines not on this page · raw message
include/linux/fs.h +4 -0
@@ -1628,6 +1628,8 @@ struct file_operations {long (*fallocate)(struct file *file,int mode,loff_t offset,loff_t len);void (*show_fdinfo)(struct seq_file *m,struct file *f); +int (*clone_range)(struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff);#ifndef CONFIG_MMU unsigned (*mmap_capabilities)(struct file *);#endif
@@ -2678,6 +2680,8 @@ int __dax_fault(struct vm_area_struct *, struct vm_fault *, get_block_t,int dax_pfn_mkwrite (struct vm_area_struct *,struct vm_fault *);#define dax_mkwrite (vma, vmf, gb, iod) dax_fault(vma, vmf, gb, iod)#define __dax_mkwrite (vma, vmf, gb, iod) __dax_fault(vma, vmf, gb, iod) +int vfs_file_clone_range (struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff);#ifdef CONFIG_BLOCK typedef void (dio_submit_t)(int rw, struct bio *bio, struct inode *inode,
include/uapi/linux/fs.h +9 -0
@@ -39,6 +39,13 @@#define RENAME_EXCHANGE (1 << 1)/* Exchange source and dest */ #define RENAME_WHITEOUT (1 << 2)/* Whiteout source */ +struct file_clone_range { +__s64 src_fd; +__u64 src_offset; +__u64 src_length; +__u64 dest_offset; +}; +struct fstrim_range {__u64 start;__u64 len;
@@ -159,6 +166,8 @@ struct inodes_stat_t {#define FIFREEZE _IOWR('X', 119, int)/* Freeze */ #define FITHAW _IOWR('X', 120, int)/* Thaw */ #define FITRIM _IOWR('X', 121, struct fstrim_range)/* Trim */ +#define FICLONE _IOW(0x94, 9, int)/* Clone */ +#define FICLONERANGE _IOW(0x94, 13, struct file_clone_range)/* Clone range */ #define FS_IOC_GETFLAGS _IOR('f', 1, long)#define FS_IOC_SETFLAGS _IOW('f', 2, long)
Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC PATCH 2/11 vfs/btrfs: add .clone_range file operation
In reply to Peng TaoAlso add vfs callers in do_vfs_ioctl(). Now btrfs CLONE ioctl goes through vfs_file_clone_range().
--- fs/btrfs/ctree.h | 2 ++ fs/btrfs/file.c | 1 + fs/btrfs/ioctl.c | 68 +++++----------------------------------------- fs/ioctl.c | 6 ++++ include/uapi/linux/btrfs.h | 10 ------- 5 files changed, 16 insertions(+), 71 deletions(-)
fs/btrfs/ctree.h +2 -0
@@ -3969,6 +3969,8 @@ void btrfs_get_block_group_info(struct list_head *groups_list, struct btrfs_ioctl_space_info *space);void update_ioctl_balance_args (struct btrfs_fs_info *fs_info,int lock,struct btrfs_ioctl_balance_args *bargs); +int btrfs_file_clone_range (struct file *src_file,struct file *dst_file, +loff_t off,size_t olen,loff_t destoff);/* file.c */
fs/btrfs/file.c +1 -0
@@ -2813,6 +2813,7 @@ const struct file_operations btrfs_file_operations = { .fsync = btrfs_sync_file, .fallocate = btrfs_fallocate, .unlocked_ioctl = btrfs_ioctl, + .clone_range = btrfs_file_clone_range,#ifdef CONFIG_COMPAT .compat_ioctl = btrfs_ioctl,#endif
fs/btrfs/ioctl.c +7 -61
110 lines not on this page · raw message
fs/ioctl.c +6 -0
@@ -624,6 +624,12 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,case FIGETBSZ :return put_user (inode->i_sb->s_blocksize, argp); +case FICLONE : +return ioctl_file_clone (filp, arg,0 ,0 ,0 ); + +case FICLONERANGE : +return ioctl_file_clone_range (filp, argp); +default :if (S_ISREG (inode->i_mode)) error =file_ioctl (filp, cmd, arg);
include/uapi/linux/btrfs.h +0 -10
@@ -316,12 +316,6 @@ struct btrfs_ioctl_search_args_v2 {__u64 buf[0 ];/* out - found items */ }; -struct btrfs_ioctl_clone_range_args { -__s64 src_fd; -__u64 src_offset, src_length; -__u64 dest_offset; -}; -/* flags for the defrag range ioctl */ #define BTRFS_DEFRAG_RANGE_COMPRESS 1#define BTRFS_DEFRAG_RANGE_START_IO 2
@@ -548,7 +542,6 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)#define BTRFS_IOC_TRANS_END _IO(BTRFS_IOCTL_MAGIC, 7)#define BTRFS_IOC_SYNC _IO(BTRFS_IOCTL_MAGIC, 8) -#define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)#define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \ struct btrfs_ioctl_vol_args)#define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \
@@ -556,9 +549,6 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)#define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \ struct btrfs_ioctl_vol_args) -#define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \ - struct btrfs_ioctl_clone_range_args) -#define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \ struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
Signature · 1 line
1.8.3.1
cover NFS/NFSD: add NFSv42 COPY operation support
Hi all,
This patchset adds NFSv42 COPY support to nfs and nfsd. As suggested by Christoph, it pulls btrfs BTRFS_IOC_CLONE/BTRFS_IOC_CLONE_RANGE ioctls to generic layer and adds a new file operation to call down to file systems. Then the CLONE ioctl is implemented for NFS and NFSD.
I took a slightly different approach from Anna's NFS42 COPY implementation
(http://www.spinics.net/lists/linux-nfs/msg53009.html) mainly because CLONE has different requirements than COPY. And the main differences between the two are:
1. well, CLONE is supported rather than COPY.
2. vfs_file_clone_range() does not expect file systems to do data copy, and thus no rw_verify_area() required.
3. clone does not expect partial success.
4. clone does not fall back to data copy if underlying storage does not support it.
5. no new system call required. We reuse existing BTRFS_IOC_CLONE/BTRFS_IOC_CLONE_RANGE and make it generic to all file systems.
Cheers,
Tao
Anna Schumaker (2):
nfsd: Pass filehandle to nfs4_preprocess_stateid_op()
NFSD: Implement the CLONE call
Peng Tao (9):
vfs: pull btrfs clone API to vfs layer vfs/btrfs: add .clone_range file operation
nfs42: decode_layoutstats does not need res parameter
nfs42: remove unused declaration
nfs42: add CLONE xdr functions
nfs42: add CLONE proc functions
nfs42: add .copy_range file operation
nfs: get clone_blksize when probing fsinfo
nfs42: respect clone_blksize
fs/btrfs/ctree.h | 2 + fs/btrfs/file.c | 1 + fs/btrfs/ioctl.c | 68 ++++-------------------------- fs/ioctl.c | 30 +++++++++++++ fs/nfs/client.c | 1 + fs/nfs/nfs42.h | 3 +- fs/nfs/nfs42proc.c | 71 +++++++++++++++++++++++++++++++ fs/nfs/nfs42xdr.c | 102 +++++++++++++++++++++++++++++++++++++++++++-- fs/nfs/nfs4file.c | 58 ++++++++++++++++++++++++++ fs/nfs/nfs4proc.c | 4 +- fs/nfs/nfs4xdr.c | 26 ++++++++++++ fs/nfsd/nfs4proc.c | 91 ++++++++++++++++++++++++++++++++++++---- fs/nfsd/nfs4state.c | 5 +-- fs/nfsd/nfs4xdr.c | 21 ++++++++++ fs/nfsd/state.h | 4 +- fs/nfsd/vfs.c | 7 ++++ fs/nfsd/vfs.h | 1 + fs/nfsd/xdr4.h | 10 +++++ fs/read_write.c | 45 ++++++++++++++++++++ include/linux/fs.h | 4 ++ include/linux/nfs4.h | 7 +++- include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 20 +++++++++ include/uapi/linux/btrfs.h | 10 ----- include/uapi/linux/fs.h | 9 ++++ 25 files changed, 510 insertions(+), 92 deletions(-)
Signature · 1 line
1.8.3.1
RFC PATCH 3/11 nfs42: decode_layoutstats does not need res parameter
--- fs/nfs/nfs42xdr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/nfs/nfs42xdr.c +2 -3
@@ -238,8 +238,7 @@ out_overflow:return -EIO ; } -static int decode_layoutstats (struct xdr_stream *xdr, -struct nfs42_layoutstat_res *res) +static int decode_layoutstats (struct xdr_stream *xdr) {return decode_op_hdr (xdr,OP_LAYOUTSTATS ); }
@@ -343,7 +342,7 @@ static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp, goto out;WARN_ON (res->num_dev >PNFS_LAYOUTSTATS_MAXDEV );for (i =0 ; i < res->num_dev; i++) { - status =decode_layoutstats (xdr, res); + status =decode_layoutstats (xdr);if (status) goto out; }
Signature · 1 line
1.8.3.1
RFC PATCH 4/11 nfs42: remove unused declaration
In reply to Peng Tao--- fs/nfs/nfs42.h | 2 -- 1 file changed, 2 deletions(-)
fs/nfs/nfs42.h +0 -2
@@ -17,7 +17,5 @@ int nfs42_proc_deallocate(struct file *, loff_t, loff_t);loff_t nfs42_proc_llseek (struct file *,loff_t ,int );int nfs42_proc_layoutstats_generic (struct nfs_server *,struct nfs42_layoutstat_data *); -/* nfs4.2xdr.h */ -extern struct rpc_procinfo nfs4_2_procedures[];#endif /* __LINUX_FS_NFS_NFS4_2_H */
Signature · 1 line
1.8.3.1
RFC PATCH 5/11 nfs42: add CLONE xdr functions
In reply to Peng Taoxdr definitions per draft-ietf-nfsv4-minorversion2-38.txt
--- fs/nfs/nfs42xdr.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++- fs/nfs/nfs4xdr.c | 1 + include/linux/nfs4.h | 2 + include/linux/nfs_xdr.h | 19 ++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-)
fs/nfs/nfs42xdr.c +96 -1
@@ -34,6 +34,12 @@ 1 /* opaque devaddr4 length */ + \ XDR_QUADLEN(PNFS_LAYOUTSTATS_MAXSIZE))#define decode_layoutstats_maxsz (op_decode_hdr_maxsz) +#define encode_clone_maxsz (encode_stateid_maxsz + \ + encode_stateid_maxsz + \ + 2 /* src offset */ + \ + 2 /* dst offset */ + \ + 2 /* count */) +#define decode_clone_maxsz (op_decode_hdr_maxsz)#define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \ encode_putfh_maxsz + \
@@ -65,7 +71,20 @@ decode_sequence_maxsz + \ decode_putfh_maxsz + \ PNFS_LAYOUTSTATS_MAXDEV * decode_layoutstats_maxsz) - +#define NFS4_enc_clone_sz (compound_encode_hdr_maxsz + \ + encode_sequence_maxsz + \ + encode_putfh_maxsz + \ + encode_savefh_maxsz + \ + encode_putfh_maxsz + \ + encode_clone_maxsz + \ + encode_getattr_maxsz) +#define NFS4_dec_clone_sz (compound_decode_hdr_maxsz + \ + decode_sequence_maxsz + \ + decode_putfh_maxsz + \ + decode_savefh_maxsz + \ + decode_putfh_maxsz + \ + decode_clone_maxsz + \ + decode_getattr_maxsz)static void encode_fallocate (struct xdr_stream *xdr,struct nfs42_falloc_args *args)
@@ -128,6 +147,21 @@ static void encode_layoutstats(struct xdr_stream *xdr,encode_uint32 (xdr,0 ); } +static void encode_clone (struct xdr_stream *xdr, +struct nfs42_clone_args *args, +struct compound_hdr *hdr) +{ +__be32 *p; + +encode_op_hdr (xdr,OP_CLONE , decode_clone_maxsz, hdr); +encode_nfs4_stateid (xdr, &args->src_stateid); +encode_nfs4_stateid (xdr, &args->dst_stateid); + p =reserve_space (xdr,3 *8 ); + p =xdr_encode_hyper (p, args->src_offset); + p =xdr_encode_hyper (p, args->dst_offset); +xdr_encode_hyper (p, args->count); +} +/* * Encode ALLOCATE request */
@@ -206,6 +240,27 @@ static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req,encode_nops (&hdr); } +/* +* Encode CLONE request +*/ +static void nfs4_xdr_enc_clone (struct rpc_rqst *req, +struct xdr_stream *xdr, +struct nfs42_clone_args *args) +{ +struct compound_hdr hdr = { + .minorversion =nfs4_xdr_minorversion (&args->seq_args), + }; + +encode_compound_hdr (xdr, req, &hdr); +encode_sequence (xdr, &args->seq_args, &hdr); +encode_putfh (xdr, args->src_fh, &hdr); +encode_savefh (xdr, &hdr); +encode_putfh (xdr, args->dst_fh, &hdr); +encode_clone (xdr, args, &hdr); +encode_getfattr (xdr, args->dst_bitmask, &hdr); +encode_nops (&hdr); +} +static int decode_allocate (struct xdr_stream *xdr,struct nfs42_falloc_res *res) {return decode_op_hdr (xdr,OP_ALLOCATE );
@@ -243,6 +298,11 @@ static int decode_layoutstats(struct xdr_stream *xdr)return decode_op_hdr (xdr,OP_LAYOUTSTATS ); } +static int decode_clone (struct xdr_stream *xdr) +{ +return decode_op_hdr (xdr,OP_CLONE ); +} +/* * Decode ALLOCATE request */
@@ -351,4 +411,39 @@ out: return status; } +/* +* Decode CLONE request +*/ +static int nfs4_xdr_dec_clone (struct rpc_rqst *rqstp, +struct xdr_stream *xdr, +struct nfs42_clone_res *res) +{ +struct compound_hdr hdr; +int status; + + status =decode_compound_hdr (xdr, &hdr); +if (status) + goto out; + status =decode_sequence (xdr, &res->seq_res, rqstp); +if (status) + goto out; + status =decode_putfh (xdr); +if (status) + goto out; + status =decode_savefh (xdr); +if (status) + goto out; + status =decode_putfh (xdr); +if (status) + goto out; + status =decode_clone (xdr); +if (status) + goto out; + status =decode_getfattr (xdr, res->dst_fattr, res->server); + +out: + res->rpc_status = status; +return status; +} +#endif /* __LINUX_FS_NFS_NFS4_2XDR_H */
fs/nfs/nfs4xdr.c +1 -0
@@ -7434,6 +7434,7 @@ struct rpc_procinfo nfs4_procedures[] = {PROC (ALLOCATE , enc_allocate, dec_allocate),PROC (DEALLOCATE , enc_deallocate, dec_deallocate),PROC (LAYOUTSTATS , enc_layoutstats, dec_layoutstats), + PROC(CLONE, enc_clone, dec_clone), #endif /* CONFIG_NFS_V4_2 */ };
include/linux/nfs4.h +2 -0
@@ -130,6 +130,7 @@ enum nfs_opnum4 {OP_READ_PLUS =68 ,OP_SEEK =69 ,OP_WRITE_SAME =70 , +OP_CLONE =71 , OP_ILLEGAL = 10044, };
@@ -501,6 +502,7 @@ enum {NFSPROC4_CLNT_ALLOCATE ,NFSPROC4_CLNT_DEALLOCATE ,NFSPROC4_CLNT_LAYOUTSTATS , + NFSPROC4_CLNT_CLONE, };/* nfs41 types */
include/linux/nfs_xdr.h +19 -0
@@ -359,6 +359,25 @@ struct nfs42_layoutstat_data {struct nfs42_layoutstat_res res; }; +struct nfs42_clone_args { +struct nfs4_sequence_args seq_args; +struct nfs_fh *src_fh; +struct nfs_fh *dst_fh; +nfs4_stateid src_stateid; +nfs4_stateid dst_stateid; +__u64 src_offset; +__u64 dst_offset; +__u64 count; +const u32 *dst_bitmask; +}; + +struct nfs42_clone_res { +struct nfs4_sequence_res seq_res; +unsigned int rpc_status; +struct nfs_fattr *dst_fattr; +const struct nfs_server *server; +}; +struct stateowner_id {__u64 create_time;__u32 uniquifier;
Signature · 1 line
1.8.3.1
RFC PATCH 6/11 nfs42: add CLONE proc functions
In reply to Peng Tao--- fs/nfs/nfs42.h | 1 + fs/nfs/nfs42proc.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4proc.c | 3 +- include/linux/nfs_fs_sb.h | 1 + 4 files changed, 75 insertions(+), 1 deletion(-)
fs/nfs/nfs42.h +1 -0
@@ -17,5 +17,6 @@ int nfs42_proc_deallocate(struct file *, loff_t, loff_t);loff_t nfs42_proc_llseek (struct file *,loff_t ,int );int nfs42_proc_layoutstats_generic (struct nfs_server *,struct nfs42_layoutstat_data *); +int nfs42_proc_clone (struct file *,struct file *,loff_t ,loff_t ,loff_t );#endif /* __LINUX_FS_NFS_NFS4_2_H */
fs/nfs/nfs42proc.c +71 -0
74 lines not on this page · raw message
fs/nfs/nfs4proc.c +2 -1
@@ -8659,7 +8659,8 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { | NFS_CAP_ALLOCATE |NFS_CAP_DEALLOCATE |NFS_CAP_SEEK - | NFS_CAP_LAYOUTSTATS, + |NFS_CAP_LAYOUTSTATS + | NFS_CAP_CLONE, .init_client = nfs41_init_client, .shutdown_client = nfs41_shutdown_client, .match_stateid = nfs41_match_stateid,
include/linux/nfs_fs_sb.h +1 -0
@@ -238,5 +238,6 @@ struct nfs_server {#define NFS_CAP_ALLOCATE (1U << 20)#define NFS_CAP_DEALLOCATE (1U << 21)#define NFS_CAP_LAYOUTSTATS (1U << 22) +#define NFS_CAP_CLONE (1U << 23)#endif
Signature · 1 line
1.8.3.1
RFC PATCH 7/11 nfs42: add .copy_range file operation
In reply to Peng Tao--- fs/nfs/nfs4file.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
fs/nfs/nfs4file.c +50 -0
@@ -4,6 +4,7 @@* Copyright (C) 1992 Rick Sladkey */ #include <linux/fs.h> +#include <linux/file.h> #include <linux/falloc.h> #include <linux/nfs_fs.h> #include "internal.h"
@@ -166,6 +167,54 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_treturn nfs42_proc_deallocate (filep, offset, len);return nfs42_proc_allocate (filep, offset, len); } + +static noinline int +nfs42_file_clone_range (struct file *src_file,struct file *dst_file, +loff_t src_off,size_t dst_off,loff_t count) +{ +struct inode *dst_inode =file_inode (dst_file); +struct inode *src_inode =file_inode (src_file); +int ret; + +/* src and dst must be different files */ +if (src_inode == dst_inode) +return -EINVAL ; + +/* XXX: do we lock at all? what if server needs CB_RECALL_LAYOUT? */ +if (dst_inode < src_inode) { +mutex_lock_nested (&dst_inode->i_mutex,I_MUTEX_PARENT ); +mutex_lock_nested (&src_inode->i_mutex,I_MUTEX_CHILD ); + }else { +mutex_lock_nested (&src_inode->i_mutex,I_MUTEX_PARENT ); +mutex_lock_nested (&dst_inode->i_mutex,I_MUTEX_CHILD ); + } + +/* flush all pending writes on both src and dst so that server +* has the latest data */ + ret =nfs_sync_inode (src_inode); +if (ret) + goto out_unlock; + ret =nfs_sync_inode (dst_inode); +if (ret) + goto out_unlock; + + ret =nfs42_proc_clone (src_file, dst_file, src_off, dst_off, count); + +/* truncate inode page cache of the dst range so that future reads can fetch +* new data from server */ +if (!ret) +truncate_inode_pages_range (&dst_inode->i_data, dst_off, dst_off + count -1 ); + +out_unlock: +if (dst_inode < src_inode) { +mutex_unlock (&src_inode->i_mutex); +mutex_unlock (&dst_inode->i_mutex); + }else { +mutex_unlock (&dst_inode->i_mutex); +mutex_unlock (&src_inode->i_mutex); + } +return ret; +}#endif /* CONFIG_NFS_V4_2 */ const struct file_operations nfs4_file_operations = {
@@ -187,6 +236,7 @@ const struct file_operations nfs4_file_operations = { .splice_write = iter_file_splice_write, #ifdef CONFIG_NFS_V4_2 .fallocate = nfs42_fallocate, + .clone_range = nfs42_file_clone_range, #endif /* CONFIG_NFS_V4_2 */ .check_flags = nfs_check_flags, .setlease = simple_nosetlease,
Signature · 1 line
1.8.3.1
RFC PATCH 8/11 nfs: get clone_blksize when probing fsinfo
In reply to Peng TaoNFSv42 CLONE operation is supposed to respect it.
--- fs/nfs/client.c | 1 + fs/nfs/nfs4proc.c | 1 + fs/nfs/nfs4xdr.c | 25 +++++++++++++++++++++++++ include/linux/nfs4.h | 1 + include/linux/nfs_fs_sb.h | 1 + include/linux/nfs_xdr.h | 1 + 6 files changed, 30 insertions(+)
fs/nfs/client.c +1 -0
@@ -764,6 +764,7 @@ static void nfs_server_set_fsinfo(struct nfs_server *server, server->time_delta = fsinfo->time_delta; + server->clone_blksize = fsinfo->clone_blksize;/* We're airborne Set socket buffersize */ rpc_setbufsize (server->client, server->wsize +100 , server->rsize +100 ); }
fs/nfs/nfs4proc.c +1 -0
@@ -239,6 +239,7 @@ const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZEFATTR4_WORD1_TIME_DELTA |FATTR4_WORD1_FS_LAYOUT_TYPES ,FATTR4_WORD2_LAYOUT_BLKSIZE + |FATTR4_WORD2_CLONE_BLKSIZE }; const u32 nfs4_fs_locations_bitmap[3] = {
fs/nfs/nfs4xdr.c +25 -0
@@ -4737,6 +4737,28 @@ static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,return 0 ; } +/* +* The granularity of a CLONE operation. +*/ +static int decode_attr_clone_blksize (struct xdr_stream *xdr,uint32_t *bitmap, +uint32_t *res) +{ +__be32 *p; + +dprintk ("%s: bitmap is %x\n" , __func__, bitmap[2 ]); + *res =0 ; +if (bitmap[2 ] &FATTR4_WORD2_CLONE_BLKSIZE ) { + p =xdr_inline_decode (xdr,4 ); +if (unlikely (!p)) { +print_overflow_msg (__func__, xdr); +return -EIO ; + } + *res =be32_to_cpup (p); + bitmap[2 ] &= ~FATTR4_WORD2_CLONE_BLKSIZE ; + } +return 0 ; +} +static int decode_fsinfo (struct xdr_stream *xdr,struct nfs_fsinfo *fsinfo) {unsigned int savep;
@@ -4771,6 +4793,9 @@ static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) status =decode_attr_layout_blksize (xdr, bitmap, &fsinfo->blksize);if (status) goto xdr_error; + status =decode_attr_clone_blksize (xdr, bitmap, &fsinfo->clone_blksize); +if (status) + goto xdr_error; status =verify_attr_len (xdr, savep, attrlen); xdr_error:
include/linux/nfs4.h +1 -0
@@ -422,6 +422,7 @@ enum lock_type4 {#define FATTR4_WORD2_LAYOUT_TYPES (1UL << 0)#define FATTR4_WORD2_LAYOUT_BLKSIZE (1UL << 1)#define FATTR4_WORD2_MDSTHRESHOLD (1UL << 4) +#define FATTR4_WORD2_CLONE_BLKSIZE (1UL << 13)#define FATTR4_WORD2_SECURITY_LABEL (1UL << 16)/* MDS threshold bitmap bits */
include/linux/nfs_fs_sb.h +1 -0
@@ -147,6 +147,7 @@ struct nfs_server {unsigned int acdirmax;unsigned int namelen;unsigned int options;/* extra options enabled by mount */ +unsigned int clone_blksize;/* granularity of a CLONE operation */ #define NFS_OPTION_FSCACHE 0x00000001/* - local caching enabled */ #define NFS_OPTION_MIGRATION 0x00000002/* - NFSv4 migration enabled */
include/linux/nfs_xdr.h +1 -0
@@ -141,6 +141,7 @@ struct nfs_fsinfo {__u32 lease_time;/* in seconds */ __u32 layouttype;/* supported pnfs layout driver */ __u32 blksize;/* preferred pnfs io block size */ +__u32 clone_blksize;/* granularity of a CLONE operation */ };struct nfs_fsstat {
Signature · 1 line
1.8.3.1
RFC PATCH 9/11 nfs42: respect clone_blksize
In reply to Peng Taodraft-ietf-nfsv4-minorversion2-38.txt says:
Both cl_src_offset and
cl_dst_offset must be aligned to the clone block size Section 12.2.1. The number of bytes to be cloned must be a multiple of the clone block size, except in the case in which cl_src_offset plus the number of bytes to be cloned is equal to the source file size.
--- fs/nfs/nfs4file.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/nfs/nfs4file.c +8 -0
@@ -174,12 +174,20 @@ nfs42_file_clone_range(struct file *src_file, struct file *dst_file, {struct inode *dst_inode =file_inode (dst_file);struct inode *src_inode =file_inode (src_file); +struct nfs_server *server =NFS_SERVER (dst_inode); +unsigned int bs = server->clone_blksize;int ret;/* src and dst must be different files */ if (src_inode == dst_inode)return -EINVAL ; +/* check alignment w.r.t. clone_blksize */ +if (bs) +if (!IS_ALIGNED (src_off, bs) || !IS_ALIGNED (dst_off, bs) || + (!IS_ALIGNED (count, bs) &&i_size_read (src_inode) != (src_off + count))) +return -EINVAL ; +/* XXX: do we lock at all? what if server needs CB_RECALL_LAYOUT? */ if (dst_inode < src_inode) {mutex_lock_nested (&dst_inode->i_mutex,I_MUTEX_PARENT );
Signature · 1 line
1.8.3.1
RFC PATCH 10/11 nfsd: Pass filehandle to nfs4_preprocess_stateid_op()
In reply to Peng TaoFrom: Anna Schumaker <[email protected]>
This will be needed so COPY can look up the saved_fh in addition to the current_fh.
--- fs/nfsd/nfs4proc.c | 16 +++++++++------- fs/nfsd/nfs4state.c | 5 ++--- fs/nfsd/state.h | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-)
fs/nfsd/nfs4proc.c +9 -7
@@ -776,8 +776,9 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,clear_bit (RQ_SPLICE_OK , &rqstp->rq_flags);/* check stateid */ - status =nfs4_preprocess_stateid_op (rqstp, cstate, &read->rd_stateid, -RD_STATE , &read->rd_filp, &read->rd_tmp_file); + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, + &read->rd_stateid,RD_STATE , + &read->rd_filp, &read->rd_tmp_file);if (status) {dprintk ("NFSD: nfsd4_read: couldn't process stateid!\n" ); goto out;
@@ -923,7 +924,8 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (setattr->sa_iattr.ia_valid &ATTR_SIZE ) { status =nfs4_preprocess_stateid_op (rqstp, cstate, - &setattr->sa_stateid,WR_STATE ,NULL ,NULL ); + &cstate->current_fh, &setattr->sa_stateid, +WR_STATE ,NULL ,NULL );if (status) {dprintk ("NFSD: nfsd4_setattr: couldn't process stateid!\n" );return status;
@@ -987,8 +989,8 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (write->wr_offset >=OFFSET_MAX )return nfserr_inval; - status =nfs4_preprocess_stateid_op (rqstp, cstate, stateid,WR_STATE , - &filp,NULL ); + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, + stateid,WR_STATE , &filp,NULL );if (status) {dprintk ("NFSD: nfsd4_write: couldn't process stateid!\n" );return status;
@@ -1018,7 +1020,7 @@ nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,__be32 status = nfserr_notsupp;struct file *file; - status =nfs4_preprocess_stateid_op (rqstp, cstate, + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, &fallocate->falloc_stateid,WR_STATE , &file,NULL );if (status != nfs_ok) {
@@ -1057,7 +1059,7 @@ nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,__be32 status;struct file *file; - status =nfs4_preprocess_stateid_op (rqstp, cstate, + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, &seek->seek_stateid,RD_STATE , &file,NULL );if (status) {
fs/nfsd/nfs4state.c +2 -3
@@ -4645,10 +4645,9 @@ nfs4_check_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfs4_stid *s,*/ __be32 nfs4_preprocess_stateid_op (struct svc_rqst *rqstp, -struct nfsd4_compound_state *cstate,stateid_t *stateid, -int flags,struct file **filpp,bool *tmp_file) +struct nfsd4_compound_state *cstate,struct svc_fh *fhp, +stateid_t *stateid,int flags,struct file **filpp,bool *tmp_file) { -struct svc_fh *fhp = &cstate->current_fh;struct inode *ino =d_inode (fhp->fh_dentry);struct net *net =SVC_NET (rqstp);struct nfsd_net *nn =net_generic (net, nfsd_net_id);
fs/nfsd/state.h +2 -2
@@ -584,8 +584,8 @@ struct nfsd4_compound_state;struct nfsd_net ;extern __be32 nfs4_preprocess_stateid_op (struct svc_rqst *rqstp, -struct nfsd4_compound_state *cstate,stateid_t *stateid, -int flags,struct file **filp,bool *tmp_file); +struct nfsd4_compound_state *cstate,struct svc_fh *fhp, +stateid_t *stateid,int flags,struct file **filp,bool *tmp_file);__be32 nfsd4_lookup_stateid (struct nfsd4_compound_state *cstate,stateid_t *stateid,unsigned char typemask,struct nfs4_stid **s,struct nfsd_net *nn);
Signature · 1 line
1.8.3.1
RFC PATCH 11/11 NFSD: Implement the CLONE call
In reply to Peng TaoFrom: Anna Schumaker <[email protected]>
I can simply call vfs_file_clone_range() and have the vfs do the right thing for the filesystem being exported.
--- fs/nfsd/nfs4proc.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 21 ++++++++++++++ fs/nfsd/vfs.c | 7 +++++ fs/nfsd/vfs.h | 1 + fs/nfsd/xdr4.h | 10 +++++++ include/linux/nfs4.h | 4 +-- 6 files changed, 120 insertions(+), 2 deletions(-)
fs/nfsd/nfs4proc.c +79 -0
@@ -1014,6 +1014,79 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }static __be32 +nfsd4_verify_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_clone *clone,struct file **src,struct file **dst) +{ +struct inode *src_ino, *dst_ino; +__be32 status; + + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->save_fh, + &clone->cl_src_stateid,RD_STATE , + src,NULL ); +if (status) { +dprintk ("NFSD: %s: couldn't process src stateid!\n" , __func__); +return status; + } + + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, + &clone->cl_dst_stateid,WR_STATE , + dst,NULL ); +if (status) { +dprintk ("NFSD: %s: couldn't process dst stateid!\n" , __func__); +fput (*src); + } + +/* a few extra check to make sure we send back proper errors per RFC */ + src_ino =file_inode (*src); + dst_ino =file_inode (*dst); + +if (S_ISDIR (src_ino->i_mode) ||S_ISDIR (dst_ino->i_mode)) { + status = nfserr_wrong_type; + goto out_fput; + } + +if (src_ino == dst_ino) { + status = nfserr_inval; + goto out_fput; + } + +if (!(*src)->f_op || !(*src)->f_op->clone_range) { + status = nfserr_notsupp; + goto out_fput; + } +out: +return status; +out_fput: +fput (*src); +fput (*dst); + goto out; +} + +static __be32 +nfsd4_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_clone *clone) +{ +int ret; +__be32 status; +struct file *src =NULL , *dst =NULL ; + + status =nfsd4_verify_clone (rqstp, cstate, clone, &src, &dst); +if (status) +return status; + + ret =nfsd4_clone_range (src, dst, clone->cl_src_pos, + clone->cl_count, clone->cl_dst_pos); +if (ret <0 ) + status =nfserrno (ret); +else + status = nfs_ok; + +fput (src); +fput (dst); +return status; +} + +static __be32 nfsd4_fallocate (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,struct nfsd4_fallocate *fallocate,int flags) {
@@ -2283,6 +2356,12 @@ static struct nfsd4_operation nfsd4_ops[] = { .op_name = "OP_DEALLOCATE", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, + [OP_CLONE] = { + .op_func = (nfsd4op_func)nfsd4_clone, + .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, + .op_name = "OP_CLONE", + .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, + }, [OP_SEEK] = { .op_func = (nfsd4op_func)nfsd4_seek, .op_name = "OP_SEEK",
fs/nfsd/nfs4xdr.c +21 -0
@@ -1675,6 +1675,25 @@ nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp, }static __be32 +nfsd4_decode_clone (struct nfsd4_compoundargs *argp,struct nfsd4_clone *clone) +{ +DECODE_HEAD ; + + status =nfsd4_decode_stateid (argp, &clone->cl_src_stateid); +if (status) +return status; + status =nfsd4_decode_stateid (argp, &clone->cl_dst_stateid); +if (status) +return status; + +READ_BUF (8 +8 +8 ); + p =xdr_decode_hyper (p, &clone->cl_src_pos); + p =xdr_decode_hyper (p, &clone->cl_dst_pos); + p =xdr_decode_hyper (p, &clone->cl_count); +DECODE_TAIL ; +} + +static __be32 nfsd4_decode_seek (struct nfsd4_compoundargs *argp,struct nfsd4_seek *seek) {DECODE_HEAD ;
@@ -1785,6 +1804,7 @@ static nfsd4_dec nfsd4_dec_ops[] = { [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek, [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp, + [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone, }; static inline bool
@@ -4249,6 +4269,7 @@ static nfsd4_enc nfsd4_enc_ops[] = { [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_noop, [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek, [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop, + [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop, };/*
fs/nfsd/vfs.c +7 -0
@@ -36,6 +36,7 @@#endif /* CONFIG_NFSD_V3 */ #ifdef CONFIG_NFSD_V4 +#include "../internal.h" #include "acl.h" #include "idmap.h" #endif /* CONFIG_NFSD_V4 */
@@ -498,6 +499,12 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, }#endif +int nfsd4_clone_range (struct file *src,struct file *dst,u64 src_pos, +u64 count,u64 dst_pos) +{ +return vfs_file_clone_range (src, dst, src_pos, count, dst_pos); +} +__be32 nfsd4_vfs_fallocate (struct svc_rqst *rqstp,struct svc_fh *fhp,struct file *file,loff_t offset,loff_t len,int flags)
fs/nfsd/vfs.h +1 -0
@@ -56,6 +56,7 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *, struct xdr_netobj *);__be32 nfsd4_vfs_fallocate (struct svc_rqst *,struct svc_fh *,struct file *,loff_t ,loff_t ,int ); +int nfsd4_clone_range (struct file *,struct file *,u64 ,u64 ,u64 );#endif /* CONFIG_NFSD_V4 */ __be32 nfsd_create(struct svc_rqst *, struct svc_fh *, char *name, int len, struct iattr *attrs,
fs/nfsd/xdr4.h +10 -0
@@ -491,6 +491,15 @@ struct nfsd4_fallocate {u64 falloc_length; }; +struct nfsd4_clone { +/* request */ +stateid_t cl_src_stateid; +stateid_t cl_dst_stateid; +u64 cl_src_pos; +u64 cl_dst_pos; +u64 cl_count; +}; +struct nfsd4_seek {/* request */ stateid_t seek_stateid;
@@ -555,6 +564,7 @@ struct nfsd4_op {/* NFSv4.2 */ struct nfsd4_fallocate allocate;struct nfsd4_fallocate deallocate; +struct nfsd4_clone clone;struct nfsd4_seek seek; } u;struct nfs4_replay * replay;
include/linux/nfs4.h +2 -2
@@ -139,10 +139,10 @@ enum nfs_opnum4 {Needs to be updated if more operations are defined in future.*/ #define FIRST_NFS4_OP OP_ACCESS -#define LAST_NFS4_OP OP_WRITE_SAME#define LAST_NFS40_OP OP_RELEASE_LOCKOWNER#define LAST_NFS41_OP OP_RECLAIM_COMPLETE -#define LAST_NFS42_OP OP_WRITE_SAME +#define LAST_NFS42_OP OP_CLONE +#define LAST_NFS4_OP LAST_NFS42_OPenum nfsstat4 {NFS4_OK =0 ,
Signature · 1 line
1.8.3.1
Quoted 7 lines · Peng Tao
Hi all,
This patchset adds NFSv42 COPY support to nfs and nfsd. As suggested by Christoph, it pulls btrfs BTRFS_IOC_CLONE/BTRFS_IOC_CLONE_RANGE ioctls to generic layer and adds a new file operation to call down to file systems. Then the CLONE ioctl is implemented for NFS and NFSD.
Quoted 10 lines
I took a slightly different approach from Anna's NFS42 COPY implementation
(http://www.spinics.net/lists/linux-nfs/msg53009.html) mainly because CLONE has different requirements than COPY. And the main differences between the two are:
1. well, CLONE is supported rather than COPY.
2.vfs_file_clone_range()does not expect file systems to do data copy, and thus norw_verify_area()required.
3. clone does not expect partial success.
4. clone does not fall back to data copy if underlying storage does not support it.
5. no new system call required. We reuse existing BTRFS_IOC_CLONE/BTRFS_IOC_CLONE_RANGE and make it generic to all file systems.
I should have mentioned that this overlaps with Anna's COPY work. We'll deal with the conflicts after figuring out what to do with both.
Cheers,
Tao
Quoted 49 lines
Cheers,
TaoAnna Schumaker (2):
nfsd: Pass filehandle tonfs4_preprocess_stateid_op()
NFSD: Implement the CLONE callPeng Tao (9):
vfs: pull btrfs clone API to vfs layer vfs/btrfs: add .clone_range file operation
nfs42:decode_layoutstatsdoes not need res parameter
nfs42: remove unused declaration
nfs42: add CLONE xdr functions
nfs42: add CLONE proc functions
nfs42: add .copy_range file operation
nfs: getclone_blksizewhen probing fsinfo
nfs42: respectclone_blksizefs/btrfs/ctree.h | 2 + fs/btrfs/file.c | 1 + fs/btrfs/ioctl.c | 68 ++++-------------------------- fs/ioctl.c | 30 +++++++++++++ fs/nfs/client.c | 1 + fs/nfs/nfs42.h | 3 +- fs/nfs/nfs42proc.c | 71 +++++++++++++++++++++++++++++++ fs/nfs/nfs42xdr.c | 102 +++++++++++++++++++++++++++++++++++++++++++-- fs/nfs/nfs4file.c | 58 ++++++++++++++++++++++++++ fs/nfs/nfs4proc.c | 4 +- fs/nfs/nfs4xdr.c | 26 ++++++++++++ fs/nfsd/nfs4proc.c | 91 ++++++++++++++++++++++++++++++++++++---- fs/nfsd/nfs4state.c | 5 +-- fs/nfsd/nfs4xdr.c | 21 ++++++++++ fs/nfsd/state.h | 4 +- fs/nfsd/vfs.c | 7 ++++ fs/nfsd/vfs.h | 1 + fs/nfsd/xdr4.h | 10 +++++ fs/read_write.c | 45 ++++++++++++++++++++ include/linux/fs.h | 4 ++ include/linux/nfs4.h | 7 +++- include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 20 +++++++++ include/uapi/linux/btrfs.h | 10 ----- include/uapi/linux/fs.h | 9 ++++ 25 files changed, 510 insertions(+), 92 deletions(-)--
1.8.3.1
Hey Tao,
Quoted 18 lines · Peng Tao
Quoted 7 lines · Peng Tao
Hi all,
This patchset adds NFSv42 COPY support to nfs and nfsd. As suggested by Christoph, it pulls btrfs BTRFS_IOC_CLONE/BTRFS_IOC_CLONE_RANGE ioctls to generic layer and adds a new file operation to call down to file systems. Then the CLONE ioctl is implemented for NFS and NFSD.
Quoted 10 lines
I took a slightly different approach from Anna's NFS42 COPY implementation
(http://www.spinics.net/lists/linux-nfs/msg53009.html) mainly because CLONE has different requirements than COPY. And the main differences between the two are:
1. well, CLONE is supported rather than COPY.
2.vfs_file_clone_range()does not expect file systems to do data copy, and thus norw_verify_area()required.
3. clone does not expect partial success.
4. clone does not fall back to data copy if underlying storage does not support it.
5. no new system call required. We reuse existing BTRFS_IOC_CLONE/BTRFS_IOC_CLONE_RANGE and make it generic to all file systems.
Quoted 2 lines
I should have mentioned that this overlaps with Anna's COPY work. We'll deal with the conflicts after figuring out what to do with both.
Since we're both working on this at the same time, can you change the title of this patch series to "NFSv42 CLONE"? I got confused when I saw these patches :)
Thanks,
Anna
Quoted 53 lines
Cheers,
TaoQuoted 49 lines
Cheers,
TaoAnna Schumaker (2):
nfsd: Pass filehandle tonfs4_preprocess_stateid_op()
NFSD: Implement the CLONE callPeng Tao (9):
vfs: pull btrfs clone API to vfs layer vfs/btrfs: add .clone_range file operation
nfs42:decode_layoutstatsdoes not need res parameter
nfs42: remove unused declaration
nfs42: add CLONE xdr functions
nfs42: add CLONE proc functions
nfs42: add .copy_range file operation
nfs: getclone_blksizewhen probing fsinfo
nfs42: respectclone_blksizefs/btrfs/ctree.h | 2 + fs/btrfs/file.c | 1 + fs/btrfs/ioctl.c | 68 ++++-------------------------- fs/ioctl.c | 30 +++++++++++++ fs/nfs/client.c | 1 + fs/nfs/nfs42.h | 3 +- fs/nfs/nfs42proc.c | 71 +++++++++++++++++++++++++++++++ fs/nfs/nfs42xdr.c | 102 +++++++++++++++++++++++++++++++++++++++++++-- fs/nfs/nfs4file.c | 58 ++++++++++++++++++++++++++ fs/nfs/nfs4proc.c | 4 +- fs/nfs/nfs4xdr.c | 26 ++++++++++++ fs/nfsd/nfs4proc.c | 91 ++++++++++++++++++++++++++++++++++++---- fs/nfsd/nfs4state.c | 5 +-- fs/nfsd/nfs4xdr.c | 21 ++++++++++ fs/nfsd/state.h | 4 +- fs/nfsd/vfs.c | 7 ++++ fs/nfsd/vfs.h | 1 + fs/nfsd/xdr4.h | 10 +++++ fs/read_write.c | 45 ++++++++++++++++++++ include/linux/fs.h | 4 ++ include/linux/nfs4.h | 7 +++- include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 20 +++++++++ include/uapi/linux/btrfs.h | 10 ----- include/uapi/linux/fs.h | 9 ++++ 25 files changed, 510 insertions(+), 92 deletions(-)--
1.8.3.1
Re: [PATCH RFC 03/11] nfs42: decode_layoutstats does not need res parameter
In reply to Peng TaoHey Tao,
Should this be sent as a separate patch? It could probably be included now, rather than waiting on the rest of the CLONE patches to filter through.
Thanks,
Anna
Quoted 30 lines · Peng Tao
Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Peng Tao <[email protected]>--- fs/nfs/nfs42xdr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fs/nfs/nfs42xdr.c +2
-3@@ -238,8 +238,7 @@ out_overflow:return -EIO ; } -static int decode_layoutstats (struct xdr_stream *xdr, -struct nfs42_layoutstat_res *res) +static int decode_layoutstats (struct xdr_stream *xdr) {return decode_op_hdr (xdr,OP_LAYOUTSTATS ); }@@ -343,7 +342,7 @@ static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp, goto out;WARN_ON (res->num_dev >PNFS_LAYOUTSTATS_MAXDEV );for (i =0 ; i < res->num_dev; i++) { - status =decode_layoutstats (xdr, res); + status =decode_layoutstats (xdr);if (status) goto out; }
Re: [PATCH RFC 04/11] nfs42: remove unused declaration
In reply to Peng TaoHi Tao,
Quoted 11 lines · Peng Tao
Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Peng Tao <[email protected]>--- fs/nfs/nfs42.h | 2 -- 1 file changed, 2 deletions(-)fs/nfs/nfs42.h +0
-0
fs/nfs/nfs42.h int nfs42_proc_deallocate(struct file *, loff_t, loff_t); · line 21
Quoted 5 lines
fs/nfs/nfs42.h +0
-2@@ -17,7 +17,5 @@ int nfs42_proc_deallocate(struct file *, loff_t, loff_t);loff_t nfs42_proc_llseek (struct file *,loff_t ,int );int nfs42_proc_layoutstats_generic (struct nfs_server *,struct nfs42_layoutstat_data *); -/* nfs4.2xdr.h */ -extern struct rpc_procinfo nfs4_2_procedures[];
Same thing here. Maybe submit both patches together as a cleanup patch series?
Thanks,
Anna
Quoted 3 lines
fs/nfs/nfs42.h +0
-0#endif /* __LINUX_FS_NFS_NFS4_2_H */
Re: [PATCH RFC 04/11] nfs42: remove unused declaration
Quoted 9 lines · Anna Schumaker
Hi Tao,
Quoted 6 lines · Peng Tao
Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Peng Tao <[email protected]>--- fs/nfs/nfs42.h | 2 -- 1 file changed, 2 deletions(-)
Quoted 13 lines
fs/nfs/nfs42.h int nfs42_proc_deallocate(struct file *, loff_t, loff_t); · line 21
Quoted 10 lines
fs/nfs/nfs42.h +0
-2@@ -17,7 +17,5 @@ int nfs42_proc_deallocate(struct file *, loff_t, loff_t);loff_t nfs42_proc_llseek (struct file *,loff_t ,int );int nfs42_proc_layoutstats_generic (struct nfs_server *,struct nfs42_layoutstat_data *); -/* nfs4.2xdr.h */ -extern struct rpc_procinfo nfs4_2_procedures[];Same thing here. Maybe submit both patches together as a cleanup patch series?
Will do. Thanks!
Cheers,
Tao
Quoted 11 lines
Thanks,
Annafs/nfs/nfs42.h int nfs42_proc_deallocate(struct file *, loff_t, loff_t); · line 21
Quoted 3 lines
fs/nfs/nfs42.h +0
-0#endif /* __LINUX_FS_NFS_NFS4_2_H */ --
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RFC 11/11] NFSD: Implement the CLONE call
In reply to Peng TaoQuoted 33 lines · Peng Tao
From: Anna Schumaker <[email protected]>
I can simply call
vfs_file_clone_range()and have the vfs do the right thing for the filesystem being exported.Signed-off-by Anna Schumaker <[email protected]>[hch: change to implement the CLONE op instead of COPY]Signed-off-by Christoph Hellwig <[email protected]>Signed-off-by Peng Tao <[email protected]>--- fs/nfsd/nfs4proc.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 21 ++++++++++++++ fs/nfsd/vfs.c | 7 +++++ fs/nfsd/vfs.h | 1 + fs/nfsd/xdr4.h | 10 +++++++ include/linux/nfs4.h | 4 +-- 6 files changed, 120 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +7
-0@@ -1014,6 +1014,79 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }static __be32 +nfsd4_verify_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_clone *clone,struct file **src,struct file **dst) +{ +struct inode *src_ino, *dst_ino; +__be32 status; + + status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
fs/nfsd/nfs4proc.c nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 1033
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ &clone->cl_src_stateid,RD_STATE , + src, NULL); +if (status) { +dprintk ("NFSD: %s: couldn't process src stateid!\n" , __func__); +return status; + } + + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, + &clone->cl_dst_stateid,WR_STATE , + dst,NULL );
I think this is the first case where we have to verify two stateid's.... But, OK, I think this works, and you're correct that putting the file is all that should be needed.
--b.
Quoted 202 lines
fs/nfsd/nfs4proc.c +62
-0+if (status) { +dprintk ("NFSD: %s: couldn't process dst stateid!\n" , __func__); +fput (*src); + } + +/* a few extra check to make sure we send back proper errors per RFC */ + src_ino =file_inode (*src); + dst_ino =file_inode (*dst); + +if (S_ISDIR (src_ino->i_mode) ||S_ISDIR (dst_ino->i_mode)) { + status = nfserr_wrong_type; + goto out_fput; + } + +if (src_ino == dst_ino) { + status = nfserr_inval; + goto out_fput; + } + +if (!(*src)->f_op || !(*src)->f_op->clone_range) { + status = nfserr_notsupp; + goto out_fput; + } +out: +return status; +out_fput: +fput (*src); +fput (*dst); + goto out; +} + +static __be32 +nfsd4_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_clone *clone) +{ +int ret; +__be32 status; +struct file *src =NULL , *dst =NULL ; + + status =nfsd4_verify_clone (rqstp, cstate, clone, &src, &dst); +if (status) +return status; + + ret =nfsd4_clone_range (src, dst, clone->cl_src_pos, + clone->cl_count, clone->cl_dst_pos); +if (ret <0 ) + status =nfserrno (ret); +else + status = nfs_ok; + +fput (src); +fput (dst); +return status; +} + +static __be32 nfsd4_fallocate (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,struct nfsd4_fallocate *fallocate,int flags) {@@ -2283,6 +2356,12 @@ static struct nfsd4_operation nfsd4_ops[] = { .op_name = "OP_DEALLOCATE", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, + [OP_CLONE] = { + .op_func = (nfsd4op_func)nfsd4_clone, + .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, + .op_name = "OP_CLONE", + .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, + }, [OP_SEEK] = { .op_func = (nfsd4op_func)nfsd4_seek, .op_name = "OP_SEEK",fs/nfsd/nfs4xdr.c +21
-0@@ -1675,6 +1675,25 @@ nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp, }static __be32 +nfsd4_decode_clone (struct nfsd4_compoundargs *argp,struct nfsd4_clone *clone) +{ +DECODE_HEAD ; + + status =nfsd4_decode_stateid (argp, &clone->cl_src_stateid); +if (status) +return status; + status =nfsd4_decode_stateid (argp, &clone->cl_dst_stateid); +if (status) +return status; + +READ_BUF (8 +8 +8 ); + p =xdr_decode_hyper (p, &clone->cl_src_pos); + p =xdr_decode_hyper (p, &clone->cl_dst_pos); + p =xdr_decode_hyper (p, &clone->cl_count); +DECODE_TAIL ; +} + +static __be32 nfsd4_decode_seek (struct nfsd4_compoundargs *argp,struct nfsd4_seek *seek) {DECODE_HEAD ;@@ -1785,6 +1804,7 @@ static nfsd4_dec nfsd4_dec_ops[] = { [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek, [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp, + [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone, }; static inline bool@@ -4249,6 +4269,7 @@ static nfsd4_enc nfsd4_enc_ops[] = { [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_noop, [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek, [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop, + [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop, };/* fs/nfsd/vfs.c +7
-0@@ -36,6 +36,7 @@#endif /* CONFIG_NFSD_V3 */ #ifdef CONFIG_NFSD_V4 +#include "../internal.h" #include "acl.h" #include "idmap.h" #endif /* CONFIG_NFSD_V4 */ @@ -498,6 +499,12 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, }#endif +int nfsd4_clone_range (struct file *src,struct file *dst,u64 src_pos, +u64 count,u64 dst_pos) +{ +return vfs_file_clone_range (src, dst, src_pos, count, dst_pos); +} +__be32 nfsd4_vfs_fallocate (struct svc_rqst *rqstp,struct svc_fh *fhp,struct file *file,loff_t offset,loff_t len,int flags)fs/nfsd/vfs.h +1
-0@@ -56,6 +56,7 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *, struct xdr_netobj *);__be32 nfsd4_vfs_fallocate (struct svc_rqst *,struct svc_fh *,struct file *,loff_t ,loff_t ,int ); +int nfsd4_clone_range (struct file *,struct file *,u64 ,u64 ,u64 );#endif /* CONFIG_NFSD_V4 */ __be32 nfsd_create(struct svc_rqst *, struct svc_fh *, char *name, int len, struct iattr *attrs,fs/nfsd/xdr4.h +10
-0@@ -491,6 +491,15 @@ struct nfsd4_fallocate {u64 falloc_length; }; +struct nfsd4_clone { +/* request */ +stateid_t cl_src_stateid; +stateid_t cl_dst_stateid; +u64 cl_src_pos; +u64 cl_dst_pos; +u64 cl_count; +}; +struct nfsd4_seek {/* request */ stateid_t seek_stateid;@@ -555,6 +564,7 @@ struct nfsd4_op {/* NFSv4.2 */ struct nfsd4_fallocate allocate;struct nfsd4_fallocate deallocate; +struct nfsd4_clone clone;struct nfsd4_seek seek; } u;struct nfs4_replay * replay;include/linux/nfs4.h +2
-2@@ -139,10 +139,10 @@ enum nfs_opnum4 {Needs to be updated if more operations are defined in future.*/ #define FIRST_NFS4_OP OP_ACCESS -#define LAST_NFS4_OP OP_WRITE_SAME#define LAST_NFS40_OP OP_RELEASE_LOCKOWNER#define LAST_NFS41_OP OP_RECLAIM_COMPLETE -#define LAST_NFS42_OP OP_WRITE_SAME +#define LAST_NFS42_OP OP_CLONE +#define LAST_NFS4_OP LAST_NFS42_OPenum nfsstat4 {NFS4_OK =0 ,Signature · 1 line
1.8.3.1
Re: [PATCH RFC 11/11] NFSD: Implement the CLONE call
In reply to Peng TaoQuoted 82 lines · Peng Tao
From: Anna Schumaker <[email protected]>
I can simply call
vfs_file_clone_range()and have the vfs do the right thing for the filesystem being exported.Signed-off-by Anna Schumaker <[email protected]>[hch: change to implement the CLONE op instead of COPY]Signed-off-by Christoph Hellwig <[email protected]>Signed-off-by Peng Tao <[email protected]>--- fs/nfsd/nfs4proc.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 21 ++++++++++++++ fs/nfsd/vfs.c | 7 +++++ fs/nfsd/vfs.h | 1 + fs/nfsd/xdr4.h | 10 +++++++ include/linux/nfs4.h | 4 +-- 6 files changed, 120 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +56
-0@@ -1014,6 +1014,79 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }static __be32 +nfsd4_verify_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_clone *clone,struct file **src,struct file **dst) +{ +struct inode *src_ino, *dst_ino; +__be32 status; + + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->save_fh, + &clone->cl_src_stateid,RD_STATE , + src,NULL ); +if (status) { +dprintk ("NFSD: %s: couldn't process src stateid!\n" , __func__); +return status; + } + + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, + &clone->cl_dst_stateid,WR_STATE , + dst,NULL ); +if (status) { +dprintk ("NFSD: %s: couldn't process dst stateid!\n" , __func__); +fput (*src); + } + +/* a few extra check to make sure we send back proper errors per RFC */ + src_ino =file_inode (*src); + dst_ino =file_inode (*dst); + +if (S_ISDIR (src_ino->i_mode) ||S_ISDIR (dst_ino->i_mode)) { + status = nfserr_wrong_type; + goto out_fput; + } + +if (src_ino == dst_ino) { + status = nfserr_inval; + goto out_fput; + } + +if (!(*src)->f_op || !(*src)->f_op->clone_range) { + status = nfserr_notsupp; + goto out_fput; + } +out: +return status; +out_fput: +fput (*src); +fput (*dst); + goto out; +} + +static __be32 +nfsd4_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_clone *clone) +{ +int ret; +__be32 status; +struct file *src =NULL , *dst =NULL ; +
fs/nfsd/nfs4proc.c nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 1082
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ status =nfsd4_verify_clone (rqstp, cstate, clone, &src, &dst); +if (status) +return status; + + ret =nfsd4_clone_range (src, dst, clone->cl_src_pos, + clone->cl_count, clone->cl_dst_pos); +if (ret <0 ) + status =nfserrno (ret); +else + status = nfs_ok;
Can ret be positive, then? If so are we discarding some information? (E.g. can clone_range return a success having cloned only part of the range?)
--b.
Quoted 153 lines
fs/nfsd/nfs4proc.c +13
-0+ +fput (src); +fput (dst); +return status; +} + +static __be32 nfsd4_fallocate (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,struct nfsd4_fallocate *fallocate,int flags) {@@ -2283,6 +2356,12 @@ static struct nfsd4_operation nfsd4_ops[] = { .op_name = "OP_DEALLOCATE", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, + [OP_CLONE] = { + .op_func = (nfsd4op_func)nfsd4_clone, + .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, + .op_name = "OP_CLONE", + .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, + }, [OP_SEEK] = { .op_func = (nfsd4op_func)nfsd4_seek, .op_name = "OP_SEEK",fs/nfsd/nfs4xdr.c +21
-0@@ -1675,6 +1675,25 @@ nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp, }static __be32 +nfsd4_decode_clone (struct nfsd4_compoundargs *argp,struct nfsd4_clone *clone) +{ +DECODE_HEAD ; + + status =nfsd4_decode_stateid (argp, &clone->cl_src_stateid); +if (status) +return status; + status =nfsd4_decode_stateid (argp, &clone->cl_dst_stateid); +if (status) +return status; + +READ_BUF (8 +8 +8 ); + p =xdr_decode_hyper (p, &clone->cl_src_pos); + p =xdr_decode_hyper (p, &clone->cl_dst_pos); + p =xdr_decode_hyper (p, &clone->cl_count); +DECODE_TAIL ; +} + +static __be32 nfsd4_decode_seek (struct nfsd4_compoundargs *argp,struct nfsd4_seek *seek) {DECODE_HEAD ;@@ -1785,6 +1804,7 @@ static nfsd4_dec nfsd4_dec_ops[] = { [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek, [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp, + [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone, }; static inline bool@@ -4249,6 +4269,7 @@ static nfsd4_enc nfsd4_enc_ops[] = { [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_noop, [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek, [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop, + [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop, };/* fs/nfsd/vfs.c +7
-0@@ -36,6 +36,7 @@#endif /* CONFIG_NFSD_V3 */ #ifdef CONFIG_NFSD_V4 +#include "../internal.h" #include "acl.h" #include "idmap.h" #endif /* CONFIG_NFSD_V4 */ @@ -498,6 +499,12 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, }#endif +int nfsd4_clone_range (struct file *src,struct file *dst,u64 src_pos, +u64 count,u64 dst_pos) +{ +return vfs_file_clone_range (src, dst, src_pos, count, dst_pos); +} +__be32 nfsd4_vfs_fallocate (struct svc_rqst *rqstp,struct svc_fh *fhp,struct file *file,loff_t offset,loff_t len,int flags)fs/nfsd/vfs.h +1
-0@@ -56,6 +56,7 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *, struct xdr_netobj *);__be32 nfsd4_vfs_fallocate (struct svc_rqst *,struct svc_fh *,struct file *,loff_t ,loff_t ,int ); +int nfsd4_clone_range (struct file *,struct file *,u64 ,u64 ,u64 );#endif /* CONFIG_NFSD_V4 */ __be32 nfsd_create(struct svc_rqst *, struct svc_fh *, char *name, int len, struct iattr *attrs,fs/nfsd/xdr4.h +10
-0@@ -491,6 +491,15 @@ struct nfsd4_fallocate {u64 falloc_length; }; +struct nfsd4_clone { +/* request */ +stateid_t cl_src_stateid; +stateid_t cl_dst_stateid; +u64 cl_src_pos; +u64 cl_dst_pos; +u64 cl_count; +}; +struct nfsd4_seek {/* request */ stateid_t seek_stateid;@@ -555,6 +564,7 @@ struct nfsd4_op {/* NFSv4.2 */ struct nfsd4_fallocate allocate;struct nfsd4_fallocate deallocate; +struct nfsd4_clone clone;struct nfsd4_seek seek; } u;struct nfs4_replay * replay;include/linux/nfs4.h +2
-2@@ -139,10 +139,10 @@ enum nfs_opnum4 {Needs to be updated if more operations are defined in future.*/ #define FIRST_NFS4_OP OP_ACCESS -#define LAST_NFS4_OP OP_WRITE_SAME#define LAST_NFS40_OP OP_RELEASE_LOCKOWNER#define LAST_NFS41_OP OP_RECLAIM_COMPLETE -#define LAST_NFS42_OP OP_WRITE_SAME +#define LAST_NFS42_OP OP_CLONE +#define LAST_NFS4_OP LAST_NFS42_OPenum nfsstat4 {NFS4_OK =0 ,Signature · 1 line
1.8.3.1
Re: [PATCH RFC 11/11] NFSD: Implement the CLONE call
Quoted 89 lines · J. Bruce Fields
Quoted 88 lines · Peng Tao
From: Anna Schumaker <[email protected]>
I can simply call
vfs_file_clone_range()and have the vfs do the right thing for the filesystem being exported.Signed-off-by Anna Schumaker <[email protected]>[hch: change to implement the CLONE op instead of COPY]Signed-off-by Christoph Hellwig <[email protected]>Signed-off-by Peng Tao <[email protected]>--- fs/nfsd/nfs4proc.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 21 ++++++++++++++ fs/nfsd/vfs.c | 7 +++++ fs/nfsd/vfs.h | 1 + fs/nfsd/xdr4.h | 10 +++++++ include/linux/nfs4.h | 4 +-- 6 files changed, 120 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +62
-0@@ -1014,6 +1014,79 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }static __be32 +nfsd4_verify_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_clone *clone,struct file **src,struct file **dst) +{ +struct inode *src_ino, *dst_ino; +__be32 status; + + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->save_fh, + &clone->cl_src_stateid,RD_STATE , + src,NULL ); +if (status) { +dprintk ("NFSD: %s: couldn't process src stateid!\n" , __func__); +return status; + } + + status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, + &clone->cl_dst_stateid,WR_STATE , + dst,NULL ); +if (status) { +dprintk ("NFSD: %s: couldn't process dst stateid!\n" , __func__); +fput (*src); + } + +/* a few extra check to make sure we send back proper errors per RFC */ + src_ino =file_inode (*src); + dst_ino =file_inode (*dst); + +if (S_ISDIR (src_ino->i_mode) ||S_ISDIR (dst_ino->i_mode)) { + status = nfserr_wrong_type; + goto out_fput; + } + +if (src_ino == dst_ino) { + status = nfserr_inval; + goto out_fput; + } + +if (!(*src)->f_op || !(*src)->f_op->clone_range) { + status = nfserr_notsupp; + goto out_fput; + } +out: +return status; +out_fput: +fput (*src); +fput (*dst); + goto out; +} + +static __be32 +nfsd4_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_clone *clone) +{ +int ret; +__be32 status; +struct file *src =NULL , *dst =NULL ; + + status =nfsd4_verify_clone (rqstp, cstate, clone, &src, &dst); +if (status) +return status; + + ret =nfsd4_clone_range (src, dst, clone->cl_src_pos, + clone->cl_count, clone->cl_dst_pos);
Quoted 9 lines
fs/nfsd/nfs4proc.c nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 1082
Quoted 4 lines
fs/nfsd/nfs4proc.c +4
-0+if (ret <0 ) + status =nfserrno (ret); +else + status = nfs_ok;Can ret be positive, then? If so are we discarding some information? (E.g. can
clone_rangereturn a success having cloned only part of the range?)
I don't think we want partial success. NFS42 CLONE operation response does not have a field to tell partial success either.
The btrfs CLONE ioctl also does not seem to return partial success. I think I should document it in the patch adding the new file operation.
Thanks,
Tao
Quoted 155 lines
--b.
Quoted 153 lines
fs/nfsd/nfs4proc.c +13
-0+ +fput (src); +fput (dst); +return status; +} + +static __be32 nfsd4_fallocate (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,struct nfsd4_fallocate *fallocate,int flags) {@@ -2283,6 +2356,12 @@ static struct nfsd4_operation nfsd4_ops[] = { .op_name = "OP_DEALLOCATE", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, + [OP_CLONE] = { + .op_func = (nfsd4op_func)nfsd4_clone, + .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, + .op_name = "OP_CLONE", + .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, + }, [OP_SEEK] = { .op_func = (nfsd4op_func)nfsd4_seek, .op_name = "OP_SEEK",fs/nfsd/nfs4xdr.c +21
-0@@ -1675,6 +1675,25 @@ nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp, }static __be32 +nfsd4_decode_clone (struct nfsd4_compoundargs *argp,struct nfsd4_clone *clone) +{ +DECODE_HEAD ; + + status =nfsd4_decode_stateid (argp, &clone->cl_src_stateid); +if (status) +return status; + status =nfsd4_decode_stateid (argp, &clone->cl_dst_stateid); +if (status) +return status; + +READ_BUF (8 +8 +8 ); + p =xdr_decode_hyper (p, &clone->cl_src_pos); + p =xdr_decode_hyper (p, &clone->cl_dst_pos); + p =xdr_decode_hyper (p, &clone->cl_count); +DECODE_TAIL ; +} + +static __be32 nfsd4_decode_seek (struct nfsd4_compoundargs *argp,struct nfsd4_seek *seek) {DECODE_HEAD ;@@ -1785,6 +1804,7 @@ static nfsd4_dec nfsd4_dec_ops[] = { [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek, [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp, + [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone, }; static inline bool@@ -4249,6 +4269,7 @@ static nfsd4_enc nfsd4_enc_ops[] = { [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_noop, [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek, [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop, + [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop, };/* fs/nfsd/vfs.c +7
-0@@ -36,6 +36,7 @@#endif /* CONFIG_NFSD_V3 */ #ifdef CONFIG_NFSD_V4 +#include "../internal.h" #include "acl.h" #include "idmap.h" #endif /* CONFIG_NFSD_V4 */ @@ -498,6 +499,12 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, }#endif +int nfsd4_clone_range (struct file *src,struct file *dst,u64 src_pos, +u64 count,u64 dst_pos) +{ +return vfs_file_clone_range (src, dst, src_pos, count, dst_pos); +} +__be32 nfsd4_vfs_fallocate (struct svc_rqst *rqstp,struct svc_fh *fhp,struct file *file,loff_t offset,loff_t len,int flags)fs/nfsd/vfs.h +1
-0@@ -56,6 +56,7 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *, struct xdr_netobj *);__be32 nfsd4_vfs_fallocate (struct svc_rqst *,struct svc_fh *,struct file *,loff_t ,loff_t ,int ); +int nfsd4_clone_range (struct file *,struct file *,u64 ,u64 ,u64 );#endif /* CONFIG_NFSD_V4 */ __be32 nfsd_create(struct svc_rqst *, struct svc_fh *, char *name, int len, struct iattr *attrs,fs/nfsd/xdr4.h +10
-0@@ -491,6 +491,15 @@ struct nfsd4_fallocate {u64 falloc_length; }; +struct nfsd4_clone { +/* request */ +stateid_t cl_src_stateid; +stateid_t cl_dst_stateid; +u64 cl_src_pos; +u64 cl_dst_pos; +u64 cl_count; +}; +struct nfsd4_seek {/* request */ stateid_t seek_stateid;@@ -555,6 +564,7 @@ struct nfsd4_op {/* NFSv4.2 */ struct nfsd4_fallocate allocate;struct nfsd4_fallocate deallocate; +struct nfsd4_clone clone;struct nfsd4_seek seek; } u;struct nfs4_replay * replay;include/linux/nfs4.h +2
-3@@ -139,10 +139,10 @@ enum nfs_opnum4 {Needs to be updated if more operations are defined in future.*/ #define FIRST_NFS4_OP OP_ACCESS -#define LAST_NFS4_OP OP_WRITE_SAME#define LAST_NFS40_OP OP_RELEASE_LOCKOWNER#define LAST_NFS41_OP OP_RECLAIM_COMPLETE -#define LAST_NFS42_OP OP_WRITE_SAME +#define LAST_NFS42_OP OP_CLONE +#define LAST_NFS4_OP LAST_NFS42_OPenum nfsstat4 {NFS4_OK =0 , --1.8.3.1
Re: [PATCH RFC 01/11] vfs: pull btrfs clone API to vfs layer
In reply to Peng TaoQuoted 122 lines · Peng Tao
Now that a few file systems are adding clone functionality, namingly btrfs, NFS (later in the series) and XFS (ttp://oss.sgi.com/archives/xfs/2015-06/msg00407.html), it makes sense to pull the ioctl to common code.
Add
vfs_file_clone_range()helper and .clone_range file operation interface to allow underlying filesystems to clone between regular files.The change in
do_vfs_ioctl()is defered to next patch where btrfs .clone_range is added, just so that we don't break btrfs CLONE ioctl with this patch.--- fs/ioctl.c | 24 ++++++++++++++++++++++++ fs/read_write.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 4 ++++ include/uapi/linux/fs.h | 9 +++++++++ 4 files changed, 82 insertions(+)fs/ioctl.c +24
-0@@ -215,6 +215,30 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)return error; } +static long ioctl_file_clone (struct file *dst_file,unsigned long srcfd, +u64 off,u64 olen,u64 destoff) +{ +struct fd src_file =fdget (srcfd); +int ret; + +if (!src_file.file) +return -EBADF ; + ret =vfs_file_clone_range (src_file.file, dst_file, off, olen, destoff); + +fdput (src_file); +return ret; +} + +static long ioctl_file_clone_range (struct file *file,void __user *argp) +{ +struct file_clone_range args; + +if (copy_from_user (&args, argp,sizeof (args))) +return -EFAULT ; +return ioctl_file_clone (file, args.src_fd, args.src_offset, + args.src_length, args.dest_offset); +} +#ifdef CONFIG_BLOCK static inline sector_t logical_to_blk (struct inode *inode,loff_t offset)fs/read_write.c +45
-0@@ -16,6 +16,7 @@#include <linux/pagemap.h> #include <linux/splice.h> #include <linux/compat.h> +#include <linux/mount.h> #include "internal.h" #include <asm/uaccess.h> @@ -1327,3 +1328,47 @@ COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,return do_sendfile (out_fd, in_fd,NULL , count,0 ); }#endif + +int vfs_file_clone_range (struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff) +{ +struct inode *src_ino; +struct inode *dst_ino; +ssize_t ret; + +if (!(src_file->f_mode &FMODE_READ ) || + !(dst_file->f_mode &FMODE_WRITE ) || + (dst_file->f_flags &O_APPEND ) || + !src_file->f_op || !src_file->f_op->clone_range) +return -EINVAL ; + + src_ino =file_inode (src_file); + dst_ino =file_inode (dst_file); + +if (S_ISDIR (src_ino->i_mode) ||S_ISDIR (dst_ino->i_mode)) +return -EISDIR ; + +/* sanity check on offsets and length */ +if (off + len < off || dstoff + len < dstoff || + off + len >i_size_read (src_ino)) +return -EINVAL ; + +if (src_ino->i_sb != dst_ino->i_sb || + src_file->f_path.mnt != dst_file->f_path.mnt) +return -EXDEV ; + + ret =mnt_want_write_file (dst_file); +if (ret) +return ret; + + ret = src_file->f_op->clone_range (src_file, dst_file, off, len, dstoff); +if (!ret) { +fsnotify_access (src_file); +fsnotify_modify (dst_file); + } + +mnt_drop_write_file (dst_file); + +return ret; +} +EXPORT_SYMBOL (vfs_file_clone_range);include/linux/fs.h +0
-0
include/linux/fs.h struct file_operations { · line 1632
Quoted 5 lines
include/linux/fs.h +2
-0@@ -1628,6 +1628,8 @@ struct file_operations {long (*fallocate)(struct file *file,int mode,loff_t offset,loff_t len);void (*show_fdinfo)(struct seq_file *m,struct file *f); +int (*clone_range)(struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff);
One question to btrfs guys... I wanted to add the .clone_range operation explicit semantics such that it does not allow partial success, and returns either 0 for success or a negative failure code, because we don't not expect CLONE to succeed partially. Does btrfs CLONE have the same semantics? It looks like so by going over btrfs_clone() but it would be great if someone working on btrfs can confirm it.
Thanks,
Tao
Quoted 42 lines
include/linux/fs.h +2
-0#ifndef CONFIG_MMU unsigned (*mmap_capabilities)(struct file *);#endif @@ -2678,6 +2680,8 @@ int __dax_fault(struct vm_area_struct *, struct vm_fault *, get_block_t,int dax_pfn_mkwrite (struct vm_area_struct *,struct vm_fault *);#define dax_mkwrite (vma, vmf, gb, iod) dax_fault(vma, vmf, gb, iod)#define __dax_mkwrite (vma, vmf, gb, iod) __dax_fault(vma, vmf, gb, iod) +int vfs_file_clone_range (struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff);#ifdef CONFIG_BLOCK typedef void (dio_submit_t)(int rw, struct bio *bio, struct inode *inode,include/uapi/linux/fs.h +9
-1@@ -39,6 +39,13 @@#define RENAME_EXCHANGE (1 << 1)/* Exchange source and dest */ #define RENAME_WHITEOUT (1 << 2)/* Whiteout source */ +struct file_clone_range { +__s64 src_fd; +__u64 src_offset; +__u64 src_length; +__u64 dest_offset; +}; +struct fstrim_range {__u64 start;__u64 len;@@ -159,6 +166,8 @@ struct inodes_stat_t {#define FIFREEZE _IOWR('X', 119, int)/* Freeze */ #define FITHAW _IOWR('X', 120, int)/* Thaw */ #define FITRIM _IOWR('X', 121, struct fstrim_range)/* Trim */ +#define FICLONE _IOW(0x94, 9, int)/* Clone */ +#define FICLONERANGE _IOW(0x94, 13, struct file_clone_range)/* Clone range */ #define FS_IOC_GETFLAGS _IOR('f', 1, long)#define FS_IOC_SETFLAGS _IOW('f', 2, long) --1.8.3.1
Re: [PATCH RFC 01/11] vfs: pull btrfs clone API to vfs layer
In reply to Peng TaoQuoted 8 lines · Peng Tao
Now that a few file systems are adding clone functionality, namingly btrfs, NFS (later in the series) and XFS (ttp://oss.sgi.com/archives/xfs/2015-06/msg00407.html), it makes sense to pull the ioctl to common code.
Add
vfs_file_clone_range()helper and .clone_range file operation interface to allow underlying filesystems to clone between regular files.
Quoted 6 lines
The change in
do_vfs_ioctl()is defered to next patch where btrfs .clone_range is added, just so that we don't break btrfs CLONE ioctl with this patch.
Can you please cc the entire patch series to linux-fsdevel?
Spraying random patches from a larger series to different lists is not very nice - I can't really comment on this patch because I have no idea what context it is being proposed in, what the problem being solved is, how it is being used by existing filesystems, how it will be used by your new changes, etc.
You may have explained all this in patch 0 for the series, but that hasn't been cc'd to linux-fsdevel....
Cheers,
Dave.
PS: CC list spraying also plays badly with dup filters and per-list procmail sorting that a lot of people use to manage incoming feeds....
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH RFC 01/11] vfs: pull btrfs clone API to vfs layer
Quoted 18 lines · Dave Chinner
Quoted 8 lines · Peng Tao
Now that a few file systems are adding clone functionality, namingly btrfs, NFS (later in the series) and XFS (ttp://oss.sgi.com/archives/xfs/2015-06/msg00407.html), it makes sense to pull the ioctl to common code.
Add
vfs_file_clone_range()helper and .clone_range file operation interface to allow underlying filesystems to clone between regular files.Quoted 6 lines
The change in
do_vfs_ioctl()is defered to next patch where btrfs .clone_range is added, just so that we don't break btrfs CLONE ioctl with this patch.Can you please cc the entire patch series to linux-fsdevel?
Quoted 8 lines
Spraying random patches from a larger series to different lists is not very nice - I can't really comment on this patch because I have no idea what context it is being proposed in, what the problem being solved is, how it is being used by existing filesystems, how it will be used by your new changes, etc.
You may have explained all this in patch 0 for the series, but that hasn't been cc'd to linux-fsdevel....
Also, proposed test infrastructure for the clone_range functionality that Darrick is working on for XFS (and to validate existing btrfs functionality):
http://oss.sgi.com/archives/xfs/2015-06/msg00479.html
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH RFC 01/11] vfs: pull btrfs clone API to vfs layer
In reply to Peng TaoQuoted 4 lines · Peng Tao
Now that a few file systems are adding clone functionality, namingly btrfs, NFS (later in the series) and XFS (ttp://oss.sgi.com/archives/xfs/2015-06/msg00407.html), it makes sense to pull the ioctl to common code.
Please cc me on future postings of this entire patchset, seeing as you're referencing an email I sent and am still actively working on. :)
I agree with what Dave said, please also cc the entire set to fsdevel.
--D
Quoted 169 lines
Add
vfs_file_clone_range()helper and .clone_range file operation interface to allow underlying filesystems to clone between regular files.The change in
do_vfs_ioctl()is defered to next patch where btrfs .clone_range is added, just so that we don't break btrfs CLONE ioctl with this patch.--- fs/ioctl.c | 24 ++++++++++++++++++++++++ fs/read_write.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 4 ++++ include/uapi/linux/fs.h | 9 +++++++++ 4 files changed, 82 insertions(+)fs/ioctl.c +24
-0@@ -215,6 +215,30 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)return error; } +static long ioctl_file_clone (struct file *dst_file,unsigned long srcfd, +u64 off,u64 olen,u64 destoff) +{ +struct fd src_file =fdget (srcfd); +int ret; + +if (!src_file.file) +return -EBADF ; + ret =vfs_file_clone_range (src_file.file, dst_file, off, olen, destoff); + +fdput (src_file); +return ret; +} + +static long ioctl_file_clone_range (struct file *file,void __user *argp) +{ +struct file_clone_range args; + +if (copy_from_user (&args, argp,sizeof (args))) +return -EFAULT ; +return ioctl_file_clone (file, args.src_fd, args.src_offset, + args.src_length, args.dest_offset); +} +#ifdef CONFIG_BLOCK static inline sector_t logical_to_blk (struct inode *inode,loff_t offset)fs/read_write.c +45
-0@@ -16,6 +16,7 @@#include <linux/pagemap.h> #include <linux/splice.h> #include <linux/compat.h> +#include <linux/mount.h> #include "internal.h" #include <asm/uaccess.h> @@ -1327,3 +1328,47 @@ COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,return do_sendfile (out_fd, in_fd,NULL , count,0 ); }#endif + +int vfs_file_clone_range (struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff) +{ +struct inode *src_ino; +struct inode *dst_ino; +ssize_t ret; + +if (!(src_file->f_mode &FMODE_READ ) || + !(dst_file->f_mode &FMODE_WRITE ) || + (dst_file->f_flags &O_APPEND ) || + !src_file->f_op || !src_file->f_op->clone_range) +return -EINVAL ; + + src_ino =file_inode (src_file); + dst_ino =file_inode (dst_file); + +if (S_ISDIR (src_ino->i_mode) ||S_ISDIR (dst_ino->i_mode)) +return -EISDIR ; + +/* sanity check on offsets and length */ +if (off + len < off || dstoff + len < dstoff || + off + len >i_size_read (src_ino)) +return -EINVAL ; + +if (src_ino->i_sb != dst_ino->i_sb || + src_file->f_path.mnt != dst_file->f_path.mnt) +return -EXDEV ; + + ret =mnt_want_write_file (dst_file); +if (ret) +return ret; + + ret = src_file->f_op->clone_range (src_file, dst_file, off, len, dstoff); +if (!ret) { +fsnotify_access (src_file); +fsnotify_modify (dst_file); + } + +mnt_drop_write_file (dst_file); + +return ret; +} +EXPORT_SYMBOL (vfs_file_clone_range);include/linux/fs.h +4
-0@@ -1628,6 +1628,8 @@ struct file_operations {long (*fallocate)(struct file *file,int mode,loff_t offset,loff_t len);void (*show_fdinfo)(struct seq_file *m,struct file *f); +int (*clone_range)(struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff);#ifndef CONFIG_MMU unsigned (*mmap_capabilities)(struct file *);#endif @@ -2678,6 +2680,8 @@ int __dax_fault(struct vm_area_struct *, struct vm_fault *, get_block_t,int dax_pfn_mkwrite (struct vm_area_struct *,struct vm_fault *);#define dax_mkwrite (vma, vmf, gb, iod) dax_fault(vma, vmf, gb, iod)#define __dax_mkwrite (vma, vmf, gb, iod) __dax_fault(vma, vmf, gb, iod) +int vfs_file_clone_range (struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff);#ifdef CONFIG_BLOCK typedef void (dio_submit_t)(int rw, struct bio *bio, struct inode *inode,include/uapi/linux/fs.h +9
-0@@ -39,6 +39,13 @@#define RENAME_EXCHANGE (1 << 1)/* Exchange source and dest */ #define RENAME_WHITEOUT (1 << 2)/* Whiteout source */ +struct file_clone_range { +__s64 src_fd; +__u64 src_offset; +__u64 src_length; +__u64 dest_offset; +}; +struct fstrim_range {__u64 start;__u64 len;@@ -159,6 +166,8 @@ struct inodes_stat_t {#define FIFREEZE _IOWR('X', 119, int)/* Freeze */ #define FITHAW _IOWR('X', 120, int)/* Thaw */ #define FITRIM _IOWR('X', 121, struct fstrim_range)/* Trim */ +#define FICLONE _IOW(0x94, 9, int)/* Clone */ +#define FICLONERANGE _IOW(0x94, 13, struct file_clone_range)/* Clone range */ #define FS_IOC_GETFLAGS _IOR('f', 1, long)#define FS_IOC_SETFLAGS _IOW('f', 2, long)Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RFC 02/11] vfs/btrfs: add .clone_range file operation
In reply to a message not in the archiveinclude/uapi/linux/btrfs.h struct btrfs_ioctl_search_args_v2 { · line 323
Quoted 11 lines · Peng Tao
include/uapi/linux/btrfs.h +0
-5@@ -316,12 +316,6 @@ struct btrfs_ioctl_search_args_v2 {__u64 buf[0 ];/* out - found items */ }; -struct btrfs_ioctl_clone_range_args { -__s64 src_fd; -__u64 src_offset, src_length; -__u64 dest_offset; -};
For backward compatibility and not-breaking-builds reasons, do not remove anything from this file.
include/uapi/linux/btrfs.h static inline char *btrfs_err_str(enum btrfs_err_code err_code) · line 551
Quoted 9 lines
include/uapi/linux/btrfs.h +0
-2-/* flags for the defrag range ioctl */ #define BTRFS_DEFRAG_RANGE_COMPRESS 1#define BTRFS_DEFRAG_RANGE_START_IO 2@@ -548,7 +542,6 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)#define BTRFS_IOC_TRANS_END _IO(BTRFS_IOCTL_MAGIC, 7)#define BTRFS_IOC_SYNC _IO(BTRFS_IOCTL_MAGIC, 8) -#define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
The ioctl definition reuses the BTRFS_IOCTL_MAGIC (0x94), which is IMHO wrong.
I'll comment more once the whole series is posted to fsdevel. --
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RFC 01/11] vfs: pull btrfs clone API to vfs layer
In reply to a message not in the archiveQuoted 11 lines · Darrick J. Wong
Quoted 4 lines · Peng Tao
Now that a few file systems are adding clone functionality, namingly btrfs, NFS (later in the series) and XFS (ttp://oss.sgi.com/archives/xfs/2015-06/msg00407.html), it makes sense to pull the ioctl to common code.
Please cc me on future postings of this entire patchset, seeing as you're referencing an email I sent and am still actively working on. :)
I agree with what Dave said, please also cc the entire set to fsdevel.
sorry for the inconvenience. I'll resend the series adding linux-fsdevel and you to the cc list.
Cheers,
Tao
Quoted 167 lines
--D
Quoted 165 lines
Add
vfs_file_clone_range()helper and .clone_range file operation interface to allow underlying filesystems to clone between regular files.The change in
do_vfs_ioctl()is defered to next patch where btrfs .clone_range is added, just so that we don't break btrfs CLONE ioctl with this patch.Signed-off-by Peng Tao <tao.peng-7I+n7zu2hftEKMMhf/[email protected]>--- fs/ioctl.c | 24 ++++++++++++++++++++++++ fs/read_write.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 4 ++++ include/uapi/linux/fs.h | 9 +++++++++ 4 files changed, 82 insertions(+)fs/ioctl.c +24
-0@@ -215,6 +215,30 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)return error; } +static long ioctl_file_clone (struct file *dst_file,unsigned long srcfd, +u64 off,u64 olen,u64 destoff) +{ +struct fd src_file =fdget (srcfd); +int ret; + +if (!src_file.file) +return -EBADF ; + ret =vfs_file_clone_range (src_file.file, dst_file, off, olen, destoff); + +fdput (src_file); +return ret; +} + +static long ioctl_file_clone_range (struct file *file,void __user *argp) +{ +struct file_clone_range args; + +if (copy_from_user (&args, argp,sizeof (args))) +return -EFAULT ; +return ioctl_file_clone (file, args.src_fd, args.src_offset, + args.src_length, args.dest_offset); +} +#ifdef CONFIG_BLOCK static inline sector_t logical_to_blk (struct inode *inode,loff_t offset)fs/read_write.c +45
-0@@ -16,6 +16,7 @@#include <linux/pagemap.h> #include <linux/splice.h> #include <linux/compat.h> +#include <linux/mount.h> #include "internal.h" #include <asm/uaccess.h> @@ -1327,3 +1328,47 @@ COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,return do_sendfile (out_fd, in_fd,NULL , count,0 ); }#endif + +int vfs_file_clone_range (struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff) +{ +struct inode *src_ino; +struct inode *dst_ino; +ssize_t ret; + +if (!(src_file->f_mode &FMODE_READ ) || + !(dst_file->f_mode &FMODE_WRITE ) || + (dst_file->f_flags &O_APPEND ) || + !src_file->f_op || !src_file->f_op->clone_range) +return -EINVAL ; + + src_ino =file_inode (src_file); + dst_ino =file_inode (dst_file); + +if (S_ISDIR (src_ino->i_mode) ||S_ISDIR (dst_ino->i_mode)) +return -EISDIR ; + +/* sanity check on offsets and length */ +if (off + len < off || dstoff + len < dstoff || + off + len >i_size_read (src_ino)) +return -EINVAL ; + +if (src_ino->i_sb != dst_ino->i_sb || + src_file->f_path.mnt != dst_file->f_path.mnt) +return -EXDEV ; + + ret =mnt_want_write_file (dst_file); +if (ret) +return ret; + + ret = src_file->f_op->clone_range (src_file, dst_file, off, len, dstoff); +if (!ret) { +fsnotify_access (src_file); +fsnotify_modify (dst_file); + } + +mnt_drop_write_file (dst_file); + +return ret; +} +EXPORT_SYMBOL (vfs_file_clone_range);include/linux/fs.h +4
-0@@ -1628,6 +1628,8 @@ struct file_operations {long (*fallocate)(struct file *file,int mode,loff_t offset,loff_t len);void (*show_fdinfo)(struct seq_file *m,struct file *f); +int (*clone_range)(struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff);#ifndef CONFIG_MMU unsigned (*mmap_capabilities)(struct file *);#endif @@ -2678,6 +2680,8 @@ int __dax_fault(struct vm_area_struct *, struct vm_fault *, get_block_t,int dax_pfn_mkwrite (struct vm_area_struct *,struct vm_fault *);#define dax_mkwrite (vma, vmf, gb, iod) dax_fault(vma, vmf, gb, iod)#define __dax_mkwrite (vma, vmf, gb, iod) __dax_fault(vma, vmf, gb, iod) +int vfs_file_clone_range (struct file *src_file,struct file *dst_file, +loff_t off,size_t len,loff_t dstoff);#ifdef CONFIG_BLOCK typedef void (dio_submit_t)(int rw, struct bio *bio, struct inode *inode,include/uapi/linux/fs.h +9
-1@@ -39,6 +39,13 @@#define RENAME_EXCHANGE (1 << 1)/* Exchange source and dest */ #define RENAME_WHITEOUT (1 << 2)/* Whiteout source */ +struct file_clone_range { +__s64 src_fd; +__u64 src_offset; +__u64 src_length; +__u64 dest_offset; +}; +struct fstrim_range {__u64 start;__u64 len;@@ -159,6 +166,8 @@ struct inodes_stat_t {#define FIFREEZE _IOWR('X', 119, int)/* Freeze */ #define FITHAW _IOWR('X', 120, int)/* Thaw */ #define FITRIM _IOWR('X', 121, struct fstrim_range)/* Trim */ +#define FICLONE _IOW(0x94, 9, int)/* Clone */ +#define FICLONERANGE _IOW(0x94, 13, struct file_clone_range)/* Clone range */ #define FS_IOC_GETFLAGS _IOR('f', 1, long)#define FS_IOC_SETFLAGS _IOW('f', 2, long) --1.8.3.1
Quoted 4 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RFC 02/11] vfs/btrfs: add .clone_range file operation
In reply to a message not in the archiveQuoted 7 lines · David Sterba
Quoted 6 lines · Peng Tao
include/uapi/linux/btrfs.h +0
-0@@ -316,12 +316,6 @@ struct btrfs_ioctl_search_args_v2 {__u64 buf[0 ];/* out - found items */ };
Quoted 9 lines
include/uapi/linux/btrfs.h struct btrfs_ioctl_search_args_v2 { · line 323
Quoted 5 lines
include/uapi/linux/btrfs.h +0
-5-struct btrfs_ioctl_clone_range_args { -__s64 src_fd; -__u64 src_offset, src_length; -__u64 dest_offset; -};For backward compatibility and not-breaking-builds reasons, do not remove anything from this file.
Got you. I'll keep it unchanged in the next version.
Quoted 8 lines
Quoted 8 lines
include/uapi/linux/btrfs.h +0
-1-/* flags for the defrag range ioctl */ #define BTRFS_DEFRAG_RANGE_COMPRESS 1#define BTRFS_DEFRAG_RANGE_START_IO 2@@ -548,7 +542,6 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)#define BTRFS_IOC_TRANS_END _IO(BTRFS_IOCTL_MAGIC, 7)#define BTRFS_IOC_SYNC _IO(BTRFS_IOCTL_MAGIC, 8)
Quoted 5 lines
include/uapi/linux/btrfs.h static inline char *btrfs_err_str(enum btrfs_err_code err_code) · line 551
Quoted 1 line
include/uapi/linux/btrfs.h +0
-1-#define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)The ioctl definition reuses the
BTRFS_IOCTL_MAGIC(0x94), which is IMHO wrong.
I thought it breaks ABI if we choose a different value for the type field of the ioctl. Am I misunderstanding it?
Thanks,
Tao
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RFC 02/11] vfs/btrfs: add .clone_range file operation
In reply to a message not in the archiveQuoted 7 lines · Peng Tao
Quoted 5 lines
Quoted 1 line
-#define
BTRFS_IOC_CLONE_IOW(BTRFS_IOCTL_MAGIC, 9, int)The ioctl definition reuses the
BTRFS_IOCTL_MAGIC(0x94), which is IMHO wrong.I thought it breaks ABI if we choose a different value for the type field of the ioctl. Am I misunderstanding it?
The ioctl is now private to btrfs, you're going to define the new ABI so it IMHO should use the generic filesystem ioctl magic/namespace. --
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RFC 02/11] vfs/btrfs: add .clone_range file operation
Quoted 5 lines · David Sterba
Quoted 2 lines
I thought it breaks ABI if we choose a different value for the type field of the ioctl. Am I misunderstanding it?
The ioctl is now private to btrfs, you're going to define the new ABI so it IMHO should use the generic filesystem ioctl magic/namespace.
No, that's completly backwards. We move up ioctls that have prooven to be generally useful to common code, and we've done that with various extN and XFS ones already.