提交 432a3fee 编写于 作者: D Daniel P. Berrange

Rename virDomainGetRootFilesystem to virDomainGetFilesystemForTarget

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: NDaniel P. Berrange <berrange@redhat.com>
上级 590029f6
......@@ -149,6 +149,7 @@
/tests/commandtest
/tests/conftest
/tests/cputest
/tests/domainconftest
/tests/domainsnapshotxml2xmltest
/tests/esxutilstest
/tests/eventtest
......
......@@ -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];
}
......
......@@ -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);
......
......@@ -229,7 +229,7 @@ virDomainFSTypeFromString;
virDomainFSTypeToString;
virDomainFSWrpolicyTypeFromString;
virDomainFSWrpolicyTypeToString;
virDomainGetRootFilesystem;
virDomainGetFilesystemForTarget;
virDomainGraphicsAuthConnectedTypeFromString;
virDomainGraphicsAuthConnectedTypeToString;
virDomainGraphicsDefFree;
......
......@@ -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];
......
......@@ -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;
......
......@@ -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)
......
<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>
/*
* 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)
......@@ -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);
}
......@@ -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__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册