void teardown_netstream(NetStream_t *ns)
{
    close_netstream(ns);
    apr_thread_mutex_destroy(ns->read_lock);
    apr_thread_mutex_destroy(ns->write_lock);
    apr_pool_destroy(ns->mpool);
}
int main(int argc, char **argv)
{
  int bufsize = 1024*1024;
  char buffer[bufsize], *bstate;
  int n;
  Net_timeout_t dt;
  NetStream_t *ns;
  char cmd[512];
  char *host;
  int port = 6714;
  int timeout = 15;


  if (argc < 2) {
     printf("get_version -a | host [port timeout]\n");
     printf("   -a   -Use the local host and default port\n");
     return(0);
  }

  if (strcmp(argv[1], "-a") == 0) {
    host = (char *)malloc(1024);
    gethostname(host, 1023);
  } else {
    host = argv[1];
  }

  if (argc > 2) port = atoi(argv[2]);
  if (argc == 4) timeout = atoi(argv[3]);
  set_net_timeout(&dt, timeout, 0);

  sprintf(cmd, "1 4 5 %d\n", timeout);  // IBP_ST_VERSION command

  assert(apr_initialize() == APR_SUCCESS);

  dns_cache_init(10);

  ns = cmd_send(host, port, cmd, &bstate, timeout);
  if (ns == NULL) return(-1);
  if (bstate != NULL) free(bstate);

  //** Read the result.  Termination occurs when the line "END" is read.
  //** Note that readline_netstream strips the "\n" from the end of the line
  n = NS_OK;
  while (n == NS_OK) {
     n = readline_netstream(ns, buffer, bufsize, dt);
     if (n == NS_OK) {
        if (strcmp(buffer, "END") == 0) {
           n = NS_OK+1;
        } else {
           printf("%s\n", buffer);
        }
     }
  }

  //** Close the connection
  close_netstream(ns);

  apr_terminate();
  return(0);
}
void *monitor_thread(apr_thread_t *th, void *data)
{
    ns_monitor_t *nm = (ns_monitor_t *)data;
    NetStream_t *ns = nm->ns;
    int i;

    log_printf(15, "monitor_thread: Monitoring port %d\n", nm->port);

    apr_thread_mutex_lock(nm->lock);
    while (nm->shutdown_request == 0) {
        apr_thread_mutex_unlock(nm->lock);

        i = ns->connection_request(ns->sock, 1);

        if (i == 1) {  //** Got a request
            log_printf(15, "monitor_thread: port=%d ns=%d Got a connection request time=" TT "\n", nm->port, ns_getid(ns), apr_time_now());

            //** Mark that I have a connection pending
            apr_thread_mutex_lock(nm->lock);
            nm->is_pending = 1;
            apr_thread_mutex_unlock(nm->lock);

            //** Wake up the calling thread
            apr_thread_mutex_lock(nm->trigger_lock);
            (*(nm->trigger_count))++;
            apr_thread_cond_signal(nm->trigger_cond);
            apr_thread_mutex_unlock(nm->trigger_lock);

            log_printf(15, "monitor_thread: port=%d ns=%d waiting for accept\n", nm->port, ns_getid(ns));

            //** Sleep until my connection is accepted
            apr_thread_mutex_lock(nm->lock);
            while ((nm->is_pending == 1) && (nm->shutdown_request == 0)) {
                apr_thread_cond_wait(nm->cond, nm->lock);
                log_printf(15, "monitor_thread: port=%d ns=%d Cond triggered=" TT " trigger_count=%d\n", nm->port, ns_getid(ns), apr_time_now(), *(nm->trigger_count));
            }
            apr_thread_mutex_unlock(nm->lock);
            log_printf(15, "monitor_thread: port=%d ns=%d Connection accepted time=" TT "\n", nm->port, ns_getid(ns), apr_time_now());

            //** Update pending count
//         apr_thread_mutex_lock(nm->trigger_lock);
//         *(nm->trigger_count)--;
//         apr_thread_mutex_unlock(nm->trigger_lock);
        }

        apr_thread_mutex_lock(nm->lock);
    }

    apr_thread_mutex_unlock(nm->lock);

    //** Lastly shutdown my socket
    close_netstream(ns);

    log_printf(15, "monitor_thread: Closing port %d\n", nm->port);

    apr_thread_exit(th, 0);

    return(NULL);
}
int main(int argc, char **argv)
{
  int bufsize = 1024*1024;
  char buffer[bufsize], *bstate;
  int i, port, delay, timeout, slen;
  char *host, *rid, *msg;
  NetStream_t *ns;

  if (argc < 5) {
     printf("ibp_detach_rid host port RID delay_before_umount [msg]\n");
     printf("\n");
     return(0);
  }

  i = 1;
  host = argv[i]; i++;
  port = atoi(argv[i]); i++;
  rid = argv[i]; i++;
  delay = atoi(argv[i]); i++;

  timeout = 3600;
  if (timeout < delay) timeout = delay + 30;  //** Make sure the timeout is longer than the delay

  msg = "";
  if (argc > i) msg = argv[i];

  slen = strlen(msg);
  sprintf(buffer, "1 92 %s %d %d %d %s\n", rid, delay, timeout, slen, msg);  // IBP_INTERNAL_RID_UMOUNT command

//printf("argc=%d i=%d command=%s\n", argc, i, buffer);
//return(0);
  assert(apr_initialize() == APR_SUCCESS);

  dns_cache_init(10);

  ns = cmd_send(host, port, buffer, &bstate, timeout);
  if (ns == NULL) return(-1);
  if (bstate != NULL) free(bstate);

  //** Close the connection
  close_netstream(ns);

  apr_terminate();

  return(0);
}
Exemple #5
0
int main(int argc, char **argv)
{
  int bufsize = 1024*1024;
  char buffer[bufsize], *bstate;
  int err;
  int n;
  Net_timeout_t dt;


  if (argc < 3) {
     printf("get_version host port [timeout]\n");
     return(0);
  }

  char cmd[512];
  char *host = argv[1];
  int port = atoi(argv[2]);
  int timeout = 15;

  if (argc == 4) timeout = atoi(argv[3]);

  sprintf(cmd, "1 4 5 %d\n", timeout);  // IBP_ST_VERSION command

  dns_cache_init(10);

  NetStream_t *ns = new_netstream();
  ns_config_sock(ns, -1, 0);
  set_net_timeout(&dt, 5, 0);

  //** Make the host connection
  err = net_connect(ns, host, port, dt);
  if (err != 0) {
     printf("get_version:  Can't connect to host!  host=%s port=%d  err=%d\n", host, port, err);
     return(err);
  }


  //** Send the command
  n = write_netstream(ns, cmd, strlen(cmd), dt);
  n = readline_netstream(ns, buffer, bufsize, dt);
  if (n == IBP_OK) {  
     n = atoi(string_token(buffer, " ", &bstate, &err));
     if (n != IBP_OK) {
        printf("Error %d returned!\n", n);
        close_netstream(ns);
        return(n);
     }
  }

  //** Read the result.  Termination occurs when the line "END" is read.
  //** Note that readline_netstream strips the "\n" from the end of the line
  n = 1;
  while (n > 0) {
     n = readline_netstream(ns, buffer, bufsize, dt);
     if (n > 0) {     
        if (strcmp(buffer, "END") == 0) {
           n = 0;
        } else {  
           printf("%s\n", buffer);
        }
     }
  }

  //** Close the connection
  close_netstream(ns);

  return(0);
}
Exemple #6
0
int main(int argc, char **argv)
{
  int bufsize = 1024*1024;
  char buffer[bufsize], *bstate;
  int err, i, mode;
  Net_timeout_t dt;
  time_t t;
  osd_id_t id;
  char print_time[128];
  uint64_t bytes, total_bytes;
  double fb1, fb2;
  uint64_t base_unit;
  double units;

  if (argc < 7) {
     printf("expire_list host port RID mode time count\n");
     printf("\n");
     printf("  mode  - abs or rel\n");
     printf("  time  - Future time with format of days:hours:min:sec\n");
     printf("  count - Number of allocations to retreive\n");
     printf("\n");
     return(0);
  }

  base_unit = 1024 * 1024;
  units = base_unit;
  units = 1.0 / units;

  i = 1;
  char *host = argv[i]; i++;
  int port = atoi(argv[i]); i++;
  char *rid = argv[i]; i++;
  mode = 0;
  if (strcmp(argv[i], "abs") == 0) mode = 1; 
  i++;
  t = parse_time(argv[i]); i++;
  int count = atoi(argv[i]);

  dns_cache_init(10);

  NetStream_t *ns = new_netstream();
  ns_config_sock(ns, -1, 0);

  set_net_timeout(&dt, 5, 0);

  err = net_connect(ns, host, port, dt);
  if (err != 0) {
     printf("get_alloc:  Can't connect to host!  host=%s port=%d  err=%d\n", host, port, err);
     return(err);
  }

  sprintf(buffer, "1 %d %s %d " TT " %d 10\n", INTERNAL_EXPIRE_LIST, rid, mode, t, count);
  err = write_netstream(ns, buffer, strlen(buffer), dt);
  err = readline_netstream(ns, buffer, bufsize, dt);
  if (err > 0) {  
     err = atoi(string_token(buffer, " ", &bstate, &err));
     if (err != IBP_OK) {
        printf("Error %d returned!\n", err);
        close_netstream(ns);
        return(err);
     }
  }

  //** Cycle through the data **
  total_bytes = 0;

  printf("n Time date ID  mb_max total_max_mb\n");
  printf("------------------------------------------------------------------------------------------------------\n");
  err = 0;  
  i = 0;
  while (err != -1) {
     buffer[0] = '\0';
     err = readline_netstream(ns, buffer, bufsize, dt);
//printf("err=%d buf=%s\n", err, buffer);
     if (err > 0) {     
        if (strcmp("END", buffer) == 0) { //** Finished
           err = -1;
        } else {
          parse_line(buffer, &t, &id, &bytes);
          ctime_r(&t, print_time); print_time[strlen(print_time)-1] = '\0';
          total_bytes = total_bytes + bytes;
          fb1 = bytes * units;
          fb2 = total_bytes  * units;

          printf("%4d " TT " * %s * " LU " * %lf * %lf\n", i, t, print_time, id, fb1, fb2);
        }
     }

     i++;
  }

  close_netstream(ns);

  printf("\n");

  return(0);
}