1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-30 17:18:21 +03:00

Proposed changes to the ioctl interface to fix alignment issues on some

architectures and specify an explicit width for every numeric field.
This commit is contained in:
Alasdair Kergon 2003-03-28 18:58:59 +00:00
parent 1fa74f62e8
commit 8aa577ad34
5 changed files with 51 additions and 56 deletions

View File

@ -23,7 +23,7 @@
*/
#if !((DM_VERSION_MAJOR == 1 && DM_VERSION_MINOR >= 0) || \
(DM_VERSION_MAJOR == 2 && DM_VERSION_MINOR >= 0))
(DM_VERSION_MAJOR == 3 && DM_VERSION_MINOR >= 0))
#error The version of dm-ioctl.h included is incompatible.
#endif
@ -35,7 +35,7 @@ static int _log_suppress = 0;
* Support both old and new major numbers to ease the transition.
* Clumsy, but only temporary.
*/
#if DM_VERSION_MAJOR == 2 && defined(DM_COMPAT)
#if DM_VERSION_MAJOR == 3 && defined(DM_COMPAT)
const int _dm_compat = 1;
#else
const int _dm_compat = 0;
@ -43,20 +43,20 @@ const int _dm_compat = 0;
/* *INDENT-OFF* */
static struct cmd_data _cmd_data_v2[] = {
{"create", DM_DEV_CREATE, {2, 0, 0}},
{"reload", DM_DEV_RELOAD, {2, 0, 0}},
{"remove", DM_DEV_REMOVE, {2, 0, 0}},
{"remove_all", DM_REMOVE_ALL, {2, 0, 0}},
{"suspend", DM_DEV_SUSPEND, {2, 0, 0}},
{"resume", DM_DEV_SUSPEND, {2, 0, 0}},
{"info", DM_DEV_STATUS, {2, 0, 0}},
{"deps", DM_DEV_DEPS, {2, 0, 0}},
{"rename", DM_DEV_RENAME, {2, 0, 0}},
{"version", DM_VERSION, {2, 0, 0}},
{"status", DM_TARGET_STATUS, {2, 0, 0}},
{"table", DM_TARGET_STATUS, {2, 0, 0}},
{"waitevent", DM_TARGET_WAIT, {2, 0, 0}},
static struct cmd_data _cmd_data_v3[] = {
{"create", DM_DEV_CREATE, {3, 0, 0}},
{"reload", DM_DEV_RELOAD, {3, 0, 0}},
{"remove", DM_DEV_REMOVE, {3, 0, 0}},
{"remove_all", DM_REMOVE_ALL, {3, 0, 0}},
{"suspend", DM_DEV_SUSPEND, {3, 0, 0}},
{"resume", DM_DEV_SUSPEND, {3, 0, 0}},
{"info", DM_DEV_STATUS, {3, 0, 0}},
{"deps", DM_DEV_DEPS, {3, 0, 0}},
{"rename", DM_DEV_RENAME, {3, 0, 0}},
{"version", DM_VERSION, {3, 0, 0}},
{"status", DM_TARGET_STATUS, {3, 0, 0}},
{"table", DM_TARGET_STATUS, {3, 0, 0}},
{"waitevent", DM_TARGET_WAIT, {3, 0, 0}},
};
/* *INDENT-ON* */
@ -89,7 +89,7 @@ static int _unmarshal_status_v1(struct dm_task *dmt, struct dm_ioctl_v1 *dmi)
{
char *outbuf = (char *) dmi + sizeof(struct dm_ioctl_v1);
char *outptr = outbuf;
uint32_t i;
int32_t i;
struct dm_target_spec_v1 *spec;
for (i = 0; i < dmi->target_count; i++) {
@ -138,8 +138,8 @@ static const char *_dm_task_get_uuid_v1(struct dm_task *dmt)
static struct dm_deps *_dm_task_get_deps_v1(struct dm_task *dmt)
{
return (struct dm_deps *) (((void *) dmt->dmi.v1) +
dmt->dmi.v1->data_start);
log_error("deps version 1 no longer supported by libdevmapper");
return NULL;
}
static void *_add_target_v1(struct target *t, void *out, void *end)
@ -356,8 +356,8 @@ void dm_task_destroy(struct dm_task *dmt)
if (dmt->newname)
free(dmt->newname);
if (dmt->dmi.v2)
free(dmt->dmi.v2);
if (dmt->dmi.v3)
free(dmt->dmi.v3);
if (dmt->uuid)
free(dmt->uuid);
@ -372,12 +372,12 @@ int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size)
if (_dm_version == 1)
return _dm_task_get_driver_version_v1(dmt, version, size);
if (!dmt->dmi.v2) {
if (!dmt->dmi.v3) {
version[0] = '\0';
return 0;
}
v = dmt->dmi.v2->version;
v = dmt->dmi.v3->version;
snprintf(version, size, "%u.%u.%u", v[0], v[1], v[2]);
return 1;
}
@ -496,21 +496,21 @@ int dm_task_get_info(struct dm_task *dmt, struct dm_info *info)
if (_dm_version == 1)
return _dm_task_get_info_v1(dmt, info);
if (!dmt->dmi.v2)
if (!dmt->dmi.v3)
return 0;
memset(info, 0, sizeof(*info));
info->exists = dmt->dmi.v2->flags & DM_EXISTS_FLAG ? 1 : 0;
info->exists = dmt->dmi.v3->flags & DM_EXISTS_FLAG ? 1 : 0;
if (!info->exists)
return 1;
info->suspended = dmt->dmi.v2->flags & DM_SUSPEND_FLAG ? 1 : 0;
info->read_only = dmt->dmi.v2->flags & DM_READONLY_FLAG ? 1 : 0;
info->target_count = dmt->dmi.v2->target_count;
info->open_count = dmt->dmi.v2->open_count;
info->major = MAJOR(dmt->dmi.v2->dev);
info->minor = MINOR(dmt->dmi.v2->dev);
info->suspended = dmt->dmi.v3->flags & DM_SUSPEND_FLAG ? 1 : 0;
info->read_only = dmt->dmi.v3->flags & DM_READONLY_FLAG ? 1 : 0;
info->target_count = dmt->dmi.v3->target_count;
info->open_count = dmt->dmi.v3->open_count;
info->major = MAJOR(dmt->dmi.v3->dev);
info->minor = MINOR(dmt->dmi.v3->dev);
return 1;
}
@ -520,7 +520,7 @@ const char *dm_task_get_uuid(struct dm_task *dmt)
if (_dm_version == 1)
return _dm_task_get_uuid_v1(dmt);
return (dmt->dmi.v2->uuid);
return (dmt->dmi.v3->uuid);
}
struct dm_deps *dm_task_get_deps(struct dm_task *dmt)
@ -528,8 +528,8 @@ struct dm_deps *dm_task_get_deps(struct dm_task *dmt)
if (_dm_version == 1)
return _dm_task_get_deps_v1(dmt);
return (struct dm_deps *) (((void *) dmt->dmi.v2) +
dmt->dmi.v2->data_start);
return (struct dm_deps *) (((void *) dmt->dmi.v3) +
dmt->dmi.v3->data_start);
}
int dm_task_set_ro(struct dm_task *dmt)
@ -657,7 +657,7 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt)
memset(dmi, 0, len);
version = &_cmd_data_v2[dmt->type].version;
version = &_cmd_data_v3[dmt->type].version;
dmi->version[0] = (*version)[0];
dmi->version[1] = (*version)[1];
@ -726,18 +726,18 @@ int dm_task_run(struct dm_task *dmt)
}
if ((unsigned) dmt->type >=
(sizeof(_cmd_data_v2) / sizeof(*_cmd_data_v2))) {
(sizeof(_cmd_data_v3) / sizeof(*_cmd_data_v3))) {
log_error("Internal error: unknown device-mapper task %d",
dmt->type);
goto bad;
}
command = _cmd_data_v2[dmt->type].cmd;
command = _cmd_data_v3[dmt->type].cmd;
if (dmt->type == DM_DEVICE_TABLE)
dmi->flags |= DM_STATUS_TABLE_FLAG;
log_debug("dm %s %s %s %s", _cmd_data_v2[dmt->type].name, dmi->name,
log_debug("dm %s %s %s %s", _cmd_data_v3[dmt->type].name, dmi->name,
dmi->uuid, dmt->newname ? dmt->newname : "");
if (ioctl(fd, command, dmi) < 0) {
if (_log_suppress)
@ -769,7 +769,7 @@ int dm_task_run(struct dm_task *dmt)
break;
}
dmt->dmi.v2 = dmi;
dmt->dmi.v3 = dmi;
close(fd);
return 1;

View File

@ -27,8 +27,8 @@ struct dm_ioctl_v1 {
uint32_t data_start; /* offset to start of data
* relative to start of this struct */
uint32_t target_count; /* in/out */
uint32_t open_count; /* out */
int32_t target_count; /* in/out */
int32_t open_count; /* out */
uint32_t flags; /* in/out */
__kernel_dev_t dev; /* in/out */

View File

@ -30,7 +30,7 @@ struct dm_task {
int read_only;
int minor;
union {
struct dm_ioctl *v2;
struct dm_ioctl *v3;
struct dm_ioctl_v1 *v1;
} dmi;
char *newname;

View File

@ -65,17 +65,18 @@ int dm_task_set_uuid(struct dm_task *dmt, const char *uuid);
struct dm_info {
int exists;
int suspended;
unsigned int open_count;
int major;
int minor; /* minor device number */
int32_t open_count;
uint32_t major;
uint32_t minor; /* minor device number */
int read_only; /* 0:read-write; 1:read-only */
unsigned int target_count;
int32_t target_count;
};
struct dm_deps {
unsigned int count;
__kernel_dev_t device[0];
uint32_t count;
uint32_t filler;
uint64_t device[0];
};
int dm_get_library_version(char *version, size_t size);

View File

@ -8,15 +8,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <getopt.h>
#include <linux/kdev_t.h>
@ -327,7 +320,8 @@ static int _info(int argc, char **argv)
static int _deps(int argc, char **argv)
{
int r = 0, i;
int r = 0;
uint32_t i;
struct dm_deps *deps;
/* remove <dev_name> */