virDomainResctrlNew(xmlNodePtr node,
                    virResctrlAllocPtr alloc,
                    virBitmapPtr vcpus,
                    unsigned int flags)
{
    virDomainResctrlDefPtr resctrl = NULL;
    virDomainResctrlDefPtr ret = NULL;
    g_autofree char *vcpus_str = NULL;
    g_autofree char *alloc_id = NULL;

    /* We need to format it back because we need to be consistent in the naming
     * even when users specify some "sub-optimal" string there. */
    vcpus_str = virBitmapFormat(vcpus);
    if (!vcpus_str)
        return NULL;

    if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
        alloc_id = virXMLPropString(node, "id");

    if (!alloc_id) {
        /* The number of allocations is limited and the directory structure is flat,
         * not hierarchical, so we need to have all same allocations in one
         * directory, so it's nice to have it named appropriately.  For now it's
         * 'vcpus_...' but it's designed in order for it to be changeable in the
         * future (it's part of the status XML). */
        alloc_id = g_strdup_printf("vcpus_%s", vcpus_str);
    }

    if (virResctrlAllocSetID(alloc, alloc_id) < 0)
        goto cleanup;

    if (VIR_ALLOC(resctrl) < 0)
        goto cleanup;

    if (!(resctrl->vcpus = virBitmapNewCopy(vcpus))) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("failed to copy 'vcpus'"));
        goto cleanup;
    }

    resctrl->alloc = virObjectRef(alloc);

    ret = g_steal_pointer(&resctrl);
 cleanup:
    virDomainResctrlDefFree(resctrl);
    return ret;
}
virDomainResctrlNew(xmlNodePtr node,
                    virResctrlAllocPtr alloc,
                    virBitmapPtr vcpus,
                    unsigned int flags)
{
    virDomainResctrlDefPtr resctrl = NULL;
    virDomainResctrlDefPtr ret = NULL;
    g_autofree char *vcpus_str = NULL;
    g_autofree char *alloc_id = NULL;

     
    vcpus_str = virBitmapFormat(vcpus);
    if (!vcpus_str)
        return NULL;

    if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
        alloc_id = virXMLPropString(node, "id");

    if (!alloc_id) {
         
        alloc_id = g_strdup_printf("vcpus_%s", vcpus_str);
    }

    if (virResctrlAllocSetID(alloc, alloc_id) < 0)
        goto cleanup;

    if (VIR_ALLOC(resctrl) < 0)
        goto cleanup;

    if (!(resctrl->vcpus = virBitmapNewCopy(vcpus))) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("failed to copy 'vcpus'"));
        goto cleanup;
    }

    resctrl->alloc = virObjectRef(alloc);

    ret = g_steal_pointer(&resctrl);
 cleanup:
    virDomainResctrlDefFree(resctrl);
    return ret;
}