Skip to contentSkip to conversation

ksmbd: request update to stale share config

PATCH In review atheik 2 participants 5 messages Aug 8, 2022 – Aug 10, 2022

Subsystems (3)
lore
Share & tools
lore

atheik

author
#0 lore raw

PATCH v2 1/3 ksmbd: request update to stale share config

ksmbd_share_config_get() retrieves the cached share config as long as there is at least one connection to the share. This is an issue when the user space utilities are used to update share configs. In that case there is a need to inform ksmbd that it should not use the cached share config for a new connection to the share. With these changes the tree connection flag KSMBD_TREE_CONN_FLAG_UPDATE indicates this. When this flag is set, ksmbd removes the share config from the shares hash table meaning that ksmbd_share_config_get() ends up requesting a share config from user space.

---
 fs/ksmbd/ksmbd_netlink.h     |  2 ++
 fs/ksmbd/mgmt/share_config.c |  6 +++++-
 fs/ksmbd/mgmt/share_config.h |  1 +
 fs/ksmbd/mgmt/tree_connect.c | 14 ++++++++++++++
 fs/ksmbd/smb2pdu.c           |  1 +
 5 files changed, 23 insertions(+), 1 deletion(-)
fs/ksmbd/ksmbd_netlink.h +2 -0
index 52aa0adeb951..a3211c55b01f 100644
@@ -349,6 +349,7 @@ enum KSMBD_TREE_CONN_STATUS {
 #define KSMBD_SHARE_FLAG_STREAMS		BIT(11)
 #define KSMBD_SHARE_FLAG_FOLLOW_SYMLINKS	BIT(12)
 #define KSMBD_SHARE_FLAG_ACL_XATTR		BIT(13)
+#define KSMBD_SHARE_FLAG_UPDATE 		BIT(14)
 
 /*
  * Tree connect request flags.
@@ -364,6 +365,7 @@ enum KSMBD_TREE_CONN_STATUS {
 #define KSMBD_TREE_CONN_FLAG_READ_ONLY		BIT(1)
 #define KSMBD_TREE_CONN_FLAG_WRITABLE		BIT(2)
 #define KSMBD_TREE_CONN_FLAG_ADMIN_ACCOUNT	BIT(3)
+#define KSMBD_TREE_CONN_FLAG_UPDATE		BIT(4)
 
 /*
  * RPC over IPC.
fs/ksmbd/mgmt/share_config.c +5 -1
index 70655af93b44..c9bca1c2c834 100644
@@ -51,12 +51,16 @@ static void kill_share(struct ksmbd_share_config *share)
 	kfree(share);
 }
 
-void __ksmbd_share_config_put(struct ksmbd_share_config *share)
+void ksmbd_share_config_del(struct ksmbd_share_config *share)
 {
 	down_write(&shares_table_lock);
 	hash_del(&share->hlist);
 	up_write(&shares_table_lock);
+}
 
+void __ksmbd_share_config_put(struct ksmbd_share_config *share)
+{
+	ksmbd_share_config_del(share);
 	kill_share(share);
 }
 
fs/ksmbd/mgmt/share_config.h +1 -0
index 28bf3511763f..902f2cb1963a 100644
@@ -64,6 +64,7 @@ static inline int test_share_config_flag(struct ksmbd_share_config *share,
 	return share->flags & flag;
 }
 
+void ksmbd_share_config_del(struct ksmbd_share_config *share);
 void __ksmbd_share_config_put(struct ksmbd_share_config *share);
 
 static inline void ksmbd_share_config_put(struct ksmbd_share_config *share)
fs/ksmbd/mgmt/tree_connect.c +14 -0
index dd262daa2c4a..97ab7987df6e 100644
@@ -57,6 +57,20 @@ ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess,
 		goto out_error;
 
 	tree_conn->flags = resp->connection_flags;
+	if (test_tree_conn_flag(tree_conn, KSMBD_TREE_CONN_FLAG_UPDATE)) {
+		struct ksmbd_share_config *new_sc;
+
+		ksmbd_share_config_del(sc);
+		new_sc = ksmbd_share_config_get(share_name);
+		if (!new_sc) {
+			pr_err("Failed to update stale share config\n");
+			status.ret = -ESTALE;
+			goto out_error;
+		}
+		ksmbd_share_config_put(sc);
+		sc = new_sc;
+	}
+
 	tree_conn->user = sess->user;
 	tree_conn->share_conf = sc;
 	status.tree_conn = tree_conn;
fs/ksmbd/smb2pdu.c +1 -0
index 1f9a2cda0c58..b5c36657ecfd 100644
@@ -1944,6 +1944,7 @@ int smb2_tree_connect(struct ksmbd_work *work)
 		rsp->hdr.Status = STATUS_SUCCESS;
 		rc = 0;
 		break;
+	case -ESTALE:
 	case -ENOENT:
 	case KSMBD_TREE_CONN_STATUS_NO_SHARE:
 		rsp->hdr.Status = STATUS_BAD_NETWORK_NAME;
Signature · 1 line
2.37.1
author
#1 lore raw

PATCH v2 2/3 ksmbd-tools: cleanup config group handling

Rename cp_add_ipc_share() to cp_add_ipc_group() in order to better describe its purpose. Use the ipc_group global variable so as to get rid of the group name comparison in groups_callback(). Keep track of used groups callback mode by saving it per-group. Move global group checks to global_conf_* functions.

---
 include/config_parser.h |  5 +++
 lib/config_parser.c     | 95 +++++++++++++++++++++++------------------
 2 files changed, 59 insertions(+), 41 deletions(-)
include/config_parser.h +5 -0
index b6c49b9..43212c8 100644
@@ -10,7 +10,12 @@
 
 #include <glib.h>
 
+#define GROUPS_CALLBACK_NONE	(0)
+#define GROUPS_CALLBACK_INIT	(1 << 0)
+#define GROUPS_CALLBACK_REINIT	(1 << 1)
+
 struct smbconf_group {
+	unsigned short		cb_mode;
 	char			*name;
 	GHashTable		*kv;
 };
lib/config_parser.c +54 -41

166 lines not on this page · raw message

Signature · 1 line
2.37.1
author
#2 lore raw

PATCH v2 3/3 ksmbd-tools: inform ksmbd of stale share config

In reply to atheik

When initializing a share from a group, flag the share with KSMBD_SHARE_FLAG_UPDATE if the group callback mode denotes that the config file was reloaded. If the share was flagged, then later when handling a tree connect request, flag the connection with KSMBD_TREE_CONN_FLAG_UPDATE to inform ksmbd that its cached share config is stale. If there are no failures when handling the request, remove the share flag.

---
 include/linux/ksmbd_server.h | 2 ++
 lib/management/share.c       | 3 +++
 lib/management/tree_conn.c   | 8 +++++++-
 3 files changed, 12 insertions(+), 1 deletion(-)
include/linux/ksmbd_server.h +2 -0
index 6705dac..7e86d5d 100644
@@ -235,6 +235,7 @@ enum KSMBD_TREE_CONN_STATUS {
 #define KSMBD_SHARE_FLAG_STREAMS		(1 << 11)
 #define KSMBD_SHARE_FLAG_FOLLOW_SYMLINKS	(1 << 12)
 #define KSMBD_SHARE_FLAG_ACL_XATTR		(1 << 13)
+#define KSMBD_SHARE_FLAG_UPDATE 		(1 << 14)
 
 /*
  * Tree connect request flags.
@@ -250,6 +251,7 @@ enum KSMBD_TREE_CONN_STATUS {
 #define KSMBD_TREE_CONN_FLAG_READ_ONLY		(1 << 1)
 #define KSMBD_TREE_CONN_FLAG_WRITABLE		(1 << 2)
 #define KSMBD_TREE_CONN_FLAG_ADMIN_ACCOUNT	(1 << 3)
+#define KSMBD_TREE_CONN_FLAG_UPDATE		(1 << 4)
 
 /*
  * RPC over IPC.
lib/management/share.c +3 -0
index acd6d3f..e9492b5 100644
@@ -605,6 +605,9 @@ static void init_share_from_group(struct ksmbd_share *share,
 	if (!g_ascii_strcasecmp(share->name, "ipc$"))
 		set_share_flag(share, KSMBD_SHARE_FLAG_PIPE);
 
+	if (group->cb_mode == GROUPS_CALLBACK_REINIT)
+		set_share_flag(share, KSMBD_SHARE_FLAG_UPDATE);
+
 	g_hash_table_foreach(group->kv, process_group_kv, share);
 
 	fixup_missing_fields(share);
lib/management/tree_conn.c +7 -1
index 10304d1..f5c5749 100644
@@ -73,6 +73,8 @@ int tcm_handle_tree_connect(struct ksmbd_tree_connect_request *req,
 		set_conn_flag(conn, KSMBD_TREE_CONN_FLAG_WRITABLE);
 	if (test_share_flag(share, KSMBD_SHARE_FLAG_READONLY))
 		set_conn_flag(conn, KSMBD_TREE_CONN_FLAG_READ_ONLY);
+	if (test_share_flag(share, KSMBD_SHARE_FLAG_UPDATE))
+		set_conn_flag(conn, KSMBD_TREE_CONN_FLAG_UPDATE);
 
 	if (shm_open_connection(share)) {
 		resp->status = KSMBD_TREE_CONN_STATUS_TOO_MANY_CONNS;
@@ -207,8 +209,12 @@ bind:
 		tcm_tree_conn_free(conn);
 		put_ksmbd_user(user);
 	}
+
+	g_rw_lock_writer_lock(&share->update_lock);
+	clear_share_flag(share, KSMBD_SHARE_FLAG_UPDATE);
+	g_rw_lock_writer_unlock(&share->update_lock);
+
 	return 0;
-
 out_error:
 	tcm_tree_conn_free(conn);
 	shm_close_connection(share);
Signature · 1 line
2.37.1
maintainer
#3 lore raw

Re: [PATCH v2 3/3] ksmbd-tools: inform ksmbd of stale share config

2022-08-09 7:02 GMT+09:00, atheik <[email protected]>:

Quoted 9 lines

When initializing a share from a group, flag the share with KSMBD_SHARE_FLAG_UPDATE if the group callback mode denotes that the config file was reloaded. If the share was flagged, then later when handling a tree connect request, flag the connection with KSMBD_TREE_CONN_FLAG_UPDATE to inform ksmbd that its cached share config is stale. If there are no failures when handling the request, remove the share flag.

Applied 2/3, 3/3 patches.

Thanks!

maintainer Acked-by on v2 1/3
#4 lore raw
In reply to atheik

2022-08-09 7:02 GMT+09:00, atheik <[email protected]>:

Quoted 11 lines

ksmbd_share_config_get() retrieves the cached share config as long as there is at least one connection to the share. This is an issue when the user space utilities are used to update share configs. In that case there is a need to inform ksmbd that it should not use the cached share config for a new connection to the share. With these changes the tree connection flag KSMBD_TREE_CONN_FLAG_UPDATE indicates this. When this flag is set, ksmbd removes the share config from the shares hash table meaning that ksmbd_share_config_get() ends up requesting a share config from user space.

Thanks for your patch!