]> xenbits.xensource.com Git - libvirt.git/commitdiff
Rename virDomainGetRootFilesystem to virDomainGetFilesystemForTarget
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 12 Nov 2013 11:57:56 +0000 (11:57 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 20 Feb 2014 15:50:46 +0000 (15:50 +0000)
The virDomainGetRootFilesystem method can be generalized to allow
any filesystem path to be obtained.

While doing this, start a new test case for purpose of testing various
helper methods in the domain_conf.{c,h} files, such as this one.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
.gitignore
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/lxc/lxc_container.c
src/lxc/lxc_process.c
tests/Makefile.am
tests/domainconfdata/getfilesystem.xml [new file with mode: 0644]
tests/domainconftest.c [new file with mode: 0644]
tests/testutils.c
tests/testutils.h

index 1c1548992ec2fa41c27f1727856de069d694ba4f..69c81dfd1e5c49a5a733d45ff3b75e92f38e591d 100644 (file)
 /tests/commandtest
 /tests/conftest
 /tests/cputest
+/tests/domainconftest
 /tests/domainsnapshotxml2xmltest
 /tests/esxutilstest
 /tests/eventtest
index 0a249e4bc9e04aa3ffd20d43fcdf6bcadc391e19..064a40e366cdb8102ab76aaaff54581538c72fbb 100644 (file)
@@ -18083,12 +18083,13 @@ virDomainFSRemove(virDomainDefPtr def, size_t i)
 }
 
 virDomainFSDefPtr
