Ejemplo n.º 1
0
int
do_test (int argc, char *argv[])
{
  struct aiocb64 cbs[10];
  struct aiocb64 cbs_fsync;
  struct aiocb64 *cbp[10];
  struct aiocb64 *cbp_fsync[1];
  char buf[1000];
  size_t cnt;
  int result = 0;

  /* Preparation.  */
  for (cnt = 0; cnt < 10; ++cnt)
    {
      cbs[cnt].aio_fildes = fd;
      cbs[cnt].aio_reqprio = 0;
      cbs[cnt].aio_buf = memset (&buf[cnt * 100], '0' + cnt, 100);
      cbs[cnt].aio_nbytes = 100;
      cbs[cnt].aio_offset = cnt * 100;
      cbs[cnt].aio_sigevent.sigev_notify = SIGEV_NONE;

      cbp[cnt] = &cbs[cnt];
    }

  /* First a simple test.  */
  for (cnt = 10; cnt > 0; )
    if (aio_write64 (cbp[--cnt]) < 0 && errno == ENOSYS)
      {
	error (0, 0, "no aio support in this configuration");
	return 0;
      }
  /* Wait 'til the results are there.  */
  result |= do_wait (cbp, 10, 0);
  /* Test this.  */
  result |= test_file (buf, sizeof (buf), fd, "aio_write");

  /* Read now as we've written it.  */
  memset (buf, '\0', sizeof (buf));
  /* Issue the commands.  */
  for (cnt = 10; cnt > 0; )
    {
      --cnt;
      cbp[cnt] = &cbs[cnt];
      aio_read64 (cbp[cnt]);
    }
  /* Wait 'til the results are there.  */
  result |= do_wait (cbp, 10, 0);
  /* Test this.  */
  for (cnt = 0; cnt < 1000; ++cnt)
    if (buf[cnt] != '0' + (cnt / 100))
      {
	result = 1;
	error (0, 0, "comparison failed for aio_read test");
	break;
      }

  if (cnt == 1000)
    puts ("aio_read test ok");

  /* Remove the test file contents.  */
  if (ftruncate64 (fd, 0) < 0)
    {
      error (0, errno, "ftruncate failed\n");
      result = 1;
    }

  /* Test lio_listio.  */
  for (cnt = 0; cnt < 10; ++cnt)
    {
      cbs[cnt].aio_lio_opcode = LIO_WRITE;
      cbp[cnt] = &cbs[cnt];
    }
  /* Issue the command.  */
  lio_listio64 (LIO_WAIT, cbp, 10, NULL);
  /* ...and immediately test it since we started it in wait mode.  */
  result |= test_file (buf, sizeof (buf), fd, "lio_listio (write)");

  /* Test aio_fsync.  */
  cbs_fsync.aio_fildes = fd;
  cbs_fsync.aio_sigevent.sigev_notify = SIGEV_NONE;
  cbp_fsync[0] = &cbs_fsync;

  /* Remove the test file contents first.  */
  if (ftruncate64 (fd, 0) < 0)
    {
      error (0, errno, "ftruncate failed\n");
      result = 1;
    }

  /* Write again.  */
  for (cnt = 10; cnt > 0; )
    aio_write64 (cbp[--cnt]);

  if (aio_fsync64 (O_SYNC, &cbs_fsync) < 0)
    {
      error (0, errno, "aio_fsync failed\n");
      result = 1;
    }
  result |= do_wait (cbp_fsync, 1, 0);

  /* ...and test since all data should be on disk now.  */
  result |= test_file (buf, sizeof (buf), fd, "aio_fsync (aio_write)");

  /* Test aio_cancel.  */
  /* Remove the test file contents first.  */
  if (ftruncate64 (fd, 0) < 0)
    {
      error (0, errno, "ftruncate failed\n");
      result = 1;
    }

  /* Write again.  */
  for (cnt = 10; cnt > 0; )
    aio_write64 (cbp[--cnt]);

  /* Cancel all requests.  */
  if (aio_cancel64 (fd, NULL) == -1)
    printf ("aio_cancel64 (fd, NULL) cannot cancel anything\n");

  result |= do_wait (cbp, 10, ECANCELED);

  /* Another test for aio_cancel.  */
  /* Remove the test file contents first.  */
  if (ftruncate64 (fd, 0) < 0)
    {
      error (0, errno, "ftruncate failed\n");
      result = 1;
    }

  /* Write again.  */
  for (cnt = 10; cnt > 0; )
    {
      --cnt;
      cbp[cnt] = &cbs[cnt];
      aio_write64 (cbp[cnt]);
    }
  puts ("finished3");

  /* Cancel all requests.  */
  for (cnt = 10; cnt > 0; )
    if (aio_cancel64 (fd, cbp[--cnt]) == -1)
      /* This is not an error.  The request can simply be finished.  */
      printf ("aio_cancel64 (fd, cbp[%Zd]) cannot be canceled\n", cnt);
  puts ("finished2");

  result |= do_wait (cbp, 10, ECANCELED);

  puts ("finished");

  return result;
}
Ejemplo n.º 2
0
static STATUS
DI_force(
    DI_IO	*f,
    DI_OP	*diop,
    CL_ERR_DESC	*err_code)
{

    STATUS	big_status = OK, small_status = OK, intern_status = OK;
    register DI_SLAVE_CB	*disl;

    do
    {
        if (Di_slave)
	{
	    disl = diop->di_evcb;
	    disl->file_op = DI_SL_SYNC;
	    /* Send file properties to slave */
	    FPROP_COPY(f->io_fprop,disl->io_fprop);

	    DI_slave_send( disl->dest_slave_no, diop,
			   &big_status, &small_status, &intern_status);

	    if (big_status != OK )
	        break;

	    if ( small_status == OK )
	    {
	        if ((small_status = disl->status) != OK )
	        {
		    STRUCT_ASSIGN_MACRO(disl->errcode, *err_code);
		}
	    }
	}
	else
	{
	    /* 
	    ** put code in here for fsync issues 
	    */
#ifdef xCL_ASYNC_IO
            if( Di_async_io)
	    {
                DI_AIOCB *aio;
                aio=DI_get_aiocb();
#ifdef dr6_us5
                aio->aio.aio_filedes=diop->di_fd;
#else
                aio->aio.aio_fildes=diop->di_fd;
#endif /* dr6_us5 */
#ifdef LARGEFILE64
                if(aio_fsync64( O_SYNC, &aio->aio))
#elif defined(any_aix)
                if(fsync( aio->aio.aio_fildes ))
#else
                if(aio_fsync( O_SYNC, &aio->aio))
#endif /* LARGEFILE64 */
                {
	        SETCLERR(err_code, 0, ER_fsync);
                    small_status = FAIL;
                    break;
                }
                else
                {
                    if( (small_status=CSsuspend( CS_DIOW_MASK, 0, 0) ) != OK)
                    {
                        DIlru_set_di_error( &small_status, err_code, 
				DI_LRU_CSSUSPEND_ERR, DI_GENERAL_ERR);
		        break;
                    }
#if defined(axp_osf) 
                    if (  (aio_error(&aio->aio)) != 0 )
#else
#ifdef LARGEFILE64
                    if (  (aio_error64(&aio->aio)) != 0 )
#else /* LARGEFILE64 */
                    if (  (aio_error(&aio->aio)) != 0 )
#endif /* LARGEFILE64 */
#endif
                    {
	                SETCLERR(err_code, 0, ER_fsync);
	                small_status = FAIL;
                        break;
                    }
                }
            }
            else 
#endif /* xCL_ASYNC_IO */
	    if (FSYNC(diop->di_fd) < 0)
	    {
#ifdef xCL_092_NO_RAW_FSYNC
		/* AIX returns EINVAL on character special files */
		if (errno != EINVAL) 
#endif /* xCL_092_NO_RAW_FSYNC */
		{
	            SETCLERR(err_code, 0, ER_fsync);
	            small_status = FAIL;
		}
	    }
	}

    } while (FALSE);

    if ( big_status != OK )
	small_status = big_status;

    if ( small_status != OK  )
        DIlru_set_di_error( &small_status, err_code, intern_status,
			    DI_GENERAL_ERR);

    return( small_status );
}