Skip to content

Commit d271c4b

Browse files
committed
Merge tag 'netfs-lib-20240104' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
Pull netfs updates from David Howells: A few follow-up fixes for the netfs work for this cycle. * tag 'netfs-lib-20240104' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs: netfs: Fix proc/fs/fscache symlink to point to "netfs" not "../netfs" netfs: Rearrange netfs_io_subrequest to put request pointer first 9p: Use length of data written to the server in preference to error 9p: Do a couple of cleanups 9p: Fix initialisation of netfs_inode for 9p cachefiles: Fix __cachefiles_prepare_write() Signed-off-by: Christian Brauner <brauner@kernel.org>
2 parents 86fb594 + 43833f2 commit d271c4b

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

fs/9p/v9fs_vfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct inode *v9fs_alloc_inode(struct super_block *sb);
4242
void v9fs_free_inode(struct inode *inode);
4343
struct inode *v9fs_get_inode(struct super_block *sb, umode_t mode,
4444
dev_t rdev);
45+
void v9fs_set_netfs_context(struct inode *inode);
4546
int v9fs_init_inode(struct v9fs_session_info *v9ses,
4647
struct inode *inode, umode_t mode, dev_t rdev);
4748
void v9fs_evict_inode(struct inode *inode);

fs/9p/vfs_addr.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@
2828

2929
static void v9fs_upload_to_server(struct netfs_io_subrequest *subreq)
3030
{
31-
struct inode *inode = subreq->rreq->inode;
32-
struct v9fs_inode __maybe_unused *v9inode = V9FS_I(inode);
3331
struct p9_fid *fid = subreq->rreq->netfs_priv;
34-
int err;
32+
int err, len;
3533

3634
trace_netfs_sreq(subreq, netfs_sreq_trace_submit);
37-
p9_client_write(fid, subreq->start, &subreq->io_iter, &err);
38-
netfs_write_subrequest_terminated(subreq, err < 0 ? err : subreq->len,
39-
false);
35+
len = p9_client_write(fid, subreq->start, &subreq->io_iter, &err);
36+
netfs_write_subrequest_terminated(subreq, len ?: err, false);
4037
}
4138

4239
static void v9fs_upload_to_server_worker(struct work_struct *work)
@@ -98,15 +95,13 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file)
9895

9996
if (file) {
10097
fid = file->private_data;
101-
BUG_ON(!fid);
98+
if (!fid)
99+
goto no_fid;
102100
p9_fid_get(fid);
103101
} else {
104102
fid = v9fs_fid_find_inode(rreq->inode, writing, INVALID_UID, true);
105-
if (!fid) {
106-
WARN_ONCE(1, "folio expected an open fid inode->i_private=%p\n",
107-
rreq->inode->i_private);
108-
return -EINVAL;
109-
}
103+
if (!fid)
104+
goto no_fid;
110105
}
111106

112107
/* we might need to read from a fid that was opened write-only
@@ -115,6 +110,11 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file)
115110
WARN_ON(rreq->origin == NETFS_READ_FOR_WRITE && !(fid->mode & P9_ORDWR));
116111
rreq->netfs_priv = fid;
117112
return 0;
113+
114+
no_fid:
115+
WARN_ONCE(1, "folio expected an open fid inode->i_ino=%lx\n",
116+
rreq->inode->i_ino);
117+
return -EINVAL;
118118
}
119119

120120
/**

fs/9p/vfs_inode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void v9fs_free_inode(struct inode *inode)
246246
/*
247247
* Set parameters for the netfs library
248248
*/
249-
static void v9fs_set_netfs_context(struct inode *inode)
249+
void v9fs_set_netfs_context(struct inode *inode)
250250
{
251251
struct v9fs_inode *v9inode = V9FS_I(inode);
252252
netfs_inode_init(&v9inode->netfs, &v9fs_req_ops, true);
@@ -326,8 +326,6 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses,
326326
err = -EINVAL;
327327
goto error;
328328
}
329-
330-
v9fs_set_netfs_context(inode);
331329
error:
332330
return err;
333331

@@ -359,6 +357,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, umode_t mode, dev_t rdev)
359357
iput(inode);
360358
return ERR_PTR(err);
361359
}
360+
v9fs_set_netfs_context(inode);
362361
return inode;
363362
}
364363

@@ -461,6 +460,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
461460
goto error;
462461

