~ubuntu-branches/ubuntu/precise/aufs/precise

« back to all changes in this revision

Viewing changes to fs/aufs/i_op_add.c

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2007-05-09 15:29:28 UTC
  • Revision ID: james.westby@ubuntu.com-20070509152928-4sywrmkifvz0bq02
Tags: upstream-0+20070509
ImportĀ upstreamĀ versionĀ 0+20070509

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005, 2006, 2007 Junjiro Okajima
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 */
 
18
 
 
19
/* $Id: i_op_add.c,v 1.37 2007/05/07 03:46:08 sfjro Exp $ */
 
20
 
 
21
//#include <linux/fs.h>
 
22
//#include <linux/namei.h>
 
23
#include "aufs.h"
 
24
 
 
25
/*
 
26
 * final procedure of adding a new entry, except link(2).
 
27
 * remove whiteout, instantiate, copyup the parent dir's times and size
 
28
 * and update version.
 
29
 * if it failed, re-create the removed whiteout.
 
30
 */
 
31
static int epilog(struct dentry *wh_dentry, struct dentry *dentry)
 
32
{
 
33
        int err, rerr;
 
34
        aufs_bindex_t bwh;
 
35
        struct inode *inode, *dir;
 
36
        struct dentry *wh;
 
37
        struct lkup_args lkup;
 
38
 
 
39
        LKTRTrace("wh %p, %.*s\n", wh_dentry, DLNPair(dentry));
 
40
 
 
41
        lkup.dlgt = need_dlgt(dentry->d_sb);
 
42
        bwh = -1;
 
43
        if (wh_dentry) {
 
44
                bwh = dbwh(dentry);
 
45
                err = au_unlink_wh_dentry(wh_dentry->d_parent->d_inode,
 
46
                                          wh_dentry, dentry, lkup.dlgt);
 
47
                //err = -1;
 
48
                if (unlikely(err))
 
49
                        goto out;
 
50
        }
 
51
 
 
52
        inode = au_new_inode(dentry);
 
53
        //inode = ERR_PTR(-1);
 
54
        if (!IS_ERR(inode)) {
 
55
                d_instantiate(dentry, inode);
 
56
                dir = dentry->d_parent->d_inode;
 
57
                /* or always cpup dir mtime? */
 
58
                if (ibstart(dir) == dbstart(dentry))
 
59
                        au_cpup_attr_timesizes(dir);
 
60
                dir->i_version++;
 
61
                return 0; /* success */
 
62
        }
 
63
 
 
64
        err = PTR_ERR(inode);
 
65
        if (!wh_dentry)
 
66
                goto out;
 
67
 
 
68
        /* revert */
 
69
        lkup.nfsmnt = au_nfsmnt(dentry->d_sb, bwh);
 
70
        wh = simple_create_wh(dentry, bwh, wh_dentry->d_parent, &lkup);
 
71
        //wh = ERR_PTR(-1);
 
72
        rerr = PTR_ERR(wh);
 
73
        if (!IS_ERR(wh)) {
 
74
                dput(wh);
 
75
                goto out;
 
76
        }
 
77
        IOErr("%.*s reverting whiteout failed(%d, %d)\n",
 
78
              DLNPair(dentry), err, rerr);
 
79
        err = -EIO;
 
80
 
 
81
 out:
 
82
        TraceErr(err);
 
83
        return err;
 
84
}
 
85
 
 
86
/*
 
87
 * initial procedure of adding a new entry.
 
88
 * prepare writable branch and the parent dir, lock it,
 
89
 * lookup whiteout for the new entry.
 
90
 */
 
91
static struct dentry *
 
92
lock_hdir_lkup_wh(struct dentry *dentry, struct dtime *dt,
 
93
                  struct dentry *src_dentry, int do_lock_srcdir)
 
