}
+static int
+lxcDomainAttachDeviceUnlinkHelper(pid_t pid ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+ const char *path = opaque;
+
+ VIR_DEBUG("Unlinking %s", path);
+ if (unlink(path) < 0 && errno != ENOENT) {
+ virReportSystemError(errno,
+ _("Unable to remove device %s"), path);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int
+lxcDomainAttachDeviceUnlink(virDomainObjPtr vm,
+ char *file)
+{
+ virLXCDomainObjPrivatePtr priv = vm->privateData;
+
+ if (virProcessRunInMountNamespace(priv->initpid,
+ lxcDomainAttachDeviceUnlinkHelper,
+ file) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+
static int
lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
virDomainObjPtr vm,
def = vm->def->disks[idx];
- if (virAsprintf(&dst, "/proc/%llu/root/dev/%s",
- (unsigned long long)priv->initpid, def->dst) < 0)
+ if (virAsprintf(&dst, "/dev/%s", def->dst) < 0)
goto cleanup;
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
goto cleanup;
}
- VIR_DEBUG("Unlinking %s (backed by %s)", dst, def->src);
- if (unlink(dst) < 0 && errno != ENOENT) {
+ if (lxcDomainAttachDeviceUnlink(vm, dst) < 0) {
virDomainAuditDisk(vm, def->src, NULL, "detach", false);
- virReportSystemError(errno,
- _("Unable to remove device %s"), dst);
goto cleanup;
}
virDomainAuditDisk(vm, def->src, NULL, "detach", true);
virDomainHostdevDefPtr def = NULL;
int idx, ret = -1;
char *dst = NULL;
- char *vroot = NULL;
virUSBDevicePtr usb = NULL;
if ((idx = virDomainHostdevFind(vm->def,
goto cleanup;
}
- if (virAsprintf(&vroot, "/proc/%llu/root",
- (unsigned long long)priv->initpid) < 0)
- goto cleanup;
-
- if (virAsprintf(&dst, "%s/dev/bus/usb/%03d/%03d",
- vroot,
+ if (virAsprintf(&dst, "/dev/bus/usb/%03d/%03d",
def->source.subsys.u.usb.bus,
def->source.subsys.u.usb.device) < 0)
goto cleanup;
def->source.subsys.u.usb.device, NULL)))
goto cleanup;
- VIR_DEBUG("Unlinking %s", dst);
- if (unlink(dst) < 0 && errno != ENOENT) {
+ if (lxcDomainAttachDeviceUnlink(vm, dst) < 0) {
virDomainAuditHostdev(vm, def, "detach", false);
- virReportSystemError(errno,
- _("Unable to remove device %s"), dst);
goto cleanup;
}
virDomainAuditHostdev(vm, def, "detach", true);
cleanup:
virUSBDeviceFree(usb);
VIR_FREE(dst);
- VIR_FREE(vroot);
return ret;
}
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevDefPtr def = NULL;
int idx, ret = -1;
- char *dst = NULL;
if (!priv->initpid) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
goto cleanup;
}
- if (virAsprintf(&dst, "/proc/%llu/root/%s",
- (unsigned long long)priv->initpid,
- def->source.caps.u.storage.block) < 0)
- goto cleanup;
-
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
goto cleanup;
}
- VIR_DEBUG("Unlinking %s", dst);
- if (unlink(dst) < 0 && errno != ENOENT) {
+ if (lxcDomainAttachDeviceUnlink(vm, def->source.caps.u.storage.block) < 0) {
virDomainAuditHostdev(vm, def, "detach", false);
- virReportSystemError(errno,
- _("Unable to remove device %s"), dst);
goto cleanup;
}
virDomainAuditHostdev(vm, def, "detach", true);
ret = 0;
cleanup:
- VIR_FREE(dst);
return ret;
}
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevDefPtr def = NULL;
int idx, ret = -1;
- char *dst = NULL;
if (!priv->initpid) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
goto cleanup;
}
- if (virAsprintf(&dst, "/proc/%llu/root/%s",
- (unsigned long long)priv->initpid,
- def->source.caps.u.misc.chardev) < 0)
- goto cleanup;
-
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
goto cleanup;
}
- VIR_DEBUG("Unlinking %s", dst);
- if (unlink(dst) < 0 && errno != ENOENT) {
+ if (lxcDomainAttachDeviceUnlink(vm, def->source.caps.u.misc.chardev) < 0) {
virDomainAuditHostdev(vm, def, "detach", false);
- virReportSystemError(errno,
- _("Unable to remove device %s"), dst);
goto cleanup;
}
virDomainAuditHostdev(vm, def, "detach", true);
ret = 0;
cleanup:
- VIR_FREE(dst);
return ret;
}