From: Steve French <smfrench@gmail.com>
To: Samuel Cabrero <scabrero@suse.de>
Cc: CIFS <linux-cifs@vger.kernel.org>
Subject: Re: [PATCH v4 06/11] cifs: Set witness notification handler for messages from userspace daemon
Date: Fri, 11 Dec 2020 23:55:31 -0600 [thread overview]
Message-ID: <CAH2r5mtv=pLSHV-vPOyuemO+EKb-aMCNEPiiTwY+AhX0jHzLBg@mail.gmail.com> (raw)
In-Reply-To: <20201130180257.31787-7-scabrero@suse.de>
tentatively merged into cifs-2.6.git for-next Let me know if any
updates needed to it
On Mon, Nov 30, 2020 at 12:05 PM Samuel Cabrero <scabrero@suse.de> wrote:
>
> + Set a handler for the witness notification messages received from the
> userspace daemon.
>
> + Handle the resource state change notification. When the resource
> becomes unavailable or available set the tcp status to
> CifsNeedReconnect for all channels.
>
> Signed-off-by: Samuel Cabrero <scabrero@suse.de>
> ---
> fs/cifs/cifs_swn.c | 86 ++++++++++++++++++++++++++
> fs/cifs/cifs_swn.h | 4 ++
> fs/cifs/netlink.c | 9 +++
> include/uapi/linux/cifs/cifs_netlink.h | 17 +++++
> 4 files changed, 116 insertions(+)
>
> diff --git a/fs/cifs/cifs_swn.c b/fs/cifs/cifs_swn.c
> index c0af03955d0c..63b0764af5d5 100644
> --- a/fs/cifs/cifs_swn.c
> +++ b/fs/cifs/cifs_swn.c
> @@ -383,6 +383,92 @@ static void cifs_put_swn_reg(struct cifs_swn_reg *swnreg)
> mutex_unlock(&cifs_swnreg_idr_mutex);
> }
>
> +static int cifs_swn_resource_state_changed(struct cifs_swn_reg *swnreg, const char *name, int state)
> +{
> + int i;
> +
> + switch (state) {
> + case CIFS_SWN_RESOURCE_STATE_UNAVAILABLE:
> + cifs_dbg(FYI, "%s: resource name '%s' become unavailable\n", __func__, name);
> + for (i = 0; i < swnreg->tcon->ses->chan_count; i++) {
> + spin_lock(&GlobalMid_Lock);
> + if (swnreg->tcon->ses->chans[i].server->tcpStatus != CifsExiting)
> + swnreg->tcon->ses->chans[i].server->tcpStatus = CifsNeedReconnect;
> + spin_unlock(&GlobalMid_Lock);
> + }
> + break;
> + case CIFS_SWN_RESOURCE_STATE_AVAILABLE:
> + cifs_dbg(FYI, "%s: resource name '%s' become available\n", __func__, name);
> + for (i = 0; i < swnreg->tcon->ses->chan_count; i++) {
> + spin_lock(&GlobalMid_Lock);
> + if (swnreg->tcon->ses->chans[i].server->tcpStatus != CifsExiting)
> + swnreg->tcon->ses->chans[i].server->tcpStatus = CifsNeedReconnect;
> + spin_unlock(&GlobalMid_Lock);
> + }
> + break;
> + case CIFS_SWN_RESOURCE_STATE_UNKNOWN:
> + cifs_dbg(FYI, "%s: resource name '%s' changed to unknown state\n", __func__, name);
> + break;
> + }
> + return 0;
> +}
> +
> +int cifs_swn_notify(struct sk_buff *skb, struct genl_info *info)
> +{
> + struct cifs_swn_reg *swnreg;
> + char name[256];
> + int type;
> +
> + if (info->attrs[CIFS_GENL_ATTR_SWN_REGISTRATION_ID]) {
> + int swnreg_id;
> +
> + swnreg_id = nla_get_u32(info->attrs[CIFS_GENL_ATTR_SWN_REGISTRATION_ID]);
> + mutex_lock(&cifs_swnreg_idr_mutex);
> + swnreg = idr_find(&cifs_swnreg_idr, swnreg_id);
> + mutex_unlock(&cifs_swnreg_idr_mutex);
> + if (swnreg == NULL) {
> + cifs_dbg(FYI, "%s: registration id %d not found\n", __func__, swnreg_id);
> + return -EINVAL;
> + }
> + } else {
> + cifs_dbg(FYI, "%s: missing registration id attribute\n", __func__);
> + return -EINVAL;
> + }
> +
> + if (info->attrs[CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE]) {
> + type = nla_get_u32(info->attrs[CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE]);
> + } else {
> + cifs_dbg(FYI, "%s: missing notification type attribute\n", __func__);
> + return -EINVAL;
> + }
> +
> + switch (type) {
> + case CIFS_SWN_NOTIFICATION_RESOURCE_CHANGE: {
> + int state;
> +
> + if (info->attrs[CIFS_GENL_ATTR_SWN_RESOURCE_NAME]) {
> + nla_strlcpy(name, info->attrs[CIFS_GENL_ATTR_SWN_RESOURCE_NAME],
> + sizeof(name));
> + } else {
> + cifs_dbg(FYI, "%s: missing resource name attribute\n", __func__);
> + return -EINVAL;
> + }
> + if (info->attrs[CIFS_GENL_ATTR_SWN_RESOURCE_STATE]) {
> + state = nla_get_u32(info->attrs[CIFS_GENL_ATTR_SWN_RESOURCE_STATE]);
> + } else {
> + cifs_dbg(FYI, "%s: missing resource state attribute\n", __func__);
> + return -EINVAL;
> + }
> + return cifs_swn_resource_state_changed(swnreg, name, state);
> + }
> + default:
> + cifs_dbg(FYI, "%s: unknown notification type %d\n", __func__, type);
> + break;
> + }
> +
> + return 0;
> +}
> +
> int cifs_swn_register(struct cifs_tcon *tcon)
> {
> struct cifs_swn_reg *swnreg;
> diff --git a/fs/cifs/cifs_swn.h b/fs/cifs/cifs_swn.h
> index 69c7bd1035da..7ef9ecedbd05 100644
> --- a/fs/cifs/cifs_swn.h
> +++ b/fs/cifs/cifs_swn.h
> @@ -9,9 +9,13 @@
> #define _CIFS_SWN_H
>
> struct cifs_tcon;
> +struct sk_buff;
> +struct genl_info;
>
> extern int cifs_swn_register(struct cifs_tcon *tcon);
>
> extern int cifs_swn_unregister(struct cifs_tcon *tcon);
>
> +extern int cifs_swn_notify(struct sk_buff *skb, struct genl_info *info);
> +
> #endif /* _CIFS_SWN_H */
> diff --git a/fs/cifs/netlink.c b/fs/cifs/netlink.c
> index 83008a56def5..5aaabe4cc0a7 100644
> --- a/fs/cifs/netlink.c
> +++ b/fs/cifs/netlink.c
> @@ -11,6 +11,7 @@
> #include "netlink.h"
> #include "cifsglob.h"
> #include "cifs_debug.h"
> +#include "cifs_swn.h"
>
> static const struct nla_policy cifs_genl_policy[CIFS_GENL_ATTR_MAX + 1] = {
> [CIFS_GENL_ATTR_SWN_REGISTRATION_ID] = { .type = NLA_U32 },
> @@ -24,9 +25,17 @@ static const struct nla_policy cifs_genl_policy[CIFS_GENL_ATTR_MAX + 1] = {
> [CIFS_GENL_ATTR_SWN_USER_NAME] = { .type = NLA_STRING },
> [CIFS_GENL_ATTR_SWN_PASSWORD] = { .type = NLA_STRING },
> [CIFS_GENL_ATTR_SWN_DOMAIN_NAME] = { .type = NLA_STRING },
> + [CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE] = { .type = NLA_U32 },
> + [CIFS_GENL_ATTR_SWN_RESOURCE_STATE] = { .type = NLA_U32 },
> + [CIFS_GENL_ATTR_SWN_RESOURCE_NAME] = { .type = NLA_STRING},
> };
>
> static struct genl_ops cifs_genl_ops[] = {
> + {
> + .cmd = CIFS_GENL_CMD_SWN_NOTIFY,
> + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
> + .doit = cifs_swn_notify,
> + },
> };
>
> static const struct genl_multicast_group cifs_genl_mcgrps[] = {
> diff --git a/include/uapi/linux/cifs/cifs_netlink.h b/include/uapi/linux/cifs/cifs_netlink.h
> index 5662e2774513..da3107582f49 100644
> --- a/include/uapi/linux/cifs/cifs_netlink.h
> +++ b/include/uapi/linux/cifs/cifs_netlink.h
> @@ -31,6 +31,9 @@ enum cifs_genl_attributes {
> CIFS_GENL_ATTR_SWN_USER_NAME,
> CIFS_GENL_ATTR_SWN_PASSWORD,
> CIFS_GENL_ATTR_SWN_DOMAIN_NAME,
> + CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE,
> + CIFS_GENL_ATTR_SWN_RESOURCE_STATE,
> + CIFS_GENL_ATTR_SWN_RESOURCE_NAME,
> __CIFS_GENL_ATTR_MAX,
> };
> #define CIFS_GENL_ATTR_MAX (__CIFS_GENL_ATTR_MAX - 1)
> @@ -39,8 +42,22 @@ enum cifs_genl_commands {
> CIFS_GENL_CMD_UNSPEC,
> CIFS_GENL_CMD_SWN_REGISTER,
> CIFS_GENL_CMD_SWN_UNREGISTER,
> + CIFS_GENL_CMD_SWN_NOTIFY,
> __CIFS_GENL_CMD_MAX
> };
> #define CIFS_GENL_CMD_MAX (__CIFS_GENL_CMD_MAX - 1)
>
> +enum cifs_swn_notification_type {
> + CIFS_SWN_NOTIFICATION_RESOURCE_CHANGE = 0x01,
> + CIFS_SWN_NOTIFICATION_CLIENT_MOVE = 0x02,
> + CIFS_SWN_NOTIFICATION_SHARE_MOVE = 0x03,
> + CIFS_SWN_NOTIFICATION_IP_CHANGE = 0x04,
> +};
> +
> +enum cifs_swn_resource_state {
> + CIFS_SWN_RESOURCE_STATE_UNKNOWN = 0x00,
> + CIFS_SWN_RESOURCE_STATE_AVAILABLE = 0x01,
> + CIFS_SWN_RESOURCE_STATE_UNAVAILABLE = 0xFF
> +};
> +
> #endif /* _UAPILINUX_CIFS_NETLINK_H */
> --
> 2.29.2
>
--
Thanks,
Steve
next prev parent reply other threads:[~2020-12-12 5:57 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-30 18:02 [PATCH v4 00/11] Witness protocol support for transparent failover Samuel Cabrero
2020-11-30 18:02 ` [PATCH v4 01/11] cifs: Make extract_hostname function public Samuel Cabrero
2020-12-12 3:42 ` Steve French
2020-11-30 18:02 ` [PATCH v4 02/11] cifs: Make extract_sharename " Samuel Cabrero
2020-12-12 5:50 ` Steve French
2020-11-30 18:02 ` [PATCH v4 03/11] cifs: Register generic netlink family Samuel Cabrero
2020-12-12 5:51 ` Steve French
2020-11-30 18:02 ` [PATCH v4 04/11] cifs: add witness mount option and data structs Samuel Cabrero
2020-12-12 5:07 ` Steve French
2020-11-30 18:02 ` [PATCH v4 05/11] cifs: Send witness register and unregister commands to userspace daemon Samuel Cabrero
2020-12-12 5:52 ` Steve French
2020-11-30 18:02 ` [PATCH v4 06/11] cifs: Set witness notification handler for messages from " Samuel Cabrero
2020-12-12 5:55 ` Steve French [this message]
2020-11-30 18:02 ` [PATCH v4 07/11] cifs: Add witness information to debug data dump Samuel Cabrero
2020-12-12 5:57 ` Steve French
2020-11-30 18:02 ` [PATCH v4 08/11] cifs: Send witness register messages to userspace daemon in echo task Samuel Cabrero
2020-12-12 6:00 ` Steve French
2020-11-30 18:02 ` [PATCH v4 09/11] cifs: Simplify reconnect code when dfs upcall is enabled Samuel Cabrero
2020-12-12 6:07 ` Steve French
2020-11-30 18:02 ` [PATCH v4 10/11] cifs: Handle witness client move notification Samuel Cabrero
2020-11-30 18:02 ` [PATCH v4 11/11] cifs: Handle witness share moved notification Samuel Cabrero
2020-12-09 12:36 ` [PATCH v4 00/11] Witness protocol support for transparent failover Aurélien Aptel
2020-12-09 15:06 ` Paulo Alcantara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH2r5mtv=pLSHV-vPOyuemO+EKb-aMCNEPiiTwY+AhX0jHzLBg@mail.gmail.com' \
--to=smfrench@gmail.com \
--cc=linux-cifs@vger.kernel.org \
--cc=scabrero@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).