Commit ad48bbdb authored by Leigh Stoller's avatar Leigh Stoller

Minor cleanup and fixes:

1. Small bits of cleanup to remove hardwired paths and test for images
   that live in /usr/testbed and need special handling.

2. Make sure that the image directory exists in /proj when taking a
   snapshot of a system image that lives in /usr/testbed since that is
   were we always write new images.

3. When deleting an image, remove the DB state for the highest numbered
   version if it never came ready/released.
parent 7c345c85
......@@ -53,6 +53,8 @@ my $OURDOMAIN = "@OURDOMAIN@";
my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
my $DOPROVENANCE = @IMAGEPROVENANCE@;
my $TBWWW = "@TBWWW@";
my $PROJROOT = "@PROJROOT_DIR@";
my $GROUPROOT = "@GROUPSROOT_DIR@";
# Cache of instances to avoid regenerating them.
my %images = ();
......@@ -2609,6 +2611,9 @@ sub SchedIMSDeletion($$)
#
# Is the image the newest version of the image.
#
# This needs to include deleted images, we only care about max version
# number right now.
#
sub IsNewest($)
{
my ($self) = @_;
......@@ -2850,19 +2855,50 @@ sub HaveDeltaImage($)
my ($self) = @_;
return $self->deltasize() ? 1 : 0;
}
sub IsSystemImage($)
{
my ($self) = @_;
# Yuck.
return ($self->path() =~ /^\/usr\/testbed\// ? 1 : 0);
}
#
# When images are stored in sub directories.
#
sub CreateImageDir($)
{
my ($self) = @_;
return 0
if (!$self->IsDirPath() || -e $self->path());
if (!$self->IsDirPath());
if (!mkdir($self->path(), 0775)) {
print STDERR "Could not mkdir " . $self->path() . ": $!\n";
return -1
if ($self->CreateDirectory($self->path()));
#
# For system images that are written to $TB, we still need a place
# to write new (unreleased) images in /proj.
#
if ($self->IsSystemImage()) {
return -1
if ($self->CreateDirectory($self->SaveDir()));
}
return 0;
}
sub CreateDirectory($$)
{
my ($self, $directory) = @_;
return 0
if (-e $self->path());
if (!mkdir($directory, 0775)) {
print STDERR "Could not mkdir $directory: $!\n";
return -1;
}
if (!chmod(0775, $self->path())) {
print STDERR "Could not chown " . $self->path() . ": $!\n";
if (!chmod(0775, $directory)) {
print STDERR "Could not chmod $directory: $!\n";
return -1;
}
......@@ -2882,14 +2918,36 @@ sub CreateImageDir($)
my $uid = $leader->unix_uid();
my $gid = $group->unix_gid();
if (! chown($uid, $gid, $self->path())) {
print STDERR "Could not chown($uid,$gid) " .
$self->path() . ": $!\n";
if (! chown($uid, $gid, $directory)) {
print STDERR "Could not chown($uid,$gid) $directory: $!\n";
return -1;
}
}
return 0;
}
#
# Where we write the new files.
# I think cause we do not trust the path in the descriptor since the
# user can set it. This is probably the crux; we should not let the
# user set the path.
#
sub SaveDir($)
{
my ($self) = @_;
my $savedir =
($self->pid() eq $self->gid() ||
$self->global() || $self->IsSystemImage() ?
$PROJROOT . "/" . $self->pid() . "/images/" :
$GROUPROOT . "/" . $self->pid() . "/" . $self->gid() . "/images/");
# Add in the directory.
$savedir .= basename($self->path()) . "/"
if ($self->IsDirPath());
return $savedir;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -569,6 +569,12 @@ sub DeleteVersion($)
return $self->image()->DeleteVersion();
}
sub PurgeVersion($)
{
my ($self) = @_;
return $self->image()->PurgeVersion();
}
#
# Load the project object for an image
......@@ -1160,6 +1166,18 @@ sub CreateImageDir($)
return $self->image()->CreateImageDir();
}
sub SaveDir($)
{
my ($self) = @_;
return $self->image()->SaveDir();
}
sub IsSystemImage($)
{
my ($self) = @_;
return $self->image()->IsSystemImage();
}
################################################################################
# This is the stuff from OSinfo.pm
......
......@@ -371,13 +371,13 @@ if (defined($image)) {
# officially "released". We *can* use this version of the image
# by explicitly using its version number, before it is released.
#
if ($image->path() =~ /^$TB/) {
my $path = $PROJROOT . "/" . $image->pid() . "/images/" .
basename($image->path());
# Watch for directory in original path, since basename
# drops he trailing slash.
if ($image->IsSystemImage()) {
my $path;
if ($image->IsDirPath()) {
$path .= "/";
$path = $image->SaveDir();
}
else {
$path = $image->SaveDir() . basename($image->path());
}
if ($image->Update({"path" => $path})) {
$image->PurgeVersion();
......
......@@ -681,14 +681,7 @@ my $filename = $image->TempImageFile();
my $isglobal = $image->global();
my $usepath = 0;
my $isdataset = $image->isdataset();
my $hackprefix= ($image->pid() eq $image->gid() || $isglobal ?
$PROJROOT . "/" . $image->pid() . "/images/" :
$GROUPROOT . "/" .
$image->pid() . "/" . $image->gid() . "/images/");
if ($image->IsDirPath()) {
# Add in the directory.
$hackprefix .= basename($image->path()) . "/";
}
my $prefixdir = $image->SaveDir();
#
# If we are creating a signature file for this image, get the
......@@ -702,15 +695,15 @@ if ($signature) {
#
# Redirect pathname for global images. See equiv code in clone_image.
#
if ($isglobal && ($filename =~ /^$TB/)) {
$filename = $hackprefix . basename($filename);
if ($isglobal && $image->IsSystemImage()) {
$filename = $prefixdir . basename($filename);
print "*** WARNING: Writing global descriptor to $filename instead!\n";
#
# Ditto for the signature file
#
if ($dstsigfile && ($dstsigfile =~ /^$TB/)) {
$dstsigfile = $hackprefix . basename($dstsigfile);
if ($signature) {
$dstsigfile = $prefixdir . basename($dstsigfile);
}
#
......@@ -831,9 +824,9 @@ chmod(0664, $filename) or
# it to somewhere where frisbee can access it (in case NFS is being used).
# Note that we wait to do this until after we are sure the imagedir exists.
#
if ($srcsigfile && ($srcsigfile =~ /^$TB/)) {
if ($srcsigfile && $srcimage->IsSystemImage()) {
my $osrcsigfile = $srcsigfile;
$srcsigfile = $hackprefix . basename($srcsigfile);
$srcsigfile = $prefixdir . basename($srcsigfile);
if (system("cp -fp $osrcsigfile $srcsigfile")) {
fatal("Could not copy source signature file ".
"$osrcsigfile to $srcsigfile");
......@@ -1403,16 +1396,16 @@ if ($delta && $deltapct > 0 && defined($logfile)) {
# the case that usepath=1 (target is in /usr/testbed); we do not want
# to rename them to the target (will not work anyway), they have to
# stay in /proj. More succintly, we always move the new files to the
# hackprefix location.
# prefix location.
#
my $hfilename = $hackprefix .
my $hfilename = $prefixdir .
basename(($delta ? $image->DeltaImageFile() : $image->FullImageFile()));
if (system("/bin/mv -f $filename $hfilename")) {
fatal("Could not move new image file into place");
}
if ($dstsigfile &&
system("/bin/mv -f $dstsigfile $hackprefix" .
system("/bin/mv -f $dstsigfile $prefixdir" .
basename(($delta ?
$image->FullImageSigFile() :
$image->FullImageSigFile())))) {
......
......@@ -334,13 +334,17 @@ if ($purge || $rename) {
@torename = ();
}
# Throw away the slot if it never came ready or released.
if (!($imageversion->ready() && $imageversion->released())) {
# Only if the highest numbered version, no holes please.
if ($imageversion->IsNewest() &&
!($imageversion->ready() && $imageversion->released())) {
if ($impotent) {
my $vers = $imageversion->version();
print "Would kill version $vers that never came ready\n";
next;
print "Would kill version $vers DB state since it was ".
"not ready/released\n";
}
else {
$imageversion->PurgeVersion();
}
$imageversion->PurgeVersion();
}
$EUID = 0;
......
#!/usr/bin/perl -w
#
# Copyright (c) 2014-2016 University of Utah and the Flux Group.
# Copyright (c) 2014-2017 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -174,7 +174,7 @@ if ($image->version()) {
else {
$version0 = $image;
}
if ($version0->path() =~ /^\/usr\/testbed/) {
if ($version0->IsSystemImage()) {
my $vers0src = "$PROJROOT/" . $image->pid() . "/images/";
if ($version0->IsDirPath()) {
# Add in the directory.
......
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