glusterfs

Форк
0
/
event-history.c 
77 строк · 1.7 Кб
1
/*
2
  Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
3
  This file is part of GlusterFS.
4

5
  This file is licensed to you under your choice of the GNU Lesser
6
  General Public License, version 3 or any later version (LGPLv3 or
7
  later), or the GNU General Public License, version 2 (GPLv2), in all
8
  cases as published by the Free Software Foundation.
9
*/
10

11
#include "glusterfs/event-history.h"
12
#include "glusterfs/libglusterfs-messages.h"
13

14
eh_t *
15
eh_new(size_t buffer_size, gf_boolean_t use_buffer_once,
16
       void (*destroy_buffer_data)(void *data))
17
{
18
    eh_t *history = NULL;
19
    buffer_t *buffer = NULL;
20

21
    history = GF_CALLOC(1, sizeof(eh_t), gf_common_mt_eh_t);
22
    if (!history) {
23
        goto out;
24
    }
25

26
    buffer = cb_buffer_new(buffer_size, use_buffer_once, destroy_buffer_data);
27
    if (!buffer) {
28
        GF_FREE(history);
29
        history = NULL;
30
        goto out;
31
    }
32

33
    history->buffer = buffer;
34

35
    pthread_mutex_init(&history->lock, NULL);
36
out:
37
    return history;
38
}
39

40
void
41
eh_dump(eh_t *history, void *data,
42
        void (*dumper)(circular_buffer_t *buffer, void *data))
43
{
44
    if (history)
45
        cb_buffer_dump(history->buffer, data, dumper);
46
    else
47
        gf_msg_debug("event-history", 0, "history is NULL");
48
}
49

50
int
51
eh_save_history(eh_t *history, void *data)
52
{
53
    int ret = -1;
54

55
    ret = cb_add_entry_buffer(history->buffer, data);
56

57
    return ret;
58
}
59

60
int
61
eh_destroy(eh_t *history)
62
{
63
    if (!history) {
64
        gf_msg("event-history", GF_LOG_INFO, 0, LG_MSG_INVALID_ARG,
65
               "history for the xlator is NULL");
66
        return -1;
67
    }
68

69
    cb_buffer_destroy(history->buffer);
70
    history->buffer = NULL;
71

72
    pthread_mutex_destroy(&history->lock);
73

74
    GF_FREE(history);
75

76
    return 0;
77
}
78

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.