logfs get_sb massage, part 1

move allocation of logfs_super to logfs_get_sb, pass it to
logfs_get_sb_...().

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2010-07-26 11:25:05 +04:00
parent d2d1ea9306
commit 71a1c0125f
4 changed files with 39 additions and 21 deletions

View File

@ -9,6 +9,7 @@
#include <linux/bio.h> #include <linux/bio.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/slab.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1)) #define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1))
@ -320,20 +321,23 @@ static const struct logfs_device_ops bd_devops = {
.put_device = bdev_put_device, .put_device = bdev_put_device,
}; };
int logfs_get_sb_bdev(struct file_system_type *type, int flags, int logfs_get_sb_bdev(struct logfs_super *p,
struct file_system_type *type, int flags,
const char *devname, struct vfsmount *mnt) const char *devname, struct vfsmount *mnt)
{ {
struct block_device *bdev; struct block_device *bdev;
bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, type); bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, type);
if (IS_ERR(bdev)) if (IS_ERR(bdev)) {
kfree(p);
return PTR_ERR(bdev); return PTR_ERR(bdev);
}
if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) { if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
int mtdnr = MINOR(bdev->bd_dev); int mtdnr = MINOR(bdev->bd_dev);
close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE); close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
return logfs_get_sb_mtd(type, flags, mtdnr, mnt); return logfs_get_sb_mtd(p, type, flags, mtdnr, mnt);
} }
return logfs_get_sb_device(type, flags, NULL, bdev, &bd_devops, mnt); return logfs_get_sb_device(p, type, flags, NULL, bdev, &bd_devops, mnt);
} }

View File

@ -265,14 +265,17 @@ static const struct logfs_device_ops mtd_devops = {
.put_device = mtd_put_device, .put_device = mtd_put_device,
}; };
int logfs_get_sb_mtd(struct file_system_type *type, int flags, int logfs_get_sb_mtd(struct logfs_super *s,
struct file_system_type *type, int flags,
int mtdnr, struct vfsmount *mnt) int mtdnr, struct vfsmount *mnt)
{ {
struct mtd_info *mtd; struct mtd_info *mtd;
const struct logfs_device_ops *devops = &mtd_devops; const struct logfs_device_ops *devops = &mtd_devops;
mtd = get_mtd_device(NULL, mtdnr); mtd = get_mtd_device(NULL, mtdnr);
if (IS_ERR(mtd)) if (IS_ERR(mtd)) {
kfree(s);
return PTR_ERR(mtd); return PTR_ERR(mtd);
return logfs_get_sb_device(type, flags, mtd, NULL, devops, mnt); }
return logfs_get_sb_device(s, type, flags, mtd, NULL, devops, mnt);
} }

View File

