From: Lucas Meneghel Rodrigues Subject: Re: [PATCH] KVM test: Add PCI device assignment support Date: Mon, 18 Jan 2010 14:49:14 -0200 Message-ID: <6ac58f4f1001180849v267fef64vafbdd358da16c5fe@mail.gmail.com> References: <1263320893-6219-1-git-send-email-lmr@redhat.com> <20100113021838.GA2333@aFu.nay.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable Cc: autotest@test.kernel.org, kvm@vger.kernel.org To: Yolkfull Chow Return-path: In-Reply-To: <20100113021838.GA2333@aFu.nay.redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org Ok, after some consideration I have applied the patch: http://autotest.kernel.org/changeset/4144 Thank you for your work on this test! On Wed, Jan 13, 2010 at 12:19 AM, Yolkfull Chow wrote: > On Tue, Jan 12, 2010 at 04:28:13PM -0200, Lucas Meneghel Rodrigues wrote: >> Add support to PCI device assignment on the kvm test. It supports >> both SR-IOV virtual functions and physical NIC card device >> assignment. >> >> Single Root I/O Virtualization (SR-IOV) allows a single PCI device to >> be shared amongst multiple virtual machines while retaining the >> performance benefit of assigning a PCI device to a virtual machine. >> A common example is where a single SR-IOV capable NIC - with perhaps >> only a single physical network port - might be shared with multiple >> virtual machines by assigning a virtual function to each VM. >> >> SR-IOV support is implemented in the kernel. The core implementation >> is contained in the PCI subsystem, but there must also be driver support >> for both the Physical Function (PF) and Virtual Function (VF) devices. >> With an SR-IOV capable device one can allocate VFs from a PF. The VFs >> surface as PCI devices which are backed on the physical PCI device by >> resources (queues, and register sets). >> >> Device support: >> >> In 2.6.30, the Intel=AE 82576 Gigabit Ethernet Controller is the only >> SR-IOV capable device supported. The igb driver has PF support and the >> igbvf has VF support. >> >> In 2.6.31 the Neterion=AE X3100=99 is supported as well. This device uses >> the same vxge driver for the PF as well as the VFs. >> >> In order to configure the test: >> >> =A0 * For SR-IOV virtual functions passthrough, we could specify the >> =A0 =A0 module parameter 'max_vfs' in config file. >> =A0 * For physical NIC card pass through, we should specify the device >> =A0 =A0 name(s). > > Looks good for me. > Lucas, thank you so much for improving this patch. :-) > >> >> Signed-off-by: Yolkfull Chow >> Signed-off-by: Lucas Meneghel Rodrigues >> --- >> =A0client/tests/kvm/kvm_utils.py =A0 =A0 =A0 =A0 =A0| =A0284 +++++++++++= +++++++++++++++++++++ >> =A0client/tests/kvm/kvm_vm.py =A0 =A0 =A0 =A0 =A0 =A0 | =A0 60 +++++++ >> =A0client/tests/kvm/tests_base.cfg.sample | =A0 22 +++- >> =A03 files changed, 365 insertions(+), 1 deletions(-) >> >> diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.= py >> index 2bbbe22..a2d9607 100644 >> --- a/client/tests/kvm/kvm_utils.py >> +++ b/client/tests/kvm/kvm_utils.py >> @@ -924,3 +924,287 @@ def create_report(report_dir, results_dir): >> =A0 =A0 =A0reporter =3D os.path.join(report_dir, 'html_report.py') >> =A0 =A0 =A0html_file =3D os.path.join(results_dir, 'results.html') >> =A0 =A0 =A0os.system('%s -r %s -f %s -R' % (reporter, results_dir, html_= file)) >> + >> + >> +def get_full_pci_id(pci_id): >> + =A0 =A0""" >> + =A0 =A0Get full PCI ID of pci_id. >> + >> + =A0 =A0@param pci_id: PCI ID of a device. >> + =A0 =A0""" >> + =A0 =A0cmd =3D "lspci -D | awk '/%s/ {print $1}'" % pci_id >> + =A0 =A0status, full_id =3D commands.getstatusoutput(cmd) >> + =A0 =A0if status !=3D 0: >> + =A0 =A0 =A0 =A0return None >> + =A0 =A0return full_id >> + >> + >> +def get_vendor_from_pci_id(pci_id): >> + =A0 =A0""" >> + =A0 =A0Check out the device vendor ID according to pci_id. >> + >> + =A0 =A0@param pci_id: PCI ID of a device. >> + =A0 =A0""" >> + =A0 =A0cmd =3D "lspci -n | awk '/%s/ {print $3}'" % pci_id >> + =A0 =A0return re.sub(":", " ", commands.getoutput(cmd)) >> + >> + >> +class PciAssignable(object): >> + =A0 =A0""" >> + =A0 =A0Request PCI assignable devices on host. It will check whether t= o request >> + =A0 =A0PF (physical Functions) or VF (Virtual Functions). >> + =A0 =A0""" >> + =A0 =A0def __init__(self, type=3D"nic_vf", driver=3DNone, driver_optio= n=3DNone, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 names=3DNone, devices_requested=3DNone= ): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Initialize parameter 'type' which could be: >> + =A0 =A0 =A0 =A0nic_vf: Virtual Functions >> + =A0 =A0 =A0 =A0nic_pf: Physical Function (actual hardware) >> + =A0 =A0 =A0 =A0mixed: =A0Both includes VFs and PFs >> + >> + =A0 =A0 =A0 =A0If pass through Physical NIC cards, we need to specify = which devices >> + =A0 =A0 =A0 =A0to be assigned, e.g. 'eth1 eth2'. >> + >> + =A0 =A0 =A0 =A0If pass through Virtual Functions, we need to specify h= ow many vfs >> + =A0 =A0 =A0 =A0are going to be assigned, e.g. passthrough_count =3D 8 = and max_vfs in >> + =A0 =A0 =A0 =A0config file. >> + >> + =A0 =A0 =A0 =A0@param type: PCI device type. >> + =A0 =A0 =A0 =A0@param driver: Kernel module for the PCI assignable dev= ice. >> + =A0 =A0 =A0 =A0@param driver_option: Module option to specify the maxi= mum number of >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0VFs (eg 'max_vfs=3D7') >> + =A0 =A0 =A0 =A0@param names: Physical NIC cards correspondent network = interfaces, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0e.g.'eth1 eth2 ...' >> + =A0 =A0 =A0 =A0@param devices_requested: Number of devices being reque= sted. >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0self.type =3D type >> + =A0 =A0 =A0 =A0self.driver =3D driver >> + =A0 =A0 =A0 =A0self.driver_option =3D driver_option >> + =A0 =A0 =A0 =A0if names: >> + =A0 =A0 =A0 =A0 =A0 =A0self.name_list =3D names.split() >> + =A0 =A0 =A0 =A0if devices_requested: >> + =A0 =A0 =A0 =A0 =A0 =A0self.devices_requested =3D int(devices_requeste= d) >> + =A0 =A0 =A0 =A0else: >> + =A0 =A0 =A0 =A0 =A0 =A0self.devices_requested =3D None >> + >> + >> + =A0 =A0def _get_pf_pci_id(self, name, search_str): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Get the PF PCI ID according to name. >> + >> + =A0 =A0 =A0 =A0@param name: Name of the PCI device. >> + =A0 =A0 =A0 =A0@param search_str: Search string to be used on lspci. >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0cmd =3D "ethtool -i %s | awk '/bus-info/ {print $2}'" %= name >> + =A0 =A0 =A0 =A0s, pci_id =3D commands.getstatusoutput(cmd) >> + =A0 =A0 =A0 =A0if not (s or "Cannot get driver information" in pci_id): >> + =A0 =A0 =A0 =A0 =A0 =A0return pci_id[5:] >> + =A0 =A0 =A0 =A0cmd =3D "lspci | awk '/%s/ {print $1}'" % search_str >> + =A0 =A0 =A0 =A0pci_ids =3D [id for id in commands.getoutput(cmd).split= lines()] >> + =A0 =A0 =A0 =A0nic_id =3D int(re.search('[0-9]+', name).group(0)) >> + =A0 =A0 =A0 =A0if (len(pci_ids) - 1) < nic_id: >> + =A0 =A0 =A0 =A0 =A0 =A0return None >> + =A0 =A0 =A0 =A0return pci_ids[nic_id] >> + >> + >> + =A0 =A0def _release_dev(self, pci_id): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Release a single PCI device. >> + >> + =A0 =A0 =A0 =A0@param pci_id: PCI ID of a given PCI device. >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0base_dir =3D "/sys/bus/pci" >> + =A0 =A0 =A0 =A0full_id =3D get_full_pci_id(pci_id) >> + =A0 =A0 =A0 =A0vendor_id =3D get_vendor_from_pci_id(pci_id) >> + =A0 =A0 =A0 =A0drv_path =3D os.path.join(base_dir, "devices/%s/driver"= % full_id) >> + =A0 =A0 =A0 =A0if 'pci-stub' in os.readlink(drv_path): >> + =A0 =A0 =A0 =A0 =A0 =A0cmd =3D "echo '%s' > %s/new_id" % (vendor_id, d= rv_path) >> + =A0 =A0 =A0 =A0 =A0 =A0if os.system(cmd): >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False >> + >> + =A0 =A0 =A0 =A0 =A0 =A0stub_path =3D os.path.join(base_dir, "drivers/p= ci-stub") >> + =A0 =A0 =A0 =A0 =A0 =A0cmd =3D "echo '%s' > %s/unbind" % (full_id, stu= b_path) >> + =A0 =A0 =A0 =A0 =A0 =A0if os.system(cmd): >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False >> + >> + =A0 =A0 =A0 =A0 =A0 =A0driver =3D self.dev_drivers[pci_id] >> + =A0 =A0 =A0 =A0 =A0 =A0cmd =3D "echo '%s' > %s/bind" % (full_id, drive= r) >> + =A0 =A0 =A0 =A0 =A0 =A0if os.system(cmd): >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False >> + >> + =A0 =A0 =A0 =A0return True >> + >> + >> + =A0 =A0def get_vf_devs(self): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Catch all VFs PCI IDs. >> + >> + =A0 =A0 =A0 =A0@return: List with all PCI IDs for the Virtual Function= s avaliable >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0if not self.sr_iov_setup(): >> + =A0 =A0 =A0 =A0 =A0 =A0return [] >> + >> + =A0 =A0 =A0 =A0cmd =3D "lspci | awk '/Virtual Function/ {print $1}'" >> + =A0 =A0 =A0 =A0return commands.getoutput(cmd).split() >> + >> + >> + =A0 =A0def get_pf_devs(self): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Catch all PFs PCI IDs. >> + >> + =A0 =A0 =A0 =A0@return: List with all PCI IDs for the physical hardwar= e requested >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0pf_ids =3D [] >> + =A0 =A0 =A0 =A0for name in self.name_list: >> + =A0 =A0 =A0 =A0 =A0 =A0pf_id =3D self._get_pf_pci_id(name, "Ethernet") >> + =A0 =A0 =A0 =A0 =A0 =A0if not pf_id: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue >> + =A0 =A0 =A0 =A0 =A0 =A0pf_ids.append(pf_id) >> + =A0 =A0 =A0 =A0return pf_ids >> + >> + >> + =A0 =A0def get_devs(self, count): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Check out all devices' PCI IDs according to their name. >> + >> + =A0 =A0 =A0 =A0@param count: count number of PCI devices needed for pa= ss through >> + =A0 =A0 =A0 =A0@return: a list of all devices' PCI IDs >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0if self.type =3D=3D "nic_vf": >> + =A0 =A0 =A0 =A0 =A0 =A0vf_ids =3D self.get_vf_devs() >> + =A0 =A0 =A0 =A0elif self.type =3D=3D "nic_pf": >> + =A0 =A0 =A0 =A0 =A0 =A0vf_ids =3D self.get_pf_devs() >> + =A0 =A0 =A0 =A0elif self.type =3D=3D "mixed": >> + =A0 =A0 =A0 =A0 =A0 =A0vf_ids =3D self.get_vf_devs() >> + =A0 =A0 =A0 =A0 =A0 =A0vf_ids.extend(self.get_pf_devs()) >> + =A0 =A0 =A0 =A0return vf_ids[0:count] >> + >> + >> + =A0 =A0def get_vfs_count(self): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Get VFs count number according to lspci. >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0cmd =3D "lspci | grep 'Virtual Function' | wc -l" >> + =A0 =A0 =A0 =A0# For each VF we'll see 2 prints of 'Virtual Function',= so let's >> + =A0 =A0 =A0 =A0# divide the result per 2 >> + =A0 =A0 =A0 =A0return int(commands.getoutput(cmd)) / 2 >> + >> + >> + =A0 =A0def check_vfs_count(self): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Check VFs count number according to the parameter drive= r_options. >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0return (self.get_vfs_count =3D=3D self.devices_requeste= d) >> + >> + >> + =A0 =A0def is_binded_to_stub(self, full_id): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Verify whether the device with full_id is already binde= d to pci-stub. >> + >> + =A0 =A0 =A0 =A0@param full_id: Full ID for the given PCI device >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0base_dir =3D "/sys/bus/pci" >> + =A0 =A0 =A0 =A0stub_path =3D os.path.join(base_dir, "drivers/pci-stub") >> + =A0 =A0 =A0 =A0if os.path.exists(os.path.join(stub_path, full_id)): >> + =A0 =A0 =A0 =A0 =A0 =A0return True >> + =A0 =A0 =A0 =A0return False >> + >> + >> + =A0 =A0def sr_iov_setup(self): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Ensure the PCI device is working in sr_iov mode. >> + >> + =A0 =A0 =A0 =A0Check if the PCI hardware device drive is loaded with t= he appropriate, >> + =A0 =A0 =A0 =A0parameters (number of VFs), and if it's not, perform se= tup. >> + >> + =A0 =A0 =A0 =A0@return: True, if the setup was completed successfuly, = False otherwise. >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0re_probe =3D False >> + =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput('lsmod | grep %s' % s= elf.driver) >> + =A0 =A0 =A0 =A0if s: >> + =A0 =A0 =A0 =A0 =A0 =A0re_probe =3D True >> + =A0 =A0 =A0 =A0elif not self.check_vfs_count(): >> + =A0 =A0 =A0 =A0 =A0 =A0os.system("modprobe -r %s" % self.driver) >> + =A0 =A0 =A0 =A0 =A0 =A0re_probe =3D True >> + >> + =A0 =A0 =A0 =A0# Re-probe driver with proper number of VFs >> + =A0 =A0 =A0 =A0if re_probe: >> + =A0 =A0 =A0 =A0 =A0 =A0cmd =3D "modprobe %s %s" % (self.driver, self.d= river_option) >> + =A0 =A0 =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput(cmd) >> + =A0 =A0 =A0 =A0 =A0 =A0if s: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False >> + =A0 =A0 =A0 =A0 =A0 =A0if not self.check_vfs_count(): >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False >> + =A0 =A0 =A0 =A0 =A0 =A0return True >> + >> + >> + =A0 =A0def request_devs(self): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Implement setup process: unbind the PCI device and then= bind it >> + =A0 =A0 =A0 =A0to the pci-stub driver. >> + >> + =A0 =A0 =A0 =A0@return: a list of successfully requested devices' PCI = IDs. >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0base_dir =3D "/sys/bus/pci" >> + =A0 =A0 =A0 =A0stub_path =3D os.path.join(base_dir, "drivers/pci-stub") >> + >> + =A0 =A0 =A0 =A0self.pci_ids =3D self.get_devs(self.devices_requested) >> + =A0 =A0 =A0 =A0logging.debug("The following pci_ids were found: %s" % = self.pci_ids) >> + =A0 =A0 =A0 =A0requested_pci_ids =3D [] >> + =A0 =A0 =A0 =A0self.dev_drivers =3D {} >> + >> + =A0 =A0 =A0 =A0# Setup all devices specified for assignment to guest >> + =A0 =A0 =A0 =A0for pci_id in self.pci_ids: >> + =A0 =A0 =A0 =A0 =A0 =A0full_id =3D get_full_pci_id(pci_id) >> + =A0 =A0 =A0 =A0 =A0 =A0if not full_id: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue >> + =A0 =A0 =A0 =A0 =A0 =A0drv_path =3D os.path.join(base_dir, "devices/%s= /driver" % full_id) >> + =A0 =A0 =A0 =A0 =A0 =A0dev_prev_driver=3D os.path.realpath(os.path.joi= n(drv_path, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0os.readlink(drv_path))) >> + =A0 =A0 =A0 =A0 =A0 =A0self.dev_drivers[pci_id] =3D dev_prev_driver >> + >> + =A0 =A0 =A0 =A0 =A0 =A0# Judge whether the device driver has been bind= ed to stub >> + =A0 =A0 =A0 =A0 =A0 =A0if not self.is_binded_to_stub(full_id): >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Binding device %s to stu= b" % full_id) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0vendor_id =3D get_vendor_from_pci_id(pc= i_id) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0stub_new_id =3D os.path.join(stub_path,= 'new_id') >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0unbind_dev =3D os.path.join(drv_path, '= unbind') >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0stub_bind =3D os.path.join(stub_path, '= bind') >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0info_write_to_files =3D [(vendor_id, st= ub_new_id), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 (full_id, unbind_dev), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 (full_id, stub_bind)] >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0for content, file in info_write_to_file= s: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0try: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0utils.open_write_close(= content, file) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0except IOError: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Failed t= o write %s to file %s" % >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0(content, file)) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self.is_binded_to_stub(full_id): >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.error("Binding device %= s to stub failed" % >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pci= _id) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue >> + =A0 =A0 =A0 =A0 =A0 =A0else: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Device %s already binded= to stub" % pci_id) >> + =A0 =A0 =A0 =A0 =A0 =A0requested_pci_ids.append(pci_id) >> + =A0 =A0 =A0 =A0self.pci_ids =3D requested_pci_ids >> + =A0 =A0 =A0 =A0return self.pci_ids >> + >> + >> + =A0 =A0def release_devs(self): >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0Release all PCI devices currently assigned to VMs back = to the >> + =A0 =A0 =A0 =A0virtualization host. >> + =A0 =A0 =A0 =A0""" >> + =A0 =A0 =A0 =A0try: >> + =A0 =A0 =A0 =A0 =A0 =A0for pci_id in self.dev_drivers: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self._release_dev(pci_id): >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.error("Failed to releas= e device %s to host" % >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pci= _id) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.info("Released device %= s successfully" % pci_id) >> + =A0 =A0 =A0 =A0except: >> + =A0 =A0 =A0 =A0 =A0 =A0return >> diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py >> index 7229b79..78a16ac 100755 >> --- a/client/tests/kvm/kvm_vm.py >> +++ b/client/tests/kvm/kvm_vm.py >> @@ -119,6 +119,7 @@ class VM: >> =A0 =A0 =A0 =A0 =A0self.params =3D params >> =A0 =A0 =A0 =A0 =A0self.root_dir =3D root_dir >> =A0 =A0 =A0 =A0 =A0self.address_cache =3D address_cache >> + =A0 =A0 =A0 =A0self.pci_assignable =3D None >> >> =A0 =A0 =A0 =A0 =A0# Find available monitor filename >> =A0 =A0 =A0 =A0 =A0while True: >> @@ -304,6 +305,12 @@ class VM: >> =A0 =A0 =A0 =A0 =A0elif params.get("uuid"): >> =A0 =A0 =A0 =A0 =A0 =A0 =A0qemu_cmd +=3D " -uuid %s" % params.get("uuid") >> >> + =A0 =A0 =A0 =A0# If the PCI assignment step went OK, add each one of t= he PCI assigned >> + =A0 =A0 =A0 =A0# devices to the qemu command line. >> + =A0 =A0 =A0 =A0if self.pci_assignable: >> + =A0 =A0 =A0 =A0 =A0 =A0for pci_id in self.pa_pci_ids: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0qemu_cmd +=3D " -pcidevice host=3D%s" %= pci_id >> + >> =A0 =A0 =A0 =A0 =A0return qemu_cmd >> >> >> @@ -392,6 +399,50 @@ class VM: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.uuid =3D f.read().strip() >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0f.close() >> >> + =A0 =A0 =A0 =A0 =A0 =A0if not params.get("pci_assignable") =3D=3D "no": >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa_type =3D params.get("pci_assignable") >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa_devices_requested =3D params.get("de= vices_requested") >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Virtual Functions (VF) assignable dev= ices >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if pa_type =3D=3D "vf": >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa_driver =3D params.get("drive= r") >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa_driver_option =3D params.get= ("driver_option") >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pci_assignable =3D kvm_uti= ls.PciAssignable(type=3Dpa_type, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0driver=3Dpa_driver, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0driver_option=3Dpa_driver_option, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0devices_requested=3Dpa_devices_requested) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Physical NIC (PF) assignable devices >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0elif pa_type =3D=3D "pf": >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa_device_names =3D params.get(= "device_names") >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pci_assignable =3D kvm_uti= ls.PciAssignable(type=3Dpa_type, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 names=3Dpa_device_names, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 devices_requested=3Dpa_devices_requested) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Working with both VF and PF >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0elif pa_type =3D=3D "mixed": >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa_device_names =3D params.get(= "device_names") >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa_driver =3D params.get("drive= r") >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa_driver_option =3D params.get= ("driver_option") >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pci_assignable =3D kvm_uti= ls.PciAssignable(type=3Dpa_type, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0driver=3Dpa_driver, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0driver_option=3Dpa_driver_option, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0names=3Dpa_device_names, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0devices_requested=3Dpa_devices_requested) >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pa_pci_ids =3D self.pci_assignable= .request_devs() >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if self.pa_pci_ids: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Successfuly assi= gned devices: %s" % >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0sel= f.pa_pci_ids) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.error("No PCI assignabl= e devices were assigned " >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"an= d 'pci_assignable' is defined to %s " >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"on= your config file. Aborting VM creation." % >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa_= type) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False >> + >> + =A0 =A0 =A0 =A0 =A0 =A0else: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pci_assignable =3D None >> + >> =A0 =A0 =A0 =A0 =A0 =A0 =A0# Make qemu command >> =A0 =A0 =A0 =A0 =A0 =A0 =A0qemu_command =3D self.make_qemu_command() >> >> @@ -537,6 +588,8 @@ class VM: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0# Is it already dead? >> =A0 =A0 =A0 =A0 =A0 =A0 =A0if self.is_dead(): >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("VM is already down") >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if self.pci_assignable: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pci_assignable.release_dev= s() >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Destroying VM with PID %d..." % >> @@ -557,6 +610,9 @@ class VM: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0finally: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0session.close() >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if self.pci_assignable: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pci_assign= able.release_devs() >> + >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0# Try to destroy with a monitor command >> =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Trying to kill VM with monitor= command...") >> @@ -566,6 +622,8 @@ class VM: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Wait for the VM to be really dead >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if kvm_utils.wait_for(self.is_dead, 5= , 0.5, 0.5): >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("VM is down") >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if self.pci_assignable: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pci_assignable.rel= ease_devs() >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0# If the VM isn't dead yet... >> @@ -575,6 +633,8 @@ class VM: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0# Wait for the VM to be really dead >> =A0 =A0 =A0 =A0 =A0 =A0 =A0if kvm_utils.wait_for(self.is_dead, 5, 0.5, 0= .5): >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("VM is down") >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if self.pci_assignable: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pci_assignable.release_dev= s() >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.error("Process %s is a zombie!" % sel= f.process.get_pid()) >> diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/t= ests_base.cfg.sample >> index b8f25f4..49b6d6b 100644 >> --- a/client/tests/kvm/tests_base.cfg.sample >> +++ b/client/tests/kvm/tests_base.cfg.sample >> @@ -889,7 +889,27 @@ variants: >> =A0 =A0 =A0 =A0 =A0extra_params +=3D " -mem-path /mnt/kvm_hugepage" >> >> >> +variants: >> + =A0 =A0- @no_pci_assignable: >> + =A0 =A0 =A0 =A0pci_assignable =3D no >> + =A0 =A0- pf_assignable: >> + =A0 =A0 =A0 =A0pci_assignable =3D pf >> + =A0 =A0 =A0 =A0device_names =3D eth1 >> + =A0 =A0- vf_assignable: >> + =A0 =A0 =A0 =A0pci_assignable =3D vf >> + =A0 =A0 =A0 =A0# Driver (kernel module) that supports SR-IOV hardware. >> + =A0 =A0 =A0 =A0# As of today (30-11-2009), we have 2 drivers for this = type of hardware: >> + =A0 =A0 =A0 =A0# Intel=AE 82576 Gigabit Ethernet Controller - igb >> + =A0 =A0 =A0 =A0# Neterion=AE X3100=99 - vxge >> + =A0 =A0 =A0 =A0driver =3D igb >> + =A0 =A0 =A0 =A0# Driver option to specify the maximum number of virtua= l functions >> + =A0 =A0 =A0 =A0# (on vxge the option is , for example, is max_config_d= ev) >> + =A0 =A0 =A0 =A0# the default below is for the igb driver >> + =A0 =A0 =A0 =A0driver_option =3D "max_vfs=3D7" >> + =A0 =A0 =A0 =A0# Number of devices that are going to be requested. >> + =A0 =A0 =A0 =A0devices_requested =3D 7 >> + >> + >> =A0image_name.* ?<=3D images/ >> =A0cdrom.* ?<=3D isos/ >> =A0steps ?<=3D steps/ >> - >> -- >> 1.6.5.2 > _______________________________________________ > Autotest mailing list > Autotest@test.kernel.org > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest > -- = Lucas