Skip to content

Commit 949534b

Browse files
authored
Merge pull request phpvirtualbox#186 from chotaire/chot-discard-nvme
Add Discard (TRIM) option and NVME storage controller
2 parents 9871f24 + 07566d3 commit 949534b

File tree

4 files changed

+75
-26
lines changed

4 files changed

+75
-26
lines changed

endpoints/lib/vboxServiceWrappers.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16269,8 +16269,8 @@ class DataFlagsCollection extends VBox_EnumCollection
1626916269
*/
1627016270
class MediumFormatCapabilities extends VBox_Enum
1627116271
{
16272-
public $NameMap = array(0x01 => 'Uuid', 0x02 => 'CreateFixed', 0x04 => 'CreateDynamic', 0x08 => 'CreateSplit2G', 0x10 => 'Differencing', 0x20 => 'Asynchronous', 0x40 => 'File', 0x80 => 'Properties', 0x100 => 'TcpNetworking', 0x200 => 'VFS', 0x3FF => 'CapabilityMask');
16273-
public $ValueMap = array('Uuid' => 0x01, 'CreateFixed' => 0x02, 'CreateDynamic' => 0x04, 'CreateSplit2G' => 0x08, 'Differencing' => 0x10, 'Asynchronous' => 0x20, 'File' => 0x40, 'Properties' => 0x80, 'TcpNetworking' => 0x100, 'VFS' => 0x200, 'CapabilityMask' => 0x3FF);
16272+
public $NameMap = array(0x01 => 'Uuid', 0x02 => 'CreateFixed', 0x04 => 'CreateDynamic', 0x08 => 'CreateSplit2G', 0x10 => 'Differencing', 0x20 => 'Asynchronous', 0x40 => 'File', 0x80 => 'Properties', 0x100 => 'TcpNetworking', 0x200 => 'VFS', 0x400 => 'Discard', 0x800 => 'Preferred', 0xFFF => 'CapabilityMask');
16273+
public $ValueMap = array('Uuid' => 0x01, 'CreateFixed' => 0x02, 'CreateDynamic' => 0x04, 'CreateSplit2G' => 0x08, 'Differencing' => 0x10, 'Asynchronous' => 0x20, 'File' => 0x40, 'Properties' => 0x80, 'TcpNetworking' => 0x100, 'VFS' => 0x200, 'Discard' => 0x400, 'Preferred' => 0x800, 'CapabilityMask' => 0xFFF);
1627416274
}
1627516275

1627616276
/**
@@ -16592,8 +16592,8 @@ class ReasonCollection extends VBox_EnumCollection
1659216592
*/
1659316593
class StorageBus extends VBox_Enum
1659416594
{
16595-
public $NameMap = array(0 => 'Null', 1 => 'IDE', 2 => 'SATA', 3 => 'SCSI', 4 => 'Floppy', 5 => 'SAS', 6 => 'USB');
16596-
public $ValueMap = array('Null' => 0, 'IDE' => 1, 'SATA' => 2, 'SCSI' => 3, 'Floppy' => 4, 'SAS' => 5, 'USB' => 6);
16595+
public $NameMap = array(0 => 'Null', 1 => 'IDE', 2 => 'SATA', 3 => 'SCSI', 4 => 'Floppy', 5 => 'SAS', 6 => 'USB', 7 => 'PCIe');
16596+
public $ValueMap = array('Null' => 0, 'IDE' => 1, 'SATA' => 2, 'SCSI' => 3, 'Floppy' => 4, 'SAS' => 5, 'USB' => 6, 'PCIe' => 7);
1659716597
}
1659816598

