Linux-CIFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] cifs: use existing handle for compound_op(OP_SET_INFO) when possible
@ 2019-08-29 23:53 Ronnie Sahlberg
  2019-08-30  1:19 ` Steve French
  0 siblings, 1 reply; 2+ messages in thread
From: Ronnie Sahlberg @ 2019-08-29 23:53 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French

If we already have a writable handle for a path we want to set the
attributes for then use that instead of a create/set-info/close compound.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/smb2inode.c | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c
index 939fc7b2234c..6aeb2950382c 100644
--- a/fs/cifs/smb2inode.c
+++ b/fs/cifs/smb2inode.c
@@ -192,14 +192,27 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		size[0] = sizeof(FILE_BASIC_INFO);
 		data[0] = ptr;
 
-		rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID,
-					COMPOUND_FID, current->tgid,
-					FILE_BASIC_INFORMATION,
-					SMB2_O_INFO_FILE, 0, data, size);
+		if (cfile)
+			rc = SMB2_set_info_init(tcon, &rqst[num_rqst],
+				cfile->fid.persistent_fid,
+				cfile->fid.volatile_fid, current->tgid,
+				FILE_BASIC_INFORMATION,
+				SMB2_O_INFO_FILE, 0, data, size);
+		else {
+			rc = SMB2_set_info_init(tcon, &rqst[num_rqst],
+				COMPOUND_FID,
+				COMPOUND_FID, current->tgid,
+				FILE_BASIC_INFORMATION,
+				SMB2_O_INFO_FILE, 0, data, size);
+			if (!rc) {
+				smb2_set_next_command(tcon, &rqst[num_rqst]);
+				smb2_set_related(&rqst[num_rqst]);
+			}
+		}
+
 		if (rc)
 			goto finished;
-		smb2_set_next_command(tcon, &rqst[num_rqst]);
-		smb2_set_related(&rqst[num_rqst++]);
+		num_rqst++;
 		trace_smb3_set_info_compound_enter(xid, ses->Suid, tcon->tid,
 						   full_path);
 		break;
@@ -231,8 +244,10 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 					COMPOUND_FID, COMPOUND_FID,
 					current->tgid, FILE_RENAME_INFORMATION,
 					SMB2_O_INFO_FILE, 0, data, size);
-			smb2_set_next_command(tcon, &rqst[num_rqst]);
-			smb2_set_related(&rqst[num_rqst]);
+			if (!rc) {
+				smb2_set_next_command(tcon, &rqst[num_rqst]);
+				smb2_set_related(&rqst[num_rqst]);
+			}
 		}
 		if (rc)
 			goto finished;
@@ -475,6 +490,7 @@ smb2_mkdir_setinfo(struct inode *inode, const char *name,
 {
 	FILE_BASIC_INFO data;
 	struct cifsInodeInfo *cifs_i;
+	struct cifsFileInfo *cfile;
 	u32 dosattrs;
 	int tmprc;
 
@@ -482,10 +498,11 @@ smb2_mkdir_setinfo(struct inode *inode, const char *name,
 	cifs_i = CIFS_I(inode);
 	dosattrs = cifs_i->cifsAttrs | ATTR_READONLY;
 	data.Attributes = cpu_to_le32(dosattrs);
+	cifs_get_writable_path(tcon, name, &cfile);
 	tmprc = smb2_compound_op(xid, tcon, cifs_sb, name,
 				 FILE_WRITE_ATTRIBUTES, FILE_CREATE,
 				 CREATE_NOT_FILE, &data, SMB2_OP_SET_INFO,
-				 NULL);
+				 cfile);
 	if (tmprc == 0)
 		cifs_i->cifsAttrs = dosattrs;
 }
@@ -570,6 +587,7 @@ smb2_set_file_info(struct inode *inode, const char *full_path,
 {
 	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
 	struct tcon_link *tlink;
+	struct cifsFileInfo *cfile;
 	int rc;
 
 	if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) &&
@@ -581,9 +599,11 @@ smb2_set_file_info(struct inode *inode, const char *full_path,
 	if (IS_ERR(tlink))
 		return PTR_ERR(tlink);
 
+	cifs_get_writable_path(tlink_tcon(tlink), full_path, &cfile);
+
 	rc = smb2_compound_op(xid, tlink_tcon(tlink), cifs_sb, full_path,
 			      FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, buf,
-			      SMB2_OP_SET_INFO, NULL);
+			      SMB2_OP_SET_INFO, cfile);
 	cifs_put_tlink(tlink);
 	return rc;
 }
-- 
2.13.6


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] cifs: use existing handle for compound_op(OP_SET_INFO) when possible
  2019-08-29 23:53 [PATCH] cifs: use existing handle for compound_op(OP_SET_INFO) when possible Ronnie Sahlberg
@ 2019-08-30  1:19 ` Steve French
  0 siblings, 0 replies; 2+ messages in thread
From: Steve French @ 2019-08-30  1:19 UTC (permalink / raw)
  To: Ronnie Sahlberg; +Cc: linux-cifs

Tentatively merged into cifs-2.6.git for-next pending more testing and review

