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

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

 



On 12/20/2010 11:47 PM, Osier Yang wrote:
> 
> 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.

No, I really meant lstat().  If stat() would have failed because of a
dangling symlink, then open() will fail for the same reasons.
Therefore, check errno before lstat, and use the successful lstat as
proof that a symlink is in place but that stat()ing the symlink would
fail because it is dangling.

if (open(f) < 0) {
    if ((errno == ENOENT || errno == ELOOP) &&
        lstat(f, buf) == 0) {
        /* Dangling symlink, since lstat() passed but open failed. */
        log message about ignored file
        return -2;
    }
    either an unrelated errno, like EACCES, or we got ENOENT because
    the file was deleted after readdir but before open/lstat
    error message about unaccessible file
    return -1;
}

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]