/*
 *	file_set_size_pvfs2
 *
 *	Function:	- set_size of a file
 *	Accepts:	- same arguments as MPI_File_set_size()
 *	Returns:	- Success if size is set
 */
int
mca_fs_pvfs2_file_set_size (mca_io_ompio_file_t *fh,
                            OMPI_MPI_OFFSET_TYPE size)
{
    int ret;
    mca_fs_pvfs2 *pvfs2_fs;

    pvfs2_fs = (mca_fs_pvfs2 *)fh->f_fs_ptr;

    if (OMPIO_ROOT == fh->f_rank) {
        ret = PVFS_sys_truncate(pvfs2_fs->object_ref,
                                size, &(pvfs2_fs->credentials));
        fh->f_comm->c_coll.coll_bcast (&ret,
                                       1,
                                       MPI_INT,
                                       OMPIO_ROOT,
                                       fh->f_comm,
                                       fh->f_comm->c_coll.coll_bcast_module);
    } 
    else {
        fh->f_comm->c_coll.coll_bcast (&ret,
                                       1,
                                       MPI_INT,
                                       OMPIO_ROOT,
                                       fh->f_comm,
                                       fh->f_comm->c_coll.coll_bcast_module);
    }

    if (ret != 0) {
        return OMPI_ERROR;
    }

    return OMPI_SUCCESS;
}
/* as with ADIOI_PVFS2_Flush, implement the resize operation in a scalable
 * manner. one process does the work, then broadcasts the result to everyone
 * else.  fortunately, this operation is defined to be collective */
void ADIOI_PVFS2_Resize(ADIO_File fd, ADIO_Offset size, int *error_code)
{
    int ret, rank;
    ADIOI_PVFS2_fs *pvfs_fs;
    static char myname[] = "ADIOI_PVFS2_RESIZE";

    *error_code = MPI_SUCCESS;

    pvfs_fs = (ADIOI_PVFS2_fs*)fd->fs_ptr;

    MPI_Comm_rank(fd->comm, &rank);

    /* We desginate one node in the communicator to be an 'io_worker' in 
     * ADIO_Open.  This node can perform operations on files and then 
     * inform the other nodes of the result */

    /* MPI-IO semantics treat conflicting MPI_File_set_size requests the
     * same as conflicting write requests. Thus, a resize from one
     * process does not have to be visible to the other processes until a
     * syncronization point is reached */

    if (rank == fd->hints->ranklist[0]) {
	ret = PVFS_sys_truncate(pvfs_fs->object_ref, 
		size, &(pvfs_fs->credentials));
	MPI_Bcast(&ret, 1, MPI_INT, fd->hints->ranklist[0], fd->comm);
    } else  {
	MPI_Bcast(&ret, 1, MPI_INT, fd->hints->ranklist[0], fd->comm);
    }
    /* --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_truncate", 0);
	return;
    }
    /* --END ERROR HANDLING-- */
}
Beispiel #3
0
/**
 * PVFSIOStore::Truncate: truncate a file.
 *
 * @param path the file to truncate
 * @param the length (only 0 supported)
 * @return PLFS_SUCCESS or PLFS_E* on error
 */
plfs_error_t PVFSIOStore::Truncate(const char* path, off_t length) {
    char *cpath;
    PVFS_object_ref ref;
    PVFS_credentials creds;
    int nev, pev;

    cpath = pvfsios_dedup_slash(path);
    if (cpath) {
        nev = pvfsios_get_object(this->fsid, (char *)path, &ref, &creds,
                                 PVFS2_LOOKUP_LINK_FOLLOW);
        free(cpath);
    } else {
        nev = -ENOMEM;
    }
    
    if (nev < 0) {
        return errno_to_plfs_error(-nev);
    }

    pev = PVFS_sys_truncate(ref, length, &creds);
    nev = get_err(pev);
    return errno_to_plfs_error(-nev);
}
Beispiel #4
0
/**
 * PVFSIOSHandle::Ftruncate: truncate an open file.
 *
 * @param length the new length
 * @return PLFS_SUCCESS or PLFS_E*
 */
plfs_error_t PVFSIOSHandle::Ftruncate(off_t length) {
    int pev;

    pev = PVFS_sys_truncate(this->ref, length, &this->creds);
    return errno_to_plfs_error(-(get_err(pev)));
}
Beispiel #5
0
static int test_truncat(int testcase)
{
    int ret, fs_id;
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_look;
    PVFS_size size = 0, oldsize = 0;
    PVFS_sysresp_getattr resp;
    uint32_t attrmask;
    char *filename;

    attrmask = PVFS_ATTR_SYS_ALL_NOSIZE;

    filename = (char *) malloc(sizeof(char) * 100);
    filename = strcpy(filename, "altrun");

    PVFS_util_gen_credentials(&credentials);

    if (initialize_sysint() < 0)
    {
        debug_printf("UNABLE TO INIT THE SYSTEM INTERFACE\n");
        return -1;
    }
    fs_id = pvfs_helper.fs_id;

    /* get file */
    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);
    }
    if((ret = PVFS_sys_getattr(resp_look.ref, attrmask, &credentials, &resp)) < 0)
	return ret;

    oldsize = resp.attr.size;

    switch(testcase)
    {
    case 0:
	size = 1000000;
	ret = PVFS_sys_truncate(resp_look.ref, size, &credentials);
	break;
    case 1:
	size = 100000;
	ret = PVFS_sys_truncate(resp_look.ref, size, &credentials);
	break;
    case 2:
	size = 5;
	ret = PVFS_sys_truncate(resp_look.ref, size, &credentials);
	break;
    }

    /* get file */
    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);
    }
    if((ret = PVFS_sys_getattr(resp_look.ref, attrmask, &credentials, &resp)) < 0)
	return ret;

    if(resp.attr.size != (oldsize - size))
    {
	return -1;
    }
    return 0;
}