Ignore:
Timestamp:
Jan 24, 2009, 4:16:39 AM (16 years ago)
Author:
broder
Message:

Overwrite all content of a VM's LV before deleting it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-remote/host/usr/sbin/invirt-lvm

    r1822 r1987  
    22
    33import sys
    4 import os.path
     4import time
     5import os
     6import random
     7import string
    58from subprocess import call, PIPE, Popen
    69from invirt.config import structs as config
     
    4548        print >>sys.stderr, "Error removing LV %s\n" % lvname
    4649        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
    6064    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])
    6175elif subcommand == "lvresize":
    6276    size = sys.argv[4]
     
    86100        print >>sys.stderr, "Error creating LV %s\n" %(lvname,)
    87101        sys.exit(1)
    88    
    89102
Note: See TracChangeset for help on using the changeset viewer.