"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/features/snapview-server/src/snapview-server.h" (16 Sep 2020, 10305 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 "snapview-server.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2    Copyright (c) 2014 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 #ifndef __SNAP_VIEW_H__
   11 #define __SNAP_VIEW_H__
   12 
   13 #include <glusterfs/dict.h>
   14 #include <glusterfs/defaults.h>
   15 #include <glusterfs/mem-types.h>
   16 #include <glusterfs/call-stub.h>
   17 #include <glusterfs/byte-order.h>
   18 #include <glusterfs/iatt.h>
   19 #include <ctype.h>
   20 #include <sys/uio.h>
   21 #include <glusterfs/glusterfs.h>
   22 #include <glusterfs/logging.h>
   23 #include "glfs.h"
   24 #include "glfs-handles.h"
   25 #include "glfs-internal.h"
   26 #include "glusterfs3-xdr.h"
   27 #include <glusterfs/glusterfs-acl.h>
   28 #include <glusterfs/syncop.h>
   29 #include <glusterfs/list.h>
   30 #include <glusterfs/timer.h>
   31 #include "rpc-clnt.h"
   32 #include "protocol-common.h"
   33 #include "xdr-generic.h"
   34 #include "snapview-server-messages.h"
   35 
   36 #define DEFAULT_SVD_LOG_FILE_DIRECTORY DATADIR "/log/glusterfs"
   37 
   38 #define SNAP_VIEW_MAX_GLFS_T 256
   39 #define SNAP_VIEW_MAX_GLFS_FDS 1024
   40 #define SNAP_VIEW_MAX_GLFS_OBJ_HANDLES 1024
   41 
   42 #define SVS_STACK_DESTROY(_frame)                                              \
   43     do {                                                                       \
   44         ((call_frame_t *)_frame)->local = NULL;                                \
   45         STACK_DESTROY(((call_frame_t *)_frame)->root);                         \
   46     } while (0)
   47 
   48 #define SVS_CHECK_VALID_SNAPSHOT_HANDLE(fs, this)                              \
   49     do {                                                                       \
   50         svs_private_t *_private = NULL;                                        \
   51         _private = this->private;                                              \
   52         int i = 0;                                                             \
   53         gf_boolean_t found = _gf_false;                                        \
   54         glfs_t *tmp_fs = NULL;                                                 \
   55         LOCK(&_private->snaplist_lock);                                        \
   56         {                                                                      \
   57             for (i = 0; i < _private->num_snaps; i++) {                        \
   58                 tmp_fs = _private->dirents[i].fs;                              \
   59                 gf_log(this->name, GF_LOG_DEBUG,                               \
   60                        "snap name: %s, snap volume: %s,"                       \
   61                        "dirent->fs: %p",                                       \
   62                        _private->dirents[i].name,                              \
   63                        _private->dirents[i].snap_volname, tmp_fs);             \
   64                 if (tmp_fs && fs && (tmp_fs == fs)) {                          \
   65                     found = _gf_true;                                          \
   66                     gf_msg_debug(this->name, 0,                                \
   67                                  "found the fs "                               \
   68                                  "instance");                                  \
   69                     break;                                                     \
   70                 }                                                              \
   71             }                                                                  \
   72         }                                                                      \
   73         UNLOCK(&_private->snaplist_lock);                                      \
   74                                                                                \
   75         if (!found) {                                                          \
   76             gf_log(this->name, GF_LOG_WARNING,                                 \
   77                    "failed to"                                                 \
   78                    " find the fs instance %p",                                 \
   79                    fs);                                                        \
   80             fs = NULL;                                                         \
   81         }                                                                      \
   82     } while (0)
   83 
   84 #define SVS_GET_INODE_CTX_INFO(inode_ctx, fs, object, this, loc, ret,          \
   85                                op_errno, label)                                \
   86     do {                                                                       \
   87         fs = inode_ctx->fs;                                                    \
   88         object = inode_ctx->object;                                            \
   89         SVS_CHECK_VALID_SNAPSHOT_HANDLE(fs, this);                             \
   90         if (!fs)                                                               \
   91             object = NULL;                                                     \
   92                                                                                \
   93         if (!fs || !object) {                                                  \
   94             int32_t tmp = -1;                                                  \
   95             char tmp_uuid[64];                                                 \
   96                                                                                \
   97             tmp = svs_get_handle(this, loc, inode_ctx, &op_errno);             \
   98             if (tmp) {                                                         \
   99                 gf_log(this->name, GF_LOG_ERROR,                               \
  100                        "failed to get the handle for %s "                      \
  101                        "(gfid: %s)",                                           \
  102                        loc->path, uuid_utoa_r(loc->inode->gfid, tmp_uuid));    \
  103                 ret = -1;                                                      \
  104                 goto label;                                                    \
  105             }                                                                  \
  106                                                                                \
  107             fs = inode_ctx->fs;                                                \
  108             object = inode_ctx->object;                                        \
  109         }                                                                      \
  110     } while (0);
  111 
  112 #define SVS_STRDUP(dst, src)                                                   \
  113     do {                                                                       \
  114         if (dst && strcmp(src, dst)) {                                         \
  115             GF_FREE(dst);                                                      \
  116             dst = NULL;                                                        \
  117         }                                                                      \
  118                                                                                \
  119         if (!dst)                                                              \
  120             dst = gf_strdup(src);                                              \
  121     } while (0)
  122 
  123 int
  124 svs_mgmt_submit_request(void *req, call_frame_t *frame, glusterfs_ctx_t *ctx,
  125                         rpc_clnt_prog_t *prog, int procnum, fop_cbk_fn_t cbkfn,
  126                         xdrproc_t xdrproc);
  127 
  128 int
  129 svs_get_snapshot_list(xlator_t *this);
  130 
  131 int
  132 mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count,
  133                       void *myframe);
  134 
  135 typedef enum {
  136     SNAP_VIEW_ENTRY_POINT_INODE = 0,
  137     SNAP_VIEW_SNAPSHOT_INODE,
  138     SNAP_VIEW_VIRTUAL_INODE
  139 } inode_type_t;
  140 
  141 struct svs_inode {
  142     glfs_t *fs;
  143     glfs_object_t *object;
  144     inode_type_t type;
  145 
  146     /* used only for entry point directory where gfid of the directory
  147        from where the entry point was entered is saved.
  148     */
  149     uuid_t pargfid;
  150 
  151     /* This is used to generate gfid for all sub files/dirs under this
  152      * snapshot
  153      */
  154     char *snapname;
  155     struct iatt buf;
  156 };
  157 typedef struct svs_inode svs_inode_t;
  158 
  159 struct svs_fd {
  160     glfs_fd_t *fd;
  161 };
  162 typedef struct svs_fd svs_fd_t;
  163 
  164 struct snap_dirent {
  165     char name[NAME_MAX];
  166     char uuid[UUID_CANONICAL_FORM_LEN + 1];
  167     char snap_volname[NAME_MAX];
  168     glfs_t *fs;
  169 };
  170 typedef struct snap_dirent snap_dirent_t;
  171 
  172 struct svs_private {
  173     snap_dirent_t *dirents;
  174     int num_snaps;
  175     char *volname;
  176     struct list_head snaplist;
  177     gf_lock_t snaplist_lock;
  178     struct rpc_clnt *rpc;
  179 };
  180 typedef struct svs_private svs_private_t;
  181 
  182 int
  183 __svs_inode_ctx_set(xlator_t *this, inode_t *inode, svs_inode_t *svs_inode);
  184 
  185 svs_inode_t *
  186 __svs_inode_ctx_get(xlator_t *this, inode_t *inode);
  187 
  188 svs_inode_t *
  189 svs_inode_ctx_get(xlator_t *this, inode_t *inode);
  190 
  191 int32_t
  192 svs_inode_ctx_set(xlator_t *this, inode_t *inode, svs_inode_t *svs_inode);
  193 
  194 svs_inode_t *
  195 svs_inode_ctx_get_or_new(xlator_t *this, inode_t *inode);
  196 
  197 int
  198 __svs_fd_ctx_set(xlator_t *this, fd_t *fd, svs_fd_t *svs_fd);
  199 
  200 svs_fd_t *
  201 __svs_fd_ctx_get(xlator_t *this, fd_t *fd);
  202 
  203 svs_fd_t *
  204 svs_fd_ctx_get(xlator_t *this, fd_t *fd);
  205 
  206 int32_t
  207 svs_fd_ctx_set(xlator_t *this, fd_t *fd, svs_fd_t *svs_fd);
  208 
  209 svs_fd_t *
  210 __svs_fd_ctx_get_or_new(xlator_t *this, fd_t *fd);
  211 
  212 svs_fd_t *
  213 svs_fd_ctx_get_or_new(xlator_t *this, fd_t *fd);
  214 
  215 int
  216 svs_uuid_generate(xlator_t *this, uuid_t gfid, char *snapname,
  217                   uuid_t origin_gfid);
  218 
  219 void
  220 svs_fill_ino_from_gfid(struct iatt *buf);
  221 
  222 void
  223 svs_iatt_fill(uuid_t gfid, struct iatt *buf);
  224 
  225 snap_dirent_t *
  226 svs_get_latest_snap_entry(xlator_t *this);
  227 
  228 glfs_t *
  229 svs_get_latest_snapshot(xlator_t *this);
  230 
  231 glfs_t *
  232 svs_initialise_snapshot_volume(xlator_t *this, const char *name,
  233                                int32_t *op_errno);
  234 
  235 glfs_t *
  236 __svs_initialise_snapshot_volume(xlator_t *this, const char *name,
  237                                  int32_t *op_errno);
  238 
  239 snap_dirent_t *
  240 __svs_get_snap_dirent(xlator_t *this, const char *name);
  241 
  242 int
  243 svs_mgmt_init(xlator_t *this);
  244 
  245 int32_t
  246 svs_get_handle(xlator_t *this, loc_t *loc, svs_inode_t *inode_ctx,
  247                int32_t *op_errno);
  248 
  249 glfs_t *
  250 svs_inode_glfs_mapping(xlator_t *this, inode_t *inode);
  251 
  252 glfs_t *
  253 svs_inode_ctx_glfs_mapping(xlator_t *this, svs_inode_t *inode_ctx);
  254 
  255 #endif /* __SNAP_VIEW_H__ */