设为首页 收藏本站
查看: 921|回复: 0

[经验分享] XEN passthrough NIC on SuSE

[复制链接]

尚未签到

发表于 2015-10-11 13:43:52 | 显示全部楼层 |阅读模式
  The idea is to bind the pci device (in your case a nic) to the pciback
module in the dom0 guest and then assign it to the target domU.
There are two main ways to achieve that, depending on how long you want the change to last:
a) If you want to assign the pci device to the target domU on a transient basis, do a manual allocation.
The allocation will only last until you reboot the system or the domU guest.
b) If you want the assigment to remain persistent among system reboots,
stick to the automatic approach, that basically consists on editing the
modprobe conf file, building a new initrd file system and changing the
affected domU guest configuration file so that it includes the PCI
device id in the pci parameter.
I'll only cover here the transient one.
For illustration purposes I'll use my wireless nic. Adapt the procedure to your system.
a) Manual allocation
Having your system started in Xen mode, from a dom0 bash root session do the following:
-Step 1: Find if your dom0 have support for the pciback module.
If you are using open Suse 11, and are using the stock kernel, it
should have it:


Code:
lustmord:~ # uname -r
2.6.25.18-0.2-xen
lustmord:~ # lsmod | grep pciback
lustmord:~ # modprobe pciback
lustmord:~ # lsmod | grep pciback
pciback                33940  0
xenbus_be               8192  4 pciback,netbk,blkbk,blktap
lustmord:~ #
  
Check that the directory /sys/bus/pci/drivers/pciback exists and looks like this:


Code:
lustmord:/sys/bus/pci/drivers/pciback # ls -l
total 0
--w------- 1 root root 4096 Dec  4 23:19 bind
lrwxrwxrwx 1 root root    0 Dec  4 22:58 module -> ../../../../module/pciback
--w------- 1 root root 4096 Dec  4 23:19 new_id
--w------- 1 root root 4096 Dec  4 23:19 new_slot
-rw------- 1 root root 4096 Dec  4 23:19 permissive
-rw------- 1 root root 4096 Dec  4 23:19 quirks
--w------- 1 root root 4096 Dec  4 23:19 remove_slot
-r-------- 1 root root 4096 Dec  4 23:19 slots
--w------- 1 root root 4096 Dec  4 23:19 uevent
--w------- 1 root root 4096 Dec  4 23:19 unbind
lustmord:/sys/bus/pci/drivers/pciback #
  
If it does, pciback was loaded correctly.

-Step 2: Find out the PCI device id corresponding to the device you want to allocate to the target domU:


Code:
lustmord:~ # lspci | grep [Ww]ireless
03:00.0 Network controller: Intel Corporation PRO/Wireless 4965 AG or AGN Network Connection (rev 61)
lustmord:~ #
  The long format for the PCI Id is then : 0000:03:00.0

Step 3: Find out the driver (module)  to which this PCI device is currently bound:


Code:
lustmord:~ # find /sys/bus/pci/drivers -name "0000:03:00.0"
/sys/bus/pci/drivers/iwl4965/0000:03:00.0
lustmord:~ #
  
Good, iwl4965 is bound to it. Double check that the directory content looks like this


Code:
lustmord:/sys/bus/pci/drivers/iwl4965 # ls -lrt
total 0
--w------- 1 root root 4096 Dec  4 21:44 unbind
--w------- 1 root root 4096 Dec  4 21:44 uevent
--w------- 1 root root 4096 Dec  4 21:44 new_id
lrwxrwxrwx 1 root root    0 Dec  4 21:44 module -> ../../../../module/iwl4965
--w------- 1 root root 4096 Dec  4 21:44 bind
lrwxrwxrwx 1 root root    0 Dec  4 21:44 0000:03:00.0 -> ../../../../devices/pci0000:00/0000:00:1c.1/0000:03:00.0
lustmord:/sys/bus/pci/drivers/iwl4965 #
  
Step 4: Unbind the PCI device from the iwl4965 driver:


Code:
lustmord:~ # echo -n "0000:03:00.0" > /sys/bus/pci/drivers/iwl4965/unbind
lustmord:~ #
  We can verify that, in fact, the driver iwl4965  has been unbound from the PCI device located at  0000:03:00.0 by doing this:


Code:
lustmord:~ # cd /sys/bus/pci/drivers/iwl4965/
lustmord:/sys/bus/pci/drivers/iwl4965 # ls
bind  module  new_id  uevent  unbind
lustmord:/sys/bus/pci/drivers/iwl4965 # ls -lrt
total 0
--w------- 1 root root 4096 Dec  4 21:44 uevent
--w------- 1 root root 4096 Dec  4 21:44 new_id
lrwxrwxrwx 1 root root    0 Dec  4 21:44 module -> ../../../../module/iwl4965
--w------- 1 root root 4096 Dec  4 21:44 bind
--w------- 1 root root    0 Dec  4 23:10 unbind
lustmord:/sys/bus/pci/drivers/iwl4965 #
  You will notice that the link to the PCI id vanished. That's what we want.

