Skip to contentSkip to conversation

cifs: add version-specific operations containers

PATCH New Jeff Layton 1 participant 4 messages May 11, 2012 1 message not in the archive

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

cover cifs: add version-specific operations containers

Pavel asked me to sent this set to the list. It's not a complete set of patches that do anything useful yet, but it does add some infrastructure to allow the building of an SMB2 filesystem. It adds better handling for the ver= mount option and adds a version specific struct that hangs off the TCP_Server_Info.

Note that I've not done much more than compile test this patch, so consider it an RFC. Those who are working on SMB2 (mostly Pavel and Steve at this point) are welcome to take these patches and use them if you think it reasonable.

I imagine the last patch in the series will need to be respun at some point. Changing out the send_cancel is probably better suited later on after adding operations for some of the more basic functionality. I only singled that one out since it was easy to use it to demonstrate how you'd use smb_version_operations.

Jeff Layton (3):
cifs: add a smb_version_operations struct and a smb_version enum
cifs: add ver=2.1 option support
cifs: convert send_nt_cancel into a version specific op

 fs/cifs/Makefile    |    4 ++-
 fs/cifs/cifsfs.c    |    1 +
 fs/cifs/cifsglob.h  |   19 ++++++++++++++-
 fs/cifs/connect.c   |   46 +++++++++++++++++++++++++++++-------
 fs/cifs/smb1ops.c   |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/cifs/smb2ops.c   |   24 +++++++++++++++++++
 fs/cifs/transport.c |   45 ++++++-----------------------------
 7 files changed, 155 insertions(+), 48 deletions(-)
 create mode 100644 fs/cifs/smb1ops.c
 create mode 100644 fs/cifs/smb2ops.c
Signature · 1 line
1.7.7.6
#2 lore raw

PATCH 1/3 cifs: add a smb_version_operations struct and a smb_version enum

In reply to a message not in the archive

We need a way to dispatch different operations for different versions. Behold the smb_version_operations struct. For now, that struct just holds the version enum and nothing uses it. Eventually, we'll expand this to cover other operations as we change the callers to dispatch from here.

Note too that this patch eliminates "ver=cifs" as an option. No userspace program ever sent that syntax, and it would be best not to establish it as valid if we can help it.

---
 fs/cifs/Makefile   |    2 +-
 fs/cifs/cifsfs.c   |    1 +
 fs/cifs/cifsglob.h |   12 ++++++++++++
 fs/cifs/connect.c  |   40 +++++++++++++++++++++++++++++++---------
 fs/cifs/smb1ops.c  |   24 ++++++++++++++++++++++++
 5 files changed, 69 insertions(+), 10 deletions(-)
 create mode 100644 fs/cifs/smb1ops.c
fs/cifs/Makefile +1 -1
index 005d524..0fe7025 100644
@@ -6,7 +6,7 @@ obj-$(CONFIG_CIFS) += cifs.o
 cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
 	  link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \
 	  cifs_unicode.o nterr.o xattr.o cifsencrypt.o \
-	  readdir.o ioctl.o sess.o export.o
+	  readdir.o ioctl.o sess.o export.o smb1ops.o
 
 cifs-$(CONFIG_CIFS_ACL) += cifsacl.o
 
fs/cifs/cifsfs.c +1 -0
index fd033f0..d62779f 100644
@@ -356,6 +356,7 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
 	struct sockaddr *srcaddr;
 	srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
 
+	seq_printf(s, ",ver=%s", tcon->ses->server->ops->version_string);
 	cifs_show_security(s, tcon->ses->server);
 	cifs_show_cache_flavor(s, cifs_sb);
 
