]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - fs/aufs/finfo.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/>.
24 void au_hfput(struct au_hfile
*hf
, int execed
)
27 allow_write_access(hf
->hf_file
);
34 void au_set_h_fptr(struct file
*file
, aufs_bindex_t bindex
, struct file
*val
)
36 struct au_finfo
*finfo
= au_fi(file
);
38 struct au_fidir
*fidir
;
40 fidir
= finfo
->fi_hdir
;
42 AuDebugOn(finfo
->fi_btop
!= bindex
);
45 hf
= fidir
->fd_hfile
+ bindex
;
47 if (hf
&& hf
->hf_file
)
48 au_hfput(hf
, vfsub_file_execed(file
));
50 FiMustWriteLock(file
);
51 AuDebugOn(IS_ERR_OR_NULL(file
->f_path
.dentry
));
53 hf
->hf_br
= au_sbr(file
->f_path
.dentry
->d_sb
, bindex
);
57 void au_update_figen(struct file
*file
)
59 atomic_set(&au_fi(file
)->fi_generation
, au_digen(file
->f_path
.dentry
));
60 /* smp_mb(); */ /* atomic_set */
63 /* ---------------------------------------------------------------------- */
65 struct au_fidir
*au_fidir_alloc(struct super_block
*sb
)
67 struct au_fidir
*fidir
;
70 nbr
= au_sbbot(sb
) + 1;
72 nbr
= 2; /* initial allocate for 2 branches */
73 fidir
= kzalloc(au_fidir_sz(nbr
), GFP_NOFS
);
82 int au_fidir_realloc(struct au_finfo
*finfo
, int nbr
, int may_shrink
)
85 struct au_fidir
*fidir
, *p
;
87 AuRwMustWriteLock(&finfo
->fi_rwsem
);
88 fidir
= finfo
->fi_hdir
;
92 p
= au_kzrealloc(fidir
, au_fidir_sz(fidir
->fd_nent
), au_fidir_sz(nbr
),
93 GFP_NOFS
, may_shrink
);
103 /* ---------------------------------------------------------------------- */
105 void au_finfo_fin(struct file
*file
, int atonce
)
107 struct au_finfo
*finfo
;
109 au_nfiles_dec(file
->f_path
.dentry
->d_sb
);
112 AuDebugOn(finfo
->fi_hdir
);
113 AuRwDestroy(&finfo
->fi_rwsem
);
115 au_cache_dfree_finfo(finfo
);
117 au_cache_free_finfo(finfo
);
120 void au_fi_init_once(void *_finfo
)
122 struct au_finfo
*finfo
= _finfo
;
124 au_rw_init(&finfo
->fi_rwsem
);
127 int au_finfo_init(struct file
*file
, struct au_fidir
*fidir
)
130 struct au_finfo
*finfo
;
131 struct dentry
*dentry
;
134 dentry
= file
->f_path
.dentry
;
135 finfo
= au_cache_alloc_finfo();
136 if (unlikely(!finfo
))
140 au_nfiles_inc(dentry
->d_sb
);
141 au_rw_write_lock(&finfo
->fi_rwsem
);
143 finfo
->fi_hdir
= fidir
;
144 atomic_set(&finfo
->fi_generation
, au_digen(dentry
));
145 /* smp_mb(); */ /* atomic_set */
147 file
->private_data
= finfo
;