All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfs: Export fallocate facility to kernel modules
@ 2011-10-31 19:14 Thieu Le
  2011-11-02  7:53 ` Christoph Hellwig
  2011-11-05 12:30 ` Tyler Hicks
  0 siblings, 2 replies; 8+ messages in thread
From: Thieu Le @ 2011-10-31 19:14 UTC (permalink / raw)
  To: viro; +Cc: linux-fsdevel, linux-kernel, Thieu Le

Export fallocate facility so layered file systems such as ecryptfs can
take advantage of this feature.  One example of the need for fallocate
is by ecryptfs.  ecryptfs has recently switched to a writeback cache
model so its dirty pages are not written to the lower file system
immediately.  In order to ensure that space is available when the page
is later written, ecryptfs can efficiently preallocate that space using
vfs_fallocate().

vfs_fallocate() does not perform all of the checkings of do_fallocate()
because those checks are done higher in the stack.  Checking of offset and
len are done by rw_verify_area() and generic_write_checks().  These
functions are called by VFS before ecryptfs invokes vfs_fallocate() in its
ecryptfs_write_end() function.  And since ecryptfs directly opens the lower
file, it ensures that the file is opened with the proper flags and mode.

Signed-off-by: Thieu Le <thieule@chromium.org>
---
 fs/open.c          |   14 ++++++++++----
 include/linux/fs.h |    2 ++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index f711921..8a4ba20 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -214,6 +214,15 @@ SYSCALL_ALIAS(sys_ftruncate64, SyS_ftruncate64);
 #endif /* BITS_PER_LONG == 32 */
 
 
+int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
+{
+	if (!file->f_op->fallocate)
+		return -EOPNOTSUPP;
+
+	return file->f_op->fallocate(file, mode, offset, len);
+}
+EXPORT_SYMBOL(vfs_fallocate);
+
 int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 {
 	struct inode *inode = file->f_path.dentry->d_inode;
@@ -263,10 +272,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0))
 		return -EFBIG;
 
-	if (!file->f_op->fallocate)
-		return -EOPNOTSUPP;
-
-	return file->f_op->fallocate(file, mode, offset, len);
+	return vfs_fallocate(file, mode, offset, len);
 }
 
 SYSCALL_DEFINE(fallocate)(int fd, int mode, loff_t offset, loff_t len)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 277f497..c0e1225 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1504,6 +1504,8 @@ extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
 extern int vfs_rmdir(struct inode *, struct dentry *);
 extern int vfs_unlink(struct inode *, struct dentry *);
 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
+extern int vfs_fallocate(struct file *file, int mode, loff_t offset,
+			 loff_t len);
 
 /*
  * VFS dentry helper functions.
-- 
1.7.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] vfs: Export fallocate facility to kernel modules
  2011-10-31 19:14 [PATCH] vfs: Export fallocate facility to kernel modules Thieu Le
@ 2011-11-02  7:53 ` Christoph Hellwig
  2011-11-02 21:27   ` Thieu Le
  2011-11-05 12:30 ` Tyler Hicks
  1 sibling, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2011-11-02  7:53 UTC (permalink / raw)
  To: Thieu Le; +Cc: viro, linux-fsdevel, linux-kernel

As mentioned last time please submit together with the actual user for
review.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] vfs: Export fallocate facility to kernel modules
  2011-11-02  7:53 ` Christoph Hellwig
@ 2011-11-02 21:27   ` Thieu Le
  0 siblings, 0 replies; 8+ messages in thread
From: Thieu Le @ 2011-11-02 21:27 UTC (permalink / raw)
  To: hch; +Cc: viro, linux-fsdevel, linux-kernel, Thieu Le

The patch below illustrates the use of vfs_allocate() by ecryptfs.

---

eCryptfs does not allocate space in the lower file until writepage.  In
low free space situation, this leads to the application thinking the
write succeeds but it actually fails later when the page is written out.
This patch preallocates the space in the write path using fallocate()
first.  For lower file systems that do not support fallocate(), it falls back
to writing the encrypted page directly to the lower file.  The
preallocation is only done for writes that extend the file.

Signed-off-by: Thieu Le <thieule@chromium.org>
---
 fs/ecryptfs/mmap.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 6a44148..ed0eace 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -520,9 +520,29 @@ static int ecryptfs_write_end(struct file *file,
 		goto out;
 	}
 	set_page_dirty(page);
-	unlock_page(page);
-	need_unlock_page = 0;
 	if (pos + copied > i_size_read(ecryptfs_inode)) {
+		struct ecryptfs_inode_info *inode_info =
+			ecryptfs_inode_to_private(ecryptfs_inode);
+		loff_t offset = ecryptfs_lower_header_size(crypt_stat) + pos;
+		BUG_ON(!inode_info->lower_file);
+		rc = vfs_fallocate(inode_info->lower_file, 0, offset,
+				   PAGE_CACHE_SIZE);
+		if (rc == -EOPNOTSUPP)
+			rc = ecryptfs_encrypt_page(page);
+		if (rc) {
+			if (rc != -ENOSPC) {
+				ecryptfs_printk(KERN_ERR,
+						"Error preallocating page "
+						"(upper index "
+						"[0x%.16lx], rc = [%d])\n",
+						index, rc);
+			}
+			goto out;
+		}
+
+		unlock_page(page);
+		need_unlock_page = 0;
+
 		i_size_write(ecryptfs_inode, pos + copied);
 		ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
 			"[0x%.16llx]\n",
@@ -540,6 +560,8 @@ out:
 	if (need_unlock_page)
 		unlock_page(page);
 	page_cache_release(page);
+	if (rc)
+		truncate_inode_pages(mapping, i_size_read(ecryptfs_inode));
 	return rc;
 }
 
-- 
1.7.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] vfs: Export fallocate facility to kernel modules
  2011-10-31 19:14 [PATCH] vfs: Export fallocate facility to kernel modules Thieu Le
  2011-11-02  7:53 ` Christoph Hellwig
@ 2011-11-05 12:30 ` Tyler Hicks
  2011-11-05 17:04   ` Tyler Hicks
  1 sibling, 1 reply; 8+ messages in thread
From: Tyler Hicks @ 2011-11-05 12:30 UTC (permalink / raw)
  To: Thieu Le; +Cc: viro, Christoph Hellwig, linux-fsdevel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3505 bytes --]

On 2011-10-31 12:14:05, Thieu Le wrote:
> Export fallocate facility so layered file systems such as ecryptfs can
> take advantage of this feature.  One example of the need for fallocate
> is by ecryptfs.  ecryptfs has recently switched to a writeback cache
> model so its dirty pages are not written to the lower file system
> immediately.  In order to ensure that space is available when the page
> is later written, ecryptfs can efficiently preallocate that space using
> vfs_fallocate().

Hi Thieu - Thanks for the patch. Something like this is definitely
needed for eCryptfs.

> 
> vfs_fallocate() does not perform all of the checkings of do_fallocate()
> because those checks are done higher in the stack.

After taking a closer look at the checks in do_fallocate(), I don't know
that this statement is correct. The sanity checks around offset, len,
and mode aren't guaranteed to be done higher up in the stack. The
existing VFS helper functions also seem to do these types of checks. I
think the rest of the checks are redundant.

Tyler

> Checking of offset and
> len are done by rw_verify_area() and generic_write_checks().  These
> functions are called by VFS before ecryptfs invokes vfs_fallocate() in its
> ecryptfs_write_end() function.  And since ecryptfs directly opens the lower
> file, it ensures that the file is opened with the proper flags and mode.
> 
> Signed-off-by: Thieu Le <thieule@chromium.org>
> ---
>  fs/open.c          |   14 ++++++++++----
>  include/linux/fs.h |    2 ++
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/open.c b/fs/open.c
> index f711921..8a4ba20 100644
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -214,6 +214,15 @@ SYSCALL_ALIAS(sys_ftruncate64, SyS_ftruncate64);
>  #endif /* BITS_PER_LONG == 32 */
>  
>  
> +int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
> +{
> +	if (!file->f_op->fallocate)
> +		return -EOPNOTSUPP;
> +
> +	return file->f_op->fallocate(file, mode, offset, len);
> +}
> +EXPORT_SYMBOL(vfs_fallocate);
> +
>  int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
>  {
>  	struct inode *inode = file->f_path.dentry->d_inode;
> @@ -263,10 +272,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
>  	if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0))
>  		return -EFBIG;
>  
> -	if (!file->f_op->fallocate)
> -		return -EOPNOTSUPP;
> -
> -	return file->f_op->fallocate(file, mode, offset, len);
> +	return vfs_fallocate(file, mode, offset, len);
>  }
>  
>  SYSCALL_DEFINE(fallocate)(int fd, int mode, loff_t offset, loff_t len)
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 277f497..c0e1225 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -1504,6 +1504,8 @@ extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
>  extern int vfs_rmdir(struct inode *, struct dentry *);
>  extern int vfs_unlink(struct inode *, struct dentry *);
>  extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
> +extern int vfs_fallocate(struct file *file, int mode, loff_t offset,
> +			 loff_t len);
>  
>  /*
>   * VFS dentry helper functions.
> -- 
> 1.7.3.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vfs: Export fallocate facility to kernel modules
  2011-11-05 12:30 ` Tyler Hicks
@ 2011-11-05 17:04   ` Tyler Hicks
  2011-11-16 20:22     ` Thieu Le
  0 siblings, 1 reply; 8+ messages in thread
From: Tyler Hicks @ 2011-11-05 17:04 UTC (permalink / raw)
  To: Thieu Le; +Cc: viro, Christoph Hellwig, linux-fsdevel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3960 bytes --]

On 2011-11-05 08:30:02, Tyler Hicks wrote:
> On 2011-10-31 12:14:05, Thieu Le wrote:
> > Export fallocate facility so layered file systems such as ecryptfs can
> > take advantage of this feature.  One example of the need for fallocate
> > is by ecryptfs.  ecryptfs has recently switched to a writeback cache
> > model so its dirty pages are not written to the lower file system
> > immediately.  In order to ensure that space is available when the page
> > is later written, ecryptfs can efficiently preallocate that space using
> > vfs_fallocate().
> 
> Hi Thieu - Thanks for the patch. Something like this is definitely
> needed for eCryptfs.
> 
> > 
> > vfs_fallocate() does not perform all of the checkings of do_fallocate()
> > because those checks are done higher in the stack.
> 
> After taking a closer look at the checks in do_fallocate(), I don't know
> that this statement is correct. The sanity checks around offset, len,
> and mode aren't guaranteed to be done higher up in the stack. The
> existing VFS helper functions also seem to do these types of checks. I
> think the rest of the checks are redundant.

I obviously goofed up here. Thieu states where offset and len are
checked in his following sentence. Not sure how I missed that. My
apologies.

However, I do still think that we need the fallocate mode checks in
vfs_fallocate().

Tyler

> > Checking of offset and
> > len are done by rw_verify_area() and generic_write_checks().  These
> > functions are called by VFS before ecryptfs invokes vfs_fallocate() in its
> > ecryptfs_write_end() function.  And since ecryptfs directly opens the lower
> > file, it ensures that the file is opened with the proper flags and mode.
> > 
> > Signed-off-by: Thieu Le <thieule@chromium.org>
> > ---
> >  fs/open.c          |   14 ++++++++++----
> >  include/linux/fs.h |    2 ++
> >  2 files changed, 12 insertions(+), 4 deletions(-)
> > 
> > diff --git a/fs/open.c b/fs/open.c
> > index f711921..8a4ba20 100644
> > --- a/fs/open.c
> > +++ b/fs/open.c
> > @@ -214,6 +214,15 @@ SYSCALL_ALIAS(sys_ftruncate64, SyS_ftruncate64);
> >  #endif /* BITS_PER_LONG == 32 */
> >  
> >  
> > +int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
> > +{
> > +	if (!file->f_op->fallocate)
> > +		return -EOPNOTSUPP;
> > +
> > +	return file->f_op->fallocate(file, mode, offset, len);
> > +}
> > +EXPORT_SYMBOL(vfs_fallocate);
> > +
> >  int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
> >  {
> >  	struct inode *inode = file->f_path.dentry->d_inode;
> > @@ -263,10 +272,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
> >  	if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0))
> >  		return -EFBIG;
> >  
> > -	if (!file->f_op->fallocate)
> > -		return -EOPNOTSUPP;
> > -
> > -	return file->f_op->fallocate(file, mode, offset, len);
> > +	return vfs_fallocate(file, mode, offset, len);
> >  }
> >  
> >  SYSCALL_DEFINE(fallocate)(int fd, int mode, loff_t offset, loff_t len)
> > diff --git a/include/linux/fs.h b/include/linux/fs.h
> > index 277f497..c0e1225 100644
> > --- a/include/linux/fs.h
> > +++ b/include/linux/fs.h
> > @@ -1504,6 +1504,8 @@ extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
> >  extern int vfs_rmdir(struct inode *, struct dentry *);
> >  extern int vfs_unlink(struct inode *, struct dentry *);
> >  extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
> > +extern int vfs_fallocate(struct file *file, int mode, loff_t offset,
> > +			 loff_t len);
> >  
> >  /*
> >   * VFS dentry helper functions.
> > -- 
> > 1.7.3.1
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html



[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vfs: Export fallocate facility to kernel modules
  2011-11-05 17:04   ` Tyler Hicks
@ 2011-11-16 20:22     ` Thieu Le
  2011-11-18 19:53       ` Tyler Hicks
  0 siblings, 1 reply; 8+ messages in thread
From: Thieu Le @ 2011-11-16 20:22 UTC (permalink / raw)
  To: tyhicks; +Cc: viro, hch, linux-fsdevel, linux-kernel, Thieu Le

Export fallocate facility so layered file systems such as ecryptfs can
take advantage of this feature.  One example of the need for fallocate
is by ecryptfs.  ecryptfs has recently switched to a writeback cache
model so its dirty pages are not written to the lower file system
immediately.  In order to ensure that space is available when the page
is later written, ecryptfs can efficiently preallocate that space using
vfs_fallocate().

vfs_fallocate() does not perform all of the checkings of do_fallocate()
because those checks are done higher in the stack.  Checking of offset and
len are done by rw_verify_area() and generic_write_checks().  These
functions are called by VFS before ecryptfs invokes vfs_fallocate() in its
ecryptfs_write_end() function.  And since ecryptfs directly opens the lower
file, it ensures that the file is opened with the proper flags and mode.

Signed-off-by: Thieu Le <thieule@chromium.org>
---
 fs/open.c          |   32 ++++++++++++++++++++------------
 include/linux/fs.h |    2 ++
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index 22c41b5..65c0049 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -214,13 +214,9 @@ SYSCALL_ALIAS(sys_ftruncate64, SyS_ftruncate64);
 #endif /* BITS_PER_LONG == 32 */
 
 
