2 * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
4 * This copyrighted material is made available to anyone wishing to use,
5 * modify, copy, or redistribute it subject to the terms and conditions
6 * of the GNU General Public License v.2.
9 #include <net/genetlink.h>
10 #include <linux/dlm.h>
11 #include <linux/dlm_netlink.h>
12 #include <linux/gfp.h>
14 #include "dlm_internal.h"
16 static uint32_t dlm_nl_seqnum
;
17 static uint32_t listener_nlportid
;
19 static struct genl_family family
;
21 static int prepare_data(u8 cmd
, struct sk_buff
**skbp
, size_t size
)
26 skb
= genlmsg_new(size
, GFP_NOFS
);
30 /* add the message headers */
31 data
= genlmsg_put(skb
, 0, dlm_nl_seqnum
++, &family
, 0, cmd
);
41 static struct dlm_lock_data
*mk_data(struct sk_buff
*skb
)
45 ret
= nla_reserve(skb
, DLM_TYPE_LOCK
, sizeof(struct dlm_lock_data
));
51 static int send_data(struct sk_buff
*skb
)
53 struct genlmsghdr
*genlhdr
= nlmsg_data((struct nlmsghdr
*)skb
->data
);
54 void *data
= genlmsg_data(genlhdr
);
56 genlmsg_end(skb
, data
);
58 return genlmsg_unicast(&init_net
, skb
, listener_nlportid
);
61 static int user_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
63 listener_nlportid
= info
->snd_portid
;
64 printk("user_cmd nlpid %u\n", listener_nlportid
);
68 static const struct genl_ops dlm_nl_ops
[] = {
75 static struct genl_family family __ro_after_init
= {
76 .name
= DLM_GENL_NAME
,
77 .version
= DLM_GENL_VERSION
,
79 .n_ops
= ARRAY_SIZE(dlm_nl_ops
),
80 .module
= THIS_MODULE
,
83 int __init
dlm_netlink_init(void)
85 return genl_register_family(&family
);
88 void dlm_netlink_exit(void)
90 genl_unregister_family(&family
);
93 static void fill_data(struct dlm_lock_data
*data
, struct dlm_lkb
*lkb
)
95 struct dlm_rsb
*r
= lkb
->lkb_resource
;
97 memset(data
, 0, sizeof(struct dlm_lock_data
));
99 data
->version
= DLM_LOCK_DATA_VERSION
;
100 data
->nodeid
= lkb
->lkb_nodeid
;
101 data
->ownpid
= lkb
->lkb_ownpid
;
102 data
->id
= lkb
->lkb_id
;
103 data
->remid
= lkb
->lkb_remid
;
104 data
->status
= lkb
->lkb_status
;
105 data
->grmode
= lkb
->lkb_grmode
;
106 data
->rqmode
= lkb
->lkb_rqmode
;
108 data
->xid
= lkb
->lkb_ua
->xid
;
110 data
->lockspace_id
= r
->res_ls
->ls_global_id
;
111 data
->resource_namelen
= r
->res_length
;
112 memcpy(data
->resource_name
, r
->res_name
, r
->res_length
);
116 void dlm_timeout_warn(struct dlm_lkb
*lkb
)
118 struct sk_buff
*uninitialized_var(send_skb
);
119 struct dlm_lock_data
*data
;
123 size
= nla_total_size(sizeof(struct dlm_lock_data
)) +
124 nla_total_size(0); /* why this? */
126 rv
= prepare_data(DLM_CMD_TIMEOUT
, &send_skb
, size
);
130 data
= mk_data(send_skb
);
132 nlmsg_free(send_skb
);
136 fill_data(data
, lkb
);