Changeset 19125
- Timestamp:
- Aug 19, 2008, 12:29:10 PM (18 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 1 added
- 3 edited
-
include/pantasks.h (modified) (2 diffs)
-
pantasks/ControllerOps.c (modified) (6 diffs)
-
pantasks/controller_host.c (modified) (3 diffs)
-
pantasks/test/threads.sh (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/include/pantasks.h
r17419 r19125 58 58 int Nrun; 59 59 } TimeRange; 60 61 /* data to define a host machine */ 62 typedef struct { 63 char *hostname; 64 int max_threads; 65 } Host; 60 66 61 67 /* a task is a description of the wrapping of a job */ … … 233 239 int QuitController (); 234 240 int StopController (); 241 int RestartController (); 235 242 int VerboseMode (); 236 243 int KillLocalJob (Job *job); -
trunk/Ohana/src/opihi/pantasks/ControllerOps.c
r18085 r19125 10 10 static IOBuffer stderr_buffer; 11 11 static int ControllerPID = 0; 12 13 /* local static variables to track the controller host properties */ 14 static Host *hosts = NULL; 15 static int Nhosts = 0; 16 static int NHOSTS = 0; 17 18 int AddHost (char *hostname, int max_threads) { 19 20 int N; 21 22 N = Nhosts; 23 Nhosts ++; 24 25 CHECK_REALLOCATE (hosts, Host, NHOSTS, Nhosts, 16); 26 27 hosts[N].hostname = strcreate (hostname); 28 hosts[N].max_threads = max_threads; 29 30 return (TRUE); 31 } 32 33 int DeleteHost (char *hostname) { 34 35 int i, j; 36 37 for (i = 0; i < Nhosts; i++) { 38 if (strcmp (hosts[i].hostname, hostname)) continue; 39 40 // delete this one 41 free (hosts[i].hostname); 42 for (j = i; j < Nhosts - 1; j++) { 43 hosts[j].hostname = hosts[j+1].hostname; 44 hosts[j].max_threads = hosts[j+1].max_threads; 45 } 46 Nhosts --; 47 return (TRUE); 48 } 49 return (FALSE); 50 } 12 51 13 52 /* test if the controller is running */ … … 146 185 147 186 /* is pipe still open? */ 148 if ((status == -1) && (errno == EPIPE)) return (CONTROLLER_DOWN); 187 // XXX call StopController() here? 188 if ((status == -1) && (errno == EPIPE)) { 189 StopController (); 190 return (CONTROLLER_DOWN); 191 } 149 192 150 193 /* read at least Nbytes, then watch for CONTROLLER_PROMPT */ … … 158 201 if (status == -1) nanosleep (&request, &remain); 159 202 } 160 if (status == 0) return (CONTROLLER_DOWN); 203 if (status == 0) { 204 StopController (); 205 return (CONTROLLER_DOWN); 206 } 161 207 if (status == -1) return (CONTROLLER_HUNG); 162 208 … … 245 291 if (VarConfig ("CONTROLLER", "%s", cmd) == NULL) strcpy (cmd, "pcontrol"); 246 292 293 if (hosts == NULL) { 294 NHOSTS = 16; 295 ALLOCATE (hosts, Host, NHOSTS); 296 } 297 247 298 bzero (stdin_fd, 2*sizeof(int)); 248 299 bzero (stdout_fd, 2*sizeof(int)); … … 360 411 if ((status == -1) && (errno == EPIPE)) { 361 412 StopController (); 362 gprint (GP_ERR, "controller is down\n"); 413 gprint (GP_ERR, "controller is down, restarting\n"); 414 if (!RestartController ()) { 415 return (FALSE); 416 } 363 417 return (FALSE); 364 418 } … … 509 563 return (TRUE); 510 564 } 565 566 int RestartController () { 567 568 int i, status; 569 char command[256]; 570 IOBuffer buffer; 571 572 gprint (GP_ERR, "controller is down, restarting\n"); 573 if (!StartController ()) { 574 gprint (GP_ERR, "failure to re-start pcontrol\n"); 575 return (FALSE); 576 } 577 578 InitIOBuffer (&buffer, 0x100); 579 580 // XXX lock the host table? SerialThreadLock (); 581 fprintf (stderr, "controller is down, restarting\n"); 582 for (i = 0; i < Nhosts; i++) { 583 fprintf (stderr, "controller host add %s -threads %d\n", hosts[i].hostname, hosts[i].max_threads); 584 snprintf (command, 256, "host add %s -threads %d\n", hosts[i].hostname, hosts[i].max_threads); 585 status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer); 586 } 587 // SerialThreadUnlock (); 588 589 if (status) gwrite (buffer.buffer, 1, buffer.Nbuffer, GP_LOG); 590 591 FreeIOBuffer (&buffer); 592 593 return (TRUE); 594 } -
trunk/Ohana/src/opihi/pantasks/controller_host.c
r8548 r19125 3 3 int controller_host (int argc, char **argv) { 4 4 5 int status;5 int N, status, max_threads; 6 6 char command[1024]; 7 7 IOBuffer buffer; 8 8 9 if (argc != 3) { 10 gprint (GP_ERR, "USAGE: controller host (command) (hostname)\n"); 11 return (FALSE); 9 max_threads = 0; 10 if ((N = get_argument (argc, argv, "-threads"))) { 11 remove_argument (N, &argc, argv); 12 max_threads = atoi(argv[N]); 13 remove_argument (N, &argc, argv); 12 14 } 15 16 if (argc != 3) goto usage; 13 17 14 18 /* start controller connection (if needed) */ … … 18 22 } 19 23 20 sprintf (command, "host %s %s", argv[1], argv[2]); 24 // the user may issue any of these commands: 25 // ADD, ON, RETRY, CHECK, OFF, DELETE 26 // we need to catch ADD and DELETE and modify our host table accordingly 27 if (!strcasecmp (argv[1], "ADD")) { 28 AddHost (argv[2], max_threads); 29 } else { 30 if (max_threads) goto usage; 31 } 32 33 if (!strcasecmp (argv[1], "DELETE")) { 34 DeleteHost (argv[2]); 35 } 36 37 if (max_threads) { 38 sprintf (command, "host %s %s -threads %d", argv[1], argv[2], max_threads); 39 } else { 40 sprintf (command, "host %s %s", argv[1], argv[2]); 41 } 21 42 InitIOBuffer (&buffer, 0x100); 22 43 … … 29 50 FreeIOBuffer (&buffer); 30 51 return (TRUE); 52 53 usage: 54 gprint (GP_LOG, "USAGE: controller host (command) (hostname)\n"); 55 gprint (GP_ERR, " valid commands: add, on, retry, check, off, delete\n"); 56 gprint (GP_ERR, " -threads Nthreads is optional for 'add'\n"); 57 return (FALSE); 31 58 } 32 59
Note:
See TracChangeset
for help on using the changeset viewer.
