ia64/xen-unstable

view tools/python/xen/xend/server/BlktapController.py @ 15822:2f13d0f2b07c

xend: Add blktap disk type check

Print the following error when you give a wrong disk type to xm commands:
# xm create /xen/vm1.conf disk='tap:xxx:/xen/root-vm1.img,hda1,w'
Using config file "/xen/vm1.conf".
Error: tap:xxx not a valid disk type

# xm block-attach vm2 tap:yyy:/xen/second.img hdb1 w
Error: tap:yyy not a valid disk type
Usage: xm block-attach <Domain> <BackDev> <FrontDev> <Mode>
[BackDomain]

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author kfraser@localhost.localdomain
date Fri Aug 31 14:11:15 2007 +0100 (2007-08-31)
parents 6524e02edbeb
children 221b2680ffe5
line source
1 # Copyright (c) 2005, XenSource Ltd.
4 from xen.xend.server.blkif import BlkifController
5 from xen.xend.XendLogging import log
7 phantomDev = 0;
8 phantomId = 0;
10 blktap_disk_types = [
11 'aio',
12 'sync',
13 'vmdk',
14 'ram',
15 'qcow'
16 ]
18 class BlktapController(BlkifController):
19 def __init__(self, vm):
20 BlkifController.__init__(self, vm)
22 def frontendRoot(self):
23 """@see DevController#frontendRoot"""
25 return "%s/device/vbd" % self.vm.getDomainPath()
27 def getDeviceDetails(self, config):
28 (devid, back, front) = BlkifController.getDeviceDetails(self, config)
30 phantomDevid = 0
31 wrapped = False
33 try:
34 imagetype = self.vm.info['image']['type']
35 except:
36 imagetype = ""
38 if imagetype == 'hvm':
39 tdevname = back['dev']
40 index = ['c', 'd', 'e', 'f', 'g', 'h', 'i', \
41 'j', 'l', 'm', 'n', 'o', 'p']
42 while True:
43 global phantomDev
44 global phantomId
45 import os, stat
47 phantomId = phantomId + 1
48 if phantomId == 16:
49 if index[phantomDev] == index[-1]:
50 if wrapped:
51 raise VmError(" No loopback block \
52 devices are available. ")
53 wrapped = True
54 phantomDev = 0
55 else:
56 phantomDev = phantomDev + 1
57 phantomId = 1
58 devname = 'xvd%s%d' % (index[phantomDev], phantomId)
59 try:
60 info = os.stat('/dev/%s' % devname)
61 except:
62 break
64 vbd = { 'mode': 'w', 'device': devname }
65 fn = 'tap:%s' % back['params']
67 # recurse ... by creating the vbd, then fallthrough
68 # and finish creating the original device
70 from xen.xend import XendDomain
71 dom0 = XendDomain.instance().privilegedDomain()
72 phantomDevid = dom0.create_phantom_vbd_with_vdi(vbd, fn)
73 # we need to wait for this device at a higher level
74 # the vbd that gets created will have a link to us
75 # and will let them do it there
77 # add a hook to point to the phantom device,
78 # root path is always the same (dom0 tap)
79 if phantomDevid != 0:
80 front['phantom_vbd'] = '/local/domain/0/backend/tap/0/%s' \
81 % str(phantomDevid)
83 return (devid, back, front)