void PlfsUnit::readWriteTest() { string path = mountpoint + "/readwrite1"; const char *pathname = path.c_str(); Plfs_fd *fd = NULL; plfs_error_t ret; ssize_t written; #ifdef NEGATIVE_TEST_CASES ret = plfs_open(&fd, pathname, O_CREAT | O_RDONLY, pid, 0666, NULL); CPPUNIT_ASSERT_EQUAL(0, (int)ret); CPPUNIT_ASSERT(fd); ret = plfs_write(fd, "HELLO WORLD.", 13, 0, pid, &written); CPPUNIT_ASSERT_EQUAL(PLFS_EBADF, ret); ret = plfs_close(fd, pid, uid, 0, NULL, &ref_count); CPPUNIT_ASSERT_EQUAL(0, (int)ret); fd = NULL; #endif ret = plfs_open(&fd, pathname, O_CREAT | O_RDWR, pid, 0666, NULL); CPPUNIT_ASSERT_EQUAL(0, (int)ret); CPPUNIT_ASSERT(fd); for (int i = 0; i < 10; i++) { char rbuf[13]; for (pid_t fpid = 0; fpid < 10; fpid ++) { off_t offset=rand(); ret = plfs_write(fd, "HELLO WORLD.", 13, offset, fpid, &written); CPPUNIT_ASSERT_EQUAL(13, (int)written); ret = plfs_sync(fd); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_read(fd, rbuf, 13, offset, &written); CPPUNIT_ASSERT_EQUAL(13, (int)written); CPPUNIT_ASSERT(strcmp(rbuf, "HELLO WORLD.") == 0); } } ret = plfs_close(fd, pid, uid, 0, NULL, &ref_count); CPPUNIT_ASSERT_EQUAL(0, (int)ret); fd = NULL; for (int i = 0; i < 10; i++) { char rbuf[13]; for (pid_t fpid = 0; fpid < 10; fpid ++) { off_t offset=rand(); ret = plfs_open(&fd, pathname, O_CREAT | O_RDWR, fpid, 0666, NULL); CPPUNIT_ASSERT_EQUAL(0, (int)ret); CPPUNIT_ASSERT(fd); ret = plfs_write(fd, "HELLO WORLD.", 13, offset, fpid, &written); CPPUNIT_ASSERT_EQUAL(13, (int)written); ret = plfs_sync(fd); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_read(fd, rbuf, 13, offset, &written); CPPUNIT_ASSERT_EQUAL(13, (int)written); CPPUNIT_ASSERT(strcmp(rbuf, "HELLO WORLD.") == 0); ret = plfs_close(fd, fpid, uid, 0, NULL, &ref_count); CPPUNIT_ASSERT_EQUAL(0, (int)ret); fd = NULL; } } ret = plfs_unlink(pathname); CPPUNIT_ASSERT_EQUAL(0, (int)ret); }
int main (int argc, char **argv) { const char *target; plfs_error_t ret; Plfs_fd *fd; int nr; if (argc > 1) { target = argv[1]; } else { return -1; } plfs_handle_version_arg(argc, argv[1]); fd = NULL; ret = plfs_open(&fd, target, O_RDONLY, getpid(), 0777, NULL); if (ret != PLFS_SUCCESS) { fprintf(stderr, "Couldn't open path %s\n", target); exit(1); } ret = fd->optimize_access(); if (ret != PLFS_SUCCESS) { fprintf(stderr, "optimize_access: flattenIndex of %s failed (%s)\n", target, strplfserr(ret)); } else { printf("Successfully flattened index of %s\n",target); } (void) plfs_close(fd, getpid(), getuid(), O_RDONLY, NULL, &nr); exit(( ret == PLFS_SUCCESS) ? 0 : 1); }
void PlfsUnit::truncateTest() { string path = mountpoint + "/trunctest1"; const char *pathname = path.c_str(); Plfs_fd *fd = NULL; plfs_error_t ret; struct stat stbuf; ssize_t written; ret = plfs_open(&fd, pathname, O_CREAT | O_RDWR, pid, 0666, NULL); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_write(fd, "SIMPLE_TRUNCATE_TEST", 21, 0, pid, &written); CPPUNIT_ASSERT_EQUAL(21, (int)written); ret = plfs_trunc(fd, pathname, 15, true); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_getattr(fd, pathname, &stbuf, 1); CPPUNIT_ASSERT_EQUAL(0, (int)ret); CPPUNIT_ASSERT(stbuf.st_size == 15); ret = plfs_close(fd, pid, uid, 0, NULL, &ref_count); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_trunc(NULL, pathname, 5, true); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_getattr(NULL, pathname, &stbuf, 1); CPPUNIT_ASSERT_EQUAL(0, (int)ret); CPPUNIT_ASSERT(stbuf.st_size == 5); ret = plfs_unlink(pathname); CPPUNIT_ASSERT_EQUAL(0, (int)ret); }
/* * Close a file through the PLFS interface. */ static void PLFS_Close(void *fd, IOR_param_t * param) { Plfs_fd *pfd = (Plfs_fd*)fd; plfs_error_t pret; int flags; int open_handles; uid_t uid = getuid(); flags = ( param->open == READ ? O_RDONLY : O_CREAT | O_WRONLY ); pret = plfs_close(pfd, rank, uid, flags, NULL, &open_handles); assert(open_handles==0); PDEBUG(rank,"plfs_close: %d",pret); PLFS_DIE_ON_ERROR("plfs_close",pret); }
void PlfsUnit::openCloseTest() { plfs_error_t ret; string path = mountpoint + "/openclosetest1"; const char *pathname = path.c_str(); string path2 = mountpoint + "/nonexist"; const char *nonexist = path2.c_str(); Plfs_fd *fd = NULL; ret = plfs_create(pathname, 0666, 0, pid); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_open(&fd, pathname, 0, pid, 0666, NULL); CPPUNIT_ASSERT_EQUAL(0, (int)ret); CPPUNIT_ASSERT(fd); ret = plfs_open(&fd, pathname, 0, 0, 0666, NULL); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_close(fd, pid, uid, 0, NULL, &ref_count); CPPUNIT_ASSERT_EQUAL(1, ref_count); ret = plfs_close(fd, pid, uid, 0, NULL, &ref_count); CPPUNIT_ASSERT_EQUAL(0, ref_count); ret = plfs_unlink(pathname); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_access(pathname, F_OK); CPPUNIT_ASSERT_EQUAL(PLFS_ENOENT, ret); fd = NULL; ret = plfs_open(&fd, nonexist, 0, pid, 0666, NULL); CPPUNIT_ASSERT_EQUAL(PLFS_ENOENT, ret); CPPUNIT_ASSERT(fd == NULL); ret = plfs_open(&fd, pathname, O_CREAT, pid, 0666, NULL); CPPUNIT_ASSERT_EQUAL(0, (int)ret); CPPUNIT_ASSERT(fd); ret = plfs_unlink(pathname); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_access(pathname, F_OK); CPPUNIT_ASSERT_EQUAL(PLFS_ENOENT, ret); ret = plfs_close(fd, pid, uid, 0, NULL, &ref_count); CPPUNIT_ASSERT_EQUAL(0, (int)ret); }
//Returns the number of references to the Plfs_fd remaining after the close int UPC_ADIO_Close ( Plfs_fd *fd, int open_flags, int *error_code ) { int err; uid_t uid; uid = getuid(); err = plfs_close( fd , (uint32_t) MYTHREAD, uid, open_flags, NULL); upc_barrier; *error_code = UPC_ADIO_SUCCESS; return err; }
void PlfsUnit::symlinkTest() { string path = mountpoint + "/symlinktest1"; const char *pathname = path.c_str(); string path2 = mountpoint + "/symlinktest2"; const char *pathname2 = path2.c_str(); plfs_error_t ret; Plfs_fd *fd = NULL; ret = plfs_create(pathname, 0666, 0, pid); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_symlink(pathname, pathname2); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_open(&fd, pathname2, O_CREAT | O_RDWR, pid, 0666, NULL); CPPUNIT_ASSERT_EQUAL(0, (int)ret); CPPUNIT_ASSERT(fd); ret = plfs_close(fd, pid, uid, 0, NULL, &ref_count); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_unlink(pathname2); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_symlink("./nonexist.ne", pathname2); CPPUNIT_ASSERT_EQUAL(0, (int)ret); fd = NULL; ret = plfs_open(&fd, pathname2, O_RDWR, pid, 0666, NULL); CPPUNIT_ASSERT_EQUAL(PLFS_ENOENT, ret); ret = plfs_unlink(pathname2); CPPUNIT_ASSERT_EQUAL(0, (int)ret); for (int i = 0; i < 100; i++) { string linkcontent = "./noexist.ne"; char buf[256]; sprintf(buf, "%d", i); linkcontent += buf; ret = plfs_symlink(linkcontent.c_str(), pathname2); CPPUNIT_ASSERT_EQUAL(0, (int)ret); plfs_readlink(pathname2, buf, 256, (int *)&ret); CPPUNIT_ASSERT((int)linkcontent.length() == (int)ret); CPPUNIT_ASSERT(strcmp(linkcontent.c_str(), buf) == 0); ret = plfs_unlink(pathname2); CPPUNIT_ASSERT_EQUAL(0, (int)ret); } ret = plfs_unlink(pathname); CPPUNIT_ASSERT_EQUAL(0, (int)ret); }