From d4ab91b1f254a21cac538fdffa7ff37db10ae83c Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Tue, 7 Apr 2009 05:35:32 -0700 Subject: 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 --- libglusterfsclient/src/libglusterfsclient.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libglusterfsclient/src') 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); -- cgit