static int test_files_as_dirs(int testcase) { int ret = 1, fs_id; PVFS_sys_attr attr; PVFS_credentials credentials; PVFS_sysresp_lookup resp_look; PVFS_sysresp_create resp_create; char *filename; filename = (char *) malloc(sizeof(char) * 100); filename = strcpy(filename, "name"); PVFS_util_gen_credentials(&credentials); attr.mask = PVFS_ATTR_SYS_ALL_NOSIZE; attr.owner = credentials.uid; attr.group = credentials.gid; attr.perms = 1877; attr.atime = attr.mtime = attr.ctime = 0xdeadbeef; if (initialize_sysint() < 0) { debug_printf("UNABLE TO INIT THE SYSTEM INTERFACE\n"); return -1; } fs_id = pvfs_helper.fs_id; switch(testcase) { case 0: /* get root */ ret = PVFS_sys_lookup(fs_id, "/", &credentials, &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW); if (ret < 0) { printf("Lookup failed with errcode = %d\n", ret); return (-1); } ret = PVFS_sys_create("foo", resp_look.ref, attr, &credentials, NULL, NULL, &resp_create); /* get root */ ret = PVFS_sys_lookup(fs_id, "/foo", &credentials, &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW); if (ret < 0) { printf("Lookup failed with errcode = %d\n", ret); return (-1); } ret = PVFS_sys_create("bar", resp_look.ref, attr, &credentials, NULL, NULL, &resp_create); break; case 1: /* Need to add some more interesting cases */ break; } return ret; }
/* Preconditions: none * Parameters: testcase - the test case that is checked for this function * Postconditions: returns error code of readdir * Has 2 test cases */ static int test_create(void) { int ret, fs_id; PVFS_sys_attr attr; PVFS_credentials credentials; PVFS_sysresp_lookup resp_look; PVFS_sysresp_create resp_create; char *filename; ret = -2; filename = (char *) malloc(sizeof(char) * 100); filename = strcpy(filename, "name"); PVFS_util_gen_credentials(&credentials); attr.owner = credentials.uid; attr.group = credentials.gid; attr.perms = 1877; attr.atime = attr.ctime = attr.mtime = time(NULL); fs_id = 9; ret = PVFS_sys_lookup(fs_id, "/", &credentials, &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW); if (ret < 0) { printf("Lookup failed with errcode = %d\n", ret); return (-1); } ret = PVFS_sys_create(filename, resp_look.ref, attr, &credentials, NULL, NULL, &resp_create); return ret; }
int generic_open(file_object *obj, PVFS_credentials *credentials, int nr_datafiles, PVFS_size strip_size, char *srcname, int open_type) { struct stat stat_buf; PVFS_sysresp_lookup resp_lookup; PVFS_sysresp_getattr resp_getattr; PVFS_sysresp_create resp_create; PVFS_object_ref parent_ref; PVFS_sys_dist *new_dist; int ret = -1; char *entry_name; /* name of the pvfs2 file */ char str_buf[PVFS_NAME_MAX]; /* basename of pvfs2 file */ if (obj->fs_type == UNIX_FILE) { memset(&stat_buf, 0, sizeof(struct stat)); stat(obj->u.ufs.path, &stat_buf); if (open_type == OPEN_SRC) { if (S_ISDIR(stat_buf.st_mode)) { fprintf(stderr, "Source cannot be a directory\n"); return(-1); } obj->u.ufs.fd = open(obj->u.ufs.path, O_RDONLY); obj->u.ufs.mode = (int)stat_buf.st_mode; } else { if (S_ISDIR(stat_buf.st_mode)) { if (srcname) { strncat(obj->u.ufs.path, basename(srcname), NAME_MAX); } else { fprintf(stderr, "cannot find name for " "destination. giving up\n"); return(-1); } } obj->u.ufs.fd = open(obj->u.ufs.path, O_WRONLY|O_CREAT|O_LARGEFILE|O_TRUNC,0666); } if (obj->u.ufs.fd < 0) { perror("open"); fprintf(stderr, "could not open %s\n", obj->u.ufs.path); return (-1); } } else { entry_name = str_buf; /* it's a PVFS2 file */ if (strcmp(obj->u.pvfs2.pvfs2_path, "/") == 0) { /* special case: PVFS2 root file system, so stuff the end of * srcfile onto pvfs2_path */ char *segp = NULL, *prev_segp = NULL; void *segstate = NULL; /* can only perform this special case if we know srcname */ if (srcname == NULL) { fprintf(stderr, "unable to guess filename in " "toplevel PVFS2\n"); return -1; } memset(&resp_lookup, 0, sizeof(PVFS_sysresp_lookup)); ret = PVFS_sys_lookup(obj->u.pvfs2.fs_id, obj->u.pvfs2.pvfs2_path, credentials, &resp_lookup, PVFS2_LOOKUP_LINK_FOLLOW, hints); if (ret < 0) { PVFS_perror("PVFS_sys_lookup", ret); return (-1); } parent_ref.handle = resp_lookup.ref.handle; parent_ref.fs_id = resp_lookup.ref.fs_id; while (!PINT_string_next_segment(srcname, &segp, &segstate)) { prev_segp = segp; } entry_name = prev_segp; /* see... points to basename of srcname */ } else /* given either a pvfs2 directory or a pvfs2 file */ { /* get the absolute path on the pvfs2 file system */ /*parent_ref.fs_id = obj->pvfs2.fs_id; */ if (PINT_remove_base_dir(obj->u.pvfs2.pvfs2_path,str_buf, PVFS_NAME_MAX)) { if(obj->u.pvfs2.pvfs2_path[0] != '/') { fprintf(stderr, "Error: poorly formatted path.\n"); } fprintf(stderr, "Error: cannot retrieve entry name for " "creation on %s\n", obj->u.pvfs2.user_path); return(-1); } ret = PINT_lookup_parent(obj->u.pvfs2.pvfs2_path, obj->u.pvfs2.fs_id, credentials, &parent_ref.handle); if (ret < 0) { PVFS_perror("PVFS_util_lookup_parent", ret); return (-1); } else /* parent lookup succeeded. if the pvfs2 path is just a directory, use basename of src for the new file */ { int len = strlen(obj->u.pvfs2.pvfs2_path); if (obj->u.pvfs2.pvfs2_path[len - 1] == '/') { char *segp = NULL, *prev_segp = NULL; void *segstate = NULL; if (srcname == NULL) { fprintf(stderr, "unable to guess filename\n"); return(-1); } while (!PINT_string_next_segment(srcname, &segp, &segstate)) { prev_segp = segp; } strncat(obj->u.pvfs2.pvfs2_path, prev_segp, PVFS_NAME_MAX); entry_name = prev_segp; } parent_ref.fs_id = obj->u.pvfs2.fs_id; } } memset(&resp_lookup, 0, sizeof(PVFS_sysresp_lookup)); ret = PVFS_sys_ref_lookup(parent_ref.fs_id, entry_name, parent_ref, credentials, &resp_lookup, PVFS2_LOOKUP_LINK_FOLLOW, hints); if ((ret == 0) && (open_type == OPEN_SRC)) { memset(&resp_getattr, 0, sizeof(PVFS_sysresp_getattr)); ret = PVFS_sys_getattr(resp_lookup.ref, PVFS_ATTR_SYS_ALL_NOHINT, credentials, &resp_getattr, hints); if (ret) { fprintf(stderr, "Failed to do pvfs2 getattr on %s\n", entry_name); return -1; } if (resp_getattr.attr.objtype == PVFS_TYPE_SYMLINK) { free(resp_getattr.attr.link_target); resp_getattr.attr.link_target = NULL; } obj->u.pvfs2.perms = resp_getattr.attr.perms; memcpy(&obj->u.pvfs2.attr, &resp_getattr.attr, sizeof(PVFS_sys_attr)); obj->u.pvfs2.attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; } /* at this point, we have looked up the file in the parent directory. * . If we found something, and we are the SRC, then we're done. * . We will maintain the semantic of pvfs2-import and refuse to * overwrite existing PVFS2 files, so if we found something, and we * are the DEST, then that's an error. * . Otherwise, we found nothing and we will create the destination. */ if (open_type == OPEN_SRC) { if (ret == 0) { obj->u.pvfs2.ref = resp_lookup.ref; return 0; } else { PVFS_perror("PVFS_sys_ref_lookup", ret); return (ret); } } if (open_type == OPEN_DEST) { if (ret == 0) { obj->u.pvfs2.ref = resp_lookup.ref; return 0; } else { memset(&stat_buf, 0, sizeof(struct stat)); /* preserve permissions doing a unix => pvfs2 copy */ stat(srcname, &stat_buf); make_attribs(&(obj->u.pvfs2.attr), credentials, nr_datafiles, (int)stat_buf.st_mode); if (strip_size > 0) { new_dist = PVFS_sys_dist_lookup("simple_stripe"); ret = PVFS_sys_dist_setparam(new_dist, "strip_size", &strip_size); if (ret < 0) { PVFS_perror("PVFS_sys_dist_setparam", ret); return -1; } } else { new_dist=NULL; } ret = PVFS_sys_create(entry_name, parent_ref, obj->u.pvfs2.attr, credentials, new_dist, &resp_create, NULL, hints); if (ret < 0) { PVFS_perror("PVFS_sys_create", ret); return -1; } obj->u.pvfs2.ref = resp_create.ref; } } } return 0; }
static void fake_an_open(PVFS_fs_id id, const char *pvfs2_name, int access_mode, int stripe_width, PVFS_size stripe_size, mca_fs_pvfs2 *pvfs2_fs, open_status *o_status) { int ret; PVFS_sysresp_lookup resp_lookup; PVFS_sysresp_getparent resp_getparent; PVFS_sysresp_create resp_create; PVFS_sys_attr attribs; PVFS_sys_dist *dist; memset(&attribs, 0, sizeof(PVFS_sys_attr)); attribs.owner = geteuid(); attribs.group = getegid(); attribs.perms = 0644; attribs.mask = PVFS_ATTR_SYS_ALL_SETABLE; attribs.atime = time(NULL); attribs.mtime = attribs.atime; attribs.ctime = attribs.atime; if (stripe_width > 0 ) { attribs.dfile_count = stripe_width; attribs.mask |= PVFS_ATTR_SYS_DFILE_COUNT; } dist = NULL; memset(&resp_lookup, 0, sizeof(resp_lookup)); memset(&resp_getparent, 0, sizeof(resp_getparent)); memset(&resp_create, 0, sizeof(resp_create)); ret = PVFS_sys_lookup(id, pvfs2_name, &(pvfs2_fs->credentials), &resp_lookup, PVFS2_LOOKUP_LINK_FOLLOW); if ( ret == (-PVFS_ENOENT)) { if (access_mode & MPI_MODE_CREATE) { ret = PVFS_sys_getparent(id, pvfs2_name, &(pvfs2_fs->credentials), &resp_getparent); if (ret < 0) { opal_output (1, "pvfs_sys_getparent returns with %d\n", ret); o_status->error = ret; return; } /* Set the distribution stripe size if specified */ if (0 < stripe_size) { /* Note that the distribution is hardcoded here */ dist = PVFS_sys_dist_lookup ("simple_stripe"); ret = PVFS_sys_dist_setparam (dist, "strip_size", &stripe_size); if (ret < 0) { opal_output (1, "pvfs_sys_dist_setparam returns with %d\n", ret); o_status->error = ret; } } /* Perform file creation */ ret = PVFS_sys_create(resp_getparent.basename, resp_getparent.parent_ref, attribs, &(pvfs2_fs->credentials), dist, &resp_create); /* #ifdef HAVE_PVFS2_CREATE_WITHOUT_LAYOUT ret = PVFS_sys_create(resp_getparent.basename, resp_getparent.parent_ref, attribs, &(pvfs2_fs->credentials), dist, &resp_create); #else ret = PVFS_sys_create(resp_getparent.basename, resp_getparent.parent_ref, attribs, &(pvfs2_fs->credentials), dist, NULL, &resp_create); #endif */ /* if many creates are happening in this directory, the earlier * sys_lookup may have returned ENOENT, but the sys_create could * return EEXISTS. That means the file has been created anyway, so * less work for us and we can just open it up and return the * handle */ if (ret == (-PVFS_EEXIST)) { ret = PVFS_sys_lookup(id, pvfs2_name, &(pvfs2_fs->credentials), &resp_lookup, PVFS2_LOOKUP_LINK_FOLLOW); if ( ret < 0 ) { o_status->error = ret; return; } o_status->error = ret; o_status->object_ref = resp_lookup.ref; return; } o_status->object_ref = resp_create.ref; } else { opal_output (10, "cannot create file without MPI_MODE_CREATE\n"); o_status->error = ret; return; } } else if (access_mode & MPI_MODE_EXCL) { /* lookup should not succeed if opened with EXCL */ o_status->error = -PVFS_EEXIST; return; } else { o_status->object_ref = resp_lookup.ref; } o_status->error = ret; return; }
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; }
static int pvfs_fuse_create(const char *path, mode_t mode) { int rc; PVFS_sys_attr attr; char directory[PVFS_NAME_MAX]; char filename[PVFS_SEGMENT_MAX]; pvfs_fuse_handle_t dir_pfh, *pfhp; PVFS_sysresp_create resp_create; get_path_components(path, filename, directory); /* this should fail */ rc = lookup( path, &dir_pfh, PVFS2_LOOKUP_LINK_FOLLOW ); if (rc == 0) return 0; rc = lookup( directory, &dir_pfh, PVFS2_LOOKUP_LINK_FOLLOW ); if ( rc < 0 ) return PVFS_ERROR_TO_ERRNO_N( rc ); /* Set attributes */ memset(&attr, 0, sizeof(PVFS_sys_attr)); attr.owner = dir_pfh.creds.uid; attr.group = dir_pfh.creds.gid; attr.perms = mode; attr.atime = time(NULL); attr.mtime = attr.atime; attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; attr.dfile_count = 0; rc = PVFS_sys_create(filename, dir_pfh.ref, attr, &dir_pfh.creds, NULL, &resp_create, PVFS_SYS_LAYOUT_DEFAULT, PVFS_HINT_NULL); if (rc) { /* FIXME * the PVFS2 server code returns a ENOENT instead of an EACCES * because it does a ACL lookup for the system.posix_acl_access * which returns a ENOENT from the TROVE DBPF and that error is * just passed up in prelude_check_acls (server/prelude.c). I'm * not sure that's the right thing to do. */ if ( rc == -PVFS_ENOENT ) { return -EACCES; } return PVFS_ERROR_TO_ERRNO_N( rc ); } pfhp = (pvfs_fuse_handle_t *)malloc( sizeof( pvfs_fuse_handle_t ) ); if (pfhp == NULL) { return -ENOMEM; } pfhp->ref = resp_create.ref; pfhp->creds = dir_pfh.creds; return 0; }
/** * PVFSIOStore::Open: open a file as per flags. * * @param bpath the path we are creating * @param flags read/write mode * @param mode desired permissions * @param res_store return class pointer to IOSHandle for the new file or null on error * @return PLFS_SUCCESS or PLFS_E* on error */ plfs_error_t PVFSIOStore::Open(const char *bpath, int flags, mode_t mode, class IOSHandle **res_store) { plfs_error_t rv; char *cpath; PVFS_object_ref ref; PVFS_credentials creds; int nev, pev, dhs; char *node, *parent; PVFS_sys_attr attr; PVFS_sysresp_create resp; class PVFSIOSHandle *hand; cpath = pvfsios_dedup_slash(bpath); if (cpath == NULL) { *res_store = NULL; return PLFS_ENOMEM; } nev = pvfsios_get_object(this->fsid, (char *)cpath, &ref, &creds, PVFS2_LOOKUP_LINK_FOLLOW); if (nev < 0) { if (nev != -ENOENT || (flags & O_CREAT) == 0) { goto error; } /* try and create the file now */ nev = pvfsios_get_node_and_parent(&this->fsid, cpath, &ref, &creds, &node, &parent); if (nev < 0) { /* can happen if parent directory not present */ goto error; } /* must free parent */ memset(&attr, 0, sizeof(attr)); attr.owner = creds.uid; attr.group = creds.gid; attr.perms = mode; attr.atime = time(NULL); attr.mtime = attr.atime; attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; attr.dfile_count = 0; pev = PVFS_sys_create(node, ref, attr, &creds, NULL, &resp); free(parent); if (pev < 0) { /* pvfs2fuse says to do this w/ENOENT for now */ if (pev == -PVFS_ENOENT) { nev = -EACCES; goto error; } nev = get_err(pev); goto error; } /* now update ref/creds for newly created object */ nev = pvfsios_get_object(this->fsid, (char *)cpath, &ref, &creds, PVFS2_LOOKUP_LINK_FOLLOW); if (nev < 0) { goto error; } } /* * XXXCDC: seems like we should check access permissions here * rather than waiting for an i/o attempt. (e.g. trying to * open a file for writing that you cannot write should give * an error). */ if (flags & O_TRUNC) { rv = this->Truncate(cpath, 0); if (rv != PLFS_SUCCESS) { *res_store = NULL; free(cpath); return rv; } } hand = new PVFSIOSHandle(ref, creds, dhs); if (hand == NULL) { nev = -ENOMEM; goto error; } if (dhs < 0) { nev = -EIO; goto error; } free(cpath); *res_store = hand; return PLFS_SUCCESS; error: *res_store = NULL; free(cpath); return errno_to_plfs_error(-nev); }
/* steps for getting a handle: (it gets a little convoluted, but at least * it's deterministic) * . lookup the file. * . if lookup succeeds, but we were passed MPI_MODE_EXCL, that's an error * . if lookup fails, the file might not exist. * in that case, create the file if we were passed MPI_MODE_CREATE * . if the create fails, that means someone else created the file between * our call to lookup and our call to create (like if N processors all * open the same file with MPI_COMM_SELF) * * the good news is that only one processor does this and broadcasts the * handle to everyone else in the communicator */ static void fake_an_open(PVFS_fs_id fs_id, char *pvfs_name, int access_mode, int nr_datafiles, int strip_size, ADIOI_PVFS2_fs *pvfs2_fs, open_status *o_status) { int ret; PVFS_sysresp_lookup resp_lookup; PVFS_sysresp_getparent resp_getparent; PVFS_sysresp_create resp_create; PVFS_sys_attr attribs; PVFS_sys_dist* dist; ADIOI_PVFS2_makeattribs(&attribs); if (nr_datafiles > 0 ) { attribs.dfile_count = nr_datafiles; attribs.mask |= PVFS_ATTR_SYS_DFILE_COUNT; } dist = NULL; memset(&resp_lookup, 0, sizeof(resp_lookup)); memset(&resp_getparent, 0, sizeof(resp_getparent)); memset(&resp_create, 0, sizeof(resp_create)); ret = PVFS_sys_lookup(fs_id, pvfs_name, &(pvfs2_fs->credentials), &resp_lookup, PVFS2_LOOKUP_LINK_FOLLOW); if ( (ret < 0) ) { /* XXX: check what the error was */ if (access_mode & ADIO_CREATE) { ret = PVFS_sys_getparent(fs_id, pvfs_name, &(pvfs2_fs->credentials), &resp_getparent); if (ret < 0) { FPRINTF(stderr, "pvfs_sys_getparent returns with %d\n", ret); o_status->error = ret; return; } /* Set the distribution strip size if specified */ if (0 < strip_size) { /* Note that the distribution is hardcoded here */ dist = PVFS_sys_dist_lookup("simple_stripe"); ret = PVFS_sys_dist_setparam(dist, "strip_size", &strip_size); if (ret < 0) { FPRINTF(stderr, "pvfs_sys_dist_setparam returns with %d\n", ret); o_status->error = ret; } } /* Perform file creation */ ret = PVFS_sys_create(resp_getparent.basename, resp_getparent.parent_ref, attribs, &(pvfs2_fs->credentials), dist, &resp_create); if (ret < 0) { /* XXX: should only do this for EEXISTS */ ret = PVFS_sys_lookup(fs_id, pvfs_name, &(pvfs2_fs->credentials), &resp_lookup, PVFS2_LOOKUP_LINK_FOLLOW); if ( ret < 0 ) { o_status->error = ret; return; } o_status->error = ret; o_status->object_ref = resp_lookup.ref; return; } o_status->object_ref = resp_create.ref; } else { FPRINTF(stderr, "cannot create file without MPI_MODE_CREATE\n"); o_status->error = ret; return; } } else if (access_mode & ADIO_EXCL) { /* lookup should not succeed if opened with EXCL */ o_status->error = -1; /* XXX: what should it be? */ return; } else { o_status->object_ref = resp_lookup.ref; } o_status->error = ret; return; }
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); }
static int init_files(void) { int ret, fs_id; PVFS_sys_attr attr; PVFS_credentials credentials; PVFS_sysresp_lookup resp_look; PVFS_sysresp_create resp_create; char *filename; filename = (char *) malloc(sizeof(char) * 100); filename = strcpy(filename, "name"); PVFS_util_gen_credentials(&credentials); attr.mask = PVFS_ATTR_SYS_ALL_NOSIZE; attr.owner = credentials.uid; attr.group = credentials.gid; attr.perms = 1877; attr.atime = attr.mtime = attr.ctime = 0xdeadbeef; if (initialize_sysint() < 0) { debug_printf("UNABLE TO INIT THE SYSTEM INTERFACE\n"); return -1; } fs_id = pvfs_helper.fs_id; /* get root */ ret = PVFS_sys_lookup(fs_id, "/", &credentials, &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW); if (ret < 0) { printf("Lookup failed with errcode = %d\n", ret); return (-1); } ret = PVFS_sys_create(filename, resp_look.ref, attr, &credentials, NULL, NULL, &resp_create); /* create sparse file */ filename = strcpy(filename, "sparse"); ret = PVFS_sys_create(filename, resp_look.ref, attr, &credentials, NULL, NULL, &resp_create); /* create a file for testing alocate and truncate*/ filename = strcpy(filename, "altrun"); ret = PVFS_sys_create(filename, resp_look.ref, attr, &credentials, NULL, NULL, &resp_create); filename = strcpy(filename, "invalid_perms"); credentials.uid = 444; credentials.gid = 444; if (initialize_sysint() < 0) { debug_printf("UNABLE TO INIT THE SYSTEM INTERFACE\n"); return -1; } fs_id = pvfs_helper.fs_id; /* get root */ ret = PVFS_sys_lookup(fs_id, "/", &credentials, &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW); if (ret < 0) { printf("Lookup failed with errcode = %d\n", ret); return (-1); } return PVFS_sys_create(filename, resp_look.ref, attr, &credentials, NULL, NULL, &resp_create); }