[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 04/14] qemu-nbd: Simplify --partition handling
From: |
Richard W.M. Jones |
Subject: |
Re: [Qemu-devel] [PATCH 04/14] qemu-nbd: Simplify --partition handling |
Date: |
Fri, 30 Nov 2018 22:26:45 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Fri, Nov 30, 2018 at 04:03:33PM -0600, Eric Blake wrote:
> Our open-coding of strtol handling forgot to handle overflow
> conditions. What's more, since we insiste on a user-supplied
"insist"
> partition to be non-zero, we can use 0 rather than -1 for our
> initial value to distinguish when a partition is not being
> served, for slightly more optimal code.
>
> Signed-off-by: Eric Blake <address@hidden>
> ---
> qemu-nbd.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index 55e29bd9a7e..866e64779f1 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -546,7 +546,7 @@ int main(int argc, char **argv)
> int opt_ind = 0;
> char *end;
> int flags = BDRV_O_RDWR;
> - int partition = -1;
> + int partition = 0;
> int ret = 0;
> bool seen_cache = false;
> bool seen_discard = false;
> @@ -685,13 +685,9 @@ int main(int argc, char **argv)
> flags &= ~BDRV_O_RDWR;
> break;
> case 'P':
> - partition = strtol(optarg, &end, 0);
> - if (*end) {
> - error_report("Invalid partition `%s'", optarg);
> - exit(EXIT_FAILURE);
> - }
> - if (partition < 1 || partition > 8) {
> - error_report("Invalid partition %d", partition);
> + if (qemu_strtoi(optarg, NULL, 0, &partition) < 0 ||
> + partition < 1 || partition > 8) {
> + error_report("Invalid partition %s", optarg);
Pffft only supporting a mere 8 partitions :-? I raised the limits in
nbdkit recently so it can handle an infinite number of partitions :-)
Anyway, it's a problem with the existing code, so doesn't affect the
review.
> exit(EXIT_FAILURE);
> }
> break;
> @@ -1004,7 +1000,7 @@ int main(int argc, char **argv)
> }
> fd_size -= dev_offset;
>
> - if (partition != -1) {
> + if (partition) {
> ret = find_partition(blk, partition, &dev_offset, &fd_size);
> if (ret < 0) {
> error_report("Could not find partition %d: %s", partition,
> --
> 2.17.2
Reviewed-by: Richard W.M. Jones <address@hidden>
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
- [Qemu-devel] [PATCH for-4.0 00/14] nbd: add qemu-nbd --list, Eric Blake, 2018/11/30
- [Qemu-devel] [PATCH 04/14] qemu-nbd: Simplify --partition handling, Eric Blake, 2018/11/30
- Re: [Qemu-devel] [PATCH 04/14] qemu-nbd: Simplify --partition handling,
Richard W.M. Jones <=
- [Qemu-devel] [PATCH 05/14] nbd/client: Drop pointless buf variable, Eric Blake, 2018/11/30
- [Qemu-devel] [PATCH 01/14] qemu-nbd: Use program name in error messages, Eric Blake, 2018/11/30
- [Qemu-devel] [PATCH 06/14] nbd/client: Move export name into NBDExportInfo, Eric Blake, 2018/11/30
- [Qemu-devel] [PATCH 02/14] nbd/client: More consistent error messages, Eric Blake, 2018/11/30