Commit f6aa80c1 authored by Mike Hibler's avatar Mike Hibler

Add ability to create multiple LVM logical volumes in Linux mkextrafs.

Analogous to the -v vg1,vg2,... there is now a -m lv1,lv2,...
This is used by the disk-agent to pre-create multiple logical "disks."
parent 48a2c8f7
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2010 University of Utah and the Flux Group.
* Copyright (c) 2010-2012 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -175,7 +175,7 @@ void init_volumes(void)
* mkextrafs script which will create 10 logical volumes.
*/
cout << "Creating the disk partition ..." << endl;
cmd = "sudo /usr/testbed/bin/mymkextrafs -f -lM /mnt";
cmd = "sudo /usr/testbed/bin/mymkextrafs -q -l -m vol1,vol2,vol3,vol4,vol5,vol6,vol7,vol8,vol9,vol10";
int i = system(const_cast<char *>(cmd.c_str()));
if(i)
{
......@@ -1640,6 +1640,3 @@ start_callback(event_handle_t handle,
}
}
}
......@@ -18,10 +18,10 @@ sub mysystem($);
sub usage()
{
print("Usage: mkextrafs.pl [-f] [-s slice] [-lM] [-v <vglist>] <mountpoint>\n");
print("Usage: mkextrafs.pl [-fq] [-s slice] [-lM] [-v <vglist>] [-m <lvlist>] <mountpoint>\n");
exit(-1);
}
my $optlist = "fls:v:M";
my $optlist = "fqls:v:Mm:";
#
# Yep, hardwired for now. Should be options or queried via TMCC.
......@@ -31,9 +31,11 @@ my $slice = "4";
my $partition = "";
my $forceit = 0;
my $quiet = 0;
my $lvm = 0;
my @vglist = ();
my @lvlist = ();
my $lmonster = 0;
#
......@@ -60,6 +62,9 @@ if (! getopts($optlist, \%options)) {
if (defined($options{"f"})) {
$forceit = 1;
}
if (defined($options{"q"})) {
$quiet = 1;
}
if (defined($options{"s"})) {
$slice = $options{"s"};
}
......@@ -69,17 +74,28 @@ if (defined($options{"l"})) {
if (defined($options{"v"})) {
@vglist = split(/,/,$options{"v"});
}
if (defined($options{"m"})) {
@lvlist = split(/,/,$options{"m"});
}
if (defined($options{"M"})) {
$lmonster = 1;
if (scalar(@vglist)) {
if (@vglist > 1 || @lvlist > 1) {
die("*** $0:\n".
" If you want a single giant LVM-based filesystem, you can" .
" only specify a single volume group name!\n");
" only specify a single volume group and logical volume!\n");
}
}
if (scalar(@vglist) == 0) {
@vglist = ('emulab',);
}
if (scalar(@lvlist) == 0) {
@lvlist = ('emulab',);
}
if (@vglist > 1 && @lvlist > 1) {
die("*** $0:\n".
" You cannot specify multiple volume groups and logical volumes!\n");
}
my $mountpoint;
if (!$lvm || ($lvm && $lmonster)) {
if (@ARGV != 1) {
......@@ -104,22 +120,45 @@ if ($rootdev =~ /^\/dev\/([a-z]+)\d+\s+/) {
my $diskdev = "/dev/${disk}";
my $fsdevice = "${diskdev}${slice}";
#
# For LVM, just exit if the physical volume already exists
#
if ($lvm) {
my @out = `pvs --noheadings 2>&1`;
if (grep(/^\s+$fsdevice\s+/, @out)) {
if ($quiet) {
exit(0);
} else {
die("*** $0:\n".
" LVM physical volume already exists on $fsdevice\n");
}
}
}
#
# An existing fstab entry indicates we have already done this
# XXX override with forceit? Would require unmounting and removing from fstab.
#
if (!system("egrep -q -s '^${fsdevice}' /etc/fstab")) {
die("*** $0:\n".
" There is already an entry in /etc/fstab for $fsdevice\n");
if ($quiet) {
exit(0);
} else {
die("*** $0:\n".
" There is already an entry in /etc/fstab for $fsdevice\n");
}
}
#
# Likewise, if already mounted somewhere, fail
#
my $mounted = `mount | egrep '^${fsdevice}'`;
if ($mounted =~ /^${fsdevice} on (\S*)/) {
die("*** $0:\n".
" $fsdevice is already mounted on $1\n");
my $mounted = `mount | egrep '^$fsdevice'`;
if ($mounted =~ /^$fsdevice on (\S*)/) {
if ($quiet) {
exit(0);
} else {
die("*** $0:\n".
" $fsdevice is already mounted on $1\n");
}
}
my $stype = `sfdisk $diskdev -c $slice`;
......@@ -165,12 +204,16 @@ if ($lvm) {
}
}
if ($lmonster) {
if (system("lvcreate -n emulab -l 100\%VG $vglist[0]")) {
my $pct = int(100 / scalar(@lvlist));
foreach my $lv (@lvlist) {
if (system("lvcreate -n $lv -l ${pct}\%VG $vglist[0]")) {
die("*** $0:\n".
" 'lvcreate -n emulab -l 100\%VG $vglist[0]' failed!\n");
" 'lvcreate -n $lv -l ${pct}\%VG $vglist[0]' failed!\n");
}
$fsdevice = "/dev/$vglist[0]/emulab";
}
if ($lmonster) {
$fsdevice = "/dev/$vglist[0]/$lvlist[0]";
}
else {
exit(0);
......
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