Unionfs: grab lower super_block references
authorErez Zadok <ezk@cs.sunysb.edu>
Fri, 15 Feb 2008 22:18:48 +0000 (17:18 -0500)
committerErez Zadok <ezk@cs.sunysb.edu>
Fri, 12 Aug 2011 02:37:32 +0000 (22:37 -0400)
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 23c18f7f9119643049a56eb0c5e043711c60af58..ba3471dc6279ee9ad1bdfaffab78ea2d024cf34c 100644 (file)
@@ -636,6 +636,7 @@ static int unionfs_read_super(struct super_block *sb, void *raw_data,
        sbend(sb) = bend = lower_root_info->bend;
        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);
        }
 
@@ -711,6 +712,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 986c980261a5b171147d66ac05bf08423e2fd6b6..175840f0162f3be63be1e026965246fb164128dd 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;
@@ -729,6 +737,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 14577bc997a62684795b207c3ea7a647fdb9448c..ff764d93924d33d12f7279873b0e306fcf520de1 100644 (file)
@@ -134,7 +134,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 */