Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit bea9f0a

Browse files
committed
VirtualDisk: Support floppy 'dir' mode (fat:floppy for qemu)
1 parent a80a447 commit bea9f0a

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

tests/clitest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
'ROIMG' : ro_img,
7171
'POOL' : "default-pool",
7272
'VOL' : "testvol1.img",
73+
'DIR' : os.getcwd(),
7374
'MANAGEDEXIST1' : "/default-pool/testvol1.img",
7475
'MANAGEDEXIST2' : "/default-pool/testvol2.img",
7576
'MANAGEDNEW1' : "/default-pool/clonevol",
@@ -166,6 +167,8 @@
166167
"--disk %(COLLIDE)s --force",
167168
# Two IDE cds
168169
"--disk path=%(EXISTIMG1)s,device=cdrom --disk path=%(EXISTIMG1)s,device=cdrom",
170+
# Dir with a floppy dev
171+
"--disk %(DIR)s,device=floppy",
169172
],
170173

171174
"invalid": [
@@ -196,7 +199,9 @@
196199
# Not specifying path= and non existent storage w/ no size
197200
"--disk %(NEWIMG1)s",
198201
# Colliding storage without --force
199-
"--disk %(COLLIDE)s"
202+
"--disk %(COLLIDE)s",
203+
# Dir without floppy
204+
"--disk %(DIR)s,device=cdrom",
200205
]
201206
}, # category "storage"
202207

tests/xmlconfig-xml/boot-many-devices.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<source dev='/dev/loop0'/>
2727
<target dev='sda' bus='scsi'/>
2828
</disk>
29+
<disk type='dir' device='floppy'>
30+
<source dir='/tmp'/>
31+
<target dev='fdb' bus='fdc'/>
32+
</disk>
2933
<disk type='file' device='disk'>
3034
<driver name='qemu' type='qcow2'/>
3135
<source file='/default-pool/testvol1.img'/>

tests/xmlconfig.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ def testManyDevices(self):
522522
device=VirtualDisk.DEVICE_FLOPPY))
523523
g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0",
524524
bus="scsi"))
525+
g.disks.append(VirtualDisk(conn=g.conn, path="/tmp", device="floppy"))
525526
d3 = VirtualDisk(conn=g.conn, path="/default-pool/testvol1.img",
526527
bus="scsi", driverName="qemu")
527528
g.disks.append(d3)

virtinst/VirtualDisk.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ class VirtualDisk(VirtualDevice):
173173

174174
TYPE_FILE = "file"
175175
TYPE_BLOCK = "block"
176-
types = [TYPE_FILE, TYPE_BLOCK]
176+
TYPE_DIR = "dir"
177+
types = [TYPE_FILE, TYPE_BLOCK, TYPE_DIR]
177178

178179
@staticmethod
179180
def path_exists(conn, path):
@@ -614,7 +615,9 @@ def __set_dev_type(self):
614615
else:
615616
dtype = self.TYPE_BLOCK
616617
elif self.path:
617-
if _util.stat_disk(self.path)[0]:
618+
if os.path.isdir(self.path):
619+
dtype = self.TYPE_DIR
620+
elif _util.stat_disk(self.path)[0]:
618621
dtype = self.TYPE_FILE
619622
else:
620623
dtype = self.TYPE_BLOCK
@@ -899,8 +902,9 @@ def __validate_params(self):
899902
if not create_media:
900903
# Make sure we have access to the local path
901904
if not managed_storage:
902-
if os.path.isdir(self.path) and not _util.is_vdisk(self.path):
903-
# vdisk _is_ a directory.
905+
if (os.path.isdir(self.path) and
906+
not _util.is_vdisk(self.path) and
907+
not self.device == self.DEVICE_FLOPPY):
904908
raise ValueError(_("The path '%s' must be a file or a "
905909
"device, not a directory") % self.path)
906910

@@ -1106,7 +1110,7 @@ def get_xml_config(self, disknode=None):
11061110
takes precedence.
11071111
@type disknode: C{str}
11081112
"""
1109-
typeattr = 'file'
1113+
typeattr = self.type
11101114
if self.type == VirtualDisk.TYPE_BLOCK:
11111115
typeattr = 'dev'
11121116

0 commit comments

Comments
 (0)