[libvirt] [PATCH] Fix handling of disk backing stores with cgroups

The cgroups ACL code was only allowing the primary disk image. It is possible to chain images together, so we need to search for backing stores and add them to the ACL too. Since the ACL only handles block devices, we ignore the EINVAL we get from plain files. * src/qemu/qemu_driver.c: Allow backing stores in cgroup ACLs --- src/qemu/qemu_driver.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 326cb58..ae6addd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -84,6 +84,7 @@ #include "macvtap.h" #include "nwfilter/nwfilter_gentech_driver.h" #include "hooks.h" +#include "storage_file.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -2957,18 +2958,40 @@ static int qemuSetupCgroup(struct qemud_driver *driver, } for (i = 0; i < vm->def->ndisks ; i++) { - if (vm->def->disks[i]->type != VIR_DOMAIN_DISK_TYPE_BLOCK || - vm->def->disks[i]->src == NULL) - continue; + char *path = vm->def->disks[i]->src; + while (path != NULL) { + virStorageFileMetadata meta; + int ret; + + VIR_DEBUG("Process path %s for disk %d", path, i); + rc = virCgroupAllowDevicePath(cgroup, path); + if (rc != 0) { + /* Get this for non-block devices */ + if (rc == -EINVAL) { + VIR_DEBUG("Ignoring EINVAL for %s", path); + } else { + virReportSystemError(-rc, + _("Unable to allow device %s for %s"), + path, vm->def->name); + if (path != vm->def->disks[i]->src) + VIR_FREE(path); + goto cleanup; + } + } - rc = virCgroupAllowDevicePath(cgroup, - vm->def->disks[i]->src); - if (rc != 0) { - virReportSystemError(-rc, - _("Unable to allow device %s for %s"), - vm->def->disks[i]->src, vm->def->name); - goto cleanup; - } + memset(&meta, 0, sizeof(meta)); + + ret = virStorageFileGetMetadata(path, &meta); + + if (path != vm->def->disks[i]->src) + VIR_FREE(path); + path = NULL; + + if (ret < 0) + goto cleanup; + + path = meta.backingStore; + } while (path != NULL); } rc = virCgroupAllowDeviceMajor(cgroup, 'c', DEVICE_PTY_MAJOR); -- 1.6.5.2

On 04/28/2010 09:27 AM, Daniel P. Berrange wrote:
+ memset(&meta, 0, sizeof(meta)); + + ret = virStorageFileGetMetadata(path, &meta); + + if (path != vm->def->disks[i]->src) + VIR_FREE(path); + path = NULL; + + if (ret < 0) + goto cleanup; + + path = meta.backingStore;
I had to go read virStorageFileGetMetadata to make sure there was no leak or double-free, but after a few minutes review, I'm convinced you did it right. ACK. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On Wed, Apr 28, 2010 at 11:03:42AM -0600, Eric Blake wrote:
On 04/28/2010 09:27 AM, Daniel P. Berrange wrote:
+ memset(&meta, 0, sizeof(meta)); + + ret = virStorageFileGetMetadata(path, &meta); + + if (path != vm->def->disks[i]->src) + VIR_FREE(path); + path = NULL; + + if (ret < 0) + goto cleanup; + + path = meta.backingStore;
I had to go read virStorageFileGetMetadata to make sure there was no leak or double-free, but after a few minutes review, I'm convinced you did it right.
ACK.
I'm self-NACKing this. It misses the hotplug use case with the same problem Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (2)
-
Daniel P. Berrange
-
Eric Blake