[libvirt] [PATCH] Fix build with --with-driver-modules enabled
by Matthias Bolte
Export a bunch of missing symbols and link the remote driver to gnulib.
---
src/Makefile.am | 8 +++++++-
src/libvirt_private.syms | 3 +++
src/libvirt_xenxs.syms | 21 +++++++++++++++++++++
3 files changed, 31 insertions(+), 1 deletions(-)
create mode 100644 src/libvirt_xenxs.syms
diff --git a/src/Makefile.am b/src/Makefile.am
index c3d3102..02d53ee 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -553,6 +553,7 @@ libvirt_driver_remote_la_CFLAGS = \
libvirt_driver_remote_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_remote_la_LIBADD = $(GNUTLS_LIBS) $(SASL_LIBS)
if WITH_DRIVER_MODULES
+libvirt_driver_remote_la_LIBADD += ../gnulib/lib/libgnu.la
libvirt_driver_remote_la_LDFLAGS += -module -avoid-version
endif
libvirt_driver_remote_la_SOURCES = $(REMOTE_DRIVER_SOURCES)
@@ -1077,6 +1078,10 @@ if WITH_VMX
USED_SYM_FILES += libvirt_vmx.syms
endif
+if WITH_XENXS
+USED_SYM_FILES += libvirt_xenxs.syms
+endif
+
EXTRA_DIST += \
libvirt_public.syms \
libvirt_private.syms \
@@ -1086,7 +1091,8 @@ EXTRA_DIST += \
libvirt_macvtap.syms \
libvirt_daemon.syms \
libvirt_nwfilter.syms \
- libvirt_vmx.syms
+ libvirt_vmx.syms \
+ libvirt_xenxs.syms
BUILT_SOURCES += libvirt.syms libvirt.def libvirt_qemu.def
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4cb8dda..2088f38 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -929,6 +929,7 @@ virEventRemoveHandle;
virExec;
virExecWithHook;
virFileAbsPath;
+virFileBuildPath;
virFileDeletePid;
virFileExists;
virFileFindMountPoint;
@@ -1017,6 +1018,8 @@ virStrerror;
# xml.h
+virXMLParseFileHelper;
+virXMLParseHelper;
virXMLParseStrHelper;
virXMLPropString;
virXPathBoolean;
diff --git a/src/libvirt_xenxs.syms b/src/libvirt_xenxs.syms
new file mode 100644
index 0000000..3d794d6
--- /dev/null
+++ b/src/libvirt_xenxs.syms
@@ -0,0 +1,21 @@
+#
+# These symbols are dependent upon --with-xen via WITH_XEN or --with-libxl via WITH_LIBXL.
+#
+
+# xen_sxpr.h
+xenFormatSxpr;
+xenFormatSxprChr;
+xenFormatSxprDisk;
+xenFormatSxprNet;
+xenFormatSxprOnePCI;
+xenFormatSxprSound;
+xenGetDomIdFromSxpr;
+xenGetDomIdFromSxprString;
+xenParseSxpr;
+xenParseSxprChar;
+xenParseSxprSound;
+xenParseSxprString;
+
+# xen_xm.h
+xenFormatXM;
+xenParseXM;
--
1.7.0.4
13 years, 6 months
[libvirt] virsh list didn't show anything
by YAO
Hi,
I tried to connect xen using latest libvirt
When I connected to xend, "virsh list --all" gave me the right output.
But when I connected to libxl, the virsh didn't show anything only as
follows
Id Name State
----------------------------------
I think at least Domain-0 should show up.
Did I miss some point or something broken with the libxl_driver?
13 years, 6 months
[libvirt] [PATCH] qemu : support persistent add/delete network interface
by KAMEZAWA Hiroyuki
>From 226239905ec9b01fd0bd0ce050de97d7f0d9e19c Mon Sep 17 00:00:00 2001
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu(a)jp.fujitsu.com>
Date: Wed, 18 May 2011 15:14:28 +0900
Subject: [PATCH] qemu - support persistent add/delete network interface
This patch allows to modify interfaces of domain(qemu).
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu(a)jp.fujitsu.com>
* src/conf/domain_conf.c:
(virDomainNetInsert) : Insert a network device to domain definition.
(virDomainNetIndexByMac/Ifname) : Returns an index of net device in array.
(virDomainNetRemoveByMac): Remove a NIC of passed MAC address.
* src/qemu/qemu_driver.c
(qemuDomainAttachDeviceConfig): add codes for NIC.
(qemuDomainDetachDeviceConfig): add codes for NIC.
---
src/conf/domain_conf.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 5 ++++
src/libvirt_private.syms | 4 +++
src/qemu/qemu_driver.c | 32 ++++++++++++++++++++++++++
4 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 498438a..de9abe9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5163,6 +5163,61 @@ int virDomainDiskRemoveByName(virDomainDefPtr def, const char *name)
return 0;
}
+int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net)
+{
+ if (VIR_REALLOC_N(def->nets, def->nnets) < 0)
+ return -1;
+ def->nets[def->nnets] = net;
+ def->nnets++;
+ return 0;
+}
+
+int virDomainNetIndexByMac(virDomainDefPtr def, const unsigned char *mac)
+{
+ int i;
+
+ for (i = 0; i < def->nnets; i++)
+ if (!memcmp(def->nets[i]->mac, mac, VIR_MAC_BUFLEN))
+ return i;
+ return -1;
+}
+
+int virDomainNetIndexByIfname(virDomainDefPtr def, const char *name)
+{
+ int i;
+
+ for (i = 0; i < def->nnets; i++)
+ if (def->nets[i]->ifname && STREQ(def->nets[i]->ifname, name))
+ return i;
+ return -1;
+}
+
+static void virDomainNetRemove(virDomainDefPtr def, size_t i)
+{
+ if (def->nnets > 1) {
+ memmove(def->nets + i,
+ def->nets + i + 1,
+ sizeof(*def->nets) * (def->nnets - (i + 1)));
+ def->nnets--;
+ if (VIR_REALLOC_N(def->nets, def->nnets) < 0) {
+ /* ignore harmless */
+ }
+ } else {
+ VIR_FREE(def->nets);
+ def->nnets = 0;
+ }
+}
+
+int virDomainNetRemoveByMac(virDomainDefPtr def, const unsigned char *mac)
+{
+ int i = virDomainNetIndexByMac(def, mac);
+
+ if (i < 0)
+ return -1;
+ virDomainNetRemove(def, i);
+ return 0;
+}
+
int virDomainControllerInsert(virDomainDefPtr def,
virDomainControllerDefPtr controller)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fe42f21..274e22b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1359,6 +1359,11 @@ int virDomainDiskDefAssignAddress(virCapsPtr caps, virDomainDiskDefPtr def);
void virDomainDiskRemove(virDomainDefPtr def, size_t i);
int virDomainDiskRemoveByName(virDomainDefPtr def, const char *name);
+int virDomainNetIndexByMac(virDomainDefPtr def, const unsigned char *mac);
+int virDomainNetIndexByIfname(virDomainDefPtr def, const char *iface);
+int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net);
+int virDomainNetRemoveByMac(virDomainDefPtr def, const unsigned char *mac);
+
int virDomainControllerInsert(virDomainDefPtr def,
virDomainControllerDefPtr controller);
void virDomainControllerInsertPreAlloced(virDomainDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7b6151c..2695c2e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -290,6 +290,10 @@ virDomainLoadAllConfigs;
virDomainMemballoonModelTypeFromString;
virDomainMemballoonModelTypeToString;
virDomainNetDefFree;
+virDomainNetIndexByIfname;
+virDomainNetIndexByMac;
+virDomainNetInsert;
+virDomainNetRemoveByMac;
virDomainNetTypeToString;
virDomainObjAssignDef;
virDomainObjCopyPersistentDef;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fdb3b30..0a547eb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4245,6 +4245,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
virDomainDeviceDefPtr dev)
{
virDomainDiskDefPtr disk;
+ virDomainNetDefPtr net;
switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK:
@@ -4267,6 +4268,28 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
return -1;
break;
+ case VIR_DOMAIN_DEVICE_NET:
+ net = dev->data.net;
+ if (net->ifname && virDomainNetIndexByIfname(vmdef, net->ifname)) {
+ qemuReportError(VIR_ERR_INVALID_ARG,
+ _("iface %s already exists"), net->ifname);
+ return -1;
+ }
+ if (virDomainNetIndexByMac(vmdef, net->mac) >= 0) {
+ char macbuf[VIR_MAC_STRING_BUFLEN];
+ virFormatMacAddr(net->mac, macbuf);
+ qemuReportError(VIR_ERR_INVALID_ARG,
+ _("mac %s already exists"), macbuf);
+ return -1;
+ }
+ if (virDomainNetInsert(vmdef, net)) {
+ virReportOOMError();
+ return -1;
+ }
+ dev->data.net = NULL;
+ if (qemuDomainAssignPCIAddresses(vmdef) < 0)
+ return -1;
+ break;
default:
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("persistent attach of device is not supported"));
@@ -4281,6 +4304,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
virDomainDeviceDefPtr dev)
{
virDomainDiskDefPtr disk;
+ virDomainNetDefPtr net;
switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK:
@@ -4291,6 +4315,14 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
return -1;
}
break;
+ case VIR_DOMAIN_DEVICE_NET:
+ net = dev->data.net;
+ if (virDomainNetRemoveByMac(vmdef, net->mac)) {
+ qemuReportError(VIR_ERR_INVALID_ARG,
+ _("no target device %s"), disk->dst);
+ return -1;
+ }
+ break;
default:
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("persistent detach of device is not supported"));
--
1.7.4.1
13 years, 6 months
[libvirt] [PATCH 0/3] Add device disk attach/detach support to libxl driver
by Markus Groß
This patch series adds the infrastructure to support
attaching and detaching of devices to the libxl driver.
Currently only disk devices are supported.
The first patch refactors some functions that
are needed to create the appropriate datastructures
for the libxenlight interface.
The second patch fixes the handling of vm def's on cleanup.
The last patch finally adds the device attach/detach code
and follows qemu's implementation.
Markus Groß (3):
Refactored libxl datastructure instantiation
Fix libxl vm def handling on domU cleanup
Add disk attach/detach support to libxl driver
src/libxl/libxl_conf.c | 304 ++++++++++++++-------------
src/libxl/libxl_conf.h | 8 +
src/libxl/libxl_driver.c | 526 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 697 insertions(+), 141 deletions(-)
--
1.7.5.1
13 years, 6 months
[libvirt] [PATCH] esx: Fix regression in absolute file name handling
by Matthias Bolte
Before commit 145d6cb05c45f4 (in August 2010) absolute file names
in VMX and domain XML configs were handled correctly. But this got
lost during the refactoring. The test cases didn't highlight this
problem because they have their own set of file name handling
functions. The actual ones require a real connection to an ESX
server. Also the test case functions always worked correctly.
Fix the regression and add a new in-the-wild VMX file that contains
such a problematic absolute path. Even though this test case won't
protect against new regressions.
Reported by lofic (IRC nick)
---
src/esx/esx_driver.c | 131 ++++++++++++++---------
tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.vmx | 80 ++++++++++++++
tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.xml | 36 ++++++
tests/vmx2xmltest.c | 1 +
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-6.vmx | 26 +++++
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-6.xml | 36 ++++++
tests/xml2vmxtest.c | 1 +
7 files changed, 259 insertions(+), 52 deletions(-)
create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.vmx
create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.xml
create mode 100644 tests/xml2vmxdata/xml2vmx-esx-in-the-wild-6.vmx
create mode 100644 tests/xml2vmxdata/xml2vmx-esx-in-the-wild-6.xml
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 845dd4a..809afeb 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -74,8 +74,8 @@ esxFreePrivate(esxPrivate **priv)
/*
- * Parse a file name from a .vmx file and convert it to datastore path format.
- * A .vmx file can contain file names in various formats:
+ * Parse a file name from a .vmx file and convert it to datastore path format
+ * if possbile. A .vmx file can contain file names in various formats:
*
* - A single name referencing a file in the same directory as the .vmx file:
*
@@ -97,6 +97,14 @@ esxFreePrivate(esxPrivate **priv)
* C:\Virtual Machines\test1\test1.vmdk
* \\nas1\storage1\test1\test1.vmdk
*
+ * - There might also be absolute file names referencing files outside of a
+ * datastore:
+ *
+ * /usr/lib/vmware/isoimages/linux.iso
+ *
+ * Such file names are left as is and are not converted to datastore path
+ * format because this is not possible.
+ *
* The datastore path format typically looks like this:
*
* [datastore1] test1/test1.vmdk
@@ -117,7 +125,7 @@ esxFreePrivate(esxPrivate **priv)
static char *
esxParseVMXFileName(const char *fileName, void *opaque)
{
- char *datastorePath = NULL;
+ char *result = NULL;
esxVMX_Data *data = opaque;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *datastoreList = NULL;
@@ -132,7 +140,7 @@ esxParseVMXFileName(const char *fileName, void *opaque)
if (strchr(fileName, '/') == NULL && strchr(fileName, '\\') == NULL) {
/* Plain file name, use same directory as for the .vmx file */
- if (virAsprintf(&datastorePath, "%s/%s",
+ if (virAsprintf(&result, "%s/%s",
data->datastorePathWithoutFileName, fileName) < 0) {
virReportOOMError();
goto cleanup;
@@ -184,7 +192,7 @@ esxParseVMXFileName(const char *fileName, void *opaque)
++tmp;
}
- if (virAsprintf(&datastorePath, "[%s] %s", datastoreName,
+ if (virAsprintf(&result, "[%s] %s", datastoreName,
strippedFileName) < 0) {
virReportOOMError();
goto cleanup;
@@ -194,7 +202,7 @@ esxParseVMXFileName(const char *fileName, void *opaque)
}
/* Fallback to direct datastore name match */
- if (datastorePath == NULL && STRPREFIX(fileName, "/vmfs/volumes/")) {
+ if (result == NULL && STRPREFIX(fileName, "/vmfs/volumes/")) {
if (esxVI_String_DeepCopyValue(©OfFileName, fileName) < 0) {
goto cleanup;
}
@@ -224,16 +232,24 @@ esxParseVMXFileName(const char *fileName, void *opaque)
goto cleanup;
}
- if (virAsprintf(&datastorePath, "[%s] %s", datastoreName,
+ if (virAsprintf(&result, "[%s] %s", datastoreName,
directoryAndFileName) < 0) {
virReportOOMError();
goto cleanup;
}
}
- if (datastorePath == NULL) {
+ /* If it's an absolute path outside of a datastore just use it as is */
+ if (result == NULL && *fileName == '/') {
+ /* FIXME: need to deal with Windows paths here too */
+ if (esxVI_String_DeepCopyValue(&result, fileName) < 0) {
+ goto cleanup;
+ }
+ }
+
+ if (result == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
- _("Could not find datastore for '%s'"), fileName);
+ _("Could not handle file name '%s'"), fileName);
goto cleanup;
}
}
@@ -245,15 +261,15 @@ esxParseVMXFileName(const char *fileName, void *opaque)
VIR_FREE(strippedFileName);
VIR_FREE(copyOfFileName);
- return datastorePath;
+ return result;
}
/*
* This function does the inverse of esxParseVMXFileName. It takes an file name
- * in datastore path format and converts it to a file name that can be used in
- * a .vmx file.
+ * in datastore path format or in absolute format and converts it to a file
+ * name that can be used in a .vmx file.
*
* The datastore path format and the formats found in a .vmx file are described
* in the documentation of esxParseVMXFileName.
@@ -264,9 +280,10 @@ esxParseVMXFileName(const char *fileName, void *opaque)
* based on the mount path.
*/
static char *
-esxFormatVMXFileName(const char *datastorePath, void *opaque)
+esxFormatVMXFileName(const char *fileName, void *opaque)
{
bool success = false;
+ char *result = NULL;
esxVMX_Data *data = opaque;
char *datastoreName = NULL;
char *directoryAndFileName = NULL;
@@ -276,58 +293,68 @@ esxFormatVMXFileName(const char *datastorePath, void *opaque)
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *tmp;
size_t length;
- char *absolutePath = NULL;
- /* Parse datastore path and lookup datastore */
- if (esxUtil_ParseDatastorePath(datastorePath, &datastoreName, NULL,
- &directoryAndFileName) < 0) {
- goto cleanup;
- }
+ if (*fileName == '[') {
+ /* Parse datastore path and lookup datastore */
+ if (esxUtil_ParseDatastorePath(fileName, &datastoreName, NULL,
+ &directoryAndFileName) < 0) {
+ goto cleanup;
+ }
- if (esxVI_LookupDatastoreByName(data->ctx, datastoreName, NULL, &datastore,
- esxVI_Occurrence_RequiredItem) < 0 ||
- esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj,
- &hostMount) < 0) {
- goto cleanup;
- }
+ if (esxVI_LookupDatastoreByName(data->ctx, datastoreName, NULL, &datastore,
+ esxVI_Occurrence_RequiredItem) < 0 ||
+ esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj,
+ &hostMount) < 0) {
+ goto cleanup;
+ }
- /* Detect separator type */
- if (strchr(hostMount->mountInfo->path, '\\') != NULL) {
- separator = '\\';
- }
+ /* Detect separator type */
+ if (strchr(hostMount->mountInfo->path, '\\') != NULL) {
+ separator = '\\';
+ }
- /* Strip trailing separators */
- length = strlen(hostMount->mountInfo->path);
+ /* Strip trailing separators */
+ length = strlen(hostMount->mountInfo->path);
- while (length > 0 && hostMount->mountInfo->path[length - 1] == separator) {
- --length;
- }
+ while (length > 0 && hostMount->mountInfo->path[length - 1] == separator) {
+ --length;
+ }
- /* Format as <mount>[/<directory>]/<file>, convert / to \ when necessary */
- virBufferAdd(&buffer, hostMount->mountInfo->path, length);
+ /* Format as <mount>[/<directory>]/<file>, convert / to \ when necessary */
+ virBufferAdd(&buffer, hostMount->mountInfo->path, length);
- if (separator != '/') {
- tmp = directoryAndFileName;
+ if (separator != '/') {
+ tmp = directoryAndFileName;
- while (*tmp != '\0') {
- if (*tmp == '/') {
- *tmp = separator;
- }
+ while (*tmp != '\0') {
+ if (*tmp == '/') {
+ *tmp = separator;
+ }
- ++tmp;
+ ++tmp;
+ }
}
- }
- virBufferAddChar(&buffer, separator);
- virBufferAdd(&buffer, directoryAndFileName, -1);
+ virBufferAddChar(&buffer, separator);
+ virBufferAdd(&buffer, directoryAndFileName, -1);
- if (virBufferError(&buffer)) {
- virReportOOMError();
+ if (virBufferError(&buffer)) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ result = virBufferContentAndReset(&buffer);
+ } else if (*fileName == '/') {
+ /* FIXME: need to deal with Windows paths here too */
+ if (esxVI_String_DeepCopyValue(&result, fileName) < 0) {
+ goto cleanup;
+ }
+ } else {
+ ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
+ _("Could not handle file name '%s'"), fileName);
goto cleanup;
}
- absolutePath = virBufferContentAndReset(&buffer);
-
/* FIXME: Check if referenced path/file really exists */
success = true;
@@ -335,7 +362,7 @@ esxFormatVMXFileName(const char *datastorePath, void *opaque)
cleanup:
if (! success) {
virBufferFreeAndReset(&buffer);
- VIR_FREE(absolutePath);
+ VIR_FREE(result);
}
VIR_FREE(datastoreName);
@@ -343,7 +370,7 @@ esxFormatVMXFileName(const char *datastorePath, void *opaque)
esxVI_ObjectContent_Free(&datastore);
esxVI_DatastoreHostMount_Free(&hostMount);
- return absolutePath;
+ return result;
}
diff --git a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.vmx b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.vmx
new file mode 100644
index 0000000..b795e80
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.vmx
@@ -0,0 +1,80 @@
+.encoding = "UTF-8"
+config.version = "8"
+virtualHW.version = "7"
+pciBridge0.present = "TRUE"
+pciBridge4.present = "TRUE"
+pciBridge4.virtualDev = "pcieRootPort"
+pciBridge4.functions = "8"
+pciBridge5.present = "TRUE"
+pciBridge5.virtualDev = "pcieRootPort"
+pciBridge5.functions = "8"
+pciBridge6.present = "TRUE"
+pciBridge6.virtualDev = "pcieRootPort"
+pciBridge6.functions = "8"
+pciBridge7.present = "TRUE"
+pciBridge7.virtualDev = "pcieRootPort"
+pciBridge7.functions = "8"
+vmci0.present = "TRUE"
+nvram = "el6-test.nvram"
+virtualHW.productCompatibility = "hosted"
+powerType.powerOff = "soft"
+powerType.powerOn = "hard"
+powerType.suspend = "hard"
+powerType.reset = "soft"
+displayName = "el6-test"
+extendedConfigFile = "el6-test.vmxf"
+floppy0.present = "TRUE"
+scsi0.present = "TRUE"
+scsi0.sharedBus = "none"
+scsi0.virtualDev = "pvscsi"
+memsize = "1024"
+scsi0:0.present = "TRUE"
+scsi0:0.fileName = "el6-test-000001.vmdk"
+scsi0:0.deviceType = "scsi-hardDisk"
+ide1:0.present = "TRUE"
+ide1:0.clientDevice = "FALSE"
+ide1:0.deviceType = "cdrom-image"
+ide1:0.startConnected = "FALSE"
+floppy0.startConnected = "FALSE"
+floppy0.fileName = ""
+floppy0.clientDevice = "TRUE"
+ethernet0.present = "TRUE"
+ethernet0.virtualDev = "vmxnet3"
+ethernet0.networkName = "VM Network"
+ethernet0.addressType = "generated"
+guestOS = "rhel6-64"
+uuid.location = "56 4d 15 d4 d0 62 fe 9a-80 f5 eb 8e 1a 2c 3a fc"
+uuid.bios = "56 4d 15 d4 d0 62 fe 9a-80 f5 eb 8e 1a 2c 3a fc"
+vc.uuid = "52 00 b6 9b 8d 88 7b df-a1 4a 02 70 5d 65 37 72"
+ethernet0.generatedAddress = "00:0c:29:2c:3a:fc"
+svga.vramSize = "8388608"
+vmci0.id = "439106300"
+cleanShutdown = "TRUE"
+replay.supported = "TRUE"
+sched.swap.derivedName = "/vmfs/volumes/4dd68884-f4586c0e-8223-00215aaab842/el6-test/el6-test-4475e3f0.vswp"
+replay.filename = ""
+scsi0:0.redo = ""
+pciBridge0.pciSlotNumber = "17"
+pciBridge4.pciSlotNumber = "21"
+pciBridge5.pciSlotNumber = "22"
+pciBridge6.pciSlotNumber = "23"
+pciBridge7.pciSlotNumber = "24"
+scsi0.pciSlotNumber = "160"
+ethernet0.pciSlotNumber = "192"
+vmci0.pciSlotNumber = "32"
+scsi0.sasWWID = "50 05 05 64 d0 62 fe 90"
+vmotion.checkpointFBSize = "8388608"
+ethernet0.generatedAddressOffset = "0"
+tools.remindInstall = "FALSE"
+hostCPUID.0 = "0000000a756e65476c65746e49656e69"
+hostCPUID.1 = "0001067600040800000ce33dbfebfbff"
+hostCPUID.80000001 = "00000000000000000000000120100800"
+guestCPUID.0 = "0000000a756e65476c65746e49656e69"
+guestCPUID.1 = "0001067600010800800822010febfbff"
+guestCPUID.80000001 = "00000000000000000000000120100800"
+userCPUID.0 = "0000000a756e65476c65746e49656e69"
+userCPUID.1 = "0001067600040800000822010febfbff"
+userCPUID.80000001 = "00000000000000000000000120100800"
+evcCompatibilityMode = "FALSE"
+ide1:0.fileName = "/usr/lib/vmware/isoimages/linux.iso"
+tools.syncTime = "FALSE"
diff --git a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.xml b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.xml
new file mode 100644
index 0000000..0c4e4d5
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.xml
@@ -0,0 +1,36 @@
+<domain type='vmware'>
+ <name>el6-test</name>
+ <uuid>564d15d4-d062-fe9a-80f5-eb8e1a2c3afc</uuid>
+ <memory>1048576</memory>
+ <currentMemory>1048576</currentMemory>
+ <vcpu>1</vcpu>
+ <os>
+ <type arch='x86_64'>hvm</type>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <source file='[datastore] directory/el6-test-000001.vmdk'/>
+ <target dev='sda' bus='scsi'/>
+ <address type='drive' controller='0' bus='0' unit='0'/>
+ </disk>
+ <disk type='file' device='cdrom'>
+ <source file='/usr/lib/vmware/isoimages/linux.iso'/>
+ <target dev='hdc' bus='ide'/>
+ <address type='drive' controller='0' bus='1' unit='0'/>
+ </disk>
+ <controller type='scsi' index='0' model='vmpvscsi'/>
+ <controller type='ide' index='0'/>
+ <interface type='bridge'>
+ <mac address='00:0c:29:2c:3a:fc'/>
+ <source bridge='VM Network'/>
+ <model type='vmxnet3'/>
+ </interface>
+ <video>
+ <model type='vmvga' vram='8192'/>
+ </video>
+ </devices>
+</domain>
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index e01e8ad..7396f39 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -261,6 +261,7 @@ mymain(void)
DO_TEST("esx-in-the-wild-3", "esx-in-the-wild-3");
DO_TEST("esx-in-the-wild-4", "esx-in-the-wild-4");
DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5");
+ DO_TEST("esx-in-the-wild-6", "esx-in-the-wild-6");
DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1");
DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2");
diff --git a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-6.vmx b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-6.vmx
new file mode 100644
index 0000000..1f29ae5
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-6.vmx
@@ -0,0 +1,26 @@
+.encoding = "UTF-8"
+config.version = "8"
+virtualHW.version = "4"
+guestOS = "other-64"
+uuid.bios = "56 4d 15 d4 d0 62 fe 9a-80 f5 eb 8e 1a 2c 3a fc"
+displayName = "el6-test"
+memsize = "1024"
+numvcpus = "1"
+scsi0.present = "true"
+scsi0.virtualDev = "pvscsi"
+scsi0:0.present = "true"
+scsi0:0.deviceType = "scsi-hardDisk"
+scsi0:0.fileName = "/vmfs/volumes/datastore/directory/el6-test-000001.vmdk"
+ide1:0.present = "true"
+ide1:0.deviceType = "cdrom-image"
+ide1:0.fileName = "/usr/lib/vmware/isoimages/linux.iso"
+floppy0.present = "false"
+floppy1.present = "false"
+ethernet0.present = "true"
+ethernet0.virtualDev = "vmxnet3"
+ethernet0.networkName = "VM Network"
+ethernet0.connectionType = "bridged"
+ethernet0.addressType = "generated"
+ethernet0.generatedAddress = "00:0C:29:2C:3A:FC"
+ethernet0.generatedAddressOffset = "0"
+svga.vramSize = "8388608"
diff --git a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-6.xml b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-6.xml
new file mode 100644
index 0000000..0c4e4d5
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-6.xml
@@ -0,0 +1,36 @@
+<domain type='vmware'>
+ <name>el6-test</name>
+ <uuid>564d15d4-d062-fe9a-80f5-eb8e1a2c3afc</uuid>
+ <memory>1048576</memory>
+ <currentMemory>1048576</currentMemory>
+ <vcpu>1</vcpu>
+ <os>
+ <type arch='x86_64'>hvm</type>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <source file='[datastore] directory/el6-test-000001.vmdk'/>
+ <target dev='sda' bus='scsi'/>
+ <address type='drive' controller='0' bus='0' unit='0'/>
+ </disk>
+ <disk type='file' device='cdrom'>
+ <source file='/usr/lib/vmware/isoimages/linux.iso'/>
+ <target dev='hdc' bus='ide'/>
+ <address type='drive' controller='0' bus='1' unit='0'/>
+ </disk>
+ <controller type='scsi' index='0' model='vmpvscsi'/>
+ <controller type='ide' index='0'/>
+ <interface type='bridge'>
+ <mac address='00:0c:29:2c:3a:fc'/>
+ <source bridge='VM Network'/>
+ <model type='vmxnet3'/>
+ </interface>
+ <video>
+ <model type='vmvga' vram='8192'/>
+ </video>
+ </devices>
+</domain>
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index efd4d74..66ed53d 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -272,6 +272,7 @@ mymain(void)
DO_TEST("esx-in-the-wild-3", "esx-in-the-wild-3", 4);
DO_TEST("esx-in-the-wild-4", "esx-in-the-wild-4", 4);
DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5", 4);
+ DO_TEST("esx-in-the-wild-6", "esx-in-the-wild-6", 4);
DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1", 4);
DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2", 4);
--
1.7.0.4
13 years, 6 months
[libvirt] [PATCH] openvz: Add simple testcase for config file parsing function
by Matthias Bolte
This testcase passes before the regression is added in f0443765, fails
after that commit and passes again after the regression was fixed.
---
src/openvz/openvz_conf.c | 2 +-
src/openvz/openvz_conf.h | 1 +
tests/Makefile.am | 18 +++++++++
tests/openvzutilstest.c | 91 ++++++++++++++++++++++++++++++++++++++++++++
tests/openvzutilstest.conf | 41 ++++++++++++++++++++
5 files changed, 152 insertions(+), 1 deletions(-)
create mode 100644 tests/openvzutilstest.c
create mode 100644 tests/openvzutilstest.conf
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 3e4844a..3dc6b37 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -645,7 +645,7 @@ openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value)
*
* Returns <0 on error, 0 if not found, 1 if found.
*/
-static int
+int
openvzReadConfigParam(const char *conf_file, const char *param, char **value)
{
char *line = NULL;
diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h
index 9a57551..d5a57a6 100644
--- a/src/openvz/openvz_conf.h
+++ b/src/openvz/openvz_conf.h
@@ -57,6 +57,7 @@ int openvz_readline(int fd, char *ptr, int maxlen);
int openvzExtractVersion(struct openvz_driver *driver);
int openvzReadVPSConfigParam(int vpsid, const char *param, char **value);
int openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value);
+int openvzReadConfigParam(const char *conf_file, const char *param, char **value);
int openvzCopyDefaultConfig(int vpsid);
virCapsPtr openvzCapsInit(void);
int openvzLoadDomains(struct openvz_driver *driver);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bc171d2..7ae50a2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -91,6 +91,10 @@ if WITH_QEMU
check_PROGRAMS += qemuxml2argvtest qemuxml2xmltest qemuargv2xmltest qemuhelptest
endif
+if WITH_OPENVZ
+check_PROGRAMS += openvzutilstest
+endif
+
if WITH_ESX
check_PROGRAMS += esxutilstest
endif
@@ -197,6 +201,10 @@ TESTS += qemuxml2argvtest qemuxml2xmltest qemuargv2xmltest qemuhelptest
TESTS += nwfilterxml2xmltest
endif
+if WITH_OPENVZ
+TESTS += openvzutilstest
+endif
+
if WITH_ESX
TESTS += esxutilstest
endif
@@ -301,6 +309,16 @@ else
EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c qemuhelptest.c testutilsqemu.c testutilsqemu.h
endif
+if WITH_OPENVZ
+openvzutilstest_SOURCES = \
+ openvzutilstest.c \
+ testutils.c testutils.h
+openvzutilstest_LDADD = ../src/libvirt_driver_openvz.la $(LDADDS)
+else
+EXTRA_DIST += openvzutilstest.c
+endif
+EXTRA_DIST += openvzutilstest.conf
+
if WITH_ESX
esxutilstest_SOURCES = \
esxutilstest.c \
diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c
new file mode 100644
index 0000000..1052450
--- /dev/null
+++ b/tests/openvzutilstest.c
@@ -0,0 +1,91 @@
+#include <config.h>
+
+#ifdef WITH_OPENVZ
+
+# include <stdio.h>
+# include <string.h>
+# include <unistd.h>
+
+# include "internal.h"
+# include "memory.h"
+# include "testutils.h"
+# include "util.h"
+# include "openvz/openvz_conf.h"
+
+struct testConfigParam {
+ const char *param;
+ const char *value;
+ int ret;
+};
+
+static struct testConfigParam configParams[] = {
+ { "OSTEMPLATE", "rhel-5-lystor", 1 },
+ { "IP_ADDRESS", "194.44.18.88", 1 },
+ { "THIS_PARAM_IS_MISSING", NULL, 0 },
+};
+
+static int
+testReadConfigParam(const void *data ATTRIBUTE_UNUSED)
+{
+ int result = -1;
+ int i;
+ char *conf = NULL;
+ char *value = NULL;
+
+ if (virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir) < 0) {
+ return -1;
+ }
+
+ for (i = 0; i < ARRAY_CARDINALITY(configParams); ++i) {
+ if (openvzReadConfigParam(conf, configParams[i].param,
+ &value) != configParams[i].ret) {
+ goto cleanup;
+ }
+
+ if (configParams[i].ret != 1) {
+ continue;
+ }
+
+ if (STRNEQ(configParams[i].value, value)) {
+ virtTestDifference(stderr, configParams[i].value, value);
+ goto cleanup;
+ }
+ }
+
+ result = 0;
+
+cleanup:
+ VIR_FREE(conf);
+ VIR_FREE(value);
+
+ return result;
+}
+
+static int
+mymain(void)
+{
+ int result = 0;
+
+# define DO_TEST(_name) \
+ do { \
+ if (virtTestRun("OpenVZ "#_name, 1, test##_name, \
+ NULL) < 0) { \
+ result = -1; \
+ } \
+ } while (0)
+
+ DO_TEST(ReadConfigParam);
+
+ return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
+
+#else
+
+int main(void)
+{
+ return 77; /* means 'test skipped' for automake */
+}
+
+#endif /* WITH_OPENVZ */
diff --git a/tests/openvzutilstest.conf b/tests/openvzutilstest.conf
new file mode 100644
index 0000000..a1b93b7
--- /dev/null
+++ b/tests/openvzutilstest.conf
@@ -0,0 +1,41 @@
+# sample config from http://blog.lystor.org.ua/2009/11/openvz-configuration-example.html
+
+ONBOOT="yes"
+
+# Primary parameters
+NUMPROC="8000:8000"
+AVNUMPROC="2257:2257"
+NUMTCPSOCK="8000:8000"
+NUMOTHERSOCK="8000:8000"
+VMGUARPAGES="360000:360000"
+
+# Secondary parameters
+KMEMSIZE="184953241:203448565"
+TCPSNDBUF="28883080:61651080"
+TCPRCVBUF="28883080:61651080"
+OTHERSOCKBUF="14441540:47209540"
+DGRAMRCVBUF="14441540:14441540"
+OOMGUARPAGES="360000:360000"
+PRIVVMPAGES="360000:360000"
+
+# Auxiliary parameters
+LOCKEDPAGES="9030:9030"
+SHMPAGES="15506:15506"
+PHYSPAGES="0:2147483647"
+NUMFILE="72224:72224"
+NUMFLOCK="1000:1100"
+NUMPTY="512:512"
+NUMSIGINFO="1024:1024"
+DCACHESIZE="40389343:41601024"
+NUMIPTENT="200:200"
+DISKSPACE="107733379:118506717"
+DISKINODES="55287781:60816560"
+CPUUNITS="150550"
+
+# Disk quota parameters (in form of softlimit:hardlimit)
+DISKSPACE=""
+DISKINODES=""
+QUOTATIME=""
+DISK_QUOTA=no
+OSTEMPLATE="rhel-5-lystor"
+IP_ADDRESS="194.44.18.88"
--
1.7.0.4
13 years, 6 months
[libvirt] [PATCH v3] storage: List directory volumes for dir/fs/netfs pools
by Cole Robinson
Since directories can be used for <filesystem> passthrough, they are
basically storage volumes.
v2:
Skip ., .., lost+found dirs
v3:
Use gnulib last_component
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
src/storage/storage_backend.c | 45 ++++++++++++++++++++++++++++++++------
src/storage/storage_backend.h | 7 +++++-
src/storage/storage_backend_fs.c | 14 ++++++++---
src/util/storage_file.c | 30 ++++++++++++++++++++++++-
4 files changed, 83 insertions(+), 13 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 02e455f..f23cf60 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -36,6 +36,7 @@
#include <sys/stat.h>
#include <sys/param.h>
#include <dirent.h>
+#include <dirname.h>
#ifdef __linux__
# include <sys/ioctl.h>
# include <linux/fs.h>
@@ -994,6 +995,7 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags)
{
int fd, mode = 0;
struct stat sb;
+ char *base = last_component(path);
if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOCTTY)) < 0) {
if ((errno == ENOENT || errno == ELOOP) &&
@@ -1022,9 +1024,21 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags)
mode = VIR_STORAGE_VOL_OPEN_CHAR;
else if (S_ISBLK(sb.st_mode))
mode = VIR_STORAGE_VOL_OPEN_BLOCK;
+ else if (S_ISDIR(sb.st_mode)) {
+ mode = VIR_STORAGE_VOL_OPEN_DIR;
+
+ if (STREQ(base, ".") ||
+ STREQ(base, "..") ||
+ STREQ(base, "lost+found")) {
+ VIR_FORCE_CLOSE(fd);
+ VIR_INFO("Skipping special dir '%s'", base);
+ return -2;
+ }
+ }
if (!(mode & flags)) {
VIR_FORCE_CLOSE(fd);
+ VIR_INFO("Skipping volume '%s'", path);
if (mode & VIR_STORAGE_VOL_OPEN_ERROR) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1047,11 +1061,13 @@ int virStorageBackendVolOpen(const char *path)
int
virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target,
unsigned long long *allocation,
- unsigned long long *capacity)
+ unsigned long long *capacity,
+ unsigned int openflags)
{
int ret, fd;
- if ((ret = virStorageBackendVolOpen(target->path)) < 0)
+ if ((ret = virStorageBackendVolOpenCheckMode(target->path,
+ openflags)) < 0)
return ret;
fd = ret;
@@ -1066,24 +1082,34 @@ virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target,
}
int
-virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
- int withCapacity)
+virStorageBackendUpdateVolInfoFlags(virStorageVolDefPtr vol,
+ int withCapacity,
+ unsigned int openflags)
{
int ret;
if ((ret = virStorageBackendUpdateVolTargetInfo(&vol->target,
- &vol->allocation,
- withCapacity ? &vol->capacity : NULL)) < 0)
+ &vol->allocation,
+ withCapacity ? &vol->capacity : NULL,
+ openflags)) < 0)
return ret;
if (vol->backingStore.path &&
(ret = virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
- NULL, NULL)) < 0)
+ NULL, NULL,
+ VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0)
return ret;
return 0;
}
+int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
+ int withCapacity)
+{
+ return virStorageBackendUpdateVolInfoFlags(vol, withCapacity,
+ VIR_STORAGE_VOL_OPEN_DEFAULT);
+}
+
/*
* virStorageBackendUpdateVolTargetInfoFD:
* @conn: connection to report errors on
@@ -1125,6 +1151,11 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
*/
if (capacity)
*capacity = sb.st_size;
+ } else if (S_ISDIR(sb.st_mode)) {
+ *allocation = 0;
+ if (capacity)
+ *capacity = 0;
+
} else {
off_t end;
/* XXX this is POSIX compliant, but doesn't work for CHAR files,
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index fcfbed0..67ac32c 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -93,6 +93,7 @@ enum {
VIR_STORAGE_VOL_OPEN_REG = 1 << 1, /* regular files okay */
VIR_STORAGE_VOL_OPEN_BLOCK = 1 << 2, /* block files okay */
VIR_STORAGE_VOL_OPEN_CHAR = 1 << 3, /* char files okay */
+ VIR_STORAGE_VOL_OPEN_DIR = 1 << 4, /* directories okay */
};
# define VIR_STORAGE_VOL_OPEN_DEFAULT (VIR_STORAGE_VOL_OPEN_ERROR |\
@@ -107,9 +108,13 @@ ATTRIBUTE_NONNULL(1);
int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
int withCapacity);
+int virStorageBackendUpdateVolInfoFlags(virStorageVolDefPtr vol,
+ int withCapacity,
+ unsigned int openflags);
int virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target,
unsigned long long *allocation,
- unsigned long long *capacity);
+ unsigned long long *capacity,
+ unsigned int openflags);
int virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
int fd,
unsigned long long *allocation,
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index b8d4d63..3f4d978 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -48,6 +48,11 @@
#define VIR_FROM_THIS VIR_FROM_STORAGE
+#define VIR_STORAGE_VOL_FS_OPEN_FLAGS (VIR_STORAGE_VOL_OPEN_DEFAULT |\
+ VIR_STORAGE_VOL_OPEN_DIR)
+#define VIR_STORAGE_VOL_FS_REFRESH_FLAGS (VIR_STORAGE_VOL_FS_OPEN_FLAGS &\
+ ~VIR_STORAGE_VOL_OPEN_ERROR)
+
static int ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
virStorageBackendProbeTarget(virStorageVolTargetPtr target,
char **backingStore,
@@ -65,7 +70,7 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
*encryption = NULL;
if ((ret = virStorageBackendVolOpenCheckMode(target->path,
- (VIR_STORAGE_VOL_OPEN_DEFAULT & ~VIR_STORAGE_VOL_OPEN_ERROR))) < 0)
+ VIR_STORAGE_VOL_FS_REFRESH_FLAGS)) < 0)
return ret; /* Take care to propagate ret, it is not always -1 */
fd = ret;
@@ -676,8 +681,8 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
vol->backingStore.format = backingStoreFormat;
if (virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
- NULL,
- NULL) < 0) {
+ NULL, NULL,
+ VIR_STORAGE_VOL_OPEN_DEFAULT) < 0) {
/* The backing file is currently unavailable, the capacity,
* allocation, owner, group and mode are unknown. Just log the
* error an continue.
@@ -941,7 +946,8 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
int ret;
/* Refresh allocation / permissions info in case its changed */
- ret = virStorageBackendUpdateVolInfo(vol, 0);
+ ret = virStorageBackendUpdateVolInfoFlags(vol, 0,
+ VIR_STORAGE_VOL_FS_OPEN_FLAGS);
if (ret < 0)
return ret;
diff --git a/src/util/storage_file.c b/src/util/storage_file.c
index ede79fa..8dbd933 100644
--- a/src/util/storage_file.c
+++ b/src/util/storage_file.c
@@ -24,6 +24,7 @@
#include <config.h>
#include "storage_file.h"
+#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#ifdef __linux__
@@ -736,6 +737,19 @@ virStorageFileProbeFormatFromFD(const char *path, int fd)
unsigned char *head;
ssize_t len = STORAGE_MAX_HEAD;
int ret = -1;
+ struct stat sb;
+
+ if (fstat(fd, &sb) < 0) {
+ virReportSystemError(errno,
+ _("cannot stat file '%s'"),
+ path);
+ return -1;
+ }
+
+ /* No header to probe for directories */
+ if (S_ISDIR(sb.st_mode)) {
+ return VIR_STORAGE_FILE_DIR;
+ }
if (VIR_ALLOC_N(head, len) < 0) {
virReportOOMError();
@@ -812,9 +826,10 @@ virStorageFileGetMetadataFromFD(const char *path,
int format,
virStorageFileMetadata *meta)
{
- unsigned char *head;
+ unsigned char *head = NULL;
ssize_t len = STORAGE_MAX_HEAD;
int ret = -1;
+ struct stat sb;
if (VIR_ALLOC_N(head, len) < 0) {
virReportOOMError();
@@ -823,6 +838,19 @@ virStorageFileGetMetadataFromFD(const char *path,
memset(meta, 0, sizeof (*meta));
+ if (fstat(fd, &sb) < 0) {
+ virReportSystemError(errno,
+ _("cannot stat file '%s'"),
+ path);
+ return -1;
+ }
+
+ /* No header to probe for directories */
+ if (S_ISDIR(sb.st_mode)) {
+ ret = 0;
+ goto cleanup;
+ }
+
if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
virReportSystemError(errno, _("cannot seek to start of '%s'"), path);
goto cleanup;
--
1.7.4.4
13 years, 6 months
[libvirt] [PATCH v3 0/4] support for changing cpu.shares for inactive domains from virsh cmd
by Hu Tao
Currently cpu.shares can only be configured by editing domains' xmls.
this series enables us to change cpu.shares from virsh cmd schedinfo
even when domain is inactive.
changes:
v3:
- add parameters --config, --live and --current.
v2:
- since v1 patches that delete all generated RPC files(by Daniel) and
that refactor remote generator(by Matthias) have gone into master
branch, which affects the series heavily. So rebase the series on
the latest code.
Hu Tao (4):
introduce virDomainSetSchedulerParametersFlags
qemu: introduce qemuSetSchedulerParametersFlags
remote: introduce remoteSetSchedulerParametersFlags
virsh: add parameters --live, --config and --current to cmd schedinfo
daemon/remote.c | 71 +++++++++++++++++++++++++++++++
include/libvirt/libvirt.h.in | 14 ++++++
python/generator.py | 1 +
src/driver.h | 8 ++++
src/libvirt.c | 64 ++++++++++++++++++++++++++++
src/libvirt_public.syms | 1 +
src/qemu/qemu_driver.c | 94 +++++++++++++++++++++++++++++++----------
src/remote/remote_driver.c | 69 ++++++++++++++++++++++++++++++
src/remote/remote_protocol.x | 9 ++++-
tools/virsh.c | 25 +++++++++++-
tools/virsh.pod | 6 ++-
11 files changed, 336 insertions(+), 26 deletions(-)
--
1.7.3.1
13 years, 6 months