コード例 #1
0
ファイル: plfsunit.cpp プロジェクト: JumpinJimmy/plfs-core
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);
}
コード例 #2
0
ファイル: aiori-PLFS.c プロジェクト: johnbent/ior
/*
 * Open a file through the PLFS interface.
 * Opens both the container in RDWR and the object 
 * in whatever mode is necessary
 */
static void *PLFS_Open(char *testFileName, IOR_param_t * param)
{
    int rc;

    Plfs_fd *pfd = NULL;
    plfs_error_t pret;
    mode_t mode = 0666;
    int flags = 0;
    char *timer_type = NULL;

    if (param->open == WRITE) {
        flags = O_CREAT | O_WRONLY;
        if (!rank) flags |= O_TRUNC; // only 0 truncs
        timer_type = "plfs_open_write";
    } else {
        assert(param->open == READ);
        flags = O_RDONLY;
        timer_type = "plfs_open_read";
    }
        
    StartTimer();
    pret = plfs_open(&pfd, testFileName, flags, (pid_t)rank, mode, NULL);
    AddTimer(timer_type);
    PDEBUG(rank,"plfs_open %s: %d", testFileName, pret);
    if (pret == 0) {
        return (void*)pfd;
    } else {
        return NULL;
    }
}
コード例 #3
0
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);
}
コード例 #4
0
ファイル: plfsunit.cpp プロジェクト: JumpinJimmy/plfs-core
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);
}
コード例 #5
0
ファイル: plfsunit.cpp プロジェクト: JumpinJimmy/plfs-core
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);
}
コード例 #6
0
ファイル: plfsunit.cpp プロジェクト: JumpinJimmy/plfs-core
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);
}
コード例 #7
0
ファイル: fs_plfs_file_open.c プロジェクト: bureddy/ompi
/*
 *	file_open_plfs
 *
 *	Function:	- opens a new file
 *	Accepts:	- same arguments as MPI_File_open()
 *	Returns:	- Success if new file handle
 */
int
mca_fs_plfs_file_open (struct ompi_communicator_t *comm,
                     const char* filename,
                     int access_mode,
                     struct ompi_info_t *info,
                     mca_io_ompio_file_t *fh)
{
    int rank;
    int amode;
    int old_mask, perm;
    plfs_error_t plfs_ret;
    Plfs_fd *pfd = NULL;
    char wpath[1024];
    size_t len = sizeof(int);
    char key[] = "num_hostdirs";

    rank = ompi_comm_rank ( comm );

    getcwd( wpath, sizeof(wpath) );
    sprintf( wpath,"%s/%s",wpath,filename );

    if (OMPIO_PERM_NULL == fh->f_perm) {
        old_mask = umask(022);
        umask(old_mask);
        perm = old_mask ^ 0666;
    }
    else {
        perm = fh->f_perm;
    }

    amode = 0;

    if (access_mode & MPI_MODE_RDONLY)
        amode = amode | O_RDONLY;
    if (access_mode & MPI_MODE_WRONLY)
        amode = amode | O_WRONLY;
    if (access_mode & MPI_MODE_RDWR)
        amode = amode | O_RDWR;
    if (access_mode & MPI_MODE_EXCL) {
        if( is_plfs_path(wpath) == 1 ) { //the file already exists
	    return OMPI_ERROR;
	}
    }

    if (0 == rank) {
        /* MODE_CREATE and MODE_EXCL can only be set by one process */
        if (access_mode & MPI_MODE_CREATE)
	    amode = amode | O_CREAT;

	plfs_ret = plfs_open( &pfd, wpath, amode, 0, perm, NULL );
	fh->f_fs_ptr = pfd;
    }

    comm->c_coll.coll_bcast ( &plfs_ret, 1, MPI_INT, 0, comm, comm->c_coll.coll_bcast_module);
    if ( PLFS_SUCCESS != plfs_ret ) {
        return OMPI_ERROR;
    }

    if (0 != rank) {
        plfs_ret = plfs_open( &pfd, wpath, amode, 0, perm, NULL );
	if (PLFS_SUCCESS != plfs_ret) {
	    opal_output(0, "fs_plfs_file_open: Error in plfs_open:\n%s\n", strplfserr(plfs_ret));
	    return OMPI_ERROR;
	}
	else {
	    fh->f_fs_ptr = pfd;
	}
    }

    if (mca_fs_plfs_num_hostdir > 0) {
        plfs_ret = plfs_setxattr( pfd, &mca_fs_plfs_num_hostdir, key, len );
        if (PLFS_SUCCESS != plfs_ret) {
	    opal_output(0, "fs_plfs_file_open: Error in plfs_setxattr:\n%s\n", strplfserr(plfs_ret));
	    return OMPI_ERROR;
	}
    }
    return OMPI_SUCCESS;
}