net/sched: mqprio: refactor nlattr parsing to a separate function
mqprio_init() is quite large and unwieldy to add more code to. Split the netlink attribute parsing to a dedicated function. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
8437114593
commit
feb2cf3dcf
1 changed files with 63 additions and 51 deletions
|
@ -130,42 +130,14 @@ static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int mqprio_init(struct Qdisc *sch, struct nlattr *opt,
|
||||
struct netlink_ext_ack *extack)
|
||||
static int mqprio_parse_nlattr(struct Qdisc *sch, struct tc_mqprio_qopt *qopt,
|
||||
struct nlattr *opt)
|
||||
{
|
||||
struct net_device *dev = qdisc_dev(sch);
|
||||
struct mqprio_sched *priv = qdisc_priv(sch);
|
||||
struct netdev_queue *dev_queue;
|
||||
struct Qdisc *qdisc;
|
||||
int i, err = -EOPNOTSUPP;
|
||||
struct tc_mqprio_qopt *qopt = NULL;
|
||||
struct nlattr *tb[TCA_MQPRIO_MAX + 1];
|
||||
struct nlattr *attr;
|
||||
int rem;
|
||||
int len;
|
||||
int i, rem, err;
|
||||
|
||||
BUILD_BUG_ON(TC_MAX_QUEUE != TC_QOPT_MAX_QUEUE);
|
||||
BUILD_BUG_ON(TC_BITMASK != TC_QOPT_BITMASK);
|
||||
|
||||
if (sch->parent != TC_H_ROOT)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (!netif_is_multiqueue(dev))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
/* make certain can allocate enough classids to handle queues */
|
||||
if (dev->num_tx_queues >= TC_H_MIN_PRIORITY)
|
||||
return -ENOMEM;
|
||||
|
||||
if (!opt || nla_len(opt) < sizeof(*qopt))
|
||||
return -EINVAL;
|
||||
|
||||
qopt = nla_data(opt);
|
||||
if (mqprio_parse_opt(dev, qopt))
|
||||
return -EINVAL;
|
||||
|
||||
len = nla_len(opt) - NLA_ALIGN(sizeof(*qopt));
|
||||
if (len > 0) {
|
||||
err = parse_attr(tb, TCA_MQPRIO_MAX, opt, mqprio_policy,
|
||||
sizeof(*qopt));
|
||||
if (err < 0)
|
||||
|
@ -215,6 +187,46 @@ static int mqprio_init(struct Qdisc *sch, struct nlattr *opt,
|
|||
}
|
||||
priv->flags |= TC_MQPRIO_F_MAX_RATE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mqprio_init(struct Qdisc *sch, struct nlattr *opt,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct net_device *dev = qdisc_dev(sch);
|
||||
struct mqprio_sched *priv = qdisc_priv(sch);
|
||||
struct netdev_queue *dev_queue;
|
||||
struct Qdisc *qdisc;
|
||||
int i, err = -EOPNOTSUPP;
|
||||
struct tc_mqprio_qopt *qopt = NULL;
|
||||
int len;
|
||||
|
||||
BUILD_BUG_ON(TC_MAX_QUEUE != TC_QOPT_MAX_QUEUE);
|
||||
BUILD_BUG_ON(TC_BITMASK != TC_QOPT_BITMASK);
|
||||
|
||||
if (sch->parent != TC_H_ROOT)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (!netif_is_multiqueue(dev))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
/* make certain can allocate enough classids to handle queues */
|
||||
if (dev->num_tx_queues >= TC_H_MIN_PRIORITY)
|
||||
return -ENOMEM;
|
||||
|
||||
if (!opt || nla_len(opt) < sizeof(*qopt))
|
||||
return -EINVAL;
|
||||
|
||||
qopt = nla_data(opt);
|
||||
if (mqprio_parse_opt(dev, qopt))
|
||||
return -EINVAL;
|
||||
|
||||
len = nla_len(opt) - NLA_ALIGN(sizeof(*qopt));
|
||||
if (len > 0) {
|
||||
err = mqprio_parse_nlattr(sch, qopt, opt);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
/* pre-allocate qdisc, attachment can't fail */
|
||||
|
|
Loading…
Add table
Reference in a new issue