Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'nfs-for-6.4-1' of git://git.linux-nfs.org/projects/anna/linux-nfs

Pull NFS client updates from Anna Schumaker:
"New Features:

- Convert the readdir path to use folios

- Convert the NFS fscache code to use netfs

Bugfixes and Cleanups:

- Always send a RECLAIM_COMPLETE after establishing a lease

- Simplify sysctl registrations and other cleanups

- Handle out-of-order write replies on NFS v3

- Have sunrpc call_bind_status use standard hard/soft task semantics

- Other minor cleanups"

* tag 'nfs-for-6.4-1' of git://git.linux-nfs.org/projects/anna/linux-nfs:
NFSv4.2: Rework scratch handling for READ_PLUS
NFS: Cleanup unused rpc_clnt variable
NFS: set varaiable nfs_netfs_debug_id storage-class-specifier to static
SUNRPC: remove the maximum number of retries in call_bind_status
NFS: Convert readdir page array functions to use a folio
NFS: Convert the readdir array-of-pages into an array-of-folios
NFSv3: handle out-of-order write replies.
NFS: Remove fscache specific trace points and NFS_INO_FSCACHE bit
NFS: Remove all NFSIOS_FSCACHE counters due to conversion to netfs API
NFS: Convert buffered read paths to use netfs when fscache is enabled
NFS: Configure support for netfs when NFS fscache is configured
NFS: Rename readpage_async_filler to nfs_read_add_folio
sunrpc: simplify one-level sysctl registration for debug_table
sunrpc: move sunrpc_table and proc routines above
sunrpc: simplify one-level sysctl registration for xs_tunables_table
sunrpc: simplify one-level sysctl registration for xr_tunables_table
nfs: simplify two-level sysctl registration for nfs_cb_sysctls
nfs: simplify two-level sysctl registration for nfs4_cb_sysctls
lockd: simplify two-level sysctl registration for nlm_sysctls
NFSv4.1: Always send a RECLAIM_COMPLETE after establishing lease

