From: Lucas Meneghel Rodrigues Subject: Re: [Autotest] [PATCH] Add pass through feature test (support SR-IOV) Date: Wed, 14 Oct 2009 09:13:59 -0300 Message-ID: <6ac58f4f0910140513x78bd66d0h3f91cdd1d34fb4fe@mail.gmail.com> References: <1252981235-4145-1-git-send-email-yzhou@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org, autotest@test.kernel.org To: Yolkfull Chow Return-path: Received: from mail-px0-f189.google.com ([209.85.216.189]:35787 "EHLO mail-px0-f189.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758613AbZJNMOf convert rfc822-to-8bit (ORCPT ); Wed, 14 Oct 2009 08:14:35 -0400 Received: by pxi27 with SMTP id 27so1029305pxi.22 for ; Wed, 14 Oct 2009 05:13:59 -0700 (PDT) In-Reply-To: <1252981235-4145-1-git-send-email-yzhou@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Yolkfull, I've studied about single root IO virtualization before reviewing your patch, the general approach here looks good. There were some stylistic points as far as code is concerned, so I have rebased your patch against the latest trunk, and added some explanation about the features being tested and referenced (extracted from a Fedora 12 blueprint). Please let me know if you are OK with it, I guess I will review this patch a couple more times, as the code and the features being tested are fairly complex. Thanks! On Mon, Sep 14, 2009 at 11:20 PM, Yolkfull Chow wrot= e: > It supports both SR-IOV virtual functions' and physical NIC card pass= through. > =A0* For SR-IOV virtual functions passthrough, we could specify the m= odule > =A0 =A0parameter 'max_vfs' in config file. > =A0* For physical NIC card pass through, we should specify the device= name(s). > > Signed-off-by: Yolkfull Chow > --- > =A0client/tests/kvm/kvm_tests.cfg.sample | =A0 12 ++ > =A0client/tests/kvm/kvm_utils.py =A0 =A0 =A0 =A0 | =A0248 +++++++++++= +++++++++++++++++++++- > =A0client/tests/kvm/kvm_vm.py =A0 =A0 =A0 =A0 =A0 =A0| =A0 68 +++++++= ++- > =A03 files changed, 326 insertions(+), 2 deletions(-) > > diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm= /kvm_tests.cfg.sample > index a83ef9b..c6037da 100644 > --- a/client/tests/kvm/kvm_tests.cfg.sample > +++ b/client/tests/kvm/kvm_tests.cfg.sample > @@ -627,6 +627,18 @@ variants: > > > =A0variants: > + =A0 =A0- @no_passthrough: > + =A0 =A0 =A0 =A0pass_through =3D no > + =A0 =A0- nic_passthrough: > + =A0 =A0 =A0 =A0pass_through =3D pf > + =A0 =A0 =A0 =A0passthrough_devs =3D eth1 > + =A0 =A0- vfs_passthrough: > + =A0 =A0 =A0 =A0pass_through =3D vf > + =A0 =A0 =A0 =A0max_vfs =3D 7 > + =A0 =A0 =A0 =A0vfs_count =3D 7 > + > + > +variants: > =A0 =A0 - @basic: > =A0 =A0 =A0 =A0 only Fedora Windows > =A0 =A0 - @full: > diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_uti= ls.py > index dfca938..1fe3b31 100644 > --- a/client/tests/kvm/kvm_utils.py > +++ b/client/tests/kvm/kvm_utils.py > @@ -1,5 +1,5 @@ > =A0import md5, thread, subprocess, time, string, random, socket, os, = signal, pty > -import select, re, logging, commands > +import select, re, logging, commands, cPickle > =A0from autotest_lib.client.bin import utils > =A0from autotest_lib.client.common_lib import error > =A0import kvm_subprocess > @@ -795,3 +795,249 @@ def md5sum_file(filename, size=3DNone): > =A0 =A0 =A0 =A0 size -=3D len(data) > =A0 =A0 f.close() > =A0 =A0 return o.hexdigest() > + > + > +def get_full_id(pci_id): > + =A0 =A0""" > + =A0 =A0Get full PCI ID of pci_id. > + =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_id(pci_id): > + =A0 =A0""" > + =A0 =A0Check out the device vendor ID according to PCI ID. > + =A0 =A0""" > + =A0 =A0cmd =3D "lspci -n | awk '/%s/ {print $3}'" % pci_id > + =A0 =A0return re.sub(":", " ", commands.getoutput(cmd)) > + > + > +def release_pci_devs(dict): > + =A0 =A0""" > + =A0 =A0Release assigned PCI devices to host. > + =A0 =A0""" > + =A0 =A0def release_dev(pci_id): > + =A0 =A0 =A0 =A0base_dir =3D "/sys/bus/pci" > + =A0 =A0 =A0 =A0full_id =3D get_full_id(pci_id) > + =A0 =A0 =A0 =A0vendor_id =3D get_vendor_id(pci_id) > + =A0 =A0 =A0 =A0drv_path =3D os.path.join(base_dir, "devices/%s/driv= er" % 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= , drv_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, "driver= s/pci-stub") > + =A0 =A0 =A0 =A0 =A0 =A0cmd =3D "echo '%s' > %s/unbind" % (full_id, = stub_path) > + =A0 =A0 =A0 =A0 =A0 =A0if os.system(cmd): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False > + > + =A0 =A0 =A0 =A0 =A0 =A0prev_driver =3D self.dev_prev_drivers[pci_id= ] > + =A0 =A0 =A0 =A0 =A0 =A0cmd =3D "echo '%s' > %s/bind" % (full_id, pr= ev_driver) > + =A0 =A0 =A0 =A0 =A0 =A0if os.system(cmd): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False > + =A0 =A0 =A0 =A0return True > + > + =A0 =A0for pci_id in dict.keys(): > + =A0 =A0 =A0 =A0if not release_dev(pci_id): > + =A0 =A0 =A0 =A0 =A0 =A0logging.error("Failed to release device [%s]= to host" % pci_id) > + =A0 =A0 =A0 =A0else: > + =A0 =A0 =A0 =A0 =A0 =A0logging.info("Release device [%s] successful= ly" % pci_id) > + > + > +class PassThrough: > + =A0 =A0""" > + =A0 =A0Request passthroughable devices on host. It will check wheth= er to request > + =A0 =A0PF(physical NIC cards) or VF(Virtual Functions). > + =A0 =A0""" > + =A0 =A0def __init__(self, type=3D"nic_vf", max_vfs=3DNone, names=3D= None): > + =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 NIC card > + =A0 =A0 =A0 =A0mixed: =A0Both includes VFs and PFs > + > + =A0 =A0 =A0 =A0If pass through Physical NIC cards, we need to speci= fy which devices > + =A0 =A0 =A0 =A0to be assigned, e.g. 'eth1 eth2'. > + > + =A0 =A0 =A0 =A0If pass through Virtual Functions, we need to specif= y how 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: Pass through device's type > + =A0 =A0 =A0 =A0@param max_vfs: parameter of module 'igb' > + =A0 =A0 =A0 =A0@param names: Physical NIC cards' names, e.g.'eth1 e= th2 ...' > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0self.type =3D type > + =A0 =A0 =A0 =A0if max_vfs: > + =A0 =A0 =A0 =A0 =A0 =A0self.max_vfs =3D int(max_vfs) > + =A0 =A0 =A0 =A0if names: > + =A0 =A0 =A0 =A0 =A0 =A0self.name_list =3D names.split() > + > + =A0 =A0def sr_iov_setup(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Setup SR-IOV environment, check if module 'igb' is l= oaded with > + =A0 =A0 =A0 =A0parameter 'max_vfs'. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0re_probe =3D False > + =A0 =A0 =A0 =A0# Check whether the module 'igb' is loaded > + =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput('lsmod | grep igb'= ) > + =A0 =A0 =A0 =A0if s: > + =A0 =A0 =A0 =A0 =A0 =A0re_probe =3D True > + =A0 =A0 =A0 =A0elif not self.chk_vfs_count(): > + =A0 =A0 =A0 =A0 =A0 =A0os.system("modprobe -r igb") > + =A0 =A0 =A0 =A0 =A0 =A0re_probe =3D True > + > + =A0 =A0 =A0 =A0# Re-probe module 'igb' > + =A0 =A0 =A0 =A0if re_probe: > + =A0 =A0 =A0 =A0 =A0 =A0cmd =3D "modprobe igb max_vfs=3D%d" % self.m= ax_vfs > + =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.chk_vfs_count(): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False > + =A0 =A0 =A0 =A0return True > + > + =A0 =A0def get_vfs_count(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Get Vfs count number according to 'max_vfs' > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0cmd =3D "lspci | grep 'Virtual Function' | wc -l" > + =A0 =A0 =A0 =A0return int(commands.getoutput(cmd)) > + > + =A0 =A0def chk_vfs_count(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Check VFs count number according to parameter 'max_v= fs'. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0if self.get_vfs_count() !=3D (self.max_vfs * 2): > + =A0 =A0 =A0 =A0 =A0 =A0return False > + =A0 =A0 =A0 =A0return True > + > + =A0 =A0def _get_pci_id(self, name, search_str): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Get the device's PCI ID according to name. > + =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).sp= litlines()] > + =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 _echo_to_file(self, content, file_path): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Simply echo some content to file. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0cmd =3D "echo %s > %s" % (content, file_path) > + =A0 =A0 =A0 =A0status, output =3D commands.getstatusoutput(cmd) > + =A0 =A0 =A0 =A0if status !=3D 0: > + =A0 =A0 =A0 =A0 =A0 =A0return False > + =A0 =A0 =A0 =A0return True > + > + =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 bi= nded to pci-stub. > + =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-st= ub") > + =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 request_devs(self, count, pt_file, setup=3DTrue): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Implement setup process: unbind the PCI device and t= hen bind it > + =A0 =A0 =A0 =A0to pci-stub driver. > + > + =A0 =A0 =A0 =A0@return: a list of successfully requested devices' P= CI 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-st= ub") > + > + =A0 =A0 =A0 =A0self.pci_ids =3D self.catch_devs(int(count)) > + =A0 =A0 =A0 =A0logging.debug("Catch_devs has found pci_ids: %s" % s= elf.pci_ids) > + > + =A0 =A0 =A0 =A0if setup: > + =A0 =A0 =A0 =A0 =A0 =A0requested_pci_ids =3D [] > + =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Going to setup devices: %s" %= self.pci_ids) > + =A0 =A0 =A0 =A0 =A0 =A0dev_prev_drivers =3D {} > + > + =A0 =A0 =A0 =A0 =A0 =A0# Setup all devices specified for passthroug= h to guest > + =A0 =A0 =A0 =A0 =A0 =A0for pci_id in self.pci_ids: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0full_id =3D get_full_id(pci_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not full_id: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0drv_path =3D os.path.join(base_dir, = "devices/%s/driver" % full_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev_prev_driver=3D os.path.realpath(= os.path.join(drv_path, > + =A0 =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 =A0 =A0 =A0dev_prev_drivers[pci_id] =3D dev_pre= v_driver > + > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Judge whether the device driver ha= s been binded to stub > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self.is_binded_to_stub(full_i= d): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Setting up de= vice: %s" % full_id) > + =A0 =A0 =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 =A0 =A0 =A0unbind_dev =3D os.path.join(= drv_path, 'unbind') > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0stub_bind =3D os.path.join(s= tub_path, 'bind') > + > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0vendor_id =3D get_vendor_id(= pci_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self._echo_to_file(ve= ndor_id, stub_new_id): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self._echo_to_file(fu= ll_id, unbind_dev): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self._echo_to_file(fu= ll_id, stub_bind): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self.is_binded_to_stu= b(full_id): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.error("Reque= st device failed: %s" % pci_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Device [%s] a= lready binded to stub" % pci_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0requested_pci_ids.append(pci_id) > + =A0 =A0 =A0 =A0 =A0 =A0cPickle.dump(dev_prev_drivers, pt_file) > + =A0 =A0 =A0 =A0 =A0 =A0self.pci_ids =3D requested_pci_ids > + =A0 =A0 =A0 =A0return self.pci_ids > + > + =A0 =A0def catch_vf_devs(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Catch all VFs PCI IDs and return as a list. > + =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 catch_pf_devs(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Catch all PFs PCI IDs. > + =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_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 catch_devs(self, count): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Check out all devices' PCI IDs according to their na= me. > + > + =A0 =A0 =A0 =A0@param count: count number of PCI devices needed for= pass 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.catch_vf_devs() > + =A0 =A0 =A0 =A0elif self.type =3D=3D "nic_pf": > + =A0 =A0 =A0 =A0 =A0 =A0vf_ids =3D self.catch_pf_devs() > + =A0 =A0 =A0 =A0elif self.type =3D=3D "mixed": > + =A0 =A0 =A0 =A0 =A0 =A0vf_ids =3D self.catch_vf_devs() > + =A0 =A0 =A0 =A0 =A0 =A0vf_ids.extend(self.catch_pf_devs()) > + =A0 =A0 =A0 =A0return vf_ids[0:count] > diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py > index bd7e0fc..90827a2 100755 > --- a/client/tests/kvm/kvm_vm.py > +++ b/client/tests/kvm/kvm_vm.py > @@ -1,5 +1,5 @@ > =A0#!/usr/bin/python > -import time, socket, os, logging, fcntl, re, commands > +import time, socket, os, logging, fcntl, re, commands, cPickle > =A0import kvm_utils, kvm_subprocess > > =A0""" > @@ -283,6 +283,29 @@ class VM: > =A0 =A0 =A0 =A0 elif params.get("uuid"): > =A0 =A0 =A0 =A0 =A0 =A0 qemu_cmd +=3D " -uuid %s" % params.get("uuid"= ) > > + =A0 =A0 =A0 =A0# Check whether pci_passthrough is turned on > + =A0 =A0 =A0 =A0if not params.get("pass_through") =3D=3D "no": > + =A0 =A0 =A0 =A0 =A0 =A0pt_type =3D params.get("pass_through") > + > + =A0 =A0 =A0 =A0 =A0 =A0# Virtual Functions pass through > + =A0 =A0 =A0 =A0 =A0 =A0if params.get("pass_through") =3D=3D "nic_vf= ": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough(type =3D= pt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 max_vfs =3D params.get("max_vfs")) > + =A0 =A0 =A0 =A0 =A0 =A0# Physical NIC card pass through > + =A0 =A0 =A0 =A0 =A0 =A0elif params.get("pass_through") =3D=3D "nic_= pf": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough(type=3D= pt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0names=3Dparams.get("passthro= ugh_devs")) > + =A0 =A0 =A0 =A0 =A0 =A0elif params.get("pass_through") =3D=3D "mixe= d": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough(type=3D= pt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0max_= vfs =3D params.get("max_vfs"), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0name= s=3Dparams.get("passthrough_devs")) > + =A0 =A0 =A0 =A0 =A0 =A0pt_count =3D params.get("passthrough_count") > + =A0 =A0 =A0 =A0 =A0 =A0pt_db_file =3D open("/tmp/passthrough_db", "= w") > + =A0 =A0 =A0 =A0 =A0 =A0self.pt_pci_ids =3D pt.request_devs(pt_count= , pt_file=3Dpt_db_file, setup=3DFalse) > + =A0 =A0 =A0 =A0 =A0 =A0pt_db_file.close() > + =A0 =A0 =A0 =A0 =A0 =A0for pci_id in self.pt_pci_ids: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0qemu_cmd +=3D " -pcidevice host=3D%s= " % pci_id > + > =A0 =A0 =A0 =A0 return qemu_cmd > > > @@ -365,6 +388,35 @@ class VM: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 self.uuid =3D f.read().strip() > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 f.close() > > + =A0 =A0 =A0 =A0 =A0 =A0# Request specified PCI devices for assignme= nt > + =A0 =A0 =A0 =A0 =A0 =A0if not params.get("pass_through") =3D=3D "no= ": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_type =3D params.get("pass_through= ") > + > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Virtual Functions pass through > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if params.get("pass_through") =3D=3D= "nic_vf": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Going to assi= gn VFs to guest") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough= (type =3D pt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 max_vfs =3D params.get("max_vfs")) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Physical NIC card pass through > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0elif params.get("pass_through") =3D=3D= "nic_pf": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Going to assi= gn physical NICs to guest") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough= (type=3Dpt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0names=3Dparams.get("= passthrough_devs")) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0elif params.get("pass_through") =3D=3D= "mixed": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Assigned NICs= may contain both VFs and PFs") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough= (type =3D pt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0max_vfs =3D params.g= et("max_vfs"), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0names =3D params.get= ("passthrough_devs")) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_count =3D params.get("passthrough= _count") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_db_file =3D open('/tmp/passthroug= h_db', 'w') > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pt_pci_ids =3D pt.request_devs(= pt_count, pt_file=3Dpt_db_file, setup=3DTrue) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_db_file.close() > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self.pt_pci_ids: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.error("Request speci= fied PCI device(s) failed;" > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= " pt_pci_ids are: %s" % self.pt_pci_ids) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Requested host PCI de= vice(s): %s" % self.pt_pci_ids) > + > =A0 =A0 =A0 =A0 =A0 =A0 # Make qemu command > =A0 =A0 =A0 =A0 =A0 =A0 qemu_command =3D self.make_qemu_command() > > @@ -501,11 +553,22 @@ class VM: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 using a shell command before trying t= o end the qemu process > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 with a 'quit' or a kill signal. > =A0 =A0 =A0 =A0 """ > + =A0 =A0 =A0 =A0# Release the assigned PCI devices or VFs to host > + =A0 =A0 =A0 =A0def release_pt_devs(): > + =A0 =A0 =A0 =A0 =A0 =A0try: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0db_file =3D open('/tmp/passthrough_d= b', 'r') > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_db =3D cPickle.load(db_file) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0kvm_utils.release_pci_devs(pt_db) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0db_file.close() > + =A0 =A0 =A0 =A0 =A0 =A0except: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return > + > =A0 =A0 =A0 =A0 # Is it already dead? > =A0 =A0 =A0 =A0 if self.is_dead(): > =A0 =A0 =A0 =A0 =A0 =A0 logging.debug("VM is already down") > =A0 =A0 =A0 =A0 =A0 =A0 if self.process: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 self.process.close() > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0release_pt_devs() > =A0 =A0 =A0 =A0 =A0 =A0 return > > =A0 =A0 =A0 =A0 logging.debug("Destroying VM with PID %d..." % self.p= rocess.get_pid()) > @@ -526,6 +589,7 @@ class VM: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 finally: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 session.close() > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0release_pt_devs() > > =A0 =A0 =A0 =A0 # Try to destroy with a monitor command > =A0 =A0 =A0 =A0 logging.debug("Trying to kill VM with monitor command= =2E..") > @@ -536,6 +600,7 @@ class VM: > =A0 =A0 =A0 =A0 =A0 =A0 if kvm_utils.wait_for(self.is_dead, 5, 0.5, 0= =2E5): > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 logging.debug("VM is down") > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 self.process.close() > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0release_pt_devs() > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return > > =A0 =A0 =A0 =A0 # If the VM isn't dead yet... > @@ -546,6 +611,7 @@ class VM: > =A0 =A0 =A0 =A0 if kvm_utils.wait_for(self.is_dead, 5, 0.5, 0.5): > =A0 =A0 =A0 =A0 =A0 =A0 logging.debug("VM is down") > =A0 =A0 =A0 =A0 =A0 =A0 self.process.close() > + =A0 =A0 =A0 =A0 =A0 =A0release_pt_devs() > =A0 =A0 =A0 =A0 =A0 =A0 return > > =A0 =A0 =A0 =A0 logging.error("Process %s is a zombie!" % self.proces= s.get_pid()) > -- > 1.6.2.5 > > _______________________________________________ > Autotest mailing list > Autotest@test.kernel.org > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest > --=20 Lucas