Changeset 449 for trunk/packages


Ignore:
Timestamp:
Apr 22, 2008, 4:15:57 PM (17 years ago)
Author:
price
Message:

sipb-xen-losetup: a half-sane way to use losetup

You should use this instead of plain losetup; everything that uses this
will at least not have races with other things using this.

If it's missing a feature (e.g. a losetup argument) you want,
it shouldn't be hard to add.

Location:
trunk/packages
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-guest-installer/files/usr/sbin/sipb-xen-lvcopy

    r405 r449  
    99
    1010def losetup(source, offset=0):
    11   # XXX we avoid colliding with other instances of ourself,
    12   #     but when it comes to other loop-device users we just
    13   #     pick a range things don't seem to use and hope...
    14   lockfilename = '/tmp/losetup.lock'
    15   os.close(os.open(lockfilename, os.O_CREAT+os.O_EXCL)) #lock
    16   try:
    17     loopdevice = None
    18     for i in xrange(32,60): # totally arbitrary, just looks to be unused on black-mesa
    19       filename = '/dev/loop%d'%i
    20       if 0 == len(file(filename).read(1)):
    21         loopdevice = filename # it's empty
    22         break
    23     if loopdevice is not None:
    24       call(['losetup', '-o', str(offset), loopdevice, source])
    25     else:
    26       raise RuntimeError('out of loop devices for copying VM image: too many at once?')
    27   finally:
    28     os.unlink(lockfilename) #unlock
    29   return loopdevice
    30   # XX this means we can duplicate 28 at once.  Since it takes around 30s,
    31   # this seems like an adequate capacity.
     11  p = Popen(['sipb-xen-losetup', source, str(offset)], stdout=PIPE)
     12  return p.communicate()[0].strip()
    3213
    3314def frob_copy_in_vm(target, *args):
Note: See TracChangeset for help on using the changeset viewer.