summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@zresearch.com>2009-05-05 15:59:03 +0530
committerAnand V. Avati <avati@amp.gluster.com>2009-05-05 17:36:23 +0530
commit7eb61fb44986fc834a19d9f38754f1be54d07e09 (patch)
treedb9da47c2db9edd592b929dd2ae935ee519fac41 /libglusterfsclient
parentb48df70c58f52878d58f3e1a0adc870688cdfcdc (diff)
libglusterfsclient: Conform'ify glusterfs_readdir
This commit does two things: 1. Changes glusterfs_readdir prototype to conform to the POSIX readdir(). 2. Uses a 1024-byte value instead of sizeof(struct dirent) for the @size for libgf_client_readdir. This allows even larger names to fit into a single readdir request to the server. Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'libglusterfsclient')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c42
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.h11
2 files changed, 31 insertions, 22 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index e34474982..6639356a7 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -49,6 +49,7 @@
#define LIBGF_XL_NAME "libglusterfsclient"
#define LIBGLUSTERFS_INODE_TABLE_LRU_LIMIT 1000 //14057
+#define LIBGF_READDIR_BLOCK 1024
static inline xlator_t *
libglusterfs_graph (xlator_t *graph);
@@ -3212,6 +3213,12 @@ libgf_client_readdir (libglusterfs_client_ctx_t *ctx,
dirp = (struct dirent *) (((char *) dirp) + entry_size);
count++;
+ /* FIXME: Someday, we'll enable processing
+ * more than one dirent. The reason we should
+ * break here is that the offset must not be
+ * updated beyond one entry.
+ */
+ break;
}
}
@@ -3219,17 +3226,18 @@ libgf_client_readdir (libglusterfs_client_ctx_t *ctx,
return op_ret;
}
-int
-glusterfs_readdir (glusterfs_dir_t fd,
- struct dirent *dirp,
- unsigned int count)
+static struct dirent __libgf_dirent;
+
+struct dirent *
+glusterfs_readdir (glusterfs_dir_t dirfd)
{
int op_ret = -1;
libglusterfs_client_ctx_t *ctx = NULL;
off_t offset = 0;
libglusterfs_client_fd_ctx_t *fd_ctx = NULL;
+ struct dirent *dirp = NULL;
- fd_ctx = libgf_get_fd_ctx (fd);
+ fd_ctx = libgf_get_fd_ctx (dirfd);
if (!fd_ctx) {
errno = EBADF;
goto out;
@@ -3242,20 +3250,24 @@ glusterfs_readdir (glusterfs_dir_t fd,
}
pthread_mutex_unlock (&fd_ctx->lock);
- op_ret = libgf_client_readdir (ctx, (fd_t *)fd, dirp, sizeof (*dirp),
- &offset, 1);
+ dirp = &__libgf_dirent;
+ memset (dirp, 0, sizeof (struct dirent));
+ op_ret = libgf_client_readdir (ctx, (fd_t *)dirfd, dirp,
+ LIBGF_READDIR_BLOCK, &offset, 1);
- if (op_ret > 0) {
- pthread_mutex_lock (&fd_ctx->lock);
- {
- fd_ctx->offset = offset;
- }
- pthread_mutex_unlock (&fd_ctx->lock);
- op_ret = 1;
+ if (op_ret <= 0) {
+ dirp = NULL;
+ goto out;
}
+ pthread_mutex_lock (&fd_ctx->lock);
+ {
+ fd_ctx->offset = offset;
+ }
+ pthread_mutex_unlock (&fd_ctx->lock);
+
out:
- return op_ret;
+ return dirp;
}
diff --git a/libglusterfsclient/src/libglusterfsclient.h b/libglusterfsclient/src/libglusterfsclient.h
index ae0d86a0e..1c2441b2b 100755
--- a/libglusterfsclient/src/libglusterfsclient.h
+++ b/libglusterfsclient/src/libglusterfsclient.h
@@ -607,15 +607,12 @@ glusterfs_rmdir (const char *path);
*
* @fd : The handle of the directory to be read. This handle
* is the one returned by opendir.
- * @dirp : The pointer to the array of directory entries into
- * which the directory data will be stored.
- * @count : Number of directory entries to be read.
*
- * Returns 0 on success and -1 on error with errno set appropriately.
+ * Returns the directory entry on success and NULL pointer on error
+ * with errno set appropriately.
*/
-int
-glusterfs_readdir (glusterfs_dir_t fd, struct dirent *dirp,
- unsigned int count);
+struct dirent *
+glusterfs_readdir (glusterfs_dir_t dirfd);