[Patch] bproc_pidghostnode()

Jag agrajag@linuxpower.org
Mon, 19 Feb 2001 08:15:38 -0800


--ulKx6OyYBbhdAroi
Content-Type: multipart/mixed; boundary="+QoFl77rH4lq6But"
Content-Disposition: inline


--+QoFl77rH4lq6But
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

In case anyone's interested in this patch, I found a small bug in it
where 'bpstat -p' always listed the PIDs as 0-n instead of the actual
pids.  A fixed patch is attached.

On Thu, 15 Feb 2001, Jag wrote:

> This patch adds the function bproc_pidghostnode() to libbproc.  With the
> addition of this function, bpstat no longer needs to directly mmap
> /var/run/bproc_status and can instead just use libbproc's functionality
> for that.  This patch also modifies bpstat so that it does use libbproc
> instead of directly mmaping /var/run/bproc_status.
>=20
> You need to apply the patch for bproc_pidlist() and bproc_pidnode() I
> sent this morning in order for this patch to work.
>=20
>=20
> Jag

> diff -ur bproc-2.2.fixpids/clients/bproc.c bproc-2.2.ghostnode/clients/bp=
roc.c
> --- bproc-2.2.fixpids/clients/bproc.c	Thu Feb 15 18:38:38 2001
> +++ bproc-2.2.ghostnode/clients/bproc.c	Thu Feb 15 18:41:12 2001
> @@ -292,6 +292,17 @@
>      }
>  }
> =20
> +int  bproc_pidghostnode(int pid) {
> +    if (pid < 0 || pid >=3D MAXPID) return -1;
> +    if (!status) map_process_state();
> +    if (!status) return BPROC_NODE_NONE;
> +    if (status[pid].proc || status[pid].ghost) {
> +        return node_number(status[pid].ghost);
> +    } else {
> +	return BPROC_NODE_NONE;
> +    }
> +}
> +
>  int *bproc_pidlist(void) {
>      int *list;
>      int i, j;
> diff -ur bproc-2.2.fixpids/clients/bpstat.c bproc-2.2.ghostnode/clients/b=
pstat.c
> --- bproc-2.2.fixpids/clients/bpstat.c	Fri Dec  1 11:41:50 2000
> +++ bproc-2.2.ghostnode/clients/bpstat.c	Thu Feb 15 19:01:39 2001
> @@ -32,24 +32,6 @@
>  #include <errno.h>
>  #include <netinet/in.h>
> =20
> -/* This stuff should really be in a shared header file somewhere. */
> -#define MAXPID 32768
> -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 mov=
ing to */
> -    struct node_t *last_loc;	/* Where a process was located last */
> -    struct node_t *ghost;	/* Where a process has a ghost */
> -};
> -
> -#define PROCESS_STATUS_FILE "/var/run/bproc_status"
> -
> -unsigned long node_offset;
> -unsigned long node_size;
> -struct assoc_t *status;
> -
>  char *node_state_strings[] =3D BPROC_NODE_STATE_STRINGS;
>  char *ip2str(struct sockaddr_in *addr) {
>      static char buf[30];
> @@ -61,28 +43,6 @@
>      return buf;
>  }
> =20
> -void mmap_status_file(void) {
> -    int fd;
> -    unsigned long *ptr;
> -    fd =3D open(PROCESS_STATUS_FILE, O_RDONLY);
> -    if (fd =3D=3D -1) {
> -	perror(PROCESS_STATUS_FILE);
> -	exit(1);
> -    }
> -   =20
> -    status =3D mmap(0, sizeof(struct assoc_t) * MAXPID + sizeof(long)*2,
> -		  PROT_READ, MAP_SHARED, fd, 0);
> -    if (status =3D=3D MAP_FAILED) {
> -	perror("mmap");
> -	exit(1);
> -    }
> -    close(fd);
> -
> -    ptr =3D (unsigned long *) &status[MAXPID];
> -    node_offset =3D ptr[0];
> -    node_size   =3D ptr[1];
> -}
> -
>  /* Print general machine state */
>  void print_machine_state(void) {
>      int i, stat, num;
> @@ -148,22 +108,20 @@
> =20
> =20
> =20
> -int node_number(struct node_t *node) {
> -    if (node =3D=3D 0) return -1;
> -    return (((long)node)-node_offset)/node_size;
> -}
> -
>  void print_process_state(void) {
>      int i;
> -    mmap_status_file();
> +    int *pidlist;
> +
>      printf("PID\tNode\tGhost\n");
> -    for (i=3D0; i < MAXPID; i++) {
> -	if (status[i].proc =3D=3D 0 && status[i].ghost =3D=3D 0) continue;
> +    pidlist =3D bproc_pidlist();
> +    if (!pidlist)
> +      return;
> +    for (i=3D0; pidlist[i]; i++) {
>  	printf("%d\t%d\t%d\n", i,
> -	       node_number(status[i].proc),
> -	       node_number(status[i].ghost));
> +	       bproc_pidnode(pidlist[i]),
> +	       bproc_pidghostnode(pidlist[i]));
>      }
> -    munmap(status, sizeof(struct assoc_t) * MAXPID + sizeof(long)*2);
> +    free(pidlist);
>  }
> =20
>  void print_node_address(char *_arg) {
> @@ -206,8 +164,8 @@
>      int pid;
>      char line[10000], *check;
>      int pidoffset;
> +    int pidnode;
> =20
> -    mmap_status_file();
> =20
>      if (!fgets(line, 10000, stdin)) return;
>      /* This is the header line... we need to find "PID" */
> @@ -232,8 +190,9 @@
>  	    fprintf(stderr, "punting on: %s", line);
>  	    continue;
>  	}
> -	if (status[pid].proc)
> -	    printf("%d\t", node_number(status[pid].proc));
> +	pidnode =3D bproc_pidnode(pid);
> +	if (pidnode >=3D 0)
> +	    printf("%d\t", pidnode);
>  	else
>  	    fputs("\t",stdout);
>  	fputs(line,stdout);
> diff -ur bproc-2.2.fixpids/clients/sys/bproc.h bproc-2.2.ghostnode/client=
s/sys/bproc.h
> --- bproc-2.2.fixpids/clients/sys/bproc.h	Fri Dec  1 11:41:50 2000
> +++ bproc-2.2.ghostnode/clients/sys/bproc.h	Thu Feb 15 18:41:24 2001
> @@ -83,6 +83,7 @@
> =20
>  /* Process information functions */
>  int  bproc_pidnode(int pid);
> +int  bproc_pidghostnode(int pid);
>  int *bproc_pidlist(void);
> =20
>  int  bproc_rexec       (int node, const char *cmd, char * const argv[],




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

diff -ur bproc-2.2.fixpids/clients/bproc.c bproc-2.2.ghostnode/clients/bpro=
c.c
--- bproc-2.2.fixpids/clients/bproc.c	Thu Feb 15 18:38:38 2001
+++ bproc-2.2.ghostnode/clients/bproc.c	Thu Feb 15 18:41:12 2001
@@ -292,6 +292,17 @@
     }
 }
