// device.Id should be the PCI address in the format  "bridgeAddr/deviceAddr".
// Here, bridgeAddr is the address at which the brige is attached on the root bus,
// while deviceAddr is the address at which the device is attached on the bridge.
778757
func virtioBlkDeviceHandler(device pb.Device, spec *pb.Spec, s *sandbox) error {
	// Get the device node path based on the PCI device address
	devPath, err := getPCIDeviceName(s, device.Id)
	if err != nil {
		return err
	}
	device.VmPath = devPath

	return updateSpecDeviceList(device, spec)
}
881451
func (s *Device) SetDeviceId(v string) *Device {
	s.DeviceId = &v
	return s
}
1229370
func (d *DeviceMapperDriver) deviceName(deviceHash string) string {
	return fmt.Sprintf("%s-%s", d.DevicePrefix, deviceHash)
}
784161
func (s *ListDeviceEventsInput) SetDeviceId(v string) *ListDeviceEventsInput {
	s.DeviceId = &v
	return s
}
1308972
func NewDeviceID(rawCert []byte) DeviceID {
	var n DeviceID
	hf := sha256.New()
	hf.Write(rawCert)
	hf.Sum(n[:0])
	return n
}
1111597
func GetBridgedDeviceName(macAddr string) (string, error) {
	stdout, _, err := runner.Run("list", "bridgedifs")
	if err != nil {
		return "", err
	}
	if matches := networkRegexp.FindAllString(stdout, -1); len(matches) > 0 {
		// Each match is a device
		for _, device := range matches {
			var mac, name string
			// Find the mac address and the name
			for _, line := range strings.Split(device, "\n") {
				if strings.Contains(line, "HardwareAddress") {
					mac = strings.TrimSpace(strings.TrimPrefix(line, "HardwareAddress:"))
				}
				if strings.Contains(line, "Name:") {
					name = strings.TrimSpace(strings.TrimPrefix(line, "Name:"))
				}
			}
			if strings.Contains(macAddr, mac) {
				return name, nil
			}
		}
	}
	return "", nil
}
264791
func (addr *Address) Device() (*LinkLayerDevice, error) {
	return addr.machineProxy().LinkLayerDevice(addr.doc.DeviceName)
}
846862
func (p *Peer) ID() int32 {
	p.flagsMtx.Lock()
	id := p.id
	p.flagsMtx.Unlock()

	return id
}
103135
func (devices *DeviceSet) registerDevice(id int, hash string, size uint64, transactionID uint64) (*devInfo, error) {
	logrus.Debugf("devmapper: registerDevice(%v, %v)", id, hash)
	info := &devInfo{
		Hash:          hash,
		DeviceID:      id,
		Size:          size,
		TransactionID: transactionID,
		Initialized:   false,
		devices:       devices,
	}

	devices.Devices[hash] = info

	if err := devices.saveMetadata(info); err != nil {
		// Try to remove unused device
		delete(devices.Devices, hash)
		return nil, err
	}

	return info, nil
}
1052049
func (d *DeviceMapperDriver) addDevice(headDeviceHash string) (string, error) {

	// Generate the device ID.
	deviceHash, err := utils.NewUUID62()
	if err != nil {
		return "", err
	}

	// Create the device.
	if err := d.DeviceSet.AddDevice(deviceHash, headDeviceHash); err != nil {
		glog.Errorf("Unable to create device %s: %s", deviceHash, err)
		return "", err
	}

	if headDeviceHash == "" {

		// Activate the device.
		d.DeviceSet.GetDeviceStatus(deviceHash)

		// CC-2219: Ensure the device base size is equal or greater than the
		// configured dm.basesize.
		size, err := d.deviceSize(deviceHash)
		if err != nil {
			glog.Errorf("Could not read the size of device %s: %s", deviceHash, err)
			return "", err
		}
		if baseSize := d.baseSize(); baseSize > size {

			// Make the device to match dm.basesize
			glog.V(2).Infof("Device size is smaller than dm.basesize; expanding")
			if err := d.resize(deviceHash, baseSize); err != nil {
				glog.Errorf("Could not update the size of the device %s: %s", deviceHash, err)
				return "", err
			}
		}
	}

	return deviceHash, nil
}
1286959
func (s *RegisterDeviceOutput) SetDeviceId(v string) *RegisterDeviceOutput {
	s.DeviceId = &v
	return s
}
210569
func (n *nvmlDriver) DeviceInfoAndStatusByIndex(index uint) (*DeviceInfo, *DeviceStatus, error) {
	device, err := nvml.NewDevice(index)
	if err != nil {
		return nil, nil, err
	}
	status, err := device.Status()
	if err != nil {
		return nil, nil, err
	}
	return &DeviceInfo{
			UUID:               device.UUID,
			Name:               device.Model,
			MemoryMiB:          device.Memory,
			PowerW:             device.Power,
			BAR1MiB:            device.PCI.BAR1,
			PCIBandwidthMBPerS: device.PCI.Bandwidth,
			PCIBusID:           device.PCI.BusID,
			CoresClockMHz:      device.Clocks.Cores,
			MemoryClockMHz:     device.Clocks.Memory,
		}, &DeviceStatus{
			TemperatureC:       status.Temperature,
			GPUUtilization:     status.Utilization.GPU,
			MemoryUtilization:  status.Utilization.Memory,
			EncoderUtilization: status.Utilization.Encoder,
			DecoderUtilization: status.Utilization.Decoder,
			UsedMemoryMiB:      status.Memory.Global.Used,
			ECCErrorsL1Cache:   status.Memory.ECCErrors.L1Cache,
			ECCErrorsL2Cache:   status.Memory.ECCErrors.L2Cache,
			ECCErrorsDevice:    status.Memory.ECCErrors.Device,
			PowerUsageW:        status.Power,
			BAR1UsedMiB:        status.PCI.BAR1Used,
		}, nil
}
304203
func (w *wrapper) Device(id protocol.DeviceID) (DeviceConfiguration, bool) {
	w.mut.Lock()
	defer w.mut.Unlock()
	for _, device := range w.cfg.Devices {
		if device.DeviceID == id {
			return device.Copy(), true
		}
	}
	return DeviceConfiguration{}, false
}
138648
func (a *Advertisement) Address() ble.Addr {
	b := a.e.Address(a.i)
	addr := net.HardwareAddr([]byte{b[5], b[4], b[3], b[2], b[1], b[0]})
	if a.e.AddressType(a.i) == 1 {
		return RandomAddress{addr}
	}
	return addr
}
178036
func (np *Netplan) createBridgeFromInterface(bridgeName, deviceId string, intf *Interface) {
	if np.Network.Bridges == nil {
		np.Network.Bridges = make(map[string]Bridge)
	}
	np.Network.Bridges[bridgeName] = Bridge{
		Interfaces: []string{deviceId},
		Interface:  *intf,
	}
	*intf = Interface{MTU: intf.MTU}
}
1362738
func DevicesFromInterfaceInfo(interfaces []network.InterfaceInfo) (map[string]device, []string, error) {
	nics := make(map[string]device, len(interfaces))
	var unknown []string

	for _, v := range interfaces {
		if v.InterfaceType == network.LoopbackInterface {
			continue
		}
		if v.InterfaceType != network.EthernetInterface {
			return nil, nil, errors.Errorf("interface type %q not supported", v.InterfaceType)
		}
		if v.ParentInterfaceName == "" {
			return nil, nil, errors.Errorf("parent interface name is empty")
		}
		if v.CIDR == "" {
			unknown = append(unknown, v.ParentInterfaceName)
		}
		nics[v.InterfaceName] = newNICDevice(v.InterfaceName, v.ParentInterfaceName, v.MACAddress, v.MTU)
	}

	return nics, unknown, nil
}
1335683
func deviceName(zone string, diskId uint64) string {
	return fmt.Sprintf("%s-%d", zone, diskId)
}