diff options
author | Gluster Ant <bugzilla-bot@gluster.org> | 2018-09-12 17:52:45 +0530 |
---|---|---|
committer | Nigel Babu <nigelb@redhat.com> | 2018-09-12 17:52:45 +0530 |
commit | e16868dede6455cab644805af6fe1ac312775e13 (patch) | |
tree | 15aebdb4fff2d87cf8a72f836816b3aa634da58d /xlators/features/changelog/src | |
parent | 45a71c0548b6fd2c757aa2e7b7671a1411948894 (diff) |
Land part 2 of clang-format changes
Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4
Signed-off-by: Nigel Babu <nigelb@redhat.com>
Diffstat (limited to 'xlators/features/changelog/src')
-rw-r--r-- | xlators/features/changelog/src/changelog-barrier.c | 140 | ||||
-rw-r--r-- | xlators/features/changelog/src/changelog-encoders.c | 298 | ||||
-rw-r--r-- | xlators/features/changelog/src/changelog-ev-handle.c | 570 | ||||
-rw-r--r-- | xlators/features/changelog/src/changelog-helpers.c | 2987 | ||||
-rw-r--r-- | xlators/features/changelog/src/changelog-rpc-common.c | 525 | ||||
-rw-r--r-- | xlators/features/changelog/src/changelog-rpc.c | 548 | ||||
-rw-r--r-- | xlators/features/changelog/src/changelog-rt.c | 57 | ||||
-rw-r--r-- | xlators/features/changelog/src/changelog.c | 4631 |
8 files changed, 4765 insertions, 4991 deletions
diff --git a/xlators/features/changelog/src/changelog-barrier.c b/xlators/features/changelog/src/changelog-barrier.c index ac1eb0e4397..e8d742404df 100644 --- a/xlators/features/changelog/src/changelog-barrier.c +++ b/xlators/features/changelog/src/changelog-barrier.c @@ -14,121 +14,119 @@ /* Enqueue a stub*/ void -__chlog_barrier_enqueue (xlator_t *this, call_stub_t *stub) +__chlog_barrier_enqueue(xlator_t *this, call_stub_t *stub) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; - GF_ASSERT (priv); + priv = this->private; + GF_ASSERT(priv); - list_add_tail (&stub->list, &priv->queue); - priv->queue_size++; + list_add_tail(&stub->list, &priv->queue); + priv->queue_size++; - return; + return; } /* Dequeue a stub */ call_stub_t * -__chlog_barrier_dequeue (xlator_t *this, struct list_head *queue) +__chlog_barrier_dequeue(xlator_t *this, struct list_head *queue) { - call_stub_t *stub = NULL; - changelog_priv_t *priv = NULL; + call_stub_t *stub = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; - GF_ASSERT (priv); + priv = this->private; + GF_ASSERT(priv); - if (list_empty (queue)) - goto out; + if (list_empty(queue)) + goto out; - stub = list_entry (queue->next, call_stub_t, list); - list_del_init (&stub->list); + stub = list_entry(queue->next, call_stub_t, list); + list_del_init(&stub->list); out: - return stub; + return stub; } /* Dequeue all the stubs and call corresponding resume functions */ void -chlog_barrier_dequeue_all (xlator_t *this, struct list_head *queue) +chlog_barrier_dequeue_all(xlator_t *this, struct list_head *queue) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BARRIER_INFO, - "Dequeuing all the changelog barriered fops"); + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO, + "Dequeuing all the changelog barriered fops"); - while ((stub = __chlog_barrier_dequeue (this, queue))) - call_resume (stub); + while ((stub = __chlog_barrier_dequeue(this, queue))) + call_resume(stub); - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BARRIER_INFO, - "Dequeuing changelog barriered fops is finished"); - return; + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO, + "Dequeuing changelog barriered fops is finished"); + return; } /* Function called on changelog barrier timeout */ void -chlog_barrier_timeout (void *data) +chlog_barrier_timeout(void *data) { - xlator_t *this = NULL; - changelog_priv_t *priv = NULL; - struct list_head queue = {0,}; + xlator_t *this = NULL; + changelog_priv_t *priv = NULL; + struct list_head queue = { + 0, + }; - this = data; - THIS = this; - priv = this->private; + this = data; + THIS = this; + priv = this->private; - INIT_LIST_HEAD (&queue); + INIT_LIST_HEAD(&queue); - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_BARRIER_ERROR, - "Disabling changelog barrier because of the timeout."); + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_BARRIER_ERROR, + "Disabling changelog barrier because of the timeout."); - LOCK (&priv->lock); - { - __chlog_barrier_disable (this, &queue); - } - UNLOCK (&priv->lock); + LOCK(&priv->lock); + { + __chlog_barrier_disable(this, &queue); + } + UNLOCK(&priv->lock); - chlog_barrier_dequeue_all (this, &queue); + chlog_barrier_dequeue_all(this, &queue); - return; + return; } /* Disable changelog barrier enable flag */ void -__chlog_barrier_disable (xlator_t *this, struct list_head *queue) +__chlog_barrier_disable(xlator_t *this, struct list_head *queue) { - changelog_priv_t *priv = this->private; - GF_ASSERT (priv); + changelog_priv_t *priv = this->private; + GF_ASSERT(priv); - if (priv->timer) { - gf_timer_call_cancel (this->ctx, priv->timer); - priv->timer = NULL; - } + if (priv->timer) { + gf_timer_call_cancel(this->ctx, priv->timer); + priv->timer = NULL; + } - list_splice_init (&priv->queue, queue); - priv->queue_size = 0; - priv->barrier_enabled = _gf_false; + list_splice_init(&priv->queue, queue); + priv->queue_size = 0; + priv->barrier_enabled = _gf_false; } /* Enable chagelog barrier enable with timer */ int -__chlog_barrier_enable (xlator_t *this, changelog_priv_t *priv) +__chlog_barrier_enable(xlator_t *this, changelog_priv_t *priv) { - int ret = -1; - - priv->timer = gf_timer_call_after (this->ctx, priv->timeout, - chlog_barrier_timeout, (void *)this); - if (!priv->timer) { - gf_msg (this->name, GF_LOG_CRITICAL, 0, - CHANGELOG_MSG_BARRIER_ERROR, - "Couldn't add changelog barrier timeout event."); - goto out; - } - - priv->barrier_enabled = _gf_true; - ret = 0; + int ret = -1; + + priv->timer = gf_timer_call_after(this->ctx, priv->timeout, + chlog_barrier_timeout, (void *)this); + if (!priv->timer) { + gf_msg(this->name, GF_LOG_CRITICAL, 0, CHANGELOG_MSG_BARRIER_ERROR, + "Couldn't add changelog barrier timeout event."); + goto out; + } + + priv->barrier_enabled = _gf_true; + ret = 0; out: - return ret; + return ret; } diff --git a/xlators/features/changelog/src/changelog-encoders.c b/xlators/features/changelog/src/changelog-encoders.c index 95030236636..63754516c2e 100644 --- a/xlators/features/changelog/src/changelog-encoders.c +++ b/xlators/features/changelog/src/changelog-encoders.c @@ -11,117 +11,117 @@ #include "changelog-encoders.h" size_t -entry_fn (void *data, char *buffer, gf_boolean_t encode) +entry_fn(void *data, char *buffer, gf_boolean_t encode) { - char *tmpbuf = NULL; - size_t bufsz = 0; - struct changelog_entry_fields *ce = NULL; - - ce = (struct changelog_entry_fields *) data; - - if (encode) { - tmpbuf = uuid_utoa (ce->cef_uuid); - CHANGELOG_FILL_BUFFER (buffer, bufsz, tmpbuf, strlen (tmpbuf)); - } else { - CHANGELOG_FILL_BUFFER (buffer, bufsz, - ce->cef_uuid, sizeof (uuid_t)); - } - - CHANGELOG_FILL_BUFFER (buffer, bufsz, "/", 1); - CHANGELOG_FILL_BUFFER (buffer, bufsz, - ce->cef_bname, strlen (ce->cef_bname)); - return bufsz; + char *tmpbuf = NULL; + size_t bufsz = 0; + struct changelog_entry_fields *ce = NULL; + + ce = (struct changelog_entry_fields *)data; + + if (encode) { + tmpbuf = uuid_utoa(ce->cef_uuid); + CHANGELOG_FILL_BUFFER(buffer, bufsz, tmpbuf, strlen(tmpbuf)); + } else { + CHANGELOG_FILL_BUFFER(buffer, bufsz, ce->cef_uuid, sizeof(uuid_t)); + } + + CHANGELOG_FILL_BUFFER(buffer, bufsz, "/", 1); + CHANGELOG_FILL_BUFFER(buffer, bufsz, ce->cef_bname, strlen(ce->cef_bname)); + return bufsz; } size_t -del_entry_fn (void *data, char *buffer, gf_boolean_t encode) +del_entry_fn(void *data, char *buffer, gf_boolean_t encode) { - char *tmpbuf = NULL; - size_t bufsz = 0; - struct changelog_entry_fields *ce = NULL; - - ce = (struct changelog_entry_fields *) data; - - if (encode) { - tmpbuf = uuid_utoa (ce->cef_uuid); - CHANGELOG_FILL_BUFFER (buffer, bufsz, tmpbuf, strlen (tmpbuf)); - } else { - CHANGELOG_FILL_BUFFER (buffer, bufsz, - ce->cef_uuid, sizeof (uuid_t)); - } - - CHANGELOG_FILL_BUFFER (buffer, bufsz, "/", 1); - CHANGELOG_FILL_BUFFER (buffer, bufsz, - ce->cef_bname, strlen (ce->cef_bname)); - CHANGELOG_FILL_BUFFER (buffer, bufsz, "\0", 1); - - if (ce->cef_path[0] == '\0') { - CHANGELOG_FILL_BUFFER (buffer, bufsz, "\0", 1); - } else { - CHANGELOG_FILL_BUFFER (buffer, bufsz, - ce->cef_path, strlen (ce->cef_path)); - } - - return bufsz; + char *tmpbuf = NULL; + size_t bufsz = 0; + struct changelog_entry_fields *ce = NULL; + + ce = (struct changelog_entry_fields *)data; + + if (encode) { + tmpbuf = uuid_utoa(ce->cef_uuid); + CHANGELOG_FILL_BUFFER(buffer, bufsz, tmpbuf, strlen(tmpbuf)); + } else { + CHANGELOG_FILL_BUFFER(buffer, bufsz, ce->cef_uuid, sizeof(uuid_t)); + } + + CHANGELOG_FILL_BUFFER(buffer, bufsz, "/", 1); + CHANGELOG_FILL_BUFFER(buffer, bufsz, ce->cef_bname, strlen(ce->cef_bname)); + CHANGELOG_FILL_BUFFER(buffer, bufsz, "\0", 1); + + if (ce->cef_path[0] == '\0') { + CHANGELOG_FILL_BUFFER(buffer, bufsz, "\0", 1); + } else { + CHANGELOG_FILL_BUFFER(buffer, bufsz, ce->cef_path, + strlen(ce->cef_path)); + } + + return bufsz; } size_t -fop_fn (void *data, char *buffer, gf_boolean_t encode) +fop_fn(void *data, char *buffer, gf_boolean_t encode) { - char buf[10] = {0,}; - size_t bufsz = 0; - glusterfs_fop_t fop = 0; + char buf[10] = { + 0, + }; + size_t bufsz = 0; + glusterfs_fop_t fop = 0; - fop = *(glusterfs_fop_t *) data; + fop = *(glusterfs_fop_t *)data; - if (encode) { - (void) snprintf (buf, sizeof (buf), "%d", fop); - CHANGELOG_FILL_BUFFER (buffer, bufsz, buf, strlen (buf)); - } else - CHANGELOG_FILL_BUFFER (buffer, bufsz, &fop, sizeof (fop)); + if (encode) { + (void)snprintf(buf, sizeof(buf), "%d", fop); + CHANGELOG_FILL_BUFFER(buffer, bufsz, buf, strlen(buf)); + } else + CHANGELOG_FILL_BUFFER(buffer, bufsz, &fop, sizeof(fop)); - return bufsz; + return bufsz; } size_t -number_fn (void *data, char *buffer, gf_boolean_t encode) +number_fn(void *data, char *buffer, gf_boolean_t encode) { - size_t bufsz = 0; - unsigned int nr = 0; - char buf[20] = {0,}; + size_t bufsz = 0; + unsigned int nr = 0; + char buf[20] = { + 0, + }; - nr = *(unsigned int *) data; + 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)); + 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; + return bufsz; } void -entry_free_fn (void *data) +entry_free_fn(void *data) { - changelog_opt_t *co = data; + changelog_opt_t *co = data; - if (!co) - return; + if (!co) + return; - GF_FREE (co->co_entry.cef_bname); + GF_FREE(co->co_entry.cef_bname); } void -del_entry_free_fn (void *data) +del_entry_free_fn(void *data) { - changelog_opt_t *co = data; + changelog_opt_t *co = data; - if (!co) - return; + if (!co) + return; - GF_FREE (co->co_entry.cef_bname); - GF_FREE (co->co_entry.cef_path); + GF_FREE(co->co_entry.cef_bname); + GF_FREE(co->co_entry.cef_path); } /** @@ -129,108 +129,104 @@ del_entry_free_fn (void *data) */ static void -changelog_encode_write_xtra (changelog_log_data_t *cld, - char *buffer, size_t *off, gf_boolean_t encode) +changelog_encode_write_xtra(changelog_log_data_t *cld, char *buffer, + size_t *off, gf_boolean_t encode) { - int i = 0; - size_t offset = 0; - void *data = NULL; - changelog_opt_t *co = NULL; - - offset = *off; - - co = (changelog_opt_t *) cld->cld_ptr; - - for (; i < cld->cld_xtra_records; i++, co++) { - CHANGELOG_FILL_BUFFER (buffer, offset, "\0", 1); - - switch (co->co_type) { - case CHANGELOG_OPT_REC_FOP: - data = &co->co_fop; - break; - case CHANGELOG_OPT_REC_ENTRY: - data = &co->co_entry; - break; - case CHANGELOG_OPT_REC_UINT32: - data = &co->co_uint32; - break; - } - - if (co->co_convert) - offset += co->co_convert (data, - buffer + offset, encode); - else /* no coversion: write it out as it is */ - CHANGELOG_FILL_BUFFER (buffer, offset, - data, co->co_len); + int i = 0; + size_t offset = 0; + void *data = NULL; + changelog_opt_t *co = NULL; + + offset = *off; + + co = (changelog_opt_t *)cld->cld_ptr; + + for (; i < cld->cld_xtra_records; i++, co++) { + CHANGELOG_FILL_BUFFER(buffer, offset, "\0", 1); + + switch (co->co_type) { + case CHANGELOG_OPT_REC_FOP: + data = &co->co_fop; + break; + case CHANGELOG_OPT_REC_ENTRY: + data = &co->co_entry; + break; + case CHANGELOG_OPT_REC_UINT32: + data = &co->co_uint32; + break; } - *off = offset; + if (co->co_convert) + offset += co->co_convert(data, buffer + offset, encode); + else /* no coversion: write it out as it is */ + CHANGELOG_FILL_BUFFER(buffer, offset, data, co->co_len); + } + + *off = offset; } int -changelog_encode_ascii (xlator_t *this, 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; + size_t off = 0; + size_t gfid_len = 0; + char *gfid_str = NULL; + char *buffer = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; + priv = this->private; - gfid_str = uuid_utoa (cld->cld_gfid); - gfid_len = strlen (gfid_str); + gfid_str = uuid_utoa(cld->cld_gfid); + gfid_len = strlen(gfid_str); - /* extra bytes for decorations */ - buffer = alloca (gfid_len + cld->cld_ptr_len + 10); - CHANGELOG_STORE_ASCII (priv, buffer, - off, gfid_str, gfid_len, cld); + /* extra bytes for decorations */ + 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); + if (cld->cld_xtra_records) + changelog_encode_write_xtra(cld, buffer, &off, _gf_true); - CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1); + CHANGELOG_FILL_BUFFER(buffer, off, "\0", 1); - return changelog_write_change (priv, buffer, off); + return changelog_write_change(priv, buffer, off); } int -changelog_encode_binary (xlator_t *this, 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; + size_t off = 0; + char *buffer = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; + priv = this->private; - /* extra bytes for decorations */ - buffer = alloca (sizeof (uuid_t) + cld->cld_ptr_len + 10); - CHANGELOG_STORE_BINARY (priv, buffer, off, cld->cld_gfid, cld); + /* extra bytes for decorations */ + buffer = alloca(sizeof(uuid_t) + cld->cld_ptr_len + 10); + CHANGELOG_STORE_BINARY(priv, buffer, off, cld->cld_gfid, cld); - if (cld->cld_xtra_records) - changelog_encode_write_xtra (cld, buffer, &off, _gf_false); + if (cld->cld_xtra_records) + changelog_encode_write_xtra(cld, buffer, &off, _gf_false); - CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1); + CHANGELOG_FILL_BUFFER(buffer, off, "\0", 1); - return changelog_write_change (priv, buffer, off); + return changelog_write_change(priv, buffer, off); } -static struct changelog_encoder -cb_encoder[] = { - [CHANGELOG_ENCODE_BINARY] = +static struct changelog_encoder cb_encoder[] = { + [CHANGELOG_ENCODE_BINARY] = { - .encoder = CHANGELOG_ENCODE_BINARY, - .encode = changelog_encode_binary, + .encoder = CHANGELOG_ENCODE_BINARY, + .encode = changelog_encode_binary, }, - [CHANGELOG_ENCODE_ASCII] = + [CHANGELOG_ENCODE_ASCII] = { - .encoder = CHANGELOG_ENCODE_ASCII, - .encode = 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]; + priv->ce = &cb_encoder[priv->encode_mode]; } diff --git a/xlators/features/changelog/src/changelog-ev-handle.c b/xlators/features/changelog/src/changelog-ev-handle.c index 46d45fbd778..3ed6ff821d9 100644 --- a/xlators/features/changelog/src/changelog-ev-handle.c +++ b/xlators/features/changelog/src/changelog-ev-handle.c @@ -14,19 +14,19 @@ struct rpc_clnt_program changelog_ev_program; -#define NR_IOVEC (MAX_IOVEC - 3) +#define NR_IOVEC (MAX_IOVEC - 3) struct ev_rpc_vec { - int count; - struct iovec vector[NR_IOVEC]; + int count; + struct iovec vector[NR_IOVEC]; - /* sequence number */ - unsigned long seq; + /* sequence number */ + unsigned long seq; }; struct ev_rpc { - rbuf_list_t *rlist; - struct rpc_clnt *rpc; - struct ev_rpc_vec vec; + rbuf_list_t *rlist; + struct rpc_clnt *rpc; + struct ev_rpc_vec vec; }; /** @@ -35,216 +35,215 @@ struct ev_rpc { * intelligence can be built into the server. */ int -changelog_event_dispatch_cbk (struct rpc_req *req, - struct iovec *iov, int count, void *myframe) +changelog_event_dispatch_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) { - return 0; + return 0; } /* dispatcher RPC */ int -changelog_dispatch_vec (call_frame_t *frame, xlator_t *this, - struct rpc_clnt *rpc, struct ev_rpc_vec *vec) +changelog_dispatch_vec(call_frame_t *frame, xlator_t *this, + struct rpc_clnt *rpc, struct ev_rpc_vec *vec) { - struct timeval tv = {0,}; - changelog_event_req req = {0,}; - - (void) gettimeofday (&tv, NULL); - - /** - * Event dispatch RPC header contains a sequence number for each - * dispatch. This allows the receiver to order the request before - * processing. - */ - req.seq = vec->seq; - req.tv_sec = tv.tv_sec; - req.tv_usec = tv.tv_usec; - - return changelog_rpc_sumbit_req (rpc, (void *)&req, - frame, &changelog_ev_program, - CHANGELOG_REV_PROC_EVENT, - vec->vector, vec->count, NULL, - this, changelog_event_dispatch_cbk, - (xdrproc_t) xdr_changelog_event_req); - } - - int - changelog_event_dispatch_rpc (call_frame_t *frame, xlator_t *this, void *data) - { - int idx = 0; - int count = 0; - int ret = 0; - unsigned long sequence = 0; - rbuf_iovec_t *rvec = NULL; - struct ev_rpc *erpc = NULL; - struct rlist_iter riter = {{0,},}; - - /* dispatch NR_IOVEC IO vectors at a time. */ - - erpc = data; - sequence = erpc->rlist->seq[0]; - - rlist_iter_init (&riter, erpc->rlist); - - rvec_for_each_entry (rvec, &riter) { - idx = count % NR_IOVEC; - if (++count == NR_IOVEC) { - erpc->vec.vector[idx] = rvec->iov; - erpc->vec.seq = sequence++; - erpc->vec.count = NR_IOVEC; - - ret = changelog_dispatch_vec (frame, this, - erpc->rpc, &erpc->vec); - if (ret) - break; - count = 0; - continue; - } - - erpc->vec.vector[idx] = rvec->iov; - } - - if (ret) - goto error_return; - - idx = count % NR_IOVEC; - if (idx) { - erpc->vec.seq = sequence; - erpc->vec.count = idx; - - ret = changelog_dispatch_vec (frame, this, - erpc->rpc, &erpc->vec); - } - - error_return: - return ret; + struct timeval tv = { + 0, + }; + changelog_event_req req = { + 0, + }; + + (void)gettimeofday(&tv, NULL); + + /** + * Event dispatch RPC header contains a sequence number for each + * dispatch. This allows the receiver to order the request before + * processing. + */ + req.seq = vec->seq; + req.tv_sec = tv.tv_sec; + req.tv_usec = tv.tv_usec; + + return changelog_rpc_sumbit_req( + rpc, (void *)&req, frame, &changelog_ev_program, + CHANGELOG_REV_PROC_EVENT, vec->vector, vec->count, NULL, this, + changelog_event_dispatch_cbk, (xdrproc_t)xdr_changelog_event_req); } int -changelog_rpc_notify (struct rpc_clnt *rpc, - void *mydata, rpc_clnt_event_t event, void *data) +changelog_event_dispatch_rpc(call_frame_t *frame, xlator_t *this, void *data) { - xlator_t *this = NULL; - changelog_rpc_clnt_t *crpc = NULL; - changelog_clnt_t *c_clnt = NULL; - changelog_priv_t *priv = NULL; - changelog_ev_selector_t *selection = NULL; + int idx = 0; + int count = 0; + int ret = 0; + unsigned long sequence = 0; + rbuf_iovec_t *rvec = NULL; + struct ev_rpc *erpc = NULL; + struct rlist_iter riter = { + { + 0, + }, + }; + + /* dispatch NR_IOVEC IO vectors at a time. */ + + erpc = data; + sequence = erpc->rlist->seq[0]; + + rlist_iter_init(&riter, erpc->rlist); + + rvec_for_each_entry(rvec, &riter) + { + idx = count % NR_IOVEC; + if (++count == NR_IOVEC) { + erpc->vec.vector[idx] = rvec->iov; + erpc->vec.seq = sequence++; + erpc->vec.count = NR_IOVEC; - crpc = mydata; - this = crpc->this; - c_clnt = crpc->c_clnt; + ret = changelog_dispatch_vec(frame, this, erpc->rpc, &erpc->vec); + if (ret) + break; + count = 0; + continue; + } + + erpc->vec.vector[idx] = rvec->iov; + } - priv = this->private; + if (ret) + goto error_return; - switch (event) { + idx = count % NR_IOVEC; + if (idx) { + erpc->vec.seq = sequence; + erpc->vec.count = idx; + + ret = changelog_dispatch_vec(frame, this, erpc->rpc, &erpc->vec); + } + +error_return: + return ret; +} + +int +changelog_rpc_notify(struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, + void *data) +{ + xlator_t *this = NULL; + changelog_rpc_clnt_t *crpc = NULL; + changelog_clnt_t *c_clnt = NULL; + changelog_priv_t *priv = NULL; + changelog_ev_selector_t *selection = NULL; + + crpc = mydata; + this = crpc->this; + c_clnt = crpc->c_clnt; + + priv = this->private; + + switch (event) { case RPC_CLNT_CONNECT: - selection = &priv->ev_selection; + selection = &priv->ev_selection; - LOCK (&c_clnt->wait_lock); + LOCK(&c_clnt->wait_lock); + { + LOCK(&c_clnt->active_lock); { - LOCK (&c_clnt->active_lock); - { - changelog_select_event (this, selection, - crpc->filter); - list_move_tail (&crpc->list, &c_clnt->active); - } - UNLOCK (&c_clnt->active_lock); + changelog_select_event(this, selection, crpc->filter); + list_move_tail(&crpc->list, &c_clnt->active); } - UNLOCK (&c_clnt->wait_lock); + UNLOCK(&c_clnt->active_lock); + } + UNLOCK(&c_clnt->wait_lock); - break; + break; case RPC_CLNT_DISCONNECT: - rpc_clnt_disable (crpc->rpc); + rpc_clnt_disable(crpc->rpc); - /* rpc_clnt_disable doesn't unref the rpc. It just marks - * the rpc as disabled and cancels reconnection timer. - * Hence unref the rpc object to free it. - */ - rpc_clnt_unref (crpc->rpc); + /* rpc_clnt_disable doesn't unref the rpc. It just marks + * the rpc as disabled and cancels reconnection timer. + * Hence unref the rpc object to free it. + */ + rpc_clnt_unref(crpc->rpc); - if (priv) - selection = &priv->ev_selection; + if (priv) + selection = &priv->ev_selection; - LOCK (&crpc->lock); - { - if (selection) - changelog_deselect_event (this, selection, - crpc->filter); - changelog_set_disconnect_flag (crpc, _gf_true); - } - UNLOCK (&crpc->lock); + LOCK(&crpc->lock); + { + if (selection) + changelog_deselect_event(this, selection, crpc->filter); + changelog_set_disconnect_flag(crpc, _gf_true); + } + UNLOCK(&crpc->lock); - break; + break; case RPC_CLNT_MSG: case RPC_CLNT_DESTROY: - /* Free up mydata */ - changelog_rpc_clnt_unref (crpc); - break; + /* Free up mydata */ + changelog_rpc_clnt_unref(crpc); + break; case RPC_CLNT_PING: - break; - } + break; + } - return 0; + return 0; } void * -changelog_ev_connector (void *data) +changelog_ev_connector(void *data) { - xlator_t *this = NULL; - changelog_clnt_t *c_clnt = NULL; - changelog_rpc_clnt_t *crpc = NULL; + xlator_t *this = NULL; + changelog_clnt_t *c_clnt = NULL; + changelog_rpc_clnt_t *crpc = NULL; - c_clnt = data; - this = c_clnt->this; + c_clnt = data; + this = c_clnt->this; - while (1) { - pthread_mutex_lock (&c_clnt->pending_lock); - { - while (list_empty (&c_clnt->pending)) - pthread_cond_wait (&c_clnt->pending_cond, - &c_clnt->pending_lock); - crpc = list_first_entry (&c_clnt->pending, - changelog_rpc_clnt_t, list); - crpc->rpc = - changelog_rpc_client_init (this, crpc, - crpc->sock, - changelog_rpc_notify); - if (!crpc->rpc) { - gf_smsg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_RPC_CONNECT_ERROR, - "failed to connect back", - "path=%s", crpc->sock, - NULL); - crpc->cleanup (crpc); - goto mutex_unlock; - } - - LOCK (&c_clnt->wait_lock); - { - list_move_tail (&crpc->list, &c_clnt->waitq); - } - UNLOCK (&c_clnt->wait_lock); - } - mutex_unlock: - pthread_mutex_unlock (&c_clnt->pending_lock); + while (1) { + pthread_mutex_lock(&c_clnt->pending_lock); + { + while (list_empty(&c_clnt->pending)) + pthread_cond_wait(&c_clnt->pending_cond, &c_clnt->pending_lock); + crpc = list_first_entry(&c_clnt->pending, changelog_rpc_clnt_t, + list); + crpc->rpc = changelog_rpc_client_init(this, crpc, crpc->sock, + changelog_rpc_notify); + if (!crpc->rpc) { + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_RPC_CONNECT_ERROR, + "failed to connect back", "path=%s", crpc->sock, NULL); + crpc->cleanup(crpc); + goto mutex_unlock; + } + + LOCK(&c_clnt->wait_lock); + { + list_move_tail(&crpc->list, &c_clnt->waitq); + } + UNLOCK(&c_clnt->wait_lock); } + mutex_unlock: + pthread_mutex_unlock(&c_clnt->pending_lock); + } - return NULL; + return NULL; } void -changelog_ev_cleanup_connections (xlator_t *this, changelog_clnt_t *c_clnt) +changelog_ev_cleanup_connections(xlator_t *this, changelog_clnt_t *c_clnt) { - changelog_rpc_clnt_t *crpc = NULL; + changelog_rpc_clnt_t *crpc = NULL; - /* cleanup active connections */ - LOCK (&c_clnt->active_lock); + /* cleanup active connections */ + LOCK(&c_clnt->active_lock); + { + list_for_each_entry(crpc, &c_clnt->active, list) { - list_for_each_entry (crpc, &c_clnt->active, list) { - rpc_clnt_disable (crpc->rpc); - } + rpc_clnt_disable(crpc->rpc); } - UNLOCK (&c_clnt->active_lock); + } + UNLOCK(&c_clnt->active_lock); } /** @@ -255,147 +254,146 @@ changelog_ev_cleanup_connections (xlator_t *this, changelog_clnt_t *c_clnt) */ static changelog_rpc_clnt_t * -get_client (changelog_clnt_t *c_clnt, struct list_head **next) +get_client(changelog_clnt_t *c_clnt, struct list_head **next) { - changelog_rpc_clnt_t *crpc = NULL; - - LOCK (&c_clnt->active_lock); - { - if (*next == &c_clnt->active) - goto unblock; - crpc = list_entry (*next, changelog_rpc_clnt_t, list); - /* ref rpc as DISCONNECT might unref the rpc asynchronously */ - changelog_rpc_clnt_ref (crpc); - rpc_clnt_ref (crpc->rpc); - *next = (*next)->next; - } - unblock: - UNLOCK (&c_clnt->active_lock); - - return crpc; + changelog_rpc_clnt_t *crpc = NULL; + + LOCK(&c_clnt->active_lock); + { + if (*next == &c_clnt->active) + goto unblock; + crpc = list_entry(*next, changelog_rpc_clnt_t, list); + /* ref rpc as DISCONNECT might unref the rpc asynchronously */ + changelog_rpc_clnt_ref(crpc); + rpc_clnt_ref(crpc->rpc); + *next = (*next)->next; + } +unblock: + UNLOCK(&c_clnt->active_lock); + + return crpc; } static void -put_client (changelog_clnt_t *c_clnt, changelog_rpc_clnt_t *crpc) +put_client(changelog_clnt_t *c_clnt, changelog_rpc_clnt_t *crpc) { - LOCK (&c_clnt->active_lock); - { - rpc_clnt_unref (crpc->rpc); - changelog_rpc_clnt_unref (crpc); - } - UNLOCK (&c_clnt->active_lock); + LOCK(&c_clnt->active_lock); + { + rpc_clnt_unref(crpc->rpc); + changelog_rpc_clnt_unref(crpc); + } + UNLOCK(&c_clnt->active_lock); } void -_dispatcher (rbuf_list_t *rlist, void *arg) +_dispatcher(rbuf_list_t *rlist, void *arg) { - xlator_t *this = NULL; - changelog_clnt_t *c_clnt = NULL; - changelog_rpc_clnt_t *crpc = NULL; - struct ev_rpc erpc = {0,}; - struct list_head *next = NULL; - - c_clnt = arg; - this = c_clnt->this; - - erpc.rlist = rlist; - next = c_clnt->active.next; - - while (1) { - crpc = get_client (c_clnt, &next); - if (!crpc) - break; - erpc.rpc = crpc->rpc; - (void) changelog_invoke_rpc (this, crpc->rpc, - &changelog_ev_program, - CHANGELOG_REV_PROC_EVENT, &erpc); - put_client (c_clnt, crpc); - } + xlator_t *this = NULL; + changelog_clnt_t *c_clnt = NULL; + changelog_rpc_clnt_t *crpc = NULL; + struct ev_rpc erpc = { + 0, + }; + struct list_head *next = NULL; + + c_clnt = arg; + this = c_clnt->this; + + erpc.rlist = rlist; + next = c_clnt->active.next; + + while (1) { + crpc = get_client(c_clnt, &next); + if (!crpc) + break; + erpc.rpc = crpc->rpc; + (void)changelog_invoke_rpc(this, crpc->rpc, &changelog_ev_program, + CHANGELOG_REV_PROC_EVENT, &erpc); + put_client(c_clnt, crpc); + } } /** this is called under rotbuff's lock */ void -sequencer (rbuf_list_t *rlist, void *mydata) +sequencer(rbuf_list_t *rlist, void *mydata) { - unsigned long range = 0; - changelog_clnt_t *c_clnt = 0; + unsigned long range = 0; + changelog_clnt_t *c_clnt = 0; - c_clnt = mydata; + c_clnt = mydata; - range = (RLIST_ENTRY_COUNT (rlist)) / NR_IOVEC; - if ((RLIST_ENTRY_COUNT (rlist)) % NR_IOVEC) - range++; - RLIST_STORE_SEQ (rlist, c_clnt->sequence, range); + range = (RLIST_ENTRY_COUNT(rlist)) / NR_IOVEC; + if ((RLIST_ENTRY_COUNT(rlist)) % NR_IOVEC) + range++; + RLIST_STORE_SEQ(rlist, c_clnt->sequence, range); - c_clnt->sequence += range; + c_clnt->sequence += range; } void * -changelog_ev_dispatch (void *data) +changelog_ev_dispatch(void *data) { - int ret = 0; - void *opaque = NULL; - xlator_t *this = NULL; - changelog_clnt_t *c_clnt = NULL; - struct timeval tv = {0,}; - - c_clnt = data; - this = c_clnt->this; - - while (1) { - /* TODO: change this to be pthread cond based.. later */ - - tv.tv_sec = 1; - tv.tv_usec = 0; - select (0, NULL, NULL, NULL, &tv); - - ret = rbuf_get_buffer (c_clnt->rbuf, - &opaque, sequencer, c_clnt); - if (ret != RBUF_CONSUMABLE) { - if (ret != RBUF_EMPTY) - gf_smsg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_MSG_BUFFER_STARVATION_ERROR, - "Failed to get buffer for RPC dispatch", - "rbuf_retval=%d", ret, - NULL); - continue; - } - - ret = rbuf_wait_for_completion (c_clnt->rbuf, - opaque, _dispatcher, c_clnt); - if (ret) - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_MSG_PUT_BUFFER_FAILED, - "failed to put buffer after consumption"); - + int ret = 0; + void *opaque = NULL; + xlator_t *this = NULL; + changelog_clnt_t *c_clnt = NULL; + struct timeval tv = { + 0, + }; + + c_clnt = data; + this = c_clnt->this; + + while (1) { + /* TODO: change this to be pthread cond based.. later */ + + tv.tv_sec = 1; + tv.tv_usec = 0; + select(0, NULL, NULL, NULL, &tv); + + ret = rbuf_get_buffer(c_clnt->rbuf, &opaque, sequencer, c_clnt); + if (ret != RBUF_CONSUMABLE) { + if (ret != RBUF_EMPTY) + gf_smsg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_MSG_BUFFER_STARVATION_ERROR, + "Failed to get buffer for RPC dispatch", + "rbuf_retval=%d", ret, NULL); + continue; } - return NULL; + ret = rbuf_wait_for_completion(c_clnt->rbuf, opaque, _dispatcher, + c_clnt); + if (ret) + gf_msg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_MSG_PUT_BUFFER_FAILED, + "failed to put buffer after consumption"); + } + + return NULL; } void -changelog_ev_queue_connection (changelog_clnt_t *c_clnt, - changelog_rpc_clnt_t *crpc) +changelog_ev_queue_connection(changelog_clnt_t *c_clnt, + changelog_rpc_clnt_t *crpc) { - pthread_mutex_lock (&c_clnt->pending_lock); - { - list_add_tail (&crpc->list, &c_clnt->pending); - pthread_cond_signal (&c_clnt->pending_cond); - } - pthread_mutex_unlock (&c_clnt->pending_lock); + pthread_mutex_lock(&c_clnt->pending_lock); + { + list_add_tail(&crpc->list, &c_clnt->pending); + pthread_cond_signal(&c_clnt->pending_cond); + } + pthread_mutex_unlock(&c_clnt->pending_lock); } struct rpc_clnt_procedure changelog_ev_procs[CHANGELOG_REV_PROC_MAX] = { - [CHANGELOG_REV_PROC_NULL] = {"NULL", NULL}, - [CHANGELOG_REV_PROC_EVENT] = { - "EVENT DISPATCH", changelog_event_dispatch_rpc - }, + [CHANGELOG_REV_PROC_NULL] = {"NULL", NULL}, + [CHANGELOG_REV_PROC_EVENT] = {"EVENT DISPATCH", + changelog_event_dispatch_rpc}, }; struct rpc_clnt_program changelog_ev_program = { - .progname = "CHANGELOG EVENT DISPATCHER", - .prognum = CHANGELOG_REV_RPC_PROCNUM, - .progver = CHANGELOG_REV_RPC_PROCVER, - .numproc = CHANGELOG_REV_PROC_MAX, - .proctable = changelog_ev_procs, + .progname = "CHANGELOG EVENT DISPATCHER", + .prognum = CHANGELOG_REV_RPC_PROCNUM, + .progver = CHANGELOG_REV_RPC_PROCVER, + .numproc = CHANGELOG_REV_PROC_MAX, + .proctable = changelog_ev_procs, }; diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c index 28c72a8f9d4..53219bf2d78 100644 --- a/xlators/features/changelog/src/changelog-helpers.c +++ b/xlators/features/changelog/src/changelog-helpers.c @@ -24,316 +24,301 @@ #include <pthread.h> static void -changelog_cleanup_free_mutex (void *arg_mutex) +changelog_cleanup_free_mutex(void *arg_mutex) { - pthread_mutex_t *p_mutex = (pthread_mutex_t*) arg_mutex; + pthread_mutex_t *p_mutex = (pthread_mutex_t *)arg_mutex; if (p_mutex) - pthread_mutex_unlock(p_mutex); + pthread_mutex_unlock(p_mutex); } int -changelog_thread_cleanup (xlator_t *this, pthread_t thr_id) +changelog_thread_cleanup(xlator_t *this, pthread_t thr_id) { - int ret = 0; - void *retval = NULL; - - /* send a cancel request to the thread */ - ret = pthread_cancel (thr_id); - if (ret != 0) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_CANCEL_FAILED, - "could not cancel thread"); - goto out; - } - - ret = pthread_join (thr_id, &retval); - if ((ret != 0) || (retval != PTHREAD_CANCELED)) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_CANCEL_FAILED, - "cancel request not adhered as expected"); - } + int ret = 0; + void *retval = NULL; + + /* send a cancel request to the thread */ + ret = pthread_cancel(thr_id); + if (ret != 0) { + gf_msg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_CANCEL_FAILED, "could not cancel thread"); + goto out; + } + + ret = pthread_join(thr_id, &retval); + if ((ret != 0) || (retval != PTHREAD_CANCELED)) { + gf_msg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_CANCEL_FAILED, + "cancel request not adhered as expected"); + } - out: - return ret; +out: + return ret; } void * -changelog_get_usable_buffer (changelog_local_t *local) +changelog_get_usable_buffer(changelog_local_t *local) { - changelog_log_data_t *cld = NULL; + changelog_log_data_t *cld = NULL; - if (!local) - return NULL; + if (!local) + return NULL; - cld = &local->cld; - if (!cld->cld_iobuf) - return NULL; + cld = &local->cld; + if (!cld->cld_iobuf) + return NULL; - return cld->cld_iobuf->ptr; + return cld->cld_iobuf->ptr; } static int -changelog_selector_index (unsigned int selector) +changelog_selector_index(unsigned int selector) { - return (ffs (selector) - 1); + return (ffs(selector) - 1); } int -changelog_ev_selected (xlator_t *this, - changelog_ev_selector_t *selection, - unsigned int selector) +changelog_ev_selected(xlator_t *this, changelog_ev_selector_t *selection, + unsigned int selector) { - int idx = 0; - - idx = changelog_selector_index (selector); - gf_msg_debug (this->name, 0, - "selector ref count for %d (idx: %d): %d", - selector, idx, selection->ref[idx]); - /* this can be lockless */ - return (idx < CHANGELOG_EV_SELECTION_RANGE - && (selection->ref[idx] > 0)); + int idx = 0; + + idx = changelog_selector_index(selector); + gf_msg_debug(this->name, 0, "selector ref count for %d (idx: %d): %d", + selector, idx, selection->ref[idx]); + /* this can be lockless */ + return (idx < CHANGELOG_EV_SELECTION_RANGE && (selection->ref[idx] > 0)); } void -changelog_select_event (xlator_t *this, - changelog_ev_selector_t *selection, - unsigned int selector) +changelog_select_event(xlator_t *this, changelog_ev_selector_t *selection, + unsigned int selector) { - int idx = 0; - - LOCK (&selection->reflock); - { - while (selector) { - idx = changelog_selector_index (selector); - if (idx < CHANGELOG_EV_SELECTION_RANGE) { - selection->ref[idx]++; - gf_msg_debug (this->name, 0, - "selecting event %d", idx); - } - selector &= ~(1 << idx); - } - } - UNLOCK (&selection->reflock); + int idx = 0; + + LOCK(&selection->reflock); + { + while (selector) { + idx = changelog_selector_index(selector); + if (idx < CHANGELOG_EV_SELECTION_RANGE) { + selection->ref[idx]++; + gf_msg_debug(this->name, 0, "selecting event %d", idx); + } + selector &= ~(1 << idx); + } + } + UNLOCK(&selection->reflock); } void -changelog_deselect_event (xlator_t *this, - changelog_ev_selector_t *selection, - unsigned int selector) +changelog_deselect_event(xlator_t *this, changelog_ev_selector_t *selection, + unsigned int selector) { - int idx = 0; - - LOCK (&selection->reflock); - { - while (selector) { - idx = changelog_selector_index (selector); - if (idx < CHANGELOG_EV_SELECTION_RANGE) { - selection->ref[idx]--; - gf_msg_debug (this->name, 0, - "de-selecting event %d", idx); - } - selector &= ~(1 << idx); - } - } - UNLOCK (&selection->reflock); + int idx = 0; + + LOCK(&selection->reflock); + { + while (selector) { + idx = changelog_selector_index(selector); + if (idx < CHANGELOG_EV_SELECTION_RANGE) { + selection->ref[idx]--; + gf_msg_debug(this->name, 0, "de-selecting event %d", idx); + } + selector &= ~(1 << idx); + } + } + UNLOCK(&selection->reflock); } int -changelog_init_event_selection (xlator_t *this, - changelog_ev_selector_t *selection) +changelog_init_event_selection(xlator_t *this, + changelog_ev_selector_t *selection) { - int ret = 0; - int j = CHANGELOG_EV_SELECTION_RANGE; + int ret = 0; + int j = CHANGELOG_EV_SELECTION_RANGE; - ret = LOCK_INIT (&selection->reflock); - if (ret != 0) - return -1; + ret = LOCK_INIT(&selection->reflock); + if (ret != 0) + return -1; - LOCK (&selection->reflock); - { - while (j--) { - selection->ref[j] = 0; - } + LOCK(&selection->reflock); + { + while (j--) { + selection->ref[j] = 0; } - UNLOCK (&selection->reflock); + } + UNLOCK(&selection->reflock); - return 0; + return 0; } int -changelog_cleanup_event_selection (xlator_t *this, - changelog_ev_selector_t *selection) +changelog_cleanup_event_selection(xlator_t *this, + changelog_ev_selector_t *selection) { - int j = CHANGELOG_EV_SELECTION_RANGE; + int j = CHANGELOG_EV_SELECTION_RANGE; - LOCK (&selection->reflock); - { - while (j--) { - if (selection->ref[j] > 0) - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_MSG_CLEANUP_ON_ACTIVE_REF, - "changelog event selection cleaning up " - " on active references"); - } + LOCK(&selection->reflock); + { + while (j--) { + if (selection->ref[j] > 0) + gf_msg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_MSG_CLEANUP_ON_ACTIVE_REF, + "changelog event selection cleaning up " + " on active references"); } - UNLOCK (&selection->reflock); + } + UNLOCK(&selection->reflock); - return LOCK_DESTROY (&selection->reflock); + return LOCK_DESTROY(&selection->reflock); } static void -changelog_perform_dispatch (xlator_t *this, - changelog_priv_t *priv, void *mem, size_t size) +changelog_perform_dispatch(xlator_t *this, changelog_priv_t *priv, void *mem, + size_t size) { - char *buf = NULL; - void *opaque = NULL; - - buf = rbuf_reserve_write_area (priv->rbuf, size, &opaque); - if (!buf) { - gf_msg_callingfn (this->name, - GF_LOG_WARNING, 0, - CHANGELOG_MSG_DISPATCH_EVENT_FAILED, - "failed to dispatch event"); - return; - } + char *buf = NULL; + void *opaque = NULL; + + buf = rbuf_reserve_write_area(priv->rbuf, size, &opaque); + if (!buf) { + gf_msg_callingfn(this->name, GF_LOG_WARNING, 0, + CHANGELOG_MSG_DISPATCH_EVENT_FAILED, + "failed to dispatch event"); + return; + } - memcpy (buf, mem, size); - rbuf_write_complete (opaque); + memcpy(buf, mem, size); + rbuf_write_complete(opaque); } void -changelog_dispatch_event (xlator_t *this, - changelog_priv_t *priv, changelog_event_t *ev) +changelog_dispatch_event(xlator_t *this, changelog_priv_t *priv, + changelog_event_t *ev) { - changelog_ev_selector_t *selection = NULL; + changelog_ev_selector_t *selection = NULL; - selection = &priv->ev_selection; - if (changelog_ev_selected (this, selection, ev->ev_type)) { - changelog_perform_dispatch (this, priv, ev, CHANGELOG_EV_SIZE); - } + selection = &priv->ev_selection; + if (changelog_ev_selected(this, selection, ev->ev_type)) { + changelog_perform_dispatch(this, priv, ev, CHANGELOG_EV_SIZE); + } } void -changelog_set_usable_record_and_length (changelog_local_t *local, - size_t len, int xr) +changelog_set_usable_record_and_length(changelog_local_t *local, size_t len, + int xr) { - changelog_log_data_t *cld = NULL; + changelog_log_data_t *cld = NULL; - cld = &local->cld; + cld = &local->cld; - cld->cld_ptr_len = len; - cld->cld_xtra_records = xr; + cld->cld_ptr_len = len; + cld->cld_xtra_records = xr; } void -changelog_local_cleanup (xlator_t *xl, changelog_local_t *local) +changelog_local_cleanup(xlator_t *xl, changelog_local_t *local) { - int i = 0; - changelog_opt_t *co = NULL; - changelog_log_data_t *cld = NULL; + int i = 0; + changelog_opt_t *co = NULL; + changelog_log_data_t *cld = NULL; - if (!local) - return; + if (!local) + return; - cld = &local->cld; + cld = &local->cld; - /* cleanup dynamic allocation for extra records */ - 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); - } + /* cleanup dynamic allocation for extra records */ + 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 (cld->cld_iobuf); + CHANGELOG_IOBUF_UNREF(cld->cld_iobuf); - if (local->inode) - inode_unref (local->inode); + if (local->inode) + inode_unref(local->inode); - mem_put (local); + mem_put(local); } int -changelog_write (int fd, char *buffer, size_t len) +changelog_write(int fd, char *buffer, size_t len) { - ssize_t size = 0; - size_t written = 0; + ssize_t size = 0; + size_t written = 0; - while (written < len) { - size = sys_write (fd, - buffer + written, len - written); - if (size <= 0) - break; + while (written < len) { + size = sys_write(fd, buffer + written, len - written); + if (size <= 0) + break; - written += size; - } + written += size; + } - return (written != len); + return (written != len); } int -htime_update (xlator_t *this, - changelog_priv_t *priv, unsigned long ts, - char * buffer) +htime_update(xlator_t *this, changelog_priv_t *priv, unsigned long ts, + char *buffer) { - char changelog_path[PATH_MAX+1] = {0,}; - int len = -1; - char x_value[25] = {0,}; - /* time stamp(10) + : (1) + rolltime (12 ) + buffer (2) */ - int ret = 0; - - if (priv->htime_fd ==-1) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_HTIME_ERROR, - "Htime fd not available for updation"); - ret = -1; - goto out; - } - len = snprintf(changelog_path, PATH_MAX, "%s", buffer); - if (len >= PATH_MAX) { - ret = -1; - goto out; - } - if (changelog_write (priv->htime_fd, (void*) changelog_path, len+1 ) < 0) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_HTIME_ERROR, - "Htime file content write failed"); - ret =-1; - goto out; - } - - len = snprintf (x_value, sizeof (x_value), "%lu:%d", - ts, priv->rollover_count); - if (len >= sizeof (x_value)) { - ret = -1; - goto out; - } - - if (sys_fsetxattr (priv->htime_fd, HTIME_KEY, x_value, - len, XATTR_REPLACE)) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_HTIME_ERROR, - "Htime xattr updation failed with XATTR_REPLACE", - "changelog=%s", changelog_path, - NULL); - - if (sys_fsetxattr (priv->htime_fd, HTIME_KEY, x_value, - len, 0)) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_HTIME_ERROR, - "Htime xattr updation failed", - "changelog=%s", changelog_path, - NULL); - ret = -1; - goto out; - } - } - - priv->rollover_count +=1; + char changelog_path[PATH_MAX + 1] = { + 0, + }; + int len = -1; + char x_value[25] = { + 0, + }; + /* time stamp(10) + : (1) + rolltime (12 ) + buffer (2) */ + int ret = 0; + + if (priv->htime_fd == -1) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_HTIME_ERROR, + "Htime fd not available for updation"); + ret = -1; + goto out; + } + len = snprintf(changelog_path, PATH_MAX, "%s", buffer); + if (len >= PATH_MAX) { + ret = -1; + goto out; + } + if (changelog_write(priv->htime_fd, (void *)changelog_path, len + 1) < 0) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_HTIME_ERROR, + "Htime file content write failed"); + ret = -1; + goto out; + } + + len = snprintf(x_value, sizeof(x_value), "%lu:%d", ts, + priv->rollover_count); + if (len >= sizeof(x_value)) { + ret = -1; + goto out; + } + + if (sys_fsetxattr(priv->htime_fd, HTIME_KEY, x_value, len, XATTR_REPLACE)) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_HTIME_ERROR, + "Htime xattr updation failed with XATTR_REPLACE", + "changelog=%s", changelog_path, NULL); + + if (sys_fsetxattr(priv->htime_fd, HTIME_KEY, x_value, len, 0)) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_HTIME_ERROR, + "Htime xattr updation failed", "changelog=%s", + changelog_path, NULL); + ret = -1; + goto out; + } + } + + priv->rollover_count += 1; out: - return ret; + return ret; } /* @@ -345,43 +330,45 @@ out: * 0 : If NOT empty, proceed usual. */ int -cl_is_empty (xlator_t *this, int fd) +cl_is_empty(xlator_t *this, int fd) { - int ret = -1; - size_t elen = 0; - int encoding = -1; - char buffer[1024] = {0,}; - struct stat stbuf = {0,}; - int major_version = -1; - int minor_version = -1; - - ret = sys_fstat (fd, &stbuf); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FSTAT_OP_FAILED, - "Could not stat (CHANGELOG)"); - goto out; - } - - ret = sys_lseek (fd, 0, SEEK_SET); - if (ret == -1) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_LSEEK_OP_FAILED, - "Could not lseek (CHANGELOG)"); - goto out; - } - - CHANGELOG_GET_HEADER_INFO (fd, buffer, sizeof (buffer), encoding, - major_version, minor_version, elen); - - if (elen == stbuf.st_size) { - ret = 1; - } else { - ret = 0; - } + int ret = -1; + size_t elen = 0; + int encoding = -1; + char buffer[1024] = { + 0, + }; + struct stat stbuf = { + 0, + }; + int major_version = -1; + int minor_version = -1; + + ret = sys_fstat(fd, &stbuf); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSTAT_OP_FAILED, + "Could not stat (CHANGELOG)"); + goto out; + } + + ret = sys_lseek(fd, 0, SEEK_SET); + if (ret == -1) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_LSEEK_OP_FAILED, + "Could not lseek (CHANGELOG)"); + goto out; + } + + CHANGELOG_GET_HEADER_INFO(fd, buffer, sizeof(buffer), encoding, + major_version, minor_version, elen); + + if (elen == stbuf.st_size) { + ret = 1; + } else { + ret = 0; + } out: - return ret; + return ret; } /* @@ -393,162 +380,156 @@ out: * -1 : Error */ int -update_path (xlator_t *this, char *cl_path) +update_path(xlator_t *this, char *cl_path) { - const char low_cl[] = "changelog"; - const char up_cl[] = "CHANGELOG"; - char *found = NULL; - int ret = -1; - - found = strstr(cl_path, up_cl); - - if (found == NULL) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_LSEEK_OP_FAILED, - "Could not find CHANGELOG in changelog path"); - goto out; - } else { - memcpy(found, low_cl, sizeof (low_cl) - 1); - } - - ret = 0; + const char low_cl[] = "changelog"; + const char up_cl[] = "CHANGELOG"; + char *found = NULL; + int ret = -1; + + found = strstr(cl_path, up_cl); + + if (found == NULL) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_LSEEK_OP_FAILED, + "Could not find CHANGELOG in changelog path"); + goto out; + } else { + memcpy(found, low_cl, sizeof(low_cl) - 1); + } + + ret = 0; out: - return ret; + return ret; } static int -changelog_rollover_changelog (xlator_t *this, - changelog_priv_t *priv, unsigned long ts) +changelog_rollover_changelog(xlator_t *this, changelog_priv_t *priv, + unsigned long ts) { - int ret = -1; - int notify = 0; - int cl_empty_flag = 0; - char ofile[PATH_MAX] = {0,}; - char nfile[PATH_MAX] = {0,}; - changelog_event_t ev = {0,}; - - if (priv->changelog_fd != -1) { - ret = sys_fsync (priv->changelog_fd); - if (ret < 0) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FSYNC_OP_FAILED, - "fsync failed"); - } - ret = cl_is_empty (this, priv->changelog_fd); - if (ret == 1) { - cl_empty_flag = 1; - } else if (ret == -1) { - /* Log error but proceed as usual */ - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_MSG_DETECT_EMPTY_CHANGELOG_FAILED, - "Error detecting empty changelog"); - } - sys_close (priv->changelog_fd); - priv->changelog_fd = -1; + int ret = -1; + int notify = 0; + int cl_empty_flag = 0; + char ofile[PATH_MAX] = { + 0, + }; + char nfile[PATH_MAX] = { + 0, + }; + changelog_event_t ev = { + 0, + }; + + if (priv->changelog_fd != -1) { + ret = sys_fsync(priv->changelog_fd); + if (ret < 0) { + gf_msg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_FSYNC_OP_FAILED, "fsync failed"); + } + ret = cl_is_empty(this, priv->changelog_fd); + if (ret == 1) { + cl_empty_flag = 1; + } else if (ret == -1) { + /* Log error but proceed as usual */ + gf_msg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_MSG_DETECT_EMPTY_CHANGELOG_FAILED, + "Error detecting empty changelog"); + } + sys_close(priv->changelog_fd); + priv->changelog_fd = -1; + } + + (void)snprintf(ofile, PATH_MAX, "%s/" CHANGELOG_FILE_NAME, + priv->changelog_dir); + (void)snprintf(nfile, PATH_MAX, "%s/" CHANGELOG_FILE_NAME ".%lu", + priv->changelog_dir, ts); + + if (cl_empty_flag == 1) { + ret = sys_unlink(ofile); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_UNLINK_OP_FAILED, + "error unlinking empty changelog", "path=%s", ofile, NULL); + ret = 0; /* Error in unlinking empty changelog should + not break further changelog operation, so + reset return value to 0*/ } + } else { + ret = sys_rename(ofile, nfile); - (void) snprintf (ofile, PATH_MAX, - "%s/"CHANGELOG_FILE_NAME, priv->changelog_dir); - (void) snprintf (nfile, PATH_MAX, - "%s/"CHANGELOG_FILE_NAME".%lu", - priv->changelog_dir, ts); - - if (cl_empty_flag == 1) { - ret = sys_unlink (ofile); - if (ret) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_UNLINK_OP_FAILED, - "error unlinking empty changelog", - "path=%s", ofile, - NULL); - ret = 0; /* Error in unlinking empty changelog should - not break further changelog operation, so - reset return value to 0*/ - } - } else { - ret = sys_rename (ofile, nfile); - - if (ret && (errno == ENOENT)) { - ret = 0; - goto out; - } - if (ret) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_RENAME_ERROR, - "error renaming", - "from=%s", ofile, - "to=%s", nfile, - NULL); - } + if (ret && (errno == ENOENT)) { + ret = 0; + goto out; } - - if (!ret && (cl_empty_flag == 0)) { - notify = 1; + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_RENAME_ERROR, + "error renaming", "from=%s", ofile, "to=%s", nfile, NULL); } + } - if (!ret) { - if (cl_empty_flag) { - update_path (this, nfile); - } - ret = htime_update (this, priv, ts, nfile); - if (ret == -1) { - gf_msg (this->name, GF_LOG_ERROR, - 0, CHANGELOG_MSG_HTIME_ERROR, - "could not update htime file"); - goto out; - } - } + if (!ret && (cl_empty_flag == 0)) { + notify = 1; + } - if (notify) { - ev.ev_type = CHANGELOG_OP_TYPE_JOURNAL; - memcpy (ev.u.journal.path, nfile, strlen (nfile) + 1); - changelog_dispatch_event (this, priv, &ev); + if (!ret) { + if (cl_empty_flag) { + update_path(this, nfile); } - out: - /* If this is explicit rollover initiated by snapshot, - * wakeup reconfigure thread waiting for changelog to - * rollover. This should happen even in failure cases as - * well otherwise snapshot will timeout and fail. Hence - * moved under out. - */ - if (priv->explicit_rollover) { - priv->explicit_rollover = _gf_false; - - pthread_mutex_lock (&priv->bn.bnotify_mutex); - { - if (ret) { - priv->bn.bnotify_error = _gf_true; - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_EXPLICIT_ROLLOVER_FAILED, - "Fail snapshot because of " - "previous errors"); - } else { - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BNOTIFY_INFO, "Explicit " - "rollover changelog signaling " - "bnotify", - "changelog=%s", nfile, - NULL); - } - priv->bn.bnotify = _gf_false; - pthread_cond_signal (&priv->bn.bnotify_cond); - } - pthread_mutex_unlock (&priv->bn.bnotify_mutex); + ret = htime_update(this, priv, ts, nfile); + if (ret == -1) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_HTIME_ERROR, + "could not update htime file"); + goto out; } - return ret; + } + + if (notify) { + ev.ev_type = CHANGELOG_OP_TYPE_JOURNAL; + memcpy(ev.u.journal.path, nfile, strlen(nfile) + 1); + changelog_dispatch_event(this, priv, &ev); + } +out: + /* If this is explicit rollover initiated by snapshot, + * wakeup reconfigure thread waiting for changelog to + * rollover. This should happen even in failure cases as + * well otherwise snapshot will timeout and fail. Hence + * moved under out. + */ + if (priv->explicit_rollover) { + priv->explicit_rollover = _gf_false; + + pthread_mutex_lock(&priv->bn.bnotify_mutex); + { + if (ret) { + priv->bn.bnotify_error = _gf_true; + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_EXPLICIT_ROLLOVER_FAILED, + "Fail snapshot because of " + "previous errors"); + } else { + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BNOTIFY_INFO, + "Explicit " + "rollover changelog signaling " + "bnotify", + "changelog=%s", nfile, NULL); + } + priv->bn.bnotify = _gf_false; + pthread_cond_signal(&priv->bn.bnotify_cond); + } + pthread_mutex_unlock(&priv->bn.bnotify_mutex); + } + return ret; } int -filter_cur_par_dirs (const struct dirent *entry) +filter_cur_par_dirs(const struct dirent *entry) { - if (entry == NULL) - return 0; + if (entry == NULL) + return 0; - if ((strcmp(entry->d_name, ".") == 0) || - (strcmp(entry->d_name, "..") == 0)) - return 0; - else - return 1; + if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) + return 0; + else + return 1; } /* @@ -561,313 +542,296 @@ filter_cur_par_dirs (const struct dirent *entry) */ int -find_current_htime (int ht_dir_fd, const char *ht_dir_path, char *ht_file_bname) +find_current_htime(int ht_dir_fd, const char *ht_dir_path, char *ht_file_bname) { - struct dirent **namelist = NULL; - int ret = 0; - int cnt = 0; - int i = 0; - xlator_t *this = NULL; - - this = THIS; - GF_ASSERT (this); - GF_ASSERT (ht_dir_path); - - cnt = scandir (ht_dir_path, &namelist, filter_cur_par_dirs, alphasort); - if (cnt < 0) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_SCAN_DIR_FAILED, - "scandir failed"); - } else if (cnt > 0) { - if (snprintf (ht_file_bname, NAME_MAX, "%s", - namelist[cnt - 1]->d_name) >= NAME_MAX) { - ret = -1; - goto out; - } - if (sys_fsetxattr (ht_dir_fd, HTIME_CURRENT, ht_file_bname, - strlen (ht_file_bname), 0)) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FSETXATTR_FAILED, - "fsetxattr failed: HTIME_CURRENT"); - ret = -1; - goto out; - } + struct dirent **namelist = NULL; + int ret = 0; + int cnt = 0; + int i = 0; + xlator_t *this = NULL; + + this = THIS; + GF_ASSERT(this); + GF_ASSERT(ht_dir_path); + + cnt = scandir(ht_dir_path, &namelist, filter_cur_par_dirs, alphasort); + if (cnt < 0) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_SCAN_DIR_FAILED, + "scandir failed"); + } else if (cnt > 0) { + if (snprintf(ht_file_bname, NAME_MAX, "%s", + namelist[cnt - 1]->d_name) >= NAME_MAX) { + ret = -1; + goto out; + } + if (sys_fsetxattr(ht_dir_fd, HTIME_CURRENT, ht_file_bname, + strlen(ht_file_bname), 0)) { + gf_msg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_FSETXATTR_FAILED, + "fsetxattr failed: HTIME_CURRENT"); + ret = -1; + goto out; + } + + if (sys_fsync(ht_dir_fd) < 0) { + gf_msg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_FSYNC_OP_FAILED, "fsync failed"); + ret = -1; + goto out; + } + } - if (sys_fsync (ht_dir_fd) < 0) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FSYNC_OP_FAILED, - "fsync failed"); - ret = -1; - goto out; - } - } +out: + for (i = 0; i < cnt; i++) + free(namelist[i]); + free(namelist); - out: - for (i = 0; i < cnt; i++) - free (namelist[i]); - free (namelist); + if (ret) + cnt = ret; - if (ret) - cnt = ret; - - return cnt; + return cnt; } /* Returns 0 on successful open of htime file * returns -1 on failure or error */ int -htime_open (xlator_t *this, - changelog_priv_t *priv, unsigned long ts) +htime_open(xlator_t *this, changelog_priv_t *priv, unsigned long ts) { - int ht_file_fd = -1; - int ht_dir_fd = -1; - int ret = 0; - int cnt = 0; - char ht_dir_path[PATH_MAX] = {0,}; - char ht_file_path[PATH_MAX] = {0,}; - char ht_file_bname[NAME_MAX] = {0,}; - char x_value[NAME_MAX] = {0,}; - int flags = 0; - unsigned long min_ts = 0; - unsigned long max_ts = 0; - unsigned long total = 0; - unsigned long total1 = 0; - ssize_t size = 0; - struct stat stat_buf = {0,}; - unsigned long record_len = 0; - int32_t len = 0; - - CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path); - - /* Open htime directory to get HTIME_CURRENT */ - ht_dir_fd = open (ht_dir_path, O_RDONLY); - if (ht_dir_fd == -1) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_OPEN_FAILED, "open failed", - "path=%s", ht_dir_path, - NULL); - ret = -1; - goto out; - } - - size = sys_fgetxattr (ht_dir_fd, HTIME_CURRENT, ht_file_bname, - sizeof (ht_file_bname)); - if (size < 0) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FGETXATTR_FAILED, "Error extracting" - " HTIME_CURRENT."); - - /* If upgrade scenario, find the latest HTIME.TSTAMP file - * and use the same. If error, create a new HTIME.TSTAMP - * file. - */ - cnt = find_current_htime (ht_dir_fd, ht_dir_path, - ht_file_bname); - if (cnt <= 0) { - gf_msg (this->name, GF_LOG_INFO, errno, - CHANGELOG_MSG_HTIME_INFO, - "HTIME_CURRENT not found. Changelog enabled" - " before init"); - sys_close (ht_dir_fd); - return htime_create (this, priv, ts); - } - - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_HTIME_ERROR, "Error extracting" - " HTIME_CURRENT."); - } - - gf_smsg (this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_HTIME_INFO, - "HTIME_CURRENT", - "path=%s", ht_file_bname, NULL); - len = snprintf (ht_file_path, PATH_MAX, "%s/%s", ht_dir_path, - ht_file_bname); - if ((len < 0) || (len >= PATH_MAX)) { - ret = -1; - goto out; - } - - /* Open in append mode as existing htime file is used */ - flags |= (O_RDWR | O_SYNC | O_APPEND); - ht_file_fd = open (ht_file_path, flags, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (ht_file_fd < 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_OPEN_FAILED, - "unable to open htime file", - "path=%s", ht_file_path, - NULL); - ret = -1; - goto out; - } - - /* save this htime_fd in priv->htime_fd */ - priv->htime_fd = ht_file_fd; - - ret = sys_fstat (ht_file_fd, &stat_buf); - if (ret < 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_HTIME_ERROR, - "unable to stat htime file", - "path=%s", ht_file_path, - NULL); - ret = -1; - goto out; - } - - /* Initialize rollover-number in priv to current number */ - size = sys_fgetxattr (ht_file_fd, HTIME_KEY, x_value, sizeof (x_value)); - if (size < 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FGETXATTR_FAILED, "error extracting max" - " timstamp from htime file", - "path=%s", ht_file_path, - NULL); - ret = -1; - goto out; - } - - sscanf (x_value, "%lu:%lu", &max_ts, &total); - - /* 22 = 1(/) + 20(CHANGELOG.TIMESTAMP) + 1(\x00) */ - record_len = strlen(priv->changelog_dir) + 22; - total1 = stat_buf.st_size/record_len; - if (total != total1) { - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_TOTAL_LOG_INFO, - "Mismatch of changelog count. " - "INIT CASE", - "xattr_total=%lu", total, - "size_total=%lu", total1, - NULL); - } - - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_TOTAL_LOG_INFO, - "INIT CASE", - "min=%lu", min_ts, - "max=%lu", max_ts, - "total_changelogs=%lu", total, - NULL); - - if (total < total1) - priv->rollover_count = total1 + 1; - else - priv->rollover_count = total + 1; + int ht_file_fd = -1; + int ht_dir_fd = -1; + int ret = 0; + int cnt = 0; + char ht_dir_path[PATH_MAX] = { + 0, + }; + char ht_file_path[PATH_MAX] = { + 0, + }; + char ht_file_bname[NAME_MAX] = { + 0, + }; + char x_value[NAME_MAX] = { + 0, + }; + int flags = 0; + unsigned long min_ts = 0; + unsigned long max_ts = 0; + unsigned long total = 0; + unsigned long total1 = 0; + ssize_t size = 0; + struct stat stat_buf = { + 0, + }; + unsigned long record_len = 0; + int32_t len = 0; + + CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path); + + /* Open htime directory to get HTIME_CURRENT */ + ht_dir_fd = open(ht_dir_path, O_RDONLY); + if (ht_dir_fd == -1) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED, + "open failed", "path=%s", ht_dir_path, NULL); + ret = -1; + goto out; + } + + size = sys_fgetxattr(ht_dir_fd, HTIME_CURRENT, ht_file_bname, + sizeof(ht_file_bname)); + if (size < 0) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FGETXATTR_FAILED, + "Error extracting" + " HTIME_CURRENT."); + + /* If upgrade scenario, find the latest HTIME.TSTAMP file + * and use the same. If error, create a new HTIME.TSTAMP + * file. + */ + cnt = find_current_htime(ht_dir_fd, ht_dir_path, ht_file_bname); + if (cnt <= 0) { + gf_msg(this->name, GF_LOG_INFO, errno, CHANGELOG_MSG_HTIME_INFO, + "HTIME_CURRENT not found. Changelog enabled" + " before init"); + sys_close(ht_dir_fd); + return htime_create(this, priv, ts); + } + + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_HTIME_ERROR, + "Error extracting" + " HTIME_CURRENT."); + } + + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_HTIME_INFO, + "HTIME_CURRENT", "path=%s", ht_file_bname, NULL); + len = snprintf(ht_file_path, PATH_MAX, "%s/%s", ht_dir_path, ht_file_bname); + if ((len < 0) || (len >= PATH_MAX)) { + ret = -1; + goto out; + } + + /* Open in append mode as existing htime file is used */ + flags |= (O_RDWR | O_SYNC | O_APPEND); + ht_file_fd = open(ht_file_path, flags, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (ht_file_fd < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED, + "unable to open htime file", "path=%s", ht_file_path, NULL); + ret = -1; + goto out; + } + + /* save this htime_fd in priv->htime_fd */ + priv->htime_fd = ht_file_fd; + + ret = sys_fstat(ht_file_fd, &stat_buf); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_HTIME_ERROR, + "unable to stat htime file", "path=%s", ht_file_path, NULL); + ret = -1; + goto out; + } + + /* Initialize rollover-number in priv to current number */ + size = sys_fgetxattr(ht_file_fd, HTIME_KEY, x_value, sizeof(x_value)); + if (size < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FGETXATTR_FAILED, + "error extracting max" + " timstamp from htime file", + "path=%s", ht_file_path, NULL); + ret = -1; + goto out; + } + + sscanf(x_value, "%lu:%lu", &max_ts, &total); + + /* 22 = 1(/) + 20(CHANGELOG.TIMESTAMP) + 1(\x00) */ + record_len = strlen(priv->changelog_dir) + 22; + total1 = stat_buf.st_size / record_len; + if (total != total1) { + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_TOTAL_LOG_INFO, + "Mismatch of changelog count. " + "INIT CASE", + "xattr_total=%lu", total, "size_total=%lu", total1, NULL); + } + + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_TOTAL_LOG_INFO, + "INIT CASE", "min=%lu", min_ts, "max=%lu", max_ts, + "total_changelogs=%lu", total, NULL); + + if (total < total1) + priv->rollover_count = total1 + 1; + else + priv->rollover_count = total + 1; out: - if (ht_dir_fd != -1) - sys_close (ht_dir_fd); - return ret; + if (ht_dir_fd != -1) + sys_close(ht_dir_fd); + return ret; } /* Returns 0 on successful creation of htime file * returns -1 on failure or error */ int -htime_create (xlator_t *this, - changelog_priv_t *priv, unsigned long ts) +htime_create(xlator_t *this, changelog_priv_t *priv, unsigned long ts) { - int ht_file_fd = -1; - int ht_dir_fd = -1; - int ret = 0; - char ht_dir_path[PATH_MAX] = {0,}; - char ht_file_path[PATH_MAX] = {0,}; - char ht_file_bname[NAME_MAX + 1] = {0,}; - int flags = 0; - int32_t len = 0; - - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_HTIME_INFO, "Changelog enable: Creating new " - "HTIME file", - "name=%lu", ts, - NULL); - - CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path); - - /* get the htime file name in ht_file_path */ - len = snprintf (ht_file_path, PATH_MAX, "%s/%s.%lu", ht_dir_path, - HTIME_FILE_NAME, ts); - if ((len < 0) || (len >= PATH_MAX)) { - ret = -1; - goto out; - } - - flags |= (O_CREAT | O_RDWR | O_SYNC); - ht_file_fd = open (ht_file_path, flags, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (ht_file_fd < 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_OPEN_FAILED, - "unable to create htime file", - "path=%s", ht_file_path, - NULL); - ret = -1; - goto out; - } - - if (sys_fsetxattr (ht_file_fd, HTIME_KEY, HTIME_INITIAL_VALUE, - sizeof (HTIME_INITIAL_VALUE)-1, 0)) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FSETXATTR_FAILED, - "Htime xattr initialization failed"); - ret = -1; - goto out; - } - - ret = sys_fsync (ht_file_fd); - if (ret < 0) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FSYNC_OP_FAILED, - "fsync failed"); - goto out; - } - - /* save this htime_fd in priv->htime_fd */ - priv->htime_fd = ht_file_fd; - - ht_file_fd = -1; - - /* Set xattr HTIME_CURRENT on htime directory to htime filename */ - ht_dir_fd = open (ht_dir_path, O_RDONLY); - if (ht_dir_fd == -1) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_OPEN_FAILED, "open failed", - "path=%s", ht_dir_path, - NULL); - ret = -1; - goto out; - } - - (void) snprintf (ht_file_bname, sizeof (ht_file_bname), "%s.%lu", - HTIME_FILE_NAME, ts); - if (sys_fsetxattr (ht_dir_fd, HTIME_CURRENT, ht_file_bname, - strlen (ht_file_bname), 0)) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FSETXATTR_FAILED, "fsetxattr failed:" - " HTIME_CURRENT"); - ret = -1; - goto out; - } - - ret = sys_fsync (ht_dir_fd); - if (ret < 0) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FSYNC_OP_FAILED, - "fsync failed"); - goto out; - } - - /* initialize rollover-number in priv to 1 */ - priv->rollover_count = 1; + int ht_file_fd = -1; + int ht_dir_fd = -1; + int ret = 0; + char ht_dir_path[PATH_MAX] = { + 0, + }; + char ht_file_path[PATH_MAX] = { + 0, + }; + char ht_file_bname[NAME_MAX + 1] = { + 0, + }; + int flags = 0; + int32_t len = 0; + + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_HTIME_INFO, + "Changelog enable: Creating new " + "HTIME file", + "name=%lu", ts, NULL); + + CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path); + + /* get the htime file name in ht_file_path */ + len = snprintf(ht_file_path, PATH_MAX, "%s/%s.%lu", ht_dir_path, + HTIME_FILE_NAME, ts); + if ((len < 0) || (len >= PATH_MAX)) { + ret = -1; + goto out; + } + + flags |= (O_CREAT | O_RDWR | O_SYNC); + ht_file_fd = open(ht_file_path, flags, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (ht_file_fd < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED, + "unable to create htime file", "path=%s", ht_file_path, NULL); + ret = -1; + goto out; + } + + if (sys_fsetxattr(ht_file_fd, HTIME_KEY, HTIME_INITIAL_VALUE, + sizeof(HTIME_INITIAL_VALUE) - 1, 0)) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSETXATTR_FAILED, + "Htime xattr initialization failed"); + ret = -1; + goto out; + } + + ret = sys_fsync(ht_file_fd); + if (ret < 0) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED, + "fsync failed"); + goto out; + } + + /* save this htime_fd in priv->htime_fd */ + priv->htime_fd = ht_file_fd; + + ht_file_fd = -1; + + /* Set xattr HTIME_CURRENT on htime directory to htime filename */ + ht_dir_fd = open(ht_dir_path, O_RDONLY); + if (ht_dir_fd == -1) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED, + "open failed", "path=%s", ht_dir_path, NULL); + ret = -1; + goto out; + } + + (void)snprintf(ht_file_bname, sizeof(ht_file_bname), "%s.%lu", + HTIME_FILE_NAME, ts); + if (sys_fsetxattr(ht_dir_fd, HTIME_CURRENT, ht_file_bname, + strlen(ht_file_bname), 0)) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSETXATTR_FAILED, + "fsetxattr failed:" + " HTIME_CURRENT"); + ret = -1; + goto out; + } + + ret = sys_fsync(ht_dir_fd); + if (ret < 0) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED, + "fsync failed"); + goto out; + } + + /* initialize rollover-number in priv to 1 */ + priv->rollover_count = 1; out: - if (ht_dir_fd != -1) - sys_close (ht_dir_fd); - if (ht_file_fd != -1) - sys_close (ht_file_fd); - return ret; + if (ht_dir_fd != -1) + sys_close(ht_dir_fd); + if (ht_file_fd != -1) + sys_close(ht_file_fd); + return ret; } /* Description: @@ -879,53 +843,53 @@ out: * -1 : On failure. */ int -changelog_snap_open (xlator_t *this, - changelog_priv_t *priv) +changelog_snap_open(xlator_t *this, changelog_priv_t *priv) { - int fd = -1; - int ret = 0; - int flags = 0; - char buffer[1024] = {0,}; - char c_snap_path[PATH_MAX] = {0,}; - char csnap_dir_path[PATH_MAX] = {0,}; - int32_t len = 0; - - CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir_path); - - len = snprintf (c_snap_path, PATH_MAX, "%s/"CSNAP_FILE_NAME, - csnap_dir_path); - if ((len < 0) || (len >= PATH_MAX)) { - ret = -1; - goto out; - } - - flags |= (O_CREAT | O_RDWR | O_TRUNC); - - fd = open (c_snap_path, flags, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (fd < 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_OPEN_FAILED, "unable to open file", - "path=%s", c_snap_path, - NULL); - ret = -1; - goto out; - } - priv->c_snap_fd = fd; - - (void) snprintf (buffer, 1024, CHANGELOG_HEADER, - CHANGELOG_VERSION_MAJOR, - CHANGELOG_VERSION_MINOR, - priv->ce->encoder); - ret = changelog_snap_write_change (priv, buffer, strlen (buffer)); - if (ret < 0) { - sys_close (priv->c_snap_fd); - priv->c_snap_fd = -1; - goto out; - } + int fd = -1; + int ret = 0; + int flags = 0; + char buffer[1024] = { + 0, + }; + char c_snap_path[PATH_MAX] = { + 0, + }; + char csnap_dir_path[PATH_MAX] = { + 0, + }; + int32_t len = 0; + + CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir_path); + + len = snprintf(c_snap_path, PATH_MAX, "%s/" CSNAP_FILE_NAME, + csnap_dir_path); + if ((len < 0) || (len >= PATH_MAX)) { + ret = -1; + goto out; + } + + flags |= (O_CREAT | O_RDWR | O_TRUNC); + + fd = open(c_snap_path, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (fd < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED, + "unable to open file", "path=%s", c_snap_path, NULL); + ret = -1; + goto out; + } + priv->c_snap_fd = fd; + + (void)snprintf(buffer, 1024, CHANGELOG_HEADER, CHANGELOG_VERSION_MAJOR, + CHANGELOG_VERSION_MINOR, priv->ce->encoder); + ret = changelog_snap_write_change(priv, buffer, strlen(buffer)); + if (ret < 0) { + sys_close(priv->c_snap_fd); + priv->c_snap_fd = -1; + goto out; + } out: - return ret; + return ret; } /* @@ -936,17 +900,15 @@ out: * -1 : On Failure. */ int -changelog_snap_logging_start (xlator_t *this, - changelog_priv_t *priv) +changelog_snap_logging_start(xlator_t *this, changelog_priv_t *priv) { - int ret = 0; + int ret = 0; - ret = changelog_snap_open (this, priv); - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_SNAP_INFO, - "Now starting to log in call path"); + ret = changelog_snap_open(this, priv); + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_SNAP_INFO, + "Now starting to log in call path"); - return ret; + return ret; } /* @@ -957,120 +919,116 @@ changelog_snap_logging_start (xlator_t *this, * -1 : On Failure. */ int -changelog_snap_logging_stop (xlator_t *this, - changelog_priv_t *priv) +changelog_snap_logging_stop(xlator_t *this, changelog_priv_t *priv) { - int ret = 0; + int ret = 0; - sys_close (priv->c_snap_fd); - priv->c_snap_fd = -1; + sys_close(priv->c_snap_fd); + priv->c_snap_fd = -1; - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_SNAP_INFO, - "Stopped to log in call path"); + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_SNAP_INFO, + "Stopped to log in call path"); - return ret; + return ret; } int -changelog_open_journal (xlator_t *this, - changelog_priv_t *priv) +changelog_open_journal(xlator_t *this, changelog_priv_t *priv) { - int fd = 0; - int ret = -1; - int flags = 0; - char buffer[1024] = {0,}; - char changelog_path[PATH_MAX] = {0,}; - - (void) snprintf (changelog_path, PATH_MAX, - "%s/"CHANGELOG_FILE_NAME, - priv->changelog_dir); - - flags |= (O_CREAT | O_RDWR); - if (priv->fsync_interval == 0) - flags |= O_SYNC; - - fd = open (changelog_path, flags, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (fd < 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_OPEN_FAILED, - "unable to open/create changelog file." - " change-logging will be" - " inactive", - "path=%s", changelog_path, - NULL); - goto out; - } + int fd = 0; + int ret = -1; + int flags = 0; + char buffer[1024] = { + 0, + }; + char changelog_path[PATH_MAX] = { + 0, + }; + + (void)snprintf(changelog_path, PATH_MAX, "%s/" CHANGELOG_FILE_NAME, + priv->changelog_dir); + + flags |= (O_CREAT | O_RDWR); + if (priv->fsync_interval == 0) + flags |= O_SYNC; + + fd = open(changelog_path, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (fd < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED, + "unable to open/create changelog file." + " change-logging will be" + " inactive", + "path=%s", changelog_path, NULL); + goto out; + } + + priv->changelog_fd = fd; + + (void)snprintf(buffer, 1024, CHANGELOG_HEADER, CHANGELOG_VERSION_MAJOR, + CHANGELOG_VERSION_MINOR, priv->ce->encoder); + ret = changelog_write_change(priv, buffer, strlen(buffer)); + if (ret) { + sys_close(priv->changelog_fd); + priv->changelog_fd = -1; + goto out; + } + + ret = 0; - priv->changelog_fd = fd; - - (void) snprintf (buffer, 1024, CHANGELOG_HEADER, - CHANGELOG_VERSION_MAJOR, - CHANGELOG_VERSION_MINOR, - priv->ce->encoder); - ret = changelog_write_change (priv, buffer, strlen (buffer)); - if (ret) { - sys_close (priv->changelog_fd); - priv->changelog_fd = -1; - goto out; - } - - ret = 0; - - out: - return ret; +out: + return ret; } int -changelog_start_next_change (xlator_t *this, - changelog_priv_t *priv, - unsigned long ts, gf_boolean_t finale) +changelog_start_next_change(xlator_t *this, changelog_priv_t *priv, + unsigned long ts, gf_boolean_t finale) { - int ret = -1; + int ret = -1; - ret = changelog_rollover_changelog (this, priv, ts); + ret = changelog_rollover_changelog(this, priv, ts); - if (!ret && !finale) - ret = changelog_open_journal (this, priv); + if (!ret && !finale) + ret = changelog_open_journal(this, priv); - return ret; + return ret; } /** * return the length of entry */ size_t -changelog_entry_length () +changelog_entry_length() { - return sizeof (changelog_log_data_t); + return sizeof(changelog_log_data_t); } int -changelog_fill_rollover_data (changelog_log_data_t *cld, gf_boolean_t is_last) +changelog_fill_rollover_data(changelog_log_data_t *cld, gf_boolean_t is_last) { - struct timeval tv = {0,}; + struct timeval tv = { + 0, + }; - cld->cld_type = CHANGELOG_TYPE_ROLLOVER; + cld->cld_type = CHANGELOG_TYPE_ROLLOVER; - if (gettimeofday (&tv, NULL)) - return -1; + if (gettimeofday(&tv, NULL)) + return -1; - cld->cld_roll_time = (unsigned long) tv.tv_sec; - cld->cld_finale = is_last; - return 0; + cld->cld_roll_time = (unsigned long)tv.tv_sec; + cld->cld_finale = is_last; + return 0; } int -changelog_snap_write_change (changelog_priv_t *priv, char *buffer, size_t len) +changelog_snap_write_change(changelog_priv_t *priv, char *buffer, size_t len) { - return changelog_write (priv->c_snap_fd, buffer, len); + return changelog_write(priv->c_snap_fd, buffer, len); } int -changelog_write_change (changelog_priv_t *priv, char *buffer, size_t len) +changelog_write_change(changelog_priv_t *priv, char *buffer, size_t len) { - return changelog_write (priv->changelog_fd, buffer, len); + return changelog_write(priv->changelog_fd, buffer, len); } /* @@ -1083,255 +1041,231 @@ changelog_write_change (changelog_priv_t *priv, char *buffer, size_t len) * -1 : On Failure. */ int -changelog_snap_handle_ascii_change (xlator_t *this, - changelog_log_data_t *cld) +changelog_snap_handle_ascii_change(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; - int ret = 0; - - if (this == NULL) { - ret = -1; - goto out; - } - - priv = this->private; - - if (priv == NULL) { - ret = -1; - goto out; - } - - gfid_str = uuid_utoa (cld->cld_gfid); - gfid_len = strlen (gfid_str); - - /* extra bytes for decorations */ - buffer = alloca (gfid_len + cld->cld_ptr_len + 10); - CHANGELOG_STORE_ASCII (priv, buffer, - off, gfid_str, gfid_len, cld); - - CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1); - - ret = changelog_snap_write_change (priv, buffer, off); - - if (ret < 0) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_WRITE_FAILED, - "error writing csnap to disk"); - } - gf_msg (this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_SNAP_INFO, - "Successfully wrote to csnap"); - ret = 0; + size_t off = 0; + size_t gfid_len = 0; + char *gfid_str = NULL; + char *buffer = NULL; + changelog_priv_t *priv = NULL; + int ret = 0; + + if (this == NULL) { + ret = -1; + goto out; + } + + priv = this->private; + + if (priv == NULL) { + ret = -1; + goto out; + } + + gfid_str = uuid_utoa(cld->cld_gfid); + gfid_len = strlen(gfid_str); + + /* extra bytes for decorations */ + buffer = alloca(gfid_len + cld->cld_ptr_len + 10); + CHANGELOG_STORE_ASCII(priv, buffer, off, gfid_str, gfid_len, cld); + + CHANGELOG_FILL_BUFFER(buffer, off, "\0", 1); + + ret = changelog_snap_write_change(priv, buffer, off); + + if (ret < 0) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_WRITE_FAILED, + "error writing csnap to disk"); + } + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_SNAP_INFO, + "Successfully wrote to csnap"); + ret = 0; out: - return ret; + return ret; } int -changelog_handle_change (xlator_t *this, - changelog_priv_t *priv, changelog_log_data_t *cld) +changelog_handle_change(xlator_t *this, changelog_priv_t *priv, + changelog_log_data_t *cld) { - int ret = 0; - - if (CHANGELOG_TYPE_IS_ROLLOVER (cld->cld_type)) { - changelog_encode_change (priv); - ret = changelog_start_next_change (this, priv, - cld->cld_roll_time, - cld->cld_finale); - if (ret) - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_GET_TIME_OP_FAILED, - "Problem rolling over changelog(s)"); - goto out; - } + int ret = 0; - /** - * case when there is reconfigure done (disabling changelog) and there - * are still fops that have updates in prgress. - */ - if (priv->changelog_fd == -1) - return 0; - - if (CHANGELOG_TYPE_IS_FSYNC (cld->cld_type)) { - ret = sys_fsync (priv->changelog_fd); - if (ret < 0) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_FSYNC_OP_FAILED, - "fsync failed"); - } - goto out; - } + if (CHANGELOG_TYPE_IS_ROLLOVER(cld->cld_type)) { + changelog_encode_change(priv); + ret = changelog_start_next_change(this, priv, cld->cld_roll_time, + cld->cld_finale); + if (ret) + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_GET_TIME_OP_FAILED, + "Problem rolling over changelog(s)"); + goto out; + } + + /** + * case when there is reconfigure done (disabling changelog) and there + * are still fops that have updates in prgress. + */ + if (priv->changelog_fd == -1) + return 0; - ret = priv->ce->encode (this, cld); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_WRITE_FAILED, - "error writing changelog to disk"); + if (CHANGELOG_TYPE_IS_FSYNC(cld->cld_type)) { + ret = sys_fsync(priv->changelog_fd); + if (ret < 0) { + gf_msg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_FSYNC_OP_FAILED, "fsync failed"); } + goto out; + } - out: - return ret; + ret = priv->ce->encode(this, cld); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_WRITE_FAILED, + "error writing changelog to disk"); + } + +out: + return ret; } changelog_local_t * -changelog_local_init (xlator_t *this, inode_t *inode, - uuid_t gfid, int xtra_records, - gf_boolean_t update_flag) +changelog_local_init(xlator_t *this, inode_t *inode, uuid_t gfid, + int xtra_records, gf_boolean_t update_flag) { - changelog_local_t *local = NULL; - struct iobuf *iobuf = NULL; - - /** - * We relax the presence of inode if @update_flag is true. - * The caller (implementation of the fop) needs to be careful to - * not blindly use local->inode. - */ - if (!update_flag && !inode) { - gf_msg_callingfn (this->name, GF_LOG_WARNING, 0, - CHANGELOG_MSG_INODE_NOT_FOUND, - "inode needed for version checking !!!"); - goto out; - } + changelog_local_t *local = NULL; + struct iobuf *iobuf = NULL; + + /** + * We relax the presence of inode if @update_flag is true. + * The caller (implementation of the fop) needs to be careful to + * not blindly use local->inode. + */ + if (!update_flag && !inode) { + gf_msg_callingfn(this->name, GF_LOG_WARNING, 0, + CHANGELOG_MSG_INODE_NOT_FOUND, + "inode needed for version checking !!!"); + goto out; + } - if (xtra_records) { - iobuf = iobuf_get2 (this->ctx->iobuf_pool, - xtra_records * CHANGELOG_OPT_RECORD_LEN); - if (!iobuf) - goto out; - } + if (xtra_records) { + iobuf = iobuf_get2(this->ctx->iobuf_pool, + xtra_records * CHANGELOG_OPT_RECORD_LEN); + if (!iobuf) + goto out; + } - local = mem_get0 (this->local_pool); - if (!local) { - CHANGELOG_IOBUF_UNREF (iobuf); - goto out; - } + local = mem_get0(this->local_pool); + if (!local) { + CHANGELOG_IOBUF_UNREF(iobuf); + goto out; + } - local->update_no_check = update_flag; + local->update_no_check = update_flag; - gf_uuid_copy (local->cld.cld_gfid, gfid); + gf_uuid_copy(local->cld.cld_gfid, gfid); - local->cld.cld_iobuf = iobuf; - local->cld.cld_xtra_records = 0; /* set by the caller */ + local->cld.cld_iobuf = iobuf; + local->cld.cld_xtra_records = 0; /* set by the caller */ - if (inode) - local->inode = inode_ref (inode); + if (inode) + local->inode = inode_ref(inode); - out: - return local; +out: + return local; } int -changelog_forget (xlator_t *this, inode_t *inode) +changelog_forget(xlator_t *this, inode_t *inode) { - uint64_t ctx_addr = 0; - changelog_inode_ctx_t *ctx = NULL; + uint64_t ctx_addr = 0; + changelog_inode_ctx_t *ctx = NULL; - inode_ctx_del (inode, this, &ctx_addr); - if (!ctx_addr) - return 0; + inode_ctx_del(inode, this, &ctx_addr); + if (!ctx_addr) + return 0; - ctx = (changelog_inode_ctx_t *) (long) ctx_addr; - GF_FREE (ctx); + ctx = (changelog_inode_ctx_t *)(long)ctx_addr; + GF_FREE(ctx); - return 0; + return 0; } int -changelog_inject_single_event (xlator_t *this, - changelog_priv_t *priv, - changelog_log_data_t *cld) +changelog_inject_single_event(xlator_t *this, changelog_priv_t *priv, + changelog_log_data_t *cld) { - return priv->cd.dispatchfn (this, priv, priv->cd.cd_data, cld, NULL); + return priv->cd.dispatchfn(this, priv, priv->cd.cd_data, cld, NULL); } /* Wait till all the black fops are drained */ void -changelog_drain_black_fops (xlator_t *this, changelog_priv_t *priv) +changelog_drain_black_fops(xlator_t *this, changelog_priv_t *priv) { - int ret = 0; - - /* clean up framework of pthread_mutex is required here as - * 'reconfigure' terminates the changelog_rollover thread - * on graph change. - */ - pthread_cleanup_push (changelog_cleanup_free_mutex, - &priv->dm.drain_black_mutex); - ret = pthread_mutex_lock (&priv->dm.drain_black_mutex); - if (ret) - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_ERROR, "pthread error", - "error=%d", ret, - NULL); - while (priv->dm.black_fop_cnt > 0) { - gf_msg_debug (this->name, 0, - "Conditional wait on black fops: %ld", - priv->dm.black_fop_cnt); - priv->dm.drain_wait_black = _gf_true; - ret = pthread_cond_wait (&priv->dm.drain_black_cond, - &priv->dm.drain_black_mutex); - if (ret) - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED, - "pthread cond wait failed", - "error=%d", ret, - NULL); - } - priv->dm.drain_wait_black = _gf_false; - ret = pthread_mutex_unlock (&priv->dm.drain_black_mutex); + int ret = 0; + + /* clean up framework of pthread_mutex is required here as + * 'reconfigure' terminates the changelog_rollover thread + * on graph change. + */ + pthread_cleanup_push(changelog_cleanup_free_mutex, + &priv->dm.drain_black_mutex); + ret = pthread_mutex_lock(&priv->dm.drain_black_mutex); + if (ret) + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_PTHREAD_ERROR, + "pthread error", "error=%d", ret, NULL); + while (priv->dm.black_fop_cnt > 0) { + gf_msg_debug(this->name, 0, "Conditional wait on black fops: %ld", + priv->dm.black_fop_cnt); + priv->dm.drain_wait_black = _gf_true; + ret = pthread_cond_wait(&priv->dm.drain_black_cond, + &priv->dm.drain_black_mutex); if (ret) - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_ERROR, "pthread error", - "error=%d", ret, - NULL); - pthread_cleanup_pop (0); - gf_msg_debug (this->name, 0, - "Woke up: Conditional wait on black fops"); + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED, + "pthread cond wait failed", "error=%d", ret, NULL); + } + priv->dm.drain_wait_black = _gf_false; + ret = pthread_mutex_unlock(&priv->dm.drain_black_mutex); + if (ret) + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_PTHREAD_ERROR, + "pthread error", "error=%d", ret, NULL); + pthread_cleanup_pop(0); + gf_msg_debug(this->name, 0, "Woke up: Conditional wait on black fops"); } /* Wait till all the white fops are drained */ void -changelog_drain_white_fops (xlator_t *this, changelog_priv_t *priv) +changelog_drain_white_fops(xlator_t *this, changelog_priv_t *priv) { - int ret = 0; - - /* clean up framework of pthread_mutex is required here as - * 'reconfigure' terminates the changelog_rollover thread - * on graph change. - */ - pthread_cleanup_push (changelog_cleanup_free_mutex, - &priv->dm.drain_white_mutex); - ret = pthread_mutex_lock (&priv->dm.drain_white_mutex); + int ret = 0; + + /* clean up framework of pthread_mutex is required here as + * 'reconfigure' terminates the changelog_rollover thread + * on graph change. + */ + pthread_cleanup_push(changelog_cleanup_free_mutex, + &priv->dm.drain_white_mutex); + ret = pthread_mutex_lock(&priv->dm.drain_white_mutex); + if (ret) + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_PTHREAD_ERROR, + "pthread error", "error=%d", ret, NULL); + while (priv->dm.white_fop_cnt > 0) { + gf_msg_debug(this->name, 0, "Conditional wait on white fops : %ld", + priv->dm.white_fop_cnt); + priv->dm.drain_wait_white = _gf_true; + ret = pthread_cond_wait(&priv->dm.drain_white_cond, + &priv->dm.drain_white_mutex); if (ret) - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_ERROR, "pthread error", - "error=%d", ret, - NULL); - while (priv->dm.white_fop_cnt > 0) { - gf_msg_debug (this->name, 0, - "Conditional wait on white fops : %ld", - priv->dm.white_fop_cnt); - priv->dm.drain_wait_white = _gf_true; - ret = pthread_cond_wait (&priv->dm.drain_white_cond, - &priv->dm.drain_white_mutex); - if (ret) - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED, - "pthread cond wait failed", - "error=%d", ret, - NULL); - } - priv->dm.drain_wait_white = _gf_false; - ret = pthread_mutex_unlock (&priv->dm.drain_white_mutex); - if (ret) - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_ERROR, "pthread error", - "error=%d", ret, - NULL); - pthread_cleanup_pop (0); - gf_msg_debug (this->name, 0, - "Woke up: Conditional wait on white fops"); + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED, + "pthread cond wait failed", "error=%d", ret, NULL); + } + priv->dm.drain_wait_white = _gf_false; + ret = pthread_mutex_unlock(&priv->dm.drain_white_mutex); + if (ret) + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_PTHREAD_ERROR, + "pthread error", "error=%d", ret, NULL); + pthread_cleanup_pop(0); + gf_msg_debug(this->name, 0, "Woke up: Conditional wait on white fops"); } /** @@ -1339,193 +1273,201 @@ changelog_drain_white_fops (xlator_t *this, changelog_priv_t *priv) * a certain time etc..). move them into separate routine. */ void * -changelog_rollover (void *data) +changelog_rollover(void *data) { - int ret = 0; - xlator_t *this = NULL; - struct timespec tv = {0,}; - changelog_log_data_t cld = {0,}; - changelog_time_slice_t *slice = NULL; - changelog_priv_t *priv = data; - - this = priv->cr.this; - slice = &priv->slice; - - while (1) { - (void) pthread_testcancel(); - - tv.tv_sec = time (NULL) + priv->rollover_time; - tv.tv_nsec = 0; - ret = 0; /* Reset ret to zero */ - - /* The race between actual rollover and explicit rollover is - * handled. If actual rollover is being done and the - * explicit rollover event comes, the event is not missed. - * Since explicit rollover sets 'cr.notify' to true, this - * thread doesn't wait on 'pthread_cond_timedwait'. - */ - pthread_cleanup_push (changelog_cleanup_free_mutex, - &priv->cr.lock); - pthread_mutex_lock (&priv->cr.lock); - { - while (ret == 0 && !priv->cr.notify) - ret = pthread_cond_timedwait (&priv->cr.cond, - &priv->cr.lock, - &tv); - if (ret == 0) - priv->cr.notify = _gf_false; - } - pthread_mutex_unlock (&priv->cr.lock); - pthread_cleanup_pop (0); - - if (ret == 0) { - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BARRIER_INFO, - "Explicit wakeup on barrier notify"); - priv->explicit_rollover = _gf_true; - } else if (ret && ret != ETIMEDOUT) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_SELECT_FAILED, - "pthread_cond_timedwait failed"); - continue; - } else if (ret && ret == ETIMEDOUT) { - gf_msg_debug (this->name, 0, "Wokeup on timeout"); - } - - /* Reading curent_color without lock is fine here - * as it is only modified here and is next to reading. - */ - if (priv->current_color == FOP_COLOR_BLACK) { - LOCK(&priv->lock); - priv->current_color = FOP_COLOR_WHITE; - UNLOCK(&priv->lock); - gf_msg_debug (this->name, 0, "Black fops" - " to be drained:%ld", - priv->dm.black_fop_cnt); - changelog_drain_black_fops (this, priv); - } else { - LOCK(&priv->lock); - priv->current_color = FOP_COLOR_BLACK; - UNLOCK(&priv->lock); - gf_msg_debug (this->name, 0, "White fops" - " to be drained:%ld", - priv->dm.white_fop_cnt); - changelog_drain_white_fops (this, priv); - } - - /* Adding delay of 1 second only during explicit rollover: - * - * Changelog rollover can happen either due to actual - * or the explicit rollover during snapshot. Actual - * rollover is controlled by tuneable called 'rollover-time'. - * The minimum granularity for rollover-time is 1 second. - * Explicit rollover is asynchronous in nature and happens - * during snapshot. - * - * Basically, rollover renames the current CHANGELOG file - * to CHANGELOG.TIMESTAMP. Let's assume, at time 't1', - * actual and explicit rollover raced against each - * other and actual rollover won the race renaming the - * CHANGELOG file to CHANGELOG.t1 and opens a new - * CHANGELOG file. There is high chance that, an immediate - * explicit rollover at time 't1' can happen with in the same - * second to rename CHANGELOG file to CHANGELOG.t1 resulting in - * purging the earlier CHANGELOG.t1 file created by actual - * rollover. So adding a delay of 1 second guarantees unique - * CHANGELOG.TIMESTAMP during explicit rollover. - */ - if (priv->explicit_rollover == _gf_true) - sleep (1); - - ret = changelog_fill_rollover_data (&cld, _gf_false); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_GET_TIME_OP_FAILED, - "failed to fill rollover data"); - continue; - } + int ret = 0; + xlator_t *this = NULL; + struct timespec tv = { + 0, + }; + changelog_log_data_t cld = { + 0, + }; + changelog_time_slice_t *slice = NULL; + changelog_priv_t *priv = data; + + this = priv->cr.this; + slice = &priv->slice; + + while (1) { + (void)pthread_testcancel(); + + tv.tv_sec = time(NULL) + priv->rollover_time; + tv.tv_nsec = 0; + ret = 0; /* Reset ret to zero */ + + /* The race between actual rollover and explicit rollover is + * handled. If actual rollover is being done and the + * explicit rollover event comes, the event is not missed. + * Since explicit rollover sets 'cr.notify' to true, this + * thread doesn't wait on 'pthread_cond_timedwait'. + */ + pthread_cleanup_push(changelog_cleanup_free_mutex, &priv->cr.lock); + pthread_mutex_lock(&priv->cr.lock); + { + while (ret == 0 && !priv->cr.notify) + ret = pthread_cond_timedwait(&priv->cr.cond, &priv->cr.lock, + &tv); + if (ret == 0) + priv->cr.notify = _gf_false; + } + pthread_mutex_unlock(&priv->cr.lock); + pthread_cleanup_pop(0); + + if (ret == 0) { + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO, + "Explicit wakeup on barrier notify"); + priv->explicit_rollover = _gf_true; + } else if (ret && ret != ETIMEDOUT) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_SELECT_FAILED, + "pthread_cond_timedwait failed"); + continue; + } else if (ret && ret == ETIMEDOUT) { + gf_msg_debug(this->name, 0, "Wokeup on timeout"); + } + + /* Reading curent_color without lock is fine here + * as it is only modified here and is next to reading. + */ + if (priv->current_color == FOP_COLOR_BLACK) { + LOCK(&priv->lock); + priv->current_color = FOP_COLOR_WHITE; + UNLOCK(&priv->lock); + gf_msg_debug(this->name, 0, + "Black fops" + " to be drained:%ld", + priv->dm.black_fop_cnt); + changelog_drain_black_fops(this, priv); + } else { + LOCK(&priv->lock); + priv->current_color = FOP_COLOR_BLACK; + UNLOCK(&priv->lock); + gf_msg_debug(this->name, 0, + "White fops" + " to be drained:%ld", + priv->dm.white_fop_cnt); + changelog_drain_white_fops(this, priv); + } + + /* Adding delay of 1 second only during explicit rollover: + * + * Changelog rollover can happen either due to actual + * or the explicit rollover during snapshot. Actual + * rollover is controlled by tuneable called 'rollover-time'. + * The minimum granularity for rollover-time is 1 second. + * Explicit rollover is asynchronous in nature and happens + * during snapshot. + * + * Basically, rollover renames the current CHANGELOG file + * to CHANGELOG.TIMESTAMP. Let's assume, at time 't1', + * actual and explicit rollover raced against each + * other and actual rollover won the race renaming the + * CHANGELOG file to CHANGELOG.t1 and opens a new + * CHANGELOG file. There is high chance that, an immediate + * explicit rollover at time 't1' can happen with in the same + * second to rename CHANGELOG file to CHANGELOG.t1 resulting in + * purging the earlier CHANGELOG.t1 file created by actual + * rollover. So adding a delay of 1 second guarantees unique + * CHANGELOG.TIMESTAMP during explicit rollover. + */ + if (priv->explicit_rollover == _gf_true) + sleep(1); - _mask_cancellation (); + ret = changelog_fill_rollover_data(&cld, _gf_false); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_GET_TIME_OP_FAILED, + "failed to fill rollover data"); + continue; + } - LOCK (&priv->lock); - { - ret = changelog_inject_single_event (this, priv, &cld); - if (!ret) - SLICE_VERSION_UPDATE (slice); - } - UNLOCK (&priv->lock); + _mask_cancellation(); - _unmask_cancellation (); + LOCK(&priv->lock); + { + ret = changelog_inject_single_event(this, priv, &cld); + if (!ret) + SLICE_VERSION_UPDATE(slice); } + UNLOCK(&priv->lock); - return NULL; + _unmask_cancellation(); + } + + return NULL; } void * -changelog_fsync_thread (void *data) +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) { - (void) pthread_testcancel(); - - tv.tv_sec = priv->fsync_interval; - tv.tv_usec = 0; - - ret = select (0, NULL, NULL, NULL, &tv); - if (ret) - continue; + 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) { + (void)pthread_testcancel(); + + tv.tv_sec = priv->fsync_interval; + tv.tv_usec = 0; + + ret = select(0, NULL, NULL, NULL, &tv); + if (ret) + continue; - _mask_cancellation (); + _mask_cancellation(); - ret = changelog_inject_single_event (this, priv, &cld); - if (ret) - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_INJECT_FSYNC_FAILED, - "failed to inject fsync event"); + ret = changelog_inject_single_event(this, priv, &cld); + if (ret) + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_INJECT_FSYNC_FAILED, + "failed to inject fsync event"); - _unmask_cancellation (); - } + _unmask_cancellation(); + } - return NULL; + return NULL; } /* macros for inode/changelog version checks */ -#define INODE_VERSION_UPDATE(priv, inode, iver, slice, type) do { \ - LOCK (&inode->lock); \ - { \ - LOCK (&priv->lock); \ - { \ - *iver = slice->changelog_version[type]; \ - } \ - UNLOCK (&priv->lock); \ - } \ - UNLOCK (&inode->lock); \ - } while (0) - -#define INODE_VERSION_EQUALS_SLICE(priv, ver, slice, type, upd) do { \ - LOCK (&priv->lock); \ - { \ - upd = (ver == slice->changelog_version[type]) \ - ? _gf_false : _gf_true; \ - } \ - UNLOCK (&priv->lock); \ - } while (0) +#define INODE_VERSION_UPDATE(priv, inode, iver, slice, type) \ + do { \ + LOCK(&inode->lock); \ + { \ + LOCK(&priv->lock); \ + { \ + *iver = slice->changelog_version[type]; \ + } \ + UNLOCK(&priv->lock); \ + } \ + UNLOCK(&inode->lock); \ + } while (0) + +#define INODE_VERSION_EQUALS_SLICE(priv, ver, slice, type, upd) \ + do { \ + LOCK(&priv->lock); \ + { \ + upd = (ver == slice->changelog_version[type]) ? _gf_false \ + : _gf_true; \ + } \ + UNLOCK(&priv->lock); \ + } while (0) static int -__changelog_inode_ctx_set (xlator_t *this, - inode_t *inode, changelog_inode_ctx_t *ctx) +__changelog_inode_ctx_set(xlator_t *this, inode_t *inode, + changelog_inode_ctx_t *ctx) { - uint64_t ctx_addr = (uint64_t) ctx; - return __inode_ctx_set (inode, this, &ctx_addr); + uint64_t ctx_addr = (uint64_t)ctx; + return __inode_ctx_set(inode, this, &ctx_addr); } /** @@ -1533,56 +1475,53 @@ __changelog_inode_ctx_set (xlator_t *this, * for a particular type. */ changelog_inode_ctx_t * -__changelog_inode_ctx_get (xlator_t *this, - inode_t *inode, unsigned long **iver, - unsigned long *version, changelog_log_type type) +__changelog_inode_ctx_get(xlator_t *this, inode_t *inode, unsigned long **iver, + unsigned long *version, changelog_log_type type) { - int ret = 0; - uint64_t ctx_addr = 0; - changelog_inode_ctx_t *ctx = NULL; - - ret = __inode_ctx_get (inode, this, &ctx_addr); - if (ret < 0) - ctx_addr = 0; - if (ctx_addr != 0) { - ctx = (changelog_inode_ctx_t *) (long)ctx_addr; - goto out; - } - - ctx = GF_CALLOC (1, sizeof (*ctx), gf_changelog_mt_inode_ctx_t); - if (!ctx) - goto out; + int ret = 0; + uint64_t ctx_addr = 0; + changelog_inode_ctx_t *ctx = NULL; + + ret = __inode_ctx_get(inode, this, &ctx_addr); + if (ret < 0) + ctx_addr = 0; + if (ctx_addr != 0) { + ctx = (changelog_inode_ctx_t *)(long)ctx_addr; + goto out; + } + + ctx = GF_CALLOC(1, sizeof(*ctx), gf_changelog_mt_inode_ctx_t); + if (!ctx) + goto out; + + ret = __changelog_inode_ctx_set(this, inode, ctx); + if (ret) { + GF_FREE(ctx); + ctx = NULL; + } - ret = __changelog_inode_ctx_set (this, inode, ctx); - if (ret) { - GF_FREE (ctx); - ctx = NULL; - } - - out: - if (ctx && iver && version) { - *iver = CHANGELOG_INODE_VERSION_TYPE (ctx, type); - *version = **iver; - } +out: + if (ctx && iver && version) { + *iver = CHANGELOG_INODE_VERSION_TYPE(ctx, type); + *version = **iver; + } - return ctx; + return ctx; } static changelog_inode_ctx_t * -changelog_inode_ctx_get (xlator_t *this, - inode_t *inode, unsigned long **iver, - unsigned long *version, changelog_log_type type) +changelog_inode_ctx_get(xlator_t *this, inode_t *inode, unsigned long **iver, + unsigned long *version, changelog_log_type type) { - changelog_inode_ctx_t *ctx = NULL; + changelog_inode_ctx_t *ctx = NULL; - LOCK (&inode->lock); - { - ctx = __changelog_inode_ctx_get (this, - inode, iver, version, type); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + ctx = __changelog_inode_ctx_get(this, inode, iver, version, type); + } + UNLOCK(&inode->lock); - return ctx; + return ctx; } /** @@ -1686,59 +1625,57 @@ changelog_inode_ctx_get (xlator_t *this, * signifies an update was recorded in the current time slice). */ 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; - changelog_log_data_t *cld_1 = NULL; - changelog_local_t *next_local = NULL; - gf_boolean_t need_upd = _gf_true; - - slice = &priv->slice; - - /** - * for fops that do not require inode version checking - */ - if (local->update_no_check) - goto update; + 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; - inode = local->inode; + slice = &priv->slice; - ctx = changelog_inode_ctx_get (this, - inode, &iver, &version, type); - if (!ctx) - goto update; + /** + * for fops that do not require inode version checking + */ + if (local->update_no_check) + goto update; - INODE_VERSION_EQUALS_SLICE (priv, version, slice, type, need_upd); + inode = local->inode; - update: - if (need_upd) { - cld_0 = &local->cld; - cld_0->cld_type = type; + ctx = changelog_inode_ctx_get(this, inode, &iver, &version, type); + if (!ctx) + goto update; - if ( (next_local = local->prev_entry) != NULL ) { - cld_1 = &next_local->cld; - cld_1->cld_type = type; - } + INODE_VERSION_EQUALS_SLICE(priv, version, slice, type, need_upd); - ret = priv->cd.dispatchfn (this, priv, - priv->cd.cd_data, cld_0, cld_1); +update: + if (need_upd) { + cld_0 = &local->cld; + cld_0->cld_type = type; - /** - * update after the dispatcher has successfully done - * it's job. - */ - if (!local->update_no_check && iver && !ret) - INODE_VERSION_UPDATE (priv, inode, iver, slice, type); + if ((next_local = local->prev_entry) != NULL) { + cld_1 = &next_local->cld; + cld_1->cld_type = type; } - return; + ret = priv->cd.dispatchfn(this, priv, priv->cd.cd_data, cld_0, cld_1); + + /** + * update after the dispatcher has successfully done + * it's job. + */ + if (!local->update_no_check && iver && !ret) + INODE_VERSION_UPDATE(priv, inode, iver, slice, type); + } + + return; } /* Begin: Geo-rep snapshot dependency changes */ @@ -1754,230 +1691,223 @@ changelog_update (xlator_t *this, changelog_priv_t *priv, */ void -changelog_color_fop_and_inc_cnt (xlator_t *this, changelog_priv_t *priv, - changelog_local_t *local) +changelog_color_fop_and_inc_cnt(xlator_t *this, changelog_priv_t *priv, + changelog_local_t *local) { - if (!priv || !local) - return; + if (!priv || !local) + return; - LOCK (&priv->lock); - { - local->color = priv->current_color; - changelog_inc_fop_cnt (this, priv, local); - } - UNLOCK (&priv->lock); + LOCK(&priv->lock); + { + local->color = priv->current_color; + changelog_inc_fop_cnt(this, priv, local); + } + UNLOCK(&priv->lock); } /* Increments the respective fop counter based on the fop color */ void -changelog_inc_fop_cnt (xlator_t *this, changelog_priv_t *priv, - changelog_local_t *local) +changelog_inc_fop_cnt(xlator_t *this, changelog_priv_t *priv, + changelog_local_t *local) { - int ret = 0; - - if (local) { - if (local->color == FOP_COLOR_BLACK) { - ret = pthread_mutex_lock (&priv->dm.drain_black_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - { - priv->dm.black_fop_cnt++; - } - ret = pthread_mutex_unlock(&priv->dm.drain_black_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - } else { - ret = pthread_mutex_lock (&priv->dm.drain_white_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - { - priv->dm.white_fop_cnt++; - } - ret = pthread_mutex_unlock(&priv->dm.drain_white_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - } - } - out: - return; + int ret = 0; + + if (local) { + if (local->color == FOP_COLOR_BLACK) { + ret = pthread_mutex_lock(&priv->dm.drain_black_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out); + { + priv->dm.black_fop_cnt++; + } + ret = pthread_mutex_unlock(&priv->dm.drain_black_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out); + } else { + ret = pthread_mutex_lock(&priv->dm.drain_white_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out); + { + priv->dm.white_fop_cnt++; + } + ret = pthread_mutex_unlock(&priv->dm.drain_white_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out); + } + } +out: + return; } /* Decrements the respective fop counter based on the fop color */ void -changelog_dec_fop_cnt (xlator_t *this, changelog_priv_t *priv, - changelog_local_t *local) +changelog_dec_fop_cnt(xlator_t *this, changelog_priv_t *priv, + changelog_local_t *local) { - int ret = 0; - - if (local) { - if (local->color == FOP_COLOR_BLACK) { - ret = pthread_mutex_lock (&priv->dm.drain_black_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - { - priv->dm.black_fop_cnt--; - if (priv->dm.black_fop_cnt == 0 && - priv->dm.drain_wait_black == _gf_true) { - ret = pthread_cond_signal ( - &priv->dm.drain_black_cond); - CHANGELOG_PTHREAD_ERROR_HANDLE_2 (ret, - out, - priv->dm.drain_black_mutex); - gf_msg_debug (this->name, 0, - "Signalled " - "draining of black"); - } - } - ret = pthread_mutex_unlock(&priv->dm.drain_black_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - } else { - ret = pthread_mutex_lock (&priv->dm.drain_white_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - { - priv->dm.white_fop_cnt--; - if (priv->dm.white_fop_cnt == 0 && - priv->dm.drain_wait_white == _gf_true) { - ret = pthread_cond_signal ( - &priv->dm.drain_white_cond); - CHANGELOG_PTHREAD_ERROR_HANDLE_2 (ret, - out, - priv->dm.drain_white_mutex); - gf_msg_debug (this->name, 0, - "Signalled " - "draining of white"); - } - } - ret = pthread_mutex_unlock(&priv->dm.drain_white_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); + int ret = 0; + + if (local) { + if (local->color == FOP_COLOR_BLACK) { + ret = pthread_mutex_lock(&priv->dm.drain_black_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out); + { + priv->dm.black_fop_cnt--; + if (priv->dm.black_fop_cnt == 0 && + priv->dm.drain_wait_black == _gf_true) { + ret = pthread_cond_signal(&priv->dm.drain_black_cond); + CHANGELOG_PTHREAD_ERROR_HANDLE_2( + ret, out, priv->dm.drain_black_mutex); + gf_msg_debug(this->name, 0, + "Signalled " + "draining of black"); + } + } + ret = pthread_mutex_unlock(&priv->dm.drain_black_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out); + } else { + ret = pthread_mutex_lock(&priv->dm.drain_white_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out); + { + priv->dm.white_fop_cnt--; + if (priv->dm.white_fop_cnt == 0 && + priv->dm.drain_wait_white == _gf_true) { + ret = pthread_cond_signal(&priv->dm.drain_white_cond); + CHANGELOG_PTHREAD_ERROR_HANDLE_2( + ret, out, priv->dm.drain_white_mutex); + gf_msg_debug(this->name, 0, + "Signalled " + "draining of white"); } + } + ret = pthread_mutex_unlock(&priv->dm.drain_white_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out); } - out: - return; + } +out: + return; } /* Write to a pipe setup between changelog main thread and changelog * rollover thread to initiate explicit rollover of changelog journal. */ int -changelog_barrier_notify (changelog_priv_t *priv, char *buf) +changelog_barrier_notify(changelog_priv_t *priv, char *buf) { - int ret = 0; - - pthread_mutex_lock (&priv->cr.lock); - { - ret = pthread_cond_signal (&priv->cr.cond); - priv->cr.notify = _gf_true; - } - pthread_mutex_unlock (&priv->cr.lock); - return ret; + int ret = 0; + + pthread_mutex_lock(&priv->cr.lock); + { + ret = pthread_cond_signal(&priv->cr.cond); + priv->cr.notify = _gf_true; + } + pthread_mutex_unlock(&priv->cr.lock); + return ret; } /* Clean up flags set on barrier notification */ void -changelog_barrier_cleanup (xlator_t *this, changelog_priv_t *priv, - struct list_head *queue) +changelog_barrier_cleanup(xlator_t *this, changelog_priv_t *priv, + struct list_head *queue) { - int ret = 0; - - LOCK (&priv->bflags.lock); - priv->bflags.barrier_ext = _gf_false; - UNLOCK (&priv->bflags.lock); - - ret = pthread_mutex_lock (&priv->bn.bnotify_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - { - priv->bn.bnotify = _gf_false; - } - ret = pthread_mutex_unlock (&priv->bn.bnotify_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - - /* Disable changelog barrier and dequeue fops */ - LOCK (&priv->lock); - { - if (priv->barrier_enabled == _gf_true) - __chlog_barrier_disable (this, queue); - else - ret = -1; - } - UNLOCK (&priv->lock); - if (ret == 0) - chlog_barrier_dequeue_all(this, queue); + int ret = 0; + + LOCK(&priv->bflags.lock); + priv->bflags.barrier_ext = _gf_false; + UNLOCK(&priv->bflags.lock); + + ret = pthread_mutex_lock(&priv->bn.bnotify_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out); + { + priv->bn.bnotify = _gf_false; + } + ret = pthread_mutex_unlock(&priv->bn.bnotify_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out); + + /* Disable changelog barrier and dequeue fops */ + LOCK(&priv->lock); + { + if (priv->barrier_enabled == _gf_true) + __chlog_barrier_disable(this, queue); + else + ret = -1; + } + UNLOCK(&priv->lock); + if (ret == 0) + chlog_barrier_dequeue_all(this, queue); - out: - return; +out: + return; } /* End: Geo-Rep snapshot dependency changes */ int32_t -changelog_fill_entry_buf (call_frame_t *frame, xlator_t *this, - loc_t *loc, changelog_local_t **local) +changelog_fill_entry_buf(call_frame_t *frame, xlator_t *this, loc_t *loc, + changelog_local_t **local) { - changelog_opt_t *co = NULL; - size_t xtra_len = 0; - char *dup_path = NULL; - char *bname = NULL; - inode_t *parent = NULL; - - GF_ASSERT (this); - - parent = inode_parent (loc->inode, 0, 0); - if (!parent) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_INODE_NOT_FOUND, - "Parent inode not found", - "gfid=%s", uuid_utoa (loc->inode->gfid), - NULL); - goto err; - } - - CHANGELOG_INIT_NOCHECK (this, *local, loc->inode, loc->inode->gfid, 5); - if (!(*local)) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_LOCAL_INIT_FAILED, "changelog local" - " initiatilization failed"); - goto err; - } - - co = changelog_get_usable_buffer (*local); - if (!co) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_NO_MEMORY, - "Failed to get buffer"); - goto err; - } - - if (loc->inode->ia_type == IA_IFDIR) { - CHANGLOG_FILL_FOP_NUMBER (co, GF_FOP_MKDIR, fop_fn, xtra_len); - co++; - CHANGELOG_FILL_UINT32 (co, S_IFDIR|0755, number_fn, xtra_len); - co++; - } else { - CHANGLOG_FILL_FOP_NUMBER (co, GF_FOP_CREATE, fop_fn, xtra_len); - co++; - CHANGELOG_FILL_UINT32 (co, S_IFREG|0644, number_fn, xtra_len); - co++; - } - - CHANGELOG_FILL_UINT32 (co, frame->root->uid, number_fn, xtra_len); + changelog_opt_t *co = NULL; + size_t xtra_len = 0; + char *dup_path = NULL; + char *bname = NULL; + inode_t *parent = NULL; + + GF_ASSERT(this); + + parent = inode_parent(loc->inode, 0, 0); + if (!parent) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_INODE_NOT_FOUND, + "Parent inode not found", "gfid=%s", + uuid_utoa(loc->inode->gfid), NULL); + goto err; + } + + CHANGELOG_INIT_NOCHECK(this, *local, loc->inode, loc->inode->gfid, 5); + if (!(*local)) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_LOCAL_INIT_FAILED, + "changelog local" + " initiatilization failed"); + goto err; + } + + co = changelog_get_usable_buffer(*local); + if (!co) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_NO_MEMORY, + "Failed to get buffer"); + goto err; + } + + if (loc->inode->ia_type == IA_IFDIR) { + CHANGLOG_FILL_FOP_NUMBER(co, GF_FOP_MKDIR, fop_fn, xtra_len); co++; - - CHANGELOG_FILL_UINT32 (co, frame->root->gid, number_fn, xtra_len); + CHANGELOG_FILL_UINT32(co, S_IFDIR | 0755, number_fn, xtra_len); + co++; + } else { + CHANGLOG_FILL_FOP_NUMBER(co, GF_FOP_CREATE, fop_fn, xtra_len); + co++; + CHANGELOG_FILL_UINT32(co, S_IFREG | 0644, number_fn, xtra_len); co++; + } - dup_path = gf_strdup (loc->path); - bname = basename (dup_path); + CHANGELOG_FILL_UINT32(co, frame->root->uid, number_fn, xtra_len); + co++; - CHANGELOG_FILL_ENTRY (co, parent->gfid, bname, entry_fn, entry_free_fn, - xtra_len, err); - changelog_set_usable_record_and_length (*local, xtra_len, 5); + CHANGELOG_FILL_UINT32(co, frame->root->gid, number_fn, xtra_len); + co++; - if (dup_path) - GF_FREE (dup_path); - if (parent) - inode_unref (parent); - return 0; + dup_path = gf_strdup(loc->path); + bname = basename(dup_path); + + CHANGELOG_FILL_ENTRY(co, parent->gfid, bname, entry_fn, entry_free_fn, + xtra_len, err); + changelog_set_usable_record_and_length(*local, xtra_len, 5); + + if (dup_path) + GF_FREE(dup_path); + if (parent) + inode_unref(parent); + return 0; err: - if (dup_path) - GF_FREE (dup_path); - if (parent) - inode_unref (parent); - return -1; + if (dup_path) + GF_FREE(dup_path); + if (parent) + inode_unref(parent); + return -1; } /* @@ -1990,93 +1920,98 @@ err: */ int -resolve_pargfid_to_path (xlator_t *this, const uuid_t pgfid, - char **path, char *bname) +resolve_pargfid_to_path(xlator_t *this, const uuid_t pgfid, char **path, + char *bname) { - char *linkname = NULL; - char *dir_handle = NULL; - char *pgfidstr = NULL; - char *saveptr = NULL; - ssize_t len = 0; - int ret = 0; - uuid_t tmp_gfid = {0, }; - uuid_t pargfid = {0, }; - changelog_priv_t *priv = NULL; - char gpath[PATH_MAX] = {0,}; - char result[PATH_MAX] = {0,}; - char *dir_name = NULL; - char pre_dir_name[PATH_MAX] = {0,}; - - GF_ASSERT (this); - priv = this->private; - GF_ASSERT (priv); - - gf_uuid_copy (pargfid, pgfid); - if (!path || gf_uuid_is_null (pargfid)) { - ret = -1; - goto out; - } - - if (__is_root_gfid (pargfid)) { - if (bname) - *path = gf_strdup (bname); - else - *path = gf_strdup ("."); - return ret; - } + char *linkname = NULL; + char *dir_handle = NULL; + char *pgfidstr = NULL; + char *saveptr = NULL; + ssize_t len = 0; + int ret = 0; + uuid_t tmp_gfid = { + 0, + }; + uuid_t pargfid = { + 0, + }; + changelog_priv_t *priv = NULL; + char gpath[PATH_MAX] = { + 0, + }; + char result[PATH_MAX] = { + 0, + }; + char *dir_name = NULL; + char pre_dir_name[PATH_MAX] = { + 0, + }; + + GF_ASSERT(this); + priv = this->private; + GF_ASSERT(priv); + + gf_uuid_copy(pargfid, pgfid); + if (!path || gf_uuid_is_null(pargfid)) { + ret = -1; + goto out; + } + + if (__is_root_gfid(pargfid)) { + if (bname) + *path = gf_strdup(bname); + else + *path = gf_strdup("."); + return ret; + } - dir_handle = alloca (PATH_MAX); - linkname = alloca (PATH_MAX); - (void) snprintf (gpath, PATH_MAX, "%s/.glusterfs/", - priv->changelog_brick); - - while (!(__is_root_gfid (pargfid))) { - len = snprintf (dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath, - pargfid[0], pargfid[1], uuid_utoa (pargfid)); - if ((len < 0) || (len >= PATH_MAX)) { - ret = -1; - goto out; - } + dir_handle = alloca(PATH_MAX); + linkname = alloca(PATH_MAX); + (void)snprintf(gpath, PATH_MAX, "%s/.glusterfs/", priv->changelog_brick); - len = sys_readlink (dir_handle, linkname, PATH_MAX); - if (len < 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_READLINK_OP_FAILED, - "could not read the " - "link from the gfid handle", - "handle=%s", dir_handle, - NULL); - ret = -1; - goto out; - } + while (!(__is_root_gfid(pargfid))) { + len = snprintf(dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath, + pargfid[0], pargfid[1], uuid_utoa(pargfid)); + if ((len < 0) || (len >= PATH_MAX)) { + ret = -1; + goto out; + } - linkname[len] = '\0'; + len = sys_readlink(dir_handle, linkname, PATH_MAX); + if (len < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_READLINK_OP_FAILED, + "could not read the " + "link from the gfid handle", + "handle=%s", dir_handle, NULL); + ret = -1; + goto out; + } - pgfidstr = strtok_r (linkname + strlen("../../00/00/"), "/", - &saveptr); - dir_name = strtok_r (NULL, "/", &saveptr); + linkname[len] = '\0'; - len = snprintf (result, PATH_MAX, "%s/%s", dir_name, - pre_dir_name); - if ((len < 0) || (len >= PATH_MAX)) { - ret = -1; - goto out; - } - if (snprintf (pre_dir_name, len + 1, "%s", result) - >= len + 1) { - ret = -1; - goto out; - } + pgfidstr = strtok_r(linkname + strlen("../../00/00/"), "/", &saveptr); + dir_name = strtok_r(NULL, "/", &saveptr); - gf_uuid_parse (pgfidstr, tmp_gfid); - gf_uuid_copy (pargfid, tmp_gfid); + len = snprintf(result, PATH_MAX, "%s/%s", dir_name, pre_dir_name); + if ((len < 0) || (len >= PATH_MAX)) { + ret = -1; + goto out; + } + if (snprintf(pre_dir_name, len + 1, "%s", result) >= len + 1) { + ret = -1; + goto out; } - if (bname) - strncat (result, bname, strlen(bname) + 1); + gf_uuid_parse(pgfidstr, tmp_gfid); + gf_uuid_copy(pargfid, tmp_gfid); + } - *path = gf_strdup (result); + if (bname) + strncat(result, bname, strlen(bname) + 1); + + *path = gf_strdup(result); out: - return ret; + return ret; } diff --git a/xlators/features/changelog/src/changelog-rpc-common.c b/xlators/features/changelog/src/changelog-rpc-common.c index 056519232cf..ce01bf7a133 100644 --- a/xlators/features/changelog/src/changelog-rpc-common.c +++ b/xlators/features/changelog/src/changelog-rpc-common.c @@ -24,65 +24,63 @@ */ void * -changelog_rpc_poller (void *arg) +changelog_rpc_poller(void *arg) { - xlator_t *this = arg; + xlator_t *this = arg; - (void) event_dispatch (this->ctx->event_pool); - return NULL; + (void)event_dispatch(this->ctx->event_pool); + return NULL; } struct rpc_clnt * -changelog_rpc_client_init (xlator_t *this, void *cbkdata, - char *sockfile, rpc_clnt_notify_t fn) +changelog_rpc_client_init(xlator_t *this, void *cbkdata, char *sockfile, + rpc_clnt_notify_t fn) { - int ret = 0; - struct rpc_clnt *rpc = NULL; - dict_t *options = NULL; - - if (!cbkdata) - cbkdata = this; - - options = dict_new (); - if (!options) - goto error_return; - - ret = rpc_transport_unix_options_build (&options, sockfile, 0); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_RPC_BUILD_ERROR, - "failed to build rpc options"); - goto dealloc_dict; - } - - rpc = rpc_clnt_new (options, this, this->name, 16); - if (!rpc) - goto dealloc_dict; - - ret = rpc_clnt_register_notify (rpc, fn, cbkdata); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_NOTIFY_REGISTER_FAILED, - "failed to register notify"); - goto dealloc_rpc_clnt; - } - - ret = rpc_clnt_start (rpc); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_RPC_START_ERROR, - "failed to start rpc"); - goto dealloc_rpc_clnt; - } - - return rpc; - - dealloc_rpc_clnt: - rpc_clnt_unref (rpc); - dealloc_dict: - dict_unref (options); - error_return: - return NULL; + int ret = 0; + struct rpc_clnt *rpc = NULL; + dict_t *options = NULL; + + if (!cbkdata) + cbkdata = this; + + options = dict_new(); + if (!options) + goto error_return; + + ret = rpc_transport_unix_options_build(&options, sockfile, 0); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_BUILD_ERROR, + "failed to build rpc options"); + goto dealloc_dict; + } + + rpc = rpc_clnt_new(options, this, this->name, 16); + if (!rpc) + goto dealloc_dict; + + ret = rpc_clnt_register_notify(rpc, fn, cbkdata); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_NOTIFY_REGISTER_FAILED, + "failed to register notify"); + goto dealloc_rpc_clnt; + } + + ret = rpc_clnt_start(rpc); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_START_ERROR, + "failed to start rpc"); + goto dealloc_rpc_clnt; + } + + return rpc; + +dealloc_rpc_clnt: + rpc_clnt_unref(rpc); +dealloc_dict: + dict_unref(options); +error_return: + return NULL; } /** @@ -90,96 +88,96 @@ changelog_rpc_client_init (xlator_t *this, void *cbkdata, * RPC server. */ int -changelog_rpc_sumbit_req (struct rpc_clnt *rpc, void *req, - call_frame_t *frame, rpc_clnt_prog_t *prog, - int procnum, struct iovec *payload, int payloadcnt, - struct iobref *iobref, xlator_t *this, - fop_cbk_fn_t cbkfn, xdrproc_t xdrproc) +changelog_rpc_sumbit_req(struct rpc_clnt *rpc, void *req, call_frame_t *frame, + rpc_clnt_prog_t *prog, int procnum, + struct iovec *payload, int payloadcnt, + struct iobref *iobref, xlator_t *this, + fop_cbk_fn_t cbkfn, xdrproc_t xdrproc) { - int ret = 0; - int count = 0; - struct iovec iov = {0, }; - struct iobuf *iobuf = NULL; - char new_iobref = 0; - ssize_t xdr_size = 0; - - GF_ASSERT (this); + int ret = 0; + int count = 0; + struct iovec iov = { + 0, + }; + struct iobuf *iobuf = NULL; + char new_iobref = 0; + ssize_t xdr_size = 0; - if (req) { - xdr_size = xdr_sizeof (xdrproc, req); + GF_ASSERT(this); - iobuf = iobuf_get2 (this->ctx->iobuf_pool, xdr_size); - if (!iobuf) { - goto out; - }; + if (req) { + xdr_size = xdr_sizeof(xdrproc, req); - if (!iobref) { - iobref = iobref_new (); - if (!iobref) { - goto out; - } + iobuf = iobuf_get2(this->ctx->iobuf_pool, xdr_size); + if (!iobuf) { + goto out; + }; - new_iobref = 1; - } + if (!iobref) { + iobref = iobref_new(); + if (!iobref) { + goto out; + } - iobref_add (iobref, iobuf); + new_iobref = 1; + } - iov.iov_base = iobuf->ptr; - iov.iov_len = iobuf_size (iobuf); + iobref_add(iobref, iobuf); - /* Create the xdr payload */ - ret = xdr_serialize_generic (iov, req, xdrproc); - if (ret == -1) { - goto out; - } + iov.iov_base = iobuf->ptr; + iov.iov_len = iobuf_size(iobuf); - iov.iov_len = ret; - count = 1; + /* Create the xdr payload */ + ret = xdr_serialize_generic(iov, req, xdrproc); + if (ret == -1) { + goto out; } - ret = rpc_clnt_submit (rpc, prog, procnum, cbkfn, &iov, count, - payload, payloadcnt, iobref, frame, NULL, - 0, NULL, 0, NULL); + iov.iov_len = ret; + count = 1; + } - out: - if (new_iobref) - iobref_unref (iobref); - if (iobuf) - iobuf_unref (iobuf); - return ret; + ret = rpc_clnt_submit(rpc, prog, procnum, cbkfn, &iov, count, payload, + payloadcnt, iobref, frame, NULL, 0, NULL, 0, NULL); + +out: + if (new_iobref) + iobref_unref(iobref); + if (iobuf) + iobuf_unref(iobuf); + return ret; } /** * Entry point to perform a remote procedure call */ int -changelog_invoke_rpc (xlator_t *this, struct rpc_clnt *rpc, - rpc_clnt_prog_t *prog, int procidx, void *arg) +changelog_invoke_rpc(xlator_t *this, struct rpc_clnt *rpc, + rpc_clnt_prog_t *prog, int procidx, void *arg) { - int ret = 0; - call_frame_t *frame = NULL; - rpc_clnt_procedure_t *proc = NULL; - - if (!this || !prog) - goto error_return; - - frame = create_frame (this, this->ctx->pool); - if (!frame) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_CREATE_FRAME_FAILED, - "failed to create frame"); - goto error_return; - } + int ret = 0; + call_frame_t *frame = NULL; + rpc_clnt_procedure_t *proc = NULL; - proc = &prog->proctable[procidx]; - if (proc->fn) - ret = proc->fn (frame, this, arg); + if (!this || !prog) + goto error_return; - STACK_DESTROY (frame->root); - return ret; + frame = create_frame(this, this->ctx->pool); + if (!frame) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_CREATE_FRAME_FAILED, + "failed to create frame"); + goto error_return; + } - error_return: - return -1; + proc = &prog->proctable[procidx]; + if (proc->fn) + ret = proc->fn(frame, this, arg); + + STACK_DESTROY(frame->root); + return ret; + +error_return: + return -1; } /** @@ -189,170 +187,169 @@ changelog_invoke_rpc (xlator_t *this, struct rpc_clnt *rpc, */ struct iobuf * -__changelog_rpc_serialize_reply (rpcsvc_request_t *req, void *arg, - struct iovec *outmsg, xdrproc_t xdrproc) +__changelog_rpc_serialize_reply(rpcsvc_request_t *req, void *arg, + struct iovec *outmsg, xdrproc_t xdrproc) { - struct iobuf *iob = NULL; - ssize_t retlen = 0; - ssize_t rsp_size = 0; + struct iobuf *iob = NULL; + ssize_t retlen = 0; + ssize_t rsp_size = 0; - rsp_size = xdr_sizeof (xdrproc, arg); - iob = iobuf_get2 (req->svc->ctx->iobuf_pool, rsp_size); - if (!iob) - goto error_return; + rsp_size = xdr_sizeof(xdrproc, arg); + iob = iobuf_get2(req->svc->ctx->iobuf_pool, rsp_size); + if (!iob) + goto error_return; - iobuf_to_iovec (iob, outmsg); + iobuf_to_iovec(iob, outmsg); - retlen = xdr_serialize_generic (*outmsg, arg, xdrproc); - if (retlen == -1) - goto unref_iob; + retlen = xdr_serialize_generic(*outmsg, arg, xdrproc); + if (retlen == -1) + goto unref_iob; - outmsg->iov_len = retlen; - return iob; + outmsg->iov_len = retlen; + return iob; - unref_iob: - iobuf_unref (iob); - error_return: - return NULL; +unref_iob: + iobuf_unref(iob); +error_return: + return NULL; } int -changelog_rpc_sumbit_reply (rpcsvc_request_t *req, - void *arg, struct iovec *payload, int payloadcount, - struct iobref *iobref, xdrproc_t xdrproc) +changelog_rpc_sumbit_reply(rpcsvc_request_t *req, void *arg, + struct iovec *payload, int payloadcount, + struct iobref *iobref, xdrproc_t xdrproc) { - int ret = -1; - struct iobuf *iob = NULL; - struct iovec iov = {0,}; - char new_iobref = 0; - - if (!req) - goto return_ret; - - if (!iobref) { - iobref = iobref_new (); - if (!iobref) - goto return_ret; - new_iobref = 1; - } - - iob = __changelog_rpc_serialize_reply (req, arg, &iov, xdrproc); - if (!iob) - gf_msg ("", GF_LOG_ERROR, 0, - CHANGELOG_MSG_RPC_SUBMIT_REPLY_FAILED, - "failed to serialize reply"); - else - iobref_add (iobref, iob); - - ret = rpcsvc_submit_generic (req, &iov, - 1, payload, payloadcount, iobref); - - if (new_iobref) - iobref_unref (iobref); - if (iob) - iobuf_unref (iob); - return_ret: - return ret; + int ret = -1; + struct iobuf *iob = NULL; + struct iovec iov = { + 0, + }; + char new_iobref = 0; + + if (!req) + goto return_ret; + + if (!iobref) { + iobref = iobref_new(); + if (!iobref) + goto return_ret; + new_iobref = 1; + } + + iob = __changelog_rpc_serialize_reply(req, arg, &iov, xdrproc); + if (!iob) + gf_msg("", GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_SUBMIT_REPLY_FAILED, + "failed to serialize reply"); + else + iobref_add(iobref, iob); + + ret = rpcsvc_submit_generic(req, &iov, 1, payload, payloadcount, iobref); + + if (new_iobref) + iobref_unref(iobref); + if (iob) + iobuf_unref(iob); +return_ret: + return ret; } void -changelog_rpc_server_destroy (xlator_t *this, rpcsvc_t *rpc, char *sockfile, - rpcsvc_notify_t fn, struct rpcsvc_program **progs) +changelog_rpc_server_destroy(xlator_t *this, rpcsvc_t *rpc, char *sockfile, + rpcsvc_notify_t fn, struct rpcsvc_program **progs) { - rpcsvc_listener_t *listener = NULL; - rpcsvc_listener_t *next = NULL; - struct rpcsvc_program *prog = NULL; - - while (*progs) { - prog = *progs; - (void) rpcsvc_program_unregister (rpc, prog); - progs++; - } - - list_for_each_entry_safe (listener, next, &rpc->listeners, list) { - rpcsvc_listener_destroy (listener); - } - - (void) rpcsvc_unregister_notify (rpc, fn, this); - sys_unlink (sockfile); - if (rpc->rxpool) { - mem_pool_destroy (rpc->rxpool); - rpc->rxpool = NULL; - } - - /* TODO Avoid freeing rpc object in case of brick multiplex - after freeing rpc object svc->rpclock corrupted and it takes - more time to detach a brick - */ - if (!this->cleanup_starting) - GF_FREE (rpc); + rpcsvc_listener_t *listener = NULL; + rpcsvc_listener_t *next = NULL; + struct rpcsvc_program *prog = NULL; + + while (*progs) { + prog = *progs; + (void)rpcsvc_program_unregister(rpc, prog); + progs++; + } + + list_for_each_entry_safe(listener, next, &rpc->listeners, list) + { + rpcsvc_listener_destroy(listener); + } + + (void)rpcsvc_unregister_notify(rpc, fn, this); + sys_unlink(sockfile); + if (rpc->rxpool) { + mem_pool_destroy(rpc->rxpool); + rpc->rxpool = NULL; + } + + /* TODO Avoid freeing rpc object in case of brick multiplex + after freeing rpc object svc->rpclock corrupted and it takes + more time to detach a brick + */ + if (!this->cleanup_starting) + GF_FREE(rpc); } rpcsvc_t * -changelog_rpc_server_init (xlator_t *this, char *sockfile, void *cbkdata, - rpcsvc_notify_t fn, struct rpcsvc_program **progs) +changelog_rpc_server_init(xlator_t *this, char *sockfile, void *cbkdata, + rpcsvc_notify_t fn, struct rpcsvc_program **progs) { - int ret = 0; - rpcsvc_t *rpc = NULL; - dict_t *options = NULL; - struct rpcsvc_program *prog = NULL; - - if (!cbkdata) - cbkdata = this; - - options = dict_new (); - if (!options) - goto error_return; - - ret = rpcsvc_transport_unix_options_build (&options, sockfile); - if (ret) - goto dealloc_dict; - - rpc = rpcsvc_init (this, this->ctx, options, 8); - if (rpc == NULL) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_RPC_START_ERROR, - "failed to init rpc"); - goto dealloc_dict; - } - - ret = rpcsvc_register_notify (rpc, fn, cbkdata); + int ret = 0; + rpcsvc_t *rpc = NULL; + dict_t *options = NULL; + struct rpcsvc_program *prog = NULL; + + if (!cbkdata) + cbkdata = this; + + options = dict_new(); + if (!options) + goto error_return; + + ret = rpcsvc_transport_unix_options_build(&options, sockfile); + if (ret) + goto dealloc_dict; + + rpc = rpcsvc_init(this, this->ctx, options, 8); + if (rpc == NULL) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_START_ERROR, + "failed to init rpc"); + goto dealloc_dict; + } + + ret = rpcsvc_register_notify(rpc, fn, cbkdata); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_NOTIFY_REGISTER_FAILED, + "failed to register notify function"); + goto dealloc_rpc; + } + + ret = rpcsvc_create_listeners(rpc, options, this->name); + if (ret != 1) { + gf_msg_debug(this->name, 0, "failed to create listeners"); + goto dealloc_rpc; + } + + while (*progs) { + prog = *progs; + ret = rpcsvc_program_register(rpc, prog, _gf_false); if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_NOTIFY_REGISTER_FAILED, - "failed to register notify function"); - goto dealloc_rpc; - } - - ret = rpcsvc_create_listeners (rpc, options, this->name); - if (ret != 1) { - gf_msg_debug (this->name, - 0, "failed to create listeners"); - goto dealloc_rpc; + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_PROGRAM_NAME_REG_FAILED, + "cannot register program " + "(name: %s, prognum: %d, pogver: %d)", + prog->progname, prog->prognum, prog->progver); + goto dealloc_rpc; } - while (*progs) { - prog = *progs; - ret = rpcsvc_program_register (rpc, prog, _gf_false); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_PROGRAM_NAME_REG_FAILED, - "cannot register program " - "(name: %s, prognum: %d, pogver: %d)", - prog->progname, prog->prognum, prog->progver); - goto dealloc_rpc; - } - - progs++; - } + progs++; + } - dict_unref (options); - return rpc; + dict_unref(options); + return rpc; - dealloc_rpc: - GF_FREE (rpc); - dealloc_dict: - dict_unref (options); - error_return: - return NULL; +dealloc_rpc: + GF_FREE(rpc); +dealloc_dict: + dict_unref(options); +error_return: + return NULL; } diff --git a/xlators/features/changelog/src/changelog-rpc.c b/xlators/features/changelog/src/changelog-rpc.c index 9027fe10a2a..828f85e8e45 100644 --- a/xlators/features/changelog/src/changelog-rpc.c +++ b/xlators/features/changelog/src/changelog-rpc.c @@ -16,256 +16,246 @@ struct rpcsvc_program *changelog_programs[]; static void -changelog_cleanup_dispatchers (xlator_t *this, - changelog_priv_t *priv, int count) +changelog_cleanup_dispatchers(xlator_t *this, changelog_priv_t *priv, int count) { - for (count--; count >= 0; count--) { - (void) changelog_thread_cleanup - (this, priv->ev_dispatcher[count]); - priv->ev_dispatcher[count] = 0; - } + for (count--; count >= 0; count--) { + (void)changelog_thread_cleanup(this, priv->ev_dispatcher[count]); + priv->ev_dispatcher[count] = 0; + } } int -changelog_cleanup_rpc_threads (xlator_t *this, changelog_priv_t *priv) +changelog_cleanup_rpc_threads(xlator_t *this, changelog_priv_t *priv) { - int ret = 0; - changelog_clnt_t *conn = NULL; - - conn = &priv->connections; - if (!conn) - return 0; - - /** terminate RPC thread(s) */ - ret = changelog_thread_cleanup (this, priv->connector); - if (ret != 0) - goto error_return; - priv->connector = 0; - - /** terminate dispatcher thread(s) */ - changelog_cleanup_dispatchers (this, priv, priv->nr_dispatchers); - - /* TODO: what about pending and waiting connections? */ - changelog_ev_cleanup_connections (this, conn); - - /* destroy locks */ - ret = pthread_mutex_destroy (&conn->pending_lock); - if (ret != 0) - goto error_return; - ret = pthread_cond_destroy (&conn->pending_cond); - if (ret != 0) - goto error_return; - ret = LOCK_DESTROY (&conn->active_lock); - if (ret != 0) - goto error_return; - ret = LOCK_DESTROY (&conn->wait_lock); - if (ret != 0) - goto error_return; + int ret = 0; + changelog_clnt_t *conn = NULL; + + conn = &priv->connections; + if (!conn) return 0; - error_return: - return -1; + /** terminate RPC thread(s) */ + ret = changelog_thread_cleanup(this, priv->connector); + if (ret != 0) + goto error_return; + priv->connector = 0; + + /** terminate dispatcher thread(s) */ + changelog_cleanup_dispatchers(this, priv, priv->nr_dispatchers); + + /* TODO: what about pending and waiting connections? */ + changelog_ev_cleanup_connections(this, conn); + + /* destroy locks */ + ret = pthread_mutex_destroy(&conn->pending_lock); + if (ret != 0) + goto error_return; + ret = pthread_cond_destroy(&conn->pending_cond); + if (ret != 0) + goto error_return; + ret = LOCK_DESTROY(&conn->active_lock); + if (ret != 0) + goto error_return; + ret = LOCK_DESTROY(&conn->wait_lock); + if (ret != 0) + goto error_return; + return 0; + +error_return: + return -1; } static int -changelog_init_rpc_threads (xlator_t *this, changelog_priv_t *priv, - rbuf_t *rbuf, int nr_dispatchers) +changelog_init_rpc_threads(xlator_t *this, changelog_priv_t *priv, rbuf_t *rbuf, + int nr_dispatchers) { - int j = 0; - int ret = 0; - changelog_clnt_t *conn = NULL; - char thread_name[GF_THREAD_NAMEMAX] = {0,}; - - - conn = &priv->connections; - - conn->this = this; - conn->rbuf = rbuf; - conn->sequence = 1; /* start with sequence number one */ - - INIT_LIST_HEAD (&conn->pending); - INIT_LIST_HEAD (&conn->active); - INIT_LIST_HEAD (&conn->waitq); - - ret = pthread_mutex_init (&conn->pending_lock, NULL); - if (ret) - goto error_return; - ret = pthread_cond_init (&conn->pending_cond, NULL); - if (ret) - goto cleanup_pending_lock; - - ret = LOCK_INIT (&conn->active_lock); - if (ret) - goto cleanup_pending_cond; - ret = LOCK_INIT (&conn->wait_lock); - if (ret) - goto cleanup_active_lock; - - /* spawn reverse connection thread */ - ret = gf_thread_create (&priv->connector, - NULL, changelog_ev_connector, conn, "clogecon"); - if (ret != 0) - goto cleanup_wait_lock; - - /* spawn dispatcher thread(s) */ - priv->ev_dispatcher = GF_CALLOC (nr_dispatchers, sizeof(pthread_t), - gf_changelog_mt_ev_dispatcher_t); - if (!priv->ev_dispatcher) - goto cleanup_connector; - - /* spawn dispatcher threads */ - for (; j < nr_dispatchers; j++) { - snprintf (thread_name, sizeof(thread_name), - "clogd%03hx", (j & 0x3ff)); - ret = gf_thread_create (&priv->ev_dispatcher[j], - NULL, changelog_ev_dispatch, conn, - thread_name); - if (ret != 0) { - changelog_cleanup_dispatchers (this, priv, j); - break; - } + int j = 0; + int ret = 0; + changelog_clnt_t *conn = NULL; + char thread_name[GF_THREAD_NAMEMAX] = { + 0, + }; + + conn = &priv->connections; + + conn->this = this; + conn->rbuf = rbuf; + conn->sequence = 1; /* start with sequence number one */ + + INIT_LIST_HEAD(&conn->pending); + INIT_LIST_HEAD(&conn->active); + INIT_LIST_HEAD(&conn->waitq); + + ret = pthread_mutex_init(&conn->pending_lock, NULL); + if (ret) + goto error_return; + ret = pthread_cond_init(&conn->pending_cond, NULL); + if (ret) + goto cleanup_pending_lock; + + ret = LOCK_INIT(&conn->active_lock); + if (ret) + goto cleanup_pending_cond; + ret = LOCK_INIT(&conn->wait_lock); + if (ret) + goto cleanup_active_lock; + + /* spawn reverse connection thread */ + ret = gf_thread_create(&priv->connector, NULL, changelog_ev_connector, conn, + "clogecon"); + if (ret != 0) + goto cleanup_wait_lock; + + /* spawn dispatcher thread(s) */ + priv->ev_dispatcher = GF_CALLOC(nr_dispatchers, sizeof(pthread_t), + gf_changelog_mt_ev_dispatcher_t); + if (!priv->ev_dispatcher) + goto cleanup_connector; + + /* spawn dispatcher threads */ + for (; j < nr_dispatchers; j++) { + snprintf(thread_name, sizeof(thread_name), "clogd%03hx", (j & 0x3ff)); + ret = gf_thread_create(&priv->ev_dispatcher[j], NULL, + changelog_ev_dispatch, conn, thread_name); + if (ret != 0) { + changelog_cleanup_dispatchers(this, priv, j); + break; } - - if (ret != 0) - goto cleanup_connector; - - priv->nr_dispatchers = nr_dispatchers; - return 0; - - cleanup_connector: - (void) pthread_cancel (priv->connector); - cleanup_wait_lock: - LOCK_DESTROY (&conn->wait_lock); - cleanup_active_lock: - LOCK_DESTROY (&conn->active_lock); - cleanup_pending_cond: - (void) pthread_cond_destroy (&conn->pending_cond); - cleanup_pending_lock: - (void) pthread_mutex_destroy (&conn->pending_lock); - error_return: - return -1; + } + + if (ret != 0) + goto cleanup_connector; + + priv->nr_dispatchers = nr_dispatchers; + return 0; + +cleanup_connector: + (void)pthread_cancel(priv->connector); +cleanup_wait_lock: + LOCK_DESTROY(&conn->wait_lock); +cleanup_active_lock: + LOCK_DESTROY(&conn->active_lock); +cleanup_pending_cond: + (void)pthread_cond_destroy(&conn->pending_cond); +cleanup_pending_lock: + (void)pthread_mutex_destroy(&conn->pending_lock); +error_return: + return -1; } int -changelog_rpcsvc_notify (rpcsvc_t *rpc, - void *xl, rpcsvc_event_t event, void *data) +changelog_rpcsvc_notify(rpcsvc_t *rpc, void *xl, rpcsvc_event_t event, + void *data) { - return 0; + return 0; } void -changelog_destroy_rpc_listner (xlator_t *this, changelog_priv_t *priv) +changelog_destroy_rpc_listner(xlator_t *this, changelog_priv_t *priv) { - char sockfile[UNIX_PATH_MAX] = {0,}; - changelog_clnt_t *c_clnt = &priv->connections; - changelog_rpc_clnt_t *crpc = NULL; - int nofconn = 0; - - /* sockfile path could have been saved to avoid this */ - CHANGELOG_MAKE_SOCKET_PATH (priv->changelog_brick, - sockfile, UNIX_PATH_MAX); - changelog_rpc_server_destroy (this, - priv->rpc, sockfile, - changelog_rpcsvc_notify, - changelog_programs); - - /* TODO Below approach is not perfect to wait for cleanup - all active connections without this code brick process - can be crash in case of brick multiplexing if any in-progress - request process on rpc by changelog xlator after - cleanup resources - */ - - if (c_clnt) { - do { - nofconn = 0; - LOCK (&c_clnt->active_lock); - list_for_each_entry (crpc, &c_clnt->active, list) { - nofconn++; - } - UNLOCK (&c_clnt->active_lock); - LOCK (&c_clnt->wait_lock); - list_for_each_entry (crpc, &c_clnt->waitq, list) { - nofconn++; - } - UNLOCK (&c_clnt->wait_lock); - pthread_mutex_lock (&c_clnt->pending_lock); - list_for_each_entry (crpc, &c_clnt->pending, list) { - nofconn++; - } - pthread_mutex_unlock (&c_clnt->pending_lock); - - } while (nofconn); /* Wait for all connection cleanup */ - } - - (void) changelog_cleanup_rpc_threads (this, priv); + char sockfile[UNIX_PATH_MAX] = { + 0, + }; + changelog_clnt_t *c_clnt = &priv->connections; + changelog_rpc_clnt_t *crpc = NULL; + int nofconn = 0; + + /* sockfile path could have been saved to avoid this */ + CHANGELOG_MAKE_SOCKET_PATH(priv->changelog_brick, sockfile, UNIX_PATH_MAX); + changelog_rpc_server_destroy(this, priv->rpc, sockfile, + changelog_rpcsvc_notify, changelog_programs); + + /* TODO Below approach is not perfect to wait for cleanup + all active connections without this code brick process + can be crash in case of brick multiplexing if any in-progress + request process on rpc by changelog xlator after + cleanup resources + */ + + if (c_clnt) { + do { + nofconn = 0; + LOCK(&c_clnt->active_lock); + list_for_each_entry(crpc, &c_clnt->active, list) { nofconn++; } + UNLOCK(&c_clnt->active_lock); + LOCK(&c_clnt->wait_lock); + list_for_each_entry(crpc, &c_clnt->waitq, list) { nofconn++; } + UNLOCK(&c_clnt->wait_lock); + pthread_mutex_lock(&c_clnt->pending_lock); + list_for_each_entry(crpc, &c_clnt->pending, list) { nofconn++; } + pthread_mutex_unlock(&c_clnt->pending_lock); + + } while (nofconn); /* Wait for all connection cleanup */ + } + + (void)changelog_cleanup_rpc_threads(this, priv); } rpcsvc_t * -changelog_init_rpc_listener (xlator_t *this, changelog_priv_t *priv, +changelog_init_rpc_listener(xlator_t *this, changelog_priv_t *priv, rbuf_t *rbuf, int nr_dispatchers) { - int ret = 0; - char sockfile[UNIX_PATH_MAX] = {0,}; - rpcsvc_t *svcp; - - ret = changelog_init_rpc_threads (this, priv, rbuf, nr_dispatchers); - if (ret) - return NULL; - - CHANGELOG_MAKE_SOCKET_PATH (priv->changelog_brick, - sockfile, UNIX_PATH_MAX); - (void) sys_unlink (sockfile); - svcp = changelog_rpc_server_init (this, sockfile, NULL, - changelog_rpcsvc_notify, - changelog_programs); - return svcp; + int ret = 0; + char sockfile[UNIX_PATH_MAX] = { + 0, + }; + rpcsvc_t *svcp; + + ret = changelog_init_rpc_threads(this, priv, rbuf, nr_dispatchers); + if (ret) + return NULL; + + CHANGELOG_MAKE_SOCKET_PATH(priv->changelog_brick, sockfile, UNIX_PATH_MAX); + (void)sys_unlink(sockfile); + svcp = changelog_rpc_server_init( + this, sockfile, NULL, changelog_rpcsvc_notify, changelog_programs); + return svcp; } void -changelog_rpc_clnt_cleanup (changelog_rpc_clnt_t *crpc) +changelog_rpc_clnt_cleanup(changelog_rpc_clnt_t *crpc) { - if (!crpc) - return; - crpc->c_clnt = NULL; - LOCK_DESTROY (&crpc->lock); - GF_FREE (crpc); + if (!crpc) + return; + crpc->c_clnt = NULL; + LOCK_DESTROY(&crpc->lock); + GF_FREE(crpc); } static changelog_rpc_clnt_t * -changelog_rpc_clnt_init (xlator_t *this, - changelog_probe_req *rpc_req, changelog_clnt_t *c_clnt) +changelog_rpc_clnt_init(xlator_t *this, changelog_probe_req *rpc_req, + changelog_clnt_t *c_clnt) { - int ret = 0; - changelog_rpc_clnt_t *crpc = NULL; - - crpc = GF_CALLOC (1, sizeof (*crpc), gf_changelog_mt_rpc_clnt_t); - if (!crpc) - goto error_return; - INIT_LIST_HEAD (&crpc->list); - - /* Take a ref, the last unref will be on RPC_CLNT_DESTROY - * which comes as a result of last rpc_clnt_unref. - */ - GF_ATOMIC_INIT (crpc->ref, 1); - changelog_set_disconnect_flag (crpc, _gf_false); - - crpc->filter = rpc_req->filter; - (void) memcpy (crpc->sock, rpc_req->sock, strlen (rpc_req->sock)); - - crpc->this = this; - crpc->c_clnt = c_clnt; - crpc->cleanup = changelog_rpc_clnt_cleanup; - - ret = LOCK_INIT (&crpc->lock); - if (ret != 0) - goto dealloc_crpc; - return crpc; - - dealloc_crpc: - GF_FREE (crpc); - error_return: - return NULL; + int ret = 0; + changelog_rpc_clnt_t *crpc = NULL; + + crpc = GF_CALLOC(1, sizeof(*crpc), gf_changelog_mt_rpc_clnt_t); + if (!crpc) + goto error_return; + INIT_LIST_HEAD(&crpc->list); + + /* Take a ref, the last unref will be on RPC_CLNT_DESTROY + * which comes as a result of last rpc_clnt_unref. + */ + GF_ATOMIC_INIT(crpc->ref, 1); + changelog_set_disconnect_flag(crpc, _gf_false); + + crpc->filter = rpc_req->filter; + (void)memcpy(crpc->sock, rpc_req->sock, strlen(rpc_req->sock)); + + crpc->this = this; + crpc->c_clnt = c_clnt; + crpc->cleanup = changelog_rpc_clnt_cleanup; + + ret = LOCK_INIT(&crpc->lock); + if (ret != 0) + goto dealloc_crpc; + return crpc; + +dealloc_crpc: + GF_FREE(crpc); +error_return: + return NULL; } /** @@ -279,58 +269,59 @@ changelog_rpc_clnt_init (xlator_t *this, */ int -changelog_handle_probe (rpcsvc_request_t *req) +changelog_handle_probe(rpcsvc_request_t *req) { - int ret = 0; - xlator_t *this = NULL; - rpcsvc_t *svc = NULL; - changelog_priv_t *priv = NULL; - changelog_clnt_t *c_clnt = NULL; - changelog_rpc_clnt_t *crpc = NULL; - - changelog_probe_req rpc_req = {0,}; - changelog_probe_rsp rpc_rsp = {0,}; - - - this = req->trans->xl; - if (this->cleanup_starting) { - gf_msg (this->name, GF_LOG_DEBUG, 0, - CHANGELOG_MSG_HANDLE_PROBE_ERROR, - "cleanup_starting flag is already set for xl"); - return 0; - } - - ret = xdr_to_generic (req->msg[0], - &rpc_req, (xdrproc_t)xdr_changelog_probe_req); - if (ret < 0) { - gf_msg ("", GF_LOG_ERROR, 0, - CHANGELOG_MSG_HANDLE_PROBE_ERROR, - "xdr decoding error"); - req->rpc_err = GARBAGE_ARGS; - goto handle_xdr_error; - } - - /* ->xl hidden in rpcsvc */ - svc = rpcsvc_request_service (req); - this = svc->xl; - priv = this->private; - c_clnt = &priv->connections; - - crpc = changelog_rpc_clnt_init (this, &rpc_req, c_clnt); - if (!crpc) - goto handle_xdr_error; - - changelog_ev_queue_connection (c_clnt, crpc); - rpc_rsp.op_ret = 0; - - goto submit_rpc; - - handle_xdr_error: - rpc_rsp.op_ret = -1; - submit_rpc: - (void) changelog_rpc_sumbit_reply (req, &rpc_rsp, NULL, 0, NULL, - (xdrproc_t)xdr_changelog_probe_rsp); + int ret = 0; + xlator_t *this = NULL; + rpcsvc_t *svc = NULL; + changelog_priv_t *priv = NULL; + changelog_clnt_t *c_clnt = NULL; + changelog_rpc_clnt_t *crpc = NULL; + + changelog_probe_req rpc_req = { + 0, + }; + changelog_probe_rsp rpc_rsp = { + 0, + }; + + this = req->trans->xl; + if (this->cleanup_starting) { + gf_msg(this->name, GF_LOG_DEBUG, 0, CHANGELOG_MSG_HANDLE_PROBE_ERROR, + "cleanup_starting flag is already set for xl"); return 0; + } + + ret = xdr_to_generic(req->msg[0], &rpc_req, + (xdrproc_t)xdr_changelog_probe_req); + if (ret < 0) { + gf_msg("", GF_LOG_ERROR, 0, CHANGELOG_MSG_HANDLE_PROBE_ERROR, + "xdr decoding error"); + req->rpc_err = GARBAGE_ARGS; + goto handle_xdr_error; + } + + /* ->xl hidden in rpcsvc */ + svc = rpcsvc_request_service(req); + this = svc->xl; + priv = this->private; + c_clnt = &priv->connections; + + crpc = changelog_rpc_clnt_init(this, &rpc_req, c_clnt); + if (!crpc) + goto handle_xdr_error; + + changelog_ev_queue_connection(c_clnt, crpc); + rpc_rsp.op_ret = 0; + + goto submit_rpc; + +handle_xdr_error: + rpc_rsp.op_ret = -1; +submit_rpc: + (void)changelog_rpc_sumbit_reply(req, &rpc_rsp, NULL, 0, NULL, + (xdrproc_t)xdr_changelog_probe_rsp); + return 0; } /** @@ -338,22 +329,21 @@ changelog_handle_probe (rpcsvc_request_t *req) */ rpcsvc_actor_t changelog_svc_actors[CHANGELOG_RPC_PROC_MAX] = { - [CHANGELOG_RPC_PROBE_FILTER] = { - "CHANGELOG PROBE FILTER", CHANGELOG_RPC_PROBE_FILTER, - changelog_handle_probe, NULL, 0, DRC_NA - }, + [CHANGELOG_RPC_PROBE_FILTER] = {"CHANGELOG PROBE FILTER", + CHANGELOG_RPC_PROBE_FILTER, + changelog_handle_probe, NULL, 0, DRC_NA}, }; struct rpcsvc_program changelog_svc_prog = { - .progname = CHANGELOG_RPC_PROGNAME, - .prognum = CHANGELOG_RPC_PROGNUM, - .progver = CHANGELOG_RPC_PROGVER, - .numactors = CHANGELOG_RPC_PROC_MAX, - .actors = changelog_svc_actors, - .synctask = _gf_true, + .progname = CHANGELOG_RPC_PROGNAME, + .prognum = CHANGELOG_RPC_PROGNUM, + .progver = CHANGELOG_RPC_PROGVER, + .numactors = CHANGELOG_RPC_PROC_MAX, + .actors = changelog_svc_actors, + .synctask = _gf_true, }; struct rpcsvc_program *changelog_programs[] = { - &changelog_svc_prog, - NULL, + &changelog_svc_prog, + NULL, }; diff --git a/xlators/features/changelog/src/changelog-rt.c b/xlators/features/changelog/src/changelog-rt.c index c262820c64c..968c76b8b20 100644 --- a/xlators/features/changelog/src/changelog-rt.c +++ b/xlators/features/changelog/src/changelog-rt.c @@ -16,52 +16,51 @@ #include "changelog-mem-types.h" int -changelog_rt_init (xlator_t *this, changelog_dispatcher_t *cd) +changelog_rt_init(xlator_t *this, changelog_dispatcher_t *cd) { - changelog_rt_t *crt = NULL; + changelog_rt_t *crt = NULL; - crt = GF_CALLOC (1, sizeof (*crt), - gf_changelog_mt_rt_t); - if (!crt) - return -1; + crt = GF_CALLOC(1, sizeof(*crt), gf_changelog_mt_rt_t); + if (!crt) + return -1; - LOCK_INIT (&crt->lock); + LOCK_INIT(&crt->lock); - cd->cd_data = crt; - cd->dispatchfn = &changelog_rt_enqueue; + cd->cd_data = crt; + cd->dispatchfn = &changelog_rt_enqueue; - return 0; + return 0; } int -changelog_rt_fini (xlator_t *this, changelog_dispatcher_t *cd) +changelog_rt_fini(xlator_t *this, changelog_dispatcher_t *cd) { - changelog_rt_t *crt = NULL; + changelog_rt_t *crt = NULL; - crt = cd->cd_data; + crt = cd->cd_data; - LOCK_DESTROY (&crt->lock); - GF_FREE (crt); + LOCK_DESTROY(&crt->lock); + GF_FREE(crt); - return 0; + return 0; } int -changelog_rt_enqueue (xlator_t *this, changelog_priv_t *priv, void *cbatch, - changelog_log_data_t *cld_0, changelog_log_data_t *cld_1) +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; + int ret = 0; + changelog_rt_t *crt = NULL; - crt = (changelog_rt_t *) cbatch; + crt = (changelog_rt_t *)cbatch; - LOCK (&crt->lock); - { - ret = changelog_handle_change (this, priv, cld_0); - if (!ret && cld_1) - ret = changelog_handle_change (this, priv, cld_1); - } - UNLOCK (&crt->lock); + LOCK(&crt->lock); + { + ret = changelog_handle_change(this, priv, cld_0); + if (!ret && cld_1) + ret = changelog_handle_change(this, priv, cld_1); + } + UNLOCK(&crt->lock); - return ret; + return ret; } diff --git a/xlators/features/changelog/src/changelog.c b/xlators/features/changelog/src/changelog.c index ab42ad869c0..35a523316ed 100644 --- a/xlators/features/changelog/src/changelog.c +++ b/xlators/features/changelog/src/changelog.c @@ -26,13 +26,12 @@ #include "changelog-rpc.h" #include "errno.h" -static struct changelog_bootstrap -cb_bootstrap[] = { - { - .mode = CHANGELOG_MODE_RT, - .ctor = changelog_rt_init, - .dtor = changelog_rt_fini, - }, +static struct changelog_bootstrap cb_bootstrap[] = { + { + .mode = CHANGELOG_MODE_RT, + .ctor = changelog_rt_init, + .dtor = changelog_rt_fini, + }, }; /* Entry operations - TYPE III */ @@ -46,1111 +45,1060 @@ cb_bootstrap[] = { /* rmdir */ int32_t -changelog_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +changelog_rmdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY); + changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (rmdir, frame, op_ret, op_errno, - preparent, postparent, xdata); - return 0; +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(rmdir, frame, op_ret, op_errno, preparent, + postparent, xdata); + return 0; } int32_t -changelog_rmdir_resume (call_frame_t *frame, xlator_t *this, - loc_t *loc, int xflags, dict_t *xdata) +changelog_rmdir_resume(call_frame_t *frame, xlator_t *this, loc_t *loc, + int xflags, dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; + priv = this->private; - gf_msg_debug (this->name, 0, "Dequeue rmdir"); - changelog_color_fop_and_inc_cnt (this, priv, - frame->local); - STACK_WIND (frame, changelog_rmdir_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->rmdir, - loc, xflags, xdata); - return 0; + gf_msg_debug(this->name, 0, "Dequeue rmdir"); + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_rmdir_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->rmdir, loc, xflags, xdata); + return 0; } int32_t -changelog_rmdir (call_frame_t *frame, xlator_t *this, - loc_t *loc, int xflags, dict_t *xdata) -{ - size_t xtra_len = 0; - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - call_stub_t *stub = NULL; - struct list_head queue = {0, }; - gf_boolean_t barrier_enabled = _gf_false; - - INIT_LIST_HEAD (&queue); - - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); - - 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++; - if (priv->capture_del_path) { - CHANGELOG_FILL_ENTRY_DIR_PATH (co, loc->pargfid, loc->name, - del_entry_fn, del_entry_free_fn, - xtra_len, wind, _gf_true); +changelog_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflags, + dict_t *xdata) +{ + size_t xtra_len = 0; + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + call_stub_t *stub = NULL; + struct list_head queue = { + 0, + }; + gf_boolean_t barrier_enabled = _gf_false; + + INIT_LIST_HEAD(&queue); + + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); + + 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++; + if (priv->capture_del_path) { + CHANGELOG_FILL_ENTRY_DIR_PATH(co, loc->pargfid, loc->name, del_entry_fn, + del_entry_free_fn, xtra_len, wind, + _gf_true); + } else { + CHANGELOG_FILL_ENTRY_DIR_PATH(co, loc->pargfid, loc->name, del_entry_fn, + del_entry_free_fn, xtra_len, wind, + _gf_false); + } + + changelog_set_usable_record_and_length(frame->local, xtra_len, 2); + + /* changelog barrier */ + /* Color assignment and increment of fop_cnt for rmdir/unlink/rename + * should be made with in priv lock if changelog barrier is not enabled. + * Because if counter is not incremented yet, draining wakes up and + * publishes the changelog but later these fops might hit the disk and + * present in snapped volume but where as the intention is these fops + * should not be present in snapped volume. + */ + LOCK(&priv->lock); + { + if ((barrier_enabled = priv->barrier_enabled)) { + stub = fop_rmdir_stub(frame, changelog_rmdir_resume, loc, xflags, + xdata); + if (!stub) + __chlog_barrier_disable(this, &queue); + else + __chlog_barrier_enqueue(this, stub); } else { - CHANGELOG_FILL_ENTRY_DIR_PATH (co, loc->pargfid, loc->name, - del_entry_fn, del_entry_free_fn, - xtra_len, wind, _gf_false); - } - - changelog_set_usable_record_and_length (frame->local, xtra_len, 2); - -/* changelog barrier */ - /* Color assignment and increment of fop_cnt for rmdir/unlink/rename - * should be made with in priv lock if changelog barrier is not enabled. - * Because if counter is not incremented yet, draining wakes up and - * publishes the changelog but later these fops might hit the disk and - * present in snapped volume but where as the intention is these fops - * should not be present in snapped volume. - */ - LOCK (&priv->lock); - { - if ((barrier_enabled = priv->barrier_enabled)) { - stub = fop_rmdir_stub (frame, changelog_rmdir_resume, - loc, xflags, xdata); - if (!stub) - __chlog_barrier_disable (this, &queue); - else - __chlog_barrier_enqueue (this, stub); - } else { - ((changelog_local_t *)frame->local)->color - = priv->current_color; - changelog_inc_fop_cnt (this, priv, frame->local); - } - } - UNLOCK (&priv->lock); - - if (barrier_enabled && stub) { - gf_msg_debug (this->name, 0, "Enqueue rmdir"); - goto out; - } - if (barrier_enabled && !stub) { - gf_smsg (this->name, GF_LOG_ERROR, ENOMEM, - CHANGELOG_MSG_NO_MEMORY, - "Failed to barrier FOPs, disabling changelog barrier", - "fop=rmdir", - NULL); - chlog_barrier_dequeue_all (this, &queue); - } - -/* changelog barrier */ - - wind: - STACK_WIND (frame, changelog_rmdir_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->rmdir, - loc, xflags, xdata); - out: - return 0; + ((changelog_local_t *)frame->local)->color = priv->current_color; + changelog_inc_fop_cnt(this, priv, frame->local); + } + } + UNLOCK(&priv->lock); + + if (barrier_enabled && stub) { + gf_msg_debug(this->name, 0, "Enqueue rmdir"); + goto out; + } + if (barrier_enabled && !stub) { + gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY, + "Failed to barrier FOPs, disabling changelog barrier", + "fop=rmdir", NULL); + chlog_barrier_dequeue_all(this, &queue); + } + + /* changelog barrier */ + +wind: + STACK_WIND(frame, changelog_rmdir_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->rmdir, loc, xflags, xdata); +out: + return 0; } /* unlink */ int32_t -changelog_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +changelog_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY); + changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (unlink, frame, op_ret, op_errno, - preparent, postparent, xdata); - return 0; +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(unlink, frame, op_ret, op_errno, preparent, + postparent, xdata); + return 0; } int32_t -changelog_unlink_resume (call_frame_t *frame, xlator_t *this, - loc_t *loc, int xflags, dict_t *xdata) +changelog_unlink_resume(call_frame_t *frame, xlator_t *this, loc_t *loc, + int xflags, dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; + priv = this->private; - gf_msg_debug (this->name, 0, "Dequeue unlink"); - changelog_color_fop_and_inc_cnt - (this, priv, frame->local); - STACK_WIND (frame, changelog_unlink_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->unlink, - loc, xflags, xdata); - return 0; + gf_msg_debug(this->name, 0, "Dequeue unlink"); + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_unlink_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->unlink, loc, xflags, xdata); + return 0; } int32_t -changelog_unlink (call_frame_t *frame, xlator_t *this, - loc_t *loc, int xflags, dict_t *xdata) -{ - size_t xtra_len = 0; - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - call_stub_t *stub = NULL; - struct list_head queue = {0, }; - gf_boolean_t barrier_enabled = _gf_false; - dht_changelog_rename_info_t *info = NULL; - int ret = 0; - char *old_name = NULL; - char *new_name = NULL; - char *nname = NULL; - - INIT_LIST_HEAD (&queue); - priv = this->private; - - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); - - ret = dict_get_bin (xdata, DHT_CHANGELOG_RENAME_OP_KEY, (void **)&info); - if (!ret) { /* special case: unlink considered as rename */ - /* 3 == fop + oldloc + newloc */ - old_name = alloca (info->oldname_len); - new_name = alloca (info->newname_len); - CHANGELOG_INIT_NOCHECK (this, frame->local, - NULL, loc->inode->gfid, 3); - - co = changelog_get_usable_buffer (frame->local); - if (!co) - goto wind; - - CHANGLOG_FILL_FOP_NUMBER (co, GF_FOP_RENAME, fop_fn, xtra_len); - - co++; - strncpy (old_name, info->buffer, info->oldname_len); - CHANGELOG_FILL_ENTRY (co, info->old_pargfid, old_name, - entry_fn, entry_free_fn, xtra_len, wind); - - co++; - /* new name resides just after old name */ - nname = info->buffer + info->oldname_len; - strncpy (new_name, nname, info->newname_len); - CHANGELOG_FILL_ENTRY (co, info->new_pargfid, new_name, - entry_fn, entry_free_fn, xtra_len, wind); - - changelog_set_usable_record_and_length (frame->local, - xtra_len, 3); - } else { /* default unlink */ - CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, wind); - 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++; - if (priv->capture_del_path) { - CHANGELOG_FILL_ENTRY_DIR_PATH (co, loc->pargfid, - loc->name, del_entry_fn, del_entry_free_fn, - xtra_len, wind, _gf_true); - } else { - CHANGELOG_FILL_ENTRY_DIR_PATH (co, loc->pargfid, - loc->name, del_entry_fn, del_entry_free_fn, - xtra_len, wind, _gf_false); - } +changelog_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflags, + dict_t *xdata) +{ + size_t xtra_len = 0; + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + call_stub_t *stub = NULL; + struct list_head queue = { + 0, + }; + gf_boolean_t barrier_enabled = _gf_false; + dht_changelog_rename_info_t *info = NULL; + int ret = 0; + char *old_name = NULL; + char *new_name = NULL; + char *nname = NULL; + + INIT_LIST_HEAD(&queue); + priv = this->private; + + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); + + ret = dict_get_bin(xdata, DHT_CHANGELOG_RENAME_OP_KEY, (void **)&info); + if (!ret) { /* special case: unlink considered as rename */ + /* 3 == fop + oldloc + newloc */ + old_name = alloca(info->oldname_len); + new_name = alloca(info->newname_len); + CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, loc->inode->gfid, 3); - changelog_set_usable_record_and_length (frame->local, - xtra_len, 2); - } + co = changelog_get_usable_buffer(frame->local); + if (!co) + goto wind; -/* changelog barrier */ - LOCK (&priv->lock); - { - if ((barrier_enabled = priv->barrier_enabled)) { - stub = fop_unlink_stub (frame, changelog_unlink_resume, - loc, xflags, xdata); - if (!stub) - __chlog_barrier_disable (this, &queue); - else - __chlog_barrier_enqueue (this, stub); - } else { - ((changelog_local_t *)frame->local)->color - = priv->current_color; - changelog_inc_fop_cnt (this, priv, frame->local); - } - } - UNLOCK (&priv->lock); + CHANGLOG_FILL_FOP_NUMBER(co, GF_FOP_RENAME, fop_fn, xtra_len); - if (barrier_enabled && stub) { - gf_msg_debug (this->name, 0, "Enqueue unlink"); - goto out; - } - if (barrier_enabled && !stub) { - gf_smsg (this->name, GF_LOG_ERROR, ENOMEM, - CHANGELOG_MSG_NO_MEMORY, - "Failed to barrier FOPs, disabling changelog barrier", - "fop=unlink", - NULL); - chlog_barrier_dequeue_all (this, &queue); - } + co++; + strncpy(old_name, info->buffer, info->oldname_len); + CHANGELOG_FILL_ENTRY(co, info->old_pargfid, old_name, entry_fn, + entry_free_fn, xtra_len, wind); -/* changelog barrier */ + co++; + /* new name resides just after old name */ + nname = info->buffer + info->oldname_len; + strncpy(new_name, nname, info->newname_len); + CHANGELOG_FILL_ENTRY(co, info->new_pargfid, new_name, entry_fn, + entry_free_fn, xtra_len, wind); + + changelog_set_usable_record_and_length(frame->local, xtra_len, 3); + } else { /* default unlink */ + CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, wind); + CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, loc->inode->gfid, 2); + + co = changelog_get_usable_buffer(frame->local); + if (!co) + goto wind; - wind: - STACK_WIND (frame, changelog_unlink_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->unlink, - loc, xflags, xdata); - out: - return 0; + CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len); + + co++; + if (priv->capture_del_path) { + CHANGELOG_FILL_ENTRY_DIR_PATH(co, loc->pargfid, loc->name, + del_entry_fn, del_entry_free_fn, + xtra_len, wind, _gf_true); + } else { + CHANGELOG_FILL_ENTRY_DIR_PATH(co, loc->pargfid, loc->name, + del_entry_fn, del_entry_free_fn, + xtra_len, wind, _gf_false); + } + + changelog_set_usable_record_and_length(frame->local, xtra_len, 2); + } + + /* changelog barrier */ + LOCK(&priv->lock); + { + if ((barrier_enabled = priv->barrier_enabled)) { + stub = fop_unlink_stub(frame, changelog_unlink_resume, loc, xflags, + xdata); + if (!stub) + __chlog_barrier_disable(this, &queue); + else + __chlog_barrier_enqueue(this, stub); + } else { + ((changelog_local_t *)frame->local)->color = priv->current_color; + changelog_inc_fop_cnt(this, priv, frame->local); + } + } + UNLOCK(&priv->lock); + + if (barrier_enabled && stub) { + gf_msg_debug(this->name, 0, "Enqueue unlink"); + goto out; + } + if (barrier_enabled && !stub) { + gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY, + "Failed to barrier FOPs, disabling changelog barrier", + "fop=unlink", NULL); + chlog_barrier_dequeue_all(this, &queue); + } + + /* changelog barrier */ + +wind: + STACK_WIND(frame, changelog_unlink_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->unlink, loc, xflags, xdata); +out: + return 0; } /* rename */ int32_t -changelog_rename_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - struct iatt *buf, struct iatt *preoldparent, - struct iatt *postoldparent, struct iatt *prenewparent, - struct iatt *postnewparent, dict_t *xdata) -{ - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; - - priv = this->private; - local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (rename, frame, op_ret, op_errno, - buf, preoldparent, postoldparent, - prenewparent, postnewparent, xdata); - return 0; +changelog_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *buf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t *xdata) +{ + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; + + priv = this->private; + local = frame->local; + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); + changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY); +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(rename, frame, op_ret, op_errno, buf, preoldparent, + postoldparent, prenewparent, postnewparent, xdata); + return 0; } int32_t -changelog_rename_resume (call_frame_t *frame, xlator_t *this, - loc_t *oldloc, loc_t *newloc, dict_t *xdata) +changelog_rename_resume(call_frame_t *frame, xlator_t *this, loc_t *oldloc, + loc_t *newloc, dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; + priv = this->private; - gf_msg_debug (this->name, 0, "Dequeue rename"); - changelog_color_fop_and_inc_cnt - (this, priv, frame->local); - STACK_WIND (frame, changelog_rename_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->rename, - oldloc, newloc, xdata); - return 0; + gf_msg_debug(this->name, 0, "Dequeue rename"); + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_rename_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->rename, oldloc, newloc, xdata); + return 0; } int32_t -changelog_rename (call_frame_t *frame, xlator_t *this, - loc_t *oldloc, loc_t *newloc, dict_t *xdata) -{ - size_t xtra_len = 0; - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - call_stub_t *stub = NULL; - struct list_head queue = {0, }; - gf_boolean_t barrier_enabled = _gf_false; - dht_changelog_rename_info_t *info = NULL; - int ret = 0; - - INIT_LIST_HEAD (&queue); - - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); - - ret = dict_get_bin (xdata, DHT_CHANGELOG_RENAME_OP_KEY, (void **)&info); - if (ret && oldloc->inode->ia_type != IA_IFDIR) { - /* xdata "NOT" set for a non-directory, - * Special rename => avoid logging */ - goto wind; - } - - /* 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); -/* changelog barrier */ - LOCK (&priv->lock); - { - if ((barrier_enabled = priv->barrier_enabled)) { - stub = fop_rename_stub (frame, changelog_rename_resume, - oldloc, newloc, xdata); - if (!stub) - __chlog_barrier_disable (this, &queue); - else - __chlog_barrier_enqueue (this, stub); - } else { - ((changelog_local_t *)frame->local)->color - = priv->current_color; - changelog_inc_fop_cnt (this, priv, frame->local); - } - } - UNLOCK (&priv->lock); - - if (barrier_enabled && stub) { - gf_msg_debug (this->name, 0, "Enqueue rename"); - goto out; - } - if (barrier_enabled && !stub) { - gf_smsg (this->name, GF_LOG_ERROR, ENOMEM, - CHANGELOG_MSG_NO_MEMORY, - "Failed to barrier FOPs, disabling changelog barrier", - "fop=rename", - NULL); - chlog_barrier_dequeue_all (this, &queue); - } -/* changelog barrier */ - - wind: - STACK_WIND (frame, changelog_rename_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->rename, - oldloc, newloc, xdata); - out: - return 0; +changelog_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, + loc_t *newloc, dict_t *xdata) +{ + size_t xtra_len = 0; + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + call_stub_t *stub = NULL; + struct list_head queue = { + 0, + }; + gf_boolean_t barrier_enabled = _gf_false; + dht_changelog_rename_info_t *info = NULL; + int ret = 0; + + INIT_LIST_HEAD(&queue); + + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); + + ret = dict_get_bin(xdata, DHT_CHANGELOG_RENAME_OP_KEY, (void **)&info); + if (ret && oldloc->inode->ia_type != IA_IFDIR) { + /* xdata "NOT" set for a non-directory, + * Special rename => avoid logging */ + goto wind; + } + + /* 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); + /* changelog barrier */ + LOCK(&priv->lock); + { + if ((barrier_enabled = priv->barrier_enabled)) { + stub = fop_rename_stub(frame, changelog_rename_resume, oldloc, + newloc, xdata); + if (!stub) + __chlog_barrier_disable(this, &queue); + else + __chlog_barrier_enqueue(this, stub); + } else { + ((changelog_local_t *)frame->local)->color = priv->current_color; + changelog_inc_fop_cnt(this, priv, frame->local); + } + } + UNLOCK(&priv->lock); + + if (barrier_enabled && stub) { + gf_msg_debug(this->name, 0, "Enqueue rename"); + goto out; + } + if (barrier_enabled && !stub) { + gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY, + "Failed to barrier FOPs, disabling changelog barrier", + "fop=rename", NULL); + chlog_barrier_dequeue_all(this, &queue); + } + /* changelog barrier */ + +wind: + STACK_WIND(frame, changelog_rename_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->rename, oldloc, newloc, xdata); +out: + return 0; } /* link */ int32_t -changelog_link_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, int32_t op_ret, - int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +changelog_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY); + changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (link, frame, op_ret, op_errno, - inode, buf, preparent, postparent, xdata); - return 0; +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(link, frame, op_ret, op_errno, inode, buf, preparent, + postparent, xdata); + return 0; } int32_t -changelog_link_resume (call_frame_t *frame, xlator_t *this, - loc_t *oldloc, loc_t *newloc, dict_t *xdata) +changelog_link_resume(call_frame_t *frame, xlator_t *this, loc_t *oldloc, + loc_t *newloc, dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - GF_VALIDATE_OR_GOTO ("changelog", this, out); - GF_VALIDATE_OR_GOTO ("changelog", this->fops, out); - GF_VALIDATE_OR_GOTO ("changelog", frame, out); + GF_VALIDATE_OR_GOTO("changelog", this, out); + GF_VALIDATE_OR_GOTO("changelog", this->fops, out); + GF_VALIDATE_OR_GOTO("changelog", frame, out); - priv = this->private; + priv = this->private; - gf_msg_debug (this->name, 0, "Dequeuing link"); - changelog_color_fop_and_inc_cnt - (this, priv, frame->local); - STACK_WIND (frame, changelog_link_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->link, - oldloc, newloc, xdata); - return 0; + gf_msg_debug(this->name, 0, "Dequeuing link"); + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_link_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata); + return 0; out: - return -1; + return -1; } int32_t -changelog_link (call_frame_t *frame, - xlator_t *this, loc_t *oldloc, - loc_t *newloc, dict_t *xdata) -{ - size_t xtra_len = 0; - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - call_stub_t *stub = NULL; - struct list_head queue = {0, }; - gf_boolean_t barrier_enabled = _gf_false; - - priv = this->private; - - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); - CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, wind); - - 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); - - LOCK (&priv->lock); - { - if ((barrier_enabled = priv->barrier_enabled)) { - stub = fop_link_stub (frame, changelog_link_resume, - oldloc, newloc, xdata); - if (!stub) - __chlog_barrier_disable (this, &queue); - else - __chlog_barrier_enqueue (this, stub); - } else { - ((changelog_local_t *)frame->local)->color - = priv->current_color; - changelog_inc_fop_cnt (this, priv, frame->local); - } - } - UNLOCK (&priv->lock); - - if (barrier_enabled && stub) { - gf_msg_debug (this->name, 0, "Enqueued link"); - goto out; - } - - if (barrier_enabled && !stub) { - gf_smsg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_NO_MEMORY, - "Failed to barrier FOPs, disabling changelog barrier", - "fop=link", - NULL); - chlog_barrier_dequeue_all (this, &queue); - } - wind: - STACK_WIND (frame, changelog_link_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->link, - oldloc, newloc, xdata); +changelog_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, + loc_t *newloc, dict_t *xdata) +{ + size_t xtra_len = 0; + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + call_stub_t *stub = NULL; + struct list_head queue = { + 0, + }; + gf_boolean_t barrier_enabled = _gf_false; + + priv = this->private; + + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); + CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, wind); + + 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); + + LOCK(&priv->lock); + { + if ((barrier_enabled = priv->barrier_enabled)) { + stub = fop_link_stub(frame, changelog_link_resume, oldloc, newloc, + xdata); + if (!stub) + __chlog_barrier_disable(this, &queue); + else + __chlog_barrier_enqueue(this, stub); + } else { + ((changelog_local_t *)frame->local)->color = priv->current_color; + changelog_inc_fop_cnt(this, priv, frame->local); + } + } + UNLOCK(&priv->lock); + + if (barrier_enabled && stub) { + gf_msg_debug(this->name, 0, "Enqueued link"); + goto out; + } + + if (barrier_enabled && !stub) { + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_NO_MEMORY, + "Failed to barrier FOPs, disabling changelog barrier", + "fop=link", NULL); + chlog_barrier_dequeue_all(this, &queue); + } +wind: + STACK_WIND(frame, changelog_link_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata); out: - return 0; + return 0; } /* mkdir */ int32_t -changelog_mkdir_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, int32_t op_ret, - int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +changelog_mkdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY); + changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (mkdir, frame, op_ret, op_errno, - inode, buf, preparent, postparent, xdata); - return 0; +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(mkdir, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); + return 0; } int32_t -changelog_mkdir_resume (call_frame_t *frame, xlator_t *this, - loc_t *loc, mode_t mode, - mode_t umask, dict_t *xdata) +changelog_mkdir_resume(call_frame_t *frame, xlator_t *this, loc_t *loc, + mode_t mode, mode_t umask, dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - GF_VALIDATE_OR_GOTO ("changelog", this, out); - GF_VALIDATE_OR_GOTO ("changelog", this->fops, out); - GF_VALIDATE_OR_GOTO ("changelog", frame, out); + GF_VALIDATE_OR_GOTO("changelog", this, out); + GF_VALIDATE_OR_GOTO("changelog", this->fops, out); + GF_VALIDATE_OR_GOTO("changelog", frame, out); - priv = this->private; + priv = this->private; - gf_msg_debug (this->name, 0, "Dequeuing mkdir"); - changelog_color_fop_and_inc_cnt - (this, priv, frame->local); - STACK_WIND (frame, changelog_mkdir_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->mkdir, - loc, mode, umask, xdata); - return 0; + gf_msg_debug(this->name, 0, "Dequeuing mkdir"); + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_mkdir_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->mkdir, loc, mode, umask, xdata); + return 0; out: - return -1; + return -1; } int32_t -changelog_mkdir (call_frame_t *frame, xlator_t *this, - loc_t *loc, mode_t mode, mode_t umask, dict_t *xdata) -{ - int ret = -1; - uuid_t gfid = {0,}; - size_t xtra_len = 0; - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - call_stub_t *stub = NULL; - struct list_head queue = {0, }; - gf_boolean_t barrier_enabled = _gf_false; - - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); - - ret = dict_get_gfuuid (xdata, "gfid-req", &gfid); - if (ret) { - gf_msg_debug (this->name, 0, - "failed to get gfid from dict"); - goto wind; - } - - 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); - - LOCK (&priv->lock); - { - if ((barrier_enabled = priv->barrier_enabled)) { - stub = fop_mkdir_stub (frame, changelog_mkdir_resume, - loc, mode, umask, xdata); - if (!stub) - __chlog_barrier_disable (this, &queue); - else - __chlog_barrier_enqueue (this, stub); - } else { - ((changelog_local_t *)frame->local)->color - = priv->current_color; - changelog_inc_fop_cnt (this, priv, frame->local); - } - } - UNLOCK (&priv->lock); - - if (barrier_enabled && stub) { - gf_msg_debug (this->name, 0, "Enqueued mkdir"); - goto out; - } - - if (barrier_enabled && !stub) { - gf_smsg (this->name, GF_LOG_ERROR, ENOMEM, - CHANGELOG_MSG_NO_MEMORY, - "Failed to barrier FOPs, disabling changelog barrier", - "fop=mkdir", - NULL); - chlog_barrier_dequeue_all (this, &queue); - } - - wind: - STACK_WIND (frame, changelog_mkdir_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->mkdir, - loc, mode, umask, xdata); +changelog_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, + mode_t umask, dict_t *xdata) +{ + int ret = -1; + uuid_t gfid = { + 0, + }; + size_t xtra_len = 0; + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + call_stub_t *stub = NULL; + struct list_head queue = { + 0, + }; + gf_boolean_t barrier_enabled = _gf_false; + + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); + + ret = dict_get_gfuuid(xdata, "gfid-req", &gfid); + if (ret) { + gf_msg_debug(this->name, 0, "failed to get gfid from dict"); + goto wind; + } + + 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); + + LOCK(&priv->lock); + { + if ((barrier_enabled = priv->barrier_enabled)) { + stub = fop_mkdir_stub(frame, changelog_mkdir_resume, loc, mode, + umask, xdata); + if (!stub) + __chlog_barrier_disable(this, &queue); + else + __chlog_barrier_enqueue(this, stub); + } else { + ((changelog_local_t *)frame->local)->color = priv->current_color; + changelog_inc_fop_cnt(this, priv, frame->local); + } + } + UNLOCK(&priv->lock); + + if (barrier_enabled && stub) { + gf_msg_debug(this->name, 0, "Enqueued mkdir"); + goto out; + } + + if (barrier_enabled && !stub) { + gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY, + "Failed to barrier FOPs, disabling changelog barrier", + "fop=mkdir", NULL); + chlog_barrier_dequeue_all(this, &queue); + } + +wind: + STACK_WIND(frame, changelog_mkdir_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->mkdir, loc, mode, umask, xdata); out: - return 0; + return 0; } /* symlink */ int32_t -changelog_symlink_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +changelog_symlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY); + changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (symlink, frame, op_ret, op_errno, - inode, buf, preparent, postparent, xdata); - return 0; +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(symlink, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); + return 0; } - int32_t -changelog_symlink_resume (call_frame_t *frame, xlator_t *this, - const char *linkname, loc_t *loc, - mode_t umask, dict_t *xdata) +changelog_symlink_resume(call_frame_t *frame, xlator_t *this, + const char *linkname, loc_t *loc, mode_t umask, + dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - GF_VALIDATE_OR_GOTO ("changelog", this, out); - GF_VALIDATE_OR_GOTO ("changelog", this->fops, out); - GF_VALIDATE_OR_GOTO ("changelog", frame, out); + GF_VALIDATE_OR_GOTO("changelog", this, out); + GF_VALIDATE_OR_GOTO("changelog", this->fops, out); + GF_VALIDATE_OR_GOTO("changelog", frame, out); - priv = this->private; + priv = this->private; - gf_msg_debug (this->name, 0, "Dequeuing symlink"); - changelog_color_fop_and_inc_cnt - (this, priv, frame->local); - STACK_WIND (frame, changelog_symlink_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->symlink, - linkname, loc, umask, xdata); - return 0; + gf_msg_debug(this->name, 0, "Dequeuing symlink"); + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_symlink_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->symlink, linkname, loc, umask, xdata); + return 0; out: - return -1; + return -1; } int32_t -changelog_symlink (call_frame_t *frame, xlator_t *this, - const char *linkname, loc_t *loc, - mode_t umask, dict_t *xdata) -{ - int ret = -1; - size_t xtra_len = 0; - uuid_t gfid = {0,}; - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - call_stub_t *stub = NULL; - struct list_head queue = {0, }; - gf_boolean_t barrier_enabled = _gf_false; - - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); - - ret = dict_get_gfuuid (xdata, "gfid-req", &gfid); - if (ret) { - gf_msg_debug (this->name, 0, - "failed to get gfid from dict"); - goto wind; - } - - 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); - - LOCK (&priv->lock); - { - if ((barrier_enabled = priv->barrier_enabled)) { - stub = fop_symlink_stub (frame, - changelog_symlink_resume, - linkname, loc, umask, xdata); - if (!stub) - __chlog_barrier_disable (this, &queue); - else - __chlog_barrier_enqueue (this, stub); - } else { - ((changelog_local_t *)frame->local)->color - = priv->current_color; - changelog_inc_fop_cnt (this, priv, frame->local); - } - } - UNLOCK (&priv->lock); - - if (barrier_enabled && stub) { - gf_msg_debug (this->name, 0, "Enqueued symlink"); - goto out; - } - - if (barrier_enabled && !stub) { - gf_smsg (this->name, GF_LOG_ERROR, ENOMEM, - CHANGELOG_MSG_NO_MEMORY, - "Failed to barrier FOPs, disabling changelog barrier", - "fop=symlink", - NULL); - chlog_barrier_dequeue_all (this, &queue); - } - - wind: - STACK_WIND (frame, changelog_symlink_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->symlink, - linkname, loc, umask, xdata); +changelog_symlink(call_frame_t *frame, xlator_t *this, const char *linkname, + loc_t *loc, mode_t umask, dict_t *xdata) +{ + int ret = -1; + size_t xtra_len = 0; + uuid_t gfid = { + 0, + }; + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + call_stub_t *stub = NULL; + struct list_head queue = { + 0, + }; + gf_boolean_t barrier_enabled = _gf_false; + + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); + + ret = dict_get_gfuuid(xdata, "gfid-req", &gfid); + if (ret) { + gf_msg_debug(this->name, 0, "failed to get gfid from dict"); + goto wind; + } + + 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); + + LOCK(&priv->lock); + { + if ((barrier_enabled = priv->barrier_enabled)) { + stub = fop_symlink_stub(frame, changelog_symlink_resume, linkname, + loc, umask, xdata); + if (!stub) + __chlog_barrier_disable(this, &queue); + else + __chlog_barrier_enqueue(this, stub); + } else { + ((changelog_local_t *)frame->local)->color = priv->current_color; + changelog_inc_fop_cnt(this, priv, frame->local); + } + } + UNLOCK(&priv->lock); + + if (barrier_enabled && stub) { + gf_msg_debug(this->name, 0, "Enqueued symlink"); + goto out; + } + + if (barrier_enabled && !stub) { + gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY, + "Failed to barrier FOPs, disabling changelog barrier", + "fop=symlink", NULL); + chlog_barrier_dequeue_all(this, &queue); + } + +wind: + STACK_WIND(frame, changelog_symlink_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->symlink, linkname, loc, umask, xdata); out: - return 0; + return 0; } /* mknod */ int32_t -changelog_mknod_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +changelog_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY); + changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (mknod, frame, op_ret, op_errno, - inode, buf, preparent, postparent, xdata); - return 0; +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(mknod, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); + return 0; } int32_t -changelog_mknod_resume (call_frame_t *frame, xlator_t *this, - loc_t *loc, mode_t mode, dev_t rdev, - mode_t umask, dict_t *xdata) +changelog_mknod_resume(call_frame_t *frame, xlator_t *this, loc_t *loc, + mode_t mode, dev_t rdev, mode_t umask, dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - GF_VALIDATE_OR_GOTO ("changelog", this, out); - GF_VALIDATE_OR_GOTO ("changelog", this->fops, out); - GF_VALIDATE_OR_GOTO ("changelog", frame, out); + GF_VALIDATE_OR_GOTO("changelog", this, out); + GF_VALIDATE_OR_GOTO("changelog", this->fops, out); + GF_VALIDATE_OR_GOTO("changelog", frame, out); - priv = this->private; + priv = this->private; - gf_msg_debug (this->name, 0, "Dequeuing mknod"); - changelog_color_fop_and_inc_cnt - (this, priv, frame->local); - STACK_WIND (frame, changelog_mknod_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->mknod, - loc, mode, rdev, umask, xdata); - return 0; + gf_msg_debug(this->name, 0, "Dequeuing mknod"); + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_mknod_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->mknod, loc, mode, rdev, umask, xdata); + return 0; out: - return -1; + return -1; } int32_t -changelog_mknod (call_frame_t *frame, - xlator_t *this, loc_t *loc, - mode_t mode, dev_t dev, mode_t umask, dict_t *xdata) -{ - int ret = -1; - uuid_t gfid = {0,}; - size_t xtra_len = 0; - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - call_stub_t *stub = NULL; - struct list_head queue = {0, }; - gf_boolean_t barrier_enabled = _gf_false; - - priv = this->private; - - /* Check whether changelog active */ - if (!(priv->active)) - goto wind; - - /* Check whether rebalance activity */ - if (frame->root->pid == GF_CLIENT_PID_DEFRAG) - goto wind; - - /* If tier-dht linkto is SET, ignore about verifiying : - * 1. Whether internal fop AND - * 2. Whether tier rebalance process activity (this will help in - * recording mknod if tier rebalance process calls this mknod) */ - if (!(dict_get (xdata, "trusted.tier.tier-dht.linkto"))) { - CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, wind); - if (frame->root->pid == GF_CLIENT_PID_TIER_DEFRAG) - goto wind; - } - - ret = dict_get_gfuuid (xdata, "gfid-req", &gfid); - if (ret) { - gf_msg_debug (this->name, 0, - "failed to get gfid from dict"); - goto wind; - } - - 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); - - LOCK (&priv->lock); - { - if ((barrier_enabled = priv->barrier_enabled)) { - stub = fop_mknod_stub (frame, changelog_mknod_resume, - loc, mode, dev, umask, xdata); - if (!stub) - __chlog_barrier_disable (this, &queue); - else - __chlog_barrier_enqueue (this, stub); - } else { - ((changelog_local_t *)frame->local)->color - = priv->current_color; - changelog_inc_fop_cnt (this, priv, frame->local); - } - } - UNLOCK (&priv->lock); - - if (barrier_enabled && stub) { - gf_msg_debug (this->name, 0, "Enqueued mknod"); - goto out; - } - - if (barrier_enabled && !stub) { - gf_smsg (this->name, GF_LOG_ERROR, ENOMEM, - CHANGELOG_MSG_NO_MEMORY, - "Failed to barrier FOPs, disabling changelog barrier", - "fop=mknod", - NULL); - chlog_barrier_dequeue_all (this, &queue); - } - - wind: - STACK_WIND (frame, changelog_mknod_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->mknod, - loc, mode, dev, umask, xdata); +changelog_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, + dev_t dev, mode_t umask, dict_t *xdata) +{ + int ret = -1; + uuid_t gfid = { + 0, + }; + size_t xtra_len = 0; + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + call_stub_t *stub = NULL; + struct list_head queue = { + 0, + }; + gf_boolean_t barrier_enabled = _gf_false; + + priv = this->private; + + /* Check whether changelog active */ + if (!(priv->active)) + goto wind; + + /* Check whether rebalance activity */ + if (frame->root->pid == GF_CLIENT_PID_DEFRAG) + goto wind; + + /* If tier-dht linkto is SET, ignore about verifiying : + * 1. Whether internal fop AND + * 2. Whether tier rebalance process activity (this will help in + * recording mknod if tier rebalance process calls this mknod) */ + if (!(dict_get(xdata, "trusted.tier.tier-dht.linkto"))) { + CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, wind); + if (frame->root->pid == GF_CLIENT_PID_TIER_DEFRAG) + goto wind; + } + + ret = dict_get_gfuuid(xdata, "gfid-req", &gfid); + if (ret) { + gf_msg_debug(this->name, 0, "failed to get gfid from dict"); + goto wind; + } + + 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); + + LOCK(&priv->lock); + { + if ((barrier_enabled = priv->barrier_enabled)) { + stub = fop_mknod_stub(frame, changelog_mknod_resume, loc, mode, dev, + umask, xdata); + if (!stub) + __chlog_barrier_disable(this, &queue); + else + __chlog_barrier_enqueue(this, stub); + } else { + ((changelog_local_t *)frame->local)->color = priv->current_color; + changelog_inc_fop_cnt(this, priv, frame->local); + } + } + UNLOCK(&priv->lock); + + if (barrier_enabled && stub) { + gf_msg_debug(this->name, 0, "Enqueued mknod"); + goto out; + } + + if (barrier_enabled && !stub) { + gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY, + "Failed to barrier FOPs, disabling changelog barrier", + "fop=mknod", NULL); + chlog_barrier_dequeue_all(this, &queue); + } + +wind: + STACK_WIND(frame, changelog_mknod_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->mknod, loc, mode, dev, umask, xdata); out: - return 0; + return 0; } /* create */ int32_t -changelog_create_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - fd_t *fd, inode_t *inode, struct iatt *buf, - struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +changelog_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - int32_t ret = 0; - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; - changelog_event_t ev = {0,}; - - priv = this->private; - local = frame->local; - - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); - - /* fill the event structure.. similar to open() */ - ev.ev_type = CHANGELOG_OP_TYPE_CREATE; - gf_uuid_copy (ev.u.create.gfid, buf->ia_gfid); - ev.u.create.flags = fd->flags; - changelog_dispatch_event (this, priv, &ev); - - if (changelog_ev_selected - (this, &priv->ev_selection, CHANGELOG_OP_TYPE_RELEASE)) { - ret = fd_ctx_set (fd, this, (uint64_t)(long) 0x1); - if (ret) - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_MSG_SET_FD_CONTEXT, - "could not set fd context (for release cbk)"); - } + int32_t ret = 0; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; + changelog_event_t ev = { + 0, + }; - changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY); + priv = this->private; + local = frame->local; - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (create, frame, - op_ret, op_errno, fd, inode, - buf, preparent, postparent, xdata); - return 0; -} + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); -int32_t -changelog_create_resume (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; + /* fill the event structure.. similar to open() */ + ev.ev_type = CHANGELOG_OP_TYPE_CREATE; + gf_uuid_copy(ev.u.create.gfid, buf->ia_gfid); + ev.u.create.flags = fd->flags; + changelog_dispatch_event(this, priv, &ev); - GF_VALIDATE_OR_GOTO ("changelog", this, out); - GF_VALIDATE_OR_GOTO ("changelog", this->fops, out); - GF_VALIDATE_OR_GOTO ("changelog", frame, out); - - priv = this->private; + if (changelog_ev_selected(this, &priv->ev_selection, + CHANGELOG_OP_TYPE_RELEASE)) { + ret = fd_ctx_set(fd, this, (uint64_t)(long)0x1); + if (ret) + gf_msg(this->name, GF_LOG_WARNING, 0, CHANGELOG_MSG_SET_FD_CONTEXT, + "could not set fd context (for release cbk)"); + } - gf_msg_debug (this->name, 0, "Dequeuing create"); - changelog_color_fop_and_inc_cnt - (this, priv, frame->local); - STACK_WIND (frame, changelog_create_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->create, - loc, flags, mode, umask, fd, xdata); - return 0; + changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY); -out: - return -1; +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(create, frame, op_ret, op_errno, fd, inode, buf, + preparent, postparent, xdata); + return 0; } int32_t -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) -{ - int ret = -1; - uuid_t gfid = {0,}; - changelog_opt_t *co = NULL; - changelog_priv_t *priv = NULL; - size_t xtra_len = 0; - call_stub_t *stub = NULL; - struct list_head queue = {0, }; - gf_boolean_t barrier_enabled = _gf_false; - - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); - - ret = dict_get_gfuuid (xdata, "gfid-req", &gfid); - if (ret) { - gf_msg_debug (this->name, 0, - "failed to get gfid from dict"); - goto wind; - } - - /* 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_create_resume(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; - changelog_set_usable_record_and_length (frame->local, xtra_len, 5); + GF_VALIDATE_OR_GOTO("changelog", this, out); + GF_VALIDATE_OR_GOTO("changelog", this->fops, out); + GF_VALIDATE_OR_GOTO("changelog", frame, out); - LOCK (&priv->lock); - { - if ((barrier_enabled = priv->barrier_enabled)) { - stub = fop_create_stub (frame, changelog_create_resume, - loc, flags, mode, umask, fd, - xdata); - if (!stub) - __chlog_barrier_disable (this, &queue); - else - __chlog_barrier_enqueue (this, stub); - } else { - ((changelog_local_t *)frame->local)->color - = priv->current_color; - changelog_inc_fop_cnt (this, priv, frame->local); - } - } - UNLOCK (&priv->lock); + priv = this->private; - if (barrier_enabled && stub) { - gf_msg_debug (this->name, 0, "Enqueued create"); - goto out; - } + gf_msg_debug(this->name, 0, "Dequeuing create"); + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_create_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->create, loc, flags, mode, umask, fd, + xdata); + return 0; - if (barrier_enabled && !stub) { - gf_smsg (this->name, GF_LOG_ERROR, ENOMEM, - CHANGELOG_MSG_NO_MEMORY, - "Failed to barrier FOPs, disabling changelog barrier", - "fop=create", - NULL); - chlog_barrier_dequeue_all (this, &queue); - } +out: + return -1; +} - wind: - STACK_WIND (frame, changelog_create_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->create, - loc, flags, mode, umask, fd, xdata); +int32_t +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) +{ + int ret = -1; + uuid_t gfid = { + 0, + }; + changelog_opt_t *co = NULL; + changelog_priv_t *priv = NULL; + size_t xtra_len = 0; + call_stub_t *stub = NULL; + struct list_head queue = { + 0, + }; + gf_boolean_t barrier_enabled = _gf_false; + + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); + + ret = dict_get_gfuuid(xdata, "gfid-req", &gfid); + if (ret) { + gf_msg_debug(this->name, 0, "failed to get gfid from dict"); + goto wind; + } + + /* 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); + + LOCK(&priv->lock); + { + if ((barrier_enabled = priv->barrier_enabled)) { + stub = fop_create_stub(frame, changelog_create_resume, loc, flags, + mode, umask, fd, xdata); + if (!stub) + __chlog_barrier_disable(this, &queue); + else + __chlog_barrier_enqueue(this, stub); + } else { + ((changelog_local_t *)frame->local)->color = priv->current_color; + changelog_inc_fop_cnt(this, priv, frame->local); + } + } + UNLOCK(&priv->lock); + + if (barrier_enabled && stub) { + gf_msg_debug(this->name, 0, "Enqueued create"); + goto out; + } + + if (barrier_enabled && !stub) { + gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY, + "Failed to barrier FOPs, disabling changelog barrier", + "fop=create", NULL); + chlog_barrier_dequeue_all(this, &queue); + } + +wind: + STACK_WIND(frame, changelog_create_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->create, loc, flags, mode, umask, fd, + xdata); out: - return 0; + return 0; } /* }}} */ - /* Metadata modification fops - TYPE II */ /* {{{ */ @@ -1158,268 +1106,253 @@ out: /* {f}setattr */ int32_t -changelog_fsetattr_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, int32_t op_ret, - int32_t op_errno, struct iatt *preop_stbuf, - struct iatt *postop_stbuf, dict_t *xdata) +changelog_fsetattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *preop_stbuf, struct iatt *postop_stbuf, + dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; - - priv = this->private; - local = frame->local; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + priv = this->private; + local = frame->local; - changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (fsetattr, frame, op_ret, op_errno, - preop_stbuf, postop_stbuf, xdata); - - return 0; + changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA); +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(fsetattr, frame, op_ret, op_errno, preop_stbuf, + postop_stbuf, xdata); + return 0; } int32_t -changelog_fsetattr (call_frame_t *frame, - xlator_t *this, fd_t *fd, - struct iatt *stbuf, int32_t valid, dict_t *xdata) +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_opt_t *co = NULL; - size_t xtra_len = 0; - - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + size_t xtra_len = 0; - CHANGELOG_OP_BOUNDARY_CHECK (frame, wind); + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); - CHANGELOG_INIT (this, frame->local, - fd->inode, fd->inode->gfid, 1); - if (!frame->local) - goto wind; + CHANGELOG_OP_BOUNDARY_CHECK(frame, 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_INIT(this, frame->local, fd->inode, fd->inode->gfid, 1); + if (!frame->local) + goto wind; - changelog_set_usable_record_and_length (frame->local, xtra_len, 1); + co = changelog_get_usable_buffer(frame->local); + if (!co) + goto wind; - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_fsetattr_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->fsetattr, - fd, stbuf, valid, xdata); - return 0; + CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len); + changelog_set_usable_record_and_length(frame->local, xtra_len, 1); +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_fsetattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fsetattr, fd, stbuf, valid, xdata); + return 0; } int32_t -changelog_setattr_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, int32_t op_ret, - int32_t op_errno, struct iatt *preop_stbuf, - struct iatt *postop_stbuf, dict_t *xdata) +changelog_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *preop_stbuf, struct iatt *postop_stbuf, + dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA); + changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (setattr, frame, op_ret, op_errno, - preop_stbuf, postop_stbuf, xdata); +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(setattr, frame, op_ret, op_errno, preop_stbuf, + postop_stbuf, xdata); - return 0; + return 0; } int32_t -changelog_setattr (call_frame_t *frame, - xlator_t *this, loc_t *loc, - struct iatt *stbuf, int32_t valid, dict_t *xdata) +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_opt_t *co = NULL; - size_t xtra_len = 0; - uuid_t shard_root_gfid = {0,}; + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + size_t xtra_len = 0; + uuid_t shard_root_gfid = { + 0, + }; - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); - CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, wind); + CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, wind); - /* Do not record META on .shard */ - gf_uuid_parse (SHARD_ROOT_GFID, shard_root_gfid); - if (gf_uuid_compare (loc->gfid, shard_root_gfid) == 0) { - goto wind; - } + /* Do not record META on .shard */ + gf_uuid_parse(SHARD_ROOT_GFID, shard_root_gfid); + if (gf_uuid_compare(loc->gfid, shard_root_gfid) == 0) { + goto wind; + } - CHANGELOG_OP_BOUNDARY_CHECK (frame, wind); + CHANGELOG_OP_BOUNDARY_CHECK(frame, wind); - CHANGELOG_INIT (this, frame->local, - loc->inode, loc->inode->gfid, 1); - if (!frame->local) - goto wind; + 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; + co = changelog_get_usable_buffer(frame->local); + if (!co) + goto wind; - CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len); + CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len); - changelog_set_usable_record_and_length (frame->local, xtra_len, 1); + changelog_set_usable_record_and_length(frame->local, xtra_len, 1); - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_setattr_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->setattr, - loc, stbuf, valid, xdata); - return 0; +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_setattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid, xdata); + return 0; } /* {f}removexattr */ int32_t -changelog_fremovexattr_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +changelog_fremovexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA_XATTR); + changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA_XATTR); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (fremovexattr, frame, op_ret, op_errno, xdata); +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(fremovexattr, frame, op_ret, op_errno, xdata); - return 0; + return 0; } int32_t -changelog_fremovexattr (call_frame_t *frame, xlator_t *this, - fd_t *fd, const char *name, dict_t *xdata) +changelog_fremovexattr(call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - size_t xtra_len = 0; + 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); + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); - CHANGELOG_OP_BOUNDARY_CHECK (frame, wind); + CHANGELOG_OP_BOUNDARY_CHECK(frame, wind); - CHANGELOG_INIT (this, frame->local, - fd->inode, fd->inode->gfid, 1); + CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 1); - co = changelog_get_usable_buffer (frame->local); - if (!co) - 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); + CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len); - changelog_set_usable_record_and_length (frame->local, xtra_len, 1); + changelog_set_usable_record_and_length(frame->local, xtra_len, 1); - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_fremovexattr_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->fremovexattr, - fd, name, xdata); - return 0; +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_fremovexattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fremovexattr, fd, name, xdata); + return 0; } int32_t -changelog_removexattr_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +changelog_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA_XATTR); + changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA_XATTR); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (removexattr, frame, op_ret, op_errno, xdata); +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(removexattr, frame, op_ret, op_errno, xdata); - return 0; + return 0; } int32_t -changelog_removexattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, const char *name, dict_t *xdata) +changelog_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc, + const char *name, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - size_t xtra_len = 0; + 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); + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); - CHANGELOG_OP_BOUNDARY_CHECK (frame, wind); + CHANGELOG_OP_BOUNDARY_CHECK(frame, wind); - CHANGELOG_INIT (this, frame->local, - loc->inode, loc->inode->gfid, 1); + CHANGELOG_INIT(this, frame->local, loc->inode, loc->inode->gfid, 1); - co = changelog_get_usable_buffer (frame->local); - if (!co) - 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); + CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len); - changelog_set_usable_record_and_length (frame->local, xtra_len, 1); + changelog_set_usable_record_and_length(frame->local, xtra_len, 1); - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_removexattr_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->removexattr, - loc, name, xdata); - return 0; +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_removexattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->removexattr, loc, name, xdata); + return 0; } /* {f}setxattr */ int32_t -changelog_setxattr_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +changelog_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA_XATTR); + changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA_XATTR); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (setxattr, frame, op_ret, op_errno, xdata); +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(setxattr, frame, op_ret, op_errno, xdata); - return 0; + return 0; } /* changelog_handle_virtual_xattr: @@ -1432,276 +1365,258 @@ changelog_setxattr_cbk (call_frame_t *frame, * any other value: ENOTSUP is returned. */ static void -changelog_handle_virtual_xattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, dict_t *dict) +changelog_handle_virtual_xattr(call_frame_t *frame, xlator_t *this, loc_t *loc, + dict_t *dict) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; - int32_t value = 0; - int ret = 0; - int dict_ret = 0; - gf_boolean_t valid = _gf_false; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; + int32_t value = 0; + int ret = 0; + int dict_ret = 0; + gf_boolean_t valid = _gf_false; - priv = this->private; - GF_ASSERT (priv); + priv = this->private; + GF_ASSERT(priv); - dict_ret = dict_get_int32 (dict, GF_XATTR_TRIGGER_SYNC, &value); + dict_ret = dict_get_int32(dict, GF_XATTR_TRIGGER_SYNC, &value); - if ((dict_ret == 0 && value == 1) && ((loc->inode->ia_type == IA_IFDIR) - || (loc->inode->ia_type == IA_IFREG))) - valid = _gf_true; + if ((dict_ret == 0 && value == 1) && ((loc->inode->ia_type == IA_IFDIR) || + (loc->inode->ia_type == IA_IFREG))) + valid = _gf_true; - if (valid) { - ret = changelog_fill_entry_buf (frame, this, loc, &local); - if (ret) { - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_ENTRY_BUF_INFO, - "Entry cannot be" - " captured for gfid, Capturing DATA" - " entry.", - "gfid=%s", uuid_utoa (loc->inode->gfid), - NULL); - goto unwind; - } - changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY); - - unwind: - /* Capture DATA only if it's a file. */ - if (loc->inode->ia_type != IA_IFDIR) - changelog_update (this, priv, frame->local, - CHANGELOG_TYPE_DATA); - /* Assign local to prev_entry, so unwind will take - * care of cleanup. */ - ((changelog_local_t *)(frame->local))->prev_entry = local; - CHANGELOG_STACK_UNWIND (setxattr, frame, 0, 0, NULL); - return; - } else { - CHANGELOG_STACK_UNWIND (setxattr, frame, -1, ENOTSUP, NULL); - return; - } + if (valid) { + ret = changelog_fill_entry_buf(frame, this, loc, &local); + if (ret) { + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_ENTRY_BUF_INFO, + "Entry cannot be" + " captured for gfid, Capturing DATA" + " entry.", + "gfid=%s", uuid_utoa(loc->inode->gfid), NULL); + goto unwind; + } + changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY); + + unwind: + /* Capture DATA only if it's a file. */ + if (loc->inode->ia_type != IA_IFDIR) + changelog_update(this, priv, frame->local, CHANGELOG_TYPE_DATA); + /* Assign local to prev_entry, so unwind will take + * care of cleanup. */ + ((changelog_local_t *)(frame->local))->prev_entry = local; + CHANGELOG_STACK_UNWIND(setxattr, frame, 0, 0, NULL); + return; + } else { + CHANGELOG_STACK_UNWIND(setxattr, frame, -1, ENOTSUP, NULL); + return; + } } int32_t -changelog_setxattr (call_frame_t *frame, - xlator_t *this, loc_t *loc, - dict_t *dict, int32_t flags, dict_t *xdata) +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_opt_t *co = NULL; - size_t xtra_len = 0; + 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); + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); - CHANGELOG_OP_BOUNDARY_CHECK (frame, wind); + CHANGELOG_OP_BOUNDARY_CHECK(frame, wind); - CHANGELOG_INIT (this, frame->local, - loc->inode, loc->inode->gfid, 1); + CHANGELOG_INIT(this, frame->local, loc->inode, loc->inode->gfid, 1); - /* On setting this virtual xattr on a file, an explicit data - * sync is triggered from geo-rep as CREATE|DATA entry is - * recorded in changelog based on xattr value. - */ - if (dict_get (dict, GF_XATTR_TRIGGER_SYNC)) { - changelog_handle_virtual_xattr (frame, this, loc, dict); - return 0; - } + /* On setting this virtual xattr on a file, an explicit data + * sync is triggered from geo-rep as CREATE|DATA entry is + * recorded in changelog based on xattr value. + */ + if (dict_get(dict, GF_XATTR_TRIGGER_SYNC)) { + changelog_handle_virtual_xattr(frame, this, loc, dict); + return 0; + } - co = changelog_get_usable_buffer (frame->local); - if (!co) - 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); + CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len); - changelog_set_usable_record_and_length (frame->local, xtra_len, 1); + changelog_set_usable_record_and_length(frame->local, xtra_len, 1); - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_setxattr_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->setxattr, - loc, dict, flags, xdata); - return 0; +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_setxattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->setxattr, loc, dict, flags, xdata); + return 0; } int32_t -changelog_fsetxattr_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, int32_t op_ret, - int32_t op_errno, dict_t *xdata) +changelog_fsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA_XATTR); + changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA_XATTR); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (fsetxattr, frame, op_ret, op_errno, xdata); +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(fsetxattr, frame, op_ret, op_errno, xdata); - return 0; + return 0; } int32_t -changelog_fsetxattr (call_frame_t *frame, - xlator_t *this, fd_t *fd, dict_t *dict, - int32_t flags, dict_t *xdata) +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_opt_t *co = NULL; - size_t xtra_len = 0; + 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_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, wind); + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); + CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, wind); - CHANGELOG_OP_BOUNDARY_CHECK (frame, wind); + CHANGELOG_OP_BOUNDARY_CHECK(frame, wind); - CHANGELOG_INIT (this, frame->local, - fd->inode, fd->inode->gfid, 1); + CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 1); - co = changelog_get_usable_buffer (frame->local); - if (!co) - 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); + CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len); - changelog_set_usable_record_and_length (frame->local, xtra_len, 1); + changelog_set_usable_record_and_length(frame->local, xtra_len, 1); - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_fsetxattr_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->fsetxattr, - fd, dict, flags, xdata); - return 0; +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_fsetxattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata); + return 0; } int32_t -changelog_xattrop_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, int32_t op_ret, - int32_t op_errno, dict_t *xattr, dict_t *xdata) +changelog_xattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xattr, + dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA); + changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (xattrop, frame, op_ret, op_errno, xattr, xdata); +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(xattrop, frame, op_ret, op_errno, xattr, xdata); - return 0; + return 0; } int32_t -changelog_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, - gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata) +changelog_xattrop(call_frame_t *frame, xlator_t *this, loc_t *loc, + gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - size_t xtra_len = 0; - int ret = 0; - void *size_attr = NULL; + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + size_t xtra_len = 0; + int ret = 0; + void *size_attr = NULL; - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); - ret = dict_get_ptr (xattr, GF_XATTR_SHARD_FILE_SIZE, &size_attr); - if (ret) - goto wind; + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); + ret = dict_get_ptr(xattr, GF_XATTR_SHARD_FILE_SIZE, &size_attr); + if (ret) + goto wind; - CHANGELOG_OP_BOUNDARY_CHECK (frame, wind); + CHANGELOG_OP_BOUNDARY_CHECK(frame, wind); - CHANGELOG_INIT (this, frame->local, - loc->inode, loc->inode->gfid, 1); + CHANGELOG_INIT(this, frame->local, loc->inode, loc->inode->gfid, 1); - co = changelog_get_usable_buffer (frame->local); - if (!co) - 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); + CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len); - changelog_set_usable_record_and_length (frame->local, xtra_len, 1); + changelog_set_usable_record_and_length(frame->local, xtra_len, 1); - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_xattrop_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->xattrop, - loc, optype, xattr, xdata); - return 0; +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_xattrop_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->xattrop, loc, optype, xattr, xdata); + return 0; } int32_t -changelog_fxattrop_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, int32_t op_ret, - int32_t op_errno, dict_t *xattr, dict_t *xdata) +changelog_fxattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xattr, + dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA_XATTR); + changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA_XATTR); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (fxattrop, frame, - op_ret, op_errno, xattr, xdata); +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(fxattrop, frame, op_ret, op_errno, xattr, xdata); - return 0; + return 0; } int32_t -changelog_fxattrop (call_frame_t *frame, - xlator_t *this, fd_t *fd, gf_xattrop_flags_t optype, - dict_t *xattr, dict_t *xdata) -{ - changelog_priv_t *priv = NULL; - changelog_opt_t *co = NULL; - size_t xtra_len = 0; - void *size_attr = NULL; - int ret = 0; - - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); - ret = dict_get_ptr (xattr, GF_XATTR_SHARD_FILE_SIZE, &size_attr); - if (ret) - goto wind; +changelog_fxattrop(call_frame_t *frame, xlator_t *this, fd_t *fd, + gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata) +{ + changelog_priv_t *priv = NULL; + changelog_opt_t *co = NULL; + size_t xtra_len = 0; + void *size_attr = NULL; + int ret = 0; + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); + ret = dict_get_ptr(xattr, GF_XATTR_SHARD_FILE_SIZE, &size_attr); + if (ret) + goto wind; - CHANGELOG_OP_BOUNDARY_CHECK (frame, wind); + CHANGELOG_OP_BOUNDARY_CHECK(frame, wind); - CHANGELOG_INIT (this, frame->local, - fd->inode, fd->inode->gfid, 1); + CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 1); - co = changelog_get_usable_buffer (frame->local); - if (!co) - 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); + CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len); - changelog_set_usable_record_and_length (frame->local, xtra_len, 1); + changelog_set_usable_record_and_length(frame->local, xtra_len, 1); - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_fxattrop_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->fxattrop, - fd, optype, xattr, xdata); - return 0; +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_fxattrop_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fxattrop, fd, optype, xattr, xdata); + return 0; } /* }}} */ - /* Data modification fops - TYPE I */ /* {{{ */ @@ -1709,164 +1624,151 @@ changelog_fxattrop (call_frame_t *frame, /* {f}truncate() */ int32_t -changelog_truncate_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, int32_t op_ret, - int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +changelog_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_DATA); + changelog_update(this, priv, local, CHANGELOG_TYPE_DATA); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (truncate, frame, - op_ret, op_errno, prebuf, postbuf, xdata); - return 0; +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(truncate, frame, op_ret, op_errno, prebuf, postbuf, + xdata); + return 0; } int32_t -changelog_truncate (call_frame_t *frame, - xlator_t *this, loc_t *loc, off_t offset, dict_t *xdata) +changelog_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, + off_t offset, dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); - CHANGELOG_INIT (this, frame->local, - loc->inode, loc->inode->gfid, 0); - LOCK(&priv->c_snap_lock); - { - if (priv->c_snap_fd != -1 && - priv->barrier_enabled == _gf_true) { - changelog_snap_handle_ascii_change (this, - &( ((changelog_local_t *)(frame->local))->cld)); - } + CHANGELOG_INIT(this, frame->local, loc->inode, loc->inode->gfid, 0); + LOCK(&priv->c_snap_lock); + { + if (priv->c_snap_fd != -1 && priv->barrier_enabled == _gf_true) { + changelog_snap_handle_ascii_change( + this, &(((changelog_local_t *)(frame->local))->cld)); } - UNLOCK(&priv->c_snap_lock); - + } + UNLOCK(&priv->c_snap_lock); - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_truncate_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->truncate, - loc, offset, xdata); - return 0; +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_truncate_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->truncate, loc, offset, xdata); + return 0; } int32_t -changelog_ftruncate_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, int32_t op_ret, - int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +changelog_ftruncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_DATA); + changelog_update(this, priv, local, CHANGELOG_TYPE_DATA); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (ftruncate, frame, - op_ret, op_errno, prebuf, postbuf, xdata); - return 0; +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(ftruncate, frame, op_ret, op_errno, prebuf, postbuf, + xdata); + return 0; } int32_t -changelog_ftruncate (call_frame_t *frame, - xlator_t *this, fd_t *fd, off_t offset, dict_t *xdata) +changelog_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); - CHANGELOG_INIT (this, frame->local, - fd->inode, fd->inode->gfid, 0); - LOCK(&priv->c_snap_lock); - { - if (priv->c_snap_fd != -1 && - priv->barrier_enabled == _gf_true) { - changelog_snap_handle_ascii_change (this, - &( ((changelog_local_t *)(frame->local))->cld)); - } + CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 0); + LOCK(&priv->c_snap_lock); + { + if (priv->c_snap_fd != -1 && priv->barrier_enabled == _gf_true) { + changelog_snap_handle_ascii_change( + this, &(((changelog_local_t *)(frame->local))->cld)); } - UNLOCK(&priv->c_snap_lock); + } + UNLOCK(&priv->c_snap_lock); - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_ftruncate_cbk, - FIRST_CHILD (this), FIRST_CHILD (this)->fops->ftruncate, - fd, offset, xdata); - return 0; +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_ftruncate_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata); + return 0; } /* writev() */ int32_t -changelog_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, - dict_t *xdata) +changelog_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - changelog_priv_t *priv = NULL; - changelog_local_t *local = NULL; + changelog_priv_t *priv = NULL; + changelog_local_t *local = NULL; - priv = this->private; - local = frame->local; + priv = this->private; + local = frame->local; - CHANGELOG_COND_GOTO (priv, ((op_ret <= 0) || !local), unwind); + CHANGELOG_COND_GOTO(priv, ((op_ret <= 0) || !local), unwind); - changelog_update (this, priv, local, CHANGELOG_TYPE_DATA); + changelog_update(this, priv, local, CHANGELOG_TYPE_DATA); - unwind: - changelog_dec_fop_cnt (this, priv, local); - CHANGELOG_STACK_UNWIND (writev, frame, - op_ret, op_errno, prebuf, postbuf, xdata); - return 0; +unwind: + changelog_dec_fop_cnt(this, priv, local); + CHANGELOG_STACK_UNWIND(writev, frame, op_ret, op_errno, prebuf, postbuf, + xdata); + return 0; } int32_t -changelog_writev (call_frame_t *frame, - xlator_t *this, fd_t *fd, struct iovec *vector, - int32_t count, off_t offset, uint32_t flags, - struct iobref *iobref, dict_t *xdata) +changelog_writev(call_frame_t *frame, xlator_t *this, fd_t *fd, + struct iovec *vector, int32_t count, off_t offset, + uint32_t flags, struct iobref *iobref, dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); - CHANGELOG_INIT (this, frame->local, - fd->inode, fd->inode->gfid, 0); - LOCK(&priv->c_snap_lock); - { - if (priv->c_snap_fd != -1 && - priv->barrier_enabled == _gf_true) { - changelog_snap_handle_ascii_change (this, - &( ((changelog_local_t *)(frame->local))->cld)); - } + CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 0); + LOCK(&priv->c_snap_lock); + { + if (priv->c_snap_fd != -1 && priv->barrier_enabled == _gf_true) { + changelog_snap_handle_ascii_change( + this, &(((changelog_local_t *)(frame->local))->cld)); } - UNLOCK(&priv->c_snap_lock); + } + UNLOCK(&priv->c_snap_lock); - wind: - changelog_color_fop_and_inc_cnt (this, priv, frame->local); - STACK_WIND (frame, changelog_writev_cbk, FIRST_CHILD (this), - FIRST_CHILD (this)->fops->writev, fd, vector, - count, offset, flags, iobref, xdata); - return 0; +wind: + changelog_color_fop_and_inc_cnt(this, priv, frame->local); + STACK_WIND(frame, changelog_writev_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->writev, fd, vector, count, offset, + flags, iobref, xdata); + return 0; } /* }}} */ @@ -1875,81 +1777,79 @@ changelog_writev (call_frame_t *frame, /* {{{ */ - - int -changelog_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, fd_t *fd, dict_t *xdata) -{ - int ret = 0; - changelog_priv_t *priv = NULL; - changelog_event_t ev = {0,}; - gf_boolean_t logopen = _gf_false; - - priv = this->private; - if (frame->local) { - frame->local = NULL; - logopen = _gf_true; - } - - CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !logopen), unwind); - - /* fill the event structure */ - ev.ev_type = CHANGELOG_OP_TYPE_OPEN; - gf_uuid_copy (ev.u.open.gfid, fd->inode->gfid); - ev.u.open.flags = fd->flags; - changelog_dispatch_event (this, priv, &ev); - - if (changelog_ev_selected - (this, &priv->ev_selection, CHANGELOG_OP_TYPE_RELEASE)) { - ret = fd_ctx_set (fd, this, (uint64_t)(long) 0x1); - if (ret) - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_MSG_SET_FD_CONTEXT, - "could not set fd context (for release cbk)"); - } +changelog_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, fd_t *fd, dict_t *xdata) +{ + int ret = 0; + changelog_priv_t *priv = NULL; + changelog_event_t ev = { + 0, + }; + gf_boolean_t logopen = _gf_false; + + priv = this->private; + if (frame->local) { + frame->local = NULL; + logopen = _gf_true; + } + + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !logopen), unwind); + + /* fill the event structure */ + ev.ev_type = CHANGELOG_OP_TYPE_OPEN; + gf_uuid_copy(ev.u.open.gfid, fd->inode->gfid); + ev.u.open.flags = fd->flags; + changelog_dispatch_event(this, priv, &ev); + + if (changelog_ev_selected(this, &priv->ev_selection, + CHANGELOG_OP_TYPE_RELEASE)) { + ret = fd_ctx_set(fd, this, (uint64_t)(long)0x1); + if (ret) + gf_msg(this->name, GF_LOG_WARNING, 0, CHANGELOG_MSG_SET_FD_CONTEXT, + "could not set fd context (for release cbk)"); + } - unwind: - CHANGELOG_STACK_UNWIND (open, frame, op_ret, op_errno, fd, xdata); - return 0; +unwind: + CHANGELOG_STACK_UNWIND(open, frame, op_ret, op_errno, fd, xdata); + return 0; } int -changelog_open (call_frame_t *frame, xlator_t *this, - loc_t *loc, int flags, fd_t *fd, dict_t *xdata) +changelog_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, + fd_t *fd, dict_t *xdata) { - changelog_priv_t *priv = NULL; + changelog_priv_t *priv = NULL; - priv = this->private; - CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind); + priv = this->private; + CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind); - frame->local = (void *)0x1; /* do not dereference in ->cbk */ + frame->local = (void *)0x1; /* do not dereference in ->cbk */ - wind: - STACK_WIND (frame, changelog_open_cbk, FIRST_CHILD (this), - FIRST_CHILD (this)->fops->open, loc, flags, fd, xdata); - return 0; +wind: + STACK_WIND(frame, changelog_open_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata); + return 0; } /* }}} */ /* {{{ */ - /* }}} */ int32_t -_changelog_generic_dispatcher (dict_t *dict, - char *key, data_t *value, void *data) +_changelog_generic_dispatcher(dict_t *dict, char *key, data_t *value, + void *data) { - xlator_t *this = NULL; - changelog_priv_t *priv = NULL; + xlator_t *this = NULL; + changelog_priv_t *priv = NULL; - this = data; - priv = this->private; + this = data; + priv = this->private; - changelog_dispatch_event (this, priv, (changelog_event_t *)value->data); - return 0; + changelog_dispatch_event(this, priv, (changelog_event_t *)value->data); + return 0; } /** @@ -1958,46 +1858,45 @@ _changelog_generic_dispatcher (dict_t *dict, * traverses the dictionary). */ int32_t -changelog_ipc (call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata) +changelog_ipc(call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata) { - if (op != GF_IPC_TARGET_CHANGELOG) - goto wind; + if (op != GF_IPC_TARGET_CHANGELOG) + goto wind; - /* it's for us, do the job */ - if (xdata) - (void) dict_foreach (xdata, - _changelog_generic_dispatcher, this); + /* it's for us, do the job */ + if (xdata) + (void)dict_foreach(xdata, _changelog_generic_dispatcher, this); - STACK_UNWIND_STRICT (ipc, frame, 0, 0, NULL); - return 0; + STACK_UNWIND_STRICT(ipc, frame, 0, 0, NULL); + return 0; - wind: - STACK_WIND (frame, default_ipc_cbk, FIRST_CHILD (this), - FIRST_CHILD (this)->fops->ipc, op, xdata); - return 0; +wind: + STACK_WIND(frame, default_ipc_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->ipc, op, xdata); + return 0; } - /* {{{ */ int32_t -changelog_release (xlator_t *this, fd_t *fd) +changelog_release(xlator_t *this, fd_t *fd) { - changelog_event_t ev = {0,}; - changelog_priv_t *priv = NULL; + changelog_event_t ev = { + 0, + }; + changelog_priv_t *priv = NULL; - priv = this->private; + priv = this->private; - ev.ev_type = CHANGELOG_OP_TYPE_RELEASE; - gf_uuid_copy (ev.u.release.gfid, fd->inode->gfid); - changelog_dispatch_event (this, priv, &ev); + ev.ev_type = CHANGELOG_OP_TYPE_RELEASE; + gf_uuid_copy(ev.u.release.gfid, fd->inode->gfid); + changelog_dispatch_event(this, priv, &ev); - (void) fd_ctx_del (fd, this, NULL); + (void)fd_ctx_del(fd, this, NULL); - return 0; + return 0; } - /* }}} */ /** @@ -2012,1040 +1911,1002 @@ changelog_release (xlator_t *this, fd_t *fd) * needed if there are more operation modes in the future. */ static void -changelog_assign_opmode (changelog_priv_t *priv, char *mode) +changelog_assign_opmode(changelog_priv_t *priv, char *mode) { - if ( strncmp (mode, "realtime", 8) == 0 ) { - priv->op_mode = CHANGELOG_MODE_RT; - } + if (strncmp(mode, "realtime", 8) == 0) { + priv->op_mode = CHANGELOG_MODE_RT; + } } static void -changelog_assign_encoding (changelog_priv_t *priv, char *enc) +changelog_assign_encoding(changelog_priv_t *priv, char *enc) { - if ( strncmp (enc, "binary", 6) == 0 ) { - priv->encode_mode = CHANGELOG_ENCODE_BINARY; - } else if ( strncmp (enc, "ascii", 5) == 0 ) { - priv->encode_mode = CHANGELOG_ENCODE_ASCII; - } + if (strncmp(enc, "binary", 6) == 0) { + priv->encode_mode = CHANGELOG_ENCODE_BINARY; + } else if (strncmp(enc, "ascii", 5) == 0) { + priv->encode_mode = CHANGELOG_ENCODE_ASCII; + } } static void changelog_assign_barrier_timeout(changelog_priv_t *priv, uint32_t timeout) { - LOCK (&priv->lock); - { - priv->timeout.tv_sec = timeout; - } - UNLOCK (&priv->lock); + LOCK(&priv->lock); + { + priv->timeout.tv_sec = timeout; + } + UNLOCK(&priv->lock); } /* cleanup any helper threads that are running */ static void -changelog_cleanup_helper_threads (xlator_t *this, changelog_priv_t *priv) +changelog_cleanup_helper_threads(xlator_t *this, changelog_priv_t *priv) { - if (priv->cr.rollover_th) { - (void) changelog_thread_cleanup (this, priv->cr.rollover_th); - priv->cr.rollover_th = 0; - } + if (priv->cr.rollover_th) { + (void)changelog_thread_cleanup(this, priv->cr.rollover_th); + priv->cr.rollover_th = 0; + } - if (priv->cf.fsync_th) { - (void) changelog_thread_cleanup (this, priv->cf.fsync_th); - priv->cf.fsync_th = 0; - } + if (priv->cf.fsync_th) { + (void)changelog_thread_cleanup(this, priv->cf.fsync_th); + priv->cf.fsync_th = 0; + } } /* spawn helper thread; cleaning up in case of errors */ static int -changelog_spawn_helper_threads (xlator_t *this, changelog_priv_t *priv) -{ - int ret = 0; - - /* Geo-Rep snapshot dependency: - * - * To implement explicit rollover of changlog journal on barrier - * notification, a pipe is created to communicate between - * 'changelog_rollover' thread and changelog main thread. The select - * call used to wait till roll-over time in changelog_rollover thread - * is modified to wait on read end of the pipe. When barrier - * notification comes (i.e, in 'reconfigure'), select in - * changelog_rollover thread is woken up explicitly by writing into - * the write end of the pipe in 'reconfigure'. - */ - - priv->cr.notify = _gf_false; - priv->cr.this = this; - ret = gf_thread_create (&priv->cr.rollover_th, - NULL, changelog_rollover, priv, "clogro"); - if (ret) - goto out; - - if (priv->fsync_interval) { - priv->cf.this = this; - ret = gf_thread_create (&priv->cf.fsync_th, - NULL, changelog_fsync_thread, priv, - "clogfsyn"); - } +changelog_spawn_helper_threads(xlator_t *this, changelog_priv_t *priv) +{ + int ret = 0; + + /* Geo-Rep snapshot dependency: + * + * To implement explicit rollover of changlog journal on barrier + * notification, a pipe is created to communicate between + * 'changelog_rollover' thread and changelog main thread. The select + * call used to wait till roll-over time in changelog_rollover thread + * is modified to wait on read end of the pipe. When barrier + * notification comes (i.e, in 'reconfigure'), select in + * changelog_rollover thread is woken up explicitly by writing into + * the write end of the pipe in 'reconfigure'. + */ + + priv->cr.notify = _gf_false; + priv->cr.this = this; + ret = gf_thread_create(&priv->cr.rollover_th, NULL, changelog_rollover, + priv, "clogro"); + if (ret) + goto out; + + if (priv->fsync_interval) { + priv->cf.this = this; + ret = gf_thread_create(&priv->cf.fsync_th, NULL, changelog_fsync_thread, + priv, "clogfsyn"); + } + + if (ret) + changelog_cleanup_helper_threads(this, priv); - if (ret) - changelog_cleanup_helper_threads (this, priv); - - out: - return ret; +out: + return ret; } int -notify (xlator_t *this, int event, void *data, ...) -{ - changelog_priv_t *priv = NULL; - dict_t *dict = NULL; - char buf[1] = {1}; - int barrier = DICT_DEFAULT; - gf_boolean_t bclean_req = _gf_false; - int ret = 0; - int ret1 = 0; - struct list_head queue = {0, }; - - INIT_LIST_HEAD (&queue); - - priv = this->private; - if (!priv) +notify(xlator_t *this, int event, void *data, ...) +{ + changelog_priv_t *priv = NULL; + dict_t *dict = NULL; + char buf[1] = {1}; + int barrier = DICT_DEFAULT; + gf_boolean_t bclean_req = _gf_false; + int ret = 0; + int ret1 = 0; + struct list_head queue = { + 0, + }; + + INIT_LIST_HEAD(&queue); + + priv = this->private; + if (!priv) + goto out; + + if (event == GF_EVENT_TRANSLATOR_OP) { + dict = data; + + barrier = dict_get_str_boolean(dict, "barrier", DICT_DEFAULT); + + switch (barrier) { + case DICT_ERROR: + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_DICT_GET_FAILED, + "Barrier dict_get_str_boolean failed"); + ret = -1; goto out; - if (event == GF_EVENT_TRANSLATOR_OP) { + case BARRIER_OFF: + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO, + "Barrier off notification"); - dict = data; - - barrier = dict_get_str_boolean (dict, "barrier", DICT_DEFAULT); + CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, out); + LOCK(&priv->c_snap_lock); + { + changelog_snap_logging_stop(this, priv); + } + UNLOCK(&priv->c_snap_lock); - switch (barrier) { - case DICT_ERROR: - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_DICT_GET_FAILED, - "Barrier dict_get_str_boolean failed"); - ret = -1; - goto out; - - case BARRIER_OFF: - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BARRIER_INFO, - "Barrier off notification"); - - CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, out); - LOCK(&priv->c_snap_lock); - { - changelog_snap_logging_stop (this, priv); - } - UNLOCK(&priv->c_snap_lock); - - LOCK (&priv->bflags.lock); - { - if (priv->bflags.barrier_ext == _gf_false) - ret = -1; - } - UNLOCK (&priv->bflags.lock); - - if (ret == -1 ) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_BARRIER_ERROR, - "Received another barrier off" - " notification while already off"); - goto out; - } - - /* Stop changelog barrier and dequeue all fops */ - LOCK (&priv->lock); - { - if (priv->barrier_enabled == _gf_true) - __chlog_barrier_disable (this, &queue); - else - ret = -1; - } - UNLOCK (&priv->lock); - /* If ret = -1, then changelog barrier is already - * disabled because of error or timeout. - */ - if (ret == 0) { - chlog_barrier_dequeue_all(this, &queue); - gf_msg(this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BARRIER_INFO, - "Disabled changelog barrier"); - } else { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_BARRIER_ERROR, - "Changelog barrier already disabled"); - } - - LOCK (&priv->bflags.lock); - { - priv->bflags.barrier_ext = _gf_false; - } - UNLOCK (&priv->bflags.lock); - - goto out; - - case BARRIER_ON: - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BARRIER_INFO, - "Barrier on notification"); - - CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, out); - LOCK(&priv->c_snap_lock); - { - changelog_snap_logging_start (this, priv); - } - UNLOCK(&priv->c_snap_lock); - - LOCK (&priv->bflags.lock); - { - if (priv->bflags.barrier_ext == _gf_true) - ret = -1; - else - priv->bflags.barrier_ext = _gf_true; - } - UNLOCK (&priv->bflags.lock); - - if (ret == -1 ) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_BARRIER_ERROR, - "Received another barrier on" - "notification when last one is" - "not served yet"); - goto out; - } - - ret = pthread_mutex_lock (&priv->bn.bnotify_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret, out, - bclean_req); - { - priv->bn.bnotify = _gf_true; - } - ret = pthread_mutex_unlock (&priv->bn.bnotify_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret, out, - bclean_req); - - /* Start changelog barrier */ - LOCK (&priv->lock); - { - ret = __chlog_barrier_enable (this, priv); - } - UNLOCK (&priv->lock); - if (ret == -1) { - changelog_barrier_cleanup (this, priv, &queue); - goto out; - } - - gf_msg(this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BARRIER_INFO, - "Enabled changelog barrier"); - - ret = changelog_barrier_notify(priv, buf); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_WRITE_FAILED, - "Explicit roll over: write failed"); - changelog_barrier_cleanup (this, priv, &queue); - ret = -1; - goto out; - } - - ret = pthread_mutex_lock (&priv->bn.bnotify_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret, out, - bclean_req); - { - /* The while condition check is required here to - * handle spurious wakeup of cond wait that can - * happen with pthreads. See man page */ - while (priv->bn.bnotify == _gf_true) { - ret = pthread_cond_wait ( - &priv->bn.bnotify_cond, - &priv->bn.bnotify_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret, - out, - bclean_req); - } - if (priv->bn.bnotify_error == _gf_true) { - ret = -1; - priv->bn.bnotify_error = _gf_false; - } - } - ret1 = pthread_mutex_unlock (&priv->bn.bnotify_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret1, out, - bclean_req); - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BNOTIFY_INFO, - "Woke up: bnotify conditional wait"); - - goto out; - - case DICT_DEFAULT: - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_DICT_GET_FAILED, - "barrier key not found"); + LOCK(&priv->bflags.lock); + { + if (priv->bflags.barrier_ext == _gf_false) ret = -1; - goto out; + } + UNLOCK(&priv->bflags.lock); + + if (ret == -1) { + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_BARRIER_ERROR, + "Received another barrier off" + " notification while already off"); + goto out; + } - default: - gf_msg (this->name, GF_LOG_ERROR, EINVAL, - CHANGELOG_MSG_DICT_GET_FAILED, - "Something went bad in dict_get_str_boolean"); + /* Stop changelog barrier and dequeue all fops */ + LOCK(&priv->lock); + { + if (priv->barrier_enabled == _gf_true) + __chlog_barrier_disable(this, &queue); + else ret = -1; - goto out; } - } else { - ret = default_notify (this, event, data); - } + UNLOCK(&priv->lock); + /* If ret = -1, then changelog barrier is already + * disabled because of error or timeout. + */ + if (ret == 0) { + chlog_barrier_dequeue_all(this, &queue); + gf_msg(this->name, GF_LOG_INFO, 0, + CHANGELOG_MSG_BARRIER_INFO, + "Disabled changelog barrier"); + } else { + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_BARRIER_ERROR, + "Changelog barrier already disabled"); + } - out: - if (bclean_req) - changelog_barrier_cleanup (this, priv, &queue); + LOCK(&priv->bflags.lock); + { + priv->bflags.barrier_ext = _gf_false; + } + UNLOCK(&priv->bflags.lock); - return ret; -} + goto out; -int32_t -mem_acct_init (xlator_t *this) -{ - int ret = -1; + case BARRIER_ON: + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO, + "Barrier on notification"); - if (!this) - return ret; + CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, out); + LOCK(&priv->c_snap_lock); + { + changelog_snap_logging_start(this, priv); + } + UNLOCK(&priv->c_snap_lock); - ret = xlator_mem_acct_init (this, gf_changelog_mt_end + 1); + LOCK(&priv->bflags.lock); + { + if (priv->bflags.barrier_ext == _gf_true) + ret = -1; + else + priv->bflags.barrier_ext = _gf_true; + } + UNLOCK(&priv->bflags.lock); + + if (ret == -1) { + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_BARRIER_ERROR, + "Received another barrier on" + "notification when last one is" + "not served yet"); + goto out; + } - if (ret != 0) { - gf_msg (this->name, GF_LOG_WARNING, ENOMEM, - CHANGELOG_MSG_NO_MEMORY, "Memory accounting" - " init failed"); - return ret; - } + ret = pthread_mutex_lock(&priv->bn.bnotify_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret, out, bclean_req); + { + priv->bn.bnotify = _gf_true; + } + ret = pthread_mutex_unlock(&priv->bn.bnotify_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret, out, bclean_req); - return ret; -} + /* Start changelog barrier */ + LOCK(&priv->lock); + { + ret = __chlog_barrier_enable(this, priv); + } + UNLOCK(&priv->lock); + if (ret == -1) { + changelog_barrier_cleanup(this, priv, &queue); + goto out; + } -static int -changelog_init (xlator_t *this, changelog_priv_t *priv) -{ - int i = 0; - int ret = -1; - struct timeval tv = {0,}; - changelog_log_data_t cld = {0,}; + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO, + "Enabled changelog barrier"); - ret = gettimeofday (&tv, NULL); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_GET_TIME_OP_FAILED, - "gettimeofday() failure"); - goto out; - } + ret = changelog_barrier_notify(priv, buf); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_WRITE_FAILED, + "Explicit roll over: write failed"); + changelog_barrier_cleanup(this, priv, &queue); + ret = -1; + goto out; + } + + ret = pthread_mutex_lock(&priv->bn.bnotify_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret, out, bclean_req); + { + /* The while condition check is required here to + * handle spurious wakeup of cond wait that can + * happen with pthreads. See man page */ + while (priv->bn.bnotify == _gf_true) { + ret = pthread_cond_wait(&priv->bn.bnotify_cond, + &priv->bn.bnotify_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret, out, bclean_req); + } + if (priv->bn.bnotify_error == _gf_true) { + ret = -1; + priv->bn.bnotify_error = _gf_false; + } + } + ret1 = pthread_mutex_unlock(&priv->bn.bnotify_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret1, out, bclean_req); + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BNOTIFY_INFO, + "Woke up: bnotify conditional wait"); - priv->slice.tv_start = tv; + goto out; - priv->maps[CHANGELOG_TYPE_DATA] = "D "; - priv->maps[CHANGELOG_TYPE_METADATA] = "M "; - priv->maps[CHANGELOG_TYPE_METADATA_XATTR] = "M "; - priv->maps[CHANGELOG_TYPE_ENTRY] = "E "; + case DICT_DEFAULT: + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_DICT_GET_FAILED, "barrier key not found"); + ret = -1; + goto out; - for (; i < CHANGELOG_MAX_TYPE; i++) { - /* start with version 1 */ - priv->slice.changelog_version[i] = 1; + default: + gf_msg(this->name, GF_LOG_ERROR, EINVAL, + CHANGELOG_MSG_DICT_GET_FAILED, + "Something went bad in dict_get_str_boolean"); + ret = -1; + goto out; } + } else { + ret = default_notify(this, event, data); + } - if (!priv->active) - return ret; +out: + if (bclean_req) + changelog_barrier_cleanup(this, priv, &queue); - /** - * 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; + return ret; +} - ret = htime_open (this, priv, cld.cld_roll_time); - /* call htime open with cld's rollover_time */ - if (ret) - goto out; +int32_t +mem_acct_init(xlator_t *this) +{ + int ret = -1; - LOCK (&priv->lock); - { - ret = changelog_inject_single_event (this, priv, &cld); - } - UNLOCK (&priv->lock); + if (!this) + return ret; - /* ... and finally spawn the helpers threads */ - ret = changelog_spawn_helper_threads (this, priv); + ret = xlator_mem_acct_init(this, gf_changelog_mt_end + 1); - out: + if (ret != 0) { + gf_msg(this->name, GF_LOG_WARNING, ENOMEM, CHANGELOG_MSG_NO_MEMORY, + "Memory accounting" + " init failed"); return ret; + } + + return ret; +} + +static int +changelog_init(xlator_t *this, changelog_priv_t *priv) +{ + int i = 0; + int ret = -1; + struct timeval tv = { + 0, + }; + changelog_log_data_t cld = { + 0, + }; + + ret = gettimeofday(&tv, NULL); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_GET_TIME_OP_FAILED, "gettimeofday() failure"); + goto out; + } + + priv->slice.tv_start = tv; + + priv->maps[CHANGELOG_TYPE_DATA] = "D "; + priv->maps[CHANGELOG_TYPE_METADATA] = "M "; + priv->maps[CHANGELOG_TYPE_METADATA_XATTR] = "M "; + priv->maps[CHANGELOG_TYPE_ENTRY] = "E "; + + for (; i < CHANGELOG_MAX_TYPE; i++) { + /* start with version 1 */ + priv->slice.changelog_version[i] = 1; + } + + if (!priv->active) + return ret; + + /** + * 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; + + ret = htime_open(this, priv, cld.cld_roll_time); + /* call htime open with cld's rollover_time */ + if (ret) + goto out; + + LOCK(&priv->lock); + { + ret = changelog_inject_single_event(this, priv, &cld); + } + UNLOCK(&priv->lock); + + /* ... and finally spawn the helpers threads */ + ret = changelog_spawn_helper_threads(this, priv); + +out: + return ret; } /** * Init barrier related condition variables and locks */ static int -changelog_barrier_pthread_init (xlator_t *this, changelog_priv_t *priv) -{ - gf_boolean_t bn_mutex_init = _gf_false; - gf_boolean_t bn_cond_init = _gf_false; - gf_boolean_t dm_mutex_black_init = _gf_false; - gf_boolean_t dm_cond_black_init = _gf_false; - gf_boolean_t dm_mutex_white_init = _gf_false; - gf_boolean_t dm_cond_white_init = _gf_false; - gf_boolean_t cr_mutex_init = _gf_false; - gf_boolean_t cr_cond_init = _gf_false; - int ret = 0; - - if ((ret = pthread_mutex_init(&priv->bn.bnotify_mutex, NULL)) != 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED, - "bnotify pthread_mutex_init failed", - "ret=%d", ret, - NULL); - ret = -1; - goto out; - } - bn_mutex_init = _gf_true; - - if ((ret = pthread_cond_init(&priv->bn.bnotify_cond, NULL)) != 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED, - "bnotify pthread_cond_init failed", - "ret=%d", ret, - NULL); - ret = -1; - goto out; - } - bn_cond_init = _gf_true; - - if ((ret = pthread_mutex_init(&priv->dm.drain_black_mutex, NULL)) != 0) - { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED, - "drain_black pthread_mutex_init failed", - "ret=%d", ret, - NULL); - ret = -1; - goto out; - } - dm_mutex_black_init = _gf_true; - - if ((ret = pthread_cond_init(&priv->dm.drain_black_cond, NULL)) != 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED, - "drain_black pthread_cond_init failed", - "ret=%d", ret, - NULL); - ret = -1; - goto out; - } - dm_cond_black_init = _gf_true; - - if ((ret = pthread_mutex_init(&priv->dm.drain_white_mutex, NULL)) != 0) - { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED, - "drain_white pthread_mutex_init failed", - "ret=%d", ret, - NULL); - ret = -1; - goto out; - } - dm_mutex_white_init = _gf_true; - - if ((ret = pthread_cond_init(&priv->dm.drain_white_cond, NULL)) != 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED, - "drain_white pthread_cond_init failed", - "ret=%d", ret, - NULL); - ret = -1; - goto out; - } - dm_cond_white_init = _gf_true; - - if ((pthread_mutex_init(&priv->cr.lock, NULL)) != 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED, - "changelog_rollover lock init failed", - "ret=%d", ret, - NULL); - ret = -1; - goto out; - } - cr_mutex_init = _gf_true; - - if ((pthread_cond_init(&priv->cr.cond, NULL)) != 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED, - "changelog_rollover cond init failed", - "ret=%d", ret, - NULL); - ret = -1; - goto out; - } - cr_cond_init = _gf_true; - out: - if (ret) { - if (bn_mutex_init) - pthread_mutex_destroy(&priv->bn.bnotify_mutex); - if (bn_cond_init) - pthread_cond_destroy (&priv->bn.bnotify_cond); - if (dm_mutex_black_init) - pthread_mutex_destroy(&priv->dm.drain_black_mutex); - if (dm_cond_black_init) - pthread_cond_destroy (&priv->dm.drain_black_cond); - if (dm_mutex_white_init) - pthread_mutex_destroy(&priv->dm.drain_white_mutex); - if (dm_cond_white_init) - pthread_cond_destroy (&priv->dm.drain_white_cond); - if (cr_mutex_init) - pthread_mutex_destroy(&priv->cr.lock); - if (cr_cond_init) - pthread_cond_destroy (&priv->cr.cond); - } - return ret; +changelog_barrier_pthread_init(xlator_t *this, changelog_priv_t *priv) +{ + gf_boolean_t bn_mutex_init = _gf_false; + gf_boolean_t bn_cond_init = _gf_false; + gf_boolean_t dm_mutex_black_init = _gf_false; + gf_boolean_t dm_cond_black_init = _gf_false; + gf_boolean_t dm_mutex_white_init = _gf_false; + gf_boolean_t dm_cond_white_init = _gf_false; + gf_boolean_t cr_mutex_init = _gf_false; + gf_boolean_t cr_cond_init = _gf_false; + int ret = 0; + + if ((ret = pthread_mutex_init(&priv->bn.bnotify_mutex, NULL)) != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED, + "bnotify pthread_mutex_init failed", "ret=%d", ret, NULL); + ret = -1; + goto out; + } + bn_mutex_init = _gf_true; + + if ((ret = pthread_cond_init(&priv->bn.bnotify_cond, NULL)) != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED, + "bnotify pthread_cond_init failed", "ret=%d", ret, NULL); + ret = -1; + goto out; + } + bn_cond_init = _gf_true; + + if ((ret = pthread_mutex_init(&priv->dm.drain_black_mutex, NULL)) != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED, + "drain_black pthread_mutex_init failed", "ret=%d", ret, NULL); + ret = -1; + goto out; + } + dm_mutex_black_init = _gf_true; + + if ((ret = pthread_cond_init(&priv->dm.drain_black_cond, NULL)) != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED, + "drain_black pthread_cond_init failed", "ret=%d", ret, NULL); + ret = -1; + goto out; + } + dm_cond_black_init = _gf_true; + + if ((ret = pthread_mutex_init(&priv->dm.drain_white_mutex, NULL)) != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED, + "drain_white pthread_mutex_init failed", "ret=%d", ret, NULL); + ret = -1; + goto out; + } + dm_mutex_white_init = _gf_true; + + if ((ret = pthread_cond_init(&priv->dm.drain_white_cond, NULL)) != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED, + "drain_white pthread_cond_init failed", "ret=%d", ret, NULL); + ret = -1; + goto out; + } + dm_cond_white_init = _gf_true; + + if ((pthread_mutex_init(&priv->cr.lock, NULL)) != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED, + "changelog_rollover lock init failed", "ret=%d", ret, NULL); + ret = -1; + goto out; + } + cr_mutex_init = _gf_true; + + if ((pthread_cond_init(&priv->cr.cond, NULL)) != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED, + "changelog_rollover cond init failed", "ret=%d", ret, NULL); + ret = -1; + goto out; + } + cr_cond_init = _gf_true; +out: + if (ret) { + if (bn_mutex_init) + pthread_mutex_destroy(&priv->bn.bnotify_mutex); + if (bn_cond_init) + pthread_cond_destroy(&priv->bn.bnotify_cond); + if (dm_mutex_black_init) + pthread_mutex_destroy(&priv->dm.drain_black_mutex); + if (dm_cond_black_init) + pthread_cond_destroy(&priv->dm.drain_black_cond); + if (dm_mutex_white_init) + pthread_mutex_destroy(&priv->dm.drain_white_mutex); + if (dm_cond_white_init) + pthread_cond_destroy(&priv->dm.drain_white_cond); + if (cr_mutex_init) + pthread_mutex_destroy(&priv->cr.lock); + if (cr_cond_init) + pthread_cond_destroy(&priv->cr.cond); + } + return ret; } /* Destroy barrier related condition variables and locks */ static void -changelog_barrier_pthread_destroy (changelog_priv_t *priv) +changelog_barrier_pthread_destroy(changelog_priv_t *priv) { - pthread_mutex_destroy (&priv->bn.bnotify_mutex); - pthread_cond_destroy (&priv->bn.bnotify_cond); - pthread_mutex_destroy (&priv->dm.drain_black_mutex); - pthread_cond_destroy (&priv->dm.drain_black_cond); - pthread_mutex_destroy (&priv->dm.drain_white_mutex); - pthread_cond_destroy (&priv->dm.drain_white_cond); - pthread_mutex_destroy(&priv->cr.lock); - pthread_cond_destroy (&priv->cr.cond); - LOCK_DESTROY (&priv->bflags.lock); + pthread_mutex_destroy(&priv->bn.bnotify_mutex); + pthread_cond_destroy(&priv->bn.bnotify_cond); + pthread_mutex_destroy(&priv->dm.drain_black_mutex); + pthread_cond_destroy(&priv->dm.drain_black_cond); + pthread_mutex_destroy(&priv->dm.drain_white_mutex); + pthread_cond_destroy(&priv->dm.drain_white_cond); + pthread_mutex_destroy(&priv->cr.lock); + pthread_cond_destroy(&priv->cr.cond); + LOCK_DESTROY(&priv->bflags.lock); } int -reconfigure (xlator_t *this, dict_t *options) -{ - int ret = 0; - char *tmp = 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,}; - char htime_dir[PATH_MAX] = {0,}; - char csnap_dir[PATH_MAX] = {0,}; - struct timeval tv = {0,}; - uint32_t timeout = 0; - - priv = this->private; - if (!priv) - goto out; - - ret = -1; - active_earlier = priv->active; - - /* first stop the rollover and the fsync thread */ - changelog_cleanup_helper_threads (this, priv); - - GF_OPTION_RECONF ("changelog-dir", tmp, options, str, out); - if (!tmp) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_DIR_OPTIONS_NOT_SET, - "\"changelog-dir\" option is not set"); - goto out; - } - - GF_FREE (priv->changelog_dir); - priv->changelog_dir = gf_strdup (tmp); - if (!priv->changelog_dir) - goto out; - - ret = mkdir_p (priv->changelog_dir, 0600, _gf_true); - +reconfigure(xlator_t *this, dict_t *options) +{ + int ret = 0; + char *tmp = 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, + }; + char htime_dir[PATH_MAX] = { + 0, + }; + char csnap_dir[PATH_MAX] = { + 0, + }; + struct timeval tv = { + 0, + }; + uint32_t timeout = 0; + + priv = this->private; + if (!priv) + goto out; + + ret = -1; + active_earlier = priv->active; + + /* first stop the rollover and the fsync thread */ + changelog_cleanup_helper_threads(this, priv); + + GF_OPTION_RECONF("changelog-dir", tmp, options, str, out); + if (!tmp) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_DIR_OPTIONS_NOT_SET, + "\"changelog-dir\" option is not set"); + goto out; + } + + GF_FREE(priv->changelog_dir); + priv->changelog_dir = gf_strdup(tmp); + if (!priv->changelog_dir) + goto out; + + ret = mkdir_p(priv->changelog_dir, 0600, _gf_true); + + if (ret) + goto out; + CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, htime_dir); + ret = mkdir_p(htime_dir, 0600, _gf_true); + + if (ret) + goto out; + + CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir); + ret = mkdir_p(csnap_dir, 0600, _gf_true); + + if (ret) + goto out; + + GF_OPTION_RECONF("changelog", active_now, options, bool, out); + + /** + * changelog_handle_change() handles changes that could possibly + * have been submit changes before changelog deactivation. + */ + if (!active_now) + priv->active = _gf_false; + + GF_OPTION_RECONF("op-mode", tmp, options, str, out); + changelog_assign_opmode(priv, tmp); + + tmp = NULL; + + GF_OPTION_RECONF("encoding", tmp, options, str, out); + changelog_assign_encoding(priv, tmp); + + GF_OPTION_RECONF("rollover-time", priv->rollover_time, options, int32, out); + GF_OPTION_RECONF("fsync-interval", priv->fsync_interval, options, int32, + out); + GF_OPTION_RECONF("changelog-barrier-timeout", timeout, options, time, out); + changelog_assign_barrier_timeout(priv, timeout); + + GF_OPTION_RECONF("capture-del-path", priv->capture_del_path, options, bool, + out); + + if (active_now || active_earlier) { + ret = changelog_fill_rollover_data(&cld, !active_now); if (ret) - goto out; - CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, htime_dir); - ret = mkdir_p (htime_dir, 0600, _gf_true); + goto out; - if (ret) - goto out; + slice = &priv->slice; - CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir); - ret = mkdir_p (csnap_dir, 0600, _gf_true); + LOCK(&priv->lock); + { + ret = changelog_inject_single_event(this, priv, &cld); + if (!ret && active_now) + SLICE_VERSION_UPDATE(slice); + } + UNLOCK(&priv->lock); if (ret) - goto out; - - GF_OPTION_RECONF ("changelog", active_now, options, bool, out); - - /** - * changelog_handle_change() handles changes that could possibly - * have been submit changes before changelog deactivation. - */ - if (!active_now) - priv->active = _gf_false; - - GF_OPTION_RECONF ("op-mode", tmp, options, str, out); - changelog_assign_opmode (priv, tmp); - - tmp = NULL; - - GF_OPTION_RECONF ("encoding", tmp, options, str, out); - changelog_assign_encoding (priv, tmp); - - GF_OPTION_RECONF ("rollover-time", - priv->rollover_time, options, int32, out); - GF_OPTION_RECONF ("fsync-interval", - priv->fsync_interval, options, int32, out); - GF_OPTION_RECONF ("changelog-barrier-timeout", - timeout, options, time, out); - changelog_assign_barrier_timeout (priv, timeout); - - GF_OPTION_RECONF ("capture-del-path", priv->capture_del_path, options, - bool, out); - - if (active_now || active_earlier) { - ret = changelog_fill_rollover_data (&cld, !active_now); - if (ret) - goto out; - - slice = &priv->slice; - - LOCK (&priv->lock); - { - ret = changelog_inject_single_event (this, priv, &cld); - if (!ret && active_now) - SLICE_VERSION_UPDATE (slice); - } - UNLOCK (&priv->lock); - - if (ret) - goto out; - - if (active_now) { - if (!active_earlier) { - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_HTIME_INFO, - "Reconfigure: Changelog Enable"); - if (gettimeofday(&tv, NULL) ) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_HTIME_ERROR, - "unable to fetch htime"); - ret = -1; - goto out; - } - htime_create (this, priv, tv.tv_sec); - } - ret = changelog_spawn_helper_threads (this, priv); + goto out; + + if (active_now) { + if (!active_earlier) { + gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_HTIME_INFO, + "Reconfigure: Changelog Enable"); + if (gettimeofday(&tv, NULL)) { + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_HTIME_ERROR, "unable to fetch htime"); + ret = -1; + goto out; } + htime_create(this, priv, tv.tv_sec); + } + ret = changelog_spawn_helper_threads(this, priv); } + } - out: - if (ret) { - /* TODO */ - } else { - gf_msg_debug (this->name, 0, - "changelog reconfigured"); - if (active_now && priv) - priv->active = _gf_true; - } +out: + if (ret) { + /* TODO */ + } else { + gf_msg_debug(this->name, 0, "changelog reconfigured"); + if (active_now && priv) + priv->active = _gf_true; + } - return ret; + return ret; } static void -changelog_freeup_options (xlator_t *this, changelog_priv_t *priv) +changelog_freeup_options(xlator_t *this, changelog_priv_t *priv) { - int ret = 0; + int ret = 0; - ret = priv->cb->dtor (this, &priv->cd); - if (ret) - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_FREEUP_FAILED, - "could not cleanup bootstrapper"); - GF_FREE (priv->changelog_brick); - GF_FREE (priv->changelog_dir); + ret = priv->cb->dtor(this, &priv->cd); + if (ret) + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_FREEUP_FAILED, + "could not cleanup bootstrapper"); + GF_FREE(priv->changelog_brick); + GF_FREE(priv->changelog_dir); } static int -changelog_init_options (xlator_t *this, changelog_priv_t *priv) +changelog_init_options(xlator_t *this, changelog_priv_t *priv) { - int ret = 0; - char *tmp = NULL; - uint32_t timeout = 0; - char htime_dir[PATH_MAX] = {0,}; - char csnap_dir[PATH_MAX] = {0,}; + int ret = 0; + char *tmp = NULL; + uint32_t timeout = 0; + char htime_dir[PATH_MAX] = { + 0, + }; + char csnap_dir[PATH_MAX] = { + 0, + }; - GF_OPTION_INIT ("changelog-brick", tmp, str, error_return); - priv->changelog_brick = gf_strdup (tmp); - if (!priv->changelog_brick) - goto error_return; + GF_OPTION_INIT("changelog-brick", tmp, str, error_return); + priv->changelog_brick = gf_strdup(tmp); + if (!priv->changelog_brick) + goto error_return; - tmp = NULL; + tmp = NULL; - GF_OPTION_INIT ("changelog-dir", tmp, str, dealloc_1); - priv->changelog_dir = gf_strdup (tmp); - if (!priv->changelog_dir) - goto dealloc_1; + GF_OPTION_INIT("changelog-dir", tmp, str, dealloc_1); + priv->changelog_dir = gf_strdup(tmp); + if (!priv->changelog_dir) + goto dealloc_1; - tmp = NULL; + tmp = NULL; - /** - * create the directory even if change-logging would be inactive - * so that consumers can _look_ into it (finding nothing...) - */ - ret = mkdir_p (priv->changelog_dir, 0600, _gf_true); + /** + * create the directory even if change-logging would be inactive + * so that consumers can _look_ into it (finding nothing...) + */ + ret = mkdir_p(priv->changelog_dir, 0600, _gf_true); - if (ret) - goto dealloc_2; + if (ret) + goto dealloc_2; - CHANGELOG_FILL_HTIME_DIR (priv->changelog_dir, htime_dir); - ret = mkdir_p (htime_dir, 0600, _gf_true); - if (ret) - goto dealloc_2; + CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, htime_dir); + ret = mkdir_p(htime_dir, 0600, _gf_true); + if (ret) + goto dealloc_2; - CHANGELOG_FILL_CSNAP_DIR (priv->changelog_dir, csnap_dir); - ret = mkdir_p (csnap_dir, 0600, _gf_true); - if (ret) - goto dealloc_2; + CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir); + ret = mkdir_p(csnap_dir, 0600, _gf_true); + if (ret) + goto dealloc_2; - GF_OPTION_INIT ("changelog", priv->active, bool, dealloc_2); - GF_OPTION_INIT ("capture-del-path", priv->capture_del_path, - bool, dealloc_2); + GF_OPTION_INIT("changelog", priv->active, bool, dealloc_2); + GF_OPTION_INIT("capture-del-path", priv->capture_del_path, bool, dealloc_2); - GF_OPTION_INIT ("op-mode", tmp, str, dealloc_2); - changelog_assign_opmode (priv, tmp); + GF_OPTION_INIT("op-mode", tmp, str, dealloc_2); + changelog_assign_opmode(priv, tmp); - tmp = NULL; + tmp = NULL; - GF_OPTION_INIT ("encoding", tmp, str, dealloc_2); - changelog_assign_encoding (priv, tmp); - changelog_encode_change (priv); + GF_OPTION_INIT("encoding", tmp, str, dealloc_2); + changelog_assign_encoding(priv, tmp); + changelog_encode_change(priv); - GF_OPTION_INIT ("rollover-time", - priv->rollover_time, int32, dealloc_2); + GF_OPTION_INIT("rollover-time", priv->rollover_time, int32, dealloc_2); - GF_OPTION_INIT ("fsync-interval", - priv->fsync_interval, int32, dealloc_2); + GF_OPTION_INIT("fsync-interval", priv->fsync_interval, int32, dealloc_2); - GF_OPTION_INIT ("changelog-barrier-timeout", - timeout, time, dealloc_2); - changelog_assign_barrier_timeout (priv, timeout); + GF_OPTION_INIT("changelog-barrier-timeout", timeout, time, dealloc_2); + changelog_assign_barrier_timeout(priv, timeout); - GF_ASSERT (cb_bootstrap[priv->op_mode].mode == priv->op_mode); - priv->cb = &cb_bootstrap[priv->op_mode]; + GF_ASSERT(cb_bootstrap[priv->op_mode].mode == priv->op_mode); + priv->cb = &cb_bootstrap[priv->op_mode]; - /* ... now bootstrap the logger */ - ret = priv->cb->ctor (this, &priv->cd); - if (ret) - goto dealloc_2; + /* ... now bootstrap the logger */ + ret = priv->cb->ctor(this, &priv->cd); + if (ret) + goto dealloc_2; - priv->changelog_fd = -1; + priv->changelog_fd = -1; - return 0; + return 0; - dealloc_2: - GF_FREE (priv->changelog_dir); - dealloc_1: - GF_FREE (priv->changelog_brick); - error_return: - return -1; +dealloc_2: + GF_FREE(priv->changelog_dir); +dealloc_1: + GF_FREE(priv->changelog_brick); +error_return: + return -1; } static void -changelog_cleanup_rpc (xlator_t *this, changelog_priv_t *priv) +changelog_cleanup_rpc(xlator_t *this, changelog_priv_t *priv) { - /* terminate rpc server */ - changelog_destroy_rpc_listner (this, priv); + /* terminate rpc server */ + changelog_destroy_rpc_listner(this, priv); - /* cleanup rot buffs */ - rbuf_dtor (priv->rbuf); + /* cleanup rot buffs */ + rbuf_dtor(priv->rbuf); - /* cleanup poller thread */ - if (priv->poller) - (void) changelog_thread_cleanup (this, priv->poller); + /* cleanup poller thread */ + if (priv->poller) + (void)changelog_thread_cleanup(this, priv->poller); } static int -changelog_init_rpc (xlator_t *this, changelog_priv_t *priv) +changelog_init_rpc(xlator_t *this, changelog_priv_t *priv) { - rpcsvc_t *rpc = NULL; - changelog_ev_selector_t *selection = NULL; + rpcsvc_t *rpc = NULL; + changelog_ev_selector_t *selection = NULL; - selection = &priv->ev_selection; + selection = &priv->ev_selection; - /* initialize event selection */ - changelog_init_event_selection (this, selection); + /* initialize event selection */ + changelog_init_event_selection(this, selection); - priv->rbuf = rbuf_init (NR_ROTT_BUFFS); - if (!priv->rbuf) - goto cleanup_thread; + priv->rbuf = rbuf_init(NR_ROTT_BUFFS); + if (!priv->rbuf) + goto cleanup_thread; - rpc = changelog_init_rpc_listener (this, priv, - priv->rbuf, NR_DISPATCHERS); - if (!rpc) - goto cleanup_rbuf; - priv->rpc = rpc; + rpc = changelog_init_rpc_listener(this, priv, priv->rbuf, NR_DISPATCHERS); + if (!rpc) + goto cleanup_rbuf; + priv->rpc = rpc; - return 0; + return 0; - cleanup_rbuf: - rbuf_dtor (priv->rbuf); - cleanup_thread: - if (priv->poller) - (void) changelog_thread_cleanup (this, priv->poller); +cleanup_rbuf: + rbuf_dtor(priv->rbuf); +cleanup_thread: + if (priv->poller) + (void)changelog_thread_cleanup(this, priv->poller); - return -1; + return -1; } int32_t -init (xlator_t *this) -{ - int ret = -1; - changelog_priv_t *priv = NULL; - - GF_VALIDATE_OR_GOTO ("changelog", this, error_return); - - if (!this->children || this->children->next) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_CHILD_MISCONFIGURED, - "translator needs a single subvolume"); - goto error_return; - } - - if (!this->parents) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_MSG_VOL_MISCONFIGURED, - "dangling volume. please check volfile"); - goto error_return; - } - - priv = GF_CALLOC (1, sizeof (*priv), gf_changelog_mt_priv_t); - if (!priv) - goto error_return; - - this->local_pool = mem_pool_new (changelog_local_t, 64); - if (!this->local_pool) { - gf_msg (this->name, GF_LOG_ERROR, ENOMEM, - CHANGELOG_MSG_NO_MEMORY, - "failed to create local memory pool"); - goto cleanup_priv; - } - - LOCK_INIT (&priv->lock); - LOCK_INIT (&priv->c_snap_lock); - - ret = changelog_init_options (this, priv); - if (ret) - goto cleanup_mempool; - - /* snap dependency changes */ - priv->dm.black_fop_cnt = 0; - priv->dm.white_fop_cnt = 0; - priv->dm.drain_wait_black = _gf_false; - priv->dm.drain_wait_white = _gf_false; - priv->current_color = FOP_COLOR_BLACK; - priv->explicit_rollover = _gf_false; - - priv->cr.notify = _gf_false; - /* Mutex is not needed as threads are not spawned yet */ - priv->bn.bnotify = _gf_false; - priv->bn.bnotify_error = _gf_false; - ret = changelog_barrier_pthread_init (this, priv); - if (ret) - goto cleanup_options; - LOCK_INIT (&priv->bflags.lock); - priv->bflags.barrier_ext = _gf_false; - - /* Changelog barrier init */ - INIT_LIST_HEAD (&priv->queue); - priv->barrier_enabled = _gf_false; - - /* RPC ball rolling.. */ - ret = changelog_init_rpc (this, priv); - if (ret) - goto cleanup_barrier; - - ret = changelog_init (this, priv); - if (ret) - goto cleanup_rpc; - - gf_msg_debug (this->name, 0, "changelog translator loaded"); - - this->private = priv; - return 0; - - cleanup_rpc: - changelog_cleanup_rpc (this, priv); - cleanup_barrier: - changelog_barrier_pthread_destroy (priv); - cleanup_options: - changelog_freeup_options (this, priv); - cleanup_mempool: - mem_pool_destroy (this->local_pool); - cleanup_priv: - GF_FREE (priv); - error_return: - this->private = NULL; - return -1; +init(xlator_t *this) +{ + int ret = -1; + changelog_priv_t *priv = NULL; + + GF_VALIDATE_OR_GOTO("changelog", this, error_return); + + if (!this->children || this->children->next) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_CHILD_MISCONFIGURED, + "translator needs a single subvolume"); + goto error_return; + } + + if (!this->parents) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_VOL_MISCONFIGURED, + "dangling volume. please check volfile"); + goto error_return; + } + + priv = GF_CALLOC(1, sizeof(*priv), gf_changelog_mt_priv_t); + if (!priv) + goto error_return; + + this->local_pool = mem_pool_new(changelog_local_t, 64); + if (!this->local_pool) { + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY, + "failed to create local memory pool"); + goto cleanup_priv; + } + + LOCK_INIT(&priv->lock); + LOCK_INIT(&priv->c_snap_lock); + + ret = changelog_init_options(this, priv); + if (ret) + goto cleanup_mempool; + + /* snap dependency changes */ + priv->dm.black_fop_cnt = 0; + priv->dm.white_fop_cnt = 0; + priv->dm.drain_wait_black = _gf_false; + priv->dm.drain_wait_white = _gf_false; + priv->current_color = FOP_COLOR_BLACK; + priv->explicit_rollover = _gf_false; + + priv->cr.notify = _gf_false; + /* Mutex is not needed as threads are not spawned yet */ + priv->bn.bnotify = _gf_false; + priv->bn.bnotify_error = _gf_false; + ret = changelog_barrier_pthread_init(this, priv); + if (ret) + goto cleanup_options; + LOCK_INIT(&priv->bflags.lock); + priv->bflags.barrier_ext = _gf_false; + + /* Changelog barrier init */ + INIT_LIST_HEAD(&priv->queue); + priv->barrier_enabled = _gf_false; + + /* RPC ball rolling.. */ + ret = changelog_init_rpc(this, priv); + if (ret) + goto cleanup_barrier; + + ret = changelog_init(this, priv); + if (ret) + goto cleanup_rpc; + + gf_msg_debug(this->name, 0, "changelog translator loaded"); + + this->private = priv; + return 0; + +cleanup_rpc: + changelog_cleanup_rpc(this, priv); +cleanup_barrier: + changelog_barrier_pthread_destroy(priv); +cleanup_options: + changelog_freeup_options(this, priv); +cleanup_mempool: + mem_pool_destroy(this->local_pool); +cleanup_priv: + GF_FREE(priv); +error_return: + this->private = NULL; + return -1; } void -fini (xlator_t *this) +fini(xlator_t *this) { - changelog_priv_t *priv = NULL; - struct list_head queue = {0, }; + changelog_priv_t *priv = NULL; + struct list_head queue = { + 0, + }; - priv = this->private; + priv = this->private; - if (priv) { - /* terminate RPC server/threads */ - changelog_cleanup_rpc (this, priv); + if (priv) { + /* terminate RPC server/threads */ + changelog_cleanup_rpc(this, priv); - /* call barrier_disable to cancel timer */ - if (priv->barrier_enabled) - __chlog_barrier_disable (this, &queue); + /* call barrier_disable to cancel timer */ + if (priv->barrier_enabled) + __chlog_barrier_disable(this, &queue); - /* cleanup barrier related objects */ - changelog_barrier_pthread_destroy (priv); + /* cleanup barrier related objects */ + changelog_barrier_pthread_destroy(priv); - /* cleanup helper threads */ - changelog_cleanup_helper_threads (this, priv); + /* cleanup helper threads */ + changelog_cleanup_helper_threads(this, priv); - /* cleanup allocated options */ - changelog_freeup_options (this, priv); + /* cleanup allocated options */ + changelog_freeup_options(this, priv); - /* deallocate mempool */ - mem_pool_destroy (this->local_pool); + /* deallocate mempool */ + mem_pool_destroy(this->local_pool); - if (priv->htime_fd != -1) { - sys_close (priv->htime_fd); - } - - /* finally, dealloac private variable */ - GF_FREE (priv); + if (priv->htime_fd != -1) { + sys_close(priv->htime_fd); } - this->private = NULL; - this->local_pool = NULL; + /* finally, dealloac private variable */ + GF_FREE(priv); + } - return; + this->private = NULL; + this->local_pool = NULL; + + return; } struct xlator_fops fops = { - .open = changelog_open, - .mknod = changelog_mknod, - .mkdir = changelog_mkdir, - .create = changelog_create, - .symlink = changelog_symlink, - .writev = changelog_writev, - .truncate = changelog_truncate, - .ftruncate = changelog_ftruncate, - .link = changelog_link, - .rename = changelog_rename, - .unlink = changelog_unlink, - .rmdir = changelog_rmdir, - .setattr = changelog_setattr, - .fsetattr = changelog_fsetattr, - .setxattr = changelog_setxattr, - .fsetxattr = changelog_fsetxattr, - .removexattr = changelog_removexattr, - .fremovexattr = changelog_fremovexattr, - .ipc = changelog_ipc, - .xattrop = changelog_xattrop, - .fxattrop = changelog_fxattrop, + .open = changelog_open, + .mknod = changelog_mknod, + .mkdir = changelog_mkdir, + .create = changelog_create, + .symlink = changelog_symlink, + .writev = changelog_writev, + .truncate = changelog_truncate, + .ftruncate = changelog_ftruncate, + .link = changelog_link, + .rename = changelog_rename, + .unlink = changelog_unlink, + .rmdir = changelog_rmdir, + .setattr = changelog_setattr, + .fsetattr = changelog_fsetattr, + .setxattr = changelog_setxattr, + .fsetxattr = changelog_fsetxattr, + .removexattr = changelog_removexattr, + .fremovexattr = changelog_fremovexattr, + .ipc = changelog_ipc, + .xattrop = changelog_xattrop, + .fxattrop = changelog_fxattrop, }; struct xlator_cbks cbks = { - .forget = changelog_forget, - .release = changelog_release, + .forget = changelog_forget, + .release = changelog_release, }; struct volume_options options[] = { - {.key = {"changelog"}, - .type = GF_OPTION_TYPE_BOOL, - .default_value = "off", - .description = "enable/disable change-logging", - .op_version = {3}, - .flags = OPT_FLAG_SETTABLE, - .level = OPT_STATUS_BASIC, - .tags = {"journal", "georep", "glusterfind"} - }, - {.key = {"changelog-brick"}, - .type = GF_OPTION_TYPE_PATH, - .description = "brick path to generate unique socket file name." - " should be the export directory of the volume strictly.", - .default_value = "{{ brick.path }}", - .op_version = {3}, - .tags = {"journal"} - }, - {.key = {"changelog-dir"}, - .type = GF_OPTION_TYPE_PATH, - .description = "directory for the changelog files", - .default_value = "{{ brick.path }}/.glusterfs/changelogs", - .op_version = {3}, - .flags = OPT_FLAG_SETTABLE, - .level = OPT_STATUS_ADVANCED, - .tags = {"journal", "georep", "glusterfind"} - }, - {.key = {"op-mode"}, - .type = GF_OPTION_TYPE_STR, - .default_value = "realtime", - .value = {"realtime"}, - .description = "operation mode - futuristic operation modes", - .op_version = {3}, - .tags = {"journal"} - }, - {.key = {"encoding"}, - .type = GF_OPTION_TYPE_STR, - .default_value = "ascii", - .value = {"binary", "ascii"}, - .description = "encoding type for changelogs", - .op_version = {3}, - .flags = OPT_FLAG_SETTABLE, - .level = OPT_STATUS_ADVANCED, - .tags = {"journal"} - }, - {.key = {"rollover-time"}, - .default_value = "15", - .type = GF_OPTION_TYPE_TIME, - .description = "time to switch to a new changelog file (in seconds)", - .op_version = {3}, - .flags = OPT_FLAG_SETTABLE, - .level = OPT_STATUS_ADVANCED, - .tags = {"journal", "georep", "glusterfind"} - }, - {.key = {"fsync-interval"}, - .type = GF_OPTION_TYPE_TIME, - .default_value = "5", - .description = "do not open CHANGELOG file with O_SYNC mode." - " instead perform fsync() at specified intervals", - .op_version = {3}, - .flags = OPT_FLAG_SETTABLE, - .level = OPT_STATUS_ADVANCED, - .tags = {"journal"} - }, - { .key = {"changelog-barrier-timeout"}, - .type = GF_OPTION_TYPE_TIME, - .default_value = BARRIER_TIMEOUT, - .description = "After 'timeout' seconds since the time 'barrier' " - "option was set to \"on\", unlink/rmdir/rename " - "operations are no longer blocked and previously " - "blocked fops are allowed to go through", - .op_version = {3}, - .flags = OPT_FLAG_SETTABLE, - .level = OPT_STATUS_ADVANCED, - .tags = {"journal"} - }, - {.key = {"capture-del-path"}, - .type = GF_OPTION_TYPE_BOOL, - .default_value = "off", - .description = "enable/disable capturing paths of deleted entries", - .op_version = {3}, - .flags = OPT_FLAG_SETTABLE, - .level = OPT_STATUS_BASIC, - .tags = {"journal", "glusterfind"} - }, - {.key = {NULL} - }, + {.key = {"changelog"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "enable/disable change-logging", + .op_version = {3}, + .flags = OPT_FLAG_SETTABLE, + .level = OPT_STATUS_BASIC, + .tags = {"journal", "georep", "glusterfind"}}, + {.key = {"changelog-brick"}, + .type = GF_OPTION_TYPE_PATH, + .description = "brick path to generate unique socket file name." + " should be the export directory of the volume strictly.", + .default_value = "{{ brick.path }}", + .op_version = {3}, + .tags = {"journal"}}, + {.key = {"changelog-dir"}, + .type = GF_OPTION_TYPE_PATH, + .description = "directory for the changelog files", + .default_value = "{{ brick.path }}/.glusterfs/changelogs", + .op_version = {3}, + .flags = OPT_FLAG_SETTABLE, + .level = OPT_STATUS_ADVANCED, + .tags = {"journal", "georep", "glusterfind"}}, + {.key = {"op-mode"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "realtime", + .value = {"realtime"}, + .description = "operation mode - futuristic operation modes", + .op_version = {3}, + .tags = {"journal"}}, + {.key = {"encoding"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "ascii", + .value = {"binary", "ascii"}, + .description = "encoding type for changelogs", + .op_version = {3}, + .flags = OPT_FLAG_SETTABLE, + .level = OPT_STATUS_ADVANCED, + .tags = {"journal"}}, + {.key = {"rollover-time"}, + .default_value = "15", + .type = GF_OPTION_TYPE_TIME, + .description = "time to switch to a new changelog file (in seconds)", + .op_version = {3}, + .flags = OPT_FLAG_SETTABLE, + .level = OPT_STATUS_ADVANCED, + .tags = {"journal", "georep", "glusterfind"}}, + {.key = {"fsync-interval"}, + .type = GF_OPTION_TYPE_TIME, + .default_value = "5", + .description = "do not open CHANGELOG file with O_SYNC mode." + " instead perform fsync() at specified intervals", + .op_version = {3}, + .flags = OPT_FLAG_SETTABLE, + .level = OPT_STATUS_ADVANCED, + .tags = {"journal"}}, + {.key = {"changelog-barrier-timeout"}, + .type = GF_OPTION_TYPE_TIME, + .default_value = BARRIER_TIMEOUT, + .description = "After 'timeout' seconds since the time 'barrier' " + "option was set to \"on\", unlink/rmdir/rename " + "operations are no longer blocked and previously " + "blocked fops are allowed to go through", + .op_version = {3}, + .flags = OPT_FLAG_SETTABLE, + .level = OPT_STATUS_ADVANCED, + .tags = {"journal"}}, + {.key = {"capture-del-path"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "enable/disable capturing paths of deleted entries", + .op_version = {3}, + .flags = OPT_FLAG_SETTABLE, + .level = OPT_STATUS_BASIC, + .tags = {"journal", "glusterfind"}}, + {.key = {NULL}}, }; |