Re: [PATCH v3 01/11] libvirt: Export libvirt config getters by moving them to util

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 06, 2015 at 12:46:16PM +0100, Erik Skultety wrote:
virConnectGetConfig and virConnectGetConfigPath were static libvirt
methods, merely because there hasn't been any need for having them
internally exported yet. Since libvirt-admin also needs to reference
libvirt config file, 'xGetConfig' should be exported.
Besides moving, this patch also renames the methods accordingly,
as they are libvirt config specific.
---
src/libvirt.c            | 55 +-----------------------------------------------
src/libvirt_private.syms |  1 +
src/util/virconf.c       | 52 +++++++++++++++++++++++++++++++++++++++++++++
src/util/virconf.h       |  1 +
4 files changed, 55 insertions(+), 54 deletions(-)


I agree with Daniel on the different config files.  But that could be
made easy (and it would make sure the path is consistent) if you kept
this function here, but added a parameter (const char *name, for
example) that would be appended with '-' after the "libvirt" string.
That would differentiate between libvirt (name == NULL), admin (name
== "admin") and could be used in the future for any other
configuration files (name == "anything").

I know it's kind of ugly and hacky, but Either ACK with the following
diff squashed in or send another version if you don't agree ;)

If you fancy the former, please adjust the commit message as well.

diff --git i/src/libvirt-admin.c w/src/libvirt-admin.c
index 00f2a5457beb..9f94a50b8fdd 100644
--- i/src/libvirt-admin.c
+++ w/src/libvirt-admin.c
@@ -210,7 +210,7 @@ virAdmConnectOpen(const char *uri, unsigned int flags)
    if (!(conn = virAdmConnectNew()))
        goto error;

-    if (virConfLoadDefault(&conf) < 0)
+    if (virConfLoadDefault(&conf, "admin") < 0)
        goto error;

    if (!uri && !(default_uri = virAdmGetDefaultURI(conf)))
diff --git i/src/libvirt.c w/src/libvirt.c
index 2dd94bfee8fb..731e4adff375 100644
--- i/src/libvirt.c
+++ w/src/libvirt.c
@@ -949,7 +949,7 @@ do_open(const char *name,
    if (ret == NULL)
        return NULL;

-    if (virConfLoadDefault(&conf) < 0)
+    if (virConfLoadDefault(&conf, NULL) < 0)
        goto failed;

    if (name && name[0] == '\0')
diff --git i/src/util/virconf.c w/src/util/virconf.c
index 792e23cd2054..ba8e96715f07 100644
--- i/src/util/virconf.c
+++ w/src/util/virconf.c
@@ -1056,20 +1056,24 @@ virConfWriteMem(char *memory, int *len, virConfPtr conf)
}

static char *
-virConfLoadDefaultPath(void)
+virConfLoadDefaultPath(const char *name)
{
    char *path;
    if (geteuid() == 0) {
-        if (virAsprintf(&path, "%s/libvirt/libvirt.conf",
-                        SYSCONFDIR) < 0)
+        if (virAsprintf(&path, "%s/libvirt/libvirt%s%s.conf",
+                        SYSCONFDIR,
+                        name ? "-" : "",
+                        name ? name : "") < 0)
            return NULL;
    } else {
        char *userdir = virGetUserConfigDirectory();
        if (!userdir)
            return NULL;

-        if (virAsprintf(&path, "%s/libvirt.conf",
-                        userdir) < 0) {
+        if (virAsprintf(&path, "%s/libvirt%s%s.conf",
+                        userdir,
+                        name ? "-" : "",
+                        name ? name : "") < 0) {
            VIR_FREE(userdir);
            return NULL;
        }
@@ -1080,14 +1084,14 @@ virConfLoadDefaultPath(void)
}

int
-virConfLoadDefault(virConfPtr *conf)
+virConfLoadDefault(virConfPtr *conf, const char *name)
{
    char *filename = NULL;
    int ret = -1;

    *conf = NULL;

-    if (!(filename = virConfLoadDefaultPath()))
+    if (!(filename = virConfLoadDefaultPath(name)))
        goto cleanup;

    if (!virFileExists(filename)) {
diff --git i/src/util/virconf.h w/src/util/virconf.h
index 7dab84ded4cb..2e7449f8869d 100644
--- i/src/util/virconf.h
+++ w/src/util/virconf.h
@@ -96,6 +96,7 @@ int virConfWriteFile(const char *filename,
int virConfWriteMem(char *memory,
                    int *len,
                    virConfPtr conf);
-int virConfLoadDefault(virConfPtr *conf);
+int virConfLoadDefault(virConfPtr *conf,
+                       const char *name);

#endif /* __VIR_CONF_H__ */
--

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]