94
{
 
95
        struct dentry *wh_dentry, *parent, *hidden_parent;
 
96
        int err;
 
97
        aufs_bindex_t bstart, bcpup;
 
98
        struct inode *dir, *h_dir;
 
99
        struct lkup_args lkup;
 
100
 
 
101
        LKTRTrace("%.*s, src %p\n", DLNPair(dentry), src_dentry);
 
102
 
 
103
        parent = dentry->d_parent;
 
104
        bstart = dbstart(dentry);
 
105
        bcpup = err = wr_dir(dentry, 1, src_dentry, -1, do_lock_srcdir);
 
106
        //err = -1;
 
107
        wh_dentry = ERR_PTR(err);
 
108
        if (unlikely(err < 0))
 
109
                goto out;
 
110
 
 
111
        dir = parent->d_inode;
 
112
        hidden_parent = au_h_dptr_i(parent, bcpup);
 
113
        h_dir = hidden_parent->d_inode;
 
114
        hdir_lock(h_dir, dir, bcpup);
 
115
        if (dt)
 
116
                dtime_store(dt, parent, hidden_parent);
 
117
        if (/* bcpup != bstart || */ bcpup != dbwh(dentry))
 
118
                return NULL; /* success */
 
119
 
 
120
        lkup.nfsmnt = au_nfsmnt(parent->d_sb, bcpup);
 
121
        lkup.dlgt = need_dlgt(parent->d_sb);
 
122
        wh_dentry = lkup_wh(hidden_parent, &dentry->d_name, &lkup);
 
123
        //wh_dentry = ERR_PTR(-1);
 
124
        if (IS_ERR(wh_dentry))
 
125
                hdir_unlock(h_dir, dir, bcpup);
 
126
 
 
127
 out:
 
128
        TraceErrPtr(wh_dentry);
 
129
        return wh_dentry;
 
130
}
 
131
 
 
132
/* ---------------------------------------------------------------------- */
 
133
 
 
134
enum {Mknod, Symlink, Creat};
 
135
struct simple_arg {
 
136
        int type;
 
137
        union {
 
138
                struct {
 
139
                        int mode;
 
140
                        struct nameidata *nd;
 
141
                } c;
 
142
                struct {
 
143
                        const char *symname;
 
144
                } s;
 
145
                struct {
 
146
                        int mode;
 
147
                        dev_t dev;
 
148
                } m;
 
149
        } u;
 
150
};
 
151
 
 
152
static int add_simple(struct inode *dir, struct dentry *dentry,
 
153
                      struct simple_arg *arg)
 
