From owner-freebsd-hackers@freebsd.org Sat Apr 20 19:28:25 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4C8D01573C9D for ; Sat, 20 Apr 2019 19:28:25 +0000 (UTC) (envelope-from freebsd-rwg@gndrsh.dnsmgr.net) Received: from gndrsh.dnsmgr.net (br1.CN84in.dnsmgr.net [69.59.192.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4EC146EF9F; Sat, 20 Apr 2019 19:28:24 +0000 (UTC) (envelope-from freebsd-rwg@gndrsh.dnsmgr.net) Received: from gndrsh.dnsmgr.net (localhost [127.0.0.1]) by gndrsh.dnsmgr.net (8.13.3/8.13.3) with ESMTP id x3KJSM8w023992; Sat, 20 Apr 2019 12:28:22 -0700 (PDT) (envelope-from freebsd-rwg@gndrsh.dnsmgr.net) Received: (from freebsd-rwg@localhost) by gndrsh.dnsmgr.net (8.13.3/8.13.3/Submit) id x3KJSMKW023991; Sat, 20 Apr 2019 12:28:22 -0700 (PDT) (envelope-from freebsd-rwg) From: "Rodney W. Grimes" Message-Id: <201904201928.x3KJSMKW023991@gndrsh.dnsmgr.net> Subject: Re: bhyve VM stopped to boot after moving virtio disks In-Reply-To: To: Mark Millard Date: Sat, 20 Apr 2019 12:28:22 -0700 (PDT) CC: Igor Mozolevsky , Hackers freeBSD , Ian Lepore X-Mailer: ELM [version 2.4ME+ PL121h (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 4EC146EF9F X-Spamd-Bar: ++ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [2.85 / 15.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; NEURAL_SPAM_SHORT(0.83)[0.827,0]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; DMARC_NA(0.00)[dnsmgr.net]; AUTH_NA(1.00)[]; NEURAL_SPAM_MEDIUM(0.60)[0.605,0]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.01)[cached: gndrsh.dnsmgr.net]; NEURAL_SPAM_LONG(0.50)[0.498,0]; R_SPF_NA(0.00)[]; FREEMAIL_TO(0.00)[yahoo.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:13868, ipnet:69.59.192.0/19, country:US]; MID_RHS_MATCH_FROM(0.00)[]; IP_SCORE(0.03)[ip: (0.11), ipnet: 69.59.192.0/19(0.06), asn: 13868(0.04), country: US(-0.06)] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Apr 2019 19:28:25 -0000 > > > On 2019-Apr-20, at 10:45, Igor Mozolevsky wrote: > > > On Sat, 20 Apr 2019 at 18:00, Ian Lepore wrote: > > > > > >> dd absolutely will fail to copy the last block of the source if it > >> isn't exactly the blocksize and you didn't specify conv=sync, and it > >> will return a zero status when doing so. It appears you've convinced > >> yourself otherwise, but for anyone else reading this thread, be aware: > >> conv=sync is required to copy the last part of the source if it's > >> smaller than the blocksize. > > > > > > Isn't that contrary to the POSIX Spec? Reading the manual [1], it is > > implied (from STDERR part of the main section) that dd will read and > > write partial blocks, cf. truncated blocks?.. > > > > 1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/dd.html > > Have you tried as Ian suggests to see if it made a difference? > Ian seems to be speaking FreeBSD, not necessarily POSIX. (I'm > talking actual FreeBSD behavior here, not necessarily documented > behavior.) > > It turns out that https://www.freebsd.org/cgi/man.cgi?dd(1) does say: > > Normally, data resulting from input or conversion or both are aggregated > into output blocks of the specified size. After the end of input is > reached, any remaining output is written as a block. This means that the > final output block may be shorter than the output block size. > > where conv=sync is described as: > > sync > Pad every input block to the input buffer size. Spaces > are used for pad bytes if a block oriented conversion > value is specified, otherwise NUL bytes are used. > > (So sync changes the overall input size when it adds pad bytes, at > least as documented.) > > It appears to me that Ian's expectations of the actual behavior and > the FreeBSD documentation of such are not a match. Absent testing, > I'd bet on Ian, even if it means FreeBSD dd has a bug. So I tested: root@x230a:/tmp/ddtest # dd if=short of=long bs=1m 0+1 records in 0+1 records out 1024 bytes transferred in 0.000101 secs (10171444 bytes/sec) root@x230a:/tmp/ddtest # ls -lag total 62 drwxr-xr-x 2 root wheel 4 Apr 20 19:16 . drwxrwxrwt 44 root wheel 283 Apr 20 19:16 .. -rw-r--r-- 1 root wheel 1024 Apr 20 19:16 long -rw-r--r-- 1 root wheel 1024 Apr 20 19:16 short And on files it is as expected, however the issue Ian describes does infact occur when dealing with block devices that can not do the "truncated" size block operation, which is extremly rare as the block devices are typically either 512, 2048 or 4096 and almost everyone using dd uses block sizes that are large multiples of this so you never end up hitting that edge of trying to write a 1k record to a 4k device. The truncated input record size is garanteed to be a mutliple of the device block size, the one case I can think of that would hit this is dd'ing a 512B disk to a 4096 native disk that happened to NOT be of a size that is a multiple of 4096, something probably VERY rare. In the case of going from a device to a file the chances of lost data are nill (and I have been doing that for 30 years and never hit it.) You DO have to be carefull if your doing forinsics, conv=sync infact can corrupt your forinsics copy in that it is the wrong size and then when someone else does the analysis they get a different results do to this size change. Part of this process usually involves verifying that the size of your image exactly matches the reported size of the device. -- Rod Grimes rgrimes@freebsd.org