Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 2 | /* |
| 3 | * (C) 2001 Clemson University and The University of Chicago |
Martin Brandenburg | afd9fb2 | 2018-02-13 20:13:46 +0000 | [diff] [blame] | 4 | * Copyright 2018 Omnibond Systems, L.L.C. |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 5 | * |
| 6 | * See COPYING in top-level directory. |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Linux VFS inode operations. |
| 11 | */ |
| 12 | |
Christoph Hellwig | 2f8b544 | 2016-11-01 07:40:13 -0600 | [diff] [blame] | 13 | #include <linux/bvec.h> |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 14 | #include "protocol.h" |
Mike Marshall | 575e946 | 2015-12-04 12:56:14 -0500 | [diff] [blame] | 15 | #include "orangefs-kernel.h" |
| 16 | #include "orangefs-bufmap.h" |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 17 | |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 18 | static int orangefs_writepage_locked(struct page *page, |
| 19 | struct writeback_control *wbc) |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 20 | { |
| 21 | struct inode *inode = page->mapping->host; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 22 | struct orangefs_write_range *wr = NULL; |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 23 | struct iov_iter iter; |
| 24 | struct bio_vec bv; |
| 25 | size_t len, wlen; |
| 26 | ssize_t ret; |
| 27 | loff_t off; |
| 28 | |
| 29 | set_page_writeback(page); |
| 30 | |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 31 | len = i_size_read(inode); |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 32 | if (PagePrivate(page)) { |
| 33 | wr = (struct orangefs_write_range *)page_private(page); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 34 | WARN_ON(wr->pos >= len); |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 35 | off = wr->pos; |
| 36 | if (off + wr->len > len) |
| 37 | wlen = len - off; |
| 38 | else |
| 39 | wlen = wr->len; |
| 40 | } else { |
| 41 | WARN_ON(1); |
| 42 | off = page_offset(page); |
| 43 | if (off + PAGE_SIZE > len) |
| 44 | wlen = len - off; |
| 45 | else |
| 46 | wlen = PAGE_SIZE; |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 47 | } |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 48 | /* Should've been handled in orangefs_invalidatepage. */ |
| 49 | WARN_ON(off == len || off + wlen > len); |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 50 | |
| 51 | bv.bv_page = page; |
| 52 | bv.bv_len = wlen; |
| 53 | bv.bv_offset = off % PAGE_SIZE; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 54 | WARN_ON(wlen == 0); |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 55 | iov_iter_bvec(&iter, WRITE, &bv, 1, wlen); |
| 56 | |
| 57 | ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, wlen, |
Mike Marshall | f9bbb68 | 2019-11-26 12:39:37 -0500 | [diff] [blame] | 58 | len, wr, NULL, NULL); |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 59 | if (ret < 0) { |
| 60 | SetPageError(page); |
| 61 | mapping_set_error(page->mapping, ret); |
| 62 | } else { |
| 63 | ret = 0; |
| 64 | } |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 65 | if (wr) { |
| 66 | kfree(wr); |
| 67 | set_page_private(page, 0); |
| 68 | ClearPagePrivate(page); |
| 69 | put_page(page); |
| 70 | } |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | static int orangefs_writepage(struct page *page, struct writeback_control *wbc) |
| 75 | { |
| 76 | int ret; |
| 77 | ret = orangefs_writepage_locked(page, wbc); |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 78 | unlock_page(page); |
| 79 | end_page_writeback(page); |
| 80 | return ret; |
| 81 | } |
| 82 | |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 83 | struct orangefs_writepages { |
| 84 | loff_t off; |
| 85 | size_t len; |
| 86 | kuid_t uid; |
| 87 | kgid_t gid; |
| 88 | int maxpages; |
| 89 | int npages; |
| 90 | struct page **pages; |
| 91 | struct bio_vec *bv; |
| 92 | }; |
| 93 | |
| 94 | static int orangefs_writepages_work(struct orangefs_writepages *ow, |
| 95 | struct writeback_control *wbc) |
| 96 | { |
| 97 | struct inode *inode = ow->pages[0]->mapping->host; |
| 98 | struct orangefs_write_range *wrp, wr; |
| 99 | struct iov_iter iter; |
| 100 | ssize_t ret; |
| 101 | size_t len; |
| 102 | loff_t off; |
| 103 | int i; |
| 104 | |
| 105 | len = i_size_read(inode); |
| 106 | |
| 107 | for (i = 0; i < ow->npages; i++) { |
| 108 | set_page_writeback(ow->pages[i]); |
| 109 | ow->bv[i].bv_page = ow->pages[i]; |
| 110 | ow->bv[i].bv_len = min(page_offset(ow->pages[i]) + PAGE_SIZE, |
| 111 | ow->off + ow->len) - |
| 112 | max(ow->off, page_offset(ow->pages[i])); |
| 113 | if (i == 0) |
| 114 | ow->bv[i].bv_offset = ow->off - |
| 115 | page_offset(ow->pages[i]); |
| 116 | else |
| 117 | ow->bv[i].bv_offset = 0; |
| 118 | } |
| 119 | iov_iter_bvec(&iter, WRITE, ow->bv, ow->npages, ow->len); |
| 120 | |
| 121 | WARN_ON(ow->off >= len); |
| 122 | if (ow->off + ow->len > len) |
| 123 | ow->len = len - ow->off; |
| 124 | |
| 125 | off = ow->off; |
| 126 | wr.uid = ow->uid; |
| 127 | wr.gid = ow->gid; |
| 128 | ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, ow->len, |
Mike Marshall | f9bbb68 | 2019-11-26 12:39:37 -0500 | [diff] [blame] | 129 | 0, &wr, NULL, NULL); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 130 | if (ret < 0) { |
| 131 | for (i = 0; i < ow->npages; i++) { |
| 132 | SetPageError(ow->pages[i]); |
| 133 | mapping_set_error(ow->pages[i]->mapping, ret); |
| 134 | if (PagePrivate(ow->pages[i])) { |
| 135 | wrp = (struct orangefs_write_range *) |
| 136 | page_private(ow->pages[i]); |
| 137 | ClearPagePrivate(ow->pages[i]); |
| 138 | put_page(ow->pages[i]); |
| 139 | kfree(wrp); |
| 140 | } |
| 141 | end_page_writeback(ow->pages[i]); |
| 142 | unlock_page(ow->pages[i]); |
| 143 | } |
| 144 | } else { |
| 145 | ret = 0; |
| 146 | for (i = 0; i < ow->npages; i++) { |
| 147 | if (PagePrivate(ow->pages[i])) { |
| 148 | wrp = (struct orangefs_write_range *) |
| 149 | page_private(ow->pages[i]); |
| 150 | ClearPagePrivate(ow->pages[i]); |
| 151 | put_page(ow->pages[i]); |
| 152 | kfree(wrp); |
| 153 | } |
| 154 | end_page_writeback(ow->pages[i]); |
| 155 | unlock_page(ow->pages[i]); |
| 156 | } |
| 157 | } |
| 158 | return ret; |
| 159 | } |
| 160 | |
| 161 | static int orangefs_writepages_callback(struct page *page, |
| 162 | struct writeback_control *wbc, void *data) |
| 163 | { |
| 164 | struct orangefs_writepages *ow = data; |
| 165 | struct orangefs_write_range *wr; |
| 166 | int ret; |
| 167 | |
| 168 | if (!PagePrivate(page)) { |
| 169 | unlock_page(page); |
| 170 | /* It's not private so there's nothing to write, right? */ |
| 171 | printk("writepages_callback not private!\n"); |
| 172 | BUG(); |
| 173 | return 0; |
| 174 | } |
| 175 | wr = (struct orangefs_write_range *)page_private(page); |
| 176 | |
| 177 | ret = -1; |
| 178 | if (ow->npages == 0) { |
| 179 | ow->off = wr->pos; |
| 180 | ow->len = wr->len; |
| 181 | ow->uid = wr->uid; |
| 182 | ow->gid = wr->gid; |
| 183 | ow->pages[ow->npages++] = page; |
| 184 | ret = 0; |
| 185 | goto done; |
| 186 | } |
| 187 | if (!uid_eq(ow->uid, wr->uid) || !gid_eq(ow->gid, wr->gid)) { |
| 188 | orangefs_writepages_work(ow, wbc); |
| 189 | ow->npages = 0; |
| 190 | ret = -1; |
| 191 | goto done; |
| 192 | } |
| 193 | if (ow->off + ow->len == wr->pos) { |
| 194 | ow->len += wr->len; |
| 195 | ow->pages[ow->npages++] = page; |
| 196 | ret = 0; |
| 197 | goto done; |
| 198 | } |
| 199 | done: |
| 200 | if (ret == -1) { |
| 201 | if (ow->npages) { |
| 202 | orangefs_writepages_work(ow, wbc); |
| 203 | ow->npages = 0; |
| 204 | } |
| 205 | ret = orangefs_writepage_locked(page, wbc); |
| 206 | mapping_set_error(page->mapping, ret); |
| 207 | unlock_page(page); |
| 208 | end_page_writeback(page); |
| 209 | } else { |
| 210 | if (ow->npages == ow->maxpages) { |
| 211 | orangefs_writepages_work(ow, wbc); |
| 212 | ow->npages = 0; |
| 213 | } |
| 214 | } |
| 215 | return ret; |
| 216 | } |
| 217 | |
| 218 | static int orangefs_writepages(struct address_space *mapping, |
| 219 | struct writeback_control *wbc) |
| 220 | { |
| 221 | struct orangefs_writepages *ow; |
| 222 | struct blk_plug plug; |
| 223 | int ret; |
| 224 | ow = kzalloc(sizeof(struct orangefs_writepages), GFP_KERNEL); |
| 225 | if (!ow) |
| 226 | return -ENOMEM; |
| 227 | ow->maxpages = orangefs_bufmap_size_query()/PAGE_SIZE; |
| 228 | ow->pages = kcalloc(ow->maxpages, sizeof(struct page *), GFP_KERNEL); |
| 229 | if (!ow->pages) { |
| 230 | kfree(ow); |
| 231 | return -ENOMEM; |
| 232 | } |
| 233 | ow->bv = kcalloc(ow->maxpages, sizeof(struct bio_vec), GFP_KERNEL); |
| 234 | if (!ow->bv) { |
| 235 | kfree(ow->pages); |
| 236 | kfree(ow); |
| 237 | return -ENOMEM; |
| 238 | } |
| 239 | blk_start_plug(&plug); |
| 240 | ret = write_cache_pages(mapping, wbc, orangefs_writepages_callback, ow); |
| 241 | if (ow->npages) |
| 242 | ret = orangefs_writepages_work(ow, wbc); |
| 243 | blk_finish_plug(&plug); |
| 244 | kfree(ow->pages); |
| 245 | kfree(ow->bv); |
| 246 | kfree(ow); |
| 247 | return ret; |
| 248 | } |
| 249 | |
Mike Marshall | dd59a64 | 2019-03-25 18:59:29 -0400 | [diff] [blame] | 250 | static int orangefs_launder_page(struct page *); |
| 251 | |
Martin Brandenburg | a68d9c6 | 2018-02-15 18:02:43 +0000 | [diff] [blame] | 252 | static int orangefs_readpage(struct file *file, struct page *page) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 253 | { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 254 | struct inode *inode = page->mapping->host; |
Martin Brandenburg | c453dcf | 2018-02-16 20:51:24 +0000 | [diff] [blame] | 255 | struct iov_iter iter; |
| 256 | struct bio_vec bv; |
| 257 | ssize_t ret; |
Mike Marshall | dd59a64 | 2019-03-25 18:59:29 -0400 | [diff] [blame] | 258 | loff_t off; /* offset into this page */ |
| 259 | pgoff_t index; /* which page */ |
| 260 | struct page *next_page; |
| 261 | char *kaddr; |
Mike Marshall | dd59a64 | 2019-03-25 18:59:29 -0400 | [diff] [blame] | 262 | loff_t read_size; |
Mike Marshall | dd59a64 | 2019-03-25 18:59:29 -0400 | [diff] [blame] | 263 | int buffer_index = -1; /* orangefs shared memory slot */ |
| 264 | int slot_index; /* index into slot */ |
| 265 | int remaining; |
| 266 | |
| 267 | /* |
Mike Marshall | ec95f1d | 2020-04-08 08:52:40 -0400 | [diff] [blame] | 268 | * Get up to this many bytes from Orangefs at a time and try |
| 269 | * to fill them into the page cache at once. Tests with dd made |
| 270 | * this seem like a reasonable static number, if there was |
| 271 | * interest perhaps this number could be made setable through |
| 272 | * sysfs... |
Mike Marshall | dd59a64 | 2019-03-25 18:59:29 -0400 | [diff] [blame] | 273 | */ |
Mike Marshall | ec95f1d | 2020-04-08 08:52:40 -0400 | [diff] [blame] | 274 | read_size = 524288; |
Mike Marshall | dd59a64 | 2019-03-25 18:59:29 -0400 | [diff] [blame] | 275 | |
| 276 | if (PageDirty(page)) |
| 277 | orangefs_launder_page(page); |
Al Viro | 74f68fc | 2015-10-08 18:31:05 -0400 | [diff] [blame] | 278 | |
Martin Brandenburg | c453dcf | 2018-02-16 20:51:24 +0000 | [diff] [blame] | 279 | off = page_offset(page); |
Mike Marshall | dd59a64 | 2019-03-25 18:59:29 -0400 | [diff] [blame] | 280 | index = off >> PAGE_SHIFT; |
Martin Brandenburg | c453dcf | 2018-02-16 20:51:24 +0000 | [diff] [blame] | 281 | bv.bv_page = page; |
| 282 | bv.bv_len = PAGE_SIZE; |
| 283 | bv.bv_offset = 0; |
| 284 | iov_iter_bvec(&iter, READ, &bv, 1, PAGE_SIZE); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 285 | |
Martin Brandenburg | c453dcf | 2018-02-16 20:51:24 +0000 | [diff] [blame] | 286 | ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, &off, &iter, |
Mike Marshall | f9bbb68 | 2019-11-26 12:39:37 -0500 | [diff] [blame] | 287 | read_size, inode->i_size, NULL, &buffer_index, file); |
Mike Marshall | dd59a64 | 2019-03-25 18:59:29 -0400 | [diff] [blame] | 288 | remaining = ret; |
Al Viro | 74f68fc | 2015-10-08 18:31:05 -0400 | [diff] [blame] | 289 | /* this will only zero remaining unread portions of the page data */ |
Martin Brandenburg | c453dcf | 2018-02-16 20:51:24 +0000 | [diff] [blame] | 290 | iov_iter_zero(~0U, &iter); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 291 | /* takes care of potential aliasing */ |
| 292 | flush_dcache_page(page); |
Martin Brandenburg | c453dcf | 2018-02-16 20:51:24 +0000 | [diff] [blame] | 293 | if (ret < 0) { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 294 | SetPageError(page); |
Mike Marshall | dd59a64 | 2019-03-25 18:59:29 -0400 | [diff] [blame] | 295 | unlock_page(page); |
| 296 | goto out; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 297 | } else { |
| 298 | SetPageUptodate(page); |
| 299 | if (PageError(page)) |
| 300 | ClearPageError(page); |
| 301 | ret = 0; |
| 302 | } |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 303 | /* unlock the page after the ->readpage() routine completes */ |
| 304 | unlock_page(page); |
Mike Marshall | dd59a64 | 2019-03-25 18:59:29 -0400 | [diff] [blame] | 305 | |
| 306 | if (remaining > PAGE_SIZE) { |
| 307 | slot_index = 0; |
| 308 | while ((remaining - PAGE_SIZE) >= PAGE_SIZE) { |
| 309 | remaining -= PAGE_SIZE; |
| 310 | /* |
| 311 | * It is an optimization to try and fill more than one |
| 312 | * page... by now we've already gotten the single |
| 313 | * page we were after, if stuff doesn't seem to |
| 314 | * be going our way at this point just return |
| 315 | * and hope for the best. |
| 316 | * |
| 317 | * If we look for pages and they're already there is |
| 318 | * one reason to give up, and if they're not there |
| 319 | * and we can't create them is another reason. |
| 320 | */ |
| 321 | |
| 322 | index++; |
| 323 | slot_index++; |
| 324 | next_page = find_get_page(inode->i_mapping, index); |
| 325 | if (next_page) { |
| 326 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 327 | "%s: found next page, quitting\n", |
| 328 | __func__); |
| 329 | put_page(next_page); |
| 330 | goto out; |
| 331 | } |
| 332 | next_page = find_or_create_page(inode->i_mapping, |
| 333 | index, |
| 334 | GFP_KERNEL); |
| 335 | /* |
| 336 | * I've never hit this, leave it as a printk for |
| 337 | * now so it will be obvious. |
| 338 | */ |
| 339 | if (!next_page) { |
| 340 | printk("%s: can't create next page, quitting\n", |
| 341 | __func__); |
| 342 | goto out; |
| 343 | } |
| 344 | kaddr = kmap_atomic(next_page); |
| 345 | orangefs_bufmap_page_fill(kaddr, |
| 346 | buffer_index, |
| 347 | slot_index); |
| 348 | kunmap_atomic(kaddr); |
| 349 | SetPageUptodate(next_page); |
| 350 | unlock_page(next_page); |
| 351 | put_page(next_page); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | out: |
| 356 | if (buffer_index != -1) |
| 357 | orangefs_bufmap_put(buffer_index); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 358 | return ret; |
| 359 | } |
| 360 | |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 361 | static int orangefs_write_begin(struct file *file, |
| 362 | struct address_space *mapping, |
| 363 | loff_t pos, unsigned len, unsigned flags, struct page **pagep, |
| 364 | void **fsdata) |
| 365 | { |
| 366 | struct orangefs_write_range *wr; |
| 367 | struct page *page; |
| 368 | pgoff_t index; |
| 369 | int ret; |
| 370 | |
| 371 | index = pos >> PAGE_SHIFT; |
| 372 | |
| 373 | page = grab_cache_page_write_begin(mapping, index, flags); |
| 374 | if (!page) |
| 375 | return -ENOMEM; |
| 376 | |
| 377 | *pagep = page; |
| 378 | |
| 379 | if (PageDirty(page) && !PagePrivate(page)) { |
| 380 | /* |
| 381 | * Should be impossible. If it happens, launder the page |
| 382 | * since we don't know what's dirty. This will WARN in |
| 383 | * orangefs_writepage_locked. |
| 384 | */ |
| 385 | ret = orangefs_launder_page(page); |
| 386 | if (ret) |
| 387 | return ret; |
| 388 | } |
| 389 | if (PagePrivate(page)) { |
| 390 | struct orangefs_write_range *wr; |
| 391 | wr = (struct orangefs_write_range *)page_private(page); |
| 392 | if (wr->pos + wr->len == pos && |
| 393 | uid_eq(wr->uid, current_fsuid()) && |
| 394 | gid_eq(wr->gid, current_fsgid())) { |
| 395 | wr->len += len; |
| 396 | goto okay; |
| 397 | } else { |
| 398 | ret = orangefs_launder_page(page); |
| 399 | if (ret) |
| 400 | return ret; |
| 401 | } |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | wr = kmalloc(sizeof *wr, GFP_KERNEL); |
| 405 | if (!wr) |
| 406 | return -ENOMEM; |
| 407 | |
| 408 | wr->pos = pos; |
| 409 | wr->len = len; |
| 410 | wr->uid = current_fsuid(); |
| 411 | wr->gid = current_fsgid(); |
| 412 | SetPagePrivate(page); |
| 413 | set_page_private(page, (unsigned long)wr); |
| 414 | get_page(page); |
| 415 | okay: |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 419 | static int orangefs_write_end(struct file *file, struct address_space *mapping, |
| 420 | loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) |
| 421 | { |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 422 | struct inode *inode = page->mapping->host; |
| 423 | loff_t last_pos = pos + copied; |
| 424 | |
| 425 | /* |
| 426 | * No need to use i_size_read() here, the i_size |
| 427 | * cannot change under us because we hold the i_mutex. |
| 428 | */ |
| 429 | if (last_pos > inode->i_size) |
| 430 | i_size_write(inode, last_pos); |
| 431 | |
| 432 | /* zero the stale part of the page if we did a short copy */ |
| 433 | if (!PageUptodate(page)) { |
| 434 | unsigned from = pos & (PAGE_SIZE - 1); |
| 435 | if (copied < len) { |
| 436 | zero_user(page, from + copied, len - copied); |
| 437 | } |
| 438 | /* Set fully written pages uptodate. */ |
| 439 | if (pos == page_offset(page) && |
| 440 | (len == PAGE_SIZE || pos + len == inode->i_size)) { |
| 441 | zero_user_segment(page, from + copied, PAGE_SIZE); |
| 442 | SetPageUptodate(page); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | set_page_dirty(page); |
| 447 | unlock_page(page); |
| 448 | put_page(page); |
| 449 | |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 450 | mark_inode_dirty_sync(file_inode(file)); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 451 | return copied; |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 454 | static void orangefs_invalidatepage(struct page *page, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 455 | unsigned int offset, |
| 456 | unsigned int length) |
| 457 | { |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 458 | struct orangefs_write_range *wr; |
| 459 | wr = (struct orangefs_write_range *)page_private(page); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 460 | |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 461 | if (offset == 0 && length == PAGE_SIZE) { |
| 462 | kfree((struct orangefs_write_range *)page_private(page)); |
| 463 | set_page_private(page, 0); |
| 464 | ClearPagePrivate(page); |
| 465 | put_page(page); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 466 | return; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 467 | /* write range entirely within invalidate range (or equal) */ |
| 468 | } else if (page_offset(page) + offset <= wr->pos && |
| 469 | wr->pos + wr->len <= page_offset(page) + offset + length) { |
| 470 | kfree((struct orangefs_write_range *)page_private(page)); |
| 471 | set_page_private(page, 0); |
| 472 | ClearPagePrivate(page); |
| 473 | put_page(page); |
| 474 | /* XXX is this right? only caller in fs */ |
| 475 | cancel_dirty_page(page); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 476 | return; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 477 | /* invalidate range chops off end of write range */ |
| 478 | } else if (wr->pos < page_offset(page) + offset && |
| 479 | wr->pos + wr->len <= page_offset(page) + offset + length && |
| 480 | page_offset(page) + offset < wr->pos + wr->len) { |
| 481 | size_t x; |
| 482 | x = wr->pos + wr->len - (page_offset(page) + offset); |
| 483 | WARN_ON(x > wr->len); |
| 484 | wr->len -= x; |
| 485 | wr->uid = current_fsuid(); |
| 486 | wr->gid = current_fsgid(); |
| 487 | /* invalidate range chops off beginning of write range */ |
| 488 | } else if (page_offset(page) + offset <= wr->pos && |
| 489 | page_offset(page) + offset + length < wr->pos + wr->len && |
| 490 | wr->pos < page_offset(page) + offset + length) { |
| 491 | size_t x; |
| 492 | x = page_offset(page) + offset + length - wr->pos; |
| 493 | WARN_ON(x > wr->len); |
| 494 | wr->pos += x; |
| 495 | wr->len -= x; |
| 496 | wr->uid = current_fsuid(); |
| 497 | wr->gid = current_fsgid(); |
| 498 | /* invalidate range entirely within write range (punch hole) */ |
| 499 | } else if (wr->pos < page_offset(page) + offset && |
| 500 | page_offset(page) + offset + length < wr->pos + wr->len) { |
| 501 | /* XXX what do we do here... should not WARN_ON */ |
| 502 | WARN_ON(1); |
| 503 | /* punch hole */ |
| 504 | /* |
| 505 | * should we just ignore this and write it out anyway? |
| 506 | * it hardly makes sense |
| 507 | */ |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 508 | return; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 509 | /* non-overlapping ranges */ |
| 510 | } else { |
| 511 | /* WARN if they do overlap */ |
| 512 | if (!((page_offset(page) + offset + length <= wr->pos) ^ |
| 513 | (wr->pos + wr->len <= page_offset(page) + offset))) { |
| 514 | WARN_ON(1); |
| 515 | printk("invalidate range offset %llu length %u\n", |
| 516 | page_offset(page) + offset, length); |
| 517 | printk("write range offset %llu length %zu\n", |
| 518 | wr->pos, wr->len); |
| 519 | } |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 520 | return; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 521 | } |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 522 | |
| 523 | /* |
| 524 | * Above there are returns where wr is freed or where we WARN. |
| 525 | * Thus the following runs if wr was modified above. |
| 526 | */ |
| 527 | |
| 528 | orangefs_launder_page(page); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 529 | } |
| 530 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 531 | static int orangefs_releasepage(struct page *page, gfp_t foo) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 532 | { |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 533 | return !PagePrivate(page); |
| 534 | } |
| 535 | |
| 536 | static void orangefs_freepage(struct page *page) |
| 537 | { |
| 538 | if (PagePrivate(page)) { |
| 539 | kfree((struct orangefs_write_range *)page_private(page)); |
| 540 | set_page_private(page, 0); |
| 541 | ClearPagePrivate(page); |
| 542 | put_page(page); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | static int orangefs_launder_page(struct page *page) |
| 547 | { |
| 548 | int r = 0; |
| 549 | struct writeback_control wbc = { |
| 550 | .sync_mode = WB_SYNC_ALL, |
| 551 | .nr_to_write = 0, |
| 552 | }; |
| 553 | wait_on_page_writeback(page); |
| 554 | if (clear_page_dirty_for_io(page)) { |
| 555 | r = orangefs_writepage_locked(page, &wbc); |
| 556 | end_page_writeback(page); |
| 557 | } |
| 558 | return r; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 559 | } |
| 560 | |
Mike Marshall | 3903f15 | 2016-06-09 15:38:03 -0400 | [diff] [blame] | 561 | static ssize_t orangefs_direct_IO(struct kiocb *iocb, |
| 562 | struct iov_iter *iter) |
| 563 | { |
Martin Brandenburg | 3e9dfc6 | 2018-11-06 19:54:49 +0000 | [diff] [blame] | 564 | /* |
| 565 | * Comment from original do_readv_writev: |
| 566 | * Common entry point for read/write/readv/writev |
| 567 | * This function will dispatch it to either the direct I/O |
| 568 | * or buffered I/O path depending on the mount options and/or |
| 569 | * augmented/extended metadata attached to the file. |
| 570 | * Note: File extended attributes override any mount options. |
| 571 | */ |
Martin Brandenburg | c453dcf | 2018-02-16 20:51:24 +0000 | [diff] [blame] | 572 | struct file *file = iocb->ki_filp; |
Martin Brandenburg | 3e9dfc6 | 2018-11-06 19:54:49 +0000 | [diff] [blame] | 573 | loff_t pos = iocb->ki_pos; |
| 574 | enum ORANGEFS_io_type type = iov_iter_rw(iter) == WRITE ? |
| 575 | ORANGEFS_IO_WRITE : ORANGEFS_IO_READ; |
| 576 | loff_t *offset = &pos; |
| 577 | struct inode *inode = file->f_mapping->host; |
| 578 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); |
| 579 | struct orangefs_khandle *handle = &orangefs_inode->refn.khandle; |
| 580 | size_t count = iov_iter_count(iter); |
Martin Brandenburg | 3e9dfc6 | 2018-11-06 19:54:49 +0000 | [diff] [blame] | 581 | ssize_t total_count = 0; |
| 582 | ssize_t ret = -EINVAL; |
| 583 | int i = 0; |
| 584 | |
| 585 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 586 | "%s-BEGIN(%pU): count(%d) after estimate_max_iovecs.\n", |
| 587 | __func__, |
| 588 | handle, |
| 589 | (int)count); |
| 590 | |
| 591 | if (type == ORANGEFS_IO_WRITE) { |
| 592 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 593 | "%s(%pU): proceeding with offset : %llu, " |
| 594 | "size %d\n", |
| 595 | __func__, |
| 596 | handle, |
| 597 | llu(*offset), |
| 598 | (int)count); |
| 599 | } |
| 600 | |
| 601 | if (count == 0) { |
| 602 | ret = 0; |
| 603 | goto out; |
| 604 | } |
| 605 | |
| 606 | while (iov_iter_count(iter)) { |
| 607 | size_t each_count = iov_iter_count(iter); |
| 608 | size_t amt_complete; |
| 609 | i++; |
| 610 | |
| 611 | /* how much to transfer in this loop iteration */ |
| 612 | if (each_count > orangefs_bufmap_size_query()) |
| 613 | each_count = orangefs_bufmap_size_query(); |
| 614 | |
| 615 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 616 | "%s(%pU): size of each_count(%d)\n", |
| 617 | __func__, |
| 618 | handle, |
| 619 | (int)each_count); |
| 620 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 621 | "%s(%pU): BEFORE wait_for_io: offset is %d\n", |
| 622 | __func__, |
| 623 | handle, |
| 624 | (int)*offset); |
| 625 | |
| 626 | ret = wait_for_direct_io(type, inode, offset, iter, |
Mike Marshall | f9bbb68 | 2019-11-26 12:39:37 -0500 | [diff] [blame] | 627 | each_count, 0, NULL, NULL, file); |
Martin Brandenburg | 3e9dfc6 | 2018-11-06 19:54:49 +0000 | [diff] [blame] | 628 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 629 | "%s(%pU): return from wait_for_io:%d\n", |
| 630 | __func__, |
| 631 | handle, |
| 632 | (int)ret); |
| 633 | |
| 634 | if (ret < 0) |
| 635 | goto out; |
| 636 | |
| 637 | *offset += ret; |
| 638 | total_count += ret; |
| 639 | amt_complete = ret; |
| 640 | |
| 641 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 642 | "%s(%pU): AFTER wait_for_io: offset is %d\n", |
| 643 | __func__, |
| 644 | handle, |
| 645 | (int)*offset); |
| 646 | |
| 647 | /* |
| 648 | * if we got a short I/O operations, |
| 649 | * fall out and return what we got so far |
| 650 | */ |
| 651 | if (amt_complete < each_count) |
| 652 | break; |
| 653 | } /*end while */ |
| 654 | |
| 655 | out: |
| 656 | if (total_count > 0) |
| 657 | ret = total_count; |
| 658 | if (ret > 0) { |
| 659 | if (type == ORANGEFS_IO_READ) { |
| 660 | file_accessed(file); |
| 661 | } else { |
| 662 | file_update_time(file); |
| 663 | if (*offset > i_size_read(inode)) |
| 664 | i_size_write(inode, *offset); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 669 | "%s(%pU): Value(%d) returned.\n", |
| 670 | __func__, |
| 671 | handle, |
| 672 | (int)ret); |
| 673 | |
| 674 | return ret; |
Mike Marshall | 3903f15 | 2016-06-09 15:38:03 -0400 | [diff] [blame] | 675 | } |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 676 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 677 | /** ORANGEFS2 implementation of address space operations */ |
Martin Brandenburg | bdd6f08 | 2018-04-03 16:27:13 +0000 | [diff] [blame] | 678 | static const struct address_space_operations orangefs_address_operations = { |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 679 | .writepage = orangefs_writepage, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 680 | .readpage = orangefs_readpage, |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 681 | .writepages = orangefs_writepages, |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 682 | .set_page_dirty = __set_page_dirty_nobuffers, |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 683 | .write_begin = orangefs_write_begin, |
Martin Brandenburg | 85ac799 | 2018-02-22 18:10:43 +0000 | [diff] [blame] | 684 | .write_end = orangefs_write_end, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 685 | .invalidatepage = orangefs_invalidatepage, |
| 686 | .releasepage = orangefs_releasepage, |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 687 | .freepage = orangefs_freepage, |
| 688 | .launder_page = orangefs_launder_page, |
Mike Marshall | 3903f15 | 2016-06-09 15:38:03 -0400 | [diff] [blame] | 689 | .direct_IO = orangefs_direct_IO, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 690 | }; |
| 691 | |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 692 | vm_fault_t orangefs_page_mkwrite(struct vm_fault *vmf) |
| 693 | { |
| 694 | struct page *page = vmf->page; |
| 695 | struct inode *inode = file_inode(vmf->vma->vm_file); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 696 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); |
| 697 | unsigned long *bitlock = &orangefs_inode->bitlock; |
| 698 | vm_fault_t ret; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 699 | struct orangefs_write_range *wr; |
| 700 | |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 701 | sb_start_pagefault(inode->i_sb); |
| 702 | |
| 703 | if (wait_on_bit(bitlock, 1, TASK_KILLABLE)) { |
| 704 | ret = VM_FAULT_RETRY; |
| 705 | goto out; |
| 706 | } |
| 707 | |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 708 | lock_page(page); |
| 709 | if (PageDirty(page) && !PagePrivate(page)) { |
| 710 | /* |
| 711 | * Should be impossible. If it happens, launder the page |
| 712 | * since we don't know what's dirty. This will WARN in |
| 713 | * orangefs_writepage_locked. |
| 714 | */ |
| 715 | if (orangefs_launder_page(page)) { |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 716 | ret = VM_FAULT_LOCKED|VM_FAULT_RETRY; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 717 | goto out; |
| 718 | } |
| 719 | } |
| 720 | if (PagePrivate(page)) { |
| 721 | wr = (struct orangefs_write_range *)page_private(page); |
| 722 | if (uid_eq(wr->uid, current_fsuid()) && |
| 723 | gid_eq(wr->gid, current_fsgid())) { |
| 724 | wr->pos = page_offset(page); |
| 725 | wr->len = PAGE_SIZE; |
| 726 | goto okay; |
| 727 | } else { |
| 728 | if (orangefs_launder_page(page)) { |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 729 | ret = VM_FAULT_LOCKED|VM_FAULT_RETRY; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 730 | goto out; |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | wr = kmalloc(sizeof *wr, GFP_KERNEL); |
| 735 | if (!wr) { |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 736 | ret = VM_FAULT_LOCKED|VM_FAULT_RETRY; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 737 | goto out; |
| 738 | } |
| 739 | wr->pos = page_offset(page); |
| 740 | wr->len = PAGE_SIZE; |
| 741 | wr->uid = current_fsuid(); |
| 742 | wr->gid = current_fsgid(); |
| 743 | SetPagePrivate(page); |
| 744 | set_page_private(page, (unsigned long)wr); |
| 745 | get_page(page); |
| 746 | okay: |
| 747 | |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 748 | file_update_time(vmf->vma->vm_file); |
| 749 | if (page->mapping != inode->i_mapping) { |
| 750 | unlock_page(page); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 751 | ret = VM_FAULT_LOCKED|VM_FAULT_NOPAGE; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 752 | goto out; |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | * We mark the page dirty already here so that when freeze is in |
| 757 | * progress, we are guaranteed that writeback during freezing will |
| 758 | * see the dirty page and writeprotect it again. |
| 759 | */ |
| 760 | set_page_dirty(page); |
| 761 | wait_for_stable_page(page); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 762 | ret = VM_FAULT_LOCKED; |
Martin Brandenburg | 52e2d0a | 2018-12-14 15:24:43 -0500 | [diff] [blame] | 763 | out: |
| 764 | sb_end_pagefault(inode->i_sb); |
| 765 | return ret; |
| 766 | } |
| 767 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 768 | static int orangefs_setattr_size(struct inode *inode, struct iattr *iattr) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 769 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 770 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); |
| 771 | struct orangefs_kernel_op_s *new_op; |
Martin Brandenburg | fecd86a | 2016-03-23 17:06:25 -0400 | [diff] [blame] | 772 | loff_t orig_size; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 773 | int ret = -EINVAL; |
| 774 | |
| 775 | gossip_debug(GOSSIP_INODE_DEBUG, |
| 776 | "%s: %pU: Handle is %pU | fs_id %d | size is %llu\n", |
| 777 | __func__, |
| 778 | get_khandle_from_ino(inode), |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 779 | &orangefs_inode->refn.khandle, |
| 780 | orangefs_inode->refn.fs_id, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 781 | iattr->ia_size); |
| 782 | |
Martin Brandenburg | fecd86a | 2016-03-23 17:06:25 -0400 | [diff] [blame] | 783 | /* Ensure that we have a up to date size, so we know if it changed. */ |
Martin Brandenburg | 8b60785 | 2018-02-07 18:44:50 +0000 | [diff] [blame] | 784 | ret = orangefs_inode_getattr(inode, ORANGEFS_GETATTR_SIZE); |
Martin Brandenburg | fecd86a | 2016-03-23 17:06:25 -0400 | [diff] [blame] | 785 | if (ret == -ESTALE) |
| 786 | ret = -EIO; |
| 787 | if (ret) { |
| 788 | gossip_err("%s: orangefs_inode_getattr failed, ret:%d:.\n", |
| 789 | __func__, ret); |
| 790 | return ret; |
| 791 | } |
| 792 | orig_size = i_size_read(inode); |
| 793 | |
Martin Brandenburg | 33713cd | 2019-04-29 17:09:48 +0000 | [diff] [blame] | 794 | /* This is truncate_setsize in a different order. */ |
| 795 | truncate_pagecache(inode, iattr->ia_size); |
| 796 | i_size_write(inode, iattr->ia_size); |
| 797 | if (iattr->ia_size > orig_size) |
| 798 | pagecache_isize_extended(inode, orig_size, iattr->ia_size); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 799 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 800 | new_op = op_alloc(ORANGEFS_VFS_OP_TRUNCATE); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 801 | if (!new_op) |
| 802 | return -ENOMEM; |
| 803 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 804 | new_op->upcall.req.truncate.refn = orangefs_inode->refn; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 805 | new_op->upcall.req.truncate.size = (__s64) iattr->ia_size; |
| 806 | |
Mike Marshall | 95f5f88 | 2018-05-11 17:11:48 -0400 | [diff] [blame] | 807 | ret = service_operation(new_op, |
| 808 | __func__, |
| 809 | get_interruptible_flag(inode)); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 810 | |
| 811 | /* |
| 812 | * the truncate has no downcall members to retrieve, but |
| 813 | * the status value tells us if it went through ok or not |
| 814 | */ |
Mike Marshall | 95f5f88 | 2018-05-11 17:11:48 -0400 | [diff] [blame] | 815 | gossip_debug(GOSSIP_INODE_DEBUG, "%s: ret:%d:\n", __func__, ret); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 816 | |
| 817 | op_release(new_op); |
| 818 | |
| 819 | if (ret != 0) |
| 820 | return ret; |
| 821 | |
Martin Brandenburg | f83140c | 2016-04-04 16:26:36 -0400 | [diff] [blame] | 822 | if (orig_size != i_size_read(inode)) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 823 | iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 824 | |
| 825 | return ret; |
| 826 | } |
| 827 | |
Martin Brandenburg | afd9fb2 | 2018-02-13 20:13:46 +0000 | [diff] [blame] | 828 | int __orangefs_setattr(struct inode *inode, struct iattr *iattr) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 829 | { |
Martin Brandenburg | df2d733 | 2018-02-12 20:29:37 +0000 | [diff] [blame] | 830 | int ret; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 831 | |
Martin Brandenburg | afd9fb2 | 2018-02-13 20:13:46 +0000 | [diff] [blame] | 832 | if (iattr->ia_valid & ATTR_MODE) { |
| 833 | if (iattr->ia_mode & (S_ISVTX)) { |
| 834 | if (is_root_handle(inode)) { |
| 835 | /* |
| 836 | * allow sticky bit to be set on root (since |
| 837 | * it shows up that way by default anyhow), |
| 838 | * but don't show it to the server |
| 839 | */ |
| 840 | iattr->ia_mode -= S_ISVTX; |
| 841 | } else { |
| 842 | gossip_debug(GOSSIP_UTILS_DEBUG, |
| 843 | "User attempted to set sticky bit on non-root directory; returning EINVAL.\n"); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 844 | ret = -EINVAL; |
| 845 | goto out; |
Martin Brandenburg | afd9fb2 | 2018-02-13 20:13:46 +0000 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | if (iattr->ia_mode & (S_ISUID)) { |
| 849 | gossip_debug(GOSSIP_UTILS_DEBUG, |
| 850 | "Attempting to set setuid bit (not supported); returning EINVAL.\n"); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 851 | ret = -EINVAL; |
| 852 | goto out; |
Martin Brandenburg | afd9fb2 | 2018-02-13 20:13:46 +0000 | [diff] [blame] | 853 | } |
| 854 | } |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 855 | |
Martin Brandenburg | 53950ef | 2017-04-25 15:38:04 -0400 | [diff] [blame] | 856 | if (iattr->ia_valid & ATTR_SIZE) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 857 | ret = orangefs_setattr_size(inode, iattr); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 858 | if (ret) |
| 859 | goto out; |
| 860 | } |
| 861 | |
Martin Brandenburg | afd9fb2 | 2018-02-13 20:13:46 +0000 | [diff] [blame] | 862 | again: |
| 863 | spin_lock(&inode->i_lock); |
| 864 | if (ORANGEFS_I(inode)->attr_valid) { |
| 865 | if (uid_eq(ORANGEFS_I(inode)->attr_uid, current_fsuid()) && |
| 866 | gid_eq(ORANGEFS_I(inode)->attr_gid, current_fsgid())) { |
| 867 | ORANGEFS_I(inode)->attr_valid = iattr->ia_valid; |
| 868 | } else { |
| 869 | spin_unlock(&inode->i_lock); |
| 870 | write_inode_now(inode, 1); |
| 871 | goto again; |
| 872 | } |
| 873 | } else { |
| 874 | ORANGEFS_I(inode)->attr_valid = iattr->ia_valid; |
| 875 | ORANGEFS_I(inode)->attr_uid = current_fsuid(); |
| 876 | ORANGEFS_I(inode)->attr_gid = current_fsgid(); |
| 877 | } |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 878 | setattr_copy(inode, iattr); |
Martin Brandenburg | afd9fb2 | 2018-02-13 20:13:46 +0000 | [diff] [blame] | 879 | spin_unlock(&inode->i_lock); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 880 | mark_inode_dirty(inode); |
| 881 | |
Martin Brandenburg | df2d733 | 2018-02-12 20:29:37 +0000 | [diff] [blame] | 882 | if (iattr->ia_valid & ATTR_MODE) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 883 | /* change mod on a file that has ACLs */ |
| 884 | ret = posix_acl_chmod(inode, inode->i_mode); |
| 885 | |
Martin Brandenburg | df2d733 | 2018-02-12 20:29:37 +0000 | [diff] [blame] | 886 | ret = 0; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 887 | out: |
Martin Brandenburg | afd9fb2 | 2018-02-13 20:13:46 +0000 | [diff] [blame] | 888 | return ret; |
| 889 | } |
| 890 | |
| 891 | /* |
| 892 | * Change attributes of an object referenced by dentry. |
| 893 | */ |
| 894 | int orangefs_setattr(struct dentry *dentry, struct iattr *iattr) |
| 895 | { |
| 896 | int ret; |
| 897 | gossip_debug(GOSSIP_INODE_DEBUG, "__orangefs_setattr: called on %pd\n", |
| 898 | dentry); |
| 899 | ret = setattr_prepare(dentry, iattr); |
| 900 | if (ret) |
| 901 | goto out; |
| 902 | ret = __orangefs_setattr(d_inode(dentry), iattr); |
| 903 | sync_inode_metadata(d_inode(dentry), 1); |
| 904 | out: |
| 905 | gossip_debug(GOSSIP_INODE_DEBUG, "orangefs_setattr: returning %d\n", |
| 906 | ret); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 907 | return ret; |
| 908 | } |
| 909 | |
| 910 | /* |
| 911 | * Obtain attributes of an object given a dentry |
| 912 | */ |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 913 | int orangefs_getattr(const struct path *path, struct kstat *stat, |
| 914 | u32 request_mask, unsigned int flags) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 915 | { |
Colin Ian King | e6b998a | 2019-07-28 19:04:07 +0100 | [diff] [blame] | 916 | int ret; |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 917 | struct inode *inode = path->dentry->d_inode; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 918 | |
| 919 | gossip_debug(GOSSIP_INODE_DEBUG, |
Martin Brandenburg | 5e4f606 | 2018-02-12 17:04:57 +0000 | [diff] [blame] | 920 | "orangefs_getattr: called on %pd mask %u\n", |
| 921 | path->dentry, request_mask); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 922 | |
Martin Brandenburg | 8b60785 | 2018-02-07 18:44:50 +0000 | [diff] [blame] | 923 | ret = orangefs_inode_getattr(inode, |
| 924 | request_mask & STATX_SIZE ? ORANGEFS_GETATTR_SIZE : 0); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 925 | if (ret == 0) { |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 926 | generic_fillattr(inode, stat); |
Mike Marshall | a7d3e78 | 2016-03-14 15:30:03 -0400 | [diff] [blame] | 927 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 928 | /* override block size reported to stat */ |
Christoph Hellwig | 5678b5d | 2019-01-21 16:23:25 +0100 | [diff] [blame] | 929 | if (!(request_mask & STATX_SIZE)) |
| 930 | stat->result_mask &= ~STATX_SIZE; |
Martin Brandenburg | 7f54910 | 2018-05-31 16:37:00 +0000 | [diff] [blame] | 931 | |
| 932 | stat->attributes_mask = STATX_ATTR_IMMUTABLE | |
| 933 | STATX_ATTR_APPEND; |
| 934 | if (inode->i_flags & S_IMMUTABLE) |
| 935 | stat->attributes |= STATX_ATTR_IMMUTABLE; |
| 936 | if (inode->i_flags & S_APPEND) |
| 937 | stat->attributes |= STATX_ATTR_APPEND; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 938 | } |
| 939 | return ret; |
| 940 | } |
| 941 | |
Martin Brandenburg | 933287d | 2016-01-30 13:46:54 -0500 | [diff] [blame] | 942 | int orangefs_permission(struct inode *inode, int mask) |
| 943 | { |
| 944 | int ret; |
| 945 | |
| 946 | if (mask & MAY_NOT_BLOCK) |
| 947 | return -ECHILD; |
| 948 | |
| 949 | gossip_debug(GOSSIP_INODE_DEBUG, "%s: refreshing\n", __func__); |
| 950 | |
| 951 | /* Make sure the permission (and other common attrs) are up to date. */ |
Martin Brandenburg | 8b60785 | 2018-02-07 18:44:50 +0000 | [diff] [blame] | 952 | ret = orangefs_inode_getattr(inode, 0); |
Martin Brandenburg | 933287d | 2016-01-30 13:46:54 -0500 | [diff] [blame] | 953 | if (ret < 0) |
| 954 | return ret; |
| 955 | |
| 956 | return generic_permission(inode, mask); |
| 957 | } |
| 958 | |
Deepa Dinamani | 95582b0 | 2018-05-08 19:36:02 -0700 | [diff] [blame] | 959 | int orangefs_update_time(struct inode *inode, struct timespec64 *time, int flags) |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 960 | { |
| 961 | struct iattr iattr; |
| 962 | gossip_debug(GOSSIP_INODE_DEBUG, "orangefs_update_time: %pU\n", |
| 963 | get_khandle_from_ino(inode)); |
| 964 | generic_update_time(inode, time, flags); |
| 965 | memset(&iattr, 0, sizeof iattr); |
| 966 | if (flags & S_ATIME) |
| 967 | iattr.ia_valid |= ATTR_ATIME; |
| 968 | if (flags & S_CTIME) |
| 969 | iattr.ia_valid |= ATTR_CTIME; |
| 970 | if (flags & S_MTIME) |
| 971 | iattr.ia_valid |= ATTR_MTIME; |
Martin Brandenburg | afd9fb2 | 2018-02-13 20:13:46 +0000 | [diff] [blame] | 972 | return __orangefs_setattr(inode, &iattr); |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 973 | } |
| 974 | |
Mike Marshall | 95f5f88 | 2018-05-11 17:11:48 -0400 | [diff] [blame] | 975 | /* ORANGEFS2 implementation of VFS inode operations for files */ |
Martin Brandenburg | bdd6f08 | 2018-04-03 16:27:13 +0000 | [diff] [blame] | 976 | static const struct inode_operations orangefs_file_inode_operations = { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 977 | .get_acl = orangefs_get_acl, |
| 978 | .set_acl = orangefs_set_acl, |
| 979 | .setattr = orangefs_setattr, |
| 980 | .getattr = orangefs_getattr, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 981 | .listxattr = orangefs_listxattr, |
Martin Brandenburg | 933287d | 2016-01-30 13:46:54 -0500 | [diff] [blame] | 982 | .permission = orangefs_permission, |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 983 | .update_time = orangefs_update_time, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 984 | }; |
| 985 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 986 | static int orangefs_init_iops(struct inode *inode) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 987 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 988 | inode->i_mapping->a_ops = &orangefs_address_operations; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 989 | |
| 990 | switch (inode->i_mode & S_IFMT) { |
| 991 | case S_IFREG: |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 992 | inode->i_op = &orangefs_file_inode_operations; |
| 993 | inode->i_fop = &orangefs_file_operations; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 994 | break; |
| 995 | case S_IFLNK: |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 996 | inode->i_op = &orangefs_symlink_inode_operations; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 997 | break; |
| 998 | case S_IFDIR: |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 999 | inode->i_op = &orangefs_dir_inode_operations; |
| 1000 | inode->i_fop = &orangefs_dir_operations; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1001 | break; |
| 1002 | default: |
| 1003 | gossip_debug(GOSSIP_INODE_DEBUG, |
| 1004 | "%s: unsupported mode\n", |
| 1005 | __func__); |
| 1006 | return -EINVAL; |
| 1007 | } |
| 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | /* |
Mike Marshall | 95f5f88 | 2018-05-11 17:11:48 -0400 | [diff] [blame] | 1013 | * Given an ORANGEFS object identifier (fsid, handle), convert it into |
| 1014 | * a ino_t type that will be used as a hash-index from where the handle will |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1015 | * be searched for in the VFS hash table of inodes. |
| 1016 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1017 | static inline ino_t orangefs_handle_hash(struct orangefs_object_kref *ref) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1018 | { |
| 1019 | if (!ref) |
| 1020 | return 0; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1021 | return orangefs_khandle_to_ino(&(ref->khandle)); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /* |
| 1025 | * Called to set up an inode from iget5_locked. |
| 1026 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1027 | static int orangefs_set_inode(struct inode *inode, void *data) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1028 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1029 | struct orangefs_object_kref *ref = (struct orangefs_object_kref *) data; |
Martin Brandenburg | a4c680a | 2016-03-16 14:35:21 -0400 | [diff] [blame] | 1030 | ORANGEFS_I(inode)->refn.fs_id = ref->fs_id; |
| 1031 | ORANGEFS_I(inode)->refn.khandle = ref->khandle; |
Martin Brandenburg | afd9fb2 | 2018-02-13 20:13:46 +0000 | [diff] [blame] | 1032 | ORANGEFS_I(inode)->attr_valid = 0; |
Martin Brandenburg | fc2e2e9 | 2017-12-12 13:46:30 -0500 | [diff] [blame] | 1033 | hash_init(ORANGEFS_I(inode)->xattr_cache); |
Martin Brandenburg | 8f04e1b | 2019-02-12 20:19:06 +0000 | [diff] [blame] | 1034 | ORANGEFS_I(inode)->mapping_time = jiffies - 1; |
| 1035 | ORANGEFS_I(inode)->bitlock = 0; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1036 | return 0; |
| 1037 | } |
| 1038 | |
| 1039 | /* |
| 1040 | * Called to determine if handles match. |
| 1041 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1042 | static int orangefs_test_inode(struct inode *inode, void *data) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1043 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1044 | struct orangefs_object_kref *ref = (struct orangefs_object_kref *) data; |
| 1045 | struct orangefs_inode_s *orangefs_inode = NULL; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1046 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1047 | orangefs_inode = ORANGEFS_I(inode); |
Mike Marshall | 95f5f88 | 2018-05-11 17:11:48 -0400 | [diff] [blame] | 1048 | /* test handles and fs_ids... */ |
| 1049 | return (!ORANGEFS_khandle_cmp(&(orangefs_inode->refn.khandle), |
| 1050 | &(ref->khandle)) && |
| 1051 | orangefs_inode->refn.fs_id == ref->fs_id); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | /* |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1055 | * Front-end to lookup the inode-cache maintained by the VFS using the ORANGEFS |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1056 | * file handle. |
| 1057 | * |
| 1058 | * @sb: the file system super block instance. |
Mike Marshall | 95f5f88 | 2018-05-11 17:11:48 -0400 | [diff] [blame] | 1059 | * @ref: The ORANGEFS object for which we are trying to locate an inode. |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1060 | */ |
Mike Marshall | 95f5f88 | 2018-05-11 17:11:48 -0400 | [diff] [blame] | 1061 | struct inode *orangefs_iget(struct super_block *sb, |
| 1062 | struct orangefs_object_kref *ref) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1063 | { |
| 1064 | struct inode *inode = NULL; |
| 1065 | unsigned long hash; |
| 1066 | int error; |
| 1067 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1068 | hash = orangefs_handle_hash(ref); |
Mike Marshall | 95f5f88 | 2018-05-11 17:11:48 -0400 | [diff] [blame] | 1069 | inode = iget5_locked(sb, |
| 1070 | hash, |
| 1071 | orangefs_test_inode, |
| 1072 | orangefs_set_inode, |
| 1073 | ref); |
Mike Marshall | b5d72cd | 2018-10-18 13:52:23 -0400 | [diff] [blame] | 1074 | |
| 1075 | if (!inode) |
| 1076 | return ERR_PTR(-ENOMEM); |
| 1077 | |
| 1078 | if (!(inode->i_state & I_NEW)) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1079 | return inode; |
| 1080 | |
Martin Brandenburg | 8b60785 | 2018-02-07 18:44:50 +0000 | [diff] [blame] | 1081 | error = orangefs_inode_getattr(inode, ORANGEFS_GETATTR_NEW); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1082 | if (error) { |
| 1083 | iget_failed(inode); |
| 1084 | return ERR_PTR(error); |
| 1085 | } |
| 1086 | |
| 1087 | inode->i_ino = hash; /* needed for stat etc */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1088 | orangefs_init_iops(inode); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1089 | unlock_new_inode(inode); |
| 1090 | |
| 1091 | gossip_debug(GOSSIP_INODE_DEBUG, |
| 1092 | "iget handle %pU, fsid %d hash %ld i_ino %lu\n", |
| 1093 | &ref->khandle, |
| 1094 | ref->fs_id, |
| 1095 | hash, |
| 1096 | inode->i_ino); |
| 1097 | |
| 1098 | return inode; |
| 1099 | } |
| 1100 | |
| 1101 | /* |
| 1102 | * Allocate an inode for a newly created file and insert it into the inode hash. |
| 1103 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1104 | struct inode *orangefs_new_inode(struct super_block *sb, struct inode *dir, |
| 1105 | int mode, dev_t dev, struct orangefs_object_kref *ref) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1106 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1107 | unsigned long hash = orangefs_handle_hash(ref); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1108 | struct inode *inode; |
| 1109 | int error; |
| 1110 | |
| 1111 | gossip_debug(GOSSIP_INODE_DEBUG, |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 1112 | "%s:(sb is %p | MAJOR(dev)=%u | MINOR(dev)=%u mode=%o)\n", |
| 1113 | __func__, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1114 | sb, |
| 1115 | MAJOR(dev), |
| 1116 | MINOR(dev), |
| 1117 | mode); |
| 1118 | |
| 1119 | inode = new_inode(sb); |
| 1120 | if (!inode) |
Mike Marshall | 5624999 | 2018-10-18 13:47:16 -0400 | [diff] [blame] | 1121 | return ERR_PTR(-ENOMEM); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1122 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1123 | orangefs_set_inode(inode, ref); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1124 | inode->i_ino = hash; /* needed for stat etc */ |
| 1125 | |
Martin Brandenburg | 8b60785 | 2018-02-07 18:44:50 +0000 | [diff] [blame] | 1126 | error = orangefs_inode_getattr(inode, ORANGEFS_GETATTR_NEW); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1127 | if (error) |
| 1128 | goto out_iput; |
| 1129 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1130 | orangefs_init_iops(inode); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1131 | inode->i_rdev = dev; |
| 1132 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1133 | error = insert_inode_locked4(inode, hash, orangefs_test_inode, ref); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1134 | if (error < 0) |
| 1135 | goto out_iput; |
| 1136 | |
| 1137 | gossip_debug(GOSSIP_INODE_DEBUG, |
| 1138 | "Initializing ACL's for inode %pU\n", |
| 1139 | get_khandle_from_ino(inode)); |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 1140 | orangefs_init_acl(inode, dir); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1141 | return inode; |
| 1142 | |
| 1143 | out_iput: |
| 1144 | iput(inode); |
| 1145 | return ERR_PTR(error); |
| 1146 | } |