diff --git a/ompi/mca/common/ompio/common_ompio_file_view.c b/ompi/mca/common/ompio/common_ompio_file_view.c index aeb3e2016c6..a1800192e92 100644 --- a/ompi/mca/common/ompio/common_ompio_file_view.c +++ b/ompi/mca/common/ompio/common_ompio_file_view.c @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2008-2019 University of Houston. All rights reserved. + * Copyright (c) 2008-2021 University of Houston. All rights reserved. * Copyright (c) 2017-2018 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved. @@ -72,6 +72,16 @@ int mca_common_ompio_set_view (ompio_file_t *fh, ptrdiff_t ftype_extent, lb, ub; ompi_datatype_t *newfiletype; + if ( (MPI_DISPLACEMENT_CURRENT == disp) && + (fh->f_amode & MPI_MODE_SEQUENTIAL) ) { + mca_sharedfp_base_module_t * shared_fp_base_module = fh->f_sharedfp; + if ( NULL == shared_fp_base_module ){ + opal_output(0, "No shared file pointer component found for this file. Can not execute\n"); + return OMPI_ERROR; + } + shared_fp_base_module->sharedfp_get_position(fh, &disp); + } + if ( NULL != fh->f_etype ) { ompi_datatype_destroy (&fh->f_etype); } @@ -167,7 +177,17 @@ int mca_common_ompio_set_view (ompio_file_t *fh, // File view is not a multiple of the etype. return MPI_ERR_ARG; } + + // make sure that displacement is not negative, which could + // lead to an illegal access. + if ( 0 < fh->f_iov_count && 0 > (off_t)fh->f_decoded_iov[0].iov_base ) { + // I think MPI_ERR_TYPE would be more appropriate, but + // this is the error code expected in a testsuite, so I just + // go with this. + return MPI_ERR_IO; + } + if( SIMPLE_PLUS == OMPIO_MCA_GET(fh, grouping_option) ) { fh->f_cc_size = get_contiguous_chunk_size (fh, 1); } diff --git a/ompi/mca/fbtl/posix/fbtl_posix.c b/ompi/mca/fbtl/posix/fbtl_posix.c index f557636acc8..90d4be49552 100644 --- a/ompi/mca/fbtl/posix/fbtl_posix.c +++ b/ompi/mca/fbtl/posix/fbtl_posix.c @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2008-2015 University of Houston. All rights reserved. + * Copyright (c) 2008-2021 University of Houston. All rights reserved. * Copyright (c) 2018 Cisco Systems, Inc. All rights reserved * Copyright (c) 2018 Research Organization for Information Science * and Technology (RIST). All rights reserved. @@ -127,14 +127,57 @@ bool mca_fbtl_posix_progress ( mca_ompio_request_t *req) if ( EINPROGRESS == data->aio_req_status[i] ) { data->aio_req_status[i] = aio_error ( &data->aio_reqs[i]); if ( 0 == data->aio_req_status[i]){ - data->aio_open_reqs--; - lcount++; /* assuming right now that aio_return will return ** the number of bytes written/read and not an error code, ** since aio_error should have returned an error in that ** case and not 0 ( which means request is complete) */ - data->aio_total_len += aio_return (&data->aio_reqs[i]); + ssize_t ret2 = aio_return (&data->aio_reqs[i]); + data->aio_total_len += ret2; + if ( data->aio_reqs[i].aio_nbytes != (size_t)ret2 ) { + /* Partial completion */ + data->aio_reqs[i].aio_offset += ret2; + data->aio_reqs[i].aio_buf = (char*)data->aio_reqs[i].aio_buf + ret2; + data->aio_reqs[i].aio_nbytes -= ret2; + data->aio_reqs[i].aio_reqprio = 0; + data->aio_reqs[i].aio_sigevent.sigev_notify = SIGEV_NONE; + data->aio_req_status[i] = EINPROGRESS; + start_offset = data->aio_reqs[i].aio_offset; + total_length = data->aio_reqs[i].aio_nbytes; + if ( data->aio_req_type == FBTL_POSIX_WRITE ) { + ret_code = mca_fbtl_posix_lock( &data->aio_lock, data->aio_fh, F_WRLCK, start_offset, total_length, OMPIO_LOCK_ENTIRE_REGION ); + if ( 0 < ret_code ) { + opal_output(1, "mca_fbtl_posix_progress: error in mca_fbtl_posix_lock() %d", ret_code); + /* Just in case some part of the lock actually succeeded. */ + mca_fbtl_posix_unlock ( &data->aio_lock, data->aio_fh ); + return OMPI_ERROR; + } + if (-1 == aio_write(&data->aio_reqs[i])) { + opal_output(1, "mca_fbtl_posix_progress: error in aio_write()"); + mca_fbtl_posix_unlock ( &data->aio_lock, data->aio_fh ); + return OMPI_ERROR; + } + } + else if ( data->aio_req_type == FBTL_POSIX_READ ) { + ret_code = mca_fbtl_posix_lock( &data->aio_lock, data->aio_fh, F_RDLCK, start_offset, total_length, OMPIO_LOCK_ENTIRE_REGION ); + if ( 0 < ret_code ) { + opal_output(1, "mca_fbtl_posix_progress: error in mca_fbtl_posix_lock() %d", ret_code); + /* Just in case some part of the lock actually succeeded. */ + mca_fbtl_posix_unlock ( &data->aio_lock, data->aio_fh ); + return OMPI_ERROR; + } + if (-1 == aio_read(&data->aio_reqs[i])) { + opal_output(1, "mca_fbtl_posix_progress: error in aio_read()"); + mca_fbtl_posix_unlock ( &data->aio_lock, data->aio_fh ); + return OMPI_ERROR; + } + mca_fbtl_posix_unlock ( &data->aio_lock, data->aio_fh ); + } + } + else { + data->aio_open_reqs--; + lcount++; + } } else if ( EINPROGRESS == data->aio_req_status[i]){ /* not yet done */ diff --git a/ompi/mca/io/ompio/io_ompio_file_set_view.c b/ompi/mca/io/ompio/io_ompio_file_set_view.c index 30542b00cdb..5340370faa5 100644 --- a/ompi/mca/io/ompio/io_ompio_file_set_view.c +++ b/ompi/mca/io/ompio/io_ompio_file_set_view.c @@ -77,7 +77,14 @@ int mca_io_ompio_file_set_view (ompi_file_t *fp, file pointer, once for the shared file pointer (if it is existent) */ fh = &data->ompio_fh; - + + if ( MPI_DISPLACEMENT_CURRENT == disp && + !(fh->f_amode & MPI_MODE_SEQUENTIAL ) ) { + // MPI_DISPLACEMENT_CURRENT is only valid if amode is MPI_MODE_SEQUENTIAL + return MPI_ERR_DISP; + } + + OPAL_THREAD_LOCK(&fp->f_lock); ret = mca_common_ompio_set_view(fh, disp, etype, filetype, datarep, info); OPAL_THREAD_UNLOCK(&fp->f_lock);