diff --git a/clientside/tmcc/freenas8/bscontrol.proxy.pl b/clientside/tmcc/freenas8/bscontrol.proxy.pl index c3f1d119fd823b6421ee2373bd0acf4e01784e9d..639202e0e2f29831151b9a5bc625f6a216eb0422 100644 --- a/clientside/tmcc/freenas8/bscontrol.proxy.pl +++ b/clientside/tmcc/freenas8/bscontrol.proxy.pl @@ -1,6 +1,6 @@ #!/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 # @@ -37,8 +37,8 @@ sub usage() print STDERR "commands:\n"; print STDERR " pools Print size info about pools\n"; print STDERR " volumes Print info about volumes\n"; - print STDERR " create \n"; - print STDERR " Create in with in MiB\n"; + print STDERR " create [ ]\n"; + print STDERR " Create in with in MiB; optionally create a filesystem of type on it\n"; print STDERR " destroy \n"; print STDERR " Destroy in \n"; exit(-1); @@ -132,9 +132,9 @@ sub volumes() return 0; } -sub create($$$) +sub create($$$;$) { - my ($pool,$vol,$size) = @_; + my ($pool,$vol,$size,$fstype) = @_; if (defined($pool) && $pool =~ /^([-\w]+)$/) { $pool = $1; @@ -154,8 +154,21 @@ sub create($$$) print STDERR "bscontrol_proxy: bogus size arg\n"; 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($$$) diff --git a/clientside/tmcc/freenas8/libfreenas.pm b/clientside/tmcc/freenas8/libfreenas.pm index 1a955f5012e6a2fa1e10cdf6a541c6f25d00bc50..fa80db90db101a0162d9adae159412b45cbab205 100644 --- a/clientside/tmcc/freenas8/libfreenas.pm +++ b/clientside/tmcc/freenas8/libfreenas.pm @@ -1,6 +1,6 @@ #!/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 # @@ -31,7 +31,7 @@ use Exporter; @EXPORT = qw( freenasPoolList freenasVolumeList - freenasVolumeCreate freenasVolumeDestroy + freenasVolumeCreate freenasVolumeDestroy freenasFSCreate freenasRunCmd freenasParseListing $FREENAS_CLI_VERB_IFACE $FREENAS_CLI_VERB_IST_EXTENT $FREENAS_CLI_VERB_IST_AUTHI $FREENAS_CLI_VERB_IST_TARGET @@ -84,6 +84,8 @@ my $VOLUME_BUSY_WAIT = 10; my $VOLUME_GONE_WAIT = 5; my $IFCONFIG = "/sbin/ifconfig"; my $ALIASMASK = "255.255.255.255"; +my $LINUX_MKFS = "/usr/local/sbin/mke2fs"; +my $FBSD_MKFS = "/sbin/newfs"; # storageconfig constants # XXX: should go somewhere more general @@ -114,6 +116,7 @@ sub freenasPoolList(); sub freenasVolumeList($); sub freenasVolumeCreate($$$); sub freenasVolumeDestroy($$); +sub freenasFSCreate($$$); sub freenasRunCmd($$); sub freenasParseListing($); @@ -367,6 +370,27 @@ sub freenasParseListing($) { 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 #