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