VIR_DEBUG("Process path '%s' for USB device", path);
if (virCgroupAllowDevicePath(cgroup, path,
- VIR_CGROUP_DEVICE_RWM) < 0)
+ VIR_CGROUP_DEVICE_RWM, false) < 0)
return -1;
return 0;
VIR_DEBUG("Process path '%s' for USB device", path);
if (virCgroupDenyDevicePath(cgroup, path,
- VIR_CGROUP_DEVICE_RWM) < 0)
+ VIR_CGROUP_DEVICE_RWM, false) < 0)
return -1;
return 0;
(def->disks[i]->src->readonly ?
VIR_CGROUP_DEVICE_READ :
VIR_CGROUP_DEVICE_RW) |
- VIR_CGROUP_DEVICE_MKNOD) < 0)
+ VIR_CGROUP_DEVICE_MKNOD, false) < 0)
goto cleanup;
}
def->fss[i]->src,
def->fss[i]->readonly ?
VIR_CGROUP_DEVICE_READ :
- VIR_CGROUP_DEVICE_RW) < 0)
+ VIR_CGROUP_DEVICE_RW, false) < 0)
goto cleanup;
}
if (virCgroupAllowDevicePath(cgroup,
hostdev->source.caps.u.storage.block,
VIR_CGROUP_DEVICE_RW |
- VIR_CGROUP_DEVICE_MKNOD) < 0)
+ VIR_CGROUP_DEVICE_MKNOD, false) < 0)
goto cleanup;
break;
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
if (virCgroupAllowDevicePath(cgroup,
hostdev->source.caps.u.misc.chardev,
VIR_CGROUP_DEVICE_RW |
- VIR_CGROUP_DEVICE_MKNOD) < 0)
+ VIR_CGROUP_DEVICE_MKNOD, false) < 0)
goto cleanup;
break;
default:
}
virDomainAuditDisk(vm, def->src, NULL, "detach", true);
- if (virCgroupDenyDevicePath(priv->cgroup, src, VIR_CGROUP_DEVICE_RWM) != 0)
+ if (virCgroupDenyDevicePath(priv->cgroup, src,
+ VIR_CGROUP_DEVICE_RWM, false) != 0)
VIR_WARN("cannot deny device %s for domain %s",
src, vm->def->name);
}
virDomainAuditHostdev(vm, def, "detach", true);
- if (virCgroupDenyDevicePath(priv->cgroup, def->source.caps.u.storage.block, VIR_CGROUP_DEVICE_RWM) != 0)
+ if (virCgroupDenyDevicePath(priv->cgroup, def->source.caps.u.storage.block,
+ VIR_CGROUP_DEVICE_RWM, false) != 0)
VIR_WARN("cannot deny device %s for domain %s",
def->source.caps.u.storage.block, vm->def->name);
}
virDomainAuditHostdev(vm, def, "detach", true);
- if (virCgroupDenyDevicePath(priv->cgroup, def->source.caps.u.misc.chardev, VIR_CGROUP_DEVICE_RWM) != 0)
+ if (virCgroupDenyDevicePath(priv->cgroup, def->source.caps.u.misc.chardev,
+ VIR_CGROUP_DEVICE_RWM, false) != 0)
VIR_WARN("cannot deny device %s for domain %s",
def->source.caps.u.misc.chardev, vm->def->name);
VIR_DEBUG("Deny path %s", src->path);
- ret = virCgroupDenyDevicePath(priv->cgroup, src->path, perms);
+ ret = virCgroupDenyDevicePath(priv->cgroup, src->path, perms, false);
} else {
if (!src->readonly && !forceReadonly)
perms |= VIR_CGROUP_DEVICE_WRITE;
VIR_DEBUG("Allow path %s, perms: %s",
src->path, virCgroupGetDevicePermsString(perms));
- ret = virCgroupAllowDevicePath(priv->cgroup, src->path, perms);
+ ret = virCgroupAllowDevicePath(priv->cgroup, src->path, perms, false);
}
virDomainAuditCgroupPath(vm, priv->cgroup,
VIR_DEBUG("Process path '%s' for device", source->data.file.path);
ret = virCgroupAllowDevicePath(priv->cgroup, source->data.file.path,
- VIR_CGROUP_DEVICE_RW);
+ VIR_CGROUP_DEVICE_RW, false);
virDomainAuditCgroupPath(vm, priv->cgroup, "allow",
source->data.file.path, "rw", ret == 0);
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
VIR_DEBUG("Process path '%s' for input device", dev->source.evdev);
ret = virCgroupAllowDevicePath(priv->cgroup, dev->source.evdev,
- VIR_CGROUP_DEVICE_RW);
+ VIR_CGROUP_DEVICE_RW, false);
virDomainAuditCgroupPath(vm, priv->cgroup, "allow", dev->source.evdev, "rw", ret == 0);
break;
}
VIR_DEBUG("Process path '%s' for USB device", path);
ret = virCgroupAllowDevicePath(priv->cgroup, path,
- VIR_CGROUP_DEVICE_RW);
+ VIR_CGROUP_DEVICE_RW, false);
virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, "rw", ret == 0);
return ret;
ret = virCgroupAllowDevicePath(priv->cgroup, path,
virSCSIDeviceGetReadonly(dev) ?
VIR_CGROUP_DEVICE_READ :
- VIR_CGROUP_DEVICE_RW);
+ VIR_CGROUP_DEVICE_RW, false);
virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path,
virSCSIDeviceGetReadonly(dev) ? "r" : "rw", ret == 0);
VIR_DEBUG("Cgroup allow %s for PCI device assignment", path);
rv = virCgroupAllowDevicePath(priv->cgroup, path,
- VIR_CGROUP_DEVICE_RW);
+ VIR_CGROUP_DEVICE_RW, false);
virDomainAuditCgroupPath(vm, priv->cgroup,
"allow", path, "rw", rv == 0);
if (rv < 0)
VIR_DEBUG("Cgroup deny %s for PCI device assignment", path);
rv = virCgroupDenyDevicePath(priv->cgroup, path,
- VIR_CGROUP_DEVICE_RWM);
+ VIR_CGROUP_DEVICE_RWM, false);
virDomainAuditCgroupPath(vm, priv->cgroup,
"deny", path, "rwm", rv == 0);
if (rv < 0)
}
rv = virCgroupAllowDevicePath(priv->cgroup, deviceACL[i],
- VIR_CGROUP_DEVICE_RW);
+ VIR_CGROUP_DEVICE_RW, false);
virDomainAuditCgroupPath(vm, priv->cgroup, "allow", deviceACL[i], "rw", rv == 0);
if (rv < 0 &&
!virLastErrorIsSystemErrno(ENOENT))
VIR_DEBUG("Setting Cgroup ACL for RNG device");
rv = virCgroupAllowDevicePath(priv->cgroup,
vm->def->rngs[i]->source.file,
- VIR_CGROUP_DEVICE_RW);
+ VIR_CGROUP_DEVICE_RW, false);
virDomainAuditCgroupPath(vm, priv->cgroup, "allow",
vm->def->rngs[i]->source.file,
"rw", rv == 0);
* @group: The cgroup to allow the device for
* @path: the device to allow
* @perms: Bitwise or of VIR_CGROUP_DEVICE permission bits to allow
+ * @ignoreEacces: Ignore lack of permission (mostly for NFS mounts)
*
* Queries the type of device and its major/minor number, and
* adds that to the cgroup ACL
*
- * Returns: 0 on success, 1 if path exists but is not a device, or
- * -1 on error
+ * Returns: 0 on success, 1 if path exists but is not a device or is not
+ * accesible, or * -1 on error
*/
int
-virCgroupAllowDevicePath(virCgroupPtr group, const char *path, int perms)
+virCgroupAllowDevicePath(virCgroupPtr group,
+ const char *path,
+ int perms,
+ bool ignoreEacces)
{
struct stat sb;
if (stat(path, &sb) < 0) {
+ if (errno == EACCES && ignoreEacces)
+ return 1;
+
virReportSystemError(errno,
_("Path '%s' is not accessible"),
path);
}
+/**
+ * virCgroupDenyDevicePath:
+ *
+ * @group: The cgroup to deny the device for
+ * @path: the device to deny
+ * @perms: Bitwise or of VIR_CGROUP_DEVICE permission bits to allow
+ * @ignoreEacces: Ignore lack of permission (mostly for NFS mounts)
+ *
+ * Queries the type of device and its major/minor number, and
+ * removes it from the cgroup ACL
+ *
+ * Returns: 0 on success, 1 if path exists but is not a device or is not
+ * accessible, or -1 on error.
+ */
int
-virCgroupDenyDevicePath(virCgroupPtr group, const char *path, int perms)
+virCgroupDenyDevicePath(virCgroupPtr group,
+ const char *path,
+ int perms,
+ bool ignoreEacces)
{
struct stat sb;
if (stat(path, &sb) < 0) {
+ if (errno == EACCES && ignoreEacces)
+ return 1;
+
virReportSystemError(errno,
_("Path '%s' is not accessible"),
path);
int
virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED,
const char *path ATTRIBUTE_UNUSED,
- int perms ATTRIBUTE_UNUSED)
+ int perms ATTRIBUTE_UNUSED,
+ bool ignoreEaccess ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Control groups not supported on this platform"));
int perms);
int virCgroupAllowDevicePath(virCgroupPtr group,
const char *path,
- int perms);
+ int perms,
+ bool ignoreEacces);
int virCgroupDenyDevice(virCgroupPtr group,
char type,
int perms);
int virCgroupDenyDevicePath(virCgroupPtr group,
const char *path,
- int perms);
+ int perms,
+ bool ignoreEacces);
int
virCgroupGetPercpuStats(virCgroupPtr group,