Skip to content

Commit c2da4ea

Browse files
committed
fix NPE for cache ref cnt
1 parent a715eb8 commit c2da4ea

6 files changed

Lines changed: 97 additions & 89 deletions

File tree

client/tomcatconf/applicationContext.xml.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@
317317
<bean id="site2SiteCustomerGatewayDaoImpl" class="com.cloud.network.dao.Site2SiteCustomerGatewayDaoImpl" />
318318
<bean id="site2SiteVpnConnectionDaoImpl" class="com.cloud.network.dao.Site2SiteVpnConnectionDaoImpl" />
319319
<bean id="site2SiteVpnGatewayDaoImpl" class="com.cloud.network.dao.Site2SiteVpnGatewayDaoImpl" />
320-
<bean id="snapshotDao2Impl" class="org.apache.cloudstack.storage.snapshot.db.SnapshotDao2Impl" />
321320
<bean id="snapshotDaoImpl" class="com.cloud.storage.dao.SnapshotDaoImpl" />
322321
<bean id="snapshotPolicyDaoImpl" class="com.cloud.storage.dao.SnapshotPolicyDaoImpl" />
323322
<bean id="snapshotScheduleDaoImpl" class="com.cloud.storage.dao.SnapshotScheduleDaoImpl" />

engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
import com.cloud.storage.Storage.ImageFormat;
4545
import com.cloud.storage.Storage.TemplateType;
4646
import com.cloud.storage.VMTemplateStoragePoolVO;
47-
import com.cloud.storage.VMTemplateVO;
4847
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
48+
import com.cloud.storage.VMTemplateVO;
4949
import com.cloud.storage.dao.VMTemplateDao;
5050
import com.cloud.storage.dao.VMTemplatePoolDao;
5151
import com.cloud.utils.component.ComponentContext;
@@ -122,12 +122,12 @@ public Long getSize() {
122122
}
123123

