how to add a new bus to lshal output
Olaf Hering
olh at suse.de
Mon Sep 10 05:43:29 PDT 2007
How exactly do I add a new bus to the lshal output?
Currenly the cdrom on legacy iSeries is not found because nothing
handles the sysfs bus 'vio'. I came up with the patch below, which is
copy&paste from other usage in hald/linux/device.c.
A hald-addon-storage process is launched if there is no media in the
tray. If there is one, the process is killed because reading (likely
from libvolume_id) takes a very long time.
For some reason, HAL_PROP_STORAGE_DRIVE_TYPE= is disk instead of cdrom.
Why is that? Where is HAL_PROP_STORAGE_DRIVE_TYPE coming from anyway?
The output looks very different when compared to something like PowerMac.
Maybe the kernel cant provide all the info hal expects.
udi = '/org/freedesktop/Hal/devices/vio_32'
info.bus = 'vio' (string)
info.callouts.add = {'hal-resmgr'} (string list)
info.interfaces = {'org.freedesktop.Hal.Device.resmgr'} (string list)
info.linux.driver = 'viocd' (string)
info.parent = '/org/freedesktop/Hal/devices/vio_vio' (string)
info.product = 'iSeries Virtual CD' (string)
info.subsystem = 'vio' (string)
info.udi = '/org/freedesktop/Hal/devices/vio_32' (string)
linux.hotplug_type = 2 (0x2) (int)
linux.subsystem = 'vio' (string)
linux.sysfs_path = '/sys/devices/vio/32' (string)
org.freedesktop.Hal.Device.resmgr.method_argnames = {'', ''} (string list)
org.freedesktop.Hal.Device.resmgr.method_execpaths = {'hal-resmgr-grant', 'hal-resmgr-revoke'} (string list)
org.freedesktop.Hal.Device.resmgr.method_names = {'Grant', 'Revoke'} (string list)
org.freedesktop.Hal.Device.resmgr.method_signatures = {'', ''} (string list)
resmgr.class = 'cdrom' (string)
storage.drive_type = 'cdrom' (string)
vio.bus_id = '32' (string)
vio.type = 'viocd' (string)
udi = '/org/freedesktop/Hal/devices/computer_storage'
block.device = '/dev/iseries/vcda' (string)
block.is_volume = false (bool)
block.major = 113 (0x71) (int)
block.minor = 0 (0x0) (int)
block.storage_device = '/org/freedesktop/Hal/devices/computer_storage' (string)
info.addons = {'hald-addon-storage'} (string list)
info.capabilities = {'storage', 'block'} (string list)
info.category = 'storage' (string)
info.parent = '/org/freedesktop/Hal/devices/vio_32' (string)
info.udi = '/org/freedesktop/Hal/devices/computer_storage' (string)
linux.hotplug_type = 3 (0x3) (int)
linux.sysfs_path = '/sys/block/iseries!vcda' (string)
storage.automount_enabled_hint = true (bool)
storage.bus = 'unknown' (string)
storage.drive_type = 'disk' (string)
storage.hotpluggable = false (bool)
storage.media_check_enabled = true (bool)
storage.model = '' (string)
storage.no_partitions_hint = false (bool)
storage.originating_device = '/org/freedesktop/Hal/devices/computer' (string)
storage.physical_device = '/org/freedesktop/Hal/devices/computer' (string)
storage.removable = true (bool)
storage.removable.media_available = false (bool)
storage.removable.support_async_notification = false (bool)
storage.requires_eject = false (bool)
storage.size = 0 (0x0) (uint64)
storage.vendor = '' (string)
---
hald/linux/device.c | 69 +++++++++++++++++++++++++++++++++++++
hald/linux/probing/probe-storage.c | 15 +++++++-
2 files changed, 83 insertions(+), 1 deletion(-)
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -2287,6 +2287,67 @@ mmc_compute_udi (HalDevice *d)
/*--------------------------------------------------------------------------------------------------------------*/
static HalDevice *
+vio_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path)
+{
+ HalDevice *d;
+ const gchar *devname;
+
+ d = hal_device_new ();
+ hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
+ hal_device_property_set_string (d, "info.subsystem", "vio");
+ hal_device_property_set_string (d, "info.bus", "vio");
+ if (parent_dev != NULL) {
+ hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
+ } else {
+ hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer");
+ }
+
+ hal_util_set_driver (d, "info.linux.driver", sysfs_path);
+
+ hal_device_property_set_string (d, "vio.bus_id",
+ hal_util_get_last_element (sysfs_path));
+
+ devname = hal_util_get_string_from_file (sysfs_path, "name");
+ if (devname != NULL) {
+ hal_device_property_set_string (d, "vio.type", devname);
+
+ if (strcmp (devname, "viocd") == 0) {
+ hal_device_property_set_string (d, "info.product", "iSeries Virtual CD");
+ hal_device_property_set_string (d, "storage.drive_type", "cdrom");
+ } else if (strcmp (devname, "viodasd") == 0) {
+ hal_device_property_set_string (d, "info.product", "iSeries Virtual Disk");
+ hal_device_property_set_string (d, "storage.drive_type", "disk");
+ } else if (strcmp (devname, "viotape") == 0) {
+ hal_device_property_set_string (d, "info.product", "iSeries Virtual Tape");
+ hal_device_property_set_string (d, "storage.drive_type", "tape");
+ } else {
+ char buf[64];
+ g_snprintf (buf, sizeof (buf), "iSeries Device (%s)", devname);
+ hal_device_property_set_string (d, "info.product", buf);
+ }
+ } else {
+ hal_device_property_set_string (d, "info.product", "iSeries Device (unknown)");
+ }
+
+ return d;
+}
+
+static gboolean
+vio_compute_udi (HalDevice *d)
+{
+ gchar udi[256];
+
+ hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/vio_%s",
+ hal_device_property_get_string (d, "vio.bus_id"));
+ hal_device_set_udi (d, udi);
+ hal_device_property_set_string (d, "info.udi", udi);
+ return TRUE;
+}
+
+/*--------------------------------------------------------------------------------------------------------------*/
+
+static HalDevice *
xen_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path)
{
HalDevice *d;
@@ -3584,6 +3645,13 @@ static DevHandler dev_handler_firewire =
.remove = dev_remove
};
+static DevHandler dev_handler_vio = {
+ .subsystem = "vio",
+ .add = vio_add,
+ .compute_udi = vio_compute_udi,
+ .remove = dev_remove
+};
+
static DevHandler dev_handler_xen = {
.subsystem = "xen",
.add = xen_add,
@@ -3652,6 +3720,7 @@ static DevHandler *dev_handlers[] = {
&dev_handler_scsi,
&dev_handler_mmc,
&dev_handler_ieee1394,
+ &dev_handler_vio,
&dev_handler_xen,
&dev_handler_ccw,
&dev_handler_ccwgroup,
--- a/hald/linux/probing/probe-storage.c
+++ b/hald/linux/probing/probe-storage.c
@@ -99,7 +99,7 @@ out:
int
main (int argc, char *argv[])
{
- int fd, num_excl_tries = 5;
+ int fd, cfd, num_excl_tries = 5;
int ret;
char *udi;
char *device_file;
@@ -108,11 +108,21 @@ main (int argc, char *argv[])
char *bus;
char *drive_type;
char *sysfs_path;
+ char mybuf[256];
dbus_bool_t only_check_for_fs;
LibHalChangeSet *cs;
cs = NULL;
+ cfd = open("/dev/console", O_RDWR);
+ if (cfd >= 0) {
+ drive_type = getenv ("HAL_PROP_STORAGE_DRIVE_TYPE");
+ device_file = getenv ("HAL_PROP_BLOCK_DEVICE");
+ sysfs_path = getenv ("HAL_PROP_LINUX_SYSFS_PATH");
+ snprintf(mybuf, sizeof(mybuf), "%s(%u): HAL_PROP_STORAGE_DRIVE_TYPE=%s HAL_PROP_BLOCK_DEVICE=%s HAL_PROP_LINUX_SYSFS_PATH=%s\n",
+ argv[0], getpid(), drive_type, device_file, sysfs_path);
+ write(cfd, mybuf, strlen(mybuf));
+ }
fd = -1;
/* hook in our debug into libvolume_id */
@@ -489,6 +499,9 @@ out:
libhal_ctx_shutdown (ctx, &error);
libhal_ctx_free (ctx);
}
+ snprintf(mybuf, sizeof(mybuf), "%s(%u): ret=%d\n", argv[0], getpid(), ret);
+ write(cfd, mybuf, strlen(mybuf));
+ close(cfd);
return ret;
}
More information about the hal
mailing list