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

When referring to a specific image version in the disk image URN, and

that image is an *imported* system image, we are almost certainly
referring to a version related to the origin image, not the local
copy (which is not in sync with the origin wrt the history). In that
case, we can use the hash from the image server to track down the local
version.

Aside; If I were going to redo the import mechanism, I would make image
provenance the default for everyone, and make the option be whether to
save or delete the image file (that was the entire reason I made
provenance optional, most sites especially geni racks, do not have
enough storage to maintain old images. And image import would always
import the history too, which is something I did later when we thought
deltas were going to solve our problems.
parent 47a3a354
......@@ -1265,7 +1265,31 @@ sub GetTicketAuxAux($)
"Malformed image URN: $dname");
goto bad;
}
$osinfo = OSImage->Lookup($ospid, $os, $vers);
# See if we have any version of this image.
$osinfo = OSImage->Lookup($ospid, $os);
#
# If we do and the request was for a specific version of
# the image and this image was imported, then the version
# number probably refers to the version at the origin. We
# want to use the hash to resolve it instead, down in
# MapToLocalImage.
#
if (defined($osinfo) && defined($vers)) {
if ($osinfo->IsLocal()) {
$osinfo = OSImage->Lookup($ospid, $os, $vers);
if (!defined($osinfo)) {
$response =
GeniResponse->Create(GENIRESPONSE_BADARGS,
undef,
"Unknown image URN: ".
"$dname");
goto bad;
}
}
else {
$osinfo = undef;
}
}
if (!defined($osinfo)) {
if ($use_imagetracker) {
my $image = GeniImage::MapToLocalImage($dname, $pid);
......@@ -1273,9 +1297,14 @@ sub GetTicketAuxAux($)
$response = $image;
goto bad;
}
$osname = ($image->IsLocal() ?
$image->versname() :
$image->metadata_url());
if ($image->IsLocal() || $image->IsSystemImage()) {
# No need for image_setup to look at it.
# System images are never auto imported.
$osname = $image->versname();
}
else {
$osname = $image->metadata_url();
}
}
else {
$response =
......
......@@ -298,6 +298,39 @@ sub MapToLocalImage($$)
#print STDERR Dumper($blob);
# The image might be version specific.
my ($ospid,$imagename,$version) = split("\/\/", $hrn->id());
if (defined($version) && $version !~ /^\d+$/) {
print STDERR "Bad version number in $urn\n";
return undef;
}
#
# We used to handle this in the caller, but if a user wants a specific
# version of an imported image we already have locally, that version
# number almost certainly refers to the version history at the origin,
# not the local history which might not have all of the versions that
# are present at the origin. This is a flaw in the original design; we
# should have been synchronizing the image history. But at this point
# there is nothing we can do except hope that the local history has a
# version with the same hash as what the image server tells us.
#
if (defined($version)) {
my $image = OSImage->Lookup($ospid, $imagename);
if (defined($image)) {
my @allversions = ();
if ($image->AllVersions(\@allversions) == 0) {
foreach my $im (@allversions) {
if (defined($im->hash()) && exists($blob->{'sha1hash'}) &&
$im->hash() eq $blob->{'sha1hash'}) {
print STDERR "MapToLocalImage: Found local image $im\n";
return $im;
}
}
}
}
}
#
# So, look to see if the user is trying to use an image that is
# present in the current project. This will happen if after an import
......@@ -309,12 +342,6 @@ sub MapToLocalImage($$)
# We are looking for an image with the same name, but we verify with
# the hash that is stored at the image server.
#
# The image might be version specific.
my (undef,$imagename,$version) = split("\/\/", $hrn->id());
if (defined($version) && $version !~ /^\d+$/) {
print STDERR "Bad version number in $urn\n";
return undef;
}
my $image = OSImage->Lookup($pid,$imagename);
if (defined($image)) {
#
......
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