From owner-freebsd-fs@freebsd.org Wed Oct 19 13:12:52 2016 Return-Path: Delivered-To: freebsd-fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0ADC7C17C4A for ; Wed, 19 Oct 2016 13:12:52 +0000 (UTC) (envelope-from ardovm@yahoo.it) Received: from nm3-vm3.bullet.mail.ir2.yahoo.com (nm3-vm3.bullet.mail.ir2.yahoo.com [212.82.96.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 96590819 for ; Wed, 19 Oct 2016 13:12:51 +0000 (UTC) (envelope-from ardovm@yahoo.it) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.it; s=s2048; t=1476882623; bh=HTUDES9BOPQw0P7AEyvzG5W0k44eKRMdmO6GA5K7loM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=E2nY88dwK2oCMT+nUswZUN8rWx/jzScT1dzEGKUM84vZPHvNUtenfJL3G73zQljWmW4Ak/7T4h6VnDPYApHPTDBcpAiLqYcSSRkk2zfcS4jxi8zTWna4gBxSLA33JFz+JoxEh8RNIxY7CM6AYxIHtigeuzCq3ORbJwM6259xP6Vx5awxQovKCmNimi7GQLrr89oe4saIa8fMBkPtXA3mV40GOOm2OJ8JmRw+HIIbXOCqIxMrDhYjhAkWO/fwb52tAsM0zt8nU64lT1iaL9kAeLOdO4nY7GK5/7/I6fFYyyitwbtg9ueIPffAfJa+MBba15rVSMQAvMmKAuAcAVE3eg== Received: from [212.82.98.49] by nm3.bullet.mail.ir2.yahoo.com with NNFMP; 19 Oct 2016 13:10:23 -0000 Received: from [46.228.39.93] by tm2.bullet.mail.ir2.yahoo.com with NNFMP; 19 Oct 2016 13:10:23 -0000 Received: from [127.0.0.1] by smtp130.mail.ir2.yahoo.com with NNFMP; 19 Oct 2016 13:10:23 -0000 X-Yahoo-Newman-Id: 953490.63995.bm@smtp130.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: Y2bN3rQVM1mAqBFGUAEC.FjwGqcaV4sP19AFmt_a22E1rJJ 4VWk8wpDM5lKqbawaoDDglZpPeUBV5Z0mN4DNPiAisuIatUdt2Ki4XUuVBqM 69bhrZo7B9DF32tvg_Qw5xbj7IyB0DWOdLKLmJY_xY4klcAaHClS2KykmgIu NRYlvyFyiNKrCXhcSBxjlShXs6s22Ebn_fzoebgwTTzXii9XD4q0YLNCugYY X2qNz0CqIC66bu7wy44MEUv_gsZJ5OEGgNU8PXKJek.gb_1AC395FBbHmpKP o9_GuCj322mKZqnIhioYSqoB5uw2clSLF.XJGEuEWdQxeu9QzwWYC4ZIjUFV oYLzQm8m5K3Bo5wseclxTLkaVI_qpc2gDynhNG8Ot42JY.4MYCUwYCXViHuy K77jZhJdbYYrgdq3FTLmr5rJ9bpPGx3Gsac7Py57iFgF8mPEohX537BRQr6J Ntn.vvdSJ7YeFn3va5tiSKhLpgtHLWYjW.sDYjgyk5iFw5WJbBuOFD0RF0Hg lHWRtY8ag4IvGUyvKlxb5oopYxExkwuH0f3BOty41Qp_UtdvS X-Yahoo-SMTP: WU.IBxeswBAAnLcBZV3tEZIK0A-- Received: by nuvolo.localdomain (Postfix, from userid 1001) id 6A2501AF109; Wed, 19 Oct 2016 15:10:22 +0200 (CEST) Date: Wed, 19 Oct 2016 15:10:22 +0200 From: Arrigo Marchiori To: Poul-Henning Kamp Cc: Arrigo Marchiori via freebsd-fs Subject: Re: Random truncated files on USB hard disk with timeouts; how to debug? Message-ID: <20161019131022.GE93031@nuvolo> References: <20161018152715.GC89691@nuvolo> <51997.1476812624@critter.freebsd.dk> <20161019062812.GA93031@nuvolo> <7759.1476858801@critter.freebsd.dk> <20161019064315.GB93031@nuvolo> <7924.1476861738@critter.freebsd.dk> <20161019080005.GD93031@nuvolo> <23735.1476876382@critter.freebsd.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <23735.1476876382@critter.freebsd.dk> User-Agent: Mutt/1.7.0 (2016-08-17) X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Oct 2016 13:12:52 -0000 Hello Poul-Henning, On Wed, Oct 19, 2016 at 11:26:22AM +0000, Poul-Henning Kamp wrote: > -------- > In message <20161019080005.GD93031@nuvolo>, Arrigo Marchiori writes: > > >> If the drive has bad power supply, that may not happen. > > > >Yes, I understand. But, forgive me for insisting: there is an > >inconsistency that is _at filesystem level_ and _temporary_, and this > >really puzzles me. > > Because the drive returns wrong data every so often and when > power is better returns correct data ? > > End-to-End arguments in system design applies here: > > Either you trust your drive, or you check everything it tells you > (ie: RAID with parity, ZFS or similar). Ok, but I cannot understand why read() returns plain zero bytes. If ``bad'' data was received from a USB read operation, it should just not make sense to the kernel. Not just show up as an empty file?... Wile fiddling with a funny file, I found that read(2) and mmap(2) behave differently. While cat(1) shows an empty file, cp(1) was able to read its contents. The file was in fact /usr/src/usr.bin/clang/clang/clang.1, the source of the clang(1) manual page. On the other hand, mv(1) does not alter the ``readability'' of the file. # mv clang.1 a # truss cat a [snip] openat(AT_FDCWD,"a",O_RDONLY,00) = 3 (0x3) fstat(1,{ mode=crw--w---- ,inode=146,size=0,blksize=4096 }) = 0 (0x0) __sysctl(0x7fffffffe5e0,0x2,0x7fffffffe5c4,0x7fffffffe5c8,0x0,0x0) = 0 (0x0) __sysctl(0x7fffffffe5e0,0x2,0x7fffffffe5c4,0x7fffffffe5c8,0x0,0x0) = 0 (0x0) mmap(0x0,2097152,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34374418432 (0x800e00000) read(3,0x800e16000,4096) = 0 (0x0) close(3) = 0 (0x0) [snip] # Truss cp a b [snip] stat("b",0x7fffffffe9d8) ERR#2 'No such file or directory' lstat("a",{ mode=-rw-r--r-- ,inode=6510202,size=16993,blksize=32768 }) = 0 (0x0) umask(0x1ff) = 18 (0x12) umask(0x12) = 511 (0x1ff) mmap(0x0,2097152,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34374418432 (0x800e00000) fstatat(AT_FDCWD,"a",{ mode=-rw-r--r-- ,inode=6510202,size=16993,blksize=32768 },0x0) = 0 (0x0) stat("b",0x7fffffffea50) ERR#2 'No such file or directory' openat(AT_FDCWD,"a",O_RDONLY,00) = 3 (0x3) openat(AT_FDCWD,"b",O_WRONLY|O_CREAT|O_TRUNC,0100644) = 4 (0x4) mmap(0x0,16993,PROT_READ,MAP_SHARED,3,0x0) = 34366304256 (0x800643000) write(4,".\\" $FreeBSD: stable/11/usr.bin"...,16993) = 16993 (0x4261) munmap(0x800643000,16993) = 0 (0x0) close(4) = 0 (0x0) close(3) = 0 (0x0) [snip] Please also consider that these commands are repeatable (on the same file): cat always sees the file empty, cp always succeedes. # cp a c # cat a # cat c [data] I think this also tracks down the problem to read operations: the file was successfully installed with yesterday's buildworld. Only today, at this time, it started to behave ``funny''. Best regards, -- rigo http://rigo.altervista.org