73
73
struct inode *h_inode;
74
74
struct super_block *sb;
75
75
struct au_branch *br;
78
78
LKTRTrace("%.*s, b%d, flags 0%o, f %d\n",
79
79
AuDLNPair(dentry), bindex, flags, !!file);
81
80
h_dentry = au_h_dptr(dentry, bindex);
82
81
AuDebugOn(!h_dentry);
83
82
h_inode = h_dentry->d_inode;
84
/* todo: a race can happen, return ENOENT */
84
/* a race condition can happen between open and unlink/rmdir */
86
85
h_file = ERR_PTR(-ENOENT);
87
if (unlikely(!h_inode))
86
if (unlikely((!d_unhashed(dentry) && d_unhashed(h_dentry))
94
hinotify = !!au_opt_test(au_mntflags(sb), UDBA_INOTIFY);
95
91
br = au_sbr(sb, bindex);
97
93
/* drop flags for writing */
128
126
static int do_coo(struct dentry *dentry, aufs_bindex_t bstart)
131
struct dentry *parent, *h_parent, *h_dentry, *gparent;
129
struct dentry *parent;
132
130
aufs_bindex_t bcpup;
133
struct inode *h_dir, *h_inode, *dir;
134
132
struct super_block *sb;
136
135
LKTRTrace("%.*s\n", AuDLNPair(dentry));
137
136
AuDebugOn(IS_ROOT(dentry));
146
145
err = 0; /* stop copyup, it is not an error */
151
h_parent = au_h_dptr(parent, bcpup);
150
if (!au_h_dptr(parent, bcpup)) {
153
151
err = au_cpup_dirs(dentry, bcpup, NULL);
154
152
if (unlikely(err))
156
h_parent = au_h_dptr(parent, bcpup);
159
h_dir = h_parent->d_inode;
160
h_dentry = au_h_dptr(dentry, bstart);
161
h_inode = h_dentry->d_inode;
162
dir = parent->d_inode;
163
/* todo: meaningless lock if CONFIG_AUFS_DEBUG is disabled. */
165
if (unlikely(au_opt_test(au_mntflags(sb), UDBA_INOTIFY)
166
&& !IS_ROOT(parent))) {
167
gparent = dget_parent(parent);
168
ii_read_lock_parent2(gparent->d_inode);
170
au_hdir_lock(h_dir, dir, bcpup);
171
/* todo: test parent-gparent relationship? */
172
mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
156
di_downgrade_lock(parent, AuLock_IR);
157
au_pin(&pin, dentry, bcpup, /*di_locked*/1,
158
/*do_gp*/au_opt_test(au_mntflags(sb), UDBA_INOTIFY));
159
h_mtx = &au_h_dptr(dentry, bstart)->d_inode->i_mutex;
160
mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
173
161
AuDebugOn(au_h_dptr(dentry, bcpup));
174
162
err = au_sio_cpup_simple(dentry, bcpup, -1, AuCpup_DTIME);
176
mutex_unlock(&h_inode->i_mutex);
177
au_hdir_unlock(h_dir, dir, bcpup);
178
if (unlikely(gparent)) {
179
ii_read_unlock(gparent->d_inode);
169
di_downgrade_lock(parent, AuLock_IR);
184
di_write_unlock(parent);
171
di_read_unlock(parent, AuLock_IR);
213
200
if (unlikely(err))
217
204
di_read_lock_child(dentry, AuLock_IR);
218
/* todo: remove this */
219
bstart = au_dbstart(dentry);
221
206
di_write_lock_child(dentry);
222
207
bstart = au_dbstart(dentry);
223
208
if (au_test_ro(sb, bstart, dentry->d_inode)) {
331
314
* prepare the @file for writing.
333
int au_ready_to_write(struct file *file, loff_t len)
316
int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
336
struct dentry *dentry, *parent, *h_dentry, *h_parent, *gparent;
337
struct inode *h_inode, *h_dir, *inode, *dir;
319
struct dentry *dentry, *parent, *h_dentry;
320
struct inode *h_inode, *inode;
338
321
struct super_block *sb;
339
322
aufs_bindex_t bstart, bcpup;
349
332
inode = dentry->d_inode;
350
333
AuDebugOn(S_ISDIR(inode->i_mode));
351
ii_read_lock_child(inode);
352
334
LKTRTrace("rdonly %d, bstart %d\n",
353
335
au_test_ro(sb, bstart, inode), bstart);
354
337
err = au_test_ro(sb, bstart, inode);
355
ii_read_unlock(inode);
356
if (!err && (au_h_fptr(file, bstart)->f_mode & FMODE_WRITE))
338
if (!err && (au_h_fptr(file, bstart)->f_mode & FMODE_WRITE)) {
339
au_pin(pin, dentry, bstart, /*di_locked*/0, /*dp_gp*/0);
359
343
/* need to cpup */
360
di_write_lock_child(dentry);
361
344
parent = dget_parent(dentry);
362
345
di_write_lock_parent(parent);
363
346
err = AuWbrCopyup(au_sbi(sb), dentry);
365
348
if (unlikely(err < 0))
369
h_parent = au_h_dptr(parent, bcpup);
352
if (!au_h_dptr(parent, bcpup)) {
371
353
err = au_cpup_dirs(dentry, bcpup, NULL);
372
354
if (unlikely(err))
374
h_parent = au_h_dptr(parent, bcpup);
377
/* todo: meaningless lock if CONFIG_AUFS_DEBUG is disabled. */
379
if (unlikely(au_opt_test(au_mntflags(sb), UDBA_INOTIFY)
380
&& !IS_ROOT(parent))) {
381
gparent = dget_parent(parent);
382
ii_read_lock_parent2(gparent->d_inode);
384
h_dir = h_parent->d_inode;
385
h_dentry = au_h_fptr(file, au_fbstart(file))->f_dentry;
358
di_downgrade_lock(parent, AuLock_IR);
359
au_pin(pin, dentry, bcpup, /*di_locked*/1,
360
/*dp_gp*/au_opt_test(au_mntflags(sb), UDBA_INOTIFY));
362
AuDebugOn(au_fbstart(file) != bstart);
363
h_dentry = au_h_fptr(file, bstart)->f_dentry;
386
364
h_inode = h_dentry->d_inode;
387
dir = parent->d_inode;
388
au_hdir_lock(h_dir, dir, bcpup);
389
/* todo: test parent-gparent relationship? */
390
365
mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
391
366
if (d_unhashed(dentry) /* || d_unhashed(h_dentry) */
392
367
/* || !h_inode->i_nlink */)
403
378
mutex_unlock(&h_inode->i_mutex);
404
au_hdir_unlock(h_dir, dir, bcpup);
405
if (unlikely(gparent)) {
406
ii_read_unlock(gparent->d_inode);
382
au_pin_set_parent_lflag(pin, /*lflag*/0);
383
goto out_dput; /* success */
389
di_downgrade_lock(parent, AuLock_IR);
411
di_write_unlock(parent);
412
di_write_unlock(dentry);
391
di_read_unlock(parent, AuLock_IR);
419
399
/* ---------------------------------------------------------------------- */
467
446
bstart = new_bstart;
469
448
hi_wh = au_hi_wh(inode, bstart);
470
if (au_opt_test(au_mntflags(sb), PLINK)
449
if (au_opt_test(mnt_flags, PLINK)
471
450
&& au_plink_test(sb, inode)
472
451
&& !d_unhashed(dentry)) {
473
452
err = au_test_and_cpup_dirs(dentry, bstart, NULL);
475
454
/* always superio. */
476
#if 1 /* reserved for future use */
477
456
h_dir = au_h_dptr(parent, bstart)->d_inode;
478
au_hdir_lock(h_dir, dir, bstart);
457
mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
479
458
err = au_sio_cpup_simple(dentry, bstart, -1, AuCpup_DTIME);
480
au_hdir_unlock(h_dir, dir, bstart);
459
mutex_unlock(&h_dir->i_mutex);
460
#else /* reserved for future use */
482
461
if (!au_test_wkq(current)) {
484
463
struct cpup_pseudo_link_args args = {
654
632
sgen = au_sigen(sb);
655
633
fi_write_lock(file);
656
634
fgen = au_figen(file);
657
di_read_lock_child(dentry, AuLock_IR);
635
di_write_lock_child(dentry);
658
636
bstart = au_dbstart(dentry);
659
637
pseudo_link = (bstart != au_ibstart(dentry->d_inode));
660
di_read_unlock(dentry, AuLock_IR);
661
638
if (sgen == fgen && !pseudo_link && au_fbstart(file) == bstart) {
640
di_downgrade_lock(dentry, AuLock_IR);
663
641
fi_downgrade_lock(file);
664
643
goto out; /* success */
672
651
* to revalidate. but si_rwsem in DEBUG_RWSEM will cause a
673
652
* deadlock. removed the code.
675
di_write_lock_child(dentry);
676
654
err = au_reval_dpath(dentry, sgen);
677
di_write_unlock(dentry);
678
655
if (unlikely(err < 0))
680
657
AuDebugOn(au_digen(dentry) != sgen
681
658
|| au_iigen(dentry->d_inode) != sgen);
684
di_read_lock_child(dentry, AuLock_IR);
685
661
err = refresh_file(file, reopen
686
662
/* , au_opt_test(au_mnt_flags(sb), REFROF) */);
687
di_read_unlock(dentry, AuLock_IR);
665
di_downgrade_lock(dentry, AuLock_IR);
690
666
fi_downgrade_lock(file);
669
di_write_unlock(dentry);
692
670
fi_write_unlock(file);