示例#1
0
/*
 * Delete a file through the POSIX interface.
 */
static void POSIX_Delete(char *testFileName, IOR_param_t * param)
{
        char errmsg[256];
        sprintf(errmsg, "[RANK %03d]: unlink() of file \"%s\" failed\n",
                rank, testFileName);
        if (unlink(testFileName) != 0)
                EWARN(errmsg);
}
示例#2
0
void gpfs_free_all_locks(int fd)
{
        int rc;
        struct {
                gpfsFcntlHeader_t header;
                gpfsFreeRange_t release;
        } release_all;
        release_all.header.totalLength = sizeof(release_all);
        release_all.header.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
        release_all.header.fcntlReserved = 0;

        release_all.release.structLen = sizeof(release_all.release);
        release_all.release.structType = GPFS_FREE_RANGE;
        release_all.release.start = 0;
        release_all.release.length = 0;

        rc = gpfs_fcntl(fd, &release_all);
        if (verbose >= VERBOSE_0 && rc != 0) {
                EWARN("gpfs_fcntl release all locks hint failed.");
        }
}
示例#3
0
void gpfs_access_end(int fd, IOR_offset_t length, IOR_param_t *param, int access)
{
        int rc;
        struct {
                gpfsFcntlHeader_t header;
                gpfsFreeRange_t free;
        } free_locks;


        free_locks.header.totalLength = sizeof(free_locks);
        free_locks.header.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
        free_locks.header.fcntlReserved = 0;

        free_locks.free.structLen = sizeof(free_locks.free);
        free_locks.free.structType = GPFS_FREE_RANGE;
        free_locks.free.start = param->offset;
        free_locks.free.length = length;

        rc = gpfs_fcntl(fd, &free_locks);
        if (verbose >= VERBOSE_2 && rc != 0) {
                EWARN("gpfs_fcntl free range hint failed.");
        }
}
示例#4
0
void gpfs_access_start(int fd, IOR_offset_t length, IOR_param_t *param, int access)
{
        int rc;
        struct {
                gpfsFcntlHeader_t header;
                gpfsAccessRange_t access;
        } take_locks;

        take_locks.header.totalLength = sizeof(take_locks);
        take_locks.header.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
        take_locks.header.fcntlReserved = 0;

        take_locks.access.structLen = sizeof(take_locks.access);
        take_locks.access.structType = GPFS_ACCESS_RANGE;
        take_locks.access.start = param->offset;
        take_locks.access.length = length;
        take_locks.access.isWrite = (access == WRITE);

        rc = gpfs_fcntl(fd, &take_locks);
        if (verbose >= VERBOSE_2 && rc != 0) {
                EWARN("gpfs_fcntl access range hint failed.");
        }
}
示例#5
0
/*
 * Perform fsync().
 */
static void POSIX_Fsync(void *fd, IOR_param_t * param)
{
        if (fsync(*(int *)fd) != 0)
                EWARN("fsync() failed");
}
示例#6
0
/* Wrapping the system read() just so we can read
 * a pipe with the libsndfile API and if the
 * pipe was not sound data then we can read
 * what was in the front of the pipe from 
 * the qp_rd buffer.  It turns out that stdio
 * streams are in the same library as the read()
 * function and do not call my wrapper.
 * So we use our own Getline() that starts by
 * copying from the qp_rd buffer and than switches
 * to calling getline() after the buffer is all
 * copied.  This function does more than we
 * need, because we wrongly thought that getline would
 * call it.  We are lucky that libsndfile does not
 * use stdio streams to read. */
