diff options
Diffstat (limited to 'fs/pstore/inode.c')
-rw-r--r-- | fs/pstore/inode.c | 192 |
1 files changed, 109 insertions, 83 deletions
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 549d245d0b42..977ed2723845 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -27,6 +27,7 @@ #include <linux/string.h> #include <linux/mount.h> #include <linux/ramfs.h> +#include <linux/parser.h> #include <linux/sched.h> #include <linux/magic.h> #include <linux/pstore.h> @@ -40,9 +41,29 @@ struct pstore_private { u64 id; 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 @@ -53,54 +74,99 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry) struct pstore_private *p = dentry->d_inode->i_private; p->erase(p->id); - kfree(p); return simple_unlink(dir, dentry); } +static void pstore_evict_inode(struct inode *inode) +{ + end_writeback(inode); + kfree(inode->i_private); +} + static const struct inode_operations pstore_dir_inode_operations = { .lookup = simple_lookup, .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; +} + +enum { + Opt_kmsg_bytes, Opt_err +}; + +static const match_table_t tokens = { + {Opt_kmsg_bytes, "kmsg_bytes=%u"}, + {Opt_err, NULL} +}; + +static void parse_options(char *options) +{ + char *p; + substring_t args[MAX_OPT_ARGS]; + int option; + + if (!options) + return; + + while ((p = strsep(&options, ",")) != NULL) { + int token; + + if (!*p) + continue; + + token = match_token(p, tokens, args); + switch (token) { + case Opt_kmsg_bytes: + if (!match_int(&args[0], &option)) + pstore_set_kmsg_bytes(option); + break; + } + } +} + +static int pstore_remount(struct super_block *sb, int *flags, char *data) +{ + parse_options(data); + + return 0; +} + static const struct super_operations pstore_ops = { .statfs = simple_statfs, .drop_inode = generic_delete_inode, + .evict_inode = pstore_evict_inode, + .remount_fs = pstore_remount, .show_options = generic_show_options, }; static struct super_block *pstore_sb; -static struct vfsmount *pstore_mnt; int pstore_is_mounted(void) { - return pstore_mnt != 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; + return pstore_sb != NULL; } /* @@ -123,8 +189,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); if (!inode) goto fail; - inode->i_uid = inode->i_gid = 0; - private = kmalloc(sizeof *private, GFP_KERNEL); + private = kmalloc(sizeof *private + size, GFP_KERNEL); if (!private) goto fail_alloc; private->id = id; @@ -152,28 +217,19 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, if (IS_ERR(dentry)) goto fail_lockedalloc; - d_add(dentry, inode); - - mutex_unlock(&root->d_inode->i_mutex); - - if (!pstore_writefile(inode, dentry, data, size)) - goto fail_write; + memcpy(private->data, data, size); + inode->i_size = private->size = size; inode->i_private = private; if (time.tv_sec) 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); - goto fail; + + return 0; fail_lockedalloc: mutex_unlock(&root->d_inode->i_mutex); @@ -202,6 +258,8 @@ int pstore_fill_super(struct super_block *sb, void *data, int silent) sb->s_op = &pstore_ops; sb->s_time_gran = 1; + parse_options(data); + inode = pstore_get_inode(sb, NULL, S_IFDIR | 0755, 0); if (!inode) { err = -ENOMEM; @@ -225,59 +283,27 @@ fail: return err; } -static int pstore_get_sb(struct file_system_type *fs_type, - int flags, const char *dev_name, void *data, struct vfsmount *mnt) +static struct dentry *pstore_mount(struct file_system_type *fs_type, + int flags, const char *dev_name, void *data) { - struct dentry *root; - - 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; + return mount_single(fs_type, flags, data, pstore_fill_super); } static void pstore_kill_sb(struct super_block *sb) { kill_litter_super(sb); pstore_sb = NULL; - pstore_mnt = NULL; } static struct file_system_type pstore_fs_type = { .name = "pstore", - .get_sb = pstore_get_sb, + .mount = pstore_mount, .kill_sb = pstore_kill_sb, }; static int __init init_pstore_fs(void) { - int rc = 0; - struct kobject *pstorefs_kobj; - - pstorefs_kobj = kobject_create_and_add("pstore", fs_kobj); - if (!pstorefs_kobj) { - rc = -ENOMEM; - goto done; - } - - rc = sysfs_create_file(pstorefs_kobj, &pstore_kmsg_bytes_attr.attr); - if (rc) - goto done1; - - rc = register_filesystem(&pstore_fs_type); - if (rc == 0) - goto done; - - sysfs_remove_file(pstorefs_kobj, &pstore_kmsg_bytes_attr.attr); -done1: - kobject_put(pstorefs_kobj); -done: - return rc; + return register_filesystem(&pstore_fs_type); } module_init(init_pstore_fs) |