122
122
/* keep the timestamps of the parent dir when cpup */
123
123
void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
124
struct dentry *h_dentry, struct au_hinode *hdir)
124
struct dentry *h_dentry, struct au_hinode *hinode,
125
struct au_hinode *hdir)
127
struct inode *h_inode;
128
129
LKTRTrace("%.*s, hdir %d\n", AuDLNPair(dentry), !!hdir);
129
130
AuDebugOn(!dentry || !h_dentry || !h_dentry->d_inode);
131
132
dt->dt_dentry = dentry;
132
133
dt->dt_h_dentry = h_dentry;
134
dt->dt_hinode = hinode;
133
135
dt->dt_hdir = hdir;
134
inode = h_dentry->d_inode;
135
dt->dt_atime = inode->i_atime;
136
dt->dt_mtime = inode->i_mtime;
136
h_inode = h_dentry->d_inode;
137
dt->dt_atime = h_inode->i_atime;
138
dt->dt_mtime = h_inode->i_mtime;
151
153
attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
152
154
| ATTR_ATIME | ATTR_ATIME_SET;
154
vfsub_args_init(&vargs, &ign,
156
vfsub_args_init(&vargs, ign,
155
157
au_test_dlgt(au_mntflags(dt->dt_dentry->d_sb)), 0);
156
if (unlikely(dt->dt_hdir))
157
vfsub_ign_hinode(&vargs, IN_ATTRIB, dt->dt_hdir);
159
* IN_ATTRIB should be divided into
160
* IN_ATTRIB_ATIME, IN_ATTRIB_MTIME ...,
161
* and define all ORed new IN_ATTRIB macro.
163
vfsub_ign_hinode(&vargs, IN_ATTRIB, dt->dt_hinode);
164
vfsub_ign_hinode(&vargs, IN_ATTRIB, dt->dt_hdir);
158
165
err = vfsub_notify_change(dt->dt_h_dentry, &attr, &vargs);
159
166
if (unlikely(err))
160
167
AuWarn("restoring timestamps failed(%d). ignored\n", err);
163
170
/* ---------------------------------------------------------------------- */
165
static noinline_for_stack int
166
cpup_iattr(struct dentry *h_dst, struct dentry *h_src, int dlgt)
172
static noinline_for_stack
173
int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
174
int dlgt, struct au_hinode *hdir)
177
struct dentry *h_dst;
170
179
struct inode *h_isrc, *h_idst;
180
struct au_hin_ignore ign;
171
181
struct vfsub_args vargs;
183
h_dst = au_h_dptr(dst, bindex);
173
184
LKTRTrace("%.*s\n", AuDLNPair(h_dst));
174
185
h_idst = h_dst->d_inode;
175
186
/* todo? IMustLock(h_idst); */
186
197
ia.ia_mtime = h_isrc->i_mtime;
187
198
sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
189
vfsub_args_init(&vargs, NULL, dlgt, /*force_unlink*/0);
200
vfsub_args_init(&vargs, &ign, dlgt, /*force_unlink*/0);
201
vfsub_ign_hinode(&vargs, IN_ATTRIB, hdir);
190
202
err = vfsub_notify_change(h_dst, &ia, &vargs);
192
204
/* is this nfs only? */
193
205
if (!err && sbits && au_test_nfs(h_dst->d_sb)) {
194
206
ia.ia_valid = ATTR_FORCE | ATTR_MODE;
195
207
ia.ia_mode = h_isrc->i_mode;
208
vfsub_args_reinit(&vargs);
209
vfsub_ign_hinode(&vargs, IN_ATTRIB, hdir);
196
210
err = vfsub_notify_change(h_dst, &ia, &vargs);
208
222
* to support a sparse file which is opened with O_APPEND,
209
223
* we need to close the file.
211
static noinline_for_stack int
212
cpup_regular(struct dentry *dentry, aufs_bindex_t bdst, aufs_bindex_t bsrc,
225
static noinline_for_stack
226
int cpup_regular(struct dentry *dentry, aufs_bindex_t bdst, aufs_bindex_t bsrc,
227
loff_t len, struct au_hinode *hdir)
216
230
struct super_block *sb;
280
static noinline_for_stack int
281
au_do_cpup_regular(struct dentry *dentry, aufs_bindex_t bdst,
282
aufs_bindex_t bsrc, loff_t len, struct inode *h_inode,
283
struct inode *h_dir, struct dentry *h_dst, int dlgt)
294
static noinline_for_stack
295
int au_do_cpup_regular(struct dentry *dentry, aufs_bindex_t bdst,
296
aufs_bindex_t bsrc, loff_t len, struct inode *h_inode,
297
struct inode *h_dir, struct dentry *h_dst, int dlgt,
298
struct au_hinode *hdir)
302
struct au_hin_ignore ign;
287
303
struct vfsub_args vargs;
293
309
if (len == -1 || l < len)
296
err = cpup_regular(dentry, bdst, bsrc, len);
312
err = cpup_regular(dentry, bdst, bsrc, len, hdir);
298
314
goto out; /* success */
300
vfsub_args_init(&vargs, NULL, dlgt, 0);
316
vfsub_args_init(&vargs, &ign, dlgt, 0);
317
vfsub_ign_hinode(&vargs, IN_DELETE, hdir);
301
318
rerr = vfsub_unlink(h_dir, h_dst, &vargs);
303
320
AuIOErr("failed unlinking cpup-ed %.*s(%d, %d)\n",
313
static noinline_for_stack int
314
au_do_cpup_symlink(struct dentry *h_dst, struct dentry *h_src,
315
struct inode *h_dir, umode_t mode, int dlgt)
330
static int au_do_cpup_symlink(struct dentry *h_dst, struct dentry *h_src,
331
struct inode *h_dir, umode_t mode,
332
struct vfsub_args *vargs)
346
363
/* return with hidden dst inode is locked */
347
static noinline_for_stack int
348
cpup_entry(struct dentry *dentry, aufs_bindex_t bdst, aufs_bindex_t bsrc,
349
loff_t len, unsigned int flags, int dlgt)
364
static noinline_for_stack
365
int cpup_entry(struct dentry *dentry, aufs_bindex_t bdst, aufs_bindex_t bsrc,
366
loff_t len, unsigned int flags, int dlgt,
367
struct dentry *dst_parent)
351
369
int err, isdir, hinotify;
352
struct dentry *h_src, *h_dst, *h_parent, *parent;
370
struct dentry *h_src, *h_dst, *h_parent;
353
371
struct inode *h_inode, *h_dir;
354
372
struct au_dtime dt;
356
374
struct super_block *sb;
357
struct au_hinode *hgdir;
375
struct au_hinode *hgdir, *hdir;
358
376
const int do_dt = au_ftest_cpup(flags, DTIME);
359
377
unsigned int mnt_flags;
378
struct au_hin_ignore ign;
379
struct vfsub_args vargs;
361
381
LKTRTrace("%.*s, i%lu, bdst %d, bsrc %d, len %lld, dtime %u\n",
362
382
AuDLNPair(dentry), dentry->d_inode->i_ino, bdst, bsrc, len,
371
391
AuDebugOn(!h_inode);
373
393
/* stop referencing while we are creating */
374
parent = dget_parent(dentry);
375
394
h_dst = au_h_dptr(dentry, bdst);
376
395
AuDebugOn(h_dst && h_dst->d_inode);
377
396
h_parent = h_dst->d_parent; /* dir inode is locked */
378
397
h_dir = h_parent->d_inode;
379
398
IMustLock(h_dir);
399
AuDebugOn(h_parent != h_dst->d_parent);
381
402
mnt_flags = au_mntflags(sb);
382
403
hinotify = !!au_opt_test(mnt_flags, UDBA_INOTIFY);
404
if (unlikely(hinotify)) {
405
hdir = au_hi(dst_parent->d_inode, bdst);
406
AuDebugOn(hdir->hi_inode != h_dir);
385
if (unlikely(hinotify && !IS_ROOT(parent))) {
411
if (unlikely(hinotify && !IS_ROOT(dst_parent))) {
386
412
struct dentry *gparent;
387
gparent = dget_parent(parent);
413
gparent = dget_parent(dst_parent);
388
414
hgdir = au_hi(gparent->d_inode, bdst);
415
IMustLock(hgdir->hi_inode);
391
au_dtime_store(&dt, parent, h_parent, hgdir);
418
au_dtime_store(&dt, dst_parent, h_parent, hdir, hgdir);
422
vfsub_args_init(&vargs, &ign, dlgt, 0);
423
vfsub_ign_hinode(&vargs, IN_CREATE, hdir);
395
424
mode = h_inode->i_mode;
396
425
switch (mode & S_IFMT) {
398
427
/* stop updating while we are referencing */
399
428
IMustLock(h_inode);
400
err = au_h_create(h_dir, h_dst, mode | S_IWUSR, dlgt, NULL,
429
err = au_h_create(h_dir, h_dst, mode | S_IWUSR, &vargs, NULL,
401
430
au_nfsmnt(sb, bdst));
403
432
err = au_do_cpup_regular(dentry, bdst, bsrc, len,
404
h_inode, h_dir, h_dst, dlgt);
433
h_inode, h_dir, h_dst, dlgt,
408
err = vfsub_mkdir(h_dir, h_dst, mode, dlgt);
438
err = vfsub_mkdir(h_dir, h_dst, mode, &vargs);
410
440
/* setattr case: dir is not locked */
411
if (0 && au_ibstart(parent->d_inode) == bdst)
412
au_cpup_attr_nlink(parent->d_inode);
441
if (0 && au_ibstart(dst_parent->d_inode) == bdst)
442
au_cpup_attr_nlink(dst_parent->d_inode);
413
443
au_cpup_attr_nlink(dentry->d_inode);
417
err = au_do_cpup_symlink(h_dst, h_src, h_dir, mode, dlgt);
447
err = au_do_cpup_symlink(h_dst, h_src, h_dir, mode, &vargs);
452
481
* the caller must set the both of hidden dentries.
453
482
* @len is for truncating when it is -1 copyup the entire file.
455
int au_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
456
aufs_bindex_t bsrc, loff_t len, unsigned int flags)
484
static int au_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
485
aufs_bindex_t bsrc, loff_t len, unsigned int flags,
486
struct dentry *dst_parent)
458
int err, rerr, isdir, dlgt, plink;
459
struct dentry *h_src, *h_dst, *parent, *h_parent;
489
struct dentry *h_src, *h_dst, *h_parent;
460
490
struct inode *dst_inode, *h_dir, *inode;
461
491
struct super_block *sb;
462
492
aufs_bindex_t old_ibstart;
463
493
struct au_dtime dt;
494
struct au_hin_ignore ign;
464
495
struct vfsub_args vargs;
465
struct au_hinode *hgdir;
496
struct au_hinode *hgdir, *hdir;
466
497
unsigned int mnt_flags;
498
unsigned char isdir, dlgt, plink, hinotify;
468
500
LKTRTrace("%.*s, i%lu, bdst %d, bsrc %d, len %lld, flags 0x%x\n",
469
501
AuDLNPair(dentry), dentry->d_inode->i_ino, bdst, bsrc, len,
479
511
AuDebugOn(!h_src || !h_src->d_inode);
480
512
inode = dentry->d_inode;
481
513
IiMustWriteLock(inode);
482
parent = dget_parent(dentry);
515
dst_parent = dget_parent(dentry);
484
519
mnt_flags = au_mntflags(sb);
485
520
dlgt = !!au_test_dlgt(mnt_flags);
486
521
plink = !!au_opt_test(mnt_flags, PLINK);
522
hinotify = !!au_opt_test(mnt_flags, UDBA_INOTIFY);
524
if (unlikely(hinotify))
525
hdir = au_hi(dst_parent->d_inode, bdst);
487
526
dst_inode = au_h_iptr(inode, bdst);
488
527
if (unlikely(dst_inode)) {
489
528
if (unlikely(!plink)) {
496
535
if (dst_inode->i_nlink) {
536
const int do_dt = au_ftest_cpup(flags, DTIME);
497
538
h_src = au_plink_lkup(sb, bdst, inode);
498
539
err = PTR_ERR(h_src);
499
540
if (IS_ERR(h_src))
501
542
AuDebugOn(!h_src->d_inode);
502
err = vfsub_link(h_src, h_dir, h_dst, dlgt);
546
if (unlikely(hinotify && !IS_ROOT(dst_parent))) {
547
struct dentry *gparent;
548
gparent = dget_parent(dst_parent);
549
hgdir = au_hi(gparent->d_inode, bdst);
550
IMustLock(hgdir->hi_inode);
553
au_dtime_store(&dt, dst_parent, h_parent, hdir,
556
vfsub_args_init(&vargs, &ign, dlgt, 0);
557
vfsub_ign_hinode(&vargs, IN_CREATE, hdir);
558
err = vfsub_link(h_src, h_dir, h_dst, &vargs);
560
au_dtime_revert(&dt);
511
569
old_ibstart = au_ibstart(inode);
512
err = cpup_entry(dentry, bdst, bsrc, len, flags, dlgt);
570
err = cpup_entry(dentry, bdst, bsrc, len, flags, dlgt, dst_parent);
513
571
if (unlikely(err))
515
573
dst_inode = h_dst->d_inode;
516
574
mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
518
576
/* todo: test dlgt? */
519
err = cpup_iattr(h_dst, h_src, dlgt);
577
err = cpup_iattr(dentry, bdst, h_src, dlgt, hdir);
520
578
#if 0 /* reserved for future use */
522
580
err = cpup_xattrs(h_src, h_dst);
539
597
mutex_unlock(&dst_inode->i_mutex);
541
599
if (unlikely(au_opt_test(mnt_flags, UDBA_INOTIFY)
542
&& !IS_ROOT(parent))) {
600
&& !IS_ROOT(dst_parent))) {
543
601
struct dentry *gparent;
544
gparent = dget_parent(parent);
602
gparent = dget_parent(dst_parent);
545
603
hgdir = au_hi(gparent->d_inode, bdst);
548
au_dtime_store(&dt, parent, h_parent, hgdir);
549
vfsub_args_init(&vargs, NULL, dlgt, 0);
606
au_dtime_store(&dt, dst_parent, h_parent, hdir, hgdir);
607
vfsub_args_init(&vargs, &ign, dlgt, 0);
608
vfsub_ign_hinode(&vargs, IN_DELETE, hdir);
551
610
rerr = vfsub_unlink(h_dir, h_dst, &vargs);
569
628
aufs_bindex_t bdst, bsrc;
571
630
unsigned int flags;
631
struct dentry *dst_parent;
574
634
static void au_call_cpup_single(void *args)
576
636
struct au_cpup_single_args *a = args;
577
637
*a->errp = au_cpup_single(a->dentry, a->bdst, a->bsrc, a->len,
638
a->flags, a->dst_parent);
581
641
int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
582
aufs_bindex_t bsrc, loff_t len, unsigned int flags)
642
aufs_bindex_t bsrc, loff_t len, unsigned int flags,
643
struct dentry *dst_parent)
584
645
int err, wkq_err;
585
646
struct dentry *h_dentry;
593
654
mode = h_dentry->d_inode->i_mode & S_IFMT;
594
655
if ((mode != S_IFCHR && mode != S_IFBLK)
595
656
|| capable(CAP_MKNOD))
596
err = au_cpup_single(dentry, bdst, bsrc, len, flags);
657
err = au_cpup_single(dentry, bdst, bsrc, len, flags,
598
660
struct au_cpup_single_args args = {
712
775
/* ---------------------------------------------------------------------- */
714
static noinline_for_stack int
715
au_do_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst,
716
struct dentry *wh_dentry, struct file *file, loff_t len)
777
static int au_do_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst,
778
struct dentry *wh_dentry, struct file *file,
719
782
struct au_dinfo *dinfo;
732
795
dinfo->di_hdentry[0 + bstart].hd_dentry
733
796
= au_h_fptr(file, au_fbstart(file))->f_dentry;
734
err = au_cpup_single(dentry, bdst, bstart, len, !AuCpup_DTIME);
797
err = au_cpup_single(dentry, bdst, bstart, len, !AuCpup_DTIME, NULL);
735
798
if (!err && file) {
736
799
err = au_reopen_nondir(file);
737
800
dinfo->di_hdentry[0 + bstart].hd_dentry = h_d_bstart;
785
849
if (IS_ERR(wh_dentry))
789
if (unlikely(au_opt_test(mnt_flags, UDBA_INOTIFY)
790
&& !IS_ROOT(parent))) {
791
struct dentry *gparent;
792
gparent = dget_parent(parent);
793
hgdir = au_hi(gparent->d_inode, bdst);
854
if (unlikely(au_opt_test(mnt_flags, UDBA_INOTIFY))) {
855
hdir = au_hi(parent->d_inode, bdst);
856
if (!IS_ROOT(parent)) {
857
struct dentry *gparent;
858
gparent = dget_parent(parent);
859
hgdir = au_hi(gparent->d_inode, bdst);
796
au_dtime_store(&dt, parent, h_parent, hgdir);
863
au_dtime_store(&dt, parent, h_parent, hdir, hgdir);
797
864
err = au_do_cpup_wh(dentry, bdst, wh_dentry, file, len);
798
865
if (unlikely(err))
801
868
AuDebugOn(!d_unhashed(dentry));
802
869
/* dget first to force sillyrename on nfs */
804
vfsub_args_init(&vargs, NULL, dlgt, 0);
871
vfsub_args_init(&vargs, &ign, dlgt, 0);
872
vfsub_ign_hinode(&vargs, IN_DELETE, hdir);
805
873
err = vfsub_unlink(h_parent->d_inode, wh_dentry, &vargs);
806
874
if (unlikely(err)) {
807
875
AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
928
997
/* somebody else might create while we were sleeping */
929
998
if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
930
struct inode *h_dir = h_parent->d_inode,
931
*dir = parent->d_inode;
999
struct inode *h_gdir, *gdir,
1000
*h_dir = h_parent->d_inode;
1002
/* todo: try au_pin() */
933
1003
if (au_h_dptr(d, bdst))
934
1004
au_update_dbstart(d);
935
1005
if (parent != locked)
936
1006
di_read_lock_parent3(parent, AuLock_IR);
938
1010
if (unlikely(hinotify && !IS_ROOT(parent))) {
939
1011
gparent = dget_parent(parent);
1012
gdir = gparent->d_inode;
940
1013
if (gparent != locked)
941
ii_read_lock_parent4(gparent->d_inode);
1014
ii_read_lock_parent4(gdir);
1015
h_gdir = au_h_iptr(gdir, bdst);
1016
mutex_lock_nested(&h_gdir->i_mutex,
947
au_hdir_lock(h_dir, dir, bdst);
1019
mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT2);
948
1020
err = cp(d, bdst, h_parent, arg);
949
au_hdir_unlock(h_dir, dir, bdst);
1021
mutex_unlock(&h_dir->i_mutex);
950
1022
if (unlikely(gparent)) {
951
ii_read_unlock(gparent->d_inode);
1023
mutex_unlock(&h_gdir->i_mutex);
1024
if (gparent != locked)
1025
ii_read_unlock(gdir);
954
1028
if (parent != locked)