From b131b34262d3526c8c099633be82acb27d4dced0 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Fri, 11 Nov 2011 13:56:32 +0100 Subject: [PATCH 01/31] empty repository From a049329467d3e01cfc53dab50a61136f0da91583 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Mon, 14 Nov 2011 14:17:32 +0100 Subject: [PATCH 02/31] added tag to help keep original /etc/export entries.. --- Makefile | 17 ++++ mxmount | 240 ++++++++++++++++++++++++++++++++++++++++++++++++ mxmount.service | 11 +++ 3 files changed, 268 insertions(+) create mode 100644 Makefile create mode 100755 mxmount create mode 100644 mxmount.service diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1d3bd58 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ + +PREFIX=/usr +BINDIR=/usr/bin +SYSCONFDIR=/etc +SYSTEMDSYSTEMDIR=${SYSCONFDIR}/systemd/system + +DESTDIR= + +clean: + +all: + +install: + install -d -m 0755 ${DESTDIR}${BINDIR} + install -m 0755 mxmount ${DESTDIR}${BINDIR} + install -d -m 0755 ${DESTDIR}${SYSTEMDSYSTEMDIR} + install -m 0644 mxmount.service ${DESTDIR}${SYSTEMDSYSTEMDIR} diff --git a/mxmount b/mxmount new file mode 100755 index 0000000..87c66d9 --- /dev/null +++ b/mxmount @@ -0,0 +1,240 @@ +#!/usr/bin/perl + +use Sys::Hostname; +use Data::Dumper; +use Socket; + +######################################## + +my $configfile="/etc/mxmounts"; +my $exports="/etc/exports"; + +######################################## + +my $tag = "# DO NOT EDIT BELOW THIS LINE # created by /usr/bin/mxmount #"; + +my $fullhostname, $hostname; +my @lines,@exports; +my %V, %D; + +$fullhostname = hostname(); +($hostname) = $fullhostname =~ /^(.*?)\./; + +%D = (); +%V = ( + DEFAULT_MOUNT_FS => '', + DEFAULT_MOUNT_OPTIONS => '', + DEFAULT_EXPORT_OPTIONS => '', + DEFAULT_MOUNT_PREFIX => '/', + + SHORTHOST => $hostname, + FULLHOST => $fullhostname, + + NONE => '', + NULL => '' +); + +@lines = read_file($configfile); +@exports = read_file_raw($exports); + +@lines = parse_variables(@lines); + +@lines = parse_data(@lines); + +foreach(@lines) { + print STDERR "skipping: '$_'\n"; +} + +#print Dumper \%D; + +mount_all(); +create_exports(); + +system(exportfs -ra); + +sub create_exports { + my $allmp = $D{$hostname}; + my @CMD; + + open(EXPORTS, '>', $exports) or die "can't open $exports: $!"; + + foreach my $exp (@exports) { + chomp($exp); + next if($exp =~ /^\s*$/); + last if($exp eq $tag); + print EXPORTS "$exp\n"; + } + + print EXPORTS "\n$tag\n\n# auch du nicht, donald 8)\n\n"; + + foreach my $mp (@$allmp) { + next if($mp->{noexport}); + @CMD = ($mp->{mountpoint}, $mp->{exportopts}); + + print join " ", "$exports: ", @CMD, "\n"; + print EXPORTS join " ", @CMD, "\n"; + + } + + close EXPORTS; +} + + +sub mount_all { + my $allmp = $D{$hostname}; + my @CMD; + foreach my $mp (sort { $a->{mountpoint} <=> $b->{mountpoint} } @$allmp) { + + @CMD = (); + + push @CMD, 'mount', "LABEL=$mp->{label}", $mp->{mountpoint}; + + if($mp->{fs}) { + push @CMD, '-t', $mp->{fs}; + } + if($mp->{mountopts}) { + push @CMD, '-o', $mp->{mountopts}; + } + system('mkdir','-p',$mp->{mountpoint}); + print STDERR join " ", @CMD, "\n"; + system(@CMD); + } +} + +sub parse_data { + my @lines = @_; + my @invalid = (); + my @data; + + my $rest; + + foreach(@lines) { + @data = split /\s+/, $_; + + unless($data[1]) { + push @invalid, $_; + next; + } + + my $D = {}; + + $D->{line} = $_; + + $D->{host} = $data[0]; + + + $D->{label} = $data[1]; + if($D->{label} =~ /^!(.*)/) { + $D->{noexport} = 1; + $D->{label} = $1; + } + + if($D->{label} =~ /(.*):(.*)/) { + $D->{label} = $1; + $D->{mountpoint} = $2; + } else { + if($D->{label} =~ /^X/) { + $D->{mountpoint} = 'X/' . $D->{label}; + $D->{label} = lc($D->{label}); + } else { + $D->{mountpoint} = $D->{label}; + } + } + if($D->{mountpoint} !~ m(^\/)) { + $D->{mountpoint} = "$V{DEFAULT_MOUNT_PREFIX}/" . $D->{mountpoint}; + } + + $D->{fs} = 'auto'; + $D->{mountopts} = $data[2] ? $data[2] : $V{DEFAULT_MOUNT_OPTIONS}; + if($D->{mountopts} =~ /\[(.*)\](.*)/) { + $D->{fs} = $1; + $D->{mountopts} = $2; + } + + $D->{exportopts} = $data[3] ? $data[3] : $V{DEFAULT_EXPORT_OPTIONS}; + + foreach(qw(host label mountpoint fs mountopts exportopts )) { + $D->{$_} = expand_variables($D->{$_}); + } + + + push @{$D{$D->{host}}}, $D; + } + return @invalid; +} + +sub expand_variables { + my $s = shift; + + foreach my $k (keys %V) { + $s =~ s/$k/$V{$k}/g; + } + + return $s; +} + + +sub parse_variables { + my @lines = @_; + my @invalid = (); + + my $key, $value; + + foreach(@lines) { + if(($key, $value) = /^(\S+)=\s*(.*)$/) { + $V{$key} = $value; + } else { + push @invalid,expand_variables($_); + } + } + return @invalid; +} + +sub read_file { + my $file = shift; + open F, "$file" or die "can't open $file: $!\n"; + + my @lines=(); + my $line=""; + my $cont=0; + + while() { + chomp; + next if(/^\s*#/ or /^\s*$/); + + $cont=0; + + s/#.*$//; # remove comments.. + + $_ = $line . $_; + + if(s/\\\s*$//) { + # line continous in next line.. + $cont=1; + } + + $line = $_; + + unless($cont) { + $line =~ s/\s+/ /g; + $line =~ s/^\s+//; + $line =~ s/\s+$//; + push @lines, $line; + $line=""; + } + } + + close F; + return @lines; +} + +sub read_file_raw { + my $file = shift; + my @lines; + + open F, "$file" or return; + @lines = ; + close F; + + return @lines; +} diff --git a/mxmount.service b/mxmount.service new file mode 100644 index 0000000..2409b49 --- /dev/null +++ b/mxmount.service @@ -0,0 +1,11 @@ +[Unit] +Description=MX mount local data filessystems +ConditionPathExists=/etc/mxmounts + +[Service] +Type=oneshot +ExecStart=/usr/bin/mxmount +RemainAfterExit=yes + +[Install] +WantedBy=local-fs.target From 37bf7324b284c2ea060d75c396c5e947ec7a316c Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Fri, 18 Nov 2011 10:04:48 +0100 Subject: [PATCH 03/31] code style fixes --- mxmount | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mxmount b/mxmount index 87c66d9..125c00c 100755 --- a/mxmount +++ b/mxmount @@ -22,10 +22,10 @@ $fullhostname = hostname(); %D = (); %V = ( - DEFAULT_MOUNT_FS => '', - DEFAULT_MOUNT_OPTIONS => '', + DEFAULT_MOUNT_FS => '', + DEFAULT_MOUNT_OPTIONS => '', DEFAULT_EXPORT_OPTIONS => '', - DEFAULT_MOUNT_PREFIX => '/', + DEFAULT_MOUNT_PREFIX => '/', SHORTHOST => $hostname, FULLHOST => $fullhostname, From 42b6e12e59cb38a74f2096464c76195bdf78f963 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 21 Dec 2011 16:06:16 +0100 Subject: [PATCH 04/31] add a new shortlabel format for dataX to mount at PREFIX/X --- mxmount | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mxmount b/mxmount index 125c00c..6f0cb8f 100755 --- a/mxmount +++ b/mxmount @@ -136,8 +136,11 @@ sub parse_data { if($D->{label} =~ /^X/) { $D->{mountpoint} = 'X/' . $D->{label}; $D->{label} = lc($D->{label}); + } elsif($D->{label} =~ /^data(.*)/) { + $D->{mountpoint} = $1; } else { - $D->{mountpoint} = $D->{label}; + warn "mxmount: unknown shortlabel '$D->{label}'.. skipping.."; + next; } } if($D->{mountpoint} !~ m(^\/)) { From 61ae4cc3d571a4ec9e7f57d9e024122f61d83c02 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 5 Jun 2012 13:47:40 +0200 Subject: [PATCH 05/31] Add default, not exported data0 for every host missing a data0 entry --- mxmount | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mxmount b/mxmount index 6f0cb8f..f16d13a 100755 --- a/mxmount +++ b/mxmount @@ -47,11 +47,28 @@ foreach(@lines) { #print Dumper \%D; +add_data0_if_not_present(); + mount_all(); create_exports(); system(exportfs -ra); +sub add_data0_if_not_present { + my $allmp = $D{$hostname}; + + foreach my $mp (sort { $a->{mountpoint} <=> $b->{mountpoint} } @$allmp ) { + if ($mp->{label} eq "data0") { + return; + } + } + + # print "no data0 found\n"; + parse_data("$hostname !data0"); + # print Dumper $D{$hostname}; +} + + sub create_exports { my $allmp = $D{$hostname}; my @CMD; From 2bfcf5d1a9c8584893560701fb67097b2520c013 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 14 Feb 2013 13:37:10 +0100 Subject: [PATCH 06/31] add support for confidential jbods --- mxmount | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxmount b/mxmount index f16d13a..b27a336 100755 --- a/mxmount +++ b/mxmount @@ -153,6 +153,10 @@ sub parse_data { if($D->{label} =~ /^X/) { $D->{mountpoint} = 'X/' . $D->{label}; $D->{label} = lc($D->{label}); + } elsif($D->{label} =~ /^C/) { + $D->{mountpoint} = 'C/' . $D->{label}; + $D->{label} = lc($D->{label}); + $D->{noexport} = 1; } elsif($D->{label} =~ /^data(.*)/) { $D->{mountpoint} = $1; } else { From 02aec9841bb3bd15384d896c83d97b6a1803ac1c Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Mon, 27 May 2013 10:54:40 +0200 Subject: [PATCH 07/31] fix minor bug.. *hust* this is a workaround for a stupid perl bug... *HUST* --- mxmount | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxmount b/mxmount index b27a336..7409276 100755 --- a/mxmount +++ b/mxmount @@ -52,7 +52,7 @@ add_data0_if_not_present(); mount_all(); create_exports(); -system(exportfs -ra); +system("exportfs -ra"); sub add_data0_if_not_present { my $allmp = $D{$hostname}; From 258a2a800e78658bee79897439505bd97546e70c Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Mon, 27 May 2013 11:07:27 +0200 Subject: [PATCH 08/31] fix some perl warnings --- mxmount | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mxmount b/mxmount index 7409276..8c7ded2 100755 --- a/mxmount +++ b/mxmount @@ -4,18 +4,23 @@ use Sys::Hostname; use Data::Dumper; use Socket; +use warnings; + ######################################## -my $configfile="/etc/mxmounts"; -my $exports="/etc/exports"; +my $configfile = "/etc/mxmounts"; +my $exports = "/etc/exports"; ######################################## my $tag = "# DO NOT EDIT BELOW THIS LINE # created by /usr/bin/mxmount #"; -my $fullhostname, $hostname; -my @lines,@exports; -my %V, %D; +my $fullhostname; +my $hostname; +my @lines; +my @exports; +my %V; +my %D; $fullhostname = hostname(); ($hostname) = $fullhostname =~ /^(.*?)\./; @@ -100,7 +105,7 @@ sub create_exports { sub mount_all { my $allmp = $D{$hostname}; my @CMD; - foreach my $mp (sort { $a->{mountpoint} <=> $b->{mountpoint} } @$allmp) { + foreach my $mp (sort { $a->{mountpoint} cmp $b->{mountpoint} } @$allmp) { @CMD = (); @@ -202,7 +207,7 @@ sub parse_variables { my @lines = @_; my @invalid = (); - my $key, $value; + my ($key, $value); foreach(@lines) { if(($key, $value) = /^(\S+)=\s*(.*)$/) { From 4ade260daaf2b2de5d029a4a4bccb759ca3946eb Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 28 May 2013 14:43:14 +0200 Subject: [PATCH 09/31] fix more warnings.. --- mxmount | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxmount b/mxmount index 8c7ded2..0f29f30 100755 --- a/mxmount +++ b/mxmount @@ -62,7 +62,7 @@ system("exportfs -ra"); sub add_data0_if_not_present { my $allmp = $D{$hostname}; - foreach my $mp (sort { $a->{mountpoint} <=> $b->{mountpoint} } @$allmp ) { + foreach my $mp (sort { $a->{mountpoint} cmp $b->{mountpoint} } @$allmp ) { if ($mp->{label} eq "data0") { return; } From 72599067b81b8a2a3c132353d840ab2a8e4b91df Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 16 Jun 2015 14:54:07 +0200 Subject: [PATCH 10/31] mxmount: Allow export of C0000 Jbods if exportopts are set e.g. acedia C4014 defaults,inode64 @confidential(sync,rw,no_root_squash,no_subtree_check,insecure_locks) --- mxmount | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mxmount b/mxmount index 0f29f30..d3db82b 100755 --- a/mxmount +++ b/mxmount @@ -161,7 +161,9 @@ sub parse_data { } elsif($D->{label} =~ /^C/) { $D->{mountpoint} = 'C/' . $D->{label}; $D->{label} = lc($D->{label}); - $D->{noexport} = 1; + if (!$data[3]) { + $D->{noexport} = 1; + } } elsif($D->{label} =~ /^data(.*)/) { $D->{mountpoint} = $1; } else { From a0a1b72500fe8b412dc6b0fd46dd335b62e91ac7 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 16 Jun 2015 16:09:46 +0200 Subject: [PATCH 11/31] mxmount: Fix undefined array usage --- mxmount | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mxmount b/mxmount index d3db82b..6a24eec 100755 --- a/mxmount +++ b/mxmount @@ -62,6 +62,8 @@ system("exportfs -ra"); sub add_data0_if_not_present { my $allmp = $D{$hostname}; + $allmp = [] unless (defined $allmp); + foreach my $mp (sort { $a->{mountpoint} cmp $b->{mountpoint} } @$allmp ) { if ($mp->{label} eq "data0") { return; From 6c9441e1051ff31893f93ab8405e6825d3d5f243 Mon Sep 17 00:00:00 2001 From: "root@pappnase /dev/pts/3 141.14.28.170" Date: Tue, 23 Aug 2016 13:02:32 +0200 Subject: [PATCH 12/31] fix data0 destination overmount when /amd/hostname/0 is already a destination from another partition skipp adding !data0. this happened when booting from mxonastick. --- mxmount | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxmount b/mxmount index 6a24eec..3cb1b66 100755 --- a/mxmount +++ b/mxmount @@ -68,6 +68,10 @@ sub add_data0_if_not_present { if ($mp->{label} eq "data0") { return; } + if ($mp->{mountpoint} eq "$V{DEFAULT_MOUNT_PREFIX}/$hostname/0") { + print STDERR "$mp->{mountpoint} already blocked by $mp->{label}\n"; + return; + } } # print "no data0 found\n"; From f3f825be736ca7eb774cf48ed9d15d38d340a872 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 16 Feb 2017 10:48:57 +0100 Subject: [PATCH 13/31] mxmount: removed some whitespace clutter --- mxmount | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/mxmount b/mxmount index 3cb1b66..5c7213e 100755 --- a/mxmount +++ b/mxmount @@ -31,7 +31,7 @@ $fullhostname = hostname(); DEFAULT_MOUNT_OPTIONS => '', DEFAULT_EXPORT_OPTIONS => '', DEFAULT_MOUNT_PREFIX => '/', - + SHORTHOST => $hostname, FULLHOST => $fullhostname, @@ -98,12 +98,12 @@ sub create_exports { foreach my $mp (@$allmp) { next if($mp->{noexport}); @CMD = ($mp->{mountpoint}, $mp->{exportopts}); - + print join " ", "$exports: ", @CMD, "\n"; print EXPORTS join " ", @CMD, "\n"; - + } - + close EXPORTS; } @@ -112,11 +112,11 @@ sub mount_all { my $allmp = $D{$hostname}; my @CMD; foreach my $mp (sort { $a->{mountpoint} cmp $b->{mountpoint} } @$allmp) { - + @CMD = (); - + push @CMD, 'mount', "LABEL=$mp->{label}", $mp->{mountpoint}; - + if($mp->{fs}) { push @CMD, '-t', $mp->{fs}; } @@ -133,7 +133,7 @@ sub parse_data { my @lines = @_; my @invalid = (); my @data; - + my $rest; foreach(@lines) { @@ -145,7 +145,7 @@ sub parse_data { } my $D = {}; - + $D->{line} = $_; $D->{host} = $data[0]; @@ -156,7 +156,7 @@ sub parse_data { $D->{noexport} = 1; $D->{label} = $1; } - + if($D->{label} =~ /(.*):(.*)/) { $D->{label} = $1; $D->{mountpoint} = $2; @@ -189,11 +189,11 @@ sub parse_data { } $D->{exportopts} = $data[3] ? $data[3] : $V{DEFAULT_EXPORT_OPTIONS}; - + foreach(qw(host label mountpoint fs mountopts exportopts )) { $D->{$_} = expand_variables($D->{$_}); } - + push @{$D{$D->{host}}}, $D; } @@ -202,11 +202,11 @@ sub parse_data { sub expand_variables { my $s = shift; - + foreach my $k (keys %V) { $s =~ s/$k/$V{$k}/g; } - + return $s; } @@ -238,13 +238,13 @@ sub read_file { while() { chomp; next if(/^\s*#/ or /^\s*$/); - + $cont=0; - + s/#.*$//; # remove comments.. - + $_ = $line . $_; - + if(s/\\\s*$//) { # line continous in next line.. $cont=1; @@ -260,7 +260,7 @@ sub read_file { $line=""; } } - + close F; return @lines; } From 2937a002ea7b3e52fafbaec5d57bb3bba93e607a Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 16 Feb 2017 11:08:44 +0100 Subject: [PATCH 14/31] mxmount: renamed tag to exportstag, removed the funny note for donald Changes should help reading the code. --- mxmount | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mxmount b/mxmount index 5c7213e..4e57625 100755 --- a/mxmount +++ b/mxmount @@ -13,7 +13,7 @@ my $exports = "/etc/exports"; ######################################## -my $tag = "# DO NOT EDIT BELOW THIS LINE # created by /usr/bin/mxmount #"; +my $exportstag = "# DO NOT EDIT BELOW THIS LINE # created by /usr/bin/mxmount #"; my $fullhostname; my $hostname; @@ -89,11 +89,11 @@ sub create_exports { foreach my $exp (@exports) { chomp($exp); next if($exp =~ /^\s*$/); - last if($exp eq $tag); + last if($exp eq $exportstag); print EXPORTS "$exp\n"; } - print EXPORTS "\n$tag\n\n# auch du nicht, donald 8)\n\n"; + print EXPORTS "\n$exportstag\n\n"; foreach my $mp (@$allmp) { next if($mp->{noexport}); From 6e04723b8045b939d6ef94c1856a438e2721bfe7 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 16 Feb 2017 11:20:00 +0100 Subject: [PATCH 15/31] mxmount: added mount option for M-labels --- mxmount | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxmount b/mxmount index 4e57625..736da0f 100755 --- a/mxmount +++ b/mxmount @@ -170,6 +170,9 @@ sub parse_data { if (!$data[3]) { $D->{noexport} = 1; } + } elsif($D->{label} =~ /^M/) { + $D->{mountpoint} = 'M/' . $D->{label}; + $D->{label} = lc($D->{label}); } elsif($D->{label} =~ /^data(.*)/) { $D->{mountpoint} = $1; } else { From 3eabfd1cf7431cd3c92cc480b49d5829f5788f89 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 16 Feb 2017 11:21:53 +0100 Subject: [PATCH 16/31] mxmount: commented the various raid labels --- mxmount | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mxmount b/mxmount index 736da0f..887a1e3 100755 --- a/mxmount +++ b/mxmount @@ -161,16 +161,16 @@ sub parse_data { $D->{label} = $1; $D->{mountpoint} = $2; } else { - if($D->{label} =~ /^X/) { + if($D->{label} =~ /^X/) { # X: decent controller based raid $D->{mountpoint} = 'X/' . $D->{label}; $D->{label} = lc($D->{label}); - } elsif($D->{label} =~ /^C/) { + } elsif($D->{label} =~ /^C/) { # C: controller based raid, confidential $D->{mountpoint} = 'C/' . $D->{label}; $D->{label} = lc($D->{label}); if (!$data[3]) { $D->{noexport} = 1; } - } elsif($D->{label} =~ /^M/) { + } elsif($D->{label} =~ /^M/) { # M: decent software raid (mdadm) $D->{mountpoint} = 'M/' . $D->{label}; $D->{label} = lc($D->{label}); } elsif($D->{label} =~ /^data(.*)/) { From 57306a0c7f5ca7ed4fde23d0bdbf433738d5afb9 Mon Sep 17 00:00:00 2001 From: Peter Marquardt Date: Tue, 5 Sep 2017 16:35:15 +0200 Subject: [PATCH 17/31] mxmount: add mdadm --assemble to allow detectable /dev/mdx's to be mounted. --- mxmount | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxmount b/mxmount index 887a1e3..2a2e05d 100755 --- a/mxmount +++ b/mxmount @@ -53,7 +53,7 @@ foreach(@lines) { #print Dumper \%D; add_data0_if_not_present(); - +system("mdadm --assemble --scan --config=partition"); mount_all(); create_exports(); From 23f7937d6b0a4a9ac0cbb7521bfe82ac40d97ee9 Mon Sep 17 00:00:00 2001 From: thomas Date: Mon, 11 Sep 2017 16:51:58 +0200 Subject: [PATCH 18/31] mxmount: add --no-degraded to mdadm --assemble This assembles but does not start degraded arrays. --- mxmount | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxmount b/mxmount index 2a2e05d..22324c2 100755 --- a/mxmount +++ b/mxmount @@ -53,7 +53,7 @@ foreach(@lines) { #print Dumper \%D; add_data0_if_not_present(); -system("mdadm --assemble --scan --config=partition"); +system("mdadm --assemble --scan --config=partition --no-degraded"); mount_all(); create_exports(); From 64b067517ed4dd66688ce1464ae5c8cbaca485a8 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Tue, 19 Sep 2017 19:26:36 +0200 Subject: [PATCH 19/31] mxmount: Remove whitespace on blank line --- mxmount | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxmount b/mxmount index 22324c2..40a223b 100755 --- a/mxmount +++ b/mxmount @@ -149,7 +149,7 @@ sub parse_data { $D->{line} = $_; $D->{host} = $data[0]; - + $D->{label} = $data[1]; if($D->{label} =~ /^!(.*)/) { From 0b0c45a2452ddfea93c9b05d6eeb3712235aef88 Mon Sep 17 00:00:00 2001 From: thomas Date: Mon, 12 Feb 2018 11:38:46 +0100 Subject: [PATCH 20/31] Run mxmount after mxraid assembly phase. --- mxmount.service | 1 + 1 file changed, 1 insertion(+) diff --git a/mxmount.service b/mxmount.service index 2409b49..6434001 100644 --- a/mxmount.service +++ b/mxmount.service @@ -1,5 +1,6 @@ [Unit] Description=MX mount local data filessystems +After=mxraid.startup.service ConditionPathExists=/etc/mxmounts [Service] From 28c7f011f800a51e650628895c47cb80391feb85 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 15 Feb 2018 12:45:17 +0100 Subject: [PATCH 21/31] mxmount: remove mdadm --assemble assembly is now done via mxtools/mxraid, before mxmount is called. --- mxmount | 1 - 1 file changed, 1 deletion(-) diff --git a/mxmount b/mxmount index 40a223b..740bf13 100755 --- a/mxmount +++ b/mxmount @@ -53,7 +53,6 @@ foreach(@lines) { #print Dumper \%D; add_data0_if_not_present(); -system("mdadm --assemble --scan --config=partition --no-degraded"); mount_all(); create_exports(); From 2879b1700fecb269c59761870b4520f9c62f6e49 Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 14 Mar 2018 16:18:33 +0100 Subject: [PATCH 22/31] Introduce D label prefix for scratch raids Rationale: SW-RAIDs are assembled by serials, Serials are kept in a database, thus they need a uniqe label. Since this applies also for level-0 scratch raids, and a clash with decent SW-RAIDs (M-prefix) is unwanted, they get the D-prefix. --- mxmount | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxmount b/mxmount index 740bf13..9ea675c 100755 --- a/mxmount +++ b/mxmount @@ -169,6 +169,9 @@ sub parse_data { if (!$data[3]) { $D->{noexport} = 1; } + } elsif($D->{label} =~ /^D/) { # D: scratch software raid (mdadm) + $D->{mountpoint} = 'D/' . $D->{label}; + $D->{label} = lc($D->{label}); } elsif($D->{label} =~ /^M/) { # M: decent software raid (mdadm) $D->{mountpoint} = 'M/' . $D->{label}; $D->{label} = lc($D->{label}); From b935396cdf3bc69fa17f0db046c4a1420328198e Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 19 Nov 2018 11:22:13 +0100 Subject: [PATCH 23/31] mxmount: install.sh: Add mxmount Import mxmount into mxtools install.sh script and remove the imported and now ununsed mxmount/Makefile. --- install.sh | 2 ++ mxmount/Makefile | 17 ----------------- 2 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 mxmount/Makefile diff --git a/install.sh b/install.sh index 9bdf6e0..fcbf487 100755 --- a/install.sh +++ b/install.sh @@ -127,4 +127,6 @@ install_data clusterd/clusterd.service "$DESTDIR$systemdunitdi install_exec clusterd/clusterd "$DESTDIR$usr_sbindir/clusterd" install_exec setuid/setuid "$DESTDIR$usr_sbindir/setuid" install_exec uvpn/uvpn "$DESTDIR$usr_bindir/uvpn" +install_exec mxmount/mxmount "$DESTDIR$usr_bindir/mxmount" +install_data mxmount/mxmount.service "$DESTDIR$systemdunitdir/mxmount.service" exit diff --git a/mxmount/Makefile b/mxmount/Makefile deleted file mode 100644 index 1d3bd58..0000000 --- a/mxmount/Makefile +++ /dev/null @@ -1,17 +0,0 @@ - -PREFIX=/usr -BINDIR=/usr/bin -SYSCONFDIR=/etc -SYSTEMDSYSTEMDIR=${SYSCONFDIR}/systemd/system - -DESTDIR= - -clean: - -all: - -install: - install -d -m 0755 ${DESTDIR}${BINDIR} - install -m 0755 mxmount ${DESTDIR}${BINDIR} - install -d -m 0755 ${DESTDIR}${SYSTEMDSYSTEMDIR} - install -m 0644 mxmount.service ${DESTDIR}${SYSTEMDSYSTEMDIR} From 635eede32fb23809eba5b51f580b43ee3423f06f Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 19 Nov 2018 11:40:13 +0100 Subject: [PATCH 24/31] mxmount: Remove unused variables DEFAULT_MOUNT_FS,FULLHOST,NONE,NULL are never used. Remove unused variables. Note, that SHORTHOST is currently used by /etc/mxmounts. --- mxmount/mxmount | 5 ----- 1 file changed, 5 deletions(-) diff --git a/mxmount/mxmount b/mxmount/mxmount index 9ea675c..0a4c366 100755 --- a/mxmount/mxmount +++ b/mxmount/mxmount @@ -27,16 +27,11 @@ $fullhostname = hostname(); %D = (); %V = ( - DEFAULT_MOUNT_FS => '', DEFAULT_MOUNT_OPTIONS => '', DEFAULT_EXPORT_OPTIONS => '', DEFAULT_MOUNT_PREFIX => '/', SHORTHOST => $hostname, - FULLHOST => $fullhostname, - - NONE => '', - NULL => '' ); @lines = read_file($configfile); From 1d9bd5d0ceeb64e2a7410a4a5dd37887a0d18c9d Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 19 Nov 2018 11:49:44 +0100 Subject: [PATCH 25/31] mxmount: Remove some lines which don't have a function --- mxmount/mxmount | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/mxmount/mxmount b/mxmount/mxmount index 0a4c366..44ec7e5 100755 --- a/mxmount/mxmount +++ b/mxmount/mxmount @@ -1,18 +1,11 @@ #!/usr/bin/perl use Sys::Hostname; -use Data::Dumper; -use Socket; - use warnings; -######################################## - my $configfile = "/etc/mxmounts"; my $exports = "/etc/exports"; -######################################## - my $exportstag = "# DO NOT EDIT BELOW THIS LINE # created by /usr/bin/mxmount #"; my $fullhostname; @@ -45,8 +38,6 @@ foreach(@lines) { print STDERR "skipping: '$_'\n"; } -#print Dumper \%D; - add_data0_if_not_present(); mount_all(); create_exports(); @@ -67,13 +58,9 @@ sub add_data0_if_not_present { return; } } - - # print "no data0 found\n"; parse_data("$hostname !data0"); - # print Dumper $D{$hostname}; } - sub create_exports { my $allmp = $D{$hostname}; my @CMD; @@ -86,7 +73,6 @@ sub create_exports { last if($exp eq $exportstag); print EXPORTS "$exp\n"; } - print EXPORTS "\n$exportstag\n\n"; foreach my $mp (@$allmp) { @@ -97,11 +83,9 @@ sub create_exports { print EXPORTS join " ", @CMD, "\n"; } - close EXPORTS; } - sub mount_all { my $allmp = $D{$hostname}; my @CMD; @@ -143,8 +127,6 @@ sub parse_data { $D->{line} = $_; $D->{host} = $data[0]; - - $D->{label} = $data[1]; if($D->{label} =~ /^!(.*)/) { $D->{noexport} = 1; @@ -193,8 +175,6 @@ sub parse_data { foreach(qw(host label mountpoint fs mountopts exportopts )) { $D->{$_} = expand_variables($D->{$_}); } - - push @{$D{$D->{host}}}, $D; } return @invalid; @@ -206,11 +186,9 @@ sub expand_variables { foreach my $k (keys %V) { $s =~ s/$k/$V{$k}/g; } - return $s; } - sub parse_variables { my @lines = @_; my @invalid = (); @@ -260,7 +238,6 @@ sub read_file { $line=""; } } - close F; return @lines; } From c2626f3fe4129bbe9c3b2bb99f2dfd5ab5453568 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 19 Nov 2018 13:09:21 +0100 Subject: [PATCH 26/31] mxmount: Add "use strict" --- mxmount/mxmount | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mxmount/mxmount b/mxmount/mxmount index 44ec7e5..47d69d6 100755 --- a/mxmount/mxmount +++ b/mxmount/mxmount @@ -1,7 +1,8 @@ #!/usr/bin/perl -use Sys::Hostname; +use strict; use warnings; +use Sys::Hostname; my $configfile = "/etc/mxmounts"; my $exports = "/etc/exports"; From 3822b7bf653c59a0a0d1fe437b5b13081abcb155 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 19 Nov 2018 14:21:59 +0100 Subject: [PATCH 27/31] mxmount: Expand host groups by hostconfig When /etc/mxmounts uses the netgroup syntax to export to a list of clients (usually @amd), expand the list using hostconfig to a list of hosts from inside this mxmount, so that we no longer export to NIS netgroups. This is one step to get rid of NIS. Only hosts with the tag newexport should do it for now, so that we can see if there are problems before switching all hosts. We could expand /filesystem @group(opts) to /filesystem host1(opts) hosts2(opts) host3(opts) host4(opts)... but because our opts are about 50 characters and we have about 540 hosts on @amd, we save about 27000 characters per line by converting to /filesystem -opts host1 host2 host3... Notes: * `hostconfig --list` does not only accept single tag (=group) names, but complex boolean expressions as well. We could export to @1 (=allways true, any known host) or @testing&!desktop. It is suggested, not to use this as a feature. --- mxmount/mxmount | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/mxmount/mxmount b/mxmount/mxmount index 47d69d6..ed7d2ae 100755 --- a/mxmount/mxmount +++ b/mxmount/mxmount @@ -64,7 +64,7 @@ sub add_data0_if_not_present { sub create_exports { my $allmp = $D{$hostname}; - my @CMD; + my $newexport=system('hostconfig newexport')==0; open(EXPORTS, '>', $exports) or die "can't open $exports: $!"; @@ -78,11 +78,24 @@ sub create_exports { foreach my $mp (@$allmp) { next if($mp->{noexport}); - @CMD = ($mp->{mountpoint}, $mp->{exportopts}); - - print join " ", "$exports: ", @CMD, "\n"; - print EXPORTS join " ", @CMD, "\n"; - + unless ($newexport) { + my @CMD = ($mp->{mountpoint}, $mp->{exportopts}); + print join " ", "$exports: ", @CMD, "\n"; + print EXPORTS join " ", @CMD, "\n"; + } else { + my ($mountpoint,$exportopts)=($mp->{mountpoint}, $mp->{exportopts}); # '/amd/theinternet/1','@amd(sync,rw,...)' + my ($hostspec,$optspec)=$exportopts=~/^([^(]+)(.*)/; # '@amd','(sync,rw,...)' + my ($opts)=$optspec=~/\((.*)\)/; # 'sync,rw,...' + my $hosts=''; + warn "export $mountpoint to $hostspec opts $opts\n"; + if (my ($group) = $hostspec=~/^@(.+)/) { + $hosts=`hostconfig --list $group`; # expanded group + $hosts or warn "group $group is empty\n"; + } else { + $hosts=$hostspec; # single host + } + $hosts and printf EXPORTS "%s -%s %s\n",$mountpoint,$opts,$hosts; + } } close EXPORTS; } From 846af5bcc35e8594eb5f6e2878d0c507fa29a546 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 19 Nov 2018 14:53:53 +0100 Subject: [PATCH 28/31] mxmount: Use safer version of qx The perl qx operator (`cmd`) calls a shell when cmd contains shell metacharacters. If our netgroup (accidentally) contains a shell meta character, unexpected things might happen. Replace by safer code. --- mxmount/mxmount | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mxmount/mxmount b/mxmount/mxmount index ed7d2ae..70ebfce 100755 --- a/mxmount/mxmount +++ b/mxmount/mxmount @@ -45,6 +45,8 @@ create_exports(); system("exportfs -ra"); +sub safe_qx { open my $pipe,'-|',@_; return join('',<$pipe>) } + sub add_data0_if_not_present { my $allmp = $D{$hostname}; @@ -89,7 +91,7 @@ sub create_exports { my $hosts=''; warn "export $mountpoint to $hostspec opts $opts\n"; if (my ($group) = $hostspec=~/^@(.+)/) { - $hosts=`hostconfig --list $group`; # expanded group + $hosts=safe_qx('/usr/sbin/hostconfig','--list',$group); # expanded group $hosts or warn "group $group is empty\n"; } else { $hosts=$hostspec; # single host From c515e79ad380c0cdf35cb3f05c6afb439b8a7ab8 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 19 Nov 2018 14:59:15 +0100 Subject: [PATCH 29/31] mxmount: Use /usr/local/system/perl/bin/perl We might transfer /usr/bin/perl to a /pkg package in the future as we did with python. mxmount needs to be able to run before the automounter is available. Update perl path to /usr/local/system/perl/bin/perl, which is always available. --- mxmount/mxmount | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxmount/mxmount b/mxmount/mxmount index 70ebfce..9f897b2 100755 --- a/mxmount/mxmount +++ b/mxmount/mxmount @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#! /usr/local/system/perl/bin/perl use strict; use warnings; From 24b66dcf3dbac9d15f6f2f6c1d8379e66bfda78a Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 22 Nov 2018 12:25:43 +0100 Subject: [PATCH 30/31] mxmount: Add option --reexport-only Calling mxmount with --reexport-only will not try to mount filesystems, but just rewrite /etc/exports and call exportfs -ra. This is supposed to be done by clusterd, when the export groups in /etc/hostconfig were changed. --- mxmount/mxmount | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mxmount/mxmount b/mxmount/mxmount index 9f897b2..11e3056 100755 --- a/mxmount/mxmount +++ b/mxmount/mxmount @@ -3,6 +3,7 @@ use strict; use warnings; use Sys::Hostname; +use Getopt::Long; my $configfile = "/etc/mxmounts"; my $exports = "/etc/exports"; @@ -16,6 +17,13 @@ my @exports; my %V; my %D; +our $USAGE=<<"_EOF_"; +usage: $0 + $0 --reexport-only +_EOF_ + +our ($opt_reexport_only); + $fullhostname = hostname(); ($hostname) = $fullhostname =~ /^(.*?)\./; @@ -40,9 +48,15 @@ foreach(@lines) { } add_data0_if_not_present(); -mount_all(); -create_exports(); +my %options; +GetOptions ( + 'reexport-only' => \$opt_reexport_only, +) or die $USAGE; +@ARGV and die $USAGE; + +mount_all() unless $opt_reexport_only; +create_exports(); system("exportfs -ra"); sub safe_qx { open my $pipe,'-|',@_; return join('',<$pipe>) } From d5cf90d3dc411f412ddec22bd65d2bd0d17f0cd4 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 22 Nov 2018 13:47:38 +0100 Subject: [PATCH 31/31] clusterd: add --reexport `clusterd --reexport` triggers all clusterd daemons to run `mxmount --reexport-only`. This should be done, when the export groups in hostconfig were updated. --- clusterd/clusterd | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clusterd/clusterd b/clusterd/clusterd index 510cfb7..fe40fef 100755 --- a/clusterd/clusterd +++ b/clusterd/clusterd @@ -579,6 +579,7 @@ our %UDP_HANDLER= 'restart' => \&udp_rx_restart, 'flush-gidcache' => \&udp_rx_flush_gidcache, 'make-automaps' => \&udp_rx_make_automaps, + 'reexport' => \&udp_rx_reexport, 'log' => \&udp_rx_log, 'exec' => \&udp_rx_exec, 'push' => \&udp_rx_push, @@ -1089,6 +1090,10 @@ sub udp_rx_make_automaps { system '/sbin/make-automaps'; } +sub udp_rx_reexport { + system '/usr/bin/mxmount --reexport-only'; +} + #----------- tcp mgmt console ----------------------------- our $MGMT_PORT=234; @@ -1824,6 +1829,7 @@ usage: $0 [options] --exec @node cmd [args...] # execute cmd on node --flush-gidcache # flush rpc auth.unix.gid cache on all nodes --make-automaps # execute /usr/sbin/make-automaps on all nodes + --reexport # execute /usr/bin/mxmount --reexport-only on all nodes --lsof=pattern @@ -1851,6 +1857,7 @@ GetOptions 'send-restart' => \$options{'send-restart'}, 'flush-gidcache' => \$options{'flush-gidcache'}, 'make-automaps' => \$options{'make-automaps'}, + 'reexport' => \$options{'reexport'}, 'lsof=s' => \$options{'lsof'}, ) or die USAGE; @@ -1885,6 +1892,10 @@ if (defined $options{'push'}) { sync_cluster_pw() or die "$CLUSTER_PW_FILE: $!\n"; $donald_s=new My::Select::INET(Proto=>'udp') or die "$!\n"; udp_broadcast_message($donald_s,'make-automaps'); +} elsif (defined $options{'reexport'}) { + sync_cluster_pw() or die "$CLUSTER_PW_FILE: $!\n"; + $donald_s=new My::Select::INET(Proto=>'udp') or die "$!\n"; + udp_broadcast_message($donald_s,'reexport'); } elsif (defined $options{'daemon'}) { $options{'kill'} and Donald::Tools::kill_previous_server('clusterd') and sleep 2;