[libvirt] [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink
by Jim Meyering
Without this patch, a symlink pointing to a 4096-byte name
could make this code write NUL into the byte beyond end of buffer:
if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) < 0) {
virReportSystemError(conn, errno,
_("cannot resolve driver link %s"), driver_link);
goto cleanup;
}
devpath[n] = '\0';
>From a075e207bc8fb279c43c9f4f43a960ffbd9a8a70 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 14 Dec 2009 12:05:38 +0100
Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink
* src/node_device/node_device_driver.c (update_driver_name): Leave
one byte for the trailing NUL we'll append.
---
src/node_device/node_device_driver.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index f083f16..eda5d5e 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -97,7 +97,7 @@ static int update_driver_name(virConnectPtr conn,
goto cleanup;
}
- if ((n = readlink(driver_link, devpath, sizeof devpath)) < 0) {
+ if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) < 0) {
virReportSystemError(conn, errno,
_("cannot resolve driver link %s"), driver_link);
goto cleanup;
--
1.6.6.rc2.275.g51e2d
14 years, 11 months
[libvirt] [PATCH] Allow versioned pc machines for QEmu
by Diego Elio Pettenò
* docs/schemas/domain.rng: add pattern for pc-0.10, pc-0.11 and similar
machine types
---
docs/schemas/domain.rng | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index d1d3efb..dd3f732 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -171,6 +171,9 @@
<value>xenfv</value>
<value>pc</value>
<value>isapc</value>
+ <data type="string">
+ <param name="pattern">pc-[0-9\.]+</param>
+ </data>
</choice>
</attribute>
</optional>
--
1.6.5.6
14 years, 11 months
[libvirt] [PATCH] Fix owner and group in example volume XML
by Matthew Booth
The owner and group in the documentation examples were confusingly given as
'0744'. They should be numeric uid and gid. Changed the examples to use the
default uid and gid assigned to qemu in F12.
* docs/formatstorage.html.in: Change example owner and group in volume XML
---
docs/formatstorage.html.in | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index ccf5a91..5c41c39 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -119,8 +119,8 @@
<target>
<path>/dev/disk/by-path</path>
<permissions>
- <owner>0744</owner>
- <group>0744</group>
+ <owner>107</owner>
+ <group>107</group>
<mode>0744</mode>
<label>virt_image_t</label>
</permissions>
@@ -244,8 +244,8 @@
<path>/var/lib/virt/images/sparse.img</path>
<format type='qcow2'/>
<permissions>
- <owner>0744</owner>
- <group>0744</group>
+ <owner>107</owner>
+ <group>107</group>
<mode>0744</mode>
<label>virt_image_t</label>
</permissions>
@@ -294,8 +294,8 @@
<path>/var/lib/virt/images/master.img</path>
<format>raw</format>
<permissions>
- <owner>0744</owner>
- <group>0744</group>
+ <owner>107</owner>
+ <group>107</group>
<mode>0744</mode>
<label>virt_image_t</label>
</permissions>
@@ -368,8 +368,8 @@
<target>
<path>/var/lib/virt/images/sparse.img</path>
<permissions>
- <owner>0744</owner>
- <group>0744</group>
+ <owner>107</owner>
+ <group>107</group>
<mode>0744</mode>
<label>virt_image_t</label>
</permissions>
--
1.6.5.2
14 years, 11 months
[libvirt] [PATCH] Eliminate failure to delete empty storage pools
by Laine Stump
virStorageBackendFileSystemDelete was incorrectly calling unlink() in
an attempt to remove a directory. It should be calling rmdir()
instead. (remove() would also work, but could potentially succeed on a
non-empty pool if the pool was a symlink to somewhere else).
---
src/storage/storage_backend_fs.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 16e4bd9..b7d4bd6 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -693,9 +693,9 @@ virStorageBackendFileSystemDelete(virConnectPtr conn,
{
/* XXX delete all vols first ? */
- if (unlink(pool->def->target.path) < 0) {
+ if (rmdir(pool->def->target.path) < 0) {
virReportSystemError(conn, errno,
- _("cannot unlink path '%s'"),
+ _("failed to remove pool '%s'"),
pool->def->target.path);
return -1;
}
--
1.6.6.rc2.5.g49666
14 years, 11 months
[libvirt] [PATCH] Fix use of virEventAddHandleImpl()
by Jiri Denemark
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/node_device/node_device_udev.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index cf23be1..6b6e244 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -37,7 +37,7 @@
#include "uuid.h"
#include "util.h"
#include "buf.h"
-#include "daemon/event.h"
+#include "event.h"
#define VIR_FROM_THIS VIR_FROM_NODEDEV
@@ -1526,10 +1526,10 @@ static int udevDeviceMonitorStartup(int privileged ATTRIBUTE_UNUSED)
* enumeration. The alternative is to register the callback after
* we enumerate, in which case we will fail to create any devices
* that appear while the enumeration is taking place. */
- if (virEventAddHandleImpl(udev_monitor_get_fd(udev_monitor),
- VIR_EVENT_HANDLE_READABLE,
- udevEventHandleCallback,
- NULL, NULL) == -1) {
+ if (virEventAddHandle(udev_monitor_get_fd(udev_monitor),
+ VIR_EVENT_HANDLE_READABLE,
+ udevEventHandleCallback,
+ NULL, NULL) == -1) {
ret = -1;
goto out;
}
--
1.6.5.6
14 years, 11 months
[libvirt] [PATCH] Cleanup temporary #define after use
by Matthew Booth
* src/qemu/qemu_driver.c: #undef LOOKUP_PTYS after use
---
src/qemu/qemu_driver.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7e55c23..4567a66 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1436,6 +1436,7 @@ qemudFindCharDevicePTYsMonitor(virConnectPtr conn,
LOOKUP_PTYS(vm->def->serials, vm->def->nserials, "serial");
LOOKUP_PTYS(vm->def->parallels, vm->def->nparallels, "parallel");
LOOKUP_PTYS(vm->def->channels, vm->def->nchannels, "channel");
+#undef LOOKUP_PTYS
return 0;
}
--
1.6.5.2
14 years, 11 months
[libvirt] [PATCH] nodedev: Add removable storage 'media_label' prop
by Cole Robinson
Provides the CDROM label for current media. Only implemented for the udev
backend.
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
docs/schemas/nodedev.rng | 5 +++++
src/conf/node_device_conf.c | 8 ++++++++
src/conf/node_device_conf.h | 1 +
src/node_device/node_device_udev.c | 5 +++++
tests/nodedevschemadata/DVD_with_media.xml | 16 ++++++++++++++++
tests/nodedevxml2xmltest.c | 1 +
6 files changed, 36 insertions(+), 0 deletions(-)
create mode 100644 tests/nodedevschemadata/DVD_with_media.xml
diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng
index 7060274..797b1af 100644
--- a/docs/schemas/nodedev.rng
+++ b/docs/schemas/nodedev.rng
@@ -314,6 +314,11 @@
<element name='media_size'>
<ref name='uint'/>
</element>
+ <optional>
+ <element name='media_label'>
+ <text/>
+ </element>
+ </optional>
</element>
</define>
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 6003ab1..a0d256c 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -422,6 +422,11 @@ char *virNodeDeviceDefFormat(virConnectPtr conn,
"</media_available>\n", avl ? 1 : 0);
virBufferVSprintf(&buf, " <media_size>%llu</media_size>\n",
data->storage.removable_media_size);
+ if (data->storage.media_label)
+ virBufferVSprintf(&buf,
+ " <media_label>%s</media_label>\n",
+ data->storage.media_label);
+
if (data->storage.logical_block_size > 0)
virBufferVSprintf(&buf, " <logical_block_size>%llu"
"</logical_block_size>\n",
@@ -575,6 +580,8 @@ virNodeDevCapStorageParseXML(virConnectPtr conn,
if (virXPathBoolean(conn, "count(./media_available[. = '1']) > 0", ctxt))
data->storage.flags |= VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE;
+ data->storage.media_label = virXPathString(conn, "string(./media_label[1])", ctxt);
+
val = 0;
if (virNodeDevCapsDefParseULongLong(conn, "number(./media_size[1])", ctxt, &val, def,
_("no removable media size supplied for '%s'"),
@@ -1431,6 +1438,7 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
VIR_FREE(data->storage.model);
VIR_FREE(data->storage.vendor);
VIR_FREE(data->storage.serial);
+ VIR_FREE(data->storage.media_label);
break;
case VIR_NODE_DEV_CAP_LAST:
/* This case is here to shutup the compiler */
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 7a20bd6..e409a76 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -154,6 +154,7 @@ struct _virNodeDevCapsDef {
char *model;
char *vendor;
char *serial;
+ char *media_label;
unsigned flags; /* virNodeDevStorageCapFlags bits */
} storage;
} data;
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 9b48052..c78643e 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -867,6 +867,11 @@ static int udevProcessCDROM(struct udev_device *device,
def->caps->data.storage.flags |=
VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE;
+ if (udevGetStringProperty(device, "ID_FS_LABEL",
+ &data->storage.media_label) == PROPERTY_ERROR) {
+ goto out;
+ }
+
if (udevGetUint64SysfsAttr(device,
"size",
&data->storage.num_blocks) == PROPERTY_ERROR) {
diff --git a/tests/nodedevschemadata/DVD_with_media.xml b/tests/nodedevschemadata/DVD_with_media.xml
new file mode 100644
index 0000000..673e88f
--- /dev/null
+++ b/tests/nodedevschemadata/DVD_with_media.xml
@@ -0,0 +1,16 @@
+<device>
+ <name>DVD_GCC_4247N</name>
+ <parent>pci_8086_27df_scsi_host_scsi_device_lun0</parent>
+ <capability type='storage'>
+ <block>/dev/sr0</block>
+ <bus>scsi</bus>
+ <drive_type>cdrom</drive_type>
+ <model>RW/DVD GCC-4247N</model>
+ <vendor>HL-DT-ST</vendor>
+ <capability type='removable'>
+ <media_available>1</media_available>
+ <media_size>12345678</media_size>
+ <media_label>Windows_XP_Label</media_label>
+ </capability>
+ </capability>
+</device>
diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c
index 7621212..bf8be7e 100644
--- a/tests/nodedevxml2xmltest.c
+++ b/tests/nodedevxml2xmltest.c
@@ -80,6 +80,7 @@ mymain(int argc, char **argv)
DO_TEST("computer");
DO_TEST("DVD_GCC_4247N");
+ DO_TEST("DVD_with_media");
DO_TEST("net_00_13_02_b9_f9_d3");
DO_TEST("net_00_15_58_2f_e9_55");
DO_TEST("pci_1002_71c4");
--
1.6.5.2
14 years, 11 months
[libvirt] [PATCH] expose SR IOV physical/virtual function relationships
by Dave Allan
Attached is a patch that exposes the relationships between physical and
virtual functions on SR IOV capable devices.
Dave
>From cc5b72f99cd472aa0c07d8115e0abc970feab704 Mon Sep 17 00:00:00 2001
From: David Allan <dallan(a)redhat.com>
Date: Mon, 30 Nov 2009 15:58:47 -0500
Subject: [PATCH 1/2] Add SR IOV physical and virtual function relationships
---
src/conf/node_device_conf.c | 16 ++++
src/conf/node_device_conf.h | 3 +
src/node_device/node_device_driver.h | 10 +++
src/node_device/node_device_hal.c | 6 ++
src/node_device/node_device_linux_sysfs.c | 122 ++++++++++++++++++++++++++++-
5 files changed, 156 insertions(+), 1 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 6003ab1..4b5d17c 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -246,6 +246,7 @@ char *virNodeDeviceDefFormat(virConnectPtr conn,
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
virNodeDevCapsDefPtr caps;
+ unsigned int i = 0;
char *tmp;
virBufferAddLit(&buf, "<device>\n");
@@ -318,6 +319,16 @@ char *virNodeDeviceDefFormat(virConnectPtr conn,
data->pci_dev.vendor_name);
else
virBufferAddLit(&buf, " />\n");
+ if (data->pci_dev.physical_function) {
+ virBufferEscapeString(&buf, " <physical_function>%s</physical_function>\n",
+ data->pci_dev.physical_function);
+ }
+ if (data->pci_dev.num_virtual_functions > 0) {
+ for (i = 0 ; i < data->pci_dev.num_virtual_functions ; i++) {
+ virBufferEscapeString(&buf, " <virtual_function>%s</virtual_function>\n",
+ data->pci_dev.virtual_functions[i]);
+ }
+ }
break;
case VIR_NODE_DEV_CAP_USB_DEV:
virBufferVSprintf(&buf, " <bus>%d</bus>\n", data->usb_dev.bus);
@@ -1387,6 +1398,7 @@ out:
void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
{
+ int i = 0;
union _virNodeDevCapData *data = &caps->data;
switch (caps->type) {
@@ -1402,6 +1414,10 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
case VIR_NODE_DEV_CAP_PCI_DEV:
VIR_FREE(data->pci_dev.product_name);
VIR_FREE(data->pci_dev.vendor_name);
+ VIR_FREE(data->pci_dev.physical_function);
+ for (i = 0 ; i < data->pci_dev.num_virtual_functions ; i++) {
+ VIR_FREE(data->pci_dev.virtual_functions[i]);
+ }
break;
case VIR_NODE_DEV_CAP_USB_DEV:
VIR_FREE(data->usb_dev.product_name);
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 7a20bd6..11b7539 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -105,6 +105,9 @@ struct _virNodeDevCapsDef {
unsigned class;
char *product_name;
char *vendor_name;
+ char *physical_function;
+ char **virtual_functions;
+ unsigned num_virtual_functions;
} pci_dev;
struct {
unsigned bus;
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index 4f0822c..d358276 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -61,6 +61,14 @@ int check_fc_host_linux(union _virNodeDevCapData *d);
#define check_vport_capable(d) check_vport_capable_linux(d)
int check_vport_capable_linux(union _virNodeDevCapData *d);
+#define get_physical_function(s,d) get_physical_function_linux(s,d)
+int get_physical_function_linux(const char *sysfs_path,
+ union _virNodeDevCapData *d);
+
+#define get_virtual_functions(s,d) get_virtual_functions_linux(s,d)
+int get_virtual_functions_linux(const char *sysfs_path,
+ union _virNodeDevCapData *d);
+
#define read_wwn(host, file, wwn) read_wwn_linux(host, file, wwn)
int read_wwn_linux(int host, const char *file, char **wwn);
@@ -68,6 +76,8 @@ int read_wwn_linux(int host, const char *file, char **wwn);
#define check_fc_host(d)
#define check_vport_capable(d)
+#define get_physical_function(sysfs_path, d)
+#define get_virtual_functions(sysfs_path, d)
#define read_wwn(host, file, wwn)
#endif /* __linux__ */
diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index 31c1764..7cb931e 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -145,14 +145,20 @@ static int gather_pci_cap(LibHalContext *ctx, const char *udi,
(void)virStrToLong_ui(p+1, &p, 16, &d->pci_dev.slot);
(void)virStrToLong_ui(p+1, &p, 16, &d->pci_dev.function);
}
+
+ get_physical_function(sysfs_path, d);
+ get_virtual_functions(sysfs_path, d);
+
VIR_FREE(sysfs_path);
}
+
(void)get_int_prop(ctx, udi, "pci.vendor_id", (int *)&d->pci_dev.vendor);
if (get_str_prop(ctx, udi, "pci.vendor", &d->pci_dev.vendor_name) != 0)
(void)get_str_prop(ctx, udi, "info.vendor", &d->pci_dev.vendor_name);
(void)get_int_prop(ctx, udi, "pci.product_id", (int *)&d->pci_dev.product);
if (get_str_prop(ctx, udi, "pci.product", &d->pci_dev.product_name) != 0)
(void)get_str_prop(ctx, udi, "info.product", &d->pci_dev.product_name);
+
return 0;
}
diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c
index b7cf782..6b9738c 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -29,6 +29,7 @@
#include "virterror_internal.h"
#include "memory.h"
#include "logging.h"
+#include <dirent.h>
#define VIR_FROM_THIS VIR_FROM_NODEDEV
@@ -70,7 +71,7 @@ int read_wwn_linux(int host, const char *file, char **wwn)
char buf[64];
if (open_wwn_file(LINUX_SYSFS_FC_HOST_PREFIX, host, file, &fd) < 0) {
- goto out;
+ goto out;
}
memset(buf, 0, sizeof(buf));
@@ -184,4 +185,123 @@ out:
return retval;
}
+
+static int get_sriov_function(const char *device_link,
+ char **pci_device)
+{
+ char *device_path = NULL, *device_name = NULL;
+ char errbuf[64];
+ int ret = -1;
+
+ VIR_DEBUG("Attempting to resolve device path from device link '%s'\n",
+ device_link);
+
+ if (!virFileExists(device_link)) {
+
+ VIR_DEBUG("SR IOV function link '%s' does not exist\n", device_link);
+ /* Not an SR IOV device, not an error, either. */
+ ret = 0;
+ goto out;
+
+ }
+
+ device_path = realpath(device_link, device_path);
+ if (device_path == NULL) {
+ memset(errbuf, '\0', sizeof(errbuf));
+ VIR_ERROR("Failed to resolve device link '%s': '%s'\n", device_link,
+ strerror_r(errno, errbuf, sizeof(errbuf)));
+ goto out;
+ }
+
+ VIR_DEBUG("SR IOV device path is '%s'\n", device_path);
+ device_name = basename(device_path);
+ *pci_device = strdup(device_name);
+ if (*pci_device == NULL) {
+ VIR_ERROR0("Failed to allocate memory for PCI device name\n");
+ goto out;
+ }
+
+ VIR_DEBUG("SR IOV function is '%s'\n", *pci_device);
+ ret = 0;
+
+out:
+ VIR_FREE(device_path);
+ return ret;
+}
+
+
+int get_physical_function_linux(const char *sysfs_path,
+ union _virNodeDevCapData *d ATTRIBUTE_UNUSED)
+{
+ int ret = -1;
+ char *device_link = NULL;
+
+ VIR_DEBUG("Attempting to get SR IOV physical function for device "
+ "with sysfs path '%s'\n", sysfs_path);
+
+ if (virBuildPath(&device_link, sysfs_path, "physfn") == -1) {
+ virReportOOMError(NULL);
+ } else {
+ ret = get_sriov_function(device_link, &d->pci_dev.physical_function);
+ }
+
+ VIR_FREE(device_link);
+ return ret;
+}
+
+
+int get_virtual_functions_linux(const char *sysfs_path,
+ union _virNodeDevCapData *d)
+{
+ int ret = -1;
+ DIR *dir = NULL;
+ struct dirent *entry = NULL;
+ char *device_link = NULL;
+
+ VIR_DEBUG("Attempting to get SR IOV virtual functions for device"
+ "with sysfs path '%s'\n", sysfs_path);
+
+ dir = opendir(sysfs_path);
+ if (dir == NULL) {
+ goto out;
+ }
+
+ while ((entry = readdir(dir))) {
+ if (STRPREFIX(entry->d_name, "virtfn")) {
+ /* This local is just to avoid lines of code much > 80 col. */
+ unsigned int *num_funcs = &d->pci_dev.num_virtual_functions;
+
+ if (virBuildPath(&device_link, sysfs_path, entry->d_name) == -1) {
+ virReportOOMError(NULL);
+ goto out;
+ }
+
+ VIR_DEBUG("Number of virtual functions: %d\n", *num_funcs);
+ if (VIR_REALLOC_N(d->pci_dev.virtual_functions, (*num_funcs) + 1) != 0) {
+ virReportOOMError(NULL);
+ goto out;
+ }
+
+ if (get_sriov_function(device_link,
+ &d->pci_dev.virtual_functions[*num_funcs]) != 0) {
+ VIR_ERROR("Failed to get SR IOV function from device link '%s'\n",
+ device_link);
+ goto out;
+ } else {
+ (*num_funcs)++;
+ }
+
+ VIR_FREE(device_link);
+ }
+ }
+
+ closedir(dir);
+
+ ret = 0;
+
+out:
+ VIR_FREE(device_link);
+ return 0;
+}
+
#endif /* __linux__ */
--
1.6.5.2
14 years, 11 months