Skip to contentSkip to conversation

Helper functions for smb2 compound ops

PATCH Volker Lendecke 2 participants 3 messages Mar 19, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello!

This is not a formal patchset, more a request for comments.

In fs/cifs when doing compound operations I see a lot of fiddly boilerplate code. Attached find a little patchset that introduces a struct smb2_compound_op capturing most of that boilerplate code, along with a few sample uses.

Is that worth exploring further?

Thanks,

Volker

From 171cceab65b87153d165ffb86c7bd218facb3e51 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <[email protected]>
Date: Sun, 19 Mar 2023 16:53:18 +0100
Subject: [PATCH 1/6] cifs: Add required includes to cifsfs.h

struct file and a few others are referenced in prototypes.

---
 fs/cifs/cifsfs.h | 3 +++
 1 file changed, 3 insertions(+)
fs/cifs/cifsfs.h +3 -0
index 71fe0a0a7992..23391162391e 100644
@@ -9,6 +9,9 @@
 #ifndef _CIFSFS_H
 #define _CIFSFS_H
 
+#include <linux/dcache.h>
+#include <linux/fs.h>
+
 #include <linux/hash.h>
 
 #define ROOT_I 2
Signature · 18 lines
2.30.2


From ab37ec994a2d6f5e98760b85c3cb31582676e322 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <[email protected]>
Date: Sun, 19 Mar 2023 16:54:50 +0100
Subject: [PATCH 2/6] cifs: Add struct smb2_compound_op

Infrastructure to make handling of open/<op>/close easier

Signed-off-by: Volker Lendecke <[email protected]>
---
 fs/cifs/Makefile       |   1 +
 fs/cifs/smb2compound.c | 200 +++++++++++++++++++++++++++++++++++++++++
 fs/cifs/smb2compound.h |  33 +++++++
 3 files changed, 234 insertions(+)
 create mode 100644 fs/cifs/smb2compound.c
 create mode 100644 fs/cifs/smb2compound.h
fs/cifs/Makefile +1 -0
index 304a7f6cc13a..ece58d2e3712 100644
@@ -10,6 +10,7 @@ cifs-y := trace.o cifsfs.o cifs_debug.o connect.o dir.o file.o \
 	  cached_dir.o cifs_unicode.o nterr.o cifsencrypt.o \
 	  readdir.o ioctl.o sess.o export.o unc.o winucase.o \
 	  smb2ops.o smb2maperror.o smb2transport.o \
+	  smb2compound.o \
 	  smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifsacl.o fs_context.o \
 	  dns_resolve.o cifs_spnego_negtokeninit.asn1.o asn1.o
 
fs/cifs/smb2compound.c new file +200 -0

200 lines not on this page · raw message

fs/cifs/smb2compound.h new file +33 -0
new file mode 100644
index 000000000000..0a4116ef32ba
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: LGPL-2.1 */
+/*
+ *  Copyright (c) 2023, Volker Lendecke <[email protected]>
+ */
+
+struct smb2_compound_op {
+	struct cifs_fid fid;
+	int num_rqst;
+	struct smb_rqst *rqst;
+	struct kvec *rqst_iov;
+	int *resp_buftype;
+	struct kvec *rsp_iov;
+};
+
+struct smb2_compound_op *smb2_compound_op_init(bool openclose,
+					       int num_ops,
+					       int *num_rqst_iovs,
+					       int *op_idx);
+
+void smb2_compound_op_free(struct smb2_compound_op *op);
+
+int smb2_compound_openclose(struct smb2_compound_op *op,
+			    struct cifs_sb_info *cifs_sb,
+			    struct cifs_tcon *tcon,
+			    struct TCP_Server_Info *server,
+			    __u8 *oplock, struct cifs_open_parms *oparms,
+			    const char *path);
+
+int smb2_compound_send_recv(const unsigned int xid,
+			    struct cifs_tcon *tcon,
+			    struct cifs_ses *ses,
+			    struct TCP_Server_Info *server,
+			    struct smb2_compound_op *op);
Signature · 14 lines
2.30.2


