Blame view

fs/dlm/netlink.c 2.87 KB
3ae1acf93   David Teigland   [DLM] add lock ti...
1
2
3
4
5
6
7
8
9
10
11
  /*
   * Copyright (C) 2007 Red Hat, Inc.  All rights reserved.
   *
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU General Public License v.2.
   */
  
  #include <net/genetlink.h>
  #include <linux/dlm.h>
  #include <linux/dlm_netlink.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
12
  #include <linux/gfp.h>
3ae1acf93   David Teigland   [DLM] add lock ti...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  
  #include "dlm_internal.h"
  
  static uint32_t dlm_nl_seqnum;
  static uint32_t listener_nlpid;
  
  static struct genl_family family = {
  	.id		= GENL_ID_GENERATE,
  	.name		= DLM_GENL_NAME,
  	.version	= DLM_GENL_VERSION,
  };
  
  static int prepare_data(u8 cmd, struct sk_buff **skbp, size_t size)
  {
  	struct sk_buff *skb;
  	void *data;
573c24c4a   David Teigland   dlm: always use G...
29
  	skb = genlmsg_new(size, GFP_NOFS);
3ae1acf93   David Teigland   [DLM] add lock ti...
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  	if (!skb)
  		return -ENOMEM;
  
  	/* add the message headers */
  	data = genlmsg_put(skb, 0, dlm_nl_seqnum++, &family, 0, cmd);
  	if (!data) {
  		nlmsg_free(skb);
  		return -EINVAL;
  	}
  
  	*skbp = skb;
  	return 0;
  }
  
  static struct dlm_lock_data *mk_data(struct sk_buff *skb)
  {
  	struct nlattr *ret;
  
  	ret = nla_reserve(skb, DLM_TYPE_LOCK, sizeof(struct dlm_lock_data));
  	if (!ret)
  		return NULL;
  	return nla_data(ret);
  }
  
  static int send_data(struct sk_buff *skb)
  {
  	struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data);
  	void *data = genlmsg_data(genlhdr);
  	int rv;
  
  	rv = genlmsg_end(skb, data);
  	if (rv < 0) {
  		nlmsg_free(skb);
  		return rv;
  	}
134e63756   Johannes Berg   genetlink: make n...
65
  	return genlmsg_unicast(&init_net, skb, listener_nlpid);
3ae1acf93   David Teigland   [DLM] add lock ti...
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  }
  
  static int user_cmd(struct sk_buff *skb, struct genl_info *info)
  {
  	listener_nlpid = info->snd_pid;
  	printk("user_cmd nlpid %u
  ", listener_nlpid);
  	return 0;
  }
  
  static struct genl_ops dlm_nl_ops = {
  	.cmd		= DLM_CMD_HELLO,
  	.doit		= user_cmd,
  };
30727174b   Denis Cheng   dlm: add __init a...
80
  int __init dlm_netlink_init(void)
3ae1acf93   David Teigland   [DLM] add lock ti...
81
  {
a4d935bd9   Changli Gao   dlm: use genl_reg...
82
  	return genl_register_family_with_ops(&family, &dlm_nl_ops, 1);
3ae1acf93   David Teigland   [DLM] add lock ti...
83
  }
88ad23195   Leonardo Potenza   dlm: section mism...
84
  void dlm_netlink_exit(void)
3ae1acf93   David Teigland   [DLM] add lock ti...
85
  {
3ae1acf93   David Teigland   [DLM] add lock ti...
86
87
88
89
90
91
  	genl_unregister_family(&family);
  }
  
  static void fill_data(struct dlm_lock_data *data, struct dlm_lkb *lkb)
  {
  	struct dlm_rsb *r = lkb->lkb_resource;
3ae1acf93   David Teigland   [DLM] add lock ti...
92
93
94
95
96
97
98
99
100
101
102
  
  	memset(data, 0, sizeof(struct dlm_lock_data));
  
  	data->version = DLM_LOCK_DATA_VERSION;
  	data->nodeid = lkb->lkb_nodeid;
  	data->ownpid = lkb->lkb_ownpid;
  	data->id = lkb->lkb_id;
  	data->remid = lkb->lkb_remid;
  	data->status = lkb->lkb_status;
  	data->grmode = lkb->lkb_grmode;
  	data->rqmode = lkb->lkb_rqmode;
d292c0cc4   David Teigland   dlm: eliminate as...
103
104
  	if (lkb->lkb_ua)
  		data->xid = lkb->lkb_ua->xid;
3ae1acf93   David Teigland   [DLM] add lock ti...
105
106
107
108
109
110
111
112
113
  	if (r) {
  		data->lockspace_id = r->res_ls->ls_global_id;
  		data->resource_namelen = r->res_length;
  		memcpy(data->resource_name, r->res_name, r->res_length);
  	}
  }
  
  void dlm_timeout_warn(struct dlm_lkb *lkb)
  {
180b65df7   Ingo Molnar   fix warning in fs...
114
  	struct sk_buff *uninitialized_var(send_skb);
3ae1acf93   David Teigland   [DLM] add lock ti...
115
  	struct dlm_lock_data *data;
3ae1acf93   David Teigland   [DLM] add lock ti...
116
117
  	size_t size;
  	int rv;
3ae1acf93   David Teigland   [DLM] add lock ti...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  	size = nla_total_size(sizeof(struct dlm_lock_data)) +
  	       nla_total_size(0); /* why this? */
  
  	rv = prepare_data(DLM_CMD_TIMEOUT, &send_skb, size);
  	if (rv < 0)
  		return;
  
  	data = mk_data(send_skb);
  	if (!data) {
  		nlmsg_free(send_skb);
  		return;
  	}
  
  	fill_data(data, lkb);
  
  	send_data(send_skb);
  }