For UNIX sockets make vnode point not to the socket, but to the UNIX PCB,

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

While here, make the union in the struct vnode anonymous.
This commit is contained in:
Gleb Smirnoff 2017-06-02 17:31:25 +00:00
parent 67e984c8f2
commit 0c3c207ffd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=319502
5 changed files with 20 additions and 29 deletions

View File

@ -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;
@ -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;
@ -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;
@ -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;
@ -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);

View File

@ -1128,7 +1128,7 @@ 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);
}
@ -1136,7 +1136,7 @@ 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);
}
@ -1144,7 +1144,7 @@ int
vop_stdunp_detach(struct vop_unp_detach_args *ap)
{
ap->a_vp->v_socket = NULL;
ap->a_vp->v_unpcb = NULL;
return (0);
}

View File

@ -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;

View File

@ -662,7 +662,7 @@ vop_advise {
vop_unp_bind {
IN struct vnode *vp;
IN struct socket *socket;
IN struct unpcb *unpcb;
};
@ -670,7 +670,7 @@ vop_unp_bind {
vop_unp_connect {
IN struct vnode *vp;
OUT struct socket **socket;
OUT struct unpcb **unpcb;
};

View File

@ -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
@ -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 */
@ -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 {