From: Stephen Hemminger <stephen@networkplumber.org>
To: Nishanth Devarajan <ndev2021@gmail.com>
Cc: netdev@vger.kernel.org, doucette@bu.edu, michel.machado@gmail.com
Subject: Re: [PATCH iproute2/net-next v2]tc: B.W limits can now be specified in %.
Date: Wed, 15 Nov 2017 09:58:56 -0800 [thread overview]
Message-ID: <20171115095856.591ee0a9@xeon-e3> (raw)
In-Reply-To: <20171115013618.GA19575@gmail.com>
On Wed, 15 Nov 2017 07:06:21 +0530
Nishanth Devarajan <ndev2021@gmail.com> wrote:
> int parse_percent_rate(char *rate, const char *str, char *dev)
You aren't modifyin dev so it should be const char *
> +{
> + long max_rate_bits;
> + int ret, saved_errno;
> + double perc, rate_bits;
> + char *str_perc, *p;
> +
> + if (!dev[0]) {
> + fprintf(stderr, "No device specified; specify device to rate limit by percentage\n");
> + return -1;
> + }
> +
> + if (read_prop(dev, "speed", &max_rate_bits))
> + return -1;
If speed is unknown, then many will devices will return -1.
You need to handle that.
Since speed reported by kernel is in mbits per second, it
would make sense to rename max_rate_bits to mbit.
> +
> + ret = sscanf(str, "%m[0-9.%]", &str_perc);
> + if (ret != 1)
> + goto malf;
> +
> + /* Make sure there's only one percent sign and it's at the end */
> + perc = strtod(str_perc, &p);
> + if (*p != '%' || *(p++) != '\0')
> + goto malf;
There already is parse_percent in tc/q_netem.c.
Please move that to util and use that instead of coding here.
> +
> + saved_errno = errno;
> + free(str_perc);
> +
> + if (perc > 100.0 || perc < 0.0 || saved_errno == ERANGE) {
> + fprintf(stderr, "Invalid rate specified; should be between [0,100]%% but is %s\n", str);
> + return -1;
> + }
> +
> + rate_bits = (perc * max_rate_bits) / 100.0;
> +
> + ret = snprintf(rate, 20, "%lf", rate_bits);
> + if (ret <= 0 || ret >= 20) {
> + fprintf(stderr, "Unable to parse calculated rate\n");
> + return -1;
> + }
> +
> + return 0;
> +
> +malf:
> + fprintf(stderr, "Specified rate value could not be read or is malformed\n");
> + return -1;
> +}
prev parent reply other threads:[~2017-11-15 17:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-15 1:36 [PATCH iproute2/net-next v2]tc: B.W limits can now be specified in % Nishanth Devarajan
2017-11-15 8:13 ` Jakub Kicinski
2017-11-15 17:58 ` Stephen Hemminger [this message]
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=20171115095856.591ee0a9@xeon-e3 \
--to=stephen@networkplumber.org \
--cc=doucette@bu.edu \
--cc=michel.machado@gmail.com \
--cc=ndev2021@gmail.com \
--cc=netdev@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.