Skip to content

Commit 2154347

Browse files
committed
Merge patch series "Orangefs fixes for 6.15"
Matthew Wilcox (Oracle) <[email protected]> says: The start of this was the removal of orangefs_writepage(), but it quickly spiralled into a more comprehensive cleanup. The first patch is an actual bug fix. I haven't tagged it for backport, as I don't think we really care about 32-bit systems any more, but feel free to add a cc to stable if you disagree. Patches 2 and 3 are compilation fixes for warnings which aren't enabled by default. Patches 4-9 are improvements which simplify orangefs or convert it from pages to folios. There is still a little use of 'struct page' in orangefs, but it's not in the areas that deal with the page cache. * patches from https://lore.kernel.org/r/[email protected]: orangefs: Convert orangefs_writepages to contain an array of folios orangefs: Simplify bvec setup in orangefs_writepages_work() orangefs: Unify error & success paths in orangefs_writepages_work() orangefs: Pass mapping to orangefs_writepages_work() orangefs: Convert orangefs_writepage_locked() to take a folio orangefs: Remove orangefs_writepage() orangefs: make open_for_read and open_for_write boolean orangefs: Move s_kmod_keyword_mask_map to orangefs-debugfs.c orangefs: Do not truncate file size Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
2 parents 2014c95 + 73f233b commit 2154347

File tree

4 files changed

+109
-130
lines changed

4 files changed

+109
-130
lines changed

fs/orangefs/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ ssize_t wait_for_direct_io(enum ORANGEFS_io_type type, struct inode *inode,
5757
int buffer_index;
5858
ssize_t ret;
5959
size_t copy_amount;
60-
int open_for_read;
61-
int open_for_write;
60+
bool open_for_read;
61+
bool open_for_write;
6262

6363
new_op = op_alloc(ORANGEFS_VFS_OP_FILE_IO);
6464
if (!new_op)

fs/orangefs/inode.c

Lines changed: 64 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616
#include "orangefs-kernel.h"
1717
#include "orangefs-bufmap.h"
1818

19-
static int orangefs_writepage_locked(struct page *page,
20-
struct writeback_control *wbc)
19+
static int orangefs_writepage_locked(struct folio *folio,
20+
struct writeback_control *wbc)
2121
{
22-
struct inode *inode = page->mapping->host;
22+
struct inode *inode = folio->mapping->host;
2323
struct orangefs_write_range *wr = NULL;
2424
struct iov_iter iter;
2525
struct bio_vec bv;
26-
size_t len, wlen;
26+
size_t wlen;
2727
ssize_t ret;
28-
loff_t off;
28+
loff_t len, off;
2929

30-
set_page_writeback(page);
30+
folio_start_writeback(folio);
3131

3232
len = i_size_read(inode);
33-
if (PagePrivate(page)) {
34-
wr = (struct orangefs_write_range *)page_private(page);
33+
if (folio->private) {
34+
wr = folio->private;
3535
WARN_ON(wr->pos >= len);
3636
off = wr->pos;
3737
if (off + wr->len > len)
@@ -40,36 +40,27 @@ static int orangefs_writepage_locked(struct page *page,
4040
wlen = wr->len;
4141
} else {
4242
WARN_ON(1);
43-
off = page_offset(page);
44-
if (off + PAGE_SIZE > len)
43+
off = folio_pos(folio);
44+
wlen = folio_size(folio);
45+
46+
if (wlen > len - off)
4547
wlen = len - off;
46-
else
47-
wlen = PAGE_SIZE;
4848
}
4949
/* Should've been handled in orangefs_invalidate_folio. */
5050
WARN_ON(off == len || off + wlen > len);
5151

5252
WARN_ON(wlen == 0);
53-
bvec_set_page(&bv, page, wlen, off % PAGE_SIZE);
53+
bvec_set_folio(&bv, folio, wlen, offset_in_folio(folio, off));
5454
iov_iter_bvec(&iter, ITER_SOURCE, &bv, 1, wlen);
5555

5656
ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, wlen,
5757
len, wr, NULL, NULL);
5858
if (ret < 0) {
59-
mapping_set_error(page->mapping, ret);
59+
mapping_set_error(folio->mapping, ret);
6060
} else {
6161
ret = 0;
6262
}
63-
kfree(detach_page_private(page));
64-
return ret;
65-
}
66-
67-
static int orangefs_writepage(struct page *page, struct writeback_control *wbc)
68-
{
69-
int ret;
70-
ret = orangefs_writepage_locked(page, wbc);
71-
unlock_page(page);
72-
end_page_writeback(page);
63+
kfree(folio_detach_private(folio));
7364
return ret;
7465
}
7566

@@ -79,33 +70,33 @@ struct orangefs_writepages {
7970
kuid_t uid;
8071
kgid_t gid;
8172
int maxpages;
82-
int npages;
83-
struct page **pages;
73+
int nfolios;
74+
struct address_space *mapping;
75+
struct folio **folios;
8476
struct bio_vec *bv;
8577
};
8678

8779
static int orangefs_writepages_work(struct orangefs_writepages *ow,
88-
struct writeback_control *wbc)
80+
struct writeback_control *wbc)
8981
{
90-
struct inode *inode = ow->pages[0]->mapping->host;
82+
struct inode *inode = ow->mapping->host;
9183
struct orangefs_write_range *wrp, wr;
9284
struct iov_iter iter;
9385
ssize_t ret;
94-
size_t len;
95-
loff_t off;
86+
size_t start;
87+
loff_t len, off;
9688
int i;
9789

9890
len = i_size_read(inode);
9991

100-
for (i = 0; i < ow->npages; i++) {
101-
set_page_writeback(ow->pages[i]);
102-
bvec_set_page(&ow->bv[i], ow->pages[i],
103-
min(page_offset(ow->pages[i]) + PAGE_SIZE,
104-
ow->off + ow->len) -
105-
max(ow->off, page_offset(ow->pages[i])),
106-
i == 0 ? ow->off - page_offset(ow->pages[i]) : 0);
92+
start = offset_in_folio(ow->folios[0], ow->off);
93+
for (i = 0; i < ow->nfolios; i++) {
94+
folio_start_writeback(ow->folios[i]);
95+
bvec_set_folio(&ow->bv[i], ow->folios[i],
96+
folio_size(ow->folios[i]) - start, start);
97+
start = 0;
10798
}
108-
iov_iter_bvec(&iter, ITER_SOURCE, ow->bv, ow->npages, ow->len);
99+
iov_iter_bvec(&iter, ITER_SOURCE, ow->bv, ow->nfolios, ow->len);
109100

110101
WARN_ON(ow->off >= len);
111102
if (ow->off + ow->len > len)
@@ -116,40 +107,24 @@ static int orangefs_writepages_work(struct orangefs_writepages *ow,
116107
wr.gid = ow->gid;
117108
ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, ow->len,
118109
0, &wr, NULL, NULL);
119-
if (ret < 0) {
120-
for (i = 0; i < ow->npages; i++) {
121-
mapping_set_error(ow->pages[i]->mapping, ret);
122-
if (PagePrivate(ow->pages[i])) {
123-
wrp = (struct orangefs_write_range *)
124-
page_private(ow->pages[i]);
125-
ClearPagePrivate(ow->pages[i]);
126-
put_page(ow->pages[i]);
127-
kfree(wrp);
128-
}
129-
end_page_writeback(ow->pages[i]);
130-
unlock_page(ow->pages[i]);
131-
}
132-
} else {
110+
if (ret < 0)
111+
mapping_set_error(ow->mapping, ret);
112+
else
133113
ret = 0;
134-
for (i = 0; i < ow->npages; i++) {
135-
if (PagePrivate(ow->pages[i])) {
136-
wrp = (struct orangefs_write_range *)
137-
page_private(ow->pages[i]);
138-
ClearPagePrivate(ow->pages[i]);
139-
put_page(ow->pages[i]);
140-
kfree(wrp);
141-
}
142-
end_page_writeback(ow->pages[i]);
143-
unlock_page(ow->pages[i]);
144-
}
114+
115+
for (i = 0; i < ow->nfolios; i++) {
116+
wrp = folio_detach_private(ow->folios[i]);
117+
kfree(wrp);
118+
folio_end_writeback(ow->folios[i]);
119+
folio_unlock(ow->folios[i]);
145120
}
121+
146122
return ret;
147123
}
148124

149125
static int orangefs_writepages_callback(struct folio *folio,
150-
struct writeback_control *wbc, void *data)
126+
struct writeback_control *wbc, struct orangefs_writepages *ow)
151127
{
152-
struct orangefs_writepages *ow = data;
153128
struct orangefs_write_range *wr = folio->private;
154129
int ret;
155130

@@ -162,41 +137,41 @@ static int orangefs_writepages_callback(struct folio *folio,
162137
}
163138

164139
ret = -1;
165-
if (ow->npages == 0) {
140+
if (ow->nfolios == 0) {
166141
ow->off = wr->pos;
167142
ow->len = wr->len;
168143
ow->uid = wr->uid;
169144
ow->gid = wr->gid;
170-
ow->pages[ow->npages++] = &folio->page;
145+
ow->folios[ow->nfolios++] = folio;
171146
ret = 0;
172147
goto done;
173148
}
174149
if (!uid_eq(ow->uid, wr->uid) || !gid_eq(ow->gid, wr->gid)) {
175150
orangefs_writepages_work(ow, wbc);
176-
ow->npages = 0;
151+
ow->nfolios = 0;
177152
ret = -1;
178153
goto done;
179154
}
180155
if (ow->off + ow->len == wr->pos) {
181156
ow->len += wr->len;
182-
ow->pages[ow->npages++] = &folio->page;
157+
ow->folios[ow->nfolios++] = folio;
183158
ret = 0;
184159
goto done;
185160
}
186161
done:
187162
if (ret == -1) {
188-
if (ow->npages) {
163+
if (ow->nfolios) {
189164
orangefs_writepages_work(ow, wbc);
190-
ow->npages = 0;
165+
ow->nfolios = 0;
191166
}
192-
ret = orangefs_writepage_locked(&folio->page, wbc);
167+
ret = orangefs_writepage_locked(folio, wbc);
193168
mapping_set_error(folio->mapping, ret);
194169
folio_unlock(folio);
195170
folio_end_writeback(folio);
196171
} else {
197-
if (ow->npages == ow->maxpages) {
172+
if (ow->nfolios == ow->maxpages) {
198173
orangefs_writepages_work(ow, wbc);
199-
ow->npages = 0;
174+
ow->nfolios = 0;
200175
}
201176
}
202177
return ret;
@@ -207,31 +182,35 @@ static int orangefs_writepages(struct address_space *mapping,
207182
{
208183
struct orangefs_writepages *ow;
209184
struct blk_plug plug;
210-
int ret;
185+
int error;
186+
struct folio *folio = NULL;
187+
211188
ow = kzalloc(sizeof(struct orangefs_writepages), GFP_KERNEL);
212189
if (!ow)
213190
return -ENOMEM;
214191
ow->maxpages = orangefs_bufmap_size_query()/PAGE_SIZE;
215-
ow->pages = kcalloc(ow->maxpages, sizeof(struct page *), GFP_KERNEL);
216-
if (!ow->pages) {
192+
ow->folios = kcalloc(ow->maxpages, sizeof(struct folio *), GFP_KERNEL);
193+
if (!ow->folios) {
217194
kfree(ow);
218195
return -ENOMEM;
219196
}
220197
ow->bv = kcalloc(ow->maxpages, sizeof(struct bio_vec), GFP_KERNEL);
221198
if (!ow->bv) {
222-
kfree(ow->pages);
199+
kfree(ow->folios);
223200
kfree(ow);
224201
return -ENOMEM;
225202
}
203+
ow->mapping = mapping;
226204
blk_start_plug(&plug);
227-
ret = write_cache_pages(mapping, wbc, orangefs_writepages_callback, ow);
228-
if (ow->npages)
229-
ret = orangefs_writepages_work(ow, wbc);
205+
while ((folio = writeback_iter(mapping, wbc, folio, &error)))
206+
error = orangefs_writepages_callback(folio, wbc, ow);
207+
if (ow->nfolios)
208+
error = orangefs_writepages_work(ow, wbc);
230209
blk_finish_plug(&plug);
231-
kfree(ow->pages);
210+
kfree(ow->folios);
232211
kfree(ow->bv);
233212
kfree(ow);
234-
return ret;
213+
return error;
235214
}
236215

237216
static int orangefs_launder_folio(struct folio *);
@@ -484,7 +463,7 @@ static int orangefs_launder_folio(struct folio *folio)
484463
};
485464
folio_wait_writeback(folio);
486465
if (folio_clear_dirty_for_io(folio)) {
487-
r = orangefs_writepage_locked(&folio->page, &wbc);
466+
r = orangefs_writepage_locked(folio, &wbc);
488467
folio_end_writeback(folio);
489468
}
490469
return r;
@@ -606,7 +585,6 @@ static ssize_t orangefs_direct_IO(struct kiocb *iocb,
606585

607586
/** ORANGEFS2 implementation of address space operations */
608587
static const struct address_space_operations orangefs_address_operations = {
609-
.writepage = orangefs_writepage,
610588
.readahead = orangefs_readahead,
611589
.read_folio = orangefs_read_folio,
612590
.writepages = orangefs_writepages,
@@ -616,6 +594,7 @@ static const struct address_space_operations orangefs_address_operations = {
616594
.invalidate_folio = orangefs_invalidate_folio,
617595
.release_folio = orangefs_release_folio,
618596
.free_folio = orangefs_free_folio,
597+
.migrate_folio = filemap_migrate_folio,
619598
.launder_folio = orangefs_launder_folio,
620599
.direct_IO = orangefs_direct_IO,
621600
};

fs/orangefs/orangefs-debug.h

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,47 +43,4 @@
4343
#define GOSSIP_MAX_NR 16
4444
#define GOSSIP_MAX_DEBUG (((__u64)1 << GOSSIP_MAX_NR) - 1)
4545

46-
/* a private internal type */
47-
struct __keyword_mask_s {
48-
const char *keyword;
49-
__u64 mask_val;
50-
};
51-
52-
/*
53-
* Map all kmod keywords to kmod debug masks here. Keep this
54-
* structure "packed":
55-
*
56-
* "all" is always last...
57-
*
58-
* keyword mask_val index
59-
* foo 1 0
60-
* bar 2 1
61-
* baz 4 2
62-
* qux 8 3
63-
* . . .
64-
*/
65-
static struct __keyword_mask_s s_kmod_keyword_mask_map[] = {
66-
{"super", GOSSIP_SUPER_DEBUG},
67-
{"inode", GOSSIP_INODE_DEBUG},
68-
{"file", GOSSIP_FILE_DEBUG},
69-
{"dir", GOSSIP_DIR_DEBUG},
70-
{"utils", GOSSIP_UTILS_DEBUG},
71-
{"wait", GOSSIP_WAIT_DEBUG},
72-
{"acl", GOSSIP_ACL_DEBUG},
73-
{"dcache", GOSSIP_DCACHE_DEBUG},
74-
{"dev", GOSSIP_DEV_DEBUG},
75-
{"name", GOSSIP_NAME_DEBUG},
76-
{"bufmap", GOSSIP_BUFMAP_DEBUG},
77-
{"cache", GOSSIP_CACHE_DEBUG},
78-
{"debugfs", GOSSIP_DEBUGFS_DEBUG},
79-
{"xattr", GOSSIP_XATTR_DEBUG},
80-
{"init", GOSSIP_INIT_DEBUG},
81-
{"sysfs", GOSSIP_SYSFS_DEBUG},
82-
{"none", GOSSIP_NO_DEBUG},
83-
{"all", GOSSIP_MAX_DEBUG}
84-
};
85-
86-
static const int num_kmod_keyword_mask_map = (int)
87-
(ARRAY_SIZE(s_kmod_keyword_mask_map));
88-
8946
#endif /* __ORANGEFS_DEBUG_H */

0 commit comments

Comments
 (0)