Exemple #1
0
static void rf_client_ver(void)
{
  CL_SLOT *cl = (CL_SLOT *)cur_slot;
  CARD8 msg[20];

  /* FIXME: Check protocol version. */

  /* FIXME: Functions like authentication should be available in
     separate modules, not in I/O part of the code. */
  /* FIXME: Higher level I/O functions should be implemented
     instead of things like buf_put_CARD32 + aio_write. */

  log_write(LL_DETAIL, "Client supports %.11s", cur_slot->readbuf);

  if (s_password[0]) {
    /* Request VNC authentication */
    buf_put_CARD32(msg, 2);

    /* Prepare "random" challenge */
    rfb_gen_challenge(cl->auth_challenge);
    memcpy(&msg[4], cl->auth_challenge, 16);

    /* Send both auth ID and challenge */
    aio_write(NULL, msg, 20);
    aio_setread(rf_client_auth, NULL, 16);
  } else {
    log_write(LL_WARN, "Not requesting authentication from %s",
              cur_slot->name);
    buf_put_CARD32(msg, 1);
    aio_write(NULL, msg, 4);
    aio_setread(rf_client_initmsg, NULL, 1);
  }
}
Exemple #2
0
static void send_new_cliprects(void)
{
  CL_SLOT *cl = (CL_SLOT *)cur_slot;
  CARD8 msg_hdr[4] = {
    0, 0, 0, 1
  };
  CARD8 rect_hdr[12];
  FB_RECT rect;

  crDebug("Sending new cliprects to proxy: %d, %d .. %d, %d",
          cl->new_clip_bounds.x1,
          cl->new_clip_bounds.y1,
          cl->new_clip_bounds.x2,
          cl->new_clip_bounds.y2);

  log_write(LL_DEBUG, "Sending NewCliprects (%dx%d) to %s",
            (int)cl->fb_width, (int)cl->fb_height, cur_slot->name);

  buf_put_CARD16(&msg_hdr[2], 1); /* one rect */
  aio_write(NULL, msg_hdr, 4);

  rect.x = cl->new_clip_bounds.x1;
  rect.y = cl->new_clip_bounds.y1;
  rect.w = cl->new_clip_bounds.x2 - cl->new_clip_bounds.x1;
  rect.h = cl->new_clip_bounds.y2 - cl->new_clip_bounds.y1;
  rect.enc = RFB_ENCODING_CLIPRECTS;

  put_rect_header(rect_hdr, &rect);
  aio_write(wf_client_update_finished, rect_hdr, 12);

  /* Something has been queued for sending. */
  cl->update_in_progress = 1;
  cl->update_requested = 0;
}
Exemple #3
0
static void send_newfbsize(void)
{
  CL_SLOT *cl = (CL_SLOT *)cur_slot;
  CARD8 msg_hdr[4] = {
    0, 0, 0, 1
  };
  CARD8 rect_hdr[12];
  FB_RECT rect;

  log_write(LL_DEBUG, "Sending NewFBSize update (%dx%d) to %s",
            (int)cl->fb_width, (int)cl->fb_height, cur_slot->name);

  buf_put_CARD16(&msg_hdr[2], 1);
  aio_write(NULL, msg_hdr, 4);

  rect.x = 0;
  rect.y = 0;
  rect.w = cl->fb_width;
  rect.h = cl->fb_height;
  rect.enc = RFB_ENCODING_NEWFBSIZE;

  put_rect_header(rect_hdr, &rect);
  aio_write(wf_client_update_finished, rect_hdr, 12);

  /* Something has been queued for sending. */
  cl->update_in_progress = 1;
  cl->update_requested = 0;
}
Exemple #4
0
static void rf_client_auth(void)
{
  CL_SLOT *cl = (CL_SLOT *)cur_slot;
  unsigned char resp_rw[16];
  unsigned char resp_ro[16];
  unsigned char msg[4];

  /* Place correct crypted responses to resp_rw, resp_ro */
  rfb_crypt(resp_rw, cl->auth_challenge, s_password);
  rfb_crypt(resp_ro, cl->auth_challenge, s_password_ro);

  /* Compare client response with correct ones */
  /* FIXME: Implement "too many tries" functionality some day. */
  if (memcmp(cur_slot->readbuf, resp_rw, 16) == 0) {
    cl->readonly = 0;
    log_write(LL_MSG, "Full-control authentication passed by %s",
              cur_slot->name);
  } else if (memcmp(cur_slot->readbuf, resp_ro, 16) == 0) {
    cl->readonly = 1;
    log_write(LL_MSG, "Read-only authentication passed by %s",
              cur_slot->name);
  } else {
    log_write(LL_WARN, "Authentication failed for %s", cur_slot->name);
    buf_put_CARD32(msg, 1);
    aio_write(wf_client_auth_failed, msg, 4);
    return;
  }

  buf_put_CARD32(msg, 0);
  aio_write(NULL, msg, 4);
  aio_setread(rf_client_initmsg, NULL, 1);
}
Exemple #5
0
IoObject *IoAsyncRequest_write(IoAsyncRequest *self, IoObject *locals, IoMessage *m)
{
	/*doc AsyncRequest write(fileOffset, aSeq, bufferOffset, numberOfBytesToWrite)
	Submits an async write request. Returns nil on error, self otherwise. 
	*/
	
	int r;
	IoSeq *data;
	UArray *ba;
	int bufferOffset;
	int bytesToWrite;

	IOCB(self)->aio_offset = (size_t)CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));

	data = IoMessage_locals_seqArgAt_(m, locals, 1);
	ba = IoSeq_rawUArray(data);

	bufferOffset = IoMessage_locals_intArgAt_(m, locals, 2);
	bytesToWrite = IoMessage_locals_intArgAt_(m, locals, 3);

	if (bytesToWrite > UArray_size(ba) - bufferOffset)
	{
		bytesToWrite = UArray_size(ba) - bufferOffset;
	}

	IOCB(self)->aio_nbytes = bytesToWrite;
	IOCB(self)->aio_buf = realloc(IOCB_BUFFER(self), bytesToWrite);
	memcpy(IOCB_BUFFER(self), UArray_bytes(ba), bytesToWrite);

	r = aio_write(IOCB(self));

	return r == 0 ? self : IONIL(self);
}
Exemple #6
0
void pass_cuttext_to_host(CARD8 *text, size_t len)
{
  AIO_SLOT *saved_slot = cur_slot;
  CARD8 client_cuttext_hdr[8] = {
    6, 0, 0, 0, 0, 0, 0, 0
  };

  if (s_host_slot != NULL) {
    buf_put_CARD32(&client_cuttext_hdr[4], (CARD32)len);

    cur_slot = s_host_slot;
    aio_write(NULL, client_cuttext_hdr, sizeof(client_cuttext_hdr));
    aio_write(NULL, text, len);
    cur_slot = saved_slot;
  }
}
Exemple #7
0
	void write(iterator sa, iterator se)
	{
		lock.lock();

		if ( high-low == numbuffers )
		{
			aiocb *waitlist[1] = { &contexts[low%numbuffers] };
			// std::cerr << "waiting for " << low << std::endl;
			aio_suspend (waitlist,1,0);
			low++;
		}
		
		u_int64_t const len = se-sa;
		// std::cerr << "writing " << s.size() << std::endl;

		buffers[high % numbuffers] = AutoArray<char>(len);
		std::copy ( sa, se, buffers[high%numbuffers].get() );
		memset ( &contexts[high%numbuffers], 0, sizeof(aiocb) );
		contexts[high%numbuffers].aio_fildes = fd;
		contexts[high%numbuffers].aio_buf = buffers[high % numbuffers].get();
		contexts[high%numbuffers].aio_nbytes = len;
		contexts[high%numbuffers].aio_offset = 0;
		contexts[high%numbuffers].aio_sigevent.sigev_notify = SIGEV_NONE;
		aio_write( & contexts[high%numbuffers] );		

		high++;		
		
		lock.unlock();
	}
