int virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
bool allowProbing,
bool ignoreOpenFailure,
+ uid_t uid, gid_t gid,
virDomainDiskDefPathIterator iter,
void *opaque)
{
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;
}
int virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
bool allowProbing,
bool ignoreOpenFailure,
+ uid_t uid, gid_t gid,
virDomainDiskDefPathIterator iter,
void *opaque);
return virDomainDiskDefForeachPath(disk,
driver->allowDiskFormatProbing,
true,
+ driver->user, driver->group,
qemuSetupDiskPathAllow,
&data);
}
return virDomainDiskDefForeachPath(disk,
driver->allowDiskFormatProbing,
true,
+ driver->user, driver->group,
qemuTeardownDiskPathDeny,
&data);
}
return virDomainDiskDefForeachPath(disk,
virSecurityManagerGetAllowDiskFormatProbing(mgr),
false,
+ priv->user, priv->group,
virSecurityDACSetSecurityFileLabel,
mgr);
}
if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK)
return 0;
+ /* XXX On one hand, it would be nice to have the driver's uid:gid
+ * here so we could retry opens with it. On the other hand, it
+ * probably doesn't matter because in practice that's only useful
+ * for files on root-squashed NFS shares, and NFS doesn't properly
+ * support selinux anyway.
+ */
return virDomainDiskDefForeachPath(disk,
allowDiskFormatProbing,
true,
+ -1, -1, /* current process uid:gid */
SELinuxSetSecurityFileLabel,
secdef);
}
/* XXX passing ignoreOpenFailure = true to get back to the behavior
* from before using virDomainDiskDefForeachPath. actually we should
* be passing ignoreOpenFailure = false and handle open errors more
- * careful than just ignoring them */
+ * careful than just ignoring them.
+ * XXX2 - if we knew the qemu user:group here we could send it in
+ * so that the open could be re-tried as that user:group.
+ */
int ret = virDomainDiskDefForeachPath(ctl->def->disks[i],
ctl->allowDiskFormatProbing,
true,
+ -1, -1 /* current uid:gid */
add_file_path,
&buf);
if (ret != 0)