1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 10:25:13 +03:00

o map loads ok now

o request function appears to work, but something is segfaulting when i
  mke2fs
This commit is contained in:
Joe Thornber 2001-08-23 12:35:02 +00:00
parent 0bdf99c171
commit 3cf3ab579e
6 changed files with 195 additions and 149 deletions

View File

@ -39,7 +39,7 @@ struct mapped_device;
typedef unsigned int offset_t; typedef unsigned int offset_t;
typedef int (*dm_ctr_fn)(offset_t b, offset_t e, struct mapped_device *md, typedef int (*dm_ctr_fn)(offset_t b, offset_t e, struct mapped_device *md,
const char *context, void **result); const char *cb, const char *ce, void **result);
typedef void (*dm_dtr_fn)(void *c); typedef void (*dm_dtr_fn)(void *c);
typedef int (*dm_map_fn)(struct buffer_head *bh, void *context); typedef int (*dm_map_fn)(struct buffer_head *bh, void *context);

View File

@ -49,16 +49,15 @@ static struct proc_dir_entry *_control;
static devfs_handle_t _dev_dir; static devfs_handle_t _dev_dir;
static int _line_splitter(struct file *file, const char *buffer, static int line_splitter(struct file *file, const char *buffer,
unsigned long count, void *data); unsigned long count, void *data);
int _process_control(const char *b, const char *e, int minor); static int process_control(const char *b, const char *e, int minor);
static int _process_table(const char *b, const char *e, int minor); static int process_table(const char *b, const char *e, int minor);
static const char *_eat_space(const char *b, const char *e); static int get_word(const char *b, const char *e,
static int _get_word(const char *b, const char *e, const char **wb, const char **we);
const char **wb, const char **we); static int tok_cmp(const char *str, const char *b, const char *e);
static int _tok_cmp(const char *str, const char *b, const char *e); static void tok_cpy(char *dest, size_t max,
static void _tok_cpy(char *dest, size_t max, const char *b, const char *e);
const char *b, const char *e);
typedef int (*process_fn)(const char *b, const char *e, int minor); typedef int (*process_fn)(const char *b, const char *e, int minor);
@ -82,9 +81,9 @@ int dm_init_fs()
if (!(_control = create_proc_entry(_control_name, S_IWUSR, _proc_dir))) if (!(_control = create_proc_entry(_control_name, S_IWUSR, _proc_dir)))
goto fail; goto fail;
_control->write_proc = _line_splitter; _control->write_proc = line_splitter;
pfd->fn = _process_control; pfd->fn = process_control;
pfd->minor = -1; pfd->minor = -1;
_control->data = pfd; _control->data = pfd;
@ -118,7 +117,7 @@ int dm_fs_add(struct mapped_device *md)
if (!pfd) if (!pfd)
return -ENOMEM; return -ENOMEM;
pfd->fn = _process_table; pfd->fn = process_table;
pfd->minor = MINOR(md->dev); pfd->minor = MINOR(md->dev);
if (!(md->pde = create_proc_entry(md->name, S_IRUGO | S_IWUSR, if (!(md->pde = create_proc_entry(md->name, S_IRUGO | S_IWUSR,
@ -127,7 +126,7 @@ int dm_fs_add(struct mapped_device *md)
return -ENOMEM; return -ENOMEM;
} }
md->pde->write_proc = _line_splitter; md->pde->write_proc = line_splitter;
md->pde->data = pfd; md->pde->data = pfd;
md->devfs_entry = md->devfs_entry =
@ -140,7 +139,7 @@ int dm_fs_add(struct mapped_device *md)
kfree(pfd); kfree(pfd);
remove_proc_entry(md->name, _proc_dir); remove_proc_entry(md->name, _proc_dir);
md->pde = 0; md->pde = 0;
return -ENOMEM; /* FIXME: better error ? */ return -ENOMEM;
} }
return 0; return 0;
@ -159,7 +158,7 @@ int dm_fs_remove(struct mapped_device *md)
return 0; return 0;
} }
int _process_control(const char *b, const char *e, int minor) static int process_control(const char *b, const char *e, int minor)
{ {
const char *wb, *we; const char *wb, *we;
char name[64]; char name[64];
@ -169,27 +168,27 @@ int _process_control(const char *b, const char *e, int minor)
* create <name> [minor] * create <name> [minor]
* remove <name> * remove <name>
*/ */
if (!_get_word(b, e, &wb, &we)) if (get_word(b, e, &wb, &we))
return -EINVAL; return -EINVAL;
b = we; b = we;
if (!_tok_cmp("create", wb, we)) if (!tok_cmp("create", wb, we))
create = 1; create = 1;
else if (_tok_cmp("remove", wb, we)) else if (tok_cmp("remove", wb, we))
return -EINVAL; return -EINVAL;
if (!_get_word(b, e, &wb, &we)) if (get_word(b, e, &wb, &we))
return -EINVAL; return -EINVAL;
b = we; b = we;
_tok_cpy(name, sizeof(name), wb, we); tok_cpy(name, sizeof(name), wb, we);
if (!create) if (!create)
return dm_remove(name); return dm_remove(name);
else { else {
if (_get_word(b, e, &wb, &we)) { if (!get_word(b, e, &wb, &we)) {
minor = simple_strtol(wb, (char **) &we, 10); minor = simple_strtol(wb, (char **) &we, 10);
if (we == wb) if (we == wb)
@ -202,27 +201,27 @@ int _process_control(const char *b, const char *e, int minor)
return -EINVAL; return -EINVAL;
} }
static int _process_table(const char *b, const char *e, int minor) static int process_table(const char *b, const char *e, int minor)
{ {
const char *wb, *we; const char *wb, *we;
struct mapped_device *md = dm_find_minor(minor); struct mapped_device *md = dm_find_minor(minor);
void *context; void *context;
int ret; int r;
if (!md) if (!md)
return -ENXIO; return -ENXIO;
if (!_get_word(b, e, &wb, &we)) if (get_word(b, e, &wb, &we))
return -EINVAL; return -EINVAL;
if (!_tok_cmp("begin", b, e)) { if (!tok_cmp("begin", b, e)) {
/* suspend the device if it's active */ /* suspend the device if it's active */
dm_suspend(md); dm_suspend(md);
/* start loading a table */ /* start loading a table */
dm_start_table(md); dm_start_table(md);
} else if (!_tok_cmp("end", b, e)) { } else if (!tok_cmp("end", b, e)) {
/* activate the device ... <evil chuckle> ... */ /* activate the device ... <evil chuckle> ... */
dm_complete_table(md); dm_complete_table(md);
dm_activate(md); dm_activate(md);
@ -233,74 +232,69 @@ static int _process_table(const char *b, const char *e, int minor)
char high_s[64], *ptr; char high_s[64], *ptr;
char target[64]; char target[64];
struct target *t; struct target *t;
offset_t high; offset_t last = 0, high;
if (len > sizeof(high_s)) if (len > sizeof(high_s))
return 0; return -EINVAL;
strncpy(high_s, wb, we - wb); strncpy(high_s, wb, we - wb);
high_s[len] = '\0'; high_s[len] = '\0';
high = simple_strtol(high_s, &ptr, 10); high = simple_strtol(high_s, &ptr, 10);
if (ptr == high_s) if (ptr == high_s)
return 0; return -EINVAL;
b = we; b = we;
if (!_get_word(b, e, &wb, &we)) if (get_word(b, e, &wb, &we))
return 0; return -EINVAL;
len = we - wb; len = we - wb;
if (len > sizeof(target)) if (len > sizeof(target))
return 0; return -EINVAL;
strncpy(target, wb, len); strncpy(target, wb, len);
target[len] = '\0'; target[len] = '\0';
if (!(t = dm_get_target(target))) if (!(t = dm_get_target(target)))
return 0; return -EINVAL;
if ((ret = t->ctr(md->highs[md->num_targets - 1], if (md->num_targets)
high, md, we, &context))) last = md->highs[md->num_targets - 1] + 1;
return ret;
dm_add_entry(md, high, t->map, context); if ((r = t->ctr(last, high, md, we, e, &context)))
return r;
if ((r = dm_add_entry(md, high, t->map, context)))
return r;
} }
return 1; return 0;
} }
static const char *_eat_space(const char *b, const char *e) static int get_word(const char *b, const char *e,
const char **wb, const char **we)
{ {
while(b != e && isspace((int) *b)) b = eat_space(b, e);
b++;
return b;
}
static int _get_word(const char *b, const char *e,
const char **wb, const char **we)
{
b = _eat_space(b, e);
if (b == e) if (b == e)
return 0; return -EINVAL;
*wb = b; *wb = b;
while(b != e && !isspace((int) *b)) while(b != e && !isspace((int) *b))
b++; b++;
*we = b; *we = b;
return 1; return 0;
} }
static int _line_splitter(struct file *file, const char *buffer, static int line_splitter(struct file *file, const char *buffer,
unsigned long count, void *data) unsigned long count, void *data)
{ {
int r; int r;
const char *b = buffer, *e = buffer + count, *lb; const char *b = buffer, *e = buffer + count, *lb;
struct pf_data *pfd = (struct pf_data *) data; struct pf_data *pfd = (struct pf_data *) data;
while(b < e) { while(b < e) {
b = _eat_space(b, e); b = eat_space(b, e);
if (b == e) if (b == e)
break; break;
@ -315,7 +309,7 @@ static int _line_splitter(struct file *file, const char *buffer,
return count; return count;
} }
static int _tok_cmp(const char *str, const char *b, const char *e) static int tok_cmp(const char *str, const char *b, const char *e)
{ {
while (*str && b != e) { while (*str && b != e) {
if (*str < *b) if (*str < *b)
@ -336,8 +330,8 @@ static int _tok_cmp(const char *str, const char *b, const char *e)
return -1; return -1;
} }
static void _tok_cpy(char *dest, size_t max, static void tok_cpy(char *dest, size_t max,
const char *b, const char *e) const char *b, const char *e)
{ {
size_t len = e - b; size_t len = e - b;
if (len > --max) if (len > --max)

View File

@ -27,20 +27,20 @@
#include "dm.h" #include "dm.h"
static int _alloc_targets(struct mapped_device *md, int num); static int alloc_targets(struct mapped_device *md, int num);
static inline ulong _round_up(ulong n, ulong size) static inline ulong round_up(ulong n, ulong size)
{ {
ulong r = n % size; ulong r = n % size;
return n + (r ? (size - r) : 0); return n + (r ? (size - r) : 0);
} }
static inline ulong _div_up(ulong n, ulong size) static inline ulong div_up(ulong n, ulong size)
{ {
return _round_up(n, size) / size; return round_up(n, size) / size;
} }
static offset_t _high(struct mapped_device *md, int l, int n) static offset_t high(struct mapped_device *md, int l, int n)
{ {
while (1) { while (1) {
if (n >= md->counts[l]) if (n >= md->counts[l])
@ -54,7 +54,7 @@ static offset_t _high(struct mapped_device *md, int l, int n)
} }
} }
static int _setup_btree_index(int l, struct mapped_device *md) static int setup_btree_index(int l, struct mapped_device *md)
{ {
int n, c, cn; int n, c, cn;
@ -62,22 +62,27 @@ static int _setup_btree_index(int l, struct mapped_device *md)
offset_t *k = md->index[l] + (n * KEYS_PER_NODE); offset_t *k = md->index[l] + (n * KEYS_PER_NODE);
for (c = 0; c < KEYS_PER_NODE; c++) for (c = 0; c < KEYS_PER_NODE; c++)
k[c] = _high(md, l + 1, cn++); k[c] = high(md, l + 1, cn++);
cn++; cn++;
} }
return 1; return 0;
} }
void dm_free_table(struct mapped_device *md) void dm_free_table(struct mapped_device *md)
{ {
int i; int i;
for (i = 0; i < md->depth; i++) for (i = 0; i < md->depth; i++) {
vfree(md->index[i]); vfree(md->index[i]);
md->index[i] = 0;
}
vfree(md->targets); vfree(md->targets);
vfree(md->contexts); vfree(md->contexts);
md->targets = 0;
md->contexts = 0;
md->num_targets = 0; md->num_targets = 0;
md->num_allocated = 0; md->num_allocated = 0;
} }
@ -88,7 +93,7 @@ int dm_start_table(struct mapped_device *md)
set_bit(DM_LOADING, &md->state); set_bit(DM_LOADING, &md->state);
dm_free_table(md); dm_free_table(md);
if ((r = _alloc_targets(md, 2))) /* FIXME: increase once debugged 256 ? */ if ((r = alloc_targets(md, 2))) /* FIXME: increase once debugged 256 ? */
return r; return r;
return 0; return 0;
@ -98,7 +103,7 @@ int dm_add_entry(struct mapped_device *md, offset_t high,
dm_map_fn target, void *context) dm_map_fn target, void *context)
{ {
if (md->num_targets >= md->num_targets && if (md->num_targets >= md->num_targets &&
!_alloc_targets(md, md->num_allocated * 2)) alloc_targets(md, md->num_allocated * 2))
return -ENOMEM; return -ENOMEM;
md->highs[md->num_targets] = high; md->highs[md->num_targets] = high;
@ -116,14 +121,14 @@ int dm_complete_table(struct mapped_device *md)
clear_bit(DM_LOADING, &md->state); clear_bit(DM_LOADING, &md->state);
/* how many indexes will the btree have ? */ /* how many indexes will the btree have ? */
for (n = _div_up(md->num_targets, KEYS_PER_NODE), i = 1; n != 1; i++) for (n = div_up(md->num_targets, KEYS_PER_NODE), i = 1; n != 1; i++)
n = _div_up(n, KEYS_PER_NODE + 1); n = div_up(n, KEYS_PER_NODE + 1);
md->depth = i; md->depth = i;
md->counts[md->depth - 1] = _div_up(md->num_targets, KEYS_PER_NODE); md->counts[md->depth - 1] = div_up(md->num_targets, KEYS_PER_NODE);
while (--i) while (--i)
md->counts[i - 1] = _div_up(md->counts[i], KEYS_PER_NODE + 1); md->counts[i - 1] = div_up(md->counts[i], KEYS_PER_NODE + 1);
for (i = 0; i < md->depth; i++) { for (i = 0; i < md->depth; i++) {
size_t s = NODE_SIZE * md->counts[i]; size_t s = NODE_SIZE * md->counts[i];
@ -136,13 +141,13 @@ int dm_complete_table(struct mapped_device *md)
/* fill in higher levels */ /* fill in higher levels */
for (i = md->depth - 1; i; i--) for (i = md->depth - 1; i; i--)
_setup_btree_index(i - 1, md); setup_btree_index(i - 1, md);
set_bit(DM_LOADED, &md->state); set_bit(DM_LOADED, &md->state);
return 1; return 0;
} }
static int _alloc_targets(struct mapped_device *md, int num) static int alloc_targets(struct mapped_device *md, int num)
{ {
offset_t *n_highs; offset_t *n_highs;
dm_map_fn *n_targets; dm_map_fn *n_targets;

View File

@ -25,6 +25,8 @@
#include "dm.h" #include "dm.h"
#include <linux/ctype.h>
static struct target *_targets; static struct target *_targets;
static spinlock_t _lock = SPIN_LOCK_UNLOCKED; static spinlock_t _lock = SPIN_LOCK_UNLOCKED;
@ -84,20 +86,20 @@ int register_map_target(const char *name, dm_ctr_fn ctr,
* *
* 'linear' target maps a linear range of a device * 'linear' target maps a linear range of a device
*/ */
int _io_err_ctr(offset_t b, offset_t e, struct mapped_device *md, int io_err_ctr(offset_t b, offset_t e, struct mapped_device *md,
const char *context, void **result) const char *cb, const char *ce, void **result)
{ {
/* this takes no arguments */ /* this takes no arguments */
*result = 0; *result = 0;
return 1; return 0;
} }
void _io_err_dtr(void *c) void io_err_dtr(void *c)
{ {
/* empty */ /* empty */
} }
int _io_err_map(struct buffer_head *bh, void *context) int io_err_map(struct buffer_head *bh, void *context)
{ {
buffer_IO_error(bh); buffer_IO_error(bh);
return 0; return 0;
@ -109,38 +111,47 @@ struct linear_c {
int offset; /* FIXME: we need a signed offset type */ int offset; /* FIXME: we need a signed offset type */
}; };
int _linear_ctr(offset_t b, offset_t e, struct mapped_device *md, static int get_number(const char **b, const char *e, unsigned int *n)
const char *context, void **result) {
char *ptr;
*b = eat_space(*b, e);
if (*b >= e)
return -EINVAL;
*n = simple_strtoul(*b, &ptr, 10);
if (ptr == *b)
return -EINVAL;
*b = ptr;
return 0;
}
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: /* context string should be of the form:
* <major> <minor> <offset> * <major> <minor> <offset>
*/ */
char *ptr = (char *) context;
struct linear_c *lc; struct linear_c *lc;
int major, minor, start; unsigned int major, minor, start;
int r;
/* FIXME: somewhat verbose */ if ((r = get_number(&cb, ce, &major)))
major = simple_strtol(context, &ptr, 10); return r;
if (ptr == context)
return 0;
context = ptr; if ((r = get_number(&cb, ce, &minor)))
minor = simple_strtol(context, &ptr, 10); return r;
if (ptr == context)
return 0;
context = ptr; if ((r = get_number(&cb, ce, &start)))
start = simple_strtoul(context, &ptr, 10); return r;
if (ptr == context)
return 0;
if (!(lc = kmalloc(sizeof(lc), GFP_KERNEL))) { if (!(lc = kmalloc(sizeof(lc), GFP_KERNEL))) {
WARN("couldn't allocate memory for linear context\n"); WARN("couldn't allocate memory for linear context\n");
return 0; return -EINVAL;
} }
lc->dev = MKDEV(major, minor); lc->dev = MKDEV((int) major, (int) minor);
lc->offset = start - b; lc->offset = (int) start - (int) low;
if (!dm_add_device(md, lc->dev)) { if (!dm_add_device(md, lc->dev)) {
kfree(lc); kfree(lc);
@ -148,15 +159,15 @@ int _linear_ctr(offset_t b, offset_t e, struct mapped_device *md,
} }
*result = lc; *result = lc;
return 1; return 0;
} }
void _linear_dtr(void *c) void linear_dtr(void *c)
{ {
kfree(c); kfree(c);
} }
int _linear_map(struct buffer_head *bh, void *context) int linear_map(struct buffer_head *bh, void *context)
{ {
struct linear_c *lc = (struct linear_c *) context; struct linear_c *lc = (struct linear_c *) context;
@ -173,8 +184,8 @@ int dm_std_targets(void)
if ((ret = register_map_target(n, \ if ((ret = register_map_target(n, \
fn ## _ctr, fn ## _dtr, fn ## _map) < 0)) return ret fn ## _ctr, fn ## _dtr, fn ## _map) < 0)) return ret
xx("io-err", _io_err); xx("io-err", io_err);
xx("linear", _linear); xx("linear", linear);
#undef xx #undef xx
return 0; return 0;

View File

@ -36,8 +36,10 @@
/* defines for blk.h */ /* defines for blk.h */
#define MAJOR_NR DM_BLK_MAJOR #define MAJOR_NR DM_BLK_MAJOR
#define DEVICE_OFF(device) #define DEVICE_NR(device) MINOR(device) /* has no partition bits */
#define LOCAL_END_REQUEST #define DEVICE_NAME "device-mapper" /* name for messaging */
#define DEVICE_NO_RANDOM /* no entropy to contribute */
#define DEVICE_OFF(d) /* do-nothing */
#include <linux/blk.h> #include <linux/blk.h>
@ -117,7 +119,7 @@
#define DEFAULT_READ_AHEAD 64 #define DEFAULT_READ_AHEAD 64
const char *_name = "device-mapper"; const char *_name = "device-mapper";
int _version[3] = {1, 0, 0}; int _version[3] = {0, 1, 0};
#define rl down_read(&_dev_lock) #define rl down_read(&_dev_lock)
#define ru up_read(&_dev_lock) #define ru up_read(&_dev_lock)
@ -132,23 +134,23 @@ static int _block_size[MAX_DEVICES];
static int _blksize_size[MAX_DEVICES]; static int _blksize_size[MAX_DEVICES];
static int _hardsect_size[MAX_DEVICES]; static int _hardsect_size[MAX_DEVICES];
static int _blk_open(struct inode *inode, struct file *file); static int blk_open(struct inode *inode, struct file *file);
static int _blk_close(struct inode *inode, struct file *file); static int blk_close(struct inode *inode, struct file *file);
static int _blk_ioctl(struct inode *inode, struct file *file, static int blk_ioctl(struct inode *inode, struct file *file,
uint command, ulong a); uint command, ulong a);
struct block_device_operations dm_blk_dops = { struct block_device_operations dm_blk_dops = {
open: _blk_open, open: blk_open,
release: _blk_close, release: blk_close,
ioctl: _blk_ioctl ioctl: blk_ioctl
}; };
static int _request_fn(request_queue_t *q, int rw, struct buffer_head *bh); static int request(request_queue_t *q, int rw, struct buffer_head *bh);
/* /*
* setup and teardown the driver * setup and teardown the driver
*/ */
static int _init(void) static int init(void)
{ {
int ret; int ret;
@ -171,14 +173,14 @@ static int _init(void)
return -EIO; return -EIO;
} }
blk_queue_make_request(BLK_DEFAULT_QUEUE(MAJOR_NR), _request_fn); blk_queue_make_request(BLK_DEFAULT_QUEUE(MAJOR_NR), request);
printk(KERN_INFO "%s(%d, %d, %d) successfully initialised\n", _name, printk(KERN_INFO "%s %d.%d.%d initialised\n", _name,
_version[0], _version[1], _version[2]); _version[0], _version[1], _version[2]);
return 0; return 0;
} }
static void _fin(void) static void fin(void)
{ {
dm_fin_fs(); dm_fin_fs();
@ -190,14 +192,14 @@ static void _fin(void)
blksize_size[MAJOR_NR] = 0; blksize_size[MAJOR_NR] = 0;
hardsect_size[MAJOR_NR] = 0; hardsect_size[MAJOR_NR] = 0;
printk(KERN_INFO "%s(%d, %d, %d) successfully finalised\n", _name, printk(KERN_INFO "%s %d.%d.%d finalised\n", _name,
_version[0], _version[1], _version[2]); _version[0], _version[1], _version[2]);
} }
/* /*
* block device functions * block device functions
*/ */
static int _blk_open(struct inode *inode, struct file *file) static int blk_open(struct inode *inode, struct file *file)
{ {
int minor = MINOR(inode->i_rdev); int minor = MINOR(inode->i_rdev);
struct mapped_device *md; struct mapped_device *md;
@ -220,7 +222,7 @@ static int _blk_open(struct inode *inode, struct file *file)
return 0; return 0;
} }
static int _blk_close(struct inode *inode, struct file *file) static int blk_close(struct inode *inode, struct file *file)
{ {
int minor = MINOR(inode->i_rdev); int minor = MINOR(inode->i_rdev);
struct mapped_device *md; struct mapped_device *md;
@ -243,7 +245,7 @@ static int _blk_close(struct inode *inode, struct file *file)
return 0; return 0;
} }
static int _blk_ioctl(struct inode *inode, struct file *file, static int blk_ioctl(struct inode *inode, struct file *file,
uint command, ulong a) uint command, ulong a)
{ {
/* FIXME: check in the latest Rubini that all expected ioctl's /* FIXME: check in the latest Rubini that all expected ioctl's
@ -290,7 +292,7 @@ static int _blk_ioctl(struct inode *inode, struct file *file,
return 0; return 0;
} }
static int _request_fn(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; struct mapped_device *md;
offset_t *node; offset_t *node;
@ -358,7 +360,7 @@ static inline int __any_old_dev(void)
return -1; return -1;
} }
static struct mapped_device *_alloc_dev(int minor) static struct mapped_device *alloc_dev(int minor)
{ {
struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL); struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL);
memset(md, 0, sizeof(*md)); memset(md, 0, sizeof(*md));
@ -393,7 +395,7 @@ static inline struct mapped_device *__find_name(const char *name)
return 0; return 0;
} }
static int _open_dev(struct dev_list *d) static int open_dev(struct dev_list *d)
{ {
int err; int err;
@ -408,13 +410,27 @@ static int _open_dev(struct dev_list *d)
return 0; return 0;
} }
static void _close_dev(struct dev_list *d) static void close_dev(struct dev_list *d)
{ {
blkdev_put(d->bd, BDEV_FILE); blkdev_put(d->bd, BDEV_FILE);
bdput(d->bd); bdput(d->bd);
d->bd = 0; d->bd = 0;
} }
static int __find_hardsect_size(struct mapped_device *md)
{
int r = INT_MAX, s;
struct dev_list *dl;
for (dl = md->devices; dl; dl = dl->next) {
s = get_hardsect_size(dl->dev);
if (s < r)
r = s;
}
return r;
}
struct mapped_device *dm_find_name(const char *name) struct mapped_device *dm_find_name(const char *name)
{ {
struct mapped_device *md; struct mapped_device *md;
@ -445,7 +461,7 @@ int dm_create(const char *name, int minor)
if (minor >= MAX_DEVICES) if (minor >= MAX_DEVICES)
return -ENXIO; return -ENXIO;
if (!(md = _alloc_dev(minor))) if (!(md = alloc_dev(minor)))
return -ENOMEM; return -ENOMEM;
wl; wl;
@ -485,7 +501,7 @@ int dm_remove(const char *name)
return r; return r;
} }
//dm_free_table(md); dm_free_table(md);
for (d = md->devices; d; d = n) { for (d = md->devices; d; d = n) {
n = d->next; n = d->next;
kfree(d); kfree(d);
@ -504,29 +520,48 @@ int dm_add_device(struct mapped_device *md, kdev_t dev)
struct dev_list *d = kmalloc(sizeof(*d), GFP_KERNEL); struct dev_list *d = kmalloc(sizeof(*d), GFP_KERNEL);
if (!d) if (!d)
return 0; return -EINVAL;
d->dev = dev; d->dev = dev;
d->next = md->devices; d->next = md->devices;
md->devices = d; md->devices = d;
return 1; return 0;
} }
int dm_activate(struct mapped_device *md) int dm_activate(struct mapped_device *md)
{ {
int ret; int ret, minor;
struct dev_list *d, *od; struct dev_list *d, *od;
if (is_active(md)) wl;
return 1;
if (is_active(md)) {
wu;
return 0;
}
if (!md->num_targets) {
wu;
return -ENXIO;
}
rl;
/* open all the devices */ /* open all the devices */
for (d = md->devices; d; d = d->next) for (d = md->devices; d; d = d->next)
if ((ret = _open_dev(d))) if ((ret = open_dev(d)))
goto bad; goto bad;
ru;
minor = MINOR(md->dev);
_block_size[minor] = md->highs[md->num_targets - 1] + 1;
_blksize_size[minor] = BLOCK_SIZE; /* FIXME: this depends on
the mapping table */
_hardsect_size[minor] = __find_hardsect_size(md);
register_disk(NULL, md->dev, 1, &dm_blk_dops, _block_size[minor]);
set_bit(DM_ACTIVE, &md->state);
wu;
return 0; return 0;
@ -534,7 +569,7 @@ int dm_activate(struct mapped_device *md)
od = d; od = d;
for (d = md->devices; d != od; d = d->next) for (d = md->devices; d != od; d = d->next)
_close_dev(d); close_dev(d);
ru; ru;
return ret; return ret;
@ -548,17 +583,17 @@ void dm_suspend(struct mapped_device *md)
/* close all the devices */ /* close all the devices */
for (d = md->devices; d; d = d->next) for (d = md->devices; d; d = d->next)
_close_dev(d); close_dev(d);
set_active(md, 0); clear_bit(DM_ACTIVE, &md->state);
} }
/* /*
* module hooks * module hooks
*/ */
module_init(_init); module_init(init);
module_exit(_fin); module_exit(fin);
/* /*
* Local variables: * Local variables:

View File

@ -40,6 +40,7 @@
#include <linux/compatmac.h> #include <linux/compatmac.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/devfs_fs_kernel.h> #include <linux/devfs_fs_kernel.h>
#include <linux/ctype.h>
#include <linux/device-mapper.h> #include <linux/device-mapper.h>
#define MAX_DEPTH 16 #define MAX_DEPTH 16
@ -134,12 +135,12 @@ static inline int is_active(struct mapped_device *md)
return test_bit(DM_ACTIVE, &md->state); return test_bit(DM_ACTIVE, &md->state);
} }
static inline void set_active(struct mapped_device *md, int set) static inline const char *eat_space(const char *b, const char *e)
{ {
if (set) while(b != e && isspace((int) *b))
set_bit(DM_ACTIVE, &md->state); b++;
else
clear_bit(DM_ACTIVE,& md->state); return b;
} }
#endif #endif