static int virXPathULongBase(const char *xpath, xmlXPathContextPtr ctxt, int base, unsigned long *value) { xmlXPathObjectPtr obj; xmlNodePtr relnode; int ret = 0; if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid parameter to virXPathULong()")); return -1; } relnode = ctxt->node; obj = xmlXPathEval(BAD_CAST xpath, ctxt); ctxt->node = relnode; if ((obj != NULL) && (obj->type == XPATH_STRING) && (obj->stringval != NULL) && (obj->stringval[0] != 0)) { if (virStrToLong_ul((char *) obj->stringval, NULL, base, value) < 0) ret = -2; } else if ((obj != NULL) && (obj->type == XPATH_NUMBER) && (!(isnan(obj->floatval)))) { *value = (unsigned long) obj->floatval; if (*value != obj->floatval) { ret = -2; } } else { ret = -1; } xmlXPathFreeObject(obj); return ret; }
static int virNetDevBridgeGet(const char *brname, const char *paramname, /* sysfs param name */ unsigned long *value, /* current value */ int fd, /* control socket */ struct ifreq *ifr) /* pre-filled bridge name */ { char *path = NULL; int ret = -1; if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname) < 0) return -1; if (virFileExists(path)) { char *valuestr; if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0) goto cleanup; if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) { virReportSystemError(EINVAL, _("Unable to get bridge %s %s"), brname, paramname); VIR_FREE(valuestr); goto cleanup; } VIR_FREE(valuestr); } else {
static int virNetDevBridgeGet(const char *brname, const char *paramname, /* sysfs param name */ unsigned long *value) /* current value */ { struct ifreq ifr; VIR_AUTOFREE(char *) path = NULL; VIR_AUTOCLOSE fd = -1; if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname) < 0) return -1; if (virFileExists(path)) { VIR_AUTOFREE(char *) valuestr = NULL; if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0) return -1; if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) { virReportSystemError(EINVAL, _("Unable to get bridge %s %s"), brname, paramname); return -1; } } else {
static int lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties) { virConfValuePtr value; if ((value = virConfGetValue(properties, "lxc.cgroup.cpu.shares")) && value->str) { if (virStrToLong_ul(value->str, NULL, 10, &def->cputune.shares) < 0) goto error; def->cputune.sharesSpecified = true; } if ((value = virConfGetValue(properties, "lxc.cgroup.cpu.cfs_quota_us")) && value->str && virStrToLong_ll(value->str, NULL, 10, &def->cputune.quota) < 0) goto error; if ((value = virConfGetValue(properties, "lxc.cgroup.cpu.cfs_period_us")) && value->str && virStrToLong_ull(value->str, NULL, 10, &def->cputune.period) < 0) goto error; return 0; error: virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse integer: '%s'"), value->str); return -1; }
/* * This function is adapted from vm_parse_memsize in * /lib/libvmmapi/vmmapi.c in the FreeBSD Source tree. */ static int bhyveParseMemsize(const char *arg, size_t *ret_memsize) { size_t val; int error; if (virStrToLong_ul(arg, NULL, 10, &val) == 0) { /* * For the sake of backward compatibility if the memory size * specified on the command line is less than a megabyte then * it is interpreted as being in units of MB. */ if (val < 1024 * 1024UL) val *= 1024 * 1024UL; *ret_memsize = val; error = 0; } else { error = expand_number(arg, ret_memsize); } /* use memory in KiB here */ *ret_memsize /= 1024UL; return error; }