Bug Summary

File:xlators/mgmt/glusterd/src/glusterd-utils.c
Location:line 4046, column 16
Description:Access to field 'private' results in a dereference of a null pointer (loaded from variable 'this')

Annotated Source Code

1/*
2 Copyright (c) 2006-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#ifndef _CONFIG_H
11#define _CONFIG_H
12#include "config.h"
13#endif
14#include <openssl/md5.h>
15#include <inttypes.h>
16
17#include "globals.h"
18#include "glusterfs.h"
19#include "compat.h"
20#include "dict.h"
21#include "xlator.h"
22#include "logging.h"
23#include "timer.h"
24#include "defaults.h"
25#include "compat.h"
26#include "syncop.h"
27#include "run.h"
28#include "compat-errno.h"
29#include "statedump.h"
30#include "syscall.h"
31#include "glusterd-mem-types.h"
32#include "glusterd.h"
33#include "glusterd-op-sm.h"
34#include "glusterd-sm.h"
35#include "glusterd-utils.h"
36#include "glusterd-store.h"
37#include "glusterd-volgen.h"
38#include "glusterd-pmap.h"
39
40#include "xdr-generic.h"
41#include <sys/resource.h>
42#include <inttypes.h>
43#include <signal.h>
44#include <sys/types.h>
45#include <net/if.h>
46#include <sys/ioctl.h>
47#include <sys/socket.h>
48#include <rpc/pmap_clnt.h>
49#include <unistd.h>
50#include <fnmatch.h>
51#include <sys/statvfs.h>
52#include <ifaddrs.h>
53
54#ifdef GF_LINUX_HOST_OS1
55#include <mntent.h>
56#endif
57
58#ifdef GF_SOLARIS_HOST_OS
59#include <sys/sockio.h>
60#endif
61
62#define NFS_PROGRAM100003 100003
63#define NFSV3_VERSION3 3
64
65#define MOUNT_PROGRAM100005 100005
66#define MOUNTV3_VERSION3 3
67#define MOUNTV1_VERSION1 1
68
69#define NLM_PROGRAM100021 100021
70#define NLMV4_VERSION4 4
71#define NLMV1_VERSION1 1
72
73#define CEILING_POS(X)(((X)-(int)(X)) > 0 ? (int)((X)+1) : (int)(X)) (((X)-(int)(X)) > 0 ? (int)((X)+1) : (int)(X))
74
75static glusterd_lock_t lock;
76
77static void
78md5_wrapper(const unsigned char *data, size_t len, char *md5)
79{
80 unsigned short i = 0;
81 unsigned short lim = MD5_DIGEST_LENGTH16*2+1;
82 unsigned char scratch[MD5_DIGEST_LENGTH16] = {0,};
83 MD5(data, len, scratch);
84 for (; i < MD5_DIGEST_LENGTH16; i++)
85 snprintf(md5 + i * 2, lim-i*2, "%02x", scratch[i]);
86}
87
88int32_t
89glusterd_get_lock_owner (uuid_t *uuid)
90{
91 uuid_copy (*uuid, lock.owner) ;
92 return 0;
93}
94
95static int32_t
96glusterd_set_lock_owner (uuid_t owner)
97{
98 uuid_copy (lock.owner, owner);
99 //TODO: set timestamp
100 return 0;
101}
102
103static int32_t
104glusterd_unset_lock_owner (uuid_t owner)
105{
106 uuid_clear (lock.owner);
107 //TODO: set timestamp
108 return 0;
109}
110
111gf_boolean_t
112glusterd_is_fuse_available ()
113{
114
115 int fd = 0;
116
117 fd = open ("/dev/fuse", O_RDWR02);
118
119 if (fd > -1 && !close (fd))
120 return _gf_true;
121 else
122 return _gf_false;
123}
124
125gf_boolean_t
126glusterd_is_loopback_localhost (const struct sockaddr *sa, char *hostname)
127{
128 GF_ASSERT (sa)do { if (!(sa)) { do { do { if (0) printf ("Assertion failed: "
"sa"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 128, GF_LOG_ERROR, "Assertion failed: " "sa")
; } while (0); } } while (0)
;
129
130 gf_boolean_t is_local = _gf_false;
131 const struct in_addr *addr4 = NULL((void*)0);
132 const struct in6_addr *addr6 = NULL((void*)0);
133 uint8_t *ap = NULL((void*)0);
134 struct in6_addr loopbackaddr6 = IN6ADDR_LOOPBACK_INIT{ { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } };
135
136 switch (sa->sa_family) {
137 case AF_INET2:
138 addr4 = &(((struct sockaddr_in *)sa)->sin_addr);
139 ap = (uint8_t*)&addr4->s_addr;
140 if (ap[0] == 127)
141 is_local = _gf_true;
142 break;
143
144 case AF_INET610:
145 addr6 = &(((struct sockaddr_in6 *)sa)->sin6_addr);
146 if (memcmp (addr6, &loopbackaddr6,
147 sizeof (loopbackaddr6)) == 0)
148 is_local = _gf_true;
149 break;
150
151 default:
152 if (hostname)
153 gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("unknown address family %d for %s", sa
->sa_family, hostname); } while (0); _gf_log ("glusterd", "glusterd-utils.c"
, __FUNCTION__, 155, GF_LOG_ERROR, "unknown address family %d for %s"
, sa->sa_family, hostname); } while (0)
154 "unknown address family %d for %s",do { do { if (0) printf ("unknown address family %d for %s", sa
->sa_family, hostname); } while (0); _gf_log ("glusterd", "glusterd-utils.c"
, __FUNCTION__, 155, GF_LOG_ERROR, "unknown address family %d for %s"
, sa->sa_family, hostname); } while (0)
155 sa->sa_family, hostname)do { do { if (0) printf ("unknown address family %d for %s", sa
->sa_family, hostname); } while (0); _gf_log ("glusterd", "glusterd-utils.c"
, __FUNCTION__, 155, GF_LOG_ERROR, "unknown address family %d for %s"
, sa->sa_family, hostname); } while (0)
;
156 break;
157 }
158
159 return is_local;
160}
161
162char *
163get_ip_from_addrinfo (struct addrinfo *addr, char **ip)
164{
165 char buf[64];
166 void *in_addr = NULL((void*)0);
167 struct sockaddr_in *s4 = NULL((void*)0);
168 struct sockaddr_in6 *s6 = NULL((void*)0);
169
170 switch (addr->ai_family)
171 {
172 case AF_INET2:
173 s4 = (struct sockaddr_in *)addr->ai_addr;
174 in_addr = &s4->sin_addr;
175 break;
176
177 case AF_INET610:
178 s6 = (struct sockaddr_in6 *)addr->ai_addr;
179 in_addr = &s6->sin6_addr;
180 break;
181
182 default:
183 gf_log ("glusterd", GF_LOG_ERROR, "Invalid family")do { do { if (0) printf ("Invalid family"); } while (0); _gf_log
("glusterd", "glusterd-utils.c", __FUNCTION__, 183, GF_LOG_ERROR
, "Invalid family"); } while (0)
;
184 return NULL((void*)0);
185 }
186
187 if (!inet_ntop(addr->ai_family, in_addr, buf, sizeof(buf))) {
188 gf_log ("glusterd", GF_LOG_ERROR, "String conversion failed")do { do { if (0) printf ("String conversion failed"); } while
(0); _gf_log ("glusterd", "glusterd-utils.c", __FUNCTION__, 188
, GF_LOG_ERROR, "String conversion failed"); } while (0)
;
189 return NULL((void*)0);
190 }
191
192 *ip = strdup (buf);
193 return *ip;
194}
195
196gf_boolean_t
197glusterd_interface_search (char *ip)
198{
199 int32_t ret = -1;
200 gf_boolean_t found = _gf_false;
201 struct ifaddrs *ifaddr, *ifa;
202 int family;
203 char host[NI_MAXHOST1025];
204 xlator_t *this = NULL((void*)0);
205 char *pct = NULL((void*)0);
206
207 this = THIS(*__glusterfs_this_location());
208
209 ret = getifaddrs (&ifaddr);
210
211 if (ret != 0) {
212 gf_log (this->name, GF_LOG_ERROR, "getifaddrs() failed: %s\n",do { do { if (0) printf ("getifaddrs() failed: %s\n", gai_strerror
(ret)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 213, GF_LOG_ERROR, "getifaddrs() failed: %s\n"
, gai_strerror(ret)); } while (0)
213 gai_strerror(ret))do { do { if (0) printf ("getifaddrs() failed: %s\n", gai_strerror
(ret)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 213, GF_LOG_ERROR, "getifaddrs() failed: %s\n"
, gai_strerror(ret)); } while (0)
;
214 goto out;
215 }
216
217 for (ifa = ifaddr; ifa != NULL((void*)0); ifa = ifa->ifa_next) {
218 if (!ifa->ifa_addr) {
219 /*
220 * This seemingly happens if an interface hasn't
221 * been bound to a particular protocol (seen with
222 * TUN devices).
223 */
224 continue;
225 }
226 family = ifa->ifa_addr->sa_family;
227
228 if (family != AF_INET2 && family != AF_INET610)
229 continue;
230
231 ret = getnameinfo (ifa->ifa_addr,
232 (family == AF_INET2) ? sizeof(struct sockaddr_in) :
233 sizeof(struct sockaddr_in6),
234 host, NI_MAXHOST1025, NULL((void*)0), 0, NI_NUMERICHOST1);
235
236 if (ret != 0) {
237 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("getnameinfo() failed: %s\n", gai_strerror
(ret)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 239, GF_LOG_ERROR, "getnameinfo() failed: %s\n"
, gai_strerror(ret)); } while (0)
238 "getnameinfo() failed: %s\n",do { do { if (0) printf ("getnameinfo() failed: %s\n", gai_strerror
(ret)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 239, GF_LOG_ERROR, "getnameinfo() failed: %s\n"
, gai_strerror(ret)); } while (0)
239 gai_strerror(ret))do { do { if (0) printf ("getnameinfo() failed: %s\n", gai_strerror
(ret)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 239, GF_LOG_ERROR, "getnameinfo() failed: %s\n"
, gai_strerror(ret)); } while (0)
;
240 goto out;
241 }
242
243 /*
244 * Sometimes the address comes back as addr%eth0 or
245 * similar. Since % is an invalid character, we can
246 * strip it out with confidence that doing so won't
247 * harm anything.
248 */
249 pct = index(host,'%');
250 if (pct) {
251 *pct = '\0';
252 }
253
254 if (strncmp (ip, host, NI_MAXHOST1025) == 0) {
255 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("%s is local address at interface %s"
, ip, ifa->ifa_name); } while (0); _gf_log (this->name,
"glusterd-utils.c", __FUNCTION__, 257, GF_LOG_DEBUG, "%s is local address at interface %s"
, ip, ifa->ifa_name); } while (0)
256 "%s is local address at interface %s",do { do { if (0) printf ("%s is local address at interface %s"
, ip, ifa->ifa_name); } while (0); _gf_log (this->name,
"glusterd-utils.c", __FUNCTION__, 257, GF_LOG_DEBUG, "%s is local address at interface %s"
, ip, ifa->ifa_name); } while (0)
257 ip, ifa->ifa_name)do { do { if (0) printf ("%s is local address at interface %s"
, ip, ifa->ifa_name); } while (0); _gf_log (this->name,
"glusterd-utils.c", __FUNCTION__, 257, GF_LOG_DEBUG, "%s is local address at interface %s"
, ip, ifa->ifa_name); } while (0)
;
258 found = _gf_true;
259 goto out;
260 }
261 }
262out:
263 if(ifaddr)
264 freeifaddrs (ifaddr);
265 return found;
266}
267
268
269gf_boolean_t
270glusterd_is_local_addr (char *hostname)
271{
272 int32_t ret = -1;
273 struct addrinfo *result = NULL((void*)0);
274 struct addrinfo *res = NULL((void*)0);
275 gf_boolean_t found = _gf_false;
276 char *ip = NULL((void*)0);
277 xlator_t *this = NULL((void*)0);
278
279 this = THIS(*__glusterfs_this_location());
280 ret = getaddrinfo (hostname, NULL((void*)0), NULL((void*)0), &result);
281
282 if (ret != 0) {
283 gf_log (this->name, GF_LOG_ERROR, "error in getaddrinfo: %s\n",do { do { if (0) printf ("error in getaddrinfo: %s\n", gai_strerror
(ret)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 284, GF_LOG_ERROR, "error in getaddrinfo: %s\n"
, gai_strerror(ret)); } while (0)
284 gai_strerror(ret))do { do { if (0) printf ("error in getaddrinfo: %s\n", gai_strerror
(ret)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 284, GF_LOG_ERROR, "error in getaddrinfo: %s\n"
, gai_strerror(ret)); } while (0)
;
285 goto out;
286 }
287
288 for (res = result; res != NULL((void*)0); res = res->ai_next) {
289 gf_log (this->name, GF_LOG_DEBUG, "%s ",do { do { if (0) printf ("%s ", get_ip_from_addrinfo (res, &
ip)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 290, GF_LOG_DEBUG, "%s ", get_ip_from_addrinfo
(res, &ip)); } while (0)
290 get_ip_from_addrinfo (res, &ip))do { do { if (0) printf ("%s ", get_ip_from_addrinfo (res, &
ip)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 290, GF_LOG_DEBUG, "%s ", get_ip_from_addrinfo
(res, &ip)); } while (0)
;
291
292 found = glusterd_is_loopback_localhost (res->ai_addr, hostname)
293 || glusterd_interface_search (ip);
294 if (found)
295 goto out;
296 }
297
298out:
299 if (result)
300 freeaddrinfo (result);
301
302 if (!found)
303 gf_log (this->name, GF_LOG_DEBUG, "%s is not local", hostname)do { do { if (0) printf ("%s is not local", hostname); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 303, GF_LOG_DEBUG, "%s is not local", hostname); } while (0
)
;
304
305 return found;
306}
307
308int32_t
309glusterd_lock (uuid_t uuid)
310{
311
312 uuid_t owner;
313 char new_owner_str[50];
314 char owner_str[50];
315 int ret = -1;
316 xlator_t *this = NULL((void*)0);
317
318 this = THIS(*__glusterfs_this_location());
319 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 319, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
320
321 GF_ASSERT (uuid)do { if (!(uuid)) { do { do { if (0) printf ("Assertion failed: "
"uuid"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 321, GF_LOG_ERROR, "Assertion failed: " "uuid"
); } while (0); } } while (0)
;
322
323 glusterd_get_lock_owner (&owner);
324
325 if (!uuid_is_null (owner)) {
326 gf_log (this->name, GF_LOG_ERROR, "Unable to get lock"do { do { if (0) printf ("Unable to get lock" " for uuid: %s, lock held by: %s"
, uuid_utoa_r (uuid, new_owner_str), uuid_utoa_r (owner, owner_str
)); } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 329, GF_LOG_ERROR, "Unable to get lock" " for uuid: %s, lock held by: %s"
, uuid_utoa_r (uuid, new_owner_str), uuid_utoa_r (owner, owner_str
)); } while (0)
327 " for uuid: %s, lock held by: %s",do { do { if (0) printf ("Unable to get lock" " for uuid: %s, lock held by: %s"
, uuid_utoa_r (uuid, new_owner_str), uuid_utoa_r (owner, owner_str
)); } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 329, GF_LOG_ERROR, "Unable to get lock" " for uuid: %s, lock held by: %s"
, uuid_utoa_r (uuid, new_owner_str), uuid_utoa_r (owner, owner_str
)); } while (0)
328 uuid_utoa_r (uuid, new_owner_str),do { do { if (0) printf ("Unable to get lock" " for uuid: %s, lock held by: %s"
, uuid_utoa_r (uuid, new_owner_str), uuid_utoa_r (owner, owner_str
)); } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 329, GF_LOG_ERROR, "Unable to get lock" " for uuid: %s, lock held by: %s"
, uuid_utoa_r (uuid, new_owner_str), uuid_utoa_r (owner, owner_str
)); } while (0)
329 uuid_utoa_r (owner, owner_str))do { do { if (0) printf ("Unable to get lock" " for uuid: %s, lock held by: %s"
, uuid_utoa_r (uuid, new_owner_str), uuid_utoa_r (owner, owner_str
)); } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 329, GF_LOG_ERROR, "Unable to get lock" " for uuid: %s, lock held by: %s"
, uuid_utoa_r (uuid, new_owner_str), uuid_utoa_r (owner, owner_str
)); } while (0)
;
330 goto out;
331 }
332
333 ret = glusterd_set_lock_owner (uuid);
334
335 if (!ret) {
336 gf_log (this->name, GF_LOG_DEBUG, "Cluster lock held by"do { do { if (0) printf ("Cluster lock held by" " %s", uuid_utoa
(uuid)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 337, GF_LOG_DEBUG, "Cluster lock held by" " %s"
, uuid_utoa (uuid)); } while (0)
337 " %s", uuid_utoa (uuid))do { do { if (0) printf ("Cluster lock held by" " %s", uuid_utoa
(uuid)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 337, GF_LOG_DEBUG, "Cluster lock held by" " %s"
, uuid_utoa (uuid)); } while (0)
;
338 }
339
340out:
341 return ret;
342}
343
344
345int32_t
346glusterd_unlock (uuid_t uuid)
347{
348 uuid_t owner;
349 char new_owner_str[50];
350 char owner_str[50];
351 int32_t ret = -1;
352 xlator_t *this = NULL((void*)0);
353
354 this = THIS(*__glusterfs_this_location());
355 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 355, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
356
357 GF_ASSERT (uuid)do { if (!(uuid)) { do { do { if (0) printf ("Assertion failed: "
"uuid"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 357, GF_LOG_ERROR, "Assertion failed: " "uuid"
); } while (0); } } while (0)
;
358
359 glusterd_get_lock_owner (&owner);
360
361 if (uuid_is_null (owner)) {
362 gf_log (this->name, GF_LOG_ERROR, "Cluster lock not held!")do { do { if (0) printf ("Cluster lock not held!"); } while (
0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__,
362, GF_LOG_ERROR, "Cluster lock not held!"); } while (0)
;
363 goto out;
364 }
365
366 ret = uuid_compare (uuid, owner);
367
368 if (ret) {
369 gf_log (this->name, GF_LOG_ERROR, "Cluster lock held by %s ,"do { do { if (0) printf ("Cluster lock held by %s ," "unlock req from %s!"
, uuid_utoa_r (owner ,owner_str) , uuid_utoa_r (uuid, new_owner_str
)); } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 371, GF_LOG_ERROR, "Cluster lock held by %s ," "unlock req from %s!"
, uuid_utoa_r (owner ,owner_str) , uuid_utoa_r (uuid, new_owner_str
)); } while (0)
370 "unlock req from %s!", uuid_utoa_r (owner ,owner_str)do { do { if (0) printf ("Cluster lock held by %s ," "unlock req from %s!"
, uuid_utoa_r (owner ,owner_str) , uuid_utoa_r (uuid, new_owner_str
)); } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 371, GF_LOG_ERROR, "Cluster lock held by %s ," "unlock req from %s!"
, uuid_utoa_r (owner ,owner_str) , uuid_utoa_r (uuid, new_owner_str
)); } while (0)
371 , uuid_utoa_r (uuid, new_owner_str))do { do { if (0) printf ("Cluster lock held by %s ," "unlock req from %s!"
, uuid_utoa_r (owner ,owner_str) , uuid_utoa_r (uuid, new_owner_str
)); } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 371, GF_LOG_ERROR, "Cluster lock held by %s ," "unlock req from %s!"
, uuid_utoa_r (owner ,owner_str) , uuid_utoa_r (uuid, new_owner_str
)); } while (0)
;
372 goto out;
373 }
374
375 ret = glusterd_unset_lock_owner (uuid);
376
377 if (ret) {
378 gf_log (this->name, GF_LOG_ERROR, "Unable to clear cluster "do { do { if (0) printf ("Unable to clear cluster " "lock"); }
while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 379, GF_LOG_ERROR, "Unable to clear cluster " "lock"); } while
(0)
379 "lock")do { do { if (0) printf ("Unable to clear cluster " "lock"); }
while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 379, GF_LOG_ERROR, "Unable to clear cluster " "lock"); } while
(0)
;
380 goto out;
381 }
382
383 ret = 0;
384
385out:
386 return ret;
387}
388
389
390int
391glusterd_get_uuid (uuid_t *uuid)
392{
393 glusterd_conf_t *priv = NULL((void*)0);
394
395 priv = THIS(*__glusterfs_this_location())->private;
396
397 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 397, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
398
399 uuid_copy (*uuid, MY_UUID(__glusterd_uuid()));
400
401 return 0;
402}
403
404int
405glusterd_submit_request (struct rpc_clnt *rpc, void *req,
406 call_frame_t *frame, rpc_clnt_prog_t *prog,
407 int procnum, struct iobref *iobref,
408 xlator_t *this, fop_cbk_fn_t cbkfn, xdrproc_t xdrproc)
409{
410 int ret = -1;
411 struct iobuf *iobuf = NULL((void*)0);
412 int count = 0;
413 char new_iobref = 0, start_ping = 0;
414 struct iovec iov = {0, };
415 ssize_t req_size = 0;
416
417 GF_ASSERT (rpc)do { if (!(rpc)) { do { do { if (0) printf ("Assertion failed: "
"rpc"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 417, GF_LOG_ERROR, "Assertion failed: " "rpc"
); } while (0); } } while (0)
;
418 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 418, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
419
420 if (req) {
421 req_size = xdr_sizeof (xdrproc, req);
422 iobuf = iobuf_get2 (this->ctx->iobuf_pool, req_size);
423 if (!iobuf) {
424 goto out;
425 };
426
427 if (!iobref) {
428 iobref = iobref_new ();
429 if (!iobref) {
430 goto out;
431 }
432
433 new_iobref = 1;
434 }
435
436 iobref_add (iobref, iobuf);
437
438 iov.iov_base = iobuf->ptr;
439 iov.iov_len = iobuf_pagesize (iobuf)(iobuf->iobuf_arena->page_size);
440
441 /* Create the xdr payload */
442 ret = xdr_serialize_generic (iov, req, xdrproc);
443 if (ret == -1) {
444 goto out;
445 }
446 iov.iov_len = ret;
447 count = 1;
448 }
449
450 /* Send the msg */
451 ret = rpc_clnt_submit (rpc, prog, procnum, cbkfn,
452 &iov, count,
453 NULL((void*)0), 0, iobref, frame, NULL((void*)0), 0, NULL((void*)0), 0, NULL((void*)0));
454
455 if (ret == 0) {
456 pthread_mutex_lock (&rpc->conn.lock);
457 {
458 if (!rpc->conn.ping_started) {
459 start_ping = 1;
460 }
461 }
462 pthread_mutex_unlock (&rpc->conn.lock);
463 }
464
465 if (start_ping)
466 //client_start_ping ((void *) this);
467
468 ret = 0;
469out:
470 if (new_iobref) {
471 iobref_unref (iobref);
472 }
473
474 iobuf_unref (iobuf);
475
476 return ret;
477}
478
479struct iobuf *
480glusterd_serialize_reply (rpcsvc_request_t *req, void *arg,
481 struct iovec *outmsg, xdrproc_t xdrproc)
482{
483 struct iobuf *iob = NULL((void*)0);
484 ssize_t retlen = -1;
485 ssize_t rsp_size = 0;
486
487 /* First, get the io buffer into which the reply in arg will
488 * be serialized.
489 */
490 rsp_size = xdr_sizeof (xdrproc, arg);
491 iob = iobuf_get2 (req->svc->ctx->iobuf_pool, rsp_size);
492 if (!iob) {
493 gf_log ("", GF_LOG_ERROR, "Failed to get iobuf")do { do { if (0) printf ("Failed to get iobuf"); } while (0);
_gf_log ("", "glusterd-utils.c", __FUNCTION__, 493, GF_LOG_ERROR
, "Failed to get iobuf"); } while (0)
;
494 goto ret;
495 }
496
497 iobuf_to_iovec (iob, outmsg);
498 /* Use the given serializer to translate the give C structure in arg
499 * to XDR format which will be written into the buffer in outmsg.
500 */
501 /* retlen is used to received the error since size_t is unsigned and we
502 * need -1 for error notification during encoding.
503 */
504 retlen = xdr_serialize_generic (*outmsg, arg, xdrproc);
505 if (retlen == -1) {
506 gf_log ("", GF_LOG_ERROR, "Failed to encode message")do { do { if (0) printf ("Failed to encode message"); } while
(0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 506, GF_LOG_ERROR
, "Failed to encode message"); } while (0)
;
507 goto ret;
508 }
509
510 outmsg->iov_len = retlen;
511ret:
512 if (retlen == -1) {
513 iobuf_unref (iob);
514 iob = NULL((void*)0);
515 }
516
517 return iob;
518}
519
520int
521glusterd_submit_reply (rpcsvc_request_t *req, void *arg,
522 struct iovec *payload, int payloadcount,
523 struct iobref *iobref, xdrproc_t xdrproc)
524{
525 struct iobuf *iob = NULL((void*)0);
526 int ret = -1;
527 struct iovec rsp = {0,};
528 char new_iobref = 0;
529
530 if (!req) {
531 GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: "
"req"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 531, GF_LOG_ERROR, "Assertion failed: " "req"
); } while (0); } } while (0)
;
532 goto out;
533 }
534
535 if (!iobref) {
536 iobref = iobref_new ();
537 if (!iobref) {
538 gf_log ("", GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 538, GF_LOG_ERROR, "out of memory"
); } while (0)
;
539 goto out;
540 }
541
542 new_iobref = 1;
543 }
544
545 iob = glusterd_serialize_reply (req, arg, &rsp, xdrproc);
546 if (!iob) {
547 gf_log ("", GF_LOG_ERROR, "Failed to serialize reply")do { do { if (0) printf ("Failed to serialize reply"); } while
(0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 547, GF_LOG_ERROR
, "Failed to serialize reply"); } while (0)
;
548 } else {
549 iobref_add (iobref, iob);
550 }
551
552 ret = rpcsvc_submit_generic (req, &rsp, 1, payload, payloadcount,
553 iobref);
554
555 /* Now that we've done our job of handing the message to the RPC layer
556 * we can safely unref the iob in the hope that RPC layer must have
557 * ref'ed the iob on receiving into the txlist.
558 */
559 if (ret == -1) {
560 gf_log ("", GF_LOG_ERROR, "Reply submission failed")do { do { if (0) printf ("Reply submission failed"); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 560, GF_LOG_ERROR
, "Reply submission failed"); } while (0)
;
561 goto out;
562 }
563
564 ret = 0;
565out:
566
567 if (new_iobref) {
568 iobref_unref (iobref);
569 }
570
571 if (iob)
572 iobuf_unref (iob);
573 return ret;
574}
575
576gf_boolean_t
577glusterd_check_volume_exists (char *volname)
578{
579 char pathname[1024] = {0,};
580 struct stat stbuf = {0,};
581 int32_t ret = -1;
582 glusterd_conf_t *priv = NULL((void*)0);
583
584 priv = THIS(*__glusterfs_this_location())->private;
585
586 snprintf (pathname, 1024, "%s/vols/%s", priv->workdir,
587 volname);
588
589 ret = stat (pathname, &stbuf);
590
591 if (ret) {
592 gf_log (THIS->name, GF_LOG_DEBUG, "Volume %s does not exist."do { do { if (0) printf ("Volume %s does not exist." "stat failed with errno : %d on path: %s"
, volname, (*__errno_location ()), pathname); } while (0); _gf_log
((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 594, GF_LOG_DEBUG, "Volume %s does not exist."
"stat failed with errno : %d on path: %s", volname, (*__errno_location
()), pathname); } while (0)
593 "stat failed with errno : %d on path: %s",do { do { if (0) printf ("Volume %s does not exist." "stat failed with errno : %d on path: %s"
, volname, (*__errno_location ()), pathname); } while (0); _gf_log
((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 594, GF_LOG_DEBUG, "Volume %s does not exist."
"stat failed with errno : %d on path: %s", volname, (*__errno_location
()), pathname); } while (0)
594 volname, errno, pathname)do { do { if (0) printf ("Volume %s does not exist." "stat failed with errno : %d on path: %s"
, volname, (*__errno_location ()), pathname); } while (0); _gf_log
((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 594, GF_LOG_DEBUG, "Volume %s does not exist."
"stat failed with errno : %d on path: %s", volname, (*__errno_location
()), pathname); } while (0)
;
595 return _gf_false;
596 }
597
598 return _gf_true;
599}
600
601int32_t
602glusterd_volinfo_new (glusterd_volinfo_t **volinfo)
603{
604 glusterd_volinfo_t *new_volinfo = NULL((void*)0);
605 int32_t ret = -1;
606
607 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 607, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
608
609 new_volinfo = GF_CALLOC (1, sizeof(*new_volinfo),__gf_calloc (1, sizeof(*new_volinfo), gf_gld_mt_glusterd_volinfo_t
)
610 gf_gld_mt_glusterd_volinfo_t)__gf_calloc (1, sizeof(*new_volinfo), gf_gld_mt_glusterd_volinfo_t
)
;
611
612 if (!new_volinfo)
613 goto out;
614
615 INIT_LIST_HEAD (&new_volinfo->vol_list)do { (&new_volinfo->vol_list)->next = (&new_volinfo
->vol_list)->prev = &new_volinfo->vol_list; } while
(0)
;
616 INIT_LIST_HEAD (&new_volinfo->bricks)do { (&new_volinfo->bricks)->next = (&new_volinfo
->bricks)->prev = &new_volinfo->bricks; } while (
0)
;
617
618 new_volinfo->dict = dict_new ();
619 if (!new_volinfo->dict) {
620 GF_FREE (new_volinfo)__gf_free (new_volinfo);
621
622 goto out;
623 }
624
625 new_volinfo->gsync_slaves = dict_new ();
626 if (!new_volinfo->gsync_slaves) {
627 GF_FREE (new_volinfo)__gf_free (new_volinfo);
628
629 goto out;
630 }
631
632 new_volinfo->xl = THIS(*__glusterfs_this_location());
633
634 *volinfo = new_volinfo;
635
636 ret = 0;
637
638out:
639 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-utils.c"
, __FUNCTION__, 639, GF_LOG_DEBUG, "Returning %d", ret); } while
(0)
;
640 return ret;
641}
642
643void
644glusterd_auth_cleanup (glusterd_volinfo_t *volinfo) {
645
646 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 646, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
647
648 GF_FREE (volinfo->auth.username)__gf_free (volinfo->auth.username);
649
650 GF_FREE (volinfo->auth.password)__gf_free (volinfo->auth.password);
651}
652
653char *
654glusterd_auth_get_username (glusterd_volinfo_t *volinfo) {
655
656 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 656, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
657
658 return volinfo->auth.username;
659}
660
661char *
662glusterd_auth_get_password (glusterd_volinfo_t *volinfo) {
663
664 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 664, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
665
666 return volinfo->auth.password;
667}
668
669int32_t
670glusterd_auth_set_username (glusterd_volinfo_t *volinfo, char *username) {
671
672 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 672, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
673 GF_ASSERT (username)do { if (!(username)) { do { do { if (0) printf ("Assertion failed: "
"username"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 673, GF_LOG_ERROR, "Assertion failed: " "username"
); } while (0); } } while (0)
;
674
675 volinfo->auth.username = gf_strdup (username);
676 return 0;
677}
678
679int32_t
680glusterd_auth_set_password (glusterd_volinfo_t *volinfo, char *password) {
681
682 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 682, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
683 GF_ASSERT (password)do { if (!(password)) { do { do { if (0) printf ("Assertion failed: "
"password"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 683, GF_LOG_ERROR, "Assertion failed: " "password"
); } while (0); } } while (0)
;
684
685 volinfo->auth.password = gf_strdup (password);
686 return 0;
687}
688
689int32_t
690glusterd_brickinfo_delete (glusterd_brickinfo_t *brickinfo)
691{
692 int32_t ret = -1;
693
694 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 694, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
695
696 list_del_init (&brickinfo->brick_list);
697
698 GF_FREE (brickinfo->logfile)__gf_free (brickinfo->logfile);
699 GF_FREE (brickinfo)__gf_free (brickinfo);
700
701 ret = 0;
702
703 return ret;
704}
705
706int32_t
707glusterd_volume_brickinfos_delete (glusterd_volinfo_t *volinfo)
708{
709 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
710 glusterd_brickinfo_t *tmp = NULL((void*)0);
711 int32_t ret = 0;
712
713 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 713, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
714
715 list_for_each_entry_safe (brickinfo, tmp, &volinfo->bricks,for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo
->bricks)->next)-(unsigned long)(&((typeof(*brickinfo
) *)0)->brick_list))), tmp = ((typeof(*brickinfo) *)((char
*)(brickinfo->brick_list.next)-(unsigned long)(&((typeof
(*brickinfo) *)0)->brick_list))); &brickinfo->brick_list
!= (&volinfo->bricks); brickinfo = tmp, tmp = ((typeof
(*tmp) *)((char *)(tmp->brick_list.next)-(unsigned long)(&
((typeof(*tmp) *)0)->brick_list))))
716 brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo
->bricks)->next)-(unsigned long)(&((typeof(*brickinfo
) *)0)->brick_list))), tmp = ((typeof(*brickinfo) *)((char
*)(brickinfo->brick_list.next)-(unsigned long)(&((typeof
(*brickinfo) *)0)->brick_list))); &brickinfo->brick_list
!= (&volinfo->bricks); brickinfo = tmp, tmp = ((typeof
(*tmp) *)((char *)(tmp->brick_list.next)-(unsigned long)(&
((typeof(*tmp) *)0)->brick_list))))
{
717 ret = glusterd_brickinfo_delete (brickinfo);
718 if (ret)
719 goto out;
720 }
721
722out:
723 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-utils.c"
, __FUNCTION__, 723, GF_LOG_DEBUG, "Returning %d", ret); } while
(0)
;
724 return ret;
725}
726
727int32_t
728glusterd_volinfo_delete (glusterd_volinfo_t *volinfo)
729{
730 int32_t ret = -1;
731
732 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 732, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
733
734 list_del_init (&volinfo->vol_list);
735
736 ret = glusterd_volume_brickinfos_delete (volinfo);
737 if (ret)
738 goto out;
739 if (volinfo->dict)
740 dict_unref (volinfo->dict);
741 if (volinfo->gsync_slaves)
742 dict_unref (volinfo->gsync_slaves);
743 GF_FREE (volinfo->logdir)__gf_free (volinfo->logdir);
744
745 glusterd_auth_cleanup (volinfo);
746
747 GF_FREE (volinfo)__gf_free (volinfo);
748 ret = 0;
749
750out:
751 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-utils.c"
, __FUNCTION__, 751, GF_LOG_DEBUG, "Returning %d", ret); } while
(0)
;
752 return ret;
753}
754
755
756int32_t
757glusterd_brickinfo_new (glusterd_brickinfo_t **brickinfo)
758{
759 glusterd_brickinfo_t *new_brickinfo = NULL((void*)0);
760 int32_t ret = -1;
761
762 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 762, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
763
764 new_brickinfo = GF_CALLOC (1, sizeof(*new_brickinfo),__gf_calloc (1, sizeof(*new_brickinfo), gf_gld_mt_glusterd_brickinfo_t
)
765 gf_gld_mt_glusterd_brickinfo_t)__gf_calloc (1, sizeof(*new_brickinfo), gf_gld_mt_glusterd_brickinfo_t
)
;
766
767 if (!new_brickinfo)
768 goto out;
769
770 INIT_LIST_HEAD (&new_brickinfo->brick_list)do { (&new_brickinfo->brick_list)->next = (&new_brickinfo
->brick_list)->prev = &new_brickinfo->brick_list
; } while (0)
;
771
772 *brickinfo = new_brickinfo;
773
774 ret = 0;
775
776out:
777 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-utils.c"
, __FUNCTION__, 777, GF_LOG_DEBUG, "Returning %d", ret); } while
(0)
;
778 return ret;
779}
780
781int32_t
782glusterd_resolve_brick (glusterd_brickinfo_t *brickinfo)
783{
784 int32_t ret = -1;
785 xlator_t *this = NULL((void*)0);
786
787 this = THIS(*__glusterfs_this_location());
788 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 788, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
789
790 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 790, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
791
792 ret = glusterd_hostname_to_uuid (brickinfo->hostname, brickinfo->uuid);
793 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-utils.c", __FUNCTION__, 793, GF_LOG_DEBUG
, "Returning %d", ret); } while (0)
;
794 return ret;
795}
796
797int32_t
798glusterd_brickinfo_new_from_brick (char *brick,
799 glusterd_brickinfo_t **brickinfo)
800{
801 int32_t ret = -1;
802 glusterd_brickinfo_t *new_brickinfo = NULL((void*)0);
803 char *hostname = NULL((void*)0);
804 char *path = NULL((void*)0);
805 char *tmp_host = NULL((void*)0);
806 char *tmp_path = NULL((void*)0);
807
808 GF_ASSERT (brick)do { if (!(brick)) { do { do { if (0) printf ("Assertion failed: "
"brick"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 808, GF_LOG_ERROR, "Assertion failed: " "brick"
); } while (0); } } while (0)
;
809 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 809, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
810
811 tmp_host = gf_strdup (brick);
812 if (tmp_host && !get_host_name (tmp_host, &hostname))
813 goto out;
814 tmp_path = gf_strdup (brick);
815 if (tmp_path && !get_path_name (tmp_path, &path))
816 goto out;
817
818 GF_ASSERT (hostname)do { if (!(hostname)) { do { do { if (0) printf ("Assertion failed: "
"hostname"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 818, GF_LOG_ERROR, "Assertion failed: " "hostname"
); } while (0); } } while (0)
;
819 GF_ASSERT (path)do { if (!(path)) { do { do { if (0) printf ("Assertion failed: "
"path"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 819, GF_LOG_ERROR, "Assertion failed: " "path"
); } while (0); } } while (0)
;
820
821 ret = glusterd_brickinfo_new (&new_brickinfo);
822 if (ret)
823 goto out;
824
825 ret = gf_canonicalize_path (path);
826 if (ret)
827 goto out;
828
829 strncpy (new_brickinfo->hostname, hostname, 1024);
830 strncpy (new_brickinfo->path, path, 1024);
831
832 *brickinfo = new_brickinfo;
833
834 ret = 0;
835out:
836 GF_FREE (tmp_host)__gf_free (tmp_host);
837 if (tmp_host)
838 GF_FREE (tmp_path)__gf_free (tmp_path);
839 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-utils.c"
, __FUNCTION__, 839, GF_LOG_DEBUG, "Returning %d", ret); } while
(0)
;
840 return ret;
841}
842
843static gf_boolean_t
844_is_prefix (char *str1, char *str2)
845{
846 GF_ASSERT (str1)do { if (!(str1)) { do { do { if (0) printf ("Assertion failed: "
"str1"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 846, GF_LOG_ERROR, "Assertion failed: " "str1"
); } while (0); } } while (0)
;
847 GF_ASSERT (str2)do { if (!(str2)) { do { do { if (0) printf ("Assertion failed: "
"str2"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 847, GF_LOG_ERROR, "Assertion failed: " "str2"
); } while (0); } } while (0)
;
848
849 int i = 0;
850 int len1 = 0;
851 int len2 = 0;
852 int small_len = 0;
853 char *bigger = NULL((void*)0);
854 gf_boolean_t prefix = _gf_true;
855
856 len1 = strlen (str1);
857 len2 = strlen (str2);
858 small_len = min (len1, len2)((len1)<(len2)?(len1):(len2));
859 for (i = 0; i < small_len; i++) {
860 if (str1[i] != str2[i]) {
861 prefix = _gf_false;
862 break;
863 }
864 }
865
866 if (len1 < len2)
867 bigger = str2;
868
869 else if (len1 > len2)
870 bigger = str1;
871
872 else
873 return prefix;
874
875 if (bigger[small_len] != '/')
876 prefix = _gf_false;
877
878 return prefix;
879}
880
881/* Checks if @path is available in the peer identified by @uuid
882 * 'availability' is determined by querying current state of volumes
883 * in the cluster. */
884gf_boolean_t
885glusterd_is_brickpath_available (uuid_t uuid, char *path)
886{
887 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
888 glusterd_volinfo_t *volinfo = NULL((void*)0);
889 glusterd_conf_t *priv = NULL((void*)0);
890 gf_boolean_t available = _gf_false;
891 char tmp_path[PATH_MAX4096+1] = {0};
892 char tmp_brickpath[PATH_MAX4096+1] = {0};
893
894 priv = THIS(*__glusterfs_this_location())->private;
895
896 strncpy (tmp_path, path, PATH_MAX4096);
897 /* path may not yet exist */
898 if (!realpath (path, tmp_path)) {
899 if (errno(*__errno_location ()) != ENOENT2) {
900 goto out;
901 }
902 /* When realpath(3) fails, tmp_path is undefined. */
903 strncpy(tmp_path,path,PATH_MAX4096);
904 }
905
906 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))))
{
907 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))))
{
908 if (uuid_compare (uuid, brickinfo->uuid))
909 continue;
910
911 if (!realpath (brickinfo->path, tmp_brickpath)) {
912 if (errno(*__errno_location ()) == ENOENT2)
913 strncpy (tmp_brickpath, brickinfo->path,
914 PATH_MAX4096);
915 else
916 goto out;
917 }
918
919 if (_is_prefix (tmp_brickpath, tmp_path))
920 goto out;
921 }
922 }
923 available = _gf_true;
924out:
925 return available;
926}
927
928int
929glusterd_validate_and_create_brickpath (glusterd_brickinfo_t *brickinfo,
930 uuid_t volume_id, char **op_errstr,
931 gf_boolean_t is_force)
932{
933 int ret = -1;
934 char parentdir[PATH_MAX4096] = {0,};
935 struct stat parent_st = {0,};
936 struct stat brick_st = {0,};
937 struct stat root_st = {0,};
938 char msg[2048] = {0,};
939 gf_boolean_t is_created = _gf_false;
940
941 ret = mkdir (brickinfo->path, 0777);
942 if (ret) {
943 if (errno(*__errno_location ()) != EEXIST17) {
944 snprintf (msg, sizeof (msg), "Failed to create brick "
945 "directory for brick %s:%s. Reason : %s ",
946 brickinfo->hostname, brickinfo->path,
947 strerror (errno(*__errno_location ())));
948 goto out;
949 }
950 } else {
951 is_created = _gf_true;
952 }
953
954 ret = lstat (brickinfo->path, &brick_st);
955 if (ret) {
956 snprintf (msg, sizeof (msg), "lstat failed on %s. Reason : %s",
957 brickinfo->path, strerror (errno(*__errno_location ())));
958 goto out;
959 }
960
961 if ((!is_created) && (!S_ISDIR (brick_st.st_mode)((((brick_st.st_mode)) & 0170000) == (0040000)))) {
962 snprintf (msg, sizeof (msg), "The provided path %s which is "
963 "already present, is not a directory",
964 brickinfo->path);
965 ret = -1;
966 goto out;
967 }
968
969 snprintf (parentdir, sizeof (parentdir), "%s/..", brickinfo->path);
970
971 ret = lstat ("/", &root_st);
972 if (ret) {
973 snprintf (msg, sizeof (msg), "lstat failed on /. Reason : %s",
974 strerror (errno(*__errno_location ())));
975 goto out;
976 }
977
978 ret = lstat (parentdir, &parent_st);
979 if (ret) {
980 snprintf (msg, sizeof (msg), "lstat failed on %s. Reason : %s",
981 parentdir, strerror (errno(*__errno_location ())));
982 goto out;
983 }
984
985 if (!is_force) {
986 if (brick_st.st_dev != parent_st.st_dev) {
987 snprintf (msg, sizeof (msg), "The brick %s:%s is a "
988 "mount point. Please create a sub-directory "
989 "under the mount point and use that as the "
990 "brick directory. Or use 'force' at the end "
991 "of the command if you want to override this "
992 "behavior.", brickinfo->hostname,
993 brickinfo->path);
994 ret = -1;
995 goto out;
996 }
997 else if (parent_st.st_dev == root_st.st_dev) {
998 snprintf (msg, sizeof (msg), "The brick %s:%s is "
999 "is being created in the root partition. It "
1000 "is recommended that you don't use the "
1001 "system's root partition for storage backend."
1002 " Or use 'force' at the end of the command if"
1003 " you want to override this behavior.",
1004 brickinfo->hostname, brickinfo->path);
1005 ret = -1;
1006 goto out;
1007 }
1008 }
1009
1010 ret = glusterd_check_and_set_brick_xattr (brickinfo->hostname,
1011 brickinfo->path, volume_id,
1012 op_errstr);
1013 if (ret)
1014 goto out;
1015
1016 ret = 0;
1017
1018out:
1019 if (ret && is_created)
1020 rmdir (brickinfo->path);
1021 if (ret && !*op_errstr && msg[0] != '\0')
1022 *op_errstr = gf_strdup (msg);
1023
1024 return ret;
1025}
1026
1027int32_t
1028glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path,
1029 glusterd_volinfo_t *volinfo,
1030 glusterd_brickinfo_t **brickinfo)
1031{
1032 glusterd_brickinfo_t *brickiter = NULL((void*)0);
1033 uuid_t peer_uuid = {0};
1034 int32_t ret = -1;
1035 xlator_t *this = NULL((void*)0);
1036
1037 this = THIS(*__glusterfs_this_location());
1038
1039 if (uuid) {
1040 uuid_copy (peer_uuid, uuid);
1041 } else {
1042 ret = glusterd_hostname_to_uuid (hostname, peer_uuid);
1043 if (ret)
1044 goto out;
1045 }
1046 ret = -1;
1047 list_for_each_entry (brickiter, &volinfo->bricks, brick_list)for (brickiter = ((typeof(*brickiter) *)((char *)((&volinfo
->bricks)->next)-(unsigned long)(&((typeof(*brickiter
) *)0)->brick_list))); &brickiter->brick_list != (&
volinfo->bricks); brickiter = ((typeof(*brickiter) *)((char
*)(brickiter->brick_list.next)-(unsigned long)(&((typeof
(*brickiter) *)0)->brick_list))))
{
1048
1049 if ((uuid_is_null (brickiter->uuid)) &&
1050 (glusterd_resolve_brick (brickiter) != 0))
1051 goto out;
1052 if (uuid_compare (peer_uuid, brickiter->uuid))
1053 continue;
1054
1055 if (strcmp (brickiter->path, path) == 0) {
1056 gf_log (this->name, GF_LOG_DEBUG, LOGSTR_FOUND_BRICK,do { do { if (0) printf ("Found brick %s:%s in volume %s", brickiter
->hostname, brickiter->path, volinfo->volname); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 1058, GF_LOG_DEBUG, "Found brick %s:%s in volume %s", brickiter
->hostname, brickiter->path, volinfo->volname); } while
(0)
1057 brickiter->hostname, brickiter->path,do { do { if (0) printf ("Found brick %s:%s in volume %s", brickiter
->hostname, brickiter->path, volinfo->volname); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 1058, GF_LOG_DEBUG, "Found brick %s:%s in volume %s", brickiter
->hostname, brickiter->path, volinfo->volname); } while
(0)
1058 volinfo->volname)do { do { if (0) printf ("Found brick %s:%s in volume %s", brickiter
->hostname, brickiter->path, volinfo->volname); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 1058, GF_LOG_DEBUG, "Found brick %s:%s in volume %s", brickiter
->hostname, brickiter->path, volinfo->volname); } while
(0)
;
1059 ret = 0;
1060 if (brickinfo)
1061 *brickinfo = brickiter;
1062 break;
1063 }
1064 }
1065
1066out:
1067 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-utils.c", __FUNCTION__, 1067, GF_LOG_DEBUG
, "Returning %d", ret); } while (0)
;
1068 return ret;
1069}
1070
1071int32_t
1072glusterd_volume_brickinfo_get_by_brick (char *brick,
1073 glusterd_volinfo_t *volinfo,
1074 glusterd_brickinfo_t **brickinfo)
1075{
1076 int32_t ret = -1;
1077 glusterd_brickinfo_t *tmp_brickinfo = NULL((void*)0);
1078
1079 GF_ASSERT (brick)do { if (!(brick)) { do { do { if (0) printf ("Assertion failed: "
"brick"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1079, GF_LOG_ERROR, "Assertion failed: " "brick"
); } while (0); } } while (0)
;
1080 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1080, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
1081
1082 ret = glusterd_brickinfo_new_from_brick (brick, &tmp_brickinfo);
1083 if (ret)
1084 goto out;
1085
1086 ret = glusterd_volume_brickinfo_get (NULL((void*)0), tmp_brickinfo->hostname,
1087 tmp_brickinfo->path, volinfo,
1088 brickinfo);
1089 (void) glusterd_brickinfo_delete (tmp_brickinfo);
1090out:
1091 gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 1091, GF_LOG_DEBUG, "Returning %d"
, ret); } while (0)
;
1092 return ret;
1093}
1094
1095gf_boolean_t
1096glusterd_is_brick_decommissioned (glusterd_volinfo_t *volinfo, char *hostname,
1097 char *path)
1098{
1099 gf_boolean_t decommissioned = _gf_false;
1100 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
1101 int ret = -1;
1102
1103 ret = glusterd_volume_brickinfo_get (NULL((void*)0), hostname, path, volinfo,
1104 &brickinfo);
1105 if (ret)
1106 goto out;
1107 decommissioned = brickinfo->decommissioned;
1108out:
1109 return decommissioned;
1110}
1111
1112int32_t
1113glusterd_friend_cleanup (glusterd_peerinfo_t *peerinfo)
1114{
1115 GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: "
"peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1115, GF_LOG_ERROR, "Assertion failed: " "peerinfo"
); } while (0); } } while (0)
;
1116 glusterd_peerctx_t *peerctx = NULL((void*)0);
1117 gf_boolean_t quorum_action = _gf_false;
1118
1119 if (peerinfo->quorum_contrib != QUORUM_NONE)
12
Taking true branch
1120 quorum_action = _gf_true;
1121 if (peerinfo->rpc) {
13
Taking false branch
1122 /* cleanup the saved-frames before last unref */
1123 rpc_clnt_connection_cleanup (&peerinfo->rpc->conn);
1124
1125 peerctx = peerinfo->rpc->mydata;
1126 peerinfo->rpc->mydata = NULL((void*)0);
1127 peerinfo->rpc = rpc_clnt_unref (peerinfo->rpc);
1128 peerinfo->rpc = NULL((void*)0);
1129 if (peerctx) {
1130 GF_FREE (peerctx->errstr)__gf_free (peerctx->errstr);
1131 GF_FREE (peerctx)__gf_free (peerctx);
1132 }
1133 }
1134 glusterd_peer_destroy (peerinfo);
1135
1136 if (quorum_action)
14
Taking true branch
1137 glusterd_do_quorum_action ();
15
Calling 'glusterd_do_quorum_action'
1138 return 0;
1139}
1140
1141int32_t
1142glusterd_volinfo_find (char *volname, glusterd_volinfo_t **volinfo)
1143{
1144 glusterd_volinfo_t *tmp_volinfo = NULL((void*)0);
1145 int32_t ret = -1;
1146 xlator_t *this = NULL((void*)0);
1147 glusterd_conf_t *priv = NULL((void*)0);
1148
1149 GF_ASSERT (volname)do { if (!(volname)) { do { do { if (0) printf ("Assertion failed: "
"volname"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1149, GF_LOG_ERROR, "Assertion failed: " "volname"
); } while (0); } } while (0)
;
1150
1151 this = THIS(*__glusterfs_this_location());
1152 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1152, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
1153
1154 priv = this->private;
1155 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1155, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
1156
1157 list_for_each_entry (tmp_volinfo, &priv->volumes, vol_list)for (tmp_volinfo = ((typeof(*tmp_volinfo) *)((char *)((&priv
->volumes)->next)-(unsigned long)(&((typeof(*tmp_volinfo
) *)0)->vol_list))); &tmp_volinfo->vol_list != (&
priv->volumes); tmp_volinfo = ((typeof(*tmp_volinfo) *)((char
*)(tmp_volinfo->vol_list.next)-(unsigned long)(&((typeof
(*tmp_volinfo) *)0)->vol_list))))
{
1158 if (!strcmp (tmp_volinfo->volname, volname)) {
1159 gf_log (this->name, GF_LOG_DEBUG, "Volume %s found", volname)do { do { if (0) printf ("Volume %s found", volname); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 1159, GF_LOG_DEBUG, "Volume %s found", volname); } while (0
)
;
1160 ret = 0;
1161 *volinfo = tmp_volinfo;
1162 break;
1163 }
1164 }
1165
1166 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-utils.c", __FUNCTION__, 1166, GF_LOG_DEBUG
, "Returning %d", ret); } while (0)
;
1167 return ret;
1168}
1169
1170int32_t
1171glusterd_service_stop (const char *service, char *pidfile, int sig,
1172 gf_boolean_t force_kill)
1173{
1174 int32_t ret = -1;
1175 pid_t pid = -1;
1176 xlator_t *this = NULL((void*)0);
1177
1178 this = THIS(*__glusterfs_this_location());
1179 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1179, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
1180 if (!glusterd_is_service_running (pidfile, &pid)) {
1181 ret = 0;
1182 gf_log (this->name, GF_LOG_INFO, "%s already stopped", service)do { do { if (0) printf ("%s already stopped", service); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 1182, GF_LOG_INFO, "%s already stopped", service); } while (
0)
;
1183 goto out;
1184 }
1185 gf_log (this->name, GF_LOG_DEBUG, "Stopping gluster %s running in pid: "do { do { if (0) printf ("Stopping gluster %s running in pid: "
"%d", service, pid); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 1186, GF_LOG_DEBUG, "Stopping gluster %s running in pid: "
"%d", service, pid); } while (0)
1186 "%d", service, pid)do { do { if (0) printf ("Stopping gluster %s running in pid: "
"%d", service, pid); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 1186, GF_LOG_DEBUG, "Stopping gluster %s running in pid: "
"%d", service, pid); } while (0)
;
1187
1188 ret = kill (pid, sig);
1189 if (!force_kill)
1190 goto out;
1191
1192 sleep (1);
1193 if (glusterd_is_service_running (pidfile, NULL((void*)0))) {
1194 ret = kill (pid, SIGKILL9);
1195 if (ret) {
1196 gf_log (this->name, GF_LOG_ERROR, "Unable to "do { do { if (0) printf ("Unable to " "kill pid %d reason: %s"
, pid, strerror((*__errno_location ()))); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 1198, GF_LOG_ERROR
, "Unable to " "kill pid %d reason: %s", pid, strerror((*__errno_location
()))); } while (0)
1197 "kill pid %d reason: %s", pid,do { do { if (0) printf ("Unable to " "kill pid %d reason: %s"
, pid, strerror((*__errno_location ()))); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 1198, GF_LOG_ERROR
, "Unable to " "kill pid %d reason: %s", pid, strerror((*__errno_location
()))); } while (0)
1198 strerror(errno))do { do { if (0) printf ("Unable to " "kill pid %d reason: %s"
, pid, strerror((*__errno_location ()))); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 1198, GF_LOG_ERROR
, "Unable to " "kill pid %d reason: %s", pid, strerror((*__errno_location
()))); } while (0)
;
1199 goto out;
1200 }
1201 }
1202
1203 ret = 0;
1204out:
1205 return ret;
1206}
1207
1208void
1209glusterd_set_socket_filepath (char *sock_filepath, char *sockpath, size_t len)
1210{
1211 char md5_sum[MD5_DIGEST_LENGTH16*2+1] = {0,};
1212
1213 md5_wrapper ((unsigned char *) sock_filepath, strlen(sock_filepath), md5_sum);
1214 snprintf (sockpath, len, "%s/%s.socket", GLUSTERD_SOCK_DIR"/var/run", md5_sum);
1215}
1216
1217void
1218glusterd_set_brick_socket_filepath (glusterd_volinfo_t *volinfo,
1219 glusterd_brickinfo_t *brickinfo,
1220 char *sockpath, size_t len)
1221{
1222 char export_path[PATH_MAX4096] = {0,};
1223 char sock_filepath[PATH_MAX4096] = {0,};
1224 char volume_dir[PATH_MAX4096] = {0,};
1225 xlator_t *this = NULL((void*)0);
1226 glusterd_conf_t *priv = NULL((void*)0);
1227 int expected_file_len = 0;
1228
1229 expected_file_len = strlen (GLUSTERD_SOCK_DIR"/var/run") + strlen ("/") +
1230 MD5_DIGEST_LENGTH16*2 + strlen (".socket") + 1;
1231 GF_ASSERT (len >= expected_file_len)do { if (!(len >= expected_file_len)) { do { do { if (0) printf
("Assertion failed: " "len >= expected_file_len"); } while
(0); _gf_log_callingfn ("", "glusterd-utils.c", __FUNCTION__
, 1231, GF_LOG_ERROR, "Assertion failed: " "len >= expected_file_len"
); } while (0); } } while (0)
;
1232 this = THIS(*__glusterfs_this_location());
1233 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1233, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
1234
1235 priv = this->private;
1236
1237 GLUSTERD_GET_VOLUME_DIR (volume_dir, volinfo, priv)snprintf (volume_dir, 4096, "%s/vols/%s", priv->workdir, volinfo
->volname);
;
1238 GLUSTERD_REMOVE_SLASH_FROM_PATH (brickinfo->path, export_path)do { int i = 0; for (i = 1; i < strlen (brickinfo->path
); i++) { export_path[i-1] = brickinfo->path[i]; if (export_path
[i-1] == '/') export_path[i-1] = '-'; } } while (0)
;
1239 snprintf (sock_filepath, PATH_MAX4096, "%s/run/%s-%s",
1240 volume_dir, brickinfo->hostname, export_path);
1241
1242 glusterd_set_socket_filepath (sock_filepath, sockpath, len);
1243}
1244
1245/* connection happens only if it is not aleady connected,
1246 * reconnections are taken care by rpc-layer
1247 */
1248int32_t
1249glusterd_brick_connect (glusterd_volinfo_t *volinfo,
1250 glusterd_brickinfo_t *brickinfo)
1251{
1252 int ret = 0;
1253 char socketpath[PATH_MAX4096] = {0};
1254 dict_t *options = NULL((void*)0);
1255 struct rpc_clnt *rpc = NULL((void*)0);
1256 glusterd_conf_t *priv = THIS(*__glusterfs_this_location())->private;
1257
1258 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1258, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
1259 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1259, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
1260
1261 if (brickinfo->rpc == NULL((void*)0)) {
1262 glusterd_set_brick_socket_filepath (volinfo, brickinfo,
1263 socketpath,
1264 sizeof (socketpath));
1265
1266 /* Setting frame-timeout to 10mins (600seconds).
1267 * Unix domain sockets ensures that the connection is reliable.
1268 * The default timeout of 30mins used for unreliable network
1269 * connections is too long for unix domain socket connections.
1270 */
1271 ret = rpc_clnt_transport_unix_options_build (&options,
1272 socketpath, 600);
1273 if (ret)
1274 goto out;
1275 synclock_unlock (&priv->big_lock);
1276 ret = glusterd_rpc_create (&rpc, options,
1277 glusterd_brick_rpc_notify,
1278 brickinfo);
1279 synclock_lock (&priv->big_lock);
1280 if (ret)
1281 goto out;
1282 brickinfo->rpc = rpc;
1283 }
1284out:
1285 gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 1285, GF_LOG_DEBUG, "Returning %d"
, ret); } while (0)
;
1286 return ret;
1287}
1288
1289/* Caller should ensure that brick process is not running*/
1290static void
1291_reap_brick_process (char *pidfile, char *brickpath)
1292{
1293 unlink (pidfile);
1294 /* Brick process is not running and pmap may have an entry for it.*/
1295 pmap_registry_remove (THIS(*__glusterfs_this_location()), 0, brickpath,
1296 GF_PMAP_PORT_BRICKSERVER, NULL((void*)0));
1297}
1298
1299static int
1300_mk_rundir_p (glusterd_volinfo_t *volinfo)
1301{
1302 char voldir[PATH_MAX4096] = {0,};
1303 char rundir[PATH_MAX4096] = {0,};
1304 glusterd_conf_t *priv = NULL((void*)0);
1305 xlator_t *this = NULL((void*)0);
1306 int ret = -1;
1307
1308 this = THIS(*__glusterfs_this_location());
1309 priv = this->private;
1310 GLUSTERD_GET_VOLUME_DIR (voldir, volinfo, priv)snprintf (voldir, 4096, "%s/vols/%s", priv->workdir, volinfo
->volname);
;
1311 snprintf (rundir, sizeof (rundir)-1, "%s/run", voldir);
1312 ret = mkdir_p (rundir, 0777, _gf_true);
1313 if (ret)
1314 gf_log (this->name, GF_LOG_ERROR, "Failed to create rundir")do { do { if (0) printf ("Failed to create rundir"); } while (
0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__,
1314, GF_LOG_ERROR, "Failed to create rundir"); } while (0)
;
1315 return ret;
1316}
1317
1318int32_t
1319glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
1320 glusterd_brickinfo_t *brickinfo,
1321 gf_boolean_t wait)
1322{
1323 int32_t ret = -1;
1324 xlator_t *this = NULL((void*)0);
1325 glusterd_conf_t *priv = NULL((void*)0);
1326 char pidfile[PATH_MAX4096+1] = {0,};
1327 char volfile[PATH_MAX4096] = {0,};
1328 runner_t runner = {0,};
1329 char exp_path[PATH_MAX4096] = {0,};
1330 char logfile[PATH_MAX4096] = {0,};
1331 int port = 0;
1332 int rdma_port = 0;
1333 char socketpath[PATH_MAX4096] = {0};
1334 char glusterd_uuid[1024] = {0,};
1335 char valgrind_logfile[PATH_MAX4096] = {0};
1336
1337 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1337, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
1338 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1338, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
1339
1340 this = THIS(*__glusterfs_this_location());
1341 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1341, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
1342
1343 priv = this->private;
1344 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1344, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
1345
1346 ret = _mk_rundir_p (volinfo);
1347 if (ret)
1348 goto out;
1349 GLUSTERD_GET_BRICK_PIDFILE (pidfile, volinfo, brickinfo, priv)do { char exp_path[4096] = {0,}; char volpath[4096] = {0,}; snprintf
(volpath, 4096, "%s/vols/%s", priv->workdir, volinfo->
volname);; do { int i = 0; for (i = 1; i < strlen (brickinfo
->path); i++) { exp_path[i-1] = brickinfo->path[i]; if (
exp_path[i-1] == '/') exp_path[i-1] = '-'; } } while (0); snprintf
(pidfile, 4096, "%s/run/%s-%s.pid", volpath, brickinfo->hostname
, exp_path); } while (0)
;
1350 if (glusterd_is_service_running (pidfile, NULL((void*)0)))
1351 goto connect;
1352
1353 _reap_brick_process (pidfile, brickinfo->path);
1354
1355 port = brickinfo->port;
1356 if (!port)
1357 port = pmap_registry_alloc (THIS(*__glusterfs_this_location()));
1358
1359 runinit (&runner);
1360
1361 if (priv->valgrind) {
1362 /* Run bricks with valgrind */
1363 if (volinfo->logdir) {
1364 snprintf (valgrind_logfile, PATH_MAX4096,
1365 "%s/valgrind-%s-%s.log",
1366 volinfo->logdir,
1367 volinfo->volname, exp_path);
1368 } else {
1369 snprintf (valgrind_logfile, PATH_MAX4096,
1370 "%s/bricks/valgrind-%s-%s.log",
1371 DEFAULT_LOG_FILE_DIRECTORY"/usr/local/var" "/log/glusterfs",
1372 volinfo->volname, exp_path);
1373 }
1374
1375 runner_add_args (&runner, "valgrind", "--leak-check=full",
1376 "--trace-children=yes", "--track-origins=yes",
1377 NULL((void*)0));
1378 runner_argprintf (&runner, "--log-file=%s", valgrind_logfile);
1379 }
1380
1381 GLUSTERD_REMOVE_SLASH_FROM_PATH (brickinfo->path, exp_path)do { int i = 0; for (i = 1; i < strlen (brickinfo->path
); i++) { exp_path[i-1] = brickinfo->path[i]; if (exp_path
[i-1] == '/') exp_path[i-1] = '-'; } } while (0)
;
1382 snprintf (volfile, PATH_MAX4096, "%s.%s.%s", volinfo->volname,
1383 brickinfo->hostname, exp_path);
1384
1385 if (volinfo->logdir) {
1386 snprintf (logfile, PATH_MAX4096, "%s/%s.log",
1387 volinfo->logdir, exp_path);
1388 } else {
1389 snprintf (logfile, PATH_MAX4096, "%s/bricks/%s.log",
1390 DEFAULT_LOG_FILE_DIRECTORY"/usr/local/var" "/log/glusterfs", exp_path);
1391 }
1392 if (!brickinfo->logfile)
1393 brickinfo->logfile = gf_strdup (logfile);
1394
1395 glusterd_set_brick_socket_filepath (volinfo, brickinfo, socketpath,
1396 sizeof (socketpath));
1397
1398 (void) snprintf (glusterd_uuid, 1024, "*-posix.glusterd-uuid=%s",
1399 uuid_utoa (MY_UUID(__glusterd_uuid())));
1400 runner_add_args (&runner, SBIN_DIR"/usr/local/sbin""/glusterfsd",
1401 "-s", brickinfo->hostname, "--volfile-id", volfile,
1402 "-p", pidfile, "-S", socketpath,
1403 "--brick-name", brickinfo->path,
1404 "-l", brickinfo->logfile,
1405 "--xlator-option", glusterd_uuid,
1406 NULL((void*)0));
1407
1408 runner_add_arg (&runner, "--brick-port");
1409 if (volinfo->transport_type != GF_TRANSPORT_BOTH_TCP_RDMA) {
1410 runner_argprintf (&runner, "%d", port);
1411 } else {
1412 rdma_port = brickinfo->rdma_port;
1413 if (!rdma_port)
1414 rdma_port = pmap_registry_alloc (THIS(*__glusterfs_this_location()));
1415 runner_argprintf (&runner, "%d,%d", port, rdma_port);
1416 runner_add_arg (&runner, "--xlator-option");
1417 runner_argprintf (&runner, "%s-server.transport.rdma.listen-port=%d",
1418 volinfo->volname, rdma_port);
1419 }
1420
1421 runner_add_arg (&runner, "--xlator-option");
1422 runner_argprintf (&runner, "%s-server.listen-port=%d",
1423 volinfo->volname, port);
1424
1425 if (volinfo->memory_accounting)
1426 runner_add_arg (&runner, "--mem-accounting");
1427
1428 runner_log (&runner, "", GF_LOG_DEBUG, "Starting GlusterFS");
1429 if (wait) {
1430 synclock_unlock (&priv->big_lock);
1431 ret = runner_run (&runner);
1432 synclock_lock (&priv->big_lock);
1433
1434 } else {
1435 ret = runner_run_nowait (&runner);
1436 }
1437
1438 if (ret)
1439 goto out;
1440
1441 brickinfo->port = port;
1442 brickinfo->rdma_port = rdma_port;
1443
1444connect:
1445 ret = glusterd_brick_connect (volinfo, brickinfo);
1446 if (ret)
1447 goto out;
1448out:
1449 return ret;
1450}
1451
1452int32_t
1453glusterd_brick_unlink_socket_file (glusterd_volinfo_t *volinfo,
1454 glusterd_brickinfo_t *brickinfo)
1455{
1456 char path[PATH_MAX4096] = {0,};
1457 char socketpath[PATH_MAX4096] = {0};
1458 xlator_t *this = NULL((void*)0);
1459 glusterd_conf_t *priv = NULL((void*)0);
1460 int ret = 0;
1461
1462 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1462, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
1463 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1463, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
1464
1465 this = THIS(*__glusterfs_this_location());
1466 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1466, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
1467
1468 priv = this->private;
1469 GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv)snprintf (path, 4096, "%s/vols/%s", priv->workdir, volinfo
->volname);
;
1470 glusterd_set_brick_socket_filepath (volinfo, brickinfo, socketpath,
1471 sizeof (socketpath));
1472 ret = unlink (socketpath);
1473 if (ret && (ENOENT2 == errno(*__errno_location ()))) {
1474 ret = 0;
1475 } else {
1476 gf_log (this->name, GF_LOG_ERROR, "Failed to remove %s"do { do { if (0) printf ("Failed to remove %s" " error: %s", socketpath
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 1477, GF_LOG_ERROR
, "Failed to remove %s" " error: %s", socketpath, strerror ((
*__errno_location ()))); } while (0)
1477 " error: %s", socketpath, strerror (errno))do { do { if (0) printf ("Failed to remove %s" " error: %s", socketpath
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 1477, GF_LOG_ERROR
, "Failed to remove %s" " error: %s", socketpath, strerror ((
*__errno_location ()))); } while (0)
;
1478 }
1479
1480 return ret;
1481}
1482
1483int32_t
1484glusterd_brick_disconnect (glusterd_brickinfo_t *brickinfo)
1485{
1486 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1486, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
1487
1488 if (brickinfo->rpc) {
1489 /* cleanup the saved-frames before last unref */
1490 rpc_clnt_connection_cleanup (&brickinfo->rpc->conn);
1491
1492 rpc_clnt_unref (brickinfo->rpc);
1493 brickinfo->rpc = NULL((void*)0);
1494 }
1495 return 0;
1496}
1497
1498int32_t
1499glusterd_volume_stop_glusterfs (glusterd_volinfo_t *volinfo,
1500 glusterd_brickinfo_t *brickinfo,
1501 gf_boolean_t del_brick)
1502{
1503 xlator_t *this = NULL((void*)0);
1504 glusterd_conf_t *priv = NULL((void*)0);
1505 char pidfile[PATH_MAX4096] = {0,};
1506 int ret = 0;
1507
1508 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1508, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
1509 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1509, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
1510
1511 this = THIS(*__glusterfs_this_location());
1512 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1512, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
1513
1514 priv = this->private;
1515 if (del_brick)
1516 list_del_init (&brickinfo->brick_list);
1517
1518 if (GLUSTERD_STATUS_STARTED == volinfo->status) {
1519 (void) glusterd_brick_disconnect (brickinfo);
1520 GLUSTERD_GET_BRICK_PIDFILE (pidfile, volinfo, brickinfo, priv)do { char exp_path[4096] = {0,}; char volpath[4096] = {0,}; snprintf
(volpath, 4096, "%s/vols/%s", priv->workdir, volinfo->
volname);; do { int i = 0; for (i = 1; i < strlen (brickinfo
->path); i++) { exp_path[i-1] = brickinfo->path[i]; if (
exp_path[i-1] == '/') exp_path[i-1] = '-'; } } while (0); snprintf
(pidfile, 4096, "%s/run/%s-%s.pid", volpath, brickinfo->hostname
, exp_path); } while (0)
;
1521 ret = glusterd_service_stop ("brick", pidfile, SIGTERM15, _gf_false);
1522 if (ret == 0) {
1523 glusterd_set_brick_status (brickinfo, GF_BRICK_STOPPED);
1524 (void) glusterd_brick_unlink_socket_file (volinfo, brickinfo);
1525 }
1526 }
1527
1528 if (del_brick)
1529 glusterd_delete_brick (volinfo, brickinfo);
1530
1531 return ret;
1532}
1533
1534int32_t
1535glusterd_peer_hostname_new (char *hostname, glusterd_peer_hostname_t **name)
1536{
1537 glusterd_peer_hostname_t *peer_hostname = NULL((void*)0);
1538 int32_t ret = -1;
1539
1540 GF_ASSERT (hostname)do { if (!(hostname)) { do { do { if (0) printf ("Assertion failed: "
"hostname"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1540, GF_LOG_ERROR, "Assertion failed: " "hostname"
); } while (0); } } while (0)
;
1541 GF_ASSERT (name)do { if (!(name)) { do { do { if (0) printf ("Assertion failed: "
"name"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1541, GF_LOG_ERROR, "Assertion failed: " "name"
); } while (0); } } while (0)
;
1542
1543 peer_hostname = GF_CALLOC (1, sizeof (*peer_hostname),__gf_calloc (1, sizeof (*peer_hostname), gf_gld_mt_peer_hostname_t
)
1544 gf_gld_mt_peer_hostname_t)__gf_calloc (1, sizeof (*peer_hostname), gf_gld_mt_peer_hostname_t
)
;
1545
1546 if (!peer_hostname)
1547 goto out;
1548
1549 peer_hostname->hostname = gf_strdup (hostname);
1550 INIT_LIST_HEAD (&peer_hostname->hostname_list)do { (&peer_hostname->hostname_list)->next = (&
peer_hostname->hostname_list)->prev = &peer_hostname
->hostname_list; } while (0)
;
1551
1552 *name = peer_hostname;
1553 ret = 0;
1554
1555out:
1556 gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 1556, GF_LOG_DEBUG, "Returning %d"
, ret); } while (0)
;
1557 return ret;
1558}
1559
1560/* Free LINE[0..N-1] and then the LINE buffer. */
1561static void
1562free_lines (char **line, size_t n)
1563{
1564 size_t i;
1565 for (i = 0; i < n; i++)
1566 GF_FREE (line[i])__gf_free (line[i]);
1567 GF_FREE (line)__gf_free (line);
1568}
1569
1570char **
1571glusterd_readin_file (const char *filepath, int *line_count)
1572{
1573 int ret = -1;
1574 int n = 8;
1575 int counter = 0;
1576 char buffer[PATH_MAX4096 + 256] = {0};
1577 char **lines = NULL((void*)0);
1578 FILE *fp = NULL((void*)0);
1579 void *p;
1580
1581 fp = fopen (filepath, "r");
1582 if (!fp)
1583 goto out;
1584
1585 lines = GF_CALLOC (1, n * sizeof (*lines), gf_gld_mt_charptr)__gf_calloc (1, n * sizeof (*lines), gf_gld_mt_charptr);
1586 if (!lines)
1587 goto out;
1588
1589 for (counter = 0; fgets (buffer, sizeof (buffer), fp); counter++) {
1590
1591 if (counter == n-1) {
1592 n *= 2;
1593 p = GF_REALLOC (lines, n * sizeof (char *))__gf_realloc (lines, n * sizeof (char *));
1594 if (!p) {
1595 free_lines (lines, n/2);
1596 lines = NULL((void*)0);
1597 goto out;
1598 }
1599 lines = p;
1600 }
1601
1602 lines[counter] = gf_strdup (buffer);
1603 }
1604
1605 lines[counter] = NULL((void*)0);
1606 /* Reduce allocation to minimal size. */
1607 p = GF_REALLOC (lines, (counter + 1) * sizeof (char *))__gf_realloc (lines, (counter + 1) * sizeof (char *));
1608 if (!p) {
1609 free_lines (lines, counter);
1610 lines = NULL((void*)0);
1611 goto out;
1612 }
1613 lines = p;
1614
1615 *line_count = counter;
1616 ret = 0;
1617
1618 out:
1619 if (ret)
1620 gf_log (THIS->name, GF_LOG_ERROR, "%s", strerror (errno))do { do { if (0) printf ("%s", strerror ((*__errno_location (
)))); } while (0); _gf_log ((*__glusterfs_this_location())->
name, "glusterd-utils.c", __FUNCTION__, 1620, GF_LOG_ERROR, "%s"
, strerror ((*__errno_location ()))); } while (0)
;
1621 if (fp)
1622 fclose (fp);
1623
1624 return lines;
1625}
1626
1627int
1628glusterd_compare_lines (const void *a, const void *b) {
1629
1630 return strcmp(* (char * const *) a, * (char * const *) b);
1631}
1632
1633int
1634glusterd_sort_and_redirect (const char *src_filepath, int dest_fd)
1635{
1636 int ret = -1;
1637 int line_count = 0;
1638 int counter = 0;
1639 char **lines = NULL((void*)0);
1640
1641
1642 if (!src_filepath || dest_fd < 0)
1643 goto out;
1644
1645 lines = glusterd_readin_file (src_filepath, &line_count);
1646 if (!lines)
1647 goto out;
1648
1649 qsort (lines, line_count, sizeof (*lines), glusterd_compare_lines);
1650
1651 for (counter = 0; lines[counter]; counter++) {
1652
1653 ret = write (dest_fd, lines[counter],
1654 strlen (lines[counter]));
1655 if (ret < 0)
1656 goto out;
1657
1658 GF_FREE (lines[counter])__gf_free (lines[counter]);
1659 }
1660
1661 ret = 0;
1662 out:
1663 GF_FREE (lines)__gf_free (lines);
1664
1665 return ret;
1666}
1667
1668int
1669glusterd_volume_compute_cksum (glusterd_volinfo_t *volinfo)
1670{
1671 int32_t ret = -1;
1672 glusterd_conf_t *priv = NULL((void*)0);
1673 char path[PATH_MAX4096] = {0,};
1674 char cksum_path[PATH_MAX4096] = {0,};
1675 char filepath[PATH_MAX4096] = {0,};
1676 int fd = -1;
1677 uint32_t cksum = 0;
1678 char buf[4096] = {0,};
1679 char sort_filepath[PATH_MAX4096] = {0};
1680 gf_boolean_t unlink_sortfile = _gf_false;
1681 int sort_fd = 0;
1682 xlator_t *this = NULL((void*)0);
1683
1684 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1684, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
1685 this = THIS(*__glusterfs_this_location());
1686 priv = THIS(*__glusterfs_this_location())->private;
1687 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1687, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
1688
1689 GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv)snprintf (path, 4096, "%s/vols/%s", priv->workdir, volinfo
->volname);
;
1690
1691 snprintf (cksum_path, sizeof (cksum_path), "%s/%s",
1692 path, GLUSTERD_CKSUM_FILE"cksum");
1693
1694 fd = open (cksum_path, O_RDWR02 | O_APPEND02000 | O_CREAT0100| O_TRUNC01000, 0600);
1695
1696 if (-1 == fd) {
1697 gf_log (this->name, GF_LOG_ERROR, "Unable to open %s, errno: %d",do { do { if (0) printf ("Unable to open %s, errno: %d", cksum_path
, (*__errno_location ())); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 1698, GF_LOG_ERROR, "Unable to open %s, errno: %d"
, cksum_path, (*__errno_location ())); } while (0)
1698 cksum_path, errno)do { do { if (0) printf ("Unable to open %s, errno: %d", cksum_path
, (*__errno_location ())); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 1698, GF_LOG_ERROR, "Unable to open %s, errno: %d"
, cksum_path, (*__errno_location ())); } while (0)
;
1699 ret = -1;
1700 goto out;
1701 }
1702
1703 snprintf (filepath, sizeof (filepath), "%s/%s", path,
1704 GLUSTERD_VOLUME_INFO_FILE"info");
1705 snprintf (sort_filepath, sizeof (sort_filepath), "/tmp/%s.XXXXXX",
1706 volinfo->volname);
1707
1708 sort_fd = mkstemp (sort_filepath);
1709 if (sort_fd < 0) {
1710 gf_log (this->name, GF_LOG_ERROR, "Could not generate temp "do { do { if (0) printf ("Could not generate temp " "file, reason: %s for volume: %s"
, strerror ((*__errno_location ())), volinfo->volname); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 1712, GF_LOG_ERROR, "Could not generate temp " "file, reason: %s for volume: %s"
, strerror ((*__errno_location ())), volinfo->volname); } while
(0)
1711 "file, reason: %s for volume: %s", strerror (errno),do { do { if (0) printf ("Could not generate temp " "file, reason: %s for volume: %s"
, strerror ((*__errno_location ())), volinfo->volname); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 1712, GF_LOG_ERROR, "Could not generate temp " "file, reason: %s for volume: %s"
, strerror ((*__errno_location ())), volinfo->volname); } while
(0)
1712 volinfo->volname)do { do { if (0) printf ("Could not generate temp " "file, reason: %s for volume: %s"
, strerror ((*__errno_location ())), volinfo->volname); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 1712, GF_LOG_ERROR, "Could not generate temp " "file, reason: %s for volume: %s"
, strerror ((*__errno_location ())), volinfo->volname); } while
(0)
;
1713 goto out;
1714 } else {
1715 unlink_sortfile = _gf_true;
1716 }
1717
1718 /* sort the info file, result in sort_filepath */
1719
1720 ret = glusterd_sort_and_redirect (filepath, sort_fd);
1721 if (ret) {
1722 gf_log (this->name, GF_LOG_ERROR, "sorting info file failed")do { do { if (0) printf ("sorting info file failed"); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 1722, GF_LOG_ERROR, "sorting info file failed"); } while (0
)
;
1723 goto out;
1724 }
1725
1726 ret = close (sort_fd);
1727 if (ret)
1728 goto out;
1729
1730 ret = get_checksum_for_path (sort_filepath, &cksum);
1731
1732 if (ret) {
1733 gf_log (this->name, GF_LOG_ERROR, "Unable to get checksum"do { do { if (0) printf ("Unable to get checksum" " for path: %s"
, sort_filepath); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 1734, GF_LOG_ERROR, "Unable to get checksum" " for path: %s"
, sort_filepath); } while (0)
1734 " for path: %s", sort_filepath)do { do { if (0) printf ("Unable to get checksum" " for path: %s"
, sort_filepath); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 1734, GF_LOG_ERROR, "Unable to get checksum" " for path: %s"
, sort_filepath); } while (0)
;
1735 goto out;
1736 }
1737
1738 snprintf (buf, sizeof (buf), "%s=%u\n", "info", cksum);
1739 ret = write (fd, buf, strlen (buf));
1740
1741 if (ret <= 0) {
1742 ret = -1;
1743 goto out;
1744 }
1745
1746 ret = get_checksum_for_file (fd, &cksum);
1747
1748 if (ret)
1749 goto out;
1750
1751 volinfo->cksum = cksum;
1752
1753out:
1754 if (fd > 0)
1755 close (fd);
1756 if (unlink_sortfile)
1757 unlink (sort_filepath);
1758 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-utils.c", __FUNCTION__,
1758, GF_LOG_DEBUG, "Returning with %d", ret); } while (0)
;
1759
1760 return ret;
1761}
1762
1763int
1764_add_dict_to_prdict (dict_t *this, char *key, data_t *value, void *data)
1765{
1766 glusterd_dict_ctx_t *ctx = NULL((void*)0);
1767 char optkey[512] = {0,};
1768 int ret = -1;
1769
1770 ctx = data;
1771 snprintf (optkey, sizeof (optkey), "%s.%s%d", ctx->prefix,
1772 ctx->key_name, ctx->opt_count);
1773 ret = dict_set_str (ctx->dict, optkey, key);
1774 if (ret)
1775 gf_log ("", GF_LOG_ERROR, "option add for %s%d %s",do { do { if (0) printf ("option add for %s%d %s", ctx->key_name
, ctx->opt_count, key); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 1776, GF_LOG_ERROR, "option add for %s%d %s",
ctx->key_name, ctx->opt_count, key); } while (0)
1776 ctx->key_name, ctx->opt_count, key)do { do { if (0) printf ("option add for %s%d %s", ctx->key_name
, ctx->opt_count, key); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 1776, GF_LOG_ERROR, "option add for %s%d %s",
ctx->key_name, ctx->opt_count, key); } while (0)
;
1777 snprintf (optkey, sizeof (optkey), "%s.%s%d", ctx->prefix,
1778 ctx->val_name, ctx->opt_count);
1779 ret = dict_set_str (ctx->dict, optkey, value->data);
1780 if (ret)
1781 gf_log ("", GF_LOG_ERROR, "option add for %s%d %s",do { do { if (0) printf ("option add for %s%d %s", ctx->val_name
, ctx->opt_count, value->data); } while (0); _gf_log (""
, "glusterd-utils.c", __FUNCTION__, 1782, GF_LOG_ERROR, "option add for %s%d %s"
, ctx->val_name, ctx->opt_count, value->data); } while
(0)
1782 ctx->val_name, ctx->opt_count, value->data)do { do { if (0) printf ("option add for %s%d %s", ctx->val_name
, ctx->opt_count, value->data); } while (0); _gf_log (""
, "glusterd-utils.c", __FUNCTION__, 1782, GF_LOG_ERROR, "option add for %s%d %s"
, ctx->val_name, ctx->opt_count, value->data); } while
(0)
;
1783 ctx->opt_count++;
1784
1785 return ret;
1786}
1787
1788int32_t
1789glusterd_add_bricks_hname_path_to_dict (dict_t *dict,
1790 glusterd_volinfo_t *volinfo)
1791{
1792 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
1793 int ret = 0;
1794 char key[256] = {0};
1795 int index = 0;
1796
1797
1798 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))))
{
1799 snprintf (key, sizeof (key), "%d-hostname", index);
1800 ret = dict_set_str (dict, key, brickinfo->hostname);
1801 if (ret)
1802 goto out;
1803
1804 snprintf (key, sizeof (key), "%d-path", index);
1805 ret = dict_set_str (dict, key, brickinfo->path);
1806 if (ret)
1807 goto out;
1808
1809 index++;
1810 }
1811out:
1812 return ret;
1813}
1814
1815int32_t
1816glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo,
1817 dict_t *dict, int32_t count)
1818{
1819 int32_t ret = -1;
1820 char prefix[512] = {0,};
1821 char key[512] = {0,};
1822 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
1823 int32_t i = 1;
1824 char *volume_id_str = NULL((void*)0);
1825 char *src_brick = NULL((void*)0);
1826 char *dst_brick = NULL((void*)0);
1827 char *str = NULL((void*)0);
1828 glusterd_dict_ctx_t ctx = {0};
1829 char *rebalance_id_str = NULL((void*)0);
1830 char *rb_id_str = NULL((void*)0);
1831
1832 GF_ASSERT (dict)do { if (!(dict)) { do { do { if (0) printf ("Assertion failed: "
"dict"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1832, GF_LOG_ERROR, "Assertion failed: " "dict"
); } while (0); } } while (0)
;
1833 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 1833, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
1834
1835 snprintf (key, sizeof (key), "volume%d.name", count);
1836 ret = dict_set_str (dict, key, volinfo->volname);
1837 if (ret)
1838 goto out;
1839
1840 memset (key, 0, sizeof (key));
1841 snprintf (key, sizeof (key), "volume%d.type", count);
1842 ret = dict_set_int32 (dict, key, volinfo->type);
1843 if (ret)
1844 goto out;
1845
1846 memset (key, 0, sizeof (key));
1847 snprintf (key, sizeof (key), "volume%d.brick_count", count);
1848 ret = dict_set_int32 (dict, key, volinfo->brick_count);
1849 if (ret)
1850 goto out;
1851
1852 memset (key, 0, sizeof (key));
1853 snprintf (key, sizeof (key), "volume%d.version", count);
1854 ret = dict_set_int32 (dict, key, volinfo->version);
1855 if (ret)
1856 goto out;
1857
1858 memset (key, 0, sizeof (key));
1859 snprintf (key, sizeof (key), "volume%d.status", count);
1860 ret = dict_set_int32 (dict, key, volinfo->status);
1861 if (ret)
1862 goto out;
1863
1864 memset (key, 0, sizeof (key));
1865 snprintf (key, sizeof (key), "volume%d.sub_count", count);
1866 ret = dict_set_int32 (dict, key, volinfo->sub_count);
1867 if (ret)
1868 goto out;
1869
1870 memset (key, 0, sizeof (key));
1871 snprintf (key, sizeof (key), "volume%d.stripe_count", count);
1872 ret = dict_set_int32 (dict, key, volinfo->stripe_count);
1873 if (ret)
1874 goto out;
1875
1876 memset (key, 0, sizeof (key));
1877 snprintf (key, sizeof (key), "volume%d.replica_count", count);
1878 ret = dict_set_int32 (dict, key, volinfo->replica_count);
1879 if (ret)
1880 goto out;
1881
1882 memset (key, 0, sizeof (key));
1883 snprintf (key, sizeof (key), "volume%d.dist_count", count);
1884 ret = dict_set_int32 (dict, key, volinfo->dist_leaf_count);
1885 if (ret)
1886 goto out;
1887
1888 memset (key, 0, sizeof (key));
1889 snprintf (key, sizeof (key), "volume%d.ckusm", count);
1890 ret = dict_set_int64 (dict, key, volinfo->cksum);
1891 if (ret)
1892 goto out;
1893
1894 memset (key, 0, sizeof (key));
1895 snprintf (key, sizeof (key), "volume%d.transport_type", count);
1896 ret = dict_set_uint32 (dict, key, volinfo->transport_type);
1897 if (ret)
1898 goto out;
1899
1900 volume_id_str = gf_strdup (uuid_utoa (volinfo->volume_id));
1901 if (!volume_id_str) {
1902 ret = -1;
1903 goto out;
1904 }
1905 memset (key, 0, sizeof (key));
1906 snprintf (key, sizeof (key), "volume%d.volume_id", count);
1907 ret = dict_set_dynstr (dict, key, volume_id_str);
1908 if (ret)
1909 goto out;
1910 volume_id_str = NULL((void*)0);
1911
1912 memset (key, 0, sizeof (key));
1913 snprintf (key, sizeof (key), "volume%d.username", count);
1914 str = glusterd_auth_get_username (volinfo);
1915 if (str) {
1916 ret = dict_set_dynstr (dict, key, gf_strdup (str));
1917 if (ret)
1918 goto out;
1919 }
1920
1921 memset (key, 0, sizeof (key));
1922 snprintf (key, sizeof (key), "volume%d.password", count);
1923 str = glusterd_auth_get_password (volinfo);
1924 if (str) {
1925 ret = dict_set_dynstr (dict, key, gf_strdup (str));
1926 if (ret)
1927 goto out;
1928 }
1929
1930 memset (key, 0, sizeof (key));
1931 snprintf (key, 256, "volume%d.rebalance", count);
1932 ret = dict_set_int32 (dict, key, volinfo->rebal.defrag_cmd);
1933 if (ret)
1934 goto out;
1935
1936 if (volinfo->rebal.defrag_cmd) {
1937 rebalance_id_str = gf_strdup (uuid_utoa
1938 (volinfo->rebal.rebalance_id));
1939 if (!rebalance_id_str) {
1940 ret = -1;
1941 goto out;
1942 }
1943 memset (key, 0, sizeof (key));
1944 snprintf (key, 256, "volume%d.rebalance-id", count);
1945 ret = dict_set_dynstr (dict, key, rebalance_id_str);
1946 if (ret)
1947 goto out;
1948 rebalance_id_str = NULL((void*)0);
1949 }
1950
1951 memset (key, 0, sizeof (key));
1952 snprintf (key, sizeof (key), "volume%d.rebalance-op", count);
1953 ret = dict_set_uint32 (dict, key, volinfo->rebal.op);
1954 if (ret)
1955 goto out;
1956
1957 memset (key, 0, sizeof (key));
1958 snprintf (key, 256, "volume%d."GLUSTERD_STORE_KEY_RB_STATUS"rb_status", count);
1959 ret = dict_set_int32 (dict, key, volinfo->rep_brick.rb_status);
1960 if (ret)
1961 goto out;
1962
1963 if (volinfo->rep_brick.rb_status > GF_RB_STATUS_NONE) {
1964
1965 memset (key, 0, sizeof (key));
1966 snprintf (key, 256, "volume%d."GLUSTERD_STORE_KEY_RB_SRC_BRICK"rb_src",
1967 count);
1968 gf_asprintf (&src_brick, "%s:%s",
1969 volinfo->rep_brick.src_brick->hostname,
1970 volinfo->rep_brick.src_brick->path);
1971 ret = dict_set_dynstr (dict, key, src_brick);
1972 if (ret)
1973 goto out;
1974
1975 memset (key, 0, sizeof (key));
1976 snprintf (key, 256, "volume%d."GLUSTERD_STORE_KEY_RB_DST_BRICK"rb_dst",
1977 count);
1978 gf_asprintf (&dst_brick, "%s:%s",
1979 volinfo->rep_brick.dst_brick->hostname,
1980 volinfo->rep_brick.dst_brick->path);
1981 ret = dict_set_dynstr (dict, key, dst_brick);
1982 if (ret)
1983 goto out;
1984
1985 rb_id_str = gf_strdup (uuid_utoa (volinfo->rep_brick.rb_id));
1986 if (!rb_id_str) {
1987 ret = -1;
1988 goto out;
1989 }
1990
1991 memset (key, 0, sizeof (key));
1992 snprintf (key, sizeof (key), "volume%d.rb_id", count);
1993 ret = dict_set_dynstr (dict, key, rb_id_str);
1994 if (ret)
1995 goto out;
1996 rb_id_str = NULL((void*)0);
1997 }
1998
1999 snprintf (prefix, sizeof (prefix), "volume%d", count);
2000 ctx.dict = dict;
2001 ctx.prefix = prefix;
2002 ctx.opt_count = 1;
2003 ctx.key_name = "key";
2004 ctx.val_name = "value";
2005 GF_ASSERT (volinfo->dict)do { if (!(volinfo->dict)) { do { do { if (0) printf ("Assertion failed: "
"volinfo->dict"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2005, GF_LOG_ERROR, "Assertion failed: " "volinfo->dict"
); } while (0); } } while (0)
;
2006
2007 dict_foreach (volinfo->dict, _add_dict_to_prdict, &ctx);
2008 ctx.opt_count--;
2009 memset (key, 0, sizeof (key));
2010 snprintf (key, sizeof (key), "volume%d.opt-count", count);
2011 ret = dict_set_int32 (dict, key, ctx.opt_count);
2012 if (ret)
2013 goto out;
2014
2015 ctx.dict = dict;
2016 ctx.prefix = prefix;
2017 ctx.opt_count = 1;
2018 ctx.key_name = "slave-num";
2019 ctx.val_name = "slave-val";
2020 GF_ASSERT (volinfo->gsync_slaves)do { if (!(volinfo->gsync_slaves)) { do { do { if (0) printf
("Assertion failed: " "volinfo->gsync_slaves"); } while (
0); _gf_log_callingfn ("", "glusterd-utils.c", __FUNCTION__, 2020
, GF_LOG_ERROR, "Assertion failed: " "volinfo->gsync_slaves"
); } while (0); } } while (0)
;
2021
2022 dict_foreach (volinfo->gsync_slaves, _add_dict_to_prdict, &ctx);
2023 ctx.opt_count--;
2024
2025 memset (key, 0, sizeof (key));
2026 snprintf (key, sizeof (key), "volume%d.gsync-count", count);
2027 ret = dict_set_int32 (dict, key, ctx.opt_count);
2028 if (ret)
2029 goto out;
2030
2031 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))))
{
2032 memset (key, 0, sizeof (key));
2033 snprintf (key, sizeof (key), "volume%d.brick%d.hostname",
2034 count, i);
2035 ret = dict_set_str (dict, key, brickinfo->hostname);
2036 if (ret)
2037 goto out;
2038
2039 memset (key, 0, sizeof (key));
2040 snprintf (key, sizeof (key), "volume%d.brick%d.path",
2041 count, i);
2042 ret = dict_set_str (dict, key, brickinfo->path);
2043 if (ret)
2044 goto out;
2045
2046 i++;
2047 }
2048
2049
2050out:
2051 GF_FREE (volume_id_str)__gf_free (volume_id_str);
2052 GF_FREE (rebalance_id_str)__gf_free (rebalance_id_str);
2053 GF_FREE (rb_id_str)__gf_free (rb_id_str);
2054
2055 gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2055, GF_LOG_DEBUG
, "Returning with %d", ret); } while (0)
;
2056
2057 return ret;
2058}
2059
2060int32_t
2061glusterd_build_volume_dict (dict_t **vols)
2062{
2063 int32_t ret = -1;
2064 dict_t *dict = NULL((void*)0);
2065 glusterd_conf_t *priv = NULL((void*)0);
2066 glusterd_volinfo_t *volinfo = NULL((void*)0);
2067 int32_t count = 0;
2068 glusterd_dict_ctx_t ctx = {0};
2069
2070 priv = THIS(*__glusterfs_this_location())->private;
2071
2072 dict = dict_new ();
2073
2074 if (!dict)
2075 goto out;
2076
2077 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))))
{
2078 count++;
2079 ret = glusterd_add_volume_to_dict (volinfo, dict, count);
2080 if (ret)
2081 goto out;
2082 }
2083
2084
2085 ret = dict_set_int32 (dict, "count", count);
2086 if (ret)
2087 goto out;
2088
2089 ctx.dict = dict;
2090 ctx.prefix = "global";
2091 ctx.opt_count = 1;
2092 ctx.key_name = "key";
2093 ctx.val_name = "val";
2094 dict_foreach (priv->opts, _add_dict_to_prdict, &ctx);
2095 ctx.opt_count--;
2096 ret = dict_set_int32 (dict, "global-opt-count", ctx.opt_count);
2097 if (ret)
2098 goto out;
2099
2100 *vols = dict;
2101out:
2102 gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2102, GF_LOG_DEBUG
, "Returning with %d", ret); } while (0)
;
2103 if (ret)
2104 dict_unref (dict);
2105
2106 return ret;
2107}
2108
2109int32_t
2110glusterd_compare_friend_volume (dict_t *vols, int32_t count, int32_t *status,
2111 char *hostname)
2112{
2113
2114 int32_t ret = -1;
2115 char key[512] = {0,};
2116 glusterd_volinfo_t *volinfo = NULL((void*)0);
2117 char *volname = NULL((void*)0);
2118 uint32_t cksum = 0;
2119 int32_t version = 0;
2120
2121 GF_ASSERT (vols)do { if (!(vols)) { do { do { if (0) printf ("Assertion failed: "
"vols"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2121, GF_LOG_ERROR, "Assertion failed: " "vols"
); } while (0); } } while (0)
;
2122 GF_ASSERT (status)do { if (!(status)) { do { do { if (0) printf ("Assertion failed: "
"status"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2122, GF_LOG_ERROR, "Assertion failed: " "status"
); } while (0); } } while (0)
;
2123
2124 snprintf (key, sizeof (key), "volume%d.name", count);
2125 ret = dict_get_str (vols, key, &volname);
2126 if (ret)
2127 goto out;
2128
2129 ret = glusterd_volinfo_find (volname, &volinfo);
2130
2131 if (ret) {
2132 *status = GLUSTERD_VOL_COMP_UPDATE_REQ;
2133 ret = 0;
2134 goto out;
2135 }
2136
2137 memset (key, 0, sizeof (key));
2138 snprintf (key, sizeof (key), "volume%d.version", count);
2139 ret = dict_get_int32 (vols, key, &version);
2140 if (ret)
2141 goto out;
2142
2143 if (version > volinfo->version) {
2144 //Mismatch detected
2145 ret = 0;
2146 gf_log ("", GF_LOG_ERROR, "Version of volume %s differ."do { do { if (0) printf ("Version of volume %s differ." "local version = %d, remote version = %d on peer %s"
, volinfo->volname, volinfo->version, version, hostname
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 2148, GF_LOG_ERROR, "Version of volume %s differ." "local version = %d, remote version = %d on peer %s"
, volinfo->volname, volinfo->version, version, hostname
); } while (0)
2147 "local version = %d, remote version = %d on peer %s",do { do { if (0) printf ("Version of volume %s differ." "local version = %d, remote version = %d on peer %s"
, volinfo->volname, volinfo->version, version, hostname
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 2148, GF_LOG_ERROR, "Version of volume %s differ." "local version = %d, remote version = %d on peer %s"
, volinfo->volname, volinfo->version, version, hostname
); } while (0)
2148 volinfo->volname, volinfo->version, version, hostname)do { do { if (0) printf ("Version of volume %s differ." "local version = %d, remote version = %d on peer %s"
, volinfo->volname, volinfo->version, version, hostname
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 2148, GF_LOG_ERROR, "Version of volume %s differ." "local version = %d, remote version = %d on peer %s"
, volinfo->volname, volinfo->version, version, hostname
); } while (0)
;
2149 *status = GLUSTERD_VOL_COMP_UPDATE_REQ;
2150 goto out;
2151 } else if (version < volinfo->version) {
2152 *status = GLUSTERD_VOL_COMP_SCS;
2153 goto out;
2154 }
2155
2156 //Now, versions are same, compare cksums.
2157 //
2158 memset (key, 0, sizeof (key));
2159 snprintf (key, sizeof (key), "volume%d.ckusm", count);
2160 ret = dict_get_uint32 (vols, key, &cksum);
2161 if (ret)
2162 goto out;
2163
2164 if (cksum != volinfo->cksum) {
2165 ret = 0;
2166 gf_log ("", GF_LOG_ERROR, "Cksums of volume %s differ."do { do { if (0) printf ("Cksums of volume %s differ." " local cksum = %u, remote cksum = %u on peer %s"
, volinfo->volname, volinfo->cksum, cksum, hostname); }
while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2168
, GF_LOG_ERROR, "Cksums of volume %s differ." " local cksum = %u, remote cksum = %u on peer %s"
, volinfo->volname, volinfo->cksum, cksum, hostname); }
while (0)
2167 " local cksum = %u, remote cksum = %u on peer %s",do { do { if (0) printf ("Cksums of volume %s differ." " local cksum = %u, remote cksum = %u on peer %s"
, volinfo->volname, volinfo->cksum, cksum, hostname); }
while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2168
, GF_LOG_ERROR, "Cksums of volume %s differ." " local cksum = %u, remote cksum = %u on peer %s"
, volinfo->volname, volinfo->cksum, cksum, hostname); }
while (0)
2168 volinfo->volname, volinfo->cksum, cksum, hostname)do { do { if (0) printf ("Cksums of volume %s differ." " local cksum = %u, remote cksum = %u on peer %s"
, volinfo->volname, volinfo->cksum, cksum, hostname); }
while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2168
, GF_LOG_ERROR, "Cksums of volume %s differ." " local cksum = %u, remote cksum = %u on peer %s"
, volinfo->volname, volinfo->cksum, cksum, hostname); }
while (0)
;
2169 *status = GLUSTERD_VOL_COMP_RJT;
2170 goto out;
2171 }
2172
2173 *status = GLUSTERD_VOL_COMP_SCS;
2174
2175out:
2176 gf_log ("", GF_LOG_DEBUG, "Returning with ret: %d, status: %d",do { do { if (0) printf ("Returning with ret: %d, status: %d"
, ret, *status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 2177, GF_LOG_DEBUG, "Returning with ret: %d, status: %d"
, ret, *status); } while (0)
2177 ret, *status)do { do { if (0) printf ("Returning with ret: %d, status: %d"
, ret, *status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 2177, GF_LOG_DEBUG, "Returning with ret: %d, status: %d"
, ret, *status); } while (0)
;
2178 return ret;
2179}
2180
2181static int32_t
2182import_prdict_dict (dict_t *vols, dict_t *dst_dict, char *key_prefix,
2183 char *value_prefix, int opt_count, char *prefix)
2184{
2185 char key[512] = {0,};
2186 int32_t ret = 0;
2187 int i = 1;
2188 char *opt_key = NULL((void*)0);
2189 char *opt_val = NULL((void*)0);
2190 char *dup_opt_val = NULL((void*)0);
2191 char msg[2048] = {0};
2192
2193 while (i <= opt_count) {
2194 memset (key, 0, sizeof (key));
2195 snprintf (key, sizeof (key), "%s.%s%d",
2196 prefix, key_prefix, i);
2197 ret = dict_get_str (vols, key, &opt_key);
2198 if (ret) {
2199 snprintf (msg, sizeof (msg), "Volume dict key not "
2200 "specified");
2201 goto out;
2202 }
2203
2204 memset (key, 0, sizeof (key));
2205 snprintf (key, sizeof (key), "%s.%s%d",
2206 prefix, value_prefix, i);
2207 ret = dict_get_str (vols, key, &opt_val);
2208 if (ret) {
2209 snprintf (msg, sizeof (msg), "Volume dict value not "
2210 "specified");
2211 goto out;
2212 }
2213 dup_opt_val = gf_strdup (opt_val);
2214 if (!dup_opt_val) {
2215 ret = -1;
2216 goto out;
2217 }
2218 ret = dict_set_dynstr (dst_dict, opt_key, dup_opt_val);
2219 if (ret) {
2220 snprintf (msg, sizeof (msg), "Volume set %s %s "
2221 "unsuccessful", opt_key, dup_opt_val);
2222 goto out;
2223 }
2224 i++;
2225 }
2226
2227out:
2228 if (msg[0])
2229 gf_log ("glusterd", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("glusterd"
, "glusterd-utils.c", __FUNCTION__, 2229, GF_LOG_ERROR, "%s",
msg); } while (0)
;
2230 gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2230, GF_LOG_DEBUG
, "Returning with %d", ret); } while (0)
;
2231 return ret;
2232
2233}
2234
2235gf_boolean_t
2236glusterd_is_quorum_option (char *option)
2237{
2238 gf_boolean_t res = _gf_false;
2239 int i = 0;
2240 char *keys[] = {GLUSTERD_QUORUM_TYPE_KEY"cluster.server-quorum-type",
2241 GLUSTERD_QUORUM_RATIO_KEY"cluster.server-quorum-ratio", NULL((void*)0)};
2242
2243 for (i = 0; keys[i]; i++) {
2244 if (strcmp (option, keys[i]) == 0) {
2245 res = _gf_true;
2246 break;
2247 }
2248 }
2249 return res;
2250}
2251
2252gf_boolean_t
2253glusterd_is_quorum_changed (dict_t *options, char *option, char *value)
2254{
2255 int ret = 0;
2256 gf_boolean_t reconfigured = _gf_false;
2257 gf_boolean_t all = _gf_false;
2258 char *oldquorum = NULL((void*)0);
2259 char *newquorum = NULL((void*)0);
2260 char *oldratio = NULL((void*)0);
2261 char *newratio = NULL((void*)0);
2262
2263 if ((strcmp ("all", option) != 0) &&
2264 !glusterd_is_quorum_option (option))
2265 goto out;
2266
2267 if (strcmp ("all", option) == 0)
2268 all = _gf_true;
2269
2270 if (all || (strcmp (GLUSTERD_QUORUM_TYPE_KEY"cluster.server-quorum-type", option) == 0)) {
2271 newquorum = value;
2272 ret = dict_get_str (options, GLUSTERD_QUORUM_TYPE_KEY"cluster.server-quorum-type",
2273 &oldquorum);
2274 }
2275
2276 if (all || (strcmp (GLUSTERD_QUORUM_RATIO_KEY"cluster.server-quorum-ratio", option) == 0)) {
2277 newratio = value;
2278 ret = dict_get_str (options, GLUSTERD_QUORUM_RATIO_KEY"cluster.server-quorum-ratio",
2279 &oldratio);
2280 }
2281
2282 reconfigured = _gf_true;
2283
2284 if (oldquorum && newquorum && (strcmp (oldquorum, newquorum) == 0))
2285 reconfigured = _gf_false;
2286 if (oldratio && newratio && (strcmp (oldratio, newratio) == 0))
2287 reconfigured = _gf_false;
2288
2289 if ((oldratio == NULL((void*)0)) && (newratio == NULL((void*)0)) && (oldquorum == NULL((void*)0)) &&
2290 (newquorum == NULL((void*)0)))
2291 reconfigured = _gf_false;
2292out:
2293 return reconfigured;
2294}
2295
2296static inline gf_boolean_t
2297_is_contributing_to_quorum (gd_quorum_contrib_t contrib)
2298{
2299 if ((contrib == QUORUM_UP) || (contrib == QUORUM_DOWN))
2300 return _gf_true;
2301 return _gf_false;
2302}
2303
2304static inline gf_boolean_t
2305_does_quorum_meet (int active_count, int quorum_count)
2306{
2307 return (active_count >= quorum_count);
2308}
2309
2310int
2311glusterd_get_quorum_cluster_counts (xlator_t *this, int *active_count,
2312 int *quorum_count)
2313{
2314 glusterd_peerinfo_t *peerinfo = NULL((void*)0);
2315 glusterd_conf_t *conf = NULL((void*)0);
2316 int ret = -1;
2317 int inquorum_count = 0;
2318 char *val = NULL((void*)0);
2319 double quorum_percentage = 0.0;
2320 gf_boolean_t ratio = _gf_false;
2321 int count = 0;
2322
2323 conf = this->private;
2324 //Start with counting self
2325 inquorum_count = 1;
2326 if (active_count)
2327 *active_count = 1;
2328 list_for_each_entry (peerinfo, &conf->peers, uuid_list)for (peerinfo = ((typeof(*peerinfo) *)((char *)((&conf->
peers)->next)-(unsigned long)(&((typeof(*peerinfo) *)0
)->uuid_list))); &peerinfo->uuid_list != (&conf
->peers); peerinfo = ((typeof(*peerinfo) *)((char *)(peerinfo
->uuid_list.next)-(unsigned long)(&((typeof(*peerinfo)
*)0)->uuid_list))))
{
2329 if (peerinfo->quorum_contrib == QUORUM_WAITING)
2330 goto out;
2331
2332 if (_is_contributing_to_quorum (peerinfo->quorum_contrib))
2333 inquorum_count = inquorum_count + 1;
2334
2335 if (active_count && (peerinfo->quorum_contrib == QUORUM_UP))
2336 *active_count = *active_count + 1;
2337 }
2338
2339 ret = dict_get_str (conf->opts, GLUSTERD_QUORUM_RATIO_KEY"cluster.server-quorum-ratio", &val);
2340 if (ret == 0) {
2341 ratio = _gf_true;
2342 ret = gf_string2percent (val, &quorum_percentage);
2343 if (!ret)
2344 ratio = _gf_true;
2345 }
2346 if (ratio)
2347 count = CEILING_POS (inquorum_count *(((inquorum_count * quorum_percentage / 100.0)-(int)(inquorum_count
* quorum_percentage / 100.0)) > 0 ? (int)((inquorum_count
* quorum_percentage / 100.0)+1) : (int)(inquorum_count * quorum_percentage
/ 100.0))
2348 quorum_percentage / 100.0)(((inquorum_count * quorum_percentage / 100.0)-(int)(inquorum_count
* quorum_percentage / 100.0)) > 0 ? (int)((inquorum_count
* quorum_percentage / 100.0)+1) : (int)(inquorum_count * quorum_percentage
/ 100.0))
;
2349 else
2350 count = (inquorum_count * 50 / 100) + 1;
2351
2352 *quorum_count = count;
2353 ret = 0;
2354out:
2355 return ret;
2356}
2357
2358gf_boolean_t
2359glusterd_is_volume_in_server_quorum (glusterd_volinfo_t *volinfo)
2360{
2361 gf_boolean_t res = _gf_false;
2362 char *quorum_type = NULL((void*)0);
2363 int ret = 0;
2364
2365 ret = dict_get_str (volinfo->dict, GLUSTERD_QUORUM_TYPE_KEY"cluster.server-quorum-type",
2366 &quorum_type);
2367 if (ret)
2368 goto out;
2369
2370 if (strcmp (quorum_type, GLUSTERD_SERVER_QUORUM"server") == 0)
2371 res = _gf_true;
2372out:
2373 return res;
2374}
2375
2376gf_boolean_t
2377glusterd_is_any_volume_in_server_quorum (xlator_t *this)
2378{
2379 glusterd_conf_t *conf = NULL((void*)0);
2380 glusterd_volinfo_t *volinfo = NULL((void*)0);
2381
2382 conf = this->private;
2383 list_for_each_entry (volinfo, &conf->volumes, vol_list)for (volinfo = ((typeof(*volinfo) *)((char *)((&conf->
volumes)->next)-(unsigned long)(&((typeof(*volinfo) *)
0)->vol_list))); &volinfo->vol_list != (&conf->
volumes); volinfo = ((typeof(*volinfo) *)((char *)(volinfo->
vol_list.next)-(unsigned long)(&((typeof(*volinfo) *)0)->
vol_list))))
{
2384 if (glusterd_is_volume_in_server_quorum (volinfo)) {
2385 return _gf_true;
2386 }
2387 }
2388 return _gf_false;
2389}
2390
2391gf_boolean_t
2392does_gd_meet_server_quorum (xlator_t *this)
2393{
2394 int quorum_count = 0;
2395 int active_count = 0;
2396 gf_boolean_t in = _gf_false;
2397 glusterd_conf_t *conf = NULL((void*)0);
2398 int ret = -1;
2399
2400 conf = this->private;
2401 ret = glusterd_get_quorum_cluster_counts (this, &active_count,
2402 &quorum_count);
2403 if (ret)
2404 goto out;
2405
2406 if (!_does_quorum_meet (active_count, quorum_count)) {
2407 goto out;
2408 }
2409
2410 in = _gf_true;
2411out:
2412 return in;
2413}
2414
2415int
2416glusterd_spawn_daemons (void *opaque)
2417{
2418 glusterd_conf_t *conf = THIS(*__glusterfs_this_location())->private;
2419 gf_boolean_t start_bricks = (long) opaque;
2420
2421 if (start_bricks)
2422 glusterd_restart_bricks (conf);
2423 glusterd_restart_gsyncds (conf);
2424 glusterd_restart_rebalance (conf);
2425 return 0;
2426}
2427
2428void
2429glusterd_do_volume_quorum_action (xlator_t *this, glusterd_volinfo_t *volinfo,
2430 gf_boolean_t meets_quorum)
2431{
2432 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
2433 glusterd_conf_t *conf = NULL((void*)0);
2434
2435 conf = this->private;
2436 if (volinfo->status != GLUSTERD_STATUS_STARTED)
20
Taking false branch
2437 goto out;
2438
2439 if (!glusterd_is_volume_in_server_quorum (volinfo))
21
Taking true branch
2440 meets_quorum = _gf_true;
2441
2442 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))))
{
2443 if (!glusterd_is_local_brick (this, volinfo, brickinfo))
22
Taking false branch
2444 continue;
2445 if (meets_quorum)
23
Taking true branch
2446 glusterd_brick_start (volinfo, brickinfo, _gf_false);
24
Calling 'glusterd_brick_start'
2447 else
2448 glusterd_brick_stop (volinfo, brickinfo, _gf_false);
2449 }
2450out:
2451 return;
2452}
2453
2454int
2455glusterd_do_quorum_action ()
2456{
2457 xlator_t *this = NULL((void*)0);
2458 glusterd_conf_t *conf = NULL((void*)0);
2459 glusterd_volinfo_t *volinfo = NULL((void*)0);
2460 int ret = 0;
2461 int active_count = 0;
2462 int quorum_count = 0;
2463 gf_boolean_t meets = _gf_false;
2464
2465 this = THIS(*__glusterfs_this_location());
2466 conf = this->private;
2467
2468 conf->pending_quorum_action = _gf_true;
2469 ret = glusterd_lock (conf->uuid);
2470 if (ret)
16
Taking false branch
2471 goto out;
2472
2473 {
2474 ret = glusterd_get_quorum_cluster_counts (this, &active_count,
2475 &quorum_count);
2476 if (ret)
17
Taking false branch
2477 goto unlock;
2478
2479 if (_does_quorum_meet (active_count, quorum_count))
18
Taking true branch
2480 meets = _gf_true;
2481 list_for_each_entry (volinfo, &conf->volumes, vol_list)for (volinfo = ((typeof(*volinfo) *)((char *)((&conf->
volumes)->next)-(unsigned long)(&((typeof(*volinfo) *)
0)->vol_list))); &volinfo->vol_list != (&conf->
volumes); volinfo = ((typeof(*volinfo) *)((char *)(volinfo->
vol_list.next)-(unsigned long)(&((typeof(*volinfo) *)0)->
vol_list))))
{
2482 glusterd_do_volume_quorum_action (this, volinfo, meets);
19
Calling 'glusterd_do_volume_quorum_action'
2483 }
2484 }
2485unlock:
2486 (void)glusterd_unlock (conf->uuid);
2487 conf->pending_quorum_action = _gf_false;
2488out:
2489 return ret;
2490}
2491
2492int32_t
2493glusterd_import_friend_volume_opts (dict_t *vols, int count,
2494 glusterd_volinfo_t *volinfo)
2495{
2496 char key[512] = {0,};
2497 int32_t ret = -1;
2498 int opt_count = 0;
2499 char msg[2048] = {0};
2500 char volume_prefix[1024] = {0};
2501
2502 memset (key, 0, sizeof (key));
2503 snprintf (key, sizeof (key), "volume%d.opt-count", count);
2504 ret = dict_get_int32 (vols, key, &opt_count);
2505 if (ret) {
2506 snprintf (msg, sizeof (msg), "Volume option count not "
2507 "specified for %s", volinfo->volname);
2508 goto out;
2509 }
2510
2511 snprintf (volume_prefix, sizeof (volume_prefix), "volume%d", count);
2512 ret = import_prdict_dict (vols, volinfo->dict, "key", "value",
2513 opt_count, volume_prefix);
2514 if (ret) {
2515 snprintf (msg, sizeof (msg), "Unable to import options dict "
2516 "specified for %s", volinfo->volname);
2517 goto out;
2518 }
2519
2520 memset (key, 0, sizeof (key));
2521 snprintf (key, sizeof (key), "volume%d.gsync-count", count);
2522 ret = dict_get_int32 (vols, key, &opt_count);
2523 if (ret) {
2524 snprintf (msg, sizeof (msg), "Gsync count not "
2525 "specified for %s", volinfo->volname);
2526 goto out;
2527 }
2528
2529 ret = import_prdict_dict (vols, volinfo->gsync_slaves, "slave-num",
2530 "slave-val", opt_count, volume_prefix);
2531 if (ret) {
2532 snprintf (msg, sizeof (msg), "Unable to import gsync sessions "
2533 "specified for %s", volinfo->volname);
2534 goto out;
2535 }
2536
2537out:
2538 if (msg[0])
2539 gf_log ("glusterd", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("glusterd"
, "glusterd-utils.c", __FUNCTION__, 2539, GF_LOG_ERROR, "%s",
msg); } while (0)
;
2540 gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2540, GF_LOG_DEBUG
, "Returning with %d", ret); } while (0)
;
2541 return ret;
2542}
2543
2544int32_t
2545glusterd_import_new_brick (dict_t *vols, int32_t vol_count,
2546 int32_t brick_count,
2547 glusterd_brickinfo_t **brickinfo)
2548{
2549 char key[512] = {0,};
2550 int ret = -1;
2551 char *hostname = NULL((void*)0);
2552 char *path = NULL((void*)0);
2553 glusterd_brickinfo_t *new_brickinfo = NULL((void*)0);
2554 char msg[2048] = {0};
2555
2556 GF_ASSERT (vols)do { if (!(vols)) { do { do { if (0) printf ("Assertion failed: "
"vols"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2556, GF_LOG_ERROR, "Assertion failed: " "vols"
); } while (0); } } while (0)
;
2557 GF_ASSERT (vol_count >= 0)do { if (!(vol_count >= 0)) { do { do { if (0) printf ("Assertion failed: "
"vol_count >= 0"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2557, GF_LOG_ERROR, "Assertion failed: " "vol_count >= 0"
); } while (0); } } while (0)
;
2558 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2558, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
2559
2560 memset (key, 0, sizeof (key));
2561 snprintf (key, sizeof (key), "volume%d.brick%d.hostname",
2562 vol_count, brick_count);
2563 ret = dict_get_str (vols, key, &hostname);
2564 if (ret) {
2565 snprintf (msg, sizeof (msg), "%s missing in payload", key);
2566 goto out;
2567 }
2568
2569 memset (key, 0, sizeof (key));
2570 snprintf (key, sizeof (key), "volume%d.brick%d.path",
2571 vol_count, brick_count);
2572 ret = dict_get_str (vols, key, &path);
2573 if (ret) {
2574 snprintf (msg, sizeof (msg), "%s missing in payload", key);
2575 goto out;
2576 }
2577
2578 ret = glusterd_brickinfo_new (&new_brickinfo);
2579 if (ret)
2580 goto out;
2581
2582 strcpy (new_brickinfo->path, path);
2583 strcpy (new_brickinfo->hostname, hostname);
2584 //peerinfo might not be added yet
2585 (void) glusterd_resolve_brick (new_brickinfo);
2586 ret = 0;
2587 *brickinfo = new_brickinfo;
2588out:
2589 if (msg[0])
2590 gf_log ("glusterd", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("glusterd"
, "glusterd-utils.c", __FUNCTION__, 2590, GF_LOG_ERROR, "%s",
msg); } while (0)
;
2591 gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2591, GF_LOG_DEBUG
, "Returning with %d", ret); } while (0)
;
2592 return ret;
2593}
2594
2595int32_t
2596glusterd_import_bricks (dict_t *vols, int32_t vol_count,
2597 glusterd_volinfo_t *new_volinfo)
2598{
2599 int ret = -1;
2600 int brick_count = 1;
2601 glusterd_brickinfo_t *new_brickinfo = NULL((void*)0);
2602
2603 GF_ASSERT (vols)do { if (!(vols)) { do { do { if (0) printf ("Assertion failed: "
"vols"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2603, GF_LOG_ERROR, "Assertion failed: " "vols"
); } while (0); } } while (0)
;
2604 GF_ASSERT (vol_count >= 0)do { if (!(vol_count >= 0)) { do { do { if (0) printf ("Assertion failed: "
"vol_count >= 0"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2604, GF_LOG_ERROR, "Assertion failed: " "vol_count >= 0"
); } while (0); } } while (0)
;
2605 GF_ASSERT (new_volinfo)do { if (!(new_volinfo)) { do { do { if (0) printf ("Assertion failed: "
"new_volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2605, GF_LOG_ERROR, "Assertion failed: " "new_volinfo"
); } while (0); } } while (0)
;
2606 while (brick_count <= new_volinfo->brick_count) {
2607
2608 ret = glusterd_import_new_brick (vols, vol_count, brick_count,
2609 &new_brickinfo);
2610 if (ret)
2611 goto out;
2612 list_add_tail (&new_brickinfo->brick_list, &new_volinfo->bricks);
2613 brick_count++;
2614 }
2615 ret = 0;
2616out:
2617 gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2617, GF_LOG_DEBUG
, "Returning with %d", ret); } while (0)
;
2618 return ret;
2619}
2620
2621int32_t
2622glusterd_import_volinfo (dict_t *vols, int count,
2623 glusterd_volinfo_t **volinfo)
2624{
2625 int ret = -1;
2626 char key[256] = {0};
2627 char *volname = NULL((void*)0);
2628 glusterd_volinfo_t *new_volinfo = NULL((void*)0);
2629 char *volume_id_str = NULL((void*)0);
2630 char msg[2048] = {0};
2631 char *src_brick = NULL((void*)0);
2632 char *dst_brick = NULL((void*)0);
2633 char *str = NULL((void*)0);
2634 int rb_status = 0;
2635 char *rebalance_id_str = NULL((void*)0);
2636 char *rb_id_str = NULL((void*)0);
2637
2638 GF_ASSERT (vols)do { if (!(vols)) { do { do { if (0) printf ("Assertion failed: "
"vols"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2638, GF_LOG_ERROR, "Assertion failed: " "vols"
); } while (0); } } while (0)
;
2639 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2639, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
2640
2641 snprintf (key, sizeof (key), "volume%d.name", count);
2642 ret = dict_get_str (vols, key, &volname);
2643 if (ret) {
2644 snprintf (msg, sizeof (msg), "%s missing in payload", key);
2645 goto out;
2646 }
2647
2648 ret = glusterd_volinfo_new (&new_volinfo);
2649 if (ret)
2650 goto out;
2651 strncpy (new_volinfo->volname, volname, sizeof (new_volinfo->volname));
2652
2653
2654 memset (key, 0, sizeof (key));
2655 snprintf (key, sizeof (key), "volume%d.type", count);
2656 ret = dict_get_int32 (vols, key, &new_volinfo->type);
2657 if (ret) {
2658 snprintf (msg, sizeof (msg), "%s missing in payload for %s",
2659 key, volname);
2660 goto out;
2661 }
2662
2663 memset (key, 0, sizeof (key));
2664 snprintf (key, sizeof (key), "volume%d.brick_count", count);
2665 ret = dict_get_int32 (vols, key, &new_volinfo->brick_count);
2666 if (ret) {
2667 snprintf (msg, sizeof (msg), "%s missing in payload for %s",
2668 key, volname);
2669 goto out;
2670 }
2671
2672 memset (key, 0, sizeof (key));
2673 snprintf (key, sizeof (key), "volume%d.version", count);
2674 ret = dict_get_int32 (vols, key, &new_volinfo->version);
2675 if (ret) {
2676 snprintf (msg, sizeof (msg), "%s missing in payload for %s",
2677 key, volname);
2678 goto out;
2679 }
2680
2681 memset (key, 0, sizeof (key));
2682 snprintf (key, sizeof (key), "volume%d.status", count);
2683 ret = dict_get_int32 (vols, key, (int32_t *)&new_volinfo->status);
2684 if (ret) {
2685 snprintf (msg, sizeof (msg), "%s missing in payload for %s",
2686 key, volname);
2687 goto out;
2688 }
2689
2690 memset (key, 0, sizeof (key));
2691 snprintf (key, sizeof (key), "volume%d.sub_count", count);
2692 ret = dict_get_int32 (vols, key, &new_volinfo->sub_count);
2693 if (ret) {
2694 snprintf (msg, sizeof (msg), "%s missing in payload for %s",
2695 key, volname);
2696 goto out;
2697 }
2698
2699 /* not having a 'stripe_count' key is not a error
2700 (as peer may be of old version) */
2701 memset (key, 0, sizeof (key));
2702 snprintf (key, sizeof (key), "volume%d.stripe_count", count);
2703 ret = dict_get_int32 (vols, key, &new_volinfo->stripe_count);
2704 if (ret)
2705 gf_log (THIS->name, GF_LOG_INFO,do { do { if (0) printf ("peer is possibly old version"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 2706, GF_LOG_INFO, "peer is possibly old version"
); } while (0)
2706 "peer is possibly old version")do { do { if (0) printf ("peer is possibly old version"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 2706, GF_LOG_INFO, "peer is possibly old version"
); } while (0)
;
2707
2708 /* not having a 'replica_count' key is not a error
2709 (as peer may be of old version) */
2710 memset (key, 0, sizeof (key));
2711 snprintf (key, sizeof (key), "volume%d.replica_count", count);
2712 ret = dict_get_int32 (vols, key, &new_volinfo->replica_count);
2713 if (ret)
2714 gf_log (THIS->name, GF_LOG_INFO,do { do { if (0) printf ("peer is possibly old version"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 2715, GF_LOG_INFO, "peer is possibly old version"
); } while (0)
2715 "peer is possibly old version")do { do { if (0) printf ("peer is possibly old version"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 2715, GF_LOG_INFO, "peer is possibly old version"
); } while (0)
;
2716
2717 /* not having a 'dist_count' key is not a error
2718 (as peer may be of old version) */
2719 memset (key, 0, sizeof (key));
2720 snprintf (key, sizeof (key), "volume%d.dist_count", count);
2721 ret = dict_get_int32 (vols, key, &new_volinfo->dist_leaf_count);
2722 if (ret)
2723 gf_log (THIS->name, GF_LOG_INFO,do { do { if (0) printf ("peer is possibly old version"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 2724, GF_LOG_INFO, "peer is possibly old version"
); } while (0)
2724 "peer is possibly old version")do { do { if (0) printf ("peer is possibly old version"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 2724, GF_LOG_INFO, "peer is possibly old version"
); } while (0)
;
2725
2726 memset (key, 0, sizeof (key));
2727 snprintf (key, sizeof (key), "volume%d.ckusm", count);
2728 ret = dict_get_uint32 (vols, key, &new_volinfo->cksum);
2729 if (ret) {
2730 snprintf (msg, sizeof (msg), "%s missing in payload for %s",
2731 key, volname);
2732 goto out;
2733 }
2734
2735 memset (key, 0, sizeof (key));
2736 snprintf (key, sizeof (key), "volume%d.volume_id", count);
2737 ret = dict_get_str (vols, key, &volume_id_str);
2738 if (ret) {
2739 snprintf (msg, sizeof (msg), "%s missing in payload for %s",
2740 key, volname);
2741 goto out;
2742 }
2743
2744 uuid_parse (volume_id_str, new_volinfo->volume_id);
2745
2746 memset (key, 0, sizeof (key));
2747 snprintf (key, sizeof (key), "volume%d.username", count);
2748 ret = dict_get_str (vols, key, &str);
2749 if (!ret) {
2750 ret = glusterd_auth_set_username (new_volinfo, str);
2751 if (ret)
2752 goto out;
2753 }
2754
2755 memset (key, 0, sizeof (key));
2756 snprintf (key, sizeof (key), "volume%d.password", count);
2757 ret = dict_get_str (vols, key, &str);
2758 if (!ret) {
2759 ret = glusterd_auth_set_password (new_volinfo, str);
2760 if (ret)
2761 goto out;
2762 }
2763
2764 memset (key, 0, sizeof (key));
2765 snprintf (key, sizeof (key), "volume%d.transport_type", count);
2766 ret = dict_get_uint32 (vols, key, &new_volinfo->transport_type);
2767 if (ret) {
2768 snprintf (msg, sizeof (msg), "%s missing in payload for %s",
2769 key, volname);
2770 goto out;
2771 }
2772
2773 memset (key, 0, sizeof (key));
2774 snprintf (key, sizeof (key), "volume%d.rebalance", count);
2775 ret = dict_get_uint32 (vols, key, &new_volinfo->rebal.defrag_cmd);
2776 if (ret) {
2777 snprintf (msg, sizeof (msg), "%s missing in payload for %s",
2778 key, volname);
2779 goto out;
2780 }
2781
2782 if (new_volinfo->rebal.defrag_cmd) {
2783 memset (key, 0, sizeof (key));
2784 snprintf (key, sizeof (key), "volume%d.rebalance-id", count);
2785 ret = dict_get_str (vols, key, &rebalance_id_str);
2786 if (ret) {
2787 /* This is not present in older glusterfs versions,
2788 * so don't error out
2789 */
2790 ret = 0;
2791 } else {
2792 uuid_parse (rebalance_id_str,
2793 new_volinfo->rebal.rebalance_id);
2794 }
2795 }
2796
2797 memset (key, 0, sizeof (key));
2798 snprintf (key, sizeof (key), "volume%d.rebalance-op", count);
2799 ret = dict_get_uint32 (vols, key,(uint32_t *) &new_volinfo->rebal.op);
2800 if (ret) {
2801 /* This is not present in older glusterfs versions,
2802 * so don't error out
2803 */
2804 ret = 0;
2805 }
2806
2807 memset (key, 0, sizeof (key));
2808 snprintf (key, 256, "volume%d."GLUSTERD_STORE_KEY_RB_STATUS"rb_status", count);
2809 ret = dict_get_int32 (vols, key, &rb_status);
2810 if (ret)
2811 goto out;
2812 new_volinfo->rep_brick.rb_status = rb_status;
2813
2814 if (new_volinfo->rep_brick.rb_status > GF_RB_STATUS_NONE) {
2815
2816 memset (key, 0, sizeof (key));
2817 snprintf (key, 256, "volume%d."GLUSTERD_STORE_KEY_RB_SRC_BRICK"rb_src",
2818 count);
2819 ret = dict_get_str (vols, key, &src_brick);
2820 if (ret)
2821 goto out;
2822
2823 ret = glusterd_brickinfo_new_from_brick (src_brick,
2824 &new_volinfo->rep_brick.src_brick);
2825 if (ret) {
2826 gf_log ("", GF_LOG_ERROR, "Unable to create"do { do { if (0) printf ("Unable to create" " src brickinfo")
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
2827, GF_LOG_ERROR, "Unable to create" " src brickinfo"); } while
(0)
2827 " src brickinfo")do { do { if (0) printf ("Unable to create" " src brickinfo")
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
2827, GF_LOG_ERROR, "Unable to create" " src brickinfo"); } while
(0)
;
2828 goto out;
2829 }
2830
2831 memset (key, 0, sizeof (key));
2832 snprintf (key, 256, "volume%d."GLUSTERD_STORE_KEY_RB_DST_BRICK"rb_dst",
2833 count);
2834 ret = dict_get_str (vols, key, &dst_brick);
2835 if (ret)
2836 goto out;
2837
2838 ret = glusterd_brickinfo_new_from_brick (dst_brick,
2839 &new_volinfo->rep_brick.dst_brick);
2840 if (ret) {
2841 gf_log ("", GF_LOG_ERROR, "Unable to create"do { do { if (0) printf ("Unable to create" " dst brickinfo")
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
2842, GF_LOG_ERROR, "Unable to create" " dst brickinfo"); } while
(0)
2842 " dst brickinfo")do { do { if (0) printf ("Unable to create" " dst brickinfo")
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
2842, GF_LOG_ERROR, "Unable to create" " dst brickinfo"); } while
(0)
;
2843 goto out;
2844 }
2845
2846 memset (key, 0, sizeof (key));
2847 snprintf (key, sizeof (key), "volume%d.rb_id", count);
2848 ret = dict_get_str (vols, key, &rb_id_str);
2849 if (ret) {
2850 /* This is not present in older glusterfs versions,
2851 * so don't error out
2852 */
2853 ret = 0;
2854 } else {
2855 uuid_parse (rb_id_str, new_volinfo->rep_brick.rb_id);
2856 }
2857 }
2858
2859
2860 ret = glusterd_import_friend_volume_opts (vols, count, new_volinfo);
2861 if (ret)
2862 goto out;
2863 ret = glusterd_import_bricks (vols, count, new_volinfo);
2864 if (ret)
2865 goto out;
2866 *volinfo = new_volinfo;
2867out:
2868 if (msg[0])
2869 gf_log ("glusterd", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("glusterd"
, "glusterd-utils.c", __FUNCTION__, 2869, GF_LOG_ERROR, "%s",
msg); } while (0)
;
2870 gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2870, GF_LOG_DEBUG
, "Returning with %d", ret); } while (0)
;
2871 return ret;
2872}
2873
2874int32_t
2875glusterd_volume_disconnect_all_bricks (glusterd_volinfo_t *volinfo)
2876{
2877 int ret = 0;
2878 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
2879 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2879, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
2880
2881 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))))
{
2882 if (glusterd_is_brick_started (brickinfo)) {
2883 ret = glusterd_brick_disconnect (brickinfo);
2884 if (ret) {
2885 gf_log ("glusterd", GF_LOG_ERROR, "Failed to "do { do { if (0) printf ("Failed to " "disconnect %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log ("glusterd"
, "glusterd-utils.c", __FUNCTION__, 2887, GF_LOG_ERROR, "Failed to "
"disconnect %s:%s", brickinfo->hostname, brickinfo->path
); } while (0)
2886 "disconnect %s:%s", brickinfo->hostname,do { do { if (0) printf ("Failed to " "disconnect %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log ("glusterd"
, "glusterd-utils.c", __FUNCTION__, 2887, GF_LOG_ERROR, "Failed to "
"disconnect %s:%s", brickinfo->hostname, brickinfo->path
); } while (0)
2887 brickinfo->path)do { do { if (0) printf ("Failed to " "disconnect %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log ("glusterd"
, "glusterd-utils.c", __FUNCTION__, 2887, GF_LOG_ERROR, "Failed to "
"disconnect %s:%s", brickinfo->hostname, brickinfo->path
); } while (0)
;
2888 break;
2889 }
2890 }
2891 }
2892
2893 return ret;
2894}
2895
2896int32_t
2897glusterd_volinfo_copy_brick_portinfo (glusterd_volinfo_t *new_volinfo,
2898 glusterd_volinfo_t *old_volinfo)
2899{
2900 glusterd_brickinfo_t *new_brickinfo = NULL((void*)0);
2901 glusterd_brickinfo_t *old_brickinfo = NULL((void*)0);
2902
2903 int ret = 0;
2904 GF_ASSERT (new_volinfo)do { if (!(new_volinfo)) { do { do { if (0) printf ("Assertion failed: "
"new_volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2904, GF_LOG_ERROR, "Assertion failed: " "new_volinfo"
); } while (0); } } while (0)
;
2905 GF_ASSERT (old_volinfo)do { if (!(old_volinfo)) { do { do { if (0) printf ("Assertion failed: "
"old_volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2905, GF_LOG_ERROR, "Assertion failed: " "old_volinfo"
); } while (0); } } while (0)
;
2906 if (_gf_false == glusterd_is_volume_started (new_volinfo))
2907 goto out;
2908 list_for_each_entry (new_brickinfo, &new_volinfo->bricks, brick_list)for (new_brickinfo = ((typeof(*new_brickinfo) *)((char *)((&
new_volinfo->bricks)->next)-(unsigned long)(&((typeof
(*new_brickinfo) *)0)->brick_list))); &new_brickinfo->
brick_list != (&new_volinfo->bricks); new_brickinfo = (
(typeof(*new_brickinfo) *)((char *)(new_brickinfo->brick_list
.next)-(unsigned long)(&((typeof(*new_brickinfo) *)0)->
brick_list))))
{
2909 ret = glusterd_volume_brickinfo_get (new_brickinfo->uuid,
2910 new_brickinfo->hostname,
2911 new_brickinfo->path,
2912 old_volinfo, &old_brickinfo);
2913 if ((0 == ret) && glusterd_is_brick_started (old_brickinfo)) {
2914 new_brickinfo->port = old_brickinfo->port;
2915 }
2916 }
2917out:
2918 ret = 0;
2919 return ret;
2920}
2921
2922int32_t
2923glusterd_volinfo_stop_stale_bricks (glusterd_volinfo_t *new_volinfo,
2924 glusterd_volinfo_t *old_volinfo)
2925{
2926 glusterd_brickinfo_t *new_brickinfo = NULL((void*)0);
2927 glusterd_brickinfo_t *old_brickinfo = NULL((void*)0);
2928
2929 int ret = 0;
2930 GF_ASSERT (new_volinfo)do { if (!(new_volinfo)) { do { do { if (0) printf ("Assertion failed: "
"new_volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2930, GF_LOG_ERROR, "Assertion failed: " "new_volinfo"
); } while (0); } } while (0)
;
2931 GF_ASSERT (old_volinfo)do { if (!(old_volinfo)) { do { do { if (0) printf ("Assertion failed: "
"old_volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2931, GF_LOG_ERROR, "Assertion failed: " "old_volinfo"
); } while (0); } } while (0)
;
2932 if (_gf_false == glusterd_is_volume_started (old_volinfo))
2933 goto out;
2934 list_for_each_entry (old_brickinfo, &old_volinfo->bricks, brick_list)for (old_brickinfo = ((typeof(*old_brickinfo) *)((char *)((&
old_volinfo->bricks)->next)-(unsigned long)(&((typeof
(*old_brickinfo) *)0)->brick_list))); &old_brickinfo->
brick_list != (&old_volinfo->bricks); old_brickinfo = (
(typeof(*old_brickinfo) *)((char *)(old_brickinfo->brick_list
.next)-(unsigned long)(&((typeof(*old_brickinfo) *)0)->
brick_list))))
{
2935 ret = glusterd_volume_brickinfo_get (old_brickinfo->uuid,
2936 old_brickinfo->hostname,
2937 old_brickinfo->path,
2938 new_volinfo, &new_brickinfo);
2939 if (ret) {
2940 /*TODO: may need to switch to 'atomic' flavour of
2941 * brick_stop, once we make peer rpc program also
2942 * synctask enabled*/
2943 ret = glusterd_brick_stop (old_volinfo, old_brickinfo,
2944 _gf_false);
2945 if (ret)
2946 gf_log ("glusterd", GF_LOG_ERROR, "Failed to "do { do { if (0) printf ("Failed to " "stop brick %s:%s", old_brickinfo
->hostname, old_brickinfo->path); } while (0); _gf_log (
"glusterd", "glusterd-utils.c", __FUNCTION__, 2948, GF_LOG_ERROR
, "Failed to " "stop brick %s:%s", old_brickinfo->hostname
, old_brickinfo->path); } while (0)
2947 "stop brick %s:%s", old_brickinfo->hostname,do { do { if (0) printf ("Failed to " "stop brick %s:%s", old_brickinfo
->hostname, old_brickinfo->path); } while (0); _gf_log (
"glusterd", "glusterd-utils.c", __FUNCTION__, 2948, GF_LOG_ERROR
, "Failed to " "stop brick %s:%s", old_brickinfo->hostname
, old_brickinfo->path); } while (0)
2948 old_brickinfo->path)do { do { if (0) printf ("Failed to " "stop brick %s:%s", old_brickinfo
->hostname, old_brickinfo->path); } while (0); _gf_log (
"glusterd", "glusterd-utils.c", __FUNCTION__, 2948, GF_LOG_ERROR
, "Failed to " "stop brick %s:%s", old_brickinfo->hostname
, old_brickinfo->path); } while (0)
;
2949 }
2950 }
2951 ret = 0;
2952out:
2953 gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 2953, GF_LOG_DEBUG
, "Returning with %d", ret); } while (0)
;
2954 return ret;
2955}
2956
2957int32_t
2958glusterd_delete_stale_volume (glusterd_volinfo_t *stale_volinfo,
2959 glusterd_volinfo_t *valid_volinfo)
2960{
2961 GF_ASSERT (stale_volinfo)do { if (!(stale_volinfo)) { do { do { if (0) printf ("Assertion failed: "
"stale_volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2961, GF_LOG_ERROR, "Assertion failed: " "stale_volinfo"
); } while (0); } } while (0)
;
2962 GF_ASSERT (valid_volinfo)do { if (!(valid_volinfo)) { do { do { if (0) printf ("Assertion failed: "
"valid_volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 2962, GF_LOG_ERROR, "Assertion failed: " "valid_volinfo"
); } while (0); } } while (0)
;
2963
2964 /* If stale volume is in started state, copy the port numbers of the
2965 * local bricks if they exist in the valid volume information.
2966 * stop stale bricks. Stale volume information is going to be deleted.
2967 * Which deletes the valid brick information inside stale volinfo.
2968 * We dont want brick_rpc_notify to access already deleted brickinfo.
2969 * Disconnect all bricks from stale_volinfo (unconditionally), since
2970 * they are being deleted subsequently.
2971 */
2972 if (glusterd_is_volume_started (stale_volinfo)) {
2973 if (glusterd_is_volume_started (valid_volinfo)) {
2974 (void) glusterd_volinfo_stop_stale_bricks (valid_volinfo,
2975 stale_volinfo);
2976 //Only valid bricks will be running now.
2977 (void) glusterd_volinfo_copy_brick_portinfo (valid_volinfo,
2978 stale_volinfo);
2979
2980 } else {
2981 (void) glusterd_stop_bricks (stale_volinfo);
2982 }
2983
2984 (void) glusterd_volume_disconnect_all_bricks (stale_volinfo);
2985 }
2986 /* Delete all the bricks and stores and vol files. They will be created
2987 * again by the valid_volinfo. Volume store delete should not be
2988 * performed because some of the bricks could still be running,
2989 * keeping pid files under run directory
2990 */
2991 (void) glusterd_delete_all_bricks (stale_volinfo);
2992 if (stale_volinfo->shandle) {
2993 unlink (stale_volinfo->shandle->path);
2994 (void) glusterd_store_handle_destroy (stale_volinfo->shandle);
2995 stale_volinfo->shandle = NULL((void*)0);
2996 }
2997 (void) glusterd_volinfo_delete (stale_volinfo);
2998 return 0;
2999}
3000
3001int32_t
3002glusterd_import_friend_volume (dict_t *vols, size_t count)
3003{
3004
3005 int32_t ret = -1;
3006 glusterd_conf_t *priv = NULL((void*)0);
3007 xlator_t *this = NULL((void*)0);
3008 glusterd_volinfo_t *old_volinfo = NULL((void*)0);
3009 glusterd_volinfo_t *new_volinfo = NULL((void*)0);
3010
3011 GF_ASSERT (vols)do { if (!(vols)) { do { do { if (0) printf ("Assertion failed: "
"vols"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3011, GF_LOG_ERROR, "Assertion failed: " "vols"
); } while (0); } } while (0)
;
3012
3013 this = THIS(*__glusterfs_this_location());
3014 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3014, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
3015 priv = this->private;
3016 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3016, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
3017 ret = glusterd_import_volinfo (vols, count, &new_volinfo);
3018 if (ret)
3019 goto out;
3020
3021 ret = glusterd_volinfo_find (new_volinfo->volname, &old_volinfo);
3022 if (0 == ret) {
3023 (void) glusterd_delete_stale_volume (old_volinfo, new_volinfo);
3024 }
3025
3026 if (glusterd_is_volume_started (new_volinfo)) {
3027 (void) glusterd_start_bricks (new_volinfo);
3028 }
3029
3030 ret = glusterd_store_volinfo (new_volinfo, GLUSTERD_VOLINFO_VER_AC_NONE);
3031 ret = glusterd_create_volfiles_and_notify_services (new_volinfo);
3032 if (ret)
3033 goto out;
3034
3035 gd_update_volume_op_versions (new_volinfo);
3036
3037 list_add_tail (&new_volinfo->vol_list, &priv->volumes);
3038out:
3039 gf_log ("", GF_LOG_DEBUG, "Returning with ret: %d", ret)do { do { if (0) printf ("Returning with ret: %d", ret); } while
(0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 3039, GF_LOG_DEBUG
, "Returning with ret: %d", ret); } while (0)
;
3040 return ret;
3041}
3042
3043int32_t
3044glusterd_import_friend_volumes (dict_t *vols)
3045{
3046 int32_t ret = -1;
3047 int32_t count = 0;
3048 int i = 1;
3049
3050 GF_ASSERT (vols)do { if (!(vols)) { do { do { if (0) printf ("Assertion failed: "
"vols"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3050, GF_LOG_ERROR, "Assertion failed: " "vols"
); } while (0); } } while (0)
;
3051
3052 ret = dict_get_int32 (vols, "count", &count);
3053 if (ret)
3054 goto out;
3055
3056 while (i <= count) {
3057 ret = glusterd_import_friend_volume (vols, i);
3058 if (ret)
3059 goto out;
3060 i++;
3061 }
3062
3063out:
3064 gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 3064, GF_LOG_DEBUG
, "Returning with %d", ret); } while (0)
;
3065 return ret;
3066}
3067
3068int
3069glusterd_get_global_opt_version (dict_t *opts, uint32_t *version)
3070{
3071 int ret = -1;
3072 char *version_str = NULL((void*)0);
3073
3074 ret = dict_get_str (opts, GLUSTERD_GLOBAL_OPT_VERSION"global-option-version", &version_str);
3075 if (ret)
3076 goto out;
3077
3078 ret = gf_string2uint (version_str, version);
3079 if (ret)
3080 goto out;
3081 ret = 0;
3082out:
3083 return ret;
3084}
3085
3086int
3087glusterd_get_next_global_opt_version_str (dict_t *opts, char **version_str)
3088{
3089 int ret = -1;
3090 char version_string[64] = {0};
3091 uint32_t version = 0;
3092
3093 ret = glusterd_get_global_opt_version (opts, &version);
3094 if (ret)
3095 goto out;
3096 version++;
3097 snprintf (version_string, sizeof (version_string), "%"PRIu32"u", version);
3098 *version_str = gf_strdup (version_string);
3099 if (*version_str)
3100 ret = 0;
3101out:
3102 return ret;
3103}
3104
3105int32_t
3106glusterd_import_global_opts (dict_t *friend_data)
3107{
3108 xlator_t *this = NULL((void*)0);
3109 glusterd_conf_t *conf = NULL((void*)0);
3110 int ret = -1;
3111 dict_t *import_options = NULL((void*)0);
3112 int count = 0;
3113 uint32_t local_version = 0;
3114 uint32_t remote_version = 0;
3115
3116 this = THIS(*__glusterfs_this_location());
3117 conf = this->private;
3118
3119 ret = dict_get_int32 (friend_data, "global-opt-count", &count);
3120 if (ret) {
3121 //old version peer
3122 ret = 0;
3123 goto out;
3124 }
3125
3126 import_options = dict_new ();
3127 if (!import_options)
3128 goto out;
3129 ret = import_prdict_dict (friend_data, import_options, "key", "val",
3130 count, "global");
3131 if (ret) {
3132 gf_log (this->name, GF_LOG_ERROR, "Failed to import"do { do { if (0) printf ("Failed to import" " global options"
); } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 3133, GF_LOG_ERROR, "Failed to import" " global options"); }
while (0)
3133 " global options")do { do { if (0) printf ("Failed to import" " global options"
); } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 3133, GF_LOG_ERROR, "Failed to import" " global options"); }
while (0)
;
3134 goto out;
3135 }
3136
3137 ret = glusterd_get_global_opt_version (conf->opts, &local_version);
3138 if (ret)
3139 goto out;
3140 ret = glusterd_get_global_opt_version (import_options, &remote_version);
3141 if (ret)
3142 goto out;
3143 if (remote_version > local_version) {
3144 ret = glusterd_store_options (this, import_options);
3145 if (ret)
3146 goto out;
3147 dict_unref (conf->opts);
3148 conf->opts = dict_ref (import_options);
3149 }
3150 ret = 0;
3151out:
3152 if (import_options)
3153 dict_unref (import_options);
3154 return ret;
3155}
3156
3157int32_t
3158glusterd_compare_friend_data (dict_t *vols, int32_t *status, char *hostname)
3159{
3160 int32_t ret = -1;
3161 int32_t count = 0;
3162 int i = 1;
3163 gf_boolean_t update = _gf_false;
3164 gf_boolean_t stale_nfs = _gf_false;
3165 gf_boolean_t stale_shd = _gf_false;
3166
3167 GF_ASSERT (vols)do { if (!(vols)) { do { do { if (0) printf ("Assertion failed: "
"vols"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3167, GF_LOG_ERROR, "Assertion failed: " "vols"
); } while (0); } } while (0)
;
3168 GF_ASSERT (status)do { if (!(status)) { do { do { if (0) printf ("Assertion failed: "
"status"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3168, GF_LOG_ERROR, "Assertion failed: " "status"
); } while (0); } } while (0)
;
3169
3170 ret = dict_get_int32 (vols, "count", &count);
3171 if (ret)
3172 goto out;
3173
3174 while (i <= count) {
3175 ret = glusterd_compare_friend_volume (vols, i, status,
3176 hostname);
3177 if (ret)
3178 goto out;
3179
3180 if (GLUSTERD_VOL_COMP_RJT == *status) {
3181 ret = 0;
3182 goto out;
3183 }
3184 if (GLUSTERD_VOL_COMP_UPDATE_REQ == *status)
3185 update = _gf_true;
3186
3187 i++;
3188 }
3189
3190 if (update) {
3191 if (glusterd_is_nodesvc_running ("nfs"))
3192 stale_nfs = _gf_true;
3193 if (glusterd_is_nodesvc_running ("glustershd"))
3194 stale_shd = _gf_true;
3195 ret = glusterd_import_global_opts (vols);
3196 if (ret)
3197 goto out;
3198 ret = glusterd_import_friend_volumes (vols);
3199 if (ret)
3200 goto out;
3201 if (_gf_false == glusterd_are_all_volumes_stopped ()) {
3202 ret = glusterd_nodesvcs_handle_graph_change (NULL((void*)0));
3203 } else {
3204 if (stale_nfs)
3205 glusterd_nfs_server_stop ();
3206 if (stale_shd)
3207 glusterd_shd_stop ();
3208 }
3209 }
3210
3211out:
3212 gf_log ("", GF_LOG_DEBUG, "Returning with ret: %d, status: %d",do { do { if (0) printf ("Returning with ret: %d, status: %d"
, ret, *status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 3213, GF_LOG_DEBUG, "Returning with ret: %d, status: %d"
, ret, *status); } while (0)
3213 ret, *status)do { do { if (0) printf ("Returning with ret: %d, status: %d"
, ret, *status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 3213, GF_LOG_DEBUG, "Returning with ret: %d, status: %d"
, ret, *status); } while (0)
;
3214
3215 return ret;
3216}
3217
3218/* Valid only in if service is 'local' to glusterd.
3219 * pid can be -1, if reading pidfile failed */
3220gf_boolean_t
3221glusterd_is_service_running (char *pidfile, int *pid)
3222{
3223 FILE *file = NULL((void*)0);
3224 gf_boolean_t running = _gf_false;
3225 int ret = 0;
3226 int fno = 0;
3227
3228 file = fopen (pidfile, "r+");
3229 if (!file)
3230 goto out;
3231
3232 fno = fileno (file);
3233 ret = lockf (fno, F_TEST3, 0);
3234 if (ret == -1)
3235 running = _gf_true;
3236 if (!pid)
3237 goto out;
3238
3239 ret = fscanf (file, "%d", pid);
3240 if (ret <= 0) {
3241 gf_log ("", GF_LOG_ERROR, "Unable to read pidfile: %s, %s",do { do { if (0) printf ("Unable to read pidfile: %s, %s", pidfile
, strerror ((*__errno_location ()))); } while (0); _gf_log (""
, "glusterd-utils.c", __FUNCTION__, 3242, GF_LOG_ERROR, "Unable to read pidfile: %s, %s"
, pidfile, strerror ((*__errno_location ()))); } while (0)
3242 pidfile, strerror (errno))do { do { if (0) printf ("Unable to read pidfile: %s, %s", pidfile
, strerror ((*__errno_location ()))); } while (0); _gf_log (""
, "glusterd-utils.c", __FUNCTION__, 3242, GF_LOG_ERROR, "Unable to read pidfile: %s, %s"
, pidfile, strerror ((*__errno_location ()))); } while (0)
;
3243 *pid = -1;
3244 }
3245
3246out:
3247 if (file)
3248 fclose (file);
3249 return running;
3250}
3251
3252void
3253glusterd_get_nodesvc_dir (char *server, char *workdir,
3254 char *path, size_t len)
3255{
3256 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-utils.c"
, __FUNCTION__, 3256, GF_LOG_ERROR, "Assertion failed: " "len == PATH_MAX"
); } while (0); } } while (0)
;
3257 snprintf (path, len, "%s/%s", workdir, server);
3258}
3259
3260void
3261glusterd_get_nodesvc_rundir (char *server, char *workdir,
3262 char *path, size_t len)
3263{
3264 char dir[PATH_MAX4096] = {0};
3265 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-utils.c"
, __FUNCTION__, 3265, GF_LOG_ERROR, "Assertion failed: " "len == PATH_MAX"
); } while (0); } } while (0)
;
3266
3267 glusterd_get_nodesvc_dir (server, workdir, dir, sizeof (dir));
3268 snprintf (path, len, "%s/run", dir);
3269}
3270
3271void
3272glusterd_get_nodesvc_pidfile (char *server, char *workdir,
3273 char *path, size_t len)
3274{
3275 char dir[PATH_MAX4096] = {0};
3276 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-utils.c"
, __FUNCTION__, 3276, GF_LOG_ERROR, "Assertion failed: " "len == PATH_MAX"
); } while (0); } } while (0)
;
3277
3278 glusterd_get_nodesvc_rundir (server, workdir, dir, sizeof (dir));
3279 snprintf (path, len, "%s/%s.pid", dir, server);
3280}
3281
3282void
3283glusterd_get_nodesvc_volfile (char *server, char *workdir,
3284 char *volfile, size_t len)
3285{
3286 char dir[PATH_MAX4096] = {0,};
3287 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-utils.c"
, __FUNCTION__, 3287, GF_LOG_ERROR, "Assertion failed: " "len == PATH_MAX"
); } while (0); } } while (0)
;
3288
3289 glusterd_get_nodesvc_dir (server, workdir, dir, sizeof (dir));
3290 snprintf (volfile, len, "%s/%s-server.vol", dir, server);
3291}
3292
3293void
3294glusterd_nodesvc_set_online_status (char *server, gf_boolean_t status)
3295{
3296 glusterd_conf_t *priv = NULL((void*)0);
3297
3298 GF_ASSERT (server)do { if (!(server)) { do { do { if (0) printf ("Assertion failed: "
"server"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3298, GF_LOG_ERROR, "Assertion failed: " "server"
); } while (0); } } while (0)
;
3299 priv = THIS(*__glusterfs_this_location())->private;
3300 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3300, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
3301 GF_ASSERT (priv->shd)do { if (!(priv->shd)) { do { do { if (0) printf ("Assertion failed: "
"priv->shd"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3301, GF_LOG_ERROR, "Assertion failed: " "priv->shd"
); } while (0); } } while (0)
;
3302 GF_ASSERT (priv->nfs)do { if (!(priv->nfs)) { do { do { if (0) printf ("Assertion failed: "
"priv->nfs"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3302, GF_LOG_ERROR, "Assertion failed: " "priv->nfs"
); } while (0); } } while (0)
;
3303
3304 if (!strcmp("glustershd", server))
3305 priv->shd->online = status;
3306 else if (!strcmp ("nfs", server))
3307 priv->nfs->online = status;
3308}
3309
3310gf_boolean_t
3311glusterd_is_nodesvc_online (char *server)
3312{
3313 glusterd_conf_t *conf = NULL((void*)0);
3314 gf_boolean_t online = _gf_false;
3315
3316 GF_ASSERT (server)do { if (!(server)) { do { do { if (0) printf ("Assertion failed: "
"server"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3316, GF_LOG_ERROR, "Assertion failed: " "server"
); } while (0); } } while (0)
;
3317 conf = THIS(*__glusterfs_this_location())->private;
3318 GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: "
"conf"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3318, GF_LOG_ERROR, "Assertion failed: " "conf"
); } while (0); } } while (0)
;
3319 GF_ASSERT (conf->shd)do { if (!(conf->shd)) { do { do { if (0) printf ("Assertion failed: "
"conf->shd"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3319, GF_LOG_ERROR, "Assertion failed: " "conf->shd"
); } while (0); } } while (0)
;
3320 GF_ASSERT (conf->nfs)do { if (!(conf->nfs)) { do { do { if (0) printf ("Assertion failed: "
"conf->nfs"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3320, GF_LOG_ERROR, "Assertion failed: " "conf->nfs"
); } while (0); } } while (0)
;
3321
3322 if (!strcmp (server, "glustershd"))
3323 online = conf->shd->online;
3324 else if (!strcmp (server, "nfs"))
3325 online = conf->nfs->online;
3326
3327 return online;
3328}
3329
3330int32_t
3331glusterd_nodesvc_set_socket_filepath (char *rundir, uuid_t uuid,
3332 char *socketpath, int len)
3333{
3334 char sockfilepath[PATH_MAX4096] = {0,};
3335
3336 snprintf (sockfilepath, sizeof (sockfilepath), "%s/run-%s",
3337 rundir, uuid_utoa (uuid));
3338
3339 glusterd_set_socket_filepath (sockfilepath, socketpath, len);
3340 return 0;
3341}
3342
3343struct rpc_clnt*
3344glusterd_pending_node_get_rpc (glusterd_pending_node_t *pending_node)
3345{
3346 struct rpc_clnt *rpc = NULL((void*)0);
3347 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
3348 nodesrv_t *shd = NULL((void*)0);
3349 glusterd_volinfo_t *volinfo = NULL((void*)0);
3350 nodesrv_t *nfs = NULL((void*)0);
3351
3352 GF_VALIDATE_OR_GOTO (THIS->name, pending_node, out)do { if (!pending_node) { (*__errno_location ()) = 22; do { do
{ if (0) printf ("invalid argument: " "pending_node"); } while
(0); _gf_log_callingfn ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 3352, GF_LOG_ERROR, "invalid argument: "
"pending_node"); } while (0); goto out; } } while (0)
;
3353 GF_VALIDATE_OR_GOTO (THIS->name, pending_node->node, out)do { if (!pending_node->node) { (*__errno_location ()) = 22
; do { do { if (0) printf ("invalid argument: " "pending_node->node"
); } while (0); _gf_log_callingfn ((*__glusterfs_this_location
())->name, "glusterd-utils.c", __FUNCTION__, 3353, GF_LOG_ERROR
, "invalid argument: " "pending_node->node"); } while (0);
goto out; } } while (0)
;
3354
3355 if (pending_node->type == GD_NODE_BRICK) {
3356 brickinfo = pending_node->node;
3357 rpc = brickinfo->rpc;
3358
3359 } else if (pending_node->type == GD_NODE_SHD) {
3360 shd = pending_node->node;
3361 rpc = shd->rpc;
3362
3363 } else if (pending_node->type == GD_NODE_REBALANCE) {
3364 volinfo = pending_node->node;
3365 if (volinfo->rebal.defrag)
3366 rpc = volinfo->rebal.defrag->rpc;
3367
3368 } else if (pending_node->type == GD_NODE_NFS) {
3369 nfs = pending_node->node;
3370 rpc = nfs->rpc;
3371
3372 } else {
3373 GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: "
"0"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3373, GF_LOG_ERROR, "Assertion failed: " "0")
; } while (0); } } while (0)
;
3374 }
3375
3376out:
3377 return rpc;
3378}
3379
3380struct rpc_clnt*
3381glusterd_nodesvc_get_rpc (char *server)
3382{
3383 glusterd_conf_t *priv = NULL((void*)0);
3384 struct rpc_clnt *rpc = NULL((void*)0);
3385
3386 GF_ASSERT (server)do { if (!(server)) { do { do { if (0) printf ("Assertion failed: "
"server"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3386, GF_LOG_ERROR, "Assertion failed: " "server"
); } while (0); } } while (0)
;
3387 priv = THIS(*__glusterfs_this_location())->private;
3388 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3388, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
3389 GF_ASSERT (priv->shd)do { if (!(priv->shd)) { do { do { if (0) printf ("Assertion failed: "
"priv->shd"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3389, GF_LOG_ERROR, "Assertion failed: " "priv->shd"
); } while (0); } } while (0)
;
3390 GF_ASSERT (priv->nfs)do { if (!(priv->nfs)) { do { do { if (0) printf ("Assertion failed: "
"priv->nfs"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3390, GF_LOG_ERROR, "Assertion failed: " "priv->nfs"
); } while (0); } } while (0)
;
3391
3392 if (!strcmp (server, "glustershd"))
3393 rpc = priv->shd->rpc;
3394 else if (!strcmp (server, "nfs"))
3395 rpc = priv->nfs->rpc;
3396
3397 return rpc;
3398}
3399
3400int32_t
3401glusterd_nodesvc_set_rpc (char *server, struct rpc_clnt *rpc)
3402{
3403 int ret = 0;
3404 xlator_t *this = NULL((void*)0);
3405 glusterd_conf_t *priv = NULL((void*)0);
3406
3407 this = THIS(*__glusterfs_this_location());
3408 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3408, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
3409 priv = this->private;
3410 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3410, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
3411 GF_ASSERT (priv->shd)do { if (!(priv->shd)) { do { do { if (0) printf ("Assertion failed: "
"priv->shd"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3411, GF_LOG_ERROR, "Assertion failed: " "priv->shd"
); } while (0); } } while (0)
;
3412 GF_ASSERT (priv->nfs)do { if (!(priv->nfs)) { do { do { if (0) printf ("Assertion failed: "
"priv->nfs"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3412, GF_LOG_ERROR, "Assertion failed: " "priv->nfs"
); } while (0); } } while (0)
;
3413
3414 if (!strcmp ("glustershd", server))
3415 priv->shd->rpc = rpc;
3416 else if (!strcmp ("nfs", server))
3417 priv->nfs->rpc = rpc;
3418
3419 return ret;
3420}
3421
3422int32_t
3423glusterd_nodesvc_connect (char *server, char *socketpath) {
3424 int ret = 0;
3425 dict_t *options = NULL((void*)0);
3426 struct rpc_clnt *rpc = NULL((void*)0);
3427 glusterd_conf_t *priv = THIS(*__glusterfs_this_location())->private;
3428
3429 rpc = glusterd_nodesvc_get_rpc (server);
3430
3431 if (rpc == NULL((void*)0)) {
3432 /* Setting frame-timeout to 10mins (600seconds).
3433 * Unix domain sockets ensures that the connection is reliable.
3434 * The default timeout of 30mins used for unreliable network
3435 * connections is too long for unix domain socket connections.
3436 */
3437 ret = rpc_clnt_transport_unix_options_build (&options,
3438 socketpath, 600);
3439 if (ret)
3440 goto out;
3441 synclock_unlock (&priv->big_lock);
3442 ret = glusterd_rpc_create (&rpc, options,
3443 glusterd_nodesvc_rpc_notify,
3444 server);
3445 synclock_lock (&priv->big_lock);
3446 if (ret)
3447 goto out;
3448 (void) glusterd_nodesvc_set_rpc (server, rpc);
3449 }
3450out:
3451 return ret;
3452}
3453
3454int32_t
3455glusterd_nodesvc_disconnect (char *server)
3456{
3457 struct rpc_clnt *rpc = NULL((void*)0);
3458
3459 rpc = glusterd_nodesvc_get_rpc (server);
3460
3461 if (rpc) {
3462 rpc_clnt_connection_cleanup (&rpc->conn);
3463 rpc_clnt_unref (rpc);
3464 (void)glusterd_nodesvc_set_rpc (server, NULL((void*)0));
3465 }
3466
3467 return 0;
3468}
3469
3470int32_t
3471glusterd_nodesvc_start (char *server)
3472{
3473 int32_t ret = -1;
3474 xlator_t *this = NULL((void*)0);
3475 glusterd_conf_t *priv = NULL((void*)0);
3476 runner_t runner = {0,};
3477 char pidfile[PATH_MAX4096] = {0,};
3478 char logfile[PATH_MAX4096] = {0,};
3479 char volfile[PATH_MAX4096] = {0,};
3480 char rundir[PATH_MAX4096] = {0,};
3481 char sockfpath[PATH_MAX4096] = {0,};
3482 char volfileid[256] = {0};
3483 char glusterd_uuid_option[1024] = {0};
3484 char valgrind_logfile[PATH_MAX4096] = {0};
3485
3486 this = THIS(*__glusterfs_this_location());
3487 GF_ASSERT(this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3487, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
3488
3489 priv = this->private;
3490
3491 glusterd_get_nodesvc_rundir (server, priv->workdir,
3492 rundir, sizeof (rundir));
3493 ret = mkdir (rundir, 0777);
3494
3495 if ((ret == -1) && (EEXIST17 != errno(*__errno_location ()))) {
3496 gf_log ("", GF_LOG_ERROR, "Unable to create rundir %s",do { do { if (0) printf ("Unable to create rundir %s", rundir
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 3497, GF_LOG_ERROR, "Unable to create rundir %s", rundir); }
while (0)
3497 rundir)do { do { if (0) printf ("Unable to create rundir %s", rundir
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 3497, GF_LOG_ERROR, "Unable to create rundir %s", rundir); }
while (0)
;
3498 goto out;
3499 }
3500
3501 glusterd_get_nodesvc_pidfile (server, priv->workdir,
3502 pidfile, sizeof (pidfile));
3503 glusterd_get_nodesvc_volfile (server, priv->workdir,
3504 volfile, sizeof (volfile));
3505 ret = access (volfile, F_OK0);
3506 if (ret) {
3507 gf_log ("", GF_LOG_ERROR, "%s Volfile %s is not present",do { do { if (0) printf ("%s Volfile %s is not present", server
, volfile); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 3508, GF_LOG_ERROR, "%s Volfile %s is not present", server,
volfile); } while (0)
3508 server, volfile)do { do { if (0) printf ("%s Volfile %s is not present", server
, volfile); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 3508, GF_LOG_ERROR, "%s Volfile %s is not present", server,
volfile); } while (0)
;
3509 goto out;
3510 }
3511
3512 snprintf (logfile, PATH_MAX4096, "%s/%s.log", DEFAULT_LOG_FILE_DIRECTORY"/usr/local/var" "/log/glusterfs",
3513 server);
3514 snprintf (volfileid, sizeof (volfileid), "gluster/%s", server);
3515
3516 glusterd_nodesvc_set_socket_filepath (rundir, MY_UUID(__glusterd_uuid()),
3517 sockfpath, sizeof (sockfpath));
3518
3519 runinit (&runner);
3520
3521 if (priv->valgrind) {
3522 snprintf (valgrind_logfile, PATH_MAX4096,
3523 "%s/valgrind-%s.log",
3524 DEFAULT_LOG_FILE_DIRECTORY"/usr/local/var" "/log/glusterfs",
3525 server);
3526
3527 runner_add_args (&runner, "valgrind", "--leak-check=full",
3528 "--trace-children=yes", "--track-origins=yes",
3529 NULL((void*)0));
3530 runner_argprintf (&runner, "--log-file=%s", valgrind_logfile);
3531 }
3532
3533 runner_add_args (&runner, SBIN_DIR"/usr/local/sbin""/glusterfs",
3534 "-s", "localhost",
3535 "--volfile-id", volfileid,
3536 "-p", pidfile,
3537 "-l", logfile,
3538 "-S", sockfpath, NULL((void*)0));
3539
3540 if (!strcmp (server, "glustershd")) {
3541 snprintf (glusterd_uuid_option, sizeof (glusterd_uuid_option),
3542 "*replicate*.node-uuid=%s", uuid_utoa (MY_UUID(__glusterd_uuid())));
3543 runner_add_args (&runner, "--xlator-option",
3544 glusterd_uuid_option, NULL((void*)0));
3545 }
3546 runner_log (&runner, "", GF_LOG_DEBUG,
3547 "Starting the nfs/glustershd services");
3548
3549 ret = runner_run_nowait (&runner);
3550 if (ret == 0) {
3551 glusterd_nodesvc_connect (server, sockfpath);
3552 }
3553out:
3554 return ret;
3555}
3556
3557int
3558glusterd_nfs_server_start ()
3559{
3560 return glusterd_nodesvc_start ("nfs");
3561}
3562
3563int
3564glusterd_shd_start ()
3565{
3566 return glusterd_nodesvc_start ("glustershd");
3567}
3568
3569gf_boolean_t
3570glusterd_is_nodesvc_running (char *server)
3571{
3572 char pidfile[PATH_MAX4096] = {0,};
3573 glusterd_conf_t *priv = THIS(*__glusterfs_this_location())->private;
3574
3575 glusterd_get_nodesvc_pidfile (server, priv->workdir,
3576 pidfile, sizeof (pidfile));
3577 return glusterd_is_service_running (pidfile, NULL((void*)0));
3578}
3579
3580int32_t
3581glusterd_nodesvc_unlink_socket_file (char *server)
3582{
3583 int ret = 0;
3584 char sockfpath[PATH_MAX4096] = {0,};
3585 char rundir[PATH_MAX4096] = {0,};
3586 glusterd_conf_t *priv = THIS(*__glusterfs_this_location())->private;
3587
3588 glusterd_get_nodesvc_rundir (server, priv->workdir,
3589 rundir, sizeof (rundir));
3590
3591 glusterd_nodesvc_set_socket_filepath (rundir, MY_UUID(__glusterd_uuid()),
3592 sockfpath, sizeof (sockfpath));
3593
3594 ret = unlink (sockfpath);
3595 if (ret && (ENOENT2 == errno(*__errno_location ()))) {
3596 ret = 0;
3597 } else {
3598 gf_log (THIS->name, GF_LOG_ERROR, "Failed to remove %s"do { do { if (0) printf ("Failed to remove %s" " error: %s", sockfpath
, strerror ((*__errno_location ()))); } while (0); _gf_log ((
*__glusterfs_this_location())->name, "glusterd-utils.c", __FUNCTION__
, 3599, GF_LOG_ERROR, "Failed to remove %s" " error: %s", sockfpath
, strerror ((*__errno_location ()))); } while (0)
3599 " error: %s", sockfpath, strerror (errno))do { do { if (0) printf ("Failed to remove %s" " error: %s", sockfpath
, strerror ((*__errno_location ()))); } while (0); _gf_log ((
*__glusterfs_this_location())->name, "glusterd-utils.c", __FUNCTION__
, 3599, GF_LOG_ERROR, "Failed to remove %s" " error: %s", sockfpath
, strerror ((*__errno_location ()))); } while (0)
;
3600 }
3601
3602 return ret;
3603}
3604
3605int32_t
3606glusterd_nodesvc_stop (char *server, int sig)
3607{
3608 char pidfile[PATH_MAX4096] = {0,};
3609 glusterd_conf_t *priv = THIS(*__glusterfs_this_location())->private;
3610 int ret = 0;
3611
3612 if (!glusterd_is_nodesvc_running (server))
3613 goto out;
3614
3615 (void)glusterd_nodesvc_disconnect (server);
3616
3617 glusterd_get_nodesvc_pidfile (server, priv->workdir,
3618 pidfile, sizeof (pidfile));
3619 ret = glusterd_service_stop (server, pidfile, sig, _gf_true);
3620
3621 if (ret == 0) {
3622 glusterd_nodesvc_set_online_status (server, _gf_false);
3623 (void)glusterd_nodesvc_unlink_socket_file (server);
3624 }
3625out:
3626 return ret;
3627}
3628
3629void
3630glusterd_nfs_pmap_deregister ()
3631{
3632 if (pmap_unset (MOUNT_PROGRAM100005, MOUNTV3_VERSION3))
3633 gf_log ("", GF_LOG_INFO, "De-registered MOUNTV3 successfully")do { do { if (0) printf ("De-registered MOUNTV3 successfully"
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 3633, GF_LOG_INFO, "De-registered MOUNTV3 successfully"); }
while (0)
;
3634 else
3635 gf_log ("", GF_LOG_ERROR, "De-register MOUNTV3 is unsuccessful")do { do { if (0) printf ("De-register MOUNTV3 is unsuccessful"
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 3635, GF_LOG_ERROR, "De-register MOUNTV3 is unsuccessful");
} while (0)
;
3636
3637 if (pmap_unset (MOUNT_PROGRAM100005, MOUNTV1_VERSION1))
3638 gf_log ("", GF_LOG_INFO, "De-registered MOUNTV1 successfully")do { do { if (0) printf ("De-registered MOUNTV1 successfully"
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 3638, GF_LOG_INFO, "De-registered MOUNTV1 successfully"); }
while (0)
;
3639 else
3640 gf_log ("", GF_LOG_ERROR, "De-register MOUNTV1 is unsuccessful")do { do { if (0) printf ("De-register MOUNTV1 is unsuccessful"
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 3640, GF_LOG_ERROR, "De-register MOUNTV1 is unsuccessful");
} while (0)
;
3641
3642 if (pmap_unset (NFS_PROGRAM100003, NFSV3_VERSION3))
3643 gf_log ("", GF_LOG_INFO, "De-registered NFSV3 successfully")do { do { if (0) printf ("De-registered NFSV3 successfully");
} while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 3643
, GF_LOG_INFO, "De-registered NFSV3 successfully"); } while (
0)
;
3644 else
3645 gf_log ("", GF_LOG_ERROR, "De-register NFSV3 is unsuccessful")do { do { if (0) printf ("De-register NFSV3 is unsuccessful")
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
3645, GF_LOG_ERROR, "De-register NFSV3 is unsuccessful"); } while
(0)
;
3646
3647 if (pmap_unset (NLM_PROGRAM100021, NLMV4_VERSION4))
3648 gf_log ("", GF_LOG_INFO, "De-registered NLM v4 successfully")do { do { if (0) printf ("De-registered NLM v4 successfully")
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
3648, GF_LOG_INFO, "De-registered NLM v4 successfully"); } while
(0)
;
3649 else
3650 gf_log ("", GF_LOG_ERROR, "De-registration of NLM v4 failed")do { do { if (0) printf ("De-registration of NLM v4 failed");
} while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 3650
, GF_LOG_ERROR, "De-registration of NLM v4 failed"); } while (
0)
;
3651
3652 if (pmap_unset (NLM_PROGRAM100021, NLMV1_VERSION1))
3653 gf_log ("", GF_LOG_INFO, "De-registered NLM v1 successfully")do { do { if (0) printf ("De-registered NLM v1 successfully")
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
3653, GF_LOG_INFO, "De-registered NLM v1 successfully"); } while
(0)
;
3654 else
3655 gf_log ("", GF_LOG_ERROR, "De-registration of NLM v1 failed")do { do { if (0) printf ("De-registration of NLM v1 failed");
} while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 3655
, GF_LOG_ERROR, "De-registration of NLM v1 failed"); } while (
0)
;
3656
3657}
3658
3659int
3660glusterd_nfs_server_stop ()
3661{
3662 int ret = 0;
3663 gf_boolean_t deregister = _gf_false;
3664
3665 if (glusterd_is_nodesvc_running ("nfs"))
3666 deregister = _gf_true;
3667 ret = glusterd_nodesvc_stop ("nfs", SIGKILL9);
3668 if (ret)
3669 goto out;
3670 if (deregister)
3671 glusterd_nfs_pmap_deregister ();
3672out:
3673 return ret;
3674}
3675
3676int
3677glusterd_shd_stop ()
3678{
3679 return glusterd_nodesvc_stop ("glustershd", SIGTERM15);
3680}
3681
3682int
3683glusterd_add_node_to_dict (char *server, dict_t *dict, int count,
3684 dict_t *vol_opts)
3685{
3686 int ret = -1;
3687 glusterd_conf_t *priv = THIS(*__glusterfs_this_location())->private;
3688 char pidfile[PATH_MAX4096] = {0,};
3689 gf_boolean_t running = _gf_false;
3690 int pid = -1;
3691 int port = 0;
3692 char key[1024] = {0,};
3693
3694 glusterd_get_nodesvc_pidfile (server, priv->workdir, pidfile,
3695 sizeof (pidfile));
3696 //Consider service to be running only when glusterd sees it Online
3697 if (glusterd_is_nodesvc_online (server))
3698 running = glusterd_is_service_running (pidfile, &pid);
3699
3700 /* For nfs-servers/self-heal-daemon setting
3701 * brick<n>.hostname = "NFS Server" / "Self-heal Daemon"
3702 * brick<n>.path = uuid
3703 * brick<n>.port = 0
3704 *
3705 * This might be confusing, but cli displays the name of
3706 * the brick as hostname+path, so this will make more sense
3707 * when output.
3708 */
3709 snprintf (key, sizeof (key), "brick%d.hostname", count);
3710 if (!strcmp (server, "nfs"))
3711 ret = dict_set_str (dict, key, "NFS Server");
3712 else if (!strcmp (server, "glustershd"))
3713 ret = dict_set_str (dict, key, "Self-heal Daemon");
3714 if (ret)
3715 goto out;
3716
3717 memset (key, 0, sizeof (key));
3718 snprintf (key, sizeof (key), "brick%d.path", count);
3719 ret = dict_set_dynstr (dict, key, gf_strdup (uuid_utoa (MY_UUID(__glusterd_uuid()))));
3720 if (ret)
3721 goto out;
3722
3723 memset (key, 0, sizeof (key));
3724 snprintf (key, sizeof (key), "brick%d.port", count);
3725 /* Port is available only for the NFS server.
3726 * Self-heal daemon doesn't provide any port for access
3727 * by entities other than gluster.
3728 */
3729 if (!strcmp (server, "nfs")) {
3730 if (dict_get (vol_opts, "nfs.port")) {
3731 ret = dict_get_int32 (vol_opts, "nfs.port", &port);
3732 if (ret)
3733 goto out;
3734 } else
3735 port = GF_NFS3_PORT2049;
3736 }
3737 ret = dict_set_int32 (dict, key, port);
3738 if (ret)
3739 goto out;
3740
3741 memset (key, 0, sizeof (key));
3742 snprintf (key, sizeof (key), "brick%d.pid", count);
3743 ret = dict_set_int32 (dict, key, pid);
3744 if (ret)
3745 goto out;
3746
3747 memset (key, 0, sizeof (key));
3748 snprintf (key, sizeof (key), "brick%d.status", count);
3749 ret = dict_set_int32 (dict, key, running);
3750 if (ret)
3751 goto out;
3752
3753
3754out:
3755 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-utils.c"
, __FUNCTION__, 3755, GF_LOG_DEBUG, "Returning %d", ret); } while
(0)
;
3756 return ret;
3757}
3758
3759int
3760glusterd_remote_hostname_get (rpcsvc_request_t *req, char *remote_host, int len)
3761{
3762 GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: "
"req"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3762, GF_LOG_ERROR, "Assertion failed: " "req"
); } while (0); } } while (0)
;
3763 GF_ASSERT (remote_host)do { if (!(remote_host)) { do { do { if (0) printf ("Assertion failed: "
"remote_host"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3763, GF_LOG_ERROR, "Assertion failed: " "remote_host"
); } while (0); } } while (0)
;
3764 GF_ASSERT (req->trans)do { if (!(req->trans)) { do { do { if (0) printf ("Assertion failed: "
"req->trans"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3764, GF_LOG_ERROR, "Assertion failed: " "req->trans"
); } while (0); } } while (0)
;
3765
3766 char *name = NULL((void*)0);
3767 char *hostname = NULL((void*)0);
3768 char *tmp_host = NULL((void*)0);
3769 int ret = 0;
3770
3771 name = req->trans->peerinfo.identifier;
3772 tmp_host = gf_strdup (name);
3773 if (tmp_host)
3774 get_host_name (tmp_host, &hostname);
3775
3776 GF_ASSERT (hostname)do { if (!(hostname)) { do { do { if (0) printf ("Assertion failed: "
"hostname"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3776, GF_LOG_ERROR, "Assertion failed: " "hostname"
); } while (0); } } while (0)
;
3777 if (!hostname) {
3778 memset (remote_host, 0, len);
3779 ret = -1;
3780 goto out;
3781 }
3782
3783 strncpy (remote_host, hostname, strlen (hostname));
3784
3785
3786out:
3787 GF_FREE (tmp_host)__gf_free (tmp_host);
3788 return ret;
3789}
3790
3791int
3792glusterd_check_generate_start_service (int (*create_volfile) (),
3793 int (*stop) (), int (*start) ())
3794{
3795 int ret = -1;
3796
3797 ret = create_volfile ();
3798 if (ret)
3799 goto out;
3800
3801 ret = stop ();
3802 if (ret)
3803 goto out;
3804
3805 ret = start ();
3806out:
3807 return ret;
3808}
3809
3810int
3811glusterd_reconfigure_nodesvc (int (*create_volfile) ())
3812{
3813 int ret = -1;
3814
3815 ret = create_volfile ();
3816 if (ret)
3817 goto out;
3818
3819 ret = glusterd_fetchspec_notify (THIS(*__glusterfs_this_location()));
3820out:
3821 return ret;
3822}
3823
3824int
3825glusterd_reconfigure_shd ()
3826{
3827 int (*create_volfile) () = glusterd_create_shd_volfile;
3828 return glusterd_reconfigure_nodesvc (create_volfile);
3829}
3830
3831int
3832glusterd_reconfigure_nfs ()
3833{
3834 int ret = -1;
3835 gf_boolean_t identical = _gf_false;
3836
3837 ret = glusterd_check_nfs_volfile_identical (&identical);
3838 if (ret)
3839 goto out;
3840
3841 if (identical) {
3842 ret = 0;
3843 goto out;
3844 }
3845
3846 ret = glusterd_check_generate_start_nfs ();
3847
3848out:
3849 return ret;
3850}
3851
3852
3853int
3854glusterd_check_generate_start_nfs ()
3855{
3856 int ret = 0;
3857
3858 ret = glusterd_check_generate_start_service (glusterd_create_nfs_volfile,
3859 glusterd_nfs_server_stop,
3860 glusterd_nfs_server_start);
3861 return ret;
3862}
3863
3864int
3865glusterd_check_generate_start_shd ()
3866{
3867 int ret = 0;
3868
3869 ret = glusterd_check_generate_start_service (glusterd_create_shd_volfile,
3870 glusterd_shd_stop,
3871 glusterd_shd_start);
3872 if (ret == -EINVAL22)
3873 ret = 0;
3874 return ret;
3875}
3876
3877int
3878glusterd_nodesvcs_batch_op (glusterd_volinfo_t *volinfo,
3879 int (*nfs_op) (), int (*shd_op) ())
3880{
3881 int ret = 0;
3882
3883 ret = nfs_op ();
3884 if (ret)
3885 goto out;
3886
3887 if (volinfo && !glusterd_is_volume_replicate (volinfo))
3888 goto out;
3889
3890 ret = shd_op ();
3891 if (ret)
3892 goto out;
3893out:
3894 return ret;
3895}
3896
3897int
3898glusterd_nodesvcs_start (glusterd_volinfo_t *volinfo)
3899{
3900 return glusterd_nodesvcs_batch_op (volinfo,
3901 glusterd_nfs_server_start,
3902 glusterd_shd_start);
3903}
3904
3905int
3906glusterd_nodesvcs_stop (glusterd_volinfo_t *volinfo)
3907{
3908 return glusterd_nodesvcs_batch_op (volinfo,
3909 glusterd_nfs_server_stop,
3910 glusterd_shd_stop);
3911}
3912
3913gf_boolean_t
3914glusterd_are_all_volumes_stopped ()
3915{
3916 glusterd_conf_t *priv = NULL((void*)0);
3917 xlator_t *this = NULL((void*)0);
3918 glusterd_volinfo_t *voliter = NULL((void*)0);
3919
3920 this = THIS(*__glusterfs_this_location());
3921 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3921, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
3922 priv = this->private;
3923 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3923, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
3924
3925 list_for_each_entry (voliter, &priv->volumes, vol_list)for (voliter = ((typeof(*voliter) *)((char *)((&priv->
volumes)->next)-(unsigned long)(&((typeof(*voliter) *)
0)->vol_list))); &voliter->vol_list != (&priv->
volumes); voliter = ((typeof(*voliter) *)((char *)(voliter->
vol_list.next)-(unsigned long)(&((typeof(*voliter) *)0)->
vol_list))))
{
3926 if (voliter->status == GLUSTERD_STATUS_STARTED)
3927 return _gf_false;
3928 }
3929
3930 return _gf_true;
3931
3932}
3933
3934gf_boolean_t
3935glusterd_all_replicate_volumes_stopped ()
3936{
3937 glusterd_conf_t *priv = NULL((void*)0);
3938 xlator_t *this = NULL((void*)0);
3939 glusterd_volinfo_t *voliter = NULL((void*)0);
3940
3941 this = THIS(*__glusterfs_this_location());
3942 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3942, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
3943 priv = this->private;
3944 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3944, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
3945
3946 list_for_each_entry (voliter, &priv->volumes, vol_list)for (voliter = ((typeof(*voliter) *)((char *)((&priv->
volumes)->next)-(unsigned long)(&((typeof(*voliter) *)
0)->vol_list))); &voliter->vol_list != (&priv->
volumes); voliter = ((typeof(*voliter) *)((char *)(voliter->
vol_list.next)-(unsigned long)(&((typeof(*voliter) *)0)->
vol_list))))
{
3947 if (!glusterd_is_volume_replicate (voliter))
3948 continue;
3949 if (voliter->status == GLUSTERD_STATUS_STARTED)
3950 return _gf_false;
3951 }
3952
3953 return _gf_true;
3954}
3955
3956int
3957glusterd_nodesvcs_handle_graph_change (glusterd_volinfo_t *volinfo)
3958{
3959 int (*shd_op) () = NULL((void*)0);
3960 int (*nfs_op) () = NULL((void*)0);
3961
3962 shd_op = glusterd_check_generate_start_shd;
3963 nfs_op = glusterd_check_generate_start_nfs;
3964 if (glusterd_are_all_volumes_stopped ()) {
3965 shd_op = glusterd_shd_stop;
3966 nfs_op = glusterd_nfs_server_stop;
3967 } else if (glusterd_all_replicate_volumes_stopped()) {
3968 shd_op = glusterd_shd_stop;
3969 }
3970 return glusterd_nodesvcs_batch_op (volinfo, nfs_op, shd_op);
3971}
3972
3973int
3974glusterd_nodesvcs_handle_reconfigure (glusterd_volinfo_t *volinfo)
3975{
3976 return glusterd_nodesvcs_batch_op (volinfo,
3977 glusterd_reconfigure_nfs,
3978 glusterd_reconfigure_shd);
3979}
3980
3981int
3982glusterd_volume_count_get (void)
3983{
3984 glusterd_volinfo_t *tmp_volinfo = NULL((void*)0);
3985 int32_t ret = 0;
3986 xlator_t *this = NULL((void*)0);
3987 glusterd_conf_t *priv = NULL((void*)0);
3988
3989 this = THIS(*__glusterfs_this_location());
3990 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 3990, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
3991
3992 priv = this->private;
3993
3994 list_for_each_entry (tmp_volinfo, &priv->volumes, vol_list)for (tmp_volinfo = ((typeof(*tmp_volinfo) *)((char *)((&priv
->volumes)->next)-(unsigned long)(&((typeof(*tmp_volinfo
) *)0)->vol_list))); &tmp_volinfo->vol_list != (&
priv->volumes); tmp_volinfo = ((typeof(*tmp_volinfo) *)((char
*)(tmp_volinfo->vol_list.next)-(unsigned long)(&((typeof
(*tmp_volinfo) *)0)->vol_list))))
{
3995 ret++;
3996 }
3997
3998
3999 gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 3999, GF_LOG_DEBUG, "Returning %d"
, ret); } while (0)
;
4000 return ret;
4001
4002}
4003
4004int
4005glusterd_brickinfo_get (uuid_t uuid, char *hostname, char *path,
4006 glusterd_brickinfo_t **brickinfo)
4007{
4008 glusterd_volinfo_t *volinfo = NULL((void*)0);
4009 glusterd_conf_t *priv = NULL((void*)0);
4010 xlator_t *this = NULL((void*)0);
4011 int ret = -1;
4012
4013 GF_ASSERT (path)do { if (!(path)) { do { do { if (0) printf ("Assertion failed: "
"path"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4013, GF_LOG_ERROR, "Assertion failed: " "path"
); } while (0); } } while (0)
;
4014
4015 this = THIS(*__glusterfs_this_location());
4016 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4016, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
4017
4018 priv = this->private;
4019
4020 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))))
{
4021
4022 ret = glusterd_volume_brickinfo_get (uuid, hostname, path,
4023 volinfo, brickinfo);
4024 if (ret == 0)
4025 /*Found*/
4026 goto out;
4027 }
4028out:
4029 return ret;
4030}
4031
4032int
4033glusterd_brick_start (glusterd_volinfo_t *volinfo,
4034 glusterd_brickinfo_t *brickinfo,
4035 gf_boolean_t wait)
4036{
4037 int ret = -1;
4038 xlator_t *this = NULL((void*)0);
4039 glusterd_conf_t *conf = NULL((void*)0);
4040
4041 if ((!brickinfo) || (!volinfo))
25
Assuming 'brickinfo' is non-null
26
Taking false branch
4042 goto out;
4043
4044 this = THIS(*__glusterfs_this_location());
27
Value assigned to 'this'
4045 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4045, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
28
Within the expansion of the macro 'GF_ASSERT':
a
Assuming 'this' is null
4046 conf = this->private;
29
Access to field 'private' results in a dereference of a null pointer (loaded from variable 'this')
4047 GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: "
"conf"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4047, GF_LOG_ERROR, "Assertion failed: " "conf"
); } while (0); } } while (0)
;
4048
4049 if (uuid_is_null (brickinfo->uuid)) {
4050 ret = glusterd_resolve_brick (brickinfo);
4051 if (ret) {
4052 gf_log (this->name, GF_LOG_ERROR, FMTSTR_RESOLVE_BRICK,do { do { if (0) printf ("Could not find peer on which brick %s:%s resides"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 4053, GF_LOG_ERROR
, "Could not find peer on which brick %s:%s resides", brickinfo
->hostname, brickinfo->path); } while (0)
4053 brickinfo->hostname, brickinfo->path)do { do { if (0) printf ("Could not find peer on which brick %s:%s resides"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 4053, GF_LOG_ERROR
, "Could not find peer on which brick %s:%s resides", brickinfo
->hostname, brickinfo->path); } while (0)
;
4054 goto out;
4055 }
4056 }
4057
4058 if (uuid_compare (brickinfo->uuid, MY_UUID(__glusterd_uuid()))) {
4059 ret = 0;
4060 goto out;
4061 }
4062 ret = glusterd_volume_start_glusterfs (volinfo, brickinfo, wait);
4063 if (ret) {
4064 gf_log (this->name, GF_LOG_ERROR, "Unable to start brick %s:%s",do { do { if (0) printf ("Unable to start brick %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 4065, GF_LOG_ERROR
, "Unable to start brick %s:%s", brickinfo->hostname, brickinfo
->path); } while (0)
4065 brickinfo->hostname, brickinfo->path)do { do { if (0) printf ("Unable to start brick %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 4065, GF_LOG_ERROR
, "Unable to start brick %s:%s", brickinfo->hostname, brickinfo
->path); } while (0)
;
4066 goto out;
4067 }
4068
4069out:
4070 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-utils.c", __FUNCTION__, 4070, GF_LOG_DEBUG
, "returning %d ", ret); } while (0)
;
4071 return ret;
4072}
4073
4074int
4075glusterd_restart_bricks (glusterd_conf_t *conf)
4076{
4077 glusterd_volinfo_t *volinfo = NULL((void*)0);
4078 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
4079 gf_boolean_t start_nodesvcs = _gf_false;
4080 int ret = 0;
4081
4082 list_for_each_entry (volinfo, &conf->volumes, vol_list)for (volinfo = ((typeof(*volinfo) *)((char *)((&conf->
volumes)->next)-(unsigned long)(&((typeof(*volinfo) *)
0)->vol_list))); &volinfo->vol_list != (&conf->
volumes); volinfo = ((typeof(*volinfo) *)((char *)(volinfo->
vol_list.next)-(unsigned long)(&((typeof(*volinfo) *)0)->
vol_list))))
{
4083 if (volinfo->status != GLUSTERD_STATUS_STARTED)
4084 continue;
4085 start_nodesvcs = _gf_true;
4086 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))))
{
4087 glusterd_brick_start (volinfo, brickinfo, _gf_false);
4088 }
4089 }
4090
4091 if (start_nodesvcs)
4092 glusterd_nodesvcs_handle_graph_change (NULL((void*)0));
4093
4094 return ret;
4095}
4096
4097int
4098_local_gsyncd_start (dict_t *this, char *key, data_t *value, void *data)
4099{
4100 char *slave = NULL((void*)0);
4101 int uuid_len = 0;
4102 char uuid_str[64] = {0};
4103 glusterd_volinfo_t *volinfo = NULL((void*)0);
4104
4105 volinfo = data;
4106 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4106, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
4107 slave = strchr(value->data, ':');
4108 if (slave)
4109 slave ++;
4110 else
4111 return 0;
4112 uuid_len = (slave - value->data - 1);
4113
4114 strncpy (uuid_str, (char*)value->data, uuid_len);
4115 glusterd_start_gsync (volinfo, slave, uuid_str, NULL((void*)0));
4116
4117 return 0;
4118}
4119
4120int
4121glusterd_volume_restart_gsyncds (glusterd_volinfo_t *volinfo)
4122{
4123 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4123, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
4124
4125 dict_foreach (volinfo->gsync_slaves, _local_gsyncd_start, volinfo);
4126 return 0;
4127}
4128
4129int
4130glusterd_restart_gsyncds (glusterd_conf_t *conf)
4131{
4132 glusterd_volinfo_t *volinfo = NULL((void*)0);
4133 int ret = 0;
4134
4135 list_for_each_entry (volinfo, &conf->volumes, vol_list)for (volinfo = ((typeof(*volinfo) *)((char *)((&conf->
volumes)->next)-(unsigned long)(&((typeof(*volinfo) *)
0)->vol_list))); &volinfo->vol_list != (&conf->
volumes); volinfo = ((typeof(*volinfo) *)((char *)(volinfo->
vol_list.next)-(unsigned long)(&((typeof(*volinfo) *)0)->
vol_list))))
{
4136 glusterd_volume_restart_gsyncds (volinfo);
4137 }
4138 return ret;
4139}
4140
4141inline int
4142glusterd_get_dist_leaf_count (glusterd_volinfo_t *volinfo)
4143{
4144 int rcount = volinfo->replica_count;
4145 int scount = volinfo->stripe_count;
4146
4147 return (rcount ? rcount : 1) * (scount ? scount : 1);
4148}
4149
4150int
4151glusterd_get_brickinfo (xlator_t *this, const char *brickname, int port,
4152 gf_boolean_t localhost, glusterd_brickinfo_t **brickinfo)
4153{
4154 glusterd_conf_t *priv = NULL((void*)0);
4155 glusterd_volinfo_t *volinfo = NULL((void*)0);
4156 glusterd_brickinfo_t *tmpbrkinfo = NULL((void*)0);
4157 int ret = -1;
4158
4159 GF_ASSERT (brickname)do { if (!(brickname)) { do { do { if (0) printf ("Assertion failed: "
"brickname"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4159, GF_LOG_ERROR, "Assertion failed: " "brickname"
); } while (0); } } while (0)
;
4160 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4160, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
4161
4162 priv = this->private;
4163 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))))
{
4164 list_for_each_entry (tmpbrkinfo, &volinfo->bricks,for (tmpbrkinfo = ((typeof(*tmpbrkinfo) *)((char *)((&volinfo
->bricks)->next)-(unsigned long)(&((typeof(*tmpbrkinfo
) *)0)->brick_list))); &tmpbrkinfo->brick_list != (
&volinfo->bricks); tmpbrkinfo = ((typeof(*tmpbrkinfo) *
)((char *)(tmpbrkinfo->brick_list.next)-(unsigned long)(&
((typeof(*tmpbrkinfo) *)0)->brick_list))))
4165 brick_list)for (tmpbrkinfo = ((typeof(*tmpbrkinfo) *)((char *)((&volinfo
->bricks)->next)-(unsigned long)(&((typeof(*tmpbrkinfo
) *)0)->brick_list))); &tmpbrkinfo->brick_list != (
&volinfo->bricks); tmpbrkinfo = ((typeof(*tmpbrkinfo) *
)((char *)(tmpbrkinfo->brick_list.next)-(unsigned long)(&
((typeof(*tmpbrkinfo) *)0)->brick_list))))
{
4166 if (localhost && !glusterd_is_local_addr (tmpbrkinfo->hostname))
4167 continue;
4168 if (!strcmp(tmpbrkinfo->path, brickname) &&
4169 (tmpbrkinfo->port == port)) {
4170 *brickinfo = tmpbrkinfo;
4171 return 0;
4172 }
4173 }
4174 }
4175 return ret;
4176}
4177
4178glusterd_brickinfo_t*
4179glusterd_get_brickinfo_by_position (glusterd_volinfo_t *volinfo, uint32_t pos)
4180{
4181 glusterd_brickinfo_t *tmpbrkinfo = NULL((void*)0);
4182
4183 list_for_each_entry (tmpbrkinfo, &volinfo->bricks,for (tmpbrkinfo = ((typeof(*tmpbrkinfo) *)((char *)((&volinfo
->bricks)->next)-(unsigned long)(&((typeof(*tmpbrkinfo
) *)0)->brick_list))); &tmpbrkinfo->brick_list != (
&volinfo->bricks); tmpbrkinfo = ((typeof(*tmpbrkinfo) *
)((char *)(tmpbrkinfo->brick_list.next)-(unsigned long)(&
((typeof(*tmpbrkinfo) *)0)->brick_list))))
4184 brick_list)for (tmpbrkinfo = ((typeof(*tmpbrkinfo) *)((char *)((&volinfo
->bricks)->next)-(unsigned long)(&((typeof(*tmpbrkinfo
) *)0)->brick_list))); &tmpbrkinfo->brick_list != (
&volinfo->bricks); tmpbrkinfo = ((typeof(*tmpbrkinfo) *
)((char *)(tmpbrkinfo->brick_list.next)-(unsigned long)(&
((typeof(*tmpbrkinfo) *)0)->brick_list))))
{
4185 if (pos == 0)
4186 return tmpbrkinfo;
4187 pos--;
4188 }
4189 return NULL((void*)0);
4190}
4191
4192void
4193glusterd_set_brick_status (glusterd_brickinfo_t *brickinfo,
4194 gf_brick_status_t status)
4195{
4196 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4196, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
4197 brickinfo->status = status;
4198 if (GF_BRICK_STARTED == status) {
4199 gf_log ("glusterd", GF_LOG_DEBUG, "Setting brick %s:%s status "do { do { if (0) printf ("Setting brick %s:%s status " "to started"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
("glusterd", "glusterd-utils.c", __FUNCTION__, 4200, GF_LOG_DEBUG
, "Setting brick %s:%s status " "to started", brickinfo->hostname
, brickinfo->path); } while (0)
4200 "to started", brickinfo->hostname, brickinfo->path)do { do { if (0) printf ("Setting brick %s:%s status " "to started"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
("glusterd", "glusterd-utils.c", __FUNCTION__, 4200, GF_LOG_DEBUG
, "Setting brick %s:%s status " "to started", brickinfo->hostname
, brickinfo->path); } while (0)
;
4201 } else {
4202 gf_log ("glusterd", GF_LOG_DEBUG, "Setting brick %s:%s status "do { do { if (0) printf ("Setting brick %s:%s status " "to stopped"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
("glusterd", "glusterd-utils.c", __FUNCTION__, 4203, GF_LOG_DEBUG
, "Setting brick %s:%s status " "to stopped", brickinfo->hostname
, brickinfo->path); } while (0)
4203 "to stopped", brickinfo->hostname, brickinfo->path)do { do { if (0) printf ("Setting brick %s:%s status " "to stopped"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
("glusterd", "glusterd-utils.c", __FUNCTION__, 4203, GF_LOG_DEBUG
, "Setting brick %s:%s status " "to stopped", brickinfo->hostname
, brickinfo->path); } while (0)
;
4204 }
4205}
4206
4207gf_boolean_t
4208glusterd_is_brick_started (glusterd_brickinfo_t *brickinfo)
4209{
4210 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4210, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
4211 return (brickinfo->status == GF_BRICK_STARTED);
4212}
4213
4214int
4215glusterd_friend_brick_belongs (glusterd_volinfo_t *volinfo,
4216 glusterd_brickinfo_t *brickinfo, void* uuid)
4217{
4218 int ret = -1;
4219
4220 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4220, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
4221 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4221, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
4222 GF_ASSERT (uuid)do { if (!(uuid)) { do { do { if (0) printf ("Assertion failed: "
"uuid"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4222, GF_LOG_ERROR, "Assertion failed: " "uuid"
); } while (0); } } while (0)
;
4223
4224 if (uuid_is_null (brickinfo->uuid)) {
4225 ret = glusterd_resolve_brick (brickinfo);
4226 if (ret) {
4227 GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: "
"0"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4227, GF_LOG_ERROR, "Assertion failed: " "0")
; } while (0); } } while (0)
;
4228 goto out;
4229 }
4230 }
4231 if (!uuid_compare (brickinfo->uuid, *((uuid_t *)uuid)))
4232 return 0;
4233out:
4234 return -1;
4235}
4236
4237#ifdef GF_LINUX_HOST_OS1
4238static int
4239glusterd_get_brick_root (char *path, char **mount_point)
4240{
4241 char *ptr = NULL((void*)0);
4242 char *mnt_pt = NULL((void*)0);
4243 struct stat brickstat = {0};
4244 struct stat buf = {0};
4245
4246 if (!path)
4247 goto err;
4248 mnt_pt = gf_strdup (path);
4249 if (!mnt_pt)
4250 goto err;
4251 if (stat (mnt_pt, &brickstat))
4252 goto err;
4253
4254 while ((ptr = strrchr (mnt_pt, '/')) &&
4255 ptr != mnt_pt) {
4256
4257 *ptr = '\0';
4258 if (stat (mnt_pt, &buf)) {
4259 gf_log (THIS->name, GF_LOG_ERROR, "error in "do { do { if (0) printf ("error in " "stat: %s", strerror ((*
__errno_location ()))); } while (0); _gf_log ((*__glusterfs_this_location
())->name, "glusterd-utils.c", __FUNCTION__, 4260, GF_LOG_ERROR
, "error in " "stat: %s", strerror ((*__errno_location ())));
} while (0)
4260 "stat: %s", strerror (errno))do { do { if (0) printf ("error in " "stat: %s", strerror ((*
__errno_location ()))); } while (0); _gf_log ((*__glusterfs_this_location
())->name, "glusterd-utils.c", __FUNCTION__, 4260, GF_LOG_ERROR
, "error in " "stat: %s", strerror ((*__errno_location ())));
} while (0)
;
4261 goto err;
4262 }
4263
4264 if (brickstat.st_dev != buf.st_dev) {
4265 *ptr = '/';
4266 break;
4267 }
4268 }
4269
4270 if (ptr == mnt_pt) {
4271 if (stat ("/", &buf)) {
4272 gf_log (THIS->name, GF_LOG_ERROR, "error in "do { do { if (0) printf ("error in " "stat: %s", strerror ((*
__errno_location ()))); } while (0); _gf_log ((*__glusterfs_this_location
())->name, "glusterd-utils.c", __FUNCTION__, 4273, GF_LOG_ERROR
, "error in " "stat: %s", strerror ((*__errno_location ())));
} while (0)
4273 "stat: %s", strerror (errno))do { do { if (0) printf ("error in " "stat: %s", strerror ((*
__errno_location ()))); } while (0); _gf_log ((*__glusterfs_this_location
())->name, "glusterd-utils.c", __FUNCTION__, 4273, GF_LOG_ERROR
, "error in " "stat: %s", strerror ((*__errno_location ())));
} while (0)
;
4274 goto err;
4275 }
4276 if (brickstat.st_dev == buf.st_dev)
4277 strcpy (mnt_pt, "/");
4278 }
4279
4280 *mount_point = mnt_pt;
4281 return 0;
4282
4283 err:
4284 GF_FREE (mnt_pt)__gf_free (mnt_pt);
4285 return -1;
4286}
4287
4288static char*
4289glusterd_parse_inode_size (char *stream, char *pattern)
4290{
4291 char *needle = NULL((void*)0);
4292 char *trail = NULL((void*)0);
4293
4294 needle = strstr (stream, pattern);
4295 if (!needle)
4296 goto out;
4297
4298 needle = nwstrtail (needle, pattern);
4299
4300 trail = needle;
4301 while (trail && isdigit (*trail)((*__ctype_b_loc ())[(int) ((*trail))] & (unsigned short int
) _ISdigit)
) trail++;
4302 if (trail)
4303 *trail = '\0';
4304
4305out:
4306 return needle;
4307}
4308
4309static int
4310glusterd_add_inode_size_to_dict (dict_t *dict, int count)
4311{
4312 int ret = -1;
4313 char key[1024] = {0};
4314 char buffer[4096] = {0};
4315 char *inode_size = NULL((void*)0);
4316 char *device = NULL((void*)0);
4317 char *fs_name = NULL((void*)0);
4318 char *cur_word = NULL((void*)0);
4319 char *pattern = NULL((void*)0);
4320 char *trail = NULL((void*)0);
4321 runner_t runner = {0, };
4322
4323 memset (key, 0, sizeof (key));
4324 snprintf (key, sizeof (key), "brick%d.device", count);
4325 ret = dict_get_str (dict, key, &device);
4326 if (ret)
4327 goto out;
4328
4329 memset (key, 0, sizeof (key));
4330 snprintf (key, sizeof (key), "brick%d.fs_name", count);
4331 ret = dict_get_str (dict, key, &fs_name);
4332 if (ret)
4333 goto out;
4334
4335 runinit (&runner);
4336 runner_redir (&runner, STDOUT_FILENO1, RUN_PIPE-1);
4337 /* get inode size for xfs or ext2/3/4 */
4338 if (!strcmp (fs_name, "xfs")) {
4339
4340 runner_add_args (&runner, "xfs_info", device, NULL((void*)0));
4341 pattern = "isize=";
4342
4343 } else if (IS_EXT_FS(fs_name)(!strcmp (fs_name, "ext2") || !strcmp (fs_name, "ext3") || !strcmp
(fs_name, "ext4"))
) {
4344
4345 runner_add_args (&runner, "tune2fs", "-l", device, NULL((void*)0));
4346 pattern = "Inode size:";
4347
4348 } else {
4349 ret = 0;
4350 gf_log (THIS->name, GF_LOG_INFO, "Skipped fetching "do { do { if (0) printf ("Skipped fetching " "inode size for %s: FS type not recommended"
, fs_name); } while (0); _gf_log ((*__glusterfs_this_location
())->name, "glusterd-utils.c", __FUNCTION__, 4352, GF_LOG_INFO
, "Skipped fetching " "inode size for %s: FS type not recommended"
, fs_name); } while (0)
4351 "inode size for %s: FS type not recommended",do { do { if (0) printf ("Skipped fetching " "inode size for %s: FS type not recommended"
, fs_name); } while (0); _gf_log ((*__glusterfs_this_location
())->name, "glusterd-utils.c", __FUNCTION__, 4352, GF_LOG_INFO
, "Skipped fetching " "inode size for %s: FS type not recommended"
, fs_name); } while (0)
4352 fs_name)do { do { if (0) printf ("Skipped fetching " "inode size for %s: FS type not recommended"
, fs_name); } while (0); _gf_log ((*__glusterfs_this_location
())->name, "glusterd-utils.c", __FUNCTION__, 4352, GF_LOG_INFO
, "Skipped fetching " "inode size for %s: FS type not recommended"
, fs_name); } while (0)
;
4353 goto out;
4354 }
4355
4356 ret = runner_start (&runner);
4357 if (ret) {
4358 gf_log (THIS->name, GF_LOG_ERROR, "could not get inode "do { do { if (0) printf ("could not get inode " "size for %s : %s package missing"
, fs_name, ((strcmp (fs_name, "xfs")) ? "e2fsprogs" : "xfsprogs"
)); } while (0); _gf_log ((*__glusterfs_this_location())->
name, "glusterd-utils.c", __FUNCTION__, 4361, GF_LOG_ERROR, "could not get inode "
"size for %s : %s package missing", fs_name, ((strcmp (fs_name
, "xfs")) ? "e2fsprogs" : "xfsprogs")); } while (0)
4359 "size for %s : %s package missing", fs_name,do { do { if (0) printf ("could not get inode " "size for %s : %s package missing"
, fs_name, ((strcmp (fs_name, "xfs")) ? "e2fsprogs" : "xfsprogs"
)); } while (0); _gf_log ((*__glusterfs_this_location())->
name, "glusterd-utils.c", __FUNCTION__, 4361, GF_LOG_ERROR, "could not get inode "
"size for %s : %s package missing", fs_name, ((strcmp (fs_name
, "xfs")) ? "e2fsprogs" : "xfsprogs")); } while (0)
4360 ((strcmp (fs_name, "xfs")) ?do { do { if (0) printf ("could not get inode " "size for %s : %s package missing"
, fs_name, ((strcmp (fs_name, "xfs")) ? "e2fsprogs" : "xfsprogs"
)); } while (0); _gf_log ((*__glusterfs_this_location())->
name, "glusterd-utils.c", __FUNCTION__, 4361, GF_LOG_ERROR, "could not get inode "
"size for %s : %s package missing", fs_name, ((strcmp (fs_name
, "xfs")) ? "e2fsprogs" : "xfsprogs")); } while (0)
4361 "e2fsprogs" : "xfsprogs"))do { do { if (0) printf ("could not get inode " "size for %s : %s package missing"
, fs_name, ((strcmp (fs_name, "xfs")) ? "e2fsprogs" : "xfsprogs"
)); } while (0); _gf_log ((*__glusterfs_this_location())->
name, "glusterd-utils.c", __FUNCTION__, 4361, GF_LOG_ERROR, "could not get inode "
"size for %s : %s package missing", fs_name, ((strcmp (fs_name
, "xfs")) ? "e2fsprogs" : "xfsprogs")); } while (0)
;
4362 goto out;
4363 }
4364
4365 for (;;) {
4366 if (fgets (buffer, sizeof (buffer),
4367 runner_chio (&runner, STDOUT_FILENO1)) == NULL((void*)0))
4368 break;
4369 trail = strrchr (buffer, '\n');
4370 if (trail)
4371 *trail = '\0';
4372
4373 cur_word = glusterd_parse_inode_size (buffer, pattern);
4374 if (cur_word)
4375 break;
4376 }
4377
4378 ret = runner_end (&runner);
4379 if (ret) {
4380 gf_log (THIS->name, GF_LOG_ERROR, "%s exited with non-zero "do { do { if (0) printf ("%s exited with non-zero " "exit status"
, ((!strcmp (fs_name, "xfs")) ? "xfs_info" : "tune2fs")); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 4382, GF_LOG_ERROR, "%s exited with non-zero "
"exit status", ((!strcmp (fs_name, "xfs")) ? "xfs_info" : "tune2fs"
)); } while (0)
4381 "exit status", ((!strcmp (fs_name, "xfs")) ?do { do { if (0) printf ("%s exited with non-zero " "exit status"
, ((!strcmp (fs_name, "xfs")) ? "xfs_info" : "tune2fs")); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 4382, GF_LOG_ERROR, "%s exited with non-zero "
"exit status", ((!strcmp (fs_name, "xfs")) ? "xfs_info" : "tune2fs"
)); } while (0)
4382 "xfs_info" : "tune2fs"))do { do { if (0) printf ("%s exited with non-zero " "exit status"
, ((!strcmp (fs_name, "xfs")) ? "xfs_info" : "tune2fs")); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 4382, GF_LOG_ERROR, "%s exited with non-zero "
"exit status", ((!strcmp (fs_name, "xfs")) ? "xfs_info" : "tune2fs"
)); } while (0)
;
4383 goto out;
4384 }
4385 if (!cur_word) {
4386 ret = -1;
4387 gf_log (THIS->name, GF_LOG_ERROR, "Unable to retrieve inode "do { do { if (0) printf ("Unable to retrieve inode " "size using %s"
, (!strcmp (fs_name, "xfs")? "xfs_info": "tune2fs")); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 4389, GF_LOG_ERROR, "Unable to retrieve inode "
"size using %s", (!strcmp (fs_name, "xfs")? "xfs_info": "tune2fs"
)); } while (0)
4388 "size using %s",do { do { if (0) printf ("Unable to retrieve inode " "size using %s"
, (!strcmp (fs_name, "xfs")? "xfs_info": "tune2fs")); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 4389, GF_LOG_ERROR, "Unable to retrieve inode "
"size using %s", (!strcmp (fs_name, "xfs")? "xfs_info": "tune2fs"
)); } while (0)
4389 (!strcmp (fs_name, "xfs")? "xfs_info": "tune2fs"))do { do { if (0) printf ("Unable to retrieve inode " "size using %s"
, (!strcmp (fs_name, "xfs")? "xfs_info": "tune2fs")); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 4389, GF_LOG_ERROR, "Unable to retrieve inode "
"size using %s", (!strcmp (fs_name, "xfs")? "xfs_info": "tune2fs"
)); } while (0)
;
4390 goto out;
4391 }
4392
4393 inode_size = gf_strdup (cur_word);
4394
4395 memset (key, 0, sizeof (key));
4396 snprintf (key, sizeof (key), "brick%d.inode_size", count);
4397
4398 ret = dict_set_dynstr (dict, key, inode_size);
4399
4400 out:
4401 if (ret)
4402 gf_log (THIS->name, GF_LOG_ERROR, "failed to get inode size")do { do { if (0) printf ("failed to get inode size"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 4402, GF_LOG_ERROR, "failed to get inode size"
); } while (0)
;
4403 return ret;
4404}
4405
4406static int
4407glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo,
4408 dict_t *dict, int count)
4409{
4410 int ret = -1;
4411 char key[1024] = {0};
4412 char base_key[1024] = {0};
4413 char *mnt_pt = NULL((void*)0);
4414 char *fs_name = NULL((void*)0);
4415 char *mnt_options = NULL((void*)0);
4416 char *device = NULL((void*)0);
4417 FILE *mtab = NULL((void*)0);
4418 struct mntent *entry = NULL((void*)0);
4419
4420 snprintf (base_key, sizeof (base_key), "brick%d", count);
4421
4422 ret = glusterd_get_brick_root (brickinfo->path, &mnt_pt);
4423 if (ret)
4424 goto out;
4425
4426 mtab = setmntent (_PATH_MOUNTED"/etc/mtab", "r");
4427 if (!mtab) {
4428 ret = -1;
4429 goto out;
4430 }
4431
4432 entry = getmntent (mtab);
4433
4434 while (1) {
4435 if (!entry) {
4436 ret = -1;
4437 goto out;
4438 }
4439 if (!strcmp (entry->mnt_dir, mnt_pt) &&
4440 strcmp (entry->mnt_type, "rootfs"))
4441 break;
4442 entry = getmntent (mtab);
4443 }
4444
4445 /* get device file */
4446 memset (key, 0, sizeof (key));
4447 snprintf (key, sizeof (key), "%s.device", base_key);
4448
4449 device = gf_strdup (entry->mnt_fsname);
4450 ret = dict_set_dynstr (dict, key, device);
4451 if (ret)
4452 goto out;
4453
4454 /* fs type */
4455 memset (key, 0, sizeof (key));
4456 snprintf (key, sizeof (key), "%s.fs_name", base_key);
4457
4458 fs_name = gf_strdup (entry->mnt_type);
4459 ret = dict_set_dynstr (dict, key, fs_name);
4460 if (ret)
4461 goto out;
4462
4463 /* mount options */
4464 memset (key, 0, sizeof (key));
4465 snprintf (key, sizeof (key), "%s.mnt_options", base_key);
4466
4467 mnt_options = gf_strdup (entry->mnt_opts);
4468 ret = dict_set_dynstr (dict, key, mnt_options);
4469
4470 out:
4471 GF_FREE (mnt_pt)__gf_free (mnt_pt);
4472 if (mtab)
4473 endmntent (mtab);
4474
4475 return ret;
4476}
4477#endif
4478
4479int
4480glusterd_add_brick_detail_to_dict (glusterd_volinfo_t *volinfo,
4481 glusterd_brickinfo_t *brickinfo,
4482 dict_t *dict, int count)
4483{
4484 int ret = -1;
4485 uint64_t memtotal = 0;
4486 uint64_t memfree = 0;
4487 uint64_t inodes_total = 0;
4488 uint64_t inodes_free = 0;
4489 uint64_t block_size = 0;
4490 char key[1024] = {0};
4491 char base_key[1024] = {0};
4492 struct statvfs brickstat = {0};
4493 xlator_t *this = NULL((void*)0);
4494
4495 this = THIS(*__glusterfs_this_location());
4496 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4496, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
4497 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4497, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
4498 GF_ASSERT (dict)do { if (!(dict)) { do { do { if (0) printf ("Assertion failed: "
"dict"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4498, GF_LOG_ERROR, "Assertion failed: " "dict"
); } while (0); } } while (0)
;
4499
4500 snprintf (base_key, sizeof (base_key), "brick%d", count);
4501
4502 ret = statvfs (brickinfo->path, &brickstat);
4503 if (ret) {
4504 gf_log (this->name, GF_LOG_ERROR, "statfs error: %s ",do { do { if (0) printf ("statfs error: %s ", strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 4505, GF_LOG_ERROR, "statfs error: %s ", strerror
((*__errno_location ()))); } while (0)
4505 strerror (errno))do { do { if (0) printf ("statfs error: %s ", strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 4505, GF_LOG_ERROR, "statfs error: %s ", strerror
((*__errno_location ()))); } while (0)
;
4506 goto out;
4507 }
4508
4509 /* file system block size */
4510 block_size = brickstat.f_bsize;
4511 memset (key, 0, sizeof (key));
4512 snprintf (key, sizeof (key), "%s.block_size", base_key);
4513 ret = dict_set_uint64 (dict, key, block_size);
4514 if (ret)
4515 goto out;
4516
4517 /* free space in brick */
4518 memfree = brickstat.f_bfree * brickstat.f_bsize;
4519 memset (key, 0, sizeof (key));
4520 snprintf (key, sizeof (key), "%s.free", base_key);
4521 ret = dict_set_uint64 (dict, key, memfree);
4522 if (ret)
4523 goto out;
4524
4525 /* total space of brick */
4526 memtotal = brickstat.f_blocks * brickstat.f_bsize;
4527 memset (key, 0, sizeof (key));
4528 snprintf (key, sizeof (key), "%s.total", base_key);
4529 ret = dict_set_uint64 (dict, key, memtotal);
4530 if (ret)
4531 goto out;
4532
4533 /* inodes: total and free counts only for ext2/3/4 and xfs */
4534 inodes_total = brickstat.f_files;
4535 if (inodes_total) {
4536 memset (key, 0, sizeof (key));
4537 snprintf (key, sizeof (key), "%s.total_inodes", base_key);
4538 ret = dict_set_uint64 (dict, key, inodes_total);
4539 if (ret)
4540 goto out;
4541 }
4542
4543 inodes_free = brickstat.f_ffree;
4544 if (inodes_free) {
4545 memset (key, 0, sizeof (key));
4546 snprintf (key, sizeof (key), "%s.free_inodes", base_key);
4547 ret = dict_set_uint64 (dict, key, inodes_free);
4548 if (ret)
4549 goto out;
4550 }
4551#ifdef GF_LINUX_HOST_OS1
4552 ret = glusterd_add_brick_mount_details (brickinfo, dict, count);
4553 if (ret)
4554 goto out;
4555
4556 ret = glusterd_add_inode_size_to_dict (dict, count);
4557#endif
4558 out:
4559 if (ret)
4560 gf_log (this->name, GF_LOG_DEBUG, "Error adding brick"do { do { if (0) printf ("Error adding brick" " detail to dict: %s"
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 4561, GF_LOG_DEBUG
, "Error adding brick" " detail to dict: %s", strerror ((*__errno_location
()))); } while (0)
4561 " detail to dict: %s", strerror (errno))do { do { if (0) printf ("Error adding brick" " detail to dict: %s"
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 4561, GF_LOG_DEBUG
, "Error adding brick" " detail to dict: %s", strerror ((*__errno_location
()))); } while (0)
;
4562 return ret;
4563}
4564
4565int32_t
4566glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo,
4567 glusterd_brickinfo_t *brickinfo,
4568 dict_t *dict, int32_t count)
4569{
4570
4571 int ret = -1;
4572 int32_t pid = -1;
4573 int32_t brick_online = -1;
4574 char key[1024] = {0};
4575 char base_key[1024] = {0};
4576 char pidfile[PATH_MAX4096] = {0};
4577 xlator_t *this = NULL((void*)0);
4578 glusterd_conf_t *priv = NULL((void*)0);
4579
4580
4581 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4581, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
4582 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4582, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
4583 GF_ASSERT (dict)do { if (!(dict)) { do { do { if (0) printf ("Assertion failed: "
"dict"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4583, GF_LOG_ERROR, "Assertion failed: " "dict"
); } while (0); } } while (0)
;
4584
4585 this = THIS(*__glusterfs_this_location());
4586 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4586, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
4587
4588 priv = this->private;
4589
4590 snprintf (base_key, sizeof (base_key), "brick%d", count);
4591 snprintf (key, sizeof (key), "%s.hostname", base_key);
4592
4593 ret = dict_set_str (dict, key, brickinfo->hostname);
4594 if (ret)
4595 goto out;
4596
4597 memset (key, 0, sizeof (key));
4598 snprintf (key, sizeof (key), "%s.path", base_key);
4599 ret = dict_set_str (dict, key, brickinfo->path);
4600 if (ret)
4601 goto out;
4602
4603 memset (key, 0, sizeof (key));
4604 snprintf (key, sizeof (key), "%s.port", base_key);
4605 ret = dict_set_int32 (dict, key, brickinfo->port);
4606 if (ret)
4607 goto out;
4608
4609 GLUSTERD_GET_BRICK_PIDFILE (pidfile, volinfo, brickinfo, priv)do { char exp_path[4096] = {0,}; char volpath[4096] = {0,}; snprintf
(volpath, 4096, "%s/vols/%s", priv->workdir, volinfo->
volname);; do { int i = 0; for (i = 1; i < strlen (brickinfo
->path); i++) { exp_path[i-1] = brickinfo->path[i]; if (
exp_path[i-1] == '/') exp_path[i-1] = '-'; } } while (0); snprintf
(pidfile, 4096, "%s/run/%s-%s.pid", volpath, brickinfo->hostname
, exp_path); } while (0)
;
4610
4611 brick_online = glusterd_is_service_running (pidfile, &pid);
4612
4613 memset (key, 0, sizeof (key));
4614 snprintf (key, sizeof (key), "%s.pid", base_key);
4615 ret = dict_set_int32 (dict, key, pid);
4616 if (ret)
4617 goto out;
4618
4619 memset (key, 0, sizeof (key));
4620 snprintf (key, sizeof (key), "%s.status", base_key);
4621 ret = dict_set_int32 (dict, key, brick_online);
4622
4623out:
4624 if (ret)
4625 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-utils.c", __FUNCTION__, 4625, GF_LOG_DEBUG
, "Returning %d", ret); } while (0)
;
4626
4627 return ret;
4628}
4629
4630int32_t
4631glusterd_get_all_volnames (dict_t *dict)
4632{
4633 int ret = -1;
4634 int32_t vol_count = 0;
4635 char key[256] = {0};
4636 glusterd_volinfo_t *entry = NULL((void*)0);
4637 glusterd_conf_t *priv = NULL((void*)0);
4638
4639 priv = THIS(*__glusterfs_this_location())->private;
4640 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4640, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
4641
4642 list_for_each_entry (entry, &priv->volumes, vol_list)for (entry = ((typeof(*entry) *)((char *)((&priv->volumes
)->next)-(unsigned long)(&((typeof(*entry) *)0)->vol_list
))); &entry->vol_list != (&priv->volumes); entry
= ((typeof(*entry) *)((char *)(entry->vol_list.next)-(unsigned
long)(&((typeof(*entry) *)0)->vol_list))))
{
4643 memset (key, 0, sizeof (key));
4644 snprintf (key, sizeof (key), "vol%d", vol_count);
4645 ret = dict_set_str (dict, key, entry->volname);
4646 if (ret)
4647 goto out;
4648
4649 vol_count++;
4650 }
4651
4652 ret = dict_set_int32 (dict, "vol_count", vol_count);
4653
4654 out:
4655 if (ret)
4656 gf_log (THIS->name, GF_LOG_ERROR, "failed to get all "do { do { if (0) printf ("failed to get all " "volume names for status"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 4657, GF_LOG_ERROR, "failed to get all "
"volume names for status"); } while (0)
4657 "volume names for status")do { do { if (0) printf ("failed to get all " "volume names for status"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 4657, GF_LOG_ERROR, "failed to get all "
"volume names for status"); } while (0)
;
4658 return ret;
4659}
4660
4661int
4662glusterd_all_volume_cond_check (glusterd_condition_func func, int status,
4663 void *ctx)
4664{
4665 glusterd_conf_t *priv = NULL((void*)0);
4666 glusterd_volinfo_t *volinfo = NULL((void*)0);
4667 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
4668 int ret = -1;
4669 xlator_t *this = NULL((void*)0);
4670
4671 this = THIS(*__glusterfs_this_location());
4672 priv = this->private;
4673
4674 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))))
{
4675 list_for_each_entry (brickinfo, &volinfo->bricks,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))))
4676 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))))
{
4677 ret = func (volinfo, brickinfo, ctx);
4678 if (ret != status) {
4679 ret = -1;
4680 goto out;
4681 }
4682 }
4683 }
4684 ret = 0;
4685out:
4686 gf_log ("", GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 4686, GF_LOG_DEBUG, "returning %d"
, ret); } while (0)
;
4687 return ret;
4688}
4689
4690int
4691glusterd_friend_find_by_uuid (uuid_t uuid,
4692 glusterd_peerinfo_t **peerinfo)
4693{
4694 int ret = -1;
4695 glusterd_conf_t *priv = NULL((void*)0);
4696 glusterd_peerinfo_t *entry = NULL((void*)0);
4697 xlator_t *this = NULL((void*)0);
4698
4699 this = THIS(*__glusterfs_this_location());
4700 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4700, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
4701 GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: "
"peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4701, GF_LOG_ERROR, "Assertion failed: " "peerinfo"
); } while (0); } } while (0)
;
4702
4703 *peerinfo = NULL((void*)0);
4704 priv = this->private;
4705
4706 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4706, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
4707
4708 if (uuid_is_null (uuid))
4709 return -1;
4710
4711 list_for_each_entry (entry, &priv->peers, uuid_list)for (entry = ((typeof(*entry) *)((char *)((&priv->peers
)->next)-(unsigned long)(&((typeof(*entry) *)0)->uuid_list
))); &entry->uuid_list != (&priv->peers); entry
= ((typeof(*entry) *)((char *)(entry->uuid_list.next)-(unsigned
long)(&((typeof(*entry) *)0)->uuid_list))))
{
4712 if (!uuid_compare (entry->uuid, uuid)) {
4713
4714 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Friend found... state: %s", glusterd_friend_sm_state_name_get
(entry->state.state)); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 4716, GF_LOG_DEBUG, "Friend found... state: %s"
, glusterd_friend_sm_state_name_get (entry->state.state));
} while (0)
4715 "Friend found... state: %s",do { do { if (0) printf ("Friend found... state: %s", glusterd_friend_sm_state_name_get
(entry->state.state)); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 4716, GF_LOG_DEBUG, "Friend found... state: %s"
, glusterd_friend_sm_state_name_get (entry->state.state));
} while (0)
4716 glusterd_friend_sm_state_name_get (entry->state.state))do { do { if (0) printf ("Friend found... state: %s", glusterd_friend_sm_state_name_get
(entry->state.state)); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 4716, GF_LOG_DEBUG, "Friend found... state: %s"
, glusterd_friend_sm_state_name_get (entry->state.state));
} while (0)
;
4717 *peerinfo = entry;
4718 return 0;
4719 }
4720 }
4721
4722 gf_log (this->name, GF_LOG_DEBUG, "Friend with uuid: %s, not found",do { do { if (0) printf ("Friend with uuid: %s, not found", uuid_utoa
(uuid)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 4723, GF_LOG_DEBUG, "Friend with uuid: %s, not found"
, uuid_utoa (uuid)); } while (0)
4723 uuid_utoa (uuid))do { do { if (0) printf ("Friend with uuid: %s, not found", uuid_utoa
(uuid)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 4723, GF_LOG_DEBUG, "Friend with uuid: %s, not found"
, uuid_utoa (uuid)); } while (0)
;
4724 return ret;
4725}
4726
4727
4728int
4729glusterd_friend_find_by_hostname (const char *hoststr,
4730 glusterd_peerinfo_t **peerinfo)
4731{
4732 int ret = -1;
4733 glusterd_conf_t *priv = NULL((void*)0);
4734 glusterd_peerinfo_t *entry = NULL((void*)0);
4735 struct addrinfo *addr = NULL((void*)0);
4736 struct addrinfo *p = NULL((void*)0);
4737 char *host = NULL((void*)0);
4738 struct sockaddr_in6 *s6 = NULL((void*)0);
4739 struct sockaddr_in *s4 = NULL((void*)0);
4740 struct in_addr *in_addr = NULL((void*)0);
4741 char hname[1024] = {0,};
4742 xlator_t *this = NULL((void*)0);
4743
4744
4745 this = THIS(*__glusterfs_this_location());
4746 GF_ASSERT (hoststr)do { if (!(hoststr)) { do { do { if (0) printf ("Assertion failed: "
"hoststr"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4746, GF_LOG_ERROR, "Assertion failed: " "hoststr"
); } while (0); } } while (0)
;
4747 GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: "
"peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4747, GF_LOG_ERROR, "Assertion failed: " "peerinfo"
); } while (0); } } while (0)
;
4748
4749 *peerinfo = NULL((void*)0);
4750 priv = this->private;
4751
4752 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4752, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
4753
4754 list_for_each_entry (entry, &priv->peers, uuid_list)for (entry = ((typeof(*entry) *)((char *)((&priv->peers
)->next)-(unsigned long)(&((typeof(*entry) *)0)->uuid_list
))); &entry->uuid_list != (&priv->peers); entry
= ((typeof(*entry) *)((char *)(entry->uuid_list.next)-(unsigned
long)(&((typeof(*entry) *)0)->uuid_list))))
{
4755 if (!strncasecmp (entry->hostname, hoststr,
4756 1024)) {
4757
4758 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Friend %s found.. state: %d", hoststr
, entry->state.state); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 4760, GF_LOG_DEBUG, "Friend %s found.. state: %d"
, hoststr, entry->state.state); } while (0)
4759 "Friend %s found.. state: %d", hoststr,do { do { if (0) printf ("Friend %s found.. state: %d", hoststr
, entry->state.state); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 4760, GF_LOG_DEBUG, "Friend %s found.. state: %d"
, hoststr, entry->state.state); } while (0)
4760 entry->state.state)do { do { if (0) printf ("Friend %s found.. state: %d", hoststr
, entry->state.state); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 4760, GF_LOG_DEBUG, "Friend %s found.. state: %d"
, hoststr, entry->state.state); } while (0)
;
4761 *peerinfo = entry;
4762 return 0;
4763 }
4764 }
4765
4766 ret = getaddrinfo (hoststr, NULL((void*)0), NULL((void*)0), &addr);
4767 if (ret != 0) {
4768 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("error in getaddrinfo: %s\n", gai_strerror
(ret)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 4770, GF_LOG_ERROR, "error in getaddrinfo: %s\n"
, gai_strerror(ret)); } while (0)
4769 "error in getaddrinfo: %s\n",do { do { if (0) printf ("error in getaddrinfo: %s\n", gai_strerror
(ret)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 4770, GF_LOG_ERROR, "error in getaddrinfo: %s\n"
, gai_strerror(ret)); } while (0)
4770 gai_strerror(ret))do { do { if (0) printf ("error in getaddrinfo: %s\n", gai_strerror
(ret)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 4770, GF_LOG_ERROR, "error in getaddrinfo: %s\n"
, gai_strerror(ret)); } while (0)
;
4771 goto out;
4772 }
4773
4774 for (p = addr; p != NULL((void*)0); p = p->ai_next) {
4775 switch (p->ai_family) {
4776 case AF_INET2:
4777 s4 = (struct sockaddr_in *) p->ai_addr;
4778 in_addr = &s4->sin_addr;
4779 break;
4780 case AF_INET610:
4781 s6 = (struct sockaddr_in6 *) p->ai_addr;
4782 in_addr =(struct in_addr *) &s6->sin6_addr;
4783 break;
4784 default: ret = -1;
4785 goto out;
4786 }
4787 host = inet_ntoa(*in_addr);
4788
4789 ret = getnameinfo (p->ai_addr, p->ai_addrlen, hname,
4790 1024, NULL((void*)0), 0, 0);
4791 if (ret)
4792 goto out;
4793
4794 list_for_each_entry (entry, &priv->peers, uuid_list)for (entry = ((typeof(*entry) *)((char *)((&priv->peers
)->next)-(unsigned long)(&((typeof(*entry) *)0)->uuid_list
))); &entry->uuid_list != (&priv->peers); entry
= ((typeof(*entry) *)((char *)(entry->uuid_list.next)-(unsigned
long)(&((typeof(*entry) *)0)->uuid_list))))
{
4795 if (!strncasecmp (entry->hostname, host,
4796 1024) || !strncasecmp (entry->hostname,hname,
4797 1024)) {
4798 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Friend %s found.. state: %d", hoststr
, entry->state.state); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 4800, GF_LOG_DEBUG, "Friend %s found.. state: %d"
, hoststr, entry->state.state); } while (0)
4799 "Friend %s found.. state: %d",do { do { if (0) printf ("Friend %s found.. state: %d", hoststr
, entry->state.state); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 4800, GF_LOG_DEBUG, "Friend %s found.. state: %d"
, hoststr, entry->state.state); } while (0)
4800 hoststr, entry->state.state)do { do { if (0) printf ("Friend %s found.. state: %d", hoststr
, entry->state.state); } while (0); _gf_log (this->name
, "glusterd-utils.c", __FUNCTION__, 4800, GF_LOG_DEBUG, "Friend %s found.. state: %d"
, hoststr, entry->state.state); } while (0)
;
4801 *peerinfo = entry;
4802 freeaddrinfo (addr);
4803 return 0;
4804 }
4805 }
4806 }
4807
4808out:
4809 gf_log (this->name, GF_LOG_DEBUG, "Unable to find friend: %s", hoststr)do { do { if (0) printf ("Unable to find friend: %s", hoststr
); } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 4809, GF_LOG_DEBUG, "Unable to find friend: %s", hoststr); }
while (0)
;
4810 if (addr)
4811 freeaddrinfo (addr);
4812 return -1;
4813}
4814
4815int
4816glusterd_hostname_to_uuid (char *hostname, uuid_t uuid)
4817{
4818 GF_ASSERT (hostname)do { if (!(hostname)) { do { do { if (0) printf ("Assertion failed: "
"hostname"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4818, GF_LOG_ERROR, "Assertion failed: " "hostname"
); } while (0); } } while (0)
;
4819 GF_ASSERT (uuid)do { if (!(uuid)) { do { do { if (0) printf ("Assertion failed: "
"uuid"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4819, GF_LOG_ERROR, "Assertion failed: " "uuid"
); } while (0); } } while (0)
;
4820
4821 glusterd_peerinfo_t *peerinfo = NULL((void*)0);
4822 glusterd_conf_t *priv = NULL((void*)0);
4823 int ret = -1;
4824 xlator_t *this = NULL((void*)0);
4825
4826 this = THIS(*__glusterfs_this_location());
4827 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4827, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
4828 priv = this->private;
4829 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4829, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
4830
4831 ret = glusterd_friend_find_by_hostname (hostname, &peerinfo);
4832 if (ret) {
4833 if (glusterd_is_local_addr (hostname)) {
4834 uuid_copy (uuid, MY_UUID(__glusterd_uuid()));
4835 ret = 0;
4836 } else {
4837 goto out;
4838 }
4839 } else {
4840 uuid_copy (uuid, peerinfo->uuid);
4841 }
4842
4843out:
4844 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-utils.c", __FUNCTION__, 4844, GF_LOG_DEBUG
, "returning %d", ret); } while (0)
;
4845 return ret;
4846}
4847
4848int
4849glusterd_brick_stop (glusterd_volinfo_t *volinfo,
4850 glusterd_brickinfo_t *brickinfo,
4851 gf_boolean_t del_brick)
4852{
4853 int ret = -1;
4854 xlator_t *this = NULL((void*)0);
4855 glusterd_conf_t *conf = NULL((void*)0);
4856
4857 if ((!brickinfo) || (!volinfo))
4858 goto out;
4859
4860 this = THIS(*__glusterfs_this_location());
4861 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4861, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
4862 conf = this->private;
4863 GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: "
"conf"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4863, GF_LOG_ERROR, "Assertion failed: " "conf"
); } while (0); } } while (0)
;
4864
4865 if (uuid_is_null (brickinfo->uuid)) {
4866 ret = glusterd_resolve_brick (brickinfo);
4867 if (ret) {
4868 gf_log (this->name, GF_LOG_ERROR, FMTSTR_RESOLVE_BRICK,do { do { if (0) printf ("Could not find peer on which brick %s:%s resides"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 4869, GF_LOG_ERROR
, "Could not find peer on which brick %s:%s resides", brickinfo
->hostname, brickinfo->path); } while (0)
4869 brickinfo->hostname, brickinfo->path)do { do { if (0) printf ("Could not find peer on which brick %s:%s resides"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 4869, GF_LOG_ERROR
, "Could not find peer on which brick %s:%s resides", brickinfo
->hostname, brickinfo->path); } while (0)
;
4870 goto out;
4871 }
4872 }
4873
4874 if (uuid_compare (brickinfo->uuid, MY_UUID(__glusterd_uuid()))) {
4875 ret = 0;
4876 if (del_brick)
4877 glusterd_delete_brick (volinfo, brickinfo);
4878 goto out;
4879 }
4880
4881 gf_log (this->name, GF_LOG_DEBUG, "About to stop glusterfs"do { do { if (0) printf ("About to stop glusterfs" " for brick %s:%s"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 4883, GF_LOG_DEBUG
, "About to stop glusterfs" " for brick %s:%s", brickinfo->
hostname, brickinfo->path); } while (0)
4882 " for brick %s:%s", brickinfo->hostname,do { do { if (0) printf ("About to stop glusterfs" " for brick %s:%s"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 4883, GF_LOG_DEBUG
, "About to stop glusterfs" " for brick %s:%s", brickinfo->
hostname, brickinfo->path); } while (0)
4883 brickinfo->path)do { do { if (0) printf ("About to stop glusterfs" " for brick %s:%s"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 4883, GF_LOG_DEBUG
, "About to stop glusterfs" " for brick %s:%s", brickinfo->
hostname, brickinfo->path); } while (0)
;
4884 ret = glusterd_volume_stop_glusterfs (volinfo, brickinfo, del_brick);
4885 if (ret) {
4886 gf_log (this->name, GF_LOG_CRITICAL, "Unable to stop"do { do { if (0) printf ("Unable to stop" " brick: %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 4888, GF_LOG_CRITICAL
, "Unable to stop" " brick: %s:%s", brickinfo->hostname, brickinfo
->path); } while (0)
4887 " brick: %s:%s", brickinfo->hostname,do { do { if (0) printf ("Unable to stop" " brick: %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 4888, GF_LOG_CRITICAL
, "Unable to stop" " brick: %s:%s", brickinfo->hostname, brickinfo
->path); } while (0)
4888 brickinfo->path)do { do { if (0) printf ("Unable to stop" " brick: %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 4888, GF_LOG_CRITICAL
, "Unable to stop" " brick: %s:%s", brickinfo->hostname, brickinfo
->path); } while (0)
;
4889 goto out;
4890 }
4891
4892out:
4893 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-utils.c", __FUNCTION__, 4893, GF_LOG_DEBUG
, "returning %d ", ret); } while (0)
;
4894 return ret;
4895}
4896
4897int
4898glusterd_is_defrag_on (glusterd_volinfo_t *volinfo)
4899{
4900 return (volinfo->rebal.defrag != NULL((void*)0));
4901}
4902
4903gf_boolean_t
4904glusterd_is_rb_ongoing (glusterd_volinfo_t *volinfo)
4905{
4906 gf_boolean_t ret = _gf_false;
4907
4908 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4908, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
4909
4910 if (glusterd_is_rb_started (volinfo) ||
4911 glusterd_is_rb_paused (volinfo))
4912 ret = _gf_true;
4913
4914 return ret;
4915}
4916
4917int
4918glusterd_new_brick_validate (char *brick, glusterd_brickinfo_t *brickinfo,
4919 char *op_errstr, size_t len)
4920{
4921 glusterd_brickinfo_t *newbrickinfo = NULL((void*)0);
4922 int ret = -1;
4923 gf_boolean_t is_allocated = _gf_false;
4924 glusterd_peerinfo_t *peerinfo = NULL((void*)0);
4925 glusterd_conf_t *priv = NULL((void*)0);
4926 xlator_t *this = NULL((void*)0);
4927
4928 this = THIS(*__glusterfs_this_location());
4929 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4929, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
4930 priv = this->private;
4931 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4931, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
4932
4933
4934 GF_ASSERT (brick)do { if (!(brick)) { do { do { if (0) printf ("Assertion failed: "
"brick"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4934, GF_LOG_ERROR, "Assertion failed: " "brick"
); } while (0); } } while (0)
;
4935 GF_ASSERT (op_errstr)do { if (!(op_errstr)) { do { do { if (0) printf ("Assertion failed: "
"op_errstr"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 4935, GF_LOG_ERROR, "Assertion failed: " "op_errstr"
); } while (0); } } while (0)
;
4936
4937 if (!brickinfo) {
4938 ret = glusterd_brickinfo_new_from_brick (brick, &newbrickinfo);
4939 if (ret)
4940 goto out;
4941 is_allocated = _gf_true;
4942 } else {
4943 newbrickinfo = brickinfo;
4944 }
4945
4946 ret = glusterd_resolve_brick (newbrickinfo);
4947 if (ret) {
4948 snprintf(op_errstr, len, "Host %s is not in \'Peer "
4949 "in Cluster\' state", newbrickinfo->hostname);
4950 goto out;
4951 }
4952
4953 if (!uuid_compare (MY_UUID(__glusterd_uuid()), newbrickinfo->uuid)) {
4954 /* brick is local */
4955 if (!glusterd_is_brickpath_available (newbrickinfo->uuid,
4956 newbrickinfo->path)) {
4957 snprintf(op_errstr, len, "Brick: %s not available."
4958 " Brick may be containing or be contained "
4959 "by an existing brick", brick);
4960 ret = -1;
4961 goto out;
4962 }
4963
4964 } else {
4965 ret = glusterd_friend_find_by_uuid (newbrickinfo->uuid,
4966 &peerinfo);
4967 if (ret) {
4968 snprintf (op_errstr, len, "Failed to find host %s",
4969 newbrickinfo->hostname);
4970 goto out;
4971 }
4972
4973 if ((!peerinfo->connected)) {
4974 snprintf(op_errstr, len, "Host %s not connected",
4975 newbrickinfo->hostname);
4976 ret = -1;
4977 goto out;
4978 }
4979
4980 if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED) {
4981 snprintf(op_errstr, len, "Host %s is not in \'Peer "
4982 "in Cluster\' state",
4983 newbrickinfo->hostname);
4984 ret = -1;
4985 goto out;
4986 }
4987 }
4988
4989 ret = 0;
4990out:
4991 if (is_allocated)
4992 glusterd_brickinfo_delete (newbrickinfo);
4993 if (op_errstr[0] != '\0')
4994 gf_log (this->name, GF_LOG_ERROR, "%s", op_errstr)do { do { if (0) printf ("%s", op_errstr); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 4994, GF_LOG_ERROR
, "%s", op_errstr); } while (0)
;
4995 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-utils.c", __FUNCTION__, 4995, GF_LOG_DEBUG
, "returning %d ", ret); } while (0)
;
4996 return ret;
4997}
4998
4999int
5000glusterd_is_rb_started(glusterd_volinfo_t *volinfo)
5001{
5002 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("is_rb_started:status=%d", volinfo->
rep_brick.rb_status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 5003, GF_LOG_DEBUG, "is_rb_started:status=%d"
, volinfo->rep_brick.rb_status); } while (0)
5003 "is_rb_started:status=%d", volinfo->rep_brick.rb_status)do { do { if (0) printf ("is_rb_started:status=%d", volinfo->
rep_brick.rb_status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 5003, GF_LOG_DEBUG, "is_rb_started:status=%d"
, volinfo->rep_brick.rb_status); } while (0)
;
5004 return (volinfo->rep_brick.rb_status == GF_RB_STATUS_STARTED);
5005
5006}
5007
5008int
5009glusterd_is_rb_paused ( glusterd_volinfo_t *volinfo)
5010{
5011 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("is_rb_paused:status=%d", volinfo->
rep_brick.rb_status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 5012, GF_LOG_DEBUG, "is_rb_paused:status=%d",
volinfo->rep_brick.rb_status); } while (0)
5012 "is_rb_paused:status=%d", volinfo->rep_brick.rb_status)do { do { if (0) printf ("is_rb_paused:status=%d", volinfo->
rep_brick.rb_status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 5012, GF_LOG_DEBUG, "is_rb_paused:status=%d",
volinfo->rep_brick.rb_status); } while (0)
;
5013
5014 return (volinfo->rep_brick.rb_status == GF_RB_STATUS_PAUSED);
5015}
5016
5017inline int
5018glusterd_set_rb_status (glusterd_volinfo_t *volinfo, gf_rb_status_t status)
5019{
5020 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("setting status from %d to %d", volinfo
->rep_brick.rb_status, status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 5023, GF_LOG_DEBUG, "setting status from %d to %d"
, volinfo->rep_brick.rb_status, status); } while (0)
5021 "setting status from %d to %d",do { do { if (0) printf ("setting status from %d to %d", volinfo
->rep_brick.rb_status, status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 5023, GF_LOG_DEBUG, "setting status from %d to %d"
, volinfo->rep_brick.rb_status, status); } while (0)
5022 volinfo->rep_brick.rb_status,do { do { if (0) printf ("setting status from %d to %d", volinfo
->rep_brick.rb_status, status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 5023, GF_LOG_DEBUG, "setting status from %d to %d"
, volinfo->rep_brick.rb_status, status); } while (0)
5023 status)do { do { if (0) printf ("setting status from %d to %d", volinfo
->rep_brick.rb_status, status); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 5023, GF_LOG_DEBUG, "setting status from %d to %d"
, volinfo->rep_brick.rb_status, status); } while (0)
;
5024
5025 volinfo->rep_brick.rb_status = status;
5026 return 0;
5027}
5028
5029inline int
5030glusterd_rb_check_bricks (glusterd_volinfo_t *volinfo,
5031 glusterd_brickinfo_t *src, glusterd_brickinfo_t *dst)
5032{
5033 glusterd_replace_brick_t *rb = NULL((void*)0);
5034
5035 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5035, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
5036
5037 rb = &volinfo->rep_brick;
5038
5039 if (!rb->src_brick || !rb->dst_brick)
5040 return -1;
5041
5042 if (strcmp (rb->src_brick->hostname, src->hostname) ||
5043 strcmp (rb->src_brick->path, src->path)) {
5044 gf_log("", GF_LOG_ERROR, "Replace brick src bricks differ")do { do { if (0) printf ("Replace brick src bricks differ"); }
while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 5044
, GF_LOG_ERROR, "Replace brick src bricks differ"); } while (
0)
;
5045 return -1;
5046 }
5047
5048 if (strcmp (rb->dst_brick->hostname, dst->hostname) ||
5049 strcmp (rb->dst_brick->path, dst->path)) {
5050 gf_log ("", GF_LOG_ERROR, "Replace brick dst bricks differ")do { do { if (0) printf ("Replace brick dst bricks differ"); }
while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 5050
, GF_LOG_ERROR, "Replace brick dst bricks differ"); } while (
0)
;
5051 return -1;
5052 }
5053
5054 return 0;
5055}
5056
5057/*path needs to be absolute; works only on gfid, volume-id*/
5058static int
5059glusterd_is_uuid_present (char *path, char *xattr, gf_boolean_t *present)
5060{
5061 GF_ASSERT (path)do { if (!(path)) { do { do { if (0) printf ("Assertion failed: "
"path"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5061, GF_LOG_ERROR, "Assertion failed: " "path"
); } while (0); } } while (0)
;
5062 GF_ASSERT (xattr)do { if (!(xattr)) { do { do { if (0) printf ("Assertion failed: "
"xattr"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5062, GF_LOG_ERROR, "Assertion failed: " "xattr"
); } while (0); } } while (0)
;
5063 GF_ASSERT (present)do { if (!(present)) { do { do { if (0) printf ("Assertion failed: "
"present"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5063, GF_LOG_ERROR, "Assertion failed: " "present"
); } while (0); } } while (0)
;
5064
5065 int ret = -1;
5066 uuid_t uid = {0,};
5067
5068 if (!path || !xattr || !present)
5069 goto out;
5070
5071 ret = sys_lgetxattr (path, xattr, &uid, 16);
5072
5073 if (ret >= 0) {
5074 *present = _gf_true;
5075 ret = 0;
5076 goto out;
5077 }
5078
5079 switch (errno(*__errno_location ())) {
5080#if defined(ENODATA61)
5081 case ENODATA61: /* FALLTHROUGH */
5082#endif
5083#if defined(ENOATTR61) && (ENOATTR61 != ENODATA61)
5084 case ENOATTR61: /* FALLTHROUGH */
5085#endif
5086 case ENOTSUP95:
5087 *present = _gf_false;
5088 ret = 0;
5089 break;
5090 default:
5091 break;
5092 }
5093out:
5094 return ret;
5095}
5096
5097/*path needs to be absolute*/
5098static int
5099glusterd_is_path_in_use (char *path, gf_boolean_t *in_use, char **op_errstr)
5100{
5101 int i = 0;
5102 int ret = -1;
5103 gf_boolean_t used = _gf_false;
5104 char dir[PATH_MAX4096] = {0,};
5105 char *curdir = NULL((void*)0);
5106 char msg[2048] = {0};
5107 char *keys[3] = {GFID_XATTR_KEY"trusted.gfid",
5108 GF_XATTR_VOL_ID_KEY"trusted.glusterfs.volume-id",
5109 NULL((void*)0)};
5110
5111 GF_ASSERT (path)do { if (!(path)) { do { do { if (0) printf ("Assertion failed: "
"path"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5111, GF_LOG_ERROR, "Assertion failed: " "path"
); } while (0); } } while (0)
;
5112 if (!path)
5113 goto out;
5114
5115 strcpy (dir, path);
5116 curdir = dir;
5117 do {
5118 for (i = 0; !used && keys[i]; i++) {
5119 ret = glusterd_is_uuid_present (curdir, keys[i], &used);
5120 if (ret)
5121 goto out;
5122 }
5123
5124 if (used)
5125 break;
5126
5127 curdir = dirname (curdir);
5128 if (!strcmp (curdir, "."))
5129 goto out;
5130
5131
5132 } while (strcmp (curdir, "/"));
5133
5134 if (!strcmp (curdir, "/")) {
5135 for (i = 0; !used && keys[i]; i++) {
5136 ret = glusterd_is_uuid_present (curdir, keys[i], &used);
5137 if (ret)
5138 goto out;
5139 }
5140 }
5141
5142 ret = 0;
5143 *in_use = used;
5144out:
5145 if (ret) {
5146 snprintf (msg, sizeof (msg), "Failed to get extended "
5147 "attribute %s, reason: %s", keys[i],
5148 strerror (errno(*__errno_location ())));
5149 }
5150
5151 if (*in_use) {
5152 if (!strcmp (path, curdir)) {
5153 snprintf (msg, sizeof (msg), "%s is already part of a "
5154 "volume", path);
5155 } else {
5156 snprintf (msg, sizeof (msg), "parent directory %s is "
5157 "already part of a volume", curdir);
5158 }
5159 }
5160
5161 if (strlen (msg)) {
5162 gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((*
__glusterfs_this_location())->name, "glusterd-utils.c", __FUNCTION__
, 5162, GF_LOG_ERROR, "%s", msg); } while (0)
;
5163 *op_errstr = gf_strdup (msg);
5164 }
5165
5166 return ret;
5167}
5168
5169int
5170glusterd_check_and_set_brick_xattr (char *host, char *path, uuid_t uuid,
5171 char **op_errstr)
5172{
5173 int ret = -1;
5174 char msg[2048] = {0,};
5175 gf_boolean_t in_use = _gf_false;
5176
5177 /* Check for xattr support in backend fs */
5178 ret = sys_lsetxattr (path, "trusted.glusterfs.test",
5179 "working", 8, 0);
5180 if (ret) {
5181 snprintf (msg, sizeof (msg), "Glusterfs is not"
5182 " supported on brick: %s:%s.\nSetting"
5183 " extended attributes failed, reason:"
5184 " %s.", host, path, strerror(errno(*__errno_location ())));
5185 goto out;
5186
5187 } else {
5188 sys_lremovexattr (path, "trusted.glusterfs.test");
5189 }
5190
5191 ret = glusterd_is_path_in_use (path, &in_use, op_errstr);
5192 if (ret)
5193 goto out;
5194
5195 if (in_use) {
5196 ret = -1;
5197 goto out;
5198 }
5199
5200 ret = sys_lsetxattr (path, GF_XATTR_VOL_ID_KEY"trusted.glusterfs.volume-id", uuid, 16,
5201 XATTR_CREATEXATTR_CREATE);
5202 if (ret) {
5203 snprintf (msg, sizeof (msg), "Failed to set extended "
5204 "attributes %s, reason: %s",
5205 GF_XATTR_VOL_ID_KEY"trusted.glusterfs.volume-id", strerror (errno(*__errno_location ())));
5206 goto out;
5207 }
5208
5209 ret = 0;
5210out:
5211 if (strlen (msg))
5212 *op_errstr = gf_strdup (msg);
5213
5214 return ret;
5215}
5216
5217int
5218glusterd_sm_tr_log_transition_add_to_dict (dict_t *dict,
5219 glusterd_sm_tr_log_t *log, int i,
5220 int count)
5221{
5222 int ret = -1;
5223 char key[512] = {0};
5224 char timestr[64] = {0,};
5225 char *str = NULL((void*)0);
5226
5227 GF_ASSERT (dict)do { if (!(dict)) { do { do { if (0) printf ("Assertion failed: "
"dict"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5227, GF_LOG_ERROR, "Assertion failed: " "dict"
); } while (0); } } while (0)
;
5228 GF_ASSERT (log)do { if (!(log)) { do { do { if (0) printf ("Assertion failed: "
"log"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5228, GF_LOG_ERROR, "Assertion failed: " "log"
); } while (0); } } while (0)
;
5229
5230 memset (key, 0, sizeof (key));
5231 snprintf (key, sizeof (key), "log%d-old-state", count);
5232 str = log->state_name_get (log->transitions[i].old_state);
5233 ret = dict_set_str (dict, key, str);
5234 if (ret)
5235 goto out;
5236
5237 memset (key, 0, sizeof (key));
5238 snprintf (key, sizeof (key), "log%d-event", count);
5239 str = log->event_name_get (log->transitions[i].event);
5240 ret = dict_set_str (dict, key, str);
5241 if (ret)
5242 goto out;
5243
5244 memset (key, 0, sizeof (key));
5245 snprintf (key, sizeof (key), "log%d-new-state", count);
5246 str = log->state_name_get (log->transitions[i].new_state);
5247 ret = dict_set_str (dict, key, str);
5248 if (ret)
5249 goto out;
5250
5251
5252 memset (key, 0, sizeof (key));
5253 snprintf (key, sizeof (key), "log%d-time", count);
5254 gf_time_fmt (timestr, sizeof timestr, log->transitions[i].time,
5255 gf_timefmt_FT);
5256 str = gf_strdup (timestr);
5257 ret = dict_set_dynstr (dict, key, str);
5258 if (ret)
5259 goto out;
5260
5261out:
5262 gf_log ("", GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 5262, GF_LOG_DEBUG, "returning %d"
, ret); } while (0)
;
5263 return ret;
5264}
5265
5266int
5267glusterd_sm_tr_log_add_to_dict (dict_t *dict,
5268 glusterd_sm_tr_log_t *circular_log)
5269{
5270 int ret = -1;
5271 int i = 0;
5272 int start = 0;
5273 int end = 0;
5274 int index = 0;
5275 char key[256] = {0};
5276 glusterd_sm_tr_log_t *log = NULL((void*)0);
5277 int count = 0;
5278
5279 GF_ASSERT (dict)do { if (!(dict)) { do { do { if (0) printf ("Assertion failed: "
"dict"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5279, GF_LOG_ERROR, "Assertion failed: " "dict"
); } while (0); } } while (0)
;
5280 GF_ASSERT (circular_log)do { if (!(circular_log)) { do { do { if (0) printf ("Assertion failed: "
"circular_log"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5280, GF_LOG_ERROR, "Assertion failed: " "circular_log"
); } while (0); } } while (0)
;
5281
5282 log = circular_log;
5283 if (!log->count)
5284 return 0;
5285
5286 if (log->count == log->size)
5287 start = log->current + 1;
5288
5289 end = start + log->count;
5290 for (i = start; i < end; i++, count++) {
5291 index = i % log->count;
5292 ret = glusterd_sm_tr_log_transition_add_to_dict (dict, log, index,
5293 count);
5294 if (ret)
5295 goto out;
5296 }
5297
5298 memset (key, 0, sizeof (key));
5299 snprintf (key, sizeof (key), "count");
5300 ret = dict_set_int32 (dict, key, log->count);
5301
5302out:
5303 gf_log ("", GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 5303, GF_LOG_DEBUG, "returning %d"
, ret); } while (0)
;
5304 return ret;
5305}
5306
5307int
5308glusterd_sm_tr_log_init (glusterd_sm_tr_log_t *log,
5309 char * (*state_name_get) (int),
5310 char * (*event_name_get) (int),
5311 size_t size)
5312{
5313 glusterd_sm_transition_t *transitions = NULL((void*)0);
5314 int ret = -1;
5315
5316 GF_ASSERT (size > 0)do { if (!(size > 0)) { do { do { if (0) printf ("Assertion failed: "
"size > 0"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5316, GF_LOG_ERROR, "Assertion failed: " "size > 0"
); } while (0); } } while (0)
;
5317 GF_ASSERT (log && state_name_get && event_name_get)do { if (!(log && state_name_get && event_name_get
)) { do { do { if (0) printf ("Assertion failed: " "log && state_name_get && event_name_get"
); } while (0); _gf_log_callingfn ("", "glusterd-utils.c", __FUNCTION__
, 5317, GF_LOG_ERROR, "Assertion failed: " "log && state_name_get && event_name_get"
); } while (0); } } while (0)
;
5318
5319 if (!log || !state_name_get || !event_name_get || (size <= 0))
5320 goto out;
5321
5322 transitions = GF_CALLOC (size, sizeof (*transitions),__gf_calloc (size, sizeof (*transitions), gf_gld_mt_sm_tr_log_t
)
5323 gf_gld_mt_sm_tr_log_t)__gf_calloc (size, sizeof (*transitions), gf_gld_mt_sm_tr_log_t
)
;
5324 if (!transitions)
5325 goto out;
5326
5327 log->transitions = transitions;
5328 log->size = size;
5329 log->state_name_get = state_name_get;
5330 log->event_name_get = event_name_get;
5331 ret = 0;
5332
5333out:
5334 gf_log ("", GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 5334, GF_LOG_DEBUG, "returning %d"
, ret); } while (0)
;
5335 return ret;
5336}
5337
5338void
5339glusterd_sm_tr_log_delete (glusterd_sm_tr_log_t *log)
5340{
5341 if (!log)
5342 return;
5343 GF_FREE (log->transitions)__gf_free (log->transitions);
5344 return;
5345}
5346
5347int
5348glusterd_sm_tr_log_transition_add (glusterd_sm_tr_log_t *log,
5349 int old_state, int new_state,
5350 int event)
5351{
5352 glusterd_sm_transition_t *transitions = NULL((void*)0);
5353 int ret = -1;
5354 int next = 0;
5355 xlator_t *this = NULL((void*)0);
5356
5357 this = THIS(*__glusterfs_this_location());
5358 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5358, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
5359
5360 GF_ASSERT (log)do { if (!(log)) { do { do { if (0) printf ("Assertion failed: "
"log"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5360, GF_LOG_ERROR, "Assertion failed: " "log"
); } while (0); } } while (0)
;
5361 if (!log)
5362 goto out;
5363
5364 transitions = log->transitions;
5365 if (!transitions)
5366 goto out;
5367
5368 if (log->count)
5369 next = (log->current + 1) % log->size;
5370 else
5371 next = 0;
5372
5373 transitions[next].old_state = old_state;
5374 transitions[next].new_state = new_state;
5375 transitions[next].event = event;
5376 time (&transitions[next].time);
5377 log->current = next;
5378 if (log->count < log->size)
5379 log->count++;
5380 ret = 0;
5381 gf_log (this->name, GF_LOG_DEBUG, "Transitioning from '%s' to '%s' "do { do { if (0) printf ("Transitioning from '%s' to '%s' " "due to event '%s'"
, log->state_name_get (old_state), log->state_name_get (
new_state), log->event_name_get (event)); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 5383, GF_LOG_DEBUG
, "Transitioning from '%s' to '%s' " "due to event '%s'", log
->state_name_get (old_state), log->state_name_get (new_state
), log->event_name_get (event)); } while (0)
5382 "due to event '%s'", log->state_name_get (old_state),do { do { if (0) printf ("Transitioning from '%s' to '%s' " "due to event '%s'"
, log->state_name_get (old_state), log->state_name_get (
new_state), log->event_name_get (event)); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 5383, GF_LOG_DEBUG
, "Transitioning from '%s' to '%s' " "due to event '%s'", log
->state_name_get (old_state), log->state_name_get (new_state
), log->event_name_get (event)); } while (0)
5383 log->state_name_get (new_state), log->event_name_get (event))do { do { if (0) printf ("Transitioning from '%s' to '%s' " "due to event '%s'"
, log->state_name_get (old_state), log->state_name_get (
new_state), log->event_name_get (event)); } while (0); _gf_log
(this->name, "glusterd-utils.c", __FUNCTION__, 5383, GF_LOG_DEBUG
, "Transitioning from '%s' to '%s' " "due to event '%s'", log
->state_name_get (old_state), log->state_name_get (new_state
), log->event_name_get (event)); } while (0)
;
5384out:
5385 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-utils.c", __FUNCTION__, 5385, GF_LOG_DEBUG
, "returning %d", ret); } while (0)
;
5386 return ret;
5387}
5388
5389int
5390glusterd_peerinfo_new (glusterd_peerinfo_t **peerinfo,
5391 glusterd_friend_sm_state_t state, uuid_t *uuid,
5392 const char *hostname, int port)
5393{
5394 glusterd_peerinfo_t *new_peer = NULL((void*)0);
5395 int ret = -1;
5396
5397 GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: "
"peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5397, GF_LOG_ERROR, "Assertion failed: " "peerinfo"
); } while (0); } } while (0)
;
5398 if (!peerinfo)
1
Taking false branch
5399 goto out;
5400
5401 new_peer = GF_CALLOC (1, sizeof (*new_peer), gf_gld_mt_peerinfo_t)__gf_calloc (1, sizeof (*new_peer), gf_gld_mt_peerinfo_t);
5402 if (!new_peer)
2
Assuming 'new_peer' is non-null
3
Taking false branch
5403 goto out;
5404
5405 new_peer->state.state = state;
5406 if (hostname)
4
Assuming 'hostname' is null
5
Taking false branch
5407 new_peer->hostname = gf_strdup (hostname);
5408
5409 INIT_LIST_HEAD (&new_peer->uuid_list)do { (&new_peer->uuid_list)->next = (&new_peer->
uuid_list)->prev = &new_peer->uuid_list; } while (0
)
;
5410
5411 if (uuid) {
6
Assuming 'uuid' is null
7
Taking false branch
5412 uuid_copy (new_peer->uuid, *uuid);
5413 }
5414
5415 ret = glusterd_sm_tr_log_init (&new_peer->sm_log,
5416 glusterd_friend_sm_state_name_get,
5417 glusterd_friend_sm_event_name_get,
5418 GLUSTERD_TR_LOG_SIZE50);
5419 if (ret)
8
Taking true branch
5420 goto out;
9
Control jumps to line 5427
5421
5422 if (new_peer->state.state == GD_FRIEND_STATE_BEFRIENDED)
5423 new_peer->quorum_contrib = QUORUM_WAITING;
5424 new_peer->port = port;
5425 *peerinfo = new_peer;
5426out:
5427 if (ret && new_peer)
10
Taking true branch
5428 glusterd_friend_cleanup (new_peer);
11
Calling 'glusterd_friend_cleanup'
5429 gf_log ("", GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 5429, GF_LOG_DEBUG, "returning %d"
, ret); } while (0)
;
5430 return ret;
5431}
5432
5433int32_t
5434glusterd_peer_destroy (glusterd_peerinfo_t *peerinfo)
5435{
5436 int32_t ret = -1;
5437
5438 if (!peerinfo)
5439 goto out;
5440
5441 ret = glusterd_store_delete_peerinfo (peerinfo);
5442
5443 if (ret) {
5444 gf_log ("", GF_LOG_ERROR, "Deleting peer info failed")do { do { if (0) printf ("Deleting peer info failed"); } while
(0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 5444, GF_LOG_ERROR
, "Deleting peer info failed"); } while (0)
;
5445 }
5446
5447 list_del_init (&peerinfo->uuid_list);
5448 GF_FREE (peerinfo->hostname)__gf_free (peerinfo->hostname);
5449 glusterd_sm_tr_log_delete (&peerinfo->sm_log);
5450 GF_FREE (peerinfo)__gf_free (peerinfo);
5451 peerinfo = NULL((void*)0);
5452
5453 ret = 0;
5454
5455out:
5456 return ret;
5457}
5458
5459int
5460glusterd_remove_pending_entry (struct list_head *list, void *elem)
5461{
5462 glusterd_pending_node_t *pending_node = NULL((void*)0);
5463 glusterd_pending_node_t *tmp = NULL((void*)0);
5464 int ret = 0;
5465
5466 list_for_each_entry_safe (pending_node, tmp, list, list)for (pending_node = ((typeof(*pending_node) *)((char *)((list
)->next)-(unsigned long)(&((typeof(*pending_node) *)0)
->list))), tmp = ((typeof(*pending_node) *)((char *)(pending_node
->list.next)-(unsigned long)(&((typeof(*pending_node) *
)0)->list))); &pending_node->list != (list); pending_node
= tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list.next)-(
unsigned long)(&((typeof(*tmp) *)0)->list))))
{
5467 if (elem == pending_node->node) {
5468 list_del_init (&pending_node->list);
5469 GF_FREE (pending_node)__gf_free (pending_node);
5470 ret = 0;
5471 goto out;
5472 }
5473 }
5474out:
5475 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-utils.c"
, __FUNCTION__, 5475, GF_LOG_DEBUG, "returning %d", ret); } while
(0)
;
5476 return ret;
5477
5478}
5479
5480int
5481glusterd_clear_pending_nodes (struct list_head *list)
5482{
5483 glusterd_pending_node_t *pending_node = NULL((void*)0);
5484 glusterd_pending_node_t *tmp = NULL((void*)0);
5485
5486 list_for_each_entry_safe (pending_node, tmp, list, list)for (pending_node = ((typeof(*pending_node) *)((char *)((list
)->next)-(unsigned long)(&((typeof(*pending_node) *)0)
->list))), tmp = ((typeof(*pending_node) *)((char *)(pending_node
->list.next)-(unsigned long)(&((typeof(*pending_node) *
)0)->list))); &pending_node->list != (list); pending_node
= tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list.next)-(
unsigned long)(&((typeof(*tmp) *)0)->list))))
{
5487 list_del_init (&pending_node->list);
5488 GF_FREE (pending_node)__gf_free (pending_node);
5489 }
5490
5491 return 0;
5492}
5493
5494gf_boolean_t
5495glusterd_peerinfo_is_uuid_unknown (glusterd_peerinfo_t *peerinfo)
5496{
5497 GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: "
"peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5497, GF_LOG_ERROR, "Assertion failed: " "peerinfo"
); } while (0); } } while (0)
;
5498
5499 if (uuid_is_null (peerinfo->uuid))
5500 return _gf_true;
5501 return _gf_false;
5502}
5503
5504int32_t
5505glusterd_delete_volume (glusterd_volinfo_t *volinfo)
5506{
5507 int ret = -1;
5508 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5508, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
5509
5510 ret = glusterd_store_delete_volume (volinfo);
5511
5512 if (ret)
5513 goto out;
5514
5515 ret = glusterd_volinfo_delete (volinfo);
5516out:
5517 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-utils.c"
, __FUNCTION__, 5517, GF_LOG_DEBUG, "returning %d", ret); } while
(0)
;
5518 return ret;
5519}
5520
5521int32_t
5522glusterd_delete_brick (glusterd_volinfo_t* volinfo,
5523 glusterd_brickinfo_t *brickinfo)
5524{
5525 int ret = 0;
5526 char voldir[PATH_MAX4096] = {0,};
5527 glusterd_conf_t *priv = THIS(*__glusterfs_this_location())->private;
5528 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5528, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
5529 GF_ASSERT (brickinfo)do { if (!(brickinfo)) { do { do { if (0) printf ("Assertion failed: "
"brickinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5529, GF_LOG_ERROR, "Assertion failed: " "brickinfo"
); } while (0); } } while (0)
;
5530
5531 GLUSTERD_GET_VOLUME_DIR(voldir, volinfo, priv)snprintf (voldir, 4096, "%s/vols/%s", priv->workdir, volinfo
->volname);
;
5532
5533 glusterd_delete_volfile (volinfo, brickinfo);
5534 glusterd_store_delete_brick (brickinfo, voldir);
5535 glusterd_brickinfo_delete (brickinfo);
5536 volinfo->brick_count--;
5537 return ret;
5538}
5539
5540int32_t
5541glusterd_delete_all_bricks (glusterd_volinfo_t* volinfo)
5542{
5543 int ret = 0;
5544 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
5545 glusterd_brickinfo_t *tmp = NULL((void*)0);
5546
5547 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5547, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
5548
5549 list_for_each_entry_safe (brickinfo, tmp, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo
->bricks)->next)-(unsigned long)(&((typeof(*brickinfo
) *)0)->brick_list))), tmp = ((typeof(*brickinfo) *)((char
*)(brickinfo->brick_list.next)-(unsigned long)(&((typeof
(*brickinfo) *)0)->brick_list))); &brickinfo->brick_list
!= (&volinfo->bricks); brickinfo = tmp, tmp = ((typeof
(*tmp) *)((char *)(tmp->brick_list.next)-(unsigned long)(&
((typeof(*tmp) *)0)->brick_list))))
{
5550 ret = glusterd_delete_brick (volinfo, brickinfo);
5551 }
5552 return ret;
5553}
5554
5555int
5556glusterd_start_gsync (glusterd_volinfo_t *master_vol, char *slave,
5557 char *glusterd_uuid_str, char **op_errstr)
5558{
5559 int32_t ret = 0;
5560 int32_t status = 0;
5561 char buf[PATH_MAX4096] = {0,};
5562 char uuid_str [64] = {0};
5563 runner_t runner = {0,};
5564 xlator_t *this = NULL((void*)0);
5565 glusterd_conf_t *priv = NULL((void*)0);
5566 int errcode = 0;
5567
5568 this = THIS(*__glusterfs_this_location());
5569 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5569, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
5570 priv = this->private;
5571 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5571, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
5572
5573 uuid_utoa_r (MY_UUID(__glusterd_uuid()), uuid_str);
5574 if (strcmp (uuid_str, glusterd_uuid_str))
5575 goto out;
5576
5577 ret = gsync_status (master_vol->volname, slave, &status);
5578 if (status == 0)
5579 goto out;
5580
5581 snprintf (buf, PATH_MAX4096, "%s/"GEOREP"geo-replication""/%s", priv->workdir, master_vol->volname);
5582 ret = mkdir_p (buf, 0777, _gf_true);
5583 if (ret) {
5584 errcode = -1;
5585 goto out;
5586 }
5587
5588 snprintf (buf, PATH_MAX4096, DEFAULT_LOG_FILE_DIRECTORY"/usr/local/var" "/log/glusterfs""/"GEOREP"geo-replication""/%s",
5589 master_vol->volname);
5590 ret = mkdir_p (buf, 0777, _gf_true);
5591 if (ret) {
5592 errcode = -1;
5593 goto out;
5594 }
5595
5596 uuid_utoa_r (master_vol->volume_id, uuid_str);
5597 runinit (&runner);
5598 runner_add_args (&runner, GSYNCD_PREFIX"/usr/local/libexec/glusterfs""/gsyncd", "-c", NULL((void*)0));
5599 runner_argprintf (&runner, "%s/"GSYNC_CONF"geo-replication""/gsyncd.conf", priv->workdir);
5600 runner_argprintf (&runner, ":%s", master_vol->volname);
5601 runner_add_args (&runner, slave, "--config-set", "session-owner",
5602 uuid_str, NULL((void*)0));
5603 synclock_unlock (&priv->big_lock);
5604 ret = runner_run (&runner);
5605 synclock_lock (&priv->big_lock);
5606 if (ret == -1) {
5607 errcode = -1;
5608 goto out;
5609 }
5610
5611 runinit (&runner);
5612 runner_add_args (&runner, GSYNCD_PREFIX"/usr/local/libexec/glusterfs""/gsyncd", "--monitor", "-c", NULL((void*)0));
5613 runner_argprintf (&runner, "%s/"GSYNC_CONF"geo-replication""/gsyncd.conf", priv->workdir);
5614 runner_argprintf (&runner, ":%s", master_vol->volname);
5615 runner_add_arg (&runner, slave);
5616 synclock_unlock (&priv->big_lock);
5617 ret = runner_run (&runner);
5618 synclock_lock (&priv->big_lock);
5619 if (ret == -1) {
5620 gf_asprintf (op_errstr, GEOREP"geo-replication"" start failed for %s %s",
5621 master_vol->volname, slave);
5622 goto out;
5623 }
5624
5625 ret = 0;
5626
5627out:
5628 if ((ret != 0) && errcode == -1) {
5629 if (op_errstr)
5630 *op_errstr = gf_strdup ("internal error, cannot start"
5631 "the " GEOREP"geo-replication" " session");
5632 }
5633
5634 gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 5634, GF_LOG_DEBUG, "Returning %d"
, ret); } while (0)
;
5635 return ret;
5636}
5637
5638int32_t
5639glusterd_recreate_bricks (glusterd_conf_t *conf)
5640{
5641
5642 glusterd_volinfo_t *volinfo = NULL((void*)0);
5643 int ret = 0;
5644
5645 GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: "
"conf"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5645, GF_LOG_ERROR, "Assertion failed: " "conf"
); } while (0); } } while (0)
;
5646 list_for_each_entry (volinfo, &conf->volumes, vol_list)for (volinfo = ((typeof(*volinfo) *)((char *)((&conf->
volumes)->next)-(unsigned long)(&((typeof(*volinfo) *)
0)->vol_list))); &volinfo->vol_list != (&conf->
volumes); volinfo = ((typeof(*volinfo) *)((char *)(volinfo->
vol_list.next)-(unsigned long)(&((typeof(*volinfo) *)0)->
vol_list))))
{
5647 ret = generate_brick_volfiles (volinfo);
5648 }
5649 return ret;
5650}
5651
5652int32_t
5653glusterd_handle_upgrade_downgrade (dict_t *options, glusterd_conf_t *conf)
5654{
5655 int ret = 0;
5656 char *type = NULL((void*)0);
5657 gf_boolean_t upgrade = _gf_false;
5658 gf_boolean_t downgrade = _gf_false;
5659 gf_boolean_t regenerate_brick_volfiles = _gf_false;
5660 gf_boolean_t terminate = _gf_false;
5661
5662 ret = dict_get_str (options, "upgrade", &type);
5663 if (!ret) {
5664 ret = gf_string2boolean (type, &upgrade);
5665 if (ret) {
5666 gf_log ("glusterd", GF_LOG_ERROR, "upgrade option "do { do { if (0) printf ("upgrade option " "%s is not a valid boolean type"
, type); } while (0); _gf_log ("glusterd", "glusterd-utils.c"
, __FUNCTION__, 5667, GF_LOG_ERROR, "upgrade option " "%s is not a valid boolean type"
, type); } while (0)
5667 "%s is not a valid boolean type", type)do { do { if (0) printf ("upgrade option " "%s is not a valid boolean type"
, type); } while (0); _gf_log ("glusterd", "glusterd-utils.c"
, __FUNCTION__, 5667, GF_LOG_ERROR, "upgrade option " "%s is not a valid boolean type"
, type); } while (0)
;
5668 ret = -1;
5669 goto out;
5670 }
5671 if (_gf_true == upgrade)
5672 regenerate_brick_volfiles = _gf_true;
5673 }
5674
5675 ret = dict_get_str (options, "downgrade", &type);
5676 if (!ret) {
5677 ret = gf_string2boolean (type, &downgrade);
5678 if (ret) {
5679 gf_log ("glusterd", GF_LOG_ERROR, "downgrade option "do { do { if (0) printf ("downgrade option " "%s is not a valid boolean type"
, type); } while (0); _gf_log ("glusterd", "glusterd-utils.c"
, __FUNCTION__, 5680, GF_LOG_ERROR, "downgrade option " "%s is not a valid boolean type"
, type); } while (0)
5680 "%s is not a valid boolean type", type)do { do { if (0) printf ("downgrade option " "%s is not a valid boolean type"
, type); } while (0); _gf_log ("glusterd", "glusterd-utils.c"
, __FUNCTION__, 5680, GF_LOG_ERROR, "downgrade option " "%s is not a valid boolean type"
, type); } while (0)
;
5681 ret = -1;
5682 goto out;
5683 }
5684 }
5685
5686 if (upgrade && downgrade) {
5687 gf_log ("glusterd", GF_LOG_ERROR, "Both upgrade and downgrade"do { do { if (0) printf ("Both upgrade and downgrade" " options are set. Only one should be on"
); } while (0); _gf_log ("glusterd", "glusterd-utils.c", __FUNCTION__
, 5688, GF_LOG_ERROR, "Both upgrade and downgrade" " options are set. Only one should be on"
); } while (0)
5688 " options are set. Only one should be on")do { do { if (0) printf ("Both upgrade and downgrade" " options are set. Only one should be on"
); } while (0); _gf_log ("glusterd", "glusterd-utils.c", __FUNCTION__
, 5688, GF_LOG_ERROR, "Both upgrade and downgrade" " options are set. Only one should be on"
); } while (0)
;
5689 ret = -1;
5690 goto out;
5691 }
5692
5693 if (!upgrade && !downgrade)
5694 ret = 0;
5695 else
5696 terminate = _gf_true;
5697 if (regenerate_brick_volfiles) {
5698 ret = glusterd_recreate_bricks (conf);
5699 }
5700out:
5701 if (terminate && (ret == 0))
5702 kill (getpid(), SIGTERM15);
5703 return ret;
5704}
5705
5706gf_boolean_t
5707glusterd_is_volume_replicate (glusterd_volinfo_t *volinfo)
5708{
5709 gf_boolean_t replicates = _gf_false;
5710 if (volinfo && ((volinfo->type == GF_CLUSTER_TYPE_REPLICATE) ||
5711 (volinfo->type == GF_CLUSTER_TYPE_STRIPE_REPLICATE)))
5712 replicates = _gf_true;
5713 return replicates;
5714}
5715
5716int
5717glusterd_set_dump_options (char *dumpoptions_path, char *options,
5718 int option_cnt)
5719{
5720 int ret = 0;
5721 char *dup_options = NULL((void*)0);
5722 char *option = NULL((void*)0);
5723 char *tmpptr = NULL((void*)0);
5724 FILE *fp = NULL((void*)0);
5725 int nfs_cnt = 0;
5726
5727 if (0 == option_cnt ||
5728 (option_cnt == 1 && (!strcmp (options, "nfs ")))) {
5729 ret = 0;
5730 goto out;
5731 }
5732
5733 fp = fopen (dumpoptions_path, "w");
5734 if (!fp) {
5735 ret = -1;
5736 goto out;
5737 }
5738 dup_options = gf_strdup (options);
5739 gf_log ("", GF_LOG_INFO, "Received following statedump options: %s",do { do { if (0) printf ("Received following statedump options: %s"
, dup_options); } while (0); _gf_log ("", "glusterd-utils.c",
__FUNCTION__, 5740, GF_LOG_INFO, "Received following statedump options: %s"
, dup_options); } while (0)
5740 dup_options)do { do { if (0) printf ("Received following statedump options: %s"
, dup_options); } while (0); _gf_log ("", "glusterd-utils.c",
__FUNCTION__, 5740, GF_LOG_INFO, "Received following statedump options: %s"
, dup_options); } while (0)
;
5741 option = strtok_r (dup_options, " ", &tmpptr);
5742 while (option) {
5743 if (!strcmp (option, "nfs")) {
5744 if (nfs_cnt > 0) {
5745 unlink (dumpoptions_path);
5746 ret = 0;
5747 goto out;
5748 }
5749 nfs_cnt++;
5750 option = strtok_r (NULL((void*)0), " ", &tmpptr);
5751 continue;
5752 }
5753 fprintf (fp, "%s=yes\n", option);
5754 option = strtok_r (NULL((void*)0), " ", &tmpptr);
5755 }
5756
5757out:
5758 if (fp)
5759 fclose (fp);
5760 GF_FREE (dup_options)__gf_free (dup_options);
5761 return ret;
5762}
5763
5764int
5765glusterd_brick_statedump (glusterd_volinfo_t *volinfo,
5766 glusterd_brickinfo_t *brickinfo,
5767 char *options, int option_cnt, char **op_errstr)
5768{
5769 int ret = -1;
5770 xlator_t *this = NULL((void*)0);
5771 glusterd_conf_t *conf = NULL((void*)0);
5772 char pidfile_path[PATH_MAX4096] = {0,};
5773 char dumpoptions_path[PATH_MAX4096] = {0,};
5774 FILE *pidfile = NULL((void*)0);
5775 pid_t pid = -1;
5776
5777 this = THIS(*__glusterfs_this_location());
5778 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5778, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
5779 conf = this->private;
5780 GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: "
"conf"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5780, GF_LOG_ERROR, "Assertion failed: " "conf"
); } while (0); } } while (0)
;
5781
5782 if (uuid_is_null (brickinfo->uuid)) {
5783 ret = glusterd_resolve_brick (brickinfo);
5784 if (ret) {
5785 gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("Cannot resolve brick %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log ("glusterd"
, "glusterd-utils.c", __FUNCTION__, 5787, GF_LOG_ERROR, "Cannot resolve brick %s:%s"
, brickinfo->hostname, brickinfo->path); } while (0)
5786 "Cannot resolve brick %s:%s",do { do { if (0) printf ("Cannot resolve brick %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log ("glusterd"
, "glusterd-utils.c", __FUNCTION__, 5787, GF_LOG_ERROR, "Cannot resolve brick %s:%s"
, brickinfo->hostname, brickinfo->path); } while (0)
5787 brickinfo->hostname, brickinfo->path)do { do { if (0) printf ("Cannot resolve brick %s:%s", brickinfo
->hostname, brickinfo->path); } while (0); _gf_log ("glusterd"
, "glusterd-utils.c", __FUNCTION__, 5787, GF_LOG_ERROR, "Cannot resolve brick %s:%s"
, brickinfo->hostname, brickinfo->path); } while (0)
;
5788 goto out;
5789 }
5790 }
5791
5792 if (uuid_compare (brickinfo->uuid, MY_UUID(__glusterd_uuid()))) {
5793 ret = 0;
5794 goto out;
5795 }
5796
5797 GLUSTERD_GET_BRICK_PIDFILE (pidfile_path, volinfo, brickinfo, conf)do { char exp_path[4096] = {0,}; char volpath[4096] = {0,}; snprintf
(volpath, 4096, "%s/vols/%s", conf->workdir, volinfo->
volname);; do { int i = 0; for (i = 1; i < strlen (brickinfo
->path); i++) { exp_path[i-1] = brickinfo->path[i]; if (
exp_path[i-1] == '/') exp_path[i-1] = '-'; } } while (0); snprintf
(pidfile_path, 4096, "%s/run/%s-%s.pid", volpath, brickinfo->
hostname, exp_path); } while (0)
;
5798
5799 pidfile = fopen (pidfile_path, "r");
5800 if (!pidfile) {
5801 gf_log ("", GF_LOG_ERROR, "Unable to open pidfile: %s",do { do { if (0) printf ("Unable to open pidfile: %s", pidfile_path
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5802, GF_LOG_ERROR, "Unable to open pidfile: %s", pidfile_path
); } while (0)
5802 pidfile_path)do { do { if (0) printf ("Unable to open pidfile: %s", pidfile_path
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5802, GF_LOG_ERROR, "Unable to open pidfile: %s", pidfile_path
); } while (0)
;
5803 ret = -1;
5804 goto out;
5805 }
5806
5807 ret = fscanf (pidfile, "%d", &pid);
5808 if (ret <= 0) {
5809 gf_log ("", GF_LOG_ERROR, "Unable to get pid of brick process")do { do { if (0) printf ("Unable to get pid of brick process"
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5809, GF_LOG_ERROR, "Unable to get pid of brick process"); }
while (0)
;
5810 ret = -1;
5811 goto out;
5812 }
5813
5814 snprintf (dumpoptions_path, sizeof (dumpoptions_path),
5815 DEFAULT_VAR_RUN_DIRECTORY"/usr/local/var" "/run/gluster""/glusterdump.%d.options", pid);
5816 ret = glusterd_set_dump_options (dumpoptions_path, options, option_cnt);
5817 if (ret < 0) {
5818 gf_log ("", GF_LOG_ERROR, "error while parsing the statedump "do { do { if (0) printf ("error while parsing the statedump "
"options"); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5819, GF_LOG_ERROR, "error while parsing the statedump " "options"
); } while (0)
5819 "options")do { do { if (0) printf ("error while parsing the statedump "
"options"); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5819, GF_LOG_ERROR, "error while parsing the statedump " "options"
); } while (0)
;
5820 ret = -1;
5821 goto out;
5822 }
5823
5824 gf_log ("", GF_LOG_INFO, "Performing statedump on brick with pid %d",do { do { if (0) printf ("Performing statedump on brick with pid %d"
, pid); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5825, GF_LOG_INFO, "Performing statedump on brick with pid %d"
, pid); } while (0)
5825 pid)do { do { if (0) printf ("Performing statedump on brick with pid %d"
, pid); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5825, GF_LOG_INFO, "Performing statedump on brick with pid %d"
, pid); } while (0)
;
5826
5827 kill (pid, SIGUSR110);
5828
5829 sleep (1);
5830 ret = 0;
5831out:
5832 unlink (dumpoptions_path);
5833 if (pidfile)
5834 fclose (pidfile);
5835 return ret;
5836}
5837
5838int
5839glusterd_nfs_statedump (char *options, int option_cnt, char **op_errstr)
5840{
5841 int ret = -1;
5842 xlator_t *this = NULL((void*)0);
5843 glusterd_conf_t *conf = NULL((void*)0);
5844 char pidfile_path[PATH_MAX4096] = {0,};
5845 char path[PATH_MAX4096] = {0,};
5846 FILE *pidfile = NULL((void*)0);
5847 pid_t pid = -1;
5848 char dumpoptions_path[PATH_MAX4096] = {0,};
5849 char *option = NULL((void*)0);
5850 char *tmpptr = NULL((void*)0);
5851 char *dup_options = NULL((void*)0);
5852 char msg[256] = {0,};
5853
5854 this = THIS(*__glusterfs_this_location());
5855 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5855, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
5856 conf = this->private;
5857 GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: "
"conf"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5857, GF_LOG_ERROR, "Assertion failed: " "conf"
); } while (0); } } while (0)
;
5858
5859 dup_options = gf_strdup (options);
5860 option = strtok_r (dup_options, " ", &tmpptr);
5861 if (strcmp (option, "nfs")) {
5862 snprintf (msg, sizeof (msg), "for nfs statedump, options should"
5863 " be after the key nfs");
5864 *op_errstr = gf_strdup (msg);
5865 ret = -1;
5866 goto out;
5867 }
5868
5869 GLUSTERD_GET_NFS_DIR (path, conf)snprintf (path, 4096, "%s/nfs", conf->workdir);;
5870 GLUSTERD_GET_NFS_PIDFILE (pidfile_path, path){ snprintf (pidfile_path, 4096, "%s/run/nfs.pid", path); };
5871
5872 pidfile = fopen (pidfile_path, "r");
5873 if (!pidfile) {
5874 gf_log ("", GF_LOG_ERROR, "Unable to open pidfile: %s",do { do { if (0) printf ("Unable to open pidfile: %s", pidfile_path
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5875, GF_LOG_ERROR, "Unable to open pidfile: %s", pidfile_path
); } while (0)
5875 pidfile_path)do { do { if (0) printf ("Unable to open pidfile: %s", pidfile_path
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5875, GF_LOG_ERROR, "Unable to open pidfile: %s", pidfile_path
); } while (0)
;
5876 ret = -1;
5877 goto out;
5878 }
5879
5880 ret = fscanf (pidfile, "%d", &pid);
5881 if (ret <= 0) {
5882 gf_log ("", GF_LOG_ERROR, "Unable to get pid of brick process")do { do { if (0) printf ("Unable to get pid of brick process"
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5882, GF_LOG_ERROR, "Unable to get pid of brick process"); }
while (0)
;
5883 ret = -1;
5884 goto out;
5885 }
5886
5887 snprintf (dumpoptions_path, sizeof (dumpoptions_path),
5888 DEFAULT_VAR_RUN_DIRECTORY"/usr/local/var" "/run/gluster""/glusterdump.%d.options", pid);
5889 ret = glusterd_set_dump_options (dumpoptions_path, options, option_cnt);
5890 if (ret < 0) {
5891 gf_log ("", GF_LOG_ERROR, "error while parsing the statedump "do { do { if (0) printf ("error while parsing the statedump "
"options"); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5892, GF_LOG_ERROR, "error while parsing the statedump " "options"
); } while (0)
5892 "options")do { do { if (0) printf ("error while parsing the statedump "
"options"); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 5892, GF_LOG_ERROR, "error while parsing the statedump " "options"
); } while (0)
;
5893 ret = -1;
5894 goto out;
5895 }
5896
5897 gf_log ("", GF_LOG_INFO, "Performing statedump on nfs server with "do { do { if (0) printf ("Performing statedump on nfs server with "
"pid %d", pid); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 5898, GF_LOG_INFO, "Performing statedump on nfs server with "
"pid %d", pid); } while (0)
5898 "pid %d", pid)do { do { if (0) printf ("Performing statedump on nfs server with "
"pid %d", pid); } while (0); _gf_log ("", "glusterd-utils.c"
, __FUNCTION__, 5898, GF_LOG_INFO, "Performing statedump on nfs server with "
"pid %d", pid); } while (0)
;
5899
5900 kill (pid, SIGUSR110);
5901
5902 sleep (1);
5903
5904 ret = 0;
5905out:
5906 if (pidfile)
5907 fclose (pidfile);
5908 unlink (dumpoptions_path);
5909 GF_FREE (dup_options)__gf_free (dup_options);
5910 return ret;
5911}
5912
5913/* Checks if the given peer contains all the bricks belonging to the
5914 * given volume. Returns true if it does else returns false
5915 */
5916gf_boolean_t
5917glusterd_friend_contains_vol_bricks (glusterd_volinfo_t *volinfo,
5918 uuid_t friend_uuid)
5919{
5920 gf_boolean_t ret = _gf_true;
5921 glusterd_brickinfo_t *brickinfo = NULL((void*)0);
5922
5923 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5923, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
5924
5925 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))))
{
5926 if (uuid_compare (friend_uuid, brickinfo->uuid)) {
5927 ret = _gf_false;
5928 break;
5929 }
5930 }
5931 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-utils.c"
, __FUNCTION__, 5931, GF_LOG_DEBUG, "Returning %d", ret); } while
(0)
;
5932 return ret;
5933}
5934
5935/* Remove all volumes which completely belong to given friend
5936 */
5937int
5938glusterd_friend_remove_cleanup_vols (uuid_t uuid)
5939{
5940 int ret = -1;
5941 glusterd_conf_t *priv = NULL((void*)0);
5942 glusterd_volinfo_t *volinfo = NULL((void*)0);
5943 glusterd_volinfo_t *tmp_volinfo = NULL((void*)0);
5944
5945 priv = THIS(*__glusterfs_this_location())->private;
5946 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5946, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
5947
5948 list_for_each_entry_safe (volinfo, tmp_volinfo,for (volinfo = ((typeof(*volinfo) *)((char *)((&priv->
volumes)->next)-(unsigned long)(&((typeof(*volinfo) *)
0)->vol_list))), tmp_volinfo = ((typeof(*volinfo) *)((char
*)(volinfo->vol_list.next)-(unsigned long)(&((typeof(
*volinfo) *)0)->vol_list))); &volinfo->vol_list != (
&priv->volumes); volinfo = tmp_volinfo, tmp_volinfo = (
(typeof(*tmp_volinfo) *)((char *)(tmp_volinfo->vol_list.next
)-(unsigned long)(&((typeof(*tmp_volinfo) *)0)->vol_list
))))
5949 &priv->volumes, vol_list)for (volinfo = ((typeof(*volinfo) *)((char *)((&priv->
volumes)->next)-(unsigned long)(&((typeof(*volinfo) *)
0)->vol_list))), tmp_volinfo = ((typeof(*volinfo) *)((char
*)(volinfo->vol_list.next)-(unsigned long)(&((typeof(
*volinfo) *)0)->vol_list))); &volinfo->vol_list != (
&priv->volumes); volinfo = tmp_volinfo, tmp_volinfo = (
(typeof(*tmp_volinfo) *)((char *)(tmp_volinfo->vol_list.next
)-(unsigned long)(&((typeof(*tmp_volinfo) *)0)->vol_list
))))
{
5950 if (glusterd_friend_contains_vol_bricks (volinfo, uuid)) {
5951 gf_log (THIS->name, GF_LOG_INFO,do { do { if (0) printf ("Deleting stale volume %s", volinfo->
volname); } while (0); _gf_log ((*__glusterfs_this_location()
)->name, "glusterd-utils.c", __FUNCTION__, 5952, GF_LOG_INFO
, "Deleting stale volume %s", volinfo->volname); } while (
0)
5952 "Deleting stale volume %s", volinfo->volname)do { do { if (0) printf ("Deleting stale volume %s", volinfo->
volname); } while (0); _gf_log ((*__glusterfs_this_location()
)->name, "glusterd-utils.c", __FUNCTION__, 5952, GF_LOG_INFO
, "Deleting stale volume %s", volinfo->volname); } while (
0)
;
5953 ret = glusterd_delete_volume (volinfo);
5954 if (ret) {
5955 gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("Error deleting stale volume"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 5956, GF_LOG_ERROR, "Error deleting stale volume"
); } while (0)
5956 "Error deleting stale volume")do { do { if (0) printf ("Error deleting stale volume"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 5956, GF_LOG_ERROR, "Error deleting stale volume"
); } while (0)
;
5957 goto out;
5958 }
5959 }
5960 }
5961 ret = 0;
5962out:
5963 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-utils.c"
, __FUNCTION__, 5963, GF_LOG_DEBUG, "Returning %d", ret); } while
(0)
;
5964 return ret;
5965}
5966
5967/* Check if the all peers are connected and befriended, except the peer
5968 * specified (the peer being detached)
5969 */
5970gf_boolean_t
5971glusterd_chk_peers_connected_befriended (uuid_t skip_uuid)
5972{
5973 gf_boolean_t ret = _gf_true;
5974 glusterd_peerinfo_t *peerinfo = NULL((void*)0);
5975 glusterd_conf_t *priv = NULL((void*)0);
5976
5977 priv= THIS(*__glusterfs_this_location())->private;
5978 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 5978, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
5979
5980 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))))
{
5981
5982 if (!uuid_is_null (skip_uuid) && !uuid_compare (skip_uuid,
5983 peerinfo->uuid))
5984 continue;
5985
5986 if ((GD_FRIEND_STATE_BEFRIENDED != peerinfo->state.state)
5987 || !(peerinfo->connected)) {
5988 ret = _gf_false;
5989 break;
5990 }
5991 }
5992 gf_log (THIS->name, GF_LOG_DEBUG, "Returning %s",do { do { if (0) printf ("Returning %s", (ret?"TRUE":"FALSE")
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 5993, GF_LOG_DEBUG, "Returning %s"
, (ret?"TRUE":"FALSE")); } while (0)
5993 (ret?"TRUE":"FALSE"))do { do { if (0) printf ("Returning %s", (ret?"TRUE":"FALSE")
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 5993, GF_LOG_DEBUG, "Returning %s"
, (ret?"TRUE":"FALSE")); } while (0)
;
5994 return ret;
5995}
5996
5997void
5998glusterd_get_client_filepath (char *filepath, glusterd_volinfo_t *volinfo,
5999 gf_transport_type type)
6000{
6001 char path[PATH_MAX4096] = {0,};
6002 glusterd_conf_t *priv = NULL((void*)0);
6003
6004 priv = THIS(*__glusterfs_this_location())->private;
6005
6006 GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv)snprintf (path, 4096, "%s/vols/%s", priv->workdir, volinfo
->volname);
;
6007
6008 if ((volinfo->transport_type == GF_TRANSPORT_BOTH_TCP_RDMA) &&
6009 (type == GF_TRANSPORT_RDMA))
6010 snprintf (filepath, PATH_MAX4096, "%s/%s.rdma-fuse.vol",
6011 path, volinfo->volname);
6012 else
6013 snprintf (filepath, PATH_MAX4096, "%s/%s-fuse.vol",
6014 path, volinfo->volname);
6015}
6016
6017void
6018glusterd_get_trusted_client_filepath (char *filepath,
6019 glusterd_volinfo_t *volinfo,
6020 gf_transport_type type)
6021{
6022 char path[PATH_MAX4096] = {0,};
6023 glusterd_conf_t *priv = NULL((void*)0);
6024
6025 priv = THIS(*__glusterfs_this_location())->private;
6026
6027 GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv)snprintf (path, 4096, "%s/vols/%s", priv->workdir, volinfo
->volname);
;
6028
6029 if ((volinfo->transport_type == GF_TRANSPORT_BOTH_TCP_RDMA) &&
6030 (type == GF_TRANSPORT_RDMA))
6031 snprintf (filepath, PATH_MAX4096,
6032 "%s/trusted-%s.rdma-fuse.vol",
6033 path, volinfo->volname);
6034 else
6035 snprintf (filepath, PATH_MAX4096,
6036 "%s/trusted-%s-fuse.vol",
6037 path, volinfo->volname);
6038}
6039
6040int
6041glusterd_volume_defrag_restart (glusterd_volinfo_t *volinfo, char *op_errstr,
6042 size_t len, int cmd, defrag_cbk_fn_t cbk)
6043{
6044 glusterd_conf_t *priv = NULL((void*)0);
6045 char pidfile[PATH_MAX4096];
6046 int ret = -1;
6047 pid_t pid;
6048
6049 priv = THIS(*__glusterfs_this_location())->private;
6050 if (!priv)
6051 return ret;
6052
6053 GLUSTERD_GET_DEFRAG_PID_FILE(pidfile, volinfo, priv)do { char defrag_path[4096]; do { char vol_path[4096]; snprintf
(vol_path, 4096, "%s/vols/%s", priv->workdir, volinfo->
volname);; snprintf (defrag_path, 4096, "%s/rebalance",vol_path
); } while (0); snprintf (pidfile, 4096, "%s/%s.pid", defrag_path
, uuid_utoa((__glusterd_uuid()))); } while (0)
;
6054
6055 if (!glusterd_is_service_running (pidfile, &pid)) {
6056 glusterd_handle_defrag_start (volinfo, op_errstr, len, cmd,
6057 cbk, volinfo->rebal.op);
6058 } else {
6059 glusterd_rebalance_rpc_create (volinfo, priv, cmd);
6060 }
6061
6062 return ret;
6063}
6064
6065int
6066glusterd_restart_rebalance (glusterd_conf_t *conf)
6067{
6068 glusterd_volinfo_t *volinfo = NULL((void*)0);
6069 int ret = 0;
6070 char op_errstr[256];
6071
6072 list_for_each_entry (volinfo, &conf->volumes, vol_list)for (volinfo = ((typeof(*volinfo) *)((char *)((&conf->
volumes)->next)-(unsigned long)(&((typeof(*volinfo) *)
0)->vol_list))); &volinfo->vol_list != (&conf->
volumes); volinfo = ((typeof(*volinfo) *)((char *)(volinfo->
vol_list.next)-(unsigned long)(&((typeof(*volinfo) *)0)->
vol_list))))
{
6073 if (!volinfo->rebal.defrag_cmd)
6074 continue;
6075 glusterd_volume_defrag_restart (volinfo, op_errstr, 256,
6076 volinfo->rebal.defrag_cmd, NULL((void*)0));
6077 }
6078 return ret;
6079}
6080
6081void
6082glusterd_volinfo_reset_defrag_stats (glusterd_volinfo_t *volinfo)
6083{
6084 glusterd_rebalance_t *rebal = NULL((void*)0);
6085 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6085, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
6086
6087 rebal = &volinfo->rebal;
6088 rebal->rebalance_files = 0;
6089 rebal->rebalance_data = 0;
6090 rebal->lookedup_files = 0;
6091 rebal->rebalance_failures = 0;
6092 rebal->rebalance_time = 0;
6093
6094}
6095
6096/* Return hostname for given uuid if it exists
6097 * else return NULL
6098 */
6099char *
6100glusterd_uuid_to_hostname (uuid_t uuid)
6101{
6102 char *hostname = NULL((void*)0);
6103 glusterd_conf_t *priv = NULL((void*)0);
6104 glusterd_peerinfo_t *entry = NULL((void*)0);
6105
6106 priv = THIS(*__glusterfs_this_location())->private;
6107 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6107, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
6108
6109 if (!uuid_compare (MY_UUID(__glusterd_uuid()), uuid)) {
6110 hostname = gf_strdup ("localhost");
6111 }
6112 if (!list_empty (&priv->peers)) {
6113 list_for_each_entry (entry, &priv->peers, uuid_list)for (entry = ((typeof(*entry) *)((char *)((&priv->peers
)->next)-(unsigned long)(&((typeof(*entry) *)0)->uuid_list
))); &entry->uuid_list != (&priv->peers); entry
= ((typeof(*entry) *)((char *)(entry->uuid_list.next)-(unsigned
long)(&((typeof(*entry) *)0)->uuid_list))))
{
6114 if (!uuid_compare (entry->uuid, uuid)) {
6115 hostname = gf_strdup (entry->hostname);
6116 break;
6117 }
6118 }
6119 }
6120
6121 return hostname;
6122}
6123
6124gf_boolean_t
6125glusterd_is_local_brick (xlator_t *this, glusterd_volinfo_t *volinfo,
6126 glusterd_brickinfo_t *brickinfo)
6127{
6128 gf_boolean_t local = _gf_false;
6129 int ret = 0;
6130 glusterd_conf_t *conf = NULL((void*)0);
6131
6132 if (uuid_is_null (brickinfo->uuid)) {
6133 ret = glusterd_resolve_brick (brickinfo);
6134 if (ret)
6135 goto out;
6136 }
6137 conf = this->private;
6138 local = !uuid_compare (brickinfo->uuid, MY_UUID(__glusterd_uuid()));
6139out:
6140 return local;
6141}
6142int
6143glusterd_validate_volume_id (dict_t *op_dict, glusterd_volinfo_t *volinfo)
6144{
6145 int ret = -1;
6146 char *volid_str = NULL((void*)0);
6147 uuid_t vol_uid = {0, };
6148 xlator_t *this = NULL((void*)0);
6149
6150 this = THIS(*__glusterfs_this_location());
6151 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6151, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
6152
6153 ret = dict_get_str (op_dict, "vol-id", &volid_str);
6154 if (ret) {
6155 gf_log (this->name, GF_LOG_ERROR, "Failed to get volume id for "do { do { if (0) printf ("Failed to get volume id for " "volume %s"
, volinfo->volname); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 6156, GF_LOG_ERROR, "Failed to get volume id for "
"volume %s", volinfo->volname); } while (0)
6156 "volume %s", volinfo->volname)do { do { if (0) printf ("Failed to get volume id for " "volume %s"
, volinfo->volname); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 6156, GF_LOG_ERROR, "Failed to get volume id for "
"volume %s", volinfo->volname); } while (0)
;
6157 goto out;
6158 }
6159 ret = uuid_parse (volid_str, vol_uid);
6160 if (ret) {
6161 gf_log (this->name, GF_LOG_ERROR, "Failed to parse volume id "do { do { if (0) printf ("Failed to parse volume id " "for volume %s"
, volinfo->volname); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 6162, GF_LOG_ERROR, "Failed to parse volume id "
"for volume %s", volinfo->volname); } while (0)
6162 "for volume %s", volinfo->volname)do { do { if (0) printf ("Failed to parse volume id " "for volume %s"
, volinfo->volname); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 6162, GF_LOG_ERROR, "Failed to parse volume id "
"for volume %s", volinfo->volname); } while (0)
;
6163 goto out;
6164 }
6165
6166 if (uuid_compare (vol_uid, volinfo->volume_id)) {
6167 gf_log (this->name, GF_LOG_ERROR, "Volume ids of volume %s - %s"do { do { if (0) printf ("Volume ids of volume %s - %s" " and %s - are different. Possibly a split brain among "
"peers.", volinfo->volname, volid_str, uuid_utoa (volinfo
->volume_id)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 6170, GF_LOG_ERROR, "Volume ids of volume %s - %s"
" and %s - are different. Possibly a split brain among " "peers."
, volinfo->volname, volid_str, uuid_utoa (volinfo->volume_id
)); } while (0)
6168 " and %s - are different. Possibly a split brain among "do { do { if (0) printf ("Volume ids of volume %s - %s" " and %s - are different. Possibly a split brain among "
"peers.", volinfo->volname, volid_str, uuid_utoa (volinfo
->volume_id)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 6170, GF_LOG_ERROR, "Volume ids of volume %s - %s"
" and %s - are different. Possibly a split brain among " "peers."
, volinfo->volname, volid_str, uuid_utoa (volinfo->volume_id
)); } while (0)
6169 "peers.", volinfo->volname, volid_str,do { do { if (0) printf ("Volume ids of volume %s - %s" " and %s - are different. Possibly a split brain among "
"peers.", volinfo->volname, volid_str, uuid_utoa (volinfo
->volume_id)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 6170, GF_LOG_ERROR, "Volume ids of volume %s - %s"
" and %s - are different. Possibly a split brain among " "peers."
, volinfo->volname, volid_str, uuid_utoa (volinfo->volume_id
)); } while (0)
6170 uuid_utoa (volinfo->volume_id))do { do { if (0) printf ("Volume ids of volume %s - %s" " and %s - are different. Possibly a split brain among "
"peers.", volinfo->volname, volid_str, uuid_utoa (volinfo
->volume_id)); } while (0); _gf_log (this->name, "glusterd-utils.c"
, __FUNCTION__, 6170, GF_LOG_ERROR, "Volume ids of volume %s - %s"
" and %s - are different. Possibly a split brain among " "peers."
, volinfo->volname, volid_str, uuid_utoa (volinfo->volume_id
)); } while (0)
;
6171 ret = -1;
6172 goto out;
6173 }
6174
6175out:
6176 return ret;
6177}
6178
6179int
6180glusterd_defrag_volume_status_update (glusterd_volinfo_t *volinfo,
6181 dict_t *rsp_dict)
6182{
6183 int ret = 0;
6184 uint64_t files = 0;
6185 uint64_t size = 0;
6186 uint64_t lookup = 0;
6187 gf_defrag_status_t status = GF_DEFRAG_STATUS_NOT_STARTED;
6188 uint64_t failures = 0;
6189 xlator_t *this = NULL((void*)0);
6190 double run_time = 0;
6191
6192 this = THIS(*__glusterfs_this_location());
6193
6194 ret = dict_get_uint64 (rsp_dict, "files", &files);
6195 if (ret)
6196 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("failed to get file count"); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6197, GF_LOG_TRACE, "failed to get file count"); } while (0
)
6197 "failed to get file count")do { do { if (0) printf ("failed to get file count"); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6197, GF_LOG_TRACE, "failed to get file count"); } while (0
)
;
6198
6199 ret = dict_get_uint64 (rsp_dict, "size", &size);
6200 if (ret)
6201 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("failed to get size of xfer"); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6202, GF_LOG_TRACE, "failed to get size of xfer"); } while (
0)
6202 "failed to get size of xfer")do { do { if (0) printf ("failed to get size of xfer"); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6202, GF_LOG_TRACE, "failed to get size of xfer"); } while (
0)
;
6203
6204 ret = dict_get_uint64 (rsp_dict, "lookups", &lookup);
6205 if (ret)
6206 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("failed to get lookedup file count")
; } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6207, GF_LOG_TRACE, "failed to get lookedup file count"); }
while (0)
6207 "failed to get lookedup file count")do { do { if (0) printf ("failed to get lookedup file count")
; } while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6207, GF_LOG_TRACE, "failed to get lookedup file count"); }
while (0)
;
6208
6209 ret = dict_get_int32 (rsp_dict, "status", (int32_t *)&status);
6210 if (ret)
6211 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("failed to get status"); } while (0)
; _gf_log (this->name, "glusterd-utils.c", __FUNCTION__, 6212
, GF_LOG_TRACE, "failed to get status"); } while (0)
6212 "failed to get status")do { do { if (0) printf ("failed to get status"); } while (0)
; _gf_log (this->name, "glusterd-utils.c", __FUNCTION__, 6212
, GF_LOG_TRACE, "failed to get status"); } while (0)
;
6213
6214 ret = dict_get_uint64 (rsp_dict, "failures", &failures);
6215 if (ret)
6216 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("failed to get failure count"); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6217, GF_LOG_TRACE, "failed to get failure count"); } while
(0)
6217 "failed to get failure count")do { do { if (0) printf ("failed to get failure count"); } while
(0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6217, GF_LOG_TRACE, "failed to get failure count"); } while
(0)
;
6218
6219 ret = dict_get_double (rsp_dict, "run-time", &run_time);
6220 if (ret)
6221 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("failed to get run-time"); } while (
0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__,
6222, GF_LOG_TRACE, "failed to get run-time"); } while (0)
6222 "failed to get run-time")do { do { if (0) printf ("failed to get run-time"); } while (
0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__,
6222, GF_LOG_TRACE, "failed to get run-time"); } while (0)
;
6223
6224 if (files)
6225 volinfo->rebal.rebalance_files = files;
6226 if (size)
6227 volinfo->rebal.rebalance_data = size;
6228 if (lookup)
6229 volinfo->rebal.lookedup_files = lookup;
6230 if (status)
6231 volinfo->rebal.defrag_status = status;
6232 if (failures)
6233 volinfo->rebal.rebalance_failures = failures;
6234 if (run_time)
6235 volinfo->rebal.rebalance_time = run_time;
6236
6237 return ret;
6238}
6239
6240int
6241glusterd_check_files_identical (char *filename1, char *filename2,
6242 gf_boolean_t *identical)
6243{
6244 int ret = -1;
6245 struct stat buf1 = {0,};
6246 struct stat buf2 = {0,};
6247 uint32_t cksum1 = 0;
6248 uint32_t cksum2 = 0;
6249 xlator_t *this = NULL((void*)0);
6250
6251 GF_ASSERT (filename1)do { if (!(filename1)) { do { do { if (0) printf ("Assertion failed: "
"filename1"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6251, GF_LOG_ERROR, "Assertion failed: " "filename1"
); } while (0); } } while (0)
;
6252 GF_ASSERT (filename2)do { if (!(filename2)) { do { do { if (0) printf ("Assertion failed: "
"filename2"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6252, GF_LOG_ERROR, "Assertion failed: " "filename2"
); } while (0); } } while (0)
;
6253 GF_ASSERT (identical)do { if (!(identical)) { do { do { if (0) printf ("Assertion failed: "
"identical"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6253, GF_LOG_ERROR, "Assertion failed: " "identical"
); } while (0); } } while (0)
;
6254
6255 this = THIS(*__glusterfs_this_location());
6256
6257 ret = stat (filename1, &buf1);
6258
6259 if (ret) {
6260 gf_log (this->name, GF_LOG_ERROR, "stat on file: %s failed "do { do { if (0) printf ("stat on file: %s failed " "(%s)", filename1
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 6261, GF_LOG_ERROR
, "stat on file: %s failed " "(%s)", filename1, strerror ((*__errno_location
()))); } while (0)
6261 "(%s)", filename1, strerror (errno))do { do { if (0) printf ("stat on file: %s failed " "(%s)", filename1
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 6261, GF_LOG_ERROR
, "stat on file: %s failed " "(%s)", filename1, strerror ((*__errno_location
()))); } while (0)
;
6262 goto out;
6263 }
6264
6265 ret = stat (filename2, &buf2);
6266
6267 if (ret) {
6268 gf_log (this->name, GF_LOG_ERROR, "stat on file: %s failed "do { do { if (0) printf ("stat on file: %s failed " "(%s)", filename2
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 6269, GF_LOG_ERROR
, "stat on file: %s failed " "(%s)", filename2, strerror ((*__errno_location
()))); } while (0)
6269 "(%s)", filename2, strerror (errno))do { do { if (0) printf ("stat on file: %s failed " "(%s)", filename2
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-utils.c", __FUNCTION__, 6269, GF_LOG_ERROR
, "stat on file: %s failed " "(%s)", filename2, strerror ((*__errno_location
()))); } while (0)
;
6270 goto out;
6271 }
6272
6273 if (buf1.st_size != buf2.st_size) {
6274 *identical = _gf_false;
6275 goto out;
6276 }
6277
6278 ret = get_checksum_for_path (filename1, &cksum1);
6279 if (ret)
6280 goto out;
6281
6282
6283 ret = get_checksum_for_path (filename2, &cksum2);
6284 if (ret)
6285 goto out;
6286
6287 if (cksum1 != cksum2)
6288 *identical = _gf_false;
6289 else
6290 *identical = _gf_true;
6291
6292out:
6293 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-utils.c", __FUNCTION__,
6293, GF_LOG_DEBUG, "Returning with %d", ret); } while (0)
;
6294 return ret;
6295}
6296
6297int
6298glusterd_volset_help (dict_t *dict, char **op_errstr)
6299{
6300 int ret = -1;
6301 gf_boolean_t xml_out = _gf_false;
6302 xlator_t *this = NULL((void*)0);
6303
6304 this = THIS(*__glusterfs_this_location());
6305
6306 if (!dict) {
6307 if (!(dict = glusterd_op_get_ctx ())) {
6308 ret = 0;
6309 goto out;
6310 }
6311 }
6312
6313 if (dict_get (dict, "help" )) {
6314 xml_out = _gf_false;
6315
6316 } else if (dict_get (dict, "help-xml" )) {
6317 xml_out = _gf_true;
6318#if (HAVE_LIB_XML1)
6319 ret = 0;
6320#else
6321 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("libxml not present in the system");
} while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6322, GF_LOG_ERROR, "libxml not present in the system"); } while
(0)
6322 "libxml not present in the system")do { do { if (0) printf ("libxml not present in the system");
} while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6322, GF_LOG_ERROR, "libxml not present in the system"); } while
(0)
;
6323 if (op_errstr)
6324 *op_errstr = gf_strdup ("Error: xml libraries not "
6325 "present to produce "
6326 "xml-output");
6327 goto out;
6328#endif
6329
6330 } else {
6331 goto out;
6332 }
6333
6334 ret = glusterd_get_volopt_content (dict, xml_out);
6335 if (ret && op_errstr)
6336 *op_errstr = gf_strdup ("Failed to get volume options help");
6337 out:
6338
6339 gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log
("glusterd", "glusterd-utils.c", __FUNCTION__, 6339, GF_LOG_DEBUG
, "Returning %d", ret); } while (0)
;
6340 return ret;
6341}
6342
6343int
6344glusterd_to_cli (rpcsvc_request_t *req, gf_cli_rsp *arg, struct iovec *payload,
6345 int payloadcount, struct iobref *iobref, xdrproc_t xdrproc,
6346 dict_t *dict)
6347{
6348 int ret = -1;
6349 char *cmd = NULL((void*)0);
6350 int op_ret = 0;
6351 char *op_errstr = NULL((void*)0);
6352 int op_errno = 0;
6353 xlator_t *this = NULL((void*)0);
6354
6355 this = THIS(*__glusterfs_this_location());
6356 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6356, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
6357
6358 op_ret = arg->op_ret;
6359 op_errstr = arg->op_errstr;
6360 op_errno = arg->op_errno;
6361
6362 ret = dict_get_str (dict, "cmd-str", &cmd);
6363 if (ret)
6364 gf_log (this->name, GF_LOG_ERROR, "Failed to get command "do { do { if (0) printf ("Failed to get command " "string"); }
while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6365, GF_LOG_ERROR, "Failed to get command " "string"); } while
(0)
6365 "string")do { do { if (0) printf ("Failed to get command " "string"); }
while (0); _gf_log (this->name, "glusterd-utils.c", __FUNCTION__
, 6365, GF_LOG_ERROR, "Failed to get command " "string"); } while
(0)
;
6366
6367 if (cmd) {
6368 if (op_ret)
6369 gf_cmd_log ("", "%s : FAILED %s %s", cmd,
6370 (op_errstr)? ":" : " ",
6371 (op_errstr)? op_errstr : " ");
6372 else
6373 gf_cmd_log ("", "%s : SUCCESS", cmd);
6374 }
6375
6376 glusterd_submit_reply (req, arg, payload, payloadcount, iobref,
6377 (xdrproc_t) xdrproc);
6378 if (dict)
6379 dict_unref (dict);
6380
6381 return ret;
6382}
6383
6384static int32_t
6385glusterd_append_gsync_status (dict_t *dst, dict_t *src)
6386{
6387 int ret = 0;
6388 char *stop_msg = NULL((void*)0);
6389
6390 ret = dict_get_str (src, "gsync-status", &stop_msg);
6391 if (ret) {
6392 ret = 0;
6393 goto out;
6394 }
6395
6396 ret = dict_set_dynstr (dst, "gsync-status", gf_strdup (stop_msg));
6397 if (ret) {
6398 gf_log ("glusterd", GF_LOG_WARNING, "Unable to set the stop"do { do { if (0) printf ("Unable to set the stop" "message in the ctx dictionary"
); } while (0); _gf_log ("glusterd", "glusterd-utils.c", __FUNCTION__
, 6399, GF_LOG_WARNING, "Unable to set the stop" "message in the ctx dictionary"
); } while (0)
6399 "message in the ctx dictionary")do { do { if (0) printf ("Unable to set the stop" "message in the ctx dictionary"
); } while (0); _gf_log ("glusterd", "glusterd-utils.c", __FUNCTION__
, 6399, GF_LOG_WARNING, "Unable to set the stop" "message in the ctx dictionary"
); } while (0)
;
6400 goto out;
6401 }
6402
6403 ret = 0;
6404 out:
6405 gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log
("glusterd", "glusterd-utils.c", __FUNCTION__, 6405, GF_LOG_DEBUG
, "Returning %d", ret); } while (0)
;
6406 return ret;
6407
6408}
6409
6410static int32_t
6411glusterd_append_status_dicts (dict_t *dst, dict_t *src)
6412{
6413 int dst_count = 0;
6414 int src_count = 0;
6415 int i = 0;
6416 int ret = 0;
6417 char mst[PATH_MAX4096] = {0,};
6418 char slv[PATH_MAX4096] = {0, };
6419 char sts[PATH_MAX4096] = {0, };
6420 char nds[PATH_MAX4096] = {0, };
6421 char *mst_val = NULL((void*)0);
6422 char *slv_val = NULL((void*)0);
6423 char *sts_val = NULL((void*)0);
6424 char *nds_val = NULL((void*)0);
6425
6426 GF_ASSERT (dst)do { if (!(dst)) { do { do { if (0) printf ("Assertion failed: "
"dst"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6426, GF_LOG_ERROR, "Assertion failed: " "dst"
); } while (0); } } while (0)
;
6427
6428 if (src == NULL((void*)0))
6429 goto out;
6430
6431 ret = dict_get_int32 (dst, "gsync-count", &dst_count);
6432 if (ret)
6433 dst_count = 0;
6434
6435 ret = dict_get_int32 (src, "gsync-count", &src_count);
6436 if (ret || !src_count) {
6437 gf_log ("", GF_LOG_DEBUG, "Source brick empty")do { do { if (0) printf ("Source brick empty"); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 6437, GF_LOG_DEBUG, "Source brick empty"
); } while (0)
;
6438 ret = 0;
6439 goto out;
6440 }
6441
6442 for (i = 1; i <= src_count; i++) {
6443 snprintf (nds, sizeof(nds), "node%d", i);
6444 snprintf (mst, sizeof(mst), "master%d", i);
6445 snprintf (slv, sizeof(slv), "slave%d", i);
6446 snprintf (sts, sizeof(sts), "status%d", i);
6447
6448 ret = dict_get_str (src, nds, &nds_val);
6449 if (ret)
6450 goto out;
6451
6452 ret = dict_get_str (src, mst, &mst_val);
6453 if (ret)
6454 goto out;
6455
6456 ret = dict_get_str (src, slv, &slv_val);
6457 if (ret)
6458 goto out;
6459
6460 ret = dict_get_str (src, sts, &sts_val);
6461 if (ret)
6462 goto out;
6463
6464 snprintf (nds, sizeof(nds), "node%d", i+dst_count);
6465 snprintf (mst, sizeof(mst), "master%d", i+dst_count);
6466 snprintf (slv, sizeof(slv), "slave%d", i+dst_count);
6467 snprintf (sts, sizeof(sts), "status%d", i+dst_count);
6468
6469 ret = dict_set_dynstr (dst, nds, gf_strdup (nds_val));
6470 if (ret)
6471 goto out;
6472
6473 ret = dict_set_dynstr (dst, mst, gf_strdup (mst_val));
6474 if (ret)
6475 goto out;
6476
6477 ret = dict_set_dynstr (dst, slv, gf_strdup (slv_val));
6478 if (ret)
6479 goto out;
6480
6481 ret = dict_set_dynstr (dst, sts, gf_strdup (sts_val));
6482 if (ret)
6483 goto out;
6484
6485 }
6486
6487 ret = dict_set_int32 (dst, "gsync-count", dst_count+src_count);
6488
6489 out:
6490 gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 6490, GF_LOG_DEBUG, "Returning %d"
, ret); } while (0)
;
6491 return ret;
6492
6493}
6494
6495int32_t
6496glusterd_gsync_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict, char *op_errstr)
6497{
6498 dict_t *ctx = NULL((void*)0);
6499 int ret = 0;
6500
6501 if (aggr) {
6502 ctx = aggr;
6503
6504 } else {
6505 ctx = glusterd_op_get_ctx ();
6506 if (!ctx) {
6507 gf_log ("", GF_LOG_ERROR,do { do { if (0) printf ("Operation Context is not present");
} while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 6508
, GF_LOG_ERROR, "Operation Context is not present"); } while (
0)
6508 "Operation Context is not present")do { do { if (0) printf ("Operation Context is not present");
} while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 6508
, GF_LOG_ERROR, "Operation Context is not present"); } while (
0)
;
6509 GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: "
"0"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6509, GF_LOG_ERROR, "Assertion failed: " "0")
; } while (0); } } while (0)
;
6510 }
6511 }
6512
6513 if (rsp_dict) {
6514 ret = glusterd_append_status_dicts (ctx, rsp_dict);
6515 if (ret)
6516 goto out;
6517
6518 ret = glusterd_append_gsync_status (ctx, rsp_dict);
6519 if (ret)
6520 goto out;
6521 }
6522 if ((op_errstr) && (strcmp ("", op_errstr))) {
6523 ret = dict_set_dynstr (ctx, "errstr", gf_strdup(op_errstr));
6524 if (ret)
6525 goto out;
6526 }
6527
6528 ret = 0;
6529 out:
6530 gf_log ("", GF_LOG_DEBUG, "Returning %d ", ret)do { do { if (0) printf ("Returning %d ", ret); } while (0); _gf_log
("", "glusterd-utils.c", __FUNCTION__, 6530, GF_LOG_DEBUG, "Returning %d "
, ret); } while (0)
;
6531 return ret;
6532}
6533
6534int32_t
6535glusterd_rb_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict)
6536{
6537 int32_t src_port = 0;
6538 int32_t dst_port = 0;
6539 int ret = 0;
6540 dict_t *ctx = NULL((void*)0);
6541
6542
6543 if (aggr) {
6544 ctx = aggr;
6545
6546 } else {
6547 ctx = glusterd_op_get_ctx ();
6548 if (!ctx) {
6549 gf_log ("", GF_LOG_ERROR,do { do { if (0) printf ("Operation Context is not present");
} while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 6550
, GF_LOG_ERROR, "Operation Context is not present"); } while (
0)
6550 "Operation Context is not present")do { do { if (0) printf ("Operation Context is not present");
} while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 6550
, GF_LOG_ERROR, "Operation Context is not present"); } while (
0)
;
6551 GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: "
"0"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6551, GF_LOG_ERROR, "Assertion failed: " "0")
; } while (0); } } while (0)
;
6552 }
6553 }
6554
6555 if (rsp_dict) {
6556 ret = dict_get_int32 (rsp_dict, "src-brick-port", &src_port);
6557 if (ret == 0) {
6558 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("src-brick-port=%d found", src_port)
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
6559, GF_LOG_DEBUG, "src-brick-port=%d found", src_port); } while
(0)
6559 "src-brick-port=%d found", src_port)do { do { if (0) printf ("src-brick-port=%d found", src_port)
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
6559, GF_LOG_DEBUG, "src-brick-port=%d found", src_port); } while
(0)
;
6560 }
6561
6562 ret = dict_get_int32 (rsp_dict, "dst-brick-port", &dst_port);
6563 if (ret == 0) {
6564 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("dst-brick-port=%d found", dst_port)
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
6565, GF_LOG_DEBUG, "dst-brick-port=%d found", dst_port); } while
(0)
6565 "dst-brick-port=%d found", dst_port)do { do { if (0) printf ("dst-brick-port=%d found", dst_port)
; } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__,
6565, GF_LOG_DEBUG, "dst-brick-port=%d found", dst_port); } while
(0)
;
6566 }
6567
6568 }
6569
6570 if (src_port) {
6571 ret = dict_set_int32 (ctx, "src-brick-port",
6572 src_port);
6573 if (ret) {
6574 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Could not set src-brick"); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 6575, GF_LOG_DEBUG
, "Could not set src-brick"); } while (0)
6575 "Could not set src-brick")do { do { if (0) printf ("Could not set src-brick"); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 6575, GF_LOG_DEBUG
, "Could not set src-brick"); } while (0)
;
6576 goto out;
6577 }
6578 }
6579
6580 if (dst_port) {
6581 ret = dict_set_int32 (ctx, "dst-brick-port",
6582 dst_port);
6583 if (ret) {
6584 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Could not set dst-brick"); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 6585, GF_LOG_DEBUG
, "Could not set dst-brick"); } while (0)
6585 "Could not set dst-brick")do { do { if (0) printf ("Could not set dst-brick"); } while (
0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 6585, GF_LOG_DEBUG
, "Could not set dst-brick"); } while (0)
;
6586 goto out;
6587 }
6588
6589 }
6590
6591out:
6592 return ret;
6593
6594}
6595
6596int32_t
6597glusterd_sync_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict)
6598{
6599 int ret = 0;
6600
6601 GF_ASSERT (rsp_dict)do { if (!(rsp_dict)) { do { do { if (0) printf ("Assertion failed: "
"rsp_dict"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6601, GF_LOG_ERROR, "Assertion failed: " "rsp_dict"
); } while (0); } } while (0)
;
6602
6603 if (!rsp_dict) {
6604 goto out;
6605 }
6606
6607 ret = glusterd_import_friend_volumes (rsp_dict);
6608out:
6609 return ret;
6610
6611}
6612
6613static int
6614_profile_volume_add_friend_rsp (dict_t *this, char *key, data_t *value,
6615 void *data)
6616{
6617 char new_key[256] = {0};
6618 glusterd_pr_brick_rsp_conv_t *rsp_ctx = NULL((void*)0);
6619 data_t *new_value = NULL((void*)0);
6620 int brick_count = 0;
6621 char brick_key[256];
6622
6623 if (strcmp (key, "count") == 0)
6624 return 0;
6625 sscanf (key, "%d%s", &brick_count, brick_key);
6626 rsp_ctx = data;
6627 new_value = data_copy (value);
6628 GF_ASSERT (new_value)do { if (!(new_value)) { do { do { if (0) printf ("Assertion failed: "
"new_value"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6628, GF_LOG_ERROR, "Assertion failed: " "new_value"
); } while (0); } } while (0)
;
6629 snprintf (new_key, sizeof (new_key), "%d%s",
6630 rsp_ctx->count + brick_count, brick_key);
6631 dict_set (rsp_ctx->dict, new_key, new_value);
6632 return 0;
6633}
6634
6635int
6636glusterd_profile_volume_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict)
6637{
6638 int ret = 0;
6639 glusterd_pr_brick_rsp_conv_t rsp_ctx = {0};
6640 int32_t brick_count = 0;
6641 int32_t count = 0;
6642 dict_t *ctx_dict = NULL((void*)0);
6643 glusterd_op_t op = GD_OP_NONE;
6644
6645 GF_ASSERT (rsp_dict)do { if (!(rsp_dict)) { do { do { if (0) printf ("Assertion failed: "
"rsp_dict"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6645, GF_LOG_ERROR, "Assertion failed: " "rsp_dict"
); } while (0); } } while (0)
;
6646
6647 ret = dict_get_int32 (rsp_dict, "count", &brick_count);
6648 if (ret) {
6649 ret = 0; //no bricks in the rsp
6650 goto out;
6651 }
6652
6653 op = glusterd_op_get_op ();
6654 GF_ASSERT (GD_OP_PROFILE_VOLUME == op)do { if (!(GD_OP_PROFILE_VOLUME == op)) { do { do { if (0) printf
("Assertion failed: " "GD_OP_PROFILE_VOLUME == op"); } while
(0); _gf_log_callingfn ("", "glusterd-utils.c", __FUNCTION__
, 6654, GF_LOG_ERROR, "Assertion failed: " "GD_OP_PROFILE_VOLUME == op"
); } while (0); } } while (0)
;
6655 if (aggr) {
6656 ctx_dict = aggr;
6657
6658 } else {
6659 ctx_dict = glusterd_op_get_ctx ();
6660 }
6661
6662 ret = dict_get_int32 (ctx_dict, "count", &count);
6663 rsp_ctx.count = count;
6664 rsp_ctx.dict = ctx_dict;
6665 dict_foreach (rsp_dict, _profile_volume_add_friend_rsp, &rsp_ctx);
6666 dict_del (ctx_dict, "count");
6667 ret = dict_set_int32 (ctx_dict, "count", count + brick_count);
6668out:
6669 return ret;
6670}
6671
6672static int
6673glusterd_volume_status_add_peer_rsp (dict_t *this, char *key, data_t *value,
6674 void *data)
6675{
6676 glusterd_status_rsp_conv_t *rsp_ctx = NULL((void*)0);
6677 data_t *new_value = NULL((void*)0);
6678 char brick_key[1024] = {0,};
6679 char new_key[1024] = {0,};
6680 int32_t index = 0;
6681 int32_t ret = 0;
6682
6683 /* Skip the following keys, they are already present in the ctx_dict */
6684 if (!strcmp (key, "count") || !strcmp (key, "cmd") ||
6685 !strcmp (key, "brick-index-max") || !strcmp (key, "other-count"))
6686 return 0;
6687
6688 rsp_ctx = data;
6689 new_value = data_copy (value);
6690 GF_ASSERT (new_value)do { if (!(new_value)) { do { do { if (0) printf ("Assertion failed: "
"new_value"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6690, GF_LOG_ERROR, "Assertion failed: " "new_value"
); } while (0); } } while (0)
;
6691
6692 sscanf (key, "brick%d.%s", &index, brick_key);
6693
6694 if (index > rsp_ctx->brick_index_max) {
6695 snprintf (new_key, sizeof (new_key), "brick%d.%s",
6696 index + rsp_ctx->other_count, brick_key);
6697 } else {
6698 strncpy (new_key, key, sizeof (new_key));
6699 new_key[sizeof (new_key) - 1] = 0;
6700 }
6701
6702 ret = dict_set (rsp_ctx->dict, new_key, new_value);
6703 if (ret)
6704 gf_log ("", GF_LOG_ERROR, "Unable to set key: %s in dict",do { do { if (0) printf ("Unable to set key: %s in dict", key
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 6705, GF_LOG_ERROR, "Unable to set key: %s in dict", key); }
while (0)
6705 key)do { do { if (0) printf ("Unable to set key: %s in dict", key
); } while (0); _gf_log ("", "glusterd-utils.c", __FUNCTION__
, 6705, GF_LOG_ERROR, "Unable to set key: %s in dict", key); }
while (0)
;
6706
6707 return 0;
6708}
6709
6710int
6711glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict)
6712{
6713 int ret = 0;
6714 glusterd_status_rsp_conv_t rsp_ctx = {0};
6715 int32_t cmd = GF_CLI_STATUS_NONE;
6716 int32_t node_count = 0;
6717 int32_t other_count = 0;
6718 int32_t brick_index_max = -1;
6719 int32_t rsp_node_count = 0;
6720 int32_t rsp_other_count = 0;
6721 int vol_count = -1;
6722 int i = 0;
6723 dict_t *ctx_dict = NULL((void*)0);
6724 char key[PATH_MAX4096] = {0,};
6725 char *volname = NULL((void*)0);
6726
6727 GF_ASSERT (rsp_dict)do { if (!(rsp_dict)) { do { do { if (0) printf ("Assertion failed: "
"rsp_dict"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6727, GF_LOG_ERROR, "Assertion failed: " "rsp_dict"
); } while (0); } } while (0)
;
6728
6729 if (aggr) {
6730 ctx_dict = aggr;
6731
6732 } else {
6733 ctx_dict = glusterd_op_get_ctx (GD_OP_STATUS_VOLUME);
6734
6735 }
6736
6737 ret = dict_get_int32 (ctx_dict, "cmd", &cmd);
6738 if (ret)
6739 goto out;
6740
6741 if (cmd & GF_CLI_STATUS_ALL && is_origin_glusterd ()) {
6742 ret = dict_get_int32 (rsp_dict, "vol_count", &vol_count);
6743 if (ret == 0) {
6744 ret = dict_set_int32 (ctx_dict, "vol_count",
6745 vol_count);
6746 if (ret)
6747 goto out;
6748
6749 for (i = 0; i < vol_count; i++) {
6750 memset (key, 0, sizeof (key));
6751 snprintf (key, sizeof (key), "vol%d", i);
6752 ret = dict_get_str (rsp_dict, key, &volname);
6753 if (ret)
6754 goto out;
6755
6756 ret = dict_set_str (ctx_dict, key, volname);
6757 if (ret)
6758 goto out;
6759 }
6760 }
6761 }
6762
6763 ret = dict_get_int32 (rsp_dict, "count", &rsp_node_count);
6764 if (ret) {
6765 ret = 0; //no bricks in the rsp
6766 goto out;
6767 }
6768
6769 ret = dict_get_int32 (rsp_dict, "other-count", &rsp_other_count);
6770 if (ret) {
6771 gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to get other count from rsp_dict"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 6772, GF_LOG_ERROR, "Failed to get other count from rsp_dict"
); } while (0)
6772 "Failed to get other count from rsp_dict")do { do { if (0) printf ("Failed to get other count from rsp_dict"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 6772, GF_LOG_ERROR, "Failed to get other count from rsp_dict"
); } while (0)
;
6773 goto out;
6774 }
6775
6776 ret = dict_get_int32 (ctx_dict, "count", &node_count);
6777 ret = dict_get_int32 (ctx_dict, "other-count", &other_count);
6778 if (!dict_get (ctx_dict, "brick-index-max")) {
6779 ret = dict_get_int32 (rsp_dict, "brick-index-max", &brick_index_max);
6780 if (ret)
6781 goto out;
6782 ret = dict_set_int32 (ctx_dict, "brick-index-max", brick_index_max);
6783 if (ret)
6784 goto out;
6785
6786 } else {
6787 ret = dict_get_int32 (ctx_dict, "brick-index-max", &brick_index_max);
6788 }
6789
6790 rsp_ctx.count = node_count;
6791 rsp_ctx.brick_index_max = brick_index_max;
6792 rsp_ctx.other_count = other_count;
6793 rsp_ctx.dict = ctx_dict;
6794
6795 dict_foreach (rsp_dict, glusterd_volume_status_add_peer_rsp, &rsp_ctx);
6796
6797 ret = dict_set_int32 (ctx_dict, "count", node_count + rsp_node_count);
6798 if (ret) {
6799 gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to update node count"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 6800, GF_LOG_ERROR, "Failed to update node count"
); } while (0)
6800 "Failed to update node count")do { do { if (0) printf ("Failed to update node count"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 6800, GF_LOG_ERROR, "Failed to update node count"
); } while (0)
;
6801 goto out;
6802 }
6803
6804 ret = dict_set_int32 (ctx_dict, "other-count",
6805 (other_count + rsp_other_count));
6806 if (ret)
6807 gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to update other-count"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 6808, GF_LOG_ERROR, "Failed to update other-count"
); } while (0)
6808 "Failed to update other-count")do { do { if (0) printf ("Failed to update other-count"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 6808, GF_LOG_ERROR, "Failed to update other-count"
); } while (0)
;
6809out:
6810 return ret;
6811}
6812
6813int
6814glusterd_volume_rebalance_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict)
6815{
6816 char key[256] = {0,};
6817 char *node_uuid = NULL((void*)0);
6818 char *node_uuid_str = NULL((void*)0);
6819 char *volname = NULL((void*)0);
6820 dict_t *ctx_dict = NULL((void*)0);
6821 double elapsed_time = 0;
6822 glusterd_conf_t *conf = NULL((void*)0);
6823 glusterd_op_t op = GD_OP_NONE;
6824 glusterd_peerinfo_t *peerinfo = NULL((void*)0);
6825 glusterd_volinfo_t *volinfo = NULL((void*)0);
6826 int ret = 0;
6827 int32_t index = 0;
6828 int32_t count = 0;
6829 int32_t current_index = 2;
6830 int32_t value32 = 0;
6831 uint64_t value = 0;
6832
6833 GF_ASSERT (rsp_dict)do { if (!(rsp_dict)) { do { do { if (0) printf ("Assertion failed: "
"rsp_dict"); } while (0); _gf_log_callingfn ("", "glusterd-utils.c"
, __FUNCTION__, 6833, GF_LOG_ERROR, "Assertion failed: " "rsp_dict"
); } while (0); } } while (0)
;
6834 conf = THIS(*__glusterfs_this_location())->private;
6835
6836 op = glusterd_op_get_op ();
6837 GF_ASSERT ((GD_OP_REBALANCE == op) ||do { if (!((GD_OP_REBALANCE == op) || (GD_OP_DEFRAG_BRICK_VOLUME
== op))) { do { do { if (0) printf ("Assertion failed: " "(GD_OP_REBALANCE == op) || (GD_OP_DEFRAG_BRICK_VOLUME == op)"
); } while (0); _gf_log_callingfn ("", "glusterd-utils.c", __FUNCTION__
, 6838, GF_LOG_ERROR, "Assertion failed: " "(GD_OP_REBALANCE == op) || (GD_OP_DEFRAG_BRICK_VOLUME == op)"
); } while (0); } } while (0)
6838 (GD_OP_DEFRAG_BRICK_VOLUME == op))do { if (!((GD_OP_REBALANCE == op) || (GD_OP_DEFRAG_BRICK_VOLUME
== op))) { do { do { if (0) printf ("Assertion failed: " "(GD_OP_REBALANCE == op) || (GD_OP_DEFRAG_BRICK_VOLUME == op)"
); } while (0); _gf_log_callingfn ("", "glusterd-utils.c", __FUNCTION__
, 6838, GF_LOG_ERROR, "Assertion failed: " "(GD_OP_REBALANCE == op) || (GD_OP_DEFRAG_BRICK_VOLUME == op)"
); } while (0); } } while (0)
;
6839
6840 if (aggr) {
6841 ctx_dict = aggr;
6842
6843 } else {
6844 ctx_dict = glusterd_op_get_ctx (op);
6845
6846 }
6847
6848 if (!ctx_dict)
6849 goto out;
6850
6851 ret = dict_get_str (ctx_dict, "volname", &volname);
6852 if (ret) {
6853 gf_log ("", GF_LOG_ERROR, "Unable to get volume name")do { do { if (0) printf ("Unable to get volume name"); } while
(0); _gf_log ("", "glusterd-utils.c", __FUNCTION__, 6853, GF_LOG_ERROR
, "Unable to get volume name"); } while (0)
;
6854 goto out;
6855 }
6856
6857 ret = glusterd_volinfo_find (volname, &volinfo);
6858
6859 if (ret)
6860 goto out;
6861
6862 ret = dict_get_int32 (rsp_dict, "count", &index);
6863 if (ret)
6864 gf_log ("", GF_LOG_ERROR, "failed to get index")do { do { if (0) printf ("failed to get index"); } while (0);
_gf_log ("", "glusterd-utils.c", __FUNCTION__, 6864, GF_LOG_ERROR
, "failed to get index"); } while (0)
;
6865
6866 memset (key, 0, 256);
6867 snprintf (key, 256, "node-uuid-%d", index);
6868 ret = dict_get_str (rsp_dict, key, &node_uuid);
6869 if (!ret) {
6870 node_uuid_str = gf_strdup (node_uuid);
6871
6872 /* Finding the index of the node-uuid in the peer-list */
6873 list_for_each_entry (peerinfo, &conf->peers, uuid_list)for (peerinfo = ((typeof(*peerinfo) *)((char *)((&conf->
peers)->next)-(unsigned long)(&((typeof(*peerinfo) *)0
)->uuid_list))); &peerinfo->uuid_list != (&conf
->peers); peerinfo = ((typeof(*peerinfo) *)((char *)(peerinfo
->uuid_list.next)-(unsigned long)(&((typeof(*peerinfo)
*)0)->uuid_list))))
{
6874 if (!strcmp(peerinfo->uuid_str, node_uuid_str)){
6875 break;
6876 }
6877 current_index++;
6878 }
6879
6880 /* Setting the largest index value as the total count. */
6881 ret = dict_get_int32 (ctx_dict, "count", &count);
6882 if (count < current_index) {
6883 ret = dict_set_int32 (ctx_dict, "count", current_index);
6884 if (ret)
6885 gf_log ("", GF_LOG_ERROR, "Failed to set count")do { do { if (0) printf ("Failed to set count"); } while (0);
_gf_log ("", "glusterd-utils.c", __FUNCTION__, 6885, GF_LOG_ERROR
, "Failed to set count"); } while (0)
;
6886 }
6887
6888 /* Setting the same index for the node, as is in the peerlist.*/
6889 memset (key, 0, 256);
6890 snprintf (key, 256, "node-uuid-%d", current_index);
6891 ret = dict_set_dynstr (ctx_dict, key, node_uuid_str);
6892 if (ret) {
6893 gf_log (THIS->name, GF_LOG_DEBUG,do { do { if (0) printf ("failed to set node-uuid"); } while (
0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 6894, GF_LOG_DEBUG, "failed to set node-uuid"
); } while (0)
6894 "failed to set node-uuid")do { do { if (0) printf ("failed to set node-uuid"); } while (
0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 6894, GF_LOG_DEBUG, "failed to set node-uuid"
); } while (0)
;
6895 }
6896 }
6897
6898 snprintf (key, 256, "files-%d", index);
6899 ret = dict_get_uint64 (rsp_dict, key, &value);
6900 if (!ret) {
6901 memset (key, 0, 256);
6902 snprintf (key, 256, "files-%d", current_index);
6903 ret = dict_set_uint64 (ctx_dict, key, value);
6904 if (ret) {
6905 gf_log (THIS->name, GF_LOG_DEBUG,do { do { if (0) printf ("failed to set the file count"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 6906, GF_LOG_DEBUG, "failed to set the file count"
); } while (0)
6906 "failed to set the file count")do { do { if (0) printf ("failed to set the file count"); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-utils.c"
, __FUNCTION__, 6906, GF_LOG_DEBUG, "failed to set the file count"
); } while (0)
;
6907 }
6908 }
6909
6910 memset (key, 0, 256);
6911 snprintf (key, 256, "size-%d", index);
6912 ret = dict_get_uint64 (rsp_dict, key, &value);
6913 if (!ret) {
6914 memset (key, 0, 256);
6915 snprintf (key, 256, "size-%d", current_index);
6916 ret = dict_set_uint64 (ctx_dict, key, value);
6917 if (ret) {
6918 gf_log (THIS->name, GF_LOG_DEBUG,do { do { if (0) printf ("failed to set the size of migration"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 6919, GF_LOG_DEBUG, "failed to set the size of migration"
); } while (0)
6919 "failed to set the size of migration")do { do { if (0) printf ("failed to set the size of migration"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 6919, GF_LOG_DEBUG, "failed to set the size of migration"
); } while (0)
;
6920 }
6921 }
6922
6923 memset (key, 0, 256);
6924 snprintf (key, 256, "lookups-%d", index);
6925 ret = dict_get_uint64 (rsp_dict, key, &value);
6926 if (!ret) {
6927 memset (key, 0, 256);
6928 snprintf (key, 256, "lookups-%d", current_index);
6929 ret = dict_set_uint64 (ctx_dict, key, value);
6930 if (ret) {
6931 gf_log (THIS->name, GF_LOG_DEBUG,do { do { if (0) printf ("failed to set lookuped file count")
; } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 6932, GF_LOG_DEBUG, "failed to set lookuped file count"
); } while (0)
6932 "failed to set lookuped file count")do { do { if (0) printf ("failed to set lookuped file count")
; } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-utils.c", __FUNCTION__, 6932, GF_LOG_DEBUG, "failed to set lookuped file count"
); } while (0)
;
6933 }
6934 }
6935
6936 memset (key, 0, 256);
6937 snprintf (key, 256, "status-%d", index);
6938 ret = dict_get_int32 (rsp_dict, key, &value32);
6939