コード例 #1
0
ファイル: connection.c プロジェクト: abhinavvv/skyefs
static int pvfs_generate_serverlist(){
    int ret, servercount, i;
    PVFS_credentials credentials; PVFS_util_gen_credentials(&credentials);

    // What hostname are we using
    if (!myhostname)
        myhostname = getenv("HOSTNAME");
    if (!myhostname){
        myhostname = malloc(HOST_NAME_MAX + 1);
        gethostname(myhostname, HOST_NAME_MAX);
        myhostname[HOST_NAME_MAX] = '\0';
    }

    skye_options.servernum = -1;

    ret = PVFS_mgmt_count_servers(pvfs_fsid,&credentials,PVFS_MGMT_META_SERVER,&servercount);
    if (ret < 0) return ret;

    skye_options.serveraddrs = malloc(sizeof(PVFS_BMI_addr_t)*(servercount));
    if (!skye_options.serveraddrs) return -ENOMEM;

    ret = PVFS_mgmt_get_server_array(pvfs_fsid,&credentials,PVFS_MGMT_META_SERVER, skye_options.serveraddrs, &servercount);
    if (ret < 0) return ret;

    const char **servers = malloc(sizeof(char*)*(servercount));
    if (!servers) return -ENOMEM;

    for (i = 0; i < servercount; i++){
        servers[i] = PVFS_mgmt_map_addr(pvfs_fsid,&credentials,skye_options.serveraddrs[i],NULL);    

        char *start, *end;

        /* cut out just the server portion of tcp://servername:port */
        end = rindex(servers[i], ':');
        start = rindex(servers[i], '/');

        servers[i] = strndup(start + 1, end - start - 1);

        if (!servers[i]) return -ENOMEM; 
        
        if (strcmp(servers[i],myhostname) == 0)
            skye_options.servernum = i;
    }

    skye_options.serverlist = servers;
    skye_options.servercount = servercount;

    return 0;
}
コード例 #2
0
ファイル: benchmark-utils.c プロジェクト: sumitn/pvfs
int test_util_init_perfs(
    PVFS_fs_id cur_fs,
    PVFS_credentials creds,
    int32_t flags,
    int * server_count)
{
    int ret, i;
    int count;

    /* count how many meta servers we have */
    ret = PVFS_mgmt_count_servers(cur_fs, &creds, flags,
                                  server_count);
    if(ret < 0)
    {
        PVFS_perror("PVFS_mgmt_count_servers", ret);
        return(ret);
    }

    count = *server_count;
    /* allocate a 2 dimensional array for statistics */
    perf_matrix = (struct PVFS_mgmt_perf_stat**)malloc(
                      count*sizeof(struct PVFS_mgmt_perf_stat*));
    if(!perf_matrix)
    {
        PVFS_perror("malloc", -1);
        return(-1);
    }
    for(i=0; i<count; i++)
    {
        perf_matrix[i] = (struct PVFS_mgmt_perf_stat *)
                         malloc(HISTORY * sizeof(struct PVFS_mgmt_perf_stat));
        if (perf_matrix[i] == NULL)
        {
            PVFS_perror("malloc", -1);
            return -1;
        }
    }

    /* allocate an array to keep up with what iteration of statistics
     * we need from each server
     */
    next_id_array = (uint32_t *) malloc(count * sizeof(uint32_t));
    if (next_id_array == NULL)
    {
        PVFS_perror("malloc", -1);
        return -1;
    }
    memset(next_id_array, 0, count*sizeof(uint32_t));

    /* allocate an array to keep up with end times from each server */
    end_time_ms_array = (uint64_t *)
                        malloc(count * sizeof(uint64_t));
    if (end_time_ms_array == NULL)
    {
        PVFS_perror("malloc", -1);
        return -1;
    }

    /* build a list of servers to talk to */
    addr_array = (PVFS_BMI_addr_t *)
                 malloc(count * sizeof(PVFS_BMI_addr_t));
    if (addr_array == NULL)
    {
        PVFS_perror("malloc", -1);
        return -1;
    }
    ret = PVFS_mgmt_get_server_array(cur_fs,
                                     &creds,
                                     flags,
                                     addr_array,
                                     &count);
    if (ret < 0)
    {
        PVFS_perror("PVFS_mgmt_get_server_array", ret);
        return -1;
    }

    return 0;

}
コード例 #3
0
ファイル: pvfs2-fsck.c プロジェクト: snsl/pvfs2-osd
int main(int argc, char **argv)
{
    int ret = -1, in_admin_mode = 0;
    PVFS_fs_id cur_fs;
    char pvfs_path[PVFS_NAME_MAX] = {0};
    PVFS_credentials creds;
    int server_count;
    PVFS_BMI_addr_t *addr_array = NULL;
    struct handlelist *hl_all, *hl_unrefd, *hl_notree;
    struct PVFS_mgmt_setparam_value param_value;

    fsck_opts = parse_args(argc, argv);
    if (!fsck_opts)
    {
	fprintf(stderr, "Error: failed to parse command line arguments.\n");
	usage(argc, argv);
	return -1;
    }

    ret = PVFS_util_init_defaults();
    if (ret != 0)
    {
	PVFS_perror("PVFS_util_init_defaults", ret);
	return -1;
    }

    /* translate local path into pvfs2 relative path */
    ret = PVFS_util_resolve(fsck_opts->mnt_point,
			    &cur_fs,
			    pvfs_path,
			    PVFS_NAME_MAX);
    if (ret != 0)
    {
	PVFS_perror("PVFS_util_resolve", ret);
	return -1;
    }

    PVFS_util_gen_credentials(&creds);

    printf("# Current FSID is %u.\n", cur_fs);

    /* count how many servers we have */
    ret = PVFS_mgmt_count_servers(cur_fs, &creds, 
	PVFS_MGMT_IO_SERVER|PVFS_MGMT_META_SERVER,
	&server_count);
    if (ret != 0)
    {
	PVFS_perror("PVFS_mgmt_count_servers", ret);
	return -1;
    }

    /* build a list of servers to talk to */
    addr_array = (PVFS_BMI_addr_t *)
	malloc(server_count * sizeof(PVFS_BMI_addr_t));
    if (addr_array == NULL)
    {
	perror("malloc");
	return -1;
    }
    ret = PVFS_mgmt_get_server_array(cur_fs,
				     &creds, 
				     PVFS_MGMT_IO_SERVER|PVFS_MGMT_META_SERVER,
				     addr_array,
				     &server_count);
    if (ret != 0)
    {
	PVFS_perror("PVFS_mgmt_get_server_array", ret);
	return -1;
    }

    /* create /lost+found, if it isn't there already */
    ret = create_lost_and_found(cur_fs,
				&creds);
    if (ret != 0) {
	if (ret == -PVFS_EAGAIN) {
	    printf("Failed to create lost+found: likely the system is "
		   "already in admin mode.  Use pvfs2-set-mode to change "
		   "back to normal mode prior to running pvfs2-fsck.\n");
	}
	return -1;
    }

    param_value.type = PVFS_MGMT_PARAM_TYPE_UINT64;
    param_value.u.value = PVFS_SERVER_ADMIN_MODE;
    /* put the servers into administrative mode */
    ret = PVFS_mgmt_setparam_list(cur_fs,
				  &creds,
				  PVFS_SERV_PARAM_MODE,
				  &param_value,
				  addr_array,
				  server_count,
				  NULL, /* detailed errors */
                                  NULL);
    if (ret != 0)
    {
	PVFS_perror("PVFS_mgmt_setparam_list", ret);
	ret = -1;
	goto exit_now;
    }
    
    in_admin_mode = 1;

    hl_all = build_handlelist(cur_fs, addr_array, server_count, &creds);
    if (hl_all == NULL) {
	ret = -1;
	goto exit_now;
    }

    /* first pass traverses the directory tree:
     * - cleans up any direntries that refer to missing objects
     * - verifies that files in the tree have all their datafiles 
     *   (or repairs if possible)
     * - verifies that all directories have their dirdata
     *   (or repairs if possible)
     */
    printf("# first pass: traversing directory tree.\n");
    traverse_directory_tree(cur_fs,
			    hl_all,
			    addr_array,
			    server_count,
			    &creds);

    /* second pass examines handles not in the directory tree:
     * - finds orphaned "sub trees" and keeps references to head
     *   - verifies files in the sub tree have all datafiles
     *     (or repairs if possible)
     *   - verifies all sub tree directories have their dirdata
     *     (or repairs if possible)
     * - builds list of metafile, dirdata, and datafiles not referenced
     *   in some sub tree to be processed later
     */
    printf("# second pass: finding orphaned sub trees.\n");
    hl_notree = find_sub_trees(cur_fs,
			       hl_all,
			       addr_array,
			       &creds);

    handlelist_finalize(&hl_all);

    param_value.type = PVFS_MGMT_PARAM_TYPE_UINT64;
    param_value.u.value = PVFS_SERVER_NORMAL_MODE;

    /* drop out of admin mode now that we've traversed the dir tree */
    PVFS_mgmt_setparam_list(cur_fs,
			    &creds,
			    PVFS_SERV_PARAM_MODE,
			    &param_value,
			    addr_array,
			    server_count,
			    NULL, NULL);
    in_admin_mode = 0;

    /* third pass moves salvagable objects into lost+found:
     * - moves sub trees into lost+found
     * - verifies that orphaned files have all their datafiles
     *   (or repairs if possible)
     *   - if orphaned file is salvagable, moves into lost+found
     * - builds list of remaining dirdata and datafiles not
     *   referenced in sub tree or orphaned file
     */
    printf("# third pass: moving orphaned sub trees and files to lost+found.\n");
    hl_unrefd = fill_lost_and_found(cur_fs,
				    hl_notree,
				    addr_array,
				    &creds);
    handlelist_finalize(&hl_notree);

    /* fourth pass removes orphaned dirdata and datafiles
     * left from the previous passes.
     */
    printf("# fourth pass: removing unreferenced objects.\n");
    cull_leftovers(cur_fs, hl_unrefd, addr_array, &creds);
    handlelist_finalize(&hl_unrefd);

 exit_now:
    if (in_admin_mode) {

        param_value.type = PVFS_MGMT_PARAM_TYPE_UINT64;
        param_value.u.value = PVFS_SERVER_NORMAL_MODE;

	/* get us out of admin mode */
	PVFS_mgmt_setparam_list(cur_fs,
				&creds,
				PVFS_SERV_PARAM_MODE,
                                &param_value,
				addr_array,
				server_count,
				NULL, NULL);
    }
    
    PVFS_sys_finalize();

    if (addr_array != NULL) free(addr_array);
    if (fsck_opts != NULL)   free(fsck_opts);

    return(ret);
}
コード例 #4
0
ファイル: pvfs2-perf-mon-snmp.c プロジェクト: snsl/pvfs2-osd
int main(int argc, char **argv)
{
    int ret = -1;
    char *retc = NULL;
    PVFS_fs_id cur_fs;
    struct options* user_opts = NULL;
    char pvfs_path[PVFS_NAME_MAX] = {0};
    int i;
    PVFS_credentials creds;
    int io_server_count;
    int64_t **perf_matrix;
    uint64_t* end_time_ms_array;
    uint32_t* next_id_array;
    PVFS_BMI_addr_t *addr_array, server_addr;
    char *cmd_buffer = (char *)malloc(CMD_BUF_SIZE);
    int max_keys, key_count;

    /* look at command line arguments */
    user_opts = parse_args(argc, argv);
    if (!user_opts)
    {
        fprintf(stderr, "Error: failed to parse command line arguments.\n");
        usage(argc, argv);
        return(-1);
    }

    ret = PVFS_util_init_defaults();
    if (ret < 0)
    {
        PVFS_perror("PVFS_util_init_defaults", ret);
        return(-1);
    }

    PVFS_util_gen_credentials(&creds);
    if (user_opts->server_addr_set)
    {
        if (PVFS_util_get_default_fsid(&cur_fs) < 0)
        {
            /* Can't find a file system */
            fprintf(stderr, "Error: failed to find a file system.\n");
            usage(argc, argv);
            return(-1);
        }
        if (user_opts->server_addr &&
                (BMI_addr_lookup (&server_addr, user_opts->server_addr) == 0))
        {
            /* set up single server */
            addr_array = (PVFS_BMI_addr_t *)malloc(sizeof(PVFS_BMI_addr_t));
            addr_array[0] = server_addr;
            io_server_count = 1;
        }
        else
        {
            /* bad argument - address not found */
            fprintf(stderr, "Error: failed to parse server address.\n");
            usage(argc, argv);
            return(-1);
        }
    }
    else
    {
        /* will sample all servers */
        /* translate local path into pvfs2 relative path */
        ret = PVFS_util_resolve(user_opts->mnt_point,
                                &cur_fs, pvfs_path, PVFS_NAME_MAX);
        if (ret < 0)
        {
            PVFS_perror("PVFS_util_resolve", ret);
            return(-1);
        }

        /* count how many I/O servers we have */
        ret = PVFS_mgmt_count_servers(cur_fs, &creds, PVFS_MGMT_IO_SERVER,
                                    &io_server_count);
        if (ret < 0)
        {
            PVFS_perror("PVFS_mgmt_count_servers", ret);
	        return(-1);
        }
    
        /* build a list of servers to talk to */
        addr_array = (PVFS_BMI_addr_t *)
	    malloc(io_server_count * sizeof(PVFS_BMI_addr_t));
        if (addr_array == NULL)
        {
	        perror("malloc");
	        return -1;
        }
        ret = PVFS_mgmt_get_server_array(cur_fs,
				     &creds,
				     PVFS_MGMT_IO_SERVER,
				     addr_array,
				     &io_server_count);
        if (ret < 0)
        {
	        PVFS_perror("PVFS_mgmt_get_server_array", ret);
	        return -1;
        }
    }

    /* count keys */
    for (max_keys = 0; key_table[max_keys].key_number >= 0; max_keys++);

    /* allocate a 2 dimensional array for statistics */
    perf_matrix = (int64_t **)malloc(io_server_count * sizeof(int64_t *));
    if (!perf_matrix)
    {
        perror("malloc");
        return(-1);
    }
    for(i=0; i<io_server_count; i++)
    {
	    perf_matrix[i] = (int64_t *)malloc(HISTORY * (max_keys + 2)
                                        * sizeof(int64_t));
	    if (perf_matrix[i] == NULL)
	    {
	        perror("malloc");
	        return -1;
	    }
    }

    /* allocate an array to keep up with what iteration of statistics
     * we need from each server 
     */
    next_id_array = (uint32_t *) malloc(io_server_count * sizeof(uint32_t));
    if (next_id_array == NULL)
    {
	     perror("malloc");
	     return -1;
    }
    memset(next_id_array, 0, io_server_count*sizeof(uint32_t));

    /* allocate an array to keep up with end times from each server */
    end_time_ms_array = (uint64_t *)malloc(io_server_count * sizeof(uint64_t));
    if (end_time_ms_array == NULL)
    {
	    perror("malloc");
	    return -1;
    }


    /* loop for ever, grabbing stats when requested */
    while (1)
    {
        int srv = 0;
        time_t snaptime = 0;
        const char *returnType = NULL; 
        int64_t returnValue = 0;
        /* wait for a request from SNMP driver */
        retc = fgets(cmd_buffer, CMD_BUF_SIZE, stdin);
        if (!retc)
        {
            /* error on read */
            return -1;
        }

        /* if PING output PONG */
        if (!strncasecmp(cmd_buffer, "PING", 4))
        {
            fprintf(stdout,"PONG\n");
	        fflush(stdout);
            continue;
        }

        /* try to parse GET command */
        if (!strncasecmp(cmd_buffer, "GET", 3))
        {
            char *c;
            /* found GET read OID */
            retc = fgets(cmd_buffer, CMD_BUF_SIZE, stdin);
            if (!retc)
            {
                /* error on read */
                return -1;
            }
            /* replace newlines with null char */
            for(c = cmd_buffer; *c != '\0'; c++)
                if (*c == '\n')
                    *c = '\0';
        }
        else
        {
            /* bad command */
            fprintf(stdout, "NONE\n");
            fflush(stdout);
            continue;
        }

        /* good command - read counters */
        if (time(NULL) - snaptime > 60)
        {
            snaptime = time(NULL);
            key_count = max_keys;
	        ret = PVFS_mgmt_perf_mon_list(cur_fs,
				          &creds,
				          perf_matrix, 
				          end_time_ms_array,
				          addr_array,
				          next_id_array,
				          io_server_count, 
                          &key_count,
				          HISTORY,
				          NULL, NULL);
	        if (ret < 0)
	        {
	            PVFS_perror("PVFS_mgmt_perf_mon_list", ret);
	            return -1;
	        }
        }

        /* format requested OID */
        if (perf_matrix[srv][key_count] != 0)
        {
            int k;
            /* this is a valid measurement */
            for(k = 0; k < max_keys &&
                    strcmp(cmd_buffer, key_table[k].key_oid); k++);
            /* out of for loop k equals selected key */
            if (k < max_keys)
            {
                returnType = key_table[k].key_type;
                returnValue = perf_matrix[srv][key_table[k].key_number];
            }
            else
            {
                /* invalid command */
                fprintf(stdout,"NONE\n");
                fflush(stdout);
                continue;
            }
        }
        else
        {
            /* invalid measurement */
            fprintf(stdout,"NONE\n");
            fflush(stdout);
            continue;
        }
        fprintf(stdout, "%s\n%llu\n", returnType, llu(returnValue));
        fflush(stdout);
        /* return to top for next command */
    }

    PVFS_sys_finalize();

    return(ret);
}