Annotation of /trunk/hal/patches/hal-0.5.10-use-g_slice-for-hotplug-events.patch
Parent Directory | Revision Log
Revision 597 -
(hide annotations)
(download)
Mon May 19 19:05:19 2008 UTC (16 years, 4 months ago) by niro
File size: 14498 byte(s)
Mon May 19 19:05:19 2008 UTC (16 years, 4 months ago) by niro
File size: 14498 byte(s)
-gentoo patches
1 | niro | 597 | From cd5de1b7be2bc761fd4319321a6985da20124b89 Mon Sep 17 00:00:00 2001 |
2 | From: Rob Taylor <rob.taylor@codethink.co.uk> | ||
3 | Date: Mon, 19 Nov 2007 16:17:27 +0000 | ||
4 | Subject: [PATCH] use g_slice for hotplug events | ||
5 | |||
6 | Using g_slice should be better (and makes for cleaner code) than our current | ||
7 | HotplugEvent pool. | ||
8 | --- | ||
9 | hald/linux/acpi.c | 8 +++--- | ||
10 | hald/linux/apm.c | 8 +++--- | ||
11 | hald/linux/blockdev.c | 12 ++++++---- | ||
12 | hald/linux/coldplug.c | 52 +++++++++++------------------------------------- | ||
13 | hald/linux/device.c | 6 ++-- | ||
14 | hald/linux/hotplug.c | 6 +---- | ||
15 | hald/linux/hotplug.h | 3 -- | ||
16 | hald/linux/osspec.c | 4 +- | ||
17 | 8 files changed, 33 insertions(+), 66 deletions(-) | ||
18 | |||
19 | diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c | ||
20 | index cc97f15..e995d70 100644 | ||
21 | --- a/hald/linux/acpi.c | ||
22 | +++ b/hald/linux/acpi.c | ||
23 | @@ -727,7 +727,7 @@ acpi_synthesize_item (const gchar *fullpath, int acpi_type) | ||
24 | { | ||
25 | HotplugEvent *hotplug_event; | ||
26 | HAL_INFO (("Processing %s", fullpath)); | ||
27 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
28 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
29 | hotplug_event->action = HOTPLUG_ACTION_ADD; | ||
30 | hotplug_event->type = HOTPLUG_EVENT_ACPI; | ||
31 | g_strlcpy (hotplug_event->acpi.acpi_path, fullpath, sizeof (hotplug_event->acpi.acpi_path)); | ||
32 | @@ -855,7 +855,7 @@ acpi_synthesize_sonypi_display (void) | ||
33 | if (!found) | ||
34 | return; | ||
35 | |||
36 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
37 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
38 | hotplug_event->action = HOTPLUG_ACTION_ADD; | ||
39 | hotplug_event->type = HOTPLUG_EVENT_ACPI; | ||
40 | g_strlcpy (hotplug_event->acpi.acpi_path, path, sizeof (hotplug_event->acpi.acpi_path)); | ||
41 | @@ -1253,7 +1253,7 @@ acpi_generate_add_hotplug_event (HalDevice *d) | ||
42 | acpi_path = hal_device_property_get_string (d, "linux.acpi_path"); | ||
43 | acpi_type = hal_device_property_get_int (d, "linux.acpi_type"); | ||
44 | |||
45 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
46 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
47 | hotplug_event->action = HOTPLUG_ACTION_ADD; | ||
48 | hotplug_event->type = HOTPLUG_EVENT_ACPI; | ||
49 | g_strlcpy (hotplug_event->acpi.acpi_path, acpi_path, sizeof (hotplug_event->acpi.acpi_path)); | ||
50 | @@ -1271,7 +1271,7 @@ acpi_generate_remove_hotplug_event (HalDevice *d) | ||
51 | acpi_path = hal_device_property_get_string (d, "linux.acpi_path"); | ||
52 | acpi_type = hal_device_property_get_int (d, "linux.acpi_type"); | ||
53 | |||
54 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
55 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
56 | hotplug_event->action = HOTPLUG_ACTION_REMOVE; | ||
57 | hotplug_event->type = HOTPLUG_EVENT_ACPI; | ||
58 | g_strlcpy (hotplug_event->acpi.acpi_path, acpi_path, sizeof (hotplug_event->acpi.acpi_path)); | ||
59 | diff --git a/hald/linux/apm.c b/hald/linux/apm.c | ||
60 | index 79c54ad..5993e43 100644 | ||
61 | --- a/hald/linux/apm.c | ||
62 | +++ b/hald/linux/apm.c | ||
63 | @@ -297,14 +297,14 @@ apm_synthesize_hotplug_events (void) | ||
64 | /* Set appropriate properties on the computer object */ | ||
65 | hal_device_property_set_string (computer, "power_management.type", "apm"); | ||
66 | |||
67 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
68 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
69 | hotplug_event->action = HOTPLUG_ACTION_ADD; | ||
70 | hotplug_event->type = HOTPLUG_EVENT_APM; | ||
71 | g_strlcpy (hotplug_event->apm.apm_path, "/proc/apm", sizeof (hotplug_event->apm.apm_path)); | ||
72 | hotplug_event->apm.apm_type = APM_TYPE_BATTERY; | ||
73 | hotplug_event_enqueue (hotplug_event); | ||
74 | |||
75 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
76 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
77 | hotplug_event->type = HOTPLUG_EVENT_APM; | ||
78 | g_strlcpy (hotplug_event->apm.apm_path, "/proc/apm", sizeof (hotplug_event->apm.apm_path)); | ||
79 | hotplug_event->apm.apm_type = APM_TYPE_AC_ADAPTER; | ||
80 | @@ -514,7 +514,7 @@ apm_generate_add_hotplug_event (HalDevice *d) | ||
81 | apm_path = hal_device_property_get_string (d, "linux.apm_path"); | ||
82 | apm_type = hal_device_property_get_int (d, "linux.apm_type"); | ||
83 | |||
84 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
85 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
86 | hotplug_event->action = HOTPLUG_ACTION_ADD; | ||
87 | hotplug_event->type = HOTPLUG_EVENT_APM; | ||
88 | g_strlcpy (hotplug_event->apm.apm_path, apm_path, sizeof (hotplug_event->apm.apm_path)); | ||
89 | @@ -532,7 +532,7 @@ apm_generate_remove_hotplug_event (HalDevice *d) | ||
90 | apm_path = hal_device_property_get_string (d, "linux.apm_path"); | ||
91 | apm_type = hal_device_property_get_int (d, "linux.apm_type"); | ||
92 | |||
93 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
94 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
95 | hotplug_event->action = HOTPLUG_ACTION_REMOVE; | ||
96 | hotplug_event->type = HOTPLUG_EVENT_APM; | ||
97 | g_strlcpy (hotplug_event->apm.apm_path, apm_path, sizeof (hotplug_event->apm.apm_path)); | ||
98 | diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c | ||
99 | index 46b5b58..e40b743 100644 | ||
100 | --- a/hald/linux/blockdev.c | ||
101 | +++ b/hald/linux/blockdev.c | ||
102 | @@ -352,7 +352,7 @@ generate_fakevolume_hotplug_event_add_for_storage_device (HalDevice *d) | ||
103 | |||
104 | snprintf (fake_sysfs_path, sizeof(fake_sysfs_path), "%s/fakevolume", sysfs_path); | ||
105 | |||
106 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
107 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
108 | hotplug_event->action = HOTPLUG_ACTION_ADD; | ||
109 | hotplug_event->type = HOTPLUG_EVENT_SYSFS_BLOCK; | ||
110 | g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem)); | ||
111 | @@ -942,6 +942,8 @@ hotplug_event_begin_add_blockdev (const gchar *sysfs_path, const gchar *device_f | ||
112 | is_device_mapper = TRUE; | ||
113 | } | ||
114 | } | ||
115 | + } else { | ||
116 | + HAL_INFO(("Couldn't find slave volume in devices")); | ||
117 | } | ||
118 | } | ||
119 | g_free (target); | ||
120 | @@ -1673,7 +1675,7 @@ blockdev_generate_add_hotplug_event (HalDevice *d) | ||
121 | serial = hal_device_property_get_string (d, "storage.serial"); | ||
122 | revision = hal_device_property_get_string (d, "storage.firmware_revision"); | ||
123 | |||
124 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
125 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
126 | hotplug_event->action = HOTPLUG_ACTION_ADD; | ||
127 | hotplug_event->type = HOTPLUG_EVENT_SYSFS; | ||
128 | g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem)); | ||
129 | @@ -1698,7 +1700,7 @@ blockdev_generate_remove_hotplug_event (HalDevice *d) | ||
130 | |||
131 | sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path"); | ||
132 | |||
133 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
134 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
135 | hotplug_event->action = HOTPLUG_ACTION_REMOVE; | ||
136 | hotplug_event->type = HOTPLUG_EVENT_SYSFS; | ||
137 | g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem)); | ||
138 | @@ -1826,7 +1828,7 @@ blockdev_process_mdstat (void) | ||
139 | } else { | ||
140 | HAL_INFO (("Adding md device at '%s' ('%s')", sysfs_path, device_file)); | ||
141 | |||
142 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
143 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
144 | hotplug_event->action = HOTPLUG_ACTION_ADD; | ||
145 | hotplug_event->type = HOTPLUG_EVENT_SYSFS_BLOCK; | ||
146 | g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem)); | ||
147 | @@ -1879,7 +1881,7 @@ blockdev_process_mdstat (void) | ||
148 | |||
149 | HAL_INFO (("Removing md device at '%s' ('%s')", sysfs_path, device_file)); | ||
150 | |||
151 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
152 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
153 | hotplug_event->action = HOTPLUG_ACTION_REMOVE; | ||
154 | hotplug_event->type = HOTPLUG_EVENT_SYSFS_BLOCK; | ||
155 | g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem)); | ||
156 | diff --git a/hald/linux/coldplug.c b/hald/linux/coldplug.c | ||
157 | index 30949ca..5538aff 100644 | ||
158 | --- a/hald/linux/coldplug.c | ||
159 | +++ b/hald/linux/coldplug.c | ||
160 | @@ -56,6 +56,11 @@ static GHashTable *sysfs_to_udev_map; | ||
161 | static GSList *device_list; | ||
162 | static char dev_root[HAL_PATH_MAX]; | ||
163 | |||
164 | +static void hotplug_event_free (HotplugEvent *ev) | ||
165 | +{ | ||
166 | + g_slice_free(HotplugEvent, ev); | ||
167 | +} | ||
168 | + | ||
169 | static gboolean | ||
170 | hal_util_init_sysfs_to_udev_map (void) | ||
171 | { | ||
172 | @@ -66,7 +71,7 @@ hal_util_init_sysfs_to_udev_map (void) | ||
173 | HotplugEvent *hotplug_event = NULL; | ||
174 | char *p; | ||
175 | |||
176 | - sysfs_to_udev_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); | ||
177 | + sysfs_to_udev_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, hotplug_event_free); | ||
178 | |||
179 | /* get udevroot */ | ||
180 | if (g_spawn_sync ("/", udevroot_argv, NULL, 0, NULL, NULL, | ||
181 | @@ -132,7 +137,7 @@ hal_util_init_sysfs_to_udev_map (void) | ||
182 | |||
183 | /* new device */ | ||
184 | if (strncmp(line, "P: ", 3) == 0) { | ||
185 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
186 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
187 | g_strlcpy (hotplug_event->sysfs.sysfs_path, "/sys", sizeof(hotplug_event->sysfs.sysfs_path)); | ||
188 | g_strlcat (hotplug_event->sysfs.sysfs_path, &line[3], sizeof(hotplug_event->sysfs.sysfs_path)); | ||
189 | continue; | ||
190 | @@ -203,22 +208,6 @@ error: | ||
191 | return FALSE; | ||
192 | } | ||
193 | |||
194 | -static HotplugEvent *pool = NULL; | ||
195 | -static int pool_next_free = 0; | ||
196 | -static int pool_num_freed = 0; | ||
197 | -static int pool_size = 1000; | ||
198 | - | ||
199 | -static void | ||
200 | -pool_free (gpointer data) | ||
201 | -{ | ||
202 | - HAL_INFO (("pool_num_freed = %d (of %d)", pool_num_freed, pool_next_free)); | ||
203 | - pool_num_freed++; | ||
204 | - if (pool_num_freed == pool_next_free) { | ||
205 | - HAL_INFO (("Freeing whole pool")); | ||
206 | - g_free (pool); | ||
207 | - } | ||
208 | -} | ||
209 | - | ||
210 | static HotplugEvent | ||
211 | *coldplug_get_hotplug_event(const gchar *sysfs_path, const gchar *subsystem, HotplugEventType type) | ||
212 | { | ||
213 | @@ -226,30 +215,13 @@ static HotplugEvent | ||
214 | const char *pos; | ||
215 | gchar path[HAL_PATH_MAX]; | ||
216 | struct stat statbuf; | ||
217 | - gboolean from_pool = FALSE; | ||
218 | - | ||
219 | - /* TODO: FIXME: this is experimental code */ | ||
220 | - if (pool == NULL) { | ||
221 | - pool = g_new0 (HotplugEvent, pool_size); | ||
222 | - pool_next_free = 0; | ||
223 | - pool_num_freed = 0; | ||
224 | - } | ||
225 | |||
226 | - if (pool_next_free >= pool_size) { | ||
227 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
228 | - } else { | ||
229 | - from_pool = TRUE; | ||
230 | - hotplug_event = pool + pool_next_free++; | ||
231 | - hotplug_event->free_function = pool_free; | ||
232 | - } | ||
233 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
234 | |||
235 | /* lookup if udev has something stored in its database */ | ||
236 | hotplug_event_udev = (HotplugEvent *) g_hash_table_lookup (sysfs_to_udev_map, sysfs_path); | ||
237 | if (hotplug_event_udev != NULL) { | ||
238 | memcpy(hotplug_event, hotplug_event_udev, sizeof(HotplugEvent)); | ||
239 | - if (from_pool) { | ||
240 | - hotplug_event->free_function = pool_free; | ||
241 | - } | ||
242 | HAL_INFO (("new event (dev node from udev) '%s' '%s'", hotplug_event->sysfs.sysfs_path, hotplug_event->sysfs.device_file)); | ||
243 | } else { | ||
244 | /* device is not in udev database */ | ||
245 | @@ -301,7 +273,7 @@ static int device_list_insert(const char *path, const char *subsystem, | ||
246 | if (!(statbuf.st_mode & S_IWUSR)) | ||
247 | goto error; | ||
248 | |||
249 | - sysfs_dev = g_new0 (struct sysfs_device, 1); | ||
250 | + sysfs_dev = g_slice_new0 (struct sysfs_device); | ||
251 | if (sysfs_dev == NULL) | ||
252 | goto error; | ||
253 | |||
254 | @@ -326,11 +298,11 @@ static int device_list_insert(const char *path, const char *subsystem, | ||
255 | sysfs_dev->path = g_strdup (path); | ||
256 | found: | ||
257 | sysfs_dev->subsystem = g_strdup (subsystem); | ||
258 | - device_list = g_slist_prepend (device_list, sysfs_dev); | ||
259 | + device_list = g_slist_append (device_list, sysfs_dev); | ||
260 | return 0; | ||
261 | |||
262 | error: | ||
263 | - g_free (sysfs_dev); | ||
264 | + g_slice_free (struct sysfs_device, sysfs_dev); | ||
265 | return -1; | ||
266 | } | ||
267 | |||
268 | @@ -512,7 +484,7 @@ static void queue_events(void) | ||
269 | |||
270 | g_free (sysfs_dev->path); | ||
271 | g_free (sysfs_dev->subsystem); | ||
272 | - g_free (sysfs_dev); | ||
273 | + g_slice_free (struct sysfs_device, sysfs_dev); | ||
274 | } | ||
275 | |||
276 | g_slist_free (device_list); | ||
277 | diff --git a/hald/linux/device.c b/hald/linux/device.c | ||
278 | index a59107f..cd7bc9e 100644 | ||
279 | --- a/hald/linux/device.c | ||
280 | +++ b/hald/linux/device.c | ||
281 | @@ -727,7 +727,7 @@ missing_scsi_host (const gchar *sysfs_path, HotplugEvent *device_event, HotplugA | ||
282 | |||
283 | /* fake host event */ | ||
284 | rc = TRUE; | ||
285 | - host_event = g_new0 (HotplugEvent, 1); | ||
286 | + host_event = g_slice_new0 (HotplugEvent); | ||
287 | host_event->action = action; | ||
288 | host_event->type = HOTPLUG_EVENT_SYSFS_DEVICE; | ||
289 | g_strlcpy (host_event->sysfs.subsystem, "scsi_host", sizeof (host_event->sysfs.subsystem)); | ||
290 | @@ -4085,7 +4085,7 @@ dev_generate_add_hotplug_event (HalDevice *d) | ||
291 | sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path"); | ||
292 | device_file = hal_device_property_get_string (d, "linux.device_file"); | ||
293 | |||
294 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
295 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
296 | hotplug_event->action = HOTPLUG_ACTION_ADD; | ||
297 | hotplug_event->type = HOTPLUG_EVENT_SYSFS; | ||
298 | g_strlcpy (hotplug_event->sysfs.subsystem, subsystem, sizeof (hotplug_event->sysfs.subsystem)); | ||
299 | @@ -4109,7 +4109,7 @@ dev_generate_remove_hotplug_event (HalDevice *d) | ||
300 | subsystem = hal_device_property_get_string (d, "linux.subsystem"); | ||
301 | sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path"); | ||
302 | |||
303 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
304 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
305 | hotplug_event->action = HOTPLUG_ACTION_REMOVE; | ||
306 | hotplug_event->type = HOTPLUG_EVENT_SYSFS; | ||
307 | g_strlcpy (hotplug_event->sysfs.subsystem, subsystem, sizeof (hotplug_event->sysfs.subsystem)); | ||
308 | diff --git a/hald/linux/hotplug.c b/hald/linux/hotplug.c | ||
309 | index 56db041..2dbc731 100644 | ||
310 | --- a/hald/linux/hotplug.c | ||
311 | +++ b/hald/linux/hotplug.c | ||
312 | @@ -62,11 +62,7 @@ hotplug_event_end (void *end_token) | ||
313 | |||
314 | hotplug_events_in_progress = g_slist_remove (hotplug_events_in_progress, hotplug_event); | ||
315 | |||
316 | - if (hotplug_event->free_function != NULL) { | ||
317 | - hotplug_event->free_function (hotplug_event); | ||
318 | - } else { | ||
319 | - g_free (hotplug_event); | ||
320 | - } | ||
321 | + g_slice_free (HotplugEvent, hotplug_event); | ||
322 | } | ||
323 | |||
324 | void | ||
325 | diff --git a/hald/linux/hotplug.h b/hald/linux/hotplug.h | ||
326 | index 27dc9d5..06a32a5 100644 | ||
327 | --- a/hald/linux/hotplug.h | ||
328 | +++ b/hald/linux/hotplug.h | ||
329 | @@ -57,9 +57,6 @@ typedef struct | ||
330 | HotplugActionType action; /* Whether the event is add or remove */ | ||
331 | HotplugEventType type; /* Type of event */ | ||
332 | gboolean reposted; /* Avoid loops */ | ||
333 | - | ||
334 | - void (*free_function) (gpointer data); | ||
335 | - | ||
336 | union { | ||
337 | struct { | ||
338 | char subsystem[HAL_NAME_MAX]; /* Kernel subsystem the device belongs to */ | ||
339 | diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c | ||
340 | index d7a8672..9ba1a5c 100644 | ||
341 | --- a/hald/linux/osspec.c | ||
342 | +++ b/hald/linux/osspec.c | ||
343 | @@ -121,7 +121,7 @@ hald_udev_data (GIOChannel *source, GIOCondition condition, gpointer user_data) | ||
344 | goto out; | ||
345 | } | ||
346 | |||
347 | - hotplug_event = g_new0 (HotplugEvent, 1); | ||
348 | + hotplug_event = g_slice_new0 (HotplugEvent); | ||
349 | hotplug_event->type = HOTPLUG_EVENT_SYSFS; | ||
350 | |||
351 | while (bufpos < sizeof (buf)) { | ||
352 | @@ -263,7 +263,7 @@ hald_udev_data (GIOChannel *source, GIOCondition condition, gpointer user_data) | ||
353 | } | ||
354 | |||
355 | invalid: | ||
356 | - g_free (hotplug_event); | ||
357 | + g_slice_free (HotplugEvent, hotplug_event); | ||
358 | |||
359 | out: | ||
360 | return TRUE; | ||
361 | -- | ||
362 | 1.5.3.7 | ||
363 |