File: | xlators/mgmt/glusterd/src/glusterd-store.c |
Location: | line 2925, column 17 |
Description: | Value stored to 'ret' is never read |
1 | /* |
2 | Copyright (c) 2007-2012 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 _CONFIG_H |
12 | #define _CONFIG_H |
13 | #include "config.h" |
14 | #endif |
15 | |
16 | #include "glusterd-op-sm.h" |
17 | #include <inttypes.h> |
18 | |
19 | |
20 | #include "globals.h" |
21 | #include "glusterfs.h" |
22 | #include "compat.h" |
23 | #include "dict.h" |
24 | #include "protocol-common.h" |
25 | #include "xlator.h" |
26 | #include "logging.h" |
27 | #include "timer.h" |
28 | #include "defaults.h" |
29 | #include "compat.h" |
30 | #include "compat-errno.h" |
31 | #include "statedump.h" |
32 | #include "glusterd-mem-types.h" |
33 | #include "glusterd.h" |
34 | #include "glusterd-sm.h" |
35 | #include "glusterd-op-sm.h" |
36 | #include "glusterd-utils.h" |
37 | #include "glusterd-hooks.h" |
38 | #include "glusterd-store.h" |
39 | |
40 | #include "rpc-clnt.h" |
41 | #include "common-utils.h" |
42 | |
43 | #include <sys/resource.h> |
44 | #include <inttypes.h> |
45 | #include <dirent.h> |
46 | |
47 | static int32_t |
48 | glusterd_store_mkdir (char *path) |
49 | { |
50 | int32_t ret = -1; |
51 | |
52 | ret = mkdir (path, 0777); |
53 | |
54 | if ((-1 == ret) && (EEXIST17 != errno(*__errno_location ()))) { |
55 | gf_log (THIS->name, GF_LOG_ERROR, "mkdir() failed on path %s,"do { do { if (0) printf ("mkdir() failed on path %s," "errno: %s" , path, strerror ((*__errno_location ()))); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 56, GF_LOG_ERROR, "mkdir() failed on path %s," "errno: %s", path, strerror ((*__errno_location ()))); } while (0) |
56 | "errno: %s", path, strerror (errno))do { do { if (0) printf ("mkdir() failed on path %s," "errno: %s" , path, strerror ((*__errno_location ()))); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 56, GF_LOG_ERROR, "mkdir() failed on path %s," "errno: %s", path, strerror ((*__errno_location ()))); } while (0); |
57 | } else { |
58 | ret = 0; |
59 | } |
60 | |
61 | return ret; |
62 | } |
63 | |
64 | int32_t |
65 | glusterd_store_handle_create_on_absence (glusterd_store_handle_t **shandle, |
66 | char *path) |
67 | { |
68 | GF_ASSERT (shandle)do { if (!(shandle)) { do { do { if (0) printf ("Assertion failed: " "shandle"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 68, GF_LOG_ERROR, "Assertion failed: " "shandle" ); } while (0); } } while (0); |
69 | int32_t ret = 0; |
70 | |
71 | if (*shandle == NULL((void*)0)) { |
72 | ret = glusterd_store_handle_new (path, shandle); |
73 | |
74 | if (ret) { |
75 | gf_log (THIS->name, GF_LOG_ERROR, "Unable to create "do { do { if (0) printf ("Unable to create " "store handle for path: %s" , path); } while (0); _gf_log ((*__glusterfs_this_location()) ->name, "glusterd-store.c", __FUNCTION__, 76, GF_LOG_ERROR , "Unable to create " "store handle for path: %s", path); } while (0) |
76 | "store handle for path: %s", path)do { do { if (0) printf ("Unable to create " "store handle for path: %s" , path); } while (0); _gf_log ((*__glusterfs_this_location()) ->name, "glusterd-store.c", __FUNCTION__, 76, GF_LOG_ERROR , "Unable to create " "store handle for path: %s", path); } while (0); |
77 | } |
78 | } |
79 | return ret; |
80 | } |
81 | |
82 | int32_t |
83 | glusterd_store_mkstemp (glusterd_store_handle_t *shandle) |
84 | { |
85 | int fd = -1; |
86 | char tmppath[PATH_MAX4096] = {0,}; |
87 | |
88 | GF_ASSERT (shandle)do { if (!(shandle)) { do { do { if (0) printf ("Assertion failed: " "shandle"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 88, GF_LOG_ERROR, "Assertion failed: " "shandle" ); } while (0); } } while (0); |
89 | GF_ASSERT (shandle->path)do { if (!(shandle->path)) { do { do { if (0) printf ("Assertion failed: " "shandle->path"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 89, GF_LOG_ERROR, "Assertion failed: " "shandle->path" ); } while (0); } } while (0); |
90 | |
91 | snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path); |
92 | fd = open (tmppath, O_RDWR02 | O_CREAT0100 | O_TRUNC01000 | O_SYNC04010000, 0600); |
93 | if (fd <= 0) { |
94 | gf_log (THIS->name, GF_LOG_ERROR, "Failed to open %s, "do { do { if (0) printf ("Failed to open %s, " "error: %s", tmppath , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-store.c", __FUNCTION__ , 95, GF_LOG_ERROR, "Failed to open %s, " "error: %s", tmppath , strerror ((*__errno_location ()))); } while (0) |
95 | "error: %s", tmppath, strerror (errno))do { do { if (0) printf ("Failed to open %s, " "error: %s", tmppath , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-store.c", __FUNCTION__ , 95, GF_LOG_ERROR, "Failed to open %s, " "error: %s", tmppath , strerror ((*__errno_location ()))); } while (0); |
96 | } |
97 | |
98 | return fd; |
99 | } |
100 | |
101 | int |
102 | glusterd_store_sync_direntry (char *path) |
103 | { |
104 | int ret = -1; |
105 | int dirfd = -1; |
106 | char *dir = NULL((void*)0); |
107 | char *pdir = NULL((void*)0); |
108 | xlator_t *this = NULL((void*)0); |
109 | |
110 | this = THIS(*__glusterfs_this_location()); |
111 | |
112 | dir = gf_strdup (path); |
113 | if (!dir) |
114 | goto out; |
115 | |
116 | pdir = dirname (dir); |
117 | dirfd = open (pdir, O_RDONLY00); |
118 | if (dirfd == -1) { |
119 | gf_log (this->name, GF_LOG_ERROR, "Failed to open directory "do { do { if (0) printf ("Failed to open directory " "%s, due to %s" , pdir, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 120, GF_LOG_ERROR , "Failed to open directory " "%s, due to %s", pdir, strerror ((*__errno_location ()))); } while (0) |
120 | "%s, due to %s", pdir, strerror (errno))do { do { if (0) printf ("Failed to open directory " "%s, due to %s" , pdir, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 120, GF_LOG_ERROR , "Failed to open directory " "%s, due to %s", pdir, strerror ((*__errno_location ()))); } while (0); |
121 | goto out; |
122 | } |
123 | |
124 | ret = fsync (dirfd); |
125 | if (ret) { |
126 | gf_log (this->name, GF_LOG_ERROR, "Failed to fsync %s, due to "do { do { if (0) printf ("Failed to fsync %s, due to " "%s", pdir , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 127, GF_LOG_ERROR , "Failed to fsync %s, due to " "%s", pdir, strerror ((*__errno_location ()))); } while (0) |
127 | "%s", pdir, strerror (errno))do { do { if (0) printf ("Failed to fsync %s, due to " "%s", pdir , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 127, GF_LOG_ERROR , "Failed to fsync %s, due to " "%s", pdir, strerror ((*__errno_location ()))); } while (0); |
128 | goto out; |
129 | } |
130 | |
131 | ret = 0; |
132 | out: |
133 | if (dirfd >= 0) { |
134 | ret = close (dirfd); |
135 | if (ret) { |
136 | gf_log (this->name, GF_LOG_ERROR, "Failed to close "do { do { if (0) printf ("Failed to close " "%s, due to %s", pdir , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 137, GF_LOG_ERROR , "Failed to close " "%s, due to %s", pdir, strerror ((*__errno_location ()))); } while (0) |
137 | "%s, due to %s", pdir, strerror (errno))do { do { if (0) printf ("Failed to close " "%s, due to %s", pdir , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 137, GF_LOG_ERROR , "Failed to close " "%s, due to %s", pdir, strerror ((*__errno_location ()))); } while (0); |
138 | } |
139 | } |
140 | |
141 | if (dir) |
142 | GF_FREE (dir)__gf_free (dir); |
143 | |
144 | return ret; |
145 | } |
146 | |
147 | int32_t |
148 | glusterd_store_rename_tmppath (glusterd_store_handle_t *shandle) |
149 | { |
150 | int32_t ret = -1; |
151 | char tmppath[PATH_MAX4096] = {0,}; |
152 | |
153 | GF_ASSERT (shandle)do { if (!(shandle)) { do { do { if (0) printf ("Assertion failed: " "shandle"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 153, GF_LOG_ERROR, "Assertion failed: " "shandle" ); } while (0); } } while (0); |
154 | GF_ASSERT (shandle->path)do { if (!(shandle->path)) { do { do { if (0) printf ("Assertion failed: " "shandle->path"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 154, GF_LOG_ERROR, "Assertion failed: " "shandle->path" ); } while (0); } } while (0); |
155 | |
156 | snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path); |
157 | ret = rename (tmppath, shandle->path); |
158 | if (ret) { |
159 | gf_log (THIS->name, GF_LOG_ERROR, "Failed to rename %s to %s, "do { do { if (0) printf ("Failed to rename %s to %s, " "error: %s" , tmppath, shandle->path, strerror ((*__errno_location ()) )); } while (0); _gf_log ((*__glusterfs_this_location())-> name, "glusterd-store.c", __FUNCTION__, 160, GF_LOG_ERROR, "Failed to rename %s to %s, " "error: %s", tmppath, shandle->path, strerror ((*__errno_location ()))); } while (0) |
160 | "error: %s", tmppath, shandle->path, strerror (errno))do { do { if (0) printf ("Failed to rename %s to %s, " "error: %s" , tmppath, shandle->path, strerror ((*__errno_location ()) )); } while (0); _gf_log ((*__glusterfs_this_location())-> name, "glusterd-store.c", __FUNCTION__, 160, GF_LOG_ERROR, "Failed to rename %s to %s, " "error: %s", tmppath, shandle->path, strerror ((*__errno_location ()))); } while (0); |
161 | goto out; |
162 | } |
163 | |
164 | ret = glusterd_store_sync_direntry (tmppath); |
165 | out: |
166 | return ret; |
167 | } |
168 | |
169 | int32_t |
170 | glusterd_store_unlink_tmppath (glusterd_store_handle_t *shandle) |
171 | { |
172 | int32_t ret = -1; |
173 | char tmppath[PATH_MAX4096] = {0,}; |
174 | |
175 | GF_ASSERT (shandle)do { if (!(shandle)) { do { do { if (0) printf ("Assertion failed: " "shandle"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 175, GF_LOG_ERROR, "Assertion failed: " "shandle" ); } while (0); } } while (0); |
176 | GF_ASSERT (shandle->path)do { if (!(shandle->path)) { do { do { if (0) printf ("Assertion failed: " "shandle->path"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 176, GF_LOG_ERROR, "Assertion failed: " "shandle->path" ); } while (0); } } while (0); |
177 | |
178 | snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path); |
179 | ret = unlink (tmppath); |
180 | if (ret && (errno(*__errno_location ()) != ENOENT2)) { |
181 | gf_log (THIS->name, GF_LOG_ERROR, "Failed to mv %s to %s, "do { do { if (0) printf ("Failed to mv %s to %s, " "error: %s" , tmppath, shandle->path, strerror ((*__errno_location ()) )); } while (0); _gf_log ((*__glusterfs_this_location())-> name, "glusterd-store.c", __FUNCTION__, 182, GF_LOG_ERROR, "Failed to mv %s to %s, " "error: %s", tmppath, shandle->path, strerror ((*__errno_location ()))); } while (0) |
182 | "error: %s", tmppath, shandle->path, strerror (errno))do { do { if (0) printf ("Failed to mv %s to %s, " "error: %s" , tmppath, shandle->path, strerror ((*__errno_location ()) )); } while (0); _gf_log ((*__glusterfs_this_location())-> name, "glusterd-store.c", __FUNCTION__, 182, GF_LOG_ERROR, "Failed to mv %s to %s, " "error: %s", tmppath, shandle->path, strerror ((*__errno_location ()))); } while (0); |
183 | } else { |
184 | ret = 0; |
185 | } |
186 | |
187 | return ret; |
188 | } |
189 | |
190 | static void |
191 | glusterd_replace_slash_with_hipen (char *str) |
192 | { |
193 | char *ptr = NULL((void*)0); |
194 | |
195 | ptr = strchr (str, '/'); |
196 | |
197 | while (ptr) { |
198 | *ptr = '-'; |
199 | ptr = strchr (str, '/'); |
200 | } |
201 | } |
202 | |
203 | int32_t |
204 | glusterd_store_create_brick_dir (glusterd_volinfo_t *volinfo) |
205 | { |
206 | int32_t ret = -1; |
207 | char brickdirpath[PATH_MAX4096] = {0,}; |
208 | glusterd_conf_t *priv = NULL((void*)0); |
209 | |
210 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 210, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
211 | |
212 | priv = THIS(*__glusterfs_this_location())->private; |
213 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 213, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); |
214 | |
215 | GLUSTERD_GET_BRICK_DIR (brickdirpath, volinfo, priv)snprintf (brickdirpath, 4096, "%s/%s/%s/%s", priv->workdir , "vols", volinfo->volname, "bricks");; |
216 | ret = glusterd_store_mkdir (brickdirpath); |
217 | |
218 | return ret; |
219 | } |
220 | |
221 | static void |
222 | glusterd_store_key_vol_brick_set (glusterd_brickinfo_t *brickinfo, |
223 | char *key_vol_brick, size_t len) |
224 | { |
225 | GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: " "brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 225, GF_LOG_ERROR, "Assertion failed: " "brickinfo" ); } while (0); } } while (0); |
226 | GF_ASSERT (key_vol_brick)do { if (!(key_vol_brick)) { do { do { if (0) printf ("Assertion failed: " "key_vol_brick"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 226, GF_LOG_ERROR, "Assertion failed: " "key_vol_brick" ); } while (0); } } while (0); |
227 | GF_ASSERT (len >= PATH_MAX)do { if (!(len >= 4096)) { do { do { if (0) printf ("Assertion failed: " "len >= PATH_MAX"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 227, GF_LOG_ERROR, "Assertion failed: " "len >= PATH_MAX" ); } while (0); } } while (0); |
228 | |
229 | snprintf (key_vol_brick, len, "%s", brickinfo->path); |
230 | glusterd_replace_slash_with_hipen (key_vol_brick); |
231 | } |
232 | |
233 | static void |
234 | glusterd_store_brickinfofname_set (glusterd_brickinfo_t *brickinfo, |
235 | char *brickfname, size_t len) |
236 | { |
237 | char key_vol_brick[PATH_MAX4096] = {0}; |
238 | |
239 | GF_ASSERT (brickfname)do { if (!(brickfname)) { do { do { if (0) printf ("Assertion failed: " "brickfname"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 239, GF_LOG_ERROR, "Assertion failed: " "brickfname" ); } while (0); } } while (0); |
240 | GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: " "brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 240, GF_LOG_ERROR, "Assertion failed: " "brickinfo" ); } while (0); } } while (0); |
241 | GF_ASSERT (len >= PATH_MAX)do { if (!(len >= 4096)) { do { do { if (0) printf ("Assertion failed: " "len >= PATH_MAX"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 241, GF_LOG_ERROR, "Assertion failed: " "len >= PATH_MAX" ); } while (0); } } while (0); |
242 | |
243 | glusterd_store_key_vol_brick_set (brickinfo, key_vol_brick, |
244 | sizeof (key_vol_brick)); |
245 | snprintf (brickfname, len, "%s:%s", brickinfo->hostname, key_vol_brick); |
246 | } |
247 | |
248 | static void |
249 | glusterd_store_brickinfopath_set (glusterd_volinfo_t *volinfo, |
250 | glusterd_brickinfo_t *brickinfo, |
251 | char *brickpath, size_t len) |
252 | { |
253 | char brickfname[PATH_MAX4096] = {0}; |
254 | char brickdirpath[PATH_MAX4096] = {0,}; |
255 | glusterd_conf_t *priv = NULL((void*)0); |
256 | |
257 | GF_ASSERT (brickpath)do { if (!(brickpath)) { do { do { if (0) printf ("Assertion failed: " "brickpath"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 257, GF_LOG_ERROR, "Assertion failed: " "brickpath" ); } while (0); } } while (0); |
258 | GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: " "brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 258, GF_LOG_ERROR, "Assertion failed: " "brickinfo" ); } while (0); } } while (0); |
259 | GF_ASSERT (len >= PATH_MAX)do { if (!(len >= 4096)) { do { do { if (0) printf ("Assertion failed: " "len >= PATH_MAX"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 259, GF_LOG_ERROR, "Assertion failed: " "len >= PATH_MAX" ); } while (0); } } while (0); |
260 | |
261 | priv = THIS(*__glusterfs_this_location())->private; |
262 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 262, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); |
263 | |
264 | GLUSTERD_GET_BRICK_DIR (brickdirpath, volinfo, priv)snprintf (brickdirpath, 4096, "%s/%s/%s/%s", priv->workdir , "vols", volinfo->volname, "bricks");; |
265 | glusterd_store_brickinfofname_set (brickinfo, brickfname, |
266 | sizeof (brickfname)); |
267 | snprintf (brickpath, len, "%s/%s", brickdirpath, brickfname); |
268 | } |
269 | |
270 | gf_boolean_t |
271 | glusterd_store_is_valid_brickpath (char *volname, char *brick) |
272 | { |
273 | char brickpath[PATH_MAX4096] = {0}; |
274 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); |
275 | glusterd_volinfo_t *volinfo = NULL((void*)0); |
276 | int32_t ret = 0; |
277 | size_t volname_len = strlen (volname); |
278 | xlator_t *this = NULL((void*)0); |
279 | |
280 | this = THIS(*__glusterfs_this_location()); |
281 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 281, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); |
282 | |
283 | ret = glusterd_brickinfo_new_from_brick (brick, &brickinfo); |
284 | if (ret) { |
285 | gf_log (this->name, GF_LOG_WARNING, "Failed to create brick "do { do { if (0) printf ("Failed to create brick " "info for brick %s" , brick); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 286, GF_LOG_WARNING, "Failed to create brick " "info for brick %s", brick); } while (0) |
286 | "info for brick %s", brick)do { do { if (0) printf ("Failed to create brick " "info for brick %s" , brick); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 286, GF_LOG_WARNING, "Failed to create brick " "info for brick %s", brick); } while (0); |
287 | ret = 0; |
288 | goto out; |
289 | } |
290 | ret = glusterd_volinfo_new (&volinfo); |
291 | if (ret) { |
292 | gf_log (this->name, GF_LOG_WARNING, "Failed to create volinfo")do { do { if (0) printf ("Failed to create volinfo"); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 292, GF_LOG_WARNING, "Failed to create volinfo"); } while ( 0); |
293 | ret = 0; |
294 | goto out; |
295 | } |
296 | if (volname_len >= sizeof (volinfo->volname)) { |
297 | gf_log (this->name, GF_LOG_WARNING, "volume name too long")do { do { if (0) printf ("volume name too long"); } while (0) ; _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 297 , GF_LOG_WARNING, "volume name too long"); } while (0); |
298 | ret = 0; |
299 | goto out; |
300 | } |
301 | memcpy (volinfo->volname, volname, volname_len+1); |
302 | glusterd_store_brickinfopath_set (volinfo, brickinfo, brickpath, |
303 | sizeof (brickpath)); |
304 | |
305 | ret = (strlen (brickpath) < _POSIX_PATH_MAX256); |
306 | |
307 | out: |
308 | if (brickinfo) |
309 | glusterd_brickinfo_delete (brickinfo); |
310 | if (volinfo) |
311 | glusterd_volinfo_delete (volinfo); |
312 | |
313 | return ret; |
314 | } |
315 | |
316 | int32_t |
317 | glusterd_store_volinfo_brick_fname_write (int vol_fd, |
318 | glusterd_brickinfo_t *brickinfo, |
319 | int32_t brick_count) |
320 | { |
321 | char key[PATH_MAX4096] = {0,}; |
322 | char brickfname[PATH_MAX4096] = {0,}; |
323 | int32_t ret = -1; |
324 | |
325 | snprintf (key, sizeof (key), "%s-%d", GLUSTERD_STORE_KEY_VOL_BRICK"brick", |
326 | brick_count); |
327 | glusterd_store_brickinfofname_set (brickinfo, brickfname, |
328 | sizeof (brickfname)); |
329 | ret = glusterd_store_save_value (vol_fd, key, brickfname); |
330 | if (ret) |
331 | goto out; |
332 | |
333 | out: |
334 | return ret; |
335 | } |
336 | |
337 | int32_t |
338 | glusterd_store_create_brick_shandle_on_absence (glusterd_volinfo_t *volinfo, |
339 | glusterd_brickinfo_t *brickinfo) |
340 | { |
341 | char brickpath[PATH_MAX4096] = {0,}; |
342 | int32_t ret = 0; |
343 | |
344 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 344, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
345 | GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: " "brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 345, GF_LOG_ERROR, "Assertion failed: " "brickinfo" ); } while (0); } } while (0); |
346 | |
347 | glusterd_store_brickinfopath_set (volinfo, brickinfo, brickpath, |
348 | sizeof (brickpath)); |
349 | ret = glusterd_store_handle_create_on_absence (&brickinfo->shandle, |
350 | brickpath); |
351 | return ret; |
352 | } |
353 | |
354 | int32_t |
355 | glusterd_store_brickinfo_write (int fd, glusterd_brickinfo_t *brickinfo) |
356 | { |
357 | char value[256] = {0,}; |
358 | int32_t ret = 0; |
359 | |
360 | GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: " "brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 360, GF_LOG_ERROR, "Assertion failed: " "brickinfo" ); } while (0); } } while (0); |
361 | GF_ASSERT (fd > 0)do { if (!(fd > 0)) { do { do { if (0) printf ("Assertion failed: " "fd > 0"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 361, GF_LOG_ERROR, "Assertion failed: " "fd > 0" ); } while (0); } } while (0); |
362 | |
363 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_BRICK_HOSTNAME"hostname", |
364 | brickinfo->hostname); |
365 | if (ret) |
366 | goto out; |
367 | |
368 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_BRICK_PATH"path", |
369 | brickinfo->path); |
370 | if (ret) |
371 | goto out; |
372 | |
373 | snprintf (value, sizeof(value), "%d", brickinfo->port); |
374 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_BRICK_PORT"listen-port", |
375 | value); |
376 | |
377 | snprintf (value, sizeof(value), "%d", brickinfo->rdma_port); |
378 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_BRICK_RDMA_PORT"rdma.listen-port", |
379 | value); |
380 | |
381 | snprintf (value, sizeof(value), "%d", brickinfo->decommissioned); |
382 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED"decommissioned", |
383 | value); |
384 | if (ret) |
385 | goto out; |
386 | |
387 | out: |
388 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 388, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
389 | return ret; |
390 | } |
391 | |
392 | int32_t |
393 | glusterd_store_perform_brick_store (glusterd_brickinfo_t *brickinfo) |
394 | { |
395 | int fd = -1; |
396 | int32_t ret = -1; |
397 | GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: " "brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 397, GF_LOG_ERROR, "Assertion failed: " "brickinfo" ); } while (0); } } while (0); |
398 | |
399 | fd = glusterd_store_mkstemp (brickinfo->shandle); |
400 | if (fd <= 0) { |
401 | ret = -1; |
402 | goto out; |
403 | } |
404 | |
405 | ret = glusterd_store_brickinfo_write (fd, brickinfo); |
406 | if (ret) |
407 | goto out; |
408 | |
409 | out: |
410 | if (ret && (fd > 0)) |
411 | glusterd_store_unlink_tmppath (brickinfo->shandle); |
412 | if (fd > 0) |
413 | close (fd); |
414 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 414, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
415 | return ret; |
416 | } |
417 | |
418 | int32_t |
419 | glusterd_store_brickinfo (glusterd_volinfo_t *volinfo, |
420 | glusterd_brickinfo_t *brickinfo, int32_t brick_count, |
421 | int vol_fd) |
422 | { |
423 | int32_t ret = -1; |
424 | |
425 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 425, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
426 | GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: " "brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 426, GF_LOG_ERROR, "Assertion failed: " "brickinfo" ); } while (0); } } while (0); |
427 | |
428 | ret = glusterd_store_volinfo_brick_fname_write (vol_fd, brickinfo, |
429 | brick_count); |
430 | if (ret) |
431 | goto out; |
432 | |
433 | ret = glusterd_store_create_brick_dir (volinfo); |
434 | if (ret) |
435 | goto out; |
436 | |
437 | ret = glusterd_store_create_brick_shandle_on_absence (volinfo, |
438 | brickinfo); |
439 | if (ret) |
440 | goto out; |
441 | |
442 | ret = glusterd_store_perform_brick_store (brickinfo); |
443 | out: |
444 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 444, GF_LOG_DEBUG, "Returning with %d", ret); } while (0); |
445 | return ret; |
446 | } |
447 | |
448 | int32_t |
449 | glusterd_store_delete_brick (glusterd_brickinfo_t *brickinfo, char *delete_path) |
450 | { |
451 | int32_t ret = -1; |
452 | glusterd_conf_t *priv = NULL((void*)0); |
453 | char brickpath[PATH_MAX4096] = {0,}; |
454 | char *ptr = NULL((void*)0); |
455 | char *tmppath = NULL((void*)0); |
456 | xlator_t *this = NULL((void*)0); |
457 | |
458 | this = THIS(*__glusterfs_this_location()); |
459 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 459, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); |
460 | GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: " "brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 460, GF_LOG_ERROR, "Assertion failed: " "brickinfo" ); } while (0); } } while (0); |
461 | |
462 | priv = this->private; |
463 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 463, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); |
464 | |
465 | tmppath = gf_strdup (brickinfo->path); |
466 | |
467 | ptr = strchr (tmppath, '/'); |
468 | |
469 | while (ptr) { |
470 | *ptr = '-'; |
471 | ptr = strchr (tmppath, '/'); |
472 | } |
473 | |
474 | snprintf (brickpath, sizeof (brickpath), |
475 | "%s/"GLUSTERD_BRICK_INFO_DIR"bricks""/%s:%s", delete_path, |
476 | brickinfo->hostname, tmppath); |
477 | |
478 | GF_FREE (tmppath)__gf_free (tmppath); |
479 | |
480 | ret = unlink (brickpath); |
481 | |
482 | if ((ret < 0) && (errno(*__errno_location ()) != ENOENT2)) { |
483 | gf_log (this->name, GF_LOG_DEBUG, "Unlink failed on %s, "do { do { if (0) printf ("Unlink failed on %s, " "reason: %s" , brickpath, strerror((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 484, GF_LOG_DEBUG , "Unlink failed on %s, " "reason: %s", brickpath, strerror(( *__errno_location ()))); } while (0) |
484 | "reason: %s", brickpath, strerror(errno))do { do { if (0) printf ("Unlink failed on %s, " "reason: %s" , brickpath, strerror((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 484, GF_LOG_DEBUG , "Unlink failed on %s, " "reason: %s", brickpath, strerror(( *__errno_location ()))); } while (0); |
485 | ret = -1; |
486 | goto out; |
487 | } else { |
488 | ret = 0; |
489 | } |
490 | |
491 | out: |
492 | if (brickinfo->shandle) { |
493 | glusterd_store_handle_destroy (brickinfo->shandle); |
494 | brickinfo->shandle = NULL((void*)0); |
495 | } |
496 | gf_log (this->name, GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 496, GF_LOG_DEBUG, "Returning with %d", ret); } while (0); |
497 | return ret; |
498 | } |
499 | |
500 | int32_t |
501 | glusterd_store_remove_bricks (glusterd_volinfo_t *volinfo, char *delete_path) |
502 | { |
503 | int32_t ret = 0; |
504 | glusterd_brickinfo_t *tmp = NULL((void*)0); |
505 | glusterd_conf_t *priv = NULL((void*)0); |
506 | char brickdir [PATH_MAX4096] = {0,}; |
507 | DIR *dir = NULL((void*)0); |
508 | struct dirent *entry = NULL((void*)0); |
509 | char path[PATH_MAX4096] = {0,}; |
510 | xlator_t *this = NULL((void*)0); |
511 | |
512 | this = THIS(*__glusterfs_this_location()); |
513 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 513, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); |
514 | |
515 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 515, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
516 | |
517 | list_for_each_entry (tmp, &volinfo->bricks, brick_list)for (tmp = ((typeof(*tmp) *)((char *)((&volinfo->bricks )->next)-(unsigned long)(&((typeof(*tmp) *)0)->brick_list ))); &tmp->brick_list != (&volinfo->bricks); tmp = ((typeof(*tmp) *)((char *)(tmp->brick_list.next)-(unsigned long)(&((typeof(*tmp) *)0)->brick_list)))) { |
518 | ret = glusterd_store_delete_brick (tmp, delete_path); |
519 | if (ret) |
520 | goto out; |
521 | } |
522 | |
523 | priv = this->private; |
524 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 524, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); |
525 | |
526 | snprintf (brickdir, sizeof (brickdir), "%s/%s", delete_path, |
527 | GLUSTERD_BRICK_INFO_DIR"bricks"); |
528 | |
529 | dir = opendir (brickdir); |
530 | |
531 | glusterd_for_each_entry (entry, dir)do { entry = ((void*)0); if (dir) { entry = readdir (dir); while (entry && (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, ".."))) { entry = readdir (dir); } } } while (0);; |
532 | |
533 | while (entry) { |
534 | snprintf (path, sizeof (path), "%s/%s", |
535 | brickdir, entry->d_name); |
536 | ret = unlink (path); |
537 | if (ret && errno(*__errno_location ()) != ENOENT2) { |
538 | gf_log (this->name, GF_LOG_DEBUG, "Unable to unlink %s, "do { do { if (0) printf ("Unable to unlink %s, " "reason: %s" , path, strerror((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 539, GF_LOG_DEBUG , "Unable to unlink %s, " "reason: %s", path, strerror((*__errno_location ()))); } while (0) |
539 | "reason: %s", path, strerror(errno))do { do { if (0) printf ("Unable to unlink %s, " "reason: %s" , path, strerror((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 539, GF_LOG_DEBUG , "Unable to unlink %s, " "reason: %s", path, strerror((*__errno_location ()))); } while (0); |
540 | } |
541 | glusterd_for_each_entry (entry, dir)do { entry = ((void*)0); if (dir) { entry = readdir (dir); while (entry && (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, ".."))) { entry = readdir (dir); } } } while (0);; |
542 | } |
543 | |
544 | closedir (dir); |
545 | |
546 | ret = rmdir (brickdir); |
547 | |
548 | out: |
549 | gf_log (this->name, GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 549, GF_LOG_DEBUG, "Returning with %d", ret); } while (0); |
550 | return ret; |
551 | } |
552 | |
553 | static int |
554 | _storeslaves (dict_t *this, char *key, data_t *value, void *data) |
555 | { |
556 | int32_t ret = 0; |
557 | glusterd_store_handle_t *shandle = NULL((void*)0); |
558 | xlator_t *xl = NULL((void*)0); |
559 | |
560 | xl = THIS(*__glusterfs_this_location()); |
561 | GF_ASSERT (xl)do { if (!(xl)) { do { do { if (0) printf ("Assertion failed: " "xl"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 561, GF_LOG_ERROR, "Assertion failed: " "xl") ; } while (0); } } while (0); |
562 | |
563 | shandle = (glusterd_store_handle_t*)data; |
564 | |
565 | GF_ASSERT (shandle)do { if (!(shandle)) { do { do { if (0) printf ("Assertion failed: " "shandle"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 565, GF_LOG_ERROR, "Assertion failed: " "shandle" ); } while (0); } } while (0); |
566 | GF_ASSERT (shandle->fd > 0)do { if (!(shandle->fd > 0)) { do { do { if (0) printf ( "Assertion failed: " "shandle->fd > 0"); } while (0); _gf_log_callingfn ("", "glusterd-store.c", __FUNCTION__, 566, GF_LOG_ERROR, "Assertion failed: " "shandle->fd > 0"); } while (0); } } while (0); |
567 | GF_ASSERT (shandle->path)do { if (!(shandle->path)) { do { do { if (0) printf ("Assertion failed: " "shandle->path"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 567, GF_LOG_ERROR, "Assertion failed: " "shandle->path" ); } while (0); } } while (0); |
568 | GF_ASSERT (key)do { if (!(key)) { do { do { if (0) printf ("Assertion failed: " "key"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 568, GF_LOG_ERROR, "Assertion failed: " "key" ); } while (0); } } while (0); |
569 | GF_ASSERT (value && value->data)do { if (!(value && value->data)) { do { do { if ( 0) printf ("Assertion failed: " "value && value->data" ); } while (0); _gf_log_callingfn ("", "glusterd-store.c", __FUNCTION__ , 569, GF_LOG_ERROR, "Assertion failed: " "value && value->data" ); } while (0); } } while (0); |
570 | |
571 | if ((!shandle) || (shandle->fd <= 0) || (!shandle->path)) |
572 | return -1; |
573 | |
574 | if (!key) |
575 | return -1; |
576 | if (!value || !value->data) |
577 | return -1; |
578 | |
579 | gf_log (xl->name, GF_LOG_DEBUG, "Storing in volinfo:key= %s, val=%s",do { do { if (0) printf ("Storing in volinfo:key= %s, val=%s" , key, value->data); } while (0); _gf_log (xl->name, "glusterd-store.c" , __FUNCTION__, 580, GF_LOG_DEBUG, "Storing in volinfo:key= %s, val=%s" , key, value->data); } while (0) |
580 | key, value->data)do { do { if (0) printf ("Storing in volinfo:key= %s, val=%s" , key, value->data); } while (0); _gf_log (xl->name, "glusterd-store.c" , __FUNCTION__, 580, GF_LOG_DEBUG, "Storing in volinfo:key= %s, val=%s" , key, value->data); } while (0); |
581 | |
582 | ret = glusterd_store_save_value (shandle->fd, key, (char*)value->data); |
583 | if (ret) { |
584 | gf_log (xl->name, GF_LOG_ERROR, "Unable to write into store"do { do { if (0) printf ("Unable to write into store" " handle for path: %s" , shandle->path); } while (0); _gf_log (xl->name, "glusterd-store.c" , __FUNCTION__, 585, GF_LOG_ERROR, "Unable to write into store" " handle for path: %s", shandle->path); } while (0) |
585 | " handle for path: %s", shandle->path)do { do { if (0) printf ("Unable to write into store" " handle for path: %s" , shandle->path); } while (0); _gf_log (xl->name, "glusterd-store.c" , __FUNCTION__, 585, GF_LOG_ERROR, "Unable to write into store" " handle for path: %s", shandle->path); } while (0); |
586 | return -1; |
587 | } |
588 | return 0; |
589 | } |
590 | |
591 | |
592 | int _storeopts (dict_t *this, char *key, data_t *value, void *data) |
593 | { |
594 | int32_t ret = 0; |
595 | int32_t exists = 0; |
596 | glusterd_store_handle_t *shandle = NULL((void*)0); |
597 | xlator_t *xl = NULL((void*)0); |
598 | |
599 | xl = THIS(*__glusterfs_this_location()); |
600 | GF_ASSERT (xl)do { if (!(xl)) { do { do { if (0) printf ("Assertion failed: " "xl"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 600, GF_LOG_ERROR, "Assertion failed: " "xl") ; } while (0); } } while (0); |
601 | |
602 | shandle = (glusterd_store_handle_t*)data; |
603 | |
604 | GF_ASSERT (shandle)do { if (!(shandle)) { do { do { if (0) printf ("Assertion failed: " "shandle"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 604, GF_LOG_ERROR, "Assertion failed: " "shandle" ); } while (0); } } while (0); |
605 | GF_ASSERT (shandle->fd > 0)do { if (!(shandle->fd > 0)) { do { do { if (0) printf ( "Assertion failed: " "shandle->fd > 0"); } while (0); _gf_log_callingfn ("", "glusterd-store.c", __FUNCTION__, 605, GF_LOG_ERROR, "Assertion failed: " "shandle->fd > 0"); } while (0); } } while (0); |
606 | GF_ASSERT (shandle->path)do { if (!(shandle->path)) { do { do { if (0) printf ("Assertion failed: " "shandle->path"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 606, GF_LOG_ERROR, "Assertion failed: " "shandle->path" ); } while (0); } } while (0); |
607 | GF_ASSERT (key)do { if (!(key)) { do { do { if (0) printf ("Assertion failed: " "key"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 607, GF_LOG_ERROR, "Assertion failed: " "key" ); } while (0); } } while (0); |
608 | GF_ASSERT (value && value->data)do { if (!(value && value->data)) { do { do { if ( 0) printf ("Assertion failed: " "value && value->data" ); } while (0); _gf_log_callingfn ("", "glusterd-store.c", __FUNCTION__ , 608, GF_LOG_ERROR, "Assertion failed: " "value && value->data" ); } while (0); } } while (0); |
609 | |
610 | if ((!shandle) || (shandle->fd <= 0) || (!shandle->path)) |
611 | return -1; |
612 | |
613 | if (!key) |
614 | return -1; |
615 | if (!value || !value->data) |
616 | return -1; |
617 | |
618 | if (is_key_glusterd_hooks_friendly (key)) { |
619 | exists = 1; |
620 | |
621 | } else { |
622 | exists = glusterd_check_option_exists (key, NULL((void*)0)); |
623 | } |
624 | |
625 | if (1 == exists) { |
626 | gf_log (xl->name, GF_LOG_DEBUG, "Storing in volinfo:key= %s, "do { do { if (0) printf ("Storing in volinfo:key= %s, " "val=%s" , key, value->data); } while (0); _gf_log (xl->name, "glusterd-store.c" , __FUNCTION__, 627, GF_LOG_DEBUG, "Storing in volinfo:key= %s, " "val=%s", key, value->data); } while (0) |
627 | "val=%s", key, value->data)do { do { if (0) printf ("Storing in volinfo:key= %s, " "val=%s" , key, value->data); } while (0); _gf_log (xl->name, "glusterd-store.c" , __FUNCTION__, 627, GF_LOG_DEBUG, "Storing in volinfo:key= %s, " "val=%s", key, value->data); } while (0); |
628 | |
629 | } else { |
630 | gf_log (xl->name, GF_LOG_DEBUG, "Discarding:key= %s, val=%s",do { do { if (0) printf ("Discarding:key= %s, val=%s", key, value ->data); } while (0); _gf_log (xl->name, "glusterd-store.c" , __FUNCTION__, 631, GF_LOG_DEBUG, "Discarding:key= %s, val=%s" , key, value->data); } while (0) |
631 | key, value->data)do { do { if (0) printf ("Discarding:key= %s, val=%s", key, value ->data); } while (0); _gf_log (xl->name, "glusterd-store.c" , __FUNCTION__, 631, GF_LOG_DEBUG, "Discarding:key= %s, val=%s" , key, value->data); } while (0); |
632 | return 0; |
633 | } |
634 | |
635 | ret = glusterd_store_save_value (shandle->fd, key, (char*)value->data); |
636 | if (ret) { |
637 | gf_log (xl->name, GF_LOG_ERROR, "Unable to write into store"do { do { if (0) printf ("Unable to write into store" " handle for path: %s" , shandle->path); } while (0); _gf_log (xl->name, "glusterd-store.c" , __FUNCTION__, 638, GF_LOG_ERROR, "Unable to write into store" " handle for path: %s", shandle->path); } while (0) |
638 | " handle for path: %s", shandle->path)do { do { if (0) printf ("Unable to write into store" " handle for path: %s" , shandle->path); } while (0); _gf_log (xl->name, "glusterd-store.c" , __FUNCTION__, 638, GF_LOG_ERROR, "Unable to write into store" " handle for path: %s", shandle->path); } while (0); |
639 | return -1; |
640 | } |
641 | return 0; |
642 | } |
643 | |
644 | int32_t |
645 | glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo) |
646 | { |
647 | char *str = NULL((void*)0); |
648 | |
649 | GF_ASSERT (fd > 0)do { if (!(fd > 0)) { do { do { if (0) printf ("Assertion failed: " "fd > 0"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 649, GF_LOG_ERROR, "Assertion failed: " "fd > 0" ); } while (0); } } while (0); |
650 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 650, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
651 | |
652 | char buf[PATH_MAX4096] = {0,}; |
653 | int32_t ret = -1; |
654 | |
655 | snprintf (buf, sizeof (buf), "%d", volinfo->type); |
656 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_TYPE"type", buf); |
657 | if (ret) |
658 | goto out; |
659 | |
660 | snprintf (buf, sizeof (buf), "%d", volinfo->brick_count); |
661 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_COUNT"count", buf); |
662 | if (ret) |
663 | goto out; |
664 | |
665 | snprintf (buf, sizeof (buf), "%d", volinfo->status); |
666 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_STATUS"status", buf); |
667 | if (ret) |
668 | goto out; |
669 | |
670 | snprintf (buf, sizeof (buf), "%d", volinfo->sub_count); |
671 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_SUB_COUNT"sub_count", |
672 | buf); |
673 | if (ret) |
674 | goto out; |
675 | |
676 | snprintf (buf, sizeof (buf), "%d", volinfo->stripe_count); |
677 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_STRIPE_CNT"stripe_count", |
678 | buf); |
679 | if (ret) |
680 | goto out; |
681 | |
682 | snprintf (buf, sizeof (buf), "%d", volinfo->replica_count); |
683 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_REPLICA_CNT"replica_count", |
684 | buf); |
685 | if (ret) |
686 | goto out; |
687 | |
688 | snprintf (buf, sizeof (buf), "%d", volinfo->version); |
689 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_VERSION"version", |
690 | buf); |
691 | if (ret) |
692 | goto out; |
693 | |
694 | snprintf (buf, sizeof (buf), "%d", volinfo->transport_type); |
695 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_TRANSPORT"transport-type", |
696 | buf); |
697 | if (ret) |
698 | goto out; |
699 | |
700 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_ID"volume-id", |
701 | uuid_utoa (volinfo->volume_id)); |
702 | if (ret) |
703 | goto out; |
704 | |
705 | str = glusterd_auth_get_username (volinfo); |
706 | if (str) { |
707 | ret = glusterd_store_save_value (fd, |
708 | GLUSTERD_STORE_KEY_USERNAME"username", |
709 | str); |
710 | if (ret) |
711 | goto out; |
712 | } |
713 | |
714 | str = glusterd_auth_get_password (volinfo); |
715 | if (str) { |
716 | ret = glusterd_store_save_value (fd, |
717 | GLUSTERD_STORE_KEY_PASSWORD"password", |
718 | str); |
719 | if (ret) |
720 | goto out; |
721 | } |
722 | |
723 | if (volinfo->backend == GD_VOL_BK_BD) { |
724 | snprintf (buf, sizeof (buf), "%d", volinfo->backend); |
725 | ret = glusterd_store_save_value (fd, |
726 | GLUSTERD_STORE_KEY_VOL_BACKEND"backend", buf); |
727 | if (ret) |
728 | goto out; |
729 | } |
730 | |
731 | out: |
732 | if (ret) |
733 | gf_log (THIS->name, GF_LOG_ERROR, "Unable to write volume "do { do { if (0) printf ("Unable to write volume " "values for %s" , volinfo->volname); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-store.c", __FUNCTION__, 734, GF_LOG_ERROR , "Unable to write volume " "values for %s", volinfo->volname ); } while (0) |
734 | "values for %s", volinfo->volname)do { do { if (0) printf ("Unable to write volume " "values for %s" , volinfo->volname); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-store.c", __FUNCTION__, 734, GF_LOG_ERROR , "Unable to write volume " "values for %s", volinfo->volname ); } while (0); |
735 | return ret; |
736 | } |
737 | |
738 | static void |
739 | glusterd_store_voldirpath_set (glusterd_volinfo_t *volinfo, char *voldirpath, |
740 | size_t len) |
741 | { |
742 | glusterd_conf_t *priv = NULL((void*)0); |
743 | |
744 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 744, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
745 | priv = THIS(*__glusterfs_this_location())->private; |
746 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 746, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); |
747 | |
748 | snprintf (voldirpath, len, "%s/%s/%s", priv->workdir, |
749 | GLUSTERD_VOLUME_DIR_PREFIX"vols", volinfo->volname); |
750 | } |
751 | |
752 | static int32_t |
753 | glusterd_store_create_volume_dir (glusterd_volinfo_t *volinfo) |
754 | { |
755 | int32_t ret = -1; |
756 | char voldirpath[PATH_MAX4096] = {0,}; |
757 | |
758 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 758, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
759 | |
760 | glusterd_store_voldirpath_set (volinfo, voldirpath, |
761 | sizeof (voldirpath)); |
762 | ret = glusterd_store_mkdir (voldirpath); |
763 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 763, GF_LOG_DEBUG, "Returning with %d", ret); } while (0); |
764 | return ret; |
765 | } |
766 | |
767 | int32_t |
768 | glusterd_store_volinfo_write (int fd, glusterd_volinfo_t *volinfo) |
769 | { |
770 | int32_t ret = -1; |
771 | glusterd_store_handle_t *shandle = NULL((void*)0); |
772 | GF_ASSERT (fd > 0)do { if (!(fd > 0)) { do { do { if (0) printf ("Assertion failed: " "fd > 0"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 772, GF_LOG_ERROR, "Assertion failed: " "fd > 0" ); } while (0); } } while (0); |
773 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 773, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
774 | GF_ASSERT (volinfo->shandle)do { if (!(volinfo->shandle)) { do { do { if (0) printf ("Assertion failed: " "volinfo->shandle"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 774, GF_LOG_ERROR, "Assertion failed: " "volinfo->shandle" ); } while (0); } } while (0); |
775 | |
776 | shandle = volinfo->shandle; |
777 | ret = glusterd_volume_exclude_options_write (fd, volinfo); |
778 | if (ret) |
779 | goto out; |
780 | |
781 | shandle->fd = fd; |
782 | dict_foreach (volinfo->dict, _storeopts, shandle); |
783 | |
784 | dict_foreach (volinfo->gsync_slaves, _storeslaves, shandle); |
785 | shandle->fd = 0; |
786 | out: |
787 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 787, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
788 | return ret; |
789 | } |
790 | |
791 | static void |
792 | glusterd_store_rbstatepath_set (glusterd_volinfo_t *volinfo, char *rbstatepath, |
793 | size_t len) |
794 | { |
795 | char voldirpath[PATH_MAX4096] = {0,}; |
796 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 796, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
797 | GF_ASSERT (rbstatepath)do { if (!(rbstatepath)) { do { do { if (0) printf ("Assertion failed: " "rbstatepath"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 797, GF_LOG_ERROR, "Assertion failed: " "rbstatepath" ); } while (0); } } while (0); |
798 | GF_ASSERT (len <= PATH_MAX)do { if (!(len <= 4096)) { do { do { if (0) printf ("Assertion failed: " "len <= PATH_MAX"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 798, GF_LOG_ERROR, "Assertion failed: " "len <= PATH_MAX" ); } while (0); } } while (0); |
799 | |
800 | glusterd_store_voldirpath_set (volinfo, voldirpath, |
801 | sizeof (voldirpath)); |
802 | snprintf (rbstatepath, len, "%s/%s", voldirpath, |
803 | GLUSTERD_VOLUME_RBSTATE_FILE"rbstate"); |
804 | } |
805 | |
806 | static void |
807 | glusterd_store_volfpath_set (glusterd_volinfo_t *volinfo, char *volfpath, |
808 | size_t len) |
809 | { |
810 | char voldirpath[PATH_MAX4096] = {0,}; |
811 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 811, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
812 | GF_ASSERT (volfpath)do { if (!(volfpath)) { do { do { if (0) printf ("Assertion failed: " "volfpath"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 812, GF_LOG_ERROR, "Assertion failed: " "volfpath" ); } while (0); } } while (0); |
813 | GF_ASSERT (len <= PATH_MAX)do { if (!(len <= 4096)) { do { do { if (0) printf ("Assertion failed: " "len <= PATH_MAX"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 813, GF_LOG_ERROR, "Assertion failed: " "len <= PATH_MAX" ); } while (0); } } while (0); |
814 | |
815 | glusterd_store_voldirpath_set (volinfo, voldirpath, |
816 | sizeof (voldirpath)); |
817 | snprintf (volfpath, len, "%s/%s", voldirpath, GLUSTERD_VOLUME_INFO_FILE"info"); |
818 | } |
819 | |
820 | static void |
821 | glusterd_store_node_state_path_set (glusterd_volinfo_t *volinfo, |
822 | char *node_statepath, size_t len) |
823 | { |
824 | char voldirpath[PATH_MAX4096] = {0,}; |
825 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 825, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
826 | GF_ASSERT (node_statepath)do { if (!(node_statepath)) { do { do { if (0) printf ("Assertion failed: " "node_statepath"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 826, GF_LOG_ERROR, "Assertion failed: " "node_statepath" ); } while (0); } } while (0); |
827 | GF_ASSERT (len <= PATH_MAX)do { if (!(len <= 4096)) { do { do { if (0) printf ("Assertion failed: " "len <= PATH_MAX"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 827, GF_LOG_ERROR, "Assertion failed: " "len <= PATH_MAX" ); } while (0); } } while (0); |
828 | |
829 | glusterd_store_voldirpath_set (volinfo, voldirpath, |
830 | sizeof (voldirpath)); |
831 | snprintf (node_statepath, len, "%s/%s", voldirpath, |
832 | GLUSTERD_NODE_STATE_FILE"node_state.info"); |
833 | } |
834 | |
835 | int32_t |
836 | glusterd_store_create_rbstate_shandle_on_absence (glusterd_volinfo_t *volinfo) |
837 | { |
838 | char rbstatepath[PATH_MAX4096] = {0}; |
839 | int32_t ret = 0; |
840 | |
841 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 841, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
842 | |
843 | glusterd_store_rbstatepath_set (volinfo, rbstatepath, sizeof (rbstatepath)); |
844 | ret = glusterd_store_handle_create_on_absence (&volinfo->rb_shandle, |
845 | rbstatepath); |
846 | return ret; |
847 | } |
848 | |
849 | int32_t |
850 | glusterd_store_create_vol_shandle_on_absence (glusterd_volinfo_t *volinfo) |
851 | { |
852 | char volfpath[PATH_MAX4096] = {0}; |
853 | int32_t ret = 0; |
854 | |
855 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 855, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
856 | |
857 | glusterd_store_volfpath_set (volinfo, volfpath, sizeof (volfpath)); |
858 | ret = glusterd_store_handle_create_on_absence (&volinfo->shandle, |
859 | volfpath); |
860 | return ret; |
861 | } |
862 | |
863 | int32_t |
864 | glusterd_store_create_nodestate_sh_on_absence (glusterd_volinfo_t *volinfo) |
865 | { |
866 | char node_state_path[PATH_MAX4096] = {0}; |
867 | int32_t ret = 0; |
868 | |
869 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 869, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
870 | |
871 | glusterd_store_node_state_path_set (volinfo, node_state_path, |
872 | sizeof (node_state_path)); |
873 | ret = |
874 | glusterd_store_handle_create_on_absence (&volinfo->node_state_shandle, |
875 | node_state_path); |
876 | |
877 | return ret; |
878 | } |
879 | |
880 | int32_t |
881 | glusterd_store_brickinfos (glusterd_volinfo_t *volinfo, int vol_fd) |
882 | { |
883 | int32_t ret = 0; |
884 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); |
885 | int32_t brick_count = 0; |
886 | |
887 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 887, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
888 | |
889 | list_for_each_entry (brickinfo, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { |
890 | ret = glusterd_store_brickinfo (volinfo, brickinfo, |
891 | brick_count, vol_fd); |
892 | if (ret) |
893 | goto out; |
894 | brick_count++; |
895 | } |
896 | out: |
897 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 897, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
898 | return ret; |
899 | } |
900 | |
901 | int32_t |
902 | glusterd_store_rbstate_write (int fd, glusterd_volinfo_t *volinfo) |
903 | { |
904 | int ret = -1; |
905 | int port = 0; |
906 | char buf[PATH_MAX4096] = {0, }; |
907 | |
908 | GF_ASSERT (fd > 0)do { if (!(fd > 0)) { do { do { if (0) printf ("Assertion failed: " "fd > 0"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 908, GF_LOG_ERROR, "Assertion failed: " "fd > 0" ); } while (0); } } while (0); |
909 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 909, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
910 | |
911 | snprintf (buf, sizeof (buf), "%d", volinfo->rep_brick.rb_status); |
912 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_RB_STATUS"rb_status", |
913 | buf); |
914 | if (ret) |
915 | goto out; |
916 | |
917 | if (volinfo->rep_brick.rb_status > GF_RB_STATUS_NONE) { |
918 | |
919 | snprintf (buf, sizeof (buf), "%s:%s", |
920 | volinfo->rep_brick.src_brick->hostname, |
921 | volinfo->rep_brick.src_brick->path); |
922 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_RB_SRC_BRICK"rb_src", |
923 | buf); |
924 | if (ret) |
925 | goto out; |
926 | |
927 | snprintf (buf, sizeof (buf), "%s:%s", |
928 | volinfo->rep_brick.dst_brick->hostname, |
929 | volinfo->rep_brick.dst_brick->path); |
930 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_RB_DST_BRICK"rb_dst", |
931 | buf); |
932 | if (ret) |
933 | goto out; |
934 | |
935 | switch (volinfo->transport_type) { |
936 | case GF_TRANSPORT_RDMA: |
937 | port = volinfo->rep_brick.dst_brick->rdma_port; |
938 | break; |
939 | |
940 | case GF_TRANSPORT_TCP: |
941 | case GF_TRANSPORT_BOTH_TCP_RDMA: |
942 | port = volinfo->rep_brick.dst_brick->port; |
943 | break; |
944 | } |
945 | |
946 | snprintf (buf, sizeof (buf), "%d", port); |
947 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_RB_DST_PORT"rb_port", |
948 | buf); |
949 | if (ret) |
950 | goto out; |
951 | uuid_unparse (volinfo->rep_brick.rb_id, buf); |
952 | ret = glusterd_store_save_value (fd, GF_REPLACE_BRICK_TID_KEY"replace-brick-id", |
953 | buf); |
954 | } |
955 | |
956 | ret = 0; |
957 | out: |
958 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 958, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
959 | return ret; |
960 | } |
961 | |
962 | int32_t |
963 | glusterd_store_perform_rbstate_store (glusterd_volinfo_t *volinfo) |
964 | { |
965 | int fd = -1; |
966 | int32_t ret = -1; |
967 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 967, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
968 | |
969 | fd = glusterd_store_mkstemp (volinfo->rb_shandle); |
970 | if (fd <= 0) { |
971 | ret = -1; |
972 | goto out; |
973 | } |
974 | |
975 | ret = glusterd_store_rbstate_write (fd, volinfo); |
976 | if (ret) |
977 | goto out; |
978 | |
979 | ret = glusterd_store_rename_tmppath (volinfo->rb_shandle); |
980 | if (ret) |
981 | goto out; |
982 | |
983 | out: |
984 | if (ret && (fd > 0)) |
985 | glusterd_store_unlink_tmppath (volinfo->rb_shandle); |
986 | if (fd > 0) |
987 | close (fd); |
988 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 988, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
989 | return ret; |
990 | } |
991 | |
992 | int32_t |
993 | glusterd_store_node_state_write (int fd, glusterd_volinfo_t *volinfo) |
994 | { |
995 | int ret = -1; |
996 | char buf[PATH_MAX4096] = {0, }; |
997 | |
998 | GF_ASSERT (fd > 0)do { if (!(fd > 0)) { do { do { if (0) printf ("Assertion failed: " "fd > 0"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 998, GF_LOG_ERROR, "Assertion failed: " "fd > 0" ); } while (0); } } while (0); |
999 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 999, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1000 | |
1001 | if (volinfo->rebal.defrag_cmd == GF_DEFRAG_CMD_STATUS) { |
1002 | ret = 0; |
1003 | goto out; |
1004 | } |
1005 | |
1006 | snprintf (buf, sizeof (buf), "%d", volinfo->rebal.defrag_cmd); |
1007 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_DEFRAG"rebalance_status", |
1008 | buf); |
1009 | if (ret) |
1010 | goto out; |
1011 | |
1012 | snprintf (buf, sizeof (buf), "%d", volinfo->rebal.op); |
1013 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_DEFRAG_OP"rebalance_op", |
1014 | buf); |
1015 | if (ret) |
1016 | goto out; |
1017 | |
1018 | if (volinfo->rebal.defrag_cmd) { |
1019 | uuid_unparse (volinfo->rebal.rebalance_id, buf); |
1020 | ret = glusterd_store_save_value (fd, |
1021 | GF_REBALANCE_TID_KEY"rebalance-id", |
1022 | buf); |
1023 | } |
1024 | out: |
1025 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 1025, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
1026 | return ret; |
1027 | } |
1028 | |
1029 | int32_t |
1030 | glusterd_store_perform_node_state_store (glusterd_volinfo_t *volinfo) |
1031 | { |
1032 | int fd = -1; |
1033 | int32_t ret = -1; |
1034 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1034, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1035 | |
1036 | fd = glusterd_store_mkstemp (volinfo->node_state_shandle); |
1037 | if (fd <= 0) { |
1038 | ret = -1; |
1039 | goto out; |
1040 | } |
1041 | |
1042 | ret = glusterd_store_node_state_write (fd, volinfo); |
1043 | if (ret) |
1044 | goto out; |
1045 | |
1046 | ret = glusterd_store_rename_tmppath (volinfo->node_state_shandle); |
1047 | if (ret) |
1048 | goto out; |
1049 | |
1050 | out: |
1051 | if (ret && (fd > 0)) |
1052 | glusterd_store_unlink_tmppath (volinfo->node_state_shandle); |
1053 | if (fd > 0) |
1054 | close (fd); |
1055 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 1055, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
1056 | return ret; |
1057 | } |
1058 | |
1059 | int32_t |
1060 | glusterd_store_perform_volume_store (glusterd_volinfo_t *volinfo) |
1061 | { |
1062 | int fd = -1; |
1063 | int32_t ret = -1; |
1064 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1064, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1065 | |
1066 | fd = glusterd_store_mkstemp (volinfo->shandle); |
1067 | if (fd <= 0) { |
1068 | ret = -1; |
1069 | goto out; |
1070 | } |
1071 | |
1072 | ret = glusterd_store_volinfo_write (fd, volinfo); |
1073 | if (ret) |
1074 | goto out; |
1075 | |
1076 | ret = glusterd_store_brickinfos (volinfo, fd); |
1077 | if (ret) |
1078 | goto out; |
1079 | |
1080 | out: |
1081 | if (ret && (fd > 0)) |
1082 | glusterd_store_unlink_tmppath (volinfo->shandle); |
1083 | if (fd > 0) |
1084 | close (fd); |
1085 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 1085, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
1086 | return ret; |
1087 | } |
1088 | |
1089 | void |
1090 | glusterd_perform_volinfo_version_action (glusterd_volinfo_t *volinfo, |
1091 | glusterd_volinfo_ver_ac_t ac) |
1092 | { |
1093 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1093, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1094 | |
1095 | switch (ac) { |
1096 | case GLUSTERD_VOLINFO_VER_AC_NONE: |
1097 | break; |
1098 | case GLUSTERD_VOLINFO_VER_AC_INCREMENT: |
1099 | volinfo->version++; |
1100 | break; |
1101 | case GLUSTERD_VOLINFO_VER_AC_DECREMENT: |
1102 | volinfo->version--; |
1103 | break; |
1104 | } |
1105 | } |
1106 | |
1107 | void |
1108 | glusterd_store_bricks_cleanup_tmp (glusterd_volinfo_t *volinfo) |
1109 | { |
1110 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); |
1111 | |
1112 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1112, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1113 | |
1114 | list_for_each_entry (brickinfo, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { |
1115 | glusterd_store_unlink_tmppath (brickinfo->shandle); |
1116 | } |
1117 | } |
1118 | |
1119 | void |
1120 | glusterd_store_volume_cleanup_tmp (glusterd_volinfo_t *volinfo) |
1121 | { |
1122 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1122, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1123 | |
1124 | glusterd_store_bricks_cleanup_tmp (volinfo); |
1125 | |
1126 | glusterd_store_unlink_tmppath (volinfo->shandle); |
1127 | |
1128 | glusterd_store_unlink_tmppath (volinfo->rb_shandle); |
1129 | |
1130 | glusterd_store_unlink_tmppath (volinfo->node_state_shandle); |
1131 | } |
1132 | |
1133 | int32_t |
1134 | glusterd_store_brickinfos_atomic_update (glusterd_volinfo_t *volinfo) |
1135 | { |
1136 | int ret = -1; |
1137 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); |
1138 | |
1139 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1139, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1140 | |
1141 | list_for_each_entry (brickinfo, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { |
1142 | ret = glusterd_store_rename_tmppath (brickinfo->shandle); |
1143 | if (ret) |
1144 | goto out; |
1145 | } |
1146 | out: |
1147 | return ret; |
1148 | } |
1149 | |
1150 | int32_t |
1151 | glusterd_store_volinfo_atomic_update (glusterd_volinfo_t *volinfo) |
1152 | { |
1153 | int ret = -1; |
1154 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1154, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1155 | |
1156 | ret = glusterd_store_rename_tmppath (volinfo->shandle); |
1157 | if (ret) |
1158 | goto out; |
1159 | |
1160 | out: |
1161 | if (ret) |
1162 | gf_log (THIS->name, GF_LOG_ERROR, "Couldn't rename "do { do { if (0) printf ("Couldn't rename " "temporary file(s): Reason %s" , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-store.c", __FUNCTION__ , 1163, GF_LOG_ERROR, "Couldn't rename " "temporary file(s): Reason %s" , strerror ((*__errno_location ()))); } while (0) |
1163 | "temporary file(s): Reason %s", strerror (errno))do { do { if (0) printf ("Couldn't rename " "temporary file(s): Reason %s" , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-store.c", __FUNCTION__ , 1163, GF_LOG_ERROR, "Couldn't rename " "temporary file(s): Reason %s" , strerror ((*__errno_location ()))); } while (0); |
1164 | return ret; |
1165 | } |
1166 | |
1167 | int32_t |
1168 | glusterd_store_volume_atomic_update (glusterd_volinfo_t *volinfo) |
1169 | { |
1170 | int ret = -1; |
1171 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1171, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1172 | |
1173 | ret = glusterd_store_brickinfos_atomic_update (volinfo); |
1174 | if (ret) |
1175 | goto out; |
1176 | |
1177 | ret = glusterd_store_volinfo_atomic_update (volinfo); |
1178 | |
1179 | out: |
1180 | return ret; |
1181 | } |
1182 | |
1183 | int32_t |
1184 | glusterd_store_volinfo (glusterd_volinfo_t *volinfo, glusterd_volinfo_ver_ac_t ac) |
1185 | { |
1186 | int32_t ret = -1; |
1187 | |
1188 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1188, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1189 | |
1190 | glusterd_perform_volinfo_version_action (volinfo, ac); |
1191 | ret = glusterd_store_create_volume_dir (volinfo); |
1192 | if (ret) |
1193 | goto out; |
1194 | |
1195 | ret = glusterd_store_create_vol_shandle_on_absence (volinfo); |
1196 | if (ret) |
1197 | goto out; |
1198 | |
1199 | ret = glusterd_store_create_rbstate_shandle_on_absence (volinfo); |
1200 | if (ret) |
1201 | goto out; |
1202 | |
1203 | ret = glusterd_store_create_nodestate_sh_on_absence (volinfo); |
1204 | if (ret) |
1205 | goto out; |
1206 | |
1207 | ret = glusterd_store_perform_volume_store (volinfo); |
1208 | if (ret) |
1209 | goto out; |
1210 | |
1211 | ret = glusterd_store_volume_atomic_update (volinfo); |
1212 | if (ret) { |
1213 | glusterd_perform_volinfo_version_action (volinfo, |
1214 | GLUSTERD_VOLINFO_VER_AC_DECREMENT); |
1215 | goto out; |
1216 | } |
1217 | |
1218 | ret = glusterd_store_perform_rbstate_store (volinfo); |
1219 | if (ret) |
1220 | goto out; |
1221 | |
1222 | ret = glusterd_store_perform_node_state_store (volinfo); |
1223 | if (ret) |
1224 | goto out; |
1225 | |
1226 | //checksum should be computed at the end |
1227 | ret = glusterd_volume_compute_cksum (volinfo); |
1228 | if (ret) |
1229 | goto out; |
1230 | |
1231 | out: |
1232 | if (ret) |
1233 | glusterd_store_volume_cleanup_tmp (volinfo); |
1234 | |
1235 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 1235, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
1236 | |
1237 | return ret; |
1238 | } |
1239 | |
1240 | |
1241 | int32_t |
1242 | glusterd_store_delete_volume (glusterd_volinfo_t *volinfo) |
1243 | { |
1244 | char pathname[PATH_MAX4096] = {0,}; |
1245 | int32_t ret = 0; |
1246 | glusterd_conf_t *priv = NULL((void*)0); |
1247 | DIR *dir = NULL((void*)0); |
1248 | struct dirent *entry = NULL((void*)0); |
1249 | char path[PATH_MAX4096] = {0,}; |
1250 | char delete_path[PATH_MAX4096] = {0,}; |
1251 | char trashdir[PATH_MAX4096] = {0,}; |
1252 | struct stat st = {0, }; |
1253 | xlator_t *this = NULL((void*)0); |
1254 | gf_boolean_t rename_fail = _gf_false; |
1255 | |
1256 | this = THIS(*__glusterfs_this_location()); |
1257 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1257, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); |
1258 | |
1259 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1259, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
1260 | priv = this->private; |
1261 | |
1262 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1262, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); |
1263 | |
1264 | GLUSTERD_GET_VOLUME_DIR (pathname, volinfo, priv)snprintf (pathname, 4096, "%s/vols/%s", priv->workdir, volinfo ->volname);; |
1265 | |
1266 | snprintf (delete_path, sizeof (delete_path), |
1267 | "%s/"GLUSTERD_TRASH"trash""/%s.deleted", priv->workdir, |
1268 | uuid_utoa (volinfo->volume_id)); |
1269 | |
1270 | snprintf (trashdir, sizeof (trashdir), "%s/"GLUSTERD_TRASH"trash", |
1271 | priv->workdir); |
1272 | |
1273 | ret = mkdir (trashdir, 0777); |
1274 | if (ret && errno(*__errno_location ()) != EEXIST17) { |
1275 | gf_log (this->name, GF_LOG_ERROR, "Failed to create trash "do { do { if (0) printf ("Failed to create trash " "directory, reason : %s" , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 1276, GF_LOG_ERROR , "Failed to create trash " "directory, reason : %s", strerror ((*__errno_location ()))); } while (0) |
1276 | "directory, reason : %s", strerror (errno))do { do { if (0) printf ("Failed to create trash " "directory, reason : %s" , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 1276, GF_LOG_ERROR , "Failed to create trash " "directory, reason : %s", strerror ((*__errno_location ()))); } while (0); |
1277 | ret = -1; |
1278 | goto out; |
1279 | } |
1280 | |
1281 | ret = rename (pathname, delete_path); |
1282 | if (ret) { |
1283 | gf_log (this->name, GF_LOG_ERROR, "Failed to rename volume "do { do { if (0) printf ("Failed to rename volume " "directory for volume %s" , volinfo->volname); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1284, GF_LOG_ERROR, "Failed to rename volume " "directory for volume %s", volinfo->volname); } while (0) |
1284 | "directory for volume %s", volinfo->volname)do { do { if (0) printf ("Failed to rename volume " "directory for volume %s" , volinfo->volname); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1284, GF_LOG_ERROR, "Failed to rename volume " "directory for volume %s", volinfo->volname); } while (0); |
1285 | rename_fail = _gf_true; |
1286 | goto out; |
1287 | } |
1288 | |
1289 | dir = opendir (delete_path); |
1290 | if (!dir) { |
1291 | gf_log (this->name, GF_LOG_DEBUG, "Failed to open directory %s."do { do { if (0) printf ("Failed to open directory %s." " Reason : %s" , delete_path, strerror ((*__errno_location ()))); } while (0 ); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1292 , GF_LOG_DEBUG, "Failed to open directory %s." " Reason : %s" , delete_path, strerror ((*__errno_location ()))); } while (0 ) |
1292 | " Reason : %s", delete_path, strerror (errno))do { do { if (0) printf ("Failed to open directory %s." " Reason : %s" , delete_path, strerror ((*__errno_location ()))); } while (0 ); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1292 , GF_LOG_DEBUG, "Failed to open directory %s." " Reason : %s" , delete_path, strerror ((*__errno_location ()))); } while (0 ); |
1293 | ret = 0; |
1294 | goto out; |
1295 | } |
1296 | ret = glusterd_store_remove_bricks (volinfo, delete_path); |
1297 | |
1298 | if (ret) { |
1299 | gf_log (this->name, GF_LOG_DEBUG, "Remove bricks failed for %s",do { do { if (0) printf ("Remove bricks failed for %s", volinfo ->volname); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1300, GF_LOG_DEBUG, "Remove bricks failed for %s" , volinfo->volname); } while (0) |
1300 | volinfo->volname)do { do { if (0) printf ("Remove bricks failed for %s", volinfo ->volname); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1300, GF_LOG_DEBUG, "Remove bricks failed for %s" , volinfo->volname); } while (0); |
1301 | } |
1302 | |
1303 | glusterd_for_each_entry (entry, dir)do { entry = ((void*)0); if (dir) { entry = readdir (dir); while (entry && (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, ".."))) { entry = readdir (dir); } } } while (0);; |
1304 | while (entry) { |
1305 | |
1306 | snprintf (path, PATH_MAX4096, "%s/%s", delete_path, entry->d_name); |
1307 | ret = stat (path, &st); |
1308 | if (ret == -1) { |
1309 | gf_log (this->name, GF_LOG_DEBUG, "Failed to stat "do { do { if (0) printf ("Failed to stat " "entry %s : %s", path , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 1310, GF_LOG_DEBUG , "Failed to stat " "entry %s : %s", path, strerror ((*__errno_location ()))); } while (0) |
1310 | "entry %s : %s", path, strerror (errno))do { do { if (0) printf ("Failed to stat " "entry %s : %s", path , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 1310, GF_LOG_DEBUG , "Failed to stat " "entry %s : %s", path, strerror ((*__errno_location ()))); } while (0); |
1311 | goto stat_failed; |
1312 | } |
1313 | |
1314 | if (S_ISDIR (st.st_mode)((((st.st_mode)) & 0170000) == (0040000))) |
1315 | ret = rmdir (path); |
1316 | else |
1317 | ret = unlink (path); |
1318 | |
1319 | if (ret) { |
1320 | gf_log (this->name, GF_LOG_DEBUG, " Failed to remove "do { do { if (0) printf (" Failed to remove " "%s. Reason : %s" , path, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1321, GF_LOG_DEBUG , " Failed to remove " "%s. Reason : %s", path, strerror ((*__errno_location ()))); } while (0) |
1321 | "%s. Reason : %s", path, strerror (errno))do { do { if (0) printf (" Failed to remove " "%s. Reason : %s" , path, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1321, GF_LOG_DEBUG , " Failed to remove " "%s. Reason : %s", path, strerror ((*__errno_location ()))); } while (0); |
1322 | } |
1323 | |
1324 | gf_log (this->name, GF_LOG_DEBUG, "%s %s",do { do { if (0) printf ("%s %s", ret ? "Failed to remove":"Removed" , entry->d_name); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1326, GF_LOG_DEBUG, "%s %s", ret ? "Failed to remove" :"Removed", entry->d_name); } while (0) |
1325 | ret ? "Failed to remove":"Removed",do { do { if (0) printf ("%s %s", ret ? "Failed to remove":"Removed" , entry->d_name); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1326, GF_LOG_DEBUG, "%s %s", ret ? "Failed to remove" :"Removed", entry->d_name); } while (0) |
1326 | entry->d_name)do { do { if (0) printf ("%s %s", ret ? "Failed to remove":"Removed" , entry->d_name); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1326, GF_LOG_DEBUG, "%s %s", ret ? "Failed to remove" :"Removed", entry->d_name); } while (0); |
1327 | stat_failed: |
1328 | memset (path, 0, sizeof(path)); |
1329 | glusterd_for_each_entry (entry, dir)do { entry = ((void*)0); if (dir) { entry = readdir (dir); while (entry && (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, ".."))) { entry = readdir (dir); } } } while (0);; |
1330 | } |
1331 | |
1332 | ret = closedir (dir); |
1333 | if (ret) { |
1334 | gf_log (this->name, GF_LOG_DEBUG, "Failed to close dir %s. "do { do { if (0) printf ("Failed to close dir %s. " "Reason : %s" ,delete_path, strerror ((*__errno_location ()))); } while (0) ; _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1335 , GF_LOG_DEBUG, "Failed to close dir %s. " "Reason : %s",delete_path , strerror ((*__errno_location ()))); } while (0) |
1335 | "Reason : %s",delete_path, strerror (errno))do { do { if (0) printf ("Failed to close dir %s. " "Reason : %s" ,delete_path, strerror ((*__errno_location ()))); } while (0) ; _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1335 , GF_LOG_DEBUG, "Failed to close dir %s. " "Reason : %s",delete_path , strerror ((*__errno_location ()))); } while (0); |
1336 | } |
1337 | |
1338 | ret = rmdir (delete_path); |
1339 | if (ret) { |
1340 | gf_log (this->name, GF_LOG_DEBUG, "Failed to rmdir: %s,err: %s",do { do { if (0) printf ("Failed to rmdir: %s,err: %s", delete_path , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 1341, GF_LOG_DEBUG , "Failed to rmdir: %s,err: %s", delete_path, strerror ((*__errno_location ()))); } while (0) |
1341 | delete_path, strerror (errno))do { do { if (0) printf ("Failed to rmdir: %s,err: %s", delete_path , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 1341, GF_LOG_DEBUG , "Failed to rmdir: %s,err: %s", delete_path, strerror ((*__errno_location ()))); } while (0); |
1342 | } |
1343 | ret = rmdir (trashdir); |
1344 | if (ret) { |
1345 | gf_log (this->name, GF_LOG_DEBUG, "Failed to rmdir: %s, Reason:"do { do { if (0) printf ("Failed to rmdir: %s, Reason:" " %s" , trashdir, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1346, GF_LOG_DEBUG , "Failed to rmdir: %s, Reason:" " %s", trashdir, strerror (( *__errno_location ()))); } while (0) |
1346 | " %s", trashdir, strerror (errno))do { do { if (0) printf ("Failed to rmdir: %s, Reason:" " %s" , trashdir, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1346, GF_LOG_DEBUG , "Failed to rmdir: %s, Reason:" " %s", trashdir, strerror (( *__errno_location ()))); } while (0); |
1347 | } |
1348 | |
1349 | out: |
1350 | if (volinfo->shandle) { |
1351 | glusterd_store_handle_destroy (volinfo->shandle); |
1352 | volinfo->shandle = NULL((void*)0); |
1353 | } |
1354 | ret = (rename_fail == _gf_true) ? -1: 0; |
1355 | |
1356 | gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1356, GF_LOG_DEBUG , "Returning %d", ret); } while (0); |
1357 | return ret; |
1358 | } |
1359 | |
1360 | |
1361 | int |
1362 | glusterd_store_read_and_tokenize (FILE *file, char *str, |
1363 | char **iter_key, char **iter_val, |
1364 | glusterd_store_op_errno_t *store_errno) |
1365 | { |
1366 | int32_t ret = -1; |
1367 | char *savetok = NULL((void*)0); |
1368 | |
1369 | GF_ASSERT (file)do { if (!(file)) { do { do { if (0) printf ("Assertion failed: " "file"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1369, GF_LOG_ERROR, "Assertion failed: " "file" ); } while (0); } } while (0); |
1370 | GF_ASSERT (str)do { if (!(str)) { do { do { if (0) printf ("Assertion failed: " "str"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1370, GF_LOG_ERROR, "Assertion failed: " "str" ); } while (0); } } while (0); |
1371 | GF_ASSERT (iter_key)do { if (!(iter_key)) { do { do { if (0) printf ("Assertion failed: " "iter_key"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1371, GF_LOG_ERROR, "Assertion failed: " "iter_key" ); } while (0); } } while (0); |
1372 | GF_ASSERT (iter_val)do { if (!(iter_val)) { do { do { if (0) printf ("Assertion failed: " "iter_val"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1372, GF_LOG_ERROR, "Assertion failed: " "iter_val" ); } while (0); } } while (0); |
1373 | GF_ASSERT (store_errno)do { if (!(store_errno)) { do { do { if (0) printf ("Assertion failed: " "store_errno"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1373, GF_LOG_ERROR, "Assertion failed: " "store_errno" ); } while (0); } } while (0); |
1374 | |
1375 | ret = fscanf (file, "%s", str); |
1376 | if (ret <= 0 || feof (file)) { |
1377 | ret = -1; |
1378 | *store_errno = GD_STORE_EOF; |
1379 | goto out; |
1380 | } |
1381 | |
1382 | *iter_key = strtok_r (str, "=", &savetok); |
1383 | if (*iter_key == NULL((void*)0)) { |
1384 | ret = -1; |
1385 | *store_errno = GD_STORE_KEY_NULL; |
1386 | goto out; |
1387 | } |
1388 | |
1389 | *iter_val = strtok_r (NULL((void*)0), "=", &savetok); |
1390 | if (*iter_key == NULL((void*)0)) { |
1391 | ret = -1; |
1392 | *store_errno = GD_STORE_VALUE_NULL; |
1393 | goto out; |
1394 | } |
1395 | |
1396 | *store_errno = GD_STORE_SUCCESS; |
1397 | ret = 0; |
1398 | out: |
1399 | return ret; |
1400 | } |
1401 | |
1402 | int32_t |
1403 | glusterd_store_retrieve_value (glusterd_store_handle_t *handle, |
1404 | char *key, char **value) |
1405 | { |
1406 | int32_t ret = -1; |
1407 | char *scan_str = NULL((void*)0); |
1408 | char *iter_key = NULL((void*)0); |
1409 | char *iter_val = NULL((void*)0); |
1410 | char *free_str = NULL((void*)0); |
1411 | struct stat st = {0,}; |
1412 | glusterd_store_op_errno_t store_errno = GD_STORE_SUCCESS; |
1413 | |
1414 | GF_ASSERT (handle)do { if (!(handle)) { do { do { if (0) printf ("Assertion failed: " "handle"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1414, GF_LOG_ERROR, "Assertion failed: " "handle" ); } while (0); } } while (0); |
1415 | |
1416 | handle->fd = open (handle->path, O_RDWR02); |
1417 | |
1418 | if (handle->fd == -1) { |
1419 | gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %s",do { do { if (0) printf ("Unable to open file %s errno: %s", handle ->path, strerror ((*__errno_location ()))); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1420, GF_LOG_ERROR, "Unable to open file %s errno: %s" , handle->path, strerror ((*__errno_location ()))); } while (0) |
1420 | handle->path, strerror (errno))do { do { if (0) printf ("Unable to open file %s errno: %s", handle ->path, strerror ((*__errno_location ()))); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1420, GF_LOG_ERROR, "Unable to open file %s errno: %s" , handle->path, strerror ((*__errno_location ()))); } while (0); |
1421 | goto out; |
1422 | } |
1423 | if (!handle->read) |
1424 | handle->read = fdopen (handle->fd, "r"); |
1425 | |
1426 | if (!handle->read) { |
1427 | gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %s",do { do { if (0) printf ("Unable to open file %s errno: %s", handle ->path, strerror ((*__errno_location ()))); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1428, GF_LOG_ERROR, "Unable to open file %s errno: %s" , handle->path, strerror ((*__errno_location ()))); } while (0) |
1428 | handle->path, strerror (errno))do { do { if (0) printf ("Unable to open file %s errno: %s", handle ->path, strerror ((*__errno_location ()))); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1428, GF_LOG_ERROR, "Unable to open file %s errno: %s" , handle->path, strerror ((*__errno_location ()))); } while (0); |
1429 | goto out; |
1430 | } |
1431 | |
1432 | ret = fstat (handle->fd, &st); |
1433 | if (ret < 0) { |
1434 | gf_log ("glusterd", GF_LOG_WARNING,do { do { if (0) printf ("stat on file failed"); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__, 1435, GF_LOG_WARNING, "stat on file failed"); } while (0) |
1435 | "stat on file failed")do { do { if (0) printf ("stat on file failed"); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__, 1435, GF_LOG_WARNING, "stat on file failed"); } while (0); |
1436 | ret = -1; |
1437 | store_errno = GD_STORE_STAT_FAILED; |
1438 | goto out; |
1439 | } |
1440 | |
1441 | scan_str = GF_CALLOC (1, st.st_size,__gf_calloc (1, st.st_size, gf_gld_mt_char) |
1442 | gf_gld_mt_char)__gf_calloc (1, st.st_size, gf_gld_mt_char); |
1443 | if (scan_str == NULL((void*)0)) { |
1444 | ret = -1; |
1445 | store_errno = GD_STORE_ENOMEM; |
1446 | goto out; |
1447 | } |
1448 | |
1449 | free_str = scan_str; |
1450 | |
1451 | do { |
1452 | ret = glusterd_store_read_and_tokenize (handle->read, scan_str, |
1453 | &iter_key, &iter_val, |
1454 | &store_errno); |
1455 | if (ret < 0) { |
1456 | goto out; |
1457 | } |
1458 | |
1459 | gf_log ("", GF_LOG_DEBUG, "key %s read", iter_key)do { do { if (0) printf ("key %s read", iter_key); } while (0 ); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1459, GF_LOG_DEBUG , "key %s read", iter_key); } while (0); |
1460 | |
1461 | if (!strcmp (key, iter_key)) { |
1462 | gf_log ("", GF_LOG_DEBUG, "key %s found", key)do { do { if (0) printf ("key %s found", key); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1462, GF_LOG_DEBUG, "key %s found" , key); } while (0); |
1463 | ret = 0; |
1464 | if (iter_val) |
1465 | *value = gf_strdup (iter_val); |
1466 | goto out; |
1467 | } |
1468 | } while (1); |
1469 | out: |
1470 | if (handle->fd > 0) { |
1471 | close (handle->fd); |
1472 | handle->read = NULL((void*)0); |
1473 | } |
1474 | |
1475 | GF_FREE (free_str)__gf_free (free_str); |
1476 | |
1477 | return ret; |
1478 | } |
1479 | |
1480 | int32_t |
1481 | glusterd_store_save_value (int fd, char *key, char *value) |
1482 | { |
1483 | int32_t ret = -1; |
1484 | FILE *fp = NULL((void*)0); |
1485 | xlator_t *this = NULL((void*)0); |
1486 | |
1487 | this = THIS(*__glusterfs_this_location()); |
1488 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1488, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); |
1489 | GF_ASSERT (fd > 0)do { if (!(fd > 0)) { do { do { if (0) printf ("Assertion failed: " "fd > 0"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1489, GF_LOG_ERROR, "Assertion failed: " "fd > 0" ); } while (0); } } while (0); |
1490 | GF_ASSERT (key)do { if (!(key)) { do { do { if (0) printf ("Assertion failed: " "key"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1490, GF_LOG_ERROR, "Assertion failed: " "key" ); } while (0); } } while (0); |
1491 | GF_ASSERT (value)do { if (!(value)) { do { do { if (0) printf ("Assertion failed: " "value"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1491, GF_LOG_ERROR, "Assertion failed: " "value" ); } while (0); } } while (0); |
1492 | |
1493 | fp = fdopen (fd, "a+"); |
1494 | if (fp == NULL((void*)0)) { |
1495 | gf_log (this->name, GF_LOG_WARNING, "fdopen failed.")do { do { if (0) printf ("fdopen failed."); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1495, GF_LOG_WARNING , "fdopen failed."); } while (0); |
1496 | ret = -1; |
1497 | goto out; |
1498 | } |
1499 | |
1500 | ret = fprintf (fp, "%s=%s\n", key, value); |
1501 | if (ret < 0) { |
1502 | gf_log (this->name, GF_LOG_WARNING, "Unable to store key: %s,"do { do { if (0) printf ("Unable to store key: %s," "value: %s, error: %s" , key, value, strerror ((*__errno_location ()))); } while (0) ; _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1504 , GF_LOG_WARNING, "Unable to store key: %s," "value: %s, error: %s" , key, value, strerror ((*__errno_location ()))); } while (0) |
1503 | "value: %s, error: %s", key, value,do { do { if (0) printf ("Unable to store key: %s," "value: %s, error: %s" , key, value, strerror ((*__errno_location ()))); } while (0) ; _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1504 , GF_LOG_WARNING, "Unable to store key: %s," "value: %s, error: %s" , key, value, strerror ((*__errno_location ()))); } while (0) |
1504 | strerror (errno))do { do { if (0) printf ("Unable to store key: %s," "value: %s, error: %s" , key, value, strerror ((*__errno_location ()))); } while (0) ; _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1504 , GF_LOG_WARNING, "Unable to store key: %s," "value: %s, error: %s" , key, value, strerror ((*__errno_location ()))); } while (0); |
1505 | ret = -1; |
1506 | goto out; |
1507 | } |
1508 | |
1509 | ret = fflush (fp); |
1510 | if (feof (fp)) { |
1511 | gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("fflush failed, error: %s", strerror ((*__errno_location ()))); } while (0); _gf_log (this->name , "glusterd-store.c", __FUNCTION__, 1513, GF_LOG_WARNING, "fflush failed, error: %s" , strerror ((*__errno_location ()))); } while (0) |
1512 | "fflush failed, error: %s",do { do { if (0) printf ("fflush failed, error: %s", strerror ((*__errno_location ()))); } while (0); _gf_log (this->name , "glusterd-store.c", __FUNCTION__, 1513, GF_LOG_WARNING, "fflush failed, error: %s" , strerror ((*__errno_location ()))); } while (0) |
1513 | strerror (errno))do { do { if (0) printf ("fflush failed, error: %s", strerror ((*__errno_location ()))); } while (0); _gf_log (this->name , "glusterd-store.c", __FUNCTION__, 1513, GF_LOG_WARNING, "fflush failed, error: %s" , strerror ((*__errno_location ()))); } while (0); |
1514 | ret = -1; |
1515 | goto out; |
1516 | } |
1517 | |
1518 | ret = 0; |
1519 | out: |
1520 | |
1521 | gf_log (this->name, GF_LOG_DEBUG, "returning: %d", ret)do { do { if (0) printf ("returning: %d", ret); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1521, GF_LOG_DEBUG , "returning: %d", ret); } while (0); |
1522 | return ret; |
1523 | } |
1524 | |
1525 | int32_t |
1526 | glusterd_store_handle_new (char *path, glusterd_store_handle_t **handle) |
1527 | { |
1528 | int32_t ret = -1; |
1529 | glusterd_store_handle_t *shandle = NULL((void*)0); |
1530 | int fd = -1; |
1531 | char *spath = NULL((void*)0); |
1532 | xlator_t *this = NULL((void*)0); |
1533 | |
1534 | this = THIS(*__glusterfs_this_location()); |
1535 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1535, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); |
1536 | |
1537 | shandle = GF_CALLOC (1, sizeof (*shandle), gf_gld_mt_store_handle_t)__gf_calloc (1, sizeof (*shandle), gf_gld_mt_store_handle_t); |
1538 | if (!shandle) |
1539 | goto out; |
1540 | |
1541 | spath = gf_strdup (path); |
1542 | |
1543 | if (!spath) |
1544 | goto out; |
1545 | |
1546 | fd = open (path, O_RDWR02 | O_CREAT0100 | O_APPEND02000, 0600); |
1547 | if (fd <= 0) { |
1548 | gf_log (this->name, GF_LOG_ERROR, "Failed to open file: %s, "do { do { if (0) printf ("Failed to open file: %s, " "error: %s" , path, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1549, GF_LOG_ERROR , "Failed to open file: %s, " "error: %s", path, strerror ((* __errno_location ()))); } while (0) |
1549 | "error: %s", path, strerror (errno))do { do { if (0) printf ("Failed to open file: %s, " "error: %s" , path, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1549, GF_LOG_ERROR , "Failed to open file: %s, " "error: %s", path, strerror ((* __errno_location ()))); } while (0); |
1550 | goto out; |
1551 | } |
1552 | |
1553 | ret = glusterd_store_sync_direntry (spath); |
1554 | if (ret) |
1555 | goto out; |
1556 | |
1557 | shandle->path = spath; |
1558 | *handle = shandle; |
1559 | |
1560 | ret = 0; |
1561 | out: |
1562 | if (fd > 0) |
1563 | close (fd); |
1564 | |
1565 | if (ret == -1) { |
1566 | GF_FREE (spath)__gf_free (spath); |
1567 | GF_FREE (shandle)__gf_free (shandle); |
1568 | } |
1569 | |
1570 | gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1570, GF_LOG_DEBUG , "Returning %d", ret); } while (0); |
1571 | return ret; |
1572 | } |
1573 | |
1574 | int |
1575 | glusterd_store_handle_retrieve (char *path, glusterd_store_handle_t **handle) |
1576 | { |
1577 | int32_t ret = -1; |
1578 | struct stat statbuf = {0}; |
1579 | |
1580 | ret = stat (path, &statbuf); |
1581 | if (ret) { |
1582 | gf_log ("glusterd", GF_LOG_ERROR, "Unable to retrieve store "do { do { if (0) printf ("Unable to retrieve store " "handle for %s, error: %s" , path, strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__, 1583, GF_LOG_ERROR , "Unable to retrieve store " "handle for %s, error: %s", path , strerror ((*__errno_location ()))); } while (0) |
1583 | "handle for %s, error: %s", path, strerror (errno))do { do { if (0) printf ("Unable to retrieve store " "handle for %s, error: %s" , path, strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__, 1583, GF_LOG_ERROR , "Unable to retrieve store " "handle for %s, error: %s", path , strerror ((*__errno_location ()))); } while (0); |
1584 | goto out; |
1585 | } |
1586 | ret = glusterd_store_handle_new (path, handle); |
1587 | out: |
1588 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1588, GF_LOG_DEBUG, "Returning %d" , ret); } while (0); |
1589 | return ret; |
1590 | } |
1591 | |
1592 | int32_t |
1593 | glusterd_store_handle_destroy (glusterd_store_handle_t *handle) |
1594 | { |
1595 | int32_t ret = -1; |
1596 | |
1597 | if (!handle) { |
1598 | ret = 0; |
1599 | goto out; |
1600 | } |
1601 | |
1602 | GF_FREE (handle->path)__gf_free (handle->path); |
1603 | |
1604 | GF_FREE (handle)__gf_free (handle); |
1605 | |
1606 | ret = 0; |
1607 | |
1608 | out: |
1609 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-store.c" , __FUNCTION__, 1609, GF_LOG_DEBUG, "Returning %d", ret); } while (0); |
1610 | |
1611 | return ret; |
1612 | } |
1613 | |
1614 | int |
1615 | glusterd_store_global_info (xlator_t *this) |
1616 | { |
1617 | int ret = -1; |
1618 | glusterd_conf_t *conf = NULL((void*)0); |
1619 | char op_version_str[15] = {0,}; |
1620 | char path[PATH_MAX4096] = {0,}; |
1621 | glusterd_store_handle_t *handle = NULL((void*)0); |
1622 | char *uuid_str = NULL((void*)0); |
1623 | |
1624 | conf = this->private; |
1625 | |
1626 | uuid_str = gf_strdup (uuid_utoa (MY_UUID(__glusterd_uuid()))); |
1627 | if (!uuid_str) |
1628 | goto out; |
1629 | |
1630 | if (!conf->handle) { |
1631 | snprintf (path, PATH_MAX4096, "%s/%s", conf->workdir, |
1632 | GLUSTERD_INFO_FILE"glusterd.info"); |
1633 | ret = glusterd_store_handle_new (path, &handle); |
1634 | if (ret) { |
1635 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Unable to get store handle"); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 1636, GF_LOG_ERROR, "Unable to get store handle"); } while ( 0) |
1636 | "Unable to get store handle")do { do { if (0) printf ("Unable to get store handle"); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 1636, GF_LOG_ERROR, "Unable to get store handle"); } while ( 0); |
1637 | goto out; |
1638 | } |
1639 | |
1640 | conf->handle = handle; |
1641 | } else |
1642 | handle = conf->handle; |
1643 | |
1644 | /* These options need to be available for all users */ |
1645 | ret = chmod (handle->path, 0644); |
1646 | if (ret) { |
1647 | gf_log (this->name, GF_LOG_ERROR, "chmod error for %s: %s",do { do { if (0) printf ("chmod error for %s: %s", "glusterd.info" , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 1648, GF_LOG_ERROR , "chmod error for %s: %s", "glusterd.info", strerror ((*__errno_location ()))); } while (0) |
1648 | GLUSTERD_INFO_FILE, strerror (errno))do { do { if (0) printf ("chmod error for %s: %s", "glusterd.info" , strerror ((*__errno_location ()))); } while (0); _gf_log (this ->name, "glusterd-store.c", __FUNCTION__, 1648, GF_LOG_ERROR , "chmod error for %s: %s", "glusterd.info", strerror ((*__errno_location ()))); } while (0); |
1649 | goto out; |
1650 | } |
1651 | |
1652 | handle->fd = glusterd_store_mkstemp (handle); |
1653 | if (handle->fd <= 0) { |
1654 | ret = -1; |
1655 | goto out; |
1656 | } |
1657 | |
1658 | ret = glusterd_store_save_value (handle->fd, GLUSTERD_STORE_UUID_KEY"UUID", |
1659 | uuid_str); |
1660 | if (ret) { |
1661 | gf_log (this->name, GF_LOG_CRITICAL,do { do { if (0) printf ("Storing uuid failed ret = %d", ret) ; } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 1662, GF_LOG_CRITICAL, "Storing uuid failed ret = %d", ret) ; } while (0) |
1662 | "Storing uuid failed ret = %d", ret)do { do { if (0) printf ("Storing uuid failed ret = %d", ret) ; } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 1662, GF_LOG_CRITICAL, "Storing uuid failed ret = %d", ret) ; } while (0); |
1663 | goto out; |
1664 | } |
1665 | |
1666 | snprintf (op_version_str, 15, "%d", conf->op_version); |
1667 | ret = glusterd_store_save_value (handle->fd, GD_OP_VERSION_KEY"operating-version", |
1668 | op_version_str); |
1669 | if (ret) { |
1670 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Storing op-version failed ret = %d" , ret); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1671, GF_LOG_ERROR, "Storing op-version failed ret = %d" , ret); } while (0) |
1671 | "Storing op-version failed ret = %d", ret)do { do { if (0) printf ("Storing op-version failed ret = %d" , ret); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1671, GF_LOG_ERROR, "Storing op-version failed ret = %d" , ret); } while (0); |
1672 | goto out; |
1673 | } |
1674 | |
1675 | ret = glusterd_store_rename_tmppath (handle); |
1676 | out: |
1677 | if (ret && (handle->fd > 0)) |
1678 | glusterd_store_unlink_tmppath (handle); |
1679 | |
1680 | if (handle->fd > 0) { |
1681 | close (handle->fd); |
1682 | handle->fd = 0; |
1683 | } |
1684 | |
1685 | if (uuid_str) |
1686 | GF_FREE (uuid_str)__gf_free (uuid_str); |
1687 | |
1688 | if (ret) |
1689 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to store glusterd global-info" ); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 1690, GF_LOG_ERROR, "Failed to store glusterd global-info") ; } while (0) |
1690 | "Failed to store glusterd global-info")do { do { if (0) printf ("Failed to store glusterd global-info" ); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 1690, GF_LOG_ERROR, "Failed to store glusterd global-info") ; } while (0); |
1691 | |
1692 | return ret; |
1693 | } |
1694 | |
1695 | int |
1696 | glusterd_retrieve_op_version (xlator_t *this, int *op_version) |
1697 | { |
1698 | char *op_version_str = NULL((void*)0); |
1699 | glusterd_conf_t *priv = NULL((void*)0); |
1700 | int ret = -1; |
1701 | int tmp_version = 0; |
1702 | char *tmp = NULL((void*)0); |
1703 | char path[PATH_MAX4096] = {0,}; |
1704 | glusterd_store_handle_t *handle = NULL((void*)0); |
1705 | |
1706 | priv = this->private; |
1707 | |
1708 | if (!priv->handle) { |
1709 | snprintf (path, PATH_MAX4096, "%s/%s", priv->workdir, |
1710 | GLUSTERD_INFO_FILE"glusterd.info"); |
1711 | ret = glusterd_store_handle_retrieve (path, &handle); |
1712 | |
1713 | if (ret) { |
1714 | gf_log ("", GF_LOG_ERROR, "Unable to get store "do { do { if (0) printf ("Unable to get store " "handle!"); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1715 , GF_LOG_ERROR, "Unable to get store " "handle!"); } while (0 ) |
1715 | "handle!")do { do { if (0) printf ("Unable to get store " "handle!"); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1715 , GF_LOG_ERROR, "Unable to get store " "handle!"); } while (0 ); |
1716 | goto out; |
1717 | } |
1718 | |
1719 | priv->handle = handle; |
1720 | } |
1721 | |
1722 | ret = glusterd_store_retrieve_value (priv->handle, |
1723 | GD_OP_VERSION_KEY"operating-version", |
1724 | &op_version_str); |
1725 | if (ret) { |
1726 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("No previous op_version present"); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 1727, GF_LOG_DEBUG, "No previous op_version present"); } while (0) |
1727 | "No previous op_version present")do { do { if (0) printf ("No previous op_version present"); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 1727, GF_LOG_DEBUG, "No previous op_version present"); } while (0); |
1728 | goto out; |
1729 | } |
1730 | |
1731 | tmp_version = strtol (op_version_str, &tmp, 10); |
1732 | if ((tmp_version <= 0) || (tmp && strlen (tmp) > 1)) { |
1733 | gf_log (this->name, GF_LOG_WARNING, "invalid version number")do { do { if (0) printf ("invalid version number"); } while ( 0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__, 1733, GF_LOG_WARNING, "invalid version number"); } while (0); |
1734 | goto out; |
1735 | } |
1736 | |
1737 | *op_version = tmp_version; |
1738 | |
1739 | ret = 0; |
1740 | out: |
1741 | if (op_version_str) |
1742 | GF_FREE (op_version_str)__gf_free (op_version_str); |
1743 | |
1744 | return ret; |
1745 | } |
1746 | |
1747 | static int |
1748 | glusterd_restore_op_version (xlator_t *this) |
1749 | { |
1750 | glusterd_conf_t *conf = NULL((void*)0); |
1751 | int ret = 0; |
1752 | int op_version = 0; |
1753 | |
1754 | conf = this->private; |
1755 | |
1756 | ret = glusterd_retrieve_op_version (this, &op_version); |
1757 | if (!ret) { |
1758 | if ((op_version < GD_OP_VERSION_MIN1) || |
1759 | (op_version > GD_OP_VERSION_MAX2)) { |
1760 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("wrong op-version (%d) retreived", op_version ); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 1761, GF_LOG_ERROR, "wrong op-version (%d) retreived", op_version ); } while (0) |
1761 | "wrong op-version (%d) retreived", op_version)do { do { if (0) printf ("wrong op-version (%d) retreived", op_version ); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 1761, GF_LOG_ERROR, "wrong op-version (%d) retreived", op_version ); } while (0); |
1762 | ret = -1; |
1763 | goto out; |
1764 | } |
1765 | conf->op_version = op_version; |
1766 | gf_log ("glusterd", GF_LOG_INFO,do { do { if (0) printf ("retrieved op-version: %d", conf-> op_version); } while (0); _gf_log ("glusterd", "glusterd-store.c" , __FUNCTION__, 1767, GF_LOG_INFO, "retrieved op-version: %d" , conf->op_version); } while (0) |
1767 | "retrieved op-version: %d", conf->op_version)do { do { if (0) printf ("retrieved op-version: %d", conf-> op_version); } while (0); _gf_log ("glusterd", "glusterd-store.c" , __FUNCTION__, 1767, GF_LOG_INFO, "retrieved op-version: %d" , conf->op_version); } while (0); |
1768 | goto out; |
1769 | } |
1770 | |
1771 | gf_log (this->name, GF_LOG_INFO, "op-version not found in store, "do { do { if (0) printf ("op-version not found in store, " "setting it to minimum op-version : %d" , 1); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1772, GF_LOG_INFO, "op-version not found in store, " "setting it to minimum op-version : %d", 1); } while (0) |
1772 | "setting it to minimum op-version : %d", GD_OP_VERSION_MIN)do { do { if (0) printf ("op-version not found in store, " "setting it to minimum op-version : %d" , 1); } while (0); _gf_log (this->name, "glusterd-store.c" , __FUNCTION__, 1772, GF_LOG_INFO, "op-version not found in store, " "setting it to minimum op-version : %d", 1); } while (0); |
1773 | |
1774 | /* If op-version is missing, set it to GD_OP_VERSION_MIN */ |
1775 | conf->op_version = GD_OP_VERSION_MIN1; |
1776 | ret = 0; |
1777 | out: |
1778 | return ret; |
1779 | } |
1780 | |
1781 | int32_t |
1782 | glusterd_retrieve_uuid () |
1783 | { |
1784 | char *uuid_str = NULL((void*)0); |
1785 | int32_t ret = -1; |
1786 | glusterd_store_handle_t *handle = NULL((void*)0); |
1787 | glusterd_conf_t *priv = NULL((void*)0); |
1788 | char path[PATH_MAX4096] = {0,}; |
1789 | |
1790 | priv = THIS(*__glusterfs_this_location())->private; |
1791 | |
1792 | if (!priv->handle) { |
1793 | snprintf (path, PATH_MAX4096, "%s/%s", priv->workdir, |
1794 | GLUSTERD_INFO_FILE"glusterd.info"); |
1795 | ret = glusterd_store_handle_retrieve (path, &handle); |
1796 | |
1797 | if (ret) { |
1798 | gf_log ("", GF_LOG_ERROR, "Unable to get store "do { do { if (0) printf ("Unable to get store " "handle!"); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1799 , GF_LOG_ERROR, "Unable to get store " "handle!"); } while (0 ) |
1799 | "handle!")do { do { if (0) printf ("Unable to get store " "handle!"); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1799 , GF_LOG_ERROR, "Unable to get store " "handle!"); } while (0 ); |
1800 | goto out; |
1801 | } |
1802 | |
1803 | priv->handle = handle; |
1804 | } |
1805 | |
1806 | ret = glusterd_store_retrieve_value (priv->handle, |
1807 | GLUSTERD_STORE_UUID_KEY"UUID", |
1808 | &uuid_str); |
1809 | |
1810 | if (ret) { |
1811 | gf_log ("", GF_LOG_INFO, "No previous uuid is present")do { do { if (0) printf ("No previous uuid is present"); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1811, GF_LOG_INFO , "No previous uuid is present"); } while (0); |
1812 | goto out; |
1813 | } |
1814 | |
1815 | uuid_parse (uuid_str, priv->uuid); |
1816 | |
1817 | out: |
1818 | GF_FREE (uuid_str)__gf_free (uuid_str); |
1819 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1819, GF_LOG_DEBUG, "Returning %d" , ret); } while (0); |
1820 | return ret; |
1821 | } |
1822 | |
1823 | int32_t |
1824 | glusterd_store_iter_new (glusterd_store_handle_t *shandle, |
1825 | glusterd_store_iter_t **iter) |
1826 | { |
1827 | int32_t ret = -1; |
1828 | glusterd_store_iter_t *tmp_iter = NULL((void*)0); |
1829 | int fd = -1; |
1830 | |
1831 | GF_ASSERT (shandle)do { if (!(shandle)) { do { do { if (0) printf ("Assertion failed: " "shandle"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1831, GF_LOG_ERROR, "Assertion failed: " "shandle" ); } while (0); } } while (0); |
1832 | GF_ASSERT (iter)do { if (!(iter)) { do { do { if (0) printf ("Assertion failed: " "iter"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1832, GF_LOG_ERROR, "Assertion failed: " "iter" ); } while (0); } } while (0); |
1833 | |
1834 | tmp_iter = GF_CALLOC (1, sizeof (*tmp_iter),__gf_calloc (1, sizeof (*tmp_iter), gf_gld_mt_store_iter_t) |
1835 | gf_gld_mt_store_iter_t)__gf_calloc (1, sizeof (*tmp_iter), gf_gld_mt_store_iter_t); |
1836 | |
1837 | if (!tmp_iter) { |
1838 | gf_log ("", GF_LOG_ERROR, "Out of Memory")do { do { if (0) printf ("Out of Memory"); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1838, GF_LOG_ERROR, "Out of Memory" ); } while (0); |
1839 | goto out; |
1840 | } |
1841 | |
1842 | fd = open (shandle->path, O_RDWR02); |
1843 | |
1844 | if (fd < 0) { |
1845 | gf_log ("", GF_LOG_ERROR, "Unable to open %s, errno: %d",do { do { if (0) printf ("Unable to open %s, errno: %d", shandle ->path, (*__errno_location ())); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1846, GF_LOG_ERROR, "Unable to open %s, errno: %d" , shandle->path, (*__errno_location ())); } while (0) |
1846 | shandle->path, errno)do { do { if (0) printf ("Unable to open %s, errno: %d", shandle ->path, (*__errno_location ())); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1846, GF_LOG_ERROR, "Unable to open %s, errno: %d" , shandle->path, (*__errno_location ())); } while (0); |
1847 | goto out; |
1848 | } |
1849 | |
1850 | tmp_iter->fd = fd; |
1851 | |
1852 | tmp_iter->file = fdopen (tmp_iter->fd, "r"); |
1853 | |
1854 | if (!tmp_iter->file) { |
1855 | gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %d",do { do { if (0) printf ("Unable to open file %s errno: %d", shandle ->path, (*__errno_location ())); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1856, GF_LOG_ERROR, "Unable to open file %s errno: %d" , shandle->path, (*__errno_location ())); } while (0) |
1856 | shandle->path, errno)do { do { if (0) printf ("Unable to open file %s errno: %d", shandle ->path, (*__errno_location ())); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1856, GF_LOG_ERROR, "Unable to open file %s errno: %d" , shandle->path, (*__errno_location ())); } while (0); |
1857 | goto out; |
1858 | } |
1859 | |
1860 | strncpy (tmp_iter->filepath, shandle->path, sizeof (tmp_iter->filepath)); |
1861 | tmp_iter->filepath[sizeof (tmp_iter->filepath) - 1] = 0; |
1862 | *iter = tmp_iter; |
1863 | ret = 0; |
1864 | |
1865 | out: |
1866 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1866, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
1867 | return ret; |
1868 | } |
1869 | |
1870 | int32_t |
1871 | glusterd_store_validate_key_value (char *storepath, char *key, char*val, |
1872 | glusterd_store_op_errno_t *op_errno) |
1873 | { |
1874 | int ret = 0; |
1875 | |
1876 | GF_ASSERT (op_errno)do { if (!(op_errno)) { do { do { if (0) printf ("Assertion failed: " "op_errno"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1876, GF_LOG_ERROR, "Assertion failed: " "op_errno" ); } while (0); } } while (0); |
1877 | GF_ASSERT (storepath)do { if (!(storepath)) { do { do { if (0) printf ("Assertion failed: " "storepath"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1877, GF_LOG_ERROR, "Assertion failed: " "storepath" ); } while (0); } } while (0); |
1878 | |
1879 | if ((key == NULL((void*)0)) && (val == NULL((void*)0))) { |
1880 | ret = -1; |
1881 | gf_log ("glusterd", GF_LOG_ERROR, "Glusterd store may be "do { do { if (0) printf ("Glusterd store may be " "corrupted, Invalid key and value (null) in %s" , storepath); } while (0); _gf_log ("glusterd", "glusterd-store.c" , __FUNCTION__, 1883, GF_LOG_ERROR, "Glusterd store may be " "corrupted, Invalid key and value (null) in %s" , storepath); } while (0) |
1882 | "corrupted, Invalid key and value (null) in %s",do { do { if (0) printf ("Glusterd store may be " "corrupted, Invalid key and value (null) in %s" , storepath); } while (0); _gf_log ("glusterd", "glusterd-store.c" , __FUNCTION__, 1883, GF_LOG_ERROR, "Glusterd store may be " "corrupted, Invalid key and value (null) in %s" , storepath); } while (0) |
1883 | storepath)do { do { if (0) printf ("Glusterd store may be " "corrupted, Invalid key and value (null) in %s" , storepath); } while (0); _gf_log ("glusterd", "glusterd-store.c" , __FUNCTION__, 1883, GF_LOG_ERROR, "Glusterd store may be " "corrupted, Invalid key and value (null) in %s" , storepath); } while (0); |
1884 | *op_errno = GD_STORE_KEY_VALUE_NULL; |
1885 | } else if (key == NULL((void*)0)) { |
1886 | ret = -1; |
1887 | gf_log ("glusterd", GF_LOG_ERROR, "Glusterd store may be "do { do { if (0) printf ("Glusterd store may be " "corrupted, Invalid key (null) in %s" , storepath); } while (0); _gf_log ("glusterd", "glusterd-store.c" , __FUNCTION__, 1888, GF_LOG_ERROR, "Glusterd store may be " "corrupted, Invalid key (null) in %s" , storepath); } while (0) |
1888 | "corrupted, Invalid key (null) in %s", storepath)do { do { if (0) printf ("Glusterd store may be " "corrupted, Invalid key (null) in %s" , storepath); } while (0); _gf_log ("glusterd", "glusterd-store.c" , __FUNCTION__, 1888, GF_LOG_ERROR, "Glusterd store may be " "corrupted, Invalid key (null) in %s" , storepath); } while (0); |
1889 | *op_errno = GD_STORE_KEY_NULL; |
1890 | } else if (val == NULL((void*)0)) { |
1891 | ret = -1; |
1892 | gf_log ("glusterd", GF_LOG_ERROR, "Glusterd store may be "do { do { if (0) printf ("Glusterd store may be " "corrupted, Invalid value (null) for key %s in %s" , key, storepath); } while (0); _gf_log ("glusterd", "glusterd-store.c" , __FUNCTION__, 1894, GF_LOG_ERROR, "Glusterd store may be " "corrupted, Invalid value (null) for key %s in %s" , key, storepath); } while (0) |
1893 | "corrupted, Invalid value (null) for key %s in %s",do { do { if (0) printf ("Glusterd store may be " "corrupted, Invalid value (null) for key %s in %s" , key, storepath); } while (0); _gf_log ("glusterd", "glusterd-store.c" , __FUNCTION__, 1894, GF_LOG_ERROR, "Glusterd store may be " "corrupted, Invalid value (null) for key %s in %s" , key, storepath); } while (0) |
1894 | key, storepath)do { do { if (0) printf ("Glusterd store may be " "corrupted, Invalid value (null) for key %s in %s" , key, storepath); } while (0); _gf_log ("glusterd", "glusterd-store.c" , __FUNCTION__, 1894, GF_LOG_ERROR, "Glusterd store may be " "corrupted, Invalid value (null) for key %s in %s" , key, storepath); } while (0); |
1895 | *op_errno = GD_STORE_VALUE_NULL; |
1896 | } else { |
1897 | ret = 0; |
1898 | *op_errno = GD_STORE_SUCCESS; |
1899 | } |
1900 | |
1901 | return ret; |
1902 | } |
1903 | |
1904 | int32_t |
1905 | glusterd_store_iter_get_next (glusterd_store_iter_t *iter, |
1906 | char **key, char **value, |
1907 | glusterd_store_op_errno_t *op_errno) |
1908 | { |
1909 | int32_t ret = -1; |
1910 | char *scan_str = NULL((void*)0); |
1911 | char *free_str = NULL((void*)0); |
1912 | char *iter_key = NULL((void*)0); |
1913 | char *iter_val = NULL((void*)0); |
1914 | struct stat st = {0,}; |
1915 | glusterd_store_op_errno_t store_errno = GD_STORE_SUCCESS; |
1916 | |
1917 | GF_ASSERT (iter)do { if (!(iter)) { do { do { if (0) printf ("Assertion failed: " "iter"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1917, GF_LOG_ERROR, "Assertion failed: " "iter" ); } while (0); } } while (0); |
1918 | GF_ASSERT (iter->file)do { if (!(iter->file)) { do { do { if (0) printf ("Assertion failed: " "iter->file"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1918, GF_LOG_ERROR, "Assertion failed: " "iter->file" ); } while (0); } } while (0); |
1919 | GF_ASSERT (key)do { if (!(key)) { do { do { if (0) printf ("Assertion failed: " "key"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1919, GF_LOG_ERROR, "Assertion failed: " "key" ); } while (0); } } while (0); |
1920 | GF_ASSERT (value)do { if (!(value)) { do { do { if (0) printf ("Assertion failed: " "value"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 1920, GF_LOG_ERROR, "Assertion failed: " "value" ); } while (0); } } while (0); |
1921 | |
1922 | ret = fstat (iter->fd, &st); |
1923 | if (ret < 0) { |
1924 | gf_log ("glusterd", GF_LOG_WARNING,do { do { if (0) printf ("stat on file failed"); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__, 1925, GF_LOG_WARNING, "stat on file failed"); } while (0) |
1925 | "stat on file failed")do { do { if (0) printf ("stat on file failed"); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__, 1925, GF_LOG_WARNING, "stat on file failed"); } while (0); |
1926 | ret = -1; |
1927 | store_errno = GD_STORE_STAT_FAILED; |
1928 | goto out; |
1929 | } |
1930 | |
1931 | scan_str = GF_CALLOC (1, st.st_size,__gf_calloc (1, st.st_size, gf_gld_mt_char) |
1932 | gf_gld_mt_char)__gf_calloc (1, st.st_size, gf_gld_mt_char); |
1933 | if (scan_str == NULL((void*)0)) { |
1934 | ret = -1; |
1935 | store_errno = GD_STORE_ENOMEM; |
1936 | goto out; |
1937 | } |
1938 | |
1939 | *key = NULL((void*)0); |
1940 | *value = NULL((void*)0); |
1941 | |
1942 | free_str = scan_str; |
1943 | |
1944 | ret = glusterd_store_read_and_tokenize (iter->file, scan_str, |
1945 | &iter_key, &iter_val, |
1946 | &store_errno); |
1947 | if (ret < 0) { |
1948 | goto out; |
1949 | } |
1950 | |
1951 | |
1952 | ret = glusterd_store_validate_key_value (iter->filepath, iter_key, |
1953 | iter_val, &store_errno); |
1954 | if (ret) |
1955 | goto out; |
1956 | |
1957 | *value = gf_strdup (iter_val); |
1958 | |
1959 | *key = gf_strdup (iter_key); |
1960 | if (!iter_key || !iter_val) { |
1961 | ret = -1; |
1962 | store_errno = GD_STORE_ENOMEM; |
1963 | goto out; |
1964 | } |
1965 | |
1966 | ret = 0; |
1967 | |
1968 | out: |
1969 | if (ret) { |
1970 | if (*key) { |
1971 | GF_FREE (*key)__gf_free (*key); |
1972 | *key = NULL((void*)0); |
1973 | } |
1974 | if (*value) { |
1975 | GF_FREE (*value)__gf_free (*value); |
1976 | *value = NULL((void*)0); |
1977 | } |
1978 | } |
1979 | GF_FREE (free_str)__gf_free (free_str); |
1980 | if (op_errno) |
1981 | *op_errno = store_errno; |
1982 | |
1983 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 1983, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
1984 | return ret; |
1985 | } |
1986 | |
1987 | int32_t |
1988 | glusterd_store_iter_get_matching (glusterd_store_iter_t *iter, |
1989 | char *key, char **value) |
1990 | { |
1991 | int32_t ret = -1; |
1992 | char *tmp_key = NULL((void*)0); |
1993 | char *tmp_value = NULL((void*)0); |
1994 | |
1995 | ret = glusterd_store_iter_get_next (iter, &tmp_key, &tmp_value, |
1996 | NULL((void*)0)); |
1997 | while (!ret) { |
1998 | if (!strncmp (key, tmp_key, strlen (key))){ |
1999 | *value = tmp_value; |
2000 | GF_FREE (tmp_key)__gf_free (tmp_key); |
2001 | goto out; |
2002 | } |
2003 | GF_FREE (tmp_key)__gf_free (tmp_key); |
2004 | GF_FREE (tmp_value)__gf_free (tmp_value); |
2005 | ret = glusterd_store_iter_get_next (iter, &tmp_key, |
2006 | &tmp_value, NULL((void*)0)); |
2007 | } |
2008 | out: |
2009 | return ret; |
2010 | } |
2011 | |
2012 | int32_t |
2013 | glusterd_store_iter_destroy (glusterd_store_iter_t *iter) |
2014 | { |
2015 | int32_t ret = -1; |
2016 | |
2017 | if (!iter) |
2018 | return 0; |
2019 | |
2020 | if (iter->file) |
2021 | ret = fclose (iter->file); |
2022 | else |
2023 | ret = 0; |
2024 | |
2025 | if (ret) { |
2026 | gf_log ("", GF_LOG_ERROR, "Unable to close fd: %d, ret: %d, "do { do { if (0) printf ("Unable to close fd: %d, ret: %d, " "errno: %d" ,iter->fd, ret, (*__errno_location ())); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2027, GF_LOG_ERROR, "Unable to close fd: %d, ret: %d, " "errno: %d" ,iter->fd, ret, (*__errno_location ())); } while (0) |
2027 | "errno: %d" ,iter->fd, ret, errno)do { do { if (0) printf ("Unable to close fd: %d, ret: %d, " "errno: %d" ,iter->fd, ret, (*__errno_location ())); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2027, GF_LOG_ERROR, "Unable to close fd: %d, ret: %d, " "errno: %d" ,iter->fd, ret, (*__errno_location ())); } while (0); |
2028 | } |
2029 | |
2030 | GF_FREE (iter)__gf_free (iter); |
2031 | |
2032 | return ret; |
2033 | } |
2034 | |
2035 | char* |
2036 | glusterd_store_strerror (glusterd_store_op_errno_t op_errno) |
2037 | { |
2038 | switch (op_errno) { |
2039 | case GD_STORE_SUCCESS: |
2040 | return "Success"; |
2041 | case GD_STORE_KEY_NULL: |
2042 | return "Invalid Key"; |
2043 | case GD_STORE_VALUE_NULL: |
2044 | return "Invalid Value"; |
2045 | case GD_STORE_KEY_VALUE_NULL: |
2046 | return "Invalid Key and Value"; |
2047 | case GD_STORE_EOF: |
2048 | return "No data"; |
2049 | case GD_STORE_ENOMEM: |
2050 | return "No memory"; |
2051 | default: |
2052 | return "Invalid errno"; |
2053 | } |
2054 | return "Invalid errno"; |
2055 | } |
2056 | |
2057 | int32_t |
2058 | glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo) |
2059 | { |
2060 | |
2061 | int32_t ret = 0; |
2062 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); |
2063 | glusterd_store_iter_t *iter = NULL((void*)0); |
2064 | char *key = NULL((void*)0); |
2065 | char *value = NULL((void*)0); |
2066 | char brickdir[PATH_MAX4096] = {0,}; |
2067 | char path[PATH_MAX4096] = {0,}; |
2068 | glusterd_conf_t *priv = NULL((void*)0); |
2069 | int32_t brick_count = 0; |
2070 | char tmpkey[4096] = {0,}; |
2071 | glusterd_store_iter_t *tmpiter = NULL((void*)0); |
2072 | char *tmpvalue = NULL((void*)0); |
2073 | struct pmap_registry *pmap = NULL((void*)0); |
2074 | glusterd_store_op_errno_t op_errno = GD_STORE_SUCCESS; |
2075 | |
2076 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2076, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); |
2077 | GF_ASSERT (volinfo->volname)do { if (!(volinfo->volname)) { do { do { if (0) printf ("Assertion failed: " "volinfo->volname"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2077, GF_LOG_ERROR, "Assertion failed: " "volinfo->volname" ); } while (0); } } while (0); |
2078 | |
2079 | priv = THIS(*__glusterfs_this_location())->private; |
2080 | |
2081 | GLUSTERD_GET_BRICK_DIR (brickdir, volinfo, priv)snprintf (brickdir, 4096, "%s/%s/%s/%s", priv->workdir, "vols" , volinfo->volname, "bricks"); |
2082 | |
2083 | ret = glusterd_store_iter_new (volinfo->shandle, &tmpiter); |
2084 | |
2085 | if (ret) |
2086 | goto out; |
2087 | |
2088 | while (brick_count < volinfo->brick_count) { |
2089 | ret = glusterd_brickinfo_new (&brickinfo); |
2090 | |
2091 | if (ret) |
2092 | goto out; |
2093 | snprintf (tmpkey, sizeof (tmpkey), "%s-%d", |
2094 | GLUSTERD_STORE_KEY_VOL_BRICK"brick",brick_count); |
2095 | ret = glusterd_store_iter_get_matching (tmpiter, tmpkey, |
2096 | &tmpvalue); |
2097 | snprintf (path, sizeof (path), "%s/%s", brickdir, tmpvalue); |
2098 | |
2099 | GF_FREE (tmpvalue)__gf_free (tmpvalue); |
2100 | |
2101 | tmpvalue = NULL((void*)0); |
2102 | |
2103 | ret = glusterd_store_handle_retrieve (path, &brickinfo->shandle); |
2104 | |
2105 | if (ret) |
2106 | goto out; |
2107 | |
2108 | ret = glusterd_store_iter_new (brickinfo->shandle, &iter); |
2109 | |
2110 | if (ret) |
2111 | goto out; |
2112 | |
2113 | ret = glusterd_store_iter_get_next (iter, &key, &value, |
2114 | &op_errno); |
2115 | if (ret) { |
2116 | gf_log ("glusterd", GF_LOG_ERROR, "Unable to iterate "do { do { if (0) printf ("Unable to iterate " "the store for brick: %s, reason: %s" , path, glusterd_store_strerror (op_errno)); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__, 2118, GF_LOG_ERROR , "Unable to iterate " "the store for brick: %s, reason: %s", path, glusterd_store_strerror (op_errno)); } while (0) |
2117 | "the store for brick: %s, reason: %s", path,do { do { if (0) printf ("Unable to iterate " "the store for brick: %s, reason: %s" , path, glusterd_store_strerror (op_errno)); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__, 2118, GF_LOG_ERROR , "Unable to iterate " "the store for brick: %s, reason: %s", path, glusterd_store_strerror (op_errno)); } while (0) |
2118 | glusterd_store_strerror (op_errno))do { do { if (0) printf ("Unable to iterate " "the store for brick: %s, reason: %s" , path, glusterd_store_strerror (op_errno)); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__, 2118, GF_LOG_ERROR , "Unable to iterate " "the store for brick: %s, reason: %s", path, glusterd_store_strerror (op_errno)); } while (0); |
2119 | goto out; |
2120 | } |
2121 | while (!ret) { |
2122 | if (!strncmp (key, GLUSTERD_STORE_KEY_BRICK_HOSTNAME"hostname", |
2123 | strlen (GLUSTERD_STORE_KEY_BRICK_HOSTNAME"hostname"))) { |
2124 | strncpy (brickinfo->hostname, value, 1024); |
2125 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_BRICK_PATH"path", |
2126 | strlen (GLUSTERD_STORE_KEY_BRICK_PATH"path"))) { |
2127 | strncpy (brickinfo->path, value, |
2128 | sizeof (brickinfo->path)); |
2129 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_BRICK_PORT"listen-port", |
2130 | strlen (GLUSTERD_STORE_KEY_BRICK_PORT"listen-port"))) { |
2131 | gf_string2int (value, &brickinfo->port); |
2132 | |
2133 | if (brickinfo->port < GF_IANA_PRIV_PORTS_START49152){ |
2134 | /* This is required to adhere to the |
2135 | IANA standards */ |
2136 | brickinfo->port = 0; |
2137 | } else { |
2138 | /* This is required to have proper ports |
2139 | assigned to bricks after restart */ |
2140 | pmap = pmap_registry_get (THIS(*__glusterfs_this_location())); |
2141 | if (pmap->last_alloc <= brickinfo->port) |
2142 | pmap->last_alloc = |
2143 | brickinfo->port + 1; |
2144 | } |
2145 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_BRICK_RDMA_PORT"rdma.listen-port", |
2146 | strlen (GLUSTERD_STORE_KEY_BRICK_RDMA_PORT"rdma.listen-port"))) { |
2147 | gf_string2int (value, &brickinfo->rdma_port); |
2148 | |
2149 | if (brickinfo->rdma_port < |
2150 | GF_IANA_PRIV_PORTS_START49152){ |
2151 | /* This is required to adhere to the |
2152 | IANA standards */ |
2153 | brickinfo->rdma_port = 0; |
2154 | } else { |
2155 | /* This is required to have proper ports |
2156 | assigned to bricks after restart */ |
2157 | pmap = pmap_registry_get (THIS(*__glusterfs_this_location())); |
2158 | if (pmap->last_alloc <= |
2159 | brickinfo->rdma_port) |
2160 | pmap->last_alloc = |
2161 | brickinfo->rdma_port +1; |
2162 | } |
2163 | |
2164 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED"decommissioned", |
2165 | strlen (GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED"decommissioned"))) { |
2166 | gf_string2int (value, &brickinfo->decommissioned); |
2167 | } else { |
2168 | gf_log ("", GF_LOG_ERROR, "Unknown key: %s",do { do { if (0) printf ("Unknown key: %s", key); } while (0) ; _gf_log ("", "glusterd-store.c", __FUNCTION__, 2169, GF_LOG_ERROR , "Unknown key: %s", key); } while (0) |
2169 | key)do { do { if (0) printf ("Unknown key: %s", key); } while (0) ; _gf_log ("", "glusterd-store.c", __FUNCTION__, 2169, GF_LOG_ERROR , "Unknown key: %s", key); } while (0); |
2170 | } |
2171 | |
2172 | GF_FREE (key)__gf_free (key); |
2173 | GF_FREE (value)__gf_free (value); |
2174 | key = NULL((void*)0); |
2175 | value = NULL((void*)0); |
2176 | |
2177 | ret = glusterd_store_iter_get_next (iter, &key, &value, |
2178 | &op_errno); |
2179 | } |
2180 | |
2181 | if (op_errno != GD_STORE_EOF) |
2182 | goto out; |
2183 | ret = glusterd_store_iter_destroy (iter); |
2184 | |
2185 | if (ret) |
2186 | goto out; |
2187 | |
2188 | list_add_tail (&brickinfo->brick_list, &volinfo->bricks); |
2189 | brick_count++; |
2190 | } |
2191 | |
2192 | ret = glusterd_store_iter_destroy (tmpiter); |
2193 | if (ret) |
2194 | goto out; |
2195 | out: |
2196 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2196, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
2197 | |
2198 | return ret; |
2199 | } |
2200 | |
2201 | |
2202 | int32_t |
2203 | glusterd_store_retrieve_rbstate (char *volname) |
2204 | { |
2205 | int32_t ret = -1; |
2206 | glusterd_volinfo_t *volinfo = NULL((void*)0); |
2207 | glusterd_store_iter_t *iter = NULL((void*)0); |
2208 | char *key = NULL((void*)0); |
2209 | char *value = NULL((void*)0); |
2210 | char volpath[PATH_MAX4096] = {0,}; |
2211 | glusterd_conf_t *priv = NULL((void*)0); |
2212 | char path[PATH_MAX4096] = {0,}; |
2213 | glusterd_store_op_errno_t op_errno = GD_STORE_SUCCESS; |
2214 | |
2215 | priv = THIS(*__glusterfs_this_location())->private; |
2216 | |
2217 | ret = glusterd_volinfo_find (volname, &volinfo); |
2218 | if (ret) { |
2219 | gf_log (THIS->name, GF_LOG_ERROR, "Couldn't get"do { do { if (0) printf ("Couldn't get" "volinfo for %s.", volname ); } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-store.c", __FUNCTION__, 2220, GF_LOG_ERROR, "Couldn't get" "volinfo for %s.", volname); } while (0) |
2220 | "volinfo for %s.", volname)do { do { if (0) printf ("Couldn't get" "volinfo for %s.", volname ); } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-store.c", __FUNCTION__, 2220, GF_LOG_ERROR, "Couldn't get" "volinfo for %s.", volname); } while (0); |
2221 | goto out; |
2222 | } |
2223 | |
2224 | GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, priv)snprintf (volpath, 4096, "%s/vols/%s", priv->workdir, volinfo ->volname);; |
2225 | snprintf (path, sizeof (path), "%s/%s", volpath, |
2226 | GLUSTERD_VOLUME_RBSTATE_FILE"rbstate"); |
2227 | |
2228 | ret = glusterd_store_handle_retrieve (path, &volinfo->rb_shandle); |
2229 | |
2230 | if (ret) |
2231 | goto out; |
2232 | |
2233 | ret = glusterd_store_iter_new (volinfo->rb_shandle, &iter); |
2234 | |
2235 | if (ret) |
2236 | goto out; |
2237 | |
2238 | ret = glusterd_store_iter_get_next (iter, &key, &value, &op_errno); |
2239 | if (ret) |
2240 | goto out; |
2241 | |
2242 | while (!ret) { |
2243 | if (!strncmp (key, GLUSTERD_STORE_KEY_RB_STATUS"rb_status", |
2244 | strlen (GLUSTERD_STORE_KEY_RB_STATUS"rb_status"))) { |
2245 | volinfo->rep_brick.rb_status = atoi (value); |
2246 | } |
2247 | |
2248 | if (volinfo->rep_brick.rb_status > GF_RB_STATUS_NONE) { |
2249 | if (!strncmp (key, GLUSTERD_STORE_KEY_RB_SRC_BRICK"rb_src", |
2250 | strlen (GLUSTERD_STORE_KEY_RB_SRC_BRICK"rb_src"))) { |
2251 | ret = glusterd_brickinfo_new_from_brick (value, |
2252 | &volinfo->rep_brick.src_brick); |
2253 | if (ret) |
2254 | goto out; |
2255 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_RB_DST_BRICK"rb_dst", |
2256 | strlen (GLUSTERD_STORE_KEY_RB_DST_BRICK"rb_dst"))) { |
2257 | ret = glusterd_brickinfo_new_from_brick (value, |
2258 | &volinfo->rep_brick.dst_brick); |
2259 | if (ret) |
2260 | goto out; |
2261 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_RB_DST_PORT"rb_port", |
2262 | strlen (GLUSTERD_STORE_KEY_RB_DST_PORT"rb_port"))) { |
2263 | switch (volinfo->transport_type) { |
2264 | case GF_TRANSPORT_RDMA: |
2265 | volinfo->rep_brick.dst_brick->rdma_port = |
2266 | atoi (value); |
2267 | break; |
2268 | |
2269 | case GF_TRANSPORT_TCP: |
2270 | case GF_TRANSPORT_BOTH_TCP_RDMA: |
2271 | volinfo->rep_brick.dst_brick->port = |
2272 | atoi (value); |
2273 | break; |
2274 | } |
2275 | } else if (!strncmp (key, GF_REPLACE_BRICK_TID_KEY"replace-brick-id", |
2276 | strlen (GF_REPLACE_BRICK_TID_KEY"replace-brick-id"))) { |
2277 | uuid_parse (value, |
2278 | volinfo->rep_brick.rb_id); |
2279 | } |
2280 | } |
2281 | |
2282 | GF_FREE (key)__gf_free (key); |
2283 | GF_FREE (value)__gf_free (value); |
2284 | key = NULL((void*)0); |
2285 | value = NULL((void*)0); |
2286 | |
2287 | ret = glusterd_store_iter_get_next (iter, &key, &value, |
2288 | &op_errno); |
2289 | } |
2290 | |
2291 | if (op_errno != GD_STORE_EOF) |
2292 | goto out; |
2293 | |
2294 | ret = glusterd_store_iter_destroy (iter); |
2295 | |
2296 | if (ret) |
2297 | goto out; |
2298 | |
2299 | out: |
2300 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2300, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
2301 | |
2302 | return ret; |
2303 | } |
2304 | |
2305 | int32_t |
2306 | glusterd_store_retrieve_node_state (char *volname) |
2307 | { |
2308 | int32_t ret = -1; |
2309 | glusterd_volinfo_t *volinfo = NULL((void*)0); |
2310 | glusterd_store_iter_t *iter = NULL((void*)0); |
2311 | char *key = NULL((void*)0); |
2312 | char *value = NULL((void*)0); |
2313 | char volpath[PATH_MAX4096] = {0,}; |
2314 | glusterd_conf_t *priv = NULL((void*)0); |
2315 | char path[PATH_MAX4096] = {0,}; |
2316 | glusterd_store_op_errno_t op_errno = GD_STORE_SUCCESS; |
2317 | |
2318 | priv = THIS(*__glusterfs_this_location())->private; |
2319 | |
2320 | ret = glusterd_volinfo_find (volname, &volinfo); |
2321 | if (ret) { |
2322 | gf_log (THIS->name, GF_LOG_ERROR, "Couldn't get"do { do { if (0) printf ("Couldn't get" "volinfo for %s.", volname ); } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-store.c", __FUNCTION__, 2323, GF_LOG_ERROR, "Couldn't get" "volinfo for %s.", volname); } while (0) |
2323 | "volinfo for %s.", volname)do { do { if (0) printf ("Couldn't get" "volinfo for %s.", volname ); } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-store.c", __FUNCTION__, 2323, GF_LOG_ERROR, "Couldn't get" "volinfo for %s.", volname); } while (0); |
2324 | goto out; |
2325 | } |
2326 | |
2327 | GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, priv)snprintf (volpath, 4096, "%s/vols/%s", priv->workdir, volinfo ->volname);; |
2328 | snprintf (path, sizeof (path), "%s/%s", volpath, |
2329 | GLUSTERD_NODE_STATE_FILE"node_state.info"); |
2330 | |
2331 | ret = glusterd_store_handle_retrieve (path, |
2332 | &volinfo->node_state_shandle); |
2333 | if (ret) |
2334 | goto out; |
2335 | |
2336 | ret = glusterd_store_iter_new (volinfo->node_state_shandle, &iter); |
2337 | |
2338 | if (ret) |
2339 | goto out; |
2340 | |
2341 | ret = glusterd_store_iter_get_next (iter, &key, &value, &op_errno); |
2342 | if (ret) |
2343 | goto out; |
2344 | |
2345 | while (ret == 0) { |
2346 | if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_DEFRAG"rebalance_status", |
2347 | strlen (GLUSTERD_STORE_KEY_VOL_DEFRAG"rebalance_status"))) { |
2348 | volinfo->rebal.defrag_cmd = atoi (value); |
2349 | } |
2350 | |
2351 | if (volinfo->rebal.defrag_cmd) { |
2352 | if (!strncmp (key, GF_REBALANCE_TID_KEY"rebalance-id", |
2353 | strlen (GF_REBALANCE_TID_KEY"rebalance-id"))) |
2354 | uuid_parse (value, volinfo->rebal.rebalance_id); |
2355 | |
2356 | if (!strncmp (key, GLUSTERD_STORE_KEY_DEFRAG_OP"rebalance_op", |
2357 | strlen (GLUSTERD_STORE_KEY_DEFRAG_OP"rebalance_op"))) |
2358 | volinfo->rebal.op = atoi (value); |
2359 | } |
2360 | |
2361 | GF_FREE (key)__gf_free (key); |
2362 | GF_FREE (value)__gf_free (value); |
2363 | key = NULL((void*)0); |
2364 | value = NULL((void*)0); |
2365 | |
2366 | ret = glusterd_store_iter_get_next (iter, &key, &value, |
2367 | &op_errno); |
2368 | } |
2369 | |
2370 | if (op_errno != GD_STORE_EOF) |
2371 | goto out; |
2372 | |
2373 | ret = glusterd_store_iter_destroy (iter); |
2374 | |
2375 | if (ret) |
2376 | goto out; |
2377 | |
2378 | out: |
2379 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2379, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
2380 | |
2381 | return ret; |
2382 | } |
2383 | |
2384 | int32_t |
2385 | glusterd_store_retrieve_volume (char *volname) |
2386 | { |
2387 | int32_t ret = -1; |
2388 | glusterd_volinfo_t *volinfo = NULL((void*)0); |
2389 | glusterd_store_iter_t *iter = NULL((void*)0); |
2390 | char *key = NULL((void*)0); |
2391 | char *value = NULL((void*)0); |
2392 | char volpath[PATH_MAX4096] = {0,}; |
2393 | glusterd_conf_t *priv = NULL((void*)0); |
2394 | char path[PATH_MAX4096] = {0,}; |
2395 | int exists = 0; |
2396 | glusterd_store_op_errno_t op_errno = GD_STORE_SUCCESS; |
2397 | |
2398 | ret = glusterd_volinfo_new (&volinfo); |
2399 | |
2400 | if (ret) |
2401 | goto out; |
2402 | |
2403 | strncpy (volinfo->volname, volname, GLUSTERD_MAX_VOLUME_NAME1000); |
2404 | |
2405 | priv = THIS(*__glusterfs_this_location())->private; |
2406 | |
2407 | GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, priv)snprintf (volpath, 4096, "%s/vols/%s", priv->workdir, volinfo ->volname);; |
2408 | snprintf (path, sizeof (path), "%s/%s", volpath, |
2409 | GLUSTERD_VOLUME_INFO_FILE"info"); |
2410 | |
2411 | ret = glusterd_store_handle_retrieve (path, &volinfo->shandle); |
2412 | |
2413 | if (ret) |
2414 | goto out; |
2415 | |
2416 | ret = glusterd_store_iter_new (volinfo->shandle, &iter); |
2417 | |
2418 | if (ret) |
2419 | goto out; |
2420 | |
2421 | ret = glusterd_store_iter_get_next (iter, &key, &value, &op_errno); |
2422 | if (ret) |
2423 | goto out; |
2424 | |
2425 | while (!ret) { |
2426 | if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_TYPE"type", |
2427 | strlen (GLUSTERD_STORE_KEY_VOL_TYPE"type"))) { |
2428 | volinfo->type = atoi (value); |
2429 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_COUNT"count", |
2430 | strlen (GLUSTERD_STORE_KEY_VOL_COUNT"count"))) { |
2431 | volinfo->brick_count = atoi (value); |
2432 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_STATUS"status", |
2433 | strlen (GLUSTERD_STORE_KEY_VOL_STATUS"status"))) { |
2434 | volinfo->status = atoi (value); |
2435 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_VERSION"version", |
2436 | strlen (GLUSTERD_STORE_KEY_VOL_VERSION"version"))) { |
2437 | volinfo->version = atoi (value); |
2438 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_PORT"port", |
2439 | strlen (GLUSTERD_STORE_KEY_VOL_PORT"port"))) { |
2440 | volinfo->port = atoi (value); |
2441 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_SUB_COUNT"sub_count", |
2442 | strlen (GLUSTERD_STORE_KEY_VOL_SUB_COUNT"sub_count"))) { |
2443 | volinfo->sub_count = atoi (value); |
2444 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_STRIPE_CNT"stripe_count", |
2445 | strlen (GLUSTERD_STORE_KEY_VOL_STRIPE_CNT"stripe_count"))) { |
2446 | volinfo->stripe_count = atoi (value); |
2447 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_REPLICA_CNT"replica_count", |
2448 | strlen (GLUSTERD_STORE_KEY_VOL_REPLICA_CNT"replica_count"))) { |
2449 | volinfo->replica_count = atoi (value); |
2450 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_TRANSPORT"transport-type", |
2451 | strlen (GLUSTERD_STORE_KEY_VOL_TRANSPORT"transport-type"))) { |
2452 | volinfo->transport_type = atoi (value); |
2453 | volinfo->nfs_transport_type = volinfo->transport_type; |
2454 | if (volinfo->transport_type == GF_TRANSPORT_BOTH_TCP_RDMA) { |
2455 | volinfo->nfs_transport_type = GF_DEFAULT_NFS_TRANSPORTGF_TRANSPORT_RDMA; |
2456 | } |
2457 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_ID"volume-id", |
2458 | strlen (GLUSTERD_STORE_KEY_VOL_ID"volume-id"))) { |
2459 | ret = uuid_parse (value, volinfo->volume_id); |
2460 | if (ret) |
2461 | gf_log ("", GF_LOG_WARNING,do { do { if (0) printf ("failed to parse uuid"); } while (0) ; _gf_log ("", "glusterd-store.c", __FUNCTION__, 2462, GF_LOG_WARNING , "failed to parse uuid"); } while (0) |
2462 | "failed to parse uuid")do { do { if (0) printf ("failed to parse uuid"); } while (0) ; _gf_log ("", "glusterd-store.c", __FUNCTION__, 2462, GF_LOG_WARNING , "failed to parse uuid"); } while (0); |
2463 | |
2464 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_USERNAME"username", |
2465 | strlen (GLUSTERD_STORE_KEY_USERNAME"username"))) { |
2466 | |
2467 | glusterd_auth_set_username (volinfo, value); |
2468 | |
2469 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_PASSWORD"password", |
2470 | strlen (GLUSTERD_STORE_KEY_PASSWORD"password"))) { |
2471 | |
2472 | glusterd_auth_set_password (volinfo, value); |
2473 | |
2474 | } else if (strstr (key, "slave")) { |
2475 | ret = dict_set_dynstr (volinfo->gsync_slaves, key, |
2476 | gf_strdup (value)); |
2477 | if (ret) { |
2478 | gf_log ("",GF_LOG_ERROR, "Error in "do { do { if (0) printf ("Error in " "dict_set_str"); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2479, GF_LOG_ERROR , "Error in " "dict_set_str"); } while (0) |
2479 | "dict_set_str")do { do { if (0) printf ("Error in " "dict_set_str"); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2479, GF_LOG_ERROR , "Error in " "dict_set_str"); } while (0); |
2480 | goto out; |
2481 | } |
2482 | gf_log ("", GF_LOG_DEBUG, "Parsed as "GEOREP" "do { do { if (0) printf ("Parsed as ""geo-replication"" " " slave:key=%s,value:%s" , key, value); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__ , 2483, GF_LOG_DEBUG, "Parsed as ""geo-replication"" " " slave:key=%s,value:%s" , key, value); } while (0) |
2483 | " slave:key=%s,value:%s", key, value)do { do { if (0) printf ("Parsed as ""geo-replication"" " " slave:key=%s,value:%s" , key, value); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__ , 2483, GF_LOG_DEBUG, "Parsed as ""geo-replication"" " " slave:key=%s,value:%s" , key, value); } while (0); |
2484 | |
2485 | } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_BACKEND"backend", |
2486 | strlen (GLUSTERD_STORE_KEY_VOL_BACKEND"backend"))) { |
2487 | volinfo->backend = atoi (value); |
2488 | } else { |
2489 | |
2490 | if (is_key_glusterd_hooks_friendly (key)) { |
2491 | exists = 1; |
2492 | |
2493 | } else { |
2494 | exists = glusterd_check_option_exists (key, |
2495 | NULL((void*)0)); |
2496 | } |
2497 | |
2498 | switch (exists) { |
2499 | case -1: |
2500 | ret = -1; |
2501 | goto out; |
2502 | |
2503 | case 0: |
2504 | gf_log ("", GF_LOG_ERROR, "Unknown key: %s",do { do { if (0) printf ("Unknown key: %s", key); } while (0) ; _gf_log ("", "glusterd-store.c", __FUNCTION__, 2505, GF_LOG_ERROR , "Unknown key: %s", key); } while (0) |
2505 | key)do { do { if (0) printf ("Unknown key: %s", key); } while (0) ; _gf_log ("", "glusterd-store.c", __FUNCTION__, 2505, GF_LOG_ERROR , "Unknown key: %s", key); } while (0); |
2506 | break; |
2507 | |
2508 | case 1: |
2509 | ret = dict_set_str(volinfo->dict, key, |
2510 | gf_strdup (value)); |
2511 | if (ret) { |
2512 | gf_log ("",GF_LOG_ERROR, "Error in "do { do { if (0) printf ("Error in " "dict_set_str"); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2513, GF_LOG_ERROR , "Error in " "dict_set_str"); } while (0) |
2513 | "dict_set_str")do { do { if (0) printf ("Error in " "dict_set_str"); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2513, GF_LOG_ERROR , "Error in " "dict_set_str"); } while (0); |
2514 | goto out; |
2515 | } |
2516 | gf_log ("", GF_LOG_DEBUG, "Parsed as Volume-"do { do { if (0) printf ("Parsed as Volume-" "set:key=%s,value:%s" , key, value); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__ , 2517, GF_LOG_DEBUG, "Parsed as Volume-" "set:key=%s,value:%s" , key, value); } while (0) |
2517 | "set:key=%s,value:%s", key, value)do { do { if (0) printf ("Parsed as Volume-" "set:key=%s,value:%s" , key, value); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__ , 2517, GF_LOG_DEBUG, "Parsed as Volume-" "set:key=%s,value:%s" , key, value); } while (0); |
2518 | break; |
2519 | } |
2520 | } |
2521 | |
2522 | GF_FREE (key)__gf_free (key); |
2523 | GF_FREE (value)__gf_free (value); |
2524 | key = NULL((void*)0); |
2525 | value = NULL((void*)0); |
2526 | |
2527 | ret = glusterd_store_iter_get_next (iter, &key, &value, |
2528 | &op_errno); |
2529 | } |
2530 | |
2531 | /* backward compatibility */ |
2532 | { |
2533 | |
2534 | switch (volinfo->type) { |
2535 | |
2536 | case GF_CLUSTER_TYPE_NONE: |
2537 | volinfo->stripe_count = 1; |
2538 | volinfo->replica_count = 1; |
2539 | break; |
2540 | |
2541 | case GF_CLUSTER_TYPE_STRIPE: |
2542 | volinfo->stripe_count = volinfo->sub_count; |
2543 | volinfo->replica_count = 1; |
2544 | break; |
2545 | |
2546 | case GF_CLUSTER_TYPE_REPLICATE: |
2547 | volinfo->stripe_count = 1; |
2548 | volinfo->replica_count = volinfo->sub_count; |
2549 | break; |
2550 | |
2551 | case GF_CLUSTER_TYPE_STRIPE_REPLICATE: |
2552 | /* Introduced in 3.3 */ |
2553 | GF_ASSERT (volinfo->stripe_count > 0)do { if (!(volinfo->stripe_count > 0)) { do { do { if ( 0) printf ("Assertion failed: " "volinfo->stripe_count > 0" ); } while (0); _gf_log_callingfn ("", "glusterd-store.c", __FUNCTION__ , 2553, GF_LOG_ERROR, "Assertion failed: " "volinfo->stripe_count > 0" ); } while (0); } } while (0); |
2554 | GF_ASSERT (volinfo->replica_count > 0)do { if (!(volinfo->replica_count > 0)) { do { do { if ( 0) printf ("Assertion failed: " "volinfo->replica_count > 0" ); } while (0); _gf_log_callingfn ("", "glusterd-store.c", __FUNCTION__ , 2554, GF_LOG_ERROR, "Assertion failed: " "volinfo->replica_count > 0" ); } while (0); } } while (0); |
2555 | break; |
2556 | |
2557 | default: |
2558 | GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: " "0"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2558, GF_LOG_ERROR, "Assertion failed: " "0") ; } while (0); } } while (0); |
2559 | break; |
2560 | } |
2561 | |
2562 | volinfo->dist_leaf_count = glusterd_get_dist_leaf_count (volinfo); |
2563 | |
2564 | volinfo->subvol_count = (volinfo->brick_count / |
2565 | volinfo->dist_leaf_count); |
2566 | |
2567 | } |
2568 | |
2569 | if (op_errno != GD_STORE_EOF) |
2570 | goto out; |
2571 | |
2572 | ret = glusterd_store_iter_destroy (iter); |
2573 | |
2574 | if (ret) |
2575 | goto out; |
2576 | |
2577 | ret = glusterd_store_retrieve_bricks (volinfo); |
2578 | if (ret) |
2579 | goto out; |
2580 | |
2581 | ret = glusterd_volume_compute_cksum (volinfo); |
2582 | if (ret) |
2583 | goto out; |
2584 | |
2585 | gd_update_volume_op_versions (volinfo); |
2586 | |
2587 | list_add_tail (&volinfo->vol_list, &priv->volumes); |
2588 | |
2589 | out: |
2590 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2590, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
2591 | |
2592 | return ret; |
2593 | } |
2594 | |
2595 | inline void |
2596 | glusterd_store_set_options_path (glusterd_conf_t *conf, char *path, size_t len) |
2597 | { |
2598 | snprintf (path, len, "%s/options", conf->workdir); |
2599 | } |
2600 | |
2601 | int |
2602 | _store_global_opts (dict_t *this, char *key, data_t *value, void *data) |
2603 | { |
2604 | glusterd_store_handle_t *shandle = data; |
2605 | |
2606 | glusterd_store_save_value (shandle->fd, key, (char*)value->data); |
2607 | return 0; |
2608 | } |
2609 | |
2610 | int32_t |
2611 | glusterd_store_options (xlator_t *this, dict_t *opts) |
2612 | { |
2613 | glusterd_store_handle_t *shandle = NULL((void*)0); |
2614 | glusterd_conf_t *conf = NULL((void*)0); |
2615 | char path[PATH_MAX4096] = {0}; |
2616 | int fd = -1; |
2617 | int32_t ret = -1; |
2618 | |
2619 | conf = this->private; |
2620 | glusterd_store_set_options_path (conf, path, sizeof (path)); |
2621 | |
2622 | ret = glusterd_store_handle_new (path, &shandle); |
2623 | if (ret) |
2624 | goto out; |
2625 | |
2626 | fd = glusterd_store_mkstemp (shandle); |
2627 | if (fd <= 0) { |
2628 | ret = -1; |
2629 | goto out; |
2630 | } |
2631 | |
2632 | shandle->fd = fd; |
2633 | dict_foreach (opts, _store_global_opts, shandle); |
2634 | shandle->fd = 0; |
2635 | ret = glusterd_store_rename_tmppath (shandle); |
2636 | if (ret) |
2637 | goto out; |
2638 | out: |
2639 | glusterd_store_handle_destroy (shandle); |
2640 | if (fd >=0 ) |
2641 | close (fd); |
2642 | return ret; |
2643 | } |
2644 | |
2645 | int32_t |
2646 | glusterd_store_retrieve_options (xlator_t *this) |
2647 | { |
2648 | char path[PATH_MAX4096] = {0}; |
2649 | glusterd_conf_t *conf = NULL((void*)0); |
2650 | glusterd_store_handle_t *shandle = NULL((void*)0); |
2651 | glusterd_store_iter_t *iter = NULL((void*)0); |
2652 | char *key = NULL((void*)0); |
2653 | char *value = NULL((void*)0); |
2654 | glusterd_store_op_errno_t op_errno = 0; |
2655 | int ret = -1; |
2656 | |
2657 | conf = this->private; |
2658 | glusterd_store_set_options_path (conf, path, sizeof (path)); |
2659 | |
2660 | ret = glusterd_store_handle_retrieve (path, &shandle); |
2661 | if (ret) |
2662 | goto out; |
2663 | |
2664 | ret = glusterd_store_iter_new (shandle, &iter); |
2665 | if (ret) |
2666 | goto out; |
2667 | |
2668 | ret = glusterd_store_iter_get_next (iter, &key, &value, &op_errno); |
2669 | while (!ret) { |
2670 | ret = dict_set_dynstr (conf->opts, key, value); |
2671 | if (ret) { |
2672 | GF_FREE (key)__gf_free (key); |
2673 | GF_FREE (value)__gf_free (value); |
2674 | goto out; |
2675 | } |
2676 | GF_FREE (key)__gf_free (key); |
2677 | key = NULL((void*)0); |
2678 | value = NULL((void*)0); |
2679 | |
2680 | ret = glusterd_store_iter_get_next (iter, &key, &value, |
2681 | &op_errno); |
2682 | } |
2683 | if (op_errno != GD_STORE_EOF) |
2684 | goto out; |
2685 | ret = 0; |
2686 | out: |
2687 | glusterd_store_iter_destroy (iter); |
2688 | glusterd_store_handle_destroy (shandle); |
2689 | return ret; |
2690 | } |
2691 | |
2692 | int32_t |
2693 | glusterd_store_retrieve_volumes (xlator_t *this) |
2694 | { |
2695 | int32_t ret = 0; |
2696 | char path[PATH_MAX4096] = {0,}; |
2697 | glusterd_conf_t *priv = NULL((void*)0); |
2698 | DIR *dir = NULL((void*)0); |
2699 | struct dirent *entry = NULL((void*)0); |
2700 | glusterd_volinfo_t *volinfo = NULL((void*)0); |
2701 | |
2702 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2702, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); |
2703 | priv = this->private; |
2704 | |
2705 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2705, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); |
2706 | |
2707 | snprintf (path, PATH_MAX4096, "%s/%s", priv->workdir, |
2708 | GLUSTERD_VOLUME_DIR_PREFIX"vols"); |
2709 | |
2710 | dir = opendir (path); |
2711 | |
2712 | if (!dir) { |
2713 | gf_log ("", GF_LOG_ERROR, "Unable to open dir %s", path)do { do { if (0) printf ("Unable to open dir %s", path); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2713, GF_LOG_ERROR , "Unable to open dir %s", path); } while (0); |
2714 | ret = -1; |
2715 | goto out; |
2716 | } |
2717 | |
2718 | glusterd_for_each_entry (entry, dir)do { entry = ((void*)0); if (dir) { entry = readdir (dir); while (entry && (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, ".."))) { entry = readdir (dir); } } } while (0);; |
2719 | |
2720 | while (entry) { |
2721 | ret = glusterd_store_retrieve_volume (entry->d_name); |
2722 | if (ret) { |
2723 | gf_log ("", GF_LOG_ERROR, "Unable to restore "do { do { if (0) printf ("Unable to restore " "volume: %s", entry ->d_name); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__ , 2724, GF_LOG_ERROR, "Unable to restore " "volume: %s", entry ->d_name); } while (0) |
2724 | "volume: %s", entry->d_name)do { do { if (0) printf ("Unable to restore " "volume: %s", entry ->d_name); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__ , 2724, GF_LOG_ERROR, "Unable to restore " "volume: %s", entry ->d_name); } while (0); |
2725 | goto out; |
2726 | } |
2727 | |
2728 | ret = glusterd_store_retrieve_rbstate (entry->d_name); |
2729 | if (ret) { |
2730 | /* Backward compatibility */ |
2731 | gf_log ("", GF_LOG_INFO, "Creating a new rbstate "do { do { if (0) printf ("Creating a new rbstate " "for volume: %s." , entry->d_name); } while (0); _gf_log ("", "glusterd-store.c" , __FUNCTION__, 2732, GF_LOG_INFO, "Creating a new rbstate " "for volume: %s." , entry->d_name); } while (0) |
2732 | "for volume: %s.", entry->d_name)do { do { if (0) printf ("Creating a new rbstate " "for volume: %s." , entry->d_name); } while (0); _gf_log ("", "glusterd-store.c" , __FUNCTION__, 2732, GF_LOG_INFO, "Creating a new rbstate " "for volume: %s." , entry->d_name); } while (0); |
2733 | ret = glusterd_volinfo_find (entry->d_name, &volinfo); |
2734 | ret = glusterd_store_create_rbstate_shandle_on_absence (volinfo); |
2735 | ret = glusterd_store_perform_rbstate_store (volinfo); |
2736 | } |
2737 | |
2738 | ret = glusterd_store_retrieve_node_state (entry->d_name); |
2739 | if (ret) { |
2740 | /* Backward compatibility */ |
2741 | gf_log ("", GF_LOG_INFO, "Creating a new node_state "do { do { if (0) printf ("Creating a new node_state " "for volume: %s." , entry->d_name); } while (0); _gf_log ("", "glusterd-store.c" , __FUNCTION__, 2742, GF_LOG_INFO, "Creating a new node_state " "for volume: %s.", entry->d_name); } while (0) |
2742 | "for volume: %s.", entry->d_name)do { do { if (0) printf ("Creating a new node_state " "for volume: %s." , entry->d_name); } while (0); _gf_log ("", "glusterd-store.c" , __FUNCTION__, 2742, GF_LOG_INFO, "Creating a new node_state " "for volume: %s.", entry->d_name); } while (0); |
2743 | ret = glusterd_volinfo_find (entry->d_name, &volinfo); |
2744 | ret = |
2745 | glusterd_store_create_nodestate_sh_on_absence (volinfo); |
2746 | ret = glusterd_store_perform_node_state_store (volinfo); |
2747 | |
2748 | } |
2749 | glusterd_for_each_entry (entry, dir)do { entry = ((void*)0); if (dir) { entry = readdir (dir); while (entry && (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, ".."))) { entry = readdir (dir); } } } while (0);; |
2750 | } |
2751 | |
2752 | out: |
2753 | if (dir) |
2754 | closedir (dir); |
2755 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2755, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
2756 | |
2757 | return ret; |
2758 | } |
2759 | |
2760 | int32_t |
2761 | glusterd_store_delete_peerinfo (glusterd_peerinfo_t *peerinfo) |
2762 | { |
2763 | int32_t ret = -1; |
2764 | glusterd_conf_t *priv = NULL((void*)0); |
2765 | char peerdir[PATH_MAX4096] = {0,}; |
2766 | char filepath[PATH_MAX4096] = {0,}; |
2767 | char hostname_path[PATH_MAX4096] = {0,}; |
2768 | |
2769 | |
2770 | if (!peerinfo) { |
2771 | ret = 0; |
2772 | goto out; |
2773 | } |
2774 | |
2775 | priv = THIS(*__glusterfs_this_location())->private; |
2776 | |
2777 | snprintf (peerdir, PATH_MAX4096, "%s/peers", priv->workdir); |
2778 | |
2779 | |
2780 | if (uuid_is_null (peerinfo->uuid)) { |
2781 | |
2782 | if (peerinfo->hostname) { |
2783 | snprintf (filepath, PATH_MAX4096, "%s/%s", peerdir, |
2784 | peerinfo->hostname); |
2785 | } else { |
2786 | ret = 0; |
2787 | goto out; |
2788 | } |
2789 | } else { |
2790 | |
2791 | snprintf (filepath, PATH_MAX4096, "%s/%s", peerdir, |
2792 | uuid_utoa (peerinfo->uuid)); |
2793 | snprintf (hostname_path, PATH_MAX4096, "%s/%s", |
2794 | peerdir, peerinfo->hostname); |
2795 | |
2796 | ret = unlink (hostname_path); |
2797 | |
2798 | if (!ret) |
2799 | goto out; |
2800 | } |
2801 | |
2802 | ret = unlink (filepath); |
2803 | if (ret && (errno(*__errno_location ()) == ENOENT2)) |
2804 | ret = 0; |
2805 | |
2806 | out: |
2807 | if (peerinfo->shandle) { |
2808 | glusterd_store_handle_destroy (peerinfo->shandle); |
2809 | peerinfo->shandle = NULL((void*)0); |
2810 | } |
2811 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2811, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
2812 | |
2813 | return ret; |
2814 | } |
2815 | |
2816 | void |
2817 | glusterd_store_peerinfo_dirpath_set (char *path, size_t len) |
2818 | { |
2819 | glusterd_conf_t *priv = NULL((void*)0); |
2820 | GF_ASSERT (path)do { if (!(path)) { do { do { if (0) printf ("Assertion failed: " "path"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2820, GF_LOG_ERROR, "Assertion failed: " "path" ); } while (0); } } while (0); |
2821 | GF_ASSERT (len >= PATH_MAX)do { if (!(len >= 4096)) { do { do { if (0) printf ("Assertion failed: " "len >= PATH_MAX"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2821, GF_LOG_ERROR, "Assertion failed: " "len >= PATH_MAX" ); } while (0); } } while (0); |
2822 | |
2823 | priv = THIS(*__glusterfs_this_location())->private; |
2824 | snprintf (path, len, "%s/peers", priv->workdir); |
2825 | } |
2826 | |
2827 | int32_t |
2828 | glusterd_store_create_peer_dir () |
2829 | { |
2830 | int32_t ret = 0; |
2831 | char path[PATH_MAX4096]; |
2832 | |
2833 | glusterd_store_peerinfo_dirpath_set (path, sizeof (path)); |
2834 | ret = glusterd_store_mkdir (path); |
2835 | |
2836 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2836, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
2837 | return ret; |
2838 | } |
2839 | |
2840 | static void |
2841 | glusterd_store_uuid_peerpath_set (glusterd_peerinfo_t *peerinfo, char *peerfpath, |
2842 | size_t len) |
2843 | { |
2844 | char peerdir[PATH_MAX4096]; |
2845 | char str[50] = {0}; |
2846 | |
2847 | GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: " "peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2847, GF_LOG_ERROR, "Assertion failed: " "peerinfo" ); } while (0); } } while (0); |
2848 | GF_ASSERT (peerfpath)do { if (!(peerfpath)) { do { do { if (0) printf ("Assertion failed: " "peerfpath"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2848, GF_LOG_ERROR, "Assertion failed: " "peerfpath" ); } while (0); } } while (0); |
2849 | GF_ASSERT (len >= PATH_MAX)do { if (!(len >= 4096)) { do { do { if (0) printf ("Assertion failed: " "len >= PATH_MAX"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2849, GF_LOG_ERROR, "Assertion failed: " "len >= PATH_MAX" ); } while (0); } } while (0); |
2850 | |
2851 | glusterd_store_peerinfo_dirpath_set (peerdir, sizeof (peerdir)); |
2852 | uuid_unparse (peerinfo->uuid, str); |
2853 | snprintf (peerfpath, len, "%s/%s", peerdir, str); |
2854 | } |
2855 | |
2856 | static void |
2857 | glusterd_store_hostname_peerpath_set (glusterd_peerinfo_t *peerinfo, |
2858 | char *peerfpath, size_t len) |
2859 | { |
2860 | char peerdir[PATH_MAX4096]; |
2861 | |
2862 | GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: " "peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2862, GF_LOG_ERROR, "Assertion failed: " "peerinfo" ); } while (0); } } while (0); |
2863 | GF_ASSERT (peerfpath)do { if (!(peerfpath)) { do { do { if (0) printf ("Assertion failed: " "peerfpath"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2863, GF_LOG_ERROR, "Assertion failed: " "peerfpath" ); } while (0); } } while (0); |
2864 | GF_ASSERT (len >= PATH_MAX)do { if (!(len >= 4096)) { do { do { if (0) printf ("Assertion failed: " "len >= PATH_MAX"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2864, GF_LOG_ERROR, "Assertion failed: " "len >= PATH_MAX" ); } while (0); } } while (0); |
2865 | |
2866 | glusterd_store_peerinfo_dirpath_set (peerdir, sizeof (peerdir)); |
2867 | snprintf (peerfpath, len, "%s/%s", peerdir, peerinfo->hostname); |
2868 | } |
2869 | |
2870 | int32_t |
2871 | glusterd_store_peerinfo_hostname_shandle_create (glusterd_peerinfo_t *peerinfo) |
2872 | { |
2873 | char peerfpath[PATH_MAX4096]; |
2874 | int32_t ret = -1; |
2875 | |
2876 | glusterd_store_hostname_peerpath_set (peerinfo, peerfpath, |
2877 | sizeof (peerfpath)); |
2878 | ret = glusterd_store_handle_create_on_absence (&peerinfo->shandle, |
2879 | peerfpath); |
2880 | return ret; |
2881 | } |
2882 | |
2883 | int32_t |
2884 | glusterd_store_peerinfo_uuid_shandle_create (glusterd_peerinfo_t *peerinfo) |
2885 | { |
2886 | char peerfpath[PATH_MAX4096]; |
2887 | int32_t ret = -1; |
2888 | |
2889 | glusterd_store_uuid_peerpath_set (peerinfo, peerfpath, |
2890 | sizeof (peerfpath)); |
2891 | ret = glusterd_store_handle_create_on_absence (&peerinfo->shandle, |
2892 | peerfpath); |
2893 | return ret; |
2894 | } |
2895 | |
2896 | int32_t |
2897 | glusterd_peerinfo_hostname_shandle_check_destroy (glusterd_peerinfo_t *peerinfo) |
2898 | { |
2899 | char peerfpath[PATH_MAX4096]; |
2900 | int32_t ret = -1; |
2901 | struct stat stbuf = {0,}; |
2902 | |
2903 | glusterd_store_hostname_peerpath_set (peerinfo, peerfpath, |
2904 | sizeof (peerfpath)); |
2905 | ret = stat (peerfpath, &stbuf); |
2906 | if (!ret) { |
2907 | if (peerinfo->shandle) |
2908 | glusterd_store_handle_destroy (peerinfo->shandle); |
2909 | peerinfo->shandle = NULL((void*)0); |
2910 | ret = unlink (peerfpath); |
2911 | } |
2912 | return ret; |
2913 | } |
2914 | |
2915 | int32_t |
2916 | glusterd_store_create_peer_shandle (glusterd_peerinfo_t *peerinfo) |
2917 | { |
2918 | int32_t ret = 0; |
2919 | |
2920 | GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: " "peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2920, GF_LOG_ERROR, "Assertion failed: " "peerinfo" ); } while (0); } } while (0); |
2921 | |
2922 | if (glusterd_peerinfo_is_uuid_unknown (peerinfo)) { |
2923 | ret = glusterd_store_peerinfo_hostname_shandle_create (peerinfo); |
2924 | } else { |
2925 | ret = glusterd_peerinfo_hostname_shandle_check_destroy (peerinfo); |
Value stored to 'ret' is never read | |
2926 | ret = glusterd_store_peerinfo_uuid_shandle_create (peerinfo); |
2927 | } |
2928 | return ret; |
2929 | } |
2930 | |
2931 | int32_t |
2932 | glusterd_store_peer_write (int fd, glusterd_peerinfo_t *peerinfo) |
2933 | { |
2934 | char buf[50] = {0}; |
2935 | int32_t ret = 0; |
2936 | |
2937 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_PEER_UUID"uuid", |
2938 | uuid_utoa (peerinfo->uuid)); |
2939 | if (ret) |
2940 | goto out; |
2941 | |
2942 | snprintf (buf, sizeof (buf), "%d", peerinfo->state.state); |
2943 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_PEER_STATE"state", buf); |
2944 | if (ret) |
2945 | goto out; |
2946 | |
2947 | ret = glusterd_store_save_value (fd, GLUSTERD_STORE_KEY_PEER_HOSTNAME"hostname" "1", |
2948 | peerinfo->hostname); |
2949 | if (ret) |
2950 | goto out; |
2951 | |
2952 | out: |
2953 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2953, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
2954 | return ret; |
2955 | } |
2956 | |
2957 | int32_t |
2958 | glusterd_store_perform_peer_store (glusterd_peerinfo_t *peerinfo) |
2959 | { |
2960 | int fd = -1; |
2961 | int32_t ret = -1; |
2962 | |
2963 | GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: " "peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2963, GF_LOG_ERROR, "Assertion failed: " "peerinfo" ); } while (0); } } while (0); |
2964 | |
2965 | fd = glusterd_store_mkstemp (peerinfo->shandle); |
2966 | if (fd <= 0) { |
2967 | ret = -1; |
2968 | goto out; |
2969 | } |
2970 | |
2971 | ret = glusterd_store_peer_write (fd, peerinfo); |
2972 | if (ret) |
2973 | goto out; |
2974 | |
2975 | ret = glusterd_store_rename_tmppath (peerinfo->shandle); |
2976 | out: |
2977 | if (ret && (fd > 0)) |
2978 | glusterd_store_unlink_tmppath (peerinfo->shandle); |
2979 | if (fd > 0) |
2980 | close (fd); |
2981 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 2981, GF_LOG_DEBUG, "Returning %d" , ret); } while (0); |
2982 | return ret; |
2983 | } |
2984 | |
2985 | int32_t |
2986 | glusterd_store_peerinfo (glusterd_peerinfo_t *peerinfo) |
2987 | { |
2988 | int32_t ret = -1; |
2989 | |
2990 | GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: " "peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 2990, GF_LOG_ERROR, "Assertion failed: " "peerinfo" ); } while (0); } } while (0); |
2991 | |
2992 | ret = glusterd_store_create_peer_dir (); |
2993 | if (ret) |
2994 | goto out; |
2995 | |
2996 | ret = glusterd_store_create_peer_shandle (peerinfo); |
2997 | if (ret) |
2998 | goto out; |
2999 | |
3000 | ret = glusterd_store_perform_peer_store (peerinfo); |
3001 | out: |
3002 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 3002, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
3003 | return ret; |
3004 | } |
3005 | |
3006 | int32_t |
3007 | glusterd_store_retrieve_peers (xlator_t *this) |
3008 | { |
3009 | int32_t ret = 0; |
3010 | glusterd_conf_t *priv = NULL((void*)0); |
3011 | DIR *dir = NULL((void*)0); |
3012 | struct dirent *entry = NULL((void*)0); |
3013 | char path[PATH_MAX4096] = {0,}; |
3014 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); |
3015 | uuid_t uuid = {0,}; |
3016 | char *hostname = NULL((void*)0); |
3017 | int32_t state = 0; |
3018 | glusterd_store_handle_t *shandle = NULL((void*)0); |
3019 | char filepath[PATH_MAX4096] = {0,}; |
3020 | glusterd_store_iter_t *iter = NULL((void*)0); |
3021 | char *key = NULL((void*)0); |
3022 | char *value = NULL((void*)0); |
3023 | glusterd_peerctx_args_t args = {0}; |
3024 | glusterd_store_op_errno_t op_errno = GD_STORE_SUCCESS; |
3025 | |
3026 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 3026, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); |
3027 | priv = this->private; |
3028 | |
3029 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 3029, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); |
3030 | |
3031 | snprintf (path, PATH_MAX4096, "%s/%s", priv->workdir, |
3032 | GLUSTERD_PEER_DIR_PREFIX"peers"); |
3033 | |
3034 | dir = opendir (path); |
3035 | |
3036 | if (!dir) { |
3037 | gf_log ("", GF_LOG_ERROR, "Unable to open dir %s", path)do { do { if (0) printf ("Unable to open dir %s", path); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 3037, GF_LOG_ERROR , "Unable to open dir %s", path); } while (0); |
3038 | ret = -1; |
3039 | goto out; |
3040 | } |
3041 | |
3042 | glusterd_for_each_entry (entry, dir)do { entry = ((void*)0); if (dir) { entry = readdir (dir); while (entry && (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, ".."))) { entry = readdir (dir); } } } while (0);; |
3043 | |
3044 | while (entry) { |
3045 | snprintf (filepath, PATH_MAX4096, "%s/%s", path, entry->d_name); |
3046 | ret = glusterd_store_handle_retrieve (filepath, &shandle); |
3047 | if (ret) |
3048 | goto out; |
3049 | |
3050 | ret = glusterd_store_iter_new (shandle, &iter); |
3051 | if (ret) |
3052 | goto out; |
3053 | |
3054 | ret = glusterd_store_iter_get_next (iter, &key, &value, |
3055 | &op_errno); |
3056 | if (ret) |
3057 | goto out; |
3058 | |
3059 | while (!ret) { |
3060 | |
3061 | if (!strncmp (GLUSTERD_STORE_KEY_PEER_UUID"uuid", key, |
3062 | strlen (GLUSTERD_STORE_KEY_PEER_UUID"uuid"))) { |
3063 | if (value) |
3064 | uuid_parse (value, uuid); |
3065 | } else if (!strncmp (GLUSTERD_STORE_KEY_PEER_STATE"state", |
3066 | key, |
3067 | strlen (GLUSTERD_STORE_KEY_PEER_STATE"state"))) { |
3068 | state = atoi (value); |
3069 | } else if (!strncmp (GLUSTERD_STORE_KEY_PEER_HOSTNAME"hostname", |
3070 | key, |
3071 | strlen (GLUSTERD_STORE_KEY_PEER_HOSTNAME"hostname"))) { |
3072 | hostname = gf_strdup (value); |
3073 | } else { |
3074 | gf_log ("", GF_LOG_ERROR, "Unknown key: %s",do { do { if (0) printf ("Unknown key: %s", key); } while (0) ; _gf_log ("", "glusterd-store.c", __FUNCTION__, 3075, GF_LOG_ERROR , "Unknown key: %s", key); } while (0) |
3075 | key)do { do { if (0) printf ("Unknown key: %s", key); } while (0) ; _gf_log ("", "glusterd-store.c", __FUNCTION__, 3075, GF_LOG_ERROR , "Unknown key: %s", key); } while (0); |
3076 | } |
3077 | |
3078 | GF_FREE (key)__gf_free (key); |
3079 | GF_FREE (value)__gf_free (value); |
3080 | key = NULL((void*)0); |
3081 | value = NULL((void*)0); |
3082 | |
3083 | ret = glusterd_store_iter_get_next (iter, &key, &value, |
3084 | &op_errno); |
3085 | } |
3086 | if (op_errno != GD_STORE_EOF) |
3087 | goto out; |
3088 | |
3089 | (void) glusterd_store_iter_destroy (iter); |
3090 | |
3091 | ret = glusterd_friend_add (hostname, 0, state, &uuid, |
3092 | &peerinfo, 1, NULL((void*)0)); |
3093 | |
3094 | GF_FREE (hostname)__gf_free (hostname); |
3095 | if (ret) |
3096 | goto out; |
3097 | |
3098 | peerinfo->shandle = shandle; |
3099 | glusterd_for_each_entry (entry, dir)do { entry = ((void*)0); if (dir) { entry = readdir (dir); while (entry && (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, ".."))) { entry = readdir (dir); } } } while (0);; |
3100 | } |
3101 | |
3102 | args.mode = GD_MODE_ON; |
3103 | list_for_each_entry (peerinfo, &priv->peers, uuid_list)for (peerinfo = ((typeof(*peerinfo) *)((char *)((&priv-> peers)->next)-(unsigned long)(&((typeof(*peerinfo) *)0 )->uuid_list))); &peerinfo->uuid_list != (&priv ->peers); peerinfo = ((typeof(*peerinfo) *)((char *)(peerinfo ->uuid_list.next)-(unsigned long)(&((typeof(*peerinfo) *)0)->uuid_list)))) { |
3104 | ret = glusterd_friend_rpc_create (this, peerinfo, &args); |
3105 | if (ret) |
3106 | goto out; |
3107 | } |
3108 | |
3109 | out: |
3110 | if (dir) |
3111 | closedir (dir); |
3112 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 3112, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
3113 | |
3114 | return ret; |
3115 | } |
3116 | |
3117 | int32_t |
3118 | glusterd_resolve_all_bricks (xlator_t *this) |
3119 | { |
3120 | int32_t ret = 0; |
3121 | glusterd_conf_t *priv = NULL((void*)0); |
3122 | glusterd_volinfo_t *volinfo = NULL((void*)0); |
3123 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); |
3124 | |
3125 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 3125, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); |
3126 | priv = this->private; |
3127 | |
3128 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-store.c" , __FUNCTION__, 3128, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); |
3129 | |
3130 | list_for_each_entry (volinfo, &priv->volumes, vol_list)for (volinfo = ((typeof(*volinfo) *)((char *)((&priv-> volumes)->next)-(unsigned long)(&((typeof(*volinfo) *) 0)->vol_list))); &volinfo->vol_list != (&priv-> volumes); volinfo = ((typeof(*volinfo) *)((char *)(volinfo-> vol_list.next)-(unsigned long)(&((typeof(*volinfo) *)0)-> vol_list)))) { |
3131 | list_for_each_entry (brickinfo, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { |
3132 | ret = glusterd_resolve_brick (brickinfo); |
3133 | if (ret) { |
3134 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("resolve brick failed in restore"); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__ , 3135, GF_LOG_ERROR, "resolve brick failed in restore"); } while (0) |
3135 | "resolve brick failed in restore")do { do { if (0) printf ("resolve brick failed in restore"); } while (0); _gf_log ("glusterd", "glusterd-store.c", __FUNCTION__ , 3135, GF_LOG_ERROR, "resolve brick failed in restore"); } while (0); |
3136 | goto out; |
3137 | } |
3138 | } |
3139 | } |
3140 | |
3141 | out: |
3142 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 3142, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); |
3143 | |
3144 | return ret; |
3145 | } |
3146 | |
3147 | int32_t |
3148 | glusterd_restore () |
3149 | { |
3150 | int32_t ret = -1; |
3151 | xlator_t *this = NULL((void*)0); |
3152 | |
3153 | this = THIS(*__glusterfs_this_location()); |
3154 | |
3155 | ret = glusterd_restore_op_version (this); |
3156 | if (ret) { |
3157 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to restore op_version"); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 3158, GF_LOG_ERROR, "Failed to restore op_version"); } while (0) |
3158 | "Failed to restore op_version")do { do { if (0) printf ("Failed to restore op_version"); } while (0); _gf_log (this->name, "glusterd-store.c", __FUNCTION__ , 3158, GF_LOG_ERROR, "Failed to restore op_version"); } while (0); |
3159 | goto out; |
3160 | } |
3161 | |
3162 | ret = glusterd_store_retrieve_volumes (this); |
3163 | if (ret) |
3164 | goto out; |
3165 | |
3166 | ret = glusterd_store_retrieve_peers (this); |
3167 | if (ret) |
3168 | goto out; |
3169 | |
3170 | ret = glusterd_resolve_all_bricks (this); |
3171 | if (ret) |
3172 | goto out; |
3173 | |
3174 | out: |
3175 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-store.c", __FUNCTION__, 3175, GF_LOG_DEBUG, "Returning %d" , ret); } while (0); |
3176 | return ret; |
3177 | } |