[libvirt] [PATCH go-xml] 1, add memoryBacking for domain. 2, add hugepages, nosharepages, locked, source, access and allocation for memoryBacking. 3, add test case for memoryBacking.

zhenwei.pi posted 1 patch 6 years, 6 months ago
Failed in applying to current master (apply log)
domain.go      | 76 +++++++++++++++++++++++++++++++++++++++++++---------------
domain_test.go | 38 +++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 19 deletions(-)
[libvirt] [PATCH go-xml] 1, add memoryBacking for domain. 2, add hugepages, nosharepages, locked, source, access and allocation for memoryBacking. 3, add test case for memoryBacking.
Posted by zhenwei.pi 6 years, 6 months ago
Signed-off-by: zhenwei.pi <zhenwei.pi@youruncloud.com>
---
 domain.go      | 76 +++++++++++++++++++++++++++++++++++++++++++---------------
 domain_test.go | 38 +++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 19 deletions(-)

diff --git a/domain.go b/domain.go
index d81ac2a..773a83e 100644
--- a/domain.go
+++ b/domain.go
@@ -459,6 +459,43 @@ type DomainMaxMemory struct {
 	Slots uint   `xml:"slots,attr,omitempty"`
 }
 
+type DomainMemoryHugepage struct {
+	Size    uint   `xml:"size,attr"`
+	Unit    string `xml:"unit,attr,omitempty"`
+	Nodeset string `xml:"nodeset,attr,omitempty"`
+}
+
+type DomainMemoryHugepages struct {
+	Hugepages []DomainMemoryHugepage `xml:"page"`
+}
+
+type DomainMemoryNosharepages struct {
+}
+
+type DomainMemoryLocked struct {
+}
+
+type DomainMemorySource struct {
+	Type string `xml:"type,attr,omitempty"`
+}
+
+type DomainMemoryAccess struct {
+	Mode string `xml:"mode,attr,omitempty"`
+}
+
+type DomainMemoryAllocation struct {
+	Mode string `xml:"mode,attr,omitempty"`
+}
+
+type DomainMemoryBacking struct {
+	MemoryHugePages    *DomainMemoryHugepages    `xml:"hugepages"`
+	MemoryNosharepages *DomainMemoryNosharepages `xml:"nosharepages"`
+	MemoryLocked       *DomainMemoryLocked       `xml:"locked"`
+	MemorySource       *DomainMemorySource       `xml:"source"`
+	MemoryAccess       *DomainMemoryAccess       `xml:"access"`
+	MemoryAllocation   *DomainMemoryAllocation   `xml:"allocation"`
+}
+
 type DomainOSType struct {
 	Arch    string `xml:"arch,attr,omitempty"`
 	Machine string `xml:"machine,attr,omitempty"`
@@ -681,25 +718,26 @@ type DomainQEMUCommandline struct {
 // matching the order of XML elements that libvirt
 // will generate when dumping XML.
 type Domain struct {
-	XMLName         xml.Name           `xml:"domain"`
-	Type            string             `xml:"type,attr,omitempty"`
-	Name            string             `xml:"name"`
-	UUID            string             `xml:"uuid,omitempty"`
-	Memory          *DomainMemory      `xml:"memory"`
-	CurrentMemory   *DomainMemory      `xml:"currentMemory"`
-	MaximumMemory   *DomainMaxMemory   `xml:"maxMemory"`
-	VCPU            *DomainVCPU        `xml:"vcpu"`
-	VCPUs           *DomainVCPUs       `xml:"vcpus"`
-	Resource        *DomainResource    `xml:"resource"`
-	SysInfo         *DomainSysInfo     `xml:"sysinfo"`
-	OS              *DomainOS          `xml:"os"`
-	Features        *DomainFeatureList `xml:"features"`
-	CPU             *DomainCPU         `xml:"cpu"`
-	Clock           *DomainClock       `xml:"clock,omitempty"`
-	OnPoweroff      string             `xml:"on_poweroff,omitempty"`
-	OnReboot        string             `xml:"on_reboot,omitempty"`
-	OnCrash         string             `xml:"on_crash,omitempty"`
-	Devices         *DomainDeviceList  `xml:"devices"`
+	XMLName         xml.Name             `xml:"domain"`
+	Type            string               `xml:"type,attr,omitempty"`
+	Name            string               `xml:"name"`
+	UUID            string               `xml:"uuid,omitempty"`
+	Memory          *DomainMemory        `xml:"memory"`
+	CurrentMemory   *DomainMemory        `xml:"currentMemory"`
+	MaximumMemory   *DomainMaxMemory     `xml:"maxMemory"`
+	MemoryBacking   *DomainMemoryBacking `xml:"memoryBacking"`
+	VCPU            *DomainVCPU          `xml:"vcpu"`
+	VCPUs           *DomainVCPUs         `xml:"vcpus"`
+	Resource        *DomainResource      `xml:"resource"`
+	SysInfo         *DomainSysInfo       `xml:"sysinfo"`
+	OS              *DomainOS            `xml:"os"`
+	Features        *DomainFeatureList   `xml:"features"`
+	CPU             *DomainCPU           `xml:"cpu"`
+	Clock           *DomainClock         `xml:"clock,omitempty"`
+	OnPoweroff      string               `xml:"on_poweroff,omitempty"`
+	OnReboot        string               `xml:"on_reboot,omitempty"`
+	OnCrash         string               `xml:"on_crash,omitempty"`
+	Devices         *DomainDeviceList    `xml:"devices"`
 	QEMUCommandline *DomainQEMUCommandline
 }
 
diff --git a/domain_test.go b/domain_test.go
index 3ff1dc1..51d413b 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -435,6 +435,33 @@ var domainTestData = []struct {
 				Value: 16384,
 				Slots: 2,
 			},
+			MemoryBacking: &DomainMemoryBacking{
+				MemoryHugePages: &DomainMemoryHugepages{
+					Hugepages: []DomainMemoryHugepage{
+						{
+							Size:    1,
+							Unit:    "G",
+							Nodeset: "0-3,5",
+						},
+						{
+							Size:    2,
+							Unit:    "M",
+							Nodeset: "4",
+						},
+					},
+				},
+				MemoryNosharepages: &DomainMemoryNosharepages{},
+				MemoryLocked:       &DomainMemoryLocked{},
+				MemorySource: &DomainMemorySource{
+					Type: "file|anonymous",
+				},
+				MemoryAccess: &DomainMemoryAccess{
+					Mode: "shared|private",
+				},
+				MemoryAllocation: &DomainMemoryAllocation{
+					Mode: "immediate|ondemand",
+				},
+			},
 			OS: &DomainOS{
 				Type: &DomainOSType{
 					Arch:    "x86_64",
@@ -532,6 +559,17 @@ var domainTestData = []struct {
 			`  <memory unit="KiB">8192</memory>`,
 			`  <currentMemory unit="KiB">4096</currentMemory>`,
 			`  <maxMemory unit="KiB" slots="2">16384</maxMemory>`,
+			`  <memoryBacking>`,
+			`    <hugepages>`,
+			`      <page size="1" unit="G" nodeset="0-3,5"></page>`,
+			`      <page size="2" unit="M" nodeset="4"></page>`,
+			`    </hugepages>`,
+			`    <nosharepages></nosharepages>`,
+			`    <locked></locked>`,
+			`    <source type="file|anonymous"></source>`,
+			`    <access mode="shared|private"></access>`,
+			`    <allocation mode="immediate|ondemand"></allocation>`,
+			`  </memoryBacking>`,
 			`  <sysinfo type="smbios">`,
 			`    <system>`,
 			`      <entry name="manufacturer">manufacturer</entry>`,
-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH go-xml] 1, add memoryBacking for domain. 2, add hugepages, nosharepages, locked, source, access and allocation for memoryBacking. 3, add test case for memoryBacking.
Posted by Daniel P. Berrange 6 years, 6 months ago
NB, please try to keep the commit message first lin at 72 chars
or less, and then have a blank line, before writing the rest of
the commit message.

I'll fix this one up when pushing.

On Tue, Sep 26, 2017 at 10:12:35AM +0800, zhenwei.pi wrote:
> Signed-off-by: zhenwei.pi <zhenwei.pi@youruncloud.com>
> ---
>  domain.go      | 76 +++++++++++++++++++++++++++++++++++++++++++---------------
>  domain_test.go | 38 +++++++++++++++++++++++++++++
>  2 files changed, 95 insertions(+), 19 deletions(-)
> 

> diff --git a/domain_test.go b/domain_test.go
> index 3ff1dc1..51d413b 100644
> --- a/domain_test.go
> +++ b/domain_test.go
> @@ -435,6 +435,33 @@ var domainTestData = []struct {
>  				Value: 16384,
>  				Slots: 2,
>  			},

> +				MemorySource: &DomainMemorySource{
> +					Type: "file|anonymous",
> +				},
> +				MemoryAccess: &DomainMemoryAccess{
> +					Mode: "shared|private",
> +				},
> +				MemoryAllocation: &DomainMemoryAllocation{
> +					Mode: "immediate|ondemand",
> +				},

In these examples, you should pick either 'file' or 'anonymous',
not include them both. Likewise for the access & allocation
data. I'll fix this when pushing


Reviewed-by: Daniel P. Berrange <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH go-xml] 1, add memoryBacking for domain. 2, add hugepages, nosharepages, locked, source, access and allocation for memoryBacking. 3, add test case for memoryBacking.
Posted by Zhenwei.Pi 6 years, 6 months ago
Signed-off-by: zhenwei.pi <zhenwei.pi@youruncloud.com>

---
  domain.go      | 76 +++++++++++++++++++++++++++++++++++++++++++---------------
  domain_test.go | 38 +++++++++++++++++++++++++++++
  2 files changed, 95 insertions(+), 19 deletions(-)

diff --git a/domain.go b/domain.go
index d81ac2a..773a83e 100644
--- a/domain.go
+++ b/domain.go
@@ -459,6 +459,43 @@ type DomainMaxMemory struct {
  	Slots uint   `xml:"slots,attr,omitempty"`
  }
  
+type DomainMemoryHugepage struct {
+	Size    uint   `xml:"size,attr"`
+	Unit    string `xml:"unit,attr,omitempty"`
+	Nodeset string `xml:"nodeset,attr,omitempty"`
+}
+
+type DomainMemoryHugepages struct {
+	Hugepages []DomainMemoryHugepage `xml:"page"`
+}
+
+type DomainMemoryNosharepages struct {
+}
+
+type DomainMemoryLocked struct {
+}
+
+type DomainMemorySource struct {
+	Type string `xml:"type,attr,omitempty"`
+}
+
+type DomainMemoryAccess struct {
+	Mode string `xml:"mode,attr,omitempty"`
+}
+
+type DomainMemoryAllocation struct {
+	Mode string `xml:"mode,attr,omitempty"`
+}
+
+type DomainMemoryBacking struct {
+	MemoryHugePages    *DomainMemoryHugepages    `xml:"hugepages"`
+	MemoryNosharepages *DomainMemoryNosharepages `xml:"nosharepages"`
+	MemoryLocked       *DomainMemoryLocked       `xml:"locked"`
+	MemorySource       *DomainMemorySource       `xml:"source"`
+	MemoryAccess       *DomainMemoryAccess       `xml:"access"`
+	MemoryAllocation   *DomainMemoryAllocation   `xml:"allocation"`
+}
+
  type DomainOSType struct {
  	Arch    string `xml:"arch,attr,omitempty"`
  	Machine string `xml:"machine,attr,omitempty"`
@@ -681,25 +718,26 @@ type DomainQEMUCommandline struct {
  // matching the order of XML elements that libvirt
  // will generate when dumping XML.
  type Domain struct {
-	XMLName         xml.Name           `xml:"domain"`
-	Type            string             `xml:"type,attr,omitempty"`
-	Name            string             `xml:"name"`
-	UUID            string             `xml:"uuid,omitempty"`
-	Memory          *DomainMemory      `xml:"memory"`
-	CurrentMemory   *DomainMemory      `xml:"currentMemory"`
-	MaximumMemory   *DomainMaxMemory   `xml:"maxMemory"`
-	VCPU            *DomainVCPU        `xml:"vcpu"`
-	VCPUs           *DomainVCPUs       `xml:"vcpus"`
-	Resource        *DomainResource    `xml:"resource"`
-	SysInfo         *DomainSysInfo     `xml:"sysinfo"`
-	OS              *DomainOS          `xml:"os"`
-	Features        *DomainFeatureList `xml:"features"`
-	CPU             *DomainCPU         `xml:"cpu"`
-	Clock           *DomainClock       `xml:"clock,omitempty"`
-	OnPoweroff      string             `xml:"on_poweroff,omitempty"`
-	OnReboot        string             `xml:"on_reboot,omitempty"`
-	OnCrash         string             `xml:"on_crash,omitempty"`
-	Devices         *DomainDeviceList  `xml:"devices"`
+	XMLName         xml.Name             `xml:"domain"`
+	Type            string               `xml:"type,attr,omitempty"`
+	Name            string               `xml:"name"`
+	UUID            string               `xml:"uuid,omitempty"`
+	Memory          *DomainMemory        `xml:"memory"`
+	CurrentMemory   *DomainMemory        `xml:"currentMemory"`
+	MaximumMemory   *DomainMaxMemory     `xml:"maxMemory"`
+	MemoryBacking   *DomainMemoryBacking `xml:"memoryBacking"`
+	VCPU            *DomainVCPU          `xml:"vcpu"`
+	VCPUs           *DomainVCPUs         `xml:"vcpus"`
+	Resource        *DomainResource      `xml:"resource"`
+	SysInfo         *DomainSysInfo       `xml:"sysinfo"`
+	OS              *DomainOS            `xml:"os"`
+	Features        *DomainFeatureList   `xml:"features"`
+	CPU             *DomainCPU           `xml:"cpu"`
+	Clock           *DomainClock         `xml:"clock,omitempty"`
+	OnPoweroff      string               `xml:"on_poweroff,omitempty"`
+	OnReboot        string               `xml:"on_reboot,omitempty"`
+	OnCrash         string               `xml:"on_crash,omitempty"`
+	Devices         *DomainDeviceList    `xml:"devices"`
  	QEMUCommandline *DomainQEMUCommandline
  }
  
diff --git a/domain_test.go b/domain_test.go
index 3ff1dc1..51d413b 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -435,6 +435,33 @@ var domainTestData = []struct {
  				Value: 16384,
  				Slots: 2,
  			},
+			MemoryBacking: &DomainMemoryBacking{
+				MemoryHugePages: &DomainMemoryHugepages{
+					Hugepages: []DomainMemoryHugepage{
+						{
+							Size:    1,
+							Unit:    "G",
+							Nodeset: "0-3,5",
+						},
+						{
+							Size:    2,
+							Unit:    "M",
+							Nodeset: "4",
+						},
+					},
+				},
+				MemoryNosharepages: &DomainMemoryNosharepages{},
+				MemoryLocked:       &DomainMemoryLocked{},
+				MemorySource: &DomainMemorySource{
+					Type: "file|anonymous",
+				},
+				MemoryAccess: &DomainMemoryAccess{
+					Mode: "shared|private",
+				},
+				MemoryAllocation: &DomainMemoryAllocation{
+					Mode: "immediate|ondemand",
+				},
+			},
  			OS: &DomainOS{
  				Type: &DomainOSType{
  					Arch:    "x86_64",
@@ -532,6 +559,17 @@ var domainTestData = []struct {
  			`  <memory unit="KiB">8192</memory>`,
  			`  <currentMemory unit="KiB">4096</currentMemory>`,
  			`  <maxMemory unit="KiB" slots="2">16384</maxMemory>`,
+			`  <memoryBacking>`,
+			`    <hugepages>`,
+			`      <page size="1" unit="G" nodeset="0-3,5"></page>`,
+			`      <page size="2" unit="M" nodeset="4"></page>`,
+			`    </hugepages>`,
+			`    <nosharepages></nosharepages>`,
+			`    <locked></locked>`,
+			`    <source type="file|anonymous"></source>`,
+			`    <access mode="shared|private"></access>`,
+			`    <allocation mode="immediate|ondemand"></allocation>`,
+			`  </memoryBacking>`,
  			`  <sysinfo type="smbios">`,
  			`    <system>`,
  			`      <entry name="manufacturer">manufacturer</entry>`,
-- 
2.7.4


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list