On Thu, Aug 29, 2019 at 6:54 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
>
> If we already have a writable handle for a path we want to set the
> attributes for then use that instead of a create/set-info/close compound.
>
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/smb2inode.c | 40 ++++++++++++++++++++++++++++++----------
>  1 file changed, 30 insertions(+), 10 deletions(-)
>
> diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c
> index 939fc7b2234c..6aeb2950382c 100644
> --- a/fs/cifs/smb2inode.c
> +++ b/fs/cifs/smb2inode.c
> @@ -192,14 +192,27 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
>                 size[0] = sizeof(FILE_BASIC_INFO);
>                 data[0] = ptr;
>
> -               rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID,
> -                                       COMPOUND_FID, current->tgid,
> -                                       FILE_BASIC_INFORMATION,
> -                                       SMB2_O_INFO_FILE, 0, data, size);
> +               if (cfile)
> +                       rc = SMB2_set_info_init(tcon, &rqst[num_rqst],
> +                               cfile->fid.persistent_fid,
> +                               cfile->fid.volatile_fid, current->tgid,
> +                               FILE_BASIC_INFORMATION,
> +                               SMB2_O_INFO_FILE, 0, data, size);
> +               else {
> +                       rc = SMB2_set_info_init(tcon, &rqst[num_rqst],
> +                               COMPOUND_FID,
> +                               COMPOUND_FID, current->tgid,
> +                               FILE_BASIC_INFORMATION,
> +                               SMB2_O_INFO_FILE, 0, data, size);
> +                       if (!rc) {
> +                               smb2_set_next_command(tcon, &rqst[num_rqst]);
> +                               smb2_set_related(&rqst[num_rqst]);
> +                       }
> +               }
> +
>                 if (rc)
>                         goto finished;
> -               smb2_set_next_command(tcon, &rqst[num_rqst]);
> -               smb2_set_related(&rqst[num_rqst++]);
> +               num_rqst++;
>                 trace_smb3_set_info_compound_enter(xid, ses->Suid, tcon->tid,
>                                                    full_path);
>                 break;
> @@ -231,8 +244,10 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
>                                         COMPOUND_FID, COMPOUND_FID,
>                                         current->tgid, FILE_RENAME_INFORMATION,
>                                         SMB2_O_INFO_FILE, 0, data, size);
> -                       smb2_set_next_command(tcon, &rqst[num_rqst]);
> -                       smb2_set_related(&rqst[num_rqst]);
> +                       if (!rc) {
> +                               smb2_set_next_command(tcon, &rqst[num_rqst]);
> +                               smb2_set_related(&rqst[num_rqst]);
> +                       }
>                 }
>                 if (rc)
>                         goto finished;
> @@ -475,6 +490,7 @@ smb2_mkdir_setinfo(struct inode *inode, const char *name,
>  {
>         FILE_BASIC_INFO data;
>         struct cifsInodeInfo *cifs_i;
> +       struct cifsFileInfo *cfile;
>         u32 dosattrs;
>         int tmprc;
>
> @@ -482,10 +498,11 @@ smb2_mkdir_setinfo(struct inode *inode, const char *name,
>         cifs_i = CIFS_I(inode);
>         dosattrs = cifs_i->cifsAttrs | ATTR_READONLY;
>         data.Attributes = cpu_to_le32(dosattrs);
> +       cifs_get_writable_path(tcon, name, &cfile);
>         tmprc = smb2_compound_op(xid, tcon, cifs_sb, name,
>                                  FILE_WRITE_ATTRIBUTES, FILE_CREATE,
>                                  CREATE_NOT_FILE, &data, SMB2_OP_SET_INFO,
> -                                NULL);
> +                                cfile);
>         if (tmprc == 0)
>                 cifs_i->cifsAttrs = dosattrs;
>  }
> @@ -570,6 +587,7 @@ smb2_set_file_info(struct inode *inode, const char *full_path,
>  {
>         struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
>         struct tcon_link *tlink;
> +       struct cifsFileInfo *cfile;
>         int rc;
>
>         if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) &&
> @@ -581,9 +599,11 @@ smb2_set_file_info(struct inode *inode, const char *full_path,
>         if (IS_ERR(tlink))
>                 return PTR_ERR(tlink);
>
> +       cifs_get_writable_path(tlink_tcon(tlink), full_path, &cfile);
> +
>         rc = smb2_compound_op(xid, tlink_tcon(tlink), cifs_sb, full_path,
>                               FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, buf,
> -                             SMB2_OP_SET_INFO, NULL);
> +                             SMB2_OP_SET_INFO, cfile);
>         cifs_put_tlink(tlink);
>         return rc;
>  }
> --
> 2.13.6
>


-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29 23:53 [PATCH] cifs: use existing handle for compound_op(OP_SET_INFO) when possible Ronnie Sahlberg
2019-08-30  1:19 ` Steve French

Linux-CIFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-cifs/0 linux-cifs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-cifs linux-cifs/ https://lore.kernel.org/linux-cifs \
		linux-cifs@vger.kernel.org linux-cifs@archiver.kernel.org
	public-inbox-index linux-cifs


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-cifs


AGPL code for this site: git clone https://public-inbox.org/ public-inbox