summaryrefslogtreecommitdiffstats
path: root/xlators/storage
diff options
context:
space:
mode:
authorvmallika <vmallika@redhat.com>2015-11-02 15:39:46 +0530
committerRaghavendra G <rgowdapp@redhat.com>2015-11-09 03:12:55 -0800
commit9380b1d1fb74cd73d306a1a501e4b7b982c1a76e (patch)
treeb2f0dbc733a166ff9e7ec548bfa59aff9321305d /xlators/storage
parent87c877c93c399863b6afcc642d015627217b79f8 (diff)
marker: do remove xattr only for last link
This is a backport of http://review.gluster.org/#/c/12033/ With unlink, rename, rmdir, contribution xattrs are removed. If the file is a last link then remove_xattr will fail with ENOENT. So it better to perform remove_xattr only if there are more links to the file > Change-Id: Ifc1e7fda4d310fd87f6f28a635c9ea78b8f3929d > BUG: 1257694 > Signed-off-by: vmallika <vmallika@redhat.com> Change-Id: Icf5fdd86bbb8eef0adeb9518e89e5b612e9e0705 BUG: 1279331 Signed-off-by: vmallika <vmallika@redhat.com> Reviewed-on: http://review.gluster.org/12549 Tested-by: NetBSD Build System <jenkins@build.gluster.org> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
Diffstat (limited to 'xlators/storage')
-rw-r--r--xlators/storage/posix/src/posix-helpers.c4
-rw-r--r--xlators/storage/posix/src/posix.c73
2 files changed, 33 insertions, 44 deletions
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index ec6075a8dfd..b6f3bf6686b 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -479,9 +479,9 @@ _posix_xattr_get_set (dict_t *xattr_req, char *key, data_t *data,
} else if (fnmatch (marker_contri_key, key, 0) == 0) {
ret = _posix_get_marker_quota_contributions (filler, key);
- } else if (strcmp(key, CTR_REQUEST_LINK_COUNT_XDATA) == 0) {
+ } else if (strcmp(key, GF_REQUEST_LINK_COUNT_XDATA) == 0) {
ret = dict_set (filler->xattr,
- CTR_REQUEST_LINK_COUNT_XDATA, data);
+ GF_REQUEST_LINK_COUNT_XDATA, data);
} else {
ret = _posix_xattr_get_set_from_backend (filler, key);
}
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 4a01e9f036f..790b61ad2da 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -80,6 +80,28 @@ extern char *marker_xattrs[];
#define SET_TO_OLD_FS_ID()
#endif
+
+dict_t*
+posix_dict_set_nlink (dict_t *req, dict_t *res, int32_t nlink)
+{
+ int ret = -1;
+
+ if (req == NULL || !dict_get (req, GF_REQUEST_LINK_COUNT_XDATA))
+ goto out;
+
+ if (res == NULL)
+ res = dict_new ();
+ if (res == NULL)
+ goto out;
+
+ ret = dict_set_uint32 (res, GF_RESPONSE_LINK_COUNT_XDATA, nlink);
+ if (ret == -1)
+ gf_msg ("posix", GF_LOG_WARNING, 0, P_MSG_SET_XDATA_FAIL,
+ "Failed to set GF_RESPONSE_LINK_COUNT_XDATA");
+out:
+ return res;
+}
+
int
posix_forget (xlator_t *this, inode_t *inode)
{
@@ -1485,7 +1507,7 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
int32_t ctr_link_req = 0;
ssize_t xattr_size = -1;
int32_t is_dht_linkto_file = 0;
- dict_t *unwind_dict = NULL;
+ dict_t *unwind_dict = NULL;
DECLARE_OLD_FS_ID_VAR;
@@ -1620,46 +1642,8 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
goto out;
}
- /*
- *
- * Check if there is a CTR_REQUEST_LINK_COUNT_XDATA from CTR Xlator
- *
- * */
- op_ret = dict_get_int32 (xdata, CTR_REQUEST_LINK_COUNT_XDATA,
- &ctr_link_req);
- if (op_ret) {
- /*Since no request no response*/
- op_ret = 0;
- goto out;
- }
-
- /* Sending back inode link count to ctr_unlink(changetimerecoder xlator)
- * via "CTR_RESPONSE_LINK_COUNT_XDATA" key using unwind_dict.
- * CTR Xlator will clear all the records if the link count has become 1
- * i.e this was the last hard link.
- * */
- unwind_dict = dict_new ();
- /* Even if unwind_dict fails to alloc memory we will not mark the FOP
- * unsuccessful
- * because this dict is only used by CTR Xlator to clear
- * all records if link count == 0*/
- if (!unwind_dict) {
- op_ret = 0;
- goto out;
- }
- /* Even if unwind_dict fails to set CTR_RESPONSE_LINK_COUNT_XDATA we
- * will not mark the FOP unsuccessful
- * because this dict is only used by CTR Xlator to clear
- * all records if link count == 0*/
- op_ret = dict_set_uint32 (unwind_dict, CTR_RESPONSE_LINK_COUNT_XDATA,
- stbuf.ia_nlink);
- if (op_ret == -1) {
- gf_msg (this->name, GF_LOG_WARNING, 0, P_MSG_SET_XDATA_FAIL,
- "Failed to set CTR_RESPONSE_LINK_COUNT_XDATA");
- }
-
+ unwind_dict = posix_dict_set_nlink (xdata, NULL, stbuf.ia_nlink);
op_ret = 0;
-
out:
SET_TO_OLD_FS_ID ();
@@ -1958,6 +1942,7 @@ posix_rename (call_frame_t *frame, xlator_t *this,
int nlink = 0;
char *pgfid_xattr_key = NULL;
int32_t nlink_samepgfid = 0;
+ dict_t *unwind_dict = NULL;
DECLARE_OLD_FS_ID_VAR;
@@ -2137,15 +2122,19 @@ unlock:
goto out;
}
+ if (was_present)
+ unwind_dict = posix_dict_set_nlink (xdata, NULL, nlink);
op_ret = 0;
-
out:
SET_TO_OLD_FS_ID ();
STACK_UNWIND_STRICT (rename, frame, op_ret, op_errno, &stbuf,
&preoldparent, &postoldparent,
- &prenewparent, &postnewparent, NULL);
+ &prenewparent, &postnewparent, unwind_dict);
+
+ if (unwind_dict)
+ dict_unref (unwind_dict);
return 0;
}