Date: Tue, 3 Mar 2020 10:11:28 +0100 From: Willem Jan Withagen <wjw@digiware.nl> To: cem@freebsd.org Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: What is the exact function of the offset parameter in preadv?? Message-ID: <896f3360-f4df-391a-3b08-47fd8de6eabb@digiware.nl> In-Reply-To: <CAG6CVpUAdOArvMWSDk5BOBsW0j3EYKKrxx0N0gYWNaacS87BKg@mail.gmail.com> References: <ecdc6007-e6dc-a30e-97fc-e18634d93430@digiware.nl> <CAG6CVpUAdOArvMWSDk5BOBsW0j3EYKKrxx0N0gYWNaacS87BKg@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <wjw@digiware.nl> 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: <VirtIO Block Adapter> on virtio_pci1 >> vtblk0: 134217727MB (34359738366 4096 byte sectors) >> ahci0: <Intel ICH8 AHCI SATA controller> mem 0xc0004000-0xc00043ff irq >> 18 at device 4.0 on pci0 >> ahci0: AHCI v1.30 with 6 6Gbps ports, Port Multiplier not supported >> atkbdc0: <Keyboard controller (i8042)> port 0x60,0x64 irq 1 on acpi0 >> atkbd0: <AT Keyboard> irq 1 on atkbdc0 >> kbd0 at atkbd0 >> atkbd0: [GIANT-LOCKED] >> driver bug: Unable to set devclass (class: atkbdc devname: (unknown)) >> psm0: <PS/2 Mouse> 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: <Generic ISA VGA> 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: >> <fstype>:<device> [options] >> Mount <device> using filesystem <fstype> >> 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) >> <empty line> Abort manual input >> >> ============= >> >> With booting from a normal file device: >> atkbdc0: <Keyboard controller (i8042)> port 0x60,0x64 irq 1 on acpi0 >> atkbd0: <AT Keyboard> irq 1 on atkbdc0 >> kbd0 at atkbd0 >> atkbd0: [GIANT-LOCKED] >> driver bug: Unable to set devclass (class: atkbdc devname: (unknown)) >> psm0: <PS/2 Mouse> 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: <Generic ISA VGA> 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: <BHYVE SATA DISK 001> 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: <BHYVE SATA DISK 001> 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"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?896f3360-f4df-391a-3b08-47fd8de6eabb>