[Devel] [Q] Connecting a physical HDD/partition to a container

Stanislav Kinsburskiу skinsbursky at odin.com
Wed Jan 27 11:04:17 PST 2016


27 янв. 2016 г. 5:30 PM пользователь Evgenii Shatokhin <eshatokhin at virtuozzo.com> написал:
>
> 27.01.2016 19:08, Stanislav Kinsburskiy пишет: 
> > 
> > 
> > 27.01.2016 16:02, Evgenii Shatokhin пишет: 
> >> 27.01.2016 16:38, Igor Sukhih пишет: 
> >>> On 01/27/2016 04:29 PM, Stanislav Kinsburskiу wrote: 
> >>>> 27 янв. 2016 г. 14:24 пользователь Evgenii Shatokhin 
> >>>> <eshatokhin at virtuozzo.com> написал: 
> >>>>> I created it with 
> >>>>> vzctl set 101 --devnodes sdb1:rw --save 
> >>>>> 
> >>>>> The node is now present in the CT. However, if I try to mount it in 
> >>>>> the CT (mount /dev/sdb1 /mnt), no error is reported but mount seems to 
> >>>>> have no effect. No files are seen in /mnt that are present on that 
> >>>>> partition. 
> >>>>> 
> >>>>> So, I guess, additional steps are needed? 
> >>>>> 
> >>>>>> You might need sysfs layout. 
> >>>>>> Please, strace your mount call and send it as a reply (attached). 
> >>>>>> 
> >>>>> Here it is. 
> >>>>> 
> >>>>> As far as I can see in strace log, mount tries to open 
> >>>>> /sys/dev/block/8:17, indeed. This file is present on the host but 
> >>>>> not in 
> >>>>> the CT. 
> >>>>> 
> >>>> Expectable. 
> >>>> Then you have to expose sysfs for this device to the container. 
> >>>> Igor, could you advice, please? 
> >>>> 
> >>> 
> >>> Lets try to use secondary disk feature first 
> >>> 
> >>> vzctl set VEID --device-add hdd --device /dev/sda --save 
> >> 
> >> No luck. The CT fails to start with "Failed to configure disk" after 
> >> that. 
> >> 
> > 
> > You can do it manually. 
> > There is a file: 
> > 
> > /sys/fs/cgroup/ve/c<CTID>/ve.sysfs_permissions 
> > 
> > which controls sysfs layout. 
> > 
> > Please, reply with results of: 
> > 
> > # ls -l /sys/dev/block/8:17 
> > 
> > I'll send you, what you have to write to this file. 
>
> Thanks for your help! 
>
> With libvzctl-7.0.172, vzctl set VEID --device-add <...> worked. 
>
> Now I am curious about these sysfs settings, just in case I will need do 
> such things manually in the future. 
>
> Could you still explain what should be done there? 
>
> Here is the output you asked for: 
>
> # ls -l /sys/dev/block/8:17 
> lrwxrwxrwx 1 root root 0 Jan 27 12:26 /sys/dev/block/8:17 -> 
> ../../devices/pci0000:00/0000:00:0d.0/ata2/host1/target1:0:0/1:0:0:0/block/sdb/sdb1 
>
> # ls -l 
> /sys/devices/pci0000:00/0000:00:0d.0/ata2/host1/target1:0:0/1:0:0:0/block/sdb/sdb1 
> total 0 
> -r--r--r-- 1 root root 4096 Jan 27 16:20 alignment_offset 
> -r--r--r-- 1 root root 4096 Jan 27 12:26 dev 
> -r--r--r-- 1 root root 4096 Jan 27 16:20 discard_alignment 
> drwxr-xr-x 2 root root    0 Jan 27 16:20 holders 
> -r--r--r-- 1 root root 4096 Jan 27 16:20 inflight 
> -r--r--r-- 1 root root 4096 Jan 27 12:26 partition 
> drwxr-xr-x 2 root root    0 Jan 27 16:20 power 
> -r--r--r-- 1 root root 4096 Jan 27 16:20 ro 
> -r--r--r-- 1 root root 4096 Jan 27 12:26 size 
> -r--r--r-- 1 root root 4096 Jan 27 12:26 start 
> -r--r--r-- 1 root root 4096 Jan 27 16:20 stat 
> lrwxrwxrwx 1 root root    0 Jan 27 12:26 subsystem -> 
> ../../../../../../../../../../class/block 
> drwxr-xr-x 2 root root    0 Jan 27 16:20 trace 
> -rw-r--r-- 1 root root 4096 Jan 27 12:26 uevent 
>

It's simple.
Yes have to write these paths to /sys/fs/cgroup/ve/c<CTID>/ve.sysfs_permissions like this:

# echo "path rx" >> /sys/fs/cgroup/ve/<CTID>/ve.sysfs_permissions

Notes:
1) "rx" are permissions: read and execute. Check host sysfs, what permissions to set.
2) writing the whole path won't work. You have to share one directory by another.
I.e. in case of "devices/pci0000:00/0000:00:0d.0/ata2/host1/target1:0:0/1:0:0:0/block/sdb/sdb1" you have to expose devices first, then devices/pci0000:00 and so on.
3) you have to expose the whole path to the symlink as well.
4) all paths are relative to sysfs root. I.e. no /sys/ in the beginning.
5) using of non-canonical paths (with ../) can be not supported.

IOW, you have to expose desired part of sysfs node by node.

Good luck.

> Regards, 
> Evgenii 



More information about the Devel mailing list