def remove_tapdisk(self, dbg):
     if isinstance(self.image, image.Vhd):
         return  # not possible to remove a tapdisk
     if self.tapdisk is not None:
         if self.dm is not None:
             self.dm.suspend(dbg)
             if self.loop is None:
                 self.loop = losetup.create(dbg, self.image.path)
             self.dm.reload(dbg, self.loop.block_device())
             self.dm.resume(dbg)
             self.tapdisk.destroy(dbg)
             self.tapdisk = None
             self.save()
 def block_device(self):
     dbg = "Device.block_device"
     if self.block is None:
         self.connected = True
         if isinstance(self.image, image.Raw):
             self.loop = losetup.find(dbg, self.image.path)
             if self.loop is None:
                 self.loop = losetup.create(dbg, self.image.path)
             self.dm = dmsetup.find(dbg, self.loop.block_device())
             if self.dm is None:
                 self.dm = dmsetup.create(dbg, self.loop.block_device())
             self.block = self.dm.block_device()
             self.save()
             return self.block
         elif isinstance(self.image, image.Vhd):
             self.tapdisk = tapdisk.create(dbg)
             self.tapdisk.open(dbg, self.image)
             self.block = self.tapdisk.block_device()
             self.save()
             return self.block
     else:
         return self.block