224
229
di_write_unlock(d1);
225
230
if (d1->d_inode == d2->d_inode)
226
rw_write_unlock(&dtodi(d2)->di_rwsem);
231
au_rw_write_unlock(&au_di(d2)->di_rwsem);
228
233
di_write_unlock(d2);
231
236
/* ---------------------------------------------------------------------- */
233
aufs_bindex_t dbstart(struct dentry *dentry)
235
DiMustAnyLock(dentry);
236
return dtodi(dentry)->di_bstart;
239
aufs_bindex_t dbend(struct dentry *dentry)
241
DiMustAnyLock(dentry);
242
return dtodi(dentry)->di_bend;
245
aufs_bindex_t dbwh(struct dentry *dentry)
247
DiMustAnyLock(dentry);
248
return dtodi(dentry)->di_bwh;
251
aufs_bindex_t dbdiropq(struct dentry *dentry)
253
DiMustAnyLock(dentry);
254
AuDebugOn(dentry->d_inode
255
&& dentry->d_inode->i_mode
256
&& !S_ISDIR(dentry->d_inode->i_mode));
257
return dtodi(dentry)->di_bdiropq;
260
238
struct dentry *au_h_dptr_i(struct dentry *dentry, aufs_bindex_t bindex)
262
240
struct dentry *d;
264
242
DiMustAnyLock(dentry);
265
if (dbstart(dentry) < 0 || bindex < dbstart(dentry))
243
if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
267
245
AuDebugOn(bindex < 0
268
/* || bindex > sbend(dentry->d_sb) */);
269
d = dtodi(dentry)->di_hdentry[0 + bindex].hd_dentry;
246
/* || bindex > au_sbend(dentry->d_sb) */);
247
d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
270
248
AuDebugOn(d && (atomic_read(&d->d_count) <= 0));
274
struct dentry *au_h_dptr(struct dentry *dentry)
276
return au_h_dptr_i(dentry, dbstart(dentry));
279
aufs_bindex_t dbtail(struct dentry *dentry)
252
aufs_bindex_t au_dbtail(struct dentry *dentry)
281
254
aufs_bindex_t bend, bwh;
283
bend = dbend(dentry);
256
bend = au_dbend(dentry);
258
bwh = au_dbwh(dentry);
286
259
//AuDebugOn(bend < bwh);
313
aufs_bindex_t dbtail_generic(struct dentry *dentry)
286
aufs_bindex_t au_dbtail_generic(struct dentry *dentry)
315
288
struct inode *inode;
317
290
inode = dentry->d_inode;
318
291
if (inode && S_ISDIR(inode->i_mode))
319
return dbtaildir(dentry);
292
return au_dbtaildir(dentry);
321
return dbtail(dentry);
294
return au_dbtail(dentry);
324
297
/* ---------------------------------------------------------------------- */
327
void set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
329
DiMustWriteLock(dentry);
330
AuDebugOn(sbend(dentry->d_sb) < bindex);
332
dtodi(dentry)->di_bstart = bindex;
335
void set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
337
DiMustWriteLock(dentry);
338
AuDebugOn(sbend(dentry->d_sb) < bindex
339
|| bindex < dbstart(dentry));
340
dtodi(dentry)->di_bend = bindex;
343
void set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
345
DiMustWriteLock(dentry);
346
AuDebugOn(sbend(dentry->d_sb) < bindex);
347
/* dbwh can be outside of bstart - bend range */
348
dtodi(dentry)->di_bwh = bindex;
351
void set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
353
DiMustWriteLock(dentry);
354
AuDebugOn(sbend(dentry->d_sb) < bindex);
299
void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
301
DiMustWriteLock(dentry);
302
AuDebugOn(au_sbend(dentry->d_sb) < bindex);
355
303
AuDebugOn((bindex >= 0
356
&& (bindex < dbstart(dentry) || dbend(dentry) < bindex))
304
&& (bindex < au_dbstart(dentry)
305
|| au_dbend(dentry) < bindex))
357
306
|| (dentry->d_inode
358
307
&& dentry->d_inode->i_mode
359
308
&& !S_ISDIR(dentry->d_inode->i_mode)));
360
dtodi(dentry)->di_bdiropq = bindex;
363
static void hintent_put(struct aufs_hdentry *hd, int do_free)
365
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) \
366
&& !defined(AuNoNfsBranch)
367
struct aufs_hdintent *hdi, *tmp;
370
if (unlikely(hd->hd_intent_list)) {
372
list_for_each_entry_safe(hdi, tmp, hd->hd_intent_list,
374
LKTRTrace("hdi %p\n", hdi);
375
hf = hdi->hdi_file[AuIntent_BRANCH];
378
//list_del(&hdi->hdi_list);
382
kfree(hd->hd_intent_list);
387
void hdput(struct aufs_hdentry *hd, int do_free)
389
hintent_put(hd, do_free);
393
void set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
394
struct dentry *h_dentry)
396
struct aufs_hdentry *hd = dtodi(dentry)->di_hdentry + bindex;
309
au_di(dentry)->di_bdiropq = bindex;
312
void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
313
struct dentry *h_dentry)
315
struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
397
316
DiMustWriteLock(dentry);
398
AuDebugOn(bindex < dtodi(dentry)->di_bstart
399
|| bindex > dtodi(dentry)->di_bend
317
AuDebugOn(bindex < au_di(dentry)->di_bstart
318
|| bindex > au_di(dentry)->di_bend
400
319
|| (h_dentry && atomic_read(&h_dentry->d_count) <= 0)
401
320
|| (h_dentry && hd->hd_dentry)
403
322
if (hd->hd_dentry)
404
hdput(hd, /*do_free*/0);
323
au_hdput(hd, /*do_free*/0);
405
324
hd->hd_dentry = h_dentry;
408
327
/* ---------------------------------------------------------------------- */
410
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) \
411
&& !defined(AuNoNfsBranch)
412
static struct file *au_find_h_intent(struct aufs_hdentry *hd, struct file *file)
414
struct file *h_file, *hf;
415
struct aufs_hdintent *hdi, *tmp;
417
LKTRTrace("%.*s\n", AuDLNPair(hd->hd_dentry));
420
spin_lock(&hd->hd_lock);
421
list_for_each_entry_safe(hdi, tmp, hd->hd_intent_list, hdi_list) {
422
hf = hdi->hdi_file[AuIntent_BRANCH];
423
if (hdi->hdi_file[AuIntent_AUFS] == file
424
&& hf->f_dentry == hd->hd_dentry) {
426
list_del(&hdi->hdi_list);
431
spin_unlock(&hd->hd_lock);
436
struct file *au_h_intent(struct dentry *dentry, aufs_bindex_t bindex,
440
struct aufs_hdentry *hd = dtodi(dentry)->di_hdentry + bindex;
442
LKTRTrace("%.*s, b%d, f %p\n", AuDLNPair(dentry), bindex, file);
443
DiMustAnyLock(dentry);
444
AuDebugOn(bindex < dtodi(dentry)->di_bstart
445
|| bindex > dtodi(dentry)->di_bend);
448
if (!hd->hd_intent_list || !file)
449
return h_file; /* success */
451
//AuDebugOn(au_test_wkq(current));
452
h_file = au_find_h_intent(hd, file);
457
int au_set_h_intent(struct dentry *dentry, aufs_bindex_t bindex,
458
struct file *file, struct file *h_file)
461
struct aufs_hdentry *hd = dtodi(dentry)->di_hdentry + bindex;
462
struct aufs_hdintent *hdi;
465
LKTRTrace("%.*s, b%d, f %p\n", AuDLNPair(dentry), bindex, file);
466
/* d_revalidate() holds read_lock */
467
//DiMustWriteLock(dentry);
468
AuDebugOn(bindex < dtodi(dentry)->di_bstart
469
|| bindex > dtodi(dentry)->di_bend
472
/* || au_test_wkq(current) */);
475
if (hd->hd_intent_list) {
477
hf = au_find_h_intent(hd, file);
480
#if 0 //def CONFIG_AUFS_DEBUG
487
AuWarn("freed hfile %.*s b%d left\n",
488
AuDLNPair(dentry), bindex);
491
spin_lock(&hd->hd_lock);
492
if (!hd->hd_intent_list) {
494
= kmalloc(sizeof(*hd->hd_intent_list),
496
if (unlikely(!hd->hd_intent_list)) {
497
spin_unlock(&hd->hd_lock);
500
INIT_LIST_HEAD(hd->hd_intent_list);
502
spin_unlock(&hd->hd_lock);
505
hdi = kmalloc(sizeof(*hdi), GFP_TEMPORARY);
510
//hdi->hdi_pid = current->pid;
511
hdi->hdi_file[AuIntent_AUFS] = file;
512
hdi->hdi_file[AuIntent_BRANCH] = h_file;
513
spin_lock(&hd->hd_lock);
514
list_add(&hdi->hdi_list, hd->hd_intent_list);
515
spin_unlock(&hd->hd_lock);
516
//AuDbgDentry(dentry);
523
#endif /* !defined(AuNoNfsBranch) */
525
/* ---------------------------------------------------------------------- */
527
void au_update_digen(struct dentry *dentry)
529
//DiMustWriteLock(dentry);
530
AuDebugOn(!dentry->d_sb);
531
atomic_set(&dtodi(dentry)->di_generation, au_sigen(dentry->d_sb));
532
//smp_mb(); /* atomic_set */
535
329
void au_update_dbrange(struct dentry *dentry, int do_put_zero)
537
struct aufs_dinfo *dinfo;
331
struct au_dinfo *dinfo;
538
332
aufs_bindex_t bindex;
539
333
struct dentry *h_d;
541
335
LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), do_put_zero);
542
336
DiMustWriteLock(dentry);
544
dinfo = dtodi(dentry);
338
dinfo = au_di(dentry);
545
339
if (unlikely(!dinfo) || dinfo->di_bstart < 0)