Skip to content

Commit f3b4815

Browse files
authored
Ac 98 updated qemu support (#33)
* Adding new -U option for qemu-img into strategic locations * Fixing typo'd paths
1 parent a2e38a6 commit f3b4815

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/qemu/QemuImg.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Iterator;
2121
import java.util.Map;
2222

23+
import com.cloud.hypervisor.kvm.resource.LibvirtConnection;
24+
import org.libvirt.LibvirtException;
2325
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
2426

2527
import com.cloud.storage.Storage;
@@ -226,6 +228,9 @@ public void create(final QemuImgFile file, final Map<String, String> options) th
226228
public void convert(final QemuImgFile srcFile, final QemuImgFile destFile, final Map<String, String> options) throws QemuImgException {
227229
final Script script = new Script(_qemuImgPath, timeout);
228230
script.add("convert");
231+
232+
includeForceShared(script);
233+
229234
// autodetect source format. Sometime int he future we may teach KVMPhysicalDisk about more formats, then we can explicitly pass them if necessary
230235
//s.add("-f");
231236
//s.add(srcFile.getFormat().toString());
@@ -304,6 +309,9 @@ public void commit(final QemuImgFile file) throws QemuImgException {
304309
public Map<String, String> info(final QemuImgFile file) throws QemuImgException {
305310
final Script s = new Script(_qemuImgPath);
306311
s.add("info");
312+
313+
includeForceShared(s);
314+
307315
s.add(file.getFileName());
308316
final OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
309317
final String result = s.execute(parser);
@@ -331,6 +339,16 @@ public Map<String, String> info(final QemuImgFile file) throws QemuImgException
331339
return info;
332340
}
333341

342+
private void includeForceShared(Script s) {
343+
try {
344+
long version = LibvirtConnection.getConnection().getVersion();
345+
if (version >= 2010000) {
346+
s.add("-U");
347+
}
348+
} catch (LibvirtException ignored) {
349+
}
350+
}
351+
334352
/* List, apply, create or delete snapshots in image */
335353
public void snapshot() throws QemuImgException {
336354

scripts/storage/qcow2/managesnapshot.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,23 @@ backup_snapshot() {
215215
( printf "${qemu_img} failed to create backup of snapshot ${snapshotname} for disk ${disk} to ${destPath}.\n" >&2; return 2 )
216216

217217
elif [ -f ${disk} ]; then
218+
219+
# Localizing this to just this branch since it is specific to our setup
220+
local forceSharedWrite=""
221+
if $qemu_img -h | grep '\[-U]' >& /dev/null
222+
then
223+
forceSharedWrite="-U"
224+
fi
225+
218226
# Does the snapshot exist?
219-
$qemu_img snapshot -l $disk|grep -w "$snapshotname" >& /dev/null
227+
$qemu_img snapshot $forceSharedWrite -l $disk|grep -w "$snapshotname" >& /dev/null
220228
if [ $? -gt 0 ]
221229
then
222230
printf "there is no $snapshotname on disk $disk\n" >&2
223231
return 1
224232
fi
225233

226-
$qemu_img convert -f qcow2 -O qcow2 -s $snapshotname $disk $destPath/$destName >& /dev/null
234+
$qemu_img convert $forceSharedWrite -f qcow2 -O qcow2 -s $snapshotname $disk $destPath/$destName >& /dev/null
227235
if [ $? -gt 0 ]
228236
then
229237
printf "Failed to backup $snapshotname for disk $disk to $destPath\n" >&2

scripts/storage/qcow2/resizevolume.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ resizeqcow2() {
178178
fi
179179
##### end sanity #####
180180

181-
actualsize=`qemu-img info $path | grep "virtual size" | sed -re 's/^.*\(([0-9]+).*$/\1/g'`
181+
# Localizing this to just this branch since it is specific to our setup
182+
local forceSharedWrite=""
183+
if qemu-img -h | grep '\[-U]' >& /dev/null
184+
then
185+
forceSharedWrite="-U"
186+
fi
187+
188+
actualsize=`qemu-img info $forceSharedWrite $path | grep "virtual size" | sed -re 's/^.*\(([0-9]+).*$/\1/g'`
182189

183190
if [ $actualsize -ne $currentsize ]
184191
then

0 commit comments

Comments
 (0)