Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Mar 2020 01:46:25 +0100
From:      Willem Jan Withagen <wjw@digiware.nl>
To:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   What is the exact function of the offset parameter in preadv??
Message-ID:  <ecdc6007-e6dc-a30e-97fc-e18634d93430@digiware.nl>

next in thread | raw e-mail | index | archive | help
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
==========






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ecdc6007-e6dc-a30e-97fc-e18634d93430>