"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/features/changelog/src/changelog-misc.h" (16 Sep 2020, 6127 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "changelog-misc.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2    Copyright (c) 2013 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 #ifndef _CHANGELOG_MISC_H
   12 #define _CHANGELOG_MISC_H
   13 
   14 #include <glusterfs/glusterfs.h>
   15 #include <glusterfs/common-utils.h>
   16 
   17 #define CHANGELOG_MAX_TYPE 4
   18 #define CHANGELOG_FILE_NAME "CHANGELOG"
   19 #define HTIME_FILE_NAME "HTIME"
   20 #define CSNAP_FILE_NAME "CHANGELOG.SNAP"
   21 #define HTIME_KEY "trusted.glusterfs.htime"
   22 #define HTIME_CURRENT "trusted.glusterfs.current_htime"
   23 #define HTIME_INITIAL_VALUE "0:0"
   24 
   25 #define CHANGELOG_VERSION_MAJOR 1
   26 #define CHANGELOG_VERSION_MINOR 2
   27 
   28 #define CHANGELOG_UNIX_SOCK DEFAULT_VAR_RUN_DIRECTORY "/changelog-%s.sock"
   29 #define CHANGELOG_TMP_UNIX_SOCK DEFAULT_VAR_RUN_DIRECTORY "/.%s%lu.sock"
   30 
   31 /**
   32  * header starts with the version and the format of the changelog.
   33  * 'version' not much of a use now.
   34  */
   35 #define CHANGELOG_HEADER                                                       \
   36     "GlusterFS Changelog | version: v%d.%d | encoding : %d\n"
   37 
   38 #define CHANGELOG_MAKE_SOCKET_PATH(brick_path, sockpath, len)                  \
   39     do {                                                                       \
   40         char xxh64[GF_XXH64_DIGEST_LENGTH * 2 + 1] = {                         \
   41             0,                                                                 \
   42         };                                                                     \
   43         gf_xxh64_wrapper((unsigned char *)brick_path, strlen(brick_path),      \
   44                          GF_XXHSUM64_DEFAULT_SEED, xxh64);                     \
   45         (void)snprintf(sockpath, len, CHANGELOG_UNIX_SOCK, xxh64);             \
   46     } while (0)
   47 
   48 #define CHANGELOG_MAKE_TMP_SOCKET_PATH(brick_path, sockpath, len)              \
   49     do {                                                                       \
   50         unsigned long pid = 0;                                                 \
   51         char xxh64[GF_XXH64_DIGEST_LENGTH * 2 + 1] = {                         \
   52             0,                                                                 \
   53         };                                                                     \
   54         pid = (unsigned long)getpid();                                         \
   55         gf_xxh64_wrapper((unsigned char *)brick_path, strlen(brick_path),      \
   56                          GF_XXHSUM64_DEFAULT_SEED, xxh64);                     \
   57         (void)snprintf(sockpath, len, CHANGELOG_TMP_UNIX_SOCK, xxh64, pid);    \
   58     } while (0)
   59 
   60 /**
   61  * ... used by libgfchangelog.
   62  */
   63 #define CHANGELOG_GET_HEADER_INFO(fd, buffer, len, enc, maj, min, elen)        \
   64     do {                                                                       \
   65         FILE *fp;                                                              \
   66         int fd_dup;                                                            \
   67                                                                                \
   68         enc = -1;                                                              \
   69         maj = -1;                                                              \
   70         min = -1;                                                              \
   71         fd_dup = dup(fd);                                                      \
   72                                                                                \
   73         if (fd_dup != -1) {                                                    \
   74             fp = fdopen(fd_dup, "r");                                          \
   75             if (fp) {                                                          \
   76                 if (fgets(buffer, len, fp)) {                                  \
   77                     elen = strlen(buffer);                                     \
   78                     sscanf(buffer, CHANGELOG_HEADER, &maj, &min, &enc);        \
   79                 }                                                              \
   80                 fclose(fp);                                                    \
   81             } else {                                                           \
   82                 sys_close(fd_dup);                                             \
   83             }                                                                  \
   84         }                                                                      \
   85     } while (0)
   86 
   87 #define CHANGELOG_FILL_HTIME_DIR(changelog_dir, path)                          \
   88     do {                                                                       \
   89         snprintf(path, sizeof(path), "%s/htime", changelog_dir);               \
   90     } while (0)
   91 
   92 #define CHANGELOG_FILL_CSNAP_DIR(changelog_dir, path)                          \
   93     do {                                                                       \
   94         snprintf(path, sizeof(path), "%s/csnap", changelog_dir);               \
   95     } while (0)
   96 /**
   97  * everything after 'CHANGELOG_TYPE_METADATA_XATTR' are internal types
   98  * (ie. none of the fops trigger this type of event), hence
   99  * CHANGELOG_MAX_TYPE = 4
  100  */
  101 typedef enum {
  102     CHANGELOG_TYPE_DATA = 0,
  103     CHANGELOG_TYPE_METADATA,
  104     CHANGELOG_TYPE_ENTRY,
  105     CHANGELOG_TYPE_METADATA_XATTR,
  106     CHANGELOG_TYPE_ROLLOVER,
  107     CHANGELOG_TYPE_FSYNC,
  108 } changelog_log_type;
  109 
  110 /* operation modes - RT for now */
  111 typedef enum {
  112     CHANGELOG_MODE_RT = 0,
  113 } changelog_mode_t;
  114 
  115 /* encoder types */
  116 
  117 typedef enum {
  118     CHANGELOG_ENCODE_MIN = 0,
  119     CHANGELOG_ENCODE_BINARY,
  120     CHANGELOG_ENCODE_ASCII,
  121     CHANGELOG_ENCODE_MAX,
  122 } changelog_encoder_t;
  123 
  124 #define CHANGELOG_VALID_ENCODING(enc)                                          \
  125     (enc > CHANGELOG_ENCODE_MIN && enc < CHANGELOG_ENCODE_MAX)
  126 
  127 #define CHANGELOG_TYPE_IS_ENTRY(type) (type == CHANGELOG_TYPE_ENTRY)
  128 #define CHANGELOG_TYPE_IS_ROLLOVER(type) (type == CHANGELOG_TYPE_ROLLOVER)
  129 #define CHANGELOG_TYPE_IS_FSYNC(type) (type == CHANGELOG_TYPE_FSYNC)
  130 
  131 #endif /* _CHANGELOG_MISC_H */