cifs: fix bug when skipping one entry too many after lseek()
Subsystems (2)
Steve, List
Please see an updated patch for the issue when skipping one entry too many after an lseek() on a direcotry and reading out of cache.
This now makes this patch plus patch4 pass generic/257.
It also introduces a trivial change to readir to avoid creating holes in thectx->pos sequence. We either need to handle holes in this sequence
or we can just avoid creating holes in the first place (which this patch does)
PATCH 1/1 cifs: fix skipping to incorrect offset in emit_cached_dirents
When application has done lseek() to a different offset on a directory fd we skipped one entry too many before we start emitting directory entries from the cache.
Also change cifs_filldir() to return -EEXIST when we encouter a dot-directory in the reply from the server. Check for this in the caller and skip caching the entry and skip incprementing ctx->pos or else we end up emitting a sequence of directory entries with holes in the ctx->pos space.
--- fs/cifs/readdir.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
fs/cifs/readdir.c +18 -7
@@ -847,14 +847,14 @@ static bool emit_cached_dirents(struct cached_dirents *cde,int rc;list_for_each_entry (dirent, &cde->entries, entry) { -if (ctx->pos >= dirent->pos) +if (ctx->pos > dirent->pos)continue ; - ctx->pos = dirent->pos; rc =dir_emit (ctx, dirent->name, dirent->namelen, dirent->fattr.cf_uniqueid, dirent->fattr.cf_dtype);if (!rc)return rc; + ctx->pos++; }return true; }
@@ -965,7 +965,7 @@ static int cifs_filldir(char *find_entry, struct file *file,/* skip . and .. since we added them first */ if (cifs_entry_is_dot (&de, file_info->srch_inf.unicode)) -return 0 ; +return -EEXIST ;if (file_info->srch_inf.unicode) {struct nls_table *nlt = cifs_sb->local_nls;
@@ -1183,6 +1183,17 @@ int cifs_readdir(struct file *file, struct dir_context *ctx) *tmp_buf =0 ; rc =cifs_filldir (current_entry, file, ctx, tmp_buf, max_len, cfid); +/* +* If we got a dot directory, just skip to the next entry. +* We have already emitted it. +*/ +if (rc == -EEXIST ) { + current_entry = +nxt_dir_entry (current_entry, end_of_smb, + cifsFile->srch_inf.info_level); + rc =0 ; +continue ; + }if (rc) {if (rc >0 ) rc =0 ;
@@ -1202,10 +1213,10 @@ int cifs_readdir(struct file *file, struct dir_context *ctx) ctx->pos, tmp_buf);cifs_save_resume_key (current_entry, cifsFile);break ; - }else - current_entry = -nxt_dir_entry (current_entry, end_of_smb, - cifsFile->srch_inf.info_level); + } + current_entry = +nxt_dir_entry (current_entry, end_of_smb, + cifsFile->srch_inf.info_level); }kfree (tmp_buf);
Signature · 1 line
2.35.3