The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6699
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === This is to allow interop with the storage package.
From b15959ae5f48f2a206a87ac9b8b363edfa3320c9 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 15:34:39 +0000 Subject: [PATCH 1/5] lxd/device/device/instance: Removes interface in place of instance.Instance Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/device/device_instance.go | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 lxd/device/device_instance.go diff --git a/lxd/device/device_instance.go b/lxd/device/device_instance.go deleted file mode 100644 index aa5d36484a..0000000000 --- a/lxd/device/device_instance.go +++ /dev/null @@ -1,23 +0,0 @@ -package device - -import ( - deviceConfig "github.com/lxc/lxd/lxd/device/config" - "github.com/lxc/lxd/lxd/instance/instancetype" -) - -// Instance is an interface that allows us to identify an Instance and its properties. -// It is intended that this interface be entirely comprised of functions which cannot be blocking -// irrespective of when they're called in the instance lifecycle. -type Instance interface { - Name() string - Type() instancetype.Type - Project() string - Path() string - DevicesPath() string - RootfsPath() string - LogPath() string - ExpandedConfig() map[string]string - LocalDevices() deviceConfig.Devices - ExpandedDevices() deviceConfig.Devices - DeviceEventHandler(*deviceConfig.RunConfig) error -} From 3a6e685d0291fc8191636bfa90d8a24aeae8185e Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 15:35:21 +0000 Subject: [PATCH 2/5] lxd/container: Replaces device.Instance with instance.Instance Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/container.go | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/lxd/container.go b/lxd/container.go index 36055a0b39..1aac67580c 100644 --- a/lxd/container.go +++ b/lxd/container.go @@ -42,29 +42,14 @@ import ( func init() { // Expose instanceLoadNodeAll to the device package converting the response to a slice of Instances. // This is because container types are defined in the main package and are not importable. - device.InstanceLoadNodeAll = func(s *state.State) ([]device.Instance, error) { - containers, err := instanceLoadNodeAll(s, instancetype.Any) - if err != nil { - return nil, err - } - - identifiers := []device.Instance{} - for _, v := range containers { - identifiers = append(identifiers, device.Instance(v)) - } - - return identifiers, nil + device.InstanceLoadNodeAll = func(s *state.State) ([]instance.Instance, error) { + return instanceLoadNodeAll(s, instancetype.Any) } // Expose instance.LoadByProjectAndName to the device package converting the response to an Instance. // This is because container types are defined in the main package and are not importable. - device.InstanceLoadByProjectAndName = func(s *state.State, project, name string) (device.Instance, error) { - container, err := instance.LoadByProjectAndName(s, project, name) - if err != nil { - return nil, err - } - - return device.Instance(container), nil + device.InstanceLoadByProjectAndName = func(s *state.State, project, name string) (instance.Instance, error) { + return instance.LoadByProjectAndName(s, project, name) } // Expose instanceValidDevices to the instance package. This is because it relies on From 77dafa72ed95ca894b151d378f3ab83dad6c1599 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 15:35:42 +0000 Subject: [PATCH 3/5] lxd/storage: Replaces device.Instance with instance.Instance Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lxd/storage.go b/lxd/storage.go index a306df945d..3351aed653 100644 --- a/lxd/storage.go +++ b/lxd/storage.go @@ -829,8 +829,8 @@ func storagePoolDriversCacheUpdate(s *state.State) { // storageVolumeMount initialises a new storage interface and checks the pool and volume are // mounted. If they are not then they are mounted. -func storageVolumeMount(state *state.State, poolName string, volumeName string, volumeTypeName string, instance device.Instance) error { - c, ok := instance.(*containerLXC) +func storageVolumeMount(state *state.State, poolName string, volumeName string, volumeTypeName string, inst instance.Instance) error { + c, ok := inst.(*containerLXC) if !ok { return fmt.Errorf("Received non-LXC container instance") } @@ -924,7 +924,7 @@ func storageVolumeUmount(state *state.State, poolName string, volumeName string, // storageRootFSApplyQuota applies a quota to an instance if it can, if it cannot then it will // return false indicating that the quota needs to be stored in volatile to be applied on next boot. -func storageRootFSApplyQuota(state *state.State, inst device.Instance, size string) error { +func storageRootFSApplyQuota(state *state.State, inst instance.Instance, size string) error { c, ok := inst.(*containerLXC) if !ok { return fmt.Errorf("Received non-LXC container instance") From 8a2702351249bef13c839e5cd73aa07e0235b5f4 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 15:36:39 +0000 Subject: [PATCH 4/5] lxd/device: Replaces device.Instance with instance.Instance Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/device/device.go | 13 +++++++------ lxd/device/device_utils_disk.go | 5 +++-- lxd/device/device_utils_instance.go | 5 +++-- lxd/device/device_utils_network.go | 3 ++- lxd/device/device_utils_unix_events.go | 9 +++++---- lxd/device/device_utils_usb_events.go | 9 +++++---- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lxd/device/device.go b/lxd/device/device.go index c608f80bc9..5e93458c31 100644 --- a/lxd/device/device.go +++ b/lxd/device/device.go @@ -4,6 +4,7 @@ import ( "fmt" deviceConfig "github.com/lxc/lxd/lxd/device/config" + "github.com/lxc/lxd/lxd/instance" "github.com/lxc/lxd/lxd/state" ) @@ -73,7 +74,7 @@ type device interface { Device // init stores the Instance, daemon State and Config into device and performs any setup. - init(Instance, *state.State, string, deviceConfig.Device, VolatileGetter, VolatileSetter) + init(instance.Instance, *state.State, string, deviceConfig.Device, VolatileGetter, VolatileSetter) // validateConfig checks Config stored by init() is valid for the instance type. validateConfig() error @@ -81,7 +82,7 @@ type device interface { // deviceCommon represents the common struct for all devices. type deviceCommon struct { - instance Instance + instance instance.Instance name string config deviceConfig.Device state *state.State @@ -93,8 +94,8 @@ type deviceCommon struct { // It also needs to be provided with volatile get and set functions for the device to allow // persistent data to be accessed. This is implemented as part of deviceCommon so that the majority // of devices don't need to implement it and can just embed deviceCommon. -func (d *deviceCommon) init(instance Instance, state *state.State, name string, conf deviceConfig.Device, volatileGet VolatileGetter, volatileSet VolatileSetter) { - d.instance = instance +func (d *deviceCommon) init(inst instance.Instance, state *state.State, name string, conf deviceConfig.Device, volatileGet VolatileGetter, volatileSet VolatileSetter) { + d.instance = inst d.name = name d.config = conf d.state = state @@ -132,7 +133,7 @@ func (d *deviceCommon) Remove() error { // If the device type is valid, but the other config validation fails then an instantiated device // is still returned with the validation error. If an unknown device is requested or the device is // not compatible with the instance type then an ErrUnsupportedDevType error is returned. -func New(instance Instance, state *state.State, name string, conf deviceConfig.Device, volatileGet VolatileGetter, volatileSet VolatileSetter) (Device, error) { +func New(inst instance.Instance, state *state.State, name string, conf deviceConfig.Device, volatileGet VolatileGetter, volatileSet VolatileSetter) (Device, error) { if conf["type"] == "" { return nil, fmt.Errorf("Missing device type for device '%s'", name) } @@ -151,7 +152,7 @@ func New(instance Instance, state *state.State, name string, conf deviceConfig.D } // Init the device and run validation of supplied config. - dev.init(instance, state, name, conf, volatileGet, volatileSet) + dev.init(inst, state, name, conf, volatileGet, volatileSet) err := dev.validateConfig() // We still return the instantiated device here, as in some scenarios the caller diff --git a/lxd/device/device_utils_disk.go b/lxd/device/device_utils_disk.go index 16da30c264..25f21090fa 100644 --- a/lxd/device/device_utils_disk.go +++ b/lxd/device/device_utils_disk.go @@ -11,18 +11,19 @@ import ( "golang.org/x/sys/unix" + "github.com/lxc/lxd/lxd/instance" "github.com/lxc/lxd/lxd/state" "github.com/lxc/lxd/shared" ) // StorageVolumeMount checks if storage volume is mounted and if not tries to mount it. -var StorageVolumeMount func(s *state.State, poolName string, volumeName string, volumeTypeName string, instance Instance) error +var StorageVolumeMount func(s *state.State, poolName string, volumeName string, volumeTypeName string, inst instance.Instance) error // StorageVolumeUmount unmounts a storage volume. var StorageVolumeUmount func(s *state.State, poolName string, volumeName string, volumeType int) error // StorageRootFSApplyQuota applies a new quota. -var StorageRootFSApplyQuota func(s *state.State, instance Instance, size string) error +var StorageRootFSApplyQuota func(s *state.State, inst instance.Instance, size string) error // BlockFsDetect detects the type of block device. func BlockFsDetect(dev string) (string, error) { diff --git a/lxd/device/device_utils_instance.go b/lxd/device/device_utils_instance.go index 9fdd778750..d001461ee5 100644 --- a/lxd/device/device_utils_instance.go +++ b/lxd/device/device_utils_instance.go @@ -5,14 +5,15 @@ import ( "sync" deviceConfig "github.com/lxc/lxd/lxd/device/config" + "github.com/lxc/lxd/lxd/instance" "github.com/lxc/lxd/lxd/state" ) // InstanceLoadNodeAll returns all local instance configs. -var InstanceLoadNodeAll func(s *state.State) ([]Instance, error) +var InstanceLoadNodeAll func(s *state.State) ([]instance.Instance, error) // InstanceLoadByProjectAndName returns instance config by project and name. -var InstanceLoadByProjectAndName func(s *state.State, project, name string) (Instance, error) +var InstanceLoadByProjectAndName func(s *state.State, project, name string) (instance.Instance, error) // reservedDevicesMutex used to coordinate access for checking reserved devices. var reservedDevicesMutex sync.Mutex diff --git a/lxd/device/device_utils_network.go b/lxd/device/device_utils_network.go index 78c3232300..02016faa24 100644 --- a/lxd/device/device_utils_network.go +++ b/lxd/device/device_utils_network.go @@ -14,6 +14,7 @@ import ( "sync" deviceConfig "github.com/lxc/lxd/lxd/device/config" + "github.com/lxc/lxd/lxd/instance" "github.com/lxc/lxd/lxd/state" "github.com/lxc/lxd/lxd/util" "github.com/lxc/lxd/shared" @@ -135,7 +136,7 @@ func NetworkRemoveInterface(nic string) error { } // NetworkRemoveInterfaceIfNeeded removes a network interface by name but only if no other instance is using it. -func NetworkRemoveInterfaceIfNeeded(state *state.State, nic string, current Instance, parent string, vlanID string) error { +func NetworkRemoveInterfaceIfNeeded(state *state.State, nic string, current instance.Instance, parent string, vlanID string) error { // Check if it's used by another instance. instances, err := InstanceLoadNodeAll(state) if err != nil { diff --git a/lxd/device/device_utils_unix_events.go b/lxd/device/device_utils_unix_events.go index 1ef75eef40..ec12643683 100644 --- a/lxd/device/device_utils_unix_events.go +++ b/lxd/device/device_utils_unix_events.go @@ -7,6 +7,7 @@ import ( "sync" deviceConfig "github.com/lxc/lxd/lxd/device/config" + "github.com/lxc/lxd/lxd/instance" "github.com/lxc/lxd/lxd/state" "github.com/lxc/lxd/shared" log "github.com/lxc/lxd/shared/log15" @@ -32,7 +33,7 @@ var unixHandlers = map[string]UnixSubscription{} var unixMutex sync.Mutex // unixRegisterHandler registers a handler function to be called whenever a Unix device event occurs. -func unixRegisterHandler(s *state.State, instance Instance, deviceName, path string, handler func(UnixEvent) (*deviceConfig.RunConfig, error)) error { +func unixRegisterHandler(s *state.State, inst instance.Instance, deviceName, path string, handler func(UnixEvent) (*deviceConfig.RunConfig, error)) error { if path == "" || handler == nil { return fmt.Errorf("Invalid subscription") } @@ -41,7 +42,7 @@ func unixRegisterHandler(s *state.State, instance Instance, deviceName, path str defer unixMutex.Unlock() // Null delimited string of project name, instance name and device name. - key := fmt.Sprintf("%s\000%s\000%s", instance.Project(), instance.Name(), deviceName) + key := fmt.Sprintf("%s\000%s\000%s", inst.Project(), inst.Name(), deviceName) unixHandlers[key] = UnixSubscription{ Path: path, Handler: handler, @@ -59,12 +60,12 @@ func unixRegisterHandler(s *state.State, instance Instance, deviceName, path str } // unixUnregisterHandler removes a registered Unix handler function for a device. -func unixUnregisterHandler(s *state.State, instance Instance, deviceName string) error { +func unixUnregisterHandler(s *state.State, inst instance.Instance, deviceName string) error { unixMutex.Lock() defer unixMutex.Unlock() // Null delimited string of project name, instance name and device name. - key := fmt.Sprintf("%s\000%s\000%s", instance.Project(), instance.Name(), deviceName) + key := fmt.Sprintf("%s\000%s\000%s", inst.Project(), inst.Name(), deviceName) sub, exists := unixHandlers[key] if !exists { diff --git a/lxd/device/device_utils_usb_events.go b/lxd/device/device_utils_usb_events.go index 5f04530a7b..dfa02ba796 100644 --- a/lxd/device/device_utils_usb_events.go +++ b/lxd/device/device_utils_usb_events.go @@ -8,6 +8,7 @@ import ( "sync" deviceConfig "github.com/lxc/lxd/lxd/device/config" + "github.com/lxc/lxd/lxd/instance" "github.com/lxc/lxd/lxd/state" log "github.com/lxc/lxd/shared/log15" "github.com/lxc/lxd/shared/logger" @@ -34,22 +35,22 @@ var usbHandlers = map[string]func(USBEvent) (*deviceConfig.RunConfig, error){} var usbMutex sync.Mutex // usbRegisterHandler registers a handler function to be called whenever a USB device event occurs. -func usbRegisterHandler(instance Instance, deviceName string, handler func(USBEvent) (*deviceConfig.RunConfig, error)) { +func usbRegisterHandler(inst instance.Instance, deviceName string, handler func(USBEvent) (*deviceConfig.RunConfig, error)) { usbMutex.Lock() defer usbMutex.Unlock() // Null delimited string of project name, instance name and device name. - key := fmt.Sprintf("%s\000%s\000%s", instance.Project(), instance.Name(), deviceName) + key := fmt.Sprintf("%s\000%s\000%s", inst.Project(), inst.Name(), deviceName) usbHandlers[key] = handler } // usbUnregisterHandler removes a registered USB handler function for a device. -func usbUnregisterHandler(instance Instance, deviceName string) { +func usbUnregisterHandler(inst instance.Instance, deviceName string) { usbMutex.Lock() defer usbMutex.Unlock() // Null delimited string of project name, instance name and device name. - key := fmt.Sprintf("%s\000%s\000%s", instance.Project(), instance.Name(), deviceName) + key := fmt.Sprintf("%s\000%s\000%s", inst.Project(), inst.Name(), deviceName) delete(usbHandlers, key) } From fdc80a1b317e23d10fbe1062a4034648edf1a4aa Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 15:38:11 +0000 Subject: [PATCH 5/5] lxd/device: Renames d.instance to d.inst to avoid conflicts with instance package Also for consistency with other package usage of instance.Instance. Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/device/device.go | 4 +-- lxd/device/disk.go | 50 +++++++++++++++---------------- lxd/device/gpu.go | 20 ++++++------- lxd/device/infiniband_physical.go | 8 ++--- lxd/device/infiniband_sriov.go | 8 ++--- lxd/device/nic_bridged.go | 38 +++++++++++------------ lxd/device/nic_ipvlan.go | 4 +-- lxd/device/nic_macvlan.go | 4 +-- lxd/device/nic_p2p.go | 2 +- lxd/device/nic_physical.go | 2 +- lxd/device/nic_routed.go | 4 +-- lxd/device/nic_sriov.go | 2 +- lxd/device/proxy.go | 18 +++++------ lxd/device/unix_common.go | 16 +++++----- lxd/device/usb.go | 14 ++++----- 15 files changed, 97 insertions(+), 97 deletions(-) diff --git a/lxd/device/device.go b/lxd/device/device.go index 5e93458c31..45ba6a7bca 100644 --- a/lxd/device/device.go +++ b/lxd/device/device.go @@ -82,7 +82,7 @@ type device interface { // deviceCommon represents the common struct for all devices. type deviceCommon struct { - instance instance.Instance + inst instance.Instance name string config deviceConfig.Device state *state.State @@ -95,7 +95,7 @@ type deviceCommon struct { // persistent data to be accessed. This is implemented as part of deviceCommon so that the majority // of devices don't need to implement it and can just embed deviceCommon. func (d *deviceCommon) init(inst instance.Instance, state *state.State, name string, conf deviceConfig.Device, volatileGet VolatileGetter, volatileSet VolatileSetter) { - d.instance = inst + d.inst = inst d.name = name d.config = conf d.state = state diff --git a/lxd/device/disk.go b/lxd/device/disk.go index 76dc6bcefc..252a42b57c 100644 --- a/lxd/device/disk.go +++ b/lxd/device/disk.go @@ -49,7 +49,7 @@ func (d *disk) isRequired(devConfig deviceConfig.Device) bool { // validateConfig checks the supplied config for correctness. func (d *disk) validateConfig() error { - if d.instance.Type() != instancetype.Container && d.instance.Type() != instancetype.VM { + if d.inst.Type() != instancetype.Container && d.inst.Type() != instancetype.VM { return ErrUnsupportedDevType } @@ -128,7 +128,7 @@ func (d *disk) validateConfig() error { // same path, so that if merged profiles share the same the path and then one is removed // this can still be cleanly removed. pathCount := 0 - for _, devConfig := range d.instance.LocalDevices() { + for _, devConfig := range d.inst.LocalDevices() { if devConfig["type"] == "disk" && devConfig["path"] == d.config["path"] { pathCount++ if pathCount > 1 { @@ -164,7 +164,7 @@ func (d *disk) validateConfig() error { // and not a profile device (check for non-empty instance name), and we have least // one expanded device (this is so we only do this expensive check after devices // have been expanded). - if d.instance.Name() != "" && len(d.instance.ExpandedDevices()) > 0 && d.config["source"] != "" && d.config["path"] != "/" { + if d.inst.Name() != "" && len(d.inst.ExpandedDevices()) > 0 && d.config["source"] != "" && d.config["path"] != "/" { isAvailable, err := d.state.Cluster.StorageVolumeIsAvailable(d.config["pool"], d.config["source"]) if err != nil { return fmt.Errorf("Check if volume is available: %v", err) @@ -182,7 +182,7 @@ func (d *disk) validateConfig() error { func (d *disk) getDevicePath(devName string, devConfig deviceConfig.Device) string { relativeDestPath := strings.TrimPrefix(devConfig["path"], "/") devPath := deviceNameEncode(deviceJoinPath("disk", devName, relativeDestPath)) - return filepath.Join(d.instance.DevicesPath(), devPath) + return filepath.Join(d.inst.DevicesPath(), devPath) } // validateEnvironment checks the runtime environment for correctness. @@ -191,7 +191,7 @@ func (d *disk) validateEnvironment() error { return fmt.Errorf("shiftfs is required by disk entry but isn't supported on system") } - if d.instance.Type() != instancetype.VM && d.config["source"] == diskSourceCloudInit { + if d.inst.Type() != instancetype.VM && d.config["source"] == diskSourceCloudInit { return fmt.Errorf("disks with source=%s are only supported by virtual machines", diskSourceCloudInit) } @@ -211,7 +211,7 @@ func (d *disk) Start() (*deviceConfig.RunConfig, error) { return nil, err } - if d.instance.Type() == instancetype.VM { + if d.inst.Type() == instancetype.VM { return d.startVM() } @@ -232,7 +232,7 @@ func (d *disk) startContainer() (*deviceConfig.RunConfig, error) { return err } - err = d.instance.DeviceEventHandler(&runConf) + err = d.inst.DeviceEventHandler(&runConf) if err != nil { return err } @@ -244,7 +244,7 @@ func (d *disk) startContainer() (*deviceConfig.RunConfig, error) { if shared.IsRootDiskDevice(d.config) { // Set the rootfs path. rootfs := deviceConfig.RootFSEntryItem{ - Path: d.instance.RootfsPath(), + Path: d.inst.RootfsPath(), } // Read-only rootfs (unlikely to work very well). @@ -300,7 +300,7 @@ func (d *disk) startContainer() (*deviceConfig.RunConfig, error) { return nil, err } - _, volume, err := d.state.Cluster.StoragePoolNodeVolumeGetTypeByProject(d.instance.Project(), d.config["source"], db.StoragePoolVolumeTypeCustom, poolID) + _, volume, err := d.state.Cluster.StoragePoolNodeVolumeGetTypeByProject(d.inst.Project(), d.config["source"], db.StoragePoolVolumeTypeCustom, poolID) if err != nil { return nil, err } @@ -397,7 +397,7 @@ func (d *disk) postStart() error { // Update applies configuration changes to a started device. func (d *disk) Update(oldDevices deviceConfig.Devices, isRunning bool) error { - if d.instance.Type() == instancetype.VM { + if d.inst.Type() == instancetype.VM { if shared.IsRootDiskDevice(d.config) { return nil } @@ -407,7 +407,7 @@ func (d *disk) Update(oldDevices deviceConfig.Devices, isRunning bool) error { if shared.IsRootDiskDevice(d.config) { // Make sure we have a valid root disk device (and only one). - expandedDevices := d.instance.ExpandedDevices() + expandedDevices := d.inst.ExpandedDevices() newRootDiskDeviceKey, _, err := shared.GetRootDiskDevice(expandedDevices.CloneNative()) if err != nil { return errors.Wrap(err, "Detect root disk device") @@ -456,7 +456,7 @@ func (d *disk) Update(oldDevices deviceConfig.Devices, isRunning bool) error { return err } - err = d.instance.DeviceEventHandler(&runConf) + err = d.inst.DeviceEventHandler(&runConf) if err != nil { return err } @@ -466,13 +466,13 @@ func (d *disk) Update(oldDevices deviceConfig.Devices, isRunning bool) error { } func (d *disk) applyQuota(newSize string) error { - return StorageRootFSApplyQuota(d.state, d.instance, newSize) + return StorageRootFSApplyQuota(d.state, d.inst, newSize) } // generateLimits adds a set of cgroup rules to apply specified limits to the supplied RunConfig. func (d *disk) generateLimits(runConf *deviceConfig.RunConfig) error { // Disk priority limits. - diskPriority := d.instance.ExpandedConfig()["limits.disk.priority"] + diskPriority := d.inst.ExpandedConfig()["limits.disk.priority"] if diskPriority != "" { if d.state.OS.CGInfo.Supports(cgroup.BlkioWeight, nil) { priorityInt, err := strconv.Atoi(diskPriority) @@ -498,7 +498,7 @@ func (d *disk) generateLimits(runConf *deviceConfig.RunConfig) error { // Disk throttle limits. hasDiskLimits := false - for _, dev := range d.instance.ExpandedDevices() { + for _, dev := range d.inst.ExpandedDevices() { if dev["type"] != "disk" { continue } @@ -679,7 +679,7 @@ func (d *disk) createDevice() (string, error) { return "", fmt.Errorf("Unknown storage type prefix \"%s\" found", volumeTypeName) } - err := StorageVolumeMount(d.state, d.config["pool"], volumeName, volumeTypeName, d.instance) + err := StorageVolumeMount(d.state, d.config["pool"], volumeName, volumeTypeName, d.inst) if err != nil { msg := fmt.Sprintf("Could not mount storage volume \"%s\" of type \"%s\" on storage pool \"%s\": %s.", volumeName, volumeTypeName, d.config["pool"], err) if !isRequired { @@ -700,8 +700,8 @@ func (d *disk) createDevice() (string, error) { } // Create the devices directory if missing. - if !shared.PathExists(d.instance.DevicesPath()) { - err := os.Mkdir(d.instance.DevicesPath(), 0711) + if !shared.PathExists(d.inst.DevicesPath()) { + err := os.Mkdir(d.inst.DevicesPath(), 0711) if err != nil { return "", err } @@ -741,7 +741,7 @@ func (d *disk) createDevice() (string, error) { // Stop is run when the device is removed from the instance. func (d *disk) Stop() (*deviceConfig.RunConfig, error) { - if d.instance.Type() == instancetype.VM { + if d.inst.Type() == instancetype.VM { // Only root disks and cloud-init:config drives supported on VMs. if shared.IsRootDiskDevice(d.config) || d.config["source"] == diskSourceCloudInit { return &deviceConfig.RunConfig{}, nil @@ -841,7 +841,7 @@ func (d *disk) getDiskLimits() (map[string]diskBlockLimit, error) { // Process all the limits blockLimits := map[string][]diskBlockLimit{} - for devName, dev := range d.instance.ExpandedDevices() { + for devName, dev := range d.inst.ExpandedDevices() { if dev["type"] != "disk" { continue } @@ -861,7 +861,7 @@ func (d *disk) getDiskLimits() (map[string]diskBlockLimit, error) { // Set the source path source := d.getDevicePath(devName, dev) if dev["source"] == "" { - source = d.instance.RootfsPath() + source = d.inst.RootfsPath() } if !shared.PathExists(source) { @@ -1149,7 +1149,7 @@ func (d *disk) getParentBlocks(path string) ([]string, error) { // generateVMConfigDrive generates an ISO containing the cloud init config for a VM. // Returns the path to the ISO. func (d *disk) generateVMConfigDrive() (string, error) { - scratchDir := filepath.Join(d.instance.DevicesPath(), deviceNameEncode(d.name)) + scratchDir := filepath.Join(d.inst.DevicesPath(), deviceNameEncode(d.name)) // Create config drive dir. err := os.MkdirAll(scratchDir, 0100) @@ -1157,7 +1157,7 @@ func (d *disk) generateVMConfigDrive() (string, error) { return "", err } - instanceConfig := d.instance.ExpandedConfig() + instanceConfig := d.inst.ExpandedConfig() // Use an empty user-data file if no custom vendor-data supplied. vendorData := instanceConfig["user.vendor-data"] @@ -1185,7 +1185,7 @@ func (d *disk) generateVMConfigDrive() (string, error) { metaData := fmt.Sprintf(`instance-id: %s local-hostname: %s %s -`, d.instance.Name(), d.instance.Name(), instanceConfig["user.meta-data"]) +`, d.inst.Name(), d.inst.Name(), instanceConfig["user.meta-data"]) err = ioutil.WriteFile(filepath.Join(scratchDir, "meta-data"), []byte(metaData), 0400) if err != nil { @@ -1196,7 +1196,7 @@ local-hostname: %s // as this is what cloud-init uses to detect, mount the drive and run the cloud-init // templates on first boot. The vendor-data template then modifies the system so that the // config drive is mounted and the agent is started on subsequent boots. - isoPath := filepath.Join(d.instance.Path(), "config.iso") + isoPath := filepath.Join(d.inst.Path(), "config.iso") _, err = shared.RunCommand("mkisofs", "-R", "-V", "cidata", "-o", isoPath, scratchDir) if err != nil { return "", err diff --git a/lxd/device/gpu.go b/lxd/device/gpu.go index fb59d404e6..30c5888040 100644 --- a/lxd/device/gpu.go +++ b/lxd/device/gpu.go @@ -32,7 +32,7 @@ type gpu struct { // validateConfig checks the supplied config for correctness. func (d *gpu) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } @@ -104,7 +104,7 @@ func (d *gpu) Start() (*deviceConfig.RunConfig, error) { return nil, err } - err = unixDeviceSetupCharNum(d.state, d.instance.DevicesPath(), "unix", d.name, d.config, major, minor, path, false, &runConf) + err = unixDeviceSetupCharNum(d.state, d.inst.DevicesPath(), "unix", d.name, d.config, major, minor, path, false, &runConf) if err != nil { return nil, err } @@ -117,7 +117,7 @@ func (d *gpu) Start() (*deviceConfig.RunConfig, error) { return nil, err } - err = unixDeviceSetupCharNum(d.state, d.instance.DevicesPath(), "unix", d.name, d.config, major, minor, path, false, &runConf) + err = unixDeviceSetupCharNum(d.state, d.inst.DevicesPath(), "unix", d.name, d.config, major, minor, path, false, &runConf) if err != nil { return nil, err } @@ -130,7 +130,7 @@ func (d *gpu) Start() (*deviceConfig.RunConfig, error) { return nil, err } - err = unixDeviceSetupCharNum(d.state, d.instance.DevicesPath(), "unix", d.name, d.config, major, minor, path, false, &runConf) + err = unixDeviceSetupCharNum(d.state, d.inst.DevicesPath(), "unix", d.name, d.config, major, minor, path, false, &runConf) if err != nil { return nil, err } @@ -145,7 +145,7 @@ func (d *gpu) Start() (*deviceConfig.RunConfig, error) { return nil, err } - err = unixDeviceSetupCharNum(d.state, d.instance.DevicesPath(), "unix", d.name, d.config, major, minor, path, false, &runConf) + err = unixDeviceSetupCharNum(d.state, d.inst.DevicesPath(), "unix", d.name, d.config, major, minor, path, false, &runConf) if err != nil { return nil, err } @@ -156,7 +156,7 @@ func (d *gpu) Start() (*deviceConfig.RunConfig, error) { if sawNvidia { // No need to mount additional nvidia non-card devices as the nvidia.runtime // setting will do this for us. - instanceConfig := d.instance.ExpandedConfig() + instanceConfig := d.inst.ExpandedConfig() if !shared.IsTrue(instanceConfig["nvidia.runtime"]) { nvidiaDevices, err := d.getNvidiaNonCardDevices() if err != nil { @@ -165,11 +165,11 @@ func (d *gpu) Start() (*deviceConfig.RunConfig, error) { for _, dev := range nvidiaDevices { prefix := deviceJoinPath("unix", d.name) - if UnixDeviceExists(d.instance.DevicesPath(), prefix, dev.path) { + if UnixDeviceExists(d.inst.DevicesPath(), prefix, dev.path) { continue } - err = unixDeviceSetupCharNum(d.state, d.instance.DevicesPath(), "unix", d.name, d.config, dev.major, dev.minor, dev.path, false, &runConf) + err = unixDeviceSetupCharNum(d.state, d.inst.DevicesPath(), "unix", d.name, d.config, dev.major, dev.minor, dev.path, false, &runConf) if err != nil { return nil, err } @@ -190,7 +190,7 @@ func (d *gpu) Stop() (*deviceConfig.RunConfig, error) { PostHooks: []func() error{d.postStop}, } - err := unixDeviceRemove(d.instance.DevicesPath(), "unix", d.name, "", &runConf) + err := unixDeviceRemove(d.inst.DevicesPath(), "unix", d.name, "", &runConf) if err != nil { return nil, err } @@ -201,7 +201,7 @@ func (d *gpu) Stop() (*deviceConfig.RunConfig, error) { // postStop is run after the device is removed from the instance. func (d *gpu) postStop() error { // Remove host files for this device. - err := unixDeviceDeleteFiles(d.state, d.instance.DevicesPath(), "unix", d.name, "") + err := unixDeviceDeleteFiles(d.state, d.inst.DevicesPath(), "unix", d.name, "") if err != nil { return fmt.Errorf("Failed to delete files for device '%s': %v", d.name, err) } diff --git a/lxd/device/infiniband_physical.go b/lxd/device/infiniband_physical.go index 71392f7180..564625461a 100644 --- a/lxd/device/infiniband_physical.go +++ b/lxd/device/infiniband_physical.go @@ -15,7 +15,7 @@ type infinibandPhysical struct { // validateConfig checks the supplied config for correctness. func (d *infinibandPhysical) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } @@ -105,7 +105,7 @@ func (d *infinibandPhysical) Start() (*deviceConfig.RunConfig, error) { runConf := deviceConfig.RunConfig{} // Configure runConf with infiniband setup instructions. - err = infinibandAddDevices(d.state, d.instance.DevicesPath(), d.name, ibDev, &runConf) + err = infinibandAddDevices(d.state, d.inst.DevicesPath(), d.name, ibDev, &runConf) if err != nil { return nil, err } @@ -135,7 +135,7 @@ func (d *infinibandPhysical) Stop() (*deviceConfig.RunConfig, error) { }, } - err := unixDeviceRemove(d.instance.DevicesPath(), IBDevPrefix, d.name, "", &runConf) + err := unixDeviceRemove(d.inst.DevicesPath(), IBDevPrefix, d.name, "", &runConf) if err != nil { return nil, err } @@ -152,7 +152,7 @@ func (d *infinibandPhysical) postStop() error { }) // Remove infiniband host files for this device. - err := unixDeviceDeleteFiles(d.state, d.instance.DevicesPath(), IBDevPrefix, d.name, "") + err := unixDeviceDeleteFiles(d.state, d.inst.DevicesPath(), IBDevPrefix, d.name, "") if err != nil { return fmt.Errorf("Failed to delete files for device '%s': %v", d.name, err) } diff --git a/lxd/device/infiniband_sriov.go b/lxd/device/infiniband_sriov.go index aa3e35b477..f471d9419b 100644 --- a/lxd/device/infiniband_sriov.go +++ b/lxd/device/infiniband_sriov.go @@ -16,7 +16,7 @@ type infinibandSRIOV struct { // validateConfig checks the supplied config for correctness. func (d *infinibandSRIOV) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } @@ -127,7 +127,7 @@ func (d *infinibandSRIOV) Start() (*deviceConfig.RunConfig, error) { runConf := deviceConfig.RunConfig{} // Configure runConf with infiniband setup instructions. - err = infinibandAddDevices(d.state, d.instance.DevicesPath(), d.name, vfDev, &runConf) + err = infinibandAddDevices(d.state, d.inst.DevicesPath(), d.name, vfDev, &runConf) if err != nil { return nil, err } @@ -155,7 +155,7 @@ func (d *infinibandSRIOV) Stop() (*deviceConfig.RunConfig, error) { NetworkInterface: []deviceConfig.RunConfigItem{{Key: "link", Value: v["host_name"]}}, } - err := unixDeviceRemove(d.instance.DevicesPath(), IBDevPrefix, d.name, "", &runConf) + err := unixDeviceRemove(d.inst.DevicesPath(), IBDevPrefix, d.name, "", &runConf) if err != nil { return nil, err } @@ -172,7 +172,7 @@ func (d *infinibandSRIOV) postStop() error { }) // Remove infiniband host files for this device. - err := unixDeviceDeleteFiles(d.state, d.instance.DevicesPath(), IBDevPrefix, d.name, "") + err := unixDeviceDeleteFiles(d.state, d.inst.DevicesPath(), IBDevPrefix, d.name, "") if err != nil { return fmt.Errorf("Failed to delete files for device '%s': %v", d.name, err) } diff --git a/lxd/device/nic_bridged.go b/lxd/device/nic_bridged.go index 0522fdbd8e..d34d7d6aeb 100644 --- a/lxd/device/nic_bridged.go +++ b/lxd/device/nic_bridged.go @@ -49,7 +49,7 @@ type nicBridged struct { // validateConfig checks the supplied config for correctness. func (d *nicBridged) validateConfig() error { - if d.instance.Type() != instancetype.Container && d.instance.Type() != instancetype.VM { + if d.inst.Type() != instancetype.Container && d.inst.Type() != instancetype.VM { return ErrUnsupportedDevType } @@ -126,9 +126,9 @@ func (d *nicBridged) Start() (*deviceConfig.RunConfig, error) { var peerName string // Only used with containers, empty for VMs. // Create veth pair and configure the peer end with custom hwaddr and mtu if supplied. - if d.instance.Type() == instancetype.Container { + if d.inst.Type() == instancetype.Container { peerName, err = networkCreateVethPair(saveData["host_name"], d.config) - } else if d.instance.Type() == instancetype.VM { + } else if d.inst.Type() == instancetype.VM { peerName = saveData["host_name"] // VMs use the host_name to link to the TAP FD. err = networkCreateTap(saveData["host_name"]) } @@ -178,7 +178,7 @@ func (d *nicBridged) Start() (*deviceConfig.RunConfig, error) { {Key: "link", Value: peerName}, } - if d.instance.Type() == instancetype.VM { + if d.inst.Type() == instancetype.VM { runConf.NetworkInterface = append(runConf.NetworkInterface, deviceConfig.RunConfigItem{Key: "hwaddr", Value: d.config["hwaddr"]}, ) @@ -195,7 +195,7 @@ func (d *nicBridged) Update(oldDevices deviceConfig.Devices, isRunning bool) err // isn't allocated old IP. This is important with IPv6 because DHCPv6 supports multiple IP // address allocation and would result in instance having leases for both old and new IPs. if d.config["hwaddr"] != "" && d.config["ipv6.address"] != oldConfig["ipv6.address"] { - err := d.networkClearLease(d.instance.Name(), d.config["parent"], d.config["hwaddr"], clearLeaseIPv6Only) + err := d.networkClearLease(d.inst.Name(), d.config["parent"], d.config["hwaddr"], clearLeaseIPv6Only) if err != nil { return err } @@ -291,7 +291,7 @@ func (d *nicBridged) postStop() error { // Remove is run when the device is removed from the instance or the instance is deleted. func (d *nicBridged) Remove() error { - err := d.networkClearLease(d.instance.Name(), d.config["parent"], d.config["hwaddr"], clearLeaseAll) + err := d.networkClearLease(d.inst.Name(), d.config["parent"], d.config["hwaddr"], clearLeaseAll) if err != nil { return err } @@ -301,7 +301,7 @@ func (d *nicBridged) Remove() error { defer dnsmasq.ConfigMutex.Unlock() // Remove dnsmasq config if it exists (doesn't return error if file is missing). - err := dnsmasq.RemoveStaticEntry(d.config["parent"], d.instance.Project(), d.instance.Name()) + err := dnsmasq.RemoveStaticEntry(d.config["parent"], d.inst.Project(), d.inst.Name()) if err != nil { return err } @@ -341,7 +341,7 @@ func (d *nicBridged) rebuildDnsmasqEntry() error { // If IP filtering is enabled, and no static IP in config, check if there is already a // dynamically assigned static IP in dnsmasq config and write that back out in new config. if (shared.IsTrue(d.config["security.ipv4_filtering"]) && ipv4Address == "") || (shared.IsTrue(d.config["security.ipv6_filtering"]) && ipv6Address == "") { - curIPv4, curIPv6, err := dnsmasq.DHCPStaticIPs(d.config["parent"], d.instance.Name()) + curIPv4, curIPv6, err := dnsmasq.DHCPStaticIPs(d.config["parent"], d.inst.Name()) if err != nil && !os.IsNotExist(err) { return err } @@ -355,7 +355,7 @@ func (d *nicBridged) rebuildDnsmasqEntry() error { } } - err = dnsmasq.UpdateStaticEntry(d.config["parent"], d.instance.Project(), d.instance.Name(), netConfig, d.config["hwaddr"], ipv4Address, ipv6Address) + err = dnsmasq.UpdateStaticEntry(d.config["parent"], d.inst.Project(), d.inst.Name(), netConfig, d.config["hwaddr"], ipv4Address, ipv6Address) if err != nil { return err } @@ -398,15 +398,15 @@ func (d *nicBridged) removeFilters(m deviceConfig.Device) error { } // Remove any IPv6 filters used for this instance. - err := d.state.Firewall.InstanceClear(firewallConsts.FamilyIPv6, firewallConsts.TableFilter, fmt.Sprintf("%s - ipv6_filtering", d.instance.Name())) + err := d.state.Firewall.InstanceClear(firewallConsts.FamilyIPv6, firewallConsts.TableFilter, fmt.Sprintf("%s - ipv6_filtering", d.inst.Name())) if err != nil { return fmt.Errorf("Failed to clear ip6tables ipv6_filter rules for %s: %v", m["name"], err) } // Read current static IP allocation configured from dnsmasq host config (if exists). var IPv4, IPv6 dhcpAllocation - if shared.PathExists(shared.VarPath("networks", m["parent"], "dnsmasq.hosts") + "/" + d.instance.Name()) { - IPv4, IPv6, err = d.getDHCPStaticIPs(m["parent"], d.instance.Name()) + if shared.PathExists(shared.VarPath("networks", m["parent"], "dnsmasq.hosts") + "/" + d.inst.Name()) { + IPv4, IPv6, err = d.getDHCPStaticIPs(m["parent"], d.inst.Name()) if err != nil { return fmt.Errorf("Failed to retrieve static IPs for filter removal from %s: %v", m["name"], err) } @@ -436,14 +436,14 @@ func (d *nicBridged) getDHCPStaticIPs(network string, instanceName string) (dhcp if IP.To4() == nil { return IPv4, IPv6, fmt.Errorf("Error parsing IP address: %v", field) } - IPv4 = dhcpAllocation{Name: d.instance.Name(), Static: true, IP: IP.To4()} + IPv4 = dhcpAllocation{Name: d.inst.Name(), Static: true, IP: IP.To4()} } else if strings.HasPrefix(field, "[") && strings.HasSuffix(field, "]") { IP := net.ParseIP(field[1 : len(field)-1]) if IP == nil { return IPv4, IPv6, fmt.Errorf("Error parsing IP address: %v", field) } - IPv6 = dhcpAllocation{Name: d.instance.Name(), Static: true, IP: IP} + IPv6 = dhcpAllocation{Name: d.inst.Name(), Static: true, IP: IP} } } } @@ -576,7 +576,7 @@ func (d *nicBridged) setFilters() (err error) { } }() - return d.state.Firewall.InstanceNicBridgedSetFilters(d.config, IPv4, IPv6, d.instance.Name()) + return d.state.Firewall.InstanceNicBridgedSetFilters(d.config, IPv4, IPv6, d.inst.Name()) } // networkAllocateVethFilterIPs retrieves previously allocated IPs, or allocate new ones if needed. @@ -619,7 +619,7 @@ func (d *nicBridged) allocateFilterIPs(netConfig map[string]string) (net.IP, net defer dnsmasq.ConfigMutex.Unlock() // Read current static IP allocation configured from dnsmasq host config (if exists). - curIPv4, curIPv6, err := d.getDHCPStaticIPs(d.config["parent"], d.instance.Name()) + curIPv4, curIPv6, err := d.getDHCPStaticIPs(d.config["parent"], d.inst.Name()) if err != nil && !os.IsNotExist(err) { return nil, nil, err } @@ -664,7 +664,7 @@ func (d *nicBridged) allocateFilterIPs(netConfig map[string]string) (net.IP, net // Allocate a new IPv4 address if IPv4 filtering enabled. if IPv4 == nil && canIPv4Allocate && shared.IsTrue(d.config["security.ipv4_filtering"]) { - IPv4, err = d.getDHCPFreeIPv4(IPv4Allocs, netConfig, d.instance.Name(), d.config["hwaddr"]) + IPv4, err = d.getDHCPFreeIPv4(IPv4Allocs, netConfig, d.inst.Name(), d.config["hwaddr"]) if err != nil { return nil, nil, err } @@ -672,7 +672,7 @@ func (d *nicBridged) allocateFilterIPs(netConfig map[string]string) (net.IP, net // Allocate a new IPv6 address if IPv6 filtering enabled. if IPv6 == nil && canIPv6Allocate && shared.IsTrue(d.config["security.ipv6_filtering"]) { - IPv6, err = d.getDHCPFreeIPv6(IPv6Allocs, netConfig, d.instance.Name(), d.config["hwaddr"]) + IPv6, err = d.getDHCPFreeIPv6(IPv6Allocs, netConfig, d.inst.Name(), d.config["hwaddr"]) if err != nil { return nil, nil, err } @@ -692,7 +692,7 @@ func (d *nicBridged) allocateFilterIPs(netConfig map[string]string) (net.IP, net IPv6Str = IPv6.String() } - err = dnsmasq.UpdateStaticEntry(d.config["parent"], d.instance.Project(), d.instance.Name(), netConfig, d.config["hwaddr"], IPv4Str, IPv6Str) + err = dnsmasq.UpdateStaticEntry(d.config["parent"], d.inst.Project(), d.inst.Name(), netConfig, d.config["hwaddr"], IPv4Str, IPv6Str) if err != nil { return nil, nil, err } diff --git a/lxd/device/nic_ipvlan.go b/lxd/device/nic_ipvlan.go index 1dca274a5e..480b8af1df 100644 --- a/lxd/device/nic_ipvlan.go +++ b/lxd/device/nic_ipvlan.go @@ -20,7 +20,7 @@ func (d *nicIPVLAN) CanHotPlug() (bool, []string) { // validateConfig checks the supplied config for correctness. func (d *nicIPVLAN) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } @@ -232,7 +232,7 @@ func (d *nicIPVLAN) postStop() error { // This will delete the parent interface if we created it for VLAN parent. if shared.IsTrue(v["last_state.created"]) { parentName := NetworkGetHostDevice(d.config["parent"], d.config["vlan"]) - err := NetworkRemoveInterfaceIfNeeded(d.state, parentName, d.instance, d.config["parent"], d.config["vlan"]) + err := NetworkRemoveInterfaceIfNeeded(d.state, parentName, d.inst, d.config["parent"], d.config["vlan"]) if err != nil { return err } diff --git a/lxd/device/nic_macvlan.go b/lxd/device/nic_macvlan.go index 03b48fad5d..fb7b87d21d 100644 --- a/lxd/device/nic_macvlan.go +++ b/lxd/device/nic_macvlan.go @@ -14,7 +14,7 @@ type nicMACVLAN struct { // validateConfig checks the supplied config for correctness. func (d *nicMACVLAN) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } @@ -151,7 +151,7 @@ func (d *nicMACVLAN) postStop() error { // This will delete the parent interface if we created it for VLAN parent. if shared.IsTrue(v["last_state.created"]) { parentName := NetworkGetHostDevice(d.config["parent"], d.config["vlan"]) - err := NetworkRemoveInterfaceIfNeeded(d.state, parentName, d.instance, d.config["parent"], d.config["vlan"]) + err := NetworkRemoveInterfaceIfNeeded(d.state, parentName, d.inst, d.config["parent"], d.config["vlan"]) if err != nil { errs = append(errs, err) } diff --git a/lxd/device/nic_p2p.go b/lxd/device/nic_p2p.go index 4112188523..2349039c50 100644 --- a/lxd/device/nic_p2p.go +++ b/lxd/device/nic_p2p.go @@ -14,7 +14,7 @@ type nicP2P struct { // validateConfig checks the supplied config for correctness. func (d *nicP2P) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } diff --git a/lxd/device/nic_physical.go b/lxd/device/nic_physical.go index 8ab2bb19c5..8376da3a07 100644 --- a/lxd/device/nic_physical.go +++ b/lxd/device/nic_physical.go @@ -14,7 +14,7 @@ type nicPhysical struct { // validateConfig checks the supplied config for correctness. func (d *nicPhysical) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } diff --git a/lxd/device/nic_routed.go b/lxd/device/nic_routed.go index a77eadc3d9..8b9db5eb31 100644 --- a/lxd/device/nic_routed.go +++ b/lxd/device/nic_routed.go @@ -23,7 +23,7 @@ func (d *nicRouted) CanHotPlug() (bool, []string) { // validateConfig checks the supplied config for correctness. func (d *nicRouted) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } @@ -310,7 +310,7 @@ func (d *nicRouted) postStop() error { // This will delete the parent interface if we created it for VLAN parent. if shared.IsTrue(v["last_state.created"]) { parentName := NetworkGetHostDevice(d.config["parent"], d.config["vlan"]) - err := NetworkRemoveInterfaceIfNeeded(d.state, parentName, d.instance, d.config["parent"], d.config["vlan"]) + err := NetworkRemoveInterfaceIfNeeded(d.state, parentName, d.inst, d.config["parent"], d.config["vlan"]) if err != nil { return err } diff --git a/lxd/device/nic_sriov.go b/lxd/device/nic_sriov.go index 4e727f4d0d..1079b9773f 100644 --- a/lxd/device/nic_sriov.go +++ b/lxd/device/nic_sriov.go @@ -24,7 +24,7 @@ type nicSRIOV struct { // validateConfig checks the supplied config for correctness. func (d *nicSRIOV) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } diff --git a/lxd/device/proxy.go b/lxd/device/proxy.go index 49e7223e80..1ac382907c 100644 --- a/lxd/device/proxy.go +++ b/lxd/device/proxy.go @@ -41,7 +41,7 @@ type proxyProcInfo struct { // validateConfig checks the supplied config for correctness. func (d *proxy) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } @@ -148,9 +148,9 @@ func (d *proxy) Start() (*deviceConfig.RunConfig, error) { } devFileName := fmt.Sprintf("proxy.%s", d.name) - pidPath := filepath.Join(d.instance.DevicesPath(), devFileName) + pidPath := filepath.Join(d.inst.DevicesPath(), devFileName) logFileName := fmt.Sprintf("proxy.%s.log", d.name) - logPath := filepath.Join(d.instance.LogPath(), logFileName) + logPath := filepath.Join(d.inst.LogPath(), logFileName) _, err = shared.RunCommand( d.state.OS.ExecPath, @@ -227,11 +227,11 @@ func (d *proxy) checkProcStarted(logPath string) (bool, error) { // Stop is run when the device is removed from the instance. func (d *proxy) Stop() (*deviceConfig.RunConfig, error) { // Remove possible iptables entries - d.state.Firewall.InstanceClear(firewallConsts.FamilyIPv4, firewallConsts.TableNat, fmt.Sprintf("%s (%s)", d.instance.Name(), d.name)) - d.state.Firewall.InstanceClear(firewallConsts.FamilyIPv6, firewallConsts.TableNat, fmt.Sprintf("%s (%s)", d.instance.Name(), d.name)) + d.state.Firewall.InstanceClear(firewallConsts.FamilyIPv4, firewallConsts.TableNat, fmt.Sprintf("%s (%s)", d.inst.Name(), d.name)) + d.state.Firewall.InstanceClear(firewallConsts.FamilyIPv6, firewallConsts.TableNat, fmt.Sprintf("%s (%s)", d.inst.Name(), d.name)) devFileName := fmt.Sprintf("proxy.%s", d.name) - devPath := filepath.Join(d.instance.DevicesPath(), devFileName) + devPath := filepath.Join(d.inst.DevicesPath(), devFileName) if !shared.PathExists(devPath) { // There's no proxy process if NAT is enabled @@ -265,7 +265,7 @@ func (d *proxy) setupNAT() error { var IPv4Addr net.IP var IPv6Addr net.IP - for _, devConfig := range d.instance.ExpandedDevices() { + for _, devConfig := range d.inst.ExpandedDevices() { if devConfig["type"] != "nic" || (devConfig["type"] == "nic" && devConfig["nictype"] != "bridged") { continue } @@ -288,7 +288,7 @@ func (d *proxy) setupNAT() error { return fmt.Errorf("NIC IP doesn't match proxy target IP") } - firewallComment := fmt.Sprintf("%s (%s)", d.instance.Name(), d.name) + firewallComment := fmt.Sprintf("%s (%s)", d.inst.Name(), d.name) revert := true defer func() { @@ -347,7 +347,7 @@ func (d *proxy) rewriteHostAddr(addr string) string { } func (d *proxy) setupProxyProcInfo() (*proxyProcInfo, error) { - cname := project.Prefix(d.instance.Project(), d.instance.Name()) + cname := project.Prefix(d.inst.Project(), d.inst.Name()) cc, err := lxc.NewContainer(cname, d.state.OS.LxcPath) if err != nil { return nil, err diff --git a/lxd/device/unix_common.go b/lxd/device/unix_common.go index fa47d244df..ba32170f90 100644 --- a/lxd/device/unix_common.go +++ b/lxd/device/unix_common.go @@ -39,7 +39,7 @@ func (d *unixCommon) isRequired() bool { // validateConfig checks the supplied config for correctness. func (d *unixCommon) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } @@ -75,7 +75,7 @@ func (d *unixCommon) Register() error { // Extract variables needed to run the event hook so that the reference to this device // struct is not needed to be kept in memory. - devicesPath := d.instance.DevicesPath() + devicesPath := d.inst.DevicesPath() devConfig := d.config deviceName := d.name state := d.state @@ -142,7 +142,7 @@ func (d *unixCommon) Register() error { // Register the handler function against the device's source path. subPath := unixDeviceSourcePath(devConfig) - err := unixRegisterHandler(d.state, d.instance, d.name, subPath, f) + err := unixRegisterHandler(d.state, d.inst, d.name, subPath, f) if err != nil { return err } @@ -164,7 +164,7 @@ func (d *unixCommon) Start() (*deviceConfig.RunConfig, error) { return nil, fmt.Errorf("Path specified is not a %s device", d.config["type"]) } - err = unixDeviceSetup(d.state, d.instance.DevicesPath(), "unix", d.name, d.config, true, &runConf) + err = unixDeviceSetup(d.state, d.inst.DevicesPath(), "unix", d.name, d.config, true, &runConf) if err != nil { return nil, err } @@ -172,7 +172,7 @@ func (d *unixCommon) Start() (*deviceConfig.RunConfig, error) { // If the device file doesn't exist on the system, but major & minor numbers have // been provided in the config then we can go ahead and create the device anyway. if d.config["major"] != "" && d.config["minor"] != "" { - err := unixDeviceSetup(d.state, d.instance.DevicesPath(), "unix", d.name, d.config, true, &runConf) + err := unixDeviceSetup(d.state, d.inst.DevicesPath(), "unix", d.name, d.config, true, &runConf) if err != nil { return nil, err } @@ -188,7 +188,7 @@ func (d *unixCommon) Start() (*deviceConfig.RunConfig, error) { // Stop is run when the device is removed from the instance. func (d *unixCommon) Stop() (*deviceConfig.RunConfig, error) { // Unregister any Unix event handlers for this device. - err := unixUnregisterHandler(d.state, d.instance, d.name) + err := unixUnregisterHandler(d.state, d.inst, d.name) if err != nil { return nil, err } @@ -197,7 +197,7 @@ func (d *unixCommon) Stop() (*deviceConfig.RunConfig, error) { PostHooks: []func() error{d.postStop}, } - err = unixDeviceRemove(d.instance.DevicesPath(), "unix", d.name, "", &runConf) + err = unixDeviceRemove(d.inst.DevicesPath(), "unix", d.name, "", &runConf) if err != nil { return nil, err } @@ -208,7 +208,7 @@ func (d *unixCommon) Stop() (*deviceConfig.RunConfig, error) { // postStop is run after the device is removed from the instance. func (d *unixCommon) postStop() error { // Remove host files for this device. - err := unixDeviceDeleteFiles(d.state, d.instance.DevicesPath(), "unix", d.name, "") + err := unixDeviceDeleteFiles(d.state, d.inst.DevicesPath(), "unix", d.name, "") if err != nil { return fmt.Errorf("Failed to delete files for device '%s': %v", d.name, err) } diff --git a/lxd/device/usb.go b/lxd/device/usb.go index c077d768b0..fd42b33f45 100644 --- a/lxd/device/usb.go +++ b/lxd/device/usb.go @@ -43,7 +43,7 @@ func (d *usb) isRequired() bool { // validateConfig checks the supplied config for correctness. func (d *usb) validateConfig() error { - if d.instance.Type() != instancetype.Container { + if d.inst.Type() != instancetype.Container { return ErrUnsupportedDevType } @@ -68,7 +68,7 @@ func (d *usb) validateConfig() error { func (d *usb) Register() error { // Extract variables needed to run the event hook so that the reference to this device // struct is not needed to be kept in memory. - devicesPath := d.instance.DevicesPath() + devicesPath := d.inst.DevicesPath() devConfig := d.config deviceName := d.name state := d.state @@ -109,7 +109,7 @@ func (d *usb) Register() error { return &runConf, nil } - usbRegisterHandler(d.instance, d.name, f) + usbRegisterHandler(d.inst, d.name, f) return nil } @@ -129,7 +129,7 @@ func (d *usb) Start() (*deviceConfig.RunConfig, error) { continue } - err := unixDeviceSetupCharNum(d.state, d.instance.DevicesPath(), "unix", d.name, d.config, usb.Major, usb.Minor, usb.Path, false, &runConf) + err := unixDeviceSetupCharNum(d.state, d.inst.DevicesPath(), "unix", d.name, d.config, usb.Major, usb.Minor, usb.Path, false, &runConf) if err != nil { return nil, err } @@ -145,13 +145,13 @@ func (d *usb) Start() (*deviceConfig.RunConfig, error) { // Stop is run when the device is removed from the instance. func (d *usb) Stop() (*deviceConfig.RunConfig, error) { // Unregister any USB event handlers for this device. - usbUnregisterHandler(d.instance, d.name) + usbUnregisterHandler(d.inst, d.name) runConf := deviceConfig.RunConfig{ PostHooks: []func() error{d.postStop}, } - err := unixDeviceRemove(d.instance.DevicesPath(), "unix", d.name, "", &runConf) + err := unixDeviceRemove(d.inst.DevicesPath(), "unix", d.name, "", &runConf) if err != nil { return nil, err } @@ -162,7 +162,7 @@ func (d *usb) Stop() (*deviceConfig.RunConfig, error) { // postStop is run after the device is removed from the instance. func (d *usb) postStop() error { // Remove host files for this device. - err := unixDeviceDeleteFiles(d.state, d.instance.DevicesPath(), "unix", d.name, "") + err := unixDeviceDeleteFiles(d.state, d.inst.DevicesPath(), "unix", d.name, "") if err != nil { return fmt.Errorf("Failed to delete files for device '%s': %v", d.name, err) }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel