From: Chen Hanxiao <chenhanxiao@xxxxxxxxxxxxxx> This patch enables percentage limit for ram filesystem <filesystem type='ram'> <source usage='10%'/> <target dir='/mnt'/> </filesystem> Percentage limit would have more priority than size limit. Signed-off-by: Chen Hanxiao <chenhanxiao@xxxxxxxxxxxxxx> --- src/conf/domain_conf.c | 21 +++++++++++++++++---- src/conf/domain_conf.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d3f1ca2..25cfde2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6068,19 +6068,27 @@ virDomainFSDefParseXML(xmlNodePtr node, } if (def->type == VIR_DOMAIN_FS_TYPE_RAM) { + int len; if (!usage) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing 'usage' attribute for RAM filesystem")); goto error; } + len = strlen(usage); + if ('%' == usage[len - 1]) { + VIR_DEBUG("usage is %s\n", usage); + *(usage + len - 1) = '\0'; + def->usage_percentage = true; + } + if (virStrToLong_ull(usage, NULL, 10, &def->usage) < 0) { virReportError(VIR_ERR_XML_ERROR, _("cannot parse usage '%s' for RAM filesystem"), usage); goto error; } - if (virScaleInteger(&def->usage, units, - 1024, ULLONG_MAX) < 0) + if (!(def->usage_percentage) && + virScaleInteger(&def->usage, units, 1024, ULLONG_MAX) < 0) goto error; } @@ -14866,8 +14874,13 @@ virDomainFSDefFormat(virBufferPtr buf, break; case VIR_DOMAIN_FS_TYPE_RAM: - virBufferAsprintf(buf, " <source usage='%lld' units='KiB'/>\n", - def->usage / 1024); + if (def->usage_percentage) { + virBufferAsprintf(buf, " <source usage='%lld%%'/>\n", + def->usage); + } else { + virBufferAsprintf(buf, " <source usage='%lld' units='KiB'/>\n", + def->usage / 1024); + } break; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4561ccc..abfa756 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -891,6 +891,7 @@ struct _virDomainFSDef { int wrpolicy; /* enum virDomainFSWrpolicy */ int format; /* enum virStorageFileFormat */ unsigned long long usage; /* in bytes */ + bool usage_percentage; /* flag for percentage limit */ char *src; char *dst; bool readonly; -- 1.8.2.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list