]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - fs/aufs/iinfo.c
2 * Copyright (C) 2005-2017 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/>.
24 struct inode
*au_h_iptr(struct inode
*inode
, aufs_bindex_t bindex
)
26 struct inode
*h_inode
;
27 struct au_hinode
*hinode
;
31 hinode
= au_hinode(au_ii(inode
), bindex
);
32 h_inode
= hinode
->hi_inode
;
33 AuDebugOn(h_inode
&& atomic_read(&h_inode
->i_count
) <= 0);
37 /* todo: hard/soft set? */
38 void au_hiput(struct au_hinode
*hinode
)
41 dput(hinode
->hi_whdentry
);
42 iput(hinode
->hi_inode
);
45 unsigned int au_hi_flags(struct inode
*inode
, int isdir
)
48 const unsigned int mnt_flags
= au_mntflags(inode
->i_sb
);
51 if (au_opt_test(mnt_flags
, XINO
))
52 au_fset_hi(flags
, XINO
);
53 if (isdir
&& au_opt_test(mnt_flags
, UDBA_HNOTIFY
))
54 au_fset_hi(flags
, HNOTIFY
);
58 void au_set_h_iptr(struct inode
*inode
, aufs_bindex_t bindex
,
59 struct inode
*h_inode
, unsigned int flags
)
61 struct au_hinode
*hinode
;
63 struct au_iinfo
*iinfo
= au_ii(inode
);
65 IiMustWriteLock(inode
);
67 hinode
= au_hinode(iinfo
, bindex
);
68 hi
= hinode
->hi_inode
;
69 AuDebugOn(h_inode
&& atomic_read(&h_inode
->i_count
) <= 0);
73 hinode
->hi_inode
= h_inode
;
76 struct super_block
*sb
= inode
->i_sb
;
79 AuDebugOn(inode
->i_mode
80 && (h_inode
->i_mode
& S_IFMT
)
81 != (inode
->i_mode
& S_IFMT
));
82 if (bindex
== iinfo
->ii_btop
)
83 au_cpup_igen(inode
, h_inode
);
84 br
= au_sbr(sb
, bindex
);
85 hinode
->hi_id
= br
->br_id
;
86 if (au_ftest_hi(flags
, XINO
)) {
87 err
= au_xino_write(sb
, bindex
, h_inode
->i_ino
,
90 AuIOErr1("failed au_xino_write() %d\n", err
);
93 if (au_ftest_hi(flags
, HNOTIFY
)
94 && au_br_hnotifyable(br
->br_perm
)) {
95 err
= au_hn_alloc(hinode
, inode
);
97 AuIOErr1("au_hn_alloc() %d\n", err
);
102 void au_set_hi_wh(struct inode
*inode
, aufs_bindex_t bindex
,
105 struct au_hinode
*hinode
;
107 IiMustWriteLock(inode
);
109 hinode
= au_hinode(au_ii(inode
), bindex
);
110 AuDebugOn(hinode
->hi_whdentry
);
111 hinode
->hi_whdentry
= h_wh
;
114 void au_update_iigen(struct inode
*inode
, int half
)
116 struct au_iinfo
*iinfo
;
117 struct au_iigen
*iigen
;
120 sigen
= au_sigen(inode
->i_sb
);
121 iinfo
= au_ii(inode
);
122 iigen
= &iinfo
->ii_generation
;
123 spin_lock(&iigen
->ig_spin
);
124 iigen
->ig_generation
= sigen
;
126 au_ig_fset(iigen
->ig_flags
, HALF_REFRESHED
);
128 au_ig_fclr(iigen
->ig_flags
, HALF_REFRESHED
);
129 spin_unlock(&iigen
->ig_spin
);
132 /* it may be called at remount time, too */
133 void au_update_ibrange(struct inode
*inode
, int do_put_zero
)
135 struct au_iinfo
*iinfo
;
136 aufs_bindex_t bindex
, bbot
;
138 AuDebugOn(au_is_bad_inode(inode
));
139 IiMustWriteLock(inode
);
141 iinfo
= au_ii(inode
);
142 if (do_put_zero
&& iinfo
->ii_btop
>= 0) {
143 for (bindex
= iinfo
->ii_btop
; bindex
<= iinfo
->ii_bbot
;
147 h_i
= au_hinode(iinfo
, bindex
)->hi_inode
;
150 && !(h_i
->i_state
& I_LINKABLE
))
151 au_set_h_iptr(inode
, bindex
, NULL
, 0);
157 bbot
= au_sbbot(inode
->i_sb
);
158 for (bindex
= 0; bindex
<= bbot
; bindex
++)
159 if (au_hinode(iinfo
, bindex
)->hi_inode
) {
160 iinfo
->ii_btop
= bindex
;
163 if (iinfo
->ii_btop
>= 0)
164 for (bindex
= bbot
; bindex
>= iinfo
->ii_btop
; bindex
--)
165 if (au_hinode(iinfo
, bindex
)->hi_inode
) {
166 iinfo
->ii_bbot
= bindex
;
169 AuDebugOn(iinfo
->ii_btop
> iinfo
->ii_bbot
);
172 /* ---------------------------------------------------------------------- */
174 void au_icntnr_init_once(void *_c
)
176 struct au_icntnr
*c
= _c
;
177 struct au_iinfo
*iinfo
= &c
->iinfo
;
179 spin_lock_init(&iinfo
->ii_generation
.ig_spin
);
180 au_rw_init(&iinfo
->ii_rwsem
);
181 inode_init_once(&c
->vfs_inode
);
184 void au_hinode_init(struct au_hinode
*hinode
)
186 hinode
->hi_inode
= NULL
;
189 hinode
->hi_whdentry
= NULL
;
192 int au_iinfo_init(struct inode
*inode
)
194 struct au_iinfo
*iinfo
;
195 struct super_block
*sb
;
196 struct au_hinode
*hi
;
200 iinfo
= &(container_of(inode
, struct au_icntnr
, vfs_inode
)->iinfo
);
201 nbr
= au_sbbot(sb
) + 1;
202 if (unlikely(nbr
<= 0))
204 hi
= kmalloc_array(nbr
, sizeof(*iinfo
->ii_hinode
), GFP_NOFS
);
208 iinfo
->ii_hinode
= hi
;
209 for (i
= 0; i
< nbr
; i
++, hi
++)
212 iinfo
->ii_generation
.ig_generation
= au_sigen(sb
);
215 iinfo
->ii_vdir
= NULL
;
221 int au_hinode_realloc(struct au_iinfo
*iinfo
, int nbr
, int may_shrink
)
224 struct au_hinode
*hip
;
226 AuRwMustWriteLock(&iinfo
->ii_rwsem
);
229 hip
= au_krealloc(iinfo
->ii_hinode
, sizeof(*hip
) * nbr
, GFP_NOFS
,
232 iinfo
->ii_hinode
= hip
;
233 i
= iinfo
->ii_bbot
+ 1;
235 for (; i
< nbr
; i
++, hip
++)
243 void au_iinfo_fin(struct inode
*inode
)
245 struct au_iinfo
*iinfo
;
246 struct au_hinode
*hi
;
247 struct super_block
*sb
;
248 aufs_bindex_t bindex
, bbot
;
249 const unsigned char unlinked
= !inode
->i_nlink
;
251 AuDebugOn(au_is_bad_inode(inode
));
256 au_xino_delete_inode(inode
, unlinked
);
259 * it is safe to hide the dependency between sbinfo and
263 si_noflush_read_lock(sb
);
264 au_xino_delete_inode(inode
, unlinked
);
269 iinfo
= au_ii(inode
);
271 au_vdir_free(iinfo
->ii_vdir
);
273 bindex
= iinfo
->ii_btop
;
275 hi
= au_hinode(iinfo
, bindex
);
276 bbot
= iinfo
->ii_bbot
;
277 while (bindex
++ <= bbot
) {
283 kfree(iinfo
->ii_hinode
);
284 AuRwDestroy(&iinfo
->ii_rwsem
);