static int lxcSetMemTune(virDomainDefPtr def, virConfPtr properties) { virConfValuePtr value; unsigned long long size = 0; if ((value = virConfGetValue(properties, "lxc.cgroup.memory.limit_in_bytes")) && value->str && STRNEQ(value->str, "-1")) { if (lxcConvertSize(value->str, &size) < 0) return -1; size = size / 1024; virDomainDefSetMemoryTotal(def, size); def->mem.hard_limit = virMemoryLimitTruncate(size); } if ((value = virConfGetValue(properties, "lxc.cgroup.memory.soft_limit_in_bytes")) && value->str && STRNEQ(value->str, "-1")) { if (lxcConvertSize(value->str, &size) < 0) return -1; def->mem.soft_limit = virMemoryLimitTruncate(size / 1024); } if ((value = virConfGetValue(properties, "lxc.cgroup.memory.memsw.limit_in_bytes")) && value->str && STRNEQ(value->str, "-1")) { if (lxcConvertSize(value->str, &size) < 0) return -1; def->mem.swap_hard_limit = virMemoryLimitTruncate(size / 1024); } return 0; }
static int lxcSetMemTune(virDomainDefPtr def, virConfPtr properties) { VIR_AUTOFREE(char *) value = NULL; unsigned long long size = 0; if (virConfGetValueString(properties, "lxc.cgroup.memory.limit_in_bytes", &value) > 0) { if (lxcConvertSize(value, &size) < 0) return -1; size = size / 1024; virDomainDefSetMemoryTotal(def, size); def->mem.hard_limit = virMemoryLimitTruncate(size); VIR_FREE(value); } if (virConfGetValueString(properties, "lxc.cgroup.memory.soft_limit_in_bytes", &value) > 0) { if (lxcConvertSize(value, &size) < 0) return -1; def->mem.soft_limit = virMemoryLimitTruncate(size / 1024); VIR_FREE(value); } if (virConfGetValueString(properties, "lxc.cgroup.memory.memsw.limit_in_bytes", &value) > 0) { if (lxcConvertSize(value, &size) < 0) return -1; def->mem.swap_hard_limit = virMemoryLimitTruncate(size / 1024); } return 0; }
static int lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab) { const char *src = NULL; char *dst = NULL; char **options = virStringSplit(fstab->options, ",", 0); bool readonly; int type = VIR_DOMAIN_FS_TYPE_MOUNT; unsigned long long usage = 0; int ret = -1; if (!options) return -1; if (fstab->dst[0] != '/') { if (virAsprintf(&dst, "/%s", fstab->dst) < 0) goto cleanup; } else { if (VIR_STRDUP(dst, fstab->dst) < 0) goto cleanup; } /* Check that we don't add basic mounts */ if (lxcIsBasicMountLocation(dst)) { ret = 0; goto cleanup; } if (STREQ(fstab->type, "tmpfs")) { char *sizeStr = NULL; size_t i; type = VIR_DOMAIN_FS_TYPE_RAM; for (i = 0; options[i]; i++) { if ((sizeStr = STRSKIP(options[i], "size="))) { if (lxcConvertSize(sizeStr, &usage) < 0) goto cleanup; break; } } if (!sizeStr) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing tmpfs size, set the size option")); goto cleanup; } } else { src = fstab->src; } /* Is it a block device that needs special favor? */ if (STRPREFIX(fstab->src, "/dev/")) type = VIR_DOMAIN_FS_TYPE_BLOCK; /* Do we have ro in options? */ readonly = virStringArrayHasString(options, "ro"); if (lxcAddFSDef(def, type, src, dst, readonly, usage) < 0) goto cleanup; ret = 1; cleanup: VIR_FREE(dst); virStringFreeList(options); return ret; }