File: | glusterfsd/src/glusterfsd.c |
Location: | line 1034, column 13 |
Description: | Access to field 'volfile_server' results in a dereference of a null pointer (loaded from variable 'cmd_args') |
1 | /* | |||
2 | Copyright (c) 2006-2013 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 | #include <stdio.h> | |||
11 | #include <string.h> | |||
12 | #include <stdlib.h> | |||
13 | #include <netinet/in.h> | |||
14 | #include <sys/socket.h> | |||
15 | #include <sys/types.h> | |||
16 | #include <sys/resource.h> | |||
17 | #include <sys/file.h> | |||
18 | #include <sys/wait.h> | |||
19 | #include <netdb.h> | |||
20 | #include <signal.h> | |||
21 | #include <libgen.h> | |||
22 | ||||
23 | #include <sys/utsname.h> | |||
24 | ||||
25 | #include <stdint.h> | |||
26 | #include <pthread.h> | |||
27 | #include <sys/stat.h> | |||
28 | #include <fcntl.h> | |||
29 | #include <time.h> | |||
30 | #include <semaphore.h> | |||
31 | #include <errno(*__errno_location ()).h> | |||
32 | #include <pwd.h> | |||
33 | ||||
34 | #ifndef _CONFIG_H | |||
35 | #define _CONFIG_H | |||
36 | #include "config.h" | |||
37 | #endif | |||
38 | ||||
39 | #ifdef HAVE_MALLOC_H1 | |||
40 | #include <malloc.h> | |||
41 | #endif | |||
42 | ||||
43 | #ifdef HAVE_MALLOC_STATS1 | |||
44 | #ifdef DEBUG | |||
45 | #include <mcheck.h> | |||
46 | #endif | |||
47 | #endif | |||
48 | ||||
49 | #include "xlator.h" | |||
50 | #include "glusterfs.h" | |||
51 | #include "compat.h" | |||
52 | #include "logging.h" | |||
53 | #include "dict.h" | |||
54 | #include "list.h" | |||
55 | #include "timer.h" | |||
56 | #include "glusterfsd.h" | |||
57 | #include "stack.h" | |||
58 | #include "revision.h" | |||
59 | #include "common-utils.h" | |||
60 | #include "event.h" | |||
61 | #include "globals.h" | |||
62 | #include "statedump.h" | |||
63 | #include "latency.h" | |||
64 | #include "glusterfsd-mem-types.h" | |||
65 | #include "syscall.h" | |||
66 | #include "call-stub.h" | |||
67 | #include <fnmatch.h> | |||
68 | #include "rpc-clnt.h" | |||
69 | #include "syncop.h" | |||
70 | ||||
71 | #include "daemon.h" | |||
72 | ||||
73 | /* process mode definitions */ | |||
74 | #define GF_SERVER_PROCESS0 0 | |||
75 | #define GF_CLIENT_PROCESS1 1 | |||
76 | #define GF_GLUSTERD_PROCESS2 2 | |||
77 | ||||
78 | /* using argp for command line parsing */ | |||
79 | static char gf_doc[] = ""; | |||
80 | static char argp_doc[] = "--volfile-server=SERVER [MOUNT-POINT]\n" \ | |||
81 | "--volfile=VOLFILE [MOUNT-POINT]"; | |||
82 | const char *argp_program_version = "" | |||
83 | PACKAGE_NAME"glusterfs"" "PACKAGE_VERSION"3git"" built on "__DATE__"May 5 2013"" "__TIME__"11:39:23" | |||
84 | "\nRepository revision: " GLUSTERFS_REPOSITORY_REVISION"git://git.gluster.com/glusterfs.git" "\n" | |||
85 | "Copyright (c) 2006-2013 Red Hat, Inc. <http://www.redhat.com/>\n" | |||
86 | "GlusterFS comes with ABSOLUTELY NO WARRANTY.\n" | |||
87 | "It is licensed to you under your choice of the GNU Lesser\n" | |||
88 | "General Public License, version 3 or any later version (LGPLv3\n" | |||
89 | "or later), or the GNU General Public License, version 2 (GPLv2),\n" | |||
90 | "in all cases as published by the Free Software Foundation."; | |||
91 | const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT"gluster-users@gluster.org" ">"; | |||
92 | ||||
93 | static error_t parse_opts (int32_t key, char *arg, struct argp_state *_state); | |||
94 | ||||
95 | static struct argp_option gf_options[] = { | |||
96 | {0, 0, 0, 0, "Basic options:"}, | |||
97 | {"volfile-server", ARGP_VOLFILE_SERVER_KEY, "SERVER", 0, | |||
98 | "Server to get the volume file from. This option overrides " | |||
99 | "--volfile option"}, | |||
100 | {"volfile-max-fetch-attempts", ARGP_VOLFILE_MAX_FETCH_ATTEMPTS, | |||
101 | "MAX-ATTEMPTS", 0, "Maximum number of connect attempts to server. " | |||
102 | "This option should be provided with --volfile-server option" | |||
103 | "[default: 1]"}, | |||
104 | {"volfile", ARGP_VOLUME_FILE_KEY, "VOLFILE", 0, | |||
105 | "File to use as VOLUME_FILE"}, | |||
106 | {"spec-file", ARGP_VOLUME_FILE_KEY, "VOLFILE", OPTION_HIDDEN0x2, | |||
107 | "File to use as VOLUME FILE"}, | |||
108 | ||||
109 | {"log-level", ARGP_LOG_LEVEL_KEY, "LOGLEVEL", 0, | |||
110 | "Logging severity. Valid options are DEBUG, INFO, WARNING, ERROR, " | |||
111 | "CRITICAL and NONE [default: INFO]"}, | |||
112 | {"log-file", ARGP_LOG_FILE_KEY, "LOGFILE", 0, | |||
113 | "File to use for logging [default: " | |||
114 | DEFAULT_LOG_FILE_DIRECTORY"/usr/local/var" "/log/glusterfs" "/" PACKAGE_NAME"glusterfs" ".log" "]"}, | |||
115 | ||||
116 | {0, 0, 0, 0, "Advanced Options:"}, | |||
117 | {"volfile-server-port", ARGP_VOLFILE_SERVER_PORT_KEY, "PORT", 0, | |||
118 | "Listening port number of volfile server"}, | |||
119 | {"volfile-server-transport", ARGP_VOLFILE_SERVER_TRANSPORT_KEY, | |||
120 | "TRANSPORT", 0, | |||
121 | "Transport type to get volfile from server [default: socket]"}, | |||
122 | {"volfile-id", ARGP_VOLFILE_ID_KEY, "KEY", 0, | |||
123 | "'key' of the volfile to be fetched from server"}, | |||
124 | {"pid-file", ARGP_PID_FILE_KEY, "PIDFILE", 0, | |||
125 | "File to use as pid file"}, | |||
126 | {"socket-file", ARGP_SOCK_FILE_KEY, "SOCKFILE", 0, | |||
127 | "File to use as unix-socket"}, | |||
128 | {"no-daemon", ARGP_NO_DAEMON_KEY, 0, 0, | |||
129 | "Run in foreground"}, | |||
130 | {"run-id", ARGP_RUN_ID_KEY, "RUN-ID", OPTION_HIDDEN0x2, | |||
131 | "Run ID for the process, used by scripts to keep track of process " | |||
132 | "they started, defaults to none"}, | |||
133 | {"debug", ARGP_DEBUG_KEY, 0, 0, | |||
134 | "Run in debug mode. This option sets --no-daemon, --log-level " | |||
135 | "to DEBUG and --log-file to console"}, | |||
136 | {"volume-name", ARGP_VOLUME_NAME_KEY, "XLATOR-NAME", 0, | |||
137 | "Translator name to be used for MOUNT-POINT [default: top most volume " | |||
138 | "definition in VOLFILE]"}, | |||
139 | {"xlator-option", ARGP_XLATOR_OPTION_KEY,"XLATOR-NAME.OPTION=VALUE", 0, | |||
140 | "Add/override an option for a translator in volume file with specified" | |||
141 | " value"}, | |||
142 | {"read-only", ARGP_READ_ONLY_KEY, 0, 0, | |||
143 | "Mount the filesystem in 'read-only' mode"}, | |||
144 | {"acl", ARGP_ACL_KEY, 0, 0, | |||
145 | "Mount the filesystem with POSIX ACL support"}, | |||
146 | {"selinux", ARGP_SELINUX_KEY, 0, 0, | |||
147 | "Enable SELinux label (extened attributes) support on inodes"}, | |||
148 | {"enable-ino32", ARGP_INODE32_KEY, "BOOL", OPTION_ARG_OPTIONAL0x1, | |||
149 | "Use 32-bit inodes when mounting to workaround broken applications" | |||
150 | "that don't support 64-bit inodes"}, | |||
151 | {"worm", ARGP_WORM_KEY, 0, 0, | |||
152 | "Mount the filesystem in 'worm' mode"}, | |||
153 | {"mac-compat", ARGP_MAC_COMPAT_KEY, "BOOL", OPTION_ARG_OPTIONAL0x1, | |||
154 | "Provide stubs for attributes needed for seamless operation on Macs " | |||
155 | #ifdef GF_DARWIN_HOST_OS | |||
156 | "[default: \"on\" on client side, else \"off\"]" | |||
157 | #else | |||
158 | "[default: \"off\"]" | |||
159 | #endif | |||
160 | }, | |||
161 | {"brick-name", ARGP_BRICK_NAME_KEY, "BRICK-NAME", OPTION_HIDDEN0x2, | |||
162 | "Brick name to be registered with Gluster portmapper" }, | |||
163 | {"brick-port", ARGP_BRICK_PORT_KEY, "BRICK-PORT", OPTION_HIDDEN0x2, | |||
164 | "Brick Port to be registered with Gluster portmapper" }, | |||
165 | {"fopen-keep-cache", ARGP_FOPEN_KEEP_CACHE_KEY, 0, 0, | |||
166 | "Do not purge the cache on file open"}, | |||
167 | ||||
168 | {0, 0, 0, 0, "Fuse options:"}, | |||
169 | {"direct-io-mode", ARGP_DIRECT_IO_MODE_KEY, "BOOL", OPTION_ARG_OPTIONAL0x1, | |||
170 | "Use direct I/O mode in fuse kernel module" | |||
171 | " [default: \"off\" if big writes are supported, else " | |||
172 | "\"on\" for fds not opened with O_RDONLY]"}, | |||
173 | {"entry-timeout", ARGP_ENTRY_TIMEOUT_KEY, "SECONDS", 0, | |||
174 | "Set entry timeout to SECONDS in fuse kernel module [default: 1]"}, | |||
175 | {"negative-timeout", ARGP_NEGATIVE_TIMEOUT_KEY, "SECONDS", 0, | |||
176 | "Set negative timeout to SECONDS in fuse kernel module [default: 0]"}, | |||
177 | {"attribute-timeout", ARGP_ATTRIBUTE_TIMEOUT_KEY, "SECONDS", 0, | |||
178 | "Set attribute timeout to SECONDS for inodes in fuse kernel module " | |||
179 | "[default: 1]"}, | |||
180 | {"gid-timeout", ARGP_GID_TIMEOUT_KEY, "SECONDS", 0, | |||
181 | "Set auxilary group list timeout to SECONDS for fuse translator " | |||
182 | "[default: 0]"}, | |||
183 | {"background-qlen", ARGP_FUSE_BACKGROUND_QLEN_KEY, "N", 0, | |||
184 | "Set fuse module's background queue length to N " | |||
185 | "[default: 64]"}, | |||
186 | {"congestion-threshold", ARGP_FUSE_CONGESTION_THRESHOLD_KEY, "N", 0, | |||
187 | "Set fuse module's congestion threshold to N " | |||
188 | "[default: 48]"}, | |||
189 | {"client-pid", ARGP_CLIENT_PID_KEY, "PID", OPTION_HIDDEN0x2, | |||
190 | "client will authenticate itself with process id PID to server"}, | |||
191 | {"user-map-root", ARGP_USER_MAP_ROOT_KEY, "USER", OPTION_HIDDEN0x2, | |||
192 | "replace USER with root in messages"}, | |||
193 | {"dump-fuse", ARGP_DUMP_FUSE_KEY, "PATH", 0, | |||
194 | "Dump fuse traffic to PATH"}, | |||
195 | {"volfile-check", ARGP_VOLFILE_CHECK_KEY, 0, 0, | |||
196 | "Enable strict volume file checking"}, | |||
197 | {"mem-accounting", ARGP_MEM_ACCOUNTING_KEY, 0, OPTION_HIDDEN0x2, | |||
198 | "Enable internal memory accounting"}, | |||
199 | {"fuse-mountopts", ARGP_FUSE_MOUNTOPTS_KEY, "OPTIONS", OPTION_HIDDEN0x2, | |||
200 | "Extra mount options to pass to FUSE"}, | |||
201 | {0, 0, 0, 0, "Miscellaneous Options:"}, | |||
202 | {0, } | |||
203 | }; | |||
204 | ||||
205 | ||||
206 | static struct argp argp = { gf_options, parse_opts, argp_doc, gf_doc }; | |||
207 | ||||
208 | int glusterfs_pidfile_cleanup (glusterfs_ctx_t *ctx); | |||
209 | int glusterfs_volumes_init (glusterfs_ctx_t *ctx); | |||
210 | int glusterfs_mgmt_init (glusterfs_ctx_t *ctx); | |||
211 | int glusterfs_listener_init (glusterfs_ctx_t *ctx); | |||
212 | int glusterfs_listener_stop (glusterfs_ctx_t *ctx); | |||
213 | ||||
214 | ||||
215 | static int | |||
216 | set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) | |||
217 | { | |||
218 | int ret = 0; | |||
219 | cmd_args_t *cmd_args = NULL((void*)0); | |||
220 | char *mount_point = NULL((void*)0); | |||
221 | char cwd[PATH_MAX4096] = {0,}; | |||
222 | ||||
223 | cmd_args = &ctx->cmd_args; | |||
224 | ||||
225 | /* Check if mount-point is absolute path, | |||
226 | * if not convert to absolute path by concating with CWD | |||
227 | */ | |||
228 | if (cmd_args->mount_point[0] != '/') { | |||
229 | if (getcwd (cwd, PATH_MAX4096) != NULL((void*)0)) { | |||
230 | ret = gf_asprintf (&mount_point, "%s/%s", cwd, | |||
231 | cmd_args->mount_point); | |||
232 | if (ret == -1) { | |||
233 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("Could not create absolute mountpoint " "path"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 235, GF_LOG_ERROR, "Could not create absolute mountpoint " "path"); } while (0) | |||
234 | "Could not create absolute mountpoint "do { do { if (0) printf ("Could not create absolute mountpoint " "path"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 235, GF_LOG_ERROR, "Could not create absolute mountpoint " "path"); } while (0) | |||
235 | "path")do { do { if (0) printf ("Could not create absolute mountpoint " "path"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 235, GF_LOG_ERROR, "Could not create absolute mountpoint " "path"); } while (0); | |||
236 | goto err; | |||
237 | } | |||
238 | } else { | |||
239 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("Could not get current working directory" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 240, GF_LOG_ERROR, "Could not get current working directory" ); } while (0) | |||
240 | "Could not get current working directory")do { do { if (0) printf ("Could not get current working directory" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 240, GF_LOG_ERROR, "Could not get current working directory" ); } while (0); | |||
241 | goto err; | |||
242 | } | |||
243 | } else | |||
244 | mount_point = gf_strdup (cmd_args->mount_point); | |||
245 | ||||
246 | ret = dict_set_dynstr (options, ZR_MOUNTPOINT_OPT"mountpoint", mount_point); | |||
247 | if (ret < 0) { | |||
248 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set mount-point to options dictionary" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 249, GF_LOG_ERROR, "failed to set mount-point to options dictionary" ); } while (0) | |||
249 | "failed to set mount-point to options dictionary")do { do { if (0) printf ("failed to set mount-point to options dictionary" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 249, GF_LOG_ERROR, "failed to set mount-point to options dictionary" ); } while (0); | |||
250 | goto err; | |||
251 | } | |||
252 | ||||
253 | if (cmd_args->fuse_attribute_timeout >= 0) { | |||
254 | ret = dict_set_double (options, ZR_ATTR_TIMEOUT_OPT"attribute-timeout", | |||
255 | cmd_args->fuse_attribute_timeout); | |||
256 | ||||
257 | if (ret < 0) { | |||
258 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key %s" , "attribute-timeout"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 260, GF_LOG_ERROR, "failed to set dict value for key %s" , "attribute-timeout"); } while (0) | |||
259 | "failed to set dict value for key %s",do { do { if (0) printf ("failed to set dict value for key %s" , "attribute-timeout"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 260, GF_LOG_ERROR, "failed to set dict value for key %s" , "attribute-timeout"); } while (0) | |||
260 | ZR_ATTR_TIMEOUT_OPT)do { do { if (0) printf ("failed to set dict value for key %s" , "attribute-timeout"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 260, GF_LOG_ERROR, "failed to set dict value for key %s" , "attribute-timeout"); } while (0); | |||
261 | goto err; | |||
262 | } | |||
263 | } | |||
264 | ||||
265 | if (cmd_args->fuse_entry_timeout >= 0) { | |||
266 | ret = dict_set_double (options, ZR_ENTRY_TIMEOUT_OPT"entry-timeout", | |||
267 | cmd_args->fuse_entry_timeout); | |||
268 | if (ret < 0) { | |||
269 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key %s" , "entry-timeout"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 271, GF_LOG_ERROR, "failed to set dict value for key %s" , "entry-timeout"); } while (0) | |||
270 | "failed to set dict value for key %s",do { do { if (0) printf ("failed to set dict value for key %s" , "entry-timeout"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 271, GF_LOG_ERROR, "failed to set dict value for key %s" , "entry-timeout"); } while (0) | |||
271 | ZR_ENTRY_TIMEOUT_OPT)do { do { if (0) printf ("failed to set dict value for key %s" , "entry-timeout"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 271, GF_LOG_ERROR, "failed to set dict value for key %s" , "entry-timeout"); } while (0); | |||
272 | goto err; | |||
273 | } | |||
274 | } | |||
275 | ||||
276 | if (cmd_args->fuse_negative_timeout >= 0) { | |||
277 | ret = dict_set_double (options, ZR_NEGATIVE_TIMEOUT_OPT"negative-timeout", | |||
278 | cmd_args->fuse_negative_timeout); | |||
279 | if (ret < 0) { | |||
280 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key %s" , "negative-timeout"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 282, GF_LOG_ERROR, "failed to set dict value for key %s" , "negative-timeout"); } while (0) | |||
281 | "failed to set dict value for key %s",do { do { if (0) printf ("failed to set dict value for key %s" , "negative-timeout"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 282, GF_LOG_ERROR, "failed to set dict value for key %s" , "negative-timeout"); } while (0) | |||
282 | ZR_NEGATIVE_TIMEOUT_OPT)do { do { if (0) printf ("failed to set dict value for key %s" , "negative-timeout"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 282, GF_LOG_ERROR, "failed to set dict value for key %s" , "negative-timeout"); } while (0); | |||
283 | goto err; | |||
284 | } | |||
285 | } | |||
286 | ||||
287 | if (cmd_args->client_pid_set) { | |||
288 | ret = dict_set_int32 (options, "client-pid", | |||
289 | cmd_args->client_pid); | |||
290 | if (ret < 0) { | |||
291 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key %s" , "client-pid"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 293, GF_LOG_ERROR, "failed to set dict value for key %s" , "client-pid"); } while (0) | |||
292 | "failed to set dict value for key %s",do { do { if (0) printf ("failed to set dict value for key %s" , "client-pid"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 293, GF_LOG_ERROR, "failed to set dict value for key %s" , "client-pid"); } while (0) | |||
293 | "client-pid")do { do { if (0) printf ("failed to set dict value for key %s" , "client-pid"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 293, GF_LOG_ERROR, "failed to set dict value for key %s" , "client-pid"); } while (0); | |||
294 | goto err; | |||
295 | } | |||
296 | } | |||
297 | ||||
298 | if (cmd_args->uid_map_root) { | |||
299 | ret = dict_set_int32 (options, "uid-map-root", | |||
300 | cmd_args->uid_map_root); | |||
301 | if (ret < 0) { | |||
302 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key %s" , "uid-map-root"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 304, GF_LOG_ERROR, "failed to set dict value for key %s" , "uid-map-root"); } while (0) | |||
303 | "failed to set dict value for key %s",do { do { if (0) printf ("failed to set dict value for key %s" , "uid-map-root"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 304, GF_LOG_ERROR, "failed to set dict value for key %s" , "uid-map-root"); } while (0) | |||
304 | "uid-map-root")do { do { if (0) printf ("failed to set dict value for key %s" , "uid-map-root"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 304, GF_LOG_ERROR, "failed to set dict value for key %s" , "uid-map-root"); } while (0); | |||
305 | goto err; | |||
306 | } | |||
307 | } | |||
308 | ||||
309 | if (cmd_args->volfile_check) { | |||
310 | ret = dict_set_int32 (options, ZR_STRICT_VOLFILE_CHECK"strict-volfile-check", | |||
311 | cmd_args->volfile_check); | |||
312 | if (ret < 0) { | |||
313 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key %s" , "strict-volfile-check"); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 315, GF_LOG_ERROR, "failed to set dict value for key %s" , "strict-volfile-check"); } while (0) | |||
314 | "failed to set dict value for key %s",do { do { if (0) printf ("failed to set dict value for key %s" , "strict-volfile-check"); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 315, GF_LOG_ERROR, "failed to set dict value for key %s" , "strict-volfile-check"); } while (0) | |||
315 | ZR_STRICT_VOLFILE_CHECK)do { do { if (0) printf ("failed to set dict value for key %s" , "strict-volfile-check"); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 315, GF_LOG_ERROR, "failed to set dict value for key %s" , "strict-volfile-check"); } while (0); | |||
316 | goto err; | |||
317 | } | |||
318 | } | |||
319 | ||||
320 | if (cmd_args->dump_fuse) { | |||
321 | ret = dict_set_static_ptr (options, ZR_DUMP_FUSE"dump-fuse", | |||
322 | cmd_args->dump_fuse); | |||
323 | if (ret < 0) { | |||
324 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key %s" , "dump-fuse"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 326, GF_LOG_ERROR, "failed to set dict value for key %s" , "dump-fuse"); } while (0) | |||
325 | "failed to set dict value for key %s",do { do { if (0) printf ("failed to set dict value for key %s" , "dump-fuse"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 326, GF_LOG_ERROR, "failed to set dict value for key %s" , "dump-fuse"); } while (0) | |||
326 | ZR_DUMP_FUSE)do { do { if (0) printf ("failed to set dict value for key %s" , "dump-fuse"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 326, GF_LOG_ERROR, "failed to set dict value for key %s" , "dump-fuse"); } while (0); | |||
327 | goto err; | |||
328 | } | |||
329 | } | |||
330 | ||||
331 | if (cmd_args->acl) { | |||
332 | ret = dict_set_static_ptr (options, "acl", "on"); | |||
333 | if (ret < 0) { | |||
334 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key acl" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 335, GF_LOG_ERROR, "failed to set dict value for key acl"); } while (0) | |||
335 | "failed to set dict value for key acl")do { do { if (0) printf ("failed to set dict value for key acl" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 335, GF_LOG_ERROR, "failed to set dict value for key acl"); } while (0); | |||
336 | goto err; | |||
337 | } | |||
338 | } | |||
339 | ||||
340 | if (cmd_args->selinux) { | |||
341 | ret = dict_set_static_ptr (options, "selinux", "on"); | |||
342 | if (ret < 0) { | |||
343 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key selinux" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 344, GF_LOG_ERROR, "failed to set dict value for key selinux" ); } while (0) | |||
344 | "failed to set dict value for key selinux")do { do { if (0) printf ("failed to set dict value for key selinux" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 344, GF_LOG_ERROR, "failed to set dict value for key selinux" ); } while (0); | |||
345 | goto err; | |||
346 | } | |||
347 | } | |||
348 | ||||
349 | if (cmd_args->enable_ino32) { | |||
350 | ret = dict_set_static_ptr (options, "enable-ino32", "on"); | |||
351 | if (ret < 0) { | |||
352 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key enable-ino32" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 353, GF_LOG_ERROR, "failed to set dict value for key enable-ino32" ); } while (0) | |||
353 | "failed to set dict value for key enable-ino32")do { do { if (0) printf ("failed to set dict value for key enable-ino32" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 353, GF_LOG_ERROR, "failed to set dict value for key enable-ino32" ); } while (0); | |||
354 | goto err; | |||
355 | } | |||
356 | } | |||
357 | ||||
358 | if (cmd_args->read_only) { | |||
359 | ret = dict_set_static_ptr (options, "read-only", "on"); | |||
360 | if (ret < 0) { | |||
361 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key read-only" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 362, GF_LOG_ERROR, "failed to set dict value for key read-only" ); } while (0) | |||
362 | "failed to set dict value for key read-only")do { do { if (0) printf ("failed to set dict value for key read-only" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 362, GF_LOG_ERROR, "failed to set dict value for key read-only" ); } while (0); | |||
363 | goto err; | |||
364 | } | |||
365 | } | |||
366 | ||||
367 | if (cmd_args->fopen_keep_cache) { | |||
368 | ret = dict_set_static_ptr(options, "fopen-keep-cache", | |||
369 | "on"); | |||
370 | if (ret < 0) { | |||
371 | gf_log("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key " "fopen-keep-cache" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 373, GF_LOG_ERROR, "failed to set dict value for key " "fopen-keep-cache" ); } while (0) | |||
372 | "failed to set dict value for key "do { do { if (0) printf ("failed to set dict value for key " "fopen-keep-cache" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 373, GF_LOG_ERROR, "failed to set dict value for key " "fopen-keep-cache" ); } while (0) | |||
373 | "fopen-keep-cache")do { do { if (0) printf ("failed to set dict value for key " "fopen-keep-cache" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 373, GF_LOG_ERROR, "failed to set dict value for key " "fopen-keep-cache" ); } while (0); | |||
374 | goto err; | |||
375 | } | |||
376 | } | |||
377 | ||||
378 | if (cmd_args->gid_timeout) { | |||
379 | ret = dict_set_int32(options, "gid-timeout", | |||
380 | cmd_args->gid_timeout); | |||
381 | if (ret < 0) { | |||
382 | gf_log("glusterfsd", GF_LOG_ERROR, "failed to set dict "do { do { if (0) printf ("failed to set dict " "value for key gid-timeout" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 383, GF_LOG_ERROR, "failed to set dict " "value for key gid-timeout" ); } while (0) | |||
383 | "value for key gid-timeout")do { do { if (0) printf ("failed to set dict " "value for key gid-timeout" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 383, GF_LOG_ERROR, "failed to set dict " "value for key gid-timeout" ); } while (0); | |||
384 | goto err; | |||
385 | } | |||
386 | } | |||
387 | if (cmd_args->background_qlen) { | |||
388 | ret = dict_set_int32 (options, "background-qlen", | |||
389 | cmd_args->background_qlen); | |||
390 | if (ret < 0) { | |||
391 | gf_log("glusterfsd", GF_LOG_ERROR, "failed to set dict "do { do { if (0) printf ("failed to set dict " "value for key background-qlen" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 392, GF_LOG_ERROR, "failed to set dict " "value for key background-qlen" ); } while (0) | |||
392 | "value for key background-qlen")do { do { if (0) printf ("failed to set dict " "value for key background-qlen" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 392, GF_LOG_ERROR, "failed to set dict " "value for key background-qlen" ); } while (0); | |||
393 | goto err; | |||
394 | } | |||
395 | } | |||
396 | if (cmd_args->congestion_threshold) { | |||
397 | ret = dict_set_int32 (options, "congestion-threshold", | |||
398 | cmd_args->congestion_threshold); | |||
399 | if (ret < 0) { | |||
400 | gf_log("glusterfsd", GF_LOG_ERROR, "failed to set dict "do { do { if (0) printf ("failed to set dict " "value for key congestion-threshold" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 401, GF_LOG_ERROR, "failed to set dict " "value for key congestion-threshold" ); } while (0) | |||
401 | "value for key congestion-threshold")do { do { if (0) printf ("failed to set dict " "value for key congestion-threshold" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 401, GF_LOG_ERROR, "failed to set dict " "value for key congestion-threshold" ); } while (0); | |||
402 | goto err; | |||
403 | } | |||
404 | } | |||
405 | ||||
406 | switch (cmd_args->fuse_direct_io_mode) { | |||
407 | case GF_OPTION_DISABLE_gf_false: /* disable */ | |||
408 | ret = dict_set_static_ptr (options, ZR_DIRECT_IO_OPT"direct-io-mode", | |||
409 | "disable"); | |||
410 | if (ret < 0) { | |||
411 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set 'disable' for key %s" , "direct-io-mode"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 413, GF_LOG_ERROR, "failed to set 'disable' for key %s" , "direct-io-mode"); } while (0) | |||
412 | "failed to set 'disable' for key %s",do { do { if (0) printf ("failed to set 'disable' for key %s" , "direct-io-mode"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 413, GF_LOG_ERROR, "failed to set 'disable' for key %s" , "direct-io-mode"); } while (0) | |||
413 | ZR_DIRECT_IO_OPT)do { do { if (0) printf ("failed to set 'disable' for key %s" , "direct-io-mode"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 413, GF_LOG_ERROR, "failed to set 'disable' for key %s" , "direct-io-mode"); } while (0); | |||
414 | goto err; | |||
415 | } | |||
416 | break; | |||
417 | case GF_OPTION_ENABLE_gf_true: /* enable */ | |||
418 | ret = dict_set_static_ptr (options, ZR_DIRECT_IO_OPT"direct-io-mode", | |||
419 | "enable"); | |||
420 | if (ret < 0) { | |||
421 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set 'enable' for key %s", "direct-io-mode"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 423, GF_LOG_ERROR, "failed to set 'enable' for key %s" , "direct-io-mode"); } while (0) | |||
422 | "failed to set 'enable' for key %s",do { do { if (0) printf ("failed to set 'enable' for key %s", "direct-io-mode"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 423, GF_LOG_ERROR, "failed to set 'enable' for key %s" , "direct-io-mode"); } while (0) | |||
423 | ZR_DIRECT_IO_OPT)do { do { if (0) printf ("failed to set 'enable' for key %s", "direct-io-mode"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 423, GF_LOG_ERROR, "failed to set 'enable' for key %s" , "direct-io-mode"); } while (0); | |||
424 | goto err; | |||
425 | } | |||
426 | break; | |||
427 | case GF_OPTION_DEFERRED2: /* default */ | |||
428 | default: | |||
429 | gf_log ("", GF_LOG_DEBUG, "fuse direct io type %d",do { do { if (0) printf ("fuse direct io type %d", cmd_args-> fuse_direct_io_mode); } while (0); _gf_log ("", "glusterfsd.c" , __FUNCTION__, 430, GF_LOG_DEBUG, "fuse direct io type %d", cmd_args ->fuse_direct_io_mode); } while (0) | |||
430 | cmd_args->fuse_direct_io_mode)do { do { if (0) printf ("fuse direct io type %d", cmd_args-> fuse_direct_io_mode); } while (0); _gf_log ("", "glusterfsd.c" , __FUNCTION__, 430, GF_LOG_DEBUG, "fuse direct io type %d", cmd_args ->fuse_direct_io_mode); } while (0); | |||
431 | break; | |||
432 | } | |||
433 | ||||
434 | if (!cmd_args->no_daemon_mode) { | |||
435 | ret = dict_set_static_ptr (options, "sync-to-mount", | |||
436 | "enable"); | |||
437 | if (ret < 0) { | |||
438 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key sync-mtab" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 439, GF_LOG_ERROR, "failed to set dict value for key sync-mtab" ); } while (0) | |||
439 | "failed to set dict value for key sync-mtab")do { do { if (0) printf ("failed to set dict value for key sync-mtab" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 439, GF_LOG_ERROR, "failed to set dict value for key sync-mtab" ); } while (0); | |||
440 | goto err; | |||
441 | } | |||
442 | } | |||
443 | ret = 0; | |||
444 | err: | |||
445 | return ret; | |||
446 | } | |||
447 | ||||
448 | int | |||
449 | create_fuse_mount (glusterfs_ctx_t *ctx) | |||
450 | { | |||
451 | int ret = 0; | |||
452 | cmd_args_t *cmd_args = NULL((void*)0); | |||
453 | xlator_t *master = NULL((void*)0); | |||
454 | ||||
455 | cmd_args = &ctx->cmd_args; | |||
456 | ||||
457 | if (!cmd_args->mount_point) { | |||
458 | gf_log ("", GF_LOG_TRACE,do { do { if (0) printf ("mount point not found, not a client process" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 459 , GF_LOG_TRACE, "mount point not found, not a client process" ); } while (0) | |||
459 | "mount point not found, not a client process")do { do { if (0) printf ("mount point not found, not a client process" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 459 , GF_LOG_TRACE, "mount point not found, not a client process" ); } while (0); | |||
460 | return 0; | |||
461 | } | |||
462 | ||||
463 | if (ctx->process_mode != GF_CLIENT_PROCESS1) { | |||
464 | gf_log("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("Not a client process, not performing mount operation" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 465, GF_LOG_ERROR, "Not a client process, not performing mount operation" ); } while (0) | |||
465 | "Not a client process, not performing mount operation")do { do { if (0) printf ("Not a client process, not performing mount operation" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 465, GF_LOG_ERROR, "Not a client process, not performing mount operation" ); } while (0); | |||
466 | return -1; | |||
467 | } | |||
468 | ||||
469 | master = GF_CALLOC (1, sizeof (*master),__gf_calloc (1, sizeof (*master), gfd_mt_xlator_t) | |||
470 | gfd_mt_xlator_t)__gf_calloc (1, sizeof (*master), gfd_mt_xlator_t); | |||
471 | if (!master) | |||
472 | goto err; | |||
473 | ||||
474 | master->name = gf_strdup ("fuse"); | |||
475 | if (!master->name) | |||
476 | goto err; | |||
477 | ||||
478 | if (xlator_set_type (master, "mount/fuse") == -1) { | |||
479 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("MOUNT-POINT %s initialization failed" , cmd_args->mount_point); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 481, GF_LOG_ERROR, "MOUNT-POINT %s initialization failed" , cmd_args->mount_point); } while (0) | |||
480 | "MOUNT-POINT %s initialization failed",do { do { if (0) printf ("MOUNT-POINT %s initialization failed" , cmd_args->mount_point); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 481, GF_LOG_ERROR, "MOUNT-POINT %s initialization failed" , cmd_args->mount_point); } while (0) | |||
481 | cmd_args->mount_point)do { do { if (0) printf ("MOUNT-POINT %s initialization failed" , cmd_args->mount_point); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 481, GF_LOG_ERROR, "MOUNT-POINT %s initialization failed" , cmd_args->mount_point); } while (0); | |||
482 | goto err; | |||
483 | } | |||
484 | ||||
485 | master->ctx = ctx; | |||
486 | master->options = get_new_dict (); | |||
487 | if (!master->options) | |||
488 | goto err; | |||
489 | ||||
490 | ret = set_fuse_mount_options (ctx, master->options); | |||
491 | if (ret) | |||
492 | goto err; | |||
493 | ||||
494 | if (cmd_args->fuse_mountopts) { | |||
495 | ret = dict_set_static_ptr (master->options, ZR_FUSE_MOUNTOPTS"fuse-mountopts", | |||
496 | cmd_args->fuse_mountopts); | |||
497 | if (ret < 0) { | |||
498 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value for key %s" , "fuse-mountopts"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 500, GF_LOG_ERROR, "failed to set dict value for key %s" , "fuse-mountopts"); } while (0) | |||
499 | "failed to set dict value for key %s",do { do { if (0) printf ("failed to set dict value for key %s" , "fuse-mountopts"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 500, GF_LOG_ERROR, "failed to set dict value for key %s" , "fuse-mountopts"); } while (0) | |||
500 | ZR_FUSE_MOUNTOPTS)do { do { if (0) printf ("failed to set dict value for key %s" , "fuse-mountopts"); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 500, GF_LOG_ERROR, "failed to set dict value for key %s" , "fuse-mountopts"); } while (0); | |||
501 | goto err; | |||
502 | } | |||
503 | } | |||
504 | ||||
505 | ret = xlator_init (master); | |||
506 | if (ret) { | |||
507 | gf_log ("", GF_LOG_DEBUG, "failed to initialize fuse translator")do { do { if (0) printf ("failed to initialize fuse translator" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 507 , GF_LOG_DEBUG, "failed to initialize fuse translator"); } while (0); | |||
508 | goto err; | |||
509 | } | |||
510 | ||||
511 | ctx->master = master; | |||
512 | ||||
513 | return 0; | |||
514 | ||||
515 | err: | |||
516 | if (master) { | |||
517 | xlator_destroy (master); | |||
518 | } | |||
519 | ||||
520 | return 1; | |||
521 | } | |||
522 | ||||
523 | ||||
524 | static FILE * | |||
525 | get_volfp (glusterfs_ctx_t *ctx) | |||
526 | { | |||
527 | int ret = 0; | |||
528 | cmd_args_t *cmd_args = NULL((void*)0); | |||
529 | FILE *specfp = NULL((void*)0); | |||
530 | struct stat statbuf; | |||
531 | ||||
532 | cmd_args = &ctx->cmd_args; | |||
533 | ||||
534 | ret = sys_lstat (cmd_args->volfile, &statbuf); | |||
535 | if (ret == -1) { | |||
536 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("%s: %s", cmd_args->volfile, strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 537, GF_LOG_ERROR, "%s: %s", cmd_args ->volfile, strerror ((*__errno_location ()))); } while (0) | |||
537 | "%s: %s", cmd_args->volfile, strerror (errno))do { do { if (0) printf ("%s: %s", cmd_args->volfile, strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 537, GF_LOG_ERROR, "%s: %s", cmd_args ->volfile, strerror ((*__errno_location ()))); } while (0); | |||
538 | return NULL((void*)0); | |||
539 | } | |||
540 | ||||
541 | if ((specfp = fopen (cmd_args->volfile, "r")) == NULL((void*)0)) { | |||
542 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("volume file %s: %s", cmd_args->volfile , strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 545, GF_LOG_ERROR, "volume file %s: %s" , cmd_args->volfile, strerror ((*__errno_location ()))); } while (0) | |||
543 | "volume file %s: %s",do { do { if (0) printf ("volume file %s: %s", cmd_args->volfile , strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 545, GF_LOG_ERROR, "volume file %s: %s" , cmd_args->volfile, strerror ((*__errno_location ()))); } while (0) | |||
544 | cmd_args->volfile,do { do { if (0) printf ("volume file %s: %s", cmd_args->volfile , strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 545, GF_LOG_ERROR, "volume file %s: %s" , cmd_args->volfile, strerror ((*__errno_location ()))); } while (0) | |||
545 | strerror (errno))do { do { if (0) printf ("volume file %s: %s", cmd_args->volfile , strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 545, GF_LOG_ERROR, "volume file %s: %s" , cmd_args->volfile, strerror ((*__errno_location ()))); } while (0); | |||
546 | return NULL((void*)0); | |||
547 | } | |||
548 | ||||
549 | gf_log ("glusterfsd", GF_LOG_DEBUG,do { do { if (0) printf ("loading volume file %s", cmd_args-> volfile); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 550, GF_LOG_DEBUG, "loading volume file %s", cmd_args ->volfile); } while (0) | |||
550 | "loading volume file %s", cmd_args->volfile)do { do { if (0) printf ("loading volume file %s", cmd_args-> volfile); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 550, GF_LOG_DEBUG, "loading volume file %s", cmd_args ->volfile); } while (0); | |||
551 | ||||
552 | return specfp; | |||
553 | } | |||
554 | ||||
555 | static int | |||
556 | gf_remember_xlator_option (struct list_head *options, char *arg) | |||
557 | { | |||
558 | glusterfs_ctx_t *ctx = NULL((void*)0); | |||
559 | cmd_args_t *cmd_args = NULL((void*)0); | |||
560 | xlator_cmdline_option_t *option = NULL((void*)0); | |||
561 | int ret = -1; | |||
562 | char *dot = NULL((void*)0); | |||
563 | char *equals = NULL((void*)0); | |||
564 | ||||
565 | ctx = glusterfsd_ctx; | |||
566 | cmd_args = &ctx->cmd_args; | |||
567 | ||||
568 | option = GF_CALLOC (1, sizeof (xlator_cmdline_option_t),__gf_calloc (1, sizeof (xlator_cmdline_option_t), gfd_mt_xlator_cmdline_option_t ) | |||
569 | gfd_mt_xlator_cmdline_option_t)__gf_calloc (1, sizeof (xlator_cmdline_option_t), gfd_mt_xlator_cmdline_option_t ); | |||
570 | if (!option) | |||
571 | goto out; | |||
572 | ||||
573 | INIT_LIST_HEAD (&option->cmd_args)do { (&option->cmd_args)->next = (&option->cmd_args )->prev = &option->cmd_args; } while (0); | |||
574 | ||||
575 | dot = strchr (arg, '.'); | |||
576 | if (!dot) { | |||
577 | gf_log ("", GF_LOG_WARNING,do { do { if (0) printf ("xlator option %s is invalid", arg); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 578, GF_LOG_WARNING, "xlator option %s is invalid", arg); } while (0) | |||
578 | "xlator option %s is invalid", arg)do { do { if (0) printf ("xlator option %s is invalid", arg); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 578, GF_LOG_WARNING, "xlator option %s is invalid", arg); } while (0); | |||
579 | goto out; | |||
580 | } | |||
581 | ||||
582 | option->volume = GF_CALLOC ((dot - arg) + 1, sizeof (char),__gf_calloc ((dot - arg) + 1, sizeof (char), gfd_mt_char) | |||
583 | gfd_mt_char)__gf_calloc ((dot - arg) + 1, sizeof (char), gfd_mt_char); | |||
584 | if (!option->volume) | |||
585 | goto out; | |||
586 | ||||
587 | strncpy (option->volume, arg, (dot - arg)); | |||
588 | ||||
589 | equals = strchr (arg, '='); | |||
590 | if (!equals) { | |||
591 | gf_log ("", GF_LOG_WARNING,do { do { if (0) printf ("xlator option %s is invalid", arg); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 592, GF_LOG_WARNING, "xlator option %s is invalid", arg); } while (0) | |||
592 | "xlator option %s is invalid", arg)do { do { if (0) printf ("xlator option %s is invalid", arg); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 592, GF_LOG_WARNING, "xlator option %s is invalid", arg); } while (0); | |||
593 | goto out; | |||
594 | } | |||
595 | ||||
596 | option->key = GF_CALLOC ((equals - dot) + 1, sizeof (char),__gf_calloc ((equals - dot) + 1, sizeof (char), gfd_mt_char) | |||
597 | gfd_mt_char)__gf_calloc ((equals - dot) + 1, sizeof (char), gfd_mt_char); | |||
598 | if (!option->key) | |||
599 | goto out; | |||
600 | ||||
601 | strncpy (option->key, dot + 1, (equals - dot - 1)); | |||
602 | ||||
603 | if (!*(equals + 1)) { | |||
604 | gf_log ("", GF_LOG_WARNING,do { do { if (0) printf ("xlator option %s is invalid", arg); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 605, GF_LOG_WARNING, "xlator option %s is invalid", arg); } while (0) | |||
605 | "xlator option %s is invalid", arg)do { do { if (0) printf ("xlator option %s is invalid", arg); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 605, GF_LOG_WARNING, "xlator option %s is invalid", arg); } while (0); | |||
606 | goto out; | |||
607 | } | |||
608 | ||||
609 | option->value = gf_strdup (equals + 1); | |||
610 | ||||
611 | list_add (&option->cmd_args, &cmd_args->xlator_options); | |||
612 | ||||
613 | ret = 0; | |||
614 | out: | |||
615 | if (ret == -1) { | |||
616 | if (option) { | |||
617 | GF_FREE (option->volume)__gf_free (option->volume); | |||
618 | GF_FREE (option->key)__gf_free (option->key); | |||
619 | GF_FREE (option->value)__gf_free (option->value); | |||
620 | ||||
621 | GF_FREE (option)__gf_free (option); | |||
622 | } | |||
623 | } | |||
624 | ||||
625 | return ret; | |||
626 | } | |||
627 | ||||
628 | ||||
629 | ||||
630 | static error_t | |||
631 | parse_opts (int key, char *arg, struct argp_state *state) | |||
632 | { | |||
633 | cmd_args_t *cmd_args = NULL((void*)0); | |||
634 | uint32_t n = 0; | |||
635 | double d = 0.0; | |||
636 | gf_boolean_t b = _gf_false; | |||
637 | char *pwd = NULL((void*)0); | |||
638 | char tmp_buf[2048] = {0,}; | |||
639 | char *tmp_str = NULL((void*)0); | |||
640 | char *port_str = NULL((void*)0); | |||
641 | struct passwd *pw = NULL((void*)0); | |||
642 | ||||
643 | cmd_args = state->input; | |||
644 | ||||
645 | switch (key) { | |||
646 | case ARGP_VOLFILE_SERVER_KEY: | |||
647 | cmd_args->volfile_server = gf_strdup (arg); | |||
648 | break; | |||
649 | ||||
650 | case ARGP_VOLFILE_MAX_FETCH_ATTEMPTS: | |||
651 | n = 0; | |||
652 | ||||
653 | if (gf_string2uint_base10 (arg, &n) == 0) { | |||
654 | cmd_args->max_connect_attempts = n; | |||
655 | break; | |||
656 | } | |||
657 | ||||
658 | argp_failure (state, -1, 0, | |||
659 | "Invalid limit on connect attempts %s", arg); | |||
660 | break; | |||
661 | ||||
662 | case ARGP_READ_ONLY_KEY: | |||
663 | cmd_args->read_only = 1; | |||
664 | break; | |||
665 | ||||
666 | case ARGP_ACL_KEY: | |||
667 | cmd_args->acl = 1; | |||
668 | gf_remember_xlator_option (&cmd_args->xlator_options, | |||
669 | "*-md-cache.cache-posix-acl=true"); | |||
670 | break; | |||
671 | ||||
672 | case ARGP_SELINUX_KEY: | |||
673 | cmd_args->selinux = 1; | |||
674 | gf_remember_xlator_option (&cmd_args->xlator_options, | |||
675 | "*-md-cache.cache-selinux=true"); | |||
676 | break; | |||
677 | ||||
678 | case ARGP_INODE32_KEY: | |||
679 | cmd_args->enable_ino32 = 1; | |||
680 | break; | |||
681 | ||||
682 | case ARGP_WORM_KEY: | |||
683 | cmd_args->worm = 1; | |||
684 | break; | |||
685 | ||||
686 | case ARGP_MAC_COMPAT_KEY: | |||
687 | if (!arg) | |||
688 | arg = "on"; | |||
689 | ||||
690 | if (gf_string2boolean (arg, &b) == 0) { | |||
691 | cmd_args->mac_compat = b; | |||
692 | ||||
693 | break; | |||
694 | } | |||
695 | ||||
696 | argp_failure (state, -1, 0, | |||
697 | "invalid value \"%s\" for mac-compat", arg); | |||
698 | break; | |||
699 | ||||
700 | case ARGP_VOLUME_FILE_KEY: | |||
701 | GF_FREE (cmd_args->volfile)__gf_free (cmd_args->volfile); | |||
702 | ||||
703 | if (arg[0] != '/') { | |||
704 | pwd = getcwd (NULL((void*)0), PATH_MAX4096); | |||
705 | if (!pwd) { | |||
706 | argp_failure (state, -1, errno(*__errno_location ()), | |||
707 | "getcwd failed with error no %d", | |||
708 | errno(*__errno_location ())); | |||
709 | break; | |||
710 | } | |||
711 | snprintf (tmp_buf, 1024, "%s/%s", pwd, arg); | |||
712 | cmd_args->volfile = gf_strdup (tmp_buf); | |||
713 | free (pwd); | |||
714 | } else { | |||
715 | cmd_args->volfile = gf_strdup (arg); | |||
716 | } | |||
717 | ||||
718 | break; | |||
719 | ||||
720 | case ARGP_LOG_LEVEL_KEY: | |||
721 | if (strcasecmp (arg, ARGP_LOG_LEVEL_NONE_OPTION"NONE") == 0) { | |||
722 | cmd_args->log_level = GF_LOG_NONE; | |||
723 | break; | |||
724 | } | |||
725 | if (strcasecmp (arg, ARGP_LOG_LEVEL_CRITICAL_OPTION"CRITICAL") == 0) { | |||
726 | cmd_args->log_level = GF_LOG_CRITICAL; | |||
727 | break; | |||
728 | } | |||
729 | if (strcasecmp (arg, ARGP_LOG_LEVEL_ERROR_OPTION"ERROR") == 0) { | |||
730 | cmd_args->log_level = GF_LOG_ERROR; | |||
731 | break; | |||
732 | } | |||
733 | if (strcasecmp (arg, ARGP_LOG_LEVEL_WARNING_OPTION"WARNING") == 0) { | |||
734 | cmd_args->log_level = GF_LOG_WARNING; | |||
735 | break; | |||
736 | } | |||
737 | if (strcasecmp (arg, ARGP_LOG_LEVEL_INFO_OPTION"INFO") == 0) { | |||
738 | cmd_args->log_level = GF_LOG_INFO; | |||
739 | break; | |||
740 | } | |||
741 | if (strcasecmp (arg, ARGP_LOG_LEVEL_DEBUG_OPTION"DEBUG") == 0) { | |||
742 | cmd_args->log_level = GF_LOG_DEBUG; | |||
743 | break; | |||
744 | } | |||
745 | if (strcasecmp (arg, ARGP_LOG_LEVEL_TRACE_OPTION"TRACE") == 0) { | |||
746 | cmd_args->log_level = GF_LOG_TRACE; | |||
747 | break; | |||
748 | } | |||
749 | ||||
750 | argp_failure (state, -1, 0, "unknown log level %s", arg); | |||
751 | break; | |||
752 | ||||
753 | case ARGP_LOG_FILE_KEY: | |||
754 | cmd_args->log_file = gf_strdup (arg); | |||
755 | break; | |||
756 | ||||
757 | case ARGP_VOLFILE_SERVER_PORT_KEY: | |||
758 | n = 0; | |||
759 | ||||
760 | if (gf_string2uint_base10 (arg, &n) == 0) { | |||
761 | cmd_args->volfile_server_port = n; | |||
762 | break; | |||
763 | } | |||
764 | ||||
765 | argp_failure (state, -1, 0, | |||
766 | "unknown volfile server port %s", arg); | |||
767 | break; | |||
768 | ||||
769 | case ARGP_VOLFILE_SERVER_TRANSPORT_KEY: | |||
770 | cmd_args->volfile_server_transport = gf_strdup (arg); | |||
771 | break; | |||
772 | ||||
773 | case ARGP_VOLFILE_ID_KEY: | |||
774 | cmd_args->volfile_id = gf_strdup (arg); | |||
775 | break; | |||
776 | ||||
777 | case ARGP_PID_FILE_KEY: | |||
778 | cmd_args->pid_file = gf_strdup (arg); | |||
779 | break; | |||
780 | ||||
781 | case ARGP_SOCK_FILE_KEY: | |||
782 | cmd_args->sock_file = gf_strdup (arg); | |||
783 | break; | |||
784 | ||||
785 | case ARGP_NO_DAEMON_KEY: | |||
786 | cmd_args->no_daemon_mode = ENABLE_NO_DAEMON_MODE1; | |||
787 | break; | |||
788 | ||||
789 | case ARGP_RUN_ID_KEY: | |||
790 | cmd_args->run_id = gf_strdup (arg); | |||
791 | break; | |||
792 | ||||
793 | case ARGP_DEBUG_KEY: | |||
794 | cmd_args->debug_mode = ENABLE_DEBUG_MODE1; | |||
795 | break; | |||
796 | ||||
797 | case ARGP_DIRECT_IO_MODE_KEY: | |||
798 | if (!arg) | |||
799 | arg = "on"; | |||
800 | ||||
801 | if (gf_string2boolean (arg, &b) == 0) { | |||
802 | cmd_args->fuse_direct_io_mode = b; | |||
803 | ||||
804 | break; | |||
805 | } | |||
806 | ||||
807 | argp_failure (state, -1, 0, | |||
808 | "unknown direct I/O mode setting \"%s\"", arg); | |||
809 | break; | |||
810 | ||||
811 | case ARGP_ENTRY_TIMEOUT_KEY: | |||
812 | d = 0.0; | |||
813 | ||||
814 | gf_string2double (arg, &d); | |||
815 | if (!(d < 0.0)) { | |||
816 | cmd_args->fuse_entry_timeout = d; | |||
817 | break; | |||
818 | } | |||
819 | ||||
820 | argp_failure (state, -1, 0, "unknown entry timeout %s", arg); | |||
821 | break; | |||
822 | ||||
823 | case ARGP_NEGATIVE_TIMEOUT_KEY: | |||
824 | d = 0.0; | |||
825 | ||||
826 | gf_string2double (arg, &d); | |||
827 | if (!(d < 0.0)) { | |||
828 | cmd_args->fuse_negative_timeout = d; | |||
829 | break; | |||
830 | } | |||
831 | ||||
832 | argp_failure (state, -1, 0, "unknown negative timeout %s", arg); | |||
833 | break; | |||
834 | ||||
835 | case ARGP_ATTRIBUTE_TIMEOUT_KEY: | |||
836 | d = 0.0; | |||
837 | ||||
838 | gf_string2double (arg, &d); | |||
839 | if (!(d < 0.0)) { | |||
840 | cmd_args->fuse_attribute_timeout = d; | |||
841 | break; | |||
842 | } | |||
843 | ||||
844 | argp_failure (state, -1, 0, | |||
845 | "unknown attribute timeout %s", arg); | |||
846 | break; | |||
847 | ||||
848 | case ARGP_CLIENT_PID_KEY: | |||
849 | if (gf_string2int (arg, &cmd_args->client_pid) == 0) { | |||
850 | cmd_args->client_pid_set = 1; | |||
851 | break; | |||
852 | } | |||
853 | ||||
854 | argp_failure (state, -1, 0, | |||
855 | "unknown client pid %s", arg); | |||
856 | break; | |||
857 | ||||
858 | case ARGP_USER_MAP_ROOT_KEY: | |||
859 | pw = getpwnam (arg); | |||
860 | if (pw) | |||
861 | cmd_args->uid_map_root = pw->pw_uid; | |||
862 | else | |||
863 | argp_failure (state, -1, 0, | |||
864 | "user %s does not exist", arg); | |||
865 | break; | |||
866 | ||||
867 | case ARGP_VOLFILE_CHECK_KEY: | |||
868 | cmd_args->volfile_check = 1; | |||
869 | break; | |||
870 | ||||
871 | case ARGP_VOLUME_NAME_KEY: | |||
872 | cmd_args->volume_name = gf_strdup (arg); | |||
873 | break; | |||
874 | ||||
875 | case ARGP_XLATOR_OPTION_KEY: | |||
876 | if (gf_remember_xlator_option (&cmd_args->xlator_options, arg)) | |||
877 | argp_failure (state, -1, 0, "invalid xlator option %s", arg); | |||
878 | ||||
879 | break; | |||
880 | ||||
881 | case ARGP_KEY_NO_ARGS0x1000002: | |||
882 | break; | |||
883 | ||||
884 | case ARGP_KEY_ARG0: | |||
885 | if (state->arg_num >= 1) | |||
886 | argp_usage (state); | |||
887 | ||||
888 | cmd_args->mount_point = gf_strdup (arg); | |||
889 | break; | |||
890 | ||||
891 | case ARGP_DUMP_FUSE_KEY: | |||
892 | cmd_args->dump_fuse = gf_strdup (arg); | |||
893 | break; | |||
894 | case ARGP_BRICK_NAME_KEY: | |||
895 | cmd_args->brick_name = gf_strdup (arg); | |||
896 | break; | |||
897 | case ARGP_BRICK_PORT_KEY: | |||
898 | n = 0; | |||
899 | ||||
900 | port_str = strtok_r (arg, ",", &tmp_str); | |||
901 | if (gf_string2uint_base10 (port_str, &n) == 0) { | |||
902 | cmd_args->brick_port = n; | |||
903 | port_str = strtok_r (NULL((void*)0), ",", &tmp_str); | |||
904 | if (port_str) { | |||
905 | if (gf_string2uint_base10 (port_str, &n) == 0) | |||
906 | cmd_args->brick_port2 = n; | |||
907 | break; | |||
908 | ||||
909 | argp_failure (state, -1, 0, | |||
910 | "wrong brick (listen) port %s", arg); | |||
911 | } | |||
912 | break; | |||
913 | } | |||
914 | ||||
915 | argp_failure (state, -1, 0, | |||
916 | "unknown brick (listen) port %s", arg); | |||
917 | break; | |||
918 | ||||
919 | case ARGP_MEM_ACCOUNTING_KEY: | |||
920 | /* TODO: it should have got handled much earlier */ | |||
921 | //gf_mem_acct_enable_set (THIS->ctx); | |||
922 | break; | |||
923 | ||||
924 | case ARGP_FOPEN_KEEP_CACHE_KEY: | |||
925 | cmd_args->fopen_keep_cache = 1; | |||
926 | break; | |||
927 | ||||
928 | case ARGP_GID_TIMEOUT_KEY: | |||
929 | if (!gf_string2int(arg, &cmd_args->gid_timeout)) | |||
930 | break; | |||
931 | ||||
932 | argp_failure(state, -1, 0, "unknown group list timeout %s", arg); | |||
933 | break; | |||
934 | case ARGP_FUSE_BACKGROUND_QLEN_KEY: | |||
935 | if (!gf_string2int (arg, &cmd_args->background_qlen)) | |||
936 | break; | |||
937 | ||||
938 | argp_failure (state, -1, 0, | |||
939 | "unknown background qlen option %s", arg); | |||
940 | break; | |||
941 | case ARGP_FUSE_CONGESTION_THRESHOLD_KEY: | |||
942 | if (!gf_string2int (arg, &cmd_args->congestion_threshold)) | |||
943 | break; | |||
944 | ||||
945 | argp_failure (state, -1, 0, | |||
946 | "unknown congestion threshold option %s", arg); | |||
947 | break; | |||
948 | ||||
949 | case ARGP_FUSE_MOUNTOPTS_KEY: | |||
950 | cmd_args->fuse_mountopts = gf_strdup (arg); | |||
951 | break; | |||
952 | } | |||
953 | ||||
954 | return 0; | |||
955 | } | |||
956 | ||||
957 | ||||
958 | void | |||
959 | cleanup_and_exit (int signum) | |||
960 | { | |||
961 | glusterfs_ctx_t *ctx = NULL((void*)0); | |||
962 | xlator_t *trav = NULL((void*)0); | |||
963 | ||||
964 | ctx = glusterfsd_ctx; | |||
965 | ||||
966 | if (!ctx) | |||
967 | return; | |||
968 | ||||
969 | gf_log_callingfn ("", GF_LOG_WARNING,do { do { if (0) printf ("received signum (%d), shutting down" , signum); } while (0); _gf_log_callingfn ("", "glusterfsd.c" , __FUNCTION__, 970, GF_LOG_WARNING, "received signum (%d), shutting down" , signum); } while (0) | |||
970 | "received signum (%d), shutting down", signum)do { do { if (0) printf ("received signum (%d), shutting down" , signum); } while (0); _gf_log_callingfn ("", "glusterfsd.c" , __FUNCTION__, 970, GF_LOG_WARNING, "received signum (%d), shutting down" , signum); } while (0); | |||
971 | ||||
972 | if (ctx->cleanup_started) | |||
973 | return; | |||
974 | ||||
975 | ctx->cleanup_started = 1; | |||
976 | glusterfs_mgmt_pmap_signout (ctx); | |||
977 | ||||
978 | /* below part is a racy code where the rpcsvc object is freed. | |||
979 | * But in another thread (epoll thread), upon poll error in the | |||
980 | * socket the transports are cleaned up where again rpcsvc object | |||
981 | * is accessed (which is already freed by the below function). | |||
982 | * Since the process is about to be killed dont execute the function | |||
983 | * below. | |||
984 | */ | |||
985 | /* if (ctx->listener) { */ | |||
986 | /* (void) glusterfs_listener_stop (ctx); */ | |||
987 | /* } */ | |||
988 | ||||
989 | /* Call fini() of FUSE xlator first: | |||
990 | * so there are no more requests coming and | |||
991 | * 'umount' of mount point is done properly */ | |||
992 | trav = ctx->master; | |||
993 | if (trav && trav->fini) { | |||
994 | THIS(*__glusterfs_this_location()) = trav; | |||
995 | trav->fini (trav); | |||
996 | } | |||
997 | ||||
998 | glusterfs_pidfile_cleanup (ctx); | |||
999 | ||||
1000 | exit (0); | |||
1001 | #if 0 | |||
1002 | /* TODO: Properly do cleanup_and_exit(), with synchronization */ | |||
1003 | if (ctx->mgmt) { | |||
1004 | /* cleanup the saved-frames before last unref */ | |||
1005 | rpc_clnt_connection_cleanup (&ctx->mgmt->conn); | |||
1006 | rpc_clnt_unref (ctx->mgmt); | |||
1007 | } | |||
1008 | ||||
1009 | /* call fini() of each xlator */ | |||
1010 | trav = NULL((void*)0); | |||
1011 | if (ctx->active) | |||
1012 | trav = ctx->active->top; | |||
1013 | while (trav) { | |||
1014 | if (trav->fini) { | |||
1015 | THIS(*__glusterfs_this_location()) = trav; | |||
1016 | trav->fini (trav); | |||
1017 | } | |||
1018 | trav = trav->next; | |||
1019 | } | |||
1020 | #endif | |||
1021 | } | |||
1022 | ||||
1023 | ||||
1024 | static void | |||
1025 | reincarnate (int signum) | |||
1026 | { | |||
1027 | int ret = 0; | |||
1028 | glusterfs_ctx_t *ctx = NULL((void*)0); | |||
1029 | cmd_args_t *cmd_args = NULL((void*)0); | |||
1030 | ||||
1031 | ctx = glusterfsd_ctx; | |||
1032 | cmd_args = &ctx->cmd_args; | |||
1033 | ||||
1034 | if (cmd_args->volfile_server) { | |||
| ||||
1035 | gf_log ("glusterfsd", GF_LOG_INFO,do { do { if (0) printf ("Fetching the volume file from server..." ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1036, GF_LOG_INFO, "Fetching the volume file from server..." ); } while (0) | |||
1036 | "Fetching the volume file from server...")do { do { if (0) printf ("Fetching the volume file from server..." ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1036, GF_LOG_INFO, "Fetching the volume file from server..." ); } while (0); | |||
1037 | ret = glusterfs_volfile_fetch (ctx); | |||
1038 | } else { | |||
1039 | gf_log ("glusterfsd", GF_LOG_DEBUG,do { do { if (0) printf ("Not reloading volume specification file on SIGHUP" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1040, GF_LOG_DEBUG, "Not reloading volume specification file on SIGHUP" ); } while (0) | |||
1040 | "Not reloading volume specification file on SIGHUP")do { do { if (0) printf ("Not reloading volume specification file on SIGHUP" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1040, GF_LOG_DEBUG, "Not reloading volume specification file on SIGHUP" ); } while (0); | |||
1041 | } | |||
1042 | ||||
1043 | /* Also, SIGHUP should do logrotate */ | |||
1044 | gf_log_logrotate (1); | |||
1045 | ||||
1046 | if (ret < 0) | |||
1047 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("volume initialization failed."); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1048 , GF_LOG_ERROR, "volume initialization failed."); } while (0) | |||
1048 | "volume initialization failed.")do { do { if (0) printf ("volume initialization failed."); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1048 , GF_LOG_ERROR, "volume initialization failed."); } while (0); | |||
1049 | ||||
1050 | return; | |||
1051 | } | |||
1052 | ||||
1053 | void | |||
1054 | emancipate (glusterfs_ctx_t *ctx, int ret) | |||
1055 | { | |||
1056 | /* break free from the parent */ | |||
1057 | if (ctx->daemon_pipe[1] != -1) { | |||
1058 | write (ctx->daemon_pipe[1], (void *) &ret, sizeof (ret)); | |||
1059 | close (ctx->daemon_pipe[1]); | |||
1060 | ctx->daemon_pipe[1] = -1; | |||
1061 | } | |||
1062 | } | |||
1063 | ||||
1064 | static uint8_t | |||
1065 | gf_get_process_mode (char *exec_name) | |||
1066 | { | |||
1067 | char *dup_execname = NULL((void*)0), *base = NULL((void*)0); | |||
1068 | uint8_t ret = 0; | |||
1069 | ||||
1070 | dup_execname = gf_strdup (exec_name); | |||
1071 | base = basename__xpg_basename (dup_execname); | |||
1072 | ||||
1073 | if (!strncmp (base, "glusterfsd", 10)) { | |||
1074 | ret = GF_SERVER_PROCESS0; | |||
1075 | } else if (!strncmp (base, "glusterd", 8)) { | |||
1076 | ret = GF_GLUSTERD_PROCESS2; | |||
1077 | } else { | |||
1078 | ret = GF_CLIENT_PROCESS1; | |||
1079 | } | |||
1080 | ||||
1081 | GF_FREE (dup_execname)__gf_free (dup_execname); | |||
1082 | ||||
1083 | return ret; | |||
1084 | } | |||
1085 | ||||
1086 | ||||
1087 | ||||
1088 | static int | |||
1089 | set_log_file_path (cmd_args_t *cmd_args) | |||
1090 | { | |||
1091 | int i = 0; | |||
1092 | int j = 0; | |||
1093 | int ret = 0; | |||
1094 | int port = 0; | |||
1095 | char *tmp_ptr = NULL((void*)0); | |||
1096 | char tmp_str[1024] = {0,}; | |||
1097 | ||||
1098 | if (cmd_args->mount_point) { | |||
1099 | j = 0; | |||
1100 | i = 0; | |||
1101 | if (cmd_args->mount_point[0] == '/') | |||
1102 | i = 1; | |||
1103 | for (; i < strlen (cmd_args->mount_point); i++,j++) { | |||
1104 | tmp_str[j] = cmd_args->mount_point[i]; | |||
1105 | if (cmd_args->mount_point[i] == '/') | |||
1106 | tmp_str[j] = '-'; | |||
1107 | } | |||
1108 | ||||
1109 | ret = gf_asprintf (&cmd_args->log_file, | |||
1110 | DEFAULT_LOG_FILE_DIRECTORY"/usr/local/var" "/log/glusterfs" "/%s.log", | |||
1111 | tmp_str); | |||
1112 | goto done; | |||
1113 | } | |||
1114 | ||||
1115 | if (cmd_args->volfile) { | |||
1116 | j = 0; | |||
1117 | i = 0; | |||
1118 | if (cmd_args->volfile[0] == '/') | |||
1119 | i = 1; | |||
1120 | for (; i < strlen (cmd_args->volfile); i++,j++) { | |||
1121 | tmp_str[j] = cmd_args->volfile[i]; | |||
1122 | if (cmd_args->volfile[i] == '/') | |||
1123 | tmp_str[j] = '-'; | |||
1124 | } | |||
1125 | ret = gf_asprintf (&cmd_args->log_file, | |||
1126 | DEFAULT_LOG_FILE_DIRECTORY"/usr/local/var" "/log/glusterfs" "/%s.log", | |||
1127 | tmp_str); | |||
1128 | goto done; | |||
1129 | } | |||
1130 | ||||
1131 | if (cmd_args->volfile_server) { | |||
1132 | port = 1; | |||
1133 | tmp_ptr = "default"; | |||
1134 | ||||
1135 | if (cmd_args->volfile_server_port) | |||
1136 | port = cmd_args->volfile_server_port; | |||
1137 | if (cmd_args->volfile_id) | |||
1138 | tmp_ptr = cmd_args->volfile_id; | |||
1139 | ||||
1140 | ret = gf_asprintf (&cmd_args->log_file, | |||
1141 | DEFAULT_LOG_FILE_DIRECTORY"/usr/local/var" "/log/glusterfs" "/%s-%s-%d.log", | |||
1142 | cmd_args->volfile_server, tmp_ptr, port); | |||
1143 | } | |||
1144 | done: | |||
1145 | return ret; | |||
1146 | } | |||
1147 | ||||
1148 | ||||
1149 | static int | |||
1150 | glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx) | |||
1151 | { | |||
1152 | cmd_args_t *cmd_args = NULL((void*)0); | |||
1153 | struct rlimit lim = {0, }; | |||
1154 | call_pool_t *pool = NULL((void*)0); | |||
1155 | int ret = -1; | |||
1156 | ||||
1157 | xlator_mem_acct_init (THIS(*__glusterfs_this_location()), gfd_mt_end); | |||
1158 | ||||
1159 | ctx->process_uuid = generate_glusterfs_ctx_id (); | |||
1160 | if (!ctx->process_uuid) { | |||
1161 | gf_log ("", GF_LOG_CRITICAL,do { do { if (0) printf ("ERROR: glusterfs uuid generation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1162 , GF_LOG_CRITICAL, "ERROR: glusterfs uuid generation failed") ; } while (0) | |||
1162 | "ERROR: glusterfs uuid generation failed")do { do { if (0) printf ("ERROR: glusterfs uuid generation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1162 , GF_LOG_CRITICAL, "ERROR: glusterfs uuid generation failed") ; } while (0); | |||
1163 | goto out; | |||
1164 | } | |||
1165 | ||||
1166 | ctx->page_size = 128 * GF_UNIT_KB1024ULL; | |||
1167 | ||||
1168 | ctx->iobuf_pool = iobuf_pool_new (); | |||
1169 | if (!ctx->iobuf_pool) { | |||
1170 | gf_log ("", GF_LOG_CRITICAL,do { do { if (0) printf ("ERROR: glusterfs iobuf pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1171 , GF_LOG_CRITICAL, "ERROR: glusterfs iobuf pool creation failed" ); } while (0) | |||
1171 | "ERROR: glusterfs iobuf pool creation failed")do { do { if (0) printf ("ERROR: glusterfs iobuf pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1171 , GF_LOG_CRITICAL, "ERROR: glusterfs iobuf pool creation failed" ); } while (0); | |||
1172 | goto out; | |||
1173 | } | |||
1174 | ||||
1175 | ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE16384); | |||
1176 | if (!ctx->event_pool) { | |||
1177 | gf_log ("", GF_LOG_CRITICAL,do { do { if (0) printf ("ERROR: glusterfs event pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1178 , GF_LOG_CRITICAL, "ERROR: glusterfs event pool creation failed" ); } while (0) | |||
1178 | "ERROR: glusterfs event pool creation failed")do { do { if (0) printf ("ERROR: glusterfs event pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1178 , GF_LOG_CRITICAL, "ERROR: glusterfs event pool creation failed" ); } while (0); | |||
1179 | goto out; | |||
1180 | } | |||
1181 | ||||
1182 | pool = GF_CALLOC (1, sizeof (call_pool_t),__gf_calloc (1, sizeof (call_pool_t), gfd_mt_call_pool_t) | |||
1183 | gfd_mt_call_pool_t)__gf_calloc (1, sizeof (call_pool_t), gfd_mt_call_pool_t); | |||
1184 | if (!pool) { | |||
1185 | gf_log ("", GF_LOG_CRITICAL,do { do { if (0) printf ("ERROR: glusterfs call pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1186 , GF_LOG_CRITICAL, "ERROR: glusterfs call pool creation failed" ); } while (0) | |||
1186 | "ERROR: glusterfs call pool creation failed")do { do { if (0) printf ("ERROR: glusterfs call pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1186 , GF_LOG_CRITICAL, "ERROR: glusterfs call pool creation failed" ); } while (0); | |||
1187 | goto out; | |||
1188 | } | |||
1189 | ||||
1190 | /* frame_mem_pool size 112 * 4k */ | |||
1191 | pool->frame_mem_pool = mem_pool_new (call_frame_t, 4096)mem_pool_new_fn (sizeof(call_frame_t), 4096, "call_frame_t"); | |||
1192 | if (!pool->frame_mem_pool) { | |||
1193 | gf_log ("", GF_LOG_CRITICAL,do { do { if (0) printf ("ERROR: glusterfs frame pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1194 , GF_LOG_CRITICAL, "ERROR: glusterfs frame pool creation failed" ); } while (0) | |||
1194 | "ERROR: glusterfs frame pool creation failed")do { do { if (0) printf ("ERROR: glusterfs frame pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1194 , GF_LOG_CRITICAL, "ERROR: glusterfs frame pool creation failed" ); } while (0); | |||
1195 | goto out; | |||
1196 | } | |||
1197 | /* stack_mem_pool size 256 * 1024 */ | |||
1198 | pool->stack_mem_pool = mem_pool_new (call_stack_t, 1024)mem_pool_new_fn (sizeof(call_stack_t), 1024, "call_stack_t"); | |||
1199 | if (!pool->stack_mem_pool) { | |||
1200 | gf_log ("", GF_LOG_CRITICAL,do { do { if (0) printf ("ERROR: glusterfs stack pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1201 , GF_LOG_CRITICAL, "ERROR: glusterfs stack pool creation failed" ); } while (0) | |||
1201 | "ERROR: glusterfs stack pool creation failed")do { do { if (0) printf ("ERROR: glusterfs stack pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1201 , GF_LOG_CRITICAL, "ERROR: glusterfs stack pool creation failed" ); } while (0); | |||
1202 | goto out; | |||
1203 | } | |||
1204 | ||||
1205 | ctx->stub_mem_pool = mem_pool_new (call_stub_t, 1024)mem_pool_new_fn (sizeof(call_stub_t), 1024, "call_stub_t"); | |||
1206 | if (!ctx->stub_mem_pool) { | |||
1207 | gf_log ("", GF_LOG_CRITICAL,do { do { if (0) printf ("ERROR: glusterfs stub pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1208 , GF_LOG_CRITICAL, "ERROR: glusterfs stub pool creation failed" ); } while (0) | |||
1208 | "ERROR: glusterfs stub pool creation failed")do { do { if (0) printf ("ERROR: glusterfs stub pool creation failed" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1208 , GF_LOG_CRITICAL, "ERROR: glusterfs stub pool creation failed" ); } while (0); | |||
1209 | goto out; | |||
1210 | } | |||
1211 | ||||
1212 | ctx->dict_pool = mem_pool_new (dict_t, GF_MEMPOOL_COUNT_OF_DICT_T)mem_pool_new_fn (sizeof(dict_t), 4096, "dict_t"); | |||
1213 | if (!ctx->dict_pool) | |||
1214 | return -1; | |||
1215 | ||||
1216 | ctx->dict_pair_pool = mem_pool_new (data_pair_t,mem_pool_new_fn (sizeof(data_pair_t), (4096 * 4), "data_pair_t" ) | |||
1217 | GF_MEMPOOL_COUNT_OF_DATA_PAIR_T)mem_pool_new_fn (sizeof(data_pair_t), (4096 * 4), "data_pair_t" ); | |||
1218 | if (!ctx->dict_pair_pool) | |||
1219 | return -1; | |||
1220 | ||||
1221 | ctx->dict_data_pool = mem_pool_new (data_t, GF_MEMPOOL_COUNT_OF_DATA_T)mem_pool_new_fn (sizeof(data_t), (4096 * 4), "data_t"); | |||
1222 | if (!ctx->dict_data_pool) | |||
1223 | return -1; | |||
1224 | ||||
1225 | INIT_LIST_HEAD (&pool->all_frames)do { (&pool->all_frames)->next = (&pool->all_frames )->prev = &pool->all_frames; } while (0); | |||
1226 | LOCK_INIT (&pool->lock)pthread_spin_init (&pool->lock, 0); | |||
1227 | ctx->pool = pool; | |||
1228 | ||||
1229 | pthread_mutex_init (&(ctx->lock), NULL((void*)0)); | |||
1230 | ||||
1231 | cmd_args = &ctx->cmd_args; | |||
1232 | ||||
1233 | /* parsing command line arguments */ | |||
1234 | cmd_args->log_level = DEFAULT_LOG_LEVELGF_LOG_INFO; | |||
1235 | ||||
1236 | cmd_args->mac_compat = GF_OPTION_DISABLE_gf_false; | |||
1237 | #ifdef GF_DARWIN_HOST_OS | |||
1238 | /* On Darwin machines, O_APPEND is not handled, | |||
1239 | * which may corrupt the data | |||
1240 | */ | |||
1241 | cmd_args->fuse_direct_io_mode = GF_OPTION_DISABLE_gf_false; | |||
1242 | #else | |||
1243 | cmd_args->fuse_direct_io_mode = GF_OPTION_DEFERRED2; | |||
1244 | #endif | |||
1245 | cmd_args->fuse_attribute_timeout = -1; | |||
1246 | cmd_args->fuse_entry_timeout = -1; | |||
1247 | ||||
1248 | INIT_LIST_HEAD (&cmd_args->xlator_options)do { (&cmd_args->xlator_options)->next = (&cmd_args ->xlator_options)->prev = &cmd_args->xlator_options ; } while (0); | |||
1249 | ||||
1250 | lim.rlim_cur = RLIM_INFINITY0xffffffffffffffffuLL; | |||
1251 | lim.rlim_max = RLIM_INFINITY0xffffffffffffffffuLL; | |||
1252 | setrlimit (RLIMIT_CORERLIMIT_CORE, &lim); | |||
1253 | ||||
1254 | ret = 0; | |||
1255 | out: | |||
1256 | ||||
1257 | if (ret && pool) { | |||
1258 | ||||
1259 | if (pool->frame_mem_pool) | |||
1260 | mem_pool_destroy (pool->frame_mem_pool); | |||
1261 | ||||
1262 | if (pool->stack_mem_pool) | |||
1263 | mem_pool_destroy (pool->stack_mem_pool); | |||
1264 | ||||
1265 | GF_FREE (pool)__gf_free (pool); | |||
1266 | } | |||
1267 | ||||
1268 | if (ret && ctx) { | |||
1269 | if (ctx->stub_mem_pool) | |||
1270 | mem_pool_destroy (ctx->stub_mem_pool); | |||
1271 | ||||
1272 | if (ctx->dict_pool) | |||
1273 | mem_pool_destroy (ctx->dict_pool); | |||
1274 | ||||
1275 | if (ctx->dict_data_pool) | |||
1276 | mem_pool_destroy (ctx->dict_data_pool); | |||
1277 | ||||
1278 | if (ctx->dict_pair_pool) | |||
1279 | mem_pool_destroy (ctx->dict_pair_pool); | |||
1280 | } | |||
1281 | ||||
1282 | return ret; | |||
1283 | } | |||
1284 | ||||
1285 | static int | |||
1286 | logging_init (glusterfs_ctx_t *ctx) | |||
1287 | { | |||
1288 | cmd_args_t *cmd_args = NULL((void*)0); | |||
1289 | int ret = 0; | |||
1290 | ||||
1291 | cmd_args = &ctx->cmd_args; | |||
1292 | ||||
1293 | if (cmd_args->log_file == NULL((void*)0)) { | |||
1294 | ret = set_log_file_path (cmd_args); | |||
1295 | if (ret == -1) { | |||
1296 | fprintf (stderrstderr, "ERROR: failed to set the log file path\n"); | |||
1297 | return -1; | |||
1298 | } | |||
1299 | } | |||
1300 | ||||
1301 | if (gf_log_init (ctx, cmd_args->log_file) == -1) { | |||
1302 | fprintf (stderrstderr, "ERROR: failed to open logfile %s\n", | |||
1303 | cmd_args->log_file); | |||
1304 | return -1; | |||
1305 | } | |||
1306 | ||||
1307 | gf_log_set_loglevel (cmd_args->log_level); | |||
1308 | ||||
1309 | return 0; | |||
1310 | } | |||
1311 | ||||
1312 | void | |||
1313 | gf_check_and_set_mem_acct (glusterfs_ctx_t *ctx, int argc, char *argv[]) | |||
1314 | { | |||
1315 | int i = 0; | |||
1316 | for (i = 0; i < argc; i++) { | |||
1317 | if (strcmp (argv[i], "--mem-accounting") == 0) { | |||
1318 | gf_mem_acct_enable_set (ctx); | |||
1319 | break; | |||
1320 | } | |||
1321 | } | |||
1322 | } | |||
1323 | ||||
1324 | int | |||
1325 | parse_cmdline (int argc, char *argv[], glusterfs_ctx_t *ctx) | |||
1326 | { | |||
1327 | int process_mode = 0; | |||
1328 | int ret = 0; | |||
1329 | struct stat stbuf = {0, }; | |||
1330 | char timestr[32]; | |||
1331 | char tmp_logfile[1024] = { 0 }; | |||
1332 | char *tmp_logfile_dyn = NULL((void*)0); | |||
1333 | char *tmp_logfilebase = NULL((void*)0); | |||
1334 | cmd_args_t *cmd_args = NULL((void*)0); | |||
1335 | ||||
1336 | cmd_args = &ctx->cmd_args; | |||
1337 | ||||
1338 | argp_parse (&argp, argc, argv, ARGP_IN_ORDER0x08, NULL((void*)0), cmd_args); | |||
1339 | ||||
1340 | if (ENABLE_DEBUG_MODE1 == cmd_args->debug_mode) { | |||
1341 | cmd_args->log_level = GF_LOG_DEBUG; | |||
1342 | cmd_args->log_file = "/dev/stderr"; | |||
1343 | cmd_args->no_daemon_mode = ENABLE_NO_DAEMON_MODE1; | |||
1344 | } | |||
1345 | ||||
1346 | process_mode = gf_get_process_mode (argv[0]); | |||
1347 | ctx->process_mode = process_mode; | |||
1348 | ||||
1349 | /* Make sure after the parsing cli, if '--volfile-server' option is | |||
1350 | given, then '--volfile-id' is mandatory */ | |||
1351 | if (cmd_args->volfile_server && !cmd_args->volfile_id) { | |||
1352 | gf_log ("glusterfs", GF_LOG_CRITICAL,do { do { if (0) printf ("ERROR: '--volfile-id' is mandatory if '-s' OR " "'--volfile-server' option is given"); } while (0); _gf_log ( "glusterfs", "glusterfsd.c", __FUNCTION__, 1354, GF_LOG_CRITICAL , "ERROR: '--volfile-id' is mandatory if '-s' OR " "'--volfile-server' option is given" ); } while (0) | |||
1353 | "ERROR: '--volfile-id' is mandatory if '-s' OR "do { do { if (0) printf ("ERROR: '--volfile-id' is mandatory if '-s' OR " "'--volfile-server' option is given"); } while (0); _gf_log ( "glusterfs", "glusterfsd.c", __FUNCTION__, 1354, GF_LOG_CRITICAL , "ERROR: '--volfile-id' is mandatory if '-s' OR " "'--volfile-server' option is given" ); } while (0) | |||
1354 | "'--volfile-server' option is given")do { do { if (0) printf ("ERROR: '--volfile-id' is mandatory if '-s' OR " "'--volfile-server' option is given"); } while (0); _gf_log ( "glusterfs", "glusterfsd.c", __FUNCTION__, 1354, GF_LOG_CRITICAL , "ERROR: '--volfile-id' is mandatory if '-s' OR " "'--volfile-server' option is given" ); } while (0); | |||
1355 | ret = -1; | |||
1356 | goto out; | |||
1357 | } | |||
1358 | ||||
1359 | if ((cmd_args->volfile_server == NULL((void*)0)) | |||
1360 | && (cmd_args->volfile == NULL((void*)0))) { | |||
1361 | if (process_mode == GF_SERVER_PROCESS0) | |||
1362 | cmd_args->volfile = gf_strdup (DEFAULT_SERVER_VOLFILE"/usr/local/etc/glusterfs" "/glusterfsd.vol"); | |||
1363 | else if (process_mode == GF_GLUSTERD_PROCESS2) | |||
1364 | cmd_args->volfile = gf_strdup (DEFAULT_GLUSTERD_VOLFILE"/usr/local/etc/glusterfs" "/glusterd.vol"); | |||
1365 | else | |||
1366 | cmd_args->volfile = gf_strdup (DEFAULT_CLIENT_VOLFILE"/usr/local/etc/glusterfs" "/glusterfs.vol"); | |||
1367 | ||||
1368 | /* Check if the volfile exists, if not give usage output | |||
1369 | and exit */ | |||
1370 | ret = stat (cmd_args->volfile, &stbuf); | |||
1371 | if (ret) { | |||
1372 | gf_log ("glusterfs", GF_LOG_CRITICAL,do { do { if (0) printf ("ERROR: parsing the volfile failed (%s)\n" , strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfs" , "glusterfsd.c", __FUNCTION__, 1374, GF_LOG_CRITICAL, "ERROR: parsing the volfile failed (%s)\n" , strerror ((*__errno_location ()))); } while (0) | |||
1373 | "ERROR: parsing the volfile failed (%s)\n",do { do { if (0) printf ("ERROR: parsing the volfile failed (%s)\n" , strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfs" , "glusterfsd.c", __FUNCTION__, 1374, GF_LOG_CRITICAL, "ERROR: parsing the volfile failed (%s)\n" , strerror ((*__errno_location ()))); } while (0) | |||
1374 | strerror (errno))do { do { if (0) printf ("ERROR: parsing the volfile failed (%s)\n" , strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfs" , "glusterfsd.c", __FUNCTION__, 1374, GF_LOG_CRITICAL, "ERROR: parsing the volfile failed (%s)\n" , strerror ((*__errno_location ()))); } while (0); | |||
1375 | /* argp_usage (argp.) */ | |||
1376 | fprintf (stderrstderr, "USAGE: %s [options] [mountpoint]\n", | |||
1377 | argv[0]); | |||
1378 | goto out; | |||
1379 | } | |||
1380 | } | |||
1381 | ||||
1382 | if (cmd_args->run_id) { | |||
1383 | ret = sys_lstat (cmd_args->log_file, &stbuf); | |||
1384 | /* If its /dev/null, or /dev/stdout, /dev/stderr, | |||
1385 | * let it use the same, no need to alter | |||
1386 | */ | |||
1387 | if (((ret == 0) && | |||
1388 | (S_ISREG (stbuf.st_mode)((((stbuf.st_mode)) & 0170000) == (0100000)) || S_ISLNK (stbuf.st_mode)((((stbuf.st_mode)) & 0170000) == (0120000)))) || | |||
1389 | (ret == -1)) { | |||
1390 | /* Have separate logfile per run */ | |||
1391 | gf_time_fmt (timestr, sizeof timestr, time (NULL((void*)0)), | |||
1392 | gf_timefmt_FT); | |||
1393 | sprintf (tmp_logfile, "%s.%s.%d", | |||
1394 | cmd_args->log_file, timestr, getpid ()); | |||
1395 | ||||
1396 | /* Create symlink to actual log file */ | |||
1397 | sys_unlink (cmd_args->log_file); | |||
1398 | ||||
1399 | tmp_logfile_dyn = gf_strdup (tmp_logfile); | |||
1400 | tmp_logfilebase = basename__xpg_basename (tmp_logfile_dyn); | |||
1401 | ret = sys_symlink (tmp_logfilebase, | |||
1402 | cmd_args->log_file); | |||
1403 | if (ret == -1) { | |||
1404 | fprintf (stderrstderr, "ERROR: symlink of logfile failed\n"); | |||
1405 | goto out; | |||
1406 | } | |||
1407 | ||||
1408 | GF_FREE (cmd_args->log_file)__gf_free (cmd_args->log_file); | |||
1409 | cmd_args->log_file = gf_strdup (tmp_logfile); | |||
1410 | ||||
1411 | GF_FREE (tmp_logfile_dyn)__gf_free (tmp_logfile_dyn); | |||
1412 | } | |||
1413 | } | |||
1414 | ||||
1415 | #ifdef GF_DARWIN_HOST_OS | |||
1416 | if (cmd_args->mount_point) | |||
1417 | cmd_args->mac_compat = GF_OPTION_DEFERRED2; | |||
1418 | #endif | |||
1419 | ||||
1420 | ret = 0; | |||
1421 | out: | |||
1422 | return ret; | |||
1423 | } | |||
1424 | ||||
1425 | ||||
1426 | int | |||
1427 | glusterfs_pidfile_setup (glusterfs_ctx_t *ctx) | |||
1428 | { | |||
1429 | cmd_args_t *cmd_args = NULL((void*)0); | |||
1430 | int ret = -1; | |||
1431 | FILE *pidfp = NULL((void*)0); | |||
1432 | ||||
1433 | cmd_args = &ctx->cmd_args; | |||
1434 | ||||
1435 | if (!cmd_args->pid_file) | |||
1436 | return 0; | |||
1437 | ||||
1438 | pidfp = fopen (cmd_args->pid_file, "a+"); | |||
1439 | if (!pidfp) { | |||
1440 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("pidfile %s error (%s)", cmd_args-> pid_file, strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1442, GF_LOG_ERROR , "pidfile %s error (%s)", cmd_args->pid_file, strerror (( *__errno_location ()))); } while (0) | |||
1441 | "pidfile %s error (%s)",do { do { if (0) printf ("pidfile %s error (%s)", cmd_args-> pid_file, strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1442, GF_LOG_ERROR , "pidfile %s error (%s)", cmd_args->pid_file, strerror (( *__errno_location ()))); } while (0) | |||
1442 | cmd_args->pid_file, strerror (errno))do { do { if (0) printf ("pidfile %s error (%s)", cmd_args-> pid_file, strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1442, GF_LOG_ERROR , "pidfile %s error (%s)", cmd_args->pid_file, strerror (( *__errno_location ()))); } while (0); | |||
1443 | goto out; | |||
1444 | } | |||
1445 | ||||
1446 | ret = lockf (fileno (pidfp), F_TLOCK2, 0); | |||
1447 | if (ret) { | |||
1448 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("pidfile %s lock error (%s)", cmd_args ->pid_file, strerror ((*__errno_location ()))); } while (0 ); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1450, GF_LOG_ERROR, "pidfile %s lock error (%s)", cmd_args->pid_file , strerror ((*__errno_location ()))); } while (0) | |||
1449 | "pidfile %s lock error (%s)",do { do { if (0) printf ("pidfile %s lock error (%s)", cmd_args ->pid_file, strerror ((*__errno_location ()))); } while (0 ); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1450, GF_LOG_ERROR, "pidfile %s lock error (%s)", cmd_args->pid_file , strerror ((*__errno_location ()))); } while (0) | |||
1450 | cmd_args->pid_file, strerror (errno))do { do { if (0) printf ("pidfile %s lock error (%s)", cmd_args ->pid_file, strerror ((*__errno_location ()))); } while (0 ); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1450, GF_LOG_ERROR, "pidfile %s lock error (%s)", cmd_args->pid_file , strerror ((*__errno_location ()))); } while (0); | |||
1451 | goto out; | |||
1452 | } | |||
1453 | ||||
1454 | gf_log ("glusterfsd", GF_LOG_TRACE,do { do { if (0) printf ("pidfile %s lock acquired", cmd_args ->pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1456, GF_LOG_TRACE, "pidfile %s lock acquired" , cmd_args->pid_file); } while (0) | |||
1455 | "pidfile %s lock acquired",do { do { if (0) printf ("pidfile %s lock acquired", cmd_args ->pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1456, GF_LOG_TRACE, "pidfile %s lock acquired" , cmd_args->pid_file); } while (0) | |||
1456 | cmd_args->pid_file)do { do { if (0) printf ("pidfile %s lock acquired", cmd_args ->pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1456, GF_LOG_TRACE, "pidfile %s lock acquired" , cmd_args->pid_file); } while (0); | |||
1457 | ||||
1458 | ret = lockf (fileno (pidfp), F_ULOCK0, 0); | |||
1459 | if (ret) { | |||
1460 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("pidfile %s unlock error (%s)", cmd_args ->pid_file, strerror ((*__errno_location ()))); } while (0 ); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1462, GF_LOG_ERROR, "pidfile %s unlock error (%s)", cmd_args->pid_file , strerror ((*__errno_location ()))); } while (0) | |||
1461 | "pidfile %s unlock error (%s)",do { do { if (0) printf ("pidfile %s unlock error (%s)", cmd_args ->pid_file, strerror ((*__errno_location ()))); } while (0 ); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1462, GF_LOG_ERROR, "pidfile %s unlock error (%s)", cmd_args->pid_file , strerror ((*__errno_location ()))); } while (0) | |||
1462 | cmd_args->pid_file, strerror (errno))do { do { if (0) printf ("pidfile %s unlock error (%s)", cmd_args ->pid_file, strerror ((*__errno_location ()))); } while (0 ); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__, 1462, GF_LOG_ERROR, "pidfile %s unlock error (%s)", cmd_args->pid_file , strerror ((*__errno_location ()))); } while (0); | |||
1463 | goto out; | |||
1464 | } | |||
1465 | ||||
1466 | ctx->pidfp = pidfp; | |||
1467 | ||||
1468 | ret = 0; | |||
1469 | out: | |||
1470 | if (ret && pidfp) | |||
1471 | fclose (pidfp); | |||
1472 | ||||
1473 | return ret; | |||
1474 | } | |||
1475 | ||||
1476 | ||||
1477 | int | |||
1478 | glusterfs_pidfile_cleanup (glusterfs_ctx_t *ctx) | |||
1479 | { | |||
1480 | cmd_args_t *cmd_args = NULL((void*)0); | |||
1481 | ||||
1482 | cmd_args = &ctx->cmd_args; | |||
1483 | ||||
1484 | if (!ctx->pidfp) | |||
1485 | return 0; | |||
1486 | ||||
1487 | gf_log ("glusterfsd", GF_LOG_TRACE,do { do { if (0) printf ("pidfile %s cleanup", cmd_args->pid_file ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1489, GF_LOG_TRACE, "pidfile %s cleanup", cmd_args->pid_file ); } while (0) | |||
1488 | "pidfile %s cleanup",do { do { if (0) printf ("pidfile %s cleanup", cmd_args->pid_file ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1489, GF_LOG_TRACE, "pidfile %s cleanup", cmd_args->pid_file ); } while (0) | |||
1489 | cmd_args->pid_file)do { do { if (0) printf ("pidfile %s cleanup", cmd_args->pid_file ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1489, GF_LOG_TRACE, "pidfile %s cleanup", cmd_args->pid_file ); } while (0); | |||
1490 | ||||
1491 | if (ctx->cmd_args.pid_file) { | |||
1492 | unlink (ctx->cmd_args.pid_file); | |||
1493 | ctx->cmd_args.pid_file = NULL((void*)0); | |||
1494 | } | |||
1495 | ||||
1496 | lockf (fileno (ctx->pidfp), F_ULOCK0, 0); | |||
1497 | fclose (ctx->pidfp); | |||
1498 | ctx->pidfp = NULL((void*)0); | |||
1499 | ||||
1500 | return 0; | |||
1501 | } | |||
1502 | ||||
1503 | int | |||
1504 | glusterfs_pidfile_update (glusterfs_ctx_t *ctx) | |||
1505 | { | |||
1506 | cmd_args_t *cmd_args = NULL((void*)0); | |||
1507 | int ret = 0; | |||
1508 | FILE *pidfp = NULL((void*)0); | |||
1509 | ||||
1510 | cmd_args = &ctx->cmd_args; | |||
1511 | ||||
1512 | pidfp = ctx->pidfp; | |||
1513 | if (!pidfp) | |||
1514 | return 0; | |||
1515 | ||||
1516 | ret = lockf (fileno (pidfp), F_TLOCK2, 0); | |||
1517 | if (ret) { | |||
1518 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("pidfile %s lock failed", cmd_args-> pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1520, GF_LOG_ERROR, "pidfile %s lock failed", cmd_args->pid_file); } while (0) | |||
1519 | "pidfile %s lock failed",do { do { if (0) printf ("pidfile %s lock failed", cmd_args-> pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1520, GF_LOG_ERROR, "pidfile %s lock failed", cmd_args->pid_file); } while (0) | |||
1520 | cmd_args->pid_file)do { do { if (0) printf ("pidfile %s lock failed", cmd_args-> pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1520, GF_LOG_ERROR, "pidfile %s lock failed", cmd_args->pid_file); } while (0); | |||
1521 | return ret; | |||
1522 | } | |||
1523 | ||||
1524 | ret = ftruncate (fileno (pidfp), 0); | |||
1525 | if (ret) { | |||
1526 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("pidfile %s truncation failed", cmd_args ->pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1528, GF_LOG_ERROR, "pidfile %s truncation failed" , cmd_args->pid_file); } while (0) | |||
1527 | "pidfile %s truncation failed",do { do { if (0) printf ("pidfile %s truncation failed", cmd_args ->pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1528, GF_LOG_ERROR, "pidfile %s truncation failed" , cmd_args->pid_file); } while (0) | |||
1528 | cmd_args->pid_file)do { do { if (0) printf ("pidfile %s truncation failed", cmd_args ->pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1528, GF_LOG_ERROR, "pidfile %s truncation failed" , cmd_args->pid_file); } while (0); | |||
1529 | return ret; | |||
1530 | } | |||
1531 | ||||
1532 | ret = fprintf (pidfp, "%d\n", getpid ()); | |||
1533 | if (ret <= 0) { | |||
1534 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("pidfile %s write failed", cmd_args-> pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1536, GF_LOG_ERROR, "pidfile %s write failed" , cmd_args->pid_file); } while (0) | |||
1535 | "pidfile %s write failed",do { do { if (0) printf ("pidfile %s write failed", cmd_args-> pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1536, GF_LOG_ERROR, "pidfile %s write failed" , cmd_args->pid_file); } while (0) | |||
1536 | cmd_args->pid_file)do { do { if (0) printf ("pidfile %s write failed", cmd_args-> pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1536, GF_LOG_ERROR, "pidfile %s write failed" , cmd_args->pid_file); } while (0); | |||
1537 | return ret; | |||
1538 | } | |||
1539 | ||||
1540 | ret = fflush (pidfp); | |||
1541 | if (ret) { | |||
1542 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("pidfile %s write failed", cmd_args-> pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1544, GF_LOG_ERROR, "pidfile %s write failed" , cmd_args->pid_file); } while (0) | |||
1543 | "pidfile %s write failed",do { do { if (0) printf ("pidfile %s write failed", cmd_args-> pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1544, GF_LOG_ERROR, "pidfile %s write failed" , cmd_args->pid_file); } while (0) | |||
1544 | cmd_args->pid_file)do { do { if (0) printf ("pidfile %s write failed", cmd_args-> pid_file); } while (0); _gf_log ("glusterfsd", "glusterfsd.c" , __FUNCTION__, 1544, GF_LOG_ERROR, "pidfile %s write failed" , cmd_args->pid_file); } while (0); | |||
1545 | return ret; | |||
1546 | } | |||
1547 | ||||
1548 | gf_log ("glusterfsd", GF_LOG_DEBUG,do { do { if (0) printf ("pidfile %s updated with pid %d", cmd_args ->pid_file, getpid ()); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 1550, GF_LOG_DEBUG, "pidfile %s updated with pid %d" , cmd_args->pid_file, getpid ()); } while (0) | |||
1549 | "pidfile %s updated with pid %d",do { do { if (0) printf ("pidfile %s updated with pid %d", cmd_args ->pid_file, getpid ()); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 1550, GF_LOG_DEBUG, "pidfile %s updated with pid %d" , cmd_args->pid_file, getpid ()); } while (0) | |||
1550 | cmd_args->pid_file, getpid ())do { do { if (0) printf ("pidfile %s updated with pid %d", cmd_args ->pid_file, getpid ()); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 1550, GF_LOG_DEBUG, "pidfile %s updated with pid %d" , cmd_args->pid_file, getpid ()); } while (0); | |||
1551 | ||||
1552 | return 0; | |||
1553 | } | |||
1554 | ||||
1555 | ||||
1556 | void * | |||
1557 | glusterfs_sigwaiter (void *arg) | |||
1558 | { | |||
1559 | sigset_t set; | |||
1560 | int ret = 0; | |||
1561 | int sig = 0; | |||
1562 | ||||
1563 | ||||
1564 | sigemptyset (&set); | |||
1565 | sigaddset (&set, SIGINT2); /* cleanup_and_exit */ | |||
1566 | sigaddset (&set, SIGTERM15); /* cleanup_and_exit */ | |||
1567 | sigaddset (&set, SIGHUP1); /* reincarnate */ | |||
1568 | sigaddset (&set, SIGUSR110); /* gf_proc_dump_info */ | |||
1569 | sigaddset (&set, SIGUSR212); /* gf_latency_toggle */ | |||
1570 | ||||
1571 | for (;;) { | |||
| ||||
1572 | ret = sigwait (&set, &sig); | |||
1573 | if (ret) | |||
1574 | continue; | |||
1575 | ||||
1576 | ||||
1577 | switch (sig) { | |||
1578 | case SIGINT2: | |||
1579 | case SIGTERM15: | |||
1580 | cleanup_and_exit (sig); | |||
1581 | break; | |||
1582 | case SIGHUP1: | |||
1583 | reincarnate (sig); | |||
1584 | break; | |||
1585 | case SIGUSR110: | |||
1586 | gf_proc_dump_info (sig, glusterfsd_ctx); | |||
1587 | break; | |||
1588 | case SIGUSR212: | |||
1589 | gf_latency_toggle (sig, glusterfsd_ctx); | |||
1590 | break; | |||
1591 | default: | |||
1592 | ||||
1593 | break; | |||
1594 | } | |||
1595 | } | |||
1596 | ||||
1597 | return NULL((void*)0); | |||
1598 | } | |||
1599 | ||||
1600 | ||||
1601 | void | |||
1602 | glusterfsd_print_trace (int signum) | |||
1603 | { | |||
1604 | gf_print_trace (signum, glusterfsd_ctx); | |||
1605 | } | |||
1606 | ||||
1607 | ||||
1608 | int | |||
1609 | glusterfs_signals_setup (glusterfs_ctx_t *ctx) | |||
1610 | { | |||
1611 | sigset_t set; | |||
1612 | int ret = 0; | |||
1613 | ||||
1614 | sigemptyset (&set); | |||
1615 | ||||
1616 | /* common setting for all threads */ | |||
1617 | signal (SIGSEGV11, glusterfsd_print_trace); | |||
1618 | signal (SIGABRT6, glusterfsd_print_trace); | |||
1619 | signal (SIGILL4, glusterfsd_print_trace); | |||
1620 | signal (SIGTRAP5, glusterfsd_print_trace); | |||
1621 | signal (SIGFPE8, glusterfsd_print_trace); | |||
1622 | signal (SIGBUS7, glusterfsd_print_trace); | |||
1623 | signal (SIGINT2, cleanup_and_exit); | |||
1624 | signal (SIGPIPE13, SIG_IGN((__sighandler_t) 1)); | |||
1625 | ||||
1626 | /* block these signals from non-sigwaiter threads */ | |||
1627 | sigaddset (&set, SIGTERM15); /* cleanup_and_exit */ | |||
1628 | sigaddset (&set, SIGHUP1); /* reincarnate */ | |||
1629 | sigaddset (&set, SIGUSR110); /* gf_proc_dump_info */ | |||
1630 | sigaddset (&set, SIGUSR212); /* gf_latency_toggle */ | |||
1631 | ||||
1632 | ret = pthread_sigmask (SIG_BLOCK0, &set, NULL((void*)0)); | |||
1633 | if (ret) { | |||
1634 | gf_log ("glusterfsd", GF_LOG_WARNING,do { do { if (0) printf ("failed to execute pthread_signmask %s" , strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 1636, GF_LOG_WARNING, "failed to execute pthread_signmask %s" , strerror ((*__errno_location ()))); } while (0) | |||
1635 | "failed to execute pthread_signmask %s",do { do { if (0) printf ("failed to execute pthread_signmask %s" , strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 1636, GF_LOG_WARNING, "failed to execute pthread_signmask %s" , strerror ((*__errno_location ()))); } while (0) | |||
1636 | strerror (errno))do { do { if (0) printf ("failed to execute pthread_signmask %s" , strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 1636, GF_LOG_WARNING, "failed to execute pthread_signmask %s" , strerror ((*__errno_location ()))); } while (0); | |||
1637 | return ret; | |||
1638 | } | |||
1639 | ||||
1640 | ret = pthread_create (&ctx->sigwaiter, NULL((void*)0), glusterfs_sigwaiter, | |||
1641 | (void *) &set); | |||
1642 | if (ret) { | |||
1643 | /* | |||
1644 | TODO: | |||
1645 | fallback to signals getting handled by other threads. | |||
1646 | setup the signal handlers | |||
1647 | */ | |||
1648 | gf_log ("glusterfsd", GF_LOG_WARNING,do { do { if (0) printf ("failed to create pthread %s", strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 1650, GF_LOG_WARNING, "failed to create pthread %s" , strerror ((*__errno_location ()))); } while (0) | |||
1649 | "failed to create pthread %s",do { do { if (0) printf ("failed to create pthread %s", strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 1650, GF_LOG_WARNING, "failed to create pthread %s" , strerror ((*__errno_location ()))); } while (0) | |||
1650 | strerror (errno))do { do { if (0) printf ("failed to create pthread %s", strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterfsd" , "glusterfsd.c", __FUNCTION__, 1650, GF_LOG_WARNING, "failed to create pthread %s" , strerror ((*__errno_location ()))); } while (0); | |||
1651 | return ret; | |||
1652 | } | |||
1653 | ||||
1654 | return ret; | |||
1655 | } | |||
1656 | ||||
1657 | ||||
1658 | int | |||
1659 | daemonize (glusterfs_ctx_t *ctx) | |||
1660 | { | |||
1661 | int ret = -1; | |||
1662 | cmd_args_t *cmd_args = NULL((void*)0); | |||
1663 | int cstatus = 0; | |||
1664 | int err = 0; | |||
1665 | ||||
1666 | cmd_args = &ctx->cmd_args; | |||
1667 | ||||
1668 | ret = glusterfs_pidfile_setup (ctx); | |||
1669 | if (ret) | |||
1670 | goto out; | |||
1671 | ||||
1672 | if (cmd_args->no_daemon_mode) | |||
1673 | goto postfork; | |||
1674 | ||||
1675 | if (cmd_args->debug_mode) | |||
1676 | goto postfork; | |||
1677 | ||||
1678 | ret = pipe (ctx->daemon_pipe); | |||
1679 | if (ret) { | |||
1680 | /* If pipe() fails, retain daemon_pipe[] = {-1, -1} | |||
1681 | and parent will just not wait for child status | |||
1682 | */ | |||
1683 | ctx->daemon_pipe[0] = -1; | |||
1684 | ctx->daemon_pipe[1] = -1; | |||
1685 | } | |||
1686 | ||||
1687 | ret = os_daemon_return (0, 0); | |||
1688 | switch (ret) { | |||
1689 | case -1: | |||
1690 | if (ctx->daemon_pipe[0] != -1) { | |||
1691 | close (ctx->daemon_pipe[0]); | |||
1692 | close (ctx->daemon_pipe[1]); | |||
1693 | } | |||
1694 | ||||
1695 | gf_log ("daemonize", GF_LOG_ERROR,do { do { if (0) printf ("Daemonization failed: %s", strerror ((*__errno_location ()))); } while (0); _gf_log ("daemonize", "glusterfsd.c", __FUNCTION__, 1696, GF_LOG_ERROR, "Daemonization failed: %s" , strerror((*__errno_location ()))); } while (0) | |||
1696 | "Daemonization failed: %s", strerror(errno))do { do { if (0) printf ("Daemonization failed: %s", strerror ((*__errno_location ()))); } while (0); _gf_log ("daemonize", "glusterfsd.c", __FUNCTION__, 1696, GF_LOG_ERROR, "Daemonization failed: %s" , strerror((*__errno_location ()))); } while (0); | |||
1697 | goto out; | |||
1698 | case 0: | |||
1699 | /* child */ | |||
1700 | /* close read */ | |||
1701 | close (ctx->daemon_pipe[0]); | |||
1702 | break; | |||
1703 | default: | |||
1704 | /* parent */ | |||
1705 | /* close write */ | |||
1706 | close (ctx->daemon_pipe[1]); | |||
1707 | ||||
1708 | if (ctx->mnt_pid > 0) { | |||
1709 | ret = waitpid (ctx->mnt_pid, &cstatus, 0); | |||
1710 | if (!(ret == ctx->mnt_pid && cstatus == 0)) { | |||
1711 | gf_log ("daemonize", GF_LOG_ERROR,do { do { if (0) printf ("mount failed"); } while (0); _gf_log ("daemonize", "glusterfsd.c", __FUNCTION__, 1712, GF_LOG_ERROR , "mount failed"); } while (0) | |||
1712 | "mount failed")do { do { if (0) printf ("mount failed"); } while (0); _gf_log ("daemonize", "glusterfsd.c", __FUNCTION__, 1712, GF_LOG_ERROR , "mount failed"); } while (0); | |||
1713 | exit (1); | |||
1714 | } | |||
1715 | } | |||
1716 | ||||
1717 | err = 1; | |||
1718 | read (ctx->daemon_pipe[0], (void *)&err, sizeof (err)); | |||
1719 | _exit (err); | |||
1720 | } | |||
1721 | ||||
1722 | postfork: | |||
1723 | ret = glusterfs_pidfile_update (ctx); | |||
1724 | if (ret) | |||
1725 | goto out; | |||
1726 | ||||
1727 | glusterfs_signals_setup (ctx); | |||
1728 | out: | |||
1729 | return ret; | |||
1730 | } | |||
1731 | ||||
1732 | ||||
1733 | int | |||
1734 | glusterfs_process_volfp (glusterfs_ctx_t *ctx, FILE *fp) | |||
1735 | { | |||
1736 | glusterfs_graph_t *graph = NULL((void*)0); | |||
1737 | int ret = -1; | |||
1738 | xlator_t *trav = NULL((void*)0); | |||
1739 | ||||
1740 | graph = glusterfs_graph_construct (fp); | |||
1741 | if (!graph) { | |||
1742 | gf_log ("", GF_LOG_ERROR, "failed to construct the graph")do { do { if (0) printf ("failed to construct the graph"); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1742, GF_LOG_ERROR , "failed to construct the graph"); } while (0); | |||
1743 | goto out; | |||
1744 | } | |||
1745 | ||||
1746 | for (trav = graph->first; trav; trav = trav->next) { | |||
1747 | if (strcmp (trav->type, "mount/fuse") == 0) { | |||
1748 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("fuse xlator cannot be specified " "in volume file" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1750, GF_LOG_ERROR, "fuse xlator cannot be specified " "in volume file" ); } while (0) | |||
1749 | "fuse xlator cannot be specified "do { do { if (0) printf ("fuse xlator cannot be specified " "in volume file" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1750, GF_LOG_ERROR, "fuse xlator cannot be specified " "in volume file" ); } while (0) | |||
1750 | "in volume file")do { do { if (0) printf ("fuse xlator cannot be specified " "in volume file" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1750, GF_LOG_ERROR, "fuse xlator cannot be specified " "in volume file" ); } while (0); | |||
1751 | goto out; | |||
1752 | } | |||
1753 | } | |||
1754 | ||||
1755 | ret = glusterfs_graph_prepare (graph, ctx); | |||
1756 | if (ret) { | |||
1757 | glusterfs_graph_destroy (graph); | |||
1758 | goto out; | |||
1759 | } | |||
1760 | ||||
1761 | ret = glusterfs_graph_activate (graph, ctx); | |||
1762 | ||||
1763 | if (ret) { | |||
1764 | glusterfs_graph_destroy (graph); | |||
1765 | goto out; | |||
1766 | } | |||
1767 | ||||
1768 | gf_log_dump_graph (fp, graph); | |||
1769 | ||||
1770 | ret = 0; | |||
1771 | out: | |||
1772 | if (fp) | |||
1773 | fclose (fp); | |||
1774 | ||||
1775 | if (ret && !ctx->active) { | |||
1776 | /* there is some error in setting up the first graph itself */ | |||
1777 | cleanup_and_exit (0); | |||
1778 | } | |||
1779 | ||||
1780 | return ret; | |||
1781 | } | |||
1782 | ||||
1783 | ||||
1784 | int | |||
1785 | glusterfs_volumes_init (glusterfs_ctx_t *ctx) | |||
1786 | { | |||
1787 | FILE *fp = NULL((void*)0); | |||
1788 | cmd_args_t *cmd_args = NULL((void*)0); | |||
1789 | int ret = 0; | |||
1790 | ||||
1791 | cmd_args = &ctx->cmd_args; | |||
1792 | ||||
1793 | if (cmd_args->sock_file) { | |||
1794 | ret = glusterfs_listener_init (ctx); | |||
1795 | if (ret) | |||
1796 | goto out; | |||
1797 | } | |||
1798 | ||||
1799 | if (cmd_args->volfile_server) { | |||
1800 | ret = glusterfs_mgmt_init (ctx); | |||
1801 | /* return, do not emancipate() yet */ | |||
1802 | return ret; | |||
1803 | } | |||
1804 | ||||
1805 | fp = get_volfp (ctx); | |||
1806 | ||||
1807 | if (!fp) { | |||
1808 | gf_log ("glusterfsd", GF_LOG_ERROR,do { do { if (0) printf ("Cannot reach volume specification file" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1809, GF_LOG_ERROR, "Cannot reach volume specification file" ); } while (0) | |||
1809 | "Cannot reach volume specification file")do { do { if (0) printf ("Cannot reach volume specification file" ); } while (0); _gf_log ("glusterfsd", "glusterfsd.c", __FUNCTION__ , 1809, GF_LOG_ERROR, "Cannot reach volume specification file" ); } while (0); | |||
1810 | ret = -1; | |||
1811 | goto out; | |||
1812 | } | |||
1813 | ||||
1814 | ret = glusterfs_process_volfp (ctx, fp); | |||
1815 | if (ret) | |||
1816 | goto out; | |||
1817 | ||||
1818 | out: | |||
1819 | emancipate (ctx, ret); | |||
1820 | return ret; | |||
1821 | } | |||
1822 | ||||
1823 | ||||
1824 | /* This is the only legal global pointer */ | |||
1825 | glusterfs_ctx_t *glusterfsd_ctx; | |||
1826 | ||||
1827 | int | |||
1828 | main (int argc, char *argv[]) | |||
1829 | { | |||
1830 | glusterfs_ctx_t *ctx = NULL((void*)0); | |||
1831 | int ret = -1; | |||
1832 | char cmdlinestr[PATH_MAX4096] = {0,}; | |||
1833 | ||||
1834 | ctx = glusterfs_ctx_new (); | |||
1835 | if (!ctx) { | |||
1836 | gf_log ("glusterfs", GF_LOG_CRITICAL,do { do { if (0) printf ("ERROR: glusterfs context not initialized" ); } while (0); _gf_log ("glusterfs", "glusterfsd.c", __FUNCTION__ , 1837, GF_LOG_CRITICAL, "ERROR: glusterfs context not initialized" ); } while (0) | |||
1837 | "ERROR: glusterfs context not initialized")do { do { if (0) printf ("ERROR: glusterfs context not initialized" ); } while (0); _gf_log ("glusterfs", "glusterfsd.c", __FUNCTION__ , 1837, GF_LOG_CRITICAL, "ERROR: glusterfs context not initialized" ); } while (0); | |||
1838 | return ENOMEM12; | |||
1839 | } | |||
1840 | glusterfsd_ctx = ctx; | |||
1841 | ||||
1842 | #ifdef DEBUG | |||
1843 | gf_mem_acct_enable_set (ctx); | |||
1844 | #else | |||
1845 | /* Enable memory accounting on the fly based on argument */ | |||
1846 | gf_check_and_set_mem_acct (ctx, argc, argv); | |||
1847 | #endif | |||
1848 | ||||
1849 | ret = glusterfs_globals_init (ctx); | |||
1850 | if (ret) | |||
1851 | return ret; | |||
1852 | ||||
1853 | THIS(*__glusterfs_this_location())->ctx = ctx; | |||
1854 | ||||
1855 | ret = glusterfs_ctx_defaults_init (ctx); | |||
1856 | if (ret) | |||
1857 | goto out; | |||
1858 | ||||
1859 | ret = parse_cmdline (argc, argv, ctx); | |||
1860 | if (ret) | |||
1861 | goto out; | |||
1862 | ||||
1863 | ret = logging_init (ctx); | |||
1864 | if (ret) | |||
1865 | goto out; | |||
1866 | ||||
1867 | /* log the version of glusterfs running here along with the actual | |||
1868 | command line options. */ | |||
1869 | { | |||
1870 | int i = 0; | |||
1871 | strcpy (cmdlinestr, argv[0]); | |||
1872 | for (i = 1; i < argc; i++) { | |||
1873 | strcat (cmdlinestr, " "); | |||
1874 | strcat (cmdlinestr, argv[i]); | |||
1875 | } | |||
1876 | gf_log (argv[0], GF_LOG_INFO,do { do { if (0) printf ("Started running %s version %s (%s)" , argv[0], "3git", cmdlinestr); } while (0); _gf_log (argv[0] , "glusterfsd.c", __FUNCTION__, 1878, GF_LOG_INFO, "Started running %s version %s (%s)" , argv[0], "3git", cmdlinestr); } while (0) | |||
1877 | "Started running %s version %s (%s)",do { do { if (0) printf ("Started running %s version %s (%s)" , argv[0], "3git", cmdlinestr); } while (0); _gf_log (argv[0] , "glusterfsd.c", __FUNCTION__, 1878, GF_LOG_INFO, "Started running %s version %s (%s)" , argv[0], "3git", cmdlinestr); } while (0) | |||
1878 | argv[0], PACKAGE_VERSION, cmdlinestr)do { do { if (0) printf ("Started running %s version %s (%s)" , argv[0], "3git", cmdlinestr); } while (0); _gf_log (argv[0] , "glusterfsd.c", __FUNCTION__, 1878, GF_LOG_INFO, "Started running %s version %s (%s)" , argv[0], "3git", cmdlinestr); } while (0); | |||
1879 | } | |||
1880 | ||||
1881 | gf_proc_dump_init(); | |||
1882 | ||||
1883 | ret = create_fuse_mount (ctx); | |||
1884 | if (ret) | |||
1885 | goto out; | |||
1886 | ||||
1887 | ret = daemonize (ctx); | |||
1888 | if (ret) | |||
1889 | goto out; | |||
1890 | ||||
1891 | ctx->env = syncenv_new (0); | |||
1892 | if (!ctx->env) { | |||
1893 | gf_log ("", GF_LOG_ERROR,do { do { if (0) printf ("Could not create new sync-environment" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1894 , GF_LOG_ERROR, "Could not create new sync-environment"); } while (0) | |||
1894 | "Could not create new sync-environment")do { do { if (0) printf ("Could not create new sync-environment" ); } while (0); _gf_log ("", "glusterfsd.c", __FUNCTION__, 1894 , GF_LOG_ERROR, "Could not create new sync-environment"); } while (0); | |||
1895 | goto out; | |||
1896 | } | |||
1897 | ||||
1898 | ret = glusterfs_volumes_init (ctx); | |||
1899 | if (ret) | |||
1900 | goto out; | |||
1901 | ||||
1902 | ret = event_dispatch (ctx->event_pool); | |||
1903 | ||||
1904 | out: | |||
1905 | // glusterfs_ctx_destroy (ctx); | |||
1906 | ||||
1907 | return ret; | |||
1908 | } |