From owner-freebsd-hackers@freebsd.org Tue Mar 3 09:11:31 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 87268268F81 for ; Tue, 3 Mar 2020 09:11:31 +0000 (UTC) (envelope-from wjw@digiware.nl) Received: from smtp.digiware.nl (smtp.digiware.nl [176.74.240.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 48Wrq72Pm8z4Fb2; Tue, 3 Mar 2020 09:11:31 +0000 (UTC) (envelope-from wjw@digiware.nl) Received: from router.digiware.nl (localhost.digiware.nl [127.0.0.1]) by smtp.digiware.nl (Postfix) with ESMTP id CF9D725B07; Tue, 3 Mar 2020 10:11:28 +0100 (CET) X-Virus-Scanned: amavisd-new at digiware.com Received: from smtp.digiware.nl ([127.0.0.1]) by router.digiware.nl (router.digiware.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hRF70qu_H0zk; Tue, 3 Mar 2020 10:11:28 +0100 (CET) Received: from [192.168.10.9] (vaio [192.168.10.9]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by smtp.digiware.nl (Postfix) with ESMTPSA id 1AEFE25B06; Tue, 3 Mar 2020 10:11:28 +0100 (CET) Subject: Re: What is the exact function of the offset parameter in preadv?? To: cem@freebsd.org Cc: FreeBSD Hackers References: From: Willem Jan Withagen Message-ID: <896f3360-f4df-391a-3b08-47fd8de6eabb@digiware.nl> Date: Tue, 3 Mar 2020 10:11:28 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Firefox/68.0 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: nl X-Rspamd-Queue-Id: 48Wrq72Pm8z4Fb2 X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-5.92 / 15.00]; NEURAL_HAM_MEDIUM(-0.92)[-0.921,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[] 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: Tue, 03 Mar 2020 09:11:31 -0000 On 3-3-2020 01:35, Conrad Meyer wrote: > Hi Willem, > > The offset parameter to the p{read,write}{,v} family of functions > indeed indicates a file offset. For ordinary files, negative offsets > are invalid (EINVAL). > > Bhyve is probably accessing a special kernel device file, kmem(4), and > those negative "offsets" instead represent addresses in kernel virtual > memory. Conrad, Right, I have annotated the code that does block_local writes, and I'm in the process of adding block_rbd to it. And it is from those that I get these values. So they are actual accesses to regular files. But I think I got caught in 32->64 sign extention while printing the values. And we are actually accessing things like `size(file) - 1024` . I'll see if I can get a bit of extra doc in the manpage. Thanx, --WjW > Best, > Conrad > > On Sun, Mar 1, 2020 at 4:47 PM Willem Jan Withagen wrote: >> Hi, >> >> Tried looking in the manual page, but it does not really describes what >> off_t offset does with a preadv... >> >> I suspect that is the offset in the file to start reading from? >> >> Next question is: What if the value is negative? >> Are we then reading from the end of the file/device if it is >> seekable? >> >> Manual page says: >> The pread() and preadv() system calls may also return the following >> errors: >> [EINVAL] The offset value was negative. >> >> But then I have this behyve code that gets calls like: >> block_proc_read: buf=0x0, cnt=1, len=512, off=-1024(0xfffffc00). >> block_proc_read: buf=0x0, cnt=1, len=512, off=-512(0xfffffe00). >> block_proc_read: buf=0x0, cnt=1, len=512, off=-1024(0xfffffc00). >> block_proc_read: buf=0x0, cnt=1, len=512, off=-512(0xfffffe00). >> block_proc_read: buf=0x0, cnt=1, len=512, off=-512(0xfffffe00). >> block_proc_read: buf=0x0, cnt=1, len=2048, off=-32256(0xffff8200). >> block_proc_read: buf=0x0, cnt=1, len=512, off=512(0x200). >> block_proc_read: buf=0x0, cnt=1, len=512, off=0(0x0). >> block_proc_read: buf=0x0, cnt=1, len=512, off=512(0x200). >> block_proc_read: buf=0x0, cnt=1, len=512, off=0(0x0). >> block_proc_read: buf=0x0, cnt=1, len=512, off=512(0x200). >> block_proc_read: buf=0x0, cnt=1, len=16384, off=1024(0x400). >> block_proc_read: buf=0x0, cnt=1, len=512, off=-512(0xfffffe00). >> block_proc_read: buf=0x0, cnt=1, len=16384, off=-16896(0xffffbe00). >> block_proc_read: buf=0x0, cnt=1, len=512, off=-512(0xfffffe00). >> >> Where these are the very first calls that a bhyve loaded image executes. >> which I guess is for probing the bootdisk to see where/what it needs to >> mount a root disk. >> >> Below bhyve boot output of a not working boot, and a working boot. >> The read trace above is from the working bhyve boot. >> >> So what are the negative offsets? >> >> --WjW >> >> >> Compare >> Using block_rbd_read for reading from a Rados device >> >> ============= >> vtblk0: on virtio_pci1 >> vtblk0: 134217727MB (34359738366 4096 byte sectors) >> ahci0: mem 0xc0004000-0xc00043ff irq >> 18 at device 4.0 on pci0 >> ahci0: AHCI v1.30 with 6 6Gbps ports, Port Multiplier not supported >> atkbdc0: port 0x60,0x64 irq 1 on acpi0 >> atkbd0: irq 1 on atkbdc0 >> kbd0 at atkbd0 >> atkbd0: [GIANT-LOCKED] >> driver bug: Unable to set devclass (class: atkbdc devname: (unknown)) >> psm0: irq 12 on atkbdc0 >> psm0: [GIANT-LOCKED] >> psm0: model Generic PS/2 mouse, device ID 0 >> uart0: <16550 or compatible> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0 >> uart0: console (9600,n,8,1) >> uart1: <16550 or compatible> port 0x2f8-0x2ff irq 3 on acpi0 >> vga0: at port 0x3b0-0x3bb iomem 0xb0000-0xb7fff pnpid >> PNP0900 on isa0 >> Timecounters tick every 10.000 msec >> usb_needs_explore_all: no devclass >> Trying to mount root from ufs:/dev/ada0p2 [rw]... >> mountroot: waiting for device /dev/ada0p2... >> Mounting from ufs:/dev/ada0p2 failed with error 19. >> >> Loader variables: >> vfs.root.mountfrom=ufs:/dev/ada0p2 >> vfs.root.mountfrom.options=rw >> >> Manual root filesystem specification: >> : [options] >> Mount using filesystem >> and with the specified (optional) option list. >> >> eg. ufs:/dev/da0s1a >> zfs:zroot/ROOT/default >> cd9660:/dev/cd0 ro >> (which is equivalent to: mount -t cd9660 -o ro /dev/cd0 /) >> >> ? List valid disk boot devices >> . Yield 1 second (for background tasks) >> Abort manual input >> >> ============= >> >> With booting from a normal file device: >> atkbdc0: port 0x60,0x64 irq 1 on acpi0 >> atkbd0: irq 1 on atkbdc0 >> kbd0 at atkbd0 >> atkbd0: [GIANT-LOCKED] >> driver bug: Unable to set devclass (class: atkbdc devname: (unknown)) >> psm0: irq 12 on atkbdc0 >> psm0: [GIANT-LOCKED] >> psm0: model Generic PS/2 mouse, device ID 0 >> uart0: <16550 or compatible> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0 >> uart0: console (9600,n,8,1) >> uart1: <16550 or compatible> port 0x2f8-0x2ff irq 3 on acpi0 >> vga0: at port 0x3b0-0x3bb iomem 0xb0000-0xb7fff pnpid >> PNP0900 on isa0 >> Timecounters tick every 10.000 msec >> usb_needs_explore_all: no devclass >> Trying to mount root from ufs:/dev/ada0p2 [rw]... >> Root mount waiting for: CAM >> ada0 at ahcich0 bus 0 scbus0 target 0 lun 0 >> ada0: ACS-2 ATA SATA 3.x device >> ada0: Serial Number BHYVE-8C7D-D922-AD47 >> ada0: 600.000MB/s transfers (SATA 3.x, UDMA6, PIO 8192bytes) >> ada0: Command Queueing enabled >> ada0: 20480MB (41943040 512 byte sectors) >> ada1 at ahcich6 bus 0 scbus1 target 0 lun 0 >> ada1: ACS-2 ATA SATA 3.x device >> ada1: Serial Number BHYVE-4318-7904-5D51 >> ada1: 600.000MB/s transfers (SATA 3.x, UDMA6, PIO 8192bytes) >> ada1: Command Queueing enabled >> ada1: 20480MB (41943040 512 byte sectors) >> mountroot: waiting for device /dev/ada0p2... >> WARNING: / was not properly dismounted >> WARNING: /: mount pending error: blocks 168 files 1 >> ========== >> >> >> >> _______________________________________________ >> freebsd-hackers@freebsd.org mailing list >> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers >> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"