Skip to content

Commit 2a8d138

Browse files
vlendecsmfrench
authored andcommitted
cifs: Simplify SMB2_open_init()
Reduce code duplication by stitching together create contexts in one place. Signed-off-by: Volker Lendecke <[email protected]> Reviewed-by: Enzo Matsumiya <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 5ec629e commit 2a8d138

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

fs/cifs/smb2pdu.c

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,42 +2835,20 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
28352835
}
28362836

28372837
if (*oplock == SMB2_OPLOCK_LEVEL_BATCH) {
2838-
/* need to set Next field of lease context if we request it */
2839-
if (server->capabilities & SMB2_GLOBAL_CAP_LEASING) {
2840-
struct create_context *ccontext =
2841-
(struct create_context *)iov[n_iov-1].iov_base;
2842-
ccontext->Next =
2843-
cpu_to_le32(server->vals->create_lease_size);
2844-
}
2845-
28462838
rc = add_durable_context(iov, &n_iov, oparms,
28472839
tcon->use_persistent);
28482840
if (rc)
28492841
return rc;
28502842
}
28512843

28522844
if (tcon->posix_extensions) {
2853-
if (n_iov > 2) {
2854-
struct create_context *ccontext =
2855-
(struct create_context *)iov[n_iov-1].iov_base;
2856-
ccontext->Next =
2857-
cpu_to_le32(iov[n_iov-1].iov_len);
2858-
}
2859-
28602845
rc = add_posix_context(iov, &n_iov, oparms->mode);
28612846
if (rc)
28622847
return rc;
28632848
}
28642849

28652850
if (tcon->snapshot_time) {
28662851
cifs_dbg(FYI, "adding snapshot context\n");
2867-
if (n_iov > 2) {
2868-
struct create_context *ccontext =
2869-
(struct create_context *)iov[n_iov-1].iov_base;
2870-
ccontext->Next =
2871-
cpu_to_le32(iov[n_iov-1].iov_len);
2872-
}
2873-
28742852
rc = add_twarp_context(iov, &n_iov, tcon->snapshot_time);
28752853
if (rc)
28762854
return rc;
@@ -2894,24 +2872,13 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
28942872
set_owner = false;
28952873

28962874
if (set_owner | set_mode) {
2897-
if (n_iov > 2) {
2898-
struct create_context *ccontext =
2899-
(struct create_context *)iov[n_iov-1].iov_base;
2900-
ccontext->Next = cpu_to_le32(iov[n_iov-1].iov_len);
2901-
}
2902-
29032875
cifs_dbg(FYI, "add sd with mode 0x%x\n", oparms->mode);
29042876
rc = add_sd_context(iov, &n_iov, oparms->mode, set_owner);
29052877
if (rc)
29062878
return rc;
29072879
}
29082880
}
29092881

2910-
if (n_iov > 2) {
2911-
struct create_context *ccontext =
2912-
(struct create_context *)iov[n_iov-1].iov_base;
2913-
ccontext->Next = cpu_to_le32(iov[n_iov-1].iov_len);
2914-
}
29152882
add_query_id_context(iov, &n_iov);
29162883

29172884
if (n_iov > 2) {
@@ -2922,6 +2889,15 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
29222889
req->CreateContextsOffset = cpu_to_le32(
29232890
sizeof(struct smb2_create_req) +
29242891
iov[1].iov_len);
2892+
2893+
for (unsigned int i = 2; i < (n_iov-1); i++) {
2894+
struct kvec *v = &iov[i];
2895+
size_t len = v->iov_len;
2896+
struct create_context *cctx =
2897+
(struct create_context *)v->iov_base;
2898+
2899+
cctx->Next = cpu_to_le32(len);
2900+
}
29252901
}
29262902

29272903
rqst->rq_nvec = n_iov;

0 commit comments

Comments
 (0)