@@ -177,6 +177,21 @@ private Scope getZoneScope(Scope destScope) {
177177 return zoneScope ;
178178 }
179179
180+ private Scope pickCacheScopeForCopy (DataObject srcData , DataObject destData ) {
181+ Scope srcScope = srcData .getDataStore ().getScope ();
182+ Scope destScope = destData .getDataStore ().getScope ();
183+
184+ Scope selectedScope = null ;
185+ if (srcScope .getScopeId () != null ) {
186+ selectedScope = srcScope ;
187+ } else if (destScope .getScopeId () != null ) {
188+ selectedScope = destScope ;
189+ } else {
190+ s_logger .warn ("Cannot find a zone-wide scope for move between cache store and image store" );
191+ }
192+ return selectedScope ;
193+ }
194+
180195 protected Answer copyObject (DataObject srcData , DataObject destData ) {
181196 String value = configDao .getValue (Config .PrimaryStorageDownloadWait .toString ());
182197 int _primaryStorageDownloadWait = NumbersUtil .parseInt (value ,
@@ -186,7 +201,7 @@ protected Answer copyObject(DataObject srcData, DataObject destData) {
186201 DataObject srcForCopy = srcData ;
187202 try {
188203 if (needCacheStorage (srcData , destData )) {
189- Scope destScope = getZoneScope ( destData . getDataStore (). getScope () );
204+ Scope destScope = pickCacheScopeForCopy ( srcData , destData );
190205 srcForCopy = cacheData = cacheMgr .createCacheObject (srcData , destScope );
191206 }
192207
@@ -436,7 +451,8 @@ protected Answer copySnapshot(DataObject srcData, DataObject destData) {
436451 Answer answer = null ;
437452 try {
438453 if (needCacheStorage (srcData , destData )) {
439- cacheData = cacheMgr .getCacheObject (srcData , destData .getDataStore ().getScope ());
454+ Scope selectedScope = pickCacheScopeForCopy (srcData , destData );
455+ cacheData = cacheMgr .getCacheObject (srcData , selectedScope );
440456
441457 CopyCommand cmd = new CopyCommand (srcData .getTO (), destData .getTO (), _backupsnapshotwait , _mgmtServer .getExecuteInSequence ());
442458 cmd .setCacheTO (cacheData .getTO ());
0 commit comments