mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Timeout event implementation:
The daemon side of this is mostly the same as the patch I sent out. To select a timeout period different than the default and to get the timeout period, I added two library calls, dm_set_event_timeout() and dm_get_event_timeout(). If people are against them, the other option is to tack extra arguments onto dm_regiser_for_event() and dm_get_registered_device(). I also added a -t option to dmevent, so people can try out timeouts.
This commit is contained in:
parent
5748cb17f8
commit
5469414bf8
@ -30,6 +30,7 @@
|
|||||||
static enum event_type events = ALL_ERRORS; /* All until we can distinguish. */
|
static enum event_type events = ALL_ERRORS; /* All until we can distinguish. */
|
||||||
static char default_dso_name[] = "noop"; /* default DSO is noop */
|
static char default_dso_name[] = "noop"; /* default DSO is noop */
|
||||||
static int default_reg = 1; /* default action is register */
|
static int default_reg = 1; /* default action is register */
|
||||||
|
static uint32_t timeout;
|
||||||
|
|
||||||
/* Display help. */
|
/* Display help. */
|
||||||
static void print_usage(char *name)
|
static void print_usage(char *name)
|
||||||
@ -45,6 +46,7 @@ static void print_usage(char *name)
|
|||||||
" -h Print this usage.\n"
|
" -h Print this usage.\n"
|
||||||
" -l List registered devices.\n"
|
" -l List registered devices.\n"
|
||||||
" -r Register for event (default).\n"
|
" -r Register for event (default).\n"
|
||||||
|
" -t <timeout> (un)register for timeout event.\n"
|
||||||
" -u Unregister for event.\n"
|
" -u Unregister for event.\n"
|
||||||
"\n", cmd);
|
"\n", cmd);
|
||||||
}
|
}
|
||||||
@ -54,7 +56,7 @@ static int parse_argv(int argc, char **argv, char **dso_name_arg,
|
|||||||
char **device_arg, int *reg, int *list)
|
char **device_arg, int *reg, int *list)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
const char *options = "d:hlru";
|
const char *options = "d:hlrt:u";
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, options)) != -1) {
|
while ((c = getopt(argc, argv, options)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@ -70,6 +72,14 @@ static int parse_argv(int argc, char **argv, char **dso_name_arg,
|
|||||||
case 'r':
|
case 'r':
|
||||||
*reg = 1;
|
*reg = 1;
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
events = TIMEOUT;
|
||||||
|
if (sscanf(optarg, "%"SCNu32, &timeout) != 1){
|
||||||
|
fprintf(stderr, "invalid timeout '%s'\n",
|
||||||
|
optarg);
|
||||||
|
timeout = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
*reg = 0;
|
*reg = 0;
|
||||||
break;
|
break;
|
||||||
@ -119,19 +129,25 @@ int main(int argc, char **argv)
|
|||||||
multilog_init_verbose(standard, _LOG_DEBUG);
|
multilog_init_verbose(standard, _LOG_DEBUG);
|
||||||
|
|
||||||
if (list) {
|
if (list) {
|
||||||
do {
|
while (1) {
|
||||||
if (!(ret= dm_get_registered_device(&dso_name,
|
if ((ret= dm_get_registered_device(&dso_name, &device,
|
||||||
&device,
|
&events, next)))
|
||||||
&events, next))) {
|
break;
|
||||||
printf("%s %s 0x%x\n",
|
printf("%s %s 0x%x", dso_name, device, events);
|
||||||
dso_name, device, events);
|
if (events & TIMEOUT){
|
||||||
|
if ((ret = dm_get_event_timeout(device,
|
||||||
|
&timeout))) {
|
||||||
|
ret = EXIT_FAILURE;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
printf(" %"PRIu32"\n", timeout);
|
||||||
|
} else
|
||||||
|
printf("\n");
|
||||||
|
if (device_arg)
|
||||||
|
break;
|
||||||
|
|
||||||
if (device_arg)
|
next = 1;
|
||||||
break;
|
}
|
||||||
|
|
||||||
next = 1;
|
|
||||||
}
|
|
||||||
} while (!ret);
|
|
||||||
|
|
||||||
ret = (ret && device_arg) ? EXIT_FAILURE : EXIT_SUCCESS;
|
ret = (ret && device_arg) ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||||
goto out;
|
goto out;
|
||||||
@ -143,9 +159,16 @@ int main(int argc, char **argv)
|
|||||||
reg ? "": "un", device, strerror(-ret));
|
reg ? "": "un", device, strerror(-ret));
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
printf("%s %sregistered successfully.\n",
|
if (reg && (events & TIMEOUT) &&
|
||||||
device, reg ? "" : "un");
|
((ret = dm_set_event_timeout(device, timeout)))){
|
||||||
ret = EXIT_SUCCESS;
|
fprintf(stderr, "Failed to set timeout for %s: %s\n",
|
||||||
|
device, strerror(-ret));
|
||||||
|
ret = EXIT_FAILURE;
|
||||||
|
} else {
|
||||||
|
printf("%s %sregistered successfully.\n",
|
||||||
|
device, reg ? "" : "un");
|
||||||
|
ret = EXIT_SUCCESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#define FIFO_SERVER "/var/run/dmeventd-server"
|
#define FIFO_SERVER "/var/run/dmeventd-server"
|
||||||
#define PIDFILE "/var/run/dmeventd.pid"
|
#define PIDFILE "/var/run/dmeventd.pid"
|
||||||
|
|
||||||
|
#define DEFAULT_TIMEOUT 10
|
||||||
/* Commands for the daemon passed in the message below. */
|
/* Commands for the daemon passed in the message below. */
|
||||||
enum dmeventd_command {
|
enum dmeventd_command {
|
||||||
CMD_ACTIVE = 1,
|
CMD_ACTIVE = 1,
|
||||||
@ -32,6 +33,8 @@ enum dmeventd_command {
|
|||||||
CMD_UNREGISTER_FOR_EVENT,
|
CMD_UNREGISTER_FOR_EVENT,
|
||||||
CMD_GET_REGISTERED_DEVICE,
|
CMD_GET_REGISTERED_DEVICE,
|
||||||
CMD_GET_NEXT_REGISTERED_DEVICE,
|
CMD_GET_NEXT_REGISTERED_DEVICE,
|
||||||
|
CMD_SET_TIMEOUT,
|
||||||
|
CMD_GET_TIMEOUT,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Message passed between client and daemon. */
|
/* Message passed between client and daemon. */
|
||||||
@ -60,6 +63,7 @@ enum event_type {
|
|||||||
PATH_ERROR = 0x10, /* Failure on an io path. */
|
PATH_ERROR = 0x10, /* Failure on an io path. */
|
||||||
ADAPTOR_ERROR = 0x20, /* Failure off a host adaptor. */
|
ADAPTOR_ERROR = 0x20, /* Failure off a host adaptor. */
|
||||||
SYNC_STATUS = 0x40, /* Mirror synchronization completed/failed. */
|
SYNC_STATUS = 0x40, /* Mirror synchronization completed/failed. */
|
||||||
|
TIMEOUT = 0x80, /* Timeout has occured */
|
||||||
};
|
};
|
||||||
#define ALL_ERRORS (SECTOR_ERROR | DEVICE_ERROR | PATH_ERROR | ADAPTOR_ERROR)
|
#define ALL_ERRORS (SECTOR_ERROR | DEVICE_ERROR | PATH_ERROR | ADAPTOR_ERROR)
|
||||||
|
|
||||||
@ -69,6 +73,8 @@ int dm_unregister_for_event(char *dso_name, char *device,
|
|||||||
enum event_type events);
|
enum event_type events);
|
||||||
int dm_get_registered_device(char **dso_name, char **device,
|
int dm_get_registered_device(char **dso_name, char **device,
|
||||||
enum event_type *events, int next);
|
enum event_type *events, int next);
|
||||||
|
int dm_set_event_timeout(char *device, uint32_t timeout);
|
||||||
|
int dm_get_event_timeout(char *device, uint32_t *timeout);
|
||||||
|
|
||||||
/* Prototypes for DSO interface. */
|
/* Prototypes for DSO interface. */
|
||||||
void process_event(char *device, enum event_type event);
|
void process_event(char *device, enum event_type event);
|
||||||
|
Loading…
Reference in New Issue
Block a user