Exemplo n.º 1
0
int memcache_get (struct connection *c, const char *key, int key_len) {
  if (verbosity >= 3) {
    fprintf (stderr, "memcache_get: key='%s'\n", key);
  }
  struct fuse_file_info fi;
  if (key_len >= 5 && !strncmp (key, "stats", 5)) {
    int stats_len = filesys_prepare_stats(c);
    return_one_key (c, key, value_buff, stats_len);
    return 0;
  }
  cmd_get++;
  if (key_len <= 0) {
    return 0;
  }
  int r = -11;
  int x;
  unsigned int offset, length;
  inode_id_t inode;

  switch (key[0]) {
    case 'c':
      if (!strncmp (key, "creat", 5) && sscanf (key, "creat%d", &x) >= 1 && !parse_path (c)) {
        r = ff_create (value_buff, x, &fi);
        if (!r) {
          return_one_long (c, key, fi.fh);
        }
      }
      break;
    case 'o':
      if (!strcmp (key, "open") && !parse_path (c)) {
        r = ff_open (value_buff, &fi);
        if (!r) {
          return_one_long (c, key, fi.fh);
        }
      }
      break;
    case 'r':
      if (!strncmp (key, "read", 4) && sscanf (key, "read%u,%u,%lld", &offset, &length, &inode) >= 3) {
        fi.fh = inode;
        r = ff_read (NULL, value_buff, length, offset, &fi);
        if (r >= 0) {
          return_one_key (c, key, value_buff, r);
        }
      }
  }

  free_tmp_buffers (c);
  return 0;
}
Exemplo n.º 2
0
uint64 ff_estimate_numentries(const char *ffpath) 
{
  // get the total size of the file
  int fffd = open(ffpath, O_RDONLY | O_LARGEFILE);
  if (fffd == -1)
    errexit("ff_read: could not open %s, %s\n", ffpath,
            khstrerror(errno).c_str());
  struct stat64 sb;
  fstat64(fffd, &sb);
  close(fffd);

  // get the average size of the first 10 records
  EstimateCallbackData estimate;
  if (ff_read(ffpath, EstimateCallback, &estimate) < 0) {
    errexit("ff_read: unable to sample file for entries estimate\n");
  }
  double averageSize = (double)estimate.totalSize / (double)estimate.num;

  // estimate by dividing the total file size by the average record size
  return (uint64)((double)sb.st_size / averageSize);
}