"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/storage/posix/src/posix-handle.h" (16 Sep 2020, 14132 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 "posix-handle.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2    Copyright (c) 2011-2017 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 _POSIX_HANDLE_H
   11 #define _POSIX_HANDLE_H
   12 
   13 #include "posix-inode-handle.h"
   14 
   15 #define HANDLE_ABSPATH_LEN(this)                                               \
   16     (POSIX_BASE_PATH_LEN(this) +                                               \
   17      SLEN("/" GF_HIDDEN_PATH "/00/00/" UUID0_STR) + 1)
   18 
   19 #define MAKE_PGFID_XATTR_KEY(var, prefix, pgfid)                               \
   20     do {                                                                       \
   21         var = alloca(SLEN(prefix) + UUID_CANONICAL_FORM_LEN + 1);              \
   22         strcpy(var, prefix);                                                   \
   23         strcat(var, uuid_utoa(pgfid));                                         \
   24     } while (0)
   25 
   26 #define SET_PGFID_XATTR(path, key, value, flags, op_ret, this, label)          \
   27     do {                                                                       \
   28         value = hton32(value);                                                 \
   29         op_ret = sys_lsetxattr(path, key, &value, sizeof(value), flags);       \
   30         if (op_ret == -1) {                                                    \
   31             op_errno = errno;                                                  \
   32             gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP,          \
   33                    "setting xattr failed on %s: key = %s ", path, key);        \
   34             goto label;                                                        \
   35         }                                                                      \
   36     } while (0)
   37 
   38 #define SET_PGFID_XATTR_IF_ABSENT(path, key, value, flags, op_ret, this,       \
   39                                   label)                                       \
   40     do {                                                                       \
   41         op_ret = sys_lgetxattr(path, key, &value, sizeof(value));              \
   42         if (op_ret == -1) {                                                    \
   43             op_errno = errno;                                                  \
   44             if (op_errno == ENOATTR) {                                         \
   45                 value = 1;                                                     \
   46                 SET_PGFID_XATTR(path, key, value, flags, op_ret, this, label); \
   47             } else {                                                           \
   48                 gf_msg(this->name, GF_LOG_WARNING, op_errno, P_MSG_PGFID_OP,   \
   49                        "getting xattr "                                        \
   50                        "failed on %s: key = %s ",                              \
   51                        path, key);                                             \
   52             }                                                                  \
   53         }                                                                      \
   54     } while (0)
   55 
   56 #define REMOVE_PGFID_XATTR(path, key, op_ret, this, label)                     \
   57     do {                                                                       \
   58         op_ret = sys_lremovexattr(path, key);                                  \
   59         if (op_ret == -1) {                                                    \
   60             op_errno = errno;                                                  \
   61             gf_msg(this->name, GF_LOG_WARNING, op_errno, P_MSG_PGFID_OP,       \
   62                    "removing xattr failed"                                     \
   63                    "on %s: key = %s",                                          \
   64                    path, key);                                                 \
   65             goto label;                                                        \
   66         }                                                                      \
   67     } while (0)
   68 
   69 /* should be invoked holding a lock */
   70 #define LINK_MODIFY_PGFID_XATTR(path, key, value, flags, op_ret, this, label)  \
   71     do {                                                                       \
   72         op_ret = sys_lgetxattr(path, key, &value, sizeof(value));              \
   73         if (op_ret == -1) {                                                    \
   74             op_errno = errno;                                                  \
   75             if (op_errno == ENOATTR || op_errno == ENODATA) {                  \
   76                 value = 1;                                                     \
   77             } else {                                                           \
   78                 gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP,      \
   79                        "getting xattr "                                        \
   80                        "failed on %s: key = %s ",                              \
   81                        path, key);                                             \
   82                 goto label;                                                    \
   83             }                                                                  \
   84         } else {                                                               \
   85             value = ntoh32(value);                                             \
   86             value++;                                                           \
   87         }                                                                      \
   88         SET_PGFID_XATTR(path, key, value, flags, op_ret, this, label);         \
   89     } while (0)
   90 
   91 /* should be invoked holding a lock */
   92 #define UNLINK_MODIFY_PGFID_XATTR(path, key, value, flags, op_ret, this,       \
   93                                   label)                                       \
   94     do {                                                                       \
   95         op_ret = sys_lgetxattr(path, key, &value, sizeof(value));              \
   96         if (op_ret == -1) {                                                    \
   97             op_errno = errno;                                                  \
   98             gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP,          \
   99                    "getting xattr failed on "                                  \
  100                    "%s: key = %s ",                                            \
  101                    path, key);                                                 \
  102             goto label;                                                        \
  103         } else {                                                               \
  104             value = ntoh32(value);                                             \
  105             value--;                                                           \
  106             if (value > 0) {                                                   \
  107                 SET_PGFID_XATTR(path, key, value, flags, op_ret, this, label); \
  108             } else {                                                           \
  109                 REMOVE_PGFID_XATTR(path, key, op_ret, this, label);            \
  110             }                                                                  \
  111         }                                                                      \
  112     } while (0)
  113 
  114 #define MAKE_HANDLE_GFID_PATH(var, this, gfid)                                 \
  115     do {                                                                       \
  116         int __len = 0;                                                         \
  117         struct posix_private *__priv = this->private;                          \
  118         __len = POSIX_GFID_HANDLE_SIZE(__priv->base_path_length);              \
  119         __len += 256;                                                          \
  120         var = alloca(__len);                                                   \
  121         __len = posix_handle_gfid_path(this, gfid, var, __len);                \
  122     } while (0)
  123 
  124 #define MAKE_HANDLE_RELPATH(var, this, gfid, base)                             \
  125     do {                                                                       \
  126         int __len;                                                             \
  127         __len = POSIX_GFID_HANDLE_RELSIZE;                                     \
  128         if (base) {                                                            \
  129             __len += (strlen(base) + 1);                                       \
  130         }                                                                      \
  131         var = alloca(__len);                                                   \
  132         __len = posix_handle_relpath(this, gfid, base, var, __len);            \
  133     } while (0)
  134 
  135 #define MAKE_HANDLE_ABSPATH(var, this, gfid)                                   \
  136     do {                                                                       \
  137         struct posix_private *__priv = this->private;                          \
  138         int __len = HANDLE_ABSPATH_LEN(this);                                  \
  139         var = alloca(__len);                                                   \
  140         snprintf(var, __len, "%s/" GF_HIDDEN_PATH "/%02x/%02x/%s",             \
  141                  __priv->base_path, gfid[0], gfid[1], uuid_utoa(gfid));        \
  142     } while (0)
  143 
  144 #define MAKE_HANDLE_ABSPATH_FD(var, this, gfid, dfd)                           \
  145     do {                                                                       \
  146         struct posix_private *__priv = this->private;                          \
  147         int findex = gfid[0];                                                  \
  148         int __len = POSIX_GFID_HASH2_LEN;                                      \
  149         var = alloca(__len);                                                   \
  150         snprintf(var, __len, "%02x/%s", gfid[1], uuid_utoa(gfid));             \
  151         dfd = __priv->arrdfd[findex];                                          \
  152     } while (0)
  153 
  154 #define MAKE_ENTRY_HANDLE(entp, parp, this, loc, ent_p)                        \
  155     do {                                                                       \
  156         char *__parp;                                                          \
  157                                                                                \
  158         if (gf_uuid_is_null(loc->pargfid) || !loc->name) {                     \
  159             gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_ENTRY_HANDLE_CREATE,     \
  160                    "null pargfid/name for path %s", loc->path);                \
  161             break;                                                             \
  162         }                                                                      \
  163                                                                                \
  164         if (strchr(loc->name, '/')) {                                          \
  165             gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_ENTRY_HANDLE_CREATE,     \
  166                    "'/' in name not allowed: (%s)", loc->name);                \
  167             op_ret = -1;                                                       \
  168             break;                                                             \
  169         }                                                                      \
  170         if (LOC_HAS_ABSPATH(loc)) {                                            \
  171             MAKE_REAL_PATH(entp, this, loc->path);                             \
  172             __parp = strdupa(entp);                                            \
  173             parp = dirname(__parp);                                            \
  174             op_ret = posix_pstat(this, loc->inode, NULL, entp, ent_p,          \
  175                                  _gf_false);                                   \
  176             break;                                                             \
  177         }                                                                      \
  178         errno = 0;                                                             \
  179         op_ret = posix_istat(this, loc->inode, loc->pargfid, loc->name,        \
  180                              ent_p);                                           \
  181         if (errno != ELOOP) {                                                  \
  182             MAKE_HANDLE_PATH(parp, this, loc->pargfid, NULL);                  \
  183             MAKE_HANDLE_PATH(entp, this, loc->pargfid, loc->name);             \
  184             if (!parp || !entp) {                                              \
  185                 gf_msg(this->name, GF_LOG_ERROR, errno,                        \
  186                        P_MSG_ENTRY_HANDLE_CREATE,                              \
  187                        "Failed to create entry handle "                        \
  188                        "for path %s",                                          \
  189                        loc->path);                                             \
  190             }                                                                  \
  191             break;                                                             \
  192         }                                                                      \
  193         /* __ret == -1 && errno == ELOOP */                                    \
  194         /* expand ELOOP */                                                     \
  195     } while (0)
  196 
  197 #define POSIX_GFID_HASH2_LEN 45
  198 int
  199 posix_handle_gfid_path(xlator_t *this, uuid_t gfid, char *buf, size_t len);
  200 
  201 int
  202 posix_handle_hard(xlator_t *this, const char *path, uuid_t gfid,
  203                   struct stat *buf);
  204 
  205 int
  206 posix_handle_soft(xlator_t *this, const char *real_path, loc_t *loc,
  207                   uuid_t gfid, struct stat *buf);
  208 
  209 int
  210 posix_handle_unset(xlator_t *this, uuid_t gfid, const char *basename);
  211 
  212 int
  213 posix_create_link_if_gfid_exists(xlator_t *this, uuid_t gfid, char *real_path,
  214                                  inode_table_t *itable);
  215 
  216 int
  217 posix_check_internal_writes(xlator_t *this, fd_t *fd, int sysfd, dict_t *xdata);
  218 
  219 void
  220 posix_disk_space_check(xlator_t *this);
  221 #endif /* !_POSIX_HANDLE_H */