IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18098 for trunk/Ohana


Ignore:
Timestamp:
Jun 12, 2008, 12:52:06 PM (18 years ago)
Author:
eugene
Message:

use virtual stacks for host and job queries by user thread

Location:
trunk/Ohana/src/opihi/pcontrol
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pcontrol/CheckHost.c

    r17475 r18098  
    1515    host[0].markoff = FALSE;
    1616    StopHost (host);
    17     OffHost (host);
    1817    return (TRUE);
    1918  }
  • trunk/Ohana/src/opihi/pcontrol/CheckIdleHost.c

    r10667 r18098  
    1414    host[0].markoff = FALSE;
    1515    StopHost (host);
    16     OffHost (host);
    1716    return (TRUE);
    1817  }
  • trunk/Ohana/src/opihi/pcontrol/CheckSystem.c

    r17476 r18098  
    346346    if (host == NULL) break;
    347347    if (host[0].markoff) {
     348      // DOWN -> OFF
    348349      host[0].markoff = FALSE;
    349350      OffHost (host);
     
    354355      PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
    355356    } else {
     357      // DOWN -> IDLE (maybe)
     358      // this is a race condition with "host retry", but the only
     359      // consequence is that both StartHost and reset set the times to 0.0
    356360      StartHost (host);
    357361    }
  • trunk/Ohana/src/opihi/pcontrol/HostOps.c

    r17476 r18098  
    11# include "pcontrol.h"
     2
     3Stack *HostPool_AllHosts;  // virtual pool for user status queries
    24
    35Stack *HostPool_Idle; // these hosts are waiting for something to do
     
    911
    1012void InitHostStacks () {
     13  HostPool_AllHosts = InitStack ();
     14
    1115  HostPool_Idle = InitStack ();
    1216  HostPool_Busy = InitStack ();
     
    2630
    2731void FreeHostStacks () {
     32  // AllHosts is a virtual stack : all hosts are references
     33  FreeStack (HostPool_AllHosts);
     34
    2835  FreeHostStack (HostPool_Idle);
    2936  FreeHostStack (HostPool_Busy);
     
    3643char *GetHostStackName (int StackID) {
    3744  switch (StackID) {
     45    case PCONTROL_HOST_ALLHOSTS: return ("ALLHOSTS");
    3846    case PCONTROL_HOST_IDLE: return ("IDLE");
    3947    case PCONTROL_HOST_DOWN: return ("DOWN");
     
    5058Stack *GetHostStack (int StackID) {
    5159  switch (StackID) {
     60    case PCONTROL_HOST_ALLHOSTS: return (HostPool_AllHosts);
    5261    case PCONTROL_HOST_IDLE: return (HostPool_Idle);
    5362    case PCONTROL_HOST_DOWN: return (HostPool_Down);
     
    6372
    6473Stack *GetHostStackByName (char *name) {
     74  if (!strcasecmp (name, "all")) return (HostPool_AllHosts);
    6575  if (!strcasecmp (name, "idle")) return (HostPool_Idle);
    6676  if (!strcasecmp (name, "down")) return (HostPool_Down);
     
    202212  host[0].markoff  = FALSE;
    203213  host[0].job      = NULL;
     214
     215  PutHost (host, PCONTROL_HOST_ALLHOSTS, STACK_BOTTOM);
    204216  PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
    205217  return (host[0].HostID);
     
    207219
    208220void DelHost (Host *host) {
     221
     222  Host *copy;
     223
     224  copy = PullStackByID (HostPool_AllHosts, host[0].HostID);
     225  ASSERT (copy == host, "programming error: ALLHOSTS entry does not match");
     226
    209227  FreeIOBuffer (&host[0].comms_buffer);
    210228  FREE (host[0].hostname);
  • trunk/Ohana/src/opihi/pcontrol/IDops.c

    r8296 r18098  
    11# include "pcontrol.h"
    22
    3 static IDtype CurrentJobID  = 0;
    4 static IDtype CurrentHostID = 0;
     3static IDtype CurrentJobID  = 1;
     4static IDtype CurrentHostID = 1;
    55
    6 /* for now, no persistence : we could use the date/time to seed the upper byte(s) if needed */
     6/* for now, no persistence between sessions : we could use the date/time to seed the upper
     7 * byte(s) if needed */
    78void InitIDs () {
    8   CurrentJobID = 0;
    9   CurrentHostID = 0;
     9  CurrentJobID = 1;
     10  CurrentHostID = 1;
    1011}
    1112
     
    4142}
    4243
     44IDtype GetID (char *IDword) {
     45
     46  int Nargs;
     47  IDtype ID;
     48  unsigned int word0, word1, word2, word3;
     49  char *endptr;
     50
     51  Nargs = sscanf (IDword, "%x.%x.%x.%x", &word3, &word2, &word1, &word0);
     52  if (Nargs == 4) {
     53      IDtype tmp;
     54    ID = 0;
     55    ID |= (word0 << 0);
     56    ID |= (word1 << 16);
     57    tmp = word2;
     58    ID |= (tmp << 32);
     59    tmp = word3;
     60    ID |= (tmp << 48);
     61    return ID;
     62  }
     63   
     64  ID = strtoll (IDword, &endptr, 10);
     65  if (*endptr == 0) {
     66    return ID;
     67  }
     68
     69  return 0;
     70}
  • trunk/Ohana/src/opihi/pcontrol/JobID.c

    r7917 r18098  
    4040}
    4141
     42IDtype GetID (char *IDword) {
     43
     44  int Nargs;
     45  IDtype ID;
     46  unsigned short int word0, word1, word2, word3;
     47
     48  Nargs = sscanf (IDword, "%x.%x.%x.%x", &word0, &word1, &word2, &word3);
     49  if (Nargs == 4) {
     50    ID = 0;
     51    ID |= (word0 << 0);
     52    ID |= (word1 << 16);
     53    ID |= (word2 << 32);
     54    ID |= (word3 << 48);
     55    return ID;
     56  }
     57   
     58  ID = strtoll (IDword, &endptr, 10);
     59  if (*endptr == 0) {
     60    return ID;
     61  }
     62
     63  return 0;
     64}
  • trunk/Ohana/src/opihi/pcontrol/JobOps.c

    r18085 r18098  
    11# include "pcontrol.h"
    22
    3 // Stack *JobPool_AllJobs;
     3Stack *JobPool_AllJobs;  // virtual pool for user status queries
    44
    55Stack *JobPool_Pending;
     
    1212
    1313void InitJobStacks () {
    14   // JobPool_AllJobs = InitStack ();
     14  JobPool_AllJobs = InitStack ();
    1515
    1616  JobPool_Pending = InitStack ();
     
    3232
    3333void FreeJobStacks () {
    34 
    35   // AllJobs is a virtual stack : all jobs are references
    36   // FreeStack (JobPool_AllJobs);
    37 
    3834  FreeJobStack (JobPool_Pending);
    3935  FreeJobStack (JobPool_Busy   );
     
    4339  FreeJobStack (JobPool_Exit   );
    4440  FreeJobStack (JobPool_Crash  );
     41
     42  // AllJobs is a virtual stack : all jobs are references
     43  FreeStack (JobPool_AllJobs);
    4544}
    4645
    4746char *GetJobStackName (int StackID) {
    4847  switch (StackID) {
    49     // case PCONTROL_JOB_ALLJOBS: return ("ALLJOBS");
     48    case PCONTROL_JOB_ALLJOBS: return ("ALLJOBS");
    5049
    5150    case PCONTROL_JOB_PENDING: return ("PENDING");
     
    6463Stack *GetJobStack (int StackID) {
    6564  switch (StackID) {
    66     // case PCONTROL_JOB_ALLJOBS: return (JobPool_AllJobs);
     65    case PCONTROL_JOB_ALLJOBS: return (JobPool_AllJobs);
    6766
    6867    case PCONTROL_JOB_PENDING: return (JobPool_Pending);
     
    8180Stack *GetJobStackByName (char *name) {
    8281
    83   // if (!strcasecmp (name, "all"))     return (JobPool_AllJobs);
     82  if (!strcasecmp (name, "all"))     return (JobPool_AllJobs);
    8483
    8584  if (!strcasecmp (name, "pending")) return (JobPool_Pending);
     
    186185  job[0].argv     = argv;
    187186  job[0].hostname = hostname;
     187  job[0].realhost = NULL;
     188
     189  job[0].exit_status = 0;
     190  job[0].Reset    = FALSE;
     191  job[0].stdout_size = 0;
     192  job[0].stderr_size = 0;
     193
    188194  job[0].mode     = mode;
    189   job[0].host     = NULL;
    190   job[0].JobID    = NextJobID();
    191   job[0].Reset    = FALSE;
    192   job[0].realhost = NULL;
     195
     196  job[0].state = 0;
     197  job[0].stack = 0;
    193198
    194199  /* do this step on start? */
     
    196201  InitIOBuffer (&job[0].stderr_buff, 0x1000);
    197202
     203  job[0].dtime = 0.0;
     204  job[0].pid = 0;
     205
     206  job[0].JobID    = NextJobID();
     207  job[0].host     = NULL;
     208
    198209  JobID = job[0].JobID;
    199210
     211  // Put a copy of all created jobs on the ALLJOBS stack
     212  // This is a virtual stack: do not free the job from this stack
     213  PutJob (job, PCONTROL_JOB_ALLJOBS, STACK_BOTTOM);
    200214  PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM);
    201   // PutJob (job, PCONTROL_JOB_ALLJOBS, STACK_BOTTOM);
    202215
    203216  if (VerboseMode()) gprint (GP_ERR, "added new job\n");
     
    208221
    209222  int i;
     223
     224  Job *copy;
     225
     226  copy = PullStackByID (JobPool_AllJobs, job[0].JobID);
     227  ASSERT (copy == job, "programming error: ALLJOBS entry does not match");
    210228
    211229  FREE (job[0].hostname);
  • trunk/Ohana/src/opihi/pcontrol/StopHosts.c

    r17475 r18098  
    9595int StopHostResponse (Host *host) {
    9696
     97  OffHost (host);
    9798  HarvestHost (host[0].pid);
    9899  return (TRUE);
     
    104105  int i, result, waitstatus;
    105106
    106   gprint (GP_ERR, "harvesting within thread %d\n", pthread_self());
    107   gprint (GP_ERR, "child process %d is down, wait for exit status\n", pid);
     107  if (VerboseMode()) gprint (GP_ERR, "harvesting within thread %p\n", pthread_self());
     108  if (VerboseMode()) gprint (GP_ERR, "child process %d is down, wait for exit status\n", pid);
    108109 
    109110  // Loop a few times waiting for child to exit
  • trunk/Ohana/src/opihi/pcontrol/check.c

    r11388 r18098  
    33int check (int argc, char **argv) {
    44
    5   Job *job;
    6   Host *host;
    7   int JobID, HostID, StackID;
     5  int JobID, HostID;
     6
     7  Stack *stack = NULL;
     8  Job *job = NULL;
     9  Host *host = NULL;
    810
    911  if (argc != 3) {
     
    1416
    1517  if (!strcasecmp (argv[1], "JOB")) {
    16     JobID = atoi (argv[2]);
     18    JobID = GetID (argv[2]);
     19    if (!JobID) {
     20      gprint (GP_ERR, "invalid job id %s\n", argv[2]);
     21      return (FALSE);
     22    }
    1723
    18     SetCheckPoint ();  // ensure the JOB is on one of the stacks
    19     job = PullJobByID (JobID, &StackID);
     24    stack = GetJobStack (PCONTROL_JOB_ALLJOBS);
     25    job = PullStackByID (stack, JobID);
    2026    if (job == NULL) {
    2127      gprint (GP_LOG, "job not found\n");
    22       ClearCheckPoint ();
    2328      return (FALSE);
    2429    }
    25     gprint (GP_LOG, "STATUS %s\n", GetJobStackName(StackID));
     30
     31    gprint (GP_LOG, "STATUS %s\n", GetJobStackName(job[0].stack));
    2632    gprint (GP_LOG, "EXITST %d\n", job[0].exit_status);
    2733    gprint (GP_LOG, "STDOUT %d\n", job[0].stdout_size);
     
    3339        gprint (GP_LOG, "HOSTNAME NONE\n");
    3440    }
    35     PutJob (job, StackID, STACK_BOTTOM);
    36     ClearCheckPoint ();
     41    PushStack (stack, STACK_BOTTOM, job, job[0].JobID, job[0].argv[0]);
    3742    return (TRUE);
    3843  }
     
    4146    HostID = atoi (argv[2]);
    4247
    43     SetCheckPoint ();  // ensure the HOST is on one of the stacks
    44     host = PullHostByID (HostID, &StackID);
     48    stack = GetHostStack (PCONTROL_HOST_ALLHOSTS);
     49    host = PullStackByID (stack, HostID);
    4550    if (host == NULL) {
    4651      gprint (GP_LOG, "host not found\n");
    47       ClearCheckPoint ();
    4852      return (FALSE);
    4953    }
    50     gprint (GP_LOG, "host %s\n", GetHostStackName(StackID));
    51     PutHost (host, StackID, STACK_BOTTOM);
    52     ClearCheckPoint ();
     54    gprint (GP_LOG, "host %s\n", GetHostStackName(host[0].stack));
     55    PushStack (stack, STACK_BOTTOM, host, host[0].HostID, host[0].hostname);
    5356    return (TRUE);
    5457  }
  • trunk/Ohana/src/opihi/pcontrol/delete.c

    r8296 r18098  
    1010    return (FALSE);
    1111  }
    12   JobID = atoi (argv[1]);
     12  JobID = GetID (argv[1]);
     13  if (!JobID) {
     14    gprint (GP_ERR, "invalid job id %s\n", argv[1]);
     15    return (FALSE);
     16  }
     17     
    1318  /* use a string interp to convert JobIDs to ints ? */
    1419
  • trunk/Ohana/src/opihi/pcontrol/host.c

    r10652 r18098  
    11# include "pcontrol.h"
    22
    3 // we use CheckPoints in this function to prevent objects in flight from being missing.
    43int host (int argc, char **argv) {
    54
    6   int StackID;
    75  IDtype HostID;
    86  Host *host;
     7  Stack *AllHosts;
    98
    109  if (argc != 3) goto usage;
     10
     11  AllHosts = GetHostStack (PCONTROL_HOST_ALLHOSTS);
    1112
    1213  if (!strcasecmp (argv[1], "ADD")) {
     
    1516    return (TRUE);
    1617  }
     18
     19  // this one is safe from in-flight entries: no one else pulls from OFF
    1720  if (!strcasecmp (argv[1], "ON")) {
    1821    host = PullHostFromStackByName (PCONTROL_HOST_OFF, argv[2]);
     
    2528    return (TRUE);
    2629  }
     30
     31  // this is a race condition with "CheckDownHosts", but the only
     32  // consequence is that both StartHost and reset set the times to 0.0
    2733  if (!strcasecmp (argv[1], "RETRY")) {
    2834    // no need to use a check point [thief: CheckDownHost (DOWN->IDLE)]
    29     host = PullHostFromStackByName (PCONTROL_HOST_DOWN, argv[2]);
     35    host = PullHostFromStackByName (PCONTROL_HOST_ALLHOSTS, argv[2]);
    3036    if (!host) {
     37      gprint (GP_LOG, "host %s not found\n", argv[2]);
     38      return (FALSE);
     39    }
     40    if (host[0].stack != PCONTROL_HOST_DOWN) {
    3141      gprint (GP_LOG, "host %s is not DOWN\n", argv[2]);
    3242      return (FALSE);
    3343    }
    34     /* reset time, place back on DOWN stack */
     44    /* reset time, place back on ALLHOSTS stack */
    3545    host[0].nexttry.tv_sec  = 0;
    3646    host[0].nexttry.tv_usec = 0;
    3747    host[0].lasttry.tv_sec  = 0;
    3848    host[0].lasttry.tv_usec = 0;
    39     PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
     49    PushStack (AllHosts, STACK_BOTTOM, host, host[0].HostID, host[0].hostname);
    4050    return (TRUE);
    4151  }
     52
    4253  if (!strcasecmp (argv[1], "CHECK")) {
    43     SetCheckPoint ();  // ensure the host is on one of the stacks
    44     host = PullHostByName (argv[2], &StackID);
     54    host = PullHostFromStackByName (PCONTROL_HOST_ALLHOSTS, argv[2]);
    4555    if (host == NULL) {
    4656      gprint (GP_LOG, "host %s not found\n", argv[2]);
    47       ClearCheckPoint ();
    4857      return (FALSE);
    4958    }
    50     PutHost (host, StackID, STACK_BOTTOM);
    51     ClearCheckPoint ();
    52 
    53     gprint (GP_LOG, "host %s is %s\n", argv[2], GetHostStackName (StackID));
     59    gprint (GP_LOG, "host %s is %s\n", argv[2], GetHostStackName (host[0].stack));
     60    PushStack (AllHosts, STACK_BOTTOM, host, host[0].HostID, host[0].hostname);
    5461    return (TRUE);
    5562  }
     63
    5664  if (!strcasecmp (argv[1], "OFF")) {
    57     SetCheckPoint (); // ensure we can find the specified host
    58     host = PullHostByName (argv[2], &StackID);
     65    host = PullHostFromStackByName (PCONTROL_HOST_ALLHOSTS, argv[2]);
    5966    if (host == NULL) {
    6067      gprint (GP_LOG, "host %s not found\n", argv[2]);
    61       ClearCheckPoint ();
    6268      return (FALSE);
    6369    }
    6470    host[0].markoff = TRUE;
    65     PutHost (host, StackID, STACK_BOTTOM);
    66     ClearCheckPoint ();
     71    PushStack (AllHosts, STACK_BOTTOM, host, host[0].HostID, host[0].hostname);
    6772    return (TRUE);
    6873  }
    6974
     75  // this one is safe from in-flight entries: no one else pulls from OFF
    7076  if (!strcasecmp (argv[1], "DELETE")) {
    71     // a check point is not required: no possible thief
    7277    host = PullHostFromStackByName (PCONTROL_HOST_OFF, argv[2]);
    7378    if (!host) {
  • trunk/Ohana/src/opihi/pcontrol/pcontrol.c.in

    r16473 r18098  
    6868/* add program-dependent exit functions here */
    6969void cleanup () {
     70  // stop checking on the jobs
     71  SetRunLevel (PCONTROL_RUN_HOSTS);
    7072  DownHosts ();
    7173  ConfigFree ();
  • trunk/Ohana/src/opihi/pcontrol/status.c

    r12471 r18098  
    66int status (int argc, char **argv) {
    77
    8   SetCheckPoint ();
    9   PrintJobStack (PCONTROL_JOB_PENDING);
    10   PrintJobStack (PCONTROL_JOB_BUSY);
    11   PrintJobStack (PCONTROL_JOB_DONE);
    12   PrintJobStack (PCONTROL_JOB_KILL);
    13   PrintJobStack (PCONTROL_JOB_EXIT);
    14   PrintJobStack (PCONTROL_JOB_CRASH);
     8  PrintJobStack (PCONTROL_JOB_ALLJOBS);
     9  PrintHostStack (PCONTROL_HOST_ALLHOSTS);
    1510
    16   PrintHostStack (PCONTROL_HOST_OFF);
    17   PrintHostStack (PCONTROL_HOST_DOWN);
    18   PrintHostStack (PCONTROL_HOST_IDLE);
    19   PrintHostStack (PCONTROL_HOST_BUSY);
    20   PrintHostStack (PCONTROL_HOST_DONE);
    21   ClearCheckPoint ();
    2211  return (TRUE);
    2312}
     
    3928    job = stack[0].object[i];
    4029    ASSERT (job != NULL, "programming error");
    41     gprint (GP_LOG, "%d  %s  %d  ", i, job[0].hostname, job[0].argc);
     30    if (job[0].realhost == NULL) {
     31        gprint (GP_LOG, "%3d %9s ", i, job[0].hostname);
     32    } else {
     33        gprint (GP_LOG, "%3d %9s ", i, job[0].realhost);
     34    }
     35    gprint (GP_LOG, "%7s  ", GetJobStackName (job[0].state));
    4236    for (j = 0; j < job[0].argc; j++) {
    4337      gprint (GP_LOG, "%s ", job[0].argv[j]);
     
    6660    host = stack[0].object[i];
    6761    gprint (GP_LOG, "%d  %s  ", i, host[0].hostname);
     62    gprint (GP_LOG, "%5s  ", GetHostStackName (host[0].stack));
    6863    PrintID (GP_LOG, host[0].HostID);
    6964    gprint (GP_LOG, "\n");
Note: See TracChangeset for help on using the changeset viewer.