1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

more fixes

This commit is contained in:
Alasdair Kergon 2007-01-16 23:03:13 +00:00
parent f6af1a67b5
commit 5611829c89
3 changed files with 60 additions and 39 deletions

View File

@ -1005,40 +1005,55 @@ static int _want_registered_device(char *dso_name, char *device_uuid,
/* If DSO names and device paths are equal. */ /* If DSO names and device paths are equal. */
if (dso_name && device_uuid) if (dso_name && device_uuid)
return !strcmp(dso_name, thread->dso_data->dso_name) && return !strcmp(dso_name, thread->dso_data->dso_name) &&
!strcmp(device_uuid, thread->device.uuid); !strcmp(device_uuid, thread->device.uuid) &&
(thread->status == DM_THREAD_RUNNING ||
(thread->events & DM_EVENT_REGISTRATION_PENDING));
/* If DSO names are equal. */ /* If DSO names are equal. */
if (dso_name) if (dso_name)
return !strcmp(dso_name, thread->dso_data->dso_name); return !strcmp(dso_name, thread->dso_data->dso_name) &&
(thread->status == DM_THREAD_RUNNING ||
(thread->events & DM_EVENT_REGISTRATION_PENDING));
/* If device paths are equal. */ /* If device paths are equal. */
if (device_uuid) if (device_uuid)
return !strcmp(device_uuid, thread->device.uuid); return !strcmp(device_uuid, thread->device.uuid) &&
(thread->status == DM_THREAD_RUNNING ||
(thread->events & DM_EVENT_REGISTRATION_PENDING));
return 1; return 1;
} }
static int _get_registered_dev(struct message_data *message_data, int next) static int _get_registered_dev(struct message_data *message_data, int next)
{ {
int hit = 0; struct thread_status *thread, *hit = NULL;
struct thread_status *thread;
_lock_mutex(); _lock_mutex();
/* Iterate list of threads checking if we want a particular one. */ /* Iterate list of threads checking if we want a particular one. */
list_iterate_items(thread, &_thread_registry) list_iterate_items(thread, &_thread_registry)
if ((hit = _want_registered_device(message_data->dso_name, if (_want_registered_device(message_data->dso_name,
message_data->device_uuid, message_data->device_uuid,
thread))) thread)) {
break; hit = thread;
break;
}
/* /*
* If we got a registered device and want the next one -> * If we got a registered device and want the next one ->
* fetch next conforming element off the list. * fetch next conforming element off the list.
*/ */
if (!hit || !next) if (hit && !next) {
_unlock_mutex();
return _registered_device(message_data, hit);
}
if (!hit)
goto out; goto out;
goto out; /* FIXME the next == 1 thing is currently horridly
broken, do something about it... */
do { do {
if (list_end(&_thread_registry, &thread->list)) if (list_end(&_thread_registry, &thread->list))
goto out; goto out;
@ -1046,6 +1061,7 @@ static int _get_registered_dev(struct message_data *message_data, int next)
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)); } while (!_want_registered_device(message_data->dso_name, NULL, thread));
_unlock_mutex();
return _registered_device(message_data, thread); return _registered_device(message_data, thread);
out: out:

View File

@ -556,12 +556,12 @@ static char *_fetch_string(char **src, const int delimiter)
/* Parse a device message from the daemon. */ /* Parse a device message from the daemon. */
static int _parse_message(struct dm_event_daemon_message *msg, char **dso_name, static int _parse_message(struct dm_event_daemon_message *msg, char **dso_name,
char **dev_name, enum dm_event_mask *evmask) char **uuid, enum dm_event_mask *evmask)
{ {
char *p = msg->data; char *p = msg->data;
if ((*dso_name = _fetch_string(&p, ' ')) && if ((*dso_name = _fetch_string(&p, ' ')) &&
(*dev_name = _fetch_string(&p, ' '))) { (*uuid = _fetch_string(&p, ' '))) {
*evmask = atoi(p); *evmask = atoi(p);
return 0; return 0;
@ -577,41 +577,45 @@ static int _parse_message(struct dm_event_daemon_message *msg, char **dso_name,
* @mask * @mask
* @next * @next
* *
* FIXME: This function sucks. * Returns: 0 if handler found, error (-ENOMEM, -ENOENT) otherwise
*
* Returns: 1 if device found, 0 otherwise (even on error)
*/ */
int dm_event_get_registered_device(char **dso_name, char **device_path, int dm_event_get_registered_device(struct dm_event_handler *dmevh, int next)
enum dm_event_mask *mask, int next)
{ {
int ret; int ret;
char *dso_name_arg = NULL, *device_path_arg = NULL; char *uuid = NULL;
char *reply_dso = NULL, *reply_uuid = NULL;
enum dm_event_mask reply_mask;
struct dm_task *dmt;
struct dm_event_daemon_message msg; struct dm_event_daemon_message msg;
if (!(dmt = _get_device_info(dmevh))) {
stack;
return 0;
}
uuid = dm_task_get_uuid(dmt);
if (!(ret = _do_event(next ? DM_EVENT_CMD_GET_NEXT_REGISTERED_DEVICE : if (!(ret = _do_event(next ? DM_EVENT_CMD_GET_NEXT_REGISTERED_DEVICE :
DM_EVENT_CMD_GET_REGISTERED_DEVICE, DM_EVENT_CMD_GET_REGISTERED_DEVICE,
&msg, *dso_name, *device_path, *mask, 0))) { &msg, dmevh->dso, uuid, dmevh->mask, 0))) {
ret = !_parse_message(&msg, &dso_name_arg, &device_path_arg, /* FIXME this will probably horribly break if we get
mask); ill-formatted reply */
} else /* FIXME: Make sure this is ENOENT */ ret = _parse_message(&msg, &reply_dso, &reply_uuid, &reply_mask);
ret = 0; } else
ret = -ENOENT;
if (msg.data) if (msg.data)
dm_free(msg.data); dm_free(msg.data);
if (next) { dm_event_handler_set_uuid(dmevh, reply_uuid);
if (*dso_name) dm_event_handler_set_dso(dmevh, reply_dso);
dm_free(*dso_name); dm_event_handler_set_event_mask(dmevh, reply_mask);
if (*device_path) /* FIXME also fill in name and device number */
dm_free(*device_path); /* FIXME this probably leaks memory, since noone is going to
*dso_name = dso_name_arg; dm_free the bits in dmevh -- needs changes to
*device_path = device_path_arg; dm_event_handle_set behaviour */
} else {
if (!(*dso_name)) dm_task_destroy(dmt);
*dso_name = dso_name_arg;
if (!(*device_path))
*device_path = device_path_arg;
}
return ret; return ret;
} }

View File

@ -60,6 +60,8 @@ void dm_event_handler_set_dso(struct dm_event_handler *dmevh, const char *path);
/* /*
* Identify the device to monitor by exactly one of * Identify the device to monitor by exactly one of
* dev_name, uuid or device number. * dev_name, uuid or device number.
* FIXME we should give guarantees about how dev_name and uuid
* pontiers are handled, eg dm_strdup them
*/ */
void dm_event_handler_set_dev_name(struct dm_event_handler *dmevh, const char *dev_name); void dm_event_handler_set_dev_name(struct dm_event_handler *dmevh, const char *dev_name);
@ -81,9 +83,8 @@ int dm_event_handler_get_major(const struct dm_event_handler *dmevh);
int dm_event_handler_get_minor(const struct dm_event_handler *dmevh); int dm_event_handler_get_minor(const struct dm_event_handler *dmevh);
enum dm_event_mask dm_event_handler_get_event_mask(const struct dm_event_handler *dmevh); enum dm_event_mask dm_event_handler_get_event_mask(const struct dm_event_handler *dmevh);
/* FIXME Review interface */ /* FIXME Review interface (what about this next thing?) */
int dm_event_get_registered_device(char **dso_name, char **device_path, int dm_event_get_registered_device(struct dm_event_handler *dmevh, int next);
enum dm_event_mask *evmask, int next);
/* /*
* Initiate monitoring using dmeventd. * Initiate monitoring using dmeventd.