您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ virUUIDFormat函数代码示例

51自学网 2021-06-03 09:42:39
  C++
这篇教程C++ virUUIDFormat函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中virUUIDFormat函数的典型用法代码示例。如果您正苦于以下问题:C++ virUUIDFormat函数的具体用法?C++ virUUIDFormat怎么用?C++ virUUIDFormat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了virUUIDFormat函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: bhyveDomObjFromDomain

static virDomainObjPtrbhyveDomObjFromDomain(virDomainPtr domain){    virDomainObjPtr vm;    bhyveConnPtr privconn = domain->conn->privateData;    char uuidstr[VIR_UUID_STRING_BUFLEN];    vm = virDomainObjListFindByUUID(privconn->domains, domain->uuid);    if (!vm) {        virUUIDFormat(domain->uuid, uuidstr);        virReportError(VIR_ERR_NO_DOMAIN,                       _("no domain with matching uuid '%s' (%s)"),                       uuidstr, domain->name);        return NULL;    }    return vm;}
开发者ID:FrankYu,项目名称:libvirt,代码行数:18,


示例2: virStorageEncryptionSecretFormat

static intvirStorageEncryptionSecretFormat(virBufferPtr buf,                                 virStorageEncryptionSecretPtr secret){    const char *type;    char uuidstr[VIR_UUID_STRING_BUFLEN];    if (!(type = virStorageEncryptionSecretTypeToString(secret->type))) {        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                       _("unexpected volume encryption secret type"));        return -1;    }    virUUIDFormat(secret->uuid, uuidstr);    virBufferAsprintf(buf, "<secret type='%s' uuid='%s'/>/n",                      type, uuidstr);    return 0;}
开发者ID:JGulic,项目名称:libvirt,代码行数:18,


示例3: esxStorageVolLookupByName

static virStorageVolPtresxStorageVolLookupByName(virStoragePoolPtr pool,                          const char *name){    virStorageVolPtr volume = NULL;    esxPrivate *priv = pool->conn->storagePrivateData;    esxVI_ScsiLun *scsiLunList = NULL;    esxVI_ScsiLun *scsiLun;    /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */    unsigned char md5[MD5_DIGEST_SIZE];    char uuid_string[VIR_UUID_STRING_BUFLEN] = "";    if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {        goto cleanup;    }    for (scsiLun = scsiLunList; scsiLun;         scsiLun = scsiLun->_next) {        if (STREQ(scsiLun->deviceName, name)) {            /*             * ScsiLun provides an UUID field that is unique accross             * multiple servers. But this field length is ~55 characters             * compute MD5 hash to transform it to an acceptable             * libvirt format             */            md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5);            virUUIDFormat(md5, uuid_string);            /*             * ScsiLun provides displayName and canonicalName but both are             * optional and its observed that they can be NULL, using             * deviceName to create volume.             */            volume = virGetStorageVol(pool->conn, pool->name, name, uuid_string,                                      &esxStorageBackendISCSI, NULL);            break;        }    } cleanup:    esxVI_ScsiLun_Free(&scsiLunList);    return volume;}
开发者ID:i-ninth,项目名称:libvirt,代码行数:44,


示例4: virGetSecret

/** * virGetSecret: * @conn: the hypervisor connection * @uuid: secret UUID * * Lookup if the secret is already registered for that connection, if so return * a pointer to it, otherwise allocate a new structure, and register it in the * table. In any case a corresponding call to virUnrefSecret() is needed to not * leak data. * * Returns a pointer to the secret, or NULL in case of failure */virSecretPtrvirGetSecret(virConnectPtr conn, const unsigned char *uuid,             int usageType, const char *usageID){    virSecretPtr ret = NULL;    char uuidstr[VIR_UUID_STRING_BUFLEN];    if (!VIR_IS_CONNECT(conn)) {        virLibConnError(VIR_ERR_INVALID_CONN, _("no connection"));        return NULL;    }    virCheckNonNullArgReturn(uuid, NULL);    virCheckNonNullArgReturn(usageID, NULL);    virMutexLock(&conn->lock);    virUUIDFormat(uuid, uuidstr);    if (VIR_ALLOC(ret) < 0) {        virMutexUnlock(&conn->lock);        virReportOOMError();        goto error;    }    ret->magic = VIR_SECRET_MAGIC;    ret->conn = conn;    memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);    ret->usageType = usageType;    if (!(ret->usageID = strdup(usageID))) {        virMutexUnlock(&conn->lock);        virReportOOMError();        goto error;    }    conn->refs++;    ret->refs++;    virMutexUnlock(&conn->lock);    return ret;error:    if (ret != NULL) {        VIR_FREE(ret->usageID);        VIR_FREE(ret);    }    return NULL;}
开发者ID:intgr,项目名称:libvirt,代码行数:56,


示例5: virGetStoragePool

/** * virGetStoragePool: * @conn: the hypervisor connection * @name: pointer to the storage pool name * @uuid: pointer to the uuid * * Lookup if the storage pool is already registered for that connection, * if yes return a new pointer to it, if no allocate a new structure, * and register it in the table. In any case a corresponding call to * virUnrefStoragePool() is needed to not leak data. * * Returns a pointer to the network, or NULL in case of failure */virStoragePoolPtrvirGetStoragePool(virConnectPtr conn, const char *name,                  const unsigned char *uuid) {    virStoragePoolPtr ret = NULL;    char uuidstr[VIR_UUID_STRING_BUFLEN];    if (!VIR_IS_CONNECT(conn)) {        virLibConnError(VIR_ERR_INVALID_CONN, _("no connection"));        return NULL;    }    virCheckNonNullArgReturn(name, NULL);    virCheckNonNullArgReturn(uuid, NULL);    virMutexLock(&conn->lock);    virUUIDFormat(uuid, uuidstr);    if (VIR_ALLOC(ret) < 0) {        virMutexUnlock(&conn->lock);        virReportOOMError();        goto error;    }    ret->name = strdup(name);    if (ret->name == NULL) {        virMutexUnlock(&conn->lock);        virReportOOMError();        goto error;    }    ret->magic = VIR_STORAGE_POOL_MAGIC;    ret->conn = conn;    memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);    conn->refs++;    ret->refs++;    virMutexUnlock(&conn->lock);    return ret;error:    if (ret != NULL) {        VIR_FREE(ret->name);        VIR_FREE(ret);    }    return NULL;}
开发者ID:intgr,项目名称:libvirt,代码行数:57,


示例6: lxcContainerBuildInitCmd

/** * lxcContainerBuildInitCmd: * @vmDef: pointer to vm definition structure * * Build a virCommandPtr for launching the container 'init' process * * Returns a virCommandPtr */static virCommandPtr lxcContainerBuildInitCmd(virDomainDefPtr vmDef){    char uuidstr[VIR_UUID_STRING_BUFLEN];    virCommandPtr cmd;    virUUIDFormat(vmDef->uuid, uuidstr);    cmd = virCommandNew(vmDef->os.init);    virCommandAddEnvString(cmd, "PATH=/bin:/sbin");    virCommandAddEnvString(cmd, "TERM=linux");    virCommandAddEnvString(cmd, "container=lxc-libvirt");    virCommandAddEnvPair(cmd, "LIBVIRT_LXC_UUID", uuidstr);    virCommandAddEnvPair(cmd, "LIBVIRT_LXC_NAME", vmDef->name);    if (vmDef->os.cmdline)        virCommandAddEnvPair(cmd, "LIBVIRT_LXC_CMDLINE", vmDef->os.cmdline);    return cmd;}
开发者ID:kthguru,项目名称:libvirt,代码行数:27,


