]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - fs/aufs/branch.h
1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2005-2021 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 user_namespace
*au_br_userns(struct au_branch
*br
)
151 return mnt_user_ns(br
->br_path
.mnt
);
154 static inline struct super_block
*au_br_sb(struct au_branch
*br
)
156 return au_br_mnt(br
)->mnt_sb
;
159 static inline int au_br_rdonly(struct au_branch
*br
)
161 return (sb_rdonly(au_br_sb(br
))
162 || !au_br_writable(br
->br_perm
))
166 static inline int au_br_hnotifyable(int brperm __maybe_unused
)
168 #ifdef CONFIG_AUFS_HNOTIFY
169 return !(brperm
& AuBrPerm_RR
);
175 static inline int au_br_test_oflag(int oflag
, struct au_branch
*br
)
180 exec_flag
= oflag
& __FMODE_EXEC
;
181 if (unlikely(exec_flag
&& path_noexec(&br
->br_path
)))
187 static inline void au_xino_get(struct au_branch
*br
)
193 kref_get(&xi
->xi_kref
);
196 static inline int au_xino_count(struct au_branch
*br
)
204 v
= kref_read(&xi
->xi_kref
);
209 /* ---------------------------------------------------------------------- */
213 void au_br_free(struct au_sbinfo
*sinfo
);
214 int au_br_index(struct super_block
*sb
, aufs_bindex_t br_id
);
216 int au_br_add(struct super_block
*sb
, struct au_opt_add
*add
, int remount
);
218 int au_br_del(struct super_block
*sb
, struct au_opt_del
*del
, int remount
);
219 long au_ibusy_ioctl(struct file
*file
, unsigned long arg
);
221 long au_ibusy_compat_ioctl(struct file
*file
, unsigned long arg
);
224 int au_br_mod(struct super_block
*sb
, struct au_opt_mod
*mod
, int remount
,
227 int au_br_stfs(struct au_branch
*br
, struct aufs_stfs
*stfs
);
230 static const loff_t au_loff_max
= LLONG_MAX
;
232 aufs_bindex_t
au_xi_root(struct super_block
*sb
, struct dentry
*dentry
);
233 struct file
*au_xino_create(struct super_block
*sb
, char *fpath
, int silent
,
235 struct file
*au_xino_create2(struct super_block
*sb
, struct path
*base
,
236 struct file
*copy_src
);
238 struct au_xino
*xi
; /* switch between xino and xigen */
241 struct file
*copy_src
;
243 struct file
*au_xi_new(struct super_block
*sb
, struct au_xi_new
*xinew
);
245 int au_xino_read(struct super_block
*sb
, aufs_bindex_t bindex
, ino_t h_ino
,
247 int au_xino_write(struct super_block
*sb
, aufs_bindex_t bindex
, ino_t h_ino
,
249 ssize_t
xino_fread(struct file
*file
, void *buf
, size_t size
, loff_t
*pos
);
250 ssize_t
xino_fwrite(struct file
*file
, void *buf
, size_t size
, loff_t
*pos
);
252 int au_xib_trunc(struct super_block
*sb
);
253 int au_xino_trunc(struct super_block
*sb
, aufs_bindex_t bindex
, int idx_begin
);
255 struct au_xino
*au_xino_alloc(unsigned int nfile
);
256 int au_xino_put(struct au_branch
*br
);
257 struct file
*au_xino_file1(struct au_xino
*xi
);
260 void au_xino_clr(struct super_block
*sb
);
261 int au_xino_set(struct super_block
*sb
, struct au_opt_xino
*xiopt
, int remount
);
262 struct file
*au_xino_def(struct super_block
*sb
);
263 int au_xino_init_br(struct super_block
*sb
, struct au_branch
*br
, ino_t hino
,
266 ino_t
au_xino_new_ino(struct super_block
*sb
);
267 void au_xino_delete_inode(struct inode
*inode
, const int unlinked
);
269 void au_xinondir_leave(struct super_block
*sb
, aufs_bindex_t bindex
,
270 ino_t h_ino
, int idx
);
271 int au_xinondir_enter(struct super_block
*sb
, aufs_bindex_t bindex
, ino_t h_ino
,
274 int au_xino_path(struct seq_file
*seq
, struct file
*file
);
276 /* ---------------------------------------------------------------------- */
278 /* @idx is signed to accept -1 meaning the first file */
279 static inline struct file
*au_xino_file(struct au_xino
*xi
, int idx
)
288 if (idx
< xi
->xi_nfile
)
289 file
= xi
->xi_file
[idx
];
291 file
= au_xino_file1(xi
);
297 /* ---------------------------------------------------------------------- */
299 /* Superblock to branch */
301 aufs_bindex_t
au_sbr_id(struct super_block
*sb
, aufs_bindex_t bindex
)
303 return au_sbr(sb
, bindex
)->br_id
;
307 struct vfsmount
*au_sbr_mnt(struct super_block
*sb
, aufs_bindex_t bindex
)
309 return au_br_mnt(au_sbr(sb
, bindex
));
313 struct user_namespace
*au_sbr_userns(struct super_block
*sb
, aufs_bindex_t bindex
)
315 return au_br_userns(au_sbr(sb
, bindex
));
319 struct super_block
*au_sbr_sb(struct super_block
*sb
, aufs_bindex_t bindex
)
321 return au_br_sb(au_sbr(sb
, bindex
));
324 static inline int au_sbr_perm(struct super_block
*sb
, aufs_bindex_t bindex
)
326 return au_sbr(sb
, bindex
)->br_perm
;
329 static inline int au_sbr_whable(struct super_block
*sb
, aufs_bindex_t bindex
)
331 return au_br_whable(au_sbr_perm(sb
, bindex
));
334 /* ---------------------------------------------------------------------- */
336 #define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
337 #define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
338 #define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
339 #define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
341 #define wbr_wh_read_trylock_nested(wbr) \
342 au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
343 #define wbr_wh_write_trylock_nested(wbr) \
344 au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
347 #define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
348 #define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
349 #define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
351 #define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
352 #define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
353 #define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
355 /* ---------------------------------------------------------------------- */
357 #ifdef CONFIG_AUFS_FHSM
358 static inline void au_br_fhsm_init(struct au_br_fhsm
*brfhsm
)
360 mutex_init(&brfhsm
->bf_lock
);
361 brfhsm
->bf_jiffy
= 0;
362 brfhsm
->bf_readable
= 0;
365 static inline void au_br_fhsm_fin(struct au_br_fhsm
*brfhsm
)
367 mutex_destroy(&brfhsm
->bf_lock
);
370 AuStubVoid(au_br_fhsm_init
, struct au_br_fhsm
*brfhsm
)
371 AuStubVoid(au_br_fhsm_fin
, struct au_br_fhsm
*brfhsm
)
374 #endif /* __KERNEL__ */
375 #endif /* __AUFS_BRANCH_H__ */