From: Jiri Pirko <jiri@resnulli.us>
To: ecree@xilinx.com
Cc: netdev@vger.kernel.org, linux-net-drivers@amd.com,
davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
edumazet@google.com, habetsm.xilinx@gmail.com,
johannes@sipsolutions.net, marcelo.leitner@gmail.com,
Edward Cree <ecree.xilinx@gmail.com>
Subject: Re: [RFC PATCH net-next 1/3] netlink: add support for formatted extack messages
Date: Thu, 13 Oct 2022 14:55:42 +0200 [thread overview]
Message-ID: <Y0gKzgmWSgw/+4Oc@nanopsycho> (raw)
In-Reply-To: <a01a9a1539c22800b2a5827cf234756f13fa6b97.1665147129.git.ecree.xilinx@gmail.com>
Fri, Oct 07, 2022 at 03:25:12PM CEST, ecree@xilinx.com wrote:
>From: Edward Cree <ecree.xilinx@gmail.com>
>
>Include an 80-byte buffer in struct netlink_ext_ack that can be used
> for scnprintf()ed messages. This does mean that the resulting string
> can't be enumerated, translated etc. in the way NL_SET_ERR_MSG() was
> designed to allow.
>
>Signed-off-by: Edward Cree <ecree.xilinx@gmail.com>
>---
> include/linux/netlink.h | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
>diff --git a/include/linux/netlink.h b/include/linux/netlink.h
>index d51e041d2242..bfab9dbd64fa 100644
>--- a/include/linux/netlink.h
>+++ b/include/linux/netlink.h
>@@ -64,6 +64,7 @@ netlink_kernel_create(struct net *net, int unit, struct netlink_kernel_cfg *cfg)
>
> /* this can be increased when necessary - don't expose to userland */
> #define NETLINK_MAX_COOKIE_LEN 20
>+#define NETLINK_MAX_FMTMSG_LEN 80
>
> /**
> * struct netlink_ext_ack - netlink extended ACK report struct
>@@ -75,6 +76,8 @@ netlink_kernel_create(struct net *net, int unit, struct netlink_kernel_cfg *cfg)
> * @miss_nest: nest missing an attribute (%NULL if missing top level attr)
> * @cookie: cookie data to return to userspace (for success)
> * @cookie_len: actual cookie data length
>+ * @_msg_buf: output buffer for formatted message strings - don't access
>+ * directly, use %NL_SET_ERR_MSG_FMT
> */
> struct netlink_ext_ack {
> const char *_msg;
>@@ -84,13 +87,13 @@ struct netlink_ext_ack {
> u16 miss_type;
> u8 cookie[NETLINK_MAX_COOKIE_LEN];
> u8 cookie_len;
>+ char _msg_buf[NETLINK_MAX_FMTMSG_LEN];
> };
>
> /* Always use this macro, this allows later putting the
> * message into a separate section or such for things
> * like translation or listing all possible messages.
>- * Currently string formatting is not supported (due
>- * to the lack of an output buffer.)
>+ * If string formatting is needed use NL_SET_ERR_MSG_FMT.
> */
> #define NL_SET_ERR_MSG(extack, msg) do { \
> static const char __msg[] = msg; \
>@@ -102,9 +105,23 @@ struct netlink_ext_ack {
> __extack->_msg = __msg; \
> } while (0)
>
>+#define NL_SET_ERR_MSG_FMT(extack, fmt, args...) do { \
>+ struct netlink_ext_ack *__extack = (extack); \
>+ \
>+ scnprintf(__extack->_msg_buf, NETLINK_MAX_FMTMSG_LEN, \
>+ (fmt), ##args); \
>+ do_trace_netlink_extack(__extack->_msg_buf); \
>+ \
>+ if (__extack) \
>+ __extack->_msg = __extack->_msg_buf; \
>+} while (0)
>+
> #define NL_SET_ERR_MSG_MOD(extack, msg) \
> NL_SET_ERR_MSG((extack), KBUILD_MODNAME ": " msg)
>
>+#define NL_SET_ERR_MSG_FMT_MOD(extack, fmt, args...) \
I wonder, wouldn't it be better to just have NL_SET_ERR_MSG_MOD which
accepts format string and that's it. I understand there is an extra
overhead for the messages that don't use formatting, but do we care?
This is no fastpath and usually happens only seldom. The API towards
the driver would be more simple.
I like this a lot!
>+ NL_SET_ERR_MSG_FMT((extack), KBUILD_MODNAME ": " fmt, ##args)
>+
> #define NL_SET_BAD_ATTR_POLICY(extack, attr, pol) do { \
> if ((extack)) { \
> (extack)->bad_attr = (attr); \
next prev parent reply other threads:[~2022-10-13 12:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-07 13:25 [RFC PATCH net-next 0/3] netlink: formatted extacks ecree
2022-10-07 13:25 ` [RFC PATCH net-next 1/3] netlink: add support for formatted extack messages ecree
2022-10-07 13:35 ` Johannes Berg
2022-10-07 13:46 ` Edward Cree
2022-10-07 13:49 ` Johannes Berg
2022-10-07 13:58 ` Edward Cree
2022-10-13 12:59 ` Jiri Pirko
2022-10-13 13:35 ` Edward Cree
2022-10-07 18:32 ` Jakub Kicinski
2022-10-13 12:55 ` Jiri Pirko [this message]
2022-10-17 12:00 ` Edward Cree
2022-10-17 18:44 ` Jakub Kicinski
2022-10-07 13:25 ` [RFC PATCH net-next 2/3] sfc: use formatted extacks instead of efx_tc_err() ecree
2022-10-07 13:25 ` [RFC PATCH net-next 3/3] sfc: remove 'log-tc-errors' ethtool private flag ecree
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y0gKzgmWSgw/+4Oc@nanopsycho \
--to=jiri@resnulli.us \
--cc=davem@davemloft.net \
--cc=ecree.xilinx@gmail.com \
--cc=ecree@xilinx.com \
--cc=edumazet@google.com \
--cc=habetsm.xilinx@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-net-drivers@amd.com \
--cc=marcelo.leitner@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox