diff mbox series

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

Message ID 20220808024341.63913-3-atteh.mailbox@gmail.com (mailing list archive)
State New, archived
Headers show
Series [1/3] ksmbd: request update to stale share config | expand

Commit Message

Atte Heikkilä Aug. 8, 2022, 2:43 a.m. UTC
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.

Signed-off-by: Atte Heikkilä <atteh.mailbox@gmail.com>
---
 include/linux/ksmbd_server.h | 2 ++
 lib/management/share.c       | 3 +++
 lib/management/tree_conn.c   | 8 +++++++-
 3 files changed, 12 insertions(+), 1 deletion(-)

Comments

Hyunchul Lee Aug. 8, 2022, 5:19 a.m. UTC | #1
2022년 8월 8일 (월) 오전 11:47, atheik <atteh.mailbox@gmail.com>님이 작성:
>
> 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.
>
> Signed-off-by: Atte Heikkilä <atteh.mailbox@gmail.com>

Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>

> ---
>  include/linux/ksmbd_server.h | 2 ++
>  lib/management/share.c       | 3 +++
>  lib/management/tree_conn.c   | 8 +++++++-
>  3 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/ksmbd_server.h b/include/linux/ksmbd_server.h
> index 6705dac..7e86d5d 100644
> --- a/include/linux/ksmbd_server.h
> +++ b/include/linux/ksmbd_server.h
> @@ -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.
> diff --git a/lib/management/share.c b/lib/management/share.c
> index acd6d3f..e9492b5 100644
> --- a/lib/management/share.c
> +++ b/lib/management/share.c
> @@ -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);
> diff --git a/lib/management/tree_conn.c b/lib/management/tree_conn.c
> index 10304d1..f5c5749 100644
> --- a/lib/management/tree_conn.c
> +++ b/lib/management/tree_conn.c
> @@ -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);
> --
> 2.37.1
>
diff mbox series

Patch

diff --git a/include/linux/ksmbd_server.h b/include/linux/ksmbd_server.h
index 6705dac..7e86d5d 100644
--- a/include/linux/ksmbd_server.h
+++ b/include/linux/ksmbd_server.h
@@ -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.
diff --git a/lib/management/share.c b/lib/management/share.c
index acd6d3f..e9492b5 100644
--- a/lib/management/share.c
+++ b/lib/management/share.c
@@ -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);
diff --git a/lib/management/tree_conn.c b/lib/management/tree_conn.c
index 10304d1..f5c5749 100644
--- a/lib/management/tree_conn.c
+++ b/lib/management/tree_conn.c
@@ -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);