Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2007 Red Hat, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <net/genetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/dlm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/dlm_netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "dlm_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) static uint32_t dlm_nl_seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static uint32_t listener_nlportid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static struct genl_family family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static int prepare_data(u8 cmd, struct sk_buff **skbp, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	skb = genlmsg_new(size, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	/* add the message headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	data = genlmsg_put(skb, 0, dlm_nl_seqnum++, &family, 0, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		nlmsg_free(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	*skbp = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static struct dlm_lock_data *mk_data(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct nlattr *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	ret = nla_reserve(skb, DLM_TYPE_LOCK, sizeof(struct dlm_lock_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return nla_data(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int send_data(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	void *data = genlmsg_data(genlhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	genlmsg_end(skb, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return genlmsg_unicast(&init_net, skb, listener_nlportid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static int user_cmd(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	listener_nlportid = info->snd_portid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	printk("user_cmd nlpid %u\n", listener_nlportid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static const struct genl_small_ops dlm_nl_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		.cmd	= DLM_CMD_HELLO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		.doit	= user_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static struct genl_family family __ro_after_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.name		= DLM_GENL_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.version	= DLM_GENL_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.small_ops	= dlm_nl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.n_small_ops	= ARRAY_SIZE(dlm_nl_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	.module		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) int __init dlm_netlink_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return genl_register_family(&family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) void dlm_netlink_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	genl_unregister_family(&family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static void fill_data(struct dlm_lock_data *data, struct dlm_lkb *lkb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct dlm_rsb *r = lkb->lkb_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	memset(data, 0, sizeof(struct dlm_lock_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	data->version = DLM_LOCK_DATA_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	data->nodeid = lkb->lkb_nodeid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	data->ownpid = lkb->lkb_ownpid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	data->id = lkb->lkb_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	data->remid = lkb->lkb_remid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	data->status = lkb->lkb_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	data->grmode = lkb->lkb_grmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	data->rqmode = lkb->lkb_rqmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (lkb->lkb_ua)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		data->xid = lkb->lkb_ua->xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		data->lockspace_id = r->res_ls->ls_global_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		data->resource_namelen = r->res_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		memcpy(data->resource_name, r->res_name, r->res_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) void dlm_timeout_warn(struct dlm_lkb *lkb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct sk_buff *send_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct dlm_lock_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	size = nla_total_size(sizeof(struct dlm_lock_data)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	       nla_total_size(0); /* why this? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	rv = prepare_data(DLM_CMD_TIMEOUT, &send_skb, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	data = mk_data(send_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		nlmsg_free(send_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	fill_data(data, lkb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	send_data(send_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)