Commit 72dc3d90 authored by Mike Hibler's avatar Mike Hibler

Add the ability to put a filesystem on a persistent blockstore when created.

The -f <fstype> option to createdataset will now pre-initialize the dataset
with an empty filesystem. Supported types are: ufs and ext[234].
parent fec352d0
......@@ -539,13 +539,25 @@ sub AllocResources($;$) {
return LEASE_ERROR_FAILED();
}
#
# There may also be an associated fstype attribute.
# Note: we let caller or bscontrol do checking on the vaildity
# of the type.
#
my $fstype = $self->GetAttribute("fstype");
if (defined($fstype) && $fstype ne "") {
$fstype = "-f $fstype";
} else {
$fstype = "";
}
#
# Call the blockstore control program to handle all things
# blockstore related (e.g., the actual allocation of storage
# on the storage servers).
#
my $idx = $self->lease_idx();
if (system("$BSCONTROL -l $idx -s $size create lease-$idx")) {
if (system("$BSCONTROL -l $idx -s $size $fstype create lease-$idx")) {
print STDERR "$self: AllocResources: could not allocate storage.\n";
$self->UpdateState("unapproved");
return LEASE_ERROR_FAILED();
......
#!/usr/bin/perl -w
#
# Copyright (c) 2013 University of Utah and the Flux Group.
# Copyright (c) 2013-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -45,7 +45,7 @@ use Getopt::Std;
# The following commands are for persistent blockstores.
# For these, a blockstore name, "bsname", had better be unique.
#
# bscontrol [ -S server [ -P pool ] ] [-l leaseidx] -s size -t type create bsname
# bscontrol [ -S server [ -P pool ] ] [-l leaseidx] [-f fstype] -s size -t type create bsname
# Create a blockstore of the given size with the given name.
# If the server is not specified, we pick the "best" server,
# based on availability of space.
......@@ -70,13 +70,14 @@ sub usage()
print STDERR " info For each server, show all extant volumes\n";
exit(-1);
}
my $optlist = "hds:t:l:S:P:F";
my $optlist = "hds:t:l:S:P:Ff:";
my $debug = 0;
my $server;
my $pool;
my $size;
my $type = "stdataset";
my $leaseidx = 0;
my $fstype = "";
my $fakeit = 0;
# Protos
......@@ -171,6 +172,9 @@ if (defined($options{t})) {
if (defined($options{l})) {
$leaseidx = $options{l};
}
if (defined($options{f})) {
$fstype = $options{f};
}
if (defined($options{F})) {
$fakeit = 1;
}
......@@ -637,6 +641,13 @@ sub bs_create($$$@)
if ($leaseidx !~ /^\d+$/) {
fatal("create: lease index must be an integer");
}
if ($fstype) {
if ($fstype !~ /^(ext2|ext3|ext4|ufs)$/) {
fatal("create: fstype must be one of ext2|ext3|ext4|ufs");
} else {
$fstype = $1;
}
}
if ($type !~ /^(st|lt)dataset$/) {
fatal("create: type must be either 'stdataset' or 'ltdataset'");
}
......@@ -736,7 +747,7 @@ sub bs_create($$$@)
# Call out to the server to allocate the actual storage.
my $outref;
if (bsserver_cmd($srv, "$PROXYCMD create $pool $name $size", \$outref)) {
if (bsserver_cmd($srv, "$PROXYCMD create $pool $name $size $fstype", \$outref)) {
$pbstore->Delete();
print STDERR "*** create: could not allocate storage for '$name' on $srv/$pool:";
foreach my $str (@$outref) {
......
......@@ -31,19 +31,20 @@ use Date::Parse;
#
sub usage()
{
print STDERR "Usage: createdataset [-hdU] [-o uid] [-a attrs] [-t type] [-e expiration] -s size name\n";
print STDERR " -h This message\n";
print STDERR " -d Print additional debug info\n";
print STDERR " -U Create but do not approve; admin will need to approve later\n";
print STDERR " -s size Size in MiB\n";
print STDERR " -t type Type ('stdataset' or 'ltdataset')\n";
print STDERR " -o uid Owner (defaults to caller)\n";
print STDERR " -e date Expiration date (or 'never')\n";
print STDERR " -a attrs comma-seperated string of key=value attributes\n";
print STDERR " name Name (in the form <pid>/<id>)\n";
print STDERR "Usage: createdataset [-hdU] [-o uid] [-a attrs] [-t type] [-f fstype] [-e expiration] -s size name\n";
print STDERR " -h This message\n";
print STDERR " -d Print additional debug info\n";
print STDERR " -U Create but do not approve; admin will need to approve later\n";
print STDERR " -s size Size in MiB\n";
print STDERR " -t type Type ('stdataset' or 'ltdataset')\n";
print STDERR " -f fstype Type of filesystem to create on dataset (default is none)\n";
print STDERR " -o uid Owner (defaults to caller)\n";
print STDERR " -e date Expiration date (or 'never')\n";
print STDERR " -a attrs comma-seperated string of key=value attributes\n";
print STDERR " name Name (in the form <pid>/<id>)\n";
exit(-1);
}
my $optlist = "dhUo:s:t:e:a:";
my $optlist = "dhUo:s:t:e:a:f:";
my $debug = 0;
my $pid;
my $uid;
......@@ -51,6 +52,7 @@ my $expire;
my $dstype = "stdataset";
my $lname;
my $size;
my $fstype = "";
my $approveme = 1;
my $attrstr = "";
my %attrs = ();
......@@ -122,6 +124,12 @@ if (defined($options{s})) {
if (defined($options{t})) {
$dstype = $options{t};
}
if (defined($options{f})) {
$fstype = $options{f};
if ($fstype !~ /^(ext2|ext3|ext4|ufs)$/) {
fatal("FS type must be one of ext2, ext3, ext4, or ufs");
}
}
if (defined($options{e})) {
if ($options{e} eq "never") {
$expire = 0;
......@@ -271,8 +279,9 @@ if ($needapproval) {
#
foreach my $kv (split(',', $attrstr)) {
if ($kv =~ /^([-\w]+)=([-\w\.\+\/:]+)$/) {
# XXX filter out any size= attribute, we will re-add at the end.
if ($1 eq "size") {
# XXX filter out any attributes with explicit options,
# we will re-add those at the end.
if ($1 eq "size" || $1 eq "fstype") {
next;
}
$attrs{$1} = $2;
......@@ -281,6 +290,9 @@ foreach my $kv (split(',', $attrstr)) {
}
}
$attrs{'size'} = $size;
if ($fstype) {
$attrs{'fstype'} = $fstype;
}
#
# Check name: lease with this name must not already exist.
......
......@@ -55,7 +55,6 @@ sub fatal($);
# Configure variables
#
my $TB = "@prefix@";
my $BSCONTROL = "$TB/sbin/bscontrol";
#
# Testbed Support libraries
......
......@@ -5902,6 +5902,10 @@ class dataset:
argstr += " -t "
argstr += escapeshellarg(val)
pass
elif opt == "fstype":
argstr += " -f "
argstr += escapeshellarg(val)
pass
elif opt == "expire":
argstr += " -e "
argstr += escapeshellarg(val)
......
......@@ -2714,7 +2714,7 @@ class createdataset:
def apply(self):
try:
opts, req_args = getopt.getopt(self.argv, "hUs:t:e:", [ "help" ]);
opts, req_args = getopt.getopt(self.argv, "hUs:t:e:f:", [ "help" ]);
pass
except getopt.error, e:
print e.args[0]
......@@ -2735,6 +2735,9 @@ class createdataset:
elif opt == "-t":
params["type"] = val;
pass
elif opt == "-f":
params["fstype"] = val;
pass
elif opt == "-e":
params["expire"] = val;
pass
......@@ -2752,11 +2755,12 @@ class createdataset:
return rval;
def usage(self):
print "createdataset [-hU] [-t type] [-e expire] -s size dataset_id";
print "createdataset [-hU] [-t type] [-e expire] [-f fstype] -s size dataset_id";
print "where:";
print " -U - Create but do not approve dataset";
print " -s size - Size in MiB (1 MiB == 1024*1024)";
print " -t type - Type: one of 'stdataset' (default) or 'ltdataset'";
print " -f fstype - Filesystem type: one of 'ext2', 'ext3', 'ext4', 'ufs' (default is no filesystem creation)";
print " -e expire - Expiration date ('0' == never, default is system defined)";
print "";
print "Create a dataset with the indicated size and name";
......
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