Add genetlink utilities for payload length calculation
Subsystems (4)
RFC PATCH 1/1 Add genetlink utilities for payload length calculation
Add two utility helper functions genlmsg_msg_size() and genlmsg_total_size(). These functions are derived from their netlink counterparts.
---
include/net/genetlink.h | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+)
include/net/genetlink.h renamed from include/net/genetlink.h~genetlink-payload-size-helpers +18 -0
@@ -171,4 +171,22 @@ static inline int genlmsg_len(const stru return (nlh->nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN); } +/** +* genlmsg_msg_size - length of genetlink message not including padding +* @payload: length of message payload +*/ +static inline int genlmsg_msg_size (int payload) +{ +return GENL_HDRLEN + payload; +} + +/** +* genlmsg_total_size - length of genetlink message including padding +* @payload: length of message payload +*/ +static inline int genlmsg_total_size (int payload) +{ +return NLMSG_ALIGN (genlmsg_msg_size (payload)); +} +#endif /* __NET_GENERIC_NETLINK_H */
_
Signature · 3 lines
Balbir Singh, Linux Technology Center, IBM Software Labs
RFC PATCH 1/1 Fix getdelays.c - cpumask length and error reporting.
Fix the length passed while (un)registering cpumask. We were passing sizeof the array, make it strlen().
Error value printed in fatal errors should be derived from the message. The message contains an nlmsgerr embedded with an error value. We must report that value to the user.
---
Documentation/accounting/getdelays.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
Documentation/accounting/getdelays.c renamed from Documentation/accounting/getdelays.c~taskstats-fix-delayacct-utility +4 -3
@@ -285,7 +285,7 @@ int main(int argc, char *argv[])if (maskset) { rc =send_cmd (nl_sd, id, mypid,TASKSTATS_CMD_GET ,TASKSTATS_CMD_ATTR_REGISTER_CPUMASK , - &cpumask,sizeof (cpumask)); + &cpumask,strlen (cpumask) +1 );PRINTF ("Sent register cpumask, retval %d\n" , rc);if (rc <0 ) {printf ("error sending register cpumask\n" );
@@ -315,7 +315,8 @@ int main(int argc, char *argv[]) }if (msg.n.nlmsg_type ==NLMSG_ERROR || !NLMSG_OK ((&msg.n), rep_len)) { -printf ("fatal reply error, errno %d\n" , errno); +struct nlmsgerr *err =NLMSG_DATA (&msg); +printf ("fatal reply error, errno %d\n" , err->error); goto done; }
@@ -383,7 +384,7 @@ done:if (maskset) { rc =send_cmd (nl_sd, id, mypid,TASKSTATS_CMD_GET ,TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK , - &cpumask,sizeof (cpumask)); + &cpumask,strlen (cpumask) +1 );printf ("Sent deregister mask, retval %d\n" , rc);if (rc <0 )err (rc,"error sending deregister cpumask\n" );
_
Signature · 3 lines
Balbir Singh, Linux Technology Center, IBM Software Labs
RFC PATCH 1/1 Fix taskstats size calculation (use the new genetlink utility functions)
In reply to Balbir SinghThe addition of the CSA patch pushed the size of struct taskstats to 256 bytes. This exposed a problem with prepare_reply(), we were not allocating space for the netlink and genetlink header. It worked earlier because alloc_skb() would align the skb to SMP_CACHE_BYTES, which added some additonal bytes.
---
kernel/taskstats.c | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-)
kernel/taskstats.c renamed from kernel/taskstats.c~taskstats-fix-msg-size +1 -1
@@ -77,7 +77,7 @@ static int prepare_reply(struct genl_inf/* * If new attributes are added, please revisit this allocation */ - skb =nlmsg_new (size,GFP_KERNEL ); + skb =nlmsg_new (genlmsg_total_size (size),GFP_KERNEL );if (!skb)return -ENOMEM ;
_
Signature · 3 lines
Balbir Singh, Linux Technology Center, IBM Software Labs