mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Another ioctl interface update:
Supply offset to start of variable data area (so struct size can change without breaking backward compatibility) Add command that just returns the driver version
This commit is contained in:
parent
6036e5e0f7
commit
6198a4102c
@ -13,7 +13,6 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <linux/kdev_t.h>
|
||||
|
||||
@ -44,6 +43,17 @@ void dm_task_destroy(struct dm_task *dmt)
|
||||
free(dmt);
|
||||
}
|
||||
|
||||
int dm_task_get_driver_version(struct dm_task *dmt, char *version,
|
||||
size_t size)
|
||||
{
|
||||
if (!dmt->dmi)
|
||||
return 0;
|
||||
|
||||
strncpy(version, dmt->dmi->version, size);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_task_get_info(struct dm_task *dmt, struct dm_info *info)
|
||||
{
|
||||
if (!dmt->dmi)
|
||||
@ -51,12 +61,12 @@ int dm_task_get_info(struct dm_task *dmt, struct dm_info *info)
|
||||
|
||||
memset(info, 0, sizeof(*info));
|
||||
|
||||
info->exists = dmt->dmi->status & DM_EXISTS_FLAG ? 1 : 0;
|
||||
info->exists = dmt->dmi->flags & DM_EXISTS_FLAG ? 1 : 0;
|
||||
if (!info->exists)
|
||||
return 1;
|
||||
|
||||
info->suspended = dmt->dmi->status & DM_SUSPEND_FLAG ? 1 : 0;
|
||||
info->read_only = dmt->dmi->status & DM_READONLY_FLAG ? 1 : 0;
|
||||
info->suspended = dmt->dmi->flags & DM_SUSPEND_FLAG ? 1 : 0;
|
||||
info->read_only = dmt->dmi->flags & DM_READONLY_FLAG ? 1 : 0;
|
||||
info->target_count = dmt->dmi->target_count;
|
||||
info->open_count = dmt->dmi->open_count;
|
||||
info->major = MAJOR(dmt->dmi->dev);
|
||||
@ -188,15 +198,18 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt)
|
||||
|
||||
strncpy(dmi->version, DM_IOCTL_VERSION, sizeof(dmi->version));
|
||||
dmi->data_size = len;
|
||||
strncpy(dmi->name, dmt->dev_name, sizeof(dmi->name));
|
||||
dmi->data_start = sizeof(struct dm_ioctl);
|
||||
|
||||
if (dmt->dev_name)
|
||||
strncpy(dmi->name, dmt->dev_name, sizeof(dmi->name));
|
||||
|
||||
if (dmt->type == DM_DEVICE_SUSPEND)
|
||||
dmi->status |= DM_SUSPEND_FLAG;
|
||||
dmi->flags |= DM_SUSPEND_FLAG;
|
||||
if (dmt->read_only)
|
||||
dmi->status |= DM_READONLY_FLAG;
|
||||
dmi->flags |= DM_READONLY_FLAG;
|
||||
|
||||
if (dmt->minor > 0) {
|
||||
dmi->status |= DM_PERSISTENT_DEV_FLAG;
|
||||
dmi->flags |= DM_PERSISTENT_DEV_FLAG;
|
||||
dmi->dev = MKDEV(0, dmt->minor);
|
||||
}
|
||||
|
||||
@ -267,6 +280,10 @@ int dm_task_run(struct dm_task *dmt)
|
||||
command = DM_RENAME;
|
||||
break;
|
||||
|
||||
case DM_DEVICE_VERSION:
|
||||
command = DM_VERSION;
|
||||
break;
|
||||
|
||||
default:
|
||||
log("Internal error: unknown device-mapper task %d",
|
||||
dmt->type);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#define LIB_DEVICE_MAPPER_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/*
|
||||
* Since it is quite laborious to build the ioctl
|
||||
@ -39,6 +40,8 @@ enum {
|
||||
|
||||
DM_DEVICE_INFO,
|
||||
DM_DEVICE_RENAME,
|
||||
|
||||
DM_DEVICE_VERSION,
|
||||
};
|
||||
|
||||
|
||||
@ -63,6 +66,7 @@ struct dm_info {
|
||||
unsigned int target_count;
|
||||
};
|
||||
|
||||
int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size);
|
||||
int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi);
|
||||
|
||||
int dm_task_set_ro(struct dm_task *dmt);
|
||||
|
@ -156,6 +156,32 @@ out:
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _version(int argc, char **argv)
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
char version[16];
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_VERSION)))
|
||||
return 0;
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
goto out;
|
||||
|
||||
if (!dm_task_get_driver_version(dmt, (char *)&version,
|
||||
sizeof(version)))
|
||||
goto out;
|
||||
|
||||
printf("Driver version: %s\n", version);
|
||||
|
||||
r = 1;
|
||||
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _simple(int task, const char *name)
|
||||
{
|
||||
int r = 0;
|
||||
@ -256,6 +282,7 @@ static struct command _commands[] = {
|
||||
{"reload", "<dev_name> <table_file>", 2, _reload},
|
||||
{"info", "<dev_name>", 1, _info},
|
||||
{"rename", "<dev_name> <new_name>", 2, _rename},
|
||||
{"version", "", 0, _version},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
@ -322,7 +349,7 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (argc < 2) {
|
||||
if (argc == 0) {
|
||||
_usage(stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user