]> xenbits.xensource.com Git - libvirt.git/commitdiff
LXC add driver config file lxc.conf
authorAmy Griffis <amy.griffis@hp.com>
Thu, 8 Oct 2009 15:40:14 +0000 (17:40 +0200)
committerDaniel Veillard <veillard@redhat.com>
Thu, 8 Oct 2009 15:40:14 +0000 (17:40 +0200)
* src/lxc/lxc.conf: new configuration file, there is currently one
  tunable "log_with_libvirtd" that controls whether an lxc controller will
  log only to the container log file, or whether it will honor libvirtd's
  log output configuration. This provides a way to have libvirtd and its
  children log to a single file.  The default is to log to the container
  log file.
* src/Makefile.am libvirt.spec.in: add the new file
* src/lxc/lxc_conf.[ch] src/lxc/lxc_driver.c: read the new log value
  from the configuration file and pass the log informations when
  starting up a container.

libvirt.spec.in
src/Makefile.am
src/lxc/lxc.conf [new file with mode: 0644]
src/lxc/lxc_conf.c
src/lxc/lxc_conf.h
src/lxc/lxc_driver.c

index ff397e68460e8cad0fd52173e1db8839267be47f..a9a2847997454440d32832e33183dcd4b8ab474b 100644 (file)
@@ -550,6 +550,9 @@ rm -rf $RPM_BUILD_ROOT%{_datadir}/doc/libvirt-%{version}
 %if ! %{with_qemu}
 rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu.conf
 %endif
+%if ! %{with_lxc}
+rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/lxc.conf
+%endif
 
 %if %{with_libvirtd}
 chmod 0644 $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/libvirtd
@@ -630,6 +633,9 @@ fi
 %if %{with_qemu}
 %config(noreplace) %{_sysconfdir}/libvirt/qemu.conf
 %endif
+%if %{with_lxc}
+%config(noreplace) %{_sysconfdir}/libvirt/lxc.conf
+%endif
 
 %dir %{_datadir}/libvirt/
 
index 26ffafffa13ac24d6ce1d6f724931fa952faaf20..ffc6581fe483b9f4cb59dd17067aa0c6730ce04d 100644 (file)
@@ -32,6 +32,8 @@ lib_LTLIBRARIES = libvirt.la
 moddir = $(libdir)/libvirt/drivers
 mod_LTLIBRARIES =
 
+confdir = $(sysconfdir)/libvirt
+conf_DATA =
 
 # These files are not related to driver APIs. Simply generic
 # helper APIs for various purposes
@@ -431,8 +433,7 @@ libvirt_driver_qemu_la_LDFLAGS += -module -avoid-version
 endif
 libvirt_driver_qemu_la_SOURCES = $(QEMU_DRIVER_SOURCES)
 
-confdir = $(sysconfdir)/libvirt/
-conf_DATA = qemu/qemu.conf
+conf_DATA += qemu/qemu.conf
 
 augeasdir = $(datadir)/augeas/lenses
 augeas_DATA = qemu/libvirtd_qemu.aug
@@ -462,7 +463,11 @@ if WITH_DRIVER_MODULES
 libvirt_driver_lxc_la_LDFLAGS = -module -avoid-version
 endif
 libvirt_driver_lxc_la_SOURCES = $(LXC_DRIVER_SOURCES)
+
+conf_DATA += lxc/lxc.conf
+
 endif
+EXTRA_DIST += lxc/lxc.conf
 
 if WITH_UML
 if WITH_DRIVER_MODULES
diff --git a/src/lxc/lxc.conf b/src/lxc/lxc.conf
new file mode 100644 (file)
index 0000000..7a5066f
--- /dev/null
@@ -0,0 +1,13 @@
+# Master configuration file for the LXC driver.
+# All settings described here are optional - if omitted, sensible
+# defaults are used.
+
+# By default, log messages generated by the lxc controller go to the
+# container logfile. It is also possible to accumulate log messages
+# from all lxc controllers along with libvirtd's log outputs. In this
+# case, the lxc controller will honor either LIBVIRT_LOG_OUTPUTS or
+# log_outputs from libvirtd.conf.
+#
+# This is disabled by default, uncomment below to enable it.
+#
+# log_with_libvirtd = 1
index fef60baae7779ea4f830b90bd674bca2e089378e..de059bd8b52da244d33beb06360f03eba38a977b 100644 (file)
@@ -30,6 +30,7 @@
 #include "lxc_conf.h"
 #include "nodeinfo.h"
 #include "virterror_internal.h"
