2
* Copyright (C) 2007-2008 Junjiro 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, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
* $Id: plink.c,v 1.2 2008/04/21 01:45:16 sfjro Exp $
28
struct list_head list;
32
#ifdef CONFIG_AUFS_DEBUG
33
void au_plink_list(struct super_block *sb)
35
struct au_sbinfo *sbinfo;
36
struct list_head *plink_list;
37
struct pseudo_link *plink;
42
AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
44
plink_list = &sbinfo->si_plink;
45
spin_lock(&sbinfo->si_plink_lock);
46
list_for_each_entry(plink, plink_list, list)
47
AuDbg("%lu\n", plink->inode->i_ino);
48
spin_unlock(&sbinfo->si_plink_lock);
52
int au_plink_test(struct super_block *sb, struct inode *inode)
55
struct au_sbinfo *sbinfo;
56
struct list_head *plink_list;
57
struct pseudo_link *plink;
59
LKTRTrace("i%lu\n", inode->i_ino);
62
AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
65
plink_list = &sbinfo->si_plink;
66
spin_lock(&sbinfo->si_plink_lock);
67
list_for_each_entry(plink, plink_list, list)
68
if (plink->inode == inode) {
72
spin_unlock(&sbinfo->si_plink_lock);
76
/* 20 is max digits length of ulong 64 */
77
#define PLINK_NAME_LEN ((20 + 1) * 2)
79
static int plink_name(char *name, int len, struct inode *inode,
83
struct inode *h_inode;
85
LKTRTrace("i%lu, b%d\n", inode->i_ino, bindex);
86
AuDebugOn(len != PLINK_NAME_LEN);
87
h_inode = au_h_iptr(inode, bindex);
89
rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
90
AuDebugOn(rlen >= len);
94
struct dentry *au_plink_lkup(struct super_block *sb, aufs_bindex_t bindex,
97
struct dentry *h_dentry, *h_parent;
100
char tgtname[PLINK_NAME_LEN];
102
struct au_ndx ndx = {
108
LKTRTrace("b%d, i%lu\n", bindex, inode->i_ino);
109
br = au_sbr(sb, bindex);
110
h_parent = br->br_plink;
111
AuDebugOn(!h_parent);
112
h_dir = h_parent->d_inode;
115
len = plink_name(tgtname, sizeof(tgtname), inode, bindex);
117
/* always superio. */
118
ndx.nfsmnt = au_do_nfsmnt(br->br_mnt);
120
if (unlikely(au_opt_test_dlgt(au_mntflags(sb))))
121
au_fset_ndx(ndx.flags, DLGT);
123
mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
124
h_dentry = au_sio_lkup_one(tgtname, h_parent, len, &ndx);
125
mutex_unlock(&h_dir->i_mutex);
129
static int do_whplink(char *tgt, int len, struct dentry *h_parent,
130
struct dentry *h_dentry, struct vfsmount *nfsmnt,
131
struct super_block *sb)
134
struct dentry *h_tgt;
136
struct vfsub_args vargs;
137
struct au_ndx ndx = {
144
dlgt = !!au_opt_test_dlgt(au_mntflags(sb));
146
au_fset_ndx(ndx.flags, DLGT);
147
h_tgt = au_lkup_one(tgt, h_parent, len, &ndx);
148
err = PTR_ERR(h_tgt);
153
vfsub_args_init(&vargs, NULL, dlgt, 0);
154
h_dir = h_parent->d_inode;
155
if (unlikely(h_tgt->d_inode && h_tgt->d_inode != h_dentry->d_inode))
156
err = vfsub_unlink(h_dir, h_tgt, &vargs);
157
if (!err && !h_tgt->d_inode) {
158
err = vfsub_link(h_dentry, h_dir, h_tgt, dlgt);
168
struct do_whplink_args {
172
struct dentry *h_parent;
173
struct dentry *h_dentry;
174
struct vfsmount *nfsmnt;
175
struct super_block *sb;
178
static void call_do_whplink(void *args)
180
struct do_whplink_args *a = args;
181
*a->errp = do_whplink(a->tgt, a->len, a->h_parent, a->h_dentry,
185
static int whplink(struct dentry *h_dentry, struct inode *inode,
186
aufs_bindex_t bindex, struct super_block *sb)
188
int err, len, wkq_err;
189
struct au_branch *br;
190
struct dentry *h_parent;
192
char tgtname[PLINK_NAME_LEN];
194
LKTRTrace("%.*s\n", AuDLNPair(h_dentry));
195
br = au_sbr(inode->i_sb, bindex);
196
h_parent = br->br_plink;
197
AuDebugOn(!h_parent);
198
h_dir = h_parent->d_inode;
201
len = plink_name(tgtname, sizeof(tgtname), inode, bindex);
203
/* always superio. */
204
mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
205
if (!au_test_wkq(current)) {
206
struct do_whplink_args args = {
210
.h_parent = h_parent,
211
.h_dentry = h_dentry,
212
.nfsmnt = au_do_nfsmnt(br->br_mnt),
215
wkq_err = au_wkq_wait(call_do_whplink, &args, /*dlgt*/0);
216
if (unlikely(wkq_err))
219
err = do_whplink(tgtname, len, h_parent, h_dentry,
220
au_do_nfsmnt(br->br_mnt), sb);
221
mutex_unlock(&h_dir->i_mutex);
227
void au_plink_append(struct super_block *sb, struct inode *inode,
228
struct dentry *h_dentry, aufs_bindex_t bindex)
230
struct au_sbinfo *sbinfo;
231
struct list_head *plink_list;
232
struct pseudo_link *plink;
235
LKTRTrace("i%lu\n", inode->i_ino);
238
AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
242
plink_list = &sbinfo->si_plink;
243
spin_lock(&sbinfo->si_plink_lock);
244
list_for_each_entry(plink, plink_list, list) {
246
if (plink->inode == inode) {
254
plink = kmalloc(sizeof(*plink), GFP_ATOMIC);
256
plink->inode = igrab(inode);
257
list_add(&plink->list, plink_list);
262
spin_unlock(&sbinfo->si_plink_lock);
265
err = whplink(h_dentry, inode, bindex, sb);
267
if (unlikely(cnt > AUFS_PLINK_WARN))
268
AuWarn1("unexpectedly many pseudo links, %d\n", cnt);
270
AuWarn("err %d, damaged pseudo link. ignored.\n", err);
273
static void do_put_plink(struct pseudo_link *plink, int do_del)
279
list_del(&plink->list);
283
void au_plink_put(struct super_block *sb)
285
struct au_sbinfo *sbinfo;
286
struct list_head *plink_list;
287
struct pseudo_link *plink, *tmp;
292
AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
294
plink_list = &sbinfo->si_plink;
295
//spin_lock(&sbinfo->si_plink_lock);
296
list_for_each_entry_safe(plink, tmp, plink_list, list)
297
do_put_plink(plink, 0);
298
INIT_LIST_HEAD(plink_list);
299
//spin_unlock(&sbinfo->si_plink_lock);
302
void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
304
struct au_sbinfo *sbinfo;
305
struct list_head *plink_list;
306
struct pseudo_link *plink, *tmp;
308
aufs_bindex_t bstart, bend, bindex;
314
AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
316
plink_list = &sbinfo->si_plink;
317
//spin_lock(&sbinfo->si_plink_lock);
318
list_for_each_entry_safe(plink, tmp, plink_list, list) {
320
inode = igrab(plink->inode);
321
ii_write_lock_child(inode);
322
bstart = au_ibstart(inode);
323
bend = au_ibend(inode);
325
for (bindex = bstart; bindex <= bend; bindex++) {
326
if (!au_h_iptr(inode, bindex)
327
|| au_ii_br_id(inode, bindex) != br_id)
329
au_set_h_iptr(inode, bindex, NULL, 0);
334
do_put_plink(plink, 1);
337
for (bindex = bstart; bindex <= bend; bindex++)
338
if (au_h_iptr(inode, bindex)) {
343
do_put_plink(plink, 1);
345
ii_write_unlock(inode);
348
//spin_unlock(&sbinfo->si_plink_lock);