]>
Commit | Line | Data |
---|---|---|
3d14c5d2 | 1 | #include <linux/ceph/ceph_debug.h> |
1d3576fd SW |
2 | |
3 | #include <linux/backing-dev.h> | |
4 | #include <linux/fs.h> | |
5 | #include <linux/mm.h> | |
6 | #include <linux/pagemap.h> | |
7 | #include <linux/writeback.h> /* generic_writepages */ | |
5a0e3ad6 | 8 | #include <linux/slab.h> |
1d3576fd SW |
9 | #include <linux/pagevec.h> |
10 | #include <linux/task_io_accounting_ops.h> | |
11 | ||
12 | #include "super.h" | |
3d14c5d2 | 13 | #include "mds_client.h" |
99ccbd22 | 14 | #include "cache.h" |
3d14c5d2 | 15 | #include <linux/ceph/osd_client.h> |
1d3576fd SW |
16 | |
17 | /* | |
18 | * Ceph address space ops. | |
19 | * | |
20 | * There are a few funny things going on here. | |
21 | * | |
22 | * The page->private field is used to reference a struct | |
23 | * ceph_snap_context for _every_ dirty page. This indicates which | |
24 | * snapshot the page was logically dirtied in, and thus which snap | |
25 | * context needs to be associated with the osd write during writeback. | |
26 | * | |
27 | * Similarly, struct ceph_inode_info maintains a set of counters to | |
25985edc | 28 | * count dirty pages on the inode. In the absence of snapshots, |
1d3576fd SW |
29 | * i_wrbuffer_ref == i_wrbuffer_ref_head == the dirty page count. |
30 | * | |
31 | * When a snapshot is taken (that is, when the client receives | |
32 | * notification that a snapshot was taken), each inode with caps and | |
33 | * with dirty pages (dirty pages implies there is a cap) gets a new | |
34 | * ceph_cap_snap in the i_cap_snaps list (which is sorted in ascending | |
35 | * order, new snaps go to the tail). The i_wrbuffer_ref_head count is | |
36 | * moved to capsnap->dirty. (Unless a sync write is currently in | |
37 | * progress. In that case, the capsnap is said to be "pending", new | |
38 | * writes cannot start, and the capsnap isn't "finalized" until the | |
39 | * write completes (or fails) and a final size/mtime for the inode for | |
40 | * that snap can be settled upon.) i_wrbuffer_ref_head is reset to 0. | |
41 | * | |
42 | * On writeback, we must submit writes to the osd IN SNAP ORDER. So, | |
43 | * we look for the first capsnap in i_cap_snaps and write out pages in | |
44 | * that snap context _only_. Then we move on to the next capsnap, | |
45 | * eventually reaching the "live" or "head" context (i.e., pages that | |
46 | * are not yet snapped) and are writing the most recently dirtied | |
47 | * pages. | |
48 | * | |
49 | * Invalidate and so forth must take care to ensure the dirty page | |
50 | * accounting is preserved. | |
51 | */ | |
52 | ||
2baba250 YS |
53 | #define CONGESTION_ON_THRESH(congestion_kb) (congestion_kb >> (PAGE_SHIFT-10)) |
54 | #define CONGESTION_OFF_THRESH(congestion_kb) \ | |
55 | (CONGESTION_ON_THRESH(congestion_kb) - \ | |
56 | (CONGESTION_ON_THRESH(congestion_kb) >> 2)) | |
57 | ||
61600ef8 YZ |
58 | static inline struct ceph_snap_context *page_snap_context(struct page *page) |
59 | { | |
60 | if (PagePrivate(page)) | |
61 | return (void *)page->private; | |
62 | return NULL; | |
63 | } | |
1d3576fd SW |
64 | |
65 | /* | |
66 | * Dirty a page. Optimistically adjust accounting, on the assumption | |
67 | * that we won't race with invalidate. If we do, readjust. | |
68 | */ | |
69 | static int ceph_set_page_dirty(struct page *page) | |
70 | { | |
71 | struct address_space *mapping = page->mapping; | |
72 | struct inode *inode; | |
73 | struct ceph_inode_info *ci; | |
1d3576fd | 74 | struct ceph_snap_context *snapc; |
7d6e1f54 | 75 | int ret; |
1d3576fd SW |
76 | |
77 | if (unlikely(!mapping)) | |
78 | return !TestSetPageDirty(page); | |
79 | ||
7d6e1f54 | 80 | if (PageDirty(page)) { |
1d3576fd SW |
81 | dout("%p set_page_dirty %p idx %lu -- already dirty\n", |
82 | mapping->host, page, page->index); | |
7d6e1f54 | 83 | BUG_ON(!PagePrivate(page)); |
1d3576fd SW |
84 | return 0; |
85 | } | |
86 | ||
87 | inode = mapping->host; | |
88 | ci = ceph_inode(inode); | |
89 | ||
1d3576fd | 90 | /* dirty the head */ |
be655596 | 91 | spin_lock(&ci->i_ceph_lock); |
5dda377c YZ |
92 | BUG_ON(ci->i_wr_ref == 0); // caller should hold Fw reference |
93 | if (__ceph_have_pending_cap_snap(ci)) { | |
94 | struct ceph_cap_snap *capsnap = | |
95 | list_last_entry(&ci->i_cap_snaps, | |
96 | struct ceph_cap_snap, | |
97 | ci_item); | |
98 | snapc = ceph_get_snap_context(capsnap->context); | |
99 | capsnap->dirty_pages++; | |
100 | } else { | |
101 | BUG_ON(!ci->i_head_snapc); | |
102 | snapc = ceph_get_snap_context(ci->i_head_snapc); | |
103 | ++ci->i_wrbuffer_ref_head; | |
104 | } | |
1d3576fd | 105 | if (ci->i_wrbuffer_ref == 0) |
0444d76a | 106 | ihold(inode); |
1d3576fd SW |
107 | ++ci->i_wrbuffer_ref; |
108 | dout("%p set_page_dirty %p idx %lu head %d/%d -> %d/%d " | |
109 | "snapc %p seq %lld (%d snaps)\n", | |
110 | mapping->host, page, page->index, | |
111 | ci->i_wrbuffer_ref-1, ci->i_wrbuffer_ref_head-1, | |
112 | ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head, | |
113 | snapc, snapc->seq, snapc->num_snaps); | |
be655596 | 114 | spin_unlock(&ci->i_ceph_lock); |
1d3576fd | 115 | |
7d6e1f54 SZ |
116 | /* |
117 | * Reference snap context in page->private. Also set | |
118 | * PagePrivate so that we get invalidatepage callback. | |
119 | */ | |
120 | BUG_ON(PagePrivate(page)); | |
121 | page->private = (unsigned long)snapc; | |
122 | SetPagePrivate(page); | |
1d3576fd | 123 | |
7d6e1f54 SZ |
124 | ret = __set_page_dirty_nobuffers(page); |
125 | WARN_ON(!PageLocked(page)); | |
126 | WARN_ON(!page->mapping); | |
1d3576fd | 127 | |
7d6e1f54 | 128 | return ret; |
1d3576fd SW |
129 | } |
130 | ||
131 | /* | |
132 | * If we are truncating the full page (i.e. offset == 0), adjust the | |
133 | * dirty page counters appropriately. Only called if there is private | |
134 | * data on the page. | |
135 | */ | |
d47992f8 LC |
136 | static void ceph_invalidatepage(struct page *page, unsigned int offset, |
137 | unsigned int length) | |
1d3576fd | 138 | { |
4ce1e9ad | 139 | struct inode *inode; |
1d3576fd | 140 | struct ceph_inode_info *ci; |
61600ef8 | 141 | struct ceph_snap_context *snapc = page_snap_context(page); |
1d3576fd | 142 | |
4ce1e9ad | 143 | inode = page->mapping->host; |
b150f5c1 MT |
144 | ci = ceph_inode(inode); |
145 | ||
09cbfeaf | 146 | if (offset != 0 || length != PAGE_SIZE) { |
b150f5c1 MT |
147 | dout("%p invalidatepage %p idx %lu partial dirty page %u~%u\n", |
148 | inode, page, page->index, offset, length); | |
149 | return; | |
150 | } | |
4ce1e9ad | 151 | |
99ccbd22 MT |
152 | ceph_invalidate_fscache_page(inode, page); |
153 | ||
154 | if (!PagePrivate(page)) | |
155 | return; | |
156 | ||
1d3576fd SW |
157 | /* |
158 | * We can get non-dirty pages here due to races between | |
159 | * set_page_dirty and truncate_complete_page; just spit out a | |
160 | * warning, in case we end up with accounting problems later. | |
161 | */ | |
162 | if (!PageDirty(page)) | |
163 | pr_err("%p invalidatepage %p page not dirty\n", inode, page); | |
164 | ||
b150f5c1 | 165 | ClearPageChecked(page); |
1d3576fd | 166 | |
b150f5c1 MT |
167 | dout("%p invalidatepage %p idx %lu full dirty page\n", |
168 | inode, page, page->index); | |
169 | ||
170 | ceph_put_wrbuffer_cap_refs(ci, 1, snapc); | |
171 | ceph_put_snap_context(snapc); | |
172 | page->private = 0; | |
173 | ClearPagePrivate(page); | |
1d3576fd SW |
174 | } |
175 | ||
1d3576fd SW |
176 | static int ceph_releasepage(struct page *page, gfp_t g) |
177 | { | |
45311267 YZ |
178 | dout("%p releasepage %p idx %lu\n", page->mapping->host, |
179 | page, page->index); | |
1d3576fd | 180 | WARN_ON(PageDirty(page)); |
99ccbd22 MT |
181 | |
182 | /* Can we release the page from the cache? */ | |
183 | if (!ceph_release_fscache_page(page, g)) | |
184 | return 0; | |
185 | ||
186 | return !PagePrivate(page); | |
1d3576fd SW |
187 | } |
188 | ||
189 | /* | |
190 | * read a single page, without unlocking it. | |
191 | */ | |
192 | static int readpage_nounlock(struct file *filp, struct page *page) | |
193 | { | |
496ad9aa | 194 | struct inode *inode = file_inode(filp); |
1d3576fd | 195 | struct ceph_inode_info *ci = ceph_inode(inode); |
99ccbd22 | 196 | struct ceph_osd_client *osdc = |
3d14c5d2 | 197 | &ceph_inode_to_client(inode)->client->osdc; |
1d3576fd | 198 | int err = 0; |
83701246 | 199 | u64 off = page_offset(page); |
09cbfeaf | 200 | u64 len = PAGE_SIZE; |
1d3576fd | 201 | |
83701246 | 202 | if (off >= i_size_read(inode)) { |
09cbfeaf | 203 | zero_user_segment(page, 0, PAGE_SIZE); |
83701246 YZ |
204 | SetPageUptodate(page); |
205 | return 0; | |
206 | } | |
99ccbd22 | 207 | |
fcc02d2a YZ |
208 | if (ci->i_inline_version != CEPH_INLINE_NONE) { |
209 | /* | |
210 | * Uptodate inline data should have been added | |
211 | * into page cache while getting Fcr caps. | |
212 | */ | |
213 | if (off == 0) | |
214 | return -EINVAL; | |
09cbfeaf | 215 | zero_user_segment(page, 0, PAGE_SIZE); |
fcc02d2a YZ |
216 | SetPageUptodate(page); |
217 | return 0; | |
218 | } | |
83701246 YZ |
219 | |
220 | err = ceph_readpage_from_fscache(inode, page); | |
99ccbd22 MT |
221 | if (err == 0) |
222 | goto out; | |
223 | ||
1d3576fd SW |
224 | dout("readpage inode %p file %p page %p index %lu\n", |
225 | inode, filp, page, page->index); | |
226 | err = ceph_osdc_readpages(osdc, ceph_vino(inode), &ci->i_layout, | |
83701246 | 227 | off, &len, |
1d3576fd | 228 | ci->i_truncate_seq, ci->i_truncate_size, |
b7495fc2 | 229 | &page, 1, 0); |
1d3576fd SW |
230 | if (err == -ENOENT) |
231 | err = 0; | |
232 | if (err < 0) { | |
233 | SetPageError(page); | |
18302805 | 234 | ceph_fscache_readpage_cancel(inode, page); |
1d3576fd | 235 | goto out; |
1d3576fd | 236 | } |
09cbfeaf | 237 | if (err < PAGE_SIZE) |
23cd573b | 238 | /* zero fill remainder of page */ |
09cbfeaf | 239 | zero_user_segment(page, err, PAGE_SIZE); |
23cd573b ZZ |
240 | else |
241 | flush_dcache_page(page); | |
1d3576fd | 242 | |
23cd573b ZZ |
243 | SetPageUptodate(page); |
244 | ceph_readpage_to_fscache(inode, page); | |
99ccbd22 | 245 | |
1d3576fd SW |
246 | out: |
247 | return err < 0 ? err : 0; | |
248 | } | |
249 | ||
250 | static int ceph_readpage(struct file *filp, struct page *page) | |
251 | { | |
252 | int r = readpage_nounlock(filp, page); | |
253 | unlock_page(page); | |
254 | return r; | |
255 | } | |
256 | ||
257 | /* | |
7c272194 | 258 | * Finish an async read(ahead) op. |
1d3576fd | 259 | */ |
85e084fe | 260 | static void finish_read(struct ceph_osd_request *req) |
1d3576fd | 261 | { |
7c272194 | 262 | struct inode *inode = req->r_inode; |
87060c10 | 263 | struct ceph_osd_data *osd_data; |
85e084fe ID |
264 | int rc = req->r_result <= 0 ? req->r_result : 0; |
265 | int bytes = req->r_result >= 0 ? req->r_result : 0; | |
e0c59487 | 266 | int num_pages; |
7c272194 | 267 | int i; |
1d3576fd | 268 | |
7c272194 SW |
269 | dout("finish_read %p req %p rc %d bytes %d\n", inode, req, rc, bytes); |
270 | ||
271 | /* unlock all pages, zeroing any data we didn't read */ | |
406e2c9f | 272 | osd_data = osd_req_op_extent_osd_data(req, 0); |
87060c10 AE |
273 | BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGES); |
274 | num_pages = calc_pages_for((u64)osd_data->alignment, | |
275 | (u64)osd_data->length); | |
e0c59487 | 276 | for (i = 0; i < num_pages; i++) { |
87060c10 | 277 | struct page *page = osd_data->pages[i]; |
7c272194 | 278 | |
368e3585 YZ |
279 | if (rc < 0 && rc != -ENOENT) { |
280 | ceph_fscache_readpage_cancel(inode, page); | |
f36132a7 | 281 | goto unlock; |
368e3585 | 282 | } |
09cbfeaf | 283 | if (bytes < (int)PAGE_SIZE) { |
7c272194 SW |
284 | /* zero (remainder of) page */ |
285 | int s = bytes < 0 ? 0 : bytes; | |
09cbfeaf | 286 | zero_user_segment(page, s, PAGE_SIZE); |
1d3576fd | 287 | } |
7c272194 SW |
288 | dout("finish_read %p uptodate %p idx %lu\n", inode, page, |
289 | page->index); | |
290 | flush_dcache_page(page); | |
291 | SetPageUptodate(page); | |
99ccbd22 | 292 | ceph_readpage_to_fscache(inode, page); |
f36132a7 | 293 | unlock: |
7c272194 | 294 | unlock_page(page); |
09cbfeaf KS |
295 | put_page(page); |
296 | bytes -= PAGE_SIZE; | |
1d3576fd | 297 | } |
87060c10 | 298 | kfree(osd_data->pages); |
1d3576fd SW |
299 | } |
300 | ||
301 | /* | |
7c272194 SW |
302 | * start an async read(ahead) operation. return nr_pages we submitted |
303 | * a read for on success, or negative error code. | |
1d3576fd | 304 | */ |
0d66a487 | 305 | static int start_read(struct inode *inode, struct list_head *page_list, int max) |
1d3576fd | 306 | { |
3d14c5d2 YS |
307 | struct ceph_osd_client *osdc = |
308 | &ceph_inode_to_client(inode)->client->osdc; | |
7c272194 SW |
309 | struct ceph_inode_info *ci = ceph_inode(inode); |
310 | struct page *page = list_entry(page_list->prev, struct page, lru); | |
acead002 | 311 | struct ceph_vino vino; |
7c272194 SW |
312 | struct ceph_osd_request *req; |
313 | u64 off; | |
1d3576fd | 314 | u64 len; |
7c272194 SW |
315 | int i; |
316 | struct page **pages; | |
317 | pgoff_t next_index; | |
318 | int nr_pages = 0; | |
319 | int ret; | |
1d3576fd | 320 | |
6285bc23 | 321 | off = (u64) page_offset(page); |
1d3576fd | 322 | |
7c272194 SW |
323 | /* count pages */ |
324 | next_index = page->index; | |
325 | list_for_each_entry_reverse(page, page_list, lru) { | |
326 | if (page->index != next_index) | |
327 | break; | |
328 | nr_pages++; | |
329 | next_index++; | |
0d66a487 SW |
330 | if (max && nr_pages == max) |
331 | break; | |
7c272194 | 332 | } |
09cbfeaf | 333 | len = nr_pages << PAGE_SHIFT; |
7c272194 SW |
334 | dout("start_read %p nr_pages %d is %lld~%lld\n", inode, nr_pages, |
335 | off, len); | |
acead002 AE |
336 | vino = ceph_vino(inode); |
337 | req = ceph_osdc_new_request(osdc, &ci->i_layout, vino, off, &len, | |
715e4cd4 | 338 | 0, 1, CEPH_OSD_OP_READ, |
acead002 | 339 | CEPH_OSD_FLAG_READ, NULL, |
7c272194 | 340 | ci->i_truncate_seq, ci->i_truncate_size, |
acead002 | 341 | false); |
6816282d SW |
342 | if (IS_ERR(req)) |
343 | return PTR_ERR(req); | |
1d3576fd | 344 | |
7c272194 | 345 | /* build page vector */ |
cf7b7e14 | 346 | nr_pages = calc_pages_for(0, len); |
687265e5 | 347 | pages = kmalloc(sizeof(*pages) * nr_pages, GFP_KERNEL); |
7c272194 SW |
348 | ret = -ENOMEM; |
349 | if (!pages) | |
350 | goto out; | |
351 | for (i = 0; i < nr_pages; ++i) { | |
352 | page = list_entry(page_list->prev, struct page, lru); | |
353 | BUG_ON(PageLocked(page)); | |
1d3576fd | 354 | list_del(&page->lru); |
99ccbd22 | 355 | |
7c272194 SW |
356 | dout("start_read %p adding %p idx %lu\n", inode, page, |
357 | page->index); | |
358 | if (add_to_page_cache_lru(page, &inode->i_data, page->index, | |
687265e5 | 359 | GFP_KERNEL)) { |
d4d3aa38 | 360 | ceph_fscache_uncache_page(inode, page); |
09cbfeaf | 361 | put_page(page); |
7c272194 | 362 | dout("start_read %p add_to_page_cache failed %p\n", |
1d3576fd | 363 | inode, page); |
7c272194 | 364 | nr_pages = i; |
1afe4785 YZ |
365 | if (nr_pages > 0) { |
366 | len = nr_pages << PAGE_SHIFT; | |
367 | break; | |
368 | } | |
7c272194 | 369 | goto out_pages; |
1d3576fd | 370 | } |
7c272194 | 371 | pages[i] = page; |
1d3576fd | 372 | } |
406e2c9f | 373 | osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0, false, false); |
7c272194 SW |
374 | req->r_callback = finish_read; |
375 | req->r_inode = inode; | |
376 | ||
377 | dout("start_read %p starting %p %lld~%lld\n", inode, req, off, len); | |
378 | ret = ceph_osdc_start_request(osdc, req, false); | |
379 | if (ret < 0) | |
380 | goto out_pages; | |
381 | ceph_osdc_put_request(req); | |
382 | return nr_pages; | |
383 | ||
384 | out_pages: | |
1afe4785 YZ |
385 | for (i = 0; i < nr_pages; ++i) { |
386 | ceph_fscache_readpage_cancel(inode, pages[i]); | |
387 | unlock_page(pages[i]); | |
388 | } | |
389 | ceph_put_page_vector(pages, nr_pages, false); | |
7c272194 SW |
390 | out: |
391 | ceph_osdc_put_request(req); | |
392 | return ret; | |
393 | } | |
1d3576fd | 394 | |
7c272194 SW |
395 | |
396 | /* | |
397 | * Read multiple pages. Leave pages we don't read + unlock in page_list; | |
398 | * the caller (VM) cleans them up. | |
399 | */ | |
400 | static int ceph_readpages(struct file *file, struct address_space *mapping, | |
401 | struct list_head *page_list, unsigned nr_pages) | |
402 | { | |
496ad9aa | 403 | struct inode *inode = file_inode(file); |
0d66a487 | 404 | struct ceph_fs_client *fsc = ceph_inode_to_client(inode); |
7c272194 | 405 | int rc = 0; |
0d66a487 SW |
406 | int max = 0; |
407 | ||
83701246 YZ |
408 | if (ceph_inode(inode)->i_inline_version != CEPH_INLINE_NONE) |
409 | return -EINVAL; | |
410 | ||
99ccbd22 MT |
411 | rc = ceph_readpages_from_fscache(mapping->host, mapping, page_list, |
412 | &nr_pages); | |
413 | ||
414 | if (rc == 0) | |
415 | goto out; | |
416 | ||
09cbfeaf KS |
417 | if (fsc->mount_options->rsize >= PAGE_SIZE) |
418 | max = (fsc->mount_options->rsize + PAGE_SIZE - 1) | |
0d66a487 | 419 | >> PAGE_SHIFT; |
7c272194 | 420 | |
2794a82a AE |
421 | dout("readpages %p file %p nr_pages %d max %d\n", inode, |
422 | file, nr_pages, | |
0d66a487 | 423 | max); |
7c272194 | 424 | while (!list_empty(page_list)) { |
0d66a487 | 425 | rc = start_read(inode, page_list, max); |
7c272194 SW |
426 | if (rc < 0) |
427 | goto out; | |
428 | BUG_ON(rc == 0); | |
429 | } | |
1d3576fd | 430 | out: |
76be778b MT |
431 | ceph_fscache_readpages_cancel(inode, page_list); |
432 | ||
7c272194 | 433 | dout("readpages %p file %p ret %d\n", inode, file, rc); |
1d3576fd SW |
434 | return rc; |
435 | } | |
436 | ||
437 | /* | |
438 | * Get ref for the oldest snapc for an inode with dirty data... that is, the | |
439 | * only snap context we are allowed to write back. | |
1d3576fd | 440 | */ |
6298a337 | 441 | static struct ceph_snap_context *get_oldest_context(struct inode *inode, |
e1966b49 | 442 | loff_t *snap_size) |
1d3576fd SW |
443 | { |
444 | struct ceph_inode_info *ci = ceph_inode(inode); | |
445 | struct ceph_snap_context *snapc = NULL; | |
446 | struct ceph_cap_snap *capsnap = NULL; | |
447 | ||
be655596 | 448 | spin_lock(&ci->i_ceph_lock); |
1d3576fd SW |
449 | list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { |
450 | dout(" cap_snap %p snapc %p has %d dirty pages\n", capsnap, | |
451 | capsnap->context, capsnap->dirty_pages); | |
452 | if (capsnap->dirty_pages) { | |
453 | snapc = ceph_get_snap_context(capsnap->context); | |
454 | if (snap_size) | |
455 | *snap_size = capsnap->size; | |
456 | break; | |
457 | } | |
458 | } | |
7d8cb26d | 459 | if (!snapc && ci->i_wrbuffer_ref_head) { |
80e755fe | 460 | snapc = ceph_get_snap_context(ci->i_head_snapc); |
1d3576fd SW |
461 | dout(" head snapc %p has %d dirty pages\n", |
462 | snapc, ci->i_wrbuffer_ref_head); | |
463 | } | |
be655596 | 464 | spin_unlock(&ci->i_ceph_lock); |
1d3576fd SW |
465 | return snapc; |
466 | } | |
467 | ||
468 | /* | |
469 | * Write a single page, but leave the page locked. | |
470 | * | |
471 | * If we get a write error, set the page error bit, but still adjust the | |
472 | * dirty page accounting (i.e., page is no longer dirty). | |
473 | */ | |
474 | static int writepage_nounlock(struct page *page, struct writeback_control *wbc) | |
475 | { | |
476 | struct inode *inode; | |
477 | struct ceph_inode_info *ci; | |
3d14c5d2 | 478 | struct ceph_fs_client *fsc; |
1d3576fd | 479 | struct ceph_osd_client *osdc; |
6298a337 | 480 | struct ceph_snap_context *snapc, *oldest; |
fc2744aa | 481 | loff_t page_off = page_offset(page); |
e1966b49 | 482 | loff_t snap_size = -1; |
2baba250 | 483 | long writeback_stat; |
e1966b49 | 484 | u64 truncate_size; |
fc2744aa | 485 | u32 truncate_seq; |
09cbfeaf | 486 | int err = 0, len = PAGE_SIZE; |
1d3576fd SW |
487 | |
488 | dout("writepage %p idx %lu\n", page, page->index); | |
489 | ||
490 | if (!page->mapping || !page->mapping->host) { | |
491 | dout("writepage %p - no mapping\n", page); | |
492 | return -EFAULT; | |
493 | } | |
494 | inode = page->mapping->host; | |
495 | ci = ceph_inode(inode); | |
3d14c5d2 YS |
496 | fsc = ceph_inode_to_client(inode); |
497 | osdc = &fsc->client->osdc; | |
1d3576fd SW |
498 | |
499 | /* verify this is a writeable snap context */ | |
61600ef8 | 500 | snapc = page_snap_context(page); |
1d3576fd SW |
501 | if (snapc == NULL) { |
502 | dout("writepage %p page %p not dirty?\n", inode, page); | |
503 | goto out; | |
504 | } | |
6298a337 SW |
505 | oldest = get_oldest_context(inode, &snap_size); |
506 | if (snapc->seq > oldest->seq) { | |
1d3576fd | 507 | dout("writepage %p page %p snapc %p not writeable - noop\n", |
61600ef8 | 508 | inode, page, snapc); |
1d3576fd SW |
509 | /* we should only noop if called by kswapd */ |
510 | WARN_ON((current->flags & PF_MEMALLOC) == 0); | |
6298a337 | 511 | ceph_put_snap_context(oldest); |
1d3576fd SW |
512 | goto out; |
513 | } | |
6298a337 | 514 | ceph_put_snap_context(oldest); |
1d3576fd | 515 | |
fc2744aa YZ |
516 | spin_lock(&ci->i_ceph_lock); |
517 | truncate_seq = ci->i_truncate_seq; | |
518 | truncate_size = ci->i_truncate_size; | |
e1966b49 | 519 | if (snap_size == -1) |
fc2744aa YZ |
520 | snap_size = i_size_read(inode); |
521 | spin_unlock(&ci->i_ceph_lock); | |
522 | ||
1d3576fd | 523 | /* is this a partial page at end of file? */ |
fc2744aa YZ |
524 | if (page_off >= snap_size) { |
525 | dout("%p page eof %llu\n", page, snap_size); | |
526 | goto out; | |
527 | } | |
528 | if (snap_size < page_off + len) | |
529 | len = snap_size - page_off; | |
1d3576fd | 530 | |
ae00d4f3 SW |
531 | dout("writepage %p page %p index %lu on %llu~%u snapc %p\n", |
532 | inode, page, page->index, page_off, len, snapc); | |
1d3576fd | 533 | |
3d14c5d2 | 534 | writeback_stat = atomic_long_inc_return(&fsc->writeback_count); |
2baba250 | 535 | if (writeback_stat > |
3d14c5d2 YS |
536 | CONGESTION_ON_THRESH(fsc->mount_options->congestion_kb)) |
537 | set_bdi_congested(&fsc->backing_dev_info, BLK_RW_ASYNC); | |
2baba250 | 538 | |
1d3576fd SW |
539 | set_page_writeback(page); |
540 | err = ceph_osdc_writepages(osdc, ceph_vino(inode), | |
541 | &ci->i_layout, snapc, | |
542 | page_off, len, | |
fc2744aa | 543 | truncate_seq, truncate_size, |
24808826 | 544 | &inode->i_mtime, &page, 1); |
1d3576fd | 545 | if (err < 0) { |
ad15ec06 YZ |
546 | struct writeback_control tmp_wbc; |
547 | if (!wbc) | |
548 | wbc = &tmp_wbc; | |
549 | if (err == -ERESTARTSYS) { | |
550 | /* killed by SIGKILL */ | |
551 | dout("writepage interrupted page %p\n", page); | |
552 | redirty_page_for_writepage(wbc, page); | |
553 | end_page_writeback(page); | |
554 | goto out; | |
555 | } | |
556 | dout("writepage setting page/mapping error %d %p\n", | |
557 | err, page); | |
1d3576fd SW |
558 | SetPageError(page); |
559 | mapping_set_error(&inode->i_data, err); | |
ad15ec06 | 560 | wbc->pages_skipped++; |
1d3576fd SW |
561 | } else { |
562 | dout("writepage cleaned page %p\n", page); | |
563 | err = 0; /* vfs expects us to return 0 */ | |
564 | } | |
565 | page->private = 0; | |
566 | ClearPagePrivate(page); | |
567 | end_page_writeback(page); | |
568 | ceph_put_wrbuffer_cap_refs(ci, 1, snapc); | |
6298a337 | 569 | ceph_put_snap_context(snapc); /* page's reference */ |
1d3576fd SW |
570 | out: |
571 | return err; | |
572 | } | |
573 | ||
574 | static int ceph_writepage(struct page *page, struct writeback_control *wbc) | |
575 | { | |
dbd646a8 YS |
576 | int err; |
577 | struct inode *inode = page->mapping->host; | |
578 | BUG_ON(!inode); | |
70b666c3 | 579 | ihold(inode); |
dbd646a8 | 580 | err = writepage_nounlock(page, wbc); |
ad15ec06 YZ |
581 | if (err == -ERESTARTSYS) { |
582 | /* direct memory reclaimer was killed by SIGKILL. return 0 | |
583 | * to prevent caller from setting mapping/page error */ | |
584 | err = 0; | |
585 | } | |
1d3576fd | 586 | unlock_page(page); |
dbd646a8 | 587 | iput(inode); |
1d3576fd SW |
588 | return err; |
589 | } | |
590 | ||
1d3576fd SW |
591 | /* |
592 | * lame release_pages helper. release_pages() isn't exported to | |
593 | * modules. | |
594 | */ | |
595 | static void ceph_release_pages(struct page **pages, int num) | |
596 | { | |
597 | struct pagevec pvec; | |
598 | int i; | |
599 | ||
600 | pagevec_init(&pvec, 0); | |
601 | for (i = 0; i < num; i++) { | |
602 | if (pagevec_add(&pvec, pages[i]) == 0) | |
603 | pagevec_release(&pvec); | |
604 | } | |
605 | pagevec_release(&pvec); | |
606 | } | |
607 | ||
1d3576fd SW |
608 | /* |
609 | * async writeback completion handler. | |
610 | * | |
611 | * If we get an error, set the mapping error bit, but not the individual | |
612 | * page error bits. | |
613 | */ | |
85e084fe | 614 | static void writepages_finish(struct ceph_osd_request *req) |
1d3576fd SW |
615 | { |
616 | struct inode *inode = req->r_inode; | |
1d3576fd | 617 | struct ceph_inode_info *ci = ceph_inode(inode); |
87060c10 | 618 | struct ceph_osd_data *osd_data; |
1d3576fd | 619 | struct page *page; |
5b64640c YZ |
620 | int num_pages, total_pages = 0; |
621 | int i, j; | |
622 | int rc = req->r_result; | |
1d3576fd SW |
623 | struct ceph_snap_context *snapc = req->r_snapc; |
624 | struct address_space *mapping = inode->i_mapping; | |
3d14c5d2 | 625 | struct ceph_fs_client *fsc = ceph_inode_to_client(inode); |
5b64640c | 626 | bool remove_page; |
1d3576fd | 627 | |
5b64640c YZ |
628 | dout("writepages_finish %p rc %d\n", inode, rc); |
629 | if (rc < 0) | |
1d3576fd | 630 | mapping_set_error(mapping, rc); |
5b64640c YZ |
631 | |
632 | /* | |
633 | * We lost the cache cap, need to truncate the page before | |
634 | * it is unlocked, otherwise we'd truncate it later in the | |
635 | * page truncation thread, possibly losing some data that | |
636 | * raced its way in | |
637 | */ | |
638 | remove_page = !(ceph_caps_issued(ci) & | |
639 | (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)); | |
1d3576fd SW |
640 | |
641 | /* clean all pages */ | |
5b64640c YZ |
642 | for (i = 0; i < req->r_num_ops; i++) { |
643 | if (req->r_ops[i].op != CEPH_OSD_OP_WRITE) | |
644 | break; | |
e63dc5c7 | 645 | |
5b64640c YZ |
646 | osd_data = osd_req_op_extent_osd_data(req, i); |
647 | BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGES); | |
648 | num_pages = calc_pages_for((u64)osd_data->alignment, | |
649 | (u64)osd_data->length); | |
650 | total_pages += num_pages; | |
651 | for (j = 0; j < num_pages; j++) { | |
652 | page = osd_data->pages[j]; | |
653 | BUG_ON(!page); | |
654 | WARN_ON(!PageUptodate(page)); | |
655 | ||
656 | if (atomic_long_dec_return(&fsc->writeback_count) < | |
657 | CONGESTION_OFF_THRESH( | |
658 | fsc->mount_options->congestion_kb)) | |
659 | clear_bdi_congested(&fsc->backing_dev_info, | |
660 | BLK_RW_ASYNC); | |
661 | ||
b109eec6 YZ |
662 | if (rc < 0) |
663 | SetPageError(page); | |
664 | ||
5b64640c YZ |
665 | ceph_put_snap_context(page_snap_context(page)); |
666 | page->private = 0; | |
667 | ClearPagePrivate(page); | |
668 | dout("unlocking %p\n", page); | |
669 | end_page_writeback(page); | |
670 | ||
671 | if (remove_page) | |
672 | generic_error_remove_page(inode->i_mapping, | |
673 | page); | |
674 | ||
675 | unlock_page(page); | |
676 | } | |
677 | dout("writepages_finish %p wrote %llu bytes cleaned %d pages\n", | |
678 | inode, osd_data->length, rc >= 0 ? num_pages : 0); | |
e63dc5c7 | 679 | |
5b64640c | 680 | ceph_release_pages(osd_data->pages, num_pages); |
1d3576fd | 681 | } |
1d3576fd | 682 | |
5b64640c YZ |
683 | ceph_put_wrbuffer_cap_refs(ci, total_pages, snapc); |
684 | ||
685 | osd_data = osd_req_op_extent_osd_data(req, 0); | |
87060c10 AE |
686 | if (osd_data->pages_from_pool) |
687 | mempool_free(osd_data->pages, | |
640ef79d | 688 | ceph_sb_to_client(inode->i_sb)->wb_pagevec_pool); |
1d3576fd | 689 | else |
87060c10 | 690 | kfree(osd_data->pages); |
1d3576fd SW |
691 | ceph_osdc_put_request(req); |
692 | } | |
693 | ||
1d3576fd SW |
694 | /* |
695 | * initiate async writeback | |
696 | */ | |
697 | static int ceph_writepages_start(struct address_space *mapping, | |
698 | struct writeback_control *wbc) | |
699 | { | |
700 | struct inode *inode = mapping->host; | |
1d3576fd | 701 | struct ceph_inode_info *ci = ceph_inode(inode); |
fc2744aa YZ |
702 | struct ceph_fs_client *fsc = ceph_inode_to_client(inode); |
703 | struct ceph_vino vino = ceph_vino(inode); | |
1d3576fd SW |
704 | pgoff_t index, start, end; |
705 | int range_whole = 0; | |
706 | int should_loop = 1; | |
707 | pgoff_t max_pages = 0, max_pages_ever = 0; | |
80e755fe | 708 | struct ceph_snap_context *snapc = NULL, *last_snapc = NULL, *pgsnapc; |
1d3576fd SW |
709 | struct pagevec pvec; |
710 | int done = 0; | |
711 | int rc = 0; | |
712 | unsigned wsize = 1 << inode->i_blkbits; | |
713 | struct ceph_osd_request *req = NULL; | |
021b77be | 714 | int do_sync = 0; |
e1966b49 YZ |
715 | loff_t snap_size, i_size; |
716 | u64 truncate_size; | |
fc2744aa | 717 | u32 truncate_seq; |
1d3576fd SW |
718 | |
719 | /* | |
720 | * Include a 'sync' in the OSD request if this is a data | |
721 | * integrity write (e.g., O_SYNC write or fsync()), or if our | |
722 | * cap is being revoked. | |
723 | */ | |
c62988ec | 724 | if ((wbc->sync_mode == WB_SYNC_ALL) || |
725 | ceph_caps_revoking(ci, CEPH_CAP_FILE_BUFFER)) | |
1d3576fd SW |
726 | do_sync = 1; |
727 | dout("writepages_start %p dosync=%d (mode=%s)\n", | |
728 | inode, do_sync, | |
729 | wbc->sync_mode == WB_SYNC_NONE ? "NONE" : | |
730 | (wbc->sync_mode == WB_SYNC_ALL ? "ALL" : "HOLD")); | |
731 | ||
48fec5d0 | 732 | if (ACCESS_ONCE(fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { |
6c93df5d YZ |
733 | if (ci->i_wrbuffer_ref > 0) { |
734 | pr_warn_ratelimited( | |
735 | "writepage_start %p %lld forced umount\n", | |
736 | inode, ceph_ino(inode)); | |
737 | } | |
a341d4df | 738 | mapping_set_error(mapping, -EIO); |
1d3576fd SW |
739 | return -EIO; /* we're in a forced umount, don't write! */ |
740 | } | |
3d14c5d2 YS |
741 | if (fsc->mount_options->wsize && fsc->mount_options->wsize < wsize) |
742 | wsize = fsc->mount_options->wsize; | |
09cbfeaf KS |
743 | if (wsize < PAGE_SIZE) |
744 | wsize = PAGE_SIZE; | |
745 | max_pages_ever = wsize >> PAGE_SHIFT; | |
1d3576fd SW |
746 | |
747 | pagevec_init(&pvec, 0); | |
748 | ||
1d3576fd SW |
749 | /* where to start/end? */ |
750 | if (wbc->range_cyclic) { | |
751 | start = mapping->writeback_index; /* Start from prev offset */ | |
752 | end = -1; | |
753 | dout(" cyclic, start at %lu\n", start); | |
754 | } else { | |
09cbfeaf KS |
755 | start = wbc->range_start >> PAGE_SHIFT; |
756 | end = wbc->range_end >> PAGE_SHIFT; | |
1d3576fd SW |
757 | if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) |
758 | range_whole = 1; | |
759 | should_loop = 0; | |
760 | dout(" not cyclic, %lu to %lu\n", start, end); | |
761 | } | |
762 | index = start; | |
763 | ||
764 | retry: | |
765 | /* find oldest snap context with dirty data */ | |
766 | ceph_put_snap_context(snapc); | |
e1966b49 | 767 | snap_size = -1; |
1d3576fd SW |
768 | snapc = get_oldest_context(inode, &snap_size); |
769 | if (!snapc) { | |
770 | /* hmm, why does writepages get called when there | |
771 | is no dirty data? */ | |
772 | dout(" no snap context with dirty data?\n"); | |
773 | goto out; | |
774 | } | |
775 | dout(" oldest snapc is %p seq %lld (%d snaps)\n", | |
776 | snapc, snapc->seq, snapc->num_snaps); | |
fc2744aa YZ |
777 | |
778 | spin_lock(&ci->i_ceph_lock); | |
779 | truncate_seq = ci->i_truncate_seq; | |
780 | truncate_size = ci->i_truncate_size; | |
e1966b49 | 781 | i_size = i_size_read(inode); |
fc2744aa YZ |
782 | spin_unlock(&ci->i_ceph_lock); |
783 | ||
1d3576fd SW |
784 | if (last_snapc && snapc != last_snapc) { |
785 | /* if we switched to a newer snapc, restart our scan at the | |
786 | * start of the original file range. */ | |
787 | dout(" snapc differs from last pass, restarting at %lu\n", | |
788 | index); | |
789 | index = start; | |
790 | } | |
791 | last_snapc = snapc; | |
792 | ||
793 | while (!done && index <= end) { | |
794 | unsigned i; | |
795 | int first; | |
5b64640c YZ |
796 | pgoff_t strip_unit_end = 0; |
797 | int num_ops = 0, op_idx; | |
798 | int pvec_pages, locked_pages = 0; | |
799 | struct page **pages = NULL, **data_pages; | |
e5975c7c | 800 | mempool_t *pool = NULL; /* Becomes non-null if mempool used */ |
1d3576fd SW |
801 | struct page *page; |
802 | int want; | |
5b64640c | 803 | u64 offset = 0, len = 0; |
1d3576fd | 804 | |
1d3576fd SW |
805 | max_pages = max_pages_ever; |
806 | ||
807 | get_more_pages: | |
808 | first = -1; | |
809 | want = min(end - index, | |
810 | min((pgoff_t)PAGEVEC_SIZE, | |
811 | max_pages - (pgoff_t)locked_pages) - 1) | |
812 | + 1; | |
813 | pvec_pages = pagevec_lookup_tag(&pvec, mapping, &index, | |
814 | PAGECACHE_TAG_DIRTY, | |
815 | want); | |
816 | dout("pagevec_lookup_tag got %d\n", pvec_pages); | |
817 | if (!pvec_pages && !locked_pages) | |
818 | break; | |
819 | for (i = 0; i < pvec_pages && locked_pages < max_pages; i++) { | |
820 | page = pvec.pages[i]; | |
821 | dout("? %p idx %lu\n", page, page->index); | |
822 | if (locked_pages == 0) | |
823 | lock_page(page); /* first page */ | |
824 | else if (!trylock_page(page)) | |
825 | break; | |
826 | ||
827 | /* only dirty pages, or our accounting breaks */ | |
828 | if (unlikely(!PageDirty(page)) || | |
829 | unlikely(page->mapping != mapping)) { | |
830 | dout("!dirty or !mapping %p\n", page); | |
831 | unlock_page(page); | |
832 | break; | |
833 | } | |
834 | if (!wbc->range_cyclic && page->index > end) { | |
835 | dout("end of range %p\n", page); | |
836 | done = 1; | |
837 | unlock_page(page); | |
838 | break; | |
839 | } | |
5b64640c YZ |
840 | if (strip_unit_end && (page->index > strip_unit_end)) { |
841 | dout("end of strip unit %p\n", page); | |
1d3576fd SW |
842 | unlock_page(page); |
843 | break; | |
844 | } | |
845 | if (wbc->sync_mode != WB_SYNC_NONE) { | |
846 | dout("waiting on writeback %p\n", page); | |
847 | wait_on_page_writeback(page); | |
848 | } | |
e1966b49 YZ |
849 | if (page_offset(page) >= |
850 | (snap_size == -1 ? i_size : snap_size)) { | |
851 | dout("%p page eof %llu\n", page, | |
852 | (snap_size == -1 ? i_size : snap_size)); | |
1d3576fd SW |
853 | done = 1; |
854 | unlock_page(page); | |
855 | break; | |
856 | } | |
857 | if (PageWriteback(page)) { | |
858 | dout("%p under writeback\n", page); | |
859 | unlock_page(page); | |
860 | break; | |
861 | } | |
862 | ||
863 | /* only if matching snap context */ | |
61600ef8 | 864 | pgsnapc = page_snap_context(page); |
80e755fe SW |
865 | if (pgsnapc->seq > snapc->seq) { |
866 | dout("page snapc %p %lld > oldest %p %lld\n", | |
867 | pgsnapc, pgsnapc->seq, snapc, snapc->seq); | |
1d3576fd SW |
868 | unlock_page(page); |
869 | if (!locked_pages) | |
870 | continue; /* keep looking for snap */ | |
871 | break; | |
872 | } | |
873 | ||
874 | if (!clear_page_dirty_for_io(page)) { | |
875 | dout("%p !clear_page_dirty_for_io\n", page); | |
876 | unlock_page(page); | |
877 | break; | |
878 | } | |
879 | ||
e5975c7c AE |
880 | /* |
881 | * We have something to write. If this is | |
882 | * the first locked page this time through, | |
5b64640c YZ |
883 | * calculate max possinle write size and |
884 | * allocate a page array | |
e5975c7c | 885 | */ |
1d3576fd | 886 | if (locked_pages == 0) { |
5b64640c YZ |
887 | u64 objnum; |
888 | u64 objoff; | |
889 | ||
1d3576fd | 890 | /* prepare async write request */ |
e5975c7c | 891 | offset = (u64)page_offset(page); |
1d3576fd | 892 | len = wsize; |
5b64640c YZ |
893 | |
894 | rc = ceph_calc_file_object_mapping(&ci->i_layout, | |
895 | offset, len, | |
896 | &objnum, &objoff, | |
897 | &len); | |
898 | if (rc < 0) { | |
8c71897b HC |
899 | unlock_page(page); |
900 | break; | |
901 | } | |
902 | ||
5b64640c YZ |
903 | num_ops = 1 + do_sync; |
904 | strip_unit_end = page->index + | |
09cbfeaf | 905 | ((len - 1) >> PAGE_SHIFT); |
88486957 | 906 | |
5b64640c | 907 | BUG_ON(pages); |
88486957 | 908 | max_pages = calc_pages_for(0, (u64)len); |
fc2744aa YZ |
909 | pages = kmalloc(max_pages * sizeof (*pages), |
910 | GFP_NOFS); | |
88486957 AE |
911 | if (!pages) { |
912 | pool = fsc->wb_pagevec_pool; | |
88486957 | 913 | pages = mempool_alloc(pool, GFP_NOFS); |
e5975c7c | 914 | BUG_ON(!pages); |
88486957 | 915 | } |
5b64640c YZ |
916 | |
917 | len = 0; | |
918 | } else if (page->index != | |
09cbfeaf | 919 | (offset + len) >> PAGE_SHIFT) { |
5b64640c YZ |
920 | if (num_ops >= (pool ? CEPH_OSD_SLAB_OPS : |
921 | CEPH_OSD_MAX_OPS)) { | |
922 | redirty_page_for_writepage(wbc, page); | |
923 | unlock_page(page); | |
924 | break; | |
925 | } | |
926 | ||
927 | num_ops++; | |
928 | offset = (u64)page_offset(page); | |
929 | len = 0; | |
1d3576fd SW |
930 | } |
931 | ||
932 | /* note position of first page in pvec */ | |
933 | if (first < 0) | |
934 | first = i; | |
935 | dout("%p will write page %p idx %lu\n", | |
936 | inode, page, page->index); | |
2baba250 | 937 | |
5b64640c YZ |
938 | if (atomic_long_inc_return(&fsc->writeback_count) > |
939 | CONGESTION_ON_THRESH( | |
3d14c5d2 YS |
940 | fsc->mount_options->congestion_kb)) { |
941 | set_bdi_congested(&fsc->backing_dev_info, | |
213c99ee | 942 | BLK_RW_ASYNC); |
2baba250 YS |
943 | } |
944 | ||
e5975c7c | 945 | pages[locked_pages] = page; |
1d3576fd | 946 | locked_pages++; |
09cbfeaf | 947 | len += PAGE_SIZE; |
1d3576fd SW |
948 | } |
949 | ||
950 | /* did we get anything? */ | |
951 | if (!locked_pages) | |
952 | goto release_pvec_pages; | |
953 | if (i) { | |
954 | int j; | |
955 | BUG_ON(!locked_pages || first < 0); | |
956 | ||
957 | if (pvec_pages && i == pvec_pages && | |
958 | locked_pages < max_pages) { | |
959 | dout("reached end pvec, trying for more\n"); | |
960 | pagevec_reinit(&pvec); | |
961 | goto get_more_pages; | |
962 | } | |
963 | ||
964 | /* shift unused pages over in the pvec... we | |
965 | * will need to release them below. */ | |
966 | for (j = i; j < pvec_pages; j++) { | |
5b64640c | 967 | dout(" pvec leftover page %p\n", pvec.pages[j]); |
1d3576fd SW |
968 | pvec.pages[j-i+first] = pvec.pages[j]; |
969 | } | |
970 | pvec.nr -= i-first; | |
971 | } | |
972 | ||
5b64640c | 973 | new_request: |
e5975c7c | 974 | offset = page_offset(pages[0]); |
5b64640c YZ |
975 | len = wsize; |
976 | ||
977 | req = ceph_osdc_new_request(&fsc->client->osdc, | |
978 | &ci->i_layout, vino, | |
979 | offset, &len, 0, num_ops, | |
980 | CEPH_OSD_OP_WRITE, | |
981 | CEPH_OSD_FLAG_WRITE | | |
982 | CEPH_OSD_FLAG_ONDISK, | |
983 | snapc, truncate_seq, | |
984 | truncate_size, false); | |
985 | if (IS_ERR(req)) { | |
986 | req = ceph_osdc_new_request(&fsc->client->osdc, | |
987 | &ci->i_layout, vino, | |
988 | offset, &len, 0, | |
989 | min(num_ops, | |
990 | CEPH_OSD_SLAB_OPS), | |
991 | CEPH_OSD_OP_WRITE, | |
992 | CEPH_OSD_FLAG_WRITE | | |
993 | CEPH_OSD_FLAG_ONDISK, | |
994 | snapc, truncate_seq, | |
995 | truncate_size, true); | |
996 | BUG_ON(IS_ERR(req)); | |
e1966b49 | 997 | } |
5b64640c | 998 | BUG_ON(len < page_offset(pages[locked_pages - 1]) + |
09cbfeaf | 999 | PAGE_SIZE - offset); |
5b64640c YZ |
1000 | |
1001 | req->r_callback = writepages_finish; | |
1002 | req->r_inode = inode; | |
1d3576fd | 1003 | |
5b64640c YZ |
1004 | /* Format the osd request message and submit the write */ |
1005 | len = 0; | |
1006 | data_pages = pages; | |
1007 | op_idx = 0; | |
1008 | for (i = 0; i < locked_pages; i++) { | |
1009 | u64 cur_offset = page_offset(pages[i]); | |
1010 | if (offset + len != cur_offset) { | |
1011 | if (op_idx + do_sync + 1 == req->r_num_ops) | |
1012 | break; | |
1013 | osd_req_op_extent_dup_last(req, op_idx, | |
1014 | cur_offset - offset); | |
1015 | dout("writepages got pages at %llu~%llu\n", | |
1016 | offset, len); | |
1017 | osd_req_op_extent_osd_data_pages(req, op_idx, | |
1018 | data_pages, len, 0, | |
a4ce40a9 | 1019 | !!pool, false); |
5b64640c | 1020 | osd_req_op_extent_update(req, op_idx, len); |
e5975c7c | 1021 | |
5b64640c YZ |
1022 | len = 0; |
1023 | offset = cur_offset; | |
1024 | data_pages = pages + i; | |
1025 | op_idx++; | |
1026 | } | |
1027 | ||
1028 | set_page_writeback(pages[i]); | |
09cbfeaf | 1029 | len += PAGE_SIZE; |
5b64640c YZ |
1030 | } |
1031 | ||
1032 | if (snap_size != -1) { | |
1033 | len = min(len, snap_size - offset); | |
1034 | } else if (i == locked_pages) { | |
1035 | /* writepages_finish() clears writeback pages | |
1036 | * according to the data length, so make sure | |
1037 | * data length covers all locked pages */ | |
09cbfeaf | 1038 | u64 min_len = len + 1 - PAGE_SIZE; |
5b64640c YZ |
1039 | len = min(len, (u64)i_size_read(inode) - offset); |
1040 | len = max(len, min_len); | |
1041 | } | |
1042 | dout("writepages got pages at %llu~%llu\n", offset, len); | |
e5975c7c | 1043 | |
5b64640c YZ |
1044 | osd_req_op_extent_osd_data_pages(req, op_idx, data_pages, len, |
1045 | 0, !!pool, false); | |
1046 | osd_req_op_extent_update(req, op_idx, len); | |
e5975c7c | 1047 | |
5b64640c YZ |
1048 | if (do_sync) { |
1049 | op_idx++; | |
1050 | osd_req_op_init(req, op_idx, CEPH_OSD_OP_STARTSYNC, 0); | |
1051 | } | |
1052 | BUG_ON(op_idx + 1 != req->r_num_ops); | |
1053 | ||
1054 | pool = NULL; | |
1055 | if (i < locked_pages) { | |
1056 | BUG_ON(num_ops <= req->r_num_ops); | |
1057 | num_ops -= req->r_num_ops; | |
1058 | num_ops += do_sync; | |
1059 | locked_pages -= i; | |
1060 | ||
1061 | /* allocate new pages array for next request */ | |
1062 | data_pages = pages; | |
1063 | pages = kmalloc(locked_pages * sizeof (*pages), | |
1064 | GFP_NOFS); | |
1065 | if (!pages) { | |
1066 | pool = fsc->wb_pagevec_pool; | |
1067 | pages = mempool_alloc(pool, GFP_NOFS); | |
1068 | BUG_ON(!pages); | |
1069 | } | |
1070 | memcpy(pages, data_pages + i, | |
1071 | locked_pages * sizeof(*pages)); | |
1072 | memset(data_pages + i, 0, | |
1073 | locked_pages * sizeof(*pages)); | |
1074 | } else { | |
1075 | BUG_ON(num_ops != req->r_num_ops); | |
1076 | index = pages[i - 1]->index + 1; | |
1077 | /* request message now owns the pages array */ | |
1078 | pages = NULL; | |
1079 | } | |
e5975c7c | 1080 | |
bb873b53 | 1081 | req->r_mtime = inode->i_mtime; |
9d6fcb08 SW |
1082 | rc = ceph_osdc_start_request(&fsc->client->osdc, req, true); |
1083 | BUG_ON(rc); | |
1d3576fd SW |
1084 | req = NULL; |
1085 | ||
5b64640c YZ |
1086 | wbc->nr_to_write -= i; |
1087 | if (pages) | |
1088 | goto new_request; | |
1089 | ||
1d3576fd SW |
1090 | if (wbc->nr_to_write <= 0) |
1091 | done = 1; | |
1092 | ||
1093 | release_pvec_pages: | |
1094 | dout("pagevec_release on %d pages (%p)\n", (int)pvec.nr, | |
1095 | pvec.nr ? pvec.pages[0] : NULL); | |
1096 | pagevec_release(&pvec); | |
1097 | ||
1098 | if (locked_pages && !done) | |
1099 | goto retry; | |
1100 | } | |
1101 | ||
1102 | if (should_loop && !done) { | |
1103 | /* more to do; loop back to beginning of file */ | |
1104 | dout("writepages looping back to beginning of file\n"); | |
1105 | should_loop = 0; | |
1106 | index = 0; | |
1107 | goto retry; | |
1108 | } | |
1109 | ||
1110 | if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) | |
1111 | mapping->writeback_index = index; | |
1112 | ||
1113 | out: | |
3ed97d63 | 1114 | ceph_osdc_put_request(req); |
1d3576fd SW |
1115 | ceph_put_snap_context(snapc); |
1116 | dout("writepages done, rc = %d\n", rc); | |
1d3576fd SW |
1117 | return rc; |
1118 | } | |
1119 | ||
1120 | ||
1121 | ||
1122 | /* | |
1123 | * See if a given @snapc is either writeable, or already written. | |
1124 | */ | |
1125 | static int context_is_writeable_or_written(struct inode *inode, | |
1126 | struct ceph_snap_context *snapc) | |
1127 | { | |
1128 | struct ceph_snap_context *oldest = get_oldest_context(inode, NULL); | |
6298a337 SW |
1129 | int ret = !oldest || snapc->seq <= oldest->seq; |
1130 | ||
1131 | ceph_put_snap_context(oldest); | |
1132 | return ret; | |
1d3576fd SW |
1133 | } |
1134 | ||
1135 | /* | |
1136 | * We are only allowed to write into/dirty the page if the page is | |
1137 | * clean, or already dirty within the same snap context. | |
8f883c24 SW |
1138 | * |
1139 | * called with page locked. | |
1140 | * return success with page locked, | |
1141 | * or any failure (incl -EAGAIN) with page unlocked. | |
1d3576fd | 1142 | */ |
4af6b225 YS |
1143 | static int ceph_update_writeable_page(struct file *file, |
1144 | loff_t pos, unsigned len, | |
1145 | struct page *page) | |
1d3576fd | 1146 | { |
496ad9aa | 1147 | struct inode *inode = file_inode(file); |
6c93df5d | 1148 | struct ceph_fs_client *fsc = ceph_inode_to_client(inode); |
1d3576fd | 1149 | struct ceph_inode_info *ci = ceph_inode(inode); |
09cbfeaf KS |
1150 | loff_t page_off = pos & PAGE_MASK; |
1151 | int pos_in_page = pos & ~PAGE_MASK; | |
1d3576fd SW |
1152 | int end_in_page = pos_in_page + len; |
1153 | loff_t i_size; | |
1d3576fd | 1154 | int r; |
80e755fe | 1155 | struct ceph_snap_context *snapc, *oldest; |
1d3576fd | 1156 | |
6c93df5d YZ |
1157 | if (ACCESS_ONCE(fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { |
1158 | dout(" page %p forced umount\n", page); | |
1159 | unlock_page(page); | |
1160 | return -EIO; | |
1161 | } | |
1162 | ||
1d3576fd SW |
1163 | retry_locked: |
1164 | /* writepages currently holds page lock, but if we change that later, */ | |
1165 | wait_on_page_writeback(page); | |
1166 | ||
61600ef8 | 1167 | snapc = page_snap_context(page); |
80e755fe | 1168 | if (snapc && snapc != ci->i_head_snapc) { |
1d3576fd SW |
1169 | /* |
1170 | * this page is already dirty in another (older) snap | |
1171 | * context! is it writeable now? | |
1172 | */ | |
80e755fe | 1173 | oldest = get_oldest_context(inode, NULL); |
1d3576fd | 1174 | |
80e755fe | 1175 | if (snapc->seq > oldest->seq) { |
6298a337 | 1176 | ceph_put_snap_context(oldest); |
1d3576fd | 1177 | dout(" page %p snapc %p not current or oldest\n", |
6298a337 | 1178 | page, snapc); |
1d3576fd SW |
1179 | /* |
1180 | * queue for writeback, and wait for snapc to | |
1181 | * be writeable or written | |
1182 | */ | |
6298a337 | 1183 | snapc = ceph_get_snap_context(snapc); |
1d3576fd | 1184 | unlock_page(page); |
3c6f6b79 | 1185 | ceph_queue_writeback(inode); |
a78bbd4b | 1186 | r = wait_event_killable(ci->i_cap_wq, |
1d3576fd SW |
1187 | context_is_writeable_or_written(inode, snapc)); |
1188 | ceph_put_snap_context(snapc); | |
8f883c24 SW |
1189 | if (r == -ERESTARTSYS) |
1190 | return r; | |
4af6b225 | 1191 | return -EAGAIN; |
1d3576fd | 1192 | } |
6298a337 | 1193 | ceph_put_snap_context(oldest); |
1d3576fd SW |
1194 | |
1195 | /* yay, writeable, do it now (without dropping page lock) */ | |
1196 | dout(" page %p snapc %p not current, but oldest\n", | |
1197 | page, snapc); | |
1198 | if (!clear_page_dirty_for_io(page)) | |
1199 | goto retry_locked; | |
1200 | r = writepage_nounlock(page, NULL); | |
1201 | if (r < 0) | |
1202 | goto fail_nosnap; | |
1203 | goto retry_locked; | |
1204 | } | |
1205 | ||
1206 | if (PageUptodate(page)) { | |
1207 | dout(" page %p already uptodate\n", page); | |
1208 | return 0; | |
1209 | } | |
1210 | ||
1211 | /* full page? */ | |
09cbfeaf | 1212 | if (pos_in_page == 0 && len == PAGE_SIZE) |
1d3576fd SW |
1213 | return 0; |
1214 | ||
1215 | /* past end of file? */ | |
99c88e69 | 1216 | i_size = i_size_read(inode); |
1d3576fd | 1217 | |
1d3576fd SW |
1218 | if (page_off >= i_size || |
1219 | (pos_in_page == 0 && (pos+len) >= i_size && | |
09cbfeaf | 1220 | end_in_page - pos_in_page != PAGE_SIZE)) { |
1d3576fd | 1221 | dout(" zeroing %p 0 - %d and %d - %d\n", |
09cbfeaf | 1222 | page, pos_in_page, end_in_page, (int)PAGE_SIZE); |
1d3576fd SW |
1223 | zero_user_segments(page, |
1224 | 0, pos_in_page, | |
09cbfeaf | 1225 | end_in_page, PAGE_SIZE); |
1d3576fd SW |
1226 | return 0; |
1227 | } | |
1228 | ||
1229 | /* we need to read it. */ | |
1d3576fd SW |
1230 | r = readpage_nounlock(file, page); |
1231 | if (r < 0) | |
1232 | goto fail_nosnap; | |
1233 | goto retry_locked; | |
1d3576fd SW |
1234 | fail_nosnap: |
1235 | unlock_page(page); | |
1236 | return r; | |
1237 | } | |
1238 | ||
4af6b225 YS |
1239 | /* |
1240 | * We are only allowed to write into/dirty the page if the page is | |
1241 | * clean, or already dirty within the same snap context. | |
1242 | */ | |
1243 | static int ceph_write_begin(struct file *file, struct address_space *mapping, | |
1244 | loff_t pos, unsigned len, unsigned flags, | |
1245 | struct page **pagep, void **fsdata) | |
1246 | { | |
496ad9aa | 1247 | struct inode *inode = file_inode(file); |
4af6b225 | 1248 | struct page *page; |
09cbfeaf | 1249 | pgoff_t index = pos >> PAGE_SHIFT; |
7971bd92 | 1250 | int r; |
4af6b225 YS |
1251 | |
1252 | do { | |
8f883c24 | 1253 | /* get a page */ |
4af6b225 | 1254 | page = grab_cache_page_write_begin(mapping, index, 0); |
7971bd92 SW |
1255 | if (!page) |
1256 | return -ENOMEM; | |
4af6b225 YS |
1257 | |
1258 | dout("write_begin file %p inode %p page %p %d~%d\n", file, | |
213c99ee | 1259 | inode, page, (int)pos, (int)len); |
4af6b225 YS |
1260 | |
1261 | r = ceph_update_writeable_page(file, pos, len, page); | |
c1d00b2d | 1262 | if (r < 0) |
09cbfeaf | 1263 | put_page(page); |
c1d00b2d TK |
1264 | else |
1265 | *pagep = page; | |
4af6b225 YS |
1266 | } while (r == -EAGAIN); |
1267 | ||
1268 | return r; | |
1269 | } | |
1270 | ||
1d3576fd SW |
1271 | /* |
1272 | * we don't do anything in here that simple_write_end doesn't do | |
5dda377c | 1273 | * except adjust dirty page accounting |
1d3576fd SW |
1274 | */ |
1275 | static int ceph_write_end(struct file *file, struct address_space *mapping, | |
1276 | loff_t pos, unsigned len, unsigned copied, | |
1277 | struct page *page, void *fsdata) | |
1278 | { | |
496ad9aa | 1279 | struct inode *inode = file_inode(file); |
09cbfeaf | 1280 | unsigned from = pos & (PAGE_SIZE - 1); |
1d3576fd SW |
1281 | int check_cap = 0; |
1282 | ||
1283 | dout("write_end file %p inode %p page %p %d~%d (%d)\n", file, | |
1284 | inode, page, (int)pos, (int)copied, (int)len); | |
1285 | ||
1286 | /* zero the stale part of the page if we did a short copy */ | |
1287 | if (copied < len) | |
1288 | zero_user_segment(page, from+copied, len); | |
1289 | ||
1290 | /* did file size increase? */ | |
99c88e69 | 1291 | if (pos+copied > i_size_read(inode)) |
1d3576fd SW |
1292 | check_cap = ceph_inode_set_size(inode, pos+copied); |
1293 | ||
1294 | if (!PageUptodate(page)) | |
1295 | SetPageUptodate(page); | |
1296 | ||
1297 | set_page_dirty(page); | |
1298 | ||
1299 | unlock_page(page); | |
09cbfeaf | 1300 | put_page(page); |
1d3576fd SW |
1301 | |
1302 | if (check_cap) | |
1303 | ceph_check_caps(ceph_inode(inode), CHECK_CAPS_AUTHONLY, NULL); | |
1304 | ||
1305 | return copied; | |
1306 | } | |
1307 | ||
1308 | /* | |
1309 | * we set .direct_IO to indicate direct io is supported, but since we | |
1310 | * intercept O_DIRECT reads and writes early, this function should | |
1311 | * never get called. | |
1312 | */ | |
c8b8e32d | 1313 | static ssize_t ceph_direct_io(struct kiocb *iocb, struct iov_iter *iter) |
1d3576fd SW |
1314 | { |
1315 | WARN_ON(1); | |
1316 | return -EINVAL; | |
1317 | } | |
1318 | ||
1319 | const struct address_space_operations ceph_aops = { | |
1320 | .readpage = ceph_readpage, | |
1321 | .readpages = ceph_readpages, | |
1322 | .writepage = ceph_writepage, | |
1323 | .writepages = ceph_writepages_start, | |
1324 | .write_begin = ceph_write_begin, | |
1325 | .write_end = ceph_write_end, | |
1326 | .set_page_dirty = ceph_set_page_dirty, | |
1327 | .invalidatepage = ceph_invalidatepage, | |
1328 | .releasepage = ceph_releasepage, | |
1329 | .direct_IO = ceph_direct_io, | |
1330 | }; | |
1331 | ||
4f7e89f6 YZ |
1332 | static void ceph_block_sigs(sigset_t *oldset) |
1333 | { | |
1334 | sigset_t mask; | |
1335 | siginitsetinv(&mask, sigmask(SIGKILL)); | |
1336 | sigprocmask(SIG_BLOCK, &mask, oldset); | |
1337 | } | |
1338 | ||
1339 | static void ceph_restore_sigs(sigset_t *oldset) | |
1340 | { | |
1341 | sigprocmask(SIG_SETMASK, oldset, NULL); | |
1342 | } | |
1d3576fd SW |
1343 | |
1344 | /* | |
1345 | * vm ops | |
1346 | */ | |
61f68816 YZ |
1347 | static int ceph_filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
1348 | { | |
1349 | struct inode *inode = file_inode(vma->vm_file); | |
1350 | struct ceph_inode_info *ci = ceph_inode(inode); | |
1351 | struct ceph_file_info *fi = vma->vm_file->private_data; | |
3738daa6 | 1352 | struct page *pinned_page = NULL; |
09cbfeaf | 1353 | loff_t off = vmf->pgoff << PAGE_SHIFT; |
61f68816 | 1354 | int want, got, ret; |
4f7e89f6 YZ |
1355 | sigset_t oldset; |
1356 | ||
1357 | ceph_block_sigs(&oldset); | |
61f68816 YZ |
1358 | |
1359 | dout("filemap_fault %p %llx.%llx %llu~%zd trying to get caps\n", | |
09cbfeaf | 1360 | inode, ceph_vinop(inode), off, (size_t)PAGE_SIZE); |
61f68816 YZ |
1361 | if (fi->fmode & CEPH_FILE_MODE_LAZY) |
1362 | want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO; | |
1363 | else | |
1364 | want = CEPH_CAP_FILE_CACHE; | |
4f7e89f6 YZ |
1365 | |
1366 | got = 0; | |
1367 | ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page); | |
6ce026e4 | 1368 | if (ret < 0) |
4f7e89f6 | 1369 | goto out_restore; |
6ce026e4 | 1370 | |
61f68816 | 1371 | dout("filemap_fault %p %llu~%zd got cap refs on %s\n", |
09cbfeaf | 1372 | inode, off, (size_t)PAGE_SIZE, ceph_cap_string(got)); |
61f68816 | 1373 | |
83701246 YZ |
1374 | if ((got & (CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO)) || |
1375 | ci->i_inline_version == CEPH_INLINE_NONE) | |
1376 | ret = filemap_fault(vma, vmf); | |
1377 | else | |
1378 | ret = -EAGAIN; | |
61f68816 YZ |
1379 | |
1380 | dout("filemap_fault %p %llu~%zd dropping cap refs on %s ret %d\n", | |
09cbfeaf | 1381 | inode, off, (size_t)PAGE_SIZE, ceph_cap_string(got), ret); |
3738daa6 | 1382 | if (pinned_page) |
09cbfeaf | 1383 | put_page(pinned_page); |
61f68816 YZ |
1384 | ceph_put_cap_refs(ci, got); |
1385 | ||
83701246 | 1386 | if (ret != -EAGAIN) |
4f7e89f6 | 1387 | goto out_restore; |
83701246 YZ |
1388 | |
1389 | /* read inline data */ | |
09cbfeaf | 1390 | if (off >= PAGE_SIZE) { |
83701246 YZ |
1391 | /* does not support inline data > PAGE_SIZE */ |
1392 | ret = VM_FAULT_SIGBUS; | |
1393 | } else { | |
1394 | int ret1; | |
1395 | struct address_space *mapping = inode->i_mapping; | |
1396 | struct page *page = find_or_create_page(mapping, 0, | |
c62d2555 MH |
1397 | mapping_gfp_constraint(mapping, |
1398 | ~__GFP_FS)); | |
83701246 YZ |
1399 | if (!page) { |
1400 | ret = VM_FAULT_OOM; | |
4f7e89f6 | 1401 | goto out_inline; |
83701246 YZ |
1402 | } |
1403 | ret1 = __ceph_do_getattr(inode, page, | |
1404 | CEPH_STAT_CAP_INLINE_DATA, true); | |
1405 | if (ret1 < 0 || off >= i_size_read(inode)) { | |
1406 | unlock_page(page); | |
09cbfeaf | 1407 | put_page(page); |
6ce026e4 YZ |
1408 | if (ret1 < 0) |
1409 | ret = ret1; | |
1410 | else | |
1411 | ret = VM_FAULT_SIGBUS; | |
4f7e89f6 | 1412 | goto out_inline; |
83701246 | 1413 | } |
09cbfeaf KS |
1414 | if (ret1 < PAGE_SIZE) |
1415 | zero_user_segment(page, ret1, PAGE_SIZE); | |
83701246 YZ |
1416 | else |
1417 | flush_dcache_page(page); | |
1418 | SetPageUptodate(page); | |
1419 | vmf->page = page; | |
1420 | ret = VM_FAULT_MAJOR | VM_FAULT_LOCKED; | |
4f7e89f6 YZ |
1421 | out_inline: |
1422 | dout("filemap_fault %p %llu~%zd read inline data ret %d\n", | |
1423 | inode, off, (size_t)PAGE_SIZE, ret); | |
83701246 | 1424 | } |
4f7e89f6 YZ |
1425 | out_restore: |
1426 | ceph_restore_sigs(&oldset); | |
6ce026e4 YZ |
1427 | if (ret < 0) |
1428 | ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS; | |
1429 | ||
61f68816 YZ |
1430 | return ret; |
1431 | } | |
1d3576fd SW |
1432 | |
1433 | /* | |
1434 | * Reuse write_begin here for simplicity. | |
1435 | */ | |
1436 | static int ceph_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |
1437 | { | |
496ad9aa | 1438 | struct inode *inode = file_inode(vma->vm_file); |
61f68816 YZ |
1439 | struct ceph_inode_info *ci = ceph_inode(inode); |
1440 | struct ceph_file_info *fi = vma->vm_file->private_data; | |
f66fd9f0 | 1441 | struct ceph_cap_flush *prealloc_cf; |
61f68816 | 1442 | struct page *page = vmf->page; |
6285bc23 | 1443 | loff_t off = page_offset(page); |
61f68816 YZ |
1444 | loff_t size = i_size_read(inode); |
1445 | size_t len; | |
1446 | int want, got, ret; | |
4f7e89f6 | 1447 | sigset_t oldset; |
3ca9c3bd | 1448 | |
f66fd9f0 YZ |
1449 | prealloc_cf = ceph_alloc_cap_flush(); |
1450 | if (!prealloc_cf) | |
6ce026e4 | 1451 | return VM_FAULT_OOM; |
f66fd9f0 | 1452 | |
4f7e89f6 | 1453 | ceph_block_sigs(&oldset); |
f66fd9f0 | 1454 | |
28127bdd YZ |
1455 | if (ci->i_inline_version != CEPH_INLINE_NONE) { |
1456 | struct page *locked_page = NULL; | |
1457 | if (off == 0) { | |
1458 | lock_page(page); | |
1459 | locked_page = page; | |
1460 | } | |
1461 | ret = ceph_uninline_data(vma->vm_file, locked_page); | |
1462 | if (locked_page) | |
1463 | unlock_page(locked_page); | |
6ce026e4 | 1464 | if (ret < 0) |
f66fd9f0 | 1465 | goto out_free; |
28127bdd YZ |
1466 | } |
1467 | ||
09cbfeaf KS |
1468 | if (off + PAGE_SIZE <= size) |
1469 | len = PAGE_SIZE; | |
1d3576fd | 1470 | else |
09cbfeaf | 1471 | len = size & ~PAGE_MASK; |
1d3576fd | 1472 | |
61f68816 YZ |
1473 | dout("page_mkwrite %p %llx.%llx %llu~%zd getting caps i_size %llu\n", |
1474 | inode, ceph_vinop(inode), off, len, size); | |
1475 | if (fi->fmode & CEPH_FILE_MODE_LAZY) | |
1476 | want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO; | |
1477 | else | |
1478 | want = CEPH_CAP_FILE_BUFFER; | |
4f7e89f6 YZ |
1479 | |
1480 | got = 0; | |
1481 | ret = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, off + len, | |
1482 | &got, NULL); | |
6ce026e4 | 1483 | if (ret < 0) |
4f7e89f6 | 1484 | goto out_free; |
6ce026e4 | 1485 | |
61f68816 YZ |
1486 | dout("page_mkwrite %p %llu~%zd got cap refs on %s\n", |
1487 | inode, off, len, ceph_cap_string(got)); | |
1488 | ||
1489 | /* Update time before taking page lock */ | |
1490 | file_update_time(vma->vm_file); | |
4af6b225 | 1491 | |
f0b33df5 YZ |
1492 | do { |
1493 | lock_page(page); | |
4af6b225 | 1494 | |
f0b33df5 YZ |
1495 | if ((off > size) || (page->mapping != inode->i_mapping)) { |
1496 | unlock_page(page); | |
1497 | ret = VM_FAULT_NOPAGE; | |
1498 | break; | |
1499 | } | |
1500 | ||
1501 | ret = ceph_update_writeable_page(vma->vm_file, off, len, page); | |
1502 | if (ret >= 0) { | |
1503 | /* success. we'll keep the page locked. */ | |
1504 | set_page_dirty(page); | |
1505 | ret = VM_FAULT_LOCKED; | |
1506 | } | |
1507 | } while (ret == -EAGAIN); | |
4af6b225 | 1508 | |
28127bdd YZ |
1509 | if (ret == VM_FAULT_LOCKED || |
1510 | ci->i_inline_version != CEPH_INLINE_NONE) { | |
61f68816 YZ |
1511 | int dirty; |
1512 | spin_lock(&ci->i_ceph_lock); | |
28127bdd | 1513 | ci->i_inline_version = CEPH_INLINE_NONE; |
f66fd9f0 YZ |
1514 | dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR, |
1515 | &prealloc_cf); | |
61f68816 YZ |
1516 | spin_unlock(&ci->i_ceph_lock); |
1517 | if (dirty) | |
1518 | __mark_inode_dirty(inode, dirty); | |
1519 | } | |
1520 | ||
1521 | dout("page_mkwrite %p %llu~%zd dropping cap refs on %s ret %d\n", | |
1522 | inode, off, len, ceph_cap_string(got), ret); | |
1523 | ceph_put_cap_refs(ci, got); | |
f66fd9f0 | 1524 | out_free: |
4f7e89f6 | 1525 | ceph_restore_sigs(&oldset); |
f66fd9f0 | 1526 | ceph_free_cap_flush(prealloc_cf); |
6ce026e4 YZ |
1527 | if (ret < 0) |
1528 | ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS; | |
1d3576fd SW |
1529 | return ret; |
1530 | } | |
1531 | ||
31c542a1 YZ |
1532 | void ceph_fill_inline_data(struct inode *inode, struct page *locked_page, |
1533 | char *data, size_t len) | |
1534 | { | |
1535 | struct address_space *mapping = inode->i_mapping; | |
1536 | struct page *page; | |
1537 | ||
1538 | if (locked_page) { | |
1539 | page = locked_page; | |
1540 | } else { | |
1541 | if (i_size_read(inode) == 0) | |
1542 | return; | |
1543 | page = find_or_create_page(mapping, 0, | |
c62d2555 MH |
1544 | mapping_gfp_constraint(mapping, |
1545 | ~__GFP_FS)); | |
31c542a1 YZ |
1546 | if (!page) |
1547 | return; | |
1548 | if (PageUptodate(page)) { | |
1549 | unlock_page(page); | |
09cbfeaf | 1550 | put_page(page); |
31c542a1 YZ |
1551 | return; |
1552 | } | |
1553 | } | |
1554 | ||
0668ff52 | 1555 | dout("fill_inline_data %p %llx.%llx len %zu locked_page %p\n", |
31c542a1 YZ |
1556 | inode, ceph_vinop(inode), len, locked_page); |
1557 | ||
1558 | if (len > 0) { | |
1559 | void *kaddr = kmap_atomic(page); | |
1560 | memcpy(kaddr, data, len); | |
1561 | kunmap_atomic(kaddr); | |
1562 | } | |
1563 | ||
1564 | if (page != locked_page) { | |
09cbfeaf KS |
1565 | if (len < PAGE_SIZE) |
1566 | zero_user_segment(page, len, PAGE_SIZE); | |
31c542a1 YZ |
1567 | else |
1568 | flush_dcache_page(page); | |
1569 | ||
1570 | SetPageUptodate(page); | |
1571 | unlock_page(page); | |
09cbfeaf | 1572 | put_page(page); |
31c542a1 YZ |
1573 | } |
1574 | } | |
1575 | ||
28127bdd YZ |
1576 | int ceph_uninline_data(struct file *filp, struct page *locked_page) |
1577 | { | |
1578 | struct inode *inode = file_inode(filp); | |
1579 | struct ceph_inode_info *ci = ceph_inode(inode); | |
1580 | struct ceph_fs_client *fsc = ceph_inode_to_client(inode); | |
1581 | struct ceph_osd_request *req; | |
1582 | struct page *page = NULL; | |
1583 | u64 len, inline_version; | |
1584 | int err = 0; | |
1585 | bool from_pagecache = false; | |
1586 | ||
1587 | spin_lock(&ci->i_ceph_lock); | |
1588 | inline_version = ci->i_inline_version; | |
1589 | spin_unlock(&ci->i_ceph_lock); | |
1590 | ||
1591 | dout("uninline_data %p %llx.%llx inline_version %llu\n", | |
1592 | inode, ceph_vinop(inode), inline_version); | |
1593 | ||
1594 | if (inline_version == 1 || /* initial version, no data */ | |
1595 | inline_version == CEPH_INLINE_NONE) | |
1596 | goto out; | |
1597 | ||
1598 | if (locked_page) { | |
1599 | page = locked_page; | |
1600 | WARN_ON(!PageUptodate(page)); | |
1601 | } else if (ceph_caps_issued(ci) & | |
1602 | (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) { | |
1603 | page = find_get_page(inode->i_mapping, 0); | |
1604 | if (page) { | |
1605 | if (PageUptodate(page)) { | |
1606 | from_pagecache = true; | |
1607 | lock_page(page); | |
1608 | } else { | |
09cbfeaf | 1609 | put_page(page); |
28127bdd YZ |
1610 | page = NULL; |
1611 | } | |
1612 | } | |
1613 | } | |
1614 | ||
1615 | if (page) { | |
1616 | len = i_size_read(inode); | |
09cbfeaf KS |
1617 | if (len > PAGE_SIZE) |
1618 | len = PAGE_SIZE; | |
28127bdd YZ |
1619 | } else { |
1620 | page = __page_cache_alloc(GFP_NOFS); | |
1621 | if (!page) { | |
1622 | err = -ENOMEM; | |
1623 | goto out; | |
1624 | } | |
1625 | err = __ceph_do_getattr(inode, page, | |
1626 | CEPH_STAT_CAP_INLINE_DATA, true); | |
1627 | if (err < 0) { | |
1628 | /* no inline data */ | |
1629 | if (err == -ENODATA) | |
1630 | err = 0; | |
1631 | goto out; | |
1632 | } | |
1633 | len = err; | |
1634 | } | |
1635 | ||
1636 | req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout, | |
1637 | ceph_vino(inode), 0, &len, 0, 1, | |
1638 | CEPH_OSD_OP_CREATE, | |
1639 | CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE, | |
34b759b4 | 1640 | NULL, 0, 0, false); |
28127bdd YZ |
1641 | if (IS_ERR(req)) { |
1642 | err = PTR_ERR(req); | |
1643 | goto out; | |
1644 | } | |
1645 | ||
bb873b53 | 1646 | req->r_mtime = inode->i_mtime; |
28127bdd YZ |
1647 | err = ceph_osdc_start_request(&fsc->client->osdc, req, false); |
1648 | if (!err) | |
1649 | err = ceph_osdc_wait_request(&fsc->client->osdc, req); | |
1650 | ceph_osdc_put_request(req); | |
1651 | if (err < 0) | |
1652 | goto out; | |
1653 | ||
1654 | req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout, | |
1655 | ceph_vino(inode), 0, &len, 1, 3, | |
1656 | CEPH_OSD_OP_WRITE, | |
1657 | CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE, | |
34b759b4 ID |
1658 | NULL, ci->i_truncate_seq, |
1659 | ci->i_truncate_size, false); | |
28127bdd YZ |
1660 | if (IS_ERR(req)) { |
1661 | err = PTR_ERR(req); | |
1662 | goto out; | |
1663 | } | |
1664 | ||
1665 | osd_req_op_extent_osd_data_pages(req, 1, &page, len, 0, false, false); | |
1666 | ||
ec137c10 YZ |
1667 | { |
1668 | __le64 xattr_buf = cpu_to_le64(inline_version); | |
1669 | err = osd_req_op_xattr_init(req, 0, CEPH_OSD_OP_CMPXATTR, | |
1670 | "inline_version", &xattr_buf, | |
1671 | sizeof(xattr_buf), | |
1672 | CEPH_OSD_CMPXATTR_OP_GT, | |
1673 | CEPH_OSD_CMPXATTR_MODE_U64); | |
1674 | if (err) | |
1675 | goto out_put; | |
1676 | } | |
1677 | ||
1678 | { | |
1679 | char xattr_buf[32]; | |
1680 | int xattr_len = snprintf(xattr_buf, sizeof(xattr_buf), | |
1681 | "%llu", inline_version); | |
1682 | err = osd_req_op_xattr_init(req, 2, CEPH_OSD_OP_SETXATTR, | |
1683 | "inline_version", | |
1684 | xattr_buf, xattr_len, 0, 0); | |
1685 | if (err) | |
1686 | goto out_put; | |
1687 | } | |
28127bdd | 1688 | |
bb873b53 | 1689 | req->r_mtime = inode->i_mtime; |
28127bdd YZ |
1690 | err = ceph_osdc_start_request(&fsc->client->osdc, req, false); |
1691 | if (!err) | |
1692 | err = ceph_osdc_wait_request(&fsc->client->osdc, req); | |
1693 | out_put: | |
1694 | ceph_osdc_put_request(req); | |
1695 | if (err == -ECANCELED) | |
1696 | err = 0; | |
1697 | out: | |
1698 | if (page && page != locked_page) { | |
1699 | if (from_pagecache) { | |
1700 | unlock_page(page); | |
09cbfeaf | 1701 | put_page(page); |
28127bdd YZ |
1702 | } else |
1703 | __free_pages(page, 0); | |
1704 | } | |
1705 | ||
1706 | dout("uninline_data %p %llx.%llx inline_version %llu = %d\n", | |
1707 | inode, ceph_vinop(inode), inline_version, err); | |
1708 | return err; | |
1709 | } | |
1710 | ||
7cbea8dc | 1711 | static const struct vm_operations_struct ceph_vmops = { |
61f68816 | 1712 | .fault = ceph_filemap_fault, |
1d3576fd SW |
1713 | .page_mkwrite = ceph_page_mkwrite, |
1714 | }; | |
1715 | ||
1716 | int ceph_mmap(struct file *file, struct vm_area_struct *vma) | |
1717 | { | |
1718 | struct address_space *mapping = file->f_mapping; | |
1719 | ||
1720 | if (!mapping->a_ops->readpage) | |
1721 | return -ENOEXEC; | |
1722 | file_accessed(file); | |
1723 | vma->vm_ops = &ceph_vmops; | |
1d3576fd SW |
1724 | return 0; |
1725 | } | |
10183a69 YZ |
1726 | |
1727 | enum { | |
1728 | POOL_READ = 1, | |
1729 | POOL_WRITE = 2, | |
1730 | }; | |
1731 | ||
779fe0fb YZ |
1732 | static int __ceph_pool_perm_get(struct ceph_inode_info *ci, |
1733 | s64 pool, struct ceph_string *pool_ns) | |
10183a69 YZ |
1734 | { |
1735 | struct ceph_fs_client *fsc = ceph_inode_to_client(&ci->vfs_inode); | |
1736 | struct ceph_mds_client *mdsc = fsc->mdsc; | |
1737 | struct ceph_osd_request *rd_req = NULL, *wr_req = NULL; | |
1738 | struct rb_node **p, *parent; | |
1739 | struct ceph_pool_perm *perm; | |
1740 | struct page **pages; | |
779fe0fb | 1741 | size_t pool_ns_len; |
10183a69 YZ |
1742 | int err = 0, err2 = 0, have = 0; |
1743 | ||
1744 | down_read(&mdsc->pool_perm_rwsem); | |
1745 | p = &mdsc->pool_perm_tree.rb_node; | |
1746 | while (*p) { | |
1747 | perm = rb_entry(*p, struct ceph_pool_perm, node); | |
1748 | if (pool < perm->pool) | |
1749 | p = &(*p)->rb_left; | |
1750 | else if (pool > perm->pool) | |
1751 | p = &(*p)->rb_right; | |
1752 | else { | |
779fe0fb YZ |
1753 | int ret = ceph_compare_string(pool_ns, |
1754 | perm->pool_ns, | |
1755 | perm->pool_ns_len); | |
1756 | if (ret < 0) | |
1757 | p = &(*p)->rb_left; | |
1758 | else if (ret > 0) | |
1759 | p = &(*p)->rb_right; | |
1760 | else { | |
1761 | have = perm->perm; | |
1762 | break; | |
1763 | } | |
10183a69 YZ |
1764 | } |
1765 | } | |
1766 | up_read(&mdsc->pool_perm_rwsem); | |
1767 | if (*p) | |
1768 | goto out; | |
1769 | ||
779fe0fb YZ |
1770 | if (pool_ns) |
1771 | dout("__ceph_pool_perm_get pool %lld ns %.*s no perm cached\n", | |
1772 | pool, (int)pool_ns->len, pool_ns->str); | |
1773 | else | |
1774 | dout("__ceph_pool_perm_get pool %lld no perm cached\n", pool); | |
10183a69 YZ |
1775 | |
1776 | down_write(&mdsc->pool_perm_rwsem); | |
779fe0fb | 1777 | p = &mdsc->pool_perm_tree.rb_node; |
10183a69 YZ |
1778 | parent = NULL; |
1779 | while (*p) { | |
1780 | parent = *p; | |
1781 | perm = rb_entry(parent, struct ceph_pool_perm, node); | |
1782 | if (pool < perm->pool) | |
1783 | p = &(*p)->rb_left; | |
1784 | else if (pool > perm->pool) | |
1785 | p = &(*p)->rb_right; | |
1786 | else { | |
779fe0fb YZ |
1787 | int ret = ceph_compare_string(pool_ns, |
1788 | perm->pool_ns, | |
1789 | perm->pool_ns_len); | |
1790 | if (ret < 0) | |
1791 | p = &(*p)->rb_left; | |
1792 | else if (ret > 0) | |
1793 | p = &(*p)->rb_right; | |
1794 | else { | |
1795 | have = perm->perm; | |
1796 | break; | |
1797 | } | |
10183a69 YZ |
1798 | } |
1799 | } | |
1800 | if (*p) { | |
1801 | up_write(&mdsc->pool_perm_rwsem); | |
1802 | goto out; | |
1803 | } | |
1804 | ||
34b759b4 | 1805 | rd_req = ceph_osdc_alloc_request(&fsc->client->osdc, NULL, |
10183a69 YZ |
1806 | 1, false, GFP_NOFS); |
1807 | if (!rd_req) { | |
1808 | err = -ENOMEM; | |
1809 | goto out_unlock; | |
1810 | } | |
1811 | ||
1812 | rd_req->r_flags = CEPH_OSD_FLAG_READ; | |
1813 | osd_req_op_init(rd_req, 0, CEPH_OSD_OP_STAT, 0); | |
1814 | rd_req->r_base_oloc.pool = pool; | |
779fe0fb YZ |
1815 | if (pool_ns) |
1816 | rd_req->r_base_oloc.pool_ns = ceph_get_string(pool_ns); | |
d30291b9 | 1817 | ceph_oid_printf(&rd_req->r_base_oid, "%llx.00000000", ci->i_vino.ino); |
10183a69 | 1818 | |
13d1ad16 ID |
1819 | err = ceph_osdc_alloc_messages(rd_req, GFP_NOFS); |
1820 | if (err) | |
1821 | goto out_unlock; | |
10183a69 | 1822 | |
34b759b4 | 1823 | wr_req = ceph_osdc_alloc_request(&fsc->client->osdc, NULL, |
10183a69 YZ |
1824 | 1, false, GFP_NOFS); |
1825 | if (!wr_req) { | |
1826 | err = -ENOMEM; | |
1827 | goto out_unlock; | |
1828 | } | |
1829 | ||
fe5da05e | 1830 | wr_req->r_flags = CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ACK; |
10183a69 | 1831 | osd_req_op_init(wr_req, 0, CEPH_OSD_OP_CREATE, CEPH_OSD_OP_FLAG_EXCL); |
63244fa1 | 1832 | ceph_oloc_copy(&wr_req->r_base_oloc, &rd_req->r_base_oloc); |
d30291b9 | 1833 | ceph_oid_copy(&wr_req->r_base_oid, &rd_req->r_base_oid); |
10183a69 | 1834 | |
13d1ad16 ID |
1835 | err = ceph_osdc_alloc_messages(wr_req, GFP_NOFS); |
1836 | if (err) | |
1837 | goto out_unlock; | |
10183a69 YZ |
1838 | |
1839 | /* one page should be large enough for STAT data */ | |
1840 | pages = ceph_alloc_page_vector(1, GFP_KERNEL); | |
1841 | if (IS_ERR(pages)) { | |
1842 | err = PTR_ERR(pages); | |
1843 | goto out_unlock; | |
1844 | } | |
1845 | ||
1846 | osd_req_op_raw_data_in_pages(rd_req, 0, pages, PAGE_SIZE, | |
1847 | 0, false, true); | |
10183a69 YZ |
1848 | err = ceph_osdc_start_request(&fsc->client->osdc, rd_req, false); |
1849 | ||
bb873b53 | 1850 | wr_req->r_mtime = ci->vfs_inode.i_mtime; |
10183a69 YZ |
1851 | err2 = ceph_osdc_start_request(&fsc->client->osdc, wr_req, false); |
1852 | ||
1853 | if (!err) | |
1854 | err = ceph_osdc_wait_request(&fsc->client->osdc, rd_req); | |
1855 | if (!err2) | |
1856 | err2 = ceph_osdc_wait_request(&fsc->client->osdc, wr_req); | |
1857 | ||
1858 | if (err >= 0 || err == -ENOENT) | |
1859 | have |= POOL_READ; | |
1860 | else if (err != -EPERM) | |
1861 | goto out_unlock; | |
1862 | ||
1863 | if (err2 == 0 || err2 == -EEXIST) | |
1864 | have |= POOL_WRITE; | |
1865 | else if (err2 != -EPERM) { | |
1866 | err = err2; | |
1867 | goto out_unlock; | |
1868 | } | |
1869 | ||
779fe0fb YZ |
1870 | pool_ns_len = pool_ns ? pool_ns->len : 0; |
1871 | perm = kmalloc(sizeof(*perm) + pool_ns_len + 1, GFP_NOFS); | |
10183a69 YZ |
1872 | if (!perm) { |
1873 | err = -ENOMEM; | |
1874 | goto out_unlock; | |
1875 | } | |
1876 | ||
1877 | perm->pool = pool; | |
1878 | perm->perm = have; | |
779fe0fb YZ |
1879 | perm->pool_ns_len = pool_ns_len; |
1880 | if (pool_ns_len > 0) | |
1881 | memcpy(perm->pool_ns, pool_ns->str, pool_ns_len); | |
1882 | perm->pool_ns[pool_ns_len] = 0; | |
1883 | ||
10183a69 YZ |
1884 | rb_link_node(&perm->node, parent, p); |
1885 | rb_insert_color(&perm->node, &mdsc->pool_perm_tree); | |
1886 | err = 0; | |
1887 | out_unlock: | |
1888 | up_write(&mdsc->pool_perm_rwsem); | |
1889 | ||
3ed97d63 ID |
1890 | ceph_osdc_put_request(rd_req); |
1891 | ceph_osdc_put_request(wr_req); | |
10183a69 YZ |
1892 | out: |
1893 | if (!err) | |
1894 | err = have; | |
779fe0fb YZ |
1895 | if (pool_ns) |
1896 | dout("__ceph_pool_perm_get pool %lld ns %.*s result = %d\n", | |
1897 | pool, (int)pool_ns->len, pool_ns->str, err); | |
1898 | else | |
1899 | dout("__ceph_pool_perm_get pool %lld result = %d\n", pool, err); | |
10183a69 YZ |
1900 | return err; |
1901 | } | |
1902 | ||
1903 | int ceph_pool_perm_check(struct ceph_inode_info *ci, int need) | |
1904 | { | |
7627151e | 1905 | s64 pool; |
779fe0fb | 1906 | struct ceph_string *pool_ns; |
10183a69 YZ |
1907 | int ret, flags; |
1908 | ||
1909 | if (ceph_test_mount_opt(ceph_inode_to_client(&ci->vfs_inode), | |
1910 | NOPOOLPERM)) | |
1911 | return 0; | |
1912 | ||
1913 | spin_lock(&ci->i_ceph_lock); | |
1914 | flags = ci->i_ceph_flags; | |
7627151e | 1915 | pool = ci->i_layout.pool_id; |
10183a69 YZ |
1916 | spin_unlock(&ci->i_ceph_lock); |
1917 | check: | |
1918 | if (flags & CEPH_I_POOL_PERM) { | |
1919 | if ((need & CEPH_CAP_FILE_RD) && !(flags & CEPH_I_POOL_RD)) { | |
7627151e | 1920 | dout("ceph_pool_perm_check pool %lld no read perm\n", |
10183a69 YZ |
1921 | pool); |
1922 | return -EPERM; | |
1923 | } | |
1924 | if ((need & CEPH_CAP_FILE_WR) && !(flags & CEPH_I_POOL_WR)) { | |
7627151e | 1925 | dout("ceph_pool_perm_check pool %lld no write perm\n", |
10183a69 YZ |
1926 | pool); |
1927 | return -EPERM; | |
1928 | } | |
1929 | return 0; | |
1930 | } | |
1931 | ||
779fe0fb YZ |
1932 | pool_ns = ceph_try_get_string(ci->i_layout.pool_ns); |
1933 | ret = __ceph_pool_perm_get(ci, pool, pool_ns); | |
1934 | ceph_put_string(pool_ns); | |
10183a69 YZ |
1935 | if (ret < 0) |
1936 | return ret; | |
1937 | ||
1938 | flags = CEPH_I_POOL_PERM; | |
1939 | if (ret & POOL_READ) | |
1940 | flags |= CEPH_I_POOL_RD; | |
1941 | if (ret & POOL_WRITE) | |
1942 | flags |= CEPH_I_POOL_WR; | |
1943 | ||
1944 | spin_lock(&ci->i_ceph_lock); | |
779fe0fb YZ |
1945 | if (pool == ci->i_layout.pool_id && |
1946 | pool_ns == rcu_dereference_raw(ci->i_layout.pool_ns)) { | |
1947 | ci->i_ceph_flags |= flags; | |
10183a69 | 1948 | } else { |
7627151e | 1949 | pool = ci->i_layout.pool_id; |
10183a69 YZ |
1950 | flags = ci->i_ceph_flags; |
1951 | } | |
1952 | spin_unlock(&ci->i_ceph_lock); | |
1953 | goto check; | |
1954 | } | |
1955 | ||
1956 | void ceph_pool_perm_destroy(struct ceph_mds_client *mdsc) | |
1957 | { | |
1958 | struct ceph_pool_perm *perm; | |
1959 | struct rb_node *n; | |
1960 | ||
1961 | while (!RB_EMPTY_ROOT(&mdsc->pool_perm_tree)) { | |
1962 | n = rb_first(&mdsc->pool_perm_tree); | |
1963 | perm = rb_entry(n, struct ceph_pool_perm, node); | |
1964 | rb_erase(n, &mdsc->pool_perm_tree); | |
1965 | kfree(perm); | |
1966 | } | |
1967 | } |