From aeda0a31977e8da295b913e6a306ff01ccf0ce0a Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Mon, 11 May 2009 18:22:29 +0530 Subject: libglusterfsclient: Revert and re-do readdir conformance This commit basically reverts the previous readdir conformance patch I sent a few days back. That commit had a completely retarded and broken way of maintaining per-directory dirent. It was broken for two reasons: 1. Creating a wrapper structure around the directory's fd_t only for storing a struct dirent is not clean enough. This commit takes a better approach by storing the dirent in fd_t context. This dirent is valid only if the fd_t refers to a directory. 2. That commit was made and tested under the assumption (..stupidity is a better word..) that only opendir call is used for opening a directory. That is not correct. Directories are also opened using the open syscall. The point is, glusterfs_open returns an fd_t and so did glusterfs_opendir. The previous patch actually changed opendir to return a new wrapper structure. That is fine, if we go by the POSIX definition of open and opendir because, they're both supposed to return different types, an int and a DIR*. However, in libglusterfsclient, all other code assumes that directory handles corresponding to DIR* and file descriptors corresponding to int types are the same type, resulting in use of the same locking and fd context addition/extraction code. So a directory opened using opendir returned a wrapper structure which went down into the libglusterfsclient stack where some function called a lock on the handle assuming it was an fd_t, since it is not and dereferencing of the supposed fd->inode->lock results in a seg fault. Obviously, this didnt show up till unfs3 used open() to open a directory and not opendir. Signed-off-by: Anand V. Avati --- libglusterfsclient/src/libglusterfsclient-internals.h | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'libglusterfsclient/src/libglusterfsclient-internals.h') diff --git a/libglusterfsclient/src/libglusterfsclient-internals.h b/libglusterfsclient/src/libglusterfsclient-internals.h index 4cdde26e7..40ad6f692 100755 --- a/libglusterfsclient/src/libglusterfsclient-internals.h +++ b/libglusterfsclient/src/libglusterfsclient-internals.h @@ -83,6 +83,11 @@ typedef struct { pthread_mutex_t lock; off_t offset; libglusterfs_client_ctx_t *ctx; + /* `man readdir` says readdir is non-re-entrant + * only if two readdirs are racing on the same + * handle. + */ + struct dirent dirp; } libglusterfs_client_fd_ctx_t; typedef struct libglusterfs_client_async_local { @@ -231,16 +236,4 @@ struct vmp_entry { }; -/* Internal directory handle inited in opendir. - * This is needed in order to store a per-handle - * dirent structure. - */ -struct libgf_dir_handle { - fd_t *dirfd; - struct dirent dirp; -}; - - - - #endif -- cgit