Skip to content

Commit 89a5bfa

Browse files
author
Steve French
committed
smb3: optimize open to not send query file internal info
We can cut one third of the traffic on open by not querying the inode number explicitly via SMB3 query_info since it is now returned on open in the qfid context. This is better in multiple ways, and speeds up file open about 10% (more if network is slow). Reviewed-by: Pavel Shilovsky <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent bf3c90e commit 89a5bfa

File tree

5 files changed

+56
-26
lines changed

5 files changed

+56
-26
lines changed

fs/cifs/smb2file.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,20 @@ smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
8888
}
8989

9090
if (buf) {
91-
/* open response does not have IndexNumber field - get it */
92-
rc = SMB2_get_srv_num(xid, oparms->tcon, fid->persistent_fid,
91+
/* if open response does not have IndexNumber field - get it */
92+
if (smb2_data->IndexNumber == 0) {
93+
rc = SMB2_get_srv_num(xid, oparms->tcon,
94+
fid->persistent_fid,
9395
fid->volatile_fid,
9496
&smb2_data->IndexNumber);
95-
if (rc) {
96-
/* let get_inode_info disable server inode numbers */
97-
smb2_data->IndexNumber = 0;
98-
rc = 0;
97+
if (rc) {
98+
/*
99+
* let get_inode_info disable server inode
100+
* numbers
101+
*/
102+
smb2_data->IndexNumber = 0;
103+
rc = 0;
104+
}
99105
}
100106
move_smb2_info_to_cifs(buf, smb2_data);
101107
}

fs/cifs/smb2ops.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,11 +754,12 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
754754
tcon->crfid.is_valid = true;
755755
kref_init(&tcon->crfid.refcount);
756756

757+
/* BB TBD check to see if oplock level check can be removed below */
757758
if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) {
758759
kref_get(&tcon->crfid.refcount);
759-
oplock = smb2_parse_lease_state(server, o_rsp,
760-
&oparms.fid->epoch,
761-
oparms.fid->lease_key);
760+
smb2_parse_contexts(server, o_rsp,
761+
&oparms.fid->epoch,
762+
oparms.fid->lease_key, &oplock, NULL);
762763
} else
763764
goto oshr_exit;
764765

fs/cifs/smb2pdu.c

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,26 +1873,46 @@ create_reconnect_durable_buf(struct cifs_fid *fid)
18731873
return buf;
18741874
}
18751875

1876-
__u8
1877-
smb2_parse_lease_state(struct TCP_Server_Info *server,
1876+
static void
1877+
parse_query_id_ctxt(struct create_context *cc, struct smb2_file_all_info *buf)
1878+
{
1879+
struct create_on_disk_id *pdisk_id = (struct create_on_disk_id *)cc;
1880+
1881+
cifs_dbg(FYI, "parse query id context 0x%llx 0x%llx\n",
1882+
pdisk_id->DiskFileId, pdisk_id->VolumeId);
1883+
buf->IndexNumber = pdisk_id->DiskFileId;
1884+
}
1885+
1886+
void
1887+
smb2_parse_contexts(struct TCP_Server_Info *server,
18781888
struct smb2_create_rsp *rsp,
1879-
unsigned int *epoch, char *lease_key)
1889+
unsigned int *epoch, char *lease_key, __u8 *oplock,
1890+
struct smb2_file_all_info *buf)
18801891
{
18811892
char *data_offset;
18821893
struct create_context *cc;
18831894
unsigned int next;
18841895
unsigned int remaining;
18851896
char *name;
18861897

1898+
*oplock = 0;
18871899
data_offset = (char *)rsp + le32_to_cpu(rsp->CreateContextsOffset);
18881900
remaining = le32_to_cpu(rsp->CreateContextsLength);
18891901
cc = (struct create_context *)data_offset;
1902+
1903+
/* Initialize inode number to 0 in case no valid data in qfid context */
1904+
if (buf)
1905+
buf->IndexNumber = 0;
1906+
18901907
while (remaining >= sizeof(struct create_context)) {
18911908
name = le16_to_cpu(cc->NameOffset) + (char *)cc;
18921909
if (le16_to_cpu(cc->NameLength) == 4 &&
1893-
strncmp(name, "RqLs", 4) == 0)
1894-
return server->ops->parse_lease_buf(cc, epoch,
1895-
lease_key);
1910+
strncmp(name, SMB2_CREATE_REQUEST_LEASE, 4) == 0)
1911+
*oplock = server->ops->parse_lease_buf(cc, epoch,
1912+
lease_key);
1913+
else if (buf && (le16_to_cpu(cc->NameLength) == 4) &&
1914+
strncmp(name, SMB2_CREATE_QUERY_ON_DISK_ID, 4) == 0)
1915+
parse_query_id_ctxt(cc, buf);
18961916

18971917
next = le32_to_cpu(cc->Next);
18981918
if (!next)
@@ -1901,7 +1921,10 @@ smb2_parse_lease_state(struct TCP_Server_Info *server,
19011921
cc = (struct create_context *)((char *)cc + next);
19021922
}
19031923

1904-
return 0;
1924+
if (rsp->OplockLevel != SMB2_OPLOCK_LEVEL_LEASE)
1925+
*oplock = rsp->OplockLevel;
1926+
1927+
return;
19051928
}
19061929

19071930
static int
@@ -2588,12 +2611,9 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
25882611
buf->DeletePending = 0;
25892612
}
25902613

2591-
if (rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE)
2592-
*oplock = smb2_parse_lease_state(server, rsp,
2593-
&oparms->fid->epoch,
2594-
oparms->fid->lease_key);
2595-
else
2596-
*oplock = rsp->OplockLevel;
2614+
2615+
smb2_parse_contexts(server, rsp, &oparms->fid->epoch,
2616+
oparms->fid->lease_key, oplock, buf);
25972617
creat_exit:
25982618
SMB2_open_free(&rqst);
25992619
free_rsp_buf(resp_buftype, rsp);

fs/cifs/smb2pdu.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,9 @@ struct durable_reconnect_context_v2 {
818818
} __packed;
819819

820820
/* See MS-SMB2 2.2.14.2.9 */
821-
struct on_disk_id {
821+
struct create_on_disk_id {
822+
struct create_context ccontext;
823+
__u8 Name[8];
822824
__le64 DiskFileId;
823825
__le64 VolumeId;
824826
__u32 Reserved[4];

fs/cifs/smb2proto.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,10 @@ extern int smb3_validate_negotiate(const unsigned int, struct cifs_tcon *);
228228

229229
extern enum securityEnum smb2_select_sectype(struct TCP_Server_Info *,
230230
enum securityEnum);
231-
extern __u8 smb2_parse_lease_state(struct TCP_Server_Info *server,
232-
struct smb2_create_rsp *rsp,
233-
unsigned int *epoch, char *lease_key);
231+
extern void smb2_parse_contexts(struct TCP_Server_Info *server,
232+
struct smb2_create_rsp *rsp,
233+
unsigned int *epoch, char *lease_key,
234+
__u8 *oplock, struct smb2_file_all_info *buf);
234235
extern int smb3_encryption_required(const struct cifs_tcon *tcon);
235236
extern int smb2_validate_iov(unsigned int offset, unsigned int buffer_length,
236237
struct kvec *iov, unsigned int min_buf_size);

0 commit comments

Comments
 (0)