README 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. qfilexchgd is a daemon responsible for managing exchange of block
  2. devices ("virtual pendrives") between VMs. It is used for
  3. a) copying files between AppVMs
  4. b) copying a single file between an AppVM and a DVM
  5. qfilexchgd is event driven. The sources of events are:
  6. a) trigger of xenstore watch for the changes in /local/domain xenstore hierarchy -
  7. to detect start/stop of VMs, and maintain vmname->vm_xid dictionary
  8. b) triger of xenstore watch for a change in /local/domain/domid/device/qpen
  9. key - VMs write to this key to request service from qfilexchgd
  10. Copying files between AppVMs is implemented as follows:
  11. 1) AppVM1 user runs qvm-copy-to-vm script (accessible from Dolphin file manager by
  12. "right click on a file(s)->Actions->Send to VM" menu). It calls
  13. "/usr/lib/qubes/qubes_penctl new", and it writes "new" request to its device/qpen
  14. key. qfilexchgd creates a new 1G file, makes vfat fs on it, and does block-attach
  15. so that this file is attached as /dev/xvdg in AppVM1.
  16. 2) AppVM1 mounts /dev/xvdg on /mnt/outgoing and copies some files there,
  17. then unmounts it.
  18. 3) AppVM1 writes "send DestVM" request to its device/qpen key (calling
  19. "/usr/lib/qubes/qubes_penctl send DestVM"). After getting confirmation by
  20. displaying a dialog box in dom0 display, qfilexchgd detaches /dev/xvdg
  21. from AppVM1, attaches it as /dev/xvdh to DestVM.
  22. 4) In DestVM, udev script for /dev/xvdh named qubes_add_pendrive_script (see
  23. /etc/udev/rules.d/qubes.rules) mounts /dev/xvdh on /mnt/incoming, and then
  24. waits for /mnt/incoming to become unmounted. A file manager
  25. running in DestVM shows a new volume, and user in DestVM may copy files from
  26. it. When user in DestVM is done, then user unmounts /dev/xvdh.
  27. qubes_add_pendrive_script then tells qfilexchgd to detach /dev/xvdh and
  28. terminates.
  29. Copying a single file between AppVM and a DVM is implemented as
  30. follows:
  31. 1) User in AppVM1 runs qvm-open-in-dvm (accessible from Dolphin file manager
  32. by "right click on a file->Actions->Open in DVM" menu). qvm-open-in-dvm
  33. a) gets a new /dev/xvdg (just as described in previous paragraph)
  34. b) computes a new unique transaction seq SEQ,
  35. c) writes the requested file name (say, /home/user/document.txt) to
  36. /home/user/.dvm/SEQ.
  37. d) creates a dvm_header (see core.git/appvm/dvm.h) on /dev/xvdg, followed by
  38. file contents
  39. e) writes the "send disposable SEQ" to its device/qpen xenstore key.
  40. 2) qfilexchgd sees that "send" argument=="disposable", and creates the new
  41. DVM by calling /usr/lib/qubes/qubes_restore. It adds new DVM to qubesDB via
  42. qvm_collection.add_new_appvm. Then it attaches /dev/xvdg from AppVM1 as
  43. /dev/xvdh in DVM.
  44. 3) In DVM, qubes_add_pendrive_script sees non-zero "qubes_transaction_seq"
  45. key in xenstore, and instead processing it as in the case of normal copy,
  46. treats it as a request to DVM (because we run in DVM). It retrieves the
  47. body of the file passed in
  48. /dev/xvdh, copies to /tmp, and runs "mime-open" to open appropriate
  49. executable to edit it. When mime-open returns, if the file was modified,
  50. it is sent back to AppVM1 (by writing "send AppVM1 SEQ" to device/qpen).
  51. Then DVM destroys itself.
  52. 4) In AppVM1, a new /dev/xvdh appears (because DVM sent it).
  53. qubes_add_pendrive_script sees non-zero "qubes_transaction_seq" key, and
  54. treats it as response from DVM (because we run in AppVM, not DVM). It
  55. retrieves the filename from
  56. /home/user/.dvm/SEQ, and copies data from /dev/xvdh to it.
  57. qfilexchgd is started after first qubes_guid is started, so that it
  58. has access to X display in dom0 to present dialog messages.