forked from lstoll/libvirt-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorageVol.java
More file actions
204 lines (185 loc) · 5.89 KB
/
Copy pathStorageVol.java
File metadata and controls
204 lines (185 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package org.libvirt;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.StoragePoolPointer;
import org.libvirt.jna.StorageVolPointer;
import org.libvirt.jna.virStorageVolInfo;
/**
* An acutal storage bucket.
*/
public class StorageVol {
static final class DeleteFlags {
/**
* Delete metadata only (fast)
*/
static final int VIR_STORAGE_POOL_DELETE_NORMAL = 0;
/**
* Clear all data to zeros (slow)
*/
static final int VIR_STORAGE_POOL_DELETE_ZEROED = 1;
}
public static enum Type {
/**
* Regular file based volumes
*/
VIR_STORAGE_VOL_FILE,
/**
* Block based volumes
*/
VIR_STORAGE_VOL_BLOCK
}
/**
* the native virStorageVolPtr.
*/
StorageVolPointer VSVP;
/**
* The VirConnect Object that represents the Hypervisor of this Domain
*/
protected Connect virConnect;
/**
* the libvirt instance
*/
protected Libvirt libvirt;
/**
* Constructs a VirStorageVol object from a known native virStoragePoolPtr,
* and a VirConnect object. For use when native libvirt returns a
* virStorageVolPtr, i.e. error handling.
*
* @param virConnect
* the Domain's hypervisor
* @param VSVP
* the native virStorageVolPtr
*/
StorageVol(Connect virConnect, StorageVolPointer VSVP) {
this.virConnect = virConnect;
this.VSVP = VSVP;
libvirt = virConnect.libvirt;
}
/**
* Delete the storage volume from the pool
*
* @param flags
* future flags, use 0 for now
* @throws LibvirtException
*/
public void delete(int flags) throws LibvirtException {
int result = libvirt.virStorageVolDelete(VSVP, flags);
ErrorHandler.processError(libvirt, result);
}
@Override
public void finalize() throws LibvirtException {
free();
}
/**
* Release the storage volume handle. The underlying storage volume contains
* to exist
*
* @throws LibvirtException
* @return number of references left (>= 0) for success, -1 for failure.
*/
public int free() throws LibvirtException {
int success = 0;
if (VSVP != null) {
int result = libvirt.virStorageVolFree(VSVP);
ErrorHandler.processError(libvirt, result);
VSVP = null;
}
return success;
}
/**
* Provides the connection object associated with a storage volume. The
* reference counter on the connection is not increased by this call.
*
* @return the Connect object
*/
public Connect getConnect() {
return virConnect;
}
/**
* Fetches volatile information about the storage volume such as its current
* allocation
*
* @return StorageVolInfo object
* @throws LibvirtException
*/
public StorageVolInfo getInfo() throws LibvirtException {
virStorageVolInfo vInfo = new virStorageVolInfo();
int result = libvirt.virStorageVolGetInfo(VSVP, vInfo);
ErrorHandler.processError(libvirt, result);
return new StorageVolInfo(vInfo);
}
/**
* Fetch the storage volume key. This is globally unique, so the same volume
* will have the same key no matter what host it is accessed from
*
* @return the key
* @throws LibvirtException
*/
public String getKey() throws LibvirtException {
String returnValue = libvirt.virStorageVolGetKey(VSVP);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
/**
* Fetch the storage volume name. This is unique within the scope of a pool
*
* @return the name
* @throws LibvirtException
*/
public String getName() throws LibvirtException {
String returnValue = libvirt.virStorageVolGetName(VSVP);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
/**
* Fetch the storage volume path. Depending on the pool configuration this
* is either persistent across hosts, or dynamically assigned at pool
* startup. Consult pool documentation for information on getting the
* persistent naming
*
* @return the storage volume path
* @throws LibvirtException
*/
public String getPath() throws LibvirtException {
String returnValue = libvirt.virStorageVolGetPath(VSVP);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
/**
* Fetch an XML document describing all aspects of this storage volume
*
* @param flags
* flags for XML generation (unused, pass 0)
* @return the XML document
* @throws LibvirtException
*/
public String getXMLDesc(int flags) throws LibvirtException {
String returnValue = libvirt.virStorageVolGetXMLDesc(VSVP, flags);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
/**
* Fetch a storage pool which contains this volume
*
* @return StoragePool object,
* @throws LibvirtException
*/
public StoragePool storagePoolLookupByVolume() throws LibvirtException {
StoragePoolPointer ptr = libvirt.virStoragePoolLookupByVolume(VSVP);
ErrorHandler.processError(libvirt, ptr);
return new StoragePool(virConnect, ptr);
}
/**
* Ensure data previously on a volume is not accessible to future reads
*
* @see <a
* href="http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolWipe">Libvirt
* Documentation</a>
* @return 0 on success, or -1 on error
* @throws LibvirtException
*/
public int wipe() throws LibvirtException {
int returnValue = libvirt.virStorageVolWipe(VSVP, 0);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
}