Changeset 3203
- Timestamp:
- Feb 12, 2005, 9:34:34 AM (21 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 11 added
- 1 deleted
- 15 edited
-
include/pcontrol.h (modified) (4 diffs)
-
pclient/reset.c (modified) (1 diff)
-
pcontrol/CheckBusyJob.c (added)
-
pcontrol/CheckDoneHost.c (added)
-
pcontrol/CheckDoneJob.c (added)
-
pcontrol/CheckHost.c (modified) (4 diffs)
-
pcontrol/CheckIdleHost.c (added)
-
pcontrol/CheckJob.c (deleted)
-
pcontrol/CheckSystem.c (modified) (1 diff)
-
pcontrol/GetJobOutput.c (added)
-
pcontrol/HostOps.c (modified) (7 diffs)
-
pcontrol/IOBufferOps.c (added)
-
pcontrol/JobID.c (modified) (3 diffs)
-
pcontrol/JobOps.c (modified) (8 diffs)
-
pcontrol/Makefile (added)
-
pcontrol/QueueOps.c (modified) (2 diffs)
-
pcontrol/ResetJob.c (added)
-
pcontrol/StartHost.c (modified) (2 diffs)
-
pcontrol/StartJob.c (modified) (7 diffs)
-
pcontrol/host.c (modified) (5 diffs)
-
pcontrol/init.c (added)
-
pcontrol/job.c (modified) (4 diffs)
-
pcontrol/memstr.c (added)
-
pcontrol/pclient.c (modified) (1 diff)
-
pcontrol/pcontrol.c (modified) (1 diff)
-
pcontrol/rconnect.c (modified) (2 diffs)
-
pcontrol/status.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/include/pcontrol.h
r3187 r3203 7 7 # include <sys/wait.h> 8 8 9 /** pcontrol global data **/ 9 typedef struct timeval Ptime; 10 typedef unsigned long long IDtype; 10 11 11 12 /** job status values **/ 12 enum {13 typedef enum { 13 14 PCONTROL_JOB_PENDING, 14 15 PCONTROL_JOB_BUSY, 15 16 PCONTROL_JOB_EXIT, 16 17 PCONTROL_JOB_CRASH, 18 PCONTROL_JOB_HUNG, 19 PCONTROL_JOB_DONE, 17 20 } JobStat; 18 21 19 22 /** job status values **/ 20 enum {23 typedef enum { 21 24 PCONTROL_JOB_ANYHOST, 22 25 PCONTROL_JOB_WANTHOST, 23 PCONTROL_JOB_NEEDHOST, 26 PCONTROL_JOB_NEEDHOST, 24 27 } JobMode; 25 28 26 29 /** host status values **/ 27 enum {30 typedef enum { 28 31 PCONTROL_HOST_IDLE, 29 32 PCONTROL_HOST_BUSY, 30 33 PCONTROL_HOST_DOWN, 34 PCONTROL_HOST_DONE, 31 35 PCONTROL_HOST_OFF, 32 36 } HostStat; 37 38 /* stack special positions */ 39 typedef enum { 40 STACK_TOP = 0, 41 STACK_BOTTOM = -1, 42 } StackWhere; 43 44 typedef enum { 45 PCLIENT_HUNG = -1, 46 PCLIENT_DOWN = 0, 47 PCLIENT_GOOD = 1, 48 } PclientStat; 33 49 34 50 typedef struct { … … 49 65 } Fifo; 50 66 51 typedef struct timeval Ptime;52 53 67 /* data to define a job */ 54 68 typedef struct { 55 int argc; 56 char **argv; 57 char *hostname; 58 int exitstatus; 59 JobMode mode; 60 JobStat status; 61 IOBuffer stdin; 62 IOBuffer stdout; 63 IOBuffer stderr; 64 Ptime start; 65 Ptime accum; 66 Ptime timer; 69 int argc; 70 char **argv; 71 char *hostname; 72 int exit_status; 73 int Reset; 74 JobMode mode; 75 JobStat state; 76 JobStat stack; 77 IOBuffer stdout; 78 IOBuffer stderr; 79 Ptime start; 80 Ptime accum; 81 Ptime timer; 67 82 struct Host *host; 68 int pid;69 IDtype JobID;83 int pid; 84 IDtype JobID; 70 85 } Job; 71 86 72 87 /* data to define a host machine */ 73 88 typedef struct { 74 char *hostname; 75 int stdin; 76 int stdout; 77 int stderr; 78 int markoff; 79 HostStat status; 80 Ptime start; 81 Ptime accum; 82 Ptime timer; 89 char *hostname; 90 int stdin; 91 int stdout; 92 int stderr; 93 int markoff; 94 int pid; 95 HostStat stack; 96 Ptime start; 97 Ptime accum; 98 Ptime timer; 99 IDtype HostID; 83 100 struct Job *job; 84 101 } Host; … … 88 105 int Nobject; 89 106 int NOBJECT; 90 } Queue;107 } Stack; 91 108 109 /* these should be loaded from ConfigInit or from opihi variables */ 92 110 static char *CONNECT; /* connection method (ssh, rsh, etc) */ 93 111 static char *PCLIENT; /* shell on remote host (eg, pclient) */ 112 113 # define FREE(X) if (X != NULL) { free (X); } 114 # define CLOSE(FD) { if (FD) close (FD); FD = 0; } 94 115 95 116 /** IOBuffers allow the following operations (see pclient.h) **/ … … 99 120 void FreeIOBuffer (IOBuffer *buffer); 100 121 101 # define FREE(X) if (X != NULL) { free (X); } 102 103 enum { 104 QUEUE_TOP = 0, 105 QUEUE_BOTTOM = -1, 106 } QueueWhere; 107 122 void *GetStack (Stack *stack, int where); 123 int PutStack (Stack *stack, int where, void *object); 124 Stack *InitStack (); 125 Stack *GetHostStack (int StackID); 126 int PutHost (Host *host, int StackID, int where); 127 Host *GetHost (int StackID, int where); 128 int FindHost (IDtype HostID, int StackID); 129 int FindNamedHost (char *name, int StackID); 130 void AddHost (char *hostname); 131 void DownHost (Host *host); 132 void DelHost (Host *host); 133 int CheckSystem (); 134 int CheckBusyJobs (); 135 int CheckDoneJobs (); 136 int CheckDoneHosts (); 137 int CheckLiveHosts (); 138 int CheckDownHosts (); 139 int CheckIdleHosts (); 140 int CheckIdleHost (Host *host); 141 void InitIDs (); 142 IDtype NextJobID (); 143 IDtype NextHostID (); 144 void PrintID (FILE *f, IDtype ID); 145 int CheckBusyJob (Job *job); 146 int StartHost (Host *host); 147 int CheckDoneHost (Host *host); 148 int CheckDoneJob (Job *job); 149 int GetJobOutput (Job *job, char *channel); 150 int ResetJob (Job *job); 151 int PclientCommand (Host *host, char *command, IOBuffer *buffer); 152 int rconnect (char *command, char *hostname, char *shell, int *stdio); 153 int CheckHost (Host *host); 154 char *memstr (char *m1, char *m2, int n); 155 Stack *GetJobStack (int StackID); 156 int PutJob (Job *job, int StackID, int where); 157 Job *GetJob (int StackID, int where); 158 int FindJob (IDtype JobID, int StackID); 159 IDtype AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv); 160 void KillJob (Job *job); 161 void DelJob (Job *job); 162 Host *UnlinkJobAndHost (Job *job); 163 void LinkJobAndHost (Job *job, Host *host); -
trunk/Ohana/src/opihi/pclient/reset.c
r3187 r3203 7 7 if (argc != 1) { 8 8 fprintf (stderr, "USAGE: reset\n"); 9 fprintf (stdout, "STATUS %d\n", -2);9 fprintf (stdout, "STATUS -1\n"); 10 10 return (FALSE); 11 11 } -
trunk/Ohana/src/opihi/pcontrol/CheckHost.c
r3187 r3203 3 3 int CheckHost (Host *host) { 4 4 5 int i, status;5 int i, N, status; 6 6 IOBuffer buffer; 7 7 Job *job; … … 15 15 16 16 /* if host has a job, job is dead, push to Pending */ 17 if (host[0].sta tus== PCONTROL_HOST_BUSY) {17 if (host[0].stack == PCONTROL_HOST_BUSY) { 18 18 job = host[0].job; 19 19 N = FindJob (job[0].JobID, PCONTROL_JOB_BUSY); … … 24 24 job[0].host = NULL; /* unlink host & job */ 25 25 job = GetJob (PCONTROL_JOB_BUSY, N); 26 PutJob (job, PCONTROL_JOB_PENDING, QUEUE_BOTTOM);26 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 27 27 } 28 28 host[0].job = NULL; 29 PutHost (host, PCONTROL_HOST_DOWN, QUEUE_BOTTOM);30 Free Buffer (&buffer);29 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 30 FreeIOBuffer (&buffer); 31 31 return (FALSE); 32 32 … … 34 34 fprintf (stderr, "host %s is not responding\n", host[0].hostname); 35 35 /*** do we mark this in some way (HUNG) ? ***/ 36 PutHost (host, host[0].sta tus, QUEUE_BOTTOM);37 Free Buffer (&buffer);36 PutHost (host, host[0].stack, STACK_BOTTOM); 37 FreeIOBuffer (&buffer); 38 38 return (FALSE); 39 39 40 40 default: 41 41 fprintf (stderr, "host %s is alive\n", host[0].hostname); 42 PutHost (host, host[0].sta tus, QUEUE_BOTTOM);43 Free Buffer (&buffer);42 PutHost (host, host[0].stack, STACK_BOTTOM); 43 FreeIOBuffer (&buffer); 44 44 return (TRUE); 45 45 } -
trunk/Ohana/src/opihi/pcontrol/CheckSystem.c
r3187 r3203 4 4 5 5 CheckBusyJobs(); 6 CheckDoneJobs(); 7 CheckDoneHosts(); 8 CheckIdleHosts(); 9 CheckDownHosts(); 10 11 /** add in different timescales for heartbeat? **/ 6 12 CheckLiveHosts(); 7 CheckDownHosts();8 CheckIdleHosts();9 10 13 } 11 14 12 CheckBusyJobs () {15 int CheckBusyJobs () { 13 16 14 queue = GetJobQueue (PCONTROL_JOB_BUSY); 15 Nobjects = queue[0].Nobjects; 17 int i, Nobject; 18 Stack *stack; 19 Job *job; 16 20 17 for (i = 0; i < Nobjects; i++) { 18 job = GetObject (queue, QUEUE_TOP); 19 CheckJob (job); 21 stack = GetJobStack (PCONTROL_JOB_BUSY); 22 Nobject = stack[0].Nobject; 23 24 for (i = 0; i < Nobject; i++) { 25 job = GetStack (stack, STACK_TOP); 26 CheckBusyJob (job); 20 27 } 21 28 } 22 29 23 CheckLiveHosts () {30 int CheckDoneJobs () { 24 31 25 queue = GetHostQueue (PCONTROL_HOST_IDLE); 26 Nobjects = queue[0].Nobjects; 32 int i, Nobject; 33 Stack *stack; 34 Job *job; 27 35 28 for (i = 0; i < Nobjects; i++) { 29 host = GetObject (queue, QUEUE_TOP); 36 stack = GetJobStack (PCONTROL_JOB_DONE); 37 Nobject = stack[0].Nobject; 38 39 for (i = 0; i < Nobject; i++) { 40 job = GetStack (stack, STACK_TOP); 41 CheckDoneJob (job); 42 } 43 } 44 45 int CheckDoneHosts () { 46 47 int i, Nobject; 48 Stack *stack; 49 Host *host; 50 51 stack = GetHostStack (PCONTROL_HOST_DONE); 52 Nobject = stack[0].Nobject; 53 54 for (i = 0; i < Nobject; i++) { 55 host = GetStack (stack, STACK_TOP); 56 StartHost (host); 57 } 58 } 59 60 /* this is just a heartbeat check */ 61 int CheckLiveHosts () { 62 63 int i, Nobject; 64 Stack *stack; 65 Host *host; 66 67 stack = GetHostStack (PCONTROL_HOST_IDLE); 68 Nobject = stack[0].Nobject; 69 70 for (i = 0; i < Nobject; i++) { 71 host = GetStack (stack, STACK_TOP); 30 72 CheckHost (host); 31 73 } 32 74 33 queue = GetHostQueue(PCONTROL_HOST_BUSY);34 Nobject s = queue[0].Nobjects;75 stack = GetHostStack (PCONTROL_HOST_BUSY); 76 Nobject = stack[0].Nobject; 35 77 36 for (i = 0; i < Nobject s; i++) {37 host = Get Object (queue, QUEUE_TOP);78 for (i = 0; i < Nobject; i++) { 79 host = GetStack (stack, STACK_TOP); 38 80 CheckHost (host); 39 81 } 40 82 } 41 83 42 CheckDownHosts () {84 int CheckDownHosts () { 43 85 44 queue = GetHostQueue (PCONTROL_HOST_DOWN); 45 Nobjects = queue[0].Nobjects; 86 int i, Nobject; 87 Stack *stack; 88 Host *host; 46 89 47 for (i = 0; i < Nobjects; i++) { 48 host = GetObject (queue, QUEUE_TOP); 90 stack = GetHostStack (PCONTROL_HOST_DOWN); 91 Nobject = stack[0].Nobject; 92 93 for (i = 0; i < Nobject; i++) { 94 host = GetStack (stack, STACK_TOP); 49 95 StartHost (host); 50 96 } 51 97 } 52 98 53 CheckIdleHosts () {99 int CheckIdleHosts () { 54 100 55 hqueue = HostPool_Idle; 56 jqueue = JobPool_Pending; 101 int i, Nobject; 102 Stack *stack; 103 Host *host; 57 104 58 for (i = 0; i < hqueue[0].Nobjects; i++) { 59 host = (Host *) hqueue[0].object[i]; 60 /** need to add a timeout here **/ 61 for (j = 0; j < jqueue[0].Nobjects; j++) { 62 job = (Job *) jqueue[0].object[j]; 63 if ((job[0].mode == PCONTROL_JOB_ANYHOST) || 64 (!strcasecmp (job[0].hostname, host[0].hostname)) 105 /* check if there are any pending jobs, otherwise skip step */ 106 stack = GetJobStack (PCONTROL_JOB_PENDING); 107 if (!stack[0].Nobject) return; 65 108 66 StartHost (host); 109 stack = GetHostStack (PCONTROL_HOST_IDLE); 110 Nobject = stack[0].Nobject; 111 112 for (i = 0; i < Nobject; i++) { 113 host = GetStack (stack, STACK_TOP); 114 CheckIdleHost (host); 67 115 } 68 116 } 69 70 /*** this section is tricky: need to have a plan on making WANTHOST likely71 but not required (on average, every host is currently in use. some possible tricks:72 73 - search through PENDING for N entries looking for WANTHOST / matching host74 - keep job through N tries waiting for WANTHOST75 ***/ -
trunk/Ohana/src/opihi/pcontrol/HostOps.c
r3189 r3203 1 1 # include "pcontrol.h" 2 2 3 Queue*HostPool_Idle;4 Queue*HostPool_Busy;5 Queue*HostPool_Down;6 Queue*HostPool_Off;3 Stack *HostPool_Idle; 4 Stack *HostPool_Busy; 5 Stack *HostPool_Down; 6 Stack *HostPool_Off; 7 7 8 Queue *GetHostQueue (int QueueID) { 9 switch (QueueID) { 8 void InitHostStacks () { 9 HostPool_Idle = InitStack (); 10 HostPool_Busy = InitStack (); 11 HostPool_Down = InitStack (); 12 HostPool_Off = InitStack (); 13 } 14 15 Stack *GetHostStack (int StackID) { 16 switch (StackID) { 10 17 case PCONTROL_HOST_IDLE: 11 18 return (HostPool_Idle); … … 17 24 return (HostPool_Off); 18 25 default: 19 fprintf (stderr, "error: unknown host queue\n");26 fprintf (stderr, "error: unknown host stack\n"); 20 27 return (NULL); 21 28 } … … 23 30 } 24 31 25 int PutHost (Host *host, int QueueID, int where) {32 int PutHost (Host *host, int StackID, int where) { 26 33 27 34 int status; 28 Queue *queue;35 Stack *stack; 29 36 30 queue = GetHostQueue (QueueID);31 if ( queue== NULL) return (FALSE);37 stack = GetHostStack (StackID); 38 if (stack == NULL) return (FALSE); 32 39 33 host[0].sta tus = QueueID;34 status = Put Object (queue, where, host);40 host[0].stack = StackID; 41 status = PutStack (stack, where, host); 35 42 return (status); 36 43 } 37 44 38 Host *GetHost (int QueueID, int where) {45 Host *GetHost (int StackID, int where) { 39 46 40 47 Host *host; 41 Queue *queue;48 Stack *stack; 42 49 43 queue = GetHostQueue (QueueID);44 if ( queue== NULL) return (NULL);50 stack = GetHostStack (StackID); 51 if (stack == NULL) return (NULL); 45 52 46 host = Get Object (queue, where);53 host = GetStack (stack, where); 47 54 return (host); 48 55 } 49 56 50 int FindHost (IDtype HostID, int QueueID) {57 int FindHost (IDtype HostID, int StackID) { 51 58 52 Queue *queue; 59 int i; 60 Host *host; 61 Stack *stack; 53 62 54 queue = GetHostQueue (QueueID);55 if ( queue== NULL) return (-2);63 stack = GetHostStack (StackID); 64 if (stack == NULL) return (-2); 56 65 57 for (i = 0; i < queue[0].Nobject; i++) {58 host = (Host *) queue[0].object;66 for (i = 0; i < stack[0].Nobject; i++) { 67 host = (Host *) stack[0].object; 59 68 if (host[0].HostID == HostID) { 60 69 return (i); … … 64 73 } 65 74 66 int FindNamedHost (char *name, int QueueID) {75 int FindNamedHost (char *name, int StackID) { 67 76 68 Queue *queue; 77 int i; 78 Host *host; 79 Stack *stack; 69 80 70 queue = GetHostQueue (QueueID);71 if ( queue== NULL) return (-2);81 stack = GetHostStack (StackID); 82 if (stack == NULL) return (-2); 72 83 73 for (i = 0; i < queue[0].Nobject; i++) {74 host = (Host *) queue[0].object;75 if (!strcasecmp (host[0].hostname, host)) {84 for (i = 0; i < stack[0].Nobject; i++) { 85 host = (Host *) stack[0].object; 86 if (!strcasecmp (host[0].hostname, name)) { 76 87 return (i); 77 88 } … … 80 91 } 81 92 82 AddHost (char *hostname) {93 void AddHost (char *hostname) { 83 94 84 95 Host *host; … … 94 105 host[0].markoff = FALSE; 95 106 host[0].job = NULL; 96 DownHost (host);107 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 97 108 } 98 109 99 DelHost (Host *host) { 110 void DownHost (Host *host) { 111 112 CLOSE (host[0].stdin); 113 CLOSE (host[0].stdout); 114 CLOSE (host[0].stderr); 115 host[0].job = NULL; 116 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 117 } 118 119 void DelHost (Host *host) { 100 120 FREE (host[0].hostname); 101 121 FREE (host[0].job); … … 103 123 } 104 124 105 MarkOffHost (Host *host) {106 if (host[0].status != PCONTROL_HOST_BUSY) {107 return (FALSE);108 }109 host[0].markoff = TRUE;110 PutObject (HostPool_Busy, host); /**** where are we removing hosts? **/111 }112 -
trunk/Ohana/src/opihi/pcontrol/JobID.c
r3187 r3203 1 1 # include "pcontrol.h" 2 3 typedef unsigned long long IDtype;4 2 5 3 static IDtype CurrentJobID = 0; … … 7 5 8 6 /* for now, no persistence : we could use the date/time to seed the upper byte(s) if needed */ 9 InitIDs () {7 void InitIDs () { 10 8 CurrentJobID = 0; 11 9 CurrentHostID = 0; … … 32 30 void PrintID (FILE *f, IDtype ID) { 33 31 32 unsigned short int word0, word1, word2, word3; 33 34 34 word0 = 0xffff & ID; 35 35 word1 = 0xffff & (ID >> 16); -
trunk/Ohana/src/opihi/pcontrol/JobOps.c
r3189 r3203 1 1 # include "pcontrol.h" 2 2 3 Queue*JobPool_Pending;4 Queue*JobPool_Busy;5 Queue*JobPool_Exit;6 Queue*JobPool_Crash;3 Stack *JobPool_Pending; 4 Stack *JobPool_Busy; 5 Stack *JobPool_Exit; 6 Stack *JobPool_Crash; 7 7 8 Queue *GetJobQueue (int QueueID) { 9 switch (QueueID) { 8 void InitJobStacks () { 9 JobPool_Pending = InitStack (); 10 JobPool_Busy = InitStack (); 11 JobPool_Exit = InitStack (); 12 JobPool_Crash = InitStack (); 13 } 14 15 Stack *GetJobStack (int StackID) { 16 switch (StackID) { 10 17 case PCONTROL_JOB_PENDING: 11 18 return (JobPool_Pending); … … 14 21 case PCONTROL_JOB_EXIT: 15 22 return (JobPool_Exit); 16 case PCONTROL_JOB_C rash:23 case PCONTROL_JOB_CRASH: 17 24 return (JobPool_Crash); 18 25 default: 19 fprintf (stderr, "error: unknown job queue\n");26 fprintf (stderr, "error: unknown job stack\n"); 20 27 return (NULL); 21 28 } … … 23 30 } 24 31 25 int PutJob (Job *job, int QueueID, int where) {32 int PutJob (Job *job, int StackID, int where) { 26 33 27 34 int status; 28 Queue *queue;35 Stack *stack; 29 36 30 queue = GetJobQueue (QueueID);31 if ( queue== NULL) return (FALSE);37 stack = GetJobStack (StackID); 38 if (stack == NULL) return (FALSE); 32 39 33 job[0].status = QueueID; 34 status = PutObject (queue, where, job); 40 /* be default, these are both the same - to override, set state after PutJob */ 41 job[0].state = StackID; 42 job[0].stack = StackID; 43 status = PutStack (stack, where, job); 35 44 return (status); 36 45 } 37 46 38 Job *GetJob (int QueueID, int where) {47 Job *GetJob (int StackID, int where) { 39 48 40 49 Job *job; 41 Queue *queue;50 Stack *stack; 42 51 43 queue = GetJobQueue (QueueID);44 if ( queue== NULL) return (NULL);52 stack = GetJobStack (StackID); 53 if (stack == NULL) return (NULL); 45 54 46 job = Get Object (queue, where);55 job = GetStack (stack, where); 47 56 return (job); 48 57 } 49 58 50 int FindJob (IDtype JobID, int QueueID) {59 int FindJob (IDtype JobID, int StackID) { 51 60 61 int i; 52 62 Job *job; 53 Queue *queue;63 Stack *stack; 54 64 55 queue = GetJobQueue (QueueID);56 if ( queue== NULL) return (-2);65 stack = GetJobStack (StackID); 66 if (stack == NULL) return (-2); 57 67 58 for (i = 0; i < queue[0].Nobject; i++) {59 job = (Job *) queue[0].object;68 for (i = 0; i < stack[0].Nobject; i++) { 69 job = (Job *) stack[0].object; 60 70 if (job[0].JobID == JobID) { 61 71 return (i); … … 65 75 } 66 76 67 AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv) {77 IDtype AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv) { 68 78 69 79 Job *job; … … 76 86 job[0].mode = mode; 77 87 job[0].host = NULL; 78 job[0].ID = NextJobID(); 88 job[0].JobID = NextJobID(); 89 job[0].Reset = FALSE; 79 90 80 InitIOBuffer (&job[0].stdin, 0x1000);91 /* do this step on start? */ 81 92 InitIOBuffer (&job[0].stdout, 0x1000); 82 93 InitIOBuffer (&job[0].stderr, 0x1000); 83 94 84 PutJob (job, PCONTROL_JOB_PENDING, QUEUE_BOTTOM); 95 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 96 return (job[0].JobID); 85 97 } 86 98 87 DelJob (Job *job) { 99 void DelJob (Job *job) { 100 101 int i; 88 102 89 103 FREE (job[0].hostname); … … 93 107 FREE (job[0].argv); 94 108 95 FreeIOBuffer (&job[0].stdin);96 109 FreeIOBuffer (&job[0].stdout); 97 110 FreeIOBuffer (&job[0].stderr); … … 100 113 } 101 114 102 KillJob (Job *job) { 115 # if (0) 116 void KillJob (Job *job) { 103 117 118 int status; 104 119 char line[64]; 120 Host *host; 105 121 106 122 sprintf (line, "reset\n"); … … 110 126 if ((status == -1) && (errno == EPIPE)) { 111 127 fprintf (stderr, "host %s is down\n", host[0].hostname); 112 PutHost (host, PCONTROL_HOST_DOWN, QUEUE_BOTTOM);113 PutJob (job, PCONTROL_JOB_PENDING, QUEUE_BOTTOM);128 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 129 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 114 130 return (FALSE); 115 131 } 116 132 /* check for a response */ 117 133 134 /** this needs to be cleaned up to handle the slow response case **/ 118 135 } 136 # endif 137 138 Host *UnlinkJobAndHost (Job *job) { 139 140 int N; 141 Host *host; 142 143 host = job[0].host; 144 145 /* unlink host & job */ 146 job[0].host = NULL; 147 host[0].job = NULL; 148 149 /*** need to pop host off of correct stack XXX ***/ 150 N = FindHost (host[0].HostID, host[0].stack); 151 if (N < 0) { 152 fprintf (stderr, "programming error: host is not found in current stack\n"); 153 exit (2); 154 } 155 host = GetHost (host[0].stack, N); 156 return (host); 157 } 158 159 void LinkJobAndHost (Job *job, Host *host) { 160 job[0].host = host; 161 host[0].job = job; 162 } -
trunk/Ohana/src/opihi/pcontrol/QueueOps.c
r3187 r3203 2 2 3 3 /* get object from point in stack (negative == distance from end) */ 4 void *Get Queue (Queue *queue, int where) {4 void *GetStack (Stack *stack, int where) { 5 5 6 6 int i; 7 7 void *object; 8 8 9 /* QUEUE_TOP == 0, QUEUE_BOTTOM == -1 */9 /* STACK_TOP == 0, STACK_BOTTOM == -1 */ 10 10 /* this code correctly handles the negative 'where' and Nobject == 0 */ 11 if (where < 0) where += queue[0].Nobject;11 if (where < 0) where += stack[0].Nobject; 12 12 if (where < 0) return (NULL); 13 if (where >= queue[0].Nobject) return (NULL);13 if (where >= stack[0].Nobject) return (NULL); 14 14 15 object = queue[0].object[where];16 queue[0].Nobject --;17 for (i = where; i < queue[0].Nobject; i++) {18 queue[0].object[i] = queue[0].object[i+1];15 object = stack[0].object[where]; 16 stack[0].Nobject --; 17 for (i = where; i < stack[0].Nobject; i++) { 18 stack[0].object[i] = stack[0].object[i+1]; 19 19 } 20 20 return (object); … … 22 22 23 23 /* push object on top of stack */ 24 int Put Queue (Queue *queue, int where, void *object) {24 int PutStack (Stack *stack, int where, void *object) { 25 25 26 26 int i; 27 27 28 /* QUEUE_TOP == 0, QUEUE_BOTTOM == -1 */28 /* STACK_TOP == 0, STACK_BOTTOM == -1 */ 29 29 /* this code correctly handles the negative 'where' and Nobject == 0 */ 30 if (where < 0) where += queue[0].Nobject + 1;30 if (where < 0) where += stack[0].Nobject + 1; 31 31 if (where < 0) return (FALSE); 32 if (where > queue[0].Nobject) return (FALSE);32 if (where > stack[0].Nobject) return (FALSE); 33 33 34 /* extend queueas needed */35 if ( queue[0].Nobject >= queue[0].NOBJECT) {36 queue[0].NOBJECT += 100;37 REALLOCATE ( queue[0].object, void *, queue[0].NOBJECT);34 /* extend stack as needed */ 35 if (stack[0].Nobject >= stack[0].NOBJECT) { 36 stack[0].NOBJECT += 100; 37 REALLOCATE (stack[0].object, void *, stack[0].NOBJECT); 38 38 } 39 39 40 for (i = queue[0].Nobject; i > where; i--) {41 queue[0].object[i] = queue[0].object[i-1];40 for (i = stack[0].Nobject; i > where; i--) { 41 stack[0].object[i] = stack[0].object[i-1]; 42 42 } 43 queue[0].object[where] = object;44 queue[0].Nobject ++;43 stack[0].object[where] = object; 44 stack[0].Nobject ++; 45 45 return (TRUE); 46 46 } 47 47 48 /* allocate queue, setup with default values, allocate data */49 Queue *InitQueue() {48 /* allocate stack, setup with default values, allocate data */ 49 Stack *InitStack () { 50 50 51 Queue *queue;51 Stack *stack; 52 52 53 ALLOCATE ( queue, Queue, 1);53 ALLOCATE (stack, Stack, 1); 54 54 55 queue[0].Nobject = 0;56 queue[0].NOBJECT = 50;57 ALLOCATE ( queue[0].object, void *, queue[0].NOBJECT);58 return ( queue);55 stack[0].Nobject = 0; 56 stack[0].NOBJECT = 50; 57 ALLOCATE (stack[0].object, void *, stack[0].NOBJECT); 58 return (stack); 59 59 } 60 60 61 /* these queues are not super efficient, and should probably be replaced with linked lists,61 /* these stacks are not super efficient, and should probably be replaced with linked lists, 62 62 but I find these easier to get my brain around 63 63 */ -
trunk/Ohana/src/opihi/pcontrol/StartHost.c
r3187 r3203 3 3 int StartHost (Host *host) { 4 4 5 int pid; 5 6 int stdio[3]; 6 7 7 pid = rconnect (CONNECT, host[0].hostname, PCLIENT, stdio); 8 /* pid = rconnect (CONNECT, host[0].hostname, PCLIENT, stdio); */ 9 10 pid = rconnect ("ssh", host[0].hostname, "pclient", stdio); 8 11 if (!pid) { /** failure to start **/ 9 12 fprintf (stderr, "failure to start %s\n", host[0].hostname); 10 PutHost (host, PCONTROL_HOST_DOWN, QUEUE_BOTTOM);13 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 11 14 return (FALSE); 12 15 } … … 15 18 host[0].stderr = stdio[2]; 16 19 host[0].pid = pid; 17 PutHost (host, PCONTROL_HOST_IDLE, QUEUE_BOTTOM);20 PutHost (host, PCONTROL_HOST_IDLE, STACK_BOTTOM); 18 21 return (TRUE); 19 22 } -
trunk/Ohana/src/opihi/pcontrol/StartJob.c
r3187 r3203 3 3 int StartJob (Job *job) { 4 4 5 int Nline; 6 char *line; 5 int i, Nline, status; 6 char *line, *p; 7 Host *host; 7 8 IOBuffer buffer; 8 9 9 InitIOBuffer (&buffer );10 InitIOBuffer (&buffer, 0x100); 10 11 11 12 /* job must have assigned host */ … … 17 18 18 19 /* construct command line : job arg0 arg1 ... argN\n */ 19 Nline = 10 + argc;20 for (i = 0; i < argc; i++) {20 Nline = 10 + job[0].argc; 21 for (i = 0; i < job[0].argc; i++) { 21 22 Nline += strlen (job[0].argv[i]); 22 23 } … … 24 25 bzero (line, Nline); 25 26 strcpy (line, "job"); 26 for (i = 0; i < argc; i++) {27 for (i = 0; i < job[0].argc; i++) { 27 28 strcat (line, " "); 28 29 strcat (line, job[0].argv[i]); 29 30 } 30 strcat (line, "\n");31 31 32 32 status = PclientCommand (host, line, &buffer); … … 35 35 /* check on success of pclient command */ 36 36 switch (status) { 37 case DOWN:37 case PCLIENT_DOWN: 38 38 fprintf (stderr, "host %s is down\n", host[0].hostname); 39 goto escape; 40 /*** different behavior for ANYHOST, WANTHOST, NEEDHOST ***/ 39 goto failure; 41 40 42 case HUNG:41 case PCLIENT_HUNG: 43 42 fprintf (stderr, "host %s is not responding\n", host[0].hostname); 44 goto escape; 45 /*** should we consider a HUNG host DOWN? ***/ 43 goto failure; 46 44 47 case TRUE:45 case PCLIENT_GOOD: 48 46 fprintf (stderr, "message received\n"); 49 47 break; … … 60 58 exit (1); 61 59 } 62 fscan(p, "%*s %d", &status);60 sscanf (p, "%*s %d", &status); 63 61 switch (status) { 64 62 case -1: 65 63 fprintf (stderr, "error in pclient child\n"); 66 goto escape; 67 /*** should we consider this host DOWN? ***/ 64 goto failure; 68 65 69 66 case -2: … … 77 74 default: 78 75 job[0].pid = status; 79 PutHost (host, PCONTROL_HOST_BUSY, QUEUE_BOTTOM); 80 PutJob (job, PCONTROL_JOB_BUSY, QUEUE_BOTTOM); 76 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); 77 PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM); 78 FreeIOBuffer (&buffer); 79 /** need to start timers here **/ 81 80 return (TRUE); 82 81 } … … 85 84 exit (1); 86 85 87 escape: 88 job[0].host = NULL; /* unlink host & job */ 86 failure: 87 /* unlink host & job */ 88 job[0].host = NULL; 89 89 host[0].job = NULL; 90 /*** need to pop host from corresponding queue (BUSY) ***/ 91 PutHost (host, PCONTROL_HOST_DOWN, QUEUE_BOTTOM); 92 PutJob (job, PCONTROL_JOB_PENDING, QUEUE_BOTTOM); 93 FreeBuffer (&buffer); 90 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 91 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 92 FreeIOBuffer (&buffer); 94 93 return (FALSE); 95 94 } 96 95 97 /* 98 this function sends a new command to the pclient. 99 before calling this function: 100 - grab the job from its queue (remove it from that queue with GetQueue) 101 - identify the target host (MUST already be IDLE) 102 - grab the host from its queue (remove it from that queue with GetQueue) 103 - link job and host (job[0].host = host, host[0].job = job) 104 - job must also have a valid command (argc, argv) 105 */ 96 /** note : host and job popped off stacks : can't use UnlinkJobAndHost **/ -
trunk/Ohana/src/opihi/pcontrol/host.c
r3189 r3203 3 3 int host (int argc, char **argv) { 4 4 5 int pid, status; 5 int N, Delete, Off, On; 6 Host *host; 6 7 7 /* this section needs some help: find the specified host in the queues */8 /* this section needs some help: find the specified host in the stacks */ 8 9 Delete = FALSE; 9 10 if ((N = get_argument (argc, argv, "-delete"))) { … … 12 13 } 13 14 14 /* this section needs some help: find the specified host in the queues */15 /* this section needs some help: find the specified host in the stacks */ 15 16 Off = FALSE; 16 17 if ((N = get_argument (argc, argv, "-off"))) { … … 29 30 30 31 if (Delete) { 31 host = FindHost (argv[1], PCONTROL_HOST_OFF);32 if ( host == NULL) {32 N = FindNamedHost (argv[1], PCONTROL_HOST_OFF); 33 if (N < 0) { 33 34 fprintf (stderr, "host %s is not OFF\n", argv[1]); 34 35 return (FALSE); 35 36 } 37 host = GetHost (PCONTROL_HOST_OFF, N); 36 38 DelHost (host); 37 39 return (TRUE); … … 45 47 } 46 48 host = GetHost (PCONTROL_HOST_OFF, N); 47 PutHost (host, PCONTROL_HOST_DOWN, QUEUE_BOTTOM);49 DownHost (host); 48 50 return (TRUE); 49 51 } … … 52 54 N = FindNamedHost (argv[1], PCONTROL_HOST_IDLE); 53 55 if (N >= 0) { 54 host = GetHost (PCONTROL_HOST_OFF, N); 55 PutHost (host, PCONTROL_HOST_OFF, QUEUE_BOTTOM); 56 host = GetHost (PCONTROL_HOST_IDLE, N); 57 CLOSE (host[0].stdin); 58 CLOSE (host[0].stdout); 59 CLOSE (host[0].stderr); 60 PutHost (host, PCONTROL_HOST_OFF, STACK_BOTTOM); 56 61 return (TRUE); 57 62 } 58 63 N = FindNamedHost (argv[1], PCONTROL_HOST_DOWN); 59 64 if (N >= 0) { 60 host = GetHost (PCONTROL_HOST_ OFF, N);61 PutHost (host, PCONTROL_HOST_OFF, QUEUE_BOTTOM);65 host = GetHost (PCONTROL_HOST_DOWN, N); 66 PutHost (host, PCONTROL_HOST_OFF, STACK_BOTTOM); 62 67 return (TRUE); 63 68 } 64 69 N = FindNamedHost (argv[1], PCONTROL_HOST_BUSY); 65 70 if (N >= 0) { 66 host = GetHost (PCONTROL_HOST_OFF, N); 67 PutHost (host, PCONTROL_HOST_OFF, QUEUE_BOTTOM); 71 host = GetHost (PCONTROL_HOST_BUSY, N); 72 host[0].markoff = TRUE; 73 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); 68 74 return (TRUE); 69 75 } -
trunk/Ohana/src/opihi/pcontrol/job.c
r3187 r3203 3 3 int job (int argc, char **argv) { 4 4 5 int pid, status; 5 char *Host, **targv; 6 int i, N, Mode, targc, Timeout; 7 IDtype JobID; 6 8 7 9 Host = NULL; … … 16 18 if (Mode == PCONTROL_JOB_WANTHOST) { 17 19 fprintf (stderr, "ERROR: -host and +host are incompatible\n"); 18 free(Host);20 FREE (Host); 19 21 return (FALSE); 20 22 } … … 34 36 if (argc < 2) { 35 37 fprintf (stderr, "USAGE: job [options] (arg0) (arg1) ... (argN)\n"); 38 FREE (Host); 36 39 return (FALSE); 37 40 } … … 46 49 FREE (Host); 47 50 48 fprintf (stdout, "STATUS %d\n", ChildPID);51 fprintf (stdout, "STATUS %d\n", JobID); 49 52 return (TRUE); 50 53 -
trunk/Ohana/src/opihi/pcontrol/pclient.c
r3187 r3203 4 4 # define PCLIENT_PROMPT "pclient:" 5 5 6 # define DOWN 07 # define HUNG -18 9 6 int PclientCommand (Host *host, char *command, IOBuffer *buffer) { 10 7 11 /* send command to client */ 12 status = write (host[0].stdin, command, strlen(command)); 13 if ((status == -1) && (errno == EPIPE)) return (DOWN); 8 int i; 9 int status; 10 char *line; 11 12 /* send command to client (adding on \n) */ 13 ALLOCATE (line, char, MAX (1, strlen(command))); 14 sprintf (line, "%s\n", command); 15 status = write (host[0].stdin, line, strlen(line)); 16 free (line); 17 18 /* is pipe still open? */ 19 if ((status == -1) && (errno == EPIPE)) return (PCLIENT_DOWN); 14 20 15 21 /* watch for response - wait up to 1 second */ 16 p= NULL;22 line = NULL; 17 23 status = -1; 18 for (i = 0; (i < PCLIENT_TIMEOUT) && (status == -1) && ( p== NULL); i++) {24 for (i = 0; (i < PCLIENT_TIMEOUT) && (status == -1) && (line == NULL); i++) { 19 25 status = ReadtoIOBuffer (buffer, host[0].stdout); 20 p= memstr (buffer[0].buffer, PCLIENT_PROMPT, buffer[0].Nbuffer);26 line = memstr (buffer[0].buffer, PCLIENT_PROMPT, buffer[0].Nbuffer); 21 27 } 22 if (status == 0) return ( DOWN);23 if (status == -1) return ( HUNG);24 return ( TRUE);28 if (status == 0) return (PCLIENT_DOWN); 29 if (status == -1) return (PCLIENT_HUNG); 30 return (PCLIENT_GOOD); 25 31 } 32 33 /* memstr returns a view, not an allocated string : don't free */ -
trunk/Ohana/src/opihi/pcontrol/pcontrol.c
r3187 r3203 41 41 InitOutfile (); 42 42 InitPcontrol (); 43 InitChild ();44 43 45 44 rl_readline_name = opihi_name; -
trunk/Ohana/src/opihi/pcontrol/rconnect.c
r3187 r3203 10 10 int i, stdin_fd[2], stdout_fd[2], stderr_fd[2], status; 11 11 pid_t pid; 12 char command[0x100];13 12 char *p; 13 char **argv; 14 14 IOBuffer buffer; 15 15 … … 76 76 status = -1; 77 77 for (i = 0; (i < CONNECT_TIMEOUT) && (status == -1) && (p == NULL); i++) { 78 status = ReadtoIOBuffer ( buffer, stdout_fd[0]);79 p = memstr (buffer [0].buffer, "CONNECTED", buffer[0].Nbuffer);78 status = ReadtoIOBuffer (&buffer, stdout_fd[0]); 79 p = memstr (buffer.buffer, "CONNECTED", buffer.Nbuffer); 80 80 } 81 81 if (status == 0) goto pipe_error;
Note:
See TracChangeset
for help on using the changeset viewer.
