Skip to content

Commit d67af86

Browse files
cl-k-takahashirohityadavcloud
authored andcommitted
kvm: check if storage pool is mounted before creating pool xml (apache#2696)
Now the KVM agent checks whether a storage pool is mounted or not mounted before calling storagePoolCreateXML(). Signed-off-by: Kai Takahashi <[email protected]>
1 parent 76367db commit d67af86

File tree

1 file changed

+13
-33
lines changed

1 file changed

+13
-33
lines changed

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -147,44 +147,24 @@ private StoragePool createNetfsStoragePool(PoolType fsType, Connect conn, String
147147
StoragePool sp = null;
148148
try {
149149
s_logger.debug(spd.toString());
150-
sp = conn.storagePoolCreateXML(spd.toString(), 0);
151-
return sp;
152-
} catch (LibvirtException e) {
153-
s_logger.error(e.toString());
154-
// if error is that pool is mounted, try to handle it
155-
if (e.toString().contains("already mounted")) {
156-
s_logger.error("Attempting to unmount old mount libvirt is unaware of at " + targetPath);
150+
// check whether the pool is already mounted
151+
int mountpointResult = Script.runSimpleBashScriptForExitValue("mountpoint -q " + targetPath);
152+
// if the pool is mounted, try to unmount it
153+
if(mountpointResult == 0) {
154+
s_logger.info("Attempting to unmount old mount at " + targetPath);
157155
String result = Script.runSimpleBashScript("umount -l " + targetPath);
158156
if (result == null) {
159-
s_logger.error("Succeeded in unmounting " + targetPath);
160-
try {
161-
sp = conn.storagePoolCreateXML(spd.toString(), 0);
162-
s_logger.error("Succeeded in redefining storage");
163-
return sp;
164-
} catch (LibvirtException l) {
165-
s_logger.error("Target was already mounted, unmounted it but failed to redefine storage:" + l);
166-
}
157+
s_logger.info("Succeeded in unmounting " + targetPath);
167158
} else {
168-
s_logger.error("Failed in unmounting and redefining storage");
159+
s_logger.error("Failed in unmounting storage");
169160
}
170-
} else {
171-
s_logger.error("Internal error occurred when attempting to mount: specified path may be invalid");
172-
throw e;
173161
}
174-
if (sp != null) {
175-
try {
176-
if (sp.isPersistent() == 1) {
177-
sp.destroy();
178-
sp.undefine();
179-
} else {
180-
sp.destroy();
181-
}
182-
sp.free();
183-
} catch (LibvirtException l) {
184-
s_logger.debug("Failed to undefine " + fsType.toString() + " storage pool with: " + l.toString());
185-
}
186-
}
187-
return null;
162+
163+
sp = conn.storagePoolCreateXML(spd.toString(), 0);
164+
return sp;
165+
} catch (LibvirtException e) {
166+
s_logger.error(e.toString());
167+
throw e;
188168
}
189169
}
190170

0 commit comments

Comments
 (0)