On 3/2/21 1:12 PM, Richard W.M. Jones wrote:
>>
>> h->fd = openat (dfd, file, flags);
>> + if (h->fd == -1 && !readonly) {
>> + int saved_errno = errno;
>> + flags = (flags & ~O_ACCMODE) | O_RDONLY;
>> + h->fd = openat (dfd, file, flags);
>> + if (h->fd == -1)
>> + errno = saved_errno;
>> + else
>> + h->can_write = false;
>> + }
>> if (h->fd == -1) {
>> nbdkit_error ("open: %s: %m", file);
>
> This will always report the error that failed open when using O_RDWR.
> But if open(O_RDWR) fail with EPERM, and open(O_RDONLY) fails
> with another error, the other error will be hidden.
>
> Maybe it is better to log the first error so we don't need to save errno
> when trying to open in read only mode?
Maybe we could put it in a nbdkit_debug message?
Sure, I can do that as a followup.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization:
qemu.org |
libvirt.org