summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--xlators/features/changelog/lib/examples/c/get-changes.c2
-rw-r--r--xlators/features/changelog/lib/src/gf-changelog-helpers.h1
-rw-r--r--xlators/features/changelog/lib/src/gf-changelog-process.c79
-rw-r--r--xlators/features/changelog/src/Makefile.am8
-rw-r--r--xlators/features/changelog/src/changelog-encoders.c118
-rw-r--r--xlators/features/changelog/src/changelog-encoders.h12
-rw-r--r--xlators/features/changelog/src/changelog-helpers.c211
-rw-r--r--xlators/features/changelog/src/changelog-helpers.h254
-rw-r--r--xlators/features/changelog/src/changelog-mem-types.h9
-rw-r--r--xlators/features/changelog/src/changelog-misc.h10
-rw-r--r--xlators/features/changelog/src/changelog-rt.c9
-rw-r--r--xlators/features/changelog/src/changelog-rt.h5
-rw-r--r--xlators/features/changelog/src/changelog.c531
13 files changed, 664 insertions, 585 deletions
diff --git a/xlators/features/changelog/lib/examples/c/get-changes.c b/xlators/features/changelog/lib/examples/c/get-changes.c
index 14562585a..6d0d0357d 100644
--- a/xlators/features/changelog/lib/examples/c/get-changes.c
+++ b/xlators/features/changelog/lib/examples/c/get-changes.c
@@ -40,7 +40,7 @@ main (int argc, char ** argv)
char fbuf[PATH_MAX] = {0,};
/* get changes for brick "/home/vshankar/export/yow/yow-1" */
- ret = gf_changelog_register ("/home/vshankar/export/yow/yow-1",
+ ret = gf_changelog_register ("/home/vshankar/exports/yow/yow-1",
"/tmp/scratch", "/tmp/change.log", 9, 5);
if (ret) {
handle_error ("register failed");
diff --git a/xlators/features/changelog/lib/src/gf-changelog-helpers.h b/xlators/features/changelog/lib/src/gf-changelog-helpers.h
index f35220ccb..3aa6ed7b8 100644
--- a/xlators/features/changelog/lib/src/gf-changelog-helpers.h
+++ b/xlators/features/changelog/lib/src/gf-changelog-helpers.h
@@ -94,5 +94,4 @@ gf_ftruncate (int fd, off_t length);
off_t
gf_lseek (int fd, off_t offset, int whence);
-
#endif
diff --git a/xlators/features/changelog/lib/src/gf-changelog-process.c b/xlators/features/changelog/lib/src/gf-changelog-process.c
index df7204931..3ea2700c6 100644
--- a/xlators/features/changelog/lib/src/gf-changelog-process.c
+++ b/xlators/features/changelog/lib/src/gf-changelog-process.c
@@ -36,6 +36,17 @@ int nr_gfids[] = {
[GF_FOP_CREATE] = 1,
};
+int nr_extra_recs[] = {
+ [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,
+};
+
static char *
binary_to_ascii (uuid_t uuid)
{
@@ -211,20 +222,20 @@ gf_changelog_parse_ascii (xlator_t *this,
gf_changelog_t *gfc, int from_fd, int to_fd,
size_t start_offset, struct stat *stbuf)
{
- int ng = 0;
- int ret = -1;
- int fop = 0;
- int len = 0;
- off_t off = 0;
- off_t nleft = 0;
- char *ptr = NULL;
- char *eptr = NULL;
- char *start = NULL;
- char *mover = NULL;
- int parse_err = 0;
- char current_mover = ' ';
- char ascii[LINE_BUFSIZE] = {0,};
- const char *fopname = NULL;
+ int ng = 0;
+ int ret = -1;
+ int fop = 0;
+ int len = 0;
+ off_t off = 0;
+ off_t nleft = 0;
+ char *ptr = NULL;
+ char *eptr = NULL;
+ char *start = NULL;
+ char *mover = NULL;
+ int parse_err = 0;
+ char current_mover = ' ';
+ char ascii[LINE_BUFSIZE] = {0,};
+ const char *fopname = NULL;
nleft = stbuf->st_size;
@@ -249,7 +260,6 @@ gf_changelog_parse_ascii (xlator_t *this,
switch (current_mover) {
case 'D':
- case 'M':
MOVER_MOVE (mover, nleft, 1);
/* target gfid */
@@ -258,6 +268,32 @@ gf_changelog_parse_ascii (xlator_t *this,
FILL_AND_MOVE(ptr, ascii, off,
mover, nleft, UUID_CANONICAL_FORM_LEN);
break;
+ case 'M':
+ MOVER_MOVE (mover, nleft, 1);
+
+ /* target gfid */
+ PARSE_GFID (mover, ptr, UUID_CANONICAL_FORM_LEN,
+ conv_noop, parse_err);
+ FILL_AND_MOVE (ptr, ascii, off,
+ mover, nleft, UUID_CANONICAL_FORM_LEN);
+ FILL_AND_MOVE (" ", ascii, off, mover, nleft, 1);
+
+ /* fop */
+ len = strlen (mover);
+ VERIFY_SEPARATOR (mover, len, parse_err);
+
+ fop = atoi (mover);
+ if ( (fopname = gf_fop_list[fop]) == NULL) {
+ parse_err = 1;
+ break;
+ }
+
+ MOVER_MOVE (mover, nleft, len);
+
+ len = strlen (fopname);
+ GF_CHANGELOG_FILL_BUFFER (fopname, ascii, off, len);
+
+ break;
case 'E':
MOVER_MOVE (mover, nleft, 1);
@@ -285,6 +321,17 @@ gf_changelog_parse_ascii (xlator_t *this,
len = strlen (fopname);
GF_CHANGELOG_FILL_BUFFER (fopname, ascii, off, len);
+ ng = nr_extra_recs[fop];
+ for (;ng > 0; ng--) {
+ MOVER_MOVE (mover, nleft, 1);
+ len = strlen (mover);
+ VERIFY_SEPARATOR (mover, len, parse_err);
+
+ GF_CHANGELOG_FILL_BUFFER (" ", ascii, off, 1);
+ FILL_AND_MOVE (mover, ascii,
+ off, mover, nleft, len);
+ }
+
/* pargfid + bname */
ng = nr_gfids[fop];
while (ng-- > 0) {
@@ -320,7 +367,7 @@ gf_changelog_parse_ascii (xlator_t *this,
if (gf_changelog_write (to_fd, ascii, off) != off) {
gf_log (this->name, GF_LOG_ERROR,
"processing ascii changelog failed due to "
- " wrror in writing change (reason: %s)",
+ " error in writing change (reason: %s)",
strerror (errno));
break;
}
diff --git a/xlators/features/changelog/src/Makefile.am b/xlators/features/changelog/src/Makefile.am
index f8beba430..e85031ad4 100644
--- a/xlators/features/changelog/src/Makefile.am
+++ b/xlators/features/changelog/src/Makefile.am
@@ -3,17 +3,15 @@ xlator_LTLIBRARIES = changelog.la
xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/features
noinst_HEADERS = changelog-helpers.h changelog-mem-types.h changelog-rt.h \
- changelog-misc.h changelog-encoders.h changelog-notifier.h \
- changelog-fops.h policy/changelog-policy.h
+ changelog-misc.h changelog-encoders.h changelog-notifier.h
changelog_la_LDFLAGS = -module -avoidversion
changelog_la_SOURCES = changelog.c changelog-rt.c changelog-helpers.c \
- changelog-encoders.c changelog-notifier.c changelog-default-fops.c \
- policy/changelog-policy-default.c policy/changelog-policy-replication.c
+ changelog-encoders.c changelog-notifier.c
changelog_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
-AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src -Ipolicy/ -fPIC -D_FILE_OFFSET_BITS=64 \
+AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src -fPIC -D_FILE_OFFSET_BITS=64 \
-D_GNU_SOURCE -D$(GF_HOST_OS) -shared -nostartfiles -DDATADIR=\"$(localstatedir)\"
AM_CFLAGS = -Wall $(GF_CFLAGS)
diff --git a/xlators/features/changelog/src/changelog-encoders.c b/xlators/features/changelog/src/changelog-encoders.c
index 8d45ee1ff..08626ee2f 100644
--- a/xlators/features/changelog/src/changelog-encoders.c
+++ b/xlators/features/changelog/src/changelog-encoders.c
@@ -56,6 +56,24 @@ fop_fn (void *data, char *buffer, gf_boolean_t encode)
return bufsz;
}
+size_t
+number_fn (void *data, char *buffer, gf_boolean_t encode)
+{
+ size_t bufsz = 0;
+ unsigned int nr = 0;
+ char buf[20] = {0,};
+
+ nr = *(unsigned int *) data;
+
+ if (encode) {
+ (void) snprintf (buf, sizeof (buf), "%u", nr);
+ CHANGELOG_FILL_BUFFER (buffer, bufsz, buf, strlen (buf));
+ } else
+ CHANGELOG_FILL_BUFFER (buffer, bufsz, &nr, sizeof (unsigned int));
+
+ return bufsz;
+}
+
void
entry_free_fn (void *data)
{
@@ -72,7 +90,7 @@ entry_free_fn (void *data)
*/
static inline void
-changelog_encode_write_xtra (changelog_write_data_t *cwd,
+changelog_encode_write_xtra (changelog_log_data_t *cld,
char *buffer, size_t *off, gf_boolean_t encode)
{
int i = 0;
@@ -82,11 +100,10 @@ changelog_encode_write_xtra (changelog_write_data_t *cwd,
offset = *off;
- co = (changelog_opt_t *) cwd->cwd_ptr;
+ co = (changelog_opt_t *) cld->cld_ptr;
- for (; i < cwd->cwd_xtra_records; i++, co++) {
- if (i)
- CHANGELOG_FILL_BUFFER (buffer, offset, "\0", 1);
+ for (; i < cld->cld_xtra_records; i++, co++) {
+ CHANGELOG_FILL_BUFFER (buffer, offset, "\0", 1);
switch (co->co_type) {
case CHANGELOG_OPT_REC_FOP:
@@ -95,11 +112,8 @@ changelog_encode_write_xtra (changelog_write_data_t *cwd,
case CHANGELOG_OPT_REC_ENTRY:
data = &co->co_entry;
break;
- case CHANGELOG_OPT_REC_ULL:
- data = &co->co_number;
- break;
- case CHANGELOG_OPT_REC_UUID:
- data = &co->co_uuid;
+ case CHANGELOG_OPT_REC_UINT32:
+ data = &co->co_uint32;
break;
}
@@ -115,59 +129,69 @@ changelog_encode_write_xtra (changelog_write_data_t *cwd,
}
int
-changelog_encode_ascii (xlator_t *this,
- changelog_local_t *local, changelog_log_data_t *cld)
+changelog_encode_ascii (xlator_t *this, changelog_log_data_t *cld)
{
- size_t off = 0;
- size_t gfid_len = 0;
- char *gfid_str = NULL;
- char *buffer = NULL;
- changelog_priv_t *priv = NULL;
- changelog_write_data_t *cwd = NULL;
+ size_t off = 0;
+ size_t gfid_len = 0;
+ char *gfid_str = NULL;
+ char *buffer = NULL;
+ changelog_priv_t *priv = NULL;
priv = this->private;
- cwd = &cld->cld_wdata;
- gfid_str = uuid_utoa (cwd->cwd_gfid);
+ gfid_str = uuid_utoa (cld->cld_gfid);
gfid_len = strlen (gfid_str);
/* extra bytes for decorations */
- buffer = alloca (gfid_len + cwd->cwd_ptr_len + 100);
- if (!priv->no_gfid_hdr)
- CHANGELOG_STORE_ASCII (priv, buffer,
- off, gfid_str, gfid_len, cld);
-
- if (cwd->cwd_xtra_records) {
- changelog_encode_write_xtra (cwd, buffer, &off, _gf_true);
- CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1);
- }
+ buffer = alloca (gfid_len + cld->cld_ptr_len + 10);
+ CHANGELOG_STORE_ASCII (priv, buffer,
+ off, gfid_str, gfid_len, cld);
+
+ if (cld->cld_xtra_records)
+ changelog_encode_write_xtra (cld, buffer, &off, _gf_true);
- return changelog_write_change (this, priv,
- local, buffer, off);
+ CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1);
+
+ return changelog_write_change (priv, buffer, off);
}
int
-changelog_encode_binary (xlator_t *this,
- changelog_local_t *local, changelog_log_data_t *cld)
+changelog_encode_binary (xlator_t *this, changelog_log_data_t *cld)
{
- size_t off = 0;
- char *buffer = NULL;
- changelog_priv_t *priv = NULL;
- changelog_write_data_t *cwd = NULL;
+ size_t off = 0;
+ char *buffer = NULL;
+ changelog_priv_t *priv = NULL;
priv = this->private;
- cwd = &cld->cld_wdata;
/* extra bytes for decorations */
- buffer = alloca (sizeof (uuid_t) + cwd->cwd_ptr_len + 100);
- if (!priv->no_gfid_hdr)
- CHANGELOG_STORE_BINARY (priv, buffer, off, cwd->cwd_gfid, cld);
+ buffer = alloca (sizeof (uuid_t) + cld->cld_ptr_len + 10);
+ CHANGELOG_STORE_BINARY (priv, buffer, off, cld->cld_gfid, cld);
- if (cwd->cwd_xtra_records) {
- changelog_encode_write_xtra (cwd, buffer, &off, _gf_false);
- CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1);
- }
+ if (cld->cld_xtra_records)
+ changelog_encode_write_xtra (cld, buffer, &off, _gf_false);
+
+ CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1);
- return changelog_write_change (this, priv,
- local, buffer, off);
+ return changelog_write_change (priv, buffer, off);
+}
+
+static struct changelog_encoder
+cb_encoder[] = {
+ [CHANGELOG_ENCODE_BINARY] =
+ {
+ .encoder = CHANGELOG_ENCODE_BINARY,
+ .encode = changelog_encode_binary,
+ },
+ [CHANGELOG_ENCODE_ASCII] =
+ {
+ .encoder = CHANGELOG_ENCODE_ASCII,
+ .encode = changelog_encode_ascii,
+ },
+};
+
+void
+changelog_encode_change( changelog_priv_t * priv)
+{
+ priv->ce = &cb_encoder[priv->encode_mode];
}
diff --git a/xlators/features/changelog/src/changelog-encoders.h b/xlators/features/changelog/src/changelog-encoders.h
index 2a96ba4dd..c5dcc8a77 100644
--- a/xlators/features/changelog/src/changelog-encoders.h
+++ b/xlators/features/changelog/src/changelog-encoders.h
@@ -21,7 +21,6 @@
priv->maps[cld->cld_type], 1); \
CHANGELOG_FILL_BUFFER (buffer, \
off, gfid, gfid_len); \
- CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1); \
} while (0)
#define CHANGELOG_STORE_BINARY(priv, buf, off, gfid, cld) do { \
@@ -29,20 +28,21 @@
priv->maps[cld->cld_type], 1); \
CHANGELOG_FILL_BUFFER (buffer, \
off, gfid, sizeof (uuid_t)); \
- CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1); \
} while (0)
size_t
entry_fn (void *data, char *buffer, gf_boolean_t encode);
size_t
fop_fn (void *data, char *buffer, gf_boolean_t encode);
+size_t
+number_fn (void *data, char *buffer, gf_boolean_t encode);
void
entry_free_fn (void *data);
int
-changelog_encode_binary (xlator_t *,
- changelog_local_t *, changelog_log_data_t *);
+changelog_encode_binary (xlator_t *, changelog_log_data_t *);
int
-changelog_encode_ascii (xlator_t *,
- changelog_local_t *, changelog_log_data_t *);
+changelog_encode_ascii (xlator_t *, changelog_log_data_t *);
+void
+changelog_encode_change(changelog_priv_t *);
#endif /* _CHANGELOG_ENCODERS_H */
diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c
index ad4fe4013..91c43a16c 100644
--- a/xlators/features/changelog/src/changelog-helpers.c
+++ b/xlators/features/changelog/src/changelog-helpers.c
@@ -21,6 +21,7 @@
#include "changelog-helpers.h"
#include "changelog-mem-types.h"
+#include "changelog-encoders.h"
#include <pthread.h>
void
@@ -52,45 +53,51 @@ changelog_thread_cleanup (xlator_t *this, pthread_t thr_id)
inline void *
changelog_get_usable_buffer (changelog_local_t *local)
{
- changelog_write_data_t *cwd = &local->cld.cld_wdata;
+ changelog_log_data_t *cld = NULL;
- if (!cwd->cwd_iobuf)
+ if (!local)
+ return NULL;
+
+ cld = &local->cld;
+ if (!cld->cld_iobuf)
return NULL;
- return cwd->cwd_ptr;
+ return cld->cld_iobuf->ptr;
}
inline void
changelog_set_usable_record_and_length (changelog_local_t *local,
size_t len, int xr)
{
- changelog_write_data_t *cwd = &local->cld.cld_wdata;
+ changelog_log_data_t *cld = NULL;
- cwd->cwd_ptr_len = len;
- cwd->cwd_xtra_records = xr;
+ cld = &local->cld;
+
+ cld->cld_ptr_len = len;
+ cld->cld_xtra_records = xr;
}
void
changelog_local_cleanup (xlator_t *xl, changelog_local_t *local)
{
- int i = 0;
- changelog_opt_t *co = NULL;
- changelog_write_data_t *cwd = NULL;
+ int i = 0;
+ changelog_opt_t *co = NULL;
+ changelog_log_data_t *cld = NULL;
if (!local)
return;
- cwd = &local->cld.cld_wdata;
+ cld = &local->cld;
/* cleanup dynamic allocation for extra records */
- if (cwd->cwd_xtra_records) {
- co = (changelog_opt_t *) cwd->cwd_ptr;
- for (; i < cwd->cwd_xtra_records; i++, co++)
+ if (cld->cld_xtra_records) {
+ co = (changelog_opt_t *) cld->cld_ptr;
+ for (; i < cld->cld_xtra_records; i++, co++)
if (co->co_free)
co->co_free (co);
}
- CHANGELOG_IOBUF_UNREF (cwd->cwd_iobuf);
+ CHANGELOG_IOBUF_UNREF (cld->cld_iobuf);
if (local->inode)
inode_unref (local->inode);
@@ -118,8 +125,7 @@ changelog_write (int fd, char *buffer, size_t len)
static int
changelog_rollover_changelog (xlator_t *this,
- changelog_priv_t *priv,
- changelog_rollover_data_t *crd)
+ changelog_priv_t *priv, unsigned long ts)
{
int ret = -1;
int notify = 0;
@@ -132,22 +138,11 @@ changelog_rollover_changelog (xlator_t *this,
priv->changelog_fd = -1;
}
- /**
- * no rolling-over of changelogs, policy implementer choose
- * to do the heavy-lifting of having distinct changelog name.
- *
- * NOTE: This implies libgfchangelog would not be notified
- (well, we could, but lets not do that now...)
- */
- if (!crd->crd_use_suffix)
- return 0;
-
(void) snprintf (ofile, PATH_MAX,
- "%s/%s", priv->changelog_dir,
- crd->crd_changelog_oname);
- (void) snprintf (nfile, PATH_MAX, "%s/%s.%lu",
- priv->changelog_dir,
- crd->crd_changelog_name, crd->crd_roll_key);
+ "%s/"CHANGELOG_FILE_NAME, priv->changelog_dir);
+ (void) snprintf (nfile, PATH_MAX,
+ "%s/"CHANGELOG_FILE_NAME".%lu",
+ priv->changelog_dir, ts);
ret = rename (ofile, nfile);
if (!ret)
@@ -179,8 +174,7 @@ changelog_rollover_changelog (xlator_t *this,
int
changelog_open (xlator_t *this,
- changelog_priv_t *priv,
- changelog_local_t *local, changelog_rollover_data_t *crd)
+ changelog_priv_t *priv)
{
int fd = 0;
int ret = -1;
@@ -189,12 +183,12 @@ changelog_open (xlator_t *this,
char changelog_path[PATH_MAX] = {0,};
(void) snprintf (changelog_path, PATH_MAX,
- "%s/%s", priv->changelog_dir,
- crd->crd_changelog_name);
+ "%s/"CHANGELOG_FILE_NAME,
+ priv->changelog_dir);
flags |= (O_CREAT | O_RDWR);
if (priv->fsync_interval == 0)
- flags |= O_SYNC;
+ flags |= O_SYNC;
fd = open (changelog_path, flags,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -207,25 +201,12 @@ changelog_open (xlator_t *this,
}
priv->changelog_fd = fd;
- CHANGELOG_INVOKE_CFOP (this, priv, reset_offset, local);
-
- /* preallocate if required */
- if (crd->crd_prealloc_size > 0) {
- ret = posix_fallocate (priv->changelog_fd,
- 0, crd->crd_prealloc_size);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to preallocate %llu bytes",
- (unsigned long long) crd->crd_prealloc_size);
- }
- }
(void) snprintf (buffer, 1024, CHANGELOG_HEADER,
CHANGELOG_VERSION_MAJOR,
CHANGELOG_VERSION_MINOR,
- priv->encode_mode);
- ret = changelog_write_change (this, priv,
- local, buffer, strlen (buffer));
+ priv->ce->encoder);
+ ret = changelog_write_change (priv, buffer, strlen (buffer));
if (ret) {
close (priv->changelog_fd);
priv->changelog_fd = -1;
@@ -238,19 +219,18 @@ changelog_open (xlator_t *this,
return ret;
}
-static int
+int
changelog_start_next_change (xlator_t *this,
changelog_priv_t *priv,
- changelog_local_t *local,
- changelog_log_data_t *cld)
+ unsigned long ts, gf_boolean_t finale)
{
- int ret = 0;
- changelog_rollover_data_t *crd = &cld->cld_roll;
+ int ret = -1;
- ret = changelog_rollover_changelog (this, priv, crd);
+ ret = changelog_rollover_changelog (this, priv, ts);
+
+ if (!ret && !finale)
+ ret = changelog_open (this, priv);
- if (!ret && !crd->crd_finale)
- ret = changelog_open (this, priv, local, crd);
return ret;
}
@@ -264,42 +244,37 @@ changelog_entry_length ()
}
int
-changelog_write_change (xlator_t *this, changelog_priv_t *priv,
- changelog_local_t *local, char *buffer, size_t len)
+changelog_fill_rollover_data (changelog_log_data_t *cld, gf_boolean_t is_last)
{
- int ret = -1;
- off_t offset = 0;
- ssize_t size = 0;
- size_t writen = 0;
-
- offset = CHANGELOG_INVOKE_CFOP (this, priv, get_offset, local);
+ struct timeval tv = {0,};
- while (writen < len) {
- size = pwrite (priv->changelog_fd,
- buffer + writen, len - writen, offset + writen);
- if (size <= 0)
- break;
+ cld->cld_type = CHANGELOG_TYPE_ROLLOVER;
- writen += size;
- }
+ if (gettimeofday (&tv, NULL))
+ return -1;
- if (writen == len) {
- ret = 0;
- CHANGELOG_INVOKE_CFOP (this, priv, set_offset, local, writen);
- }
+ cld->cld_roll_time = (unsigned long) tv.tv_sec;
+ cld->cld_finale = is_last;
+ return 0;
+}
- return ret;
+int
+changelog_write_change (changelog_priv_t *priv, char *buffer, size_t len)
+{
+ return changelog_write (priv->changelog_fd, buffer, len);
}
inline int
changelog_handle_change (xlator_t *this,
- changelog_priv_t *priv,
- changelog_local_t *local, changelog_log_data_t *cld)
+ changelog_priv_t *priv, changelog_log_data_t *cld)
{
int ret = 0;
if (CHANGELOG_TYPE_IS_ROLLOVER (cld->cld_type)) {
- ret = changelog_start_next_change (this, priv, local, cld);
+ changelog_encode_change(priv);
+ ret = changelog_start_next_change (this, priv,
+ cld->cld_roll_time,
+ cld->cld_finale);
if (ret)
gf_log (this->name, GF_LOG_ERROR,
"Problem rolling over changelog(s)");
@@ -323,7 +298,7 @@ changelog_handle_change (xlator_t *this,
goto out;
}
- ret = priv->ce->encode (this, local, cld);
+ ret = priv->ce->encode (this, cld);
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
"error writing changelog to disk");
@@ -333,17 +308,6 @@ changelog_handle_change (xlator_t *this,
return ret;
}
-static inline void
-changelog_local_init_defaults (changelog_local_t *local,
- uuid_t gfid, struct iobuf *iobuf)
-{
- changelog_write_data_t *cwd = &(local->cld.cld_wdata);
-
- uuid_copy (cwd->cwd_gfid, gfid);
- cwd->cwd_iobuf = iobuf;
- cwd->cwd_xtra_records = 0; /* set by the caller */
-}
-
changelog_local_t *
changelog_local_init (xlator_t *this, inode_t *inode,
uuid_t gfid, int xtra_records,
@@ -353,7 +317,7 @@ changelog_local_init (xlator_t *this, inode_t *inode,
struct iobuf *iobuf = NULL;
/**
- * Relax the presence of inode if @update_flag is true.
+ * We relax the presence of inode if @update_flag is true.
* The caller (implmentation of the fop) needs to be careful to
* not blindly use local->inode.
*/
@@ -378,7 +342,10 @@ changelog_local_init (xlator_t *this, inode_t *inode,
local->update_no_check = update_flag;
- (void) changelog_local_init_defaults (local, gfid, iobuf);
+ uuid_copy (local->cld.cld_gfid, gfid);
+
+ local->cld.cld_iobuf = iobuf;
+ local->cld.cld_xtra_records = 0; /* set by the caller */
if (inode)
local->inode = inode_ref (inode);
@@ -406,11 +373,9 @@ changelog_forget (xlator_t *this, inode_t *inode)
int
changelog_inject_single_event (xlator_t *this,
changelog_priv_t *priv,
- changelog_local_t *local,
changelog_log_data_t *cld)
{
- return priv->cd.dispatchfn (this, priv,
- priv->cd.cd_data, local, cld);
+ return priv->cd.dispatchfn (this, priv, priv->cd.cd_data, cld, NULL);
}
/**
@@ -421,9 +386,9 @@ void *
changelog_rollover (void *data)
{
int ret = 0;
- char *cname = NULL;
xlator_t *this = NULL;
struct timeval tv = {0,};
+ changelog_log_data_t cld = {0,};
changelog_time_slice_t *slice = NULL;
changelog_priv_t *priv = data;
@@ -438,11 +403,16 @@ changelog_rollover (void *data)
if (ret)
continue;
+ ret = changelog_fill_rollover_data (&cld, _gf_false);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "failed to fill rollover data");
+ continue;
+ }
+
LOCK (&priv->lock);
{
- cname = CHANGELOG_FNAME_FROM_POLICY (priv->cp);
- ret = CHANGELOG_INVOKE_CFOP (this, priv, rollover,
- cname, _gf_false);
+ ret = changelog_inject_single_event (this, priv, &cld);
if (!ret)
SLICE_VERSION_UPDATE (slice);
}
@@ -458,9 +428,11 @@ changelog_fsync_thread (void *data)
int ret = 0;
xlator_t *this = NULL;
struct timeval tv = {0,};
+ changelog_log_data_t cld = {0,};
changelog_priv_t *priv = data;
this = priv->cf.this;
+ cld.cld_type = CHANGELOG_TYPE_FSYNC;
while (1) {
tv.tv_sec = priv->fsync_interval;
@@ -470,7 +442,7 @@ changelog_fsync_thread (void *data)
if (ret)
continue;
- ret = CHANGELOG_INVOKE_CFOP (this, priv, sync);
+ ret = changelog_inject_single_event (this, priv, &cld);
if (ret)
gf_log (this->name, GF_LOG_ERROR,
"failed to inject fsync event");
@@ -668,19 +640,19 @@ changelog_inode_ctx_get (xlator_t *this,
* signifies an update was recorded in the current time slice).
*/
inline void
-changelog_update (xlator_t *this,
- changelog_priv_t *priv,
- changelog_local_t *local,
- changelog_log_type type)
+changelog_update (xlator_t *this, changelog_priv_t *priv,
+ changelog_local_t *local, changelog_log_type type)
{
- int ret = 0;
- unsigned long *iver = NULL;
- unsigned long version = 0;
- inode_t *inode = NULL;
- changelog_time_slice_t *slice = NULL;
- changelog_inode_ctx_t *ctx = NULL;
- changelog_log_data_t *cld_0 = NULL;
- gf_boolean_t need_upd = _gf_true;
+ int ret = 0;
+ unsigned long *iver = NULL;
+ unsigned long version = 0;
+ inode_t *inode = NULL;
+ changelog_time_slice_t *slice = NULL;
+ changelog_inode_ctx_t *ctx = NULL;
+ changelog_log_data_t *cld_0 = NULL;
+ changelog_log_data_t *cld_1 = NULL;
+ changelog_local_t *next_local = NULL;
+ gf_boolean_t need_upd = _gf_true;
slice = &priv->slice;
@@ -704,8 +676,13 @@ changelog_update (xlator_t *this,
cld_0 = &local->cld;
cld_0->cld_type = type;
+ if ( (next_local = local->prev_entry) != NULL ) {
+ cld_1 = &next_local->cld;
+ cld_1->cld_type = type;
+ }
+
ret = priv->cd.dispatchfn (this, priv,
- priv->cd.cd_data, local, cld_0);
+ priv->cd.cd_data, cld_0, cld_1);
/**
* update after the dispatcher has successfully done
diff --git a/xlators/features/changelog/src/changelog-helpers.h b/xlators/features/changelog/src/changelog-helpers.h
index 656fb7ffa..16d60b99b 100644
--- a/xlators/features/changelog/src/changelog-helpers.h
+++ b/xlators/features/changelog/src/changelog-helpers.h
@@ -19,15 +19,23 @@
#include "changelog-misc.h"
/**
- * structures representing the changelog entries
+ * the changelog entry
*/
-typedef struct changelog_write_data {
+typedef struct changelog_log_data {
+ /* rollover related */
+ unsigned long cld_roll_time;
+
+ /* reopen changelog? */
+ gf_boolean_t cld_finale;
+
+ changelog_log_type cld_type;
+
/**
* sincd gfid is _always_ a necessity, it's not a part
* of the iobuf. by doing this we do not add any overhead
* for data and metadata related fops.
*/
- uuid_t cwd_gfid;
+ uuid_t cld_gfid;
/**
* iobufs are used for optionals records: pargfid, path,
@@ -35,78 +43,25 @@ typedef struct changelog_write_data {
* to allocate (iobuf_get() in the fop) and get unref'ed
* in the callback (CHANGELOG_STACK_UNWIND).
*/
- struct iobuf *cwd_iobuf;
+ struct iobuf *cld_iobuf;
+
+#define cld_ptr cld_iobuf->ptr
/**
* after allocation you can point this to the length of
* usable data, but make sure it does not exceed the
* the size of the requested iobuf.
*/
- size_t cwd_iobuf_len;
- #define cwd_ptr cwd_iobuf->ptr
- #define cwd_ptr_len cwd_iobuf_len
-
- /**
- * number of optional records
- */
- int cwd_xtra_records;
-} changelog_write_data_t;
-
-typedef struct changelog_rollover_data {
- /**
- * need a changelog reopen?
- */
- gf_boolean_t crd_finale;
+ size_t cld_iobuf_len;
- /**
- * changelog file name to be opened after a rollover
- */
- char crd_changelog_name[PATH_MAX];
+#define cld_ptr_len cld_iobuf_len
/**
- * changelog file name before rollover
- */
- char crd_changelog_oname[PATH_MAX];
-
- /**
- * use @crd_roll_key as suffix during roll-over
- */
- gf_boolean_t crd_use_suffix;
-
- /**
- * suffix used when rolling a changelog
- */
- unsigned long crd_roll_key;
-
- /**
- * preallocation? if yes, how much?
- */
- off_t crd_prealloc_size;
-} changelog_rollover_data_t;
-
-/**
- * the changelog entry: structure representing the type of entry
- * and a union encapsulating the above declared structures.
- */
-typedef struct changelog_log_data {
- /**
- * type of the log data entry
- */
- changelog_log_type cld_type;
-
- /**
- * union for the type of changelog operations. @fsync() does
- * not have a corresponding entry in this union as it just
- * performs and @fsync() on ->changelog_fd.
+ * number of optional records
*/
- union {
- changelog_write_data_t cld_wdata;
- changelog_rollover_data_t cld_roll;
- };
+ int cld_xtra_records;
} changelog_log_data_t;
-typedef struct changelog_local changelog_local_t;
-
/**
* holder for dispatch function and private data
*/
@@ -115,9 +70,8 @@ typedef struct changelog_priv changelog_priv_t;
typedef struct changelog_dispatcher {
void *cd_data;
- int (*dispatchfn) (xlator_t *,
- changelog_priv_t *, void *,
- changelog_local_t *, changelog_log_data_t *);
+ int (*dispatchfn) (xlator_t *, changelog_priv_t *, void *,
+ changelog_log_data_t *, changelog_log_data_t *);
} changelog_dispatcher_t;
struct changelog_bootstrap {
@@ -128,84 +82,9 @@ struct changelog_bootstrap {
struct changelog_encoder {
changelog_encoder_t encoder;
- int (*encode) (xlator_t *,
- changelog_local_t *, changelog_log_data_t *);
+ int (*encode) (xlator_t *, changelog_log_data_t *);
};
-struct changelog_ops {
- /* changelog open */
- int (*open) (xlator_t *, changelog_priv_t *,
- void *, char *, gf_boolean_t);
-
- /* changelog close */
- int (*close) (xlator_t *, changelog_priv_t *, void *);
-
- /* changelog rollover */
- int (*rollover) (xlator_t *,
- changelog_priv_t *,
- void *, char *, gf_boolean_t);
-
- int (*sync) (xlator_t *, changelog_priv_t *, void *);
-
- /* changelog write */
- int (*write) (xlator_t *,
- changelog_priv_t *, void *,
- changelog_local_t *, changelog_log_type);
-
- /* changelog read */
- int (*read) (xlator_t *,
- changelog_priv_t *, void *, char *);
-
- int (*unlink) (xlator_t *,
- changelog_priv_t *, void *, char *);
-
- /* {get|set} offset */
- off_t (*get_offset) (xlator_t *this,
- changelog_priv_t *, void *, changelog_local_t *);
-
- void (*set_offset) (xlator_t *this,
- changelog_priv_t *, void *,
- changelog_local_t *, off_t);
-
- void (*reset_offset) (xlator_t *this, changelog_priv_t *,
- void *, changelog_local_t *);
-};
-
-/**
- * This structure is _filled_ by the policy init (@init_policy) routine.
- * Default @fops and @cops are passed to the init routine, which can
- * choose to override the file operation or changelog operation behaviour.
- * Just by _replacing_ the function pointers, a policy can change it's
- * file and changelog operation behaviour. Kind of inheritance...
- */
-struct changelog_logpolicy {
- /* current changelog name */
- char changelog_name[PATH_MAX];
-
- /* private data */
- void *cpriv;
-
- /* file ops for the policy */
- struct xlator_fops *fops;
-
- /* changelog operations for the policy */
- struct changelog_ops *cops;
-
- /* current active policy */
- changelog_log_policy_t policy;
-
- int (*init_policy) (xlator_t *,
- changelog_priv_t *priv,
- struct changelog_logpolicy *);
- int (*fini_policy) (xlator_t *, struct changelog_logpolicy *);
-};
-
-#define CHANGELOG_FNAME_FROM_POLICY(c) c->changelog_name
-
-#define CHANGELOG_INVOKE_FOP(priv,fop,...) priv->cp->fops->fop (__VA_ARGS__)
-
-#define CHANGELOG_INVOKE_CFOP(this,priv,fop,...) \
- priv->cp->cops->fop (this, priv, priv->cp->cpriv, ##__VA_ARGS__)
/* xlator private */
@@ -263,11 +142,6 @@ typedef struct changelog_notify {
struct changelog_priv {
gf_boolean_t active;
- /**
- * write the record header?
- */
- gf_boolean_t no_gfid_hdr;
-
/* to generate unique socket file per brick */
char *changelog_brick;
@@ -317,44 +191,25 @@ struct changelog_priv {
/* encoder */
struct changelog_encoder *ce;
-
- /* logging policy */
- changelog_log_policy_t policy;
-
- /* policy logger */
- struct changelog_logpolicy *cp;
-
- /* current NSR term */
- uint32_t term;
};
struct changelog_local {
inode_t *inode;
-
- /**
- * fops that do not need inode version checks
- */
gf_boolean_t update_no_check;
- /**
- * the log data entry
- */
changelog_log_data_t cld;
/**
- * number of bytes written: used for continuation
- */
- off_t nr_bytes;
-
- /**
- * temporary scratch pads
+ * ->prev_entry is used in cases when there needs to be
+ * additional changelog entry for the parent (eg. rename)
+ * It's analogous to ->next in single linked list world,
+ * but we call it as ->prev_entry... ha ha ha
*/
- union {
- void *ptr;
- unsigned long val;
- } lu;
+ struct changelog_local *prev_entry;
};
+typedef struct changelog_local changelog_local_t;
+
/* inode version is stored in inode ctx */
typedef struct changelog_inode_ctx {
unsigned long iversion[CHANGELOG_MAX_TYPE];
@@ -369,9 +224,8 @@ typedef struct changelog_inode_ctx {
*/
typedef enum {
CHANGELOG_OPT_REC_FOP,
- CHANGELOG_OPT_REC_ULL,
- CHANGELOG_OPT_REC_UUID,
CHANGELOG_OPT_REC_ENTRY,
+ CHANGELOG_OPT_REC_UINT32,
} changelog_optional_rec_type_t;
struct changelog_entry_fields {
@@ -400,9 +254,8 @@ typedef struct {
size_t co_len;
union {
- uuid_t co_uuid;
+ unsigned int co_uint32;
glusterfs_fop_t co_fop;
- unsigned long long co_number;
struct changelog_entry_fields co_entry;
};
} changelog_opt_t;
@@ -426,26 +279,29 @@ changelog_local_t *
changelog_local_init (xlator_t *this, inode_t *inode, uuid_t gfid,
int xtra_records, gf_boolean_t update_flag);
int
+changelog_start_next_change (xlator_t *this,
+ changelog_priv_t *priv,
+ unsigned long ts, gf_boolean_t finale);
+int
+changelog_open (xlator_t *this, changelog_priv_t *priv);
+int
+changelog_fill_rollover_data (changelog_log_data_t *cld, gf_boolean_t is_last);
+int
changelog_inject_single_event (xlator_t *this,
changelog_priv_t *priv,
- changelog_local_t *local,
changelog_log_data_t *cld);
inline size_t
changelog_entry_length ();
inline int
changelog_write (int fd, char *buffer, size_t len);
int
-changelog_write_change (xlator_t *this, changelog_priv_t *priv,
- changelog_local_t *local, char *buffer, size_t len);
+changelog_write_change (changelog_priv_t *priv, char *buffer, size_t len);
inline int
changelog_handle_change (xlator_t *this,
- changelog_priv_t *priv,
- changelog_local_t *local, changelog_log_data_t *cld);
+ changelog_priv_t *priv, changelog_log_data_t *cld);
inline void
-changelog_update (xlator_t *this,
- changelog_priv_t *priv,
- changelog_local_t *local,
- changelog_log_type type);
+changelog_update (xlator_t *this, changelog_priv_t *priv,
+ changelog_local_t *local, changelog_log_type type);
void *
changelog_rollover (void *data);
void *
@@ -465,6 +321,9 @@ changelog_forget (xlator_t *this, inode_t *inode);
} \
STACK_UNWIND_STRICT (fop, frame, params); \
changelog_local_cleanup (__xl, __local); \
+ if (__local && __local->prev_entry) \
+ changelog_local_cleanup (__xl, \
+ __local->prev_entry); \
} while (0)
#define CHANGELOG_IOBUF_REF(iobuf) do { \
@@ -489,12 +348,20 @@ changelog_forget (xlator_t *this, inode_t *inode);
} \
} while (0)
-#define CHANGELOG_FILL_FOP_NUMBER(co, fop, converter, xlen) do { \
- co->co_convert = converter; \
- co->co_free = NULL; \
- co->co_type = CHANGELOG_OPT_REC_FOP; \
- co->co_fop = fop; \
- xlen += sizeof (fop); \
+#define CHANGELOG_FILL_UINT32(co, number, converter, xlen) do { \
+ co->co_convert = converter; \
+ co->co_free = NULL; \
+ co->co_type = CHANGELOG_OPT_REC_UINT32; \
+ co->co_uint32 = number; \
+ xlen += sizeof (unsigned int); \
+ } while (0)
+
+#define CHANGLOG_FILL_FOP_NUMBER(co, fop, converter, xlen) do { \
+ co->co_convert = converter; \
+ co->co_free = NULL; \
+ co->co_type = CHANGELOG_OPT_REC_FOP; \
+ co->co_fop = fop; \
+ xlen += sizeof (fop); \
} while (0)
#define CHANGELOG_FILL_ENTRY(co, pargfid, bname, \
@@ -535,7 +402,4 @@ changelog_forget (xlator_t *this, inode_t *inode);
goto label; \
} while (0)
-int
-changelog_open (xlator_t *this, changelog_priv_t *priv, changelog_local_t *local, changelog_rollover_data_t *crd);
-
#endif /* _CHANGELOG_HELPERS_H */
diff --git a/xlators/features/changelog/src/changelog-mem-types.h b/xlators/features/changelog/src/changelog-mem-types.h
index a65bbb4f2..d72464eab 100644
--- a/xlators/features/changelog/src/changelog-mem-types.h
+++ b/xlators/features/changelog/src/changelog-mem-types.h
@@ -19,11 +19,10 @@ enum gf_changelog_mem_types {
gf_changelog_mt_batch_t = gf_common_mt_end + 3,
gf_changelog_mt_rt_t = gf_common_mt_end + 4,
gf_changelog_mt_inode_ctx_t = gf_common_mt_end + 5,
- gf_changelog_mt_fop_policy_t = gf_common_mt_end + 6,
- gf_changelog_mt_libgfchangelog_t = gf_common_mt_end + 7,
- gf_changelog_mt_libgfchangelog_rl_t = gf_common_mt_end + 8,
- gf_changelog_mt_libgfchangelog_dirent_t = gf_common_mt_end + 9,
- gf_changelog_mt_changelog_buffer_t = gf_common_mt_end + 10,
+ gf_changelog_mt_libgfchangelog_t = gf_common_mt_end + 6,
+ gf_changelog_mt_libgfchangelog_rl_t = gf_common_mt_end + 7,
+ gf_changelog_mt_libgfchangelog_dirent_t = gf_common_mt_end + 8,
+ gf_changelog_mt_changelog_buffer_t = gf_common_mt_end + 9,
gf_changelog_mt_end
};
diff --git a/xlators/features/changelog/src/changelog-misc.h b/xlators/features/changelog/src/changelog-misc.h
index 58bd3279d..127b03e2e 100644
--- a/xlators/features/changelog/src/changelog-misc.h
+++ b/xlators/features/changelog/src/changelog-misc.h
@@ -18,7 +18,7 @@
#define CHANGELOG_FILE_NAME "CHANGELOG"
#define CHANGELOG_VERSION_MAJOR 1
-#define CHANGELOG_VERSION_MINOR 0
+#define CHANGELOG_VERSION_MINOR 1
#define CHANGELOG_UNIX_SOCK DEFAULT_VAR_RUN_DIRECTORY"/changelog-%s.sock"
@@ -65,7 +65,7 @@
} while (0)
/**
- * everything after @CHANGELOG_TYPE_ENTRY are internal types
+ * everything after 'CHANGELOG_TYPE_ENTRY' are internal types
* (ie. none of the fops trigger this type of event), hence
* CHANGELOG_MAX_TYPE = 3
*/
@@ -91,12 +91,6 @@ typedef enum {
CHANGELOG_ENCODE_MAX,
} changelog_encoder_t;
-/* logging policies */
-typedef enum {
- CHANGELOG_LOG_POLICY_DEFAULT = 0,
- CHANGELOG_LOG_POLICY_REPLICATE,
-} changelog_log_policy_t;
-
#define CHANGELOG_VALID_ENCODING(enc) \
(enc > CHANGELOG_ENCODE_MIN && enc < CHANGELOG_ENCODE_MAX)
diff --git a/xlators/features/changelog/src/changelog-rt.c b/xlators/features/changelog/src/changelog-rt.c
index 4e801ae85..c147f68ca 100644
--- a/xlators/features/changelog/src/changelog-rt.c
+++ b/xlators/features/changelog/src/changelog-rt.c
@@ -52,9 +52,8 @@ changelog_rt_fini (xlator_t *this, changelog_dispatcher_t *cd)
}
int
-changelog_rt_enqueue (xlator_t *this,
- changelog_priv_t *priv, void *cbatch,
- changelog_local_t *local, changelog_log_data_t *cld_0)
+changelog_rt_enqueue (xlator_t *this, changelog_priv_t *priv, void *cbatch,
+ changelog_log_data_t *cld_0, changelog_log_data_t *cld_1)
{
int ret = 0;
changelog_rt_t *crt = NULL;
@@ -63,7 +62,9 @@ changelog_rt_enqueue (xlator_t *this,
LOCK (&crt->lock);
{
- ret = changelog_handle_change (this, priv, local, cld_0);
+ ret = changelog_handle_change (this, priv, cld_0);
+ if (!ret && cld_1)
+ ret = changelog_handle_change (this, priv, cld_1);
}
UNLOCK (&crt->lock);
diff --git a/xlators/features/changelog/src/changelog-rt.h b/xlators/features/changelog/src/changelog-rt.h
index 09398041d..1fc2bbc5b 100644
--- a/xlators/features/changelog/src/changelog-rt.h
+++ b/xlators/features/changelog/src/changelog-rt.h
@@ -27,8 +27,7 @@ changelog_rt_init (xlator_t *this, changelog_dispatcher_t *cd);
int
changelog_rt_fini (xlator_t *this, changelog_dispatcher_t *cd);
int
-changelog_rt_enqueue (xlator_t *this,
- changelog_priv_t *priv, void *cbatch,
- changelog_local_t *local, changelog_log_data_t *cld_0);
+changelog_rt_enqueue (xlator_t *this, changelog_priv_t *priv, void *cbatch,
+ changelog_log_data_t *cld_0, changelog_log_data_t *cld_1);
#endif /* _CHANGELOG_RT_H */
diff --git a/xlators/features/changelog/src/changelog.c b/xlators/features/changelog/src/changelog.c
index 2e01161a9..5fe3b4362 100644
--- a/xlators/features/changelog/src/changelog.c
+++ b/xlators/features/changelog/src/changelog.c
@@ -17,15 +17,15 @@
#include "defaults.h"
#include "logging.h"
#include "iobuf.h"
-#include <pthread.h>
#include "changelog-rt.h"
-#include "changelog-notifier.h"
+
#include "changelog-encoders.h"
#include "changelog-mem-types.h"
-#include "changelog-fops.h"
-#include "changelog-policy.h"
+#include <pthread.h>
+
+#include "changelog-notifier.h"
static struct changelog_bootstrap
cb_bootstrap[] = {
@@ -36,42 +36,12 @@ cb_bootstrap[] = {
},
};
-static struct changelog_encoder
-cb_encoder[] = {
- [CHANGELOG_ENCODE_BINARY] =
- {
- .encoder = CHANGELOG_ENCODE_BINARY,
- .encode = changelog_encode_binary,
- },
- [CHANGELOG_ENCODE_ASCII] =
- {
- .encoder = CHANGELOG_ENCODE_ASCII,
- .encode = changelog_encode_ascii,
- },
-};
-
-static struct changelog_logpolicy
-cb_policy[] = {
- [CHANGELOG_LOG_POLICY_DEFAULT] =
- {
- .fops = NULL,
- .cops = NULL,
- .policy = CHANGELOG_LOG_POLICY_DEFAULT,
- .init_policy = changelog_default_policy_init,
- .fini_policy = changelog_default_policy_fini,
- },
- [CHANGELOG_LOG_POLICY_REPLICATE] =
- {
- .fops = NULL,
- .cops = NULL,
- .policy = CHANGELOG_LOG_POLICY_REPLICATE,
- .init_policy = changelog_replication_policy_init,
- .fini_policy = changelog_replication_policy_fini,
- },
-};
-
/* Entry operations - TYPE III */
+/**
+ * entry operations do not undergo inode version checking.
+ */
+
/* {{{ */
/* rmdir */
@@ -89,8 +59,7 @@ changelog_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
unwind:
CHANGELOG_STACK_UNWIND (rmdir, frame, op_ret, op_errno,
@@ -102,12 +71,27 @@ int32_t
changelog_rmdir (call_frame_t *frame, xlator_t *this,
loc_t *loc, int xflags, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, rmdir, frame, this, loc, xflags, xdata);
+ CHANGELOG_INIT_NOCHECK (this, frame->local,
+ NULL, loc->inode->gfid, 2);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+
+ co++;
+ CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
+ entry_fn, entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 2);
wind:
STACK_WIND (frame, changelog_rmdir_cbk,
@@ -131,8 +115,7 @@ changelog_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
unwind:
CHANGELOG_STACK_UNWIND (unlink, frame, op_ret, op_errno,
@@ -144,13 +127,27 @@ int32_t
changelog_unlink (call_frame_t *frame, xlator_t *this,
loc_t *loc, int xflags, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (xdata, wind);
- CHANGELOG_INVOKE_FOP (priv, unlink, frame, this, loc, xflags, xdata);
+ CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, loc->inode->gfid, 2);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+
+ co++;
+ CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
+ entry_fn, entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 2);
wind:
STACK_WIND (frame, changelog_unlink_cbk,
@@ -177,8 +174,7 @@ changelog_rename_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
unwind:
CHANGELOG_STACK_UNWIND (rename, frame, op_ret, op_errno,
@@ -192,12 +188,32 @@ int32_t
changelog_rename (call_frame_t *frame, xlator_t *this,
loc_t *oldloc, loc_t *newloc, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, rename, frame, this, oldloc, newloc, xdata);
+ /* 3 == fop + oldloc + newloc */
+ CHANGELOG_INIT_NOCHECK (this, frame->local,
+ NULL, oldloc->inode->gfid, 3);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+
+ co++;
+ CHANGELOG_FILL_ENTRY (co, oldloc->pargfid, oldloc->name,
+ entry_fn, entry_free_fn, xtra_len, wind);
+
+ co++;
+ CHANGELOG_FILL_ENTRY (co, newloc->pargfid, newloc->name,
+ entry_fn, entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 3);
wind:
STACK_WIND (frame, changelog_rename_cbk,
@@ -223,8 +239,7 @@ changelog_link_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
unwind:
CHANGELOG_STACK_UNWIND (link, frame, op_ret, op_errno,
@@ -237,14 +252,28 @@ changelog_link (call_frame_t *frame,
xlator_t *this, loc_t *oldloc,
loc_t *newloc, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (xdata, wind);
- CHANGELOG_INVOKE_FOP (priv, link, frame, this, oldloc, newloc, xdata);
+ CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, oldloc->gfid, 2);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+
+ co++;
+ CHANGELOG_FILL_ENTRY (co, newloc->pargfid, newloc->name,
+ entry_fn, entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 2);
wind:
STACK_WIND (frame, changelog_link_cbk,
@@ -270,8 +299,7 @@ changelog_mkdir_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
unwind:
CHANGELOG_STACK_UNWIND (mkdir, frame, op_ret, op_errno,
@@ -283,13 +311,46 @@ int32_t
changelog_mkdir (call_frame_t *frame, xlator_t *this,
loc_t *loc, mode_t mode, mode_t umask, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ int ret = -1;
+ uuid_t gfid = {0,};
+ void *uuid_req = NULL;
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, mkdir, frame, this,
- loc, mode, umask, xdata);
+ ret = dict_get_ptr (xdata, "gfid-req", &uuid_req);
+ if (ret) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get gfid from dict");
+ goto wind;
+ }
+ uuid_copy (gfid, uuid_req);
+
+ CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, gfid, 5);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32 (co, S_IFDIR | mode, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32 (co, frame->root->uid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32 (co, frame->root->gid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
+ entry_fn, entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 5);
wind:
STACK_WIND (frame, changelog_mkdir_cbk,
@@ -315,8 +376,7 @@ changelog_symlink_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
unwind:
CHANGELOG_STACK_UNWIND (symlink, frame, op_ret, op_errno,
@@ -329,13 +389,37 @@ changelog_symlink (call_frame_t *frame, xlator_t *this,
const char *linkname, loc_t *loc,
mode_t umask, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ int ret = -1;
+ size_t xtra_len = 0;
+ uuid_t gfid = {0,};
+ void *uuid_req = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, symlink, frame, this,
- linkname, loc, umask, xdata);
+ ret = dict_get_ptr (xdata, "gfid-req", &uuid_req);
+ if (ret) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get gfid from dict");
+ goto wind;
+ }
+ uuid_copy (gfid, uuid_req);
+
+ CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, gfid, 2);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
+ entry_fn, entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 2);
wind:
STACK_WIND (frame, changelog_symlink_cbk,
@@ -361,8 +445,7 @@ changelog_mknod_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
unwind:
CHANGELOG_STACK_UNWIND (mknod, frame, op_ret, op_errno,
@@ -375,13 +458,46 @@ changelog_mknod (call_frame_t *frame,
xlator_t *this, loc_t *loc,
mode_t mode, dev_t dev, mode_t umask, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ int ret = -1;
+ uuid_t gfid = {0,};
+ void *uuid_req = NULL;
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, mknod, frame, this,
- loc, mode, dev, umask, xdata);
+ ret = dict_get_ptr (xdata, "gfid-req", &uuid_req);
+ if (ret) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get gfid from dict");
+ goto wind;
+ }
+ uuid_copy (gfid, uuid_req);
+
+ CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, gfid, 5);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32 (co, mode, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32 (co, frame->root->uid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32 (co, frame->root->gid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
+ entry_fn, entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 5);
wind:
STACK_WIND (frame, changelog_mknod_cbk,
@@ -408,8 +524,7 @@ changelog_create_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
unwind:
CHANGELOG_STACK_UNWIND (create, frame,
@@ -423,13 +538,49 @@ changelog_create (call_frame_t *frame, xlator_t *this,
loc_t *loc, int32_t flags, mode_t mode,
mode_t umask, fd_t *fd, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ int ret = -1;
+ uuid_t gfid = {0,};
+ void *uuid_req = NULL;
+ changelog_opt_t *co = NULL;
+ changelog_priv_t *priv = NULL;
+ size_t xtra_len = 0;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, create, frame, this, loc,
- flags, mode, umask, fd, xdata);
+ ret = dict_get_ptr (xdata, "gfid-req", &uuid_req);
+ if (ret) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get gfid from dict");
+ goto wind;
+ }
+ uuid_copy (gfid, uuid_req);
+
+ /* init with two extra records */
+ CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, gfid, 5);
+ if (!frame->local)
+ goto wind;
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32 (co, mode, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32 (co, frame->root->uid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32 (co, frame->root->gid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
+ entry_fn, entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 5);
wind:
STACK_WIND (frame, changelog_create_cbk,
@@ -461,8 +612,7 @@ changelog_fsetattr_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_METADATA);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA);
unwind:
CHANGELOG_STACK_UNWIND (fsetattr, frame, op_ret, op_errno,
@@ -478,13 +628,25 @@ changelog_fsetattr (call_frame_t *frame,
xlator_t *this, fd_t *fd,
struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, fsetattr,
- frame, this, fd, stbuf, valid, xdata);
+ CHANGELOG_INIT (this, frame->local,
+ fd->inode, fd->inode->gfid, 1);
+ if (!frame->local)
+ goto wind;
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
wind:
STACK_WIND (frame, changelog_fsetattr_cbk,
@@ -509,8 +671,7 @@ changelog_setattr_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_METADATA);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA);
unwind:
CHANGELOG_STACK_UNWIND (setattr, frame, op_ret, op_errno,
@@ -524,13 +685,25 @@ changelog_setattr (call_frame_t *frame,
xlator_t *this, loc_t *loc,
struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, setattr,
- frame, this, loc, stbuf, valid, xdata);
+ CHANGELOG_INIT (this, frame->local,
+ loc->inode, loc->inode->gfid, 1);
+ if (!frame->local)
+ goto wind;
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
wind:
STACK_WIND (frame, changelog_setattr_cbk,
@@ -554,8 +727,7 @@ changelog_fremovexattr_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_METADATA);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA);
unwind:
CHANGELOG_STACK_UNWIND (fremovexattr, frame, op_ret, op_errno, xdata);
@@ -567,13 +739,23 @@ int32_t
changelog_fremovexattr (call_frame_t *frame, xlator_t *this,
fd_t *fd, const char *name, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, fremovexattr,
- frame, this, fd, name, xdata);
+ CHANGELOG_INIT (this, frame->local,
+ fd->inode, fd->inode->gfid, 1);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
wind:
STACK_WIND (frame, changelog_fremovexattr_cbk,
@@ -595,8 +777,7 @@ changelog_removexattr_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_METADATA);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA);
unwind:
CHANGELOG_STACK_UNWIND (removexattr, frame, op_ret, op_errno, xdata);
@@ -608,12 +789,23 @@ int32_t
changelog_removexattr (call_frame_t *frame, xlator_t *this,
loc_t *loc, const char *name, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, removexattr, frame, this, loc, name, xdata);
+ CHANGELOG_INIT (this, frame->local,
+ loc->inode, loc->inode->gfid, 1);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
wind:
STACK_WIND (frame, changelog_removexattr_cbk,
@@ -637,8 +829,7 @@ changelog_setxattr_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_METADATA);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA);
unwind:
CHANGELOG_STACK_UNWIND (setxattr, frame, op_ret, op_errno, xdata);
@@ -651,13 +842,23 @@ changelog_setxattr (call_frame_t *frame,
xlator_t *this, loc_t *loc,
dict_t *dict, int32_t flags, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, setxattr,
- frame, this, loc, dict, flags, xdata);
+ CHANGELOG_INIT (this, frame->local,
+ loc->inode, loc->inode->gfid, 1);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
wind:
STACK_WIND (frame, changelog_setxattr_cbk,
@@ -679,8 +880,7 @@ changelog_fsetxattr_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv,
- write, local, CHANGELOG_TYPE_METADATA);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA);
unwind:
CHANGELOG_STACK_UNWIND (fsetxattr, frame, op_ret, op_errno, xdata);
@@ -693,13 +893,23 @@ changelog_fsetxattr (call_frame_t *frame,
xlator_t *this, fd_t *fd, dict_t *dict,
int32_t flags, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, fsetxattr,
- frame, this, fd, dict, flags, xdata);
+ CHANGELOG_INIT (this, frame->local,
+ fd->inode, fd->inode->gfid, 1);
+
+ co = changelog_get_usable_buffer (frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+
+ changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
wind:
STACK_WIND (frame, changelog_fsetxattr_cbk,
@@ -731,7 +941,7 @@ changelog_truncate_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv, write, local, CHANGELOG_TYPE_DATA);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_DATA);
unwind:
CHANGELOG_STACK_UNWIND (truncate, frame,
@@ -748,7 +958,8 @@ changelog_truncate (call_frame_t *frame,
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, truncate, frame, this, loc, offset, xdata);
+ CHANGELOG_INIT (this, frame->local,
+ loc->inode, loc->inode->gfid, 0);
wind:
STACK_WIND (frame, changelog_truncate_cbk,
@@ -771,7 +982,7 @@ changelog_ftruncate_cbk (call_frame_t *frame,
CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv, write, local, CHANGELOG_TYPE_DATA);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_DATA);
unwind:
CHANGELOG_STACK_UNWIND (ftruncate, frame,
@@ -788,7 +999,8 @@ changelog_ftruncate (call_frame_t *frame,
priv = this->private;
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, ftruncate, frame, this, fd, offset, xdata);
+ CHANGELOG_INIT (this, frame->local,
+ fd->inode, fd->inode->gfid, 0);
wind:
STACK_WIND (frame, changelog_ftruncate_cbk,
@@ -813,7 +1025,7 @@ changelog_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
CHANGELOG_COND_GOTO (priv, ((op_ret <= 0) || !local), unwind);
- CHANGELOG_INVOKE_CFOP (this, priv, write, local, CHANGELOG_TYPE_DATA);
+ changelog_update (this, priv, local, CHANGELOG_TYPE_DATA);
unwind:
CHANGELOG_STACK_UNWIND (writev, frame,
@@ -830,11 +1042,10 @@ changelog_writev (call_frame_t *frame,
changelog_priv_t *priv = NULL;
priv = this->private;
-
CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_INVOKE_FOP (priv, writev, frame, this, fd,
- vector, count, offset, flags, iobref, xdata);
+ CHANGELOG_INIT (this, frame->local,
+ fd->inode, fd->inode->gfid, 0);
wind:
STACK_WIND (frame, changelog_writev_cbk, FIRST_CHILD (this),
@@ -874,15 +1085,6 @@ changelog_assign_encoding (changelog_priv_t *priv, char *enc)
}
}
-static void
-changelog_assign_policy (changelog_priv_t *priv, char *pol)
-{
- if ( strncmp (pol, "default", 7) == 0 )
- priv->policy = CHANGELOG_LOG_POLICY_DEFAULT;
- else if ( strncmp (pol, "replication", 11) == 0 )
- priv->policy = CHANGELOG_LOG_POLICY_REPLICATE;
-}
-
/* cleanup any helper threads that are running */
static void
changelog_cleanup_helper_threads (xlator_t *this, changelog_priv_t *priv)
@@ -905,17 +1107,15 @@ changelog_spawn_helper_threads (xlator_t *this, changelog_priv_t *priv)
int ret = 0;
priv->cr.this = this;
- if (priv->rollover_time) {
- ret = pthread_create (&priv->cr.rollover_th,
- NULL, changelog_rollover, priv);
- if (ret)
- goto out;
- }
+ ret = gf_thread_create (&priv->cr.rollover_th,
+ NULL, changelog_rollover, priv);
+ if (ret)
+ goto out;
if (priv->fsync_interval) {
priv->cf.this = this;
- ret = pthread_create (&priv->cf.fsync_th,
- NULL, changelog_fsync_thread, priv);
+ ret = gf_thread_create (&priv->cf.fsync_th,
+ NULL, changelog_fsync_thread, priv);
}
if (ret)
@@ -979,8 +1179,8 @@ changelog_spawn_notifier (xlator_t *this, changelog_priv_t *priv)
priv->cn.this = this;
priv->cn.rfd = pipe_fd[0];
- ret = pthread_create (&priv->cn.notify_th,
- NULL, changelog_notifier, priv);
+ ret = gf_thread_create (&priv->cn.notify_th,
+ NULL, changelog_notifier, priv);
out:
return ret;
@@ -1008,10 +1208,10 @@ mem_acct_init (xlator_t *this)
static int
changelog_init (xlator_t *this, changelog_priv_t *priv)
{
- int i = 0;
- int ret = -1;
- char *cname = NULL;
- struct timeval tv = {0,};
+ int i = 0;
+ int ret = -1;
+ struct timeval tv = {0,};
+ changelog_log_data_t cld = {0,};
ret = gettimeofday (&tv, NULL);
if (ret) {
@@ -1039,18 +1239,21 @@ changelog_init (xlator_t *this, changelog_priv_t *priv)
if (ret)
goto out;
- cname = CHANGELOG_FNAME_FROM_POLICY (priv->cp);
+ /**
+ * start with a fresh changelog file every time. this is done
+ * in case there was an encoding change. so... things are kept
+ * simple here.
+ */
+ ret = changelog_fill_rollover_data (&cld, _gf_false);
+ if (ret)
+ goto out;
LOCK (&priv->lock);
{
- ret = CHANGELOG_INVOKE_CFOP (this, priv,
- open, cname, _gf_false);
+ ret = changelog_inject_single_event (this, priv, &cld);
}
UNLOCK (&priv->lock);
- if (ret)
- goto out;
-
/* ... and finally spawn the helpers threads */
ret = changelog_spawn_helper_threads (this, priv);
@@ -1063,11 +1266,11 @@ reconfigure (xlator_t *this, dict_t *options)
{
int ret = 0;
char *tmp = NULL;
- char *cname = NULL;
changelog_priv_t *priv = NULL;
gf_boolean_t active_earlier = _gf_true;
gf_boolean_t active_now = _gf_true;
changelog_time_slice_t *slice = NULL;
+ changelog_log_data_t cld = {0,};
priv = this->private;
if (!priv)
@@ -1118,13 +1321,15 @@ reconfigure (xlator_t *this, dict_t *options)
priv->fsync_interval, options, int32, out);
if (active_now || active_earlier) {
+ ret = changelog_fill_rollover_data (&cld, !active_now);
+ if (ret)
+ goto out;
+
slice = &priv->slice;
- cname = CHANGELOG_FNAME_FROM_POLICY (priv->cp);
LOCK (&priv->lock);
{
- ret = CHANGELOG_INVOKE_CFOP (this, priv, rollover,
- cname, !active_now);
+ ret = changelog_inject_single_event (this, priv, &cld);
if (!ret && active_now)
SLICE_VERSION_UPDATE (slice);
}
@@ -1231,43 +1436,20 @@ init (xlator_t *this)
GF_OPTION_INIT ("encoding", tmp, str, out);
changelog_assign_encoding (priv, tmp);
- tmp = NULL;
-
- GF_OPTION_INIT ("policy", tmp, str, out);
- changelog_assign_policy (priv, tmp);
+ GF_OPTION_INIT ("rollover-time", priv->rollover_time, int32, out);
GF_OPTION_INIT ("fsync-interval", priv->fsync_interval, int32, out);
- GF_ASSERT (cb_encoder[priv->encode_mode].encoder == priv->encode_mode);
- priv->ce = &cb_encoder[priv->encode_mode];
+ changelog_encode_change(priv);
GF_ASSERT (cb_bootstrap[priv->op_mode].mode == priv->op_mode);
priv->cb = &cb_bootstrap[priv->op_mode];
- GF_ASSERT (cb_policy[priv->policy].policy == priv->policy);
- priv->cp = &cb_policy[priv->policy];
-
/* ... now bootstrap the logger */
ret = priv->cb->ctor (this, &priv->cd);
if (ret)
goto out;
- /* ... init logging policy */
- ret = priv->cp->init_policy (this, priv, priv->cp);
- if (ret)
- goto out;
-
- /* override the value if set */
- if (dict_get (this->options, "rollover-time")) {
- ret = dict_get_int32 (this->options,
- "rollover-time", &priv->rollover_time);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "Cannot get value for \"rollover-time\"");
- goto out;
- }
- }
-
priv->changelog_fd = -1;
ret = changelog_init (this, priv);
if (ret)
@@ -1346,7 +1528,7 @@ struct xlator_cbks cbks = {
struct volume_options options[] = {
{.key = {"changelog"},
.type = GF_OPTION_TYPE_BOOL,
- .default_value = "on",
+ .default_value = "off",
.description = "enable/disable change-logging"
},
{.key = {"changelog-brick"},
@@ -1371,7 +1553,8 @@ struct volume_options options[] = {
.description = "encoding type for changelogs"
},
{.key = {"rollover-time"},
- .type = GF_OPTION_TYPE_INT,
+ .default_value = "60",
+ .type = GF_OPTION_TYPE_TIME,
.description = "time to switch to a new changelog file (in seconds)"
},
{.key = {"fsync-interval"},
@@ -1380,12 +1563,6 @@ struct volume_options options[] = {
.description = "do not open CHANGELOG file with O_SYNC mode."
" instead perform fsync() at specified intervals"
},
- {.key = {"policy"},
- .type = GF_OPTION_TYPE_STR,
- .default_value = "replication",
- .value = {"default", "replication"},
- .description = "Logging policies"
- },
{.key = {NULL}
},
};