From edfe56dfd8ceb4ef0c160484de04af30e8f5b7df Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Tue, 14 Apr 2015 14:42:46 +0530 Subject: feature/changelog: Capture path for deletes PROBLEM: There is no way to get the path of deleted file if we have gfid from changelog since the file is already deleted. SOLUTION: Do a recursive readlink on parent gfid in backend .glusterfs path to get the complete path in I/O callpath in changelog translator and capture it in callback. The path captured is relative from the brick root. The field separator used is '\0'. e.g., ......\0/bname\0\0 ADDITIONAL REQUIRED CHANGES: 1. The changelog translator option called "changelog.capture-del-path" is introduced to enable or disable the capturing of deleted entry path. e.g., gluster vol set changelog.capture-del-path on/off If capture-del-path is disabled, '\0' is captured instead of relative path. e.g., ......\0/bname\0\0\0 2. The minor number in the version of changelog is bumped up from v1.1 to v1.2. 3. If recursive readlink is failed for some reason, it will capture \0 in place of . e.g., ......\0/bname\0\0\0 (same as when caputre-del-path option is disabled) 4. If bname argument passed to "resolve_pargfid_to_path" function is NULL and pargfid is ROOT, "." is returned. This is not the case with changelog, where bname is always passed. This is applicable to other consumers of "resolve_pargfid_to_path" routine. NOTE: Changelog parser should consider the above new changes and should parse accordingly. BUG: 1218383 Change-Id: I5d89cf4157befd207771f6c0248d2493fbf85832 Signed-off-by: Kotresh HR Reviewed-on: http://review.gluster.org/10288 Reviewed-on: http://review.gluster.org/10535 Tested-by: Gluster Build System Tested-by: NetBSD Build System Reviewed-by: Aravinda VK Reviewed-by: Vijay Bellur --- .../features/changelog/src/changelog-encoders.c | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'xlators/features/changelog/src/changelog-encoders.c') diff --git a/xlators/features/changelog/src/changelog-encoders.c b/xlators/features/changelog/src/changelog-encoders.c index ea9db4061ca..ea395e11f90 100644 --- a/xlators/features/changelog/src/changelog-encoders.c +++ b/xlators/features/changelog/src/changelog-encoders.c @@ -38,6 +38,38 @@ entry_fn (void *data, char *buffer, gf_boolean_t encode) return bufsz; } +size_t +del_entry_fn (void *data, char *buffer, gf_boolean_t encode) +{ + char *tmpbuf = NULL; + size_t bufsz = 0; + struct changelog_entry_fields *ce = NULL; + + ce = (struct changelog_entry_fields *) data; + + if (encode) { + tmpbuf = uuid_utoa (ce->cef_uuid); + CHANGELOG_FILL_BUFFER (buffer, bufsz, tmpbuf, strlen (tmpbuf)); + } else { + CHANGELOG_FILL_BUFFER (buffer, bufsz, + ce->cef_uuid, sizeof (uuid_t)); + } + + CHANGELOG_FILL_BUFFER (buffer, bufsz, "/", 1); + CHANGELOG_FILL_BUFFER (buffer, bufsz, + ce->cef_bname, strlen (ce->cef_bname)); + CHANGELOG_FILL_BUFFER (buffer, bufsz, "\0", 1); + + if (ce->cef_path[0] == '\0') { + CHANGELOG_FILL_BUFFER (buffer, bufsz, "\0", 1); + } else { + CHANGELOG_FILL_BUFFER (buffer, bufsz, + ce->cef_path, strlen (ce->cef_path)); + } + + return bufsz; +} + size_t fop_fn (void *data, char *buffer, gf_boolean_t encode) { @@ -85,6 +117,18 @@ entry_free_fn (void *data) GF_FREE (co->co_entry.cef_bname); } +void +del_entry_free_fn (void *data) +{ + changelog_opt_t *co = data; + + if (!co) + return; + + GF_FREE (co->co_entry.cef_bname); + GF_FREE (co->co_entry.cef_path); +} + /** * try to write all data in one shot */ -- cgit