summaryrefslogtreecommitdiffstats
path: root/tests/basic/meta.t
diff options
context:
space:
mode:
authorVishal Pandey <vishpandey2014@gmail.com>2017-11-14 14:33:19 +0530
committerAravinda VK <avishwan@redhat.com>2017-11-15 09:57:00 +0000
commit5f5d166e89367dc0d72fa02ca4e8ca2d28a06cdd (patch)
treef3eaf5174792a7706d5d00659023145bf88aa9f5 /tests/basic/meta.t
parenta5b5cbb99eb946cdc9ad08b2d321005def13f0a1 (diff)
eventsapi: glustereventsd hardcodes working-directory
Issue: Glusterevents daemon hardcodes glusterd working directory even though it can be changed later in .vol file which causes breaks in the code. Fix: Use python subprocess module to get the working directory of gluster daemon in eventsapiconf.py.in. Change-Id: I5e92185604f8c8aeb77dabdc00f9ea0f8e92c88d BUG: 1512455 Signed-off-by: Vishal Pandey <vishpandey2014@gmail.com>
Diffstat (limited to 'tests/basic/meta.t')
0 files changed, 0 insertions, 0 deletions
DIGEST_LEN]) +{ + uint32_t last, padn; + uint32_t high, low; + uint8_t msglen[8]; + + high = (ctx->totalN >> 29) + | (ctx->totalN2 << 3); + low = (ctx->totalN << 3); + + SIVAL(msglen, 0, low); + SIVAL(msglen, 4, high); + + last = ctx->totalN & 0x3F; + padn = last < 56 ? 56 - last : 120 - last; + + md5_update(ctx, md5_padding, padn); + md5_update(ctx, msglen, 8); + + SIVAL(digest, 0, ctx->A); + SIVAL(digest, 4, ctx->B); + SIVAL(digest, 8, ctx->C); + SIVAL(digest, 12, ctx->D); +} + +void get_md5(uint8_t *out, const uint8_t *input, int n) +{ + md_context ctx; + md5_begin(&ctx); + md5_update(&ctx, input, n); + md5_result(&ctx, out); +} + +#ifdef TEST_MD5 + +#include +#include + +/* + * those are the standard RFC 1321 test vectors + */ + +static struct { + char *str, *md5; +} tests[] = { + { "", + "d41d8cd98f00b204e9800998ecf8427e" }, + { "a", + "0cc175b9c0f1b6a831c399e269772661" }, + { "abc", + "900150983cd24fb0d6963f7d28e17f72" }, + { "message digest", + "f96b697d7cb7938d525a2f31aaf161d0" }, + { "abcdefghijklmnopqrstuvwxyz", + "c3fcd3d76192e4007dfb496cca67e13b" }, + { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "d174ab98d277d9f5a5611c2c9f419d9f" }, + { "12345678901234567890123456789012345678901234567890123456789012345678901234567890", + "57edf4a22be3c955ac49da2e2107b67a" }, + { NULL, NULL } +}; + +int main(int argc, char *argv[]) +{ + FILE *f; + int i, j; + char output[33]; + md_context ctx; + uint8_t buf[1000]; + uint8_t md5sum[MD5_DIGEST_LEN]; + + if (argc < 2) { + printf("\nMD5 Validation Tests:\n\n"); + + for (i = 0; tests[i].str; i++) { + char *str = tests[i].str; + char *chk = tests[i].md5; + + printf(" Test %d ", i + 1); + + get_md5(md5sum, str, strlen(str)); + + for (j = 0; j < MD5_DIGEST_LEN; j++) + sprintf(output + j * 2, "%02x", md5sum[j]); + + if (memcmp(output, chk, 32)) { + printf("failed!\n"); + return 1; + } + + printf("passed.\n"); + } + + printf("\n"); + return 0; + } + + while (--argc) { + if (!(f = fopen(*++argv, "rb"))) { + perror("fopen"); + return 1; + } + + md5_begin(&ctx); + + while ((i = fread(buf, 1, sizeof buf, f)) > 0) + md5_update(&ctx, buf, i); + + fclose(f); + + md5_result(&ctx, md5sum); + + for (j = 0; j < MD5_DIGEST_LEN; j++) + printf("%02x", md5sum[j]); + + printf(" %s\n", *argv); + } + + return 0; +} + +#endif diff --git a/contrib/md5/md5.h b/contrib/md5/md5.h new file mode 100644 index 000000000..ba8f08dbc --- /dev/null +++ b/contrib/md5/md5.h @@ -0,0 +1,78 @@ +/* rsync-3.0.6/byteorder.h */ + +/* + * Simple byteorder handling. + * + * Copyright (C) 1992-1995 Andrew Tridgell + * Copyright (C) 2007-2008 Wayne Davison + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, visit the http://fsf.org website. + */ + +#undef CAREFUL_ALIGNMENT + +/* We know that the x86 can handle misalignment and has the same + * byte order (LSB-first) as the 32-bit numbers we transmit. */ + +#ifdef __i386__ +#define CAREFUL_ALIGNMENT 0 +#endif + +#ifndef CAREFUL_ALIGNMENT +#define CAREFUL_ALIGNMENT 1 +#endif + +#define CVAL(buf,pos) (((unsigned char *)(buf))[pos]) +#define UVAL(buf,pos) ((uint32_t)CVAL(buf,pos)) +#define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val)) + +#if CAREFUL_ALIGNMENT +#define PVAL(buf,pos) (UVAL(buf,pos)|UVAL(buf,(pos)+1)<<8) +#define IVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+2)<<16) +#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8) +#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16)) +#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32_t)(val))) +#else + +/* this handles things for architectures like the 386 that can handle + alignment errors */ + +/* + WARNING: This section is dependent on the length of int32 + being correct. set CAREFUL_ALIGNMENT if it is not. +*/ + +#define IVAL(buf,pos) (*(uint32_t *)((char *)(buf) + (pos))) +#define SIVAL(buf,pos,val) IVAL(buf,pos)=((uint32_t)(val)) +#endif + +/* The include file for both the MD4 and MD5 routines. */ + +#define MD5_DIGEST_LEN 16 +#define MAX_DIGEST_LEN MD5_DIGEST_LEN + +#define CSUM_CHUNK 64 + +typedef struct { + uint32_t A, B, C, D; + uint32_t totalN; /* bit count, lower 32 bits */ + uint32_t totalN2; /* bit count, upper 32 bits */ + uint8_t buffer[CSUM_CHUNK]; +} md_context; + +void md5_begin(md_context *ctx); +void md5_update(md_context *ctx, const uint8_t *input, uint32_t length); +void md5_result(md_context *ctx, uint8_t digest[MD5_DIGEST_LEN]); + +void get_md5(uint8_t digest[MD5_DIGEST_LEN], const uint8_t *input, int n); diff --git a/glusterfsd/src/fetch-spec.c b/glusterfsd/src/fetch-spec.c index 239b3c902..f8dcb7584 100644 --- a/glusterfsd/src/fetch-spec.c +++ b/glusterfsd/src/fetch-spec.c @@ -34,6 +34,8 @@ #include "defaults.h" +#if 0 + int glusterfs_graph_parent_up (xlator_t *graph); static int @@ -297,3 +299,5 @@ fetch_spec (glusterfs_ctx_t *ctx) return spec_fp; } + +#endif diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index cf486d84f..01d155a2d 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 Gluster, Inc. + Copyright (c) 2006-2010 Gluster, Inc. This file is part of GlusterFS. GlusterFS is GF_FREE software; you can redistribute it and/or modify @@ -70,6 +70,7 @@ #include "statedump.h" #include "latency.h" #include "glusterfsd-mem-types.h" +#include "syscall.h" #include @@ -94,7 +95,7 @@ const char *argp_program_version = "" \ "the GNU General Public License."; const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; -error_t parse_opts (int32_t key, char *arg, struct argp_state *_state); +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:"}, @@ -106,11 +107,11 @@ static struct argp_option gf_options[] = { "This option should be provided with --volfile-server option" "[default: 1]"}, {"volfile", ARGP_VOLUME_FILE_KEY, "VOLFILE", 0, - "File to use as VOLUME_FILE [default: "DEFAULT_CLIENT_VOLUME_FILE" or " - DEFAULT_SERVER_VOLUME_FILE"]"}, + "File to use as VOLUME_FILE [default: "DEFAULT_CLIENT_VOLFILE" or " + DEFAULT_SERVER_VOLFILE"]"}, {"spec-file", ARGP_VOLUME_FILE_KEY, "VOLFILE", OPTION_HIDDEN, - "File to use as VOLFILE [default : "DEFAULT_CLIENT_VOLUME_FILE" or " - DEFAULT_SERVER_VOLUME_FILE"]"}, + "File to use as VOLFILE [default : "DEFAULT_CLIENT_VOLFILE" or " + DEFAULT_SERVER_VOLFILE"]"}, {"log-server", ARGP_LOG_SERVER_KEY, "LOG SERVER", 0, "Server to use as the central log server." "--log-server option"}, @@ -174,194 +175,83 @@ static struct argp_option gf_options[] = { static struct argp argp = { gf_options, parse_opts, argp_doc, gf_doc }; -/* Make use of pipe to synchronize daemonization */ -int -gf_daemon (int *pipe_fd) -{ - pid_t pid = -1; - int ret = -1; - int gf_daemon_buff = 0; - - if (pipe (pipe_fd) < 0) { - gf_log ("glusterfs", GF_LOG_ERROR, - "pipe creation error- %s", strerror (errno)); - return -1; - } - - if ((pid = fork ()) < 0) { - gf_log ("glusterfs", GF_LOG_ERROR, "fork error: %s", - strerror (errno)); - return -1; - } else if (pid != 0) { - close (pipe_fd[1]); - ret = read (pipe_fd[0], &gf_daemon_buff, - sizeof (int)); - close (pipe_fd[0]); - - if (ret == -1) { - gf_log ("glusterfs", GF_LOG_ERROR, - "read error on pipe- %s", strerror (errno)); - return ret; - } else if (ret == 0) { - gf_log ("glusterfs", GF_LOG_ERROR, - "end of file- %s", strerror (errno)); - return -1; - } else { - if (gf_daemon_buff == 0) - exit (EXIT_SUCCESS); - else - exit (EXIT_FAILURE); - } - } - - /*child continues*/ - close (pipe_fd[0]); - if (os_daemon (0, 0) == -1) { - gf_log ("glusterfs", GF_LOG_ERROR, - "unable to run in daemon mode: %s", - strerror (errno)); - return -1; - } - return 0; -} - -static void -_gf_dump_details (int argc, char **argv) -{ - extern FILE *gf_log_logfile; - int i = 0; - char timestr[256]; - time_t utime = 0; - struct tm *tm = NULL; - pid_t mypid = 0; - struct utsname uname_buf = {{0, }, }; - int uname_ret = -1; - - utime = time (NULL); - tm = localtime (&utime); - mypid = getpid (); - uname_ret = uname (&uname_buf); - - /* Which git? What time? */ - strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); - fprintf (gf_log_logfile, - "========================================" - "========================================\n"); - fprintf (gf_log_logfile, "Version : %s %s built on %s %s\n", - PACKAGE_NAME, PACKAGE_VERSION, __DATE__, __TIME__); - fprintf (gf_log_logfile, "git: %s\n", - GLUSTERFS_REPOSITORY_REVISION); - fprintf (gf_log_logfile, "Starting Time: %s\n", timestr); - fprintf (gf_log_logfile, "Command line : "); - for (i = 0; i < argc; i++) { - fprintf (gf_log_logfile, "%s ", argv[i]); - } - - fprintf (gf_log_logfile, "\nPID : %d\n", mypid); - - if (uname_ret == 0) { - fprintf (gf_log_logfile, "System name : %s\n", uname_buf.sysname); - fprintf (gf_log_logfile, "Nodename : %s\n", uname_buf.nodename); - fprintf (gf_log_logfile, "Kernel Release : %s\n", uname_buf.release); - fprintf (gf_log_logfile, "Hardware Identifier: %s\n", uname_buf.machine); - } - - - fprintf (gf_log_logfile, "\n"); - fflush (gf_log_logfile); -} - -static xlator_t * -gf_get_first_xlator (xlator_t *list) -{ - xlator_t *trav = NULL, *head = NULL; +int glusterfs_pidfile_cleanup (glusterfs_ctx_t *ctx); +int glusterfs_volumes_init (glusterfs_ctx_t *ctx); - trav = list; - do { - if (trav->prev == NULL) { - head = trav; - } - - trav = trav->prev; - } while (trav != NULL); - - return head; -} - -static xlator_t * -_add_fuse_mount (xlator_t *graph) +int +create_fuse_mount (glusterfs_ctx_t *ctx) { int ret = 0; cmd_args_t *cmd_args = NULL; - xlator_t *top = NULL; - glusterfs_ctx_t *ctx = NULL; - xlator_list_t *xlchild = NULL; + xlator_t *master = NULL; - ctx = graph->ctx; cmd_args = &ctx->cmd_args; - xlchild = GF_CALLOC (sizeof (*xlchild), 1, - gfd_mt_xlator_list_t); - ERR_ABORT (xlchild); - xlchild->xlator = graph; + if (!cmd_args->mount_point) + return 0; - top = GF_CALLOC (1, sizeof (*top), - gfd_mt_xlator_t); - top->name = gf_strdup ("fuse"); - if (xlator_set_type (top, ZR_XLATOR_FUSE) == -1) { - fprintf (stderr, - "MOUNT-POINT %s initialization failed", - cmd_args->mount_point); - gf_log ("glusterfs", GF_LOG_ERROR, + master = GF_CALLOC (1, sizeof (*master), + gfd_mt_xlator_t); + if (!master) + goto err; + + master->name = gf_strdup ("fuse"); + if (!master->name) + goto err; + + if (xlator_set_type (master, ZR_XLATOR_FUSE) == -1) { + gf_log ("glusterfsd", GF_LOG_ERROR, "MOUNT-POINT %s initialization failed", cmd_args->mount_point); - return NULL; + goto err; } - top->children = xlchild; - top->ctx = graph->ctx; - top->next = gf_get_first_xlator (graph); - top->options = get_new_dict (); - ret = dict_set_static_ptr (top->options, ZR_MOUNTPOINT_OPT, + master->ctx = ctx; + master->options = get_new_dict (); + + ret = dict_set_static_ptr (master->options, ZR_MOUNTPOINT_OPT, cmd_args->mount_point); if (ret < 0) { - gf_log ("glusterfs", GF_LOG_DEBUG, + gf_log ("glusterfsd", GF_LOG_ERROR, "failed to set mount-point to options dictionary"); + goto err; } if (cmd_args->fuse_attribute_timeout >= 0) - ret = dict_set_double (top->options, ZR_ATTR_TIMEOUT_OPT, + ret = dict_set_double (master->options, ZR_ATTR_TIMEOUT_OPT, cmd_args->fuse_attribute_timeout); if (cmd_args->fuse_entry_timeout) - ret = dict_set_double (top->options, ZR_ENTRY_TIMEOUT_OPT, + ret = dict_set_double (master->options, ZR_ENTRY_TIMEOUT_OPT, cmd_args->fuse_entry_timeout); if (cmd_args->volfile_check) - ret = dict_set_int32 (top->options, ZR_STRICT_VOLFILE_CHECK, + ret = dict_set_int32 (master->options, ZR_STRICT_VOLFILE_CHECK, cmd_args->volfile_check); if (cmd_args->dump_fuse) - ret = dict_set_static_ptr (top->options, ZR_DUMP_FUSE, + ret = dict_set_static_ptr (master->options, ZR_DUMP_FUSE, cmd_args->dump_fuse); #ifdef GF_DARWIN_HOST_OS /* On Darwin machines, O_APPEND is not handled, * which may corrupt the data */ + if (cmd_args->fuse_direct_io_mode_flag == 1) { - gf_log ("glusterfs", GF_LOG_DEBUG, + gf_log ("glusterfsd", GF_LOG_DEBUG, "'direct-io-mode' in fuse causes data corruption " "if O_APPEND is used. disabling 'direct-io-mode'"); } ret = dict_set_static_ptr (top->options, ZR_DIRECT_IO_OPT, "disable"); + #else /* ! DARWIN HOST OS */ switch (cmd_args->fuse_direct_io_mode_flag) { case 0: /* disable */ - ret = dict_set_static_ptr (top->options, ZR_DIRECT_IO_OPT, + ret = dict_set_static_ptr (master->options, ZR_DIRECT_IO_OPT, "disable"); break; case 1: /* enable */ - ret = dict_set_static_ptr (top->options, ZR_DIRECT_IO_OPT, + ret = dict_set_static_ptr (master->options, ZR_DIRECT_IO_OPT, "enable"); break; case 2: /* default */ @@ -371,60 +261,25 @@ _add_fuse_mount (xlator_t *graph) #endif /* GF_DARWIN_HOST_OS */ - graph->parents = GF_CALLOC (1, sizeof (xlator_list_t), - gfd_mt_xlator_list_t); - graph->parents->xlator = top; - - return top; -} + ret = xlator_init (master); + if (ret) + goto err; -static xlator_t * -_add_volume (xlator_t *graph, const char *voltype) -{ - cmd_args_t *cmd_args = NULL; - xlator_t *top = NULL; - glusterfs_ctx_t *ctx = NULL; - xlator_list_t *xlchild = NULL; - char *shortvoltype = (char *)voltype; + ctx->master = master; - ctx = graph->ctx; - cmd_args = &ctx->cmd_args; - for (;;) { - if (*(shortvoltype++) == '/') - break; - assert (*shortvoltype); - } - - xlchild = CALLOC (sizeof (*xlchild), 1); - if (!xlchild) { - return NULL; - } - xlchild->xlator = graph; + return 0; - top = CALLOC (1, sizeof (*top)); - top->name = strdup (shortvoltype); - if (xlator_set_type (top, voltype) == -1) { - fprintf (stderr, - "%s volume initialization failed", - shortvoltype); - gf_log ("glusterfs", GF_LOG_ERROR, - "%s initialization failed", shortvoltype); - return NULL; +err: + if (master) { + xlator_destroy (master); } - top->children = xlchild; - top->ctx = graph->ctx; - top->next = gf_get_first_xlator (graph); - top->options = get_new_dict (); - graph->parents = CALLOC (1, sizeof (xlator_list_t)); - graph->parents->xlator = top; - - return top; + return -1; } static FILE * -_get_specfp (glusterfs_ctx_t *ctx) +get_volfp (glusterfs_ctx_t *ctx) { int ret = 0; cmd_args_t *cmd_args = NULL; @@ -434,18 +289,15 @@ _get_specfp (glusterfs_ctx_t *ctx) cmd_args = &ctx->cmd_args; if (cmd_args->volfile_server) { - specfp = fetch_spec (ctx); +// specfp = fetch_spec (ctx); if (specfp == NULL) { - fprintf (stderr, - "error while getting volume file from " - "server %s\n", cmd_args->volfile_server); - gf_log ("glusterfs", GF_LOG_ERROR, + gf_log ("glusterfsd", GF_LOG_ERROR, "error while getting volume file from " "server %s", cmd_args->volfile_server); } else { - gf_log ("glusterfs", GF_LOG_DEBUG, + gf_log ("glusterfsd", GF_LOG_DEBUG, "loading volume file from server %s", cmd_args->volfile_server); } @@ -453,284 +305,27 @@ _get_specfp (glusterfs_ctx_t *ctx) return specfp; } - ret = stat (cmd_args->volume_file, &statbuf); + ret = sys_lstat (cmd_args->volfile, &statbuf); if (ret == -1) { - fprintf (stderr, "%s: %s\n", - cmd_args->volume_file, strerror (errno)); - gf_log ("glusterfs", GF_LOG_ERROR, - "%s: %s", cmd_args->volume_file, strerror (errno)); - return NULL; - } - if (!(S_ISREG (statbuf.st_mode) || S_ISLNK (statbuf.st_mode))) { - fprintf (stderr, - "provide a valid volume file\n"); - gf_log ("glusterfs", GF_LOG_ERROR, - "provide a valid volume file"); + gf_log ("glusterfsd", GF_LOG_ERROR, + "%s: %s", cmd_args->volfile, strerror (errno)); return NULL; } - if ((specfp = fopen (cmd_args->volume_file, "r")) == NULL) { - fprintf (stderr, "volume file %s: %s\n", - cmd_args->volume_file, - strerror (errno)); - gf_log ("glusterfs", GF_LOG_ERROR, + + if ((specfp = fopen (cmd_args->volfile, "r")) == NULL) { + gf_log ("glusterfsd", GF_LOG_ERROR, "volume file %s: %s", - cmd_args->volume_file, + cmd_args->volfile, strerror (errno)); return NULL; } - gf_log ("glusterfs", GF_LOG_DEBUG, - "loading volume file %s", cmd_args->volume_file); + gf_log ("glusterfsd", GF_LOG_DEBUG, + "loading volume file %s", cmd_args->volfile); return specfp; } -static xlator_t * -_parse_specfp (glusterfs_ctx_t *ctx, - FILE *specfp) -{ - int spec_fd = 0; - cmd_args_t *cmd_args = NULL; - xlator_t *tree = NULL, *trav = NULL, *new_tree = NULL; - - cmd_args = &ctx->cmd_args; - - fseek (specfp, 0L, SEEK_SET); - - tree = file_to_xlator_tree (ctx, specfp); - trav = tree; - - if (tree == NULL) { - if (cmd_args->volfile_server) { - fprintf (stderr, - "error in parsing volume file given by " - "server %s\n", cmd_args->volfile_server); - gf_log ("glusterfs", GF_LOG_ERROR, - "error in parsing volume file given by " - "server %s", cmd_args->volfile_server); - } - else { - fprintf (stderr, - "error in parsing volume file %s\n", - cmd_args->volume_file); - gf_log ("glusterfs", GF_LOG_ERROR, - "error in parsing volume file %s", - cmd_args->volume_file); - } - return NULL; - } - - spec_fd = fileno (specfp); - get_checksum_for_file (spec_fd, &ctx->volfile_checksum); - - /* if volume_name is given, then we attach to it */ - if (cmd_args->volume_name) { - while (trav) { - if (strcmp (trav->name, cmd_args->volume_name) == 0) { - new_tree = trav; - break; - } - trav = trav->next; - } - - if (!trav) { - if (cmd_args->volfile_server) { - fprintf (stderr, - "volume %s not found in volume " - "file given by server %s\n", - cmd_args->volume_name, - cmd_args->volfile_server); - gf_log ("glusterfs", GF_LOG_ERROR, - "volume %s not found in volume " - "file given by server %s", - cmd_args->volume_name, - cmd_args->volfile_server); - } else { - fprintf (stderr, - "volume %s not found in volume " - "file %s\n", - cmd_args->volume_name, - cmd_args->volume_file); - gf_log ("glusterfs", GF_LOG_ERROR, - "volume %s not found in volume " - "file %s", cmd_args->volume_name, - cmd_args->volume_file); - } - return NULL; - } - tree = trav; - } - return tree; -} - -static int -_log_if_option_is_invalid (xlator_t *xl, data_pair_t *pair) -{ - volume_opt_list_t *vol_opt = NULL; - volume_option_t *opt = NULL; - int i = 0; - int index = 0; - int found = 0; - - /* Get the first volume_option */ - list_for_each_entry (vol_opt, &xl->volume_options, list) { - /* Warn for extra option */ - if (!vol_opt->given_opt) - break; - - opt = vol_opt->given_opt; - for (index = 0; - ((index < ZR_OPTION_MAX_ARRAY_SIZE) && - (opt[index].key && opt[index].key[0])); index++) - for (i = 0; (i < ZR_VOLUME_MAX_NUM_KEY) && - opt[index].key[i]; i++) { - if (fnmatch (opt[index].key[i], - pair->key, - FNM_NOESCAPE) == 0) { - found = 1; - break; - } - } - } - - if (!found) { - gf_log (xl->name, GF_LOG_WARNING, - "option '%s' is not recognized", - pair->key); - } - return 0; -} - -static int -_xlator_graph_init (xlator_t *xl) -{ - volume_opt_list_t *vol_opt = NULL; - data_pair_t *pair = NULL; - xlator_t *trav = NULL; - int ret = -1; - - trav = xl; - - while (trav->prev) - trav = trav->prev; - - /* Validate phase */ - while (trav) { - /* Get the first volume_option */ - list_for_each_entry (vol_opt, - &trav->volume_options, list) - break; - if ((ret = - validate_xlator_volume_options (trav, - vol_opt->given_opt)) < 0) { - gf_log (trav->name, GF_LOG_ERROR, - "validating translator failed"); - return ret; - } - trav = trav->next; - } - - - trav = xl; - while (trav->prev) - trav = trav->prev; - /* Initialization phase */ - while (trav) { - if (!trav->ready) { - if ((ret = xlator_tree_init (trav)) < 0) { - gf_log ("glusterfs", GF_LOG_ERROR, - "initializing translator failed"); - return ret; - } - } - trav = trav->next; - } - - /* No error in this phase, just bunch of warning if at all */ - trav = xl; - - while (trav->prev) - trav = trav->prev; - - /* Validate again phase */ - while (trav) { - pair = trav->options->members_list; - while (pair) { - _log_if_option_is_invalid (trav, pair); - pair = pair->next; - } - trav = trav->next; - } - - return ret; -} - -int -glusterfs_graph_parent_up (xlator_t *graph) -{ - xlator_t *trav = NULL; - int ret = -1; - - trav = graph; - - while (trav->prev) - trav = trav->prev; - - while (trav) { - if (!xlator_has_parent (trav)) { - ret = trav->notify (trav, GF_EVENT_PARENT_UP, trav); - } - - if (ret) - break; - - trav = trav->next; - } - - return ret; -} - -int -glusterfs_graph_init (xlator_t *graph, int fuse) -{ - volume_opt_list_t *vol_opt = NULL; - - if (fuse) { - /* FUSE needs to be initialized earlier than the - other translators */ - list_for_each_entry (vol_opt, - &graph->volume_options, list) - break; - if (validate_xlator_volume_options (graph, - vol_opt->given_opt) == -1) { - gf_log (graph->name, GF_LOG_ERROR, - "validating translator failed"); - return -1; - } - - if (graph->mem_acct_init (graph) != 0) - return -1; - - if (xlator_init (graph) != 0) - return -1; - - graph->ready = 1; - } - if (_xlator_graph_init (graph) == -1) - return -1; - - /* check server or fuse is given */ - if (graph->ctx->top == NULL) { - fprintf (stderr, "no valid translator loaded at the top, or" - "no mount point given. exiting\n"); - gf_log ("glusterfs", GF_LOG_ERROR, - "no valid translator loaded at the top or " - "no mount point given. exiting"); - return -1; - } - - return 0; -} static int gf_remember_xlator_option (struct list_head *options, char *arg) @@ -742,7 +337,7 @@ gf_remember_xlator_option (struct list_head *options, char *arg) char *dot = NULL; char *equals = NULL; - ctx = get_global_ctx_ptr (); + ctx = glusterfs_ctx_get (); cmd_args = &ctx->cmd_args; option = GF_CALLOC (1, sizeof (xlator_cmdline_option_t), @@ -791,42 +386,8 @@ out: } -static void -gf_add_cmdline_options (xlator_t *graph, cmd_args_t *cmd_args) -{ - int ret = 0; - xlator_t *trav = graph; - xlator_cmdline_option_t *cmd_option = NULL; - - while (trav) { - list_for_each_entry (cmd_option, - &cmd_args->xlator_options, cmd_args) { - if (!fnmatch (cmd_option->volume, - trav->name, FNM_NOESCAPE)) { - ret = dict_set_str (trav->options, - cmd_option->key, - cmd_option->value); - if (ret == 0) { - gf_log ("glusterfs", GF_LOG_WARNING, - "adding option '%s' for " - "volume '%s' with value '%s'", - cmd_option->key, trav->name, - cmd_option->value); - } else { - gf_log ("glusterfs", GF_LOG_WARNING, - "adding option '%s' for " - "volume '%s' failed: %s", - cmd_option->key, trav->name, - strerror (-ret)); - } - } - } - trav = trav->next; - } -} - -error_t +static error_t parse_opts (int key, char *arg, struct argp_state *state) { cmd_args_t *cmd_args = NULL; @@ -861,10 +422,16 @@ parse_opts (int key, char *arg, struct argp_state *state) break; case ARGP_VOLUME_FILE_KEY: - cmd_args->volume_file = gf_strdup (arg); + if (cmd_args->volfile) + GF_FREE (cmd_args->volfile); + + cmd_args->volfile = gf_strdup (arg); break; case ARGP_LOG_SERVER_KEY: + if (cmd_args->log_server) + GF_FREE (cmd_args->log_server); + cmd_args->log_server = gf_strdup (arg); break; @@ -1017,48 +584,40 @@ parse_opts (int key, char *arg, struct argp_state *state) } -void +static void cleanup_and_exit (int signum) { glusterfs_ctx_t *ctx = NULL; - xlator_t *trav = NULL; - ctx = get_global_ctx_ptr (); + ctx = glusterfs_ctx_get (); - gf_log ("glusterfs", GF_LOG_WARNING, "shutting down"); + gf_log ("glusterfsd", GF_LOG_NORMAL, "shutting down"); - if (ctx->pidfp) { - lockf (fileno (ctx->pidfp), F_ULOCK, 0); - fclose (ctx->pidfp); - ctx->pidfp = NULL; - } + glusterfs_pidfile_cleanup (ctx); - if (ctx->specfp) { - fclose (ctx->specfp); - ctx->specfp = NULL; - } + exit (0); +} - if (ctx->cmd_args.pid_file) { - unlink (ctx->cmd_args.pid_file); - ctx->cmd_args.pid_file = NULL; - } - if (ctx->graph) { - trav = ctx->graph; - ctx->graph = NULL; - while (trav) { - trav->fini (trav); - trav = trav->next; - } - exit (0); - } else { - gf_log ("glusterfs", GF_LOG_DEBUG, "no graph present"); - } +static void +reincarnate (int signum) +{ + int ret = 0; + glusterfs_ctx_t *ctx = NULL; + + ctx = glusterfs_ctx_get (); + + gf_log ("glusterfsd", GF_LOG_NORMAL, + "Reloading volfile ..."); + + ret = glusterfs_volumes_init (ctx); + + return; } static char * -zr_build_process_uuid () +generate_uuid () { char tmp_str[1024] = {0,}; char hostname[256] = {0,}; @@ -1066,14 +625,14 @@ zr_build_process_uuid () struct tm now = {0, }; char now_str[32]; - if (-1 == gettimeofday(&tv, NULL)) { - gf_log ("", GF_LOG_ERROR, + if (gettimeofday (&tv, NULL) == -1) { + gf_log ("glusterfsd", GF_LOG_ERROR, "gettimeofday: failed %s", strerror (errno)); } - if (-1 == gethostname (hostname, 256)) { - gf_log ("", GF_LOG_ERROR, + if (gethostname (hostname, 256) == -1) { + gf_log ("glusterfsd", GF_LOG_ERROR, "gethostname: failed %s", strerror (errno)); } @@ -1094,6 +653,7 @@ zr_build_process_uuid () #define GF_SERVER_PROCESS 0 #define GF_CLIENT_PROCESS 1 + static uint8_t gf_get_process_mode (char *exec_name) { @@ -1114,7 +674,9 @@ gf_get_process_mode (char *exec_name) return ret; } -int + + +static int set_log_file_path (cmd_args_t *cmd_args) { int i = 0; @@ -1134,30 +696,31 @@ set_log_file_path (cmd_args_t *cmd_args) if (cmd_args->mount_point[i] == '/') tmp_str[j] = '-'; } + ret = gf_asprintf (&cmd_args->log_file, DEFAULT_LOG_FILE_DIRECTORY "/%s.log", tmp_str); - if (-1 == ret) { + if (ret == -1) { gf_log ("glusterfsd", GF_LOG_ERROR, "asprintf failed while setting up log-file"); } goto done; } - if (cmd_args->volume_file) { + if (cmd_args->volfile) { j = 0; i = 0; - if (cmd_args->volume_file[0] == '/') + if (cmd_args->volfile[0] == '/') i = 1; - for (; i < strlen (cmd_args->volume_file); i++,j++) { - tmp_str[j] = cmd_args->volume_file[i]; - if (cmd_args->volume_file[i] == '/') + for (; i < strlen (cmd_args->volfile); i++,j++) { + tmp_str[j] = cmd_args->volfile[i]; + if (cmd_args->volfile[i] == '/') tmp_str[j] = '-'; } ret = gf_asprintf (&cmd_args->log_file, DEFAULT_LOG_FILE_DIRECTORY "/%s.log", tmp_str); - if (-1 == ret) { + if (ret == -1) { gf_log ("glusterfsd", GF_LOG_ERROR, "asprintf failed while setting up log-file"); } @@ -1185,91 +748,120 @@ done: return ret; } -int -main (int argc, char *argv[]) + +static int +glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx) { - glusterfs_ctx_t *ctx = NULL; - cmd_args_t *cmd_args = NULL; - call_pool_t *pool = NULL; - struct stat stbuf; - char tmp_logfile[1024] = { 0 }; - char *tmp_logfile_dyn = NULL; - char *tmp_logfilebase = NULL; - char timestr[256] = { 0 }; - time_t utime; - struct tm *tm = NULL; - int ret = 0; - struct rlimit lim; - FILE *specfp = NULL; - xlator_t *graph = NULL; - xlator_t *trav = NULL; - int fuse_volume_found = 0; - int xl_count = 0; - uint8_t process_mode = 0; - int pipe_fd[2]; - int gf_success = 0; - int gf_failure = -1; + cmd_args_t *cmd_args = NULL; + struct rlimit lim = {0, }; + call_pool_t *pool = NULL; - ret = glusterfs_globals_init (); - if (ret) - return ret; + xlator_mem_acct_init (THIS, gfd_mt_end); - ret = xlator_mem_acct_init (THIS, gfd_mt_end); - if (ret) - return ret; + ctx->process_uuid = generate_uuid (); + if (!ctx->process_uuid) + return -1; + + ctx->page_size = 128 * GF_UNIT_KB; + + ctx->iobuf_pool = iobuf_pool_new (8 * GF_UNIT_MB, ctx->page_size); + if (!ctx->iobuf_pool) + return -1; + + ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE); + if (!ctx->event_pool) + return -1; + + pool = GF_CALLOC (1, sizeof (call_pool_t), + gfd_mt_call_pool_t); + if (!pool) + return -1; + INIT_LIST_HEAD (&pool->all_frames); + LOCK_INIT (&pool->lock); + ctx->pool = pool; + + pthread_mutex_init (&(ctx->lock), NULL); - utime = time (NULL); - ctx = glusterfs_ctx_get (); - process_mode = gf_get_process_mode (argv[0]); - set_global_ctx_ptr (ctx); - ctx->process_uuid = zr_build_process_uuid (); cmd_args = &ctx->cmd_args; /* parsing command line arguments */ cmd_args->log_level = DEFAULT_LOG_LEVEL; - cmd_args->fuse_direct_io_mode_flag = 2; + cmd_args->fuse_direct_io_mode_flag = _gf_true; cmd_args->fuse_attribute_timeout = -1; INIT_LIST_HEAD (&cmd_args->xlator_options); - argp_parse (&argp, argc, argv, ARGP_IN_ORDER, NULL, cmd_args); + lim.rlim_cur = RLIM_INFINITY; + lim.rlim_max = RLIM_INFINITY; + setrlimit (RLIMIT_CORE, &lim); - if (ENABLE_DEBUG_MODE == cmd_args->debug_mode) { - cmd_args->log_level = GF_LOG_DEBUG; - cmd_args->log_file = "/dev/stdout"; - cmd_args->no_daemon_mode = ENABLE_NO_DAEMON_MODE; - } + return 0; +} - if ((cmd_args->volfile_server == NULL) - && (cmd_args->volume_file == NULL)) { - if (process_mode == GF_SERVER_PROCESS) - cmd_args->volume_file = gf_strdup (DEFAULT_SERVER_VOLUME_FILE); - else - cmd_args->volume_file = gf_strdup (DEFAULT_CLIENT_VOLUME_FILE); - } + +static int +logging_init (glusterfs_ctx_t *ctx) +{ + cmd_args_t *cmd_args = NULL; + int ret = 0; + + cmd_args = &ctx->cmd_args; if (cmd_args->log_file == NULL) { ret = set_log_file_path (cmd_args); - if (-1 == ret) { + if (ret == -1) { fprintf (stderr, "failed to set the log file path.. " "exiting\n"); return -1; } } - ctx->page_size = 128 * GF_UNIT_KB; - ctx->iobuf_pool = iobuf_pool_new (8 * GF_UNIT_MB, ctx->page_size); - ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE); - pthread_mutex_init (&(ctx->lock), NULL); - pool = ctx->pool = GF_CALLOC (1, sizeof (call_pool_t), - gfd_mt_call_pool_t); - ERR_ABORT (ctx->pool); - LOCK_INIT (&pool->lock); - INIT_LIST_HEAD (&pool->all_frames); + if (gf_log_init (cmd_args->log_file) == -1) { + fprintf (stderr, + "failed to open logfile %s. exiting\n", + cmd_args->log_file); + return -1; + } + + gf_log_set_loglevel (cmd_args->log_level); + + return 0; +} + + +int +parse_cmdline (int argc, char *argv[], cmd_args_t *cmd_args) +{ + int process_mode = 0; + int ret = 0; + struct stat stbuf = {0, }; + struct tm *tm = NULL; + time_t utime; + char timestr[256]; + char tmp_logfile[1024] = { 0 }; + char *tmp_logfile_dyn = NULL; + char *tmp_logfilebase = NULL; + + argp_parse (&argp, argc, argv, ARGP_IN_ORDER, NULL, cmd_args); + + if (ENABLE_DEBUG_MODE == cmd_args->debug_mode) { + cmd_args->log_level = GF_LOG_DEBUG; + cmd_args->log_file = "/dev/stderr"; + cmd_args->no_daemon_mode = ENABLE_NO_DAEMON_MODE; + } + + process_mode = gf_get_process_mode (argv[0]); + + if ((cmd_args->volfile_server == NULL) + && (cmd_args->volfile == NULL)) { + if (process_mode == GF_SERVER_PROCESS) + cmd_args->volfile = gf_strdup (DEFAULT_SERVER_VOLFILE); + else + cmd_args->volfile = gf_strdup (DEFAULT_CLIENT_VOLFILE); + } - /* initializing logs */ if (cmd_args->run_id) { - ret = stat (cmd_args->log_file, &stbuf); + ret = sys_lstat (cmd_args->log_file, &stbuf); /* If its /dev/null, or /dev/stdout, /dev/stderr, * let it use the same, no need to alter */ @@ -1283,12 +875,13 @@ main (int argc, char *argv[]) cmd_args->log_file, timestr, getpid ()); /* Create symlink to actual log file */ - unlink (cmd_args->log_file); + sys_unlink (cmd_args->log_file); tmp_logfile_dyn = gf_strdup (tmp_logfile); tmp_logfilebase = basename (tmp_logfile_dyn); - ret = symlink (tmp_logfilebase, cmd_args->log_file); - if (-1 == ret) { + ret = sys_symlink (tmp_logfilebase, + cmd_args->log_file); + if (ret == -1) { fprintf (stderr, "symlink of logfile failed"); } else { GF_FREE (cmd_args->log_file); @@ -1299,218 +892,346 @@ main (int argc, char *argv[]) } } - gf_global_variable_init (); + return 0; +} - if (gf_log_init (cmd_args->log_file) == -1) { - fprintf (stderr, - "failed to open logfile %s. exiting\n", - cmd_args->log_file); - return -1; - } - gf_log_set_loglevel (cmd_args->log_level); - gf_proc_dump_init(); - /* setting up environment */ - lim.rlim_cur = RLIM_INFINITY; - lim.rlim_max = RLIM_INFINITY; - if (setrlimit (RLIMIT_CORE, &lim) == -1) { - fprintf (stderr, "ignoring %s\n", - strerror (errno)); - } -#ifdef DEBUG - mtrace (); -#endif +int +glusterfs_pidfile_setup (glusterfs_ctx_t *ctx) +{ + cmd_args_t *cmd_args = NULL; + int ret = 0; + FILE *pidfp = NULL; - signal (SIGUSR1, gf_proc_dump_info); - signal (SIGUSR2, gf_latency_toggle); - signal (SIGSEGV, gf_print_trace); - signal (SIGABRT, gf_print_trace); - signal (SIGPIPE, SIG_IGN); - signal (SIGHUP, gf_log_logrotate); - signal (SIGTERM, cleanup_and_exit); - /* if used inside GDB, then this is overridden, hence making - it a safer option */ - signal (SIGINT, cleanup_and_exit); - - /* This is used to dump details */ - /* signal (SIGUSR2, (sighandler_t) glusterfs_stats); */ - - /* getting and parsing volume file */ - if ((specfp = _get_specfp (ctx)) == NULL) { - /* _get_specfp() prints necessary error message */ - gf_log ("glusterfs", GF_LOG_ERROR, "exiting\n"); - argp_help (&argp, stderr, ARGP_HELP_SEE, (char *) argv[0]); + cmd_args = &ctx->cmd_args; + + if (!cmd_args->pid_file) + return 0; + + pidfp = fopen (cmd_args->pid_file, "a+"); + if (!pidfp) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "pidfile %s error (%s)", + cmd_args->pid_file, strerror (errno)); return -1; } - if ((graph = _parse_specfp (ctx, specfp)) == NULL) { - /* _parse_specfp() prints necessary error message */ - fprintf (stderr, "exiting\n"); - gf_log ("glusterfs", GF_LOG_ERROR, "exiting"); - return -1; + ret = lockf (fileno (pidfp), F_TLOCK, 0); + if (ret) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "pidfile %s lock error (%s)", + cmd_args->pid_file, strerror (errno)); + return ret; } - ctx->specfp = specfp; - /* check whether MOUNT-POINT argument and fuse volume are given - * at same time or not. If not, add argument MOUNT-POINT to graph - * as top volume if given - */ - trav = graph; - fuse_volume_found = 0; - - while (trav) { - if (strcmp (trav->type, ZR_XLATOR_FUSE) == 0) { - if (dict_get (trav->options, - ZR_MOUNTPOINT_OPT) != NULL) { - trav->ctx = graph->ctx; - fuse_volume_found = 1; - } - } + gf_log ("glusterfsd", GF_LOG_TRACE, + "pidfile %s lock acquired", + cmd_args->pid_file); + + ret = lockf (fileno (pidfp), F_ULOCK, 0); + + ctx->pidfp = pidfp; + + return 0; +} + + +int +glusterfs_pidfile_cleanup (glusterfs_ctx_t *ctx) +{ + cmd_args_t *cmd_args = NULL; + + cmd_args = &ctx->cmd_args; - xl_count++; /* Getting this value right is very important */ - trav = trav->next; + if (!ctx->pidfp) + return 0; + + gf_log ("glusterfsd", GF_LOG_TRACE, + "pidfile %s unlocking", + cmd_args->pid_file); + + lockf (fileno (ctx->pidfp), F_ULOCK, 0); + fclose (ctx->pidfp); + ctx->pidfp = NULL; + + if (ctx->cmd_args.pid_file) { + unlink (ctx->cmd_args.pid_file); + ctx->cmd_args.pid_file = NULL; } - ctx->xl_count = xl_count + 1; + return 0; +} - if (cmd_args->read_only && !fuse_volume_found && - (cmd_args->mount_point == NULL)) { - gf_log ("glusterfs", GF_LOG_ERROR, - "'--read-only' option is valid only on client side"); - fprintf (stderr, "'--read-only' option is valid only " - "on client side, exiting\n"); - return -1; +int +glusterfs_pidfile_update (glusterfs_ctx_t *ctx) +{ + cmd_args_t *cmd_args = NULL; + int ret = 0; + FILE *pidfp = NULL; + + cmd_args = &ctx->cmd_args; + + pidfp = ctx->pidfp; + if (!pidfp) + return 0; + + ret = lockf (fileno (pidfp), F_TLOCK, 0); + if (ret) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "pidfile %s lock failed", + cmd_args->pid_file); + return ret; } - if (graph && !fuse_volume_found && (cmd_args->mount_point != NULL)) { - /* Check for read-only option and add a read-only translator */ - if (cmd_args->read_only) - graph = _add_volume (graph, ZR_XLATOR_READ_ONLY); - if (graph -#ifndef GF_DARWIN_HOST_OS - && cmd_args->mac_compat -#endif - ) - graph = _add_volume (graph, ZR_XLATOR_MAC_COMPAT); - if (graph) - graph = _add_fuse_mount (graph); + + ret = ftruncate (fileno (pidfp), 0); + if (ret) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "pidfile %s truncation failed", + cmd_args->pid_file); + return ret; } - if (!graph) { - fprintf (stderr, "failed to complete xlator graph, exiting\n"); - gf_log ("glusterfs", GF_LOG_ERROR, "exiting"); - return -1; + + ret = fprintf (pidfp, "%d\n", getpid ()); + if (ret <= 0) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "pidfile %s write failed", + cmd_args->pid_file); + return ret; } - /* daemonize now */ - if (!cmd_args->no_daemon_mode) { - if (gf_daemon (pipe_fd) == -1) { - gf_log ("glusterfs", GF_LOG_ERROR, - "unable to run in daemon mode: %s", - strerror (errno)); - return -1; + ret = fflush (pidfp); + if (ret) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "pidfile %s write failed", + cmd_args->pid_file); + return ret; + } + + gf_log ("glusterfsd", GF_LOG_DEBUG, + "pidfile %s updated with pid %d", + cmd_args->pid_file, getpid ()); + + return 0; +} + + +void * +glusterfs_sigwaiter (void *arg) +{ + sigset_t set; + int ret = 0; + int sig = 0; + + + sigaddset (&set, SIGINT); /* cleanup_and_exit */ + sigaddset (&set, SIGTERM); /* cleanup_and_exit */ + sigaddset (&set, SIGHUP); /* reincarnate */ + sigaddset (&set, SIGUSR1); /* gf_proc_dump_info */ + sigaddset (&set, SIGUSR2); /* gf_latency_toggle */ + + for (;;) { + ret = sigwait (&set, &sig); + if (ret) { + gf_log ("sigwaiter", GF_LOG_ERROR, + "sigwait returned error (%s)", + strerror (ret)); + continue; } - /* we are daemon now */ - _gf_dump_details (argc, argv); - if (cmd_args->pid_file != NULL) { - ctx->pidfp = fopen (cmd_args->pid_file, "a+"); - if (ctx->pidfp == NULL) { - gf_log ("glusterfs", GF_LOG_ERROR, - "unable to open pid file %s, %s.", - cmd_args->pid_file, - strerror (errno)); - if (write (pipe_fd[1], &gf_failure, - sizeof (int)) < 0) { - gf_log ("glusterfs", GF_LOG_ERROR, - "Write on pipe error"); - } - /* do cleanup and exit ?! */ - return -1; - } - ret = lockf (fileno (ctx->pidfp), - (F_LOCK | F_TLOCK), 0); - if (ret == -1) { - gf_log ("glusterfs", GF_LOG_ERROR, - "Is another instance of %s running?", - argv[0]); - fclose (ctx->pidfp); - if (write (pipe_fd[1], &gf_failure, - sizeof (int)) < 0) { - gf_log ("glusterfs", GF_LOG_ERROR, - "Write on pipe error"); - } - return ret; - } - ret = ftruncate (fileno (ctx->pidfp), 0); - if (ret == -1) { - gf_log ("glusterfs", GF_LOG_ERROR, - "unable to truncate file %s. %s.", - cmd_args->pid_file, - strerror (errno)); - lockf (fileno (ctx->pidfp), F_ULOCK, 0); - fclose (ctx->pidfp); - if (write (pipe_fd[1], &gf_failure, - sizeof (int)) < 0) { - gf_log ("glusterfs", GF_LOG_ERROR, - "Write on pipe error"); - } - return ret; - } + gf_log ("sigwaiter", GF_LOG_DEBUG, + "received signal %d", sig); - /* update pid file, if given */ - fprintf (ctx->pidfp, "%d\n", getpid ()); - fflush (ctx->pidfp); - /* we close pid file on exit */ + switch (sig) { + case SIGINT: + case SIGTERM: + cleanup_and_exit (sig); + break; + case SIGHUP: + reincarnate (sig); + break; + case SIGUSR1: + gf_proc_dump_info (sig); + break; + case SIGUSR2: + gf_latency_toggle (sig); + break; + default: + gf_log ("sigwaiter", GF_LOG_ERROR, + "unhandled signal: %d", sig); + break; } - } else { - /* - * Need to have this line twice because PID is different - * in daemon and non-daemon cases. - */ + } - _gf_dump_details (argc, argv); + return NULL; +} + + +int +glusterfs_signals_setup (glusterfs_ctx_t *ctx) +{ + sigset_t set; + int ret = 0; + + sigemptyset (&set); + + /* common setting for all threads */ + signal (SIGSEGV, gf_print_trace); + signal (SIGABRT, gf_print_trace); + signal (SIGILL, gf_print_trace); + signal (SIGTRAP, gf_print_trace); + signal (SIGFPE, gf_print_trace); + signal (SIGBUS, gf_print_trace); + signal (SIGPIPE, SIG_IGN); + + /* block these signals from non-sigwaiter threads */ + sigaddset (&set, SIGINT); /* cleanup_and_exit */ + sigaddset (&set, SIGTERM); /* cleanup_and_exit */ + sigaddset (&set, SIGHUP); /* reincarnate */ + sigaddset (&set, SIGUSR1); /* gf_proc_dump_info */ + sigaddset (&set, SIGUSR2); /* gf_latency_toggle */ + + ret = pthread_sigmask (SIG_BLOCK, &set, NULL); + if (ret) + return ret; + + ret = pthread_create (&ctx->sigwaiter, NULL, glusterfs_sigwaiter, + (void *) &set); + if (ret) { + /* + TODO: + fallback to signals getting handled by other threads. + setup the signal handlers + */ + return ret; } - gf_log_volume_file (ctx->specfp); + return ret; +} - gf_log ("glusterfs", GF_LOG_DEBUG, - "running in pid %d", getpid ()); - gf_timer_registry_init (ctx); +int +daemonize (glusterfs_ctx_t *ctx) +{ + int ret = 0; + cmd_args_t *cmd_args = NULL; - /* override xlator options with command line options - * where applicable - */ - gf_add_cmdline_options (graph, cmd_args); - - ctx->graph = graph; - if (glusterfs_graph_init (graph, fuse_volume_found) != 0) { - gf_log ("glusterfs", GF_LOG_ERROR, - "translator initialization failed. exiting"); - if (!cmd_args->no_daemon_mode && - (write (pipe_fd[1], &gf_failure, sizeof (int)) < 0)) { - gf_log ("glusterfs", GF_LOG_ERROR, - "Write on pipe failed," - "daemonize problem.exiting: %s", - strerror (errno)); - } - return -1; + + cmd_args = &ctx->cmd_args; + + ret = glusterfs_pidfile_setup (ctx); + if (ret) + return ret; + + if (cmd_args->no_daemon_mode) + goto postfork; + + if (cmd_args->debug_mode) + goto postfork; + + daemon (0, 0); + +postfork: + ret = glusterfs_pidfile_update (ctx); + if (ret) + return ret; + + glusterfs_signals_setup (ctx); + + return ret; +} + + +int +glusterfs_volumes_init (glusterfs_ctx_t *ctx) +{ + FILE *fp = NULL; + glusterfs_graph_t *graph = NULL; + int ret = 0; + + fp = get_volfp (ctx); + + if (!fp) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "Cannot reach volume specification file"); + ret = -1; + goto out; } - /* Send PARENT_UP notify to all the translators now */ - glusterfs_graph_parent_up (graph); + graph = glusterfs_graph_construct (fp); - gf_log ("glusterfs", GF_LOG_NORMAL, "Successfully started"); + if (!graph) { + ret = -1; + goto out; + } - if (!cmd_args->no_daemon_mode && - (write (pipe_fd[1], &gf_success, sizeof (int)) < 0)) { - gf_log ("glusterfs", GF_LOG_ERROR, - "Write on pipe failed," - "daemonize problem. exiting: %s", - strerror (errno)); - return -1; + ret = glusterfs_graph_prepare (graph, ctx); + + if (ret) { + glusterfs_graph_destroy (graph); + ret = -1; + goto out; } - event_dispatch (ctx->event_pool); + ret = glusterfs_graph_activate (ctx, graph); - return 0; + if (ret) { + glusterfs_graph_destroy (graph); + ret = -1; + goto out; + } + +out: + if (fp) + fclose (fp); + + return ret; +} + + +int +main (int argc, char *argv[]) +{ + glusterfs_ctx_t *ctx = NULL; + int ret = -1; + + ret = glusterfs_globals_init (); + if (ret) + return ret; + + ctx = glusterfs_ctx_get (); + if (!ctx) + return ENOMEM; + + ret = glusterfs_ctx_defaults_init (ctx); + if (ret) + goto out; + + ret = parse_cmdline (argc, argv, &ctx->cmd_args); + if (ret) + goto out; + + ret = logging_init (ctx); + if (ret) + goto out; + + gf_proc_dump_init(); + + ret = create_fuse_mount (ctx); + if (ret) + goto out; + + ret = daemonize (ctx); + if (ret) + goto out; + + ret = glusterfs_volumes_init (ctx); + if (ret) + goto out; + + ret = event_dispatch (ctx->event_pool); + +out: +// glusterfs_ctx_destroy (ctx); + + return ret; } diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h index 929e27d70..629167117 100644 --- a/glusterfsd/src/glusterfsd.h +++ b/glusterfsd/src/glusterfsd.h @@ -25,8 +25,8 @@ #include "config.h" #endif -#define DEFAULT_CLIENT_VOLUME_FILE CONFDIR "/glusterfs.vol" -#define DEFAULT_SERVER_VOLUME_FILE CONFDIR "/glusterfsd.vol" +#define DEFAULT_CLIENT_VOLFILE CONFDIR "/glusterfs.vol" +#define DEFAULT_SERVER_VOLFILE CONFDIR "/glusterfsd.vol" #define DEFAULT_LOG_FILE_DIRECTORY DATADIR "/log/glusterfs" #define DEFAULT_LOG_LEVEL GF_LOG_NORMAL @@ -54,26 +54,26 @@ #define ZR_DUMP_FUSE "dump-fuse" enum argp_option_keys { - ARGP_VOLFILE_SERVER_KEY = 's', - ARGP_VOLUME_FILE_KEY = 'f', - ARGP_LOG_LEVEL_KEY = 'L', - ARGP_LOG_FILE_KEY = 'l', - ARGP_VOLFILE_SERVER_PORT_KEY = 131, - ARGP_VOLFILE_SERVER_TRANSPORT_KEY = 132, + ARGP_VOLFILE_SERVER_KEY = 's', + ARGP_VOLUME_FILE_KEY = 'f', + ARGP_LOG_LEVEL_KEY = 'L', + ARGP_LOG_FILE_KEY = 'l', + ARGP_VOLFILE_SERVER_PORT_KEY = 131, + ARGP_VOLFILE_SERVER_TRANSPORT_KEY = 132, ARGP_PID_FILE_KEY = 'p', - ARGP_NO_DAEMON_KEY = 'N', - ARGP_RUN_ID_KEY = 'r', - ARGP_DEBUG_KEY = 133, - ARGP_DISABLE_DIRECT_IO_MODE_KEY = 134, - ARGP_ENTRY_TIMEOUT_KEY = 135, - ARGP_ATTRIBUTE_TIMEOUT_KEY = 136, + ARGP_NO_DAEMON_KEY = 'N', + ARGP_RUN_ID_KEY = 'r', + ARGP_DEBUG_KEY = 133, + ARGP_DISABLE_DIRECT_IO_MODE_KEY = 134, + ARGP_ENTRY_TIMEOUT_KEY = 135, + ARGP_ATTRIBUTE_TIMEOUT_KEY = 136, ARGP_VOLUME_NAME_KEY = 137, ARGP_XLATOR_OPTION_KEY = 138, - ARGP_ENABLE_DIRECT_IO_MODE_KEY = 139, + ARGP_ENABLE_DIRECT_IO_MODE_KEY = 139, #ifdef GF_DARWIN_HOST_OS ARGP_NON_LOCAL_KEY = 140, #endif /* DARWIN */ - ARGP_VOLFILE_ID_KEY = 143, + ARGP_VOLFILE_ID_KEY = 143, ARGP_VOLFILE_CHECK_KEY = 144, ARGP_VOLFILE_MAX_FETCH_ATTEMPTS = 145, ARGP_LOG_SERVER_KEY = 146, diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index acca3f04a..795744883 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -1,21 +1,21 @@ libglusterfs_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) -libglusterfs_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" -D$(GF_HOST_OS) -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\" -I$(CONTRIBDIR)/rbtree -DSCHEDULERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/scheduler\" +libglusterfs_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" -D$(GF_HOST_OS) -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\" -I$(CONTRIBDIR)/rbtree -DSCHEDULERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/scheduler\" -I$(CONTRIBDIR)/md5 libglusterfs_la_LIBADD = @LEXLIB@ lib_LTLIBRARIES = libglusterfs.la -libglusterfs_la_SOURCES = dict.c spec.lex.c y.tab.c xlator.c logging.c hashfn.c defaults.c common-utils.c timer.c inode.c call-stub.c compat.c fd.c compat-errno.c event.c mem-pool.c gf-dirent.c syscall.c iobuf.c globals.c statedump.c stack.c checksum.c md5.c $(CONTRIBDIR)/rbtree/rb.c rbthash.c latency.c +libglusterfs_la_SOURCES = dict.c graph.lex.c y.tab.c xlator.c logging.c hashfn.c defaults.c common-utils.c timer.c inode.c call-stub.c compat.c fd.c compat-errno.c event.c mem-pool.c gf-dirent.c syscall.c iobuf.c globals.c statedump.c stack.c checksum.c $(CONTRIBDIR)/md5/md5.c $(CONTRIBDIR)/rbtree/rb.c rbthash.c latency.c graph.c -noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h logging.h xlator.h stack.h timer.h list.h inode.h call-stub.h compat.h fd.h revision.h compat-errno.h event.h mem-pool.h byte-order.h gf-dirent.h locking.h syscall.h iobuf.h globals.h statedump.h checksum.h md5.h $(CONTRIBDIR)/rbtree/rb.h rbthash.h iatt.h latency.h +noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h logging.h xlator.h stack.h timer.h list.h inode.h call-stub.h compat.h fd.h revision.h compat-errno.h event.h mem-pool.h byte-order.h gf-dirent.h locking.h syscall.h iobuf.h globals.h statedump.h checksum.h $(CONTRIBDIR)/md5/md5.h $(CONTRIBDIR)/rbtree/rb.h rbthash.h iatt.h latency.h -EXTRA_DIST = spec.l spec.y +EXTRA_DIST = graph.l graph.y -spec.lex.c: spec.l y.tab.h - $(LEX) -t $(srcdir)/spec.l > $@ +graph.lex.c: graph.l y.tab.h + $(LEX) -t $(srcdir)/graph.l > $@ -y.tab.c y.tab.h: spec.y - $(YACC) -d $(srcdir)/spec.y +y.tab.c y.tab.h: graph.y + $(YACC) -d $(srcdir)/graph.y -CLEANFILES = spec.lex.c y.tab.c y.tab.h +CLEANFILES = graph.lex.c y.tab.c y.tab.h diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index c93dcc41d..694a9040c 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -48,7 +48,6 @@ typedef int32_t (*rw_op_t)(int32_t fd, char *buf, int32_t size); typedef int32_t (*rwv_op_t)(int32_t fd, const struct iovec *buf, int32_t size); -static glusterfs_ctx_t *gf_global_ctx; struct dnscache6 { @@ -179,85 +178,6 @@ err: return -1; } -char *gf_fop_list[GF_FOP_MAXVALUE]; -char *gf_mgmt_list[GF_MGMT_MAXVALUE]; - -void -gf_global_variable_init() -{ - gf_fop_list[GF_FOP_NULL] = "NULL"; - gf_fop_list[GF_FOP_STAT] = "STAT"; - gf_fop_list[GF_FOP_READLINK] = "READLINK"; - gf_fop_list[GF_FOP_MKNOD] = "MKNOD"; - gf_fop_list[GF_FOP_MKDIR] = "MKDIR"; - gf_fop_list[GF_FOP_UNLINK] = "UNLINK"; - gf_fop_list[GF_FOP_RMDIR] = "RMDIR"; - gf_fop_list[GF_FOP_SYMLINK] = "SYMLINK"; - gf_fop_list[GF_FOP_RENAME] = "RENAME"; - gf_fop_list[GF_FOP_LINK] = "LINK"; - gf_fop_list[GF_FOP_TRUNCATE] = "TRUNCATE"; - gf_fop_list[GF_FOP_OPEN] = "OPEN"; - gf_fop_list[GF_FOP_READ] = "READ"; - gf_fop_list[GF_FOP_WRITE] = "WRITE"; - gf_fop_list[GF_FOP_STATFS] = "STATFS"; - gf_fop_list[GF_FOP_FLUSH] = "FLUSH"; - gf_fop_list[GF_FOP_FSYNC] = "FSYNC"; - gf_fop_list[GF_FOP_SETXATTR] = "SETXATTR"; - gf_fop_list[GF_FOP_GETXATTR] = "GETXATTR"; - gf_fop_list[GF_FOP_REMOVEXATTR] = "REMOVEXATTR"; - gf_fop_list[GF_FOP_OPENDIR] = "OPENDIR"; - gf_fop_list[GF_FOP_FSYNCDIR] = "FSYNCDIR"; - gf_fop_list[GF_FOP_ACCESS] = "ACCESS"; - gf_fop_list[GF_FOP_CREATE] = "CREATE"; - gf_fop_list[GF_FOP_FTRUNCATE] = "FTRUNCATE"; - gf_fop_list[GF_FOP_FSTAT] = "FSTAT"; - gf_fop_list[GF_FOP_LK] = "LK"; - gf_fop_list[GF_FOP_LOOKUP] = "LOOKUP"; - gf_fop_list[GF_FOP_READDIR] = "READDIR"; - gf_fop_list[GF_FOP_INODELK] = "INODELK"; - gf_fop_list[GF_FOP_FINODELK] = "FINODELK"; - gf_fop_list[GF_FOP_ENTRYLK] = "ENTRYLK"; - gf_fop_list[GF_FOP_FENTRYLK] = "FENTRYLK"; - gf_fop_list[GF_FOP_CHECKSUM] = "CHECKSUM"; - gf_fop_list[GF_FOP_XATTROP] = "XATTROP"; - gf_fop_list[GF_FOP_FXATTROP] = "FXATTROP"; - gf_fop_list[GF_FOP_FSETXATTR] = "FSETXATTR"; - gf_fop_list[GF_FOP_FGETXATTR] = "FGETXATTR"; - gf_fop_list[GF_FOP_RCHECKSUM] = "RCHECKSUM"; - gf_fop_list[GF_FOP_SETATTR] = "SETATTR"; - gf_fop_list[GF_FOP_FSETATTR] = "FSETATTR"; - gf_fop_list[GF_FOP_READDIRP] = "READDIRP"; - gf_fop_list[GF_FOP_GETSPEC] = "GETSPEC"; - gf_fop_list[GF_FOP_FORGET] = "FORGET"; - gf_fop_list[GF_FOP_RELEASE] = "RELEASE"; - gf_fop_list[GF_FOP_RELEASEDIR] = "RELEASEDIR"; - - gf_fop_list[GF_MGMT_NULL] = "NULL"; - - /* Are there any more variables to be included? All global - variables initialization should go here */ - - return; -} - -void -set_global_ctx_ptr (glusterfs_ctx_t *ctx) -{ - gf_global_ctx = ctx; -} - -/* - * Don't use this function other than in glusterfsd.c. libglusterfsclient does - * not set gf_global_ctx since there can be multiple glusterfs-contexts - * initialized in a single process. Instead access the context from ctx member - * of the xlator object. - */ - -glusterfs_ctx_t * -get_global_ctx_ptr (void) -{ - return gf_global_ctx; -} void gf_log_volume_file (FILE *specfp) @@ -397,8 +317,7 @@ gf_print_trace (int32_t signum) /* Pending frames, (if any), list them in order */ ret = write (fd, "pending frames:\n", 16); { - extern glusterfs_ctx_t *gf_global_ctx; - glusterfs_ctx_t *ctx = gf_global_ctx; + glusterfs_ctx_t *ctx = glusterfs_ctx_get (); struct list_head *trav = ((call_pool_t *)ctx->pool)->all_frames.next; while (trav != (&((call_pool_t *)ctx->pool)->all_frames)) { call_frame_t *tmp = (call_frame_t *)(&((call_stack_t *)trav)->frames); diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 06933d7c4..80111a26d 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -82,8 +82,6 @@ enum _gf_boolean typedef enum _gf_boolean gf_boolean_t; void gf_global_variable_init(void); -void set_global_ctx_ptr (glusterfs_ctx_t *ctx); -glusterfs_ctx_t *get_global_ctx_ptr (void); in_addr_t gf_resolve_ip (const char *hostname, void **dnscache); diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c index b01caf765..d26854ebd 100644 --- a/libglusterfs/src/fd.c +++ b/libglusterfs/src/fd.c @@ -30,17 +30,18 @@ #endif -static uint32_t +static int gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr); + static fd_t * _fd_ref (fd_t *fd); -/* - Allocate in memory chunks of power of 2 starting from 1024B +/* + Allocate in memory chunks of power of 2 starting from 1024B Assumes fdtable->lock is held */ -static inline uint32_t +static inline int gf_roundup_power_of_two (uint32_t nr) { uint32_t result = 1; @@ -58,6 +59,7 @@ gf_roundup_power_of_two (uint32_t nr) return result; } + static int gf_fd_chain_fd_entries (fdentry_t *entries, uint32_t startidx, uint32_t endcount) @@ -80,18 +82,17 @@ gf_fd_chain_fd_entries (fdentry_t *entries, uint32_t startidx, } -static uint32_t +static int gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr) { - fdentry_t *oldfds = NULL; - uint32_t oldmax_fds = -1; - - if (fdtable == NULL || nr < 0) - { + fdentry_t *oldfds = NULL; + uint32_t oldmax_fds = -1; + + if (fdtable == NULL || nr < 0) { gf_log ("fd", GF_LOG_ERROR, "invalid argument"); return EINVAL; } - + nr /= (1024 / sizeof (fdentry_t)); nr = gf_roundup_power_of_two (nr + 1); nr *= (1024 / sizeof (fdentry_t)); @@ -102,7 +103,7 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr) fdtable->fdentries = GF_CALLOC (nr, sizeof (fdentry_t), gf_common_mt_fdentry_t); ERR_ABORT (fdtable->fdentries); - fdtable->max_fds = nr; + fdtable->max_fds = nr; if (oldfds) { uint32_t cpy = oldmax_fds * sizeof (fdentry_t); @@ -121,8 +122,9 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr) return 0; } + fdtable_t * -gf_fd_fdtable_alloc (void) +gf_fd_fdtable_alloc (void) { fdtable_t *fdtable = NULL; @@ -141,6 +143,7 @@ gf_fd_fdtable_alloc (void) return fdtable; } + fdentry_t * __gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count) { @@ -160,10 +163,12 @@ out: return fdentries; } + fdentry_t * gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count) { fdentry_t *entries = NULL; + if (fdtable) { pthread_mutex_lock (&fdtable->lock); { @@ -175,14 +180,15 @@ gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count) return entries; } -void + +void gf_fd_fdtable_destroy (fdtable_t *fdtable) { struct list_head list = {0, }; fd_t *fd = NULL; fdentry_t *fdentries = NULL; uint32_t fd_count = 0; - int32_t i = 0; + int32_t i = 0; INIT_LIST_HEAD (&list); @@ -210,20 +216,21 @@ gf_fd_fdtable_destroy (fdtable_t *fdtable) } } -int32_t + +int gf_fd_unused_get (fdtable_t *fdtable, fd_t *fdptr) { int32_t fd = -1; fdentry_t *fde = NULL; int error; int alloc_attempts = 0; - + if (fdtable == NULL || fdptr == NULL) { gf_log ("fd", GF_LOG_ERROR, "invalid argument"); return EINVAL; } - + pthread_mutex_lock (&fdtable->lock); { fd_alloc_try_again: @@ -268,20 +275,18 @@ out: } -inline void +inline void gf_fd_put (fdtable_t *fdtable, int32_t fd) { fd_t *fdptr = NULL; fdentry_t *fde = NULL; - if (fdtable == NULL || fd < 0) - { + if (fdtable == NULL || fd < 0) { gf_log ("fd", GF_LOG_ERROR, "invalid argument"); return; } - - if (!(fd < fdtable->max_fds)) - { + + if (!(fd < fdtable->max_fds)) { gf_log ("fd", GF_LOG_ERROR, "invalid argument"); return; } @@ -316,16 +321,14 @@ fd_t * gf_fd_fdptr_get (fdtable_t *fdtable, int64_t fd) { fd_t *fdptr = NULL; - - if (fdtable == NULL || fd < 0) - { + + if (fdtable == NULL || fd < 0) { gf_log ("fd", GF_LOG_ERROR, "invalid argument"); errno = EINVAL; return NULL; } - - if (!(fd < fdtable->max_fds)) - { + + if (!(fd < fdtable->max_fds)) { gf_log ("fd", GF_LOG_ERROR, "invalid argument"); errno = EINVAL; return NULL; @@ -343,14 +346,16 @@ gf_fd_fdptr_get (fdtable_t *fdtable, int64_t fd) return fdptr; } + fd_t * _fd_ref (fd_t *fd) { ++fd->refcount; - + return fd; } + fd_t * fd_ref (fd_t *fd) { @@ -364,10 +369,11 @@ fd_ref (fd_t *fd) LOCK (&fd->inode->lock); refed_fd = _fd_ref (fd); UNLOCK (&fd->inode->lock); - + return refed_fd; } + fd_t * _fd_unref (fd_t *fd) { @@ -375,25 +381,26 @@ _fd_unref (fd_t *fd) --fd->refcount; - if (fd->refcount == 0){ + if (fd->refcount == 0) { list_del_init (&fd->inode_list); } - + return fd; } + static void fd_destroy (fd_t *fd) { xlator_t *xl = NULL; - int i = 0; + int i = 0; xlator_t *old_THIS = NULL; if (fd == NULL){ gf_log ("xlator", GF_LOG_ERROR, "invalid arugument"); goto out; } - + if (fd->inode == NULL){ gf_log ("xlator", GF_LOG_ERROR, "fd->inode is NULL"); goto out; @@ -402,7 +409,7 @@ fd_destroy (fd_t *fd) goto out; if (IA_ISDIR (fd->inode->ia_type)) { - for (i = 0; i < fd->inode->table->xl->ctx->xl_count; i++) { + for (i = 0; i < fd->inode->table->xl->graph->xl_count; i++) { if (fd->_ctx[i].key) { xl = (xlator_t *)(long)fd->_ctx[i].key; old_THIS = THIS; @@ -413,7 +420,7 @@ fd_destroy (fd_t *fd) } } } else { - for (i = 0; i < fd->inode->table->xl->ctx->xl_count; i++) { + for (i = 0; i < fd->inode->table->xl->graph->xl_count; i++) { if (fd->_ctx[i].key) { xl = (xlator_t *)(long)fd->_ctx[i].key; old_THIS = THIS; @@ -424,18 +431,18 @@ fd_destroy (fd_t *fd) } } } - + LOCK_DESTROY (&fd->lock); GF_FREE (fd->_ctx); inode_unref (fd->inode); fd->inode = (inode_t *)0xaaaaaaaa; GF_FREE (fd); - out: return; } + void fd_unref (fd_t *fd) { @@ -445,14 +452,14 @@ fd_unref (fd_t *fd) gf_log ("fd.c", GF_LOG_ERROR, "fd is NULL"); return; } - + LOCK (&fd->inode->lock); { _fd_unref (fd); refcount = fd->refcount; } UNLOCK (&fd->inode->lock); - + if (refcount == 0) { fd_destroy (fd); } @@ -460,6 +467,7 @@ fd_unref (fd_t *fd) return ; } + fd_t * fd_bind (fd_t *fd) { @@ -476,7 +484,7 @@ fd_bind (fd_t *fd) list_add (&fd->inode_list, &inode->fd_list); } UNLOCK (&inode->lock); - + return fd; } @@ -484,22 +492,23 @@ fd_t * fd_create (inode_t *inode, pid_t pid) { fd_t *fd = NULL; - + if (inode == NULL) { gf_log ("fd", GF_LOG_ERROR, "invalid argument"); return NULL; } - + fd = GF_CALLOC (1, sizeof (fd_t), gf_common_mt_fd_t); ERR_ABORT (fd); - + fd->_ctx = GF_CALLOC (1, (sizeof (struct _fd_ctx) * - inode->table->xl->ctx->xl_count), + inode->table->xl->graph->xl_count), gf_common_mt_fd_ctx); + fd->inode = inode_ref (inode); fd->pid = pid; INIT_LIST_HEAD (&fd->inode_list); - + LOCK_INIT (&fd->lock); LOCK (&inode->lock); @@ -509,6 +518,7 @@ fd_create (inode_t *inode, pid_t pid) return fd; } + fd_t * fd_lookup (inode_t *inode, pid_t pid) { @@ -537,24 +547,26 @@ fd_lookup (inode_t *inode, pid_t pid) } } UNLOCK (&inode->lock); - + return fd; } + uint8_t fd_list_empty (inode_t *inode) { - uint8_t empty = 0; + uint8_t empty = 0; LOCK (&inode->lock); { empty = list_empty (&inode->fd_list); } UNLOCK (&inode->lock); - + return empty; } + int __fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) { @@ -564,8 +576,8 @@ __fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) if (!fd || !xlator) return -1; - - for (index = 0; index < xlator->ctx->xl_count; index++) { + + for (index = 0; index < xlator->graph->xl_count; index++) { if (!fd->_ctx[index].key) { if (set_idx == -1) set_idx = index; @@ -577,12 +589,12 @@ __fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) break; } } - + if (set_idx == -1) { ret = -1; goto out; } - + fd->_ctx[set_idx].key = (uint64_t)(long) xlator; fd->_ctx[set_idx].value = value; @@ -598,7 +610,7 @@ fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) if (!fd || !xlator) return -1; - + LOCK (&fd->lock); { ret = __fd_ctx_set (fd, xlator, value); @@ -609,7 +621,7 @@ fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) } -int +int __fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) { int index = 0; @@ -617,26 +629,26 @@ __fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) if (!fd || !xlator) return -1; - - for (index = 0; index < xlator->ctx->xl_count; index++) { + + for (index = 0; index < xlator->graph->xl_count; index++) { if (fd->_ctx[index].key == (uint64_t)(long)xlator) break; } - - if (index == xlator->ctx->xl_count) { + + if (index == xlator->graph->xl_count) { ret = -1; goto out; } - if (value) + if (value) *value = fd->_ctx[index].value; - + out: return ret; } -int +int fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) { int ret = 0; @@ -654,7 +666,7 @@ fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) } -int +int __fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value) { int index = 0; @@ -662,20 +674,20 @@ __fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value) if (!fd || !xlator) return -1; - - for (index = 0; index < xlator->ctx->xl_count; index++) { + + for (index = 0; index < xlator->graph->xl_count; index++) { if (fd->_ctx[index].key == (uint64_t)(long)xlator) break; } - - if (index == xlator->ctx->xl_count) { + + if (index == xlator->graph->xl_count) { ret = -1; goto out; } - - if (value) - *value = fd->_ctx[index].value; - + + if (value) + *value = fd->_ctx[index].value; + fd->_ctx[index].key = 0; fd->_ctx[index].value = 0; @@ -684,14 +696,14 @@ out: } -int +int fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value) { int ret = 0; if (!fd || !xlator) return -1; - + LOCK (&fd->lock); { ret = __fd_ctx_del (fd, xlator, value); @@ -709,7 +721,7 @@ fd_dump (fd_t *fd, char *prefix) if (!fd) return; - + memset(key, 0, sizeof(key)); gf_proc_dump_build_key(key, prefix, "pid"); gf_proc_dump_write(key, "%d", fd->pid); @@ -733,10 +745,11 @@ fdentry_dump (fdentry_t *fdentry, char *prefix) if (GF_FDENTRY_ALLOCATED != fdentry->next_free) return; - if (fdentry->fd) + if (fdentry->fd) fd_dump(fdentry->fd, prefix); } + void fdtable_dump (fdtable_t *fdtable, char *prefix) { @@ -746,7 +759,7 @@ fdtable_dump (fdtable_t *fdtable, char *prefix) if (!fdtable) return; - + ret = pthread_mutex_trylock (&fdtable->lock); if (ret) { @@ -763,7 +776,7 @@ fdtable_dump (fdtable_t *fdtable, char *prefix) gf_proc_dump_write(key, "%d", fdtable->first_free); for ( i = 0 ; i < fdtable->max_fds; i++) { - if (GF_FDENTRY_ALLOCATED == + if (GF_FDENTRY_ALLOCATED == fdtable->fdentries[i].next_free) { gf_proc_dump_build_key(key, prefix, "fdentry[%d]", i); gf_proc_dump_add_section(key); @@ -773,4 +786,3 @@ fdtable_dump (fdtable_t *fdtable, char *prefix) pthread_mutex_unlock(&fdtable->lock); } - diff --git a/libglusterfs/src/fd.h b/libglusterfs/src/fd.h index 9c5ebd8d7..c2181d8af 100644 --- a/libglusterfs/src/fd.h +++ b/libglusterfs/src/fd.h @@ -33,9 +33,10 @@ struct _inode; struct _dict; + struct _fd_ctx { - uint64_t key; - uint64_t value; + uint64_t key; + uint64_t value; }; /* If this structure changes, please have mercy on the booster maintainer @@ -55,12 +56,14 @@ struct _fd { }; typedef struct _fd fd_t; + struct fd_table_entry { fd_t *fd; int next_free; }; typedef struct fd_table_entry fdentry_t; + struct _fdtable { int refcount; uint32_t max_fds; @@ -70,6 +73,7 @@ struct _fdtable { }; typedef struct _fdtable fdtable_t; + /* Signifies no more entries in the fd table. */ #define GF_FDTABLE_END -1 @@ -81,58 +85,77 @@ typedef struct _fdtable fdtable_t; #include "logging.h" #include "xlator.h" -inline void + +inline void gf_fd_put (fdtable_t *fdtable, int32_t fd); + fd_t * gf_fd_fdptr_get (fdtable_t *fdtable, int64_t fd); + fdtable_t * gf_fd_fdtable_alloc (void); -int32_t + +int gf_fd_unused_get (fdtable_t *fdtable, fd_t *fdptr); + fdentry_t * gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count); -void + +void gf_fd_fdtable_destroy (fdtable_t *fdtable); + fd_t * fd_ref (fd_t *fd); + void fd_unref (fd_t *fd); + fd_t * fd_create (struct _inode *inode, pid_t pid); + fd_t * fd_lookup (struct _inode *inode, pid_t pid); + uint8_t fd_list_empty (struct _inode *inode); + fd_t * fd_bind (fd_t *fd); + int fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value); -int + +int fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value); -int + +int fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value); + int __fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value); -int + +int __fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value); -int + +int __fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value); + #endif /* _FD_H */ diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c index 9677a169e..d480f089f 100644 --- a/libglusterfs/src/globals.c +++ b/libglusterfs/src/globals.c @@ -24,12 +24,73 @@ #include -#include "globals.h" #include "glusterfs.h" +#include "globals.h" #include "xlator.h" #include "mem-pool.h" +/* gf_*_list[] */ + +char *gf_fop_list[GF_FOP_MAXVALUE]; +char *gf_mgmt_list[GF_MGMT_MAXVALUE]; + + +void +gf_op_list_init() +{ + gf_fop_list[GF_FOP_NULL] = "NULL"; + gf_fop_list[GF_FOP_STAT] = "STAT"; + gf_fop_list[GF_FOP_READLINK] = "READLINK"; + gf_fop_list[GF_FOP_MKNOD] = "MKNOD"; + gf_fop_list[GF_FOP_MKDIR] = "MKDIR"; + gf_fop_list[GF_FOP_UNLINK] = "UNLINK"; + gf_fop_list[GF_FOP_RMDIR] = "RMDIR"; + gf_fop_list[GF_FOP_SYMLINK] = "SYMLINK"; + gf_fop_list[GF_FOP_RENAME] = "RENAME"; + gf_fop_list[GF_FOP_LINK] = "LINK"; + gf_fop_list[GF_FOP_TRUNCATE] = "TRUNCATE"; + gf_fop_list[GF_FOP_OPEN] = "OPEN"; + gf_fop_list[GF_FOP_READ] = "READ"; + gf_fop_list[GF_FOP_WRITE] = "WRITE"; + gf_fop_list[GF_FOP_STATFS] = "STATFS"; + gf_fop_list[GF_FOP_FLUSH] = "FLUSH"; + gf_fop_list[GF_FOP_FSYNC] = "FSYNC"; + gf_fop_list[GF_FOP_SETXATTR] = "SETXATTR"; + gf_fop_list[GF_FOP_GETXATTR] = "GETXATTR"; + gf_fop_list[GF_FOP_REMOVEXATTR] = "REMOVEXATTR"; + gf_fop_list[GF_FOP_OPENDIR] = "OPENDIR"; + gf_fop_list[GF_FOP_FSYNCDIR] = "FSYNCDIR"; + gf_fop_list[GF_FOP_ACCESS] = "ACCESS"; + gf_fop_list[GF_FOP_CREATE] = "CREATE"; + gf_fop_list[GF_FOP_FTRUNCATE] = "FTRUNCATE"; + gf_fop_list[GF_FOP_FSTAT] = "FSTAT"; + gf_fop_list[GF_FOP_LK] = "LK"; + gf_fop_list[GF_FOP_LOOKUP] = "LOOKUP"; + gf_fop_list[GF_FOP_READDIR] = "READDIR"; + gf_fop_list[GF_FOP_INODELK] = "INODELK"; + gf_fop_list[GF_FOP_FINODELK] = "FINODELK"; + gf_fop_list[GF_FOP_ENTRYLK] = "ENTRYLK"; + gf_fop_list[GF_FOP_FENTRYLK] = "FENTRYLK"; + gf_fop_list[GF_FOP_CHECKSUM] = "CHECKSUM"; + gf_fop_list[GF_FOP_XATTROP] = "XATTROP"; + gf_fop_list[GF_FOP_FXATTROP] = "FXATTROP"; + gf_fop_list[GF_FOP_FSETXATTR] = "FSETXATTR"; + gf_fop_list[GF_FOP_FGETXATTR] = "FGETXATTR"; + gf_fop_list[GF_FOP_RCHECKSUM] = "RCHECKSUM"; + gf_fop_list[GF_FOP_SETATTR] = "SETATTR"; + gf_fop_list[GF_FOP_FSETATTR] = "FSETATTR"; + gf_fop_list[GF_FOP_READDIRP] = "READDIRP"; + gf_fop_list[GF_FOP_GETSPEC] = "GETSPEC"; + gf_fop_list[GF_FOP_FORGET] = "FORGET"; + gf_fop_list[GF_FOP_RELEASE] = "RELEASE"; + gf_fop_list[GF_FOP_RELEASEDIR] = "RELEASEDIR"; + + gf_fop_list[GF_MGMT_NULL] = "NULL"; + return; +} + + /* CTX */ static glusterfs_ctx_t *glusterfs_ctx; @@ -48,6 +109,7 @@ glusterfs_ctx_init () goto out; } + INIT_LIST_HEAD (&glusterfs_ctx->graphs); ret = pthread_mutex_init (&glusterfs_ctx->lock, NULL); out: @@ -168,7 +230,7 @@ glusterfs_central_log_flag_init () { int ret = 0; - ret = pthread_key_create (¢ral_log_flag_key, + ret = pthread_key_create (¢ral_log_flag_key, glusterfs_central_log_flag_destroy); if (ret != 0) { @@ -194,7 +256,7 @@ glusterfs_central_log_flag_get () long flag = 0; flag = (long) pthread_getspecific (central_log_flag_key); - + return flag; } @@ -211,6 +273,8 @@ glusterfs_globals_init () { int ret = 0; + gf_op_list_init (); + ret = glusterfs_ctx_init (); if (ret) goto out; diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h index 58f37d185..e09c69511 100644 --- a/libglusterfs/src/globals.h +++ b/libglusterfs/src/globals.h @@ -27,13 +27,14 @@ #define GF_REQUEST_MAXGROUPS 16 #include "glusterfs.h" -#include "xlator.h" /* CTX */ #define CTX (glusterfs_ctx_get()) glusterfs_ctx_t *glusterfs_ctx_get (); +#include "xlator.h" + /* THIS */ #define THIS (*__glusterfs_this_location()) diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index f4134d9ea..b6db51489 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -45,6 +45,7 @@ #include "list.h" #include "logging.h" + #define GF_YES 1 #define GF_NO 0 @@ -95,7 +96,7 @@ typedef enum { GF_FOP_WRITE, GF_FOP_STATFS, GF_FOP_FLUSH, - GF_FOP_FSYNC, + GF_FOP_FSYNC, /* 15 */ GF_FOP_SETXATTR, GF_FOP_GETXATTR, GF_FOP_REMOVEXATTR, @@ -104,7 +105,7 @@ typedef enum { GF_FOP_ACCESS, GF_FOP_CREATE, GF_FOP_FTRUNCATE, - GF_FOP_FSTAT, + GF_FOP_FSTAT, /* 25 */ GF_FOP_LK, GF_FOP_LOOKUP, GF_FOP_READDIR, @@ -141,6 +142,7 @@ typedef enum { GF_OP_TYPE_MAX, } gf_op_type_t; + /* NOTE: all the miscellaneous flags used by GlusterFS should be listed here */ typedef enum { GF_LK_GETLK = 0, @@ -148,32 +150,38 @@ typedef enum { GF_LK_SETLKW, } glusterfs_lk_cmds_t; + typedef enum { GF_LK_F_RDLCK = 0, GF_LK_F_WRLCK, GF_LK_F_UNLCK } glusterfs_lk_types_t; + typedef enum { - GF_LOCK_POSIX, + GF_LOCK_POSIX, GF_LOCK_INTERNAL } gf_lk_domain_t; + typedef enum { ENTRYLK_LOCK, ENTRYLK_UNLOCK, ENTRYLK_LOCK_NB } entrylk_cmd; + typedef enum { ENTRYLK_RDLCK, ENTRYLK_WRLCK } entrylk_type; + typedef enum { GF_XATTROP_ADD_ARRAY, } gf_xattrop_flags_t; + #define GF_SET_IF_NOT_PRESENT 0x1 /* default behaviour */ #define GF_SET_OVERWRITE 0x2 /* Overwrite with the buf given */ #define GF_SET_DIR_ONLY 0x4 @@ -186,17 +194,18 @@ typedef enum { #define GF_REPLICATE_TRASH_DIR ".landfill" struct _xlator_cmdline_option { - struct list_head cmd_args; - char *volume; - char *key; - char *value; + struct list_head cmd_args; + char *volume; + char *key; + char *value; }; typedef struct _xlator_cmdline_option xlator_cmdline_option_t; + struct _cmd_args { /* basic options */ char *volfile_server; - char *volume_file; + char *volfile; char *log_server; gf_loglevel_t log_level; char *log_file; @@ -229,41 +238,61 @@ struct _cmd_args { }; typedef struct _cmd_args cmd_args_t; -struct _glusterfs_ctx { - cmd_args_t cmd_args; - char *process_uuid; - FILE *specfp; - FILE *pidfp; - char fin; - void *timer; - void *ib; - void *pool; - void *graph; - void *top; /* either fuse or server protocol */ - void *event_pool; - void *iobuf_pool; - pthread_mutex_t lock; - int xl_count; - uint32_t volfile_checksum; - size_t page_size; - unsigned char measure_latency; /* toggle switch for latency measurement */ + +struct _glusterfs_graph { + struct list_head list; + char graph_uuid[128]; + struct timeval dob; + void *first; + void *top; /* selected by -n */ + int xl_count; + uint32_t volfile_checksum; }; +typedef struct _glusterfs_graph glusterfs_graph_t; + +struct _glusterfs_ctx { + cmd_args_t cmd_args; + char *process_uuid; + FILE *pidfp; + char fin; + void *timer; + void *ib; + void *pool; + void *event_pool; + void *iobuf_pool; + pthread_mutex_t lock; + size_t page_size; + struct list_head graphs; /* double linked list of graphs - one per volfile parse */ + glusterfs_graph_t *active; /* the latest graph in use */ + void *master; /* fuse, or libglusterfsclient (however, not protocol/server) */ + void *mgmt; /* xlator implementing MOPs for centralized logging, volfile server */ + unsigned char measure_latency; /* toggle switch for latency measurement */ + pthread_t sigwaiter; +}; typedef struct _glusterfs_ctx glusterfs_ctx_t; + typedef enum { - GF_EVENT_PARENT_UP = 1, - GF_EVENT_POLLIN, - GF_EVENT_POLLOUT, - GF_EVENT_POLLERR, - GF_EVENT_CHILD_UP, - GF_EVENT_CHILD_DOWN, - GF_EVENT_CHILD_CONNECTING, - GF_EVENT_TRANSPORT_CLEANUP, - GF_EVENT_TRANSPORT_CONNECTED, - GF_EVENT_VOLFILE_MODIFIED, + GF_EVENT_PARENT_UP = 1, + GF_EVENT_POLLIN, + GF_EVENT_POLLOUT, + GF_EVENT_POLLERR, + GF_EVENT_CHILD_UP, + GF_EVENT_CHILD_DOWN, + GF_EVENT_CHILD_CONNECTING, + GF_EVENT_TRANSPORT_CLEANUP, + GF_EVENT_TRANSPORT_CONNECTED, + GF_EVENT_VOLFILE_MODIFIED, + GF_EVENT_GRAPH_NEW, } glusterfs_event_t; + #define GF_MUST_CHECK __attribute__((warn_unused_result)) +int glusterfs_graph_prepare (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx); +int glusterfs_graph_destroy (glusterfs_graph_t *graph); +int glusterfs_graph_activate (glusterfs_ctx_t *ctx, glusterfs_graph_t *graph); +glusterfs_graph_t *glusterfs_graph_construct (FILE *fp); +glusterfs_graph_t *glusterfs_graph_new (); #endif /* _GLUSTERFS_H */ diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c new file mode 100644 index 000000000..a59b427bf --- /dev/null +++ b/libglusterfs/src/graph.c @@ -0,0 +1,499 @@ +/* + Copyright (c) 2010 Gluster, Inc. + This file is part of GlusterFS. + + GlusterFS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + GlusterFS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "xlator.h" +#include +#include +#include +#include "defaults.h" + + + + +#if 0 +static void +_gf_dump_details (int argc, char **argv) +{ + extern FILE *gf_log_logfile; + int i = 0; + char timestr[256]; + time_t utime = 0; + struct tm *tm = NULL; + pid_t mypid = 0; + struct utsname uname_buf = {{0, }, }; + int uname_ret = -1; + + utime = time (NULL); + tm = localtime (&utime); + mypid = getpid (); + uname_ret = uname (&uname_buf); + + /* Which git? What time? */ + strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); + fprintf (gf_log_logfile, + "========================================" + "========================================\n"); + fprintf (gf_log_logfile, "Version : %s %s built on %s %s\n", + PACKAGE_NAME, PACKAGE_VERSION, __DATE__, __TIME__); + fprintf (gf_log_logfile, "git: %s\n", + GLUSTERFS_REPOSITORY_REVISION); + fprintf (gf_log_logfile, "Starting Time: %s\n", timestr); + fprintf (gf_log_logfile, "Command line : "); + for (i = 0; i < argc; i++) { + fprintf (gf_log_logfile, "%s ", argv[i]); + } + + fprintf (gf_log_logfile, "\nPID : %d\n", mypid); + + if (uname_ret == 0) { + fprintf (gf_log_logfile, "System name : %s\n", + uname_buf.sysname); + fprintf (gf_log_logfile, "Nodename : %s\n", +