=20
+int  bproc_pidghostnode(int pid) {
+    if (pid < 0 || pid >=3D MAXPID) return -1;
+    if (!status) map_process_state();
+    if (!status) return BPROC_NODE_NONE;
+    if (status[pid].proc || status[pid].ghost) {
+        return node_number(status[pid].ghost);
+    } else {
+	return BPROC_NODE_NONE;
+    }
+}
+
 int *bproc_pidlist(void) {
     int *list;
     int i, j;
diff -ur bproc-2.2.fixpids/clients/bpstat.c bproc-2.2.ghostnode/clients/bps=
tat.c
--- bproc-2.2.fixpids/clients/bpstat.c	Fri Dec  1 11:41:50 2000
+++ bproc-2.2.ghostnode/clients/bpstat.c	Mon Feb 19 11:12:16 2001
@@ -32,24 +32,6 @@
 #include <errno.h>
 #include <netinet/in.h>
=20
-/* This stuff should really be in a shared header file somewhere. */
-#define MAXPID 32768
-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 movin=
g to */
-    struct node_t *last_loc;	/* Where a process was located last */
-    struct node_t *ghost;	/* Where a process has a ghost */
-};
-
-#define PROCESS_STATUS_FILE "/var/run/bproc_status"
-
-unsigned long node_offset;
-unsigned long node_size;
-struct assoc_t *status;
-
 char *node_state_strings[] =3D BPROC_NODE_STATE_STRINGS;
 char *ip2str(struct sockaddr_in *addr) {
     static char buf[30];
@@ -61,28 +43,6 @@
     return buf;
 }
