| 1 | |
| 2 | |
| 3 | * (C) 2001 Clemson University and The University of Chicago
|
| 4 | * Copyright 2018 Omnibond Systems, L.L.C.
|
| 5 | *
|
| 6 | * See COPYING in top-level directory.
|
| 7 |
|
| 8 |
|
| 9 | |
| 10 | * Linux VFS inode operations.
|
| 11 |
|
| 12 |
|
| 13 | #include <linux/blkdev.h>
|
| 14 | #include <linux/fileattr.h>
|
| 15 | #include "protocol.h"
|
| 16 | #include "orangefs-kernel.h"
|
| 17 | #include "orangefs-bufmap.h"
|
| 18 |
|
| 19 | static int orangefs_writepage_locked(struct folio *folio,
|
| 20 | struct writeback_control *wbc)
|
| 21 | {
|
| 22 | struct inode *inode = folio->mapping->host;
|
| 23 | struct orangefs_write_range *wr = NULL;
|
| 24 | struct iov_iter iter;
|
| 25 | struct bio_vec bv;
|
| 26 | size_t wlen;
|
| 27 | ssize_t ret;
|
| 28 | loff_t len, off;
|
| 29 |
|
| 30 | folio_start_writeback(folio);
|
| 31 |
|
| 32 | len = i_size_read(inode);
|
| 33 | if (folio->private) {
|
| 34 | wr = folio->private;
|
| 35 | off = wr->pos;
|
| 36 | if ((off + wr->len > len) && (off <= len))
|
| 37 | wlen = len - off;
|
| 38 | else
|
| 39 | wlen = wr->len;
|
| 40 | if (wlen == 0)
|
| 41 | wlen = wr->len;
|
| 42 | } else {
|
| 43 | WARN_ON(1);
|
| 44 | off = folio_pos(folio);
|
| 45 | wlen = folio_size(folio);
|
| 46 |
|
| 47 | if (wlen > len - off)
|
| 48 | wlen = len - off;
|
| 49 | }
|
| 50 |
|
| 51 | WARN_ON(wlen == 0);
|
| 52 | bvec_set_folio(&bv, folio, wlen, offset_in_folio(folio, off));
|
| 53 | iov_iter_bvec(&iter, ITER_SOURCE, &bv, 1, wlen);
|
| 54 |
|
| 55 | ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, wlen,
|
| 56 | len, wr, NULL, NULL);
|
| 57 | if (ret < 0) {
|
| 58 | mapping_set_error(folio->mapping, ret);
|
| 59 | } else {
|
| 60 | ret = 0;
|
| 61 | }
|
| 62 | kfree(folio_detach_private(folio));
|
| 63 | return ret;
|
| 64 | }
|
| 65 |
|
| 66 | struct orangefs_writepages {
|
| 67 | loff_t off;
|
| 68 | size_t len;
|
| 69 | kuid_t uid;
|
| 70 | kgid_t gid;
|
| 71 | int maxpages;
|
| 72 | int nfolios;
|
| 73 | struct address_space *mapping;
|
| 74 | struct folio **folios;
|
| 75 | struct bio_vec *bv;
|
| 76 | };
|
| 77 |
|
| 78 | static int orangefs_writepages_work(struct orangefs_writepages *ow,
|
| 79 | struct writeback_control *wbc)
|
| 80 | {
|
| 81 | struct inode *inode = ow->mapping->host;
|
| 82 | struct orangefs_write_range *wrp, wr;
|
| 83 | struct iov_iter iter;
|
| 84 | ssize_t ret;
|
| 85 | size_t start;
|
| 86 | loff_t len, off;
|
| 87 | int i;
|
| 88 |
|
| 89 | len = i_size_read(inode);
|
| 90 |
|
| 91 | start = offset_in_folio(ow->folios[0], ow->off);
|
| 92 | for (i = 0; i < ow->nfolios; i++) {
|
| 93 | folio_start_writeback(ow->folios[i]);
|
| 94 | bvec_set_folio(&ow->bv[i], ow->folios[i],
|
| 95 | folio_size(ow->folios[i]) - start, start);
|
| 96 | start = 0;
|
| 97 | }
|
| 98 | iov_iter_bvec(&iter, ITER_SOURCE, ow->bv, ow->nfolios, ow->len);
|
| 99 |
|
| 100 | WARN_ON(ow->off >= len);
|
| 101 | if (ow->off + ow->len > len)
|
| 102 | ow->len = len - ow->off;
|
| 103 |
|
| 104 | off = ow->off;
|
| 105 | wr.uid = ow->uid;
|
| 106 | wr.gid = ow->gid;
|
| 107 | ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, ow->len,
|
| 108 | 0, &wr, NULL, NULL);
|
| 109 | if (ret < 0)
|
| 110 | mapping_set_error(ow->mapping, ret);
|
| 111 | else
|
| 112 | ret = 0;
|
| 113 |
|
| 114 | for (i = 0; i < ow->nfolios; i++) {
|
| 115 | wrp = folio_detach_private(ow->folios[i]);
|
| 116 | kfree(wrp);
|
| 117 | folio_end_writeback(ow->folios[i]);
|
| 118 | folio_unlock(ow->folios[i]);
|
| 119 | }
|
| 120 |
|
| 121 | return ret;
|
| 122 | }
|
| 123 |
|
| 124 | static int orangefs_writepages_callback(struct folio *folio,
|
| 125 | struct writeback_control *wbc, struct orangefs_writepages *ow)
|
| 126 | {
|
| 127 | struct orangefs_write_range *wr = folio->private;
|
| 128 | int ret;
|
| 129 |
|
| 130 | if (!wr) {
|
| 131 | folio_unlock(folio);
|
| 132 |
|
| 133 | printk("writepages_callback not private!\n");
|
| 134 | BUG();
|
| 135 | return 0;
|
| 136 | }
|
| 137 |
|
| 138 | ret = -1;
|
| 139 | if (ow->nfolios == 0) {
|
| 140 | ow->off = wr->pos;
|
| 141 | ow->len = wr->len;
|
| 142 | ow->uid = wr->uid;
|
| 143 | ow->gid = wr->gid;
|
| 144 | ow->folios[ow->nfolios++] = folio;
|
| 145 | ret = 0;
|
| 146 | goto done;
|
| 147 | }
|
| 148 | if (!uid_eq(ow->uid, wr->uid) || !gid_eq(ow->gid, wr->gid)) {
|
| 149 | orangefs_writepages_work(ow, wbc);
|
| 150 | ow->nfolios = 0;
|
| 151 | ret = -1;
|
| 152 | goto done;
|
| 153 | }
|
| 154 | if (ow->off + ow->len == wr->pos) {
|
| 155 | ow->len += wr->len;
|
| 156 | ow->folios[ow->nfolios++] = folio;
|
| 157 | ret = 0;
|
| 158 | goto done;
|
| 159 | }
|
| 160 | done:
|
| 161 | if (ret == -1) {
|
| 162 | if (ow->nfolios) {
|
| 163 | orangefs_writepages_work(ow, wbc);
|
| 164 | ow->nfolios = 0;
|
| 165 | }
|
| 166 | ret = orangefs_writepage_locked(folio, wbc);
|
| 167 | mapping_set_error(folio->mapping, ret);
|
| 168 | folio_unlock(folio);
|
| 169 | folio_end_writeback(folio);
|
| 170 | } else {
|
| 171 | if (ow->nfolios == ow->maxpages) {
|
| 172 | orangefs_writepages_work(ow, wbc);
|
| 173 | ow->nfolios = 0;
|
| 174 | }
|
| 175 | }
|
| 176 | return ret;
|
| 177 | }
|
| 178 |
|
| 179 | static int orangefs_writepages(struct address_space *mapping,
|
| 180 | struct writeback_control *wbc)
|
| 181 | {
|
| 182 | struct orangefs_writepages *ow;
|
| 183 | struct blk_plug plug;
|
| 184 | int error;
|
| 185 | struct folio *folio = NULL;
|
| 186 |
|
| 187 | ow = kzalloc_obj(struct orangefs_writepages);
|
| 188 | if (!ow)
|
| 189 | return -ENOMEM;
|
| 190 | ow->maxpages = orangefs_bufmap_size_query()/PAGE_SIZE;
|
| 191 | ow->folios = kzalloc_objs(struct folio *, ow->maxpages);
|
| 192 | if (!ow->folios) {
|
| 193 | kfree(ow);
|
| 194 | return -ENOMEM;
|
| 195 | }
|
| 196 | ow->bv = kzalloc_objs(struct bio_vec, ow->maxpages);
|
| 197 | if (!ow->bv) {
|
| 198 | kfree(ow->folios);
|
| 199 | kfree(ow);
|
| 200 | return -ENOMEM;
|
| 201 | }
|
| 202 | ow->mapping = mapping;
|
| 203 | blk_start_plug(&plug);
|
| 204 | while ((folio = writeback_iter(mapping, wbc, folio, &error)))
|
| 205 | error = orangefs_writepages_callback(folio, wbc, ow);
|
| 206 | if (ow->nfolios)
|
| 207 | error = orangefs_writepages_work(ow, wbc);
|
| 208 | blk_finish_plug(&plug);
|
| 209 | kfree(ow->folios);
|
| 210 | kfree(ow->bv);
|
| 211 | kfree(ow);
|
| 212 | return error;
|
| 213 | }
|
| 214 |
|
| 215 | static int orangefs_launder_folio(struct folio *);
|
| 216 |
|
| 217 | static void orangefs_readahead(struct readahead_control *rac)
|
| 218 | {
|
| 219 | loff_t offset;
|
| 220 | struct iov_iter iter;
|
| 221 | struct inode *inode = rac->mapping->host;
|
| 222 | struct xarray *i_pages;
|
| 223 | struct folio *folio;
|
| 224 | loff_t new_start = readahead_pos(rac);
|
| 225 | int ret;
|
| 226 | size_t new_len = 0;
|
| 227 | size_t this_size;
|
| 228 | size_t remaining;
|
| 229 |
|
| 230 | loff_t bytes_remaining = inode->i_size - readahead_pos(rac);
|
| 231 | loff_t pages_remaining = bytes_remaining / PAGE_SIZE;
|
| 232 |
|
| 233 | if (pages_remaining >= 1024)
|
| 234 | new_len = 4194304;
|
| 235 | else if (pages_remaining > readahead_count(rac))
|
| 236 | new_len = bytes_remaining;
|
| 237 |
|
| 238 | if (new_len)
|
| 239 | readahead_expand(rac, new_start, new_len);
|
| 240 |
|
| 241 | offset = readahead_pos(rac);
|
| 242 | i_pages = &rac->mapping->i_pages;
|
| 243 |
|
| 244 | iov_iter_xarray(&iter, ITER_DEST, i_pages,
|
| 245 | offset, readahead_length(rac));
|
| 246 |
|
| 247 | remaining = readahead_length(rac);
|
| 248 | while (remaining) {
|
| 249 | if (remaining > 4194304)
|
| 250 | this_size = 4194304;
|
| 251 | else
|
| 252 | this_size = remaining;
|
| 253 |
|
| 254 |
|
| 255 | if ((ret = wait_for_direct_io(ORANGEFS_IO_READ, inode,
|
| 256 | &offset, &iter, this_size,
|
| 257 | inode->i_size, NULL, NULL, rac->file)) < 0) {
|
| 258 | gossip_debug(GOSSIP_FILE_DEBUG,
|
| 259 | "%s: wait_for_direct_io failed. :%d: \n",
|
| 260 | __func__, ret);
|
| 261 | goto cleanup;
|
| 262 | } else {
|
| 263 | ret = 0;
|
| 264 | }
|
| 265 |
|
| 266 | remaining -= this_size;
|
| 267 | offset += this_size;
|
| 268 | }
|
| 269 |
|
| 270 | cleanup:
|
| 271 |
|
| 272 | while ((folio = readahead_folio(rac))) {
|
| 273 | if (!ret)
|
| 274 | folio_mark_uptodate(folio);
|
| 275 | folio_unlock(folio);
|
| 276 | }
|
| 277 | }
|
| 278 |
|
| 279 | static int orangefs_read_folio(struct file *file, struct folio *folio)
|
| 280 | {
|
| 281 | struct inode *inode = folio->mapping->host;
|
| 282 | struct iov_iter iter;
|
| 283 | struct bio_vec bv;
|
| 284 | ssize_t ret;
|
| 285 | loff_t off;
|
| 286 |
|
| 287 | if (folio_test_dirty(folio))
|
| 288 | orangefs_launder_folio(folio);
|
| 289 |
|
| 290 | off = folio_pos(folio);
|
| 291 | bvec_set_folio(&bv, folio, folio_size(folio), 0);
|
| 292 | iov_iter_bvec(&iter, ITER_DEST, &bv, 1, folio_size(folio));
|
| 293 |
|
| 294 | ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, &off, &iter,
|
| 295 | folio_size(folio), inode->i_size, NULL, NULL, file);
|
| 296 |
|
| 297 | iov_iter_zero(~0U, &iter);
|
| 298 |
|
| 299 | flush_dcache_folio(folio);
|
| 300 | if (ret > 0)
|
| 301 | ret = 0;
|
| 302 | folio_end_read(folio, ret == 0);
|
| 303 | return ret;
|
| 304 | }
|
| 305 |
|
| 306 | static int orangefs_write_begin(const struct kiocb *iocb,
|
| 307 | struct address_space *mapping, loff_t pos,
|
| 308 | unsigned len, struct folio **foliop,
|
| 309 | void **fsdata)
|
| 310 | {
|
| 311 | struct orangefs_write_range *wr;
|
| 312 | struct folio *folio;
|
| 313 | int ret;
|
| 314 |
|
| 315 | folio = __filemap_get_folio(mapping, pos / PAGE_SIZE, FGP_WRITEBEGIN,
|
| 316 | mapping_gfp_mask(mapping));
|
| 317 | if (IS_ERR(folio))
|
| 318 | return PTR_ERR(folio);
|
| 319 |
|
| 320 | *foliop = folio;
|
| 321 |
|
| 322 | if (folio_test_dirty(folio) && !folio_test_private(folio)) {
|
| 323 | |
| 324 | * Should be impossible. If it happens, launder the page
|
| 325 | * since we don't know what's dirty. This will WARN in
|
| 326 | * orangefs_writepage_locked.
|
| 327 |
|
| 328 | ret = orangefs_launder_folio(folio);
|
| 329 | if (ret)
|
| 330 | return ret;
|
| 331 | }
|
| 332 | if (folio_test_private(folio)) {
|
| 333 | struct orangefs_write_range *wr;
|
| 334 | wr = folio_get_private(folio);
|
| 335 | if (wr->pos + wr->len == pos &&
|
| 336 | uid_eq(wr->uid, current_fsuid()) &&
|
| 337 | gid_eq(wr->gid, current_fsgid())) {
|
| 338 | wr->len += len;
|
| 339 | goto okay;
|
| 340 | } else {
|
| 341 | wr->pos = pos;
|
| 342 | wr->len = len;
|
| 343 | ret = orangefs_launder_folio(folio);
|
| 344 | if (ret)
|
| 345 | return ret;
|
| 346 | }
|
| 347 | }
|
| 348 |
|
| 349 | wr = kmalloc_obj(*wr);
|
| 350 | if (!wr)
|
| 351 | return -ENOMEM;
|
| 352 |
|
| 353 | wr->pos = pos;
|
| 354 | wr->len = len;
|
| 355 | wr->uid = current_fsuid();
|
| 356 | wr->gid = current_fsgid();
|
| 357 | folio_attach_private(folio, wr);
|
| 358 | okay:
|
| 359 | return 0;
|
| 360 | }
|
| 361 |
|
| 362 | static int orangefs_write_end(const struct kiocb *iocb,
|
| 363 | struct address_space *mapping,
|
| 364 | loff_t pos, unsigned len, unsigned copied,
|
| 365 | struct folio *folio, void *fsdata)
|
| 366 | {
|
| 367 | struct inode *inode = folio->mapping->host;
|
| 368 | loff_t last_pos = pos + copied;
|
| 369 |
|
| 370 | |
| 371 | * No need to use i_size_read() here, the i_size
|
| 372 | * cannot change under us because we hold the i_mutex.
|
| 373 |
|
| 374 | if (last_pos > inode->i_size)
|
| 375 | i_size_write(inode, last_pos);
|
| 376 |
|
| 377 |
|
| 378 | if (!folio_test_uptodate(folio)) {
|
| 379 | unsigned from = pos & (PAGE_SIZE - 1);
|
| 380 | if (copied < len) {
|
| 381 | folio_zero_range(folio, from + copied, len - copied);
|
| 382 | }
|
| 383 |
|
| 384 | if (pos == folio_pos(folio) &&
|
| 385 | (len == PAGE_SIZE || pos + len == inode->i_size)) {
|
| 386 | folio_zero_segment(folio, from + copied, PAGE_SIZE);
|
| 387 | folio_mark_uptodate(folio);
|
| 388 | }
|
| 389 | }
|
| 390 |
|
| 391 | folio_mark_dirty(folio);
|
| 392 | folio_unlock(folio);
|
| 393 | folio_put(folio);
|
| 394 |
|
| 395 | mark_inode_dirty_sync(file_inode(iocb->ki_filp));
|
| 396 | return copied;
|
| 397 | }
|
| 398 |
|
| 399 | static void orangefs_invalidate_folio(struct folio *folio,
|
| 400 | size_t offset, size_t length)
|
| 401 | {
|
| 402 | struct orangefs_write_range *wr = folio_get_private(folio);
|
| 403 |
|
| 404 | if (offset == 0 && length == PAGE_SIZE) {
|
| 405 | kfree(folio_detach_private(folio));
|
| 406 | return;
|
| 407 |
|
| 408 | } else if (folio_pos(folio) + offset <= wr->pos &&
|
| 409 | wr->pos + wr->len <= folio_pos(folio) + offset + length) {
|
| 410 | kfree(folio_detach_private(folio));
|
| 411 |
|
| 412 | folio_cancel_dirty(folio);
|
| 413 | return;
|
| 414 |
|
| 415 | } else if (wr->pos < folio_pos(folio) + offset &&
|
| 416 | wr->pos + wr->len <= folio_pos(folio) + offset + length &&
|
| 417 | folio_pos(folio) + offset < wr->pos + wr->len) {
|
| 418 | size_t x;
|
| 419 | x = wr->pos + wr->len - (folio_pos(folio) + offset);
|
| 420 | WARN_ON(x > wr->len);
|
| 421 | wr->len -= x;
|
| 422 | wr->uid = current_fsuid();
|
| 423 | wr->gid = current_fsgid();
|
| 424 |
|
| 425 | } else if (folio_pos(folio) + offset <= wr->pos &&
|
| 426 | folio_pos(folio) + offset + length < wr->pos + wr->len &&
|
| 427 | wr->pos < folio_pos(folio) + offset + length) {
|
| 428 | size_t x;
|
| 429 | x = folio_pos(folio) + offset + length - wr->pos;
|
| 430 | WARN_ON(x > wr->len);
|
| 431 | wr->pos += x;
|
| 432 | wr->len -= x;
|
| 433 | wr->uid = current_fsuid();
|
| 434 | wr->gid = current_fsgid();
|
| 435 |
|
| 436 | } else if (wr->pos < folio_pos(folio) + offset &&
|
| 437 | folio_pos(folio) + offset + length < wr->pos + wr->len) {
|
| 438 |
|
| 439 | WARN_ON(1);
|
| 440 |
|
| 441 | |
| 442 | * should we just ignore this and write it out anyway?
|
| 443 | * it hardly makes sense
|
| 444 |
|
| 445 | return;
|
| 446 |
|
| 447 | } else {
|
| 448 |
|
| 449 | if (!((folio_pos(folio) + offset + length <= wr->pos) ^
|
| 450 | (wr->pos + wr->len <= folio_pos(folio) + offset))) {
|
| 451 | WARN_ON(1);
|
| 452 | printk("invalidate range offset %llu length %zu\n",
|
| 453 | folio_pos(folio) + offset, length);
|
| 454 | printk("write range offset %llu length %zu\n",
|
| 455 | wr->pos, wr->len);
|
| 456 | }
|
| 457 | return;
|
| 458 | }
|
| 459 |
|
| 460 | |
| 461 | * Above there are returns where wr is freed or where we WARN.
|
| 462 | * Thus the following runs if wr was modified above.
|
| 463 |
|
| 464 |
|
| 465 | orangefs_launder_folio(folio);
|
| 466 | }
|
| 467 |
|
| 468 | static bool orangefs_release_folio(struct folio *folio, gfp_t foo)
|
| 469 | {
|
| 470 | return !folio_test_private(folio);
|
| 471 | }
|
| 472 |
|
| 473 | static void orangefs_free_folio(struct folio *folio)
|
| 474 | {
|
| 475 | kfree(folio_detach_private(folio));
|
| 476 | }
|
| 477 |
|
| 478 | static int orangefs_launder_folio(struct folio *folio)
|
| 479 | {
|
| 480 | int r = 0;
|
| 481 | struct writeback_control wbc = {
|
| 482 | .sync_mode = WB_SYNC_ALL,
|
| 483 | .nr_to_write = 0,
|
| 484 | };
|
| 485 | folio_wait_writeback(folio);
|
| 486 | if (folio_clear_dirty_for_io(folio)) {
|
| 487 | r = orangefs_writepage_locked(folio, &wbc);
|
| 488 | folio_end_writeback(folio);
|
| 489 | }
|
| 490 | return r;
|
| 491 | }
|
| 492 |
|
| 493 | static ssize_t orangefs_direct_IO(struct kiocb *iocb,
|
| 494 | struct iov_iter *iter)
|
| 495 | {
|
| 496 | |
| 497 | * Comment from original do_readv_writev:
|
| 498 | * Common entry point for read/write/readv/writev
|
| 499 | * This function will dispatch it to either the direct I/O
|
| 500 | * or buffered I/O path depending on the mount options and/or
|
| 501 | * augmented/extended metadata attached to the file.
|
| 502 | * Note: File extended attributes override any mount options.
|
| 503 |
|
| 504 | struct file *file = iocb->ki_filp;
|
| 505 | loff_t pos = iocb->ki_pos;
|
| 506 | enum ORANGEFS_io_type type = iov_iter_rw(iter) == WRITE ?
|
| 507 | ORANGEFS_IO_WRITE : ORANGEFS_IO_READ;
|
| 508 | loff_t *offset = &pos;
|
| 509 | struct inode *inode = file->f_mapping->host;
|
| 510 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
|
| 511 | struct orangefs_khandle *handle = &orangefs_inode->refn.khandle;
|
| 512 | size_t count = iov_iter_count(iter);
|
| 513 | ssize_t total_count = 0;
|
| 514 | ssize_t ret = -EINVAL;
|
| 515 |
|
| 516 | gossip_debug(GOSSIP_FILE_DEBUG,
|
| 517 | "%s-BEGIN(%pU): count(%d) after estimate_max_iovecs.\n",
|
| 518 | __func__,
|
| 519 | handle,
|
| 520 | (int)count);
|
| 521 |
|
| 522 | if (type == ORANGEFS_IO_WRITE) {
|
| 523 | gossip_debug(GOSSIP_FILE_DEBUG,
|
| 524 | "%s(%pU): proceeding with offset : %llu, "
|
| 525 | "size %d\n",
|
| 526 | __func__,
|
| 527 | handle,
|
| 528 | llu(*offset),
|
| 529 | (int)count);
|
| 530 | }
|
| 531 |
|
| 532 | if (count == 0) {
|
| 533 | ret = 0;
|
| 534 | goto out;
|
| 535 | }
|
| 536 |
|
| 537 | while (iov_iter_count(iter)) {
|
| 538 | size_t each_count = iov_iter_count(iter);
|
| 539 | size_t amt_complete;
|
| 540 |
|
| 541 |
|
| 542 | if (each_count > orangefs_bufmap_size_query())
|
| 543 | each_count = orangefs_bufmap_size_query();
|
| 544 |
|
| 545 | gossip_debug(GOSSIP_FILE_DEBUG,
|
| 546 | "%s(%pU): size of each_count(%d)\n",
|
| 547 | __func__,
|
| 548 | handle,
|
| 549 | (int)each_count);
|
| 550 | gossip_debug(GOSSIP_FILE_DEBUG,
|
| 551 | "%s(%pU): BEFORE wait_for_io: offset is %d\n",
|
| 552 | __func__,
|
| 553 | handle,
|
| 554 | (int)*offset);
|
| 555 |
|
| 556 | ret = wait_for_direct_io(type, inode, offset, iter,
|
| 557 | each_count, 0, NULL, NULL, file);
|
| 558 | gossip_debug(GOSSIP_FILE_DEBUG,
|
| 559 | "%s(%pU): return from wait_for_io:%d\n",
|
| 560 | __func__,
|
| 561 | handle,
|
| 562 | (int)ret);
|
| 563 |
|
| 564 | if (ret < 0)
|
| 565 | goto out;
|
| 566 |
|
| 567 | *offset += ret;
|
| 568 | total_count += ret;
|
| 569 | amt_complete = ret;
|
| 570 |
|
| 571 | gossip_debug(GOSSIP_FILE_DEBUG,
|
| 572 | "%s(%pU): AFTER wait_for_io: offset is %d\n",
|
| 573 | __func__,
|
| 574 | handle,
|
| 575 | (int)*offset);
|
| 576 |
|
| 577 | |
| 578 | * if we got a short I/O operations,
|
| 579 | * fall out and return what we got so far
|
| 580 |
|
| 581 | if (amt_complete < each_count)
|
| 582 | break;
|
| 583 | }
|
| 584 |
|
| 585 | out:
|
| 586 | if (total_count > 0)
|
| 587 | ret = total_count;
|
| 588 | if (ret > 0) {
|
| 589 | if (type == ORANGEFS_IO_READ) {
|
| 590 | file_accessed(file);
|
| 591 | } else {
|
| 592 | file_update_time(file);
|
| 593 | if (*offset > i_size_read(inode))
|
| 594 | i_size_write(inode, *offset);
|
| 595 | }
|
| 596 | }
|
| 597 |
|
| 598 | gossip_debug(GOSSIP_FILE_DEBUG,
|
| 599 | "%s(%pU): Value(%d) returned.\n",
|
| 600 | __func__,
|
| 601 | handle,
|
| 602 | (int)ret);
|
| 603 |
|
| 604 | return ret;
|
| 605 | }
|
| 606 |
|
| 607 |
|
| 608 | static const struct address_space_operations orangefs_address_operations = {
|
| 609 | .readahead = orangefs_readahead,
|
| 610 | .read_folio = orangefs_read_folio,
|
| 611 | .writepages = orangefs_writepages,
|
| 612 | .dirty_folio = filemap_dirty_folio,
|
| 613 | .write_begin = orangefs_write_begin,
|
| 614 | .write_end = orangefs_write_end,
|
| 615 | .invalidate_folio = orangefs_invalidate_folio,
|
| 616 | .release_folio = orangefs_release_folio,
|
| 617 | .free_folio = orangefs_free_folio,
|
| 618 | .migrate_folio = filemap_migrate_folio,
|
| 619 | .launder_folio = orangefs_launder_folio,
|
| 620 | .direct_IO = orangefs_direct_IO,
|
| 621 | };
|
| 622 |
|
| 623 | vm_fault_t orangefs_page_mkwrite(struct vm_fault *vmf)
|
| 624 | {
|
| 625 | struct folio *folio = page_folio(vmf->page);
|
| 626 | struct inode *inode = file_inode(vmf->vma->vm_file);
|
| 627 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
|
| 628 | unsigned long *bitlock = &orangefs_inode->bitlock;
|
| 629 | vm_fault_t ret;
|
| 630 | struct orangefs_write_range *wr;
|
| 631 |
|
| 632 | sb_start_pagefault(inode->i_sb);
|
| 633 |
|
| 634 | if (wait_on_bit(bitlock, 1, TASK_KILLABLE)) {
|
| 635 | ret = VM_FAULT_RETRY;
|
| 636 | goto out;
|
| 637 | }
|
| 638 |
|
| 639 | folio_lock(folio);
|
| 640 | if (folio_test_dirty(folio) && !folio_test_private(folio)) {
|
| 641 | |
| 642 | * Should be impossible. If it happens, launder the folio
|
| 643 | * since we don't know what's dirty. This will WARN in
|
| 644 | * orangefs_writepage_locked.
|
| 645 |
|
| 646 | if (orangefs_launder_folio(folio)) {
|
| 647 | ret = VM_FAULT_LOCKED|VM_FAULT_RETRY;
|
| 648 | goto out;
|
| 649 | }
|
| 650 | }
|
| 651 | if (folio_test_private(folio)) {
|
| 652 | wr = folio_get_private(folio);
|
| 653 | if (uid_eq(wr->uid, current_fsuid()) &&
|
| 654 | gid_eq(wr->gid, current_fsgid())) {
|
| 655 | wr->pos = folio_pos(folio);
|
| 656 | wr->len = folio_size(folio);
|
| 657 | goto okay;
|
| 658 | } else {
|
| 659 | if (orangefs_launder_folio(folio)) {
|
| 660 | ret = VM_FAULT_LOCKED|VM_FAULT_RETRY;
|
| 661 | goto out;
|
| 662 | }
|
| 663 | }
|
| 664 | }
|
| 665 | wr = kmalloc_obj(*wr);
|
| 666 | if (!wr) {
|
| 667 | ret = VM_FAULT_LOCKED|VM_FAULT_RETRY;
|
| 668 | goto out;
|
| 669 | }
|
| 670 | wr->pos = folio_pos(folio);
|
| 671 | wr->len = folio_size(folio);
|
| 672 | wr->uid = current_fsuid();
|
| 673 | wr->gid = current_fsgid();
|
| 674 | folio_attach_private(folio, wr);
|
| 675 | okay:
|
| 676 |
|
| 677 | file_update_time(vmf->vma->vm_file);
|
| 678 | if (folio->mapping != inode->i_mapping) {
|
| 679 | folio_unlock(folio);
|
| 680 | ret = VM_FAULT_LOCKED|VM_FAULT_NOPAGE;
|
| 681 | goto out;
|
| 682 | }
|
| 683 |
|
| 684 | |
| 685 | * We mark the folio dirty already here so that when freeze is in
|
| 686 | * progress, we are guaranteed that writeback during freezing will
|
| 687 | * see the dirty folio and writeprotect it again.
|
| 688 |
|
| 689 | folio_mark_dirty(folio);
|
| 690 | folio_wait_stable(folio);
|
| 691 | ret = VM_FAULT_LOCKED;
|
| 692 | out:
|
| 693 | sb_end_pagefault(inode->i_sb);
|
| 694 | return ret;
|
| 695 | }
|
| 696 |
|
| 697 | static int orangefs_setattr_size(struct inode *inode, struct iattr *iattr)
|
| 698 | {
|
| 699 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
|
| 700 | struct orangefs_kernel_op_s *new_op;
|
| 701 | loff_t orig_size;
|
| 702 | int ret = -EINVAL;
|
| 703 |
|
| 704 | gossip_debug(GOSSIP_INODE_DEBUG,
|
| 705 | "%s: %pU: Handle is %pU | fs_id %d | size is %llu\n",
|
| 706 | __func__,
|
| 707 | get_khandle_from_ino(inode),
|
| 708 | &orangefs_inode->refn.khandle,
|
| 709 | orangefs_inode->refn.fs_id,
|
| 710 | iattr->ia_size);
|
| 711 |
|
| 712 |
|
| 713 | ret = orangefs_inode_getattr(inode, ORANGEFS_GETATTR_SIZE);
|
| 714 | if (ret == -ESTALE)
|
| 715 | ret = -EIO;
|
| 716 | if (ret) {
|
| 717 | gossip_err("%s: orangefs_inode_getattr failed, ret:%d:.\n",
|
| 718 | __func__, ret);
|
| 719 | return ret;
|
| 720 | }
|
| 721 | orig_size = i_size_read(inode);
|
| 722 |
|
| 723 |
|
| 724 | truncate_pagecache(inode, iattr->ia_size);
|
| 725 | i_size_write(inode, iattr->ia_size);
|
| 726 | if (iattr->ia_size > orig_size)
|
| 727 | pagecache_isize_extended(inode, orig_size, iattr->ia_size);
|
| 728 |
|
| 729 | new_op = op_alloc(ORANGEFS_VFS_OP_TRUNCATE);
|
| 730 | if (!new_op)
|
| 731 | return -ENOMEM;
|
| 732 |
|
| 733 | new_op->upcall.req.truncate.refn = orangefs_inode->refn;
|
| 734 | new_op->upcall.req.truncate.size = (__s64) iattr->ia_size;
|
| 735 |
|
| 736 | ret = service_operation(new_op,
|
| 737 | __func__,
|
| 738 | get_interruptible_flag(inode));
|
| 739 |
|
| 740 | |
| 741 | * the truncate has no downcall members to retrieve, but
|
| 742 | * the status value tells us if it went through ok or not
|
| 743 |
|
| 744 | gossip_debug(GOSSIP_INODE_DEBUG, "%s: ret:%d:\n", __func__, ret);
|
| 745 |
|
| 746 | op_release(new_op);
|
| 747 |
|
| 748 | if (ret != 0)
|
| 749 | return ret;
|
| 750 |
|
| 751 | if (orig_size != i_size_read(inode))
|
| 752 | iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
|
| 753 |
|
| 754 | return ret;
|
| 755 | }
|
| 756 |
|
| 757 | int __orangefs_setattr(struct inode *inode, struct iattr *iattr)
|
| 758 | {
|
| 759 | int ret;
|
| 760 |
|
| 761 | if (iattr->ia_valid & ATTR_MODE) {
|
| 762 | if (iattr->ia_mode & (S_ISVTX)) {
|
| 763 | if (is_root_handle(inode)) {
|
| 764 | |
| 765 | * allow sticky bit to be set on root (since
|
| 766 | * it shows up that way by default anyhow),
|
| 767 | * but don't show it to the server
|
| 768 |
|
| 769 | iattr->ia_mode -= S_ISVTX;
|
| 770 | } else {
|
| 771 | gossip_debug(GOSSIP_UTILS_DEBUG,
|
| 772 | "User attempted to set sticky bit on non-root directory; returning EINVAL.\n");
|
| 773 | ret = -EINVAL;
|
| 774 | goto out;
|
| 775 | }
|
| 776 | }
|
| 777 | if (iattr->ia_mode & (S_ISUID)) {
|
| 778 | gossip_debug(GOSSIP_UTILS_DEBUG,
|
| 779 | "Attempting to set setuid bit (not supported); returning EINVAL.\n");
|
| 780 | ret = -EINVAL;
|
| 781 | goto out;
|
| 782 | }
|
| 783 | }
|
| 784 |
|
| 785 | if (iattr->ia_valid & ATTR_SIZE) {
|
| 786 | ret = orangefs_setattr_size(inode, iattr);
|
| 787 | if (ret)
|
| 788 | goto out;
|
| 789 | }
|
| 790 |
|
| 791 | again:
|
| 792 | spin_lock(&inode->i_lock);
|
| 793 | if (ORANGEFS_I(inode)->attr_valid) {
|
| 794 | if (uid_eq(ORANGEFS_I(inode)->attr_uid, current_fsuid()) &&
|
| 795 | gid_eq(ORANGEFS_I(inode)->attr_gid, current_fsgid())) {
|
| 796 | ORANGEFS_I(inode)->attr_valid = iattr->ia_valid;
|
| 797 | } else {
|
| 798 | spin_unlock(&inode->i_lock);
|
| 799 | write_inode_now(inode, 1);
|
| 800 | goto again;
|
| 801 | }
|
| 802 | } else {
|
| 803 | ORANGEFS_I(inode)->attr_valid = iattr->ia_valid;
|
| 804 | ORANGEFS_I(inode)->attr_uid = current_fsuid();
|
| 805 | ORANGEFS_I(inode)->attr_gid = current_fsgid();
|
| 806 | }
|
| 807 | setattr_copy(&nop_mnt_idmap, inode, iattr);
|
| 808 | spin_unlock(&inode->i_lock);
|
| 809 | mark_inode_dirty(inode);
|
| 810 |
|
| 811 | ret = 0;
|
| 812 | out:
|
| 813 | return ret;
|
| 814 | }
|
| 815 |
|
| 816 | int __orangefs_setattr_mode(struct dentry *dentry, struct iattr *iattr)
|
| 817 | {
|
| 818 | int ret;
|
| 819 | struct inode *inode = d_inode(dentry);
|
| 820 |
|
| 821 | ret = __orangefs_setattr(inode, iattr);
|
| 822 |
|
| 823 | if (!ret && (iattr->ia_valid & ATTR_MODE))
|
| 824 | ret = posix_acl_chmod(&nop_mnt_idmap, dentry, inode->i_mode);
|
| 825 | return ret;
|
| 826 | }
|
| 827 |
|
| 828 | |
| 829 | * Change attributes of an object referenced by dentry.
|
| 830 |
|
| 831 | int orangefs_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
|
| 832 | struct iattr *iattr)
|
| 833 | {
|
| 834 | int ret;
|
| 835 | gossip_debug(GOSSIP_INODE_DEBUG, "__orangefs_setattr: called on %pd\n",
|
| 836 | dentry);
|
| 837 | ret = setattr_prepare(&nop_mnt_idmap, dentry, iattr);
|
| 838 | if (ret)
|
| 839 | goto out;
|
| 840 | ret = __orangefs_setattr_mode(dentry, iattr);
|
| 841 | sync_inode_metadata(d_inode(dentry), 1);
|
| 842 | out:
|
| 843 | gossip_debug(GOSSIP_INODE_DEBUG, "orangefs_setattr: returning %d\n",
|
| 844 | ret);
|
| 845 | return ret;
|
| 846 | }
|
| 847 |
|
| 848 | |
| 849 | * Obtain attributes of an object given a dentry
|
| 850 |
|
| 851 | int orangefs_getattr(const struct mnt_idmap *idmap, const struct path *path,
|
| 852 | struct kstat *stat, u32 request_mask, unsigned int flags)
|
| 853 | {
|
| 854 | int ret;
|
| 855 | struct inode *inode = path->dentry->d_inode;
|
| 856 |
|
| 857 | gossip_debug(GOSSIP_INODE_DEBUG,
|
| 858 | "orangefs_getattr: called on %pd mask %u\n",
|
| 859 | path->dentry, request_mask);
|
| 860 |
|
| 861 | ret = orangefs_inode_getattr(inode,
|
| 862 | request_mask & STATX_SIZE ? ORANGEFS_GETATTR_SIZE : 0);
|
| 863 | if (ret == 0) {
|
| 864 | generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
|
| 865 |
|
| 866 |
|
| 867 | if (!(request_mask & STATX_SIZE))
|
| 868 | stat->result_mask &= ~STATX_SIZE;
|
| 869 |
|
| 870 | generic_fill_statx_attr(inode, stat);
|
| 871 | }
|
| 872 | return ret;
|
| 873 | }
|
| 874 |
|
| 875 | int orangefs_permission(const struct mnt_idmap *idmap,
|
| 876 | struct inode *inode, int mask)
|
| 877 | {
|
| 878 | int ret;
|
| 879 |
|
| 880 | if (mask & MAY_NOT_BLOCK)
|
| 881 | return -ECHILD;
|
| 882 |
|
| 883 | gossip_debug(GOSSIP_INODE_DEBUG, "%s: refreshing\n", __func__);
|
| 884 |
|
| 885 |
|
| 886 | ret = orangefs_inode_getattr(inode, 0);
|
| 887 | if (ret < 0)
|
| 888 | return ret;
|
| 889 |
|
| 890 | return generic_permission(&nop_mnt_idmap, inode, mask);
|
| 891 | }
|
| 892 |
|
| 893 | int orangefs_update_time(struct inode *inode, enum fs_update_time type,
|
| 894 | unsigned int flags)
|
| 895 | {
|
| 896 | struct iattr iattr = { };
|
| 897 | int dirty;
|
| 898 |
|
| 899 | if (flags & IOCB_NOWAIT)
|
| 900 | return -EAGAIN;
|
| 901 |
|
| 902 | switch (type) {
|
| 903 | case FS_UPD_ATIME:
|
| 904 | iattr.ia_valid = ATTR_ATIME;
|
| 905 | break;
|
| 906 | case FS_UPD_CMTIME:
|
| 907 | iattr.ia_valid = ATTR_CTIME | ATTR_MTIME;
|
| 908 | break;
|
| 909 | }
|
| 910 |
|
| 911 | dirty = inode_update_time(inode, type, flags);
|
| 912 | if (dirty <= 0)
|
| 913 | return dirty;
|
| 914 | return __orangefs_setattr(inode, &iattr);
|
| 915 | }
|
| 916 |
|
| 917 | static int orangefs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
|
| 918 | {
|
| 919 | u64 val = 0;
|
| 920 | int ret;
|
| 921 |
|
| 922 | gossip_debug(GOSSIP_FILE_DEBUG, "%s: called on %pd\n", __func__,
|
| 923 | dentry);
|
| 924 |
|
| 925 | ret = orangefs_inode_getxattr(d_inode(dentry),
|
| 926 | "user.pvfs2.meta_hint",
|
| 927 | &val, sizeof(val));
|
| 928 | if (ret < 0 && ret != -ENODATA)
|
| 929 | return ret;
|
| 930 |
|
| 931 | gossip_debug(GOSSIP_FILE_DEBUG, "%s: flags=%u\n", __func__, (u32) val);
|
| 932 |
|
| 933 | fileattr_fill_flags(fa, val);
|
| 934 | return 0;
|
| 935 | }
|
| 936 |
|
| 937 | static int orangefs_fileattr_set(const struct mnt_idmap *idmap,
|
| 938 | struct dentry *dentry, struct file_kattr *fa)
|
| 939 | {
|
| 940 | u64 val = 0;
|
| 941 |
|
| 942 | gossip_debug(GOSSIP_FILE_DEBUG, "%s: called on %pd\n", __func__,
|
| 943 | dentry);
|
| 944 | |
| 945 | * ORANGEFS_MIRROR_FL is set internally when the mirroring mode is
|
| 946 | * turned on for a file. The user is not allowed to turn on this bit,
|
| 947 | * but the bit is present if the user first gets the flags and then
|
| 948 | * updates the flags with some new settings. So, we ignore it in the
|
| 949 | * following edit. bligon.
|
| 950 |
|
| 951 | if (fileattr_has_fsx(fa) ||
|
| 952 | (fa->flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NOATIME_FL | ORANGEFS_MIRROR_FL))) {
|
| 953 | gossip_err("%s: only supports setting one of FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NOATIME_FL\n",
|
| 954 | __func__);
|
| 955 | return -EOPNOTSUPP;
|
| 956 | }
|
| 957 | val = fa->flags;
|
| 958 | gossip_debug(GOSSIP_FILE_DEBUG, "%s: flags=%u\n", __func__, (u32) val);
|
| 959 | return orangefs_inode_setxattr(d_inode(dentry),
|
| 960 | "user.pvfs2.meta_hint",
|
| 961 | &val, sizeof(val), 0);
|
| 962 | }
|
| 963 |
|
| 964 |
|
| 965 | static const struct inode_operations orangefs_file_inode_operations = {
|
| 966 | .get_inode_acl = orangefs_get_acl,
|
| 967 | .set_acl = orangefs_set_acl,
|
| 968 | .setattr = orangefs_setattr,
|
| 969 | .getattr = orangefs_getattr,
|
| 970 | .listxattr = orangefs_listxattr,
|
| 971 | .permission = orangefs_permission,
|
| 972 | .update_time = orangefs_update_time,
|
| 973 | .fileattr_get = orangefs_fileattr_get,
|
| 974 | .fileattr_set = orangefs_fileattr_set,
|
| 975 | };
|
| 976 |
|
| 977 | static int orangefs_init_iops(struct inode *inode)
|
| 978 | {
|
| 979 | inode->i_mapping->a_ops = &orangefs_address_operations;
|
| 980 |
|
| 981 | switch (inode->i_mode & S_IFMT) {
|
| 982 | case S_IFREG:
|
| 983 | inode->i_op = &orangefs_file_inode_operations;
|
| 984 | inode->i_fop = &orangefs_file_operations;
|
| 985 | break;
|
| 986 | case S_IFLNK:
|
| 987 | inode->i_op = &orangefs_symlink_inode_operations;
|
| 988 | break;
|
| 989 | case S_IFDIR:
|
| 990 | inode->i_op = &orangefs_dir_inode_operations;
|
| 991 | inode->i_fop = &orangefs_dir_operations;
|
| 992 | break;
|
| 993 | default:
|
| 994 | gossip_debug(GOSSIP_INODE_DEBUG,
|
| 995 | "%s: unsupported mode\n",
|
| 996 | __func__);
|
| 997 | return -EINVAL;
|
| 998 | }
|
| 999 |
|
| 1000 | return 0;
|
| 1001 | }
|
| 1002 |
|
| 1003 | |
| 1004 | * Given an ORANGEFS object identifier (fsid, handle), convert it into
|
| 1005 | * a ino_t type that will be used as a hash-index from where the handle will
|
| 1006 | * be searched for in the VFS hash table of inodes.
|
| 1007 |
|
| 1008 | static inline ino_t orangefs_handle_hash(struct orangefs_object_kref *ref)
|
| 1009 | {
|
| 1010 | if (!ref)
|
| 1011 | return 0;
|
| 1012 | return orangefs_khandle_to_ino(&(ref->khandle));
|
| 1013 | }
|
| 1014 |
|
| 1015 | |
| 1016 | * Called to set up an inode from iget5_locked.
|
| 1017 |
|
| 1018 | static int orangefs_set_inode(struct inode *inode, void *data)
|
| 1019 | {
|
| 1020 | struct orangefs_object_kref *ref = (struct orangefs_object_kref *) data;
|
| 1021 | ORANGEFS_I(inode)->refn.fs_id = ref->fs_id;
|
| 1022 | ORANGEFS_I(inode)->refn.khandle = ref->khandle;
|
| 1023 | ORANGEFS_I(inode)->attr_valid = 0;
|
| 1024 | hash_init(ORANGEFS_I(inode)->xattr_cache);
|
| 1025 | ORANGEFS_I(inode)->mapping_time = jiffies - 1;
|
| 1026 | ORANGEFS_I(inode)->bitlock = 0;
|
| 1027 | return 0;
|
| 1028 | }
|
| 1029 |
|
| 1030 | |
| 1031 | * Called to determine if handles match.
|
| 1032 |
|
| 1033 | static int orangefs_test_inode(struct inode *inode, void *data)
|
| 1034 | {
|
| 1035 | struct orangefs_object_kref *ref = (struct orangefs_object_kref *) data;
|
| 1036 | struct orangefs_inode_s *orangefs_inode = NULL;
|
| 1037 |
|
| 1038 | orangefs_inode = ORANGEFS_I(inode);
|
| 1039 |
|
| 1040 | return (!ORANGEFS_khandle_cmp(&(orangefs_inode->refn.khandle),
|
| 1041 | &(ref->khandle)) &&
|
| 1042 | orangefs_inode->refn.fs_id == ref->fs_id);
|
| 1043 | }
|
| 1044 |
|
| 1045 | |
| 1046 | * Front-end to lookup the inode-cache maintained by the VFS using the ORANGEFS
|
| 1047 | * file handle.
|
| 1048 | *
|
| 1049 | * @sb: the file system super block instance.
|
| 1050 | * @ref: The ORANGEFS object for which we are trying to locate an inode.
|
| 1051 |
|
| 1052 | struct inode *orangefs_iget(struct super_block *sb,
|
| 1053 | struct orangefs_object_kref *ref)
|
| 1054 | {
|
| 1055 | struct inode *inode = NULL;
|
| 1056 | unsigned long hash;
|
| 1057 | int error;
|
| 1058 |
|
| 1059 | hash = orangefs_handle_hash(ref);
|
| 1060 | inode = iget5_locked(sb,
|
| 1061 | hash,
|
| 1062 | orangefs_test_inode,
|
| 1063 | orangefs_set_inode,
|
| 1064 | ref);
|
| 1065 |
|
| 1066 | if (!inode)
|
| 1067 | return ERR_PTR(-ENOMEM);
|
| 1068 |
|
| 1069 | if (!(inode_state_read_once(inode) & I_NEW))
|
| 1070 | return inode;
|
| 1071 |
|
| 1072 | error = orangefs_inode_getattr(inode, ORANGEFS_GETATTR_NEW);
|
| 1073 | if (error) {
|
| 1074 | iget_failed(inode);
|
| 1075 | return ERR_PTR(error);
|
| 1076 | }
|
| 1077 |
|
| 1078 | inode->i_ino = hash;
|
| 1079 | orangefs_init_iops(inode);
|
| 1080 | unlock_new_inode(inode);
|
| 1081 |
|
| 1082 | gossip_debug(GOSSIP_INODE_DEBUG,
|
| 1083 | "iget handle %pU, fsid %d hash %ld i_ino %llu\n",
|
| 1084 | &ref->khandle,
|
| 1085 | ref->fs_id,
|
| 1086 | hash,
|
| 1087 | inode->i_ino);
|
| 1088 |
|
| 1089 | return inode;
|
| 1090 | }
|
| 1091 |
|
| 1092 | |
| 1093 | * Allocate an inode for a newly created file and insert it into the inode hash.
|
| 1094 |
|
| 1095 | struct inode *orangefs_new_inode(struct super_block *sb, struct inode *dir,
|
| 1096 | umode_t mode, dev_t dev, struct orangefs_object_kref *ref)
|
| 1097 | {
|
| 1098 | struct posix_acl *acl = NULL, *default_acl = NULL;
|
| 1099 | unsigned long hash = orangefs_handle_hash(ref);
|
| 1100 | struct inode *inode;
|
| 1101 | int error;
|
| 1102 |
|
| 1103 | gossip_debug(GOSSIP_INODE_DEBUG,
|
| 1104 | "%s:(sb is %p | MAJOR(dev)=%u | MINOR(dev)=%u mode=%o)\n",
|
| 1105 | __func__,
|
| 1106 | sb,
|
| 1107 | MAJOR(dev),
|
| 1108 | MINOR(dev),
|
| 1109 | mode);
|
| 1110 |
|
| 1111 | inode = new_inode(sb);
|
| 1112 | if (!inode)
|
| 1113 | return ERR_PTR(-ENOMEM);
|
| 1114 |
|
| 1115 | error = posix_acl_create(dir, &mode, &default_acl, &acl);
|
| 1116 | if (error)
|
| 1117 | goto out_iput;
|
| 1118 |
|
| 1119 | orangefs_set_inode(inode, ref);
|
| 1120 | inode->i_ino = hash;
|
| 1121 |
|
| 1122 | error = orangefs_inode_getattr(inode, ORANGEFS_GETATTR_NEW);
|
| 1123 | if (error)
|
| 1124 | goto out_iput;
|
| 1125 |
|
| 1126 | orangefs_init_iops(inode);
|
| 1127 | inode->i_rdev = dev;
|
| 1128 |
|
| 1129 | if (default_acl) {
|
| 1130 | error = __orangefs_set_acl(inode, default_acl,
|
| 1131 | ACL_TYPE_DEFAULT);
|
| 1132 | if (error)
|
| 1133 | goto out_iput;
|
| 1134 | }
|
| 1135 |
|
| 1136 | if (acl) {
|
| 1137 | error = __orangefs_set_acl(inode, acl, ACL_TYPE_ACCESS);
|
| 1138 | if (error)
|
| 1139 | goto out_iput;
|
| 1140 | }
|
| 1141 |
|
| 1142 | error = insert_inode_locked4(inode, hash, orangefs_test_inode, ref);
|
| 1143 | if (error < 0)
|
| 1144 | goto out_iput;
|
| 1145 |
|
| 1146 | gossip_debug(GOSSIP_INODE_DEBUG,
|
| 1147 | "Initializing ACL's for inode %pU\n",
|
| 1148 | get_khandle_from_ino(inode));
|
| 1149 | if (mode != inode->i_mode) {
|
| 1150 | struct iattr iattr = {
|
| 1151 | .ia_mode = mode,
|
| 1152 | .ia_valid = ATTR_MODE,
|
| 1153 | };
|
| 1154 | inode->i_mode = mode;
|
| 1155 | __orangefs_setattr(inode, &iattr);
|
| 1156 | __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
|
| 1157 | }
|
| 1158 | posix_acl_release(acl);
|
| 1159 | posix_acl_release(default_acl);
|
| 1160 | return inode;
|
| 1161 |
|
| 1162 | out_iput:
|
| 1163 | iput(inode);
|
| 1164 | posix_acl_release(acl);
|
| 1165 | posix_acl_release(default_acl);
|
| 1166 | return ERR_PTR(error);
|
| 1167 | }
|