diff options
author | Jiffin Tony Thottan <jthottan@redhat.com> | 2015-03-25 15:04:19 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2015-05-04 23:21:06 -0700 |
commit | c85b7c2c0c7b8b9e576ebd20e7446b9051c733e4 (patch) | |
tree | 16d2075b2ff5ab8ed524197fc0eaeeddf8e81030 /xlators/features/trash | |
parent | 3933109fa34d2e405364b57103f8b6a427acc8ec (diff) |
features/trash : Notify CTR translator if an unlink happens to a file
Backport of http://review.gluster.org/#/c/9989/
This implementation is same as the posix_unlink_cbk() where CTR sends
a request during a unlink to send the number of links to the inode
and posix obliges sending it using the unwind xdata dict.
For Trash xlator a unlink is stat + mkdir(if parent is not present)
+ rename. And hence this is handled in trash_unlink_rename_cbk().
Change-Id: I402e83567b88e3c9fe171379693c82937af567f9
BUG: 1218032
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
Signed-off-by: Joseph Fernandes <josferna@redhat.com>
Signed-off-by: Anoop C S <achiraya@redhat.com>
Reviewed-on: http://review.gluster.org/10513
Reviewed-by: Joseph Fernandes
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Dan Lambright <dlambrig@redhat.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/features/trash')
-rw-r--r-- | xlators/features/trash/src/trash.c | 65 | ||||
-rw-r--r-- | xlators/features/trash/src/trash.h | 1 |
2 files changed, 66 insertions, 0 deletions
diff --git a/xlators/features/trash/src/trash.c b/xlators/features/trash/src/trash.c index 5cc051004b4..dafeb183f87 100644 --- a/xlators/features/trash/src/trash.c +++ b/xlators/features/trash/src/trash.c @@ -750,6 +750,7 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, char *dir_name = NULL; char *tmp_cookie = NULL; loc_t tmp_loc = {0,}; + dict_t *new_xdata = NULL; char *tmp_stat = NULL; char real_path[PATH_MAX] = {0,}; int ret = 0; @@ -829,6 +830,58 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } + /********************************************************************** + * + * CTR Xlator message handling done here! + * + **********************************************************************/ + /** + * If unlink is handled by trash translator, it should inform the + * CTR Xlator. And trash translator only handles the unlink for + * the last hardlink. + * + * Check if there is a CTR_REQUEST_LINK_COUNT_XDATA from CTR Xlator + * + */ + + if (local->ctr_link_count_req) { + + /* Sending back inode link count to ctr_unlink + * (changetimerecoder xlator) via + * "CTR_RESPONSE_LINK_COUNT_XDATA" key using xdata. + * */ + if (xdata) { + ret = dict_set_uint32 (xdata, + CTR_RESPONSE_LINK_COUNT_XDATA, + 1); + if (ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "Failed to set" + " CTR_RESPONSE_LINK_COUNT_XDATA"); + } + } else { + new_xdata = dict_new (); + if (!new_xdata) { + gf_log (this->name, GF_LOG_WARNING, + "Memory allocation failure while " + "creating new_xdata"); + goto ctr_out; + } + ret = dict_set_uint32 (new_xdata, + CTR_RESPONSE_LINK_COUNT_XDATA, + 1); + if (ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "Failed to set" + " CTR_RESPONSE_LINK_COUNT_XDATA"); + } +ctr_out: + TRASH_STACK_UNWIND (unlink, frame, 0, op_errno, + &local->preparent, + &local->postparent, new_xdata); + goto out; + } + } /* All other cases, unlink should return success */ TRASH_STACK_UNWIND (unlink, frame, 0, op_errno, &local->preparent, &local->postparent, xdata); @@ -837,6 +890,8 @@ out: GF_FREE (tmp_str); if (tmp_cookie) GF_FREE (tmp_cookie); + if (new_xdata) + dict_unref (new_xdata); return ret; } @@ -938,6 +993,7 @@ trash_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int xflags, trash_private_t *priv = NULL; trash_local_t *local = NULL;/* files inside trash */ int32_t match = 0; + int32_t ctr_link_req = 0; char *pathbuf = NULL; int ret = 0; @@ -1034,6 +1090,15 @@ trash_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int xflags, goto out; } + /* To know whether CTR xlator requested for the link count */ + ret = dict_get_int32 (xdata, CTR_REQUEST_LINK_COUNT_XDATA, + &ctr_link_req); + if (ret) { + local->ctr_link_count_req = _gf_false; + ret = 0; + } else + local->ctr_link_count_req = _gf_true; + LOCK_INIT (&frame->lock); STACK_WIND (frame, trash_unlink_stat_cbk, diff --git a/xlators/features/trash/src/trash.h b/xlators/features/trash/src/trash.h index 3e03edf5474..37d8f7b3d85 100644 --- a/xlators/features/trash/src/trash.h +++ b/xlators/features/trash/src/trash.h @@ -50,6 +50,7 @@ struct trash_struct { int32_t loop_count; struct iatt preparent; struct iatt postparent; + gf_boolean_t ctr_link_count_req; }; typedef struct trash_struct trash_local_t; |