Hi,
I would like to replace the manual list in unix domain sockets with
a SLIST. That makes the code easier to read.
ok?
bluhm
Index: sys/kern/kern_sysctl.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.283
diff -u -p -r1.283 kern_sysctl.c
--- sys/kern/kern_sysctl.c 11 Feb 2015 05:09:33 -0000 1.283
+++ sys/kern/kern_sysctl.c 28 Mar 2015 11:48:10 -0000
@@ -1146,8 +1146,10 @@ fill_file(struct kinfo_file *kf, struct
if (show_pointers) {
kf->unp_conn = PTRTOINT64(unpcb->unp_conn);
- kf->unp_refs = PTRTOINT64(unpcb->unp_refs);
- kf->unp_nextref =
PTRTOINT64(unpcb->unp_nextref);
+ kf->unp_refs = PTRTOINT64(
+ SLIST_FIRST(&unpcb->unp_refs));
+ kf->unp_nextref = PTRTOINT64(
+ SLIST_NEXT(unpcb, unp_nextref));
kf->v_un = PTRTOINT64(unpcb->unp_vnode);
kf->unp_addr = PTRTOINT64(unpcb->unp_addr);
}
Index: sys/kern/uipc_usrreq.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/uipc_usrreq.c,v
retrieving revision 1.79
diff -u -p -r1.79 uipc_usrreq.c
--- sys/kern/uipc_usrreq.c 11 Dec 2014 19:21:57 -0000 1.79
+++ sys/kern/uipc_usrreq.c 28 Mar 2015 11:48:10 -0000
@@ -38,6 +38,7 @@
#include <sys/filedesc.h>
#include <sys/domain.h>
#include <sys/protosw.h>
+#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/unpcb.h>
@@ -380,8 +381,8 @@ unp_detach(struct unpcb *unp)
}
if (unp->unp_conn)
unp_disconnect(unp);
- while (unp->unp_refs)
- unp_drop(unp->unp_refs, ECONNRESET);
+ while (!SLIST_EMPTY(&unp->unp_refs))
+ unp_drop(SLIST_FIRST(&unp->unp_refs), ECONNRESET);
soisdisconnected(unp->unp_socket);
unp->unp_socket->so_pcb = NULL;
m_freem(unp->unp_addr);
@@ -554,8 +555,7 @@ unp_connect2(struct socket *so, struct s
switch (so->so_type) {
case SOCK_DGRAM:
- unp->unp_nextref = unp2->unp_refs;
- unp2->unp_refs = unp;
+ SLIST_INSERT_HEAD(&unp2->unp_refs, unp, unp_nextref);
soisconnected(so);
break;
@@ -583,20 +583,7 @@ unp_disconnect(struct unpcb *unp)
switch (unp->unp_socket->so_type) {
case SOCK_DGRAM:
- if (unp2->unp_refs == unp)
- unp2->unp_refs = unp->unp_nextref;
- else {
- unp2 = unp2->unp_refs;
- for (;;) {
- if (unp2 == NULL)
- panic("unp_disconnect");
- if (unp2->unp_nextref == unp)
- break;
- unp2 = unp2->unp_nextref;
- }
- unp2->unp_nextref = unp->unp_nextref;
- }
- unp->unp_nextref = NULL;
+ SLIST_REMOVE(&unp2->unp_refs, unp, unpcb, unp_nextref);
unp->unp_socket->so_state &= ~SS_ISCONNECTED;
break;
Index: sys/sys/unpcb.h
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/sys/unpcb.h,v
retrieving revision 1.8
diff -u -p -r1.8 unpcb.h
--- sys/sys/unpcb.h 30 Jun 2010 19:57:05 -0000 1.8
+++ sys/sys/unpcb.h 28 Mar 2015 11:48:10 -0000
@@ -63,8 +63,8 @@ struct unpcb {
struct vnode *unp_vnode; /* if associated with file */
ino_t unp_ino; /* fake inode number */
struct unpcb *unp_conn; /* control block of connected socket */
- struct unpcb *unp_refs; /* referencing socket linked list */
- struct unpcb *unp_nextref; /* link in unp_refs list */
+ SLIST_HEAD(,unpcb) unp_refs; /* referencing socket linked list */
+ SLIST_ENTRY(unpcb) unp_nextref; /* link in unp_refs list */
struct mbuf *unp_addr; /* bound address of socket */
int unp_flags; /* this unpcb contains peer eids */
struct sockpeercred unp_connid;/* id of peer process */
Index: lib/libkvm/kvm_file2.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/lib/libkvm/kvm_file2.c,v
retrieving revision 1.44
diff -u -p -r1.44 kvm_file2.c
--- lib/libkvm/kvm_file2.c 11 Feb 2015 05:11:04 -0000 1.44
+++ lib/libkvm/kvm_file2.c 28 Mar 2015 12:30:34 -0000
@@ -656,8 +656,10 @@ fill_file(kvm_t *kd, struct kinfo_file *
return (-1);
}
kf->unp_conn = PTRTOINT64(unpcb.unp_conn);
- kf->unp_refs = PTRTOINT64(unpcb.unp_refs);
- kf->unp_nextref = PTRTOINT64(unpcb.unp_nextref);
+ kf->unp_refs = PTRTOINT64(
+ SLIST_FIRST(&unpcb.unp_refs));
+ kf->unp_nextref = PTRTOINT64(
+ SLIST_NEXT(&unpcb, unp_nextref));
kf->v_un = PTRTOINT64(unpcb.unp_vnode);
if (unpcb.unp_addr != NULL) {
struct mbuf mb;