From a6deeaeddba1be71d8feca93579bbd128db682c3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <[email protected]>
Date: Sun, 19 Mar 2023 16:25:07 +0100
Subject: [PATCH 3/6] cifs: Use smb2_compound_op in smb2_query_info_compound

Remove special-case code

Signed-off-by: Volker Lendecke <[email protected]>
---
 fs/cifs/smb2ops.c | 120 +++++++++++++---------------------------------
 1 file changed, 33 insertions(+), 87 deletions(-)
fs/cifs/smb2ops.c +33 -87

160 lines not on this page · raw message

Signature · 15 lines
2.30.2


From c22a9bffca9b804d838bd176785d4c886b0938d4 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <[email protected]>
Date: Sun, 19 Mar 2023 17:50:59 +0100
Subject: [PATCH 4/6] cifs: Use smb2_compound_op in smb2_unlink()

Reduce use of smb2_compound_op()

Signed-off-by: Volker Lendecke <[email protected]>
---
 fs/cifs/smb2glob.h  |  1 -
 fs/cifs/smb2inode.c | 54 +++++++++++++++++++++++++++++++++------------
 2 files changed, 40 insertions(+), 15 deletions(-)
fs/cifs/smb2glob.h +0 -1
index 82e916ad167c..d9e7c122eee5 100644
@@ -29,7 +29,6 @@
 #define SMB2_OP_QUERY_DIR 4
 #define SMB2_OP_MKDIR 5
 #define SMB2_OP_RENAME 6
-#define SMB2_OP_DELETE 7
 #define SMB2_OP_HARDLINK 8
 #define SMB2_OP_SET_EOF 9
 #define SMB2_OP_RMDIR 10
fs/cifs/smb2inode.c +40 -14

78 lines not on this page · raw message

Signature · 15 lines
2.30.2


From 71c8b6024ad6438712e0a0ab35710fa6ea7bc3f2 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <[email protected]>
Date: Sun, 19 Mar 2023 19:02:36 +0100
Subject: [PATCH 5/6] cifs: Use smb2_compound_op in smb2_set_path_size()

Avoid boilerplate code

Signed-off-by: Volker Lendecke <[email protected]>
---
 fs/cifs/smb2glob.h  |   1 -
 fs/cifs/smb2inode.c | 101 ++++++++++++++++++++++++--------------------
 2 files changed, 55 insertions(+), 47 deletions(-)
fs/cifs/smb2glob.h +0 -1
index d9e7c122eee5..897c16c4ea69 100644
@@ -30,7 +30,6 @@
 #define SMB2_OP_MKDIR 5
 #define SMB2_OP_RENAME 6
 #define SMB2_OP_HARDLINK 8
-#define SMB2_OP_SET_EOF 9
 #define SMB2_OP_RMDIR 10
 #define SMB2_OP_POSIX_QUERY_INFO 11
 
fs/cifs/smb2inode.c +55 -46

122 lines not on this page · raw message

Signature · 14 lines
2.30.2


From 35f02f7d37624e37f33eb53a4071c156a8d422a8 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <[email protected]>
Date: Sun, 19 Mar 2023 19:22:23 +0100
Subject: [PATCH 6/6] cifs: Use smb2_compound_op in smb2_query_symlink()

Avoid boilerplate code

Signed-off-by: Volker Lendecke <[email protected]>
---
 fs/cifs/smb2ops.c | 83 +++++++++--------------------------------------
 1 file changed, 16 insertions(+), 67 deletions(-)
fs/cifs/smb2ops.c +16 -67

131 lines not on this page · raw message

Signature · 1 line
2.30.2
#1 lore raw

My main worry is that it is relatively large (which can make it harder to review, and harder for Ronnie and Paulo et al to backport) but if it is the cleanest way to solve various problems, then it could be worth pursuing. Otherwise, I prefer cleanup (unless relatively small and reasonably easy to review) when it is related to fixing other problems.

