Commit 76117dbb authored by Mike Hibler's avatar Mike Hibler

Support creation of a filesystem when creating a block store.

Can do ext[234] or ufs.
parent 7e4a26d6
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# Copyright (c) 2013 University of Utah and the Flux Group. # Copyright (c) 2013-2014 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -37,8 +37,8 @@ sub usage() ...@@ -37,8 +37,8 @@ sub usage()
print STDERR "commands:\n"; print STDERR "commands:\n";
print STDERR " pools Print size info about pools\n"; print STDERR " pools Print size info about pools\n";
print STDERR " volumes Print info about volumes\n"; print STDERR " volumes Print info about volumes\n";
print STDERR " create <pool> <vol> <size>\n"; print STDERR " create <pool> <vol> <size> [ <fstype> ]\n";
print STDERR " Create <vol> in <pool> with <size> in MiB\n"; print STDERR " Create <vol> in <pool> with <size> in MiB; optionally create a filesystem of type <fstype> on it\n";
print STDERR " destroy <pool> <vol>\n"; print STDERR " destroy <pool> <vol>\n";
print STDERR " Destroy <vol> in <pool>\n"; print STDERR " Destroy <vol> in <pool>\n";
exit(-1); exit(-1);
...@@ -132,9 +132,9 @@ sub volumes() ...@@ -132,9 +132,9 @@ sub volumes()
return 0; return 0;
} }
sub create($$$) sub create($$$;$)
{ {
my ($pool,$vol,$size) = @_; my ($pool,$vol,$size,$fstype) = @_;
if (defined($pool) && $pool =~ /^([-\w]+)$/) { if (defined($pool) && $pool =~ /^([-\w]+)$/) {
$pool = $1; $pool = $1;
...@@ -154,8 +154,21 @@ sub create($$$) ...@@ -154,8 +154,21 @@ sub create($$$)
print STDERR "bscontrol_proxy: bogus size arg\n"; print STDERR "bscontrol_proxy: bogus size arg\n";
return 1; return 1;
} }
if (!defined($fstype)) {
$fstype = "none";
} elsif ($fstype =~ /^(ext2|ext3|ext4|ufs)$/) {
$fstype = $1;
} else {
print STDERR "bscontrol_proxy: bogus fstype arg\n";
return 1;
}
my $rv = freenasVolumeCreate($pool, $vol, $size);
if ($rv == 0 && $fstype ne "none") {
$rv = freenasFSCreate($pool, $vol, $fstype);
}
return freenasVolumeCreate($pool, $vol, $size); return $rv;
} }
sub destroy($$$) sub destroy($$$)
......
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# Copyright (c) 2013 University of Utah and the Flux Group. # Copyright (c) 2013-2014 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -31,7 +31,7 @@ use Exporter; ...@@ -31,7 +31,7 @@ use Exporter;
@EXPORT = @EXPORT =
qw( qw(
freenasPoolList freenasVolumeList freenasPoolList freenasVolumeList
freenasVolumeCreate freenasVolumeDestroy freenasVolumeCreate freenasVolumeDestroy freenasFSCreate
freenasRunCmd freenasParseListing freenasRunCmd freenasParseListing
$FREENAS_CLI_VERB_IFACE $FREENAS_CLI_VERB_IST_EXTENT $FREENAS_CLI_VERB_IFACE $FREENAS_CLI_VERB_IST_EXTENT
$FREENAS_CLI_VERB_IST_AUTHI $FREENAS_CLI_VERB_IST_TARGET $FREENAS_CLI_VERB_IST_AUTHI $FREENAS_CLI_VERB_IST_TARGET
...@@ -84,6 +84,8 @@ my $VOLUME_BUSY_WAIT = 10; ...@@ -84,6 +84,8 @@ my $VOLUME_BUSY_WAIT = 10;
my $VOLUME_GONE_WAIT = 5; my $VOLUME_GONE_WAIT = 5;
my $IFCONFIG = "/sbin/ifconfig"; my $IFCONFIG = "/sbin/ifconfig";
my $ALIASMASK = "255.255.255.255"; my $ALIASMASK = "255.255.255.255";
my $LINUX_MKFS = "/usr/local/sbin/mke2fs";
my $FBSD_MKFS = "/sbin/newfs";
# storageconfig constants # storageconfig constants
# XXX: should go somewhere more general # XXX: should go somewhere more general
...@@ -114,6 +116,7 @@ sub freenasPoolList(); ...@@ -114,6 +116,7 @@ sub freenasPoolList();
sub freenasVolumeList($); sub freenasVolumeList($);
sub freenasVolumeCreate($$$); sub freenasVolumeCreate($$$);
sub freenasVolumeDestroy($$); sub freenasVolumeDestroy($$);
sub freenasFSCreate($$$);
sub freenasRunCmd($$); sub freenasRunCmd($$);
sub freenasParseListing($); sub freenasParseListing($);
...@@ -367,6 +370,27 @@ sub freenasParseListing($) { ...@@ -367,6 +370,27 @@ sub freenasParseListing($) {
return @retlist; return @retlist;
} }
sub freenasFSCreate($$$) {
my ($pool,$vol,$fstype) = @_;
my $cmd;
if ($fstype =~ /^ext[234]$/) {
$cmd = "$LINUX_MKFS -t $fstype -o Linux";
} elsif ($fstype eq "ufs") {
$cmd = "$FBSD_MKFS";
} else {
warn("*** WARNING: freenasFSCreate: unknown fs type '$fstype'");
return -1;
}
my $redir = ">/dev/null 2>&1";
if (system("$cmd /dev/zvol/$pool/$vol $redir") != 0) {
warn("*** WARNING: freenasFSCreate: '$cmd /dev/zvol/$pool/$vol' failed");
return -1;
}
return 0;
}
####################################################################### #######################################################################
# package-local functions # package-local functions
# #
......
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