コード例 #1
0
ファイル: bon_file.cpp プロジェクト: azat-archive/bonnie
int COpenTest::delete_random(BonTimer &timer)
{
  random_sort(timer.random_source);
  timer.start();
  int i;
  Duration dur;
  for(i = 0; i < m_number; i++)
  {
    dur.start();
    if(unlink(m_file_names[i]))
    {
      fprintf(stderr, "Can't delete file %s\n", m_file_names[i]);
      return -1;
    }
    if(m_sync && m_sync_dir)
    {
      if(fsync(m_directoryHandles[m_dirIndex[i]]))
      {
        fprintf(stderr, "Can't sync directory, turning off dir-sync.\n");
        m_sync_dir = false;
      }
    }
    dur.stop();
  }
  if(m_number_directories > 1)
  {
    char buf[6];
    for(i = 0; i < m_number_directories; i++)
    {
      sprintf(buf, "%05d", i);
      if(m_sync)
      {
        close(m_directoryHandles[i]);
      }
      if(rmdir(buf))
      {
        io_error("rmdir");
        return -1;
      }
    }
  }
  else
  {
    if(m_sync)
    {
      close(m_directoryHandles[0]);
    }
  }
  if(chdir("..") || rmdir(m_dirname))
  {
    io_error("rmdir");
    return -1;
  }
  delete m_dirname;
  m_dirname = NULL;
  sync();
  timer.stop_and_record(DelRand);
  timer.add_latency(DelRand, dur.getMax());
  return 0;
}
コード例 #2
0
ファイル: bon_file.cpp プロジェクト: azat-archive/bonnie
int COpenTest::stat_random(BonTimer &timer)
{
  random_sort(timer.random_source);
  timer.start();

  int i;
  Duration dur;
  for(i = 0; i < m_number; i++)
  {
    dur.start();
    if(-1 == stat_file(m_file_names[i]))
      return -1;
    dur.stop();
  }
  timer.stop_and_record(StatRand);
  timer.add_latency(StatRand, dur.getMax());
  return 0;
}
コード例 #3
0
ファイル: bon_file.cpp プロジェクト: azat-archive/bonnie
int COpenTest::stat_sequential(BonTimer &timer)
{
  timer.start();
  int count = 0;
  Duration dur;
  for(int i = 0; i < m_number_directories; i++)
  {
    char buf[6];
    if(m_number_directories != 1)
    {
      sprintf(buf, "%05d", i);
      if(chdir(buf))
      {
        fprintf(stderr, "Can't change to directory %s\n", buf);
        return -1;
      }
    }
    DIR *d = opendir(".");
    if(!d)
    {
      fprintf(stderr, "Can't open directory.\n");
      if(m_number_directories != 1)
      {
        if(chdir(".."))
          fprintf(stderr, "Can't chdir().\n");
      }
      return -1;
    }
    dirent *file_ent;
    while(1)
    {
      dur.start();
      file_ent = readdir(d);
      if(file_ent == NULL)
        break;
      if(*m_exit)
      {
        if(m_number_directories != 1 && chdir(".."))
        {
          fprintf(stderr, "Can't change to directory ..\n");
          return -1;
        }
        return eCtrl_C;
      }
      if(file_ent->d_name[0] != '.') // our files do not start with a dot
      {
        if(-1 == stat_file(file_ent->d_name))
        {
          if(m_number_directories != 1)
          {
            if(chdir(".."))
            {
              fprintf(stderr, "Can't chdir().\n");
              return -1;
            }
          }
          dur.stop();
          return -1;
        }
        count++;
        dur.stop();
      }
    }
    closedir(d);
    if(m_number_directories != 1)
    {
      if(chdir(".."))
      {
        fprintf(stderr, "Can't change to directory ..\n");
        return -1;
      }
    }
  }
  if(count != m_number)
  {
    fprintf(stderr, "Expected %d files but only got %d\n", m_number, count);
    return -1;
  }
  timer.stop_and_record(StatSeq);
  timer.add_latency(StatSeq, dur.getMax());
  return 0;
}
コード例 #4
0
ファイル: bon_file.cpp プロジェクト: azat-archive/bonnie
int COpenTest::delete_sequential(BonTimer &timer)
{
  timer.start();
  int count = 0;
  Duration dur;
  for(int i = 0; i < m_number_directories; i++)
  {
    char buf[6];
    if(m_number_directories != 1)
    {
      sprintf(buf, "%05d", i);
      if(chdir(buf))
      {
        fprintf(stderr, "Can't change to directory %s\n", buf);
        return -1;
      }
    }
    DIR *d = opendir(".");
    if(!d)
    {
      fprintf(stderr, "Can't open directory.\n");
      if(m_number_directories != 1)
      {
        if(chdir(".."))
          fprintf(stderr, "Can't chdir().\n");
      }
      return -1;
    }
    dirent *file_ent;

    while(1)
    {
      dur.start();
      file_ent = readdir(d);
      if(file_ent == NULL)
        break;
      if(file_ent->d_name[0] != '.')
      {
        if(unlink(file_ent->d_name))
        {
          fprintf(stderr, "Can't delete file %s\n", file_ent->d_name);
          return -1;
        }


        if(m_sync && m_sync_dir)
        {
          if(fsync(m_directoryHandles[i]))
          {
            fprintf(stderr, "Can't sync directory, turning off dir-sync.\n");
            m_sync_dir = false;
          }
        }
        count++;
      }
      dur.stop();
    }
    closedir(d);
    if(m_sync)
    {
      close(m_directoryHandles[i]);
    }
    if(m_number_directories != 1)
    {
      if(chdir("..") || rmdir(buf))
      {
        io_error("rmdir");
        return -1;
      }
    }
  }
  if(chdir("..") || rmdir(m_dirname))
  {
    io_error("rmdir");
    return -1;
  }
  delete m_dirname;
  m_dirname = NULL;
  if(count != m_number)
  {
    fprintf(stderr, "Expected %d files but only got %d\n", m_number, count);
    return -1;
  }
  sync();
  timer.stop_and_record(DelSeq);
  timer.add_latency(DelSeq, dur.getMax());
  return 0;
}
コード例 #5
0
ファイル: bon_file.cpp プロジェクト: azat-archive/bonnie
int COpenTest::create(CPCCHAR dirname, BonTimer &timer, int num, int max_size
                    , int min_size, int num_directories, bool do_random)
{
  if(num_directories >= 100000)
  {
    fprintf(stderr, "Can't have more than 99,999 directories.\n");
    return -1;
  }

  m_number = num * DirectoryUnit;
  m_number_directories = num_directories;
  make_names(timer.random_source, do_random);
  m_max = max_size;
  m_min = min_size;
  m_size_range = m_max - m_min;
  m_dirname = new char[strlen(dirname) + 1];
  strcpy(m_dirname, dirname);

  if(num_directories >= 100000)
  {
    fprintf(stderr, "Can't have more than 99,999 directories.\n");
    return -1;
  }
  if(mkdir(dirname, S_IRWXU))
  {
    fprintf(stderr, "Can't make directory %s\n", dirname);
    return -1;
  }
  if(chdir(dirname))
  {
    fprintf(stderr, "Can't change to directory %s\n", dirname);
    return -1;
  }
  int i;
  if(m_sync)
    m_directoryHandles = new FILE_TYPE[num_directories];
  if(num_directories > 1)
  {
    for(i = 0; i < num_directories; i++)
    {
      sprintf(m_buf, "%05d", i);
      if(mkdir(m_buf, S_IRWXU))
      {
        fprintf(stderr, "Can't make directory %s\n", m_buf);
        return -1;
      }
      if(m_sync)
      {
        m_directoryHandles[i] = open(m_buf, O_RDONLY);
        if(m_directoryHandles[i] == -1)
        {
          fprintf(stderr, "Can't get directory handle.\n");
          return -1;
        }
      }
    }
  }
  else if(m_sync)
  {
    m_directoryHandles[0] = open(".", O_RDONLY);
    if(m_directoryHandles[0] == -1)
    {
      fprintf(stderr, "Can't get directory handle.\n");
      return -1;
    }
  }

  Duration dur;
  timer.start();
  for(i = 0; i < m_number; i++)
  {
    if(*m_exit)
    {
      if(m_number_directories != 1 && chdir(".."))
      {
        fprintf(stderr, "Can't change to directory ..\n");
        return -1;
      }
      return eCtrl_C;
    }
    dur.start();
    // m_max < 0 means link or sym-link
    if(m_max < 0)
    {
      if(i == 0)
      {
        if(create_a_file(m_file_names[0], m_buf, 0, m_dirIndex ? m_dirIndex[0] : 0))
          return -1;
      }
      else
      {
        // create_a_link() looks at m_max to see what to do
        if(create_a_link(m_file_names[0], m_file_names[i], m_dirIndex ? m_dirIndex[i] : 0))
          return -1;
      }
    }
    else
    {
      int size;
      if(m_size_range)
        size = m_min + (timer.random_source.getNum() % (m_size_range + 1));
      else
        size = m_max;
      if(create_a_file(m_file_names[i], m_buf, size, m_dirIndex ? m_dirIndex[i] : 0))
        return -1;
    }
    dur.stop();
  }
  sync();
  timer.stop_and_record(do_random ? CreateRand : CreateSeq);
  timer.add_latency(do_random ? CreateRand : CreateSeq, dur.getMax());
  return 0;
}