summaryrefslogtreecommitdiffstats
path: root/xlators/features/changelog/src/changelog-misc.h
blob: 257c1f34218386c8febc118d15539cd110d57dc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
   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 _CHANGELOG_MISC_H
#define _CHANGELOG_MISC_H

#include "glusterfs.h"
#include "common-utils.h"

#define CHANGELOG_MAX_TYPE  3
#define CHANGELOG_FILE_NAME "CHANGELOG"
#define HTIME_FILE_NAME "HTIME"
#define HTIME_KEY "trusted.glusterfs.htime"
#define HTIME_INITIAL_VALUE "0:0"

#define CHANGELOG_VERSION_MAJOR  1
#define CHANGELOG_VERSION_MINOR  1

#define CHANGELOG_UNIX_SOCK  DEFAULT_VAR_RUN_DIRECTORY"/changelog-%s.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 md5_sum[MD5_DIGEST_LENGTH*2+1] = {0,};             \
                md5_wrapper((unsigned char *) brick_path,               \
                            strlen(brick_path),                         \
                            md5_sum);                                   \
                (void) snprintf (sockpath, len,                         \
                                 CHANGELOG_UNIX_SOCK, md5_sum);         \
        } while (0)

/**
 * ... used by libgfchangelog.
 */
#define CHANGELOG_GET_ENCODING(fd, buffer, len, enc, enc_len) do {      \
                FILE *fp;                                               \
                int fd_dup, maj, min;                                   \
                                                                        \
                enc = -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 {                                        \
                                close (fd_dup);                         \
                        }                                               \
                }                                                       \
        } while (0)

#define CHANGELOG_FILL_HTIME_DIR(changelog_dir, path) do {      \
                strcpy (path, changelog_dir);                   \
                strcat (path, "/htime");                        \
        } while(0)
/**
 * everything after 'CHANGELOG_TYPE_ENTRY' are internal types
 * (ie. none of the fops trigger this type of event), hence
 * CHANGELOG_MAX_TYPE = 3
 */
typedef enum {
        CHANGELOG_TYPE_DATA = 0,
        CHANGELOG_TYPE_METADATA,
        CHANGELOG_TYPE_ENTRY,
        CHANGELOG_TYPE_ROLLOVER,
        CHANGELOG_TYPE_FSYNC,
} changelog_log_type;

/* operation modes - RT for now */
typedef enum {
        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_encoder_t;

#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)

#endif /* _CHANGELOG_MISC_H */