On 08/26/14 13:21, Eric Blake wrote: > The hard part of managing the disk copy is already coded; all > this had to do was convert the XML and virTypedParameters into > the internal representation. > > With this patch, all blockcopy operations that used the old > API should also work via the new API. Additional extensions, > such as supporting the granularity tunable or a network rather > than file destination, will be added as later patches. > > * src/qemu/qemu_driver.c (qemuDomainBlockCopy): New function. > > Signed-off-by: Eric Blake <eblake@xxxxxxxxxx> > --- > src/qemu/qemu_driver.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 81 insertions(+) > > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c > index f3c5387..4876617 100644 > --- a/src/qemu/qemu_driver.c > +++ b/src/qemu/qemu_driver.c > @@ -15507,6 +15507,86 @@ qemuDomainBlockRebase(virDomainPtr dom, const char *path, const char *base, > return ret; > } > > + > +static int > +qemuDomainBlockCopy(virDomainPtr dom, const char *disk, const char *destxml, > + virTypedParameterPtr params, int nparams, > + unsigned int flags) > +{ > + virQEMUDriverPtr driver = dom->conn->privateData; > + virDomainObjPtr vm; > + int ret = -1; > + unsigned long bandwidth = 0; > + unsigned int granularity = 0; > + unsigned int buf_size = 0; > + virStorageSourcePtr dest = NULL; > + size_t i; > + > + virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW | > + VIR_DOMAIN_BLOCK_COPY_REUSE_EXT, -1); > + if (virTypedParamsValidate(params, nparams, > + VIR_DOMAIN_BLOCK_COPY_BANDWIDTH, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_COPY_GRANULARITY, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BLOCK_COPY_BUF_SIZE, > + VIR_TYPED_PARAM_UINT, > + NULL) < 0) > + return -1; > + > + if (!(vm = qemuDomObjFromDomain(dom))) > + return -1; > + > + if (virDomainBlockCopyEnsureACL(dom->conn, vm->def) < 0) > + goto cleanup; > + > + for (i = 0; i < nparams; i++) { > + virTypedParameterPtr param = ¶ms[i]; > + > + /* Typed params (wisely) refused to expose unsigned long, but > + * back-compat demands that we stick with unsigned long > + * bandwidth. Hence, we have to do overflow detection if this > + * is a 32-bit server handling a 64-bit client. */ > + if (STREQ(param->field, VIR_DOMAIN_BLOCK_COPY_BANDWIDTH)) { > + if (params[i].value.ul > ULONG_MAX) { > + virReportError(VIR_ERR_OVERFLOW, > + _("bandwidth must be less than %llu"), > + ULONG_MAX + 1ULL); > + goto cleanup; > + } > + bandwidth = params[i].value.ul; > + } else if (STREQ(param->field, VIR_DOMAIN_BLOCK_COPY_GRANULARITY)) { > + granularity = params[i].value.ui; > + } else if (STREQ(param->field, VIR_DOMAIN_BLOCK_COPY_BUF_SIZE)) { > + buf_size = params[i].value.ui; > + } > + } > + if (granularity) { > + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", > + _("granularity tuning not supported yet")); > + goto cleanup; > + } > + if (buf_size) { > + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", > + _("buffer size tuning not supported yet")); > + goto cleanup; > + } > + > + if (!(dest = virDomainDiskDefSourceParse(destxml, vm->def, driver->xmlopt, > + VIR_DOMAIN_XML_INACTIVE))) > + goto cleanup; > + > + ret = qemuDomainBlockCopyCommon(&vm, dom->conn, disk, dest, > + bandwidth, flags); I don't think you need to do the dance with passing vm as an pointer and having it returned. Insted you can unlock/free it in qemuDomainBlockCopyCommon. This will also clean the messy part in 5/8. > + > + cleanup: > + virStorageSourceFree(dest); > + if (vm) > + virObjectUnlock(vm); > + return ret; > +} > + > + > static int > ACK
Attachment:
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list