]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - fs/aufs/sbinfo.c
2 * Copyright (C) 2005-2016 Junjiro R. Okajima
4 * This program, aufs is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * superblock private data
25 * they are necessary regardless sysfs is disabled.
27 void au_si_free(struct kobject
*kobj
)
30 struct au_sbinfo
*sbinfo
;
31 char *locked __maybe_unused
; /* debug only */
33 sbinfo
= container_of(kobj
, struct au_sbinfo
, si_kobj
);
34 for (i
= 0; i
< AuPlink_NHASH
; i
++)
35 AuDebugOn(!hlist_empty(&sbinfo
->si_plink
[i
].head
));
36 AuDebugOn(atomic_read(&sbinfo
->si_nowait
.nw_len
));
38 AuDebugOn(percpu_counter_sum(&sbinfo
->si_ninodes
));
39 percpu_counter_destroy(&sbinfo
->si_ninodes
);
40 AuDebugOn(percpu_counter_sum(&sbinfo
->si_nfiles
));
41 percpu_counter_destroy(&sbinfo
->si_nfiles
);
43 au_rw_write_lock(&sbinfo
->si_rwsem
);
45 au_rw_write_unlock(&sbinfo
->si_rwsem
);
47 au_delayed_kfree(sbinfo
->si_branch
);
48 for (i
= 0; i
< AU_NPIDMAP
; i
++)
49 if (sbinfo
->au_si_pid
.pid_bitmap
[i
])
50 au_delayed_kfree(sbinfo
->au_si_pid
.pid_bitmap
[i
]);
51 mutex_destroy(&sbinfo
->au_si_pid
.pid_mtx
);
52 mutex_destroy(&sbinfo
->si_xib_mtx
);
53 AuRwDestroy(&sbinfo
->si_rwsem
);
55 au_delayed_kfree(sbinfo
);
58 int au_si_alloc(struct super_block
*sb
)
61 struct au_sbinfo
*sbinfo
;
64 sbinfo
= kzalloc(sizeof(*sbinfo
), GFP_NOFS
);
65 if (unlikely(!sbinfo
))
68 /* will be reallocated separately */
69 sbinfo
->si_branch
= kzalloc(sizeof(*sbinfo
->si_branch
), GFP_NOFS
);
70 if (unlikely(!sbinfo
->si_branch
))
73 err
= sysaufs_si_init(sbinfo
);
77 au_nwt_init(&sbinfo
->si_nowait
);
78 au_rw_init_wlock(&sbinfo
->si_rwsem
);
79 mutex_init(&sbinfo
->au_si_pid
.pid_mtx
);
81 percpu_counter_init(&sbinfo
->si_ninodes
, 0, GFP_NOFS
);
82 percpu_counter_init(&sbinfo
->si_nfiles
, 0, GFP_NOFS
);
85 sbinfo
->si_last_br_id
= AUFS_BRANCH_MAX
/ 2;
87 sbinfo
->si_wbr_copyup
= AuWbrCopyup_Def
;
88 sbinfo
->si_wbr_create
= AuWbrCreate_Def
;
89 sbinfo
->si_wbr_copyup_ops
= au_wbr_copyup_ops
+ sbinfo
->si_wbr_copyup
;
90 sbinfo
->si_wbr_create_ops
= au_wbr_create_ops
+ sbinfo
->si_wbr_create
;
94 sbinfo
->si_mntflags
= au_opts_plink(AuOpt_Def
);
96 sbinfo
->si_xino_jiffy
= jiffies
;
97 sbinfo
->si_xino_expire
98 = msecs_to_jiffies(AUFS_XINO_DEF_SEC
* MSEC_PER_SEC
);
99 mutex_init(&sbinfo
->si_xib_mtx
);
100 sbinfo
->si_xino_brid
= -1;
101 /* leave si_xib_last_pindex and si_xib_next_bit */
103 au_sphl_init(&sbinfo
->si_aopen
);
105 sbinfo
->si_rdcache
= msecs_to_jiffies(AUFS_RDCACHE_DEF
* MSEC_PER_SEC
);
106 sbinfo
->si_rdblk
= AUFS_RDBLK_DEF
;
107 sbinfo
->si_rdhash
= AUFS_RDHASH_DEF
;
108 sbinfo
->si_dirwh
= AUFS_DIRWH_DEF
;
110 for (i
= 0; i
< AuPlink_NHASH
; i
++)
111 au_sphl_init(sbinfo
->si_plink
+ i
);
112 init_waitqueue_head(&sbinfo
->si_plink_wq
);
113 spin_lock_init(&sbinfo
->si_plink_maint_lock
);
115 au_sphl_init(&sbinfo
->si_files
);
117 /* with getattr by default */
118 sbinfo
->si_iop_array
= aufs_iop
;
120 /* leave other members for sysaufs and si_mnt. */
122 sb
->s_fs_info
= sbinfo
;
124 return 0; /* success */
127 au_delayed_kfree(sbinfo
->si_branch
);
129 au_delayed_kfree(sbinfo
);
134 int au_sbr_realloc(struct au_sbinfo
*sbinfo
, int nbr
, int may_shrink
)
137 struct au_branch
**brp
;
139 AuRwMustWriteLock(&sbinfo
->si_rwsem
);
142 sz
= sizeof(*brp
) * (sbinfo
->si_bbot
+ 1);
145 brp
= au_kzrealloc(sbinfo
->si_branch
, sz
, sizeof(*brp
) * nbr
, GFP_NOFS
,
148 sbinfo
->si_branch
= brp
;
155 /* ---------------------------------------------------------------------- */
157 unsigned int au_sigen_inc(struct super_block
*sb
)
164 gen
= ++au_sbi(sb
)->si_generation
;
165 au_update_digen(sb
->s_root
);
166 inode
= d_inode(sb
->s_root
);
167 au_update_iigen(inode
, /*half*/0);
172 aufs_bindex_t
au_new_br_id(struct super_block
*sb
)
176 struct au_sbinfo
*sbinfo
;
181 for (i
= 0; i
<= AUFS_BRANCH_MAX
; i
++) {
182 br_id
= ++sbinfo
->si_last_br_id
;
183 AuDebugOn(br_id
< 0);
184 if (br_id
&& au_br_index(sb
, br_id
) < 0)
191 /* ---------------------------------------------------------------------- */
193 /* it is ok that new 'nwt' tasks are appended while we are sleeping */
194 int si_read_lock(struct super_block
*sb
, int flags
)
199 if (au_ftest_lock(flags
, FLUSH
))
200 au_nwt_flush(&au_sbi(sb
)->si_nowait
);
202 si_noflush_read_lock(sb
);
203 err
= au_plink_maint(sb
, flags
);
210 int si_write_lock(struct super_block
*sb
, int flags
)
214 if (au_ftest_lock(flags
, FLUSH
))
215 au_nwt_flush(&au_sbi(sb
)->si_nowait
);
217 si_noflush_write_lock(sb
);
218 err
= au_plink_maint(sb
, flags
);
225 /* dentry and super_block lock. call at entry point */
226 int aufs_read_lock(struct dentry
*dentry
, int flags
)
229 struct super_block
*sb
;
232 err
= si_read_lock(sb
, flags
);
236 if (au_ftest_lock(flags
, DW
))
237 di_write_lock_child(dentry
);
239 di_read_lock_child(dentry
, flags
);
241 if (au_ftest_lock(flags
, GEN
)) {
242 err
= au_digen_test(dentry
, au_sigen(sb
));
243 if (!au_opt_test(au_mntflags(sb
), UDBA_NONE
))
244 AuDebugOn(!err
&& au_dbrange_test(dentry
));
246 err
= au_dbrange_test(dentry
);
248 aufs_read_unlock(dentry
, flags
);
255 void aufs_read_unlock(struct dentry
*dentry
, int flags
)
257 if (au_ftest_lock(flags
, DW
))
258 di_write_unlock(dentry
);
260 di_read_unlock(dentry
, flags
);
261 si_read_unlock(dentry
->d_sb
);
264 void aufs_write_lock(struct dentry
*dentry
)
266 si_write_lock(dentry
->d_sb
, AuLock_FLUSH
| AuLock_NOPLMW
);
267 di_write_lock_child(dentry
);
270 void aufs_write_unlock(struct dentry
*dentry
)
272 di_write_unlock(dentry
);
273 si_write_unlock(dentry
->d_sb
);
276 int aufs_read_and_write_lock2(struct dentry
*d1
, struct dentry
*d2
, int flags
)
280 struct super_block
*sb
;
283 err
= si_read_lock(sb
, flags
);
287 di_write_lock2_child(d1
, d2
, au_ftest_lock(flags
, DIRS
));
289 if (au_ftest_lock(flags
, GEN
)) {
290 sigen
= au_sigen(sb
);
291 err
= au_digen_test(d1
, sigen
);
292 AuDebugOn(!err
&& au_dbrange_test(d1
));
294 err
= au_digen_test(d2
, sigen
);
295 AuDebugOn(!err
&& au_dbrange_test(d2
));
298 aufs_read_and_write_unlock2(d1
, d2
);
305 void aufs_read_and_write_unlock2(struct dentry
*d1
, struct dentry
*d2
)
307 di_write_unlock2(d1
, d2
);
308 si_read_unlock(d1
->d_sb
);
311 /* ---------------------------------------------------------------------- */
313 static void si_pid_alloc(struct au_si_pid
*au_si_pid
, int idx
)
317 BUILD_BUG_ON(sizeof(unsigned long) !=
318 sizeof(*au_si_pid
->pid_bitmap
));
320 mutex_lock(&au_si_pid
->pid_mtx
);
321 p
= au_si_pid
->pid_bitmap
[idx
];
325 * but keeping 'si_pid_set()' void is more important.
327 p
= kcalloc(BITS_TO_LONGS(AU_PIDSTEP
),
328 sizeof(*au_si_pid
->pid_bitmap
),
334 au_si_pid
->pid_bitmap
[idx
] = p
;
335 mutex_unlock(&au_si_pid
->pid_mtx
);
338 void si_pid_set(struct super_block
*sb
)
342 unsigned long *bitmap
;
343 struct au_si_pid
*au_si_pid
;
345 si_pid_idx_bit(&idx
, &bit
);
346 au_si_pid
= &au_sbi(sb
)->au_si_pid
;
347 bitmap
= au_si_pid
->pid_bitmap
[idx
];
349 si_pid_alloc(au_si_pid
, idx
);
350 bitmap
= au_si_pid
->pid_bitmap
[idx
];
352 AuDebugOn(test_bit(bit
, bitmap
));
353 set_bit(bit
, bitmap
);