Index: trunk/Ohana/src/opihi/pcontrol/MachineOps.c
===================================================================
--- trunk/Ohana/src/opihi/pcontrol/MachineOps.c	(revision 26521)
+++ trunk/Ohana/src/opihi/pcontrol/MachineOps.c	(revision 29540)
@@ -1,3 +1,4 @@
 # include "pcontrol.h"
+# define DEBUG 0
 
 static int MAX_UNWANTED_HOST_JOBS = 5;
@@ -107,4 +108,5 @@
 int AddMachineJob (Host *host, Job *job) {
 
+  int i;
   Machine *machine;
 
@@ -114,7 +116,14 @@
   machine[0].NjobsRealhost ++;
 
-  // skip jobs that do not have a targeted host
-  if (job[0].hostname == NULL) {
-    return (TRUE);
+  // skip jobs that do not have a targeted host or any xhosts
+  if (!job[0].hostname && !job[0].Nxhosts) {
+    return (TRUE);
+  }
+
+  for (i = 0; i < job[0].Nxhosts; i++) {
+    // find machine matching the xhost name (these count against the unwanted host total)
+    machine = FindMachineByName (job[0].xhosts[i]); // Can this fail?
+    if (!machine) continue;
+    machine[0].NjobsWanthost ++;
   }
 
@@ -134,4 +143,5 @@
 int DelMachineJob (Host *host, Job *job) {
 
+  int i;
   Machine *machine;
 
@@ -141,7 +151,14 @@
   machine[0].NjobsRealhost --;
 
-  // skip jobs that do not have a targeted host
-  if (job[0].hostname == NULL) {
-    return (TRUE);
+  // skip jobs that do not have a targeted host or any xhosts
+  if (!job[0].hostname && !job[0].Nxhosts) {
+    return (TRUE);
+  }
+
+  for (i = 0; i < job[0].Nxhosts; i++) {
+    // find machine matching the xhost name (these count against the unwanted host total)
+    machine = FindMachineByName (job[0].xhosts[i]); // Can this fail?
+    if (!machine) continue;
+    machine[0].NjobsWanthost --;
   }
 
@@ -175,21 +192,36 @@
 int CheckMachineJobs (Host *host, Job *job) {
 
+  int i;
   Machine *machine;
 
   machine = FindMachineByName (job[0].hostname);
-  if (machine == NULL) return (TRUE);
-  // fprintf (stderr, "wanthost: %s, Ntotal: %d, Nmax: %d\n", job[0].hostname, machine[0].NjobsWanthost + machine[0].NjobsRealhost, machine[0].Nhosts + MAX_UNWANTED_HOST_JOBS);
-  // if (machine[0].NjobsWanthost + machine[0].NjobsRealhost >= machine[0].Nhosts + MAX_UNWANTED_HOST_JOBS) {
-  if (machine[0].NjobsWanthost >= MAX_UNWANTED_HOST_JOBS) {
-    // fprintf (stderr, "too many outstanding jobs wanting host %s, delay job %s for now\n", job[0].hostname, job[0].argv[0]);
-    return (FALSE);
-  }
+  if (machine) {
+    if (DEBUG) fprintf (stderr, "wanthost: %s, Ntotal: %d, Nmax: %d\n", machine[0].name, machine[0].NjobsWanthost + machine[0].NjobsRealhost, machine[0].Nhosts + MAX_UNWANTED_HOST_JOBS);
+    if (machine[0].NjobsWanthost >= MAX_UNWANTED_HOST_JOBS) {
+      if (DEBUG) fprintf (stderr, "too many outstanding jobs wanting host %s, delay job %s for now\n", machine[0].name, job[0].argv[0]);
+      return (FALSE);
+    }
+  }
+
+  for (i = 0; i < job[0].Nxhosts; i++) {
+    machine = FindMachineByName (job[0].xhosts[i]);
+    if (machine) {
+      if (DEBUG) fprintf (stderr, "xhost: %s, Ntotal: %d, Nmax: %d\n", machine[0].name, machine[0].NjobsWanthost + machine[0].NjobsRealhost, machine[0].Nhosts + MAX_UNWANTED_HOST_JOBS);
+      if (machine[0].NjobsWanthost >= MAX_UNWANTED_HOST_JOBS) {
+	if (DEBUG) fprintf (stderr, "too many outstanding jobs wanting host %s, delay job %s for now\n", machine[0].name, job[0].argv[0]);
+	return (FALSE);
+      }
+    }
+  }    
 
   machine = FindMachineByName (host[0].hostname);
-  // fprintf (stderr, "realhost: %s, Ntotal: %d, Nmax: %d\n", host[0].hostname, machine[0].NjobsWanthost + machine[0].NjobsRealhost, machine[0].Nhosts + MAX_UNWANTED_HOST_JOBS);
-  if (machine[0].NjobsWanthost >= MAX_UNWANTED_HOST_JOBS) {
-    // fprintf (stderr, "too many outstanding jobs wanting host %s, delay job %s for now\n", job[0].hostname, job[0].argv[0]);
-    return (FALSE);
-  }
+  if (machine) {
+    if (DEBUG) fprintf (stderr, "realhost: %s, Ntotal: %d, Nmax: %d\n", machine[0].name, machine[0].NjobsWanthost + machine[0].NjobsRealhost, machine[0].Nhosts + MAX_UNWANTED_HOST_JOBS);
+    if (machine[0].NjobsWanthost >= MAX_UNWANTED_HOST_JOBS) {
+      if (DEBUG) fprintf (stderr, "too many outstanding jobs wanting host %s, delay job %s for now\n", machine[0].name, job[0].argv[0]);
+      return (FALSE);
+    }
+  }
+
   return (TRUE);
 }
