~ubuntu-branches/ubuntu/vivid/aufs/vivid

« back to all changes in this revision

Viewing changes to fs/aufs/dentry.c

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2007-12-15 23:32:51 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20071215233251-2vgs2lmg8mai5d9e
Tags: 0+20071211-1ubuntu1
* Merge from debian unstable (LP: #175705), remaining changes:
  - Fix for Ubuntu Kernels (updated)
* patches/01_vserver.dpatch: Removed
* patches/06_ubuntu.dpatch: Added (update of ubuntu patch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 */
18
18
 
19
 
/* $Id: dentry.c,v 1.44 2007/06/04 02:17:34 sfjro Exp $ */
 
19
/* $Id: dentry.c,v 1.64 2007/12/03 01:37:50 sfjro Exp $ */
20
20
 
21
21
//#include <linux/fs.h>
22
22
//#include <linux/namei.h>
23
23
#include "aufs.h"
24
24
 
25
 
#ifdef CONFIG_AUFS_LHASH_PATCH
 
25
#if 0
 
26
/* subset of nameidata */
 
27
struct au_ndsub {
 
28
        struct dentry   *dentry;
 
29
        struct vfsmount *mnt;
 
30
        unsigned int    flags;
 
31
 
 
32
        union {
 
33
                struct open_intent open;
 
34
        } intent;
 
35
};
 
36
 
 
37
static void au_ndsub_restore(struct nameidata *nd, struct au_ndsub *save)
 
38
{
 
39
        nd->dentry = save->dentry;
 
40
        nd->mnt = save->mnt;
 
41
        nd->flags = save->flags;
 
42
        nd->intent = save->intent;
 
43
}
 
44
#endif
 
45
 
 
46
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) \
 
47
        && !defined(AuNoNfsBranch)
 
48
static int au_fake_intent(/* struct au_ndsub *save,  */struct nameidata *nd, int perm)
 
49
{
 
50
        int err;
 
51
 
 
52
        LKTRTrace("perm %d\n", perm);
 
53
 
 
54
        err = 0;
 
55
#if 0
 
56
        save->dentry = nd->dentry;
 
57
        save->mnt = nd->mnt;
 
58
        save->flags = nd->flags;
 
59
        save->intent = nd->intent;
 
60
#endif
 
61
 
 
62
        nd->intent.open.file = NULL;
 
63
        if (nd->flags & LOOKUP_OPEN) {
 
64
                err = -ENFILE;
 
65
                nd->intent.open.file = get_empty_filp();
 
66
                if (unlikely(!nd->intent.open.file)) {
 
67
                        //nd->intent.open.file = save->intent.open.file;
 
68
                        goto out;
 
69
                }
 
70
 
 
71
                err = 0;
 
72
                if (!br_writable(perm)) {
 
73
                        nd->intent.open.flags = au_file_roflags
 
74
                                (nd->intent.open.flags) | FMODE_READ;
 
75
                        nd->flags &= ~LOOKUP_CREATE;
 
76
                }
 
77
        }
 
78
 
 
79
 out:
 
80
        AuTraceErr(err);
 
81
        return err;
 
82
}
 
83
 
 
84
static int au_hin_after_reval(struct nameidata *nd, struct dentry *dentry,
 
85
                              aufs_bindex_t bindex, struct file *file)
 
86
{
 
87
        int err;
 
88
 
 
89
        LKTRTrace("nd %p, %.*s, b%d, f %d\n",
 
90
                  nd, AuDLNPair(dentry), bindex, !!file);
 
91
 
 
92
        err = 0;
 
93
        if ((nd->flags & LOOKUP_OPEN)
 
94
            && nd->intent.open.file
 
95
            && !IS_ERR(nd->intent.open.file)) {
 
96
                if (nd->intent.open.file->f_dentry) {
 
97
                        //AuDbgFile(nd->intent.open.file);
 
98
                        err = au_set_h_intent(dentry, bindex, file,
 
99
                                              nd->intent.open.file);
 
100
                        if (!err)
 
101
                                nd->intent.open.file = NULL;
 
102
                }
 
103
                if (unlikely(nd->intent.open.file))
 
104
                        put_filp(nd->intent.open.file);
 
105
        }
 
106
 
 
107
        return err;
 
108
}
26
109
 
27
110
#ifdef CONFIG_AUFS_DLGT
28
 
struct lookup_hash_args {
 
111
struct au_lookup_hash_args {
29
112
        struct dentry **errp;
30
113
        struct qstr *name;
31
114
        struct dentry *base;
32
115
        struct nameidata *nd;
33
116
};
34
117
 
35
 
static void call_lookup_hash(void *args)
 
118
static void au_call_lookup_hash(void *args)
36
119
{
37
 
        struct lookup_hash_args *a = args;
38
 
        *a->errp = __lookup_hash(a->name, a->base, a->nd);
 
120
        struct au_lookup_hash_args *a = args;
 
121
        *a->errp = vfsub__lookup_hash(a->name, a->base, a->nd);
39
122
}
40
123
#endif /* CONFIG_AUFS_DLGT */
41
124
 
42
 
static struct dentry *lkup_hash(const char *name, struct dentry *parent,
43
 
                                int len, struct lkup_args *lkup)
 
125
static struct dentry *au_lkup_hash(const char *name, struct dentry *parent,
 
126
                                   int len, struct aufs_ndx *ndx)
44
127
{
45
128
        struct dentry *dentry;
46
129
        char *p;
47
130
        unsigned long hash;
48
131
        struct qstr this;
49
132
        unsigned int c;
50
 
        struct nameidata tmp_nd;
 
133
        struct nameidata tmp_nd, *ndo;
 
134
        int err;
51
135
 
52
136
        dentry = ERR_PTR(-EACCES);
53
137
        this.name = name;
55
139
        if (unlikely(!len))
56
140
                goto out;
57
141
 
58
 
        p = (void*)name;
 
142
        p = (void *)name;
59
143
        hash = init_name_hash();
60
144
        while (len--) {
61
145
                c = *p++;
65
149
        }
66
150
        this.hash = end_name_hash(hash);
67
151
 
68
 
        memset(&tmp_nd, 0, sizeof(tmp_nd));
 
152
        ndo = ndx->nd;
 
153
        if (ndo) {
 
154
                tmp_nd = *ndo;
 
155
                err = au_fake_intent(&tmp_nd, ndx->br->br_perm);
 
156
                dentry = ERR_PTR(err);
 
157
                if (unlikely(err))
 
158
                        goto out_intent;
 
159
        } else
 
160
                memset(&tmp_nd, 0, sizeof(tmp_nd));
 
161
 
69
162
        tmp_nd.dentry = dget(parent);
70
 
        tmp_nd.mnt = mntget(lkup->nfsmnt);
 
163
        tmp_nd.mnt = mntget(ndx->nfsmnt);
71
164
#ifndef CONFIG_AUFS_DLGT
72
 
        dentry = __lookup_hash(&this, parent, &tmp_nd);
 
165
        dentry = vfsub__lookup_hash(&this, parent, &tmp_nd);
73
166
#else
74
 
        if (!lkup->dlgt)
75
 
                dentry = __lookup_hash(&this, parent, &tmp_nd);
 
167
        if (!ndx->dlgt)
 
168
                dentry = vfsub__lookup_hash(&this, parent, &tmp_nd);
76
169
        else {
77
170
                int wkq_err;
78
 
                struct lookup_hash_args args = {
 
171
                struct au_lookup_hash_args args = {
79
172
                        .errp   = &dentry,
80
173
                        .name   = &this,
81
174
                        .base   = parent,
82
175
                        .nd     = &tmp_nd
83
176
                };
84
 
                wkq_err = au_wkq_wait(call_lookup_hash, &args, /*dlgt*/1);
 
177
                wkq_err = au_wkq_wait(au_call_lookup_hash, &args, /*dlgt*/1);
85
178
                if (unlikely(wkq_err))
86
179
                        dentry = ERR_PTR(wkq_err);
87
180
        }
88
 
#endif
 
181
#endif /* CONFIG_AUFS_DLGT */
 
182
        if (0 && !IS_ERR(dentry))
 
183
                AuDbgDentry(dentry);
 
184
        if (!IS_ERR(dentry)) {
 
185
                /* why negative dentry for a new dir was unhashed? */
 
186
                if (unlikely(d_unhashed(dentry)))
 
187
                        d_rehash(dentry);
 
188
                if (tmp_nd.intent.open.file
 
189
                    && tmp_nd.intent.open.file->f_dentry) {
 
190
                        //AuDbgFile(tmp_nd.intent.open.file);
 
191
                        ndx->nd_file = tmp_nd.intent.open.file;
 
192
                        tmp_nd.intent.open.file = NULL;
 
193
                        //br_get(ndx->br);
 
194
                }
 
195
        }
89
196
        path_release(&tmp_nd);
90
197
 
 
198
 out_intent:
 
199
        if (tmp_nd.intent.open.file)
 
200
                put_filp(tmp_nd.intent.open.file);
91
201
 out:
92
 
        TraceErrPtr(dentry);
 
202
        AuTraceErrPtr(dentry);
93
203
        return dentry;
94
204
}
95
 
#elif defined(CONFIG_AUFS_DLGT)
96
 
static struct dentry *lkup_hash(const char *name, struct dentry *parent,
97
 
                                int len, struct lkup_args *lkup)
 
205
#else
 
206
static int au_fake_intent(struct nameidata *nd, int perm)
 
207
{
 
208
        return 0;
 
209
}
 
210
 
 
211
static int au_hin_after_reval(struct nameidata *nd, struct dentry *dentry,
 
212
                              aufs_bindex_t bindex, struct file *file)
 
213
{
 
214
        return 0;
 
215
}
 
216
 
 
217
#if !defined(AuNoNfsBranch) || defined(CONFIG_AUFS_DLGT)
 
218
static struct dentry *au_lkup_hash(const char *name, struct dentry *parent,
 
219
                                   int len, struct aufs_ndx *ndx)
98
220
{
99
221
        return ERR_PTR(-ENOSYS);
100
222
}
101
223
#endif
 
224
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) && !AuNoNfsBranch */
 
225
 
 
226
/* ---------------------------------------------------------------------- */
 
227
 
 
228
#if !defined(AuNoNfsBranch) || defined(CONFIG_AUFS_DLGT)
102
229
 
103
230
#ifdef CONFIG_AUFS_DLGT
104
 
struct lookup_one_len_args {
 
231
struct au_lookup_one_len_args {
105
232
        struct dentry **errp;
106
233
        const char *name;
107
234
        struct dentry *parent;
108
235
        int len;
109
236
};
110
237
 
111
 
static void call_lookup_one_len(void *args)
 
238
static void au_call_lookup_one_len(void *args)
112
239
{
113
 
        struct lookup_one_len_args *a = args;
114
 
        *a->errp = lookup_one_len(a->name, a->parent, a->len);
 
240
        struct au_lookup_one_len_args *a = args;
 
241
        *a->errp = vfsub_lookup_one_len(a->name, a->parent, a->len);
115
242
}
116
243
#endif /* CONFIG_AUFS_DLGT */
117
244
 
118
 
#if defined(CONFIG_AUFS_LHASH_PATCH) || defined(CONFIG_AUFS_DLGT)
119
245
/* cf. lookup_one_len() in linux/fs/namei.c */
120
 
struct dentry *lkup_one(const char *name, struct dentry *parent, int len,
121
 
                        struct lkup_args *lkup)
 
246
struct dentry *au_lkup_one(const char *name, struct dentry *parent, int len,
 
247
                           struct aufs_ndx *ndx)
122
248
{
123
249
        struct dentry *dentry;
124
250
 
125
 
        LKTRTrace("%.*s/%.*s, lkup{%p, %d}\n",
126
 
                  DLNPair(parent), len, name, lkup->nfsmnt, lkup->dlgt);
 
251
        LKTRTrace("%.*s/%.*s, ndx{%d, %d}\n",
 
252
                  AuDLNPair(parent), len, name, !!ndx->nfsmnt, ndx->dlgt);
127
253
 
128
 
        if (!lkup->nfsmnt) {
 
254
        ndx->nd_file = NULL;
 
255
        if (!ndx->nfsmnt) {
129
256
#ifndef CONFIG_AUFS_DLGT
130
 
                dentry = lookup_one_len(name, parent, len);
 
257
                dentry = vfsub_lookup_one_len(name, parent, len);
131
258
#else
132
 
                if (!lkup->dlgt)
133
 
                        dentry = lookup_one_len(name, parent, len);
 
259
                if (!ndx->dlgt)
 
260
                        dentry = vfsub_lookup_one_len(name, parent, len);
134
261
                else {
135
262
                        int wkq_err;
136
 
                        struct lookup_one_len_args args = {
 
263
                        struct au_lookup_one_len_args args = {
137
264
                                .errp   = &dentry,
138
265
                                .name   = name,
139
266
                                .parent = parent,
140
267
                                .len    = len
141
268
                        };
142
 
                        wkq_err = au_wkq_wait(call_lookup_one_len, &args,
 
269
                        wkq_err = au_wkq_wait(au_call_lookup_one_len, &args,
143
270
                                              /*dlgt*/1);
144
271
                        if (unlikely(wkq_err))
145
272
                                dentry = ERR_PTR(wkq_err);
146
273
                }
147
 
#endif
 
274
#endif /* CONFIG_AUFS_DLGT */
 
275
 
148
276
        } else
149
 
                dentry = lkup_hash(name, parent, len, lkup);
 
277
                dentry = au_lkup_hash(name, parent, len, ndx);
150
278
 
151
 
        TraceErrPtr(dentry);
 
279
        AuTraceErrPtr(dentry);
152
280
        return dentry;
153
281
}
154
 
#endif
 
282
#endif /* !defined(AuNoNfsBranch) || defined(CONFIG_AUFS_DLGT) */
155
283
 
156
 
struct lkup_one_args {
 
284
struct au_lkup_one_args {
157
285
        struct dentry **errp;
158
286
        const char *name;
159
287
        struct dentry *parent;
160
288
        int len;
161
 
        struct lkup_args *lkup;
 
289
        struct aufs_ndx *ndx;
162
290
};
163
291
 
164
 
static void call_lkup_one(void *args)
 
292
static void au_call_lkup_one(void *args)
165
293
{
166
 
        struct lkup_one_args *a = args;
167
 
        *a->errp = lkup_one(a->name, a->parent, a->len, a->lkup);
 
294
        struct au_lkup_one_args *a = args;
 
295
        *a->errp = au_lkup_one(a->name, a->parent, a->len, a->ndx);
168
296
}
169
297
 
 
298
struct au_do_lookup_args {
 
299
        unsigned int            allow_neg:1;
 
300
        unsigned int            dlgt:1;
 
301
        mode_t                  type;
 
302
        struct nameidata        *nd;
 
303
};
 
304
 
170
305
/*
171
306
 * returns positive/negative dentry, NULL or an error.
172
307
 * NULL means whiteout-ed or not-found.
173
308
 */
174
 
static struct dentry *do_lookup(struct dentry *hidden_parent,
175
 
                                struct dentry *dentry, aufs_bindex_t bindex,
176
 
                                struct qstr *wh_name, int allow_neg,
177
 
                                mode_t type, int dlgt)
 
309
static
 
310
struct dentry *au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
 
311
                            aufs_bindex_t bindex, struct qstr *wh_name,
 
312
                            struct au_do_lookup_args *args)
178
313
{
179
 
        struct dentry *hidden_dentry;
 
314
        struct dentry *h_dentry;
180
315
        int wh_found, wh_able, opq;
181
 
        struct inode *hidden_dir, *hidden_inode;
 
316
        struct inode *h_dir, *h_inode;
182
317
        struct qstr *name;
183
318
        struct super_block *sb;
184
 
        struct lkup_args lkup = {.dlgt = dlgt};
 
319
        struct nameidata tmp_nd;
 
320
        struct aufs_ndx ndx = {
 
321
                .dlgt   = args->dlgt,
 
322
                .nd     = args->nd
 
323
        };
185
324
 
186
 
        LKTRTrace("%.*s/%.*s, b%d, allow_neg %d, type 0%o, dlgt %d\n",
187
 
                  DLNPair(hidden_parent), DLNPair(dentry), bindex, allow_neg,
188
 
                  type, dlgt);
 
325
        LKTRTrace("%.*s/%.*s, b%d, {allow_neg %d, type 0%o, dlgt %d, nd %d}\n",
 
326
                  AuDLNPair(h_parent), AuDLNPair(dentry), bindex,
 
327
                  args->allow_neg, args->type, args->dlgt, !!args->nd);
189
328
        AuDebugOn(IS_ROOT(dentry));
190
 
        hidden_dir = hidden_parent->d_inode;
191
 
        IMustLock(hidden_dir);
 
329
        h_dir = h_parent->d_inode;
192
330
 
193
331
        wh_found = 0;
194
332
        sb = dentry->d_sb;
195
 
        wh_able = sbr_is_whable(sb, bindex);
196
 
        lkup.nfsmnt = au_nfsmnt(sb, bindex);
 
333
        ndx.nfsmnt = au_nfsmnt(sb, bindex);
 
334
        LKTRTrace("nfsmnt %p\n", ndx.nfsmnt);
 
335
        ndx.br = stobr(sb, bindex);
 
336
        wh_able = br_whable(ndx.br->br_perm);
197
337
        name = &dentry->d_name;
198
338
        if (unlikely(wh_able)) {
199
 
#if 0 //def CONFIG_AUFS_ROBR
 
339
#ifdef CONFIG_AUFS_ROBR
 
340
                wh_found = -EPERM;
200
341
                if (strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
201
 
                        wh_found = is_wh(hidden_parent, wh_name, /*try_sio*/0,
202
 
                                         &lkup);
203
 
                else
204
 
                        wh_found = -EPERM;
 
342
                        wh_found = au_test_wh(h_parent, wh_name, /*try_sio*/0,
 
343
                                              &ndx);
205
344
#else
206
 
                wh_found = is_wh(hidden_parent, wh_name, /*try_sio*/0, &lkup);
 
345
                wh_found = au_test_wh(h_parent, wh_name, /*try_sio*/0, &ndx);
207
346
#endif
208
347
        }
209
348
        //if (LktrCond) wh_found = -1;
210
 
        hidden_dentry = ERR_PTR(wh_found);
 
349
        h_dentry = ERR_PTR(wh_found);
211
350
        if (!wh_found)
212
351
                goto real_lookup;
213
352
        if (unlikely(wh_found < 0))
216
355
        /* We found a whiteout */
217
356
        //set_dbend(dentry, bindex);
218
357
        set_dbwh(dentry, bindex);
219
 
        if (!allow_neg)
 
358
        if (!args->allow_neg)
220
359
                return NULL; /* success */
 
360
        if (unlikely(ndx.nd
 
361
                     && au_test_nfs(h_parent->d_sb)
 
362
                     && (ndx.nd->flags & LOOKUP_CREATE))) {
 
363
                tmp_nd = *ndx.nd;
 
364
                tmp_nd.flags &= ~(LOOKUP_OPEN | LOOKUP_CREATE);
 
365
                ndx.nd = &tmp_nd;
 
366
        }
221
367
 
222
368
 real_lookup:
223
 
        // do not superio.
224
 
        hidden_dentry = lkup_one(name->name, hidden_parent, name->len, &lkup);
225
 
        //if (LktrCond) {dput(hidden_dentry); hidden_dentry = ERR_PTR(-1);}
226
 
        if (IS_ERR(hidden_dentry))
 
369
        /* do not superio. */
 
370
        h_dentry = au_lkup_one(name->name, h_parent, name->len, &ndx);
 
371
        //if (LktrCond) {dput(h_dentry); h_dentry = ERR_PTR(-1);}
 
372
        if (IS_ERR(h_dentry))
227
373
                goto out;
228
 
        AuDebugOn(d_unhashed(hidden_dentry));
229
 
        hidden_inode = hidden_dentry->d_inode;
230
 
        if (!hidden_inode) {
231
 
                if (!allow_neg)
 
374
        AuDebugOn(d_unhashed(h_dentry));
 
375
        h_inode = h_dentry->d_inode;
 
376
        if (!h_inode) {
 
377
                if (!args->allow_neg)
232
378
                        goto out_neg;
233
379
        } else if (wh_found
234
 
                   || (type && type != (hidden_inode->i_mode & S_IFMT)))
 
380
                   || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
235
381
                goto out_neg;
236
382
 
237
383
        if (dbend(dentry) <= bindex)
238
384
                set_dbend(dentry, bindex);
239
 
        if (dbstart(dentry) == -1 || bindex < dbstart(dentry))
 
385
        if (dbstart(dentry) < 0 || bindex < dbstart(dentry))
240
386
                set_dbstart(dentry, bindex);
241
 
        set_h_dptr(dentry, bindex, hidden_dentry);
242
 
 
243
 
        if (!hidden_inode || !S_ISDIR(hidden_inode->i_mode) || !wh_able)
244
 
                return hidden_dentry; /* success */
245
 
 
246
 
        hi_lock_child(hidden_inode);
247
 
        opq = is_diropq(hidden_dentry, &lkup);
 
387
        set_h_dptr(dentry, bindex, h_dentry);
 
388
 
 
389
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) \
 
390
        && !defined(AuNoNfsBranch)
 
391
        if (unlikely(ndx.nd_file)) {
 
392
                int err;
 
393
                AuDebugOn(!args->nd);
 
394
                err = au_set_h_intent(dentry, bindex,
 
395
                                      args->nd->intent.open.file, ndx.nd_file);
 
396
                if (unlikely(err)) {
 
397
                        fput(ndx.nd_file);
 
398
                        set_h_dptr(dentry, bindex, NULL);
 
399
                        //todo: update bstart and bend
 
400
                        h_dentry = ERR_PTR(err);
 
401
                        goto out;
 
402
                }
 
403
        }
 
404
#endif
 
405
 
 
406
        if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able)
 
407
                return h_dentry; /* success */
 
408
 
 
409
        vfsub_i_lock_nested(h_inode, AuLsc_I_CHILD);
 
410
        opq = au_test_diropq(h_dentry, &ndx);
248
411
        //if (LktrCond) opq = -1;
249
 
        i_unlock(hidden_inode);
 
412
        vfsub_i_unlock(h_inode);
250
413
        if (opq > 0)
251
414
                set_dbdiropq(dentry, bindex);
252
415
        else if (unlikely(opq < 0)) {
253
416
                set_h_dptr(dentry, bindex, NULL);
254
 
                hidden_dentry = ERR_PTR(opq);
 
417
                h_dentry = ERR_PTR(opq);
255
418
        }
256
419
        goto out;
257
420
 
258
421
 out_neg:
259
 
        dput(hidden_dentry);
260
 
        hidden_dentry = NULL;
 
422
        dput(h_dentry);
 
423
        h_dentry = NULL;
261
424
 out:
262
 
        TraceErrPtr(hidden_dentry);
263
 
        return hidden_dentry;
 
425
        AuTraceErrPtr(h_dentry);
 
426
        return h_dentry;
264
427
}
265
428
 
266
429
/*
267
430
 * returns the number of hidden positive dentries,
268
431
 * otherwise an error.
269
432
 */
270
 
int lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
 
433
int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
 
434
                   struct nameidata *nd)
271
435
{
272
 
        int npositive, err, allow_neg, dlgt;
 
436
        int npositive, err;
273
437
        struct dentry *parent;
274
438
        aufs_bindex_t bindex, btail;
275
439
        const struct qstr *name = &dentry->d_name;
276
440
        struct qstr whname;
277
441
        struct super_block *sb;
 
442
        struct au_do_lookup_args args = {
 
443
                .type   = type,
 
444
                .nd     = nd
 
445
        };
278
446
 
279
 
        LKTRTrace("%.*s, b%d, type 0%o\n", LNPair(name), bstart, type);
 
447
        LKTRTrace("%.*s, b%d, type 0%o\n", AuLNPair(name), bstart, type);
280
448
        AuDebugOn(bstart < 0 || IS_ROOT(dentry));
 
449
 
 
450
        /* dir may not be locked */
281
451
        parent = dget_parent(dentry);
282
452
 
283
 
#if 1 //ndef CONFIG_AUFS_ROBR
 
453
#ifndef CONFIG_AUFS_ROBR
284
454
        err = -EPERM;
285
455
        if (unlikely(!strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
286
456
                goto out;
292
462
                goto out;
293
463
 
294
464
        sb = dentry->d_sb;
295
 
        dlgt = need_dlgt(sb);
296
 
        allow_neg = !type;
 
465
        args.dlgt = !!au_need_dlgt(sb);
 
466
        args.allow_neg = !type;
297
467
        npositive = 0;
298
468
        btail = dbtaildir(parent);
299
469
        for (bindex = bstart; bindex <= btail; bindex++) {
300
 
                struct dentry *hidden_parent, *hidden_dentry;
301
 
                struct inode *hidden_inode;
302
 
                struct inode *hidden_dir;
 
470
                struct dentry *h_parent, *h_dentry;
 
471
                struct inode *h_inode, *h_dir;
303
472
 
304
 
                hidden_dentry = au_h_dptr_i(dentry, bindex);
305
 
                if (hidden_dentry) {
306
 
                        if (hidden_dentry->d_inode)
 
473
                h_dentry = au_h_dptr_i(dentry, bindex);
 
474
                if (h_dentry) {
 
475
                        if (h_dentry->d_inode)
307
476
                                npositive++;
308
477
                        if (type != S_IFDIR)
309
478
                                break;
310
479
                        continue;
311
480
                }
312
 
                hidden_parent = au_h_dptr_i(parent, bindex);
313
 
                if (!hidden_parent)
 
481
                h_parent = au_h_dptr_i(parent, bindex);
 
482
                if (!h_parent)
314
483
                        continue;
315
 
                hidden_dir = hidden_parent->d_inode;
316
 
                if (!hidden_dir || !S_ISDIR(hidden_dir->i_mode))
 
484
                h_dir = h_parent->d_inode;
 
485
                if (!h_dir || !S_ISDIR(h_dir->i_mode))
317
486
                        continue;
318
487
 
319
 
                hi_lock_parent(hidden_dir);
320
 
                hidden_dentry = do_lookup(hidden_parent, dentry, bindex,
321
 
                                          &whname, allow_neg, type, dlgt);
 
488
                vfsub_i_lock_nested(h_dir, AuLsc_I_PARENT);
 
489
                h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
 
490
                                        &args);
322
491
                // do not dput for testing
323
 
                //if (LktrCond) {hidden_dentry = ERR_PTR(-1);}
324
 
                i_unlock(hidden_dir);
325
 
                err = PTR_ERR(hidden_dentry);
326
 
                if (IS_ERR(hidden_dentry))
 
492
                //if (LktrCond) {h_dentry = ERR_PTR(-1);}
 
493
                vfsub_i_unlock(h_dir);
 
494
                err = PTR_ERR(h_dentry);
 
495
                if (IS_ERR(h_dentry))
327
496
                        goto out_wh;
328
 
                allow_neg = 0;
 
497
                args.allow_neg = 0;
329
498
 
330
 
                if (dbwh(dentry) != -1)
 
499
                if (dbwh(dentry) >= 0)
331
500
                        break;
332
 
                if (!hidden_dentry)
 
501
                if (!h_dentry)
333
502
                        continue;
334
 
                hidden_inode = hidden_dentry->d_inode;
335
 
                if (!hidden_inode)
 
503
                h_inode = h_dentry->d_inode;
 
504
                if (!h_inode)
336
505
                        continue;
337
506
                npositive++;
338
 
                if (!type)
339
 
                        type = hidden_inode->i_mode & S_IFMT;
340
 
                if (type != S_IFDIR)
 
507
                if (!args.type)
 
508
                        args.type = h_inode->i_mode & S_IFMT;
 
509
                if (args.type != S_IFDIR)
341
510
                        break;
342
 
                else if (dbdiropq(dentry) != -1)
 
511
                else if (dbdiropq(dentry) >= 0)
343
512
                        break;
344
513
        }
345
514
 
353
522
        au_free_whname(&whname);
354
523
 out:
355
524
        dput(parent);
356
 
        TraceErr(err);
 
525
        AuTraceErr(err);
357
526
        return err;
358
527
}
359
528
 
360
 
struct dentry *sio_lkup_one(const char *name, struct dentry *parent, int len,
361
 
                            struct lkup_args *lkup)
 
529
struct dentry *au_sio_lkup_one(const char *name, struct dentry *parent, int len,
 
530
                               struct aufs_ndx *ndx)
362
531
{
363
532
        struct dentry *dentry;
364
533
        int wkq_err;
365
534
 
366
 
        LKTRTrace("%.*s/%.*s\n", DLNPair(parent), len, name);
367
 
        IMustLock(parent->d_inode);
 
535
        LKTRTrace("%.*s/%.*s\n", AuDLNPair(parent), len, name);
368
536
 
369
 
        if (!au_test_perm(parent->d_inode, MAY_EXEC, lkup->dlgt))
370
 
                dentry = lkup_one(name, parent, len, lkup);
 
537
        if (!au_test_perm(parent->d_inode, MAY_EXEC, ndx->dlgt))
 
538
                dentry = au_lkup_one(name, parent, len, ndx);
371
539
        else {
372
540
                // ugly
373
 
                int dlgt = lkup->dlgt;
374
 
                struct lkup_one_args args = {
 
541
                int dlgt = ndx->dlgt;
 
542
                struct au_lkup_one_args args = {
375
543
                        .errp   = &dentry,
376
544
                        .name   = name,
377
545
                        .parent = parent,
378
546
                        .len    = len,
379
 
                        .lkup   = lkup
 
547
                        .ndx    = ndx
380
548
                };
381
549
 
382
 
                lkup->dlgt = 0;
383
 
                wkq_err = au_wkq_wait(call_lkup_one, &args, /*dlgt*/0);
 
550
                ndx->dlgt = 0;
 
551
                wkq_err = au_wkq_wait(au_call_lkup_one, &args, /*dlgt*/0);
384
552
                if (unlikely(wkq_err))
385
553
                        dentry = ERR_PTR(wkq_err);
386
 
                lkup->dlgt = dlgt;
 
554
                ndx->dlgt = dlgt;
387
555
        }
388
556
 
389
 
        TraceErrPtr(dentry);
 
557
        AuTraceErrPtr(dentry);
390
558
        return dentry;
391
559
}
392
560
 
393
561
/*
394
562
 * lookup @dentry on @bindex which should be negative.
395
563
 */
396
 
int lkup_neg(struct dentry *dentry, aufs_bindex_t bindex)
 
564
int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex)
397
565
{
398
566
        int err;
399
 
        struct dentry *parent, *hidden_parent, *hidden_dentry;
400
 
        struct inode *hidden_dir;
401
 
        struct lkup_args lkup;
 
567
        struct dentry *parent, *h_parent, *h_dentry;
 
568
        struct inode *h_dir;
 
569
        struct aufs_ndx ndx = {
 
570
                .nd     = NULL,
 
571
                //.br   = NULL
 
572
        };
 
573
        struct super_block *sb;
402
574
 
403
 
        LKTRTrace("%.*s, b%d\n", DLNPair(dentry), bindex);
 
575
        LKTRTrace("%.*s, b%d\n", AuDLNPair(dentry), bindex);
 
576
        /* dir may not be locked */
404
577
        parent = dget_parent(dentry);
405
578
        AuDebugOn(!parent || !parent->d_inode
406
579
                  || !S_ISDIR(parent->d_inode->i_mode));
407
 
        hidden_parent = au_h_dptr_i(parent, bindex);
408
 
        AuDebugOn(!hidden_parent);
409
 
        hidden_dir = hidden_parent->d_inode;
410
 
        AuDebugOn(!hidden_dir || !S_ISDIR(hidden_dir->i_mode));
411
 
        IMustLock(hidden_dir);
 
580
        h_parent = au_h_dptr_i(parent, bindex);
 
581
        AuDebugOn(!h_parent);
 
582
        h_dir = h_parent->d_inode;
 
583
        AuDebugOn(!h_dir || !S_ISDIR(h_dir->i_mode));
412
584
 
413
 
        lkup.nfsmnt = au_nfsmnt(dentry->d_sb, bindex);
414
 
        lkup.dlgt = need_dlgt(dentry->d_sb);
415
 
        hidden_dentry = sio_lkup_one(dentry->d_name.name, hidden_parent,
416
 
                                     dentry->d_name.len, &lkup);
417
 
        //if (LktrCond) {dput(hidden_dentry); hidden_dentry = ERR_PTR(-1);}
418
 
        err = PTR_ERR(hidden_dentry);
419
 
        if (IS_ERR(hidden_dentry))
 
585
        sb = dentry->d_sb;
 
586
        ndx.nfsmnt = au_nfsmnt(sb, bindex);
 
587
        ndx.dlgt = au_need_dlgt(sb);
 
588
        h_dentry = au_sio_lkup_one(dentry->d_name.name, h_parent,
 
589
                                   dentry->d_name.len, &ndx);
 
590
        //if (LktrCond) {dput(h_dentry); h_dentry = ERR_PTR(-1);}
 
591
        err = PTR_ERR(h_dentry);
 
592
        if (IS_ERR(h_dentry))
420
593
                goto out;
421
 
        if (unlikely(hidden_dentry->d_inode)) {
 
594
        if (unlikely(h_dentry->d_inode)) {
422
595
                err = -EIO;
423
 
                IOErr("b%d %.*s should be negative.%s\n",
424
 
                      bindex, DLNPair(hidden_dentry),
425
 
                      au_flag_test(dentry->d_sb, AuFlag_UDBA_INOTIFY) ? "" :
426
 
                      " Try udba=inotify.");
427
 
                dput(hidden_dentry);
 
596
                AuIOErr("b%d %.*s should be negative.\n",
 
597
                        bindex, AuDLNPair(h_dentry));
 
598
                dput(h_dentry);
428
599
                goto out;
429
600
        }
430
601
 
432
603
                set_dbstart(dentry, bindex);
433
604
        if (dbend(dentry) < bindex)
434
605
                set_dbend(dentry, bindex);
435
 
        set_h_dptr(dentry, bindex, hidden_dentry);
 
606
        set_h_dptr(dentry, bindex, h_dentry);
436
607
        err = 0;
437
608
 
438
609
 out:
439
610
        dput(parent);
440
 
        TraceErr(err);
 
611
        AuTraceErr(err);
441
612
        return err;
442
613
}
443
614
 
447
618
 */
448
619
int au_refresh_hdentry(struct dentry *dentry, mode_t type)
449
620
{
450
 
        int npositive, pgen, new_sz, sgen, dgen;
 
621
        int npositive, new_sz;
451
622
        struct aufs_dinfo *dinfo;
452
623
        struct super_block *sb;
453
624
        struct dentry *parent;
454
625
        aufs_bindex_t bindex, parent_bend, parent_bstart, bwh, bdiropq, bend;
455
626
        struct aufs_hdentry *p;
456
 
        //struct nameidata nd;
457
627
 
458
 
        LKTRTrace("%.*s, type 0%o\n", DLNPair(dentry), type);
 
628
        LKTRTrace("%.*s, type 0%o\n", AuDLNPair(dentry), type);
459
629
        DiMustWriteLock(dentry);
460
630
        sb = dentry->d_sb;
461
631
        AuDebugOn(IS_ROOT(dentry));
462
632
        parent = dget_parent(dentry);
463
 
        pgen = au_digen(parent);
464
 
        sgen = au_sigen(sb);
465
 
        dgen = au_digen(dentry);
466
 
        AuDebugOn(pgen != sgen);
 
633
        AuDebugOn(au_digen(parent) != au_sigen(sb));
467
634
 
468
635
        npositive = -ENOMEM;
469
636
        new_sz = sizeof(*dinfo->di_hdentry) * (sbend(sb) + 1);
518
685
 
519
686
        // test here
520
687
        dinfo->di_bwh = -1;
521
 
        if (unlikely(bwh != -1 && bwh <= sbend(sb) && sbr_is_whable(sb, bwh)))
 
688
        if (unlikely(bwh >= 0 && bwh <= sbend(sb) && sbr_whable(sb, bwh)))
522
689
                dinfo->di_bwh = bwh;
523
690
        dinfo->di_bdiropq = -1;
524
 
        if (unlikely(bdiropq != -1 && bdiropq <= sbend(sb)
525
 
                     && sbr_is_whable(sb, bdiropq)))
 
691
        if (unlikely(bdiropq >= 0 && bdiropq <= sbend(sb)
 
692
                     && sbr_whable(sb, bdiropq)))
526
693
                dinfo->di_bdiropq = bdiropq;
527
694
        parent_bend = dbend(parent);
528
695
        p = dinfo->di_hdentry;
544
711
        if (type != S_IFDIR && dinfo->di_bstart == parent_bstart)
545
712
                goto out_dgen; /* success */
546
713
 
547
 
#if 0
548
 
        nd.last_type = LAST_ROOT;
549
 
        nd.flags = LOOKUP_FOLLOW;
550
 
        nd.depth = 0;
551
 
        nd.mnt = mntget(??);
552
 
        nd.dentry = dget(parent);
553
 
#endif
554
 
        npositive = lkup_dentry(dentry, parent_bstart, type);
 
714
        npositive = au_lkup_dentry(dentry, parent_bstart, type, /*nd*/NULL);
555
715
        //if (LktrCond) npositive = -1;
556
716
        if (npositive < 0)
557
717
                goto out;
 
718
        if (unlikely(dinfo->di_bwh >= 0 && dinfo->di_bwh <= dinfo->di_bstart))
 
719
                d_drop(dentry);
558
720
 
559
721
 out_dgen:
560
722
        au_update_digen(dentry);
561
723
 out:
562
724
        dput(parent);
563
 
        TraceErr(npositive);
 
725
        AuTraceErr(npositive);
564
726
        return npositive;
565
727
}
566
728
 
567
 
static int h_d_revalidate(struct dentry *dentry, struct nameidata *nd,
568
 
                          int do_udba)
 
729
static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
 
730
                          struct nameidata *nd, int do_udba)
569
731
{
570
 
        int err, plus, locked, unhashed, is_root, h_plus, is_nfs;
 
732
        int err, plus, locked, unhashed, is_root, h_plus, valid;
571
733
        struct nameidata fake_nd, *p;
572
734
        aufs_bindex_t bindex, btail, bstart, ibs, ibe;
573
735
        struct super_block *sb;
574
 
        struct inode *inode, *first, *h_inode, *h_cached_inode;
 
736
        struct inode *first, *h_inode, *h_cached_inode;
575
737
        umode_t mode, h_mode;
576
738
        struct dentry *h_dentry;
577
739
        int (*reval)(struct dentry *, struct nameidata *);
578
740
        struct qstr *name;
579
741
 
580
 
        LKTRTrace("%.*s\n", DLNPair(dentry));
581
 
        inode = dentry->d_inode;
 
742
        LKTRTrace("%.*s, nd %d\n", AuDLNPair(dentry), !!nd);
582
743
        AuDebugOn(inode && au_digen(dentry) != au_iigen(inode));
583
 
        //DbgDentry(dentry);
584
 
        //DbgInode(inode);
585
744
 
586
745
        err = 0;
587
746
        sb = dentry->d_sb;
588
747
        plus = 0;
589
748
        mode = 0;
590
749
        first = NULL;
591
 
        ibs = ibe = -1;
 
750
        ibs = -1;
 
751
        ibe = -1;
592
752
        unhashed = d_unhashed(dentry);
593
753
        is_root = IS_ROOT(dentry);
594
754
        name = &dentry->d_name;
608
768
                ibe = ibend(inode);
609
769
        }
610
770
 
611
 
        btail = bstart = dbstart(dentry);
 
771
        bstart = dbstart(dentry);
 
772
        btail = bstart;
612
773
        if (inode && S_ISDIR(inode->i_mode))
613
774
                btail = dbtaildir(dentry);
614
775
        locked = 0;
615
 
        if (nd) {
616
 
                fake_nd = *nd;
617
776
#ifndef CONFIG_AUFS_FAKE_DM
618
 
                if (dentry != nd->dentry) {
619
 
                        di_read_lock_parent(nd->dentry, 0);
620
 
                        locked = 1;
621
 
                }
 
777
        if (nd && dentry != nd->dentry) {
 
778
                di_read_lock_parent(nd->dentry, 0);
 
779
                locked = 1;
 
780
        }
622
781
#endif
623
 
        }
624
782
        for (bindex = bstart; bindex <= btail; bindex++) {
625
783
                h_dentry = au_h_dptr_i(dentry, bindex);
626
784
                if (unlikely(!h_dentry))
628
786
                if (unlikely(do_udba
629
787
                             && !is_root
630
788
                             && (unhashed != d_unhashed(h_dentry)
631
 
#if 1
 
789
//#if 1
632
790
                                 || name->len != h_dentry->d_name.len
633
791
                                 || memcmp(name->name, h_dentry->d_name.name,
634
792
                                           name->len)
635
 
#endif
 
793
//#endif
636
794
                                     ))) {
637
795
                        LKTRTrace("unhash 0x%x 0x%x, %.*s %.*s\n",
638
796
                                  unhashed, d_unhashed(h_dentry),
639
 
                                  DLNPair(dentry), DLNPair(h_dentry));
 
797
                                  AuDLNPair(dentry), AuDLNPair(h_dentry));
640
798
                        goto err;
641
799
                }
642
800
 
645
803
                        reval = h_dentry->d_op->d_revalidate;
646
804
                if (unlikely(reval)) {
647
805
                        //LKTRLabel(hidden reval);
648
 
                        p = fake_dm(&fake_nd, nd, sb, bindex);
 
806
                        if (nd) {
 
807
                                memcpy(&fake_nd, nd, sizeof(*nd));
 
808
                                err = au_fake_intent(&fake_nd,
 
809
                                                     sbr_perm(sb, bindex));
 
810
                                if (unlikely(err))
 
811
                                        goto err;
 
812
                        }
 
813
                        p = au_fake_dm(&fake_nd, nd, sb, bindex);
649
814
                        AuDebugOn(IS_ERR(p));
650
 
                        err = !reval(h_dentry, p);
651
 
                        fake_dm_release(p);
 
815
                        AuDebugOn(nd && p != &fake_nd);
 
816
                        LKTRTrace("b%d\n", bindex);
 
817
 
 
818
                        /* it may return tri-state */
 
819
                        valid = reval(h_dentry, p);
 
820
                        if (unlikely(valid < 0))
 
821
                                err = valid;
 
822
                        else if (!valid)
 
823
                                err = -EINVAL;
 
824
                        else
 
825
                                AuDebugOn(err);
 
826
 
 
827
                        if (p) {
 
828
                                int e;
 
829
                                AuDebugOn(!nd);
 
830
                                e = au_hin_after_reval(p, dentry, bindex,
 
831
                                                       nd->intent.open.file);
 
832
                                au_update_fuse_h_inode(p->mnt, h_dentry);
 
833
                                /*ignore*/
 
834
                                if (unlikely(e && !err))
 
835
                                        err = e;
 
836
                        } else
 
837
                                au_update_fuse_h_inode(NULL, h_dentry);
 
838
                        /*ignore*/
 
839
                        au_fake_dm_release(p);
652
840
                        if (unlikely(err)) {
653
 
                                //Dbg("here\n");
654
 
                                goto err;
 
841
                                //AuDbg("here\n");
 
842
                                /* do not goto err, to keep the errno */
 
843
                                break;
655
844
                        }
656
845
                }
657
846
 
661
850
                /* UDBA tests */
662
851
                h_inode = h_dentry->d_inode;
663
852
                if (unlikely(!!inode != !!h_inode)) {
664
 
                        //Dbg("here\n");
 
853
                        //AuDbg("here\n");
665
854
                        goto err;
666
855
                }
667
856
 
668
857
                h_plus = plus;
669
858
                h_mode = mode;
670
859
                h_cached_inode = h_inode;
671
 
                is_nfs = 0;
672
860
                if (h_inode) {
673
861
                        h_mode = (h_inode->i_mode & S_IFMT);
674
862
                        h_plus = (h_inode->i_nlink > 0);
 
863
                        //AuDbgInode(inode);
 
864
                        //AuDbgInode(h_inode);
675
865
                }
676
 
                if (inode && ibs <= bindex && bindex <= ibe) {
 
866
                if (inode && ibs <= bindex && bindex <= ibe)
677
867
                        h_cached_inode = au_h_iptr_i(inode, bindex);
678
 
                        //is_nfs = au_is_nfs(h_cached_inode->i_sb);
679
 
                }
680
868
 
681
 
                LKTRTrace("{%d, 0%o, %p}, h{%d, 0%o, %p}\n",
682
 
                          plus, mode, h_cached_inode,
683
 
                          h_plus, h_mode, h_inode);
684
 
                if (unlikely(plus != h_plus || mode != h_mode
685
 
                             || (h_cached_inode != h_inode /* && !is_nfs */))) {
686
 
                        //Dbg("here\n");
 
869
                LKTRTrace("{%d, 0%o, %d}, h{%d, 0%o, %d}\n",
 
870
                          plus, mode, !!h_cached_inode,
 
871
                          h_plus, h_mode, !!h_inode);
 
872
                if (unlikely(plus != h_plus
 
873
                             || mode != h_mode
 
874
                             || h_cached_inode != h_inode))
687
875
                        goto err;
688
 
                }
689
876
                continue;
690
877
 
691
878
        err:
697
884
                di_read_unlock(nd->dentry, 0);
698
885
#endif
699
886
 
700
 
#if 0
701
 
        // some filesystem uses CURRENT_TIME_SEC instead of CURRENT_TIME.
702
 
        // NFS may stop IN_DELETE because of DCACHE_NFSFS_RENAMED.
703
 
#if 0
704
 
                     && (!timespec_equal(&inode->i_ctime, &first->i_ctime)
705
 
                         || !timespec_equal(&inode->i_atime, &first->i_atime))
706
 
#endif
 
887
        /*
 
888
         * judging by timestamps is meaningless since some filesystem uses
 
889
         * CURRENT_TIME_SEC instead of CURRENT_TIME.
 
890
         */
 
891
        /*
 
892
         * NFS may stop IN_DELETE because of DCACHE_NFSFS_RENAMED.
 
893
         */
 
894
 
 
895
#if 0 // debug
 
896
        if (!err)
 
897
                au_update_from_fuse(inode);
707
898
        if (unlikely(!err && udba && first))
708
899
                au_cpup_attr_all(inode);
709
900
#endif
710
901
 
711
 
        TraceErr(err);
 
902
        AuTraceErr(err);
712
903
        return err;
713
904
}
714
905
 
715
 
static int simple_reval_dpath(struct dentry *dentry, int sgen)
 
906
static int simple_reval_dpath(struct dentry *dentry, au_gen_t sgen)
716
907
{
717
908
        int err;
718
909
        mode_t type;
719
910
        struct dentry *parent;
720
911
        struct inode *inode;
721
912
 
722
 
        LKTRTrace("%.*s, sgen %d\n", DLNPair(dentry), sgen);
 
913
        LKTRTrace("%.*s, sgen %d\n", AuDLNPair(dentry), sgen);
723
914
        SiMustAnyLock(dentry->d_sb);
724
915
        DiMustWriteLock(dentry);
725
916
        inode = dentry->d_inode;
729
920
                return 0;
730
921
 
731
922
        parent = dget_parent(dentry);
732
 
        di_read_lock_parent(parent, AUFS_I_RLOCK);
 
923
        di_read_lock_parent(parent, AuLock_IR);
733
924
        AuDebugOn(au_digen(parent) != sgen);
734
925
#ifdef CONFIG_AUFS_DEBUG
735
926
        {
738
929
                struct au_dpage *dpage;
739
930
                struct dentry **dentries;
740
931
 
741
 
                err = au_dpages_init(&dpages, GFP_KERNEL);
 
932
                err = au_dpages_init(&dpages, GFP_TEMPORARY);
742
933
                AuDebugOn(err);
743
934
                err = au_dcsub_pages_rev(&dpages, parent, /*do_include*/1, NULL,
744
935
                                         NULL);
757
948
        err = au_refresh_hdentry(dentry, type);
758
949
        if (err >= 0)
759
950
                err = au_refresh_hinode(inode, dentry);
760
 
        di_read_unlock(parent, AUFS_I_RLOCK);
 
951
        di_read_unlock(parent, AuLock_IR);
761
952
        dput(parent);
762
 
        TraceErr(err);
 
953
        AuTraceErr(err);
763
954
        return err;
764
955
}
765
956
 
766
 
int au_reval_dpath(struct dentry *dentry, int sgen)
 
957
int au_reval_dpath(struct dentry *dentry, au_gen_t sgen)
767
958
{
768
959
        int err;
769
960
        struct dentry *d, *parent;
770
961
        struct inode *inode;
771
962
 
772
 
        LKTRTrace("%.*s, sgen %d\n", DLNPair(dentry), sgen);
 
963
        LKTRTrace("%.*s, sgen %d\n", AuDLNPair(dentry), sgen);
773
964
        AuDebugOn(!dentry->d_inode);
774
965
        DiMustWriteLock(dentry);
775
966
 
777
968
                return simple_reval_dpath(dentry, sgen);
778
969
 
779
970
        /* slow loop, keep it simple and stupid */
780
 
        /* cf: cpup_dirs() */
 
971
        /* cf: au_cpup_dirs() */
781
972
        err = 0;
 
973
        parent = NULL;
782
974
        while (au_digen(dentry) != sgen) {
783
975
                d = dentry;
784
976
                while (1) {
785
 
                        parent = d->d_parent; // dget_parent()
 
977
                        dput(parent);
 
978
                        parent = dget_parent(d);
786
979
                        if (au_digen(parent) == sgen)
787
980
                                break;
788
981
                        d = parent;
790
983
 
791
984
                inode = d->d_inode;
792
985
                if (d != dentry) {
793
 
                        //i_lock(inode);
 
986
                        //vfsub_i_lock(inode);
794
987
                        di_write_lock_child(d);
795
988
                }
796
989
 
797
990
                /* someone might update our dentry while we were sleeping */
798
991
                if (au_digen(d) != sgen) {
799
 
                        di_read_lock_parent(parent, AUFS_I_RLOCK);
 
992
                        di_read_lock_parent(parent, AuLock_IR);
800
993
                        /* returns a number of positive dentries */
801
994
                        err = au_refresh_hdentry(d, inode->i_mode & S_IFMT);
802
995
                        //err = -1;
803
996
                        if (err >= 0)
804
997
                                err = au_refresh_hinode(inode, d);
805
998
                        //err = -1;
806
 
                        di_read_unlock(parent, AUFS_I_RLOCK);
 
999
                        di_read_unlock(parent, AuLock_IR);
807
1000
                }
808
1001
 
809
1002
                if (d != dentry) {
810
1003
                        di_write_unlock(d);
811
 
                        //i_unlock(inode);
 
1004
                        //vfsub_i_unlock(inode);
812
1005
                }
 
1006
                dput(parent);
813
1007
                if (unlikely(err))
814
1008
                        break;
815
1009
        }
816
1010
 
817
 
        TraceErr(err);
 
1011
        AuTraceErr(err);
818
1012
        return err;
819
1013
}
820
1014
 
824
1018
 */
825
1019
static int aufs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
826
1020
{
827
 
        int valid, sgen, err, do_udba;
 
1021
        int valid, err, do_udba;
828
1022
        struct super_block *sb;
 
1023
        au_gen_t sgen;
829
1024
        struct inode *inode;
 
1025
        struct nameidata tmp_nd, *ndp;
 
1026
        struct aufs_sbinfo *sbinfo;
 
1027
        //todo: no more lower nameidata, only here. re-use it.
830
1028
 
831
 
        LKTRTrace("dentry %.*s\n", DLNPair(dentry));
 
1029
        LKTRTrace("dentry %.*s\n", AuDLNPair(dentry));
832
1030
        if (nd && nd->dentry)
833
 
                LKTRTrace("nd %.*s\n", DLNPair(nd->dentry));
 
1031
                LKTRTrace("nd{%.*s, 0x%x}\n", AuDLNPair(nd->dentry), nd->flags);
834
1032
        //dir case: AuDebugOn(dentry->d_parent != nd->dentry);
835
 
        //remove failure case: AuDebugOn(!IS_ROOT(dentry) && d_unhashed(dentry));
 
1033
        //remove failure case:AuDebugOn(!IS_ROOT(dentry) && d_unhashed(dentry));
836
1034
        AuDebugOn(!dentry->d_fsdata);
837
 
        //DbgDentry(dentry);
 
1035
        //AuDbgDentry(dentry);
838
1036
 
839
1037
        err = -EINVAL;
840
1038
        inode = dentry->d_inode;
841
 
        //DbgInode(inode);
842
1039
        sb = dentry->d_sb;
843
 
        si_read_lock(sb);
 
1040
        si_read_lock(sb, AuLock_FLUSH);
 
1041
 
844
1042
        sgen = au_sigen(sb);
845
1043
        if (au_digen(dentry) == sgen)
846
 
                di_read_lock_child(dentry, !AUFS_I_RLOCK);
 
1044
                di_read_lock_child(dentry, !AuLock_IR);
847
1045
        else {
848
1046
                AuDebugOn(IS_ROOT(dentry));
849
1047
#ifdef ForceInotify
850
 
                Dbg("UDBA or digen, %.*s\n", DLNPair(dentry));
 
1048
                AuDbg("UDBA or digen, %.*s\n", AuDLNPair(dentry));
851
1049
#endif
852
 
                //i_lock(inode);
 
1050
                //di_read_lock_child(dentry, AuLock_IR);err = -EINVAL; goto out;
 
1051
                //vfsub_i_lock(inode);
853
1052
                di_write_lock_child(dentry);
854
1053
                if (inode)
855
1054
                        err = au_reval_dpath(dentry, sgen);
856
1055
                //err = -1;
857
 
                di_downgrade_lock(dentry, AUFS_I_RLOCK);
858
 
                //i_unlock(inode);
 
1056
                di_downgrade_lock(dentry, AuLock_IR);
 
1057
                //vfsub_i_unlock(inode);
859
1058
                if (unlikely(err))
860
1059
                        goto out;
861
1060
                ii_read_unlock(inode);
868
1067
                else {
869
1068
                        AuDebugOn(IS_ROOT(dentry));
870
1069
#ifdef ForceInotify
871
 
                        Dbg("UDBA or survived, %.*s\n", DLNPair(dentry));
 
1070
                        AuDbg("UDBA or survived, %.*s\n", AuDLNPair(dentry));
 
1071
                        //au_debug_on();
 
1072
                        //AuDbgInode(inode);
 
1073
                        //au_debug_off();
872
1074
#endif
 
1075
                        //ii_read_lock_child(inode);err = -EINVAL; goto out;
873
1076
                        ii_write_lock_child(inode);
874
1077
                        err = au_refresh_hinode(inode, dentry);
875
1078
                        ii_downgrade_lock(inode);
882
1085
#if 0 // fix it
883
1086
        /* parent dir i_nlink is not updated in the case of setattr */
884
1087
        if (S_ISDIR(inode->i_mode)) {
885
 
                i_lock(inode);
 
1088
                vfsub_i_lock(inode);
886
1089
                ii_write_lock(inode);
887
1090
                au_cpup_attr_nlink(inode);
888
1091
                ii_write_unlock(inode);
889
 
                i_unlock(inode);
 
1092
                vfsub_i_unlock(inode);
890
1093
        }
891
1094
#endif
892
1095
 
893
1096
        err = -EINVAL;
894
 
        do_udba = !au_flag_test(sb, AuFlag_UDBA_NONE);
 
1097
        sbinfo = stosi(sb);
 
1098
        do_udba = (AuFlag(sbinfo, f_udba) != AuUdba_NONE);
895
1099
        if (do_udba && inode && ibstart(inode) >= 0
896
1100
            && au_test_higen(inode, au_h_iptr(inode)))
897
1101
                goto out;
898
 
        err = h_d_revalidate(dentry, nd, do_udba);
 
1102
        ndp = au_dup_nd(sbinfo, &tmp_nd, nd);
 
1103
        err = h_d_revalidate(dentry, inode, ndp, do_udba);
899
1104
        //err = -1;
900
1105
 
901
1106
 out:
902
 
        aufs_read_unlock(dentry, AUFS_I_RLOCK);
903
 
        TraceErr(err);
 
1107
#if 0
 
1108
        AuDbgDentry(dentry);
 
1109
        if (nd && (nd->flags & LOOKUP_OPEN)) {
 
1110
                LKTRTrace("intent.open.file %p\n", nd->intent.open.file);
 
1111
                if (nd->intent.open.file && nd->intent.open.file->f_dentry)
 
1112
                        AuDbgFile(nd->intent.open.file);
 
1113
        }
 
1114
#endif
 
1115
        au_store_fmode_exec(nd, inode);
 
1116
 
 
1117
        if (inode)
 
1118
                ii_read_unlock(inode);
 
1119
        di_read_unlock(dentry, !AuLock_IR);
 
1120
        si_read_unlock(sb);
 
1121
        AuTraceErr(err);
904
1122
        valid = !err;
905
 
        //au_debug_on();
906
1123
        if (!valid)
907
 
                LKTRTrace("%.*s invalid\n", DLNPair(dentry));
908
 
        //au_debug_off();
 
1124
                LKTRTrace("%.*s invalid\n", AuDLNPair(dentry));
909
1125
        return valid;
910
1126
}
911
1127
 
914
1130
        struct aufs_dinfo *dinfo;
915
1131
        aufs_bindex_t bend, bindex;
916
1132
 
917
 
        LKTRTrace("%.*s\n", DLNPair(dentry));
 
1133
        LKTRTrace("%.*s\n", AuDLNPair(dentry));
918
1134
        AuDebugOn(!d_unhashed(dentry));
919
1135
 
920
1136
        dinfo = dentry->d_fsdata;
935
1151
                }
936
1152
        }
937
1153
        kfree(dinfo->di_hdentry);
938
 
        cache_free_dinfo(dinfo);
939
 
}
940
 
 
941
 
#if 0
942
 
/* it may be called at remount time, too */
943
 
static void aufs_d_iput(struct dentry *dentry, struct inode *inode)
944
 
{
945
 
        struct super_block *sb;
946
 
 
947
 
        LKTRTrace("%.*s, i%lu\n", DLNPair(dentry), inode->i_ino);
948
 
 
949
 
        sb = dentry->d_sb;
950
 
#if 0
951
 
        si_read_lock(sb);
952
 
        if (unlikely(au_flag_test(sb, AuFlag_PLINK)
953
 
                     && au_is_plinked(sb, inode))) {
954
 
                ii_write_lock(inode);
955
 
                au_update_brange(inode, 1);
956
 
                ii_write_unlock(inode);
957
 
        }
958
 
        si_read_unlock(sb);
959
 
#endif
960
 
        iput(inode);
961
 
}
962
 
#endif
 
1154
        au_cache_free_dinfo(dinfo);
 
1155
}
963
1156
 
964
1157
struct dentry_operations aufs_dop = {
965
1158
        .d_revalidate   = aufs_d_revalidate,
966
 
        .d_release      = aufs_d_release
 
1159
        .d_release      = aufs_d_release,
 
1160
        /* never use d_delete, especially in case of nfs server */
 
1161
        //.d_delete     = aufs_d_delete
967
1162
        //.d_iput               = aufs_d_iput
968
1163
};