Skip to content

Commit 63c69ad

Browse files
joannekoongMiklos Szeredi
authored andcommitted
fuse: refactor fuse_fill_write_pages()
Refactor the logic in fuse_fill_write_pages() for copying out write data. This will make the future change for supporting large folios for writes easier. No functional changes. Signed-off-by: Joanne Koong <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Reviewed-by: Bernd Schubert <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 3568a95 commit 63c69ad

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

fs/fuse/file.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,21 +1132,21 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
11321132
struct fuse_args_pages *ap = &ia->ap;
11331133
struct fuse_conn *fc = get_fuse_conn(mapping->host);
11341134
unsigned offset = pos & (PAGE_SIZE - 1);
1135-
unsigned int nr_pages = 0;
11361135
size_t count = 0;
1137-
int err;
1136+
unsigned int num;
1137+
int err = 0;
1138+
1139+
num = min(iov_iter_count(ii), fc->max_write);
1140+
num = min(num, max_pages << PAGE_SHIFT);
11381141

11391142
ap->args.in_pages = true;
11401143
ap->descs[0].offset = offset;
11411144

1142-
do {
1145+
while (num) {
11431146
size_t tmp;
11441147
struct folio *folio;
11451148
pgoff_t index = pos >> PAGE_SHIFT;
1146-
size_t bytes = min_t(size_t, PAGE_SIZE - offset,
1147-
iov_iter_count(ii));
1148-
1149-
bytes = min_t(size_t, bytes, fc->max_write - count);
1149+
unsigned bytes = min(PAGE_SIZE - offset, num);
11501150

11511151
again:
11521152
folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
@@ -1178,14 +1178,13 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
11781178
goto again;
11791179
}
11801180

1181-
err = 0;
11821181
ap->folios[ap->num_folios] = folio;
11831182
ap->descs[ap->num_folios].length = tmp;
11841183
ap->num_folios++;
1185-
nr_pages++;
11861184

11871185
count += tmp;
11881186
pos += tmp;
1187+
num -= tmp;
11891188
offset += tmp;
11901189
if (offset == PAGE_SIZE)
11911190
offset = 0;
@@ -1200,10 +1199,9 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
12001199
ia->write.folio_locked = true;
12011200
break;
12021201
}
1203-
if (!fc->big_writes)
1202+
if (!fc->big_writes || offset != 0)
12041203
break;
1205-
} while (iov_iter_count(ii) && count < fc->max_write &&
1206-
nr_pages < max_pages && offset == 0);
1204+
}
12071205

12081206
return count > 0 ? count : err;
12091207
}

0 commit comments

Comments
 (0)