154
{
 
155
        int err, dlgt;
 
156
        struct dentry *hidden_dentry, *hidden_parent, *wh_dentry, *parent;
 
157
        struct inode *hidden_dir;
 
158
        struct dtime dt;
 
159
 
 
160
        LKTRTrace("type %d, %.*s\n", arg->type, DLNPair(dentry));
 
161
        IMustLock(dir);
 
162
 
 
163
        aufs_read_lock(dentry, AUFS_D_WLOCK);
 
164
        parent = dentry->d_parent;
 
165
        di_write_lock_parent(parent);
 
166
        wh_dentry = lock_hdir_lkup_wh(dentry, &dt, /*src_dentry*/NULL,
 
167
                                      /*do_lock_srcdir*/0);
 
168
        //wh_dentry = ERR_PTR(-1);
 
169
        err = PTR_ERR(wh_dentry);
 
170
        if (IS_ERR(wh_dentry))
 
171
                goto out;
 
172
 
 
173
        hidden_dentry = au_h_dptr(dentry);
 
174
        hidden_parent = hidden_dentry->d_parent;
 
175
        hidden_dir = hidden_parent->d_inode;
 
176
        IMustLock(hidden_dir);
 
177
        dlgt = need_dlgt(dir->i_sb);
 
178
 
 
179
#if 1 // partial testing
 
180
        switch (arg->type) {
 
181
        case Creat:
 
182
#if 0
 
183
                if (arg->u.c.nd) {
 
184
                        struct nameidata fake_nd;
 
185
                        fake_nd = *arg->u.c.nd;
 
186
                        fake_nd.dentry = dget(hidden_parent);
 
187
                        fake_nd.mnt = sbr_mnt(dentry->d_sb, dbstart(dentry));
 
188
                        mntget(fake_nd.mnt);
 
189
                        err = vfsub_create(hidden_dir, hidden_dentry,
 
190
                                           arg->u.c.mode, &fake_nd, dlgt);
 
191
                        path_release(&fake_nd);
 
192
                } else
 
193
#endif
 
194
                        err = vfsub_create(hidden_dir, hidden_dentry,
 
195
                                           arg->u.c.mode, NULL, dlgt);
 
196
                break;
 
197
        case Symlink:
 
198
                err = vfsub_symlink(hidden_dir, hidden_dentry,
 
199
                                    arg->u.s.symname, S_IALLUGO, dlgt);
 
200
                break;
 
201
        case Mknod:
 
202
                err = vfsub_mknod(hidden_dir, hidden_dentry,
 
203
                                  arg->u.m.mode, arg->u.m.dev, dlgt);
 
204
                break;
 
205
        default:
 
206
                BUG();
 
207
        }
 
208
#else
 
209
        err = -1;
 
210
#endif
 
211
        if (!err)
 
212
                err = epilog(wh_dentry, dentry);
 
213
        //err = -1;
 
214
 
 
215
        /* revert */
 
216
        if (unlikely(err && hidden_dentry->d_inode)) {
 
217
                int rerr;
 
218
                rerr = vfsub_unlink(hidden_dir, hidden_dentry, dlgt);
 
219
                //rerr = -1;
 
220
                if (rerr) {
 
221
                        IOErr("%.*s revert failure(%d, %d)\n",
 
222
                              DLNPair(dentry), err, rerr);
 
223
                        err = -EIO;
 
224
                }
 
225
                dtime_revert(&dt, !CPUP_LOCKED_GHDIR);
 
226
                d_drop(dentry);
 
227
        }
 
228
 
 
229
        hdir_unlock(hidden_dir, dir, dbstart(dentry));
 
230
        dput(wh_dentry);
 
231
 
 
232
 out:
 
233
        if (unlikely(err)) {
 
234
                au_update_dbstart(dentry);
 
235
                d_drop(dentry);
 
236
        }
 
237
        di_write_unlock(parent);
 
238
        aufs_read_unlock(dentry, AUFS_D_WLOCK);
 
239
        TraceErr(err);
 
240
        return err;
 
241
}
 
242
 
 
243
int aufs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
 
244
{
 
245
        struct simple_arg arg = {
 
246
                .type = Mknod,
 
247
                .u.m = {.mode = mode, .dev = dev}
 
248
        };
 
249
        return add_simple(dir, dentry, &arg);
 
250
}
 
251
 
 
252
int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
 
253
{
 
254
        struct simple_arg arg = {
 
255
                .type = Symlink,
 
256
                .u.s.symname = symname
 
257
        };
 
258
        return add_simple(dir, dentry, &arg);
 
259
}
 
260
 
 
261
int aufs_create(struct inode *dir, struct dentry *dentry, int mode,
 
262
                struct nameidata *nd)
 
263
{
 
264
        struct simple_arg arg = {
 
265
                .type = Creat,
 
266
                .u.c = {.mode = mode, .nd = nd}
 
267
        };
 
268
        return add_simple(dir, dentry, &arg);
 
269
}
 
270
 
 
271
/* ---------------------------------------------------------------------- */
 
272
 
 
273
struct link_arg {
 
274
        aufs_bindex_t bdst, bsrc;
 
275
        int issamedir, dlgt;
 
276
        struct dentry *src_parent, *parent, *hidden_dentry;
 
277
        struct inode *hidden_dir, *inode;
 
278
};
 
279
 
 
280
static int cpup_before_link(struct dentry *src_dentry, struct inode *dir,
 
281
                            struct link_arg *a)
 