@ -471,24 +471,30 @@ void logfs_compr_exit(void);
/* dev_bdev.c */ /* dev_bdev.c */
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
int logfs_get_sb_bdev(struct file_system_type *type, int flags, int logfs_get_sb_bdev(struct logfs_super *s,
struct file_system_type *type, int flags,
const char *devname, struct vfsmount *mnt); const char *devname, struct vfsmount *mnt);
#else #else
static inline int logfs_get_sb_bdev(struct file_system_type *type, int flags, static inline int logfs_get_sb_bdev(struct logfs_super *s,
struct file_system_type *type, int flags,
const char *devname, struct vfsmount *mnt) const char *devname, struct vfsmount *mnt)
{ {
kfree(s);
return -ENODEV; return -ENODEV;
} }
#endif #endif
/* dev_mtd.c */ /* dev_mtd.c */
#ifdef CONFIG_MTD #ifdef CONFIG_MTD
int logfs_get_sb_mtd(struct file_system_type *type, int flags, int logfs_get_sb_mtd(struct logfs_super *s,
struct file_system_type *type, int flags,
int mtdnr, struct vfsmount *mnt); int mtdnr, struct vfsmount *mnt);
#else #else
static inline int logfs_get_sb_mtd(struct file_system_type *type, int flags, static inline int logfs_get_sb_mtd(struct logfs_super *s,
struct file_system_type *type, int flags,
int mtdnr, struct vfsmount *mnt) int mtdnr, struct vfsmount *mnt)
{ {
kfree(s);
return -ENODEV; return -ENODEV;
} }
#endif #endif
@ -619,7 +625,8 @@ void emergency_read_end(struct page *page);
void logfs_crash_dump(struct super_block *sb); void logfs_crash_dump(struct super_block *sb);
void *memchr_inv(const void *s, int c, size_t n); void *memchr_inv(const void *s, int c, size_t n);
int logfs_statfs(struct dentry *dentry, struct kstatfs *stats); int logfs_statfs(struct dentry *dentry, struct kstatfs *stats);
int logfs_get_sb_device(struct file_system_type *type, int flags, int logfs_get_sb_device(struct logfs_super *s,
struct file_system_type *type, int flags,
struct mtd_info *mtd, struct block_device *bdev, struct mtd_info *mtd, struct block_device *bdev,
const struct logfs_device_ops *devops, struct vfsmount *mnt); const struct logfs_device_ops *devops, struct vfsmount *mnt);
int logfs_check_ds(struct logfs_disk_super *ds); int logfs_check_ds(struct logfs_disk_super *ds);

View File

@ -536,19 +536,16 @@ static void logfs_kill_sb(struct super_block *sb)
log_super("LogFS: Finished unmounting\n"); log_super("LogFS: Finished unmounting\n");
} }
int logfs_get_sb_device(struct file_system_type *type, int flags, int logfs_get_sb_device(struct logfs_super *super,
struct file_system_type *type, int flags,
struct mtd_info *mtd, struct block_device *bdev, struct mtd_info *mtd, struct block_device *bdev,
const struct logfs_device_ops *devops, struct vfsmount *mnt) const struct logfs_device_ops *devops, struct vfsmount *mnt)
{ {
struct logfs_super *super;
struct super_block *sb; struct super_block *sb;
int err = -ENOMEM; int err = -ENOMEM;
static int mount_count; static int mount_count;
log_super("LogFS: Start mount %x\n", mount_count++); log_super("LogFS: Start mount %x\n", mount_count++);
super = kzalloc(sizeof(*super), GFP_KERNEL);
if (!super)
goto err0;
super->s_mtd = mtd; super->s_mtd = mtd;
super->s_bdev = bdev; super->s_bdev = bdev;
@ -603,20 +600,27 @@ static int logfs_get_sb(struct file_system_type *type, int flags,
const char *devname, void *data, struct vfsmount *mnt) const char *devname, void *data, struct vfsmount *mnt)
{ {
ulong mtdnr; ulong mtdnr;
struct logfs_super *super;
super = kzalloc(sizeof(*super), GFP_KERNEL);
if (!super)
return -ENOMEM;
if (!devname) if (!devname)
return logfs_get_sb_bdev(type, flags, devname, mnt); return logfs_get_sb_bdev(super, type, flags, devname, mnt);
if (strncmp(devname, "mtd", 3)) if (strncmp(devname, "mtd", 3))
return logfs_get_sb_bdev(type, flags, devname, mnt); return logfs_get_sb_bdev(super, type, flags, devname, mnt);
{ {
char *garbage; char *garbage;
mtdnr = simple_strtoul(devname+3, &garbage, 0); mtdnr = simple_strtoul(devname+3, &garbage, 0);
if (*garbage) if (*garbage) {
kfree(super);
return -EINVAL; return -EINVAL;
}
} }
return logfs_get_sb_mtd(type, flags, mtdnr, mnt); return logfs_get_sb_mtd(super, type, flags, mtdnr, mnt);
} }
static struct file_system_type logfs_fs_type = { static struct file_system_type logfs_fs_type = {