[Patch] fixes for bproc_pidlist() and bproc_pidnode()

Jag agrajag@linuxpower.org
Thu, 15 Feb 2001 05:53:34 -0800


--zmbF4WfaG2f6E7cU
Content-Type: multipart/mixed; boundary="HC0F8i/BfMshQzR8"
Content-Disposition: inline


--HC0F8i/BfMshQzR8
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

In BProc 2.2, bproc_pidlist() and bproc_pidnode() did not return the
proper value because they used the wrong struct to try to read an
mmap'ed file.  The program bpstat, does properlly understand the mmaped
file, so I borrowed some code from bpstat in order to make
bproc_pidlist() and bproc_pidnode() in libbproc work properlly.

I also modified bproc_pidnode() so that on error it returns -3
(BPROC_NODE_NONE) as opposed to -1 (BPROC_NODE_MASTER).  I did this
because there are times when it is valid to return -1 to represent the
process is running on the master node, when in fact there is no error.
With the code in in BProc 2.2, its impossible for a developer to know if
bproc_pidnode() returning -1 means the process is running on the master
node, or if there was an error (such as not being able to map the file,
or the process not existing).

Jag

--HC0F8i/BfMshQzR8
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="bproc-2.2-fixpids.patch"
Content-Transfer-Encoding: quoted-printable

diff -ur bproc-2.2/clients/bproc.c bproc-2.2.fixpids/clients/bproc.c
--- bproc-2.2/clients/bproc.c	Fri Dec  1 11:41:50 2000
+++ bproc-2.2.fixpids/clients/bproc.c	Wed Feb 14 15:24:19 2001
@@ -240,18 +240,33 @@
  *  PID mapping DB routines
  *-----------------------------------------------------------------------*/
 #define MAXPID 32768
-struct bproc_status_type {
-    int proc_node;
-    int ghost_node;
+
+struct assoc_t {
+    void *move_req_id;          /* Request ID of move in progress */
+
+    /* Other locations */
+    struct node_t *proc;        /* Where a process exists */
+    struct node_t *movingto;    /* Where a process is in the process of mo=
ving to */
+    struct node_t *last_loc;    /* Where a process was located last */
+    struct node_t *ghost;       /* Where a process has a ghost */
 };
-static struct bproc_status_type *status=3D0;
+
+static struct assoc_t *status=3D0;
+static unsigned long node_offset;
+static unsigned long node_size;
+static int node_number(struct node_t *node) {
+    if (node =3D=3D 0) return BPROC_NODE_MASTER;
+    return (((long)node)-node_offset)/node_size;
+}
+
 static
 int map_process_state(void) {
     int fd;
+    unsigned long *ptr;
     fd =3D open(PROCESS_STATUS_FILE, O_RDONLY);
     if (fd =3D=3D -1) return -1;
   =20
-    status =3D mmap(0, sizeof(struct bproc_status_type) * MAXPID,
+    status =3D mmap(0, sizeof(struct assoc_t) * MAXPID + sizeof(long)*2,
 		  PROT_READ, MAP_SHARED, fd, 0);
     if (status =3D=3D MAP_FAILED) {
 	status =3D 0;
@@ -259,14 +274,22 @@
 	return -1;
     }
     close(fd);
+
+    ptr =3D (unsigned long *) &status[MAXPID];
+    node_offset =3D ptr[0];
+    node_size   =3D ptr[1];
     return 0;
 }
=20
 int  bproc_pidnode(int pid) {
     if (pid < 0 || pid >=3D MAXPID) return -1;
     if (!status) map_process_state();
-    if (!status) return -1;
-    return status[pid].proc_node;
+    if (!status) return BPROC_NODE_NONE;
+    if (status[pid].proc || status[pid].ghost) {
+        return node_number(status[pid].proc);
+    } else {
+	return BPROC_NODE_NONE;
+    }
 }
=20
 int *bproc_pidlist(void) {
@@ -278,7 +301,7 @@
     if (!list) return 0;
=20
     for (i=3Dj=3D0; i< MAXPID; i++)
-	if (status[i].proc_node !=3D -1)
+	if (status[i].proc !=3D 0 || status[i].ghost !=3D 0)
 	    list[j++]=3Di;
     list[j++] =3D 0;
     return list;

--HC0F8i/BfMshQzR8--

--zmbF4WfaG2f6E7cU
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6i99e+pq97aGGtXARAiV7AKCbkTPnCodQAR7GZDgLLfQrFLSjqgCgzdMC
/IHy9QJQ1xjwD49qD4weNp0=
=YerD
-----END PGP SIGNATURE-----

--zmbF4WfaG2f6E7cU--