summaryrefslogtreecommitdiffstats
path: root/xlators/features/changelog/src/changelog.c
diff options
context:
space:
mode:
authorJeff Darcy <jdarcy@redhat.com>2014-01-14 16:59:00 +0000
committerJeff Darcy <jdarcy@redhat.com>2014-01-14 16:59:00 +0000
commit92eaa72ea4cd0d06c2161842c548008db0eee01c (patch)
tree441658ad7f69a2a3deb404e43a7ff8e2d50e101a /xlators/features/changelog/src/changelog.c
parente0cce4cf7c22d5cd8ab6c2aff4ecf28c18c6a469 (diff)
Temporarily revert NSR-specific changelog patches.
This is necessary so that patches from upstream can merge cleanly. Otherwise there are some nasty conflicts, and resolving them by hand gets even uglier than this approach. Change-Id: I4235f8ba0ad63563c2e7dec1a1e8eeb636657574 Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'xlators/features/changelog/src/changelog.c')
-rw-r--r--xlators/features/changelog/src/changelog.c531
1 files changed, 354 insertions, 177 deletions
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}
},
};