Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Samuel Cabrero and committed by
Steve French
fed979a7 bf80e5d4

+116
+86
fs/cifs/cifs_swn.c
··· 383 383 mutex_unlock(&cifs_swnreg_idr_mutex); 384 384 } 385 385 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 + 386 472 int cifs_swn_register(struct cifs_tcon *tcon) 387 473 { 388 474 struct cifs_swn_reg *swnreg;
+4
fs/cifs/cifs_swn.h
··· 9 9 #define _CIFS_SWN_H 10 10 11 11 struct cifs_tcon; 12 + struct sk_buff; 13 + struct genl_info; 12 14 13 15 extern int cifs_swn_register(struct cifs_tcon *tcon); 14 16 15 17 extern int cifs_swn_unregister(struct cifs_tcon *tcon); 18 + 19 + extern int cifs_swn_notify(struct sk_buff *skb, struct genl_info *info); 16 20 17 21 #endif /* _CIFS_SWN_H */
+9
fs/cifs/netlink.c
··· 11 11 #include "netlink.h" 12 12 #include "cifsglob.h" 13 13 #include "cifs_debug.h" 14 + #include "cifs_swn.h" 14 15 15 16 static const struct nla_policy cifs_genl_policy[CIFS_GENL_ATTR_MAX + 1] = { 16 17 [CIFS_GENL_ATTR_SWN_REGISTRATION_ID] = { .type = NLA_U32 }, ··· 25 24 [CIFS_GENL_ATTR_SWN_USER_NAME] = { .type = NLA_STRING }, 26 25 [CIFS_GENL_ATTR_SWN_PASSWORD] = { .type = NLA_STRING }, 27 26 [CIFS_GENL_ATTR_SWN_DOMAIN_NAME] = { .type = NLA_STRING }, 27 + [CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE] = { .type = NLA_U32 }, 28 + [CIFS_GENL_ATTR_SWN_RESOURCE_STATE] = { .type = NLA_U32 }, 29 + [CIFS_GENL_ATTR_SWN_RESOURCE_NAME] = { .type = NLA_STRING}, 28 30 }; 29 31 30 32 static struct genl_ops cifs_genl_ops[] = { 33 + { 34 + .cmd = CIFS_GENL_CMD_SWN_NOTIFY, 35 + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 36 + .doit = cifs_swn_notify, 37 + }, 31 38 }; 32 39 33 40 static const struct genl_multicast_group cifs_genl_mcgrps[] = {
+17
include/uapi/linux/cifs/cifs_netlink.h
··· 31 31 CIFS_GENL_ATTR_SWN_USER_NAME, 32 32 CIFS_GENL_ATTR_SWN_PASSWORD, 33 33 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, 34 37 __CIFS_GENL_ATTR_MAX, 35 38 }; 36 39 #define CIFS_GENL_ATTR_MAX (__CIFS_GENL_ATTR_MAX - 1) ··· 42 39 CIFS_GENL_CMD_UNSPEC, 43 40 CIFS_GENL_CMD_SWN_REGISTER, 44 41 CIFS_GENL_CMD_SWN_UNREGISTER, 42 + CIFS_GENL_CMD_SWN_NOTIFY, 45 43 __CIFS_GENL_CMD_MAX 46 44 }; 47 45 #define CIFS_GENL_CMD_MAX (__CIFS_GENL_CMD_MAX - 1) 46 + 47 + enum cifs_swn_notification_type { 48 + CIFS_SWN_NOTIFICATION_RESOURCE_CHANGE = 0x01, 49 + CIFS_SWN_NOTIFICATION_CLIENT_MOVE = 0x02, 50 + CIFS_SWN_NOTIFICATION_SHARE_MOVE = 0x03, 51 + CIFS_SWN_NOTIFICATION_IP_CHANGE = 0x04, 52 + }; 53 + 54 + enum cifs_swn_resource_state { 55 + CIFS_SWN_RESOURCE_STATE_UNKNOWN = 0x00, 56 + CIFS_SWN_RESOURCE_STATE_AVAILABLE = 0x01, 57 + CIFS_SWN_RESOURCE_STATE_UNAVAILABLE = 0xFF 58 + }; 48 59 49 60 #endif /* _UAPILINUX_CIFS_NETLINK_H */