static int count_bes(slotnum_t gslotnum, int max) {
    slotnum_t bslotnum;
    int count;

    for (bslotnum = FILE_SLOT(gr_slot, gslotnum).be_head, count = 0;
         bslotnum && count < max;
	 bslotnum = speedy_slot_next(bslotnum))
    {
	++count;
    }
    return count;
}
/* Kill and remove all be's in the be_wait list */
void speedy_backend_remove_be_wait(slotnum_t gslotnum) {
    gr_slot_t *gslot = &FILE_SLOT(gr_slot, gslotnum);
    slotnum_t bslotnum, next;

    for (bslotnum = gslot->be_head;
         bslotnum && !FILE_SLOT(be_slot, bslotnum).fe_running;
	 bslotnum = next)
    {
	next = speedy_slot_next(bslotnum);
	speedy_util_kill(FILE_SLOT(be_slot, bslotnum).pid, SIGTERM);
    }
}
Exemple #3
0
int
main(int argc, char **argv)
{
  char filename[PATH_MAX];
  int sz = 0;
  char *data = NULL;

  sprintf(filename, "/tmp/speedy.6.%x.F", geteuid());

  FILE *fh = fopen(filename, "r");
  if (fh) {
    struct stat st;
    if (stat(filename, &st) == 0) {
      sz = st.st_size;
    }

    if (sz) {
      data = malloc(sz);
      fread(data, 1, sz, fh);
    }
  } else {
    printf("Cannot read file (%s).\n", filename);
  }

  if (data) {
    speedy_file_t *speedy_file_maddr = (speedy_file_t*)data;
    file_head_t *h = &FILE_HEAD;
    slotnum_t slotnum, num1;
    slot_t *slot;
    int i;
    time_t ctime = h->create_time.tv_sec;

    printf("{\n");
    printf("  header => {\n");
    printf("    create_time   => { sec => %d, usec => %d, text => '%s' },\n", h->create_time.tv_sec, h->create_time.tv_usec, ptime(&ctime));
    printf("    lock_owner    => %d,\n", h->lock_owner);
    printf("    group_head    => %d,\n", h->group_head);
    printf("    group_tail    => %d,\n", h->group_tail);
    printf("    slot_free     => %d,\n", h->slot_free);
    printf("    slots_alloced => %d,\n", h->slots_alloced);
    printf("    fe_run_head   => %d,\n", h->fe_run_head);
    printf("    fe_run_tail   => %d,\n", h->fe_run_tail);
    printf("    file_removed  => %d\n", h->file_removed);
    printf("  },\n");

    printf("  free_slots => [ ");
    for (slotnum = h->slot_free; !BAD_SLOTNUM(slotnum);
	 slotnum = speedy_slot_next(slotnum)) {
      printf("%d", slotnum);
      if (!BAD_SLOTNUM(speedy_slot_next(slotnum))) printf(", ");
    }
    printf(" ],\n");

    printf("  fe_running => [ ");
    for (slotnum = h->fe_run_head; !BAD_SLOTNUM(slotnum);
	 slotnum = speedy_slot_next(slotnum)) {
      printf("%d\n", slotnum);
      if (!BAD_SLOTNUM(speedy_slot_next(slotnum))) printf(", ");
    }
    printf(" ],\n");

    printf("  group_list => {\n");
    for (slotnum = h->group_head; !BAD_SLOTNUM(slotnum);
	 slotnum = speedy_slot_next(slotnum)) {
      gr_slot_t *gr = &FILE_SLOT(gr_slot, slotnum);
      grnm_slot_t *name = &FILE_SLOT(grnm_slot, gr->name_slot);
      scr_slot_t *scr = &FILE_SLOT(scr_slot, gr->script_head);
      printf("    index       => %d,\n", slotnum);
      printf("    be_starting => %d,\n", gr->be_starting);
      printf("    be_parent   => { pid => %d },\n", gr->be_parent);
      printf("    script_head => %d,\n", gr->script_head);
      printf("    scripts     => [\n");
      for (num1 = gr->script_head; !BAD_SLOTNUM(num1);
	   num1 = speedy_slot_next(num1)) {
	scr = &FILE_SLOT(scr_slot, num1);
	printf("      {\n");
	printf("        index   => %d,\n", num1);
	printf("        dev_num => %d,\n", scr->dev_num);
	printf("        ino_num => %d,\n", scr->ino_num);
	printf("        mtime   => { sec => %d, text => '%s' }\n",
	       scr->mtime, ptime(&scr->mtime));
	printf("      }");
	if (!BAD_SLOTNUM(speedy_slot_next(slotnum))) printf(", ");
      }
      printf("  ],\n");
      printf("    name_slot   => { index => %d, text => '%s' },\n",
	     gr->name_slot, name->name);
      printf("    be_head     => %d,\n", gr->be_head);
      printf("    be_tail     => %d,\n", gr->be_tail);
      printf("    fe_head     => %d,\n", gr->fe_head);
      printf("    fe_tail     => %d,\n", gr->fe_tail);
      printf("    fe_wait_list => [\n");
      for (num1 = gr->fe_head; !BAD_SLOTNUM(num1);
	   num1 = speedy_slot_next(num1)) {
	fe_slot_t *fe = &FILE_SLOT(fe_slot, num1);
	printf("      {\n");
	printf("        index       => %d,\n", num1);
	printf("        pid         => { pid => %d },\n", fe->pid);
	printf("        exit_val    => %d,\n", fe->exit_val);
	printf("        backend     => %d,\n", fe->backend);
	printf("        exit_on_sig => %d,\n", fe->exit_on_sig);
	printf("        sent_sig    => %d,\n", fe->sent_sig);
	printf("      },\n");
      }
      printf("    ],\n");
      printf("    be_list => [\n");
      for (num1 = gr->be_head; !BAD_SLOTNUM(num1);
	   num1 = speedy_slot_next(num1)) {
	be_slot_t *be = &FILE_SLOT(be_slot, num1);
	printf("      {\n");
	printf("        index      => %d,\n", num1);
	printf("        pid        => { pid => %d },\n", be->pid);
	printf("        fe_running => %d,\n", be->fe_running);
	printf("        maturity   => %d\n", be->maturity);
	printf("      },\n");
      }
      printf("    ]\n");
      printf("  }\n");
    }
    printf("}\n");
  }

  return 0;
}