Ejemplo n.º 1
0
/* convenience function to return all nodes, or default node if none found */
static fsa_node_addr *get_storage_nodes(void)
{
    GKeyFile *config = fsa_get_config();
    int default_port = fsa_get_admind_port(config);
    fsa_node_addr *nodes = NULL;

    /* use localhost if no config file found */
    if (config == NULL) {
        fsa_error(LOG_WARNING,
                  "Unable to read config file at '%s', assuming localhost\n",
                  fs_get_config_file()); 
        nodes = fsa_node_addr_new("localhost");
        nodes->port = default_port;
        return nodes;
    }

    nodes = fsa_get_node_list(config);

    /* done with config */
    fsa_config_free(config);

    /* if no nodes found in config file, use localhost */
    if (nodes == NULL) {
        fsa_error(LOG_WARNING,
                  "No nodes found in '%s', assuming localhost\n",
                  fs_get_config_file()); 
        nodes = fsa_node_addr_new("localhost");
        nodes->port = default_port;
        return nodes;
    }

    return nodes;
}
Ejemplo n.º 2
0
/* check command line opts and config file to set server_port global */
static int init_server_port(void)
{
    int port;

    /* no port given on command line */
    if (cport == NULL) {
        /* get default or config file port */
        GKeyFile *config = fsa_get_config();
        port = fsa_get_admind_port(config);
        fsa_config_free(config);

        if (port == -1) {
            if (errno == ADM_ERR_BAD_CONFIG) {
                fprintf(
                    stderr,
                    "%s: non-numeric port specified in %s",
                    program_invocation_short_name, fs_get_config_file()
                );
            }
            else if (errno == ERANGE) {
                fprintf(
                    stderr,
                    "%s: port number out of range 0-65535 in %s",
                    program_invocation_short_name, fs_get_config_file()
                );
            }
            else {
                fprintf(
                    stderr,
                    "%s: unknown error reading port from config file at %s\n",
                    program_invocation_short_name, fs_get_config_file()
                );
            }
            return -1;
        }
    }
    else {
        /* cport has been specified on command line */

        if (!fsa_is_int(cport)) {
            fprintf(stderr, "%s: non-numeric port specified on command line\n",
                    program_invocation_short_name);
            return -1;
        }

        port = atoi(cport);
        if (port < 0 || port > 65535) {
            fprintf(stderr, "%s: port number %d out of range 0-65535\n",
                    program_invocation_short_name, port);
            return -1;
        }
    }

    /* have a port 0-65535 if we got here */
    sprintf(server_port, "%d", port);
    return 0;
}
Ejemplo n.º 3
0
/* Get /etc/4store.conf as GKeyFile */
GKeyFile *fsa_get_config(void)
{
    GKeyFile *config_file = g_key_file_new();
    GError *err = NULL;
    const char *filename = fs_get_config_file();
    int rv;
    int flags = G_KEY_FILE_NONE;

    rv = g_key_file_load_from_file(config_file, filename, flags, &err);
    if (!rv || err != NULL) {
        if (err->code != G_FILE_ERROR_NOENT
            && err->code != G_FILE_ERROR_EXIST
            && err->code != G_FILE_ERROR_ISDIR) {
            fsa_error(LOG_ERR, "error reading %s: %s(%d)",
                      filename, err->message, err->code);
        }
        g_error_free(err);
        g_key_file_free(config_file);
        errno = ADM_ERR_GENERIC;
        return NULL;
    }

    errno = 0;
    return config_file;
}
Ejemplo n.º 4
0
/* Check whether admin daemon on all nodes is reachable */
static int cmd_list_nodes(void)
{
    /* this command has no arguments, exit if any are found */
    if (args_index >= 0) {
        print_invalid_arg();
        return 1;
    }

    /* network related vars */
    struct addrinfo hints;
    int default_port = FS_ADMIND_PORT;
    fsa_node_addr *nodes = NULL;
    fsa_node_addr *p;
    int sock_fd;
    char ipaddr[INET6_ADDRSTRLEN];

    /* printing/output related vars */
    int all_nodes_ok = 0;
    int hostlen = 13;
    int len;
    int node_num = 0;
    int n_nodes = 0;

    /* Setup hints information */
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    /* attempt to read /etc/4store.conf */
    GKeyFile *config = fsa_get_config();

    if (config == NULL) {
        /* assume localhost if no config file found */
        fsa_error(LOG_WARNING,
                  "Unable to read config file at '%s', assuming localhost\n",
                  fs_get_config_file()); 
    }
    else {
        nodes = fsa_get_node_list(config);
        if (nodes == NULL) {
            fsa_error(LOG_WARNING,
                      "No nodes found in '%s', assuming localhost\n",
                      fs_get_config_file()); 
            default_port = fsa_get_admind_port(config);
        }
    }

    if (nodes == NULL) {
        /* Use localhost and default port */
        nodes = fsa_node_addr_new("localhost");
        nodes->port = default_port;
    }


    /* loop through once to get lengths of various fields */
    for (p = nodes; p != NULL; p = p->next) {
        len = strlen(p->host) + 1;
        if (len > hostlen) {
            hostlen = len;
        }

        n_nodes += 1;
    }

    int n_nodes_len = int_len(n_nodes);
    if (n_nodes_len < 11) {
        n_nodes_len = 11;
    }

    /* print column headers */
    if (colour_flag) {
        printf(ANSI_COLOUR_BLUE);
    }

    printf("%-*s %-*s port  status      ip_address\n",
           n_nodes_len, "node_number", hostlen, "hostname");

    if (colour_flag) {
        printf(ANSI_COLOUR_RESET);
    }

    /* loop through all nodes and attempt to connect admin daemon on each */
    for (p = nodes; p != NULL; p = p->next) {
        /* set default output for IP address */
        strcpy(ipaddr, "unknown");

        /* check if we can open conn to admin daemon */
        sock_fd = fsaf_connect_to_admind(p->host, p->port, &hints, ipaddr);

        /* print result of attempted connection */
        printf("%-*d %-*s %-5d ",
               n_nodes_len, node_num, hostlen, p->host, p->port);
        if (sock_fd == -1) {
            print_colour("unreachable", ANSI_COLOUR_RED);
            all_nodes_ok = 2;
        }
        else {
            print_colour("ok         ", ANSI_COLOUR_GREEN);
            close(sock_fd);
        }
        printf(" %s\n", ipaddr);

        node_num += 1;
    }

    fsa_node_addr_free(nodes);
    fsa_config_free(config);

    return all_nodes_ok;
}