Changeset 3203 for trunk/Ohana/src/opihi/pcontrol/JobOps.c
- Timestamp:
- Feb 12, 2005, 9:34:34 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pcontrol/JobOps.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.
