Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.cloudstack.quota.dao.QuotaUsageDao;
import org.apache.cloudstack.quota.vo.QuotaAccountVO;
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -47,8 +46,10 @@
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

@RunWith(MockitoJUnitRunner.class)
public class QuotaAlertManagerImplTest extends TestCase {
Expand Down Expand Up @@ -179,7 +180,11 @@ public void testSendQuotaAlert() throws UnsupportedEncodingException, MessagingE
public void testGetDifferenceDays() {
Date now = new Date();
assertTrue(QuotaAlertManagerImpl.getDifferenceDays(now, now) == 0L);
assertTrue(QuotaAlertManagerImpl.getDifferenceDays(now, new DateTime(now).plusDays(1).toDate()) == 1L);
Calendar c = Calendar.getInstance();
c.setTimeZone(TimeZone.getTimeZone("UTC"));
Calendar c2 = (Calendar) c.clone();
c2.add(Calendar.DATE, 1);
assertEquals(1L, QuotaAlertManagerImpl.getDifferenceDays(c.getTime(), c2.getTime()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DevicesDef;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef.DeviceType;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef.DiscardType;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef.DiskProtocol;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.FeaturesDef;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.FilesystemDef;
Expand Down Expand Up @@ -2124,6 +2125,11 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
} else {
final int devId = volume.getDiskSeq().intValue();

if (diskBusType == DiskDef.DiskBus.SCSI ) {
disk.setQemuDriver(true);
disk.setDiscard(DiscardType.UNMAP);
}

if (pool.getType() == StoragePoolType.RBD) {
/*
For RBD pools we use the secret mechanism in libvirt.
Expand Down Expand Up @@ -2322,6 +2328,10 @@ public synchronized String attachOrDetachDisk(final Connect conn,
}

diskdef = new DiskDef();
if (busT == DiskDef.DiskBus.SCSI) {
diskdef.setQemuDriver(true);
diskdef.setDiscard(DiscardType.UNMAP);
}
if (attachingPool.getType() == StoragePoolType.RBD) {
diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), attachingPool.getAuthUserName(),
attachingPool.getUuid(), devId, busT, DiskProtocol.RBD, DiskDef.DiskFmtType.RAW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,23 @@ public String toString() {
}
}

public enum DiscardType {
IGNORE("ignore"), UNMAP("unmap");
String _discardType;
DiscardType(String discardType) {
_discardType = discardType;
}

@Override
public String toString() {
if (_discardType == null) {
return "ignore";
}
return _discardType;
}

}

private DeviceType _deviceType; /* floppy, disk, cdrom */
private DiskType _diskType;
private DiskProtocol _diskProtocol;
Expand All @@ -565,6 +582,15 @@ public String toString() {
private DiskCacheMode _diskCacheMode;
private String _serial;
private boolean qemuDriver = true;
private DiscardType _discard = DiscardType.IGNORE;

public DiscardType getDiscard() {
return _discard;
}

public void setDiscard(DiscardType discard) {
this._discard = discard;
}

public void setDeviceType(DeviceType deviceType) {
_deviceType = deviceType;
Expand Down Expand Up @@ -763,7 +789,11 @@ public String toString() {
diskBuilder.append(">\n");
if(qemuDriver) {
diskBuilder.append("<driver name='qemu'" + " type='" + _diskFmtType
+ "' cache='" + _diskCacheMode + "' " + "/>\n");
+ "' cache='" + _diskCacheMode + "' ");
if(_discard != null && _discard != DiscardType.IGNORE) {
diskBuilder.append("discard='" + _discard.toString() + "' ");
}
diskBuilder.append("/>\n");
}

if (_diskType == DiskType.FILE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef.DeviceType;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef.DiscardType;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef.DiskProtocol;
import com.cloud.storage.JavaStorageLayer;
import com.cloud.storage.Storage.ImageFormat;
Expand Down Expand Up @@ -995,6 +996,11 @@ protected synchronized String attachOrDetachDisk(final Connect conn, final boole
}
}
diskdef = new DiskDef();
if (busT == DiskDef.DiskBus.SCSI) {
diskdef.setQemuDriver(true);
diskdef.setDiscard(DiscardType.UNMAP);
}

diskdef.setSerial(serial);
if (attachingPool.getType() == StoragePoolType.RBD) {
if(resource.getHypervisorType() == Hypervisor.HypervisorType.LXC){
Expand Down