Debian Codegraph @

lib/Sys/Virt/StorageVol.pm

raw
1 # -*- perl -*-
2 #
3 # Copyright (C) 2006-2009 Red Hat
4 # Copyright (C) 2006-2009 Daniel P. Berrange
5 #
6 # This program is free software; You can redistribute it and/or modify
7 # it under either:
8 #
9 # a) the GNU General Public License as published by the Free
10 # Software Foundation; either version 2, or (at your option) any
11 # later version,
12 #
13 # or
14 #
15 # b) the "Artistic License"
16 #
17 # The file "LICENSE" distributed along with this file provides full
18 # details of the terms and conditions of the two licenses.
19
20 =pod
21
22 =head1 NAME
23
24 Sys::Virt::StorageVol - Represent & manage a libvirt storage volume
25
26 =head1 DESCRIPTION
27
28 The C<Sys::Virt::StorageVol> module represents a storage volume managed
29 by libvirt. A storage volume is always associated with a containing
30 storage pool (C<Sys::Virt::StoragePool>).
31
32 =head1 METHODS
33
34 =over 4
35
36 =cut
37
38 package Sys::Virt::StorageVol;
39
40 use strict;
41 use warnings;
42
43
44 sub _new {
45 my $proto = shift;
46 my $class = ref($proto) || $proto;
47 my %params = @_;
48
49 my $self;
50 if (exists $params{name}) {
51 my $pool = exists $params{pool} ? $params{pool} : die "pool parameter is required";
52 $self = Sys::Virt::StorageVol::_lookup_by_name($pool, $params{name});
53 } elsif (exists $params{key}) {
54 my $con = exists $params{connection} ? $params{connection} : die "connection parameter is required";
55 $self = Sys::Virt::StorageVol::_lookup_by_key($con, $params{key});
56 } elsif (exists $params{path}) {
57 my $con = exists $params{connection} ? $params{connection} : die "connection parameter is required";
58 $self = Sys::Virt::StorageVol::_lookup_by_path($con, $params{path});
59 } elsif (exists $params{xml}) {
60 my $pool = exists $params{pool} ? $params{pool} : die "pool parameter is required";
61 if ($params{clone}) {
62 $self = Sys::Virt::StorageVol::_create_xml_from($pool, $params{xml}, $params{clone}, 0);
63 } else {
64 $self = Sys::Virt::StorageVol::_create_xml($pool, $params{xml}, 0);
65 }
66 } else {
67 die "name, key, path or xml parameters are required";
68 }
69
70 bless $self, $class;
71
72 return $self;
73 }
74
75
76 =item my $name = $vol->get_name()
77
78 Returns a string with a locally unique name of the storage vol
79
80 =item my $name = $vol->get_key()
81
82 Returns a string with a globally unique key for the storage vol
83
84 =item my $name = $vol->get_path()
85
86 Returns a string with a locally unique file path of the storage vol
87
88 =item my $xml = $vol->get_xml_description()
89
90 Returns an XML document containing a complete description of
91 the storage vol's configuration
92
93 =item $vol->delete($flags)
94
95 Immediately delete the storage volume freeing its storage resources.
96 The C<flags> parameter indicates any special action to be taken when
97 deleting the volume.
98
99 =item $vol->resize($newcapacity, $flags=0)
100
101 Adjust the size of the storage volume. The C<$newcapacity> value
102 semantics depend on the C<$flags> parameter. If C<$flags>
103 specifies C<RESIZE_DELTA> then the C<$newcapacity> is relative
104 to the current size. If C<$flags> specifies C<RESIZE_SHRINK>
105 then the C<$newcapacity> value is the amount of space to remove
106
107 =item $vol->wipe($flags = 0)
108
109 Clear the data in the storage volume to avoid future information
110 leak. The C<flags> parameter is currently unused and defaults
111 to zero.
112
113 =item $vol->wipe_pattern($algorithm, $flags = 0)
114
115 Clear the data in the storage volume to avoid future information
116 leak. The C<$algorithm> parameter specifies the data pattern used
117 to erase data, and should be one of the WIPE ALGORITHM CONSTANTS
118 listed later. The C<flags> parameter is currently unused and defaults
119 to zero.
120
121 =item my $info = $vol->get_info($flags = 0)
122
123 Retrieve live information about the storage volume. The returned
124 C<$info> hash reference contains three keys. C<type> indicates whether
125 the volume is a file or block device. C<capacity> provides the maximum
126 logical size of the volume. C<allocation> provides the current
127 physical usage of the volume. The allocation may be less than the
128 capacity for sparse, or grow-on-demand volumes. The allocation
129 may also be larger than the capacity, if there is a metadata overhead
130 for the volume format. C<$flags> may take one of the values
131
132 =over 4
133
134 =item Sys::Virt::StorageVol::USE_ALLOCATION
135
136 Return the current allocation in allocation
137
138 =item Sys::Virt::StorageVol::GET_PHYSICAL
139
140 Return the physical size in allocation
141
142 =back
143
144 =item $vol->download($st, $offset, $length, $flags=0);
145
146 Download data from C<$vol> using the stream C<$st>. If C<$offset>
147 and C<$length> are non-zero, then restrict data to the specified
148 volume byte range. The C<$flags> accept the following values:
149
150 =over 4
151
152 =item Sys::Virt::StorageVol::VOL_DOWNLOAD_SPARSE_STREAM
153
154 If this flag is is set in @flags effective transmission of holes
155 is enabled. This assumes using the stream C<$st> with combination of
156 C<sparse_recv_all> or C<recv($flags =
157 VIR_STREAM_RECV_STOP_AT_HOLE)> for honouring holes sent by server.
158
159 =back
160
161 =item $vol->upload($st, $offset, $length, $flags=0);
162
163 Upload data to C<$vol> using the stream C<$st>. If C<$offset>
164 and C<$length> are non-zero, then restrict data to the specified
165 volume byte range. The C<$flags> accept the following values:
166
167 =over 4
168
169 =item Sys::Virt::StorageVol::VOL_UPLOAD_SPARSE_STREAM
170
171 If this is set in C<$flags> effective transmission of holes is
172 enabled. This assumes using the stream C<$st> with combination of
173 C<sparse_send_all> or C<send_hole> to preserve source file
174 sparseness.
175
176 =back
177
178 =back
179
180 =head1 CONSTANTS
181
182 The following sets of constants are useful when dealing with storage
183 volumes
184
185 =head2 VOLUME TYPES
186
187 The following constants are useful for interpreting the C<type>
188 field in the hash returned by the C<get_info> method
189
190 =over 4
191
192 =item Sys::Virt::StorageVol::TYPE_FILE
193
194 The volume is a plain file
195
196 =item Sys::Virt::StorageVol::TYPE_BLOCK
197
198 The volume is a block device
199
200 =item Sys::Virt::StorageVol::TYPE_DIR
201
202 The volume is a directory
203
204 =item Sys::Virt::StorageVol::TYPE_NETWORK
205
206 The volume is a network source
207
208 =item Sys::Virt::StorageVol::TYPE_NETDIR
209
210 The volume is a network directory
211
212 =item Sys::Virt::StorageVol::TYPE_PLOOP
213
214 The volume is a ploop directory
215
216 =back
217
218 =head2 CREATE MODES
219
220 The following constants are useful for the C<flags> parameter of
221 the C<create> method
222
223 =over 4
224
225 =item Sys::Virt::StorageVol::CREATE_PREALLOC_METADATA
226
227 Preallocate header metadata when creating the volume.
228
229 =item Sys::Virt::StorageVol::CREATE_REFLINK
230
231 Perform lightweight reference copy
232
233 =item Sys::Virt::StorageVol::CREATE_VALIDATE
234
235 Validate the XML document against schema
236
237 =back
238
239 =head2 DELETE MODES
240
241 The following constants are useful for the C<flags> parameter of
242 the C<delete> method
243
244 =over 4
245
246 =item Sys::Virt::StorageVol::DELETE_NORMAL
247
248 Do a plain delete without any attempt to scrub data.
249
250 =item Sys::Virt::StorageVol::DELETE_ZEROED
251
252 Zero out current allocated blocks when deleting the volume
253
254 =item Sys::Virt::StorageVol::DELETE_WITH_SNAPSHOTS
255
256 Delete snapshots associated with the volume
257
258 =back
259
260 =head2 WIPE ALGORITHM CONSTANTS
261
262 The following constants specify the algorithm for erasing
263 data
264
265 =over 4
266
267 =item Sys::Virt::StorageVol::WIPE_ALG_BSI
268
269 9-pass method recommended by the German Center
270 of Security in Information Technologies
271
272 =item Sys::Virt::StorageVol::WIPE_ALG_DOD
273
274 4-pass Dod 5220.22-M section, 8-306 procedure
275
276 =item Sys::Virt::StorageVol::WIPE_ALG_GUTMANN
277
278 The canonical 35-pass sequence
279
280 =item Sys::Virt::StorageVol::WIPE_ALG_NNSA
281
282 4-pass NNSA Policy Letter NAP-14.1-C (XVI-8)
283
284 =item Sys::Virt::StorageVol::WIPE_ALG_PFITZNER7
285
286 7-pass random
287
288 =item Sys::Virt::StorageVol::WIPE_ALG_PFITZNER33
289
290 33-pass random
291
292 =item Sys::Virt::StorageVol::WIPE_ALG_RANDOM
293
294 1-pass random
295
296 =item Sys::Virt::StorageVol::WIPE_ALG_SCHNEIER
297
298 7-pass method described by Bruce Schneier in "Applied
299 Cryptography" (1996)
300
301 =item Sys::Virt::StorageVol::WIPE_ALG_ZERO
302
303 1-pass, all zeroes
304
305 =item Sys::Virt::StorageVol::WIPE_ALG_TRIM
306
307 1-pass, trim all data on the volume by using TRIM or DISCARD
308
309 =back
310
311 =head2 VOLUME RESIZE CONSTANTS
312
313 The following constants control how storage volumes can
314 be resized
315
316 =over 4
317
318 =item Sys::Virt::StorageVol::RESIZE_ALLOCATE
319
320 Fully allocate the extra space required during resize
321
322 =item Sys::Virt::StorageVol::RESIZE_DELTA
323
324 Treat the new capacity as a delta to the current capacity
325
326 =item Sys::Virt::StorageVol::RESIZE_SHRINK
327
328 Treat the new capacity as an amount to remove from the capacity
329
330 =back
331
332 =cut
333
334
335 1;
336
337 =head1 AUTHORS
338
339 Daniel P. Berrange <[email protected]>
340
341 =head1 COPYRIGHT
342
343 Copyright (C) 2006-2009 Red Hat
344 Copyright (C) 2006-2009 Daniel P. Berrange
345
346 =head1 LICENSE
347
348 This program is free software; you can redistribute it and/or modify
349 it under the terms of either the GNU General Public License as published
350 by the Free Software Foundation (either version 2 of the License, or at
351 your option any later version), or, the Artistic License, as specified
352 in the Perl README file.
353
354 =head1 SEE ALSO
355
356 L<Sys::Virt>, L<Sys::Virt::Error>, C<http://libvirt.org>
357
358 =cut