From d72c47cb04725c694921e7f3277f6230c26bc936 Mon Sep 17 00:00:00 2001 From: Vikas Gorur Date: Thu, 29 Oct 2009 05:08:34 +0000 Subject: cluster/afr: Move deleted files to /.trash in entry self-heal. If entry self-heal determines that a file/directory should be deleted from a subvolume, move that entry to a directory called "/.trash" on that subvolume. This is for two reasons: 1) It limits the damage that can be done by a "wrong" entry self-heal. 2) It solves the problem of a to-be-deleted directory not being empty. Signed-off-by: Anand V. Avati BUG: 227 (replicate selfheal does not remove directory with contents in it) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=227 --- xlators/cluster/afr/src/afr-dir-read.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'xlators/cluster/afr/src/afr-dir-read.c') diff --git a/xlators/cluster/afr/src/afr-dir-read.c b/xlators/cluster/afr/src/afr-dir-read.c index 5261243d1..fe1f4dadf 100644 --- a/xlators/cluster/afr/src/afr-dir-read.c +++ b/xlators/cluster/afr/src/afr-dir-read.c @@ -155,6 +155,7 @@ afr_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t ** children = NULL; gf_dirent_t * entry = NULL; + gf_dirent_t * tmp = NULL; int child_index = -1; @@ -166,10 +167,16 @@ afr_readdir_cbk (call_frame_t *frame, void *cookie, child_index = (long) cookie; if (op_ret != -1) { - list_for_each_entry (entry, &entries->list, list) { + list_for_each_entry_safe (entry, tmp, &entries->list, list) { entry->d_ino = afr_itransform (entry->d_ino, priv->child_count, child_index); + + if ((local->fd->inode == local->fd->inode->table->root) + && !strcmp (entry->d_name, AFR_TRASH_DIR)) { + list_del_init (&entry->list); + FREE (entry); + } } } @@ -189,6 +196,7 @@ afr_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ino_t inum = 0; gf_dirent_t * entry = NULL; + gf_dirent_t * tmp = NULL; int child_index = -1; @@ -200,13 +208,19 @@ afr_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, child_index = (long) cookie; if (op_ret != -1) { - list_for_each_entry (entry, &entries->list, list) { + list_for_each_entry_safe (entry, tmp, &entries->list, list) { inum = afr_itransform (entry->d_ino, priv->child_count, child_index); entry->d_ino = inum; inum = afr_itransform (entry->d_stat.st_ino, priv->child_count, child_index); entry->d_stat.st_ino = inum; + + if ((local->fd->inode == local->fd->inode->table->root) + && !strcmp (entry->d_name, AFR_TRASH_DIR)) { + list_del_init (&entry->list); + FREE (entry); + } } } -- cgit