-0.95.03-cvs (2002-03-05)
+0.95.04-cvs (2002-03-07)
static int _switches[NUM_SWITCHES];
static int _values[NUM_SWITCHES];
-
/*
* Commands
*/
static int _parse_file(struct dm_task *dmt, const char *file)
{
- char buffer[LINE_SIZE], *ttype, *ptr, *comment;
- FILE *fp = fopen(file, "r");
- unsigned long long start, size;
- int r = 0, n, line = 0;
+ char buffer[LINE_SIZE], *ttype, *ptr, *comment;
+ FILE *fp = fopen(file, "r");
+ unsigned long long start, size;
+ int r = 0, n, line = 0;
- if (!fp) {
- err("Couldn't open '%s' for reading", file);
- return 0;
- }
+ if (!fp) {
+ err("Couldn't open '%s' for reading", file);
+ return 0;
+ }
- while (fgets(buffer, sizeof(buffer), fp)) {
+ while (fgets(buffer, sizeof(buffer), fp)) {
line++;
/* trim trailing space */
*ptr = '\0';
/* trim leading space */
- for (ptr = buffer; *ptr && isspace((int) *ptr); ptr++)
- ;
+ for (ptr = buffer; *ptr && isspace((int) *ptr); ptr++) ;
- if (!*ptr || *ptr == '#')
- continue;
+ if (!*ptr || *ptr == '#')
+ continue;
- if (sscanf(ptr, "%llu %llu %as %n",
- &start, &size, &ttype, &n) < 3) {
- err("%s:%d Invalid format", file, line);
- goto out;
- }
+ if (sscanf(ptr, "%llu %llu %as %n",
+ &start, &size, &ttype, &n) < 3) {
+ err("%s:%d Invalid format", file, line);
+ goto out;
+ }
ptr += n;
if ((comment = strchr(ptr, (int) '#')))
*comment = '\0';
- if (!dm_task_add_target(dmt, start, size, ttype, ptr))
- goto out;
+ if (!dm_task_add_target(dmt, start, size, ttype, ptr))
+ goto out;
free(ttype);
- }
- r = 1;
+ }
+ r = 1;
- out:
- fclose(fp);
- return r;
+ out:
+ fclose(fp);
+ return r;
}
static int _load(int task, const char *name, const char *file)
r = 1;
-out:
+ out:
dm_task_destroy(dmt);
return r;
int r = 0;
struct dm_task *dmt;
- if (!(dmt = dm_task_create(DM_DEVICE_RENAME)))
- return 0;
+ if (!(dmt = dm_task_create(DM_DEVICE_RENAME)))
+ return 0;
- if (!dm_task_set_name(dmt, argv[1]))
- goto out;
+ if (!dm_task_set_name(dmt, argv[1]))
+ goto out;
if (!dm_task_set_newname(dmt, argv[2]))
goto out;
- if (!dm_task_run(dmt))
- goto out;
+ if (!dm_task_run(dmt))
+ goto out;
- r = 1;
+ r = 1;
-out:
- dm_task_destroy(dmt);
+ out:
+ dm_task_destroy(dmt);
- return r;
+ return r;
}
static int _version(int argc, char **argv)
if (!dm_task_run(dmt))
goto out;
- if (!dm_task_get_driver_version(dmt, (char *)&version,
+ if (!dm_task_get_driver_version(dmt, (char *) &version,
sizeof(version)))
goto out;
r = dm_task_run(dmt);
- out:
+ out:
dm_task_destroy(dmt);
return r;
}
+static int _remove_all(int argc, char **argv)
+{
+ return _simple(DM_DEVICE_REMOVE_ALL, "");
+}
+
static int _remove(int argc, char **argv)
{
return _simple(DM_DEVICE_REMOVE, argv[1]);
r = 1;
- out:
+ out:
dm_task_destroy(dmt);
return r;
}
r = 1;
- out:
+ out:
dm_task_destroy(dmt);
return r;
}
-
/*
* dispatch table
*/
-typedef int (*command_fn)(int argc, char **argv);
+typedef int (*command_fn) (int argc, char **argv);
struct command {
char *name;
static struct command _commands[] = {
{"create", "<dev_name> <table_file>", 2, _create},
{"remove", "<dev_name>", 1, _remove},
+ {"remove_all", "", 0, _remove_all},
{"suspend", "<dev_name>", 1, _suspend},
{"resume", "<dev_name>", 1, _resume},
{"reload", "<dev_name> <table_file>", 2, _reload},
{NULL, NULL, 0, NULL}
};
-static void _usage(FILE *out)
+static void _usage(FILE * out)
{
int i;
fprintf(out, "usage:\n");
for (i = 0; _commands[i].name; i++)
- fprintf(out, "\t%s %s\n",
- _commands[i].name, _commands[i].help);
+ fprintf(out, "\t%s %s\n", _commands[i].name, _commands[i].help);
return;
}
return 0;
}
-
-0.94.06-cvs (2002-03-07)
+0.94.07-cvs (2002-03-07)
struct target *target;
int rw;
- void (*end_io)(struct buffer_head *bh, int uptodate);
+ void (*end_io) (struct buffer_head * bh, int uptodate);
void *context;
};
static devfs_handle_t _dev_dir;
-static int request(request_queue_t *q, int rw, struct buffer_head *bh);
+static int request(request_queue_t * q, int rw, struct buffer_head *bh);
static int dm_user_bmap(struct inode *inode, struct lv_bmap *lvb);
/*
if (r)
goto out_mirror;
-
return 0;
out_mirror:
static void __exit dm_exit(void)
{
+ dm_destroy_all();
dm_interface_exit();
dm_stripe_exit();
dm_linear_exit();
case BLKGETSIZE:
size = VOLUME_SIZE(minor);
- if (copy_to_user((void *)a, &size, sizeof(long)))
+ if (copy_to_user((void *) a, &size, sizeof(long)))
return -EFAULT;
break;
case BLKGETSIZE64:
size = VOLUME_SIZE(minor);
- if (put_user((u64)size, (u64 *)a))
+ if (put_user((u64) size, (u64 *) a))
return -EFAULT;
break;
return (KEYS_PER_NODE * n) + k;
}
-static int request(request_queue_t *q, int rw, struct buffer_head *bh)
+static int request(request_queue_t * q, int rw, struct buffer_head *bh)
{
struct mapped_device *md;
int r, minor = MINOR(bh->b_rdev);
}
}
-
if ((r = __map_buffer(md, bh, rw, __find_node(md->map, bh))) < 0)
goto bad;
md->name[sizeof(md->name) - 1] = '\0';
if (*uuid) {
- if (!(md->uuid = kmalloc(strnlen(uuid, DM_UUID_LEN),
+ if (!(md->uuid = kmalloc(strnlen(uuid, DM_UUID_LEN),
GFP_KERNEL))) {
DMWARN("unable to allocate uuid - out of memory.");
return NULL;
spin_unlock(&_create_lock);
return 0;
- err:
+ err:
_devs[minor] = NULL;
if (md->uuid)
kfree(md->uuid);
return 0;
}
+/*
+ * Destroy all devices - except suspended ones...
+ */
+void dm_destroy_all(void)
+{
+ int i;
+ struct mapped_device *md;
+
+ for (i = 0; i < MAX_DEVICES; i++) {
+ md = dm_get_w(i);
+ if (!md)
+ continue;
+
+ dm_destroy(md);
+ dm_put_w(i);
+ }
+}
+
/*
* Sets or clears the read-only flag for the device. Write lock
* must be held.
int dm_create(const char *name, const char *uuid,
int minor, struct dm_table *table);
int dm_set_name(const char *oldname, const char *newname);
+void dm_destroy_all(void);
/*
* You must have the write lock before calling the remaining md
static int version(struct dm_ioctl *user)
{
- return copy_to_user(user, DM_DRIVER_VERSION, sizeof(DM_DRIVER_VERSION));
+ return copy_to_user(user, DM_DRIVER_VERSION, sizeof(DM_DRIVER_VERSION));
}
static int copy_params(struct dm_ioctl *user, struct dm_ioctl **result)
struct dm_target_spec **spec, char **params)
{
*spec = (struct dm_target_spec *)
- ((unsigned char *) last + next);
+ ((unsigned char *) last + next);
*params = (char *) (*spec + 1);
- if (*spec < (last + 1) || ((void *)*spec > end))
+ if (*spec < (last + 1) || ((void *) *spec > end))
return -EINVAL;
return valid_str(*params, begin, end);
for (i = 0; i < args->target_count; i++) {
- r = first ? next_target((struct dm_target_spec *)args,
+ r = first ? next_target((struct dm_target_spec *) args,
args->data_start,
begin, end, &spec, ¶ms) :
- next_target(spec, spec->next,
- begin, end, &spec, ¶ms);
+ next_target(spec, spec->next, begin, end, &spec, ¶ms);
if (r)
PARSE_ERROR("unable to find target");
/* Build the target */
if (ttype->ctr(table, spec->sector_start, spec->length,
argc, argv, &context)) {
- DMWARN("%s: target constructor failed",
- (char *)context);
+ DMWARN("%s: target constructor failed",
+ (char *) context);
return -EINVAL;
}
__info(md, param);
dm_put_r(minor);
- out:
+ out:
return results_to_user(user, param, NULL, 0);
}
*/
count = 0;
list_for_each(tmp, &md->map->devices)
- count++;
+ count++;
/*
* Allocate a kernel space version of the dm_target_status
*/
deps->count = count;
count = 0;
- list_for_each (tmp, &md->map->devices) {
+ list_for_each(tmp, &md->map->devices) {
struct dm_dev *dd = list_entry(tmp, struct dm_dev, list);
deps->dev[count++] = kdev_t_to_nr(dd->dev);
}
dm_put_r(minor);
- out:
+ out:
r = results_to_user(user, param, deps, len);
kfree(deps);
}
minor = (param->flags & DM_PERSISTENT_DEV_FLAG) ?
- MINOR(to_kdev_t(param->dev)) : -1;
+ MINOR(to_kdev_t(param->dev)) : -1;
r = dm_create(param->name, param->uuid, minor, t);
if (r) {
return -ENXIO;
minor = MINOR(md->dev);
- r = (param->flags & DM_SUSPEND_FLAG) ?
- dm_suspend(md) : dm_resume(md);
+ r = (param->flags & DM_SUSPEND_FLAG) ? dm_suspend(md) : dm_resume(md);
dm_put_w(minor);
return r;
struct dm_ioctl *p;
uint cmd = _IOC_NR(command);
- if (cmd == DM_VERSION_CMD)
+ switch (cmd) {
+ case DM_REMOVE_ALL_CMD:
+ dm_destroy_all();
+ case DM_VERSION_CMD:
return version((struct dm_ioctl *) a);
+ default:
+ break;
+ }
r = copy_params((struct dm_ioctl *) a, &p);
if (r)
return r;
+ /* FIXME: Change to use size 0 next time ioctl version gets changed */
switch (cmd) {
case DM_CREATE_CMD:
r = create(p, (struct dm_ioctl *) a);
r = devfs_generate_path(_dm_misc.devfs_handle, rname + 3,
sizeof rname - 3);
if (r == -ENOSYS)
- return 0; /* devfs not present */
+ return 0; /* devfs not present */
if (r < 0) {
DMERR("devfs_generate_path failed for control device");
strncpy(rname + r, "../", 3);
r = devfs_mk_symlink(NULL, DM_DIR "/control",
- DEVFS_FL_DEFAULT, rname + r,
- &_ctl_handle, NULL);
+ DEVFS_FL_DEFAULT, rname + r, &_ctl_handle, NULL);
if (r) {
DMERR("devfs_mk_symlink failed for control device");
goto failed;
struct dm_ioctl {
char version[16];
- unsigned long data_size; /* total size of data passed in */
- /* including this struct */
+ unsigned long data_size; /* total size of data passed in
+ * including this struct */
- unsigned long data_start; /* offset to start of data */
- /* relative to start of this struct */
+ unsigned long data_start; /* offset to start of data
+ * relative to start of this struct */
char name[DM_NAME_LEN]; /* device name */
__kernel_dev_t dev; /* in/out */
- char uuid[DM_UUID_LEN]; /* unique identifier for
+ char uuid[DM_UUID_LEN]; /* unique identifier for
* the block device */
};
*/
};
-
/*
* Used to retrieve the target dependencies.
*/
struct dm_target_deps {
unsigned int count;
- __kernel_dev_t dev[0]; /* out */
+ __kernel_dev_t dev[0]; /* out */
};
-
#define DM_IOCTL 0xfd
enum {
- DM_CREATE_CMD=0,
+ DM_CREATE_CMD = 0,
DM_REMOVE_CMD,
DM_SUSPEND_CMD,
DM_RELOAD_CMD,
DM_INFO_CMD,
DM_RENAME_CMD,
DM_VERSION_CMD,
- DM_DEPS_CMD
+ DM_DEPS_CMD,
+ DM_REMOVE_ALL_CMD
};
-#define DM_CREATE _IOWR(DM_IOCTL, DM_CREATE_CMD, struct dm_ioctl)
-#define DM_REMOVE _IOW(DM_IOCTL, DM_REMOVE_CMD, struct dm_ioctl)
-#define DM_SUSPEND _IOW(DM_IOCTL, DM_SUSPEND_CMD, struct dm_ioctl)
-#define DM_RELOAD _IOW(DM_IOCTL, DM_RELOAD_CMD, struct dm_ioctl)
+#define DM_CREATE _IOWR(DM_IOCTL, DM_CREATE_CMD, struct dm_ioctl)
+#define DM_REMOVE _IOW(DM_IOCTL, DM_REMOVE_CMD, struct dm_ioctl)
+#define DM_SUSPEND _IOW(DM_IOCTL, DM_SUSPEND_CMD, struct dm_ioctl)
+#define DM_RELOAD _IOW(DM_IOCTL, DM_RELOAD_CMD, struct dm_ioctl)
#define DM_INFO _IOWR(DM_IOCTL, DM_INFO_CMD, struct dm_ioctl)
#define DM_RENAME _IOW(DM_IOCTL, DM_RENAME_CMD, struct dm_ioctl)
#define DM_VERSION _IOR(DM_IOCTL, DM_VERSION_CMD, struct dm_ioctl)
#define DM_DEPS _IOR(DM_IOCTL, DM_DEPS_CMD, struct dm_ioctl)
+#define DM_REMOVE_ALL _IOR(DM_IOCTL, DM_REMOVE_ALL_CMD, struct dm_ioctl)
#define DM_IOCTL_VERSION @DM_IOCTL_VERSION@
#define DM_DRIVER_VERSION @DM_DRIVER_VERSION@
#define DM_EXISTS_FLAG 0x00000004
#define DM_PERSISTENT_DEV_FLAG 0x00000008
-#endif /* _LINUX_DM_IOCTL_H */
+#endif /* _LINUX_DM_IOCTL_H */
free(dmt);
}
-int dm_task_get_driver_version(struct dm_task *dmt, char *version,
- size_t size)
+int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size)
{
if (!dmt->dmi)
return 0;
}
struct target *create_target(uint64_t start,
- uint64_t len,
- const char *type, const char *params)
+ uint64_t len, const char *type, const char *params)
{
struct target *t = malloc(sizeof(*t));
if (!t) {
- log_error("create_target: malloc(%d) failed", sizeof(*t));
+ log_error("create_target: malloc(%d) failed", sizeof(*t));
return NULL;
}
t->length = len;
return t;
- bad:
+ bad:
free(t->params);
free(t->type);
free(t);
return dmi;
- bad:
+ bad:
free(dmi);
return NULL;
}
command = DM_REMOVE;
break;
+ case DM_DEVICE_REMOVE_ALL:
+ command = DM_REMOVE_ALL;
+ break;
+
case DM_DEVICE_SUSPEND:
command = DM_SUSPEND;
break;
default:
log_error("Internal error: unknown device-mapper task %d",
- dmt->type);
+ dmt->type);
goto bad;
}
if (ioctl(fd, command, dmi) < 0) {
log_error("device-mapper ioctl cmd %d failed: %s", dmt->type,
- strerror(errno));
+ strerror(errno));
goto bad;
}
close(fd);
return 1;
- bad:
+ bad:
free(dmi);
if (fd >= 0)
close(fd);
return 0;
}
-
* each ioctl command you want to execute.
*/
-
-typedef void (*dm_log_fn)(int level, const char *file, int line,
- const char *f, ...);
+typedef void (*dm_log_fn) (int level, const char *file, int line,
+ const char *f, ...);
/*
* The library user may wish to register their own
DM_DEVICE_CREATE,
DM_DEVICE_RELOAD,
DM_DEVICE_REMOVE,
+ DM_DEVICE_REMOVE_ALL,
DM_DEVICE_SUSPEND,
DM_DEVICE_RESUME,
DM_DEVICE_VERSION,
};
-
struct dm_task;
struct dm_task *dm_task_create(int type);
};
int dm_get_library_version(char *version, size_t size);
-int dm_task_get_driver_version(struct dm_task *dmt, char *version,
- size_t size);
+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);
struct dm_deps *dm_task_get_deps(struct dm_task *dmt);
*/
int dm_task_add_target(struct dm_task *dmt,
uint64_t start,
- uint64_t size,
- const char *ttype,
- const char *params);
+ uint64_t size, const char *ttype, const char *params);
/*
* Call this to actually run the ioctl.
int dm_set_dev_dir(const char *dir);
const char *dm_dir(void);
-#endif /* LIB_DEVICE_MAPPER_H */
+#endif /* LIB_DEVICE_MAPPER_H */