@@ -67,7 +67,7 @@ protected boolean mountNfs(Connection conn, String remoteDir, String localDir) {
6767 String results = hypervisorResource .callHostPluginAsync (conn , "cloud-plugin-storage" , "mountNfsSecondaryStorage" , 100 * 1000 ,
6868 "localDir" , localDir , "remoteDir" , remoteDir );
6969 if (results == null || results .isEmpty ()) {
70- String errMsg = "Could not mount secondary storage " + remoteDir + " on host " ;
70+ String errMsg = "Could not mount secondary storage " + remoteDir + " on host " + localDir ;
7171 s_logger .warn (errMsg );
7272 throw new CloudRuntimeException (errMsg );
7373 }
@@ -87,14 +87,9 @@ protected SR createFileSR(Connection conn, String path) {
8787 PBD pbd = null ;
8888 try {
8989 String srname = hypervisorResource .getHost ().uuid + path .trim ();
90- try {
91- Set <SR > srs = SR .getByNameLabel (conn , srname );
92- if ( srs != null && !srs .isEmpty ()) {
93- return srs .iterator ().next ();
94- }
95- } catch (Exception e ) {
96- // getByNameLabel may throw exception if sr is found
97- // ignore the exception since cs will create the SR
90+ Set <SR > srs = SR .getByNameLabel (conn , srname );
91+ if ( srs != null && !srs .isEmpty ()) {
92+ return srs .iterator ().next ();
9893 }
9994 Map <String , String > smConfig = new HashMap <String , String >();
10095 Host host = Host .getByUuid (conn , hypervisorResource .getHost ().uuid );
@@ -146,6 +141,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
146141 DataStoreTO srcStore = srcData .getDataStore ();
147142 Connection conn = hypervisorResource .getConnection ();
148143 SR srcSr = null ;
144+ Task task = null ;
149145 try {
150146 if ((srcStore instanceof NfsTO ) && (srcData .getObjectType () == DataObjectType .TEMPLATE )) {
151147 NfsTO srcImageStore = (NfsTO )srcStore ;
@@ -184,7 +180,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
184180 }
185181 String pUuid = poolsr .getUuid (conn );
186182 boolean isISCSI = IsISCSI (poolsr .getType (conn ));
187- Task task = srcVdi .copyAsync2 (conn , poolsr , null , null );
183+ task = srcVdi .copyAsync2 (conn , poolsr , null , null );
188184 // poll every 1 seconds ,
189185 hypervisorResource .waitForTask (conn , task , 1000 , wait * 1000 );
190186 hypervisorResource .checkForSuccess (conn , task );
@@ -209,6 +205,13 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
209205 s_logger .warn (msg , e );
210206 return new CopyCmdAnswer (msg );
211207 } finally {
208+ if ( task != null ) {
209+ try {
210+ task .destroy (conn );
211+ } catch (Exception e ) {
212+ s_logger .debug ("unable to destroy task(" + task .toWireString () + ") due to " + e .toString ());
213+ }
214+ }
212215 if (srcSr != null ) {
213216 hypervisorResource .removeSR (conn , srcSr );
214217 }
@@ -227,17 +230,16 @@ protected String backupSnapshot(Connection conn, String primaryStorageSRUuid, St
227230 SR ssSR = null ;
228231
229232 String remoteDir = secondaryStorageMountPath ;
230-
231233 try {
232234 ssSR = createFileSr (conn , remoteDir , path );
233235 filesrcreated = true ;
234236
235237 VDI snapshotvdi = VDI .getByUuid (conn , snapshotUuid );
236- Task task = null ;
237238 if (wait == 0 ) {
238239 wait = 2 * 60 * 60 ;
239240 }
240241 VDI dvdi = null ;
242+ Task task = null ;
241243 try {
242244 VDI previousSnapshotVdi = null ;
243245 if (prevSnapshotUuid != null ) {
@@ -253,9 +255,8 @@ protected String backupSnapshot(Connection conn, String primaryStorageSRUuid, St
253255 if (task != null ) {
254256 try {
255257 task .destroy (conn );
256- } catch (Exception e1 ) {
257- s_logger .warn ("unable to destroy task(" + task .toString () + ") on host("
258- + ") due to " , e1 );
258+ } catch (Exception e ) {
259+ s_logger .warn ("unable to destroy task(" + task .toWireString () + ") due to " + e .toString ());
259260 }
260261 }
261262 }
@@ -342,6 +343,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
342343 String localMountPoint = BaseMountPointOnHost + File .separator + UUID .nameUUIDFromBytes (secondaryStorageUrl .getBytes ()).toString ();
343344 if (fullbackup ) {
344345 SR snapshotSr = null ;
346+ Task task = null ;
345347 try {
346348 String localDir = "/var/cloud_mount/" + UUID .nameUUIDFromBytes (secondaryStorageMountPath .getBytes ());
347349 mountNfs (conn , secondaryStorageMountPath , localDir );
@@ -354,7 +356,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
354356
355357 snapshotSr = createFileSr (conn , secondaryStorageMountPath , folder );
356358
357- Task task = snapshotVdi .copyAsync2 (conn , snapshotSr , null , null );
359+ task = snapshotVdi .copyAsync2 (conn , snapshotSr , null , null );
358360 // poll every 1 seconds ,
359361 hypervisorResource .waitForTask (conn , task , 1000 , wait * 1000 );
360362 hypervisorResource .checkForSuccess (conn , task );
@@ -394,6 +396,13 @@ public Answer backupSnapshot(CopyCommand cmd) {
394396 }
395397
396398 } finally {
399+ if (task != null ) {
400+ try {
401+ task .destroy (conn );
402+ } catch (Exception e ) {
403+ s_logger .warn ("unable to destroy task(" + task .toWireString () + ") due to " + e .toString ());
404+ }
405+ }
397406 if ( snapshotSr != null ) {
398407 hypervisorResource .removeSR (conn , snapshotSr );
399408 }
@@ -457,6 +466,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
457466 boolean result = false ;
458467 String secondaryStorageMountPath = null ;
459468 String installPath = null ;
469+ Task task = null ;
460470 try {
461471 URI uri = new URI (secondaryStoragePoolURL );
462472 secondaryStorageMountPath = uri .getHost () + ":" + uri .getPath ();
@@ -472,7 +482,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
472482 tmpltSR = createFileSr (conn , uri .getHost () + ":" + uri .getPath (), installPath );
473483
474484 // copy volume to template SR
475- Task task = vol .copyAsync2 (conn , tmpltSR , null , null );
485+ task = vol .copyAsync2 (conn , tmpltSR , null , null );
476486 // poll every 1 seconds ,
477487 hypervisorResource .waitForTask (conn , task , 1000 , wait * 1000 );
478488 hypervisorResource .checkForSuccess (conn , task );
@@ -513,6 +523,14 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
513523 }
514524 details = "Creating template from volume " + volumeUUID + " failed due to " + e .toString ();
515525 s_logger .error (details , e );
526+ } finally {
527+ if (task != null ) {
528+ try {
529+ task .destroy (conn );
530+ } catch (Exception e ) {
531+ s_logger .warn ("unable to destroy task(" + task .toWireString () + ") due to " + e .toString ());
532+ }
533+ }
516534 }
517535 return new CopyCmdAnswer (details );
518536 }
@@ -592,6 +610,7 @@ public Answer createVolumeFromSnapshot(CopyCommand cmd) {
592610 // poll every 1 seconds ,
593611 hypervisorResource .waitForTask (conn , task , 1000 , wait * 1000 );
594612 hypervisorResource .checkForSuccess (conn , task );
613+ task .destroy (conn );
595614 }
596615
597616 result = true ;
@@ -638,6 +657,7 @@ public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) {
638657
639658 if (destStore instanceof NfsTO ) {
640659 SR secondaryStorage = null ;
660+ Task task = null ;
641661 try {
642662 NfsTO nfsStore = (NfsTO )destStore ;
643663 URI uri = new URI (nfsStore .getUrl ());
@@ -651,7 +671,7 @@ public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) {
651671 // Look up the volume on the source primary storage pool
652672 VDI srcVdi = getVDIbyUuid (conn , srcVolume .getPath ());
653673 // Copy the volume to secondary storage
654- Task task = srcVdi .copyAsync2 (conn , secondaryStorage , null , null );
674+ task = srcVdi .copyAsync2 (conn , secondaryStorage , null , null );
655675 // poll every 1 seconds ,
656676 hypervisorResource .waitForTask (conn , task , 1000 , wait * 1000 );
657677 hypervisorResource .checkForSuccess (conn , task );
@@ -666,6 +686,13 @@ public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) {
666686 s_logger .debug ("Failed to copy volume to secondary: " + e .toString ());
667687 return new CopyCmdAnswer ("Failed to copy volume to secondary: " + e .toString ());
668688 } finally {
689+ if (task != null ) {
690+ try {
691+ task .destroy (conn );
692+ } catch (Exception e ) {
693+ s_logger .warn ("unable to destroy task(" + task .toWireString () + ") due to " + e .toString ());
694+ }
695+ }
669696 hypervisorResource .removeSR (conn , secondaryStorage );
670697 }
671698 }
@@ -700,10 +727,11 @@ public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
700727 return new CopyCmdAnswer (e .toString ());
701728 }
702729 SR srcSr = createFileSr (conn , uri .getHost () + ":" + uri .getPath (), volumeDirectory );
730+ Task task = null ;
703731 try {
704732 SR primaryStoragePool = hypervisorResource .getStorageRepository (conn , primaryStore .getUuid ());
705733 VDI srcVdi = VDI .getByUuid (conn , volumeUuid );
706- Task task = srcVdi .copyAsync2 (conn , primaryStoragePool , null , null );
734+ task = srcVdi .copyAsync2 (conn , primaryStoragePool , null , null );
707735 // poll every 1 seconds ,
708736 hypervisorResource .waitForTask (conn , task , 1000 , wait * 1000 );
709737 hypervisorResource .checkForSuccess (conn , task );
@@ -718,6 +746,13 @@ public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
718746 s_logger .warn (msg , e );
719747 return new CopyCmdAnswer (e .toString ());
720748 } finally {
749+ if (task != null ) {
750+ try {
751+ task .destroy (conn );
752+ } catch (Exception e ) {
753+ s_logger .warn ("unable to destroy task(" + task .toString () + ") due to " + e .toString ());
754+ }
755+ }
721756 if (srcSr != null ) {
722757 hypervisorResource .removeSR (conn , srcSr );
723758 }
@@ -791,6 +826,7 @@ public Answer createTemplateFromSnapshot(CopyCommand cmd) {
791826 // poll every 1 seconds ,
792827 hypervisorResource .waitForTask (conn , task , 1000 , wait * 1000 );
793828 hypervisorResource .checkForSuccess (conn , task );
829+ task .destroy (conn );
794830 }
795831
796832 destVdi = VDI .getByUuid (conn , destVdiUuid );
0 commit comments