1659916599
/**
@@ -16609,8 +16609,8 @@ class StorageBusCollection extends VBox_EnumCollection
1660916609
*/
1661016610
class StorageControllerType extends VBox_Enum
1661116611
{
16612-
public $NameMap = array(0 => 'Null', 1 => 'LsiLogic', 2 => 'BusLogic', 3 => 'IntelAhci', 4 => 'PIIX3', 5 => 'PIIX4', 6 => 'ICH6', 7 => 'I82078', 8 => 'LsiLogicSas', 9 => 'USB');
16613-
public $ValueMap = array('Null' => 0, 'LsiLogic' => 1, 'BusLogic' => 2, 'IntelAhci' => 3, 'PIIX3' => 4, 'PIIX4' => 5, 'ICH6' => 6, 'I82078' => 7, 'LsiLogicSas' => 8, 'USB' => 9);
16612+
public $NameMap = array(0 => 'Null', 1 => 'LsiLogic', 2 => 'BusLogic', 3 => 'IntelAhci', 4 => 'PIIX3', 5 => 'PIIX4', 6 => 'ICH6', 7 => 'I82078', 8 => 'LsiLogicSas', 9 => 'USB', 10 => 'NVMe');
16613+
public $ValueMap = array('Null' => 0, 'LsiLogic' => 1, 'BusLogic' => 2, 'IntelAhci' => 3, 'PIIX3' => 4, 'PIIX4' => 5, 'ICH6' => 6, 'I82078' => 7, 'LsiLogicSas' => 8, 'USB' => 9, 'NVMe' => 10);
1661416614
}
1661516615

1661616616
/**

endpoints/lib/vboxconnector.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ public function remote_machineSave($args) {
19921992
$c->useHostIOCache = $sc['useHostIOCache'];
19931993

19941994
// Set sata port count
1995-
if($sc['bus'] == 'SATA') {
1995+
if(($sc['bus'] == 'SATA')||($sc['bus'] == 'PCIe')) {
19961996
$max = max(1,intval(@$sc['portCount']));
19971997
foreach($sc['mediumAttachments'] as $ma) {
19981998
$max = max($max,(intval($ma['port'])+1));
@@ -2048,8 +2048,16 @@ public function remote_machineSave($args) {
20482048
// HardDisk medium attachment type
20492049
} else if($ma['type'] == 'HardDisk') {
20502050

2051+
$ma['nonRotational']=($ma['nonRotational']?1:0);
2052+
$ma['discard']=($ma['discard']?1:0);
2053+
$ma['hotPluggable']=($ma['hotPluggable']?1:0);
20512054
$m->nonRotationalDevice($name, $ma['port'], $ma['device'], $ma['nonRotational']);
20522055

2056+
// Set Discard (TRIM) Option
2057+
if($this->settings->enableAdvancedConfig) {
2058+
$m->setAutoDiscardForDevice($name, $ma['port'], $ma['device'], $ma['discard']);
2059+
}
2060+
20532061
// Remove IgnoreFlush key?
20542062
if($this->settings->enableHDFlushConfig) {
20552063

@@ -4501,6 +4509,7 @@ private function _machineGetMediumAttachments(&$mas) {
45014509
'temporaryEject' => $ma->temporaryEject,
45024510
'nonRotational' => $ma->nonRotational,
45034511
'hotPluggable' => $ma->hotPluggable,
4512+
'discard' => $ma->discard,
45044513
);
45054514
}
45064515

@@ -5561,7 +5570,8 @@ public function remote_vboxSystemPropertiesGet($args) {
55615570
'PIIX4',
55625571
'ICH6',
55635572
'I82078',
5564-
'USB');
5573+
'USB',
5574+
'NVMe');
55655575

55665576
foreach($scts as $t) {
55675577
$scs[$t] = $sp->getStorageControllerHotplugCapable($t);
@@ -5696,7 +5706,8 @@ private function _util_getIgnoreFlushKey($port,$device,$cType) {
56965706
'intelahci' => 'ahci',
56975707
'lsilogic' => 'lsilogicscsi',
56985708
'buslogic' => 'buslogic',
5699-
'lsilogicsas' => 'lsilogicsas'
5709+
'lsilogicsas' => 'lsilogicsas',
5710+
'nvme' => 'nvme'
57005711
);
57015712

57025713
if(!isset($cTypes[strtolower($cType)])) {
@@ -5831,5 +5842,4 @@ private function _util_resultCodeText($c) {
58315842

58325843
return @$rcodes['0x'.strtoupper(dechex($c))] . ' (0x'.strtoupper(dechex($c)).')';
58335844
}
5834-
}
5835-
5845+
}

js/phpvirtualbox.js

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,7 +2430,7 @@ var vboxMedia = {
24302430
},
24312431

24322432
/**
2433-
* Return true if a medium format supports
2433+
* Return true if a medium format supports Split2G
24342434
*/
24352435
formatSupportsSplit: function(format) {
24362436

@@ -2445,6 +2445,23 @@ var vboxMedia = {
24452445
}
24462446
return false;
24472447
},
2448+
2449+
/**
2450+
* Return true if a medium format supports Discard
2451+
*/
2452+
formatSupportsDiscard: function(format) {
2453+
2454+
var format = format.toLowerCase();
2455+
2456+
var mfs = $('#vboxPane').data('vboxSystemProperties').mediumFormats;
2457+
2458+
for(var i = 0; i < mfs.length; i++) {
2459+
if(mfs[i].id.toLowerCase() == format) {
2460+
return (jQuery.inArray('Discard',mfs[i].capabilities) > -1);
2461+
}
2462+
}
2463+
return false;
2464+
},
24482465

