From mboxrd@z Thu Jan 1 00:00:00 1970 From: "H. Peter Anvin" Subject: Re: compat: autofs v5 packet size ambiguity - update Date: Wed, 22 Feb 2012 09:43:24 -0800 Message-ID: <4F45293C.8050209@zytor.com> References: <20120221.221609.218135609185671883.davem@davemloft.net> <1329889428.2193.45.camel@perseus.themaw.net> <4F4484F0.9070501@zytor.com> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii" To: Linus Torvalds Cc: Ian Kent , David Miller , linux-kernel@vger.kernel.org, autofs@vger.kernel.org, Thomas Meyer , Al Viro On 02/22/2012 08:10 AM, Linus Torvalds wrote: > > Well, the kernel gives the right semantics for pipes too - writes are > guaranteed to be "atomic", so even in the presence of multiple writers > you can trivially do packetized data. > > You just have to (a) add the length to the packet and (b) do the > length+packet write as a single write (which is limited to PIPE_SIZE - > 4kB - for the atomicity guarantee). > > If you don't have multiple concurrent writers without locking, the (b) > part falls away entirely, of course. > > Yes, for the reader side you need to be able to handle the fact that > you can get more than one packet in one read() call, but sorting that > out isn't hard either. > What you describe above is pretty much how autofs 3 used to work; except it would do one read() for the header including length and then another read() for the body. Of course, it could just have read ahead -- if you read part of the next packet, it wouldn't really matter since at least at that time the daemon was single-threaded and would have to loop back anyway. The PIPE_SIZE guarantee took care of the fact that this was a multiple writer/single reader situation (since the writes happens in the context of the process requesting a mount.) Either way, SOCK_DGRAM and SOCK_SEQPACKET would solve all of the problems and would Just Work, and packet boundaries would then be explicit. > But yeah, writing fixed-size data and then having a reader that reads > fixed-size data is just not a very good approach. It's doubly bad when > the "fixed size" isn't an explicit size that is documented in the > protocol, but depends on data structures. Indeed. -hpa -- H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.