Unionfs: grab lower super_block references
authorRachita Kothiyal <rachita@dewey.fsl.cs.sunysb.edu>
Fri, 29 Feb 2008 15:25:15 +0000 (10:25 -0500)
committerRachita Kothiyal <rachita@dewey.fsl.cs.sunysb.edu>
Fri, 29 Feb 2008 15:25:15 +0000 (10:25 -0500)
This prevents the lower super_block from being destroyed too early, when a
lower file system is being unmounted with MNT_FORCE or MNT_DETACH.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/main.c
fs/unionfs/super.c
fs/unionfs/union.h

index c1a9763ff9a1b6d60a70cac7a88f8559753f305e..04a453f734df0fe9162fd400c548db275746efb0 100644 (file)
@@ -713,6 +713,7 @@ static int unionfs_read_super(struct super_block *sb, void *raw_data,
        high_bid = -1;
        for (bindex = bstart; bindex <= bend; bindex++) {
                struct dentry *d = lower_root_info->lower_paths[bindex].dentry;
+               atomic_inc(&d->d_sb->s_active);
                unionfs_set_lower_super_idx(sb, bindex, d->d_sb);
 
                if (bid) {
@@ -812,6 +813,8 @@ out_dput:
                        dput(d);
                        /* initializing: can't use unionfs_mntput here */
                        mntput(m);
+                       /* drop refs we took earlier */
+                       atomic_dec(&d->d_sb->s_active);
                }
                kfree(lower_root_info->lower_paths);
                kfree(lower_root_info);
index 965d301a5105f86933cd25e8331c57525772f4eb..87beae52c87596d89cd6ee02fdd6d54068a987d6 100644 (file)
@@ -116,6 +116,14 @@ static void unionfs_put_super(struct super_block *sb)
                }
        BUG_ON(leaks != 0);
 
+       /* decrement lower super references */
+       for (bindex = bstart; bindex <= bend; bindex++) {
+               struct super_block *s;
+               s = unionfs_lower_super_idx(sb, bindex);
+               unionfs_set_lower_super_idx(sb, bindex, NULL);
+               atomic_dec(&s->s_active);
+       }
+
        kfree(spd->data);
        kfree(spd);
        sb->s_fs_info = NULL;
@@ -761,6 +769,12 @@ out_no_change:
         */
        purge_sb_data(sb);
 
+       /* grab new lower super references; release old ones */
+       for (i = 0; i < new_branches; i++)
+               atomic_inc(&new_data[i].sb->s_active);
+       for (i = 0; i < new_branches; i++)
+               atomic_dec(&UNIONFS_SB(sb)->data[i].sb->s_active);
+
        /* copy new vectors into their correct place */
        tmp_data = UNIONFS_SB(sb)->data;
        UNIONFS_SB(sb)->data = new_data;
index 1cade8893bde96078903b5cfc87f54c43d6176e4..d903d4f887ce5f4530c705ebdf6bc8ca9f2b08d8 100644 (file)
@@ -169,7 +169,7 @@ struct unionfs_dentry_info {
 
 /* These are the pointers to our various objects. */
 struct unionfs_data {
-       struct super_block *sb;
+       struct super_block *sb; /* lower super_block */
        atomic_t open_files;    /* number of open files on branch */
        int branchperms;
        int branch_id;          /* unique branch ID at re/mount time */