Ramdisk/Linux.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 68 CC 8 SCAR 30.6
CC
8
Cov
0%
mount
42.0
unmount
12.0
BEGIN
2.0
CRAP 21.3
1 ###########################################
2 package Sys::Ramdisk::Linux;
3 ###########################################
4 use strict;
5 use warnings;
6 use Log::Log4perl qw(:easy);
7 use Sysadm::Install qw(bin_find tap);
8  
9 use base qw(Sys::Ramdisk);
10  
11 ###########################################
12 sub mount {
13 ###########################################
14 my($self) = @_;
15  
16 # mkdir -p /mnt/myramdisk
17 # mount -t tmpfs -o size=20m tmpfs /mnt/myramdisk
18  
19 for (qw(dir size)) {
20 if(! defined $self->{ $_ }) {
21 LOGWARN "Mandatory parameter $_ not set";
22 return undef;
23 }
24 }
25  
26 $self->{mount} = bin_find("mount") unless $self->{mount};
27 $self->{umount} = bin_find("umount") unless $self->{umount};
28  
29 for (qw(mount umount)) {
30 if(!defined $self->{$_}) {
31 LOGWARN "No $_ command found in PATH";
32 return undef;
33 }
34 }
35  
36 my @cmd = ($self->{mount},
37 "-t", "tmpfs",
38 "-o", "size=$self->{size}",
39 "tmpfs", $self->{dir});
40  
41 INFO "Mounting ramdisk: @cmd";
42 my($stdout, $stderr, $rc) = tap @cmd;
43
44 if($rc) {
45 LOGWARN "Mount command '@cmd' failed: $stderr";
46 return;
47 }
48
49 $self->{mounted} = 1;
50
51 return 1;
52 }
53  
54 ###########################################
55 sub unmount {
56 ###########################################
57 my($self) = @_;
58  
59 return if !exists $self->{mounted};
60  
61 my @cmd = ($self->{umount}, $self->{dir});
62  
63 INFO "Unmounting ramdisk: @cmd";
64  
65 my($stdout, $stderr, $rc) = tap @cmd;
66
67 if($rc) {
68 LOGWARN "Mount command '@cmd' failed: $stderr";
69 return;
70 }
71
72 $self->{mounted} = 0;
73  
74 return 1;
75 }
76  
77 1;
78  
79 __END__