Skip to content

Commit ac1cf6e

Browse files
joannekoongMiklos Szeredi
authored andcommitted
fuse: convert ioctls to use folios
Convert ioctl requests to use folios instead of pages. No functional changes. Signed-off-by: Joanne Koong <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent f2ef459 commit ac1cf6e

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

fs/fuse/fuse_i.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,16 @@ static inline void fuse_page_descs_length_init(struct fuse_page_desc *descs,
10511051
descs[i].length = PAGE_SIZE - descs[i].offset;
10521052
}
10531053

1054+
static inline void fuse_folio_descs_length_init(struct fuse_folio_desc *descs,
1055+
unsigned int index,
1056+
unsigned int nr_folios)
1057+
{
1058+
int i;
1059+
1060+
for (i = index; i < index + nr_folios; i++)
1061+
descs[i].length = PAGE_SIZE - descs[i].offset;
1062+
}
1063+
10541064
static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket *bucket)
10551065
{
10561066
/* Need RCU protection to prevent use after free after the decrement */

fs/fuse/ioctl.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
251251
BUILD_BUG_ON(sizeof(struct fuse_ioctl_iovec) * FUSE_IOCTL_MAX_IOV > PAGE_SIZE);
252252

253253
err = -ENOMEM;
254-
ap.pages = fuse_pages_alloc(fm->fc->max_pages, GFP_KERNEL, &ap.descs);
254+
ap.folios = fuse_folios_alloc(fm->fc->max_pages, GFP_KERNEL, &ap.folio_descs);
255255
iov_page = (struct iovec *) __get_free_page(GFP_KERNEL);
256-
if (!ap.pages || !iov_page)
256+
if (!ap.folios || !iov_page)
257257
goto out;
258258

259-
fuse_page_descs_length_init(ap.descs, 0, fm->fc->max_pages);
259+
fuse_folio_descs_length_init(ap.folio_descs, 0, fm->fc->max_pages);
260260

261261
/*
262262
* If restricted, initialize IO parameters as encoded in @cmd.
@@ -306,14 +306,14 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
306306
err = -ENOMEM;
307307
if (max_pages > fm->fc->max_pages)
308308
goto out;
309-
while (ap.num_pages < max_pages) {
310-
ap.pages[ap.num_pages] = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
311-
if (!ap.pages[ap.num_pages])
309+
ap.uses_folios = true;
310+
while (ap.num_folios < max_pages) {
311+
ap.folios[ap.num_folios] = folio_alloc(GFP_KERNEL | __GFP_HIGHMEM, 0);
312+
if (!ap.folios[ap.num_folios])
312313
goto out;
313-
ap.num_pages++;
314+
ap.num_folios++;
314315
}
315316

316-
317317
/* okay, let's send it to the client */
318318
ap.args.opcode = FUSE_IOCTL;
319319
ap.args.nodeid = ff->nodeid;
@@ -327,8 +327,8 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
327327

328328
err = -EFAULT;
329329
iov_iter_init(&ii, ITER_SOURCE, in_iov, in_iovs, in_size);
330-
for (i = 0; iov_iter_count(&ii) && !WARN_ON(i >= ap.num_pages); i++) {
331-
c = copy_page_from_iter(ap.pages[i], 0, PAGE_SIZE, &ii);
330+
for (i = 0; iov_iter_count(&ii) && !WARN_ON(i >= ap.num_folios); i++) {
331+
c = copy_folio_from_iter(ap.folios[i], 0, PAGE_SIZE, &ii);
332332
if (c != PAGE_SIZE && iov_iter_count(&ii))
333333
goto out;
334334
}
@@ -366,7 +366,7 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
366366
in_iovs + out_iovs > FUSE_IOCTL_MAX_IOV)
367367
goto out;
368368

369-
vaddr = kmap_local_page(ap.pages[0]);
369+
vaddr = kmap_local_folio(ap.folios[0], 0);
370370
err = fuse_copy_ioctl_iovec(fm->fc, iov_page, vaddr,
371371
transferred, in_iovs + out_iovs,
372372
(flags & FUSE_IOCTL_COMPAT) != 0);
@@ -394,17 +394,17 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
394394

395395
err = -EFAULT;
396396
iov_iter_init(&ii, ITER_DEST, out_iov, out_iovs, transferred);
397-
for (i = 0; iov_iter_count(&ii) && !WARN_ON(i >= ap.num_pages); i++) {
398-
c = copy_page_to_iter(ap.pages[i], 0, PAGE_SIZE, &ii);
397+
for (i = 0; iov_iter_count(&ii) && !WARN_ON(i >= ap.num_folios); i++) {
398+
c = copy_folio_to_iter(ap.folios[i], 0, PAGE_SIZE, &ii);
399399
if (c != PAGE_SIZE && iov_iter_count(&ii))
400400
goto out;
401401
}
402402
err = 0;
403403
out:
404404
free_page((unsigned long) iov_page);
405-
while (ap.num_pages)
406-
__free_page(ap.pages[--ap.num_pages]);
407-
kfree(ap.pages);
405+
while (ap.num_folios)
406+
folio_put(ap.folios[--ap.num_folios]);
407+
kfree(ap.folios);
408408

409409
return err ? err : outarg.result;
410410
}

0 commit comments

Comments
 (0)