Skip to content

Commit fed979a

Browse files
scabrerosmfrench
authored andcommitted
cifs: Set witness notification handler for messages from userspace daemon
+ 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> Reviewed-by: Aurelien Aptel <aaptel@suse.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent bf80e5d commit fed979a

4 files changed

Lines changed: 116 additions & 0 deletions

File tree

‎fs/cifs/cifs_swn.c‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,92 @@ static void cifs_put_swn_reg(struct cifs_swn_reg *swnreg)
383383
mutex_unlock(&cifs_swnreg_idr_mutex);
384384
}
385385

386+
static int cifs_swn_resource_state_changed(struct cifs_swn_reg *swnreg, const char *name, int state)
387+
{
388+
int i;
389+
390+
switch (state) {
391+
case CIFS_SWN_RESOURCE_STATE_UNAVAILABLE:
392+
cifs_dbg(FYI, "%s: resource name '%s' become unavailable\n", __func__, name);
393+
for (i = 0; i < swnreg->tcon->ses->chan_count; i++) {
394+
spin_lock(&GlobalMid_Lock);
395+
if (swnreg->tcon->ses->chans[i].server->tcpStatus != CifsExiting)
396+
swnreg->tcon->ses->chans[i].server->tcpStatus = CifsNeedReconnect;
397+
spin_unlock(&GlobalMid_Lock);
398+
}
399+
break;
400+
case CIFS_SWN_RESOURCE_STATE_AVAILABLE:
401+
cifs_dbg(FYI, "%s: resource name '%s' become available\n", __func__, name);
402+
for (i = 0; i < swnreg->tcon->ses->chan_count; i++) {
403+
spin_lock(&GlobalMid_Lock);
404+
if (swnreg->tcon->ses->chans[i].server->tcpStatus != CifsExiting)
405+
swnreg->tcon->ses->chans[i].server->tcpStatus = CifsNeedReconnect;
406+
spin_unlock(&GlobalMid_Lock);
407+
}
408+
break;
409+
case CIFS_SWN_RESOURCE_STATE_UNKNOWN:
410+
cifs_dbg(FYI, "%s: resource name '%s' changed to unknown state\n", __func__, name);
411+
break;
412+
}
413+
return 0;
414+
}
415+
416+
int cifs_swn_notify(struct sk_buff *skb, struct genl_info *info)
417+
{
418+
struct cifs_swn_reg *swnreg;
419+
char name[256];
420+
int type;
421+
422+
if (info->attrs[CIFS_GENL_ATTR_SWN_REGISTRATION_ID]) {
423+
int swnreg_id;
424+
425+
swnreg_id = nla_get_u32(info->attrs[CIFS_GENL_ATTR_SWN_REGISTRATION_ID]);
426+
mutex_lock(&cifs_swnreg_idr_mutex);
427+
swnreg = idr_find(&cifs_swnreg_idr, swnreg_id);
428+
mutex_unlock(&cifs_swnreg_idr_mutex);
429+
if (swnreg == NULL) {
430+
cifs_dbg(FYI, "%s: registration id %d not found\n", __func__, swnreg_id);
431+
return -EINVAL;
432+
}
433+
} else {
434+
cifs_dbg(FYI, "%s: missing registration id attribute\n", __func__);
435+
return -EINVAL;
436+
}
437+
438+
if (info->attrs[CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE]) {
439+
type = nla_get_u32(info->attrs[CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE]);
440+
} else {
441+
cifs_dbg(FYI, "%s: missing notification type attribute\n", __func__);
442+
return -EINVAL;
443+
}
444+
445+
switch (type) {
446+
case CIFS_SWN_NOTIFICATION_RESOURCE_CHANGE: {
447+
int state;
448+
449+
if (info->attrs[CIFS_GENL_ATTR_SWN_RESOURCE_NAME]) {
450+
nla_strlcpy(name, info->attrs[CIFS_GENL_ATTR_SWN_RESOURCE_NAME],
451+
sizeof(name));
452+
} else {
453+
cifs_dbg(FYI, "%s: missing resource name attribute\n", __func__);
454+
return -EINVAL;
455+
}
456+
if (info->attrs[CIFS_GENL_ATTR_SWN_RESOURCE_STATE]) {
457+
state = nla_get_u32(info->attrs[CIFS_GENL_ATTR_SWN_RESOURCE_STATE]);
458+
} else {
459+
cifs_dbg(FYI, "%s: missing resource state attribute\n", __func__);
460+
return -EINVAL;
461+
}
462+
return cifs_swn_resource_state_changed(swnreg, name, state);
463+
}
464+
default:
465+
cifs_dbg(FYI, "%s: unknown notification type %d\n", __func__, type);
466+
break;
467+
}
468+
469+
return 0;
470+
}
471+
386472
int cifs_swn_register(struct cifs_tcon *tcon)
387473
{
388474
struct cifs_swn_reg *swnreg;

‎fs/cifs/cifs_swn.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
#define _CIFS_SWN_H
1010

1111
struct cifs_tcon;
12+
struct sk_buff;
13+
struct genl_info;
1214

1315
extern int cifs_swn_register(struct cifs_tcon *tcon);
1416

1517
extern int cifs_swn_unregister(struct cifs_tcon *tcon);
1618

19+
extern int cifs_swn_notify(struct sk_buff *skb, struct genl_info *info);
20+
1721
#endif /* _CIFS_SWN_H */

‎fs/cifs/netlink.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "netlink.h"
1212
#include "cifsglob.h"
1313
#include "cifs_debug.h"
14+
#include "cifs_swn.h"
1415

1516
static const struct nla_policy cifs_genl_policy[CIFS_GENL_ATTR_MAX + 1] = {
1617
[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] = {
2425
[CIFS_GENL_ATTR_SWN_USER_NAME] = { .type = NLA_STRING },
2526
[CIFS_GENL_ATTR_SWN_PASSWORD] = { .type = NLA_STRING },
2627
[CIFS_GENL_ATTR_SWN_DOMAIN_NAME] = { .type = NLA_STRING },
28+
[CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE] = { .type = NLA_U32 },
29+
[CIFS_GENL_ATTR_SWN_RESOURCE_STATE] = { .type = NLA_U32 },
30+
[CIFS_GENL_ATTR_SWN_RESOURCE_NAME] = { .type = NLA_STRING},
2731
};
2832

2933
static struct genl_ops cifs_genl_ops[] = {
34+
{
35+
.cmd = CIFS_GENL_CMD_SWN_NOTIFY,
36+
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
37+
.doit = cifs_swn_notify,
38+
},
3039
};
3140

3241
static const struct genl_multicast_group cifs_genl_mcgrps[] = {

‎include/uapi/linux/cifs/cifs_netlink.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ enum cifs_genl_attributes {
3131
CIFS_GENL_ATTR_SWN_USER_NAME,
3232
CIFS_GENL_ATTR_SWN_PASSWORD,
3333
CIFS_GENL_ATTR_SWN_DOMAIN_NAME,
34+
CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE,
35+
CIFS_GENL_ATTR_SWN_RESOURCE_STATE,
36+
CIFS_GENL_ATTR_SWN_RESOURCE_NAME,
3437
__CIFS_GENL_ATTR_MAX,
3538
};
3639
#define CIFS_GENL_ATTR_MAX (__CIFS_GENL_ATTR_MAX - 1)
@@ -39,8 +42,22 @@ enum cifs_genl_commands {
3942
CIFS_GENL_CMD_UNSPEC,
4043
CIFS_GENL_CMD_SWN_REGISTER,
4144
CIFS_GENL_CMD_SWN_UNREGISTER,
45+
CIFS_GENL_CMD_SWN_NOTIFY,
4246
__CIFS_GENL_CMD_MAX
4347
};
4448
#define CIFS_GENL_CMD_MAX (__CIFS_GENL_CMD_MAX - 1)
4549

50+
enum cifs_swn_notification_type {
51+
CIFS_SWN_NOTIFICATION_RESOURCE_CHANGE = 0x01,
52+
CIFS_SWN_NOTIFICATION_CLIENT_MOVE = 0x02,
53+
CIFS_SWN_NOTIFICATION_SHARE_MOVE = 0x03,
54+
CIFS_SWN_NOTIFICATION_IP_CHANGE = 0x04,
55+
};
56+
57+
enum cifs_swn_resource_state {
58+
CIFS_SWN_RESOURCE_STATE_UNKNOWN = 0x00,
59+
CIFS_SWN_RESOURCE_STATE_AVAILABLE = 0x01,
60+
CIFS_SWN_RESOURCE_STATE_UNAVAILABLE = 0xFF
61+
};
62+
4663
#endif /* _UAPILINUX_CIFS_NETLINK_H */

0 commit comments

Comments
 (0)