* CLONE fixes, V2
@ 2015-11-13 8:38 Christoph Hellwig
2015-11-13 8:38 ` [PATCH 1/5] nfs: pass on count for CLONE operations Christoph Hellwig
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Christoph Hellwig @ 2015-11-13 8:38 UTC (permalink / raw)
To: Trond Myklebust; +Cc: Peng Tao, linux-nfs
Resend of the clone fixes. This includes support for intra-file CLONES
recently added to the spec, and makes the CLONE_RANGE ioctl compatible
with the original btrfs one, so that programs written for it actually
work.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/5] nfs: pass on count for CLONE operations
2015-11-13 8:38 CLONE fixes, V2 Christoph Hellwig
@ 2015-11-13 8:38 ` Christoph Hellwig
2015-11-13 8:38 ` [PATCH 2/5] nfs: offer native ioctls even if CONFIG_COMPAT is set Christoph Hellwig
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2015-11-13 8:38 UTC (permalink / raw)
To: Trond Myklebust; +Cc: Peng Tao, linux-nfs
Currently we pass uninitialized stack garbage in the count parameter.
The value is usually large enought to clone whole files and thus let
simple tests pass, but it makes the tests for range clones very unhappy.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/nfs/nfs42proc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c
index 3e92a3c..303d22e 100644
--- a/fs/nfs/nfs42proc.c
+++ b/fs/nfs/nfs42proc.c
@@ -284,6 +284,7 @@ static int _nfs42_proc_clone(struct rpc_message *msg, struct file *src_f,
.dst_fh = NFS_FH(dst_inode),
.src_offset = src_offset,
.dst_offset = dst_offset,
+ .count = count,
.dst_bitmask = server->cache_consistency_bitmask,
};
struct nfs42_clone_res res = {
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] nfs: offer native ioctls even if CONFIG_COMPAT is set
2015-11-13 8:38 CLONE fixes, V2 Christoph Hellwig
2015-11-13 8:38 ` [PATCH 1/5] nfs: pass on count for CLONE operations Christoph Hellwig
@ 2015-11-13 8:38 ` Christoph Hellwig
2015-11-13 8:38 ` [PATCH 3/5] nfs: allow intra-file CLONE Christoph Hellwig
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2015-11-13 8:38 UTC (permalink / raw)
To: Trond Myklebust; +Cc: Peng Tao, linux-nfs
Without this for example 64-bit binaries on typical amd64 distributions
would not be able to use ioctls on NFS. For now this only affects clones.
Additionally ->compat_ioctl is defined even for non-compat builds, so
get rid of the pointless ifdef.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/nfs/nfs4file.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index 4aa5719..e45f686 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -347,9 +347,6 @@ const struct file_operations nfs4_file_operations = {
#endif /* CONFIG_NFS_V4_2 */
.check_flags = nfs_check_flags,
.setlease = simple_nosetlease,
-#ifdef CONFIG_COMPAT
.unlocked_ioctl = nfs4_ioctl,
-#else
.compat_ioctl = nfs4_ioctl,
-#endif /* CONFIG_COMPAT */
};
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] nfs: allow intra-file CLONE
2015-11-13 8:38 CLONE fixes, V2 Christoph Hellwig
2015-11-13 8:38 ` [PATCH 1/5] nfs: pass on count for CLONE operations Christoph Hellwig
2015-11-13 8:38 ` [PATCH 2/5] nfs: offer native ioctls even if CONFIG_COMPAT is set Christoph Hellwig
@ 2015-11-13 8:38 ` Christoph Hellwig
2015-11-13 9:09 ` Christoph Hellwig
2015-11-13 8:38 ` [PATCH 4/5] nfs: use btrfs ioctl defintions for clone Christoph Hellwig
2015-11-13 8:38 ` [PATCH 5/5] nfs: reduce the amount of ifdefs for v4.2 in nfs4file.c Christoph Hellwig
4 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2015-11-13 8:38 UTC (permalink / raw)
To: Trond Myklebust; +Cc: Peng Tao, linux-nfs
Originally CLONE didn't allow for intra-file clones, but we recently
updated the spec to support this feature which is also supported by
local Linux file systems.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/nfs/nfs4file.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index e45f686..4b4dd89 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -203,6 +203,7 @@ nfs42_ioctl_clone(struct file *dst_file, unsigned long srcfd,
struct fd src_file;
struct inode *src_inode;
unsigned int bs = server->clone_blksize;
+ bool same_inode = false;
int ret;
/* dst file must be opened for writing */
@@ -221,10 +222,8 @@ nfs42_ioctl_clone(struct file *dst_file, unsigned long srcfd,
src_inode = file_inode(src_file.file);
- /* src and dst must be different files */
- ret = -EINVAL;
if (src_inode == dst_inode)
- goto out_fput;
+ same_inode = true;
/* src file must be opened for reading */
if (!(src_file.file->f_mode & FMODE_READ))
@@ -249,8 +248,16 @@ nfs42_ioctl_clone(struct file *dst_file, unsigned long srcfd,
goto out_fput;
}
+ /* verify if ranges are overlapped within the same file */
+ if (same_inode) {
+ if (dst_off + count > src_off && dst_off < src_off + count)
+ goto out_fput;
+ }
+
/* XXX: do we lock at all? what if server needs CB_RECALL_LAYOUT? */
- if (dst_inode < src_inode) {
+ if (same_inode) {
+ mutex_lock(&src_inode->i_mutex);
+ } 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 {
@@ -275,7 +282,9 @@ nfs42_ioctl_clone(struct file *dst_file, unsigned long srcfd,
truncate_inode_pages_range(&dst_inode->i_data, dst_off, dst_off + count - 1);
out_unlock:
- if (dst_inode < src_inode) {
+ if (same_inode) {
+ mutex_unlock(&src_inode->i_mutex);
+ } else if (dst_inode < src_inode) {
mutex_unlock(&src_inode->i_mutex);
mutex_unlock(&dst_inode->i_mutex);
} else {
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] nfs: use btrfs ioctl defintions for clone
2015-11-13 8:38 CLONE fixes, V2 Christoph Hellwig
` (2 preceding siblings ...)
2015-11-13 8:38 ` [PATCH 3/5] nfs: allow intra-file CLONE Christoph Hellwig
@ 2015-11-13 8:38 ` Christoph Hellwig
2015-11-13 8:38 ` [PATCH 5/5] nfs: reduce the amount of ifdefs for v4.2 in nfs4file.c Christoph Hellwig
4 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2015-11-13 8:38 UTC (permalink / raw)
To: Trond Myklebust; +Cc: Peng Tao, linux-nfs
The NFS CLONE_RANGE defintion was wrong and thus never worked. Fix this
by simply using the btrfs ioctl defintion.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/nfs/nfs4file.c | 10 ++++++----
include/uapi/linux/nfs.h | 11 -----------
2 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index 4b4dd89..5f63f2d 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -7,6 +7,7 @@
#include <linux/file.h>
#include <linux/falloc.h>
#include <linux/nfs_fs.h>
+#include <uapi/linux/btrfs.h> /* BTRFS_IOC_CLONE/BTRFS_IOC_CLONE_RANGE */
#include "delegation.h"
#include "internal.h"
#include "iostat.h"
@@ -300,12 +301,13 @@ out_drop_write:
static long nfs42_ioctl_clone_range(struct file *dst_file, void __user *argp)
{
- struct nfs_ioctl_clone_range_args args;
+ struct btrfs_ioctl_clone_range_args args;
if (copy_from_user(&args, argp, sizeof(args)))
return -EFAULT;
- return nfs42_ioctl_clone(dst_file, args.src_fd, args.src_off, args.dst_off, args.count);
+ return nfs42_ioctl_clone(dst_file, args.src_fd, args.src_offset,
+ args.dest_offset, args.src_length);
}
#else
static long nfs42_ioctl_clone(struct file *dst_file, unsigned long srcfd,
@@ -325,9 +327,9 @@ long nfs4_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
void __user *argp = (void __user *)arg;
switch (cmd) {
- case NFS_IOC_CLONE:
+ case BTRFS_IOC_CLONE:
return nfs42_ioctl_clone(file, arg, 0, 0, 0);
- case NFS_IOC_CLONE_RANGE:
+ case BTRFS_IOC_CLONE_RANGE:
return nfs42_ioctl_clone_range(file, argp);
}
diff --git a/include/uapi/linux/nfs.h b/include/uapi/linux/nfs.h
index 654bae3..5e62961 100644
--- a/include/uapi/linux/nfs.h
+++ b/include/uapi/linux/nfs.h
@@ -33,17 +33,6 @@
#define NFS_PIPE_DIRNAME "nfs"
-/* NFS ioctls */
-/* Let's follow btrfs lead on CLONE to avoid messing userspace */
-#define NFS_IOC_CLONE _IOW(0x94, 9, int)
-#define NFS_IOC_CLONE_RANGE _IOW(0x94, 13, int)
-
-struct nfs_ioctl_clone_range_args {
- __s64 src_fd;
- __u64 src_off, count;
- __u64 dst_off;
-};
-
/*
* NFS stats. The good thing with these values is that NFSv3 errors are
* a superset of NFSv2 errors (with the exception of NFSERR_WFLUSH which
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] nfs: reduce the amount of ifdefs for v4.2 in nfs4file.c
2015-11-13 8:38 CLONE fixes, V2 Christoph Hellwig
` (3 preceding siblings ...)
2015-11-13 8:38 ` [PATCH 4/5] nfs: use btrfs ioctl defintions for clone Christoph Hellwig
@ 2015-11-13 8:38 ` Christoph Hellwig
4 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2015-11-13 8:38 UTC (permalink / raw)
To: Trond Myklebust; +Cc: Peng Tao, linux-nfs
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/nfs/nfs4file.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index 5f63f2d..49dbeab 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -309,18 +309,6 @@ static long nfs42_ioctl_clone_range(struct file *dst_file, void __user *argp)
return nfs42_ioctl_clone(dst_file, args.src_fd, args.src_offset,
args.dest_offset, args.src_length);
}
-#else
-static long nfs42_ioctl_clone(struct file *dst_file, unsigned long srcfd,
- u64 src_off, u64 dst_off, u64 count)
-{
- return -ENOTTY;
-}
-
-static long nfs42_ioctl_clone_range(struct file *dst_file, void __user *argp)
-{
- return -ENOTTY;
-}
-#endif /* CONFIG_NFS_V4_2 */
long nfs4_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
@@ -335,13 +323,9 @@ long nfs4_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
return -ENOTTY;
}
+#endif /* CONFIG_NFS_V4_2 */
const struct file_operations nfs4_file_operations = {
-#ifdef CONFIG_NFS_V4_2
- .llseek = nfs4_file_llseek,
-#else
- .llseek = nfs_file_llseek,
-#endif
.read_iter = nfs_file_read,
.write_iter = nfs_file_write,
.mmap = nfs_file_mmap,
@@ -353,11 +337,14 @@ const struct file_operations nfs4_file_operations = {
.flock = nfs_flock,
.splice_read = nfs_file_splice_read,
.splice_write = iter_file_splice_write,
-#ifdef CONFIG_NFS_V4_2
- .fallocate = nfs42_fallocate,
-#endif /* CONFIG_NFS_V4_2 */
.check_flags = nfs_check_flags,
.setlease = simple_nosetlease,
+#ifdef CONFIG_NFS_V4_2
+ .llseek = nfs4_file_llseek,
+ .fallocate = nfs42_fallocate,
.unlocked_ioctl = nfs4_ioctl,
.compat_ioctl = nfs4_ioctl,
+#else
+ .llseek = nfs_file_llseek,
+#endif
};
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/5] nfs: allow intra-file CLONE
2015-11-13 8:38 ` [PATCH 3/5] nfs: allow intra-file CLONE Christoph Hellwig
@ 2015-11-13 9:09 ` Christoph Hellwig
0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2015-11-13 9:09 UTC (permalink / raw)
To: Trond Myklebust; +Cc: Peng Tao, linux-nfs
Meh, a fixlet got lost while rebasing. See below for the one liner
or just grab the git tree from:
http://git.infradead.org/users/hch/pnfs.git/shortlog/refs/heads/clone-fixes
git://git.infradead.org/users/hch/pnfs.git clone-fixes
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index 49dbeab..db9b5fe 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -258,7 +258,7 @@ nfs42_ioctl_clone(struct file *dst_file, unsigned long srcfd,
/* XXX: do we lock at all? what if server needs CB_RECALL_LAYOUT? */
if (same_inode) {
mutex_lock(&src_inode->i_mutex);
- } if (dst_inode < src_inode) {
+ } else 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 {
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-11-13 9:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-13 8:38 CLONE fixes, V2 Christoph Hellwig
2015-11-13 8:38 ` [PATCH 1/5] nfs: pass on count for CLONE operations Christoph Hellwig
2015-11-13 8:38 ` [PATCH 2/5] nfs: offer native ioctls even if CONFIG_COMPAT is set Christoph Hellwig
2015-11-13 8:38 ` [PATCH 3/5] nfs: allow intra-file CLONE Christoph Hellwig
2015-11-13 9:09 ` Christoph Hellwig
2015-11-13 8:38 ` [PATCH 4/5] nfs: use btrfs ioctl defintions for clone Christoph Hellwig
2015-11-13 8:38 ` [PATCH 5/5] nfs: reduce the amount of ifdefs for v4.2 in nfs4file.c Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox