Changeset 1987 for trunk/packages/invirt-remote/host/usr/sbin/invirt-lvm
- Timestamp:
- Jan 24, 2009, 4:16:39 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/invirt-remote/host/usr/sbin/invirt-lvm
r1822 r1987 2 2 3 3 import sys 4 import os.path 4 import time 5 import os 6 import random 7 import string 5 8 from subprocess import call, PIPE, Popen 6 9 from invirt.config import structs as config … … 45 48 print >>sys.stderr, "Error removing LV %s\n" % lvname 46 49 sys.exit(1) 47 # I know this is the wrong answer, but sometimes the first 48 # lvchange -a n fails for no particularly good reason, so this is 49 # a pretty good workaround 50 call(["/sbin/lvchange", "-a", "n", lvpath]) 51 rv = call(["/sbin/lvchange", "-a", "n", lvpath]) 52 if rv != 0: 53 error() 54 rv = call(["/sbin/lvchange", "-a", "ey", lvpath]) 55 if rv != 0: 56 error() 57 rv = call(["/sbin/lvremove", "--force", lvpath]) 58 if rv != 0: 59 error() 50 51 # Rename the LV to something else so we can wipe it before reusing 52 # the space 53 while True: 54 new_lvname = "old_%s_%s" % (lvname, ''.join(random.choice(string.ascii_letters) for i in xrange(6))) 55 new_lvpath = "/dev/%s/%s" % (vg, new_lvname) 56 p = Popen(["/sbin/lvrename", lvpath, new_lvpath], stdout=PIPE, stderr=PIPE) 57 rv = p.wait() 58 if rv == 5 and 'already exists in volume group' in p.stderr.read(): 59 continue 60 elif rv != 0: 61 error() 62 else: 63 break 60 64 ensureoff(machine) 65 66 # Fork. The child process wipes the LV and then deletes 67 # it. There's not really anything sane to do with errors (since 68 # this is running non-interactively), so let's just drop them on 69 # the floor for now. 70 if os.fork() == 0: 71 call(["/bin/dd", "if=/dev/zero", "of=%s" % new_lvpath]) 72 call(["/sbin/lvchange", "-a", "n", new_lvpath]) 73 call(["/sbin/lvchange", "-a", "ey", new_lvpath]) 74 call(["/sbin/lvremove", "--force", new_lvpath]) 61 75 elif subcommand == "lvresize": 62 76 size = sys.argv[4] … … 86 100 print >>sys.stderr, "Error creating LV %s\n" %(lvname,) 87 101 sys.exit(1) 88 89 102
Note: See TracChangeset
for help on using the changeset viewer.