aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Fries <David@Fries.net>2014-04-08 23:37:08 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-05-27 16:56:21 -0400
commit34470e0bfae223e3f22bd2bd6e0e1dac366c9290 (patch)
treef1c90448f6a4c2b23923498f954a72136ca1392a
parentfd1a73c60ee0bfd3fefc96ad270effd69b350aba (diff)
connector: allow multiple messages to be sent in one packet
This increases the amount of bundling to reduce the number of packets sent. For the one wire use there can be multiple struct w1_netlink_cmd in a struct w1_netlink_msg and multiple of those in struct cn_msg, and with this change multiple of those in a struct nlmsghdr, and at each level the len identifies there being multiple of the next. Signed-off-by: David Fries <David@Fries.net> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--Documentation/connector/connector.txt13
-rw-r--r--drivers/connector/connector.c17
-rw-r--r--include/linux/connector.h1
3 files changed, 26 insertions, 5 deletions
diff --git a/Documentation/connector/connector.txt b/Documentation/connector/connector.txt
index e5c5f5e6ab70..e56abdb21975 100644
--- a/Documentation/connector/connector.txt
+++ b/Documentation/connector/connector.txt
@@ -24,7 +24,8 @@ netlink based networking for inter-process communication in a significantly
24easier way: 24easier way:
25 25
26int cn_add_callback(struct cb_id *id, char *name, void (*callback) (struct cn_msg *, struct netlink_skb_parms *)); 26int cn_add_callback(struct cb_id *id, char *name, void (*callback) (struct cn_msg *, struct netlink_skb_parms *));
27void cn_netlink_send(struct cn_msg *msg, u32 __group, int gfp_mask); 27void cn_netlink_send_multi(struct cn_msg *msg, u16 len, u32 portid, u32 __group, int gfp_mask);
28void cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group, int gfp_mask);
28 29
29struct cb_id 30struct cb_id
30{ 31{
@@ -71,15 +72,21 @@ void cn_del_callback(struct cb_id *id);
71 struct cb_id *id - unique connector's user identifier. 72 struct cb_id *id - unique connector's user identifier.
72 73
73 74
74int cn_netlink_send(struct cn_msg *msg, u32 __groups, int gfp_mask); 75int cn_netlink_send_multi(struct cn_msg *msg, u16 len, u32 portid, u32 __groups, int gfp_mask);
76int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __groups, int gfp_mask);
75 77
76 Sends message to the specified groups. It can be safely called from 78 Sends message to the specified groups. It can be safely called from
77 softirq context, but may silently fail under strong memory pressure. 79 softirq context, but may silently fail under strong memory pressure.
78 If there are no listeners for given group -ESRCH can be returned. 80 If there are no listeners for given group -ESRCH can be returned.
79 81
80 struct cn_msg * - message header(with attached data). 82 struct cn_msg * - message header(with attached data).
83 u16 len - for *_multi multiple cn_msg messages can be sent
84 u32 port - destination port.
85 If non-zero the message will be sent to the
86 given port, which should be set to the
87 original sender.
81 u32 __group - destination group. 88 u32 __group - destination group.
82 If __group is zero, then appropriate group will 89 If port and __group is zero, then appropriate group will
83 be searched through all registered connector users, 90 be searched through all registered connector users,
84 and message will be delivered to the group which was 91 and message will be delivered to the group which was
85 created for user with the same ID as in msg. 92 created for user with the same ID as in msg.
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index b14f1d36f897..f612d68629dc 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -43,6 +43,8 @@ static struct cn_dev cdev;
43static int cn_already_initialized; 43static int cn_already_initialized;
44 44
45/* 45/*
46 * Sends mult (multiple) cn_msg at a time.
47 *
46 * msg->seq and msg->ack are used to determine message genealogy. 48 * msg->seq and msg->ack are used to determine message genealogy.
47 * When someone sends message it puts there locally unique sequence 49 * When someone sends message it puts there locally unique sequence
48 * and random acknowledge numbers. Sequence number may be copied into 50 * and random acknowledge numbers. Sequence number may be copied into
@@ -62,10 +64,13 @@ static int cn_already_initialized;
62 * the acknowledgement number in the original message + 1, then it is 64 * the acknowledgement number in the original message + 1, then it is
63 * a new message. 65 * a new message.
64 * 66 *
67 * If msg->len != len, then additional cn_msg messages are expected following
68 * the first msg.
69 *
65 * The message is sent to, the portid if given, the group if given, both if 70 * The message is sent to, the portid if given, the group if given, both if
66 * both, or if both are zero then the group is looked up and sent there. 71 * both, or if both are zero then the group is looked up and sent there.
67 */ 72 */
68int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group, 73int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
69 gfp_t gfp_mask) 74 gfp_t gfp_mask)
70{ 75{
71 struct cn_callback_entry *__cbq; 76 struct cn_callback_entry *__cbq;
@@ -98,7 +103,7 @@ int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group,
98 if (!portid && !netlink_has_listeners(dev->nls, group)) 103 if (!portid && !netlink_has_listeners(dev->nls, group))
99 return -ESRCH; 104 return -ESRCH;
100 105
101 size = sizeof(*msg) + msg->len; 106 size = sizeof(*msg) + len;
102 107
103 skb = nlmsg_new(size, gfp_mask); 108 skb = nlmsg_new(size, gfp_mask);
104 if (!skb) 109 if (!skb)
@@ -121,6 +126,14 @@ int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group,
121 gfp_mask); 126 gfp_mask);
122 return netlink_unicast(dev->nls, skb, portid, !(gfp_mask&__GFP_WAIT)); 127 return netlink_unicast(dev->nls, skb, portid, !(gfp_mask&__GFP_WAIT));
123} 128}
129EXPORT_SYMBOL_GPL(cn_netlink_send_mult);
130
131/* same as cn_netlink_send_mult except msg->len is used for len */
132int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group,
133 gfp_t gfp_mask)
134{
135 return cn_netlink_send_mult(msg, msg->len, portid, __group, gfp_mask);
136}
124EXPORT_SYMBOL_GPL(cn_netlink_send); 137EXPORT_SYMBOL_GPL(cn_netlink_send);
125 138
126/* 139/*
diff --git a/include/linux/connector.h b/include/linux/connector.h
index be9c4747d511..f8fe8637d771 100644
--- a/include/linux/connector.h
+++ b/include/linux/connector.h
@@ -71,6 +71,7 @@ struct cn_dev {
71int cn_add_callback(struct cb_id *id, const char *name, 71int cn_add_callback(struct cb_id *id, const char *name,
72 void (*callback)(struct cn_msg *, struct netlink_skb_parms *)); 72 void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
73void cn_del_callback(struct cb_id *); 73void cn_del_callback(struct cb_id *);
74int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 group, gfp_t gfp_mask);
74int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 group, gfp_t gfp_mask); 75int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 group, gfp_t gfp_mask);
75 76
76int cn_queue_add_callback(struct cn_queue_dev *dev, const char *name, 77int cn_queue_add_callback(struct cn_queue_dev *dev, const char *name,