summaryrefslogtreecommitdiffstats
path: root/xlators/features/changelog/lib/src/gf-changelog.c
diff options
context:
space:
mode:
authorKotresh H R <khiremat@redhat.com>2014-02-13 23:53:27 +0530
committerVijay Bellur <vbellur@redhat.com>2014-04-28 04:53:36 -0700
commitf2bac9f9d5b9956969ddd25a54bc636b82f6923e (patch)
treefa0a3987f4685e6e8a83dbb9234c860757dd5304 /xlators/features/changelog/lib/src/gf-changelog.c
parent54a5a42848870ee17b923c6c37d65fdfe4a5fec9 (diff)
features/libgfchangelog: APIs to process history changelogs.
1. Create directories in following fashion for history API's usage when consumer is registered with libgfchangelog shared library through gf_changelog_register. scratch_dir/.history scratch_dir/.history/.current scratch_dir/.history/.processed scratch_dir/.history/.processing 2. Added new file 'gf-history-changelog.c' and following APIs are provided for consumers to process history changelogs. 1. gf_history_changelog_scan: Move processed history changelog file from .processing to .processed 2. gf_history_changelog_next_change: Return the next history changelog file entry. Zero means all history chanelogs are consumed. 3. gf_history_changelog_done: Scan .processing directory and generate a list of change entries. 4. gf_history_changelog_start_fresh: For a set of changelogs, start from the begining. NOTE: Though this patch provides above funcationalities. It is considered functionally full with the patch (http://review.gluster.org/#/c/6930/). Change-Id: I200780c7278e0a6c008910d93faad5858a4b3e76 Original-author: Kotresh H R <khiremat@redhat.com> Signed-off-by: Kotresh H R <khiremat@redhat.com> Signed-off-by: Ajeet Jha <ajha@redhat.com> Reviewed-on: http://review.gluster.org/6998 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Venky Shankar <vshankar@redhat.com> Tested-by: Venky Shankar <vshankar@redhat.com>
Diffstat (limited to 'xlators/features/changelog/lib/src/gf-changelog.c')
-rw-r--r--xlators/features/changelog/lib/src/gf-changelog.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/xlators/features/changelog/lib/src/gf-changelog.c b/xlators/features/changelog/lib/src/gf-changelog.c
index 4b2b25ad573..0827f2cac6c 100644
--- a/xlators/features/changelog/lib/src/gf-changelog.c
+++ b/xlators/features/changelog/lib/src/gf-changelog.c
@@ -82,6 +82,10 @@ __attribute__ ((destructor)) gf_changelog_dtor (void)
gfc = this->private;
if (gfc) {
+ if (gfc->hist_gfc) {
+ gf_changelog_cleanup(gfc->hist_gfc);
+ GF_FREE (gfc->hist_gfc);
+ }
gf_changelog_cleanup (gfc);
GF_FREE (gfc);
}
@@ -437,6 +441,7 @@ gf_changelog_register (char *brick_path, char *scratch_dir,
int errn = 0;
xlator_t *this = NULL;
gf_changelog_t *gfc = NULL;
+ char hist_scratch_dir[PATH_MAX] = {0,};
this = THIS;
if (!this->ctx)
@@ -460,6 +465,52 @@ gf_changelog_register (char *brick_path, char *scratch_dir,
goto cleanup;
}
+ /* Begin: Changes for History API */
+ gfc->hist_gfc = NULL;
+
+ gfc->hist_gfc = GF_CALLOC (1, sizeof (*gfc),
+ gf_changelog_mt_libgfchangelog_t);
+ if (!gfc->hist_gfc)
+ goto cleanup;
+
+ gfc->hist_gfc->gfc_dir = NULL;
+ gfc->hist_gfc->gfc_fd = gfc->hist_gfc->gfc_sockfd = -1;
+ gfc->hist_gfc->this = NULL;
+
+ (void) strncpy (hist_scratch_dir, scratch_dir, PATH_MAX);
+ (void) snprintf (hist_scratch_dir, PATH_MAX,
+ "%s/"GF_CHANGELOG_HISTORY_DIR"/",
+ gfc->gfc_working_dir);
+
+ ret = mkdir_p (hist_scratch_dir, 0600, _gf_false);
+ if (ret) {
+ errn = errno;
+ goto cleanup;
+ }
+
+ gfc->hist_gfc->gfc_working_dir = realpath (hist_scratch_dir, NULL);
+ if (!gfc->hist_gfc->gfc_working_dir) {
+ errn = errno;
+ goto cleanup;
+ }
+
+ ret = gf_changelog_open_dirs (gfc->hist_gfc);
+ if (ret) {
+ errn = errno;
+ gf_log (this->name, GF_LOG_ERROR,
+ "could not create entries in history scratch dir");
+ goto cleanup;
+ }
+
+ (void) strncpy (gfc->hist_gfc->gfc_brickpath, brick_path, PATH_MAX);
+
+ for (i=0; i < 256; i++) {
+ gfc->hist_gfc->rfc3986[i] =
+ (isalnum(i) || i == '~' ||
+ i == '-' || i == '.' || i == '_') ? i : 0;
+ }
+ /* End: Changes for History API*/
+
ret = gf_changelog_open_dirs (gfc);
if (ret) {
errn = errno;
@@ -494,7 +545,7 @@ gf_changelog_register (char *brick_path, char *scratch_dir,
goto cleanup;
}
- for (; i < 256; i++) {
+ for (i=0; i < 256; i++) {
gfc->rfc3986[i] =
(isalnum(i) || i == '~' ||
i == '-' || i == '.' || i == '_') ? i : 0;
@@ -506,6 +557,10 @@ gf_changelog_register (char *brick_path, char *scratch_dir,
goto out;
cleanup:
+ if (gfc->hist_gfc) {
+ gf_changelog_cleanup (gfc->hist_gfc);
+ GF_FREE (gfc->hist_gfc);
+ }
gf_changelog_cleanup (gfc);
GF_FREE (gfc);
this->private = NULL;