1 /* handling of writes to regular files and writing back to the server 2 * 3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 4 * Written by David Howells (dhowells@redhat.com) 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 9 * 2 of the License, or (at your option) any later version. 10 */ 11 12 #include <linux/backing-dev.h> 13 #include <linux/slab.h> 14 #include <linux/fs.h> 15 #include <linux/pagemap.h> 16 #include <linux/writeback.h> 17 #include <linux/pagevec.h> 18 #include "internal.h" 19 20 /* 21 * We use page->private to hold the amount of the page that we've written to, 22 * splitting the field into two parts. However, we need to represent a range 23 * 0...PAGE_SIZE inclusive, so we can't support 64K pages on a 32-bit system. 24 */ 25 #if PAGE_SIZE > 32768 26 #define AFS_PRIV_MAX 0xffffffff 27 #define AFS_PRIV_SHIFT 32 28 #else 29 #define AFS_PRIV_MAX 0xffff 30 #define AFS_PRIV_SHIFT 16 31 #endif 32 33 /* 34 * mark a page as having been made dirty and thus needing writeback 35 */ 36 int afs_set_page_dirty(struct page *page) 37 { 38 _enter(""); 39 return __set_page_dirty_nobuffers(page); 40 } 41 42 /* 43 * partly or wholly fill a page that's under preparation for writing 44 */ 45 static int afs_fill_page(struct afs_vnode *vnode, struct key *key, 46 loff_t pos, unsigned int len, struct page *page) 47 { 48 struct afs_read *req; 49 int ret; 50 51 _enter(",,%llu", (unsigned long long)pos); 52 53 req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *), 54 GFP_KERNEL); 55 if (!req) 56 return -ENOMEM; 57 58 atomic_set(&req->usage, 1); 59 req->pos = pos; 60 req->len = len; 61 req->nr_pages = 1; 62 req->pages[0] = page; 63 get_page(page); 64 65 ret = afs_fetch_data(vnode, key, req); 66 afs_put_read(req); 67 if (ret < 0) { 68 if (ret == -ENOENT) { 69 _debug("got NOENT from server" 70 " - marking file deleted and stale"); 71 set_bit(AFS_VNODE_DELETED, &vnode->flags); 72 ret = -ESTALE; 73 } 74 } 75 76 _leave(" = %d", ret); 77 return ret; 78 } 79 80 /* 81 * prepare to perform part of a write to a page 82 */ 83 int afs_write_begin(struct file *file, struct address_space *mapping, 84 loff_t pos, unsigned len, unsigned flags, 85 struct page **pagep, void **fsdata) 86 { 87 struct afs_vnode *vnode = AFS_FS_I(file_inode(file)); 88 struct page *page; 89 struct key *key = afs_file_key(file); 90 unsigned long priv; 91 unsigned f, from = pos & (PAGE_SIZE - 1); 92 unsigned t, to = from + len; 93 pgoff_t index = pos >> PAGE_SHIFT; 94 int ret; 95 96 _enter("{%x:%u},{%lx},%u,%u", 97 vnode->fid.vid, vnode->fid.vnode, index, from, to); 98 99 /* We want to store information about how much of a page is altered in 100 * page->private. 101 */ 102 BUILD_BUG_ON(PAGE_SIZE > 32768 && sizeof(page->private) < 8); 103 104 page = grab_cache_page_write_begin(mapping, index, flags); 105 if (!page) 106 return -ENOMEM; 107 108 if (!PageUptodate(page) && len != PAGE_SIZE) { 109 ret = afs_fill_page(vnode, key, pos & PAGE_MASK, PAGE_SIZE, page); 110 if (ret < 0) { 111 unlock_page(page); 112 put_page(page); 113 _leave(" = %d [prep]", ret); 114 return ret; 115 } 116 SetPageUptodate(page); 117 } 118 119 /* page won't leak in error case: it eventually gets cleaned off LRU */ 120 *pagep = page; 121 122 try_again: 123 /* See if this page is already partially written in a way that we can 124 * merge the new write with. 125 */ 126 t = f = 0; 127 if (PagePrivate(page)) { 128 priv = page_private(page); 129 f = priv & AFS_PRIV_MAX; 130 t = priv >> AFS_PRIV_SHIFT; 131 ASSERTCMP(f, <=, t); 132 } 133 134 if (f != t) { 135 if (to < f || from > t) 136 goto flush_conflicting_write; 137 if (from < f) 138 f = from; 139 if (to > t) 140 t = to; 141 } else { 142 f = from; 143 t = to; 144 } 145 146 priv = (unsigned long)t << AFS_PRIV_SHIFT; 147 priv |= f; 148 SetPagePrivate(page); 149 set_page_private(page, priv); 150 _leave(" = 0"); 151 return 0; 152 153 /* The previous write and this write aren't adjacent or overlapping, so 154 * flush the page out. 155 */ 156 flush_conflicting_write: 157 _debug("flush conflict"); 158 ret = write_one_page(page); 159 if (ret < 0) { 160 _leave(" = %d", ret); 161 return ret; 162 } 163 164 ret = lock_page_killable(page); 165 if (ret < 0) { 166 _leave(" = %d", ret); 167 return ret; 168 } 169 goto try_again; 170 } 171 172 /* 173 * finalise part of a write to a page 174 */ 175 int afs_write_end(struct file *file, struct address_space *mapping, 176 loff_t pos, unsigned len, unsigned copied, 177 struct page *page, void *fsdata) 178 { 179 struct afs_vnode *vnode = AFS_FS_I(file_inode(file)); 180 struct key *key = afs_file_key(file); 181 loff_t i_size, maybe_i_size; 182 int ret; 183 184 _enter("{%x:%u},{%lx}", 185 vnode->fid.vid, vnode->fid.vnode, page->index); 186 187 maybe_i_size = pos + copied; 188 189 i_size = i_size_read(&vnode->vfs_inode); 190 if (maybe_i_size > i_size) { 191 spin_lock(&vnode->wb_lock); 192 i_size = i_size_read(&vnode->vfs_inode); 193 if (maybe_i_size > i_size) 194 i_size_write(&vnode->vfs_inode, maybe_i_size); 195 spin_unlock(&vnode->wb_lock); 196 } 197 198 if (!PageUptodate(page)) { 199 if (copied < len) { 200 /* Try and load any missing data from the server. The 201 * unmarshalling routine will take care of clearing any 202 * bits that are beyond the EOF. 203 */ 204 ret = afs_fill_page(vnode, key, pos + copied, 205 len - copied, page); 206 if (ret < 0) 207 return ret; 208 } 209 SetPageUptodate(page); 210 } 211 212 set_page_dirty(page); 213 if (PageDirty(page)) 214 _debug("dirtied"); 215 unlock_page(page); 216 put_page(page); 217 218 return copied; 219 } 220 221 /* 222 * kill all the pages in the given range 223 */ 224 static void afs_kill_pages(struct address_space *mapping, 225 pgoff_t first, pgoff_t last) 226 { 227 struct afs_vnode *vnode = AFS_FS_I(mapping->host); 228 struct pagevec pv; 229 unsigned count, loop; 230 231 _enter("{%x:%u},%lx-%lx", 232 vnode->fid.vid, vnode->fid.vnode, first, last); 233 234 pagevec_init(&pv, 0); 235 236 do { 237 _debug("kill %lx-%lx", first, last); 238 239 count = last - first + 1; 240 if (count > PAGEVEC_SIZE) 241 count = PAGEVEC_SIZE; 242 pv.nr = find_get_pages_contig(mapping, first, count, pv.pages); 243 ASSERTCMP(pv.nr, ==, count); 244 245 for (loop = 0; loop < count; loop++) { 246 struct page *page = pv.pages[loop]; 247 ClearPageUptodate(page); 248 SetPageError(page); 249 end_page_writeback(page); 250 if (page->index >= first) 251 first = page->index + 1; 252 lock_page(page); 253 generic_error_remove_page(mapping, page); 254 } 255 256 __pagevec_release(&pv); 257 } while (first <= last); 258 259 _leave(""); 260 } 261 262 /* 263 * Redirty all the pages in a given range. 264 */ 265 static void afs_redirty_pages(struct writeback_control *wbc, 266 struct address_space *mapping, 267 pgoff_t first, pgoff_t last) 268 { 269 struct afs_vnode *vnode = AFS_FS_I(mapping->host); 270 struct pagevec pv; 271 unsigned count, loop; 272 273 _enter("{%x:%u},%lx-%lx", 274 vnode->fid.vid, vnode->fid.vnode, first, last); 275 276 pagevec_init(&pv, 0); 277 278 do { 279 _debug("redirty %lx-%lx", first, last); 280 281 count = last - first + 1; 282 if (count > PAGEVEC_SIZE) 283 count = PAGEVEC_SIZE; 284 pv.nr = find_get_pages_contig(mapping, first, count, pv.pages); 285 ASSERTCMP(pv.nr, ==, count); 286 287 for (loop = 0; loop < count; loop++) { 288 struct page *page = pv.pages[loop]; 289 290 redirty_page_for_writepage(wbc, page); 291 end_page_writeback(page); 292 if (page->index >= first) 293 first = page->index + 1; 294 } 295 296 __pagevec_release(&pv); 297 } while (first <= last); 298 299 _leave(""); 300 } 301 302 /* 303 * write to a file 304 */ 305 static int afs_store_data(struct address_space *mapping, 306 pgoff_t first, pgoff_t last, 307 unsigned offset, unsigned to) 308 { 309 struct afs_vnode *vnode = AFS_FS_I(mapping->host); 310 struct afs_fs_cursor fc; 311 struct afs_wb_key *wbk = NULL; 312 struct list_head *p; 313 int ret = -ENOKEY, ret2; 314 315 _enter("%s{%x:%u.%u},%lx,%lx,%x,%x", 316 vnode->volume->name, 317 vnode->fid.vid, 318 vnode->fid.vnode, 319 vnode->fid.unique, 320 first, last, offset, to); 321 322 spin_lock(&vnode->wb_lock); 323 p = vnode->wb_keys.next; 324 325 /* Iterate through the list looking for a valid key to use. */ 326 try_next_key: 327 while (p != &vnode->wb_keys) { 328 wbk = list_entry(p, struct afs_wb_key, vnode_link); 329 _debug("wbk %u", key_serial(wbk->key)); 330 ret2 = key_validate(wbk->key); 331 if (ret2 == 0) 332 goto found_key; 333 if (ret == -ENOKEY) 334 ret = ret2; 335 p = p->next; 336 } 337 338 spin_unlock(&vnode->wb_lock); 339 afs_put_wb_key(wbk); 340 _leave(" = %d [no keys]", ret); 341 return ret; 342 343 found_key: 344 refcount_inc(&wbk->usage); 345 spin_unlock(&vnode->wb_lock); 346 347 _debug("USE WB KEY %u", key_serial(wbk->key)); 348 349 ret = -ERESTARTSYS; 350 if (afs_begin_vnode_operation(&fc, vnode, wbk->key)) { 351 while (afs_select_fileserver(&fc)) { 352 fc.cb_break = vnode->cb_break + vnode->cb_s_break; 353 afs_fs_store_data(&fc, mapping, first, last, offset, to); 354 } 355 356 afs_check_for_remote_deletion(&fc, fc.vnode); 357 afs_vnode_commit_status(&fc, vnode, fc.cb_break); 358 ret = afs_end_vnode_operation(&fc); 359 } 360 361 switch (ret) { 362 case -EACCES: 363 case -EPERM: 364 case -ENOKEY: 365 case -EKEYEXPIRED: 366 case -EKEYREJECTED: 367 case -EKEYREVOKED: 368 _debug("next"); 369 spin_lock(&vnode->wb_lock); 370 p = wbk->vnode_link.next; 371 afs_put_wb_key(wbk); 372 goto try_next_key; 373 } 374 375 afs_put_wb_key(wbk); 376 _leave(" = %d", ret); 377 return ret; 378 } 379 380 /* 381 * Synchronously write back the locked page and any subsequent non-locked dirty 382 * pages. 383 */ 384 static int afs_write_back_from_locked_page(struct address_space *mapping, 385 struct writeback_control *wbc, 386 struct page *primary_page, 387 pgoff_t final_page) 388 { 389 struct page *pages[8], *page; 390 unsigned long count, priv; 391 unsigned n, offset, to, f, t; 392 pgoff_t start, first, last; 393 int loop, ret; 394 395 _enter(",%lx", primary_page->index); 396 397 count = 1; 398 if (test_set_page_writeback(primary_page)) 399 BUG(); 400 401 /* Find all consecutive lockable dirty pages that have contiguous 402 * written regions, stopping when we find a page that is not 403 * immediately lockable, is not dirty or is missing, or we reach the 404 * end of the range. 405 */ 406 start = primary_page->index; 407 priv = page_private(primary_page); 408 offset = priv & AFS_PRIV_MAX; 409 to = priv >> AFS_PRIV_SHIFT; 410 411 WARN_ON(offset == to); 412 413 if (start >= final_page || to < PAGE_SIZE) 414 goto no_more; 415 416 start++; 417 do { 418 _debug("more %lx [%lx]", start, count); 419 n = final_page - start + 1; 420 if (n > ARRAY_SIZE(pages)) 421 n = ARRAY_SIZE(pages); 422 n = find_get_pages_contig(mapping, start, ARRAY_SIZE(pages), pages); 423 _debug("fgpc %u", n); 424 if (n == 0) 425 goto no_more; 426 if (pages[0]->index != start) { 427 do { 428 put_page(pages[--n]); 429 } while (n > 0); 430 goto no_more; 431 } 432 433 for (loop = 0; loop < n; loop++) { 434 if (to != PAGE_SIZE) 435 break; 436 page = pages[loop]; 437 if (page->index > final_page) 438 break; 439 if (!trylock_page(page)) 440 break; 441 if (!PageDirty(page) || PageWriteback(page)) { 442 unlock_page(page); 443 break; 444 } 445 446 priv = page_private(page); 447 f = priv & AFS_PRIV_MAX; 448 t = priv >> AFS_PRIV_SHIFT; 449 if (f != 0) { 450 unlock_page(page); 451 break; 452 } 453 to = t; 454 455 if (!clear_page_dirty_for_io(page)) 456 BUG(); 457 if (test_set_page_writeback(page)) 458 BUG(); 459 unlock_page(page); 460 put_page(page); 461 } 462 count += loop; 463 if (loop < n) { 464 for (; loop < n; loop++) 465 put_page(pages[loop]); 466 goto no_more; 467 } 468 469 start += loop; 470 } while (start <= final_page && count < 65536); 471 472 no_more: 473 /* We now have a contiguous set of dirty pages, each with writeback 474 * set; the first page is still locked at this point, but all the rest 475 * have been unlocked. 476 */ 477 unlock_page(primary_page); 478 479 first = primary_page->index; 480 last = first + count - 1; 481 482 _debug("write back %lx[%u..] to %lx[..%u]", first, offset, last, to); 483 484 ret = afs_store_data(mapping, first, last, offset, to); 485 switch (ret) { 486 case 0: 487 ret = count; 488 break; 489 490 default: 491 pr_notice("kAFS: Unexpected error from FS.StoreData %d\n", ret); 492 /* Fall through */ 493 case -EACCES: 494 case -EPERM: 495 case -ENOKEY: 496 case -EKEYEXPIRED: 497 case -EKEYREJECTED: 498 case -EKEYREVOKED: 499 afs_redirty_pages(wbc, mapping, first, last); 500 mapping_set_error(mapping, ret); 501 break; 502 503 case -EDQUOT: 504 case -ENOSPC: 505 afs_redirty_pages(wbc, mapping, first, last); 506 mapping_set_error(mapping, -ENOSPC); 507 break; 508 509 case -EROFS: 510 case -EIO: 511 case -EREMOTEIO: 512 case -EFBIG: 513 case -ENOENT: 514 case -ENOMEDIUM: 515 case -ENXIO: 516 afs_kill_pages(mapping, first, last); 517 mapping_set_error(mapping, ret); 518 break; 519 } 520 521 _leave(" = %d", ret); 522 return ret; 523 } 524 525 /* 526 * write a page back to the server 527 * - the caller locked the page for us 528 */ 529 int afs_writepage(struct page *page, struct writeback_control *wbc) 530 { 531 int ret; 532 533 _enter("{%lx},", page->index); 534 535 ret = afs_write_back_from_locked_page(page->mapping, wbc, page, 536 wbc->range_end >> PAGE_SHIFT); 537 if (ret < 0) { 538 _leave(" = %d", ret); 539 return 0; 540 } 541 542 wbc->nr_to_write -= ret; 543 544 _leave(" = 0"); 545 return 0; 546 } 547 548 /* 549 * write a region of pages back to the server 550 */ 551 static int afs_writepages_region(struct address_space *mapping, 552 struct writeback_control *wbc, 553 pgoff_t index, pgoff_t end, pgoff_t *_next) 554 { 555 struct page *page; 556 int ret, n; 557 558 _enter(",,%lx,%lx,", index, end); 559 560 do { 561 n = find_get_pages_tag(mapping, &index, PAGECACHE_TAG_DIRTY, 562 1, &page); 563 if (!n) 564 break; 565 566 _debug("wback %lx", page->index); 567 568 if (page->index > end) { 569 *_next = index; 570 put_page(page); 571 _leave(" = 0 [%lx]", *_next); 572 return 0; 573 } 574 575 /* at this point we hold neither mapping->tree_lock nor lock on 576 * the page itself: the page may be truncated or invalidated 577 * (changing page->mapping to NULL), or even swizzled back from 578 * swapper_space to tmpfs file mapping 579 */ 580 ret = lock_page_killable(page); 581 if (ret < 0) { 582 put_page(page); 583 _leave(" = %d", ret); 584 return ret; 585 } 586 587 if (page->mapping != mapping || !PageDirty(page)) { 588 unlock_page(page); 589 put_page(page); 590 continue; 591 } 592 593 if (PageWriteback(page)) { 594 unlock_page(page); 595 if (wbc->sync_mode != WB_SYNC_NONE) 596 wait_on_page_writeback(page); 597 put_page(page); 598 continue; 599 } 600 601 if (!clear_page_dirty_for_io(page)) 602 BUG(); 603 ret = afs_write_back_from_locked_page(mapping, wbc, page, end); 604 put_page(page); 605 if (ret < 0) { 606 _leave(" = %d", ret); 607 return ret; 608 } 609 610 wbc->nr_to_write -= ret; 611 612 cond_resched(); 613 } while (index < end && wbc->nr_to_write > 0); 614 615 *_next = index; 616 _leave(" = 0 [%lx]", *_next); 617 return 0; 618 } 619 620 /* 621 * write some of the pending data back to the server 622 */ 623 int afs_writepages(struct address_space *mapping, 624 struct writeback_control *wbc) 625 { 626 pgoff_t start, end, next; 627 int ret; 628 629 _enter(""); 630 631 if (wbc->range_cyclic) { 632 start = mapping->writeback_index; 633 end = -1; 634 ret = afs_writepages_region(mapping, wbc, start, end, &next); 635 if (start > 0 && wbc->nr_to_write > 0 && ret == 0) 636 ret = afs_writepages_region(mapping, wbc, 0, start, 637 &next); 638 mapping->writeback_index = next; 639 } else if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) { 640 end = (pgoff_t)(LLONG_MAX >> PAGE_SHIFT); 641 ret = afs_writepages_region(mapping, wbc, 0, end, &next); 642 if (wbc->nr_to_write > 0) 643 mapping->writeback_index = next; 644 } else { 645 start = wbc->range_start >> PAGE_SHIFT; 646 end = wbc->range_end >> PAGE_SHIFT; 647 ret = afs_writepages_region(mapping, wbc, start, end, &next); 648 } 649 650 _leave(" = %d", ret); 651 return ret; 652 } 653 654 /* 655 * completion of write to server 656 */ 657 void afs_pages_written_back(struct afs_vnode *vnode, struct afs_call *call) 658 { 659 struct pagevec pv; 660 unsigned count, loop; 661 pgoff_t first = call->first, last = call->last; 662 663 _enter("{%x:%u},{%lx-%lx}", 664 vnode->fid.vid, vnode->fid.vnode, first, last); 665 666 pagevec_init(&pv, 0); 667 668 do { 669 _debug("done %lx-%lx", first, last); 670 671 count = last - first + 1; 672 if (count > PAGEVEC_SIZE) 673 count = PAGEVEC_SIZE; 674 pv.nr = find_get_pages_contig(vnode->vfs_inode.i_mapping, 675 first, count, pv.pages); 676 ASSERTCMP(pv.nr, ==, count); 677 678 for (loop = 0; loop < count; loop++) { 679 set_page_private(pv.pages[loop], 0); 680 end_page_writeback(pv.pages[loop]); 681 } 682 first += count; 683 __pagevec_release(&pv); 684 } while (first <= last); 685 686 afs_prune_wb_keys(vnode); 687 _leave(""); 688 } 689 690 /* 691 * write to an AFS file 692 */ 693 ssize_t afs_file_write(struct kiocb *iocb, struct iov_iter *from) 694 { 695 struct afs_vnode *vnode = AFS_FS_I(file_inode(iocb->ki_filp)); 696 ssize_t result; 697 size_t count = iov_iter_count(from); 698 699 _enter("{%x.%u},{%zu},", 700 vnode->fid.vid, vnode->fid.vnode, count); 701 702 if (IS_SWAPFILE(&vnode->vfs_inode)) { 703 printk(KERN_INFO 704 "AFS: Attempt to write to active swap file!\n"); 705 return -EBUSY; 706 } 707 708 if (!count) 709 return 0; 710 711 result = generic_file_write_iter(iocb, from); 712 713 _leave(" = %zd", result); 714 return result; 715 } 716 717 /* 718 * flush any dirty pages for this process, and check for write errors. 719 * - the return status from this call provides a reliable indication of 720 * whether any write errors occurred for this process. 721 */ 722 int afs_fsync(struct file *file, loff_t start, loff_t end, int datasync) 723 { 724 struct inode *inode = file_inode(file); 725 struct afs_vnode *vnode = AFS_FS_I(inode); 726 727 _enter("{%x:%u},{n=%pD},%d", 728 vnode->fid.vid, vnode->fid.vnode, file, 729 datasync); 730 731 return file_write_and_wait_range(file, start, end); 732 } 733 734 /* 735 * Flush out all outstanding writes on a file opened for writing when it is 736 * closed. 737 */ 738 int afs_flush(struct file *file, fl_owner_t id) 739 { 740 _enter(""); 741 742 if ((file->f_mode & FMODE_WRITE) == 0) 743 return 0; 744 745 return vfs_fsync(file, 0); 746 } 747 748 /* 749 * notification that a previously read-only page is about to become writable 750 * - if it returns an error, the caller will deliver a bus error signal 751 */ 752 int afs_page_mkwrite(struct vm_area_struct *vma, struct page *page) 753 { 754 struct afs_vnode *vnode = AFS_FS_I(vma->vm_file->f_mapping->host); 755 756 _enter("{{%x:%u}},{%lx}", 757 vnode->fid.vid, vnode->fid.vnode, page->index); 758 759 /* wait for the page to be written to the cache before we allow it to 760 * be modified */ 761 #ifdef CONFIG_AFS_FSCACHE 762 fscache_wait_on_page_write(vnode->cache, page); 763 #endif 764 765 _leave(" = 0"); 766 return 0; 767 } 768 769 /* 770 * Prune the keys cached for writeback. The caller must hold vnode->wb_lock. 771 */ 772 void afs_prune_wb_keys(struct afs_vnode *vnode) 773 { 774 LIST_HEAD(graveyard); 775 struct afs_wb_key *wbk, *tmp; 776 777 /* Discard unused keys */ 778 spin_lock(&vnode->wb_lock); 779 780 if (!mapping_tagged(&vnode->vfs_inode.i_data, PAGECACHE_TAG_WRITEBACK) && 781 !mapping_tagged(&vnode->vfs_inode.i_data, PAGECACHE_TAG_DIRTY)) { 782 list_for_each_entry_safe(wbk, tmp, &vnode->wb_keys, vnode_link) { 783 if (refcount_read(&wbk->usage) == 1) 784 list_move(&wbk->vnode_link, &graveyard); 785 } 786 } 787 788 spin_unlock(&vnode->wb_lock); 789 790 while (!list_empty(&graveyard)) { 791 wbk = list_entry(graveyard.next, struct afs_wb_key, vnode_link); 792 list_del(&wbk->vnode_link); 793 afs_put_wb_key(wbk); 794 } 795 } 796 797 /* 798 * Clean up a page during invalidation. 799 */ 800 int afs_launder_page(struct page *page) 801 { 802 struct address_space *mapping = page->mapping; 803 struct afs_vnode *vnode = AFS_FS_I(mapping->host); 804 unsigned long priv; 805 unsigned int f, t; 806 int ret = 0; 807 808 _enter("{%lx}", page->index); 809 810 priv = page_private(page); 811 if (clear_page_dirty_for_io(page)) { 812 f = 0; 813 t = PAGE_SIZE; 814 if (PagePrivate(page)) { 815 f = priv & AFS_PRIV_MAX; 816 t = priv >> AFS_PRIV_SHIFT; 817 } 818 819 ret = afs_store_data(mapping, page->index, page->index, t, f); 820 } 821 822 set_page_private(page, 0); 823 ClearPagePrivate(page); 824 825 #ifdef CONFIG_AFS_FSCACHE 826 if (PageFsCache(page)) { 827 fscache_wait_on_page_write(vnode->cache, page); 828 fscache_uncache_page(vnode->cache, page); 829 } 830 #endif 831 return ret; 832 } 833