463462
v9fs_stat2inode(st, inode, sb, 0);
463+
v9fs_set_netfs_context(inode);
464464
v9fs_cache_inode_get_cookie(inode);
465465
unlock_new_inode(inode);
466466
return inode;

fs/9p/vfs_inode_dotl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
128128
goto error;
129129

130130
v9fs_stat2inode_dotl(st, inode, 0);
131+
v9fs_set_netfs_context(inode);
131132
v9fs_cache_inode_get_cookie(inode);
132133
retval = v9fs_get_acl(inode, fid);
133134
if (retval)

fs/cachefiles/io.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -522,16 +522,22 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
522522
bool no_space_allocated_yet)
523523
{
524524
struct cachefiles_cache *cache = object->volume->cache;
525-
loff_t start = *_start, pos;
526-
size_t len = *_len, down;
525+
unsigned long long start = *_start, pos;
526+
size_t len = *_len;
527527
int ret;
528528

529529
/* Round to DIO size */
530-
down = start - round_down(start, PAGE_SIZE);
531-
*_start = start - down;
532-
*_len = round_up(down + len, PAGE_SIZE);
533-
if (down < start || *_len > upper_len)
530+
start = round_down(*_start, PAGE_SIZE);
531+
if (start != *_start) {
532+
kleave(" = -ENOBUFS [down]");
533+
return -ENOBUFS;
534+
}
535+
if (*_len > upper_len) {
536+
kleave(" = -ENOBUFS [up]");
534537
return -ENOBUFS;
538+
}
539+
540+
*_len = round_up(len, PAGE_SIZE);
535541

536542
/* We need to work out whether there's sufficient disk space to perform
537543
* the write - but we can skip that check if we have space already
@@ -542,15 +548,15 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
542548

543549
pos = cachefiles_inject_read_error();
544550
if (pos == 0)
545-
pos = vfs_llseek(file, *_start, SEEK_DATA);
551+
pos = vfs_llseek(file, start, SEEK_DATA);
546552
if (pos < 0 && pos >= (loff_t)-MAX_ERRNO) {
547553
if (pos == -ENXIO)
548554
goto check_space; /* Unallocated tail */
549555
trace_cachefiles_io_error(object, file_inode(file), pos,
550556
cachefiles_trace_seek_error);
551557
return pos;
552558
}
553-
if ((u64)pos >= (u64)*_start + *_len)
559+
if (pos >= start + *_len)
554560
goto check_space; /* Unallocated region */
555561

556562
/* We have a block that's at least partially filled - if we're low on
@@ -563,21 +569,21 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
563569

564570
pos = cachefiles_inject_read_error();
565571
if (pos == 0)
566-
pos = vfs_llseek(file, *_start, SEEK_HOLE);
572+
pos = vfs_llseek(file, start, SEEK_HOLE);
567573
if (pos < 0 && pos >= (loff_t)-MAX_ERRNO) {
568574
trace_cachefiles_io_error(object, file_inode(file), pos,
569575
cachefiles_trace_seek_error);
570576
return pos;
571577
}
572-
if ((u64)pos >= (u64)*_start + *_len)
578+
if (pos >= start + *_len)
573579
return 0; /* Fully allocated */
574580

575581
/* Partially allocated, but insufficient space: cull. */
576582
fscache_count_no_write_space();
577583
ret = cachefiles_inject_remove_error();
578584
if (ret == 0)
579585
ret = vfs_fallocate(file, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
580-
*_start, *_len);
586+
start, *_len);
581587
if (ret < 0) {
582588
trace_cachefiles_io_error(object, file_inode(file), ret,
583589
cachefiles_trace_fallocate_error);

fs/netfs/fscache_proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
int __init fscache_proc_init(void)
1818
{
19-
if (!proc_symlink("fs/fscache", NULL, "../netfs"))
19+
if (!proc_symlink("fs/fscache", NULL, "netfs"))
2020
goto error_sym;
2121

2222
if (!proc_create_seq("fs/netfs/caches", S_IFREG | 0444, NULL,

include/linux/netfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ struct netfs_cache_resources {
204204
* the pages it points to can be relied on to exist for the duration.
205205
*/
206206
struct netfs_io_subrequest {
207-
struct work_struct work;
208207
struct netfs_io_request *rreq; /* Supervising I/O request */
208+
struct work_struct work;
209209
struct list_head rreq_link; /* Link in rreq->subrequests */
210210
struct iov_iter io_iter; /* Iterator for this subrequest */
211211
loff_t start; /* Where to start the I/O */

0 commit comments

Comments
 (0)