Ejemplo n.º 1
0
err_t sys_pwritev(fd_t fd, const struct iovec* iov, int iovcnt, off_t seek_to_offset, ssize_t* num_written_out)
{
  ssize_t got;
  ssize_t got_total;
  err_t err_out;
  int i;
  int niovs = IOV_MAX;

  STARTING_SLOW_SYSCALL;

  err_out = 0;
  got_total = 0;
  for( i = 0; i < iovcnt; i += niovs ) {
    niovs = iovcnt - i;
    if( niovs > IOV_MAX ) niovs = IOV_MAX;

    // Some systems pwritev doesn't take a const struct iovec*, hence the cast
    got = pwritev(fd, (struct iovec*) &iov[i], niovs, seek_to_offset + got_total);
    if( got != -1 ) {
      got_total += got;
    } else {
      err_out = errno;
      break;
    }
    if( got != sys_iov_total_bytes(&iov[i], niovs) ) {
      break;
    }
  }

  *num_written_out = got_total;

  DONE_SLOW_SYSCALL;

  return err_out;
}
Ejemplo n.º 2
0
err_t sys_preadv(fd_t fd, const struct iovec* iov, int iovcnt, off_t seek_to_offset, ssize_t* num_read_out)
{
  ssize_t got;
  ssize_t got_total;
  err_t err_out;
  int i;

  STARTING_SLOW_SYSCALL;

  err_out = 0;
  got_total = 0;
  for( i = 0; i < iovcnt; i++ ) {
    got = 0;
    err_out = do_pread(fd, iov[i].iov_base, iov[i].iov_len, seek_to_offset + got_total, &got);
    if( got >= 0 ) {
      got_total += got;
    } else {
      break;
    }
    if( (size_t) got != iov[i].iov_len ) {
      break;
    }
  }

  if( err_out == 0 && got_total == 0 && sys_iov_total_bytes(iov, iovcnt) != 0 ) err_out = EEOF;

  *num_read_out = got_total;

  DONE_SLOW_SYSCALL;

  return err_out;
}
Ejemplo n.º 3
0
qioerr hdfs_writev(void* fl, const struct iovec* iov, int iovcnt, ssize_t* num_written_out, void* fs)
{
  ssize_t got;
  ssize_t got_total = 0;
  qioerr err_out = 0;
  int i;

  STARTING_SLOW_SYSCALL;
  for (i = 0; i < iovcnt; i++) {
    got = hdfsWrite(to_hdfs_fs(fs)->hfs, to_hdfs_file(fl)->file, (void*)(iov[i].iov_base), iov[i].iov_len);

    if (got != -1)
      got_total += got;
    else {
      err_out = qio_mkerror_errno();
      break;
    }

    if (got != sys_iov_total_bytes(&iov[i], iov[i].iov_len))
      break;
  }

  *num_written_out = got_total;
  DONE_SLOW_SYSCALL;

  return err_out;
}
Ejemplo n.º 4
0
err_t sys_preadv(fd_t fd, const struct iovec* iov, int iovcnt, off_t seek_to_offset, ssize_t* num_read_out)
{
  ssize_t got;
  ssize_t got_total;
  err_t err_out;
  int i;
  int niovs = IOV_MAX;

  STARTING_SLOW_SYSCALL;

  err_out = 0;
  got_total = 0;
  for( i = 0; i < iovcnt; i += niovs ) {
    niovs = iovcnt - i;
    if( niovs > IOV_MAX ) niovs = IOV_MAX;

    // Some systems preadv doesn't take a const struct iovec*, hence the cast
    got = preadv(fd, (struct iovec*) &iov[i], niovs, seek_to_offset + got_total);
    #ifdef __CYGWIN__
    if( got == -1 && errno == ENODATA ) got = 0;
    #endif
    if( got != -1 ) {
      got_total += got;
    } else {
      err_out = errno;
      break;
    }
    if( got != sys_iov_total_bytes(&iov[i], niovs) ) {
      break;
    }
  }

  if( err_out == 0 && got_total == 0 && sys_iov_total_bytes(iov, iovcnt) != 0 ) err_out = EEOF;

  *num_read_out = got_total;

  DONE_SLOW_SYSCALL;

  return err_out;
}
Ejemplo n.º 5
0
err_t sys_readv(fd_t fd, const struct iovec* iov, int iovcnt, ssize_t* num_read_out)
{
  ssize_t got;
  ssize_t got_total;
  err_t err_out;
  int i;
  int niovs = IOV_MAX;

  STARTING_SLOW_SYSCALL;

  err_out = 0;
  got_total = 0;
  for( i = 0; i < iovcnt; i += niovs ) {
    niovs = iovcnt - i;
    if( niovs > IOV_MAX ) niovs = IOV_MAX;

    // Some systems readv doesn't take a const struct iovec*, hence the cast
    got = readv(fd, (struct iovec*) &iov[i], niovs);
    if( got != -1 ) {
      got_total += got;
    } else {
      err_out = errno;
      break;
    }
    if( got != sys_iov_total_bytes(&iov[i], niovs) ) {
      break;
    }
  }

  if( err_out == 0 && got_total == 0 && sys_iov_total_bytes(iov, iovcnt) != 0 ) err_out = EEOF;

  *num_read_out = got_total;

  DONE_SLOW_SYSCALL;

  return err_out;
}
Ejemplo n.º 6
0
static
qioerr  curl_preadv_internal(void* file, const struct iovec *vector, int count, off_t offset, ssize_t* num_read_out, void* fs)
{
  CURLcode err;
  ssize_t got_total;
  qioerr err_out = 0;
  struct curl_iovec_t write_vec;
  curl_handle* local_handle = to_curl_handle(file);

  STARTING_SLOW_SYSCALL;

  got_total = 0;
  write_vec.total_read = 0;
  write_vec.count = count;
  write_vec.vec = (struct iovec*)vector;
  write_vec.amt_read = 0;
  write_vec.offset = 0;
  write_vec.curr = 0;

  // offset = -1 if we want readv
  offset = offset == -1 ? local_handle->current_offset : offset;

  if (local_handle->seekable)  // we can request byteranges
    curl_easy_setopt(local_handle->curl, CURLOPT_RESUME_FROM_LARGE, offset);
  else
    write_vec.offset = offset;

  curl_easy_setopt(local_handle->curl, CURLOPT_WRITEFUNCTION, buf_writer);

  // Read into write_vec
  curl_easy_setopt(local_handle->curl, CURLOPT_WRITEDATA, &write_vec);

  // Read our data into the buf
  err = curl_easy_perform(local_handle->curl);
  DONE_SLOW_SYSCALL;

  got_total = write_vec.total_read;
  local_handle->current_offset += got_total;

  if ((err == CURLE_RANGE_ERROR ||  err == CURLE_OK) && got_total == 0 && sys_iov_total_bytes(vector, count) != 0)
    err_out = qio_int_to_err(EEOF);

  curl_easy_setopt(local_handle->curl, CURLOPT_WRITEFUNCTION, NULL);
  curl_easy_setopt(local_handle->curl, CURLOPT_WRITEDATA, NULL);

  *num_read_out = got_total;
  return err_out;
}
Ejemplo n.º 7
0
static
qioerr curl_writev(void* fl, const struct iovec* iov, int iovcnt, ssize_t* num_written_out, void* fs)
{
  CURLcode ret;
  qioerr err_out = 0;
  struct curl_iovec_t write_vec;

  write_vec.total_read = 0;
  write_vec.count = iovcnt;
  write_vec.vec = (struct iovec*)iov;
  write_vec.amt_read = 0;
  write_vec.offset = 0;
  write_vec.curr = 0;

  STARTING_SLOW_SYSCALL;
  /*tell it to "upload" to the URL*/
  curl_easy_setopt(to_curl_handle(fl)->curl, CURLOPT_UPLOAD, 1L);
  // set it up to write over curl
  curl_easy_setopt(to_curl_handle(fl)->curl, CURLOPT_READFUNCTION, read_data);
  // Tell curl how much data to expect
  curl_easy_setopt(to_curl_handle(fl)->curl, CURLOPT_INFILESIZE_LARGE,  (curl_off_t)sys_iov_total_bytes(iov, iovcnt));
  curl_easy_setopt(to_curl_handle(fl)->curl, CURLOPT_READDATA, &write_vec);
  ret = curl_easy_perform(to_curl_handle(fl)->curl);
  *num_written_out = write_vec.total_read;

  if (ret != CURLE_OK)
    err_out = qio_mkerror_errno();

  curl_easy_setopt(to_curl_handle(fl)->curl, CURLOPT_UPLOAD, 0L);
  curl_easy_setopt(to_curl_handle(fl)->curl, CURLOPT_INFILESIZE_LARGE, 0L);
  curl_easy_setopt(to_curl_handle(fl)->curl, CURLOPT_READFUNCTION, NULL);
  curl_easy_setopt(to_curl_handle(fl)->curl, CURLOPT_READDATA, NULL);

  DONE_SLOW_SYSCALL;

  return err_out;
}
Ejemplo n.º 8
0
qioerr hdfs_preadv (void* file, const struct iovec *vector, int count, off_t offset, ssize_t* num_read_out, void* fs)
{
  ssize_t got;
  ssize_t got_total;
  qioerr err_out = 0;
  int i;

  STARTING_SLOW_SYSCALL;

#ifdef HDFS3

  const hdfs_file orig_hfl = *to_hdfs_file(file);
  const hdfs_fs orig_hfs = *to_hdfs_fs(fs);

  hdfsFS hfs = hdfsConnect(orig_hfs.fs_name, orig_hfs.fs_port);
  hdfsFile hfl = hdfsOpenFile(hfs, orig_hfl.pathnm, O_RDONLY, 0, 0, 0);

  //assert connection
  CREATE_ERROR((hfs == NULL), err_out, ECONNREFUSED, "Unable to read HDFS file", error);

  if(hfl == NULL) {
    err_out = qio_mkerror_errno();
    goto error;
  }

#endif

  err_out = 0;
  got_total = 0;
  for(i = 0; i < count; i++) {

#ifdef HDFS3
    hdfsSeek(hfs, hfl, offset+got_total);
    got = hdfsRead(hfs, hfl, (void*)vector[i].iov_base, vector[i].iov_len);
#else
    got = hdfsPread(to_hdfs_fs(fs)->hfs, to_hdfs_file(file)->file, offset + got_total, (void*)vector[i].iov_base, vector[i].iov_len);
#endif

    if( got != -1 ) {
      got_total += got;
    } else {
      err_out = qio_mkerror_errno();
      break;
    }
    if(got != (ssize_t)vector[i].iov_len ) {
      break;
    }
  }

  if( err_out == 0 && got_total == 0 && sys_iov_total_bytes(vector, count) != 0 )
    err_out = qio_int_to_err(EEOF);

  *num_read_out = got_total;

#ifdef HDFS3
  got = hdfsCloseFile(hfs, hfl);
  if(got == -1) { err_out = qio_mkerror_errno(); }

  got = hdfsDisconnect(hfs);
  if(got == -1) { err_out = qio_mkerror_errno(); }

#endif

  DONE_SLOW_SYSCALL;

#ifdef HDFS3
error:
#endif
  return err_out;
}