Commit 1a81ff05 authored by Mike Hibler's avatar Mike Hibler

Add option to handle all images in a project.

Also, when marking a project as active to force its directory to be
exported to boss, make sure we put back the old value of last_activity
afterward.
parent bd996776
......@@ -33,17 +33,20 @@ use File::Basename;
sub usage()
{
print("Usage: imagetodir [-nq] <imageid>\n" .
" imagetodir [-nq] -P pid\n" .
" imagetodir [-nq] -a\n" .
"Options:\n".
" -P pid Do all images for a specific project\n".
" -a Do ALL images\n".
" -n Impotent mode\n".
" -q Quiet mode\n");
exit(-1);
}
my $optlist = "qna";
my $optlist = "qnaP:";
my $impotent = 0;
my $quiet = 0;
my $doall = 0;
my $doallpid;
#
# Configure variables
......@@ -84,6 +87,7 @@ use emutil;
use Node;
use OSImage;
use User;
use Project;
#
# Parse command arguments. Once we return from getopts, all that should be
......@@ -99,13 +103,21 @@ if (defined($options{"n"})) {
if (defined($options{"q"})) {
$quiet = 1;
}
if (defined($options{"P"})) {
if ($options{"P"} =~ /^([-\w]+)$/) {
$doallpid = $1;
} else {
fatal("Invalid project name for -P");
}
if (!Project->Lookup($doallpid)) {
fatal("No such project '$doallpid'");
}
}
if (defined($options{"a"})) {
$doall = 1;
# XXX for now
$impotent = 1;
}
usage()
if (!$doall && @ARGV != 1);
if (!$doall && !$doallpid && @ARGV != 1);
sub ConvertImage($)
{
......@@ -117,7 +129,8 @@ sub ConvertImage($)
}
my @images = ();
if ($image->AllVersions(\@images)) {
fatal("Could not get list of image (versions)");
print STDERR "Could not get list of (versions) for $image\n";
return -1;
}
my $newpath = dirname($image->path()) . "/" . $image->imagename() . "/";
if (-e $newpath && -f $newpath) {
......@@ -144,7 +157,7 @@ sub ConvertImage($)
$gid = $project->unix_gid();
my $user = User->Lookup($image->creator_idx());
if (!defined($project)) {
if (!defined($user)) {
print STDERR "No creator for image\n";
return -1;
}
......@@ -228,25 +241,52 @@ sub ConvertImage($)
}
}
if ($doall) {
my @images = OSImage->ListAll(undef, undef);
if ($doall || $doallpid) {
my @images = OSImage->ListAll(undef, $doallpid);
my %lastactive = ();
if ($WITHZFS && $ZFS_NOEXPORT) {
#
# Have to force the new directories to be exported.
# See ZFS code in exports_setup
#
my %projs = ();
foreach my $imagename (@images) {
my $image = OSImage->Lookup($imagename);
# XXX OSImage->Lookup blows up on old multi-partition images
my $image = Image->Lookup($imagename);
if ($image && $image->ezid()) {
$image = OSImage->Lookup($imagename);
}
my $project = $image->GetProject();
$project->BumpActivity();
if (!exists($projs{$project->pid()})) {
$projs{$project->pid()} = $project;
}
}
foreach my $pname (keys %projs) {
if (! -d "$PROJROOT/$pname/images") {
my $project = $projs{$pname};
$lastactive{$pname}{'obj'} = $project;
$lastactive{$pname}{'last'} = $project->GetActivity();
if (!$impotent) {
$project->BumpActivity();
}
}
}
if (keys(%lastactive) > 0) {
my $activate = int(keys %lastactive);
print STDERR "Found $activate inactive projects, activating ...\n";
if (!$impotent) {
system($EXPORTSSETUP) == 0 or
fatal("$EXPORTSSETUP failed");
}
}
system($EXPORTSSETUP) == 0 or
fatal("$EXPORTSSETUP failed");
}
foreach my $imagename (@images) {
my $image = OSImage->Lookup($imagename);
# XXX OSImage->Lookup blows up on old multi-partition images
my $image = Image->Lookup($imagename);
if ($image && $image->ezid()) {
$image = OSImage->Lookup($imagename);
}
next
if (!defined($image->path()));
......@@ -258,12 +298,29 @@ if ($doall) {
# There is some lag before the automounter can mount the new volume.
#
if (emutil::waitForMount("$PROJROOT/$pid") < 0) {
fatal("Could not access $PROJROOT/$pid");
print STDERR "Could not access $PROJROOT/$pid, ignoring\n";
next;
}
}
print "--> $image\n";
ConvertImage($image);
}
# Restore last legit activity timestamp for otherwise inactive projects
if ($WITHZFS && $ZFS_NOEXPORT && keys(%lastactive) > 0) {
print STDERR "Restoring last activity stamps ...\n";
foreach my $pname (keys %lastactive) {
my $project = $lastactive{$pname}{'obj'};
my $last = $lastactive{$pname}{'last'};
if (!$impotent) {
$project->SetActivity($last);
}
}
if (!$impotent) {
system($EXPORTSSETUP) == 0 or
fatal("$EXPORTSSETUP failed");
}
}
}
else {
my $image = OSImage->Lookup($ARGV[0]);
......
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