Date: Wed, 26 Feb 2014 23:52:48 +0000 From: "Son, Sonny" <Sonny.Son@netapp.com> To: John-Mark Gurney <jmg@funkthat.com> Cc: "freebsd-net \(freebsd-net@freebsd.org\)" <freebsd-net@freebsd.org> Subject: RE: socket lock Message-ID: <3967D1AB1B4E6F4CA4E2329EEB83ED3E30D8C43F@SACEXCMBX03-PRD.hq.netapp.com> In-Reply-To: <20140226225336.GG92037@funkthat.com> References: <3967D1AB1B4E6F4CA4E2329EEB83ED3E30D8C3A7@SACEXCMBX03-PRD.hq.netapp.com> <20140226225336.GG92037@funkthat.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Thanks John-Mark. That explains. I will do more research and bug you guys a= gain if I need help. Regards... -----Original Message----- From: John-Mark Gurney [mailto:jmg@funkthat.com]=20 Sent: Wednesday, February 26, 2014 2:54 PM To: Son, Sonny Cc: freebsd-net (freebsd-net@freebsd.org) Subject: Re: socket lock Son, Sonny wrote this message on Wed, Feb 26, 2014 at 22:47 +0000: > Can somebody explain me how socket data structure-i.e. 'struct socket'-is= protected in FreeBSD? It seems that socket is accessed and modified withou= t lock in some places. As an instance, the following code reads and/or modi= fies various socket fields including so_error without socket lock held: Have you seen this in sys/socketvar.h? /*- * Locking key to struct socket: * (a) constant after allocation, no locking required. * (b) locked by SOCK_LOCK(so). * (c) locked by SOCKBUF_LOCK(&so->so_rcv). * (d) locked by SOCKBUF_LOCK(&so->so_snd). * (e) locked by ACCEPT_LOCK(). * (f) not locked since integer reads/writes are atomic. * (g) used only as a sleep/wakeup address, no value. * (h) locked by global mutex so_global_mtx. */ > int > sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, > struct mbuf *top, struct mbuf *control, int flags, struct thread=20 > *td) { [...] > if (so->so_error) { > error =3D so->so_error; > so->so_error =3D 0; <=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D we do have socket's send buffer lock but not socket lock (, which is so= cket recv buffer lock) > SOCKBUF_UNLOCK(&so->so_snd); > goto out; > } So, so_error is: u_short so_error; /* (f) error affecting connection *= / and f is: * (f) not locked since integer reads/writes are atomic. Though, I'm not so sure u_short counts as an integer.. it maybe should be s= omething like u_register_t, but not sure about this... --=20 John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3967D1AB1B4E6F4CA4E2329EEB83ED3E30D8C43F>