+650 -568
+1
fs/nfs/Kconfig
··· 170 170 config NFS_FSCACHE 171 171 bool "Provide NFS client caching support" 172 172 depends on NFS_FS=m && FSCACHE || NFS_FS=y && FSCACHE=y 173 + select NETFS_SUPPORT 173 174 help 174 175 Say Y here if you want NFS data to be cached locally on disc through 175 176 the general filesystem cache manager
+149 -151
fs/nfs/dir.c
··· 55 55 static int nfs_readdir(struct file *, struct dir_context *); 56 56 static int nfs_fsync_dir(struct file *, loff_t, loff_t, int); 57 57 static loff_t nfs_llseek_dir(struct file *, loff_t, int); 58 - static void nfs_readdir_free_folio(struct folio *); 58 + static void nfs_readdir_clear_array(struct folio *); 59 59 60 60 const struct file_operations nfs_dir_operations = { 61 61 .llseek = nfs_llseek_dir, ··· 67 67 }; 68 68 69 69 const struct address_space_operations nfs_dir_aops = { 70 - .free_folio = nfs_readdir_free_folio, 70 + .free_folio = nfs_readdir_clear_array, 71 71 }; 72 72 73 73 #define NFS_INIT_DTSIZE PAGE_SIZE ··· 146 146 u64 change_attr; 147 147 u64 last_cookie; 148 148 unsigned int size; 149 - unsigned char page_full : 1, 150 - page_is_eof : 1, 149 + unsigned char folio_full : 1, 150 + folio_is_eof : 1, 151 151 cookies_are_ordered : 1; 152 152 struct nfs_cache_array_entry array[]; 153 153 }; 154 154 155 155 struct nfs_readdir_descriptor { 156 156 struct file *file; 157 - struct page *page; 157 + struct folio *folio; 158 158 struct dir_context *ctx; 159 - pgoff_t page_index; 160 - pgoff_t page_index_max; 159 + pgoff_t folio_index; 160 + pgoff_t folio_index_max; 161 161 u64 dir_cookie; 162 162 u64 last_cookie; 163 163 loff_t current_index; ··· 198 198 nfs_set_dtsize(desc, desc->dtsize << 1); 199 199 } 200 200 201 - static void nfs_readdir_page_init_array(struct page *page, u64 last_cookie, 202 - u64 change_attr) 201 + static void nfs_readdir_folio_init_array(struct folio *folio, u64 last_cookie, 202 + u64 change_attr) 203 203 { 204 204 struct nfs_cache_array *array; 205 205 206 - array = kmap_local_page(page); 206 + array = kmap_local_folio(folio, 0); 207 207 array->change_attr = change_attr; 208 208 array->last_cookie = last_cookie; 209 209 array->size = 0; 210 - array->page_full = 0; 211 - array->page_is_eof = 0; 210 + array->folio_full = 0; 211 + array->folio_is_eof = 0; 212 212 array->cookies_are_ordered = 1; 213 213 kunmap_local(array); 214 214 } ··· 216 216 /* 217 217 * we are freeing strings created by nfs_add_to_readdir_array() 218 218 */ 219 - static void nfs_readdir_clear_array(struct page *page) 219 + static void nfs_readdir_clear_array(struct folio *folio) 220 220 { 221 221 struct nfs_cache_array *array; 222 222 unsigned int i; 223 223 224 - array = kmap_local_page(page); 224 + array = kmap_local_folio(folio, 0); 225 225 for (i = 0; i < array->size; i++) 226 226 kfree(array->array[i].name); 227 227 array->size = 0; 228 228 kunmap_local(array); 229 229 } 230 230 231 - static void nfs_readdir_free_folio(struct folio *folio) 231 + static void nfs_readdir_folio_reinit_array(struct folio *folio, u64 last_cookie, 232 + u64 change_attr) 232 233 { 233 - nfs_readdir_clear_array(&folio->page); 234 + nfs_readdir_clear_array(folio); 235 + nfs_readdir_folio_init_array(folio, last_cookie, change_attr); 234 236 } 235 237 236 - static void nfs_readdir_page_reinit_array(struct page *page, u64 last_cookie, 237 - u64 change_attr) 238 + static struct folio * 239 + nfs_readdir_folio_array_alloc(u64 last_cookie, gfp_t gfp_flags) 238 240 { 239 - nfs_readdir_clear_array(page); 240 - nfs_readdir_page_init_array(page, last_cookie, change_attr); 241 + struct folio *folio = folio_alloc(gfp_flags, 0); 242 + if (folio) 243 + nfs_readdir_folio_init_array(folio, last_cookie, 0); 244 + return folio; 241 245 } 242 246 243 - static struct page * 244 - nfs_readdir_page_array_alloc(u64 last_cookie, gfp_t gfp_flags) 247 + static void nfs_readdir_folio_array_free(struct folio *folio) 245 248 { 246 - struct page *page = alloc_page(gfp_flags); 247 - if (page) 248 - nfs_readdir_page_init_array(page, last_cookie, 0); 249 - return page; 250 - } 251 - 252 - static void nfs_readdir_page_array_free(struct page *page) 253 - { 254 - if (page) { 255 - nfs_readdir_clear_array(page); 256 - put_page(page); 249 + if (folio) { 250 + nfs_readdir_clear_array(folio); 251 + folio_put(folio); 257 252 } 258 253 } 259 254 ··· 259 264 260 265 static void nfs_readdir_array_set_eof(struct nfs_cache_array *array) 261 266 { 262 - array->page_is_eof = 1; 263 - array->page_full = 1; 267 + array->folio_is_eof = 1; 268 + array->folio_full = 1; 264 269 } 265 270 266 271 static bool nfs_readdir_array_is_full(struct nfs_cache_array *array) 267 272 { 268 - return array->page_full; 273 + return array->folio_full; 269 274 } 270 275 271 276 /* ··· 297 302 */ 298 303 static int nfs_readdir_array_can_expand(struct nfs_cache_array *array) 299 304 { 300 - if (array->page_full) 305 + if (array->folio_full) 301 306 return -ENOSPC; 302 307 if (array->size == nfs_readdir_array_maxentries()) { 303 - array->page_full = 1; 308 + array->folio_full = 1; 304 309 return -ENOSPC; 305 310 } 306 311 return 0; 307 312 } 308 313 309 - static int nfs_readdir_page_array_append(struct page *page, 310 - const struct nfs_entry *entry, 311 - u64 *cookie) 314 + static int nfs_readdir_folio_array_append(struct folio *folio, 315 + const struct nfs_entry *entry, 316 + u64 *cookie) 312 317 { 313 318 struct nfs_cache_array *array; 314 319 struct nfs_cache_array_entry *cache_entry; ··· 317 322 318 323 name = nfs_readdir_copy_name(entry->name, entry->len); 319 324 320 - array = kmap_atomic(page); 325 + array = kmap_atomic(folio_page(folio, 0)); 321 326 if (!name) 322 327 goto out; 323 328 ret = nfs_readdir_array_can_expand(array); ··· 356 361 * 127 readdir entries for a typical 64-bit system, that works out to a 357 362 * cache of ~ 33 million entries per directory. 358 363 */ 359 - static pgoff_t nfs_readdir_page_cookie_hash(u64 cookie) 364 + static pgoff_t nfs_readdir_folio_cookie_hash(u64 cookie) 360 365 { 361 366 if (cookie == 0) 362 367 return 0; 363 368 return hash_64(cookie, 18); 364 369 } 365 370 366 - static bool nfs_readdir_page_validate(struct page *page, u64 last_cookie, 367 - u64 change_attr) 371 + static bool nfs_readdir_folio_validate(struct folio *folio, u64 last_cookie, 372 + u64 change_attr) 368 373 { 369 - struct nfs_cache_array *array = kmap_local_page(page); 374 + struct nfs_cache_array *array = kmap_local_folio(folio, 0); 370 375 int ret = true; 371 376 372 377 if (array->change_attr != change_attr) ··· 377 382 return ret; 378 383 } 379 384 380 - static void nfs_readdir_page_unlock_and_put(struct page *page) 385 + static void nfs_readdir_folio_unlock_and_put(struct folio *folio) 381 386 { 382 - unlock_page(page); 383 - put_page(page); 387 + folio_unlock(folio); 388 + folio_put(folio); 384 389 } 385 390 386 - static void nfs_readdir_page_init_and_validate(struct page *page, u64 cookie, 387 - u64 change_attr) 391 + static void nfs_readdir_folio_init_and_validate(struct folio *folio, u64 cookie, 392 + u64 change_attr) 388 393 { 389 - if (PageUptodate(page)) { 390 - if (nfs_readdir_page_validate(page, cookie, change_attr)) 394 + if (folio_test_uptodate(folio)) { 395 + if (nfs_readdir_folio_validate(folio, cookie, change_attr)) 391 396 return; 392 - nfs_readdir_clear_array(page); 397 + nfs_readdir_clear_array(folio); 393 398 } 394 - nfs_readdir_page_init_array(page, cookie, change_attr); 395 - SetPageUptodate(page); 399 + nfs_readdir_folio_init_array(folio, cookie, change_attr); 400 + folio_mark_uptodate(folio); 396 401 } 397 402 398 - static struct page *nfs_readdir_page_get_locked(struct address_space *mapping, 399 - u64 cookie, u64 change_attr) 403 + static struct folio *nfs_readdir_folio_get_locked(struct address_space *mapping, 404 + u64 cookie, u64 change_attr) 400 405 { 401 - pgoff_t index = nfs_readdir_page_cookie_hash(cookie); 402 - struct page *page; 406 + pgoff_t index = nfs_readdir_folio_cookie_hash(cookie); 407 + struct folio *folio; 403 408 404 - page = grab_cache_page(mapping, index); 405 - if (!page) 409 + folio = filemap_grab_folio(mapping, index); 410 + if (!folio) 406 411 return NULL; 407 - nfs_readdir_page_init_and_validate(page, cookie, change_attr); 408 - return page; 412 + nfs_readdir_folio_init_and_validate(folio, cookie, change_attr); 413 + return folio; 409 414 } 410 415 411 - static u64 nfs_readdir_page_last_cookie(struct page *page) 416 + static u64 nfs_readdir_folio_last_cookie(struct folio *folio) 412 417 { 413 418 struct nfs_cache_array *array; 414 419 u64 ret; 415 420 416 - array = kmap_local_page(page); 421 + array = kmap_local_folio(folio, 0); 417 422 ret = array->last_cookie; 418 423 kunmap_local(array); 419 424 return ret; 420 425 } 421 426 422 - static bool nfs_readdir_page_needs_filling(struct page *page) 427 + static bool nfs_readdir_folio_needs_filling(struct folio *folio) 423 428 { 424 429 struct nfs_cache_array *array; 425 430 bool ret; 426 431 427 - array = kmap_local_page(page); 432 + array = kmap_local_folio(folio, 0); 428 433 ret = !nfs_readdir_array_is_full(array); 429 434 kunmap_local(array); 430 435 return ret; 431 436 } 432 437 433 - static void nfs_readdir_page_set_eof(struct page *page) 438 + static void nfs_readdir_folio_set_eof(struct folio *folio) 434 439 { 435 440 struct nfs_cache_array *array; 436 441 437 - array = kmap_local_page(page); 442 + array = kmap_local_folio(folio, 0); 438 443 nfs_readdir_array_set_eof(array); 439 444 kunmap_local(array); 440 445 } 441 446 442 - static struct page *nfs_readdir_page_get_next(struct address_space *mapping, 443 - u64 cookie, u64 change_attr) 447 + static struct folio *nfs_readdir_folio_get_next(struct address_space *mapping, 448 + u64 cookie, u64 change_attr) 444 449 { 445 - pgoff_t index = nfs_readdir_page_cookie_hash(cookie); 446 - struct page *page; 450 + pgoff_t index = nfs_readdir_folio_cookie_hash(cookie); 451 + struct folio *folio; 447 452 448 - page = grab_cache_page_nowait(mapping, index); 449 - if (!page) 453 + folio = __filemap_get_folio(mapping, index, 454 + FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT, 455 + mapping_gfp_mask(mapping)); 456 + if (!folio) 450 457 return NULL; 451 - nfs_readdir_page_init_and_validate(page, cookie, change_attr); 452 - if (nfs_readdir_page_last_cookie(page) != cookie) 453 - nfs_readdir_page_reinit_array(page, cookie, change_attr); 454 - return page; 458 + nfs_readdir_folio_init_and_validate(folio, cookie, change_attr); 459 + if (nfs_readdir_folio_last_cookie(folio) != cookie) 460 + nfs_readdir_folio_reinit_array(folio, cookie, change_attr); 461 + return folio; 455 462 } 456 463 457 464 static inline ··· 478 481 static void nfs_readdir_seek_next_array(struct nfs_cache_array *array, 479 482 struct nfs_readdir_descriptor *desc) 480 483 { 481 - if (array->page_full) { 484 + if (array->folio_full) { 482 485 desc->last_cookie = array->last_cookie; 483 486 desc->current_index += array->size; 484 487 desc->cache_entry_index = 0; 485 - desc->page_index++; 488 + desc->folio_index++; 486 489 } else 487 490 desc->last_cookie = nfs_readdir_array_index_cookie(array); 488 491 } ··· 491 494 { 492 495 desc->current_index = 0; 493 496 desc->last_cookie = 0; 494 - desc->page_index = 0; 497 + desc->folio_index = 0; 495 498 } 496 499 497 500 static int nfs_readdir_search_for_pos(struct nfs_cache_array *array, ··· 503 506 if (diff < 0) 504 507 goto out_eof; 505 508 if (diff >= array->size) { 506 - if (array->page_is_eof) 509 + if (array->folio_is_eof) 507 510 goto out_eof; 508 511 nfs_readdir_seek_next_array(array, desc); 509 512 return -EAGAIN; ··· 551 554 } 552 555 } 553 556 check_eof: 554 - if (array->page_is_eof) { 557 + if (array->folio_is_eof) { 555 558 status = -EBADCOOKIE; 556 559 if (desc->dir_cookie == array->last_cookie) 557 560 desc->eof = true; ··· 565 568 struct nfs_cache_array *array; 566 569 int status; 567 570 568 - array = kmap_local_page(desc->page); 571 + array = kmap_local_folio(desc->folio, 0); 569 572 570 573 if (desc->dir_cookie == 0) 571 574 status = nfs_readdir_search_for_pos(array, desc); ··· 816 819 } 817 820 818 821 /* Perform conversion from xdr to cache array */ 819 - static int nfs_readdir_page_filler(struct nfs_readdir_descriptor *desc, 820 - struct nfs_entry *entry, 821 - struct page **xdr_pages, unsigned int buflen, 822 - struct page **arrays, size_t narrays, 823 - u64 change_attr) 822 + static int nfs_readdir_folio_filler(struct nfs_readdir_descriptor *desc, 823 + struct nfs_entry *entry, 824 + struct page **xdr_pages, unsigned int buflen, 825 + struct folio **arrays, size_t narrays, 826 + u64 change_attr) 824 827 { 825 828 struct address_space *mapping = desc->file->f_mapping; 829 + struct folio *new, *folio = *arrays; 826 830 struct xdr_stream stream; 831 + struct page *scratch; 827 832 struct xdr_buf buf; 828 - struct page *scratch, *new, *page = *arrays; 829 833 u64 cookie; 830 834 int status; 831 835 ··· 842 844 if (status != 0) 843 845 break; 844 846 845 - status = nfs_readdir_page_array_append(page, entry, &cookie); 847 + status = nfs_readdir_folio_array_append(folio, entry, &cookie); 846 848 if (status != -ENOSPC) 847 849 continue; 848 850 849 - if (page->mapping != mapping) { 851 + if (folio->mapping != mapping) { 850 852 if (!--narrays) 851 853 break; 852 - new = nfs_readdir_page_array_alloc(cookie, GFP_KERNEL); 854 + new = nfs_readdir_folio_array_alloc(cookie, GFP_KERNEL); 853 855 if (!new) 854 856 break; 855 857 arrays++; 856 - *arrays = page = new; 858 + *arrays = folio = new; 857 859 } else { 858 - new = nfs_readdir_page_get_next(mapping, cookie, 859 - change_attr); 860 + new = nfs_readdir_folio_get_next(mapping, cookie, 861 + change_attr); 860 862 if (!new) 861 863 break; 862 - if (page != *arrays) 863 - nfs_readdir_page_unlock_and_put(page); 864 - page = new; 864 + if (folio != *arrays) 865 + nfs_readdir_folio_unlock_and_put(folio); 866 + folio = new; 865 867 } 866 - desc->page_index_max++; 867 - status = nfs_readdir_page_array_append(page, entry, &cookie); 868 + desc->folio_index_max++; 869 + status = nfs_readdir_folio_array_append(folio, entry, &cookie); 868 870 } while (!status && !entry->eof); 869 871 870 872 switch (status) { 871 873 case -EBADCOOKIE: 872 874 if (!entry->eof) 873 875 break; 874 - nfs_readdir_page_set_eof(page); 876 + nfs_readdir_folio_set_eof(folio); 875 877 fallthrough; 876 878 case -EAGAIN: 877 879 status = 0; ··· 884 886 ; 885 887 } 886 888 887 - if (page != *arrays) 888 - nfs_readdir_page_unlock_and_put(page); 889 + if (folio != *arrays) 890 + nfs_readdir_folio_unlock_and_put(folio); 889 891 890 892 put_page(scratch); 891 893 return status; ··· 925 927 926 928 static int nfs_readdir_xdr_to_array(struct nfs_readdir_descriptor *desc, 927 929 __be32 *verf_arg, __be32 *verf_res, 928 - struct page **arrays, size_t narrays) 930 + struct folio **arrays, size_t narrays) 929 931 { 930 932 u64 change_attr; 931 933 struct page **pages; 932 - struct page *page = *arrays; 934 + struct folio *folio = *arrays; 933 935 struct nfs_entry *entry; 934 936 size_t array_size; 935 937 struct inode *inode = file_inode(desc->file); ··· 940 942 entry = kzalloc(sizeof(*entry), GFP_KERNEL); 941 943 if (!entry) 942 944 return -ENOMEM; 943 - entry->cookie = nfs_readdir_page_last_cookie(page); 945 + entry->cookie = nfs_readdir_folio_last_cookie(folio); 944 946 entry->fh = nfs_alloc_fhandle(); 945 947 entry->fattr = nfs_alloc_fattr_with_label(NFS_SERVER(inode)); 946 948 entry->server = NFS_SERVER(inode); ··· 960 962 961 963 pglen = status; 962 964 if (pglen != 0) 963 - status = nfs_readdir_page_filler(desc, entry, pages, pglen, 964 - arrays, narrays, change_attr); 965 + status = nfs_readdir_folio_filler(desc, entry, pages, pglen, 966 + arrays, narrays, change_attr); 965 967 else 966 - nfs_readdir_page_set_eof(page); 968 + nfs_readdir_folio_set_eof(folio); 967 969 desc->buffer_fills++; 968 970 969 971 free_pages: ··· 975 977 return status; 976 978 } 977 979 978 - static void nfs_readdir_page_put(struct nfs_readdir_descriptor *desc) 980 + static void nfs_readdir_folio_put(struct nfs_readdir_descriptor *desc) 979 981 { 980 - put_page(desc->page); 981 - desc->page = NULL; 982 + folio_put(desc->folio); 983 + desc->folio = NULL; 982 984 } 983 985 984 986 static void 985 - nfs_readdir_page_unlock_and_put_cached(struct nfs_readdir_descriptor *desc) 987 + nfs_readdir_folio_unlock_and_put_cached(struct nfs_readdir_descriptor *desc) 986 988 { 987 - unlock_page(desc->page); 988 - nfs_readdir_page_put(desc); 989 + folio_unlock(desc->folio); 990 + nfs_readdir_folio_put(desc); 989 991 } 990 992 991 - static struct page * 992 - nfs_readdir_page_get_cached(struct nfs_readdir_descriptor *desc) 993 + static struct folio * 994 + nfs_readdir_folio_get_cached(struct nfs_readdir_descriptor *desc) 993 995 { 994 996 struct address_space *mapping = desc->file->f_mapping; 995 997 u64 change_attr = inode_peek_iversion_raw(mapping->host); 996 998 u64 cookie = desc->last_cookie; 997 - struct page *page; 999 + struct folio *folio; 998 1000 999 - page = nfs_readdir_page_get_locked(mapping, cookie, change_attr); 1000 - if (!page) 1001 + folio = nfs_readdir_folio_get_locked(mapping, cookie, change_attr); 1002 + if (!folio) 1001 1003 return NULL; 1002 - if (desc->clear_cache && !nfs_readdir_page_needs_filling(page)) 1003 - nfs_readdir_page_reinit_array(page, cookie, change_attr); 1004 - return page; 1004 + if (desc->clear_cache && !nfs_readdir_folio_needs_filling(folio)) 1005 + nfs_readdir_folio_reinit_array(folio, cookie, change_attr); 1006 + return folio; 1005 1007 } 1006 1008 1007 1009 /* ··· 1015 1017 __be32 verf[NFS_DIR_VERIFIER_SIZE]; 1016 1018 int res; 1017 1019 1018 - desc->page = nfs_readdir_page_get_cached(desc); 1019 - if (!desc->page) 1020 + desc->folio = nfs_readdir_folio_get_cached(desc); 1021 + if (!desc->folio) 1020 1022 return -ENOMEM; 1021 - if (nfs_readdir_page_needs_filling(desc->page)) { 1023 + if (nfs_readdir_folio_needs_filling(desc->folio)) { 1022 1024 /* Grow the dtsize if we had to go back for more pages */ 1023 - if (desc->page_index == desc->page_index_max) 1025 + if (desc->folio_index == desc->folio_index_max) 1024 1026 nfs_grow_dtsize(desc); 1025 - desc->page_index_max = desc->page_index; 1027 + desc->folio_index_max = desc->folio_index; 1026 1028 trace_nfs_readdir_cache_fill(desc->file, nfsi->cookieverf, 1027 1029 desc->last_cookie, 1028 - desc->page->index, desc->dtsize); 1030 + desc->folio->index, desc->dtsize); 1029 1031 res = nfs_readdir_xdr_to_array(desc, nfsi->cookieverf, verf, 1030 - &desc->page, 1); 1032 + &desc->folio, 1); 1031 1033 if (res < 0) { 1032 - nfs_readdir_page_unlock_and_put_cached(desc); 1034 + nfs_readdir_folio_unlock_and_put_cached(desc); 1033 1035 trace_nfs_readdir_cache_fill_done(inode, res); 1034 1036 if (res == -EBADCOOKIE || res == -ENOTSYNC) { 1035 1037 invalidate_inode_pages2(desc->file->f_mapping); ··· 1057 1059 res = nfs_readdir_search_array(desc); 1058 1060 if (res == 0) 1059 1061 return 0; 1060 - nfs_readdir_page_unlock_and_put_cached(desc); 1062 + nfs_readdir_folio_unlock_and_put_cached(desc); 1061 1063 return res; 1062 1064 } 1063 1065 ··· 1085 1087 unsigned int i; 1086 1088 bool first_emit = !desc->dir_cookie; 1087 1089 1088 - array = kmap_local_page(desc->page); 1090 + array = kmap_local_folio(desc->folio, 0); 1089 1091 for (i = desc->cache_entry_index; i < array->size; i++) { 1090 1092 struct nfs_cache_array_entry *ent; 1091 1093 ··· 1112 1114 break; 1113 1115 } 1114 1116 } 1115 - if (array->page_is_eof) 1117 + if (array->folio_is_eof) 1116 1118 desc->eof = !desc->eob; 1117 1119 1118 1120 kunmap_local(array); ··· 1134 1136 */ 1135 1137 static int uncached_readdir(struct nfs_readdir_descriptor *desc) 1136 1138 { 1137 - struct page **arrays; 1139 + struct folio **arrays; 1138 1140 size_t i, sz = 512; 1139 1141 __be32 verf[NFS_DIR_VERIFIER_SIZE]; 1140 1142 int status = -ENOMEM; ··· 1145 1147 arrays = kcalloc(sz, sizeof(*arrays), GFP_KERNEL); 1146 1148 if (!arrays) 1147 1149 goto out; 1148 - arrays[0] = nfs_readdir_page_array_alloc(desc->dir_cookie, GFP_KERNEL); 1150 + arrays[0] = nfs_readdir_folio_array_alloc(desc->dir_cookie, GFP_KERNEL); 1149 1151 if (!arrays[0]) 1150 1152 goto out; 1151 1153 1152 - desc->page_index = 0; 1154 + desc->folio_index = 0; 1153 1155 desc->cache_entry_index = 0; 1154 1156 desc->last_cookie = desc->dir_cookie; 1155 - desc->page_index_max = 0; 1157 + desc->folio_index_max = 0; 1156 1158 1157 1159 trace_nfs_readdir_uncached(desc->file, desc->verf, desc->last_cookie, 1158 1160 -1, desc->dtsize); ··· 1164 1166 } 1165 1167 1166 1168 for (i = 0; !desc->eob && i < sz && arrays[i]; i++) { 1167 - desc->page = arrays[i]; 1169 + desc->folio = arrays[i]; 1168 1170 nfs_do_filldir(desc, verf); 1169 1171 } 1170 - desc->page = NULL; 1172 + desc->folio = NULL; 1171 1173 1172 1174 /* 1173 1175 * Grow the dtsize if we have to go back for more pages, ··· 1177 1179 if (!desc->eob) 1178 1180 nfs_grow_dtsize(desc); 1179 1181 else if (desc->buffer_fills == 1 && 1180 - i < (desc->page_index_max >> 1)) 1182 + i < (desc->folio_index_max >> 1)) 1181 1183 nfs_shrink_dtsize(desc); 1182 1184 } 1183 1185 out_free: 1184 1186 for (i = 0; i < sz && arrays[i]; i++) 1185 - nfs_readdir_page_array_free(arrays[i]); 1187 + nfs_readdir_folio_array_free(arrays[i]); 1186 1188 out: 1187 1189 if (!nfs_readdir_use_cookie(desc->file)) 1188 1190 nfs_readdir_rewind_search(desc); 1189 - desc->page_index_max = -1; 1191 + desc->folio_index_max = -1; 1190 1192 kfree(arrays); 1191 1193 dfprintk(DIRCACHE, "NFS: %s: returns %d\n", __func__, status); 1192 1194 return status; ··· 1238 1240 goto out; 1239 1241 desc->file = file; 1240 1242 desc->ctx = ctx; 1241 - desc->page_index_max = -1; 1243 + desc->folio_index_max = -1; 1242 1244 1243 1245 spin_lock(&file->f_lock); 1244 1246 desc->dir_cookie = dir_ctx->dir_cookie; 1245 - desc->page_index = dir_ctx->page_index; 1247 + desc->folio_index = dir_ctx->page_index; 1246 1248 desc->last_cookie = dir_ctx->last_cookie; 1247 1249 desc->attr_gencount = dir_ctx->attr_gencount; 1248 1250 desc->eof = dir_ctx->eof; ··· 1289 1291 break; 1290 1292 1291 1293 nfs_do_filldir(desc, nfsi->cookieverf); 1292 - nfs_readdir_page_unlock_and_put_cached(desc); 1293 - if (desc->page_index == desc->page_index_max) 1294 + nfs_readdir_folio_unlock_and_put_cached(desc); 1295 + if (desc->folio_index == desc->folio_index_max) 1294 1296 desc->clear_cache = force_clear; 1295 1297 } while (!desc->eob && !desc->eof); 1296 1298 ··· 1298 1300 dir_ctx->dir_cookie = desc->dir_cookie; 1299 1301 dir_ctx->last_cookie = desc->last_cookie; 1300 1302 dir_ctx->attr_gencount = desc->attr_gencount; 1301 - dir_ctx->page_index = desc->page_index; 1303 + dir_ctx->page_index = desc->folio_index; 1302 1304 dir_ctx->force_clear = force_clear; 1303 1305 dir_ctx->eof = desc->eof; 1304 1306 dir_ctx->dtsize = desc->dtsize;
+141 -95
fs/nfs/fscache.c
··· 15 15 #include <linux/seq_file.h> 16 16 #include <linux/slab.h> 17 17 #include <linux/iversion.h> 18 + #include <linux/xarray.h> 19 + #include <linux/fscache.h> 20 + #include <linux/netfs.h> 18 21 19 22 #include "internal.h" 20 23 #include "iostat.h" ··· 166 163 struct nfs_server *nfss = NFS_SERVER(inode); 167 164 struct nfs_inode *nfsi = NFS_I(inode); 168 165 169 - nfsi->fscache = NULL; 166 + netfs_inode(inode)->cache = NULL; 170 167 if (!(nfss->fscache && S_ISREG(inode->i_mode))) 171 168 return; 172 169 173 170 nfs_fscache_update_auxdata(&auxdata, inode); 174 171 175 - nfsi->fscache = fscache_acquire_cookie(NFS_SB(inode->i_sb)->fscache, 172 + netfs_inode(inode)->cache = fscache_acquire_cookie( 173 + nfss->fscache, 176 174 0, 177 175 nfsi->fh.data, /* index_key */ 178 176 nfsi->fh.size, ··· 187 183 */ 188 184 void nfs_fscache_clear_inode(struct inode *inode) 189 185 { 190 - struct nfs_inode *nfsi = NFS_I(inode); 191 - struct fscache_cookie *cookie = nfs_i_fscache(inode); 192 - 193 - fscache_relinquish_cookie(cookie, false); 194 - nfsi->fscache = NULL; 186 + fscache_relinquish_cookie(netfs_i_cookie(netfs_inode(inode)), false); 187 + netfs_inode(inode)->cache = NULL; 195 188 } 196 189 197 190 /* ··· 213 212 void nfs_fscache_open_file(struct inode *inode, struct file *filp) 214 213 { 215 214 struct nfs_fscache_inode_auxdata auxdata; 216 - struct fscache_cookie *cookie = nfs_i_fscache(inode); 215 + struct fscache_cookie *cookie = netfs_i_cookie(netfs_inode(inode)); 217 216 bool open_for_write = inode_is_open_for_write(inode); 218 217 219 218 if (!fscache_cookie_valid(cookie)) ··· 231 230 void nfs_fscache_release_file(struct inode *inode, struct file *filp) 232 231 { 233 232 struct nfs_fscache_inode_auxdata auxdata; 234 - struct fscache_cookie *cookie = nfs_i_fscache(inode); 233 + struct fscache_cookie *cookie = netfs_i_cookie(netfs_inode(inode)); 235 234 loff_t i_size = i_size_read(inode); 236 235 237 236 nfs_fscache_update_auxdata(&auxdata, inode); 238 237 fscache_unuse_cookie(cookie, &auxdata, &i_size); 239 238 } 240 239 241 - /* 242 - * Fallback page reading interface. 243 - */ 244 - static int fscache_fallback_read_page(struct inode *inode, struct page *page) 240 + int nfs_netfs_read_folio(struct file *file, struct folio *folio) 245 241 { 246 - struct netfs_cache_resources cres; 247 - struct fscache_cookie *cookie = nfs_i_fscache(inode); 248 - struct iov_iter iter; 249 - struct bio_vec bvec; 250 - int ret; 242 + if (!netfs_inode(folio_inode(folio))->cache) 243 + return -ENOBUFS; 251 244 252 - memset(&cres, 0, sizeof(cres)); 253 - bvec_set_page(&bvec, page, PAGE_SIZE, 0); 254 - iov_iter_bvec(&iter, ITER_DEST, &bvec, 1, PAGE_SIZE); 255 - 256 - ret = fscache_begin_read_operation(&cres, cookie); 257 - if (ret < 0) 258 - return ret; 259 - 260 - ret = fscache_read(&cres, page_offset(page), &iter, NETFS_READ_HOLE_FAIL, 261 - NULL, NULL); 262 - fscache_end_operation(&cres); 263 - return ret; 245 + return netfs_read_folio(file, folio); 264 246 } 265 247 266 - /* 267 - * Fallback page writing interface. 268 - */ 269 - static int fscache_fallback_write_page(struct inode *inode, struct page *page, 270 - bool no_space_allocated_yet) 248 + int nfs_netfs_readahead(struct readahead_control *ractl) 271 249 { 272 - struct netfs_cache_resources cres; 273 - struct fscache_cookie *cookie = nfs_i_fscache(inode); 274 - struct iov_iter iter; 275 - struct bio_vec bvec; 276 - loff_t start = page_offset(page); 277 - size_t len = PAGE_SIZE; 278 - int ret; 250 + struct inode *inode = ractl->mapping->host; 279 251 280 - memset(&cres, 0, sizeof(cres)); 281 - bvec_set_page(&bvec, page, PAGE_SIZE, 0); 282 - iov_iter_bvec(&iter, ITER_SOURCE, &bvec, 1, PAGE_SIZE); 252 + if (!netfs_inode(inode)->cache) 253 + return -ENOBUFS; 283 254 284 - ret = fscache_begin_write_operation(&cres, cookie); 285 - if (ret < 0) 286 - return ret; 287 - 288 - ret = cres.ops->prepare_write(&cres, &start, &len, i_size_read(inode), 289 - no_space_allocated_yet); 290 - if (ret == 0) 291 - ret = fscache_write(&cres, page_offset(page), &iter, NULL, NULL); 292 - fscache_end_operation(&cres); 293 - return ret; 255 + netfs_readahead(ractl); 256 + return 0; 294 257 } 295 258 296 - /* 297 - * Retrieve a page from fscache 298 - */ 299 - int __nfs_fscache_read_page(struct inode *inode, struct page *page) 259 + static atomic_t nfs_netfs_debug_id; 260 + static int nfs_netfs_init_request(struct netfs_io_request *rreq, struct file *file) 300 261 { 301 - int ret; 262 + rreq->netfs_priv = get_nfs_open_context(nfs_file_open_context(file)); 263 + rreq->debug_id = atomic_inc_return(&nfs_netfs_debug_id); 302 264 303 - trace_nfs_fscache_read_page(inode, page); 304 - if (PageChecked(page)) { 305 - ClearPageChecked(page); 306 - ret = 1; 307 - goto out; 265 + return 0; 266 + } 267 + 268 + static void nfs_netfs_free_request(struct netfs_io_request *rreq) 269 + { 270 + put_nfs_open_context(rreq->netfs_priv); 271 + } 272 + 273 + static inline int nfs_netfs_begin_cache_operation(struct netfs_io_request *rreq) 274 + { 275 + return fscache_begin_read_operation(&rreq->cache_resources, 276 + netfs_i_cookie(netfs_inode(rreq->inode))); 277 + } 278 + 279 + static struct nfs_netfs_io_data *nfs_netfs_alloc(struct netfs_io_subrequest *sreq) 280 + { 281 + struct nfs_netfs_io_data *netfs; 282 + 283 + netfs = kzalloc(sizeof(*netfs), GFP_KERNEL_ACCOUNT); 284 + if (!netfs) 285 + return NULL; 286 + netfs->sreq = sreq; 287 + refcount_set(&netfs->refcount, 1); 288 + return netfs; 289 + } 290 + 291 + static bool nfs_netfs_clamp_length(struct netfs_io_subrequest *sreq) 292 + { 293 + size_t rsize = NFS_SB(sreq->rreq->inode->i_sb)->rsize; 294 + 295 + sreq->len = min(sreq->len, rsize); 296 + return true; 297 + } 298 + 299 + static void nfs_netfs_issue_read(struct netfs_io_subrequest *sreq) 300 + { 301 + struct nfs_netfs_io_data *netfs; 302 + struct nfs_pageio_descriptor pgio; 303 + struct inode *inode = sreq->rreq->inode; 304 + struct nfs_open_context *ctx = sreq->rreq->netfs_priv; 305 + struct page *page; 306 + int err; 307 + pgoff_t start = (sreq->start + sreq->transferred) >> PAGE_SHIFT; 308 + pgoff_t last = ((sreq->start + sreq->len - 309 + sreq->transferred - 1) >> PAGE_SHIFT); 310 + XA_STATE(xas, &sreq->rreq->mapping->i_pages, start); 311 + 312 + nfs_pageio_init_read(&pgio, inode, false, 313 + &nfs_async_read_completion_ops); 314 + 315 + netfs = nfs_netfs_alloc(sreq); 316 + if (!netfs) 317 + return netfs_subreq_terminated(sreq, -ENOMEM, false); 318 + 319 + pgio.pg_netfs = netfs; /* used in completion */ 320 + 321 + xas_lock(&xas); 322 + xas_for_each(&xas, page, last) { 323 + /* nfs_read_add_folio() may schedule() due to pNFS layout and other RPCs */ 324 + xas_pause(&xas); 325 + xas_unlock(&xas); 326 + err = nfs_read_add_folio(&pgio, ctx, page_folio(page)); 327 + if (err < 0) { 328 + netfs->error = err; 329 + goto out; 330 + } 331 + xas_lock(&xas); 308 332 } 309 - 310 - ret = fscache_fallback_read_page(inode, page); 311 - if (ret < 0) { 312 - nfs_inc_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_FAIL); 313 - SetPageChecked(page); 314 - goto out; 315 - } 316 - 317 - /* Read completed synchronously */ 318 - nfs_inc_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_OK); 319 - SetPageUptodate(page); 320 - ret = 0; 333 + xas_unlock(&xas); 321 334 out: 322 - trace_nfs_fscache_read_page_exit(inode, page, ret); 323 - return ret; 335 + nfs_pageio_complete_read(&pgio); 336 + nfs_netfs_put(netfs); 324 337 } 325 338 326 - /* 327 - * Store a newly fetched page in fscache. We can be certain there's no page 328 - * stored in the cache as yet otherwise we would've read it from there. 329 - */ 330 - void __nfs_fscache_write_page(struct inode *inode, struct page *page) 339 + void nfs_netfs_initiate_read(struct nfs_pgio_header *hdr) 331 340 { 332 - int ret; 341 + struct nfs_netfs_io_data *netfs = hdr->netfs; 333 342 334 - trace_nfs_fscache_write_page(inode, page); 343 + if (!netfs) 344 + return; 335 345 336 - ret = fscache_fallback_write_page(inode, page, true); 337 - 338 - if (ret != 0) { 339 - nfs_inc_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_WRITTEN_FAIL); 340 - nfs_inc_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_UNCACHED); 341 - } else { 342 - nfs_inc_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_WRITTEN_OK); 343 - } 344 - trace_nfs_fscache_write_page_exit(inode, page, ret); 346 + nfs_netfs_get(netfs); 345 347 } 348 + 349 + int nfs_netfs_folio_unlock(struct folio *folio) 350 + { 351 + struct inode *inode = folio_file_mapping(folio)->host; 352 + 353 + /* 354 + * If fscache is enabled, netfs will unlock pages. 355 + */ 356 + if (netfs_inode(inode)->cache) 357 + return 0; 358 + 359 + return 1; 360 + } 361 + 362 + void nfs_netfs_read_completion(struct nfs_pgio_header *hdr) 363 + { 364 + struct nfs_netfs_io_data *netfs = hdr->netfs; 365 + struct netfs_io_subrequest *sreq; 366 + 367 + if (!netfs) 368 + return; 369 + 370 + sreq = netfs->sreq; 371 + if (test_bit(NFS_IOHDR_EOF, &hdr->flags)) 372 + __set_bit(NETFS_SREQ_CLEAR_TAIL, &sreq->flags); 373 + 374 + if (hdr->error) 375 + netfs->error = hdr->error; 376 + else 377 + atomic64_add(hdr->res.count, &netfs->transferred); 378 + 379 + nfs_netfs_put(netfs); 380 + hdr->netfs = NULL; 381 + } 382 + 383 + const struct netfs_request_ops nfs_netfs_ops = { 384 + .init_request = nfs_netfs_init_request, 385 + .free_request = nfs_netfs_free_request, 386 + .begin_cache_operation = nfs_netfs_begin_cache_operation, 387 + .issue_read = nfs_netfs_issue_read, 388 + .clamp_length = nfs_netfs_clamp_length 389 + };
+92 -39
fs/nfs/fscache.h
··· 34 34 u64 change_attr; 35 35 }; 36 36 37 + struct nfs_netfs_io_data { 38 + /* 39 + * NFS may split a netfs_io_subrequest into multiple RPCs, each 40 + * with their own read completion. In netfs, we can only call 41 + * netfs_subreq_terminated() once for each subrequest. Use the 42 + * refcount here to double as a marker of the last RPC completion, 43 + * and only call netfs via netfs_subreq_terminated() once. 44 + */ 45 + refcount_t refcount; 46 + struct netfs_io_subrequest *sreq; 47 + 48 + /* 49 + * Final disposition of the netfs_io_subrequest, sent in 50 + * netfs_subreq_terminated() 51 + */ 52 + atomic64_t transferred; 53 + int error; 54 + }; 55 + 56 + static inline void nfs_netfs_get(struct nfs_netfs_io_data *netfs) 57 + { 58 + refcount_inc(&netfs->refcount); 59 + } 60 + 61 + static inline void nfs_netfs_put(struct nfs_netfs_io_data *netfs) 62 + { 63 + ssize_t final_len; 64 + 65 + /* Only the last RPC completion should call netfs_subreq_terminated() */ 66 + if (!refcount_dec_and_test(&netfs->refcount)) 67 + return; 68 + 69 + /* 70 + * The NFS pageio interface may read a complete page, even when netfs 71 + * only asked for a partial page. Specifically, this may be seen when 72 + * one thread is truncating a file while another one is reading the last 73 + * page of the file. 74 + * Correct the final length here to be no larger than the netfs subrequest 75 + * length, and thus avoid netfs's "Subreq overread" warning message. 76 + */ 77 + final_len = min_t(s64, netfs->sreq->len, atomic64_read(&netfs->transferred)); 78 + netfs_subreq_terminated(netfs->sreq, netfs->error ?: final_len, false); 79 + kfree(netfs); 80 + } 81 + static inline void nfs_netfs_inode_init(struct nfs_inode *nfsi) 82 + { 83 + netfs_inode_init(&nfsi->netfs, &nfs_netfs_ops); 84 + } 85 + extern void nfs_netfs_initiate_read(struct nfs_pgio_header *hdr); 86 + extern void nfs_netfs_read_completion(struct nfs_pgio_header *hdr); 87 + extern int nfs_netfs_folio_unlock(struct folio *folio); 88 + 37 89 /* 38 90 * fscache.c 39 91 */ ··· 96 44 extern void nfs_fscache_clear_inode(struct inode *); 97 45 extern void nfs_fscache_open_file(struct inode *, struct file *); 98 46 extern void nfs_fscache_release_file(struct inode *, struct file *); 99 - 100 - extern int __nfs_fscache_read_page(struct inode *, struct page *); 101 - extern void __nfs_fscache_write_page(struct inode *, struct page *); 47 + extern int nfs_netfs_readahead(struct readahead_control *ractl); 48 + extern int nfs_netfs_read_folio(struct file *file, struct folio *folio); 102 49 103 50 static inline bool nfs_fscache_release_folio(struct folio *folio, gfp_t gfp) 104 51 { ··· 105 54 if (current_is_kswapd() || !(gfp & __GFP_FS)) 106 55 return false; 107 56 folio_wait_fscache(folio); 108 - fscache_note_page_release(nfs_i_fscache(folio->mapping->host)); 109 - nfs_inc_fscache_stats(folio->mapping->host, 110 - NFSIOS_FSCACHE_PAGES_UNCACHED); 111 57 } 58 + fscache_note_page_release(netfs_i_cookie(netfs_inode(folio->mapping->host))); 112 59 return true; 113 - } 114 - 115 - /* 116 - * Retrieve a page from an inode data storage object. 117 - */ 118 - static inline int nfs_fscache_read_page(struct inode *inode, struct page *page) 119 - { 120 - if (nfs_i_fscache(inode)) 121 - return __nfs_fscache_read_page(inode, page); 122 - return -ENOBUFS; 123 - } 124 - 125 - /* 126 - * Store a page newly fetched from the server in an inode data storage object 127 - * in the cache. 128 - */ 129 - static inline void nfs_fscache_write_page(struct inode *inode, 130 - struct page *page) 131 - { 132 - if (nfs_i_fscache(inode)) 133 - __nfs_fscache_write_page(inode, page); 134 60 } 135 61 136 62 static inline void nfs_fscache_update_auxdata(struct nfs_fscache_inode_auxdata *auxdata, ··· 129 101 static inline void nfs_fscache_invalidate(struct inode *inode, int flags) 130 102 { 131 103 struct nfs_fscache_inode_auxdata auxdata; 132 - struct nfs_inode *nfsi = NFS_I(inode); 104 + struct fscache_cookie *cookie = netfs_i_cookie(&NFS_I(inode)->netfs); 133 105 134 - if (nfsi->fscache) { 135 - nfs_fscache_update_auxdata(&auxdata, inode); 136 - fscache_invalidate(nfsi->fscache, &auxdata, 137 - i_size_read(inode), flags); 138 - } 106 + nfs_fscache_update_auxdata(&auxdata, inode); 107 + fscache_invalidate(cookie, &auxdata, i_size_read(inode), flags); 139 108 } 140 109 141 110 /* ··· 145 120 return "no "; 146 121 } 147 122 123 + static inline void nfs_netfs_set_pgio_header(struct nfs_pgio_header *hdr, 124 + struct nfs_pageio_descriptor *desc) 125 + { 126 + hdr->netfs = desc->pg_netfs; 127 + } 128 + static inline void nfs_netfs_set_pageio_descriptor(struct nfs_pageio_descriptor *desc, 129 + struct nfs_pgio_header *hdr) 130 + { 131 + desc->pg_netfs = hdr->netfs; 132 + } 133 + static inline void nfs_netfs_reset_pageio_descriptor(struct nfs_pageio_descriptor *desc) 134 + { 135 + desc->pg_netfs = NULL; 136 + } 148 137 #else /* CONFIG_NFS_FSCACHE */ 138 + static inline void nfs_netfs_inode_init(struct nfs_inode *nfsi) {} 139 + static inline void nfs_netfs_initiate_read(struct nfs_pgio_header *hdr) {} 140 + static inline void nfs_netfs_read_completion(struct nfs_pgio_header *hdr) {} 141 + static inline int nfs_netfs_folio_unlock(struct folio *folio) 142 + { 143 + return 1; 144 + } 149 145 static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {} 150 146 151 147 static inline void nfs_fscache_init_inode(struct inode *inode) {} ··· 174 128 static inline void nfs_fscache_open_file(struct inode *inode, 175 129 struct file *filp) {} 176 130 static inline void nfs_fscache_release_file(struct inode *inode, struct file *file) {} 131 + static inline int nfs_netfs_readahead(struct readahead_control *ractl) 132 + { 133 + return -ENOBUFS; 134 + } 135 + static inline int nfs_netfs_read_folio(struct file *file, struct folio *folio) 136 + { 137 + return -ENOBUFS; 138 + } 177 139 178 140 static inline bool nfs_fscache_release_folio(struct folio *folio, gfp_t gfp) 179 141 { 180 142 return true; /* may release folio */ 181 143 } 182 - static inline int nfs_fscache_read_page(struct inode *inode, struct page *page) 183 - { 184 - return -ENOBUFS; 185 - } 186 - static inline void nfs_fscache_write_page(struct inode *inode, struct page *page) {} 187 144 static inline void nfs_fscache_invalidate(struct inode *inode, int flags) {} 188 145 189 146 static inline const char *nfs_server_fscache_state(struct nfs_server *server) 190 147 { 191 148 return "no "; 192 149 } 193 - 150 + static inline void nfs_netfs_set_pgio_header(struct nfs_pgio_header *hdr, 151 + struct nfs_pageio_descriptor *desc) {} 152 + static inline void nfs_netfs_set_pageio_descriptor(struct nfs_pageio_descriptor *desc, 153 + struct nfs_pgio_header *hdr) {} 154 + static inline void nfs_netfs_reset_pageio_descriptor(struct nfs_pageio_descriptor *desc) {} 194 155 #endif /* CONFIG_NFS_FSCACHE */ 195 156 #endif /* _NFS_FSCACHE_H */
+99 -15
fs/nfs/inode.c
··· 208 208 209 209 nfsi->cache_validity |= flags; 210 210 211 - if (inode->i_mapping->nrpages == 0) 212 - nfsi->cache_validity &= ~(NFS_INO_INVALID_DATA | 213 - NFS_INO_DATA_INVAL_DEFER); 214 - else if (nfsi->cache_validity & NFS_INO_INVALID_DATA) 215 - nfsi->cache_validity &= ~NFS_INO_DATA_INVAL_DEFER; 211 + if (inode->i_mapping->nrpages == 0) { 212 + nfsi->cache_validity &= ~NFS_INO_INVALID_DATA; 213 + nfs_ooo_clear(nfsi); 214 + } else if (nfsi->cache_validity & NFS_INO_INVALID_DATA) { 215 + nfs_ooo_clear(nfsi); 216 + } 216 217 trace_nfs_set_cache_invalid(inode, 0); 217 218 } 218 219 EXPORT_SYMBOL_GPL(nfs_set_cache_invalid); ··· 678 677 trace_nfs_size_truncate(inode, offset); 679 678 i_size_write(inode, offset); 680 679 /* Optimisation */ 681 - if (offset == 0) 682 - NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_DATA | 683 - NFS_INO_DATA_INVAL_DEFER); 680 + if (offset == 0) { 681 + NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_DATA; 682 + nfs_ooo_clear(NFS_I(inode)); 683 + } 684 684 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_SIZE; 685 685 686 686 spin_unlock(&inode->i_lock); ··· 1109 1107 1110 1108 spin_lock(&inode->i_lock); 1111 1109 if (list_empty(&nfsi->open_files) && 1112 - (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER)) 1110 + nfs_ooo_test(nfsi)) 1113 1111 nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA | 1114 1112 NFS_INO_REVAL_FORCED); 1115 1113 list_add_tail_rcu(&ctx->list, &nfsi->open_files); ··· 1353 1351 1354 1352 set_bit(NFS_INO_INVALIDATING, bitlock); 1355 1353 smp_wmb(); 1356 - nfsi->cache_validity &= 1357 - ~(NFS_INO_INVALID_DATA | NFS_INO_DATA_INVAL_DEFER); 1354 + nfsi->cache_validity &= ~NFS_INO_INVALID_DATA; 1355 + nfs_ooo_clear(nfsi); 1358 1356 spin_unlock(&inode->i_lock); 1359 1357 trace_nfs_invalidate_mapping_enter(inode); 1360 1358 ret = nfs_invalidate_mapping(inode, mapping); ··· 1816 1814 return 0; 1817 1815 } 1818 1816 1817 + static void nfs_ooo_merge(struct nfs_inode *nfsi, 1818 + u64 start, u64 end) 1819 + { 1820 + int i, cnt; 1821 + 1822 + if (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER) 1823 + /* No point merging anything */ 1824 + return; 1825 + 1826 + if (!nfsi->ooo) { 1827 + nfsi->ooo = kmalloc(sizeof(*nfsi->ooo), GFP_ATOMIC); 1828 + if (!nfsi->ooo) { 1829 + nfsi->cache_validity |= NFS_INO_DATA_INVAL_DEFER; 1830 + return; 1831 + } 1832 + nfsi->ooo->cnt = 0; 1833 + } 1834 + 1835 + /* add this range, merging if possible */ 1836 + cnt = nfsi->ooo->cnt; 1837 + for (i = 0; i < cnt; i++) { 1838 + if (end == nfsi->ooo->gap[i].start) 1839 + end = nfsi->ooo->gap[i].end; 1840 + else if (start == nfsi->ooo->gap[i].end) 1841 + start = nfsi->ooo->gap[i].start; 1842 + else 1843 + continue; 1844 + /* Remove 'i' from table and loop to insert the new range */ 1845 + cnt -= 1; 1846 + nfsi->ooo->gap[i] = nfsi->ooo->gap[cnt]; 1847 + i = -1; 1848 + } 1849 + if (start != end) { 1850 + if (cnt >= ARRAY_SIZE(nfsi->ooo->gap)) { 1851 + nfsi->cache_validity |= NFS_INO_DATA_INVAL_DEFER; 1852 + kfree(nfsi->ooo); 1853 + nfsi->ooo = NULL; 1854 + return; 1855 + } 1856 + nfsi->ooo->gap[cnt].start = start; 1857 + nfsi->ooo->gap[cnt].end = end; 1858 + cnt += 1; 1859 + } 1860 + nfsi->ooo->cnt = cnt; 1861 + } 1862 + 1863 + static void nfs_ooo_record(struct nfs_inode *nfsi, 1864 + struct nfs_fattr *fattr) 1865 + { 1866 + /* This reply was out-of-order, so record in the 1867 + * pre/post change id, possibly cancelling 1868 + * gaps created when iversion was jumpped forward. 1869 + */ 1870 + if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) && 1871 + (fattr->valid & NFS_ATTR_FATTR_PRECHANGE)) 1872 + nfs_ooo_merge(nfsi, 1873 + fattr->change_attr, 1874 + fattr->pre_change_attr); 1875 + } 1876 + 1819 1877 static int nfs_refresh_inode_locked(struct inode *inode, 1820 1878 struct nfs_fattr *fattr) 1821 1879 { ··· 1886 1824 1887 1825 if (attr_cmp > 0 || nfs_inode_finish_partial_attr_update(fattr, inode)) 1888 1826 ret = nfs_update_inode(inode, fattr); 1889 - else if (attr_cmp == 0) 1890 - ret = nfs_check_inode_attributes(inode, fattr); 1827 + else { 1828 + nfs_ooo_record(NFS_I(inode), fattr); 1829 + 1830 + if (attr_cmp == 0) 1831 + ret = nfs_check_inode_attributes(inode, fattr); 1832 + } 1891 1833 1892 1834 trace_nfs_refresh_inode_exit(inode, ret); 1893 1835 return ret; ··· 1982 1916 if (attr_cmp < 0) 1983 1917 return 0; 1984 1918 if ((fattr->valid & NFS_ATTR_FATTR) == 0 || !attr_cmp) { 1919 + /* Record the pre/post change info before clearing PRECHANGE */ 1920 + nfs_ooo_record(NFS_I(inode), fattr); 1985 1921 fattr->valid &= ~(NFS_ATTR_FATTR_PRECHANGE 1986 1922 | NFS_ATTR_FATTR_PRESIZE 1987 1923 | NFS_ATTR_FATTR_PREMTIME ··· 2138 2070 2139 2071 /* More cache consistency checks */ 2140 2072 if (fattr->valid & NFS_ATTR_FATTR_CHANGE) { 2073 + if (!have_writers && nfsi->ooo && nfsi->ooo->cnt == 1 && 2074 + nfsi->ooo->gap[0].end == inode_peek_iversion_raw(inode)) { 2075 + /* There is one remaining gap that hasn't been 2076 + * merged into iversion - do that now. 2077 + */ 2078 + inode_set_iversion_raw(inode, nfsi->ooo->gap[0].start); 2079 + kfree(nfsi->ooo); 2080 + nfsi->ooo = NULL; 2081 + } 2141 2082 if (!inode_eq_iversion_raw(inode, fattr->change_attr)) { 2142 2083 /* Could it be a race with writeback? */ 2143 2084 if (!(have_writers || have_delegation)) { ··· 2168 2091 dprintk("NFS: change_attr change on server for file %s/%ld\n", 2169 2092 inode->i_sb->s_id, 2170 2093 inode->i_ino); 2171 - } else if (!have_delegation) 2172 - nfsi->cache_validity |= NFS_INO_DATA_INVAL_DEFER; 2094 + } else if (!have_delegation) { 2095 + nfs_ooo_record(nfsi, fattr); 2096 + nfs_ooo_merge(nfsi, inode_peek_iversion_raw(inode), 2097 + fattr->change_attr); 2098 + } 2173 2099 inode_set_iversion_raw(inode, fattr->change_attr); 2174 2100 } 2175 2101 } else { ··· 2326 2246 return NULL; 2327 2247 nfsi->flags = 0UL; 2328 2248 nfsi->cache_validity = 0UL; 2249 + nfsi->ooo = NULL; 2329 2250 #if IS_ENABLED(CONFIG_NFS_V4) 2330 2251 nfsi->nfs4_acl = NULL; 2331 2252 #endif /* CONFIG_NFS_V4 */ 2332 2253 #ifdef CONFIG_NFS_V4_2 2333 2254 nfsi->xattr_cache = NULL; 2334 2255 #endif 2256 + nfs_netfs_inode_init(nfsi); 2257 + 2335 2258 return &nfsi->vfs_inode; 2336 2259 } 2337 2260 EXPORT_SYMBOL_GPL(nfs_alloc_inode); 2338 2261 2339 2262 void nfs_free_inode(struct inode *inode) 2340 2263 { 2264 + kfree(NFS_I(inode)->ooo); 2341 2265 kmem_cache_free(nfs_inode_cachep, NFS_I(inode)); 2342 2266 } 2343 2267 EXPORT_SYMBOL_GPL(nfs_free_inode);
+9
fs/nfs/internal.h
··· 452 452 extern int nfs_client_for_each_server(struct nfs_client *clp, 453 453 int (*fn)(struct nfs_server *, void *), 454 454 void *data); 455 + #ifdef CONFIG_NFS_FSCACHE 456 + extern const struct netfs_request_ops nfs_netfs_ops; 457 + #endif 458 + 455 459 /* io.c */ 456 460 extern void nfs_start_io_read(struct inode *inode); 457 461 extern void nfs_end_io_read(struct inode *inode); ··· 485 481 486 482 struct nfs_pgio_completion_ops; 487 483 /* read.c */ 484 + extern const struct nfs_pgio_completion_ops nfs_async_read_completion_ops; 488 485 extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, 489 486 struct inode *inode, bool force_mds, 490 487 const struct nfs_pgio_completion_ops *compl_ops); 488 + extern int nfs_read_add_folio(struct nfs_pageio_descriptor *pgio, 489 + struct nfs_open_context *ctx, 490 + struct folio *folio); 491 + extern void nfs_pageio_complete_read(struct nfs_pageio_descriptor *pgio); 491 492 extern void nfs_read_prepare(struct rpc_task *task, void *calldata); 492 493 extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio); 493 494
-17
fs/nfs/iostat.h
··· 17 17 18 18 struct nfs_iostats { 19 19 unsigned long long bytes[__NFSIOS_BYTESMAX]; 20 - #ifdef CONFIG_NFS_FSCACHE 21 - unsigned long long fscache[__NFSIOS_FSCACHEMAX]; 22 - #endif 23 20 unsigned long events[__NFSIOS_COUNTSMAX]; 24 21 } ____cacheline_aligned; 25 22 ··· 45 48 { 46 49 nfs_add_server_stats(NFS_SERVER(inode), stat, addend); 47 50 } 48 - 49 - #ifdef CONFIG_NFS_FSCACHE 50 - static inline void nfs_add_fscache_stats(struct inode *inode, 51 - enum nfs_stat_fscachecounters stat, 52 - long addend) 53 - { 54 - this_cpu_add(NFS_SERVER(inode)->io_stats->fscache[stat], addend); 55 - } 56 - static inline void nfs_inc_fscache_stats(struct inode *inode, 57 - enum nfs_stat_fscachecounters stat) 58 - { 59 - this_cpu_inc(NFS_SERVER(inode)->io_stats->fscache[stat]); 60 - } 61 - #endif 62 51 63 52 static inline struct nfs_iostats __percpu *nfs_alloc_iostats(void) 64 53 {
+2 -2
fs/nfs/nfs42xdr.c
··· 1122 1122 uint32_t segments; 1123 1123 struct read_plus_segment *segs; 1124 1124 int status, i; 1125 - char scratch_buf[16]; 1126 1125 __be32 *p; 1127 1126 1128 1127 status = decode_op_hdr(xdr, OP_READ_PLUS); ··· 1142 1143 if (!segs) 1143 1144 return -ENOMEM; 1144 1145 1145 - xdr_set_scratch_buffer(xdr, &scratch_buf, sizeof(scratch_buf)); 1146 1146 status = -EIO; 1147 1147 for (i = 0; i < segments; i++) { 1148 1148 status = decode_read_plus_segment(xdr, &segs[i]); ··· 1345 1347 struct nfs_pgio_res *res = data; 1346 1348 struct compound_hdr hdr; 1347 1349 int status; 1350 + 1351 + xdr_set_scratch_buffer(xdr, res->scratch, sizeof(res->scratch)); 1348 1352 1349 1353 status = decode_compound_hdr(xdr, &hdr); 1350 1354 if (status)
+12 -5
fs/nfs/nfs4proc.c
··· 5439 5439 5440 5440 static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) 5441 5441 { 5442 + if (hdr->res.scratch) 5443 + kfree(hdr->res.scratch); 5442 5444 if (!nfs4_sequence_done(task, &hdr->res.seq_res)) 5443 5445 return -EAGAIN; 5444 5446 if (nfs4_read_stateid_changed(task, &hdr->args)) ··· 5454 5452 } 5455 5453 5456 5454 #if defined CONFIG_NFS_V4_2 && defined CONFIG_NFS_V4_2_READ_PLUS 5457 - static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, 5455 + static bool nfs42_read_plus_support(struct nfs_pgio_header *hdr, 5458 5456 struct rpc_message *msg) 5459 5457 { 5460 5458 /* Note: We don't use READ_PLUS with pNFS yet */ 5461 - if (nfs_server_capable(hdr->inode, NFS_CAP_READ_PLUS) && !hdr->ds_clp) 5459 + if (nfs_server_capable(hdr->inode, NFS_CAP_READ_PLUS) && !hdr->ds_clp) { 5462 5460 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS]; 5461 + hdr->res.scratch = kmalloc(32, GFP_KERNEL); 5462 + return hdr->res.scratch != NULL; 5463 + } 5464 + return false; 5463 5465 } 5464 5466 #else 5465 - static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, 5467 + static bool nfs42_read_plus_support(struct nfs_pgio_header *hdr, 5466 5468 struct rpc_message *msg) 5467 5469 { 5470 + return false; 5468 5471 } 5469 5472 #endif /* CONFIG_NFS_V4_2 */ 5470 5473 ··· 5479 5472 hdr->timestamp = jiffies; 5480 5473 if (!hdr->pgio_done_cb) 5481 5474 hdr->pgio_done_cb = nfs4_read_done_cb; 5482 - msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; 5483 - nfs42_read_plus_support(hdr, msg); 5475 + if (!nfs42_read_plus_support(hdr, msg)) 5476 + msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; 5484 5477 nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0, 0); 5485 5478 } 5486 5479
+4 -4
fs/nfs/nfs4state.c
··· 67 67 68 68 #define OPENOWNER_POOL_SIZE 8 69 69 70 + static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp); 71 + 70 72 const nfs4_stateid zero_stateid = { 71 73 { .data = { 0 } }, 72 74 .type = NFS4_SPECIAL_STATEID_TYPE, ··· 332 330 status = nfs4_proc_create_session(clp, cred); 333 331 if (status != 0) 334 332 goto out; 333 + if (!(clp->cl_exchange_flags & EXCHGID4_FLAG_CONFIRMED_R)) 334 + nfs4_state_start_reclaim_reboot(clp); 335 335 nfs41_finish_session_reset(clp); 336 336 nfs_mark_client_ready(clp, NFS_CS_READY); 337 337 out: ··· 1209 1205 { 1210 1206 struct task_struct *task; 1211 1207 char buf[INET6_ADDRSTRLEN + sizeof("-manager") + 1]; 1212 - struct rpc_clnt *cl = clp->cl_rpcclient; 1213 - 1214 - while (cl != cl->cl_parent) 1215 - cl = cl->cl_parent; 1216 1208 1217 1209 set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); 1218 1210 if (test_and_set_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state) != 0) {
-91
fs/nfs/nfstrace.h
··· 39 39 { BIT(NFS_INO_STALE), "STALE" }, \ 40 40 { BIT(NFS_INO_ACL_LRU_SET), "ACL_LRU_SET" }, \ 41 41 { BIT(NFS_INO_INVALIDATING), "INVALIDATING" }, \ 42 - { BIT(NFS_INO_FSCACHE), "FSCACHE" }, \ 43 42 { BIT(NFS_INO_LAYOUTCOMMIT), "NEED_LAYOUTCOMMIT" }, \ 44 43 { BIT(NFS_INO_LAYOUTCOMMITTING), "LAYOUTCOMMIT" }, \ 45 44 { BIT(NFS_INO_LAYOUTSTATS), "LAYOUTSTATS" }, \ ··· 1242 1243 ) 1243 1244 ); 1244 1245 1245 - DECLARE_EVENT_CLASS(nfs_fscache_page_event, 1246 - TP_PROTO( 1247 - const struct inode *inode, 1248 - struct page *page 1249 - ), 1250 - 1251 - TP_ARGS(inode, page), 1252 - 1253 - TP_STRUCT__entry( 1254 - __field(dev_t, dev) 1255 - __field(u32, fhandle) 1256 - __field(u64, fileid) 1257 - __field(loff_t, offset) 1258 - ), 1259 - 1260 - TP_fast_assign( 1261 - const struct nfs_inode *nfsi = NFS_I(inode); 1262 - const struct nfs_fh *fh = &nfsi->fh; 1263 - 1264 - __entry->offset = page_index(page) << PAGE_SHIFT; 1265 - __entry->dev = inode->i_sb->s_dev; 1266 - __entry->fileid = nfsi->fileid; 1267 - __entry->fhandle = nfs_fhandle_hash(fh); 1268 - ), 1269 - 1270 - TP_printk( 1271 - "fileid=%02x:%02x:%llu fhandle=0x%08x " 1272 - "offset=%lld", 1273 - MAJOR(__entry->dev), MINOR(__entry->dev), 1274 - (unsigned long long)__entry->fileid, 1275 - __entry->fhandle, 1276 - (long long)__entry->offset 1277 - ) 1278 - ); 1279 - DECLARE_EVENT_CLASS(nfs_fscache_page_event_done, 1280 - TP_PROTO( 1281 - const struct inode *inode, 1282 - struct page *page, 1283 - int error 1284 - ), 1285 - 1286 - TP_ARGS(inode, page, error), 1287 - 1288 - TP_STRUCT__entry( 1289 - __field(int, error) 1290 - __field(dev_t, dev) 1291 - __field(u32, fhandle) 1292 - __field(u64, fileid) 1293 - __field(loff_t, offset) 1294 - ), 1295 - 1296 - TP_fast_assign( 1297 - const struct nfs_inode *nfsi = NFS_I(inode); 1298 - const struct nfs_fh *fh = &nfsi->fh; 1299 - 1300 - __entry->offset = page_index(page) << PAGE_SHIFT; 1301 - __entry->dev = inode->i_sb->s_dev; 1302 - __entry->fileid = nfsi->fileid; 1303 - __entry->fhandle = nfs_fhandle_hash(fh); 1304 - __entry->error = error; 1305 - ), 1306 - 1307 - TP_printk( 1308 - "fileid=%02x:%02x:%llu fhandle=0x%08x " 1309 - "offset=%lld error=%d", 1310 - MAJOR(__entry->dev), MINOR(__entry->dev), 1311 - (unsigned long long)__entry->fileid, 1312 - __entry->fhandle, 1313 - (long long)__entry->offset, __entry->error 1314 - ) 1315 - ); 1316 - #define DEFINE_NFS_FSCACHE_PAGE_EVENT(name) \ 1317 - DEFINE_EVENT(nfs_fscache_page_event, name, \ 1318 - TP_PROTO( \ 1319 - const struct inode *inode, \ 1320 - struct page *page \ 1321 - ), \ 1322 - TP_ARGS(inode, page)) 1323 - #define DEFINE_NFS_FSCACHE_PAGE_EVENT_DONE(name) \ 1324 - DEFINE_EVENT(nfs_fscache_page_event_done, name, \ 1325 - TP_PROTO( \ 1326 - const struct inode *inode, \ 1327 - struct page *page, \ 1328 - int error \ 1329 - ), \ 1330 - TP_ARGS(inode, page, error)) 1331 - DEFINE_NFS_FSCACHE_PAGE_EVENT(nfs_fscache_read_page); 1332 - DEFINE_NFS_FSCACHE_PAGE_EVENT_DONE(nfs_fscache_read_page_exit); 1333 - DEFINE_NFS_FSCACHE_PAGE_EVENT(nfs_fscache_write_page); 1334 - DEFINE_NFS_FSCACHE_PAGE_EVENT_DONE(nfs_fscache_write_page_exit); 1335 1246 1336 1247 TRACE_EVENT(nfs_pgio_error, 1337 1248 TP_PROTO(
+4
fs/nfs/pagelist.c
··· 26 26 #include "internal.h" 27 27 #include "pnfs.h" 28 28 #include "nfstrace.h" 29 + #include "fscache.h" 29 30 30 31 #define NFSDBG_FACILITY NFSDBG_PAGECACHE 31 32 ··· 106 105 hdr->good_bytes = mirror->pg_count; 107 106 hdr->io_completion = desc->pg_io_completion; 108 107 hdr->dreq = desc->pg_dreq; 108 + nfs_netfs_set_pgio_header(hdr, desc); 109 109 hdr->release = release; 110 110 hdr->completion_ops = desc->pg_completion_ops; 111 111 if (hdr->completion_ops->init_hdr) ··· 943 941 desc->pg_lseg = NULL; 944 942 desc->pg_io_completion = NULL; 945 943 desc->pg_dreq = NULL; 944 + nfs_netfs_reset_pageio_descriptor(desc); 946 945 desc->pg_bsize = bsize; 947 946 948 947 desc->pg_mirror_count = 1; ··· 1480 1477 1481 1478 desc->pg_io_completion = hdr->io_completion; 1482 1479 desc->pg_dreq = hdr->dreq; 1480 + nfs_netfs_set_pageio_descriptor(desc, hdr); 1483 1481 list_splice_init(&hdr->pages, &pages); 1484 1482 while (!list_empty(&pages)) { 1485 1483 struct nfs_page *req = nfs_list_entry(pages.next);
+54 -57
fs/nfs/read.c
··· 31 31 32 32 #define NFSDBG_FACILITY NFSDBG_PAGECACHE 33 33 34 - static const struct nfs_pgio_completion_ops nfs_async_read_completion_ops; 34 + const struct nfs_pgio_completion_ops nfs_async_read_completion_ops; 35 35 static const struct nfs_rw_ops nfs_rw_read_ops; 36 36 37 37 static struct kmem_cache *nfs_rdata_cachep; ··· 74 74 } 75 75 EXPORT_SYMBOL_GPL(nfs_pageio_init_read); 76 76 77 - static void nfs_pageio_complete_read(struct nfs_pageio_descriptor *pgio) 77 + void nfs_pageio_complete_read(struct nfs_pageio_descriptor *pgio) 78 78 { 79 79 struct nfs_pgio_mirror *pgm; 80 80 unsigned long npages; ··· 110 110 111 111 static void nfs_readpage_release(struct nfs_page *req, int error) 112 112 { 113 - struct inode *inode = d_inode(nfs_req_openctx(req)->dentry); 114 113 struct folio *folio = nfs_page_to_folio(req); 115 - 116 - dprintk("NFS: read done (%s/%llu %d@%lld)\n", inode->i_sb->s_id, 117 - (unsigned long long)NFS_FILEID(inode), req->wb_bytes, 118 - (long long)req_offset(req)); 119 114 120 115 if (nfs_error_is_fatal_on_server(error) && error != -ETIMEDOUT) 121 116 folio_set_error(folio); 122 - if (nfs_page_group_sync_on_bit(req, PG_UNLOCKPAGE)) { 123 - if (folio_test_uptodate(folio)) 124 - nfs_fscache_write_page(inode, &folio->page); 125 - folio_unlock(folio); 126 - } 117 + if (nfs_page_group_sync_on_bit(req, PG_UNLOCKPAGE)) 118 + if (nfs_netfs_folio_unlock(folio)) 119 + folio_unlock(folio); 120 + 127 121 nfs_release_request(req); 128 122 } 129 - 130 - struct nfs_readdesc { 131 - struct nfs_pageio_descriptor pgio; 132 - struct nfs_open_context *ctx; 133 - }; 134 123 135 124 static void nfs_page_group_set_uptodate(struct nfs_page *req) 136 125 { ··· 142 153 143 154 if (test_bit(NFS_IOHDR_EOF, &hdr->flags)) { 144 155 /* note: regions of the page not covered by a 145 - * request are zeroed in readpage_async_filler */ 156 + * request are zeroed in nfs_read_add_folio 157 + */ 146 158 if (bytes > hdr->good_bytes) { 147 159 /* nothing in this request was good, so zero 148 160 * the full extent of the request */ ··· 171 181 nfs_list_remove_request(req); 172 182 nfs_readpage_release(req, error); 173 183 } 184 + nfs_netfs_read_completion(hdr); 185 + 174 186 out: 175 187 hdr->release(hdr); 176 188 } ··· 183 191 struct rpc_task_setup *task_setup_data, int how) 184 192 { 185 193 rpc_ops->read_setup(hdr, msg); 194 + nfs_netfs_initiate_read(hdr); 186 195 trace_nfs_initiate_read(hdr); 187 196 } 188 197 ··· 199 206 } 200 207 } 201 208 202 - static const struct nfs_pgio_completion_ops nfs_async_read_completion_ops = { 209 + const struct nfs_pgio_completion_ops nfs_async_read_completion_ops = { 203 210 .error_cleanup = nfs_async_read_error, 204 211 .completion = nfs_read_completion, 205 212 }; ··· 274 281 nfs_readpage_retry(task, hdr); 275 282 } 276 283 277 - static int readpage_async_filler(struct nfs_readdesc *desc, struct folio *folio) 284 + int nfs_read_add_folio(struct nfs_pageio_descriptor *pgio, 285 + struct nfs_open_context *ctx, 286 + struct folio *folio) 278 287 { 279 288 struct inode *inode = folio_file_mapping(folio)->host; 280 289 struct nfs_server *server = NFS_SERVER(inode); ··· 292 297 293 298 aligned_len = min_t(unsigned int, ALIGN(len, rsize), fsize); 294 299 295 - if (!IS_SYNC(inode)) { 296 - error = nfs_fscache_read_page(inode, &folio->page); 297 - if (error == 0) 298 - goto out_unlock; 300 + new = nfs_page_create_from_folio(ctx, folio, 0, aligned_len); 301 + if (IS_ERR(new)) { 302 + error = PTR_ERR(new); 303 + goto out; 299 304 } 300 - 301 - new = nfs_page_create_from_folio(desc->ctx, folio, 0, aligned_len); 302 - if (IS_ERR(new)) 303 - goto out_error; 304 305 305 306 if (len < fsize) 306 307 folio_zero_segment(folio, len, fsize); 307 - if (!nfs_pageio_add_request(&desc->pgio, new)) { 308 + if (!nfs_pageio_add_request(pgio, new)) { 308 309 nfs_list_remove_request(new); 309 - error = desc->pgio.pg_error; 310 + error = pgio->pg_error; 310 311 nfs_readpage_release(new, error); 311 312 goto out; 312 313 } 313 314 return 0; 314 - out_error: 315 - error = PTR_ERR(new); 316 - out_unlock: 317 - folio_unlock(folio); 318 315 out: 319 316 return error; 320 317 } ··· 319 332 */ 320 333 int nfs_read_folio(struct file *file, struct folio *folio) 321 334 { 322 - struct nfs_readdesc desc; 323 335 struct inode *inode = file_inode(file); 336 + struct nfs_pageio_descriptor pgio; 337 + struct nfs_open_context *ctx; 324 338 int ret; 325 339 326 340 trace_nfs_aop_readpage(inode, folio); ··· 345 357 if (NFS_STALE(inode)) 346 358 goto out_unlock; 347 359 348 - desc.ctx = get_nfs_open_context(nfs_file_open_context(file)); 349 - 350 - xchg(&desc.ctx->error, 0); 351 - nfs_pageio_init_read(&desc.pgio, inode, false, 352 - &nfs_async_read_completion_ops); 353 - 354 - ret = readpage_async_filler(&desc, folio); 355 - if (ret) 360 + ret = nfs_netfs_read_folio(file, folio); 361 + if (!ret) 356 362 goto out; 357 363 358 - nfs_pageio_complete_read(&desc.pgio); 359 - ret = desc.pgio.pg_error < 0 ? desc.pgio.pg_error : 0; 364 + ctx = get_nfs_open_context(nfs_file_open_context(file)); 365 + 366 + xchg(&ctx->error, 0); 367 + nfs_pageio_init_read(&pgio, inode, false, 368 + &nfs_async_read_completion_ops); 369 + 370 + ret = nfs_read_add_folio(&pgio, ctx, folio); 371 + if (ret) 372 + goto out_put; 373 + 374 + nfs_pageio_complete_read(&pgio); 375 + ret = pgio.pg_error < 0 ? pgio.pg_error : 0; 360 376 if (!ret) { 361 377 ret = folio_wait_locked_killable(folio); 362 378 if (!folio_test_uptodate(folio) && !ret) 363 - ret = xchg(&desc.ctx->error, 0); 379 + ret = xchg(&ctx->error, 0); 364 380 } 381 + out_put: 382 + put_nfs_open_context(ctx); 365 383 out: 366 - put_nfs_open_context(desc.ctx); 367 384 trace_nfs_aop_readpage_done(inode, folio, ret); 368 385 return ret; 369 386 out_unlock: 370 387 folio_unlock(folio); 371 - trace_nfs_aop_readpage_done(inode, folio, ret); 372 - return ret; 388 + goto out; 373 389 } 374 390 375 391 void nfs_readahead(struct readahead_control *ractl) 376 392 { 393 + struct nfs_pageio_descriptor pgio; 394 + struct nfs_open_context *ctx; 377 395 unsigned int nr_pages = readahead_count(ractl); 378 396 struct file *file = ractl->file; 379 - struct nfs_readdesc desc; 380 397 struct inode *inode = ractl->mapping->host; 381 398 struct folio *folio; 382 399 int ret; ··· 394 401 if (NFS_STALE(inode)) 395 402 goto out; 396 403 404 + ret = nfs_netfs_readahead(ractl); 405 + if (!ret) 406 + goto out; 407 + 397 408 if (file == NULL) { 398 409 ret = -EBADF; 399 - desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ); 400 - if (desc.ctx == NULL) 410 + ctx = nfs_find_open_context(inode, NULL, FMODE_READ); 411 + if (ctx == NULL) 401 412 goto out; 402 413 } else 403 - desc.ctx = get_nfs_open_context(nfs_file_open_context(file)); 414 + ctx = get_nfs_open_context(nfs_file_open_context(file)); 404 415 405 - nfs_pageio_init_read(&desc.pgio, inode, false, 416 + nfs_pageio_init_read(&pgio, inode, false, 406 417 &nfs_async_read_completion_ops); 407 418 408 419 while ((folio = readahead_folio(ractl)) != NULL) { 409 - ret = readpage_async_filler(&desc, folio); 420 + ret = nfs_read_add_folio(&pgio, ctx, folio); 410 421 if (ret) 411 422 break; 412 423 } 413 424 414 - nfs_pageio_complete_read(&desc.pgio); 425 + nfs_pageio_complete_read(&pgio); 415 426 416 - put_nfs_open_context(desc.ctx); 427 + put_nfs_open_context(ctx); 417 428 out: 418 429 trace_nfs_aop_readahead_done(inode, nr_pages, ret); 419 430 }
-11
fs/nfs/super.c
··· 692 692 totals.events[i] += stats->events[i]; 693 693 for (i = 0; i < __NFSIOS_BYTESMAX; i++) 694 694 totals.bytes[i] += stats->bytes[i]; 695 - #ifdef CONFIG_NFS_FSCACHE 696 - for (i = 0; i < __NFSIOS_FSCACHEMAX; i++) 697 - totals.fscache[i] += stats->fscache[i]; 698 - #endif 699 695 700 696 preempt_enable(); 701 697 } ··· 702 706 seq_puts(m, "\n\tbytes:\t"); 703 707 for (i = 0; i < __NFSIOS_BYTESMAX; i++) 704 708 seq_printf(m, "%Lu ", totals.bytes[i]); 705 - #ifdef CONFIG_NFS_FSCACHE 706 - if (nfss->options & NFS_OPTION_FSCACHE) { 707 - seq_puts(m, "\n\tfsc:\t"); 708 - for (i = 0; i < __NFSIOS_FSCACHEMAX; i++) 709 - seq_printf(m, "%Lu ", totals.fscache[i]); 710 - } 711 - #endif 712 709 seq_putc(m, '\n'); 713 710 714 711 rpc_clnt_show_stats(m, nfss->client);
+57 -15
include/linux/nfs_fs.h
··· 31 31 #include <linux/sunrpc/auth.h> 32 32 #include <linux/sunrpc/clnt.h> 33 33 34 + #ifdef CONFIG_NFS_FSCACHE 35 + #include <linux/netfs.h> 36 + #endif 37 + 34 38 #include <linux/nfs.h> 35 39 #include <linux/nfs2.h> 36 40 #include <linux/nfs3.h> ··· 195 191 /* Open contexts for shared mmap writes */ 196 192 struct list_head open_files; 197 193 194 + /* Keep track of out-of-order replies. 195 + * The ooo array contains start/end pairs of 196 + * numbers from the changeid sequence when 197 + * the inode's iversion has been updated. 198 + * It also contains end/start pair (i.e. reverse order) 199 + * of sections of the changeid sequence that have 200 + * been seen in replies from the server. 201 + * Normally these should match and when both 202 + * A:B and B:A are found in ooo, they are both removed. 203 + * And if a reply with A:B causes an iversion update 204 + * of A:B, then neither are added. 205 + * When a reply has pre_change that doesn't match 206 + * iversion, then the changeid pair and any consequent 207 + * change in iversion ARE added. Later replies 208 + * might fill in the gaps, or possibly a gap is caused 209 + * by a change from another client. 210 + * When a file or directory is opened, if the ooo table 211 + * is not empty, then we assume the gaps were due to 212 + * another client and we invalidate the cached data. 213 + * 214 + * We can only track a limited number of concurrent gaps. 215 + * Currently that limit is 16. 216 + * We allocate the table on demand. If there is insufficient 217 + * memory, then we probably cannot cache the file anyway 218 + * so there is no loss. 219 + */ 220 + struct { 221 + int cnt; 222 + struct { 223 + u64 start, end; 224 + } gap[16]; 225 + } *ooo; 226 + 198 227 #if IS_ENABLED(CONFIG_NFS_V4) 199 228 struct nfs4_cached_acl *nfs4_acl; 200 229 /* NFSv4 state */ ··· 241 204 /* how many bytes have been written/read and how many bytes queued up */ 242 205 __u64 write_io; 243 206 __u64 read_io; 244 - #ifdef CONFIG_NFS_FSCACHE 245 - struct fscache_cookie *fscache; 246 - #endif 247 - struct inode vfs_inode; 248 - 249 207 #ifdef CONFIG_NFS_V4_2 250 208 struct nfs4_xattr_cache *xattr_cache; 251 209 #endif 210 + union { 211 + struct inode vfs_inode; 212 + #ifdef CONFIG_NFS_FSCACHE 213 + struct netfs_inode netfs; /* netfs context and VFS inode */ 214 + #endif 215 + }; 252 216 }; 253 217 254 218 struct nfs4_copy_state { ··· 314 276 #define NFS_INO_ACL_LRU_SET (2) /* Inode is on the LRU list */ 315 277 #define NFS_INO_INVALIDATING (3) /* inode is being invalidated */ 316 278 #define NFS_INO_PRESERVE_UNLINKED (4) /* preserve file if removed while open */ 317 - #define NFS_INO_FSCACHE (5) /* inode can be cached by FS-Cache */ 318 279 #define NFS_INO_LAYOUTCOMMIT (9) /* layoutcommit required */ 319 280 #define NFS_INO_LAYOUTCOMMITTING (10) /* layoutcommit inflight */ 320 281 #define NFS_INO_LAYOUTSTATS (11) /* layoutstats inflight */ ··· 364 327 static inline int NFS_STALE(const struct inode *inode) 365 328 { 366 329 return test_bit(NFS_INO_STALE, &NFS_I(inode)->flags); 367 - } 368 - 369 - static inline struct fscache_cookie *nfs_i_fscache(struct inode *inode) 370 - { 371 - #ifdef CONFIG_NFS_FSCACHE 372 - return NFS_I(inode)->fscache; 373 - #else 374 - return NULL; 375 - #endif 376 330 } 377 331 378 332 static inline __u64 NFS_FILEID(const struct inode *inode) ··· 643 615 if (sizeof(ino_t) < sizeof(u64)) 644 616 ino ^= fileid >> (sizeof(u64)-sizeof(ino_t)) * 8; 645 617 return ino; 618 + } 619 + 620 + static inline void nfs_ooo_clear(struct nfs_inode *nfsi) 621 + { 622 + nfsi->cache_validity &= ~NFS_INO_DATA_INVAL_DEFER; 623 + kfree(nfsi->ooo); 624 + nfsi->ooo = NULL; 625 + } 626 + 627 + static inline bool nfs_ooo_test(struct nfs_inode *nfsi) 628 + { 629 + return (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER) || 630 + (nfsi->ooo && nfsi->ooo->cnt > 0); 631 + 646 632 } 647 633 648 634 #define NFS_JUKEBOX_RETRY_TIME (5 * HZ)
-12
include/linux/nfs_iostat.h
··· 119 119 __NFSIOS_COUNTSMAX, 120 120 }; 121 121 122 - /* 123 - * NFS local caching servicing counters 124 - */ 125 - enum nfs_stat_fscachecounters { 126 - NFSIOS_FSCACHE_PAGES_READ_OK, 127 - NFSIOS_FSCACHE_PAGES_READ_FAIL, 128 - NFSIOS_FSCACHE_PAGES_WRITTEN_OK, 129 - NFSIOS_FSCACHE_PAGES_WRITTEN_FAIL, 130 - NFSIOS_FSCACHE_PAGES_UNCACHED, 131 - __NFSIOS_FSCACHEMAX, 132 - }; 133 - 134 122 #endif /* _LINUX_NFS_IOSTAT */
+3
include/linux/nfs_page.h
··· 105 105 struct pnfs_layout_segment *pg_lseg; 106 106 struct nfs_io_completion *pg_io_completion; 107 107 struct nfs_direct_req *pg_dreq; 108 + #ifdef CONFIG_NFS_FSCACHE 109 + void *pg_netfs; 110 + #endif 108 111 unsigned int pg_bsize; /* default bsize for mirrors */ 109 112 110 113 u32 pg_mirror_count;
+4
include/linux/nfs_xdr.h
··· 670 670 struct { 671 671 unsigned int replen; /* used by read */ 672 672 int eof; /* used by read */ 673 + void * scratch; /* used by read */ 673 674 }; 674 675 struct { 675 676 struct nfs_writeverf * verf; /* used by write */ ··· 1620 1619 const struct nfs_rw_ops *rw_ops; 1621 1620 struct nfs_io_completion *io_completion; 1622 1621 struct nfs_direct_req *dreq; 1622 + #ifdef CONFIG_NFS_FSCACHE 1623 + void *netfs; 1624 + #endif 1623 1625 1624 1626 int pnfs_error; 1625 1627 int error; /* merge with pnfs_error */
+1 -2
include/linux/sunrpc/sched.h
··· 90 90 #endif 91 91 unsigned char tk_priority : 2,/* Task priority */ 92 92 tk_garb_retry : 2, 93 - tk_cred_retry : 2, 94 - tk_rebind_retry : 2; 93 + tk_cred_retry : 2; 95 94 }; 96 95 97 96 typedef void (*rpc_action)(struct rpc_task *);
-3
net/sunrpc/clnt.c
··· 2050 2050 status = -EOPNOTSUPP; 2051 2051 break; 2052 2052 } 2053 - if (task->tk_rebind_retry == 0) 2054 - break; 2055 - task->tk_rebind_retry--; 2056 2053 rpc_delay(task, 3*HZ); 2057 2054 goto retry_timeout; 2058 2055 case -ENOBUFS:
-1
net/sunrpc/sched.c
··· 817 817 /* Initialize retry counters */ 818 818 task->tk_garb_retry = 2; 819 819 task->tk_cred_retry = 2; 820 - task->tk_rebind_retry = 2; 821 820 822 821 /* starting timestamp */ 823 822 task->tk_start = ktime_get();
+15 -27
net/sunrpc/sysctl.c
··· 40 40 41 41 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) 42 42 43 - static struct ctl_table_header *sunrpc_table_header; 44 - static struct ctl_table sunrpc_table[]; 45 - 46 - void 47 - rpc_register_sysctl(void) 48 - { 49 - if (!sunrpc_table_header) 50 - sunrpc_table_header = register_sysctl_table(sunrpc_table); 51 - } 52 - 53 - void 54 - rpc_unregister_sysctl(void) 55 - { 56 - if (sunrpc_table_header) { 57 - unregister_sysctl_table(sunrpc_table_header); 58 - sunrpc_table_header = NULL; 59 - } 60 - } 61 - 62 43 static int proc_do_xprt(struct ctl_table *table, int write, 63 44 void *buffer, size_t *lenp, loff_t *ppos) 64 45 { ··· 123 142 return 0; 124 143 } 125 144 145 + static struct ctl_table_header *sunrpc_table_header; 126 146 127 147 static struct ctl_table debug_table[] = { 128 148 { ··· 163 181 { } 164 182 }; 165 183 166 - static struct ctl_table sunrpc_table[] = { 167 - { 168 - .procname = "sunrpc", 169 - .mode = 0555, 170 - .child = debug_table 171 - }, 172 - { } 173 - }; 184 + void 185 + rpc_register_sysctl(void) 186 + { 187 + if (!sunrpc_table_header) 188 + sunrpc_table_header = register_sysctl("sunrpc", debug_table); 189 + } 174 190 191 + void 192 + rpc_unregister_sysctl(void) 193 + { 194 + if (sunrpc_table_header) { 195 + unregister_sysctl_table(sunrpc_table_header); 196 + sunrpc_table_header = NULL; 197 + } 198 + } 175 199 #endif
+1 -10
net/sunrpc/xprtrdma/transport.c
··· 140 140 { }, 141 141 }; 142 142 143 - static struct ctl_table sunrpc_table[] = { 144 - { 145 - .procname = "sunrpc", 146 - .mode = 0555, 147 - .child = xr_tunables_table 148 - }, 149 - { }, 150 - }; 151 - 152 143 #endif 153 144 154 145 static const struct rpc_xprt_ops xprt_rdma_procs; ··· 790 799 791 800 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) 792 801 if (!sunrpc_table_header) 793 - sunrpc_table_header = register_sysctl_table(sunrpc_table); 802 + sunrpc_table_header = register_sysctl("sunrpc", xr_tunables_table); 794 803 #endif 795 804 return 0; 796 805 }
+2 -11
net/sunrpc/xprtsock.c
··· 78 78 79 79 /* 80 80 * We can register our own files under /proc/sys/sunrpc by 81 - * calling register_sysctl_table() again. The files in that 81 + * calling register_sysctl() again. The files in that 82 82 * directory become the union of all files registered there. 83 83 * 84 84 * We simply need to make sure that we don't collide with ··· 154 154 .maxlen = sizeof(xs_tcp_fin_timeout), 155 155 .mode = 0644, 156 156 .proc_handler = proc_dointvec_jiffies, 157 - }, 158 - { }, 159 - }; 160 - 161 - static struct ctl_table sunrpc_table[] = { 162 - { 163 - .procname = "sunrpc", 164 - .mode = 0555, 165 - .child = xs_tunables_table 166 157 }, 167 158 { }, 168 159 }; ··· 3169 3178 int init_socket_xprt(void) 3170 3179 { 3171 3180 if (!sunrpc_table_header) 3172 - sunrpc_table_header = register_sysctl_table(sunrpc_table); 3181 + sunrpc_table_header = register_sysctl("sunrpc", xs_tunables_table); 3173 3182 3174 3183 xprt_register_transport(&xs_local_transport); 3175 3184 xprt_register_transport(&xs_udp_transport);