1 #include <linux/ceph/ceph_debug.h>
3 #include <linux/backing-dev.h>
6 #include <linux/pagemap.h>
7 #include <linux/writeback.h> /* generic_writepages */
8 #include <linux/slab.h>
9 #include <linux/pagevec.h>
10 #include <linux/task_io_accounting_ops.h>
13 #include "mds_client.h"
15 #include <linux/ceph/osd_client.h>
18 * Ceph address space ops.
20 * There are a few funny things going on here.
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.
27 * Similarly, struct ceph_inode_info maintains a set of counters to
28 * count dirty pages on the inode. In the absence of snapshots,
29 * i_wrbuffer_ref == i_wrbuffer_ref_head == the dirty page count.
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.
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
49 * Invalidate and so forth must take care to ensure the dirty page
50 * accounting is preserved.
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))
58 static inline struct ceph_snap_context *page_snap_context(struct page *page)
60 if (PagePrivate(page))
61 return (void *)page->private;
66 * Dirty a page. Optimistically adjust accounting, on the assumption
67 * that we won't race with invalidate. If we do, readjust.
69 static int ceph_set_page_dirty(struct page *page)
71 struct address_space *mapping = page->mapping;
73 struct ceph_inode_info *ci;
74 struct ceph_snap_context *snapc;
77 if (unlikely(!mapping))
78 return !TestSetPageDirty(page);
80 if (PageDirty(page)) {
81 dout("%p set_page_dirty %p idx %lu -- already dirty\n",
82 mapping->host, page, page->index);
83 BUG_ON(!PagePrivate(page));
87 inode = mapping->host;
88 ci = ceph_inode(inode);
91 spin_lock(&ci->i_ceph_lock);
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,
98 snapc = ceph_get_snap_context(capsnap->context);
99 capsnap->dirty_pages++;
101 BUG_ON(!ci->i_head_snapc);
102 snapc = ceph_get_snap_context(ci->i_head_snapc);
103 ++ci->i_wrbuffer_ref_head;
105 if (ci->i_wrbuffer_ref == 0)
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);
114 spin_unlock(&ci->i_ceph_lock);
117 * Reference snap context in page->private. Also set
118 * PagePrivate so that we get invalidatepage callback.
120 BUG_ON(PagePrivate(page));
121 page->private = (unsigned long)snapc;
122 SetPagePrivate(page);
124 ret = __set_page_dirty_nobuffers(page);
125 WARN_ON(!PageLocked(page));
126 WARN_ON(!page->mapping);
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
136 static void ceph_invalidatepage(struct page *page, unsigned int offset,
140 struct ceph_inode_info *ci;
141 struct ceph_snap_context *snapc = page_snap_context(page);
143 inode = page->mapping->host;
144 ci = ceph_inode(inode);
146 if (offset != 0 || length != PAGE_CACHE_SIZE) {
147 dout("%p invalidatepage %p idx %lu partial dirty page %u~%u\n",
148 inode, page, page->index, offset, length);
152 ceph_invalidate_fscache_page(inode, page);
154 if (!PagePrivate(page))
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.
162 if (!PageDirty(page))
163 pr_err("%p invalidatepage %p page not dirty\n", inode, page);
165 ClearPageChecked(page);
167 dout("%p invalidatepage %p idx %lu full dirty page\n",
168 inode, page, page->index);
170 ceph_put_wrbuffer_cap_refs(ci, 1, snapc);
171 ceph_put_snap_context(snapc);
173 ClearPagePrivate(page);
176 static int ceph_releasepage(struct page *page, gfp_t g)
178 struct inode *inode = page->mapping ? page->mapping->host : NULL;
179 dout("%p releasepage %p idx %lu\n", inode, page, page->index);
180 WARN_ON(PageDirty(page));
182 /* Can we release the page from the cache? */
183 if (!ceph_release_fscache_page(page, g))
186 return !PagePrivate(page);
190 * read a single page, without unlocking it.
192 static int readpage_nounlock(struct file *filp, struct page *page)
194 struct inode *inode = file_inode(filp);
195 struct ceph_inode_info *ci = ceph_inode(inode);
196 struct ceph_osd_client *osdc =
197 &ceph_inode_to_client(inode)->client->osdc;
199 u64 off = page_offset(page);
200 u64 len = PAGE_CACHE_SIZE;
202 if (off >= i_size_read(inode)) {
203 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
204 SetPageUptodate(page);
208 if (ci->i_inline_version != CEPH_INLINE_NONE) {
210 * Uptodate inline data should have been added
211 * into page cache while getting Fcr caps.
215 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
216 SetPageUptodate(page);
220 err = ceph_readpage_from_fscache(inode, page);
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,
228 ci->i_truncate_seq, ci->i_truncate_size,
234 ceph_fscache_readpage_cancel(inode, page);
237 if (err < PAGE_CACHE_SIZE)
238 /* zero fill remainder of page */
239 zero_user_segment(page, err, PAGE_CACHE_SIZE);
241 flush_dcache_page(page);
243 SetPageUptodate(page);
244 ceph_readpage_to_fscache(inode, page);
247 return err < 0 ? err : 0;
250 static int ceph_readpage(struct file *filp, struct page *page)
252 int r = readpage_nounlock(filp, page);
258 * Finish an async read(ahead) op.
260 static void finish_read(struct ceph_osd_request *req, struct ceph_msg *msg)
262 struct inode *inode = req->r_inode;
263 struct ceph_osd_data *osd_data;
264 int rc = req->r_result;
265 int bytes = le32_to_cpu(msg->hdr.data_len);
269 dout("finish_read %p req %p rc %d bytes %d\n", inode, req, rc, bytes);
271 /* unlock all pages, zeroing any data we didn't read */
272 osd_data = osd_req_op_extent_osd_data(req, 0);
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);
276 for (i = 0; i < num_pages; i++) {
277 struct page *page = osd_data->pages[i];
281 if (bytes < (int)PAGE_CACHE_SIZE) {
282 /* zero (remainder of) page */
283 int s = bytes < 0 ? 0 : bytes;
284 zero_user_segment(page, s, PAGE_CACHE_SIZE);
286 dout("finish_read %p uptodate %p idx %lu\n", inode, page,
288 flush_dcache_page(page);
289 SetPageUptodate(page);
290 ceph_readpage_to_fscache(inode, page);
293 page_cache_release(page);
294 bytes -= PAGE_CACHE_SIZE;
296 kfree(osd_data->pages);
299 static void ceph_unlock_page_vector(struct page **pages, int num_pages)
303 for (i = 0; i < num_pages; i++)
304 unlock_page(pages[i]);
308 * start an async read(ahead) operation. return nr_pages we submitted
309 * a read for on success, or negative error code.
311 static int start_read(struct inode *inode, struct list_head *page_list, int max)
313 struct ceph_osd_client *osdc =
314 &ceph_inode_to_client(inode)->client->osdc;
315 struct ceph_inode_info *ci = ceph_inode(inode);
316 struct page *page = list_entry(page_list->prev, struct page, lru);
317 struct ceph_vino vino;
318 struct ceph_osd_request *req;
327 off = (u64) page_offset(page);
330 next_index = page->index;
331 list_for_each_entry_reverse(page, page_list, lru) {
332 if (page->index != next_index)
336 if (max && nr_pages == max)
339 len = nr_pages << PAGE_CACHE_SHIFT;
340 dout("start_read %p nr_pages %d is %lld~%lld\n", inode, nr_pages,
342 vino = ceph_vino(inode);
343 req = ceph_osdc_new_request(osdc, &ci->i_layout, vino, off, &len,
344 0, 1, CEPH_OSD_OP_READ,
345 CEPH_OSD_FLAG_READ, NULL,
346 ci->i_truncate_seq, ci->i_truncate_size,
351 /* build page vector */
352 nr_pages = calc_pages_for(0, len);
353 pages = kmalloc(sizeof(*pages) * nr_pages, GFP_NOFS);
357 for (i = 0; i < nr_pages; ++i) {
358 page = list_entry(page_list->prev, struct page, lru);
359 BUG_ON(PageLocked(page));
360 list_del(&page->lru);
362 dout("start_read %p adding %p idx %lu\n", inode, page,
364 if (add_to_page_cache_lru(page, &inode->i_data, page->index,
366 ceph_fscache_uncache_page(inode, page);
367 page_cache_release(page);
368 dout("start_read %p add_to_page_cache failed %p\n",
375 osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0, false, false);
376 req->r_callback = finish_read;
377 req->r_inode = inode;
379 ceph_osdc_build_request(req, off, NULL, vino.snap, NULL);
381 dout("start_read %p starting %p %lld~%lld\n", inode, req, off, len);
382 ret = ceph_osdc_start_request(osdc, req, false);
385 ceph_osdc_put_request(req);
389 ceph_unlock_page_vector(pages, nr_pages);
390 ceph_release_page_vector(pages, nr_pages);
392 ceph_osdc_put_request(req);
398 * Read multiple pages. Leave pages we don't read + unlock in page_list;
399 * the caller (VM) cleans them up.
401 static int ceph_readpages(struct file *file, struct address_space *mapping,
402 struct list_head *page_list, unsigned nr_pages)
404 struct inode *inode = file_inode(file);
405 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
409 if (ceph_inode(inode)->i_inline_version != CEPH_INLINE_NONE)
412 rc = ceph_readpages_from_fscache(mapping->host, mapping, page_list,
418 if (fsc->mount_options->rsize >= PAGE_CACHE_SIZE)
419 max = (fsc->mount_options->rsize + PAGE_CACHE_SIZE - 1)
422 dout("readpages %p file %p nr_pages %d max %d\n", inode,
425 while (!list_empty(page_list)) {
426 rc = start_read(inode, page_list, max);
432 ceph_fscache_readpages_cancel(inode, page_list);
434 dout("readpages %p file %p ret %d\n", inode, file, rc);
439 * Get ref for the oldest snapc for an inode with dirty data... that is, the
440 * only snap context we are allowed to write back.
442 static struct ceph_snap_context *get_oldest_context(struct inode *inode,
445 struct ceph_inode_info *ci = ceph_inode(inode);
446 struct ceph_snap_context *snapc = NULL;
447 struct ceph_cap_snap *capsnap = NULL;
449 spin_lock(&ci->i_ceph_lock);
450 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) {
451 dout(" cap_snap %p snapc %p has %d dirty pages\n", capsnap,
452 capsnap->context, capsnap->dirty_pages);
453 if (capsnap->dirty_pages) {
454 snapc = ceph_get_snap_context(capsnap->context);
456 *snap_size = capsnap->size;
460 if (!snapc && ci->i_wrbuffer_ref_head) {
461 snapc = ceph_get_snap_context(ci->i_head_snapc);
462 dout(" head snapc %p has %d dirty pages\n",
463 snapc, ci->i_wrbuffer_ref_head);
465 spin_unlock(&ci->i_ceph_lock);
470 * Write a single page, but leave the page locked.
472 * If we get a write error, set the page error bit, but still adjust the
473 * dirty page accounting (i.e., page is no longer dirty).
475 static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
478 struct ceph_inode_info *ci;
479 struct ceph_fs_client *fsc;
480 struct ceph_osd_client *osdc;
481 struct ceph_snap_context *snapc, *oldest;
482 loff_t page_off = page_offset(page);
484 u64 truncate_size, snap_size = 0;
486 int err = 0, len = PAGE_CACHE_SIZE;
488 dout("writepage %p idx %lu\n", page, page->index);
490 if (!page->mapping || !page->mapping->host) {
491 dout("writepage %p - no mapping\n", page);
494 inode = page->mapping->host;
495 ci = ceph_inode(inode);
496 fsc = ceph_inode_to_client(inode);
497 osdc = &fsc->client->osdc;
499 /* verify this is a writeable snap context */
500 snapc = page_snap_context(page);
502 dout("writepage %p page %p not dirty?\n", inode, page);
505 oldest = get_oldest_context(inode, &snap_size);
506 if (snapc->seq > oldest->seq) {
507 dout("writepage %p page %p snapc %p not writeable - noop\n",
509 /* we should only noop if called by kswapd */
510 WARN_ON((current->flags & PF_MEMALLOC) == 0);
511 ceph_put_snap_context(oldest);
514 ceph_put_snap_context(oldest);
516 spin_lock(&ci->i_ceph_lock);
517 truncate_seq = ci->i_truncate_seq;
518 truncate_size = ci->i_truncate_size;
520 snap_size = i_size_read(inode);
521 spin_unlock(&ci->i_ceph_lock);
523 /* is this a partial page at end of file? */
524 if (page_off >= snap_size) {
525 dout("%p page eof %llu\n", page, snap_size);
528 if (snap_size < page_off + len)
529 len = snap_size - page_off;
531 dout("writepage %p page %p index %lu on %llu~%u snapc %p\n",
532 inode, page, page->index, page_off, len, snapc);
534 writeback_stat = atomic_long_inc_return(&fsc->writeback_count);
536 CONGESTION_ON_THRESH(fsc->mount_options->congestion_kb))
537 set_bdi_congested(&fsc->backing_dev_info, BLK_RW_ASYNC);
539 ceph_readpage_to_fscache(inode, page);
541 set_page_writeback(page);
542 err = ceph_osdc_writepages(osdc, ceph_vino(inode),
543 &ci->i_layout, snapc,
545 truncate_seq, truncate_size,
546 &inode->i_mtime, &page, 1);
548 dout("writepage setting page/mapping error %d %p\n", err, page);
550 mapping_set_error(&inode->i_data, err);
552 wbc->pages_skipped++;
554 dout("writepage cleaned page %p\n", page);
555 err = 0; /* vfs expects us to return 0 */
558 ClearPagePrivate(page);
559 end_page_writeback(page);
560 ceph_put_wrbuffer_cap_refs(ci, 1, snapc);
561 ceph_put_snap_context(snapc); /* page's reference */
566 static int ceph_writepage(struct page *page, struct writeback_control *wbc)
569 struct inode *inode = page->mapping->host;
572 err = writepage_nounlock(page, wbc);
580 * lame release_pages helper. release_pages() isn't exported to
583 static void ceph_release_pages(struct page **pages, int num)
588 pagevec_init(&pvec, 0);
589 for (i = 0; i < num; i++) {
590 if (pagevec_add(&pvec, pages[i]) == 0)
591 pagevec_release(&pvec);
593 pagevec_release(&pvec);
597 * async writeback completion handler.
599 * If we get an error, set the mapping error bit, but not the individual
602 static void writepages_finish(struct ceph_osd_request *req,
603 struct ceph_msg *msg)
605 struct inode *inode = req->r_inode;
606 struct ceph_inode_info *ci = ceph_inode(inode);
607 struct ceph_osd_data *osd_data;
612 struct ceph_snap_context *snapc = req->r_snapc;
613 struct address_space *mapping = inode->i_mapping;
614 int rc = req->r_result;
615 u64 bytes = req->r_ops[0].extent.length;
616 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
618 unsigned issued = ceph_caps_issued(ci);
620 osd_data = osd_req_op_extent_osd_data(req, 0);
621 BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGES);
622 num_pages = calc_pages_for((u64)osd_data->alignment,
623 (u64)osd_data->length);
626 * Assume we wrote the pages we originally sent. The
627 * osd might reply with fewer pages if our writeback
628 * raced with a truncation and was adjusted at the osd,
629 * so don't believe the reply.
634 mapping_set_error(mapping, rc);
636 dout("writepages_finish %p rc %d bytes %llu wrote %d (pages)\n",
637 inode, rc, bytes, wrote);
639 /* clean all pages */
640 for (i = 0; i < num_pages; i++) {
641 page = osd_data->pages[i];
643 WARN_ON(!PageUptodate(page));
646 atomic_long_dec_return(&fsc->writeback_count);
648 CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb))
649 clear_bdi_congested(&fsc->backing_dev_info,
652 ceph_put_snap_context(page_snap_context(page));
654 ClearPagePrivate(page);
655 dout("unlocking %d %p\n", i, page);
656 end_page_writeback(page);
659 * We lost the cache cap, need to truncate the page before
660 * it is unlocked, otherwise we'd truncate it later in the
661 * page truncation thread, possibly losing some data that
664 if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0)
665 generic_error_remove_page(inode->i_mapping, page);
669 dout("%p wrote+cleaned %d pages\n", inode, wrote);
670 ceph_put_wrbuffer_cap_refs(ci, num_pages, snapc);
672 ceph_release_pages(osd_data->pages, num_pages);
673 if (osd_data->pages_from_pool)
674 mempool_free(osd_data->pages,
675 ceph_sb_to_client(inode->i_sb)->wb_pagevec_pool);
677 kfree(osd_data->pages);
678 ceph_osdc_put_request(req);
682 * initiate async writeback
684 static int ceph_writepages_start(struct address_space *mapping,
685 struct writeback_control *wbc)
687 struct inode *inode = mapping->host;
688 struct ceph_inode_info *ci = ceph_inode(inode);
689 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
690 struct ceph_vino vino = ceph_vino(inode);
691 pgoff_t index, start, end;
694 pgoff_t max_pages = 0, max_pages_ever = 0;
695 struct ceph_snap_context *snapc = NULL, *last_snapc = NULL, *pgsnapc;
699 unsigned wsize = 1 << inode->i_blkbits;
700 struct ceph_osd_request *req = NULL;
702 u64 truncate_size, snap_size;
706 * Include a 'sync' in the OSD request if this is a data
707 * integrity write (e.g., O_SYNC write or fsync()), or if our
708 * cap is being revoked.
710 if ((wbc->sync_mode == WB_SYNC_ALL) ||
711 ceph_caps_revoking(ci, CEPH_CAP_FILE_BUFFER))
713 dout("writepages_start %p dosync=%d (mode=%s)\n",
715 wbc->sync_mode == WB_SYNC_NONE ? "NONE" :
716 (wbc->sync_mode == WB_SYNC_ALL ? "ALL" : "HOLD"));
718 if (fsc->mount_state == CEPH_MOUNT_SHUTDOWN) {
719 pr_warn("writepage_start %p on forced umount\n", inode);
720 return -EIO; /* we're in a forced umount, don't write! */
722 if (fsc->mount_options->wsize && fsc->mount_options->wsize < wsize)
723 wsize = fsc->mount_options->wsize;
724 if (wsize < PAGE_CACHE_SIZE)
725 wsize = PAGE_CACHE_SIZE;
726 max_pages_ever = wsize >> PAGE_CACHE_SHIFT;
728 pagevec_init(&pvec, 0);
730 /* where to start/end? */
731 if (wbc->range_cyclic) {
732 start = mapping->writeback_index; /* Start from prev offset */
734 dout(" cyclic, start at %lu\n", start);
736 start = wbc->range_start >> PAGE_CACHE_SHIFT;
737 end = wbc->range_end >> PAGE_CACHE_SHIFT;
738 if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
741 dout(" not cyclic, %lu to %lu\n", start, end);
746 /* find oldest snap context with dirty data */
747 ceph_put_snap_context(snapc);
749 snapc = get_oldest_context(inode, &snap_size);
751 /* hmm, why does writepages get called when there
753 dout(" no snap context with dirty data?\n");
757 snap_size = i_size_read(inode);
758 dout(" oldest snapc is %p seq %lld (%d snaps)\n",
759 snapc, snapc->seq, snapc->num_snaps);
761 spin_lock(&ci->i_ceph_lock);
762 truncate_seq = ci->i_truncate_seq;
763 truncate_size = ci->i_truncate_size;
765 snap_size = i_size_read(inode);
766 spin_unlock(&ci->i_ceph_lock);
768 if (last_snapc && snapc != last_snapc) {
769 /* if we switched to a newer snapc, restart our scan at the
770 * start of the original file range. */
771 dout(" snapc differs from last pass, restarting at %lu\n",
777 while (!done && index <= end) {
781 int pvec_pages, locked_pages;
782 struct page **pages = NULL;
783 mempool_t *pool = NULL; /* Becomes non-null if mempool used */
791 max_pages = max_pages_ever;
795 want = min(end - index,
796 min((pgoff_t)PAGEVEC_SIZE,
797 max_pages - (pgoff_t)locked_pages) - 1)
799 pvec_pages = pagevec_lookup_tag(&pvec, mapping, &index,
802 dout("pagevec_lookup_tag got %d\n", pvec_pages);
803 if (!pvec_pages && !locked_pages)
805 for (i = 0; i < pvec_pages && locked_pages < max_pages; i++) {
806 page = pvec.pages[i];
807 dout("? %p idx %lu\n", page, page->index);
808 if (locked_pages == 0)
809 lock_page(page); /* first page */
810 else if (!trylock_page(page))
813 /* only dirty pages, or our accounting breaks */
814 if (unlikely(!PageDirty(page)) ||
815 unlikely(page->mapping != mapping)) {
816 dout("!dirty or !mapping %p\n", page);
820 if (!wbc->range_cyclic && page->index > end) {
821 dout("end of range %p\n", page);
826 if (next && (page->index != next)) {
827 dout("not consecutive %p\n", page);
831 if (wbc->sync_mode != WB_SYNC_NONE) {
832 dout("waiting on writeback %p\n", page);
833 wait_on_page_writeback(page);
835 if (page_offset(page) >= snap_size) {
836 dout("%p page eof %llu\n", page, snap_size);
841 if (PageWriteback(page)) {
842 dout("%p under writeback\n", page);
847 /* only if matching snap context */
848 pgsnapc = page_snap_context(page);
849 if (pgsnapc->seq > snapc->seq) {
850 dout("page snapc %p %lld > oldest %p %lld\n",
851 pgsnapc, pgsnapc->seq, snapc, snapc->seq);
854 continue; /* keep looking for snap */
858 if (!clear_page_dirty_for_io(page)) {
859 dout("%p !clear_page_dirty_for_io\n", page);
865 * We have something to write. If this is
866 * the first locked page this time through,
867 * allocate an osd request and a page array
870 if (locked_pages == 0) {
872 /* prepare async write request */
873 offset = (u64)page_offset(page);
875 req = ceph_osdc_new_request(&fsc->client->osdc,
880 CEPH_OSD_FLAG_WRITE |
881 CEPH_OSD_FLAG_ONDISK,
883 truncate_size, true);
891 osd_req_op_init(req, 1,
892 CEPH_OSD_OP_STARTSYNC, 0);
894 req->r_callback = writepages_finish;
895 req->r_inode = inode;
897 max_pages = calc_pages_for(0, (u64)len);
898 pages = kmalloc(max_pages * sizeof (*pages),
901 pool = fsc->wb_pagevec_pool;
902 pages = mempool_alloc(pool, GFP_NOFS);
907 /* note position of first page in pvec */
910 dout("%p will write page %p idx %lu\n",
911 inode, page, page->index);
914 atomic_long_inc_return(&fsc->writeback_count);
915 if (writeback_stat > CONGESTION_ON_THRESH(
916 fsc->mount_options->congestion_kb)) {
917 set_bdi_congested(&fsc->backing_dev_info,
921 set_page_writeback(page);
922 pages[locked_pages] = page;
924 next = page->index + 1;
927 /* did we get anything? */
929 goto release_pvec_pages;
932 BUG_ON(!locked_pages || first < 0);
934 if (pvec_pages && i == pvec_pages &&
935 locked_pages < max_pages) {
936 dout("reached end pvec, trying for more\n");
937 pagevec_reinit(&pvec);
941 /* shift unused pages over in the pvec... we
942 * will need to release them below. */
943 for (j = i; j < pvec_pages; j++) {
944 dout(" pvec leftover page %p\n",
946 pvec.pages[j-i+first] = pvec.pages[j];
951 /* Format the osd request message and submit the write */
953 offset = page_offset(pages[0]);
954 len = min(snap_size - offset,
955 (u64)locked_pages << PAGE_CACHE_SHIFT);
956 dout("writepages got %d pages at %llu~%llu\n",
957 locked_pages, offset, len);
959 osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0,
962 pages = NULL; /* request message now owns the pages array */
965 /* Update the write op length in case we changed it */
967 osd_req_op_extent_update(req, 0, len);
969 vino = ceph_vino(inode);
970 ceph_osdc_build_request(req, offset, snapc, vino.snap,
973 rc = ceph_osdc_start_request(&fsc->client->osdc, req, true);
979 wbc->nr_to_write -= locked_pages;
980 if (wbc->nr_to_write <= 0)
984 dout("pagevec_release on %d pages (%p)\n", (int)pvec.nr,
985 pvec.nr ? pvec.pages[0] : NULL);
986 pagevec_release(&pvec);
988 if (locked_pages && !done)
992 if (should_loop && !done) {
993 /* more to do; loop back to beginning of file */
994 dout("writepages looping back to beginning of file\n");
1000 if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
1001 mapping->writeback_index = index;
1005 ceph_osdc_put_request(req);
1006 ceph_put_snap_context(snapc);
1007 dout("writepages done, rc = %d\n", rc);
1014 * See if a given @snapc is either writeable, or already written.
1016 static int context_is_writeable_or_written(struct inode *inode,
1017 struct ceph_snap_context *snapc)
1019 struct ceph_snap_context *oldest = get_oldest_context(inode, NULL);
1020 int ret = !oldest || snapc->seq <= oldest->seq;
1022 ceph_put_snap_context(oldest);
1027 * We are only allowed to write into/dirty the page if the page is
1028 * clean, or already dirty within the same snap context.
1030 * called with page locked.
1031 * return success with page locked,
1032 * or any failure (incl -EAGAIN) with page unlocked.
1034 static int ceph_update_writeable_page(struct file *file,
1035 loff_t pos, unsigned len,
1038 struct inode *inode = file_inode(file);
1039 struct ceph_inode_info *ci = ceph_inode(inode);
1040 loff_t page_off = pos & PAGE_CACHE_MASK;
1041 int pos_in_page = pos & ~PAGE_CACHE_MASK;
1042 int end_in_page = pos_in_page + len;
1045 struct ceph_snap_context *snapc, *oldest;
1048 /* writepages currently holds page lock, but if we change that later, */
1049 wait_on_page_writeback(page);
1051 snapc = page_snap_context(page);
1052 if (snapc && snapc != ci->i_head_snapc) {
1054 * this page is already dirty in another (older) snap
1055 * context! is it writeable now?
1057 oldest = get_oldest_context(inode, NULL);
1059 if (snapc->seq > oldest->seq) {
1060 ceph_put_snap_context(oldest);
1061 dout(" page %p snapc %p not current or oldest\n",
1064 * queue for writeback, and wait for snapc to
1065 * be writeable or written
1067 snapc = ceph_get_snap_context(snapc);
1069 ceph_queue_writeback(inode);
1070 r = wait_event_interruptible(ci->i_cap_wq,
1071 context_is_writeable_or_written(inode, snapc));
1072 ceph_put_snap_context(snapc);
1073 if (r == -ERESTARTSYS)
1077 ceph_put_snap_context(oldest);
1079 /* yay, writeable, do it now (without dropping page lock) */
1080 dout(" page %p snapc %p not current, but oldest\n",
1082 if (!clear_page_dirty_for_io(page))
1084 r = writepage_nounlock(page, NULL);
1090 if (PageUptodate(page)) {
1091 dout(" page %p already uptodate\n", page);
1096 if (pos_in_page == 0 && len == PAGE_CACHE_SIZE)
1099 /* past end of file? */
1100 i_size = inode->i_size; /* caller holds i_mutex */
1102 if (page_off >= i_size ||
1103 (pos_in_page == 0 && (pos+len) >= i_size &&
1104 end_in_page - pos_in_page != PAGE_CACHE_SIZE)) {
1105 dout(" zeroing %p 0 - %d and %d - %d\n",
1106 page, pos_in_page, end_in_page, (int)PAGE_CACHE_SIZE);
1107 zero_user_segments(page,
1109 end_in_page, PAGE_CACHE_SIZE);
1113 /* we need to read it. */
1114 r = readpage_nounlock(file, page);
1124 * We are only allowed to write into/dirty the page if the page is
1125 * clean, or already dirty within the same snap context.
1127 static int ceph_write_begin(struct file *file, struct address_space *mapping,
1128 loff_t pos, unsigned len, unsigned flags,
1129 struct page **pagep, void **fsdata)
1131 struct inode *inode = file_inode(file);
1133 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
1138 page = grab_cache_page_write_begin(mapping, index, 0);
1143 dout("write_begin file %p inode %p page %p %d~%d\n", file,
1144 inode, page, (int)pos, (int)len);
1146 r = ceph_update_writeable_page(file, pos, len, page);
1148 page_cache_release(page);
1151 } while (r == -EAGAIN);
1157 * we don't do anything in here that simple_write_end doesn't do
1158 * except adjust dirty page accounting
1160 static int ceph_write_end(struct file *file, struct address_space *mapping,
1161 loff_t pos, unsigned len, unsigned copied,
1162 struct page *page, void *fsdata)
1164 struct inode *inode = file_inode(file);
1165 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
1168 dout("write_end file %p inode %p page %p %d~%d (%d)\n", file,
1169 inode, page, (int)pos, (int)copied, (int)len);
1171 /* zero the stale part of the page if we did a short copy */
1173 zero_user_segment(page, from+copied, len);
1175 /* did file size increase? */
1176 /* (no need for i_size_read(); we caller holds i_mutex */
1177 if (pos+copied > inode->i_size)
1178 check_cap = ceph_inode_set_size(inode, pos+copied);
1180 if (!PageUptodate(page))
1181 SetPageUptodate(page);
1183 set_page_dirty(page);
1186 page_cache_release(page);
1189 ceph_check_caps(ceph_inode(inode), CHECK_CAPS_AUTHONLY, NULL);
1195 * we set .direct_IO to indicate direct io is supported, but since we
1196 * intercept O_DIRECT reads and writes early, this function should
1199 static ssize_t ceph_direct_io(struct kiocb *iocb, struct iov_iter *iter,
1206 const struct address_space_operations ceph_aops = {
1207 .readpage = ceph_readpage,
1208 .readpages = ceph_readpages,
1209 .writepage = ceph_writepage,
1210 .writepages = ceph_writepages_start,
1211 .write_begin = ceph_write_begin,
1212 .write_end = ceph_write_end,
1213 .set_page_dirty = ceph_set_page_dirty,
1214 .invalidatepage = ceph_invalidatepage,
1215 .releasepage = ceph_releasepage,
1216 .direct_IO = ceph_direct_io,
1223 static int ceph_filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1225 struct inode *inode = file_inode(vma->vm_file);
1226 struct ceph_inode_info *ci = ceph_inode(inode);
1227 struct ceph_file_info *fi = vma->vm_file->private_data;
1228 struct page *pinned_page = NULL;
1229 loff_t off = vmf->pgoff << PAGE_CACHE_SHIFT;
1232 dout("filemap_fault %p %llx.%llx %llu~%zd trying to get caps\n",
1233 inode, ceph_vinop(inode), off, (size_t)PAGE_CACHE_SIZE);
1234 if (fi->fmode & CEPH_FILE_MODE_LAZY)
1235 want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO;
1237 want = CEPH_CAP_FILE_CACHE;
1240 ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want,
1241 -1, &got, &pinned_page);
1244 if (ret != -ERESTARTSYS) {
1246 return VM_FAULT_SIGBUS;
1249 dout("filemap_fault %p %llu~%zd got cap refs on %s\n",
1250 inode, off, (size_t)PAGE_CACHE_SIZE, ceph_cap_string(got));
1252 if ((got & (CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO)) ||
1253 ci->i_inline_version == CEPH_INLINE_NONE)
1254 ret = filemap_fault(vma, vmf);
1258 dout("filemap_fault %p %llu~%zd dropping cap refs on %s ret %d\n",
1259 inode, off, (size_t)PAGE_CACHE_SIZE, ceph_cap_string(got), ret);
1261 page_cache_release(pinned_page);
1262 ceph_put_cap_refs(ci, got);
1267 /* read inline data */
1268 if (off >= PAGE_CACHE_SIZE) {
1269 /* does not support inline data > PAGE_SIZE */
1270 ret = VM_FAULT_SIGBUS;
1273 struct address_space *mapping = inode->i_mapping;
1274 struct page *page = find_or_create_page(mapping, 0,
1275 mapping_gfp_mask(mapping) &
1281 ret1 = __ceph_do_getattr(inode, page,
1282 CEPH_STAT_CAP_INLINE_DATA, true);
1283 if (ret1 < 0 || off >= i_size_read(inode)) {
1285 page_cache_release(page);
1286 ret = VM_FAULT_SIGBUS;
1289 if (ret1 < PAGE_CACHE_SIZE)
1290 zero_user_segment(page, ret1, PAGE_CACHE_SIZE);
1292 flush_dcache_page(page);
1293 SetPageUptodate(page);
1295 ret = VM_FAULT_MAJOR | VM_FAULT_LOCKED;
1298 dout("filemap_fault %p %llu~%zd read inline data ret %d\n",
1299 inode, off, (size_t)PAGE_CACHE_SIZE, ret);
1304 * Reuse write_begin here for simplicity.
1306 static int ceph_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
1308 struct inode *inode = file_inode(vma->vm_file);
1309 struct ceph_inode_info *ci = ceph_inode(inode);
1310 struct ceph_file_info *fi = vma->vm_file->private_data;
1311 struct page *page = vmf->page;
1312 loff_t off = page_offset(page);
1313 loff_t size = i_size_read(inode);
1317 if (ci->i_inline_version != CEPH_INLINE_NONE) {
1318 struct page *locked_page = NULL;
1323 ret = ceph_uninline_data(vma->vm_file, locked_page);
1325 unlock_page(locked_page);
1327 return VM_FAULT_SIGBUS;
1330 if (off + PAGE_CACHE_SIZE <= size)
1331 len = PAGE_CACHE_SIZE;
1333 len = size & ~PAGE_CACHE_MASK;
1335 dout("page_mkwrite %p %llx.%llx %llu~%zd getting caps i_size %llu\n",
1336 inode, ceph_vinop(inode), off, len, size);
1337 if (fi->fmode & CEPH_FILE_MODE_LAZY)
1338 want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO;
1340 want = CEPH_CAP_FILE_BUFFER;
1343 ret = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, off + len,
1347 if (ret != -ERESTARTSYS) {
1349 return VM_FAULT_SIGBUS;
1352 dout("page_mkwrite %p %llu~%zd got cap refs on %s\n",
1353 inode, off, len, ceph_cap_string(got));
1355 /* Update time before taking page lock */
1356 file_update_time(vma->vm_file);
1360 ret = VM_FAULT_NOPAGE;
1362 (page->mapping != inode->i_mapping))
1365 ret = ceph_update_writeable_page(vma->vm_file, off, len, page);
1367 /* success. we'll keep the page locked. */
1368 set_page_dirty(page);
1369 ret = VM_FAULT_LOCKED;
1374 ret = VM_FAULT_SIGBUS;
1377 if (ret != VM_FAULT_LOCKED)
1379 if (ret == VM_FAULT_LOCKED ||
1380 ci->i_inline_version != CEPH_INLINE_NONE) {
1382 spin_lock(&ci->i_ceph_lock);
1383 ci->i_inline_version = CEPH_INLINE_NONE;
1384 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR);
1385 spin_unlock(&ci->i_ceph_lock);
1387 __mark_inode_dirty(inode, dirty);
1390 dout("page_mkwrite %p %llu~%zd dropping cap refs on %s ret %d\n",
1391 inode, off, len, ceph_cap_string(got), ret);
1392 ceph_put_cap_refs(ci, got);
1397 void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
1398 char *data, size_t len)
1400 struct address_space *mapping = inode->i_mapping;
1406 if (i_size_read(inode) == 0)
1408 page = find_or_create_page(mapping, 0,
1409 mapping_gfp_mask(mapping) & ~__GFP_FS);
1412 if (PageUptodate(page)) {
1414 page_cache_release(page);
1419 dout("fill_inline_data %p %llx.%llx len %zu locked_page %p\n",
1420 inode, ceph_vinop(inode), len, locked_page);
1423 void *kaddr = kmap_atomic(page);
1424 memcpy(kaddr, data, len);
1425 kunmap_atomic(kaddr);
1428 if (page != locked_page) {
1429 if (len < PAGE_CACHE_SIZE)
1430 zero_user_segment(page, len, PAGE_CACHE_SIZE);
1432 flush_dcache_page(page);
1434 SetPageUptodate(page);
1436 page_cache_release(page);
1440 int ceph_uninline_data(struct file *filp, struct page *locked_page)
1442 struct inode *inode = file_inode(filp);
1443 struct ceph_inode_info *ci = ceph_inode(inode);
1444 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
1445 struct ceph_osd_request *req;
1446 struct page *page = NULL;
1447 u64 len, inline_version;
1449 bool from_pagecache = false;
1451 spin_lock(&ci->i_ceph_lock);
1452 inline_version = ci->i_inline_version;
1453 spin_unlock(&ci->i_ceph_lock);
1455 dout("uninline_data %p %llx.%llx inline_version %llu\n",
1456 inode, ceph_vinop(inode), inline_version);
1458 if (inline_version == 1 || /* initial version, no data */
1459 inline_version == CEPH_INLINE_NONE)
1464 WARN_ON(!PageUptodate(page));
1465 } else if (ceph_caps_issued(ci) &
1466 (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) {
1467 page = find_get_page(inode->i_mapping, 0);
1469 if (PageUptodate(page)) {
1470 from_pagecache = true;
1473 page_cache_release(page);
1480 len = i_size_read(inode);
1481 if (len > PAGE_CACHE_SIZE)
1482 len = PAGE_CACHE_SIZE;
1484 page = __page_cache_alloc(GFP_NOFS);
1489 err = __ceph_do_getattr(inode, page,
1490 CEPH_STAT_CAP_INLINE_DATA, true);
1492 /* no inline data */
1493 if (err == -ENODATA)
1500 req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
1501 ceph_vino(inode), 0, &len, 0, 1,
1503 CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE,
1504 ceph_empty_snapc, 0, 0, false);
1510 ceph_osdc_build_request(req, 0, NULL, CEPH_NOSNAP, &inode->i_mtime);
1511 err = ceph_osdc_start_request(&fsc->client->osdc, req, false);
1513 err = ceph_osdc_wait_request(&fsc->client->osdc, req);
1514 ceph_osdc_put_request(req);
1518 req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
1519 ceph_vino(inode), 0, &len, 1, 3,
1521 CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE,
1523 ci->i_truncate_seq, ci->i_truncate_size,
1530 osd_req_op_extent_osd_data_pages(req, 1, &page, len, 0, false, false);
1533 __le64 xattr_buf = cpu_to_le64(inline_version);
1534 err = osd_req_op_xattr_init(req, 0, CEPH_OSD_OP_CMPXATTR,
1535 "inline_version", &xattr_buf,
1537 CEPH_OSD_CMPXATTR_OP_GT,
1538 CEPH_OSD_CMPXATTR_MODE_U64);
1545 int xattr_len = snprintf(xattr_buf, sizeof(xattr_buf),
1546 "%llu", inline_version);
1547 err = osd_req_op_xattr_init(req, 2, CEPH_OSD_OP_SETXATTR,
1549 xattr_buf, xattr_len, 0, 0);
1554 ceph_osdc_build_request(req, 0, NULL, CEPH_NOSNAP, &inode->i_mtime);
1555 err = ceph_osdc_start_request(&fsc->client->osdc, req, false);
1557 err = ceph_osdc_wait_request(&fsc->client->osdc, req);
1559 ceph_osdc_put_request(req);
1560 if (err == -ECANCELED)
1563 if (page && page != locked_page) {
1564 if (from_pagecache) {
1566 page_cache_release(page);
1568 __free_pages(page, 0);
1571 dout("uninline_data %p %llx.%llx inline_version %llu = %d\n",
1572 inode, ceph_vinop(inode), inline_version, err);
1576 static struct vm_operations_struct ceph_vmops = {
1577 .fault = ceph_filemap_fault,
1578 .page_mkwrite = ceph_page_mkwrite,
1581 int ceph_mmap(struct file *file, struct vm_area_struct *vma)
1583 struct address_space *mapping = file->f_mapping;
1585 if (!mapping->a_ops->readpage)
1587 file_accessed(file);
1588 vma->vm_ops = &ceph_vmops;
1597 static int __ceph_pool_perm_get(struct ceph_inode_info *ci, u32 pool)
1599 struct ceph_fs_client *fsc = ceph_inode_to_client(&ci->vfs_inode);
1600 struct ceph_mds_client *mdsc = fsc->mdsc;
1601 struct ceph_osd_request *rd_req = NULL, *wr_req = NULL;
1602 struct rb_node **p, *parent;
1603 struct ceph_pool_perm *perm;
1604 struct page **pages;
1605 int err = 0, err2 = 0, have = 0;
1607 down_read(&mdsc->pool_perm_rwsem);
1608 p = &mdsc->pool_perm_tree.rb_node;
1610 perm = rb_entry(*p, struct ceph_pool_perm, node);
1611 if (pool < perm->pool)
1613 else if (pool > perm->pool)
1614 p = &(*p)->rb_right;
1620 up_read(&mdsc->pool_perm_rwsem);
1624 dout("__ceph_pool_perm_get pool %u no perm cached\n", pool);
1626 down_write(&mdsc->pool_perm_rwsem);
1630 perm = rb_entry(parent, struct ceph_pool_perm, node);
1631 if (pool < perm->pool)
1633 else if (pool > perm->pool)
1634 p = &(*p)->rb_right;
1641 up_write(&mdsc->pool_perm_rwsem);
1645 rd_req = ceph_osdc_alloc_request(&fsc->client->osdc,
1647 1, false, GFP_NOFS);
1653 rd_req->r_flags = CEPH_OSD_FLAG_READ;
1654 osd_req_op_init(rd_req, 0, CEPH_OSD_OP_STAT, 0);
1655 rd_req->r_base_oloc.pool = pool;
1656 snprintf(rd_req->r_base_oid.name, sizeof(rd_req->r_base_oid.name),
1657 "%llx.00000000", ci->i_vino.ino);
1658 rd_req->r_base_oid.name_len = strlen(rd_req->r_base_oid.name);
1660 wr_req = ceph_osdc_alloc_request(&fsc->client->osdc,
1662 1, false, GFP_NOFS);
1668 wr_req->r_flags = CEPH_OSD_FLAG_WRITE |
1669 CEPH_OSD_FLAG_ACK | CEPH_OSD_FLAG_ONDISK;
1670 osd_req_op_init(wr_req, 0, CEPH_OSD_OP_CREATE, CEPH_OSD_OP_FLAG_EXCL);
1671 wr_req->r_base_oloc.pool = pool;
1672 wr_req->r_base_oid = rd_req->r_base_oid;
1674 /* one page should be large enough for STAT data */
1675 pages = ceph_alloc_page_vector(1, GFP_KERNEL);
1676 if (IS_ERR(pages)) {
1677 err = PTR_ERR(pages);
1681 osd_req_op_raw_data_in_pages(rd_req, 0, pages, PAGE_SIZE,
1683 ceph_osdc_build_request(rd_req, 0, NULL, CEPH_NOSNAP,
1684 &ci->vfs_inode.i_mtime);
1685 err = ceph_osdc_start_request(&fsc->client->osdc, rd_req, false);
1687 ceph_osdc_build_request(wr_req, 0, NULL, CEPH_NOSNAP,
1688 &ci->vfs_inode.i_mtime);
1689 err2 = ceph_osdc_start_request(&fsc->client->osdc, wr_req, false);
1692 err = ceph_osdc_wait_request(&fsc->client->osdc, rd_req);
1694 err2 = ceph_osdc_wait_request(&fsc->client->osdc, wr_req);
1696 if (err >= 0 || err == -ENOENT)
1698 else if (err != -EPERM)
1701 if (err2 == 0 || err2 == -EEXIST)
1703 else if (err2 != -EPERM) {
1708 perm = kmalloc(sizeof(*perm), GFP_NOFS);
1716 rb_link_node(&perm->node, parent, p);
1717 rb_insert_color(&perm->node, &mdsc->pool_perm_tree);
1720 up_write(&mdsc->pool_perm_rwsem);
1723 ceph_osdc_put_request(rd_req);
1725 ceph_osdc_put_request(wr_req);
1729 dout("__ceph_pool_perm_get pool %u result = %d\n", pool, err);
1733 int ceph_pool_perm_check(struct ceph_inode_info *ci, int need)
1738 if (ceph_test_mount_opt(ceph_inode_to_client(&ci->vfs_inode),
1742 spin_lock(&ci->i_ceph_lock);
1743 flags = ci->i_ceph_flags;
1744 pool = ceph_file_layout_pg_pool(ci->i_layout);
1745 spin_unlock(&ci->i_ceph_lock);
1747 if (flags & CEPH_I_POOL_PERM) {
1748 if ((need & CEPH_CAP_FILE_RD) && !(flags & CEPH_I_POOL_RD)) {
1749 dout("ceph_pool_perm_check pool %u no read perm\n",
1753 if ((need & CEPH_CAP_FILE_WR) && !(flags & CEPH_I_POOL_WR)) {
1754 dout("ceph_pool_perm_check pool %u no write perm\n",
1761 ret = __ceph_pool_perm_get(ci, pool);
1765 flags = CEPH_I_POOL_PERM;
1766 if (ret & POOL_READ)
1767 flags |= CEPH_I_POOL_RD;
1768 if (ret & POOL_WRITE)
1769 flags |= CEPH_I_POOL_WR;
1771 spin_lock(&ci->i_ceph_lock);
1772 if (pool == ceph_file_layout_pg_pool(ci->i_layout)) {
1773 ci->i_ceph_flags = flags;
1775 pool = ceph_file_layout_pg_pool(ci->i_layout);
1776 flags = ci->i_ceph_flags;
1778 spin_unlock(&ci->i_ceph_lock);
1782 void ceph_pool_perm_destroy(struct ceph_mds_client *mdsc)
1784 struct ceph_pool_perm *perm;
1787 while (!RB_EMPTY_ROOT(&mdsc->pool_perm_tree)) {
1788 n = rb_first(&mdsc->pool_perm_tree);
1789 perm = rb_entry(n, struct ceph_pool_perm, node);
1790 rb_erase(n, &mdsc->pool_perm_tree);