Ejemplo n.º 1
0
void NodeWrap::checkPool(char *pool_name)
{
    virStoragePoolPtr pool_ptr;

    bool found = false;
    for (std::vector<PoolWrap*>::iterator iter = pools.begin();
            iter != pools.end(); iter++) {
        if ((*iter)->pool_name == pool_name) {
            found = true;
            break;
        }
    }

    if (found) {
        return;
    }

    pool_ptr = virStoragePoolLookupByName(conn, pool_name);
    if (!pool_ptr) {
        REPORT_ERR(conn, "virStoragePoolLookupByName");
    } else {
        printf("Creating new pool: %s, ptr is %p\n", pool_name, pool_ptr);
        PoolWrap *pool;
        try {
            pool = new PoolWrap(agent, this, pool_ptr, conn);
            printf("Created new pool: %s, ptr is %p\n", pool_name, pool_ptr);
            pools.push_back(pool);
        } catch (int i) {
            printf ("Error constructing pool\n");
            REPORT_ERR(conn, "constructing pool.");
            delete pool;
        }
    }
}
Ejemplo n.º 2
0
void NodeWrap::syncPools()
{
    int maxname;

    maxname = virConnectNumOfStoragePools(conn);
    if (maxname < 0) {
        REPORT_ERR(conn, "virConnectNumOfStroagePools");
        return;
    } else {
        char **names;
        names = (char **) malloc(sizeof(char *) * maxname);

        if ((maxname = virConnectListStoragePools(conn, names, maxname)) < 0) {
            REPORT_ERR(conn, "virConnectListStoragePools");
            return;
        }

        for (int i = 0; i < maxname; i++) {
            checkPool(names[i]);
            free(names[i]);
        }
        free(names);
    }

    maxname = virConnectNumOfDefinedStoragePools(conn);
    if (maxname < 0) {
        REPORT_ERR(conn, "virConnectNumOfDefinedStoragePools");
        return;
    } else {
        char **names;
        names = (char **) malloc(sizeof(char *) * maxname);

        if ((maxname = virConnectListDefinedStoragePools(conn, names, maxname)) < 0) {
            REPORT_ERR(conn, "virConnectListDefinedStoragePools");
            return;
        }

        for (int i = 0; i < maxname; i++) {
            checkPool(names[i]);
            free(names[i]);
        }

        free(names);
    }

    /* Go through our list of pools and ensure that they still exist. */
    for (std::vector<PoolWrap*>::iterator iter = pools.begin(); iter != pools.end();) {

        printf ("Verifying pool %s\n", (*iter)->pool_name.c_str());
        virStoragePoolPtr ptr = virStoragePoolLookupByUUIDString(conn, (*iter)->pool_uuid.c_str());
        if (ptr == NULL) {
            printf("Destroying pool %s\n", (*iter)->pool_name.c_str());
            delete(*iter);
            iter = pools.erase(iter);
        } else {
            virStoragePoolFree(ptr);
            iter++;
        }
    }
}
Ejemplo n.º 3
0
void ppp_copy(cs * to, cs const * from)
{
  int j;
  if(!CS_CSC(to) || !CS_CSC(from)) REPORT_ERR(PPP_EOP);
  if(to->n != from->n || to->m != from->m) REPORT_ERR(PPP_EOP);
  cs * zero = cs_spalloc(from->m, from->n, 0, 1, 0);
  for(j=0;j<=zero->n;++j)
    zero->p[j] = 0;
  ppp_add(to, from, zero, 1);
  cs_spfree(zero);
}
Ejemplo n.º 4
0
VolumeWrap::VolumeWrap(PoolWrap *parent,
                       virStorageVolPtr volume_ptr,
                       virConnectPtr connect):
    PackageOwner<PoolWrap::PackageDefinition>(parent),
    ManagedObject(package().data_Volume),
    _volume_ptr(volume_ptr), _conn(connect),
    _lvm_name(""), _has_lvm_child(false),
    _wrap_parent(parent)
{
    const char *volume_key;
    char *volume_path;
    const char *volume_name;

    volume_key = virStorageVolGetKey(_volume_ptr);
    if (volume_key == NULL) {
        REPORT_ERR(_conn, "Error getting storage volume key\n");
        throw 1;
    }
    _volume_key = volume_key;

    volume_path = virStorageVolGetPath(_volume_ptr);
    if (volume_path == NULL) {
        REPORT_ERR(_conn, "Error getting volume path\n");
        throw 1;
    }
    _volume_path = volume_path;

    volume_name = virStorageVolGetName(_volume_ptr);
    if (volume_name == NULL) {
        REPORT_ERR(_conn, "Error getting volume name\n");
        throw 1;
    }
    _volume_name = volume_name;

    _data.setProperty("key", _volume_key);
    _data.setProperty("path", _volume_path);
    _data.setProperty("name", _volume_name);
    _data.setProperty("childLVMName", _lvm_name);
    _data.setProperty("storagePool", parent->objectID());

    // Set defaults
    _data.setProperty("capacity", (uint64_t)0);
    _data.setProperty("allocation", (uint64_t)0);

    addData(_data);

    printf("done\n");
}
Ejemplo n.º 5
0
void
VolumeWrap::update()
{
    virStorageVolInfo info;
    int ret;

    printf("Updating volume info\n");

    ret = virStorageVolGetInfo(_volume_ptr, &info);
    if (ret < 0) {
        REPORT_ERR(_conn, "VolumeWrap: Unable to get info of storage volume info\n");
        return;
    }
    _data.setProperty("capacity", (uint64_t)info.capacity);
    _data.setProperty("allocation", (uint64_t)info.allocation);
}
Ejemplo n.º 6
0
int
insert_record(struct bdb_t *bdbp, void *key_ptr, size_t key_len, void *value_ptr, size_t value_len)
{
    int ret;
    DBT key_ref, value_ref;

    bzero(&key_ref, sizeof key_ref);
    bzero(&value_ref, sizeof value_ref);
    bdbp->error_no = 0;

    key_ref.data = key_ptr;
    key_ref.size = key_len;
    value_ref.data = value_ptr;
    value_ref.size = value_len;

    BUILD_DB_PREFIX;
    if ((ret = bdbp->dbp->put(bdbp->dbp, NULL, &key_ref, &value_ref, 0)) != 0)
    {
        REPORT_ERR("bdb insert failed: %d - %s", ret, db_strerror(ret));
    }

err:
    return ret;
}
Ejemplo n.º 7
0
int
find_record(struct bdb_t *bdbp, DBT **dbt_ptr, void *key_ptr, size_t key_len, size_t *value_len)
{
    assert(dbt_ptr != NULL);
    assert(key_ptr != NULL);
    assert(value_len != NULL);

    void *value_ptr = NULL;
    int ret;
    DBT query_cond;
    int alloc_flag;

    alloc_flag = 0;

    if (*dbt_ptr == NULL)
    {
        if ((*dbt_ptr = slab_alloc(sizeof **dbt_ptr)) == NULL)
        {
            ret = -1;
            REPORT_ERR("memory is not enough");
        }
        alloc_flag = alloc_flag | FIND_RECORD_ALLOC_DBT_PTR;
    }
    if ((value_ptr = slab_alloc(*value_len)) == NULL)
    {
        ret = -1;
        REPORT_ERR("memory is not enough");
    }
    alloc_flag = alloc_flag | FIND_RECORD_ALLOC_VAL_PTR;

    memset(&query_cond, 0, sizeof query_cond);
    memset(*dbt_ptr, 0, sizeof **dbt_ptr);
    memset(value_ptr, 0, *value_len);

    query_cond.data = key_ptr;
    query_cond.size = key_len;
    (*dbt_ptr)->data = value_ptr;
    (*dbt_ptr)->ulen = *value_len;
    (*dbt_ptr)->flags = DB_DBT_USERMEM;

    BUILD_DB_PREFIX;
    if ((ret = bdbp->dbp->get(bdbp->dbp, NULL, &query_cond, *dbt_ptr, 0)) != 0)
    {
        if (ret != DB_NOTFOUND)
            REPORT_ERR("bdb query failed: %s", db_strerror(ret));
    }

err:
    if (ret != 0)
    {
        if ((alloc_flag & FIND_RECORD_ALLOC_DBT_PTR) && (*dbt_ptr != NULL))
        {
            slab_free(*dbt_ptr);
            *dbt_ptr = NULL;
        }
        if ((alloc_flag & FIND_RECORD_ALLOC_VAL_PTR) && (value_ptr != NULL))
        {
            slab_free(value_ptr);
            if (*dbt_ptr != NULL)
                (*dbt_ptr)->data = NULL;
        }
    }
    return ret;
}
Ejemplo n.º 8
0
int
list_keys(struct bdb_t *bdbp, void *start_key, size_t key_len, void **key_ptr, size_t *key_count)
{
    (void) start_key;
    (void) key_len;

    DBC *cursor;
    int ret;
    if ((ret = bdbp->dbp->cursor(bdbp->dbp, NULL, &cursor, DB_CURSOR_BULK)) != 0)
        return ret;
    
    DBT key, value;
    memset(&key, 0, sizeof(DBT));
    memset(&value, 0, sizeof(DBT));
    key.flags = DB_DBT_MALLOC;
    key.data = start_key;
    if (start_key)
        key.size = key_len;

    // printf("start_key, key_len = %p %zu\n", start_key, key_len);

    value.flags = DB_DBT_REALLOC;

    size_t count = 0;

    
    for (ret = cursor->get(cursor, &key, &value, DB_SET_RANGE); ret != DB_NOTFOUND; ret = cursor->get(cursor, &key, &value, DB_NEXT)) {

        if (ret != 0) {
            for (size_t i = 0; i < count; i++)
                free(key_ptr[i]);
            goto err;
        }

        if (count >= *key_count) {
            free(key.data);
            break;
        }

        if (key.size == key_len) {
            if (start_key && memcmp(start_key, key.data, key_len) == 0) {
                free(key.data);
                continue;
            }
            key_ptr[count++] = key.data;
        }
        else {
            REPORT_ERR("invalid key size %"PRIu32", should be %zu", key.size, key_len);
        }
    }
    ret = 0;

    *key_count = count;

err:
    cursor->close(cursor);

    free(value.data);

    return ret;
}
Ejemplo n.º 9
0
/* Tokenize a header. tokens may be NULL, in which case the number of tokens
   are counted, allowing the caller to allocate enough room */
