mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o dm_destroy_all() called on exit - but doesn't touch suspended devices yet.
o 'dmsetup remove_all' calls dm_destroy_all() to provide a quick way to prepare for unloading the module o Ran through indent again.
This commit is contained in:
parent
11d2da4036
commit
e09a7b5787
@ -43,8 +43,7 @@ void dm_task_destroy(struct dm_task *dmt)
|
|||||||
free(dmt);
|
free(dmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
int dm_task_get_driver_version(struct dm_task *dmt, char *version,
|
int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size)
|
||||||
size_t size)
|
|
||||||
{
|
{
|
||||||
if (!dmt->dmi)
|
if (!dmt->dmi)
|
||||||
return 0;
|
return 0;
|
||||||
@ -97,13 +96,12 @@ int dm_task_set_newname(struct dm_task *dmt, const char *newname)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct target *create_target(uint64_t start,
|
struct target *create_target(uint64_t start,
|
||||||
uint64_t len,
|
uint64_t len, const char *type, const char *params)
|
||||||
const char *type, const char *params)
|
|
||||||
{
|
{
|
||||||
struct target *t = malloc(sizeof(*t));
|
struct target *t = malloc(sizeof(*t));
|
||||||
|
|
||||||
if (!t) {
|
if (!t) {
|
||||||
log_error("create_target: malloc(%d) failed", sizeof(*t));
|
log_error("create_target: malloc(%d) failed", sizeof(*t));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +121,7 @@ struct target *create_target(uint64_t start,
|
|||||||
t->length = len;
|
t->length = len;
|
||||||
return t;
|
return t;
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
free(t->params);
|
free(t->params);
|
||||||
free(t->type);
|
free(t->type);
|
||||||
free(t);
|
free(t);
|
||||||
@ -241,7 +239,7 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt)
|
|||||||
|
|
||||||
return dmi;
|
return dmi;
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
free(dmi);
|
free(dmi);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -278,6 +276,10 @@ int dm_task_run(struct dm_task *dmt)
|
|||||||
command = DM_REMOVE;
|
command = DM_REMOVE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DM_DEVICE_REMOVE_ALL:
|
||||||
|
command = DM_REMOVE_ALL;
|
||||||
|
break;
|
||||||
|
|
||||||
case DM_DEVICE_SUSPEND:
|
case DM_DEVICE_SUSPEND:
|
||||||
command = DM_SUSPEND;
|
command = DM_SUSPEND;
|
||||||
break;
|
break;
|
||||||
@ -304,13 +306,13 @@ int dm_task_run(struct dm_task *dmt)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
log_error("Internal error: unknown device-mapper task %d",
|
log_error("Internal error: unknown device-mapper task %d",
|
||||||
dmt->type);
|
dmt->type);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, command, dmi) < 0) {
|
if (ioctl(fd, command, dmi) < 0) {
|
||||||
log_error("device-mapper ioctl cmd %d failed: %s", dmt->type,
|
log_error("device-mapper ioctl cmd %d failed: %s", dmt->type,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,10 +330,9 @@ int dm_task_run(struct dm_task *dmt)
|
|||||||
close(fd);
|
close(fd);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
free(dmi);
|
free(dmi);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +20,8 @@
|
|||||||
* each ioctl command you want to execute.
|
* each ioctl command you want to execute.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
typedef void (*dm_log_fn) (int level, const char *file, int line,
|
||||||
typedef void (*dm_log_fn)(int level, const char *file, int line,
|
const char *f, ...);
|
||||||
const char *f, ...);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The library user may wish to register their own
|
* The library user may wish to register their own
|
||||||
@ -35,6 +34,7 @@ enum {
|
|||||||
DM_DEVICE_CREATE,
|
DM_DEVICE_CREATE,
|
||||||
DM_DEVICE_RELOAD,
|
DM_DEVICE_RELOAD,
|
||||||
DM_DEVICE_REMOVE,
|
DM_DEVICE_REMOVE,
|
||||||
|
DM_DEVICE_REMOVE_ALL,
|
||||||
|
|
||||||
DM_DEVICE_SUSPEND,
|
DM_DEVICE_SUSPEND,
|
||||||
DM_DEVICE_RESUME,
|
DM_DEVICE_RESUME,
|
||||||
@ -46,7 +46,6 @@ enum {
|
|||||||
DM_DEVICE_VERSION,
|
DM_DEVICE_VERSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct dm_task;
|
struct dm_task;
|
||||||
|
|
||||||
struct dm_task *dm_task_create(int type);
|
struct dm_task *dm_task_create(int type);
|
||||||
@ -74,8 +73,7 @@ struct dm_deps {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int dm_get_library_version(char *version, size_t size);
|
int dm_get_library_version(char *version, size_t size);
|
||||||
int dm_task_get_driver_version(struct dm_task *dmt, char *version,
|
int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size);
|
||||||
size_t size);
|
|
||||||
int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi);
|
int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi);
|
||||||
|
|
||||||
struct dm_deps *dm_task_get_deps(struct dm_task *dmt);
|
struct dm_deps *dm_task_get_deps(struct dm_task *dmt);
|
||||||
@ -89,9 +87,7 @@ int dm_task_set_minor(struct dm_task *dmt, int minor);
|
|||||||
*/
|
*/
|
||||||
int dm_task_add_target(struct dm_task *dmt,
|
int dm_task_add_target(struct dm_task *dmt,
|
||||||
uint64_t start,
|
uint64_t start,
|
||||||
uint64_t size,
|
uint64_t size, const char *ttype, const char *params);
|
||||||
const char *ttype,
|
|
||||||
const char *params);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Call this to actually run the ioctl.
|
* Call this to actually run the ioctl.
|
||||||
@ -104,4 +100,4 @@ int dm_task_run(struct dm_task *dmt);
|
|||||||
int dm_set_dev_dir(const char *dir);
|
int dm_set_dev_dir(const char *dir);
|
||||||
const char *dm_dir(void);
|
const char *dm_dir(void);
|
||||||
|
|
||||||
#endif /* LIB_DEVICE_MAPPER_H */
|
#endif /* LIB_DEVICE_MAPPER_H */
|
||||||
|
@ -36,23 +36,22 @@ enum {
|
|||||||
static int _switches[NUM_SWITCHES];
|
static int _switches[NUM_SWITCHES];
|
||||||
static int _values[NUM_SWITCHES];
|
static int _values[NUM_SWITCHES];
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Commands
|
* Commands
|
||||||
*/
|
*/
|
||||||
static int _parse_file(struct dm_task *dmt, const char *file)
|
static int _parse_file(struct dm_task *dmt, const char *file)
|
||||||
{
|
{
|
||||||
char buffer[LINE_SIZE], *ttype, *ptr, *comment;
|
char buffer[LINE_SIZE], *ttype, *ptr, *comment;
|
||||||
FILE *fp = fopen(file, "r");
|
FILE *fp = fopen(file, "r");
|
||||||
unsigned long long start, size;
|
unsigned long long start, size;
|
||||||
int r = 0, n, line = 0;
|
int r = 0, n, line = 0;
|
||||||
|
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
err("Couldn't open '%s' for reading", file);
|
err("Couldn't open '%s' for reading", file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||||
line++;
|
line++;
|
||||||
|
|
||||||
/* trim trailing space */
|
/* trim trailing space */
|
||||||
@ -63,32 +62,31 @@ static int _parse_file(struct dm_task *dmt, const char *file)
|
|||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
|
||||||
/* trim leading space */
|
/* trim leading space */
|
||||||
for (ptr = buffer; *ptr && isspace((int) *ptr); ptr++)
|
for (ptr = buffer; *ptr && isspace((int) *ptr); ptr++) ;
|
||||||
;
|
|
||||||
|
|
||||||
if (!*ptr || *ptr == '#')
|
if (!*ptr || *ptr == '#')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (sscanf(ptr, "%llu %llu %as %n",
|
if (sscanf(ptr, "%llu %llu %as %n",
|
||||||
&start, &size, &ttype, &n) < 3) {
|
&start, &size, &ttype, &n) < 3) {
|
||||||
err("%s:%d Invalid format", file, line);
|
err("%s:%d Invalid format", file, line);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr += n;
|
ptr += n;
|
||||||
if ((comment = strchr(ptr, (int) '#')))
|
if ((comment = strchr(ptr, (int) '#')))
|
||||||
*comment = '\0';
|
*comment = '\0';
|
||||||
|
|
||||||
if (!dm_task_add_target(dmt, start, size, ttype, ptr))
|
if (!dm_task_add_target(dmt, start, size, ttype, ptr))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
free(ttype);
|
free(ttype);
|
||||||
}
|
}
|
||||||
r = 1;
|
r = 1;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _load(int task, const char *name, const char *file)
|
static int _load(int task, const char *name, const char *file)
|
||||||
@ -116,7 +114,7 @@ static int _load(int task, const char *name, const char *file)
|
|||||||
|
|
||||||
r = 1;
|
r = 1;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
@ -137,24 +135,24 @@ static int _rename(int argc, char **argv)
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
struct dm_task *dmt;
|
struct dm_task *dmt;
|
||||||
|
|
||||||
if (!(dmt = dm_task_create(DM_DEVICE_RENAME)))
|
if (!(dmt = dm_task_create(DM_DEVICE_RENAME)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!dm_task_set_name(dmt, argv[1]))
|
if (!dm_task_set_name(dmt, argv[1]))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!dm_task_set_newname(dmt, argv[2]))
|
if (!dm_task_set_newname(dmt, argv[2]))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!dm_task_run(dmt))
|
if (!dm_task_run(dmt))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
r = 1;
|
r = 1;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _version(int argc, char **argv)
|
static int _version(int argc, char **argv)
|
||||||
@ -172,7 +170,7 @@ static int _version(int argc, char **argv)
|
|||||||
if (!dm_task_run(dmt))
|
if (!dm_task_run(dmt))
|
||||||
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;
|
||||||
|
|
||||||
@ -201,11 +199,16 @@ static int _simple(int task, const char *name)
|
|||||||
|
|
||||||
r = dm_task_run(dmt);
|
r = dm_task_run(dmt);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _remove_all(int argc, char **argv)
|
||||||
|
{
|
||||||
|
return _simple(DM_DEVICE_REMOVE_ALL, "");
|
||||||
|
}
|
||||||
|
|
||||||
static int _remove(int argc, char **argv)
|
static int _remove(int argc, char **argv)
|
||||||
{
|
{
|
||||||
return _simple(DM_DEVICE_REMOVE, argv[1]);
|
return _simple(DM_DEVICE_REMOVE, argv[1]);
|
||||||
@ -260,7 +263,7 @@ static int _info(int argc, char **argv)
|
|||||||
|
|
||||||
r = 1;
|
r = 1;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -305,16 +308,15 @@ static int _deps(int argc, char **argv)
|
|||||||
|
|
||||||
r = 1;
|
r = 1;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dispatch table
|
* dispatch table
|
||||||
*/
|
*/
|
||||||
typedef int (*command_fn)(int argc, char **argv);
|
typedef int (*command_fn) (int argc, char **argv);
|
||||||
|
|
||||||
struct command {
|
struct command {
|
||||||
char *name;
|
char *name;
|
||||||
@ -326,6 +328,7 @@ struct command {
|
|||||||
static struct command _commands[] = {
|
static struct command _commands[] = {
|
||||||
{"create", "<dev_name> <table_file>", 2, _create},
|
{"create", "<dev_name> <table_file>", 2, _create},
|
||||||
{"remove", "<dev_name>", 1, _remove},
|
{"remove", "<dev_name>", 1, _remove},
|
||||||
|
{"remove_all", "", 0, _remove_all},
|
||||||
{"suspend", "<dev_name>", 1, _suspend},
|
{"suspend", "<dev_name>", 1, _suspend},
|
||||||
{"resume", "<dev_name>", 1, _resume},
|
{"resume", "<dev_name>", 1, _resume},
|
||||||
{"reload", "<dev_name> <table_file>", 2, _reload},
|
{"reload", "<dev_name> <table_file>", 2, _reload},
|
||||||
@ -336,14 +339,13 @@ static struct command _commands[] = {
|
|||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void _usage(FILE *out)
|
static void _usage(FILE * out)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fprintf(out, "usage:\n");
|
fprintf(out, "usage:\n");
|
||||||
for (i = 0; _commands[i].name; i++)
|
for (i = 0; _commands[i].name; i++)
|
||||||
fprintf(out, "\t%s %s\n",
|
fprintf(out, "\t%s %s\n", _commands[i].name, _commands[i].help);
|
||||||
_commands[i].name, _commands[i].help);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,4 +425,3 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user