Skip to content

Commit

Permalink
CA-11936: Automatically plug block-based RAW VDIs via blkback
Browse files Browse the repository at this point in the history
This patch causes block-based (LV) RAW VDIs to be automatically plugged by
blkback. This is achieved as follows:

During VDI.attach, we detect that the SR handles LVM and that the VDI driver
is 'aio'. In that case, we write 'backend-kind: vbd' to xenstore_data, which
causes the toolstack to use the /local/domain/0/backend/vbd/ path instead of
.../vbd3/. This is the preferred method following CP-11511. By writing to
.../vbd/, blkback wakes up instead of tapback.

During VDI.activate, we create the /dev/sm/backend/ node using the maj/min
numbers of the actual VDI (LV) instead of those of the blktap2 device. This
causes the udev hotplug scripts to write the /physical-device/ entry with
information of the LV, creating the blkfront-blkback-vdi datapath without
blktap2 or tapdisk3 in the middle.

Note that a tapdisk3 and a blktap2 will still exist in dom0, providing all
necessary backend infrastructure resources for other operations.

Signed-off-by: Felipe Franciosi <[email protected]>
  • Loading branch information
franciozzy committed Apr 9, 2015
1 parent 86a988b commit 3830450
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions drivers/blktap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,12 @@ class SymLink(Link):
def readlink(self):
return os.readlink(self.path())

def realpath(self):
return os.path.realpath(self.path())

def is_block(self):
return S_ISBLK(os.stat(self.realpath()).st_mode)

def symlink(self):
return self.path

Expand Down Expand Up @@ -1487,6 +1493,13 @@ def attach(self, sr_uuid, vdi_uuid, writable, activate = False):
{"rdonly": not writable})
self.BackendLink.from_uuid(sr_uuid, vdi_uuid).mklink(dev_path)

# Decide whether to use tapdisk3 or blkback
if (self.target.get_vdi_type() == "aio") and \
(self.target.vdi.sr.handles("lvm")):
self.xenstore_data['backend-kind'] = 'vbd'
else:
self.xenstore_data['backend-kind'] = 'vbd3'

# Return backend/ link
back_path = self.BackendLink.from_uuid(sr_uuid, vdi_uuid).path()
struct = { 'params': back_path,
Expand Down Expand Up @@ -1571,8 +1584,14 @@ def _activate_locked(self, sr_uuid, vdi_uuid, options):
break
raise

# Link backend directly to RAW LV VDIs
phy_dev = self.PhyLink.from_uuid(sr_uuid, vdi_uuid)
if phy_dev.is_block() and self.target.get_vdi_type() == "aio":
dev_path = phy_dev.realpath()

# Link result to backend/
self.BackendLink.from_uuid(sr_uuid, vdi_uuid).mklink(dev_path)

return True

def _activate(self, sr_uuid, vdi_uuid, options):
Expand Down

0 comments on commit 3830450

Please sign in to comment.