From: Simon Horman <horms@kernel.org>
To: David Howells <dhowells@redhat.com>
Cc: Christian Brauner <christian@brauner.io>,
Jeff Layton <jlayton@kernel.org>,
Gao Xiang <hsiangkao@linux.alibaba.com>,
Dominique Martinet <asmadeus@codewreck.org>,
Steve French <smfrench@gmail.com>,
Matthew Wilcox <willy@infradead.org>,
Marc Dionne <marc.dionne@auristor.com>,
Paulo Alcantara <pc@manguebit.com>,
Shyam Prasad N <sprasad@microsoft.com>,
Tom Talpey <tom@talpey.com>,
Eric Van Hensbergen <ericvh@kernel.org>,
Ilya Dryomov <idryomov@gmail.com>,
linux-cachefs@redhat.com, linux-afs@lists.infradead.org,
linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org,
ceph-devel@vger.kernel.org, v9fs@lists.linux.dev,
linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Yiqun Leng <yqleng@linux.alibaba.com>,
Jia Zhu <zhujia.zj@bytedance.com>
Subject: Re: [PATCH 1/5] cachefiles: Fix __cachefiles_prepare_write()
Date: Sun, 7 Jan 2024 16:09:16 +0000 [thread overview]
Message-ID: <20240107160916.GA129355@kernel.org> (raw)
In-Reply-To: <20240103145935.384404-2-dhowells@redhat.com>
On Wed, Jan 03, 2024 at 02:59:25PM +0000, David Howells wrote:
> Fix __cachefiles_prepare_write() to correctly determine whether the
> requested write will fit correctly with the DIO alignment.
>
> Reported-by: Gao Xiang <hsiangkao@linux.alibaba.com>
> Signed-off-by: David Howells <dhowells@redhat.com>
> Tested-by: Yiqun Leng <yqleng@linux.alibaba.com>
> Tested-by: Jia Zhu <zhujia.zj@bytedance.com>
> cc: Jeff Layton <jlayton@kernel.org>
> cc: linux-cachefs@redhat.com
> cc: linux-erofs@lists.ozlabs.org
> cc: linux-fsdevel@vger.kernel.org
> cc: linux-mm@kvack.org
> ---
> fs/cachefiles/io.c | 28 +++++++++++++++++-----------
> 1 file changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c
> index bffffedce4a9..7529b40bc95a 100644
> --- a/fs/cachefiles/io.c
> +++ b/fs/cachefiles/io.c
> @@ -522,16 +522,22 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
> bool no_space_allocated_yet)
> {
> struct cachefiles_cache *cache = object->volume->cache;
> - loff_t start = *_start, pos;
> - size_t len = *_len, down;
> + unsigned long long start = *_start, pos;
> + size_t len = *_len;
> int ret;
>
> /* Round to DIO size */
> - down = start - round_down(start, PAGE_SIZE);
> - *_start = start - down;
> - *_len = round_up(down + len, PAGE_SIZE);
> - if (down < start || *_len > upper_len)
> + start = round_down(*_start, PAGE_SIZE);
> + if (start != *_start) {
> + kleave(" = -ENOBUFS [down]");
> + return -ENOBUFS;
> + }
> + if (*_len > upper_len) {
> + kleave(" = -ENOBUFS [up]");
> return -ENOBUFS;
> + }
> +
> + *_len = round_up(len, PAGE_SIZE);
>
> /* We need to work out whether there's sufficient disk space to perform
> * the write - but we can skip that check if we have space already
> @@ -542,7 +548,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
>
> pos = cachefiles_inject_read_error();
> if (pos == 0)
> - pos = vfs_llseek(file, *_start, SEEK_DATA);
> + pos = vfs_llseek(file, start, SEEK_DATA);
> if (pos < 0 && pos >= (loff_t)-MAX_ERRNO) {
Hi David,
I realise these patches have been accepted, but I have a minor nit:
pos is now unsigned, and so cannot be less than zero.
Flagged by Smatch and Coccinelle.
> if (pos == -ENXIO)
> goto check_space; /* Unallocated tail */
> @@ -550,7 +556,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
> cachefiles_trace_seek_error);
> return pos;
> }
> - if ((u64)pos >= (u64)*_start + *_len)
> + if (pos >= start + *_len)
> goto check_space; /* Unallocated region */
>
> /* We have a block that's at least partially filled - if we're low on
> @@ -563,13 +569,13 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
>
> pos = cachefiles_inject_read_error();
> if (pos == 0)
> - pos = vfs_llseek(file, *_start, SEEK_HOLE);
> + pos = vfs_llseek(file, start, SEEK_HOLE);
> if (pos < 0 && pos >= (loff_t)-MAX_ERRNO) {
Ditto.
> trace_cachefiles_io_error(object, file_inode(file), pos,
> cachefiles_trace_seek_error);
> return pos;
> }
> - if ((u64)pos >= (u64)*_start + *_len)
> + if (pos >= start + *_len)
> return 0; /* Fully allocated */
>
> /* Partially allocated, but insufficient space: cull. */
> @@ -577,7 +583,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
> ret = cachefiles_inject_remove_error();
> if (ret == 0)
> ret = vfs_fallocate(file, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
> - *_start, *_len);
> + start, *_len);
> if (ret < 0) {
> trace_cachefiles_io_error(object, file_inode(file), ret,
> cachefiles_trace_fallocate_error);
>
next prev parent reply other threads:[~2024-01-07 16:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-03 14:59 [PATCH 0/5] netfs, cachefiles, 9p: Additional patches David Howells
2024-01-03 14:59 ` [PATCH 1/5] cachefiles: Fix __cachefiles_prepare_write() David Howells
2024-01-07 16:09 ` Simon Horman [this message]
2024-01-08 22:31 ` David Howells
2024-01-09 8:32 ` Simon Horman
2024-01-03 14:59 ` [PATCH 2/5] 9p: Fix initialisation of netfs_inode for 9p David Howells
2024-01-03 14:59 ` [PATCH 3/5] 9p: Do a couple of cleanups David Howells
2024-01-03 19:45 ` Dominique Martinet
2024-01-03 14:59 ` [PATCH 4/5] 9p: Always update remote_i_size in stat2inode David Howells
2024-01-03 19:42 ` Dominique Martinet
2024-01-03 14:59 ` [PATCH 5/5] 9p: Use length of data written to the server in preference to error David Howells
2024-01-03 19:46 ` Dominique Martinet
2024-01-03 15:47 ` [PATCH 6/5] netfs: Rearrange netfs_io_subrequest to put request pointer first David Howells
2024-01-03 21:15 ` [PATCH 7/5] netfs: Fix proc/fs/fscache symlink to point to "netfs" not "../netfs" David Howells
2024-01-05 10:33 ` [PATCH 0/5] netfs, cachefiles, 9p: Additional patches Christian Brauner
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=20240107160916.GA129355@kernel.org \
--to=horms@kernel.org \
--cc=asmadeus@codewreck.org \
--cc=ceph-devel@vger.kernel.org \
--cc=christian@brauner.io \
--cc=dhowells@redhat.com \
--cc=ericvh@kernel.org \
--cc=hsiangkao@linux.alibaba.com \
--cc=idryomov@gmail.com \
--cc=jlayton@kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-cachefs@redhat.com \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=marc.dionne@auristor.com \
--cc=netdev@vger.kernel.org \
--cc=pc@manguebit.com \
--cc=smfrench@gmail.com \
--cc=sprasad@microsoft.com \
--cc=tom@talpey.com \
--cc=v9fs@lists.linux.dev \
--cc=willy@infradead.org \
--cc=yqleng@linux.alibaba.com \
--cc=zhujia.zj@bytedance.com \
/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