| Line 138... |
Line 138... |
| 138 |
}
|
138 |
}
|
| 139 |
|
139 |
|
| 140 |
logMsg("mountDriveByLabel: Looking for drive with label '$driveInfo->{label}'");
|
140 |
logMsg("mountDriveByLabel: Looking for drive with label '$driveInfo->{label}'");
|
| 141 |
# default to /mnt/label if not provided
|
141 |
# default to /mnt/label if not provided
|
| 142 |
$driveInfo->{mountPath} //= "/mnt/$driveInfo->{label}"; # this is where we'll mount it if we find it
|
142 |
$driveInfo->{mountPath} //= "/mnt/$driveInfo->{label}"; # this is where we'll mount it if we find it
|
| 143 |
$driveInfo->{filesystem} //= 'ufs'; # default to mounting ufs
|
143 |
$driveInfo->{fstype} //= 'ufs'; # default to mounting ufs
|
| 144 |
# The location for the label depends on filesystem. Only providing access to ufs and msdos here for safety.
|
144 |
# The location for the label depends on filesystem. Only providing access to ufs and msdos here for safety.
|
| 145 |
# gpt labeled drives for ufs are in /dev/gpt/, for msdosfs in /dev/msdosfs/
|
145 |
# gpt labeled drives for ufs are in /dev/gpt/, for msdosfs in /dev/msdosfs/
|
| 146 |
$driveInfo->{label} = $driveInfo->{filesystem} eq 'msdos' ? "/dev/msdosfs/$driveInfo->{label}" : "/dev/gpt/$driveInfo->{label}";
|
146 |
my $labelPath = $driveInfo->{fstype} eq 'msdos' ? "/dev/msdosfs/$driveInfo->{label}" : "/dev/gpt/$driveInfo->{label}";
|
| 147 |
# drive already mounted, just return the path
|
147 |
# drive already mounted, just return the path
|
| 148 |
my $output = runCmd( "mount | grep '$driveInfo->{mountPath}'" );
|
148 |
my $output = runCmd( "mount | grep '$driveInfo->{mountPath}'" );
|
| 149 |
return $driveInfo->{mountPath} if ( $lastRunError == 0 ); # grep found it for us
|
149 |
return $driveInfo->{mountPath} if ( $lastRunError == 0 ); # grep found it for us
|
| 150 |
# default to 10 minutes (600 seconds) if not provided
|
150 |
# default to 10 minutes (600 seconds) if not provided
|
| 151 |
$driveInfo->{timeout} //= 600;
|
151 |
$driveInfo->{timeout} //= 600;
|
| 152 |
# default to checking every minute if not provided
|
152 |
# default to checking every minute if not provided
|
| 153 |
$driveInfo->{check_interval} //= 15;
|
153 |
$driveInfo->{check_interval} //= 15;
|
| 154 |
# wait up to $timeout seconds for device to appear, checking every 10 seconds
|
154 |
# wait up to $timeout seconds for device to appear, checking every 10 seconds
|
| 155 |
while ( $driveInfo->{timeout} > 0 ) {
|
155 |
while ( $driveInfo->{timeout} > 0 ) {
|
| 156 |
if ( -e "$driveInfo->{label}" ) {
|
156 |
if ( -e "$labelPath" ) {
|
| 157 |
last;
|
157 |
last;
|
| 158 |
} else {
|
158 |
} else {
|
| 159 |
print "Waiting for drive labeled $driveInfo->{label}\n";
|
159 |
print "Waiting for drive labeled $driveInfo->{label}, looking in $labelPath\n";
|
| 160 |
sleep $driveInfo->{check_interval};
|
160 |
sleep $driveInfo->{check_interval};
|
| 161 |
$driveInfo->{timeout} -= $driveInfo->{check_interval};
|
161 |
$driveInfo->{timeout} -= $driveInfo->{check_interval};
|
| 162 |
}
|
162 |
}
|
| 163 |
}
|
163 |
}
|
| 164 |
# if we found it, mount and return mount path
|
164 |
# if we found it, mount and return mount path
|
| 165 |
if ( -e "$driveInfo->{label}" ) {
|
165 |
if ( -e "$labelPath" ) {
|
| 166 |
# ensure mount point
|
166 |
# ensure mount point
|
| 167 |
unless ( -d $driveInfo->{mountPath} || make_path($driveInfo->{mountPath}) ) {
|
167 |
unless ( -d $driveInfo->{mountPath} || make_path($driveInfo->{mountPath}) ) {
|
| 168 |
logMsg("Failed to create $driveInfo->{mountPath}: $!");
|
168 |
logMsg("Failed to create $driveInfo->{mountPath}: $!");
|
| 169 |
return '';
|
169 |
return '';
|
| 170 |
}
|
170 |
}
|
| 171 |
# mount device
|
171 |
# mount device
|
| 172 |
runCmd( "mount -t $driveInfo->{filesystem} $driveInfo->{label} $driveInfo->{mountPath}" );
|
172 |
runCmd( "mount -t $driveInfo->{fstype} $labelPath $driveInfo->{mountPath}" );
|
| 173 |
if ( $lastRunError ) {
|
173 |
if ( $lastRunError ) {
|
| 174 |
logMsg("Failed to mount $driveInfo->{label} on $driveInfo->{mountPath}: $!");
|
174 |
logMsg("Failed to mount $labelPath on $driveInfo->{mountPath}: $!");
|
| 175 |
return '';
|
175 |
return '';
|
| 176 |
}
|
176 |
}
|
| 177 |
return $driveInfo->{mountPath};
|
177 |
return $driveInfo->{mountPath};
|
| 178 |
} else {
|
178 |
} else {
|
| 179 |
return '';
|
179 |
return '';
|
| Line 347... |
Line 347... |
| 347 |
$geliConfig->{'diskList'} //= [ findGeliDisks() ];
|
347 |
$geliConfig->{'diskList'} //= [ findGeliDisks() ];
|
| 348 |
|
348 |
|
| 349 |
my $diskList = $geliConfig->{'diskList'};
|
349 |
my $diskList = $geliConfig->{'diskList'};
|
| 350 |
my $poolname = $geliConfig->{'poolname'};
|
350 |
my $poolname = $geliConfig->{'poolname'};
|
| 351 |
my $keyfile = $geliConfig->{'target'};
|
351 |
my $keyfile = $geliConfig->{'target'};
|
| - |
|
352 |
|
| - |
|
353 |
# check if the pool already attached (grep returns 0 on found, something else on not)
|
| - |
|
354 |
runCmd( "zpool list -H -o name | grep $poolname" );
|
| - |
|
355 |
return $poolname unless $lastRunError;
|
| - |
|
356 |
|
| 352 |
unless ( -e $keyfile ) {
|
357 |
unless ( -e $keyfile ) {
|
| 353 |
logMsg "GELI keyfile $keyfile does not exist\n";
|
358 |
logMsg "GELI keyfile $keyfile does not exist\n";
|
| 354 |
return '';
|
359 |
return '';
|
| 355 |
}
|
360 |
}
|
| 356 |
|
361 |
|
| Line 643... |
Line 648... |
| 643 |
$logFile //= $reportConfig->{logFile};
|
648 |
$logFile //= $reportConfig->{logFile};
|
| 644 |
logMsg( "Beginning sendReport" );
|
649 |
logMsg( "Beginning sendReport" );
|
| 645 |
# if targetDrive defined and there is a valid label for it, try to mount it and write the report there
|
650 |
# if targetDrive defined and there is a valid label for it, try to mount it and write the report there
|
| 646 |
if ( defined $reportConfig->{targetDrive} && defined $reportConfig->{targetDrive}->{label} && $reportConfig->{targetDrive}->{label} ) {
|
651 |
if ( defined $reportConfig->{targetDrive} && defined $reportConfig->{targetDrive}->{label} && $reportConfig->{targetDrive}->{label} ) {
|
| 647 |
logMsg( "Saving report to disk with label $reportConfig->{targetDrive}->{label}" );
|
652 |
logMsg( "Saving report to disk with label $reportConfig->{targetDrive}->{label}" );
|
| 648 |
my $mountPoint = mountDriveByLabel( $reportConfig->{targetDrive}->{label}, $reportConfig->{targetDrive}->{mount_point}, 300 );
|
653 |
if ( $reportConfig->{targetDrive}->{mountPath} = mountDriveByLabel( $reportConfig->{targetDrive} ) ) {
|
| 649 |
if ( defined $mountPoint && $mountPoint ) {
|
- |
|
| 650 |
copyReportToDrive( $logFile, $mountPoint );
|
654 |
copyReportToDrive( $logFile, $reportConfig->{targetDrive}->{mountPath} );
|
| 651 |
`umount $mountPoint`;
|
655 |
unmountDriveByLabel( $reportConfig->{targetDrive} );
|
| 652 |
rmdir $mountPoint;
|
- |
|
| 653 |
} else {
|
656 |
} else {
|
| 654 |
logMsg( "Warning: could not mount report target drive with label '$reportConfig->{targetDrive}->{label}'" );
|
657 |
logMsg( "Warning: could not mount report target drive with label '$reportConfig->{targetDrive}->{label}'" );
|
| 655 |
}
|
658 |
}
|
| 656 |
}
|
659 |
}
|
| 657 |
# if they have set an e-mail address, try to e-mail the report
|
660 |
# if they have set an e-mail address, try to e-mail the report
|
| Line 671... |
Line 674... |
| 671 |
return unless defined $logFile && -e $logFile;
|
674 |
return unless defined $logFile && -e $logFile;
|
| 672 |
return unless defined $mountPoint && -d $mountPoint;
|
675 |
return unless defined $mountPoint && -d $mountPoint;
|
| 673 |
|
676 |
|
| 674 |
my $targetFile = "$mountPoint/" . ( split( /\//, $logFile ) )[-1];
|
677 |
my $targetFile = "$mountPoint/" . ( split( /\//, $logFile ) )[-1];
|
| 675 |
logMsg( "Copying report log file $logFile to drive at $mountPoint" );
|
678 |
logMsg( "Copying report log file $logFile to drive at $mountPoint" );
|
| - |
|
679 |
use File::Copy;
|
| 676 |
unless ( copy( $logFile, $targetFile ) ) {
|
680 |
unless ( copy( $logFile, $targetFile ) ) {
|
| 677 |
logMsg( "Could not copy report log file to target drive: $!" );
|
681 |
logMsg( "Could not copy report log file to target drive: $!" );
|
| 678 |
}
|
682 |
}
|
| 679 |
}
|
683 |
}
|
| 680 |
|
684 |
|