[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH][RFC] helper of copy-storage-* features



On Thu, Oct 18, 2012 at 12:47 AM, li guang <lig fnst cn fujitsu com> wrote:
> 在 2012-10-17三的 21:50 -0500,Doug Goldstein写道:
>> On Sun, Oct 14, 2012 at 9:48 PM, liguang <lig fnst cn fujitsu com> wrote:
>> > help to create disk images copy-storage-* required,
>> > try to do non-shared migration without bothering to
>> > create disk images at target by hand.
>> >
>> > consider this situation:
>> > 1. non-shared migration
>> >    virsh migrate --copy-storage-all ...
>> > 2. migration fails
>> > 3. create disk images required
>> >    qemu-img create ...
>> > 4  migration run smoothly
>> > so, try do remove step 2, 3, 4
>> >
>> > +char *virDirOfFile(const char *file)
>> > +{
>> > +    char *p, *tmp;
>> > +
>> > +    if (file == NULL)
>> > +        return NULL;
>> > +    if ((tmp = strdup(file)) == NULL)
>> > +        return NULL;
>> > +    if ((p = strrchr(file, '/')) == NULL)
>> > +        return getcwd(tmp, strlen(file));
>> > +    if (strlen(p) == 0)
>> > +        return NULL;
>> > +    tmp[strlen(file) - strlen(p)] = '\0';
>> > +
>> > +    return tmp;
>> > +}
>>
>> Eric probably knows better than I do but it seems like we can probably
>> pull in dirname() from gnulib for this rather than implementing our
>> own version.
>>
>
> maybe, but dirname has its own known issues(e.g. for old version glibc,
> dirname will "generate a segfault if given a NULL argument"), so I
> try to choose a loosely implementation.
> but, if libvirt cares nothing about these tiny issues, I'd like
> to choose dirname.

That's why I'm suggesting to use dirname from gnulib, which fixes
several of those issues. Additionally the implementation above
wouldn't work on Windows, not that we currently build the libvirtd on
Windows but if the function was used in the future the function would
have to be fixed.

>
>> > diff --git a/src/util/util.h b/src/util/util.h
>> > index 4316ab1..255b7b2 100644
>> > --- a/src/util/util.h
>> > +++ b/src/util/util.h
>> > @@ -114,6 +114,7 @@ enum {
>> >  };
>> >  int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid,
>> >                   unsigned int flags) ATTRIBUTE_RETURN_CHECK;
>> > +char *virDirOfFile(const char *file) ATTRIBUTE_RETURN_CHECK;
>> >  int virFileMakePath(const char *path) ATTRIBUTE_RETURN_CHECK;
>> >  int virFileMakePathWithMode(const char *path,
>> >                              mode_t mode) ATTRIBUTE_RETURN_CHECK;
>> > --
>> > 1.7.2.5
>> >
>> > --
>> > libvir-list mailing list
>> > libvir-list redhat com
>> > https://www.redhat.com/mailman/listinfo/libvir-list
>>
>>
>>
>
> --
> liguang    lig fnst cn fujitsu com
> FNST linux kernel team
>

-- 
Doug Goldstein


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]