1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-24 14:50:34 +03:00

o added global dm_table_lookup_device(path)

o changed linear target to : <device_path> <start>
This commit is contained in:
Joe Thornber 2001-08-31 18:26:27 +00:00
parent bc68ed8b1d
commit d004f28074
5 changed files with 71 additions and 33 deletions

View File

@ -53,6 +53,7 @@ int dm_register_target(const char *name, dm_ctr_fn ctr, dm_dtr_fn dtr,
* destination devices are handled correctly
* (ie. opened/closed).
*/
int dm_table_lookup_device(const char *path, kdev_t *d);
int dm_table_add_device(struct dm_table *t, kdev_t dev);
void dm_table_remove_device(struct dm_table *t, kdev_t dev);

View File

@ -55,11 +55,7 @@ static int process_table(const char *b, const char *e, int minor,
struct dm_table **map);
static int line_splitter(struct file *file, const char *buffer,
unsigned long count, void *data);
static int get_word(const char *b, const char *e,
const char **wb, const char **we);
static int tok_cmp(const char *str, const char *b, const char *e);
static void tok_cpy(char *dest, size_t max,
const char *b, const char *e);
typedef int (*process_fn)(const char *b, const char *e, int minor,
struct dm_table **map);
@ -289,21 +285,6 @@ static int process_table(const char *b, const char *e, int minor,
return 0;
}
static int get_word(const char *b, const char *e,
const char **wb, const char **we)
{
b = eat_space(b, e);
if (b == e)
return -EINVAL;
*wb = b;
while(b != e && !isspace((int) *b))
b++;
*we = b;
return 0;
}
static int line_splitter(struct file *file, const char *buffer,
unsigned long count, void *data)
{
@ -348,12 +329,3 @@ static int tok_cmp(const char *str, const char *b, const char *e)
return -1;
}
static void tok_cpy(char *dest, size_t max,
const char *b, const char *e)
{
size_t len = e - b;
if (len > --max)
len = max;
strncpy(dest, b, len);
dest[len] = '\0';
}

View File

@ -206,6 +206,37 @@ int dm_table_add_entry(struct dm_table *t, offset_t high,
return 0;
}
/*
* convert a device path to a kdev_t. I've not
* looked at vfs stuff before so could someone
* more knowledgeable please check this.
*/
int dm_table_lookup_device(const char *path, kdev_t *d)
{
int r;
struct nameidata nd;
struct inode *inode;
if (!path_init(path, LOOKUP_FOLLOW, &nd))
return 0;
if ((r = path_walk(path, &nd)))
goto bad;
inode = nd.dentry->d_inode;
if (!S_ISBLK(inode->i_mode)) {
r = -EINVAL;
goto bad;
}
*d = inode->i_bdev->bd_dev;
bad:
path_release(&nd);
return r;
}
/*
* see if we've already got a device in the list.
*/

View File

@ -115,20 +115,25 @@ struct linear_c {
/*
* construct a linear mapping.
* <major> <minor> <offset>
* <dev_path> <offset>
*/
static int linear_ctr(struct dm_table *t,
offset_t low, offset_t high,
const char *cb, const char *ce, void **result)
{
struct linear_c *lc;
unsigned int major, minor, start;
unsigned int start;
kdev_t dev;
int r;
char path[256];
const char *wb, *we;
if ((r = get_number(&cb, ce, &major)))
if ((r = get_word(cb, ce, &wb, &we)))
return r;
cb = we;
if ((r = get_number(&cb, ce, &minor)))
tok_cpy(path, sizeof(path) - 1, wb, we);
if ((r = dm_table_lookup_device(path, &dev)))
return r;
if ((r = get_number(&cb, ce, &start)))
@ -139,7 +144,7 @@ static int linear_ctr(struct dm_table *t,
return -EINVAL;
}
lc->dev = MKDEV((int) major, (int) minor);
lc->dev = dev;
lc->offset = (int) start - (int) low;
if ((r = dm_table_add_device(t, lc->dev))) {

View File

@ -275,6 +275,10 @@ static inline const char *eat_space(const char *b, const char *e)
return b;
}
/*
* FIXME: these are too big to be inlines
*/
static inline int get_number(const char **b, const char *e, unsigned int *n)
{
char *ptr;
@ -290,4 +294,29 @@ static inline int get_number(const char **b, const char *e, unsigned int *n)
return 0;
}
static inline int get_word(const char *b, const char *e,
const char **wb, const char **we)
{
b = eat_space(b, e);
if (b == e)
return -EINVAL;
*wb = b;
while(b != e && !isspace((int) *b))
b++;
*we = b;
return 0;
}
static inline void tok_cpy(char *dest, size_t max,
const char *b, const char *e)
{
size_t len = e - b;
if (len > --max)
len = max;
strncpy(dest, b, len);
dest[len] = '\0';
}
#endif