-:    0:Source:/home/MPI/testing/mpich2/mpich2/src/mpi/romio/adio/ad_nfs/ad_nfs_iwrite.c
        -:    0:Graph:ad_nfs_iwrite.gcno
        -:    0:Data:-
        -:    0:Runs:0
        -:    0:Programs:0
        -:    1:/* -*- Mode: C; c-basic-offset:4 ; -*- */
        -:    2:/* 
        -:    3: *   Copyright (C) 1997 University of Chicago. 
        -:    4: *   See COPYRIGHT notice in top-level directory.
        -:    5: */
        -:    6:
        -:    7:#include "ad_nfs.h"
        -:    8:
        -:    9:#include "../../mpi-io/mpioimpl.h"
        -:   10:#include "../../mpi-io/mpioprof.h"
        -:   11:#include "mpiu_greq.h"
        -:   12:
        -:   13:#include <string.h>
        -:   14:
        -:   15:#ifdef ROMIO_HAVE_WORKING_AIO
        -:   16:static MPIX_Grequest_class ADIOI_GEN_greq_class = 0;
        -:   17:/* this routine is nearly identical to ADIOI_GEN_IwriteContig, except we lock
        -:   18: * around I/O */
        -:   19:void ADIOI_NFS_IwriteContig(ADIO_File fd, void *buf, int count, 
        -:   20:                MPI_Datatype datatype, int file_ptr_type,
        -:   21:                ADIO_Offset offset, ADIO_Request *request, int *error_code)  
    #####:   22:{
        -:   23:    int len, typesize;
    #####:   24:    int aio_errno = 0;
        -:   25:    static char myname[] = "ADIOI_NFS_IWRITECONTIG";
        -:   26:
    #####:   27:    MPI_Type_size(datatype, &typesize);
    #####:   28:    len = count * typesize;
        -:   29:
    #####:   30:    if (file_ptr_type == ADIO_INDIVIDUAL) offset = fd->fp_ind;
    #####:   31:    aio_errno = ADIOI_NFS_aio(fd, buf, len, offset, 1, request);
    #####:   32:    if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += len;
        -:   33:
    #####:   34:    fd->fp_sys_posn = -1;
        -:   35:
    #####:   36:    if (aio_errno != 0) {
        -:   37:	/* --BEGIN ERROR HANDLING-- */
    #####:   38:	MPIO_ERR_CREATE_CODE_ERRNO(myname, aio_errno, error_code);
    #####:   39:	return;
        -:   40:	/* --END ERROR HANDLING-- */
        -:   41:    }
    #####:   42:    else *error_code = MPI_SUCCESS;
    #####:   43:    return;
        -:   44:}
        -:   45:#endif
        -:   46:
        -:   47:/* This function is for implementation convenience. It is not user-visible.
        -:   48: * It takes care of the differences in the interface for nonblocking I/O
        -:   49: * on various Unix machines! If wr==1 write, wr==0 read.
        -:   50: *
        -:   51: * Returns 0 on success, -errno on failure.
        -:   52: */
        -:   53:#ifdef ROMIO_HAVE_WORKING_AIO
        -:   54:int ADIOI_NFS_aio(ADIO_File fd, void *buf, int len, ADIO_Offset offset,
        -:   55:		  int wr, MPI_Request *request)
    #####:   56:{
    #####:   57:    int err=-1, fd_sys;
        -:   58:    int error_code, this_errno;
        -:   59:
        -:   60:    struct aiocb *aiocbp;
        -:   61:    ADIOI_AIO_Request *aio_req;
        -:   62:
    #####:   63:    fd_sys = fd->fd_sys;
        -:   64:
    #####:   65:    aio_req = (ADIOI_AIO_Request*)ADIOI_Calloc(sizeof(ADIOI_AIO_Request), 1);
    #####:   66:    aiocbp = (struct aiocb *) ADIOI_Calloc(sizeof(struct aiocb), 1);
    #####:   67:    aiocbp->aio_offset = offset;
    #####:   68:    aiocbp->aio_buf    = buf;
    #####:   69:    aiocbp->aio_nbytes = len;
        -:   70:
        -:   71:#ifdef ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_WHENCE
        -:   72:    aiocbp->aio_whence = SEEK_SET;
        -:   73:#endif
        -:   74:#ifdef ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_FILDES
    #####:   75:    aiocbp->aio_fildes = fd_sys;
        -:   76:#endif
        -:   77:#ifdef ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_SIGEVENT
        -:   78:# ifdef AIO_SIGNOTIFY_NONE
        -:   79:    aiocbp->aio_sigevent.sigev_notify = SIGEV_NONE;
        -:   80:# endif
    #####:   81:    aiocbp->aio_sigevent.sigev_signo = 0;
        -:   82:#endif
        -:   83:#ifdef ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_REQPRIO
        -:   84:# ifdef AIO_PRIO_DFL
        -:   85:    aiocbp->aio_reqprio = AIO_PRIO_DFL;   /* not needed in DEC Unix 4.0 */
        -:   86:# else
    #####:   87:    aiocbp->aio_reqprio = 0;
        -:   88:# endif
        -:   89:#endif
        -:   90:
    #####:   91:    if (wr) ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
    #####:   92:    else ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
        -:   93:
        -:   94:#ifndef ROMIO_HAVE_AIO_CALLS_NEED_FILEDES
    #####:   95:    if (wr) err = aio_write(aiocbp);
    #####:   96:    else err = aio_read(aiocbp);
        -:   97:#else
        -:   98:    /* Broken IBM interface */
        -:   99:    if (wr) err = aio_write(fd_sys, aiocbp);
        -:  100:    else err = aio_read(fd_sys, aiocbp);
        -:  101:#endif
        -:  102:
    #####:  103:    this_errno = errno;
    #####:  104:    ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
        -:  105:
    #####:  106:    if (err == -1) {
    #####:  107:	if (this_errno == EAGAIN) {
        -:  108:        /* exceeded the max. no. of outstanding requests.
        -:  109:           complete all previous async. requests and try again. */
    #####:  110:	    ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
        -:  111:			    offset, NULL, &error_code);
    #####:  112:	    MPIO_Completed_request_create(&fd, len, &error_code, request);
    #####:  113:	    return 0;
        -:  114:	} else {
    #####:  115:	    return -this_errno;
        -:  116:	}
        -:  117:    }
    #####:  118:    aio_req->aiocbp = aiocbp;
    #####:  119:    if (ADIOI_GEN_greq_class == 0) {
    #####:  120:	    MPIX_Grequest_class_create(ADIOI_GEN_aio_query_fn, 
        -:  121:			    ADIOI_GEN_aio_free_fn, MPIU_Greq_cancel_fn, 
        -:  122:			    ADIOI_GEN_aio_poll_fn, ADIOI_GEN_aio_wait_fn, 
        -:  123:			    &ADIOI_GEN_greq_class);
        -:  124:    }
    #####:  125:    MPIX_Grequest_class_allocate(ADIOI_GEN_greq_class, aio_req, request);
    #####:  126:    memcpy(&(aio_req->req), request, sizeof(MPI_Request));
    #####:  127:    return 0;
        -:  128:}
        -:  129:#endif