Exemple #8
0
int
aioperf_aio_write(aioperf_io_task_t *io_task)
{
    aioperf_repository_t    *repository = NULL;
    aioperf_conf_info_t     *conf_info = NULL;
    unsigned long            left_size = 0;


    repository = io_task->repository;
    conf_info = repository->conf_info;
    left_size = io_task->file_size - io_task->offset;

    if (left_size > conf_info->buf_size) {
        io_task->aio_req.aio_nbytes = conf_info->buf_size;
    } else {
        io_task->aio_req.aio_nbytes = left_size;
    }

    io_task->aio_req.aio_fildes = io_task->fd;
    io_task->aio_req.aio_buf = io_task->repository->buf;
    io_task->aio_req.aio_offset = io_task->offset;
    
    io_task->aio_req.aio_sigevent.sigev_notify = SIGEV_THREAD;
    io_task->aio_req.aio_sigevent.sigev_notify_function = aioperf_aio_callback;
    io_task->aio_req.aio_sigevent.sigev_notify_attributes = NULL;
    io_task->aio_req.aio_sigevent.sigev_value.sival_ptr = io_task;
    
    if (aio_write(&io_task->aio_req) < 0) {
        printf("aio write error\n");
        return AIOPERF_ERROR;
    }

    return AIOPERF_OK;
}
Exemple #9
0
int main()
{
#define BUF_SIZE 512
	char buf[BUF_SIZE];
	struct aiocb aiocb;

#if _POSIX_ASYNCHRONOUS_IO != 200112L
	exit(PTS_UNSUPPORTED);
#endif

	memset(buf, 0xaa, BUF_SIZE);
	memset(&aiocb, 0, sizeof(struct aiocb));
	aiocb.aio_fildes = -1;
	aiocb.aio_buf = buf;
	aiocb.aio_nbytes = BUF_SIZE;

	if (aio_write(&aiocb) != -1)
	{
		printf(TNAME " bad aio_write return value()\n");
		exit(PTS_FAIL);
	}

	if (errno != EBADF)
	{
		printf(TNAME " errno is not EBADF %s\n", strerror(errno));
		exit(PTS_FAIL);
	}


	printf ("Test PASSED\n");
	return PTS_PASS;
}
void HostProxy_GadgetFS::send_data(__u8 endpoint,__u8 attributes,__u16 maxPacketSize,__u8* dataptr,int length) {
	if (!endpoint) {
		int rc=write(p_device_file,dataptr,length);
		if (rc<0) {
			fprintf(stderr,"Fail on EP00 write %d %s\n",errno,strerror(errno));
		} else {
			//fprintf(stderr,"Sent %d bytes on EP00\n",rc);
		}
		return;
	}
	if (!(endpoint & 0x80)) {
		fprintf(stderr,"trying to send %d bytes on an out EP%02x\n",length,endpoint);
		return;
	}
	int number=endpoint&0x0f;
	if (!p_epin_async[number]) {
		fprintf(stderr,"trying to send %d bytes on a non-open EP%02x\n",length,endpoint);
		return;
	}

	aiocb* aio=p_epin_async[number];
	aio->aio_buf=malloc(length);
	memcpy((void*)(aio->aio_buf),dataptr,length);
	aio->aio_nbytes=length;

	int rc=aio_write(aio);
	if (rc) {
		fprintf(stderr,"Error submitting aio for EP%02x %d %s\n",endpoint,errno,strerror(errno));
	} else {
		if (debugLevel > 2)
			std::cerr << "Submitted " << length << " bytes to gadgetfs EP" << std::hex << (unsigned)endpoint << std::dec << '\n';
		p_epin_active[number]=true;
	}
}
Exemple #11
0
void AioReadCompleteHandle(sigval_t v_sigval)
{
    AIO_PARA_S *pAio = (AIO_PARA_S *)v_sigval.sival_ptr;
    struct aiocb *pCb = &pAio->cb;
    int ret = 0;

    ret = aio_error(pCb);
    if (0 != ret)
    {
        printf("aio_error failed. [ret: %d]\n", ret);
        FreeResource(pAio, 1);
        return;
    }
    
    ret = aio_return(pCb);
    if (0 > ret)
    {
        printf("aio_return failed. [ret: %d]\n", ret);
        FreeResource(pAio, 1);
        return;
    }

    pCb->aio_nbytes = ret;
    pCb->aio_fildes = pAio->fdWr;
    pCb->aio_sigevent.sigev_notify_function = AioWriteCompleteHandle;
    
    ret = aio_write(pCb);
    if (0 > ret)
    {
        printf("aio_write failed. [ret: %d]\n", ret);
        FreeResource(pAio, 1);
    }

    return;
}
Exemple #12
0
static int init_pages()
{
    for (int i = 0; i < globals.addr_space_size; ++i)
    {
        if (pthread_mutex_init(&globals.metadata[i].lock, NULL) == ERROR)
            return ERROR;
        
        globals.metadata[i].page_index = i;
        globals.metadata[i].reference_counter = 0;
        globals.metadata[i].frame_number = -1;
        globals.metadata[i].modified = false;
    }
    for (int i = 0; i < globals.mem_size; ++i)
    {
        globals.pages[i].data = calloc(globals.page_size, sizeof(uint8_t));
        if (globals.pages[i].data == NULL)
            return ERROR;
        globals.metadata[i].frame_number = i;
        globals.pages[i].meta = &globals.metadata[i];
    }
    struct aiocb * aio_init_table[1];
    struct aiocb aio_init;
    aio_init_table[0] = &aio_init;
    aiocb_setup(&aio_init, 0, 0);
    for (int i = 0; i < globals.addr_space_size; ++i) {
        if (aio_write(&aio_init) == ERROR) return ERROR;
        if (aio_suspend((const struct aiocb * const *)aio_init_table, 1, NULL) 
            == ERROR)
            return ERROR;
    }
    return SUCCESS;
}
Exemple #13
0
/*
 * Request to stop a lockspace locally.
 *
 * Triggered by peer nodes.
 *
 * This can take a long time to complete, so use an asynchronous request.
 *
 * Essentially equivalent to:
 *
 *   echo 0 > /sys/kernel/dlm/<name>/control
 */
