Re: [RFC PATCHv4 13/15] qemu: consolidate migration to file code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 09, 2011 at 07:18:31PM -0700, Eric Blake wrote:
> This points out that core dumps (still) don't work for root-squash
> NFS, since the fd is not opened correctly.  This patch should not
> introduce any functionality change, it is just a refactoring to
> avoid duplicated code.
> 
> * src/qemu/qemu_driver.c (qemuDomainMigrateToFile): New function.
> (qemudDomainSaveFlag, doCoreDump): Use it.
> ---
>  src/qemu/qemu_driver.c |  249 +++++++++++++++++++++---------------------------
>  1 files changed, 110 insertions(+), 139 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 9de19ea..2422482 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -1766,6 +1766,101 @@ endjob:
>      return ret;
>  }
> 
> +/* Internal function called while driver lock is held and vm is active.  */
> +static int
> +qemuDomainMigrateToFile(struct qemud_driver *driver, virDomainObjPtr vm,
> +                        virBitmapPtr qemuCaps,
> +                        int fd, off_t offset, const char *path,
> +                        int compressed,
> +                        bool is_reg, bool bypassSecurityDriver)
> +{
> +    qemuDomainObjPrivatePtr priv = vm->privateData;
> +    virCgroupPtr cgroup = NULL;
> +    int ret = -1;
> +    int rc;
> +
> +    if (!is_reg &&
> +        qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
> +        if (virCgroupForDomain(driver->cgroup, vm->def->name,
> +                               &cgroup, 0) != 0) {
> +            qemuReportError(VIR_ERR_INTERNAL_ERROR,
> +                            _("Unable to find cgroup for %s"),
> +                            vm->def->name);
> +            goto cleanup;
> +        }
> +        rc = virCgroupAllowDevicePath(cgroup, path,
> +                                      VIR_CGROUP_DEVICE_RW);
> +        qemuAuditCgroupPath(vm, cgroup, "allow", path, "rw", rc);
> +        if (rc < 0) {
> +            virReportSystemError(-rc,
> +                                 _("Unable to allow device %s for %s"),
> +                                 path, vm->def->name);
> +            goto cleanup;
> +        }
> +    }
> +
> +    if ((!bypassSecurityDriver) &&
> +        virSecurityManagerSetSavedStateLabel(driver->securityManager,
> +                                             vm, path) < 0)
> +        goto cleanup;
> +
> +    if (compressed == QEMUD_SAVE_FORMAT_RAW) {
> +        const char *args[] = { "cat", NULL };
> +
> +        qemuDomainObjEnterMonitorWithDriver(driver, vm);
> +        if (qemuCaps && qemuCapsGet(qemuCaps, QEMU_CAPS_MIGRATE_QEMU_FD) &&
> +            priv->monConfig->type == VIR_DOMAIN_CHR_TYPE_UNIX) {
> +            rc = qemuMonitorMigrateToFd(priv->mon,
> +                                        QEMU_MONITOR_MIGRATE_BACKGROUND,
> +                                        fd);
> +        } else {
> +            rc = qemuMonitorMigrateToFile(priv->mon,
> +                                          QEMU_MONITOR_MIGRATE_BACKGROUND,
> +                                          args, path, offset);
> +        }
> +        qemuDomainObjExitMonitorWithDriver(driver, vm);
> +    } else {
> +        const char *prog = qemudSaveCompressionTypeToString(compressed);
> +        const char *args[] = {
> +            prog,
> +            "-c",
> +            NULL
> +        };
> +        qemuDomainObjEnterMonitorWithDriver(driver, vm);
> +        rc = qemuMonitorMigrateToFile(priv->mon,
> +                                      QEMU_MONITOR_MIGRATE_BACKGROUND,
> +                                      args, path, offset);
> +        qemuDomainObjExitMonitorWithDriver(driver, vm);
> +    }
> +
> +    if (rc < 0)
> +        goto cleanup;
> +
> +    rc = qemuMigrationWaitForCompletion(driver, vm);
> +
> +    if (rc < 0)
> +        goto cleanup;
> +
> +    ret = 0;
> +
> +cleanup:
> +    if ((!bypassSecurityDriver) &&
> +        virSecurityManagerRestoreSavedStateLabel(driver->securityManager,
> +                                                 vm, path) < 0)
> +        VIR_WARN("failed to restore save state label on %s", path);
> +
> +    if (cgroup != NULL) {
> +        rc = virCgroupDenyDevicePath(cgroup, path,
> +                                     VIR_CGROUP_DEVICE_RWM);
> +        qemuAuditCgroupPath(vm, cgroup, "deny", path, "rwm", rc);
> +        if (rc < 0)
> +            VIR_WARN("Unable to deny device %s for %s %d",
> +                     path, vm->def->name, rc);
> +        virCgroupFree(&cgroup);
> +    }
> +    return ret;
> +}

I think it could be worth moving this method into qemu_migrate.h/.c
now it is decoupled from the public API objects/methods.

ACK to the refactoring regardless.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]