Skip to content

Commit

Permalink
Merge branch 'journal-v6'
Browse files Browse the repository at this point in the history
This patchset adds journal support into simplefs using jbd2, the only
available journal is external (you could create it using mke2fs -O
journal_dev, for more info look into simple-test.sh), and the only spot
that have start/write_access/dirty_metadata/stop is simplefs_write()
(IOW no support for creation).

This branch is compacted, for more verbose versions of this patchset
please look into more older version (v4, v3, ...).

Here is the example of records in journal:
==> final-jbd2-ext4.logdump <==
logdump
Journal starts at block 1, transaction 4
Found expected sequence 4, type 1 (descriptor block) at block 1
Found expected sequence 4, type 2 (commit block) at block 16
Found expected sequence 5, type 1 (descriptor block) at block 17
Found expected sequence 5, type 2 (commit block) at block 19
Found expected sequence 6, type 1 (descriptor block) at block 20
Found expected sequence 6, type 2 (commit block) at block 22
No magic number at block 23: end of journal.

==> final-jbd2-simplefs.logdump <==
debugfs:  logdump -f /dev/loop0
Ext2 superblock header found.
Journal starts at block 2, transaction 2
Found expected sequence 2, type 1 (descriptor block) at block 2
Found expected sequence 2, type 2 (commit block) at block 4
Found expected sequence 3, type 1 (descriptor block) at block 5
Found expected sequence 3, type 2 (commit block) at block 7
Found expected sequence 4, type 1 (descriptor block) at block 8
Found expected sequence 4, type 2 (commit block) at block 10
Found expected sequence 5, type 1 (descriptor block) at block 11
Found expected sequence 5, type 2 (commit block) at block 13
Found expected sequence 6, type 1 (descriptor block) at block 14
Found expected sequence 6, type 2 (commit block) at block 16
Found expected sequence 7, type 1 (descriptor block) at block 17
Found expected sequence 7, type 2 (commit block) at block 19
Found expected sequence 8, type 1 (descriptor block) at block 20
Found expected sequence 8, type 2 (commit block) at block 22
No magic number at block 23: end of journal.

* journal-v6:
  simplefs_write: install h_sync (sync on close) for jbd2 handle
  Use max available journal size with jbd2_journal_init_dev()
  simple-test: create journal with 4k block size
  simple-test: use losetup+journal_path=/dev/loopX for mounting with journal
  Handle bdevs for journal_path= mount flag
  Actually load journal by calling jbd2_journal_load()
  simple-test: mount fs with journal
  Implement journal_path option
  Add loader for internal journal (we need to update mkfs to support this)
  Add sfs_trace for lookup and compare inside it
  simple-test: enable jbd2-debug
  Check that journal was initialized successfully
  Write journal device name
  Implement external journal device instead of internal
  simplefs_write: add journaling using jbd2
  Initial support of journaling
  • Loading branch information
azat committed Oct 1, 2014
2 parents 072ef5b + 4c486f7 commit 5d00eeb
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 45 deletions.
59 changes: 48 additions & 11 deletions mkfs-simplefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@

#include "simple.h"

const uint64_t WELCOMEFILE_DATABLOCK_NUMBER = 3;
const uint64_t WELCOMEFILE_INODE_NUMBER = 2;
#define WELCOMEFILE_DATABLOCK_NUMBER (SIMPLEFS_LAST_RESERVED_BLOCK + 1)
#define WELCOMEFILE_INODE_NUMBER (SIMPLEFS_LAST_RESERVED_INODE + 1)

static int write_superblock(int fd)
{
struct simplefs_super_block sb = {
.version = 1,
.magic = SIMPLEFS_MAGIC,
.block_size = SIMPLEFS_DEFAULT_BLOCK_SIZE,
/* One inode for rootdirectory and another for a welcome file that we are going to create */
.inodes_count = 2,
.inodes_count = WELCOMEFILE_INODE_NUMBER,
/* FIXME: Free blocks management is not implemented yet */
.free_blocks = (~0) & ~(1 << WELCOMEFILE_DATABLOCK_NUMBER),
.free_blocks = (~0) & ~(1 << SIMPLEFS_LAST_RESERVED_BLOCK),
};
ssize_t ret;

Expand All @@ -37,7 +36,7 @@ static int write_superblock(int fd)
return 0;
}

