[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend. |
Date: |
Wed, 26 Sep 2012 18:38:02 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1 |
Il 26/09/2012 18:11, Bharata B Rao ha scritto:
>>> +static int parse_volume_options(GlusterConf *gconf, char *path)
>>> > > +{
>>> > > + char *token, *saveptr;
>>> > > +
>>> > > + /* volname */
>>> > > + token = strtok_r(path, "/", &saveptr);
>>> > > + if (!token) {
>>> > > + return -EINVAL;
>>> > > + }
>>> > > + gconf->volname = g_strdup(token);
>>> > > +
>>> > > + /* image */
>>> > > + token = strtok_r(NULL, "?", &saveptr);
>> >
>> > If I understand uri.c right, there is no ? in the path, so there's no
>> > reason to call strtok. You could just use the rest of the string.
Actually there could be a %3F which uri.c would unescape to ? (only the
query part is left escaped), so your usage of strtok_r is incorrect.
> As you note, I don't need 2nd strtok strictly since the rest of the string
> is available in saveptr. But I thought using saveptr is not ideal or
> preferred.
> I wanted to use the most appropriate/safe delimiter to extract the image
> string
> in the 2nd strtok and decided to use '?'.
I don't think it is defined what saveptr points to.
http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf2/strtok_r.htm
says "the strtok_r subroutine also updates the Pointer parameter with
the starting address of the token following the first occurrence of the
Separators parameter". I read this as:
*saveptr = token + strlen(token) + 1;
which is consistent with this strtok example from the C standard:
#include <string.h>
static char str[] = "?a???b,";
char *t;
t = strtok(str, "?"); // t points to the token "a"
t = strtok(str, ","); // t points to the token "??b"
Have you tested this code with multiple consecutive slashes?
> If you think using saveptr is fine, then I could use that as below...
>
> /* image */
> if (!*saveptr) {
> return -EINVAL;
> }
> gconf->image = g_strdup(saveptr);
>
I would avoid strtok_r completely:
char *p = path + strcpsn(path, "/");
if (*p == '\0') {
return -EINVAL;
}
gconf->volname = g_strndup(path, p - path);
p += strspn(p, "/");
if (*p == '\0') {
return -EINVAL;
}
gconf->image = g_strdup(p);
Paolo
- [Qemu-devel] [PATCH v9 2/4] qemu: URI parsing library, (continued)
- [Qemu-devel] [PATCH v9 2/4] qemu: URI parsing library, Bharata B Rao, 2012/09/24
- [Qemu-devel] [PATCH v9 3/4] configure: Add a config option for GlusterFS as block backend, Bharata B Rao, 2012/09/24
- [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend., Bharata B Rao, 2012/09/24
- Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend., Paolo Bonzini, 2012/09/24
- Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend., Kevin Wolf, 2012/09/26
- Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend., Paolo Bonzini, 2012/09/26
- Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend., Bharata B Rao, 2012/09/26
- Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend.,
Paolo Bonzini <=
- Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend., Bharata B Rao, 2012/09/27
- Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend., Paolo Bonzini, 2012/09/27
- Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend., Bharata B Rao, 2012/09/27
- Re: [Qemu-devel] [PATCH v9 4/4] block: Support GlusterFS as a QEMU block backend., Paolo Bonzini, 2012/09/27