=20
-void mmap_status_file(void) {
-    int fd;
-    unsigned long *ptr;
-    fd =3D open(PROCESS_STATUS_FILE, O_RDONLY);
-    if (fd =3D=3D -1) {
-	perror(PROCESS_STATUS_FILE);
-	exit(1);
-    }
-   =20
-    status =3D mmap(0, sizeof(struct assoc_t) * MAXPID + sizeof(long)*2,
-		  PROT_READ, MAP_SHARED, fd, 0);
-    if (status =3D=3D MAP_FAILED) {
-	perror("mmap");
-	exit(1);
-    }
-    close(fd);
-
-    ptr =3D (unsigned long *) &status[MAXPID];
-    node_offset =3D ptr[0];
-    node_size   =3D ptr[1];
-}
-
 /* Print general machine state */
 void print_machine_state(void) {
     int i, stat, num;
@@ -148,22 +108,20 @@
=20
=20
=20
-int node_number(struct node_t *node) {
-    if (node =3D=3D 0) return -1;
-    return (((long)node)-node_offset)/node_size;
-}
-
 void print_process_state(void) {
     int i;
-    mmap_status_file();
+    int *pidlist;
+
     printf("PID\tNode\tGhost\n");
-    for (i=3D0; i < MAXPID; i++) {
-	if (status[i].proc =3D=3D 0 && status[i].ghost =3D=3D 0) continue;
-	printf("%d\t%d\t%d\n", i,
-	       node_number(status[i].proc),
-	       node_number(status[i].ghost));
+    pidlist =3D bproc_pidlist();
+    if (!pidlist)
+      return;
+    for (i=3D0; pidlist[i]; i++) {
+	printf("%d\t%d\t%d\n", pidlist[i],
+	       bproc_pidnode(pidlist[i]),
+	       bproc_pidghostnode(pidlist[i]));
     }
-    munmap(status, sizeof(struct assoc_t) * MAXPID + sizeof(long)*2);
+    free(pidlist);
 }
=20
 void print_node_address(char *_arg) {
@@ -206,8 +164,8 @@
     int pid;
     char line[10000], *check;
     int pidoffset;
+    int pidnode;
=20
-    mmap_status_file();
=20
     if (!fgets(line, 10000, stdin)) return;
     /* This is the header line... we need to find "PID" */
@@ -232,8 +190,9 @@
 	    fprintf(stderr, "punting on: %s", line);
 	    continue;
 	}
-	if (status[pid].proc)
-	    printf("%d\t", node_number(status[pid].proc));
+	pidnode =3D bproc_pidnode(pid);
+	if (pidnode >=3D 0)
+	    printf("%d\t", pidnode);
 	else
 	    fputs("\t",stdout);
 	fputs(line,stdout);
diff -ur bproc-2.2.fixpids/clients/sys/bproc.h bproc-2.2.ghostnode/clients/=
sys/bproc.h
--- bproc-2.2.fixpids/clients/sys/bproc.h	Fri Dec  1 11:41:50 2000
+++ bproc-2.2.ghostnode/clients/sys/bproc.h	Thu Feb 15 18:41:24 2001
@@ -83,6 +83,7 @@
=20
 /* Process information functions */
 int  bproc_pidnode(int pid);
+int  bproc_pidghostnode(int pid);
 int *bproc_pidlist(void);
=20
 int  bproc_rexec       (int node, const char *cmd, char * const argv[],

--+QoFl77rH4lq6But--

--ulKx6OyYBbhdAroi
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

iD8DBQE6kUaq+pq97aGGtXARAjxrAJ9Gtc/8zJickwoWJZQU9pG43B26fwCgk1fB
UxKQru9rlcUEVt3NLjIgT7c=
=e+6r
-----END PGP SIGNATURE-----

--ulKx6OyYBbhdAroi--