Add O_DENY* support for VFS and CIFS/NFS
Subsystems (7)
v4 cover Add O_DENY* support for VFS and CIFS/NFS
Main changes from the previous one:
1) O_DENYMAND is removed, sharelock mount option is introduced.
2) Patch fcntl.h and VFS patches are united into one.
3) flock/LOCK_MAND is disabled for sharelock mounts.
This patchset adds support of O_DENY* flags for Linux fs layer. These flags can be used by any application that needs share reservations to organize a file access. VFS already has some sort of this capability - now it's done through flock/LOCK_MAND mechanis, but that approach is non-atomic. This patchset build new capabilities on top of the existing one but doesn't bring any changes into the flock call semantic.
These flags can be used by NFS (built-in-kernel) and CIFS (Samba) servers and Wine applications through VFS (for local filesystems) or CIFS/NFS modules. This will help when e.g. Samba and NFS server share the same directory for Windows and Linux users or Wine applications use Samba/NFS share to access the same data from different clients.
According to the previous discussions the most problematic question is how to prevent situations like DoS attacks where e.g /lib/liba.so file can be open with DENYREAD, or smth like this. That's why extra mount option 'sharelock' is added for switching on/off O_DENY* flags processing. It allows us to avoid use of these flags on critical places (like /, /lib) and turn them on if we really want it proccessed that way.
So, we have 3 new flags:O_DENYREAD - to prevent other opens with read access,O_DENYWRITE - to prevent other opens with write access,O_DENYDELETE - to prevent delete operations (this flag is not implemented in VFS and NFS part and only suitable for CIFS module),
The patchset avoid data races problem on newely created files: open with O_CREAT can return the -ETXTBSY error for a successfully created file if this files was locked with a deny lock by another task. Also, it turns flock/LOCK_MAND capability off for mounts with 'sharelock' option. This let us not mix one share reservation approach with another.
The #1 patch adds flags to fcntl and implements VFS part. The patches #3, #4, #5 are related to CIFS-specific changes, #6 and #7 describe NFS and NFSD parts.
The preliminary patch for Samba that replaces the existing use of flock/LOCK_MAND mechanism with O_DENY* flags:
http://git.etersoft.ru/people/piastry/packages/?p=samba.git;a=commitdiff;h=173070262b7f29134ad6b2e49a760017c11aec4a
The future part of open man page patch:
-----O_DENYREAD, O_DENYWRIYE, O_DENYDELETE - used to inforce a mandatory share reservation scheme of the file access. If these flag is passed, the open fails with -EBUSY in following cases:
1) if O_DENYREAD flag is specified and there is another open with O_DENYMAND flag and READ access to the file;
2) if O_DENYWRITE flag is specified and there is another open with O_DENYMAND flag and WRITE access to the file;
3) if READ access is requested and there is another open with O_DENYMAND and O_DENYREAD flags;
4) if WRITE access is requested and there is another open with O_DENYMAND and O_DENYWRITE flags.
If O_DENYDELETE flag is specified and the open succeded, any further unlink operation will fail with -EBUSY untill this open is closed. Now this flag is processed by CIFS filesystems only.
This mechanism is done through flocks. If O_DENY* flags are specified, flock syscall is processed after the open. The share modes are translated into flock according the following rules:
1) !O_DENYREAD -> LOCK_READ | LOCK_MAND
2) !O_DENYWRITE -> LOCK_WRITE | LOCK_MAND
-----
Pavel Shilovsky (7):
fcntl: Introduce new O_DENY* open flags
CIFS: Add share_access parm to open request
CIFS: Add O_DENY* open flags support
CIFS: Use NT_CREATE_ANDX command for forcemand mounts
NFSv4: Add O_DENY* open flags support
NFSD: Pass share reservations flags to VFS
locks: Disable LOCK_MAND support for MS_SHARELOCK mounts
fs/cifs/cifsacl.c | 8 +-- fs/cifs/cifsglob.h | 18 ++++++- fs/cifs/cifsproto.h | 8 +-- fs/cifs/cifssmb.c | 50 +++++++++--------- fs/cifs/dir.c | 16 +++--- fs/cifs/file.c | 20 +++++--- fs/cifs/inode.c | 16 +++--- fs/cifs/link.c | 25 +++------ fs/cifs/readdir.c | 5 +- fs/cifs/smb1ops.c | 16 +++--- fs/cifs/smb2file.c | 10 ++-- fs/cifs/smb2inode.c | 4 +- fs/cifs/smb2ops.c | 10 ++-- fs/cifs/smb2pdu.c | 6 +-- fs/cifs/smb2proto.h | 14 ++--- fs/fcntl.c | 5 +- fs/locks.c | 108 ++++++++++++++++++++++++++++++++++++--- fs/namei.c | 45 ++++++++++++++-- fs/nfs/internal.h | 3 +- fs/nfs/nfs4proc.c | 2 + fs/nfs/nfs4xdr.c | 21 ++++++-- fs/nfs/super.c | 3 +- fs/nfsd/nfs4state.c | 46 ++++++++++++++++- fs/proc_namespace.c | 1 + include/linux/fs.h | 7 +++ include/uapi/asm-generic/fcntl.h | 11 ++++ include/uapi/linux/fs.h | 1 + 27 files changed, 355 insertions(+), 124 deletions(-)
Signature · 1 line
1.8.1.5
PATCH v4 1/7 fcntl: Introduce new O_DENY* open flags
This patch adds 3 flags:
1) O_DENYREAD that doesn't permit read access,
2) O_DENYWRITE that doesn't permit write access,
3) O_DENYDELETE that doesn't permit delete or rename,
Network filesystems CIFS, SMB2.0, SMB3.0 and NFSv4 have such flags - this change can benefit cifs and nfs modules as well as Samba and NFS file servers that export the same directory for Windows clients, or Wine applications that access the same files simultaneously.
These flags are only take affect for opens on mounts with 'sharelock' mount option. They are translated to flock's flags:
!O_DENYREAD -> LOCK_READ | LOCK_MAND
!O_DENYWRITE -> LOCK_WRITE | LOCK_MAND
and set through flock_lock_file on a file. If the file can't be locked due conflicts with another open with O_DENY* flags, the -EBUSY error code is returned.
Create codepath is slightly changed to prevent data races on newely created files: when open with O_CREAT can return with -EBUSY error for successfully created files due to a deny lock set by another task.
--- fs/fcntl.c | 5 ++- fs/locks.c | 93 +++++++++++++++++++++++++++++++++++++--- fs/namei.c | 45 +++++++++++++++++-- fs/proc_namespace.c | 1 + include/linux/fs.h | 7 +++ include/uapi/asm-generic/fcntl.h | 11 +++++ include/uapi/linux/fs.h | 1 + 7 files changed, 150 insertions(+), 13 deletions(-)
fs/fcntl.c +3 -2
@@ -730,14 +730,15 @@ static int __init fcntl_init(void)* Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY * is defined as O_NONBLOCK on some platforms and not on others. */ -BUILD_BUG_ON (19 -1 /* for O_RDONLY being 0 */ !=HWEIGHT32 ( +BUILD_BUG_ON (22 -1 /* for O_RDONLY being 0 */ !=HWEIGHT32 (O_RDONLY |O_WRONLY |O_RDWR |O_CREAT |O_EXCL |O_NOCTTY |O_TRUNC |O_APPEND |/* O_NONBLOCK | */ __O_SYNC |O_DSYNC |FASYNC |O_DIRECT |O_LARGEFILE |O_DIRECTORY |O_NOFOLLOW |O_NOATIME |O_CLOEXEC | - __FMODE_EXEC |O_PATH + __FMODE_EXEC |O_PATH |O_DENYREAD | +O_DENYWRITE |O_DENYDELETE )); fasync_cache = kmem_cache_create("fasync_cache",
fs/locks.c +86 -7
112 lines not on this page · raw message
fs/namei.c +41 -4
80 lines not on this page · raw message
fs/proc_namespace.c +1 -0
@@ -44,6 +44,7 @@ static int show_sb_opts(struct seq_file *m, struct super_block *sb) { MS_SYNCHRONOUS, ",sync" }, { MS_DIRSYNC, ",dirsync" }, { MS_MANDLOCK, ",mand" }, + { MS_SHARELOCK, ",sharelock" }, { 0, NULL } };const struct proc_fs_info *fs_infop;
include/linux/fs.h +7 -0
@@ -1005,6 +1005,7 @@ extern int lease_modify(struct file_lock **, int);extern int lock_may_read (struct inode *,loff_t start,unsigned long count);extern int lock_may_write (struct inode *,loff_t start,unsigned long count);extern void locks_delete_block (struct file_lock *waiter); +extern int deny_lock_file (struct file *);extern void lock_flocks (void );extern void unlock_flocks (void );#else /* !CONFIG_FILE_LOCKING */
@@ -1153,6 +1154,11 @@ static inline void locks_delete_block(struct file_lock *waiter) { } +static inline int deny_lock_file (struct file *filp) +{ +return 0 ; +} +static inline void lock_flocks (void ) { }
@@ -1668,6 +1674,7 @@ struct super_operations {#define IS_PRIVATE (inode) ((inode)->i_flags & S_PRIVATE)#define IS_IMA (inode) ((inode)->i_flags & S_IMA)#define IS_AUTOMOUNT (inode) ((inode)->i_flags & S_AUTOMOUNT) +#define IS_SHARELOCK (inode) __IS_FLG(inode, MS_SHARELOCK)#define IS_NOSEC (inode) ((inode)->i_flags & S_NOSEC)/*
include/uapi/asm-generic/fcntl.h +11 -0
@@ -84,6 +84,17 @@#define O_PATH 010000000#endif +#ifndef O_DENYREAD +#define O_DENYREAD 020000000/* Do not permit read access */ +#endif +#ifndef O_DENYWRITE +#define O_DENYWRITE 040000000/* Do not permit write access */ +#endif +/* FMODE_NONOTIFY 0100000000 */ +#ifndef O_DENYDELETE +#define O_DENYDELETE 0200000000/* Do not permit delete or rename */ +#endif +#ifndef O_NDELAY #define O_NDELAY O_NONBLOCK#endif
include/uapi/linux/fs.h +1 -0
@@ -86,6 +86,7 @@ struct inodes_stat_t {#define MS_KERNMOUNT (1<<22)/* this is a kern_mount call */ #define MS_I_VERSION (1<<23)/* Update inode I_version field */ #define MS_STRICTATIME (1<<24)/* Always perform atime updates */ +#define MS_SHARELOCK (1<<25)/* Allow share locks on an FS */ #define MS_NOSEC (1<<28)#define MS_BORN (1<<29)#define MS_ACTIVE (1<<30)
Signature · 1 line
1.8.1.5
PATCH v4 2/7 CIFS: Add share_access parm to open request
In reply to Pavel Shilovskyand simplify CIFSSMBOpen params.
--- fs/cifs/cifsacl.c | 8 ++++---- fs/cifs/cifsglob.h | 2 +- fs/cifs/cifsproto.h | 8 ++++---- fs/cifs/cifssmb.c | 50 +++++++++++++++++++++++++++----------------------- fs/cifs/dir.c | 12 ++++++------ fs/cifs/file.c | 10 ++++++---- fs/cifs/inode.c | 16 ++++++---------- fs/cifs/link.c | 25 ++++++++----------------- fs/cifs/readdir.c | 5 ++--- fs/cifs/smb1ops.c | 16 +++++++--------- fs/cifs/smb2file.c | 10 +++++----- fs/cifs/smb2inode.c | 4 ++-- fs/cifs/smb2ops.c | 10 ++++++---- fs/cifs/smb2pdu.c | 6 +++--- fs/cifs/smb2proto.h | 14 ++++++++------ 15 files changed, 95 insertions(+), 101 deletions(-)
fs/cifs/cifsacl.c +4 -4
@@ -891,8 +891,8 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, create_options |=CREATE_OPEN_BACKUP_INTENT ; rc =CIFSSMBOpen (xid, tcon, path,FILE_OPEN ,READ_CONTROL , - create_options, &fid, &oplock,NULL , cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +FILE_SHARE_ALL , create_options, &fid, &oplock, +NULL , cifs_sb);if (!rc) { rc =CIFSSMBGetCIFSACL (xid, tcon, fid, &pntsd, pacllen);CIFSSMBClose (xid, tcon, fid);
@@ -952,8 +952,8 @@ int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen, access_flags =WRITE_DAC ; rc =CIFSSMBOpen (xid, tcon, path,FILE_OPEN , access_flags, - create_options, &fid, &oplock,NULL , cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +FILE_SHARE_ALL , create_options, &fid, &oplock, +NULL , cifs_sb);if (rc) {cERROR (1 ,"Unable to open file to set ACL" ); goto out;
fs/cifs/cifsglob.h +1 -1
@@ -310,7 +310,7 @@ struct smb_version_operations { struct cifs_sb_info *);/* open a file for non-posix mounts */ int (*open)(const unsigned int ,struct cifs_tcon *,const char *,int , -int ,int ,struct cifs_fid *,__u32 *,FILE_ALL_INFO *, +int ,int ,int ,struct cifs_fid *,__u32 *,FILE_ALL_INFO *,struct cifs_sb_info *);/* set fid protocol-specific info */ void (*set_fid)(struct cifsFileInfo *,struct cifs_fid *,__u32 );
fs/cifs/cifsproto.h +4 -4
@@ -361,10 +361,10 @@ extern int CIFSSMBQueryReparseLinkInfo(const unsigned int xid, const struct nls_table *nls_codepage);#endif /* temporarily unused until cifs_symlink fixed */ extern int CIFSSMBOpen (const unsigned int xid,struct cifs_tcon *tcon, -const char *fileName,const int disposition, -const int access_flags,const int omode, -__u16 *netfid,int *pOplock,FILE_ALL_INFO *, -const struct nls_table *nls_codepage,int remap); +const char *file_name,const int disposition, +const int desired_access,const int share_access, +const int omode,__u16 *netfid,int *oplock, +FILE_ALL_INFO *,struct cifs_sb_info *); extern int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, const char *fileName, const int disposition, const int access_flags, const int omode,
fs/cifs/cifssmb.c +27 -23
97 lines not on this page · raw message
fs/cifs/dir.c +6 -6
@@ -203,6 +203,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,FILE_ALL_INFO *buf =NULL ;struct inode *newinode =NULL ;int disposition; +int share_access =FILE_SHARE_ALL ;struct TCP_Server_Info *server = tcon->ses->server; *oplock =0 ;
@@ -320,8 +321,8 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, create_options |=CREATE_OPEN_BACKUP_INTENT ; rc = server->ops->open (xid, tcon, full_path, disposition, - desired_access, create_options, fid, oplock, - buf, cifs_sb); + desired_access, share_access, create_options, + fid, oplock, buf, cifs_sb);if (rc) {cFYI (1 ,"cifs_create returned 0x%x" , rc); goto out;
@@ -626,10 +627,9 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,if (backup_cred (cifs_sb)) create_options |=CREATE_OPEN_BACKUP_INTENT ; - rc =CIFSSMBOpen (xid, pTcon, full_path,FILE_CREATE , -GENERIC_WRITE , create_options, - &fileHandle, &oplock, buf, cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); + rc =CIFSSMBOpen (xid, pTcon, full_path,FILE_CREATE ,GENERIC_WRITE , +FILE_SHARE_ALL , create_options, &fileHandle, &oplock, + buf, cifs_sb);if (rc) goto mknod_out;
fs/cifs/file.c +6 -4
@@ -174,6 +174,7 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, {int rc;int desired_access; +int share_access =FILE_SHARE_ALL ;int disposition;int create_options =CREATE_NOT_DIR ;FILE_ALL_INFO *buf;
@@ -220,8 +221,8 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, create_options |=CREATE_OPEN_BACKUP_INTENT ; rc = server->ops->open (xid, tcon, full_path, disposition, - desired_access, create_options, fid, oplock, buf, - cifs_sb); + desired_access, share_access, create_options, + fid, oplock, buf, cifs_sb);if (rc) goto out;
@@ -579,6 +580,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)struct inode *inode;char *full_path =NULL ;int desired_access; +int share_access =FILE_SHARE_ALL ;int disposition =FILE_OPEN ;int create_options =CREATE_NOT_DIR ;struct cifs_fid fid;
@@ -658,8 +660,8 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)* not dirty locally we could do this. */ rc = server->ops->open (xid, tcon, full_path, disposition, - desired_access, create_options, &fid, &oplock, -NULL , cifs_sb); + desired_access, share_access, create_options, + &fid, &oplock,NULL , cifs_sb);if (rc) {mutex_unlock (&cfile->fh_mutex);cFYI (1 ,"cifs_reopen returned 0x%x" , rc);
fs/cifs/inode.c +6 -10
@@ -396,10 +396,8 @@ cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path, tcon =tlink_tcon (tlink); rc =CIFSSMBOpen (xid, tcon, path,FILE_OPEN ,GENERIC_READ , -CREATE_NOT_DIR , &netfid, &oplock,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); +FILE_SHARE_ALL ,CREATE_NOT_DIR , &netfid, &oplock, +NULL , cifs_sb);if (rc ==0 ) {int buf_type =CIFS_NO_BUFFER ;/* Read header */
@@ -987,9 +985,8 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry, tcon =tlink_tcon (tlink); rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN , -DELETE |FILE_WRITE_ATTRIBUTES ,CREATE_NOT_DIR , - &netfid, &oplock,NULL , cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +DELETE |FILE_WRITE_ATTRIBUTES ,FILE_SHARE_ALL , +CREATE_NOT_DIR , &netfid, &oplock,NULL , cifs_sb);if (rc !=0 ) goto out;
@@ -1509,9 +1506,8 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry,/* open the file to be renamed -- we need DELETE perms */ rc =CIFSSMBOpen (xid, tcon, from_path,FILE_OPEN ,DELETE , -CREATE_NOT_DIR , &srcfid, &oplock,NULL , - cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); +FILE_SHARE_ALL ,CREATE_NOT_DIR , &srcfid, &oplock,NULL , + cifs_sb);if (rc ==0 ) { rc = CIFSSMBRenameOpenFile(xid, tcon, srcfid, (const char *) to_dentry->d_name.name,
fs/cifs/link.c +8 -17
@@ -187,16 +187,11 @@ CIFSCreateMFSymLink(const unsigned int xid, struct cifs_tcon *tcon, {int rc;int oplock =0 ; -int remap;int create_options =CREATE_NOT_DIR ;__u16 netfid =0 ;u8 *buf;unsigned int bytes_written =0 ;struct cifs_io_parms io_parms; -struct nls_table *nls_codepage; - - nls_codepage = cifs_sb->local_nls; - remap = cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ; buf =kmalloc (CIFS_MF_SYMLINK_FILE_SIZE ,GFP_KERNEL );if (!buf)
@@ -212,8 +207,8 @@ CIFSCreateMFSymLink(const unsigned int xid, struct cifs_tcon *tcon, create_options |=CREATE_OPEN_BACKUP_INTENT ; rc =CIFSSMBOpen (xid, tcon, fromName,FILE_CREATE ,GENERIC_WRITE , - create_options, &netfid, &oplock,NULL , - nls_codepage, remap); +FILE_SHARE_ALL , create_options, &netfid, &oplock,NULL , + cifs_sb);if (rc !=0 ) {kfree (buf);return rc;
@@ -240,7 +235,7 @@ CIFSCreateMFSymLink(const unsigned int xid, struct cifs_tcon *tcon,static int CIFSQueryMFSymLink (const unsigned int xid,struct cifs_tcon *tcon,const unsigned char *searchName,char **symlinkinfo, -const struct nls_table *nls_codepage,int remap) +struct cifs_sb_info *cifs_sb) {int rc;int oplock =0 ;
@@ -254,8 +249,8 @@ CIFSQueryMFSymLink(const unsigned int xid, struct cifs_tcon *tcon,FILE_ALL_INFO file_info; rc =CIFSSMBOpen (xid, tcon, searchName,FILE_OPEN ,GENERIC_READ , -CREATE_NOT_DIR , &netfid, &oplock, &file_info, - nls_codepage, remap); +FILE_SHARE_ALL ,CREATE_NOT_DIR , &netfid, &oplock, + &file_info, cifs_sb);if (rc !=0 )return rc;
@@ -332,10 +327,8 @@ CIFSCheckMFSymlink(struct cifs_fattr *fattr, pTcon =tlink_tcon (tlink); rc =CIFSSMBOpen (xid, pTcon, path,FILE_OPEN ,GENERIC_READ , -CREATE_NOT_DIR , &netfid, &oplock, &file_info, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); +FILE_SHARE_ALL ,CREATE_NOT_DIR , &netfid, &oplock, + &file_info, cifs_sb);if (rc !=0 ) goto out;
@@ -530,9 +523,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)*/ if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MF_SYMLINKS ) rc =CIFSQueryMFSymLink (xid, tcon, full_path, &target_path, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); + cifs_sb);if ((rc !=0 ) &&cap_unix (tcon->ses)) rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, &target_path,
fs/cifs/readdir.c +2 -3
@@ -224,9 +224,8 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb,char *tmpbuffer; rc =CIFSSMBOpen (xid, ptcon, full_path,FILE_OPEN ,GENERIC_READ , -OPEN_REPARSE_POINT , &fid, &oplock,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +FILE_SHARE_ALL ,OPEN_REPARSE_POINT , &fid, &oplock,NULL , + cifs_sb);if (!rc) { tmpbuffer =kmalloc (maxpath); rc = CIFSSMBQueryReparseLinkInfo(xid, ptcon, full_path,
fs/cifs/smb1ops.c +7 -9
@@ -671,9 +671,9 @@ cifs_mkdir_setinfo(struct inode *inode, const char *full_path,static int cifs_open_file (const unsigned int xid,struct cifs_tcon *tcon,const char *path, -int disposition,int desired_access,int create_options, -struct cifs_fid *fid,__u32 *oplock,FILE_ALL_INFO *buf, -struct cifs_sb_info *cifs_sb) +int disposition,int desired_access,int share_access, +int create_options,struct cifs_fid *fid,__u32 *oplock, +FILE_ALL_INFO *buf,struct cifs_sb_info *cifs_sb) {if (!(tcon->ses->capabilities &CAP_NT_SMBS )) return SMBLegacyOpen(xid, tcon, path, disposition,
@@ -682,9 +682,8 @@ cifs_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);return CIFSSMBOpen (xid, tcon, path, disposition, desired_access, - create_options, &fid->netfid, oplock, buf, - cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); + share_access, create_options, &fid->netfid, oplock, + buf, cifs_sb); } static void
@@ -779,9 +778,8 @@ smb_set_file_info(struct inode *inode, const char *full_path,cFYI (1 ,"calling SetFileInfo since SetPathInfo for times not supported " "by this server" ); rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN , -SYNCHRONIZE |FILE_WRITE_ATTRIBUTES ,CREATE_NOT_DIR , - &netfid, &oplock,NULL , cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +SYNCHRONIZE |FILE_WRITE_ATTRIBUTES ,FILE_SHARE_ALL , +CREATE_NOT_DIR , &netfid, &oplock,NULL , cifs_sb);if (rc !=0 ) {if (rc == -EIO )
fs/cifs/smb2file.c +5 -5
@@ -58,9 +58,9 @@ smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock)int smb2_open_file (const unsigned int xid,struct cifs_tcon *tcon,const char *path, -int disposition,int desired_access,int create_options, -struct cifs_fid *fid,__u32 *oplock,FILE_ALL_INFO *buf, -struct cifs_sb_info *cifs_sb) +int disposition,int desired_access,int share_access, +int create_options,struct cifs_fid *fid,__u32 *oplock, +FILE_ALL_INFO *buf,struct cifs_sb_info *cifs_sb) {int rc;__le16 *smb2_path;
@@ -87,8 +87,8 @@ smb2_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path,memcpy (smb2_oplock +1 , fid->lease_key,SMB2_LEASE_KEY_SIZE ); rc =SMB2_open (xid, tcon, smb2_path, &fid->persistent_fid, - &fid->volatile_fid, desired_access, disposition, -0 ,0 , smb2_oplock, smb2_data); + &fid->volatile_fid, desired_access, share_access, + disposition,0 ,0 , smb2_oplock, smb2_data);if (rc) goto out;
fs/cifs/smb2inode.c +2 -2
@@ -54,8 +54,8 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ; rc =SMB2_open (xid, tcon, utf16_path, &persistent_fid, &volatile_fid, - desired_access, create_disposition, file_attributes, - create_options, &oplock,NULL ); + desired_access,FILE_SHARE_ALL , create_disposition, + file_attributes, create_options, &oplock,NULL );if (rc) {kfree (utf16_path);return rc;
fs/cifs/smb2ops.c +6 -4
@@ -222,7 +222,8 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ; rc =SMB2_open (xid, tcon, utf16_path, &persistent_fid, &volatile_fid, -FILE_READ_ATTRIBUTES ,FILE_OPEN ,0 ,0 , &oplock,NULL ); +FILE_READ_ATTRIBUTES ,FILE_SHARE_ALL ,FILE_OPEN ,0 ,0 , + &oplock,NULL );if (rc) {kfree (utf16_path);return rc;
@@ -432,8 +433,8 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ; rc =SMB2_open (xid, tcon, utf16_path, &persistent_fid, &volatile_fid, -FILE_READ_ATTRIBUTES |FILE_READ_DATA ,FILE_OPEN ,0 ,0 , - &oplock,NULL ); +FILE_READ_ATTRIBUTES |FILE_READ_DATA ,FILE_SHARE_ALL , +FILE_OPEN ,0 ,0 , &oplock,NULL );kfree (utf16_path);if (rc) {cERROR (1 ,"open dir failed" );
@@ -515,7 +516,8 @@ smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,u8 oplock =SMB2_OPLOCK_LEVEL_NONE ; rc =SMB2_open (xid, tcon, &srch_path, &persistent_fid, &volatile_fid, -FILE_READ_ATTRIBUTES ,FILE_OPEN ,0 ,0 , &oplock,NULL ); +FILE_READ_ATTRIBUTES ,FILE_SHARE_ALL ,FILE_OPEN ,0 ,0 , + &oplock,NULL );if (rc)return rc; buf->f_type =SMB2_MAGIC_NUMBER ;
fs/cifs/smb2pdu.c +3 -3
@@ -910,8 +910,8 @@ parse_lease_state(struct smb2_create_rsp *rsp)int SMB2_open (const unsigned int xid,struct cifs_tcon *tcon,__le16 *path,u64 *persistent_fid,u64 *volatile_fid,__u32 desired_access, -__u32 create_disposition,__u32 file_attributes,__u32 create_options, -__u8 *oplock,struct smb2_file_all_info *buf) +__u32 share_access,__u32 create_disposition,__u32 file_attributes, +__u32 create_options,__u8 *oplock,struct smb2_file_all_info *buf) {struct smb2_create_req *req;struct smb2_create_rsp *rsp;
@@ -940,7 +940,7 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, req->DesiredAccess =cpu_to_le32 (desired_access);/* File attributes ignored on open (used in create though) */ req->FileAttributes =cpu_to_le32 (file_attributes); - req->ShareAccess =FILE_SHARE_ALL_LE ; + req->ShareAccess =cpu_to_le32 (share_access); req->CreateDisposition =cpu_to_le32 (create_disposition); req->CreateOptions =cpu_to_le32 (create_options); uni_path_len = (2 *UniStrnlen ((wchar_t *)path,PATH_MAX )) +2 ;
fs/cifs/smb2proto.h +8 -6
@@ -86,9 +86,10 @@ extern int smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon,extern int smb2_open_file (const unsigned int xid,struct cifs_tcon *tcon,const char *full_path,int disposition, -int desired_access,int create_options, -struct cifs_fid *fid,__u32 *oplock, -FILE_ALL_INFO *buf,struct cifs_sb_info *cifs_sb); +int desired_access,int share_access, +int create_options,struct cifs_fid *fid, +__u32 *oplock,FILE_ALL_INFO *buf, +struct cifs_sb_info *cifs_sb);extern void smb2_set_oplock_level (struct cifsInodeInfo *cinode,__u32 oplock);extern int smb2_unlock_range (struct cifsFileInfo *cfile,struct file_lock *flock,const unsigned int xid);
@@ -108,9 +109,10 @@ extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses,extern int SMB2_tdis (const unsigned int xid,struct cifs_tcon *tcon);extern int SMB2_open (const unsigned int xid,struct cifs_tcon *tcon,__le16 *path,u64 *persistent_fid,u64 *volatile_fid, -__u32 desired_access,__u32 create_disposition, -__u32 file_attributes,__u32 create_options, -__u8 *oplock,struct smb2_file_all_info *buf); +__u32 desired_access,__u32 share_access, +__u32 create_disposition,__u32 file_attributes, +__u32 create_options,__u8 *oplock, +struct smb2_file_all_info *buf);extern int SMB2_close (const unsigned int xid,struct cifs_tcon *tcon,u64 persistent_file_id,u64 volatile_file_id); extern int SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon,
Signature · 1 line
1.8.1.5
PATCH v4 3/7 CIFS: Add O_DENY* open flags support
In reply to Pavel ShilovskyConstruct share_access value from O_DENY* flags and send it to the server.
--- fs/cifs/cifsglob.h | 16 +++++++++++++++- fs/cifs/dir.c | 3 +++ fs/cifs/file.c | 4 ++++ fs/locks.c | 8 ++++++++ 4 files changed, 30 insertions(+), 1 deletion(-)
fs/cifs/cifsglob.h +15 -1
@@ -465,7 +465,7 @@ struct smb_vol { CIFS_MOUNT_CIFS_BACKUPUID | CIFS_MOUNT_CIFS_BACKUPGID)#define CIFS_MS_MASK (MS_RDONLY | MS_MANDLOCK | MS_NOEXEC | MS_NOSUID | \ - MS_NODEV | MS_SYNCHRONOUS) + MS_NODEV | MS_SYNCHRONOUS | MS_SHARELOCK)struct cifs_mnt_data {struct cifs_sb_info *cifs_sb;
@@ -947,6 +947,20 @@ struct cifsFileInfo {struct work_struct oplock_break;/* work for oplock breaks */ }; +static inline int +cifs_get_share_flags (unsigned int flags) +{ +int share_access =0 ; + +if (!(flags &O_DENYREAD )) + share_access |=FILE_SHARE_READ ; +if (!(flags &O_DENYWRITE )) + share_access |=FILE_SHARE_WRITE ; +if (!(flags &O_DENYDELETE )) + share_access |=FILE_SHARE_DELETE ; +return share_access; +} +struct cifs_io_parms {__u16 netfid;#ifdef CONFIG_CIFS_SMB2
fs/cifs/dir.c +3 -0
@@ -294,6 +294,9 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,else cFYI (1 ,"Create flag not set in create function" ); +if (IS_SHARELOCK (inode)) + share_access =cifs_get_share_flags (oflags); +/* * BB add processing to set equivalent of mode - e.g. via CreateX with * ACLs
fs/cifs/file.c +4 -0
@@ -210,6 +210,8 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,*********************************************************************/ disposition =cifs_get_disposition (f_flags); +if (IS_SHARELOCK (inode)) + share_access =cifs_get_share_flags (f_flags);/* BB pass O_SYNC flag through on file attributes .. BB */
@@ -645,6 +647,8 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) } desired_access =cifs_convert_flags (cfile->f_flags); +if (IS_SHARELOCK (inode)) + share_access =cifs_get_share_flags (cfile->f_flags);if (backup_cred (cifs_sb)) create_options |=CREATE_OPEN_BACKUP_INTENT ;
fs/locks.c +8 -0
@@ -846,10 +846,18 @@ deny_lock_file(struct file *filp) {struct file_lock *lock;int error =0 ; +const char *fsname = filp->f_path.dentry->d_inode->i_sb->s_type->name;if (!IS_SHARELOCK (filp->f_path.dentry->d_inode))return error; +/* +* Don't set a lock on CIFS file systems because they can process it +* themselves. +*/ +if (!strncmp (fsname,"cifs" ,4 )) +return error; + error =flock_make_lock (filp, &lock,deny_flags_to_cmd (filp->f_flags));if (error)return error;
Signature · 1 line
1.8.1.5
Jeff Layton
NAKRe: [PATCH v4 3/7] CIFS: Add O_DENY* open flags support
Quoted 91 lines · On Fri, 5 Apr 2013 20:57:51 +0400 Pavel Shilovsky…
Construct
share_accessvalue from O_DENY* flags and send it to the server.Signed-off-by Pavel Shilovsky <[email protected]>--- fs/cifs/cifsglob.h | 16 +++++++++++++++- fs/cifs/dir.c | 3 +++ fs/cifs/file.c | 4 ++++ fs/locks.c | 8 ++++++++ 4 files changed, 30 insertions(+), 1 deletion(-)fs/cifs/cifsglob.h +15
-1@@ -465,7 +465,7 @@ struct smb_vol { CIFS_MOUNT_CIFS_BACKUPUID | CIFS_MOUNT_CIFS_BACKUPGID)#define CIFS_MS_MASK (MS_RDONLY | MS_MANDLOCK | MS_NOEXEC | MS_NOSUID | \ - MS_NODEV | MS_SYNCHRONOUS) + MS_NODEV | MS_SYNCHRONOUS | MS_SHARELOCK)struct cifs_mnt_data {struct cifs_sb_info *cifs_sb;@@ -947,6 +947,20 @@ struct cifsFileInfo {struct work_struct oplock_break;/* work for oplock breaks */ }; +static inline int +cifs_get_share_flags (unsigned int flags) +{ +int share_access =0 ; + +if (!(flags &O_DENYREAD )) + share_access |=FILE_SHARE_READ ; +if (!(flags &O_DENYWRITE )) + share_access |=FILE_SHARE_WRITE ; +if (!(flags &O_DENYDELETE )) + share_access |=FILE_SHARE_DELETE ; +return share_access; +} +struct cifs_io_parms {__u16 netfid;#ifdef CONFIG_CIFS_SMB2 fs/cifs/dir.c +3
-0@@ -294,6 +294,9 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,else cFYI (1 ,"Create flag not set in create function" ); +if (IS_SHARELOCK (inode)) + share_access =cifs_get_share_flags (oflags); +/* * BB add processing to set equivalent of mode - e.g. via CreateX with * ACLs fs/cifs/file.c +4
-0@@ -210,6 +210,8 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,*********************************************************************/ disposition =cifs_get_disposition (f_flags); +if (IS_SHARELOCK (inode)) + share_access =cifs_get_share_flags (f_flags);/* BB pass O_SYNC flag through on file attributes .. BB */ @@ -645,6 +647,8 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) } desired_access =cifs_convert_flags (cfile->f_flags); +if (IS_SHARELOCK (inode)) + share_access =cifs_get_share_flags (cfile->f_flags);if (backup_cred (cifs_sb)) create_options |=CREATE_OPEN_BACKUP_INTENT ;fs/locks.c +1
-0@@ -846,10 +846,18 @@ deny_lock_file(struct file *filp) {struct file_lock *lock;int error =0 ; +const char *fsname = filp->f_path.dentry->d_inode->i_sb->s_type->name;
fs/locks.c deny_lock_file(struct file *filp) · line 860
Quoted 10 lines
fs/locks.c +7
-0if (!IS_SHARELOCK (filp->f_path.dentry->d_inode))return error; +/* +* Don't set a lock on CIFS file systems because they can process it +* themselves. +*/ +if (!strncmp (fsname,"cifs" ,4 )) +return error; +
NAK....
This is really nasty. Instead of doing this, you should instead create a new file_system_type->fs_flags value. Then, set that flag for cifs and nfs4, and test it here.
Quoted 3 lines
fs/locks.c +0
-0error =flock_make_lock (filp, &lock,deny_flags_to_cmd (filp->f_flags));if (error)return error;
Signature · 5 lines
Jeff Layton <[email protected]> -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 3/7] CIFS: Add O_DENY* open flags support
2013/4/8 Jeff Layton <[email protected]>:
Quoted 107 lines
Quoted 91 lines · On Fri, 5 Apr 2013 20:57:51 +0400 Pavel Shilovsky <[email protected]> wrote:
Construct
share_accessvalue from O_DENY* flags and send it to the server.Signed-off-by Pavel Shilovsky <[email protected]>--- fs/cifs/cifsglob.h | 16 +++++++++++++++- fs/cifs/dir.c | 3 +++ fs/cifs/file.c | 4 ++++ fs/locks.c | 8 ++++++++ 4 files changed, 30 insertions(+), 1 deletion(-)fs/cifs/cifsglob.h +15
-1@@ -465,7 +465,7 @@ struct smb_vol { CIFS_MOUNT_CIFS_BACKUPUID | CIFS_MOUNT_CIFS_BACKUPGID)#define CIFS_MS_MASK (MS_RDONLY | MS_MANDLOCK | MS_NOEXEC | MS_NOSUID | \ - MS_NODEV | MS_SYNCHRONOUS) + MS_NODEV | MS_SYNCHRONOUS | MS_SHARELOCK)struct cifs_mnt_data {struct cifs_sb_info *cifs_sb;@@ -947,6 +947,20 @@ struct cifsFileInfo {struct work_struct oplock_break;/* work for oplock breaks */ }; +static inline int +cifs_get_share_flags (unsigned int flags) +{ +int share_access =0 ; + +if (!(flags &O_DENYREAD )) + share_access |=FILE_SHARE_READ ; +if (!(flags &O_DENYWRITE )) + share_access |=FILE_SHARE_WRITE ; +if (!(flags &O_DENYDELETE )) + share_access |=FILE_SHARE_DELETE ; +return share_access; +} +struct cifs_io_parms {__u16 netfid;#ifdef CONFIG_CIFS_SMB2 fs/cifs/dir.c +3
-0@@ -294,6 +294,9 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,else cFYI (1 ,"Create flag not set in create function" ); +if (IS_SHARELOCK (inode)) + share_access =cifs_get_share_flags (oflags); +/* * BB add processing to set equivalent of mode - e.g. via CreateX with * ACLs fs/cifs/file.c +4
-0@@ -210,6 +210,8 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,*********************************************************************/ disposition =cifs_get_disposition (f_flags); +if (IS_SHARELOCK (inode)) + share_access =cifs_get_share_flags (f_flags);/* BB pass O_SYNC flag through on file attributes .. BB */ @@ -645,6 +647,8 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) } desired_access =cifs_convert_flags (cfile->f_flags); +if (IS_SHARELOCK (inode)) + share_access =cifs_get_share_flags (cfile->f_flags);if (backup_cred (cifs_sb)) create_options |=CREATE_OPEN_BACKUP_INTENT ;fs/locks.c +1
-0@@ -846,10 +846,18 @@ deny_lock_file(struct file *filp) {struct file_lock *lock;int error =0 ; +const char *fsname = filp->f_path.dentry->d_inode->i_sb->s_type->name;fs/locks.c deny_lock_file(struct file *filp) · line 860
Quoted 10 lines
fs/locks.c +7
-0if (!IS_SHARELOCK (filp->f_path.dentry->d_inode))return error; +/* +* Don't set a lock on CIFS file systems because they can process it +* themselves. +*/ +if (!strncmp (fsname,"cifs" ,4 )) +return error; +NAK....
Quoted 3 lines
This is really nasty. Instead of doing this, you should instead create a new
file_system_type->fs_flagsvalue. Then, set that flag for cifs and nfs4, and test it here.
It seems I missed this fs_flags opportunity. Thank you for pointing it out - I will fix and repost.
--
Best regards,
Pavel Shilovsky.
PATCH v4 4/7 CIFS: Use NT_CREATE_ANDX command for forcemand mounts
In reply to Pavel Shilovskyforcemand mount option now lets us use Windows mandatory style of byte-range locks even if server supports posix ones - switches on Windows locking mechanism. Share flags is another locking mehanism provided by Windows semantic that can be used by NT_CREATE_ANDX command. This patch combines all Windows locking mechanism in one mount option by using NT_CREATE_ANDX to open files if forcemand is on.
--- fs/cifs/dir.c | 1 + fs/cifs/file.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-)
fs/cifs/dir.c +1 -0
@@ -217,6 +217,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, }if (tcon->unix_ext &&cap_unix (tcon->ses) && !tcon->broken_posix_open && + ((cifs_sb->mnt_cifs_flags &CIFS_MOUNT_NOPOSIXBRL ) ==0 ) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &le64_to_cpu (tcon->fsUnixInfo.Capability))) { rc = cifs_posix_open(full_path, &newinode, inode->i_sb, mode,
fs/cifs/file.c +4 -2
@@ -455,8 +455,9 @@ int cifs_open(struct inode *inode, struct file *file)else oplock =0 ; -if (!tcon->broken_posix_open && tcon->unix_ext && -cap_unix (tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP & +if (!tcon->broken_posix_open && tcon->unix_ext &&cap_unix (tcon->ses) + && ((cifs_sb->mnt_cifs_flags &CIFS_MOUNT_NOPOSIXBRL ) ==0 ) && + (CIFS_UNIX_POSIX_PATH_OPS_CAP &le64_to_cpu (tcon->fsUnixInfo.Capability))) {/* can not refresh inode info since size could be stale */ rc = cifs_posix_open(full_path, &inode, inode->i_sb,
@@ -624,6 +625,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) oplock =0 ;if (tcon->unix_ext &&cap_unix (tcon->ses) && + ((cifs_sb->mnt_cifs_flags &CIFS_MOUNT_NOPOSIXBRL ) ==0 ) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &le64_to_cpu (tcon->fsUnixInfo.Capability))) {/*
Signature · 1 line
1.8.1.5
PATCH v4 5/7 NFSv4: Add O_DENY* open flags support
In reply to Pavel Shilovskyby passing these flags to NFSv4 open request.
--- fs/locks.c | 6 +++--- fs/nfs/internal.h | 3 ++- fs/nfs/nfs4proc.c | 2 ++ fs/nfs/nfs4xdr.c | 21 +++++++++++++++++---- fs/nfs/super.c | 3 ++- 5 files changed, 26 insertions(+), 9 deletions(-)
fs/locks.c +3 -3
@@ -852,10 +852,10 @@ deny_lock_file(struct file *filp)return error;/* -* Don't set a lock on CIFS file systems because they can process it -* themselves. +* Don't set a lock on CIFS and NFSv4 file systems because they can +* process it themselves. */ -if (!strncmp (fsname,"cifs" ,4 )) +if (!strncmp (fsname,"cifs" ,4 ) || !strncmp (fsname,"nfs4" ,4 ))return error; error =flock_make_lock (filp, &lock,deny_flags_to_cmd (filp->f_flags));
fs/nfs/internal.h +2 -1
@@ -6,7 +6,8 @@#include <linux/mount.h> #include <linux/security.h> -#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) +#define NFS_MS_MASK (MS_RDONLY | MS_NOSUID | MS_NODEV | MS_NOEXEC | \ + MS_SYNCHRONOUS | MS_SHARELOCK)struct nfs_string ;
fs/nfs/nfs4proc.c +2 -0
@@ -793,6 +793,8 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,atomic_inc (&sp->so_count); p->o_arg.fh =NFS_FH (dir); p->o_arg.open_flags = flags; +if (!IS_SHARELOCK (dir)) + p->o_arg.open_flags &= ~(O_DENYREAD |O_DENYWRITE ); p->o_arg.fmode = fmode & (FMODE_READ |FMODE_WRITE );/* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS * will return permission denied for all bits until close */
fs/nfs/nfs4xdr.c +17 -4
@@ -1325,7 +1325,8 @@ static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, strucencode_string (xdr, name->len, name->name); } -static void encode_share_access (struct xdr_stream *xdr,fmode_t fmode) +static void encode_share_access (struct xdr_stream *xdr,fmode_t fmode, +int open_flags) {__be32 *p;
@@ -1343,7 +1344,19 @@ static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)default : *p++ =cpu_to_be32 (0 ); } - *p =cpu_to_be32 (0 );/* for linux, share_deny = 0 always */ +switch (open_flags & (O_DENYREAD |O_DENYWRITE )) { +case O_DENYREAD : + *p =cpu_to_be32 (NFS4_SHARE_DENY_READ ); +break ; +case O_DENYWRITE : + *p =cpu_to_be32 (NFS4_SHARE_DENY_WRITE ); +break ; +case O_DENYREAD |O_DENYWRITE : + *p =cpu_to_be32 (NFS4_SHARE_DENY_BOTH ); +break ; +default : + *p =cpu_to_be32 (0 ); + } }static inline void encode_openhdr (struct xdr_stream *xdr,const struct nfs_openargs *arg)
@@ -1354,7 +1367,7 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena* owner 4 = 32 */ encode_nfs4_seqid (xdr, arg->seqid); -encode_share_access (xdr, arg->fmode); +encode_share_access (xdr, arg->fmode, arg->open_flags); p =reserve_space (xdr,36 ); p =xdr_encode_hyper (p, arg->clientid); *p++ =cpu_to_be32 (24 );
@@ -1491,7 +1504,7 @@ static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeencode_op_hdr (xdr,OP_OPEN_DOWNGRADE , decode_open_downgrade_maxsz, hdr);encode_nfs4_stateid (xdr, arg->stateid);encode_nfs4_seqid (xdr, arg->seqid); -encode_share_access (xdr, arg->fmode); +encode_share_access (xdr, arg->fmode,0 ); } static void
fs/nfs/super.c +2 -1
@@ -2589,6 +2589,7 @@ nfs_xdev_mount(struct file_system_type *fs_type, int flags,struct nfs_server *server;struct dentry *mntroot =ERR_PTR (-ENOMEM );struct nfs_subversion *nfs_mod =NFS_SB (data->sb)->nfs_client->cl_nfs_mod; +int sharelock = data->sb->s_flags &MS_SHARELOCK ;/* save sharelock option */ dprintk ("--> nfs_xdev_mount()\n" );
@@ -2600,7 +2601,7 @@ nfs_xdev_mount(struct file_system_type *fs_type, int flags,if (IS_ERR (server)) mntroot =ERR_CAST (server);else - mntroot =nfs_fs_mount_common (server, flags, + mntroot =nfs_fs_mount_common (server, flags | sharelock, dev_name, &mount_info, nfs_mod); dprintk("<-- nfs_xdev_mount() = %ld\n",
Signature · 1 line
1.8.1.5
PATCH v4 6/7 NFSD: Pass share reservations flags to VFS
In reply to Pavel Shilovskythat maps them into O_DENY flags and make them visible for applications that use O_DENYMAND opens.
--- fs/locks.c | 1 + fs/nfsd/nfs4state.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-)
fs/locks.c +1 -0
@@ -869,6 +869,7 @@ deny_lock_file(struct file *filp)locks_free_lock (lock);return error; } +EXPORT_SYMBOL (deny_lock_file);static int __posix_lock_file (struct inode *inode,struct file_lock *request,struct file_lock *conflock) {
fs/nfsd/nfs4state.c +45 -1
82 lines not on this page · raw message
Signature · 1 line
1.8.1.5
PATCH v4 7/7 locks: Disable LOCK_MAND support for MS_SHARELOCK mounts
In reply to Pavel Shilovsky--- fs/locks.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/locks.c +6 -0
@@ -1722,6 +1722,12 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)if (!f.file) goto out; +/* Disable LOCK_MAND support for FS mounted with MS_SHARELOCK */ +if (IS_SHARELOCK (f.file->f_path.dentry->d_inode)) { + error = -EPERM ; + goto out; + } + can_sleep = !(cmd &LOCK_NB ); cmd &= ~LOCK_NB ; unlock = (cmd ==LOCK_UN );
Signature · 1 line
1.8.1.5
2013/4/5 Pavel Shilovsky <[email protected]>:
Quoted 23 lines
Main changes from the previous one:
1)O_DENYMANDis removed, sharelock mount option is introduced.
2) Patchfcntl.hand VFS patches are united into one.
3) flock/LOCK_MAND is disabled for sharelock mounts.This patchset adds support of O_DENY* flags for Linux fs layer. These flags can be used by any application that needs share reservations to organize a file access. VFS already has some sort of this capability - now it's done through flock/LOCK_MAND mechanis, but that approach is non-atomic. This patchset build new capabilities on top of the existing one but doesn't bring any changes into the flock call semantic.
These flags can be used by NFS (built-in-kernel) and CIFS (Samba) servers and Wine applications through VFS (for local filesystems) or CIFS/NFS modules. This will help when e.g. Samba and NFS server share the same directory for Windows and Linux users or Wine applications use Samba/NFS share to access the same data from different clients.
According to the previous discussions the most problematic question is how to prevent situations like DoS attacks where e.g
/lib/liba.sofile can be open with DENYREAD, or smth like this. That's why extra mount option 'sharelock' is added for switching on/off O_DENY* flags processing. It allows us to avoid use of these flags on critical places (like /, /lib) and turn them on if we really want it proccessed that way.So, we have 3 new flags:
O_DENYREAD- to prevent other opens with read access,O_DENYWRITE- to prevent other opens with write access,O_DENYDELETE- to prevent delete operations (this flag is not implemented in VFS and NFS part and only suitable for CIFS module),The patchset avoid data races problem on newely created files: open with
O_CREATcan return the-ETXTBSYerror for a successfully created file if this files was locked with a deny lock by another task. Also, it turns flock/LOCK_MAND capability off for mounts with 'sharelock' option. This let us not mix one share reservation approach with another.The #1 patch adds flags to fcntl and implements VFS part. The patches #3, #4, #5 are related to CIFS-specific changes, #6 and #7 describe NFS and NFSD parts.
The preliminary patch for Samba that replaces the existing use of flock/LOCK_MAND mechanism with O_DENY* flags:
http://git.etersoft.ru/people/piastry/packages/?p=samba.git;a=commitdiff;h=173070262b7f29134ad6b2e49a760017c11aec4a
Quoted 8 lines
The future part of open man page patch:
-----
O_DENYREAD,O_DENYWRIYE,O_DENYDELETE- used to inforce a mandatory share reservation scheme of the file access. If these flag is passed, the open fails with-EBUSYin following cases:
1) ifO_DENYREADflag is specified and there is another open withO_DENYMANDflag and READ access to the file;
2) ifO_DENYWRITEflag is specified and there is another open withO_DENYMANDflag and WRITE access to the file;
3) if READ access is requested and there is another open withO_DENYMANDandO_DENYREADflags;
4) if WRITE access is requested and there is another open withO_DENYMANDandO_DENYWRITEflags.
Should be without O_DENYMAND (copy-and-paste issue, sorry):
1) if O_DENYREAD flag is specified and there is another open with READ access to the file;
2) if O_DENYWRITE flag is specified and there is another open with WRITE access to the file;
3) if READ access is requested and there is another open with O_DENYREAD flags;
4) if WRITE access is requested and there is another open with O_DENYWRITE flags.
--
Best regards,
Pavel Shilovsky.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html