]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - fs/aufs/branch.h
012459ad57f345b0383426228e8596a9611a7d31
1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2005-2019 Junjiro R. Okajima
5 * This program, aufs is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * branch filesystems and xino for them
23 #ifndef __AUFS_BRANCH_H__
24 #define __AUFS_BRANCH_H__
28 #include <linux/mount.h>
35 /* ---------------------------------------------------------------------- */
39 struct file
**xi_file
;
40 unsigned int xi_nfile
;
46 /* reserved for future use */
47 /* unsigned long *bitmap; */
48 wait_queue_head_t wqh
;
51 struct mutex xi_mtx
; /* protects xi_file array */
52 struct hlist_bl_head xi_writing
;
54 atomic_t xi_truncating
;
59 /* File-based Hierarchical Storage Management */
61 #ifdef CONFIG_AUFS_FHSM
63 unsigned long bf_jiffy
;
64 struct aufs_stfs bf_stfs
;
69 /* members for writable branch only */
70 enum {AuBrWh_BASE
, AuBrWh_PLINK
, AuBrWh_ORPH
, AuBrWh_Last
};
72 struct au_rwsem wbr_wh_rwsem
;
73 struct dentry
*wbr_wh
[AuBrWh_Last
];
74 atomic_t wbr_wh_running
;
75 #define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
76 #define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
77 #define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
80 unsigned long long wbr_bytes
;
83 /* ext2 has 3 types of operations at least, ext3 has 4 */
84 #define AuBrDynOp (AuDyLast * 4)
86 #ifdef CONFIG_AUFS_HFSNOTIFY
87 /* support for asynchronous destruction */
88 struct au_br_hfsnotify
{
89 struct fsnotify_group
*hfsn_group
;
96 struct attribute attr
;
105 /* protected by superblock rwsem */
107 struct au_xino
*br_xino
;
113 spinlock_t br_dykey_lock
;
114 struct au_dykey
*br_dykey
[AuBrDynOp
];
115 au_lcnt_t br_nfiles
; /* opened files */
116 au_lcnt_t br_count
; /* in-use for other */
118 struct au_wbr
*br_wbr
;
119 struct au_br_fhsm
*br_fhsm
;
121 #ifdef CONFIG_AUFS_HFSNOTIFY
122 struct au_br_hfsnotify
*br_hfsn
;
126 /* entries under sysfs per mount-point */
127 struct au_brsysfs br_sysfs
[AuBrSysfs_Last
];
130 #ifdef CONFIG_DEBUG_FS
131 struct dentry
*br_dbgaufs
; /* xino */
134 struct au_dr_br br_dirren
;
137 /* ---------------------------------------------------------------------- */
139 static inline struct vfsmount
*au_br_mnt(struct au_branch
*br
)
141 return br
->br_path
.mnt
;
144 static inline struct dentry
*au_br_dentry(struct au_branch
*br
)
146 return br
->br_path
.dentry
;
149 static inline struct super_block
*au_br_sb(struct au_branch
*br
)
151 return au_br_mnt(br
)->mnt_sb
;
154 static inline int au_br_rdonly(struct au_branch
*br
)
156 return (sb_rdonly(au_br_sb(br
))
157 || !au_br_writable(br
->br_perm
))
161 static inline int au_br_hnotifyable(int brperm __maybe_unused
)
163 #ifdef CONFIG_AUFS_HNOTIFY
164 return !(brperm
& AuBrPerm_RR
);
170 static inline int au_br_test_oflag(int oflag
, struct au_branch
*br
)
175 exec_flag
= oflag
& __FMODE_EXEC
;
176 if (unlikely(exec_flag
&& path_noexec(&br
->br_path
)))
182 static inline void au_xino_get(struct au_branch
*br
)
188 kref_get(&xi
->xi_kref
);
191 static inline int au_xino_count(struct au_branch
*br
)
199 v
= kref_read(&xi
->xi_kref
);
204 /* ---------------------------------------------------------------------- */
208 void au_br_free(struct au_sbinfo
*sinfo
);
209 int au_br_index(struct super_block
*sb
, aufs_bindex_t br_id
);
211 int au_br_add(struct super_block
*sb
, struct au_opt_add
*add
, int remount
);
213 int au_br_del(struct super_block
*sb
, struct au_opt_del
*del
, int remount
);
214 long au_ibusy_ioctl(struct file
*file
, unsigned long arg
);
216 long au_ibusy_compat_ioctl(struct file
*file
, unsigned long arg
);
219 int au_br_mod(struct super_block
*sb
, struct au_opt_mod
*mod
, int remount
,
222 int au_br_stfs(struct au_branch
*br
, struct aufs_stfs
*stfs
);
225 static const loff_t au_loff_max
= LLONG_MAX
;
227 aufs_bindex_t
au_xi_root(struct super_block
*sb
, struct dentry
*dentry
);
228 struct file
*au_xino_create(struct super_block
*sb
, char *fpath
, int silent
,
230 struct file
*au_xino_create2(struct super_block
*sb
, struct path
*base
,
231 struct file
*copy_src
);
233 struct au_xino
*xi
; /* switch between xino and xigen */
236 struct file
*copy_src
;
238 struct file
*au_xi_new(struct super_block
*sb
, struct au_xi_new
*xinew
);
240 int au_xino_read(struct super_block
*sb
, aufs_bindex_t bindex
, ino_t h_ino
,
242 int au_xino_write(struct super_block
*sb
, aufs_bindex_t bindex
, ino_t h_ino
,
244 ssize_t
xino_fread(vfs_readf_t func
, struct file
*file
, void *buf
, size_t size
,
246 ssize_t
xino_fwrite(vfs_writef_t func
, struct file
*file
, void *buf
,
247 size_t size
, loff_t
*pos
);
249 int au_xib_trunc(struct super_block
*sb
);
250 int au_xino_trunc(struct super_block
*sb
, aufs_bindex_t bindex
, int idx_begin
);
252 struct au_xino
*au_xino_alloc(unsigned int nfile
);
253 int au_xino_put(struct au_branch
*br
);
254 struct file
*au_xino_file1(struct au_xino
*xi
);
257 void au_xino_clr(struct super_block
*sb
);
258 int au_xino_set(struct super_block
*sb
, struct au_opt_xino
*xiopt
, int remount
);
259 struct file
*au_xino_def(struct super_block
*sb
);
260 int au_xino_init_br(struct super_block
*sb
, struct au_branch
*br
, ino_t hino
,
263 ino_t
au_xino_new_ino(struct super_block
*sb
);
264 void au_xino_delete_inode(struct inode
*inode
, const int unlinked
);
266 void au_xinondir_leave(struct super_block
*sb
, aufs_bindex_t bindex
,
267 ino_t h_ino
, int idx
);
268 int au_xinondir_enter(struct super_block
*sb
, aufs_bindex_t bindex
, ino_t h_ino
,
271 int au_xino_path(struct seq_file
*seq
, struct file
*file
);
273 /* ---------------------------------------------------------------------- */
275 /* @idx is signed to accept -1 meaning the first file */
276 static inline struct file
*au_xino_file(struct au_xino
*xi
, int idx
)
285 if (idx
< xi
->xi_nfile
)
286 file
= xi
->xi_file
[idx
];
288 file
= au_xino_file1(xi
);
294 /* ---------------------------------------------------------------------- */
296 /* Superblock to branch */
298 aufs_bindex_t
au_sbr_id(struct super_block
*sb
, aufs_bindex_t bindex
)
300 return au_sbr(sb
, bindex
)->br_id
;
304 struct vfsmount
*au_sbr_mnt(struct super_block
*sb
, aufs_bindex_t bindex
)
306 return au_br_mnt(au_sbr(sb
, bindex
));
310 struct super_block
*au_sbr_sb(struct super_block
*sb
, aufs_bindex_t bindex
)
312 return au_br_sb(au_sbr(sb
, bindex
));
315 static inline int au_sbr_perm(struct super_block
*sb
, aufs_bindex_t bindex
)
317 return au_sbr(sb
, bindex
)->br_perm
;
320 static inline int au_sbr_whable(struct super_block
*sb
, aufs_bindex_t bindex
)
322 return au_br_whable(au_sbr_perm(sb
, bindex
));
325 /* ---------------------------------------------------------------------- */
327 #define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
328 #define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
329 #define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
330 #define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
332 #define wbr_wh_read_trylock_nested(wbr) \
333 au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
334 #define wbr_wh_write_trylock_nested(wbr) \
335 au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
338 #define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
339 #define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
340 #define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
342 #define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
343 #define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
344 #define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
346 /* ---------------------------------------------------------------------- */
348 #ifdef CONFIG_AUFS_FHSM
349 static inline void au_br_fhsm_init(struct au_br_fhsm
*brfhsm
)
351 mutex_init(&brfhsm
->bf_lock
);
352 brfhsm
->bf_jiffy
= 0;
353 brfhsm
->bf_readable
= 0;
356 static inline void au_br_fhsm_fin(struct au_br_fhsm
*brfhsm
)
358 mutex_destroy(&brfhsm
->bf_lock
);
361 AuStubVoid(au_br_fhsm_init
, struct au_br_fhsm
*brfhsm
)
362 AuStubVoid(au_br_fhsm_fin
, struct au_br_fhsm
*brfhsm
)
365 #endif /* __KERNEL__ */
366 #endif /* __AUFS_BRANCH_H__ */