Commit 85cb6895 authored by Mike Hibler's avatar Mike Hibler

Handle the upcoming PERSIST=(0|1) attribute in storageconfig.

We need to know if a blockstore is persistent so we can avoid blindly
doing a mkfs on those!
parent a479c52f
......@@ -105,16 +105,22 @@ SWITCH: for ($action) {
#
# XXX this should be docleanup(3), but we have not implemented
# the nasty temporary removal of LVM/ZFS/etc state from the
# imageable filesystems.
# imageable filesystems for local blockstores.
#
# So for now we just do a shutdown. This will do the right thing
# for SAN-based blockstores which only use traditional filesystem
# mounts (i.e., no volume manager) and thus have no local disk
# state (as SAN mounts do not appear in /etc/fstab).
#
# It is also the right thing for the local SYSVOL case in which
# you want the blockstore to be included in the image.
#
# So for now we just do a shutdown. This is correct in the SYSVOL
# case where you want that blockstore to be included in the image.
# It is not correct for other blockstores, where you will get
# partial state in the image (e.g., in /etc/lvm or /etc/zfs).
#
# The moral is: if you are going to do a custom image, you should
# only create a SYSVOL blockstore and you should take a whole-disk
# image!
# only use persistent SAN-based blockstores or create a SYSVOL local
# blockstore and take a whole-disk image!
#
docleanup(0);
last SWITCH;
......@@ -396,7 +402,9 @@ sub process($$$$)
warn("*** Invalid iSCSI target name '".$href->{'UUID'}."'\n");
return 0;
}
if (!exists($href->{'PERSIST'})) {
$href->{'PERSIST'} = 0;
}
}
elsif ($class eq "local") {
if ($href->{'HOSTID'} ne "localhost" ||
......@@ -452,7 +460,12 @@ sub process($$$$)
my $msg;
if ($href->{'CLASS'} eq "SAN" && $href->{'PROTO'} eq "iSCSI") {
$msg = "iSCSI node";
if ($href->{'PERSIST'}) {
$msg = "persistent ";
} else {
$msg = "";
}
$msg .= "iSCSI node";
} elsif ($href->{'CLASS'} eq "local") {
$msg = "local disk";
}
......@@ -511,7 +524,11 @@ sub process($$$$)
if ($href->{'CMD'} eq "ELEMENT") {
if ($href->{'CLASS'} eq "SAN" && $href->{'PROTO'} eq "iSCSI") {
print " $vname: iSCSI node attached as $dev";
my $msg = "$vname:";
if ($href->{'PERSIST'}) {
$msg .= " persistent";
}
print " $msg iSCSI node attached as $dev";
}
}
elsif ($href->{'CMD'} eq "SLICE") {
......
......@@ -3384,6 +3384,8 @@ sub getarpinfo($;$)
# \d+ -- size in mebibytes. Informational; could be used for sanity checking.
# PERMS :=
# (RO|RW) -- i.e., read-only or read-write.
# PERSIST :=
# (0|1) -- 1 if this is a persistent (across swapins) storage element.
#
# if CLASS=="local" :
# IDX :=
......@@ -3448,6 +3450,7 @@ sub getstorageconfig($;$) {
'HOSTID' => '[-\w\.]+',
'MOUNTPOINT' => '\/[-\w\/\.]+',
'PERMS' => '(RO|RW)',
'PERSIST' => '(0|1)',
'PROTO' => '(iSCSI|local|SCSI|SAS|SATA|PATA|IDE)',
'UUID' => '[-\w\.:]+',
'UUID_TYPE'=> '(iqn|serial)',
......
......@@ -918,7 +918,7 @@ sub os_check_storage_element($$)
return -1;
}
# fsck it in case of an abrupt shutdown
if (mysystem("$FSCK -p /dev/$dev $redir")) {
if (mysystem("$FSCK -t ufs -p /dev/$dev $redir")) {
warn("*** $bsid: fsck of /dev/$dev failed\n");
return -1;
}
......@@ -1111,9 +1111,21 @@ sub os_create_storage($$)
}
#
# Create the filesystem
# If this is a persistent iSCSI disk, we never create the filesystem!
# Instead, we fsck it in case it was not shutdown cleanly in its
# previous existence.
#
if (mysystem("$MKFS -b $UFSBS $mdev $redir")) {
if ($href->{'CLASS'} eq "SAN" && $href->{'PROTO'} eq "iSCSI" &&
$href->{'PERSIST'} != 0) {
if (mysystem("$FSCK -t ufs -p $mdev $redir")) {
warn("*** $lv: fsck of persistent store $mdev failed\n");
return 0;
}
}
#
# Otherwise, create the filesystem
#
elsif (mysystem("$MKFS -b $UFSBS $mdev $redir")) {
warn("*** $lv: could not create FS$logmsg\n");
return 0;
}
......
......@@ -772,6 +772,7 @@ sub os_check_storage_slice($$)
sub os_create_storage($$)
{
my ($so,$href) = @_;
my $fstype;
my $rv = 0;
# record all the output for debugging
......@@ -801,30 +802,54 @@ sub os_create_storage($$)
}
#
# Create the filesystem:
# If this is a persistent iSCSI disk, we never create the filesystem!
# Instead, we fsck it in case it was not shutdown cleanly in its
# previous existence.
#
if ($href->{'CLASS'} eq "SAN" && $href->{'PROTO'} eq "iSCSI" &&
$href->{'PERSIST'} != 0) {
# figure out what the fstype is
$fstype = `blkid -s TYPE -o value $mdev`;
chomp($fstype);
if ($fstype =~ /^(ext\d)$/) {
$fstype = $1;
} else {
warn("*** $lv: could not determine FS type for persistent store on $mdev, assuming ext4\n");
$fstype = "ext4";
}
if (mysystem("$FSCK -p $mdev $redir")) {
warn("*** $lv: fsck of persistent store $mdev failed\n");
return 0;
}
}
#
# Otherwise, create the filesystem:
#
# Start by trying ext4 which is much faster when creating large FSes.
# Otherwise fall back on ext3 and then ext2.
#
my $failed = 1;
my $fstype;
my $fsopts = "-F -q";
if ($failed) {
$fstype = "ext4";
$fsopts .= " -E lazy_itable_init=1";
$failed = mysystem("$MKFS -t $fstype $fsopts $mdev $redir");
}
if ($failed) {
$fstype = "ext3";
$failed = mysystem("$MKFS -t $fstype $fsopts $mdev $redir");
}
if ($failed) {
$fstype = "ext2";
$failed = mysystem("$MKFS -t $fstype $fsopts $mdev $redir");
}
if ($failed) {
warn("*** $lv: could not create FS\n");
return 0;
else {
my $failed = 1;
my $fsopts = "-F -q";
if ($failed) {
$fstype = "ext4";
$fsopts .= " -E lazy_itable_init=1";
$failed = mysystem("$MKFS -t $fstype $fsopts $mdev $redir");
}
if ($failed) {
$fstype = "ext3";
$failed = mysystem("$MKFS -t $fstype $fsopts $mdev $redir");
}
if ($failed) {
$fstype = "ext2";
$failed = mysystem("$MKFS -t $fstype $fsopts $mdev $redir");
}
if ($failed) {
warn("*** $lv: could not create FS\n");
return 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