[libvirt] PATCH: 7/7: Misc fixes

Daniel P. Berrange berrange at redhat.com
Thu Nov 20 18:03:56 UTC 2008


This patch contains a couple of misc fixes. HAL has separate 'block'
and 'storage' and 'volume' capabilities. Actual devices get the
'block' and 'storage' capability, while partitions get the 'block'
and 'volume' capability. 

We have no need to expose partitions in this API, since we already
have a explicit storage pool impl for this. In addition, DeviceKit
will not expose partition information.

There are also a number of misc devices HAL shows that don't have
any capabilities in libvirt XML yet. Wierd embeedded components
from the chipset, and and sound devices.  DeviceKit doesn't (currently)
expose any of these, and since we have no capability info for them
it is fairly pointless exposing them from the HAL impl in libvirt
either.

Thus, this patch  does a couple of things

 - Filters out any devices from HAL for which we have no capabilities
 - Removes the 'block' capability, and list the block device name
   in the 'storage' capability XML
 - In virsh nodedev-list, alphabetically sort device names

If we find we want some of these devices we're filtering, we can
easily re-add them in future - I prefer to expose too little info
for now, than too much.

Daniel

diff -r f99baad5c0da src/node_device_conf.c
--- a/src/node_device_conf.c	Thu Nov 20 17:48:12 2008 +0000
+++ b/src/node_device_conf.c	Thu Nov 20 17:48:16 2008 +0000
@@ -43,7 +43,6 @@
               "usb_device",
               "usb",
               "net",
-              "block",
               "scsi_host",
               "scsi",
               "storage");
@@ -280,10 +279,6 @@
                 virBufferVSprintf(&buf, "    <capability type='%s'/>\n", subtyp);
             }
             break;
-        case VIR_NODE_DEV_CAP_BLOCK:
-            virBufferVSprintf(&buf, "    <device>%s</device>\n",
-                              data->block.device);
-            break;
         case VIR_NODE_DEV_CAP_SCSI_HOST:
             virBufferVSprintf(&buf, "    <host>%d</host>\n",
                               data->scsi_host.host);
@@ -299,6 +294,8 @@
                                   data->scsi.type);
             break;
         case VIR_NODE_DEV_CAP_STORAGE:
+            virBufferVSprintf(&buf, "    <block>%s</blocke>\n",
+                              data->storage.block);
             if (data->storage.bus)
                 virBufferVSprintf(&buf, "    <bus>%s</bus>\n",
                                   data->storage.bus);
@@ -380,15 +377,13 @@
         VIR_FREE(data->net.interface);
         VIR_FREE(data->net.address);
         break;
-    case VIR_NODE_DEV_CAP_BLOCK:
-        VIR_FREE(data->block.device);
-        break;
     case VIR_NODE_DEV_CAP_SCSI_HOST:
         break;
     case VIR_NODE_DEV_CAP_SCSI:
         VIR_FREE(data->scsi.type);
         break;
     case VIR_NODE_DEV_CAP_STORAGE:
+        VIR_FREE(data->storage.block);
         VIR_FREE(data->storage.bus);
         VIR_FREE(data->storage.drive_type);
         VIR_FREE(data->storage.model);
diff -r f99baad5c0da src/node_device_conf.h
--- a/src/node_device_conf.h	Thu Nov 20 17:48:12 2008 +0000
+++ b/src/node_device_conf.h	Thu Nov 20 17:48:16 2008 +0000
@@ -34,7 +34,6 @@
     VIR_NODE_DEV_CAP_USB_DEV,		/* USB device */
     VIR_NODE_DEV_CAP_USB_INTERFACE,	/* USB interface */
     VIR_NODE_DEV_CAP_NET,		/* Network device */
-    VIR_NODE_DEV_CAP_BLOCK,		/* Block device */
     VIR_NODE_DEV_CAP_SCSI_HOST,		/* SCSI Host Bus Adapter */
     VIR_NODE_DEV_CAP_SCSI,		/* SCSI device */
     VIR_NODE_DEV_CAP_STORAGE,		/* Storage device */
