From owner-svn-src-all@FreeBSD.ORG Mon Nov 3 00:53:37 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 10ED0513; Mon, 3 Nov 2014 00:53:37 +0000 (UTC) Received: from mail105.syd.optusnet.com.au (mail105.syd.optusnet.com.au [211.29.132.249]) by mx1.freebsd.org (Postfix) with ESMTP id BF679C6E; Mon, 3 Nov 2014 00:53:35 +0000 (UTC) Received: from c122-106-147-133.carlnfd1.nsw.optusnet.com.au (c122-106-147-133.carlnfd1.nsw.optusnet.com.au [122.106.147.133]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id 1D2DB1046A42; Mon, 3 Nov 2014 11:53:27 +1100 (AEDT) Date: Mon, 3 Nov 2014 11:53:26 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Ian Lepore Subject: Re: svn commit: r273958 - head/sys/dev/random In-Reply-To: <1414961583.1200.27.camel@revolution.hippie.lan> Message-ID: <20141103113629.I3149@besplex.bde.org> References: <201411020201.sA221unt091493@svn.freebsd.org> <720EB74E-094A-43F3-8B1C-47BC7F6FECC3@grondar.org> <1414934579.17308.248.camel@revolution.hippie.lan> <6FB65828-6A79-4BDE-A9F7-BC472BA538CE@grondar.org> <20141102192057.GB53947@kib.kiev.ua> <29A795E1-19E2-49E4-9653-143D3F6F3F12@grondar.org> <20141102194625.GC53947@kib.kiev.ua> <751CD860-95B9-4F68-AE69-976B42823AD0@grondar.org> <54568E41.8030305@delphij.net> <20141102201331.GE53947@kib.kiev.ua> <545693B4.8030602@delphij.net> <1414961583.1200.27.camel@revolution.hippie.lan> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=fvDlOjIf c=1 sm=1 tr=0 a=7NqvjVvQucbO2RlWB8PEog==:117 a=PO7r1zJSAAAA:8 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=dqrdoiUPIJBHaAnRjlAA:9 a=CjuIK1q_8ugA:10 Cc: "src-committers@freebsd.org" , d@delphij.net, "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" , Mark R V Murray , Konstantin Belousov X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Nov 2014 00:53:37 -0000 On Sun, 2 Nov 2014, Ian Lepore wrote: > On Sun, 2014-11-02 at 12:27 -0800, Xin Li wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA512 >> >> Hi, Mark, >> >> I'd like to propose the attached patch for review. It replaces >> tsleep's with sx_sleep's, then checks the return value and quit the loop. > > It still doesn't handle the partial read/write case Kostik mentioned, > but there are plenty of other drivers that don't get that right. Returning an error for a partial read is good enough for random devices, since there is no problem with discarding the input. Upper layers are still broken, so this (discarding the input is what happens automatically except for ERESTART, EINTR and EWOULDBLOCK. > Given > that the ra_read/ra_write functions can't return error, it would only be > errors from uiomove() in play. I guess it would be something like this: > > nbytes = uio->uio_resid; > while (uio->uio_resid && !error) { > c = MIN(uio->uio_resid, PAGE_SIZE); > (random_adaptor->ra_read)(random_buf, c); > error = uiomove(random_buf, c, uio); > } > if (uio->uio_resid != nbytes) > error = 0; /* Return partial read, not error. */ This is unnecessary except for upper layer bugs. Upper layers already convert error to 0 under the condition (uio->uio_resid != original_resid), except they only do this if 'error' was EINTR, ERESTART and EWOULDBLOCK -- other cases are broken. Thus all drivers have the burden of doing the conversion if they want to be correct. Some file systems generally back out of failing writes so that returning an error is correct. Bruce