Skip to content

Commit 34470e0

Browse files
dfriesgregkh
authored andcommitted
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>
1 parent fd1a73c commit 34470e0

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

‎Documentation/connector/connector.txt‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ netlink based networking for inter-process communication in a significantly
2424
easier way:
2525

2626
int cn_add_callback(struct cb_id *id, char *name, void (*callback) (struct cn_msg *, struct netlink_skb_parms *));
27-
void cn_netlink_send(struct cn_msg *msg, u32 __group, int gfp_mask);
27+
void cn_netlink_send_multi(struct cn_msg *msg, u16 len, u32 portid, u32 __group, int gfp_mask);
28+
void cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group, int gfp_mask);
2829

2930
struct cb_id
3031
{
@@ -71,15 +72,21 @@ void cn_del_callback(struct cb_id *id);
7172
struct cb_id *id - unique connector's user identifier.
7273

7374

74-
int cn_netlink_send(struct cn_msg *msg, u32 __groups, int gfp_mask);
75+
int cn_netlink_send_multi(struct cn_msg *msg, u16 len, u32 portid, u32 __groups, int gfp_mask);
76+
int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __groups, int gfp_mask);
7577

7678
Sends message to the specified groups. It can be safely called from
7779
softirq context, but may silently fail under strong memory pressure.
7880
If there are no listeners for given group -ESRCH can be returned.
7981

8082
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.
8188
u32 __group - destination group.
82-
If __group is zero, then appropriate group will
89+
If port and __group is zero, then appropriate group will
8390
be searched through all registered connector users,
8491
and message will be delivered to the group which was
8592
created for user with the same ID as in msg.

‎drivers/connector/connector.c‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ static struct cn_dev cdev;
4343
static int cn_already_initialized;
4444

4545
/*
46+
* Sends mult (multiple) cn_msg at a time.
47+
*
4648
* msg->seq and msg->ack are used to determine message genealogy.
4749
* When someone sends message it puts there locally unique sequence
4850
* and random acknowledge numbers. Sequence number may be copied into
@@ -62,10 +64,13 @@ static int cn_already_initialized;
6264
* the acknowledgement number in the original message + 1, then it is
6365
* a new message.
6466
*
67+
* If msg->len != len, then additional cn_msg messages are expected following
68+
* the first msg.
69+
*
6570
* The message is sent to, the portid if given, the group if given, both if
6671
* both, or if both are zero then the group is looked up and sent there.
6772
*/
68-
int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group,
73+
int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
6974
gfp_t gfp_mask)
7075
{
7176
struct cn_callback_entry *__cbq;
@@ -98,7 +103,7 @@ int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group,
98103
if (!portid && !netlink_has_listeners(dev->nls, group))
99104
return -ESRCH;
100105

101-
size = sizeof(*msg) + msg->len;
106+
size = sizeof(*msg) + len;
102107

103108
skb = nlmsg_new(size, gfp_mask);
104109
if (!skb)
@@ -121,6 +126,14 @@ int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group,
121126
gfp_mask);
122127
return netlink_unicast(dev->nls, skb, portid, !(gfp_mask&__GFP_WAIT));
123128
}
129+
EXPORT_SYMBOL_GPL(cn_netlink_send_mult);
130+
131+
/* same as cn_netlink_send_mult except msg->len is used for len */
132+
int 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+
}
124137
EXPORT_SYMBOL_GPL(cn_netlink_send);
125138

126139
/*

‎include/linux/connector.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct cn_dev {
7171
int cn_add_callback(struct cb_id *id, const char *name,
7272
void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
7373
void cn_del_callback(struct cb_id *);
74+
int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 group, gfp_t gfp_mask);
7475
int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 group, gfp_t gfp_mask);
7576

7677
int cn_queue_add_callback(struct cn_queue_dev *dev, const char *name,

0 commit comments

Comments
 (0)