Exemple #1
0
static void
reincarnate (int signum)
{
    int                 ret = 0;
    glusterfs_ctx_t    *ctx = NULL;
    cmd_args_t         *cmd_args = NULL;

    ctx = glusterfs_ctx_get ();
    cmd_args = &ctx->cmd_args;


    if (cmd_args->volfile_server) {
        gf_log ("glusterfsd", GF_LOG_NORMAL,
                "Fetching the volume file from server...");
        ret = glusterfs_volfile_fetch (ctx);
    } else {
        gf_log ("glusterfsd", GF_LOG_NORMAL,
                "Reloading volfile ...");
        ret = glusterfs_volumes_init (ctx);
    }

    if (ret < 0)
        gf_log ("glusterfsd", GF_LOG_ERROR,
                "volume initialization failed.");

    /* Also, SIGHUP should do logroate */
    gf_log_logrotate (1);

    return;
}
Exemple #2
0
void
cleanup_and_exit (int signum)
{
    glusterfs_ctx_t *ctx      = NULL;
    xlator_t        *trav     = NULL;

    ctx = glusterfs_ctx_get ();

    /* TODO: is this the right place? */
    if (!ctx)
        return;
    if (ctx->cleanup_started)
        return;

    ctx->cleanup_started = 1;
    glusterfs_mgmt_pmap_signout (ctx);

    /* Call fini() of FUSE xlator first:
     * so there are no more requests coming and
     * 'umount' of mount point is done properly */
    trav = ctx->master;
    if (trav && trav->fini) {
        THIS = trav;
        trav->fini (trav);
    }

    gf_log ("glusterfsd", GF_LOG_NORMAL, "shutting down");

    glusterfs_pidfile_cleanup (ctx);

    exit (0);
#if 0
    /* TODO: Properly do cleanup_and_exit(), with synchronisations */
    if (ctx->mgmt)
        rpc_clnt_unref (ctx->mgmt);

    /* call fini() of each xlator */
    trav = NULL;
    if (ctx->active)
        trav = ctx->active->top;
    while (trav) {
        if (trav->fini) {
            THIS = trav;
            trav->fini (trav);
        }
        trav = trav->next;
    }
#endif
}
Exemple #3
0
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);
    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;
}
Exemple #4
0
struct mem_pool *
mem_pool_new_fn (unsigned long sizeof_type,
                 unsigned long count, char *name)
{
        struct mem_pool  *mem_pool = NULL;
        unsigned long     padded_sizeof_type = 0;
        void             *pool = NULL;
        int               i = 0;
        int               ret = 0;
        struct list_head *list = NULL;
        glusterfs_ctx_t  *ctx = NULL;

        if (!sizeof_type || !count) {
                gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
                return NULL;
        }
        padded_sizeof_type = sizeof_type + GF_MEM_POOL_PAD_BOUNDARY;

        mem_pool = GF_CALLOC (sizeof (*mem_pool), 1, gf_common_mt_mem_pool);
        if (!mem_pool)
                return NULL;

        ret = gf_asprintf (&mem_pool->name, "%s:%s", THIS->name, name);
        if (ret < 0)
                return NULL;

        if (!mem_pool->name) {
                GF_FREE (mem_pool);
                return NULL;
        }

        LOCK_INIT (&mem_pool->lock);
        INIT_LIST_HEAD (&mem_pool->list);
        INIT_LIST_HEAD (&mem_pool->global_list);

        mem_pool->padded_sizeof_type = padded_sizeof_type;
        mem_pool->cold_count = count;
        mem_pool->real_sizeof_type = sizeof_type;

        pool = GF_CALLOC (count, padded_sizeof_type, gf_common_mt_long);
        if (!pool) {
                GF_FREE (mem_pool->name);
                GF_FREE (mem_pool);
                return NULL;
        }

        for (i = 0; i < count; i++) {
                list = pool + (i * (padded_sizeof_type));
                INIT_LIST_HEAD (list);
                list_add_tail (list, &mem_pool->list);
        }

        mem_pool->pool = pool;
        mem_pool->pool_end = pool + (count * (padded_sizeof_type));

        /* add this pool to the global list */
        ctx = glusterfs_ctx_get ();
        if (!ctx)
                goto out;

        list_add (&mem_pool->global_list, &ctx->mempool_list);

out:
        return mem_pool;
}
/* TODO: It looks like backtrace_symbols allocates memory,
   it may be problem because mostly memory allocation/free causes 'sigsegv' */