示例7: vmwareDomainUndefineFlags

static intvmwareDomainUndefineFlags(virDomainPtr dom,                          unsigned int flags){    struct vmware_driver *driver = dom->conn->privateData;    virDomainObjPtr vm;    int ret = -1;    virCheckFlags(0, -1);    vmwareDriverLock(driver);    vm = virDomainFindByUUID(&driver->domains, dom->uuid);    if (!vm) {        char uuidstr[VIR_UUID_STRING_BUFLEN];        virUUIDFormat(dom->uuid, uuidstr);        vmwareError(VIR_ERR_NO_DOMAIN,                    _("no domain with matching uuid '%s'"), uuidstr);        goto cleanup;    }    if (!vm->persistent) {        vmwareError(VIR_ERR_OPERATION_INVALID,                    "%s", _("cannot undefine transient domain"));        goto cleanup;    }    if (virDomainObjIsActive(vm)) {        vm->persistent = 0;    } else {        virDomainRemoveInactive(&driver->domains, vm);        vm = NULL;    }    ret = 0;  cleanup:    if (vm)        virDomainObjUnlock(vm);    vmwareDriverUnlock(driver);    return ret;}
开发者ID:kantai,项目名称:libvirt-vfork,代码行数:43,


示例8: libxlMakeDomCreateInfo

static intlibxlMakeDomCreateInfo(libxl_ctx *ctx,                       virDomainDefPtr def,                       libxl_domain_create_info *c_info){    char uuidstr[VIR_UUID_STRING_BUFLEN];    libxl_domain_create_info_init(c_info);    if (STREQ(def->os.type, "hvm"))        c_info->type = LIBXL_DOMAIN_TYPE_HVM;    else        c_info->type = LIBXL_DOMAIN_TYPE_PV;    if (VIR_STRDUP(c_info->name, def->name) < 0)        goto error;    if (def->nseclabels &&        def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_STATIC) {        if (libxl_flask_context_to_sid(ctx,                                       def->seclabels[0]->label,                                       strlen(def->seclabels[0]->label),                                       &c_info->ssidref)) {            virReportError(VIR_ERR_INTERNAL_ERROR,                           _("libxenlight failed to resolve security label '%s'"),                           def->seclabels[0]->label);        }    }    virUUIDFormat(def->uuid, uuidstr);    if (libxl_uuid_from_string(&c_info->uuid, uuidstr)) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("libxenlight failed to parse UUID '%s'"), uuidstr);        goto error;    }    return 0;error:    libxl_domain_create_info_dispose(c_info);    return -1;}
开发者ID:dmitryilyin,项目名称:libvirt,代码行数:42,


示例9: lxctoolsReadUUID

static int lxctoolsReadUUID(struct lxc_container* cont, unsigned char* uuid){    int ret = -1;    const char* config_path = cont->config_file_name(cont);    FILE* fd;    size_t read_len = 0;    char* linestr = NULL;    if ((fd = fopen(config_path, "r+")) == NULL) {        goto cleanup;    }    if (getline(&linestr, &read_len, fd) < 0) {        goto cleanup;    }    if (strncmp(linestr, "# UUID:", 7) != 0) {        char uuid_str[7+VIR_UUID_STRING_BUFLEN+1] = "# UUID:";        if (virUUIDGenerate(uuid) < 0) {           goto cleanup;        }        if (virUUIDFormat(uuid, uuid_str+7) == NULL) {            goto cleanup;        }        uuid_str[7+VIR_UUID_STRING_BUFLEN-1] = '/n';        uuid_str[7+VIR_UUID_STRING_BUFLEN] = '/0';        if (addToBeginning(fd, uuid_str) < 0) {            goto cleanup;        }        ret = 0;        goto cleanup;    }    linestr[strlen(linestr)-1] = '/0';    if (virUUIDParse(linestr+7, uuid) < 0) {        goto cleanup;    }    ret = 0; cleanup:    VIR_FREE(linestr);    fclose(fd);    return ret;}
开发者ID:RWTH-OS,项目名称:libvirt,代码行数:41,


示例10: virSecretEventValueChangedNew

/** * virSecretEventValueChangedNew: * @uuid: UUID of the secret object the event describes * * Create a new secret lifecycle event. */virObjectEventPtrvirSecretEventValueChangedNew(const unsigned char *uuid,                              int usage_type,                              const char *usage_id){    virSecretEventValueChangedPtr event;    char uuidstr[VIR_UUID_STRING_BUFLEN];    if (virSecretEventsInitialize() < 0)        return NULL;    virUUIDFormat(uuid, uuidstr);    VIR_DEBUG("Event %s %d %s", uuidstr, usage_type, usage_id);    if (!(event = virObjectEventNew(virSecretEventValueChangedClass,                                    virSecretEventDispatchDefaultFunc,                                    VIR_SECRET_EVENT_ID_VALUE_CHANGED,                                    usage_type, usage_id, uuid, uuidstr)))        return NULL;    return (virObjectEventPtr)event;}
开发者ID:libvirt,项目名称:libvirt,代码行数:27,


示例11: virCloseCallbacksGetConn

virConnectPtrvirCloseCallbacksGetConn(virCloseCallbacksPtr closeCallbacks,                         virDomainObjPtr vm){    char uuidstr[VIR_UUID_STRING_BUFLEN];    virDriverCloseDefPtr closeDef;    virConnectPtr conn = NULL;    virUUIDFormat(vm->def->uuid, uuidstr);    VIR_DEBUG("vm=%s, uuid=%s", vm->def->name, uuidstr);    virObjectLock(closeCallbacks);    closeDef = virHashLookup(closeCallbacks->list, uuidstr);    if (closeDef)        conn = closeDef->conn;    virObjectUnlock(closeCallbacks);    VIR_DEBUG("conn=%p", conn);    return conn;}
开发者ID:RWTH-OS,项目名称:libvirt,代码行数:22,


示例12: virReleaseSecret

/** * virReleaseSecret: * @secret: the secret to release * * Unconditionally release all memory associated with a secret.  The conn.lock * mutex must be held prior to calling this, and will be released prior to this * returning. The secret obj must not be used once this method returns. * * It will also unreference the associated connection object, which may also be * released if its ref count hits zero. */static voidvirReleaseSecret(virSecretPtr secret) {    virConnectPtr conn = secret->conn;    char uuidstr[VIR_UUID_STRING_BUFLEN];    virUUIDFormat(secret->uuid, uuidstr);    VIR_DEBUG("release secret %p %s", secret, uuidstr);    VIR_FREE(secret->usageID);    secret->magic = -1;    VIR_FREE(secret);    if (conn) {        VIR_DEBUG("unref connection %p %d", conn, conn->refs);        conn->refs--;        if (conn->refs == 0) {            virReleaseConnect(conn);            /* Already unlocked mutex */            return;        }        virMutexUnlock(&conn->lock);    }}
开发者ID:intgr,项目名称:libvirt,代码行数:34,


示例13: virReleaseStoragePool

