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

Add -r option to remove existing cached images.

parent eea2d6de
......@@ -36,16 +36,19 @@ my $TAR = "/bin/tar";
sub usage()
{
print STDERR "Usage: mkimagecache [-c | -t count] [-s size] <imagename>\n";
print STDERR " mkimagecache -r <imagename>\n";
print STDERR "options:\n";
print STDERR " -c count - Create count\n";
print STDERR " -t count - Create as many as needed to reach count\n";
print STDERR " -s size - Size of lvm in GB, if no base lvm to look at\n";
print STDERR " -r - Remove all cached images\n";
exit(-1);
}
my $optlist = "c:s:t:";
my $optlist = "c:s:t:r";
my $count = 1;
my $total = 0;
my $size = 0;
my $clear = 0;
#
# Turn off line buffering on output
......@@ -77,6 +80,9 @@ if (defined($options{"t"})) {
if (defined($options{"s"})) {
$size = $options{"s"};
}
if (defined($options{"r"})) {
$clear = 1;
}
my $imagename = $ARGV[0];
# See libvnode_openvz ...
my $imagelockpath = "/var/emulab/db/openvz.image.$imagename.ready";
......@@ -89,6 +95,27 @@ if ((my $locked = TBScriptLock($imagelockname,
die("Could not get the $imagelockname lock after a long time!\n");
}
#
# Look for existing cache files.
#
my @files = glob("/dev/openvz/_C_${imagename}_*");
my $idx = 0;
#
# Delete all existing cache files.
#
if ($clear) {
foreach my $file (@files) {
system("lvremove -f $file");
if ($?) {
TBScriptUnlock();
exit(1);
}
}
TBScriptUnlock();
exit(0);
}
#
# Need the base size for copy.
#
......@@ -109,12 +136,6 @@ else {
usage();
}
#
# Look for existing cache files and skip those.
#
my @files = glob("/dev/openvz/_C_${imagename}_*");
my $idx = 0;
while ($count > 0) {
if (grep {$_ eq "/dev/openvz/_C_${imagename}_${idx}"} @files) {
$count--
......
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