-int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
+int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 {
 	struct inode *inode = file->f_path.dentry->d_inode;
-	long ret;
-
-	if (offset < 0 || len <= 0)
-		return -EINVAL;
 
 	/* Return error if mode is not supported */
 	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
@@ -231,13 +227,28 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	    !(mode & FALLOC_FL_KEEP_SIZE))
 		return -EOPNOTSUPP;
 
-	if (!(file->f_mode & FMODE_WRITE))
-		return -EBADF;
-
 	/* It's not possible punch hole on append only file */
 	if (mode & FALLOC_FL_PUNCH_HOLE && IS_APPEND(inode))
 		return -EPERM;
 
+	if (!file->f_op->fallocate)
+		return -EOPNOTSUPP;
+
+	return file->f_op->fallocate(file, mode, offset, len);
+}
+EXPORT_SYMBOL(vfs_fallocate);
+
+int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
+{
+	struct inode *inode = file->f_path.dentry->d_inode;
+	long ret;
+
+	if (offset < 0 || len <= 0)
+		return -EINVAL;
+
+	if (!(file->f_mode & FMODE_WRITE))
+		return -EBADF;
+
 	if (IS_IMMUTABLE(inode))
 		return -EPERM;
 
@@ -263,10 +274,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0))
 		return -EFBIG;
 
