From: Volker Lendecke <vl@samba.org>
Date: Thu, 30 Mar 2023 12:04:46 +0000
Subject: [PATCH] cifs: Simplify SMB2_open_init()
Git-commit: 2a8d1387ed985341364b471ad63e323431ef6c4a
References: bsc#1193629
Patch-mainline: v6.4-rc1
Reduce code duplication by stitching together create contexts in one
place.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Enzo Matsumiya <ematsumiya@suse.de>
Signed-off-by: Steve French <stfrench@microsoft.com>
Acked-by: Paulo Alcantara <palcantara@suse.de>
---
fs/cifs/smb2pdu.c | 43 ++++++++++---------------------------------
1 file changed, 10 insertions(+), 33 deletions(-)
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2835,14 +2835,6 @@ SMB2_open_init(struct cifs_tcon *tcon, s
}
if (*oplock == SMB2_OPLOCK_LEVEL_BATCH) {
- /* need to set Next field of lease context if we request it */
- if (server->capabilities & SMB2_GLOBAL_CAP_LEASING) {
- struct create_context *ccontext =
- (struct create_context *)iov[n_iov-1].iov_base;
- ccontext->Next =
- cpu_to_le32(server->vals->create_lease_size);
- }
-
rc = add_durable_context(iov, &n_iov, oparms,
tcon->use_persistent);
if (rc)
@@ -2850,13 +2842,6 @@ SMB2_open_init(struct cifs_tcon *tcon, s
}
if (tcon->posix_extensions) {
- if (n_iov > 2) {
- struct create_context *ccontext =
- (struct create_context *)iov[n_iov-1].iov_base;
- ccontext->Next =
- cpu_to_le32(iov[n_iov-1].iov_len);
- }
-
rc = add_posix_context(iov, &n_iov, oparms->mode);
if (rc)
return rc;
@@ -2864,13 +2849,6 @@ SMB2_open_init(struct cifs_tcon *tcon, s
if (tcon->snapshot_time) {
cifs_dbg(FYI, "adding snapshot context\n");
- if (n_iov > 2) {
- struct create_context *ccontext =
- (struct create_context *)iov[n_iov-1].iov_base;
- ccontext->Next =
- cpu_to_le32(iov[n_iov-1].iov_len);
- }
-
rc = add_twarp_context(iov, &n_iov, tcon->snapshot_time);
if (rc)
return rc;
@@ -2894,12 +2872,6 @@ SMB2_open_init(struct cifs_tcon *tcon, s
set_owner = false;
if (set_owner | set_mode) {
- if (n_iov > 2) {
- struct create_context *ccontext =
- (struct create_context *)iov[n_iov-1].iov_base;
- ccontext->Next = cpu_to_le32(iov[n_iov-1].iov_len);
- }
-
cifs_dbg(FYI, "add sd with mode 0x%x\n", oparms->mode);
rc = add_sd_context(iov, &n_iov, oparms->mode, set_owner);
if (rc)
@@ -2907,14 +2879,10 @@ SMB2_open_init(struct cifs_tcon *tcon, s
}
}
- if (n_iov > 2) {
- struct create_context *ccontext =
- (struct create_context *)iov[n_iov-1].iov_base;
- ccontext->Next = cpu_to_le32(iov[n_iov-1].iov_len);
- }
add_query_id_context(iov, &n_iov);
if (n_iov > 2) {
+ unsigned int i;
/*
* We have create contexts behind iov[1] (the file
* name), point at them from the main create request
@@ -2922,6 +2890,15 @@ SMB2_open_init(struct cifs_tcon *tcon, s
req->CreateContextsOffset = cpu_to_le32(
sizeof(struct smb2_create_req) +
iov[1].iov_len);
+
+ for (i = 2; i < (n_iov-1); i++) {
+ struct kvec *v = &iov[i];
+ size_t len = v->iov_len;
+ struct create_context *cctx =
+ (struct create_context *)v->iov_base;
+
+ cctx->Next = cpu_to_le32(len);
+ }
}
rqst->rq_nvec = n_iov;