src/worker.cc
// Direct device access thread.
// Return false on software error.
Direct device access thread.
Return false on software error.
Direct device access thread . Return false on software error .
bool DiskThread::Work() {
  int fd;
  logprintf(9, "Log: Starting disk thread %d, disk %s\n",
            thread_num_, device_name_.c_str());
  srandom(time(NULL));
  if (!OpenDevice(&fd)) {
    status_ = false;
    return false;
  }
#ifdef HAVE_POSIX_MEMALIGN
  int memalign_result = posix_memalign(&block_buffer_, kBufferAlignment,
                              sat_->page_length());
#else
  block_buffer_ = memalign(kBufferAlignment, sat_->page_length());
  int memalign_result = (block_buffer_ == 0);
#endif
  if (memalign_result) {
    CloseDevice(fd);
    logprintf(0, "Process Error: Unable to allocate memory for buffers "
                 "for disk %s (thread %d) posix memalign returned %d.\n",
              device_name_.c_str(), thread_num_, memalign_result);
    status_ = false;
    return false;
  }
#ifdef HAVE_LIBAIO_H
  if (io_setup(5, &aio_ctx_)) {
    CloseDevice(fd);
    logprintf(0, "Process Error: Unable to create aio context for disk %s"
              " (thread %d).\n",
              device_name_.c_str(), thread_num_);
    status_ = false;
    return false;
  }
#endif
  bool result = DoWork(fd);
  status_ = result;
#ifdef HAVE_LIBAIO_H
  io_destroy(aio_ctx_);
#endif
  CloseDevice(fd);
  logprintf(9, "Log: Completed %d (disk %s): disk thread status %d, "
               "%d pages copied\n",
            thread_num_, device_name_.c_str(), status_, pages_copied_);
  return result;
}
bool DiskThread :: Work ( ) { int fd ; logprintf ( 9 , " \n " , thread_num_ , device_name_ . c_str ( ) ) ; srandom ( time ( NULL ) ) ; if ( ! OpenDevice ( & fd ) ) { status_ = false ; return false ; } #ifdef HAVE_POSIX_MEMALIGN int memalign_result = posix_memalign ( & block_buffer_ , kBufferAlignment , sat_ -> page_length ( ) ) ; #else block_buffer_ = memalign ( kBufferAlignment , sat_ -> page_length ( ) ) ; int memalign_result = ( block_buffer_ == 0 ) ; #endif if ( memalign_result ) { CloseDevice ( fd ) ; logprintf ( 0 , " " " \n " , device_name_ . c_str ( ) , thread_num_ , memalign_result ) ; status_ = false ; return false ; } #ifdef HAVE_LIBAIO_H if ( io_setup ( 5 , & aio_ctx_ ) ) { CloseDevice ( fd ) ; logprintf ( 0 , " " " \n " , device_name_ . c_str ( ) , thread_num_ ) ; status_ = false ; return false ; } #endif bool result = DoWork ( fd ) ; status_ = result ; #ifdef HAVE_LIBAIO_H io_destroy ( aio_ctx_ ) ; #endif CloseDevice ( fd ) ; logprintf ( 9 , " " " \n " , thread_num_ , device_name_ . c_str ( ) , status_ , pages_copied_ ) ; return result ; }
Direct device access thread.
Direct device access thread .
// Allocate a block buffer aligned to 512 bytes since the kernel requires it // when using direct IO.