124124
/*
125-
*
125+
*
126126
* // If the template that was passed into this allocator is not
127127
* installed in the storage pool, // add 3 * (template size on secondary
128128
* storage) to the running total VMTemplateHostVO templateHostVO =
129129
* _storageMgr.findVmTemplateHost(templateForVmCreation.getId(), null);
130-
*
130+
*
131131
* if (templateHostVO == null) { VMTemplateSwiftVO templateSwiftVO =
132132
* _swiftMgr.findByTmpltId(templateForVmCreation.getId()); if
133133
* (templateSwiftVO != null) { long templateSize =
@@ -152,12 +152,14 @@ public ImageFormat getFormat() {
152152
return this.imageVO.getFormat();
153153
}
154154

155-
// public boolean stateTransit(TemplateEvent e) throws NoTransitionException {
156-
// this.imageVO = imageDao.findById(this.imageVO.getId());
157-
// boolean result = imageMgr.getStateMachine().transitTo(this.imageVO, e, null, imageDao);
158-
// this.imageVO = imageDao.findById(this.imageVO.getId());
159-
// return result;
160-
// }
155+
// public boolean stateTransit(TemplateEvent e) throws NoTransitionException
156+
// {
157+
// this.imageVO = imageDao.findById(this.imageVO.getId());
158+
// boolean result = imageMgr.getStateMachine().transitTo(this.imageVO, e,
159+
// null, imageDao);
160+
// this.imageVO = imageDao.findById(this.imageVO.getId());
161+
// return result;
162+
// }
161163

162164
@Override
163165
public void processEvent(Event event) {
@@ -175,9 +177,10 @@ public void processEvent(Event event) {
175177
templEvent = TemplateEvent.OperationFailed;
176178
}
177179

178-
// if (templEvent != null && this.getDataStore().getRole() == DataStoreRole.Image) {
179-
// this.stateTransit(templEvent);
180-
// }
180+
// if (templEvent != null && this.getDataStore().getRole() ==
181+
// DataStoreRole.Image) {
182+
// this.stateTransit(templEvent);
183+
// }
181184
}
182185

183186
objectInStoreMgr.update(this, event);
@@ -238,9 +241,10 @@ public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answe
238241
templEvent = TemplateEvent.OperationFailed;
239242
}
240243

241-
// if (templEvent != null && this.getDataStore().getRole() == DataStoreRole.Image) {
242-
// this.stateTransit(templEvent);
243-
// }
244+
// if (templEvent != null && this.getDataStore().getRole() ==
245+
// DataStoreRole.Image) {
246+
// this.stateTransit(templEvent);
247+
// }
244248
}
245249
objectInStoreMgr.update(this, event);
246250
} catch (NoTransitionException e) {
@@ -264,9 +268,8 @@ public void incRefCount() {
264268
return;
265269
}
266270

267-
if (this.dataStore.getRole() == DataStoreRole.Image ||
268-
this.dataStore.getRole() == DataStoreRole.ImageCache) {
269-
TemplateDataStoreVO store = templateStoreDao.findById(this.dataStore.getId());
271+
if (this.dataStore.getRole() == DataStoreRole.Image || this.dataStore.getRole() == DataStoreRole.ImageCache) {
272+
TemplateDataStoreVO store = templateStoreDao.findByStoreTemplate(dataStore.getId(), this.getId());
270273
store.incrRefCnt();
271274
store.setLastUpdated(new Date());
272275
templateStoreDao.update(store.getId(), store);
@@ -278,9 +281,8 @@ public void decRefCount() {
278281
if (this.dataStore == null) {
279282
return;
280283
}
281-
if (this.dataStore.getRole() == DataStoreRole.Image ||
282-
this.dataStore.getRole() == DataStoreRole.ImageCache) {
283-
TemplateDataStoreVO store = templateStoreDao.findById(this.dataStore.getId());
284+
if (this.dataStore.getRole() == DataStoreRole.Image || this.dataStore.getRole() == DataStoreRole.ImageCache) {
285+
TemplateDataStoreVO store = templateStoreDao.findByStoreTemplate(dataStore.getId(), this.getId());
284286
store.decrRefCnt();
285287
store.setLastUpdated(new Date());
286288
templateStoreDao.update(store.getId(), store);
@@ -292,9 +294,8 @@ public Long getRefCount() {
292294
if (this.dataStore == null) {
293295
return null;
294296
}
295-
if (this.dataStore.getRole() == DataStoreRole.Image ||
296-
this.dataStore.getRole() == DataStoreRole.ImageCache) {
297-
TemplateDataStoreVO store = templateStoreDao.findById(this.dataStore.getId());
297+
if (this.dataStore.getRole() == DataStoreRole.Image || this.dataStore.getRole() == DataStoreRole.ImageCache) {
298+
TemplateDataStoreVO store = templateStoreDao.findByStoreTemplate(dataStore.getId(), this.getId());
298299
return store.getRefCnt();
299300
}
300301
return null;
@@ -442,5 +443,4 @@ public boolean delete() {
442443
return true;
443444
}
444445

445-
446446
}

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import javax.inject.Inject;
2424

25-
import com.cloud.storage.DataStoreRole;
2625
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
2726
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
2827
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
@@ -41,6 +40,7 @@
4140
import com.cloud.agent.api.to.DataObjectType;
4241
import com.cloud.agent.api.to.DataTO;
4342
import com.cloud.hypervisor.Hypervisor.HypervisorType;
43+
import com.cloud.storage.DataStoreRole;
4444
import com.cloud.storage.Snapshot;
4545
import com.cloud.storage.SnapshotVO;
4646
import com.cloud.storage.dao.SnapshotDao;
@@ -279,9 +279,9 @@ public void incRefCount() {
279279
return;
280280
}
281281

282-
if (this.store.getRole() == DataStoreRole.Image ||
283-
this.store.getRole() == DataStoreRole.ImageCache) {
284-
SnapshotDataStoreVO store = snapshotStoreDao.findById(this.store.getId());
282+
if (this.store.getRole() == DataStoreRole.Image || this.store.getRole() == DataStoreRole.ImageCache) {
283+
SnapshotDataStoreVO store = snapshotStoreDao.findByStoreSnapshot(this.store.getRole(), this.store.getId(),
284+
this.getId());
285285
store.incrRefCnt();
286286
store.setLastUpdated(new Date());
287287
snapshotStoreDao.update(store.getId(), store);
@@ -293,9 +293,9 @@ public void decRefCount() {
293293
if (this.store == null) {
294294
return;
295295
}
296-
if (this.store.getRole() == DataStoreRole.Image ||
297-
this.store.getRole() == DataStoreRole.ImageCache) {
298-
SnapshotDataStoreVO store = snapshotStoreDao.findById(this.store.getId());
296+
if (this.store.getRole() == DataStoreRole.Image || this.store.getRole() == DataStoreRole.ImageCache) {
297+
SnapshotDataStoreVO store = snapshotStoreDao.findByStoreSnapshot(this.store.getRole(), this.store.getId(),
298+
this.getId());
299299
store.decrRefCnt();
300300
store.setLastUpdated(new Date());
301301
snapshotStoreDao.update(store.getId(), store);
@@ -307,9 +307,9 @@ public Long getRefCount() {
307307
if (this.store == null) {
308308
return null;
309309
}
310-
if (this.store.getRole() == DataStoreRole.Image ||
311-
this.store.getRole() == DataStoreRole.ImageCache) {
312-
SnapshotDataStoreVO store = snapshotStoreDao.findById(this.store.getId());
310+
if (this.store.getRole() == DataStoreRole.Image || this.store.getRole() == DataStoreRole.ImageCache) {
311+
SnapshotDataStoreVO store = snapshotStoreDao.findByStoreSnapshot(this.store.getRole(), this.store.getId(),
312+
this.getId());
313313
return store.getRefCnt();
314314
}
315315
return null;

engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ public void processEventOnly(ObjectInDataStoreStateMachine.Event event) {
252252
}
253253
}
254254

255-
256255
@Override
257256
public String getName() {
258257
return this.volumeVO.getName();
@@ -456,9 +455,8 @@ public void incRefCount() {
456455
return;
457456
}
458457

459-
if (this.dataStore.getRole() == DataStoreRole.Image ||
460-
this.dataStore.getRole() == DataStoreRole.ImageCache) {
461-
VolumeDataStoreVO store = volumeStoreDao.findById(this.dataStore.getId());
458+
if (this.dataStore.getRole() == DataStoreRole.Image || this.dataStore.getRole() == DataStoreRole.ImageCache) {
459+
VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
462460
store.incrRefCnt();
463461
store.setLastUpdated(new Date());
464462
volumeStoreDao.update(store.getId(), store);
@@ -470,9 +468,8 @@ public void decRefCount() {
470468
if (this.dataStore == null) {
471469
return;
472470
}
473-
if (this.dataStore.getRole() == DataStoreRole.Image ||
474-
this.dataStore.getRole() == DataStoreRole.ImageCache) {
475-
VolumeDataStoreVO store = volumeStoreDao.findById(this.dataStore.getId());
471+
if (this.dataStore.getRole() == DataStoreRole.Image || this.dataStore.getRole() == DataStoreRole.ImageCache) {
472+
VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
476473
store.decrRefCnt();
477474
store.setLastUpdated(new Date());
478475
volumeStoreDao.update(store.getId(), store);
@@ -484,9 +481,8 @@ public Long getRefCount() {
484481
if (this.dataStore == null) {
485482
return null;
486483
}
487-
if (this.dataStore.getRole() == DataStoreRole.Image ||
488-
this.dataStore.getRole() == DataStoreRole.ImageCache) {
489-
VolumeDataStoreVO store = volumeStoreDao.findById(this.dataStore.getId());
484+
if (this.dataStore.getRole() == DataStoreRole.Image || this.dataStore.getRole() == DataStoreRole.ImageCache) {
485+
VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
490486
return store.getRefCnt();
491487
}
492488
return null;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,6 @@ public Answer attachVolume(AttachCommand cmd) {
699699
s_logger.debug("Failed to attach volume: " + vol.getPath() + ", due to " + e.toString());
700700
return new AttachAnswer(e.toString());
701701
}
702-
703-
704702
}
705703

706704
@Override

0 commit comments

Comments
 (0)