File: | libglusterfs/src/xlator.c |
Location: | line 128, column 13 |
Description: | Dereference of null pointer (loaded from variable 'dl_handle') |
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 | #ifndef _CONFIG_H | |||||
12 | #define _CONFIG_H | |||||
13 | #include "config.h" | |||||
14 | #endif | |||||
15 | ||||||
16 | #include "xlator.h" | |||||
17 | #include <dlfcn.h> | |||||
18 | #include <netdb.h> | |||||
19 | #include <fnmatch.h> | |||||
20 | #include "defaults.h" | |||||
21 | ||||||
22 | #define SET_DEFAULT_FOP(fn)do { if (!xl->fops->fn) xl->fops->fn = default_fn ; } while (0) do { \ | |||||
23 | if (!xl->fops->fn) \ | |||||
24 | xl->fops->fn = default_##fn; \ | |||||
25 | } while (0) | |||||
26 | ||||||
27 | #define SET_DEFAULT_CBK(fn)do { if (!xl->cbks->fn) xl->cbks->fn = default_fn ; } while (0) do { \ | |||||
28 | if (!xl->cbks->fn) \ | |||||
29 | xl->cbks->fn = default_##fn; \ | |||||
30 | } while (0) | |||||
31 | ||||||
32 | ||||||
33 | static void | |||||
34 | fill_defaults (xlator_t *xl) | |||||
35 | { | |||||
36 | if (xl == NULL((void*)0)) { | |||||
37 | gf_log_callingfn ("xlator", GF_LOG_WARNING, "invalid argument")do { do { if (0) printf ("invalid argument"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 37, GF_LOG_WARNING, "invalid argument" ); } while (0); | |||||
38 | return; | |||||
39 | } | |||||
40 | ||||||
41 | SET_DEFAULT_FOP (create)do { if (!xl->fops->create) xl->fops->create = default_create ; } while (0); | |||||
42 | SET_DEFAULT_FOP (open)do { if (!xl->fops->open) xl->fops->open = default_open ; } while (0); | |||||
43 | SET_DEFAULT_FOP (stat)do { if (!xl->fops->stat) xl->fops->stat = default_stat ; } while (0); | |||||
44 | SET_DEFAULT_FOP (readlink)do { if (!xl->fops->readlink) xl->fops->readlink = default_readlink; } while (0); | |||||
45 | SET_DEFAULT_FOP (mknod)do { if (!xl->fops->mknod) xl->fops->mknod = default_mknod ; } while (0); | |||||
46 | SET_DEFAULT_FOP (mkdir)do { if (!xl->fops->mkdir) xl->fops->mkdir = default_mkdir ; } while (0); | |||||
47 | SET_DEFAULT_FOP (unlink)do { if (!xl->fops->unlink) xl->fops->unlink = default_unlink ; } while (0); | |||||
48 | SET_DEFAULT_FOP (rmdir)do { if (!xl->fops->rmdir) xl->fops->rmdir = default_rmdir ; } while (0); | |||||
49 | SET_DEFAULT_FOP (symlink)do { if (!xl->fops->symlink) xl->fops->symlink = default_symlink ; } while (0); | |||||
50 | SET_DEFAULT_FOP (rename)do { if (!xl->fops->rename) xl->fops->rename = default_rename ; } while (0); | |||||
51 | SET_DEFAULT_FOP (link)do { if (!xl->fops->link) xl->fops->link = default_link ; } while (0); | |||||
52 | SET_DEFAULT_FOP (truncate)do { if (!xl->fops->truncate) xl->fops->truncate = default_truncate; } while (0); | |||||
53 | SET_DEFAULT_FOP (readv)do { if (!xl->fops->readv) xl->fops->readv = default_readv ; } while (0); | |||||
54 | SET_DEFAULT_FOP (writev)do { if (!xl->fops->writev) xl->fops->writev = default_writev ; } while (0); | |||||
55 | SET_DEFAULT_FOP (statfs)do { if (!xl->fops->statfs) xl->fops->statfs = default_statfs ; } while (0); | |||||
56 | SET_DEFAULT_FOP (flush)do { if (!xl->fops->flush) xl->fops->flush = default_flush ; } while (0); | |||||
57 | SET_DEFAULT_FOP (fsync)do { if (!xl->fops->fsync) xl->fops->fsync = default_fsync ; } while (0); | |||||
58 | SET_DEFAULT_FOP (setxattr)do { if (!xl->fops->setxattr) xl->fops->setxattr = default_setxattr; } while (0); | |||||
59 | SET_DEFAULT_FOP (getxattr)do { if (!xl->fops->getxattr) xl->fops->getxattr = default_getxattr; } while (0); | |||||
60 | SET_DEFAULT_FOP (fsetxattr)do { if (!xl->fops->fsetxattr) xl->fops->fsetxattr = default_fsetxattr; } while (0); | |||||
61 | SET_DEFAULT_FOP (fgetxattr)do { if (!xl->fops->fgetxattr) xl->fops->fgetxattr = default_fgetxattr; } while (0); | |||||
62 | SET_DEFAULT_FOP (removexattr)do { if (!xl->fops->removexattr) xl->fops->removexattr = default_removexattr; } while (0); | |||||
63 | SET_DEFAULT_FOP (fremovexattr)do { if (!xl->fops->fremovexattr) xl->fops->fremovexattr = default_fremovexattr; } while (0); | |||||
64 | SET_DEFAULT_FOP (opendir)do { if (!xl->fops->opendir) xl->fops->opendir = default_opendir ; } while (0); | |||||
65 | SET_DEFAULT_FOP (readdir)do { if (!xl->fops->readdir) xl->fops->readdir = default_readdir ; } while (0); | |||||
66 | SET_DEFAULT_FOP (readdirp)do { if (!xl->fops->readdirp) xl->fops->readdirp = default_readdirp; } while (0); | |||||
67 | SET_DEFAULT_FOP (fsyncdir)do { if (!xl->fops->fsyncdir) xl->fops->fsyncdir = default_fsyncdir; } while (0); | |||||
68 | SET_DEFAULT_FOP (access)do { if (!xl->fops->access) xl->fops->access = default_access ; } while (0); | |||||
69 | SET_DEFAULT_FOP (ftruncate)do { if (!xl->fops->ftruncate) xl->fops->ftruncate = default_ftruncate; } while (0); | |||||
70 | SET_DEFAULT_FOP (fstat)do { if (!xl->fops->fstat) xl->fops->fstat = default_fstat ; } while (0); | |||||
71 | SET_DEFAULT_FOP (lk)do { if (!xl->fops->lk) xl->fops->lk = default_lk ; } while (0); | |||||
72 | SET_DEFAULT_FOP (inodelk)do { if (!xl->fops->inodelk) xl->fops->inodelk = default_inodelk ; } while (0); | |||||
73 | SET_DEFAULT_FOP (finodelk)do { if (!xl->fops->finodelk) xl->fops->finodelk = default_finodelk; } while (0); | |||||
74 | SET_DEFAULT_FOP (entrylk)do { if (!xl->fops->entrylk) xl->fops->entrylk = default_entrylk ; } while (0); | |||||
75 | SET_DEFAULT_FOP (fentrylk)do { if (!xl->fops->fentrylk) xl->fops->fentrylk = default_fentrylk; } while (0); | |||||
76 | SET_DEFAULT_FOP (lookup)do { if (!xl->fops->lookup) xl->fops->lookup = default_lookup ; } while (0); | |||||
77 | SET_DEFAULT_FOP (rchecksum)do { if (!xl->fops->rchecksum) xl->fops->rchecksum = default_rchecksum; } while (0); | |||||
78 | SET_DEFAULT_FOP (xattrop)do { if (!xl->fops->xattrop) xl->fops->xattrop = default_xattrop ; } while (0); | |||||
79 | SET_DEFAULT_FOP (fxattrop)do { if (!xl->fops->fxattrop) xl->fops->fxattrop = default_fxattrop; } while (0); | |||||
80 | SET_DEFAULT_FOP (setattr)do { if (!xl->fops->setattr) xl->fops->setattr = default_setattr ; } while (0); | |||||
81 | SET_DEFAULT_FOP (fsetattr)do { if (!xl->fops->fsetattr) xl->fops->fsetattr = default_fsetattr; } while (0); | |||||
82 | ||||||
83 | SET_DEFAULT_FOP (getspec)do { if (!xl->fops->getspec) xl->fops->getspec = default_getspec ; } while (0); | |||||
84 | ||||||
85 | SET_DEFAULT_CBK (release)do { if (!xl->cbks->release) xl->cbks->release = default_release ; } while (0); | |||||
86 | SET_DEFAULT_CBK (releasedir)do { if (!xl->cbks->releasedir) xl->cbks->releasedir = default_releasedir; } while (0); | |||||
87 | SET_DEFAULT_CBK (forget)do { if (!xl->cbks->forget) xl->cbks->forget = default_forget ; } while (0); | |||||
88 | ||||||
89 | if (!xl->notify) | |||||
90 | xl->notify = default_notify; | |||||
91 | ||||||
92 | if (!xl->mem_acct_init) | |||||
93 | xl->mem_acct_init = default_mem_acct_init; | |||||
94 | ||||||
95 | return; | |||||
96 | } | |||||
97 | ||||||
98 | ||||||
99 | int | |||||
100 | xlator_set_type_virtual (xlator_t *xl, const char *type) | |||||
101 | { | |||||
102 | GF_VALIDATE_OR_GOTO ("xlator", xl, out)do { if (!xl) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "xl"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 102, GF_LOG_ERROR, "invalid argument: " "xl"); } while (0); goto out; } } while (0); | |||||
103 | GF_VALIDATE_OR_GOTO ("xlator", type, out)do { if (!type) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "type"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 103, GF_LOG_ERROR, "invalid argument: " "type"); } while (0); goto out; } } while (0); | |||||
104 | ||||||
105 | xl->type = gf_strdup (type); | |||||
106 | ||||||
107 | if (xl->type) | |||||
108 | return 0; | |||||
109 | ||||||
110 | out: | |||||
111 | return -1; | |||||
112 | } | |||||
113 | ||||||
114 | ||||||
115 | int | |||||
116 | xlator_volopt_dynload (char *xlator_type, void **dl_handle, | |||||
117 | volume_opt_list_t *opt_list) | |||||
118 | { | |||||
119 | int ret = -1; | |||||
120 | char *name = NULL((void*)0); | |||||
121 | void *handle = NULL((void*)0); | |||||
122 | volume_opt_list_t *vol_opt = NULL((void*)0); | |||||
123 | ||||||
124 | GF_VALIDATE_OR_GOTO ("xlator", xlator_type, out)do { if (!xlator_type) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "xlator_type"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 124 , GF_LOG_ERROR, "invalid argument: " "xlator_type"); } while ( 0); goto out; } } while (0); | |||||
125 | ||||||
126 | GF_ASSERT (dl_handle)do { if (!(dl_handle)) { do { do { if (0) printf ("Assertion failed: " "dl_handle"); } while (0); _gf_log_callingfn ("", "xlator.c" , __FUNCTION__, 126, GF_LOG_ERROR, "Assertion failed: " "dl_handle" ); } while (0); } } while (0); | |||||
| ||||||
127 | ||||||
128 | if (*dl_handle) | |||||
| ||||||
129 | if (dlclose (*dl_handle)) | |||||
130 | gf_log ("xlator", GF_LOG_WARNING, "Unable to close "do { do { if (0) printf ("Unable to close " "previously opened handle( may be stale)." "Ignoring the invalid handle"); } while (0); _gf_log ("xlator" , "xlator.c", __FUNCTION__, 132, GF_LOG_WARNING, "Unable to close " "previously opened handle( may be stale)." "Ignoring the invalid handle" ); } while (0) | |||||
131 | "previously opened handle( may be stale)."do { do { if (0) printf ("Unable to close " "previously opened handle( may be stale)." "Ignoring the invalid handle"); } while (0); _gf_log ("xlator" , "xlator.c", __FUNCTION__, 132, GF_LOG_WARNING, "Unable to close " "previously opened handle( may be stale)." "Ignoring the invalid handle" ); } while (0) | |||||
132 | "Ignoring the invalid handle")do { do { if (0) printf ("Unable to close " "previously opened handle( may be stale)." "Ignoring the invalid handle"); } while (0); _gf_log ("xlator" , "xlator.c", __FUNCTION__, 132, GF_LOG_WARNING, "Unable to close " "previously opened handle( may be stale)." "Ignoring the invalid handle" ); } while (0); | |||||
133 | ||||||
134 | ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR"/usr/local/lib/glusterfs/3git/xlator", xlator_type); | |||||
135 | if (-1 == ret) { | |||||
136 | gf_log ("xlator", GF_LOG_ERROR, "asprintf failed")do { do { if (0) printf ("asprintf failed"); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 136, GF_LOG_ERROR, "asprintf failed" ); } while (0); | |||||
137 | goto out; | |||||
138 | } | |||||
139 | ||||||
140 | ret = -1; | |||||
141 | ||||||
142 | gf_log ("xlator", GF_LOG_TRACE, "attempt to load file %s", name)do { do { if (0) printf ("attempt to load file %s", name); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 142, GF_LOG_TRACE , "attempt to load file %s", name); } while (0); | |||||
143 | ||||||
144 | handle = dlopen (name, RTLD_NOW0x00002|RTLD_GLOBAL0x00100); | |||||
145 | if (!handle) { | |||||
146 | gf_log ("xlator", GF_LOG_WARNING, "%s", dlerror ())do { do { if (0) printf ("%s", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 146, GF_LOG_WARNING, "%s" , dlerror ()); } while (0); | |||||
147 | goto out; | |||||
148 | } | |||||
149 | *dl_handle = handle; | |||||
150 | ||||||
151 | ||||||
152 | vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),__gf_calloc (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t ) | |||||
153 | gf_common_mt_volume_opt_list_t)__gf_calloc (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t ); | |||||
154 | ||||||
155 | if (!vol_opt) { | |||||
156 | goto out; | |||||
157 | } | |||||
158 | ||||||
159 | if (!(vol_opt->given_opt = dlsym (handle, "options"))) { | |||||
160 | dlerror (); | |||||
161 | gf_log ("xlator", GF_LOG_DEBUG,do { do { if (0) printf ("Strict option validation not enforced -- neglecting" ); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 162 , GF_LOG_DEBUG, "Strict option validation not enforced -- neglecting" ); } while (0) | |||||
162 | "Strict option validation not enforced -- neglecting")do { do { if (0) printf ("Strict option validation not enforced -- neglecting" ); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 162 , GF_LOG_DEBUG, "Strict option validation not enforced -- neglecting" ); } while (0); | |||||
163 | } | |||||
164 | opt_list->given_opt = vol_opt->given_opt; | |||||
165 | ||||||
166 | INIT_LIST_HEAD (&vol_opt->list)do { (&vol_opt->list)->next = (&vol_opt->list )->prev = &vol_opt->list; } while (0); | |||||
167 | list_add_tail (&vol_opt->list, &opt_list->list); | |||||
168 | ||||||
169 | ret = 0; | |||||
170 | out: | |||||
171 | GF_FREE (name)__gf_free (name); | |||||
172 | ||||||
173 | gf_log ("xlator", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 173, GF_LOG_DEBUG, "Returning %d" , ret); } while (0); | |||||
174 | return ret; | |||||
175 | ||||||
176 | } | |||||
177 | ||||||
178 | ||||||
179 | int | |||||
180 | xlator_dynload (xlator_t *xl) | |||||
181 | { | |||||
182 | int ret = -1; | |||||
183 | char *name = NULL((void*)0); | |||||
184 | void *handle = NULL((void*)0); | |||||
185 | volume_opt_list_t *vol_opt = NULL((void*)0); | |||||
186 | class_methods_t *vtbl = NULL((void*)0); | |||||
187 | ||||||
188 | GF_VALIDATE_OR_GOTO ("xlator", xl, out)do { if (!xl) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "xl"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 188, GF_LOG_ERROR, "invalid argument: " "xl"); } while (0); goto out; } } while (0); | |||||
189 | ||||||
190 | INIT_LIST_HEAD (&xl->volume_options)do { (&xl->volume_options)->next = (&xl->volume_options )->prev = &xl->volume_options; } while (0); | |||||
191 | ||||||
192 | ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR"/usr/local/lib/glusterfs/3git/xlator", xl->type); | |||||
193 | if (-1 == ret) { | |||||
194 | gf_log ("xlator", GF_LOG_ERROR, "asprintf failed")do { do { if (0) printf ("asprintf failed"); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 194, GF_LOG_ERROR, "asprintf failed" ); } while (0); | |||||
195 | goto out; | |||||
196 | } | |||||
197 | ||||||
198 | ret = -1; | |||||
199 | ||||||
200 | gf_log ("xlator", GF_LOG_TRACE, "attempt to load file %s", name)do { do { if (0) printf ("attempt to load file %s", name); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 200, GF_LOG_TRACE , "attempt to load file %s", name); } while (0); | |||||
201 | ||||||
202 | handle = dlopen (name, RTLD_NOW0x00002|RTLD_GLOBAL0x00100); | |||||
203 | if (!handle) { | |||||
204 | gf_log ("xlator", GF_LOG_WARNING, "%s", dlerror ())do { do { if (0) printf ("%s", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 204, GF_LOG_WARNING, "%s" , dlerror ()); } while (0); | |||||
205 | goto out; | |||||
206 | } | |||||
207 | xl->dlhandle = handle; | |||||
208 | ||||||
209 | if (!(xl->fops = dlsym (handle, "fops"))) { | |||||
210 | gf_log ("xlator", GF_LOG_WARNING, "dlsym(fops) on %s",do { do { if (0) printf ("dlsym(fops) on %s", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 211, GF_LOG_WARNING , "dlsym(fops) on %s", dlerror ()); } while (0) | |||||
211 | dlerror ())do { do { if (0) printf ("dlsym(fops) on %s", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 211, GF_LOG_WARNING , "dlsym(fops) on %s", dlerror ()); } while (0); | |||||
212 | goto out; | |||||
213 | } | |||||
214 | ||||||
215 | if (!(xl->cbks = dlsym (handle, "cbks"))) { | |||||
216 | gf_log ("xlator", GF_LOG_WARNING, "dlsym(cbks) on %s",do { do { if (0) printf ("dlsym(cbks) on %s", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 217, GF_LOG_WARNING , "dlsym(cbks) on %s", dlerror ()); } while (0) | |||||
217 | dlerror ())do { do { if (0) printf ("dlsym(cbks) on %s", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 217, GF_LOG_WARNING , "dlsym(cbks) on %s", dlerror ()); } while (0); | |||||
218 | goto out; | |||||
219 | } | |||||
220 | ||||||
221 | /* | |||||
222 | * If class_methods exists, its contents override any definitions of | |||||
223 | * init or fini for that translator. Otherwise, we fall back to the | |||||
224 | * older method of looking for init and fini directly. | |||||
225 | */ | |||||
226 | vtbl = dlsym(handle,"class_methods"); | |||||
227 | if (vtbl) { | |||||
228 | xl->init = vtbl->init; | |||||
229 | xl->fini = vtbl->fini; | |||||
230 | xl->reconfigure = vtbl->reconfigure; | |||||
231 | xl->notify = vtbl->notify; | |||||
232 | } | |||||
233 | else { | |||||
234 | if (!(*VOID(&xl->init)((void **) ((void *) &xl->init)) = dlsym (handle, "init"))) { | |||||
235 | gf_log ("xlator", GF_LOG_WARNING, "dlsym(init) on %s",do { do { if (0) printf ("dlsym(init) on %s", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 236, GF_LOG_WARNING , "dlsym(init) on %s", dlerror ()); } while (0) | |||||
236 | dlerror ())do { do { if (0) printf ("dlsym(init) on %s", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 236, GF_LOG_WARNING , "dlsym(init) on %s", dlerror ()); } while (0); | |||||
237 | goto out; | |||||
238 | } | |||||
239 | ||||||
240 | if (!(*VOID(&(xl->fini))((void **) ((void *) &(xl->fini))) = dlsym (handle, "fini"))) { | |||||
241 | gf_log ("xlator", GF_LOG_WARNING, "dlsym(fini) on %s",do { do { if (0) printf ("dlsym(fini) on %s", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 242, GF_LOG_WARNING , "dlsym(fini) on %s", dlerror ()); } while (0) | |||||
242 | dlerror ())do { do { if (0) printf ("dlsym(fini) on %s", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__, 242, GF_LOG_WARNING , "dlsym(fini) on %s", dlerror ()); } while (0); | |||||
243 | goto out; | |||||
244 | } | |||||
245 | if (!(*VOID(&(xl->reconfigure))((void **) ((void *) &(xl->reconfigure))) = dlsym (handle, | |||||
246 | "reconfigure"))) { | |||||
247 | gf_log ("xlator", GF_LOG_TRACE,do { do { if (0) printf ("dlsym(reconfigure) on %s -- neglecting" , dlerror()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__ , 249, GF_LOG_TRACE, "dlsym(reconfigure) on %s -- neglecting" , dlerror()); } while (0) | |||||
248 | "dlsym(reconfigure) on %s -- neglecting",do { do { if (0) printf ("dlsym(reconfigure) on %s -- neglecting" , dlerror()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__ , 249, GF_LOG_TRACE, "dlsym(reconfigure) on %s -- neglecting" , dlerror()); } while (0) | |||||
249 | dlerror())do { do { if (0) printf ("dlsym(reconfigure) on %s -- neglecting" , dlerror()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__ , 249, GF_LOG_TRACE, "dlsym(reconfigure) on %s -- neglecting" , dlerror()); } while (0); | |||||
250 | } | |||||
251 | if (!(*VOID(&(xl->notify))((void **) ((void *) &(xl->notify))) = dlsym (handle, "notify"))) { | |||||
252 | gf_log ("xlator", GF_LOG_TRACE,do { do { if (0) printf ("dlsym(notify) on %s -- neglecting", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__ , 254, GF_LOG_TRACE, "dlsym(notify) on %s -- neglecting", dlerror ()); } while (0) | |||||
253 | "dlsym(notify) on %s -- neglecting",do { do { if (0) printf ("dlsym(notify) on %s -- neglecting", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__ , 254, GF_LOG_TRACE, "dlsym(notify) on %s -- neglecting", dlerror ()); } while (0) | |||||
254 | dlerror ())do { do { if (0) printf ("dlsym(notify) on %s -- neglecting", dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__ , 254, GF_LOG_TRACE, "dlsym(notify) on %s -- neglecting", dlerror ()); } while (0); | |||||
255 | } | |||||
256 | ||||||
257 | } | |||||
258 | ||||||
259 | if (!(xl->dumpops = dlsym (handle, "dumpops"))) { | |||||
260 | gf_log ("xlator", GF_LOG_TRACE,do { do { if (0) printf ("dlsym(dumpops) on %s -- neglecting" , dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__ , 261, GF_LOG_TRACE, "dlsym(dumpops) on %s -- neglecting", dlerror ()); } while (0) | |||||
261 | "dlsym(dumpops) on %s -- neglecting", dlerror ())do { do { if (0) printf ("dlsym(dumpops) on %s -- neglecting" , dlerror ()); } while (0); _gf_log ("xlator", "xlator.c", __FUNCTION__ , 261, GF_LOG_TRACE, "dlsym(dumpops) on %s -- neglecting", dlerror ()); } while (0); | |||||
262 | } | |||||
263 | ||||||
264 | if (!(*VOID(&(xl->mem_acct_init))((void **) ((void *) &(xl->mem_acct_init))) = dlsym (handle, "mem_acct_init"))) { | |||||
265 | gf_log (xl->name, GF_LOG_TRACE,do { do { if (0) printf ("dlsym(mem_acct_init) on %s -- neglecting" , dlerror ()); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__, 267, GF_LOG_TRACE, "dlsym(mem_acct_init) on %s -- neglecting" , dlerror ()); } while (0) | |||||
266 | "dlsym(mem_acct_init) on %s -- neglecting",do { do { if (0) printf ("dlsym(mem_acct_init) on %s -- neglecting" , dlerror ()); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__, 267, GF_LOG_TRACE, "dlsym(mem_acct_init) on %s -- neglecting" , dlerror ()); } while (0) | |||||
267 | dlerror ())do { do { if (0) printf ("dlsym(mem_acct_init) on %s -- neglecting" , dlerror ()); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__, 267, GF_LOG_TRACE, "dlsym(mem_acct_init) on %s -- neglecting" , dlerror ()); } while (0); | |||||
268 | } | |||||
269 | ||||||
270 | vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),__gf_calloc (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t ) | |||||
271 | gf_common_mt_volume_opt_list_t)__gf_calloc (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t ); | |||||
272 | ||||||
273 | if (!vol_opt) { | |||||
274 | goto out; | |||||
275 | } | |||||
276 | ||||||
277 | if (!(vol_opt->given_opt = dlsym (handle, "options"))) { | |||||
278 | dlerror (); | |||||
279 | gf_log (xl->name, GF_LOG_TRACE,do { do { if (0) printf ("Strict option validation not enforced -- neglecting" ); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__ , 280, GF_LOG_TRACE, "Strict option validation not enforced -- neglecting" ); } while (0) | |||||
280 | "Strict option validation not enforced -- neglecting")do { do { if (0) printf ("Strict option validation not enforced -- neglecting" ); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__ , 280, GF_LOG_TRACE, "Strict option validation not enforced -- neglecting" ); } while (0); | |||||
281 | } | |||||
282 | INIT_LIST_HEAD (&vol_opt->list)do { (&vol_opt->list)->next = (&vol_opt->list )->prev = &vol_opt->list; } while (0); | |||||
283 | list_add_tail (&vol_opt->list, &xl->volume_options); | |||||
284 | ||||||
285 | fill_defaults (xl); | |||||
286 | ||||||
287 | ret = 0; | |||||
288 | ||||||
289 | out: | |||||
290 | GF_FREE (name)__gf_free (name); | |||||
291 | return ret; | |||||
292 | } | |||||
293 | ||||||
294 | ||||||
295 | int | |||||
296 | xlator_set_type (xlator_t *xl, const char *type) | |||||
297 | { | |||||
298 | int ret = 0; | |||||
299 | ||||||
300 | ret = xlator_set_type_virtual (xl, type); | |||||
301 | if (!ret) | |||||
302 | ret = xlator_dynload (xl); | |||||
303 | ||||||
304 | return ret; | |||||
305 | } | |||||
306 | ||||||
307 | ||||||
308 | void | |||||
309 | xlator_foreach (xlator_t *this, | |||||
310 | void (*fn)(xlator_t *each, | |||||
311 | void *data), | |||||
312 | void *data) | |||||
313 | { | |||||
314 | xlator_t *first = NULL((void*)0); | |||||
315 | xlator_t *old_THIS = NULL((void*)0); | |||||
316 | ||||||
317 | GF_VALIDATE_OR_GOTO ("xlator", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 317, GF_LOG_ERROR, "invalid argument: " "this"); } while (0); goto out; } } while (0); | |||||
318 | GF_VALIDATE_OR_GOTO ("xlator", fn, out)do { if (!fn) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "fn"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 318, GF_LOG_ERROR, "invalid argument: " "fn"); } while (0); goto out; } } while (0); | |||||
319 | ||||||
320 | first = this; | |||||
321 | ||||||
322 | while (first->prev) | |||||
323 | first = first->prev; | |||||
324 | ||||||
325 | while (first) { | |||||
326 | old_THIS = THIS(*__glusterfs_this_location()); | |||||
327 | THIS(*__glusterfs_this_location()) = first; | |||||
328 | ||||||
329 | fn (first, data); | |||||
330 | ||||||
331 | THIS(*__glusterfs_this_location()) = old_THIS; | |||||
332 | first = first->next; | |||||
333 | } | |||||
334 | ||||||
335 | out: | |||||
336 | return; | |||||
337 | } | |||||
338 | ||||||
339 | ||||||
340 | void | |||||
341 | xlator_foreach_depth_first (xlator_t *this, | |||||
342 | void (*fn)(xlator_t *each, void *data), | |||||
343 | void *data) | |||||
344 | { | |||||
345 | xlator_list_t *subv = NULL((void*)0); | |||||
346 | ||||||
347 | subv = this->children; | |||||
348 | ||||||
349 | while (subv) { | |||||
350 | xlator_foreach_depth_first (subv->xlator, fn, data); | |||||
351 | subv = subv->next; | |||||
352 | } | |||||
353 | ||||||
354 | fn (this, data); | |||||
355 | } | |||||
356 | ||||||
357 | ||||||
358 | xlator_t * | |||||
359 | xlator_search_by_name (xlator_t *any, const char *name) | |||||
360 | { | |||||
361 | xlator_t *search = NULL((void*)0); | |||||
362 | ||||||
363 | GF_VALIDATE_OR_GOTO ("xlator", any, out)do { if (!any) { (*__errno_location ()) = 22; do { do { if (0 ) printf ("invalid argument: " "any"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 363, GF_LOG_ERROR, "invalid argument: " "any"); } while (0); goto out; } } while (0); | |||||
364 | GF_VALIDATE_OR_GOTO ("xlator", name, out)do { if (!name) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "name"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 364, GF_LOG_ERROR, "invalid argument: " "name"); } while (0); goto out; } } while (0); | |||||
365 | ||||||
366 | search = any; | |||||
367 | ||||||
368 | while (search->prev) | |||||
369 | search = search->prev; | |||||
370 | ||||||
371 | while (search) { | |||||
372 | if (!strcmp (search->name, name)) | |||||
373 | break; | |||||
374 | search = search->next; | |||||
375 | } | |||||
376 | ||||||
377 | out: | |||||
378 | return search; | |||||
379 | } | |||||
380 | ||||||
381 | xlator_t * | |||||
382 | xlator_search_by_xl_type (xlator_t *any, const char *type) | |||||
383 | { | |||||
384 | xlator_t *search = NULL((void*)0); | |||||
385 | ||||||
386 | GF_VALIDATE_OR_GOTO ("xlator", any, out)do { if (!any) { (*__errno_location ()) = 22; do { do { if (0 ) printf ("invalid argument: " "any"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 386, GF_LOG_ERROR, "invalid argument: " "any"); } while (0); goto out; } } while (0); | |||||
387 | GF_VALIDATE_OR_GOTO ("xlator", type, out)do { if (!type) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "type"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 387, GF_LOG_ERROR, "invalid argument: " "type"); } while (0); goto out; } } while (0); | |||||
388 | ||||||
389 | search = any; | |||||
390 | ||||||
391 | while (search->prev) | |||||
392 | search = search->prev; | |||||
393 | ||||||
394 | while (search) { | |||||
395 | if (!strcmp (search->type, type)) | |||||
396 | break; | |||||
397 | search = search->next; | |||||
398 | } | |||||
399 | ||||||
400 | out: | |||||
401 | return search; | |||||
402 | } | |||||
403 | ||||||
404 | static int | |||||
405 | __xlator_init(xlator_t *xl) | |||||
406 | { | |||||
407 | xlator_t *old_THIS = NULL((void*)0); | |||||
408 | int ret = 0; | |||||
409 | ||||||
410 | old_THIS = THIS(*__glusterfs_this_location()); | |||||
411 | THIS(*__glusterfs_this_location()) = xl; | |||||
412 | ||||||
413 | ret = xl->init (xl); | |||||
414 | ||||||
415 | THIS(*__glusterfs_this_location()) = old_THIS; | |||||
416 | ||||||
417 | return ret; | |||||
418 | } | |||||
419 | ||||||
420 | ||||||
421 | int | |||||
422 | xlator_init (xlator_t *xl) | |||||
423 | { | |||||
424 | int32_t ret = -1; | |||||
425 | ||||||
426 | GF_VALIDATE_OR_GOTO ("xlator", xl, out)do { if (!xl) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "xl"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 426, GF_LOG_ERROR, "invalid argument: " "xl"); } while (0); goto out; } } while (0); | |||||
427 | ||||||
428 | if (xl->mem_acct_init) | |||||
429 | xl->mem_acct_init (xl); | |||||
430 | ||||||
431 | if (!xl->init) { | |||||
432 | gf_log (xl->name, GF_LOG_WARNING, "No init() found")do { do { if (0) printf ("No init() found"); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__, 432, GF_LOG_WARNING, "No init() found"); } while (0); | |||||
433 | goto out; | |||||
434 | } | |||||
435 | ||||||
436 | ret = __xlator_init (xl); | |||||
437 | ||||||
438 | if (ret) { | |||||
439 | gf_log (xl->name, GF_LOG_ERROR,do { do { if (0) printf ("Initialization of volume '%s' failed," " review your volfile again", xl->name); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__, 442, GF_LOG_ERROR, "Initialization of volume '%s' failed," " review your volfile again", xl->name); } while (0) | |||||
440 | "Initialization of volume '%s' failed,"do { do { if (0) printf ("Initialization of volume '%s' failed," " review your volfile again", xl->name); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__, 442, GF_LOG_ERROR, "Initialization of volume '%s' failed," " review your volfile again", xl->name); } while (0) | |||||
441 | " review your volfile again",do { do { if (0) printf ("Initialization of volume '%s' failed," " review your volfile again", xl->name); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__, 442, GF_LOG_ERROR, "Initialization of volume '%s' failed," " review your volfile again", xl->name); } while (0) | |||||
442 | xl->name)do { do { if (0) printf ("Initialization of volume '%s' failed," " review your volfile again", xl->name); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__, 442, GF_LOG_ERROR, "Initialization of volume '%s' failed," " review your volfile again", xl->name); } while (0); | |||||
443 | goto out; | |||||
444 | } | |||||
445 | ||||||
446 | xl->init_succeeded = 1; | |||||
447 | ||||||
448 | ret = 0; | |||||
449 | out: | |||||
450 | return ret; | |||||
451 | } | |||||
452 | ||||||
453 | ||||||
454 | static void | |||||
455 | xlator_fini_rec (xlator_t *xl) | |||||
456 | { | |||||
457 | xlator_list_t *trav = NULL((void*)0); | |||||
458 | xlator_t *old_THIS = NULL((void*)0); | |||||
459 | ||||||
460 | GF_VALIDATE_OR_GOTO ("xlator", xl, out)do { if (!xl) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "xl"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 460, GF_LOG_ERROR, "invalid argument: " "xl"); } while (0); goto out; } } while (0); | |||||
461 | ||||||
462 | trav = xl->children; | |||||
463 | ||||||
464 | while (trav) { | |||||
465 | if (!trav->xlator->init_succeeded) { | |||||
466 | break; | |||||
467 | } | |||||
468 | ||||||
469 | xlator_fini_rec (trav->xlator); | |||||
470 | gf_log (trav->xlator->name, GF_LOG_DEBUG, "fini done")do { do { if (0) printf ("fini done"); } while (0); _gf_log ( trav->xlator->name, "xlator.c", __FUNCTION__, 470, GF_LOG_DEBUG , "fini done"); } while (0); | |||||
471 | trav = trav->next; | |||||
472 | } | |||||
473 | ||||||
474 | if (xl->init_succeeded) { | |||||
475 | if (xl->fini) { | |||||
476 | old_THIS = THIS(*__glusterfs_this_location()); | |||||
477 | THIS(*__glusterfs_this_location()) = xl; | |||||
478 | ||||||
479 | xl->fini (xl); | |||||
480 | ||||||
481 | if (xl->local_pool) | |||||
482 | mem_pool_destroy (xl->local_pool); | |||||
483 | ||||||
484 | THIS(*__glusterfs_this_location()) = old_THIS; | |||||
485 | } else { | |||||
486 | gf_log (xl->name, GF_LOG_DEBUG, "No fini() found")do { do { if (0) printf ("No fini() found"); } while (0); _gf_log (xl->name, "xlator.c", __FUNCTION__, 486, GF_LOG_DEBUG, "No fini() found" ); } while (0); | |||||
487 | } | |||||
488 | xl->init_succeeded = 0; | |||||
489 | } | |||||
490 | ||||||
491 | out: | |||||
492 | return; | |||||
493 | } | |||||
494 | ||||||
495 | ||||||
496 | int | |||||
497 | xlator_notify (xlator_t *xl, int event, void *data, ...) | |||||
498 | { | |||||
499 | xlator_t *old_THIS = NULL((void*)0); | |||||
500 | int ret = 0; | |||||
501 | ||||||
502 | old_THIS = THIS(*__glusterfs_this_location()); | |||||
503 | THIS(*__glusterfs_this_location()) = xl; | |||||
504 | ||||||
505 | ret = xl->notify (xl, event, data); | |||||
506 | ||||||
507 | THIS(*__glusterfs_this_location()) = old_THIS; | |||||
508 | ||||||
509 | return ret; | |||||
510 | } | |||||
511 | ||||||
512 | ||||||
513 | int | |||||
514 | xlator_mem_acct_init (xlator_t *xl, int num_types) | |||||
515 | { | |||||
516 | int i = 0; | |||||
517 | int ret = 0; | |||||
518 | ||||||
519 | if (!xl) | |||||
520 | return -1; | |||||
521 | ||||||
522 | if (!xl->ctx->mem_acct_enable) | |||||
523 | return 0; | |||||
524 | ||||||
525 | xl->mem_acct.num_types = num_types; | |||||
526 | ||||||
527 | xl->mem_acct.rec = CALLOC(num_types, sizeof(struct mem_acct_rec))__gf_default_calloc(num_types,sizeof(struct mem_acct_rec)); | |||||
528 | ||||||
529 | if (!xl->mem_acct.rec) { | |||||
530 | return -1; | |||||
531 | } | |||||
532 | ||||||
533 | for (i = 0; i < num_types; i++) { | |||||
534 | ret = LOCK_INIT(&(xl->mem_acct.rec[i].lock))pthread_spin_init (&(xl->mem_acct.rec[i].lock), 0); | |||||
535 | if (ret) { | |||||
536 | fprintf(stderrstderr, "Unable to lock..errno : %d",errno(*__errno_location ())); | |||||
537 | } | |||||
538 | } | |||||
539 | ||||||
540 | return 0; | |||||
541 | } | |||||
542 | ||||||
543 | ||||||
544 | void | |||||
545 | xlator_tree_fini (xlator_t *xl) | |||||
546 | { | |||||
547 | xlator_t *top = NULL((void*)0); | |||||
548 | ||||||
549 | GF_VALIDATE_OR_GOTO ("xlator", xl, out)do { if (!xl) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "xl"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 549, GF_LOG_ERROR, "invalid argument: " "xl"); } while (0); goto out; } } while (0); | |||||
550 | ||||||
551 | top = xl; | |||||
552 | xlator_fini_rec (top); | |||||
553 | ||||||
554 | out: | |||||
555 | return; | |||||
556 | } | |||||
557 | ||||||
558 | ||||||
559 | int | |||||
560 | xlator_tree_free (xlator_t *tree) | |||||
561 | { | |||||
562 | xlator_t *trav = tree; | |||||
563 | xlator_t *prev = tree; | |||||
564 | ||||||
565 | if (!tree) { | |||||
566 | gf_log ("parser", GF_LOG_ERROR, "Translator tree not found")do { do { if (0) printf ("Translator tree not found"); } while (0); _gf_log ("parser", "xlator.c", __FUNCTION__, 566, GF_LOG_ERROR , "Translator tree not found"); } while (0); | |||||
567 | return -1; | |||||
568 | } | |||||
569 | ||||||
570 | while (prev) { | |||||
571 | trav = prev->next; | |||||
572 | dict_destroy (prev->options); | |||||
573 | GF_FREE (prev->name)__gf_free (prev->name); | |||||
574 | GF_FREE (prev->type)__gf_free (prev->type); | |||||
575 | GF_FREE (prev)__gf_free (prev); | |||||
576 | prev = trav; | |||||
577 | } | |||||
578 | ||||||
579 | return 0; | |||||
580 | } | |||||
581 | ||||||
582 | ||||||
583 | void | |||||
584 | loc_wipe (loc_t *loc) | |||||
585 | { | |||||
586 | if (loc->inode) { | |||||
587 | inode_unref (loc->inode); | |||||
588 | loc->inode = NULL((void*)0); | |||||
589 | } | |||||
590 | if (loc->path) { | |||||
591 | GF_FREE ((char *)loc->path)__gf_free ((char *)loc->path); | |||||
592 | loc->path = NULL((void*)0); | |||||
593 | } | |||||
594 | ||||||
595 | if (loc->parent) { | |||||
596 | inode_unref (loc->parent); | |||||
597 | loc->parent = NULL((void*)0); | |||||
598 | } | |||||
599 | ||||||
600 | memset (loc, 0, sizeof (*loc)); | |||||
601 | } | |||||
602 | ||||||
603 | int | |||||
604 | loc_path (loc_t *loc, const char *bname) | |||||
605 | { | |||||
606 | int ret = 0; | |||||
607 | ||||||
608 | if (loc->path) | |||||
609 | goto out; | |||||
610 | ||||||
611 | ret = -1; | |||||
612 | ||||||
613 | if (bname && !strlen (bname)) | |||||
614 | bname = NULL((void*)0); | |||||
615 | ||||||
616 | if (!bname) | |||||
617 | goto inode_path; | |||||
618 | ||||||
619 | if (loc->parent && !uuid_is_null (loc->parent->gfid)) { | |||||
620 | ret = inode_path (loc->parent, bname, (char**)&loc->path); | |||||
621 | } else if (!uuid_is_null (loc->pargfid)) { | |||||
622 | ret = gf_asprintf ((char**)&loc->path, INODE_PATH_FMT"<gfid:%s>""/%s", | |||||
623 | uuid_utoa (loc->pargfid), bname); | |||||
624 | } | |||||
625 | ||||||
626 | if (loc->path) | |||||
627 | goto out; | |||||
628 | ||||||
629 | inode_path: | |||||
630 | if (loc->inode && !uuid_is_null (loc->inode->gfid)) { | |||||
631 | ret = inode_path (loc->inode, NULL((void*)0), (char **)&loc->path); | |||||
632 | } else if (!uuid_is_null (loc->gfid)) { | |||||
633 | ret = gf_asprintf ((char**)&loc->path, INODE_PATH_FMT"<gfid:%s>", | |||||
634 | uuid_utoa (loc->gfid)); | |||||
635 | } | |||||
636 | out: | |||||
637 | return ret; | |||||
638 | } | |||||
639 | ||||||
640 | char* | |||||
641 | loc_gfid_utoa (loc_t *loc) | |||||
642 | { | |||||
643 | uuid_t gfid={0}; | |||||
644 | ||||||
645 | if (!loc) | |||||
646 | goto out; | |||||
647 | else if (!uuid_is_null (loc->gfid)) | |||||
648 | uuid_copy (gfid, loc->gfid); | |||||
649 | else if (loc->inode && (!uuid_is_null (loc->inode->gfid))) | |||||
650 | uuid_copy (gfid, loc->inode->gfid); | |||||
651 | out: | |||||
652 | return uuid_utoa (gfid); | |||||
653 | } | |||||
654 | ||||||
655 | int | |||||
656 | loc_copy (loc_t *dst, loc_t *src) | |||||
657 | { | |||||
658 | int ret = -1; | |||||
659 | ||||||
660 | GF_VALIDATE_OR_GOTO ("xlator", dst, err)do { if (!dst) { (*__errno_location ()) = 22; do { do { if (0 ) printf ("invalid argument: " "dst"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 660, GF_LOG_ERROR, "invalid argument: " "dst"); } while (0); goto err; } } while (0); | |||||
661 | GF_VALIDATE_OR_GOTO ("xlator", src, err)do { if (!src) { (*__errno_location ()) = 22; do { do { if (0 ) printf ("invalid argument: " "src"); } while (0); _gf_log_callingfn ("xlator", "xlator.c", __FUNCTION__, 661, GF_LOG_ERROR, "invalid argument: " "src"); } while (0); goto err; } } while (0); | |||||
662 | ||||||
663 | uuid_copy (dst->gfid, src->gfid); | |||||
664 | uuid_copy (dst->pargfid, src->pargfid); | |||||
665 | uuid_copy (dst->gfid, src->gfid); | |||||
666 | ||||||
667 | if (src->inode) | |||||
668 | dst->inode = inode_ref (src->inode); | |||||
669 | ||||||
670 | if (src->parent) | |||||
671 | dst->parent = inode_ref (src->parent); | |||||
672 | ||||||
673 | if (src->path) { | |||||
674 | dst->path = gf_strdup (src->path); | |||||
675 | ||||||
676 | if (!dst->path) | |||||
677 | goto out; | |||||
678 | ||||||
679 | if (src->name) | |||||
680 | dst->name = strrchr (dst->path, '/'); | |||||
681 | if (dst->name) | |||||
682 | dst->name++; | |||||
683 | } | |||||
684 | ||||||
685 | ret = 0; | |||||
686 | out: | |||||
687 | if (ret == -1) | |||||
688 | loc_wipe (dst); | |||||
689 | ||||||
690 | err: | |||||
691 | return ret; | |||||
692 | } | |||||
693 | ||||||
694 | int | |||||
695 | xlator_list_destroy (xlator_list_t *list) | |||||
696 | { | |||||
697 | xlator_list_t *next = NULL((void*)0); | |||||
698 | ||||||
699 | while (list) { | |||||
700 | next = list->next; | |||||
701 | GF_FREE (list)__gf_free (list); | |||||
702 | list = next; | |||||
703 | } | |||||
704 | ||||||
705 | return 0; | |||||
706 | } | |||||
707 | ||||||
708 | ||||||
709 | int | |||||
710 | xlator_destroy (xlator_t *xl) | |||||
711 | { | |||||
712 | volume_opt_list_t *vol_opt = NULL((void*)0); | |||||
713 | volume_opt_list_t *tmp = NULL((void*)0); | |||||
714 | ||||||
715 | if (!xl) | |||||
716 | return 0; | |||||
717 | ||||||
718 | GF_FREE (xl->name)__gf_free (xl->name); | |||||
719 | GF_FREE (xl->type)__gf_free (xl->type); | |||||
720 | if (xl->dlhandle) | |||||
721 | dlclose (xl->dlhandle); | |||||
722 | if (xl->options) | |||||
723 | dict_destroy (xl->options); | |||||
724 | ||||||
725 | xlator_list_destroy (xl->children); | |||||
726 | ||||||
727 | xlator_list_destroy (xl->parents); | |||||
728 | ||||||
729 | list_for_each_entry_safe (vol_opt, tmp, &xl->volume_options, list)for (vol_opt = ((typeof(*vol_opt) *)((char *)((&xl->volume_options )->next)-(unsigned long)(&((typeof(*vol_opt) *)0)-> list))), tmp = ((typeof(*vol_opt) *)((char *)(vol_opt->list .next)-(unsigned long)(&((typeof(*vol_opt) *)0)->list) )); &vol_opt->list != (&xl->volume_options); vol_opt = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list.next)-( unsigned long)(&((typeof(*tmp) *)0)->list)))) { | |||||
730 | list_del_init (&vol_opt->list); | |||||
731 | GF_FREE (vol_opt)__gf_free (vol_opt); | |||||
732 | } | |||||
733 | ||||||
734 | GF_FREE (xl)__gf_free (xl); | |||||
735 | ||||||
736 | return 0; | |||||
737 | } | |||||
738 | ||||||
739 | ||||||
740 | int | |||||
741 | is_gf_log_command (xlator_t *this, const char *name, char *value) | |||||
742 | { | |||||
743 | xlator_t *trav = NULL((void*)0); | |||||
744 | char key[1024] = {0,}; | |||||
745 | int ret = -1; | |||||
746 | int log_level = -1; | |||||
747 | gf_boolean_t syslog_flag = 0; | |||||
748 | glusterfs_ctx_t *ctx = NULL((void*)0); | |||||
749 | ||||||
750 | if (!strcmp ("trusted.glusterfs.syslog", name)) { | |||||
751 | ret = gf_string2boolean (value, &syslog_flag); | |||||
752 | if (ret) { | |||||
753 | ret = EOPNOTSUPP95; | |||||
754 | goto out; | |||||
755 | } | |||||
756 | if (syslog_flag) | |||||
757 | gf_log_enable_syslog (); | |||||
758 | else | |||||
759 | gf_log_disable_syslog (); | |||||
760 | ||||||
761 | goto out; | |||||
762 | } | |||||
763 | ||||||
764 | if (fnmatch ("trusted.glusterfs*set-log-level", name, FNM_NOESCAPE(1 << 1))) | |||||
765 | goto out; | |||||
766 | ||||||
767 | log_level = glusterd_check_log_level (value); | |||||
768 | if (log_level == -1) { | |||||
769 | ret = EOPNOTSUPP95; | |||||
770 | goto out; | |||||
771 | } | |||||
772 | ||||||
773 | /* Some crude way to change the log-level of process */ | |||||
774 | if (!strcmp (name, "trusted.glusterfs.set-log-level")) { | |||||
775 | /* */ | |||||
776 | gf_log ("glusterfs", gf_log_get_loglevel(),do { do { if (0) printf ("setting log level to %d (old-value=%d)" , log_level, gf_log_get_loglevel()); } while (0); _gf_log ("glusterfs" , "xlator.c", __FUNCTION__, 778, gf_log_get_loglevel(), "setting log level to %d (old-value=%d)" , log_level, gf_log_get_loglevel()); } while (0) | |||||
777 | "setting log level to %d (old-value=%d)",do { do { if (0) printf ("setting log level to %d (old-value=%d)" , log_level, gf_log_get_loglevel()); } while (0); _gf_log ("glusterfs" , "xlator.c", __FUNCTION__, 778, gf_log_get_loglevel(), "setting log level to %d (old-value=%d)" , log_level, gf_log_get_loglevel()); } while (0) | |||||
778 | log_level, gf_log_get_loglevel())do { do { if (0) printf ("setting log level to %d (old-value=%d)" , log_level, gf_log_get_loglevel()); } while (0); _gf_log ("glusterfs" , "xlator.c", __FUNCTION__, 778, gf_log_get_loglevel(), "setting log level to %d (old-value=%d)" , log_level, gf_log_get_loglevel()); } while (0); | |||||
779 | gf_log_set_loglevel (log_level); | |||||
780 | ret = 0; | |||||
781 | goto out; | |||||
782 | } | |||||
783 | ||||||
784 | if (!strcmp (name, "trusted.glusterfs.fuse.set-log-level")) { | |||||
785 | /* */ | |||||
786 | gf_log (this->name, gf_log_get_xl_loglevel (this),do { do { if (0) printf ("setting log level to %d (old-value=%d)" , log_level, gf_log_get_xl_loglevel (this)); } while (0); _gf_log (this->name, "xlator.c", __FUNCTION__, 788, gf_log_get_xl_loglevel (this), "setting log level to %d (old-value=%d)", log_level, gf_log_get_xl_loglevel (this)); } while (0) | |||||
787 | "setting log level to %d (old-value=%d)",do { do { if (0) printf ("setting log level to %d (old-value=%d)" , log_level, gf_log_get_xl_loglevel (this)); } while (0); _gf_log (this->name, "xlator.c", __FUNCTION__, 788, gf_log_get_xl_loglevel (this), "setting log level to %d (old-value=%d)", log_level, gf_log_get_xl_loglevel (this)); } while (0) | |||||
788 | log_level, gf_log_get_xl_loglevel (this))do { do { if (0) printf ("setting log level to %d (old-value=%d)" , log_level, gf_log_get_xl_loglevel (this)); } while (0); _gf_log (this->name, "xlator.c", __FUNCTION__, 788, gf_log_get_xl_loglevel (this), "setting log level to %d (old-value=%d)", log_level, gf_log_get_xl_loglevel (this)); } while (0); | |||||
789 | gf_log_set_xl_loglevel (this, log_level); | |||||
790 | ret = 0; | |||||
791 | goto out; | |||||
792 | } | |||||
793 | ||||||
794 | ctx = this->ctx; | |||||
795 | if (!ctx) | |||||
796 | goto out; | |||||
797 | if (!ctx->active) | |||||
798 | goto out; | |||||
799 | trav = ctx->active->top; | |||||
800 | ||||||
801 | while (trav) { | |||||
802 | snprintf (key, 1024, "trusted.glusterfs.%s.set-log-level", | |||||
803 | trav->name); | |||||
804 | if (fnmatch (name, key, FNM_NOESCAPE(1 << 1)) == 0) { | |||||
805 | gf_log (trav->name, gf_log_get_xl_loglevel (trav),do { do { if (0) printf ("setting log level to %d (old-value=%d)" , log_level, gf_log_get_xl_loglevel (trav)); } while (0); _gf_log (trav->name, "xlator.c", __FUNCTION__, 807, gf_log_get_xl_loglevel (trav), "setting log level to %d (old-value=%d)", log_level, gf_log_get_xl_loglevel (trav)); } while (0) | |||||
806 | "setting log level to %d (old-value=%d)",do { do { if (0) printf ("setting log level to %d (old-value=%d)" , log_level, gf_log_get_xl_loglevel (trav)); } while (0); _gf_log (trav->name, "xlator.c", __FUNCTION__, 807, gf_log_get_xl_loglevel (trav), "setting log level to %d (old-value=%d)", log_level, gf_log_get_xl_loglevel (trav)); } while (0) | |||||
807 | log_level, gf_log_get_xl_loglevel (trav))do { do { if (0) printf ("setting log level to %d (old-value=%d)" , log_level, gf_log_get_xl_loglevel (trav)); } while (0); _gf_log (trav->name, "xlator.c", __FUNCTION__, 807, gf_log_get_xl_loglevel (trav), "setting log level to %d (old-value=%d)", log_level, gf_log_get_xl_loglevel (trav)); } while (0); | |||||
808 | gf_log_set_xl_loglevel (trav, log_level); | |||||
809 | ret = 0; | |||||
810 | } | |||||
811 | trav = trav->next; | |||||
812 | } | |||||
813 | out: | |||||
814 | return ret; | |||||
815 | } | |||||
816 | ||||||
817 | ||||||
818 | int | |||||
819 | glusterd_check_log_level (const char *value) | |||||
820 | { | |||||
821 | int log_level = -1; | |||||
822 | ||||||
823 | if (!strcasecmp (value, "CRITICAL")) { | |||||
824 | log_level = GF_LOG_CRITICAL; | |||||
825 | } else if (!strcasecmp (value, "ERROR")) { | |||||
826 | log_level = GF_LOG_ERROR; | |||||
827 | } else if (!strcasecmp (value, "WARNING")) { | |||||
828 | log_level = GF_LOG_WARNING; | |||||
829 | } else if (!strcasecmp (value, "INFO")) { | |||||
830 | log_level = GF_LOG_INFO; | |||||
831 | } else if (!strcasecmp (value, "DEBUG")) { | |||||
832 | log_level = GF_LOG_DEBUG; | |||||
833 | } else if (!strcasecmp (value, "TRACE")) { | |||||
834 | log_level = GF_LOG_TRACE; | |||||
835 | } else if (!strcasecmp (value, "NONE")) { | |||||
836 | log_level = GF_LOG_NONE; | |||||
837 | } | |||||
838 | ||||||
839 | if (log_level == -1) | |||||
840 | gf_log (THIS->name, GF_LOG_ERROR, "Invalid log-level. possible values "do { do { if (0) printf ("Invalid log-level. possible values " "are DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "xlator.c" , __FUNCTION__, 841, GF_LOG_ERROR, "Invalid log-level. possible values " "are DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE"); } while (0) | |||||
841 | "are DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE")do { do { if (0) printf ("Invalid log-level. possible values " "are DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "xlator.c" , __FUNCTION__, 841, GF_LOG_ERROR, "Invalid log-level. possible values " "are DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE"); } while (0); | |||||
842 | ||||||
843 | return log_level; | |||||
844 | } | |||||
845 |