static void
stop_lockspace(struct lockspace *ls)
{
	struct lockspace_aio_request *ls_aio_req;
	struct aio_request *aio_req;

	ls->stopping |= node_mask(local_node);
	ls_aio_req = malloc(sizeof(*ls_aio_req));
	if (!ls_aio_req)
		fail(NULL);
	memset(ls_aio_req, 0, sizeof(*ls_aio_req));
	ls_aio_req->ls = ls;
	aio_req = &ls_aio_req->aio_req;
	aio_req->aiocb.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
	aio_req->aiocb.aio_sigevent.sigev_signo = SIGUSR1;
	aio_req->aiocb.aio_sigevent.sigev_value.sival_ptr = aio_req;
	aio_req->aiocb.aio_fildes = ls->control_fd;
	aio_req->aiocb.aio_nbytes = 1;
	aio_req->aiocb.aio_buf = "0";
	aio_req->complete = complete_stop_lockspace;
	list_add(&aio_req->list, &aio_pending);
	if (aio_write(&aio_req->aiocb) == 0)
		return;
	list_del(&aio_req->list);
	failf("%s/%s/control", DLM_SYSFS_DIR, ls->name);
}
Exemple #14
0
// Takes any char buffer, copies it into a Write struct, and
// enqueues the IO
void LogBase::writeCharBuffer(const char* buffer, uint32_t size)
{
    if (bytesWritten < FILE_MAX_SIZE) bytesWritten += size;

    // Add a new Write struct
    ongoingSizes.push_back(Write());
    Write* current = &ongoingSizes.back();

    // Copy in the buffer
    current->buffer = std::string(buffer, size);

    // Recommended by aio--zeroes the CB
    memset(&current->control, 0, sizeof(current->control));

    // Set up the CB
    current->control.aio_fildes = fileDescriptor;
    current->control.aio_buf = const_cast<char *>(current->buffer.data());
    current->control.aio_nbytes = size;
    current->control.aio_sigevent.sigev_notify = SIGEV_NONE;

    // Enqueue the write
    int result = aio_write(&current->control);

    // Make sure the write didn't immediately fail
    if (result == -1)
    {
        std::cout<< "AIO write enqueue failed with error " << strerror(errno)
                 << std::endl;
    }

#ifdef DEBUG_LOGGING
        std::cout << "Enqueued a char buffer for writing."
                  << std::endl;
#endif
}
Exemple #15
0
static struct aiocb *wrapper_aio(int fd,
    volatile char *buf,
    size_t bytes,
    off_t offset,
    int opcode) {

  struct aiocb *cb = (struct aiocb *)malloc(sizeof(struct aiocb));
  if (cb == NULL)
    return NULL;
  memset(cb, 0, sizeof(struct aiocb));
  cb->aio_nbytes = bytes;
  cb->aio_fildes = fd;
  cb->aio_offset = offset;
  cb->aio_buf = buf;
  int ret;
  switch (opcode) {
    case WORMUP_READ:
      if ((ret = aio_read(cb)) == -1) {
        free(cb);
        return NULL;
      }
      break;
    case WORMUP_WRITE:
      if ((ret = aio_write(cb)) == -1) {
        free(cb);
        return NULL;
      }
      break;
    default:
      return NULL;
  }
  return cb;
}
Exemple #16
0
/*
 * Completion of release_lockspace().
 */
