diff options
author | Shehjar Tikoo <shehjart@zresearch.com> | 2009-04-16 23:52:54 -0700 |
---|---|---|
committer | Anand V. Avati <avati@amp.gluster.com> | 2009-04-17 13:42:38 +0530 |
commit | 1873d0bdb53af0311e8ad344116c0923448a6ff5 (patch) | |
tree | 30496cb9f05a8c77781233db5c617d44bad816cc | |
parent | 79215d4f2487e6db87e5fd637f0262037c1d230b (diff) |
libglusterfsclient: Check for directory on O_CREAT
If we have received an O_CREAT for a name where that basename is a
directory, and if we have successfully looked up the inode for this directory,
then we can check for S_ISDIR in libglusterfsclient and prevent sending a message
to the server through libgf_client_creat. See also the comment inline.
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
-rwxr-xr-x | libglusterfsclient/src/libglusterfsclient.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index d91b026a1..fd1ce0fa5 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -1536,9 +1536,19 @@ glusterfs_open (glusterfs_handle_t handle, fd = fd_create (loc.inode, 0); fd->flags = flags; - if ((flags & O_CREAT) == O_CREAT) + if ((flags & O_CREAT) == O_CREAT) { + /* If we have the st_mode for the basename, check if + * it is a directory here itself, rather than sending + * a network message through libgf_client_creat, and + * then receiving a EISDIR. + */ + if (S_ISDIR (loc.inode->st_mode)) { + errno = EISDIR; + op_ret = -1; + goto op_over; + } op_ret = libgf_client_creat (ctx, &loc, fd, flags, mode); - else { + } else { if (S_ISDIR (loc.inode->st_mode)) { if (((flags & O_RDONLY) == O_RDONLY) && ((flags & O_WRONLY) == 0) && @@ -1555,6 +1565,7 @@ glusterfs_open (glusterfs_handle_t handle, } } +op_over: if (op_ret == -1) { fd_unref (fd); fd = NULL; |