]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cgroup: determine when skipping non-devices
authorEric Blake <eblake@redhat.com>
Thu, 17 Feb 2011 00:05:54 +0000 (17:05 -0700)
committerEric Blake <eblake@redhat.com>
Thu, 24 Feb 2011 20:31:05 +0000 (13:31 -0700)
* src/util/cgroup.c (virCgroupAllowDevicePath)
(virCgroupDenyDevicePath): Don't fail with EINVAL for
non-devices.
* src/qemu/qemu_driver.c (qemudDomainSaveFlag): Update caller.
* src/qemu/qemu_cgroup.c (qemuSetupDiskPathAllow)
(qemuSetupChardevCgroup, qemuSetupHostUsbDeviceCgroup)
(qemuSetupCgroup, qemuTeardownDiskPathDeny): Likewise.

src/qemu/qemu_cgroup.c
src/qemu/qemu_driver.c
src/util/cgroup.c

index 8cd6ce9e398efc70d6628263dc83d3bae7117871..3907a09de4e1fbe8549f17cdfdacc3dd84bc9996 100644 (file)
@@ -66,11 +66,8 @@ int qemuSetupDiskPathAllow(virDomainDiskDefPtr disk ATTRIBUTE_UNUSED,
     VIR_DEBUG("Process path %s for disk", path);
     /* XXX RO vs RW */
     rc = virCgroupAllowDevicePath(cgroup, path);
-    if (rc != 0) {
-        /* Get this for non-block devices */
-        if (rc == -EINVAL) {
-            VIR_DEBUG("Ignoring EINVAL for %s", path);
-        } else if (rc == -EACCES) { /* Get this for root squash NFS */
+    if (rc < 0) {
+        if (rc == -EACCES) { /* Get this for root squash NFS */
             VIR_DEBUG("Ignoring EACCES for %s", path);
         } else {
             virReportSystemError(-rc,
@@ -106,11 +103,8 @@ int qemuTeardownDiskPathDeny(virDomainDiskDefPtr disk ATTRIBUTE_UNUSED,
     VIR_DEBUG("Process path %s for disk", path);
     /* XXX RO vs RW */
     rc = virCgroupDenyDevicePath(cgroup, path);
-    if (rc != 0) {
-        /* Get this for non-block devices */
-        if (rc == -EINVAL) {
-            VIR_DEBUG("Ignoring EINVAL for %s", path);
-        } else if (rc == -EACCES) { /* Get this for root squash NFS */
+    if (rc < 0) {
+        if (rc == -EACCES) { /* Get this for root squash NFS */
             VIR_DEBUG("Ignoring EACCES for %s", path);
         } else {
             virReportSystemError(-rc,
@@ -148,7 +142,7 @@ int qemuSetupChardevCgroup(virDomainDefPtr def,
 
     VIR_DEBUG("Process path '%s' for disk", dev->source.data.file.path);
     rc = virCgroupAllowDevicePath(cgroup, dev->source.data.file.path);
-    if (rc != 0) {
+    if (rc < 0) {
         virReportSystemError(-rc,
                              _("Unable to allow device %s for %s"),
                              dev->source.data.file.path, def->name);
@@ -168,7 +162,7 @@ int qemuSetupHostUsbDeviceCgroup(usbDevice *dev ATTRIBUTE_UNUSED,
 
     VIR_DEBUG("Process path '%s' for USB device", path);
     rc = virCgroupAllowDevicePath(cgroup, path);
-    if (rc != 0) {
+    if (rc < 0) {
         virReportSystemError(-rc,
                              _("Unable to allow device %s"),
                              path);
index 102f7801a4807a4eaef085f6532a4583d2dd3475..20d91df7b00ec6fa5ceb5065f35ede6c41d41069 100644 (file)
@@ -1962,7 +1962,7 @@ static int qemudDomainSaveFlag(struct qemud_driver *driver, virDomainPtr dom,
             goto endjob;
         }
         rc = virCgroupAllowDevicePath(cgroup, path);
-        if (rc != 0) {
+        if (rc < 0) {
             virReportSystemError(-rc,
                                  _("Unable to allow device %s for %s"),
                                  path, vm->def->name);
@@ -2011,7 +2011,7 @@ static int qemudDomainSaveFlag(struct qemud_driver *driver, virDomainPtr dom,
 
     if (cgroup != NULL) {
         rc = virCgroupDenyDevicePath(cgroup, path);
-        if (rc != 0)
+        if (rc < 0)
             VIR_WARN("Unable to deny device %s for %s %d",
                      path, vm->def->name, rc);
     }
@@ -2042,7 +2042,7 @@ endjob:
 
             if (cgroup != NULL) {
                 rc = virCgroupDenyDevicePath(cgroup, path);
-                if (rc != 0)
+                if (rc < 0)
                     VIR_WARN("Unable to deny device %s for %s: %d",
                              path, vm->def->name, rc);
             }
index a1299aa76f72a57daaac7eb34093b32e609e7c7b..78efc6995cf290f83280665bb44b4b91056dc819 100644 (file)
@@ -1146,7 +1146,8 @@ int virCgroupAllowDeviceMajor(virCgroupPtr group, char type, int major)
  * Queries the type of device and its major/minor number, and
  * adds that to the cgroup ACL
  *
- * Returns: 0 on success
+ * Returns: 0 on success, 1 if path exists but is not a device, or
+ * negative errno value on failure
  */
 #if defined(major) && defined(minor)
 int virCgroupAllowDevicePath(virCgroupPtr group, const char *path)
@@ -1157,7 +1158,7 @@ int virCgroupAllowDevicePath(virCgroupPtr group, const char *path)
         return -errno;
 
     if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode))
-        return -EINVAL;
+        return 1;
 
     return virCgroupAllowDevice(group,
                                 S_ISCHR(sb.st_mode) ? 'c' : 'b',
@@ -1241,7 +1242,7 @@ int virCgroupDenyDevicePath(virCgroupPtr group, const char *path)
         return -errno;
 
     if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode))
-        return -EINVAL;
+        return 1;
 
     return virCgroupDenyDevice(group,
                                S_ISCHR(sb.st_mode) ? 'c' : 'b',