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
#
# 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 <pool> <vol> <size>\n";
print STDERR " Create <vol> in <pool> with <size> in MiB\n";
print STDERR " create <pool> <vol> <size> [ <fstype> ]\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 <vol> in <pool>\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($$$)
......
#!/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
#
......
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