diff options
Diffstat (limited to 'xlators/features/changelog')
34 files changed, 8729 insertions, 8747 deletions
diff --git a/xlators/features/changelog/lib/examples/c/get-changes-multi.c b/xlators/features/changelog/lib/examples/c/get-changes-multi.c index 3741bdf6edc..5ea5bbb6630 100644 --- a/xlators/features/changelog/lib/examples/c/get-changes-multi.c +++ b/xlators/features/changelog/lib/examples/c/get-changes-multi.c @@ -25,64 +25,66 @@ #include "changelog.h" -void *brick_init (void *xl, struct gf_brick_spec *brick) +void * +brick_init(void *xl, struct gf_brick_spec *brick) { - return brick; + return brick; } -void brick_fini (void *xl, char *brick, void *data) +void +brick_fini(void *xl, char *brick, void *data) { - return; + return; } -void brick_callback (void *xl, char *brick, - void *data, changelog_event_t *ev) +void +brick_callback(void *xl, char *brick, void *data, changelog_event_t *ev) { - printf ("->callback: (brick,type) [%s:%d]\n", brick, ev->ev_type); + printf("->callback: (brick,type) [%s:%d]\n", brick, ev->ev_type); } -void fill_brick_spec (struct gf_brick_spec *brick, char *path) +void +fill_brick_spec(struct gf_brick_spec *brick, char *path) { - brick->brick_path = strdup (path); - brick->filter = CHANGELOG_OP_TYPE_BR_RELEASE; - - brick->init = brick_init; - brick->fini = brick_fini; - brick->callback = brick_callback; - brick->connected = NULL; - brick->disconnected = NULL; + brick->brick_path = strdup(path); + brick->filter = CHANGELOG_OP_TYPE_BR_RELEASE; + + brick->init = brick_init; + brick->fini = brick_fini; + brick->callback = brick_callback; + brick->connected = NULL; + brick->disconnected = NULL; } int -main (int argc, char **argv) +main(int argc, char **argv) { - int ret = 0; - void *bricks = NULL; - struct gf_brick_spec *brick = NULL; + int ret = 0; + void *bricks = NULL; + struct gf_brick_spec *brick = NULL; - bricks = calloc (2, sizeof (struct gf_brick_spec)); - if (!bricks) - goto error_return; + bricks = calloc(2, sizeof(struct gf_brick_spec)); + if (!bricks) + goto error_return; - brick = (struct gf_brick_spec *)bricks; - fill_brick_spec (brick, "/export/z1/zwoop"); + brick = (struct gf_brick_spec *)bricks; + fill_brick_spec(brick, "/export/z1/zwoop"); - brick++; - fill_brick_spec (brick, "/export/z2/zwoop"); + brick++; + fill_brick_spec(brick, "/export/z2/zwoop"); - ret = gf_changelog_init (NULL); - if (ret) - goto error_return; + ret = gf_changelog_init(NULL); + if (ret) + goto error_return; - ret = gf_changelog_register_generic ((struct gf_brick_spec *)bricks, 2, - 0, "/tmp/multi-changes.log", 9, - NULL); - if (ret) - goto error_return; + ret = gf_changelog_register_generic((struct gf_brick_spec *)bricks, 2, 0, + "/tmp/multi-changes.log", 9, NULL); + if (ret) + goto error_return; - /* let callbacks do the job */ - select (0, NULL, NULL, NULL, NULL); + /* let callbacks do the job */ + select(0, NULL, NULL, NULL, NULL); - error_return: - return -1; +error_return: + return -1; } diff --git a/xlators/features/changelog/lib/examples/c/get-changes.c b/xlators/features/changelog/lib/examples/c/get-changes.c index ef766c566b6..8bc651c24a4 100644 --- a/xlators/features/changelog/lib/examples/c/get-changes.c +++ b/xlators/features/changelog/lib/examples/c/get-changes.c @@ -27,67 +27,67 @@ #include "changelog.h" -#define handle_error(fn) \ - printf ("%s (reason: %s)\n", fn, strerror (errno)) +#define handle_error(fn) printf("%s (reason: %s)\n", fn, strerror(errno)) int -main (int argc, char ** argv) +main(int argc, char **argv) { - int i = 0; - int ret = 0; - ssize_t nr_changes = 0; - ssize_t changes = 0; - char fbuf[PATH_MAX] = {0,}; - - ret = gf_changelog_init (NULL); - if (ret) { - handle_error ("Init failed"); - goto out; + int i = 0; + int ret = 0; + ssize_t nr_changes = 0; + ssize_t changes = 0; + char fbuf[PATH_MAX] = { + 0, + }; + + ret = gf_changelog_init(NULL); + if (ret) { + handle_error("Init failed"); + goto out; + } + + /* get changes for brick "/home/vshankar/export/yow/yow-1" */ + ret = gf_changelog_register("/export/z1/zwoop", "/tmp/scratch", + "/tmp/change.log", 9, 5); + if (ret) { + handle_error("register failed"); + goto out; + } + + while (1) { + i = 0; + nr_changes = gf_changelog_scan(); + if (nr_changes < 0) { + handle_error("scan(): "); + break; } - /* get changes for brick "/home/vshankar/export/yow/yow-1" */ - ret = gf_changelog_register ("/export/z1/zwoop", - "/tmp/scratch", "/tmp/change.log", 9, 5); - if (ret) { - handle_error ("register failed"); - goto out; - } - - while (1) { - i = 0; - nr_changes = gf_changelog_scan (); - if (nr_changes < 0) { - handle_error ("scan(): "); - break; - } - - if (nr_changes == 0) - goto next; + if (nr_changes == 0) + goto next; - printf ("Got %ld changelog files\n", nr_changes); + printf("Got %ld changelog files\n", nr_changes); - while ( (changes = - gf_changelog_next_change (fbuf, PATH_MAX)) > 0) { - printf ("changelog file [%d]: %s\n", ++i, fbuf); + while ((changes = gf_changelog_next_change(fbuf, PATH_MAX)) > 0) { + printf("changelog file [%d]: %s\n", ++i, fbuf); - /* process changelog */ - /* ... */ - /* ... */ - /* ... */ - /* done processing */ + /* process changelog */ + /* ... */ + /* ... */ + /* ... */ + /* done processing */ - ret = gf_changelog_done (fbuf); - if (ret) - handle_error ("gf_changelog_done"); - } + ret = gf_changelog_done(fbuf); + if (ret) + handle_error("gf_changelog_done"); + } - if (changes == -1) - handle_error ("gf_changelog_next_change"); + if (changes == -1) + handle_error("gf_changelog_next_change"); - next: - sleep (10); - } + next: + sleep(10); + } - out: - return ret; +out: + return ret; } diff --git a/xlators/features/changelog/lib/examples/c/get-history.c b/xlators/features/changelog/lib/examples/c/get-history.c index ee3ec0ad100..3e888d75ca6 100644 --- a/xlators/features/changelog/lib/examples/c/get-history.c +++ b/xlators/features/changelog/lib/examples/c/get-history.c @@ -27,90 +27,90 @@ #include "changelog.h" -#define handle_error(fn) \ - printf ("%s (reason: %s)\n", fn, strerror (errno)) +#define handle_error(fn) printf("%s (reason: %s)\n", fn, strerror(errno)) int -main (int argc, char ** argv) +main(int argc, char **argv) { - int i = 0; - int ret = 0; - ssize_t nr_changes = 0; - ssize_t changes = 0; - char fbuf[PATH_MAX] = {0,}; - unsigned long end_ts = 0; - - ret = gf_changelog_init (NULL); - if (ret) { - handle_error ("init failed"); - goto out; + int i = 0; + int ret = 0; + ssize_t nr_changes = 0; + ssize_t changes = 0; + char fbuf[PATH_MAX] = { + 0, + }; + unsigned long end_ts = 0; + + ret = gf_changelog_init(NULL); + if (ret) { + handle_error("init failed"); + goto out; + } + + ret = gf_changelog_register("/export/z1/zwoop", "/tmp/scratch_v1", + "/tmp/changes.log", 9, 5); + if (ret) { + handle_error("register failed"); + goto out; + } + + int a, b; + printf("give the two numbers start and end\t"); + scanf("%d%d", &a, &b); + ret = gf_history_changelog("/export/z1/zwoop/.glusterfs/changelogs", a, b, + 3, &end_ts); + if (ret == -1) { + printf("history failed"); + goto out; + } + + printf("end time till when changelog available : %d , ret(%d) \t", end_ts, + ret); + fflush(stdout); + + while (1) { + nr_changes = gf_history_changelog_scan(); + printf("scanned, nr_changes : %d\n", nr_changes); + if (nr_changes < 0) { + handle_error("scan(): "); + break; } - ret = gf_changelog_register ("/export/z1/zwoop", - "/tmp/scratch_v1", "/tmp/changes.log", - 9, 5); - if (ret) { - handle_error ("register failed"); - goto out; + if (nr_changes == 0) { + printf("done scanning \n"); + goto out; } - int a, b; - printf ("give the two numbers start and end\t"); - scanf ("%d%d", &a, &b); - ret = gf_history_changelog ("/export/z1/zwoop/.glusterfs/changelogs", - a, b, 3, &end_ts); - if (ret == -1) { - printf ("history failed"); - goto out; - } + printf("Got %ld changelog files\n", nr_changes); + + while ((changes = gf_history_changelog_next_change(fbuf, PATH_MAX)) > + 0) { + printf("changelog file [%d]: %s\n", ++i, fbuf); - printf ("end time till when changelog available : %d , ret(%d) \t", end_ts, ret); - fflush(stdout); - - while (1) { - nr_changes = gf_history_changelog_scan (); - printf ("scanned, nr_changes : %d\n",nr_changes); - if (nr_changes < 0) { - handle_error ("scan(): "); - break; - } - - if (nr_changes == 0) { - printf ("done scanning \n"); - goto out; - } - - printf ("Got %ld changelog files\n", nr_changes); - - while ( (changes = - gf_history_changelog_next_change (fbuf, PATH_MAX)) > 0) { - printf ("changelog file [%d]: %s\n", ++i, fbuf); - - /* process changelog */ - /* ... */ - /* ... */ - /* ... */ - /* done processing */ - - ret = gf_history_changelog_done (fbuf); - if (ret) - handle_error ("gf_changelog_done"); - } - /* - if (changes == -1) - handle_error ("gf_changelog_next_change"); - if (nr_changes ==1){ - printf("continue scanning\n"); - } - - if(nr_changes == 0){ - printf("done scanning \n"); - goto out; - } - */ + /* process changelog */ + /* ... */ + /* ... */ + /* ... */ + /* done processing */ + + ret = gf_history_changelog_done(fbuf); + if (ret) + handle_error("gf_changelog_done"); + } + /* + if (changes == -1) + handle_error ("gf_changelog_next_change"); + if (nr_changes ==1){ + printf("continue scanning\n"); } + if(nr_changes == 0){ + printf("done scanning \n"); + goto out; + } + */ + } out: - return ret; + return ret; } diff --git a/xlators/features/changelog/lib/examples/python/changes.py b/xlators/features/changelog/lib/examples/python/changes.py index 077c1108cce..c410d3b000d 100644..100755 --- a/xlators/features/changelog/lib/examples/python/changes.py +++ b/xlators/features/changelog/lib/examples/python/changes.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 from __future__ import print_function import os diff --git a/xlators/features/changelog/lib/examples/python/libgfchangelog.py b/xlators/features/changelog/lib/examples/python/libgfchangelog.py index 2cdbf1152b9..2da9f2d2a8c 100644 --- a/xlators/features/changelog/lib/examples/python/libgfchangelog.py +++ b/xlators/features/changelog/lib/examples/python/libgfchangelog.py @@ -1,8 +1,10 @@ import os from ctypes import * +from ctypes.util import find_library class Changes(object): - libgfc = CDLL("libgfchangelog.so", mode=RTLD_GLOBAL, use_errno=True) + libgfc = CDLL(find_library("gfchangelog"), mode=RTLD_GLOBAL, + use_errno=True) @classmethod def geterrno(cls): diff --git a/xlators/features/changelog/lib/src/Makefile.am b/xlators/features/changelog/lib/src/Makefile.am index c4b9a3df692..c933ec53ed2 100644 --- a/xlators/features/changelog/lib/src/Makefile.am +++ b/xlators/features/changelog/lib/src/Makefile.am @@ -1,7 +1,7 @@ libgfchangelog_la_CFLAGS = -Wall $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) \ -DDATADIR=\"$(localstatedir)\" -libgfchangelog_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 -fpic \ +libgfchangelog_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 -D__USE_LARGEFILE64 -fpic \ -I../../../src/ -I$(top_srcdir)/libglusterfs/src \ -I$(top_srcdir)/xlators/features/changelog/src \ -I$(top_srcdir)/rpc/xdr/src -I$(top_builddir)/rpc/xdr/src \ diff --git a/xlators/features/changelog/lib/src/changelog-lib-messages.h b/xlators/features/changelog/lib/src/changelog-lib-messages.h index 2061217b801..d7fe7274353 100644 --- a/xlators/features/changelog/lib/src/changelog-lib-messages.h +++ b/xlators/features/changelog/lib/src/changelog-lib-messages.h @@ -11,7 +11,7 @@ #ifndef _CHANGELOG_LIB_MESSAGES_H_ #define _CHANGELOG_LIB_MESSAGES_H_ -#include "glfs-message-id.h" +#include <glusterfs/glfs-message-id.h> /* To add new message IDs, append new identifiers at the end of the list. * @@ -23,39 +23,52 @@ * glfs-message-id.h. */ -GLFS_MSGID(CHANGELOG_LIB, - CHANGELOG_LIB_MSG_OPEN_FAILED, - CHANGELOG_LIB_MSG_FAILED_TO_RMDIR, - CHANGELOG_LIB_MSG_SCRATCH_DIR_ENTRIES_CREATION_ERROR, - CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED, - CHANGELOG_LIB_MSG_OPENDIR_ERROR, - CHANGELOG_LIB_MSG_RENAME_FAILED, - CHANGELOG_LIB_MSG_READ_ERROR, - CHANGELOG_LIB_MSG_HTIME_ERROR, - CHANGELOG_LIB_MSG_GET_TIME_ERROR, - CHANGELOG_LIB_MSG_WRITE_FAILED, - CHANGELOG_LIB_MSG_PTHREAD_ERROR, - CHANGELOG_LIB_MSG_MMAP_FAILED, - CHANGELOG_LIB_MSG_MUNMAP_FAILED, - CHANGELOG_LIB_MSG_ASCII_ERROR, - CHANGELOG_LIB_MSG_STAT_FAILED, - CHANGELOG_LIB_MSG_GET_XATTR_FAILED, - CHANGELOG_LIB_MSG_PUBLISH_ERROR, - CHANGELOG_LIB_MSG_PARSE_ERROR, - CHANGELOG_LIB_MSG_TOTAL_LOG_INFO, - CHANGELOG_LIB_MSG_CLEANUP_ERROR, - CHANGELOG_LIB_MSG_UNLINK_FAILED, - CHANGELOG_LIB_MSG_NOTIFY_REGISTER_FAILED, - CHANGELOG_LIB_MSG_INVOKE_RPC_FAILED, - CHANGELOG_LIB_MSG_DRAINING_EVENT_INFO, - CHANGELOG_LIB_MSG_CLEANING_BRICK_ENTRY_INFO, - CHANGELOG_LIB_MSG_FREEING_ENTRY_INFO, - CHANGELOG_LIB_MSG_XDR_DECODING_FAILED, - CHANGELOG_LIB_MSG_NOTIFY_REGISTER_INFO, - CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, - CHANGELOG_LIB_MSG_COPY_FROM_BUFFER_FAILED, - CHANGELOG_LIB_MSG_PTHREAD_JOIN_FAILED, - CHANGELOG_LIB_MSG_HIST_FAILED -); +GLFS_MSGID( + CHANGELOG_LIB, CHANGELOG_LIB_MSG_OPEN_FAILED, + CHANGELOG_LIB_MSG_FAILED_TO_RMDIR, + CHANGELOG_LIB_MSG_SCRATCH_DIR_ENTRIES_CREATION_ERROR, + CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED, CHANGELOG_LIB_MSG_OPENDIR_ERROR, + CHANGELOG_LIB_MSG_RENAME_FAILED, CHANGELOG_LIB_MSG_READ_ERROR, + CHANGELOG_LIB_MSG_HTIME_ERROR, CHANGELOG_LIB_MSG_GET_TIME_ERROR, + CHANGELOG_LIB_MSG_WRITE_FAILED, CHANGELOG_LIB_MSG_PTHREAD_ERROR, + CHANGELOG_LIB_MSG_MMAP_FAILED, CHANGELOG_LIB_MSG_MUNMAP_FAILED, + CHANGELOG_LIB_MSG_ASCII_ERROR, CHANGELOG_LIB_MSG_STAT_FAILED, + CHANGELOG_LIB_MSG_GET_XATTR_FAILED, CHANGELOG_LIB_MSG_PUBLISH_ERROR, + CHANGELOG_LIB_MSG_PARSE_ERROR, CHANGELOG_LIB_MSG_MIN_MAX_INFO, + CHANGELOG_LIB_MSG_CLEANUP_ERROR, CHANGELOG_LIB_MSG_UNLINK_FAILED, + CHANGELOG_LIB_MSG_NOTIFY_REGISTER_FAILED, + CHANGELOG_LIB_MSG_INVOKE_RPC_FAILED, CHANGELOG_LIB_MSG_DRAINING_EVENT_INFO, + CHANGELOG_LIB_MSG_CLEANING_BRICK_ENTRY_INFO, + CHANGELOG_LIB_MSG_FREEING_ENTRY_INFO, CHANGELOG_LIB_MSG_XDR_DECODING_FAILED, + CHANGELOG_LIB_MSG_NOTIFY_REGISTER_INFO, + CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, + CHANGELOG_LIB_MSG_COPY_FROM_BUFFER_FAILED, + CHANGELOG_LIB_MSG_PTHREAD_JOIN_FAILED, CHANGELOG_LIB_MSG_HIST_FAILED, + CHANGELOG_LIB_MSG_DRAINED_EVENT_INFO, CHANGELOG_LIB_MSG_PARSE_ERROR_CEASED, + CHANGELOG_LIB_MSG_REQUESTING_INFO, CHANGELOG_LIB_MSG_FINAL_INFO); + +#define CHANGELOG_LIB_MSG_NOTIFY_REGISTER_INFO_STR "Registering brick" +#define CHANGELOG_LIB_MSG_RENAME_FAILED_STR "error moving changelog file" +#define CHANGELOG_LIB_MSG_OPEN_FAILED_STR "cannot open changelog file" +#define CHANGELOG_LIB_MSG_UNLINK_FAILED_STR "failed to unlink" +#define CHANGELOG_LIB_MSG_FAILED_TO_RMDIR_STR "failed to rmdir" +#define CHANGELOG_LIB_MSG_STAT_FAILED_STR "stat failed on changelog file" +#define CHANGELOG_LIB_MSG_PARSE_ERROR_STR "could not parse changelog" +#define CHANGELOG_LIB_MSG_PARSE_ERROR_CEASED_STR \ + "parsing error, ceased publishing..." +#define CHANGELOG_LIB_MSG_HTIME_ERROR_STR "fop failed on htime file" +#define CHANGELOG_LIB_MSG_GET_XATTR_FAILED_STR \ + "error extracting max timstamp from htime file" +#define CHANGELOG_LIB_MSG_MIN_MAX_INFO_STR "changelogs min max" +#define CHANGELOG_LIB_MSG_REQUESTING_INFO_STR "Requesting historical changelogs" +#define CHANGELOG_LIB_MSG_FINAL_INFO_STR "FINAL" +#define CHANGELOG_LIB_MSG_HIST_FAILED_STR \ + "Requested changelog range is not available" +#define CHANGELOG_LIB_MSG_GET_TIME_ERROR_STR "wrong result" +#define CHANGELOG_LIB_MSG_CLEANING_BRICK_ENTRY_INFO_STR \ + "Cleaning brick entry for brick" +#define CHANGELOG_LIB_MSG_DRAINING_EVENT_INFO_STR "Draining event" +#define CHANGELOG_LIB_MSG_DRAINED_EVENT_INFO_STR "Drained event" +#define CHANGELOG_LIB_MSG_FREEING_ENTRY_INFO_STR "freeing entry" #endif /* !_CHANGELOG_MESSAGES_H_ */ diff --git a/xlators/features/changelog/lib/src/gf-changelog-api.c b/xlators/features/changelog/lib/src/gf-changelog-api.c index 372550c7acf..81a5cbfec10 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-api.c +++ b/xlators/features/changelog/lib/src/gf-changelog-api.c @@ -8,10 +8,10 @@ cases as published by the Free Software Foundation. */ -#include "compat-uuid.h" -#include "globals.h" -#include "glusterfs.h" -#include "syscall.h" +#include <glusterfs/compat-uuid.h> +#include <glusterfs/globals.h> +#include <glusterfs/glusterfs.h> +#include <glusterfs/syscall.h> #include "gf-changelog-helpers.h" #include "gf-changelog-journal.h" @@ -19,57 +19,54 @@ #include "changelog-lib-messages.h" int -gf_changelog_done (char *file) +gf_changelog_done(char *file) { - int ret = -1; - char *buffer = NULL; - xlator_t *this = NULL; - gf_changelog_journal_t *jnl = NULL; - char to_path[PATH_MAX] = {0,}; - - errno = EINVAL; - - this = THIS; - if (!this) - goto out; - - jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this); - if (!jnl) - goto out; - - if (!file || !strlen (file)) - goto out; - - /* make sure 'file' is inside ->jnl_working_dir */ - buffer = realpath (file, NULL); - if (!buffer) - goto out; - - if (strncmp (jnl->jnl_working_dir, - buffer, strlen (jnl->jnl_working_dir))) - goto out; - - (void) snprintf (to_path, PATH_MAX, "%s%s", - jnl->jnl_processed_dir, basename (buffer)); - gf_msg_debug (this->name, 0, - "moving %s to processed directory", file); - ret = sys_rename (buffer, to_path); - if (ret) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_RENAME_FAILED, - "cannot move changelog file", - "from=%s", file, - "to=%s", to_path, - NULL); - goto out; - } - - ret = 0; + int ret = -1; + char *buffer = NULL; + xlator_t *this = NULL; + gf_changelog_journal_t *jnl = NULL; + char to_path[PATH_MAX] = { + 0, + }; + + errno = EINVAL; + + this = THIS; + if (!this) + goto out; + + jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this); + if (!jnl) + goto out; + + if (!file || !strlen(file)) + goto out; + + /* make sure 'file' is inside ->jnl_working_dir */ + buffer = realpath(file, NULL); + if (!buffer) + goto out; + + if (strncmp(jnl->jnl_working_dir, buffer, strlen(jnl->jnl_working_dir))) + goto out; + + (void)snprintf(to_path, PATH_MAX, "%s%s", jnl->jnl_processed_dir, + basename(buffer)); + gf_msg_debug(this->name, 0, "moving %s to processed directory", file); + ret = sys_rename(buffer, to_path); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_RENAME_FAILED, "from=%s", file, "to=%s", + to_path, NULL); + goto out; + } + + ret = 0; - out: - if (buffer) - free (buffer); /* allocated by realpath() */ - return ret; +out: + if (buffer) + free(buffer); /* allocated by realpath() */ + return ret; } /** @@ -77,28 +74,28 @@ gf_changelog_done (char *file) * for a set of changelogs, start from the beginning */ int -gf_changelog_start_fresh () +gf_changelog_start_fresh() { - xlator_t *this = NULL; - gf_changelog_journal_t *jnl = NULL; + xlator_t *this = NULL; + gf_changelog_journal_t *jnl = NULL; - this = THIS; - if (!this) - goto out; + this = THIS; + if (!this) + goto out; - errno = EINVAL; + errno = EINVAL; - jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this); - if (!jnl) - goto out; + jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this); + if (!jnl) + goto out; - if (gf_ftruncate (jnl->jnl_fd, 0)) - goto out; + if (gf_ftruncate(jnl->jnl_fd, 0)) + goto out; - return 0; + return 0; - out: - return -1; +out: + return -1; } /** @@ -107,40 +104,42 @@ gf_changelog_start_fresh () * consumed. */ ssize_t -gf_changelog_next_change (char *bufptr, size_t maxlen) +gf_changelog_next_change(char *bufptr, size_t maxlen) { - ssize_t size = -1; - int tracker_fd = 0; - xlator_t *this = NULL; - gf_changelog_journal_t *jnl = NULL; - char buffer[PATH_MAX] = {0,}; + ssize_t size = -1; + int tracker_fd = 0; + xlator_t *this = NULL; + gf_changelog_journal_t *jnl = NULL; + char buffer[PATH_MAX] = { + 0, + }; - errno = EINVAL; + errno = EINVAL; - this = THIS; - if (!this) - goto out; + this = THIS; + if (!this) + goto out; - jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this); - if (!jnl) - goto out; + jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this); + if (!jnl) + goto out; - tracker_fd = jnl->jnl_fd; + tracker_fd = jnl->jnl_fd; - size = gf_readline (tracker_fd, buffer, maxlen); - if (size < 0) { - size = -1; - goto out; - } + size = gf_readline(tracker_fd, buffer, maxlen); + if (size < 0) { + size = -1; + goto out; + } - if (size == 0) - goto out; + if (size == 0) + goto out; - memcpy (bufptr, buffer, size - 1); - bufptr[size - 1] = '\0'; + memcpy(bufptr, buffer, size - 1); + bufptr[size - 1] = '\0'; out: - return size; + return size; } /** @@ -152,70 +151,74 @@ out: * This call also acts as a cancellation point for the consumer. */ ssize_t -gf_changelog_scan () +gf_changelog_scan() { - int tracker_fd = 0; - size_t off = 0; - xlator_t *this = NULL; - size_t nr_entries = 0; - gf_changelog_journal_t *jnl = NULL; - struct dirent *entry = NULL; - struct dirent scratch[2] = {{0,},}; - char buffer[PATH_MAX] = {0,}; - - this = THIS; - if (!this) - goto out; - - jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this); - if (!jnl) - goto out; - if (JNL_IS_API_DISCONNECTED (jnl)) { - errno = ENOTCONN; - goto out; + int tracker_fd = 0; + size_t off = 0; + xlator_t *this = NULL; + size_t nr_entries = 0; + gf_changelog_journal_t *jnl = NULL; + struct dirent *entry = NULL; + struct dirent scratch[2] = { + { + 0, + }, + }; + char buffer[PATH_MAX] = { + 0, + }; + + this = THIS; + if (!this) + goto out; + + jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this); + if (!jnl) + goto out; + if (JNL_IS_API_DISCONNECTED(jnl)) { + errno = ENOTCONN; + goto out; + } + + errno = EINVAL; + + tracker_fd = jnl->jnl_fd; + if (gf_ftruncate(tracker_fd, 0)) + goto out; + + rewinddir(jnl->jnl_dir); + + for (;;) { + errno = 0; + entry = sys_readdir(jnl->jnl_dir, scratch); + if (!entry || errno != 0) + break; + + if (!strcmp(basename(entry->d_name), ".") || + !strcmp(basename(entry->d_name), "..")) + continue; + + nr_entries++; + + GF_CHANGELOG_FILL_BUFFER(jnl->jnl_processing_dir, buffer, off, + strlen(jnl->jnl_processing_dir)); + GF_CHANGELOG_FILL_BUFFER(entry->d_name, buffer, off, + strlen(entry->d_name)); + GF_CHANGELOG_FILL_BUFFER("\n", buffer, off, 1); + + if (gf_changelog_write(tracker_fd, buffer, off) != off) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_WRITE_FAILED, + "error writing changelog filename" + " to tracker file"); + break; } + off = 0; + } - errno = EINVAL; - - tracker_fd = jnl->jnl_fd; - if (gf_ftruncate (tracker_fd, 0)) - goto out; - - rewinddir (jnl->jnl_dir); - - for (;;) { - errno = 0; - entry = sys_readdir (jnl->jnl_dir, scratch); - if (!entry || errno != 0) - break; - - if (!strcmp (basename (entry->d_name), ".") - || !strcmp (basename (entry->d_name), "..")) - continue; - - nr_entries++; - - GF_CHANGELOG_FILL_BUFFER (jnl->jnl_processing_dir, - buffer, off, - strlen (jnl->jnl_processing_dir)); - GF_CHANGELOG_FILL_BUFFER (entry->d_name, buffer, - off, strlen (entry->d_name)); - GF_CHANGELOG_FILL_BUFFER ("\n", buffer, off, 1); - - if (gf_changelog_write (tracker_fd, buffer, off) != off) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_WRITE_FAILED, - "error writing changelog filename" - " to tracker file"); - break; - } - off = 0; - } - - if (!entry) { - if (gf_lseek (tracker_fd, 0, SEEK_SET) != -1) - return nr_entries; - } - out: - return -1; + if (!entry) { + if (gf_lseek(tracker_fd, 0, SEEK_SET) != -1) + return nr_entries; + } +out: + return -1; } diff --git a/xlators/features/changelog/lib/src/gf-changelog-helpers.c b/xlators/features/changelog/lib/src/gf-changelog-helpers.c index 9ff1d135933..75f8a6dfc08 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-helpers.c +++ b/xlators/features/changelog/lib/src/gf-changelog-helpers.c @@ -11,40 +11,36 @@ #include "changelog-mem-types.h" #include "gf-changelog-helpers.h" #include "changelog-lib-messages.h" -#include "syscall.h" - -ssize_t gf_changelog_read_path (int fd, char *buffer, size_t bufsize) -{ - return sys_read (fd, buffer, bufsize); -} +#include <glusterfs/syscall.h> size_t -gf_changelog_write (int fd, char *buffer, size_t len) +gf_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; + return written; } void -gf_rfc3986_encode_space_newline (unsigned char *s, char *enc, char *estr) +gf_rfc3986_encode_space_newline(unsigned char *s, char *enc, char *estr) { - for (; *s; s++) { - if (estr[*s]) - sprintf(enc, "%c", estr[*s]); - else - sprintf(enc, "%%%02X", *s); - while (*++enc); - } + for (; *s; s++) { + if (estr[*s]) + sprintf(enc, "%c", estr[*s]); + else + sprintf(enc, "%%%02X", *s); + while (*++enc) + ; + } } /** @@ -62,158 +58,113 @@ gf_rfc3986_encode_space_newline (unsigned char *s, char *enc, char *estr) * made a part of libglusterfs. */ -static pthread_key_t rl_key; -static pthread_once_t rl_once = PTHREAD_ONCE_INIT; - -static void -readline_destructor (void *ptr) -{ - GF_FREE (ptr); -} - -static void -readline_once (void) -{ - pthread_key_create (&rl_key, readline_destructor); -} +static __thread read_line_t thread_tsd = {}; static ssize_t -my_read (read_line_t *tsd, int fd, char *ptr) -{ - if (tsd->rl_cnt <= 0) { - tsd->rl_cnt = sys_read (fd, tsd->rl_buf, MAXLINE); - - if (tsd->rl_cnt < 0) - return -1; - else if (tsd->rl_cnt == 0) - return 0; - tsd->rl_bufptr = tsd->rl_buf; - } - - tsd->rl_cnt--; - *ptr = *tsd->rl_bufptr++; - return 1; -} - -static int -gf_readline_init_once (read_line_t **tsd) +my_read(read_line_t *tsd, int fd, char *ptr) { - if (pthread_once (&rl_once, readline_once) != 0) - return -1; + if (tsd->rl_cnt <= 0) { + tsd->rl_cnt = sys_read(fd, tsd->rl_buf, MAXLINE); - *tsd = pthread_getspecific (rl_key); - if (*tsd) - goto out; - - *tsd = GF_CALLOC (1, sizeof (**tsd), - gf_changelog_mt_libgfchangelog_rl_t); - if (!*tsd) - return -1; - - if (pthread_setspecific (rl_key, *tsd) != 0) - return -1; + if (tsd->rl_cnt < 0) + return -1; + else if (tsd->rl_cnt == 0) + return 0; + tsd->rl_bufptr = tsd->rl_buf; + } - out: - return 0; + tsd->rl_cnt--; + *ptr = *tsd->rl_bufptr++; + return 1; } ssize_t -gf_readline (int fd, void *vptr, size_t maxlen) +gf_readline(int fd, void *vptr, size_t maxlen) { - size_t n = 0; - size_t rc = 0; - char c = ' '; - char *ptr = NULL; - read_line_t *tsd = NULL; - - if (gf_readline_init_once (&tsd)) - return -1; - - ptr = vptr; - for (n = 1; n < maxlen; n++) { - if ( (rc = my_read (tsd, fd, &c)) == 1 ) { - *ptr++ = c; - if (c == '\n') - break; - } else if (rc == 0) { - *ptr = '\0'; - return (n - 1); - } else - return -1; - } - - *ptr = '\0'; - return n; - + size_t n = 0; + size_t rc = 0; + char c = ' '; + char *ptr = NULL; + read_line_t *tsd = &thread_tsd; + + ptr = vptr; + for (n = 1; n < maxlen; n++) { + if ((rc = my_read(tsd, fd, &c)) == 1) { + *ptr++ = c; + if (c == '\n') + break; + } else if (rc == 0) { + *ptr = '\0'; + return (n - 1); + } else + return -1; + } + + *ptr = '\0'; + return n; } off_t -gf_lseek (int fd, off_t offset, int whence) +gf_lseek(int fd, off_t offset, int whence) { - off_t off = 0; - read_line_t *tsd = NULL; + off_t off = 0; + read_line_t *tsd = &thread_tsd; - if (gf_readline_init_once (&tsd)) - return -1; + off = sys_lseek(fd, offset, whence); + if (off == -1) + return -1; - off = sys_lseek (fd, offset, whence); - if (off == -1) - return -1; + tsd->rl_cnt = 0; + tsd->rl_bufptr = tsd->rl_buf; - tsd->rl_cnt = 0; - tsd->rl_bufptr = tsd->rl_buf; - - return off; + return off; } int -gf_ftruncate (int fd, off_t length) +gf_ftruncate(int fd, off_t length) { - read_line_t *tsd = NULL; + read_line_t *tsd = &thread_tsd; - if (gf_readline_init_once (&tsd)) - return -1; + if (sys_ftruncate(fd, 0)) + return -1; - if (sys_ftruncate (fd, 0)) - return -1; + tsd->rl_cnt = 0; + tsd->rl_bufptr = tsd->rl_buf; - tsd->rl_cnt = 0; - tsd->rl_bufptr = tsd->rl_buf; - - return 0; + return 0; } int -gf_thread_cleanup (xlator_t *this, pthread_t thread) +gf_thread_cleanup(xlator_t *this, pthread_t thread) { - int ret = 0; - void *res = NULL; - - ret = pthread_cancel (thread); - if (ret != 0) { - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, - "Failed to send cancellation to thread"); - goto error_return; - } - - ret = pthread_join (thread, &res); - if (ret != 0) { - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, - "failed to join thread"); - goto error_return; - } - - if (res != PTHREAD_CANCELED) { - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, - "Thread could not be cleaned up"); - goto error_return; - } - - return 0; - - error_return: - return -1; + int ret = 0; + void *res = NULL; + + ret = pthread_cancel(thread); + if (ret != 0) { + gf_msg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, + "Failed to send cancellation to thread"); + goto error_return; + } + + ret = pthread_join(thread, &res); + if (ret != 0) { + gf_msg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, + "failed to join thread"); + goto error_return; + } + + if (res != PTHREAD_CANCELED) { + gf_msg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, + "Thread could not be cleaned up"); + goto error_return; + } + + return 0; + +error_return: + return -1; } diff --git a/xlators/features/changelog/lib/src/gf-changelog-helpers.h b/xlators/features/changelog/lib/src/gf-changelog-helpers.h index b05628ee70d..9c609d33172 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-helpers.h +++ b/xlators/features/changelog/lib/src/gf-changelog-helpers.h @@ -14,36 +14,37 @@ #include <unistd.h> #include <dirent.h> #include <limits.h> -#include "locking.h" +#include <glusterfs/locking.h> -#include <xlator.h> +#include <glusterfs/xlator.h> #include "changelog.h" #include "changelog-rpc-common.h" #include "gf-changelog-journal.h" -#define GF_CHANGELOG_TRACKER "tracker" +#define GF_CHANGELOG_TRACKER "tracker" -#define GF_CHANGELOG_CURRENT_DIR ".current" -#define GF_CHANGELOG_PROCESSED_DIR ".processed" +#define GF_CHANGELOG_CURRENT_DIR ".current" +#define GF_CHANGELOG_PROCESSED_DIR ".processed" #define GF_CHANGELOG_PROCESSING_DIR ".processing" -#define GF_CHANGELOG_HISTORY_DIR ".history" +#define GF_CHANGELOG_HISTORY_DIR ".history" #define TIMESTAMP_LENGTH 10 #ifndef MAXLINE #define MAXLINE 4096 #endif -#define GF_CHANGELOG_FILL_BUFFER(ptr, ascii, off, len) do { \ - memcpy (ascii + off, ptr, len); \ - off += len; \ - } while (0) +#define GF_CHANGELOG_FILL_BUFFER(ptr, ascii, off, len) \ + do { \ + memcpy(ascii + off, ptr, len); \ + off += len; \ + } while (0) typedef struct read_line { - int rl_cnt; - char *rl_bufptr; - char rl_buf[MAXLINE]; + int rl_cnt; + char *rl_bufptr; + char rl_buf[MAXLINE]; } read_line_t; struct gf_changelog; @@ -55,51 +56,50 @@ struct gf_event; * ->next_seq holds the next _expected_ sequence number. */ struct gf_event_list { - pthread_mutex_t lock; /* protects this structure */ - pthread_cond_t cond; + pthread_mutex_t lock; /* protects this structure */ + pthread_cond_t cond; - pthread_t invoker; + pthread_t invoker; - unsigned long next_seq; /* next sequence number expected: - zero during bootstrap */ + unsigned long next_seq; /* next sequence number expected: + zero during bootstrap */ - struct gf_changelog *entry; /* backpointer to it's brick - encapsulator (entry) */ - struct list_head events; /* list of events */ + struct gf_changelog *entry; /* backpointer to it's brick + encapsulator (entry) */ + struct list_head events; /* list of events */ }; /** * include a refcount if it's of use by additional layers */ struct gf_event { - int count; + int count; - unsigned long seq; + unsigned long seq; - struct list_head list; + struct list_head list; - struct iovec iov[0]; + struct iovec iov[0]; }; -#define GF_EVENT_CALLOC_SIZE(cnt, len) \ - (sizeof (struct gf_event) + (cnt * sizeof (struct iovec)) + len) +#define GF_EVENT_CALLOC_SIZE(cnt, len) \ + (sizeof(struct gf_event) + (cnt * sizeof(struct iovec)) + len) /** * assign the base address of the IO vector to the correct memory o * area and set it's addressable length. */ -#define GF_EVENT_ASSIGN_IOVEC(vec, event, len, pos) \ - do { \ - vec->iov_base = ((char *)event) + \ - sizeof (struct gf_event) + \ - (event->count * sizeof (struct iovec)) + pos; \ - vec->iov_len = len; \ - pos += len; \ - } while (0) +#define GF_EVENT_ASSIGN_IOVEC(vec, event, len, pos) \ + do { \ + vec->iov_base = ((char *)event) + sizeof(struct gf_event) + \ + (event->count * sizeof(struct iovec)) + pos; \ + vec->iov_len = len; \ + pos += len; \ + } while (0) typedef enum gf_changelog_conn_state { - GF_CHANGELOG_CONN_STATE_PENDING = 0, - GF_CHANGELOG_CONN_STATE_ACCEPTED, - GF_CHANGELOG_CONN_STATE_DISCONNECTED, + GF_CHANGELOG_CONN_STATE_PENDING = 0, + GF_CHANGELOG_CONN_STATE_ACCEPTED, + GF_CHANGELOG_CONN_STATE_DISCONNECTED, } gf_changelog_conn_state_t; /** @@ -107,153 +107,149 @@ typedef enum gf_changelog_conn_state { * notifications are streamed. */ typedef struct gf_changelog { - gf_lock_t statelock; - gf_changelog_conn_state_t connstate; + gf_lock_t statelock; + gf_changelog_conn_state_t connstate; - xlator_t *this; + xlator_t *this; - struct list_head list; /* list of instances */ + struct list_head list; /* list of instances */ - char brick[PATH_MAX]; /* brick path for this end-point */ + char brick[PATH_MAX]; /* brick path for this end-point */ - changelog_rpc_t grpc; /* rpc{-clnt,svc} for this brick */ -#define RPC_PROBER(ent) ent->grpc.rpc -#define RPC_REBORP(ent) ent->grpc.svc -#define RPC_SOCK(ent) ent->grpc.sock + changelog_rpc_t grpc; /* rpc{-clnt,svc} for this brick */ +#define RPC_PROBER(ent) ent->grpc.rpc +#define RPC_REBORP(ent) ent->grpc.svc +#define RPC_SOCK(ent) ent->grpc.sock - unsigned int notify; /* notification flag(s) */ + unsigned int notify; /* notification flag(s) */ - FINI *fini; /* destructor callback */ - CALLBACK *callback; /* event callback dispatcher */ - CONNECT *connected; /* connect callback */ - DISCONNECT *disconnected; /* disconnection callback */ + FINI *fini; /* destructor callback */ + CALLBACK *callback; /* event callback dispatcher */ + CONNECT *connected; /* connect callback */ + DISCONNECT *disconnected; /* disconnection callback */ - void *ptr; /* owner specific private data */ - xlator_t *invokerxl; /* consumers _this_, if valid, - assigned to THIS before cbk is - invoked */ + void *ptr; /* owner specific private data */ + xlator_t *invokerxl; /* consumers _this_, if valid, + assigned to THIS before cbk is + invoked */ - gf_boolean_t ordered; + gf_boolean_t ordered; - void (*queueevent) (struct gf_event_list *, struct gf_event *); - void (*pickevent) (struct gf_event_list *, struct gf_event **); + void (*queueevent)(struct gf_event_list *, struct gf_event *); + void (*pickevent)(struct gf_event_list *, struct gf_event **); - struct gf_event_list event; + struct gf_event_list event; } gf_changelog_t; static inline int -gf_changelog_filter_check (gf_changelog_t *entry, changelog_event_t *event) +gf_changelog_filter_check(gf_changelog_t *entry, changelog_event_t *event) { - if (event->ev_type & entry->notify) - return 1; - return 0; + if (event->ev_type & entry->notify) + return 1; + return 0; } -#define GF_NEED_ORDERED_EVENTS(ent) (ent->ordered == _gf_true) +#define GF_NEED_ORDERED_EVENTS(ent) (ent->ordered == _gf_true) /** private structure */ typedef struct gf_private { - pthread_mutex_t lock; /* protects ->connections, cleanups */ - pthread_cond_t cond; + pthread_mutex_t lock; /* protects ->connections, cleanups */ + pthread_cond_t cond; - void *api; /* pointer for API access */ + void *api; /* pointer for API access */ - pthread_t poller; /* event poller thread */ - pthread_t connectionjanitor; /* connection cleaner */ + pthread_t poller; /* event poller thread */ + pthread_t connectionjanitor; /* connection cleaner */ - struct list_head connections; /* list of connections */ - struct list_head cleanups; /* list of connection to be - cleaned up */ + struct list_head connections; /* list of connections */ + struct list_head cleanups; /* list of connection to be + cleaned up */ } gf_private_t; -#define GF_CHANGELOG_GET_API_PTR(this) (((gf_private_t *) this->private)->api) +#define GF_CHANGELOG_GET_API_PTR(this) (((gf_private_t *)this->private)->api) /** * upcall: invoke callback with _correct_ THIS */ -#define GF_CHANGELOG_INVOKE_CBK(this, cbk, brick, args ...) \ - do { \ - xlator_t *old_this = NULL; \ - xlator_t *invokerxl = NULL; \ - \ - invokerxl = entry->invokerxl; \ - old_this = this; \ - \ - if (invokerxl) { \ - THIS = invokerxl; \ - } \ - \ - cbk (invokerxl, brick, args); \ - THIS = old_this; \ - \ - } while (0) - -#define SAVE_THIS(xl) \ - do { \ - old_this = xl; \ - THIS = master; \ - } while (0) - -#define RESTORE_THIS() \ - do { \ - if (old_this) \ - THIS = old_this; \ - } while (0) +#define GF_CHANGELOG_INVOKE_CBK(this, cbk, brick, args...) \ + do { \ + xlator_t *old_this = NULL; \ + xlator_t *invokerxl = NULL; \ + \ + invokerxl = entry->invokerxl; \ + old_this = this; \ + \ + if (invokerxl) { \ + THIS = invokerxl; \ + } \ + \ + cbk(invokerxl, brick, args); \ + THIS = old_this; \ + \ + } while (0) + +#define SAVE_THIS(xl) \ + do { \ + old_this = xl; \ + THIS = master; \ + } while (0) + +#define RESTORE_THIS() \ + do { \ + if (old_this) \ + THIS = old_this; \ + } while (0) /** APIs and the rest */ void * -gf_changelog_process (void *data); - -ssize_t -gf_changelog_read_path (int fd, char *buffer, size_t bufsize); +gf_changelog_process(void *data); void -gf_rfc3986_encode_space_newline (unsigned char *s, char *enc, char *estr); +gf_rfc3986_encode_space_newline(unsigned char *s, char *enc, char *estr); size_t -gf_changelog_write (int fd, char *buffer, size_t len); +gf_changelog_write(int fd, char *buffer, size_t len); ssize_t -gf_readline (int fd, void *vptr, size_t maxlen); +gf_readline(int fd, void *vptr, size_t maxlen); int -gf_ftruncate (int fd, off_t length); +gf_ftruncate(int fd, off_t length); off_t -gf_lseek (int fd, off_t offset, int whence); +gf_lseek(int fd, off_t offset, int whence); int -gf_changelog_consume (xlator_t *this, - gf_changelog_journal_t *jnl, - char *from_path, gf_boolean_t no_publish); +gf_changelog_consume(xlator_t *this, gf_changelog_journal_t *jnl, + char *from_path, gf_boolean_t no_publish); int -gf_changelog_publish (xlator_t *this, - gf_changelog_journal_t *jnl, char *from_path); +gf_changelog_publish(xlator_t *this, gf_changelog_journal_t *jnl, + char *from_path); int -gf_thread_cleanup (xlator_t *this, pthread_t thread); +gf_thread_cleanup(xlator_t *this, pthread_t thread); void * -gf_changelog_callback_invoker (void *arg); +gf_changelog_callback_invoker(void *arg); int -gf_cleanup_event (xlator_t *, struct gf_event_list *); +gf_cleanup_event(xlator_t *, struct gf_event_list *); /* (un)ordered event queueing */ void -queue_ordered_event (struct gf_event_list *, struct gf_event *); +queue_ordered_event(struct gf_event_list *, struct gf_event *); void -queue_unordered_event (struct gf_event_list *, struct gf_event *); +queue_unordered_event(struct gf_event_list *, struct gf_event *); /* (un)ordered event picking */ void -pick_event_ordered (struct gf_event_list *, struct gf_event **); +pick_event_ordered(struct gf_event_list *, struct gf_event **); void -pick_event_unordered (struct gf_event_list *, struct gf_event **); +pick_event_unordered(struct gf_event_list *, struct gf_event **); /* connection janitor thread */ void * -gf_changelog_connection_janitor (void *); +gf_changelog_connection_janitor(void *); #endif diff --git a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c index 9c1a498f655..7f6e2329e71 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c +++ b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c @@ -8,11 +8,11 @@ cases as published by the Free Software Foundation. */ -#include "compat-uuid.h" -#include "globals.h" -#include "glusterfs.h" -#include "syscall.h" -#include "compat-errno.h" +#include <glusterfs/compat-uuid.h> +#include <glusterfs/globals.h> +#include <glusterfs/glusterfs.h> +#include <glusterfs/syscall.h> +#include <glusterfs/compat-errno.h> #include "gf-changelog-helpers.h" @@ -25,112 +25,107 @@ extern int byebye; -enum changelog_versions { - VERSION_1_1 = 0, - VERSION_1_2 = 1 -}; +enum changelog_versions { VERSION_1_1 = 0, VERSION_1_2 = 1 }; /** * number of gfid records after fop number */ -int nr_gfids[2][GF_FOP_MAXVALUE] = { - { - [GF_FOP_MKNOD] = 1, - [GF_FOP_MKDIR] = 1, - [GF_FOP_UNLINK] = 1, - [GF_FOP_RMDIR] = 1, - [GF_FOP_SYMLINK] = 1, - [GF_FOP_RENAME] = 2, - [GF_FOP_LINK] = 1, - [GF_FOP_CREATE] = 1, - }, - { - [GF_FOP_MKNOD] = 1, - [GF_FOP_MKDIR] = 1, - [GF_FOP_UNLINK] = 2, - [GF_FOP_RMDIR] = 2, - [GF_FOP_SYMLINK] = 1, - [GF_FOP_RENAME] = 2, - [GF_FOP_LINK] = 1, - [GF_FOP_CREATE] = 1, - } -}; - -int nr_extra_recs[2][GF_FOP_MAXVALUE] = { - { - [GF_FOP_MKNOD] = 3, - [GF_FOP_MKDIR] = 3, - [GF_FOP_UNLINK] = 0, - [GF_FOP_RMDIR] = 0, - [GF_FOP_SYMLINK] = 0, - [GF_FOP_RENAME] = 0, - [GF_FOP_LINK] = 0, - [GF_FOP_CREATE] = 3, - }, - { - [GF_FOP_MKNOD] = 3, - [GF_FOP_MKDIR] = 3, - [GF_FOP_UNLINK] = 0, - [GF_FOP_RMDIR] = 0, - [GF_FOP_SYMLINK] = 0, - [GF_FOP_RENAME] = 0, - [GF_FOP_LINK] = 0, - [GF_FOP_CREATE] = 3, - } -}; +int nr_gfids[2][GF_FOP_MAXVALUE] = {{ + [GF_FOP_MKNOD] = 1, + [GF_FOP_MKDIR] = 1, + [GF_FOP_UNLINK] = 1, + [GF_FOP_RMDIR] = 1, + [GF_FOP_SYMLINK] = 1, + [GF_FOP_RENAME] = 2, + [GF_FOP_LINK] = 1, + [GF_FOP_CREATE] = 1, + }, + { + [GF_FOP_MKNOD] = 1, + [GF_FOP_MKDIR] = 1, + [GF_FOP_UNLINK] = 2, + [GF_FOP_RMDIR] = 2, + [GF_FOP_SYMLINK] = 1, + [GF_FOP_RENAME] = 2, + [GF_FOP_LINK] = 1, + [GF_FOP_CREATE] = 1, + }}; + +int nr_extra_recs[2][GF_FOP_MAXVALUE] = {{ + [GF_FOP_MKNOD] = 3, + [GF_FOP_MKDIR] = 3, + [GF_FOP_UNLINK] = 0, + [GF_FOP_RMDIR] = 0, + [GF_FOP_SYMLINK] = 0, + [GF_FOP_RENAME] = 0, + [GF_FOP_LINK] = 0, + [GF_FOP_CREATE] = 3, + }, + { + [GF_FOP_MKNOD] = 3, + [GF_FOP_MKDIR] = 3, + [GF_FOP_UNLINK] = 0, + [GF_FOP_RMDIR] = 0, + [GF_FOP_SYMLINK] = 0, + [GF_FOP_RENAME] = 0, + [GF_FOP_LINK] = 0, + [GF_FOP_CREATE] = 3, + }}; static char * -binary_to_ascii (uuid_t uuid) +binary_to_ascii(uuid_t uuid) { - return uuid_utoa (uuid); + return uuid_utoa(uuid); } static char * -conv_noop (char *ptr) { return ptr; } - -#define VERIFY_SEPARATOR(ptr, plen, perr) \ - { \ - if (*(ptr + plen) != '\0') { \ - perr = 1; \ - break; \ - } \ - } +conv_noop(char *ptr) +{ + return ptr; +} -#define MOVER_MOVE(mover, nleft, bytes) \ - { \ - mover += bytes; \ - nleft -= bytes; \ - } \ - -#define PARSE_GFID(mov, ptr, le, fn, perr) \ - { \ - VERIFY_SEPARATOR (mov, le, perr); \ - ptr = fn (mov); \ - if (!ptr) { \ - perr = 1; \ - break; \ - } \ - } +#define VERIFY_SEPARATOR(ptr, plen, perr) \ + { \ + if (*(ptr + plen) != '\0') { \ + perr = 1; \ + break; \ + } \ + } -#define FILL_AND_MOVE(pt, buf, of, mo, nl, le) \ - { \ - GF_CHANGELOG_FILL_BUFFER (pt, buf, of, strlen (pt)); \ - MOVER_MOVE (mo, nl, le); \ - } +#define MOVER_MOVE(mover, nleft, bytes) \ + { \ + mover += bytes; \ + nleft -= bytes; \ + } + +#define PARSE_GFID(mov, ptr, le, fn, perr) \ + { \ + VERIFY_SEPARATOR(mov, le, perr); \ + ptr = fn(mov); \ + if (!ptr) { \ + perr = 1; \ + break; \ + } \ + } +#define FILL_AND_MOVE(pt, buf, of, mo, nl, le) \ + { \ + GF_CHANGELOG_FILL_BUFFER(pt, buf, of, strlen(pt)); \ + MOVER_MOVE(mo, nl, le); \ + } -#define PARSE_GFID_MOVE(ptr, uuid, mover, nleft, perr) \ - { \ - memcpy (uuid, mover, sizeof (uuid_t)); \ - ptr = binary_to_ascii (uuid); \ - if (!ptr) { \ - perr = 1; \ - break; \ - } \ - MOVER_MOVE (mover, nleft, sizeof (uuid_t)); \ - } \ +#define PARSE_GFID_MOVE(ptr, uuid, mover, nleft, perr) \ + { \ + memcpy(uuid, mover, sizeof(uuid_t)); \ + ptr = binary_to_ascii(uuid); \ + if (!ptr) { \ + perr = 1; \ + break; \ + } \ + MOVER_MOVE(mover, nleft, sizeof(uuid_t)); \ + } -#define LINE_BUFSIZE (3*PATH_MAX) /* enough buffer for extra chars too */ +#define LINE_BUFSIZE (3 * PATH_MAX) /* enough buffer for extra chars too */ /** * using mmap() makes parsing easy. fgets() cannot be used here as @@ -145,111 +140,107 @@ conv_noop (char *ptr) { return ptr; } */ static int -gf_changelog_parse_binary (xlator_t *this, - gf_changelog_journal_t *jnl, - int from_fd, int to_fd, - size_t start_offset, struct stat *stbuf, - int version_idx) +gf_changelog_parse_binary(xlator_t *this, gf_changelog_journal_t *jnl, + int from_fd, int to_fd, size_t start_offset, + struct stat *stbuf, int version_idx) { - int ret = -1; - off_t off = 0; - off_t nleft = 0; - uuid_t uuid = {0,}; - char *ptr = NULL; - char *bname_start = NULL; - char *bname_end = NULL; - char *mover = NULL; - void *start = NULL; - char current_mover = ' '; - size_t blen = 0; - int parse_err = 0; - char *ascii = NULL; - - ascii = GF_CALLOC (LINE_BUFSIZE, sizeof(char), gf_common_mt_char); - - nleft = stbuf->st_size; - - start = mmap (NULL, nleft, PROT_READ, MAP_PRIVATE, from_fd, 0); - if (start == MAP_FAILED) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_MMAP_FAILED, - "mmap() error"); - goto out; - } - - mover = start; + int ret = -1; + off_t off = 0; + off_t nleft = 0; + uuid_t uuid = { + 0, + }; + char *ptr = NULL; + char *bname_start = NULL; + char *bname_end = NULL; + char *mover = NULL; + void *start = NULL; + char current_mover = ' '; + size_t blen = 0; + int parse_err = 0; + char *ascii = NULL; + + ascii = GF_CALLOC(LINE_BUFSIZE, sizeof(char), gf_common_mt_char); + + nleft = stbuf->st_size; + + start = mmap(NULL, nleft, PROT_READ, MAP_PRIVATE, from_fd, 0); + if (start == MAP_FAILED) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_MMAP_FAILED, + "mmap() error"); + goto out; + } - MOVER_MOVE (mover, nleft, start_offset); + mover = start; - while (nleft > 0) { + MOVER_MOVE(mover, nleft, start_offset); - off = blen = 0; - ptr = bname_start = bname_end = NULL; + while (nleft > 0) { + off = blen = 0; + ptr = bname_start = bname_end = NULL; - current_mover = *mover; + current_mover = *mover; - switch (current_mover) { - case 'D': - case 'M': - MOVER_MOVE (mover, nleft, 1); - PARSE_GFID_MOVE (ptr, uuid, mover, nleft, parse_err); + switch (current_mover) { + case 'D': + case 'M': + MOVER_MOVE(mover, nleft, 1); + PARSE_GFID_MOVE(ptr, uuid, mover, nleft, parse_err); - break; + break; - case 'E': - MOVER_MOVE (mover, nleft, 1); - PARSE_GFID_MOVE (ptr, uuid, mover, nleft, parse_err); + case 'E': + MOVER_MOVE(mover, nleft, 1); + PARSE_GFID_MOVE(ptr, uuid, mover, nleft, parse_err); - bname_start = mover; - bname_end = strchr (mover, '\n'); - if (bname_end == NULL) { - parse_err = 1; - break; - } + bname_start = mover; + bname_end = strchr(mover, '\n'); + if (bname_end == NULL) { + parse_err = 1; + break; + } - blen = bname_end - bname_start; - MOVER_MOVE (mover, nleft, blen); + blen = bname_end - bname_start; + MOVER_MOVE(mover, nleft, blen); - break; + break; - default: - parse_err = 1; - } + default: + parse_err = 1; + } - if (parse_err) - break; + if (parse_err) + break; + + GF_CHANGELOG_FILL_BUFFER(¤t_mover, ascii, off, 1); + GF_CHANGELOG_FILL_BUFFER(" ", ascii, off, 1); + GF_CHANGELOG_FILL_BUFFER(ptr, ascii, off, strlen(ptr)); + if (blen) + GF_CHANGELOG_FILL_BUFFER(bname_start, ascii, off, blen); + GF_CHANGELOG_FILL_BUFFER("\n", ascii, off, 1); + + if (gf_changelog_write(to_fd, ascii, off) != off) { + gf_msg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_ASCII_ERROR, + "processing binary changelog failed due to " + " error in writing ascii change"); + break; + } - GF_CHANGELOG_FILL_BUFFER (¤t_mover, ascii, off, 1); - GF_CHANGELOG_FILL_BUFFER (" ", ascii, off, 1); - GF_CHANGELOG_FILL_BUFFER (ptr, ascii, off, strlen (ptr)); - if (blen) - GF_CHANGELOG_FILL_BUFFER (bname_start, - ascii, off, blen); - GF_CHANGELOG_FILL_BUFFER ("\n", ascii, off, 1); - - if (gf_changelog_write (to_fd, ascii, off) != off) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_ASCII_ERROR, - "processing binary changelog failed due to " - " error in writing ascii change"); - break; - } + MOVER_MOVE(mover, nleft, 1); + } - MOVER_MOVE (mover, nleft, 1); - } + if ((nleft == 0) && (!parse_err)) + ret = 0; - if ((nleft == 0) && (!parse_err)) - ret = 0; - - if (munmap (start, stbuf->st_size)) - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_MUNMAP_FAILED, - "munmap() error"); - out: - if (ascii) - GF_FREE (ascii); - return ret; + if (munmap(start, stbuf->st_size)) + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_MUNMAP_FAILED, + "munmap() error"); +out: + if (ascii) + GF_FREE(ascii); + return ret; } /** @@ -258,798 +249,781 @@ gf_changelog_parse_binary (xlator_t *this, * - use fop name rather than fop number */ static int -gf_changelog_parse_ascii (xlator_t *this, - gf_changelog_journal_t *jnl, - int from_fd, int to_fd, - size_t start_offset, struct stat *stbuf, - int version_idx) +gf_changelog_parse_ascii(xlator_t *this, gf_changelog_journal_t *jnl, + int from_fd, int to_fd, size_t start_offset, + struct stat *stbuf, int version_idx) { - int ng = 0; - int ret = -1; - int fop = 0; - int len = 0; - off_t off = 0; - off_t nleft = 0; - char *ptr = NULL; - char *eptr = NULL; - void *start = NULL; - char *mover = NULL; - int parse_err = 0; - char current_mover = ' '; - char *ascii = NULL; - const char *fopname = NULL; - - ascii = GF_CALLOC (LINE_BUFSIZE, sizeof(char), gf_common_mt_char); - - nleft = stbuf->st_size; - - start = mmap (NULL, nleft, PROT_READ, MAP_PRIVATE, from_fd, 0); - if (start == MAP_FAILED) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_MMAP_FAILED, - "mmap() error"); - goto out; - } + int ng = 0; + int ret = -1; + int fop = 0; + int len = 0; + off_t off = 0; + off_t nleft = 0; + char *ptr = NULL; + char *eptr = NULL; + void *start = NULL; + char *mover = NULL; + int parse_err = 0; + char current_mover = ' '; + char *ascii = NULL; + const char *fopname = NULL; + + ascii = GF_CALLOC(LINE_BUFSIZE, sizeof(char), gf_common_mt_char); + + nleft = stbuf->st_size; + + start = mmap(NULL, nleft, PROT_READ, MAP_PRIVATE, from_fd, 0); + if (start == MAP_FAILED) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_MMAP_FAILED, + "mmap() error"); + goto out; + } - mover = start; + mover = start; - MOVER_MOVE (mover, nleft, start_offset); + MOVER_MOVE(mover, nleft, start_offset); - while (nleft > 0) { - off = 0; - current_mover = *mover; + while (nleft > 0) { + off = 0; + current_mover = *mover; - GF_CHANGELOG_FILL_BUFFER (¤t_mover, ascii, off, 1); - GF_CHANGELOG_FILL_BUFFER (" ", ascii, off, 1); + GF_CHANGELOG_FILL_BUFFER(¤t_mover, ascii, off, 1); + GF_CHANGELOG_FILL_BUFFER(" ", ascii, off, 1); - switch (current_mover) { - case 'D': - MOVER_MOVE (mover, nleft, 1); + switch (current_mover) { + case 'D': + MOVER_MOVE(mover, nleft, 1); - /* target gfid */ - PARSE_GFID (mover, ptr, UUID_CANONICAL_FORM_LEN, - conv_noop, parse_err); - FILL_AND_MOVE(ptr, ascii, off, - mover, nleft, UUID_CANONICAL_FORM_LEN); - break; - case 'M': - MOVER_MOVE (mover, nleft, 1); + /* target gfid */ + PARSE_GFID(mover, ptr, UUID_CANONICAL_FORM_LEN, conv_noop, + parse_err); + FILL_AND_MOVE(ptr, ascii, off, mover, nleft, + UUID_CANONICAL_FORM_LEN); + break; + case 'M': + MOVER_MOVE(mover, nleft, 1); + + /* target gfid */ + PARSE_GFID(mover, ptr, UUID_CANONICAL_FORM_LEN, conv_noop, + parse_err); + FILL_AND_MOVE(ptr, ascii, off, mover, nleft, + UUID_CANONICAL_FORM_LEN); + FILL_AND_MOVE(" ", ascii, off, mover, nleft, 1); + + /* fop */ + len = strlen(mover); + VERIFY_SEPARATOR(mover, len, parse_err); + + fop = atoi(mover); + fopname = gf_fop_list[fop]; + if (fopname == NULL) { + parse_err = 1; + break; + } - /* target gfid */ - PARSE_GFID (mover, ptr, UUID_CANONICAL_FORM_LEN, - conv_noop, parse_err); - FILL_AND_MOVE (ptr, ascii, off, - mover, nleft, UUID_CANONICAL_FORM_LEN); - FILL_AND_MOVE (" ", ascii, off, mover, nleft, 1); + MOVER_MOVE(mover, nleft, len); - /* fop */ - len = strlen (mover); - VERIFY_SEPARATOR (mover, len, parse_err); + len = strlen(fopname); + GF_CHANGELOG_FILL_BUFFER(fopname, ascii, off, len); - fop = atoi (mover); - fopname = gf_fop_list[fop]; - if (fopname == NULL) { - parse_err = 1; - break; - } + break; - MOVER_MOVE (mover, nleft, len); + case 'E': + MOVER_MOVE(mover, nleft, 1); + + /* target gfid */ + PARSE_GFID(mover, ptr, UUID_CANONICAL_FORM_LEN, conv_noop, + parse_err); + FILL_AND_MOVE(ptr, ascii, off, mover, nleft, + UUID_CANONICAL_FORM_LEN); + FILL_AND_MOVE(" ", ascii, off, mover, nleft, 1); + + /* fop */ + len = strlen(mover); + VERIFY_SEPARATOR(mover, len, parse_err); + + fop = atoi(mover); + fopname = gf_fop_list[fop]; + if (fopname == NULL) { + parse_err = 1; + break; + } - len = strlen (fopname); - GF_CHANGELOG_FILL_BUFFER (fopname, ascii, off, len); + MOVER_MOVE(mover, nleft, len); - break; + len = strlen(fopname); + GF_CHANGELOG_FILL_BUFFER(fopname, ascii, off, len); - case 'E': - MOVER_MOVE (mover, nleft, 1); - - /* target gfid */ - PARSE_GFID (mover, ptr, UUID_CANONICAL_FORM_LEN, - conv_noop, parse_err); - FILL_AND_MOVE (ptr, ascii, off, - mover, nleft, UUID_CANONICAL_FORM_LEN); - FILL_AND_MOVE (" ", ascii, off, - mover, nleft, 1); - - /* fop */ - len = strlen (mover); - VERIFY_SEPARATOR (mover, len, parse_err); - - fop = atoi (mover); - fopname = gf_fop_list[fop]; - if (fopname == NULL) { - parse_err = 1; - break; - } - - MOVER_MOVE (mover, nleft, len); - - len = strlen (fopname); - GF_CHANGELOG_FILL_BUFFER (fopname, ascii, off, len); - - ng = nr_extra_recs[version_idx][fop]; - for (; ng > 0; ng--) { - MOVER_MOVE (mover, nleft, 1); - len = strlen (mover); - VERIFY_SEPARATOR (mover, len, parse_err); - - GF_CHANGELOG_FILL_BUFFER (" ", ascii, off, 1); - FILL_AND_MOVE (mover, ascii, - off, mover, nleft, len); - } - - /* pargfid + bname */ - ng = nr_gfids[version_idx][fop]; - while (ng-- > 0) { - MOVER_MOVE (mover, nleft, 1); - len = strlen (mover); - if (!len) { - MOVER_MOVE (mover, nleft, 1); - continue; - } - - GF_CHANGELOG_FILL_BUFFER (" ", ascii, off, 1); - - PARSE_GFID (mover, ptr, len, - conv_noop, parse_err); - eptr = calloc (3, strlen (ptr)); - if (!eptr) { - parse_err = 1; - break; - } - - gf_rfc3986_encode_space_newline ( - (unsigned char *) ptr, - eptr, - jnl->rfc3986_space_newline); - FILL_AND_MOVE (eptr, ascii, off, - mover, nleft, len); - free (eptr); - } + ng = nr_extra_recs[version_idx][fop]; + for (; ng > 0; ng--) { + MOVER_MOVE(mover, nleft, 1); + len = strlen(mover); + VERIFY_SEPARATOR(mover, len, parse_err); - break; - default: - parse_err = 1; + GF_CHANGELOG_FILL_BUFFER(" ", ascii, off, 1); + FILL_AND_MOVE(mover, ascii, off, mover, nleft, len); } - if (parse_err) + /* pargfid + bname */ + ng = nr_gfids[version_idx][fop]; + while (ng-- > 0) { + MOVER_MOVE(mover, nleft, 1); + len = strlen(mover); + if (!len) { + MOVER_MOVE(mover, nleft, 1); + continue; + } + + GF_CHANGELOG_FILL_BUFFER(" ", ascii, off, 1); + + PARSE_GFID(mover, ptr, len, conv_noop, parse_err); + eptr = calloc(3, strlen(ptr)); + if (!eptr) { + parse_err = 1; break; + } - GF_CHANGELOG_FILL_BUFFER ("\n", ascii, off, 1); - - if (gf_changelog_write (to_fd, ascii, off) != off) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_ASCII_ERROR, - "processing ascii changelog failed due to " - " error in writing change"); - break; + gf_rfc3986_encode_space_newline((unsigned char *)ptr, eptr, + jnl->rfc3986_space_newline); + FILL_AND_MOVE(eptr, ascii, off, mover, nleft, len); + free(eptr); } - MOVER_MOVE (mover, nleft, 1); + break; + default: + parse_err = 1; + } + + if (parse_err) + break; + + GF_CHANGELOG_FILL_BUFFER("\n", ascii, off, 1); + if (gf_changelog_write(to_fd, ascii, off) != off) { + gf_msg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_ASCII_ERROR, + "processing ascii changelog failed due to " + " error in writing change"); + break; } - if ((nleft == 0) && (!parse_err)) - ret = 0; + MOVER_MOVE(mover, nleft, 1); + } + + if ((nleft == 0) && (!parse_err)) + ret = 0; - if (munmap (start, stbuf->st_size)) - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_MUNMAP_FAILED, - "munmap() error"); + if (munmap(start, stbuf->st_size)) + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_MUNMAP_FAILED, + "munmap() error"); - out: - if (ascii) - GF_FREE (ascii); +out: + if (ascii) + GF_FREE(ascii); - return ret; + return ret; } static int -gf_changelog_decode (xlator_t *this, gf_changelog_journal_t *jnl, - int from_fd, int to_fd, struct stat *stbuf, int *zerob) +gf_changelog_decode(xlator_t *this, gf_changelog_journal_t *jnl, int from_fd, + int to_fd, struct stat *stbuf, int *zerob) { - int ret = -1; - int encoding = -1; - int major_version = -1; - int minor_version = -1; - int version_idx = -1; - size_t elen = 0; - char buffer[1024] = {0,}; - - CHANGELOG_GET_HEADER_INFO (from_fd, buffer, 1024, encoding, - major_version, minor_version, elen); - if (encoding == -1) /* unknown encoding */ - goto out; - - if (major_version == -1) /* unknown major version */ - goto out; - - if (minor_version == -1) /* unknown minor version */ - goto out; - - if (!CHANGELOG_VALID_ENCODING (encoding)) - goto out; - - if (elen == stbuf->st_size) { - *zerob = 1; - goto out; - } + int ret = -1; + int encoding = -1; + int major_version = -1; + int minor_version = -1; + int version_idx = -1; + size_t elen = 0; + char buffer[1024] = { + 0, + }; + + CHANGELOG_GET_HEADER_INFO(from_fd, buffer, sizeof(buffer), encoding, + major_version, minor_version, elen); + if (encoding == -1) /* unknown encoding */ + goto out; + + if (major_version == -1) /* unknown major version */ + goto out; + + if (minor_version == -1) /* unknown minor version */ + goto out; + + if (!CHANGELOG_VALID_ENCODING(encoding)) + goto out; + + if (elen == stbuf->st_size) { + *zerob = 1; + goto out; + } - if (major_version == 1 && minor_version == 1) { - version_idx = VERSION_1_1; - } else if (major_version == 1 && minor_version == 2) { - version_idx = VERSION_1_2; - } + if (major_version == 1 && minor_version == 1) { + version_idx = VERSION_1_1; + } else if (major_version == 1 && minor_version == 2) { + version_idx = VERSION_1_2; + } - if (version_idx == -1) /* unknown version number */ - goto out; + if (version_idx == -1) /* unknown version number */ + goto out; - /** - * start processing after the header - */ - if (sys_lseek (from_fd, elen, SEEK_SET) < 0) { - goto out; - } - switch (encoding) { + /** + * start processing after the header + */ + if (sys_lseek(from_fd, elen, SEEK_SET) < 0) { + goto out; + } + switch (encoding) { case CHANGELOG_ENCODE_BINARY: - /** - * this ideally should have been a part of changelog-encoders.c - * (ie. part of the changelog translator). - */ - ret = gf_changelog_parse_binary (this, jnl, from_fd, - to_fd, elen, stbuf, - version_idx); - break; + /** + * this ideally should have been a part of changelog-encoders.c + * (ie. part of the changelog translator). + */ + ret = gf_changelog_parse_binary(this, jnl, from_fd, to_fd, elen, + stbuf, version_idx); + break; case CHANGELOG_ENCODE_ASCII: - ret = gf_changelog_parse_ascii (this, jnl, from_fd, - to_fd, elen, stbuf, - version_idx); - break; - } + ret = gf_changelog_parse_ascii(this, jnl, from_fd, to_fd, elen, + stbuf, version_idx); + break; + } out: - return ret; + return ret; } int -gf_changelog_publish (xlator_t *this, - gf_changelog_journal_t *jnl, char *from_path) +gf_changelog_publish(xlator_t *this, gf_changelog_journal_t *jnl, + char *from_path) { - int ret = 0; - char dest[PATH_MAX] = {0,}; - char to_path[PATH_MAX] = {0,}; - struct stat stbuf = {0,}; - - (void) snprintf (to_path, PATH_MAX, "%s%s", - jnl->jnl_current_dir, basename (from_path)); - - /* handle zerob file that won't exist in current */ - ret = sys_stat (to_path, &stbuf); - if (ret) { - if (errno == ENOENT) - ret = 0; - goto out; - } + int ret = 0; + char dest[PATH_MAX] = { + 0, + }; + char to_path[PATH_MAX] = { + 0, + }; + struct stat stbuf = { + 0, + }; + + if (snprintf(to_path, PATH_MAX, "%s%s", jnl->jnl_current_dir, + basename(from_path)) >= PATH_MAX) + return -1; - (void) snprintf (dest, PATH_MAX, "%s%s", - jnl->jnl_processing_dir, basename (from_path)); + /* handle zerob file that won't exist in current */ + ret = sys_stat(to_path, &stbuf); + if (ret) { + if (errno == ENOENT) + ret = 0; + goto out; + } - ret = sys_rename (to_path, dest); - if (ret) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_RENAME_FAILED, - "error moving changelog to processing dir", - "path=%s", to_path, - NULL); - } + if (snprintf(dest, PATH_MAX, "%s%s", jnl->jnl_processing_dir, + basename(from_path)) >= PATH_MAX) + return -1; + + ret = sys_rename(to_path, dest); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_RENAME_FAILED, "from=%s", to_path, "to=%s", + dest, NULL); + } out: - return ret; + return ret; } int -gf_changelog_consume (xlator_t *this, - gf_changelog_journal_t *jnl, - char *from_path, gf_boolean_t no_publish) +gf_changelog_consume(xlator_t *this, gf_changelog_journal_t *jnl, + char *from_path, gf_boolean_t no_publish) { - int ret = -1; - int fd1 = 0; - int fd2 = 0; - int zerob = 0; - struct stat stbuf = {0,}; - char dest[PATH_MAX] = {0,}; - char to_path[PATH_MAX] = {0,}; - - ret = sys_stat (from_path, &stbuf); - if (ret || !S_ISREG(stbuf.st_mode)) { - ret = -1; - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_STAT_FAILED, - "stat failed on changelog file", - "path=%s", from_path, - NULL); - goto out; - } + int ret = -1; + int fd1 = 0; + int fd2 = 0; + int zerob = 0; + struct stat stbuf = { + 0, + }; + char dest[PATH_MAX] = { + 0, + }; + char to_path[PATH_MAX] = { + 0, + }; + + if (snprintf(to_path, PATH_MAX, "%s%s", jnl->jnl_current_dir, + basename(from_path)) >= PATH_MAX) + goto out; + if (snprintf(dest, PATH_MAX, "%s%s", jnl->jnl_processing_dir, + basename(from_path)) >= PATH_MAX) + goto out; + + ret = sys_stat(from_path, &stbuf); + if (ret || !S_ISREG(stbuf.st_mode)) { + ret = -1; + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_STAT_FAILED, + "path=%s", from_path, NULL); + goto out; + } - fd1 = open (from_path, O_RDONLY); - if (fd1 < 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_OPEN_FAILED, - "cannot open changelog file", - "path=%s", from_path, - NULL); - goto out; - } + fd1 = open(from_path, O_RDONLY); + if (fd1 < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_OPEN_FAILED, + "path=%s", from_path, NULL); + goto out; + } - (void) snprintf (to_path, PATH_MAX, "%s%s", - jnl->jnl_current_dir, basename (from_path)); - (void) snprintf (dest, PATH_MAX, "%s%s", - jnl->jnl_processing_dir, basename (from_path)); - - fd2 = open (to_path, O_CREAT | O_TRUNC | O_RDWR, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (fd2 < 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_OPEN_FAILED, - "cannot create ascii changelog file", - "path=%s", to_path, - NULL); + fd2 = open(to_path, O_CREAT | O_TRUNC | O_RDWR, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (fd2 < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_OPEN_FAILED, + "path=%s", to_path, NULL); + goto close_fd; + } else { + ret = gf_changelog_decode(this, jnl, fd1, fd2, &stbuf, &zerob); + + sys_close(fd2); + + if (!ret) { + /* move it to processing on a successful + decode */ + if (no_publish == _gf_true) goto close_fd; - } else { - ret = gf_changelog_decode (this, jnl, fd1, - fd2, &stbuf, &zerob); - - sys_close (fd2); - - if (!ret) { - /* move it to processing on a successful - decode */ - if (no_publish == _gf_true) - goto close_fd; - ret = sys_rename (to_path, dest); - if (ret) - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_RENAME_FAILED, - "error moving changelog to processing dir", - "path=%s", to_path, - NULL); - } + ret = sys_rename(to_path, dest); + if (ret) + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_RENAME_FAILED, "from=%s", to_path, + "to=%s", dest, NULL); + } - /* remove it from .current if it's an empty file */ - if (zerob) { - /* zerob changelogs must be unlinked */ - ret = sys_unlink (to_path); - if (ret) - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_UNLINK_FAILED, - "could not unlink empty changelog", - "path=%s", to_path, - NULL); - } + /* remove it from .current if it's an empty file */ + if (zerob) { + /* zerob changelogs must be unlinked */ + ret = sys_unlink(to_path); + if (ret) + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_UNLINK_FAILED, "name=empty changelog", + "path=%s", to_path, NULL); } + } - close_fd: - sys_close (fd1); +close_fd: + sys_close(fd1); - out: - return ret; +out: + return ret; } void * -gf_changelog_process (void *data) +gf_changelog_process(void *data) { - xlator_t *this = NULL; - gf_changelog_journal_t *jnl = NULL; - gf_changelog_entry_t *entry = NULL; - gf_changelog_processor_t *jnl_proc = NULL; - - jnl = data; - jnl_proc = jnl->jnl_proc; - THIS = jnl->this; - this = jnl->this; - - while (1) { - pthread_mutex_lock (&jnl_proc->lock); - { - while (list_empty (&jnl_proc->entries)) { - jnl_proc->waiting = _gf_true; - pthread_cond_wait - (&jnl_proc->cond, &jnl_proc->lock); - } - - entry = list_first_entry (&jnl_proc->entries, - gf_changelog_entry_t, list); - if (entry) - list_del (&entry->list); - - jnl_proc->waiting = _gf_false; - } - pthread_mutex_unlock (&jnl_proc->lock); + xlator_t *this = NULL; + gf_changelog_journal_t *jnl = NULL; + gf_changelog_entry_t *entry = NULL; + gf_changelog_processor_t *jnl_proc = NULL; + + jnl = data; + jnl_proc = jnl->jnl_proc; + THIS = jnl->this; + this = jnl->this; + + while (1) { + pthread_mutex_lock(&jnl_proc->lock); + { + while (list_empty(&jnl_proc->entries)) { + jnl_proc->waiting = _gf_true; + pthread_cond_wait(&jnl_proc->cond, &jnl_proc->lock); + } - if (entry) { - (void) gf_changelog_consume (this, jnl, - entry->path, _gf_false); - GF_FREE (entry); - } + entry = list_first_entry(&jnl_proc->entries, gf_changelog_entry_t, + list); + if (entry) + list_del(&entry->list); + + jnl_proc->waiting = _gf_false; } + pthread_mutex_unlock(&jnl_proc->lock); - return NULL; + if (entry) { + (void)gf_changelog_consume(this, jnl, entry->path, _gf_false); + GF_FREE(entry); + } + } + + return NULL; } void -gf_changelog_queue_journal (gf_changelog_processor_t *jnl_proc, - changelog_event_t *event) +gf_changelog_queue_journal(gf_changelog_processor_t *jnl_proc, + changelog_event_t *event) { - size_t len = 0; - gf_changelog_entry_t *entry = NULL; + size_t len = 0; + gf_changelog_entry_t *entry = NULL; - entry = GF_CALLOC (1, sizeof (gf_changelog_entry_t), - gf_changelog_mt_libgfchangelog_entry_t); - if (!entry) - return; - INIT_LIST_HEAD (&entry->list); + entry = GF_CALLOC(1, sizeof(gf_changelog_entry_t), + gf_changelog_mt_libgfchangelog_entry_t); + if (!entry) + return; + INIT_LIST_HEAD(&entry->list); - len = strlen (event->u.journal.path); - (void)memcpy (entry->path, event->u.journal.path, len+1); - entry->path[len] = '\0'; + len = strlen(event->u.journal.path); + (void)memcpy(entry->path, event->u.journal.path, len + 1); + entry->path[len] = '\0'; - pthread_mutex_lock (&jnl_proc->lock); - { - list_add_tail (&entry->list, &jnl_proc->entries); - if (jnl_proc->waiting) - pthread_cond_signal (&jnl_proc->cond); - } - pthread_mutex_unlock (&jnl_proc->lock); + pthread_mutex_lock(&jnl_proc->lock); + { + list_add_tail(&entry->list, &jnl_proc->entries); + if (jnl_proc->waiting) + pthread_cond_signal(&jnl_proc->cond); + } + pthread_mutex_unlock(&jnl_proc->lock); - return; + return; } void -gf_changelog_handle_journal (void *xl, char *brick, - void *cbkdata, changelog_event_t *event) +gf_changelog_handle_journal(void *xl, char *brick, void *cbkdata, + changelog_event_t *event) { - gf_changelog_journal_t *jnl = NULL; - gf_changelog_processor_t *jnl_proc = NULL; + gf_changelog_journal_t *jnl = NULL; + gf_changelog_processor_t *jnl_proc = NULL; - jnl = cbkdata; - jnl_proc = jnl->jnl_proc; + jnl = cbkdata; + jnl_proc = jnl->jnl_proc; - gf_changelog_queue_journal (jnl_proc, event); + gf_changelog_queue_journal(jnl_proc, event); } void -gf_changelog_journal_disconnect (void *xl, char *brick, void *data) +gf_changelog_journal_disconnect(void *xl, char *brick, void *data) { - gf_changelog_journal_t *jnl = NULL; + gf_changelog_journal_t *jnl = NULL; - jnl = data; + jnl = data; - pthread_spin_lock (&jnl->lock); - { - JNL_SET_API_STATE (jnl, JNL_API_DISCONNECTED); - }; - pthread_spin_unlock (&jnl->lock); + pthread_spin_lock(&jnl->lock); + { + JNL_SET_API_STATE(jnl, JNL_API_DISCONNECTED); + }; + pthread_spin_unlock(&jnl->lock); } void -gf_changelog_journal_connect (void *xl, char *brick, void *data) +gf_changelog_journal_connect(void *xl, char *brick, void *data) { - gf_changelog_journal_t *jnl = NULL; + gf_changelog_journal_t *jnl = NULL; - jnl = data; + jnl = data; - pthread_spin_lock (&jnl->lock); - { - JNL_SET_API_STATE (jnl, JNL_API_CONNECTED); - }; - pthread_spin_unlock (&jnl->lock); + pthread_spin_lock(&jnl->lock); + { + JNL_SET_API_STATE(jnl, JNL_API_CONNECTED); + }; + pthread_spin_unlock(&jnl->lock); - return; + return; } void -gf_changelog_cleanup_processor (gf_changelog_journal_t *jnl) +gf_changelog_cleanup_processor(gf_changelog_journal_t *jnl) { - int ret = 0; - xlator_t *this = NULL; - gf_changelog_processor_t *jnl_proc = NULL; - - this = THIS; - if (!this || !jnl || !jnl->jnl_proc) - goto error_return; - - jnl_proc = jnl->jnl_proc; - - ret = gf_thread_cleanup (this, jnl_proc->processor); - if (ret != 0) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_CLEANUP_ERROR, - "failed to cleanup processor thread"); - goto error_return; - } + int ret = 0; + xlator_t *this = NULL; + gf_changelog_processor_t *jnl_proc = NULL; - (void)pthread_mutex_destroy (&jnl_proc->lock); - (void)pthread_cond_destroy (&jnl_proc->cond); + this = THIS; + if (!this || !jnl || !jnl->jnl_proc) + goto error_return; - GF_FREE (jnl_proc); + jnl_proc = jnl->jnl_proc; - error_return: - return; + ret = gf_thread_cleanup(this, jnl_proc->processor); + if (ret != 0) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_CLEANUP_ERROR, + "failed to cleanup processor thread"); + goto error_return; + } + + (void)pthread_mutex_destroy(&jnl_proc->lock); + (void)pthread_cond_destroy(&jnl_proc->cond); + + GF_FREE(jnl_proc); + +error_return: + return; } int -gf_changelog_init_processor (gf_changelog_journal_t *jnl) +gf_changelog_init_processor(gf_changelog_journal_t *jnl) { - int ret = -1; - gf_changelog_processor_t *jnl_proc = NULL; + int ret = -1; + gf_changelog_processor_t *jnl_proc = NULL; - jnl_proc = GF_CALLOC (1, sizeof (gf_changelog_processor_t), - gf_changelog_mt_libgfchangelog_t); - if (!jnl_proc) - goto error_return; - - ret = pthread_mutex_init (&jnl_proc->lock, NULL); - if (ret != 0) - goto free_jnl_proc; - ret = pthread_cond_init (&jnl_proc->cond, NULL); - if (ret != 0) - goto cleanup_mutex; - - INIT_LIST_HEAD (&jnl_proc->entries); - jnl_proc->waiting = _gf_false; - jnl->jnl_proc = jnl_proc; - - ret = gf_thread_create (&jnl_proc->processor, - NULL, gf_changelog_process, jnl, "clogproc"); - if (ret != 0) { - jnl->jnl_proc = NULL; - goto cleanup_cond; - } + jnl_proc = GF_CALLOC(1, sizeof(gf_changelog_processor_t), + gf_changelog_mt_libgfchangelog_t); + if (!jnl_proc) + goto error_return; + + ret = pthread_mutex_init(&jnl_proc->lock, NULL); + if (ret != 0) + goto free_jnl_proc; + ret = pthread_cond_init(&jnl_proc->cond, NULL); + if (ret != 0) + goto cleanup_mutex; + + INIT_LIST_HEAD(&jnl_proc->entries); + jnl_proc->waiting = _gf_false; + jnl->jnl_proc = jnl_proc; + + ret = gf_thread_create(&jnl_proc->processor, NULL, gf_changelog_process, + jnl, "clogproc"); + if (ret != 0) { + jnl->jnl_proc = NULL; + goto cleanup_cond; + } - return 0; + return 0; - cleanup_cond: - (void) pthread_cond_destroy (&jnl_proc->cond); - cleanup_mutex: - (void) pthread_mutex_destroy (&jnl_proc->lock); - free_jnl_proc: - GF_FREE (jnl_proc); - error_return: - return -1; +cleanup_cond: + (void)pthread_cond_destroy(&jnl_proc->cond); +cleanup_mutex: + (void)pthread_mutex_destroy(&jnl_proc->lock); +free_jnl_proc: + GF_FREE(jnl_proc); +error_return: + return -1; } static void -gf_changelog_cleanup_fds (gf_changelog_journal_t *jnl) +gf_changelog_cleanup_fds(gf_changelog_journal_t *jnl) { - /* tracker fd */ - if (jnl->jnl_fd != -1) - sys_close (jnl->jnl_fd); - /* processing dir */ - if (jnl->jnl_dir) - sys_closedir (jnl->jnl_dir); - - if (jnl->jnl_working_dir) - free (jnl->jnl_working_dir); /* allocated by realpath */ + /* tracker fd */ + if (jnl->jnl_fd != -1) + sys_close(jnl->jnl_fd); + /* processing dir */ + if (jnl->jnl_dir) + sys_closedir(jnl->jnl_dir); + + if (jnl->jnl_working_dir) + free(jnl->jnl_working_dir); /* allocated by realpath */ } static int -gf_changelog_open_dirs (xlator_t *this, gf_changelog_journal_t *jnl) +gf_changelog_open_dirs(xlator_t *this, gf_changelog_journal_t *jnl) { - int ret = -1; - DIR *dir = NULL; - int tracker_fd = 0; - char tracker_path[PATH_MAX] = {0,}; - - /* .current */ - (void) snprintf (jnl->jnl_current_dir, PATH_MAX, - "%s/"GF_CHANGELOG_CURRENT_DIR"/", - jnl->jnl_working_dir); - ret = recursive_rmdir (jnl->jnl_current_dir); - if (ret) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_FAILED_TO_RMDIR, - "Failed to rmdir", - "path=%s", jnl->jnl_current_dir, - NULL); - goto out; - } - ret = mkdir_p (jnl->jnl_current_dir, 0600, _gf_false); - if (ret) - goto out; + int ret = -1; + DIR *dir = NULL; + int tracker_fd = 0; + char tracker_path[PATH_MAX] = { + 0, + }; + + /* .current */ + (void)snprintf(jnl->jnl_current_dir, PATH_MAX, + "%s/" GF_CHANGELOG_CURRENT_DIR "/", jnl->jnl_working_dir); + ret = recursive_rmdir(jnl->jnl_current_dir); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_FAILED_TO_RMDIR, "path=%s", + jnl->jnl_current_dir, NULL); + goto out; + } + ret = mkdir_p(jnl->jnl_current_dir, 0600, _gf_false); + if (ret) + goto out; + + /* .processed */ + (void)snprintf(jnl->jnl_processed_dir, PATH_MAX, + "%s/" GF_CHANGELOG_PROCESSED_DIR "/", jnl->jnl_working_dir); + ret = mkdir_p(jnl->jnl_processed_dir, 0600, _gf_false); + if (ret) + goto out; + + /* .processing */ + (void)snprintf(jnl->jnl_processing_dir, PATH_MAX, + "%s/" GF_CHANGELOG_PROCESSING_DIR "/", jnl->jnl_working_dir); + ret = recursive_rmdir(jnl->jnl_processing_dir); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_FAILED_TO_RMDIR, "path=%s", + jnl->jnl_processing_dir, NULL); + goto out; + } - /* .processed */ - (void) snprintf (jnl->jnl_processed_dir, PATH_MAX, - "%s/"GF_CHANGELOG_PROCESSED_DIR"/", - jnl->jnl_working_dir); - ret = mkdir_p (jnl->jnl_processed_dir, 0600, _gf_false); - if (ret) - goto out; - - /* .processing */ - (void) snprintf (jnl->jnl_processing_dir, PATH_MAX, - "%s/"GF_CHANGELOG_PROCESSING_DIR"/", - jnl->jnl_working_dir); - ret = recursive_rmdir (jnl->jnl_processing_dir); - if (ret) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_FAILED_TO_RMDIR, - "Failed to rmdir", - "path=%s", jnl->jnl_processing_dir, - NULL); - goto out; - } + ret = mkdir_p(jnl->jnl_processing_dir, 0600, _gf_false); + if (ret) + goto out; - ret = mkdir_p (jnl->jnl_processing_dir, 0600, _gf_false); - if (ret) - goto out; - - dir = sys_opendir (jnl->jnl_processing_dir); - if (!dir) { - gf_msg ("", GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_OPENDIR_ERROR, - "opendir() error"); - goto out; - } + dir = sys_opendir(jnl->jnl_processing_dir); + if (!dir) { + gf_msg("", GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_OPENDIR_ERROR, + "opendir() error"); + goto out; + } - jnl->jnl_dir = dir; + jnl->jnl_dir = dir; - (void) snprintf (tracker_path, PATH_MAX, - "%s/"GF_CHANGELOG_TRACKER, jnl->jnl_working_dir); + (void)snprintf(tracker_path, PATH_MAX, "%s/" GF_CHANGELOG_TRACKER, + jnl->jnl_working_dir); - tracker_fd = open (tracker_path, O_CREAT | O_APPEND | O_RDWR, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (tracker_fd < 0) { - sys_closedir (jnl->jnl_dir); - ret = -1; - goto out; - } + tracker_fd = open(tracker_path, O_CREAT | O_APPEND | O_RDWR, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (tracker_fd < 0) { + sys_closedir(jnl->jnl_dir); + ret = -1; + goto out; + } - jnl->jnl_fd = tracker_fd; - ret = 0; - out: - return ret; + jnl->jnl_fd = tracker_fd; + ret = 0; +out: + return ret; } int -gf_changelog_init_history (xlator_t *this, - gf_changelog_journal_t *jnl, - char *brick_path) +gf_changelog_init_history(xlator_t *this, gf_changelog_journal_t *jnl, + char *brick_path) { - int i = 0; - int ret = 0; - char hist_scratch_dir[PATH_MAX] = {0,}; + int i = 0; + int ret = 0; + char hist_scratch_dir[PATH_MAX] = { + 0, + }; - jnl->hist_jnl = GF_CALLOC (1, sizeof (*jnl), - gf_changelog_mt_libgfchangelog_t); - if (!jnl->hist_jnl) - goto error_return; + jnl->hist_jnl = GF_CALLOC(1, sizeof(*jnl), + gf_changelog_mt_libgfchangelog_t); + if (!jnl->hist_jnl) + goto error_return; - jnl->hist_jnl->jnl_dir = NULL; - jnl->hist_jnl->jnl_fd = -1; + jnl->hist_jnl->jnl_dir = NULL; + jnl->hist_jnl->jnl_fd = -1; - (void) snprintf (hist_scratch_dir, PATH_MAX, - "%s/"GF_CHANGELOG_HISTORY_DIR"/", - jnl->jnl_working_dir); + (void)snprintf(hist_scratch_dir, PATH_MAX, + "%s/" GF_CHANGELOG_HISTORY_DIR "/", jnl->jnl_working_dir); - ret = mkdir_p (hist_scratch_dir, 0600, _gf_false); - if (ret) - goto dealloc_hist; - - jnl->hist_jnl->jnl_working_dir = realpath (hist_scratch_dir, NULL); - if (!jnl->hist_jnl->jnl_working_dir) - goto dealloc_hist; - - ret = gf_changelog_open_dirs (this, jnl->hist_jnl); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_OPENDIR_ERROR, - "could not create entries in history scratch dir"); - goto dealloc_hist; - } + ret = mkdir_p(hist_scratch_dir, 0600, _gf_false); + if (ret) + goto dealloc_hist; - (void) strncpy (jnl->hist_jnl->jnl_brickpath, brick_path, PATH_MAX-1); - jnl->hist_jnl->jnl_brickpath[PATH_MAX-1] = 0; + jnl->hist_jnl->jnl_working_dir = realpath(hist_scratch_dir, NULL); + if (!jnl->hist_jnl->jnl_working_dir) + goto dealloc_hist; - for (i = 0; i < 256; i++) { - jnl->hist_jnl->rfc3986_space_newline[i] = - (i == ' ' || i == '\n' || i == '%') ? 0 : i; - } + ret = gf_changelog_open_dirs(this, jnl->hist_jnl); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_OPENDIR_ERROR, + "could not create entries in history scratch dir"); + goto dealloc_hist; + } - return 0; + if (snprintf(jnl->hist_jnl->jnl_brickpath, PATH_MAX, "%s", brick_path) >= + PATH_MAX) + goto dealloc_hist; - dealloc_hist: - GF_FREE (jnl->hist_jnl); - jnl->hist_jnl = NULL; - error_return: - return -1; + for (i = 0; i < 256; i++) { + jnl->hist_jnl->rfc3986_space_newline[i] = (i == ' ' || i == '\n' || + i == '%') + ? 0 + : i; + } + + return 0; + +dealloc_hist: + GF_FREE(jnl->hist_jnl); + jnl->hist_jnl = NULL; +error_return: + return -1; } void -gf_changelog_journal_fini (void *xl, char *brick, void *data) +gf_changelog_journal_fini(void *xl, char *brick, void *data) { - gf_changelog_journal_t *jnl = NULL; + gf_changelog_journal_t *jnl = NULL; - jnl = data; + jnl = data; - gf_changelog_cleanup_processor (jnl); + gf_changelog_cleanup_processor(jnl); - gf_changelog_cleanup_fds (jnl); - if (jnl->hist_jnl) - gf_changelog_cleanup_fds (jnl->hist_jnl); + gf_changelog_cleanup_fds(jnl); + if (jnl->hist_jnl) + gf_changelog_cleanup_fds(jnl->hist_jnl); - GF_FREE (jnl); + GF_FREE(jnl); } void * -gf_changelog_journal_init (void *xl, struct gf_brick_spec *brick) +gf_changelog_journal_init(void *xl, struct gf_brick_spec *brick) { - int i = 0; - int ret = 0; - xlator_t *this = NULL; - struct stat buf = {0,}; - char *scratch_dir = NULL; - gf_changelog_journal_t *jnl = NULL; - - this = xl; - scratch_dir = (char *) brick->ptr; - - jnl = GF_CALLOC (1, sizeof (gf_changelog_journal_t), - gf_changelog_mt_libgfchangelog_t); - if (!jnl) - goto error_return; - - if (sys_stat (scratch_dir, &buf) && errno == ENOENT) { - ret = mkdir_p (scratch_dir, 0600, _gf_true); - if (ret) - goto dealloc_private; - } - - jnl->jnl_working_dir = realpath (scratch_dir, NULL); - if (!jnl->jnl_working_dir) - goto dealloc_private; - - ret = gf_changelog_open_dirs (this, jnl); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_OPENDIR_ERROR, - "could not create entries in scratch dir"); - goto dealloc_private; - } + int i = 0; + int ret = 0; + xlator_t *this = NULL; + struct stat buf = { + 0, + }; + char *scratch_dir = NULL; + gf_changelog_journal_t *jnl = NULL; + + this = xl; + scratch_dir = (char *)brick->ptr; + + jnl = GF_CALLOC(1, sizeof(gf_changelog_journal_t), + gf_changelog_mt_libgfchangelog_t); + if (!jnl) + goto error_return; + + if (snprintf(jnl->jnl_brickpath, PATH_MAX, "%s", brick->brick_path) >= + PATH_MAX) + goto dealloc_private; + + if (sys_stat(scratch_dir, &buf) && errno == ENOENT) { + ret = mkdir_p(scratch_dir, 0600, _gf_true); + if (ret) + goto dealloc_private; + } - (void) strncpy (jnl->jnl_brickpath, brick->brick_path, PATH_MAX-1); - jnl->jnl_brickpath[PATH_MAX-1] = 0; + jnl->jnl_working_dir = realpath(scratch_dir, NULL); + if (!jnl->jnl_working_dir) + goto dealloc_private; - /* RFC 3986 {de,en}coding */ - for (i = 0; i < 256; i++) { - jnl->rfc3986_space_newline[i] = - (i == ' ' || i == '\n' || i == '%') ? 0 : i; - } + ret = gf_changelog_open_dirs(this, jnl); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_OPENDIR_ERROR, + "could not create entries in scratch dir"); + goto dealloc_private; + } - ret = gf_changelog_init_history (this, jnl, brick->brick_path); - if (ret) - goto cleanup_fds; + /* RFC 3986 {de,en}coding */ + for (i = 0; i < 256; i++) { + jnl->rfc3986_space_newline[i] = (i == ' ' || i == '\n' || i == '%') ? 0 + : i; + } - /* initialize journal processor */ - jnl->this = this; - ret = gf_changelog_init_processor (jnl); - if (ret) - goto cleanup_fds; - - JNL_SET_API_STATE (jnl, JNL_API_CONN_INPROGESS); - ret = pthread_spin_init (&jnl->lock, 0); - if (ret != 0) - goto cleanup_processor; - return jnl; - - cleanup_processor: - gf_changelog_cleanup_processor (jnl); - cleanup_fds: - gf_changelog_cleanup_fds (jnl); - if (jnl->hist_jnl) - gf_changelog_cleanup_fds (jnl->hist_jnl); - dealloc_private: - GF_FREE (jnl); - error_return: - return NULL; + ret = gf_changelog_init_history(this, jnl, brick->brick_path); + if (ret) + goto cleanup_fds; + + /* initialize journal processor */ + jnl->this = this; + ret = gf_changelog_init_processor(jnl); + if (ret) + goto cleanup_fds; + + JNL_SET_API_STATE(jnl, JNL_API_CONN_INPROGESS); + ret = pthread_spin_init(&jnl->lock, 0); + if (ret != 0) + goto cleanup_processor; + return jnl; + +cleanup_processor: + gf_changelog_cleanup_processor(jnl); +cleanup_fds: + gf_changelog_cleanup_fds(jnl); + if (jnl->hist_jnl) + gf_changelog_cleanup_fds(jnl->hist_jnl); +dealloc_private: + GF_FREE(jnl); +error_return: + return NULL; } diff --git a/xlators/features/changelog/lib/src/gf-changelog-journal.h b/xlators/features/changelog/lib/src/gf-changelog-journal.h index 46d50f159d9..ba5b9bf827e 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-journal.h +++ b/xlators/features/changelog/lib/src/gf-changelog-journal.h @@ -17,91 +17,91 @@ #include "changelog.h" enum api_conn { - JNL_API_CONNECTED, - JNL_API_CONN_INPROGESS, - JNL_API_DISCONNECTED, + JNL_API_CONNECTED, + JNL_API_CONN_INPROGESS, + JNL_API_DISCONNECTED, }; typedef struct gf_changelog_entry { - char path[PATH_MAX]; + char path[PATH_MAX]; - struct list_head list; + struct list_head list; } gf_changelog_entry_t; typedef struct gf_changelog_processor { - pthread_mutex_t lock; /* protects ->entries */ - pthread_cond_t cond; /* waiter during empty list */ - gf_boolean_t waiting; + pthread_mutex_t lock; /* protects ->entries */ + pthread_cond_t cond; /* waiter during empty list */ + gf_boolean_t waiting; - pthread_t processor; /* thread-id of journal processing thread */ + pthread_t processor; /* thread-id of journal processing thread */ - struct list_head entries; + struct list_head entries; } gf_changelog_processor_t; typedef struct gf_changelog_journal { - DIR *jnl_dir; /* 'processing' directory stream */ + DIR *jnl_dir; /* 'processing' directory stream */ - int jnl_fd; /* fd to the tracker file */ + int jnl_fd; /* fd to the tracker file */ - char jnl_brickpath[PATH_MAX]; /* brick path for this end-point */ + char jnl_brickpath[PATH_MAX]; /* brick path for this end-point */ - gf_changelog_processor_t *jnl_proc; + gf_changelog_processor_t *jnl_proc; - char *jnl_working_dir; /* scratch directory */ + char *jnl_working_dir; /* scratch directory */ - char jnl_current_dir[PATH_MAX]; - char jnl_processed_dir[PATH_MAX]; - char jnl_processing_dir[PATH_MAX]; + char jnl_current_dir[PATH_MAX]; + char jnl_processed_dir[PATH_MAX]; + char jnl_processing_dir[PATH_MAX]; - char rfc3986_space_newline[256]; /* RFC 3986 string encoding */ + char rfc3986_space_newline[256]; /* RFC 3986 string encoding */ - struct gf_changelog_journal *hist_jnl; - int hist_done; /* holds 0 done scanning, - 1 keep scanning and -1 error */ + struct gf_changelog_journal *hist_jnl; + int hist_done; /* holds 0 done scanning, + 1 keep scanning and -1 error */ - pthread_spinlock_t lock; - int connected; - xlator_t *this; + pthread_spinlock_t lock; + int connected; + xlator_t *this; } gf_changelog_journal_t; -#define JNL_SET_API_STATE(jnl, state) (jnl->connected = state) -#define JNL_IS_API_DISCONNECTED(jnl) (jnl->connected == JNL_API_DISCONNECTED) +#define JNL_SET_API_STATE(jnl, state) (jnl->connected = state) +#define JNL_IS_API_DISCONNECTED(jnl) (jnl->connected == JNL_API_DISCONNECTED) /* History API */ typedef struct gf_changelog_history_data { - int len; + int len; - int htime_fd; + int htime_fd; - /* parallelism count */ - int n_parallel; + /* parallelism count */ + int n_parallel; - /* history from, to indexes */ - unsigned long from; - unsigned long to; - xlator_t *this; + /* history from, to indexes */ + unsigned long from; + unsigned long to; + xlator_t *this; } gf_changelog_history_data_t; typedef struct gf_changelog_consume_data { - /** set of inputs */ + /** set of inputs */ - /* fd to read from */ - int fd; + /* fd to read from */ + int fd; - /* from @offset */ - off_t offset; + /* from @offset */ + off_t offset; - xlator_t *this; + xlator_t *this; - gf_changelog_journal_t *jnl; + gf_changelog_journal_t *jnl; - /** set of outputs */ + /** set of outputs */ - /* return value */ - int retval; + /* return value */ + int retval; - /* journal processed */ - char changelog[PATH_MAX]; + /* journal processed */ + char changelog[PATH_MAX]; } gf_changelog_consume_data_t; /* event handler */ diff --git a/xlators/features/changelog/lib/src/gf-changelog-reborp.c b/xlators/features/changelog/lib/src/gf-changelog-reborp.c index f9fb8fcf01a..56b11cbb705 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-reborp.c +++ b/xlators/features/changelog/lib/src/gf-changelog-reborp.c @@ -15,143 +15,126 @@ #include "changelog-rpc-common.h" #include "changelog-lib-messages.h" -#include "syscall.h" +#include <glusterfs/syscall.h> /** * Reverse socket: actual data transfer handler. Connection * initiator is PROBER, data transfer is REBORP. */ -struct rpcsvc_program *gf_changelog_reborp_programs[]; +static struct rpcsvc_program *gf_changelog_reborp_programs[]; void * -gf_changelog_connection_janitor (void *arg) +gf_changelog_connection_janitor(void *arg) { - int32_t ret = 0; - xlator_t *this = NULL; - gf_private_t *priv = NULL; - gf_changelog_t *entry = NULL; - struct gf_event *event = NULL; - struct gf_event_list *ev = NULL; - unsigned long drained = 0; - - this = arg; - THIS = this; - - priv = this->private; - - while (1) { - pthread_mutex_lock (&priv->lock); - { - while (list_empty (&priv->cleanups)) - pthread_cond_wait (&priv->cond, &priv->lock); - - entry = list_first_entry (&priv->cleanups, - gf_changelog_t, list); - list_del_init (&entry->list); - } - pthread_mutex_unlock (&priv->lock); - - drained = 0; - ev = &entry->event; - - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_LIB_MSG_CLEANING_BRICK_ENTRY_INFO, - "Cleaning brick entry for brick", - "brick=%s", entry->brick, - NULL); - - /* 0x0: disable rpc-clnt */ - rpc_clnt_disable (RPC_PROBER (entry)); - - /* 0x1: cleanup callback invoker thread */ - ret = gf_cleanup_event (this, ev); - if (ret) - continue; - - /* 0x2: drain pending events */ - while (!list_empty (&ev->events)) { - event = list_first_entry (&ev->events, - struct gf_event, list); - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_LIB_MSG_DRAINING_EVENT_INFO, - "Draining event", - "seq=%lu", event->seq, - "payload=%d", event->count, - NULL); - - GF_FREE (event); - drained++; - } - - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_LIB_MSG_DRAINING_EVENT_INFO, - "Drained events", - "num=%lu", drained, - NULL); - - /* 0x3: freeup brick entry */ - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_LIB_MSG_FREEING_ENTRY_INFO, - "freeing entry", - "entry=%p", entry, - NULL); - LOCK_DESTROY (&entry->statelock); - GF_FREE (entry); + int32_t ret = 0; + xlator_t *this = NULL; + gf_private_t *priv = NULL; + gf_changelog_t *entry = NULL; + struct gf_event *event = NULL; + struct gf_event_list *ev = NULL; + unsigned long drained = 0; + + this = arg; + THIS = this; + + priv = this->private; + + while (1) { + pthread_mutex_lock(&priv->lock); + { + while (list_empty(&priv->cleanups)) + pthread_cond_wait(&priv->cond, &priv->lock); + + entry = list_first_entry(&priv->cleanups, gf_changelog_t, list); + list_del_init(&entry->list); + } + pthread_mutex_unlock(&priv->lock); + + drained = 0; + ev = &entry->event; + + gf_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_LIB_MSG_CLEANING_BRICK_ENTRY_INFO, "brick=%s", + entry->brick, NULL); + + /* 0x0: disable rpc-clnt */ + rpc_clnt_disable(RPC_PROBER(entry)); + + /* 0x1: cleanup callback invoker thread */ + ret = gf_cleanup_event(this, ev); + if (ret) + continue; + + /* 0x2: drain pending events */ + while (!list_empty(&ev->events)) { + event = list_first_entry(&ev->events, struct gf_event, list); + gf_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_LIB_MSG_DRAINING_EVENT_INFO, "seq=%lu", + event->seq, "payload=%d", event->count, NULL); + + GF_FREE(event); + drained++; } - return NULL; + gf_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_LIB_MSG_DRAINED_EVENT_INFO, "num=%lu", drained, NULL); + + /* 0x3: freeup brick entry */ + gf_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_LIB_MSG_FREEING_ENTRY_INFO, "entry=%p", entry, NULL); + LOCK_DESTROY(&entry->statelock); + GF_FREE(entry); + } + + return NULL; } int -gf_changelog_reborp_rpcsvc_notify (rpcsvc_t *rpc, void *mydata, - rpcsvc_event_t event, void *data) +gf_changelog_reborp_rpcsvc_notify(rpcsvc_t *rpc, void *mydata, + rpcsvc_event_t event, void *data) { - int ret = 0; - xlator_t *this = NULL; - gf_changelog_t *entry = NULL; + int ret = 0; + xlator_t *this = NULL; + gf_changelog_t *entry = NULL; - if (!(event == RPCSVC_EVENT_ACCEPT || - event == RPCSVC_EVENT_DISCONNECT)) - return 0; + if (!(event == RPCSVC_EVENT_ACCEPT || event == RPCSVC_EVENT_DISCONNECT)) + return 0; - entry = mydata; - this = entry->this; + entry = mydata; + this = entry->this; - switch (event) { + switch (event) { case RPCSVC_EVENT_ACCEPT: - ret = sys_unlink (RPC_SOCK(entry)); - if (ret != 0) - gf_smsg (this->name, GF_LOG_WARNING, errno, - CHANGELOG_LIB_MSG_UNLINK_FAILED, - "failed to unlink " - "reverse socket", - "path=%s", RPC_SOCK (entry), - NULL); - if (entry->connected) - GF_CHANGELOG_INVOKE_CBK (this, entry->connected, - entry->brick, entry->ptr); - break; + ret = sys_unlink(RPC_SOCK(entry)); + if (ret != 0) + gf_smsg(this->name, GF_LOG_WARNING, errno, + CHANGELOG_LIB_MSG_UNLINK_FAILED, "name=reverse socket", + "path=%s", RPC_SOCK(entry), NULL); + if (entry->connected) + GF_CHANGELOG_INVOKE_CBK(this, entry->connected, entry->brick, + entry->ptr); + break; case RPCSVC_EVENT_DISCONNECT: - if (entry->disconnected) - GF_CHANGELOG_INVOKE_CBK (this, entry->disconnected, - entry->brick, entry->ptr); - /* passthrough */ + if (entry->disconnected) + GF_CHANGELOG_INVOKE_CBK(this, entry->disconnected, entry->brick, + entry->ptr); + /* passthrough */ default: - break; - } + break; + } - return 0; + return 0; } rpcsvc_t * -gf_changelog_reborp_init_rpc_listner (xlator_t *this, - char *path, char *sock, void *cbkdata) +gf_changelog_reborp_init_rpc_listner(xlator_t *this, char *path, char *sock, + void *cbkdata) { - CHANGELOG_MAKE_TMP_SOCKET_PATH (path, sock, UNIX_PATH_MAX); - return changelog_rpc_server_init (this, sock, cbkdata, - gf_changelog_reborp_rpcsvc_notify, - gf_changelog_reborp_programs); + CHANGELOG_MAKE_TMP_SOCKET_PATH(path, sock, UNIX_PATH_MAX); + return changelog_rpc_server_init(this, sock, cbkdata, + gf_changelog_reborp_rpcsvc_notify, + gf_changelog_reborp_programs); } /** @@ -164,29 +147,27 @@ gf_changelog_reborp_init_rpc_listner (xlator_t *this, * @FIXME: cleanup this bugger once server filters events. */ void -gf_changelog_invoke_callback (gf_changelog_t *entry, - struct iovec **vec, int payloadcnt) +gf_changelog_invoke_callback(gf_changelog_t *entry, struct iovec **vec, + int payloadcnt) { - int i = 0; - int evsize = 0; - xlator_t *this = NULL; - changelog_event_t *event = NULL; - - this = entry->this; - - for (; i < payloadcnt; i++) { - event = (changelog_event_t *)vec[i]->iov_base; - evsize = vec[i]->iov_len / CHANGELOG_EV_SIZE; - - for (; evsize > 0; evsize--, event++) { - if (gf_changelog_filter_check (entry, event)) { - GF_CHANGELOG_INVOKE_CBK (this, - entry->callback, - entry->brick, - entry->ptr, event); - } - } + int i = 0; + int evsize = 0; + xlator_t *this = NULL; + changelog_event_t *event = NULL; + + this = entry->this; + + for (; i < payloadcnt; i++) { + event = (changelog_event_t *)vec[i]->iov_base; + evsize = vec[i]->iov_len / CHANGELOG_EV_SIZE; + + for (; evsize > 0; evsize--, event++) { + if (gf_changelog_filter_check(entry, event)) { + GF_CHANGELOG_INVOKE_CBK(this, entry->callback, entry->brick, + entry->ptr, event); + } } + } } /** @@ -197,218 +178,218 @@ gf_changelog_invoke_callback (gf_changelog_t *entry, */ int -__is_expected_sequence (struct gf_event_list *ev, struct gf_event *event) +__is_expected_sequence(struct gf_event_list *ev, struct gf_event *event) { - return (ev->next_seq == event->seq); + return (ev->next_seq == event->seq); } int -__can_process_event (struct gf_event_list *ev, struct gf_event **event) +__can_process_event(struct gf_event_list *ev, struct gf_event **event) { - *event = list_first_entry (&ev->events, struct gf_event, list); + *event = list_first_entry(&ev->events, struct gf_event, list); - if (__is_expected_sequence (ev, *event)) { - list_del (&(*event)->list); - ev->next_seq++; - return 1; - } + if (__is_expected_sequence(ev, *event)) { + list_del(&(*event)->list); + ev->next_seq++; + return 1; + } - return 0; + return 0; } void -pick_event_ordered (struct gf_event_list *ev, struct gf_event **event) +pick_event_ordered(struct gf_event_list *ev, struct gf_event **event) { - pthread_mutex_lock (&ev->lock); - { - while (list_empty (&ev->events) - || !__can_process_event (ev, event)) - pthread_cond_wait (&ev->cond, &ev->lock); - } - pthread_mutex_unlock (&ev->lock); + pthread_mutex_lock(&ev->lock); + { + while (list_empty(&ev->events) || !__can_process_event(ev, event)) + pthread_cond_wait(&ev->cond, &ev->lock); + } + pthread_mutex_unlock(&ev->lock); } void -pick_event_unordered (struct gf_event_list *ev, struct gf_event **event) +pick_event_unordered(struct gf_event_list *ev, struct gf_event **event) { - pthread_mutex_lock (&ev->lock); - { - while (list_empty (&ev->events)) - pthread_cond_wait (&ev->cond, &ev->lock); - *event = list_first_entry (&ev->events, struct gf_event, list); - list_del (&(*event)->list); - } - pthread_mutex_unlock (&ev->lock); + pthread_mutex_lock(&ev->lock); + { + while (list_empty(&ev->events)) + pthread_cond_wait(&ev->cond, &ev->lock); + *event = list_first_entry(&ev->events, struct gf_event, list); + list_del(&(*event)->list); + } + pthread_mutex_unlock(&ev->lock); } void * -gf_changelog_callback_invoker (void *arg) +gf_changelog_callback_invoker(void *arg) { - xlator_t *this = NULL; - gf_changelog_t *entry = NULL; - struct iovec *vec = NULL; - struct gf_event *event = NULL; - struct gf_event_list *ev = NULL; + xlator_t *this = NULL; + gf_changelog_t *entry = NULL; + struct iovec *vec = NULL; + struct gf_event *event = NULL; + struct gf_event_list *ev = NULL; - ev = arg; - entry = ev->entry; - THIS = this = entry->this; + ev = arg; + entry = ev->entry; + THIS = this = entry->this; - while (1) { - entry->pickevent (ev, &event); + while (1) { + entry->pickevent(ev, &event); - vec = (struct iovec *) &event->iov; - gf_changelog_invoke_callback (entry, &vec, event->count); + vec = (struct iovec *)&event->iov; + gf_changelog_invoke_callback(entry, &vec, event->count); - GF_FREE (event); - } + GF_FREE(event); + } - return NULL; + return NULL; } static int -orderfn (struct list_head *pos1, struct list_head *pos2) +orderfn(struct list_head *pos1, struct list_head *pos2) { - struct gf_event *event1 = NULL; - struct gf_event *event2 = NULL; + struct gf_event *event1 = NULL; + struct gf_event *event2 = NULL; - event1 = list_entry (pos1, struct gf_event, list); - event2 = list_entry (pos2, struct gf_event, list); + event1 = list_entry(pos1, struct gf_event, list); + event2 = list_entry(pos2, struct gf_event, list); - if (event1->seq > event2->seq) - return 1; - return -1; + if (event1->seq > event2->seq) + return 1; + return -1; } void -queue_ordered_event (struct gf_event_list *ev, struct gf_event *event) +queue_ordered_event(struct gf_event_list *ev, struct gf_event *event) { - /* add event to the ordered event list and wake up listener(s) */ - pthread_mutex_lock (&ev->lock); - { - list_add_order (&event->list, &ev->events, orderfn); - if (!ev->next_seq) - ev->next_seq = event->seq; - if (ev->next_seq == event->seq) - pthread_cond_signal (&ev->cond); - } - pthread_mutex_unlock (&ev->lock); + /* add event to the ordered event list and wake up listener(s) */ + pthread_mutex_lock(&ev->lock); + { + list_add_order(&event->list, &ev->events, orderfn); + if (!ev->next_seq) + ev->next_seq = event->seq; + if (ev->next_seq == event->seq) + pthread_cond_signal(&ev->cond); + } + pthread_mutex_unlock(&ev->lock); } void -queue_unordered_event (struct gf_event_list *ev, struct gf_event *event) +queue_unordered_event(struct gf_event_list *ev, struct gf_event *event) { - /* add event to the tail of the queue and wake up listener(s) */ - pthread_mutex_lock (&ev->lock); - { - list_add_tail (&event->list, &ev->events); - pthread_cond_signal (&ev->cond); - } - pthread_mutex_unlock (&ev->lock); + /* add event to the tail of the queue and wake up listener(s) */ + pthread_mutex_lock(&ev->lock); + { + list_add_tail(&event->list, &ev->events); + pthread_cond_signal(&ev->cond); + } + pthread_mutex_unlock(&ev->lock); } int -gf_changelog_event_handler (rpcsvc_request_t *req, - xlator_t *this, gf_changelog_t *entry) +gf_changelog_event_handler(rpcsvc_request_t *req, xlator_t *this, + gf_changelog_t *entry) { - int i = 0; - size_t payloadlen = 0; - ssize_t len = 0; - int payloadcnt = 0; - changelog_event_req rpc_req = {0,}; - changelog_event_rsp rpc_rsp = {0,}; - struct iovec *vec = NULL; - struct gf_event *event = NULL; - struct gf_event_list *ev = NULL; - - ev = &entry->event; - - len = xdr_to_generic (req->msg[0], - &rpc_req, (xdrproc_t)xdr_changelog_event_req); - if (len < 0) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_XDR_DECODING_FAILED, - "xdr decoding failed"); - req->rpc_err = GARBAGE_ARGS; - goto handle_xdr_error; - } - - if (len < req->msg[0].iov_len) { - payloadcnt = 1; - payloadlen = (req->msg[0].iov_len - len); - } - for (i = 1; i < req->count; i++) { - payloadcnt++; - payloadlen += req->msg[i].iov_len; - } - - event = GF_CALLOC (1, GF_EVENT_CALLOC_SIZE (payloadcnt, payloadlen), - gf_changelog_mt_libgfchangelog_event_t); - if (!event) - goto handle_xdr_error; - INIT_LIST_HEAD (&event->list); - - payloadlen = 0; - event->seq = rpc_req.seq; - event->count = payloadcnt; - - /* deep copy IO vectors */ - vec = &event->iov[0]; - GF_EVENT_ASSIGN_IOVEC (vec, event, - (req->msg[0].iov_len - len), payloadlen); - (void) memcpy (vec->iov_base, - req->msg[0].iov_base + len, vec->iov_len); - - for (i = 1; i < req->count; i++) { - vec = &event->iov[i]; - GF_EVENT_ASSIGN_IOVEC (vec, event, - req->msg[i].iov_len, payloadlen); - (void) memcpy (event->iov[i].iov_base, - req->msg[i].iov_base, req->msg[i].iov_len); - } - - gf_msg_debug (this->name, 0, - "seq: %lu [%s] (time: %lu.%lu), (vec: %d, len: %zd)", - rpc_req.seq, entry->brick, rpc_req.tv_sec, - rpc_req.tv_usec, payloadcnt, payloadlen); - - /* dispatch event */ - entry->queueevent (ev, event); - - /* ack sequence number */ - rpc_rsp.op_ret = 0; - rpc_rsp.seq = rpc_req.seq; - - goto submit_rpc; - - handle_xdr_error: - rpc_rsp.op_ret = -1; - rpc_rsp.seq = 0; /* invalid */ - submit_rpc: - return changelog_rpc_sumbit_reply (req, &rpc_rsp, NULL, 0, NULL, - (xdrproc_t)xdr_changelog_event_rsp); + int i = 0; + size_t payloadlen = 0; + ssize_t len = 0; + int payloadcnt = 0; + changelog_event_req rpc_req = { + 0, + }; + changelog_event_rsp rpc_rsp = { + 0, + }; + struct iovec *vec = NULL; + struct gf_event *event = NULL; + struct gf_event_list *ev = NULL; + + ev = &entry->event; + + len = xdr_to_generic(req->msg[0], &rpc_req, + (xdrproc_t)xdr_changelog_event_req); + if (len < 0) { + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_LIB_MSG_XDR_DECODING_FAILED, "xdr decoding failed"); + req->rpc_err = GARBAGE_ARGS; + goto handle_xdr_error; + } + + if (len < req->msg[0].iov_len) { + payloadcnt = 1; + payloadlen = (req->msg[0].iov_len - len); + } + for (i = 1; i < req->count; i++) { + payloadcnt++; + payloadlen += req->msg[i].iov_len; + } + + event = GF_CALLOC(1, GF_EVENT_CALLOC_SIZE(payloadcnt, payloadlen), + gf_changelog_mt_libgfchangelog_event_t); + if (!event) + goto handle_xdr_error; + INIT_LIST_HEAD(&event->list); + + payloadlen = 0; + event->seq = rpc_req.seq; + event->count = payloadcnt; + + /* deep copy IO vectors */ + vec = &event->iov[0]; + GF_EVENT_ASSIGN_IOVEC(vec, event, (req->msg[0].iov_len - len), payloadlen); + (void)memcpy(vec->iov_base, req->msg[0].iov_base + len, vec->iov_len); + + for (i = 1; i < req->count; i++) { + vec = &event->iov[i]; + GF_EVENT_ASSIGN_IOVEC(vec, event, req->msg[i].iov_len, payloadlen); + (void)memcpy(event->iov[i].iov_base, req->msg[i].iov_base, + req->msg[i].iov_len); + } + + gf_msg_debug(this->name, 0, + "seq: %" PRIu64 " [%s] (time: %" PRIu64 ".%" PRIu64 + "), " + "(vec: %d, len: %zd)", + rpc_req.seq, entry->brick, rpc_req.tv_sec, rpc_req.tv_usec, + payloadcnt, payloadlen); + + /* dispatch event */ + entry->queueevent(ev, event); + + /* ack sequence number */ + rpc_rsp.op_ret = 0; + rpc_rsp.seq = rpc_req.seq; + + goto submit_rpc; + +handle_xdr_error: + rpc_rsp.op_ret = -1; + rpc_rsp.seq = 0; /* invalid */ +submit_rpc: + return changelog_rpc_sumbit_reply(req, &rpc_rsp, NULL, 0, NULL, + (xdrproc_t)xdr_changelog_event_rsp); } int -gf_changelog_reborp_handle_event (rpcsvc_request_t *req) +gf_changelog_reborp_handle_event(rpcsvc_request_t *req) { - xlator_t *this = NULL; - rpcsvc_t *svc = NULL; - gf_changelog_t *entry = NULL; + xlator_t *this = NULL; + rpcsvc_t *svc = NULL; + gf_changelog_t *entry = NULL; - svc = rpcsvc_request_service (req); - entry = svc->mydata; + svc = rpcsvc_request_service(req); + entry = svc->mydata; - this = THIS = entry->this; + this = THIS = entry->this; - return gf_changelog_event_handler (req, this, entry); + return gf_changelog_event_handler(req, this, entry); } -rpcsvc_actor_t gf_changelog_reborp_actors[CHANGELOG_REV_PROC_MAX] = { - [CHANGELOG_REV_PROC_EVENT] = { - "CHANGELOG EVENT HANDLER", CHANGELOG_REV_PROC_EVENT, - gf_changelog_reborp_handle_event, NULL, 0, DRC_NA - }, +static rpcsvc_actor_t gf_changelog_reborp_actors[CHANGELOG_REV_PROC_MAX] = { + [CHANGELOG_REV_PROC_EVENT] = {"CHANGELOG EVENT HANDLER", + gf_changelog_reborp_handle_event, NULL, + CHANGELOG_REV_PROC_EVENT, DRC_NA, 0}, }; /** @@ -417,16 +398,16 @@ rpcsvc_actor_t gf_changelog_reborp_actors[CHANGELOG_REV_PROC_MAX] = { * and that's required to invoke the callback with the appropriate * brick path and it's private data. */ -struct rpcsvc_program gf_changelog_reborp_prog = { - .progname = "LIBGFCHANGELOG REBORP", - .prognum = CHANGELOG_REV_RPC_PROCNUM, - .progver = CHANGELOG_REV_RPC_PROCVER, - .numactors = CHANGELOG_REV_PROC_MAX, - .actors = gf_changelog_reborp_actors, - .synctask = _gf_false, +static struct rpcsvc_program gf_changelog_reborp_prog = { + .progname = "LIBGFCHANGELOG REBORP", + .prognum = CHANGELOG_REV_RPC_PROCNUM, + .progver = CHANGELOG_REV_RPC_PROCVER, + .numactors = CHANGELOG_REV_PROC_MAX, + .actors = gf_changelog_reborp_actors, + .synctask = _gf_false, }; -struct rpcsvc_program *gf_changelog_reborp_programs[] = { - &gf_changelog_reborp_prog, - NULL, +static struct rpcsvc_program *gf_changelog_reborp_programs[] = { + &gf_changelog_reborp_prog, + NULL, }; diff --git a/xlators/features/changelog/lib/src/gf-changelog-rpc.c b/xlators/features/changelog/lib/src/gf-changelog-rpc.c index 7eb5416ae98..8ec6ffbcebc 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-rpc.c +++ b/xlators/features/changelog/lib/src/gf-changelog-rpc.c @@ -16,31 +16,32 @@ struct rpc_clnt_program gf_changelog_clnt; /* TODO: piggyback reconnect to called (upcall) */ int -gf_changelog_rpc_notify (struct rpc_clnt *rpc, - void *mydata, rpc_clnt_event_t event, void *data) +gf_changelog_rpc_notify(struct rpc_clnt *rpc, void *mydata, + rpc_clnt_event_t event, void *data) { - switch (event) { + switch (event) { case RPC_CLNT_CONNECT: - break; + break; case RPC_CLNT_DISCONNECT: case RPC_CLNT_MSG: case RPC_CLNT_DESTROY: case RPC_CLNT_PING: - break; - } + break; + } - return 0; + return 0; } struct rpc_clnt * -gf_changelog_rpc_init (xlator_t *this, gf_changelog_t *entry) +gf_changelog_rpc_init(xlator_t *this, gf_changelog_t *entry) { - char sockfile[UNIX_PATH_MAX] = {0,}; + char sockfile[UNIX_PATH_MAX] = { + 0, + }; - CHANGELOG_MAKE_SOCKET_PATH (entry->brick, - sockfile, UNIX_PATH_MAX); - return changelog_rpc_client_init (this, entry, - sockfile, gf_changelog_rpc_notify); + CHANGELOG_MAKE_SOCKET_PATH(entry->brick, sockfile, UNIX_PATH_MAX); + return changelog_rpc_client_init(this, entry, sockfile, + gf_changelog_rpc_notify); } /** @@ -48,51 +49,50 @@ gf_changelog_rpc_init (xlator_t *this, gf_changelog_t *entry) */ int -gf_probe_changelog_cbk (struct rpc_req *req, - struct iovec *iovec, int count, void *myframe) +gf_probe_changelog_cbk(struct rpc_req *req, struct iovec *iovec, int count, + void *myframe) { - return 0; + return 0; } int -gf_probe_changelog_filter (call_frame_t *frame, xlator_t *this, void *data) +gf_probe_changelog_filter(call_frame_t *frame, xlator_t *this, void *data) { - char *sock = NULL; - gf_changelog_t *entry = NULL; - changelog_probe_req req = {0,}; - - entry = data; - sock = RPC_SOCK (entry); - - (void) memcpy (&req.sock, sock, strlen (sock)); - req.filter = entry->notify; - - /* invoke RPC */ - return changelog_rpc_sumbit_req (RPC_PROBER (entry), (void *) &req, - frame, &gf_changelog_clnt, - CHANGELOG_RPC_PROBE_FILTER, NULL, 0, - NULL, this, gf_probe_changelog_cbk, - (xdrproc_t) xdr_changelog_probe_req); + char *sock = NULL; + gf_changelog_t *entry = NULL; + changelog_probe_req req = { + 0, + }; + + entry = data; + sock = RPC_SOCK(entry); + + (void)memcpy(&req.sock, sock, strlen(sock)); + req.filter = entry->notify; + + /* invoke RPC */ + return changelog_rpc_sumbit_req( + RPC_PROBER(entry), (void *)&req, frame, &gf_changelog_clnt, + CHANGELOG_RPC_PROBE_FILTER, NULL, 0, NULL, this, gf_probe_changelog_cbk, + (xdrproc_t)xdr_changelog_probe_req); } int -gf_changelog_invoke_rpc (xlator_t *this, gf_changelog_t *entry, int procidx) +gf_changelog_invoke_rpc(xlator_t *this, gf_changelog_t *entry, int procidx) { - return changelog_invoke_rpc (this, RPC_PROBER (entry), - &gf_changelog_clnt, procidx, entry); + return changelog_invoke_rpc(this, RPC_PROBER(entry), &gf_changelog_clnt, + procidx, entry); } struct rpc_clnt_procedure gf_changelog_procs[CHANGELOG_RPC_PROC_MAX] = { - [CHANGELOG_RPC_PROC_NULL] = {"NULL", NULL}, - [CHANGELOG_RPC_PROBE_FILTER] = { - "PROBE FILTER", gf_probe_changelog_filter - }, + [CHANGELOG_RPC_PROC_NULL] = {"NULL", NULL}, + [CHANGELOG_RPC_PROBE_FILTER] = {"PROBE FILTER", gf_probe_changelog_filter}, }; struct rpc_clnt_program gf_changelog_clnt = { - .progname = "LIBGFCHANGELOG", - .prognum = CHANGELOG_RPC_PROGNUM, - .progver = CHANGELOG_RPC_PROGVER, - .numproc = CHANGELOG_RPC_PROC_MAX, - .proctable = gf_changelog_procs, + .progname = "LIBGFCHANGELOG", + .prognum = CHANGELOG_RPC_PROGNUM, + .progver = CHANGELOG_RPC_PROGVER, + .numproc = CHANGELOG_RPC_PROC_MAX, + .proctable = gf_changelog_procs, }; diff --git a/xlators/features/changelog/lib/src/gf-changelog-rpc.h b/xlators/features/changelog/lib/src/gf-changelog-rpc.h index 1c982eef809..5c82d6f1c08 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-rpc.h +++ b/xlators/features/changelog/lib/src/gf-changelog-rpc.h @@ -11,16 +11,18 @@ #ifndef __GF_CHANGELOG_RPC_H #define __GF_CHANGELOG_RPC_H -#include "xlator.h" +#include <glusterfs/xlator.h> #include "gf-changelog-helpers.h" #include "changelog-rpc-common.h" -struct rpc_clnt *gf_changelog_rpc_init (xlator_t *, gf_changelog_t *); +struct rpc_clnt * +gf_changelog_rpc_init(xlator_t *, gf_changelog_t *); -int gf_changelog_invoke_rpc (xlator_t *, gf_changelog_t *, int); +int +gf_changelog_invoke_rpc(xlator_t *, gf_changelog_t *, int); rpcsvc_t * -gf_changelog_reborp_init_rpc_listner (xlator_t *, char *, char *, void *); +gf_changelog_reborp_init_rpc_listner(xlator_t *, char *, char *, void *); #endif diff --git a/xlators/features/changelog/lib/src/gf-changelog.c b/xlators/features/changelog/lib/src/gf-changelog.c index 6ad6c63740d..57c3d39ef76 100644 --- a/xlators/features/changelog/lib/src/gf-changelog.c +++ b/xlators/features/changelog/lib/src/gf-changelog.c @@ -22,11 +22,11 @@ #endif #include <string.h> -#include "globals.h" -#include "glusterfs.h" -#include "logging.h" -#include "defaults.h" -#include "syncop.h" +#include <glusterfs/globals.h> +#include <glusterfs/glusterfs.h> +#include <glusterfs/logging.h> +#include <glusterfs/defaults.h> +#include <glusterfs/syncop.h> #include "gf-changelog-rpc.h" #include "gf-changelog-helpers.h" @@ -45,291 +45,315 @@ */ xlator_t *master = NULL; -static inline -gf_private_t *gf_changelog_alloc_priv () +static inline gf_private_t * +gf_changelog_alloc_priv() { - int ret = 0; - gf_private_t *priv = NULL; - - priv = GF_CALLOC (1, sizeof (*priv), gf_changelog_mt_priv_t); - if (!priv) - goto error_return; - INIT_LIST_HEAD (&priv->connections); - INIT_LIST_HEAD (&priv->cleanups); - - ret = pthread_mutex_init (&priv->lock, NULL); - if (ret != 0) - goto free_priv; - ret = pthread_cond_init (&priv->cond, NULL); - if (ret != 0) - goto cleanup_mutex; - - priv->api = NULL; - return priv; - - cleanup_mutex: - (void) pthread_mutex_destroy (&priv->lock); - free_priv: - GF_FREE (priv); - error_return: - return NULL; + int ret = 0; + gf_private_t *priv = NULL; + + priv = GF_CALLOC(1, sizeof(*priv), gf_changelog_mt_priv_t); + if (!priv) + goto error_return; + INIT_LIST_HEAD(&priv->connections); + INIT_LIST_HEAD(&priv->cleanups); + + ret = pthread_mutex_init(&priv->lock, NULL); + if (ret != 0) + goto free_priv; + ret = pthread_cond_init(&priv->cond, NULL); + if (ret != 0) + goto cleanup_mutex; + + priv->api = NULL; + return priv; + +cleanup_mutex: + (void)pthread_mutex_destroy(&priv->lock); +free_priv: + GF_FREE(priv); +error_return: + return NULL; } -#define GF_CHANGELOG_EVENT_POOL_SIZE 16384 +#define GF_CHANGELOG_EVENT_POOL_SIZE 16384 #define GF_CHANGELOG_EVENT_THREAD_COUNT 4 static int -gf_changelog_ctx_defaults_init (glusterfs_ctx_t *ctx) +gf_changelog_ctx_defaults_init(glusterfs_ctx_t *ctx) { - cmd_args_t *cmd_args = NULL; - struct rlimit lim = {0, }; - call_pool_t *pool = NULL; - int ret = -1; + cmd_args_t *cmd_args = NULL; + struct rlimit lim = { + 0, + }; + call_pool_t *pool = NULL; + int ret = -1; + + ret = xlator_mem_acct_init(THIS, gf_changelog_mt_end); + if (ret != 0) + return -1; - ret = xlator_mem_acct_init (THIS, gf_changelog_mt_end); - if (ret != 0) - return -1; + ctx->process_uuid = generate_glusterfs_ctx_id(); + if (!ctx->process_uuid) + return -1; - ctx->process_uuid = generate_glusterfs_ctx_id (); - if (!ctx->process_uuid) - return -1; + ctx->page_size = 128 * GF_UNIT_KB; - ctx->page_size = 128 * GF_UNIT_KB; + ctx->iobuf_pool = iobuf_pool_new(); + if (!ctx->iobuf_pool) + goto free_pool; - ctx->iobuf_pool = iobuf_pool_new (); - if (!ctx->iobuf_pool) - return -1; + ctx->event_pool = gf_event_pool_new(GF_CHANGELOG_EVENT_POOL_SIZE, + GF_CHANGELOG_EVENT_THREAD_COUNT); + if (!ctx->event_pool) + goto free_pool; - ctx->event_pool = event_pool_new (GF_CHANGELOG_EVENT_POOL_SIZE, - GF_CHANGELOG_EVENT_THREAD_COUNT); - if (!ctx->event_pool) - return -1; + pool = GF_CALLOC(1, sizeof(call_pool_t), + gf_changelog_mt_libgfchangelog_call_pool_t); + if (!pool) + goto free_pool; - pool = GF_CALLOC (1, sizeof (call_pool_t), - gf_changelog_mt_libgfchangelog_call_pool_t); - if (!pool) - return -1; + /* frame_mem_pool size 112 * 64 */ + pool->frame_mem_pool = mem_pool_new(call_frame_t, 32); + if (!pool->frame_mem_pool) + goto free_pool; - /* frame_mem_pool size 112 * 64 */ - pool->frame_mem_pool = mem_pool_new (call_frame_t, 32); - if (!pool->frame_mem_pool) - return -1; + /* stack_mem_pool size 256 * 128 */ + pool->stack_mem_pool = mem_pool_new(call_stack_t, 16); - /* stack_mem_pool size 256 * 128 */ - pool->stack_mem_pool = mem_pool_new (call_stack_t, 16); + if (!pool->stack_mem_pool) + goto free_pool; - if (!pool->stack_mem_pool) - return -1; + ctx->stub_mem_pool = mem_pool_new(call_stub_t, 16); + if (!ctx->stub_mem_pool) + goto free_pool; - ctx->stub_mem_pool = mem_pool_new (call_stub_t, 16); - if (!ctx->stub_mem_pool) - return -1; + ctx->dict_pool = mem_pool_new(dict_t, 32); + if (!ctx->dict_pool) + goto free_pool; - ctx->dict_pool = mem_pool_new (dict_t, 32); - if (!ctx->dict_pool) - return -1; + ctx->dict_pair_pool = mem_pool_new(data_pair_t, 512); + if (!ctx->dict_pair_pool) + goto free_pool; - ctx->dict_pair_pool = mem_pool_new (data_pair_t, 512); - if (!ctx->dict_pair_pool) - return -1; + ctx->dict_data_pool = mem_pool_new(data_t, 512); + if (!ctx->dict_data_pool) + goto free_pool; - ctx->dict_data_pool = mem_pool_new (data_t, 512); - if (!ctx->dict_data_pool) - return -1; + ctx->logbuf_pool = mem_pool_new(log_buf_t, 256); + if (!ctx->logbuf_pool) + goto free_pool; - ctx->logbuf_pool = mem_pool_new (log_buf_t, 256); - if (!ctx->logbuf_pool) - return -1; + INIT_LIST_HEAD(&pool->all_frames); + LOCK_INIT(&pool->lock); + ctx->pool = pool; - INIT_LIST_HEAD (&pool->all_frames); - LOCK_INIT (&pool->lock); - ctx->pool = pool; + LOCK_INIT(&ctx->lock); - LOCK_INIT (&ctx->lock); + cmd_args = &ctx->cmd_args; - cmd_args = &ctx->cmd_args; + INIT_LIST_HEAD(&cmd_args->xlator_options); - INIT_LIST_HEAD (&cmd_args->xlator_options); + lim.rlim_cur = RLIM_INFINITY; + lim.rlim_max = RLIM_INFINITY; + setrlimit(RLIMIT_CORE, &lim); - lim.rlim_cur = RLIM_INFINITY; - lim.rlim_max = RLIM_INFINITY; - setrlimit (RLIMIT_CORE, &lim); + return 0; - return 0; +free_pool: + if (pool) { + GF_FREE(pool->frame_mem_pool); + + GF_FREE(pool->stack_mem_pool); + + GF_FREE(pool); + } + + GF_FREE(ctx->stub_mem_pool); + + GF_FREE(ctx->dict_pool); + + GF_FREE(ctx->dict_pair_pool); + + GF_FREE(ctx->dict_data_pool); + + GF_FREE(ctx->logbuf_pool); + + GF_FREE(ctx->iobuf_pool); + + GF_FREE(ctx->event_pool); + + return -1; } /* TODO: cleanup ctx defaults */ void -gf_changelog_cleanup_this (xlator_t *this) +gf_changelog_cleanup_this(xlator_t *this) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - if (!this) - return; + if (!this) + return; - ctx = this->ctx; - syncenv_destroy (ctx->env); - free (ctx); + ctx = this->ctx; + syncenv_destroy(ctx->env); + free(ctx); - this->private = NULL; - this->ctx = NULL; + this->private = NULL; + this->ctx = NULL; - mem_pools_fini (); + mem_pools_fini(); } static int -gf_changelog_init_context () +gf_changelog_init_context() { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = glusterfs_ctx_new (); - if (!ctx) - goto error_return; + ctx = glusterfs_ctx_new(); + if (!ctx) + goto error_return; - if (glusterfs_globals_init (ctx)) - goto free_ctx; + if (glusterfs_globals_init(ctx)) + goto free_ctx; - THIS->ctx = ctx; - if (gf_changelog_ctx_defaults_init (ctx)) - goto free_ctx; + THIS->ctx = ctx; + if (gf_changelog_ctx_defaults_init(ctx)) + goto free_ctx; - ctx->env = syncenv_new (0, 0, 0); - if (!ctx->env) - goto free_ctx; - return 0; + ctx->env = syncenv_new(0, 0, 0); + if (!ctx->env) + goto free_ctx; + return 0; - free_ctx: - free (ctx); - THIS->ctx = NULL; - error_return: - return -1; +free_ctx: + free(ctx); + THIS->ctx = NULL; +error_return: + return -1; } static int -gf_changelog_init_master () +gf_changelog_init_master() { - int ret = 0; + int ret = 0; - mem_pools_init_early (); - ret = gf_changelog_init_context (); - mem_pools_init_late (); + ret = gf_changelog_init_context(); + mem_pools_init(); - return ret; + return ret; } /* TODO: cleanup clnt/svc on failure */ int -gf_changelog_setup_rpc (xlator_t *this, - gf_changelog_t *entry, int proc) +gf_changelog_setup_rpc(xlator_t *this, gf_changelog_t *entry, int proc) { - int ret = 0; - rpcsvc_t *svc = NULL; - struct rpc_clnt *rpc = NULL; - - /** - * Initialize a connect back socket. A probe() RPC call to the server - * triggers a reverse connect. - */ - svc = gf_changelog_reborp_init_rpc_listner (this, entry->brick, - RPC_SOCK (entry), entry); - if (!svc) - goto error_return; - RPC_REBORP (entry) = svc; - - /* Initialize an RPC client */ - rpc = gf_changelog_rpc_init (this, entry); - if (!rpc) - goto error_return; - RPC_PROBER (entry) = rpc; - - /** - * @FIXME - * till we have connection state machine, let's delay the RPC call - * for now.. - */ - sleep (2); - - /** - * Probe changelog translator for reverse connection. After a successful - * call, there's less use of the client and can be disconnected, but - * let's leave the connection active for any future RPC calls. - */ - ret = gf_changelog_invoke_rpc (this, entry, proc); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_INVOKE_RPC_FAILED, - "Could not initiate probe RPC, bailing out!!!"); - goto error_return; - } - - return 0; - - error_return: - return -1; + int ret = 0; + rpcsvc_t *svc = NULL; + struct rpc_clnt *rpc = NULL; + + /** + * Initialize a connect back socket. A probe() RPC call to the server + * triggers a reverse connect. + */ + svc = gf_changelog_reborp_init_rpc_listner(this, entry->brick, + RPC_SOCK(entry), entry); + if (!svc) + goto error_return; + RPC_REBORP(entry) = svc; + + /* Initialize an RPC client */ + rpc = gf_changelog_rpc_init(this, entry); + if (!rpc) + goto error_return; + RPC_PROBER(entry) = rpc; + + /** + * @FIXME + * till we have connection state machine, let's delay the RPC call + * for now.. + */ + sleep(2); + + /** + * Probe changelog translator for reverse connection. After a successful + * call, there's less use of the client and can be disconnected, but + * let's leave the connection active for any future RPC calls. + */ + ret = gf_changelog_invoke_rpc(this, entry, proc); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_INVOKE_RPC_FAILED, + "Could not initiate probe RPC, bailing out!!!"); + goto error_return; + } + + return 0; + +error_return: + return -1; } int -gf_cleanup_event (xlator_t *this, struct gf_event_list *ev) +gf_cleanup_event(xlator_t *this, struct gf_event_list *ev) { - int ret = 0; - - ret = gf_thread_cleanup (this, ev->invoker); - if (ret) { - gf_msg (this->name, GF_LOG_WARNING, -ret, - CHANGELOG_LIB_MSG_CLEANUP_ERROR, - "cannot cleanup callback invoker thread." - " Not freeing resources"); - return -1; - } + int ret = 0; + + ret = gf_thread_cleanup(this, ev->invoker); + if (ret) { + gf_msg(this->name, GF_LOG_WARNING, -ret, + CHANGELOG_LIB_MSG_CLEANUP_ERROR, + "cannot cleanup callback invoker thread." + " Not freeing resources"); + return -1; + } - ev->entry = NULL; + ev->entry = NULL; - return 0; + return 0; } static int -gf_init_event (gf_changelog_t *entry) +gf_init_event(gf_changelog_t *entry) { - int ret = 0; - struct gf_event_list *ev = NULL; - - ev = &entry->event; - ev->entry = entry; - - ret = pthread_mutex_init (&ev->lock, NULL); - if (ret != 0) - goto error_return; - ret = pthread_cond_init (&ev->cond, NULL); - if (ret != 0) - goto cleanup_mutex; - INIT_LIST_HEAD (&ev->events); - - ev->next_seq = 0; /* bootstrap sequencing */ - - if (GF_NEED_ORDERED_EVENTS (entry)) { - entry->pickevent = pick_event_ordered; - entry->queueevent = queue_ordered_event; - } else { - entry->pickevent = pick_event_unordered; - entry->queueevent = queue_unordered_event; - } - - ret = gf_thread_create (&ev->invoker, NULL, - gf_changelog_callback_invoker, ev, "clogcbki"); - if (ret != 0) { - entry->pickevent = NULL; - entry->queueevent = NULL; - goto cleanup_cond; - } - - return 0; - - cleanup_cond: - (void) pthread_cond_destroy (&ev->cond); - cleanup_mutex: - (void) pthread_mutex_destroy (&ev->lock); - error_return: - return -1; + int ret = 0; + struct gf_event_list *ev = NULL; + + ev = &entry->event; + ev->entry = entry; + + ret = pthread_mutex_init(&ev->lock, NULL); + if (ret != 0) + goto error_return; + ret = pthread_cond_init(&ev->cond, NULL); + if (ret != 0) + goto cleanup_mutex; + INIT_LIST_HEAD(&ev->events); + + ev->next_seq = 0; /* bootstrap sequencing */ + + if (GF_NEED_ORDERED_EVENTS(entry)) { + entry->pickevent = pick_event_ordered; + entry->queueevent = queue_ordered_event; + } else { + entry->pickevent = pick_event_unordered; + entry->queueevent = queue_unordered_event; + } + + ret = gf_thread_create(&ev->invoker, NULL, gf_changelog_callback_invoker, + ev, "clogcbki"); + if (ret != 0) { + entry->pickevent = NULL; + entry->queueevent = NULL; + goto cleanup_cond; + } + + return 0; + +cleanup_cond: + (void)pthread_cond_destroy(&ev->cond); +cleanup_mutex: + (void)pthread_mutex_destroy(&ev->lock); +error_return: + return -1; } /** @@ -339,250 +363,241 @@ gf_init_event (gf_changelog_t *entry) * - destroy rpc{-clnt, svc} */ int -gf_cleanup_brick_connection (xlator_t *this, gf_changelog_t *entry) +gf_cleanup_brick_connection(xlator_t *this, gf_changelog_t *entry) { - return 0; + return 0; } int -gf_cleanup_connections (xlator_t *this) +gf_cleanup_connections(xlator_t *this) { - return 0; + return 0; } static int -gf_setup_brick_connection (xlator_t *this, - struct gf_brick_spec *brick, - gf_boolean_t ordered, void *xl) +gf_setup_brick_connection(xlator_t *this, struct gf_brick_spec *brick, + gf_boolean_t ordered, void *xl) { - int ret = 0; - gf_private_t *priv = NULL; - gf_changelog_t *entry = NULL; - - priv = this->private; - - if (!brick->callback || !brick->init || !brick->fini) - goto error_return; - - entry = GF_CALLOC (1, sizeof (*entry), - gf_changelog_mt_libgfchangelog_t); - if (!entry) - goto error_return; - INIT_LIST_HEAD (&entry->list); - - LOCK_INIT (&entry->statelock); - entry->connstate = GF_CHANGELOG_CONN_STATE_PENDING; - - entry->notify = brick->filter; - (void) strncpy (entry->brick, brick->brick_path, PATH_MAX-1); - entry->brick[PATH_MAX-1] = 0; - - entry->this = this; - entry->invokerxl = xl; - - entry->ordered = ordered; - ret = gf_init_event (entry); - if (ret) - goto free_entry; - - entry->fini = brick->fini; - entry->callback = brick->callback; - entry->connected = brick->connected; - entry->disconnected = brick->disconnected; - - entry->ptr = brick->init (this, brick); - if (!entry->ptr) - goto cleanup_event; - priv->api = entry->ptr; /* pointer to API, if required */ - - pthread_mutex_lock (&priv->lock); - { - list_add_tail (&entry->list, &priv->connections); - } - pthread_mutex_unlock (&priv->lock); - - ret = gf_changelog_setup_rpc (this, entry, CHANGELOG_RPC_PROBE_FILTER); - if (ret) - goto cleanup_event; - return 0; - - cleanup_event: - (void) gf_cleanup_event (this, &entry->event); - free_entry: - gf_msg_debug (this->name, 0, "freeing entry %p", entry); - list_del (&entry->list); /* FIXME: kludge for now */ - GF_FREE (entry); - error_return: - return -1; + int ret = 0; + gf_private_t *priv = NULL; + gf_changelog_t *entry = NULL; + + priv = this->private; + + if (!brick->callback || !brick->init || !brick->fini) + goto error_return; + + entry = GF_CALLOC(1, sizeof(*entry), gf_changelog_mt_libgfchangelog_t); + if (!entry) + goto error_return; + INIT_LIST_HEAD(&entry->list); + + LOCK_INIT(&entry->statelock); + entry->connstate = GF_CHANGELOG_CONN_STATE_PENDING; + + entry->notify = brick->filter; + if (snprintf(entry->brick, PATH_MAX, "%s", brick->brick_path) >= PATH_MAX) + goto free_entry; + + entry->this = this; + entry->invokerxl = xl; + + entry->ordered = ordered; + ret = gf_init_event(entry); + if (ret) + goto free_entry; + + entry->fini = brick->fini; + entry->callback = brick->callback; + entry->connected = brick->connected; + entry->disconnected = brick->disconnected; + + entry->ptr = brick->init(this, brick); + if (!entry->ptr) + goto cleanup_event; + priv->api = entry->ptr; /* pointer to API, if required */ + + pthread_mutex_lock(&priv->lock); + { + list_add_tail(&entry->list, &priv->connections); + } + pthread_mutex_unlock(&priv->lock); + + ret = gf_changelog_setup_rpc(this, entry, CHANGELOG_RPC_PROBE_FILTER); + if (ret) + goto cleanup_event; + return 0; + +cleanup_event: + (void)gf_cleanup_event(this, &entry->event); +free_entry: + gf_msg_debug(this->name, 0, "freeing entry %p", entry); + list_del(&entry->list); /* FIXME: kludge for now */ + GF_FREE(entry); +error_return: + return -1; } int -gf_changelog_register_brick (xlator_t *this, - struct gf_brick_spec *brick, - gf_boolean_t ordered, void *xl) +gf_changelog_register_brick(xlator_t *this, struct gf_brick_spec *brick, + gf_boolean_t ordered, void *xl) { - return gf_setup_brick_connection (this, brick, ordered, xl); + return gf_setup_brick_connection(this, brick, ordered, xl); } static int -gf_changelog_setup_logging (xlator_t *this, char *logfile, int loglevel) +gf_changelog_setup_logging(xlator_t *this, char *logfile, int loglevel) { - /* passing ident as NULL means to use default ident for syslog */ - if (gf_log_init (this->ctx, logfile, NULL)) - return -1; + /* passing ident as NULL means to use default ident for syslog */ + if (gf_log_init(this->ctx, logfile, NULL)) + return -1; - gf_log_set_loglevel (this->ctx, (loglevel == -1) ? GF_LOG_INFO : - loglevel); - return 0; + gf_log_set_loglevel(this->ctx, (loglevel == -1) ? GF_LOG_INFO : loglevel); + return 0; } static int -gf_changelog_set_master (xlator_t *master, void *xl) +gf_changelog_set_master(xlator_t *master, void *xl) { - int32_t ret = 0; - xlator_t *this = NULL; - xlator_t *old_this = NULL; - gf_private_t *priv = NULL; - - this = xl; - if (!this || !this->ctx) { - ret = gf_changelog_init_master (); - if (ret) - return -1; - this = THIS; - } + int32_t ret = 0; + xlator_t *this = NULL; + xlator_t *old_this = NULL; + gf_private_t *priv = NULL; + + this = xl; + if (!this || !this->ctx) { + ret = gf_changelog_init_master(); + if (ret) + return -1; + this = THIS; + } - master->ctx = this->ctx; + master->ctx = this->ctx; - INIT_LIST_HEAD (&master->volume_options); - SAVE_THIS (THIS); + INIT_LIST_HEAD(&master->volume_options); + SAVE_THIS(THIS); - ret = xlator_mem_acct_init (THIS, gf_changelog_mt_end); - if (ret != 0) - goto restore_this; + ret = xlator_mem_acct_init(THIS, gf_changelog_mt_end); + if (ret != 0) + goto restore_this; - priv = gf_changelog_alloc_priv (); - if (!priv) { - ret = -1; - goto restore_this; - } + priv = gf_changelog_alloc_priv(); + if (!priv) { + ret = -1; + goto restore_this; + } - if (!xl) { - /* poller thread */ - ret = gf_thread_create (&priv->poller, - NULL, changelog_rpc_poller, THIS, - "clogpoll"); - if (ret != 0) { - GF_FREE (priv); - gf_msg (master->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED, - "failed to spawn poller thread"); - goto restore_this; - } + if (!xl) { + /* poller thread */ + ret = gf_thread_create(&priv->poller, NULL, changelog_rpc_poller, THIS, + "clogpoll"); + if (ret != 0) { + GF_FREE(priv); + gf_msg(master->name, GF_LOG_ERROR, 0, + CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED, + "failed to spawn poller thread"); + goto restore_this; } + } - master->private = priv; + master->private = priv; - restore_this: - RESTORE_THIS (); +restore_this: + RESTORE_THIS(); - return ret; + return ret; } int -gf_changelog_init (void *xl) +gf_changelog_init(void *xl) { - int ret = 0; - gf_private_t *priv = NULL; - - if (master) - return 0; - - master = calloc (1, sizeof (*master)); - if (!master) - goto error_return; - - master->name = strdup ("gfchangelog"); - if (!master->name) - goto dealloc_master; - - ret = gf_changelog_set_master (master, xl); - if (ret) - goto dealloc_name; - - priv = master->private; - ret = gf_thread_create (&priv->connectionjanitor, NULL, - gf_changelog_connection_janitor, master, - "clogjan"); - if (ret != 0) { - /* TODO: cleanup priv, mutex (poller thread for !xl) */ - goto dealloc_name; - } + int ret = 0; + gf_private_t *priv = NULL; + if (master) return 0; - dealloc_name: - free (master->name); - dealloc_master: - free (master); - master = NULL; - error_return: - return -1; + master = calloc(1, sizeof(*master)); + if (!master) + goto error_return; + + master->name = strdup("gfchangelog"); + if (!master->name) + goto dealloc_master; + + ret = gf_changelog_set_master(master, xl); + if (ret) + goto dealloc_name; + + priv = master->private; + ret = gf_thread_create(&priv->connectionjanitor, NULL, + gf_changelog_connection_janitor, master, "clogjan"); + if (ret != 0) { + /* TODO: cleanup priv, mutex (poller thread for !xl) */ + goto dealloc_name; + } + + return 0; + +dealloc_name: + free(master->name); +dealloc_master: + free(master); + master = NULL; +error_return: + return -1; } int -gf_changelog_register_generic (struct gf_brick_spec *bricks, int count, - int ordered, char *logfile, int lvl, void *xl) +gf_changelog_register_generic(struct gf_brick_spec *bricks, int count, + int ordered, char *logfile, int lvl, void *xl) { - int ret = 0; - xlator_t *this = NULL; - xlator_t *old_this = NULL; - struct gf_brick_spec *brick = NULL; - gf_boolean_t need_order = _gf_false; + int ret = 0; + xlator_t *this = NULL; + xlator_t *old_this = NULL; + struct gf_brick_spec *brick = NULL; + gf_boolean_t need_order = _gf_false; - SAVE_THIS (xl); + SAVE_THIS(xl); - this = THIS; - if (!this) - goto error_return; + this = THIS; + if (!this) + goto error_return; - ret = gf_changelog_setup_logging (this, logfile, lvl); - if (ret) - goto error_return; - - need_order = (ordered) ? _gf_true : _gf_false; - - brick = bricks; - while (count--) { - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_LIB_MSG_NOTIFY_REGISTER_INFO, - "Registering brick", - "brick=%s", brick->brick_path, - "notify_filter=%d", brick->filter, - NULL); - - ret = gf_changelog_register_brick (this, brick, need_order, xl); - if (ret != 0) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_NOTIFY_REGISTER_FAILED, - "Error registering with changelog xlator"); - break; - } - - brick++; + ret = gf_changelog_setup_logging(this, logfile, lvl); + if (ret) + goto error_return; + + need_order = (ordered) ? _gf_true : _gf_false; + + brick = bricks; + while (count--) { + gf_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_LIB_MSG_NOTIFY_REGISTER_INFO, "brick=%s", + brick->brick_path, "notify_filter=%d", brick->filter, NULL); + + ret = gf_changelog_register_brick(this, brick, need_order, xl); + if (ret != 0) { + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_LIB_MSG_NOTIFY_REGISTER_FAILED, + "Error registering with changelog xlator"); + break; } - if (ret != 0) - goto cleanup_inited_bricks; + brick++; + } - RESTORE_THIS(); - return 0; + if (ret != 0) + goto cleanup_inited_bricks; - cleanup_inited_bricks: - gf_cleanup_connections (this); - error_return: - RESTORE_THIS(); - return -1; + RESTORE_THIS(); + return 0; + +cleanup_inited_bricks: + gf_cleanup_connections(this); +error_return: + RESTORE_THIS(); + return -1; } /** @@ -609,27 +624,29 @@ gf_changelog_register_generic (struct gf_brick_spec *bricks, int count, * For generic API, refer gf_changelog_register_generic(). */ int -gf_changelog_register (char *brick_path, char *scratch_dir, - char *log_file, int log_level, int max_reconnects) +gf_changelog_register(char *brick_path, char *scratch_dir, char *log_file, + int log_level, int max_reconnects) { - struct gf_brick_spec brick = {0,}; + struct gf_brick_spec brick = { + 0, + }; - if (master) - THIS = master; - else - return -1; + if (master) + THIS = master; + else + return -1; - brick.brick_path = brick_path; - brick.filter = CHANGELOG_OP_TYPE_JOURNAL; + brick.brick_path = brick_path; + brick.filter = CHANGELOG_OP_TYPE_JOURNAL; - brick.init = gf_changelog_journal_init; - brick.fini = gf_changelog_journal_fini; - brick.callback = gf_changelog_handle_journal; - brick.connected = gf_changelog_journal_connect; - brick.disconnected = gf_changelog_journal_disconnect; + brick.init = gf_changelog_journal_init; + brick.fini = gf_changelog_journal_fini; + brick.callback = gf_changelog_handle_journal; + brick.connected = gf_changelog_journal_connect; + brick.disconnected = gf_changelog_journal_disconnect; - brick.ptr = scratch_dir; + brick.ptr = scratch_dir; - return gf_changelog_register_generic (&brick, 1, 1, - log_file, log_level, NULL); + return gf_changelog_register_generic(&brick, 1, 1, log_file, log_level, + NULL); } diff --git a/xlators/features/changelog/lib/src/gf-history-changelog.c b/xlators/features/changelog/lib/src/gf-history-changelog.c index fd92dd7ed0b..a16219f3664 100644 --- a/xlators/features/changelog/lib/src/gf-history-changelog.c +++ b/xlators/features/changelog/lib/src/gf-history-changelog.c @@ -8,10 +8,10 @@ #endif #include <string.h> -#include "globals.h" -#include "glusterfs.h" -#include "logging.h" -#include "syscall.h" +#include <glusterfs/globals.h> +#include <glusterfs/glusterfs.h> +#include <glusterfs/logging.h> +#include <glusterfs/syscall.h> #include "gf-changelog-helpers.h" #include "gf-changelog-journal.h" @@ -36,62 +36,60 @@ * -1: On error. */ int -gf_history_changelog_done (char *file) +gf_history_changelog_done(char *file) { - int ret = -1; - char *buffer = NULL; - xlator_t *this = NULL; - gf_changelog_journal_t *jnl = NULL; - gf_changelog_journal_t *hist_jnl = NULL; - char to_path[PATH_MAX] = {0,}; + int ret = -1; + char *buffer = NULL; + xlator_t *this = NULL; + gf_changelog_journal_t *jnl = NULL; + gf_changelog_journal_t *hist_jnl = NULL; + char to_path[PATH_MAX] = { + 0, + }; + + errno = EINVAL; + + this = THIS; + if (!this) + goto out; + + jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this); + if (!jnl) + goto out; + + hist_jnl = jnl->hist_jnl; + if (!hist_jnl) + goto out; + + if (!file || !strlen(file)) + goto out; + + /* make sure 'file' is inside ->jnl_working_dir */ + buffer = realpath(file, NULL); + if (!buffer) + goto out; + + if (strncmp(hist_jnl->jnl_working_dir, buffer, + strlen(hist_jnl->jnl_working_dir))) + goto out; + + (void)snprintf(to_path, PATH_MAX, "%s%s", hist_jnl->jnl_processed_dir, + basename(buffer)); + gf_msg_debug(this->name, 0, "moving %s to processed directory", file); + ret = sys_rename(buffer, to_path); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_RENAME_FAILED, "from=%s", file, "to=%s", + to_path, NULL); + goto out; + } + + ret = 0; - errno = EINVAL; - - this = THIS; - if (!this) - goto out; - - jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this); - if (!jnl) - goto out; - - hist_jnl = jnl->hist_jnl; - if (!hist_jnl) - goto out; - - if (!file || !strlen (file)) - goto out; - - /* make sure 'file' is inside ->jnl_working_dir */ - buffer = realpath (file, NULL); - if (!buffer) - goto out; - - if (strncmp (hist_jnl->jnl_working_dir, - buffer, strlen (hist_jnl->jnl_working_dir))) - goto out; - - (void) snprintf (to_path, PATH_MAX, "%s%s", - hist_jnl->jnl_processed_dir, basename (buffer)); - gf_msg_debug (this->name, 0, - "moving %s to processed directory", file); - ret = sys_rename (buffer, to_path); - if (ret) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_RENAME_FAILED, - "cannot move changelog file", - "from=%s", file, - "to=%s", to_path, - NULL); - goto out; - } - - ret = 0; - - out: - if (buffer) - free (buffer); /* allocated by realpath() */ - return ret; +out: + if (buffer) + free(buffer); /* allocated by realpath() */ + return ret; } /** @@ -105,33 +103,33 @@ gf_history_changelog_done (char *file) * -1: On error. */ int -gf_history_changelog_start_fresh () +gf_history_changelog_start_fresh() { - xlator_t *this = NULL; - gf_changelog_journal_t *jnl = NULL; - gf_changelog_journal_t *hist_jnl = NULL; + xlator_t *this = NULL; + gf_changelog_journal_t *jnl = NULL; + gf_changelog_journal_t *hist_jnl = NULL; - this = THIS; - if (!this) - goto out; + this = THIS; + if (!this) + goto out; - errno = EINVAL; + errno = EINVAL; - jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this); - if (!jnl) - goto out; + jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this); + if (!jnl) + goto out; - hist_jnl = jnl->hist_jnl; - if (!hist_jnl) - goto out; + hist_jnl = jnl->hist_jnl; + if (!hist_jnl) + goto out; - if (gf_ftruncate (hist_jnl->jnl_fd, 0)) - goto out; + if (gf_ftruncate(hist_jnl->jnl_fd, 0)) + goto out; - return 0; + return 0; - out: - return -1; +out: + return -1; } /** @@ -150,50 +148,52 @@ gf_history_changelog_start_fresh () * -1 : On error. */ ssize_t -gf_history_changelog_next_change (char *bufptr, size_t maxlen) +gf_history_changelog_next_change(char *bufptr, size_t maxlen) { - ssize_t size = -1; - int tracker_fd = 0; - xlator_t *this = NULL; - gf_changelog_journal_t *jnl = NULL; - gf_changelog_journal_t *hist_jnl = NULL; - char buffer[PATH_MAX] = {0,}; - - if (maxlen > PATH_MAX) { - errno = ENAMETOOLONG; - goto out; - } + ssize_t size = -1; + int tracker_fd = 0; + xlator_t *this = NULL; + gf_changelog_journal_t *jnl = NULL; + gf_changelog_journal_t *hist_jnl = NULL; + char buffer[PATH_MAX] = { + 0, + }; - errno = EINVAL; + if (maxlen > PATH_MAX) { + errno = ENAMETOOLONG; + goto out; + } - this = THIS; - if (!this) - goto out; + errno = EINVAL; - jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this); - if (!jnl) - goto out; + this = THIS; + if (!this) + goto out; - hist_jnl = jnl->hist_jnl; - if (!hist_jnl) - goto out; + jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this); + if (!jnl) + goto out; - tracker_fd = hist_jnl->jnl_fd; + hist_jnl = jnl->hist_jnl; + if (!hist_jnl) + goto out; - size = gf_readline (tracker_fd, buffer, maxlen); - if (size < 0) { - size = -1; - goto out; - } + tracker_fd = hist_jnl->jnl_fd; - if (size == 0) - goto out; + size = gf_readline(tracker_fd, buffer, maxlen); + if (size < 0) { + size = -1; + goto out; + } - memcpy (bufptr, buffer, size - 1); - bufptr[size - 1] = '\0'; + if (size == 0) + goto out; + + memcpy(bufptr, buffer, size - 1); + bufptr[size - 1] = '\0'; out: - return size; + return size; } /** @@ -214,97 +214,100 @@ out: * */ ssize_t -gf_history_changelog_scan () +gf_history_changelog_scan() { - int tracker_fd = 0; - size_t off = 0; - xlator_t *this = NULL; - size_t nr_entries = 0; - gf_changelog_journal_t *jnl = NULL; - gf_changelog_journal_t *hist_jnl = NULL; - struct dirent *entry = NULL; - struct dirent scratch[2] = {{0,},}; - char buffer[PATH_MAX] = {0,}; - static int is_last_scan; - - this = THIS; - if (!this) - goto out; + int tracker_fd = 0; + size_t off = 0; + xlator_t *this = NULL; + size_t nr_entries = 0; + gf_changelog_journal_t *jnl = NULL; + gf_changelog_journal_t *hist_jnl = NULL; + struct dirent *entry = NULL; + struct dirent scratch[2] = { + { + 0, + }, + }; + char buffer[PATH_MAX] = { + 0, + }; + static int is_last_scan; + + this = THIS; + if (!this) + goto out; + + jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this); + if (!jnl) + goto out; + if (JNL_IS_API_DISCONNECTED(jnl)) { + errno = ENOTCONN; + goto out; + } + + hist_jnl = jnl->hist_jnl; + if (!hist_jnl) + goto out; + +retry: + if (is_last_scan == 1) + return 0; + if (hist_jnl->hist_done == 0) + is_last_scan = 1; - jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this); - if (!jnl) - goto out; - if (JNL_IS_API_DISCONNECTED (jnl)) { - errno = ENOTCONN; - goto out; - } + errno = EINVAL; + if (hist_jnl->hist_done == -1) + goto out; - hist_jnl = jnl->hist_jnl; - if (!hist_jnl) - goto out; + tracker_fd = hist_jnl->jnl_fd; - retry: - if (is_last_scan == 1) - return 0; - if (hist_jnl->hist_done == 0) - is_last_scan = 1; + if (gf_ftruncate(tracker_fd, 0)) + goto out; - errno = EINVAL; - if (hist_jnl->hist_done == -1) - goto out; + rewinddir(hist_jnl->jnl_dir); - tracker_fd = hist_jnl->jnl_fd; + for (;;) { + errno = 0; + entry = sys_readdir(hist_jnl->jnl_dir, scratch); + if (!entry || errno != 0) + break; - if (gf_ftruncate (tracker_fd, 0)) - goto out; + if (strcmp(basename(entry->d_name), ".") == 0 || + strcmp(basename(entry->d_name), "..") == 0) + continue; + + nr_entries++; - rewinddir (hist_jnl->jnl_dir); - - for (;;) { - errno = 0; - entry = sys_readdir (hist_jnl->jnl_dir, scratch); - if (!entry || errno != 0) - break; - - if (strcmp (basename (entry->d_name), ".") == 0 || - strcmp (basename (entry->d_name), "..") == 0) - continue; - - nr_entries++; - - GF_CHANGELOG_FILL_BUFFER (hist_jnl->jnl_processing_dir, - buffer, off, - strlen (hist_jnl->jnl_processing_dir)); - GF_CHANGELOG_FILL_BUFFER (entry->d_name, buffer, - off, strlen (entry->d_name)); - GF_CHANGELOG_FILL_BUFFER ("\n", buffer, off, 1); - - if (gf_changelog_write (tracker_fd, buffer, off) != off) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_WRITE_FAILED, - "error writing changelog filename" - " to tracker file"); - break; - } - off = 0; + GF_CHANGELOG_FILL_BUFFER(hist_jnl->jnl_processing_dir, buffer, off, + strlen(hist_jnl->jnl_processing_dir)); + GF_CHANGELOG_FILL_BUFFER(entry->d_name, buffer, off, + strlen(entry->d_name)); + GF_CHANGELOG_FILL_BUFFER("\n", buffer, off, 1); + + if (gf_changelog_write(tracker_fd, buffer, off) != off) { + gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_WRITE_FAILED, + "error writing changelog filename" + " to tracker file"); + break; } + off = 0; + } + + gf_msg_debug(this->name, 0, "hist_done %d, is_last_scan: %d", + hist_jnl->hist_done, is_last_scan); - gf_msg_debug (this->name, 0, - "hist_done %d, is_last_scan: %d", - hist_jnl->hist_done, is_last_scan); - - if (!entry) { - if (gf_lseek (tracker_fd, 0, SEEK_SET) != -1) { - if (nr_entries > 0) - return nr_entries; - else { - sleep(1); - goto retry; - } - } + if (!entry) { + if (gf_lseek(tracker_fd, 0, SEEK_SET) != -1) { + if (nr_entries > 0) + return nr_entries; + else { + sleep(1); + goto retry; + } } - out: - return -1; + } +out: + return -1; } /* @@ -312,36 +315,36 @@ gf_history_changelog_scan () * Returns 0 on success(updates given time-stamp), -1 on failure. */ int -gf_history_get_timestamp (int fd, int index, int len, - unsigned long *ts) +gf_history_get_timestamp(int fd, int index, int len, unsigned long *ts) { - xlator_t *this = NULL; - int n_read = -1; - char path_buf[PATH_MAX]= {0,}; - char *iter = path_buf; - size_t offset = index * (len+1); - unsigned long value = 0; - int ret = 0; - - this = THIS; - if (!this) { - return -1; - } - - n_read = sys_pread (fd, path_buf, len, offset); - if (n_read < 0 ) { - ret = -1; - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_READ_ERROR, - "could not read from htime file"); - goto out; - } - iter+= len - TIMESTAMP_LENGTH; - sscanf (iter, "%lu",&value); + xlator_t *this = NULL; + int n_read = -1; + char path_buf[PATH_MAX] = { + 0, + }; + char *iter = path_buf; + size_t offset = index * (len + 1); + unsigned long value = 0; + int ret = 0; + + this = THIS; + if (!this) { + return -1; + } + + n_read = sys_pread(fd, path_buf, len, offset); + if (n_read < 0) { + ret = -1; + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_READ_ERROR, + "could not read from htime file"); + goto out; + } + iter += len - TIMESTAMP_LENGTH; + sscanf(iter, "%lu", &value); out: - if(ret == 0) - *ts = value; - return ret; + if (ret == 0) + *ts = value; + return ret; } /* @@ -349,38 +352,37 @@ out: * Checks whether @value is there next to @target_index or not */ int -gf_history_check ( int fd, int target_index, unsigned long value, int len) +gf_history_check(int fd, int target_index, unsigned long value, int len) { - int ret = 0; - unsigned long ts1 = 0; - unsigned long ts2 = 0; - - if (target_index == 0) { - ret = gf_history_get_timestamp (fd, target_index, len, &ts1); - if (ret == -1) - goto out; - if (value <= ts1) - goto out; - else { - ret = -1; - goto out; - } - } + int ret = 0; + unsigned long ts1 = 0; + unsigned long ts2 = 0; - ret = gf_history_get_timestamp (fd, target_index, len, &ts1); - if (ret ==-1) - goto out; - ret = gf_history_get_timestamp (fd, target_index -1, len, &ts2); - if (ret ==-1) - goto out; - - if ( (value <= ts1) && (value > ts2) ) { - goto out; - } - else - ret = -1; + if (target_index == 0) { + ret = gf_history_get_timestamp(fd, target_index, len, &ts1); + if (ret == -1) + goto out; + if (value <= ts1) + goto out; + else { + ret = -1; + goto out; + } + } + + ret = gf_history_get_timestamp(fd, target_index, len, &ts1); + if (ret == -1) + goto out; + ret = gf_history_get_timestamp(fd, target_index - 1, len, &ts2); + if (ret == -1) + goto out; + + if ((value <= ts1) && (value > ts2)) { + goto out; + } else + ret = -1; out: - return ret; + return ret; } /* @@ -400,78 +402,69 @@ out: */ int -gf_history_b_search (int fd, unsigned long value, - unsigned long from, unsigned long to, int len) +gf_history_b_search(int fd, unsigned long value, unsigned long from, + unsigned long to, int len) { - int m_index = -1; - unsigned long cur_value = 0; - unsigned long ts1 = 0; - int ret = 0; - - m_index = (from + to)/2; - - if ( (to - from) <=1 ) { - /* either one or 2 changelogs left */ - if ( to != from ) { - /* check if value is less or greater than to - * return accordingly - */ - ret = gf_history_get_timestamp (fd, from, len, &ts1); - if (ret ==-1) - goto out; - if ( ts1 >= value) { - /* actually compatision should be - * exactly == but considering - * - * case of only 2 changelogs in htime file - */ - return from; - } - else - return to; - } - else - return to; - } - - ret = gf_history_get_timestamp (fd, m_index, len, &cur_value); + int m_index = -1; + unsigned long cur_value = 0; + unsigned long ts1 = 0; + int ret = 0; + + m_index = (from + to) / 2; + + if ((to - from) <= 1) { + /* either one or 2 changelogs left */ + if (to != from) { + /* check if value is less or greater than to + * return accordingly + */ + ret = gf_history_get_timestamp(fd, from, len, &ts1); + if (ret == -1) + goto out; + if (ts1 >= value) { + /* actually compatision should be + * exactly == but considering + * + * case of only 2 changelogs in htime file + */ + return from; + } else + return to; + } else + return to; + } + + ret = gf_history_get_timestamp(fd, m_index, len, &cur_value); + if (ret == -1) + goto out; + if (cur_value == value) { + return m_index; + } else if (value > cur_value) { + ret = gf_history_get_timestamp(fd, m_index + 1, len, &cur_value); if (ret == -1) - goto out; - if (cur_value == value) { + goto out; + if (value < cur_value) + return m_index + 1; + else + return gf_history_b_search(fd, value, m_index + 1, to, len); + } else { + if (m_index == 0) { + /* we are sure that values exists + * in this htime file + */ + return 0; + } else { + ret = gf_history_get_timestamp(fd, m_index - 1, len, &cur_value); + if (ret == -1) + goto out; + if (value > cur_value) { return m_index; + } else + return gf_history_b_search(fd, value, from, m_index - 1, len); } - else if (value > cur_value) { - ret = gf_history_get_timestamp (fd, m_index+1, len, &cur_value); - if (ret == -1) - goto out; - if (value < cur_value) - return m_index + 1; - else - return gf_history_b_search (fd, value, - m_index+1, to, len); - } - else { - if (m_index ==0) { - /* we are sure that values exists - * in this htime file - */ - return 0; - } - else { - ret = gf_history_get_timestamp (fd, m_index-1, len, - &cur_value); - if (ret == -1) - goto out; - if (value > cur_value) { - return m_index; - } - else - return gf_history_b_search (fd, value, from, - m_index-1, len); - } - } + } out: - return -1; + return -1; } /* @@ -484,65 +477,59 @@ out: * 0 : No, Not usable ( contains, "changelog") */ int -gf_is_changelog_usable (char *cl_path) +gf_is_changelog_usable(char *cl_path) { - int ret = -1; - const char low_c[] = "changelog"; - char *str_ret = NULL; - char *bname = NULL; + int ret = -1; + const char low_c[] = "changelog"; + char *str_ret = NULL; + char *bname = NULL; - bname = basename (cl_path); + bname = basename(cl_path); - str_ret = strstr (bname, low_c); + str_ret = strstr(bname, low_c); - if (str_ret != NULL) - ret = 0; - else - ret = 1; - - return ret; + if (str_ret != NULL) + ret = 0; + else + ret = 1; + return ret; } void * -gf_changelog_consume_wrap (void* data) +gf_changelog_consume_wrap(void *data) { - int ret = -1; - ssize_t nread = 0; - xlator_t *this = NULL; - gf_changelog_consume_data_t *ccd = NULL; - - ccd = (gf_changelog_consume_data_t *) data; - this = ccd->this; - - ccd->retval = -1; - - nread = sys_pread (ccd->fd, ccd->changelog, PATH_MAX-1, ccd->offset); - if (nread < 0) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_READ_ERROR, - "cannot read from history metadata file"); - goto out; - } - - /* TODO: handle short reads and EOF. */ - if (gf_is_changelog_usable (ccd->changelog) == 1) { - - ret = gf_changelog_consume (ccd->this, - ccd->jnl, ccd->changelog, _gf_true); - if (ret) { - gf_smsg (this->name, GF_LOG_ERROR, - 0, CHANGELOG_LIB_MSG_PARSE_ERROR, - "could not parse changelog", - "name=%s", ccd->changelog, - NULL); - goto out; - } + int ret = -1; + ssize_t nread = 0; + xlator_t *this = NULL; + gf_changelog_consume_data_t *ccd = NULL; + + ccd = (gf_changelog_consume_data_t *)data; + this = ccd->this; + + ccd->retval = -1; + + nread = sys_pread(ccd->fd, ccd->changelog, PATH_MAX - 1, ccd->offset); + if (nread < 0) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_READ_ERROR, + "cannot read from history metadata file"); + goto out; + } + + /* TODO: handle short reads and EOF. */ + if (gf_is_changelog_usable(ccd->changelog) == 1) { + ret = gf_changelog_consume(ccd->this, ccd->jnl, ccd->changelog, + _gf_true); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_PARSE_ERROR, + "name=%s", ccd->changelog, NULL); + goto out; } - ccd->retval = 0; + } + ccd->retval = 0; - out: - return NULL; +out: + return NULL; } /** @@ -551,133 +538,132 @@ gf_changelog_consume_wrap (void* data) * to index "to" in open htime file whose fd is "fd". */ -#define MAX_PARALLELS 10 +#define MAX_PARALLELS 10 void * -gf_history_consume (void * data) +gf_history_consume(void *data) { - xlator_t *this = NULL; - gf_changelog_journal_t *jnl = NULL; - gf_changelog_journal_t *hist_jnl = NULL; - int ret = 0; - int iter = 0; - int fd = -1; - int from = -1; - int to = -1; - int len = -1; - int n_parallel = 0; - int n_envoked = 0; - gf_boolean_t publish = _gf_true; - pthread_t th_id[MAX_PARALLELS] = {0,}; - gf_changelog_history_data_t *hist_data = NULL; - gf_changelog_consume_data_t ccd[MAX_PARALLELS] = {{0},}; - gf_changelog_consume_data_t *curr = NULL; - char thread_name[GF_THREAD_NAMEMAX] = {0,}; - - hist_data = (gf_changelog_history_data_t *) data; - if (hist_data == NULL) { - ret = -1; - goto out; - } - - fd = hist_data->htime_fd; - from = hist_data->from; - to = hist_data->to; - len = hist_data->len; - n_parallel = hist_data->n_parallel; - - THIS = hist_data->this; - this = hist_data->this; - if (!this) { - ret = -1; - goto out; - } - - jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this); - if (!jnl) { - ret = -1; - goto out; - } - - hist_jnl = jnl->hist_jnl; - if (!hist_jnl) { - ret = -1; - goto out; - } - - while (from <= to) { - n_envoked = 0; - - for (iter = 0 ; (iter < n_parallel) && (from <= to); iter++) { - curr = &ccd[iter]; - - curr->this = this; - curr->jnl = hist_jnl; - curr->fd = fd; - curr->offset = from * (len + 1); - - curr->retval = 0; - memset (curr->changelog, '\0', PATH_MAX); - snprintf (thread_name, sizeof(thread_name), - "clogc%03hx", ((iter + 1) & 0x3ff)); - - ret = gf_thread_create (&th_id[iter], NULL, - gf_changelog_consume_wrap, curr, - thread_name); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, ret, - CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED - , "could not create consume-thread"); - goto sync; - } else - n_envoked++; - - from++; - } - - sync: - for (iter = 0; iter < n_envoked; iter++) { - ret = pthread_join (th_id[iter], NULL); - if (ret) { - publish = _gf_false; - gf_msg (this->name, GF_LOG_ERROR, ret, - CHANGELOG_LIB_MSG_PTHREAD_JOIN_FAILED, - "pthread_join() error"); - /* try to join the rest */ - continue; - } - - if (publish == _gf_false) - continue; - - curr = &ccd[iter]; - if (ccd->retval) { - publish = _gf_false; - gf_msg (this->name, GF_LOG_ERROR, - 0, CHANGELOG_LIB_MSG_PARSE_ERROR, - "parsing error, ceased publishing..."); - continue; - } - - ret = gf_changelog_publish (curr->this, - curr->jnl, curr->changelog); - if (ret) { - publish = _gf_false; - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_PUBLISH_ERROR, - "publish error, ceased publishing..."); - } - } - } - - /* informing "parsing done". */ - hist_jnl->hist_done = (publish == _gf_true) ? 0 : -1; + xlator_t *this = NULL; + gf_changelog_journal_t *jnl = NULL; + gf_changelog_journal_t *hist_jnl = NULL; + int ret = 0; + int iter = 0; + int fd = -1; + int from = -1; + int to = -1; + int len = -1; + int n_parallel = 0; + int n_envoked = 0; + gf_boolean_t publish = _gf_true; + pthread_t th_id[MAX_PARALLELS] = { + 0, + }; + gf_changelog_history_data_t *hist_data = NULL; + gf_changelog_consume_data_t ccd[MAX_PARALLELS] = { + {0}, + }; + gf_changelog_consume_data_t *curr = NULL; + + hist_data = (gf_changelog_history_data_t *)data; + if (hist_data == NULL) { + ret = -1; + goto out; + } + + fd = hist_data->htime_fd; + from = hist_data->from; + to = hist_data->to; + len = hist_data->len; + n_parallel = hist_data->n_parallel; + + THIS = hist_data->this; + this = hist_data->this; + if (!this) { + ret = -1; + goto out; + } + + jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this); + if (!jnl) { + ret = -1; + goto out; + } + + hist_jnl = jnl->hist_jnl; + if (!hist_jnl) { + ret = -1; + goto out; + } + + while (from <= to) { + n_envoked = 0; + + for (iter = 0; (iter < n_parallel) && (from <= to); iter++) { + curr = &ccd[iter]; + + curr->this = this; + curr->jnl = hist_jnl; + curr->fd = fd; + curr->offset = from * (len + 1); + + curr->retval = 0; + memset(curr->changelog, '\0', PATH_MAX); + + ret = gf_thread_create(&th_id[iter], NULL, + gf_changelog_consume_wrap, curr, + "clogc%03hx", (iter + 1) & 0x3ff); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, ret, + CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED, + "could not create consume-thread"); + goto sync; + } else + n_envoked++; + + from++; + } + + sync: + for (iter = 0; iter < n_envoked; iter++) { + ret = pthread_join(th_id[iter], NULL); + if (ret) { + publish = _gf_false; + gf_msg(this->name, GF_LOG_ERROR, ret, + CHANGELOG_LIB_MSG_PTHREAD_JOIN_FAILED, + "pthread_join() error"); + /* try to join the rest */ + continue; + } + + if (publish == _gf_false) + continue; + + curr = &ccd[iter]; + if (ccd->retval) { + publish = _gf_false; + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_LIB_MSG_PARSE_ERROR_CEASED, NULL); + continue; + } + + ret = gf_changelog_publish(curr->this, curr->jnl, curr->changelog); + if (ret) { + publish = _gf_false; + gf_msg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_LIB_MSG_PUBLISH_ERROR, + "publish error, ceased publishing..."); + } + } + } + + /* informing "parsing done". */ + hist_jnl->hist_done = (publish == _gf_true) ? 0 : -1; out: - if (fd != -1) - (void) sys_close (fd); - GF_FREE (hist_data); - return NULL; + if (fd != -1) + (void)sys_close(fd); + GF_FREE(hist_data); + return NULL; } /** @@ -707,317 +693,328 @@ out: * -2 : Ignore this metadata file and process next */ int -gf_changelog_extract_min_max (const char *dname, const char *htime_dir, - int *fd, unsigned long *total, - unsigned long *min_ts, unsigned long *max_ts) +gf_changelog_extract_min_max(const char *dname, const char *htime_dir, int *fd, + unsigned long *total, unsigned long *min_ts, + unsigned long *max_ts) { - int ret = -1; - xlator_t *this = NULL; - char htime_file[PATH_MAX] = {0,}; - struct stat stbuf = {0,}; - char *iter = NULL; - char x_value[30] = {0,}; - - this = THIS; - - snprintf (htime_file, PATH_MAX, "%s/%s", htime_dir, dname); + int ret = -1; + xlator_t *this = NULL; + char htime_file[PATH_MAX] = { + 0, + }; + struct stat stbuf = { + 0, + }; + char *iter = NULL; + char x_value[30] = { + 0, + }; + + this = THIS; + + snprintf(htime_file, PATH_MAX, "%s/%s", htime_dir, dname); + + iter = (htime_file + strlen(htime_file) - TIMESTAMP_LENGTH); + sscanf(iter, "%lu", min_ts); + + ret = sys_stat(htime_file, &stbuf); + if (ret) { + ret = -1; + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_HTIME_ERROR, + "op=stat", "path=%s", htime_file, NULL); + goto out; + } + + /* ignore everything except regular files */ + if (!S_ISREG(stbuf.st_mode)) { + ret = -2; + goto out; + } + + *fd = open(htime_file, O_RDONLY); + if (*fd < 0) { + ret = -1; + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_HTIME_ERROR, + "op=open", "path=%s", htime_file, NULL); + goto out; + } + + /* Looks good, extract max timestamp */ + ret = sys_fgetxattr(*fd, HTIME_KEY, x_value, sizeof(x_value)); + if (ret < 0) { + ret = -1; + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_GET_XATTR_FAILED, "path=%s", htime_file, + NULL); + goto out; + } + + sscanf(x_value, "%lu:%lu", max_ts, total); + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_LIB_MSG_MIN_MAX_INFO, + "min=%lu", *min_ts, "max=%lu", *max_ts, "total_changelogs=%lu", + *total, NULL); + + ret = 0; - iter = (htime_file + strlen (htime_file) - TIMESTAMP_LENGTH); - sscanf (iter ,"%lu",min_ts); +out: + return ret; +} - ret = sys_stat (htime_file, &stbuf); +/* gf_history_changelog returns actual_end and spawns threads to + * parse historical changelogs. The return values are as follows. + * 0 : On success + * 1 : Successful, but partial historical changelogs available, + * end time falls into different htime file or future time + * -2 : Error, requested historical changelog not available, not + * even partial + * -1 : On any error + */ +int +gf_history_changelog(char *changelog_dir, unsigned long start, + unsigned long end, int n_parallel, + unsigned long *actual_end) +{ + int ret = 0; + int len = -1; + int fd = -1; + int n_read = -1; + unsigned long min_ts = 0; + unsigned long max_ts = 0; + unsigned long end2 = 0; + unsigned long ts1 = 0; + unsigned long ts2 = 0; + unsigned long to = 0; + unsigned long from = 0; + unsigned long total_changelog = 0; + xlator_t *this = NULL; + gf_changelog_journal_t *jnl = NULL; + gf_changelog_journal_t *hist_jnl = NULL; + gf_changelog_history_data_t *hist_data = NULL; + DIR *dirp = NULL; + struct dirent *entry = NULL; + struct dirent scratch[2] = { + { + 0, + }, + }; + pthread_t consume_th = 0; + char htime_dir[PATH_MAX] = { + 0, + }; + char buffer[PATH_MAX] = { + 0, + }; + gf_boolean_t partial_history = _gf_false; + + pthread_attr_t attr; + + this = THIS; + if (!this) { + ret = -1; + goto out; + } + + ret = pthread_attr_init(&attr); + if (ret != 0) { + gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_PTHREAD_ERROR, + "Pthread init failed"); + return -1; + } + + jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this); + if (!jnl) { + ret = -1; + goto out; + } + + hist_jnl = (gf_changelog_journal_t *)jnl->hist_jnl; + if (!hist_jnl) { + ret = -1; + goto out; + } + + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_LIB_MSG_REQUESTING_INFO, + "start=%lu", start, "end=%lu", end, NULL); + + /* basic sanity check */ + if (start > end || n_parallel <= 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_HIST_FAILED, + "start=%lu", start, "end=%lu", end, "thread_count=%d", + n_parallel, NULL); + ret = -1; + goto out; + } + + /* cap parallelism count */ + if (n_parallel > MAX_PARALLELS) + n_parallel = MAX_PARALLELS; + + CHANGELOG_FILL_HTIME_DIR(changelog_dir, htime_dir); + + dirp = sys_opendir(htime_dir); + if (dirp == NULL) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_HTIME_ERROR, + "op=opendir", "path=%s", htime_dir, NULL); + ret = -1; + goto out; + } + + for (;;) { + errno = 0; + + entry = sys_readdir(dirp, scratch); + + if (!entry || errno != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_HIST_FAILED, "start=%lu", start, + "end=%lu", end, NULL); + ret = -2; + break; + } + + ret = gf_changelog_extract_min_max(entry->d_name, htime_dir, &fd, + &total_changelog, &min_ts, &max_ts); if (ret) { - ret = -1; - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_HTIME_ERROR, - "stat() failed on htime file", - "path=%s", htime_file, - NULL); - goto out; - } - - /* ignore everything except regular files */ - if (!S_ISREG (stbuf.st_mode)) { - ret = -2; - goto out; + if (-2 == ret) + continue; + goto out; } - *fd = open (htime_file, O_RDONLY); - if (*fd < 0) { + if (start >= min_ts && start < max_ts) { + /** + * TODO: handle short reads later... + */ + n_read = sys_read(fd, buffer, PATH_MAX); + if (n_read < 0) { ret = -1; - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_HTIME_ERROR, - "open() failed for htime file", - "path=%s", htime_file, - NULL); + gf_msg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_READ_ERROR, + "unable to read htime file"); goto out; - } + } - /* Looks good, extract max timestamp */ - ret = sys_fgetxattr (*fd, HTIME_KEY, x_value, sizeof (x_value)); - if (ret < 0) { - ret = -1; - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_GET_XATTR_FAILED, - "error extracting max timstamp from htime file" - "path=%s", htime_file, - NULL); - goto out; - } - - sscanf (x_value, "%lu:%lu", max_ts, total); - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_LIB_MSG_TOTAL_LOG_INFO, - "changelogs min max", - "min=%lu", *min_ts, - "max=%lu", *max_ts, - "total_changelogs=%lu", *total, - NULL); + len = strlen(buffer); - ret = 0; + /** + * search @start in the htime file returning it's index + * (@from) + */ + from = gf_history_b_search(fd, start, 0, total_changelog - 1, len); - out: - return ret; -} - -int -gf_history_changelog (char* changelog_dir, unsigned long start, - unsigned long end, int n_parallel, - unsigned long *actual_end) -{ - int ret = 0; - int len = -1; - int fd = -1; - int n_read = -1; - unsigned long min_ts = 0; - unsigned long max_ts = 0; - unsigned long end2 = 0; - unsigned long ts1 = 0; - unsigned long ts2 = 0; - unsigned long to = 0; - unsigned long from = 0; - unsigned long total_changelog = 0; - xlator_t *this = NULL; - gf_changelog_journal_t *jnl = NULL; - gf_changelog_journal_t *hist_jnl = NULL; - gf_changelog_history_data_t *hist_data = NULL; - DIR *dirp = NULL; - struct dirent *entry = NULL; - struct dirent scratch[2] = {{0,},}; - pthread_t consume_th = 0; - char htime_dir[PATH_MAX] = {0,}; - char buffer[PATH_MAX] = {0,}; - - pthread_attr_t attr; - - this = THIS; - if (!this) { + /* ensuring correctness of gf_b_search */ + if (gf_history_check(fd, from, start, len) != 0) { + ret = -1; + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_LIB_MSG_GET_TIME_ERROR, "for=start", + "start=%lu", start, "idx=%lu", from, NULL); + goto out; + } + + end2 = (end <= max_ts) ? end : max_ts; + + /* Check if end falls out of same HTIME file. The end + * falling to a different htime file or changelog + * disable-enable is detected only after 20 seconds. + * This is required because, applications generally + * asks historical changelogs till current time and + * it is possible changelog is not rolled over yet. + * So, buffer time of default rollover time plus 5 + * seconds is subtracted. If the application requests + * the end time with in half a minute of changelog + * disable, it's not detected as changelog disable and + * it's application's responsibility to retry after + * 20 seconds before confirming it as partial history. + */ + if ((end - 20) > max_ts) { + partial_history = _gf_true; + } + + /** + * search @end2 in htime file returning it's index (@to) + */ + to = gf_history_b_search(fd, end2, 0, total_changelog - 1, len); + + if (gf_history_check(fd, to, end2, len) != 0) { ret = -1; + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_LIB_MSG_GET_TIME_ERROR, "for=end", + "start=%lu", end2, "idx=%lu", to, NULL); goto out; - } + } - ret = pthread_attr_init (&attr); - if (ret != 0) { - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_PTHREAD_ERROR, - "Pthread init failed"); - return -1; - } + ret = gf_history_get_timestamp(fd, from, len, &ts1); + if (ret == -1) + goto out; - jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this); - if (!jnl) { - ret = -1; + ret = gf_history_get_timestamp(fd, to, len, &ts2); + if (ret == -1) goto out; - } - hist_jnl = (gf_changelog_journal_t *) jnl->hist_jnl; - if (!hist_jnl) { + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_LIB_MSG_FINAL_INFO, + "from=%lu", ts1, "to=%lu", ts2, "changes=%lu", + (to - from + 1), NULL); + + hist_data = GF_CALLOC(1, sizeof(gf_changelog_history_data_t), + gf_changelog_mt_history_data_t); + + hist_data->htime_fd = fd; + hist_data->from = from; + hist_data->to = to; + hist_data->len = len; + hist_data->n_parallel = n_parallel; + hist_data->this = this; + + ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + if (ret != 0) { + gf_msg(this->name, GF_LOG_ERROR, ret, + CHANGELOG_LIB_MSG_PTHREAD_ERROR, + "unable to sets the detach" + " state attribute"); ret = -1; goto out; - } + } - /* basic sanity check */ - if (start > end || n_parallel <= 0) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_HIST_FAILED, "Sanity check failed", - "start=%lu", start, - "end=%lu", end, - "thread_count=%d", n_parallel, - NULL); + /* spawn a thread for background parsing & publishing */ + ret = gf_thread_create(&consume_th, &attr, gf_history_consume, + hist_data, "cloghcon"); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, ret, + CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED, + "creation of consume parent-thread" + " failed."); ret = -1; goto out; - } + } - /* cap parallelism count */ - if (n_parallel > MAX_PARALLELS) - n_parallel = MAX_PARALLELS; + goto out; - CHANGELOG_FILL_HTIME_DIR (changelog_dir, htime_dir); - - dirp = sys_opendir (htime_dir); - if (dirp == NULL) { - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_HTIME_ERROR, - "open dir on htime failed", - "path=%s", htime_dir, - NULL); - ret = -1; - goto out; + } else { /* end of range check */ + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_LIB_MSG_HIST_FAILED, "start=%lu", start, + "end=%lu", end, "chlog_min=%lu", min_ts, "chlog_max=%lu", + max_ts, NULL); } - - for (;;) { - - errno = 0; - - entry = sys_readdir (dirp, scratch); - - if (!entry || errno != 0) - break; - - ret = gf_changelog_extract_min_max (entry->d_name, htime_dir, - &fd, &total_changelog, - &min_ts, &max_ts); - if (ret) { - if (-2 == ret) - continue; - goto out; - } - - if (start >= min_ts && start < max_ts) { - /** - * TODO: handle short reads later... - */ - n_read = sys_read (fd, buffer, PATH_MAX); - if (n_read < 0) { - ret = -1; - gf_msg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_READ_ERROR, - "unable to read htime file"); - goto out; - } - - len = strlen (buffer); - - /** - * search @start in the htime file returning it's index - * (@from) - */ - from = gf_history_b_search (fd, start, 0, - total_changelog - 1, len); - - /* ensuring correctness of gf_b_search */ - if (gf_history_check (fd, from, start, len) != 0) { - ret = -1; - gf_smsg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_GET_TIME_ERROR, - "wrong result for start", - "start=%lu", start, - "idx=%lu", from, - NULL); - goto out; - } - - end2 = (end <= max_ts) ? end : max_ts; - - /** - * search @end2 in htime file returning it's index (@to) - */ - to = gf_history_b_search (fd, end2, - 0, total_changelog - 1, len); - - if (gf_history_check (fd, to, end2, len) != 0) { - ret = -1; - gf_smsg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_GET_TIME_ERROR, - "wrong result for end", - "start=%lu", end2, - "idx=%lu", to, - NULL); - goto out; - } - - ret = gf_history_get_timestamp (fd, from, len, &ts1); - if (ret == -1) - goto out; - - ret = gf_history_get_timestamp (fd, to, len, &ts2); - if (ret == -1) - goto out; - - gf_smsg (this->name, GF_LOG_INFO, 0, - CHANGELOG_LIB_MSG_TOTAL_LOG_INFO, - "FINAL", - "from=%lu", ts1, - "to=%lu", ts2, - "changes=%lu", (to - from + 1), - NULL); - - hist_data = GF_CALLOC (1, - sizeof (gf_changelog_history_data_t), - gf_changelog_mt_history_data_t); - - hist_data->htime_fd = fd; - hist_data->from = from; - hist_data->to = to; - hist_data->len = len; - hist_data->n_parallel = n_parallel; - hist_data->this = this; - - ret = pthread_attr_setdetachstate - (&attr, PTHREAD_CREATE_DETACHED); - if (ret != 0) { - gf_msg (this->name, GF_LOG_ERROR, ret, - CHANGELOG_LIB_MSG_PTHREAD_ERROR, - "unable to sets the detach" - " state attribute"); - ret = -1; - goto out; - } - - /* spawn a thread for background parsing & publishing */ - ret = gf_thread_create (&consume_th, &attr, - gf_history_consume, hist_data, - "cloghcon"); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, ret, - CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED - , "creation of consume parent-thread" - " failed."); - ret = -1; - goto out; - } - - goto out; - - } else {/* end of range check */ - gf_smsg (this->name, GF_LOG_ERROR, errno, - CHANGELOG_LIB_MSG_HIST_FAILED, - "Requested changelog " - "range is not available.", - "start=%lu", start, - "chlog_min=%lu", min_ts, - "chlog_max=%lu", max_ts, - NULL); - ret = -2; - goto out; - } - } /* end of readdir() */ + } /* end of readdir() */ out: - if (dirp != NULL) - (void) sys_closedir (dirp); + if (dirp != NULL) + (void)sys_closedir(dirp); - if (ret < 0) { - if (fd != -1) - (void) sys_close (fd); - GF_FREE (hist_data); - (void) pthread_attr_destroy (&attr); + if (ret < 0) { + if (fd != -1) + (void)sys_close(fd); + GF_FREE(hist_data); + (void)pthread_attr_destroy(&attr); - return ret; - } + return ret; + } - hist_jnl->hist_done = 1; - *actual_end = ts2; + hist_jnl->hist_done = 1; + *actual_end = ts2; - return ret; + if (partial_history) { + ret = 1; + } + + return ret; } diff --git a/xlators/features/changelog/src/changelog-barrier.c b/xlators/features/changelog/src/changelog-barrier.c index ac1eb0e4397..0fb89ddb127 100644 --- a/xlators/features/changelog/src/changelog-barrier.c +++ b/xlators/features/changelog/src/changelog-barrier.c @@ -10,125 +10,122 @@ #include "changelog-helpers.h" #include "changelog-messages.h" -#include "call-stub.h" +#include <glusterfs/call-stub.h> /* 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_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_DEQUEUING_BARRIER_FOPS, + NULL); - 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_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_MSG_DEQUEUING_BARRIER_FOPS_FINISHED, NULL); + 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_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_BARRIER_TIMEOUT, NULL); - 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_smsg(this->name, GF_LOG_CRITICAL, 0, + CHANGELOG_MSG_TIMEOUT_ADD_FAILED, NULL); + 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-encoders.h b/xlators/features/changelog/src/changelog-encoders.h index d6a50cc9ef7..26252696d56 100644 --- a/xlators/features/changelog/src/changelog-encoders.h +++ b/xlators/features/changelog/src/changelog-encoders.h @@ -11,41 +11,39 @@ #ifndef _CHANGELOG_ENCODERS_H #define _CHANGELOG_ENCODERS_H -#include "xlator.h" -#include "defaults.h" +#include <glusterfs/xlator.h> +#include <glusterfs/defaults.h> #include "changelog-helpers.h" -#define CHANGELOG_STORE_ASCII(priv, buf, off, gfid, gfid_len, cld) do { \ - CHANGELOG_FILL_BUFFER (buffer, off, \ - priv->maps[cld->cld_type], 1); \ - CHANGELOG_FILL_BUFFER (buffer, \ - off, gfid, gfid_len); \ - } while (0) +#define CHANGELOG_STORE_ASCII(priv, buf, off, gfid, gfid_len, cld) \ + do { \ + CHANGELOG_FILL_BUFFER(buffer, off, priv->maps[cld->cld_type], 1); \ + CHANGELOG_FILL_BUFFER(buffer, off, gfid, gfid_len); \ + } while (0) -#define CHANGELOG_STORE_BINARY(priv, buf, off, gfid, cld) do { \ - CHANGELOG_FILL_BUFFER (buffer, off, \ - priv->maps[cld->cld_type], 1); \ - CHANGELOG_FILL_BUFFER (buffer, \ - off, gfid, sizeof (uuid_t)); \ - } while (0) +#define CHANGELOG_STORE_BINARY(priv, buf, off, gfid, cld) \ + do { \ + CHANGELOG_FILL_BUFFER(buffer, off, priv->maps[cld->cld_type], 1); \ + CHANGELOG_FILL_BUFFER(buffer, off, gfid, sizeof(uuid_t)); \ + } while (0) size_t -entry_fn (void *data, char *buffer, gf_boolean_t encode); +entry_fn(void *data, char *buffer, gf_boolean_t encode); size_t -del_entry_fn (void *data, char *buffer, gf_boolean_t encode); +del_entry_fn(void *data, char *buffer, gf_boolean_t encode); size_t -fop_fn (void *data, char *buffer, gf_boolean_t encode); +fop_fn(void *data, char *buffer, gf_boolean_t encode); size_t -number_fn (void *data, char *buffer, gf_boolean_t encode); +number_fn(void *data, char *buffer, gf_boolean_t encode); void -entry_free_fn (void *data); +entry_free_fn(void *data); void -del_entry_free_fn (void *data); +del_entry_free_fn(void *data); int -changelog_encode_binary (xlator_t *, changelog_log_data_t *); +changelog_encode_binary(xlator_t *, changelog_log_data_t *); int -changelog_encode_ascii (xlator_t *, changelog_log_data_t *); +changelog_encode_ascii(xlator_t *, changelog_log_data_t *); void changelog_encode_change(changelog_priv_t *); diff --git a/xlators/features/changelog/src/changelog-ev-handle.c b/xlators/features/changelog/src/changelog-ev-handle.c index 46d45fbd778..aa94459de5a 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,229 @@ 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, + }, + }; - crpc = mydata; - this = crpc->this; - c_clnt = crpc->c_clnt; + /* dispatch NR_IOVEC IO vectors at a time. */ - priv = this->private; + erpc = data; + sequence = erpc->rlist->seq[0]; - switch (event) { - case RPC_CLNT_CONNECT: - selection = &priv->ev_selection; + rlist_iter_init(&riter, erpc->rlist); - LOCK (&c_clnt->wait_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); - } - UNLOCK (&c_clnt->wait_lock); + 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; - case RPC_CLNT_DISCONNECT: - rpc_clnt_disable (crpc->rpc); + count = 0; + continue; + } + + erpc->vec.vector[idx] = rvec->iov; + } - /* 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 (ret) + goto error_return; - if (priv) - selection = &priv->ev_selection; + 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; +} - LOCK (&crpc->lock); +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; + uint64_t clntcnt = 0; + uint64_t xprtcnt = 0; + + crpc = mydata; + this = crpc->this; + c_clnt = crpc->c_clnt; + + priv = this->private; + + switch (event) { + case RPC_CLNT_CONNECT: + selection = &priv->ev_selection; + GF_ATOMIC_INC(priv->clntcnt); + + LOCK(&c_clnt->wait_lock); + { + LOCK(&c_clnt->active_lock); { - if (selection) - changelog_deselect_event (this, selection, - crpc->filter); - changelog_set_disconnect_flag (crpc, _gf_true); + changelog_select_event(this, selection, crpc->filter); + list_move_tail(&crpc->list, &c_clnt->active); } - UNLOCK (&crpc->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 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; + + LOCK(&crpc->lock); + { + if (selection) + changelog_deselect_event(this, selection, crpc->filter); + changelog_set_disconnect_flag(crpc, _gf_true); + } + UNLOCK(&crpc->lock); + LOCK(&c_clnt->active_lock); + { + list_del_init(&crpc->list); + } + UNLOCK(&c_clnt->active_lock); + + 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); + clntcnt = GF_ATOMIC_DEC(priv->clntcnt); + xprtcnt = GF_ATOMIC_GET(priv->xprtcnt); + if (this->cleanup_starting) { + if (!clntcnt && !xprtcnt) + changelog_process_cleanup_event(this); + } + 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, "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 +268,145 @@ 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_smsg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_MSG_PUT_BUFFER_FAILED, NULL); + } + + 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-ev-handle.h b/xlators/features/changelog/src/changelog-ev-handle.h index e89af8793a8..cc1af58a276 100644 --- a/xlators/features/changelog/src/changelog-ev-handle.h +++ b/xlators/features/changelog/src/changelog-ev-handle.h @@ -11,68 +11,67 @@ #ifndef __CHANGELOG_EV_HANDLE_H #define __CHANGELOG_EV_HANDLE_H -#include "list.h" -#include "xlator.h" +#include <glusterfs/list.h> +#include <glusterfs/xlator.h> #include "rpc-clnt.h" -#include "rot-buffs.h" +#include <glusterfs/rot-buffs.h> struct changelog_clnt; typedef struct changelog_rpc_clnt { - xlator_t *this; + xlator_t *this; - gf_lock_t lock; + gf_lock_t lock; - gf_atomic_t ref; - gf_boolean_t disconnected; + gf_atomic_t ref; + gf_boolean_t disconnected; - unsigned int filter; - char sock[UNIX_PATH_MAX]; + unsigned int filter; + char sock[UNIX_PATH_MAX]; - struct changelog_clnt *c_clnt; /* back pointer to list holder */ + struct changelog_clnt *c_clnt; /* back pointer to list holder */ - struct rpc_clnt *rpc; /* RPC client endpoint */ + struct rpc_clnt *rpc; /* RPC client endpoint */ - struct list_head list; /* ->pending, ->waitq, ->active */ + struct list_head list; /* ->pending, ->waitq, ->active */ - void (*cleanup) - (struct changelog_rpc_clnt *); /* cleanup handler */ + void (*cleanup)(struct changelog_rpc_clnt *); /* cleanup handler */ } changelog_rpc_clnt_t; static inline void -changelog_rpc_clnt_ref (changelog_rpc_clnt_t *crpc) +changelog_rpc_clnt_ref(changelog_rpc_clnt_t *crpc) { - GF_ATOMIC_INC (crpc->ref); + GF_ATOMIC_INC(crpc->ref); } static inline void -changelog_set_disconnect_flag (changelog_rpc_clnt_t *crpc, gf_boolean_t flag) +changelog_set_disconnect_flag(changelog_rpc_clnt_t *crpc, gf_boolean_t flag) { - crpc->disconnected = flag; + crpc->disconnected = flag; } static inline int -changelog_rpc_clnt_is_disconnected (changelog_rpc_clnt_t *crpc) +changelog_rpc_clnt_is_disconnected(changelog_rpc_clnt_t *crpc) { - return (crpc->disconnected == _gf_true); + return (crpc->disconnected == _gf_true); } static inline void -changelog_rpc_clnt_unref (changelog_rpc_clnt_t *crpc) +changelog_rpc_clnt_unref(changelog_rpc_clnt_t *crpc) { - gf_boolean_t gone = _gf_false; - uint64_t ref = 0; + gf_boolean_t gone = _gf_false; + uint64_t ref = 0; - ref = GF_ATOMIC_DEC (crpc->ref); + ref = GF_ATOMIC_DEC(crpc->ref); - if (!ref && changelog_rpc_clnt_is_disconnected (crpc)) { - list_del (&crpc->list); - gone = _gf_true; - } + if (!ref && changelog_rpc_clnt_is_disconnected(crpc)) { + list_del(&crpc->list); + gone = _gf_true; + } - if (gone) - crpc->cleanup (crpc); + if (gone) + crpc->cleanup(crpc); } /** @@ -100,35 +99,38 @@ changelog_rpc_clnt_unref (changelog_rpc_clnt_t *crpc) */ typedef struct changelog_clnt { - xlator_t *this; + xlator_t *this; - /* pending connections */ - pthread_mutex_t pending_lock; - pthread_cond_t pending_cond; - struct list_head pending; + /* pending connections */ + pthread_mutex_t pending_lock; + pthread_cond_t pending_cond; + struct list_head pending; - /* current active connections */ - gf_lock_t active_lock; - struct list_head active; + /* current active connections */ + gf_lock_t active_lock; + struct list_head active; - gf_lock_t wait_lock; - struct list_head waitq; + gf_lock_t wait_lock; + struct list_head waitq; - /* consumer part of rot-buffs */ - rbuf_t *rbuf; - unsigned long sequence; + /* consumer part of rot-buffs */ + rbuf_t *rbuf; + unsigned long sequence; } changelog_clnt_t; -void *changelog_ev_connector (void *); +void * +changelog_ev_connector(void *); -void *changelog_ev_dispatch (void *); +void * +changelog_ev_dispatch(void *); /* APIs */ void -changelog_ev_queue_connection (changelog_clnt_t *, changelog_rpc_clnt_t *); +changelog_ev_queue_connection(changelog_clnt_t *, changelog_rpc_clnt_t *); void -changelog_ev_cleanup_connections (xlator_t *, changelog_clnt_t *); +changelog_ev_cleanup_connections(xlator_t *, changelog_clnt_t *); +void +changelog_process_cleanup_event(xlator_t *); #endif - diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c index 81bd99bcb7d..e561997d858 100644 --- a/xlators/features/changelog/src/changelog-helpers.c +++ b/xlators/features/changelog/src/changelog-helpers.c @@ -8,11 +8,11 @@ cases as published by the Free Software Foundation. */ -#include "xlator.h" -#include "defaults.h" -#include "logging.h" -#include "iobuf.h" -#include "syscall.h" +#include <glusterfs/xlator.h> +#include <glusterfs/defaults.h> +#include <glusterfs/logging.h> +#include <glusterfs/iobuf.h> +#include <glusterfs/syscall.h> #include "changelog-helpers.h" #include "changelog-encoders.h" @@ -22,313 +22,281 @@ #include "changelog-encoders.h" #include "changelog-rpc-common.h" #include <pthread.h> +#include <time.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_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_CANCEL_FAILED, NULL); + goto out; + } + + ret = pthread_join(thr_id, &retval); + if ((ret != 0) || (retval != PTHREAD_CANCELED)) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_PTHREAD_CANCEL_FAILED, NULL); + } - 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; - - ret = LOCK_INIT (&selection->reflock); - if (ret != 0) - return -1; + int ret = 0; + int j = CHANGELOG_EV_SELECTION_RANGE; - LOCK (&selection->reflock); - { - while (j--) { - selection->ref[j] = 0; - } - } - UNLOCK (&selection->reflock); - - return 0; -} - -int -changelog_cleanup_event_selection (xlator_t *this, - changelog_ev_selector_t *selection) -{ - int j = CHANGELOG_EV_SELECTION_RANGE; + ret = LOCK_INIT(&selection->reflock); + if (ret != 0) + return -1; - 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--) { + selection->ref[j] = 0; } - UNLOCK (&selection->reflock); + } + UNLOCK(&selection->reflock); - return LOCK_DESTROY (&selection->reflock); + return 0; } 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, time_t 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; - } - strncpy (changelog_path, buffer, PATH_MAX); - len = strlen (changelog_path); - changelog_path[len] = '\0'; /* redundant */ - - 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; - } - - snprintf (x_value, sizeof x_value, "%lu:%d", - ts, priv->rollover_count); - - if (sys_fsetxattr (priv->htime_fd, HTIME_KEY, x_value, - strlen (x_value), 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, - strlen (x_value), 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_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_HTIME_ERROR, + "reason=fd not available", NULL); + 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_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_HTIME_ERROR, + "reason=write failed", NULL); + ret = -1; + goto out; + } + + len = snprintf(x_value, sizeof(x_value), "%ld:%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, + "reason=xattr updation failed", "XATTR_REPLACE=true", + "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, + "reason=xattr updation failed", "changelog=%s", + changelog_path, NULL); + ret = -1; + goto out; + } + } + + priv->rollover_count += 1; out: - return ret; + return ret; } /* @@ -340,43 +308,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, 1024, 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_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSTAT_OP_FAILED, + NULL); + goto out; + } + + ret = sys_lseek(fd, 0, SEEK_SET); + if (ret == -1) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_LSEEK_OP_FAILED, + NULL); + 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; } /* @@ -388,162 +358,172 @@ out: * -1 : Error */ int -update_path (xlator_t *this, char *cl_path) +update_path(xlator_t *this, char *cl_path) { - char low_cl[] = "changelog"; - 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 { - strncpy(found, low_cl, strlen(low_cl)); - } - - 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_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_PATH_NOT_FOUND, + NULL); + 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, time_t 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; - } - - (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); + int ret = -1; + int notify = 0; + int cl_empty_flag = 0; + struct tm *gmt; + char yyyymmdd[40]; + char ofile[PATH_MAX] = { + 0, + }; + char nfile[PATH_MAX] = { + 0, + }; + char nfile_dir[PATH_MAX] = { + 0, + }; + changelog_event_t ev = { + 0, + }; + + if (priv->changelog_fd != -1) { + ret = sys_fsync(priv->changelog_fd); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_FSYNC_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_MSG_DETECT_EMPTY_CHANGELOG_FAILED, NULL); + } + sys_close(priv->changelog_fd); + priv->changelog_fd = -1; + } + + /* Get GMT time. */ + gmt = gmtime(&ts); + + strftime(yyyymmdd, sizeof(yyyymmdd), "%Y/%m/%d", gmt); + + (void)snprintf(ofile, PATH_MAX, "%s/" CHANGELOG_FILE_NAME, + priv->changelog_dir); + (void)snprintf(nfile, PATH_MAX, "%s/%s/" CHANGELOG_FILE_NAME ".%ld", + priv->changelog_dir, yyyymmdd, ts); + (void)snprintf(nfile_dir, PATH_MAX, "%s/%s", priv->changelog_dir, yyyymmdd); + + if (cl_empty_flag == 1) { + ret = sys_unlink(ofile); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_UNLINK_OP_FAILED, "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); + + /* Changelog file rename gets ENOENT when parent dir doesn't exist */ + if (errno == ENOENT) { + ret = mkdir_p(nfile_dir, 0600, _gf_true); + + if ((ret == -1) && (EEXIST != errno)) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_MKDIR_ERROR, "%s", nfile_dir, NULL); + goto out; + } - 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); - } + ret = sys_rename(ofile, nfile); } - if (!ret && (cl_empty_flag == 0)) { - notify = 1; + if (ret && (errno == ENOENT)) { + ret = 0; + goto out; } - - 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) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_RENAME_ERROR, + "from=%s", ofile, "to=%s", nfile, NULL); } + } + + 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_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_HTIME_ERROR, + NULL); + 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_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_EXPLICIT_ROLLOVER_FAILED, NULL); + } else { + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BNOTIFY_INFO, + "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; } /* @@ -556,306 +536,284 @@ 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) { - strncpy (ht_file_bname, namelist[cnt - 1]->d_name, NAME_MAX); - ht_file_bname[NAME_MAX - 1] = 0; - - 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; - } - } + 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_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_SCAN_DIR_FAILED, + NULL); + } 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_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_FSETXATTR_FAILED, "HTIME_CURRENT", NULL); + ret = -1; + goto out; + } + + if (sys_fsync(ht_dir_fd) < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_FSYNC_OP_FAILED, NULL); + 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, time_t 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, + "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_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FGETXATTR_FAILED, + "name=HTIME_CURRENT", NULL); + + /* 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_smsg(this->name, GF_LOG_INFO, errno, + CHANGELOG_MSG_NO_HTIME_CURRENT, NULL); + sys_close(ht_dir_fd); + return htime_create(this, priv, ts); + } + + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_HTIME_CURRENT_ERROR, NULL); + } + + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_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, + "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_STAT_ERROR, + "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, + "name=%s", HTIME_KEY, "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, + "xattr_total=%lu", total, "size_total=%lu", total1, NULL); + } + + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_TOTAL_LOG_INFO, "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, time_t 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; - } - - /* 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; - } - - /* save this htime_fd in priv->htime_fd */ - priv->htime_fd = ht_file_fd; - /* 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_NEW_HTIME_FILE, + "name=%ld", 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.%ld", 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, + "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_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_XATTR_INIT_FAILED, NULL); + ret = -1; + goto out; + } + + ret = sys_fsync(ht_file_fd); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED, + NULL); + 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, + "path=%s", ht_dir_path, NULL); + ret = -1; + goto out; + } + + (void)snprintf(ht_file_bname, sizeof(ht_file_bname), "%s.%ld", + HTIME_FILE_NAME, ts); + if (sys_fsetxattr(ht_dir_fd, HTIME_CURRENT, ht_file_bname, + strlen(ht_file_bname), 0)) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSETXATTR_FAILED, + " HTIME_CURRENT", NULL); + ret = -1; + goto out; + } + + ret = sys_fsync(ht_dir_fd); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED, + NULL); + goto out; + } + + /* initialize rollover-number in priv to 1 */ + priv->rollover_count = 1; out: - if (ht_dir_fd != -1) - sys_close (ht_dir_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: @@ -867,53 +825,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, + "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; } /* @@ -924,17 +882,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_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_SNAP_INFO, "starting", + NULL); - return ret; + return ret; } /* @@ -945,120 +901,104 @@ 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_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_SNAP_INFO, "Stopped", + NULL); - 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, + "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, time_t 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) +void +changelog_fill_rollover_data(changelog_log_data_t *cld, gf_boolean_t is_last) { - struct timeval tv = {0,}; - - cld->cld_type = CHANGELOG_TYPE_ROLLOVER; - - if (gettimeofday (&tv, NULL)) - return -1; - - cld->cld_roll_time = (unsigned long) tv.tv_sec; - cld->cld_finale = is_last; - return 0; + cld->cld_type = CHANGELOG_TYPE_ROLLOVER; + cld->cld_roll_time = gf_time(); + cld->cld_finale = is_last; } 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); } /* @@ -1071,255 +1011,230 @@ 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_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_WRITE_FAILED, + "csnap", NULL); + } + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_WROTE_TO_CSNAP, NULL); + 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_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_GET_TIME_OP_FAILED, NULL); + 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_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_FSYNC_OP_FAILED, NULL); } + goto out; + } - out: - return ret; + ret = priv->ce->encode(this, cld); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_WRITE_FAILED, + "changelog", NULL); + } + +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; + 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 !!!"); - /** - * 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; - } + 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, + "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, "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, + "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); - 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); + 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, + "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); - 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, "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, + "error=%d", ret, NULL); + pthread_cleanup_pop(0); + gf_msg_debug(this->name, 0, "Woke up: Conditional wait on white fops"); } /** @@ -1327,193 +1242,194 @@ 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); - } + 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 = gf_time() + 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_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO, + NULL); + priv->explicit_rollover = _gf_true; + } else if (ret && ret != ETIMEDOUT) { + gf_smsg(this->name, GF_LOG_ERROR, errno, + CHANGELOG_MSG_SELECT_FAILED, NULL); + 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); - /* 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; - } + changelog_fill_rollover_data(&cld, _gf_false); - _mask_cancellation (); + _mask_cancellation(); - LOCK (&priv->lock); - { - ret = changelog_inject_single_event (this, priv, &cld); - if (!ret) - SLICE_VERSION_UPDATE (slice); - } - UNLOCK (&priv->lock); - - _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_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_INJECT_FSYNC_FAILED, NULL); - _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)(uintptr_t)ctx; + return __inode_ctx_set(inode, this, &ctx_addr); } /** @@ -1521,56 +1437,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; } /** @@ -1674,59 +1587,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 */ @@ -1742,230 +1653,221 @@ 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, + "type=parent", "gfid=%s", uuid_utoa(loc->inode->gfid), NULL); + goto err; + } + + CHANGELOG_INIT_NOCHECK(this, *local, loc->inode, loc->inode->gfid, 5); + if (!(*local)) { + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_LOCAL_INIT_FAILED, + NULL); + goto err; + } + + co = changelog_get_usable_buffer(*local); + if (!co) { + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_GET_BUFFER_FAILED, + NULL); + 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; } /* @@ -1978,89 +1880,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; - } - strncpy (pre_dir_name, result, sizeof(pre_dir_name)); + 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-helpers.h b/xlators/features/changelog/src/changelog-helpers.h index 1551337c16f..38fa7590c32 100644 --- a/xlators/features/changelog/src/changelog-helpers.h +++ b/xlators/features/changelog/src/changelog-helpers.h @@ -11,14 +11,14 @@ #ifndef _CHANGELOG_HELPERS_H #define _CHANGELOG_HELPERS_H -#include "locking.h" -#include "timer.h" +#include <glusterfs/locking.h> +#include <glusterfs/timer.h> #include "pthread.h" -#include "iobuf.h" -#include "rot-buffs.h" +#include <glusterfs/iobuf.h> +#include <glusterfs/rot-buffs.h> #include "changelog-misc.h" -#include "call-stub.h" +#include <glusterfs/call-stub.h> #include "rpcsvc.h" #include "changelog-ev-handle.h" @@ -30,44 +30,44 @@ * the changelog entry */ typedef struct changelog_log_data { - /* rollover related */ - unsigned long cld_roll_time; + /* rollover related */ + time_t cld_roll_time; - /* reopen changelog? */ - gf_boolean_t cld_finale; + /* reopen changelog? */ + gf_boolean_t cld_finale; - changelog_log_type cld_type; + changelog_log_type cld_type; - /** - * sincd gfid is _always_ a necessity, it's not a part - * of the iobuf. by doing this we do not add any overhead - * for data and metadata related fops. - */ - uuid_t cld_gfid; + /** + * sincd gfid is _always_ a necessity, it's not a part + * of the iobuf. by doing this we do not add any overhead + * for data and metadata related fops. + */ + uuid_t cld_gfid; - /** - * iobufs are used for optionals records: pargfid, path, - * write offsets etc.. It's the fop implementers job - * to allocate (iobuf_get() in the fop) and get unref'ed - * in the callback (CHANGELOG_STACK_UNWIND). - */ - struct iobuf *cld_iobuf; + /** + * iobufs are used for optionals records: pargfid, path, + * write offsets etc.. It's the fop implementers job + * to allocate (iobuf_get() in the fop) and get unref'ed + * in the callback (CHANGELOG_STACK_UNWIND). + */ + struct iobuf *cld_iobuf; #define cld_ptr cld_iobuf->ptr - /** - * after allocation you can point this to the length of - * usable data, but make sure it does not exceed the - * the size of the requested iobuf. - */ - size_t cld_iobuf_len; + /** + * after allocation you can point this to the length of + * usable data, but make sure it does not exceed the + * the size of the requested iobuf. + */ + size_t cld_iobuf_len; #define cld_ptr_len cld_iobuf_len - /** - * number of optional records - */ - int cld_xtra_records; + /** + * number of optional records + */ + int cld_xtra_records; } changelog_log_data_t; /** @@ -77,55 +77,48 @@ typedef struct changelog_log_data { typedef struct changelog_priv changelog_priv_t; typedef struct changelog_dispatcher { - void *cd_data; - int (*dispatchfn) (xlator_t *, changelog_priv_t *, void *, - changelog_log_data_t *, changelog_log_data_t *); + void *cd_data; + int (*dispatchfn)(xlator_t *, changelog_priv_t *, void *, + changelog_log_data_t *, changelog_log_data_t *); } changelog_dispatcher_t; struct changelog_bootstrap { - changelog_mode_t mode; - int (*ctor) (xlator_t *, changelog_dispatcher_t *); - int (*dtor) (xlator_t *, changelog_dispatcher_t *); + changelog_mode_t mode; + int (*ctor)(xlator_t *, changelog_dispatcher_t *); + int (*dtor)(xlator_t *, changelog_dispatcher_t *); }; struct changelog_encoder { - changelog_encoder_t encoder; - int (*encode) (xlator_t *, changelog_log_data_t *); + changelog_encoder_t encoder; + int (*encode)(xlator_t *, changelog_log_data_t *); }; - /* xlator private */ typedef struct changelog_time_slice { - /** - * just in case we need nanosecond granularity some day. - * field is unused as of now (maybe we'd need it later). - */ - struct timeval tv_start; - - /** - * version of changelog file, incremented each time changes - * rollover. - */ - unsigned long changelog_version[CHANGELOG_MAX_TYPE]; + /** + * version of changelog file, incremented each time changes + * rollover. + */ + unsigned long changelog_version[CHANGELOG_MAX_TYPE]; } changelog_time_slice_t; typedef struct changelog_rollover { - /* rollover thread */ - pthread_t rollover_th; + /* rollover thread */ + pthread_t rollover_th; - xlator_t *this; + xlator_t *this; - pthread_mutex_t lock; - pthread_cond_t cond; - gf_boolean_t notify; + pthread_mutex_t lock; + pthread_cond_t cond; + gf_boolean_t notify; } changelog_rollover_t; typedef struct changelog_fsync { - /* fsync() thread */ - pthread_t fsync_th; + /* fsync() thread */ + pthread_t fsync_th; - xlator_t *this; + xlator_t *this; } changelog_fsync_t; /* Draining during changelog rollover (for geo-rep snapshot dependency): @@ -145,198 +138,219 @@ typedef struct changelog_fsync { */ typedef enum chlog_fop_color { - FOP_COLOR_BLACK, - FOP_COLOR_WHITE + FOP_COLOR_BLACK, + FOP_COLOR_WHITE } chlog_fop_color_t; /* Barrier notify variable */ typedef struct barrier_notify { - pthread_mutex_t bnotify_mutex; - pthread_cond_t bnotify_cond; - gf_boolean_t bnotify; - gf_boolean_t bnotify_error; + pthread_mutex_t bnotify_mutex; + pthread_cond_t bnotify_cond; + gf_boolean_t bnotify; + gf_boolean_t bnotify_error; } barrier_notify_t; /* Two separate mutex and conditional variable set is used * to drain white and black fops. */ typedef struct drain_mgmt { - pthread_mutex_t drain_black_mutex; - pthread_cond_t drain_black_cond; - pthread_mutex_t drain_white_mutex; - pthread_cond_t drain_white_cond; - /* Represents black fops count in-transit */ - unsigned long black_fop_cnt; - /* Represents white fops count in-transit */ - unsigned long white_fop_cnt; - gf_boolean_t drain_wait_black; - gf_boolean_t drain_wait_white; + pthread_mutex_t drain_black_mutex; + pthread_cond_t drain_black_cond; + pthread_mutex_t drain_white_mutex; + pthread_cond_t drain_white_cond; + /* Represents black fops count in-transit */ + unsigned long black_fop_cnt; + /* Represents white fops count in-transit */ + unsigned long white_fop_cnt; + gf_boolean_t drain_wait_black; + gf_boolean_t drain_wait_white; } drain_mgmt_t; /* External barrier as a result of snap on/off indicating flag*/ typedef struct barrier_flags { - gf_lock_t lock; - gf_boolean_t barrier_ext; + gf_lock_t lock; + gf_boolean_t barrier_ext; } barrier_flags_t; /* Event selection */ typedef struct changelog_ev_selector { - gf_lock_t reflock; + gf_lock_t reflock; - /** - * Array of references for each selection bit. - */ - unsigned int ref[CHANGELOG_EV_SELECTION_RANGE]; + /** + * Array of references for each selection bit. + */ + unsigned int ref[CHANGELOG_EV_SELECTION_RANGE]; } changelog_ev_selector_t; - /* changelog's private structure */ struct changelog_priv { - gf_boolean_t active; + /* changelog journalling */ + gf_boolean_t active; + + /* changelog live notifications */ + gf_boolean_t rpc_active; + + /* to generate unique socket file per brick */ + char *changelog_brick; + + /* logging directory */ + char *changelog_dir; - /* to generate unique socket file per brick */ - char *changelog_brick; + /* htime directory */ + char *htime_dir; - /* logging directory */ - char *changelog_dir; + /* one file for all changelog types */ + int changelog_fd; - /* htime directory */ - char *htime_dir; + /* htime fd for current changelog session */ + int htime_fd; - /* one file for all changelog types */ - int changelog_fd; + /* c_snap_fd is fd for call-path changelog */ + int c_snap_fd; - /* htime fd for current changelog session */ - int htime_fd; + /* rollover_count used by htime */ + int rollover_count; - /* c_snap_fd is fd for call-path changelog */ - int c_snap_fd; + gf_lock_t lock; - /* rollover_count used by htime */ - int rollover_count; + /* lock to synchronize CSNAP updation */ + gf_lock_t c_snap_lock; - gf_lock_t lock; + /* written end of the pipe */ + int wfd; - /* lock to synchronize CSNAP updation */ - gf_lock_t c_snap_lock; + /* rollover time */ + int32_t rollover_time; - /* written end of the pipe */ - int wfd; + /* fsync() interval */ + int32_t fsync_interval; - /* rollover time */ - int32_t rollover_time; + /* changelog type maps */ + const char *maps[CHANGELOG_MAX_TYPE]; - /* fsync() interval */ - int32_t fsync_interval; + /* time slicer */ + changelog_time_slice_t slice; - /* changelog type maps */ - const char *maps[CHANGELOG_MAX_TYPE]; + /* context of the updater */ + changelog_dispatcher_t cd; - /* time slicer */ - changelog_time_slice_t slice; + /* context of the rollover thread */ + changelog_rollover_t cr; - /* context of the updater */ - changelog_dispatcher_t cd; + /* context of fsync thread */ + changelog_fsync_t cf; - /* context of the rollover thread */ - changelog_rollover_t cr; + /* operation mode */ + changelog_mode_t op_mode; - /* context of fsync thread */ - changelog_fsync_t cf; + /* bootstrap routine for 'current' logger */ + struct changelog_bootstrap *cb; - /* operation mode */ - changelog_mode_t op_mode; + /* encoder mode */ + changelog_encoder_t encode_mode; - /* bootstrap routine for 'current' logger */ - struct changelog_bootstrap *cb; + /* encoder */ + struct changelog_encoder *ce; - /* encoder mode */ - changelog_encoder_t encode_mode; + /** + * snapshot dependency changes + */ - /* encoder */ - struct changelog_encoder *ce; + /* Draining of fops*/ + drain_mgmt_t dm; - /** - * snapshot dependency changes - */ + /* Represents the active color. Initially by default black */ + chlog_fop_color_t current_color; - /* Draining of fops*/ - drain_mgmt_t dm; + /* flag to determine explicit rollover is triggered */ + gf_boolean_t explicit_rollover; - /* Represents the active color. Initially by default black */ - chlog_fop_color_t current_color; + /* barrier notification variable protected by mutex */ + barrier_notify_t bn; - /* flag to determine explicit rollover is triggered */ - gf_boolean_t explicit_rollover; + /* barrier on/off indicating flags */ + barrier_flags_t bflags; - /* barrier notification variable protected by mutex */ - barrier_notify_t bn; + /* changelog barrier on/off indicating flag */ + gf_boolean_t barrier_enabled; + struct list_head queue; + uint32_t queue_size; + gf_timer_t *timer; + struct timespec timeout; - /* barrier on/off indicating flags */ - barrier_flags_t bflags; + /** + * buffers, RPC, event selection, notifications and other + * beasts. + */ - /* changelog barrier on/off indicating flag */ - gf_boolean_t barrier_enabled; - struct list_head queue; - uint32_t queue_size; - gf_timer_t *timer; - struct timespec timeout; + /* epoll pthread */ + pthread_t poller; - /** - * buffers, RPC, event selection, notifications and other - * beasts. - */ + /* rotational buffer */ + rbuf_t *rbuf; - /* epoll pthread */ - pthread_t poller; + /* changelog RPC server */ + rpcsvc_t *rpc; - /* rotational buffer */ - rbuf_t *rbuf; + /* event selection */ + changelog_ev_selector_t ev_selection; - /* changelog RPC server */ - rpcsvc_t *rpc; + /* client handling (reverse connection) */ + pthread_t connector; - /* event selection */ - changelog_ev_selector_t ev_selection; + int nr_dispatchers; + pthread_t *ev_dispatcher; - /* client handling (reverse connection) */ - pthread_t connector; + changelog_clnt_t connections; - int nr_dispatchers; - pthread_t *ev_dispatcher; + /* glusterfind dependency to capture paths on deleted entries*/ + gf_boolean_t capture_del_path; - changelog_clnt_t connections; + /* Save total no. of listners */ + gf_atomic_t listnercnt; - /* glusterfind dependency to capture paths on deleted entries*/ - gf_boolean_t capture_del_path; + /* Save total no. of xprt are associated with listner */ + gf_atomic_t xprtcnt; + + /* Save xprt list */ + struct list_head xprt_list; + + /* Save total no. of client connection */ + gf_atomic_t clntcnt; + + /* Save cleanup brick in victim */ + xlator_t *victim; + + /* Status to save cleanup notify status */ + gf_boolean_t notify_down; }; struct changelog_local { - inode_t *inode; - gf_boolean_t update_no_check; + inode_t *inode; + gf_boolean_t update_no_check; - changelog_log_data_t cld; + changelog_log_data_t cld; - /** - * ->prev_entry is used in cases when there needs to be - * additional changelog entry for the parent (eg. rename) - * It's analogous to ->next in single linked list world, - * but we call it as ->prev_entry... ha ha ha - */ - struct changelog_local *prev_entry; + /** + * ->prev_entry is used in cases when there needs to be + * additional changelog entry for the parent (eg. rename) + * It's analogous to ->next in single linked list world, + * but we call it as ->prev_entry... ha ha ha + */ + struct changelog_local *prev_entry; - /* snap dependency changes */ - chlog_fop_color_t color; + /* snap dependency changes */ + chlog_fop_color_t color; }; typedef struct changelog_local changelog_local_t; /* inode version is stored in inode ctx */ typedef struct changelog_inode_ctx { - unsigned long iversion[CHANGELOG_MAX_TYPE]; + unsigned long iversion[CHANGELOG_MAX_TYPE]; } changelog_inode_ctx_t; -#define CHANGELOG_INODE_VERSION_TYPE(ctx, type) &(ctx->iversion[type]) +#define CHANGELOG_INODE_VERSION_TYPE(ctx, type) &(ctx->iversion[type]) /** * Optional Records: @@ -344,269 +358,276 @@ typedef struct changelog_inode_ctx { * @changelog_opt_t struct. The array is allocated via @iobufs. */ typedef enum { - CHANGELOG_OPT_REC_FOP, - CHANGELOG_OPT_REC_ENTRY, - CHANGELOG_OPT_REC_UINT32, + CHANGELOG_OPT_REC_FOP, + CHANGELOG_OPT_REC_ENTRY, + CHANGELOG_OPT_REC_UINT32, } changelog_optional_rec_type_t; struct changelog_entry_fields { - uuid_t cef_uuid; - char *cef_bname; - char *cef_path; + uuid_t cef_uuid; + char *cef_bname; + char *cef_path; }; typedef struct { - /** - * @co_covert can be used to do post-processing of the record before - * it's persisted to the CHANGELOG. If this is NULL, then the record - * is persisted as per it's in memory format. - */ - size_t (*co_convert) (void *data, char *buffer, gf_boolean_t encode); - - /* release routines */ - void (*co_free) (void *data); - - /* type of the field */ - changelog_optional_rec_type_t co_type; - - /** - * sizeof of the 'valid' field in the union. This field is not used if - * @co_convert is specified. - */ - size_t co_len; - - union { - unsigned int co_uint32; - glusterfs_fop_t co_fop; - struct changelog_entry_fields co_entry; - }; + /** + * @co_covert can be used to do post-processing of the record before + * it's persisted to the CHANGELOG. If this is NULL, then the record + * is persisted as per it's in memory format. + */ + size_t (*co_convert)(void *data, char *buffer, gf_boolean_t encode); + + /* release routines */ + void (*co_free)(void *data); + + /* type of the field */ + changelog_optional_rec_type_t co_type; + + /** + * sizeof of the 'valid' field in the union. This field is not used if + * @co_convert is specified. + */ + size_t co_len; + + union { + unsigned int co_uint32; + glusterfs_fop_t co_fop; + struct changelog_entry_fields co_entry; + }; } changelog_opt_t; -#define CHANGELOG_OPT_RECORD_LEN sizeof (changelog_opt_t) +#define CHANGELOG_OPT_RECORD_LEN sizeof(changelog_opt_t) /** * helpers routines */ int -changelog_thread_cleanup (xlator_t *this, pthread_t thr_id); +changelog_thread_cleanup(xlator_t *this, pthread_t thr_id); void * -changelog_get_usable_buffer (changelog_local_t *local); +changelog_get_usable_buffer(changelog_local_t *local); 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); void -changelog_local_cleanup (xlator_t *xl, changelog_local_t *local); +changelog_local_cleanup(xlator_t *xl, changelog_local_t *local); changelog_local_t * -changelog_local_init (xlator_t *this, inode_t *inode, uuid_t gfid, - int xtra_records, gf_boolean_t update_flag); -int -changelog_start_next_change (xlator_t *this, - changelog_priv_t *priv, - unsigned long ts, gf_boolean_t finale); +changelog_local_init(xlator_t *this, inode_t *inode, uuid_t gfid, + int xtra_records, gf_boolean_t update_flag); int -changelog_open_journal (xlator_t *this, changelog_priv_t *priv); +changelog_start_next_change(xlator_t *this, changelog_priv_t *priv, time_t ts, + gf_boolean_t finale); int -changelog_fill_rollover_data (changelog_log_data_t *cld, gf_boolean_t is_last); +changelog_open_journal(xlator_t *this, changelog_priv_t *priv); +void +changelog_fill_rollover_data(changelog_log_data_t *cld, gf_boolean_t is_last); int -changelog_inject_single_event (xlator_t *this, - changelog_priv_t *priv, - changelog_log_data_t *cld); +changelog_inject_single_event(xlator_t *this, changelog_priv_t *priv, + changelog_log_data_t *cld); size_t -changelog_entry_length (); +changelog_entry_length(); int -changelog_write (int fd, char *buffer, size_t len); +changelog_write(int fd, char *buffer, size_t 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); 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); void -changelog_update (xlator_t *this, changelog_priv_t *priv, - changelog_local_t *local, changelog_log_type type); +changelog_update(xlator_t *this, changelog_priv_t *priv, + changelog_local_t *local, changelog_log_type type); void * -changelog_rollover (void *data); +changelog_rollover(void *data); void * -changelog_fsync_thread (void *data); +changelog_fsync_thread(void *data); int -changelog_forget (xlator_t *this, inode_t *inode); +changelog_forget(xlator_t *this, inode_t *inode); int -htime_update (xlator_t *this, changelog_priv_t *priv, - unsigned long ts, char * buffer); +htime_update(xlator_t *this, changelog_priv_t *priv, time_t ts, char *buffer); int -htime_open (xlator_t *this, changelog_priv_t *priv, unsigned long ts); +htime_open(xlator_t *this, changelog_priv_t *priv, time_t ts); int -htime_create (xlator_t *this, changelog_priv_t *priv, unsigned long ts); +htime_create(xlator_t *this, changelog_priv_t *priv, time_t ts); /* Geo-Rep snapshot dependency changes */ 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); 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); 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 -changelog_barrier_notify (changelog_priv_t *priv, char* buf); +changelog_barrier_notify(changelog_priv_t *priv, char *buf); 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); void -changelog_drain_white_fops (xlator_t *this, changelog_priv_t *priv); +changelog_drain_white_fops(xlator_t *this, changelog_priv_t *priv); void -changelog_drain_black_fops (xlator_t *this, changelog_priv_t *priv); +changelog_drain_black_fops(xlator_t *this, changelog_priv_t *priv); /* Crash consistency of changelog wrt snapshot */ int -changelog_snap_logging_stop ( xlator_t *this, changelog_priv_t *priv); +changelog_snap_logging_stop(xlator_t *this, changelog_priv_t *priv); int -changelog_snap_logging_start ( xlator_t *this, changelog_priv_t *priv); +changelog_snap_logging_start(xlator_t *this, changelog_priv_t *priv); int -changelog_snap_open ( xlator_t *this, changelog_priv_t *priv); +changelog_snap_open(xlator_t *this, changelog_priv_t *priv); 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); 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); /* Changelog barrier routines */ -void __chlog_barrier_enqueue (xlator_t *this, call_stub_t *stub); -void __chlog_barrier_disable (xlator_t *this, struct list_head *queue); -void chlog_barrier_dequeue_all (xlator_t *this, struct list_head *queue); -call_stub_t *__chlog_barrier_dequeue (xlator_t *this, struct list_head *queue); -int __chlog_barrier_enable (xlator_t *this, changelog_priv_t *priv); +void +__chlog_barrier_enqueue(xlator_t *this, call_stub_t *stub); +void +__chlog_barrier_disable(xlator_t *this, struct list_head *queue); +void +chlog_barrier_dequeue_all(xlator_t *this, struct list_head *queue); +call_stub_t * +__chlog_barrier_dequeue(xlator_t *this, struct list_head *queue); +int +__chlog_barrier_enable(xlator_t *this, changelog_priv_t *priv); 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); /* event selection routines */ -void changelog_select_event (xlator_t *, - changelog_ev_selector_t *, unsigned int); -void changelog_deselect_event (xlator_t *, - changelog_ev_selector_t *, unsigned int); -int changelog_init_event_selection (xlator_t *, - changelog_ev_selector_t *); -int changelog_cleanup_event_selection (xlator_t *, - changelog_ev_selector_t *); -int changelog_ev_selected (xlator_t *, - changelog_ev_selector_t *, unsigned int); void -changelog_dispatch_event (xlator_t *, changelog_priv_t *, changelog_event_t *); +changelog_select_event(xlator_t *, changelog_ev_selector_t *, unsigned int); +void +changelog_deselect_event(xlator_t *, changelog_ev_selector_t *, unsigned int); +int +changelog_init_event_selection(xlator_t *, changelog_ev_selector_t *); +int +changelog_ev_selected(xlator_t *, changelog_ev_selector_t *, unsigned int); +void +changelog_dispatch_event(xlator_t *, changelog_priv_t *, changelog_event_t *); changelog_inode_ctx_t * -__changelog_inode_ctx_get (xlator_t *, inode_t *, unsigned long **, - unsigned long *, changelog_log_type); +__changelog_inode_ctx_get(xlator_t *, inode_t *, unsigned long **, + unsigned long *, changelog_log_type); int -resolve_pargfid_to_path (xlator_t *this, const uuid_t gfid, char **path, - char *bname); +resolve_pargfid_to_path(xlator_t *this, const uuid_t gfid, char **path, + char *bname); /* macros */ -#define CHANGELOG_STACK_UNWIND(fop, frame, params ...) do { \ - changelog_local_t *__local = NULL; \ - xlator_t *__xl = NULL; \ - if (frame) { \ - __local = frame->local; \ - __xl = frame->this; \ - frame->local = NULL; \ - } \ - STACK_UNWIND_STRICT (fop, frame, params); \ - if (__local && __local->prev_entry) \ - changelog_local_cleanup (__xl, \ - __local->prev_entry); \ - changelog_local_cleanup (__xl, __local); \ - } while (0) - -#define CHANGELOG_IOBUF_REF(iobuf) do { \ - if (iobuf) \ - iobuf_ref (iobuf); \ - } while (0) - -#define CHANGELOG_IOBUF_UNREF(iobuf) do { \ - if (iobuf) \ - iobuf_unref (iobuf); \ - } while (0) - -#define CHANGELOG_FILL_BUFFER(buffer, off, val, len) do { \ - memcpy (buffer + off, val, len); \ - off += len; \ - } while (0) - -#define SLICE_VERSION_UPDATE(slice) do { \ - int i = 0; \ - for (; i < CHANGELOG_MAX_TYPE; i++) { \ - slice->changelog_version[i]++; \ - } \ - } while (0) - -#define CHANGELOG_FILL_UINT32(co, number, converter, xlen) do { \ - co->co_convert = converter; \ - co->co_free = NULL; \ - co->co_type = CHANGELOG_OPT_REC_UINT32; \ - co->co_uint32 = number; \ - xlen += sizeof (unsigned int); \ - } while (0) - -#define CHANGLOG_FILL_FOP_NUMBER(co, fop, converter, xlen) do { \ - co->co_convert = converter; \ - co->co_free = NULL; \ - co->co_type = CHANGELOG_OPT_REC_FOP; \ - co->co_fop = fop; \ - xlen += sizeof (fop); \ - } while (0) - -#define CHANGELOG_FILL_ENTRY(co, pargfid, bname, \ - converter, freefn, xlen, label) \ - do { \ - co->co_convert = converter; \ - co->co_free = freefn; \ - co->co_type = CHANGELOG_OPT_REC_ENTRY; \ - gf_uuid_copy (co->co_entry.cef_uuid, pargfid); \ - co->co_entry.cef_bname = gf_strdup(bname); \ - if (!co->co_entry.cef_bname) \ - goto label; \ - xlen += (UUID_CANONICAL_FORM_LEN + strlen (bname)); \ - } while (0) - -#define CHANGELOG_FILL_ENTRY_DIR_PATH(co, pargfid, bname, converter, \ - del_freefn, xlen, label, capture_del) \ - do { \ - co->co_convert = converter; \ - co->co_free = del_freefn; \ - co->co_type = CHANGELOG_OPT_REC_ENTRY; \ - gf_uuid_copy (co->co_entry.cef_uuid, pargfid); \ - co->co_entry.cef_bname = gf_strdup(bname); \ - if (!co->co_entry.cef_bname) \ - goto label; \ - xlen += (UUID_CANONICAL_FORM_LEN + strlen (bname)); \ - if (!capture_del || resolve_pargfid_to_path (this, pargfid, \ - &(co->co_entry.cef_path), co->co_entry.cef_bname)) { \ - co->co_entry.cef_path = gf_strdup ("\0"); \ - xlen += 1; \ - } else { \ - xlen += (strlen (co->co_entry.cef_path)); \ - } \ - } while (0) - -#define CHANGELOG_INIT(this, local, inode, gfid, xrec) \ - local = changelog_local_init (this, inode, gfid, xrec, _gf_false) - -#define CHANGELOG_INIT_NOCHECK(this, local, inode, gfid, xrec) \ - local = changelog_local_init (this, inode, gfid, xrec, _gf_true) - -#define CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, label) do { \ - if (!priv->active) \ - goto label; \ - /* ignore rebalance process's activity. */ \ - if ((frame->root->pid == GF_CLIENT_PID_DEFRAG) || \ - (frame->root->pid == GF_CLIENT_PID_TIER_DEFRAG)) \ - goto label; \ - } while (0) +#define CHANGELOG_STACK_UNWIND(fop, frame, params...) \ + do { \ + changelog_local_t *__local = NULL; \ + xlator_t *__xl = NULL; \ + if (frame) { \ + __local = frame->local; \ + __xl = frame->this; \ + frame->local = NULL; \ + } \ + STACK_UNWIND_STRICT(fop, frame, params); \ + if (__local && __local->prev_entry) \ + changelog_local_cleanup(__xl, __local->prev_entry); \ + changelog_local_cleanup(__xl, __local); \ + } while (0) + +#define CHANGELOG_IOBUF_REF(iobuf) \ + do { \ + if (iobuf) \ + iobuf_ref(iobuf); \ + } while (0) + +#define CHANGELOG_IOBUF_UNREF(iobuf) \ + do { \ + if (iobuf) \ + iobuf_unref(iobuf); \ + } while (0) + +#define CHANGELOG_FILL_BUFFER(buffer, off, val, len) \ + do { \ + memcpy(buffer + off, val, len); \ + off += len; \ + } while (0) + +#define SLICE_VERSION_UPDATE(slice) \ + do { \ + int i = 0; \ + for (; i < CHANGELOG_MAX_TYPE; i++) { \ + slice->changelog_version[i]++; \ + } \ + } while (0) + +#define CHANGELOG_FILL_UINT32(co, number, converter, xlen) \ + do { \ + co->co_convert = converter; \ + co->co_free = NULL; \ + co->co_type = CHANGELOG_OPT_REC_UINT32; \ + co->co_uint32 = number; \ + xlen += sizeof(unsigned int); \ + } while (0) + +#define CHANGLOG_FILL_FOP_NUMBER(co, fop, converter, xlen) \ + do { \ + co->co_convert = converter; \ + co->co_free = NULL; \ + co->co_type = CHANGELOG_OPT_REC_FOP; \ + co->co_fop = fop; \ + xlen += sizeof(fop); \ + } while (0) + +#define CHANGELOG_FILL_ENTRY(co, pargfid, bname, converter, freefn, xlen, \ + label) \ + do { \ + co->co_convert = converter; \ + co->co_free = freefn; \ + co->co_type = CHANGELOG_OPT_REC_ENTRY; \ + gf_uuid_copy(co->co_entry.cef_uuid, pargfid); \ + co->co_entry.cef_bname = gf_strdup(bname); \ + if (!co->co_entry.cef_bname) \ + goto label; \ + xlen += (UUID_CANONICAL_FORM_LEN + strlen(bname)); \ + } while (0) + +#define CHANGELOG_FILL_ENTRY_DIR_PATH(co, pargfid, bname, converter, \ + del_freefn, xlen, label, capture_del) \ + do { \ + co->co_convert = converter; \ + co->co_free = del_freefn; \ + co->co_type = CHANGELOG_OPT_REC_ENTRY; \ + gf_uuid_copy(co->co_entry.cef_uuid, pargfid); \ + co->co_entry.cef_bname = gf_strdup(bname); \ + if (!co->co_entry.cef_bname) \ + goto label; \ + xlen += (UUID_CANONICAL_FORM_LEN + strlen(bname)); \ + if (!capture_del || \ + resolve_pargfid_to_path(this, pargfid, &(co->co_entry.cef_path), \ + co->co_entry.cef_bname)) { \ + co->co_entry.cef_path = gf_strdup("\0"); \ + xlen += 1; \ + } else { \ + xlen += (strlen(co->co_entry.cef_path)); \ + } \ + } while (0) + +#define CHANGELOG_INIT(this, local, inode, gfid, xrec) \ + local = changelog_local_init(this, inode, gfid, xrec, _gf_false) + +#define CHANGELOG_INIT_NOCHECK(this, local, inode, gfid, xrec) \ + local = changelog_local_init(this, inode, gfid, xrec, _gf_true) + +#define CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, label) \ + do { \ + if (!priv->active) \ + goto label; \ + /* ignore rebalance process's activity. */ \ + if ((frame->root->pid == GF_CLIENT_PID_DEFRAG) || \ + (frame->root->pid == GF_CLIENT_PID_TIER_DEFRAG)) \ + goto label; \ + } while (0) /* If it is a METADATA entry and fop num being GF_FOP_NULL, don't * log in the changelog as it is of no use. And also if it is @@ -615,78 +636,80 @@ resolve_pargfid_to_path (xlator_t *this, const uuid_t gfid, char **path, * to same changelog will be missed. Hence check for boundary * condition. */ -#define CHANGELOG_OP_BOUNDARY_CHECK(frame, label) do { \ - if (frame->root->op <= GF_FOP_NULL || \ - frame->root->op >= GF_FOP_MAXVALUE) \ - goto label; \ - } while (0) +#define CHANGELOG_OP_BOUNDARY_CHECK(frame, label) \ + do { \ + if (frame->root->op <= GF_FOP_NULL || \ + frame->root->op >= GF_FOP_MAXVALUE) \ + goto label; \ + } while (0) /** * ignore internal fops for all clients except AFR self-heal daemon */ -#define CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, dict, label) do { \ - if ((frame->root->pid != GF_CLIENT_PID_SELF_HEALD) \ - && dict \ - && dict_get (dict, GLUSTERFS_INTERNAL_FOP_KEY)) \ - goto label; \ - } while (0) - -#define CHANGELOG_COND_GOTO(priv, cond, label) do { \ - if (!priv->active || cond) \ - goto label; \ - } while (0) +#define CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, dict, label) \ + do { \ + if ((frame->root->pid != GF_CLIENT_PID_SELF_HEALD) && dict && \ + dict_get(dict, GLUSTERFS_INTERNAL_FOP_KEY)) \ + goto label; \ + } while (0) + +#define CHANGELOG_COND_GOTO(priv, cond, label) \ + do { \ + if (!priv->active || cond) \ + goto label; \ + } while (0) /* Begin: Geo-Rep snapshot dependency changes */ -#define DICT_ERROR -1 -#define BARRIER_OFF 0 -#define BARRIER_ON 1 -#define DICT_DEFAULT 2 - -#define CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, label) do { \ - if (!priv->active) { \ - gf_msg (this->name, GF_LOG_WARNING, 0, \ - CHANGELOG_MSG_NOT_ACTIVE, \ - "Changelog is not active, return success"); \ - ret = 0; \ - goto label; \ - } \ - } while (0) +#define DICT_ERROR -1 +#define BARRIER_OFF 0 +#define BARRIER_ON 1 +#define DICT_DEFAULT 2 + +#define CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, label) \ + do { \ + if (!priv->active) { \ + gf_smsg(this->name, GF_LOG_WARNING, 0, \ + CHANGELOG_MSG_CHANGELOG_NOT_ACTIVE, NULL); \ + ret = 0; \ + goto label; \ + } \ + } while (0) /* Log pthread error and goto label */ -#define CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, label) do { \ - if (ret) { \ - gf_smsg (this->name, GF_LOG_ERROR, \ - 0, CHANGELOG_MSG_PTHREAD_ERROR, \ - "pthread error", "error=%d", ret, NULL); \ - ret = -1; \ - goto label; \ - } \ - } while (0); +#define CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, label) \ + do { \ + if (ret) { \ + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_PTHREAD_ERROR, \ + "error=%d", ret, NULL); \ + ret = -1; \ + goto label; \ + } \ + } while (0); /* Log pthread error, set flag and goto label */ -#define CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret, label, flag) do { \ - if (ret) { \ - gf_smsg (this->name, GF_LOG_ERROR, 0, \ - CHANGELOG_MSG_PTHREAD_ERROR, \ - "pthread error", "error=%d", ret, NULL); \ - ret = -1; \ - flag = _gf_true; \ - goto label; \ - } \ - } while (0) +#define CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret, label, flag) \ + do { \ + if (ret) { \ + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_PTHREAD_ERROR, \ + "error=%d", ret, NULL); \ + ret = -1; \ + flag = _gf_true; \ + goto label; \ + } \ + } while (0) /* Log pthread error, unlock mutex and goto label */ -#define CHANGELOG_PTHREAD_ERROR_HANDLE_2(ret, label, mutex) do { \ - if (ret) { \ - gf_smsg (this->name, GF_LOG_ERROR, \ - 0, CHANGELOG_MSG_PTHREAD_ERROR, \ - "pthread error", "error=%d", ret, NULL); \ - ret = -1; \ - pthread_mutex_unlock (&mutex); \ - goto label; \ - } \ - } while (0) +#define CHANGELOG_PTHREAD_ERROR_HANDLE_2(ret, label, mutex) \ + do { \ + if (ret) { \ + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_PTHREAD_ERROR, \ + "error=%d", ret, NULL); \ + ret = -1; \ + pthread_mutex_unlock(&mutex); \ + goto label; \ + } \ + } while (0) /* End: Geo-Rep snapshot dependency changes */ diff --git a/xlators/features/changelog/src/changelog-mem-types.h b/xlators/features/changelog/src/changelog-mem-types.h index 33fea31b979..a2d8a9cbe93 100644 --- a/xlators/features/changelog/src/changelog-mem-types.h +++ b/xlators/features/changelog/src/changelog-mem-types.h @@ -11,24 +11,24 @@ #ifndef _CHANGELOG_MEM_TYPES_H #define _CHANGELOG_MEM_TYPES_H -#include "mem-types.h" +#include <glusterfs/mem-types.h> enum gf_changelog_mem_types { - gf_changelog_mt_priv_t = gf_common_mt_end + 1, - gf_changelog_mt_str_t = gf_common_mt_end + 2, - gf_changelog_mt_batch_t = gf_common_mt_end + 3, - gf_changelog_mt_rt_t = gf_common_mt_end + 4, - gf_changelog_mt_inode_ctx_t = gf_common_mt_end + 5, - gf_changelog_mt_rpc_clnt_t = gf_common_mt_end + 6, - gf_changelog_mt_libgfchangelog_t = gf_common_mt_end + 7, - gf_changelog_mt_libgfchangelog_entry_t = gf_common_mt_end + 8, - gf_changelog_mt_libgfchangelog_rl_t = gf_common_mt_end + 9, - gf_changelog_mt_changelog_buffer_t = gf_common_mt_end + 10, - gf_changelog_mt_history_data_t = gf_common_mt_end + 11, - gf_changelog_mt_libgfchangelog_call_pool_t = gf_common_mt_end + 12, - gf_changelog_mt_libgfchangelog_event_t = gf_common_mt_end + 13, - gf_changelog_mt_ev_dispatcher_t = gf_common_mt_end + 14, - gf_changelog_mt_end + gf_changelog_mt_priv_t = gf_common_mt_end + 1, + gf_changelog_mt_str_t = gf_common_mt_end + 2, + gf_changelog_mt_batch_t = gf_common_mt_end + 3, + gf_changelog_mt_rt_t = gf_common_mt_end + 4, + gf_changelog_mt_inode_ctx_t = gf_common_mt_end + 5, + gf_changelog_mt_rpc_clnt_t = gf_common_mt_end + 6, + gf_changelog_mt_libgfchangelog_t = gf_common_mt_end + 7, + gf_changelog_mt_libgfchangelog_entry_t = gf_common_mt_end + 8, + gf_changelog_mt_libgfchangelog_rl_t = gf_common_mt_end + 9, + gf_changelog_mt_changelog_buffer_t = gf_common_mt_end + 10, + gf_changelog_mt_history_data_t = gf_common_mt_end + 11, + gf_changelog_mt_libgfchangelog_call_pool_t = gf_common_mt_end + 12, + gf_changelog_mt_libgfchangelog_event_t = gf_common_mt_end + 13, + gf_changelog_mt_ev_dispatcher_t = gf_common_mt_end + 14, + gf_changelog_mt_end }; #endif diff --git a/xlators/features/changelog/src/changelog-messages.h b/xlators/features/changelog/src/changelog-messages.h index bbef2f2bde5..cb0e16c85d8 100644 --- a/xlators/features/changelog/src/changelog-messages.h +++ b/xlators/features/changelog/src/changelog-messages.h @@ -11,7 +11,7 @@ #ifndef _CHANGELOG_MESSAGES_H_ #define _CHANGELOG_MESSAGES_H_ -#include "glfs-message-id.h" +#include <glusterfs/glfs-message-id.h> /* To add new message IDs, append new identifiers at the end of the list. * @@ -23,63 +23,150 @@ * glfs-message-id.h. */ -GLFS_MSGID(CHANGELOG, - CHANGELOG_MSG_OPEN_FAILED, - CHANGELOG_MSG_NO_MEMORY, - CHANGELOG_MSG_VOL_MISCONFIGURED, - CHANGELOG_MSG_RENAME_ERROR, - CHANGELOG_MSG_READ_ERROR, - CHANGELOG_MSG_HTIME_ERROR, - CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED, - CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED, - CHANGELOG_MSG_CHILD_MISCONFIGURED, - CHANGELOG_MSG_DIR_OPTIONS_NOT_SET, - CHANGELOG_MSG_CLOSE_ERROR, - CHANGELOG_MSG_PIPE_CREATION_ERROR, - CHANGELOG_MSG_DICT_GET_FAILED, - CHANGELOG_MSG_BARRIER_INFO, - CHANGELOG_MSG_BARRIER_ERROR, - CHANGELOG_MSG_GET_TIME_OP_FAILED, - CHANGELOG_MSG_WRITE_FAILED, - CHANGELOG_MSG_PTHREAD_ERROR, - CHANGELOG_MSG_INODE_NOT_FOUND, - CHANGELOG_MSG_FSYNC_OP_FAILED, - CHANGELOG_MSG_TOTAL_LOG_INFO, - CHANGELOG_MSG_SNAP_INFO, - CHANGELOG_MSG_SELECT_FAILED, - CHANGELOG_MSG_FCNTL_FAILED, - CHANGELOG_MSG_BNOTIFY_INFO, - CHANGELOG_MSG_ENTRY_BUF_INFO, - CHANGELOG_MSG_NOT_ACTIVE, - CHANGELOG_MSG_LOCAL_INIT_FAILED, - CHANGELOG_MSG_NOTIFY_REGISTER_FAILED, - CHANGELOG_MSG_PROGRAM_NAME_REG_FAILED, - CHANGELOG_MSG_HANDLE_PROBE_ERROR, - CHANGELOG_MSG_SET_FD_CONTEXT, - CHANGELOG_MSG_FREEUP_FAILED, - CHANGELOG_MSG_HTIME_INFO, - CHANGELOG_MSG_RPC_SUBMIT_REPLY_FAILED, - CHANGELOG_MSG_RPC_BUILD_ERROR, - CHANGELOG_MSG_RPC_CONNECT_ERROR, - CHANGELOG_MSG_RPC_START_ERROR, - CHANGELOG_MSG_BUFFER_STARVATION_ERROR, - CHANGELOG_MSG_SCAN_DIR_FAILED, - CHANGELOG_MSG_FSETXATTR_FAILED, - CHANGELOG_MSG_FGETXATTR_FAILED, - CHANGELOG_MSG_CLEANUP_ON_ACTIVE_REF, - CHANGELOG_MSG_DISPATCH_EVENT_FAILED, - CHANGELOG_MSG_PUT_BUFFER_FAILED, - CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED, - CHANGELOG_MSG_PTHREAD_CANCEL_FAILED, - CHANGELOG_MSG_INJECT_FSYNC_FAILED, - CHANGELOG_MSG_CREATE_FRAME_FAILED, - CHANGELOG_MSG_FSTAT_OP_FAILED, - CHANGELOG_MSG_LSEEK_OP_FAILED, - CHANGELOG_MSG_STRSTR_OP_FAILED, - CHANGELOG_MSG_UNLINK_OP_FAILED, - CHANGELOG_MSG_DETECT_EMPTY_CHANGELOG_FAILED, - CHANGELOG_MSG_READLINK_OP_FAILED, - CHANGELOG_MSG_EXPLICIT_ROLLOVER_FAILED -); +GLFS_MSGID( + CHANGELOG, CHANGELOG_MSG_OPEN_FAILED, CHANGELOG_MSG_BARRIER_FOP_FAILED, + CHANGELOG_MSG_VOL_MISCONFIGURED, CHANGELOG_MSG_RENAME_ERROR, + CHANGELOG_MSG_READ_ERROR, CHANGELOG_MSG_HTIME_ERROR, + CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED, + CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED, CHANGELOG_MSG_CHILD_MISCONFIGURED, + CHANGELOG_MSG_DIR_OPTIONS_NOT_SET, CHANGELOG_MSG_CLOSE_ERROR, + CHANGELOG_MSG_PIPE_CREATION_ERROR, CHANGELOG_MSG_DICT_GET_FAILED, + CHANGELOG_MSG_BARRIER_INFO, CHANGELOG_MSG_BARRIER_ERROR, + CHANGELOG_MSG_GET_TIME_OP_FAILED, CHANGELOG_MSG_WRITE_FAILED, + CHANGELOG_MSG_PTHREAD_ERROR, CHANGELOG_MSG_INODE_NOT_FOUND, + CHANGELOG_MSG_FSYNC_OP_FAILED, CHANGELOG_MSG_TOTAL_LOG_INFO, + CHANGELOG_MSG_SNAP_INFO, CHANGELOG_MSG_SELECT_FAILED, + CHANGELOG_MSG_FCNTL_FAILED, CHANGELOG_MSG_BNOTIFY_INFO, + CHANGELOG_MSG_ENTRY_BUF_INFO, CHANGELOG_MSG_CHANGELOG_NOT_ACTIVE, + CHANGELOG_MSG_LOCAL_INIT_FAILED, CHANGELOG_MSG_NOTIFY_REGISTER_FAILED, + CHANGELOG_MSG_PROGRAM_NAME_REG_FAILED, CHANGELOG_MSG_HANDLE_PROBE_ERROR, + CHANGELOG_MSG_SET_FD_CONTEXT, CHANGELOG_MSG_FREEUP_FAILED, + CHANGELOG_MSG_RECONFIGURE, CHANGELOG_MSG_RPC_SUBMIT_REPLY_FAILED, + CHANGELOG_MSG_RPC_BUILD_ERROR, CHANGELOG_MSG_RPC_CONNECT_ERROR, + CHANGELOG_MSG_RPC_START_ERROR, CHANGELOG_MSG_BUFFER_STARVATION_ERROR, + CHANGELOG_MSG_SCAN_DIR_FAILED, CHANGELOG_MSG_FSETXATTR_FAILED, + CHANGELOG_MSG_FGETXATTR_FAILED, CHANGELOG_MSG_CLEANUP_ON_ACTIVE_REF, + CHANGELOG_MSG_DISPATCH_EVENT_FAILED, CHANGELOG_MSG_PUT_BUFFER_FAILED, + CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED, CHANGELOG_MSG_PTHREAD_CANCEL_FAILED, + CHANGELOG_MSG_INJECT_FSYNC_FAILED, CHANGELOG_MSG_CREATE_FRAME_FAILED, + CHANGELOG_MSG_FSTAT_OP_FAILED, CHANGELOG_MSG_LSEEK_OP_FAILED, + CHANGELOG_MSG_STRSTR_OP_FAILED, CHANGELOG_MSG_UNLINK_OP_FAILED, + CHANGELOG_MSG_DETECT_EMPTY_CHANGELOG_FAILED, + CHANGELOG_MSG_READLINK_OP_FAILED, CHANGELOG_MSG_EXPLICIT_ROLLOVER_FAILED, + CHANGELOG_MSG_RPCSVC_NOTIFY_FAILED, CHANGELOG_MSG_MEMORY_INIT_FAILED, + CHANGELOG_MSG_NO_MEMORY, CHANGELOG_MSG_HTIME_STAT_ERROR, + CHANGELOG_MSG_HTIME_CURRENT_ERROR, CHANGELOG_MSG_BNOTIFY_COND_INFO, + CHANGELOG_MSG_NO_HTIME_CURRENT, CHANGELOG_MSG_HTIME_CURRENT, + CHANGELOG_MSG_NEW_HTIME_FILE, CHANGELOG_MSG_MKDIR_ERROR, + CHANGELOG_MSG_PATH_NOT_FOUND, CHANGELOG_MSG_XATTR_INIT_FAILED, + CHANGELOG_MSG_WROTE_TO_CSNAP, CHANGELOG_MSG_UNUSED_0, + CHANGELOG_MSG_GET_BUFFER_FAILED, CHANGELOG_MSG_BARRIER_STATE_NOTIFY, + CHANGELOG_MSG_BARRIER_DISABLED, CHANGELOG_MSG_BARRIER_ALREADY_DISABLED, + CHANGELOG_MSG_BARRIER_ON_ERROR, CHANGELOG_MSG_BARRIER_ENABLE, + CHANGELOG_MSG_BARRIER_KEY_NOT_FOUND, CHANGELOG_MSG_ERROR_IN_DICT_GET, + CHANGELOG_MSG_UNUSED_1, CHANGELOG_MSG_UNUSED_2, + CHANGELOG_MSG_DEQUEUING_BARRIER_FOPS, + CHANGELOG_MSG_DEQUEUING_BARRIER_FOPS_FINISHED, + CHANGELOG_MSG_BARRIER_TIMEOUT, CHANGELOG_MSG_TIMEOUT_ADD_FAILED, + CHANGELOG_MSG_CLEANUP_ALREADY_SET); +#define CHANGELOG_MSG_BARRIER_FOP_FAILED_STR \ + "failed to barrier FOPs, disabling changelog barrier" +#define CHANGELOG_MSG_MEMORY_INIT_FAILED_STR "memory accounting init failed" +#define CHANGELOG_MSG_NO_MEMORY_STR "failed to create local memory pool" +#define CHANGELOG_MSG_ENTRY_BUF_INFO_STR \ + "Entry cannot be captured for gfid, Capturing DATA entry." +#define CHANGELOG_MSG_PTHREAD_ERROR_STR "pthread error" +#define CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED_STR "pthread_mutex_init failed" +#define CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED_STR "pthread_cond_init failed" +#define CHANGELOG_MSG_HTIME_ERROR_STR "failed to update HTIME file" +#define CHANGELOG_MSG_HTIME_STAT_ERROR_STR "unable to stat htime file" +#define CHANGELOG_MSG_HTIME_CURRENT_ERROR_STR "Error extracting HTIME_CURRENT." +#define CHANGELOG_MSG_UNLINK_OP_FAILED_STR "error unlinking empty changelog" +#define CHANGELOG_MSG_RENAME_ERROR_STR "error renaming" +#define CHANGELOG_MSG_MKDIR_ERROR_STR "unable to create directory" +#define CHANGELOG_MSG_BNOTIFY_INFO_STR \ + "Explicit rollover changelog signaling bnotify" +#define CHANGELOG_MSG_BNOTIFY_COND_INFO_STR "Woke up: bnotify conditional wait" +#define CHANGELOG_MSG_RECONFIGURE_STR "Reconfigure: Changelog Enable" +#define CHANGELOG_MSG_NO_HTIME_CURRENT_STR \ + "HTIME_CURRENT not found. Changelog enabled before init" +#define CHANGELOG_MSG_HTIME_CURRENT_STR "HTIME_CURRENT" +#define CHANGELOG_MSG_NEW_HTIME_FILE_STR \ + "Changelog enable: Creating new HTIME file" +#define CHANGELOG_MSG_FGETXATTR_FAILED_STR "fgetxattr failed" +#define CHANGELOG_MSG_TOTAL_LOG_INFO_STR "changelog info" +#define CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED_STR "pthread cond wait failed" +#define CHANGELOG_MSG_INODE_NOT_FOUND_STR "inode not found" +#define CHANGELOG_MSG_READLINK_OP_FAILED_STR \ + "could not read the link from the gfid handle" +#define CHANGELOG_MSG_OPEN_FAILED_STR "unable to open file" +#define CHANGELOG_MSG_RPC_CONNECT_ERROR_STR "failed to connect back" +#define CHANGELOG_MSG_BUFFER_STARVATION_ERROR_STR \ + "Failed to get buffer for RPC dispatch" +#define CHANGELOG_MSG_PTHREAD_CANCEL_FAILED_STR "could not cancel thread" +#define CHANGELOG_MSG_FSTAT_OP_FAILED_STR "Could not stat (CHANGELOG)" +#define CHANGELOG_MSG_LSEEK_OP_FAILED_STR "Could not lseek (changelog)" +#define CHANGELOG_MSG_PATH_NOT_FOUND_STR \ + "Could not find CHANGELOG in changelog path" +#define CHANGELOG_MSG_FSYNC_OP_FAILED_STR "fsync failed" +#define CHANGELOG_MSG_DETECT_EMPTY_CHANGELOG_FAILED_STR \ + "Error detecting empty changelog" +#define CHANGELOG_MSG_EXPLICIT_ROLLOVER_FAILED_STR \ + "Fail snapshot because of previous errors" +#define CHANGELOG_MSG_SCAN_DIR_FAILED_STR "scandir failed" +#define CHANGELOG_MSG_FSETXATTR_FAILED_STR "fsetxattr failed" +#define CHANGELOG_MSG_XATTR_INIT_FAILED_STR "Htime xattr initialization failed" +#define CHANGELOG_MSG_SNAP_INFO_STR "log in call path" +#define CHANGELOG_MSG_WRITE_FAILED_STR "error writing to disk" +#define CHANGELOG_MSG_WROTE_TO_CSNAP_STR "Successfully wrote to csnap" +#define CHANGELOG_MSG_GET_TIME_OP_FAILED_STR "Problem rolling over changelog(s)" +#define CHANGELOG_MSG_BARRIER_INFO_STR "Explicit wakeup on barrier notify" +#define CHANGELOG_MSG_SELECT_FAILED_STR "pthread_cond_timedwait failed" +#define CHANGELOG_MSG_INJECT_FSYNC_FAILED_STR "failed to inject fsync event" +#define CHANGELOG_MSG_LOCAL_INIT_FAILED_STR \ + "changelog local initialization failed" +#define CHANGELOG_MSG_GET_BUFFER_FAILED_STR "Failed to get buffer" +#define CHANGELOG_MSG_SET_FD_CONTEXT_STR \ + "could not set fd context(for release cbk)" +#define CHANGELOG_MSG_DICT_GET_FAILED_STR "Barrier failed" +#define CHANGELOG_MSG_BARRIER_STATE_NOTIFY_STR "Barrier notification" +#define CHANGELOG_MSG_BARRIER_ERROR_STR \ + "Received another barrier off notification while already off" +#define CHANGELOG_MSG_BARRIER_DISABLED_STR "disabled changelog barrier" +#define CHANGELOG_MSG_BARRIER_ALREADY_DISABLED_STR \ + "Changelog barrier already disabled" +#define CHANGELOG_MSG_BARRIER_ON_ERROR_STR \ + "Received another barrier on notification when last one is not served yet" +#define CHANGELOG_MSG_BARRIER_ENABLE_STR "Enabled changelog barrier" +#define CHANGELOG_MSG_BARRIER_KEY_NOT_FOUND_STR "barrier key not found" +#define CHANGELOG_MSG_ERROR_IN_DICT_GET_STR \ + "Something went wrong in dict_get_str_boolean" +#define CHANGELOG_MSG_DIR_OPTIONS_NOT_SET_STR "changelog-dir option is not set" +#define CHANGELOG_MSG_FREEUP_FAILED_STR "could not cleanup bootstrapper" +#define CHANGELOG_MSG_CHILD_MISCONFIGURED_STR \ + "translator needs a single subvolume" +#define CHANGELOG_MSG_VOL_MISCONFIGURED_STR \ + "dangling volume. please check volfile" +#define CHANGELOG_MSG_DEQUEUING_BARRIER_FOPS_STR \ + "Dequeuing all the changelog barriered fops" +#define CHANGELOG_MSG_DEQUEUING_BARRIER_FOPS_FINISHED_STR \ + "Dequeuing changelog barriered fops is finished" +#define CHANGELOG_MSG_BARRIER_TIMEOUT_STR \ + "Disabling changelog barrier because of the timeout" +#define CHANGELOG_MSG_TIMEOUT_ADD_FAILED_STR \ + "Couldn't add changelog barrier timeout event" +#define CHANGELOG_MSG_RPC_BUILD_ERROR_STR "failed to build rpc options" +#define CHANGELOG_MSG_NOTIFY_REGISTER_FAILED_STR "failed to register notify" +#define CHANGELOG_MSG_RPC_START_ERROR_STR "failed to start rpc" +#define CHANGELOG_MSG_CREATE_FRAME_FAILED_STR "failed to create frame" +#define CHANGELOG_MSG_RPC_SUBMIT_REPLY_FAILED_STR "failed to serialize reply" +#define CHANGELOG_MSG_PROGRAM_NAME_REG_FAILED_STR "cannot register program" +#define CHANGELOG_MSG_CHANGELOG_NOT_ACTIVE_STR \ + "Changelog is not active, return success" +#define CHANGELOG_MSG_PUT_BUFFER_FAILED_STR \ + "failed to put buffer after consumption" +#define CHANGELOG_MSG_CLEANUP_ALREADY_SET_STR \ + "cleanup_starting flag is already set for xl" +#define CHANGELOG_MSG_HANDLE_PROBE_ERROR_STR "xdr decoding error" #endif /* !_CHANGELOG_MESSAGES_H_ */ diff --git a/xlators/features/changelog/src/changelog-misc.h b/xlators/features/changelog/src/changelog-misc.h index 93af201879e..e2addc09414 100644 --- a/xlators/features/changelog/src/changelog-misc.h +++ b/xlators/features/changelog/src/changelog-misc.h @@ -11,10 +11,10 @@ #ifndef _CHANGELOG_MISC_H #define _CHANGELOG_MISC_H -#include "glusterfs.h" -#include "common-utils.h" +#include <glusterfs/glusterfs.h> +#include <glusterfs/common-utils.h> -#define CHANGELOG_MAX_TYPE 4 +#define CHANGELOG_MAX_TYPE 4 #define CHANGELOG_FILE_NAME "CHANGELOG" #define HTIME_FILE_NAME "HTIME" #define CSNAP_FILE_NAME "CHANGELOG.SNAP" @@ -22,111 +22,110 @@ #define HTIME_CURRENT "trusted.glusterfs.current_htime" #define HTIME_INITIAL_VALUE "0:0" -#define CHANGELOG_VERSION_MAJOR 1 -#define CHANGELOG_VERSION_MINOR 2 +#define CHANGELOG_VERSION_MAJOR 1 +#define CHANGELOG_VERSION_MINOR 2 -#define CHANGELOG_UNIX_SOCK DEFAULT_VAR_RUN_DIRECTORY"/changelog-%s.sock" -#define CHANGELOG_TMP_UNIX_SOCK DEFAULT_VAR_RUN_DIRECTORY"/.%s%lu.sock" +#define CHANGELOG_UNIX_SOCK DEFAULT_VAR_RUN_DIRECTORY "/changelog-%s.sock" +#define CHANGELOG_TMP_UNIX_SOCK DEFAULT_VAR_RUN_DIRECTORY "/.%s%lu.sock" /** * header starts with the version and the format of the changelog. * 'version' not much of a use now. */ -#define CHANGELOG_HEADER \ - "GlusterFS Changelog | version: v%d.%d | encoding : %d\n" - -#define CHANGELOG_MAKE_SOCKET_PATH(brick_path, sockpath, len) do { \ - char xxh64[GF_XXH64_DIGEST_LENGTH*2+1] = {0,}; \ - gf_xxh64_wrapper ((unsigned char *)brick_path, \ - strlen(brick_path), \ - GF_XXHSUM64_DEFAULT_SEED, xxh64); \ - (void) snprintf (sockpath, len, \ - CHANGELOG_UNIX_SOCK, xxh64); \ - } while (0) - -#define CHANGELOG_MAKE_TMP_SOCKET_PATH(brick_path, sockpath, len) do { \ - unsigned long pid = 0; \ - char xxh64[GF_XXH64_DIGEST_LENGTH*2+1] = {0,}; \ - pid = (unsigned long) getpid (); \ - gf_xxh64_wrapper ((unsigned char *)brick_path, \ - strlen(brick_path), \ - GF_XXHSUM64_DEFAULT_SEED, xxh64); \ - (void) snprintf (sockpath, \ - len, CHANGELOG_TMP_UNIX_SOCK, \ - xxh64, pid); \ - } while (0) - +#define CHANGELOG_HEADER \ + "GlusterFS Changelog | version: v%d.%d | encoding : %d\n" + +#define CHANGELOG_MAKE_SOCKET_PATH(brick_path, sockpath, len) \ + do { \ + char xxh64[GF_XXH64_DIGEST_LENGTH * 2 + 1] = { \ + 0, \ + }; \ + gf_xxh64_wrapper((unsigned char *)brick_path, strlen(brick_path), \ + GF_XXHSUM64_DEFAULT_SEED, xxh64); \ + (void)snprintf(sockpath, len, CHANGELOG_UNIX_SOCK, xxh64); \ + } while (0) + +#define CHANGELOG_MAKE_TMP_SOCKET_PATH(brick_path, sockpath, len) \ + do { \ + unsigned long pid = 0; \ + char xxh64[GF_XXH64_DIGEST_LENGTH * 2 + 1] = { \ + 0, \ + }; \ + pid = (unsigned long)getpid(); \ + gf_xxh64_wrapper((unsigned char *)brick_path, strlen(brick_path), \ + GF_XXHSUM64_DEFAULT_SEED, xxh64); \ + (void)snprintf(sockpath, len, CHANGELOG_TMP_UNIX_SOCK, xxh64, pid); \ + } while (0) /** * ... used by libgfchangelog. */ -#define CHANGELOG_GET_HEADER_INFO(fd, buffer, len, enc, maj, min, elen) do { \ - FILE *fp; \ - int fd_dup; \ - \ - enc = -1; \ - maj = -1; \ - min = -1; \ - fd_dup = dup (fd); \ - \ - if (fd_dup != -1) { \ - fp = fdopen (fd_dup, "r"); \ - if (fp) { \ - if (fgets (buffer, len, fp)) { \ - elen = strlen (buffer); \ - sscanf (buffer, \ - CHANGELOG_HEADER, \ - &maj, &min, &enc); \ - } \ - fclose (fp); \ - } else { \ - sys_close (fd_dup); \ - } \ - } \ - } while (0) - -#define CHANGELOG_FILL_HTIME_DIR(changelog_dir, path) do { \ - strncpy (path, changelog_dir, sizeof (path) - 1); \ - strcat (path, "/htime"); \ - } while(0) - -#define CHANGELOG_FILL_CSNAP_DIR(changelog_dir, path) do { \ - strncpy (path, changelog_dir, sizeof (path) - 1); \ - strcat (path, "/csnap"); \ - } while(0) +#define CHANGELOG_GET_HEADER_INFO(fd, buffer, len, enc, maj, min, elen) \ + do { \ + FILE *fp; \ + int fd_dup; \ + \ + enc = -1; \ + maj = -1; \ + min = -1; \ + fd_dup = dup(fd); \ + \ + if (fd_dup != -1) { \ + fp = fdopen(fd_dup, "r"); \ + if (fp) { \ + if (fgets(buffer, len, fp)) { \ + elen = strlen(buffer); \ + sscanf(buffer, CHANGELOG_HEADER, &maj, &min, &enc); \ + } \ + fclose(fp); \ + } else { \ + sys_close(fd_dup); \ + } \ + } \ + } while (0) + +#define CHANGELOG_FILL_HTIME_DIR(changelog_dir, path) \ + do { \ + snprintf(path, sizeof(path), "%s/htime", changelog_dir); \ + } while (0) + +#define CHANGELOG_FILL_CSNAP_DIR(changelog_dir, path) \ + do { \ + snprintf(path, sizeof(path), "%s/csnap", changelog_dir); \ + } while (0) /** * everything after 'CHANGELOG_TYPE_METADATA_XATTR' are internal types * (ie. none of the fops trigger this type of event), hence * CHANGELOG_MAX_TYPE = 4 */ typedef enum { - CHANGELOG_TYPE_DATA = 0, - CHANGELOG_TYPE_METADATA, - CHANGELOG_TYPE_ENTRY, - CHANGELOG_TYPE_METADATA_XATTR, - CHANGELOG_TYPE_ROLLOVER, - CHANGELOG_TYPE_FSYNC, + CHANGELOG_TYPE_DATA = 0, + CHANGELOG_TYPE_METADATA, + CHANGELOG_TYPE_ENTRY, + CHANGELOG_TYPE_METADATA_XATTR, + CHANGELOG_TYPE_ROLLOVER, + CHANGELOG_TYPE_FSYNC, } changelog_log_type; /* operation modes - RT for now */ typedef enum { - CHANGELOG_MODE_RT = 0, + CHANGELOG_MODE_RT = 0, } changelog_mode_t; /* encoder types */ typedef enum { - CHANGELOG_ENCODE_MIN = 0, - CHANGELOG_ENCODE_BINARY, - CHANGELOG_ENCODE_ASCII, - CHANGELOG_ENCODE_MAX, + CHANGELOG_ENCODE_MIN = 0, + CHANGELOG_ENCODE_BINARY, + CHANGELOG_ENCODE_ASCII, + CHANGELOG_ENCODE_MAX, } changelog_encoder_t; -#define CHANGELOG_VALID_ENCODING(enc) \ - (enc > CHANGELOG_ENCODE_MIN && enc < CHANGELOG_ENCODE_MAX) +#define CHANGELOG_VALID_ENCODING(enc) \ + (enc > CHANGELOG_ENCODE_MIN && enc < CHANGELOG_ENCODE_MAX) -#define CHANGELOG_TYPE_IS_ENTRY(type) (type == CHANGELOG_TYPE_ENTRY) -#define CHANGELOG_TYPE_IS_ROLLOVER(type) (type == CHANGELOG_TYPE_ROLLOVER) -#define CHANGELOG_TYPE_IS_FSYNC(type) (type == CHANGELOG_TYPE_FSYNC) +#define CHANGELOG_TYPE_IS_ENTRY(type) (type == CHANGELOG_TYPE_ENTRY) +#define CHANGELOG_TYPE_IS_ROLLOVER(type) (type == CHANGELOG_TYPE_ROLLOVER) +#define CHANGELOG_TYPE_IS_FSYNC(type) (type == CHANGELOG_TYPE_FSYNC) #endif /* _CHANGELOG_MISC_H */ diff --git a/xlators/features/changelog/src/changelog-rpc-common.c b/xlators/features/changelog/src/changelog-rpc-common.c index 056519232cf..125246a17e1 100644 --- a/xlators/features/changelog/src/changelog-rpc-common.c +++ b/xlators/features/changelog/src/changelog-rpc-common.c @@ -11,7 +11,7 @@ #include "changelog-rpc-common.h" #include "changelog-messages.h" -#include "syscall.h" +#include <glusterfs/syscall.h> /** ***************************************************** Client Interface @@ -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)gf_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_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_BUILD_ERROR, + NULL); + 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_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_NOTIFY_REGISTER_FAILED, NULL); + goto dealloc_rpc_clnt; + } + + ret = rpc_clnt_start(rpc); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_START_ERROR, + NULL); + goto dealloc_rpc_clnt; + } + + dict_unref(options); + 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; + } + + 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; +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; + + if (!this || !prog) + goto error_return; + + frame = create_frame(this, this->ctx->pool); + if (!frame) { + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_CREATE_FRAME_FAILED, + NULL); + goto error_return; + } - proc = &prog->proctable[procidx]; - if (proc->fn) - ret = proc->fn (frame, this, arg); + proc = &prog->proctable[procidx]; + if (proc->fn) + ret = proc->fn(frame, this, arg); - STACK_DESTROY (frame->root); - return ret; + STACK_DESTROY(frame->root); + return ret; - error_return: - return -1; +error_return: + return -1; } /** @@ -189,170 +187,173 @@ 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_smsg("", GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_SUBMIT_REPLY_FAILED, + NULL); + 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++; + rpcsvc_listener_t *listener = NULL; + rpcsvc_listener_t *next = NULL; + struct rpcsvc_program *prog = NULL; + rpc_transport_t *trans = NULL; + + if (!rpc) + return; + + while (*progs) { + prog = *progs; + (void)rpcsvc_program_unregister(rpc, prog); + progs++; + } + + list_for_each_entry_safe(listener, next, &rpc->listeners, list) + { + if (listener->trans) { + trans = listener->trans; + rpc_transport_disconnect(trans, _gf_false); } + } - list_for_each_entry_safe (listener, next, &rpc->listeners, list) { - rpcsvc_listener_destroy (listener); - } + (void)rpcsvc_unregister_notify(rpc, fn, this); - (void) rpcsvc_unregister_notify (rpc, fn, this); - sys_unlink (sockfile); + /* 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) { if (rpc->rxpool) { - mem_pool_destroy (rpc->rxpool); - rpc->rxpool = NULL; + 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); + 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; - } + int ret = 0; + rpcsvc_t *rpc = NULL; + dict_t *options = NULL; + struct rpcsvc_program *prog = NULL; - 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; - } + if (!cbkdata) + cbkdata = this; - ret = rpcsvc_create_listeners (rpc, options, this->name); - if (ret != 1) { - gf_msg_debug (this->name, - 0, "failed to create listeners"); - goto dealloc_rpc; - } + options = dict_new(); + if (!options) + return NULL; - 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++; + 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_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_START_ERROR, + NULL); + goto dealloc_dict; + } + + ret = rpcsvc_register_notify(rpc, fn, cbkdata); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_NOTIFY_REGISTER_FAILED, NULL); + 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_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_PROGRAM_NAME_REG_FAILED, "name%s", + prog->progname, "prognum=%d", prog->prognum, "pogver=%d", + prog->progver, NULL); + goto dealloc_rpc; } - dict_unref (options); - return rpc; + progs++; + } - dealloc_rpc: - GF_FREE (rpc); - dealloc_dict: - dict_unref (options); - error_return: - return NULL; + dict_unref(options); + return rpc; + +dealloc_rpc: + GF_FREE(rpc); +dealloc_dict: + dict_unref(options); + return NULL; } diff --git a/xlators/features/changelog/src/changelog-rpc-common.h b/xlators/features/changelog/src/changelog-rpc-common.h index 1a630536924..4d9aa2c694b 100644 --- a/xlators/features/changelog/src/changelog-rpc-common.h +++ b/xlators/features/changelog/src/changelog-rpc-common.h @@ -13,8 +13,8 @@ #include "rpcsvc.h" #include "rpc-clnt.h" -#include "gf-event.h" -#include "call-stub.h" +#include <glusterfs/gf-event.h> +#include <glusterfs/call-stub.h> #include "changelog-xdr.h" #include "xdr-generic.h" @@ -24,61 +24,62 @@ /** * Let's keep this non-configurable for now. */ -#define NR_ROTT_BUFFS 4 +#define NR_ROTT_BUFFS 4 #define NR_DISPATCHERS (NR_ROTT_BUFFS - 1) enum changelog_rpc_procnum { - CHANGELOG_RPC_PROC_NULL = 0, - CHANGELOG_RPC_PROBE_FILTER = 1, - CHANGELOG_RPC_PROC_MAX = 2, + CHANGELOG_RPC_PROC_NULL = 0, + CHANGELOG_RPC_PROBE_FILTER = 1, + CHANGELOG_RPC_PROC_MAX = 2, }; -#define CHANGELOG_RPC_PROGNUM 1885957735 -#define CHANGELOG_RPC_PROGVER 1 +#define CHANGELOG_RPC_PROGNUM 1885957735 +#define CHANGELOG_RPC_PROGVER 1 /** * reverse connection: data xfer path */ enum changelog_reverse_rpc_procnum { - CHANGELOG_REV_PROC_NULL = 0, - CHANGELOG_REV_PROC_EVENT = 1, - CHANGELOG_REV_PROC_MAX = 2, + CHANGELOG_REV_PROC_NULL = 0, + CHANGELOG_REV_PROC_EVENT = 1, + CHANGELOG_REV_PROC_MAX = 2, }; -#define CHANGELOG_REV_RPC_PROCNUM 1886350951 -#define CHANGELOG_REV_RPC_PROCVER 1 +#define CHANGELOG_REV_RPC_PROCNUM 1886350951 +#define CHANGELOG_REV_RPC_PROCVER 1 typedef struct changelog_rpc { - rpcsvc_t *svc; - struct rpc_clnt *rpc; - char sock[UNIX_PATH_MAX]; /* tied to server */ + rpcsvc_t *svc; + struct rpc_clnt *rpc; + char sock[UNIX_PATH_MAX]; /* tied to server */ } changelog_rpc_t; /* event poller */ -void *changelog_rpc_poller (void *); +void * +changelog_rpc_poller(void *); /* CLIENT API */ struct rpc_clnt * -changelog_rpc_client_init (xlator_t *, void *, char *, rpc_clnt_notify_t); +changelog_rpc_client_init(xlator_t *, void *, char *, rpc_clnt_notify_t); int -changelog_rpc_sumbit_req (struct rpc_clnt *, void *, call_frame_t *, - rpc_clnt_prog_t *, int , struct iovec *, int, - struct iobref *, xlator_t *, fop_cbk_fn_t, xdrproc_t); +changelog_rpc_sumbit_req(struct rpc_clnt *, void *, call_frame_t *, + rpc_clnt_prog_t *, int, struct iovec *, int, + struct iobref *, xlator_t *, fop_cbk_fn_t, xdrproc_t); int -changelog_invoke_rpc (xlator_t *, struct rpc_clnt *, - rpc_clnt_prog_t *, int , void *); +changelog_invoke_rpc(xlator_t *, struct rpc_clnt *, rpc_clnt_prog_t *, int, + void *); /* SERVER API */ int -changelog_rpc_sumbit_reply (rpcsvc_request_t *, void *, - struct iovec *, int, struct iobref *, xdrproc_t); +changelog_rpc_sumbit_reply(rpcsvc_request_t *, void *, struct iovec *, int, + struct iobref *, xdrproc_t); rpcsvc_t * -changelog_rpc_server_init (xlator_t *, char *, void*, - rpcsvc_notify_t, struct rpcsvc_program **); +changelog_rpc_server_init(xlator_t *, char *, void *, rpcsvc_notify_t, + struct rpcsvc_program **); void -changelog_rpc_server_destroy (xlator_t *, rpcsvc_t *, char *, - rpcsvc_notify_t, struct rpcsvc_program **); +changelog_rpc_server_destroy(xlator_t *, rpcsvc_t *, char *, rpcsvc_notify_t, + struct rpcsvc_program **); #endif diff --git a/xlators/features/changelog/src/changelog-rpc.c b/xlators/features/changelog/src/changelog-rpc.c index 9027fe10a2a..440b88091a6 100644 --- a/xlators/features/changelog/src/changelog-rpc.c +++ b/xlators/features/changelog/src/changelog-rpc.c @@ -8,264 +8,346 @@ cases as published by the Free Software Foundation. */ -#include "syscall.h" +#include <glusterfs/syscall.h> #include "changelog-rpc.h" #include "changelog-mem-types.h" #include "changelog-ev-handle.h" -struct rpcsvc_program *changelog_programs[]; +static 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); + + /* 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; + + 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++) { + ret = gf_thread_create(&priv->ev_dispatcher[j], NULL, + changelog_ev_dispatch, conn, "clogd%03hx", + j & 0x3ff); + 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; +} + +int +changelog_rpcsvc_notify(rpcsvc_t *rpc, void *xl, rpcsvc_event_t event, + void *data) { - 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; + xlator_t *this = NULL; + rpc_transport_t *trans = NULL; + rpc_transport_t *xprt = NULL; + rpc_transport_t *xp_next = NULL; + changelog_priv_t *priv = NULL; + uint64_t listnercnt = 0; + uint64_t xprtcnt = 0; + uint64_t clntcnt = 0; + rpcsvc_listener_t *listener = NULL; + rpcsvc_listener_t *next = NULL; + gf_boolean_t listner_found = _gf_false; + socket_private_t *sockpriv = NULL; + + if (!xl || !data || !rpc) { + gf_msg_callingfn("changelog", GF_LOG_WARNING, 0, + CHANGELOG_MSG_RPCSVC_NOTIFY_FAILED, + "Calling rpc_notify without initializing"); + goto out; + } + + this = xl; + trans = data; + priv = this->private; + + if (!priv) { + gf_msg_callingfn("changelog", GF_LOG_WARNING, 0, + CHANGELOG_MSG_RPCSVC_NOTIFY_FAILED, + "Calling rpc_notify without priv initializing"); + goto out; + } + + if (event == RPCSVC_EVENT_ACCEPT) { + GF_ATOMIC_INC(priv->xprtcnt); + LOCK(&priv->lock); + { + list_add_tail(&trans->list, &priv->xprt_list); + } + UNLOCK(&priv->lock); + goto out; + } + + if (event == RPCSVC_EVENT_DISCONNECT) { + list_for_each_entry_safe(listener, next, &rpc->listeners, list) + { + if (listener && listener->trans) { + if (listener->trans == trans) { + listnercnt = GF_ATOMIC_DEC(priv->listnercnt); + listner_found = _gf_true; + rpcsvc_listener_destroy(listener); } + } } - if (ret != 0) - goto cleanup_connector; + if (listnercnt > 0) { + goto out; + } + if (listner_found) { + LOCK(&priv->lock); + list_for_each_entry_safe(xprt, xp_next, &priv->xprt_list, list) + { + sockpriv = (socket_private_t *)(xprt->private); + gf_log("changelog", GF_LOG_INFO, + "Send disconnect" + " on socket %d", + sockpriv->sock); + rpc_transport_disconnect(xprt, _gf_false); + } + UNLOCK(&priv->lock); + goto out; + } + LOCK(&priv->lock); + { + list_del_init(&trans->list); + } + UNLOCK(&priv->lock); - priv->nr_dispatchers = nr_dispatchers; - return 0; + xprtcnt = GF_ATOMIC_DEC(priv->xprtcnt); + clntcnt = GF_ATOMIC_GET(priv->clntcnt); + if (!xprtcnt && !clntcnt) { + changelog_process_cleanup_event(this); + } + } - 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; +out: + return 0; } -int -changelog_rpcsvc_notify (rpcsvc_t *rpc, - void *xl, rpcsvc_event_t event, void *data) +void +changelog_process_cleanup_event(xlator_t *this) { - return 0; + gf_boolean_t cleanup_notify = _gf_false; + changelog_priv_t *priv = NULL; + char sockfile[UNIX_PATH_MAX] = { + 0, + }; + + if (!this) + return; + priv = this->private; + if (!priv) + return; + + LOCK(&priv->lock); + { + cleanup_notify = priv->notify_down; + priv->notify_down = _gf_true; + } + UNLOCK(&priv->lock); + + if (priv->victim && !cleanup_notify) { + default_notify(this, GF_EVENT_PARENT_DOWN, priv->victim); + + if (priv->rpc) { + /* sockfile path could have been saved to avoid this */ + CHANGELOG_MAKE_SOCKET_PATH(priv->changelog_brick, sockfile, + UNIX_PATH_MAX); + sys_unlink(sockfile); + (void)rpcsvc_unregister_notify(priv->rpc, changelog_rpcsvc_notify, + this); + if (priv->rpc->rxpool) { + mem_pool_destroy(priv->rpc->rxpool); + priv->rpc->rxpool = NULL; + } + GF_FREE(priv->rpc); + priv->rpc = NULL; + } + } } 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, + }; + + /* 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); } 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,81 +361,80 @@ 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_smsg(this->name, GF_LOG_DEBUG, 0, CHANGELOG_MSG_CLEANUP_ALREADY_SET, + NULL); return 0; + } + + ret = xdr_to_generic(req->msg[0], &rpc_req, + (xdrproc_t)xdr_changelog_probe_req); + if (ret < 0) { + gf_smsg("", GF_LOG_ERROR, 0, CHANGELOG_MSG_HANDLE_PROBE_ERROR, NULL); + 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; } /** * RPC declarations */ -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 - }, +static rpcsvc_actor_t changelog_svc_actors[CHANGELOG_RPC_PROC_MAX] = { + [CHANGELOG_RPC_PROBE_FILTER] = {"CHANGELOG PROBE FILTER", + changelog_handle_probe, NULL, + CHANGELOG_RPC_PROBE_FILTER, DRC_NA, 0}, }; -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, +static 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, }; -struct rpcsvc_program *changelog_programs[] = { - &changelog_svc_prog, - NULL, +static struct rpcsvc_program *changelog_programs[] = { + &changelog_svc_prog, + NULL, }; diff --git a/xlators/features/changelog/src/changelog-rpc.h b/xlators/features/changelog/src/changelog-rpc.h index 9f1e2d223a3..b1707565249 100644 --- a/xlators/features/changelog/src/changelog-rpc.h +++ b/xlators/features/changelog/src/changelog-rpc.h @@ -11,21 +11,21 @@ #ifndef __CHANGELOG_RPC_H #define __CHANGELOG_RPC_H -#include "xlator.h" +#include <glusterfs/xlator.h> #include "changelog-helpers.h" /* one time */ #include "socket.h" #include "changelog-rpc-common.h" -#define CHANGELOG_RPC_PROGNAME "GlusterFS Changelog" +#define CHANGELOG_RPC_PROGNAME "GlusterFS Changelog" rpcsvc_t * -changelog_init_rpc_listener (xlator_t *, changelog_priv_t *, rbuf_t *, int); +changelog_init_rpc_listener(xlator_t *, changelog_priv_t *, rbuf_t *, int); void -changelog_destroy_rpc_listner (xlator_t *, changelog_priv_t *); +changelog_destroy_rpc_listner(xlator_t *, changelog_priv_t *); int -changelog_cleanup_rpc_threads (xlator_t *this, changelog_priv_t *priv); +changelog_cleanup_rpc_threads(xlator_t *this, changelog_priv_t *priv); #endif diff --git a/xlators/features/changelog/src/changelog-rt.c b/xlators/features/changelog/src/changelog-rt.c index c262820c64c..841545ae359 100644 --- a/xlators/features/changelog/src/changelog-rt.c +++ b/xlators/features/changelog/src/changelog-rt.c @@ -8,60 +8,59 @@ cases as published by the Free Software Foundation. */ -#include "xlator.h" -#include "defaults.h" -#include "logging.h" +#include <glusterfs/xlator.h> +#include <glusterfs/defaults.h> +#include <glusterfs/logging.h> #include "changelog-rt.h" #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-rt.h b/xlators/features/changelog/src/changelog-rt.h index 1fc2bbc5bb9..28b9827d85b 100644 --- a/xlators/features/changelog/src/changelog-rt.h +++ b/xlators/features/changelog/src/changelog-rt.h @@ -11,23 +11,23 @@ #ifndef _CHANGELOG_RT_H #define _CHANGELOG_RT_H -#include "locking.h" -#include "timer.h" +#include <glusterfs/locking.h> +#include <glusterfs/timer.h> #include "pthread.h" #include "changelog-helpers.h" /* unused as of now - may be you would need it later */ typedef struct changelog_rt { - gf_lock_t lock; + gf_lock_t lock; } changelog_rt_t; int -changelog_rt_init (xlator_t *this, changelog_dispatcher_t *cd); +changelog_rt_init(xlator_t *this, changelog_dispatcher_t *cd); int -changelog_rt_fini (xlator_t *this, changelog_dispatcher_t *cd); +changelog_rt_fini(xlator_t *this, changelog_dispatcher_t *cd); 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); #endif /* _CHANGELOG_RT_H */ diff --git a/xlators/features/changelog/src/changelog.c b/xlators/features/changelog/src/changelog.c index ab42ad869c0..6a6e5af859e 100644 --- a/xlators/features/changelog/src/changelog.c +++ b/xlators/features/changelog/src/changelog.c @@ -8,11 +8,11 @@ cases as published by the Free Software Foundation. */ -#include "xlator.h" -#include "defaults.h" -#include "syscall.h" -#include "logging.h" -#include "iobuf.h" +#include <glusterfs/xlator.h> +#include <glusterfs/defaults.h> +#include <glusterfs/syscall.h> +#include <glusterfs/logging.h> +#include <glusterfs/iobuf.h> #include "changelog-rt.h" @@ -26,15 +26,20 @@ #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, + }, }; +static int +changelog_init_rpc(xlator_t *this, changelog_priv_t *priv); + +static int +changelog_init(xlator_t *this, changelog_priv_t *priv); + /* Entry operations - TYPE III */ /** @@ -46,1111 +51,1052 @@ 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_BARRIER_FOP_FAILED, "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_BARRIER_FOP_FAILED, "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_BARRIER_FOP_FAILED, "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_BARRIER_FOP_FAILED, + "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_BARRIER_FOP_FAILED, "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_BARRIER_FOP_FAILED, "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_BARRIER_FOP_FAILED, "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); - - 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; -} + priv = this->private; + local = frame->local; -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; + CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind); - GF_VALIDATE_OR_GOTO ("changelog", this, out); - GF_VALIDATE_OR_GOTO ("changelog", this->fops, out); - GF_VALIDATE_OR_GOTO ("changelog", frame, out); + /* 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); - 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_smsg(this->name, GF_LOG_WARNING, 0, CHANGELOG_MSG_SET_FD_CONTEXT, + NULL); + } - 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_BARRIER_FOP_FAILED, "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 +1104,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; + CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 1); + if (!frame->local) + goto wind; - CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len); + co = changelog_get_usable_buffer(frame->local); + if (!co) + goto wind; - 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; + 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 +1363,255 @@ 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, + "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 +1619,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 +1772,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_smsg(this->name, GF_LOG_WARNING, 0, CHANGELOG_MSG_SET_FD_CONTEXT, + NULL); + } - 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 +1853,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 +1906,1084 @@ 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"); - } - - if (ret) - changelog_cleanup_helper_threads (this, priv); +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); - 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, }; +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, + }; + uint64_t xprtcnt = 0; + uint64_t clntcnt = 0; + changelog_clnt_t *conn = NULL; + gf_boolean_t cleanup_notify = _gf_false; + char sockfile[UNIX_PATH_MAX] = { + 0, + }; + rpcsvc_listener_t *listener = NULL; + rpcsvc_listener_t *next = NULL; + + INIT_LIST_HEAD(&queue); + + priv = this->private; + if (!priv) + goto out; + + if (event == GF_EVENT_PARENT_DOWN) { + priv->victim = data; + gf_log(this->name, GF_LOG_INFO, + "cleanup changelog rpc connection of brick %s", + priv->victim->name); + + if (priv->rpc_active) { + this->cleanup_starting = 1; + changelog_destroy_rpc_listner(this, priv); + conn = &priv->connections; + if (conn) + changelog_ev_cleanup_connections(this, conn); + xprtcnt = GF_ATOMIC_GET(priv->xprtcnt); + clntcnt = GF_ATOMIC_GET(priv->clntcnt); + if (!xprtcnt && !clntcnt) { + LOCK(&priv->lock); + { + cleanup_notify = priv->notify_down; + priv->notify_down = _gf_true; + } + UNLOCK(&priv->lock); + if (priv->rpc) { + list_for_each_entry_safe(listener, next, + &priv->rpc->listeners, list) + { + if (listener->trans) { + rpc_transport_unref(listener->trans); + } + } + rpcsvc_destroy(priv->rpc); + priv->rpc = NULL; + } + CHANGELOG_MAKE_SOCKET_PATH(priv->changelog_brick, sockfile, + UNIX_PATH_MAX); + sys_unlink(sockfile); + if (!cleanup_notify) + default_notify(this, GF_EVENT_PARENT_DOWN, data); + } + } else { + default_notify(this, GF_EVENT_PARENT_DOWN, data); + } + goto out; + } - INIT_LIST_HEAD (&queue); + if (event == GF_EVENT_TRANSLATOR_OP) { + dict = data; - priv = this->private; - if (!priv) - goto out; + barrier = dict_get_str_boolean(dict, "barrier", DICT_DEFAULT); - if (event == GF_EVENT_TRANSLATOR_OP) { + switch (barrier) { + case DICT_ERROR: + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_DICT_GET_FAILED, "dict_get_str_boolean", + NULL); + ret = -1; + goto out; - dict = data; + case BARRIER_OFF: + gf_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_MSG_BARRIER_STATE_NOTIFY, "off", NULL); - 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"); + LOCK(&priv->bflags.lock); + { + if (priv->bflags.barrier_ext == _gf_false) ret = -1; - goto out; + } + UNLOCK(&priv->bflags.lock); - case BARRIER_OFF: - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BARRIER_INFO, - "Barrier off notification"); + if (ret == -1) { + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_BARRIER_ERROR, NULL); + goto out; + } - CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, out); - LOCK(&priv->c_snap_lock); - { - changelog_snap_logging_stop (this, priv); - } - UNLOCK(&priv->c_snap_lock); + /* 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_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_MSG_BARRIER_DISABLED, NULL); + } else { + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_BARRIER_ALREADY_DISABLED, NULL); + } - 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; - } + LOCK(&priv->bflags.lock); + { + priv->bflags.barrier_ext = _gf_false; + } + UNLOCK(&priv->bflags.lock); - /* 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"); - } + goto out; - LOCK (&priv->bflags.lock); - { - priv->bflags.barrier_ext = _gf_false; - } - UNLOCK (&priv->bflags.lock); + case BARRIER_ON: + gf_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_MSG_BARRIER_STATE_NOTIFY, "on", NULL); - goto out; + CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, out); + LOCK(&priv->c_snap_lock); + { + changelog_snap_logging_start(this, priv); + } + UNLOCK(&priv->c_snap_lock); - case BARRIER_ON: - gf_msg (this->name, GF_LOG_INFO, 0, - CHANGELOG_MSG_BARRIER_INFO, - "Barrier on notification"); + LOCK(&priv->bflags.lock); + { + if (priv->bflags.barrier_ext == _gf_true) + ret = -1; + else + priv->bflags.barrier_ext = _gf_true; + } + UNLOCK(&priv->bflags.lock); - 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; - } + if (ret == -1) { + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_BARRIER_ON_ERROR, NULL); + 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; - } + 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); - 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; - } + /* 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; + } - 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"); - ret = -1; - goto out; + gf_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_MSG_BARRIER_ENABLE, NULL); - default: - gf_msg (this->name, GF_LOG_ERROR, EINVAL, - CHANGELOG_MSG_DICT_GET_FAILED, - "Something went bad in dict_get_str_boolean"); + ret = changelog_barrier_notify(priv, buf); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_WRITE_FAILED, "Explicit roll over", + NULL); + 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; - goto out; + priv->bn.bnotify_error = _gf_false; + } } - } else { - ret = default_notify (this, event, data); + ret1 = pthread_mutex_unlock(&priv->bn.bnotify_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret1, out, bclean_req); + gf_smsg(this->name, GF_LOG_INFO, 0, + CHANGELOG_MSG_BNOTIFY_COND_INFO, NULL); + + goto out; + + case DICT_DEFAULT: + gf_smsg(this->name, GF_LOG_ERROR, 0, + CHANGELOG_MSG_BARRIER_KEY_NOT_FOUND, NULL); + ret = -1; + goto out; + + default: + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, + CHANGELOG_MSG_ERROR_IN_DICT_GET, NULL); + ret = -1; + goto out; } + } else { + ret = default_notify(this, event, data); + } - out: - if (bclean_req) - changelog_barrier_cleanup (this, priv, &queue); +out: + if (bclean_req) + changelog_barrier_cleanup(this, priv, &queue); - return ret; + return ret; } int32_t -mem_acct_init (xlator_t *this) +mem_acct_init(xlator_t *this) { - int ret = -1; + int ret = -1; - if (!this) - return ret; + if (!this) + return ret; - ret = xlator_mem_acct_init (this, gf_changelog_mt_end + 1); - - if (ret != 0) { - gf_msg (this->name, GF_LOG_WARNING, ENOMEM, - CHANGELOG_MSG_NO_MEMORY, "Memory accounting" - " init failed"); - return ret; - } + ret = xlator_mem_acct_init(this, gf_changelog_mt_end + 1); + if (ret != 0) { + gf_smsg(this->name, GF_LOG_WARNING, ENOMEM, + CHANGELOG_MSG_MEMORY_INIT_FAILED, NULL); return ret; + } + + return ret; } static int -changelog_init (xlator_t *this, changelog_priv_t *priv) +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,}; + int i = 0; + int ret = 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 "; - 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; - } + for (; i < CHANGELOG_MAX_TYPE; i++) { + /* start with version 1 */ + priv->slice.changelog_version[i] = 1; + } - if (!priv->active) - return ret; + 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; + /** + * start with a fresh changelog file every time. this is done + * in case there was an encoding change. so... things are kept + * simple here. + */ + changelog_fill_rollover_data(&cld, _gf_false); - ret = htime_open (this, priv, cld.cld_roll_time); - /* call htime open with cld's rollover_time */ - 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); + 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); + /* ... and finally spawn the helpers threads */ + ret = changelog_spawn_helper_threads(this, priv); - out: - return ret; +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, "name=bnotify", + "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, "name=bnotify", + "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, "name=drain_black", + "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, "name=drain_black", + "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, "name=drain_white", + "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, "name=drain_white", + "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, + "name=changelog_rollover", "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; - } +static void +changelog_cleanup_rpc(xlator_t *this, changelog_priv_t *priv) +{ + /* terminate rpc server */ + if (!this->cleanup_starting) + changelog_destroy_rpc_listner(this, priv); - GF_FREE (priv->changelog_dir); - priv->changelog_dir = gf_strdup (tmp); - if (!priv->changelog_dir) - goto out; + (void)changelog_cleanup_rpc_threads(this, priv); + /* cleanup rot buffs */ + rbuf_dtor(priv->rbuf); - ret = mkdir_p (priv->changelog_dir, 0600, _gf_true); + /* cleanup poller thread */ + if (priv->poller) + (void)changelog_thread_cleanup(this, priv->poller); +} +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; + gf_boolean_t rpc_active_earlier = _gf_true; + gf_boolean_t rpc_active_now = _gf_true; + gf_boolean_t iniate_rpc = _gf_false; + changelog_time_slice_t *slice = NULL; + changelog_log_data_t cld = { + 0, + }; + char htime_dir[PATH_MAX] = { + 0, + }; + char csnap_dir[PATH_MAX] = { + 0, + }; + uint32_t timeout = 0; + + priv = this->private; + if (!priv) + goto out; + + ret = -1; + active_earlier = priv->active; + rpc_active_earlier = priv->rpc_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_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_DIR_OPTIONS_NOT_SET, + NULL); + 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); + GF_OPTION_RECONF("changelog-notification", rpc_active_now, options, bool, + out); + + /* If journalling is enabled, enable rpc notifications */ + if (active_now && !active_earlier) { + if (!rpc_active_earlier) + iniate_rpc = _gf_true; + } + + if (rpc_active_now && !rpc_active_earlier) { + iniate_rpc = _gf_true; + } + + /* TODO: Disable of changelog-notifications is not supported for now + * as there is no clean way of cleaning up of rpc resources + */ + + if (iniate_rpc) { + ret = changelog_init_rpc(this, priv); if (ret) - goto out; - CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, htime_dir); - ret = mkdir_p (htime_dir, 0600, _gf_true); + goto out; + priv->rpc_active = _gf_true; + } - if (ret) - goto out; + /** + * changelog_handle_change() handles changes that could possibly + * have been submit changes before changelog deactivation. + */ + if (!active_now) + priv->active = _gf_false; - CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir); - ret = mkdir_p (csnap_dir, 0600, _gf_true); + GF_OPTION_RECONF("op-mode", tmp, options, str, out); + changelog_assign_opmode(priv, tmp); - 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; + tmp = NULL; - GF_OPTION_RECONF ("op-mode", tmp, options, str, out); - changelog_assign_opmode (priv, tmp); + GF_OPTION_RECONF("encoding", tmp, options, str, out); + changelog_assign_encoding(priv, tmp); - tmp = NULL; + 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 ("encoding", tmp, options, str, out); - changelog_assign_encoding (priv, tmp); + GF_OPTION_RECONF("capture-del-path", priv->capture_del_path, options, bool, + out); - 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); + if (active_now || active_earlier) { + changelog_fill_rollover_data(&cld, !active_now); - GF_OPTION_RECONF ("capture-del-path", priv->capture_del_path, options, - bool, out); + slice = &priv->slice; - if (active_now || active_earlier) { - ret = changelog_fill_rollover_data (&cld, !active_now); - if (ret) - goto out; + LOCK(&priv->lock); + { + ret = changelog_inject_single_event(this, priv, &cld); + if (!ret && active_now) + SLICE_VERSION_UPDATE(slice); + } + UNLOCK(&priv->lock); - slice = &priv->slice; + if (ret) + goto out; - 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); - } + if (active_now) { + if (!active_earlier) { + gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_RECONFIGURE, + NULL); + htime_create(this, priv, gf_time()); + } + 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_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_FREEUP_FAILED, NULL); + 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("changelog-notification", priv->rpc_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; -} - -static void -changelog_cleanup_rpc (xlator_t *this, changelog_priv_t *priv) -{ - /* terminate rpc server */ - changelog_destroy_rpc_listner (this, priv); - - /* cleanup rot buffs */ - rbuf_dtor (priv->rbuf); - - /* cleanup poller thread */ - if (priv->poller) - (void) changelog_thread_cleanup (this, priv->poller); +dealloc_2: + GF_FREE(priv->changelog_dir); +dealloc_1: + GF_FREE(priv->changelog_brick); +error_return: + return -1; } 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; - +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_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_CHILD_MISCONFIGURED, + NULL); + goto error_return; + } + + if (!this->parents) { + gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_VOL_MISCONFIGURED, + NULL); + 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_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY, + NULL); + goto cleanup_priv; + } + + LOCK_INIT(&priv->lock); + LOCK_INIT(&priv->c_snap_lock); + GF_ATOMIC_INIT(priv->listnercnt, 0); + GF_ATOMIC_INIT(priv->clntcnt, 0); + GF_ATOMIC_INIT(priv->xprtcnt, 0); + INIT_LIST_HEAD(&priv->xprt_list); + priv->htime_fd = -1; + + 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; + + if (priv->rpc_active || priv->active) { /* RPC ball rolling.. */ - ret = changelog_init_rpc (this, priv); - if (ret) - goto cleanup_barrier; - - ret = changelog_init (this, priv); + ret = changelog_init_rpc(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; + goto cleanup_barrier; + priv->rpc_active = _gf_true; + } + + 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: + if (priv->rpc_active) { + 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); + this->local_pool = NULL; +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); - - /* call barrier_disable to cancel timer */ - if (priv->barrier_enabled) - __chlog_barrier_disable (this, &queue); - - /* cleanup barrier related objects */ - changelog_barrier_pthread_destroy (priv); + if (priv) { + if (priv->active || priv->rpc_active) { + /* terminate RPC server/threads */ + changelog_cleanup_rpc(this, priv); + GF_FREE(priv->ev_dispatcher); + } + /* call barrier_disable to cancel timer */ + if (priv->barrier_enabled) + __chlog_barrier_disable(this, &queue); - /* cleanup helper threads */ - changelog_cleanup_helper_threads (this, priv); + /* cleanup barrier related objects */ + changelog_barrier_pthread_destroy(priv); - /* cleanup allocated options */ - changelog_freeup_options (this, priv); + /* cleanup helper threads */ + changelog_cleanup_helper_threads(this, priv); - /* deallocate mempool */ - mem_pool_destroy (this->local_pool); + /* cleanup allocated options */ + changelog_freeup_options(this, priv); - if (priv->htime_fd != -1) { - sys_close (priv->htime_fd); - } + /* deallocate mempool */ + mem_pool_destroy(this->local_pool); - /* 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-notification"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "enable/disable changelog live notification", + .op_version = {3}, + .level = OPT_STATUS_BASIC, + .tags = {"bitrot", "georep"}}, + {.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}}, +}; + +xlator_api_t xlator_api = { + .init = init, + .fini = fini, + .notify = notify, + .reconfigure = reconfigure, + .mem_acct_init = mem_acct_init, + .op_version = {1}, /* Present from the initial version */ + .fops = &fops, + .cbks = &cbks, + .options = options, + .identifier = "changelog", + .category = GF_MAINTAINED, }; |
