line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2014, cPanel, Inc. |
2
|
|
|
|
|
|
|
# All rights reserved. |
3
|
|
|
|
|
|
|
# http://cpanel.net/ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the same |
6
|
|
|
|
|
|
|
# terms as Perl itself. See the LICENSE file for further details. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Filesys::POSIX::Snapshot::Inode; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
11
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
3
|
use Filesys::POSIX::Bits; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
242
|
|
14
|
1
|
|
|
1
|
|
4
|
use Filesys::POSIX::Mem::Inode (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
15
|
1
|
|
|
1
|
|
4
|
use Filesys::POSIX::Mem::Directory (); |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
9
|
|
16
|
1
|
|
|
1
|
|
3
|
use Filesys::POSIX::Mem::Bucket (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
3
|
use Filesys::POSIX::Error qw(throw); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
447
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @ISA = qw(Filesys::POSIX::Mem::Inode); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub from_inode { |
23
|
46
|
|
|
46
|
0
|
59
|
my ( $class, $inode, %opts ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
46
|
|
|
|
|
114
|
my $new_inode = bless { |
26
|
|
|
|
|
|
|
'inode' => $inode, |
27
|
|
|
|
|
|
|
'copied' => 0 |
28
|
|
|
|
|
|
|
}, $class; |
29
|
|
|
|
|
|
|
|
30
|
46
|
|
|
|
|
81
|
my @ATTRIBUTES = qw( |
31
|
|
|
|
|
|
|
size atime mtime ctime uid gid mode dev rdev parent |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
46
|
|
|
|
|
35
|
@{$new_inode}{@ATTRIBUTES} = @{$inode}{@ATTRIBUTES}; |
|
46
|
|
|
|
|
165
|
|
|
46
|
|
|
|
|
89
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# Overwrite any values within the current inode with ones optionally passed |
38
|
|
|
|
|
|
|
# in %opts. |
39
|
|
|
|
|
|
|
# |
40
|
46
|
|
|
|
|
59
|
foreach my $attribute (@ATTRIBUTES) { |
41
|
460
|
100
|
|
|
|
633
|
$new_inode->{$attribute} = $opts{$attribute} |
42
|
|
|
|
|
|
|
if exists $opts{$attribute}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# Copy the symlink destination from the given inode provided, if |
47
|
|
|
|
|
|
|
# present. |
48
|
|
|
|
|
|
|
# |
49
|
46
|
100
|
|
|
|
84
|
if ( $inode->link ) { |
50
|
1
|
|
|
|
|
4
|
$new_inode->{'dest'} = $inode->readlink; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# |
54
|
|
|
|
|
|
|
# If it was specified at mount time that we should snapshot directory |
55
|
|
|
|
|
|
|
# listings immediately, then do so. |
56
|
|
|
|
|
|
|
# |
57
|
46
|
100
|
100
|
|
|
73
|
if ( $inode->dir && $opts{'dev'}->{'flags'}->{'immediate_dir_copy'} ) { |
58
|
15
|
|
|
|
|
21
|
$new_inode->{'directory'} = $new_inode->_copy_dir( $inode->directory ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
46
|
|
|
|
|
111
|
return $new_inode; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _copy_dir { |
65
|
17
|
|
|
17
|
|
16
|
my ( $self, $directory ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
17
|
|
|
|
|
37
|
my $new_directory = Filesys::POSIX::Mem::Directory->new; |
68
|
|
|
|
|
|
|
|
69
|
17
|
|
|
|
|
27
|
$directory->open; |
70
|
|
|
|
|
|
|
|
71
|
17
|
|
|
|
|
25
|
while ( defined( my $item = $directory->read ) ) { |
72
|
77
|
100
|
100
|
|
|
259
|
next if $item eq '.' || $item eq '..'; |
73
|
|
|
|
|
|
|
|
74
|
43
|
|
|
|
|
62
|
my $inode = $directory->get($item); |
75
|
|
|
|
|
|
|
|
76
|
43
|
|
|
|
|
74
|
$new_directory->set( |
77
|
|
|
|
|
|
|
$item, |
78
|
|
|
|
|
|
|
__PACKAGE__->from_inode( |
79
|
|
|
|
|
|
|
$inode, |
80
|
|
|
|
|
|
|
'parent' => $self, |
81
|
|
|
|
|
|
|
'dev' => $self->{'dev'} |
82
|
|
|
|
|
|
|
) |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
17
|
|
|
|
|
30
|
$directory->close; |
87
|
|
|
|
|
|
|
|
88
|
17
|
|
|
|
|
25
|
return $new_directory; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _copy_file { |
92
|
1
|
|
|
1
|
|
1
|
my ($self) = @_; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
2
|
my $dev_flags = $self->{'dev'}->{'flags'}; |
95
|
1
|
|
|
|
|
3
|
my $inode_file = $self->{'inode'}->open($O_RDONLY); |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
6
|
my $bucket = Filesys::POSIX::Mem::Bucket->new( |
98
|
|
|
|
|
|
|
'inode' => $self, |
99
|
|
|
|
|
|
|
'max' => $dev_flags->{'bucket_max'}, |
100
|
|
|
|
|
|
|
'dir' => $dev_flags->{'bucket_dir'} |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
6
|
while ( my $len = $inode_file->read( my $buf, 4096 ) ) { |
104
|
0
|
|
|
|
|
0
|
$bucket->write( $buf, $len ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
3
|
$inode_file->close; |
108
|
1
|
|
|
|
|
2
|
$bucket->close; |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
2
|
return $bucket; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub directory { |
114
|
10
|
|
|
10
|
1
|
77
|
my ($self) = @_; |
115
|
|
|
|
|
|
|
|
116
|
10
|
100
|
|
|
|
21
|
throw &Errno::ENOTDIR unless $self->dir; |
117
|
|
|
|
|
|
|
|
118
|
9
|
100
|
|
|
|
17
|
unless ( $self->{'directory'} ) { |
119
|
2
|
|
|
|
|
6
|
$self->{'directory'} = $self->_copy_dir( $self->{'inode'}->directory ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
9
|
|
|
|
|
13
|
return $self->{'directory'}; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub open { |
126
|
4
|
|
|
4
|
0
|
3
|
my ( $self, $flags ) = @_; |
127
|
|
|
|
|
|
|
|
128
|
4
|
100
|
|
|
|
10
|
unless ( $self->{'bucket'} ) { |
129
|
2
|
100
|
66
|
|
|
15
|
if ( $self->file && $flags & ( $O_WRONLY | $O_RDWR ) ) { |
130
|
1
|
|
|
|
|
3
|
$self->{'bucket'} = $self->_copy_file; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
4
|
100
|
|
|
|
8
|
if ( $self->{'bucket'} ) { |
135
|
3
|
|
|
|
|
8
|
return $self->{'bucket'}->open($flags); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
1
|
|
|
|
|
4
|
return $self->{'inode'}->open($flags); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |