Re: [PATCH v3 3/7] CIFS: Add O_DENY* open flags support

2013-03-12 Thread Jeff Layton
On Thu, 28 Feb 2013 19:25:29 +0400
Pavel Shilovsky  wrote:

> Make CIFSSMBOpen take share_flags as a parm that allows us
> to pass new O_DENY* flags to the server.
> 
> Signed-off-by: Pavel Shilovsky 
> ---
>  fs/cifs/cifsacl.c   |  6 --
>  fs/cifs/cifsglob.h  | 12 +++-
>  fs/cifs/cifsproto.h |  9 +
>  fs/cifs/cifssmb.c   | 47 +--
>  fs/cifs/dir.c   | 13 -
>  fs/cifs/file.c  | 12 
>  fs/cifs/inode.c | 11 ++-
>  fs/cifs/link.c  | 10 +-
>  fs/cifs/readdir.c   |  2 +-
>  fs/cifs/smb1ops.c   | 15 ---
>  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, 105 insertions(+), 76 deletions(-)
> 
> diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
> index 5cbd00e..222b989 100644
> --- a/fs/cifs/cifsacl.c
> +++ b/fs/cifs/cifsacl.c
> @@ -891,7 +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,
> + FILE_SHARE_ALL, create_options, &fid, &oplock,
> + NULL, cifs_sb->local_nls,
>   cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
>   if (!rc) {
>   rc = CIFSSMBGetCIFSACL(xid, tcon, fid, &pntsd, pacllen);
> @@ -952,7 +953,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,
> + FILE_SHARE_ALL, create_options, &fid, &oplock,
> + NULL, cifs_sb->local_nls,
>   cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
>   if (rc) {
>   cERROR(1, "Unable to open file to set ACL");
> diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
> index e6899ce..f1d62ed 100644
> --- a/fs/cifs/cifsglob.h
> +++ b/fs/cifs/cifsglob.h
> @@ -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);
> @@ -947,6 +947,16 @@ struct cifsFileInfo {
>   struct work_struct oplock_break; /* work for oplock breaks */
>  };
>  
> +#define CIFS_DENY_RW_FLAGS_SHIFT 22
> +#define CIFS_DENY_DEL_FLAG_SHIFT 23
> +
> +static inline int cifs_get_share_flags(unsigned int flags)
> +{
> + return (flags & O_DENYMAND) ?
> + (((~(flags >> CIFS_DENY_RW_FLAGS_SHIFT)) & 3) |
> +  ((~(flags >> CIFS_DENY_DEL_FLAG_SHIFT)) & 4)) : FILE_SHARE_ALL;
> +}
> +
>  struct cifs_io_parms {
>   __u16 netfid;
>  #ifdef CONFIG_CIFS_SMB2
> diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
> index 1988c1b..9661607 100644
> --- a/fs/cifs/cifsproto.h
> +++ b/fs/cifs/cifsproto.h
> @@ -361,10 +361,11 @@ 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 access_flags, const int share_flags,
> + const int omode, __u16 *netfid, int *oplock,
> + FILE_ALL_INFO *, const struct nls_table *nls_codepage,
> + int remap);

Yuck...maybe it's time for a struct cifs_openargs? At the very least,
while you're in here, it would be good to just pass in a cifs_sb
instead of a nls_table and a remap flag.

>  extern int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon,
>   const char *fileName, const int disposition,
>   const int access_flags, const int omode,
> diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
> index 76d0d29..9c4632f 100644
> --- a/fs/cifs/cifssmb.c
> +++ b/fs/cifs/cifssmb.c
> @@ -1289,10 +1289

[PATCH v3 3/7] CIFS: Add O_DENY* open flags support

2013-02-28 Thread Pavel Shilovsky
Make CIFSSMBOpen take share_flags as a parm that allows us
to pass new O_DENY* flags to the server.

Signed-off-by: Pavel Shilovsky 
---
 fs/cifs/cifsacl.c   |  6 --
 fs/cifs/cifsglob.h  | 12 +++-
 fs/cifs/cifsproto.h |  9 +
 fs/cifs/cifssmb.c   | 47 +--
 fs/cifs/dir.c   | 13 -
 fs/cifs/file.c  | 12 
 fs/cifs/inode.c | 11 ++-
 fs/cifs/link.c  | 10 +-
 fs/cifs/readdir.c   |  2 +-
 fs/cifs/smb1ops.c   | 15 ---
 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, 105 insertions(+), 76 deletions(-)

diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index 5cbd00e..222b989 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -891,7 +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,
+   FILE_SHARE_ALL, create_options, &fid, &oplock,
+   NULL, cifs_sb->local_nls,
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
if (!rc) {
rc = CIFSSMBGetCIFSACL(xid, tcon, fid, &pntsd, pacllen);
@@ -952,7 +953,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,
+   FILE_SHARE_ALL, create_options, &fid, &oplock,
+   NULL, cifs_sb->local_nls,
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
if (rc) {
cERROR(1, "Unable to open file to set ACL");
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index e6899ce..f1d62ed 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -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);
@@ -947,6 +947,16 @@ struct cifsFileInfo {
struct work_struct oplock_break; /* work for oplock breaks */
 };
 
+#define CIFS_DENY_RW_FLAGS_SHIFT   22
+#define CIFS_DENY_DEL_FLAG_SHIFT   23
+
+static inline int cifs_get_share_flags(unsigned int flags)
+{
+   return (flags & O_DENYMAND) ?
+   (((~(flags >> CIFS_DENY_RW_FLAGS_SHIFT)) & 3) |
+((~(flags >> CIFS_DENY_DEL_FLAG_SHIFT)) & 4)) : FILE_SHARE_ALL;
+}
+
 struct cifs_io_parms {
__u16 netfid;
 #ifdef CONFIG_CIFS_SMB2
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 1988c1b..9661607 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -361,10 +361,11 @@ 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 access_flags, const int share_flags,
+   const int omode, __u16 *netfid, int *oplock,
+   FILE_ALL_INFO *, const struct nls_table *nls_codepage,
+   int remap);
 extern int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon,
const char *fileName, const int disposition,
const int access_flags, const int omode,
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 76d0d29..9c4632f 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -1289,10 +1289,11 @@ OldOpenRetry:
 
 int
 CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon,
-   const char *fileName, const int openDisposition,
-   const int access_flags, const int create_options, __u16 *netfid,
-   int *pOplock, FILE_ALL_INFO *pfile_info,
-   const struct nls_table *nls_codepage, int remap)
+   const