16
16
#include "orangefs-kernel.h"
17
17
#include "orangefs-bufmap.h"
18
18
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 )
21
21
{
22
- struct inode * inode = page -> mapping -> host ;
22
+ struct inode * inode = folio -> mapping -> host ;
23
23
struct orangefs_write_range * wr = NULL ;
24
24
struct iov_iter iter ;
25
25
struct bio_vec bv ;
26
- size_t len , wlen ;
26
+ size_t wlen ;
27
27
ssize_t ret ;
28
- loff_t off ;
28
+ loff_t len , off ;
29
29
30
- set_page_writeback ( page );
30
+ folio_start_writeback ( folio );
31
31
32
32
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 ;
35
35
WARN_ON (wr -> pos >= len );
36
36
off = wr -> pos ;
37
37
if (off + wr -> len > len )
@@ -40,36 +40,27 @@ static int orangefs_writepage_locked(struct page *page,
40
40
wlen = wr -> len ;
41
41
} else {
42
42
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 )
45
47
wlen = len - off ;
46
- else
47
- wlen = PAGE_SIZE ;
48
48
}
49
49
/* Should've been handled in orangefs_invalidate_folio. */
50
50
WARN_ON (off == len || off + wlen > len );
51
51
52
52
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 ) );
54
54
iov_iter_bvec (& iter , ITER_SOURCE , & bv , 1 , wlen );
55
55
56
56
ret = wait_for_direct_io (ORANGEFS_IO_WRITE , inode , & off , & iter , wlen ,
57
57
len , wr , NULL , NULL );
58
58
if (ret < 0 ) {
59
- mapping_set_error (page -> mapping , ret );
59
+ mapping_set_error (folio -> mapping , ret );
60
60
} else {
61
61
ret = 0 ;
62
62
}
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 ));
73
64
return ret ;
74
65
}
75
66
@@ -79,33 +70,33 @@ struct orangefs_writepages {
79
70
kuid_t uid ;
80
71
kgid_t gid ;
81
72
int maxpages ;
82
- int npages ;
83
- struct page * * pages ;
73
+ int nfolios ;
74
+ struct address_space * mapping ;
75
+ struct folio * * folios ;
84
76
struct bio_vec * bv ;
85
77
};
86
78
87
79
static int orangefs_writepages_work (struct orangefs_writepages * ow ,
88
- struct writeback_control * wbc )
80
+ struct writeback_control * wbc )
89
81
{
90
- struct inode * inode = ow -> pages [ 0 ] -> mapping -> host ;
82
+ struct inode * inode = ow -> mapping -> host ;
91
83
struct orangefs_write_range * wrp , wr ;
92
84
struct iov_iter iter ;
93
85
ssize_t ret ;
94
- size_t len ;
95
- loff_t off ;
86
+ size_t start ;
87
+ loff_t len , off ;
96
88
int i ;
97
89
98
90
len = i_size_read (inode );
99
91
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 ;
107
98
}
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 );
109
100
110
101
WARN_ON (ow -> off >= len );
111
102
if (ow -> off + ow -> len > len )
@@ -116,40 +107,24 @@ static int orangefs_writepages_work(struct orangefs_writepages *ow,
116
107
wr .gid = ow -> gid ;
117
108
ret = wait_for_direct_io (ORANGEFS_IO_WRITE , inode , & off , & iter , ow -> len ,
118
109
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
133
113
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 ]);
145
120
}
121
+
146
122
return ret ;
147
123
}
148
124
149
125
static int orangefs_writepages_callback (struct folio * folio ,
150
- struct writeback_control * wbc , void * data )
126
+ struct writeback_control * wbc , struct orangefs_writepages * ow )
151
127
{
152
- struct orangefs_writepages * ow = data ;
153
128
struct orangefs_write_range * wr = folio -> private ;
154
129
int ret ;
155
130
@@ -162,41 +137,41 @@ static int orangefs_writepages_callback(struct folio *folio,
162
137
}
163
138
164
139
ret = -1 ;
165
- if (ow -> npages == 0 ) {
140
+ if (ow -> nfolios == 0 ) {
166
141
ow -> off = wr -> pos ;
167
142
ow -> len = wr -> len ;
168
143
ow -> uid = wr -> uid ;
169
144
ow -> gid = wr -> gid ;
170
- ow -> pages [ow -> npages ++ ] = & folio -> page ;
145
+ ow -> folios [ow -> nfolios ++ ] = folio ;
171
146
ret = 0 ;
172
147
goto done ;
173
148
}
174
149
if (!uid_eq (ow -> uid , wr -> uid ) || !gid_eq (ow -> gid , wr -> gid )) {
175
150
orangefs_writepages_work (ow , wbc );
176
- ow -> npages = 0 ;
151
+ ow -> nfolios = 0 ;
177
152
ret = -1 ;
178
153
goto done ;
179
154
}
180
155
if (ow -> off + ow -> len == wr -> pos ) {
181
156
ow -> len += wr -> len ;
182
- ow -> pages [ow -> npages ++ ] = & folio -> page ;
157
+ ow -> folios [ow -> nfolios ++ ] = folio ;
183
158
ret = 0 ;
184
159
goto done ;
185
160
}
186
161
done :
187
162
if (ret == -1 ) {
188
- if (ow -> npages ) {
163
+ if (ow -> nfolios ) {
189
164
orangefs_writepages_work (ow , wbc );
190
- ow -> npages = 0 ;
165
+ ow -> nfolios = 0 ;
191
166
}
192
- ret = orangefs_writepage_locked (& folio -> page , wbc );
167
+ ret = orangefs_writepage_locked (folio , wbc );
193
168
mapping_set_error (folio -> mapping , ret );
194
169
folio_unlock (folio );
195
170
folio_end_writeback (folio );
196
171
} else {
197
- if (ow -> npages == ow -> maxpages ) {
172
+ if (ow -> nfolios == ow -> maxpages ) {
198
173
orangefs_writepages_work (ow , wbc );
199
- ow -> npages = 0 ;
174
+ ow -> nfolios = 0 ;
200
175
}
201
176
}
202
177
return ret ;
@@ -207,31 +182,35 @@ static int orangefs_writepages(struct address_space *mapping,
207
182
{
208
183
struct orangefs_writepages * ow ;
209
184
struct blk_plug plug ;
210
- int ret ;
185
+ int error ;
186
+ struct folio * folio = NULL ;
187
+
211
188
ow = kzalloc (sizeof (struct orangefs_writepages ), GFP_KERNEL );
212
189
if (!ow )
213
190
return - ENOMEM ;
214
191
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 ) {
217
194
kfree (ow );
218
195
return - ENOMEM ;
219
196
}
220
197
ow -> bv = kcalloc (ow -> maxpages , sizeof (struct bio_vec ), GFP_KERNEL );
221
198
if (!ow -> bv ) {
222
- kfree (ow -> pages );
199
+ kfree (ow -> folios );
223
200
kfree (ow );
224
201
return - ENOMEM ;
225
202
}
203
+ ow -> mapping = mapping ;
226
204
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 );
230
209
blk_finish_plug (& plug );
231
- kfree (ow -> pages );
210
+ kfree (ow -> folios );
232
211
kfree (ow -> bv );
233
212
kfree (ow );
234
- return ret ;
213
+ return error ;
235
214
}
236
215
237
216
static int orangefs_launder_folio (struct folio * );
@@ -484,7 +463,7 @@ static int orangefs_launder_folio(struct folio *folio)
484
463
};
485
464
folio_wait_writeback (folio );
486
465
if (folio_clear_dirty_for_io (folio )) {
487
- r = orangefs_writepage_locked (& folio -> page , & wbc );
466
+ r = orangefs_writepage_locked (folio , & wbc );
488
467
folio_end_writeback (folio );
489
468
}
490
469
return r ;
@@ -606,7 +585,6 @@ static ssize_t orangefs_direct_IO(struct kiocb *iocb,
606
585
607
586
/** ORANGEFS2 implementation of address space operations */
608
587
static const struct address_space_operations orangefs_address_operations = {
609
- .writepage = orangefs_writepage ,
610
588
.readahead = orangefs_readahead ,
611
589
.read_folio = orangefs_read_folio ,
612
590
.writepages = orangefs_writepages ,
@@ -616,6 +594,7 @@ static const struct address_space_operations orangefs_address_operations = {
616
594
.invalidate_folio = orangefs_invalidate_folio ,
617
595
.release_folio = orangefs_release_folio ,
618
596
.free_folio = orangefs_free_folio ,
597
+ .migrate_folio = filemap_migrate_folio ,
619
598
.launder_folio = orangefs_launder_folio ,
620
599
.direct_IO = orangefs_direct_IO ,
621
600
};
0 commit comments