kvm arm64 auto manage nvram #6860

Merged
merged 1 commit into from Jan 24, 2017
Jump to file or symbol
Failed to load files and symbols.
+6 −90
Split
@@ -48,9 +48,6 @@ type domainParams interface {
Loader() string
// NetworkInfo contains the network interfaces to create in the domain.
NetworkInfo() []InterfaceInfo
- // NVRAM returns the path to the UEFI variable storage drive. This is a
- // "pflash" drive where UEFI stores variables used for booting an image.
- NVRAM() string
// RAM returns the amount of RAM to use.
RAM() uint64
// ValidateDomainParams returns nil if the domainParams are valid.
@@ -152,8 +149,6 @@ func generateOSElement(p domainParams) OS {
ReadOnly: "yes",
Type: "pflash",
},
-
- NVRAMVars: p.NVRAM(),
}
default:
return OS{Type: OSType{Text: "hvm"}}
@@ -220,9 +215,6 @@ type OS struct {
Type OSType `xml:"type"`
// Loader is a pointer so it is omitted if empty.
Loader *NVRAMCode `xml:"loader,omitempty"`
- // NVRAMVars is the writable storage for UEFI to store variables.
- // See: https://libvirt.org/formatdomain.html#elementsOS
- NVRAMVars string `xml:"nvram,omitempty"`
}
// OSType provides details that are required on certain architectures, e.g.
@@ -68,7 +68,6 @@ var arm64DomainStr = `
<os>
<type arch="aarch64" machine="virt">hvm</type>
<loader readonly="yes" type="pflash">/shared/readonly.fd</loader>
- <nvram>/private/writable.fd</nvram>
</os>
<features>
<gic version="host"></gic>
@@ -125,7 +124,6 @@ func (domainXMLSuite) TestNewDomain(c *gc.C) {
params := dummyParams{ifaceInfo: ifaces, diskInfo: disks, memory: 1024, cpuCores: 2, hostname: "juju-someid", arch: test.arch}
if test.arch == "arm64" {
- params.nvram = "/private/writable.fd"
params.loader = "/shared/readonly.fd"
}
@@ -68,8 +68,6 @@ type CreateMachineParams struct {
RootDisk uint64
Interfaces []libvirt.InterfaceInfo
- nvram string
-
disks []libvirt.DiskInfo
findPath func(string) (string, error)
@@ -92,12 +90,6 @@ func (p CreateMachineParams) Loader() string {
return nvramCode
}
-// NVRAM is the path to the "pflash" drive where UEFI stores variables related
-// to booting an image. At the time of this writing only ARM64 uses this.
-func (p CreateMachineParams) NVRAM() string {
- return p.nvram
-}
-
// Host implements libvirt.domainParams.
func (p CreateMachineParams) Host() string {
return p.Hostname
@@ -186,10 +178,6 @@ func CreateMachine(params CreateMachineParams) error {
return errors.Annotate(err, "failed to write instance metadata")
}
- if err = createNVRAM(params); err != nil {
- return errors.Annotatef(err, "failed to create NVRAM on %q for %q", params.Arch(), params.Host())
- }
-
dsPath, err := writeDatasourceVolume(params)
if err != nil {
return errors.Annotatef(err, "failed to write data source volume for %q", params.Host())
@@ -257,9 +245,13 @@ func DestroyMachine(c *kvmContainer) error {
logger.Infof("`virsh destroy %s` failed: %q", c.Name(), err)
}
+ // The nvram flag here removes the pflash drive for us. There is also a
+ // `remove-all-storage` flag, but it is unclear if that would also remove
+ // the backing store which we don't want to do. So we remove those manually
+ // after undefining.
_, err = c.runCmd("virsh", "undefine", "--nvram", c.Name())
if err != nil {
- logger.Infof("`virsh undefine %s` failed: %q", c.Name(), err)
+ logger.Infof("`virsh undefine --nvram %s` failed: %q", c.Name(), err)
}
guestBase, err := guestPath(c.pathfinder)
if err != nil {
@@ -471,40 +463,6 @@ func writeRootDisk(params CreateMachineParams) (string, error) {
return imgPath, nil
}
-// createNVRAM creates an empty NVRAM (pflash) drive. This is required for
-// booting UEFI images. As of Xenial Two pflash drives are required. One
-// provides the actual firmware which can be shared read-only and is provided
-// in a shared directory by qemu-efi. It is in /usr/share/AAVMF/AAVMF_CODE.fd.
-// The the second is for storing variables to be read on subsequent boots.
-// This creates that second drive from a template.
-func createNVRAM(params CreateMachineParams) error {
- if params.Arch() != arch.ARM64 {
- return nil
- }
-
- guestBase, err := guestPath(params.findPath)
- if err != nil {
- return errors.Trace(err)
- }
- params.nvram = filepath.Join(guestBase, fmt.Sprintf("%s-VARS.fd", params.Host()))
- f, err := os.Create(params.nvram)
- if err != nil {
- return errors.Trace(err)
- }
- defer func() {
- err = f.Close()
- if err != nil {
- logger.Infof("failed to close %q %s", f.Name(), err)
- }
- }()
-
- err = f.Truncate(64 * (1 << 20))
- if err != nil {
- return errors.Annotatef(err, "failed to create NVRAM %q", f.Name())
- }
- return nil
-}
-
// pool info parses and returns the output of `virsh pool-info <poolname>`.
func poolInfo(runCmd runFunc) (*libvirtPool, error) {
output, err := runCmd("virsh", "pool-info", poolName)
@@ -4,9 +4,7 @@
package kvm
import (
- "crypto/sha256"
"errors"
- "fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -116,36 +114,6 @@ func (libvirtInternalSuite) TestWriteDomainXMLMissingBothDisk(c *gc.C) {
c.Assert(got, gc.Matches, "")
}
-func (libvirtInternalSuite) TestCreateNVRAMOnARM64(c *gc.C) {
- d := c.MkDir()
-
- err := os.MkdirAll(filepath.Join(d, "kvm", "guests"), 0755)
- c.Check(err, jc.ErrorIsNil)
- p := CreateMachineParams{
- Hostname: "host00",
- arch: "arm64",
- findPath: func(string) (string, error) { return d, nil },
- }
- err = createNVRAM(p)
- c.Check(err, jc.ErrorIsNil)
- data, err := ioutil.ReadFile(filepath.Join(d, "kvm", "guests", "host00-VARS.fd"))
- c.Check(err, jc.ErrorIsNil)
- got := fmt.Sprintf("%x", sha256.Sum256(data))
- c.Assert(got, gc.Equals, "3b6a07d0d404fab4e23b6d34bc6696a6a312dd92821332385e5af7c01c421351")
-}
-
-func (libvirtInternalSuite) TestCreateNVRAMOnAMD64(c *gc.C) {
- d := c.MkDir()
-
- p := CreateMachineParams{
- Hostname: "host00",
- arch: "amd64",
- findPath: func(string) (string, error) { return d, nil },
- }
- err := createNVRAM(p)
- c.Assert(err, jc.ErrorIsNil)
-}
-
func (libvirtInternalSuite) TestWriteDomainXMLNoHostname(c *gc.C) {
d := c.MkDir()
@@ -186,7 +186,7 @@ func (commandWrapperSuite) TestDestroyMachineFails(c *gc.C) {
})
log := c.GetTestLog()
c.Check(log, jc.Contains, "`virsh destroy aname` failed")
- c.Check(log, jc.Contains, "`virsh undefine aname` failed")
+ c.Check(log, jc.Contains, "`virsh undefine --nvram aname` failed")
c.Assert(err, jc.ErrorIsNil)
}