Changeset 500 for trunk/packages/sipb-xen-dom0
- Timestamp:
- May 4, 2008, 8:45:44 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-dom0/files/usr/sbin/sipb-xen-losetup
r449 r500 3 3 import sys 4 4 import os 5 from subprocess import call 5 from subprocess import call, Popen, PIPE 6 6 7 7 def losetup(source, offset=0): 8 # XXX we avoid colliding with other instances of ourself,9 # but when it comes to other loop-device users we just10 # pick a range things don't seem to use and hope...11 8 lockfilename = '/tmp/losetup.lock' 12 9 os.close(os.open(lockfilename, os.O_CREAT+os.O_EXCL)) #lock 13 10 try: 14 loopdevice = None 15 for i in xrange(32,60): # totally arbitrary, just looks to be unused on black-mesa 16 filename = '/dev/loop%d'%i 17 if 0 == len(file(filename).read(1)): 18 loopdevice = filename # it's empty 19 break 20 if loopdevice is not None: 21 call(['losetup', '-o', str(offset), loopdevice, source]) 22 else: 11 loopdevice = Popen(['losetup', '-f'], stdout=PIPE).communicate()[0].rstrip() 12 if loopdevice == '': 23 13 raise RuntimeError('out of loop devices for copying VM image: too many at once?') 14 if call(['losetup', '-o', str(offset), loopdevice, source]) != 0: 15 raise RuntimeError('losetup failed') 24 16 finally: 25 17 os.unlink(lockfilename) #unlock
Note: See TracChangeset
for help on using the changeset viewer.