static int write_inode_store(int fd)
static int write_root_inode(int fd)
{
ssize_t ret;

Expand All @@ -59,8 +58,26 @@ static int write_inode_store(int fd)
printf("root directory inode written succesfully\n");
return 0;
}
static int write_journal_inode(int fd)
{
ssize_t ret;

struct simplefs_inode journal;

journal.inode_no = SIMPLEFS_JOURNAL_INODE_NUMBER;
journal.data_block_number = SIMPLEFS_JOURNAL_BLOCK_NUMBER;

ret = write(fd, &journal, sizeof(journal));

if (ret != sizeof(journal)) {
printf("Error while writing journal inode. Retry your mkfs\n");
return -1;
}

static int write_inode(int fd, const struct simplefs_inode *i)
printf("journal inode written succesfully\n");
return 0;
}
static int write_welcome_inode(int fd, const struct simplefs_inode *i)
{
off_t nbytes;
ssize_t ret;
Expand All @@ -73,7 +90,7 @@ static int write_inode(int fd, const struct simplefs_inode *i)
}
printf("welcomefile inode written succesfully\n");

nbytes = SIMPLEFS_DEFAULT_BLOCK_SIZE - sizeof(*i) - sizeof(*i);
nbytes = SIMPLEFS_DEFAULT_BLOCK_SIZE - (sizeof(*i) * 3);
ret = lseek(fd, nbytes, SEEK_CUR);
if (ret == (off_t)-1) {
printf
Expand All @@ -82,9 +99,23 @@ static int write_inode(int fd, const struct simplefs_inode *i)
}

printf
("inode store padding bytes (after the two inodes) written sucessfully\n");
("inode store padding bytes (after the three inodes) written sucessfully\n");
return 0;
}

int write_journal(int fd)
{
ssize_t ret;
ret = lseek(fd, SIMPLEFS_DEFAULT_BLOCK_SIZE * SIMPLEFS_JOURNAL_BLOCKS, SEEK_CUR);
if (ret == (off_t)-1) {
printf("Can't write journal. Retry you mkfs\n");
return -1;
}

printf("Journal written successfully\n");
return 0;
}

int write_dirent(int fd, const struct simplefs_dir_record *record)
{
ssize_t nbytes = sizeof(*record), ret;
Expand Down Expand Up @@ -154,11 +185,17 @@ int main(int argc, char *argv[])
do {
if (write_superblock(fd))
break;
if (write_inode_store(fd))

if (write_root_inode(fd))
break;
if (write_journal_inode(fd))
break;
if (write_welcome_inode(fd, &welcome))
break;

if (write_inode(fd, &welcome))
if (write_journal(fd))
break;

if (write_dirent(fd, &record))
break;
if (write_block(fd, welcomefile_body, welcome.file_size))
Expand Down
17 changes: 14 additions & 3 deletions simple-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@

set -e

echo 1 >| /sys/module/jbd2/parameters/jbd2_debug

root_pwd="$PWD"
test_dir="test-dir-$RANDOM"
test_mount_point="test-mount-point-$RANDOM"
test_journal_dev=""

function create_journal()
{
dd bs=1M count=10 if=/dev/zero of="$1"
mke2fs -b 4096 -O journal_dev "$1"
}
function create_test_image()
{
dd bs=4096 count=100 if=/dev/zero of="$1"
Expand All @@ -27,12 +35,14 @@ function create_test_image()
function mount_fs_image()
{
insmod simplefs.ko
mount -o loop,owner,group,users -t simplefs "$1" "$2"
test_journal_dev=$(losetup -f --show "$1")
mount -o loop,owner,group,users,journal_path="$test_journal_dev" -t simplefs "$2" "$3"
dmesg | tail -n20
}
function unmount_fs()
{
umount "$1"
losetup -d $test_journal_dev
rmmod simplefs.ko
dmesg | tail -n20
}
Expand Down Expand Up @@ -106,15 +116,16 @@ cleanup
trap cleanup SIGINT EXIT
mkdir "$test_dir" "$test_mount_point"
create_test_image "$test_dir/image"
create_journal "$test_dir/journal"

# 1
mount_fs_image "$test_dir/image" "$test_mount_point"
mount_fs_image "$test_dir/journal" "$test_dir/image" "$test_mount_point"
do_some_operations "$test_mount_point"
cd "$root_pwd"
unmount_fs "$test_mount_point"

# 2
mount_fs_image "$test_dir/image" "$test_mount_point"
mount_fs_image "$test_dir/journal" "$test_dir/image" "$test_mount_point"
do_read_operations "$test_mount_point"
cd "$root_pwd"
unmount_fs "$test_mount_point"
Expand Down
Loading

0 comments on commit 5d00eeb

Please sign in to comment.