static void tokenize(const char *header, php_rfc822_token_t *tokens,
                     int *ntokens, int report_errors) {
  register const char *p, *q, *start;
  int in_bracket = 0;

/* NB: parser assumes that the header has two bytes of NUL terminator */

  YYCURSOR = header;
  YYLIMIT = YYCURSOR + strlen(YYCURSOR) + 1;

  *ntokens = 0;

state_ground:
  start = YYCURSOR;

#if DEBUG_RFC822_SCANNER
  printf("ground: start=%p limit=%p cursor=%p: [%d] %s\n",
         start, YYLIMIT, YYCURSOR, *YYCURSOR, YYCURSOR);
#endif

{
  YYCTYPE yych;
  static const unsigned char yybm[] = {
      0, 192, 192, 192, 192, 192, 192, 192,
    192,  96,  96, 192, 192,  96, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
     96,  64,   0, 192, 192,  64, 192, 192,
     64,  64, 192, 192,  64, 192,  64,  64,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192,  64,  64,  64,  64,  64,  64,
     64, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192,  64, 192,  64, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
    192, 192, 192, 192, 192, 192, 192, 192,
  };

  if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
  yych = *YYCURSOR;
  if (yybm[0+yych] & 32) {
    goto yy4;
  }
  if (yych <= '-') {
    if (yych <= '%') {
      if (yych <= '!') {
        if (yych <= 0x00) goto yy2;
        if (yych <= ' ') goto yy21;
        goto yy19;
      } else {
        if (yych <= '"') goto yy12;
        if (yych <= '$') goto yy21;
        goto yy19;
      }
    } else {
      if (yych <= ')') {
        if (yych <= '\'') goto yy21;
        if (yych <= '(') goto yy10;
        goto yy7;
      } else {
        if (yych == ',') goto yy19;
        goto yy21;
      }
    }
  } else {
    if (yych <= '>') {
      if (yych <= ';') {
        if (yych <= '/') goto yy19;
        if (yych <= '9') goto yy21;
        goto yy19;
      } else {
        if (yych <= '<') goto yy15;
        if (yych <= '=') goto yy19;
        goto yy17;
      }
    } else {
      if (yych <= '[') {
        if (yych <= '@') goto yy19;
        if (yych <= 'Z') goto yy21;
        goto yy19;
      } else {
        if (yych <= '\\') goto yy9;
        if (yych <= ']') goto yy19;
        goto yy21;
      }
    }
  }
yy2:
  ++YYCURSOR;
  {  goto stop; }
yy4:
  ++YYCURSOR;
  if (YYLIMIT <= YYCURSOR) YYFILL(1);
  yych = *YYCURSOR;
  if (yybm[0+yych] & 32) {
    goto yy4;
  }
  {  DBG_STATE("SPACE"); goto state_ground; }
yy7:
  ++YYCURSOR;
yy8:
  {  REPORT_ERR("token not valid in ground state"); goto state_ground; }
yy9:
  yych = *++YYCURSOR;
  if (yybm[0+yych] & 128) {
    goto yy21;
  }
  goto yy8;
yy10:
  ++YYCURSOR;
  {  DBG_STATE("START COMMENT");
    if (tokens) {
      tokens->token = '(';
      tokens->value = start;
      tokens->valuelen = 0;
    }
    goto state_comment;
  }
yy12:
  ++YYCURSOR;
  if (YYLIMIT <= YYCURSOR) YYFILL(1);
  yych = *YYCURSOR;
  if (yybm[0+yych] & 64) {
    goto yy12;
  }
  if (yych >= 0x01) goto yy26;
yy15:
  ++YYCURSOR;
  if ((yych = *YYCURSOR) == '>') goto yy24;
  {   DBG_STATE("LANGLE");
    if (in_bracket) {
      REPORT_ERR("already in < bracket");
      goto state_ground;
    }
    in_bracket = 1;
    ADD_ATOM_TOKEN();
    goto state_ground;
  }
yy17:
  ++YYCURSOR;
  {  DBG_STATE("RANGLE");
    if (!in_bracket) {
      REPORT_ERR("not in < bracket");
      goto state_ground;
    }
    in_bracket = 0;
    ADD_ATOM_TOKEN();
    goto state_ground;
  }
yy19:
  ++YYCURSOR;
  {   DBG_STATE("ATOM"); ADD_ATOM_TOKEN(); goto state_ground; }
yy21:
  ++YYCURSOR;
  if (YYLIMIT <= YYCURSOR) YYFILL(1);
  yych = *YYCURSOR;
  if (yybm[0+yych] & 128) {
    goto yy21;
  }
  {  DBG_STATE("ANY");
    if (tokens) {
      tokens->token = 0;
      tokens->valuelen = YYCURSOR - start;
      tokens->value = start;
      tokens++;
    }
    ++*ntokens;
    goto state_ground;
  }
yy24:
  ++YYCURSOR;
  {  DBG_STATE("NULL <>");
    ADD_ATOM_TOKEN();
    if (tokens) {
      tokens->token = 0;
      tokens->value = "";
      tokens->valuelen = 0;
      tokens++;
    }
    ++*ntokens;
    start++;
    ADD_ATOM_TOKEN();
    goto state_ground;
  }
yy26:
  ++YYCURSOR;
  {   DBG_STATE("QUOTE STRING");
    if (tokens) {
      tokens->token = '"';
      tokens->value = start + 1;
      tokens->valuelen = YYCURSOR - start - 2;
      tokens++;
    }
    ++*ntokens;

    goto state_ground;
  }
}

state_comment:
  {
    int comment_depth = 1;
    while (1) {
      if (*YYCURSOR == 0) {
        /* unexpected end of header */
        REPORT_ERR("unexpected end of header");
        /* fake a quoted string for this last token */
        if (tokens)
          tokens->token = '"';
        ++*ntokens;
        return;
      } else if (*YYCURSOR == '(') {
        comment_depth++;
      } else if (*YYCURSOR == ')' && --comment_depth == 0) {
        /* end of nested comment sequence */
        YYCURSOR++;
        if (tokens)
          tokens->valuelen++;
        break;
      } else if (*YYCURSOR == '\\' && YYCURSOR[1]) {
        YYCURSOR++;
        if (tokens)
          tokens->valuelen++;
      }
      YYCURSOR++;
    }
    if (tokens) {
      tokens->valuelen = YYCURSOR - tokens->value;
      tokens++;
    }
    ++*ntokens;
    goto state_ground;
  }
stop:
#if DEBUG_RFC822_SCANNER
  printf("STOPing parser ntokens=%d YYCURSOR=%p YYLIMIT=%p start=%p "
         "cursor=[%d] %s start=%s\n", *ntokens,
         YYCURSOR, YYLIMIT, start, *YYCURSOR, YYCURSOR, start);
#else
  ;
#endif
}
Ejemplo n.º 10
0
NodeWrap::NodeWrap(ManagementAgent* _agent, string _name) : name(_name), agent(_agent)
{
    virNodeInfo info;
    char *hostname;
    char libvirt_version[256] = "Unknown";
    char api_version[256] = "Unknown";
    char hv_version[256] = "Unknown";
    char *uri;
    const char *hv_type;
    unsigned long api_v;
    unsigned long libvirt_v;
    unsigned long hv_v;
    int ret;
    unsigned int major;
    unsigned int minor;
    unsigned int rel;

    conn = virConnectOpen(NULL);
    if (!conn) {
        REPORT_ERR(conn, "virConnectOpen");
        throw -1;
    }

    hostname = virConnectGetHostname(conn);
    if (hostname == NULL) {
        REPORT_ERR(conn, "virConnectGetHostname");
        throw -1;
    }

    hv_type = virConnectGetType(conn);
    if (hv_type == NULL) {
        REPORT_ERR(conn, "virConnectGetType");
        throw -1;
    }

    uri = virConnectGetURI(conn);
    if (uri == NULL) {
        REPORT_ERR(conn, "virConnectGetURI");
        throw -1;
    }

    ret = virGetVersion(&libvirt_v, hv_type, &api_v);
    if (ret < 0) {
        REPORT_ERR(conn, "virGetVersion");
    } else {
        major = libvirt_v / 1000000;
        libvirt_v %= 1000000;
        minor = libvirt_v / 1000;
        rel = libvirt_v % 1000;
        snprintf(libvirt_version, sizeof(libvirt_version), "%d.%d.%d", major, minor, rel);

        major = api_v / 1000000;
        api_v %= 1000000;
        minor = api_v / 1000;
        rel = api_v % 1000;
        snprintf(api_version, sizeof(api_version), "%d.%d.%d", major, minor, rel);
    }

    ret = virConnectGetVersion(conn, &hv_v);
    if (ret < 0) {
        REPORT_ERR(conn, "virConnectGetVersion");
    } else {
        major = hv_v / 1000000;
        hv_v %= 1000000;
        minor = hv_v / 1000;
        rel = hv_v % 1000;
        snprintf(hv_version, sizeof(hv_version), "%d.%d.%d", major, minor, rel);
    }

    ret = virNodeGetInfo(conn, &info);
    if (ret < 0) {
        REPORT_ERR(conn, "virNodeGetInfo");
        memset((void *) &info, sizeof(info), 1);
    }

    mgmtObject = new _qmf::Node(agent, this, hostname, uri, libvirt_version, api_version, hv_version, hv_type,
                                info.model, info.memory, info.cpus, info.mhz, info.nodes, info.sockets,
                                info.cores, info.threads);
    agent->addObject(mgmtObject);
}
Ejemplo n.º 11
0
void NodeWrap::syncDomains()
{
    /* Sync up with domains that are defined but not active. */
    int maxname = virConnectNumOfDefinedDomains(conn);
    if (maxname < 0) {
        REPORT_ERR(conn, "virConnectNumOfDefinedDomains");
        return;
    } else {
        char **dnames;
        dnames = (char **) malloc(sizeof(char *) * maxname);

        if ((maxname = virConnectListDefinedDomains(conn, dnames, maxname)) < 0) {
            REPORT_ERR(conn, "virConnectListDefinedDomains");
            free(dnames);
            return;
        }


        for (int i = 0; i < maxname; i++) {
            virDomainPtr domain_ptr;

            bool found = false;
            for (std::vector<DomainWrap*>::iterator iter = domains.begin();
                    iter != domains.end(); iter++) {
                if ((*iter)->domain_name == dnames[i]) {
                    found = true;
                    break;
                }
            }

            if (found) {
                continue;
            }

            domain_ptr = virDomainLookupByName(conn, dnames[i]);
            if (!domain_ptr) {
                REPORT_ERR(conn, "virDomainLookupByName");
            } else {
                DomainWrap *domain;
                try {
                    domain = new DomainWrap(agent, this, domain_ptr, conn);
                    printf("Created new domain: %s, ptr is %p\n", dnames[i], domain_ptr);
                    domains.push_back(domain);
                } catch (int i) {
                    printf ("Error constructing domain\n");
                    REPORT_ERR(conn, "constructing domain.");
                    delete domain;
                }
            }
        }
        for (int i = 0; i < maxname; i++) {
            free(dnames[i]);
        }

        free(dnames);
    }

    /* Go through all the active domains */
    int maxids = virConnectNumOfDomains(conn);
    if (maxids < 0) {
        REPORT_ERR(conn, "virConnectNumOfDomains");
        return;
    } else {
        int *ids;
        ids = (int *) malloc(sizeof(int *) * maxids);

        if ((maxids = virConnectListDomains(conn, ids, maxids)) < 0) {
            printf("Error getting list of defined domains\n");
            return;
        }

        for (int i = 0; i < maxids; i++) {
            virDomainPtr domain_ptr;
            char dom_uuid[VIR_UUID_STRING_BUFLEN];

            domain_ptr = virDomainLookupByID(conn, ids[i]);
            if (!domain_ptr) {
                REPORT_ERR(conn, "virDomainLookupByID");
                continue;
            }

            if (virDomainGetUUIDString(domain_ptr, dom_uuid) < 0) {
                REPORT_ERR(conn, "virDomainGetUUIDString");
                continue;
            }

            bool found = false;
            for (std::vector<DomainWrap*>::iterator iter = domains.begin();
                    iter != domains.end(); iter++) {
                if (strcmp((*iter)->domain_uuid.c_str(), dom_uuid) == 0) {
                    found = true;
                    break;
                }
            }

            if (found) {
                virDomainFree(domain_ptr);
                continue;
            }

            DomainWrap *domain;
            try {
                domain = new DomainWrap(agent, this, domain_ptr, conn);
                printf("Created new domain: %d, ptr is %p\n", ids[i], domain_ptr);
                domains.push_back(domain);
            } catch (int i) {
                printf ("Error constructing domain\n");
                REPORT_ERR(conn, "constructing domain.");
                delete domain;
            }
        }

        free(ids);
    }

    /* Go through our list of domains and ensure that they still exist. */
    for (std::vector<DomainWrap*>::iterator iter = domains.begin(); iter != domains.end();) {

        printf("verifying domain %s\n", (*iter)->domain_name.c_str());
        virDomainPtr ptr = virDomainLookupByUUIDString(conn, (*iter)->domain_uuid.c_str());
        if (ptr == NULL) {
            REPORT_ERR(conn, "virDomainLookupByUUIDString");
            delete (*iter);
            iter = domains.erase(iter);
        } else {
            virDomainFree(ptr);
            iter++;
        }
    }
}
Ejemplo n.º 12
0
STATUS
MExdump(
	i4	chain,
	i4	(*fmt)())	/* must be a VARARGS function */
{
    register ME_HEAD	*head;
    register ME_NODE	*blk;
    char		*which;

    STATUS	mexnodedump();
    STATUS	MExheaddump();

    MEstatus = OK;

    switch(chain)
    {
	case ME_D_BOTH:
	    REPORT_ERR(MExdump(ME_D_ALLOC, fmt));
	    if (MEstatus == OK)
		REPORT_ERR(MExdump(ME_D_FREE, fmt));
	    break;

	case ME_D_ALLOC:
	    head = &MElist;
	    which = "Allocated";
	    break;

	case ME_D_FREE:
	    head = &MEfreelist;
	    which = "Free";
	    break;

	default:
	    MEstatus = ME_BD_CHAIN;
	    break;
    }

    if ((chain != ME_D_BOTH) && (MEstatus == OK))
    {
	(void)(*fmt)("\n'%s' chain begins at 0x%08x\n", which,  head);

	REPORT_ERR( MExheaddump( head, fmt ) );
	if (MEstatus == OK)
	{
	    blk = head->MEfirst;
	    while ( blk != (ME_NODE *)head && MEstatus == OK )
	    {
		REPORT_ERR( MExnodedump( blk, fmt ) );
		if (MEstatus == OK)
		{
		    if( blk == blk->MEnext )
		    {
			(void)(*fmt)("\tLOOP DETECTED\n");
			break;
		    }
		    blk = blk->MEnext;
		}
	    }
	}
    }

    return(MEstatus);
}
Ejemplo n.º 13
0
/* Returns the number of iterations */
int conjugate_gradient(cs const * A, cs const * b, cs * x, int imax, double epsilon)
{
  int i;
  cs *At, *r, *d, *y, *q;
  double delnew, delold, del0, alpha, beta;
  
  /* Check input */
  if(!CS_CSC(A) || !CS_CSC(b) || !CS_CSC(x)) REPORT_ERR(PPP_EOP);
  if(imax < 0 || epsilon <= 0 || epsilon >= 1) REPORT_ERR(PPP_EOP);
  if(A->n != x->m || A->m != b->m || x->n != 1 || b->n != 1) REPORT_ERR(PPP_EOP);
  if(A->n != A->m) REPORT_ERR(PPP_EOP);

  /* Allocate memory for all cs */
  At = cs_spalloc(A->n, A->m, A->nzmax, 1, 0);
  r = cs_spalloc(b->m, b->n, b->m, 1, 0);
  d = cs_spalloc(b->m, b->n, b->m, 1, 0);
  y = cs_spalloc(b->m, b->n, b->m, 1, 0);
  q = cs_spalloc(b->m, b->n, b->m, 1, 0);
   
  At = cs_transpose(A, 1);

  i = 0;

  /* r <= b - Ax */
  ppp_gaty(y, At, x); 
  ppp_add(r, b, y, -1);

  /* d <= r */
  ppp_copy(d, r);

  /* delnew <= r'r */
  ppp_dotproduct(&delnew, r, r);

  del0 = delnew;

  while(i < imax && delnew > epsilon * epsilon * del0){
#if defined(LOG_ALGO)
    printf("[Round %d, Line %d]\n", i, 0);
    printf("At:\n");
    cs_print(At, 0);
    printf("del0: %lf\n", del0);
    printf("x:\n");
    cs_print(x, 0);
    printf("r:\n");
    cs_print(r, 0);
    printf("d:\n");
    cs_print(d, 0);
    printf("y:\n");
    cs_print(y, 0);
    printf("q:\n");
    cs_print(q, 0);
    printf("delnew: %lf\n", delnew);
#endif
    /* q <= Ad */
    ppp_gaty(q, At, d);
#if defined(LOG_ALGO)
    printf("[Round %d, Line %d]\n", i, 1);
    printf("q:\n");
    cs_print(q, 0);
#endif
    /* alpha <= delnew / (d'q) */
    ppp_dotproduct(&alpha, d, q);
    alpha = delnew / alpha;
#if defined(LOG_ALGO)
    printf("[Round %d, Line %d]\n", i, 2);
    printf("alpha: %lf\n", alpha);
#endif
    /* x <= x + alpha d */
    ppp_add(y, x, d, alpha);
    ppp_copy(x, y);
#if defined(LOG_ALGO)
    printf("[Round %d, Line %d]\n", i, 3);
    printf("x:\n");
    cs_print(x, 0);
#endif
    if((i+1) % 50 == 0){
      /* r <= b - Ax */
      ppp_gaty(y, A, x);
      ppp_add(r, b, y, -1);
#if defined(LOG_ALGO)
      printf("[Round %d, Line %d]\n", i, 4);
      printf("r:\n");
      cs_print(r, 0);
#endif
    }else{
      /* r <= r - alpha q */
      ppp_add(y, r, q, -1 * alpha);
      ppp_copy(r, y);
#if defined(LOG_ALGO)
      printf("[Round %d, Line %d]\n", i, 5);
      printf("r:\n");
      cs_print(r, 0);
#endif
    }
    delold = delnew;
#if defined(LOG_ALGO)
      printf("[Round %d, Line %d]\n", i, 6);
      printf("delold: %lf\n", delold);
#endif
    /* delnew = r'r */
    ppp_dotproduct(&delnew, r, r);
#if defined(LOG_ALGO)
      printf("[Round %d, Line %d]\n", i, 7);
      printf("delnew: %lf\n", delnew);
#endif
    beta = delnew / delold;
#if defined(LOG_ALGO)
      printf("[Round %d, Line %d]\n", i, 8);
      printf("beta: %lf\n", beta);
#endif
    /* d <= r + beta d */
    ppp_add(y, r, d, beta);
    ppp_copy(d, y);
#if defined(LOG_ALGO)
      printf("[Round %d, Line %d]\n", i, 9);
      printf("d:\n");
      cs_print(d, 0);
#endif
    i++;
  }

  cs_spfree(At);
  cs_spfree(r);
  cs_spfree(d);
  cs_spfree(y);
  cs_spfree(q);

  return i;
}