Skip to contentSkip to conversation

: pkt_sched: Manage qdisc_ops grab/release outside of qdisc_create.

PATCH In review David Miller 1 participant 1 message Jul 14, 2008

Subsystems (3)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

PATCH 3/14 : pkt_sched: Manage qdisc_ops grab/release outside of qdisc_create.

Let the caller do this. That way, when we replicate qdisc creation for multiple queues, we only have to do the ops lookup and management once outside of the for-each-netdev-queue loop.

---
 net/sched/sch_api.c |   54 ++++++++++++++++++++++++++++----------------------
 1 files changed, 30 insertions(+), 24 deletions(-)
net/sched/sch_api.c +30 -24
index 3ed3b32..b0da006 100644
@@ -555,20 +555,15 @@ static int qdisc_graft(struct netdev_queue *dev_queue, struct Qdisc *parent,
 	return err;
 }
 
-/* Allocate and initialize new qdisc.  Parameters are passed via tca.  */
-
-static struct Qdisc *
-qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
-	     u32 parent, u32 handle, struct nlattr **tca, int *errp)
+static struct Qdisc_ops *tc_grab_ops(struct nlattr *kind)
 {
-	int err;
-	struct nlattr *kind = tca[TCA_KIND];
-	struct Qdisc *sch;
-	struct Qdisc_ops *ops;
+	struct Qdisc_ops *ops = qdisc_lookup_ops(kind);
+
+	if (ops)
+		return ops;
 
-	ops = qdisc_lookup_ops(kind);
 #ifdef CONFIG_KMOD
-	if (ops == NULL && kind != NULL) {
+	if (kind) {
 		char name[IFNAMSIZ];
 		if (nla_strlcpy(name, kind, IFNAMSIZ) < IFNAMSIZ) {
 			/* We dropped the RTNL semaphore in order to
@@ -588,21 +583,28 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
 				 * so don't keep a reference.
 				 */
 				module_put(ops->owner);
-				err = -EAGAIN;
-				goto err_out;
+				return ERR_PTR(-EAGAIN);
 			}
 		}
 	}
 #endif
+	return ERR_PTR(-ENOENT);
+}
 
-	err = -ENOENT;
-	if (ops == NULL)
-		goto err_out;
+/* Allocate and initialize new qdisc.  Parameters are passed via tca.  */
+
+static struct Qdisc *
+qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
+	     struct Qdisc_ops *ops,
+	     u32 parent, u32 handle, struct nlattr **tca, int *errp)
+{
+	int err;
+	struct Qdisc *sch;
 
 	sch = qdisc_alloc(dev_queue, ops);
 	if (IS_ERR(sch)) {
 		err = PTR_ERR(sch);
-		goto err_out2;
+		goto err_out;
 	}
 
 	sch->parent = parent;
@@ -615,7 +617,7 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
 			handle = qdisc_alloc_handle(dev);
 			err = -ENOMEM;
 			if (handle == 0)
-				goto err_out3;
+				goto err_out_dev_put;
 		}
 	}
 
@@ -634,7 +636,7 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
 				 */
 				if (ops->destroy)
 					ops->destroy(sch);
-				goto err_out3;
+				goto err_out_dev_put;
 			}
 		}
 		qdisc_lock_tree(dev);
@@ -643,11 +645,9 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
 
 		return sch;
 	}
-err_out3:
+err_out_dev_put:
 	dev_put(dev);
 	kfree((char *) sch - sch->padded);
-err_out2:
-	module_put(ops->owner);
 err_out:
 	*errp = err;
 	return NULL;
@@ -786,12 +786,18 @@ static struct Qdisc *tc_create(struct net_device *dev,
 			       u32 parent, u32 handle,
 			       struct nlattr **tca)
 {
+	struct Qdisc_ops *ops = tc_grab_ops(tca[TCA_KIND]);
 	struct Qdisc *q;
 	int err = 0;
 
-	q = qdisc_create(dev, dev_queue, parent, handle, tca, &err);
-	if (unlikely(!q))
+	if (IS_ERR(ops))
+		return ERR_PTR(PTR_ERR(ops));
+
+	q = qdisc_create(dev, dev_queue, ops, parent, handle, tca, &err);
+	if (unlikely(!q)) {
+		module_put(ops->owner);
 		return ERR_PTR(err);
+	}
 
 	return q;
 }
Signature · 1 line
1.5.6.2.255.gbed62