static void
complete_release(struct aio_request *aio_req)
{
	struct dlm_write_request *req = (void *)aio_req->aiocb.aio_buf;
	struct lockspace *ls;

	for (ls = lockspaces; ls; ls = ls->next) {
		if (ls->minor == req->i.lspace.minor)
			break;
	}
	if (ls) {
		/*
		 * Lockspaces are reference counted in the kernel.  The first
		 * DLM_USER_CREATE_LOCKSPACE request creates a lockspace; the
		 * last DLM_USER_REMOVE_LOCKSPACE request removes it.  Continue
		 * removing the lockspace until it disappears.
		 */
		list_add(&aio_req->list, &aio_pending);
		if (aio_write(&aio_req->aiocb) == 0)
			return;
		list_del(&aio_req->list);
		fail(NULL);
	}
	free((void *)aio_req->aiocb.aio_buf);
	free(aio_req);
}
Exemple #17
0
/* ARGSUSED */
static void aiohandler(int signo, siginfo_t *info, void *context) {
    int  myerrno, mystatus, serrno;
    serrno = errno;
    myerrno = aio_error(&aiocb_read);
    if (myerrno == EINPROGRESS) {
        errno = serrno;
        return;
    }
    if (myerrno) {
        seterror(myerrno);
        errno = serrno;
        return;
    }
    mystatus = aio_return(&aiocb_read);
    totalbytes += mystatus;
    aiocb_read.aio_offset += mystatus;
    aiocb_write.aio_nbytes = mystatus;
    if (mystatus == 0)
        doneflag = 1;
    else if (aio_write(&aiocb_write) == -1)
        seterror(errno);
    else if (readstart() == -1)
        seterror(errno);
    errno = serrno;
}
Exemple #18
0
int 
lio_listio(int mode, struct aiocb *const apv[], int nent, 
	   struct sigevent *sigevp)
{
	int i;

#ifndef notyet
	if (sigevp &&
	    (sigevp->sigev_notify != SIGEV_NONE) &&
	    (sigevp->sigev_notify != SIGEV_THREAD))
		return (ENOSYS);
#endif