282
{
 
283
        int err;
 
284
        unsigned int flags;
 
285
        struct inode *hi, *hdir = NULL, *src_dir;
 
286
 
 
287
        TraceEnter();
 
288
 
 
289
        err = 0;
 
290
        flags = au_flags_cpup(CPUP_DTIME, a->parent);
 
291
        src_dir = a->src_parent->d_inode;
 
292
        if (!a->issamedir) {
 
293
                // todo: dead lock?
 
294
                di_read_lock_parent2(a->src_parent, AUFS_I_RLOCK);
 
295
                // this temporary unlock/lock is safe
 
296
                hdir_unlock(a->hidden_dir, dir, a->bdst);
 
297
                err = test_and_cpup_dirs(src_dentry, a->bdst, a->parent);
 
298
                //err = -1;
 
299
                if (!err) {
 
300
                        hdir = au_h_iptr_i(src_dir, a->bdst);
 
301
                        hdir_lock(hdir, src_dir, a->bdst);
 
302
                        flags = au_flags_cpup(CPUP_DTIME, a->src_parent);
 
303
                }
 
304
        }
 
305
 
 
306
        if (!err) {
 
307
                hi = au_h_dptr(src_dentry)->d_inode;
 
308
                hi_lock_child(hi);
 
309
                err = sio_cpup_simple(src_dentry, a->bdst, -1, flags);
 
310
                //err = -1;
 
311
                i_unlock(hi);
 
312
        }
 
313
 
 
314
        if (!a->issamedir) {
 
315
                if (hdir)
 
316
                        hdir_unlock(hdir, src_dir, a->bdst);
 
317
                hdir_lock(a->hidden_dir, dir, a->bdst);
 
318
                di_read_unlock(a->src_parent, AUFS_I_RLOCK);
 
319
        }
 
320
 
 
321
        TraceErr(err);
 
322
        return err;
 
323
}
 
324
 
 
325
static int cpup_or_link(struct dentry *src_dentry, struct link_arg *a)
 
326
{
 
327
        int err;
 
328
        struct inode *inode, *h_inode, *h_dst_inode;
 
329
        struct dentry *h_dentry;
 
330
        aufs_bindex_t bstart;
 
331
        struct super_block *sb;
 
332
 
 
333
        TraceEnter();
 
334
 
 
335
        sb = src_dentry->d_sb;
 
336
        inode = src_dentry->d_inode;
 
337
        h_dentry = au_h_dptr(src_dentry);
 
338
        h_inode = h_dentry->d_inode;
 
339
        bstart = ibstart(inode);
 
340
        h_dst_inode = NULL;
 
341
        if (bstart <= a->bdst)
 
342
                h_dst_inode = au_h_iptr_i(inode, a->bdst);
 
343
 
 
344
        if (!h_dst_inode) {
 
345
                /* copyup src_dentry as the name of dentry. */
 
346
                set_dbstart(src_dentry, a->bdst);
 
347
                set_h_dptr(src_dentry, a->bdst, dget(a->hidden_dentry));
 
348
                hi_lock_child(h_inode);
 
349
                err = sio_cpup_single(src_dentry, a->bdst, a->bsrc, -1,
 
350
                                      au_flags_cpup(!CPUP_DTIME, a->parent));
 
351
                //err = -1;
 
352
                i_unlock(h_inode);
 
353
                set_h_dptr(src_dentry, a->bdst, NULL);
 
354
                set_dbstart(src_dentry, a->bsrc);
 
355
        } else {
 
356
                /* the inode of src_dentry already exists on a.bdst branch */
 
357
                h_dentry = d_find_alias(h_dst_inode);
 
358
                if (h_dentry) {
 
359
                        err = vfsub_link(h_dentry, a->hidden_dir,
 
360
                                         a->hidden_dentry, a->dlgt);
 
361
                        dput(h_dentry);
 
362
                } else {
 
363
                        IOErr("no dentry found for i%lu on b%d\n",
 
364
                              h_dst_inode->i_ino, a->bdst);
 
365
                        err = -EIO;
 
366
                }
 
367
        }
 
368
 
 
369
        if (!err)
 
370
                append_plink(sb, a->inode, a->hidden_dentry, a->bdst);
 
371
 
 
372
        TraceErr(err);
 
373
        return err;
 
374
}
 
375
 
 
376
int aufs_link(struct dentry *src_dentry, struct inode *dir,
 
377
              struct dentry *dentry)
 
378
{
 
379
        int err, rerr;
 
380
        struct dentry *hidden_parent, *wh_dentry, *hidden_src_dentry;
 
381
        struct dtime dt;
 
382
        struct link_arg a;
 
383
        struct super_block *sb;
 
384
 
 
385
        LKTRTrace("src %.*s, i%lu, dst %.*s\n",
 
386
                  DLNPair(src_dentry), dir->i_ino, DLNPair(dentry));
 
387
        IMustLock(dir);
 
388
        IMustLock(src_dentry->d_inode);
 
389
 
 
390
        aufs_read_and_write_lock2(dentry, src_dentry, /*isdir*/0);
 
391
        a.src_parent = src_dentry->d_parent;
 
392
        a.parent = dentry->d_parent;
 
393
        a.issamedir = (a.src_parent == a.parent);
 
394
        di_write_lock_parent(a.parent);
 
395
        wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, !a.issamedir);
 
396
        //wh_dentry = ERR_PTR(-1);
 
397
        err = PTR_ERR(wh_dentry);
 
398
        if (IS_ERR(wh_dentry))
 
399
                goto out;
 
400
 
 
401
        a.inode = src_dentry->d_inode;
 
402
        a.hidden_dentry = au_h_dptr(dentry);
 
403
        hidden_parent = a.hidden_dentry->d_parent;
 
404
        a.hidden_dir = hidden_parent->d_inode;
 
405
        IMustLock(a.hidden_dir);
 
406
 
 
407
        err = 0;
 
408
        sb = dentry->d_sb;
 
409
        a.dlgt = need_dlgt(sb);
 
410
 
 
411
        //todo: minor optimize, their sb may be same while their bindex differs.
 
412
        a.bsrc = dbstart(src_dentry);
 
413
        a.bdst = dbstart(dentry);
 
414
        hidden_src_dentry = au_h_dptr(src_dentry);
 
415
        if (unlikely(!au_flag_test(sb, AuFlag_PLINK))) {
 
416
                /*
 
417
                 * copyup src_dentry to the branch we process,
 
418
                 * and then link(2) to it.
 
419
                 * gave up 'pseudo link by cpup' approach,
 
420
                 * since nlink may be one and some applications will not work.
 
421
                 */
 
422
                if (a.bdst < a.bsrc
 
423
                    /* && hidden_src_dentry->d_sb != a.hidden_dentry->d_sb */)
 
424
                        err = cpup_before_link(src_dentry, dir, &a);
 
425
                if (!err) {
 
426
                        hidden_src_dentry = au_h_dptr(src_dentry);
 
427
                        err = vfsub_link(hidden_src_dentry, a.hidden_dir,
 
428
                                         a.hidden_dentry, a.dlgt);
 
429
                        //err = -1;
 
430
                }
 
431
        } else {
 
432
                if (a.bdst < a.bsrc
 
433
                    /* && hidden_src_dentry->d_sb != a.hidden_dentry->d_sb */)
 
434
                        err = cpup_or_link(src_dentry, &a);
 
435
                else {
 
436
                        hidden_src_dentry = au_h_dptr(src_dentry);
 
437
                        err = vfsub_link(hidden_src_dentry, a.hidden_dir,
 
438
                                         a.hidden_dentry, a.dlgt);
 
439
                        //err = -1;
 
440
                }
 
441
        }
 
442
        if (unlikely(err))
 
443
                goto out_unlock;
 
444
        if (wh_dentry) {
 
445
                err = au_unlink_wh_dentry(a.hidden_dir, wh_dentry, dentry,
 
446
                                          a.dlgt);
 
447
                //err = -1;
 
448
                if (unlikely(err))
 
449
                        goto out_revert;
 
450
        }
 
