From patchwork Mon Aug 8 02:43:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Atte_Heikkil=C3=A4?= X-Patchwork-Id: 12938440 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E393C19F2A for ; Mon, 8 Aug 2022 02:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244123AbiHHCrI (ORCPT ); Sun, 7 Aug 2022 22:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244138AbiHHCqt (ORCPT ); Sun, 7 Aug 2022 22:46:49 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2526813D57 for ; Sun, 7 Aug 2022 19:44:04 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id e15so10854000lfs.0 for ; Sun, 07 Aug 2022 19:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=0G2g4+ARrzM2zKTNBhdzSazHv/st7jrSWN5Aluts6so=; b=qZfOsTc7OlvOjdFIprscH/vifayfC5uENL/kkgIXrt1J2fePRlSwpzdQVtzOnUFQFy 6hvExJVDMXxEP2m0RQIKn7OfmE+jrvF6WRyd/6n+kRKV2gWMeukV9IWlG7Yq0VjEcpMI POsoT09+ThuNOUdt+3XDBtXMBoMQgDsSRMLaNCtwMC5QtAKOGLFyMczqQZg4ehpaBqbv 0mo2HPd2itt4o/rW2K5isFHZC4RDBBljXr6//JH2R5XHcDC9o/zU8ls2Wdec4j9BdYzb /mnlTPGdHYZbg3gjaemeH4DFhEQ53d7KmimUpPAFvopAy2RDhLP4Uuq8nW5zHvqBVvTN DsYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=0G2g4+ARrzM2zKTNBhdzSazHv/st7jrSWN5Aluts6so=; b=QjTSzuE1yF5LvsNzyjpzfNuOG4r+1D7BYktXLgsXq0XSjCt6WQyBy+X7fgDfD5AAJi 4QQUhIosn+DCKKO9yzSHC/rbE+HOQ0KgxbzaTTmzrpf+uo+QAg48lvel/zUf8aT8nK4z HHa8VSYWOyygfDCu6it653718180axnfJJ2FH9ohjyCAycj1tP0HQivKYJaDeAFEPwUG DUQjI+Jxf3AgfoPRT4teNdwb41PhbcN4k/yA1/WzeH+uRQ8CiVvJ0a6ucVwEUY8akQMS cu4sGXxr8IfucRQNixviqyrG9hEUbuSkL0Ra1p6PtTqht6tB+FmrbhBo8zjlJTMQ42Bw Sgtg== X-Gm-Message-State: ACgBeo1EQ5lXw/UpAaAdPvPS5tKdTl1ZDxxVYdQYvosTHpAh+P6iXnfK i2kX8yN/U46V60Jye34s/vN0HFGaspw= X-Google-Smtp-Source: AA6agR4z0ZR3Xpk7bcO1NJPcSyuO+idiJ1a2A090OEkCI1ZvMfhV0DFaOKAgG7e4sNrJNsQic9laEw== X-Received: by 2002:a05:6512:3085:b0:48c:fcf8:18ab with SMTP id z5-20020a056512308500b0048cfcf818abmr42152lfd.113.1659926640360; Sun, 07 Aug 2022 19:44:00 -0700 (PDT) Received: from pohjola.lan (mobile-user-c1d2e4-79.dhcp.inet.fi. [193.210.228.79]) by smtp.gmail.com with ESMTPSA id v22-20020ac25596000000b0048a77a2c4b2sm1255125lfg.158.2022.08.07.19.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 19:44:00 -0700 (PDT) From: atheik To: linux-cifs@vger.kernel.org Cc: atheik Subject: [PATCH 1/3] ksmbd: request update to stale share config Date: Mon, 8 Aug 2022 05:43:39 +0300 Message-Id: <20220808024341.63913-1-atteh.mailbox@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org 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. Signed-off-by: Atte Heikkilä --- ksmbd_netlink.h | 2 ++ mgmt/share_config.c | 6 +++++- mgmt/share_config.h | 1 + mgmt/tree_connect.c | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ksmbd_netlink.h b/ksmbd_netlink.h index 192cb13..5d77b72 100644 --- a/ksmbd_netlink.h +++ b/ksmbd_netlink.h @@ -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. diff --git a/mgmt/share_config.c b/mgmt/share_config.c index 70655af..c9bca1c 100644 --- a/mgmt/share_config.c +++ b/mgmt/share_config.c @@ -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); } diff --git a/mgmt/share_config.h b/mgmt/share_config.h index 28bf351..902f2cb 100644 --- a/mgmt/share_config.h +++ b/mgmt/share_config.h @@ -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) diff --git a/mgmt/tree_connect.c b/mgmt/tree_connect.c index 7d467e1..0cf6265 100644 --- a/mgmt/tree_connect.c +++ b/mgmt/tree_connect.c @@ -65,6 +65,20 @@ ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess, } 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; From patchwork Mon Aug 8 02:43:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Atte_Heikkil=C3=A4?= X-Patchwork-Id: 12938441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7AA0C25B0C for ; Mon, 8 Aug 2022 02:47:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242910AbiHHCrJ (ORCPT ); Sun, 7 Aug 2022 22:47:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244154AbiHHCqu (ORCPT ); Sun, 7 Aug 2022 22:46:50 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 188BF13D72 for ; Sun, 7 Aug 2022 19:44:05 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id v2so2138776lfi.6 for ; Sun, 07 Aug 2022 19:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=bgE+UMo9Vo+rfBsSHMr4wD8GPdfh6ZtGp/tMNdv+oq4=; b=PF+shWvvtMASNZj9keR8EMhxOqJgtkBwEvZ8Sn9ZQ8PUtiNzDB9Sl9APK5NRKAHg1h L9aN/k2RDSRTnpl6kTJ52xcuDuuF0dPg14QgIZa7BTxbSNv+8otvewA0wY41R8YLdYvV OPcmE3WJ84vlJZYvy+rYf8jOEuSLEiHoCAFb/jeOSs8epMp5WDeFG2tDfMrJYzSXmZ6T tOEmZ6ylJh/nYPOfZpIwtFAMpJZKAoVbqZeDoORAkMPd8EmxxSSUwhE3psTtpm7M5cpa ty/JwoQ9C56IQkrE+RlRauR/Jh9+2FTuI1N2UTXhutP91PntYzfN5u0QVZqaq8iyPo9L Zfiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=bgE+UMo9Vo+rfBsSHMr4wD8GPdfh6ZtGp/tMNdv+oq4=; b=MkQinU9c0bUxLqeJ/XGW2rpJIZYS2A/uU/pxTvuOIAFXCephHAPqzKhwi8TWk9m2B1 g1Tx+LZZZMghdYmnuQ+NToGS3nv4PCW6TnS8qBzVYyjM4SbOrlpSzmnjRY2m8IzIRTUs /Jq9pS31UAjqJqHZ61vrrZI5XR6HimdrKIfi3fk+c8UhEAcKozo1aPME/azBfeajnXUq YGIqa1QNUv3fJOBoxmt6Pm/hw8hYPvH7+oyzIcAjDxQEmeAxqoGLzukCJ5HoK44w8eG2 B7Krw9wfgc7xxun3yATUXbM/0CJY3uMD8RcroCmuiUSY3lVIf2KpxT+y2G1pyrkAci/9 1vsw== X-Gm-Message-State: ACgBeo0u7Ljp2Jsx/p3IiQmlRI9kJxs79IpvnzuVeIN5SCCz7ZSTDyrV WePrbXnvFCedNy6DozUaSnUrj6u21gc= X-Google-Smtp-Source: AA6agR6PwsrsR8/9ZXCiy1s0ACurUfUtPE2cp6mij5ZFKV2aMeQplKACEXg302ALCYaT3TABVRt4fA== X-Received: by 2002:a05:6512:230d:b0:48a:f158:623e with SMTP id o13-20020a056512230d00b0048af158623emr5974156lfu.437.1659926641069; Sun, 07 Aug 2022 19:44:01 -0700 (PDT) Received: from pohjola.lan (mobile-user-c1d2e4-79.dhcp.inet.fi. [193.210.228.79]) by smtp.gmail.com with ESMTPSA id v22-20020ac25596000000b0048a77a2c4b2sm1255125lfg.158.2022.08.07.19.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 19:44:00 -0700 (PDT) From: atheik To: linux-cifs@vger.kernel.org Cc: atheik Subject: [PATCH 2/3] ksmbd-tools: cleanup config group handling Date: Mon, 8 Aug 2022 05:43:40 +0300 Message-Id: <20220808024341.63913-2-atteh.mailbox@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808024341.63913-1-atteh.mailbox@gmail.com> References: <20220808024341.63913-1-atteh.mailbox@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org 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. Signed-off-by: Atte Heikkilä Reviewed-by: Hyunchul Lee --- include/config_parser.h | 5 +++ lib/config_parser.c | 95 +++++++++++++++++++++++------------------ 2 files changed, 59 insertions(+), 41 deletions(-) diff --git a/include/config_parser.h b/include/config_parser.h index b6c49b9..43212c8 100644 --- a/include/config_parser.h +++ b/include/config_parser.h @@ -10,7 +10,12 @@ #include +#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; }; diff --git a/lib/config_parser.c b/lib/config_parser.c index 5e7a438..d311386 100644 --- a/lib/config_parser.c +++ b/lib/config_parser.c @@ -21,7 +21,7 @@ struct smbconf_global global_conf; struct smbconf_parser parser; -struct smbconf_group *global_group; +struct smbconf_group *global_group, *ipc_group; unsigned long long memparse(const char *v) { @@ -107,6 +107,7 @@ static int add_new_group(char *line) } group = g_malloc(sizeof(struct smbconf_group)); + group->cb_mode = GROUPS_CALLBACK_NONE; group->name = name; group->kv = g_hash_table_new_full(g_str_hash, g_str_equal, @@ -561,6 +562,9 @@ static void global_conf_default(void) static void global_conf_create(void) { + if (!global_group || global_group->cb_mode != GROUPS_CALLBACK_INIT) + return; + /* * This will transfer server options to global_conf, and leave behind * in the global parser group, the options that must be applied to every @@ -569,6 +573,23 @@ static void global_conf_create(void) g_hash_table_foreach_remove(global_group->kv, global_group_kv, NULL); } +static void append_key_value(gpointer _k, gpointer _v, gpointer user_data) +{ + GHashTable *receiver = (GHashTable *) user_data; + + /* Don't override local share options */ + if (!g_hash_table_lookup(receiver, _k)) + g_hash_table_insert(receiver, g_strdup(_k), g_strdup(_v)); +} + +static void global_conf_update(struct smbconf_group *group) +{ + if (!global_group) + return; + + g_hash_table_foreach(global_group->kv, append_key_value, group->kv); +} + static void global_conf_fixup_missing(void) { int ret; @@ -607,39 +628,29 @@ static void global_conf_fixup_missing(void) ret); } -static void append_key_value(gpointer _k, gpointer _v, gpointer user_data) -{ - GHashTable *receiver = (GHashTable *) user_data; - - /* Don't override local share options */ - if (!g_hash_table_lookup(receiver, _k)) - g_hash_table_insert(receiver, g_strdup(_k), g_strdup(_v)); -} - -#define GROUPS_CALLBACK_STARTUP_INIT 0x1 -#define GROUPS_CALLBACK_REINIT 0x2 - static void groups_callback(gpointer _k, gpointer _v, gpointer user_data) { - struct smbconf_group *group = (struct smbconf_group *)_v; + struct smbconf_group *group = (struct smbconf_group *) _v; + unsigned short cb_mode = *(unsigned short *) user_data; - if (group != global_group) { - if (global_group && g_ascii_strcasecmp(_k, "ipc$")) - g_hash_table_foreach(global_group->kv, - append_key_value, - group->kv); + if (group == global_group) + return; - shm_add_new_share(group); - } + group->cb_mode = cb_mode; + + if (group != ipc_group) + global_conf_update(group); + + shm_add_new_share(group); } -static int cp_add_ipc_share(void) +static int cp_add_ipc_group(void) { char *comment = NULL, *guest = NULL; int ret = 0; - if (g_hash_table_lookup(parser.groups, "ipc$")) - return 0; + if (ipc_group) + return ret; comment = g_strdup("comment = IPC share"); guest = g_strdup("guest ok = yes"); @@ -649,13 +660,18 @@ static int cp_add_ipc_share(void) if (ret) { pr_err("Unable to add IPC$ share\n"); ret = -EINVAL; + goto out; } + + ipc_group = g_hash_table_lookup(parser.groups, "ipc$"); +out: g_free(comment); g_free(guest); return ret; } -static int __cp_parse_smbconfig(const char *smbconf, GHFunc cb, long flags) +static int __cp_parse_smbconfig(const char *smbconf, GHFunc cb, + unsigned short cb_mode) { int ret; @@ -665,35 +681,32 @@ static int __cp_parse_smbconfig(const char *smbconf, GHFunc cb, long flags) if (ret) return ret; - ret = cp_add_ipc_share(); - if (!ret) { - global_group = g_hash_table_lookup(parser.groups, "global"); + ret = cp_add_ipc_group(); + if (ret) + goto out; - if (global_group && (flags == GROUPS_CALLBACK_STARTUP_INIT)) - global_conf_create(); + global_group = g_hash_table_lookup(parser.groups, "global"); + if (global_group) + global_group->cb_mode = cb_mode; - g_hash_table_foreach(parser.groups, - groups_callback, - NULL); - - global_conf_fixup_missing(); - } + global_conf_create(); + g_hash_table_foreach(parser.groups, groups_callback, &cb_mode); + global_conf_fixup_missing(); +out: cp_smbconfig_destroy(); return ret; } int cp_parse_reload_smbconf(const char *smbconf) { - return __cp_parse_smbconfig(smbconf, - groups_callback, + return __cp_parse_smbconfig(smbconf, groups_callback, GROUPS_CALLBACK_REINIT); } int cp_parse_smbconf(const char *smbconf) { - return __cp_parse_smbconfig(smbconf, - groups_callback, - GROUPS_CALLBACK_STARTUP_INIT); + return __cp_parse_smbconfig(smbconf, groups_callback, + GROUPS_CALLBACK_INIT); } int cp_parse_pwddb(const char *pwddb) From patchwork Mon Aug 8 02:43:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Atte_Heikkil=C3=A4?= X-Patchwork-Id: 12938442 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DB3EC25B0C for ; Mon, 8 Aug 2022 02:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235693AbiHHCrL (ORCPT ); Sun, 7 Aug 2022 22:47:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244177AbiHHCqx (ORCPT ); Sun, 7 Aug 2022 22:46:53 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3553813E14 for ; Sun, 7 Aug 2022 19:44:08 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id r17so10723840lfm.11 for ; Sun, 07 Aug 2022 19:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=392Dmd/PigXAyQNBc3FJhswVSBZOfqlGTZD5FExUpT0=; b=Y6vvswH7nK5J35BM7oHLkI+N3mObnwDPIyxsc0n5QczMNvtBngHhIUnD9bwztxsAhH 4G4yfHz5joZ56JWG7OAIbwPIX+AxmxlJyMlZKAyzXfYvcYG8WBBZV3dfj3lk80DTpNnF b9QkwDZTQonUpUHxZAncAiFxtg0g7gp3sZ0KeMzvql0L9FmUMn9LqiWcUT704tiCQoka LhI836OfNKfUF7EqRPN43q0WV7FJUna6BNNXN0MT2Gu4Zca+zscEKpgm3qDSYhWc+UtS hzXj+Gka/95ZLn5LoARjPe0S85gyGaFmAeTv2KCmNEqfNb/fqbYsaKkeaA64xKeaHd3i wFtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=392Dmd/PigXAyQNBc3FJhswVSBZOfqlGTZD5FExUpT0=; b=cLYT1Xa55bni88e7zB8ElMCA4KNIGiF9COmwbvLbQDqEHEvYuxZOXDmUj1mwI2yZB1 /FhvL97rCq385Y4GTG8aadY7OvmQiM1v713kWdTwae0aHei2/CNspufSW1cFw4nsUxWu U8k+FKGBYBc5VTVHxnSY9Ud8iJyn85rfP47PrEIs1U7C9aFKyqVMBIhHsvjWmb1OCgmC ajstB9ieOdjUbWH2aG1V2AaiQ10YzSEyYOSAIbMAHYEdTacQjdScNCqJWZzW1Cg9ZHxD xDIwsUvZpOq/PFmjsAJpgZNM0zFXwlWF4daXCoz1nTsdq8omvAKxEmUb3EEq/qXFCjt8 si5w== X-Gm-Message-State: ACgBeo2+MOH/jT3j0a87CzqSMQP0O6NC3GGeUphISJyJkh7L1+3CRpIM PcA1pw6yYnLcRK+4AUZUrEq3Xiv0gYQ= X-Google-Smtp-Source: AA6agR6nFVkGpNHeGYt8khyIOoiNr9U0nlQP8dG0ovpxS8GZcORTEUeahSodWTow/eEVppTIbAco1w== X-Received: by 2002:a05:6512:138e:b0:47f:77cc:327a with SMTP id p14-20020a056512138e00b0047f77cc327amr5797722lfa.277.1659926641744; Sun, 07 Aug 2022 19:44:01 -0700 (PDT) Received: from pohjola.lan (mobile-user-c1d2e4-79.dhcp.inet.fi. [193.210.228.79]) by smtp.gmail.com with ESMTPSA id v22-20020ac25596000000b0048a77a2c4b2sm1255125lfg.158.2022.08.07.19.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 19:44:01 -0700 (PDT) From: atheik To: linux-cifs@vger.kernel.org Cc: atheik Subject: [PATCH 3/3] ksmbd-tools: inform ksmbd of stale share config Date: Mon, 8 Aug 2022 05:43:41 +0300 Message-Id: <20220808024341.63913-3-atteh.mailbox@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808024341.63913-1-atteh.mailbox@gmail.com> References: <20220808024341.63913-1-atteh.mailbox@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org 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ä Reviewed-by: Hyunchul Lee --- 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);