X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-remote.git/blobdiff_plain/308f5555dc4e49e2e2c734e03f7875bb9220f700..74bf6f0c14efbc2e33fd9f8d79bdb807286725ca:/host/usr/sbin/invirt-lvm?ds=inline diff --git a/host/usr/sbin/invirt-lvm b/host/usr/sbin/invirt-lvm index a2a6cc9..cae6b2b 100755 --- a/host/usr/sbin/invirt-lvm +++ b/host/usr/sbin/invirt-lvm @@ -22,6 +22,14 @@ def ensureoff(machine): rv = call(["/usr/sbin/xm", "destroy", prefix + machine], stderr=PIPE) +machine_specific = subcommand not in ['lvcreate-all', 'vgcapacity'] + +if machine_specific: + machine = sys.argv[2] + disk = sys.argv[3] + lvname = prefix + machine + "_" + disk + lvpath = "/dev/" + vg + "/" + lvname + if subcommand == "lvcreate-all": from invirt import database import re @@ -38,12 +46,7 @@ if subcommand == "lvcreate-all": if rv != 0: print >>sys.stderr, "Error creating LV %s\n" %(lvname,) sys.exit(1) -else: - machine = sys.argv[2] - disk = sys.argv[3] - lvname = prefix + machine + "_" + disk - lvpath = "/dev/" + vg + "/" + lvname -if subcommand == "lvremove": +elif subcommand == "lvremove": def error(): print >>sys.stderr, "Error removing LV %s\n" % lvname sys.exit(1) @@ -63,15 +66,9 @@ if subcommand == "lvremove": break ensureoff(machine) - # Fork. The child process wipes the LV and then deletes - # it. There's not really anything sane to do with errors (since - # this is running non-interactively), so let's just drop them on - # the floor for now. - if os.fork() == 0: - call(["/usr/bin/ionice", "-c", "2", "-n", "7", "/bin/dd", "if=/dev/zero", "of=%s" % new_lvpath]) - call(["/sbin/lvchange", "-a", "n", new_lvpath]) - call(["/sbin/lvchange", "-a", "ey", new_lvpath]) - call(["/sbin/lvremove", "--force", new_lvpath]) + # Touch a file corresponding to the new name of the LV; a separate + # daemon will handle wiping and deleting it. + open(os.path.join('/var/lib/invirt-remote/cleanup', new_lvname), 'w') elif subcommand == "lvresize": size = sys.argv[4] ensureoff(machine) @@ -99,4 +96,23 @@ elif subcommand == "lvcreate": if rv != 0: print >>sys.stderr, "Error creating LV %s\n" %(lvname,) sys.exit(1) +elif subcommand == "vgcapacity": + p = Popen(["/sbin/vgs", "-o", "vg_extent_size,vg_extent_count,vg_free_count", + "--noheadings", "--units", "k", "--nosuffix", "--separator", ":", + vg], + stdout=PIPE, stderr=PIPE) + out,err = p.communicate() + + try: + fields = out.strip().split(':') + extent_size = float(fields[0]) # in kibibytes + extent_count = int(fields[1]) + free_count = int(fields[2]) + total_space_TiB = extent_size * extent_count / 1024.**3 + free_space_TiB = extent_size * free_count / 1024.**3 + print >>sys.stdout, "Total: %.3f TiB" % (total_space_TiB,) + print >>sys.stdout, "Free: %.3f TiB" % (free_space_TiB,) + except: + print >>sys.stderr, "Error obtaining vg capacity:\n%s\n" % (err,) + sys.exit(1)