/* Preconditions: none * Parameters: testcase - the test case that is checked for this function * Postconditions: returns error code of readdir * Has 2 tset cases */ static int test_remove(void) { PVFS_credentials credentials; PVFS_sysresp_lookup resp_look; char *filename; int ret; int fs_id; ret = -2; filename = (char *) malloc(sizeof(char) * 100); filename = strcpy(filename, "name"); PVFS_util_gen_credentials(&credentials); fs_id = 9; ret = PVFS_sys_lookup(fs_id, filename, &credentials, &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW); if (ret < 0) { printf("Lookup failed with errcode = %d\n", ret); return (-1); } ret = PVFS_sys_remove(filename, resp_look.ref, &credentials); return ret; }
void ADIOI_PVFS2_Delete(const char *filename, int *error_code) { PVFS_credentials credentials; PVFS_sysresp_getparent resp_getparent; int ret; PVFS_fs_id cur_fs; static char myname[] = "ADIOI_PVFS2_DELETE"; char pvfs_path[PVFS_NAME_MAX] = {0}; ADIOI_PVFS2_Init(error_code); /* --BEGIN ERROR HANDLING-- */ if (*error_code != MPI_SUCCESS) { /* ADIOI_PVFS2_INIT handles creating error codes itself */ return; } /* --END ERROR HANDLING-- */ /* in most cases we'll store the credentials in the fs struct, but we don't * have one of those in Delete */ ADIOI_PVFS2_makecredentials(&credentials); /* given the filename, figure out which pvfs filesystem it is on */ ret = PVFS_util_resolve(filename, &cur_fs, pvfs_path, PVFS_NAME_MAX); /* --BEGIN ERROR HANDLING-- */ if (ret != 0) { *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, ADIOI_PVFS2_error_convert(ret), "Error in PVFS_util_resolve", 0); return; } /* --END ERROR HANDLING-- */ ret = PVFS_sys_getparent(cur_fs, pvfs_path, &credentials, &resp_getparent); ret = PVFS_sys_remove(resp_getparent.basename, resp_getparent.parent_ref, &credentials); /* --BEGIN ERROR HANDLING-- */ if (ret != 0) { *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, ADIOI_PVFS2_error_convert(ret), "Error in PVFS_sys_remove", 0); return; } /* --END ERROR HANDLING-- */ *error_code = MPI_SUCCESS; return; }
/* * simple helper to remove a pvfs2 file * * returns 0 on success. * -1 if some error happened. */ int remove_file(PVFS_object_ref parent_refn, char *name) { int ret = -1; PVFS_credentials credentials; PVFS_util_gen_credentials(&credentials); ret = PVFS_sys_remove(name, parent_refn, &credentials); if (ret < 0) { printf("remove failed\n"); return ret; } return 0; }
/** * pvfsios_remove: remove a file or directory * * @param fsidp target filesystem * @param path file or directory to remove * @return 0 or -err */ static int pvfsios_remove(PVFS_fs_id *fsidp, const char *path) { int nev, pev; PVFS_object_ref ref; PVFS_credentials creds; char *node, *parent; nev = pvfsios_get_node_and_parent(fsidp, path, &ref, &creds, &node, &parent); if (nev < 0) { return(nev); } pev = PVFS_sys_remove(node, ref, &creds); nev = get_err(pev); free(parent); return(nev); }
static int pvfs_fuse_remove( const char *path ) { int rc; char parent[PVFS_NAME_MAX]; char filename[PVFS_SEGMENT_MAX]; pvfs_fuse_handle_t parent_pfh; get_path_components(path, filename, parent); lookup( parent, &parent_pfh, PVFS2_LOOKUP_LINK_FOLLOW ); rc = PVFS_sys_remove(filename, parent_pfh.ref, &parent_pfh.creds, PVFS_HINT_NULL); if (rc) { return PVFS_ERROR_TO_ERRNO_N( rc ); } return 0; }
/* * file_delete_pvfs2 * * Function: - deletes a file * Accepts: - file name & info * Returns: - Success if file closed */ int mca_fs_pvfs2_file_delete (char* file_name, struct ompi_info_t *info) { PVFS_credentials credentials; PVFS_sysresp_getparent resp_getparent; int ret; PVFS_fs_id pvfs2_id; char pvfs2_path[OMPIO_MAX_NAME] = {0}; char * ncache_timeout; if (!mca_fs_pvfs2_IS_INITIALIZED) { /* disable the pvfs2 ncache */ ncache_timeout = getenv("PVFS2_NCACHE_TIMEOUT"); if (ncache_timeout == NULL ) setenv("PVFS2_NCACHE_TIMEOUT", "0", 1); ret = PVFS_util_init_defaults(); if (ret < 0) { return OMPI_ERROR; } mca_fs_pvfs2_IS_INITIALIZED = 1; } memset (&credentials, 0, sizeof(PVFS_credentials)); PVFS_util_gen_credentials (&credentials); ret = PVFS_util_resolve(file_name, &pvfs2_id, pvfs2_path, OMPIO_MAX_NAME); if (ret != 0) { return OMPI_ERROR; } ret = PVFS_sys_getparent(pvfs2_id, pvfs2_path, &credentials, &resp_getparent); ret = PVFS_sys_remove(resp_getparent.basename, resp_getparent.parent_ref, &credentials); if (ret != 0) { return OMPI_ERROR; } return OMPI_SUCCESS; }
static int test_remove_nonempty_dir(int testcase) { PVFS_credentials credentials; PVFS_sysresp_lookup resp_look; char *filename; int ret; int fs_id; ret = -2; filename = (char *) malloc(sizeof(char) * 100); filename = strcpy(filename, "/"); PVFS_util_gen_credentials(&credentials); if (initialize_sysint() < 0) { debug_printf("UNABLE TO INIT SYSTEM INTERFACE\n"); return -1; } fs_id = pvfs_helper.fs_id; ret = PVFS_sys_lookup(fs_id, filename, &credentials, &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW); if (ret < 0) { printf("Lookup failed with errcode = %d\n", ret); return (-1); } switch (testcase) { case 0: ret = PVFS_sys_remove(NULL, resp_look.ref, &credentials); break; default: fprintf(stderr, "Error: invalid case number \n"); } 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 main(int argc, char * argv[]) { FILE * f; int ret; PVFS_fs_id curfs; PVFS_Request file_req; PVFS_Request mem_req; int count; char line[255]; int size; PVFS_offset offset=0; PVFS_credentials creds; PVFS_sysresp_create create_resp; PVFS_sysresp_io io_resp; PVFS_sysresp_lookup lookup_resp; PVFS_sys_attr attr; const char * filename = "test-accesses-file"; int j = 0, i = 0; char * membuff; char errormsg[255]; if(argc < 2) { fprintf(stderr, "test-accesses <sizes file>\n"); exit(1); } f = fopen(argv[1], "r"); if(!f) { fprintf(stderr, "error opening file\n"); return errno; } if(fgets(line, 255, f) == NULL) { fprintf(stderr, "error in file\n"); exit(1); } if(sscanf(line, "%d", &count) < 1) { fprintf(stderr, "error in file\n"); exit(1); } ret = PVFS_util_init_defaults(); if(ret < 0) goto error; ret = PVFS_util_get_default_fsid(&curfs); if(ret < 0) goto error; ret = PVFS_sys_lookup(curfs, "/", &creds, &lookup_resp, 0, NULL); if(ret < 0) goto error; PVFS_util_gen_credentials(&creds); attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; attr.owner = creds.uid; attr.group = creds.gid; attr.perms = 0644; attr.atime = attr.ctime = attr.mtime = time(NULL); ret = PVFS_sys_create( (char*)filename, lookup_resp.ref, attr, &creds, NULL, &create_resp, NULL, NULL); if(ret < 0) goto error; for(; i < count; ++i) { if(fgets(line, 255, f) == NULL) { fprintf(stderr, "error in file\n"); exit(1); } if(sscanf(line, "%d", &size) < 1) { fprintf(stderr, "error in file\n"); exit(1); } membuff = malloc(size); assert(membuff); for(j = 0; j < size; ++j) { membuff[j] = j; } ret = PVFS_Request_contiguous( size, PVFS_BYTE, &file_req); if(ret < 0) goto error; ret = PVFS_Request_contiguous( size, PVFS_BYTE, &mem_req); if(ret < 0) goto error; printf("Performing Write: offset: %llu, size: %d\n", llu(offset), size); ret = PVFS_sys_io( create_resp.ref, file_req, offset, membuff, mem_req, &creds, &io_resp, PVFS_IO_WRITE, NULL); if(ret < 0) goto error; printf("Write response: size: %llu\n", llu(io_resp.total_completed)); offset += size; PVFS_Request_free(&mem_req); PVFS_Request_free(&file_req); free(membuff); } return 0; error: fclose(f); PVFS_sys_remove( (char*)filename, lookup_resp.ref, &creds, NULL); PVFS_perror_gossip(errormsg, ret); fprintf(stderr, "%s\n", errormsg); return PVFS_get_errno_mapping(ret); }
int main(int argc, char **argv) { PVFS_error pvfs_error; int i; char test_file[PATH_MAX]; PVFS_sys_attr attr; PVFS_fs_id cur_fs; PVFS_credentials credentials; PVFS_sysresp_lookup lookup_resp; PVFS_sysresp_create create_resp; char basepath[PATH_MAX]; int rank, nprocs, ret; MPI_Info info; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); parse_args(argc, argv); /* provide hints if you want */ info = MPI_INFO_NULL; if (rank == 0) { printf("\nprocs: %d\nops: %d\n===========\n", nprocs, opt_nfiles); } ret = PVFS_util_init_defaults(); if(ret != 0) { PVFS_perror("PVFS_util_init_defaults", ret); return ret; } ret = PVFS_util_resolve(opt_basedir, &cur_fs, basepath, PATH_MAX); if(ret != 0) { PVFS_perror("PVFS_util_resolve", ret); return ret; } PVFS_util_gen_credentials(&credentials); pvfs_error = PVFS_sys_lookup( cur_fs, basepath, &credentials, &lookup_resp, PVFS2_LOOKUP_LINK_NO_FOLLOW); if(pvfs_error != 0) { PVFS_perror("PVFS_sys_lookup", pvfs_error); return PVFS_get_errno_mapping(pvfs_error); } 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); /* synchronize with other clients (if any) */ MPI_Barrier(MPI_COMM_WORLD); for(i = 0; i < opt_nfiles; ++i) { memset(test_file, 0, PATH_MAX); snprintf(test_file, PATH_MAX, "testfile.%d.%d", rank, i); test_util_start_timing(); pvfs_error = PVFS_sys_create(test_file, lookup_resp.ref, attr, &credentials, NULL, NULL, &create_resp); test_util_stop_timing(); if(pvfs_error != 0) { PVFS_perror("PVFS_sys_craete", pvfs_error); return PVFS_get_errno_mapping(pvfs_error); } test_util_print_timing(rank); } for(i = 0; i < opt_nfiles; ++i) { memset(test_file, 0, PATH_MAX); snprintf(test_file, PATH_MAX, "testfile.%d.%d", rank, i); pvfs_error = PVFS_sys_remove(test_file, lookup_resp.ref, &credentials); if(pvfs_error != 0) { fprintf(stderr, "Failed to remove: %s\n", test_file); PVFS_perror("PVFS_sys_remove", pvfs_error); return PVFS_get_errno_mapping(pvfs_error); } } MPI_Finalize(); return 0; }