-virDomainGetRootFilesystem(virDomainDefPtr def)
+virDomainGetFilesystemForTarget(virDomainDefPtr def,
+                                const char *path)
 {
     size_t i;
 
     for (i = 0; i < def->nfss; i++) {
-        if (STREQ(def->fss[i]->dst, "/"))
+        if (STREQ(def->fss[i]->dst, path))
             return def->fss[i];
     }
 
index b961425c1b5f7d288692935f784faa3c7153dec9..97d6337ba8203fb5deacf0c55995e2c034b8bebc 100644 (file)
@@ -2563,7 +2563,8 @@ int virDiskNameToBusDeviceIndex(virDomainDiskDefPtr disk,
                                 int *busIdx,
                                 int *devIdx);
 
-virDomainFSDefPtr virDomainGetRootFilesystem(virDomainDefPtr def);
+virDomainFSDefPtr virDomainGetFilesystemForTarget(virDomainDefPtr def,
+                                                  const char *path);
 int virDomainFSInsert(virDomainDefPtr def, virDomainFSDefPtr fs);
 int virDomainFSIndexByName(virDomainDefPtr def, const char *name);
 virDomainFSDefPtr virDomainFSRemove(virDomainDefPtr def, size_t i);
index 341d2e06395bd589a21c80456a966ff707b3766c..08962876e49a4712da223972cdde9e6a04e1b3c3 100644 (file)
@@ -229,7 +229,7 @@ virDomainFSTypeFromString;
 virDomainFSTypeToString;
 virDomainFSWrpolicyTypeFromString;
 virDomainFSWrpolicyTypeToString;
-virDomainGetRootFilesystem;
+virDomainGetFilesystemForTarget;
 virDomainGraphicsAuthConnectedTypeFromString;
 virDomainGraphicsAuthConnectedTypeToString;
 virDomainGraphicsDefFree;
index f08dbc2b1cef8668b70fa913b032224f97c37535..71548043eb04f9ef454bacce52c8ed3c355cb185 100644 (file)
@@ -1823,7 +1823,7 @@ static int lxcContainerChild(void *data)
     if (lxcContainerSetID(vmDef) < 0)
         goto cleanup;
 
-    root = virDomainGetRootFilesystem(vmDef);
+    root = virDomainGetFilesystemForTarget(vmDef, "/");
 
     if (argv->nttyPaths) {
         const char *tty = argv->ttyPaths[0];
index ac7ed39c56a9b4701a321f9ef055d7986bbe20fb..1ebad9c22eed5891d6f20aa48623146d596f8c83 100644 (file)
@@ -957,7 +957,7 @@ virLXCProcessReadLogOutput(virDomainObjPtr vm,
 static int
 virLXCProcessEnsureRootFS(virDomainObjPtr vm)
 {
-    virDomainFSDefPtr root = virDomainGetRootFilesystem(vm->def);
+    virDomainFSDefPtr root = virDomainGetFilesystemForTarget(vm->def, "/");
 
     if (root)
         return 0;
index 0c72cc2489061769c9ef3503873b4d069a3bb181..91eeeac6b57c7a292081ee89d9b8953da4d2e89b 100644 (file)
@@ -65,6 +65,7 @@ EXTRA_DIST =          \
        commanddata \
        confdata \
        cputestdata \
+       domainconfdata \
        domainschemadata \
        domainschematest \
        domainsnapshotschematest \
@@ -147,6 +148,7 @@ test_programs = virshtest sockettest \
        virnetdevbandwidthtest \
        virkmodtest \
        vircapstest \
+       domainconftest \
        $(NULL)
 
 if WITH_REMOTE
@@ -939,6 +941,10 @@ sysinfotest_SOURCES = \
        sysinfotest.c testutils.h testutils.c
 sysinfotest_LDADD = $(LDADDS)
 
+domainconftest_SOURCES = \
+       domainconftest.c testutils.h testutils.c
+domainconftest_LDADD = $(LDADDS)
+
 fdstreamtest_SOURCES = \
        fdstreamtest.c testutils.h testutils.c
 fdstreamtest_LDADD = $(LDADDS)
diff --git a/tests/domainconfdata/getfilesystem.xml b/tests/domainconfdata/getfilesystem.xml
new file mode 100644 (file)
index 0000000..2ee78b4
--- /dev/null
@@ -0,0 +1,28 @@
+<domain type='test'>
+  <name>demo</name>
+  <uuid>8369f1ac-7e46-e869-4ca5-759d51478066</uuid>
+  <memory unit='KiB'>500000</memory>
+  <currentMemory unit='KiB'>500000</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64'>hvm</type>
+    <init>/bin/sh</init>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/'/>
+      <target dir='/'/>
+    </filesystem>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/'/>
+      <target dir='/dev'/>
+    </filesystem>
+    <console type='pty'>
+      <target type='lxc' port='0'/>
+    </console>
+  </devices>
+</domain>
diff --git a/tests/domainconftest.c b/tests/domainconftest.c
new file mode 100644 (file)
index 0000000..d38ef5c
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Daniel P. Berrange <berrange@redhat.com>
+ */
+
+#include <config.h>
+
+#include "testutils.h"
+#include "virerror.h"
+#include "viralloc.h"
+#include "virlog.h"
+
+#include "domain_conf.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static virCapsPtr caps;
+static virDomainXMLOptionPtr xmlopt;
+
+struct testGetFilesystemData {
+    const char *filename;
+    const char *path;
+    bool expectEntry;
+};
+
+static int testGetFilesystem(const void *opaque)
+{
+    int ret = -1;
+    char *xmlData = NULL;
+    virDomainDefPtr def = NULL;
+    char *filename = NULL;
+    const struct testGetFilesystemData *data = opaque;
+    virDomainFSDefPtr fsdef;
+
+    if (virAsprintf(&filename, "%s/domainconfdata/%s.xml",
+                    abs_srcdir, data->filename) < 0)
+        goto cleanup;
+
+    if (virtTestLoadFile(filename, &xmlData) < 0)
+        goto cleanup;
+
+    if (!(def = virDomainDefParseString(xmlData, caps, xmlopt,
+                                        1 << VIR_DOMAIN_VIRT_TEST, 0)))
+        goto cleanup;
+
+    fsdef = virDomainGetFilesystemForTarget(def,
+                                            data->path);
+    if (!fsdef) {
+        if (data->expectEntry) {
+            fprintf(stderr, "Expected FS for path '%s' in '%s'\n",
+                    data->path, filename);
+            goto cleanup;
+        }
+    } else {
+        if (!data->expectEntry) {
+            fprintf(stderr, "Unexpected FS for path '%s' in '%s'\n",
+                    data->path, filename);
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+cleanup:
+    virDomainDefFree(def);
+    VIR_FREE(xmlData);
+    VIR_FREE(filename);
+    return ret;
+}
+
+static int
+mymain(void)
+{
+    int ret = 0;
+
+    if ((caps = virTestGenericCapsInit()) == NULL)
+        goto cleanup;
+
+    if (!(xmlopt = virTestGenericDomainXMLConfInit()))
+        goto cleanup;
+
+#define DO_TEST_GET_FS(fspath, expect)                                  \
+    do {                                                                \
+        struct testGetFilesystemData data = {                           \
+            .filename = "getfilesystem",                                \
+            .path = fspath,                                             \
+            .expectEntry = expect,                                      \
+        };                                                              \
+        if (virtTestRun("Get FS " fspath, testGetFilesystem, &data) < 0) \
+            ret = -1;                                                   \
+    } while (0)
+
+    DO_TEST_GET_FS("/", true);
+    DO_TEST_GET_FS("/dev", true);
+    DO_TEST_GET_FS("/dev/pts", false);
+    DO_TEST_GET_FS("/doesnotexist", false);
+
+    virObjectUnref(caps);
+    virObjectUnref(xmlopt);
+
+ cleanup:
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
index 3f42b13270e5ab394e0d22e46e44ef1f7ce8b748..97d5b50cdc499c6f1dba2b4bea61b7ba8b24b5ec 100644 (file)
@@ -834,3 +834,60 @@ int virtTestClearLineRegex(const char *pattern,
 
     return 0;
 }
+
+
+virCapsPtr virTestGenericCapsInit(void)
+{
+    virCapsPtr caps;
+    virCapsGuestPtr guest;
+
+    if ((caps = virCapabilitiesNew(VIR_ARCH_X86_64,
+                                   0, 0)) == NULL)
+        return NULL;
+
+    if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_I686,
+                                         "/usr/bin/acme-virt", NULL,
+                                         0, NULL)) == NULL)
+        goto error;
+
+    if (!virCapabilitiesAddGuestDomain(guest, "test", NULL, NULL, 0, NULL))
+        goto error;
+
+
+    if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_X86_64,
+                                         "/usr/bin/acme-virt", NULL,
+                                         0, NULL)) == NULL)
+        goto error;
+
+    if (!virCapabilitiesAddGuestDomain(guest, "test", NULL, NULL, 0, NULL))
+        goto error;
+
+
+    if (virTestGetDebug()) {
+        char *caps_str;
+
+        caps_str = virCapabilitiesFormatXML(caps);
+        if (!caps_str)
+            goto error;
+
+        fprintf(stderr, "Generic driver capabilities:\n%s", caps_str);
+
+        VIR_FREE(caps_str);
+    }
+
+    return caps;
+
+error:
+    virObjectUnref(caps);
+    return NULL;
+}
+
+static virDomainDefParserConfig virTestGenericDomainDefParserConfig;
+static virDomainXMLPrivateDataCallbacks virTestGenericPrivateDataCallbacks;
+
+virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void)
+{
+    return virDomainXMLOptionNew(&virTestGenericDomainDefParserConfig,
+                                 &virTestGenericPrivateDataCallbacks,
+                                 NULL);
+}
index 29eb9d91d1132812cd67bcbf7df7d1fc41cbb16b..fa37246b4863509d4ab2e311b35a7317d27c10c7 100644 (file)
@@ -27,6 +27,8 @@
 # include "viralloc.h"
 # include "virfile.h"
 # include "virstring.h"
+# include "capabilities.h"
+# include "domain_conf.h"
 
 # define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
 # define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
@@ -104,4 +106,7 @@ int virtTestMain(int argc,
         return virtTestMain(argc, argv, func);                          \
     }
 
+virCapsPtr virTestGenericCapsInit(void);
+virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);
+
 #endif /* __VIT_TEST_UTILS_H__ */