mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
add a dso-private variable to dmeventd interface
more inline docn
This commit is contained in:
parent
ee6e6529ee
commit
b1d32a03c7
@ -1,5 +1,6 @@
|
|||||||
Version 1.02.16 -
|
Version 1.02.16 -
|
||||||
===================================
|
===================================
|
||||||
|
Add a dso-private variable to dmeventd dso interface.
|
||||||
Add dm_event_handler_[gs]et_timeout functions.
|
Add dm_event_handler_[gs]et_timeout functions.
|
||||||
Streamline dm_report_field_* interface.
|
Streamline dm_report_field_* interface.
|
||||||
Add cmdline debug & version options to dmeventd.
|
Add cmdline debug & version options to dmeventd.
|
||||||
|
@ -77,6 +77,19 @@ static int _debug = 0;
|
|||||||
*/
|
*/
|
||||||
static pthread_mutex_t _global_mutex;
|
static pthread_mutex_t _global_mutex;
|
||||||
|
|
||||||
|
/*
|
||||||
|
There are three states a thread can attain (see struct
|
||||||
|
thread_status, field int status):
|
||||||
|
|
||||||
|
- DM_THREAD_RUNNING: thread has started up and is either working or
|
||||||
|
waiting for events... transitions to either SHUTDOWN or DONE
|
||||||
|
- DM_THREAD_SHUTDOWN: thread is still doing something, but it is
|
||||||
|
supposed to terminate (and transition to DONE) as soon as it
|
||||||
|
finishes whatever it was doing at the point of flipping state to
|
||||||
|
SHUTDOWN... the thread is still on the thread list
|
||||||
|
- DM_THREAD_DONE: thread has terminated and has been moved over to
|
||||||
|
unused thread list, cleanup pending
|
||||||
|
*/
|
||||||
#define DM_THREAD_RUNNING 0
|
#define DM_THREAD_RUNNING 0
|
||||||
#define DM_THREAD_SHUTDOWN 1
|
#define DM_THREAD_SHUTDOWN 1
|
||||||
#define DM_THREAD_DONE 2
|
#define DM_THREAD_DONE 2
|
||||||
@ -106,7 +119,7 @@ struct dso_data {
|
|||||||
* DM_DEVICE_STATUS). It should not destroy it.
|
* DM_DEVICE_STATUS). It should not destroy it.
|
||||||
* The caller must dispose of the task.
|
* The caller must dispose of the task.
|
||||||
*/
|
*/
|
||||||
void (*process_event)(struct dm_task *dmt, enum dm_event_mask event);
|
void (*process_event)(struct dm_task *dmt, enum dm_event_mask event, void **user);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Device registration.
|
* Device registration.
|
||||||
@ -117,7 +130,7 @@ struct dso_data {
|
|||||||
* and activate a mapping).
|
* and activate a mapping).
|
||||||
*/
|
*/
|
||||||
int (*register_device)(const char *device, const char *uuid, int major,
|
int (*register_device)(const char *device, const char *uuid, int major,
|
||||||
int minor);
|
int minor, void **user);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Device unregistration.
|
* Device unregistration.
|
||||||
@ -127,7 +140,7 @@ struct dso_data {
|
|||||||
* steps (eg, deactivate mapping, metadata update).
|
* steps (eg, deactivate mapping, metadata update).
|
||||||
*/
|
*/
|
||||||
int (*unregister_device)(const char *device, const char *uuid,
|
int (*unregister_device)(const char *device, const char *uuid,
|
||||||
int major, int minor);
|
int major, int minor, void **user);
|
||||||
};
|
};
|
||||||
static LIST_INIT(_dso_registry);
|
static LIST_INIT(_dso_registry);
|
||||||
|
|
||||||
@ -166,13 +179,16 @@ struct thread_status {
|
|||||||
} device;
|
} device;
|
||||||
uint32_t event_nr; /* event number */
|
uint32_t event_nr; /* event number */
|
||||||
int processing; /* Set when event is being processed */
|
int processing; /* Set when event is being processed */
|
||||||
int status; /* running/shutdown/done */
|
|
||||||
|
int status; /* see DM_THREAD_{RUNNING,SHUTDOWN,DONE}
|
||||||
|
constants above */
|
||||||
enum dm_event_mask events; /* bitfield for event filter. */
|
enum dm_event_mask events; /* bitfield for event filter. */
|
||||||
enum dm_event_mask current_events; /* bitfield for occured events. */
|
enum dm_event_mask current_events; /* bitfield for occured events. */
|
||||||
struct dm_task *current_task;
|
struct dm_task *current_task;
|
||||||
time_t next_time;
|
time_t next_time;
|
||||||
uint32_t timeout;
|
uint32_t timeout;
|
||||||
struct list timeout_list;
|
struct list timeout_list;
|
||||||
|
void *dso_private; /* dso per-thread status variable */
|
||||||
};
|
};
|
||||||
static LIST_INIT(_thread_registry);
|
static LIST_INIT(_thread_registry);
|
||||||
static LIST_INIT(_thread_registry_unused);
|
static LIST_INIT(_thread_registry_unused);
|
||||||
@ -630,7 +646,8 @@ static int _do_register_device(struct thread_status *thread)
|
|||||||
return thread->dso_data->register_device(thread->device.name,
|
return thread->dso_data->register_device(thread->device.name,
|
||||||
thread->device.uuid,
|
thread->device.uuid,
|
||||||
thread->device.major,
|
thread->device.major,
|
||||||
thread->device.minor);
|
thread->device.minor,
|
||||||
|
&(thread->dso_private));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unregister a device with the DSO. */
|
/* Unregister a device with the DSO. */
|
||||||
@ -639,13 +656,14 @@ static int _do_unregister_device(struct thread_status *thread)
|
|||||||
return thread->dso_data->unregister_device(thread->device.name,
|
return thread->dso_data->unregister_device(thread->device.name,
|
||||||
thread->device.uuid,
|
thread->device.uuid,
|
||||||
thread->device.major,
|
thread->device.major,
|
||||||
thread->device.minor);
|
thread->device.minor,
|
||||||
|
&(thread->dso_private));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process an event in the DSO. */
|
/* Process an event in the DSO. */
|
||||||
static void _do_process_event(struct thread_status *thread, struct dm_task *task)
|
static void _do_process_event(struct thread_status *thread, struct dm_task *task)
|
||||||
{
|
{
|
||||||
thread->dso_data->process_event(task, thread->current_events);
|
thread->dso_data->process_event(task, thread->current_events, &(thread->dso_private));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Thread cleanup handler to unregister device. */
|
/* Thread cleanup handler to unregister device. */
|
||||||
@ -1107,22 +1125,25 @@ static int _get_registered_dev(struct message_data *message_data, int next)
|
|||||||
if (!hit)
|
if (!hit)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
goto out; /* FIXME the next == 1 thing is currently horridly
|
thread = hit;
|
||||||
broken, do something about it... */
|
|
||||||
|
|
||||||
do {
|
while (1) {
|
||||||
if (list_end(&_thread_registry, &thread->list))
|
if (list_end(&_thread_registry, &thread->list))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
thread = list_item(thread->list.n, struct thread_status);
|
thread = list_item(thread->list.n, struct thread_status);
|
||||||
} while (!_want_registered_device(message_data->dso_name, NULL, thread));
|
if (_want_registered_device(message_data->dso_name, NULL, thread)) {
|
||||||
|
hit = thread;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_unlock_mutex();
|
_unlock_mutex();
|
||||||
return _registered_device(message_data, thread);
|
return _registered_device(message_data, hit);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
_unlock_mutex();
|
_unlock_mutex();
|
||||||
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,9 +98,9 @@ int dm_event_unregister_handler(const struct dm_event_handler *dmevh);
|
|||||||
|
|
||||||
/* Prototypes for DSO interface, see dmeventd.c, struct dso_data for
|
/* Prototypes for DSO interface, see dmeventd.c, struct dso_data for
|
||||||
detailed descriptions. */
|
detailed descriptions. */
|
||||||
void process_event(struct dm_task *dmt, enum dm_event_mask evmask);
|
void process_event(struct dm_task *dmt, enum dm_event_mask evmask, void **user);
|
||||||
int register_device(const char *device_name, const char *uuid, int major, int minor);
|
int register_device(const char *device_name, const char *uuid, int major, int minor, void **user);
|
||||||
int unregister_device(const char *device_name, const char *uuid, int major,
|
int unregister_device(const char *device_name, const char *uuid, int major,
|
||||||
int minor);
|
int minor, void **user);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -757,8 +757,7 @@ int dm_report_output(struct dm_report *rh)
|
|||||||
/* Print and clear buffer */
|
/* Print and clear buffer */
|
||||||
list_iterate_safe(rowh, rtmp, &rh->rows) {
|
list_iterate_safe(rowh, rtmp, &rh->rows) {
|
||||||
if (!dm_pool_begin_object(rh->mem, 512)) {
|
if (!dm_pool_begin_object(rh->mem, 512)) {
|
||||||
log_error("dm_report: "
|
log_error("dm_report: Unable to allocate output line");
|
||||||
"dm_pool_begin_object failed for row");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
row = list_item(rowh, struct row);
|
row = list_item(rowh, struct row);
|
||||||
@ -771,35 +770,48 @@ int dm_report_output(struct dm_report *rh)
|
|||||||
width = field->props->width;
|
width = field->props->width;
|
||||||
if (!(rh->flags & DM_REPORT_OUTPUT_ALIGNED)) {
|
if (!(rh->flags & DM_REPORT_OUTPUT_ALIGNED)) {
|
||||||
if (!dm_pool_grow_object(rh->mem, repstr,
|
if (!dm_pool_grow_object(rh->mem, repstr,
|
||||||
strlen(repstr)))
|
strlen(repstr))) {
|
||||||
goto bad_grow;
|
log_error("dm_report: Unable to extend output line");
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!(align = field->props->flags & DM_REPORT_FIELD_ALIGN_MASK))
|
if (!(align = field->props->flags & DM_REPORT_FIELD_ALIGN_MASK))
|
||||||
align = (field->props->flags & DM_REPORT_FIELD_TYPE_NUMBER) ?
|
align = (field->props->flags & DM_REPORT_FIELD_TYPE_NUMBER) ?
|
||||||
DM_REPORT_FIELD_ALIGN_RIGHT : DM_REPORT_FIELD_ALIGN_LEFT;
|
DM_REPORT_FIELD_ALIGN_RIGHT : DM_REPORT_FIELD_ALIGN_LEFT;
|
||||||
if (align & DM_REPORT_FIELD_ALIGN_LEFT) {
|
if (align & DM_REPORT_FIELD_ALIGN_LEFT) {
|
||||||
if (dm_snprintf(buf, sizeof(buf), "%-*.*s",
|
if (dm_snprintf(buf, sizeof(buf), "%-*.*s",
|
||||||
width, width, repstr) < 0)
|
width, width, repstr) < 0) {
|
||||||
goto bad_snprintf;
|
log_error("dm_report: left-aligned snprintf() failed");
|
||||||
if (!dm_pool_grow_object(rh->mem, buf, width))
|
goto bad;
|
||||||
goto bad_grow;
|
}
|
||||||
|
if (!dm_pool_grow_object(rh->mem, buf, width)) {
|
||||||
|
log_error("dm_report: Unable to extend output line");
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
} else if (align & DM_REPORT_FIELD_ALIGN_RIGHT) {
|
} else if (align & DM_REPORT_FIELD_ALIGN_RIGHT) {
|
||||||
if (dm_snprintf(buf, sizeof(buf), "%*.*s",
|
if (dm_snprintf(buf, sizeof(buf), "%*.*s",
|
||||||
width, width, repstr) < 0)
|
width, width, repstr) < 0) {
|
||||||
goto bad_snprintf;
|
log_error("dm_report: right-aligned snprintf() failed");
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
if (!dm_pool_grow_object(rh->mem, buf, width))
|
if (!dm_pool_grow_object(rh->mem, buf, width))
|
||||||
goto bad_grow;
|
log_error("dm_report: Unable to extend output line");
|
||||||
|
goto bad;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!list_end(&row->fields, fh))
|
if (!list_end(&row->fields, fh))
|
||||||
if (!dm_pool_grow_object(rh->mem, rh->separator,
|
if (!dm_pool_grow_object(rh->mem, rh->separator,
|
||||||
strlen(rh->separator)))
|
strlen(rh->separator))) {
|
||||||
goto bad_grow;
|
log_error("dm_report: Unable to extend output line");
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
list_del(&field->list);
|
list_del(&field->list);
|
||||||
}
|
}
|
||||||
if (!dm_pool_grow_object(rh->mem, "\0", 1))
|
if (!dm_pool_grow_object(rh->mem, "\0", 1)) {
|
||||||
goto bad_grow;
|
log_error("dm_report: Unable to terminate output line");
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
log_print("%s", (char *) dm_pool_end_object(rh->mem));
|
log_print("%s", (char *) dm_pool_end_object(rh->mem));
|
||||||
list_del(&row->list);
|
list_del(&row->list);
|
||||||
}
|
}
|
||||||
@ -809,10 +821,7 @@ int dm_report_output(struct dm_report *rh)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
bad_snprintf:
|
bad:
|
||||||
log_error("dm_report: snprintf row failed");
|
|
||||||
bad_grow:
|
|
||||||
log_error("dm_report: Failed to generate row for printing");
|
|
||||||
dm_pool_abandon_object(rh->mem);
|
dm_pool_abandon_object(rh->mem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user