Skip to content

Commit

Permalink
For UNIX sockets make vnode point not to the socket, but to the UNIX …
Browse files Browse the repository at this point in the history
…PCB,

since the latter is the thing that links together VFS and sockets.

While here, make the union in the struct vnode anonymous.
  • Loading branch information
glebius committed Jun 2, 2017
1 parent ab63ba1 commit 8a7f8bb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
16 changes: 5 additions & 11 deletions sys/kern/uipc_usrreq.c
Expand Up @@ -552,7 +552,7 @@ uipc_bindat(int fd, struct socket *so, struct sockaddr *nam, struct thread *td)

UNP_LINK_WLOCK();
UNP_PCB_LOCK(unp);
VOP_UNP_BIND(vp, unp->unp_socket);
VOP_UNP_BIND(vp, unp);
unp->unp_vnode = vp;
unp->unp_addr = soun;
unp->unp_flags &= ~UNP_BINDING;
Expand Down Expand Up @@ -670,9 +670,6 @@ uipc_detach(struct socket *so)
UNP_LINK_WLOCK();
UNP_PCB_LOCK(unp);

/*
* XXXRW: Should assert vp->v_socket == so.
*/
if ((vp = unp->unp_vnode) != NULL) {
VOP_UNP_DETACH(vp);
unp->unp_vnode = NULL;
Expand Down Expand Up @@ -1386,11 +1383,12 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam,
* and to protect simultaneous locking of multiple pcbs.
*/
UNP_LINK_WLOCK();
VOP_UNP_CONNECT(vp, &so2);
if (so2 == NULL) {
VOP_UNP_CONNECT(vp, &unp2);
if (unp2 == NULL) {
error = ECONNREFUSED;
goto bad2;
}
so2 = unp2->unp_socket;
if (so->so_type != so2->so_type) {
error = EPROTOTYPE;
goto bad2;
Expand Down Expand Up @@ -2454,7 +2452,6 @@ unp_scan(struct mbuf *m0, void (*op)(struct filedescent **, int))
void
vfs_unp_reclaim(struct vnode *vp)
{
struct socket *so;
struct unpcb *unp;
int active;

Expand All @@ -2464,10 +2461,7 @@ vfs_unp_reclaim(struct vnode *vp)

active = 0;
UNP_LINK_WLOCK();
VOP_UNP_CONNECT(vp, &so);
if (so == NULL)
goto done;
unp = sotounpcb(so);
VOP_UNP_CONNECT(vp, &unp);
if (unp == NULL)
goto done;
UNP_PCB_LOCK(unp);
Expand Down
6 changes: 3 additions & 3 deletions sys/kern/vfs_default.c
Expand Up @@ -1128,23 +1128,23 @@ int
vop_stdunp_bind(struct vop_unp_bind_args *ap)
{

ap->a_vp->v_socket = ap->a_socket;
ap->a_vp->v_unpcb = ap->a_unpcb;
return (0);
}

int
vop_stdunp_connect(struct vop_unp_connect_args *ap)
{

*ap->a_socket = ap->a_vp->v_socket;
*ap->a_unpcb = ap->a_vp->v_unpcb;
return (0);
}

int
vop_stdunp_detach(struct vop_unp_detach_args *ap)
{

ap->a_vp->v_socket = NULL;
ap->a_vp->v_unpcb = NULL;
return (0);
}

Expand Down
5 changes: 4 additions & 1 deletion sys/kern/vfs_subr.c
Expand Up @@ -2994,7 +2994,10 @@ _vdrop(struct vnode *vp, bool locked)
/* XXX Elsewhere we detect an already freed vnode via NULL v_op. */
vp->v_op = NULL;
#endif
bzero(&vp->v_un, sizeof(vp->v_un));
vp->v_mountedhere = NULL;
vp->v_unpcb = NULL;
vp->v_rdev = NULL;
vp->v_fifoinfo = NULL;
vp->v_lasta = vp->v_clen = vp->v_cstart = vp->v_lastw = 0;
vp->v_iflag = 0;
vp->v_vflag = 0;
Expand Down
4 changes: 2 additions & 2 deletions sys/kern/vnode_if.src
Expand Up @@ -662,15 +662,15 @@ vop_advise {

vop_unp_bind {
IN struct vnode *vp;
IN struct socket *socket;
IN struct unpcb *unpcb;
};


%% unp_connect vp L L L

vop_unp_connect {
IN struct vnode *vp;
OUT struct socket **socket;
OUT struct unpcb **unpcb;
};


Expand Down
18 changes: 6 additions & 12 deletions sys/sys/vnode.h
Expand Up @@ -112,14 +112,13 @@ struct vnode {

/*
* Type specific fields, only one applies to any given vnode.
* See #defines below for renaming to v_* namespace.
*/
union {
struct mount *vu_mount; /* v ptr to mountpoint (VDIR) */
struct socket *vu_socket; /* v unix domain net (VSOCK) */
struct cdev *vu_cdev; /* v device (VCHR, VBLK) */
struct fifoinfo *vu_fifoinfo; /* v fifo (VFIFO) */
} v_un;
struct mount *v_mountedhere; /* v ptr to mountpoint (VDIR) */
struct unpcb *v_unpcb; /* v unix domain net (VSOCK) */
struct cdev *v_rdev; /* v device (VCHR, VBLK) */
struct fifoinfo *v_fifoinfo; /* v fifo (VFIFO) */
};

/*
* vfs_hash: (mount + inode) -> vnode hash. The hash value
Expand Down Expand Up @@ -175,11 +174,6 @@ struct vnode {

#endif /* defined(_KERNEL) || defined(_KVM_VNODE) */

#define v_mountedhere v_un.vu_mount
#define v_socket v_un.vu_socket
#define v_rdev v_un.vu_cdev
#define v_fifoinfo v_un.vu_fifoinfo

#define bo2vnode(bo) __containerof((bo), struct vnode, v_bufobj)

/* XXX: These are temporary to avoid a source sweep at this time */
Expand All @@ -200,7 +194,7 @@ struct xvnode {
long xv_numoutput; /* num of writes in progress */
enum vtype xv_type; /* vnode type */
union {
void *xvu_socket; /* socket, if VSOCK */
void *xvu_socket; /* unpcb, if VSOCK */
void *xvu_fifo; /* fifo, if VFIFO */
dev_t xvu_rdev; /* maj/min, if VBLK/VCHR */
struct {
Expand Down

0 comments on commit 8a7f8bb

Please sign in to comment.