]> git.neil.brown.name Git - LaFS.git/commitdiff
more error tests in lafs_mount
authorNeilBrown <neilb@suse.de>
Mon, 18 Oct 2010 01:00:41 +0000 (12:00 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 18 Oct 2010 01:29:08 +0000 (12:29 +1100)
Nothing particularly interesting, just catching all possible errors
and handling gracefully.

Signed-off-by: NeilBrown <neilb@suse.de>
roll.c
super.c

diff --git a/roll.c b/roll.c
index 4a6938d2694aa05ad264b3763e7fd4332f69a034..2c561db5c3e00060c6d9cdcea57ef182ed1261a2 100644 (file)
--- a/roll.c
+++ b/roll.c
@@ -713,8 +713,8 @@ static int roll_forward(struct fs *fs)
 int
 lafs_mount(struct fs *fs)
 {
-       struct datablock *b;
-       struct inode *root;
+       struct datablock *b = NULL;
+       struct inode *ino;
        struct inode *rootdir;
        struct dentry *de;
        int err;
@@ -723,11 +723,13 @@ lafs_mount(struct fs *fs)
        int orphan_count;
 
        fs->rolled = 0;
-       fs->ss[0].root = root = iget_locked(fs->prime_sb, 0);
-       k->root = root;
+       fs->ss[0].root = ino = iget_locked(fs->prime_sb, 0);
+       k->root = ino;
 
        err = -ENOMEM;
-       b = lafs_get_block(root, 0, NULL, GFP_KERNEL, MKREF(mount));
+       if (!ino)
+               goto err;
+       b = lafs_get_block(ino, 0, NULL, GFP_KERNEL, MKREF(mount));
        if (!b)
                goto err;
        set_bit(B_Root, &b->b.flags);
@@ -740,14 +742,13 @@ lafs_mount(struct fs *fs)
        if (err)
                goto err;
 
-       err = lafs_import_inode(root, b);
+       err = lafs_import_inode(ino, b);
        if (err)
                goto err;
        putdref(b, MKREF(mount));
        b = NULL;
 
-       unlock_new_inode(root);
-       /* FIXME lots of error checking */
+       unlock_new_inode(ino);
 
        rootdir = lafs_iget(fs->prime_sb, 2, SYNC);
        err = PTR_ERR(rootdir);
@@ -755,16 +756,35 @@ lafs_mount(struct fs *fs)
                goto err;
        de = d_alloc_root(rootdir);
        err = PTR_ERR(de);
-       if (IS_ERR(de))
+       if (IS_ERR(de)) {
+               iput(rootdir);
                goto err;
+       }
        fs->prime_sb->s_root = de;
 
-       fs->orphans = lafs_iget(fs->prime_sb, 8, SYNC);
+       ino = lafs_iget(fs->prime_sb, 8, SYNC);
+       err = PTR_ERR(ino);
+       if (IS_ERR(ino))
+               goto err;
+       if (LAFSI(ino)->type != TypeOrphanList) {
+               iput(ino);
+               err = -EINVAL;
+               goto err;
+       }
+       fs->orphans = ino;
        for (d = 0; d < fs->devices ; d++) {
-               fs->devs[d].segsum = lafs_iget(fs->prime_sb,
-                                              fs->devs[d].usage_inum,
-                                              SYNC);
-               /* FIXME check this is a segusage file */
+               ino = lafs_iget(fs->prime_sb,
+                               fs->devs[d].usage_inum,
+                               SYNC);
+               err = PTR_ERR(ino);
+               if (IS_ERR(ino))
+                       goto err;
+               if (LAFSI(ino)->type != TypeSegmentMap) {
+                       iput(ino);
+                       err = -EINVAL;
+                       goto err;
+               }
+               fs->devs[d].segsum = ino;
        }
        orphan_count = lafs_count_orphans(fs->orphans);
        LAFSI(fs->orphans)->md.orphan.nextfree = orphan_count;
@@ -776,11 +796,12 @@ lafs_mount(struct fs *fs)
        lafs_add_orphans(fs, fs->orphans, orphan_count);
 
        for (d = 0; d < 4; d++) {
-               fs->cleaner.seg[d].chead = alloc_page(GFP_KERNEL);
+               struct page *p = alloc_page(GFP_KERNEL);
+               if (!p)
+                       err = -ENOMEM;
+               fs->cleaner.seg[d].chead = p;
                INIT_LIST_HEAD(&fs->cleaner.seg[d].cleaning);
        }
-       return err;
-
 err:
        putdref(b, MKREF(mount));
        return err;
diff --git a/super.c b/super.c
index 5ec7029b262b6097387ba63a52cb74645ab938b6..853ed7bd6282a9169b1c39dfe3cabb9b9e3cb24f 100644 (file)
--- a/super.c
+++ b/super.c
@@ -762,6 +762,10 @@ static void lafs_kill_sb(struct super_block *sb)
        flush_scheduled_work();
        lafs_stop_thread(fs);
 
+       for (i = 0; i < 4; i++)
+               if (fs->cleaner.seg[i].chead)
+                       put_page(fs->cleaner.seg[i].chead);
+
        kfree(fs->state);
        kfree(fs->ss);
        kfree(fs->devs);