static bool cmdVolClone(vshControl *ctl, const vshCmd *cmd) { virStoragePoolPtr origpool = NULL; virStorageVolPtr origvol = NULL, newvol = NULL; const char *name = NULL; char *origxml = NULL; xmlChar *newxml = NULL; bool ret = false; unsigned int flags = 0; if (!(origvol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) goto cleanup; if (vshCommandOptBool(cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; origpool = virStoragePoolLookupByVolume(origvol); if (!origpool) { vshError(ctl, "%s", _("failed to get parent pool")); goto cleanup; } if (vshCommandOptStringReq(ctl, cmd, "newname", &name) < 0) goto cleanup; origxml = virStorageVolGetXMLDesc(origvol, 0); if (!origxml) goto cleanup; newxml = vshMakeCloneXML(origxml, name); if (!newxml) { vshPrint(ctl, "%s", _("Failed to allocate XML buffer")); goto cleanup; } newvol = virStorageVolCreateXMLFrom(origpool, (char *) newxml, origvol, flags); if (newvol != NULL) { vshPrint(ctl, _("Vol %s cloned from %s\n"), virStorageVolGetName(newvol), virStorageVolGetName(origvol)); } else { vshError(ctl, _("Failed to clone vol from %s"), virStorageVolGetName(origvol)); goto cleanup; } ret = true; cleanup: VIR_FREE(origxml); xmlFree(newxml); if (origvol) virStorageVolFree(origvol); if (newvol) virStorageVolFree(newvol); if (origpool) virStoragePoolFree(origpool); return ret; }
static bool cmdVolClone(vshControl *ctl, const vshCmd *cmd) { virStoragePoolPtr origpool = NULL; virStorageVolPtr origvol = NULL, newvol = NULL; const char *name = NULL; char *origxml = NULL; xmlChar *newxml = NULL; bool ret = false; if (!vshConnectionUsability(ctl, ctl->conn)) goto cleanup; if (!(origvol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) goto cleanup; origpool = virStoragePoolLookupByVolume(origvol); if (!origpool) { vshError(ctl, "%s", _("failed to get parent pool")); goto cleanup; } if (vshCommandOptString(cmd, "newname", &name) <= 0) goto cleanup; origxml = virStorageVolGetXMLDesc(origvol, 0); if (!origxml) goto cleanup; newxml = makeCloneXML(origxml, name); if (!newxml) { vshPrint(ctl, "%s", _("Failed to allocate XML buffer")); goto cleanup; } newvol = virStorageVolCreateXMLFrom(origpool, (char *) newxml, origvol, 0); if (newvol != NULL) { vshPrint(ctl, _("Vol %s cloned from %s\n"), virStorageVolGetName(newvol), virStorageVolGetName(origvol)); } else { vshError(ctl, _("Failed to clone vol from %s"), virStorageVolGetName(origvol)); goto cleanup; } ret = true; cleanup: VIR_FREE(origxml); xmlFree(newxml); if (origvol) virStorageVolFree(origvol); if (newvol) virStorageVolFree(newvol); if (origpool) virStoragePoolFree(origpool); return ret; }
static bool cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd) { virStorageVolPtr vol; bool ret = true; char *dump; if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) return false; dump = virStorageVolGetXMLDesc(vol, 0); if (dump != NULL) { vshPrint(ctl, "%s", dump); VIR_FREE(dump); } else { ret = false; } virStorageVolFree(vol); return ret; }
Result StorageVolControlThread::getStorageVolXMLDesc() { Result result; result.name = QString("%1_%2").arg(task.srcConName).arg(currPoolName); QString name = task.object; if (currStoragePool!=NULL) { virStoragePoolFree(currStoragePool); currStoragePool = NULL; }; currStoragePool = virStoragePoolLookupByName( *task.srcConnPtr, currPoolName.toUtf8().data()); bool read = false; char *Returns = NULL; // flags: extra flags; not used yet, so callers should always pass 0 unsigned int flags = 0; virStorageVol *storageVol = virStorageVolLookupByName( currStoragePool, name.toUtf8().data()); if ( storageVol!=NULL ) { Returns = virStorageVolGetXMLDesc(storageVol, flags); if ( Returns==NULL ) result.err = sendConnErrors(); else read = true; virStorageVolFree(storageVol); } else result.err = sendConnErrors(); QTemporaryFile f; f.setAutoRemove(false); f.setFileTemplate(QString("%1%2XML_Desc-XXXXXX.xml") .arg(QDir::tempPath()).arg(QDir::separator())); read = f.open(); if (read) f.write(Returns); result.fileName.append(f.fileName()); f.close(); if ( Returns!=NULL ) free(Returns); result.msg.append(QString("'<b>%1</b>' StorageVol %2 XML'ed") .arg(name).arg((read)?"":"don't")); result.result = read; return result; }
bool VolumeWrap::handleMethod(qmf::AgentSession& session, qmf::AgentEvent& event) { int ret; if (*this != event.getDataAddr()) { return false; } const std::string& methodName(event.getMethodName()); qpid::types::Variant::Map args(event.getArguments()); if (methodName == "getXMLDesc") { const char *desc = virStorageVolGetXMLDesc(_volume_ptr, 0); if (!desc) { std::string err = FORMAT_ERR(_conn, "Error getting xml description for volume (virStorageVolGetXMLDesc).", &ret); raiseException(session, event, err, STATUS_USER + ret); } else { event.addReturnArgument("description", desc); session.methodSuccess(event); } return true; } if (methodName == "delete") { ret = virStorageVolDelete(_volume_ptr, 0); if (ret < 0) { std::string err = FORMAT_ERR(_conn, "Error deleting storage volume (virStorageVolDelete).", &ret); raiseException(session, event, err, STATUS_USER + ret); } else { update(); session.methodSuccess(event); } return true; } raiseException(session, event, ERROR_UNKNOWN_METHOD, STATUS_UNKNOWN_METHOD); return true; }
/** * gvir_storage_vol_get_config: * @vol: the storage_vol * @flags: the flags * @err: Place-holder for possible errors * * Returns: (transfer full): the config. The returned object should be * unreffed with g_object_unref() when no longer needed. */ GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, guint flags, GError **err) { GVirStorageVolPrivate *priv; gchar *xml; g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), NULL); g_return_val_if_fail(err == NULL || *err == NULL, NULL); priv = vol->priv; if (!(xml = virStorageVolGetXMLDesc(priv->handle, flags))) { gvir_set_error_literal(err, GVIR_STORAGE_VOL_ERROR, 0, "Unable to get storage_vol XML config"); return NULL; } GVirConfigStorageVol *conf = gvir_config_storage_vol_new_from_xml(xml, err); free(xml); return conf; }