From 34595f863cf29f18f1ccd2a149ddcf9977dfe352 Mon Sep 17 00:00:00 2001 From: Mike Hibler Date: Thu, 23 Jan 2014 09:39:35 -0700 Subject: [PATCH] Handle read-only iSCSI disks: mount them RO if they have a mountpoint. --- clientside/tmcc/common/config/rc.storage | 14 ++++++++++-- clientside/tmcc/freebsd/liblocstorage.pm | 28 +++++++++++++++++++----- clientside/tmcc/linux/liblocstorage.pm | 27 ++++++++++++++++++----- 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/clientside/tmcc/common/config/rc.storage b/clientside/tmcc/common/config/rc.storage index a982d1410..34b8b77d9 100644 --- a/clientside/tmcc/common/config/rc.storage +++ b/clientside/tmcc/common/config/rc.storage @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# Copyright (c) 2004-2013 University of Utah and the Flux Group. +# Copyright (c) 2004-2014 University of Utah and the Flux Group. # # {{{EMULAB-LICENSE # @@ -405,6 +405,9 @@ sub process($$$$) if (!exists($href->{'PERSIST'})) { $href->{'PERSIST'} = 0; } + if (!exists($href->{'PERMS'})) { + $href->{'PERMS'} = "RW"; + } } elsif ($class eq "local") { if ($href->{'HOSTID'} ne "localhost" || @@ -528,6 +531,9 @@ sub process($$$$) if ($href->{'PERSIST'}) { $msg .= " persistent"; } + if ($href->{'PERMS'} eq "RO") { + $msg .= " read-only"; + } print " $msg iSCSI node attached as $dev"; } } @@ -537,7 +543,11 @@ sub process($$$$) } } if ($href->{'MOUNTPOINT'}) { - print " mounted on " . $href->{'MOUNTPOINT'}; + my $w = "RW"; + if ($href->{'PERMS'} eq "RO") { + $w = "RO"; + } + print " mounted $w on " . $href->{'MOUNTPOINT'}; } print "\n"; } else { diff --git a/clientside/tmcc/freebsd/liblocstorage.pm b/clientside/tmcc/freebsd/liblocstorage.pm index 69142f862..d2100ce6b 100644 --- a/clientside/tmcc/freebsd/liblocstorage.pm +++ b/clientside/tmcc/freebsd/liblocstorage.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 # @@ -912,18 +912,26 @@ sub os_check_storage_element($$) if ($mpoint) { my $line = `$MOUNT | grep '^/dev/$dev on '`; if (!$line) { + my $mopt = ""; + my $fopt = "-p"; + + # check for RO export and adjust options accordingly + if (exists($href->{'PERMS'}) && $href->{'PERMS'} eq "RO") { + $mopt = "-o ro"; + $fopt = "-n"; + } + # the mountpoint should exist if (! -d "$mpoint") { warn("*** $bsid: no mount point $mpoint\n"); return -1; } # fsck it in case of an abrupt shutdown - if (mysystem("$FSCK -t ufs -p /dev/$dev $redir")) { + if (mysystem("$FSCK $fopt -t ufs /dev/$dev $redir")) { warn("*** $bsid: fsck of /dev/$dev failed\n"); return -1; } - # and mount it - if (mysystem("$MOUNT -t ufs /dev/$dev $mpoint $redir")) { + if (mysystem("$MOUNT $mopt -t ufs /dev/$dev $mpoint $redir")) { warn("*** $bsid: could not mount /dev/$dev on $mpoint\n"); return -1; } @@ -1098,6 +1106,9 @@ sub os_create_storage($$) return 0; } + my $mopt = ""; + my $fopt = "-p"; + if (exists($href->{'MOUNTPOINT'}) && !exists($href->{'MOUNTED'})) { my $lv = $href->{'VOLNAME'}; my $mdev = $href->{'LVDEV'}; @@ -1117,7 +1128,12 @@ sub os_create_storage($$) # if ($href->{'CLASS'} eq "SAN" && $href->{'PROTO'} eq "iSCSI" && $href->{'PERSIST'} != 0) { - if (mysystem("$FSCK -t ufs -p $mdev $redir")) { + # check for RO export and adjust options accordingly + if (exists($href->{'PERMS'}) && $href->{'PERMS'} eq "RO") { + $mopt = "-o ro"; + $fopt = "-n"; + } + if (mysystem("$FSCK $fopt -t ufs $mdev $redir")) { warn("*** $lv: fsck of persistent store $mdev failed\n"); return 0; } @@ -1158,7 +1174,7 @@ sub os_create_storage($$) return 0; } } else { - if (mysystem("$MOUNT -t ufs $mdev $mpoint $redir")) { + if (mysystem("$MOUNT $mopt -t ufs $mdev $mpoint $redir")) { warn("*** $lv: could not mount $mdev on $mpoint$logmsg\n"); return 0; } diff --git a/clientside/tmcc/linux/liblocstorage.pm b/clientside/tmcc/linux/liblocstorage.pm index e862b0258..78cfee2b7 100644 --- a/clientside/tmcc/linux/liblocstorage.pm +++ b/clientside/tmcc/linux/liblocstorage.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 # @@ -610,17 +610,26 @@ sub os_check_storage_element($$) if ($mpoint) { my $line = `$MOUNT | grep '^/dev/$dev on '`; if (!$line) { + my $mopt = ""; + my $fopt = "-p"; + + # check for RO export and adjust options accordingly + if (exists($href->{'PERMS'}) && $href->{'PERMS'} eq "RO") { + $mopt = "-o ro"; + $fopt = "-n"; + } + # the mountpoint should exist if (! -d "$mpoint") { warn("*** $bsid: no mount point $mpoint\n"); return -1; } # fsck it in case of an abrupt shutdown - if (mysystem("$FSCK -p /dev/$dev $redir")) { + if (mysystem("$FSCK $fopt /dev/$dev $redir")) { warn("*** $bsid: fsck of /dev/$dev failed\n"); return -1; } - if (mysystem("$MOUNT /dev/$dev $mpoint $redir")) { + if (mysystem("$MOUNT $mopt /dev/$dev $mpoint $redir")) { warn("*** $bsid: could not mount /dev/$dev on $mpoint\n"); return -1; } @@ -789,6 +798,9 @@ sub os_create_storage($$) return 0; } + my $mopt = ""; + my $fopt = "-p"; + if (exists($href->{'MOUNTPOINT'})) { my $lv = $href->{'VOLNAME'}; my $mdev = $href->{'LVDEV'}; @@ -808,6 +820,11 @@ sub os_create_storage($$) # if ($href->{'CLASS'} eq "SAN" && $href->{'PROTO'} eq "iSCSI" && $href->{'PERSIST'} != 0) { + # check for RO export and adjust options accordingly + if (exists($href->{'PERMS'}) && $href->{'PERMS'} eq "RO") { + $mopt = "-o ro"; + $fopt = "-n"; + } # figure out what the fstype is $fstype = `blkid -s TYPE -o value $mdev`; chomp($fstype); @@ -818,7 +835,7 @@ sub os_create_storage($$) $fstype = "ext4"; } - if (mysystem("$FSCK -p $mdev $redir")) { + if (mysystem("$FSCK $fopt $mdev $redir")) { warn("*** $lv: fsck of persistent store $mdev failed\n"); return 0; } @@ -880,7 +897,7 @@ sub os_create_storage($$) return 0; } } else { - if (mysystem("$MOUNT -t $fstype $mdev $mpoint $redir")) { + if (mysystem("$MOUNT $mopt -t $fstype $mdev $mpoint $redir")) { warn("*** $lv: could not mount $mdev on $mpoint$logmsg\n"); return 0; } -- GitLab