@@ -107,9 +106,6 @@
             enum virNodeDevNetCapType subtype;  /* LAST -> no subtype */
         } net;
         struct {
-            char *device;
-        } block;
-        struct {
             unsigned host;
         } scsi_host;
         struct {
@@ -122,6 +118,7 @@
         struct {
             unsigned long long size;
             unsigned long long removable_media_size;
+            char *block;
             char *bus;
             char *drive_type;
             char *model;
diff -r f99baad5c0da src/node_device_devkit.c
--- a/src/node_device_devkit.c	Thu Nov 20 17:48:12 2008 +0000
+++ b/src/node_device_devkit.c	Thu Nov 20 17:48:16 2008 +0000
@@ -31,6 +31,7 @@
 #include "event.h"
 #include "memory.h"
 #include "uuid.h"
+#include "logging.h"
 
 #include "node_device.h"
 
@@ -133,12 +134,12 @@
 }
 
 
-static int gather_block_cap(DevkitDevice *dkdev,
-                          union _virNodeDevCapData *d)
+static int gather_storage_cap(DevkitDevice *dkdev,
+                              union _virNodeDevCapData *d)
 {
     const char *device = devkit_device_get_device_file(dkdev);
 
-    if (device && ((d->block.device = strdup(device)) == NULL))
+    if (device && ((d->storage.block = strdup(device)) == NULL))
         return -1;
 
     return 0;
@@ -158,7 +159,7 @@
     { "pci",        VIR_NODE_DEV_CAP_PCI_DEV,   gather_pci_cap },
     { "usb",        VIR_NODE_DEV_CAP_USB_DEV,   gather_usb_cap },
     { "net",        VIR_NODE_DEV_CAP_NET,       gather_net_cap },
-    { "block",      VIR_NODE_DEV_CAP_BLOCK,     gather_block_cap },
+    { "block",      VIR_NODE_DEV_CAP_STORAGE,   gather_storage_cap },
     // TODO: more caps!
 };
 
diff -r f99baad5c0da src/node_device_hal.c
--- a/src/node_device_hal.c	Thu Nov 20 17:48:12 2008 +0000
+++ b/src/node_device_hal.c	Thu Nov 20 17:48:16 2008 +0000
@@ -210,14 +210,6 @@
 }
 
 
-static int gather_block_cap(LibHalContext *ctx, const char *udi,
-                            union _virNodeDevCapData *d)
-{
-    (void)get_str_prop(ctx, udi, "block.device", &d->block.device);
-    return 0;
-}
-
-
 static int gather_scsi_host_cap(LibHalContext *ctx, const char *udi,
                                 union _virNodeDevCapData *d)
 {
@@ -242,6 +234,7 @@
                               union _virNodeDevCapData *d)
 {
     int val;
+    (void)get_str_prop(ctx, udi, "block.device", &d->storage.block);
     (void)get_str_prop(ctx, udi, "storage.bus", &d->storage.bus);
     (void)get_str_prop(ctx, udi, "storage.drive_type", &d->storage.drive_type);
     (void)get_str_prop(ctx, udi, "storage.model", &d->storage.model);
@@ -306,7 +299,6 @@
     { "usb",        VIR_NODE_DEV_CAP_USB_INTERFACE, gather_usb_cap },
     { "usb_device", VIR_NODE_DEV_CAP_USB_DEV,       gather_usb_device_cap },
     { "net",        VIR_NODE_DEV_CAP_NET,           gather_net_cap },
-    { "block",      VIR_NODE_DEV_CAP_BLOCK,         gather_block_cap },
     { "scsi_host",  VIR_NODE_DEV_CAP_SCSI_HOST,     gather_scsi_host_cap },
     { "scsi",       VIR_NODE_DEV_CAP_SCSI,          gather_scsi_cap },
     { "storage",    VIR_NODE_DEV_CAP_STORAGE,       gather_storage_cap },
@@ -436,6 +428,13 @@
 
     rv = gather_capabilities(ctx, udi, &dev->def->caps);
     if (rv != 0) goto failure;
+
+    if (dev->def->caps == NULL) {
+        virNodeDeviceDefFree(dev->def);
+        VIR_FREE(dev);
+        VIR_FREE(udi);
+        return;
+    }
 
     if (VIR_REALLOC_N(driverState->devs.objs, driverState->devs.count + 1) < 0)
         goto failure;
diff -r f99baad5c0da src/virsh.c
--- a/src/virsh.c	Thu Nov 20 17:48:12 2008 +0000
+++ b/src/virsh.c	Thu Nov 20 17:48:16 2008 +0000
@@ -4462,6 +4462,7 @@
         free(devices);
         return FALSE;
     }
+    qsort(&devices[0], num_devices, sizeof(char*), namesorter);
     for (i = 0; i < num_devices; i++) {
         vshPrint(ctl, "%s\n", devices[i]);
         free(devices[i]);

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list