Last active
August 29, 2015 14:05
-
-
Save rcleere/c162c801cc998d18883d to your computer and use it in GitHub Desktop.
Libvirt 1.2.3 patch to add <rlimit_nofile> to XML and apply to LXC on boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c | |
index 6fb216e..f1a5722 100644 | |
--- a/src/conf/domain_conf.c | |
+++ b/src/conf/domain_conf.c | |
@@ -12966,6 +12966,23 @@ virDomainDefParseXML(xmlDocPtr xml, | |
VIR_FREE(tmp); | |
} | |
+ /* Extract rlimit_nofiles */ | |
+ n = virXPathULong("string(./rlimit_nofile[1])", ctxt, &count); | |
+ if (n == -2) { | |
+ virReportError(VIR_ERR_XML_ERROR, "%s", | |
+ _("maximum nofiles must be an integer")); | |
+ goto error; | |
+ } else if (n < 0) { | |
+ def->rlimit_nofile = 0; | |
+ } else { | |
+ def->rlimit_nofile = count; | |
+ if (count <= 0) { | |
+ virReportError(VIR_ERR_XML_ERROR, | |
+ _("rlimit_nofile must be greater than 0 '%lu'"), count); | |
+ goto error; | |
+ } | |
+ } | |
+ | |
/* Extract custom metadata */ | |
if ((node = virXPathNode("./metadata[1]", ctxt)) != NULL) | |
def->metadata = xmlCopyNode(node, 1); | |
@@ -17851,6 +17868,10 @@ virDomainDefFormatInternal(virDomainDefPtr def, | |
goto error; | |
} | |
+ if (def->rlimit_nofile) | |
+ virBufferAsprintf(buf, "<rlimit_nofile>%lu</rlimit_nofile>\n", | |
+ def->rlimit_nofile); | |
+ | |
virBufferAdjustIndent(buf, -2); | |
virBufferAddLit(buf, "</domain>\n"); | |
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h | |
index f3f24c4..a35d335 100644 | |
--- a/src/conf/domain_conf.h | |
+++ b/src/conf/domain_conf.h | |
@@ -2047,6 +2047,8 @@ struct _virDomainDef { | |
int hyperv_features[VIR_DOMAIN_HYPERV_LAST]; | |
unsigned int hyperv_spinlocks; | |
+ unsigned long rlimit_nofile; | |
+ | |
virDomainClockDef clock; | |
size_t ngraphics; | |
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c | |
index 3bc15cc..1ec3b5f 100644 | |
--- a/src/lxc/lxc_controller.c | |
+++ b/src/lxc/lxc_controller.c | |
@@ -2478,6 +2478,9 @@ int main(int argc, char *argv[]) | |
} | |
} | |
+ if (ctrl->def->rlimit_nofile > 0) | |
+ if (virProcessSetMaxFiles(0, ctrl->def->rlimit_nofile) < 0) | |
+ goto cleanup; | |
rc = virLXCControllerRun(ctrl); | |
cleanup: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment