2014-07-31 17:53:46

by Nicholas Krause

[permalink] [raw]
Subject: [PATCH] Add support to check for FALLOC_FL_COLLAPSE_RANGE and FALLOC_FL_ZERO_RANGE crap modes

This adds checks for the stated modes as if they are crap we will return error
not supported.

Signed-off-by: Nicholas Krause <[email protected]>
---
fs/btrfs/file.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 1f2b99c..599495a 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2490,7 +2490,8 @@ static long btrfs_fallocate(struct file *file, int mode,
alloc_end = round_up(offset + len, blocksize);

/* Make sure we aren't being give some crap mode */
- if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
+ if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE|
+ FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE))
return -EOPNOTSUPP;

if (mode & FALLOC_FL_PUNCH_HOLE)
--
1.7.10.4


2014-07-31 19:09:36

by Hugo Mills

[permalink] [raw]
Subject: Re: [PATCH] Add support to check for FALLOC_FL_COLLAPSE_RANGE and FALLOC_FL_ZERO_RANGE crap modes

On Thu, Jul 31, 2014 at 01:53:33PM -0400, Nicholas Krause wrote:
> This adds checks for the stated modes as if they are crap we will return error
> not supported.

You've just enabled two options, but you haven't actually
implemented the code behind it. I would tell you *NOT* to do anything
else on this work until you can answer the question: What happens if
you apply this patch, create a large file called "foo.txt", and then a
userspace program executes the following code?

int fd = open("foo.txt", O_RDWR);
fallocate(fd, FALLOCATE_FL_COLLAPSE_RANGE, 50, 50);

Try it on a btrfs filesystem, both with and without your patch.
Also try it on an ext4 filesystem.

Once you've done all of that, reply to this mail and tell me what
the problem is with this patch. You need to make two answers: what are
the technical problems with the patch? What errors have you made in
the development process?

*Only* if you can answer those questions sensibly, should you write
any more patches, of any kind.

Hugo.

> Signed-off-by: Nicholas Krause <[email protected]>
> ---
> fs/btrfs/file.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 1f2b99c..599495a 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -2490,7 +2490,8 @@ static long btrfs_fallocate(struct file *file, int mode,
> alloc_end = round_up(offset + len, blocksize);
>
> /* Make sure we aren't being give some crap mode */
> - if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
> + if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE|
> + FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE))
> return -EOPNOTSUPP;
>
> if (mode & FALLOC_FL_PUNCH_HOLE)
> --
> 1.7.10.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

--
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
PGP key: 65E74AC0 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
--- The glass is neither half-full nor half-empty; it is twice as ---
large as it needs to be.


Attachments:
(No filename) (2.20 kB)
signature.asc (811.00 B)
Digital signature
Download all attachments

2014-08-01 01:49:23

by Duncan

[permalink] [raw]
Subject: Re: [PATCH] Add support to check for FALLOC_FL_COLLAPSE_RANGE and FALLOC_FL_ZERO_RANGE crap modes

Nicholas Krause posted on Thu, 31 Jul 2014 13:53:33 -0400 as excerpted:

> This adds checks for the stated modes as if they are crap we will return
> error not supported.
>
> Signed-off-by: Nicholas Krause <[email protected]>
> ---
> fs/btrfs/file.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 1f2b99c..599495a
> 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2490,7 +2490,8 @@
> static long btrfs_fallocate(struct file *file, int mode,
> alloc_end = round_up(offset + len, blocksize);
>
> /* Make sure we aren't being give some crap mode */
> - if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
> + if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE| +
> FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE))
> return -EOPNOTSUPP;
>
> if (mode & FALLOC_FL_PUNCH_HOLE)

Is the supporting code already there?

You're removing the EOPNOTSUPP errors, but the code doesn't add the
support, just removes the errors in the check for it, yet your comment
doesn't point out that the support is actually already there with a
pointer to either the commit adding it or the functions supporting it, as
it should if that's true and the implementing patch simply forgot to
remove those checks.

--
Duncan - List replies preferred. No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master." Richard Stallman

2014-08-01 01:53:18

by Nicholas Krause

[permalink] [raw]
Subject: Re: [PATCH] Add support to check for FALLOC_FL_COLLAPSE_RANGE and FALLOC_FL_ZERO_RANGE crap modes

On Thu, Jul 31, 2014 at 3:09 PM, Hugo Mills <[email protected]> wrote:
> On Thu, Jul 31, 2014 at 01:53:33PM -0400, Nicholas Krause wrote:
>> This adds checks for the stated modes as if they are crap we will return error
>> not supported.
>
> You've just enabled two options, but you haven't actually
> implemented the code behind it. I would tell you *NOT* to do anything
> else on this work until you can answer the question: What happens if
> you apply this patch, create a large file called "foo.txt", and then a
> userspace program executes the following code?
>
> int fd = open("foo.txt", O_RDWR);
> fallocate(fd, FALLOCATE_FL_COLLAPSE_RANGE, 50, 50);
>
> Try it on a btrfs filesystem, both with and without your patch.
> Also try it on an ext4 filesystem.
>
> Once you've done all of that, reply to this mail and tell me what
> the problem is with this patch. You need to make two answers: what are
> the technical problems with the patch? What errors have you made in
> the development process?
>
> *Only* if you can answer those questions sensibly, should you write
> any more patches, of any kind.
>
> Hugo.
>
>> Signed-off-by: Nicholas Krause <[email protected]>
>> ---
>> fs/btrfs/file.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
>> index 1f2b99c..599495a 100644
>> --- a/fs/btrfs/file.c
>> +++ b/fs/btrfs/file.c
>> @@ -2490,7 +2490,8 @@ static long btrfs_fallocate(struct file *file, int mode,
>> alloc_end = round_up(offset + len, blocksize);
>>
>> /* Make sure we aren't being give some crap mode */
>> - if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
>> + if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE|
>> + FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE))
>> return -EOPNOTSUPP;
>>
>> if (mode & FALLOC_FL_PUNCH_HOLE)
>> --
>> 1.7.10.4
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
> --
> === Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
> PGP key: 65E74AC0 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
> --- The glass is neither half-full nor half-empty; it is twice as ---
> large as it needs to be.
Calls are there in btrfs , therefore will either kernel panic or cause an oops.
Need to test this patch as this is very easy to catch bug.
Nick