From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, vivien.didelot@savoirfairelinux.com,
andrew@lunn.ch, jiri@resnulli.us,
Florian Fainelli <f.fainelli@gmail.com>
Subject: [PATCH net-next 2/4] net: switchdev: Add object dump deferred operation
Date: Mon, 9 Jan 2017 11:45:01 -0800 [thread overview]
Message-ID: <20170109194503.10713-3-f.fainelli@gmail.com> (raw)
In-Reply-To: <20170109194503.10713-1-f.fainelli@gmail.com>
Add plumbing required to perform dump operations in a deferred context,
this mostly wraps the existing switchdev_obj_port_dump() function into a
switchdev_obj_port_dump_now() and adds two wrappers (normal and
deferred) around.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
net/switchdev/switchdev.c | 71 +++++++++++++++++++++++++++++++++++++----------
1 file changed, 57 insertions(+), 14 deletions(-)
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index 3d70ad02c617..4fa9972d72d2 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -545,26 +545,15 @@ int switchdev_port_obj_del(struct net_device *dev,
}
EXPORT_SYMBOL_GPL(switchdev_port_obj_del);
-/**
- * switchdev_port_obj_dump - Dump port objects
- *
- * @dev: port device
- * @id: object ID
- * @obj: object to dump
- * @cb: function to call with a filled object
- *
- * rtnl_lock must be held.
- */
-int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj,
- switchdev_obj_dump_cb_t *cb)
+static int switchdev_port_obj_dump_now(struct net_device *dev,
+ struct switchdev_obj *obj,
+ switchdev_obj_dump_cb_t *cb)
{
const struct switchdev_ops *ops = dev->switchdev_ops;
struct net_device *lower_dev;
struct list_head *iter;
int err = -EOPNOTSUPP;
- ASSERT_RTNL();
-
if (ops && ops->switchdev_port_obj_dump)
return ops->switchdev_port_obj_dump(dev, obj, cb);
@@ -580,6 +569,60 @@ int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj,
return err;
}
+
+struct switchdev_obj_dump_deferred_item {
+ struct switchdev_obj obj;
+ switchdev_obj_dump_cb_t *cb;
+};
+
+static void switchdev_port_obj_dump_deferred(struct net_device *dev,
+ void *data)
+{
+ struct switchdev_obj_dump_deferred_item *i = data;
+ struct switchdev_obj *obj = &i->obj;
+ int err;
+
+ err = switchdev_port_obj_dump_now(dev, obj, i->cb);
+ if (err && err != -EOPNOTSUPP)
+ netdev_err(dev, "failed (err=%d) to dump object (id=%d)\n",
+ err, obj->id);
+ if (obj->complete)
+ obj->complete(dev, err, obj->complete_priv);
+}
+
+static int switchdev_port_obj_dump_defer(struct net_device *dev,
+ struct switchdev_obj *obj,
+ switchdev_obj_dump_cb_t *cb)
+{
+ struct switchdev_obj_dump_deferred_item item;
+
+ memcpy(&item.obj, obj, switchdev_obj_size(obj));
+ item.cb = cb;
+
+ return switchdev_deferred_enqueue(dev, &item, sizeof(item),
+ NULL,
+ switchdev_port_obj_dump_deferred);
+}
+
+/**
+ * switchdev_port_obj_dump - Dump port objects
+ *
+ * @dev: port device
+ * @id: object ID
+ * @obj: object to dump
+ * @cb: function to call with a filled object
+ *
+ * rtnl_lock must be held and must not be in atomic section,
+ * in case SWITCHDEV_F_DEFER flag is not set.
+ */
+int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj,
+ switchdev_obj_dump_cb_t *cb)
+{
+ if (obj->flags & SWITCHDEV_F_DEFER)
+ return switchdev_port_obj_dump_defer(dev, obj, cb);
+ ASSERT_RTNL();
+ return switchdev_port_obj_dump_now(dev, obj, cb);
+}
EXPORT_SYMBOL_GPL(switchdev_port_obj_dump);
static RAW_NOTIFIER_HEAD(switchdev_notif_chain);
--
2.9.3
next prev parent reply other threads:[~2017-01-09 19:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-09 19:44 [PATCH net-next 0/4] net: switchdev: Avoid sleep in atomic with DSA Florian Fainelli
2017-01-09 19:45 ` [PATCH net-next 1/4] net: switchdev: Prepare for deferred functions modifying objects Florian Fainelli
2017-01-09 19:45 ` Florian Fainelli [this message]
2017-01-09 19:45 ` [PATCH net-next 3/4] net: switchdev: Add switchdev_port_bridge_getlink_deferred Florian Fainelli
2017-01-09 20:11 ` Marcelo Ricardo Leitner
2017-01-09 20:13 ` Florian Fainelli
2017-01-09 20:28 ` Marcelo Ricardo Leitner
2017-01-09 20:29 ` Florian Fainelli
2017-01-10 0:25 ` kbuild test robot
2017-01-09 19:45 ` [PATCH net-next 4/4] net: dsa: Utilize switchdev_port_bridge_getlink_deferred() Florian Fainelli
2017-01-09 20:48 ` [PATCH net-next 0/4] net: switchdev: Avoid sleep in atomic with DSA Ido Schimmel
2017-01-09 20:56 ` Florian Fainelli
2017-01-09 21:14 ` Ido Schimmel
2017-01-09 21:23 ` Andrew Lunn
2017-01-09 21:29 ` Ido Schimmel
2017-01-10 12:08 ` Jiri Pirko
2017-01-10 13:25 ` Ido Schimmel
2017-01-10 14:18 ` Jiri Pirko
2017-01-10 16:08 ` Ido Schimmel
2017-01-10 16:13 ` Jiri Pirko
2017-01-11 1:42 ` Florian Fainelli
2017-01-11 14:59 ` Andrew Lunn
2017-01-09 21:19 ` Vivien Didelot
2017-01-11 1:26 ` David Miller
2017-01-09 21:05 ` Andrew Lunn
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=20170109194503.10713-3-f.fainelli@gmail.com \
--to=f.fainelli@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--cc=vivien.didelot@savoirfairelinux.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).