2
* Copyright (C) 2005-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
20
* copy-up functions, see wbr_policy.c for copy-down
22
* $Id: cpup.c,v 1.4 2008/05/04 23:51:40 sfjro Exp $
25
#include <linux/fs_stack.h>
26
#include <linux/uaccess.h>
29
/* violent cpup_attr_*() functions don't care inode lock */
30
void au_cpup_attr_timesizes(struct inode *inode)
32
struct inode *h_inode;
34
LKTRTrace("i%lu\n", inode->i_ino);
36
h_inode = au_h_iptr(inode, au_ibstart(inode));
38
//IMustLock(!h_inode);
40
fsstack_copy_attr_times(inode, h_inode);
41
spin_lock(&inode->i_lock);
42
fsstack_copy_inode_size(inode, h_inode);
43
spin_unlock(&inode->i_lock);
46
void au_cpup_attr_nlink(struct inode *inode)
48
struct inode *h_inode;
50
LKTRTrace("i%lu\n", inode->i_ino);
52
AuDebugOn(!inode->i_mode);
54
h_inode = au_h_iptr(inode, au_ibstart(inode));
55
inode->i_nlink = h_inode->i_nlink;
58
* fewer nlink makes find(1) noisy, but larger nlink doesn't.
59
* it may includes whplink directory.
61
if (unlikely(S_ISDIR(h_inode->i_mode))) {
62
aufs_bindex_t bindex, bend;
63
bend = au_ibend(inode);
64
for (bindex = au_ibstart(inode) + 1; bindex <= bend; bindex++) {
65
h_inode = au_h_iptr(inode, bindex);
67
au_add_nlink(inode, h_inode);
72
void au_cpup_attr_changeable(struct inode *inode)
74
struct inode *h_inode;
76
LKTRTrace("i%lu\n", inode->i_ino);
78
h_inode = au_h_iptr(inode, au_ibstart(inode));
81
inode->i_mode = h_inode->i_mode;
82
inode->i_uid = h_inode->i_uid;
83
inode->i_gid = h_inode->i_gid;
84
au_cpup_attr_timesizes(inode);
87
inode->i_flags = h_inode->i_flags;
90
void au_cpup_igen(struct inode *inode, struct inode *h_inode)
92
inode->i_generation = h_inode->i_generation;
93
au_ii(inode)->ii_hsb1 = h_inode->i_sb;
96
void au_cpup_attr_all(struct inode *inode)
98
struct inode *h_inode;
100
LKTRTrace("i%lu\n", inode->i_ino);
102
h_inode = au_h_iptr(inode, au_ibstart(inode));
105
au_cpup_attr_changeable(inode);
106
if (inode->i_nlink > 0)
107
au_cpup_attr_nlink(inode);
109
switch (inode->i_mode & S_IFMT) {
112
inode->i_rdev = au_h_rdev(h_inode, /*h_mnt*/NULL,
115
inode->i_blkbits = h_inode->i_blkbits;
116
au_cpup_igen(inode, h_inode);
119
/* ---------------------------------------------------------------------- */
121
/* Note: dt_dentry and dt_hidden_dentry are not dget/dput-ed */
123
/* keep the timestamps of the parent dir when cpup */
124
void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
125
struct dentry *h_dentry, struct au_hinode *hdir)
129
LKTRTrace("%.*s, hdir %d\n", AuDLNPair(dentry), !!hdir);
130
AuDebugOn(!dentry || !h_dentry || !h_dentry->d_inode);
132
dt->dt_dentry = dentry;
133
dt->dt_h_dentry = h_dentry;
135
inode = h_dentry->d_inode;
136
dt->dt_atime = inode->i_atime;
137
dt->dt_mtime = inode->i_mtime;
141
void au_dtime_revert(struct au_dtime *dt)
145
struct au_hin_ignore ign;
146
struct vfsub_args vargs;
148
LKTRTrace("%.*s\n", AuDLNPair(dt->dt_dentry));
150
attr.ia_atime = dt->dt_atime;
151
attr.ia_mtime = dt->dt_mtime;
152
attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
153
| ATTR_ATIME | ATTR_ATIME_SET;
155
vfsub_args_init(&vargs, &ign,
156
au_opt_test_dlgt(au_mntflags(dt->dt_dentry->d_sb)), 0);
157
if (unlikely(dt->dt_hdir))
158
vfsub_ign_hinode(&vargs, IN_ATTRIB, dt->dt_hdir);
159
err = vfsub_notify_change(dt->dt_h_dentry, &attr, &vargs);
161
AuWarn("restoring timestamps failed(%d). ignored\n", err);
164
/* ---------------------------------------------------------------------- */
166
static noinline_for_stack int
167
cpup_iattr(struct dentry *h_dst, struct dentry *h_src, int dlgt)
171
struct inode *h_isrc, *h_idst;
172
struct vfsub_args vargs;
174
LKTRTrace("%.*s\n", AuDLNPair(h_dst));
175
h_idst = h_dst->d_inode;
177
h_isrc = h_src->d_inode;
180
ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID
181
| ATTR_ATIME | ATTR_MTIME
182
| ATTR_ATIME_SET | ATTR_MTIME_SET;
183
ia.ia_mode = h_isrc->i_mode;
184
ia.ia_uid = h_isrc->i_uid;
185
ia.ia_gid = h_isrc->i_gid;
186
ia.ia_atime = h_isrc->i_atime;
187
ia.ia_mtime = h_isrc->i_mtime;
188
sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
190
vfsub_args_init(&vargs, NULL, dlgt, /*force_unlink*/0);
191
err = vfsub_notify_change(h_dst, &ia, &vargs);
192
//if (LktrCond) err = -1;
194
/* is this nfs only? */
195
if (!err && sbits && au_test_nfs(h_dst->d_sb)) {
196
ia.ia_valid = ATTR_FORCE | ATTR_MODE;
197
ia.ia_mode = h_isrc->i_mode;
198
err = vfsub_notify_change(h_dst, &ia, &vargs);
202
h_idst->i_flags = h_isrc->i_flags; //??
209
* to support a sparse file which is opened with O_APPEND,
210
* we need to close the file.
212
static noinline_for_stack int
213
cpup_regular(struct dentry *dentry, aufs_bindex_t bdst, aufs_bindex_t bsrc,
217
struct super_block *sb;
218
struct inode *h_inode;
221
aufs_bindex_t bindex;
223
struct dentry *dentry;
225
void *label, *label_file;
229
.flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
232
.label_file = &&out_src_file
236
.flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
238
.label = &&out_src_file,
239
.label_file = &&out_dst_file
243
LKTRTrace("dentry %.*s, bdst %d, bsrc %d, len %lld\n",
244
AuDLNPair(dentry), bdst, bsrc, len);
245
AuDebugOn(bsrc <= bdst);
248
AuDebugOn(au_test_ro(sb, bdst, dentry->d_inode));
249
/* bsrc branch can be ro/rw. */
252
for (i = 0; i < 2; i++, h++) {
253
h->dentry = au_h_dptr(dentry, h->bindex);
254
AuDebugOn(!h->dentry);
255
h_inode = h->dentry->d_inode;
256
AuDebugOn(!h_inode || !S_ISREG(h_inode->i_mode));
257
h->file = au_h_open(dentry, h->bindex, h->flags, /*file*/NULL);
259
//{fput(h->file);au_sbr_put(sb, h->bindex);h->file=ERR_PTR(-1);}
260
err = PTR_ERR(h->file);
264
if (unlikely(!h->file->f_op))
268
/* stop updating while we copyup */
269
IMustLock(hidden[SRC].dentry->d_inode);
270
err = au_copy_file(hidden[DST].file, hidden[SRC].file, len, sb);
273
fput(hidden[DST].file);
274
au_sbr_put(sb, hidden[DST].bindex);
276
fput(hidden[SRC].file);
277
au_sbr_put(sb, hidden[SRC].bindex);
283
static noinline_for_stack int
284
au_do_cpup_regular(struct dentry *dentry, aufs_bindex_t bdst,
285
aufs_bindex_t bsrc, loff_t len, struct inode *h_inode,
286
struct inode *h_dir, struct dentry *h_dst, int dlgt)
290
struct vfsub_args vargs;
295
l = i_size_read(h_inode);
296
if (len == -1 || l < len)
299
err = cpup_regular(dentry, bdst, bsrc, len);
300
//if (LktrCond) err = -1;
302
goto out; /* success */
304
vfsub_args_init(&vargs, NULL, dlgt, 0);
305
rerr = vfsub_unlink(h_dir, h_dst, &vargs);
307
AuIOErr("failed unlinking cpup-ed %.*s(%d, %d)\n",
308
AuDLNPair(h_dst), err, rerr);
317
static noinline_for_stack int
318
au_do_cpup_symlink(struct dentry *h_dst, struct dentry *h_src,
319
struct inode *h_dir, umode_t mode, int dlgt)
329
//if (LktrCond) {__putname(sym); sym = NULL;}
335
symlen = h_src->d_inode->i_op->readlink(h_src, (char __user *)sym,
338
//if (LktrCond) err = symlen = -1;
343
err = vfsub_symlink(h_dir, h_dst, sym, mode, dlgt);
345
//{vfs_unlink(h_dir, h_dst); err = -1;}
354
/* return with hidden dst inode is locked */
355
static noinline_for_stack int
356
cpup_entry(struct dentry *dentry, aufs_bindex_t bdst, aufs_bindex_t bsrc,
357
loff_t len, unsigned int flags, int dlgt)
359
int err, isdir, hinotify;
360
struct dentry *h_src, *h_dst, *h_parent, *parent;
361
struct inode *h_inode, *h_dir;
364
struct super_block *sb;
365
struct au_hinode *hgdir;
366
const int do_dt = au_ftest_cpup(flags, DTIME);
367
unsigned int mnt_flags;
369
LKTRTrace("%.*s, i%lu, bdst %d, bsrc %d, len %Ld, dtime %u\n",
370
AuDLNPair(dentry), dentry->d_inode->i_ino, bdst, bsrc, len,
373
AuDebugOn(bdst >= bsrc || au_test_ro(sb, bdst, NULL));
374
/* bsrc branch can be ro/rw. */
376
h_src = au_h_dptr(dentry, bsrc);
378
h_inode = h_src->d_inode;
381
/* stop referencing while we are creating */
382
parent = dget_parent(dentry);
383
h_dst = au_h_dptr(dentry, bdst);
384
AuDebugOn(h_dst && h_dst->d_inode);
385
h_parent = h_dst->d_parent; /* dir inode is locked */
386
h_dir = h_parent->d_inode;
389
mnt_flags = au_mntflags(sb);
390
hinotify = !!au_opt_test(mnt_flags, UDBA_INOTIFY);
393
if (unlikely(hinotify && !IS_ROOT(parent))) {
394
struct dentry *gparent;
395
gparent = dget_parent(parent);
396
hgdir = au_hi(gparent->d_inode, bdst);
399
au_dtime_store(&dt, parent, h_parent, hgdir);
403
mode = h_inode->i_mode;
404
switch (mode & S_IFMT) {
406
/* stop updating while we are referencing */
408
err = au_h_create(h_dir, h_dst, mode | S_IWUSR, dlgt, NULL,
409
au_nfsmnt(sb, bdst));
410
//if (LktrCond) {vfs_unlink(h_dir, h_dst); err = -1;}
412
err = au_do_cpup_regular(dentry, bdst, bsrc, len,
413
h_inode, h_dir, h_dst, dlgt);
417
err = vfsub_mkdir(h_dir, h_dst, mode, dlgt);
418
//if (LktrCond) {vfs_rmdir(h_dir, h_dst); err = -1;}
420
/* setattr case: dir is not locked */
421
if (0 && au_ibstart(parent->d_inode) == bdst)
422
au_cpup_attr_nlink(parent->d_inode);
423
au_cpup_attr_nlink(dentry->d_inode);
427
err = au_do_cpup_symlink(h_dst, h_src, h_dir, mode, dlgt);
431
AuDebugOn(!capable(CAP_MKNOD));
435
err = vfsub_mknod(h_dir, h_dst, mode,
436
au_h_rdev(h_inode, /*h_mnt*/NULL, h_src),
438
//if (LktrCond) {vfs_unlink(h_dir, h_dst); err = -1;}
441
AuIOErr("Unknown inode type 0%o\n", mode);
445
//todo: should it be always?
446
if (unlikely(hinotify
448
&& au_opt_test(mnt_flags, XINO)
449
&& h_inode->i_nlink == 1
451
au_xino_write0(sb, bsrc, h_inode->i_ino, /*ino*/0);
452
/* ignore this error */
455
au_dtime_revert(&dt);
462
* copyup the @dentry from @bsrc to @bdst.
463
* the caller must set the both of hidden dentries.
464
* @len is for truncating when it is -1 copyup the entire file.
466
int au_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
467
aufs_bindex_t bsrc, loff_t len, unsigned int flags)
469
int err, rerr, isdir, dlgt, plink;
470
struct dentry *h_src, *h_dst, *parent, *h_parent;
471
struct inode *dst_inode, *h_dir, *inode;
472
struct super_block *sb;
473
aufs_bindex_t old_ibstart;
475
struct vfsub_args vargs;
476
struct au_hinode *hgdir;
477
unsigned int mnt_flags;
479
LKTRTrace("%.*s, i%lu, bdst %d, bsrc %d, len %Ld, flags 0x%x\n",
480
AuDLNPair(dentry), dentry->d_inode->i_ino, bdst, bsrc, len,
483
AuDebugOn(bsrc <= bdst);
484
h_dst = au_h_dptr(dentry, bdst);
485
AuDebugOn(!h_dst || h_dst->d_inode);
486
h_parent = h_dst->d_parent; /* dir inode is locked */
487
h_dir = h_parent->d_inode;
489
h_src = au_h_dptr(dentry, bsrc);
490
AuDebugOn(!h_src || !h_src->d_inode);
491
inode = dentry->d_inode;
492
IiMustWriteLock(inode);
493
parent = dget_parent(dentry);
495
mnt_flags = au_mntflags(sb);
496
dlgt = !!au_opt_test_dlgt(mnt_flags);
497
plink = !!au_opt_test(mnt_flags, PLINK);
498
dst_inode = au_h_iptr(inode, bdst);
499
if (unlikely(dst_inode)) {
500
if (unlikely(!plink)) {
502
AuIOErr("i%lu exists on a upper branch "
503
"but plink is disabled\n", inode->i_ino);
507
if (dst_inode->i_nlink) {
508
h_src = au_plink_lkup(sb, bdst, inode);
509
err = PTR_ERR(h_src);
512
AuDebugOn(!h_src->d_inode);
513
err = vfsub_link(h_src, h_dir, h_dst, dlgt);
519
au_update_brange(inode, 1);
522
old_ibstart = au_ibstart(inode);
523
err = cpup_entry(dentry, bdst, bsrc, len, flags, dlgt);
526
dst_inode = h_dst->d_inode;
527
mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
530
err = cpup_iattr(h_dst, h_src, dlgt);
531
//if (LktrCond) err = -1;
534
err = cpup_xattrs(h_src, h_dst);
536
isdir = S_ISDIR(dst_inode->i_mode);
538
if (bdst < old_ibstart)
539
au_set_ibstart(inode, bdst);
540
au_set_h_iptr(inode, bdst, igrab(dst_inode),
541
au_hi_flags(inode, isdir));
542
mutex_unlock(&dst_inode->i_mutex);
544
&& h_src->d_inode->i_nlink > 1
546
au_plink_append(sb, inode, h_dst, bdst);
547
goto out; /* success */
551
mutex_unlock(&dst_inode->i_mutex);
553
if (unlikely(au_opt_test(mnt_flags, UDBA_INOTIFY)
554
&& !IS_ROOT(parent))) {
555
struct dentry *gparent;
556
gparent = dget_parent(parent);
557
hgdir = au_hi(gparent->d_inode, bdst);
560
au_dtime_store(&dt, parent, h_parent, hgdir);
561
vfsub_args_init(&vargs, NULL, dlgt, 0);
563
rerr = vfsub_unlink(h_dir, h_dst, &vargs);
565
rerr = vfsub_rmdir(h_dir, h_dst, &vargs);
567
au_dtime_revert(&dt);
569
AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
579
struct au_cpup_single_args {
581
struct dentry *dentry;
582
aufs_bindex_t bdst, bsrc;
587
static void au_call_cpup_single(void *args)
589
struct au_cpup_single_args *a = args;
590
*a->errp = au_cpup_single(a->dentry, a->bdst, a->bsrc, a->len,
594
int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
595
aufs_bindex_t bsrc, loff_t len, unsigned int flags)
598
struct dentry *h_dentry;
601
LKTRTrace("%.*s, i%lu, bdst %d, bsrc %d, len %Ld, flags 0x%x\n",
602
AuDLNPair(dentry), dentry->d_inode->i_ino, bdst, bsrc, len,
605
h_dentry = au_h_dptr(dentry, bsrc);
606
mode = h_dentry->d_inode->i_mode & S_IFMT;
607
if ((mode != S_IFCHR && mode != S_IFBLK)
608
|| capable(CAP_MKNOD))
609
err = au_cpup_single(dentry, bdst, bsrc, len, flags);
611
struct au_cpup_single_args args = {
619
wkq_err = au_wkq_wait(au_call_cpup_single, &args, /*dlgt*/0);
620
if (unlikely(wkq_err))
629
* copyup the @dentry from the first active hidden branch to @bdst,
630
* using au_cpup_single().
632
int au_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
637
aufs_bindex_t bsrc, bend;
639
LKTRTrace("%.*s, bdst %d, len %Ld, flags 0x%x\n",
640
AuDLNPair(dentry), bdst, len, flags);
641
inode = dentry->d_inode;
642
AuDebugOn(!S_ISDIR(inode->i_mode) && au_dbstart(dentry) < bdst);
644
bend = au_dbend(dentry);
645
for (bsrc = bdst + 1; bsrc <= bend; bsrc++)
646
if (au_h_dptr(dentry, bsrc))
648
AuDebugOn(!au_h_dptr(dentry, bsrc));
650
err = au_lkup_neg(dentry, bdst);
653
err = au_cpup_single(dentry, bdst, bsrc, len, flags);
655
return 0; /* success */
658
au_set_h_dptr(dentry, bdst, NULL);
659
au_set_dbstart(dentry, bsrc);
666
struct au_cpup_simple_args {
668
struct dentry *dentry;
674
static void au_call_cpup_simple(void *args)
676
struct au_cpup_simple_args *a = args;
677
*a->errp = au_cpup_simple(a->dentry, a->bdst, a->len, a->flags);
680
int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
683
int err, do_sio, dlgt, wkq_err;
684
struct dentry *parent;
685
struct inode *h_dir, *dir;
687
LKTRTrace("%.*s, b%d, len %Ld, flags 0x%x\n",
688
AuDLNPair(dentry), bdst, len, flags);
690
parent = dget_parent(dentry);
691
dir = parent->d_inode;
692
h_dir = au_h_iptr(dir, bdst);
693
dlgt = !!au_opt_test_dlgt(au_mntflags(dir->i_sb));
694
do_sio = au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE, dlgt);
697
* testing CAP_MKNOD is for generic fs,
698
* but CAP_FSETID is for xfs only, currently.
700
umode_t mode = dentry->d_inode->i_mode;
701
do_sio = (((mode & (S_IFCHR | S_IFBLK))
702
&& !capable(CAP_MKNOD))
703
|| ((mode & (S_ISUID | S_ISGID))
704
&& !capable(CAP_FSETID)));
707
err = au_cpup_simple(dentry, bdst, len, flags);
709
struct au_cpup_simple_args args = {
716
wkq_err = au_wkq_wait(au_call_cpup_simple, &args, /*dlgt*/0);
717
if (unlikely(wkq_err))
726
/* ---------------------------------------------------------------------- */
728
static noinline_for_stack int
729
au_do_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst,
730
struct dentry *wh_dentry, struct file *file, loff_t len)
733
struct au_dinfo *dinfo;
734
aufs_bindex_t bstart;
735
struct dentry *h_d_bdst, *h_d_bstart;
739
dinfo = au_di(dentry);
740
bstart = dinfo->di_bstart;
741
h_d_bdst = dinfo->di_hdentry[0 + bdst].hd_dentry;
742
dinfo->di_bstart = bdst;
743
dinfo->di_hdentry[0 + bdst].hd_dentry = wh_dentry;
744
h_d_bstart = dinfo->di_hdentry[0 + bstart].hd_dentry;
746
dinfo->di_hdentry[0 + bstart].hd_dentry
747
= au_h_fptr(file, au_fbstart(file))->f_dentry;
748
err = au_cpup_single(dentry, bdst, bstart, len, !AuCpup_DTIME);
749
//if (LktrCond) err = -1;
751
err = au_reopen_nondir(file);
753
dinfo->di_hdentry[0 + bstart].hd_dentry = h_d_bstart;
755
dinfo->di_hdentry[0 + bdst].hd_dentry = h_d_bdst;
756
dinfo->di_bstart = bstart;
763
* copyup the deleted file for writing.
765
int au_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
769
struct dentry *parent, *h_parent, *wh_dentry;
770
struct super_block *sb;
771
unsigned int mnt_flags;
773
struct vfsub_args vargs;
774
struct au_hinode *hgdir;
775
struct au_ndx ndx = {
781
LKTRTrace("%.*s, bdst %d, len %Lu\n", AuDLNPair(dentry), bdst, len);
782
AuDebugOn(S_ISDIR(dentry->d_inode->i_mode)
783
|| (file && !(file->f_mode & FMODE_WRITE)));
784
DiMustWriteLock(dentry);
786
parent = dget_parent(dentry);
787
IiMustAnyLock(parent->d_inode);
788
h_parent = au_h_dptr(parent, bdst);
789
AuDebugOn(!h_parent);
792
mnt_flags = au_mntflags(sb);
794
ndx.nfsmnt = au_nfsmnt(sb, bdst);
795
if (unlikely(au_opt_test_dlgt(mnt_flags))) {
797
au_fset_ndx(ndx.flags, DLGT);
799
wh_dentry = au_whtmp_lkup(h_parent, &dentry->d_name, &ndx);
800
//if (LktrCond) {dput(wh_dentry); wh_dentry = ERR_PTR(-1);}
801
err = PTR_ERR(wh_dentry);
802
if (IS_ERR(wh_dentry))
806
if (unlikely(au_opt_test(mnt_flags, UDBA_INOTIFY)
807
&& !IS_ROOT(parent))) {
808
struct dentry *gparent;
809
gparent = dget_parent(parent);
810
hgdir = au_hi(gparent->d_inode, bdst);
813
au_dtime_store(&dt, parent, h_parent, hgdir);
814
err = au_do_cpup_wh(dentry, bdst, wh_dentry, file, len);
818
AuDebugOn(!d_unhashed(dentry));
819
/* dget first to force sillyrename on nfs */
821
vfsub_args_init(&vargs, NULL, dlgt, 0);
822
err = vfsub_unlink(h_parent->d_inode, wh_dentry, &vargs);
823
//if (LktrCond) err = -1;
825
AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
826
AuDLNPair(wh_dentry), err);
829
au_dtime_revert(&dt);
830
au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
841
struct au_cpup_wh_args {
843
struct dentry *dentry;
849
static void au_call_cpup_wh(void *args)
851
struct au_cpup_wh_args *a = args;
852
*a->errp = au_cpup_wh(a->dentry, a->bdst, a->len, a->file);
855
int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
859
struct dentry *parent;
860
struct inode *dir, *h_dir;
863
parent = dget_parent(dentry);
864
dir = parent->d_inode;
866
h_dir = au_h_iptr(dir, bdst);
868
if (!au_test_h_perm_sio
869
(h_dir, MAY_EXEC | MAY_WRITE,
870
au_opt_test_dlgt(au_mntflags(dentry->d_sb))))
871
err = au_cpup_wh(dentry, bdst, len, file);
873
struct au_cpup_wh_args args = {
880
wkq_err = au_wkq_wait(au_call_cpup_wh, &args, /*dlgt*/0);
881
if (unlikely(wkq_err))
890
/* ---------------------------------------------------------------------- */
893
* generic routine for both of copy-up and copy-down.
894
* Although I've tried building a path by dcsub, I gave up this approach.
895
* Since the ancestor directory may be moved/renamed during copy.
897
/* cf. revalidate function in file.c */
898
int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, struct dentry *locked,
899
int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
900
struct dentry *h_parent, void *arg),
904
struct super_block *sb;
905
struct dentry *d, *parent, *h_parent, *gparent, *real_parent;
907
LKTRTrace("%.*s, b%d, parent i%lu, locked %p\n",
908
AuDLNPair(dentry), bdst, parent_ino(dentry), locked);
910
AuDebugOn(au_test_ro(sb, bdst, NULL));
912
parent = dget_parent(dentry);
913
IiMustWriteLock(parent->d_inode);
914
if (unlikely(IS_ROOT(parent)))
917
DiMustAnyLock(locked);
918
IiMustAnyLock(locked->d_inode);
921
/* slow loop, keep it simple and stupid */
922
real_parent = parent;
923
hinotify = !!au_opt_test(au_mntflags(sb), UDBA_INOTIFY);
926
parent = dget_parent(dentry);
927
h_parent = au_h_dptr(parent, bdst);
929
goto out; /* success */
931
/* find top dir which is needed to cpup */
935
parent = dget_parent(d);
936
if (parent != locked) {
937
di_read_lock_parent3(parent, !AuLock_IR);
938
h_parent = au_h_dptr(parent, bdst);
939
di_read_unlock(parent, !AuLock_IR);
941
h_parent = au_h_dptr(parent, bdst);
944
if (d != real_parent)
945
di_write_lock_child3(d);
947
/* somebody else might create while we were sleeping */
948
if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
949
struct inode *h_dir = h_parent->d_inode,
950
*dir = parent->d_inode;
952
if (au_h_dptr(d, bdst))
953
au_update_dbstart(d);
954
//AuDebugOn(au_dbstart(d) <= bdst);
955
if (parent != locked)
956
di_read_lock_parent3(parent, AuLock_IR);
958
if (unlikely(hinotify && !IS_ROOT(parent))) {
959
gparent = dget_parent(parent);
960
if (gparent != locked)
961
ii_read_lock_parent4(gparent->d_inode);
967
au_hdir_lock(h_dir, dir, bdst);
968
err = cp(d, bdst, h_parent, arg);
969
//if (LktrCond) err = -1;
970
au_hdir_unlock(h_dir, dir, bdst);
971
if (unlikely(gparent)) {
972
ii_read_unlock(gparent->d_inode);
975
if (parent != locked)
976
di_read_unlock(parent, AuLock_IR);
979
if (d != real_parent)
991
static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
992
struct dentry *h_parent, void *arg)
996
err = au_sio_cpup_simple(dentry, bdst, -1, AuCpup_DTIME);
1002
int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst,
1003
struct dentry *locked)
1007
err = au_cp_dirs(dentry, bdst, locked, au_cpup_dir, NULL);
1013
int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst,
1014
struct dentry *locked)
1017
struct dentry *parent;
1020
parent = dget_parent(dentry);
1021
dir = parent->d_inode;
1022
LKTRTrace("%.*s, b%d, parent i%lu, locked %p\n",
1023
AuDLNPair(dentry), bdst, dir->i_ino, locked);
1024
DiMustReadLock(parent);
1025
IiMustReadLock(dir);
1028
if (au_h_iptr(dir, bdst))
1031
di_read_unlock(parent, AuLock_IR);
1032
di_write_lock_parent2(parent);
1033
/* someone else might change our inode while we were sleeping */
1034
if (unlikely(!au_h_iptr(dir, bdst)))
1035
err = au_cpup_dirs(dentry, bdst, locked);
1036
di_downgrade_lock(parent, AuLock_IR);