summaryrefslogtreecommitdiffstats
path: root/xlators/features/changelog/lib
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2015-04-09 00:14:50 +0530
committerVijay Bellur <vbellur@redhat.com>2015-05-08 03:22:02 -0700
commitbd6474eb64fd753bb636f45fd6a099df3b619152 (patch)
treede26693d12f1e9f5702e3bc1796ef9053148f153 /xlators/features/changelog/lib
parent3afff4aacd1b74eff44a9fe320b1547eb165b2eb (diff)
features/changelog: Version support for Changelog Parser
As optional feature, during unlink, full path will be recorded. Changelog Version number to be bumped up to 1.2. With this patch, parser checks the version number before parsing and handles accordingly. Change-Id: Ic1ad98259c39e417029a08e26a1d4b467817e65a BUG: 1218383 Signed-off-by: Kotresh HR <khiremat@redhat.com> Reviewed-on: http://review.gluster.org/10166 Reviewed-on: http://review.gluster.org/10620 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Saravanakumar Arumugam <sarumuga@redhat.com> Tested-by: NetBSD Build System Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/features/changelog/lib')
-rw-r--r--xlators/features/changelog/lib/src/gf-changelog-journal-handler.c75
1 files changed, 66 insertions, 9 deletions
diff --git a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c
index 4029a562dfa..e5bc38f865d 100644
--- a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c
+++ b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c
@@ -22,10 +22,16 @@
extern int byebye;
+enum changelog_versions {
+ VERSION_1_1 = 0,
+ VERSION_1_2 = 1
+};
+
/**
* number of gfid records after fop number
*/
-int nr_gfids[] = {
+int nr_gfids[2][GF_FOP_MAXVALUE] = {
+ {
[GF_FOP_MKNOD] = 1,
[GF_FOP_MKDIR] = 1,
[GF_FOP_UNLINK] = 1,
@@ -34,9 +40,31 @@ int nr_gfids[] = {
[GF_FOP_RENAME] = 2,
[GF_FOP_LINK] = 1,
[GF_FOP_CREATE] = 1,
+ },
+ {
+ [GF_FOP_MKNOD] = 1,
+ [GF_FOP_MKDIR] = 1,
+ [GF_FOP_UNLINK] = 2,
+ [GF_FOP_RMDIR] = 2,
+ [GF_FOP_SYMLINK] = 1,
+ [GF_FOP_RENAME] = 2,
+ [GF_FOP_LINK] = 1,
+ [GF_FOP_CREATE] = 1,
+ }
};
-int nr_extra_recs[] = {
+int nr_extra_recs[2][GF_FOP_MAXVALUE] = {
+ {
+ [GF_FOP_MKNOD] = 3,
+ [GF_FOP_MKDIR] = 3,
+ [GF_FOP_UNLINK] = 0,
+ [GF_FOP_RMDIR] = 0,
+ [GF_FOP_SYMLINK] = 0,
+ [GF_FOP_RENAME] = 0,
+ [GF_FOP_LINK] = 0,
+ [GF_FOP_CREATE] = 3,
+ },
+ {
[GF_FOP_MKNOD] = 3,
[GF_FOP_MKDIR] = 3,
[GF_FOP_UNLINK] = 0,
@@ -45,6 +73,7 @@ int nr_extra_recs[] = {
[GF_FOP_RENAME] = 0,
[GF_FOP_LINK] = 0,
[GF_FOP_CREATE] = 3,
+ }
};
static char *
@@ -116,7 +145,8 @@ static int
gf_changelog_parse_binary (xlator_t *this,
gf_changelog_journal_t *jnl,
int from_fd, int to_fd,
- size_t start_offset, struct stat *stbuf)
+ size_t start_offset, struct stat *stbuf,
+ int version_idx)
{
int ret = -1;
@@ -222,7 +252,8 @@ static int
gf_changelog_parse_ascii (xlator_t *this,
gf_changelog_journal_t *jnl,
int from_fd, int to_fd,
- size_t start_offset, struct stat *stbuf)
+ size_t start_offset, struct stat *stbuf,
+ int version_idx)
{
int ng = 0;
int ret = -1;
@@ -324,7 +355,7 @@ gf_changelog_parse_ascii (xlator_t *this,
len = strlen (fopname);
GF_CHANGELOG_FILL_BUFFER (fopname, ascii, off, len);
- ng = nr_extra_recs[fop];
+ ng = nr_extra_recs[version_idx][fop];
for (; ng > 0; ng--) {
MOVER_MOVE (mover, nleft, 1);
len = strlen (mover);
@@ -336,10 +367,15 @@ gf_changelog_parse_ascii (xlator_t *this,
}
/* pargfid + bname */
- ng = nr_gfids[fop];
+ ng = nr_gfids[version_idx][fop];
while (ng-- > 0) {
MOVER_MOVE (mover, nleft, 1);
len = strlen (mover);
+ if (!len) {
+ MOVER_MOVE (mover, nleft, 1);
+ continue;
+ }
+
GF_CHANGELOG_FILL_BUFFER (" ", ascii, off, 1);
PARSE_GFID (mover, ptr, len,
@@ -420,13 +456,23 @@ gf_changelog_decode (xlator_t *this, gf_changelog_journal_t *jnl,
{
int ret = -1;
int encoding = -1;
+ int major_version = -1;
+ int minor_version = -1;
+ int version_idx = -1;
size_t elen = 0;
char buffer[1024] = {0,};
- CHANGELOG_GET_ENCODING (from_fd, buffer, 1024, encoding, elen);
+ CHANGELOG_GET_HEADER_INFO (from_fd, buffer, 1024, encoding,
+ major_version, minor_version, elen);
if (encoding == -1) /* unknown encoding */
goto out;
+ if (major_version == -1) /* unknown major version */
+ goto out;
+
+ if (minor_version == -1) /* unknown minor version */
+ goto out;
+
if (!CHANGELOG_VALID_ENCODING (encoding))
goto out;
@@ -435,6 +481,15 @@ gf_changelog_decode (xlator_t *this, gf_changelog_journal_t *jnl,
goto out;
}
+ if (major_version == 1 && minor_version == 1) {
+ version_idx = VERSION_1_1;
+ } else if (major_version == 1 && minor_version == 2) {
+ version_idx = VERSION_1_2;
+ }
+
+ if (version_idx == -1) /* unknown version number */
+ goto out;
+
/**
* start processing after the header
*/
@@ -447,12 +502,14 @@ gf_changelog_decode (xlator_t *this, gf_changelog_journal_t *jnl,
* (ie. part of the changelog translator).
*/
ret = gf_changelog_parse_binary (this, jnl, from_fd,
- to_fd, elen, stbuf);
+ to_fd, elen, stbuf,
+ version_idx);
break;
case CHANGELOG_ENCODE_ASCII:
ret = gf_changelog_parse_ascii (this, jnl, from_fd,
- to_fd, elen, stbuf);
+ to_fd, elen, stbuf,
+ version_idx);
break;
default:
ret = gf_changelog_copy (this, from_fd, to_fd);