From cfba6098a4ef8c672969d69678fcdca7c8bb6399 Mon Sep 17 00:00:00 2001 From: Jiffin Tony Thottan Date: Mon, 18 Jul 2016 11:12:43 +0530 Subject: xlator/trash : append '/' at the end in trash_notify_lookup_cbk In the notify function in trash xlator, a lookup is performed to obtain path of old trash directory. The result usually contains path without '/' at the end. The trash xlator maintains expects '/' at the end for the values such as 'old trash dir' and 'new trash dir'. Otherwise certian checks in the code will fail. Upstream reference: >Change-Id: I89e02e4b249314fb6536297f959865feee182c83 >BUG: 1357397 >Signed-off-by: Jiffin Tony Thottan >Reviewed-on: http://review.gluster.org/14938 >Smoke: Gluster Build System >CentOS-regression: Gluster Build System >Reviewed-by: Anoop C S >NetBSD-regression: NetBSD Build System >Reviewed-by: Jeff Darcy >(cherry picked from commit d90307c1b0245e0e6a39044a28819cde520a100c) Change-Id: I89e02e4b249314fb6536297f959865feee182c83 BUG: 1358268 Signed-off-by: Jiffin Tony Thottan Signed-off-by: Oleksandr Natalenko Reviewed-on: http://review.gluster.org/14966 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System --- tests/bugs/unclassified/bug-1357397.t | 29 +++++++++++++++++++++++++++++ xlators/features/trash/src/trash.c | 15 ++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 tests/bugs/unclassified/bug-1357397.t diff --git a/tests/bugs/unclassified/bug-1357397.t b/tests/bugs/unclassified/bug-1357397.t new file mode 100644 index 00000000000..dc76787b505 --- /dev/null +++ b/tests/bugs/unclassified/bug-1357397.t @@ -0,0 +1,29 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../volume.rc + +cleanup + +TEST glusterd +TEST pidof glusterd + +TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1,2} + +TEST $CLI volume start $V0 + +TEST [ -e $B0/${V0}1/.trashcan ] + +TEST [ -e $B0/${V0}1/.trashcan/internal_op ] + +TEST $CLI volume stop $V0 + +rm -rf $B0/${V0}1/.trashcan/internal_op + +TEST [ ! -e $B0/${V0}1/.trashcan/internal_op ] + +TEST $CLI volume start $V0 force + +TEST [ -e $B0/${V0}1/.trashcan/internal_op ] + +cleanup diff --git a/xlators/features/trash/src/trash.c b/xlators/features/trash/src/trash.c index a74716dce15..3a65d788ae9 100644 --- a/xlators/features/trash/src/trash.c +++ b/xlators/features/trash/src/trash.c @@ -294,7 +294,7 @@ trash_notify_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, { data_t *data = NULL; trash_private_t *priv = NULL; - int ret = 0; + int ret = 0; priv = this->private; GF_VALIDATE_OR_GOTO ("trash", priv, out); @@ -310,14 +310,19 @@ trash_notify_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } } else { - priv->oldtrash_dir = gf_strdup (data->data); + priv->oldtrash_dir = GF_CALLOC (1, PATH_MAX, + gf_common_mt_char); if (!priv->oldtrash_dir) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); ret = ENOMEM; goto out; } - gf_log (this->name, GF_LOG_DEBUG, "old trash directory" - " path is %s", data->data); + /* appending '/' if it is not present */ + sprintf (priv->oldtrash_dir, "%s%c", data->data, + data->data[strlen(data->data) - 1] != '/' ? '/' : '\0' + ); + gf_log (this->name, GF_LOG_DEBUG, "old trash directory path " + "is %s", priv->oldtrash_dir); } out: @@ -382,7 +387,7 @@ trash_internal_op_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, struct iatt *buf, struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - if (op_ret != 0) + if (op_ret != 0 && !(op_errno == EEXIST)) gf_log (this->name, GF_LOG_ERROR, "mkdir failed for " "internal op directory : %s", strerror (op_errno)); return op_ret; -- cgit