+#include "conf.h"
 #include "logging.h"
 
 
@@ -90,6 +91,10 @@ no_memory:
 
 int lxcLoadDriverConfig(lxc_driver_t *driver)
 {
+    char *filename;
+    virConfPtr conf;
+    virConfValuePtr p;
+
     /* Set the container configuration directory */
     if ((driver->configDir = strdup(LXC_CONFIG_DIR)) == NULL)
         goto no_memory;
@@ -98,6 +103,25 @@ int lxcLoadDriverConfig(lxc_driver_t *driver)
     if ((driver->logDir = strdup(LXC_LOG_DIR)) == NULL)
         goto no_memory;
 
+    if ((filename = strdup(SYSCONF_DIR "/libvirt/lxc.conf")) == NULL)
+        goto no_memory;
+
+    /* Avoid error from non-existant or unreadable file. */
+    if (access (filename, R_OK) == -1)
+        return 0;
+    conf = virConfReadFile(filename, 0);
+    if (!conf)
+        return 0;
+
+    p = virConfGetValue(conf, "log_with_libvirtd");
+    if (p) {
+        if (p->type != VIR_CONF_LONG)
+            VIR_WARN0("lxcLoadDriverConfig: invalid setting: log_with_libvirtd");
+        else
+            driver->log_libvirtd = p->l;
+    }
+
+    virConfFree(conf);
     return 0;
 
 no_memory:
index 15402d8d11cf15812b5781a77812bbf2bd377501..6e4c8553cccbf57784a900e802a3d4ed0e2e7641 100644 (file)
@@ -49,6 +49,7 @@ struct __lxc_driver {
     char *autostartDir;
     char *stateDir;
     char *logDir;
+    int log_libvirtd;
     int have_netns;
 
     /* An array of callbacks */
index ecdd5b7797332c447e4b238deab4a6adaa1bb489..ef0d368092efbe0d3555d50950405ac09db84026 100644 (file)
@@ -949,11 +949,13 @@ static int lxcControllerStart(virConnectPtr conn,
     char *filterstr;
     char *outputstr;
     char *tmp;
+    int log_level;
     pid_t child;
     int status;
     fd_set keepfd;
     char appPtyStr[30];
     const char *emulator;
+    lxc_driver_t *driver = conn->privateData;
 
     FD_ZERO(&keepfd);
 
@@ -1003,7 +1005,8 @@ static int lxcControllerStart(virConnectPtr conn,
         lenv[lenvc++] = envval;                                         \
     } while (0)
 
-    if (virAsprintf(&tmp, "LIBVIRT_DEBUG=%d", virLogGetDefaultPriority()) < 0)
+    log_level = virLogGetDefaultPriority();
+    if (virAsprintf(&tmp, "LIBVIRT_DEBUG=%d", log_level) < 0)
         goto no_memory;
     ADD_ENV(tmp);
 
@@ -1015,12 +1018,18 @@ static int lxcControllerStart(virConnectPtr conn,
         VIR_FREE(filterstr);
     }
 
-    if (virLogGetNbOutputs() > 0) {
-        outputstr = virLogGetOutputs();
-        if (!outputstr)
+    if (driver->log_libvirtd) {
+        if (virLogGetNbOutputs() > 0) {
+            outputstr = virLogGetOutputs();
+            if (!outputstr)
+                goto no_memory;
+            ADD_ENV_PAIR("LIBVIRT_LOG_OUTPUTS", outputstr);
+            VIR_FREE(outputstr);
+        }
+    } else {
+        if (virAsprintf(&tmp, "LIBVIRT_LOG_OUTPUTS=%d:stderr", log_level) < 0)
             goto no_memory;
-        ADD_ENV_PAIR("LIBVIRT_LOG_OUTPUTS", outputstr);
-        VIR_FREE(outputstr);
+        ADD_ENV(tmp);
     }
 
     ADD_ENV(NULL);
@@ -1626,6 +1635,7 @@ static int lxcStartup(int privileged)
          virEventAddTimeout(-1, lxcDomainEventFlush, lxc_driver, NULL)) < 0)
         goto cleanup;
 
+    lxc_driver->log_libvirtd = 0; /* by default log to container logfile */
     lxc_driver->have_netns = lxcCheckNetNsSupport();
 
     rc = virCgroupForDriver("lxc", &lxc_driver->cgroup, privileged, 1);