451
 
 
452
        dir->i_version++;
 
453
        if (ibstart(dir) == dbstart(dentry))
 
454
                au_cpup_attr_timesizes(dir);
 
455
        if (!d_unhashed(a.hidden_dentry)
 
456
            /* || hidden_old_inode->i_nlink <= nlink */
 
457
            /* || SB_NFS(hidden_src_dentry->d_sb) */) {
 
458
                dentry->d_inode = igrab(a.inode);
 
459
                d_instantiate(dentry, a.inode);
 
460
                a.inode->i_nlink++;
 
461
                a.inode->i_ctime = dir->i_ctime;
 
462
        } else
 
463
                /* nfs case (< 2.6.15) */
 
464
                d_drop(dentry);
 
465
#if 0
 
466
        au_debug_on();
 
467
        DbgInode(a.inode);
 
468
        au_debug_off();
 
469
        {
 
470
                aufs_bindex_t i;
 
471
                for (i = ibstart(a.inode); i <= ibend(a.inode); i++) {
 
472
                        struct xino xino;
 
473
                        struct inode *hi;
 
474
                        hi = au_h_iptr_i(a.inode, i);
 
475
                        if (hi) {
 
476
                                xino_read(sb, i, hi->i_ino, &xino);
 
477
                                Dbg("hi%lu, i%lu\n", hi->i_ino, xino.ino);
 
478
                        }
 
479
                }
 
480
        }
 
481
#endif
 
482
        goto out_unlock; /* success */
 
483
 
 
484
 out_revert:
 
485
#if 0 // remove
 
486
        if (d_unhashed(a.hidden_dentry)) {
 
487
                /* hardlink on nfs (< 2.6.15) */
 
488
                struct dentry *d;
 
489
                const struct qstr *name = &a.hidden_dentry->d_name;
 
490
                DEBUG_ON(a.hidden_dentry->d_parent->d_inode != a.hidden_dir);
 
491
                // do not superio.
 
492
                d = lkup_one(name->name, a.hidden_dentry->d_parent, name->len,
 
493
                             au_nfsmnt(sb, a.bdst)??, need_dlgt(sb));
 
494
                rerr = PTR_ERR(d);
 
495
                if (IS_ERR(d))
 
496
                        goto out_rerr;
 
497
                dput(a.hidden_dentry);
 
498
                a.hidden_dentry = d;
 
499
                DEBUG_ON(!d->d_inode);
 
500
        }
 
501
#endif
 
502
        rerr = vfsub_unlink(a.hidden_dir, a.hidden_dentry, a.dlgt);
 
503
        //rerr = -1;
 
504
        if (!rerr)
 
505
                goto out_dt;
 
506
// out_rerr:
 
507
        IOErr("%.*s reverting failed(%d, %d)\n", DLNPair(dentry), err, rerr);
 
508
        err = -EIO;
 
509
 out_dt:
 
510
        d_drop(dentry);
 
511
        dtime_revert(&dt, !CPUP_LOCKED_GHDIR);
 
512
 out_unlock:
 
513
        hdir_unlock(a.hidden_dir, dir, a.bdst);
 
514
        dput(wh_dentry);
 
515
 out:
 
516
        if (unlikely(err)) {
 
517
                au_update_dbstart(dentry);
 
518
                d_drop(dentry);
 
519
        }
 
520
        di_write_unlock(a.parent);
 
521
        aufs_read_and_write_unlock2(dentry, src_dentry);
 
522
        TraceErr(err);
 
523
        return err;
 
524
}
 
525
 
 
526
int aufs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
 
