mirror of
git://sourceware.org/git/lvm2.git
synced 2025-04-01 18:50:41 +03:00
o Further tidyups and fixes.
This commit is contained in:
parent
57613d7345
commit
03505a0f58
@ -33,7 +33,7 @@ struct dmfs_error {
|
||||
|
||||
void dmfs_add_error(struct dm_table *t, unsigned num, char *str)
|
||||
{
|
||||
int len = strlen(str) + sizeof(dmfs_error) + 12;
|
||||
int len = strlen(str) + sizeof(struct dmfs_error) + 12;
|
||||
struct dmfs_error *e = kmalloc(len, GFP_KERNEL);
|
||||
if (e) {
|
||||
e->msg = (char *)(e + 1);
|
||||
@ -52,7 +52,7 @@ void dmfs_zap_errors(struct dm_table *t)
|
||||
}
|
||||
}
|
||||
|
||||
static struct dmfs_error find_initial_message(struct dn_table *t, loff_t *pos)
|
||||
static struct dmfs_error *find_initial_message(struct dm_table *t, loff_t *pos)
|
||||
{
|
||||
struct dmfs_error *e;
|
||||
struct list_head *tmp, *head;
|
||||
@ -105,7 +105,7 @@ static ssize_t dmfs_error_read(struct file *file, char *buf, size_t size, loff_t
|
||||
int copied = 0;
|
||||
loff_t offset = *pos;
|
||||
|
||||
if (!access_ok(VERIFY_WRITE, buf, count))
|
||||
if (!access_ok(VERIFY_WRITE, buf, size))
|
||||
return -EFAULT;
|
||||
|
||||
down(&dmi->sem);
|
||||
@ -126,15 +126,15 @@ static int dmfs_error_sync(struct file *file, struct dentry *dentry, int datasyn
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct dm_table_file_operations = {
|
||||
static struct file_operations dmfs_error_file_operations = {
|
||||
read: dmfs_error_read,
|
||||
fsync: dmfs_error_sync,
|
||||
};
|
||||
|
||||
static struct dmfs_error_inode_operations = {
|
||||
static struct inode_operations dmfs_error_inode_operations = {
|
||||
};
|
||||
|
||||
int dmfs_create_error(struct inode *dir, int mode)
|
||||
struct inode *dmfs_create_error(struct inode *dir, int mode)
|
||||
{
|
||||
struct inode *inode = new_inode(dir->i_sb);
|
||||
|
||||
|
@ -27,9 +27,10 @@
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
extern struct dmfs_address_space_operations;
|
||||
extern struct address_space_operations dmfs_address_space_operations;
|
||||
extern struct inode *dmfs_create_tdir(struct inode *dir, int mode);
|
||||
|
||||
struct dentry *dmfs_verify_name(struct inode *dir, char *name)
|
||||
struct dentry *dmfs_verify_name(struct inode *dir, const char *name)
|
||||
{
|
||||
struct nameidata nd;
|
||||
int err = -ENOENT;
|
||||
@ -37,22 +38,22 @@ struct dentry *dmfs_verify_name(struct inode *dir, char *name)
|
||||
if (path_init(name, LOOKUP_FOLLOW, &nd))
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
err = path_walk(path, &nd);
|
||||
err = path_walk(name, &nd);
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
err = -EINVAL;
|
||||
if (nd.mnt->mnt->sb != dir->i_sb)
|
||||
if (nd.mnt->mnt_sb != dir->i_sb)
|
||||
goto err_out;
|
||||
|
||||
if (nd.dentry->d_parent != dir)
|
||||
if (nd.dentry->d_parent->d_inode != dir)
|
||||
goto err_out;
|
||||
|
||||
dget(nd.dentry);
|
||||
path_release(nd);
|
||||
path_release(&nd);
|
||||
return nd.dentry;
|
||||
err_out:
|
||||
path_release(nd);
|
||||
path_release(&nd);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
@ -68,7 +69,7 @@ struct inode *dmfs_create_symlink(struct inode *dir, int mode)
|
||||
inode->i_blocks = 0;
|
||||
inode->i_rdev = NODEV;
|
||||
inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME;
|
||||
inode->i_aop = &dmfs_address_space_operations;
|
||||
inode->i_mapping->a_ops = &dmfs_address_space_operations;
|
||||
inode->i_op = &page_symlink_inode_operations;
|
||||
}
|
||||
|
||||
@ -82,7 +83,7 @@ static int dmfs_lv_unlink(struct inode *dir, struct dentry *dentry)
|
||||
if (!(inode->i_mode & S_IFLNK))
|
||||
return -EINVAL;
|
||||
|
||||
inode->n_link--;
|
||||
inode->i_nlink--;
|
||||
dput(dentry);
|
||||
return 0;
|
||||
}
|
||||
@ -95,7 +96,7 @@ static int dmfs_lv_symlink(struct inode *dir, struct dentry *dentry,
|
||||
int rv;
|
||||
int l;
|
||||
|
||||
if (dentry->d_name.len != 6 || memcmp(dentry->d_name, "ACTIVE", 6) != 0)
|
||||
if (dentry->d_name.len != 6 || memcmp(dentry->d_name.name, "ACTIVE", 6) != 0)
|
||||
return -EINVAL;
|
||||
|
||||
de = dmfs_verify_name(dir, symname);
|
||||
@ -133,20 +134,18 @@ static int is_identifier(const char *str, int len)
|
||||
|
||||
static int dmfs_lv_mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||
{
|
||||
struct super_block *sb = dir->i_sb;
|
||||
struct inode *inode;
|
||||
struct mapped_device *md;
|
||||
|
||||
if (dentry->d_name.len >= DM_NAME_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
if (!is_identifier(name, dentry->d_name.len))
|
||||
if (!is_identifier(dentry->d_name.name, dentry->d_name.len))
|
||||
return -EPERM;
|
||||
|
||||
if (dentry->d_name.len == 6 && memcmp(dentry->d_name.name, "ACTIVE", 6) == 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (dentry->d_name[0] == '.')
|
||||
if (dentry->d_name.name[0] == '.')
|
||||
return -EINVAL;
|
||||
|
||||
inode = dmfs_create_tdir(dir, mode);
|
||||
@ -163,7 +162,7 @@ static int dmfs_lv_mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||
* represents a table. If it is NULL then the inode is a virtual
|
||||
* file and should be deleted along with the directory.
|
||||
*/
|
||||
static inline positive(struct dentry *dentry)
|
||||
static inline int positive(struct dentry *dentry)
|
||||
{
|
||||
return dentry->d_inode && !d_unhashed(dentry);
|
||||
}
|
||||
@ -214,13 +213,13 @@ static int dmfs_lv_sync(struct file *file, struct dentry *dentry, int datasync)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct dm_root_file_operations = {
|
||||
static struct file_operations dmfs_lv_file_operations = {
|
||||
read: generic_read_dir,
|
||||
readdir: dcache_readdir,
|
||||
fsync: dmfs_lv_sync,
|
||||
};
|
||||
|
||||
static struct dm_root_inode_operations = {
|
||||
static struct inode_operations dmfs_lv_inode_operations = {
|
||||
lookup: dmfs_lv_lookup,
|
||||
unlink: dmfs_lv_unlink,
|
||||
symlink: dmfs_lv_symlink,
|
||||
@ -232,11 +231,11 @@ struct inode *dmfs_create_lv(struct super_block *sb, int mode, struct dentry *de
|
||||
{
|
||||
struct inode *inode = dmfs_new_inode(sb, mode | S_IFDIR);
|
||||
struct mapped_device *md;
|
||||
char *name = dentry->d_name.name;
|
||||
const char *name = dentry->d_name.name;
|
||||
|
||||
if (inode) {
|
||||
inode->i_fop = &dmfs_lv_file_operations;
|
||||
inode->i_op = &dmfs_lv_dir_operations;
|
||||
inode->i_op = &dmfs_lv_inode_operations;
|
||||
md = dm_create(name, -1);
|
||||
if (md == NULL) {
|
||||
iput(inode);
|
||||
|
@ -27,6 +27,8 @@
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
extern struct inode *dmfs_create_lv(struct inode *dir, int mode, struct dentry *dentry);
|
||||
|
||||
static int is_identifier(const char *str, int len)
|
||||
{
|
||||
while(len--) {
|
||||
@ -39,17 +41,15 @@ static int is_identifier(const char *str, int len)
|
||||
|
||||
static int dmfs_root_mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||
{
|
||||
struct super_block *sb = dir->i_sb;
|
||||
struct inode *inode;
|
||||
struct mapped_device *md;
|
||||
|
||||
if (dentry->d_name.len >= DM_NAME_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
if (!is_identifier(name, dentry->d_name.len))
|
||||
if (!is_identifier(dentry->d_name.name, dentry->d_name.len))
|
||||
return -EPERM;
|
||||
|
||||
if (dentry->d_name[0] == '.')
|
||||
if (dentry->d_name.name[0] == '.')
|
||||
return -EINVAL;
|
||||
|
||||
inode = dmfs_create_lv(dir, mode, dentry);
|
||||
@ -66,7 +66,7 @@ static int dmfs_root_mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||
* represents a table. If it is NULL then the inode is a virtual
|
||||
* file and should be deleted along with the directory.
|
||||
*/
|
||||
static inline positive(struct dentry *dentry)
|
||||
static inline int positive(struct dentry *dentry)
|
||||
{
|
||||
return dentry->d_inode && !d_unhashed(dentry);
|
||||
}
|
||||
@ -127,13 +127,13 @@ static int dmfs_root_sync(struct file *file, struct dentry *dentry, int datasync
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct dm_root_file_operations = {
|
||||
static struct file_operations dmfs_root_file_operations = {
|
||||
read: generic_read_dir,
|
||||
readdir: dcache_readdir,
|
||||
fsync: dmfs_root_sync,
|
||||
};
|
||||
|
||||
static struct dm_root_inode_operations = {
|
||||
static struct inode_operations dmfs_root_inode_operations = {
|
||||
lookup: dmfs_root_lookup,
|
||||
mkdir: dmfs_root_mkdir,
|
||||
rmdir: dmfs_root_rmdir,
|
||||
@ -153,7 +153,7 @@ struct inode *dmfs_create_root(struct super_block *sb, int mode)
|
||||
inode->i_rdev = NODEV;
|
||||
inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME;
|
||||
inode->i_fop = &dmfs_root_file_operations;
|
||||
inode->i_op = &dmfs_root_dir_operations;
|
||||
inode->i_op = &dmfs_root_inode_operations;
|
||||
}
|
||||
|
||||
return inode;
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <linux/config.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
static ssize_t dmfs_status_read(struct file *file, char *buf, size_t size, loff_t *pos)
|
||||
{
|
||||
return 0;
|
||||
@ -32,15 +34,15 @@ static int dmfs_status_sync(struct file *file, struct dentry *dentry, int datasy
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct dm_table_file_operations = {
|
||||
static struct file_operations dmfs_status_file_operations = {
|
||||
read: dmfs_status_read,
|
||||
fsync: dmfs_status_sync,
|
||||
};
|
||||
|
||||
static struct dmfs_status_inode_operations = {
|
||||
static struct inode_operations dmfs_status_inode_operations = {
|
||||
};
|
||||
|
||||
int dmfs_create_status(struct inode *dir, int mode)
|
||||
struct inode *dmfs_create_status(struct inode *dir, int mode)
|
||||
{
|
||||
struct inode *inode = new_inode(dir->i_sb);
|
||||
|
||||
|
@ -46,7 +46,7 @@ static void dmfs_delete_inode(struct inode *inode)
|
||||
if (dmi->md)
|
||||
dm_remove(dmi->md);
|
||||
if (dmi->table)
|
||||
dm_put_table(dmi->table):
|
||||
dm_put_table(dmi->table);
|
||||
if (dmi->dentry)
|
||||
dm_unlock_tdir(dmi->dentry);
|
||||
kfree(dmi);
|
||||
@ -70,7 +70,7 @@ struct super_block *dmfs_read_super(struct super_block *sb, void *data, int sile
|
||||
sb->s_blocksize = PAGE_CACHE_SIZE;
|
||||
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
|
||||
sb->s_magic = DMFS_MAGIC;
|
||||
sb->s_ops = &dmfs_super_operations;
|
||||
sb->s_op = &dmfs_super_operations;
|
||||
sb->s_maxbytes = MAX_NON_LFS;
|
||||
|
||||
inode = dmfs_create_root(sb, 0755);
|
||||
@ -107,7 +107,7 @@ struct inode *dmfs_new_inode(struct super_block *sb, int mode)
|
||||
}
|
||||
memset(dmi, sizeof(struct dmfs_i), 0);
|
||||
init_MUTEX(&dmi->sem);
|
||||
inode->generic_ip = dmi;
|
||||
inode->u.generic_ip = dmi;
|
||||
}
|
||||
return inode;
|
||||
}
|
||||
|
@ -24,18 +24,6 @@
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
static inline char *next_token(char **p)
|
||||
{
|
||||
static const char *delim = " \t";
|
||||
char *r;
|
||||
|
||||
do {
|
||||
r = strsep(p, delim);
|
||||
} while(r && *r == 0);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static offset_t start_of_next_range(struct dm_table *t)
|
||||
{
|
||||
offset_t n = 0;
|
||||
@ -45,7 +33,7 @@ static offset_t start_of_next_range(struct dm_table *t)
|
||||
return n;
|
||||
}
|
||||
|
||||
static void dmfs_parse_line(struct dmfs_table *t, unsigned num, char *str)
|
||||
static void dmfs_parse_line(struct dm_table *t, unsigned num, char *str)
|
||||
{
|
||||
char *p = str;
|
||||
const char *tok;
|
||||
@ -82,7 +70,7 @@ static void dmfs_parse_line(struct dmfs_table *t, unsigned num, char *str)
|
||||
msg = "This message should never appear (constructor error)";
|
||||
rv = ttype->ctr(t, start, size, p, &context);
|
||||
msg = context;
|
||||
if (rv == 0)) {
|
||||
if (rv == 0) {
|
||||
printk(KERN_DEBUG "%ul %ul %s %s", start, size,
|
||||
ttype->name,
|
||||
ttype->print(context));
|
||||
@ -150,7 +138,6 @@ static struct dm_table *dmfs_parse(struct inode *inode)
|
||||
{
|
||||
struct address_space *mapping = inode->i_mapping;
|
||||
unsigned long index = 0;
|
||||
unsigned long offset = 0;
|
||||
unsigned long end_index, end_offset;
|
||||
unsigned long page;
|
||||
unsigned long rem = 0;
|
||||
@ -193,7 +180,7 @@ static struct dm_table *dmfs_parse(struct inode *inode)
|
||||
goto broken;
|
||||
|
||||
kaddr = kmap(pg);
|
||||
rv = dmfs_parse_page(t, kaddr, end, (char *)page, &rem);
|
||||
rv = dmfs_parse_page(t, kaddr, end, (char *)page, &rem, &num);
|
||||
kunmap(pg);
|
||||
|
||||
if (rv)
|
||||
@ -224,23 +211,27 @@ parse_error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int dmfs_release(struct inode *inode, struct file *f)
|
||||
static int dmfs_table_release(struct inode *inode, struct file *f)
|
||||
{
|
||||
struct dmfs_i *dmi = inode->u.generic_ip;
|
||||
struct dentry *dentry = f->f_dentry;
|
||||
struct inode *parent = dentry->d_parent->d_inode;
|
||||
struct dmfs_i *dmi = DMFS_I(parent);
|
||||
struct dm_table *table;
|
||||
|
||||
if (!(f->f_mode & S_IWUGO))
|
||||
return 0;
|
||||
if (f->f_mode & FMODE_WRITE) {
|
||||
|
||||
down(&dmi->sem);
|
||||
table = dmfs_parse(inode);
|
||||
down(&dmi->sem);
|
||||
table = dmfs_parse(inode);
|
||||
|
||||
if (table) {
|
||||
if (dmi->table)
|
||||
dm_put_table(dmi->table);
|
||||
dmi->table = table;
|
||||
if (table) {
|
||||
if (dmi->table)
|
||||
dm_put_table(dmi->table);
|
||||
dmi->table = table;
|
||||
}
|
||||
up(&dmi->sem);
|
||||
|
||||
put_write_access(parent);
|
||||
}
|
||||
up(&dmi->sem);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -310,49 +301,38 @@ static int get_exclusive_write_access(struct inode *inode)
|
||||
static int dmfs_table_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct dentry *dentry = file->f_dentry;
|
||||
struct inode *inode = dentry->d_parent->d_inode;
|
||||
struct inode *parent = dentry->d_parent->d_inode;
|
||||
|
||||
if (file->f_mode & FMODE_WRITE) {
|
||||
if (get_exclusive_write_access(inode))
|
||||
if (get_exclusive_write_access(parent))
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_table_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
if (file->f_mode & FMODE_WRITE) {
|
||||
struct dentry *dentry = file->f_dentry;
|
||||
struct inode *inode = dentry->d_parent->d_inode;
|
||||
|
||||
put_write_access(inode);
|
||||
}
|
||||
}
|
||||
|
||||
static int dmfs_table_sync(struct file *file, struct dentry *dentry, int datasync)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct dmfs_address_space_operations = {
|
||||
struct address_space_operations dmfs_address_space_operations = {
|
||||
readpage: dmfs_readpage,
|
||||
writepage: dmfs_writepage,
|
||||
prepare_write: dmfs_prepare_write,
|
||||
commit_write: dmfs_commit_write,
|
||||
};
|
||||
|
||||
static struct dmfs_table_file_operations = {
|
||||
static struct file_operations dmfs_table_file_operations = {
|
||||
llseek: generic_file_llseek,
|
||||
read: generic_file_read,
|
||||
write: generic_file_write, /* FIXME: Needs to hold dmi->sem */
|
||||
open: dmfs_table_open,
|
||||
release: dmfs_table_release,
|
||||
fsync: dmfs_table_sync,
|
||||
release: dmfs_release,
|
||||
};
|
||||
|
||||
static struct dmfs_table_inode_operations = {
|
||||
static struct inode_operations dmfs_table_inode_operations = {
|
||||
};
|
||||
|
||||
int dmfs_create_table(struct inode *dir, int mode)
|
||||
|
@ -58,7 +58,7 @@ static int dmfs_tdir_unlink(struct inode *dir, struct dentry *dentry)
|
||||
static struct dentry *dmfs_tdir_lookup(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
struct inode *inode = NULL;
|
||||
char *name = dentry->d_name.name;
|
||||
const char *name = dentry->d_name.name;
|
||||
|
||||
switch(dentry->d_name.len) {
|
||||
case 5:
|
||||
@ -82,16 +82,16 @@ static int dmfs_tdir_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
||||
int i;
|
||||
struct dentry *dentry = filp->f_dentry;
|
||||
|
||||
i = flip->f_pos;
|
||||
i = filp->f_pos;
|
||||
switch(i) {
|
||||
case 0:
|
||||
if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
|
||||
break;
|
||||
i++;
|
||||
flip->f_pos++;
|
||||
filp->f_pos++;
|
||||
/* fallthrough */
|
||||
case 1:
|
||||
if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0
|
||||
if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
|
||||
break;
|
||||
i++;
|
||||
filp->f_pos++;
|
||||
@ -123,24 +123,24 @@ static int dmfs_tdir_sync(struct file *file, struct dentry *dentry, int datasync
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct dmfs_tdir_file_operations = {
|
||||
static struct file_operations dmfs_tdir_file_operations = {
|
||||
read: generic_read_dir,
|
||||
readdir: dmfs_tdir_readdir,
|
||||
fsync: dmfs_tdir_sync,
|
||||
};
|
||||
|
||||
static struct dmfs_tdir_inode_operations = {
|
||||
static struct inode_operations dmfs_tdir_inode_operations = {
|
||||
lookup: dmfs_tdir_lookup,
|
||||
unlink: dmfs_tdir_unlink,
|
||||
};
|
||||
|
||||
struct inode *dmfs_create_tdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||
{
|
||||
struct inode *inode = dmfs_new_inode(sb, mode | S_IFDIR);
|
||||
struct inode *inode = dmfs_new_inode(dir->i_sb, mode | S_IFDIR);
|
||||
|
||||
if (inode) {
|
||||
inode->i_fop = &dmfs_tdir_file_operations;
|
||||
inode->i_op = &dmfs_tdir_dir_operations;
|
||||
inode->i_op = &dmfs_tdir_inode_operations;
|
||||
}
|
||||
|
||||
return inode;
|
||||
|
Loading…
x
Reference in New Issue
Block a user