Lines Matching refs:desc
179 static void nfs_set_dtsize(struct nfs_readdir_descriptor *desc, unsigned int sz) in nfs_set_dtsize() argument
181 struct nfs_server *server = NFS_SERVER(file_inode(desc->file)); in nfs_set_dtsize()
188 desc->dtsize = sz; in nfs_set_dtsize()
191 static void nfs_shrink_dtsize(struct nfs_readdir_descriptor *desc) in nfs_shrink_dtsize() argument
193 nfs_set_dtsize(desc, desc->dtsize >> 1); in nfs_shrink_dtsize()
196 static void nfs_grow_dtsize(struct nfs_readdir_descriptor *desc) in nfs_grow_dtsize() argument
198 nfs_set_dtsize(desc, desc->dtsize << 1); in nfs_grow_dtsize()
479 struct nfs_readdir_descriptor *desc) in nfs_readdir_seek_next_array() argument
482 desc->last_cookie = array->last_cookie; in nfs_readdir_seek_next_array()
483 desc->current_index += array->size; in nfs_readdir_seek_next_array()
484 desc->cache_entry_index = 0; in nfs_readdir_seek_next_array()
485 desc->folio_index++; in nfs_readdir_seek_next_array()
487 desc->last_cookie = nfs_readdir_array_index_cookie(array); in nfs_readdir_seek_next_array()
490 static void nfs_readdir_rewind_search(struct nfs_readdir_descriptor *desc) in nfs_readdir_rewind_search() argument
492 desc->current_index = 0; in nfs_readdir_rewind_search()
493 desc->last_cookie = 0; in nfs_readdir_rewind_search()
494 desc->folio_index = 0; in nfs_readdir_rewind_search()
498 struct nfs_readdir_descriptor *desc) in nfs_readdir_search_for_pos() argument
500 loff_t diff = desc->ctx->pos - desc->current_index; in nfs_readdir_search_for_pos()
508 nfs_readdir_seek_next_array(array, desc); in nfs_readdir_search_for_pos()
513 desc->dir_cookie = array->array[index].cookie; in nfs_readdir_search_for_pos()
514 desc->cache_entry_index = index; in nfs_readdir_search_for_pos()
517 desc->eof = true; in nfs_readdir_search_for_pos()
535 struct nfs_readdir_descriptor *desc) in nfs_readdir_search_for_cookie() argument
540 if (!nfs_readdir_array_cookie_in_range(array, desc->dir_cookie)) in nfs_readdir_search_for_cookie()
544 if (array->array[i].cookie == desc->dir_cookie) { in nfs_readdir_search_for_cookie()
545 if (nfs_readdir_use_cookie(desc->file)) in nfs_readdir_search_for_cookie()
546 desc->ctx->pos = desc->dir_cookie; in nfs_readdir_search_for_cookie()
548 desc->ctx->pos = desc->current_index + i; in nfs_readdir_search_for_cookie()
549 desc->cache_entry_index = i; in nfs_readdir_search_for_cookie()
556 if (desc->dir_cookie == array->last_cookie) in nfs_readdir_search_for_cookie()
557 desc->eof = true; in nfs_readdir_search_for_cookie()
559 nfs_readdir_seek_next_array(array, desc); in nfs_readdir_search_for_cookie()
563 static int nfs_readdir_search_array(struct nfs_readdir_descriptor *desc) in nfs_readdir_search_array() argument
568 array = kmap_local_folio(desc->folio, 0); in nfs_readdir_search_array()
570 if (desc->dir_cookie == 0) in nfs_readdir_search_array()
571 status = nfs_readdir_search_for_pos(array, desc); in nfs_readdir_search_array()
573 status = nfs_readdir_search_for_cookie(array, desc); in nfs_readdir_search_array()
580 static int nfs_readdir_xdr_filler(struct nfs_readdir_descriptor *desc, in nfs_readdir_xdr_filler() argument
585 struct inode *inode = file_inode(desc->file); in nfs_readdir_xdr_filler()
587 .dentry = file_dentry(desc->file), in nfs_readdir_xdr_filler()
588 .cred = desc->file->f_cred, in nfs_readdir_xdr_filler()
593 .plus = desc->plus, in nfs_readdir_xdr_filler()
604 desc->dir_verifier = nfs_save_change_attribute(inode); in nfs_readdir_xdr_filler()
608 if (error == -ENOTSUPP && desc->plus) { in nfs_readdir_xdr_filler()
610 desc->plus = arg.plus = false; in nfs_readdir_xdr_filler()
615 desc->timestamp = timestamp; in nfs_readdir_xdr_filler()
616 desc->gencount = gencount; in nfs_readdir_xdr_filler()
621 static int xdr_decode(struct nfs_readdir_descriptor *desc, in xdr_decode() argument
624 struct inode *inode = file_inode(desc->file); in xdr_decode()
627 error = NFS_PROTO(inode)->decode_dirent(xdr, entry, desc->plus); in xdr_decode()
630 entry->fattr->time_start = desc->timestamp; in xdr_decode()
631 entry->fattr->gencount = desc->gencount; in xdr_decode()
803 static int nfs_readdir_entry_decode(struct nfs_readdir_descriptor *desc, in nfs_readdir_entry_decode() argument
811 ret = xdr_decode(desc, entry, stream); in nfs_readdir_entry_decode()
812 if (ret || !desc->plus) in nfs_readdir_entry_decode()
814 nfs_prime_dcache(file_dentry(desc->file), entry, desc->dir_verifier); in nfs_readdir_entry_decode()
819 static int nfs_readdir_folio_filler(struct nfs_readdir_descriptor *desc, in nfs_readdir_folio_filler() argument
825 struct address_space *mapping = desc->file->f_mapping; in nfs_readdir_folio_filler()
841 status = nfs_readdir_entry_decode(desc, entry, &stream); in nfs_readdir_folio_filler()
866 desc->folio_index_max++; in nfs_readdir_folio_filler()
881 if (!desc->plus) in nfs_readdir_folio_filler()
883 while (!nfs_readdir_entry_decode(desc, entry, &stream)) in nfs_readdir_folio_filler()
926 static int nfs_readdir_xdr_to_array(struct nfs_readdir_descriptor *desc, in nfs_readdir_xdr_to_array() argument
935 struct inode *inode = file_inode(desc->file); in nfs_readdir_xdr_to_array()
936 unsigned int dtsize = desc->dtsize; in nfs_readdir_xdr_to_array()
956 status = nfs_readdir_xdr_filler(desc, verf_arg, entry->cookie, pages, in nfs_readdir_xdr_to_array()
963 status = nfs_readdir_folio_filler(desc, entry, pages, pglen, in nfs_readdir_xdr_to_array()
967 desc->buffer_fills++; in nfs_readdir_xdr_to_array()
978 static void nfs_readdir_folio_put(struct nfs_readdir_descriptor *desc) in nfs_readdir_folio_put() argument
980 folio_put(desc->folio); in nfs_readdir_folio_put()
981 desc->folio = NULL; in nfs_readdir_folio_put()
985 nfs_readdir_folio_unlock_and_put_cached(struct nfs_readdir_descriptor *desc) in nfs_readdir_folio_unlock_and_put_cached() argument
987 folio_unlock(desc->folio); in nfs_readdir_folio_unlock_and_put_cached()
988 nfs_readdir_folio_put(desc); in nfs_readdir_folio_unlock_and_put_cached()
992 nfs_readdir_folio_get_cached(struct nfs_readdir_descriptor *desc) in nfs_readdir_folio_get_cached() argument
994 struct address_space *mapping = desc->file->f_mapping; in nfs_readdir_folio_get_cached()
996 u64 cookie = desc->last_cookie; in nfs_readdir_folio_get_cached()
1002 if (desc->clear_cache && !nfs_readdir_folio_needs_filling(folio)) in nfs_readdir_folio_get_cached()
1011 static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc) in find_and_lock_cache_page() argument
1013 struct inode *inode = file_inode(desc->file); in find_and_lock_cache_page()
1018 desc->folio = nfs_readdir_folio_get_cached(desc); in find_and_lock_cache_page()
1019 if (!desc->folio) in find_and_lock_cache_page()
1021 if (nfs_readdir_folio_needs_filling(desc->folio)) { in find_and_lock_cache_page()
1023 if (desc->folio_index == desc->folio_index_max) in find_and_lock_cache_page()
1024 nfs_grow_dtsize(desc); in find_and_lock_cache_page()
1025 desc->folio_index_max = desc->folio_index; in find_and_lock_cache_page()
1026 trace_nfs_readdir_cache_fill(desc->file, nfsi->cookieverf, in find_and_lock_cache_page()
1027 desc->last_cookie, in find_and_lock_cache_page()
1028 desc->folio->index, desc->dtsize); in find_and_lock_cache_page()
1029 res = nfs_readdir_xdr_to_array(desc, nfsi->cookieverf, verf, in find_and_lock_cache_page()
1030 &desc->folio, 1); in find_and_lock_cache_page()
1032 nfs_readdir_folio_unlock_and_put_cached(desc); in find_and_lock_cache_page()
1035 invalidate_inode_pages2(desc->file->f_mapping); in find_and_lock_cache_page()
1036 nfs_readdir_rewind_search(desc); in find_and_lock_cache_page()
1046 if (desc->last_cookie == 0 && in find_and_lock_cache_page()
1050 invalidate_inode_pages2_range(desc->file->f_mapping, 1, in find_and_lock_cache_page()
1055 desc->clear_cache = false; in find_and_lock_cache_page()
1057 res = nfs_readdir_search_array(desc); in find_and_lock_cache_page()
1060 nfs_readdir_folio_unlock_and_put_cached(desc); in find_and_lock_cache_page()
1065 static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc) in readdir_search_pagecache() argument
1070 res = find_and_lock_cache_page(desc); in readdir_search_pagecache()
1080 static void nfs_do_filldir(struct nfs_readdir_descriptor *desc, in nfs_do_filldir() argument
1083 struct file *file = desc->file; in nfs_do_filldir()
1086 bool first_emit = !desc->dir_cookie; in nfs_do_filldir()
1088 array = kmap_local_folio(desc->folio, 0); in nfs_do_filldir()
1089 for (i = desc->cache_entry_index; i < array->size; i++) { in nfs_do_filldir()
1099 desc->eob = true; in nfs_do_filldir()
1104 if (!dir_emit(desc->ctx, ent->name, ent->name_len, in nfs_do_filldir()
1106 desc->eob = true; in nfs_do_filldir()
1109 memcpy(desc->verf, verf, sizeof(desc->verf)); in nfs_do_filldir()
1111 desc->dir_cookie = array->last_cookie; in nfs_do_filldir()
1112 nfs_readdir_seek_next_array(array, desc); in nfs_do_filldir()
1114 desc->dir_cookie = array->array[i + 1].cookie; in nfs_do_filldir()
1115 desc->last_cookie = array->array[0].cookie; in nfs_do_filldir()
1118 desc->ctx->pos = desc->dir_cookie; in nfs_do_filldir()
1120 desc->ctx->pos++; in nfs_do_filldir()
1123 desc->eof = !desc->eob; in nfs_do_filldir()
1127 (unsigned long long)desc->dir_cookie); in nfs_do_filldir()
1142 static int uncached_readdir(struct nfs_readdir_descriptor *desc) in uncached_readdir() argument
1150 (unsigned long long)desc->dir_cookie); in uncached_readdir()
1155 arrays[0] = nfs_readdir_folio_array_alloc(desc->dir_cookie, GFP_KERNEL); in uncached_readdir()
1159 desc->folio_index = 0; in uncached_readdir()
1160 desc->cache_entry_index = 0; in uncached_readdir()
1161 desc->last_cookie = desc->dir_cookie; in uncached_readdir()
1162 desc->folio_index_max = 0; in uncached_readdir()
1164 trace_nfs_readdir_uncached(desc->file, desc->verf, desc->last_cookie, in uncached_readdir()
1165 -1, desc->dtsize); in uncached_readdir()
1167 status = nfs_readdir_xdr_to_array(desc, desc->verf, verf, arrays, sz); in uncached_readdir()
1169 trace_nfs_readdir_uncached_done(file_inode(desc->file), status); in uncached_readdir()
1173 for (i = 0; !desc->eob && i < sz && arrays[i]; i++) { in uncached_readdir()
1174 desc->folio = arrays[i]; in uncached_readdir()
1175 nfs_do_filldir(desc, verf); in uncached_readdir()
1177 desc->folio = NULL; in uncached_readdir()
1183 if (!desc->eof) { in uncached_readdir()
1184 if (!desc->eob) in uncached_readdir()
1185 nfs_grow_dtsize(desc); in uncached_readdir()
1186 else if (desc->buffer_fills == 1 && in uncached_readdir()
1187 i < (desc->folio_index_max >> 1)) in uncached_readdir()
1188 nfs_shrink_dtsize(desc); in uncached_readdir()
1194 if (!nfs_readdir_use_cookie(desc->file)) in uncached_readdir()
1195 nfs_readdir_rewind_search(desc); in uncached_readdir()
1196 desc->folio_index_max = -1; in uncached_readdir()
1203 struct nfs_readdir_descriptor *desc, in nfs_readdir_handle_cache_misses() argument
1207 if (desc->ctx->pos == 0 || !desc->plus) in nfs_readdir_handle_cache_misses()
1225 struct nfs_readdir_descriptor *desc; in nfs_readdir() local
1243 desc = kzalloc(sizeof(*desc), GFP_KERNEL); in nfs_readdir()
1244 if (!desc) in nfs_readdir()
1246 desc->file = file; in nfs_readdir()
1247 desc->ctx = ctx; in nfs_readdir()
1248 desc->folio_index_max = -1; in nfs_readdir()
1251 desc->dir_cookie = dir_ctx->dir_cookie; in nfs_readdir()
1252 desc->folio_index = dir_ctx->page_index; in nfs_readdir()
1253 desc->last_cookie = dir_ctx->last_cookie; in nfs_readdir()
1254 desc->attr_gencount = dir_ctx->attr_gencount; in nfs_readdir()
1255 desc->eof = dir_ctx->eof; in nfs_readdir()
1256 nfs_set_dtsize(desc, dir_ctx->dtsize); in nfs_readdir()
1257 memcpy(desc->verf, dir_ctx->verf, sizeof(desc->verf)); in nfs_readdir()
1263 if (desc->eof) { in nfs_readdir()
1268 desc->plus = nfs_use_readdirplus(inode, ctx, cache_hits, cache_misses); in nfs_readdir()
1269 force_clear = nfs_readdir_handle_cache_misses(inode, desc, cache_misses, in nfs_readdir()
1271 desc->clear_cache = force_clear; in nfs_readdir()
1274 res = readdir_search_pagecache(desc); in nfs_readdir()
1279 if (desc->dir_cookie && !desc->eof) { in nfs_readdir()
1281 res = uncached_readdir(desc); in nfs_readdir()
1289 if (res == -ETOOSMALL && desc->plus) { in nfs_readdir()
1291 desc->plus = false; in nfs_readdir()
1292 desc->eof = false; in nfs_readdir()
1298 nfs_do_filldir(desc, nfsi->cookieverf); in nfs_readdir()
1299 nfs_readdir_folio_unlock_and_put_cached(desc); in nfs_readdir()
1300 if (desc->folio_index == desc->folio_index_max) in nfs_readdir()
1301 desc->clear_cache = force_clear; in nfs_readdir()
1302 } while (!desc->eob && !desc->eof); in nfs_readdir()
1305 dir_ctx->dir_cookie = desc->dir_cookie; in nfs_readdir()
1306 dir_ctx->last_cookie = desc->last_cookie; in nfs_readdir()
1307 dir_ctx->attr_gencount = desc->attr_gencount; in nfs_readdir()
1308 dir_ctx->page_index = desc->folio_index; in nfs_readdir()
1310 dir_ctx->eof = desc->eof; in nfs_readdir()
1311 dir_ctx->dtsize = desc->dtsize; in nfs_readdir()
1312 memcpy(dir_ctx->verf, desc->verf, sizeof(dir_ctx->verf)); in nfs_readdir()
1315 kfree(desc); in nfs_readdir()