/*
Copyright (c) 2006-2013 Red Hat, Inc. <http://www.redhat.com>
This file is part of GlusterFS.
This file is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3 or
later), or the GNU General Public License, version 2 (GPLv2), in all
cases as published by the Free Software Foundation.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/file.h>
#include <sys/wait.h>
#include <netdb.h>
#include <signal.h>
#include <libgen.h>
#include <dlfcn.h>
#include <sys/utsname.h>
#include <stdint.h>
#include <pthread.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <semaphore.h>
#include <errno.h>
#include <pwd.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_MALLOC_STATS
#ifdef DEBUG
#include <mcheck.h>
#endif
#endif
#include "xlator.h"
#include "glusterfs.h"
#include "compat.h"
#include "logging.h"
#include "glusterfsd-messages.h"
#include "dict.h"
#include "list.h"
#include "timer.h"
#include "glusterfsd.h"
#include "stack.h"
#include "revision.h"
#include "common-utils.h"
#include "event.h"
#include "globals.h"
#include "statedump.h"
#include "latency.h"
#include "glusterfsd-mem-types.h"
#include "syscall.h"
#include "call-stub.h"
#include <fnmatch.h>
#include "rpc-clnt.h"
#include "syncop.h"
#include "client_t.h"
#include "netgroups.h"
#include "exports.h"
#include "daemon.h"
#include "tw.h"
/* process mode definitions */
#define GF_SERVER_PROCESS 0
#define GF_CLIENT_PROCESS 1
#define GF_GLUSTERD_PROCESS 2
/* using argp for command line parsing */
static char gf_doc[] = "";
static char argp_doc[] = "--volfile-server=SERVER [MOUNT-POINT]\n" \
"--volfile=VOLFILE [MOUNT-POINT]";
const char *argp_program_version = ""
PACKAGE_NAME" "PACKAGE_VERSION" built on "__DATE__" "__TIME__
"\nRepository revision: " GLUSTERFS_REPOSITORY_REVISION "\n"
"Copyright (c) 2006-2013 Red Hat, Inc. <http://www.redhat.com/>\n"
"GlusterFS comes with ABSOLUTELY NO WARRANTY.\n"
"It is licensed to you under your choice of the GNU Lesser\n"
"General Public License, version 3 or any later version (LGPLv3\n"
"or later), or the GNU General Public License, version 2 (GPLv2),\n"
"in all cases as published by the Free Software Foundation.";
const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
static error_t parse_opts (int32_t key, char *arg, struct argp_state *_state);
static struct argp_option gf_options[] = {
{0, 0, 0, 0, "Basic options:"},
{"volfile-server", ARGP_VOLFILE_SERVER_KEY, "SERVER", 0,
"Server to get the volume file from. Unix domain socket path when "
"transport type 'unix'. This option overrides --volfile option"},
{"volfile", ARGP_VOLUME_FILE_KEY, "VOLFILE", 0,
"File to use as VOLUME_FILE"},
{"spec-file", ARGP_VOLUME_FILE_KEY, "VOLFILE", OPTION_HIDDEN,
"File to use as VOLUME FILE"},
{"log-level", ARGP_LOG_LEVEL_KEY, "LOGLEVEL", 0,
"Logging severity. Valid options are DEBUG, INFO, WARNING, ERROR, "
"CRITICAL, TRACE and NONE [default: INFO]"},
{"log-file", ARGP_LOG_FILE_KEY, "LOGFILE", 0,
"File to use for logging [default: "
DEFAULT_LOG_FILE_DIRECTORY "/" PACKAGE_NAME ".log" "]"},
{"logger", ARGP_LOGGER, "LOGGER", 0, "Set which logging sub-system to "
"log to, valid options are: gluster-log and syslog, "
"[default: \"gluster-log\"]"},
{"log-format", ARGP_LOG_FORMAT, "LOG-FORMAT", 0, "Set log format, valid"
" options are: no-msg-id and with-msg-id, [default: \"with-msg-id\"]"},
{"log-buf-size", ARGP_LOG_BUF_SIZE, "LOG-BUF-SIZE", 0, "Set logging "
"buffer size, [default: 5]"},
{"log-flush-timeout", ARGP_LOG_FLUSH_TIMEOUT, "LOG-FLUSH-TIMEOUT", 0,
"Set log flush timeout, [default: 2 minutes]"},
{0, 0, 0, 0, "Advanced Options:"},
{"volfile-server-port", ARGP_VOLFILE_SERVER_PORT_KEY, "PORT", 0,
"Listening port number of volfile server"},
{"volfile-server-transport", ARGP_VOLFILE_SERVER_TRANSPORT_KEY,
"TRANSPORT", 0,
"Transport type to get volfile from server [default: socket]"},
{"volfile-id", ARGP_VOLFILE_ID_KEY, "KEY", 0,
"'key' of the volfile to be fetched from server"},
{"pid-file", ARGP_PID_FILE_KEY, "PIDFILE", 0,
"File to use as pid file"},
{"socket-file", ARGP_SOCK_FILE_KEY, "SOCKFILE", 0,
"File to use as unix-socket"},
{"no-daemon", ARGP_NO_DAEMON_KEY, 0, 0,
"Run in foreground"},
{"run-id", ARGP_RUN_ID_KEY, "RUN-ID", OPTION_HIDDEN,
"Run ID for the process, used by scripts to keep track of process "
"they started, defaults to none"},
{"debug", ARGP_DEBUG_KEY, 0, 0,
"Run in debug mode. This option sets --no-daemon, --log-level "
"to DEBUG and --log-file to console"},
{"volume-name", ARGP_VOLUME_NAME_KEY, "XLATOR-NAME", 0,
"Translator name to be used for MOUNT-POINT [default: top most volume "
"definition in VOLFILE]"},
{"xlator-option", ARGP_XLATOR_OPTION_KEY,"XLATOR-NAME.OPTION=VALUE", 0,
"Add/override an option for a translator in volume file with specified"
" value"},
{"read-only", ARGP_READ_ONLY_KEY, 0, 0,
"Mount the filesystem in 'read-only' mode"},
{"acl", ARGP_ACL_KEY, 0, 0,
"Mount the filesystem with POSIX ACL support"},
{"selinux", ARGP_SELINUX_KEY, 0, 0,
"Enable SELinux label (extended attributes) support on inodes"},
{"capability", ARGP_CAPABILITY_KEY, 0, 0,
|