summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
Diffstat (limited to 'xlators')
-rw-r--r--xlators/features/changelog/lib/src/gf-changelog-journal-handler.c75
-rw-r--r--xlators/features/changelog/src/changelog-misc.h6
2 files changed, 70 insertions, 11 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 4029a56..e5bc38f 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);
diff --git a/xlators/features/changelog/src/changelog-misc.h b/xlators/features/changelog/src/changelog-misc.h
index acec6f6..c0349ca 100644
--- a/xlators/features/changelog/src/changelog-misc.h
+++ b/xlators/features/changelog/src/changelog-misc.h
@@ -60,11 +60,13 @@
/**
* ... used by libgfchangelog.
*/
-#define CHANGELOG_GET_ENCODING(fd, buffer, len, enc, enc_len) do { \
+#define CHANGELOG_GET_HEADER_INFO(fd, buffer, len, enc, maj, min, elen) do { \
FILE *fp; \
- int fd_dup, maj, min; \
+ int fd_dup; \
\
enc = -1; \
+ maj = -1; \
+ min = -1; \
fd_dup = dup (fd); \
\
if (fd_dup != -1) { \