linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE
@ 2021-03-26  1:31 Ronnie Sahlberg
  2021-03-26  5:58 ` kernel test robot
  2021-03-26  8:35 ` Dan Carpenter
  0 siblings, 2 replies; 8+ messages in thread
From: Ronnie Sahlberg @ 2021-03-26  1:31 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/smb2ops.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 9bae7e8deb09..1082c22551d7 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -3640,6 +3640,44 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
 	return rc;
 }
 
+static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
+			    loff_t off, loff_t len)
+{
+	int rc;
+	unsigned int xid;
+	struct cifsFileInfo *cfile = file->private_data;
+	__le64 eof;
+
+	xid = get_xid();
+
+	if (off + len < off) {
+		rc -EFBIG;
+		goto out;
+	}
+
+	if (off >= i_size_read(file->f_inode) ||
+	    off + len >= i_size_read(file->f_inode)) {
+		rc -EINVAL;
+		goto out;
+	}
+
+	rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
+				  i_size_read(file->f_inode) - off - len, off);
+	if (rc < 0)
+		goto out;
+
+	eof = i_size_read(file->f_inode) - len;
+	rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
+			  cfile->fid.volatile_fid, cfile->pid, &eof);
+	if (rc < 0)
+		goto out;
+
+	rc = 0;
+ out:
+	free_xid(xid);
+	return rc;
+}
+
 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
 {
 	struct cifsFileInfo *wrcfile, *cfile = file->private_data;
@@ -3811,6 +3849,8 @@ static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
 		return smb3_zero_range(file, tcon, off, len, false);
 	} else if (mode == FALLOC_FL_KEEP_SIZE)
 		return smb3_simple_falloc(file, tcon, off, len, true);
+	else if (mode == FALLOC_FL_COLLAPSE_RANGE)
+		return smb3_collapse_range(file, tcon, off, len);
 	else if (mode == 0)
 		return smb3_simple_falloc(file, tcon, off, len, false);
 
-- 
2.29.2


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

* Re: [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE
  2021-03-26  1:31 [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE Ronnie Sahlberg
@ 2021-03-26  5:58 ` kernel test robot
  2021-03-26  8:35 ` Dan Carpenter
  1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2021-03-26  5:58 UTC (permalink / raw)
  To: Ronnie Sahlberg, linux-cifs; +Cc: kbuild-all, clang-built-linux, Steve French

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

Hi Ronnie,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on cifs/for-next]
[also build test WARNING on v5.12-rc4 next-20210325]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ronnie-Sahlberg/cifs-add-support-for-FALLOC_FL_COLLAPSE_RANGE/20210326-093328
base:   git://git.samba.org/sfrench/cifs-2.6.git for-next
config: x86_64-randconfig-a015-20210325 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project f490a5969bd52c8a48586f134ff8f02ccbb295b3)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/0536911dc253bdf2243c8054b5f6fbd256dcdb49
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Ronnie-Sahlberg/cifs-add-support-for-FALLOC_FL_COLLAPSE_RANGE/20210326-093328
        git checkout 0536911dc253bdf2243c8054b5f6fbd256dcdb49
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   fs/cifs/smb2ops.c:3654:6: warning: expression result unused [-Wunused-value]
                   rc -EFBIG;
                   ~~ ^~~~~~
   fs/cifs/smb2ops.c:3660:6: warning: expression result unused [-Wunused-value]
                   rc -EINVAL;
                   ~~ ^~~~~~~
>> fs/cifs/smb2ops.c:3654:3: warning: variable 'rc' is uninitialized when used here [-Wuninitialized]
                   rc -EFBIG;
                   ^~
   fs/cifs/smb2ops.c:3646:8: note: initialize the variable 'rc' to silence this warning
           int rc;
                 ^
                  = 0
   3 warnings generated.


vim +/rc +3654 fs/cifs/smb2ops.c

  3642	
  3643	static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
  3644				    loff_t off, loff_t len)
  3645	{
  3646		int rc;
  3647		unsigned int xid;
  3648		struct cifsFileInfo *cfile = file->private_data;
  3649		__le64 eof;
  3650	
  3651		xid = get_xid();
  3652	
  3653		if (off + len < off) {
> 3654			rc -EFBIG;
  3655			goto out;
  3656		}
  3657	
  3658		if (off >= i_size_read(file->f_inode) ||
  3659		    off + len >= i_size_read(file->f_inode)) {
  3660			rc -EINVAL;
  3661			goto out;
  3662		}
  3663	
  3664		rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
  3665					  i_size_read(file->f_inode) - off - len, off);
  3666		if (rc < 0)
  3667			goto out;
  3668	
  3669		eof = i_size_read(file->f_inode) - len;
  3670		rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
  3671				  cfile->fid.volatile_fid, cfile->pid, &eof);
  3672		if (rc < 0)
  3673			goto out;
  3674	
  3675		rc = 0;
  3676	 out:
  3677		free_xid(xid);
  3678		return rc;
  3679	}
  3680	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 29984 bytes --]

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

* Re: [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE
  2021-03-26  1:31 [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE Ronnie Sahlberg
  2021-03-26  5:58 ` kernel test robot
@ 2021-03-26  8:35 ` Dan Carpenter
  1 sibling, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2021-03-26  8:35 UTC (permalink / raw)
  To: kbuild, Ronnie Sahlberg, linux-cifs; +Cc: lkp, kbuild-all, Steve French

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

Hi Ronnie,

url:    https://github.com/0day-ci/linux/commits/Ronnie-Sahlberg/cifs-add-support-for-FALLOC_FL_COLLAPSE_RANGE/20210326-093328
base:   git://git.samba.org/sfrench/cifs-2.6.git for-next
config: i386-randconfig-m021-20210325 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/cifs/smb2ops.c:3654 smb3_collapse_range() warn: statement has no effect 5
fs/cifs/smb2ops.c:3654 smb3_collapse_range() error: uninitialized symbol 'rc'.

Old smatch warnings:
fs/cifs/smb2ops.c:3660 smb3_collapse_range() warn: statement has no effect 5
fs/cifs/smb2ops.c:3660 smb3_collapse_range() error: uninitialized symbol 'rc'.

vim +3654 fs/cifs/smb2ops.c

0536911dc253bd Ronnie Sahlberg 2021-03-26  3643  static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
0536911dc253bd Ronnie Sahlberg 2021-03-26  3644  			    loff_t off, loff_t len)
0536911dc253bd Ronnie Sahlberg 2021-03-26  3645  {
0536911dc253bd Ronnie Sahlberg 2021-03-26  3646  	int rc;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3647  	unsigned int xid;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3648  	struct cifsFileInfo *cfile = file->private_data;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3649  	__le64 eof;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3650  
0536911dc253bd Ronnie Sahlberg 2021-03-26  3651  	xid = get_xid();
0536911dc253bd Ronnie Sahlberg 2021-03-26  3652  
0536911dc253bd Ronnie Sahlberg 2021-03-26  3653  	if (off + len < off) {
0536911dc253bd Ronnie Sahlberg 2021-03-26 @3654  		rc -EFBIG;

Missing = character.

0536911dc253bd Ronnie Sahlberg 2021-03-26  3655  		goto out;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3656  	}
0536911dc253bd Ronnie Sahlberg 2021-03-26  3657  
0536911dc253bd Ronnie Sahlberg 2021-03-26  3658  	if (off >= i_size_read(file->f_inode) ||
0536911dc253bd Ronnie Sahlberg 2021-03-26  3659  	    off + len >= i_size_read(file->f_inode)) {
0536911dc253bd Ronnie Sahlberg 2021-03-26  3660  		rc -EINVAL;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3661  		goto out;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3662  	}
0536911dc253bd Ronnie Sahlberg 2021-03-26  3663  
0536911dc253bd Ronnie Sahlberg 2021-03-26  3664  	rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
0536911dc253bd Ronnie Sahlberg 2021-03-26  3665  				  i_size_read(file->f_inode) - off - len, off);
0536911dc253bd Ronnie Sahlberg 2021-03-26  3666  	if (rc < 0)
0536911dc253bd Ronnie Sahlberg 2021-03-26  3667  		goto out;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3668  
0536911dc253bd Ronnie Sahlberg 2021-03-26  3669  	eof = i_size_read(file->f_inode) - len;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3670  	rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
0536911dc253bd Ronnie Sahlberg 2021-03-26  3671  			  cfile->fid.volatile_fid, cfile->pid, &eof);
0536911dc253bd Ronnie Sahlberg 2021-03-26  3672  	if (rc < 0)
0536911dc253bd Ronnie Sahlberg 2021-03-26  3673  		goto out;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3674  
0536911dc253bd Ronnie Sahlberg 2021-03-26  3675  	rc = 0;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3676   out:
0536911dc253bd Ronnie Sahlberg 2021-03-26  3677  	free_xid(xid);
0536911dc253bd Ronnie Sahlberg 2021-03-26  3678  	return rc;
0536911dc253bd Ronnie Sahlberg 2021-03-26  3679  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 39072 bytes --]

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

