Skip to content

Commit e7749af

Browse files
author
Kelven Yang
committed
Bug 7772: Add hypervisor type to snapshots table, fix issues with createVolumeFromSnapshot if snapshot was taken under data volume
1 parent bd788b1 commit e7749af

6 files changed

Lines changed: 32 additions & 12 deletions

File tree

‎api/src/com/cloud/storage/Snapshot.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
package com.cloud.storage;
2020

2121
import java.util.Date;
22+
23+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2224

2325
public interface Snapshot {
2426
public enum Type {
@@ -59,5 +61,6 @@ public boolean equals(String status) {
5961
String getName();
6062
Date getCreated();
6163
short getSnapshotType();
62-
Status getStatus();
64+
Status getStatus();
65+
HypervisorType getHypervisorType();
6366
}

‎core/src/com/cloud/storage/SnapshotVO.java‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import javax.persistence.Table;
3232
import javax.persistence.TableGenerator;
3333

34+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3435
import com.cloud.utils.db.GenericDao;
3536
import com.google.gson.annotations.Expose;
3637

@@ -79,10 +80,14 @@ public class SnapshotVO implements Snapshot {
7980

8081
@Column(name="prev_snap_id")
8182
long prevSnapshotId;
83+
84+
@Column(name="hypervisor_type")
85+
@Enumerated(value=EnumType.STRING)
86+
HypervisorType hypervisorType;
8287

8388
public SnapshotVO() { }
8489

85-
public SnapshotVO(long id, long accountId, long volumeId, String path, String name, short snapshotType, String typeDescription) {
90+
public SnapshotVO(long id, long accountId, long volumeId, String path, String name, short snapshotType, String typeDescription, HypervisorType hypervisorType) {
8691
this.id = id;
8792
this.accountId = accountId;
8893
this.volumeId = volumeId;
@@ -91,7 +96,8 @@ public SnapshotVO(long id, long accountId, long volumeId, String path, String na
9196
this.snapshotType = snapshotType;
9297
this.typeDescription = typeDescription;
9398
this.status = Status.Creating;
94-
this.prevSnapshotId = 0;
99+
this.prevSnapshotId = 0;
100+
this.hypervisorType = hypervisorType;
95101
}
96102

97103
@Override
@@ -126,7 +132,13 @@ public String getName() {
126132
@Override
127133
public short getSnapshotType() {
128134
return snapshotType;
129-
}
135+
}
136+
137+
@Override
138+
public HypervisorType getHypervisorType() {
139+
return hypervisorType;
140+
}
141+
130142
public void setSnapshotType(short snapshotType) {
131143
this.snapshotType = snapshotType;
132144
}

‎server/src/com/cloud/storage/StorageManagerImpl.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public boolean canVmRestartOnAnotherServer(long vmId) {
546546
}
547547

548548
@DB
549-
protected Pair<VolumeVO, String> createVolumeFromSnapshot(VolumeVO volume, SnapshotVO snapshot, VMTemplateVO template, long virtualsize) {
549+
protected Pair<VolumeVO, String> createVolumeFromSnapshot(VolumeVO volume, SnapshotVO snapshot, long virtualsize) {
550550
VolumeVO createdVolume = null;
551551
Long volumeId = volume.getId();
552552

@@ -565,7 +565,7 @@ protected Pair<VolumeVO, String> createVolumeFromSnapshot(VolumeVO volume, Snaps
565565

566566
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
567567
DataCenterVO dc = _dcDao.findById(volume.getDataCenterId());
568-
DiskProfile dskCh = new DiskProfile(volume, diskOffering, template.getHypervisorType());
568+
DiskProfile dskCh = new DiskProfile(volume, diskOffering, snapshot.getHypervisorType());
569569

570570
int retry = 0;
571571
// Determine what pod to store the volume in
@@ -658,7 +658,7 @@ protected VolumeVO createVolumeFromSnapshot(VolumeVO volume, long snapshotId) {
658658
template = _templateDao.findById(originalVolume.getTemplateId());
659659
}
660660

661-
Pair<VolumeVO, String> volumeDetails = createVolumeFromSnapshot(volume, snapshot, template, originalVolume.getSize());
661+
Pair<VolumeVO, String> volumeDetails = createVolumeFromSnapshot(volume, snapshot, originalVolume.getSize());
662662
createdVolume = volumeDetails.first();
663663

664664
Transaction txn = Transaction.currentTxn();

‎server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ public SnapshotVO createSnapshotOnPrimary(VolumeVO volume, Long policyId, Long s
231231
// Create the Snapshot object and save it so we can return it to the
232232
// user
233233
Type snapshotType = SnapshotVO.getSnapshotType(policyId);
234+
HypervisorType hypervisorType = this._volsDao.getHypervisorType(volumeId);
234235
SnapshotVO snapshotVO = new SnapshotVO(snapshotId, volume.getAccountId(), volume.getId(), null, snapshotName,
235-
(short) snapshotType.ordinal(), snapshotType.name());
236+
(short) snapshotType.ordinal(), snapshotType.name(), hypervisorType);
236237
snapshotVO = _snapshotDao.persist(snapshotVO);
237238
id = snapshotVO.getId();
238239
assert id != null;

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,10 @@ public VMTemplateVO createPrivateTemplate(CreateTemplateCmd command) throws Clou
18441844
// Specify RAW format makes it unusable for snapshots.
18451845
privateTemplate.setFormat(ImageFormat.RAW);
18461846
}
1847-
1847+
1848+
if(snapshot != null)
1849+
privateTemplate.setHypervisorType(snapshot.getHypervisorType());
1850+
18481851
_templateDao.update(templateId, privateTemplate);
18491852

18501853
// add template zone ref for this template

‎setup/db/create-schema.sql‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ CREATE TABLE `cloud`.`cluster` (
228228
`guid` varchar(255) UNIQUE DEFAULT NULL COMMENT 'guid for the cluster',
229229
`pod_id` bigint unsigned NOT NULL COMMENT 'pod id',
230230
`data_center_id` bigint unsigned NOT NULL COMMENT 'data center id',
231-
`hypervisor_type` varchar(255),
231+
`hypervisor_type` varchar(32),
232232
`cluster_type` varchar(64) DEFAULT 'CloudManaged',
233233
PRIMARY KEY (`id`)
234234
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -361,6 +361,7 @@ CREATE TABLE `cloud`.`snapshots` (
361361
`removed` datetime COMMENT 'Date removed. not null if removed',
362362
`backup_snap_id` varchar(255) COMMENT 'Back up uuid of the snapshot',
363363
`prev_snap_id` bigint unsigned COMMENT 'Id of the most recent snapshot',
364+
`hypervisor_type` varchar(32) NOT NULL COMMENT 'hypervisor that the snapshot was taken under',
364365
PRIMARY KEY (`id`)
365366
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
366367

@@ -693,7 +694,7 @@ CREATE TABLE `cloud`.`vm_template` (
693694
`prepopulate` int(1) unsigned NOT NULL default 0 COMMENT 'prepopulate this template to primary storage',
694695
`cross_zones` int(1) unsigned NOT NULL default 0 COMMENT 'Make this template available in all zones',
695696
`extractable` int(1) unsigned NOT NULL default 1 COMMENT 'Is this template extractable',
696-
`hypervisor_type` varchar(255) COMMENT 'hypervisor that the template is belonged to',
697+
`hypervisor_type` varchar(32) COMMENT 'hypervisor that the template is belonged to',
697698
PRIMARY KEY (`id`)
698699
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
699700

@@ -1144,7 +1145,7 @@ CREATE TABLE `cloud`.`guest_os` (
11441145

11451146
CREATE TABLE `cloud`.`guest_os_hypervisor` (
11461147
`id` bigint unsigned NOT NULL auto_increment,
1147-
`hypervisor_type` varchar(255) NOT NULL,
1148+
`hypervisor_type` varchar(32) NOT NULL,
11481149
`guest_os_name` varchar(255) NOT NULL,
11491150
`guest_os_id` bigint unsigned NOT NULL,
11501151
PRIMARY KEY (`id`)

0 commit comments

Comments
 (0)