glusterfs
77 строк · 1.7 Кб
1/*
2Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
3This file is part of GlusterFS.
4
5This file is licensed to you under your choice of the GNU Lesser
6General Public License, version 3 or any later version (LGPLv3 or
7later), or the GNU General Public License, version 2 (GPLv2), in all
8cases as published by the Free Software Foundation.
9*/
10
11#include "glusterfs/event-history.h"12#include "glusterfs/libglusterfs-messages.h"13
14eh_t *15eh_new(size_t buffer_size, gf_boolean_t use_buffer_once,16void (*destroy_buffer_data)(void *data))17{
18eh_t *history = NULL;19buffer_t *buffer = NULL;20
21history = GF_CALLOC(1, sizeof(eh_t), gf_common_mt_eh_t);22if (!history) {23goto out;24}25
26buffer = cb_buffer_new(buffer_size, use_buffer_once, destroy_buffer_data);27if (!buffer) {28GF_FREE(history);29history = NULL;30goto out;31}32
33history->buffer = buffer;34
35pthread_mutex_init(&history->lock, NULL);36out:37return history;38}
39
40void
41eh_dump(eh_t *history, void *data,42void (*dumper)(circular_buffer_t *buffer, void *data))43{
44if (history)45cb_buffer_dump(history->buffer, data, dumper);46else47gf_msg_debug("event-history", 0, "history is NULL");48}
49
50int
51eh_save_history(eh_t *history, void *data)52{
53int ret = -1;54
55ret = cb_add_entry_buffer(history->buffer, data);56
57return ret;58}
59
60int
61eh_destroy(eh_t *history)62{
63if (!history) {64gf_msg("event-history", GF_LOG_INFO, 0, LG_MSG_INVALID_ARG,65"history for the xlator is NULL");66return -1;67}68
69cb_buffer_destroy(history->buffer);70history->buffer = NULL;71
72pthread_mutex_destroy(&history->lock);73
74GF_FREE(history);75
76return 0;77}
78