2020import java .io .FileInputStream ;
2121import java .io .BufferedInputStream ;
2222import java .io .IOException ;
23- import java .net .URI ;
24- import java .net .URISyntaxException ;
2523import java .util .ArrayList ;
2624import java .util .List ;
2725import java .util .UUID ;
2826import java .util .Map ;
29- import java .util .HashMap ;
3027import org .apache .log4j .Logger ;
3128import org .apache .commons .codec .binary .Base64 ;
3229import org .apache .cloudstack .utils .qemu .QemuImg ;
3734import org .libvirt .LibvirtException ;
3835import org .libvirt .Secret ;
3936import org .libvirt .StoragePool ;
40- import org .libvirt .StoragePoolInfo ;
4137import org .libvirt .StorageVol ;
4238import org .libvirt .StoragePoolInfo .StoragePoolState ;
4339import com .ceph .rados .Rados ;
4844import com .ceph .rbd .RbdException ;
4945import com .ceph .rbd .jna .RbdSnapInfo ;
5046
51- import com .cloud .agent .api .ManageSnapshotCommand ;
5247import com .cloud .hypervisor .kvm .resource .LibvirtConnection ;
5348import com .cloud .hypervisor .kvm .resource .LibvirtSecretDef ;
5449import com .cloud .hypervisor .kvm .resource .LibvirtSecretDef .usage ;
6358import com .cloud .storage .Storage .StoragePoolType ;
6459import com .cloud .storage .StorageLayer ;
6560import com .cloud .utils .exception .CloudRuntimeException ;
66- import com .cloud .utils .script .OutputInterpreter ;
6761import com .cloud .utils .script .Script ;
6862
6963public class LibvirtStorageAdaptor implements StorageAdaptor {
@@ -72,8 +66,6 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
7266 private StorageLayer _storageLayer ;
7367 private String _mountPoint = "/mnt" ;
7468 private String _manageSnapshotPath ;
75- private String _lockfile = "KVMFILELOCK" + File .separator + ".lock" ;
76- private static final int ACQUIRE_GLOBAL_FILELOCK_TIMEOUT_FOR_KVM = 300 ; // 300 seconds
7769
7870 private String rbdTemplateSnapName = "cloudstack-base-snap" ;
7971 private int rbdFeatures = (1 <<0 ); /* Feature 1<<0 means layering in RBD format 2 */
@@ -1175,10 +1167,6 @@ public boolean deleteStoragePool(KVMStoragePool pool) {
11751167 return deleteStoragePool (pool .getUuid ());
11761168 }
11771169
1178- // refreshPool and deleteVol are used to fix CLOUDSTACK-2729/CLOUDSTACK-2780
1179- // They are caused by a libvirt bug (https://bugzilla.redhat.com/show_bug.cgi?id=977706)
1180- // However, we also need to fix the issues in CloudStack source code.
1181- // A file lock is used to prevent deleting a volume from a KVM storage pool when refresh it.
11821170 private void refreshPool (StoragePool pool ) throws LibvirtException {
11831171 pool .refresh (0 );
11841172 return ;
@@ -1188,28 +1176,4 @@ private void deleteVol(LibvirtStoragePool pool, StorageVol vol) throws LibvirtEx
11881176 vol .delete (0 );
11891177 }
11901178
1191- private boolean lock (String path , int wait ) {
1192- File lockFile = new File (path );
1193- lockFile .getParentFile ().mkdir ();
1194- boolean havelock = false ;
1195- try {
1196- while (wait > 0 ) {
1197- if (lockFile .createNewFile ()) {
1198- havelock = true ;
1199- break ;
1200- }
1201- s_logger .debug ("lockFile " + _lockfile + " already exists, waiting 1000 ms" );
1202- Thread .sleep (1000 );
1203- wait --;
1204- }
1205- } catch (IOException e ) {
1206- } catch (InterruptedException e ) {
1207- }
1208- return havelock ;
1209- }
1210-
1211- private void unlock (String path ) {
1212- File lockFile = new File (path );
1213- lockFile .delete ();
1214- }
12151179}
0 commit comments