summaryrefslogtreecommitdiffstats
path: root/xlators/storage
diff options
context:
space:
mode:
authorEmmanuel Dreyfus <manu@netbsd.org>2014-12-17 10:41:05 +0100
committerRaghavendra Bhat <raghavendra@redhat.com>2014-12-17 03:48:22 -0800
commite398f99d9ac7ca5c83004b814a4e8561916187f0 (patch)
treed74d7fe7dc7e45aa37b12fb88557c5ecab4a68b4 /xlators/storage
parent466a6f37ebaaad746e2eae045ebd249e28673717 (diff)
telldir()/seekdir() portability fixes
POSIX says that an offset obtained from telldir() can only be used on the same DIR *. Linux is abls to reuse the offset accross closedir()/opendir() for a given directory, but this is not portable and such a behavior should be fixed. An incomplete fix for the posix xlator was merged in http://review.gluster.com/8926 This change set completes it. - Perform the same fix index xlator. - Use appropriate casts and variable types so that 32 bit signed offsets obtained by telldir() do not get clobbered when copied into 64 bit signed types. - modify glfs-heal.c and afr-self-heald.c so that they do not use anonymous fd, since this will cause closedir()/opendir() between each syncop_readdir(). On failure we fallback to anonymous fs only for Linux so that we can cope with updated client vs not updated brick. - Avoid sending an EINVAL when the client request for the EOF offset. Here we fix an error in previous fix for posix xlator: since we fill each directory entry with the offset of the next entry, we must consider as EOF the offset of the last entry, and not the value of telldir() after we read it. - Add checks in regression tests that we do not hit cases where offsets fed to seekdir() are wrong. Introduce log_newer() shell function to check for messages produced by the current script. This fix gather changes from http://review.gluster.org/9047 and http://review.gluster.org/8936 making them obsolete. BUG: 1129939 Change-Id: I59fb7f06a872c4f98987105792d648141c258c6a Signed-off-by: Emmanuel Dreyfus <manu@netbsd.org> Reviewed-on: http://review.gluster.org/9071 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com> Tested-by: Raghavendra Bhat <raghavendra@redhat.com>
Diffstat (limited to 'xlators/storage')
-rw-r--r--xlators/storage/posix/src/posix.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index a3aa57a..638e0f5 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -4857,6 +4857,7 @@ posix_fill_readdir (fd_t *fd, DIR *dir, off_t off, size_t size,
gf_dirent_t *entries, xlator_t *this, int32_t skip_dirs)
{
off_t in_case = -1;
+ off_t last_off = 0;
size_t filled = 0;
int count = 0;
char entrybuf[sizeof(struct dirent) + 256 + 8];
@@ -4892,11 +4893,11 @@ posix_fill_readdir (fd_t *fd, DIR *dir, off_t off, size_t size,
} else {
seekdir (dir, off);
#ifndef GF_LINUX_HOST_OS
- if (telldir(dir) != (long)off && off != pfd->dir_eof) {
+ if ((u_long)telldir(dir) != off && off != pfd->dir_eof) {
gf_log (THIS->name, GF_LOG_ERROR,
- "seekdir(%ld) failed on dir=%p: "
+ "seekdir(0x%llx) failed on dir=%p: "
"Invalid argument (offset reused from "
- "another DIR * structure?)", (long)off, dir);
+ "another DIR * structure?)", off, dir);
errno = EINVAL;
count = -1;
goto out;
@@ -4905,7 +4906,7 @@ posix_fill_readdir (fd_t *fd, DIR *dir, off_t off, size_t size,
}
while (filled <= size) {
- in_case = telldir (dir);
+ in_case = (u_long)telldir (dir);
if (in_case == -1) {
gf_log (THIS->name, GF_LOG_ERROR,
@@ -4965,13 +4966,13 @@ posix_fill_readdir (fd_t *fd, DIR *dir, off_t off, size_t size,
if (this_size + filled > size) {
seekdir (dir, in_case);
#ifndef GF_LINUX_HOST_OS
- if (telldir(dir) != (long)in_case &&
+ if ((u_long)telldir(dir) != in_case &&
in_case != pfd->dir_eof) {
gf_log (THIS->name, GF_LOG_ERROR,
- "seekdir(%ld) failed on dir=%p: "
+ "seekdir(0x%llx) failed on dir=%p: "
"Invalid argument (offset reused from "
"another DIR * structure?)",
- (long)in_case, dir);
+ in_case, dir);
errno = EINVAL;
count = -1;
goto out;
@@ -4988,7 +4989,14 @@ posix_fill_readdir (fd_t *fd, DIR *dir, off_t off, size_t size,
entry->d_name, strerror (errno));
goto out;
}
- this_entry->d_off = telldir (dir);
+ /*
+ * we store the offset of next entry here, which is
+ * probably not intended, but code using syncop_readdir()
+ * (glfs-heal.c, afr-self-heald.c, pump.c) rely on it
+ * for directory read resumption.
+ */
+ last_off = (u_long)telldir(dir);
+ this_entry->d_off = last_off;
this_entry->d_ino = entry->d_ino;
this_entry->d_type = entry->d_type;
@@ -5002,7 +5010,7 @@ posix_fill_readdir (fd_t *fd, DIR *dir, off_t off, size_t size,
/* Indicate EOF */
errno = ENOENT;
/* Remember EOF offset for later detection */
- pfd->dir_eof = telldir (dir);
+ pfd->dir_eof = (u_long)last_off;
}
out:
return count;