The biggest problems I would like to fix are:
1) using compounding in more places (plenty of benchmarks or simple examples like gunzip, tar, rsync, to go through to look for places where network traces show compounding not being used)
2) optimizing compounding better e.g.
- "ls -l" of directory with mfsymlinks sends multiple compound
requests for every mfsymlink when only need one
- "ls" sends an extra roundtrip for 99% of cases, to send the
final querydir (which gets no more files rc ...). We should be sending "open/querydir/querydir" compound not "open/querydir")
3) ) we need to fix a few cases when we open a file in compound ops when we already have an appropriate one open
4) we request leases where appropriate for compounding sequences (e.g. open/querydir) e.g. when open sent but no close and reasonable possibility of benefiting from deferred close.
5) we set the parent lease key where possible (quoting from MS-SMB2:
"The client MUST search the GlobalFileTable for the parent directory of the file being opened. The name of the parent directory is obtained by removing the last component of the path. If any entry is found, ParentLeaseKey is obtained from File.LeaseKey of that entry and SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET bit MUST be set in the Flags field.")
6) we need to make sure we are always requesting handle leases (e.g. RWH or RH) - we have one case (cachiong directories) where we request "R" instead of "RH" and we need to make sure that we close any deferred opens (or cached dir opens) when we lose the 'H' on a lease

Quoted 15 lines · Volker Lendecke

Hello!

This is not a formal patchset, more a request for comments.

In fs/cifs when doing compound operations I see a lot of fiddly boilerplate code. Attached find a little patchset that introduces a struct smb2_compound_op capturing most of that boilerplate code, along with a few sample uses.

Is that worth exploring further?

Thanks,

Volker

Signature · 3 lines
Thanks,

Steve
#2 lore raw

Hello Steve,

the goal of struct smb2_compound_op is to make it easier to work with compound requests. In particular the existing smb2_compound_op() function in smb2inode.c is very hard to understand, let alone modify. As an example it took me really a long time to get 64ce47cb1b29d7d6aab6 right, and I still see it as a very clumsy approach. It should not be neccesary to kmemdup output deep inside this routine, but it was the only approach I could find.

To me it would be much easier if the open/qinfo/close sequence was flat in smb311_posix_query_path_info() and we could dissect the results while the response is still around.

So yes, this fs/cifs/smb2compound.c is 200 lines of code, but I think it is really simply structured code that should be easy to review.

Volker

Am Sun, Mar 19, 2023 at 02:49:09PM -0500 schrieb Steve French:

Quoted 59 lines

My main worry is that it is relatively large (which can make it harder to review, and harder for Ronnie and Paulo et al to backport) but if it is the cleanest way to solve various problems, then it could be worth pursuing. Otherwise, I prefer cleanup (unless relatively small and reasonably easy to review) when it is related to fixing other problems.

The biggest problems I would like to fix are:
1) using compounding in more places (plenty of benchmarks or simple examples like gunzip, tar, rsync, to go through to look for places where network traces show compounding not being used)
2) optimizing compounding better e.g.
- "ls -l" of directory with mfsymlinks sends multiple compound
requests for every mfsymlink when only need one
- "ls" sends an extra roundtrip for 99% of cases, to send the
final querydir (which gets no more files rc ...). We should be sending "open/querydir/querydir" compound not "open/querydir")
3) ) we need to fix a few cases when we open a file in compound ops when we already have an appropriate one open
4) we request leases where appropriate for compounding sequences (e.g. open/querydir) e.g. when open sent but no close and reasonable possibility of benefiting from deferred close.
5) we set the parent lease key where possible (quoting from MS-SMB2:
"The client MUST search the GlobalFileTable for the parent directory of the file being opened. The name of the parent directory is obtained by removing the last component of the path. If any entry is found, ParentLeaseKey is obtained from File.LeaseKey of that entry and SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET bit MUST be set in the Flags field.")
6) we need to make sure we are always requesting handle leases (e.g. RWH or RH) - we have one case (cachiong directories) where we request "R" instead of "RH" and we need to make sure that we close any deferred opens (or cached dir opens) when we lose the 'H' on a lease

Quoted 15 lines · Volker Lendecke

Hello!

This is not a formal patchset, more a request for comments.

In fs/cifs when doing compound operations I see a lot of fiddly boilerplate code. Attached find a little patchset that introduces a struct smb2_compound_op capturing most of that boilerplate code, along with a few sample uses.

Is that worth exploring further?

Thanks,

Volker

Signature · 3 lines
Thanks,

Steve