diff mbox

[2/4] fs: Prevent doing FALLOC_FL_ZERO_RANGE on append only file

Message ID 1397242665-2183-2-git-send-email-lczerner@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lukas Czerner April 11, 2014, 6:57 p.m. UTC
Currently punch hole and collapse range fallocate operation are not
allowed on append only file. This should be case for zero range as well.
Fix it.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 fs/open.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Theodore Ts'o April 12, 2014, 1:49 p.m. UTC | #1
On Fri, Apr 11, 2014 at 08:57:43PM +0200, Lukas Czerner wrote:
> Currently punch hole and collapse range fallocate operation are not
> allowed on append only file. This should be case for zero range as well.
> Fix it.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>

Looks good to me.  If people don't object, I'll carry this in the ext4
tree for merging in 3.15, since this is a bug fix...

     	 	    	  	     	  - Ted
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christoph Hellwig April 12, 2014, 3:19 p.m. UTC | #2
On Fri, Apr 11, 2014 at 08:57:43PM +0200, Lukas Czerner wrote:
>  	/*
> -	 * It's not possible to punch hole or perform collapse range
> -	 * on append only file
> +	 * It's not possible to punch hole, perform collapse range
> +	 * or zero range on append only file
>  	 */
> -	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE)
> +	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
> +		    FALLOC_FL_ZERO_RANGE)

Might be better to make this a negative test fo the operation that is
allowed on an appen only file.  That's also much better future proof.

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dave Chinner April 15, 2014, 9:36 p.m. UTC | #3
On Tue, Apr 15, 2014 at 03:09:42PM +0200, Lukáš Czerner wrote:
> On Sat, 12 Apr 2014, Christoph Hellwig wrote:
> 
> > Date: Sat, 12 Apr 2014 08:19:35 -0700
> > From: Christoph Hellwig <hch@infradead.org>
> > To: Lukas Czerner <lczerner@redhat.com>
> > Cc: linux-fsdevel@vger.kernel.org, ceph-devel@vger.kernel.org,
> >     linux-ext4@vger.kernel.org, xfs@oss.sgi.com
> > Subject: Re: [PATCH 2/4] fs: Prevent doing FALLOC_FL_ZERO_RANGE on append only
> >      file
> > 
> > On Fri, Apr 11, 2014 at 08:57:43PM +0200, Lukas Czerner wrote:
> > >  	/*
> > > -	 * It's not possible to punch hole or perform collapse range
> > > -	 * on append only file
> > > +	 * It's not possible to punch hole, perform collapse range
> > > +	 * or zero range on append only file
> > >  	 */
> > > -	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE)
> > > +	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
> > > +		    FALLOC_FL_ZERO_RANGE)
> > 
> > Might be better to make this a negative test fo the operation that is
> > allowed on an appen only file.  That's also much better future proof.
> > 
> 
> True, it might be better to do it this way:
> 
> if (mode & ~FALLOC_FL_KEEP_SIZE && IS_APPEND(inode))

if ((mode & ~FALLOC_FL_KEEP_SIZE) && IS_APPEND(inode))

:)

Cheers,

Dave.
diff mbox

Patch

diff --git a/fs/open.c b/fs/open.c
index 631aea81..7882ff5 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -254,10 +254,11 @@  int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 		return -EBADF;
 
 	/*
-	 * It's not possible to punch hole or perform collapse range
-	 * on append only file
+	 * It's not possible to punch hole, perform collapse range
+	 * or zero range on append only file
 	 */
-	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE)
+	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
+		    FALLOC_FL_ZERO_RANGE)
 	    && IS_APPEND(inode))
 		return -EPERM;