File: | xlators/cluster/dht/src/dht-shared.c |
Location: | line 471, column 9 |
Description: | Value stored to 'ret' is never read |
1 | /* |
2 | Copyright (c) 2008-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 | |
12 | #ifndef _CONFIG_H |
13 | #define _CONFIG_H |
14 | #include "config.h" |
15 | #endif |
16 | |
17 | /* TODO: add NS locking */ |
18 | |
19 | #include "statedump.h" |
20 | #include "dht-common.h" |
21 | |
22 | /* TODO: |
23 | - use volumename in xattr instead of "dht" |
24 | - use NS locks |
25 | - handle all cases in self heal layout reconstruction |
26 | - complete linkfile selfheal |
27 | */ |
28 | struct volume_options options[]; |
29 | |
30 | void |
31 | dht_layout_dump (dht_layout_t *layout, const char *prefix) |
32 | { |
33 | |
34 | char key[GF_DUMP_MAX_BUF_LEN4096]; |
35 | int i = 0; |
36 | |
37 | if (!layout) |
38 | goto out; |
39 | if (!prefix) |
40 | goto out; |
41 | |
42 | gf_proc_dump_build_key(key, prefix, "cnt"){ _gf_proc_dump_build_key(key, prefix, "cnt"); }; |
43 | gf_proc_dump_write(key, "%d", layout->cnt); |
44 | gf_proc_dump_build_key(key, prefix, "preset"){ _gf_proc_dump_build_key(key, prefix, "preset"); }; |
45 | gf_proc_dump_write(key, "%d", layout->preset); |
46 | gf_proc_dump_build_key(key, prefix, "gen"){ _gf_proc_dump_build_key(key, prefix, "gen"); }; |
47 | gf_proc_dump_write(key, "%d", layout->gen); |
48 | if (layout->type != IA_INVAL) { |
49 | gf_proc_dump_build_key(key, prefix, "inode type"){ _gf_proc_dump_build_key(key, prefix, "inode type"); }; |
50 | gf_proc_dump_write(key, "%d", layout->type); |
51 | } |
52 | |
53 | if (!IA_ISDIR (layout->type)(layout->type == IA_IFDIR)) |
54 | goto out; |
55 | |
56 | for (i = 0; i < layout->cnt; i++) { |
57 | gf_proc_dump_build_key(key, prefix,"list[%d].err", i){ _gf_proc_dump_build_key(key, prefix,"list[%d].err", i); }; |
58 | gf_proc_dump_write(key, "%d", layout->list[i].err); |
59 | gf_proc_dump_build_key(key, prefix,"list[%d].start", i){ _gf_proc_dump_build_key(key, prefix,"list[%d].start", i); }; |
60 | gf_proc_dump_write(key, "%u", layout->list[i].start); |
61 | gf_proc_dump_build_key(key, prefix,"list[%d].stop", i){ _gf_proc_dump_build_key(key, prefix,"list[%d].stop", i); }; |
62 | gf_proc_dump_write(key, "%u", layout->list[i].stop); |
63 | if (layout->list[i].xlator) { |
64 | gf_proc_dump_build_key(key, prefix,{ _gf_proc_dump_build_key(key, prefix, "list[%d].xlator.type" , i); } |
65 | "list[%d].xlator.type", i){ _gf_proc_dump_build_key(key, prefix, "list[%d].xlator.type" , i); }; |
66 | gf_proc_dump_write(key, "%s", |
67 | layout->list[i].xlator->type); |
68 | gf_proc_dump_build_key(key, prefix,{ _gf_proc_dump_build_key(key, prefix, "list[%d].xlator.name" , i); } |
69 | "list[%d].xlator.name", i){ _gf_proc_dump_build_key(key, prefix, "list[%d].xlator.name" , i); }; |
70 | gf_proc_dump_write(key, "%s", |
71 | layout->list[i].xlator->name); |
72 | } |
73 | } |
74 | |
75 | out: |
76 | return; |
77 | } |
78 | |
79 | |
80 | int32_t |
81 | dht_priv_dump (xlator_t *this) |
82 | { |
83 | char key_prefix[GF_DUMP_MAX_BUF_LEN4096]; |
84 | char key[GF_DUMP_MAX_BUF_LEN4096]; |
85 | int i = 0; |
86 | dht_conf_t *conf = NULL((void*)0); |
87 | int ret = -1; |
88 | |
89 | if (!this) |
90 | goto out; |
91 | |
92 | conf = this->private; |
93 | if (!conf) |
94 | goto out; |
95 | |
96 | ret = TRY_LOCK(&conf->subvolume_lock)pthread_spin_trylock (&conf->subvolume_lock); |
97 | if (ret != 0) { |
98 | return ret; |
99 | } |
100 | |
101 | gf_proc_dump_add_section("xlator.cluster.dht.%s.priv", this->name); |
102 | gf_proc_dump_build_key(key_prefix,"xlator.cluster.dht","%s.priv",{ _gf_proc_dump_build_key(key_prefix, "xlator.cluster.dht","%s.priv" , this->name); } |
103 | this->name){ _gf_proc_dump_build_key(key_prefix, "xlator.cluster.dht","%s.priv" , this->name); }; |
104 | gf_proc_dump_write("subvol_cnt","%d", conf->subvolume_cnt); |
105 | for (i = 0; i < conf->subvolume_cnt; i++) { |
106 | sprintf (key, "subvolumes[%d]", i); |
107 | gf_proc_dump_write(key, "%s.%s", conf->subvolumes[i]->type, |
108 | conf->subvolumes[i]->name); |
109 | if (conf->file_layouts && conf->file_layouts[i]){ |
110 | sprintf (key, "file_layouts[%d]", i); |
111 | dht_layout_dump(conf->file_layouts[i], key); |
112 | } |
113 | if (conf->dir_layouts && conf->dir_layouts[i]) { |
114 | sprintf (key, "dir_layouts[%d]", i); |
115 | dht_layout_dump(conf->dir_layouts[i], key); |
116 | } |
117 | if (conf->subvolume_status) { |
118 | |
119 | sprintf (key, "subvolume_status[%d]", i); |
120 | gf_proc_dump_write(key, "%d", |
121 | (int)conf->subvolume_status[i]); |
122 | } |
123 | |
124 | } |
125 | |
126 | gf_proc_dump_write("search_unhashed", "%d", conf->search_unhashed); |
127 | gf_proc_dump_write("gen", "%d", conf->gen); |
128 | gf_proc_dump_write("min_free_disk", "%lf", conf->min_free_disk); |
129 | gf_proc_dump_write("min_free_inodes", "%lf", conf->min_free_inodes); |
130 | gf_proc_dump_write("disk_unit", "%c", conf->disk_unit); |
131 | gf_proc_dump_write("refresh_interval", "%d", conf->refresh_interval); |
132 | gf_proc_dump_write("unhashed_sticky_bit", "%d", conf->unhashed_sticky_bit); |
133 | if (conf ->du_stats) { |
134 | gf_proc_dump_write("du_stats.avail_percent", "%lf", |
135 | conf->du_stats->avail_percent); |
136 | gf_proc_dump_write("du_stats.avail_space", "%lu", |
137 | conf->du_stats->avail_space); |
138 | gf_proc_dump_write("du_stats.avail_inodes", "%lf", |
139 | conf->du_stats->avail_inodes); |
140 | gf_proc_dump_write("du_stats.log", "%lu", conf->du_stats->log); |
141 | } |
142 | |
143 | if (conf->last_stat_fetch.tv_sec) |
144 | gf_proc_dump_write("last_stat_fetch", "%s", |
145 | ctime(&conf->last_stat_fetch.tv_sec)); |
146 | |
147 | UNLOCK(&conf->subvolume_lock)pthread_spin_unlock (&conf->subvolume_lock); |
148 | |
149 | out: |
150 | return ret; |
151 | } |
152 | |
153 | int32_t |
154 | dht_inodectx_dump (xlator_t *this, inode_t *inode) |
155 | { |
156 | int ret = -1; |
157 | dht_layout_t *layout = NULL((void*)0); |
158 | |
159 | if (!this) |
160 | goto out; |
161 | if (!inode) |
162 | goto out; |
163 | |
164 | ret = dht_inode_ctx_layout_get (inode, this, &layout); |
165 | |
166 | if ((ret != 0) || !layout) |
167 | return ret; |
168 | |
169 | gf_proc_dump_add_section("xlator.cluster.dht.%s.inode", this->name); |
170 | dht_layout_dump(layout, "layout"); |
171 | |
172 | out: |
173 | return ret; |
174 | } |
175 | |
176 | void |
177 | dht_fini (xlator_t *this) |
178 | { |
179 | int i = 0; |
180 | dht_conf_t *conf = NULL((void*)0); |
181 | |
182 | GF_VALIDATE_OR_GOTO ("dht", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("dht", "dht-shared.c", __FUNCTION__, 182, GF_LOG_ERROR, "invalid argument: " "this"); } while (0); goto out; } } while (0); |
183 | |
184 | conf = this->private; |
185 | this->private = NULL((void*)0); |
186 | if (conf) { |
187 | if (conf->file_layouts) { |
188 | for (i = 0; i < conf->subvolume_cnt; i++) { |
189 | GF_FREE (conf->file_layouts[i])__gf_free (conf->file_layouts[i]); |
190 | } |
191 | GF_FREE (conf->file_layouts)__gf_free (conf->file_layouts); |
192 | } |
193 | |
194 | GF_FREE (conf->subvolumes)__gf_free (conf->subvolumes); |
195 | |
196 | GF_FREE (conf->subvolume_status)__gf_free (conf->subvolume_status); |
197 | |
198 | GF_FREE (conf)__gf_free (conf); |
199 | } |
200 | out: |
201 | return; |
202 | } |
203 | |
204 | int32_t |
205 | mem_acct_init (xlator_t *this) |
206 | { |
207 | int ret = -1; |
208 | |
209 | GF_VALIDATE_OR_GOTO ("dht", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("dht", "dht-shared.c", __FUNCTION__, 209, GF_LOG_ERROR, "invalid argument: " "this"); } while (0); goto out; } } while (0); |
210 | |
211 | ret = xlator_mem_acct_init (this, gf_dht_mt_end + 1); |
212 | |
213 | if (ret != 0) { |
214 | gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"do { do { if (0) printf ("Memory accounting init" "failed"); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 215, GF_LOG_ERROR, "Memory accounting init" "failed"); } while (0) |
215 | "failed")do { do { if (0) printf ("Memory accounting init" "failed"); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 215, GF_LOG_ERROR, "Memory accounting init" "failed"); } while (0); |
216 | return ret; |
217 | } |
218 | out: |
219 | return ret; |
220 | } |
221 | |
222 | |
223 | int |
224 | dht_parse_decommissioned_bricks (xlator_t *this, dht_conf_t *conf, |
225 | const char *bricks) |
226 | { |
227 | int i = 0; |
228 | int ret = -1; |
229 | char *tmpstr = NULL((void*)0); |
230 | char *dup_brick = NULL((void*)0); |
231 | char *node = NULL((void*)0); |
232 | |
233 | if (!conf || !bricks) |
234 | goto out; |
235 | |
236 | dup_brick = gf_strdup (bricks); |
237 | node = strtok_r (dup_brick, ",", &tmpstr); |
238 | while (node) { |
239 | for (i = 0; i < conf->subvolume_cnt; i++) { |
240 | if (!strcmp (conf->subvolumes[i]->name, node)) { |
241 | conf->decommissioned_bricks[i] = |
242 | conf->subvolumes[i]; |
243 | conf->decommission_subvols_cnt++; |
244 | gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("decommissioning subvolume %s", conf ->subvolumes[i]->name); } while (0); _gf_log (this-> name, "dht-shared.c", __FUNCTION__, 246, GF_LOG_INFO, "decommissioning subvolume %s" , conf->subvolumes[i]->name); } while (0) |
245 | "decommissioning subvolume %s",do { do { if (0) printf ("decommissioning subvolume %s", conf ->subvolumes[i]->name); } while (0); _gf_log (this-> name, "dht-shared.c", __FUNCTION__, 246, GF_LOG_INFO, "decommissioning subvolume %s" , conf->subvolumes[i]->name); } while (0) |
246 | conf->subvolumes[i]->name)do { do { if (0) printf ("decommissioning subvolume %s", conf ->subvolumes[i]->name); } while (0); _gf_log (this-> name, "dht-shared.c", __FUNCTION__, 246, GF_LOG_INFO, "decommissioning subvolume %s" , conf->subvolumes[i]->name); } while (0); |
247 | break; |
248 | } |
249 | } |
250 | if (i == conf->subvolume_cnt) { |
251 | /* Wrong node given. */ |
252 | goto out; |
253 | } |
254 | node = strtok_r (NULL((void*)0), ",", &tmpstr); |
255 | } |
256 | |
257 | ret = 0; |
258 | conf->decommission_in_progress = 1; |
259 | out: |
260 | GF_FREE (dup_brick)__gf_free (dup_brick); |
261 | |
262 | return ret; |
263 | } |
264 | |
265 | void |
266 | dht_init_regex (xlator_t *this, dict_t *odict, char *name, |
267 | regex_t *re, gf_boolean_t *re_valid) |
268 | { |
269 | char *temp_str; |
270 | |
271 | if (dict_get_str (odict, name, &temp_str) != 0) { |
272 | if (strcmp(name,"rsync-hash-regex")) { |
273 | return; |
274 | } |
275 | temp_str = "^\\.(.+)\\.[^.]+$"; |
276 | } |
277 | |
278 | if (*re_valid) { |
279 | regfree(re); |
280 | *re_valid = _gf_false; |
281 | } |
282 | |
283 | if (!strcmp(temp_str,"none")) { |
284 | return; |
285 | } |
286 | |
287 | if (regcomp(re,temp_str,REG_EXTENDED1) == 0) { |
288 | gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("using regex %s = %s", name, temp_str ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 289, GF_LOG_INFO, "using regex %s = %s", name, temp_str); } while (0) |
289 | "using regex %s = %s", name, temp_str)do { do { if (0) printf ("using regex %s = %s", name, temp_str ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 289, GF_LOG_INFO, "using regex %s = %s", name, temp_str); } while (0); |
290 | *re_valid = _gf_true; |
291 | } |
292 | else { |
293 | gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("compiling regex %s failed", temp_str ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 294, GF_LOG_WARNING, "compiling regex %s failed", temp_str) ; } while (0) |
294 | "compiling regex %s failed", temp_str)do { do { if (0) printf ("compiling regex %s failed", temp_str ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 294, GF_LOG_WARNING, "compiling regex %s failed", temp_str) ; } while (0); |
295 | } |
296 | } |
297 | |
298 | int |
299 | dht_reconfigure (xlator_t *this, dict_t *options) |
300 | { |
301 | dht_conf_t *conf = NULL((void*)0); |
302 | char *temp_str = NULL((void*)0); |
303 | gf_boolean_t search_unhashed; |
304 | int ret = -1; |
305 | |
306 | GF_VALIDATE_OR_GOTO ("dht", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("dht", "dht-shared.c", __FUNCTION__, 306, GF_LOG_ERROR, "invalid argument: " "this"); } while (0); goto out; } } while (0); |
307 | GF_VALIDATE_OR_GOTO ("dht", options, out)do { if (!options) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "options"); } while (0); _gf_log_callingfn ("dht", "dht-shared.c", __FUNCTION__, 307, GF_LOG_ERROR, "invalid argument: " "options"); } while (0); goto out; } } while (0); |
308 | |
309 | conf = this->private; |
310 | if (!conf) |
311 | return 0; |
312 | |
313 | if (dict_get_str (options, "lookup-unhashed", &temp_str) == 0) { |
314 | /* If option is not "auto", other options _should_ be boolean*/ |
315 | if (strcasecmp (temp_str, "auto")) { |
316 | if (!gf_string2boolean (temp_str, &search_unhashed)) { |
317 | gf_log(this->name, GF_LOG_DEBUG, "Reconfigure:"do { do { if (0) printf ("Reconfigure:" " lookup-unhashed reconfigured (%s)" , temp_str); } while (0); _gf_log (this->name, "dht-shared.c" , __FUNCTION__, 319, GF_LOG_DEBUG, "Reconfigure:" " lookup-unhashed reconfigured (%s)" , temp_str); } while (0) |
318 | " lookup-unhashed reconfigured (%s)",do { do { if (0) printf ("Reconfigure:" " lookup-unhashed reconfigured (%s)" , temp_str); } while (0); _gf_log (this->name, "dht-shared.c" , __FUNCTION__, 319, GF_LOG_DEBUG, "Reconfigure:" " lookup-unhashed reconfigured (%s)" , temp_str); } while (0) |
319 | temp_str)do { do { if (0) printf ("Reconfigure:" " lookup-unhashed reconfigured (%s)" , temp_str); } while (0); _gf_log (this->name, "dht-shared.c" , __FUNCTION__, 319, GF_LOG_DEBUG, "Reconfigure:" " lookup-unhashed reconfigured (%s)" , temp_str); } while (0); |
320 | conf->search_unhashed = search_unhashed; |
321 | } else { |
322 | gf_log(this->name, GF_LOG_ERROR, "Reconfigure:"do { do { if (0) printf ("Reconfigure:" " lookup-unhashed should be boolean," " not (%s), defaulting to (%d)", temp_str, conf->search_unhashed ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 325, GF_LOG_ERROR, "Reconfigure:" " lookup-unhashed should be boolean," " not (%s), defaulting to (%d)", temp_str, conf->search_unhashed ); } while (0) |
323 | " lookup-unhashed should be boolean,"do { do { if (0) printf ("Reconfigure:" " lookup-unhashed should be boolean," " not (%s), defaulting to (%d)", temp_str, conf->search_unhashed ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 325, GF_LOG_ERROR, "Reconfigure:" " lookup-unhashed should be boolean," " not (%s), defaulting to (%d)", temp_str, conf->search_unhashed ); } while (0) |
324 | " not (%s), defaulting to (%d)",do { do { if (0) printf ("Reconfigure:" " lookup-unhashed should be boolean," " not (%s), defaulting to (%d)", temp_str, conf->search_unhashed ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 325, GF_LOG_ERROR, "Reconfigure:" " lookup-unhashed should be boolean," " not (%s), defaulting to (%d)", temp_str, conf->search_unhashed ); } while (0) |
325 | temp_str, conf->search_unhashed)do { do { if (0) printf ("Reconfigure:" " lookup-unhashed should be boolean," " not (%s), defaulting to (%d)", temp_str, conf->search_unhashed ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 325, GF_LOG_ERROR, "Reconfigure:" " lookup-unhashed should be boolean," " not (%s), defaulting to (%d)", temp_str, conf->search_unhashed ); } while (0); |
326 | //return -1; |
327 | ret = -1; |
328 | goto out; |
329 | } |
330 | } else { |
331 | gf_log(this->name, GF_LOG_DEBUG, "Reconfigure:"do { do { if (0) printf ("Reconfigure:" " lookup-unhashed reconfigured auto " ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 332, GF_LOG_DEBUG, "Reconfigure:" " lookup-unhashed reconfigured auto " ); } while (0) |
332 | " lookup-unhashed reconfigured auto ")do { do { if (0) printf ("Reconfigure:" " lookup-unhashed reconfigured auto " ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 332, GF_LOG_DEBUG, "Reconfigure:" " lookup-unhashed reconfigured auto " ); } while (0); |
333 | conf->search_unhashed = GF_DHT_LOOKUP_UNHASHED_AUTO2; |
334 | } |
335 | } |
336 | |
337 | GF_OPTION_RECONF ("min-free-disk", conf->min_free_disk, options,do { int val_ret = 0; val_ret = xlator_option_reconf_percent_or_size ((*__glusterfs_this_location()), options, "min-free-disk", & (conf->min_free_disk)); if (val_ret) goto out; } while (0) |
338 | percent_or_size, out)do { int val_ret = 0; val_ret = xlator_option_reconf_percent_or_size ((*__glusterfs_this_location()), options, "min-free-disk", & (conf->min_free_disk)); if (val_ret) goto out; } while (0); |
339 | /* option can be any one of percent or bytes */ |
340 | conf->disk_unit = 0; |
341 | if (conf->min_free_disk < 100.0) |
342 | conf->disk_unit = 'p'; |
343 | |
344 | GF_OPTION_RECONF ("min-free-inodes", conf->min_free_inodes, options,do { int val_ret = 0; val_ret = xlator_option_reconf_percent ( (*__glusterfs_this_location()), options, "min-free-inodes", & (conf->min_free_inodes)); if (val_ret) goto out; } while ( 0) |
345 | percent, out)do { int val_ret = 0; val_ret = xlator_option_reconf_percent ( (*__glusterfs_this_location()), options, "min-free-inodes", & (conf->min_free_inodes)); if (val_ret) goto out; } while ( 0); |
346 | |
347 | GF_OPTION_RECONF ("directory-layout-spread", conf->dir_spread_cnt,do { int val_ret = 0; val_ret = xlator_option_reconf_uint32 ( (*__glusterfs_this_location()), options, "directory-layout-spread" , &(conf->dir_spread_cnt)); if (val_ret) goto out; } while (0) |
348 | options, uint32, out)do { int val_ret = 0; val_ret = xlator_option_reconf_uint32 ( (*__glusterfs_this_location()), options, "directory-layout-spread" , &(conf->dir_spread_cnt)); if (val_ret) goto out; } while (0); |
349 | |
350 | GF_OPTION_RECONF ("readdir-optimize", conf->readdir_optimize, options,do { int val_ret = 0; val_ret = xlator_option_reconf_bool ((* __glusterfs_this_location()), options, "readdir-optimize", & (conf->readdir_optimize)); if (val_ret) goto out; } while ( 0) |
351 | bool, out)do { int val_ret = 0; val_ret = xlator_option_reconf_bool ((* __glusterfs_this_location()), options, "readdir-optimize", & (conf->readdir_optimize)); if (val_ret) goto out; } while ( 0); |
352 | if (conf->defrag) { |
353 | GF_OPTION_RECONF ("rebalance-stats", conf->defrag->stats,do { int val_ret = 0; val_ret = xlator_option_reconf_bool ((* __glusterfs_this_location()), options, "rebalance-stats", & (conf->defrag->stats)); if (val_ret) goto out; } while ( 0) |
354 | options, bool, out)do { int val_ret = 0; val_ret = xlator_option_reconf_bool ((* __glusterfs_this_location()), options, "rebalance-stats", & (conf->defrag->stats)); if (val_ret) goto out; } while ( 0); |
355 | } |
356 | |
357 | if (dict_get_str (options, "decommissioned-bricks", &temp_str) == 0) { |
358 | ret = dht_parse_decommissioned_bricks (this, conf, temp_str); |
359 | if (ret == -1) |
360 | goto out; |
361 | } |
362 | |
363 | dht_init_regex (this, options, "rsync-hash-regex", |
364 | &conf->rsync_regex, &conf->rsync_regex_valid); |
365 | dht_init_regex (this, options, "extra-hash-regex", |
366 | &conf->extra_regex, &conf->extra_regex_valid); |
367 | |
368 | ret = 0; |
369 | out: |
370 | return ret; |
371 | } |
372 | |
373 | static int |
374 | gf_defrag_pattern_list_fill (xlator_t *this, gf_defrag_info_t *defrag, char *data) |
375 | { |
376 | int ret = -1; |
377 | char *tmp_str = NULL((void*)0); |
378 | char *tmp_str1 = NULL((void*)0); |
379 | char *dup_str = NULL((void*)0); |
380 | char *num = NULL((void*)0); |
381 | char *pattern_str = NULL((void*)0); |
382 | char *pattern = NULL((void*)0); |
383 | gf_defrag_pattern_list_t *temp_list = NULL((void*)0); |
384 | gf_defrag_pattern_list_t *pattern_list = NULL((void*)0); |
385 | |
386 | if (!this || !defrag || !data) |
387 | goto out; |
388 | |
389 | /* Get the pattern for pattern list. "pattern:<optional-size>" |
390 | * eg: *avi, *pdf:10MB, *:1TB |
391 | */ |
392 | pattern_str = strtok_r (data, ",", &tmp_str); |
393 | while (pattern_str) { |
394 | dup_str = gf_strdup (pattern_str); |
395 | pattern_list = GF_CALLOC (1, sizeof (gf_defrag_pattern_list_t),__gf_calloc (1, sizeof (gf_defrag_pattern_list_t), 1) |
396 | 1)__gf_calloc (1, sizeof (gf_defrag_pattern_list_t), 1); |
397 | if (!pattern_list) { |
398 | goto out; |
399 | } |
400 | pattern = strtok_r (dup_str, ":", &tmp_str1); |
401 | num = strtok_r (NULL((void*)0), ":", &tmp_str1); |
402 | if (!pattern) |
403 | goto out; |
404 | if (!num) { |
405 | if (gf_string2bytesize(pattern, &pattern_list->size) |
406 | == 0) { |
407 | pattern = "*"; |
408 | } |
409 | } else if (gf_string2bytesize (num, &pattern_list->size) != 0) { |
410 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("invalid number format \"%s\"", num) ; } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 411, GF_LOG_ERROR, "invalid number format \"%s\"", num); } while (0) |
411 | "invalid number format \"%s\"", num)do { do { if (0) printf ("invalid number format \"%s\"", num) ; } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 411, GF_LOG_ERROR, "invalid number format \"%s\"", num); } while (0); |
412 | goto out; |
413 | } |
414 | memcpy (pattern_list->path_pattern, pattern, strlen (dup_str)); |
415 | |
416 | if (!defrag->defrag_pattern) |
417 | temp_list = NULL((void*)0); |
418 | else |
419 | temp_list = defrag->defrag_pattern; |
420 | |
421 | pattern_list->next = temp_list; |
422 | |
423 | defrag->defrag_pattern = pattern_list; |
424 | pattern_list = NULL((void*)0); |
425 | |
426 | GF_FREE (dup_str)__gf_free (dup_str); |
427 | dup_str = NULL((void*)0); |
428 | |
429 | pattern_str = strtok_r (NULL((void*)0), ",", &tmp_str); |
430 | } |
431 | |
432 | ret = 0; |
433 | out: |
434 | if (ret) |
435 | GF_FREE (pattern_list)__gf_free (pattern_list); |
436 | GF_FREE (dup_str)__gf_free (dup_str); |
437 | |
438 | return ret; |
439 | } |
440 | |
441 | int |
442 | dht_init (xlator_t *this) |
443 | { |
444 | dht_conf_t *conf = NULL((void*)0); |
445 | char *temp_str = NULL((void*)0); |
446 | int ret = -1; |
447 | int i = 0; |
448 | gf_defrag_info_t *defrag = NULL((void*)0); |
449 | int cmd = 0; |
450 | char *node_uuid = NULL((void*)0); |
451 | |
452 | |
453 | GF_VALIDATE_OR_GOTO ("dht", this, err)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("dht", "dht-shared.c", __FUNCTION__, 453, GF_LOG_ERROR, "invalid argument: " "this"); } while (0); goto err; } } while (0); |
454 | |
455 | if (!this->children) { |
456 | gf_log (this->name, GF_LOG_CRITICAL,do { do { if (0) printf ("Distribute needs more than one subvolume" ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 457, GF_LOG_CRITICAL, "Distribute needs more than one subvolume" ); } while (0) |
457 | "Distribute needs more than one subvolume")do { do { if (0) printf ("Distribute needs more than one subvolume" ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 457, GF_LOG_CRITICAL, "Distribute needs more than one subvolume" ); } while (0); |
458 | return -1; |
459 | } |
460 | |
461 | if (!this->parents) { |
462 | gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("dangling volume. check volfile"); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 463, GF_LOG_WARNING, "dangling volume. check volfile"); } while (0) |
463 | "dangling volume. check volfile")do { do { if (0) printf ("dangling volume. check volfile"); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 463, GF_LOG_WARNING, "dangling volume. check volfile"); } while (0); |
464 | } |
465 | |
466 | conf = GF_CALLOC (1, sizeof (*conf), gf_dht_mt_dht_conf_t)__gf_calloc (1, sizeof (*conf), gf_dht_mt_dht_conf_t); |
467 | if (!conf) { |
468 | goto err; |
469 | } |
470 | |
471 | ret = dict_get_int32 (this->options, "rebalance-cmd", &cmd); |
Value stored to 'ret' is never read | |
472 | |
473 | if (cmd) { |
474 | defrag = GF_CALLOC (1, sizeof (gf_defrag_info_t),__gf_calloc (1, sizeof (gf_defrag_info_t), gf_defrag_info_mt) |
475 | gf_defrag_info_mt)__gf_calloc (1, sizeof (gf_defrag_info_t), gf_defrag_info_mt); |
476 | |
477 | GF_VALIDATE_OR_GOTO (this->name, defrag, err)do { if (!defrag) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "defrag"); } while (0); _gf_log_callingfn (this->name, "dht-shared.c", __FUNCTION__, 477, GF_LOG_ERROR , "invalid argument: " "defrag"); } while (0); goto err; } } while (0); |
478 | |
479 | LOCK_INIT (&defrag->lock)pthread_spin_init (&defrag->lock, 0); |
480 | |
481 | defrag->is_exiting = 0; |
482 | |
483 | conf->defrag = defrag; |
484 | |
485 | ret = dict_get_str (this->options, "node-uuid", &node_uuid); |
486 | if (ret) { |
487 | gf_log (this->name, GF_LOG_ERROR, "node-uuid not "do { do { if (0) printf ("node-uuid not " "specified"); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__, 488 , GF_LOG_ERROR, "node-uuid not " "specified"); } while (0) |
488 | "specified")do { do { if (0) printf ("node-uuid not " "specified"); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__, 488 , GF_LOG_ERROR, "node-uuid not " "specified"); } while (0); |
489 | goto err; |
490 | } |
491 | |
492 | if (uuid_parse (node_uuid, defrag->node_uuid)) { |
493 | gf_log (this->name, GF_LOG_ERROR, "Cannot parse "do { do { if (0) printf ("Cannot parse " "glusterd node uuid" ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 494, GF_LOG_ERROR, "Cannot parse " "glusterd node uuid"); } while (0) |
494 | "glusterd node uuid")do { do { if (0) printf ("Cannot parse " "glusterd node uuid" ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 494, GF_LOG_ERROR, "Cannot parse " "glusterd node uuid"); } while (0); |
495 | goto err; |
496 | } |
497 | |
498 | defrag->cmd = cmd; |
499 | |
500 | defrag->stats = _gf_false; |
501 | } |
502 | |
503 | conf->search_unhashed = GF_DHT_LOOKUP_UNHASHED_ON1; |
504 | if (dict_get_str (this->options, "lookup-unhashed", &temp_str) == 0) { |
505 | /* If option is not "auto", other options _should_ be boolean */ |
506 | if (strcasecmp (temp_str, "auto")) |
507 | gf_string2boolean (temp_str, &conf->search_unhashed); |
508 | else |
509 | conf->search_unhashed = GF_DHT_LOOKUP_UNHASHED_AUTO2; |
510 | } |
511 | |
512 | GF_OPTION_INIT ("unhashed-sticky-bit", conf->unhashed_sticky_bit, bool,do { int val_ret = 0; val_ret = xlator_option_init_bool ((*__glusterfs_this_location ()), (*__glusterfs_this_location())->options, "unhashed-sticky-bit" , &(conf->unhashed_sticky_bit)); if (val_ret) goto err ; } while (0) |
513 | err)do { int val_ret = 0; val_ret = xlator_option_init_bool ((*__glusterfs_this_location ()), (*__glusterfs_this_location())->options, "unhashed-sticky-bit" , &(conf->unhashed_sticky_bit)); if (val_ret) goto err ; } while (0); |
514 | |
515 | GF_OPTION_INIT ("use-readdirp", conf->use_readdirp, bool, err)do { int val_ret = 0; val_ret = xlator_option_init_bool ((*__glusterfs_this_location ()), (*__glusterfs_this_location())->options, "use-readdirp" , &(conf->use_readdirp)); if (val_ret) goto err; } while (0); |
516 | |
517 | GF_OPTION_INIT ("min-free-disk", conf->min_free_disk, percent_or_size,do { int val_ret = 0; val_ret = xlator_option_init_percent_or_size ((*__glusterfs_this_location()), (*__glusterfs_this_location ())->options, "min-free-disk", &(conf->min_free_disk )); if (val_ret) goto err; } while (0) |
518 | err)do { int val_ret = 0; val_ret = xlator_option_init_percent_or_size ((*__glusterfs_this_location()), (*__glusterfs_this_location ())->options, "min-free-disk", &(conf->min_free_disk )); if (val_ret) goto err; } while (0); |
519 | |
520 | GF_OPTION_INIT ("min-free-inodes", conf->min_free_inodes, percent,do { int val_ret = 0; val_ret = xlator_option_init_percent (( *__glusterfs_this_location()), (*__glusterfs_this_location()) ->options, "min-free-inodes", &(conf->min_free_inodes )); if (val_ret) goto err; } while (0) |
521 | err)do { int val_ret = 0; val_ret = xlator_option_init_percent (( *__glusterfs_this_location()), (*__glusterfs_this_location()) ->options, "min-free-inodes", &(conf->min_free_inodes )); if (val_ret) goto err; } while (0); |
522 | |
523 | conf->dir_spread_cnt = conf->subvolume_cnt; |
524 | GF_OPTION_INIT ("directory-layout-spread", conf->dir_spread_cnt,do { int val_ret = 0; val_ret = xlator_option_init_uint32 ((* __glusterfs_this_location()), (*__glusterfs_this_location())-> options, "directory-layout-spread", &(conf->dir_spread_cnt )); if (val_ret) goto err; } while (0) |
525 | uint32, err)do { int val_ret = 0; val_ret = xlator_option_init_uint32 ((* __glusterfs_this_location()), (*__glusterfs_this_location())-> options, "directory-layout-spread", &(conf->dir_spread_cnt )); if (val_ret) goto err; } while (0); |
526 | |
527 | GF_OPTION_INIT ("assert-no-child-down", conf->assert_no_child_down,do { int val_ret = 0; val_ret = xlator_option_init_bool ((*__glusterfs_this_location ()), (*__glusterfs_this_location())->options, "assert-no-child-down" , &(conf->assert_no_child_down)); if (val_ret) goto err ; } while (0) |
528 | bool, err)do { int val_ret = 0; val_ret = xlator_option_init_bool ((*__glusterfs_this_location ()), (*__glusterfs_this_location())->options, "assert-no-child-down" , &(conf->assert_no_child_down)); if (val_ret) goto err ; } while (0); |
529 | |
530 | GF_OPTION_INIT ("readdir-optimize", conf->readdir_optimize, bool, err)do { int val_ret = 0; val_ret = xlator_option_init_bool ((*__glusterfs_this_location ()), (*__glusterfs_this_location())->options, "readdir-optimize" , &(conf->readdir_optimize)); if (val_ret) goto err; } while (0); |
531 | |
532 | if (defrag) { |
533 | GF_OPTION_INIT ("rebalance-stats", defrag->stats, bool, err)do { int val_ret = 0; val_ret = xlator_option_init_bool ((*__glusterfs_this_location ()), (*__glusterfs_this_location())->options, "rebalance-stats" , &(defrag->stats)); if (val_ret) goto err; } while (0 ); |
534 | if (dict_get_str (this->options, "rebalance-filter", &temp_str) |
535 | == 0) { |
536 | if (gf_defrag_pattern_list_fill (this, defrag, temp_str) |
537 | == -1) { |
538 | gf_log (this->name, GF_LOG_ERROR, "Cannot parse"do { do { if (0) printf ("Cannot parse" " rebalance-filter (%s)" , temp_str); } while (0); _gf_log (this->name, "dht-shared.c" , __FUNCTION__, 539, GF_LOG_ERROR, "Cannot parse" " rebalance-filter (%s)" , temp_str); } while (0) |
539 | " rebalance-filter (%s)", temp_str)do { do { if (0) printf ("Cannot parse" " rebalance-filter (%s)" , temp_str); } while (0); _gf_log (this->name, "dht-shared.c" , __FUNCTION__, 539, GF_LOG_ERROR, "Cannot parse" " rebalance-filter (%s)" , temp_str); } while (0); |
540 | goto err; |
541 | } |
542 | } |
543 | } |
544 | |
545 | /* option can be any one of percent or bytes */ |
546 | conf->disk_unit = 0; |
547 | if (conf->min_free_disk < 100) |
548 | conf->disk_unit = 'p'; |
549 | |
550 | ret = dht_init_subvolumes (this, conf); |
551 | if (ret == -1) { |
552 | goto err; |
553 | } |
554 | |
555 | if (dict_get_str (this->options, "decommissioned-bricks", &temp_str) == 0) { |
556 | ret = dht_parse_decommissioned_bricks (this, conf, temp_str); |
557 | if (ret == -1) |
558 | goto err; |
559 | } |
560 | |
561 | dht_init_regex (this, this->options, "rsync-hash-regex", |
562 | &conf->rsync_regex, &conf->rsync_regex_valid); |
563 | dht_init_regex (this, this->options, "extra-hash-regex", |
564 | &conf->extra_regex, &conf->extra_regex_valid); |
565 | |
566 | ret = dht_layouts_init (this, conf); |
567 | if (ret == -1) { |
568 | goto err; |
569 | } |
570 | |
571 | LOCK_INIT (&conf->subvolume_lock)pthread_spin_init (&conf->subvolume_lock, 0); |
572 | LOCK_INIT (&conf->layout_lock)pthread_spin_init (&conf->layout_lock, 0); |
573 | |
574 | conf->gen = 1; |
575 | |
576 | this->local_pool = mem_pool_new (dht_local_t, 512)mem_pool_new_fn (sizeof(dht_local_t), 512, "dht_local_t"); |
577 | if (!this->local_pool) { |
578 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to create local_t's memory pool" ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 579, GF_LOG_ERROR, "failed to create local_t's memory pool" ); } while (0) |
579 | "failed to create local_t's memory pool")do { do { if (0) printf ("failed to create local_t's memory pool" ); } while (0); _gf_log (this->name, "dht-shared.c", __FUNCTION__ , 579, GF_LOG_ERROR, "failed to create local_t's memory pool" ); } while (0); |
580 | goto err; |
581 | } |
582 | |
583 | GF_OPTION_INIT ("xattr-name", conf->xattr_name, str, err)do { int val_ret = 0; val_ret = xlator_option_init_str ((*__glusterfs_this_location ()), (*__glusterfs_this_location())->options, "xattr-name" , &(conf->xattr_name)); if (val_ret) goto err; } while (0); |
584 | gf_asprintf (&conf->link_xattr_name, "%s.linkto", conf->xattr_name); |
585 | gf_asprintf (&conf->wild_xattr_name, "%s*", conf->xattr_name); |
586 | if (!conf->link_xattr_name || !conf->wild_xattr_name) { |
587 | goto err; |
588 | } |
589 | |
590 | this->private = conf; |
591 | |
592 | return 0; |
593 | |
594 | err: |
595 | if (conf) { |
596 | if (conf->file_layouts) { |
597 | for (i = 0; i < conf->subvolume_cnt; i++) { |
598 | GF_FREE (conf->file_layouts[i])__gf_free (conf->file_layouts[i]); |
599 | } |
600 | GF_FREE (conf->file_layouts)__gf_free (conf->file_layouts); |
601 | } |
602 | |
603 | GF_FREE (conf->subvolumes)__gf_free (conf->subvolumes); |
604 | |
605 | GF_FREE (conf->subvolume_status)__gf_free (conf->subvolume_status); |
606 | |
607 | GF_FREE (conf->du_stats)__gf_free (conf->du_stats); |
608 | |
609 | GF_FREE (conf->defrag)__gf_free (conf->defrag); |
610 | |
611 | GF_FREE (conf->xattr_name)__gf_free (conf->xattr_name); |
612 | GF_FREE (conf->link_xattr_name)__gf_free (conf->link_xattr_name); |
613 | GF_FREE (conf->wild_xattr_name)__gf_free (conf->wild_xattr_name); |
614 | |
615 | GF_FREE (conf)__gf_free (conf); |
616 | } |
617 | |
618 | return -1; |
619 | } |
620 | |
621 | |
622 | struct volume_options options[] = { |
623 | { .key = {"lookup-unhashed"}, |
624 | .value = {"auto", "yes", "no", "enable", "disable", "1", "0", |
625 | "on", "off"}, |
626 | .type = GF_OPTION_TYPE_STR, |
627 | .default_value = "on", |
628 | .description = "This option if set to ON, does a lookup through " |
629 | "all the sub-volumes, in case a lookup didn't return any result " |
630 | "from the hash subvolume. If set to OFF, it does not do a lookup " |
631 | "on the remaining subvolumes." |
632 | }, |
633 | { .key = {"min-free-disk"}, |
634 | .type = GF_OPTION_TYPE_PERCENT_OR_SIZET, |
635 | .default_value = "10%", |
636 | .description = "Percentage/Size of disk space, after which the " |
637 | "process starts balancing out the cluster, and logs will appear " |
638 | "in log files", |
639 | }, |
640 | { .key = {"min-free-inodes"}, |
641 | .type = GF_OPTION_TYPE_PERCENT, |
642 | .default_value = "5%", |
643 | .description = "after system has only N% of inodes, warnings " |
644 | "starts to appear in log files", |
645 | }, |
646 | { .key = {"unhashed-sticky-bit"}, |
647 | .type = GF_OPTION_TYPE_BOOL, |
648 | .default_value = "off", |
649 | }, |
650 | { .key = {"use-readdirp"}, |
651 | .type = GF_OPTION_TYPE_BOOL, |
652 | .default_value = "on", |
653 | .description = "This option if set to ON, forces the use of " |
654 | "readdirp, and hence also displays the stats of the files." |
655 | }, |
656 | { .key = {"assert-no-child-down"}, |
657 | .type = GF_OPTION_TYPE_BOOL, |
658 | .default_value = "off", |
659 | .description = "This option if set to ON, in the event of " |
660 | "CHILD_DOWN, will call exit." |
661 | }, |
662 | { .key = {"directory-layout-spread"}, |
663 | .type = GF_OPTION_TYPE_INT, |
664 | .min = 1, |
665 | .validate = GF_OPT_VALIDATE_MIN, |
666 | .description = "Specifies the directory layout spread." |
667 | }, |
668 | { .key = {"decommissioned-bricks"}, |
669 | .type = GF_OPTION_TYPE_ANY, |
670 | .description = "This option if set to ON, decommissions " |
671 | "the brick, so that no new data is allowed to be created " |
672 | "on that brick." |
673 | }, |
674 | { .key = {"rebalance-cmd"}, |
675 | .type = GF_OPTION_TYPE_INT, |
676 | }, |
677 | { .key = {"node-uuid"}, |
678 | .type = GF_OPTION_TYPE_STR, |
679 | }, |
680 | { .key = {"rebalance-stats"}, |
681 | .type = GF_OPTION_TYPE_BOOL, |
682 | .default_value = "off", |
683 | .description = "This option if set to ON displays and logs the " |
684 | " time taken for migration of each file, during the rebalance " |
685 | "process. If set to OFF, the rebalance logs will only display the " |
686 | "time spent in each directory." |
687 | }, |
688 | { .key = {"readdir-optimize"}, |
689 | .type = GF_OPTION_TYPE_BOOL, |
690 | .default_value = "off", |
691 | .description = "This option if set to ON enables the optimization " |
692 | "that allows DHT to requests non-first subvolumes to filter out " |
693 | "directory entries." |
694 | }, |
695 | { .key = {"rsync-hash-regex"}, |
696 | .type = GF_OPTION_TYPE_STR, |
697 | /* Setting a default here doesn't work. See dht_init_regex. */ |
698 | .description = "Regular expression for stripping temporary-file " |
699 | "suffix and prefix used by rsync, to prevent relocation when the " |
700 | "file is renamed." |
701 | }, |
702 | { .key = {"extra-hash-regex"}, |
703 | .type = GF_OPTION_TYPE_STR, |
704 | /* Setting a default here doesn't work. See dht_init_regex. */ |
705 | .description = "Regular expression for stripping temporary-file " |
706 | "suffix and prefix used by an application, to prevent relocation when " |
707 | "the file is renamed." |
708 | }, |
709 | { .key = {"rebalance-filter"}, |
710 | .type = GF_OPTION_TYPE_STR, |
711 | }, |
712 | |
713 | { .key = {"xattr-name"}, |
714 | .type = GF_OPTION_TYPE_STR, |
715 | .default_value = "trusted.glusterfs.dht", |
716 | .description = "Base for extended attributes used by this " |
717 | "translator instance, to avoid conflicts with others above or " |
718 | "below it." |
719 | }, |
720 | |
721 | /* NUFA option */ |
722 | { .key = {"local-volume-name"}, |
723 | .type = GF_OPTION_TYPE_XLATOR |
724 | }, |
725 | |
726 | /* switch option */ |
727 | { .key = {"pattern.switch.case"}, |
728 | .type = GF_OPTION_TYPE_ANY |
729 | }, |
730 | |
731 | { .key = {NULL((void*)0)} }, |
732 | }; |