]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
smb/client: pass cifs_open_info_data to SMB2_open()
authorChenXiaoSong <chenxiaosong@kylinos.cn>
Thu, 9 Jul 2026 02:57:01 +0000 (10:57 +0800)
committerSteve French <stfrench@microsoft.com>
Thu, 9 Jul 2026 12:55:55 +0000 (07:55 -0500)
Let SMB2_open() fill the smb2_file_all_info embedded in cifs_open_info_data
directly. This removes the temporary smb2_file_all_info copy in
smb2_open_file().

Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/link.c
fs/smb/client/smb2file.c
fs/smb/client/smb2pdu.c
fs/smb/client/smb2proto.h

index 0014523d6511f1a61fa4c6caf90584ef27a035bd..b60dc407815dc4f758ed2c2d234cabd5cb56e665 100644 (file)
@@ -320,7 +320,7 @@ smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
        int buf_type = CIFS_NO_BUFFER;
        __le16 *utf16_path;
        __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
-       struct smb2_file_all_info file_info = {};
+       struct cifs_open_info_data data = {};
 
        oparms = (struct cifs_open_parms) {
                .tcon = tcon,
@@ -336,12 +336,12 @@ smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
        if (utf16_path == NULL)
                return -ENOMEM;
 
-       rc = SMB2_open(xid, &oparms, utf16_path, &oplock, &file_info, NULL,
+       rc = SMB2_open(xid, &oparms, utf16_path, &oplock, &data, NULL,
                       NULL, NULL);
        if (rc)
                goto qmf_out_open_fail;
 
-       if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) {
+       if (data.fi.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) {
                /* it's not a symlink */
                rc = -ENOENT; /* Is there a better rc to return? */
                goto qmf_out;
index 6860eff3169329de5c7877824a832f8bea729188..5ef919bce52d0a334139e60dfbaa440b0be1f710 100644 (file)
@@ -154,8 +154,6 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
        __le16 *smb2_path;
        __u8 smb2_oplock;
        struct cifs_open_info_data *data = buf;
-       struct smb2_file_all_info file_info = {};
-       struct smb2_file_all_info *smb2_data = data ? &file_info : NULL;
        struct kvec err_iov = {};
        int err_buftype = CIFS_NO_BUFFER;
        struct cifs_fid *fid = oparms->fid;
@@ -182,14 +180,14 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
        }
        smb2_oplock = SMB2_OPLOCK_LEVEL_BATCH;
 
-       rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL, &err_iov,
+       rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, data, NULL, &err_iov,
                       &err_buftype);
        if (rc == -EACCES && retry_without_read_attributes) {
                free_rsp_buf(err_buftype, err_iov.iov_base);
                memset(&err_iov, 0, sizeof(err_iov));
                err_buftype = CIFS_NO_BUFFER;
                oparms->desired_access &= ~FILE_READ_ATTRIBUTES;
-               rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL, &err_iov,
+               rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, data, NULL, &err_iov,
                               &err_buftype);
        }
        if (rc && data) {
@@ -202,9 +200,9 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
                                                         oparms->path,
                                                         &data->symlink_target);
                        if (!rc) {
-                               memset(smb2_data, 0, sizeof(*smb2_data));
+                               memset(&data->fi, 0, sizeof(data->fi));
                                oparms->create_options |= OPEN_REPARSE_POINT;
-                               rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data,
+                               rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, data,
                                               NULL, NULL, NULL);
                                oparms->create_options &= ~OPEN_REPARSE_POINT;
                        }
@@ -238,23 +236,22 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
                rc = 0;
        }
 
-       if (smb2_data) {
+       if (data) {
                /* if open response does not have IndexNumber field - get it */
-               if (smb2_data->IndexNumber == 0) {
+               if (data->fi.IndexNumber == 0) {
                        rc = SMB2_get_srv_num(xid, oparms->tcon,
                                      fid->persistent_fid,
                                      fid->volatile_fid,
-                                     &smb2_data->IndexNumber);
+                                     &data->fi.IndexNumber);
                        if (rc) {
                                /*
                                 * let get_inode_info disable server inode
                                 * numbers
                                 */
-                               smb2_data->IndexNumber = 0;
+                               data->fi.IndexNumber = 0;
                                rc = 0;
                        }
                }
-               memcpy(&data->fi, smb2_data, sizeof(data->fi));
        }
 
        *oplock = smb2_oplock;
index 95c0efe9d43b1f355c01160ebeb2196069042dc1..bc77170458b362b28c1d2fc7ca74bacc74da130f 100644 (file)
@@ -3287,7 +3287,7 @@ SMB2_open_free(struct smb_rqst *rqst)
 
 int
 SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
-         __u8 *oplock, struct smb2_file_all_info *buf,
+         __u8 *oplock, struct cifs_open_info_data *buf,
          struct create_posix_rsp *posix,
          struct kvec *err_iov, int *buftype)
 {
@@ -3302,6 +3302,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
        int rc = 0;
        int flags = 0;
        int retries = 0, cur_sleep = 0;
+       struct smb2_file_all_info *file_info = buf ? &buf->fi : NULL;
 
 replay_again:
        /* reinitialize for possible replay */
@@ -3370,21 +3371,21 @@ replay_again:
        oparms->fid->mid = le64_to_cpu(rsp->hdr.MessageId);
 #endif /* CIFS_DEBUG2 */
 
-       if (buf) {
-               buf->CreationTime = rsp->CreationTime;
-               buf->LastAccessTime = rsp->LastAccessTime;
-               buf->LastWriteTime = rsp->LastWriteTime;
-               buf->ChangeTime = rsp->ChangeTime;
-               buf->AllocationSize = rsp->AllocationSize;
-               buf->EndOfFile = rsp->EndofFile;
-               buf->Attributes = rsp->FileAttributes;
-               buf->NumberOfLinks = cpu_to_le32(1);
-               buf->DeletePending = 0; /* successful open = not delete pending */
+       if (file_info) {
+               file_info->CreationTime = rsp->CreationTime;
+               file_info->LastAccessTime = rsp->LastAccessTime;
+               file_info->LastWriteTime = rsp->LastWriteTime;
+               file_info->ChangeTime = rsp->ChangeTime;
+               file_info->AllocationSize = rsp->AllocationSize;
+               file_info->EndOfFile = rsp->EndofFile;
+               file_info->Attributes = rsp->FileAttributes;
+               file_info->NumberOfLinks = cpu_to_le32(1);
+               file_info->DeletePending = 0; /* successful open = not delete pending */
        }
 
 
        rc = smb2_parse_contexts(server, &rsp_iov, &oparms->fid->epoch,
-                                oparms->fid->lease_key, oplock, buf, posix);
+                                oparms->fid->lease_key, oplock, file_info, posix);
 
        trace_smb3_open_done(xid, rsp->PersistentFileId, tcon->tid, ses->Suid,
                             oparms->create_options, oparms->desired_access,
index 78a4e1c340f99536deb4fdd21d4b021bc731c122..e01effe45ae2e66009b88644654c5ef0c3eb9e1a 100644 (file)
@@ -136,7 +136,7 @@ int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
              struct cifs_tcon *tcon, const struct nls_table *cp);
 int SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon);
 int SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms,
-             __le16 *path, __u8 *oplock, struct smb2_file_all_info *buf,
+             __le16 *path, __u8 *oplock, struct cifs_open_info_data *buf,
              struct create_posix_rsp *posix, struct kvec *err_iov,
              int *buftype);
 int SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,