1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-18 10:04:20 +03:00

updated dmeventd interface

This commit is contained in:
Alasdair Kergon 2007-01-11 22:24:32 +00:00
parent 3165248642
commit 6b36e863cb
4 changed files with 41 additions and 54 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.18 - Version 2.02.18 -
==================================== ====================================
Revised libdevmapper-event interface for dmeventd.
Remove dmeventd mirror status line word limit. Remove dmeventd mirror status line word limit.
Use CFLAGS when linking so mixed sparc builds can supply -m64. Use CFLAGS when linking so mixed sparc builds can supply -m64.
Prevent permission changes on active mirrors. Prevent permission changes on active mirrors.

View File

@ -161,34 +161,18 @@ static int _remove_failed_devices(const char *device)
return (r == 1) ? 0 : -1; return (r == 1) ? 0 : -1;
} }
void process_event(const char *device, enum dm_event_type event) void process_event(struct dm_task *dmt, enum dm_event_type event)
{ {
struct dm_task *dmt;
void *next = NULL; void *next = NULL;
uint64_t start, length; uint64_t start, length;
char *target_type = NULL; char *target_type = NULL;
char *params; char *params;
const char *device = dm_task_get_name(dmt);
if (pthread_mutex_trylock(&_event_mutex)) { if (pthread_mutex_trylock(&_event_mutex)) {
syslog(LOG_NOTICE, "Another thread is handling an event. Waiting..."); syslog(LOG_NOTICE, "Another thread is handling an event. Waiting...");
pthread_mutex_lock(&_event_mutex); pthread_mutex_lock(&_event_mutex);
} }
/* FIXME Move inside libdevmapper */
if (!(dmt = dm_task_create(DM_DEVICE_STATUS))) {
syslog(LOG_ERR, "Unable to create dm_task.\n");
goto fail;
}
if (!dm_task_set_name(dmt, device)) {
syslog(LOG_ERR, "Unable to set device name.\n");
goto fail;
}
if (!dm_task_run(dmt)) {
syslog(LOG_ERR, "Unable to run task.\n");
goto fail;
}
do { do {
next = dm_get_next_target(dmt, next, &start, &length, next = dm_get_next_target(dmt, next, &start, &length,
&target_type, &params); &target_type, &params);
@ -226,24 +210,21 @@ void process_event(const char *device, enum dm_event_type event)
case ME_IGNORE: case ME_IGNORE:
break; break;
default: default:
/* FIXME Wrong: it can also return -E2BIG but it's never used! */ /* FIXME Provide value then! */
syslog(LOG_INFO, "Unknown event received.\n"); syslog(LOG_INFO, "Unknown event received.\n");
} }
} while (next); } while (next);
fail:
if (dmt)
dm_task_destroy(dmt);
pthread_mutex_unlock(&_event_mutex); pthread_mutex_unlock(&_event_mutex);
} }
int register_device(const char *device) int register_device(const char *device, const char *uuid, int major, int minor)
{ {
int r = 0; int r = 0;
pthread_mutex_lock(&_register_mutex); pthread_mutex_lock(&_register_mutex);
syslog(LOG_INFO, "Monitoring mirror device, %s for events\n", device); syslog(LOG_INFO, "Monitoring mirror device %s for events\n", device);
/* /*
* Need some space for allocations. 1024 should be more * Need some space for allocations. 1024 should be more
@ -273,10 +254,13 @@ out:
return r; return r;
} }
int unregister_device(const char *device) int unregister_device(const char *device, const char *uuid, int major, int minor)
{ {
pthread_mutex_lock(&_register_mutex); pthread_mutex_lock(&_register_mutex);
syslog(LOG_INFO, "No longer monitoring mirror device %s for events\n",
device);
if (!--_register_count) { if (!--_register_count) {
dm_pool_destroy(_mem_pool); dm_pool_destroy(_mem_pool);
_mem_pool = NULL; _mem_pool = NULL;

View File

@ -161,34 +161,18 @@ static int _remove_failed_devices(const char *device)
return (r == 1) ? 0 : -1; return (r == 1) ? 0 : -1;
} }
void process_event(const char *device, enum dm_event_type event) void process_event(struct dm_task *dmt, enum dm_event_type event)
{ {
struct dm_task *dmt;
void *next = NULL; void *next = NULL;
uint64_t start, length; uint64_t start, length;
char *target_type = NULL; char *target_type = NULL;
char *params; char *params;
const char *device = dm_task_get_name(dmt);
if (pthread_mutex_trylock(&_event_mutex)) { if (pthread_mutex_trylock(&_event_mutex)) {
syslog(LOG_NOTICE, "Another thread is handling an event. Waiting..."); syslog(LOG_NOTICE, "Another thread is handling an event. Waiting...");
pthread_mutex_lock(&_event_mutex); pthread_mutex_lock(&_event_mutex);
} }
/* FIXME Move inside libdevmapper */
if (!(dmt = dm_task_create(DM_DEVICE_STATUS))) {
syslog(LOG_ERR, "Unable to create dm_task.\n");
goto fail;
}
if (!dm_task_set_name(dmt, device)) {
syslog(LOG_ERR, "Unable to set device name.\n");
goto fail;
}
if (!dm_task_run(dmt)) {
syslog(LOG_ERR, "Unable to run task.\n");
goto fail;
}
do { do {
next = dm_get_next_target(dmt, next, &start, &length, next = dm_get_next_target(dmt, next, &start, &length,
&target_type, &params); &target_type, &params);
@ -226,24 +210,21 @@ void process_event(const char *device, enum dm_event_type event)
case ME_IGNORE: case ME_IGNORE:
break; break;
default: default:
/* FIXME Wrong: it can also return -E2BIG but it's never used! */ /* FIXME Provide value then! */
syslog(LOG_INFO, "Unknown event received.\n"); syslog(LOG_INFO, "Unknown event received.\n");
} }
} while (next); } while (next);
fail:
if (dmt)
dm_task_destroy(dmt);
pthread_mutex_unlock(&_event_mutex); pthread_mutex_unlock(&_event_mutex);
} }
int register_device(const char *device) int register_device(const char *device, const char *uuid, int major, int minor)
{ {
int r = 0; int r = 0;
pthread_mutex_lock(&_register_mutex); pthread_mutex_lock(&_register_mutex);
syslog(LOG_INFO, "Monitoring mirror device, %s for events\n", device); syslog(LOG_INFO, "Monitoring mirror device %s for events\n", device);
/* /*
* Need some space for allocations. 1024 should be more * Need some space for allocations. 1024 should be more
@ -273,10 +254,13 @@ out:
return r; return r;
} }
int unregister_device(const char *device) int unregister_device(const char *device, const char *uuid, int major, int minor)
{ {
pthread_mutex_lock(&_register_mutex); pthread_mutex_lock(&_register_mutex);
syslog(LOG_INFO, "No longer monitoring mirror device %s for events\n",
device);
if (!--_register_count) { if (!--_register_count) {
dm_pool_destroy(_mem_pool); dm_pool_destroy(_mem_pool);
_mem_pool = NULL; _mem_pool = NULL;

View File

@ -397,6 +397,7 @@ static int _target_register_events(struct lv_segment *seg,
char *dso, *name; char *dso, *name;
struct logical_volume *lv; struct logical_volume *lv;
struct volume_group *vg; struct volume_group *vg;
struct dm_event_handler *handler;
lv = seg->lv; lv = seg->lv;
vg = lv->vg; vg = lv->vg;
@ -409,10 +410,18 @@ static int _target_register_events(struct lv_segment *seg,
if (!(name = build_dm_name(vg->cmd->mem, vg->name, lv->name, NULL))) if (!(name = build_dm_name(vg->cmd->mem, vg->name, lv->name, NULL)))
return_0; return_0;
/* FIXME Save a returned handle here so we can unregister it later */ if (!(handler = dm_event_handler_create()))
if (!dm_event_register(dso, name, DM_EVENT_ALL_ERRORS))
return_0; return_0;
dm_event_handler_set_dso(handler, dso);
dm_event_handler_set_name(handler, name);
dm_event_handler_set_events(handler, DM_EVENT_ALL_ERRORS);
if (!dm_event_register(handler)) {
dm_event_handler_destroy(handler);
return_0;
}
dm_event_handler_destroy(handler);
log_info("Registered %s for events", name); log_info("Registered %s for events", name);
return 1; return 1;
@ -425,6 +434,7 @@ static int _target_unregister_events(struct lv_segment *seg,
char *name; char *name;
struct logical_volume *lv; struct logical_volume *lv;
struct volume_group *vg; struct volume_group *vg;
struct dm_event_handler *handler;
lv = seg->lv; lv = seg->lv;
vg = lv->vg; vg = lv->vg;
@ -436,10 +446,18 @@ static int _target_unregister_events(struct lv_segment *seg,
if (!(name = build_dm_name(vg->cmd->mem, vg->name, lv->name, NULL))) if (!(name = build_dm_name(vg->cmd->mem, vg->name, lv->name, NULL)))
return_0; return_0;
/* FIXME Use handle returned by registration function instead of dso */ if (!(handler = dm_event_handler_create()))
if (!dm_event_unregister(dso, name, DM_EVENT_ALL_ERRORS))
return_0; return_0;
dm_event_handler_set_dso(handler, dso);
dm_event_handler_set_name(handler, name);
dm_event_handler_set_events(handler, DM_EVENT_ALL_ERRORS);
if (!dm_event_unregister(handler)) {
dm_event_handler_destroy(handler);
return_0;
}
dm_event_handler_destroy(handler);
log_info("Unregistered %s for events", name); log_info("Unregistered %s for events", name);
return 1; return 1;