line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
2
|
|
|
|
|
|
|
$Tapper::Installer::Precondition::Rawimage::VERSION = '5.0.1'; |
3
|
|
|
|
|
|
|
use strict; |
4
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
78
|
|
5
|
3
|
|
|
3
|
|
17
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
60
|
|
6
|
|
|
|
|
|
|
use File::Path; |
7
|
3
|
|
|
3
|
|
15
|
use Moose; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
122
|
|
8
|
3
|
|
|
3
|
|
13
|
extends 'Tapper::Installer::Precondition'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
15
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my ($self, $img) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
0
|
1
|
|
return "not filename given for rawimage" if not $img->{name}; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
my $img_size = 2048*1024; # 2GByte - size of standard rawimage in kbyte |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $filename = $img->{name}; |
20
|
|
|
|
|
|
|
my $path = $self->cfg->{paths}{base_dir}.$img->{path}; |
21
|
0
|
|
|
|
|
|
my $size = $img->{size} || $img_size; |
22
|
0
|
|
|
|
|
|
my ($error, $retval); |
23
|
0
|
|
0
|
|
|
|
|
24
|
0
|
|
|
|
|
|
if (not -d $path) { |
25
|
|
|
|
|
|
|
mkpath($path, {error => \$error}); |
26
|
0
|
0
|
|
|
|
|
foreach my $diag (@$error) { |
27
|
0
|
|
|
|
|
|
my ($file, $message) = each %$diag; |
28
|
0
|
|
|
|
|
|
return "general error: $message\n" if $file eq ''; |
29
|
0
|
|
|
|
|
|
return "Can't create $file: $message"; |
30
|
0
|
0
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$filename = $path."/".$filename; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
($error, $retval) = $self->log_and_exec("dd if=/dev/zero of=$filename bs=1024 count=$size"); |
36
|
|
|
|
|
|
|
return $retval if $error; |
37
|
0
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
($error, $retval) = $self->log_and_exec("/sbin/mkfs.ext3 -F -L tapper $filename"); |
39
|
|
|
|
|
|
|
return $retval if $error; |
40
|
0
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
$self->makedir($self->cfg->{paths}{guest_mount_dir}) if not -d $self->cfg->{paths}{guest_mount_dir}; |
42
|
|
|
|
|
|
|
($error, $retval) = $self->log_and_exec("mount -o loop $filename ".$self->cfg->{paths}{guest_mount_dir}); |
43
|
0
|
0
|
|
|
|
|
return $retval if $error; |
44
|
0
|
|
|
|
|
|
my $mountdir = $self->cfg->{paths}{guest_mount_dir}; |
45
|
0
|
0
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
mkdir ("$mountdir/etc") or return ("Can't create /etc in raw image $filename: $!"); |
47
|
|
|
|
|
|
|
open(my $FH,">","$mountdir/etc/tapper-release") or return "Can't open /etc/tapper-release in raw image $filename: $!"; |
48
|
0
|
0
|
|
|
|
|
print $FH "Tapper"; |
49
|
0
|
0
|
|
|
|
|
close $FH; |
50
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
($error, $retval) = $self->log_and_exec("umount $mountdir"); |
52
|
|
|
|
|
|
|
return $retval if $error; |
53
|
0
|
|
|
|
|
|
return 0; |
54
|
0
|
0
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=pod |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=encoding UTF-8 |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Tapper::Installer::Precondition::Rawimage |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Tapper::Installer::Precondition::Rawimage; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Tapper::Installer::Precondition::Rawimage - Create a raw image to be used as guest root for virtualisation |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This precondition should only be created when parsing "virt" preconditions. It's not useful for kernel developers. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 FUNCTIONS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 install |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Create the raw image. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
@param hash ref - contains all information about the image to be created |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
@return success - 0 |
87
|
|
|
|
|
|
|
@return error - return value of system or error string |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 AUTHORS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=over 4 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item * |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Tapper Team <tapper-ops@amazon.com> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=back |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Advanced Micro Devices, Inc. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This is free software, licensed under: |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |