Commit fbe0aa1f authored by Tony Luck's avatar Tony Luck Committed by Al Viro

Some fixes for pstore

1) Change from ->get_sb() to ->mount()
2) Use mount_single() instead of mount_nodev()
3) Pulled in ramfs_get_inode() & trimmed to what I need for pstore
4) Drop the ugly pstore_writefile() Just save data using kmalloc() and
   provide a pstore_file_read() that uses simple_read_from_buffer().
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 474a00ee
...@@ -40,9 +40,29 @@ ...@@ -40,9 +40,29 @@
struct pstore_private { struct pstore_private {
u64 id; u64 id;
int (*erase)(u64); int (*erase)(u64);
ssize_t size;
char data[];
}; };
#define pstore_get_inode ramfs_get_inode static int pstore_file_open(struct inode *inode, struct file *file)
{
file->private_data = inode->i_private;
return 0;
}
static ssize_t pstore_file_read(struct file *file, char __user *userbuf,
size_t count, loff_t *ppos)
{
struct pstore_private *ps = file->private_data;
return simple_read_from_buffer(userbuf, count, ppos, ps->data, ps->size);
}
static const struct file_operations pstore_file_operations = {
.open = pstore_file_open,
.read = pstore_file_read,
.llseek = default_llseek,
};
/* /*
* When a file is unlinked from our file system we call the * When a file is unlinked from our file system we call the
...@@ -63,6 +83,30 @@ static const struct inode_operations pstore_dir_inode_operations = { ...@@ -63,6 +83,30 @@ static const struct inode_operations pstore_dir_inode_operations = {
.unlink = pstore_unlink, .unlink = pstore_unlink,
}; };
static struct inode *pstore_get_inode(struct super_block *sb,
const struct inode *dir, int mode, dev_t dev)
{
struct inode *inode = new_inode(sb);
if (inode) {
inode->i_ino = get_next_ino();
inode->i_uid = inode->i_gid = 0;
inode->i_mode = mode;
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
switch (mode & S_IFMT) {
case S_IFREG:
inode->i_fop = &pstore_file_operations;
break;
case S_IFDIR:
inode->i_op = &pstore_dir_inode_operations;
inode->i_fop = &simple_dir_operations;
inc_nlink(inode);
break;
}
}
return inode;
}
static const struct super_operations pstore_ops = { static const struct super_operations pstore_ops = {
.statfs = simple_statfs, .statfs = simple_statfs,
.drop_inode = generic_delete_inode, .drop_inode = generic_delete_inode,
...@@ -70,37 +114,10 @@ static const struct super_operations pstore_ops = { ...@@ -70,37 +114,10 @@ static const struct super_operations pstore_ops = {
}; };
static struct super_block *pstore_sb; static struct super_block *pstore_sb;
static struct vfsmount *pstore_mnt;
int pstore_is_mounted(void) int pstore_is_mounted(void)
{ {
return pstore_mnt != NULL; return pstore_sb != NULL;
}
/*
* Set up a file structure as if we had opened this file and
* write our data to it.
*/
static int pstore_writefile(struct inode *inode, struct dentry *dentry,
char *data, size_t size)
{
struct file f;
ssize_t n;
mm_segment_t old_fs = get_fs();
memset(&f, '0', sizeof f);
f.f_mapping = inode->i_mapping;
f.f_path.dentry = dentry;
f.f_path.mnt = pstore_mnt;
f.f_pos = 0;
f.f_op = inode->i_fop;
set_fs(KERNEL_DS);
n = do_sync_write(&f, data, size, &f.f_pos);
set_fs(old_fs);
fsnotify_modify(&f);
return n == size;
} }
/* /*
...@@ -123,8 +140,7 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, ...@@ -123,8 +140,7 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
inode = pstore_get_inode(pstore_sb, root->d_inode, S_IFREG | 0444, 0); inode = pstore_get_inode(pstore_sb, root->d_inode, S_IFREG | 0444, 0);
if (!inode) if (!inode)
goto fail; goto fail;
inode->i_uid = inode->i_gid = 0; private = kmalloc(sizeof *private + size, GFP_KERNEL);
private = kmalloc(sizeof *private, GFP_KERNEL);
if (!private) if (!private)
goto fail_alloc; goto fail_alloc;
private->id = id; private->id = id;
...@@ -152,28 +168,19 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, ...@@ -152,28 +168,19 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
if (IS_ERR(dentry)) if (IS_ERR(dentry))
goto fail_lockedalloc; goto fail_lockedalloc;
d_add(dentry, inode); memcpy(private->data, data, size);
inode->i_size = private->size = size;
mutex_unlock(&root->d_inode->i_mutex);
if (!pstore_writefile(inode, dentry, data, size))
goto fail_write;
inode->i_private = private; inode->i_private = private;
if (time.tv_sec) if (time.tv_sec)
inode->i_mtime = inode->i_ctime = time; inode->i_mtime = inode->i_ctime = time;
return 0; d_add(dentry, inode);
fail_write:
kfree(private);
inode->i_nlink--;
mutex_lock(&root->d_inode->i_mutex);
d_delete(dentry);
dput(dentry);
mutex_unlock(&root->d_inode->i_mutex); mutex_unlock(&root->d_inode->i_mutex);
goto fail;
return 0;
fail_lockedalloc: fail_lockedalloc:
mutex_unlock(&root->d_inode->i_mutex); mutex_unlock(&root->d_inode->i_mutex);
...@@ -225,32 +232,21 @@ int pstore_fill_super(struct super_block *sb, void *data, int silent) ...@@ -225,32 +232,21 @@ int pstore_fill_super(struct super_block *sb, void *data, int silent)
return err; return err;
} }
static int pstore_get_sb(struct file_system_type *fs_type, static struct dentry *pstore_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt) int flags, const char *dev_name, void *data)
{ {
struct dentry *root; return mount_single(fs_type, flags, data, pstore_fill_super);
root = mount_nodev(fs_type, flags, data, pstore_fill_super);
if (IS_ERR(root))
return -ENOMEM;
mnt->mnt_root = root;
mnt->mnt_sb = root->d_sb;
pstore_mnt = mnt;
return 0;
} }
static void pstore_kill_sb(struct super_block *sb) static void pstore_kill_sb(struct super_block *sb)
{ {
kill_litter_super(sb); kill_litter_super(sb);
pstore_sb = NULL; pstore_sb = NULL;
pstore_mnt = NULL;
} }
static struct file_system_type pstore_fs_type = { static struct file_system_type pstore_fs_type = {
.name = "pstore", .name = "pstore",
.get_sb = pstore_get_sb, .mount = pstore_mount,
.kill_sb = pstore_kill_sb, .kill_sb = pstore_kill_sb,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment