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