Example #1
0
static int
lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties)
{
    virConfValuePtr value;
    virBitmapPtr nodeset = NULL;

    if ((value = virConfGetValue(properties, "lxc.cgroup.cpuset.cpus")) &&
            value->str) {
        if (virBitmapParse(value->str, 0, &def->cpumask,
                           VIR_DOMAIN_CPUMASK_LEN) < 0)
            return -1;

        def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC;
    }

    if ((value = virConfGetValue(properties, "lxc.cgroup.cpuset.mems")) &&
        value->str) {
        if (virBitmapParse(value->str, 0, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
            return -1;
        if (virDomainNumatuneSet(def->numa,
                                 def->placement_mode ==
                                 VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC,
                                 VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC,
                                 VIR_DOMAIN_NUMATUNE_MEM_STRICT,
                                 nodeset) < 0) {
            virBitmapFree(nodeset);
            return -1;
        }
        virBitmapFree(nodeset);
    }

    return 0;
}
Example #2
0
static int
lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties)
{
    VIR_AUTOFREE(char *) value = NULL;
    virBitmapPtr nodeset = NULL;

    if (virConfGetValueString(properties, "lxc.cgroup.cpuset.cpus",
                              &value) > 0) {
        if (virBitmapParse(value, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
            return -1;
        def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC;
        VIR_FREE(value);
    }

    if (virConfGetValueString(properties, "lxc.cgroup.cpuset.mems",
                              &value) > 0) {
        if (virBitmapParse(value, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
            return -1;
        if (virDomainNumatuneSet(def->numa,
                                 def->placement_mode ==
                                 VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC,
                                 VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC,
                                 VIR_DOMAIN_NUMATUNE_MEM_STRICT,
                                 nodeset) < 0) {
            virBitmapFree(nodeset);
            return -1;
        }
        virBitmapFree(nodeset);
    }

    return 0;
}
Example #3
0
int
virDomainNumatuneParseXML(virDomainNumaPtr numa,
                          bool placement_static,
                          xmlXPathContextPtr ctxt)
{
    char *tmp = NULL;
    int mode = -1;
    int n = 0;
    int placement = -1;
    int ret = -1;
    virBitmapPtr nodeset = NULL;
    xmlNodePtr node = NULL;

    if (virXPathInt("count(./numatune)", ctxt, &n) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("cannot extract numatune nodes"));
        goto cleanup;
    } else if (n > 1) {
        virReportError(VIR_ERR_XML_ERROR, "%s",
                       _("only one numatune is supported"));
        goto cleanup;
    }

    node = virXPathNode("./numatune/memory[1]", ctxt);

    if (!placement_static && !node)
        placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO;

    if (node) {
        if ((tmp = virXMLPropString(node, "mode")) &&
            (mode = virDomainNumatuneMemModeTypeFromString(tmp)) < 0) {
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                           _("Unsupported NUMA memory tuning mode '%s'"), tmp);
            goto cleanup;
        }
        VIR_FREE(tmp);

        if ((tmp = virXMLPropString(node, "placement")) &&
            (placement = virDomainNumatunePlacementTypeFromString(tmp)) < 0) {
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                           _("Unsupported NUMA memory placement mode '%s'"), tmp);
            goto cleanup;
        }
        VIR_FREE(tmp);

        tmp = virXMLPropString(node, "nodeset");
        if (tmp) {
            if (virBitmapParse(tmp, 0, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
                goto cleanup;

            if (virBitmapIsAllClear(nodeset)) {
                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                               _("Invalid value of 'nodeset': %s"), tmp);
                goto cleanup;
            }

            VIR_FREE(tmp);
        }
    }

    if (virDomainNumatuneSet(numa,
                             placement_static,
                             placement,
                             mode,
                             nodeset) < 0)
        goto cleanup;

    if (virDomainNumatuneNodeParseXML(numa, ctxt) < 0)
        goto cleanup;

    ret = 0;
 cleanup:
    virBitmapFree(nodeset);
    VIR_FREE(tmp);
    return ret;
}
int
virDomainNumatuneParseXML(virDomainNumatunePtr *numatunePtr,
                          bool placement_static,
                          size_t ncells,
                          xmlXPathContextPtr ctxt)
{
    char *tmp = NULL;
    int mode = -1;
    int n = 0;
    int placement = -1;
    int ret = -1;
    virBitmapPtr nodeset = NULL;
    xmlNodePtr node = NULL;

    if (virXPathInt("count(./numatune)", ctxt, &n) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("cannot extract numatune nodes"));
        goto cleanup;
    } else if (n > 1) {
        virReportError(VIR_ERR_XML_ERROR, "%s",
                       _("only one numatune is supported"));
        goto cleanup;
    }

    node = virXPathNode("./numatune/memory[1]", ctxt);

    if (*numatunePtr) {
        virDomainNumatuneFree(*numatunePtr);
        *numatunePtr = NULL;
    }

    if (!node && placement_static) {
        if (virDomainNumatuneNodeParseXML(numatunePtr, ncells, ctxt) < 0)
            goto cleanup;
        return 0;
    }

    if (!node) {
        /* We know that placement_mode is "auto" if we're here */
        ret = virDomainNumatuneSet(numatunePtr,
                                   placement_static,
                                   VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO,
                                   -1,
                                   NULL);
        goto cleanup;
    }

    tmp = virXMLPropString(node, "mode");
    if (tmp) {
        mode = virDomainNumatuneMemModeTypeFromString(tmp);
        if (mode < 0) {
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                           _("Unsupported NUMA memory tuning mode '%s'"),
                           tmp);
            goto cleanup;
        }
    }
    VIR_FREE(tmp);

    tmp = virXMLPropString(node, "placement");
    if (tmp) {
        placement = virDomainNumatunePlacementTypeFromString(tmp);
        if (placement < 0) {
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                           _("Unsupported NUMA memory placement mode '%s'"),
                           tmp);
            goto cleanup;
        }
    }
    VIR_FREE(tmp);

    tmp = virXMLPropString(node, "nodeset");
    if (tmp && virBitmapParse(tmp, 0, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
        goto cleanup;
    VIR_FREE(tmp);

    if (virDomainNumatuneSet(numatunePtr,
                             placement_static,
                             placement,
                             mode,
                             nodeset) < 0)
        goto cleanup;

    if (virDomainNumatuneNodeParseXML(numatunePtr, ncells, ctxt) < 0)
        goto cleanup;

    ret = 0;
 cleanup:
    virBitmapFree(nodeset);
    VIR_FREE(tmp);
    return ret;
}
Example #5
0
int lxctoolsReadConfig(struct lxc_container* cont, virDomainDefPtr def)
{
    char* item_str = NULL;
    virNodeInfoPtr nodeinfo = NULL;
    lxctoolsConffilePtr conffile = NULL;

    if (VIR_ALLOC(nodeinfo) < 0) {
        goto error;
    }
    
    if (virCapabilitiesGetNodeInfo(nodeinfo) < 0) {
        goto error;
    }
    
    if (VIR_ALLOC(conffile) < 0)
        goto error;

    if (lxctoolsConffileRead(conffile, cont->config_file_name(cont)) < 0) {
        virReportError(VIR_ERR_OPERATION_FAILED, "'%s'", _("failed to read conffile"));
        goto error;
    }
    if ((item_str = lxctoolsConffileGetItem(conffile, "lxc.arch")) == NULL) {
        goto error;
    }
    if (item_str[0] != '\0') {
        if (strcmp(item_str, "x86") == 0 || strcmp(item_str, "i686")  == 0) {
            def->os.arch = VIR_ARCH_I686;
        }
        else if (strcmp(item_str, "x86_64") == 0 || strcmp(item_str, "amd64") == 0) {
            def->os.arch = VIR_ARCH_X86_64;
        } else {
            virReportError(VIR_ERR_OPERATION_FAILED, "Unknown architecture '%s'.", item_str);
            goto error;
        }
    }
    VIR_FREE(item_str);
    item_str = NULL;

    if ((item_str = lxctoolsConffileGetItem(conffile, "lxc.cgroup.cpuset.cpus")) == NULL){
        goto error;
    }
    if (item_str[0] == '\0') {
        if (virDomainDefSetVcpusMax(def, nodeinfo->cpus, NULL) < 0)
            goto error;
        def->cpumask = virBitmapNew(nodeinfo->cpus);
        virBitmapSetAll(def->cpumask);
    } else {
        int cpunum;
        if ( (cpunum = virBitmapParse(item_str, &def->cpumask, nodeinfo->cpus) ) < 0) {
            goto error;
        }  
        if (virDomainDefSetVcpusMax(def, cpunum, NULL) < 0)
            goto error;
    }

    if (virDomainDefSetVcpus(def, virDomainDefGetVcpusMax(def)) < 0)
        goto error;
   
    VIR_FREE(item_str);
    item_str = NULL;

    if ((item_str = lxctoolsConffileGetItem(conffile, "lxc.cgroup.cpu.shares")) == NULL) {
        goto error;
    }
    if (item_str[0] != '\0') {
        unsigned long shares;
        sscanf(item_str, "%lu", &shares);
        def->cputune.shares = shares;
        def->cputune.sharesSpecified = true;
    }

    VIR_FREE(item_str);
    item_str = NULL;

    if ((item_str = lxctoolsConffileGetItem(conffile, "lxc.cgroup.cpu.cfs_period_us")) == NULL) {
        goto error;
    }
    if (item_str[0] != '\0') {
        unsigned long long period;
        sscanf(item_str, "%llu", &period);
        def->cputune.period = period;
    }

    VIR_FREE(item_str);
    item_str = NULL;

    if ((item_str = lxctoolsConffileGetItem(conffile, "lxc.cgroup.cpu.cfs_quota_us")) == NULL) {
        goto error;
    }
    if (item_str[0] != '\0') {
        long long quota;
        sscanf(item_str, "%llu", &quota);
        def->cputune.quota = quota;
    }

    VIR_FREE(item_str);
    item_str = NULL;


    if ((item_str = lxctoolsConffileGetItem(conffile, "lxc.cgroup.memory.limit_in_bytes")) == NULL) {
        goto error;
    }
    if (item_str[0] == '\0') {
        virDomainDefSetMemoryTotal(def, nodeinfo->memory);
    } else {
        virDomainDefSetMemoryTotal(def, memToULL(item_str)); 
    }


    def->mem.cur_balloon = virDomainDefGetMemoryTotal(def);
//    def->mem.max_memory = nodeinfo->memory;
//    def->mem.memory_slots = 1; //maybe delete max_memory alltogether

    VIR_FREE(item_str);
    item_str = NULL;
    if ((item_str = lxctoolsConffileGetItem(conffile, "lxc.cgroup.memory.soft_limit_in_bytes")) == NULL) {
        goto error;
    }
    if (item_str[0] != '\0') {
        def->mem.soft_limit = memToULL(item_str);
    }

    VIR_FREE(item_str);
    item_str = NULL;

    if ((item_str = lxctoolsConffileGetItem(conffile, "lxc.cgroup.cpuset.mems")) == NULL) {
        goto error;
    }
    if (item_str[0] != '\0') {
        virBitmapPtr nodeset;
        if (virBitmapParse(item_str, &nodeset, nodeinfo->nodes) < 0) {
            goto error;
        }  
        if (virDomainNumatuneSet(def->numa,
                             true,
                             VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT,
                             VIR_DOMAIN_NUMATUNE_MEM_STRICT,
                             nodeset) < 0 ) {
            goto error;
        }
    }

    VIR_FREE(item_str);
    item_str = NULL;

    if ((item_str = lxctoolsConffileGetItem(conffile, "lxc.include")) == NULL) {
        goto error;
    }

    //lxc.include is optional!
    if (item_str[0] != '\0') {
        def->metadata = xmlNewNode(NULL, (const xmlChar*) "metadata");
        xmlNewTextChild(def->metadata, NULL, (const xmlChar*) (const xmlChar*)"lxctools:include", (const xmlChar*)item_str);
    }

    VIR_FREE(item_str);
    item_str = NULL;
    if (lxctoolsReadFSConfig(conffile, def) < 0)
        goto error;

    if (lxctoolsReadNetConfig(cont, def) < 0)
        goto error;

    return 0;
 error:
    VIR_FREE(item_str);
    VIR_FREE(nodeinfo);
    return -1;
}