diff options
author | Xavi Hernandez <xhernandez@redhat.com> | 2021-03-09 00:24:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-09 04:54:07 +0530 |
commit | dc9bab7959b068617ef00f355c63bdca060b9605 (patch) | |
tree | 077436685af60d830d8a72ebb5a1c45ddb32283d /xlators | |
parent | d917bc3299f6f1b89ca61971b04c41e70bedb24b (diff) | |
download | glusterfs-dc9bab7959b068617ef00f355c63bdca060b9605.tar.gz glusterfs-dc9bab7959b068617ef00f355c63bdca060b9605.tar.xz glusterfs-dc9bab7959b068617ef00f355c63bdca060b9605.zip |
afr: fix directory entry count (#2233)
AFR may hide some existing entries from a directory when reading it
because they are generated internally for private management. However
the returned number of entries from readdir() function is not updated
accordingly. So it may return a number higher than the real entries
present in the gf_dirent list.
This may cause unexpected behavior of clients, including gfapi which
incorrectly assumes that there was an entry when the list was actually
empty.
This patch also makes the check in gfapi more robust to avoid similar
issues that could appear in the future.
Fixes: #2232
Change-Id: I81ba3699248a53ebb0ee4e6e6231a4301436f763
Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/cluster/afr/src/afr-dir-read.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/xlators/cluster/afr/src/afr-dir-read.c b/xlators/cluster/afr/src/afr-dir-read.c index f8bf8340da..a6a3470569 100644 --- a/xlators/cluster/afr/src/afr-dir-read.c +++ b/xlators/cluster/afr/src/afr-dir-read.c @@ -163,7 +163,7 @@ afr_validate_read_subvol(inode_t *inode, xlator_t *this, int par_read_subvol) return 0; } -static void +static int32_t afr_readdir_transform_entries(call_frame_t *frame, gf_dirent_t *subvol_entries, int subvol, gf_dirent_t *entries, fd_t *fd) { @@ -174,6 +174,7 @@ afr_readdir_transform_entries(call_frame_t *frame, gf_dirent_t *subvol_entries, afr_private_t *priv = NULL; gf_boolean_t need_heal = _gf_false; gf_boolean_t validate_subvol = _gf_false; + int32_t count = 0; this = THIS; priv = this->private; @@ -190,6 +191,7 @@ afr_readdir_transform_entries(call_frame_t *frame, gf_dirent_t *subvol_entries, list_del_init(&entry->list); list_add_tail(&entry->list, &entries->list); + count++; if (!validate_subvol) continue; @@ -203,6 +205,8 @@ afr_readdir_transform_entries(call_frame_t *frame, gf_dirent_t *subvol_entries, } } } + + return count; } int32_t @@ -228,8 +232,9 @@ afr_readdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, } if (op_ret >= 0) - afr_readdir_transform_entries(frame, subvol_entries, (long)cookie, - &entries, local->fd); + op_ret = afr_readdir_transform_entries(frame, subvol_entries, + (long)cookie, &entries, + local->fd); AFR_STACK_UNWIND(readdir, frame, op_ret, op_errno, &entries, xdata); |