527
{
 
528
        int err, rerr, diropq, dlgt;
 
529
        struct dentry *hidden_dentry, *hidden_parent, *wh_dentry, *parent,
 
530
                *opq_dentry;
 
531
        struct inode *hidden_dir, *hidden_inode;
 
532
        struct dtime dt;
 
533
        aufs_bindex_t bindex;
 
534
        struct super_block *sb;
 
535
 
 
536
        LKTRTrace("i%lu, %.*s, mode 0%o\n", dir->i_ino, DLNPair(dentry), mode);
 
537
        IMustLock(dir);
 
538
 
 
539
        aufs_read_lock(dentry, AUFS_D_WLOCK);
 
540
        parent = dentry->d_parent;
 
541
        di_write_lock_parent(parent);
 
542
        wh_dentry = lock_hdir_lkup_wh(dentry, &dt, /*src_dentry*/NULL,
 
543
                                      /*do_lock_srcdir*/0);
 
544
        //wh_dentry = ERR_PTR(-1);
 
545
        err = PTR_ERR(wh_dentry);
 
546
        if (IS_ERR(wh_dentry))
 
547
                goto out;
 
548
 
 
549
        sb = dentry->d_sb;
 
550
        bindex = dbstart(dentry);
 
551
        hidden_dentry = au_h_dptr(dentry);
 
552
        hidden_parent = hidden_dentry->d_parent;
 
553
        hidden_dir = hidden_parent->d_inode;
 
554
        IMustLock(hidden_dir);
 
555
        dlgt = need_dlgt(sb);
 
556
 
 
557
        err = vfsub_mkdir(hidden_dir, hidden_dentry, mode, dlgt);
 
558
        //err = -1;
 
559
        if (unlikely(err))
 
560
                goto out_unlock;
 
561
        hidden_inode = hidden_dentry->d_inode;
 
562
 
 
563
        /* make the dir opaque */
 
564
        diropq = 0;
 
565
        if (unlikely(wh_dentry || au_flag_test(sb, AuFlag_ALWAYS_DIROPQ))) {
 
566
                hi_lock_child(hidden_inode);
 
567
                opq_dentry = create_diropq(dentry, bindex, dlgt);
 
568
                //opq_dentry = ERR_PTR(-1);
 
569
                i_unlock(hidden_inode);
 
570
                err = PTR_ERR(opq_dentry);
 
571
                if (IS_ERR(opq_dentry))
 
572
                        goto out_dir;
 
573
                dput(opq_dentry);
 
574
                diropq = 1;
 
575
        }
 
576
 
 
577
        err = epilog(wh_dentry, dentry);
 
578
        //err = -1;
 
579
        if (!err) {
 
580
                dir->i_nlink++;
 
581
                goto out_unlock; /* success */
 
582
        }
 
583
 
 
584
        /* revert */
 
585
        if (unlikely(diropq)) {
 
586
                LKTRLabel(revert opq);
 
587
                hi_lock_child(hidden_inode);
 
588
                rerr = remove_diropq(dentry, bindex, dlgt);
 
589
                //rerr = -1;
 
590
                i_unlock(hidden_inode);
 
591
                if (rerr) {
 
592
                        IOErr("%.*s reverting diropq failed(%d, %d)\n",
 
593
                              DLNPair(dentry), err, rerr);
 
594
                        err = -EIO;
 
595
                }
 
596
        }
 
597
 
 
598
 out_dir:
 
599
        LKTRLabel(revert dir);
 
600
        rerr = vfsub_rmdir(hidden_dir, hidden_dentry, dlgt);
 
601
        //rerr = -1;
 
602
        if (rerr) {
 
603
                IOErr("%.*s reverting dir failed(%d, %d)\n",
 
604
                      DLNPair(dentry), err, rerr);
 
605
                err = -EIO;
 
606
        }
 
607
        d_drop(dentry);
 
608
        dtime_revert(&dt, /*fake flag*/CPUP_LOCKED_GHDIR);
 
609
 out_unlock:
 
610
        hdir_unlock(hidden_dir, dir, bindex);
 
611
        dput(wh_dentry);
 
612
 out:
 
613
        if (unlikely(err)) {
 
614
                au_update_dbstart(dentry);
 
615
                d_drop(dentry);
 
616
        }
 
617
        di_write_unlock(parent);
 
618
        aufs_read_unlock(dentry, AUFS_D_WLOCK);
 
619
        TraceErr(err);
 
620
        return err;
 
621
}