[libvirt] [v2] storage: Ignore dangling symbol link for filesystem pool

Osier Yang jyang at redhat.com
Tue Dec 21 06:47:55 UTC 2010


于 2010年12月21日 00:09, Eric Blake 写道:
> On 12/20/2010 12:14 AM, Osier Yang wrote:
>> If there is a dangling symbol link in filesystem pool, the pool
>
> s/symbol/symbolic/
>
>> will be failed to start or refresh, this patch is to fix it by
>
> s/will be failed/will fail/
>
>> ignoring it with a warning log.
>
>> @@ -986,6 +988,12 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags)
>>       struct stat sb;
>>
>>       if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOCTTY))<  0) {
>> +        if (areadlink(path)) {
>> +            VIR_WARN("cannot open volume '%s': %s", path,
>> +                     strerror(errno));
>> +            return -2;
>
> Memory leak - areadlink() returns a malloc()d string that the user must
> free.Also, areadlink() is expensive (in addition to malloc(), it makes
> several syscalls);

oh, just looked at the source code of areadlink, indeed, thanks.

a more efficient solution would be to check if errno
> is ELOOP or ENOENT (the only possibilities for a dangling symlink; any
> other error should return -1), and in those two cases a successful
> lstat() is sufficient to detect a broken symlink without resorting to
> reading its contents.
>

I guess you mean stat, lstat will not work here, as it doesn't follow
the *symbolic* link. what we need to do is to determine if the symbolic
link is dangling, so use "stat" to update the patch, v3 send, thanks
again.

Regards
Osier




More information about the libvir-list mailing list