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); }
/* * Use PLFS stat() to return aggregate file size of all objects moved */ static IOR_offset_t PLFS_GetFileSize(IOR_param_t * test, MPI_Comm testComm, char *testFileName) { struct stat stat_buf; IOR_offset_t aggFileSizeFromStat, tmpMin, tmpMax, tmpSum; plfs_error_t pret; pret = plfs_getattr(NULL, testFileName, &stat_buf, 1); PDEBUG(rank,"plfs_getattr %s : %lld\n", testFileName, stat_buf.st_size); aggFileSizeFromStat = stat_buf.st_size; if (test->filePerProc == TRUE) { MPI_CHECK(MPI_Allreduce(&aggFileSizeFromStat, &tmpSum, 1, MPI_LONG_LONG_INT, MPI_SUM, testComm), "cannot total data moved"); aggFileSizeFromStat = tmpSum; } else { MPI_CHECK(MPI_Allreduce(&aggFileSizeFromStat, &tmpMin, 1, MPI_LONG_LONG_INT, MPI_MIN, testComm), "cannot total data moved"); MPI_CHECK(MPI_Allreduce(&aggFileSizeFromStat, &tmpMax, 1, MPI_LONG_LONG_INT, MPI_MAX, testComm), "cannot total data moved"); if (tmpMin != tmpMax) { if (rank == 0) { WARN("inconsistent file size by different tasks"); } /* incorrect, but now consistent across tasks */ aggFileSizeFromStat = tmpMin; } } return (aggFileSizeFromStat); }
void PlfsUnit::chownTest() { string path = mountpoint + "/chowntest1"; const char *pathname = path.c_str(); plfs_error_t ret; ret = plfs_create(pathname, 0666, 0, pid); CPPUNIT_ASSERT_EQUAL(0, (int)ret); for (uid_t luid = 0; luid < 65536; luid += 1000) { for (gid_t lgid = 0; lgid < 65536; lgid += 1000) { struct stat stbuf; ret = plfs_chown(pathname, luid, lgid); if (uid != 0) { // not the root user. CPPUNIT_ASSERT_EQUAL(PLFS_EPERM, ret); goto unlinkout; } CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_getattr(NULL, pathname, &stbuf, 0); CPPUNIT_ASSERT_EQUAL(0, (int)ret); CPPUNIT_ASSERT_EQUAL(stbuf.st_uid, luid); CPPUNIT_ASSERT_EQUAL(stbuf.st_gid, lgid); } } ret = plfs_chown(pathname, uid, gid); CPPUNIT_ASSERT_EQUAL(0, (int)ret); unlinkout: ret = plfs_unlink(pathname); CPPUNIT_ASSERT_EQUAL(0, (int)ret); }