qemu: eliminate "Ignoring open failure" when using root-squash NFS

This eliminates the warning message reported in:

 https://bugzilla.redhat.com/show_bug.cgi?id=624447

It was caused by a failure to open an image file that is not
accessible by root (the uid libvirtd is running as) because it's on a
root-squash NFS share, owned by a different user, with permissions of
660 (or maybe 600).

The solution is to use virFileOpenAs() rather than open(). The
codepath that generates the error is during qemuSetupDiskCGroup(), but
the actual open() is in a lower-level generic function called from
many places (virDomainDiskDefForeachPath), so some other pieces of the
code were touched just to add dummy (or possibly useful) uid and gid
arguments.

Eliminating this warning message has the nice side effect that the
requested operation may even succeed (which in this case isn't
necessary, but shouldn't hurt anything either).
This commit is contained in:
Laine Stump
2012-01-12 13:24:45 -05:00
parent 90e4d681bc
commit c18a88ac48
6 changed files with 20 additions and 5 deletions

View File

@@ -13554,6 +13554,7 @@ done:
int virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
bool allowProbing,
bool ignoreOpenFailure,
uid_t uid, gid_t gid,
virDomainDiskDefPathIterator iter,
void *opaque)
{
@@ -13610,15 +13611,14 @@ int virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
goto cleanup;
}
if ((fd = open(path, O_RDONLY)) < 0) {
if ((fd = virFileOpenAs(path, O_RDONLY, 0, uid, gid, 0)) < 0) {
if (ignoreOpenFailure) {
char ebuf[1024];
VIR_WARN("Ignoring open failure on %s: %s", path,
virStrerror(errno, ebuf, sizeof(ebuf)));
virStrerror(-fd, ebuf, sizeof(ebuf)));
break;
} else {
virReportSystemError(errno,
_("unable to open disk path %s"),
virReportSystemError(-fd, _("unable to open disk path %s"),
path);
goto cleanup;
}

View File

@@ -1974,6 +1974,7 @@ typedef int (*virDomainDiskDefPathIterator)(virDomainDiskDefPtr disk,
int virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
bool allowProbing,
bool ignoreOpenFailure,
uid_t uid, gid_t gid,
virDomainDiskDefPathIterator iter,
void *opaque);