summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient/src
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@zresearch.com>2009-03-30 03:57:20 -0700
committerAnand V. Avati <avati@amp.gluster.com>2009-04-03 19:24:35 +0530
commite60d2194840b78034db1ad5c8b385a691ab3ddb6 (patch)
treeb4ee712579d99caa53260c0a43af7f78d4c6f2cc /libglusterfsclient/src
parent8b8448799cc43f20f5812bf5629c8670f76f78d3 (diff)
libglusterfsclient - change implementation of glusterfs_get
- remove redundent lookups happening in glusterfs_get. Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'libglusterfsclient/src')
-rw-r--r--libglusterfsclient/src/libglusterfsclient-dentry.c32
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient-internals.h3
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c55
3 files changed, 49 insertions, 41 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient-dentry.c b/libglusterfsclient/src/libglusterfsclient-dentry.c
index f2e1e17ff..8500827fa 100644
--- a/libglusterfsclient/src/libglusterfsclient-dentry.c
+++ b/libglusterfsclient/src/libglusterfsclient-dentry.c
@@ -322,7 +322,8 @@ out:
/* resolves loc->path to loc->parent and loc->inode */
int32_t
libgf_client_path_lookup (loc_t *loc,
- libglusterfs_client_ctx_t *ctx)
+ libglusterfs_client_ctx_t *ctx,
+ char lookup_basename)
{
char *pathname = NULL;
char *directory = NULL;
@@ -345,19 +346,30 @@ libgf_client_path_lookup (loc_t *loc,
}
libgf_client_loc_wipe (&new_loc);
- inode = inode_from_path (ctx->itable, loc->path);
pathname = strdup (loc->path);
directory = dirname (pathname);
parent = inode_from_path (ctx->itable, directory);
-
- if (inode && parent) {
- gf_log ("libglusterfsclient",
- GF_LOG_DEBUG,
- "resolved path(%s) to %"PRId64"/%"PRId64"(%s)",
- loc->path, parent->ino, inode->ino, loc->name);
- loc->inode = inode;
+
+ if (parent != NULL) {
loc->parent = parent;
- goto out;
+
+ if (!lookup_basename) {
+ gf_log ("libglusterfsclient",
+ GF_LOG_DEBUG,
+ "resolved dirname(%s) to %"PRId64,
+ loc->path, parent->ino);
+ goto out;
+ } else {
+ inode = inode_from_path (ctx->itable, loc->path);
+ if (inode != NULL) {
+ gf_log ("libglusterfsclient",
+ GF_LOG_DEBUG,
+ "resolved path(%s) to %"PRId64"/%"PRId64,
+ loc->path, parent->ino, inode->ino);
+ loc->inode = inode;
+ goto out;
+ }
+ }
} else {
gf_log ("libglusterfsclient",
GF_LOG_DEBUG,
diff --git a/libglusterfsclient/src/libglusterfsclient-internals.h b/libglusterfsclient/src/libglusterfsclient-internals.h
index 4296284fd..ad5e12fcb 100755
--- a/libglusterfsclient/src/libglusterfsclient-internals.h
+++ b/libglusterfsclient/src/libglusterfsclient-internals.h
@@ -153,7 +153,8 @@ libgf_client_loc_fill (loc_t *loc,
int32_t
libgf_client_path_lookup (loc_t *loc,
- libglusterfs_client_ctx_t *ctx);
+ libglusterfs_client_ctx_t *ctx,
+ char lookup_basename);
int32_t
libgf_client_lookup (libglusterfs_client_ctx_t *ctx,
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index 6eac2ecf4..01250f89c 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -269,10 +269,11 @@ libgf_client_loc_fill (loc_t *loc,
inode = inode_search (ctx->itable, par, name);
loc->inode = inode;
- if (inode)
- loc->ino = inode->ino;
}
+ if (inode)
+ loc->ino = inode->ino;
+
parent = loc->parent;
if (!parent) {
if (inode)
@@ -926,7 +927,7 @@ glusterfs_get (glusterfs_handle_t handle,
}
loc.path = strdup (path);
- op_ret = libgf_client_path_lookup (&loc, ctx);
+ op_ret = libgf_client_path_lookup (&loc, ctx, 0);
if (op_ret == -1) {
gf_log ("libglusterfsclient",
GF_LOG_ERROR,
@@ -938,20 +939,18 @@ glusterfs_get (glusterfs_handle_t handle,
name = basename (pathname);
op_ret = libgf_client_loc_fill (&loc, ctx, 0, loc.parent->ino, name);
- if (op_ret < 0) {
- gf_log ("libglusterfsclient",
- GF_LOG_ERROR,
- "libgf_client_loc_fill returned -1, returning EINVAL");
- errno = EINVAL;
- goto out;
- }
-
- if (size < 0)
- size = 0;
+ if (op_ret < 0) {
+ gf_log ("libglusterfsclient",
+ GF_LOG_ERROR,
+ "libgf_client_loc_fill returned -1, returning EINVAL");
+ errno = EINVAL;
+ goto out;
+ }
- if (size > 0) {
+ if (size) {
xattr_req = dict_new ();
- op_ret = dict_set (xattr_req, "glusterfs.content", data_from_uint64 (size));
+ op_ret = dict_set (xattr_req, "glusterfs.content",
+ data_from_uint64 (size));
if (op_ret < 0) {
gf_log ("libglusterfsclient",
GF_LOG_ERROR,
@@ -961,17 +960,16 @@ glusterfs_get (glusterfs_handle_t handle,
}
op_ret = libgf_client_lookup (ctx, &loc, stbuf, &dict, xattr_req);
-
- if (!op_ret && size && stbuf && stbuf->st_size && dict && buf) {
+ if (!op_ret && stbuf && (stbuf->st_size <= size) && dict && buf) {
data_t *mem_data = NULL;
void *mem = NULL;
-
+
mem_data = dict_get (dict, "glusterfs.content");
if (mem_data) {
mem = data_to_ptr (mem_data);
}
-
- if (mem && stbuf->st_size <= size) {
+
+ if (mem != NULL) {
memcpy (buf, mem, stbuf->st_size);
}
}
@@ -1160,7 +1158,7 @@ glusterfs_get_async (glusterfs_handle_t handle,
loc = CALLOC (1, sizeof (*loc));
loc->path = strdup (path);
- op_ret = libgf_client_path_lookup (loc, ctx);
+ op_ret = libgf_client_path_lookup (loc, ctx, 1);
if (op_ret == -1) {
gf_log ("libglusterfsclient",
GF_LOG_ERROR,
@@ -1189,9 +1187,6 @@ glusterfs_get_async (glusterfs_handle_t handle,
local->fop.lookup_cbk.loc = loc;
local->cbk_data = cbk_data;
- if (size < 0)
- size = 0;
-
if (size > 0) {
xattr_req = dict_new ();
op_ret = dict_set (xattr_req, "glusterfs.content", data_from_uint64 (size));
@@ -1306,7 +1301,7 @@ glusterfs_getxattr (glusterfs_handle_t handle,
}
loc.path = strdup (path);
- op_ret = libgf_client_path_lookup (&loc, ctx);
+ op_ret = libgf_client_path_lookup (&loc, ctx, 1);
if (op_ret == -1) {
gf_log ("libglusterfsclient",
GF_LOG_ERROR,
@@ -1546,7 +1541,7 @@ glusterfs_open (glusterfs_handle_t handle,
}
loc.path = strdup (path);
- op_ret = libgf_client_path_lookup (&loc, ctx);
+ op_ret = libgf_client_path_lookup (&loc, ctx, 1);
if (op_ret == -1) {
gf_log ("libglusterfsclient",
GF_LOG_ERROR,
@@ -1825,7 +1820,7 @@ glusterfs_setxattr (glusterfs_handle_t handle,
}
loc.path = strdup (path);
- op_ret = libgf_client_path_lookup (&loc, ctx);
+ op_ret = libgf_client_path_lookup (&loc, ctx, 1);
if (op_ret == -1) {
gf_log ("libglusterfsclient",
GF_LOG_ERROR,
@@ -3111,7 +3106,7 @@ glusterfs_stat (glusterfs_handle_t handle,
}
loc.path = strdup (path);
- op_ret = libgf_client_path_lookup (&loc, ctx);
+ op_ret = libgf_client_path_lookup (&loc, ctx, 1);
if (op_ret == -1) {
gf_log ("libglusterfsclient",
GF_LOG_ERROR,
@@ -3381,7 +3376,7 @@ glusterfs_mkdir (glusterfs_handle_t handle,
}
loc.path = strdup (path);
- op_ret = libgf_client_path_lookup (&loc, ctx);
+ op_ret = libgf_client_path_lookup (&loc, ctx, 1);
if (op_ret == -1) {
gf_log ("libglusterfsclient",
GF_LOG_ERROR,
@@ -3441,7 +3436,7 @@ glusterfs_rmdir (glusterfs_handle_t handle,
}
loc.path = strdup (path);
- op_ret = libgf_client_path_lookup (&loc, ctx);
+ op_ret = libgf_client_path_lookup (&loc, ctx, 1);
if (op_ret == -1) {
gf_log ("libglusterfsclient",
GF_LOG_ERROR,