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>
13 #include "dlm_internal.h"
15 static uint32_t dlm_nl_seqnum
;
16 static uint32_t listener_nlpid
;
18 static struct genl_family family
= {
19 .id
= GENL_ID_GENERATE
,
20 .name
= DLM_GENL_NAME
,
21 .version
= DLM_GENL_VERSION
,
24 static int prepare_data(u8 cmd
, struct sk_buff
**skbp
, size_t size
)
29 skb
= genlmsg_new(size
, GFP_KERNEL
);
33 /* add the message headers */
34 data
= genlmsg_put(skb
, 0, dlm_nl_seqnum
++, &family
, 0, cmd
);
44 static struct dlm_lock_data
*mk_data(struct sk_buff
*skb
)
48 ret
= nla_reserve(skb
, DLM_TYPE_LOCK
, sizeof(struct dlm_lock_data
));
54 static int send_data(struct sk_buff
*skb
)
56 struct genlmsghdr
*genlhdr
= nlmsg_data((struct nlmsghdr
*)skb
->data
);
57 void *data
= genlmsg_data(genlhdr
);
60 rv
= genlmsg_end(skb
, data
);
66 return genlmsg_unicast(skb
, listener_nlpid
);
69 static int user_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
71 listener_nlpid
= info
->snd_pid
;
72 printk("user_cmd nlpid %u\n", listener_nlpid
);
76 static struct genl_ops dlm_nl_ops
= {
81 int dlm_netlink_init(void)
85 rv
= genl_register_family(&family
);
89 rv
= genl_register_ops(&family
, &dlm_nl_ops
);
94 genl_unregister_family(&family
);
98 void dlm_netlink_exit(void)
100 genl_unregister_ops(&family
, &dlm_nl_ops
);
101 genl_unregister_family(&family
);
104 static void fill_data(struct dlm_lock_data
*data
, struct dlm_lkb
*lkb
)
106 struct dlm_rsb
*r
= lkb
->lkb_resource
;
107 struct dlm_user_args
*ua
= (struct dlm_user_args
*) lkb
->lkb_astparam
;
109 memset(data
, 0, sizeof(struct dlm_lock_data
));
111 data
->version
= DLM_LOCK_DATA_VERSION
;
112 data
->nodeid
= lkb
->lkb_nodeid
;
113 data
->ownpid
= lkb
->lkb_ownpid
;
114 data
->id
= lkb
->lkb_id
;
115 data
->remid
= lkb
->lkb_remid
;
116 data
->status
= lkb
->lkb_status
;
117 data
->grmode
= lkb
->lkb_grmode
;
118 data
->rqmode
= lkb
->lkb_rqmode
;
119 data
->timestamp
= lkb
->lkb_timestamp
;
123 data
->lockspace_id
= r
->res_ls
->ls_global_id
;
124 data
->resource_namelen
= r
->res_length
;
125 memcpy(data
->resource_name
, r
->res_name
, r
->res_length
);
129 void dlm_timeout_warn(struct dlm_lkb
*lkb
)
131 struct dlm_lock_data
*data
;
132 struct sk_buff
*send_skb
;
136 size
= nla_total_size(sizeof(struct dlm_lock_data
)) +
137 nla_total_size(0); /* why this? */
139 rv
= prepare_data(DLM_CMD_TIMEOUT
, &send_skb
, size
);
143 data
= mk_data(send_skb
);
145 nlmsg_free(send_skb
);
149 fill_data(data
, lkb
);