1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Support new target message ioctl.

This commit is contained in:
Alasdair Kergon 2004-06-08 20:34:40 +00:00
parent 603292735e
commit 62cec9b225
7 changed files with 119 additions and 7 deletions

View File

@ -1,3 +1,7 @@
Version 1.00.18
=============================
Add target message-passing ioctl.
Version 1.00.17 - 17 Apr 2004 Version 1.00.17 - 17 Apr 2004
============================= =============================
configure --with-owner= --with-group= to avoid -o and -g args to 'install' configure --with-owner= --with-group= to avoid -o and -g args to 'install'

View File

@ -17,6 +17,8 @@ dm_task_set_newname
dm_task_set_event_nr dm_task_set_event_nr
dm_task_set_major dm_task_set_major
dm_task_set_minor dm_task_set_minor
dm_task_set_sector
dm_task_set_message
dm_task_add_target dm_task_add_target
dm_get_next_target dm_get_next_target
dm_task_run dm_task_run

View File

@ -115,6 +115,7 @@ static struct cmd_data _cmd_data_v1[] = {
{ "clear", 0, {4, 0, 0} }, { "clear", 0, {4, 0, 0} },
{ "mknodes", 0, {4, 0, 0} }, { "mknodes", 0, {4, 0, 0} },
{ "versions", 0, {4, 1, 0} }, { "versions", 0, {4, 1, 0} },
{ "message", 0, {4, 2, 0} },
}; };
/* *INDENT-ON* */ /* *INDENT-ON* */

View File

