Commit 39d4a736 authored by J. R. Okajima's avatar J. R. Okajima
Browse files

aufs: dirren 4/6, rename with saving the rename info



When DIRREN is enabled and activated, the error case where
aufs rename(2) used to return EXDEV will be gone.
Aufs rename(2) registers the renaming dir inum to the list in the
branch, creates the detailed info file, and returns a success.

If udba=notify option is specified with dirren, the internal detection
may not work correctly since aufs may not be able to find the target
name.
Signed-off-by: default avatarJ. R. Okajima <hooanon05g@gmail.com>
parent 77277be2
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <linux/byteorder/generic.h> #include <linux/byteorder/generic.h>
#include "aufs.h" #include "aufs.h"
/* re-commit later */ __maybe_unused
static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent) static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
{ {
int idx; int idx;
...@@ -37,7 +36,6 @@ static int au_dr_hino_test_empty(struct au_dr_br *dr) ...@@ -37,7 +36,6 @@ static int au_dr_hino_test_empty(struct au_dr_br *dr)
return ret; return ret;
} }
/* re-commit later */ __maybe_unused
static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino) static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
{ {
struct au_dr_hino *found, *ent; struct au_dr_hino *found, *ent;
...@@ -791,7 +789,6 @@ static void au_drinfo_store_rev(struct au_drinfo_rev *rev, ...@@ -791,7 +789,6 @@ static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
} }
/* caller has to call au_dr_rename_fin() later */ /* caller has to call au_dr_rename_fin() later */
/* re-commit later */ __maybe_unused
static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt, static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
struct qstr *dst_name, void *_rev) struct qstr *dst_name, void *_rev)
{ {
...@@ -869,3 +866,107 @@ out_args: ...@@ -869,3 +866,107 @@ out_args:
out: out:
return err; return err;
} }
/* ---------------------------------------------------------------------- */
int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
struct qstr *dst_name, void *_rev)
{
int err, already;
ino_t ino;
struct super_block *sb;
struct au_branch *br;
struct au_dr_br *dr;
struct dentry *h_dentry;
struct inode *h_inode;
struct au_dr_hino *ent;
struct au_drinfo_rev *rev, **p;
AuDbg("bindex %d\n", bindex);
err = -ENOMEM;
ent = kmalloc(sizeof(*ent), GFP_NOFS);
if (unlikely(!ent))
goto out;
sb = src->d_sb;
br = au_sbr(sb, bindex);
dr = &br->br_dirren;
h_dentry = au_h_dptr(src, bindex);
h_inode = d_inode(h_dentry);
ino = h_inode->i_ino;
ent->dr_h_ino = ino;
already = au_dr_hino_test_add(dr, ino, ent);
AuDbg("b%d, hi%llu, already %d\n",
bindex, (unsigned long long)ino, already);
err = au_drinfo_store(src, bindex, dst_name, _rev);
AuTraceErr(err);
if (!err) {
p = _rev;
rev = *p;
rev->already = already;
goto out; /* success */
}
/* revert */
if (!already)
au_dr_hino_del(dr, ent);
au_kfree_rcu(ent);
out:
AuTraceErr(err);
return err;
}
void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
{
struct au_drinfo_rev *rev;
struct au_drinfo_rev_elm *elm;
int nelm;
rev = _rev;
elm = rev->elm;
for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
dput(elm->info_dentry);
au_kfree_rcu(elm->info_last);
}
au_kfree_try_rcu(rev);
}
void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
{
int err;
struct au_drinfo_store work;
struct au_drinfo_rev *rev = _rev;
struct super_block *sb;
struct au_branch *br;
struct inode *h_inode;
struct au_dr_br *dr;
struct au_dr_hino *ent;
err = au_drinfo_store_work_init(&work, btgt);
if (unlikely(err))
goto out;
sb = src->d_sb;
br = au_sbr(sb, btgt);
work.h_ppath.dentry = au_h_dptr(src, btgt);
work.h_ppath.mnt = au_br_mnt(br);
au_drinfo_store_rev(rev, &work);
au_drinfo_store_work_fin(&work);
if (rev->already)
goto out;
dr = &br->br_dirren;
h_inode = d_inode(work.h_ppath.dentry);
ent = au_dr_hino_find(dr, h_inode->i_ino);
BUG_ON(!ent);
au_dr_hino_del(dr, ent);
au_kfree_rcu(ent);
out:
au_kfree_try_rcu(rev);
if (unlikely(err))
pr_err("failed to remove dirren info\n");
}
...@@ -57,10 +57,12 @@ struct au_dr_br { }; ...@@ -57,10 +57,12 @@ struct au_dr_br { };
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
struct qstr;
struct au_branch; struct au_branch;
struct au_hinode; struct au_hinode;
struct path; struct path;
struct super_block; struct super_block;
struct dentry;
#ifdef CONFIG_AUFS_DIRREN #ifdef CONFIG_AUFS_DIRREN
int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino, int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
struct au_dr_hino *add_ent); struct au_dr_hino *add_ent);
...@@ -68,6 +70,10 @@ void au_dr_hino_free(struct au_dr_br *dr); ...@@ -68,6 +70,10 @@ void au_dr_hino_free(struct au_dr_br *dr);
int au_dr_br_init(struct super_block *sb, struct au_branch *br, int au_dr_br_init(struct super_block *sb, struct au_branch *br,
const struct path *path); const struct path *path);
int au_dr_br_fin(struct super_block *sb, struct au_branch *br); int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
struct qstr *dst_name, void *_rev);
void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
#else #else
AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino, AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
struct au_dr_hino *add_ent); struct au_dr_hino *add_ent);
...@@ -75,6 +81,11 @@ AuStubVoid(au_dr_hino_free, struct au_dr_br *dr); ...@@ -75,6 +81,11 @@ AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br, AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
const struct path *path); const struct path *path);
AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br); AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
struct qstr *dst_name, void *_rev);
AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
void *rev);
#endif #endif
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
......
...@@ -451,6 +451,14 @@ static void au_hn_bh(void *_args) ...@@ -451,6 +451,14 @@ static void au_hn_bh(void *_args)
AuDebugOn(!sbinfo); AuDebugOn(!sbinfo);
si_write_lock(sb, AuLock_NOPLMW); si_write_lock(sb, AuLock_NOPLMW);
if (au_opt_test(sbinfo->si_mntflags, DIRREN))
switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
case FS_MOVED_FROM:
case FS_MOVED_TO:
AuWarn1("DIRREN with UDBA may not work correctly "
"for the direct rename(2)\n");
}
ii_read_lock_parent(a->dir); ii_read_lock_parent(a->dir);
bfound = -1; bfound = -1;
bbot = au_ibbot(a->dir); bbot = au_ibbot(a->dir);
......
...@@ -23,12 +23,20 @@ enum { AuPARENT, AuCHILD, AuParentChild }; ...@@ -23,12 +23,20 @@ enum { AuPARENT, AuCHILD, AuParentChild };
#define AuRen_DT_DSTDIR (1 << 6) #define AuRen_DT_DSTDIR (1 << 6)
#define AuRen_DIROPQ_SRC (1 << 7) #define AuRen_DIROPQ_SRC (1 << 7)
#define AuRen_DIROPQ_DST (1 << 8) #define AuRen_DIROPQ_DST (1 << 8)
#define AuRen_DIRREN (1 << 9)
#define AuRen_DROPPED_SRC (1 << 10)
#define AuRen_DROPPED_DST (1 << 11)
#define au_ftest_ren(flags, name) ((flags) & AuRen_##name) #define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
#define au_fset_ren(flags, name) \ #define au_fset_ren(flags, name) \
do { (flags) |= AuRen_##name; } while (0) do { (flags) |= AuRen_##name; } while (0)
#define au_fclr_ren(flags, name) \ #define au_fclr_ren(flags, name) \
do { (flags) &= ~AuRen_##name; } while (0) do { (flags) &= ~AuRen_##name; } while (0)
#ifndef CONFIG_AUFS_DIRREN
#undef AuRen_DIRREN
#define AuRen_DIRREN 0
#endif
struct au_ren_args { struct au_ren_args {
struct { struct {
struct dentry *dentry, *h_dentry, *parent, *h_parent, struct dentry *dentry, *h_dentry, *parent, *h_parent,
...@@ -81,6 +89,7 @@ struct au_ren_args { ...@@ -81,6 +89,7 @@ struct au_ren_args {
struct au_whtmp_rmdir *thargs; struct au_whtmp_rmdir *thargs;
struct dentry *h_dst; struct dentry *h_dst;
struct au_hinode *h_root;
}; };
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
...@@ -293,6 +302,7 @@ static int au_ren_diropq(struct au_ren_args *a) ...@@ -293,6 +302,7 @@ static int au_ren_diropq(struct au_ren_args *a)
err = 0; err = 0;
d = a->dst_dentry; /* already renamed on the branch */ d = a->dst_dentry; /* already renamed on the branch */
if (au_ftest_ren(a->auren_flags, ISDIR_SRC) if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
&& !au_ftest_ren(a->auren_flags, DIRREN)
&& a->btgt != au_dbdiropq(a->src_dentry) && a->btgt != au_dbdiropq(a->src_dentry)
&& (a->dst_wh_dentry && (a->dst_wh_dentry
|| a->btgt <= au_dbdiropq(d) || a->btgt <= au_dbdiropq(d)
...@@ -338,6 +348,7 @@ static int do_rename(struct au_ren_args *a) ...@@ -338,6 +348,7 @@ static int do_rename(struct au_ren_args *a)
/* prepare workqueue args for asynchronous rmdir */ /* prepare workqueue args for asynchronous rmdir */
h_d = a->dst_h_dentry; h_d = a->dst_h_dentry;
if (au_ftest_ren(a->auren_flags, ISDIR_DST) if (au_ftest_ren(a->auren_flags, ISDIR_DST)
/* && !au_ftest_ren(a->auren_flags, DIRREN) */
&& d_is_positive(h_d)) { && d_is_positive(h_d)) {
err = -ENOMEM; err = -ENOMEM;
a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
...@@ -465,27 +476,35 @@ static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist) ...@@ -465,27 +476,35 @@ static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
} }
/* /*
* test if @dentry dir can be rename source or not. * test if @a->src_dentry dir can be rename source or not.
* if it can, return 0. * if it can, return 0.
* success means, * success means,
* - it is a logically empty dir. * - it is a logically empty dir.
* - or, it exists on writable branch and has no children including whiteouts * - or, it exists on writable branch and has no children including whiteouts
* on the lower branch. * on the lower branch unless DIRREN is on.
*/ */
static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt) static int may_rename_srcdir(struct au_ren_args *a)
{ {
int err; int err;
unsigned int rdhash; unsigned int rdhash;
aufs_bindex_t btop; aufs_bindex_t btop, btgt;
struct dentry *dentry;
struct super_block *sb; struct super_block *sb;
struct au_sbinfo *sbinfo;
dentry = a->src_dentry;
sb = dentry->d_sb; sb = dentry->d_sb;
sbinfo = au_sbi(sb);
if (au_opt_test(sbinfo->si_mntflags, DIRREN))
au_fset_ren(a->auren_flags, DIRREN);
btgt = a->btgt;
btop = au_dbtop(dentry); btop = au_dbtop(dentry);
if (btop != btgt) { if (btop != btgt) {
struct au_nhash whlist; struct au_nhash whlist;
SiMustAnyLock(sb); SiMustAnyLock(sb);
rdhash = au_sbi(sb)->si_rdhash; rdhash = sbinfo->si_rdhash;
if (!rdhash) if (!rdhash)
rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
dentry)); dentry));
...@@ -504,10 +523,14 @@ static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt) ...@@ -504,10 +523,14 @@ static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
out: out:
if (err == -ENOTEMPTY) { if (err == -ENOTEMPTY) {
AuWarn1("renaming dir who has child(ren) on multiple branches," if (au_ftest_ren(a->auren_flags, DIRREN)) {
" is not supported\n"); err = 0;
} else {
AuWarn1("renaming dir who has child(ren) on multiple "
"branches, is not supported\n");
err = -EXDEV; err = -EXDEV;
} }
}
return err; return err;
} }
...@@ -535,7 +558,7 @@ static int au_ren_may_dir(struct au_ren_args *a) ...@@ -535,7 +558,7 @@ static int au_ren_may_dir(struct au_ren_args *a)
err = may_rename_dstdir(d, &a->whlist); err = may_rename_dstdir(d, &a->whlist);
au_set_dbtop(d, a->btgt); au_set_dbtop(d, a->btgt);
} else } else
err = may_rename_srcdir(d, a->btgt); err = may_rename_srcdir(a);
} }
a->dst_h_dentry = au_h_dptr(d, au_dbtop(d)); a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
if (unlikely(err)) if (unlikely(err))
...@@ -544,7 +567,7 @@ static int au_ren_may_dir(struct au_ren_args *a) ...@@ -544,7 +567,7 @@ static int au_ren_may_dir(struct au_ren_args *a)
d = a->src_dentry; d = a->src_dentry;
a->src_h_dentry = au_h_dptr(d, au_dbtop(d)); a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) { if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
err = may_rename_srcdir(d, a->btgt); err = may_rename_srcdir(a);
if (unlikely(err)) { if (unlikely(err)) {
au_nhash_wh_free(&a->whlist); au_nhash_wh_free(&a->whlist);
a->whlist.nh_num = 0; a->whlist.nh_num = 0;
...@@ -634,6 +657,9 @@ static void au_ren_unlock(struct au_ren_args *a) ...@@ -634,6 +657,9 @@ static void au_ren_unlock(struct au_ren_args *a)
{ {
vfsub_unlock_rename(a->src_h_parent, a->src_hdir, vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
a->dst_h_parent, a->dst_hdir); a->dst_h_parent, a->dst_hdir);
if (au_ftest_ren(a->auren_flags, DIRREN)
&& a->h_root)
au_hn_inode_unlock(a->h_root);
if (au_ftest_ren(a->auren_flags, MNT_WRITE)) if (au_ftest_ren(a->auren_flags, MNT_WRITE))
vfsub_mnt_drop_write(au_br_mnt(a->br)); vfsub_mnt_drop_write(au_br_mnt(a->br));
} }
...@@ -653,6 +679,23 @@ static int au_ren_lock(struct au_ren_args *a) ...@@ -653,6 +679,23 @@ static int au_ren_lock(struct au_ren_args *a)
if (unlikely(err)) if (unlikely(err))
goto out; goto out;
au_fset_ren(a->auren_flags, MNT_WRITE); au_fset_ren(a->auren_flags, MNT_WRITE);
if (au_ftest_ren(a->auren_flags, DIRREN)) {
struct dentry *root;
struct inode *dir;
/*
* sbinfo is already locked, so this ii_read_lock is
* unnecessary. but our debugging feature checks it.
*/
root = a->src_inode->i_sb->s_root;
if (root != a->src_parent && root != a->dst_parent) {
dir = d_inode(root);
ii_read_lock_parent3(dir);
a->h_root = au_hi(dir, a->btgt);
ii_read_unlock(dir);
au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
}
}
a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir, a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
a->dst_h_parent, a->dst_hdir); a->dst_h_parent, a->dst_hdir);
udba = au_opt_udba(a->src_dentry->d_sb); udba = au_opt_udba(a->src_dentry->d_sb);
...@@ -748,8 +791,15 @@ static void au_ren_refresh(struct au_ren_args *a) ...@@ -748,8 +791,15 @@ static void au_ren_refresh(struct au_ren_args *a)
au_update_dbrange(d, /*do_put_zero*/0); au_update_dbrange(d, /*do_put_zero*/0);
} }
if (a->exchange
|| au_ftest_ren(a->auren_flags, DIRREN)) {
d_drop(a->src_dentry);
if (au_ftest_ren(a->auren_flags, DIRREN))
au_set_dbwh(a->src_dentry, -1);
return;
}
d = a->src_dentry; d = a->src_dentry;
if (!a->exchange) {
au_set_dbwh(d, -1); au_set_dbwh(d, -1);
bbot = au_dbbot(d); bbot = au_dbbot(d);
for (bindex = a->btgt + 1; bindex <= bbot; bindex++) { for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
...@@ -774,8 +824,6 @@ static void au_ren_refresh(struct au_ren_args *a) ...@@ -774,8 +824,6 @@ static void au_ren_refresh(struct au_ren_args *a)
} }
} }
au_set_ibbot(i, a->btgt); au_set_ibbot(i, a->btgt);
}
d_drop(a->src_dentry);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
...@@ -884,6 +932,7 @@ int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry, ...@@ -884,6 +932,7 @@ int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
unsigned int _flags) unsigned int _flags)
{ {
int err, lock_flags; int err, lock_flags;
void *rev;
/* reduce stack space */ /* reduce stack space */
struct au_ren_args *a; struct au_ren_args *a;
struct au_pin pin; struct au_pin pin;
...@@ -1099,10 +1148,22 @@ int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry, ...@@ -1099,10 +1148,22 @@ int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
/* store timestamps to be revertible */ /* store timestamps to be revertible */
au_ren_dt(a); au_ren_dt(a);
/* store dirren info */
if (au_ftest_ren(a->auren_flags, DIRREN)) {
err = au_dr_rename(a->src_dentry, a->btgt,
&a->dst_dentry->d_name, &rev);
AuTraceErr(err);
if (unlikely(err))
goto out_dt;
}
/* here we go */ /* here we go */
err = do_rename(a); err = do_rename(a);
if (unlikely(err)) if (unlikely(err))
goto out_dt; goto out_dirren;
if (au_ftest_ren(a->auren_flags, DIRREN))
au_dr_rename_fin(a->src_dentry, a->btgt, rev);
/* update dir attributes */ /* update dir attributes */
au_ren_refresh_dir(a); au_ren_refresh_dir(a);
...@@ -1112,6 +1173,9 @@ int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry, ...@@ -1112,6 +1173,9 @@ int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
goto out_hdir; /* success */ goto out_hdir; /* success */
out_dirren:
if (au_ftest_ren(a->auren_flags, DIRREN))
au_dr_rename_rev(a->src_dentry, a->btgt, rev);
out_dt: out_dt:
au_ren_rev_dt(err, a); au_ren_rev_dt(err, a);
out_hdir: out_hdir:
...@@ -1125,10 +1189,19 @@ out_children: ...@@ -1125,10 +1189,19 @@ out_children:
} }
out_parent: out_parent:
if (!err) { if (!err) {
if (d_unhashed(a->src_dentry))
au_fset_ren(a->auren_flags, DROPPED_SRC);
if (d_unhashed(a->dst_dentry))
au_fset_ren(a->auren_flags, DROPPED_DST);
if (!a->exchange) if (!a->exchange)
d_move(a->src_dentry, a->dst_dentry); d_move(a->src_dentry, a->dst_dentry);
else else {
d_exchange(a->src_dentry, a->dst_dentry); d_exchange(a->src_dentry, a->dst_dentry);
if (au_ftest_ren(a->auren_flags, DROPPED_DST))
d_drop(a->dst_dentry);
}
if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
d_drop(a->src_dentry);
} else { } else {
au_update_dbtop(a->dst_dentry); au_update_dbtop(a->dst_dentry);
if (!a->dst_inode) if (!a->dst_inode)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment