<div dir="ltr"><div>Hi!</div><div><br></div><div>First post, kind of a noobie. I've been working with LXC and libvirt for a few months now. Trying to do some interesting things with containers and Android devices :D</div>

<div><br></div>I'm running ubuntu 13.10 with LXC 1.0.1 and tried both libvirt 1.1.1 and 1.2.2 (backported from ubuntu-trusty), but with either version of libvirt am getting issues as soon as I try to get access to USB devices inside the container.<div>

<br></div><div>Relevant versions of stuff:<br><div><br></div><div><div>$ dpkg -l | grep -i lxc</div><div>ii  liblxc1                              1.0.1-0ubuntu1~ubuntu13.10.1~ppa1 i386         Linux Containers userspace tools (library)</div>

<div>ii  lxc                                  1.0.1-0ubuntu1~ubuntu13.10.1~ppa1 i386         Linux Containers userspace tools</div><div>ii  lxc-templates                        1.0.1-0ubuntu1~ubuntu13.10.1~ppa1 i386         Linux Containers userspace tools (templates)</div>

<div>ii  python3-lxc                          1.0.1-0ubuntu1~ubuntu13.10.1~ppa1 i386         Linux Containers userspace tools (Python 3.x bindings)</div></div><div><br></div><div><div>$ dpkg -l | grep libvirt</div><div>ii  libvirt-bin                          1.2.2-0ubuntu12                   i386         programs for the libvirt library</div>

<div>ii  libvirt0                             1.2.2-0ubuntu12                   i386         library for interfacing with different virtualization systems</div><div>ii  python-libvirt                       1.2.2-0ubuntu1                    i386         libvirt Python bindings</div>

</div><div><br></div><div>Here's my entire domain definition:</div><div><br></div><div><div><domain type='lxc'></div><div>  <name>oshi32134</name></div><div>  <uuid>xxxxx</uuid></div>

<div>  <memory unit='KiB'>3145728</memory></div><div>  <currentMemory unit='KiB'>3145728</currentMemory></div><div>  <vcpu placement='static'>1</vcpu></div><div>

  <resource></div><div>    <partition>/machine</partition></div><div>  </resource></div><div>  <os></div><div>    <type arch='i686'>exe</type></div><div>    <init>/sbin/init</init></div>

<div>  </os></div><div>  <clock offset='utc'/></div><div>  <on_poweroff>destroy</on_poweroff></div><div>  <on_reboot>restart</on_reboot></div><div>  <on_crash>destroy</on_crash></div>

<div>  <devices></div><div>    <emulator>/usr/lib/libvirt/libvirt_lxc</emulator></div><div>    <filesystem type='mount' accessmode='passthrough'></div><div>      <source dir='/some/valid/filesystem/location'/></div>

<div>      <target dir='/'/></div><div>    </filesystem></div><div>    <filesystem type='mount' accessmode='passthrough'></div><div>      <source dir='/another/valid/filesystem/location'/></div>

<div>      <target dir='/mnt/android'/></div><div>    </filesystem></div><div>    <interface type='bridge'></div><div>      <mac address='xx:xx:xx:xx:xx:xx'/></div><div>      <source bridge='br1'/></div>

<div>    </interface></div><div>    <console type='pty'></div><div>      <target type='lxc' port='0'/></div><div>    </console></div><div>    <hostdev mode='capabilities' type='misc'></div>

<div>      <source></div><div>        <char>/dev/kvm</char></div><div>      </source></div><div>    </hostdev></div><div><div>    <hostdev mode='subsystem' type='usb' managed='yes'></div>

<div>      <source></div><div>        <span style="color:rgb(0,0,0);white-space:pre-wrap"><vendor id='0x04e8'/></span></div><div>        <span style="color:rgb(0,0,0);white-space:pre-wrap"><product id='0x6860'/></span><span style="color:rgb(0,0,0);white-space:pre-wrap"><br>

</span></div><div><font color="#000000"><span style="white-space:pre-wrap">      </span></font></source></div><div>    </hostdev></div></div><div>  </devices></div><div></domain></div></div><div><br>

</div><div>Everything worked fine until I added the USB <hostdev> element. I'm essentially trying to get access to a physical Android device connected to the host from inside a container. When I go to start the container, I get an error about Operation not permitted. Here's the relevant bits from /var/log/libvirt/lxc/machine.log:</div>

<div><br></div><div><div>2014-04-11 22:46:40.491+0000: starting up</div><div>PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin LIBVIRT_DEBUG=3 LIBVIRT_LOG_OUTPUTS=3:stderr /usr/lib/libvirt/libvirt_lxc --name oshi32134 --console 24 --security=none --handshake 27 --background --veth vnet1</div>

<div>2014-04-11 22:46:40.597+0000: 685: info : libvirt version: 1.2.2</div><div>2014-04-11 22:46:40.597+0000: 685: error : virLXCControllerSetupHostdevSubsysUSB:1390 : Unable to create device //var/run/libvirt/lxc/oshi32134.dev/bus/usb//002//003: Operation not permitted</div>

<div>Unable to create device //var/run/libvirt/lxc/oshi32134.dev/bus/usb//002//003: Operation not permitted</div></div><div><br></div><div>I get the same output above when I use libvirt 1.1.1.</div><div><br></div><div>Tracing down through the libvirt code it looks like it fails when calling `mknod`. It's clear that libvirt converts the product/vendor ids I specified in the domain definition file to the appropriate USB bus (/dev/bus/usb/002/003, verified by comparing against output of `usb-devices`).</div>

<div><br></div><div>In a parallel effort, a colleague of mine set up a vanilla LXContainer on a new install of the same version of ubuntu, and successfully was able to communicate with the Android device from a container. The only configuration tweaks he made was make sure to whitelist the cgroup with the appropriate major/minor device number (associated with the Android device) inside the LXC configuration file. From there the container was able to appropriately create the device file as you attach/detach the Android device. </div>

<div><br></div><div>Hopefully someone can shed some light, and appreciate your patience with me as I am learning a lot of this stuff as I go :)</div><div><br></div><div>Thanks in advance for any help!</div><div>Fil</div>
</div>
</div>