-	if (!file->f_op->fallocate)
-		return -EOPNOTSUPP;
-
-	return file->f_op->fallocate(file, mode, offset, len);
+	return vfs_fallocate(file, mode, offset, len);
 }
 
 SYSCALL_DEFINE(fallocate)(int fd, int mode, loff_t offset, loff_t len)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 0c4df26..e7d26ee 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1524,6 +1524,8 @@ extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
 extern int vfs_rmdir(struct inode *, struct dentry *);
 extern int vfs_unlink(struct inode *, struct dentry *);
 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
+extern int vfs_fallocate(struct file *file, int mode, loff_t offset,
+			 loff_t len);
 
 /*
  * VFS dentry helper functions.
-- 
1.7.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] vfs: Export fallocate facility to kernel modules
  2011-11-16 20:22     ` Thieu Le
@ 2011-11-18 19:53       ` Tyler Hicks
  2011-11-21 18:55         ` Thieu Le
  0 siblings, 1 reply; 8+ messages in thread
From: Tyler Hicks @ 2011-11-18 19:53 UTC (permalink / raw)
  To: Thieu Le; +Cc: viro, hch, linux-fsdevel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 4127 bytes --]

On 2011-11-16 12:22:41, Thieu Le wrote:
> Export fallocate facility so layered file systems such as ecryptfs can
> take advantage of this feature.  One example of the need for fallocate
> is by ecryptfs.  ecryptfs has recently switched to a writeback cache
> model so its dirty pages are not written to the lower file system
> immediately.  In order to ensure that space is available when the page
> is later written, ecryptfs can efficiently preallocate that space using
> vfs_fallocate().
> 
> vfs_fallocate() does not perform all of the checkings of do_fallocate()
> because those checks are done higher in the stack.  Checking of offset and
> len are done by rw_verify_area() and generic_write_checks().  These
> functions are called by VFS before ecryptfs invokes vfs_fallocate() in its
> ecryptfs_write_end() function.  And since ecryptfs directly opens the lower
> file, it ensures that the file is opened with the proper flags and mode.

This looks good to me. Feel free to add my Reviewed-by. Of course, it
will need final sign-off by Al and/or Christoph.

Tyler

> 
> Signed-off-by: Thieu Le <thieule@chromium.org>
> ---
>  fs/open.c          |   32 ++++++++++++++++++++------------
>  include/linux/fs.h |    2 ++
>  2 files changed, 22 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/open.c b/fs/open.c
> index 22c41b5..65c0049 100644
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -214,13 +214,9 @@ SYSCALL_ALIAS(sys_ftruncate64, SyS_ftruncate64);
>  #endif /* BITS_PER_LONG == 32 */
>  
>  
> -int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
> +int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
>  {
>  	struct inode *inode = file->f_path.dentry->d_inode;
> -	long ret;
> -
> -	if (offset < 0 || len <= 0)
> -		return -EINVAL;
>  
>  	/* Return error if mode is not supported */
>  	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
> @@ -231,13 +227,28 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
>  	    !(mode & FALLOC_FL_KEEP_SIZE))
>  		return -EOPNOTSUPP;
>  
> -	if (!(file->f_mode & FMODE_WRITE))
> -		return -EBADF;
> -
>  	/* It's not possible punch hole on append only file */
>  	if (mode & FALLOC_FL_PUNCH_HOLE && IS_APPEND(inode))
>  		return -EPERM;
>  
> +	if (!file->f_op->fallocate)
> +		return -EOPNOTSUPP;
> +
> +	return file->f_op->fallocate(file, mode, offset, len);
> +}
> +EXPORT_SYMBOL(vfs_fallocate);
> +
> +int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
> +{
> +	struct inode *inode = file->f_path.dentry->d_inode;
> +	long ret;
> +
> +	if (offset < 0 || len <= 0)
> +		return -EINVAL;
> +
> +	if (!(file->f_mode & FMODE_WRITE))
> +		return -EBADF;
> +
>  	if (IS_IMMUTABLE(inode))
>  		return -EPERM;
>  
> @@ -263,10 +274,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
>  	if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0))
>  		return -EFBIG;
>  
> -	if (!file->f_op->fallocate)
> -		return -EOPNOTSUPP;
> -
> -	return file->f_op->fallocate(file, mode, offset, len);
> +	return vfs_fallocate(file, mode, offset, len);
>  }
>  
>  SYSCALL_DEFINE(fallocate)(int fd, int mode, loff_t offset, loff_t len)
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 0c4df26..e7d26ee 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -1524,6 +1524,8 @@ extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
>  extern int vfs_rmdir(struct inode *, struct dentry *);
>  extern int vfs_unlink(struct inode *, struct dentry *);
>  extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
> +extern int vfs_fallocate(struct file *file, int mode, loff_t offset,
> +			 loff_t len);
>  
>  /*
>   * VFS dentry helper functions.
> -- 
> 1.7.3.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vfs: Export fallocate facility to kernel modules
  2011-11-18 19:53       ` Tyler Hicks
@ 2011-11-21 18:55         ` Thieu Le
  0 siblings, 0 replies; 8+ messages in thread
From: Thieu Le @ 2011-11-21 18:55 UTC (permalink / raw)
  To: tyhicks, viro, hch; +Cc: linux-fsdevel, linux-kernel, Thieu Le

Export fallocate facility so layered file systems such as ecryptfs can
take advantage of this feature.  One example of the need for fallocate
is by ecryptfs.  ecryptfs has recently switched to a writeback cache
model so its dirty pages are not written to the lower file system
immediately.  In order to ensure that space is available when the page
is later written, ecryptfs can efficiently preallocate that space using
vfs_fallocate().

vfs_fallocate() does not perform all of the checkings of do_fallocate()
because those checks are done higher in the stack.  Checking of offset and
len are done by rw_verify_area() and generic_write_checks().  These
functions are called by VFS before ecryptfs invokes vfs_fallocate() in its
ecryptfs_write_end() function.  And since ecryptfs directly opens the lower
file, it ensures that the file is opened with the proper flags and mode.

Signed-off-by: Thieu Le <thieule@chromium.org>
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
---
 fs/open.c          |   32 ++++++++++++++++++++------------
 include/linux/fs.h |    2 ++
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index 22c41b5..65c0049 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -214,13 +214,9 @@ SYSCALL_ALIAS(sys_ftruncate64, SyS_ftruncate64);
 #endif /* BITS_PER_LONG == 32 */
 
 
