Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Notes on blktap2 and tapdisk 

 

# Some notes on how how tapdevs and associated devices are created. It begins here:
 
libxl:libxl__blktap_devpath calls libblktapctl.so:tap_ctl_create directly.
xenops/device.ml:mount calls it indirectly by invoking tap-ctl with the create option (which calls tap-ctl:tap_cli_create)
  
# This function in libblktapctl.so does 4 important things that are listed below
tap_cli_create:
  tap_ctl_allocate
  tap_ctl_spawn
  tap_ctl_attach
  tap_ctl_open
  
tap_ctl_allocate:
  # Open the blktap driver
  # Allocate a ring device and an IO device using the BLKTAP2_IOCTL_ALLOC_TAP ioctl (see below).
  # tap_ctl_make_device then makes the ring device node /dev/xen/blktap-2/blktapX and an IO device node /devxen/blktap-2/tapdevX
  
tap_ctl_spawn:
  # Start a new tapdisk2 process that will be associated with the X tap devices.
  # tapdisk2 creates the listener socket for the new process.
  # tapdisk2 registers the tapdisk_control_handle_request
  
tap_ctl_attach:
  # Attach to the listening tapdisk2 process just started so now messages can be passed between libblktapctl.so and that process.
  
tap_ctl_open:
  # Send the TAPDISK_MESSAGE_OPEN to the new tapdisk2 process.
  
# In the new tapdisk2 process associated with the X devices allocated above.
tapdisk_control_handle_request:
  # Get message TAPDISK_MESSAGE_OPEN and call:
  tapdisk_control_open_image:
    # Send the BLKTAP2_IOCTL_CREATE_DEVICE ioctl to blkdev (see below).
# Down in the blktap driver, the above activity translates to:
blktap_control_ioctl:
  # BLKTAP2_IOCTL_ALLOC_TAP maps to BLKTAP_IOCTL_ALLOC_TAP
  # Call blktap_control_create_tap to create the tap ring and IO devices.
  
blktap_ring_ioctl:
  # BLKTAP2_IOCTL_CREATE_DEVICE maps to BLKTAP_IOCTL_CREATE_DEVICE_COMPAT. Calls:
  blktap_device_create:
    # Sets up the /dev/tdx node name (note little x corresponds to a, b, c...)
    # Creates and adds the actual block device with add_disk() (see include/linux/genhd.h for generic block disk devices).
    # The rest happens in the standard udev way.
  
 
NOTE: when destroying a tapdev with tap-ctl the process id is the tapdisk2 process that own the tap devs. The minor number is what is called X above.