	for (i = 0; i < nent; i++)
		switch (apv[i]->aio_lio_opcode) {
		case LIO_READ:
			aio_read(apv[i]);
			break;
		case LIO_WRITE:
			aio_write(apv[i]);
			break;
		case LIO_NOP:
			break;
		}

	if (sigevp && 
	    (mode == LIO_NOWAIT)
	   ) {
		_aio_notify(sigevp);
	}

	return (0);
}
Exemple #19
0
int main()
{
	int		fd, ret;
	struct aiocb aio_wb;

	if ((fd = open(FILENAME, O_CREAT|O_RDWR, 0644)) == -1) {
		perror("open"); 
		exit(EXIT_FAILURE);
	}
	write(fd, TEST_MSG, sizeof(TEST_MSG)); 	/* data written by synchronous I/O API */
	memset(&aio_wb, 0, sizeof(struct aiocb));
	aio_wb.aio_fildes = fd;			/* operated file descript 	*/
	aio_wb.aio_buf = TEST_MSG;		/* buffer to write */
	aio_wb.aio_nbytes = sizeof(TEST_MSG);	/* number of bytes */
	aio_wb.aio_offset = 5;		/* start offset to write */
	aio_write(&aio_wb);			/* data written by asynchronous I/O API */
	while ((ret = aio_error(&aio_wb)) != 0) {
		if (ret == EINPROGRESS) {
			printf("aio_write has not been completed. sleep(1)\n");
			sleep(1);
		} else {
			printf("Error: aio_error = %d\n", ret);
			break;
		}
	}
	if ((ret = aio_return(&aio_wb)) == -1) {
		fprintf(stderr, "Err(aio_write) : %s\n", strerror(errno));
	}
	printf("> write complete: %d B\n", ret);
	fsync(fd);
	close(fd);
	return EXIT_SUCCESS;
}
Exemple #20
0
static int bs_paio_cmd_submit(struct scsi_cmd *cmd)
{
	struct scsi_lu *lu = cmd->dev;
	struct aiocb *io=NULL;
	int ret = 0;

	switch (cmd->scb[0]) {
	case SYNCHRONIZE_CACHE:
	case SYNCHRONIZE_CACHE_16:
		break;
	case WRITE_6:
	case WRITE_10:
	case WRITE_12:
	case WRITE_16:
		io=calloc(1, sizeof(*io)+sizeof(cmd));
		io->aio_fildes=lu->fd;
		io->aio_buf=scsi_get_out_buffer(cmd);
		io->aio_offset=cmd->offset;
		io->aio_nbytes=scsi_get_out_length(cmd);
		io->aio_sigevent.sigev_notify=SIGEV_THREAD;
		io->aio_sigevent.sigev_notify_function=paio_done;
		io->aio_sigevent.sigev_notify_attributes=NULL;
		io->aio_sigevent.sigev_value.sival_ptr=io;
		*(struct scsi_cmd **)(io+1)=cmd;
		ret=aio_write(io);
		if(ret==0){
			set_cmd_async(cmd);
			return 0;
		}
		break;
	case READ_6:
	case READ_10:
	case READ_12:
	case READ_16:
		io=calloc(1, sizeof(*io)+sizeof(cmd));
		io->aio_fildes=lu->fd;
		io->aio_buf=scsi_get_in_buffer(cmd);
		io->aio_offset=cmd->offset;
		io->aio_nbytes=scsi_get_in_length(cmd);
		io->aio_sigevent.sigev_notify=SIGEV_THREAD;
		io->aio_sigevent.sigev_notify_function=paio_done;
		io->aio_sigevent.sigev_notify_attributes=NULL;
		io->aio_sigevent.sigev_value.sival_ptr=io;
		*(struct scsi_cmd **)(io+1)=cmd;
		ret=aio_read(io);
		if(ret==0){
			set_cmd_async(cmd);
			return 0;
		}
		break;
	default:
		break;
	}
	if(ret!=0){
		sense_data_build(cmd, MEDIUM_ERROR, 0);
		ret = SAM_STAT_CHECK_CONDITION;
	}

	return ret;
}
			void write(iterator sa, iterator se)
			{
				lock.lock();

				// wait for free context if all buffers are in use
				if ( high-low == numbuffers )
				{
					aiocb *waitlist[1] = { &contexts[low%numbuffers] };
					aio_suspend (waitlist,1,0);
					low++;
				}
				
				uint64_t const len = se-sa;

				buffers[high % numbuffers] = ::libmaus::autoarray::AutoArray<char>(len);
				std::copy ( sa, se, buffers[high%numbuffers].get() );
				memset ( &contexts[high%numbuffers], 0, sizeof(aiocb) );
				contexts[high%numbuffers].aio_fildes = fd;
				contexts[high%numbuffers].aio_buf = buffers[high % numbuffers].get();
				contexts[high%numbuffers].aio_nbytes = len;
				contexts[high%numbuffers].aio_offset = 0;
				contexts[high%numbuffers].aio_sigevent.sigev_notify = SIGEV_NONE;
				aio_write( & contexts[high%numbuffers] );		

				high++;		
				
				lock.unlock();
			}
