Udev integration: add semaphore IPC to wait for udev rule completion
PATCH 2/4 Udev integration: add semaphore IPC to wait for udev rule completion
This patch adds simple IPC support (using semaphores) to set a communication channel between a udev rule and the process that waits for its completion.
We generate random unsigned 32 bit variable (cookie) which we use to identify the semaphore. When dealing with DM trees, we don't have to set a new IPC, we just reuse the existing one, increasing the semaphore's value. Each udev's rule completion is notified by decreasing this value. So we're waiting on zero in the process that fired off the actions.
Peter
libdm/.exported_symbols +6 -0
@@ -21,6 +21,7 @@ dm_task_get_uuid dm_task_get_read_ahead dm_task_set_ro dm_task_set_newname +dm_task_set_cookie dm_task_set_event_nr dm_task_set_major dm_task_set_minor
@@ -149,3 +150,8 @@ dm_list_last dm_list_prev dm_list_next dm_list_size +dm_notification_sem_open +dm_notification_sem_inc +dm_notification_sem_dec +dm_notification_sem_wait_zero +dm_notification_sem_close
libdm/ioctl/libdm-iface.c +7 -0
@@ -864,6 +864,13 @@ int dm_check_version(void)return 0 ; } +int dm_cookie_supported () +{ +return (dm_check_version () && + _dm_version >=4 && + _dm_version_minor >=15 ); +} +void *dm_get_next_target (struct dm_task *dmt,void *next,uint64_t *start,uint64_t *length,char **target_type,char **params)
libdm/libdevmapper.h +16 -0
@@ -155,6 +155,7 @@ int dm_task_set_major(struct dm_task *dmt, int major);int dm_task_set_uid (struct dm_task *dmt,uid_t uid);int dm_task_set_gid (struct dm_task *dmt,gid_t gid);int dm_task_set_mode (struct dm_task *dmt,mode_t mode); +int dm_task_set_cookie (struct dm_task *dmt,uint32_t cookie);int dm_task_set_event_nr (struct dm_task *dmt,uint32_t event_nr);int dm_task_set_geometry (struct dm_task *dmt,const char *cylinders,const char *heads,const char *sectors,const char *start);int dm_task_set_message (struct dm_task *dmt,const char *message);
@@ -985,4 +986,19 @@ int dm_report_field_uint64(struct dm_report *rh, struct dm_report_field *field,void dm_report_field_set_value (struct dm_report_field *field,const void *value,const void *sortvalue); +int dm_cookie_supported (); + +/* +* Functions to set simple notification channel between instances of libdm +* code by means of using semaphore identified by a cookie. Primarily used +* to provide a way of notification that related udev rule is completed as +* a consequence of libdm actions fired before and marked by the value of +* the cookie. +*/ +int dm_notification_sem_open (uint32_t *cookie); +int dm_notification_sem_inc (uint32_t cookie); +int dm_notification_sem_dec (uint32_t cookie); +int dm_notification_sem_wait_zero (uint32_t cookie); +int dm_notification_sem_close (uint32_t cookie); +#endif /* LIB_DEVICE_MAPPER_H */
libdm/libdm-common.c +147 -0
162 lines not on this page · raw message