diff options
Diffstat (limited to 'tests/utils/changelog')
| -rw-r--r-- | tests/utils/changelog/changelog.h | 125 | ||||
| -rw-r--r-- | tests/utils/changelog/get-history.c | 71 | ||||
| -rw-r--r-- | tests/utils/changelog/test-changelog-api.c | 98 | ||||
| -rw-r--r-- | tests/utils/changelog/test-history-api.c | 111 |
4 files changed, 405 insertions, 0 deletions
diff --git a/tests/utils/changelog/changelog.h b/tests/utils/changelog/changelog.h new file mode 100644 index 00000000000..1502b689eb4 --- /dev/null +++ b/tests/utils/changelog/changelog.h @@ -0,0 +1,125 @@ +/* + Copyright (c) 2013 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef _GF_CHANGELOG_H +#define _GF_CHANGELOG_H + +struct gf_brick_spec; + +/** + * Max bit shiter for event selection + */ +#define CHANGELOG_EV_SELECTION_RANGE 5 + +#define CHANGELOG_OP_TYPE_JOURNAL (1 << 0) +#define CHANGELOG_OP_TYPE_OPEN (1 << 1) +#define CHANGELOG_OP_TYPE_CREATE (1 << 2) +#define CHANGELOG_OP_TYPE_RELEASE (1 << 3) +#define CHANGELOG_OP_TYPE_BR_RELEASE \ + (1 << 4) /* logical release (last close()), \ + sent by bitrot stub */ +#define CHANGELOG_OP_TYPE_MAX (1 << CHANGELOG_EV_SELECTION_RANGE) + +struct ev_open { + unsigned char gfid[16]; + int32_t flags; +}; + +struct ev_creat { + unsigned char gfid[16]; + int32_t flags; +}; + +struct ev_release { + unsigned char gfid[16]; +}; + +struct ev_release_br { + unsigned long version; + unsigned char gfid[16]; + int32_t sign_info; +}; + +struct ev_changelog { + char path[PATH_MAX]; +}; + +typedef struct changelog_event { + unsigned int ev_type; + + union { + struct ev_open open; + struct ev_creat create; + struct ev_release release; + struct ev_changelog journal; + struct ev_release_br releasebr; + } u; +} changelog_event_t; + +#define CHANGELOG_EV_SIZE (sizeof(changelog_event_t)) + +/** + * event callback, connected & disconnection defs + */ +typedef void(CALLBACK)(void *, char *, void *, changelog_event_t *); +typedef void *(INIT)(void *, struct gf_brick_spec *); +typedef void(FINI)(void *, char *, void *); +typedef void(CONNECT)(void *, char *, void *); +typedef void(DISCONNECT)(void *, char *, void *); + +struct gf_brick_spec { + char *brick_path; + unsigned int filter; + + INIT *init; + FINI *fini; + CALLBACK *callback; + CONNECT *connected; + DISCONNECT *disconnected; + + void *ptr; +}; + +/* API set */ + +int +gf_changelog_register(char *brick_path, char *scratch_dir, char *log_file, + int log_levl, int max_reconnects); +ssize_t +gf_changelog_scan(); + +int +gf_changelog_start_fresh(); + +ssize_t +gf_changelog_next_change(char *bufptr, size_t maxlen); + +int +gf_changelog_done(char *file); + +/* newer flexible API */ +int +gf_changelog_init(void *xl); + +int +gf_changelog_register_generic(struct gf_brick_spec *bricks, int count, + int ordered, char *logfile, int lvl, void *xl); + +int +gf_history_changelog(char *changelog_dir, unsigned long start, + unsigned long end, int n_parallel, + unsigned long *actual_end); +int +gf_history_changelog_scan(); +ssize_t +gf_history_changelog_next_change(char *bufptr, size_t maxlen); +int +gf_history_changelog_done(char *file); +#endif diff --git a/tests/utils/changelog/get-history.c b/tests/utils/changelog/get-history.c new file mode 100644 index 00000000000..9963ab76958 --- /dev/null +++ b/tests/utils/changelog/get-history.c @@ -0,0 +1,71 @@ +/* + Copyright (c) 2013 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +/** + * get set of new changes every 10 seconds (just print the file names) + * + * Compile it using: + * gcc -o gethistory `pkg-config --cflags libgfchangelog` get-history.c \ + * `pkg-config --libs libgfchangelog` + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/un.h> +#include <limits.h> +#include <sys/socket.h> +#include <sys/types.h> + +#include "changelog.h" + +int +main(int argc, char **argv) +{ + int ret = 0; + unsigned long end_ts = 0; + int start = 0; + int end = 0; + + ret = gf_changelog_init(NULL); + if (ret) { + printf("-1"); + fflush(stdout); + return -1; + } + + ret = gf_changelog_register("/d/backends/patchy0", "/tmp/scratch_v1", + "/var/log/glusterfs/changes.log", 9, 5); + if (ret) { + printf("-2"); + fflush(stdout); + return -1; + } + + start = atoi(argv[1]); + end = atoi(argv[2]); + + ret = gf_history_changelog("/d/backends/patchy0/.glusterfs/changelogs", + start, end, 3, &end_ts); + if (ret < 0) { + printf("-3"); + fflush(stdout); + return -1; + } else if (ret == 1) { + printf("1"); + fflush(stdout); + return 0; + } + +out: + printf("0"); + fflush(stdout); + return 0; +} diff --git a/tests/utils/changelog/test-changelog-api.c b/tests/utils/changelog/test-changelog-api.c new file mode 100644 index 00000000000..f4eb066b630 --- /dev/null +++ b/tests/utils/changelog/test-changelog-api.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2019 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +/** + * get set of new changes every 5 seconds (just print the file names) + * + * Compile it using: + * gcc -o getchanges `pkg-config --cflags libgfchangelog` get-changes.c \ + * `pkg-config --libs libgfchangelog` + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/un.h> +#include <limits.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <errno.h> + +#include "changelog.h" + +int +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) { + printf("-1"); + fflush(stdout); + return -1; + } + + /* get changes for brick "/d/backends/patchy0" */ + ret = gf_changelog_register("/d/backends/patchy0", "/tmp/scratch_v1", + "/var/log/glusterfs/changes.log", 9, 5); + if (ret) { + printf("-2"); + fflush(stdout); + return -1; + } + + while (1) { + i = 0; + nr_changes = gf_changelog_scan(); + if (nr_changes < 0) { + printf("-4"); + fflush(stdout); + return -1; + } + + if (nr_changes == 0) + goto next; + + while ((changes = gf_changelog_next_change(fbuf, PATH_MAX)) > 0) { + /* process changelog */ + /* ... */ + /* ... */ + /* ... */ + /* done processing */ + + ret = gf_changelog_done(fbuf); + if (ret) { + printf("-5"); + fflush(stdout); + return -1; + } + } + + if (changes == -1) { + printf("-6"); + fflush(stdout); + return -1; + } + + next: + sleep(2); + } + +out: + printf("0"); + fflush(stdout); + return ret; +} diff --git a/tests/utils/changelog/test-history-api.c b/tests/utils/changelog/test-history-api.c new file mode 100644 index 00000000000..d78e387df10 --- /dev/null +++ b/tests/utils/changelog/test-history-api.c @@ -0,0 +1,111 @@ +/* + Copyright (c) 2013 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +/** + * get set of new changes every 10 seconds (just print the file names) + * + * Compile it using: + * gcc -o gethistory `pkg-config --cflags libgfchangelog` get-history.c \ + * `pkg-config --libs libgfchangelog` + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/un.h> +#include <limits.h> +#include <sys/socket.h> +#include <sys/types.h> + +#include "changelog.h" + +int +main(int argc, char **argv) +{ + int ret = 0; + int i = 0; + unsigned long end_ts = 0; + ssize_t nr_changes = 0; + ssize_t changes = 0; + int start = 0; + int end = 0; + char fbuf[PATH_MAX] = { + 0, + }; + + ret = gf_changelog_init(NULL); + if (ret) { + printf("-1"); + fflush(stdout); + return -1; + } + + ret = gf_changelog_register("/d/backends/patchy0", "/tmp/scratch_v1", + "/var/log/glusterfs/changes.log", 9, 5); + if (ret) { + printf("-2"); + fflush(stdout); + return -1; + } + + start = atoi(argv[1]); + end = atoi(argv[2]); + + ret = gf_history_changelog("/d/backends/patchy0/.glusterfs/changelogs", + start, end, 3, &end_ts); + if (ret < 0) { + printf("-3"); + fflush(stdout); + return -1; + } else if (ret == 1) { + printf("1"); + fflush(stdout); + return 0; + } + + while (1) { + nr_changes = gf_history_changelog_scan(); + if (nr_changes < 0) { + printf("-4"); + fflush(stdout); + return -1; + } + + if (nr_changes == 0) { + goto out; + } + + while ((changes = gf_history_changelog_next_change(fbuf, PATH_MAX)) > + 0) { + /* process changelog */ + /* ... */ + /* ... */ + /* ... */ + /* done processing */ + + ret = gf_history_changelog_done(fbuf); + if (ret) { + printf("-5"); + fflush(stdout); + return -1; + } + } + if (changes == -1) { + printf("-6"); + fflush(stdout); + return -1; + } + } + +out: + printf("0"); + fflush(stdout); + return 0; +} |
