| 1 |
Block scripts |
| 2 |
============= |
| 3 |
|
| 4 |
Block scripts are called at the moment anytime blkback is directly |
| 5 |
involved in providing access to a backend. There are three general |
| 6 |
cases this happens: |
| 7 |
|
| 8 |
1. When a user passes a block device in the 'target' field of the disk |
| 9 |
specification |
| 10 |
|
| 11 |
2. When a user passes a file in the 'target' field of the disk |
| 12 |
specification |
| 13 |
|
| 14 |
3. When a user specifies a custom hotplug script. |
| 15 |
|
| 16 |
Setup |
| 17 |
----- |
| 18 |
|
| 19 |
It is highly recommended that custom hotplug scripts as much as |
| 20 |
possible include and use the common Xen functionality. If the script |
| 21 |
is run from the normal block script location (/etc/xen/scripts by |
| 22 |
default), then this can be done by adding the following to the top of |
| 23 |
the script: |
| 24 |
|
| 25 |
dir=$(dirname "$0") |
| 26 |
. "$dir/block-common.sh" |
| 27 |
|
| 28 |
|
| 29 |
Inputs |
| 30 |
------ |
| 31 |
|
| 32 |
Unfortunately the inputs to the block scripts look completely |
| 33 |
different for each operating system. |
| 34 |
|
| 35 |
Inputs (Linux) |
| 36 |
-------------- |
| 37 |
|
| 38 |
In all cases, the scripts are called with either "add" or "remove" as |
| 39 |
the command. For custom scripts, the command will be the first |
| 40 |
argument of the script (i.e. $1). |
| 41 |
|
| 42 |
The environment variable XENBUS_PATH will be set to the |
| 43 |
path for the block device to be created. |
| 44 |
|
| 45 |
When the script is run, the following nodes shall already have been |
| 46 |
written into xenstore: |
| 47 |
|
| 48 |
$XENBUS/params The contents of the 'target' section of the disk specification verbatim. |
| 49 |
$XENBUS/mode 'r' (for readonly) or 'w' (for read-write) |
| 50 |
|
| 51 |
Inputs (FreeBSD) |
| 52 |
-------------- |
| 53 |
|
| 54 |
The scripts are always called with the same set of arguments. The first |
| 55 |
parameter is the xenstore backend path of the device, while the second |
| 56 |
argument is the action, which is always either "add" or "remove". |
| 57 |
|
| 58 |
When the script is run, the following nodes shall already have been |
| 59 |
written into xenstore: |
| 60 |
|
| 61 |
$XENBUS/params The contents of the 'target' section of the disk specification verbatim. |
| 62 |
$XENBUS/mode 'r' (for readonly) or 'w' (for read-write) |
| 63 |
|
| 64 |
Inputs (NetBSD) |
| 65 |
--------------- |
| 66 |
|
| 67 |
TODO |
| 68 |
|
| 69 |
Output |
| 70 |
------- |
| 71 |
|
| 72 |
Block scripts are responsible for making sure that if a file is |
| 73 |
provided to a VM read/write, that it is not provided to any other VM. |
| 74 |
|
| 75 |
FreeBSD block hotplug scripts must write |
| 76 |
"$XENBUS_PATH/physical-device-path" with the path to the physical |
| 77 |
device or file. Linux and NetBSD block hotplug scripts *should* also |
| 78 |
write this node. |
| 79 |
|
| 80 |
For the time being, Linux and NetBSD block hotplug scripts must write |
| 81 |
"$XENBUS_PATH/physical-device" with the device's major and minor |
| 82 |
numbers, written in hex, and separated by a colon. |
| 83 |
|
| 84 |
Scripts which include block-common.sh can simply call write_dev "$dev" |
| 85 |
with a path to the device, and write_dev will do the right thing, now |
| 86 |
and going forward. (See the discussion below.) |
| 87 |
|
| 88 |
Rationale and future work |
| 89 |
------------------------- |
| 90 |
|
| 91 |
Historically, the block scripts wrote a node called "physical-device", |
| 92 |
which contains the major and minor numbers, written in hex, and |
| 93 |
separated by a colon (e.g., "1a:2"). This is required by the Linux |
| 94 |
blkback driver. |
| 95 |
|
| 96 |
FreeBSD blkback, on the other hand, does not have the concept of |
| 97 |
major/minor numbers, and can give direct access to a file without |
| 98 |
going through loopback; so its driver will consume |
| 99 |
physical-device-path. |
| 100 |
|
| 101 |
On Linux, the device model (qemu) needs access to a file it can |
| 102 |
interpret to provide emulated disks before paravirtualized drivers are |
| 103 |
marked as up. The easiest way to accomplish this is to allow qemu to |
| 104 |
consume physical-device-path (rather than, say, having dom0 act as |
| 105 |
both a frontend and a backend). |
| 106 |
|
| 107 |
Going forward, the plan is at some point to have all block scripts |
| 108 |
simply write "physical-device-path", and then have libxl write the |
| 109 |
other nodes. The reason we haven't done this yet is that the main |
| 110 |
block script wants to check to make sure the *major/minor* number |
| 111 |
hasn't been re-used, rather than just checking that the *specific |
| 112 |
device node* isn't re-used. To do this it currently uses |
| 113 |
physical-device; and to do this *safely* it needs physical-device to |
| 114 |
be written with the lock held. |
| 115 |
|
| 116 |
The simplest solution for sorting this out would be to have the block |
| 117 |
script use physical-device if it's present, but if not, to directly |
| 118 |
stat physical-device-path. But there's not time before the 4.7 |
| 119 |
release to make sure all that works. |
| 120 |
|
| 121 |
Another possibility would be to only call out to scripts when using |
| 122 |
custom hotplug scripts; and when doing files or physical devices, to |
| 123 |
do the duplicate checking inside of libxl instead. The rationale for |
| 124 |
doing this in block scripts rather than in libxl isn't clear at thes |
| 125 |
point. |