void
gf_print_trace (int32_t signum)
{
        extern FILE *gf_log_logfile;
        struct tm   *tm = NULL;
        char         msg[1024] = {0,};
        char         timestr[256] = {0,};
        time_t       utime = 0;
        int          ret = 0;
        int          fd = 0;

        fd = fileno (gf_log_logfile);

        /* Pending frames, (if any), list them in order */
        ret = write (fd, "pending frames:\n", 16);
        if (ret < 0)
                goto out;

        {
                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);
                        if (tmp->root->type == GF_OP_TYPE_FOP)
                                sprintf (msg,"frame : type(%d) op(%s)\n",
                                         tmp->root->type,
                                         gf_fop_list[tmp->root->op]);
                        if (tmp->root->type == GF_OP_TYPE_MGMT)
                                sprintf (msg,"frame : type(%d) op(%s)\n",
                                         tmp->root->type,
                                         gf_mgmt_list[tmp->root->op]);

                        ret = write (fd, msg, strlen (msg));
                        if (ret < 0)
                                goto out;

                        trav = trav->next;
                }
                ret = write (fd, "\n", 1);
                if (ret < 0)
                        goto out;
        }

        sprintf (msg, "patchset: %s\n", GLUSTERFS_REPOSITORY_REVISION);
        ret = write (fd, msg, strlen (msg));
        if (ret < 0)
                goto out;

        sprintf (msg, "signal received: %d\n", signum);
        ret = write (fd, msg, strlen (msg));
        if (ret < 0)
                goto out;

        {
                /* Dump the timestamp of the crash too, so the previous logs
                   can be related */
                utime = time (NULL);
                tm    = localtime (&utime);
                strftime (timestr, 256, "%Y-%m-%d %H:%M:%S\n", tm);
                ret = write (fd, "time of crash: ", 15);
                if (ret < 0)
                        goto out;
                ret = write (fd, timestr, strlen (timestr));
                if (ret < 0)
                        goto out;
        }

        gf_dump_config_flags (fd);
#if HAVE_BACKTRACE
        /* Print 'backtrace' */
        {
                void *array[200];
                size_t size;

                size = backtrace (array, 200);
                backtrace_symbols_fd (&array[1], size-1, fd);
                sprintf (msg, "---------\n");
                ret = write (fd, msg, strlen (msg));
                if (ret < 0)
                        goto out;
        }
#endif /* HAVE_BACKTRACE */

out:
        /* Send a signal to terminate the process */
        signal (signum, SIG_DFL);
        raise (signum);
}
Exemple #6
0
static int
gf_remember_xlator_option (struct list_head *options, char *arg)
{
    glusterfs_ctx_t         *ctx = NULL;
    cmd_args_t              *cmd_args  = NULL;
    xlator_cmdline_option_t *option = NULL;
    int                      ret = -1;
    char                    *dot = NULL;
    char                    *equals = NULL;

    ctx = glusterfs_ctx_get ();
    cmd_args = &ctx->cmd_args;

    option = GF_CALLOC (1, sizeof (xlator_cmdline_option_t),
                        gfd_mt_xlator_cmdline_option_t);
    if (!option)
        goto out;

    INIT_LIST_HEAD (&option->cmd_args);

    dot = strchr (arg, '.');
    if (!dot)
        goto out;

    option->volume = GF_CALLOC ((dot - arg) + 1, sizeof (char),
                                gfd_mt_char);
    strncpy (option->volume, arg, (dot - arg));

    equals = strchr (arg, '=');
    if (!equals)
        goto out;

    option->key = GF_CALLOC ((equals - dot) + 1, sizeof (char),
                             gfd_mt_char);
    if (!option->key)
        goto out;

    strncpy (option->key, dot + 1, (equals - dot - 1));

    if (!*(equals + 1))
        goto out;

    option->value = gf_strdup (equals + 1);

    list_add (&option->cmd_args, &cmd_args->xlator_options);

    ret = 0;
out:
    if (ret == -1) {
        if (option) {
            if (option->volume)
                GF_FREE (option->volume);
            if (option->key)
                GF_FREE (option->key);
            if (option->value)
                GF_FREE (option->value);

            GF_FREE (option);
        }
    }

    return ret;
}