mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o various little tidy ups
This commit is contained in:
parent
a18deda24b
commit
5410a899ef
@ -204,7 +204,7 @@ static int process_control(const char *b, const char *e, int minor)
|
||||
static int process_table(const char *b, const char *e, int minor)
|
||||
{
|
||||
const char *wb, *we;
|
||||
struct mapped_device *md = dm_find_minor(minor);
|
||||
struct mapped_device *md = dm_find_by_minor(minor);
|
||||
void *context;
|
||||
int r;
|
||||
|
||||
@ -219,11 +219,11 @@ static int process_table(const char *b, const char *e, int minor)
|
||||
dm_suspend(md);
|
||||
|
||||
/* start loading a table */
|
||||
dm_start_table(md);
|
||||
dm_table_start(md);
|
||||
|
||||
} else if (!tok_cmp("end", b, e)) {
|
||||
/* activate the device ... <evil chuckle> ... */
|
||||
dm_complete_table(md);
|
||||
dm_table_complete(md);
|
||||
dm_activate(md);
|
||||
|
||||
} else {
|
||||
@ -264,7 +264,7 @@ static int process_table(const char *b, const char *e, int minor)
|
||||
if ((r = t->ctr(start, high, md, we, e, &context)))
|
||||
return r;
|
||||
|
||||
if ((r = dm_add_entry(md, high, t->map, context)))
|
||||
if ((r = dm_table_add_entry(md, high, t->map, context)))
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -78,17 +78,15 @@ void dm_free_table(struct mapped_device *md)
|
||||
}
|
||||
|
||||
vfree(md->targets);
|
||||
vfree(md->contexts);
|
||||
|
||||
md->highs = 0;
|
||||
md->targets = 0;
|
||||
md->contexts = 0;
|
||||
|
||||
md->num_targets = 0;
|
||||
md->num_allocated = 0;
|
||||
}
|
||||
|
||||
int dm_start_table(struct mapped_device *md)
|
||||
int dm_table_start(struct mapped_device *md)
|
||||
{
|
||||
int r;
|
||||
set_bit(DM_LOADING, &md->state);
|
||||
@ -100,7 +98,7 @@ int dm_start_table(struct mapped_device *md)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dm_add_entry(struct mapped_device *md, offset_t high,
|
||||
int dm_table_add_entry(struct mapped_device *md, offset_t high,
|
||||
dm_map_fn target, void *context)
|
||||
{
|
||||
if (md->num_targets >= md->num_targets &&
|
||||
@ -108,14 +106,14 @@ int dm_add_entry(struct mapped_device *md, offset_t high,
|
||||
return -ENOMEM;
|
||||
|
||||
md->highs[md->num_targets] = high;
|
||||
md->targets[md->num_targets] = target;
|
||||
md->contexts[md->num_targets] = context;
|
||||
md->targets[md->num_targets].map = target;
|
||||
md->targets[md->num_targets].private = context;
|
||||
|
||||
md->num_targets++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dm_complete_table(struct mapped_device *md)
|
||||
int dm_table_complete(struct mapped_device *md)
|
||||
{
|
||||
int n, i;
|
||||
|
||||
@ -151,8 +149,7 @@ int dm_complete_table(struct mapped_device *md)
|
||||
static int alloc_targets(struct mapped_device *md, int num)
|
||||
{
|
||||
offset_t *n_highs;
|
||||
dm_map_fn *n_targets;
|
||||
void **n_contexts;
|
||||
struct target_instance *n_targets;
|
||||
|
||||
if (!(n_highs = vmalloc(sizeof(*n_highs) * num)))
|
||||
return -ENOMEM;
|
||||
@ -162,31 +159,20 @@ static int alloc_targets(struct mapped_device *md, int num)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!(n_contexts = vmalloc(sizeof(*n_contexts) * num))) {
|
||||
vfree(n_highs);
|
||||
vfree(n_targets);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (md->num_targets) {
|
||||
memcpy(n_highs, md->highs,
|
||||
sizeof(*n_highs) * md->num_targets);
|
||||
|
||||
memcpy(n_targets, md->targets,
|
||||
sizeof(*n_targets) * md->num_targets);
|
||||
|
||||
memcpy(n_contexts, md->contexts,
|
||||
sizeof(*n_contexts) * md->num_targets);
|
||||
}
|
||||
|
||||
vfree(md->highs);
|
||||
vfree(md->targets);
|
||||
vfree(md->contexts);
|
||||
|
||||
md->num_allocated = num;
|
||||
md->highs = n_highs;
|
||||
md->targets = n_targets;
|
||||
md->contexts = n_contexts;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ int register_map_target(const char *name, dm_ctr_fn ctr,
|
||||
*
|
||||
* 'linear' target maps a linear range of a device
|
||||
*/
|
||||
int io_err_ctr(offset_t b, offset_t e, struct mapped_device *md,
|
||||
static int io_err_ctr(offset_t b, offset_t e, struct mapped_device *md,
|
||||
const char *cb, const char *ce, void **result)
|
||||
{
|
||||
/* this takes no arguments */
|
||||
@ -93,12 +93,12 @@ int io_err_ctr(offset_t b, offset_t e, struct mapped_device *md,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void io_err_dtr(void *c)
|
||||
static void io_err_dtr(void *c)
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
|
||||
int io_err_map(struct buffer_head *bh, void *context)
|
||||
static int io_err_map(struct buffer_head *bh, void *context)
|
||||
{
|
||||
buffer_IO_error(bh);
|
||||
return 0;
|
||||
@ -110,7 +110,7 @@ struct linear_c {
|
||||
int offset; /* FIXME: we need a signed offset type */
|
||||
};
|
||||
|
||||
int linear_ctr(offset_t low, offset_t high, struct mapped_device *md,
|
||||
static int linear_ctr(offset_t low, offset_t high, struct mapped_device *md,
|
||||
const char *cb, const char *ce, void **result)
|
||||
{
|
||||
/* context string should be of the form:
|
||||
@ -146,12 +146,12 @@ int linear_ctr(offset_t low, offset_t high, struct mapped_device *md,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void linear_dtr(void *c)
|
||||
static void linear_dtr(void *c)
|
||||
{
|
||||
kfree(c);
|
||||
}
|
||||
|
||||
int linear_map(struct buffer_head *bh, void *context)
|
||||
static int linear_map(struct buffer_head *bh, void *context)
|
||||
{
|
||||
struct linear_c *lc = (struct linear_c *) context;
|
||||
|
||||
|
@ -119,7 +119,7 @@ static void fin(void)
|
||||
blksize_size[MAJOR_NR] = 0;
|
||||
hardsect_size[MAJOR_NR] = 0;
|
||||
|
||||
printk(KERN_INFO "%s %d.%d.%d finalised\n", _name,
|
||||
printk(KERN_INFO "%s %d.%d.%d cleaned up\n", _name,
|
||||
_version[0], _version[1], _version[2]);
|
||||
}
|
||||
|
||||
@ -285,9 +285,10 @@ inline static int __map_buffer(struct mapped_device *md,
|
||||
void *context;
|
||||
struct io_hook *ih = 0;
|
||||
int r;
|
||||
struct target_instance *ti = md->targets + node;
|
||||
|
||||
fn = md->targets[node];
|
||||
context = md->contexts[node];
|
||||
fn = ti->map;
|
||||
context = ti->private;
|
||||
|
||||
if (!fn)
|
||||
return 0;
|
||||
@ -321,12 +322,28 @@ inline static int __map_buffer(struct mapped_device *md,
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline static int __find_node(struct mapped_device *md, struct buffer_head *bh)
|
||||
{
|
||||
int i = 0, l, r = 0;
|
||||
offset_t *node;
|
||||
|
||||
/* search the btree for the correct target */
|
||||
for (l = 0; l < md->depth; l++) {
|
||||
r = ((KEYS_PER_NODE + 1) * r) + i;
|
||||
node = md->index[l] + (r * KEYS_PER_NODE);
|
||||
|
||||
for (i = 0; i < KEYS_PER_NODE; i++)
|
||||
if (node[i] >= bh->b_rsector)
|
||||
break;
|
||||
}
|
||||
|
||||
return (KEYS_PER_NODE * r) + i;
|
||||
}
|
||||
|
||||
static int request(request_queue_t *q, int rw, struct buffer_head *bh)
|
||||
{
|
||||
struct mapped_device *md;
|
||||
offset_t *node;
|
||||
int i = 0, l, next_node = 0, r;
|
||||
int minor = MINOR(bh->b_rdev);
|
||||
int r, minor = MINOR(bh->b_rdev);
|
||||
|
||||
if (minor >= MAX_DEVICES)
|
||||
return -ENXIO;
|
||||
@ -352,18 +369,7 @@ static int request(request_queue_t *q, int rw, struct buffer_head *bh)
|
||||
rl; /* FIXME: there's still a race here */
|
||||
}
|
||||
|
||||
/* search the btree for the correct target */
|
||||
for (l = 0; l < md->depth; l++) {
|
||||
next_node = ((KEYS_PER_NODE + 1) * next_node) + i;
|
||||
node = md->index[l] + (next_node * KEYS_PER_NODE);
|
||||
|
||||
for (i = 0; i < KEYS_PER_NODE; i++)
|
||||
if (node[i] >= bh->b_rsector)
|
||||
break;
|
||||
}
|
||||
next_node = (KEYS_PER_NODE * next_node) + i;
|
||||
|
||||
if (!__map_buffer(md, bh, next_node))
|
||||
if (!__map_buffer(md, bh, __find_node(md, bh)))
|
||||
goto bad;
|
||||
|
||||
ru;
|
||||
@ -472,7 +478,7 @@ static int __find_hardsect_size(struct mapped_device *md)
|
||||
return r;
|
||||
}
|
||||
|
||||
struct mapped_device *dm_find_name(const char *name)
|
||||
struct mapped_device *dm_find_by_name(const char *name)
|
||||
{
|
||||
struct mapped_device *md;
|
||||
|
||||
@ -483,7 +489,7 @@ struct mapped_device *dm_find_name(const char *name)
|
||||
return md;
|
||||
}
|
||||
|
||||
struct mapped_device *dm_find_minor(int minor)
|
||||
struct mapped_device *dm_find_by_minor(int minor)
|
||||
{
|
||||
struct mapped_device *md;
|
||||
|
||||
|
@ -142,18 +142,26 @@ enum {
|
||||
DM_ACTIVE,
|
||||
};
|
||||
|
||||
/* devices that a metadevice should uses and hence open/close */
|
||||
struct dev_list {
|
||||
kdev_t dev;
|
||||
struct block_device *bd;
|
||||
struct dev_list *next;
|
||||
};
|
||||
|
||||
/* io that had to be deferred while we were suspended */
|
||||
struct deferred_io {
|
||||
int rw;
|
||||
struct buffer_head *bh;
|
||||
struct deferred_io *next;
|
||||
};
|
||||
|
||||
/* btree leaf, these do the actual mapping */
|
||||
struct target_instance {
|
||||
dm_map_fn map;
|
||||
void *private;
|
||||
};
|
||||
|
||||
struct mapped_device {
|
||||
kdev_t dev;
|
||||
char name[DM_NAME_LEN];
|
||||
@ -175,8 +183,7 @@ struct mapped_device {
|
||||
int num_targets;
|
||||
int num_allocated;
|
||||
offset_t *highs;
|
||||
dm_map_fn *targets;
|
||||
void **contexts;
|
||||
struct target_instance *targets;
|
||||
|
||||
/* used by dm-fs.c */
|
||||
devfs_handle_t devfs_entry;
|
||||
@ -186,6 +193,7 @@ struct mapped_device {
|
||||
struct dev_list *devices;
|
||||
};
|
||||
|
||||
/* information about a target type */
|
||||
struct target {
|
||||
char *name;
|
||||
dm_ctr_fn ctr;
|
||||
@ -202,8 +210,8 @@ struct target *dm_get_target(const char *name);
|
||||
int dm_std_targets(void);
|
||||
|
||||
/* dm.c */
|
||||
struct mapped_device *dm_find_name(const char *name);
|
||||
struct mapped_device *dm_find_minor(int minor);
|
||||
struct mapped_device *dm_find_by_name(const char *name);
|
||||
struct mapped_device *dm_find_by_minor(int minor);
|
||||
|
||||
int dm_create(const char *name, int minor);
|
||||
int dm_remove(const char *name);
|
||||
@ -212,10 +220,10 @@ int dm_activate(struct mapped_device *md);
|
||||
void dm_suspend(struct mapped_device *md);
|
||||
|
||||
/* dm-table.c */
|
||||
int dm_start_table(struct mapped_device *md);
|
||||
int dm_add_entry(struct mapped_device *md, offset_t high,
|
||||
int dm_table_start(struct mapped_device *md);
|
||||
int dm_table_add_entry(struct mapped_device *md, offset_t high,
|
||||
dm_map_fn target, void *context);
|
||||
int dm_complete_table(struct mapped_device *md);
|
||||
int dm_table_complete(struct mapped_device *md);
|
||||
void dm_free_table(struct mapped_device *md);
|
||||
|
||||
|
||||
@ -257,5 +265,4 @@ inline static int get_number(const char **b, const char *e, unsigned int *n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user