Debian Codegraph @

xlators/storage/posix/src/posix-handle.h

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