From 57a1e15c0fd62e892b77115c30750ed191d37ba3 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 13 Jul 2014 15:26:02 +0400 Subject: [PATCH] Implement external journal device instead of internal --- simple.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/simple.c b/simple.c index 2c64d53..26714ce 100644 --- a/simple.c +++ b/simple.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "super.h" @@ -700,15 +702,23 @@ static const struct super_operations simplefs_sops = { .put_super = simplefs_put_super, }; -static int simplefs_load_journal(struct super_block *sb) +static int simplefs_load_journal(struct super_block *sb, int devnum) { struct journal_s *journal; - struct inode *inode; + dev_t dev; + struct block_device *bdev; + int hblock, blocksize, len; struct simplefs_super_block *sfs_sb = SIMPLEFS_SB(sb); - inode = simplefs_iget(sb, SIMPLEFS_JOURNAL_INODE_NUMBER); + dev = new_decode_dev(devnum); + bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb); + if (IS_ERR(bdev)) + return 1; + blocksize = sb->s_blocksize; + hblock = bdev_logical_block_size(bdev); + len = SIMPLEFS_MAX_FILESYSTEM_OBJECTS_SUPPORTED; - journal = jbd2_journal_init_inode(inode); + journal = jbd2_journal_init_dev(bdev, sb->s_bdev, 1, len, blocksize); journal->j_private = sb; sfs_sb->journal = journal; @@ -716,6 +726,37 @@ static int simplefs_load_journal(struct super_block *sb) return 0; } +#define SIMPLEFS_OPT_JOURNAL_DEV 1 +static const match_table_t tokens = { + {SIMPLEFS_OPT_JOURNAL_DEV, "journal_dev=%u"}, +}; +static int simplefs_parse_options(struct super_block *sb, char *options) +{ + substring_t args[MAX_OPT_ARGS]; + int token, ret, arg; + char *p; + + while ((p = strsep(&options, ",")) != NULL) { + if (!*p) + continue; + + args[0].to = args[0].from = NULL; + token = match_token(p, tokens, args); + + switch (token) { + case SIMPLEFS_OPT_JOURNAL_DEV: + if (args->from && match_int(args, &arg)) + return 1; + printk(KERN_INFO "Loading journal devnum: %i\n", arg); + if ((ret = simplefs_load_journal(sb, arg))) + return ret; + break; + } + } + + return 0; +} + /* This function, as the name implies, Makes the super_block valid and * fills filesystem specific information in the super block */ int simplefs_fill_super(struct super_block *sb, void *data, int silent) @@ -784,7 +825,7 @@ int simplefs_fill_super(struct super_block *sb, void *data, int silent) goto release; } - if ((ret = simplefs_load_journal(sb))) + if ((ret = simplefs_parse_options(sb, data))) goto release; ret = 0;