From 191ab5693d3c9a0cdedc66bb24dd5efa535963d9 Mon Sep 17 00:00:00 2001 From: Jiffin Tony Thottan Date: Wed, 18 Mar 2015 14:12:03 +0530 Subject: features/trash: Handling hardlinks in trash translator In the current code of trash translator, file is moved to trash directory without checking whether it is the last hardlink.This may lead to inconsistency for a file in that gluster volume.To avoid those scenarios,so a file is moved to trash directory only if it is the last hardlink. Change-Id: Id098e53a2236c6406ef91e6e2599ea2cff9bace3 BUG: 1132465 Signed-off-by: Jiffin Tony Thottan Reviewed-on: http://review.gluster.org/9926 Reviewed-by: Anoop C S Tested-by: Gluster Build System Reviewed-by: Kaleb KEITHLEY Reviewed-by: Vijay Bellur --- xlators/features/trash/src/trash.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'xlators/features/trash/src') diff --git a/xlators/features/trash/src/trash.c b/xlators/features/trash/src/trash.c index 00e99b6266f..932f4696b78 100644 --- a/xlators/features/trash/src/trash.c +++ b/xlators/features/trash/src/trash.c @@ -879,8 +879,16 @@ trash_unlink_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } - /* if the file is too big just unlink it */ + /* Only last hardlink will be moved to trash directory */ + if (buf->ia_nlink > 1) { + STACK_WIND (frame, trash_common_unwind_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->unlink, &local->loc, + 0, xdata); + goto out; + } + /* if the file is too big just unlink it */ if (buf->ia_size > (priv->max_trash_file_size)) { gf_log (this->name, GF_LOG_DEBUG, "%s: file size too big (%"PRId64") to " @@ -1470,6 +1478,16 @@ trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, NULL, xdata); goto out; } + + /* Only last hardlink will be moved to trash directory */ + if (buf->ia_nlink > 1) { + STACK_WIND (frame, trash_common_unwind_buf_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->truncate, + &local->loc, local->fop_offset, xdata); + goto out; + } + /* If the file is too big, just unlink it. */ if (buf->ia_size > (priv->max_trash_file_size)) { gf_log (this->name, GF_LOG_DEBUG, "%s: file too big, " @@ -1972,6 +1990,16 @@ trash_ftruncate_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, NULL, xdata); goto out; } + + /* Only last hardlink will be moved to trash directory */ + if (buf->ia_nlink > 1) { + STACK_WIND (frame, trash_common_unwind_buf_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->ftruncate, + local->fd, local->fop_offset, xdata); + goto out; + } + if ((buf->ia_size > (priv->max_trash_file_size))) { STACK_WIND (frame, trash_common_unwind_buf_cbk, -- cgit