/** * virReleaseStoragePool: * @pool: the pool to release * * Unconditionally release all memory associated with a pool. * The conn.lock mutex must be held prior to calling this, and will * be released prior to this returning. The pool obj must not * be used once this method returns. * * It will also unreference the associated connection object, * which may also be released if its ref count hits zero. */static voidvirReleaseStoragePool(virStoragePoolPtr pool) {    virConnectPtr conn = pool->conn;    char uuidstr[VIR_UUID_STRING_BUFLEN];    virUUIDFormat(pool->uuid, uuidstr);    VIR_DEBUG("release pool %p %s %s", pool, pool->name, uuidstr);    pool->magic = -1;    VIR_FREE(pool->name);    VIR_FREE(pool);    if (conn) {        VIR_DEBUG("unref connection %p %d", conn, conn->refs);        conn->refs--;        if (conn->refs == 0) {            virReleaseConnect(conn);            /* Already unlocked mutex */            return;        }        virMutexUnlock(&conn->lock);    }}
开发者ID:intgr,项目名称:libvirt,代码行数:35,


示例14: virReleaseNetwork

/** * virReleaseNetwork: * @network: the network to release * * Unconditionally release all memory associated with a network. * The conn.lock mutex must be held prior to calling this, and will * be released prior to this returning. The network obj must not * be used once this method returns. * * It will also unreference the associated connection object, * which may also be released if its ref count hits zero. */static voidvirReleaseNetwork(virNetworkPtr network) {    virConnectPtr conn = network->conn;    char uuidstr[VIR_UUID_STRING_BUFLEN];    virUUIDFormat(network->uuid, uuidstr);    VIR_DEBUG("release network %p %s %s", network, network->name, uuidstr);    network->magic = -1;    VIR_FREE(network->name);    VIR_FREE(network);    if (conn) {        VIR_DEBUG("unref connection %p %d", conn, conn->refs);        conn->refs--;        if (conn->refs == 0) {            virReleaseConnect(conn);            /* Already unlocked mutex */            return;        }        virMutexUnlock(&conn->lock);    }}
开发者ID:intgr,项目名称:libvirt,代码行数:35,


示例15: vmwareDomainCreateWithFlags

static intvmwareDomainCreateWithFlags(virDomainPtr dom,                            unsigned int flags){    struct vmware_driver *driver = dom->conn->privateData;    virDomainObjPtr vm;    int ret = -1;    virCheckFlags(0, -1);    vmwareDriverLock(driver);    vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);    if (!vm) {        char uuidstr[VIR_UUID_STRING_BUFLEN];        virUUIDFormat(dom->uuid, uuidstr);        virReportError(VIR_ERR_NO_DOMAIN,                       _("No domain with matching uuid '%s'"), uuidstr);        goto cleanup;    }    if (vmwareUpdateVMStatus(driver, vm) < 0)        goto cleanup;    if (virDomainObjIsActive(vm)) {        virReportError(VIR_ERR_OPERATION_INVALID,                       "%s", _("Domain is already running"));        goto cleanup;    }    ret = vmwareStartVM(driver, vm);cleanup:    if (vm)        virObjectUnlock(vm);    vmwareDriverUnlock(driver);    return ret;}
开发者ID:bigclouds,项目名称:libvirt,代码行数:37,


示例16: openvzSetDefinedUUID

/* Do actual checking for UUID presence in conf file, * assign if not present. */intopenvzSetDefinedUUID(int vpsid, unsigned char *uuid){    char *conf_file;    char uuidstr[VIR_UUID_STRING_BUFLEN];    FILE *fp = NULL;    int ret = -1;    if (uuid == NULL)        return -1;    if (openvzLocateConfFile(vpsid, &conf_file, "conf") < 0)        return -1;    if (openvzGetVPSUUID(vpsid, uuidstr, sizeof(uuidstr)))        goto cleanup;    if (uuidstr[0] == 0) {        fp = fopen(conf_file, "a"); /* append */        if (fp == NULL)            goto cleanup;        virUUIDFormat(uuid, uuidstr);        /* Record failure if fprintf or VIR_FCLOSE fails,           and be careful always to close the stream.  */        if ((fprintf(fp, "/n#UUID: %s/n", uuidstr) < 0) ||            (VIR_FCLOSE(fp) == EOF))            goto cleanup;    }    ret = 0; cleanup:    VIR_FORCE_FCLOSE(fp);    VIR_FREE(conf_file);    return ret;}
开发者ID:noxdafox,项目名称:libvirt,代码行数:40,


示例17: virCloseCallbacksUnset