Exemple #22
0
int main()
{
	struct aiocb aiocb;

	if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
		return PTS_UNSUPPORTED;

	if (sysconf(_SC_PRIORITIZED_IO) < 200112L)
		return PTS_UNTESTED;

	memset(&aiocb, 0, sizeof(struct aiocb));
	aiocb.aio_reqprio = -1;

	if (aio_write(&aiocb) != -1)
	{
		printf(TNAME " aio_write should fail!\n");
		exit(PTS_FAIL);
	}

	if (errno != EINVAL)
	{
		printf(TNAME " errno should be EINVAL!\n");
		exit(PTS_FAIL);
	}

	printf ("Test PASSED\n");
	return PTS_PASS;
}
Exemple #23
0
static int write_to_swap(page_meta * swapped_meta)
{
    struct aiocb * aio_init_table[1];
    struct aiocb aio_init;
    aio_init_table[0] = &aio_init;
    aiocb_setup(&aio_init,
                swapped_meta->page_index,
                swapped_meta->frame_number);
    if (increase_io_operations_counter() == ERROR)
        return ERROR;
    
    if (swapped_meta->modified)
    {
        callback_wrapper(2, swapped_meta->page_index, 
                         swapped_meta->frame_number);
        if (aio_write(&aio_init) == ERROR)
            return ERROR;
        if (aio_suspend((const struct aiocb * const *)aio_init_table, 1, NULL)
            == ERROR)
            return ERROR;
        callback_wrapper(3, swapped_meta->page_index,
                         swapped_meta->frame_number);
    }
    
    swapped_meta->frame_number = -1;
    if (pthread_mutex_unlock(&swapped_meta->lock) != SUCCESS)
        return ERROR;
    return SUCCESS;
}
Exemple #24
0
int add_write(const char *fname, const char *buf, int size, char flags, function_to_call_t *fun) {
    if (fname) {
        aiob *aio = get_aiob();
        memset(aio, 0, sizeof(aiob));
        int fd = open(fname, flags & 1 ? O_CREAT|O_WRONLY
                : O_CREAT|O_WRONLY|O_APPEND, S_IRWXU|S_IRWXG);
        aio->aio_fildes = fd;
        aio->aio_buf = buf;
        aio->aio_nbytes = size;
        struct request *req = get_req();
        req->aio = aio;
        req->fun = fun;
        req->type = awrite;
        assign_svalue_no_free(&req->tmp, sp-2);
        add_req(req);
#ifdef PACKAGE_COMPRESS
        if(flags & 2)
            return aio_gzwrite(aio);
        else
#endif
            return aio_write(aio);
    } else
        error("permission denied\n");
    return 1;
}
Exemple #25
0
static int swAioGcc_write(int fd, void *inbuf, size_t size, off_t offset)
{
    swAio_gcc_t *aiocb = sw_malloc(sizeof(swAio_gcc_t));
    if (aiocb == NULL)
    {
        swWarn("malloc failed.");
        return SW_ERR;
    }

    aiocb->next = NULL;
    if (swAioGcc_request == NULL)
    {
        swAioGcc_request = aiocb;
    }
    else
    {
        swAioGcc_request->next = aiocb;
    }
    bzero(aiocb, sizeof(swAio_gcc_t));
    aiocb->aiocb.aio_fildes = fd;
    aiocb->aiocb.aio_buf = inbuf;
    aiocb->aiocb.aio_nbytes = size;
    aiocb->aiocb.aio_lio_opcode = LIO_WRITE;

    aiocb->aiocb.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
    aiocb->aiocb.aio_sigevent.sigev_signo = SIGIO;

    if (aio_write(&aiocb->aiocb) == -1)
    {
        swWarn("aio_write failed. Error: %s[%d]", strerror(errno), errno);
        return SW_ERR;
    }
    return SW_OK;
}
Exemple #26
0
Status Issue(aiocb& cb, size_t queueDepth)
{
#if CONFIG2_FILE_ENABLE_AIO
	if(queueDepth > 1)
	{
		const int ret = (cb.aio_lio_opcode == LIO_WRITE)? aio_write(&cb): aio_read(&cb);
		if(ret != 0)
			WARN_RETURN(StatusFromErrno());
	}
	else
#else
	UNUSED2(queueDepth);
#endif
	{
		ENSURE(lseek(cb.aio_fildes, cb.aio_offset, SEEK_SET) == cb.aio_offset);

		void* buf = (void*)cb.aio_buf;	// cast from volatile void*
		const ssize_t bytesTransferred = (cb.aio_lio_opcode == LIO_WRITE)? write(cb.aio_fildes, buf, cb.aio_nbytes) : read(cb.aio_fildes, buf, cb.aio_nbytes);
		if(bytesTransferred < 0)
			WARN_RETURN(StatusFromErrno());

		cb.aio_nbytes = (size_t)bytesTransferred;
	}

	return INFO::OK;
}
Exemple #27
0
static void
input_cb (EV_P_ struct ev_io *w, int revents)
{
  struct stat st;
  int i = (int)w->data;
  int err, avail;
  
  if (remaining <= 0) {
    // Done
    ev_io_stop(EV_A_ w);
    // FIXME: HACK!! belongs later
    close(fifos[i]);
    //ev_unloop(EV_A_ EVUNLOOP_ALL);
  } else {
#if 1
    fstat(w->fd, &st);
    err = ioctl(w->fd, FIONREAD, &avail);
    if (avail == 0) {
      printf("Worker %d: pipe size: %jd %d  (%d) ", i, st.st_size, avail, err);
      puts("Writing...");
      write(w->fd, "That's all folks!\n", 18);
      remaining--;
    } else {
      //puts("Waiting...");
    }
#else
    aios[i].aio_fildes = w->fd;
    aios[i].aio_buf    = "That's all folks!\n";
    aios[i].aio_nbytes = 18;
    aio_write(aios + i);
#endif
  }
}
Exemple #28
0
int main()
{
	char tmpfname[256];
#define BUF_SIZE 111
	char buf[BUF_SIZE];
	int fd;
	struct aiocb aiocb_write;
	struct aiocb aiocb_fsync;

#if _POSIX_ASYNCHRONOUS_IO != 200112L
	exit(PTS_UNSUPPORTED);
#endif

	snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_4_2_%d", 
		  getpid());
	unlink(tmpfname);
	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
		  S_IRUSR | S_IWUSR);
	if (fd == -1)
	{
		printf(TNAME " Error at open(): %s\n",
		       strerror(errno));
		exit(PTS_UNRESOLVED);
	}

	unlink(tmpfname);

	memset(&aiocb_write, 0, sizeof(aiocb_write));
	aiocb_write.aio_fildes = fd;
	aiocb_write.aio_buf = buf;
	aiocb_write.aio_nbytes = BUF_SIZE;

	if (aio_write(&aiocb_write) == -1)
	{
		printf(TNAME " Error at aio_write(): %s\n",
		       strerror(errno));
		exit(PTS_FAIL);
	}

	memset(&aiocb_fsync, 0, sizeof(aiocb_fsync));
	aiocb_fsync.aio_fildes = fd;

	if (aio_fsync(O_SYNC, &aiocb_fsync) != 0)
	{
		printf(TNAME " Error at aio_fsync()\n");
		exit(PTS_FAIL);
	}

	errno = 0;
	aio_return(&aiocb_fsync);
	if (errno != 0)
	{
		printf(TNAME " Error at aio_return() : %s\n", strerror(errno));
		exit(PTS_FAIL);
	}
	close(fd);
	printf ("Test PASSED\n");
	return PTS_PASS;
}
Exemple #29
0
int main()
{
	char tmpfname[256];
#define BUF_SIZE 111
	char buf[BUF_SIZE];
	int fd;
	int ret;
	struct aiocb aiocb_write;
	struct aiocb aiocb_fsync;

	if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
		return PTS_UNSUPPORTED;

	snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_8_2_%d",
		  getpid());
	unlink(tmpfname);
	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
		  S_IRUSR | S_IWUSR);
	if (fd == -1) {
		printf(TNAME " Error at open(): %s\n",
		       strerror(errno));
		exit(PTS_UNRESOLVED);
	}

	unlink(tmpfname);

	memset(&aiocb_write, 0, sizeof(aiocb_write));
	aiocb_write.aio_fildes = fd;
	aiocb_write.aio_buf = buf;
	aiocb_write.aio_nbytes = BUF_SIZE;

	if (aio_write(&aiocb_write) == -1) {
		printf(TNAME " Error at aio_write(): %s\n",
		       strerror(errno));
		exit(PTS_FAIL);
	}

	do {
		usleep(10000);
		ret = aio_error(&aiocb_write);
	} while (ret == EINPROGRESS);
	if (ret < 0) {
		printf(TNAME " Error at aio_error() : %s\n", strerror(ret));
		exit(PTS_FAIL);
	}

	memset(&aiocb_fsync, 0, sizeof(aiocb_fsync));
	aiocb_fsync.aio_fildes = fd;
	aiocb_fsync.aio_buf = NULL;

	if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) {
		printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno));
		exit(PTS_FAIL);
	}

	close(fd);
	printf("Test PASSED\n");
	return PTS_PASS;
}
Exemple #30
0
static PyObject *
pyaio_write(PyObject *dummy, PyObject *args) {

    PyObject *buffer;
    Py_buffer *buffer_view;

    int fd;
    Py_ssize_t offset, ret;

    Pyaio_cb *aio;
    PyObject *callback, *return_;
    Py_XINCREF(args);
    if (PyArg_ParseTuple(args, "iOnO:set_callback", &fd, &buffer,
                          &offset, &callback)) {
        if (!PyCallable_Check(callback)) {
            PyErr_SetString(PyExc_TypeError,
                    "parameter must be callable");
            return NULL;
        }
        if (!PyObject_CheckBuffer(buffer)) {
            PyErr_SetString(PyExc_TypeError,
                    "write buffer must support buffer interface");
            return NULL;
        }
        Py_XINCREF(callback); /* Add a reference to new callback */
        Py_XINCREF(buffer);
    }
    Py_XDECREF(args);

    aio = malloc(sizeof(Pyaio_cb));
    buffer_view = &(aio->buffer_view);
    /* Get a Buffer INCREF */
    PyObject_GetBuffer(buffer, buffer_view, PyBUF_CONTIG_RO);


    aio->cb = malloc(sizeof(struct aiocb));
    bzero((void *) aio->cb, sizeof(struct aiocb));
    aio->read = 0;  /* Write Operation */
    aio->callback = callback;
    aio->buffer = buffer;
    aio->cb->aio_buf = buffer_view->buf;
    aio->cb->aio_fildes = fd;
    aio->cb->aio_nbytes = buffer_view->len;
    aio->cb->aio_offset = offset;
    aio->cb->aio_sigevent.sigev_notify = SIGEV_THREAD;
    aio->cb->aio_sigevent.sigev_notify_attributes = NULL;
    aio->cb->aio_sigevent.sigev_notify_function = aio_completion_handler;
    aio->cb->aio_sigevent.sigev_value.sival_ptr = aio;

    ret = aio_write(aio->cb);

    if (ret < 0) {
        return PyErr_SetFromErrno(PyExc_IOError);
    }
    else {
        return_ = Py_BuildValue("n", ret);
        return return_;
    }
}