@ -93,6 +93,9 @@ static struct cmd_data _cmd_data_v4[] = {
#ifdef DM_LIST_VERSIONS #ifdef DM_LIST_VERSIONS
{"versions", DM_LIST_VERSIONS, {4, 1, 0}}, {"versions", DM_LIST_VERSIONS, {4, 1, 0}},
#endif #endif
#ifdef DM_TARGET_MSG
{"message", DM_TARGET_MSG, {4, 2, 0}},
#endif
}; };
/* *INDENT-ON* */ /* *INDENT-ON* */
@ -146,6 +149,9 @@ void dm_task_destroy(struct dm_task *dmt)
if (dmt->newname) if (dmt->newname)
free(dmt->newname); free(dmt->newname);
if (dmt->message)
free(dmt->message);
if (dmt->dmi.v4) if (dmt->dmi.v4)
free(dmt->dmi.v4); free(dmt->dmi.v4);
@ -190,8 +196,9 @@ static int _unmarshal_status_v1(struct dm_task *dmt, struct dm_ioctl_v1 *dmi)
if (!dm_task_add_target(dmt, spec->sector_start, if (!dm_task_add_target(dmt, spec->sector_start,
(uint64_t) spec->length, (uint64_t) spec->length,
spec->target_type, spec->target_type,
outptr + sizeof(*spec))) outptr + sizeof(*spec))) {
return 0; return 0;
}
outptr = outbuf + spec->next; outptr = outbuf + spec->next;
} }
@ -652,8 +659,9 @@ static int _unmarshal_status(struct dm_task *dmt, struct dm_ioctl *dmi)
if (!dm_task_add_target(dmt, spec->sector_start, if (!dm_task_add_target(dmt, spec->sector_start,
spec->length, spec->length,
spec->target_type, spec->target_type,
outptr + sizeof(*spec))) outptr + sizeof(*spec))) {
return 0; return 0;
}
outptr = outbuf + spec->next; outptr = outbuf + spec->next;
} }
@ -775,6 +783,23 @@ int dm_task_set_newname(struct dm_task *dmt, const char *newname)
return 1; return 1;
} }
int dm_task_set_message(struct dm_task *dmt, const char *message)
{
if (!(dmt->message = strdup(message))) {
log_error("dm_task_set_message: strdup(%s) failed", message);
return 0;
}
return 1;
}
int dm_task_set_sector(struct dm_task *dmt, uint64_t sector)
{
dmt->sector = sector;
return 1;
}
int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr) int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr)
{ {
dmt->event_nr = event_nr; dmt->event_nr = event_nr;
@ -861,6 +886,7 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt)
struct dm_ioctl *dmi; struct dm_ioctl *dmi;
struct target *t; struct target *t;
struct dm_target_msg *tmsg;
size_t len = sizeof(struct dm_ioctl); size_t len = sizeof(struct dm_ioctl);
void *b, *e; void *b, *e;
int count = 0; int count = 0;
@ -871,14 +897,32 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt)
count++; count++;
} }
if (count && (dmt->sector || dmt->message)) {
log_error("targets and message are incompatible");
return NULL;
}
if (count && dmt->newname) { if (count && dmt->newname) {
log_error("targets and newname are incompatible"); log_error("targets and newname are incompatible");
return NULL; return NULL;
} }
if (dmt->newname && (dmt->sector || dmt->message)) {
log_error("message and newname are incompatible");
return NULL;
}
if (dmt->sector && !dmt->message) {
log_error("message is required with sector");
return NULL;
}
if (dmt->newname) if (dmt->newname)
len += strlen(dmt->newname) + 1; len += strlen(dmt->newname) + 1;
if (dmt->message)
len += sizeof(struct dm_target_msg) + strlen(dmt->message) + 1;
/* /*
* Give len a minimum size so that we have space to store * Give len a minimum size so that we have space to store
* dependencies or status information. * dependencies or status information.
@ -933,6 +977,12 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt)
if (dmt->newname) if (dmt->newname)
strcpy(b, dmt->newname); strcpy(b, dmt->newname);
if (dmt->message) {
tmsg = (struct dm_target_msg *) b;
tmsg->sector = dmt->sector;
strcpy(tmsg->message, dmt->message);
}
return dmi; return dmi;
bad: bad:
@ -1118,8 +1168,9 @@ int dm_task_run(struct dm_task *dmt)
dmi->flags |= DM_STATUS_TABLE_FLAG; dmi->flags |= DM_STATUS_TABLE_FLAG;
dmi->flags |= DM_EXISTS_FLAG; /* FIXME */ dmi->flags |= DM_EXISTS_FLAG; /* FIXME */
log_debug("dm %s %s %s %s", _cmd_data_v4[dmt->type].name, dmi->name, log_debug("dm %s %s %s %s%.0llu %s", _cmd_data_v4[dmt->type].name,
dmi->uuid, dmt->newname ? dmt->newname : ""); dmi->name, dmi->uuid, dmt->newname ? dmt->newname : "",
dmt->sector, dmt->message ? dmt->message : "");
if (ioctl(_control_fd, command, dmi) < 0) { if (ioctl(_control_fd, command, dmi) < 0) {
if (errno == ENXIO && ((dmt->type == DM_DEVICE_INFO) || if (errno == ENXIO && ((dmt->type == DM_DEVICE_INFO) ||
(dmt->type == DM_DEVICE_MKNODES))) { (dmt->type == DM_DEVICE_MKNODES))) {

View File

@ -45,6 +45,8 @@ struct dm_task {
struct dm_ioctl_v1 *v1; struct dm_ioctl_v1 *v1;
} dmi; } dmi;
char *newname; char *newname;
char *message;
uint64_t sector;
char *uuid; char *uuid;
}; };

View File

@ -68,7 +68,9 @@ enum {
DM_DEVICE_MKNODES, DM_DEVICE_MKNODES,
DM_DEVICE_LIST_VERSIONS DM_DEVICE_LIST_VERSIONS,
DM_DEVICE_TARGET_MSG
}; };
struct dm_task; struct dm_task;
@ -130,6 +132,8 @@ int dm_task_set_newname(struct dm_task *dmt, const char *newname);
int dm_task_set_minor(struct dm_task *dmt, int minor); int dm_task_set_minor(struct dm_task *dmt, int minor);
int dm_task_set_major(struct dm_task *dmt, int major); int dm_task_set_major(struct dm_task *dmt, int major);
int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr); int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr);
int dm_task_set_message(struct dm_task *dmt, const char *message);
int dm_task_set_sector(struct dm_task *dmt, uint64_t sector);
/* /*
* Use these to prepare for a create or reload. * Use these to prepare for a create or reload.

View File

@ -248,6 +248,51 @@ static int _rename(int argc, char **argv, void *data)
return r; return r;
} }
static int _message(int argc, char **argv, void *data)
{
int r = 0, sz = 1, i;
struct dm_task *dmt;
char *str;
if (!(dmt = dm_task_create(DM_DEVICE_TARGET_MSG)))
return 0;
if (!dm_task_set_name(dmt, argv[1]))
goto out;
if (!dm_task_set_sector(dmt, atoll(argv[2])))
goto out;
argc -= 3;
argv += 3;
for (i = 0; i < argc; i++)
sz += strlen(argv[i]) + 1;
str = malloc(sz);
for (i = 0; i < argc; i++) {
if (i)
strcat(str, " ");
strcat(str, argv[i]);
}
if (!dm_task_set_message(dmt, str))
goto out;
free(str);
if (!dm_task_run(dmt))
goto out;
r = 1;
out:
dm_task_destroy(dmt);
return r;
}
static int _version(int argc, char **argv, void *data) static int _version(int argc, char **argv, void *data)
{ {
int r = 0; int r = 0;
@ -264,8 +309,9 @@ static int _version(int argc, char **argv, void *data)
goto out; goto out;
if (!dm_task_get_driver_version(dmt, (char *) &version, if (!dm_task_get_driver_version(dmt, (char *) &version,
sizeof(version))) sizeof(version))) {
goto out; goto out;
}
printf("Driver version: %s\n", version); printf("Driver version: %s\n", version);
@ -623,6 +669,7 @@ static struct command _commands[] = {
{"clear", "<dev_name>", 1, 1, _clear}, {"clear", "<dev_name>", 1, 1, _clear},
{"reload", "<dev_name> [<table_file>]", 1, 2, _reload}, {"reload", "<dev_name> [<table_file>]", 1, 2, _reload},
{"rename", "<dev_name> <new_name>", 2, 2, _rename}, {"rename", "<dev_name> <new_name>", 2, 2, _rename},
{"message", "<dev_name> <sector> <message>", 3, -1, _message},
{"ls", "", 0, 0, _ls}, {"ls", "", 0, 0, _ls},
{"info", "[<dev_name>]", 0, 1, _info}, {"info", "[<dev_name>]", 0, 1, _info},
{"deps", "[<dev_name>]", 0, 1, _deps}, {"deps", "[<dev_name>]", 0, 1, _deps},
@ -744,7 +791,8 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if (argc < c->min_args + 1 || argc > c->max_args + 1) { if (argc < c->min_args + 1 ||
(c->max_args >= 0 && argc > c->max_args + 1)) {
fprintf(stderr, "Incorrect number of arguments\n"); fprintf(stderr, "Incorrect number of arguments\n");
_usage(stderr); _usage(stderr);
exit(1); exit(1);