intvirCloseCallbacksUnset(virCloseCallbacksPtr closeCallbacks,                       virDomainObjPtr vm,                       virCloseCallback cb){    char uuidstr[VIR_UUID_STRING_BUFLEN];    virDriverCloseDefPtr closeDef;    int ret = -1;    virUUIDFormat(vm->def->uuid, uuidstr);    VIR_DEBUG("vm=%s, uuid=%s, cb=%p",              vm->def->name, uuidstr, cb);    virObjectLock(closeCallbacks);    closeDef = virHashLookup(closeCallbacks->list, uuidstr);    if (!closeDef)        goto cleanup;    if (closeDef->cb && closeDef->cb != cb) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Trying to remove mismatching close callback for"                         " domain %s"), vm->def->name);        goto cleanup;    }    if (virHashRemoveEntry(closeCallbacks->list, uuidstr) < 0)        goto cleanup;    virObjectUnref(vm);    ret = 0; cleanup:    virObjectUnlock(closeCallbacks);    if (!ret)        virObjectUnref(closeCallbacks);    return ret;}
开发者ID:RWTH-OS,项目名称:libvirt,代码行数:37,


示例18: virReleaseDomain

/** * virReleaseDomain: * @domain: the domain to release * * Unconditionally release all memory associated with a domain. * The conn.lock mutex must be held prior to calling this, and will * be released prior to this returning. The domain obj must not * be used once this method returns. * * It will also unreference the associated connection object, * which may also be released if its ref count hits zero. */static voidvirReleaseDomain(virDomainPtr domain) {    virConnectPtr conn = domain->conn;    char uuidstr[VIR_UUID_STRING_BUFLEN];    virUUIDFormat(domain->uuid, uuidstr);    VIR_DEBUG("release domain %p %s %s", domain, domain->name, uuidstr);    domain->magic = -1;    domain->id = -1;    VIR_FREE(domain->name);    VIR_FREE(domain);    if (conn) {        VIR_DEBUG("unref connection %p %d", conn, conn->refs);        conn->refs--;        if (conn->refs == 0) {            virReleaseConnect(conn);            /* Already unlocked mutex */            return;        }        virMutexUnlock(&conn->lock);    }}
开发者ID:intgr,项目名称:libvirt,代码行数:36,


示例19: virSecretEventStateRegisterID

/** * virSecretEventStateRegisterID: * @conn: connection to associate with callback * @state: object event state * @secret: secret to filter on or NULL for all node secrets * @eventID: ID of the event type to register for * @cb: function to invoke when event occurs * @opaque: data blob to pass to @callback * @freecb: callback to free @opaque * @callbackID: filled with callback ID * * Register the function @cb with connection @conn, from @state, for * events of type @eventID, and return the registration handle in * @callbackID. * * Returns: the number of callbacks now registered, or -1 on error */intvirSecretEventStateRegisterID(virConnectPtr conn,                              virObjectEventStatePtr state,                              virSecretPtr secret,                              int eventID,                              virConnectSecretEventGenericCallback cb,                              void *opaque,                              virFreeCallback freecb,                              int *callbackID){    char uuidstr[VIR_UUID_STRING_BUFLEN];    if (virSecretEventsInitialize() < 0)        return -1;    if (secret)        virUUIDFormat(secret->uuid, uuidstr);    return virObjectEventStateRegisterID(conn, state, secret ? uuidstr : NULL,                                         NULL, NULL,                                         virSecretEventClass, eventID,                                         VIR_OBJECT_EVENT_CALLBACK(cb),                                         opaque, freecb,                                         false, callbackID, false);}
开发者ID:libvirt,项目名称:libvirt,代码行数:41,


示例20: virNetDevMidonetUnbindPort

/** * virNetDevMidonetUnbindPort: * @virtualport: the midonet specific fields * * Unbinds a virtual port from the host * * Returns 0 in case of success or -1 in case of failure. */intvirNetDevMidonetUnbindPort(virNetDevVPortProfilePtr virtualport){    int ret = -1;    virCommandPtr cmd = NULL;    char virtportuuid[VIR_UUID_STRING_BUFLEN];    virUUIDFormat(virtualport->interfaceID, virtportuuid);    cmd = virCommandNew(MMCTL);    virCommandAddArgList(cmd, "--unbind-port", virtportuuid, NULL);    if (virCommandRun(cmd, NULL) < 0) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Unable to unbind the virtual port %s from Midonet"),                       virtportuuid);        goto cleanup;    }    ret = 0; cleanup:    virCommandFree(cmd);    return ret;}
开发者ID:Antique,项目名称:libvirt,代码行数:32,


示例21: virCloseCallbacksGet

virCloseCallbackvirCloseCallbacksGet(virCloseCallbacksPtr closeCallbacks,                     virDomainObjPtr vm,                     virConnectPtr conn){    char uuidstr[VIR_UUID_STRING_BUFLEN];    virDriverCloseDefPtr closeDef;    virCloseCallback cb = NULL;    virUUIDFormat(vm->def->uuid, uuidstr);    VIR_DEBUG("vm=%s, uuid=%s, conn=%p",              vm->def->name, uuidstr, conn);    virObjectLock(closeCallbacks);    closeDef = virHashLookup(closeCallbacks->list, uuidstr);    if (closeDef && (!conn || closeDef->conn == conn))        cb = closeDef->cb;    virObjectUnlock(closeCallbacks);    VIR_DEBUG("cb=%p", cb);    return cb;}
开发者ID:RWTH-OS,项目名称:libvirt,代码行数:24,


示例22: virCapabilitiesFormatXML

/** * virCapabilitiesFormatXML: * @caps: capabilities to format * * Convert the capabilities object into an XML representation * * Returns the XML document as a string */char *virCapabilitiesFormatXML(virCapsPtr caps){    virBuffer xml = VIR_BUFFER_INITIALIZER;    int i, j, k;    char host_uuid[VIR_UUID_STRING_BUFLEN];    virBufferAddLit(&xml, "<capabilities>/n/n");    virBufferAddLit(&xml, "  <host>/n");    if (virUUIDIsValid(caps->host.host_uuid)) {        virUUIDFormat(caps->host.host_uuid, host_uuid);        virBufferAsprintf(&xml,"    <uuid>%s</uuid>/n", host_uuid);    }    virBufferAddLit(&xml, "    <cpu>/n");    virBufferAsprintf(&xml, "      <arch>%s</arch>/n",                      caps->host.arch);    if (caps->host.nfeatures) {        virBufferAddLit(&xml, "      <features>/n");        for (i = 0 ; i < caps->host.nfeatures ; i++) {            virBufferAsprintf(&xml, "        <%s/>/n",                              caps->host.features[i]);        }        virBufferAddLit(&xml, "      </features>/n");    }    virBufferAdjustIndent(&xml, 6);    virCPUDefFormatBuf(&xml, caps->host.cpu);    virBufferAdjustIndent(&xml, -6);    virBufferAddLit(&xml, "    </cpu>/n");    if (caps->host.offlineMigrate) {        virBufferAddLit(&xml, "    <migration_features>/n");        if (caps->host.liveMigrate)            virBufferAddLit(&xml, "      <live/>/n");        if (caps->host.nmigrateTrans) {            virBufferAddLit(&xml, "      <uri_transports>/n");            for (i = 0 ; i < caps->host.nmigrateTrans ; i++) {                virBufferAsprintf(&xml, "        <uri_transport>%s</uri_transport>/n",                                      caps->host.migrateTrans[i]);            }            virBufferAddLit(&xml, "      </uri_transports>/n");        }        virBufferAddLit(&xml, "    </migration_features>/n");    }    if (caps->host.nnumaCell) {        virBufferAddLit(&xml, "    <topology>/n");        virBufferAsprintf(&xml, "      <cells num='%zu'>/n",                          caps->host.nnumaCell);        for (i = 0 ; i < caps->host.nnumaCell ; i++) {            virBufferAsprintf(&xml, "        <cell id='%d'>/n",                              caps->host.numaCell[i]->num);            virBufferAsprintf(&xml, "          <cpus num='%d'>/n",                              caps->host.numaCell[i]->ncpus);            for (j = 0 ; j < caps->host.numaCell[i]->ncpus ; j++)                virBufferAsprintf(&xml, "            <cpu id='%d'/>/n",                                  caps->host.numaCell[i]->cpus[j]);            virBufferAddLit(&xml, "          </cpus>/n");            virBufferAddLit(&xml, "        </cell>/n");        }        virBufferAddLit(&xml, "      </cells>/n");        virBufferAddLit(&xml, "    </topology>/n");    }    if (caps->host.secModel.model) {        virBufferAddLit(&xml, "    <secmodel>/n");        virBufferAsprintf(&xml, "      <model>%s</model>/n", caps->host.secModel.model);        virBufferAsprintf(&xml, "      <doi>%s</doi>/n", caps->host.secModel.doi);        virBufferAddLit(&xml, "    </secmodel>/n");    }    virBufferAddLit(&xml, "  </host>/n/n");    for (i = 0 ; i < caps->nguests ; i++) {        virBufferAddLit(&xml, "  <guest>/n");        virBufferAsprintf(&xml, "    <os_type>%s</os_type>/n",                          caps->guests[i]->ostype);        virBufferAsprintf(&xml, "    <arch name='%s'>/n",                          caps->guests[i]->arch.name);        virBufferAsprintf(&xml, "      <wordsize>%d</wordsize>/n",                          caps->guests[i]->arch.wordsize);        if (caps->guests[i]->arch.defaultInfo.emulator)            virBufferAsprintf(&xml, "      <emulator>%s</emulator>/n",                              caps->guests[i]->arch.defaultInfo.emulator);            if (caps->guests[i]->arch.defaultInfo.loader)                virBufferAsprintf(&xml, "      <loader>%s</loader>/n",                                  caps->guests[i]->arch.defaultInfo.loader);        for (j = 0 ; j < caps->guests[i]->arch.defaultInfo.nmachines ; j++) {//.........这里部分代码省略.........
开发者ID:kantai,项目名称:libvirt-vfork,代码行数:101,


示例23: virLockManagerSanlockAcquire

static int virLockManagerSanlockAcquire(virLockManagerPtr lock,                                        const char *state,                                        unsigned int flags,                                        virDomainLockFailureAction action,                                        int *fd){    virLockManagerSanlockPrivatePtr priv = lock->privateData;    struct sanlk_options *opt;    struct sanlk_resource **res_args;    int res_count;    bool res_free = false;    int sock = -1;    int rv;    int i;    virCheckFlags(VIR_LOCK_MANAGER_ACQUIRE_RESTRICT |                  VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY, -1);    if (priv->res_count == 0 &&        priv->hasRWDisks &&        driver->requireLeaseForDisks) {        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",                       _("Read/write, exclusive access, disks were present, but no leases specified"));        return -1;    }    if (VIR_ALLOC(opt) < 0) {        virReportOOMError();        return -1;    }    if (!virStrcpy(opt->owner_name, priv->vm_name, SANLK_NAME_LEN)) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Domain name '%s' exceeded %d characters"),                       priv->vm_name, SANLK_NAME_LEN);        goto error;    }    if (state && STRNEQ(state, "")) {        if ((rv = sanlock_state_to_args((char *)state,                                        &res_count,                                        &res_args)) < 0) {            if (rv <= -200)                virReportError(VIR_ERR_INTERNAL_ERROR,                               _("Unable to parse lock state %s: error %d"),                               state, rv);            else                virReportSystemError(-rv,                                     _("Unable to parse lock state %s"),                                     state);            goto error;        }        res_free = true;    } else {        res_args = priv->res_args;        res_count = priv->res_count;    }    /* We only initialize 'sock' if we are in the real     * child process and we need it to be inherited     *     * If sock==-1, then sanlock auto-open/closes a     * temporary sock     */    if (priv->vm_pid == getpid()) {        VIR_DEBUG("Register sanlock %d", flags);        if ((sock = sanlock_register()) < 0) {            if (sock <= -200)                virReportError(VIR_ERR_INTERNAL_ERROR,                               _("Failed to open socket to sanlock daemon: error %d"),                               sock);            else                virReportSystemError(-sock, "%s",                                     _("Failed to open socket to sanlock daemon"));            goto error;        }        if (action != VIR_DOMAIN_LOCK_FAILURE_DEFAULT) {            char uuidstr[VIR_UUID_STRING_BUFLEN];            virUUIDFormat(priv->vm_uuid, uuidstr);            if (virLockManagerSanlockRegisterKillscript(sock, priv->vm_uri,                                                        uuidstr, action) < 0)                goto error;        }    }    if (!(flags & VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY)) {        VIR_DEBUG("Acquiring object %u", priv->res_count);        if ((rv = sanlock_acquire(sock, priv->vm_pid, 0,                                  priv->res_count, priv->res_args,                                  opt)) < 0) {            if (rv <= -200)                virReportError(VIR_ERR_INTERNAL_ERROR,                               _("Failed to acquire lock: error %d"), rv);            else                virReportSystemError(-rv, "%s",                                     _("Failed to acquire lock"));            goto error;        }    }//.........这里部分代码省略.........
开发者ID:mithleshvrts,项目名称:libvirt-0.10.2,代码行数:101,


示例24: virNetDevOpenvswitchAddPort

/** * virNetDevOpenvswitchAddPort: * @brname: the bridge name * @ifname: the network interface name * @macaddr: the mac address of the virtual interface * @vmuuid: the Domain UUID that has this interface * @ovsport: the ovs specific fields * * Add an interface to the OVS bridge * * Returns 0 in case of success or -1 in case of failure. */int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,                                   const virMacAddr *macaddr,                                   const unsigned char *vmuuid,                                   virNetDevVPortProfilePtr ovsport,                                   virNetDevVlanPtr virtVlan){    int ret = -1;    size_t i = 0;    virCommandPtr cmd = NULL;    char macaddrstr[VIR_MAC_STRING_BUFLEN];    char ifuuidstr[VIR_UUID_STRING_BUFLEN];    char vmuuidstr[VIR_UUID_STRING_BUFLEN];    char *attachedmac_ex_id = NULL;    char *ifaceid_ex_id = NULL;    char *profile_ex_id = NULL;    char *vmid_ex_id = NULL;    virBuffer buf = VIR_BUFFER_INITIALIZER;    virMacAddrFormat(macaddr, macaddrstr);    virUUIDFormat(ovsport->interfaceID, ifuuidstr);    virUUIDFormat(vmuuid, vmuuidstr);    if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=/"%s/"",                    macaddrstr) < 0)        goto cleanup;    if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=/"%s/"",                    ifuuidstr) < 0)        goto cleanup;    if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=/"%s/"",                    vmuuidstr) < 0)        goto cleanup;    if (ovsport->profileID[0] != '/0') {        if (virAsprintf(&profile_ex_id, "external-ids:port-profile=/"%s/"",                        ovsport->profileID) < 0)            goto cleanup;    }    cmd = virCommandNew(OVSVSCTL);    virCommandAddArgList(cmd, "--timeout=5", "--", "--if-exists", "del-port",                         ifname, "--", "add-port", brname, ifname, NULL);    if (virtVlan && virtVlan->nTags > 0) {        switch (virtVlan->nativeMode) {        case VIR_NATIVE_VLAN_MODE_TAGGED:            virCommandAddArg(cmd, "vlan_mode=native-tagged");            virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag);            break;        case VIR_NATIVE_VLAN_MODE_UNTAGGED:            virCommandAddArg(cmd, "vlan_mode=native-untagged");            virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag);            break;        case VIR_NATIVE_VLAN_MODE_DEFAULT:        default:            break;        }        if (virtVlan->trunk) {            virBufferAddLit(&buf, "trunk=");            /*             * Trunk ports have at least one VLAN. Do the first one             * outside the "for" loop so we can put a "," at the             * start of the for loop if there are more than one VLANs             * on this trunk port.             */            virBufferAsprintf(&buf, "%d", virtVlan->tag[i]);            for (i = 1; i < virtVlan->nTags; i++) {                virBufferAddLit(&buf, ",");                virBufferAsprintf(&buf, "%d", virtVlan->tag[i]);            }            if (virBufferCheckError(&buf) < 0)                goto cleanup;            virCommandAddArg(cmd, virBufferCurrentContent(&buf));        } else if (virtVlan->nTags) {            virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]);        }    }    if (ovsport->profileID[0] == '/0') {        virCommandAddArgList(cmd,                        "--", "set", "Interface", ifname, attachedmac_ex_id,                        "--", "set", "Interface", ifname, ifaceid_ex_id,                        "--", "set", "Interface", ifname, vmid_ex_id,                        "--", "set", "Interface", ifname,//.........这里部分代码省略.........
开发者ID:icclab,项目名称:libvirt,代码行数:101,


示例25: createVMRecordFromXml

/* Create a VM record from the XML description */intcreateVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,                      xen_vm_record **record, xen_vm *vm){    char uuidStr[VIR_UUID_STRING_BUFLEN];    xen_string_string_map *strings = NULL;    int device_number = 0;    size_t i;    *record = xen_vm_record_alloc();    if (VIR_STRDUP((*record)->name_label, def->name) < 0)        goto error;    if (def->uuid) {        virUUIDFormat(def->uuid, uuidStr);        if (VIR_STRDUP((*record)->uuid, uuidStr) < 0)            goto error;    }    if (STREQ(def->os.type, "hvm")) {        char *boot_order = NULL;        if (VIR_STRDUP((*record)->hvm_boot_policy, "BIOS order") < 0)            goto error;        if (def->os.nBootDevs != 0)            boot_order = createXenAPIBootOrderString(def->os.nBootDevs, &def->os.bootDevs[0]);        if (boot_order != NULL) {            xen_string_string_map *hvm_boot_params = NULL;            allocStringMap(&hvm_boot_params, (char *)"order", boot_order);            (*record)->hvm_boot_params = hvm_boot_params;            VIR_FREE(boot_order);        }    } else if (STREQ(def->os.type, "xen")) {        if (VIR_STRDUP((*record)->pv_bootloader, "pygrub") < 0)            goto error;        if (def->os.kernel) {            if (VIR_STRDUP((*record)->pv_kernel, def->os.kernel) < 0)                goto error;        }        if (def->os.initrd) {            if (VIR_STRDUP((*record)->pv_ramdisk, def->os.initrd) < 0)                goto error;        }        if (def->os.cmdline) {            if (VIR_STRDUP((*record)->pv_args, def->os.cmdline) < 0)                goto error;        }        (*record)->hvm_boot_params = xen_string_string_map_alloc(0);    }    if (def->os.bootloaderArgs)        if (VIR_STRDUP((*record)->pv_bootloader_args, def->os.bootloaderArgs) < 0)            goto error;    if (def->mem.cur_balloon)        (*record)->memory_static_max = (int64_t) (def->mem.cur_balloon * 1024);    if (def->mem.max_balloon)        (*record)->memory_dynamic_max = (int64_t) (def->mem.max_balloon * 1024);    else        (*record)->memory_dynamic_max = (*record)->memory_static_max;    if (def->maxvcpus) {        (*record)->vcpus_max = (int64_t) def->maxvcpus;        (*record)->vcpus_at_startup = (int64_t) def->vcpus;    }    if (def->onPoweroff)        (*record)->actions_after_shutdown = actionShutdownLibvirt2XenapiEnum(def->onPoweroff);    if (def->onReboot)        (*record)->actions_after_reboot = actionShutdownLibvirt2XenapiEnum(def->onReboot);    if (def->onCrash)        (*record)->actions_after_crash = actionCrashLibvirt2XenapiEnum(def->onCrash);    if (def->features[VIR_DOMAIN_FEATURE_ACPI] == VIR_DOMAIN_FEATURE_STATE_ON)        allocStringMap(&strings, (char *)"acpi", (char *)"true");    if (def->features[VIR_DOMAIN_FEATURE_APIC] == VIR_DOMAIN_FEATURE_STATE_ON)        allocStringMap(&strings, (char *)"apic", (char *)"true");    if (def->features[VIR_DOMAIN_FEATURE_PAE] == VIR_DOMAIN_FEATURE_STATE_ON)        allocStringMap(&strings, (char *)"pae", (char *)"true");    if (def->features[VIR_DOMAIN_FEATURE_HAP] == VIR_DOMAIN_FEATURE_STATE_ON)        allocStringMap(&strings, (char *)"hap", (char *)"true");    if (def->features[VIR_DOMAIN_FEATURE_VIRIDIAN] == VIR_DOMAIN_FEATURE_STATE_ON)        allocStringMap(&strings, (char *)"viridian", (char *)"true");    if (strings != NULL)        (*record)->platform = strings;    (*record)->vcpus_params = xen_string_string_map_alloc(0);    (*record)->other_config = xen_string_string_map_alloc(0);    (*record)->last_boot_cpu_flags = xen_string_string_map_alloc(0);    (*record)->xenstore_data = xen_string_string_map_alloc(0);    (*record)->hvm_shadow_multiplier = 1.000;    if (!xen_vm_create(((struct _xenapiPrivate *)(conn->privateData))->session,                        vm, *record)) {        xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, NULL);        return -1;    }    for (i = 0; i < def->nnets; i++) {        if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&            def->nets[i]->data.bridge.brname) {            char *mac;            if (VIR_ALLOC_N(mac, VIR_MAC_STRING_BUFLEN) < 0)                goto error;//.........这里部分代码省略.........
开发者ID:miurahr,项目名称:libvirt,代码行数:101,


示例26: virNWFilterObjListAssignDef

virNWFilterObjPtrvirNWFilterObjListAssignDef(virNWFilterObjListPtr nwfilters,                            virNWFilterDefPtr def){    virNWFilterObjPtr obj;    virNWFilterDefPtr objdef;    if ((obj = virNWFilterObjListFindByUUID(nwfilters, def->uuid))) {        objdef = obj->def;        if (STRNEQ(def->name, objdef->name)) {            virReportError(VIR_ERR_OPERATION_FAILED,                           _("filter with same UUID but different name "                             "('%s') already exists"),                           objdef->name);            virNWFilterObjUnlock(obj);            return NULL;        }        virNWFilterObjUnlock(obj);    } else {        if ((obj = virNWFilterObjListFindByName(nwfilters, def->name))) {            char uuidstr[VIR_UUID_STRING_BUFLEN];            objdef = obj->def;            virUUIDFormat(objdef->uuid, uuidstr);            virReportError(VIR_ERR_OPERATION_FAILED,                           _("filter '%s' already exists with uuid %s"),                           def->name, uuidstr);            virNWFilterObjUnlock(obj);            return NULL;        }    }    if (virNWFilterObjListDefLoopDetect(nwfilters, def) < 0) {        virReportError(VIR_ERR_OPERATION_FAILED,                       "%s", _("filter would introduce a loop"));        return NULL;    }    if ((obj = virNWFilterObjListFindByName(nwfilters, def->name))) {        objdef = obj->def;        if (virNWFilterDefEqual(def, objdef, false)) {            virNWFilterDefFree(objdef);            obj->def = def;            return obj;        }        obj->newDef = def;        /* trigger the update on VMs referencing the filter */        if (virNWFilterTriggerVMFilterRebuild() < 0) {            obj->newDef = NULL;            virNWFilterObjUnlock(obj);            return NULL;        }        virNWFilterDefFree(objdef);        obj->def = def;        obj->newDef = NULL;        return obj;    }    if (!(obj = virNWFilterObjNew()))        return NULL;    if (VIR_APPEND_ELEMENT_COPY(nwfilters->objs,                                nwfilters->count, obj) < 0) {        virNWFilterObjUnlock(obj);        virNWFilterObjFree(obj);        return NULL;    }    obj->def = def;    return obj;}
开发者ID:RWTH-OS,项目名称:libvirt,代码行数:76,


示例27: createVMRecordFromXml

/* Create a VM record from the XML description */intcreateVMRecordFromXml (virConnectPtr conn, virDomainDefPtr def,                       xen_vm_record **record, xen_vm *vm){    char uuidStr[VIR_UUID_STRING_BUFLEN];    *record = xen_vm_record_alloc();    if (!((*record)->name_label = strdup(def->name)))        goto error_cleanup;    if (def->uuid) {        virUUIDFormat(def->uuid, uuidStr);        if (!((*record)->uuid = strdup(uuidStr)))            goto error_cleanup;    }    if (STREQ(def->os.type, "hvm")) {        char *boot_order = NULL;        if (!((*record)->hvm_boot_policy = strdup("BIOS order")))            goto error_cleanup;        if (def->os.nBootDevs != 0)            boot_order = createXenAPIBootOrderString(def->os.nBootDevs, &def->os.bootDevs[0]);        if (boot_order != NULL) {            xen_string_string_map *hvm_boot_params = NULL;            allocStringMap(&hvm_boot_params, (char *)"order", boot_order);            (*record)->hvm_boot_params = hvm_boot_params;            VIR_FREE(boot_order);        }    } else if (STREQ(def->os.type, "xen")) {        if (!((*record)->pv_bootloader = strdup("pygrub")))            goto error_cleanup;        if (def->os.kernel) {            if (!((*record)->pv_kernel = strdup(def->os.kernel)))                goto error_cleanup;        }        if (def->os.initrd) {            if (!((*record)->pv_ramdisk = strdup(def->os.initrd)))                goto error_cleanup;        }        if (def->os.cmdline) {            if (!((*record)->pv_args = strdup(def->os.cmdline)))                goto error_cleanup;        }        (*record)->hvm_boot_params = xen_string_string_map_alloc(0);    }    if (def->os.bootloaderArgs)        if (!((*record)->pv_bootloader_args = strdup(def->os.bootloaderArgs)))            goto error_cleanup;    if (def->memory)        (*record)->memory_static_max = (int64_t) (def->memory * 1024);    if (def->maxmem)        (*record)->memory_dynamic_max = (int64_t) (def->maxmem * 1024);    else        (*record)->memory_dynamic_max = (*record)->memory_static_max;    if (def->vcpus) {        (*record)->vcpus_max = (int64_t) def->vcpus;        (*record)->vcpus_at_startup = (int64_t) def->vcpus;    }    if (def->onPoweroff)        (*record)->actions_after_shutdown = actionShutdownLibvirt2XenapiEnum(def->onPoweroff);    if (def->onReboot)        (*record)->actions_after_reboot = actionShutdownLibvirt2XenapiEnum(def->onReboot);    if (def->onCrash)        (*record)->actions_after_crash = actionCrashLibvirt2XenapiEnum(def->onCrash);    xen_string_string_map *strings = NULL;    if (def->features) {        if (def->features & (1 << VIR_DOMAIN_FEATURE_ACPI))            allocStringMap(&strings, (char *)"acpi", (char *)"true");        if (def->features & (1 << VIR_DOMAIN_FEATURE_APIC))            allocStringMap(&strings, (char *)"apic", (char *)"true");        if (def->features & (1 << VIR_DOMAIN_FEATURE_PAE))            allocStringMap(&strings, (char *)"pae", (char *)"true");    }    if (strings != NULL)        (*record)->platform = strings;    (*record)->vcpus_params = xen_string_string_map_alloc(0);    (*record)->other_config = xen_string_string_map_alloc(0);    (*record)->last_boot_cpu_flags = xen_string_string_map_alloc(0);    (*record)->xenstore_data = xen_string_string_map_alloc(0);    (*record)->hvm_shadow_multiplier = 1.000;    if (!xen_vm_create(((struct _xenapiPrivate *)(conn->privateData))->session,                        vm, *record)) {        xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, NULL);        return -1;    }    int device_number = 0;    char *bridge = NULL, *mac = NULL;    int i;    for (i = 0; i < def->nnets; i++) {        if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {            if (def->nets[i]->data.bridge.brname)                if (!(bridge = strdup(def->nets[i]->data.bridge.brname)))                    goto error_cleanup;            if (def->nets[i]->mac) {                char macStr[VIR_MAC_STRING_BUFLEN];                virFormatMacAddr(def->nets[i]->mac, macStr);                if (!(mac = strdup(macStr))) {//.........这里部分代码省略.........
开发者ID:hjwsm1989,项目名称:libvirt,代码行数:101,


示例28: virStorageBackendRBDOpenRADOSConn

static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr *ptr,        virConnectPtr conn,        virStoragePoolObjPtr pool){    int ret = -1;    unsigned char *secret_value = NULL;    size_t secret_value_size;    char *rados_key = NULL;    virBuffer mon_host = VIR_BUFFER_INITIALIZER;    virSecretPtr secret = NULL;    char secretUuid[VIR_UUID_STRING_BUFLEN];    int i;    char *mon_buff = NULL;    VIR_DEBUG("Found Cephx username: %s",              pool->def->source.auth.cephx.username);    if (pool->def->source.auth.cephx.username != NULL) {        VIR_DEBUG("Using cephx authorization");        if (rados_create(&ptr->cluster,                         pool->def->source.auth.cephx.username) < 0) {            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                           _("failed to initialize RADOS"));            goto cleanup;        }        if (pool->def->source.auth.cephx.secret.uuidUsable) {            virUUIDFormat(pool->def->source.auth.cephx.secret.uuid, secretUuid);            VIR_DEBUG("Looking up secret by UUID: %s", secretUuid);            secret = virSecretLookupByUUIDString(conn, secretUuid);        } else if (pool->def->source.auth.cephx.secret.usage != NULL) {            VIR_DEBUG("Looking up secret by usage: %s",                      pool->def->source.auth.cephx.secret.usage);            secret = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_CEPH,                                            pool->def->source.auth.cephx.secret.usage);        }        if (secret == NULL) {            virReportError(VIR_ERR_NO_SECRET, "%s",                           _("failed to find the secret"));            goto cleanup;        }        secret_value = virSecretGetValue(secret, &secret_value_size, 0);        base64_encode_alloc((char *)secret_value,                            secret_value_size, &rados_key);        memset(secret_value, 0, secret_value_size);        if (rados_key == NULL) {            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                           _("failed to decode the RADOS key"));            goto cleanup;        }        VIR_DEBUG("Found cephx key: %s", rados_key);        if (rados_conf_set(ptr->cluster, "key", rados_key) < 0) {            virReportError(VIR_ERR_INTERNAL_ERROR,                           _("failed to set RADOS option: %s"),                           "rados_key");            goto cleanup;        }        memset(rados_key, 0, strlen(rados_key));        if (rados_conf_set(ptr->cluster, "auth_supported", "cephx") < 0) {            virReportError(VIR_ERR_INTERNAL_ERROR,                           _("failed to set RADOS option: %s"),                           "auth_supported");            goto cleanup;        }    } else {        VIR_DEBUG("Not using cephx authorization");        if (rados_create(&ptr->cluster, NULL) < 0) {            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                           _("failed to create the RADOS cluster"));            goto cleanup;        }        if (rados_conf_set(ptr->cluster, "auth_supported", "none") < 0) {            virReportError(VIR_ERR_INTERNAL_ERROR,                           _("failed to set RADOS option: %s"),                           "auth_supported");            goto cleanup;        }    }    VIR_DEBUG("Found %zu RADOS cluster monitors in the pool configuration",              pool->def->source.nhost);    for (i = 0; i < pool->def->source.nhost; i++) {        if (pool->def->source.hosts[i].name != NULL &&                !pool->def->source.hosts[i].port) {            virBufferAsprintf(&mon_host, "%s:6789,",                              pool->def->source.hosts[i].name);        } else if (pool->def->source.hosts[i].name != NULL &&                   pool->def->source.hosts[i].port) {            virBufferAsprintf(&mon_host, "%s:%d,",                              pool->def->source.hosts[i].name,                              pool->def->source.hosts[i].port);        } else {            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",//.........这里部分代码省略.........
开发者ID:pawitp,项目名称:libvirt,代码行数:101,


示例29: hypervDomainGetXMLDesc

static char *hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags){    char *xml = NULL;    hypervPrivate *priv = domain->conn->privateData;    virDomainDefPtr def = NULL;    char uuid_string[VIR_UUID_STRING_BUFLEN];    virBuffer query = VIR_BUFFER_INITIALIZER;    Msvm_ComputerSystem *computerSystem = NULL;    Msvm_VirtualSystemSettingData *virtualSystemSettingData = NULL;    Msvm_ProcessorSettingData *processorSettingData = NULL;    Msvm_MemorySettingData *memorySettingData = NULL;    /* Flags checked by virDomainDefFormat */    if (VIR_ALLOC(def) < 0)        goto cleanup;    virUUIDFormat(domain->uuid, uuid_string);    /* Get Msvm_ComputerSystem */    if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) {        goto cleanup;    }    /* Get Msvm_VirtualSystemSettingData */    virBufferAsprintf(&query,                      "associators of "                      "{Msvm_ComputerSystem.CreationClassName=/"Msvm_ComputerSystem/","                      "Name=/"%s/"} "                      "where AssocClass = Msvm_SettingsDefineState "                      "ResultClass = Msvm_VirtualSystemSettingData",                      uuid_string);    if (hypervGetMsvmVirtualSystemSettingDataList(priv, &query,                                                  &virtualSystemSettingData) < 0) {        goto cleanup;    }    if (virtualSystemSettingData == NULL) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Could not lookup %s for domain %s"),                       "Msvm_VirtualSystemSettingData",                       computerSystem->data->ElementName);        goto cleanup;    }    /* Get Msvm_ProcessorSettingData */    virBufferAsprintf(&query,                      "associators of "                      "{Msvm_VirtualSystemSettingData.InstanceID=/"%s/"} "                      "where AssocClass = Msvm_VirtualSystemSettingDataComponent "                      "ResultClass = Msvm_ProcessorSettingData",                      virtualSystemSettingData->data->InstanceID);    if (hypervGetMsvmProcessorSettingDataList(priv, &query,                                              &processorSettingData) < 0) {        goto cleanup;    }    if (processorSettingData == NULL) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Could not lookup %s for domain %s"),                       "Msvm_ProcessorSettingData",                       computerSystem->data->ElementName);        goto cleanup;    }    /* Get Msvm_MemorySettingData */    virBufferAsprintf(&query,                      "associators of "                      "{Msvm_VirtualSystemSettingData.InstanceID=/"%s/"} "                      "where AssocClass = Msvm_VirtualSystemSettingDataComponent "                      "ResultClass = Msvm_MemorySettingData",                      virtualSystemSettingData->data->InstanceID);    if (hypervGetMsvmMemorySettingDataList(priv, &query,                                           &memorySettingData) < 0) {        goto cleanup;    }    if (memorySettingData == NULL) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Could not lookup %s for domain %s"),                       "Msvm_MemorySettingData",                       computerSystem->data->ElementName);        goto cleanup;    }    /* Fill struct */    def->virtType = VIR_DOMAIN_VIRT_HYPERV;    if (hypervIsMsvmComputerSystemActive(computerSystem, NULL)) {        def->id = computerSystem->data->ProcessID;    } else {        def->id = -1;    }    if (virUUIDParse(computerSystem->data->Name, def->uuid) < 0) {//.........这里部分代码省略.........
开发者ID:vikhyath,项目名称:libvirt-hyperv-r2-2012,代码行数:101,


