From: Yolkfull Chow Subject: Re: [Autotest] [PATCH] Add pass through feature test (support SR-IOV) Date: Thu, 15 Oct 2009 14:46:28 +0800 Message-ID: <20091015064628.GB2503@aFu.nay.redhat.com> References: <1252981235-4145-1-git-send-email-yzhou@redhat.com> <6ac58f4f0910140513x78bd66d0h3f91cdd1d34fb4fe@mail.gmail.com> Reply-To: Yolkfull Chow 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: Lucas Meneghel Rodrigues Return-path: Received: from mx1.redhat.com ([209.132.183.28]:25321 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932869AbZJOGq6 (ORCPT ); Thu, 15 Oct 2009 02:46:58 -0400 Content-Disposition: inline In-Reply-To: <6ac58f4f0910140513x78bd66d0h3f91cdd1d34fb4fe@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Oct 14, 2009 at 09:13:59AM -0300, Lucas Meneghel Rodrigues wrot= e: > Yolkfull, I've studied about single root IO virtualization before > reviewing your patch, the general approach here looks good. There wer= e > 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). >=20 > 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. >=20 > Thanks! Lucas, thank you very much for adding a detailed explanation and improving for this test. I had reviewed the new patch and some new consideration came to my mind. I had added them on the email, please reviewed. :) >=20 > On Mon, Sep 14, 2009 at 11:20 PM, Yolkfull Chow wr= ote: > > It supports both SR-IOV virtual functions' and physical NIC card pa= ss through. > > =A0* For SR-IOV virtual functions passthrough, we could specify the= module > > =A0 =A0parameter 'max_vfs' in config file. > > =A0* For physical NIC card pass through, we should specify the devi= ce 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/k= vm/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_u= tils.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/dr= iver" % 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, "driv= ers/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, = prev_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] successf= ully" % pci_id) > > + > > + > > +class PassThrough: > > + =A0 =A0""" > > + =A0 =A0Request passthroughable devices on host. It will check whe= ther 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 spe= cify which devices > > + =A0 =A0 =A0 =A0to be assigned, e.g. 'eth1 eth2'. > > + > > + =A0 =A0 =A0 =A0If pass through Virtual Functions, we need to spec= ify 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= eth2 ...' > > + =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= loaded 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 ig= b') > > + =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= =2Emax_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= _vfs'. > > + =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 pc= i_id): > > + =A0 =A0 =A0 =A0 =A0 =A0return pci_id[5:] > > + > > + =A0 =A0 =A0 =A0cmd =3D "lspci | awk '/%s/ {print $1}'" % search_s= tr > > + =A0 =A0 =A0 =A0pci_ids =3D [id for id in commands.getoutput(cmd).= splitlines()] > > + =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 = binded 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-= 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 request_devs(self, count, pt_file, setup=3DTrue): > > + =A0 =A0 =A0 =A0""" > > + =A0 =A0 =A0 =A0Implement setup process: unbind the PCI device and= then bind it > > + =A0 =A0 =A0 =A0to 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.catch_devs(int(count)) > > + =A0 =A0 =A0 =A0logging.debug("Catch_devs has found pci_ids: %s" %= self.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 passthro= ugh 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.realpat= h(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_p= rev_driver > > + > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Judge whether the device driver = has been binded to stub > > + =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.debug("Setting up = device: %s" % full_id) > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0stub_new_id =3D os.path.jo= in(stub_path, 'new_id') > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0unbind_dev =3D os.path.joi= n(drv_path, 'unbind') > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0stub_bind =3D os.path.join= (stub_path, 'bind') > > + > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0vendor_id =3D get_vendor_i= d(pci_id) > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self._echo_to_file(= vendor_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(= full_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(= full_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_s= tub(full_id): > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.error("Req= uest 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]= already 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 = name. > > + > > + =A0 =A0 =A0 =A0@param count: count number of PCI devices needed f= or 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.p= y > > 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("uui= d") > > > > + =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 "ni= c_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("passth= rough_devs")) > > + =A0 =A0 =A0 =A0 =A0 =A0elif params.get("pass_through") =3D=3D "mi= xed": > > + =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 =A0ma= x_vfs =3D params.get("max_vfs"), > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0na= mes=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_cou= nt, 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 assign= ment > > + =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_throu= gh") > > + > > + =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 as= sign VFs to guest") > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrou= gh(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 as= sign physical NICs to guest") > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrou= gh(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 NI= Cs may contain both VFs and PFs") > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrou= gh(type =3D pt_type, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0max_vfs =3D params= =2Eget("max_vfs"), > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0names =3D params.g= et("passthrough_devs")) > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_count =3D params.get("passthrou= gh_count") > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_db_file =3D open('/tmp/passthro= ugh_db', 'w') > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pt_pci_ids =3D pt.request_dev= s(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 spe= cified 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 = device(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= to 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= _db', '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= =2Eprocess.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 comma= nd...") > > @@ -536,6 +600,7 @@ class VM: > > =A0 =A0 =A0 =A0 =A0 =A0 if kvm_utils.wait_for(self.is_dead, 5, 0.5,= 0.5): > > =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.proc= ess.get_pid()) > > -- > > 1.6.2.5 > > > > _______________________________________________ > > Autotest mailing list > > Autotest@test.kernel.org > > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest > > >=20 >=20 >=20 > --=20 > Lucas