ssize_t read(int fd, void *buf, size_t count)
{
  if(!sys_read)
  {
    char *error;
    dlerror();
    sys_read = dlsym(RTLD_NEXT, "read");
    if((error = dlerror()) != NULL)
    {
      EERROR("dlsym(RTLD_NEXT, \"read\") failed: %s\n", error);
      QP_EERROR("Failed to virtualize read(): %s\n", error);
      exit(1);
    }
  }


  if(qp_rd && qp_rd->fd == fd && !qp_rd->past)
  {
    ssize_t n;
    size_t rcount;

    //DEBUG("count=%zu  rd=%zu len=%zu\n", count, qp_rd->rd, qp_rd->len);

    if(BUF_LEN == qp_rd->rd)
    {
      /* The read before this one was the last
       * read that was buffered.  Now it is reading
       * past the buffer and we are no longer
       * buffering the read.  We are screwed if
       * we need more buffering. */
      qp_rd->past = 1;
      DEBUG("Finished virtualizing read()\n");
      return sys_read(fd, buf, count);
    }

    if(qp_rd->len >= qp_rd->rd + count)
    {
      /* pure virtual read */
      memcpy(buf, &qp_rd->buf[qp_rd->rd], count);
      qp_rd->rd += count;
      return (ssize_t) count;
    }

    if(BUF_LEN == qp_rd->len)
    {
      /* We cannot read any more and
       * we still have unread buffer data.
       * pure virtual read with less than
       * requested returned */
      /* count is greater than what is buffered */
      n = BUF_LEN - qp_rd->rd;
      memcpy(buf, &qp_rd->buf[qp_rd->rd], n);
      qp_rd->rd = BUF_LEN;
      return n;
    }

    /* At this point we will read more into
     * the buffer */

    if(count > BUF_LEN - qp_rd->rd)
      /* Giving less than asked for.
       * We may fill the buffer full. */
      rcount = BUF_LEN - qp_rd->len;
    else
      /* Try to give what was asked for. */
      rcount = count + qp_rd->rd - qp_rd->len;

    errno = 0;
    n = sys_read(fd, &qp_rd->buf[qp_rd->rd], rcount);

    if(n < 0)
    {
      EWARN("read(fd=%d, buf=%p, count=%zu) failed\n",
          fd, &qp_rd->buf[qp_rd->rd], rcount);
      QP_EWARN("reading file \"%s\" failed", qp_rd->filename);
      qp_rd->past = 1;
      return n;
    }
    if(n == 0 && qp_rd->rd == qp_rd->len)
    {
      /* virtual and real end of file */
      //DEBUG("read(fd=%d, buf=%p, count=%zu)=0 end of file\n",
      //    fd, &qp_rd->buf[qp_rd->rd], rcount);
      return n;
    }
   
    /* assuming that the OS is not a piece of shit */
    ASSERT(n <= rcount);

    qp_rd->len += n;
    n = qp_rd->len - qp_rd->rd;
    memcpy(buf, &qp_rd->buf[qp_rd->rd], n);
    qp_rd->rd += n;
    return n;
  }
  else
    return sys_read(fd, buf, count);
}
示例#7
0
qp_source_t qp_source_create(const char *filename, int value_type)
{
  struct qp_source *source;
  struct qp_reader rd;
  int r;

  source = make_source(filename, value_type);

  rd.fd = -1;
  rd.rd = 0;
  rd.len = 0;
  rd.past = 0;
  rd.file = NULL;
  rd.buf = NULL;
  rd.filename = (char *) filename;
  qp_rd = &rd;

  if(strcmp(filename,"-") == 0)
  {
    rd.file = stdin;
    rd.fd = STDIN_FILENO;
  }

  if(rd.fd == -1)
    rd.fd = open(filename, O_RDONLY);

  if(rd.fd == -1)
  {
    EWARN("open(\"%s\",O_RDONLY) failed\n", filename);
    QP_EWARN("%sFailed to open file%s %s%s%s\n",
        bred, trm, btur, filename, trm);
    goto fail;
  }

  if(!is_pipe(&rd))
  {
    /* don't buffer read() and lseek() */
    qp_rd = NULL;
  }
  else
  {
    /* this is a pipe */
    DEBUG("Virturalizing a pipe%s%s\n",
        (filename[0] == '-' && filename[1] == '\0')?
        "":" with name ",
        (filename[0] == '-' && filename[1] == '\0')?
        "":filename);
    rd.buf = qp_malloc(BUF_LEN);
  }

  if((r = read_sndfile(source, &rd)))
  {
    if(r == -1)
      goto fail;


    if(rd.past && qp_rd)
    {
      VASSERT(0, "libsndfile read to much data "
          "to see that the file was not a sndfile\n");
      QP_WARN("%sFailed to read file%s %s%s%s:"
          " read wrapper failed\n",
          bred, trm, btur, filename, trm);
      goto fail;
    }

    if(qp_rd)
    {
      /* Start reading the data from the qp_rd read() buffer */
      rd.rd = 0;
      /* no need to add more to the qp_rd read() buffer */
      rd.fd = -1;
    }
    /* The above lseek() should work fine. */
    else if(lseek(rd.fd, 0, SEEK_SET))
    {
      EWARN("lseek(fd=%d, 0, SEEK_SET) failed\n", rd.fd);
      QP_EWARN("%sFailed to read file%s %s%s%s: lseek() failed\n",
          bred, trm, btur, filename, trm);
    }

    if(!rd.file)
    {
      errno = 0;
      rd.file = fdopen(rd.fd, "r");
      ASSERT(fileno(rd.file) == rd.fd);
    }
    if(!rd.file)
    {
      EWARN("fopen(\"%s\",\"r\") failed\n", filename);
      QP_EWARN("%sFailed to open file%s %s%s%s\n",
          bred, trm, btur, filename, trm);
      goto fail;
    }

    errno = 0;

    if(read_ascii(source, &rd))
      goto fail;
  }

  if(rd.buf)
  {
    free(rd.buf);
    rd.buf = NULL;
  }

  {
    /* remove any channels that have very bad data */
    struct qp_channel **c;
    size_t i = 0, chan_num = 0;
    ASSERT(source->channels);
    c = source->channels;
    while(c[i])
    {
      ASSERT(c[i]->form == QP_CHANNEL_FORM_SERIES);
      if(!is_good_double(c[i]->series.min) ||
          !is_good_double(c[i]->series.max))
      {
        struct qp_channel **n;
        
        qp_channel_destroy(c[i]);

        /* move of all pointers from c[i+1] back one */
        for(n=&c[i]; *n;++n)
          *n = *(n+1);

        /* re-malloc copying and removing one */
        source->channels = 
          qp_realloc(source->channels, sizeof(struct qp_channel *)*
              ((source->num_channels)--));
        
        /* reset c to the next one which is now at the
         * same index */
        c = source->channels;

        QP_NOTICE("removed bad channel number %zu\n", chan_num);
      }
      else
        ++i;
      ++chan_num;
    }
    ASSERT(source->num_channels == i);
  }
  
  
  if(source->num_channels == 0)
    goto fail;


  if(source->num_channels > 1)
  {
    /****** Check that there is at least one point in all the channels */
    ssize_t i, num;
    double *x;
    num = source->num_values;
    x = qp_malloc(sizeof(double)*source->num_channels);
    for(i=0;i<source->num_channels;++i)
      x[i] = qp_channel_series_double_begin(source->channels[i]);

    while(num)
    {
      int found = 0;
      for(i=0;i<source->num_channels;++i)
        if(is_good_double(x[i]))
          ++found;

      if(found >= 2)
        /* that means there is at least one x/y point
         * in all the channels. */
        break;

      --num;
      if(!num)
        break;

      for(i=0;i<source->num_channels;++i)
        x[i] = qp_channel_series_double_next(source->channels[i]);
    }

    if(!num)
    {
      QP_WARN("Failed to find a good point in data from file \"%s\"\n",
          filename);
      goto fail;
    }
  }

  
  if(source->num_channels == 0)
    goto fail;


  if(app->op_linear_channel || source->num_channels == 1)
  {
    /* Prepend a linear channel */

    /* TODO: Make this use less memory */
    
    struct qp_channel *c, **new_channels;
    double start = 0, step = 1;
    size_t len, i;

    if(app->op_linear_channel)
    {
      c = app->op_linear_channel;
      ASSERT(c->data);
      start = ((double*)c->data)[0];
      step = ((double*)c->data)[1];
    }
    else
    {
      c = qp_channel_linear_create(start, step);
    }


    len = source->num_values;
    for(i=0;i<len;++i)
      qp_channel_series_double_append(c, start + i*step);
   
    /* Prepend the channel to source->channels */
    /* reuse dummy len */
    len = source->num_channels + 1;
    new_channels = qp_malloc(sizeof(c)*len+1);
    new_channels[0] = c;
    for(i=1;i<len;++i)
      new_channels[i] = source->channels[i-1];
    new_channels[i] = NULL;
    free(source->channels);
    source->channels = new_channels;
    ++(source->num_channels);

    if(source->labels && source->num_labels !=  source->num_channels)
    {
      // shift the labels and add the linear channel label
      source->labels = qp_realloc(source->labels,
          sizeof(char *)*(source->num_labels+2));
      source->labels[source->num_labels+1] = NULL;
      for(i=source->num_labels;i>=1;--i)
        source->labels[i] = source->labels[i-1];

      char s[128];
      snprintf(s,128, "%s[0]", source->name);
      // The first channel is the linear channel.
      source->labels[0] = qp_strdup(s);
      ++source->num_labels;
    }

    /* Another source may have more values so
     * we must make a new one in case it is used again. */
    if(app->op_linear_channel)
      app->op_linear_channel = qp_channel_linear_create(start, step);
  }
  
  add_source_buffer_remove_menus(source);
  
  {
    char skip[64];
    skip[0] = '\0';
    if(app->op_skip_lines)
      snprintf(skip, 64, "(after skipping %zu) ", app->op_skip_lines);


    INFO("created source with %zu sets of values %s"
      "in %zu channels from file %s\n",
      source->num_values, skip, source->num_channels,
      filename);

    QP_INFO("created source with %zu sets of "
      "values %sin %zu channels from file \"%s\"\n",
      source->num_values, skip, source->num_channels,
      filename);
#if QP_DEBUG
    if(source->labels)
    {
      char **labels;
      APPEND("Read labels:");
      for(labels = source->labels; *labels; ++labels)
        APPEND(" \"%s\"", *labels);
      APPEND("\n");
    }
#endif
  }

  qp_rd = NULL;

  if(strcmp(filename,"-") == 0)
    /* We do not close stdin */
    return source;

  if(rd.file)
    fclose(rd.file);
  else if(rd.fd != -1)
    close(rd.fd);

  qp_app_graph_detail_source_remake();
  qp_app_set_window_titles();

  return source;

fail:

  QP_WARN("No data loaded from file \"%s\"\n",
      filename);

  if(rd.buf)
    free(rd.buf);

  if(strcmp(filename,"-") != 0)
  {
    if(rd.file)
      fclose(rd.file);
    else if(rd.fd != -1)
      close(rd.fd);
  }

  if(source)
    qp_source_destroy(source);

  qp_rd = NULL;

  return NULL;
}
示例#8
0
static
int read_ascii(qp_source_t source, struct qp_reader *rd)
{
  char *line = NULL;
  size_t line_buf_len = 0;
  ssize_t n;
  size_t line_count = 0;
  int (*parse_line)(struct qp_source *source,
      char *line);
  int data_flag = -1;

  /* TODO: check for other types */
  source->value_type = QP_TYPE_DOUBLE;

  switch(source->value_type)
  {
    /* TODO: brake these cases up into
     * other data parsers. */
    case QP_TYPE_DOUBLE:

      parse_line = qp_source_parse_doubles;
      break;

  /* TODO: add other cases */

    default:
      ASSERT(0);
      break;
  }

  if(app->op_skip_lines)
  {
    size_t skip_lines;
    skip_lines = app->op_skip_lines;

    while(skip_lines--)
    {
      errno = 0;
      n = Getline(&line, &line_buf_len, rd->file);

      ++line_count;

      if(n == -1 || errno)
      {
        if(!errno)
        {
          /* end-of-file so it is zero length */
          WARN("getline() read no data in file %s\n",
            source->name);
          QP_WARN("read no data in file %s\n",
            source->name);
        }
        else
        {
          EWARN("getline() read no data in file %s\n",
            source->name);
          QP_EWARN("read no data in file %s\n",
            source->name);
        }

        if(line)
          free(line);
        return 1; /* error */
      }
    }
  }

#define CHUNK 16

  if(app->op_labels)
  {
    char *s, *sep;
    size_t sep_len, num_labels = 0, mem_len = CHUNK;

    source->labels = qp_malloc(sizeof(char *)*(mem_len+1));

    errno = 0;
    n = Getline(&line, &line_buf_len, rd->file);

    ++line_count;

    if(n == -1 || errno)
    {
      if(!errno)
      {
        /* end-of-file so it is zero length */
        WARN("getline() read no data in file %s\n",
          source->name);
        QP_WARN("read no data in file %s\n",
          source->name);
      }
      else
      {
        EWARN("getline() read no data in file %s\n",
          source->name);
        QP_EWARN("read no data in file %s\n",
          source->name);
      }

      if(line)
          free(line);
        return 1; /* error */
    }

    s = line;
    sep = app->op_label_separator;
    sep_len = strlen(sep);
    
    do
    {
      char *end;
      size_t len;
      end = s;
      /* find the next separator */
      end = s;
      while(*end && *end != '\n' && *end != '\r' &&
          strncmp(end, sep, sep_len))
        ++end;

      /* *end == '\0' or end == "the separator" */
      len = end - s;
      /* get a label */
      source->labels[num_labels] = qp_strndup(s, len);
      ++num_labels;

      if(!(*end) || *end == '\n' || *end == '\r')
        break;

      /* skip the separator */
      s = end + sep_len;
      if(!(*s))
        break;

      if(num_labels == mem_len)
      {
        mem_len += CHUNK;
        source->labels = qp_realloc(source->labels,
            sizeof(char *)*(mem_len+1));
      }

    } while(*s);

    source->labels[num_labels] = NULL;
    source->num_labels = num_labels;
  }
#undef CHUNK

  do
  {
    /* we seperate the first read because it shows
     * the error case when the file has no data at all. */
    errno = 0;
    n = Getline(&line, &line_buf_len, rd->file);

    ++line_count;
    if(n == -1 || errno)
    {
      if(!errno)
      {
        /* end-of-file so it is zero length */
        WARN("getline() read no data in file %s\n",
            source->name);
        QP_WARN("read no data in file %s\n",
            source->name);
      }
      else
      {
        EWARN("getline() read no data in file %s\n",
            source->name);
        QP_EWARN("read no data in file %s\n",
            source->name);

      }
      if(line)
        free(line);
      return 1; /* error */
    }
    data_flag = parse_line(source, line);
  } while(data_flag == 0);

  /* Now we have an least one line of values.
   * We would have returned if we did not. */

  errno = 0;
  while((n = Getline(&line, &line_buf_len, rd->file)) > 0)
  {
    ++line_count;
    parse_line(source, line);
    errno = 0;
  }

  if(line)
    free(line);

  /* n == -1 and errno == 0 on end-of-file */
  if((n == -1 && errno != 0) || errno)
  {
#if QP_DEBUG
    if(errno)
      EWARN("getline() failed to read file %s\n",
          source->name);
    else
      WARN("getline() failed to read file %s\n",
          source->name);
#endif
    QP_WARN("failed to read file %s\n", source->name);
    return 1; /* error */
  }

  return 0; /* success */
}