示例30: hypervDomainGetInfo

static inthypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info){    int result = -1;    hypervPrivate *priv = domain->conn->privateData;    char uuid_string[VIR_UUID_STRING_BUFLEN];    virBuffer query = VIR_BUFFER_INITIALIZER;    Msvm_ComputerSystem *computerSystem = NULL;    Msvm_VirtualSystemSettingData *virtualSystemSettingData = NULL;    Msvm_ProcessorSettingData *processorSettingData = NULL;    Msvm_MemorySettingData *memorySettingData = NULL;    memset(info, 0, sizeof(*info));    virUUIDFormat(domain->uuid, uuid_string);    /* Get Msvm_ComputerSystem */    if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) {        goto cleanup;    }    /* Get Msvm_VirtualSystemSettingData */    virBufferAsprintf(&query,                      "associators of "                      "{Msvm_ComputerSystem.CreationClassName=/"Msvm_ComputerSystem/","                      "Name=/"%s/"} "                      "where AssocClass = Msvm_SettingsDefineState "                      "ResultClass = Msvm_VirtualSystemSettingData",                      uuid_string);    if (hypervGetMsvmVirtualSystemSettingDataList(priv, &query,                                                  &virtualSystemSettingData) < 0) {        goto cleanup;    }    if (virtualSystemSettingData == NULL) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Could not lookup %s for domain %s"),                       "Msvm_VirtualSystemSettingData",                       computerSystem->data->ElementName);        goto cleanup;    }    /* Get Msvm_ProcessorSettingData */    virBufferAsprintf(&query,                      "associators of "                      "{Msvm_VirtualSystemSettingData.InstanceID=/"%s/"} "                      "where AssocClass = Msvm_VirtualSystemSettingDataComponent "                      "ResultClass = Msvm_ProcessorSettingData",                      virtualSystemSettingData->data->InstanceID);    if (hypervGetMsvmProcessorSettingDataList(priv, &query,                                              &processorSettingData) < 0) {        goto cleanup;    }    if (processorSettingData == NULL) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Could not lookup %s for domain %s"),                       "Msvm_ProcessorSettingData",                       computerSystem->data->ElementName);        goto cleanup;    }    /* Get Msvm_MemorySettingData */    virBufferAsprintf(&query,                      "associators of "                      "{Msvm_VirtualSystemSettingData.InstanceID=/"%s/"} "                      "where AssocClass = Msvm_VirtualSystemSettingDataComponent "                      "ResultClass = Msvm_MemorySettingData",                      virtualSystemSettingData->data->InstanceID);    if (hypervGetMsvmMemorySettingDataList(priv, &query,                                           &memorySettingData) < 0) {        goto cleanup;    }    if (memorySettingData == NULL) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Could not lookup %s for domain %s"),                       "Msvm_MemorySettingData",                       computerSystem->data->ElementName);        goto cleanup;    }    /* Fill struct */    info->state = hypervMsvmComputerSystemEnabledStateToDomainState(computerSystem);    info->maxMem = memorySettingData->data->Limit * 1024; /* megabyte to kilobyte */    info->memory = memorySettingData->data->VirtualQuantity * 1024; /* megabyte to kilobyte */    info->nrVirtCpu = processorSettingData->data->VirtualQuantity;    info->cpuTime = 0;    result = 0; cleanup:    hypervFreeObject(priv, (hypervObject *)computerSystem);    hypervFreeObject(priv, (hypervObject *)virtualSystemSettingData);    hypervFreeObject(priv, (hypervObject *)processorSettingData);    hypervFreeObject(priv, (hypervObject *)memorySettingData);//.........这里部分代码省略.........
开发者ID:vikhyath,项目名称:libvirt-hyperv-r2-2012,代码行数:101,



注:本文中的virUUIDFormat函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ virXPathString函数代码示例
C++ virStrToLong_i函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。