From: Stephen Hemminger <stephen@networkplumber.org>
To: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Cc: netdev@vger.kernel.org, roopa@cumulusnetworks.com,
anuradhak@cumulusnetworks.com, bridge@lists.linux-foundation.org,
wkok@cumulusnetworks.com, davem@davemloft.net
Subject: Re: [PATCH net-next 1/2] net: bridge: add support for raw sysfs port options
Date: Fri, 20 Jul 2018 08:57:25 -0700 [thread overview]
Message-ID: <20180720085725.6dc1743d@xeon-e3> (raw)
In-Reply-To: <20180720144826.29892-2-nikolay@cumulusnetworks.com>
On Fri, 20 Jul 2018 17:48:25 +0300
Nikolay Aleksandrov <nikolay@cumulusnetworks.com> wrote:
> This patch adds a new alternative store callback for port sysfs options
> which takes a raw value (buf) and can use it directly. It is needed for the
> backup port sysfs support since we have to pass the device by its name.
>
> Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
> ---
> There are a few checkpatch warnings here because of the old code, I've
> noted them in my todo and will send separate patch for simple_strtoul
> and the function prototypes.
>
> net/bridge/br_sysfs_if.c | 49 +++++++++++++++++++++++++++++++++---------------
> 1 file changed, 34 insertions(+), 15 deletions(-)
>
> diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
> index f99c5bf5c906..38c58879423d 100644
> --- a/net/bridge/br_sysfs_if.c
> +++ b/net/bridge/br_sysfs_if.c
> @@ -25,6 +25,15 @@ struct brport_attribute {
> struct attribute attr;
> ssize_t (*show)(struct net_bridge_port *, char *);
> int (*store)(struct net_bridge_port *, unsigned long);
> + int (*store_raw)(struct net_bridge_port *, char *);
> +};
> +
> +#define BRPORT_ATTR_RAW(_name, _mode, _show, _store) \
> +const struct brport_attribute brport_attr_##_name = { \
> + .attr = {.name = __stringify(_name), \
> + .mode = _mode }, \
> + .show = _show, \
> + .store_raw = _store, \
> };
>
> #define BRPORT_ATTR(_name, _mode, _show, _store) \
> @@ -270,27 +279,37 @@ static ssize_t brport_store(struct kobject *kobj,
> struct brport_attribute *brport_attr = to_brport_attr(attr);
> struct net_bridge_port *p = to_brport(kobj);
> ssize_t ret = -EINVAL;
> - char *endp;
> unsigned long val;
> + char *endp;
>
> if (!ns_capable(dev_net(p->dev)->user_ns, CAP_NET_ADMIN))
> return -EPERM;
>
> - val = simple_strtoul(buf, &endp, 0);
> - if (endp != buf) {
> - if (!rtnl_trylock())
> - return restart_syscall();
> - if (p->dev && p->br && brport_attr->store) {
> - spin_lock_bh(&p->br->lock);
> - ret = brport_attr->store(p, val);
> - spin_unlock_bh(&p->br->lock);
> - if (!ret) {
> - br_ifinfo_notify(RTM_NEWLINK, NULL, p);
> - ret = count;
> - }
> - }
> - rtnl_unlock();
> + if (!rtnl_trylock())
> + return restart_syscall();
> +
> + if (!p->dev || !p->br)
> + goto out_unlock;
> +
> + if (brport_attr->store_raw) {
> + spin_lock_bh(&p->br->lock);
> + ret = brport_attr->store_raw(p, (char *)buf);
> + spin_unlock_bh(&p->br->lock);
> + } else if (brport_attr->store) {
> + val = simple_strtoul(buf, &endp, 0);
> + if (endp == buf)
> + goto out_unlock;
> + spin_lock_bh(&p->br->lock);
> + ret = brport_attr->store(p, val);
> + spin_unlock_bh(&p->br->lock);
> + }
> + if (!ret) {
> + br_ifinfo_notify(RTM_NEWLINK, NULL, p);
> + ret = count;
> }
> +out_unlock:
> + rtnl_unlock();
> +
> return ret;
> }
>
I see where you are going with this. You want a sysfs attribute where is a string
not a number. This makes sense.
The code might be simpler if you always acquired the lock. Or maybe
move the locking into the store functions.
Casting away the const on the buf variable is going to cause warnings
and should not be necessary.
You might also want an error case if neither store or store_raw are defined.
next prev parent reply other threads:[~2018-07-20 16:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-20 14:48 [PATCH net-next 0/2] net: bridge: add support for backup port Nikolay Aleksandrov
2018-07-20 14:48 ` [PATCH net-next 1/2] net: bridge: add support for raw sysfs port options Nikolay Aleksandrov
2018-07-20 15:57 ` Stephen Hemminger [this message]
2018-07-20 17:14 ` Nikolay Aleksandrov
2018-07-20 17:20 ` Stephen Hemminger
2018-07-20 17:26 ` Nikolay Aleksandrov
2018-07-20 17:47 ` Nikolay Aleksandrov
2018-07-20 21:14 ` Stephen Hemminger
2018-07-22 6:27 ` David Miller
2018-07-22 7:41 ` Nikolay Aleksandrov
2018-07-20 14:48 ` [PATCH net-next 2/2] net: bridge: add support for backup port Nikolay Aleksandrov
2018-07-20 16:02 ` Stephen Hemminger
2018-07-20 16:41 ` Roopa Prabhu
2018-07-23 6:15 ` Toshiaki Makita
2018-07-23 8:03 ` Nikolay Aleksandrov
2018-07-20 15:22 ` [PATCH net-next 0/2] " Stephen Hemminger
2018-07-20 15:26 ` Nikolay Aleksandrov
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=20180720085725.6dc1743d@xeon-e3 \
--to=stephen@networkplumber.org \
--cc=anuradhak@cumulusnetworks.com \
--cc=bridge@lists.linux-foundation.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=nikolay@cumulusnetworks.com \
--cc=roopa@cumulusnetworks.com \
--cc=wkok@cumulusnetworks.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;
as well as URLs for NNTP newsgroup(s).