* Re: [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE
  2021-03-26 19:52 Ronnie Sahlberg
  2021-03-30 14:21 ` Aurélien Aptel
@ 2021-04-01  5:41 ` Steve French
  1 sibling, 0 replies; 8+ messages in thread
From: Steve French @ 2021-04-01  5:41 UTC (permalink / raw)
  To: Ronnie Sahlberg; +Cc: linux-cifs, samba-technical

Running xfstests on this patch (along with the previous INSERT_RANGE
patch) fixes at least six xfstests which were skipped before:

# ./check -cifs generic/072 generic/145 generic/147 generic/153
generic/351 generic/458
FSTYP         -- cifs
PLATFORM      -- Linux/x86_64 smfrench-Virtual-Machine
5.12.0-051200rc4-generic #202103212230 SMP Sun Mar 21 22:33:27 UTC
2021

generic/072 7s ...  6s
generic/145 0s ...  1s
generic/147 1s ...  0s
generic/153 0s ...  1s
generic/351 5s ...  3s
generic/458 1s ...  1s
Ran: generic/072 generic/145 generic/147 generic/153 generic/351 generic/458
Passed all 6 tests

Promising ... there are additional fallocate related tests that still
fail or are skipped, but good progress ...


On Fri, Mar 26, 2021 at 2:52 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
>
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/smb2ops.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
>
> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
> index 9bae7e8deb09..3bb18944aaa4 100644
> --- a/fs/cifs/smb2ops.c
> +++ b/fs/cifs/smb2ops.c
> @@ -3640,6 +3640,44 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
>         return rc;
>  }
>
> +static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
> +                           loff_t off, loff_t len)
> +{
> +       int rc;
> +       unsigned int xid;
> +       struct cifsFileInfo *cfile = file->private_data;
> +       __le64 eof;
> +
> +       xid = get_xid();
> +
> +       if (off + len < off) {
> +               rc = -EFBIG;
> +               goto out;
> +       }
> +
> +       if (off >= i_size_read(file->f_inode) ||
> +           off + len >= i_size_read(file->f_inode)) {
> +               rc = -EINVAL;
> +               goto out;
> +       }
> +
> +       rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
> +                                 i_size_read(file->f_inode) - off - len, off);
> +       if (rc < 0)
> +               goto out;
> +
> +       eof = i_size_read(file->f_inode) - len;
> +       rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
> +                         cfile->fid.volatile_fid, cfile->pid, &eof);
> +       if (rc < 0)
> +               goto out;
> +
> +       rc = 0;
> + out:
> +       free_xid(xid);
> +       return rc;
> +}
> +
>  static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
>  {
>         struct cifsFileInfo *wrcfile, *cfile = file->private_data;
> @@ -3811,6 +3849,8 @@ static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
>                 return smb3_zero_range(file, tcon, off, len, false);
>         } else if (mode == FALLOC_FL_KEEP_SIZE)
>                 return smb3_simple_falloc(file, tcon, off, len, true);
> +       else if (mode == FALLOC_FL_COLLAPSE_RANGE)
> +               return smb3_collapse_range(file, tcon, off, len);
>         else if (mode == 0)
>                 return smb3_simple_falloc(file, tcon, off, len, false);
>
> --
> 2.29.2
>


