From: Steve French <smfrench@gmail.com>
To: David Howells <dhowells@redhat.com>
Cc: sfrench@samba.org, linux-cifs@vger.kernel.org,
samba-technical@lists.samba.org, jlayton@kernel.org,
linux-kernel@vger.kernel.org, willy@infradead.org,
lsahlber@redhat.com, dchinner@redhat.com,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/5] smb3: Move the flush out of smb2_copychunk_range() into its callers
Date: Mon, 29 Aug 2022 11:56:58 -0500 [thread overview]
Message-ID: <CAH2r5msqTBu=wFn_wOaXucTn45WZfyNrAWqwpcGuxMFnpXyubA@mail.gmail.com> (raw)
In-Reply-To: <CAH2r5mt5iXtarkUAY7PSMGOLhkQd5LFcEz-rAnTkayxQMq_ppA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4784 bytes --]
e.g. something like the following
On Mon, Aug 29, 2022 at 12:06 AM Steve French <smfrench@gmail.com> wrote:
>
> Shouldn't this be using filemap_write_and_wait_range() not
> filemap_write_and_wait as we see in similar code in ext4 (and
> shouldn't it check rc in some of these cases)? For example for the
> copychunk_range example shouldn't the patch be modified similar to the
> following:
>
> diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
> index e9fb338b8e7e..51963e83daf7 100644
> --- a/fs/cifs/cifsfs.c
> +++ b/fs/cifs/cifsfs.c
> @@ -1219,8 +1219,6 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
>
> cifs_dbg(FYI, "copychunk range\n");
>
> - filemap_write_and_wait(src_inode->i_mapping);
> -
> if (!src_file->private_data || !dst_file->private_data) {
> rc = -EBADF;
> cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n");
> @@ -1250,6 +1248,12 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
> lock_two_nondirectories(target_inode, src_inode);
>
> cifs_dbg(FYI, "about to flush pages\n");
> +
> + rc = filemap_write_and_wait_range(src_inode->i_mapping, off,
> + off + len - 1);
> + if (rc)
> + goto out;
> +
> /* should we flush first and last page first */
> truncate_inode_pages(&target_inode->i_data, 0);
>
> On Tue, Aug 23, 2022 at 8:09 AM David Howells via samba-technical
> <samba-technical@lists.samba.org> wrote:
> >
> > Move the flush out of smb2_copychunk_range() into its callers. This will
> > allow the pagecache to be invalidated between the flush and the operation
> > in smb3_collapse_range() and smb3_insert_range().
> >
> > Signed-off-by: David Howells <dhowells@redhat.com>
> > cc: Steve French <stfrench@microsoft.com>
> > cc: Ronnie Sahlberg <lsahlber@redhat.com>
> > ---
> >
> > fs/cifs/cifsfs.c | 2 ++
> > fs/cifs/smb2ops.c | 20 ++++++++------------
> > 2 files changed, 10 insertions(+), 12 deletions(-)
> >
> > diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
> > index f54d8bf2732a..e9fb338b8e7e 100644
> > --- a/fs/cifs/cifsfs.c
> > +++ b/fs/cifs/cifsfs.c
> > @@ -1219,6 +1219,8 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
> >
> > cifs_dbg(FYI, "copychunk range\n");
> >
> > + filemap_write_and_wait(src_inode->i_mapping);
> > +
> > if (!src_file->private_data || !dst_file->private_data) {
> > rc = -EBADF;
> > cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n");
> > diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
> > index 96f3b0573606..7e3de6a0e1dc 100644
> > --- a/fs/cifs/smb2ops.c
> > +++ b/fs/cifs/smb2ops.c
> > @@ -1600,17 +1600,8 @@ smb2_copychunk_range(const unsigned int xid,
> > int chunks_copied = 0;
> > bool chunk_sizes_updated = false;
> > ssize_t bytes_written, total_bytes_written = 0;
> > - struct inode *inode;
> >
> > pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
> > -
> > - /*
> > - * We need to flush all unwritten data before we can send the
> > - * copychunk ioctl to the server.
> > - */
> > - inode = d_inode(trgtfile->dentry);
> > - filemap_write_and_wait(inode->i_mapping);
> > -
> > if (pcchunk == NULL)
> > return -ENOMEM;
> >
> > @@ -3689,6 +3680,8 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
> > goto out;
> > }
> >
> > + filemap_write_and_wait(inode->i_mapping);
> > +
> > rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
> > i_size_read(inode) - off - len, off);
> > if (rc < 0)
> > @@ -3716,18 +3709,21 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
> > int rc;
> > unsigned int xid;
> > struct cifsFileInfo *cfile = file->private_data;
> > + struct inode *inode = file_inode(file);
> > __le64 eof;
> > __u64 count;
> >
> > xid = get_xid();
> >
> > - if (off >= i_size_read(file->f_inode)) {
> > + if (off >= i_size_read(inode)) {
> > rc = -EINVAL;
> > goto out;
> > }
> >
> > - count = i_size_read(file->f_inode) - off;
> > - eof = cpu_to_le64(i_size_read(file->f_inode) + len);
> > + count = i_size_read(inode) - off;
> > + eof = cpu_to_le64(i_size_read(inode) + len);
> > +
> > + filemap_write_and_wait(inode->i_mapping);
> >
> > rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
> > cfile->fid.volatile_fid, cfile->pid, &eof);
> >
> >
> >
>
>
> --
> Thanks,
>
> Steve
--
Thanks,
Steve
[-- Attachment #2: 0001-smb3-use-filemap_write_and_wait_range-instead-of-fil.patch --]
[-- Type: text/x-patch, Size: 2262 bytes --]
From 5b12e7e9dcefe683c18ccfa064d216c8f83672d0 Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Mon, 29 Aug 2022 11:53:41 -0500
Subject: [PATCH] smb3: use filemap_write_and_wait_range instead of
filemap_write_and_wait
When doing insert range and collapse range we should be
writing out the cached pages for the ranges affected but not
the whole file.
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/cifs/cifsfs.c | 8 ++++++--
fs/cifs/smb2ops.c | 2 ++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index e9fb338b8e7e..51963e83daf7 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -1219,8 +1219,6 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
cifs_dbg(FYI, "copychunk range\n");
- filemap_write_and_wait(src_inode->i_mapping);
-
if (!src_file->private_data || !dst_file->private_data) {
rc = -EBADF;
cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n");
@@ -1250,6 +1248,12 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
lock_two_nondirectories(target_inode, src_inode);
cifs_dbg(FYI, "about to flush pages\n");
+
+ rc = filemap_write_and_wait_range(src_inode->i_mapping, off,
+ off + len - 1);
+ if (rc)
+ goto out;
+
/* should we flush first and last page first */
truncate_inode_pages(&target_inode->i_data, 0);
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 7c941ce1e7a9..12319cef42a7 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -3688,6 +3688,7 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
filemap_invalidate_lock(inode->i_mapping);
filemap_write_and_wait(inode->i_mapping);
+ rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
truncate_pagecache_range(inode, off, old_eof);
rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
@@ -3739,6 +3740,7 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
filemap_invalidate_lock(inode->i_mapping);
filemap_write_and_wait(inode->i_mapping);
+ rc = filemap_write_and_wait_range(inode->i_mapping, off, eof - 1);
truncate_pagecache_range(inode, off, old_eof);
rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
--
2.34.1
next prev parent reply other threads:[~2022-08-29 16:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-23 13:07 [PATCH 0/5] smb3: Fix missing locks and invalidation in fallocate David Howells
2022-08-23 13:07 ` [PATCH 1/5] smb3: Move the flush out of smb2_copychunk_range() into its callers David Howells
2022-08-29 5:06 ` Steve French
2022-08-29 16:56 ` Steve French [this message]
2022-08-23 13:07 ` [PATCH 2/5] smb3: missing inode locks in zero range David Howells
2022-08-23 13:07 ` [PATCH 3/5] smb3: fix temporary data corruption in collapse range David Howells
2022-08-23 14:07 ` Matthew Wilcox
2022-08-23 14:14 ` David Howells
2022-08-23 14:17 ` David Howells
2022-08-23 13:07 ` [PATCH 4/5] smb3: missing inode locks in punch hole David Howells
2022-08-23 13:07 ` [PATCH 5/5] smb3: fix temporary data corruption in insert range David Howells
2022-08-24 5:58 ` Steve French
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH2r5msqTBu=wFn_wOaXucTn45WZfyNrAWqwpcGuxMFnpXyubA@mail.gmail.com' \
--to=smfrench@gmail.com \
--cc=dchinner@redhat.com \
--cc=dhowells@redhat.com \
--cc=jlayton@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lsahlber@redhat.com \
--cc=samba-technical@lists.samba.org \
--cc=sfrench@samba.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).