Commit fbc26aea authored by Leigh B Stoller's avatar Leigh B Stoller

A big set of changes to how we create XEN guest disks.

Prior to this commit, XEN guests disks were single partition, no MBR,
the bits dumped into the lvm. This makes a snapshot of a XEN node,
look completely different then a physical disk image, especially if
users want more disk space (mkextrafs) inside the guest, and then want
to take a snapshot of that, and then run it on a physical node (which
was not possible).

With these changes, guests now use the same MBR layout as our version
two MBR, which makes them interchangeable with physical disk images.
In fact, the goal is to be able to switch back and forth as needed,
based on physical resource availability.
parent 16d4b42d
#!/usr/bin/perl -w
#
# Copyright (c) 2009-2012 University of Utah and the Flux Group.
# Copyright (c) 2009-2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -39,7 +39,6 @@ sub usage()
my $optlist = "dix:r:";
my $debug = 1;
my $infomode = 0;
my $islinux = 0;
my $VMPATH = "/var/emulab/vms/vminfo";
my $EXTRAFS = "/capture";
my $VGNAME = "xen-vg";
......@@ -141,11 +140,6 @@ if (exists($xminfo{"ramdisk"})) {
system("cp " . $xminfo{"ramdisk"} . " $ramdisk") == 0
or Fatal("Could not copy ramdisk to $ramdisk");
$xminfo{"ramdisk"} = basename($xminfo{"ramdisk"});
#
# Yuck. Need a better way to determine this.
#
$islinux = 1;
}
#
......@@ -207,26 +201,11 @@ foreach my $device (keys(%diskinfo)) {
print "Working on $device.\n";
print "Size is $lv_size. Writing to $EXTRAFS/$filename\n";
#
# The root FS is a single partition image, while the aux disks
# have a real MBR in them.
#
my $opts = "";
if (defined($options{"x"})) {
if ($device =~ /sda/ || $device =~ /xvda/) {
$opts = ($islinux ? "-l" : "-b");
}
}
else {
if (! ($device =~ /disk/)) {
$opts = ($islinux ? "-l" : "-b");
}
}
if ($infomode) {
system("imagezip -i $opts $device");
system("imagezip -i $device");
}
else {
system("imagezip -o $opts $device $EXTRAFS/$filename");
system("imagezip -o $device $EXTRAFS/$filename");
}
if ($?) {
Fatal("imagezip failed");
......
......@@ -43,9 +43,10 @@ sub usage()
"<vnodeid> <filename>\n";
exit(-1);
}
my $optlist = "F:S:pr";
my $optlist = "F:S:prs:";
my $aspack = 0;
my $norestart = 0;
my $slice = 0;
#
# Turn off line buffering on output
......@@ -55,6 +56,7 @@ $| = 1;
# Need this for predicates.
use libsetup;
use libvnode_xen;
use libutil;
#
# No configure vars.
......@@ -93,6 +95,9 @@ if (@ARGV != 2) {
if (defined($options{"p"})) {
$aspack = 1;
}
if (defined($options{"s"})) {
$slice = $options{"s"};
}
if (defined($options{"S"})) {
$iserver = $options{"S"};
if ($iserver =~ /^([-\w\.]+)$/) {
......@@ -189,23 +194,8 @@ if ($aspack) {
}
else {
my $device = libvnode_xen::lvmVolumePath($vnodeid);
my $opt = "";
my $opt = ($slice ? "-s $slice" : "");
#
# Hacky way to determine what kind of filesystem, since there
# is nothing in the MBR to tell us.
#
if (system("$zipper -i -b $device >/dev/null 2>&1") == 0) {
$opt = "-b";
}
elsif (system("$zipper -i -l $device >/dev/null 2>&1") == 0) {
$opt = "-l";
}
else {
print STDERR "Cannot determine imagezip FS type of $device\n";
$error = 1;
goto cleanup;
}
$cmd = "$zipper $opt $device $filename";
}
......@@ -225,9 +215,8 @@ if (defined($imageid)) {
# with proper trust should be able to zip up a disk. sudo will fail
# if the user is not in the proper group.
#
if (system("$sudo $cmd")) {
if (mysystem2("$sudo $cmd")) {
print STDERR "*** Failed to create image!\n";
print STDERR " command: '$sudo $cmd'\n";
$error = 1;
}
......
This diff is collapsed.
......@@ -146,12 +146,6 @@ else {
chomp($lvsize);
}
#
# Hacky attempt to determine if its a freebsd or linux disk.
#
system("$IMAGEZIP -i -b $imagelvmpath > /dev/null 2>&1");
my $zipopt = ($? ? "-l" : "-b");
while ($count > 0) {
if (grep {$_ eq "/dev/$VGNAME/_C_${imagename}_${idx}"} @files) {
$count--
......@@ -161,14 +155,17 @@ while ($count > 0) {
}
my $cachename = "_C_${imagename}_${idx}";
my $cachefile = "/dev/$VGNAME/$cachename";
my $imagemetadata;
if (mysystem2("lvcreate -d -v -L${lvsize} -n $cachename $VGNAME")) {
if (libvnode_xen::LoadImageMetadata($imagename, \$imagemetadata)) {
print STDERR "Cannot load image metadata for $imagename\n";
TBScriptUnlock();
exit(1);
}
if (mysystem2("nice $IMAGEZIP $zipopt $imagelvmpath - | ".
"nice $IMAGEUNZIP -f -o -W 128 - $cachefile")) {
mysystem2("lvremove -f $cachefile");
if (libvnode_xen::CreatePrimaryDisk("image+" . $imagename,
$imagemetadata, $cachename, undef)) {
mysystem2("lvremove -f $cachefile")
if (-e $cachefile);
TBScriptUnlock();
exit(1);
}
......
......@@ -239,7 +239,7 @@ my %xmlfields =
"op_mode", => $base_osinfo->op_mode(),
"global" => (defined($global) ?
($global ? 1 : 0) : $base_osinfo->shared()),
"wholedisk", => ($isvirtnode ? 1 : $wholedisk),
"wholedisk", => $wholedisk,
);
$xmlfields{"reboot_waittime"} = $base_osinfo->reboot_waittime()
if (defined($base_osinfo->reboot_waittime()));
......@@ -249,9 +249,18 @@ $xmlfields{"osfeatures"} = $base_osinfo->osfeatures()
if (defined($base_image)) {
$xmlfields{"mbr_version"} = $base_image->mbr_version();
$xmlfields{"loadpart"} = ($isvirtnode ? 1 : $base_image->loadpart());
$xmlfields{"loadpart"} = $base_image->loadpart();
$xmlfields{"global"} = (defined($global) ?
($global ? 1 : 0) : $base_image->global());
# Short form uses wholedisk instead. Should fix this.
if ($base_image->loadpart() == 0 && $base_image->loadlength() == 4) {
$xmlfields{"loadpart"} = 1;
$xmlfields{"wholedisk"} = 1;
}
elsif ($wholedisk) {
$xmlfields{"loadpart"} = 1;
}
}
elsif ($isvirtnode) {
$xmlfields{"reboot_waittime"} = 240;
......
......@@ -96,6 +96,7 @@ use Experiment;
use Node;
use User;
use Image;
use OSinfo;
use Logfile;
#
......@@ -501,11 +502,25 @@ if ($isec2node) {
$command = "$EC2SNAP ";
}
elsif ($isvirtnode) {
#
# Need to know this is a xen-host to tailor options.
#
my $pnode = Node->Lookup($node->phys_nodeid());
my $osinfo = OSinfo->Lookup($pnode->def_boot_osid());
if (!defined($osinfo)) {
fatal("Could not get osinfo for $pnode");
}
#
# XXX Need to add XEN package flag to descriptor.
#
if ($image->mbr_version() == 99) {
$command .= " -p";
if ($osinfo->FeatureSupported("xen-host")) {
if ($image->mbr_version() == 99) {
$command .= " -p";
}
if ($image->loadpart()) {
$command .= " -s " . $image->loadpart();
}
}
$command .= " $node_id";
}
......
......@@ -123,7 +123,7 @@ else {
if (! isset($confirmed)) {
$url = CreateURL("loadimage", $image);
$newurl = CreateURL("newimageid_ez", "target", $target);
$newurl = CreateURL("newimageid_ez", "node_id", $target);
echo "<center><form action='$url' method='post'>\n".
"<h2><b>Warning!</b></h2>".
......
......@@ -83,6 +83,16 @@ if (isset($node)) {
if (! $baseimage) {
$baseosinfo = OSinfo::Lookup($node->def_boot_osid());
}
else {
$baseosinfo = OSinfo::Lookup($baseimage->imageid());
}
if ($baseosinfo && $baseosinfo->def_parentosid()) {
$def_parentosinfo = OSinfo::Lookup($baseosinfo->def_parentosid());
if (! $def_parentosinfo) {
TBERROR("Could not lookup osinfo object for parent " .
$baseosinfo->def_parentosid(), 1);
}
}
}
elseif ($ec2) {
$nodetype = "pcvm";
......@@ -104,6 +114,9 @@ if (isset($nodetype) && $nodetype == "pcvm") {
'hide_concurrent' => 1,
'hide_footnotes' => 1,
'hide_wholedisk' => 1);
if ($def_parentosinfo && $def_parentosinfo->FeatureSupported("xen-host")) {
$view['hide_wholedisk'] = 0;
}
}
elseif (isset($nodetype) && $nodetype == "mote") {
$view = array('hide_partition' => 1, 'hide_os' => 1, 'hide_version' => 1,
......@@ -624,7 +637,7 @@ function SPITFORM($formfields, $errors)
#
# Whole Disk Image
#
if (isset($view["hide_wholedisk"])) {
if (isset($view["hide_wholedisk"]) && $view["hide_wholedisk"]) {
spithidden($formfields, 'wholedisk');
} else {
echo "<tr>
......
......@@ -337,6 +337,20 @@ class OSinfo
}
#
# See if a feature is supported
#
function FeatureSupported($feature) {
if ($this->osfeatures()) {
foreach (preg_split("/,/", $this->osfeatures()) as $f) {
if ($feature == $f) {
return 1;
}
}
}
return 0;
}
#
# Spit out an OSID link in user format.
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment