From: NeilBrown Date: Mon, 18 Oct 2010 01:00:41 +0000 (+1100) Subject: more error tests in lafs_mount X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=82991d7dfa95de2faab91e0b4ce048aea092f53d;p=LaFS.git more error tests in lafs_mount Nothing particularly interesting, just catching all possible errors and handling gracefully. Signed-off-by: NeilBrown --- diff --git a/roll.c b/roll.c index 4a6938d..2c561db 100644 --- 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 5ec7029..853ed7b 100644 --- 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);