1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
6 #include <net/genetlink.h>
8 #include <linux/dlm_netlink.h>
11 #include "dlm_internal.h"
13 static uint32_t dlm_nl_seqnum
;
14 static uint32_t listener_nlportid
;
16 static struct genl_family family
;
18 static int prepare_data(u8 cmd
, struct sk_buff
**skbp
, size_t size
)
23 skb
= genlmsg_new(size
, GFP_NOFS
);
27 /* add the message headers */
28 data
= genlmsg_put(skb
, 0, dlm_nl_seqnum
++, &family
, 0, cmd
);
38 static struct dlm_lock_data
*mk_data(struct sk_buff
*skb
)
42 ret
= nla_reserve(skb
, DLM_TYPE_LOCK
, sizeof(struct dlm_lock_data
));
48 static int send_data(struct sk_buff
*skb
)
50 struct genlmsghdr
*genlhdr
= nlmsg_data((struct nlmsghdr
*)skb
->data
);
51 void *data
= genlmsg_data(genlhdr
);
53 genlmsg_end(skb
, data
);
55 return genlmsg_unicast(&init_net
, skb
, listener_nlportid
);
58 static int user_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
60 listener_nlportid
= info
->snd_portid
;
61 printk("user_cmd nlpid %u\n", listener_nlportid
);
65 static const struct genl_ops dlm_nl_ops
[] = {
68 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
73 static struct genl_family family __ro_after_init
= {
74 .name
= DLM_GENL_NAME
,
75 .version
= DLM_GENL_VERSION
,
77 .n_ops
= ARRAY_SIZE(dlm_nl_ops
),
78 .module
= THIS_MODULE
,
81 int __init
dlm_netlink_init(void)
83 return genl_register_family(&family
);
86 void dlm_netlink_exit(void)
88 genl_unregister_family(&family
);
91 static void fill_data(struct dlm_lock_data
*data
, struct dlm_lkb
*lkb
)
93 struct dlm_rsb
*r
= lkb
->lkb_resource
;
95 memset(data
, 0, sizeof(struct dlm_lock_data
));
97 data
->version
= DLM_LOCK_DATA_VERSION
;
98 data
->nodeid
= lkb
->lkb_nodeid
;
99 data
->ownpid
= lkb
->lkb_ownpid
;
100 data
->id
= lkb
->lkb_id
;
101 data
->remid
= lkb
->lkb_remid
;
102 data
->status
= lkb
->lkb_status
;
103 data
->grmode
= lkb
->lkb_grmode
;
104 data
->rqmode
= lkb
->lkb_rqmode
;
106 data
->xid
= lkb
->lkb_ua
->xid
;
108 data
->lockspace_id
= r
->res_ls
->ls_global_id
;
109 data
->resource_namelen
= r
->res_length
;
110 memcpy(data
->resource_name
, r
->res_name
, r
->res_length
);
114 void dlm_timeout_warn(struct dlm_lkb
*lkb
)
116 struct sk_buff
*uninitialized_var(send_skb
);
117 struct dlm_lock_data
*data
;
121 size
= nla_total_size(sizeof(struct dlm_lock_data
)) +
122 nla_total_size(0); /* why this? */
124 rv
= prepare_data(DLM_CMD_TIMEOUT
, &send_skb
, size
);
128 data
= mk_data(send_skb
);
130 nlmsg_free(send_skb
);
134 fill_data(data
, lkb
);