hal: Branch 'master' - 8 commits
Rob Taylor
robtaylor at kemper.freedesktop.org
Wed Mar 12 12:16:11 PDT 2008
hald/device.c | 106 +++++++++---
hald/device_store.c | 156 ++++++++++++++---
hald/device_store.h | 2
hald/freebsd/hf-util.c | 2
hald/hald.c | 29 +++
hald/hald.h | 2
hald/hald_dbus.c | 2
hald/hald_marshal.list | 1
hald/linux/acpi.c | 14 -
hald/linux/apm.c | 24 +-
hald/linux/blockdev.c | 60 +++---
hald/linux/coldplug.c | 230 ++++++++++++++------------
hald/linux/device.c | 360 ++++++++++++++++++++---------------------
hald/linux/hotplug.c | 130 +++++++++++---
hald/linux/hotplug.h | 3
hald/linux/osspec.c | 7
hald/linux/pmu.c | 16 -
hald/solaris/devinfo.c | 8
hald/solaris/devinfo_storage.c | 48 ++---
hald/solaris/devinfo_usb.c | 16 -
hald/util.c | 49 +++--
hald/util.h | 4
22 files changed, 794 insertions(+), 475 deletions(-)
New commits:
commit 84bd77044698784c976d5a1c06c13f75ec900c17
Author: Rob Taylor <robtaylor at sultana.(none)>
Date: Thu Mar 6 13:49:21 2008 +0000
compute udis that are unique in the gdl and tdl
Introduces hald_compute_udi which computes a udi thats unique in both the
tdl and gdl and uses it everywhere relvent. This is necessary when we're
processing events in parallel as otherwise its possible to get a race condition
with two devices added with the same name. As part of this patch,
hal_util_compute_udi grwos a varargs version and no longer makes the computer
udi unique. I've also added a hal_util_make_udi_unique for use in those places
where hal_util_compute_udi was only used to check a udi was unique when
inserting into the gdl.
diff --git a/hald/freebsd/hf-util.c b/hald/freebsd/hf-util.c
index 8d6b07f..fe9c9ee 100644
--- a/hald/freebsd/hf-util.c
+++ b/hald/freebsd/hf-util.c
@@ -292,7 +292,7 @@ hf_device_set_full_udi (HalDevice *device, const char *format, ...)
requested_udi = g_strdup_vprintf(format, args);
va_end(args);
- hal_util_compute_udi(pending_gdl, actual_udi, sizeof(actual_udi), "%s", requested_udi);
+ hal_util_make_udi_unique (pending_gdl, actual_udi, sizeof(actual_udi), requested_udi);
hf_pending_gdl_free(pending_gdl);
g_free(requested_udi);
diff --git a/hald/hald.c b/hald/hald.c
index 8a160d5..a28d22e 100644
--- a/hald/hald.c
+++ b/hald/hald.c
@@ -254,6 +254,35 @@ hald_get_tdl (void)
return temporary_device_list;
}
+void
+hald_compute_udi (gchar *dst, gsize dstsize, const gchar *format, ...)
+{
+ int i;
+ char buf[256];
+ va_list args;
+
+ va_start (args, format);
+ hal_util_compute_udi_valist (hald_get_gdl (), dst, dstsize, format, args);
+ va_end (args);
+
+ if (hal_device_store_find (hald_get_gdl (), dst) == NULL &&
+ hal_device_store_find (hald_get_tdl (), dst) == NULL)
+ goto out;
+
+ for (i = 0; ; i++) {
+ g_snprintf (buf, sizeof(buf), "%s_%d", dst, i);
+ if (hal_device_store_find (hald_get_gdl (), buf) == NULL &&
+ hal_device_store_find (hald_get_tdl (), buf) == NULL) {
+ g_strlcpy (dst, buf, dstsize);
+ goto out;
+ }
+ }
+
+out:
+ ;
+
+}
+
/**
* usage:
*
diff --git a/hald/hald.h b/hald/hald.h
index 1b60e03..7c55e62 100644
--- a/hald/hald.h
+++ b/hald/hald.h
@@ -47,6 +47,8 @@ extern PolKitContext *pk_context;
HalDeviceStore *hald_get_gdl (void);
HalDeviceStore *hald_get_tdl (void);
+void hald_compute_udi (gchar *dst, gsize dstsize, const gchar *format, ...);
+
void property_atomic_update_begin ();
void property_atomic_update_end ();
diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index c56fe9e..28195e1 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -3854,7 +3854,7 @@ manager_commit_to_gdl (DBusConnection * connection, DBusMessage * message, dbus_
}
/* sanity check & avoid races */
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof udi, "%s", udi0);
+ hal_util_make_udi_unique (hald_get_gdl (), udi, sizeof udi, udi0);
if (hal_device_store_find (hald_get_gdl (), udi)) {
/* loose it */
diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
index af5145c..1c8a3e7 100644
--- a/hald/linux/acpi.c
+++ b/hald/linux/acpi.c
@@ -1006,9 +1006,9 @@ static gboolean
acpi_generic_compute_udi (HalDevice *d, ACPIDevHandler *handler)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/acpi_%s",
- hal_util_get_last_element (hal_device_property_get_string (d, "linux.acpi_path")));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/acpi_%s",
+ hal_util_get_last_element (hal_device_property_get_string (d, "linux.acpi_path")));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
diff --git a/hald/linux/apm.c b/hald/linux/apm.c
index 7b49fb2..06efe46 100644
--- a/hald/linux/apm.c
+++ b/hald/linux/apm.c
@@ -348,16 +348,16 @@ apm_generic_compute_udi (HalDevice *d, APMDevHandler *handler)
gchar udi[256];
if (handler->apm_type == APM_TYPE_BATTERY ) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/apm_battery");
-
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/apm_battery");
+
} else if (handler->apm_type == APM_TYPE_AC_ADAPTER ) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/apm_ac_adapter");
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/apm_ac_adapter");
} else {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/apm_%d",
- hal_device_property_get_int (d, "info.category"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/apm_%d",
+ hal_device_property_get_int (d, "info.category"));
}
hal_device_set_udi (d, udi);
diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c
index decacff..ffdda66 100644
--- a/hald/linux/blockdev.c
+++ b/hald/linux/blockdev.c
@@ -77,23 +77,23 @@ blockdev_compute_udi (HalDevice *d)
uuid = hal_device_property_get_string (d, "volume.uuid");
if (uuid != NULL && strlen (uuid) > 0) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/volume_uuid_%s", uuid);
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/volume_uuid_%s", uuid);
} else if (volumelabel != NULL && strlen (volumelabel) > 0) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/volume_label_%s", volumelabel);
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/volume_label_%s", volumelabel);
} else if (hal_device_property_get_bool(d, "volume.is_disc") &&
hal_device_property_get_bool(d, "volume.disc.is_blank")) {
/* this should be a empty CD/DVD */
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/volume_empty_%s",
- hal_device_property_get_string (d, "volume.disc.type"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/volume_empty_%s",
+ hal_device_property_get_string (d, "volume.disc.type"));
} else {
/* fallback to partition number, size */
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/volume_part%d_size_%lld",
- hal_device_property_get_int (d, "volume.partition.number"),
- hal_device_property_get_uint64 (d, "volume.size"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/volume_part%d_size_%lld",
+ hal_device_property_get_int (d, "volume.partition.number"),
+ hal_device_property_get_uint64 (d, "volume.size"));
}
g_free(volumelabel);
} else {
@@ -108,22 +108,22 @@ blockdev_compute_udi (HalDevice *d)
type = hal_device_property_get_string (d, "storage.drive_type");
if (serial != NULL) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/storage_serial_%s",
- serial);
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/storage_serial_%s",
+ serial);
} else if ((model != NULL) && (strlen(model) != 0) ) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/storage_model_%s",
- model);
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/storage_model_%s",
+ model);
} else if ((bus != NULL) && (type != NULL)){
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_storage_%s_%s",
- hal_device_property_get_string (d, "storage.originating_device"),
- bus, type);
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_storage_%s_%s",
+ hal_device_property_get_string (d, "storage.originating_device"),
+ bus, type);
} else {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_storage",
- hal_device_property_get_string (d, "storage.originating_device"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_storage",
+ hal_device_property_get_string (d, "storage.originating_device"));
}
}
diff --git a/hald/linux/device.c b/hald/linux/device.c
index 654d5e6..dde7c43 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -390,9 +390,9 @@ input_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_logicaldev_input",
- hal_device_property_get_string (d, "info.parent"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_logicaldev_input",
+ hal_device_property_get_string (d, "info.parent"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -470,18 +470,18 @@ bluetooth_compute_udi (HalDevice *d)
gchar udi[256];
if (hal_device_has_capability (d, "bluetooth_acl")) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx",
- hal_device_property_get_uint64 (d, "bluetooth_acl.address"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx",
+ hal_device_property_get_uint64 (d, "bluetooth_acl.address"));
} else if (hal_device_has_capability (d, "bluetooth_sco")) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx",
- hal_device_property_get_uint64 (d, "bluetooth_acl.address"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx",
+ hal_device_property_get_uint64 (d, "bluetooth_acl.address"));
} else {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_bluetooth_hci_%0llx",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_uint64 (d, "bluetooth_hci.address"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_bluetooth_hci_%0llx",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_uint64 (d, "bluetooth_hci.address"));
}
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -650,9 +650,9 @@ net_compute_udi (HalDevice *d)
/* Need to fall back to something else if mac not available. */
id = hal_util_get_last_element(hal_device_property_get_string(d, "net.originating_device"));
}
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/net_%s",
- id);
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/net_%s",
+ id);
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -687,9 +687,9 @@ scsi_generic_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_scsi_generic",
- hal_device_property_get_string (d, "info.parent"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_scsi_generic",
+ hal_device_property_get_string (d, "info.parent"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -811,9 +811,9 @@ scsi_host_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_scsi_host",
- hal_device_property_get_string (d, "info.parent"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_scsi_host",
+ hal_device_property_get_string (d, "info.parent"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -883,19 +883,19 @@ usbclass_compute_udi (HalDevice *d)
gchar udi[256];
if (hal_device_has_capability (d, "hiddev")) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_hiddev",
- hal_device_property_get_string (d, "info.parent"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_hiddev",
+ hal_device_property_get_string (d, "info.parent"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
} else if (hal_device_has_capability (d, "printer")) {
const char *serial;
serial = hal_device_property_get_string (d, "printer.serial");
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_printer_%s",
- hal_device_property_get_string (d, "info.parent"),
- serial != NULL ? serial : "noserial");
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_printer_%s",
+ hal_device_property_get_string (d, "info.parent"),
+ serial != NULL ? serial : "noserial");
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
}
@@ -932,8 +932,8 @@ usbraw_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_usbraw",
- hal_device_property_get_string (d, "info.parent"));
+ hald_compute_udi (udi, sizeof (udi), "%s_usbraw",
+ hal_device_property_get_string (d, "info.parent"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -983,8 +983,8 @@ video4linux_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_video4linux",
- hal_device_property_get_string (d, "info.parent"));
+ hald_compute_udi (udi, sizeof (udi), "%s_video4linux",
+ hal_device_property_get_string (d, "info.parent"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -1021,8 +1021,8 @@ dvb_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_dvb",
- hal_device_property_get_string (d, "info.parent"));
+ hald_compute_udi (udi, sizeof (udi), "%s_dvb",
+ hal_device_property_get_string (d, "info.parent"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -1312,41 +1312,41 @@ sound_compute_udi (HalDevice *d)
if (hal_device_has_property(d, "sound.card")) {
/* don't include card number as it may not be persistent across reboots */
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_sound_card_%i",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_string (d, "sound.card"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_sound_card_%i",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_string (d, "sound.card"));
} else if (hal_device_has_property(d, "alsa.card")) {
/* don't include card number as it may not be persistent across reboots */
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_alsa_%s_%i",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_string (d, "alsa.type"),
- hal_device_property_get_int (d, "alsa.device"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_alsa_%s_%i",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_string (d, "alsa.type"),
+ hal_device_property_get_int (d, "alsa.device"));
} else if (hal_device_has_property(d, "oss.card")) {
/* don't include card number as it may not be persistent across reboots */
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_oss_%s_%i",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_string (d, "oss.type"),
- hal_device_property_get_int (d, "oss.device"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_oss_%s_%i",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_string (d, "oss.type"),
+ hal_device_property_get_int (d, "oss.device"));
} else if (hal_device_has_property(d, "alsa.type")) {
/* handle global ALSA devices */
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_alsa_%s",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_string (d, "alsa.type"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_alsa_%s",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_string (d, "alsa.type"));
} else if (hal_device_has_property(d, "oss.type")) {
/* handle global OSS devices */
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_oss_%s",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_string (d, "oss.type"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_oss_%s",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_string (d, "oss.type"));
} else {
/* fallback */
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_sound_unknown",
- hal_device_property_get_string (d, "info.parent"));
- }
+ hald_compute_udi (udi, sizeof (udi), "%s_sound_unknown",
+ hal_device_property_get_string (d, "info.parent"));
+ }
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -1437,11 +1437,11 @@ serial_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_serial_%s_%d",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_string (d, "serial.type"),
- hal_device_property_get_int (d, "serial.port"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_serial_%s_%d",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_string (d, "serial.type"),
+ hal_device_property_get_int (d, "serial.port"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -1489,9 +1489,9 @@ tape_compute_udi (HalDevice *d)
(d, "linux.sysfs_path"));
if (!sysfs_name)
return FALSE;
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/tape_%s",
- sysfs_name);
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/tape_%s",
+ sysfs_name);
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -1536,9 +1536,9 @@ mmc_host_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_mmc_host",
- hal_device_property_get_string (d, "info.parent"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_mmc_host",
+ hal_device_property_get_string (d, "info.parent"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -1627,10 +1627,10 @@ pci_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/pci_%x_%x",
- hal_device_property_get_int (d, "pci.vendor_id"),
- hal_device_property_get_int (d, "pci.product_id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/pci_%x_%x",
+ hal_device_property_get_int (d, "pci.vendor_id"),
+ hal_device_property_get_int (d, "pci.product_id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -1838,20 +1838,20 @@ usb_compute_udi (HalDevice *d)
gchar udi[256];
if (hal_device_has_property (d, "usb.interface.number")) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_if%d",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_int (d, "usb.interface.number"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_if%d",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_int (d, "usb.interface.number"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
} else {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/usb_device_%x_%x_%s",
- hal_device_property_get_int (d, "usb_device.vendor_id"),
- hal_device_property_get_int (d, "usb_device.product_id"),
- hal_device_has_property (d, "usb_device.serial") ?
- hal_device_property_get_string (d, "usb_device.serial") :
- "noserial");
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/usb_device_%x_%x_%s",
+ hal_device_property_get_int (d, "usb_device.vendor_id"),
+ hal_device_property_get_int (d, "usb_device.product_id"),
+ hal_device_has_property (d, "usb_device.serial") ?
+ hal_device_property_get_string (d, "usb_device.serial") :
+ "noserial");
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
}
@@ -1899,11 +1899,11 @@ ide_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_ide_%d_%d",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_int (d, "ide.host"),
- hal_device_property_get_int (d, "ide.channel"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_ide_%d_%d",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_int (d, "ide.host"),
+ hal_device_property_get_int (d, "ide.channel"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -1993,9 +1993,9 @@ pnp_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/pnp_%s",
- hal_device_property_get_string (d, "pnp.id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/pnp_%s",
+ hal_device_property_get_string (d, "pnp.id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -2045,9 +2045,9 @@ platform_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/platform_%s",
- hal_device_property_get_string (d, "platform.id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/platform_%s",
+ hal_device_property_get_string (d, "platform.id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -2105,10 +2105,10 @@ serio_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_%s",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_string (d, "serio.description"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_%s",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_string (d, "serio.description"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -2183,10 +2183,10 @@ pcmcia_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/pcmcia_%d_%d",
- hal_device_property_get_int (d, "pcmcia.manfid1"),
- hal_device_property_get_int (d, "pcmcia.manfid2"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/pcmcia_%d_%d",
+ hal_device_property_get_int (d, "pcmcia.manfid1"),
+ hal_device_property_get_int (d, "pcmcia.manfid2"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -2275,10 +2275,10 @@ scsi_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_scsi_device_lun%d",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_int (d, "scsi.lun"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_scsi_device_lun%d",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_int (d, "scsi.lun"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -2369,10 +2369,10 @@ mmc_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_mmc_card_rca%d",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_int (d, "mmc.rca"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_mmc_card_rca%d",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_int (d, "mmc.rca"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -2426,10 +2426,10 @@ sdio_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_sdio%d",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_int (d, "sdio.card_id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_sdio%d",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_int (d, "sdio.card_id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -2488,9 +2488,9 @@ xen_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/xen_%s",
- hal_device_property_get_string (d, "xen.bus_id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/xen_%s",
+ hal_device_property_get_string (d, "xen.bus_id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -2569,9 +2569,9 @@ ieee1394_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/ieee1394_guid_%0llx",
- hal_device_property_get_uint64 (d, "ieee1394.guid"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/ieee1394_guid_%0llx",
+ hal_device_property_get_uint64 (d, "ieee1394.guid"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -2709,14 +2709,14 @@ firewire_compute_udi (HalDevice *d)
gchar udi[256];
if (hal_device_has_capability (d, "ieee1394")) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/ieee1394_guid%0llx",
- hal_device_property_get_uint64 (d, "ieee1394.guid"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/ieee1394_guid%0llx",
+ hal_device_property_get_uint64 (d, "ieee1394.guid"));
} else {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_unit%d",
- hal_device_property_get_string (d, "ieee1394_unit.originating_device"),
- hal_device_property_get_int (d, "ieee1394_unit.unit_index"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_unit%d",
+ hal_device_property_get_string (d, "ieee1394_unit.originating_device"),
+ hal_device_property_get_int (d, "ieee1394_unit.unit_index"));
}
hal_device_set_udi (d, udi);
@@ -2870,10 +2870,10 @@ ccw_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/ccw_%s",
- hal_device_property_get_string
- (d, "ccw.bus_id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/ccw_%s",
+ hal_device_property_get_string
+ (d, "ccw.bus_id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -3012,10 +3012,10 @@ ccwgroup_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/ccwgroup_%s",
- hal_device_property_get_string
- (d, "ccwgroup.bus_id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/ccwgroup_%s",
+ hal_device_property_get_string
+ (d, "ccwgroup.bus_id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -3068,10 +3068,10 @@ iucv_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/iucv_%s",
- hal_device_property_get_string
- (d, "iucv.bus_id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/iucv_%s",
+ hal_device_property_get_string
+ (d, "iucv.bus_id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -3110,9 +3110,9 @@ backlight_compute_udi (HalDevice *d)
dir = hal_device_property_get_string (d, "linux.sysfs_path");
name = hal_util_get_last_element(dir);
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_backlight",
- hal_device_property_get_string (d, "info.parent"));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_backlight",
+ hal_device_property_get_string (d, "info.parent"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -3494,17 +3494,17 @@ power_supply_compute_udi (HalDevice *d)
name = hal_util_get_last_element(dir);
if (name)
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_power_supply_%s_%s",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_string (d, "info.category"),
- name);
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_power_supply_%s_%s",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_string (d, "info.category"),
+ name);
else
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_power_supply_%s",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_string (d, "info.category"));
-
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_power_supply_%s",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_string (d, "info.category"));
+
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -3553,11 +3553,11 @@ drm_compute_udi (HalDevice *d)
name = hal_util_get_last_element(dir);
/* generate e.g.: /org/freedesktop/Hal/devices/pci_8086_2a02_drm_i915_card0 */
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_drm_%s_%s",
- hal_device_property_get_string (d, "info.parent"),
- hal_device_property_get_string (d, "drm.dri_library"),
- name);
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_drm_%s_%s",
+ hal_device_property_get_string (d, "info.parent"),
+ hal_device_property_get_string (d, "drm.dri_library"),
+ name);
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -3601,9 +3601,9 @@ ps3_system_bus_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/ps3_system_bus_%s",
- hal_device_property_get_string (d, "ps3_system_bus.id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/ps3_system_bus_%s",
+ hal_device_property_get_string (d, "ps3_system_bus.id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -3646,9 +3646,9 @@ virtio_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/virtio_%s",
- hal_device_property_get_string (d, "virtio.id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/virtio_%s",
+ hal_device_property_get_string (d, "virtio.id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -3702,15 +3702,15 @@ vio_compute_udi (HalDevice *d)
type = hal_device_property_get_string (d, "vio.type");
if (type) {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/vio_%s_%s",
- type,
- hal_device_property_get_string (d, "vio.id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/vio_%s_%s",
+ type,
+ hal_device_property_get_string (d, "vio.id"));
} else {
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/vio_%s",
- hal_device_property_get_string (d, "vio.id"));
- }
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/vio_%s",
+ hal_device_property_get_string (d, "vio.id"));
+ }
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
@@ -3752,9 +3752,9 @@ pseudo_compute_udi (HalDevice *d)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/pseudo",
- hal_device_property_get_string (d, "platform.id"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/pseudo",
+ hal_device_property_get_string (d, "platform.id"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
diff --git a/hald/linux/pmu.c b/hald/linux/pmu.c
index c080ed3..67ff785 100644
--- a/hald/linux/pmu.c
+++ b/hald/linux/pmu.c
@@ -212,8 +212,8 @@ static gboolean
pmu_lid_compute_udi (HalDevice *d, PMUDevHandler *handler)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/pmu_lid");
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/pmu_lid");
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -223,8 +223,8 @@ static gboolean
pmu_laptop_panel_compute_udi (HalDevice *d, PMUDevHandler *handler)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/pmu_lcd");
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/pmu_lcd");
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
@@ -400,10 +400,10 @@ static gboolean
pmu_generic_compute_udi (HalDevice *d, PMUDevHandler *handler)
{
gchar udi[256];
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices/pmu_%s_%d",
- hal_util_get_last_element (hal_device_property_get_string (d, "linux.pmu_path")),
- hal_device_property_get_int (d, "linux.pmu_type"));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices/pmu_%s_%d",
+ hal_util_get_last_element (hal_device_property_get_string (d, "linux.pmu_path")),
+ hal_device_property_get_int (d, "linux.pmu_type"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
return TRUE;
diff --git a/hald/solaris/devinfo.c b/hald/solaris/devinfo.c
index e82317f..b6a2ddc 100644
--- a/hald/solaris/devinfo.c
+++ b/hald/solaris/devinfo.c
@@ -95,10 +95,10 @@ devinfo_set_default_properties (HalDevice *d, HalDevice *parent, di_node_t node,
hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/local");
}
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "/org/freedesktop/Hal/devices%s_%d",
- devfs_path,
- di_instance (node));
+ hald_compute_udi (udi, sizeof (udi),
+ "/org/freedesktop/Hal/devices%s_%d",
+ devfs_path,
+ di_instance (node));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
diff --git a/hald/solaris/devinfo_storage.c b/hald/solaris/devinfo_storage.c
index 4e1e9b1..61f50aa 100644
--- a/hald/solaris/devinfo_storage.c
+++ b/hald/solaris/devinfo_storage.c
@@ -209,8 +209,9 @@ devinfo_ide_storage_add(HalDevice *grampa, HalDevice *parent, di_node_t node, ch
devinfo_set_default_properties (d, parent, node, devfs_path);
hal_device_property_set_string (d, "info.category", "storage");
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s/%s%d", hal_device_get_udi (parent), driver_name, di_instance (node));
+ hald_compute_udi (udi, sizeof (udi),
+ "%s/%s%d", hal_device_get_udi (parent),
+ driver_name, di_instance (node));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
PROP_STR(d, node, s, "devid", "info.product");
@@ -255,10 +256,11 @@ devinfo_scsi_add(HalDevice *parent, di_node_t node, char *devfs_path, char *devi
devinfo_set_default_properties (d, parent, node, devfs_path);
hal_device_property_set_string (d, "info.subsystem", "scsi");
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s/%s%d", hal_device_get_udi (parent), di_node_name(node), di_instance (node));
- hal_device_set_udi (d, udi);
- hal_device_property_set_string (d, "info.udi", udi);
+ hald_compute_udi (udi, sizeof (udi),
+ "%s/%s%d", hal_device_get_udi (parent),
+ di_node_name(node), di_instance (node));
+ hal_device_set_udi (d, udi);
+ hal_device_property_set_string (d, "info.udi", udi);
hal_device_property_set_int (d, "scsi.host",
hal_device_property_get_int (parent, "scsi_host.host"));
@@ -285,10 +287,11 @@ devinfo_scsi_storage_add(HalDevice *grampa, HalDevice *parent, di_node_t node, c
devinfo_set_default_properties (d, parent, node, devfs_path);
hal_device_property_set_string (d, "info.category", "storage");
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s/sd%d", hal_device_get_udi (parent), di_instance (node));
- hal_device_set_udi (d, udi);
- hal_device_property_set_string (d, "info.udi", udi);
+ hald_compute_udi (udi, sizeof (udi),
+ "%s/sd%d", hal_device_get_udi (parent),
+ di_instance (node));
+ hal_device_set_udi (d, udi);
+ hal_device_property_set_string (d, "info.udi", udi);
PROP_STR(d, node, s, "inquiry-product-id", "info.product");
hal_device_add_capability (d, "storage");
@@ -542,12 +545,13 @@ devinfo_lofi_add_major(HalDevice *parent, di_node_t node, char *devfs_path, char
devinfo_set_default_properties (d, parent, node, devfs_path);
hal_device_property_set_string (d, "info.subsystem", "pseudo");
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s/%s%d", hal_device_get_udi (parent), di_node_name(node), di_instance (node));
- hal_device_set_udi (d, udi);
- hal_device_property_set_string (d, "info.udi", udi);
+ hald_compute_udi (udi, sizeof (udi),
+ "%s/%s%d", hal_device_get_udi (parent),
+ di_node_name(node), di_instance (node));
+ hal_device_set_udi (d, udi);
+ hal_device_property_set_string (d, "info.udi", udi);
- devinfo_add_enqueue (d, devfs_path, &devinfo_lofi_handler);
+ devinfo_add_enqueue (d, devfs_path, &devinfo_lofi_handler);
} else {
d = lofi_d;
}
@@ -939,14 +943,14 @@ devinfo_volume_add(HalDevice *parent, di_node_t node, devinfo_storage_minor_t *m
devinfo_set_default_properties (d, parent, node, devfs_path);
hal_device_property_set_string (d, "info.category", "volume");
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s/%s", hal_device_get_udi (parent), slice);
- hal_device_set_udi (d, udi);
- hal_device_property_set_string (d, "info.udi", udi);
- hal_device_property_set_string (d, "info.product", slice);
+ hald_compute_udi (udi, sizeof (udi),
+ "%s/%s", hal_device_get_udi (parent), slice);
+ hal_device_set_udi (d, udi);
+ hal_device_property_set_string (d, "info.udi", udi);
+ hal_device_property_set_string (d, "info.product", slice);
- hal_device_add_capability (d, "volume");
- hal_device_add_capability (d, "block");
+ hal_device_add_capability (d, "volume");
+ hal_device_add_capability (d, "block");
hal_device_property_set_int (d, "block.major", major (dev));
hal_device_property_set_int (d, "block.minor", minor (dev));
hal_device_property_set_string (d, "block.device", devlink);
diff --git a/hald/solaris/devinfo_usb.c b/hald/solaris/devinfo_usb.c
index b0be81d..fd3d37e 100644
--- a/hald/solaris/devinfo_usb.c
+++ b/hald/solaris/devinfo_usb.c
@@ -119,11 +119,11 @@ devinfo_usb_if_add(HalDevice *parent, di_node_t node, gchar *devfs_path, int ifn
devinfo_set_default_properties (d, parent, node, devfs_path);
hal_device_property_set_string (d, "info.subsystem", "usb");
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s_if%d", hal_device_get_udi (parent), ifnum);
- hal_device_set_udi (d, udi);
- hal_device_property_set_string (d, "info.udi", udi);
- hal_device_property_set_string (d, "info.product", "USB Device Interface");
+ hald_compute_udi (udi, sizeof (udi),
+ "%s_if%d", hal_device_get_udi (parent), ifnum);
+ hal_device_set_udi (d, udi);
+ hal_device_property_set_string (d, "info.udi", udi);
+ hal_device_property_set_string (d, "info.product", "USB Device Interface");
/* copy parent's usb_device.* properties */
hal_device_merge_with_rewrite (d, parent, "usb.", "usb_device.");
@@ -209,9 +209,9 @@ devinfo_usb_scsa2usb_add(HalDevice *usbd, di_node_t node, gchar *devfs_path)
hal_device_property_set_string (d, "info.category", "scsi_host");
hal_device_property_set_int (d, "scsi_host.host", 0);
- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
- "%s/scsi_host%d", hal_device_get_udi (usbd),
- hal_device_property_get_int (d, "scsi_host.host"));
+ hald_compute_udi (hald_get_gdl (), udi, sizeof (udi),
+ "%s/scsi_host%d", hal_device_get_udi (usbd),
+ hal_device_property_get_int (d, "scsi_host.host"));
hal_device_set_udi (d, udi);
hal_device_property_set_string (d, "info.udi", udi);
hal_device_property_set_string (d, "info.product", "SCSI Host Adapter");
diff --git a/hald/util.c b/hald/util.c
index 8f2dbec..ee3cb37 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -469,36 +469,49 @@ hal_util_set_double_from_file (HalDevice *d, const gchar *key, const gchar *dire
}
void
-hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...)
+hal_util_make_udi_unique (HalDeviceStore *store, gchar *udi, gsize udisize, const char *original_udi)
{
- guint i;
- va_list args;
- gchar buf[256];
-
- va_start (args, format);
- g_vsnprintf (buf, sizeof (buf), format, args);
- va_end (args);
-
- g_strcanon (buf,
- "/_"
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "1234567890", '_');
+ int i;
- g_strlcpy (dst, buf, dstsize);
- if (hal_device_store_find (store, dst) == NULL)
+ if (hal_device_store_find (store, original_udi) == NULL) {
+ g_strlcpy (udi, original_udi, udisize);
goto out;
+ }
for (i = 0; ; i++) {
- g_snprintf (dst, dstsize, "%s_%d", buf, i);
- if (hal_device_store_find (store, dst) == NULL)
+ g_snprintf (udi, udisize, "%s_%d", original_udi, i);
+ if (hal_device_store_find (store, udi) == NULL) {
goto out;
+ }
}
out:
;
}
+void
+hal_util_compute_udi_valist (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, va_list args)
+{
+ g_vsnprintf (dst, dstsize, format, args);
+
+ g_strcanon (dst,
+ "/_"
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "1234567890", '_');
+}
+
+
+void
+hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...)
+{
+ va_list args;
+
+ va_start (args, format);
+ hal_util_compute_udi_valist (store, dst, dstsize, format, args);
+ va_end (args);
+}
+
gboolean
hal_util_path_ascend (gchar *path)
diff --git a/hald/util.h b/hald/util.h
index 7530f03..4cf9524 100644
--- a/hald/util.h
+++ b/hald/util.h
@@ -68,6 +68,10 @@ gboolean hal_util_set_bcd2_from_file (HalDevice *d, const gchar *key, const gcha
gboolean hal_util_set_double_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file);
+void hal_util_make_udi_unique (HalDeviceStore *store, gchar *udi, gsize udisize, const char *original_udi);
+
+void hal_util_compute_udi_valist (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, va_list args);
+
void hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...);
gboolean hal_util_path_ascend (gchar *path);
commit cc26838fd367a586ad1dff2dcc61370e7ea22b6a
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date: Wed Nov 14 00:50:08 2007 +0000
set 'linux.sysfs_path' as an indexed property
Greatly speeds up coldplugging, as most of the time is spent in
hal_device_store_match_key_value_string, looking up a device by its sysfs path.
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 4900acf..2a1726e 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -396,6 +396,9 @@ osspec_init (void)
/*
* setup socket for listening from messages from udev
*/
+
+ hal_device_store_index_property (hald_get_gdl (), "linux.sysfs_path");
+
memset(&saddr, 0x00, sizeof(saddr));
saddr.sun_family = AF_LOCAL;
/* use abstract namespace for socket path */
commit 8fe3d44796d6aece0e3ce41d41587a99d206c876
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date: Tue Nov 13 13:03:54 2007 +0000
process non-dependant hotplug events in parallel
Calculate event dependancy of hotplug events based of their sysfs_path. In
hotplug_event_process_queue if an event is dependant on an event in progress,
it will be held back in in the queue.
The event dependancy calculation is cribbed from udev. It requires the event
sequnce number in order to order the dependancies. We don't get event sequence
numbers during coldplug, so we emulate them using a simple counter.
diff --git a/hald/device.c b/hald/device.c
index 344d88d..170d06f 100644
--- a/hald/device.c
+++ b/hald/device.c
@@ -370,6 +370,7 @@ enum {
CAPABILITY_ADDED,
LOCK_ACQUIRED,
LOCK_RELEASED,
+ PRE_PROPERTY_CHANGED,
LAST_SIGNAL
};
@@ -425,6 +426,19 @@ hal_device_class_init (HalDeviceClass *klass)
G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN);
+ signals[PRE_PROPERTY_CHANGED] =
+ g_signal_new ("pre_property_changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (HalDeviceClass,
+ property_changed),
+ NULL, NULL,
+ hald_marshal_VOID__STRING_BOOL,
+ G_TYPE_NONE, 2,
+ G_TYPE_STRING,
+ G_TYPE_BOOLEAN);
+
+
signals[CAPABILITY_ADDED] =
g_signal_new ("capability_added",
G_TYPE_FROM_CLASS (klass),
@@ -1058,6 +1072,9 @@ hal_device_property_set_string (HalDevice *device, const char *key,
if (strcmp (hal_property_get_string (prop), value != NULL ? value : "") == 0)
return TRUE;
+ g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0,
+ key, FALSE);
+
hal_property_set_string (prop, value);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
@@ -1094,6 +1111,9 @@ hal_device_property_set_int (HalDevice *device, const char *key,
if (hal_property_get_int (prop) == value)
return TRUE;
+ g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0,
+ key, FALSE);
+
hal_property_set_int (prop, value);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
@@ -1129,6 +1149,9 @@ hal_device_property_set_uint64 (HalDevice *device, const char *key,
if (hal_property_get_uint64 (prop) == value)
return TRUE;
+ g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0,
+ key, FALSE);
+
hal_property_set_uint64 (prop, value);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
@@ -1164,6 +1187,9 @@ hal_device_property_set_bool (HalDevice *device, const char *key,
if (hal_property_get_bool (prop) == value)
return TRUE;
+ g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0,
+ key, FALSE);
+
hal_property_set_bool (prop, value);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
@@ -1199,6 +1225,9 @@ hal_device_property_set_double (HalDevice *device, const char *key,
if (hal_property_get_double (prop) == value)
return TRUE;
+ g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0,
+ key, FALSE);
+
hal_property_set_double (prop, value);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
@@ -1246,6 +1275,9 @@ hal_device_property_set_strlist (HalDevice *device, const char *key,
if (equal) return TRUE;
}
+ g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0,
+ key, FALSE);
+
/* TODO: check why hal_property_strlist_clear (prop) not work and why
* we need to remove the key and a new one to get this running:
* - multiple copy calls mixed with e.g. append rules
diff --git a/hald/device_store.c b/hald/device_store.c
index 23c054d..aff8f13 100644
--- a/hald/device_store.c
+++ b/hald/device_store.c
@@ -137,6 +137,7 @@ hal_device_store_class_init (HalDeviceStoreClass *klass)
static void
hal_device_store_init (HalDeviceStore *device)
{
+ device->property_index = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
}
GType
@@ -175,6 +176,27 @@ hal_device_store_new (void)
}
static void
+property_index_check_all (HalDeviceStore *store, HalDevice *device, gboolean add);
+
+static void
+property_index_modify_string (HalDeviceStore *store, HalDevice *device,
+ const char *key, gboolean added);
+
+static void
+device_pre_property_changed (HalDevice *device,
+ const char *key,
+ gboolean removed,
+ gpointer data)
+{
+ HalDeviceStore *store = HAL_DEVICE_STORE (data);
+
+ if (hal_device_property_get_type (device, key) == HAL_PROPERTY_TYPE_STRING) {
+ property_index_modify_string(store, device, key, FALSE);
+ }
+}
+
+
+static void
emit_device_property_changed (HalDevice *device,
const char *key,
gboolean added,
@@ -183,6 +205,10 @@ emit_device_property_changed (HalDevice *device,
{
HalDeviceStore *store = HAL_DEVICE_STORE (data);
+ if (hal_device_property_get_type (device, key) == HAL_PROPERTY_TYPE_STRING) {
+ property_index_modify_string(store, device, key, TRUE);
+ }
+
g_signal_emit (store, signals[DEVICE_PROPERTY_CHANGED], 0,
device, key, added, removed);
}
@@ -238,6 +264,8 @@ hal_device_store_add (HalDeviceStore *store, HalDevice *device)
g_signal_connect (device, "property_changed",
G_CALLBACK (emit_device_property_changed), store);
+ g_signal_connect (device, "pre_property_changed",
+ G_CALLBACK (device_pre_property_changed), store);
g_signal_connect (device, "capability_added",
G_CALLBACK (emit_device_capability_added), store);
g_signal_connect (device, "lock_acquired",
@@ -245,6 +273,7 @@ hal_device_store_add (HalDeviceStore *store, HalDevice *device)
g_signal_connect (device, "lock_released",
G_CALLBACK (emit_device_lock_released), store);
+ property_index_check_all (store, device, TRUE);
g_signal_emit (store, signals[STORE_CHANGED], 0, device, TRUE);
out:
@@ -272,6 +301,8 @@ hal_device_store_remove (HalDeviceStore *store, HalDevice *device)
(gpointer)emit_device_lock_released,
store);
+ property_index_check_all (store, device, FALSE);
+
g_signal_emit (store, signals[STORE_CHANGED], 0, device, FALSE);
g_object_unref (device);
@@ -345,25 +376,37 @@ hal_device_store_match_key_value_string (HalDeviceStore *store,
const char *value)
{
GSList *iter;
+ GSList *devices;
+ GHashTable *index;
g_return_val_if_fail (store != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
g_return_val_if_fail (value != NULL, NULL);
- for (iter = store->devices; iter != NULL; iter = iter->next) {
- HalDevice *d = HAL_DEVICE (iter->data);
- int type;
-
- if (!hal_device_has_property (d, key))
- continue;
-
- type = hal_device_property_get_type (d, key);
- if (type != HAL_PROPERTY_TYPE_STRING)
- continue;
-
- if (strcmp (hal_device_property_get_string (d, key),
- value) == 0)
- return d;
+ index = g_hash_table_lookup (store->property_index, key);
+
+ if (index) {
+ devices = g_hash_table_lookup (index, value);
+ if (devices)
+ return (HalDevice*) devices->data;
+ else
+ return NULL;
+ } else {
+ for (iter = store->devices; iter != NULL; iter = iter->next) {
+ HalDevice *d = HAL_DEVICE (iter->data);
+ int type;
+
+ if (!hal_device_has_property (d, key))
+ continue;
+
+ type = hal_device_property_get_type (d, key);
+ if (type != HAL_PROPERTY_TYPE_STRING)
+ continue;
+
+ if (strcmp (hal_device_property_get_string (d, key),
+ value) == 0)
+ return d;
+ }
}
return NULL;
@@ -404,26 +447,89 @@ hal_device_store_match_multiple_key_value_string (HalDeviceStore *store,
{
GSList *iter;
GSList *matches = NULL;
+ GSList *devices;
+ GHashTable *index;
g_return_val_if_fail (store != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
g_return_val_if_fail (value != NULL, NULL);
- for (iter = store->devices; iter != NULL; iter = iter->next) {
- HalDevice *d = HAL_DEVICE (iter->data);
- int type;
+ index = g_hash_table_lookup (store->property_index, key);
- if (!hal_device_has_property (d, key))
- continue;
+ if (index) {
+ devices = g_hash_table_lookup (index, value);
+ return g_slist_copy(devices);
+ } else {
+ for (iter = store->devices; iter != NULL; iter = iter->next) {
+ HalDevice *d = HAL_DEVICE (iter->data);
+ int type;
- type = hal_device_property_get_type (d, key);
- if (type != HAL_PROPERTY_TYPE_STRING)
- continue;
+ if (!hal_device_has_property (d, key))
+ continue;
+
+ type = hal_device_property_get_type (d, key);
+ if (type != HAL_PROPERTY_TYPE_STRING)
+ continue;
- if (strcmp (hal_device_property_get_string (d, key),
- value) == 0)
- matches = g_slist_prepend (matches, d);
+ if (strcmp (hal_device_property_get_string (d, key),
+ value) == 0)
+ matches = g_slist_prepend (matches, d);
+ }
}
return matches;
}
+
+
+void
+hal_device_store_index_property (HalDeviceStore *store, const char *key)
+{
+ GHashTable *index;
+
+ index = g_hash_table_lookup (store->property_index, key);
+
+ if (!index) {
+ index = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (store->property_index, g_strdup (key), index);
+ }
+}
+
+static void
+property_index_modify_string (HalDeviceStore *store, HalDevice *device,
+ const char *key, gboolean added)
+{
+ GHashTable *index;
+ const char *value;
+ GSList *devices;
+
+ value = hal_device_property_get_string (device, key);
+ index = g_hash_table_lookup (store->property_index, key);
+
+ if (!index) return;
+
+ devices = g_hash_table_lookup (index, value);
+
+ if (added) { /*add*/
+ HAL_DEBUG (("adding %p to (%s,%s)", device, key, value));
+ devices = g_slist_prepend (devices, device);
+ } else { /*remove*/
+ HAL_DEBUG (("removing %p from (%s,%s)", device, key, value));
+ devices = g_slist_remove_all (devices, device);
+ }
+ g_hash_table_insert (index, (gpointer) value, devices);
+}
+
+
+static void
+property_index_check_all (HalDeviceStore *store, HalDevice *device, gboolean added)
+{
+ GList *indexed_properties, *lp;
+
+ indexed_properties = g_hash_table_get_keys (store->property_index);
+ for (lp = indexed_properties; lp; lp = g_list_next (lp)) {
+ if (hal_device_property_get_type (device, lp->data) == HAL_PROPERTY_TYPE_STRING) {
+ property_index_modify_string (store, device, lp->data, added);
+ }
+ }
+}
+
diff --git a/hald/device_store.h b/hald/device_store.h
index 300f4c7..c79d2f6 100644
--- a/hald/device_store.h
+++ b/hald/device_store.h
@@ -38,6 +38,7 @@ struct _HalDeviceStore {
GObject parent;
GSList *devices;
+ GHashTable *property_index;
};
struct _HalDeviceStoreClass {
@@ -121,5 +122,6 @@ GSList *hal_device_store_match_multiple_key_value_string (HalDeviceStore
void hal_device_store_print (HalDeviceStore *store);
+void hal_device_store_index_property (HalDeviceStore *store, const char *key);
#endif /* DEVICE_STORE_H */
diff --git a/hald/hald_marshal.list b/hald/hald_marshal.list
index 14dd6f8..28439b6 100644
--- a/hald/hald_marshal.list
+++ b/hald/hald_marshal.list
@@ -1,6 +1,7 @@
VOID:OBJECT,STRING,STRING
VOID:STRING,STRING
VOID:STRING,BOOL,BOOL
+VOID:STRING,BOOL
VOID:STRING
VOID:OBJECT,BOOL
VOID:OBJECT,STRING,BOOL,BOOL
diff --git a/hald/linux/coldplug.c b/hald/linux/coldplug.c
index dbc1830..7e65951 100644
--- a/hald/linux/coldplug.c
+++ b/hald/linux/coldplug.c
@@ -56,7 +56,7 @@ static GHashTable *sysfs_to_udev_map;
static GSList *device_list;
static char dev_root[HAL_PATH_MAX];
static gchar *udevinfo_stdout = NULL;
-
+static unsigned long long coldplug_seqnum = 0;
typedef struct _UdevInfo UdevInfo;
struct _UdevInfo
@@ -309,6 +309,8 @@ no_node:
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = type;
hotplug_event->sysfs.net_ifindex = -1;
+ /*emulate sequence numbers for coldplug events*/
+ hotplug_event->sysfs.seqnum = coldplug_seqnum++;
return hotplug_event;
}
diff --git a/hald/linux/hotplug.c b/hald/linux/hotplug.c
index 2ca62ef..ec1880f 100644
--- a/hald/linux/hotplug.c
+++ b/hald/linux/hotplug.c
@@ -50,17 +50,20 @@
#include "hotplug.h"
/** Queue of ordered hotplug events */
-static GQueue *hotplug_event_queue;
+static GQueue *hotplug_event_queue = NULL;
/** List of HotplugEvent objects we are currently processing */
-static GSList *hotplug_events_in_progress = NULL;
+static GList *hotplug_events_in_progress = NULL;
+
+/** List of HotplugEvent objects that are blocked on a event in process */
+GList *hotplug_events_blocked = NULL;
void
hotplug_event_end (void *end_token)
{
HotplugEvent *hotplug_event = (HotplugEvent *) end_token;
- hotplug_events_in_progress = g_slist_remove (hotplug_events_in_progress, hotplug_event);
+ hotplug_events_in_progress = g_list_remove (hotplug_events_in_progress, hotplug_event);
g_slice_free (HotplugEvent, hotplug_event);
}
@@ -71,7 +74,7 @@ hotplug_event_reposted (void *end_token)
HotplugEvent *hotplug_event = (HotplugEvent *) end_token;
hotplug_event->reposted = TRUE;
- hotplug_events_in_progress = g_slist_remove (hotplug_events_in_progress, hotplug_event);
+ hotplug_events_in_progress = g_list_remove (hotplug_events_in_progress, hotplug_event);
}
static void
@@ -310,7 +313,7 @@ hotplug_event_begin (HotplugEvent *hotplug_event)
void
hotplug_event_enqueue (HotplugEvent *hotplug_event)
{
- if (hotplug_event_queue == NULL)
+ if (G_UNLIKELY (hotplug_event_queue == NULL))
hotplug_event_queue = g_queue_new ();
g_queue_push_tail (hotplug_event_queue, hotplug_event);
@@ -319,40 +322,111 @@ hotplug_event_enqueue (HotplugEvent *hotplug_event)
void
hotplug_event_enqueue_at_front (HotplugEvent *hotplug_event)
{
- if (hotplug_event_queue == NULL)
+ if (G_UNLIKELY (hotplug_event_queue == NULL))
hotplug_event_queue = g_queue_new ();
g_queue_push_head (hotplug_event_queue, hotplug_event);
}
+static gboolean
+compare_sysfspath(const char *running, const char *waiting)
+{
+ int i;
+
+ for (i = 0; i < HAL_PATH_MAX; i++) {
+ /* identical device event found */
+ if (running[i] == '\0' && waiting[i] == '\0')
+ return TRUE;
+
+ /* parent device event found */
+ if (running[i] == '\0' && waiting[i] == '/')
+ return TRUE;
+
+ /* child device event found */
+ if (running[i] == '/' && waiting[i] == '\0')
+ return TRUE;
+
+ /* no matching event */
+ if (running[i] != waiting[i])
+ break;
+ }
+
+ return FALSE;
+}
+
+/*
+ * Returns TRUE if @eventl depends on @eventr
+ */
+static gboolean
+compare_event (HotplugEvent *eventl, HotplugEvent *eventr)
+{
+ if (*eventl->sysfs.sysfs_path_old != '\0')
+ if (strcmp (eventr->sysfs.sysfs_path_old, eventl->sysfs.sysfs_path_old) == 0)
+ return TRUE;
+ return compare_sysfspath (eventr->sysfs.sysfs_path, eventl->sysfs.sysfs_path);
+}
+
+/*
+ * Returns TRUE if @hotplug_event depends on any event in @events
+ */
+static gboolean
+compare_events (HotplugEvent *hotplug_event, GList *events)
+{
+ GList *lp;
+ HotplugEvent *loop_event;
+
+ switch (hotplug_event->type) {
+
+ /* explicit fallthrough */
+ case HOTPLUG_EVENT_SYSFS:
+ case HOTPLUG_EVENT_SYSFS_DEVICE:
+ case HOTPLUG_EVENT_SYSFS_BLOCK:
+
+ for (lp = events; lp; lp = g_list_next (lp)) {
+ loop_event = (HotplugEvent*) lp->data;
+ /* skip ourselves and all later events*/
+ if (loop_event->sysfs.seqnum >= hotplug_event->sysfs.seqnum)
+ break;
+ if (compare_event (hotplug_event, loop_event)) {
+ HAL_DEBUG (("event %s dependant on %s", hotplug_event->sysfs.sysfs_path, loop_event->sysfs.sysfs_path));
+ return TRUE;
+ }
+ }
+ return FALSE;
+
+ default:
+ return FALSE;
+ }
+}
+
+
void
hotplug_event_process_queue (void)
{
HotplugEvent *hotplug_event;
+ GList *lp, *lp2;
- while (hotplug_events_in_progress != NULL ||
- (hotplug_event_queue != NULL &&
- !g_queue_is_empty (hotplug_event_queue))) {
-
- /* do not process events if some other event is in progress
- *
- * TODO: optimize so we can do add events in parallel by inspecting the
- * wait_for_sysfs_path parameter and hotplug_events_in_progress list
- */
- if (hotplug_events_in_progress != NULL && g_slist_length (hotplug_events_in_progress) > 0)
- goto out;
-
- hotplug_event = g_queue_pop_head (hotplug_event_queue);
- if (hotplug_event == NULL)
- goto out;
+ if (G_UNLIKELY (hotplug_event_queue == NULL))
+ return;
- hotplug_events_in_progress = g_slist_append (hotplug_events_in_progress, hotplug_event);
- hotplug_event_begin (hotplug_event);
+ for (lp = hotplug_event_queue->head; lp; lp = g_list_next (lp) ) {
+ hotplug_event = lp->data;
+ HAL_INFO (("checking event %s", hotplug_event->sysfs.sysfs_path));
+ if (!compare_events (hotplug_event, hotplug_event_queue->head)
+ && !compare_events (hotplug_event, hotplug_events_in_progress)) {
+ lp2 = lp->prev;
+ g_queue_unlink(hotplug_event_queue, lp);
+ hotplug_events_in_progress = g_list_concat (hotplug_events_in_progress, lp);
+ hotplug_event_begin (hotplug_event);
+ lp = lp2;
+ } else {
+ HAL_DEBUG (("event held back: %s", hotplug_event->sysfs.sysfs_path));
+ }
}
+ HAL_DEBUG (("events queued = %d, events in progress = %d", hotplug_event_queue->length, g_list_length (hotplug_events_in_progress)));
+
hotplug_queue_now_empty ();
-out:
- ;
}
gboolean
commit f36009411aeeffdf8c13474b067f912b9ed9bedb
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date: Thu Feb 14 11:15:58 2008 +0000
use GQuarks for property keys.
Modifies HalDevice to use GQuarks for the property keys, should reduce memory usage.
diff --git a/hald/device.c b/hald/device.c
index a0b99ac..344d88d 100644
--- a/hald/device.c
+++ b/hald/device.c
@@ -473,9 +473,9 @@ hal_device_init (HalDevice *device)
device->private->num_addons = 0;
device->private->num_addons_ready = 0;
- device->private->props = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
+ device->private->props = g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ NULL,
(GDestroyNotify) hal_property_free);
}
@@ -522,10 +522,15 @@ hal_device_new (void)
static inline HalProperty *
hal_device_property_find (HalDevice *device, const char *key)
{
+ GQuark quark = g_quark_try_string (key);
+
g_return_val_if_fail (device != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
- return g_hash_table_lookup (device->private->props, key);
+ if (quark)
+ return g_hash_table_lookup (device->private->props, GINT_TO_POINTER(quark));
+ else
+ return NULL;
}
typedef struct
@@ -851,11 +856,12 @@ hdpfe (gpointer key,
{
hdpfe_ud_t *c;
HalProperty *prop;
+ const gchar *key_string = g_quark_to_string ((GQuark) key);
c = (hdpfe_ud_t *) user_data;
prop = (HalProperty *) value;
- c->callback (c->device, (const char *) key, c->user_data);
+ c->callback (c->device, key_string, c->user_data);
}
void
@@ -1061,7 +1067,8 @@ hal_device_property_set_string (HalDevice *device, const char *key,
prop = hal_property_new (HAL_PROPERTY_TYPE_STRING);
hal_property_set_string (prop, value);
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props,
+ GINT_TO_POINTER(g_quark_from_string (key)), prop);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, TRUE);
@@ -1095,7 +1102,8 @@ hal_device_property_set_int (HalDevice *device, const char *key,
} else {
prop = hal_property_new (HAL_PROPERTY_TYPE_INT32);
hal_property_set_int (prop, value);
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props,
+ GINT_TO_POINTER(g_quark_from_string (key)), prop);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, TRUE);
@@ -1129,7 +1137,8 @@ hal_device_property_set_uint64 (HalDevice *device, const char *key,
} else {
prop = hal_property_new (HAL_PROPERTY_TYPE_UINT64);
hal_property_set_uint64 (prop, value);
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props,
+ GINT_TO_POINTER(g_quark_from_string (key)), prop);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, TRUE);
@@ -1163,7 +1172,8 @@ hal_device_property_set_bool (HalDevice *device, const char *key,
} else {
prop = hal_property_new (HAL_PROPERTY_TYPE_BOOLEAN);
hal_property_set_bool (prop, value);
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props,
+ GINT_TO_POINTER(g_quark_from_string (key)), prop);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, TRUE);
@@ -1197,7 +1207,8 @@ hal_device_property_set_double (HalDevice *device, const char *key,
} else {
prop = hal_property_new (HAL_PROPERTY_TYPE_DOUBLE);
hal_property_set_double (prop, value);
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props,
+ GINT_TO_POINTER(g_quark_from_string (key)), prop);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, TRUE);
@@ -1240,12 +1251,13 @@ hal_device_property_set_strlist (HalDevice *device, const char *key,
* - multiple copy calls mixed with e.g. append rules
*/
- g_hash_table_remove (device->private->props, key);
+ g_hash_table_remove (device->private->props, GINT_TO_POINTER(g_quark_from_string(key)));
prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
for (l = value ; l != NULL; l = l->next) {
hal_property_strlist_append (prop, l->data);
}
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props, GINT_TO_POINTER(g_quark_from_string (key)),
+ prop);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, FALSE);
@@ -1255,7 +1267,8 @@ hal_device_property_set_strlist (HalDevice *device, const char *key,
for (l = value ; l != NULL; l = l->next) {
hal_property_strlist_append (prop, l->data);
}
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props, GINT_TO_POINTER(g_quark_from_string (key)),
+ prop);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, TRUE);
@@ -1308,10 +1321,17 @@ hal_device_copy_property (HalDevice *from_device, const char *from, HalDevice *t
gboolean
hal_device_property_remove (HalDevice *device, const char *key)
{
- if (g_hash_table_remove (device->private->props, key)) {
- g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
- key, TRUE, FALSE);
- return TRUE;
+ GQuark quark = g_quark_try_string (key);
+ if (quark && g_hash_table_lookup (device->private->props, GINT_TO_POINTER(quark))) {
+ g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0,
+ key, TRUE);
+
+ if (g_hash_table_remove (device->private->props,
+ GINT_TO_POINTER(quark))) {
+ g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+ key, TRUE, FALSE);
+ return TRUE;
+ }
}
return FALSE;
}
@@ -1423,7 +1443,8 @@ hal_device_property_strlist_append (HalDevice *device,
prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
hal_property_strlist_append (prop, value);
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props,
+ GINT_TO_POINTER(g_quark_from_string (key)), prop);
if (!changeset)
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
@@ -1481,7 +1502,8 @@ hal_device_property_strlist_prepend (HalDevice *device,
prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
hal_property_strlist_prepend (prop, value);
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props,
+ GINT_TO_POINTER(g_quark_from_string (key)), prop);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, TRUE);
@@ -1527,7 +1549,8 @@ hal_device_property_strlist_clear (HalDevice *device,
if (prop == NULL) {
prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props,
+ GINT_TO_POINTER(g_quark_from_string (key)), prop);
if (!changeset)
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
@@ -1539,9 +1562,9 @@ hal_device_property_strlist_clear (HalDevice *device,
return FALSE;
/* TODO: check why hal_property_strlist_clear (prop) not work */
- g_hash_table_remove (device->private->props, key);
+ g_hash_table_remove (device->private->props, GINT_TO_POINTER(g_quark_from_string(key)));
prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props, GINT_TO_POINTER(g_quark_from_string(key)), prop);
if (!changeset) {
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
@@ -1579,7 +1602,8 @@ hal_device_property_strlist_add (HalDevice *device,
prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
hal_property_strlist_prepend (prop, value);
- g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ g_hash_table_insert (device->private->props,
+ GINT_TO_POINTER(g_quark_from_string (key)), prop);
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, TRUE);
commit 227f4a70d1f0d4a9e03935b78dad2947f0e3175c
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date: Fri Nov 9 01:37:32 2007 +0000
rework handling of data from udevinfo for more efficient memory usage
This patch reworks the handling of the output of udevinfo so that the output is
parsed into an intermediatary form (with a hash table of sysfpath to structures
pointing directly into the output as captured). This is converted into
HotplugEvents one at a time when needed by coldplug_get_hotplug_event.
diff --git a/hald/linux/coldplug.c b/hald/linux/coldplug.c
index 3ad7199..dbc1830 100644
--- a/hald/linux/coldplug.c
+++ b/hald/linux/coldplug.c
@@ -55,23 +55,107 @@ struct sysfs_device {
static GHashTable *sysfs_to_udev_map;
static GSList *device_list;
static char dev_root[HAL_PATH_MAX];
+static gchar *udevinfo_stdout = NULL;
-static void hotplug_event_free (HotplugEvent *ev)
+typedef struct _UdevInfo UdevInfo;
+
+struct _UdevInfo
+{
+ const char *sysfs_path;
+ const char *device_file;
+ const char *vendor;
+ const char *model;
+ const char *revision;
+ const char *serial;
+ const char *fsusage;
+ const char *fstype;
+ const char *fsversion;
+ const char *fsuuid;
+ const char *fslabel;
+};
+
+static void udev_info_free (gpointer data)
+{
+ g_slice_free(UdevInfo, data);
+}
+
+
+static HotplugEvent*
+udev_info_to_hotplug_event (const UdevInfo *info)
{
- g_slice_free(HotplugEvent, ev);
+ HotplugEvent *hotplug_event;
+ gchar *str;
+
+ hotplug_event = g_slice_new0 (HotplugEvent);
+ g_strlcpy (hotplug_event->sysfs.sysfs_path, "/sys", sizeof(hotplug_event->sysfs.sysfs_path));
+ g_strlcat (hotplug_event->sysfs.sysfs_path, info->sysfs_path, sizeof(hotplug_event->sysfs.sysfs_path));
+
+ HAL_INFO(("creating HotplugEvent for %s", hotplug_event->sysfs.sysfs_path));
+
+ if (info->device_file) {
+ g_snprintf (hotplug_event->sysfs.device_file, sizeof(hotplug_event->sysfs.device_file),
+ "%s/%s", dev_root, info->device_file);
+ HAL_INFO(("with device file %s", hotplug_event->sysfs.device_file));
+ }
+ if ((str = hal_util_strdup_valid_utf8(info->vendor)) != NULL) {
+ g_strlcpy (hotplug_event->sysfs.vendor, str, sizeof(hotplug_event->sysfs.vendor));
+ g_free (str);
+ }
+
+ if ((str = hal_util_strdup_valid_utf8(info->model)) != NULL) {
+ g_strlcpy (hotplug_event->sysfs.model, str, sizeof(hotplug_event->sysfs.model));
+ g_free (str);
+ }
+
+ if ((str = hal_util_strdup_valid_utf8(info->revision)) != NULL) {
+ g_strlcpy (hotplug_event->sysfs.revision, str, sizeof(hotplug_event->sysfs.revision));
+ g_free (str);
+ }
+
+ if ((str = hal_util_strdup_valid_utf8(info->serial)) != NULL) {
+ g_strlcpy (hotplug_event->sysfs.serial, str, sizeof(hotplug_event->sysfs.serial));
+ g_free (str);
+ }
+
+ if ((str = hal_util_strdup_valid_utf8(info->fsusage)) != NULL) {
+ g_strlcpy (hotplug_event->sysfs.fsusage, str, sizeof(hotplug_event->sysfs.fsusage));
+ g_free (str);
+ }
+
+ if ((str = hal_util_strdup_valid_utf8(info->fstype)) != NULL) {
+ g_strlcpy (hotplug_event->sysfs.fstype, str, sizeof(hotplug_event->sysfs.fstype));
+ g_free (str);
+ }
+
+ if ((str = hal_util_strdup_valid_utf8(info->fsversion)) != NULL) {
+ g_strlcpy (hotplug_event->sysfs.fsversion, str, sizeof(hotplug_event->sysfs.fsversion));
+ g_free (str);
+ }
+
+ if ((str = hal_util_strdup_valid_utf8(info->fsuuid)) != NULL) {
+ g_strlcpy (hotplug_event->sysfs.fsuuid, str, sizeof(hotplug_event->sysfs.fsuuid));
+ g_free (str);
+ }
+
+ if ((str = hal_util_strdup_valid_utf8(info->fslabel)) != NULL) {
+ g_strlcpy (hotplug_event->sysfs.fslabel, str, sizeof(hotplug_event->sysfs.fslabel));
+ g_free (str);
+ }
+
+ return hotplug_event;
}
+
static gboolean
hal_util_init_sysfs_to_udev_map (void)
{
char *udevdb_export_argv[] = { "/usr/bin/udevinfo", "-e", NULL };
char *udevroot_argv[] = { "/usr/bin/udevinfo", "-r", NULL };
- char *udevinfo_stdout;
int udevinfo_exitcode;
- HotplugEvent *hotplug_event = NULL;
+ UdevInfo *info = NULL;
char *p;
- sysfs_to_udev_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, hotplug_event_free);
+ sysfs_to_udev_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, udev_info_free);
/* get udevroot */
if (g_spawn_sync ("/", udevroot_argv, NULL, 0, NULL, NULL,
@@ -114,7 +198,6 @@ hal_util_init_sysfs_to_udev_map (void)
p = udevinfo_stdout;
while (p[0] != '\0') {
char *line, *end;
- gchar *str;
/* get line, terminate and move to next line */
line = p;
@@ -126,79 +209,49 @@ hal_util_init_sysfs_to_udev_map (void)
/* insert device */
if (line[0] == '\0') {
- if (hotplug_event != NULL) {
- g_hash_table_insert (sysfs_to_udev_map, g_strdup (hotplug_event->sysfs.sysfs_path), hotplug_event);
- HAL_INFO (("found (udevdb export) '%s' -> '%s'",
- hotplug_event->sysfs.sysfs_path, hotplug_event->sysfs.device_file));
- hotplug_event = NULL;
+ if (info != NULL) {
+ g_hash_table_insert (sysfs_to_udev_map, g_strdup_printf ("/sys%s", info->sysfs_path), info);
+ HAL_INFO (("found (udevdb export) '/sys%s' -> '%s/%s'",
+ info->sysfs_path, dev_root, info->device_file));
+ info = NULL;
}
continue;
}
/* new device */
if (strncmp(line, "P: ", 3) == 0) {
- hotplug_event = g_slice_new0 (HotplugEvent);
- g_strlcpy (hotplug_event->sysfs.sysfs_path, "/sys", sizeof(hotplug_event->sysfs.sysfs_path));
- g_strlcat (hotplug_event->sysfs.sysfs_path, &line[3], sizeof(hotplug_event->sysfs.sysfs_path));
+ info = g_slice_new0 (UdevInfo);
+ info->sysfs_path = &line[3];
continue;
}
/* only valid if we have an actual device */
- if (hotplug_event == NULL)
+ if (info == NULL)
continue;
if (strncmp(line, "N: ", 3) == 0) {
- g_snprintf (hotplug_event->sysfs.device_file, sizeof(hotplug_event->sysfs.device_file),
- "%s/%s", dev_root, &line[3]);
+ info->device_file = &line[3];
} else if (strncmp(line, "E: ID_VENDOR=", 13) == 0) {
- if ((str = hal_util_strdup_valid_utf8(&line[13])) != NULL) {
- g_strlcpy (hotplug_event->sysfs.vendor, str, sizeof(hotplug_event->sysfs.vendor));
- g_free (str);
- }
+ info->vendor = &line[13];
} else if (strncmp(line, "E: ID_MODEL=", 12) == 0) {
- if ((str = hal_util_strdup_valid_utf8(&line[12])) != NULL) {
- g_strlcpy (hotplug_event->sysfs.model, str, sizeof(hotplug_event->sysfs.model));
- g_free (str);
- }
+ info->model = &line[12];
} else if (strncmp(line, "E: ID_REVISION=", 15) == 0) {
- if ((str = hal_util_strdup_valid_utf8(&line[15])) != NULL) {
- g_strlcpy (hotplug_event->sysfs.revision, str, sizeof(hotplug_event->sysfs.revision));
- g_free (str);
- }
+ info->revision = &line[15];
} else if (strncmp(line, "E: ID_SERIAL=", 13) == 0) {
- if ((str = hal_util_strdup_valid_utf8(&line[13])) != NULL) {
- g_strlcpy (hotplug_event->sysfs.serial, str, sizeof(hotplug_event->sysfs.serial));
- g_free (str);
- }
+ info->serial = &line[13];
} else if (strncmp(line, "E: ID_FS_USAGE=", 15) == 0) {
- if ((str = hal_util_strdup_valid_utf8(&line[15])) != NULL) {
- g_strlcpy (hotplug_event->sysfs.fsusage, str, sizeof(hotplug_event->sysfs.fsusage));
- g_free (str);
- }
+ info->fsusage = &line[15];
} else if (strncmp(line, "E: ID_FS_TYPE=", 14) == 0) {
- if ((str = hal_util_strdup_valid_utf8(&line[14])) != NULL) {
- g_strlcpy (hotplug_event->sysfs.fstype, str, sizeof(hotplug_event->sysfs.fstype));
- g_free (str);
- }
+ info->fstype = &line[14];
} else if (strncmp(line, "E: ID_FS_VERSION=", 17) == 0) {
- if ((str = hal_util_strdup_valid_utf8(&line[17])) != NULL) {
- g_strlcpy (hotplug_event->sysfs.fsversion, str, sizeof(hotplug_event->sysfs.fsversion));
- g_free (str);
- }
+ info->fsversion = &line[17];
} else if (strncmp(line, "E: ID_FS_UUID=", 14) == 0) {
- if ((str = hal_util_strdup_valid_utf8(&line[14])) != NULL) {
- g_strlcpy (hotplug_event->sysfs.fsuuid, str, sizeof(hotplug_event->sysfs.fsuuid));
- g_free (str);
- }
+ info->fsuuid = &line[14];
} else if (strncmp(line, "E: ID_FS_LABEL=", 15) == 0) {
- if ((str = hal_util_strdup_valid_utf8(&line[15])) != NULL) {
- g_strlcpy (hotplug_event->sysfs.fslabel, str, sizeof(hotplug_event->sysfs.fslabel));
- g_free (str);
- }
+ info->fslabel = &line[15];
}
}
- g_free(udevinfo_stdout);
return TRUE;
error:
@@ -211,19 +264,20 @@ error:
static HotplugEvent
*coldplug_get_hotplug_event(const gchar *sysfs_path, const gchar *subsystem, HotplugEventType type)
{
- HotplugEvent *hotplug_event, *hotplug_event_udev;
+ HotplugEvent *hotplug_event;
const char *pos;
gchar path[HAL_PATH_MAX];
struct stat statbuf;
-
- hotplug_event = g_slice_new0 (HotplugEvent);
+ UdevInfo *info;
/* lookup if udev has something stored in its database */
- hotplug_event_udev = (HotplugEvent *) g_hash_table_lookup (sysfs_to_udev_map, sysfs_path);
- if (hotplug_event_udev != NULL) {
- memcpy(hotplug_event, hotplug_event_udev, sizeof(HotplugEvent));
+ info = (UdevInfo*) g_hash_table_lookup (sysfs_to_udev_map, sysfs_path);
+ if (info) {
+ hotplug_event = udev_info_to_hotplug_event (info);
HAL_INFO (("new event (dev node from udev) '%s' '%s'", hotplug_event->sysfs.sysfs_path, hotplug_event->sysfs.device_file));
} else {
+ hotplug_event = g_slice_new0 (HotplugEvent);
+
/* device is not in udev database */
g_strlcpy(hotplug_event->sysfs.sysfs_path, sysfs_path, sizeof(hotplug_event->sysfs.sysfs_path));
@@ -543,6 +597,7 @@ coldplug_synthesize_events (void)
}
g_hash_table_destroy (sysfs_to_udev_map);
+ g_free (udevinfo_stdout);
return TRUE;
error:
commit 99122f71f31466c1010cbe7aa95a8860ebc688d7
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date: Thu Nov 8 10:29:23 2007 +0000
process coldplug events as soon as they're generated
By processing coldplug events as soon as their generated and enqueued we can
save some memory usage now that hotplug events are allocated using g_slice
rather than in a pool.
diff --git a/hald/linux/coldplug.c b/hald/linux/coldplug.c
index 5538aff..3ad7199 100644
--- a/hald/linux/coldplug.c
+++ b/hald/linux/coldplug.c
@@ -468,7 +468,7 @@ static void scan_class(void)
}
}
-static void queue_events(void)
+static void process_coldplug_events(void)
{
GSList *dev;
@@ -481,6 +481,7 @@ static void queue_events(void)
sysfs_dev->subsystem,
sysfs_dev->type);
hotplug_event_enqueue (hotplug_event);
+ hotplug_event_process_queue();
g_free (sysfs_dev->path);
g_free (sysfs_dev->subsystem);
@@ -519,22 +520,22 @@ coldplug_synthesize_events (void)
if (stat("/sys/subsystem", &statbuf) == 0) {
scan_subsystem ("subsystem");
device_list = g_slist_sort (device_list, _device_order);
- queue_events ();
+ process_coldplug_events ();
} else {
scan_subsystem ("bus");
device_list = g_slist_sort (device_list, _device_order);
- queue_events ();
+ process_coldplug_events ();
scan_class ();
scan_single_bus ("bluetooth");
device_list = g_slist_sort (device_list, _device_order);
- queue_events ();
+ process_coldplug_events ();
/* scan /sys/block, if it isn't already a class */
if (stat("/sys/class/block", &statbuf) != 0) {
scan_block ();
device_list = g_slist_sort (device_list, _device_order);
- queue_events ();
+ process_coldplug_events ();
}
/* add events from reading /proc/mdstat */
commit 615789438e4df7ef499d6d9c288188d82f1b6eab
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date: Thu Nov 8 14:20:39 2007 +0000
use g_slice for hotplug events
Using g_slice should be better (and makes for cleaner code) than our current
HotplugEvent pool.
diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
index d8d526c..af5145c 100644
--- a/hald/linux/acpi.c
+++ b/hald/linux/acpi.c
@@ -727,7 +727,7 @@ acpi_synthesize_item (const gchar *fullpath, int acpi_type)
{
HotplugEvent *hotplug_event;
HAL_INFO (("Processing %s", fullpath));
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = HOTPLUG_EVENT_ACPI;
g_strlcpy (hotplug_event->acpi.acpi_path, fullpath, sizeof (hotplug_event->acpi.acpi_path));
@@ -855,7 +855,7 @@ acpi_synthesize_sonypi_display (void)
if (!found)
return;
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = HOTPLUG_EVENT_ACPI;
g_strlcpy (hotplug_event->acpi.acpi_path, path, sizeof (hotplug_event->acpi.acpi_path));
@@ -1271,7 +1271,7 @@ acpi_generate_add_hotplug_event (HalDevice *d)
acpi_path = hal_device_property_get_string (d, "linux.acpi_path");
acpi_type = hal_device_property_get_int (d, "linux.acpi_type");
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = HOTPLUG_EVENT_ACPI;
g_strlcpy (hotplug_event->acpi.acpi_path, acpi_path, sizeof (hotplug_event->acpi.acpi_path));
@@ -1289,7 +1289,7 @@ acpi_generate_remove_hotplug_event (HalDevice *d)
acpi_path = hal_device_property_get_string (d, "linux.acpi_path");
acpi_type = hal_device_property_get_int (d, "linux.acpi_type");
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_REMOVE;
hotplug_event->type = HOTPLUG_EVENT_ACPI;
g_strlcpy (hotplug_event->acpi.acpi_path, acpi_path, sizeof (hotplug_event->acpi.acpi_path));
diff --git a/hald/linux/apm.c b/hald/linux/apm.c
index 57d75c7..7b49fb2 100644
--- a/hald/linux/apm.c
+++ b/hald/linux/apm.c
@@ -297,14 +297,14 @@ apm_synthesize_hotplug_events (void)
/* Set appropriate properties on the computer object */
hal_device_property_set_string (computer, "power_management.type", "apm");
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = HOTPLUG_EVENT_APM;
g_strlcpy (hotplug_event->apm.apm_path, "/proc/apm", sizeof (hotplug_event->apm.apm_path));
hotplug_event->apm.apm_type = APM_TYPE_BATTERY;
hotplug_event_enqueue (hotplug_event);
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->type = HOTPLUG_EVENT_APM;
g_strlcpy (hotplug_event->apm.apm_path, "/proc/apm", sizeof (hotplug_event->apm.apm_path));
hotplug_event->apm.apm_type = APM_TYPE_AC_ADAPTER;
@@ -520,7 +520,7 @@ apm_generate_add_hotplug_event (HalDevice *d)
apm_path = hal_device_property_get_string (d, "linux.apm_path");
apm_type = hal_device_property_get_int (d, "linux.apm_type");
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = HOTPLUG_EVENT_APM;
g_strlcpy (hotplug_event->apm.apm_path, apm_path, sizeof (hotplug_event->apm.apm_path));
@@ -538,7 +538,7 @@ apm_generate_remove_hotplug_event (HalDevice *d)
apm_path = hal_device_property_get_string (d, "linux.apm_path");
apm_type = hal_device_property_get_int (d, "linux.apm_type");
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_REMOVE;
hotplug_event->type = HOTPLUG_EVENT_APM;
g_strlcpy (hotplug_event->apm.apm_path, apm_path, sizeof (hotplug_event->apm.apm_path));
diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c
index 47c95c5..decacff 100644
--- a/hald/linux/blockdev.c
+++ b/hald/linux/blockdev.c
@@ -361,7 +361,7 @@ generate_fakevolume_hotplug_event_add_for_storage_device (HalDevice *d)
snprintf (fake_sysfs_path, sizeof(fake_sysfs_path), "%s/fakevolume", sysfs_path);
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = HOTPLUG_EVENT_SYSFS_BLOCK;
g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem));
@@ -955,6 +955,8 @@ hotplug_event_begin_add_blockdev (const gchar *sysfs_path, const gchar *device_f
is_device_mapper = TRUE;
}
}
+ } else {
+ HAL_INFO(("Couldn't find slave volume in devices"));
}
}
g_free (target);
@@ -1705,7 +1707,7 @@ blockdev_generate_add_hotplug_event (HalDevice *d)
serial = hal_device_property_get_string (d, "storage.serial");
revision = hal_device_property_get_string (d, "storage.firmware_revision");
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = HOTPLUG_EVENT_SYSFS;
g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem));
@@ -1730,7 +1732,7 @@ blockdev_generate_remove_hotplug_event (HalDevice *d)
sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path");
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_REMOVE;
hotplug_event->type = HOTPLUG_EVENT_SYSFS;
g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem));
@@ -1858,7 +1860,7 @@ blockdev_process_mdstat (void)
} else {
HAL_INFO (("Adding md device at '%s' ('%s')", sysfs_path, device_file));
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = HOTPLUG_EVENT_SYSFS_BLOCK;
g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem));
@@ -1911,7 +1913,7 @@ blockdev_process_mdstat (void)
HAL_INFO (("Removing md device at '%s' ('%s')", sysfs_path, device_file));
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_REMOVE;
hotplug_event->type = HOTPLUG_EVENT_SYSFS_BLOCK;
g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem));
diff --git a/hald/linux/coldplug.c b/hald/linux/coldplug.c
index 30949ca..5538aff 100644
--- a/hald/linux/coldplug.c
+++ b/hald/linux/coldplug.c
@@ -56,6 +56,11 @@ static GHashTable *sysfs_to_udev_map;
static GSList *device_list;
static char dev_root[HAL_PATH_MAX];
+static void hotplug_event_free (HotplugEvent *ev)
+{
+ g_slice_free(HotplugEvent, ev);
+}
+
static gboolean
hal_util_init_sysfs_to_udev_map (void)
{
@@ -66,7 +71,7 @@ hal_util_init_sysfs_to_udev_map (void)
HotplugEvent *hotplug_event = NULL;
char *p;
- sysfs_to_udev_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ sysfs_to_udev_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, hotplug_event_free);
/* get udevroot */
if (g_spawn_sync ("/", udevroot_argv, NULL, 0, NULL, NULL,
@@ -132,7 +137,7 @@ hal_util_init_sysfs_to_udev_map (void)
/* new device */
if (strncmp(line, "P: ", 3) == 0) {
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
g_strlcpy (hotplug_event->sysfs.sysfs_path, "/sys", sizeof(hotplug_event->sysfs.sysfs_path));
g_strlcat (hotplug_event->sysfs.sysfs_path, &line[3], sizeof(hotplug_event->sysfs.sysfs_path));
continue;
@@ -203,22 +208,6 @@ error:
return FALSE;
}
-static HotplugEvent *pool = NULL;
-static int pool_next_free = 0;
-static int pool_num_freed = 0;
-static int pool_size = 1000;
-
-static void
-pool_free (gpointer data)
-{
- HAL_INFO (("pool_num_freed = %d (of %d)", pool_num_freed, pool_next_free));
- pool_num_freed++;
- if (pool_num_freed == pool_next_free) {
- HAL_INFO (("Freeing whole pool"));
- g_free (pool);
- }
-}
-
static HotplugEvent
*coldplug_get_hotplug_event(const gchar *sysfs_path, const gchar *subsystem, HotplugEventType type)
{
@@ -226,30 +215,13 @@ static HotplugEvent
const char *pos;
gchar path[HAL_PATH_MAX];
struct stat statbuf;
- gboolean from_pool = FALSE;
-
- /* TODO: FIXME: this is experimental code */
- if (pool == NULL) {
- pool = g_new0 (HotplugEvent, pool_size);
- pool_next_free = 0;
- pool_num_freed = 0;
- }
- if (pool_next_free >= pool_size) {
- hotplug_event = g_new0 (HotplugEvent, 1);
- } else {
- from_pool = TRUE;
- hotplug_event = pool + pool_next_free++;
- hotplug_event->free_function = pool_free;
- }
+ hotplug_event = g_slice_new0 (HotplugEvent);
/* lookup if udev has something stored in its database */
hotplug_event_udev = (HotplugEvent *) g_hash_table_lookup (sysfs_to_udev_map, sysfs_path);
if (hotplug_event_udev != NULL) {
memcpy(hotplug_event, hotplug_event_udev, sizeof(HotplugEvent));
- if (from_pool) {
- hotplug_event->free_function = pool_free;
- }
HAL_INFO (("new event (dev node from udev) '%s' '%s'", hotplug_event->sysfs.sysfs_path, hotplug_event->sysfs.device_file));
} else {
/* device is not in udev database */
@@ -301,7 +273,7 @@ static int device_list_insert(const char *path, const char *subsystem,
if (!(statbuf.st_mode & S_IWUSR))
goto error;
- sysfs_dev = g_new0 (struct sysfs_device, 1);
+ sysfs_dev = g_slice_new0 (struct sysfs_device);
if (sysfs_dev == NULL)
goto error;
@@ -326,11 +298,11 @@ static int device_list_insert(const char *path, const char *subsystem,
sysfs_dev->path = g_strdup (path);
found:
sysfs_dev->subsystem = g_strdup (subsystem);
- device_list = g_slist_prepend (device_list, sysfs_dev);
+ device_list = g_slist_append (device_list, sysfs_dev);
return 0;
error:
- g_free (sysfs_dev);
+ g_slice_free (struct sysfs_device, sysfs_dev);
return -1;
}
@@ -512,7 +484,7 @@ static void queue_events(void)
g_free (sysfs_dev->path);
g_free (sysfs_dev->subsystem);
- g_free (sysfs_dev);
+ g_slice_free (struct sysfs_device, sysfs_dev);
}
g_slist_free (device_list);
diff --git a/hald/linux/device.c b/hald/linux/device.c
index d8dfbfd..654d5e6 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -753,7 +753,7 @@ missing_scsi_host (const gchar *sysfs_path, HotplugEvent *device_event, HotplugA
/* fake host event */
rc = TRUE;
- host_event = g_new0 (HotplugEvent, 1);
+ host_event = g_slice_new0 (HotplugEvent);
host_event->action = action;
host_event->type = HOTPLUG_EVENT_SYSFS_DEVICE;
g_strlcpy (host_event->sysfs.subsystem, "scsi_host", sizeof (host_event->sysfs.subsystem));
@@ -4485,7 +4485,7 @@ dev_generate_add_hotplug_event (HalDevice *d)
sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path");
device_file = hal_device_property_get_string (d, "linux.device_file");
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = HOTPLUG_EVENT_SYSFS;
g_strlcpy (hotplug_event->sysfs.subsystem, subsystem, sizeof (hotplug_event->sysfs.subsystem));
@@ -4509,7 +4509,7 @@ dev_generate_remove_hotplug_event (HalDevice *d)
subsystem = hal_device_property_get_string (d, "linux.subsystem");
sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path");
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->action = HOTPLUG_ACTION_REMOVE;
hotplug_event->type = HOTPLUG_EVENT_SYSFS;
g_strlcpy (hotplug_event->sysfs.subsystem, subsystem, sizeof (hotplug_event->sysfs.subsystem));
diff --git a/hald/linux/hotplug.c b/hald/linux/hotplug.c
index 239ac31..2ca62ef 100644
--- a/hald/linux/hotplug.c
+++ b/hald/linux/hotplug.c
@@ -62,11 +62,7 @@ hotplug_event_end (void *end_token)
hotplug_events_in_progress = g_slist_remove (hotplug_events_in_progress, hotplug_event);
- if (hotplug_event->free_function != NULL) {
- hotplug_event->free_function (hotplug_event);
- } else {
- g_free (hotplug_event);
- }
+ g_slice_free (HotplugEvent, hotplug_event);
}
void
diff --git a/hald/linux/hotplug.h b/hald/linux/hotplug.h
index 27dc9d5..06a32a5 100644
--- a/hald/linux/hotplug.h
+++ b/hald/linux/hotplug.h
@@ -57,9 +57,6 @@ typedef struct
HotplugActionType action; /* Whether the event is add or remove */
HotplugEventType type; /* Type of event */
gboolean reposted; /* Avoid loops */
-
- void (*free_function) (gpointer data);
-
union {
struct {
char subsystem[HAL_NAME_MAX]; /* Kernel subsystem the device belongs to */
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index fb7f436..4900acf 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -121,7 +121,7 @@ hald_udev_data (GIOChannel *source, GIOCondition condition, gpointer user_data)
goto out;
}
- hotplug_event = g_new0 (HotplugEvent, 1);
+ hotplug_event = g_slice_new0 (HotplugEvent);
hotplug_event->type = HOTPLUG_EVENT_SYSFS;
while (bufpos < sizeof (buf)) {
@@ -273,7 +273,7 @@ hald_udev_data (GIOChannel *source, GIOCondition condition, gpointer user_data)
}
invalid:
- g_free (hotplug_event);
+ g_slice_free (HotplugEvent, hotplug_event);
out:
return TRUE;
commit 7bd703b8abb8252eae4002180852c492aa686d88
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date: Wed Nov 7 16:55:47 2007 +0000
use slices for HalProperty
Use g_slice for storing HalProperty. Reduces memory fragmentation during
coldplug.
diff --git a/hald/device.c b/hald/device.c
index 304f177..a0b99ac 100644
--- a/hald/device.c
+++ b/hald/device.c
@@ -80,14 +80,14 @@ hal_property_free (HalProperty *prop)
}
g_slist_free (prop->v.strlist_value);
}
- g_free (prop);
+ g_slice_free (HalProperty, prop);
}
static inline HalProperty *
hal_property_new (int type)
{
HalProperty *prop;
- prop = g_new0 (HalProperty, 1);
+ prop = g_slice_new0 (HalProperty);
prop->type = type;
return prop;
}
More information about the hal-commit
mailing list