* [PATCH v3 1/5] vfs: deny fallocate() on directory
2017-01-31 8:34 [PATCH v3 0/5] overlayfs: support freeze/thaw Amir Goldstein
@ 2017-01-31 8:34 ` Amir Goldstein
2017-01-31 10:56 ` Christoph Hellwig
[not found] ` <1485851699-25313-1-git-send-email-amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
` (3 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Amir Goldstein @ 2017-01-31 8:34 UTC (permalink / raw)
To: Miklos Szeredi
Cc: Jan Kara, Christoph Hellwig, Al Viro, linux-unionfs,
linux-fsdevel, linux-api
There was an obscure use case of fallocate of directory inode
in the vfs helper with the comment:
"Let individual file system decide if it supports preallocation
for directories or not."
But there is no in-tree file system that implements fallocate
for directory operations.
Deny an attempt to fallocate a directory with EISDIR error.
This change is needed prior to converting sb_start_write()
to file_start_write(), so freeze protection is correctly
handled for cases of fallocate file and blockdev.
Cc: linux-api@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/open.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/fs/open.c b/fs/open.c
index 9921f70..f9118f4 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -301,12 +301,10 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
if (S_ISFIFO(inode->i_mode))
return -ESPIPE;
- /*
- * Let individual file system decide if it supports preallocation
- * for directories or not.
- */
- if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode) &&
- !S_ISBLK(inode->i_mode))
+ if (S_ISDIR(inode->i_mode))
+ return -EISDIR;
+
+ if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
return -ENODEV;
/* Check for wrap through zero too */
--
2.7.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
[parent not found: <1485851699-25313-1-git-send-email-amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* [PATCH v3 2/5] vfs: deny copy_file_range() for non regular files
2017-01-31 8:34 [PATCH v3 0/5] overlayfs: support freeze/thaw Amir Goldstein
@ 2017-01-31 8:34 ` Amir Goldstein
[not found] ` <1485851699-25313-1-git-send-email-amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
` (3 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Amir Goldstein @ 2017-01-31 8:34 UTC (permalink / raw)
To: Miklos Szeredi
Cc: Jan Kara, Christoph Hellwig, Al Viro,
linux-unionfs-u79uwXL29TY76Z2rM5mHXA,
linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA
There is no in-tree file system that implements copy_file_range()
for non regular files.
Deny an attempt to copy_file_range() a directory with EISDIR
and any other non regualr file with EINVAL to conform with
behavior of vfs_{clone,dedup}_file_range().
This change is needed prior to converting sb_start_write()
to file_start_write() in the vfs helper.
Cc: linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>
Cc: Al Viro <viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
Signed-off-by: Amir Goldstein <amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
fs/read_write.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/read_write.c b/fs/read_write.c
index 5816d4c..511178d 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1518,6 +1518,11 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
if (flags != 0)
return -EINVAL;
+ if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
+ return -EISDIR;
+ if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
+ return -EINVAL;
+
ret = rw_verify_area(READ, file_in, &pos_in, len);
if (unlikely(ret))
return ret;
--
2.7.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 2/5] vfs: deny copy_file_range() for non regular files
@ 2017-01-31 8:34 ` Amir Goldstein
0 siblings, 0 replies; 11+ messages in thread
From: Amir Goldstein @ 2017-01-31 8:34 UTC (permalink / raw)
To: Miklos Szeredi
Cc: Jan Kara, Christoph Hellwig, Al Viro, linux-unionfs,
linux-fsdevel, linux-api
There is no in-tree file system that implements copy_file_range()
for non regular files.
Deny an attempt to copy_file_range() a directory with EISDIR
and any other non regualr file with EINVAL to conform with
behavior of vfs_{clone,dedup}_file_range().
This change is needed prior to converting sb_start_write()
to file_start_write() in the vfs helper.
Cc: linux-api@vger.kernel.org
Cc: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/read_write.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/read_write.c b/fs/read_write.c
index 5816d4c..511178d 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1518,6 +1518,11 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
if (flags != 0)
return -EINVAL;
+ if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
+ return -EISDIR;
+ if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
+ return -EINVAL;
+
ret = rw_verify_area(READ, file_in, &pos_in, len);
if (unlikely(ret))
return ret;
--
2.7.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
[parent not found: <1485851699-25313-3-git-send-email-amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* [PATCH v3 3/5] vfs: wrap write f_ops with file_{start,end}_write()
2017-01-31 8:34 [PATCH v3 0/5] overlayfs: support freeze/thaw Amir Goldstein
2017-01-31 8:34 ` [PATCH v3 1/5] vfs: deny fallocate() on directory Amir Goldstein
[not found] ` <1485851699-25313-1-git-send-email-amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-01-31 8:34 ` Amir Goldstein
2017-01-31 10:56 ` Christoph Hellwig
2017-01-31 8:34 ` [PATCH v3 4/5] vfs: freeze protect overlay inode on file_start_write() Amir Goldstein
2017-01-31 8:34 ` [PATCH v3 5/5] ovl: support freeze/thaw super Amir Goldstein
4 siblings, 1 reply; 11+ messages in thread
From: Amir Goldstein @ 2017-01-31 8:34 UTC (permalink / raw)
To: Miklos Szeredi
Cc: Jan Kara, Christoph Hellwig, Al Viro, linux-unionfs, linux-fsdevel
Before calling write f_ops, call file_start_write() instead
of sb_start_write().
Replace {sb,file}_start_write() for {copy,clone}_file_range() and
for fallocate().
Beyond correct semantics, this avoids freeze protection to sb when
operating on special inodes, such as fallocate() on a blockdev.
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/open.c | 4 ++--
fs/read_write.c | 4 ++--
include/linux/fs.h | 26 +++++++++++++-------------
3 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/fs/open.c b/fs/open.c
index f9118f4..949cef2 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -314,7 +314,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
if (!file->f_op->fallocate)
return -EOPNOTSUPP;
- sb_start_write(inode->i_sb);
+ file_start_write(file);
ret = file->f_op->fallocate(file, mode, offset, len);
/*
@@ -327,7 +327,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
if (ret == 0)
fsnotify_modify(file);
- sb_end_write(inode->i_sb);
+ file_end_write(file);
return ret;
}
EXPORT_SYMBOL_GPL(vfs_fallocate);
diff --git a/fs/read_write.c b/fs/read_write.c
index 511178d..820a3f0 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1543,7 +1543,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
if (len == 0)
return 0;
- sb_start_write(inode_out->i_sb);
+ file_start_write(file_out);
/*
* Try cloning first, this is supported by more file systems, and
@@ -1579,7 +1579,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
inc_syscr(current);
inc_syscw(current);
- sb_end_write(inode_out->i_sb);
+ file_end_write(file_out);
return ret;
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 4a7f3cc..78c81e6 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1741,19 +1741,6 @@ extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
extern int vfs_dedupe_file_range(struct file *file,
struct file_dedupe_range *same);
-static inline int do_clone_file_range(struct file *file_in, loff_t pos_in,
- struct file *file_out, loff_t pos_out,
- u64 len)
-{
- int ret;
-
- sb_start_write(file_inode(file_out)->i_sb);
- ret = vfs_clone_file_range(file_in, pos_in, file_out, pos_out, len);
- sb_end_write(file_inode(file_out)->i_sb);
-
- return ret;
-}
-
struct super_operations {
struct inode *(*alloc_inode)(struct super_block *sb);
void (*destroy_inode)(struct inode *);
@@ -2564,6 +2551,19 @@ static inline void file_end_write(struct file *file)
__sb_end_write(file_inode(file)->i_sb, SB_FREEZE_WRITE);
}
+static inline int do_clone_file_range(struct file *file_in, loff_t pos_in,
+ struct file *file_out, loff_t pos_out,
+ u64 len)
+{
+ int ret;
+
+ file_start_write(file_out);
+ ret = vfs_clone_file_range(file_in, pos_in, file_out, pos_out, len);
+ file_end_write(file_out);
+
+ return ret;
+}
+
/*
* get_write_access() gets write permission for a file.
* put_write_access() releases this write permission.
--
2.7.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 4/5] vfs: freeze protect overlay inode on file_start_write()
2017-01-31 8:34 [PATCH v3 0/5] overlayfs: support freeze/thaw Amir Goldstein
` (2 preceding siblings ...)
2017-01-31 8:34 ` [PATCH v3 3/5] vfs: wrap write f_ops with file_{start,end}_write() Amir Goldstein
@ 2017-01-31 8:34 ` Amir Goldstein
2017-01-31 8:34 ` [PATCH v3 5/5] ovl: support freeze/thaw super Amir Goldstein
4 siblings, 0 replies; 11+ messages in thread
From: Amir Goldstein @ 2017-01-31 8:34 UTC (permalink / raw)
To: Miklos Szeredi
Cc: Jan Kara, Christoph Hellwig, Al Viro, linux-unionfs, linux-fsdevel
Before writing to overlay file, need to check if either overlay
or upper fs are frozen.
This allows freezing overlayfs mount independently of freezing
underlying fs.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
include/linux/fs.h | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 78c81e6..8a4dbc6 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2534,14 +2534,26 @@ static inline void file_start_write(struct file *file)
{
if (!S_ISREG(file_inode(file)->i_mode))
return;
+ __sb_start_write(locks_inode(file)->i_sb, SB_FREEZE_WRITE, true);
+ if (likely(locks_inode(file) == file_inode(file)))
+ return;
__sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true);
+
}
static inline bool file_start_write_trylock(struct file *file)
{
+ int ret;
+
if (!S_ISREG(file_inode(file)->i_mode))
return true;
- return __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, false);
+ ret = __sb_start_write(locks_inode(file)->i_sb, SB_FREEZE_WRITE, false);
+ if (!ret || likely(locks_inode(file) == file_inode(file)))
+ return ret;
+ ret = __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, false);
+ if (!ret)
+ __sb_end_write(locks_inode(file)->i_sb, SB_FREEZE_WRITE);
+ return ret;
}
static inline void file_end_write(struct file *file)
@@ -2549,6 +2561,9 @@ static inline void file_end_write(struct file *file)
if (!S_ISREG(file_inode(file)->i_mode))
return;
__sb_end_write(file_inode(file)->i_sb, SB_FREEZE_WRITE);
+ if (likely(locks_inode(file) == file_inode(file)))
+ return;
+ __sb_end_write(locks_inode(file)->i_sb, SB_FREEZE_WRITE);
}
static inline int do_clone_file_range(struct file *file_in, loff_t pos_in,
--
2.7.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 5/5] ovl: support freeze/thaw super
2017-01-31 8:34 [PATCH v3 0/5] overlayfs: support freeze/thaw Amir Goldstein
` (3 preceding siblings ...)
2017-01-31 8:34 ` [PATCH v3 4/5] vfs: freeze protect overlay inode on file_start_write() Amir Goldstein
@ 2017-01-31 8:34 ` Amir Goldstein
4 siblings, 0 replies; 11+ messages in thread
From: Amir Goldstein @ 2017-01-31 8:34 UTC (permalink / raw)
To: Miklos Szeredi
Cc: Jan Kara, Christoph Hellwig, Al Viro, linux-unionfs, linux-fsdevel
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/super.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 346f668..cb85eeb 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -179,6 +179,16 @@ static int ovl_sync_fs(struct super_block *sb, int wait)
return ret;
}
+static int ovl_freeze(struct super_block *sb)
+{
+ return 0;
+}
+
+static int ovl_unfreeze(struct super_block *sb)
+{
+ return 0;
+}
+
/**
* ovl_statfs
* @sb: The overlayfs super block
@@ -242,6 +252,8 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data)
static const struct super_operations ovl_super_operations = {
.put_super = ovl_put_super,
.sync_fs = ovl_sync_fs,
+ .freeze_fs = ovl_freeze,
+ .unfreeze_fs = ovl_unfreeze,
.statfs = ovl_statfs,
.show_options = ovl_show_options,
.remount_fs = ovl_remount,
--
2.7.4
^ permalink raw reply related [flat|nested] 11+ messages in thread