From 1873d0bdb53af0311e8ad344116c0923448a6ff5 Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Thu, 16 Apr 2009 23:52:54 -0700 Subject: 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 --- libglusterfsclient/src/libglusterfsclient.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index d91b026a18c..fd1ce0fa518 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; -- cgit