Step 5: Bound the PCI id  0000:03:00.0 to the pciback module


Code:
lustmord:~ # echo -n "0000:03:00.0" > /sys/bus/pci/drivers/pciback/new_slot
lustmord:~ # echo -n "0000:03:00.0" > /sys/bus/pci/drivers/pciback/bind
  
Good. Now, verify that the module pciback is seeing the PCI   0000:03:00.0 device:


Code:
lustmord:~ # cd /sys/bus/pci/drivers/pciback/
lustmord:/sys/bus/pci/drivers/pciback # ls -l
total 0
lrwxrwxrwx 1 root root    0 Dec  4 23:25 0000:03:00.0 -> ../../../../devices/pci0000:00/0000:00:1c.1/0000:03:00.0
--w------- 1 root root    0 Dec  4 23:23 bind
lrwxrwxrwx 1 root root    0 Dec  4 22:58 module -> ../../../../module/pciback
--w------- 1 root root 4096 Dec  4 23:19 new_id
--w------- 1 root root    0 Dec  4 23:23 new_slot
-rw------- 1 root root 4096 Dec  4 23:19 permissive
-rw------- 1 root root 4096 Dec  4 23:19 quirks
--w------- 1 root root 4096 Dec  4 23:19 remove_slot
-r-------- 1 root root 4096 Dec  4 23:19 slots
--w------- 1 root root 4096 Dec  4 23:19 uevent
--w------- 1 root root 4096 Dec  4 23:19 unbind
lustmord:/sys/bus/pci/drivers/pciback #
  
Right, just as we wanted.

Step 6: Allocate the PCI  0000:03:00.0 device to the target domU:
Now, we are in conditions to attach the device to the xen guest which
is going to use it. Having the target domU stopped, run the following
command to start it with the new device:


Code:
lustmord:~ # xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1857     2     r-----    217.7
vm1-sles10                                       512     1                 0.0
vm2-sles10                                       512     1                 0.0
vm3-opensuse11                                   384     1                 0.0
  Now, we launch the domU:


Code:
lustmord:~ # xm create pci=0000:03:00.0 /etc/xen/vm/vm3-opensuse11
Using config file "/etc/xen/vm/vm3-opensuse11".
Started domain vm3-opensuse11
lustmord:~ #
  
Wait until the target domU is running, connect to it and verify that
the device was attached correctly using lspci. Once you have done that,
proceed like always. Configure the module manually or using yast:


Code:
lustmord:~ # xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1592     2     r-----    321.6
vm1-sles10                                       512     1                 0.0
vm2-sles10                                       512     1                 0.0
vm3-opensuse11                               1   384     1     -b----     20.2
lustmord:~ #
  
Now, connect to the domU:


Code:
lustmord:~ # xm console 1
Security Framework initialized
AppArmor: AppArmor initialized <NULL>
AppArmor: Registered secondary security module capability
Capability LSM initialized as secondary
Mount-cache hash table entries: 512
CPU: L1 I cache: 32K, L1 D cache: 32K
....
...
...
EXT3 FS on xvda2, internal journal
EXT3-fs: mounted filesystem with ordered data mode.
iwl4965: Intel(R) Wireless WiFi Link 4965AGN driver for Linux, 1.2.23ks
iwl4965: Copyright(c) 2003-2007 Intel Corporation
PCI: Enabling device 0000:00:00.0 (0000 -> 0002)
iwl4965: Detected Intel Wireless WiFi Link 4965AGN
iwl4965: Tunable channels: 13 802.11bg, 19 802.11a channels
....
....
....
ip_tables: (C) 2000-2006 Netfilter Core Team
nf_conntrack version 0.5.0 (7168 buckets, 28672 max)

Welcome to openSUSE 11.0 (i586) - Kernel 2.6.25.5-1.1-xen (xvc0).

linux-i8s4 login:
  Now you log in and run lspci:


Code:
linux-i8s4 login: root
password:
Have a lot of fun...
linux-i8s4:~ # lspci
00:00.0 Network controller: Intel Corporation PRO/Wireless 4965 AG or AGN Network Connection (rev 61)
linux-i8s4:~ #
  
There you have it. That is good. Now you run yast and do all the other things....And that's all there is to it.
   
版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-125479-1-1.html 上篇帖子: Xen基本原理 下篇帖子: XEN安装DOMU&OPENNEBULA虚拟机镜像制作
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表