Commit 8db14ca1 authored by Steve French's avatar Steve French

[CIFS] Avoid open on possible directories since Samba now rejects them

Small change (mostly formatting) to limit lookup based open calls to
file create only.

After discussion yesteday on samba-technical about the posix lookup
regression,  and looking at a problem with cifs posix open to one
particular Samba version, Jeff and JRA realized that Samba server's
behavior changed in this area (posix open behavior on files vs.
directories).   To make this behavior consistent, JRA just made a
fix to Samba server to alter how it handles open of directories (now
returning the equivalent of EISDIR instead of success). Since we don't
know at lookup time whether the inode is a directory or file (and
thus whether posix open will succeed with most current Samba server),
this change avoids the posix open code on lookup open (just issues
posix open on creates).    This gets the semantic benefits we want
(atomicity, posix byte range locks, improved write semantics on newly
created files) and file create still is fast, and we avoid the problem
that Jeff noticed yesterday with "openat" (and some open directory
calls) of non-cached directories to one version of Samba server, and
will work with future Samba versions (which include the fix jra just
pushed into Samba server).  I confirmed this approach with jra
yesterday and with Shirish today.

Posix open is only called (at lookup time) for file create now.
For opens (rather than creates), because we do not know if it
is a file or directory yet, and current Samba no longer allows
us to do posix open on dirs, we could end up wasting an open call
on what turns out to be a dir. For file opens, we wait to call posix
open till cifs_open.  It could be added here (lookup) in the future
but the performance tradeoff of the extra network request when EISDIR
or EACCES is returned would have to be weighed against the 50%
reduction in network traffic in the other paths.
Reviewed-by: default avatarShirish Pargaonkar <shirishp@us.ibm.com>
Tested-by: default avatarJeff Layton <jlayton@redhat.com>
CC: Jeremy Allison <jra@samba.org>
Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
parent a15ae93f
...@@ -657,31 +657,36 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, ...@@ -657,31 +657,36 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
} }
cFYI(1, ("Full path: %s inode = 0x%p", full_path, direntry->d_inode)); cFYI(1, ("Full path: %s inode = 0x%p", full_path, direntry->d_inode));
/* Posix open is only called (at lookup time) for file create now.
* For opens (rather than creates), because we do not know if it
* is a file or directory yet, and current Samba no longer allows
* us to do posix open on dirs, we could end up wasting an open call
* on what turns out to be a dir. For file opens, we wait to call posix
* open till cifs_open. It could be added here (lookup) in the future
* but the performance tradeoff of the extra network request when EISDIR
* or EACCES is returned would have to be weighed against the 50%
* reduction in network traffic in the other paths.
*/
if (pTcon->unix_ext) { if (pTcon->unix_ext) {
if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY)) && if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY)) &&
(nd->flags & LOOKUP_OPEN) && !pTcon->broken_posix_open) { (nd->flags & LOOKUP_OPEN) && !pTcon->broken_posix_open &&
if (!((nd->intent.open.flags & O_CREAT) && (nd->intent.open.flags & O_CREAT)) {
(nd->intent.open.flags & O_EXCL))) { rc = cifs_posix_open(full_path, &newInode,
rc = cifs_posix_open(full_path, &newInode,
parent_dir_inode->i_sb, parent_dir_inode->i_sb,
nd->intent.open.create_mode, nd->intent.open.create_mode,
nd->intent.open.flags, &oplock, nd->intent.open.flags, &oplock,
&fileHandle, xid); &fileHandle, xid);
/* /*
* This code works around a bug in * The check below works around a bug in POSIX
* samba posix open in samba versions 3.3.1 * open in samba versions 3.3.1 and earlier where
* and earlier where create works * open could incorrectly fail with invalid parameter.
* but open fails with invalid parameter. * If either that or op not supported returned, follow
* If either of these error codes are * the normal lookup.
* returned, follow the normal lookup. */
* Otherwise, the error during posix open if ((rc == 0) || (rc == -ENOENT))
* is handled. posix_open = true;
*/ else if ((rc == -EINVAL) || (rc != -EOPNOTSUPP))
if ((rc != -EINVAL) && (rc != -EOPNOTSUPP)) pTcon->broken_posix_open = true;
posix_open = true;
else
pTcon->broken_posix_open = true;
}
} }
if (!posix_open) if (!posix_open)
rc = cifs_get_inode_info_unix(&newInode, full_path, rc = cifs_get_inode_info_unix(&newInode, full_path,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment