@@ -288,18 +288,9 @@ public EndPoint select(DataObject srcData, DataObject destData, boolean volumeEn
288288 DataStore srcStore = srcVolume .getDataStore ();
289289 if (srcStore .getRole () == DataStoreRole .Primary ) {
290290 StoragePoolVO pool = _storagePoolDao .findById (srcStore .getId ());
291- if (pool != null && ClvmPoolManager .isClvmPoolType (pool .getPoolType ())) {
292- Long lockHostId = getClvmLockHostId (srcVolume );
293- if (lockHostId != null ) {
294- logger .info ("Routing CLVM volume {} copy operation to source lock holder host {}" ,
295- srcVolume .getUuid (), lockHostId );
296- EndPoint ep = getEndPointFromHostId (lockHostId );
297- if (ep != null ) {
298- return ep ;
299- }
300- logger .warn ("Could not get endpoint for CLVM lock host {}, falling back to default selection" ,
301- lockHostId );
302- }
291+ EndPoint clvmEp = tryRouteToClvmLockHolder (srcVolume , pool , "copy operation" );
292+ if (clvmEp != null ) {
293+ return clvmEp ;
303294 }
304295 }
305296 }
@@ -359,17 +350,10 @@ public EndPoint select(DataObject srcData, DataObject destData, StorageAction ac
359350 DataStore srcStore = volumeInfo .getDataStore ();
360351 if (srcStore != null && srcStore .getRole () == DataStoreRole .Primary ) {
361352 StoragePoolVO pool = _storagePoolDao .findById (srcStore .getId ());
362- if (pool != null && ClvmPoolManager .isClvmPoolType (pool .getPoolType ())) {
363- Long lockHostId = getClvmLockHostId (volumeInfo );
364- if (lockHostId != null ) {
365- logger .info ("CLVM snapshot backup: routing snapshot {} backup CopyCommand to lock-holder host {} (same host that created the snapshot)" ,
366- srcSnapshot .getUuid (), lockHostId );
367- EndPoint ep = getEndPointFromHostId (lockHostId );
368- if (ep != null ) {
369- return ep ;
370- }
371- logger .warn ("Could not get endpoint for CLVM lock host {}, falling back to default selection" , lockHostId );
372- }
353+ logger .debug ("Checking if CLVM store and lock-holder routing applicable for snapshot {}" , srcSnapshot .getUuid ());
354+ EndPoint clvmEp = tryRouteToClvmLockHolder (volumeInfo , pool , "snapshot backup" );
355+ if (clvmEp != null ) {
356+ return clvmEp ;
373357 }
374358 }
375359 }
@@ -537,18 +521,9 @@ public EndPoint select(DataObject object) {
537521 if (object instanceof VolumeInfo && store .getRole () == DataStoreRole .Primary ) {
538522 VolumeInfo volume = (VolumeInfo ) object ;
539523 StoragePoolVO pool = _storagePoolDao .findById (store .getId ());
540- if (pool != null && ClvmPoolManager .isClvmPoolType (pool .getPoolType ())) {
541- Long lockHostId = getClvmLockHostId (volume );
542- if (lockHostId != null ) {
543- logger .debug ("Routing CLVM volume {} operation to lock holder host {}" ,
544- volume .getUuid (), lockHostId );
545- EndPoint ep = getEndPointFromHostId (lockHostId );
546- if (ep != null ) {
547- return ep ;
548- }
549- logger .warn ("Could not get endpoint for CLVM lock host {}, falling back to default selection" ,
550- lockHostId );
551- }
524+ EndPoint clvmEp = tryRouteToClvmLockHolder (volume , pool , "operation" );
525+ if (clvmEp != null ) {
526+ return clvmEp ;
552527 }
553528 }
554529
@@ -651,21 +626,9 @@ public EndPoint select(DataObject object, StorageAction action, boolean encrypti
651626 DataStore store = volume .getDataStore ();
652627 if (store .getRole () == DataStoreRole .Primary ) {
653628 StoragePoolVO pool = _storagePoolDao .findById (store .getId ());
654- if (pool != null && ClvmPoolManager .isClvmPoolType (pool .getPoolType ())) {
655- Long lockHostId = getClvmLockHostId (volume );
656- if (lockHostId != null ) {
657- logger .info ("Routing CLVM volume {} deletion to lock holder host {}" ,
658- volume .getUuid (), lockHostId );
659- EndPoint ep = getEndPointFromHostId (lockHostId );
660- if (ep != null ) {
661- return ep ;
662- }
663- logger .warn ("Could not get endpoint for CLVM lock host {}, falling back to default selection" ,
664- lockHostId );
665- } else {
666- logger .debug ("No CLVM lock host tracked for volume {}, using default endpoint selection" ,
667- volume .getUuid ());
668- }
629+ EndPoint clvmEp = tryRouteToClvmLockHolder (volume , pool , "deletion" );
630+ if (clvmEp != null ) {
631+ return clvmEp ;
669632 }
670633 }
671634 }
@@ -789,7 +752,24 @@ public List<EndPoint> selectAll(DataStore store) {
789752 return endPoints ;
790753 }
791754
792- /**
755+ protected EndPoint tryRouteToClvmLockHolder (VolumeInfo volume , StoragePoolVO pool , String operation ) {
756+ if (pool == null || !ClvmPoolManager .isClvmPoolType (pool .getPoolType ())) {
757+ return null ;
758+ }
759+ Long lockHostId = getClvmLockHostId (volume );
760+ if (lockHostId == null ) {
761+ logger .debug ("No CLVM lock host tracked for volume {}, using default endpoint selection" , volume .getUuid ());
762+ return null ;
763+ }
764+ logger .info ("Routing CLVM volume {} {} to lock holder host {}" , volume .getUuid (), operation , lockHostId );
765+ EndPoint ep = getEndPointFromHostId (lockHostId );
766+ if (ep != null ) {
767+ return ep ;
768+ }
769+ logger .warn ("Could not get endpoint for CLVM lock host {}, falling back to default selection" , lockHostId );
770+ return null ;
771+ }
772+
793773 /**
794774 * Gets the CLVM lock host ID for a volume by querying actual LVM state.
795775 *
0 commit comments