X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-autoinstaller.git/blobdiff_plain/fe26ed9addacd59eb78febcaea7d90ef2401d82f..aa0dac9eef6c4ddc4eb036fe1f7d47170bc894a4:/files/usr/sbin/sipb-xen-lvcopy diff --git a/files/usr/sbin/sipb-xen-lvcopy b/files/usr/sbin/sipb-xen-lvcopy index 5b83460..53c5aa8 100755 --- a/files/usr/sbin/sipb-xen-lvcopy +++ b/files/usr/sbin/sipb-xen-lvcopy @@ -7,28 +7,14 @@ import tempfile import time from subprocess import call, check_call, Popen, PIPE +# Make sure to use up fd 0 to avoid a bug in subprocess in Python <= 2.5.1 +# NB we need to do this on every Python remctl script. +# See r53624 in Python svn. +sys.stdin = open('/dev/null') + 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.''' @@ -62,6 +48,9 @@ def frob_copy(target, hostname, rootpw): call(['losetup', '-d', fs]) def duplicate_by_vm(source, target, rootpw, nodd=False, nofrob=False): + if source != "ice3": + print "Error: can't clone that VM" + sys.exit(1) # source, target should be machine names prefix = 'd_' # 1. copy (by dd) source to target