File: | xlators/mgmt/glusterd/src/glusterd-hooks.c |
Location: | line 264, column 9 |
Description: | Value stored to 'priv' is never read |
1 | /* |
2 | Copyright (c) 2007-2012 Red Hat, Inc. <http://www.redhat.com> |
3 | This file is part of GlusterFS. |
4 | |
5 | This file is licensed to you under your choice of the GNU Lesser |
6 | General Public License, version 3 or any later version (LGPLv3 or |
7 | later), or the GNU General Public License, version 2 (GPLv2), in all |
8 | cases as published by the Free Software Foundation. |
9 | */ |
10 | |
11 | #ifndef _CONFIG_H |
12 | #define _CONFIG_H |
13 | #include "config.h" |
14 | #endif |
15 | |
16 | #include "globals.h" |
17 | #include "glusterfs.h" |
18 | #include "dict.h" |
19 | #include "xlator.h" |
20 | #include "logging.h" |
21 | #include "run.h" |
22 | #include "defaults.h" |
23 | #include "compat.h" |
24 | #include "compat-errno.h" |
25 | #include "glusterd.h" |
26 | #include "glusterd-sm.h" |
27 | #include "glusterd-op-sm.h" |
28 | #include "glusterd-utils.h" |
29 | #include "glusterd-store.h" |
30 | #include "glusterd-hooks.h" |
31 | |
32 | #include <fnmatch.h> |
33 | |
34 | #define EMPTY "" |
35 | char glusterd_hook_dirnames[GD_OP_MAX][256] = |
36 | { |
37 | [GD_OP_NONE] = EMPTY, |
38 | [GD_OP_CREATE_VOLUME] = "create", |
39 | [GD_OP_START_BRICK] = EMPTY, |
40 | [GD_OP_STOP_BRICK] = EMPTY, |
41 | [GD_OP_DELETE_VOLUME] = "delete", |
42 | [GD_OP_START_VOLUME] = "start", |
43 | [GD_OP_STOP_VOLUME] = "stop", |
44 | [GD_OP_DEFRAG_VOLUME] = EMPTY, |
45 | [GD_OP_ADD_BRICK] = "add-brick", |
46 | [GD_OP_REMOVE_BRICK] = "remove-brick", |
47 | [GD_OP_REPLACE_BRICK] = EMPTY, |
48 | [GD_OP_SET_VOLUME] = "set", |
49 | [GD_OP_RESET_VOLUME] = EMPTY, |
50 | [GD_OP_SYNC_VOLUME] = EMPTY, |
51 | [GD_OP_LOG_ROTATE] = EMPTY, |
52 | [GD_OP_GSYNC_SET] = EMPTY, |
53 | [GD_OP_PROFILE_VOLUME] = EMPTY, |
54 | [GD_OP_QUOTA] = EMPTY, |
55 | [GD_OP_STATUS_VOLUME] = EMPTY, |
56 | [GD_OP_REBALANCE] = EMPTY, |
57 | [GD_OP_HEAL_VOLUME] = EMPTY, |
58 | [GD_OP_STATEDUMP_VOLUME] = EMPTY, |
59 | [GD_OP_LIST_VOLUME] = EMPTY, |
60 | [GD_OP_CLEARLOCKS_VOLUME] = EMPTY, |
61 | [GD_OP_DEFRAG_BRICK_VOLUME] = EMPTY, |
62 | }; |
63 | #undef EMPTY |
64 | |
65 | static inline gf_boolean_t |
66 | glusterd_is_hook_enabled (char *script) |
67 | { |
68 | return (script[0] == 'S'); |
69 | } |
70 | |
71 | int |
72 | glusterd_hooks_create_hooks_directory (char *basedir) |
73 | { |
74 | int ret = -1; |
75 | int op = GD_OP_NONE; |
76 | int type = GD_COMMIT_HOOK_NONE; |
77 | char version_dir[PATH_MAX4096] = {0, }; |
78 | char path[PATH_MAX4096] = {0, }; |
79 | char *cmd_subdir = NULL((void*)0); |
80 | char type_subdir[GD_COMMIT_HOOK_MAX][256] = {{0, }, |
81 | "pre", |
82 | "post"}; |
83 | glusterd_conf_t *priv = NULL((void*)0); |
84 | |
85 | priv = THIS(*__glusterfs_this_location())->private; |
86 | |
87 | snprintf (path, sizeof (path), "%s/hooks", basedir); |
88 | ret = mkdir_p (path, 0777, _gf_true); |
89 | if (ret) { |
90 | gf_log (THIS->name, GF_LOG_CRITICAL, "Unable to create %s due"do { do { if (0) printf ("Unable to create %s due" "to %s", path , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-hooks.c", __FUNCTION__ , 91, GF_LOG_CRITICAL, "Unable to create %s due" "to %s", path , strerror ((*__errno_location ()))); } while (0) |
91 | "to %s", path, strerror (errno))do { do { if (0) printf ("Unable to create %s due" "to %s", path , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-hooks.c", __FUNCTION__ , 91, GF_LOG_CRITICAL, "Unable to create %s due" "to %s", path , strerror ((*__errno_location ()))); } while (0); |
92 | goto out; |
93 | } |
94 | |
95 | GLUSTERD_GET_HOOKS_DIR (version_dir, GLUSTERD_HOOK_VER, priv)snprintf (version_dir, 4096, "%s/hooks/%d", priv->workdir, 1);; |
96 | ret = mkdir_p (version_dir, 0777, _gf_true); |
97 | if (ret) { |
98 | gf_log (THIS->name, GF_LOG_CRITICAL, "Unable to create %s due "do { do { if (0) printf ("Unable to create %s due " "to %s", version_dir , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-hooks.c", __FUNCTION__ , 99, GF_LOG_CRITICAL, "Unable to create %s due " "to %s", version_dir , strerror ((*__errno_location ()))); } while (0) |
99 | "to %s", version_dir, strerror (errno))do { do { if (0) printf ("Unable to create %s due " "to %s", version_dir , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-hooks.c", __FUNCTION__ , 99, GF_LOG_CRITICAL, "Unable to create %s due " "to %s", version_dir , strerror ((*__errno_location ()))); } while (0); |
100 | goto out; |
101 | } |
102 | |
103 | for (op = GD_OP_NONE+1; op < GD_OP_MAX; op++) { |
104 | cmd_subdir = glusterd_hooks_get_hooks_cmd_subdir (op); |
105 | if (strlen (cmd_subdir) == 0) |
106 | continue; |
107 | |
108 | snprintf (path, sizeof (path), "%s/%s", version_dir, |
109 | cmd_subdir); |
110 | ret = mkdir_p (path, 0777, _gf_true); |
111 | if (ret) { |
112 | gf_log (THIS->name, GF_LOG_CRITICAL,do { do { if (0) printf ("Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-hooks.c", __FUNCTION__ , 114, GF_LOG_CRITICAL, "Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0) |
113 | "Unable to create %s due to %s",do { do { if (0) printf ("Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-hooks.c", __FUNCTION__ , 114, GF_LOG_CRITICAL, "Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0) |
114 | path, strerror (errno))do { do { if (0) printf ("Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-hooks.c", __FUNCTION__ , 114, GF_LOG_CRITICAL, "Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0); |
115 | goto out; |
116 | } |
117 | |
118 | for (type = GD_COMMIT_HOOK_PRE; type < GD_COMMIT_HOOK_MAX; |
119 | type++) { |
120 | snprintf (path, sizeof (path), "%s/%s/%s", |
121 | version_dir, cmd_subdir, type_subdir[type]); |
122 | ret = mkdir_p (path, 0777, _gf_true); |
123 | if (ret) { |
124 | gf_log (THIS->name, GF_LOG_CRITICAL,do { do { if (0) printf ("Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-hooks.c", __FUNCTION__ , 126, GF_LOG_CRITICAL, "Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0) |
125 | "Unable to create %s due to %s",do { do { if (0) printf ("Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-hooks.c", __FUNCTION__ , 126, GF_LOG_CRITICAL, "Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0) |
126 | path, strerror (errno))do { do { if (0) printf ("Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-hooks.c", __FUNCTION__ , 126, GF_LOG_CRITICAL, "Unable to create %s due to %s", path , strerror ((*__errno_location ()))); } while (0); |
127 | goto out; |
128 | } |
129 | } |
130 | } |
131 | |
132 | ret = 0; |
133 | out: |
134 | return ret; |
135 | } |
136 | |
137 | char* |
138 | glusterd_hooks_get_hooks_cmd_subdir (glusterd_op_t op) |
139 | { |
140 | GF_ASSERT ((op > GD_OP_NONE) && (op < GD_OP_MAX))do { if (!((op > GD_OP_NONE) && (op < GD_OP_MAX ))) { do { do { if (0) printf ("Assertion failed: " "(op > GD_OP_NONE) && (op < GD_OP_MAX)" ); } while (0); _gf_log_callingfn ("", "glusterd-hooks.c", __FUNCTION__ , 140, GF_LOG_ERROR, "Assertion failed: " "(op > GD_OP_NONE) && (op < GD_OP_MAX)" ); } while (0); } } while (0); |
141 | |
142 | return glusterd_hook_dirnames[op]; |
143 | } |
144 | |
145 | int |
146 | glusterd_hooks_set_volume_args (dict_t *dict, runner_t *runner) |
147 | { |
148 | int i = 0; |
149 | int count = 0; |
150 | int ret = -1; |
151 | char query[1024] = {0,}; |
152 | char *key = NULL((void*)0); |
153 | char *value = NULL((void*)0); |
154 | |
155 | ret = dict_get_int32 (dict, "count", &count); |
156 | if (ret) |
157 | goto out; |
158 | |
159 | /* This will not happen unless op_ctx |
160 | * is corrupted*/ |
161 | if (!count) |
162 | goto out; |
163 | |
164 | runner_add_arg (runner, "-o"); |
165 | for (i = 1; (ret == 0); i++) { |
166 | snprintf (query, sizeof (query), "key%d", i); |
167 | ret = dict_get_str (dict, query, &key); |
168 | if (ret) |
169 | continue; |
170 | |
171 | snprintf (query, sizeof (query), "value%d", i); |
172 | ret = dict_get_str (dict, query, &value); |
173 | if (ret) |
174 | continue; |
175 | |
176 | runner_argprintf (runner, "%s=%s", key, value); |
177 | } |
178 | |
179 | ret = 0; |
180 | out: |
181 | return ret; |
182 | } |
183 | |
184 | static int |
185 | glusterd_hooks_add_op_args (runner_t *runner, glusterd_op_t op, |
186 | dict_t *op_ctx, glusterd_commit_hook_type_t type) |
187 | { |
188 | int vol_count = 0; |
189 | gf_boolean_t truth = _gf_false; |
190 | glusterd_volinfo_t *voliter = NULL((void*)0); |
191 | glusterd_conf_t *priv = NULL((void*)0); |
192 | int ret = -1; |
193 | |
194 | priv = THIS(*__glusterfs_this_location())->private; |
195 | list_for_each_entry (voliter, &priv->volumes,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)))) |
196 | 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)))) { |
197 | if (glusterd_is_volume_started (voliter)) |
198 | vol_count++; |
199 | } |
200 | |
201 | ret = 0; |
202 | switch (op) { |
203 | case GD_OP_START_VOLUME: |
204 | if (type == GD_COMMIT_HOOK_PRE && |
205 | vol_count == 0) |
206 | truth = _gf_true; |
207 | |
208 | else if (type == GD_COMMIT_HOOK_POST && |
209 | vol_count == 1) |
210 | truth = _gf_true; |
211 | |
212 | else |
213 | truth = _gf_false; |
214 | |
215 | runner_argprintf (runner, "--first=%s", |
216 | truth? "yes":"no"); |
217 | break; |
218 | |
219 | case GD_OP_STOP_VOLUME: |
220 | if (type == GD_COMMIT_HOOK_PRE && |
221 | vol_count == 1) |
222 | truth = _gf_true; |
223 | |
224 | else if (type == GD_COMMIT_HOOK_POST && |
225 | vol_count == 0) |
226 | truth = _gf_true; |
227 | |
228 | else |
229 | truth = _gf_false; |
230 | |
231 | runner_argprintf (runner, "--last=%s", |
232 | truth? "yes":"no"); |
233 | break; |
234 | |
235 | case GD_OP_SET_VOLUME: |
236 | ret = glusterd_hooks_set_volume_args (op_ctx, runner); |
237 | break; |
238 | |
239 | default: |
240 | break; |
241 | |
242 | } |
243 | |
244 | return ret; |
245 | } |
246 | |
247 | int |
248 | glusterd_hooks_run_hooks (char *hooks_path, glusterd_op_t op, dict_t *op_ctx, |
249 | glusterd_commit_hook_type_t type) |
250 | { |
251 | xlator_t *this = NULL((void*)0); |
252 | glusterd_conf_t *priv = NULL((void*)0); |
253 | runner_t runner = {0, }; |
254 | struct dirent *entry = NULL((void*)0); |
255 | DIR *hookdir = NULL((void*)0); |
256 | char *volname = NULL((void*)0); |
257 | char **lines = NULL((void*)0); |
258 | int N = 8; /*arbitrary*/ |
259 | int lineno = 0; |
260 | int line_count = 0; |
261 | int ret = -1; |
262 | |
263 | this = THIS(*__glusterfs_this_location()); |
264 | priv = this->private; |
Value stored to 'priv' is never read | |
265 | |
266 | ret = dict_get_str (op_ctx, "volname", &volname); |
267 | if (ret) { |
268 | gf_log (this->name, GF_LOG_CRITICAL, "Failed to get volname "do { do { if (0) printf ("Failed to get volname " "from operation context" ); } while (0); _gf_log (this->name, "glusterd-hooks.c", __FUNCTION__ , 269, GF_LOG_CRITICAL, "Failed to get volname " "from operation context" ); } while (0) |
269 | "from operation context")do { do { if (0) printf ("Failed to get volname " "from operation context" ); } while (0); _gf_log (this->name, "glusterd-hooks.c", __FUNCTION__ , 269, GF_LOG_CRITICAL, "Failed to get volname " "from operation context" ); } while (0); |
270 | goto out; |
271 | } |
272 | |
273 | hookdir = opendir (hooks_path); |
274 | if (!hookdir) { |
275 | ret = -1; |
276 | gf_log (this->name, GF_LOG_ERROR, "Failed to open dir %s, due "do { do { if (0) printf ("Failed to open dir %s, due " "to %s" , hooks_path, strerror ((*__errno_location ()))); } while (0) ; _gf_log (this->name, "glusterd-hooks.c", __FUNCTION__, 277 , GF_LOG_ERROR, "Failed to open dir %s, due " "to %s", hooks_path , strerror ((*__errno_location ()))); } while (0) |
277 | "to %s", hooks_path, strerror (errno))do { do { if (0) printf ("Failed to open dir %s, due " "to %s" , hooks_path, strerror ((*__errno_location ()))); } while (0) ; _gf_log (this->name, "glusterd-hooks.c", __FUNCTION__, 277 , GF_LOG_ERROR, "Failed to open dir %s, due " "to %s", hooks_path , strerror ((*__errno_location ()))); } while (0); |
278 | goto out; |
279 | } |
280 | |
281 | lines = GF_CALLOC (1, N * sizeof (*lines), gf_gld_mt_charptr)__gf_calloc (1, N * sizeof (*lines), gf_gld_mt_charptr); |
282 | if (!lines) { |
283 | ret = -1; |
284 | goto out; |
285 | } |
286 | |
287 | ret = -1; |
288 | line_count = 0; |
289 | glusterd_for_each_entry (entry, hookdir)do { entry = ((void*)0); if (hookdir) { entry = readdir (hookdir ); while (entry && (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, ".."))) { entry = readdir (hookdir ); } } } while (0);; |
290 | while (entry) { |
291 | if (line_count == N-1) { |
292 | N *= 2; |
293 | lines = GF_REALLOC (lines, N * sizeof (char *))__gf_realloc (lines, N * sizeof (char *)); |
294 | if (!lines) |
295 | goto out; |
296 | } |
297 | |
298 | if (glusterd_is_hook_enabled (entry->d_name)) { |
299 | lines[line_count] = gf_strdup (entry->d_name); |
300 | line_count++; |
301 | } |
302 | |
303 | glusterd_for_each_entry (entry, hookdir)do { entry = ((void*)0); if (hookdir) { entry = readdir (hookdir ); while (entry && (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, ".."))) { entry = readdir (hookdir ); } } } while (0);; |
304 | } |
305 | |
306 | lines[line_count] = NULL((void*)0); |
307 | lines = GF_REALLOC (lines, (line_count + 1) * sizeof (char *))__gf_realloc (lines, (line_count + 1) * sizeof (char *)); |
308 | if (!lines) |
309 | goto out; |
310 | |
311 | qsort (lines, line_count, sizeof (*lines), glusterd_compare_lines); |
312 | |
313 | for (lineno = 0; lineno < line_count; lineno++) { |
314 | |
315 | runinit (&runner); |
316 | runner_argprintf (&runner, "%s/%s", hooks_path, lines[lineno]); |
317 | /*Add future command line arguments to hook scripts below*/ |
318 | runner_argprintf (&runner, "--volname=%s", volname); |
319 | ret = glusterd_hooks_add_op_args (&runner, op, op_ctx, type); |
320 | if (ret) { |
321 | gf_log (this->name, GF_LOG_ERROR, "Failed to add "do { do { if (0) printf ("Failed to add " "command specific arguments" ); } while (0); _gf_log (this->name, "glusterd-hooks.c", __FUNCTION__ , 322, GF_LOG_ERROR, "Failed to add " "command specific arguments" ); } while (0) |
322 | "command specific arguments")do { do { if (0) printf ("Failed to add " "command specific arguments" ); } while (0); _gf_log (this->name, "glusterd-hooks.c", __FUNCTION__ , 322, GF_LOG_ERROR, "Failed to add " "command specific arguments" ); } while (0); |
323 | goto out; |
324 | } |
325 | |
326 | ret = runner_run_reuse (&runner); |
327 | if (ret) { |
328 | runner_log (&runner, this->name, GF_LOG_ERROR, |
329 | "Failed to execute script"); |
330 | } else { |
331 | runner_log (&runner, this->name, GF_LOG_INFO, |
332 | "Ran script"); |
333 | } |
334 | runner_end (&runner); |
335 | } |
336 | |
337 | ret = 0; |
338 | out: |
339 | if (lines) { |
340 | for (lineno = 0; lineno < line_count+1; lineno++) |
341 | GF_FREE (lines[lineno])__gf_free (lines[lineno]); |
342 | |
343 | GF_FREE (lines)__gf_free (lines); |
344 | } |
345 | |
346 | if (hookdir) |
347 | closedir (hookdir); |
348 | |
349 | return ret; |
350 | } |
351 | |
352 | int |
353 | glusterd_hooks_post_stub_enqueue (char *scriptdir, glusterd_op_t op, |
354 | dict_t *op_ctx) |
355 | { |
356 | int ret = -1; |
357 | glusterd_hooks_stub_t *stub = NULL((void*)0); |
358 | glusterd_hooks_private_t *hooks_priv = NULL((void*)0); |
359 | glusterd_conf_t *conf = NULL((void*)0); |
360 | |
361 | conf = THIS(*__glusterfs_this_location())->private; |
362 | hooks_priv = conf->hooks_priv; |
363 | |
364 | ret = glusterd_hooks_stub_init (&stub, scriptdir, op, op_ctx); |
365 | if (ret) |
366 | goto out; |
367 | |
368 | pthread_mutex_lock (&hooks_priv->mutex); |
369 | { |
370 | hooks_priv->waitcount++; |
371 | list_add_tail (&stub->all_hooks, &hooks_priv->list); |
372 | pthread_cond_signal (&hooks_priv->cond); |
373 | } |
374 | pthread_mutex_unlock (&hooks_priv->mutex); |
375 | |
376 | ret = 0; |
377 | out: |
378 | return ret; |
379 | } |
380 | |
381 | int |
382 | glusterd_hooks_stub_init (glusterd_hooks_stub_t **stub, char *scriptdir, |
383 | glusterd_op_t op, dict_t *op_ctx) |
384 | { |
385 | int ret = -1; |
386 | glusterd_hooks_stub_t *hooks_stub = NULL((void*)0); |
387 | |
388 | GF_ASSERT (stub)do { if (!(stub)) { do { do { if (0) printf ("Assertion failed: " "stub"); } while (0); _gf_log_callingfn ("", "glusterd-hooks.c" , __FUNCTION__, 388, GF_LOG_ERROR, "Assertion failed: " "stub" ); } while (0); } } while (0); |
389 | if (!stub) |
390 | goto out; |
391 | |
392 | hooks_stub = GF_CALLOC (1, sizeof (*hooks_stub),__gf_calloc (1, sizeof (*hooks_stub), gf_gld_mt_hooks_stub_t) |
393 | gf_gld_mt_hooks_stub_t)__gf_calloc (1, sizeof (*hooks_stub), gf_gld_mt_hooks_stub_t); |
394 | if (!hooks_stub) |
395 | goto out; |
396 | |
397 | INIT_LIST_HEAD (&hooks_stub->all_hooks)do { (&hooks_stub->all_hooks)->next = (&hooks_stub ->all_hooks)->prev = &hooks_stub->all_hooks; } while (0); |
398 | hooks_stub->op = op; |
399 | hooks_stub->scriptdir = gf_strdup (scriptdir); |
400 | if (!hooks_stub->scriptdir) |
401 | goto out; |
402 | |
403 | hooks_stub->op_ctx = dict_copy_with_ref (op_ctx, hooks_stub->op_ctx); |
404 | if (!hooks_stub->op_ctx) |
405 | goto out; |
406 | |
407 | *stub = hooks_stub; |
408 | ret = 0; |
409 | out: |
410 | if (ret) { |
411 | gf_log (THIS->name, GF_LOG_ERROR, "Failed to initialize "do { do { if (0) printf ("Failed to initialize " "post hooks stub" ); } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-hooks.c", __FUNCTION__, 412, GF_LOG_ERROR, "Failed to initialize " "post hooks stub"); } while (0) |
412 | "post hooks stub")do { do { if (0) printf ("Failed to initialize " "post hooks stub" ); } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-hooks.c", __FUNCTION__, 412, GF_LOG_ERROR, "Failed to initialize " "post hooks stub"); } while (0); |
413 | glusterd_hooks_stub_cleanup (hooks_stub); |
414 | } |
415 | |
416 | return ret; |
417 | } |
418 | |
419 | void |
420 | glusterd_hooks_stub_cleanup (glusterd_hooks_stub_t *stub) |
421 | { |
422 | if (!stub) { |
423 | gf_log_callingfn (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("hooks_stub is NULL"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "glusterd-hooks.c" , __FUNCTION__, 424, GF_LOG_WARNING, "hooks_stub is NULL"); } while (0) |
424 | "hooks_stub is NULL")do { do { if (0) printf ("hooks_stub is NULL"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "glusterd-hooks.c" , __FUNCTION__, 424, GF_LOG_WARNING, "hooks_stub is NULL"); } while (0); |
425 | return; |
426 | } |
427 | |
428 | if (stub->op_ctx) |
429 | dict_unref (stub->op_ctx); |
430 | |
431 | GF_FREE (stub->scriptdir)__gf_free (stub->scriptdir); |
432 | |
433 | GF_FREE (stub)__gf_free (stub); |
434 | } |
435 | |
436 | static void* |
437 | hooks_worker (void *args) |
438 | { |
439 | glusterd_conf_t *conf = NULL((void*)0); |
440 | glusterd_hooks_private_t *hooks_priv = NULL((void*)0); |
441 | glusterd_hooks_stub_t *stub = NULL((void*)0); |
442 | |
443 | THIS(*__glusterfs_this_location()) = args; |
444 | conf = THIS(*__glusterfs_this_location())->private; |
445 | hooks_priv = conf->hooks_priv; |
446 | |
447 | for (;;) { |
448 | pthread_mutex_lock (&hooks_priv->mutex); |
449 | { |
450 | while (list_empty (&hooks_priv->list)) { |
451 | pthread_cond_wait (&hooks_priv->cond, |
452 | &hooks_priv->mutex); |
453 | } |
454 | stub = list_entry (hooks_priv->list.next,((glusterd_hooks_stub_t *)((char *)(hooks_priv->list.next) -(unsigned long)(&((glusterd_hooks_stub_t *)0)->all_hooks ))) |
455 | glusterd_hooks_stub_t,((glusterd_hooks_stub_t *)((char *)(hooks_priv->list.next) -(unsigned long)(&((glusterd_hooks_stub_t *)0)->all_hooks ))) |
456 | all_hooks)((glusterd_hooks_stub_t *)((char *)(hooks_priv->list.next) -(unsigned long)(&((glusterd_hooks_stub_t *)0)->all_hooks ))); |
457 | list_del_init (&stub->all_hooks); |
458 | hooks_priv->waitcount--; |
459 | |
460 | } |
461 | pthread_mutex_unlock (&hooks_priv->mutex); |
462 | |
463 | glusterd_hooks_run_hooks (stub->scriptdir, stub->op, |
464 | stub->op_ctx, GD_COMMIT_HOOK_POST); |
465 | glusterd_hooks_stub_cleanup (stub); |
466 | } |
467 | |
468 | return NULL((void*)0); |
469 | } |
470 | |
471 | int |
472 | glusterd_hooks_priv_init (glusterd_hooks_private_t **new) |
473 | { |
474 | int ret = -1; |
475 | glusterd_hooks_private_t *hooks_priv = NULL((void*)0); |
476 | |
477 | if (!new) |
478 | goto out; |
479 | |
480 | hooks_priv = GF_CALLOC (1, sizeof (*hooks_priv),__gf_calloc (1, sizeof (*hooks_priv), gf_gld_mt_hooks_priv_t) |
481 | gf_gld_mt_hooks_priv_t)__gf_calloc (1, sizeof (*hooks_priv), gf_gld_mt_hooks_priv_t); |
482 | if (!hooks_priv) |
483 | goto out; |
484 | |
485 | pthread_mutex_init (&hooks_priv->mutex, NULL((void*)0)); |
486 | pthread_cond_init (&hooks_priv->cond, NULL((void*)0)); |
487 | INIT_LIST_HEAD (&hooks_priv->list)do { (&hooks_priv->list)->next = (&hooks_priv-> list)->prev = &hooks_priv->list; } while (0); |
488 | hooks_priv->waitcount = 0; |
489 | |
490 | *new = hooks_priv; |
491 | ret = 0; |
492 | out: |
493 | return ret; |
494 | } |
495 | |
496 | int |
497 | glusterd_hooks_spawn_worker (xlator_t *this) |
498 | { |
499 | int ret = -1; |
500 | glusterd_conf_t *conf = NULL((void*)0); |
501 | glusterd_hooks_private_t *hooks_priv = NULL((void*)0); |
502 | |
503 | |
504 | ret = glusterd_hooks_priv_init (&hooks_priv); |
505 | if (ret) |
506 | goto out; |
507 | |
508 | conf = this->private; |
509 | conf->hooks_priv = hooks_priv; |
510 | ret = pthread_create (&hooks_priv->worker, NULL((void*)0), hooks_worker, |
511 | (void *)this); |
512 | if (ret) |
513 | gf_log (this->name, GF_LOG_CRITICAL, "Failed to spawn post "do { do { if (0) printf ("Failed to spawn post " "hooks worker thread" ); } while (0); _gf_log (this->name, "glusterd-hooks.c", __FUNCTION__ , 514, GF_LOG_CRITICAL, "Failed to spawn post " "hooks worker thread" ); } while (0) |
514 | "hooks worker thread")do { do { if (0) printf ("Failed to spawn post " "hooks worker thread" ); } while (0); _gf_log (this->name, "glusterd-hooks.c", __FUNCTION__ , 514, GF_LOG_CRITICAL, "Failed to spawn post " "hooks worker thread" ); } while (0); |
515 | out: |
516 | return ret; |
517 | } |