-int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
+int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 {
 	struct inode *inode = file->f_path.dentry->d_inode;
-	long ret;
-
-	if (offset < 0 || len <= 0)
-		return -EINVAL;
 
 	/* Return error if mode is not supported */
 	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
@@ -231,13 +227,28 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	    !(mode & FALLOC_FL_KEEP_SIZE))
 		return -EOPNOTSUPP;
 
-	if (!(file->f_mode & FMODE_WRITE))
-		return -EBADF;
-
 	/* It's not possible punch hole on append only file */
 	if (mode & FALLOC_FL_PUNCH_HOLE && IS_APPEND(inode))
 		return -EPERM;
 
+	if (!file->f_op->fallocate)
+		return -EOPNOTSUPP;
+
+	return file->f_op->fallocate(file, mode, offset, len);
+}
+EXPORT_SYMBOL(vfs_fallocate);
+
+int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
+{
+	struct inode *inode = file->f_path.dentry->d_inode;
+	long ret;
+
+	if (offset < 0 || len <= 0)
+		return -EINVAL;
+
+	if (!(file->f_mode & FMODE_WRITE))
+		return -EBADF;
+
 	if (IS_IMMUTABLE(inode))
 		return -EPERM;
 
@@ -263,10 +274,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0))
 		return -EFBIG;
 
-	if (!file->f_op->fallocate)
-		return -EOPNOTSUPP;
-
-	return file->f_op->fallocate(file, mode, offset, len);
+	return vfs_fallocate(file, mode, offset, len);
 }
 
 SYSCALL_DEFINE(fallocate)(int fd, int mode, loff_t offset, loff_t len)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 0c4df26..e7d26ee 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1524,6 +1524,8 @@ extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
 extern int vfs_rmdir(struct inode *, struct dentry *);
 extern int vfs_unlink(struct inode *, struct dentry *);
 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
+extern int vfs_fallocate(struct file *file, int mode, loff_t offset,
+			 loff_t len);
 
 /*
  * VFS dentry helper functions.
-- 
1.7.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-11-21 19:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-31 19:14 [PATCH] vfs: Export fallocate facility to kernel modules Thieu Le
2011-11-02  7:53 ` Christoph Hellwig
2011-11-02 21:27   ` Thieu Le
2011-11-05 12:30 ` Tyler Hicks
2011-11-05 17:04   ` Tyler Hicks
2011-11-16 20:22     ` Thieu Le
2011-11-18 19:53       ` Tyler Hicks
2011-11-21 18:55         ` Thieu Le

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.