Changeset 18098
- Timestamp:
- Jun 12, 2008, 12:52:06 PM (18 years ago)
- Location:
- trunk/Ohana/src/opihi/pcontrol
- Files:
-
- 13 edited
-
CheckHost.c (modified) (1 diff)
-
CheckIdleHost.c (modified) (1 diff)
-
CheckSystem.c (modified) (2 diffs)
-
HostOps.c (modified) (8 diffs)
-
IDops.c (modified) (2 diffs)
-
JobID.c (modified) (1 diff)
-
JobOps.c (modified) (9 diffs)
-
StopHosts.c (modified) (2 diffs)
-
check.c (modified) (4 diffs)
-
delete.c (modified) (1 diff)
-
host.c (modified) (3 diffs)
-
pcontrol.c.in (modified) (1 diff)
-
status.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pcontrol/CheckHost.c
r17475 r18098 15 15 host[0].markoff = FALSE; 16 16 StopHost (host); 17 OffHost (host);18 17 return (TRUE); 19 18 } -
trunk/Ohana/src/opihi/pcontrol/CheckIdleHost.c
r10667 r18098 14 14 host[0].markoff = FALSE; 15 15 StopHost (host); 16 OffHost (host);17 16 return (TRUE); 18 17 } -
trunk/Ohana/src/opihi/pcontrol/CheckSystem.c
r17476 r18098 346 346 if (host == NULL) break; 347 347 if (host[0].markoff) { 348 // DOWN -> OFF 348 349 host[0].markoff = FALSE; 349 350 OffHost (host); … … 354 355 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 355 356 } 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 356 360 StartHost (host); 357 361 } -
trunk/Ohana/src/opihi/pcontrol/HostOps.c
r17476 r18098 1 1 # include "pcontrol.h" 2 3 Stack *HostPool_AllHosts; // virtual pool for user status queries 2 4 3 5 Stack *HostPool_Idle; // these hosts are waiting for something to do … … 9 11 10 12 void InitHostStacks () { 13 HostPool_AllHosts = InitStack (); 14 11 15 HostPool_Idle = InitStack (); 12 16 HostPool_Busy = InitStack (); … … 26 30 27 31 void FreeHostStacks () { 32 // AllHosts is a virtual stack : all hosts are references 33 FreeStack (HostPool_AllHosts); 34 28 35 FreeHostStack (HostPool_Idle); 29 36 FreeHostStack (HostPool_Busy); … … 36 43 char *GetHostStackName (int StackID) { 37 44 switch (StackID) { 45 case PCONTROL_HOST_ALLHOSTS: return ("ALLHOSTS"); 38 46 case PCONTROL_HOST_IDLE: return ("IDLE"); 39 47 case PCONTROL_HOST_DOWN: return ("DOWN"); … … 50 58 Stack *GetHostStack (int StackID) { 51 59 switch (StackID) { 60 case PCONTROL_HOST_ALLHOSTS: return (HostPool_AllHosts); 52 61 case PCONTROL_HOST_IDLE: return (HostPool_Idle); 53 62 case PCONTROL_HOST_DOWN: return (HostPool_Down); … … 63 72 64 73 Stack *GetHostStackByName (char *name) { 74 if (!strcasecmp (name, "all")) return (HostPool_AllHosts); 65 75 if (!strcasecmp (name, "idle")) return (HostPool_Idle); 66 76 if (!strcasecmp (name, "down")) return (HostPool_Down); … … 202 212 host[0].markoff = FALSE; 203 213 host[0].job = NULL; 214 215 PutHost (host, PCONTROL_HOST_ALLHOSTS, STACK_BOTTOM); 204 216 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 205 217 return (host[0].HostID); … … 207 219 208 220 void 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 209 227 FreeIOBuffer (&host[0].comms_buffer); 210 228 FREE (host[0].hostname); -
trunk/Ohana/src/opihi/pcontrol/IDops.c
r8296 r18098 1 1 # include "pcontrol.h" 2 2 3 static IDtype CurrentJobID = 0;4 static IDtype CurrentHostID = 0;3 static IDtype CurrentJobID = 1; 4 static IDtype CurrentHostID = 1; 5 5 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 */ 7 8 void InitIDs () { 8 CurrentJobID = 0;9 CurrentHostID = 0;9 CurrentJobID = 1; 10 CurrentHostID = 1; 10 11 } 11 12 … … 41 42 } 42 43 44 IDtype 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 40 40 } 41 41 42 IDtype 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 1 1 # include "pcontrol.h" 2 2 3 // Stack *JobPool_AllJobs; 3 Stack *JobPool_AllJobs; // virtual pool for user status queries 4 4 5 5 Stack *JobPool_Pending; … … 12 12 13 13 void InitJobStacks () { 14 //JobPool_AllJobs = InitStack ();14 JobPool_AllJobs = InitStack (); 15 15 16 16 JobPool_Pending = InitStack (); … … 32 32 33 33 void FreeJobStacks () { 34 35 // AllJobs is a virtual stack : all jobs are references36 // FreeStack (JobPool_AllJobs);37 38 34 FreeJobStack (JobPool_Pending); 39 35 FreeJobStack (JobPool_Busy ); … … 43 39 FreeJobStack (JobPool_Exit ); 44 40 FreeJobStack (JobPool_Crash ); 41 42 // AllJobs is a virtual stack : all jobs are references 43 FreeStack (JobPool_AllJobs); 45 44 } 46 45 47 46 char *GetJobStackName (int StackID) { 48 47 switch (StackID) { 49 //case PCONTROL_JOB_ALLJOBS: return ("ALLJOBS");48 case PCONTROL_JOB_ALLJOBS: return ("ALLJOBS"); 50 49 51 50 case PCONTROL_JOB_PENDING: return ("PENDING"); … … 64 63 Stack *GetJobStack (int StackID) { 65 64 switch (StackID) { 66 //case PCONTROL_JOB_ALLJOBS: return (JobPool_AllJobs);65 case PCONTROL_JOB_ALLJOBS: return (JobPool_AllJobs); 67 66 68 67 case PCONTROL_JOB_PENDING: return (JobPool_Pending); … … 81 80 Stack *GetJobStackByName (char *name) { 82 81 83 //if (!strcasecmp (name, "all")) return (JobPool_AllJobs);82 if (!strcasecmp (name, "all")) return (JobPool_AllJobs); 84 83 85 84 if (!strcasecmp (name, "pending")) return (JobPool_Pending); … … 186 185 job[0].argv = argv; 187 186 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 188 194 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; 193 198 194 199 /* do this step on start? */ … … 196 201 InitIOBuffer (&job[0].stderr_buff, 0x1000); 197 202 203 job[0].dtime = 0.0; 204 job[0].pid = 0; 205 206 job[0].JobID = NextJobID(); 207 job[0].host = NULL; 208 198 209 JobID = job[0].JobID; 199 210 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); 200 214 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 201 // PutJob (job, PCONTROL_JOB_ALLJOBS, STACK_BOTTOM);202 215 203 216 if (VerboseMode()) gprint (GP_ERR, "added new job\n"); … … 208 221 209 222 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"); 210 228 211 229 FREE (job[0].hostname); -
trunk/Ohana/src/opihi/pcontrol/StopHosts.c
r17475 r18098 95 95 int StopHostResponse (Host *host) { 96 96 97 OffHost (host); 97 98 HarvestHost (host[0].pid); 98 99 return (TRUE); … … 104 105 int i, result, waitstatus; 105 106 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); 108 109 109 110 // Loop a few times waiting for child to exit -
trunk/Ohana/src/opihi/pcontrol/check.c
r11388 r18098 3 3 int check (int argc, char **argv) { 4 4 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; 8 10 9 11 if (argc != 3) { … … 14 16 15 17 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 } 17 23 18 SetCheckPoint (); // ensure the JOB is on one of the stacks19 job = Pull JobByID (JobID, &StackID);24 stack = GetJobStack (PCONTROL_JOB_ALLJOBS); 25 job = PullStackByID (stack, JobID); 20 26 if (job == NULL) { 21 27 gprint (GP_LOG, "job not found\n"); 22 ClearCheckPoint ();23 28 return (FALSE); 24 29 } 25 gprint (GP_LOG, "STATUS %s\n", GetJobStackName(StackID)); 30 31 gprint (GP_LOG, "STATUS %s\n", GetJobStackName(job[0].stack)); 26 32 gprint (GP_LOG, "EXITST %d\n", job[0].exit_status); 27 33 gprint (GP_LOG, "STDOUT %d\n", job[0].stdout_size); … … 33 39 gprint (GP_LOG, "HOSTNAME NONE\n"); 34 40 } 35 PutJob (job, StackID, STACK_BOTTOM); 36 ClearCheckPoint (); 41 PushStack (stack, STACK_BOTTOM, job, job[0].JobID, job[0].argv[0]); 37 42 return (TRUE); 38 43 } … … 41 46 HostID = atoi (argv[2]); 42 47 43 SetCheckPoint (); // ensure the HOST is on one of the stacks44 host = Pull HostByID (HostID, &StackID);48 stack = GetHostStack (PCONTROL_HOST_ALLHOSTS); 49 host = PullStackByID (stack, HostID); 45 50 if (host == NULL) { 46 51 gprint (GP_LOG, "host not found\n"); 47 ClearCheckPoint ();48 52 return (FALSE); 49 53 } 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); 53 56 return (TRUE); 54 57 } -
trunk/Ohana/src/opihi/pcontrol/delete.c
r8296 r18098 10 10 return (FALSE); 11 11 } 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 13 18 /* use a string interp to convert JobIDs to ints ? */ 14 19 -
trunk/Ohana/src/opihi/pcontrol/host.c
r10652 r18098 1 1 # include "pcontrol.h" 2 2 3 // we use CheckPoints in this function to prevent objects in flight from being missing.4 3 int host (int argc, char **argv) { 5 4 6 int StackID;7 5 IDtype HostID; 8 6 Host *host; 7 Stack *AllHosts; 9 8 10 9 if (argc != 3) goto usage; 10 11 AllHosts = GetHostStack (PCONTROL_HOST_ALLHOSTS); 11 12 12 13 if (!strcasecmp (argv[1], "ADD")) { … … 15 16 return (TRUE); 16 17 } 18 19 // this one is safe from in-flight entries: no one else pulls from OFF 17 20 if (!strcasecmp (argv[1], "ON")) { 18 21 host = PullHostFromStackByName (PCONTROL_HOST_OFF, argv[2]); … … 25 28 return (TRUE); 26 29 } 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 27 33 if (!strcasecmp (argv[1], "RETRY")) { 28 34 // 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]); 30 36 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) { 31 41 gprint (GP_LOG, "host %s is not DOWN\n", argv[2]); 32 42 return (FALSE); 33 43 } 34 /* reset time, place back on DOWNstack */44 /* reset time, place back on ALLHOSTS stack */ 35 45 host[0].nexttry.tv_sec = 0; 36 46 host[0].nexttry.tv_usec = 0; 37 47 host[0].lasttry.tv_sec = 0; 38 48 host[0].lasttry.tv_usec = 0; 39 Pu tHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);49 PushStack (AllHosts, STACK_BOTTOM, host, host[0].HostID, host[0].hostname); 40 50 return (TRUE); 41 51 } 52 42 53 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]); 45 55 if (host == NULL) { 46 56 gprint (GP_LOG, "host %s not found\n", argv[2]); 47 ClearCheckPoint ();48 57 return (FALSE); 49 58 } 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); 54 61 return (TRUE); 55 62 } 63 56 64 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]); 59 66 if (host == NULL) { 60 67 gprint (GP_LOG, "host %s not found\n", argv[2]); 61 ClearCheckPoint ();62 68 return (FALSE); 63 69 } 64 70 host[0].markoff = TRUE; 65 PutHost (host, StackID, STACK_BOTTOM); 66 ClearCheckPoint (); 71 PushStack (AllHosts, STACK_BOTTOM, host, host[0].HostID, host[0].hostname); 67 72 return (TRUE); 68 73 } 69 74 75 // this one is safe from in-flight entries: no one else pulls from OFF 70 76 if (!strcasecmp (argv[1], "DELETE")) { 71 // a check point is not required: no possible thief72 77 host = PullHostFromStackByName (PCONTROL_HOST_OFF, argv[2]); 73 78 if (!host) { -
trunk/Ohana/src/opihi/pcontrol/pcontrol.c.in
r16473 r18098 68 68 /* add program-dependent exit functions here */ 69 69 void cleanup () { 70 // stop checking on the jobs 71 SetRunLevel (PCONTROL_RUN_HOSTS); 70 72 DownHosts (); 71 73 ConfigFree (); -
trunk/Ohana/src/opihi/pcontrol/status.c
r12471 r18098 6 6 int status (int argc, char **argv) { 7 7 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); 15 10 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 ();22 11 return (TRUE); 23 12 } … … 39 28 job = stack[0].object[i]; 40 29 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)); 42 36 for (j = 0; j < job[0].argc; j++) { 43 37 gprint (GP_LOG, "%s ", job[0].argv[j]); … … 66 60 host = stack[0].object[i]; 67 61 gprint (GP_LOG, "%d %s ", i, host[0].hostname); 62 gprint (GP_LOG, "%5s ", GetHostStackName (host[0].stack)); 68 63 PrintID (GP_LOG, host[0].HostID); 69 64 gprint (GP_LOG, "\n");
Note:
See TracChangeset
for help on using the changeset viewer.
