From d2a8f9face2cbaa0489554eabb416e04f5c86d97 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Tue, 22 Apr 2008 16:15:57 -0400 Subject: [PATCH] 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. svn path=/trunk/packages/sipb-xen-guest-installer/; revision=449 --- files/usr/sbin/sipb-xen-lvcopy | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/files/usr/sbin/sipb-xen-lvcopy b/files/usr/sbin/sipb-xen-lvcopy index 5b83460..065cda2 100755 --- a/files/usr/sbin/sipb-xen-lvcopy +++ b/files/usr/sbin/sipb-xen-lvcopy @@ -8,27 +8,8 @@ import time from subprocess import call, check_call, Popen, PIPE def losetup(source, offset=0): - # XXX we avoid colliding with other instances of ourself, - # but when it comes to other loop-device users we just - # pick a range things don't seem to use and hope... - lockfilename = '/tmp/losetup.lock' - os.close(os.open(lockfilename, os.O_CREAT+os.O_EXCL)) #lock - try: - loopdevice = None - for i in xrange(32,60): # totally arbitrary, just looks to be unused on black-mesa - filename = '/dev/loop%d'%i - if 0 == len(file(filename).read(1)): - loopdevice = filename # it's empty - break - if loopdevice is not None: - call(['losetup', '-o', str(offset), loopdevice, source]) - else: - raise RuntimeError('out of loop devices for copying VM image: too many at once?') - finally: - os.unlink(lockfilename) #unlock - return loopdevice - # XX this means we can duplicate 28 at once. Since it takes around 30s, - # this seems like an adequate capacity. + p = Popen(['sipb-xen-losetup', source, str(offset)], stdout=PIPE) + return p.communicate()[0].strip() def frob_copy_in_vm(target, *args): '''UNUSED: maybe we'll use this someday; it does isolate the frobber.''' -- 1.7.9.5