Fix bug #331
PATCH 1/1 Fix bug #331
This patch adds the following checks to xend:
- Make sure a block device is not attached to more than one DomU at a time
- Make sure a block device is not attached to a DomU if it is mounted in Dom0
- Make sure a block device exists before even trying to attach it
- Make sure files specified with "file:" actually exist and have the necessary permissions
This makes tests 11_block_attach and 12_block_attach pass.
In order to check if a device is attached to another DomU, I search the /local/domain/0/device/vbd/*/*/physical-device nodes to see if any DomU had the device already. Although this is ugly, I think it's the best way, so that we don't depend on any xend internal state.
Comments?
# HG changeset patch
# User [email protected]
# Node ID 643382df7dc8a2562cf1034250244dc6b2bdebd3
# Parent 14d733e5e1d014e302d72fb78df1428ee08e3ce3
Fix bug #331. Perform some checks before creating block device to make sure that the device is not in use by another DomU, or mounted in Dom0. Also, make a small tweak to the 12_block_attach test so that we don't leave a DomU running with a block device attached.
tools/python/xen/xend/server/DevController.py +16 -0
@@ -75,6 +75,10 @@ @return The ID for the newly created device. """ + (avail, reason) = self.checkAvailability(config) + if not avail: + raise VmError("Device is unavailable: %s" % reason) + (devid, back, front) = self.getDeviceDetails(config) if devid is None: return 0
@@ -202,6 +206,18 @@ raise NotImplementedError() + def checkAvailability(self, config): + + """Determine if the device requested is available for use. + Quick checks that can be made immediately. For example, this + may be an existence, permission, or sharing check. We default + to 'available' because this may not make sense for all device + types. + + @return (isAvailable, reason) + """ + + return (True, "OK") def getDomid(self): """Stub to {@link XendDomainInfo.getDomid}, for use by our
tools/python/xen/xend/server/blkif.py +91 -0
110 lines not on this page · raw message
tools/xm-test/tests/block-create/12_block_attach_shared_domU.py +2 -2
@@ -18,7 +18,7 @@ try: dom2.start() + dom1.destroy() FAIL("Bug #331: Started a DomU with write access to an in-use block device") except DomainError, e: - pass - + dom1.destroy()
Signature · 5 lines
-- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: [email protected]
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Ewan Mellor
AppliedQuoted 10 lines · Dan Smith
This patch adds the following checks to xend:
- Make sure a block device is not attached to more than one DomU at a time
- Make sure a block device is not attached to a DomU if it is mounted in Dom0
- Make sure a block device exists before even trying to attach it
- Make sure files specified with "file:" actually exist and have the necessary permissions
Quoted 6 lines
This makes tests 11_block_attach and 12_block_attach pass.
In order to check if a device is attached to another DomU, I search the /local/domain/0/device/vbd/*/*/physical-device nodes to see if any DomU had the device already. Although this is ugly, I think it's the best way, so that we don't depend on any xend internal state.
Thanks for your patch Dan. Unfortunately, Xend is not the right place for these checks. We have to worry about device configuration even when it's not performed through Xend -- the drivers will configure the device if you write to the store, even if you don't go through Xend. With that in mind, these safety checks need to be lower down in the system. I've put them into the hotplug scripts (the physical devices support has been checked in, and support for loopback files is on its way).
I've applied the fix to 12_block_attach.
Cheers,
Ewan.
EM> Unfortunately, Xend is not the right place for these checks. We EM> have to worry about device configuration even when it's not EM> performed through Xend -- the drivers will configure the device if EM> you write to the store, even if you don't go through Xend. With EM> that in mind, these safety checks need to be lower down in the EM> system.
I think the drivers should attach multiple DomUs to the same block device, if asked to do so. The bug description said that this functionality should be provided by the tools for special-purpose filesystems that can handle concurrent writers. It seems perfectly logical to me for the drivers to do what they're told, and have the tools (whatever tools may be in use) provide the checks and protections necessary to help the user from shooting himself in the foot.
Further, I think that pushing a bunch of checks into the hotplug scripts is less desirable, as it makes it harder to communicate good information back to the frontend tools. Right now, we just get a "failed" message instead of "device missing" or "device already in use" message.
Signature · 4 lines
Dan Smith IBM Linux Technology Center Open Hypervisor Team email: [email protected]
Quoted 8 lines · Dan Smith
EM> Unfortunately, Xend is not the right place for these checks. We EM> have to worry about device configuration even when it's not EM> performed through Xend -- the drivers will configure the device if EM> you write to the store, even if you don't go through Xend. With EM> that in mind, these safety checks need to be lower down in the EM> system.
Quoted 4 lines
I think the drivers should attach multiple DomUs to the same block device, if asked to do so. The bug description said that this functionality should be provided by the tools for special-purpose filesystems that can handle concurrent writers.
My fix includes an override to the test. By setting the mode to w!, you get read-write access, with sharing allowed.
Quoted 5 lines
It seems perfectly
logical to me for the drivers to do what they're told, and have the tools (whatever tools may be in use) provide the checks and protections necessary to help the user from shooting himself in the foot.
To a certain extent, yes, but on the other hand, what you do by doing that is require all tools to duplicate the same checks. In this case, the check is so important (filesystems are easily corrupted without it) that the check would definitely have to be included in every tool, so it is better to push it down nearer the drivers, where it can be shared.
Quoted 5 lines
Further, I think that pushing a bunch of checks into the hotplug scripts is less desirable, as it makes it harder to communicate good information back to the frontend tools. Right now, we just get a "failed" message instead of "device missing" or "device already in use" message.
My changes today add support for a hotplug-error node, which includes a full error description. If you mount a filesystem in dom0 and then try to use the same as a device in a guest, you will get the message:
Error: Device 2049 (vbd) could not be connected. Device /dev/VG_XenRT/LV0 is mounted in the privileged domain, and so cannot be mounted by a guest.
which is a lot better than some of Xend's other messages.
Ewan.