--
Thanks,

Steve

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

* Re: [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE
  2021-03-30 22:09   ` ronnie sahlberg
@ 2021-03-30 22:15     ` Steve French
  0 siblings, 0 replies; 8+ messages in thread
From: Steve French @ 2021-03-30 22:15 UTC (permalink / raw)
  To: ronnie sahlberg; +Cc: Aurélien Aptel, Ronnie Sahlberg, linux-cifs

On Tue, Mar 30, 2021 at 5:09 PM ronnie sahlberg
<ronniesahlberg@gmail.com> wrote:
>
> On Wed, Mar 31, 2021 at 12:22 AM Aurélien Aptel <aaptel@suse.com> wrote:
> >
> > Ronnie Sahlberg <lsahlber@redhat.com> writes:
> > > +static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
> > > +                         loff_t off, loff_t len)
> > > +{
> > > +     int rc;
> > > +     unsigned int xid;
> > > +     struct cifsFileInfo *cfile = file->private_data;
> > > +     __le64 eof;
> > > +
> > > +     xid = get_xid();
> > > +
> > > +     if (off + len < off) {
> > > +             rc = -EFBIG;
> > > +             goto out;
> > > +     }
> >
> > loff_t is defined as 'long long' for me which is signed, and signed
> > overflow is Undefined Behaviour, unless we compile with -fwrapv which
> > I'm not sure it is something we can assume.
> >
> > Also, vfs_fallocate() in fs/open.c already does an overflow check before
> > calling f_op->falloc(), this is probably not needed. (It's also relying
> > on signed overflow so I guess it is ok...?)
>
> Thanks.
> Steve, can you drop this check from the patch?

Yes.   I was trying to run some xfstests on it vs. Windows with REFS
(and Samba with BTRFS after that).  Any observations on these two
patches and xfstests?

> > Rest of the patch looks good otherwise.
> >
> > Cheers,
> > --
> > Aurélien Aptel / SUSE Labs Samba Team




-- 
Thanks,

Steve

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

* Re: [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE
  2021-03-30 14:21 ` Aurélien Aptel
@ 2021-03-30 22:09   ` ronnie sahlberg
  2021-03-30 22:15     ` Steve French
  0 siblings, 1 reply; 8+ messages in thread
From: ronnie sahlberg @ 2021-03-30 22:09 UTC (permalink / raw)
  To: Aurélien Aptel; +Cc: Ronnie Sahlberg, linux-cifs, Steve French

On Wed, Mar 31, 2021 at 12:22 AM Aurélien Aptel <aaptel@suse.com> wrote:
>
> Ronnie Sahlberg <lsahlber@redhat.com> writes:
> > +static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
> > +                         loff_t off, loff_t len)
> > +{
> > +     int rc;
> > +     unsigned int xid;
> > +     struct cifsFileInfo *cfile = file->private_data;
> > +     __le64 eof;
> > +
> > +     xid = get_xid();
> > +
> > +     if (off + len < off) {
> > +             rc = -EFBIG;
> > +             goto out;
> > +     }
>
> loff_t is defined as 'long long' for me which is signed, and signed
> overflow is Undefined Behaviour, unless we compile with -fwrapv which
> I'm not sure it is something we can assume.
>
> Also, vfs_fallocate() in fs/open.c already does an overflow check before
> calling f_op->falloc(), this is probably not needed. (It's also relying
> on signed overflow so I guess it is ok...?)

Thanks.
Steve, can you drop this check from the patch?

>
> Rest of the patch looks good otherwise.
>
> Cheers,
> --
> Aurélien Aptel / SUSE Labs Samba Team
> GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
> SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg, DE
> GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 247165 (AG München)
>

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

* Re: [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE
  2021-03-26 19:52 Ronnie Sahlberg
@ 2021-03-30 14:21 ` Aurélien Aptel
  2021-03-30 22:09   ` ronnie sahlberg
  2021-04-01  5:41 ` Steve French
  1 sibling, 1 reply; 8+ messages in thread
From: Aurélien Aptel @ 2021-03-30 14:21 UTC (permalink / raw)
  To: Ronnie Sahlberg, linux-cifs; +Cc: Steve French

Ronnie Sahlberg <lsahlber@redhat.com> writes:
> +static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
> +			    loff_t off, loff_t len)
> +{
> +	int rc;
> +	unsigned int xid;
> +	struct cifsFileInfo *cfile = file->private_data;
> +	__le64 eof;
> +
> +	xid = get_xid();
> +
> +	if (off + len < off) {
> +		rc = -EFBIG;
> +		goto out;
> +	}

loff_t is defined as 'long long' for me which is signed, and signed
overflow is Undefined Behaviour, unless we compile with -fwrapv which
I'm not sure it is something we can assume.

Also, vfs_fallocate() in fs/open.c already does an overflow check before
calling f_op->falloc(), this is probably not needed. (It's also relying
on signed overflow so I guess it is ok...?)

Rest of the patch looks good otherwise.

Cheers,
-- 
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg, DE
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 247165 (AG München)


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

* [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE
@ 2021-03-26 19:52 Ronnie Sahlberg
  2021-03-30 14:21 ` Aurélien Aptel
  2021-04-01  5:41 ` Steve French
  0 siblings, 2 replies; 8+ messages in thread
From: Ronnie Sahlberg @ 2021-03-26 19:52 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/smb2ops.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 9bae7e8deb09..3bb18944aaa4 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -3640,6 +3640,44 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
 	return rc;
 }
 
+static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
+			    loff_t off, loff_t len)
+{
+	int rc;
+	unsigned int xid;
+	struct cifsFileInfo *cfile = file->private_data;
+	__le64 eof;
+
+	xid = get_xid();
+
+	if (off + len < off) {
+		rc = -EFBIG;
+		goto out;
+	}
+
+	if (off >= i_size_read(file->f_inode) ||
+	    off + len >= i_size_read(file->f_inode)) {
+		rc = -EINVAL;
+		goto out;
+	}
+
+	rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
+				  i_size_read(file->f_inode) - off - len, off);
+	if (rc < 0)
+		goto out;
+
+	eof = i_size_read(file->f_inode) - len;
+	rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
+			  cfile->fid.volatile_fid, cfile->pid, &eof);
+	if (rc < 0)
+		goto out;
+
+	rc = 0;
+ out:
+	free_xid(xid);
+	return rc;
+}
+
 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
 {
 	struct cifsFileInfo *wrcfile, *cfile = file->private_data;
@@ -3811,6 +3849,8 @@ static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
 		return smb3_zero_range(file, tcon, off, len, false);
 	} else if (mode == FALLOC_FL_KEEP_SIZE)
 		return smb3_simple_falloc(file, tcon, off, len, true);
+	else if (mode == FALLOC_FL_COLLAPSE_RANGE)
+		return smb3_collapse_range(file, tcon, off, len);
 	else if (mode == 0)
 		return smb3_simple_falloc(file, tcon, off, len, false);
 
-- 
2.29.2


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

end of thread, other threads:[~2021-04-01  5:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-26  1:31 [PATCH] cifs: add support for FALLOC_FL_COLLAPSE_RANGE Ronnie Sahlberg
2021-03-26  5:58 ` kernel test robot
2021-03-26  8:35 ` Dan Carpenter
2021-03-26 19:52 Ronnie Sahlberg
2021-03-30 14:21 ` Aurélien Aptel
2021-03-30 22:09   ` ronnie sahlberg
2021-03-30 22:15     ` Steve French
2021-04-01  5:41 ` Steve French

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).