fs/cifs/cifsglob.h +12 -0
index a867d99..64a9085 100644
@@ -150,6 +150,14 @@ struct cifs_cred {
  *****************************************************************
  */
 
+enum smb_version {
+	Smb_1 = 1,
+};
+
+struct smb_version_operations {
+	char		*version_string;
+};
+
 struct smb_vol {
 	char *username;
 	char *password;
@@ -205,6 +213,7 @@ struct smb_vol {
 	bool sockopt_tcp_nodelay:1;
 	unsigned short int port;
 	unsigned long actimeo; /* attribute cache timeout (jiffies) */
+	struct smb_version_operations *ops;
 	char *prepath;
 	struct sockaddr_storage srcaddr; /* allow binding to a local IP */
 	struct nls_table *local_nls;
@@ -242,6 +251,7 @@ struct TCP_Server_Info {
 	int srv_count; /* reference counter */
 	/* 15 character server name + 0x20 16th byte indicating type = srv */
 	char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
+	struct smb_version_operations	*ops;
 	enum statusEnum tcpStatus; /* what we think the status is */
 	char *hostname; /* hostname portion of UNC string */
 	struct socket *ssocket;
@@ -1069,4 +1079,6 @@ void cifs_oplock_break(struct work_struct *work);
 extern const struct slow_work_ops cifs_oplock_break_ops;
 extern struct workqueue_struct *cifsiod_wq;
 
+/* Operations for different SMB versions */
+extern struct smb_version_operations smb1_version_operations;
 #endif	/* _CIFS_GLOB_H */
fs/cifs/connect.c +31 -9
index a6c9a6a..0f1be6f 100644
@@ -278,6 +278,10 @@ static const match_table_t cifs_cacheflavor_tokens = {
 	{ Opt_cache_err, NULL }
 };
 
+static const match_table_t cifs_smb_version_tokens = {
+	{ Smb_1, "1" },
+};
+
 static int ip_connect(struct TCP_Server_Info *server);
 static int generic_ip_connect(struct TCP_Server_Info *server);
 static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
@@ -1241,6 +1245,22 @@ cifs_parse_cache_flavor(char *value, struct smb_vol *vol)
 }
 
 static int
+cifs_parse_smb_version(char *value, struct smb_vol *vol)
+{
+	substring_t args[MAX_OPT_ARGS];
+
+	switch (match_token(value, cifs_smb_version_tokens, args)) {
+	case Smb_1:
+		vol->ops = &smb1_version_operations;
+		break;
+	default:
+		cERROR(1, "Unknown ver= option specified: %s", value);
+		return 1;
+	}
+	return 0;
+}
+
+static int
 cifs_parse_mount_options(const char *mountdata, const char *devname,
 			 struct smb_vol *vol)
 {
@@ -1293,6 +1313,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 
 	vol->actimeo = CIFS_DEF_ACTIMEO;
 
+	/* FIXME: add autonegotiation -- for now, SMB1 is default */
+	vol->ops = &smb1_version_operations;
+
 	if (!mountdata)
 		goto cifs_parse_mount_err;
 
@@ -1895,15 +1918,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 			if (string == NULL)
 				goto out_nomem;
 
-			if (strnicmp(string, "cifs", 4) == 0 ||
-			    strnicmp(string, "1", 1) == 0) {
-				/* This is the default */
-				break;
-			}
-			/* For all other value, error */
-			printk(KERN_WARNING "CIFS: Invalid version"
-					    " specified\n");
-			goto cifs_parse_mount_err;
+			if (cifs_parse_smb_version(string, vol) != 0)
+				goto cifs_parse_mount_err;
+			break;
 		case Opt_sec:
 			string = match_strdup(args);
 			if (string == NULL)
@@ -2132,6 +2149,9 @@ match_security(struct TCP_Server_Info *server, struct smb_vol *vol)
 static int match_server(struct TCP_Server_Info *server, struct sockaddr *addr,
 			 struct smb_vol *vol)
 {
+	if (server->ops != vol->ops)
+		return 0;
+
 	if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns))
 		return 0;
 
@@ -2254,6 +2274,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
 		goto out_err;
 	}
 
+	tcp_ses->ops = volume_info->ops;
 	cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns));
 	tcp_ses->hostname = extract_hostname(volume_info->UNC);
 	if (IS_ERR(tcp_ses->hostname)) {
@@ -3660,6 +3681,7 @@ cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
 	if (cifs_parse_mount_options(mount_data, devname, volume_info))
 		return -EINVAL;
 
+
 	if (volume_info->nullauth) {
 		cFYI(1, "Anonymous login");
 		kfree(volume_info->username);
fs/cifs/smb1ops.c new file +24 -0
new file mode 100644
index 0000000..5237591
@@ -0,0 +1,24 @@
+/*
+ *  SMB1 (CIFS) version specific operations
+ *
+ *  Copyright (c) 2012, Jeff Layton <[email protected]>
+ *
+ *  This library is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License v2 as published
+ *  by the Free Software Foundation.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *  the GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "cifsglob.h"
+
+struct smb_version_operations smb1_version_operations = {
+	.version_string = "1",
+};
Signature · 1 line
1.7.7.6
#3 lore raw

PATCH 2/3 cifs: add ver=2.1 option support

In reply to a message not in the archive

Have ver=2.1 set the server->ops struct to one for SMB2.1

In this patch I'm avoiding the ambiguous "ver=2" syntax since it's not clear what specific version you're actually selecting in that case.

---
 fs/cifs/Makefile   |    2 ++
 fs/cifs/cifsglob.h |    2 ++
 fs/cifs/connect.c  |    6 ++++++
 fs/cifs/smb2ops.c  |   24 ++++++++++++++++++++++++
 4 files changed, 34 insertions(+), 0 deletions(-)
 create mode 100644 fs/cifs/smb2ops.c
fs/cifs/Makefile +2 -0
index 0fe7025..4b41275 100644
@@ -15,3 +15,5 @@ cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o
 cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o
 
 cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o
+
+cifs-$(CONFIG_CIFS_SMB2) += smb2ops.o
fs/cifs/cifsglob.h +2 -0
index 64a9085..3eae273 100644
@@ -152,6 +152,7 @@ struct cifs_cred {
 
 enum smb_version {
 	Smb_1 = 1,
+	Smb_21,
 };
 
 struct smb_version_operations {
@@ -1081,4 +1082,5 @@ extern struct workqueue_struct *cifsiod_wq;
 
 /* Operations for different SMB versions */
 extern struct smb_version_operations smb1_version_operations;
+extern struct smb_version_operations smb21_version_operations;
 #endif	/* _CIFS_GLOB_H */
fs/cifs/connect.c +6 -0
index 0f1be6f..e51a0a2 100644
@@ -280,6 +280,7 @@ static const match_table_t cifs_cacheflavor_tokens = {
 
 static const match_table_t cifs_smb_version_tokens = {
 	{ Smb_1, "1" },
+	{ Smb_21, "2.1" },
 };
 
 static int ip_connect(struct TCP_Server_Info *server);
@@ -1253,6 +1254,11 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol)
 	case Smb_1:
 		vol->ops = &smb1_version_operations;
 		break;
+#ifdef CONFIG_CIFS_SMB2
+	case Smb_21:
+		vol->ops = &smb21_version_operations;
+		break;
+#endif
 	default:
 		cERROR(1, "Unknown ver= option specified: %s", value);
 		return 1;
fs/cifs/smb2ops.c new file +24 -0
new file mode 100644
index 0000000..2ac672e
@@ -0,0 +1,24 @@
+/*
+ *  SMB2 version specific operations
+ *
+ *  Copyright (c) 2012, Jeff Layton <[email protected]>
+ *
+ *  This library is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License v2 as published
+ *  by the Free Software Foundation.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *  the GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "cifsglob.h"
+
+struct smb_version_operations smb21_version_operations = {
+	.version_string = "2.1",
+};
Signature · 1 line
1.7.7.6
#4 lore raw

PATCH 3/3 cifs: convert send_nt_cancel into a version specific op

In reply to a message not in the archive

For SMB2, this should be a no-op. Obviously if we wanted to do something for the SMB2 case, we could also define an operation here for it.

---
 fs/cifs/cifsglob.h  |    5 ++++-
 fs/cifs/smb1ops.c   |   40 ++++++++++++++++++++++++++++++++++++++++
 fs/cifs/transport.c |   45 ++++++++-------------------------------------
 3 files changed, 52 insertions(+), 38 deletions(-)
fs/cifs/cifsglob.h +4 -1
index 3eae273..fcf3f91 100644
@@ -155,8 +155,12 @@ enum smb_version {
 	Smb_21,
 };
 
+struct mid_q_entry;
+struct TCP_Server_Info;
+
 struct smb_version_operations {
 	char		*version_string;
+	int (*send_cancel)(struct TCP_Server_Info *server, struct smb_hdr *in_buf, struct mid_q_entry *mid);
 };
 
 struct smb_vol {
@@ -714,7 +718,6 @@ static inline void cifs_stats_bytes_read(struct cifs_tcon *tcon,
 
 #endif
 
-struct mid_q_entry;
 
 /*
  * This is the prototype for the mid receive function. This function is for
fs/cifs/smb1ops.c +40 -0
index 5237591..033984b 100644
@@ -18,7 +18,47 @@
  */
 
 #include "cifsglob.h"
+#include "cifsproto.h"
+#include "cifs_debug.h"
+
+/*
+ * An NT cancel request header looks just like the original request except:
+ *
+ * The Command is SMB_COM_NT_CANCEL
+ * The WordCount is zeroed out
+ * The ByteCount is zeroed out
+ *
+ * This function mangles an existing request buffer into a
+ * SMB_COM_NT_CANCEL request and then sends it.
+ */
+static int
+send_nt_cancel(struct TCP_Server_Info *server, struct smb_hdr *in_buf,
+		struct mid_q_entry *mid)
+{
+	int rc = 0;
+
+	/* -4 for RFC1001 length and +2 for BCC field */
+	in_buf->smb_buf_length = cpu_to_be32(sizeof(struct smb_hdr) - 4  + 2);
+	in_buf->Command = SMB_COM_NT_CANCEL;
+	in_buf->WordCount = 0;
+	put_bcc(0, in_buf);
+
+	mutex_lock(&server->srv_mutex);
+	rc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
+	if (rc) {
+		mutex_unlock(&server->srv_mutex);
+		return rc;
+	}
+	rc = smb_send(server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
+	mutex_unlock(&server->srv_mutex);
+
+	cFYI(1, "issued NT_CANCEL for mid %u, rc = %d",
+		in_buf->Mid, rc);
+
+	return rc;
+}
 
 struct smb_version_operations smb1_version_operations = {
 	.version_string = "1",
+	.send_cancel = send_nt_cancel,
 };
fs/cifs/transport.c +8 -37

77 lines not on this page · raw message

Signature · 1 line
1.7.7.6