int main(int argc, char **argv) { int ret = -1; PVFS_fs_id cur_fs; struct options* user_opts = NULL; char pvfs_path[PVFS_NAME_MAX] = {0}; PVFS_credentials creds; /* 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); } /* 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) { fprintf(stderr, "Error: could not find filesystem for %s in pvfstab\n", user_opts->mnt_point); return(-1); } PVFS_util_gen_credentials(&creds); ret = PVFS_mgmt_setparam_all(cur_fs, &creds, PVFS_SERV_PARAM_DROP_CACHES, 0, NULL, NULL /* detailed errors */); if(ret < 0) { PVFS_perror("PVFS_mgmt_setparam_all", ret); return(-1); } PVFS_sys_finalize(); return(ret); }
int main(int argc, char **argv) { int ret = -1; struct options* user_opts = NULL; struct PVFS_sys_mntent* tmp_ent = NULL; char config_server[256]; /* 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); } sprintf(config_server, "%.50s://%.150s:%d", user_opts->network_proto, user_opts->hostname, user_opts->port); /* build mnt entry */ tmp_ent = PVFS_util_gen_mntent(config_server, user_opts->fsname); if(!tmp_ent) { fprintf(stderr, "Error: failed to build mnt entry.\n"); return(-1); } ret = PVFS_sys_initialize(GOSSIP_NO_DEBUG); if(ret < 0) { fprintf(stderr, "Error: failed to initialize PVFS2 library.\n"); return(-1); } ret = PVFS_sys_fs_add(tmp_ent); if(ret < 0) { PVFS_perror("Error: could not retrieve configuration from server", ret); return(-1); } PVFS_sys_finalize(); PVFS_util_gen_mntent_release(tmp_ent); return(ret); }
int main(int argc, char **argv) { int ret = 0; struct options* user_opts = NULL; int i, k; /* look at command line arguments */ user_opts = parse_args(argc, argv); if(!user_opts) { fprintf(stderr, "Error: failed to parse " "command line arguments.\n"); return(-1); } ret = PVFS_util_init_defaults(); if(ret < 0) { PVFS_perror("PVFS_util_init_defaults", ret); return(-1); } /* * for each file the user specified * for each file the user specified */ for (i = 0; i < user_opts->target_count; i++) { ret = pvfs2_geteattr(user_opts->nkey, user_opts->key, user_opts->val, user_opts->destfiles[i]); if (ret != 0) { printf("geteattr returned error code - exiting\n"); break; } for (k = 0; k < user_opts->nkey; k++) { printf("key[%d]:%s Value:\n%s\n",k, (char *)user_opts->key[k].buffer, (char *)user_opts->val[k].buffer); } /* TODO: need to free the request descriptions */ } PVFS_sys_finalize(); return(ret); }
int main(int argc,char **argv) { int ret = -1; char str_buf[256] = {0}; char *filename = (char *)0; PVFS_fs_id cur_fs; char* entry_name; PVFS_object_ref parent_refn; PVFS_credentials credentials; if (argc != 2) { printf("usage: %s file_to_remove\n", argv[0]); return 1; } filename = argv[1]; ret = PVFS_util_init_defaults(); if (ret < 0) { PVFS_perror("PVFS_util_init_defaults", ret); return (-1); } ret = PVFS_util_get_default_fsid(&cur_fs); if (ret < 0) { PVFS_perror("PVFS_util_get_default_fsid", ret); return (-1); } if (PINT_remove_base_dir(filename,str_buf,256)) { if (filename[0] != '/') { printf("You forgot the leading '/'\n"); } printf("Cannot retrieve entry name for creation on %s\n", filename); return(-1); } printf("File to be removed is %s\n",str_buf); entry_name = str_buf; PVFS_util_gen_credentials(&credentials); ret = PINT_lookup_parent(filename, cur_fs, &credentials, &parent_refn.handle); if(ret < 0) { PVFS_perror("PVFS_util_lookup_parent", ret); return(-1); } parent_refn.fs_id = cur_fs; ret = PVFS_sys_remove(entry_name, parent_refn, &credentials, NULL); if (ret < 0) { PVFS_perror("remove failed ", ret); return(-1); } printf("===================================\n"); printf("file named %s has been removed.\n", filename); //close it down ret = PVFS_sys_finalize(); if (ret < 0) { printf("finalizing sysint failed with errcode = %d\n", ret); return (-1); } return(0); }
int pvfsDestory() { PVFS_sys_finalize(); PVFS_hint_free(hints); }
static int test_finalize(void) { int ret = -2; ret = PVFS_sys_finalize(); return ret; }
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, ¶m_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, ¶m_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, ¶m_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); }
int main(int argc, char **argv) { int ret = -1; char str_buf[256] = {0}; char *filename = (char *)0; PVFS_fs_id cur_fs; PVFS_sysresp_symlink resp_sym; char* entry_name = NULL; char *target = NULL; PVFS_object_ref parent_refn; PVFS_sys_attr attr; PVFS_credentials credentials; if (argc != 3) { fprintf(stderr,"Usage: %s filename target\n",argv[0]); return ret; } filename = argv[1]; target = argv[2]; ret = PVFS_util_init_defaults(); if (ret < 0) { PVFS_perror("PVFS_util_init_defaults", ret); return (-1); } ret = PVFS_util_get_default_fsid(&cur_fs); if (ret < 0) { PVFS_perror("PVFS_util_get_default_fsid", ret); return (-1); } if (PINT_remove_base_dir(filename,str_buf,256)) { if (filename[0] != '/') { printf("You forgot the leading '/'\n"); } printf("Cannot retrieve link name for creation on %s\n", filename); return(-1); } printf("Link to be created is %s\n",str_buf); memset(&resp_sym, 0, sizeof(PVFS_sysresp_symlink)); PVFS_util_gen_credentials(&credentials); entry_name = str_buf; attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; attr.owner = credentials.uid; attr.group = credentials.gid; attr.perms = 1877; attr.atime = attr.ctime = attr.mtime = time(NULL); ret = PINT_lookup_parent(filename, cur_fs, &credentials, &parent_refn.handle); if(ret < 0) { PVFS_perror("PVFS_util_lookup_parent", ret); return(-1); } parent_refn.fs_id = cur_fs; ret = PVFS_sys_symlink(entry_name, parent_refn, target, attr, &credentials, &resp_sym, NULL); if (ret < 0) { printf("symlink failed with errcode = %d\n", ret); return(-1); } printf("--symlink--\n"); printf("Handle: %lld\n", lld(resp_sym.ref.handle)); ret = PVFS_sys_finalize(); if (ret < 0) { printf("finalizing sysint failed with errcode = %d\n", ret); return (-1); } return(0); }
int main(int argc, char **argv) { int ret = -1, i = 0; char ** ppszPvfsPath = NULL; PVFS_fs_id * pfs_id = NULL; PVFS_credentials credentials; struct options user_opts; /* Initialize any memory */ memset(&user_opts, 0, sizeof(user_opts)); memset(&credentials, 0, sizeof(credentials)); ret = parse_args(argc, argv, &user_opts); if(ret < 0) { fprintf(stderr, "Error: failed to parse command line arguments.\n"); usage(argc, argv); return(-1); } if(user_opts.nVerbose) { fprintf(stdout, "Starting pvfs2-stat\n"); } /* Allocate space to hold the relative pvfs2 path & fs_id for each * requested file */ ppszPvfsPath = (char **)calloc(user_opts.nNumFiles, sizeof(char *)); if(ppszPvfsPath == NULL) { fprintf(stderr, "Unable to allocate memory\n"); return(-1); } /* Allocate enough space to hold file system id for each directory */ pfs_id = (PVFS_fs_id *)calloc(user_opts.nNumFiles, sizeof(PVFS_fs_id)); if(pfs_id == NULL) { fprintf(stderr, "Unable to allocate memory\n"); return(-1); } for(i = 0; i < user_opts.nNumFiles; i++) { ppszPvfsPath[i] = (char *)calloc(PVFS_NAME_MAX, sizeof(char)); if(ppszPvfsPath[i] == NULL) { fprintf(stderr, "Unable to allocate memory\n"); return(-1); } } ret = PVFS_util_init_defaults(); if(ret < 0) { PVFS_perror("PVFS_util_init_defaults", ret); return(-1); } /* Let's verify that all the given files reside on a PVFS2 filesytem */ for(i = 0; i < user_opts.nNumFiles; i++) { ret = PVFS_util_resolve(user_opts.pszFiles[i], &pfs_id[i], ppszPvfsPath[i], PVFS_NAME_MAX); if (ret < 0) { fprintf(stderr, "Error: could not find file system for %s\n", user_opts.pszFiles[i]); return(-1); } } /* We will re-use the same credentials for each call */ PVFS_util_gen_credentials(&credentials); for(i = 0; i < user_opts.nNumFiles; i++) { ret = do_stat(user_opts.pszFiles[i], ppszPvfsPath[i], pfs_id[i], &credentials, &user_opts); if(ret != 0) { fprintf(stderr, "Error stating [%s]\n", user_opts.pszFiles[i]); } } PVFS_sys_finalize(); /* Deallocate any allocated memory */ if(user_opts.pszFiles != NULL) { free(user_opts.pszFiles); } if(ppszPvfsPath != NULL) { for(i=0;i<user_opts.nNumFiles;i++) { if(ppszPvfsPath[i] != NULL) { free(ppszPvfsPath[i]); } } free(ppszPvfsPath); } if(pfs_id != NULL) { free(pfs_id); } return(0); }
int main(int argc, char **argv) { int ret = -1, i = 0; char pvfs_path[MAX_NUM_PATHS][PVFS_NAME_MAX]; PVFS_fs_id fs_id_array[MAX_NUM_PATHS] = {0}; const PVFS_util_tab* tab; struct options* user_opts = NULL; char current_dir[PVFS_NAME_MAX] = {0}; int found_one = 0; process_name = argv[0]; user_opts = parse_args(argc, argv); if (!user_opts) { fprintf(stderr, "Error: failed to parse command line " "arguments.\n"); usage(argc, argv); return(-1); } tab = PVFS_util_parse_pvfstab(NULL); if (!tab) { fprintf(stderr, "Error: failed to parse pvfstab.\n"); return(-1); } for(i = 0; i < MAX_NUM_PATHS; i++) { memset(pvfs_path[i],0,PVFS_NAME_MAX); } ret = PVFS_sys_initialize(GOSSIP_NO_DEBUG); if (ret < 0) { PVFS_perror("PVFS_sys_initialize", ret); return(-1); } /* initialize each file system that we found in the tab file */ for(i = 0; i < tab->mntent_count; i++) { ret = PVFS_sys_fs_add(&tab->mntent_array[i]); if (ret == 0) { found_one = 1; } } if (!found_one) { fprintf(stderr, "Error: could not initialize any file systems " "from %s\n", tab->tabfile_name); PVFS_sys_finalize(); return(-1); } if (user_opts->num_starts == 0) { snprintf(current_dir,PVFS_NAME_MAX,"%s/", tab->mntent_array[0].mnt_dir); user_opts->start[0] = current_dir; user_opts->num_starts = 1; } for(i = 0; i < user_opts->num_starts; i++) { ret = PVFS_util_resolve(user_opts->start[i], &fs_id_array[i], pvfs_path[i], PVFS_NAME_MAX); if ((ret == 0) && (pvfs_path[i][0] == '\0')) { strcpy(pvfs_path[i], "/"); } if (ret < 0) { fprintf(stderr, "Error: could not find file system " "for %s in pvfstab\n", user_opts->start[i]); return(-1); } } for(i = 0; i < user_opts->num_starts; i++) { char *substr = strstr(user_opts->start[i],pvfs_path[i]); char *index = user_opts->start[i]; char *search = substr; int j = 0; /* Keep the mount path info to mimic /bin/ls output */ if( strncmp(pvfs_path[i],"/",strlen(pvfs_path[i])) ) { /* Get last matching substring */ while (search) { substr = search; search = strstr(++search,pvfs_path[i]); } } else /* Root directory case has nothing to match */ { substr = &user_opts->start[i][strlen(user_opts->start[i])-1]; } while ((index != substr) && (substr != NULL)) { index++; j++; } user_opts->start[i][j] = '\0'; do_list(user_opts->start[i], pvfs_path[i], fs_id_array[i], user_opts); if (user_opts->num_starts > 1) { printf("\n"); } } PVFS_sys_finalize(); free(user_opts); return(ret); }
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); }
int finalize_sysint(void) { int ret = PVFS_sys_finalize(); pvfs_helper.initialized = 0; return ret; }
int main(int argc, char **argv) { PVFS_sysresp_lookup resp_lk; PVFS_sysresp_create resp_cr; PVFS_sysresp_io resp_io; char *filename = NULL; int ret = -1, io_size = DEFAULT_IO_SIZE; int *io_buffer = NULL; int i, errors, buffer_size; PVFS_fs_id fs_id; char name[512] = {0}; char *entry_name = NULL; PVFS_credentials credentials; PVFS_object_ref parent_refn; PVFS_sys_attr attr; PVFS_object_ref pinode_refn; PVFS_Request file_req; PVFS_Request mem_req; void *buffer = NULL; PVFS_sysresp_getattr resp_getattr; PVFS_handle *dfile_array = NULL; if (argc != 2) { fprintf(stderr, "Usage: %s <file name>\n", argv[0]); return (-1); } /* create a buffer for running I/O on */ io_buffer = (int *) malloc(io_size * sizeof(int)); if (!io_buffer) { return (-1); } /* put some data in the buffer so we can verify */ for (i = 0; i < io_size; i++) { io_buffer[i] = i; } ret = PVFS_util_init_defaults(); if (ret < 0) { PVFS_perror("PVFS_util_init_defaults", ret); return (-1); } ret = PVFS_util_get_default_fsid(&fs_id); if (ret < 0) { PVFS_perror("PVFS_util_get_default_fsid", ret); return (-1); } if (argv[1][0] == '/') { snprintf(name, 512, "%s", argv[1]); } else { snprintf(name, 512, "/%s", argv[1]); } PVFS_util_gen_credentials(&credentials); ret = PVFS_sys_lookup(fs_id, name, &credentials, &resp_lk, PVFS2_LOOKUP_LINK_FOLLOW, NULL); if (ret == -PVFS_ENOENT) { PVFS_sysresp_getparent gp_resp; printf("IO-TEST: lookup failed; creating new file.\n"); memset(&gp_resp, 0, sizeof(PVFS_sysresp_getparent)); ret = PVFS_sys_getparent(fs_id, name, &credentials, &gp_resp, NULL); if (ret < 0) { PVFS_perror("PVFS_sys_getparent failed", ret); return ret; } attr.owner = credentials.uid; attr.group = credentials.gid; attr.perms = PVFS_U_WRITE | PVFS_U_READ; attr.atime = attr.ctime = attr.mtime = time(NULL); attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; parent_refn = gp_resp.parent_ref; entry_name = rindex(name, (int)'/'); assert(entry_name); entry_name++; assert(entry_name); ret = PVFS_sys_create(entry_name, parent_refn, attr, &credentials, NULL, &resp_cr, NULL, NULL); if (ret < 0) { PVFS_perror("PVFS_sys_create() failure", ret); return (-1); } pinode_refn.fs_id = fs_id; pinode_refn.handle = resp_cr.ref.handle; } else { printf("IO-TEST: lookup succeeded; performing I/O on " "existing file.\n"); pinode_refn.fs_id = fs_id; pinode_refn.handle = resp_lk.ref.handle; } /************************************************************** * carry out I/O operation */ printf("IO-TEST: performing write on handle: %ld, fs: %d\n", (long) pinode_refn.handle, (int) pinode_refn.fs_id); buffer = io_buffer; buffer_size = io_size * sizeof(int); /* file datatype is tiled, so we can get away with a trivial type here */ file_req = PVFS_BYTE; ret = PVFS_Request_contiguous(io_size * sizeof(int), PVFS_BYTE, &(mem_req)); if (ret < 0) { PVFS_perror("PVFS_request_contiguous failure", ret); return (-1); } ret = PVFS_sys_write(pinode_refn, file_req, 0, buffer, mem_req, &credentials, &resp_io, NULL); if (ret < 0) { PVFS_perror("PVFS_sys_write failure", ret); return (-1); } printf("IO-TEST: wrote %d bytes.\n", (int) resp_io.total_completed); /* uncomment and try out the readback-and-verify stuff that follows * once reading back actually works */ memset(io_buffer, 0, io_size * sizeof(int)); /* verify */ printf("IO-TEST: performing read on handle: %ld, fs: %d\n", (long) pinode_refn.handle, (int) pinode_refn.fs_id); ret = PVFS_sys_read(pinode_refn, file_req, 0, buffer, mem_req, &credentials, &resp_io, NULL); if (ret < 0) { PVFS_perror("PVFS_sys_read failure", ret); return (-1); } printf("IO-TEST: read %d bytes.\n", (int) resp_io.total_completed); if ((io_size * sizeof(int)) != resp_io.total_completed) { fprintf(stderr, "Error: SHORT READ! skipping verification...\n"); } else { errors = 0; for (i = 0; i < io_size; i++) { if (i != io_buffer[i]) { fprintf(stderr, "error: element %d differs: should be %d, is %d\n", i, i, io_buffer[i]); errors++; } } if (errors != 0) { fprintf(stderr, "ERROR: found %d errors\n", errors); } else { printf("IO-TEST: no errors found.\n"); } } /* test out some of the mgmt functionality */ ret = PVFS_sys_getattr(pinode_refn, PVFS_ATTR_SYS_ALL_NOSIZE, &credentials, &resp_getattr, NULL); if (ret < 0) { PVFS_perror("PVFS_sys_getattr", ret); return (-1); } printf("Target file had %d datafiles:\n", resp_getattr.attr.dfile_count); dfile_array = (PVFS_handle *) malloc(resp_getattr.attr.dfile_count * sizeof(PVFS_handle)); if (!dfile_array) { perror("malloc"); return (-1); } ret = PVFS_mgmt_get_dfile_array(pinode_refn, &credentials, dfile_array, resp_getattr.attr.dfile_count, NULL); if (ret < 0) { PVFS_perror("PVFS_mgmt_get_dfile_array", ret); return (-1); } for (i = 0; i < resp_getattr.attr.dfile_count; i++) { printf("%llu\n", llu(dfile_array[i])); } /************************************************************** * shut down pending interfaces */ ret = PVFS_sys_finalize(); if (ret < 0) { fprintf(stderr, "Error: PVFS_sys_finalize() failed with errcode = %d\n", ret); return (-1); } free(filename); free(io_buffer); return (0); }