24492466
/**
24502467
* Return printable virtual hard disk variant
@@ -4747,7 +4764,13 @@ var vboxStorage = {
47474764
attrib: 'ignoreFlush',
47484765
runningEnabled: true,
47494766
});
4750-
}
4767+
};
4768+
if($('#vboxPane').data('vboxConfig').enableAdvancedConfig&&vboxMedia.formatSupportsDiscard(ma.medium.format)) {
4769+
opts[opts.length]={
4770+
label: 'Support Discard (TRIM)',
4771+
attrib: 'discard',
4772+
};
4773+
};
47514774
return opts;
47524775
case 'DVD':
47534776
// Host drive
@@ -4881,18 +4904,34 @@ var vboxStorage = {
48814904
},
48824905

48834906
USB: {
4884-
maxPortCount: 8,
4885-
maxDevicesPerPortCount: 1,
4886-
types: ['USB'],
4887-
driveTypes: ['dvd','disk'],
4888-
slotName: function(p,d) { return trans('USB Port %1','VBoxGlobal', null, 'StorageSlot').replace('%1',p); },
4889-
slots: function() {
4890-
var s = {};
4891-
for(var i = 0; i < 8; i++) {
4892-
s[i+'-0'] = trans('USB Port %1','VBoxGlobal', null, 'StorageSlot').replace('%1',i);
4893-
}
4894-
return s;
4895-
}
4907+
maxPortCount: 8,
4908+
maxDevicesPerPortCount: 1,
4909+
types: ['USB'],
4910+
driveTypes: ['dvd','disk'],
4911+
slotName: function(p,d) { return trans('USB Port %1','VBoxGlobal', null, 'StorageSlot').replace('%1',p); },
4912+
slots: function() {
4913+
var s = {};
4914+
for(var i = 0; i < 8; i++) {
4915+
s[i+'-0'] = trans('USB Port %1','VBoxGlobal', null, 'StorageSlot').replace('%1',i);
4916+
}
4917+
return s;
4918+
}
4919+
},
4920+
4921+
PCIe: {
4922+
maxPortCount: 255,
4923+
maxDevicesPerPortCount: 1,
4924+
types: ['NVMe'],
4925+
driveTypes: ['disk'],
4926+
slotName: function(p,d) { return trans('NVMe Port %1','VBoxGlobal', null, 'StorageSlot').replace('%1',p); },
4927+
slots: function() {
4928+
var s = {};
4929+
for(var i = 0; i < 8; i++) {
4930+
s[i+'-0'] = trans('NVMe Port %1','VBoxGlobal', null, 'StorageSlot').replace('%1',i);
4931+
}
4932+
return s;
4933+
},
4934+
displayInherit: 'IDE'
48964935
}
48974936
};
48984937

panes/settingsStorage.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@
945945
$('#vboxSettingsHDInfo').css('display','none');
946946

947947
// Show SATA port count
948-
if(busType == 'SATA') {
948+
if((busType == 'SATA')||(busType == 'PCIe')) {
949949
$(document.forms['frmVboxSettings'].vboxSettingsControllerPortCount).val($(tbl).data('controller').portCount);
950950
$('#vboxSettingsControllerPortCountRow').css('display','');
951951
} else {

0 commit comments

Comments
 (0)