summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@zresearch.com>2009-04-07 05:35:32 -0700
committerAnand V. Avati <avati@amp.gluster.com>2009-04-08 15:05:50 +0530
commitd4ab91b1f254a21cac538fdffa7ff37db10ae83c (patch)
tree4f5bb822e623b4dae9e7be7b36a144820711dd33
parente8282fd242ba4061a40b992ebe4549b4dd23fa11 (diff)
libglusterfsclient: Handle O_CREAT on lookup failure
On lookup failure, if O_CREAT is required, then we must: 1. explicitly lookup the parent directory. 2. create a new inode for the new file being opened. This special case is required for file creation because: 1. We cannot depend on the previous lookup to have reliably looked up the parent inode. 2. inode for the new file does not exist in the itable. Patch adapted from Raghu's original fix. Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index c44e67474de..99129fc250a 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -1543,6 +1543,21 @@ glusterfs_open (glusterfs_handle_t handle,
goto out;
}
+ if ((op_ret == -1) && ((flags & O_CREAT) == O_CREAT)) {
+ libgf_client_loc_wipe (&loc);
+ loc.path = strdup (path);
+
+ op_ret = libgf_client_path_lookup (&loc, ctx, 0);
+ if (op_ret == -1) {
+ gf_log ("libglusterfsclient", GF_LOG_ERROR,
+ "path lookup failed for (%s) while trying to"
+ " create (%s)", dirname ((char *)path), path);
+ goto out;
+ }
+
+ loc.inode = inode_new (ctx->itable);
+ }
+
pathname = strdup (path);
name = basename (pathname);