Skip to content

Commit 3830450

Browse files
committed
CA-11936: Automatically plug block-based RAW VDIs via blkback
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]>
1 parent 86a988b commit 3830450

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

drivers/blktap2.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,12 @@ class SymLink(Link):
11841184
def readlink(self):
11851185
return os.readlink(self.path())
11861186

1187+
def realpath(self):
1188+
return os.path.realpath(self.path())
1189+
1190+
def is_block(self):
1191+
return S_ISBLK(os.stat(self.realpath()).st_mode)
1192+
11871193
def symlink(self):
11881194
return self.path
11891195

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

1496+
# Decide whether to use tapdisk3 or blkback
1497+
if (self.target.get_vdi_type() == "aio") and \
1498+
(self.target.vdi.sr.handles("lvm")):
1499+
self.xenstore_data['backend-kind'] = 'vbd'
1500+
else:
1501+
self.xenstore_data['backend-kind'] = 'vbd3'
1502+
14901503
# Return backend/ link
14911504
back_path = self.BackendLink.from_uuid(sr_uuid, vdi_uuid).path()
14921505
struct = { 'params': back_path,
@@ -1571,8 +1584,14 @@ def _activate_locked(self, sr_uuid, vdi_uuid, options):
15711584
break
15721585
raise
15731586

1587+
# Link backend directly to RAW LV VDIs
1588+
phy_dev = self.PhyLink.from_uuid(sr_uuid, vdi_uuid)
1589+
if phy_dev.is_block() and self.target.get_vdi_type() == "aio":
1590+
dev_path = phy_dev.realpath()
1591+
15741592
# Link result to backend/
15751593
self.BackendLink.from_uuid(sr_uuid, vdi_uuid).mklink(dev_path)
1594+
15761595
return True
15771596

15781597
def _activate(self, sr_uuid, vdi_uuid, options):

0 commit comments

Comments
 (0)