linux compat: namespaces and cgroups

From: Chris Stephan <chris.stephan_at_live.com>
Date: Sat, 23 Oct 2021 13:01:07 UTC
Running into too many roadblocks now that namespaces and cgroups are so common (and used outside of docker/systems.) I begin working for an organization in the coming weeks that is very Linux focused, and when delving into their stack, their software makes heavy use internally of these Linux functions. As I would love to be able to test on my native workstation, I have decided on the normal masochistic way that it would be fun to extend /compat/linux to allow use on FreeBSD kernels.

I understand we have *jail* and *rctl* and my intent is not to displace this functionality but to leverage the Linux compat layer to talk native to FreeBSD native structures. Obviously not everything will have a direct analogue, but I’ve been reading through the src for a few days now and it looks close enough to be possible. Alchemy aside the following is what looks like it would require implementation:

Syscalls: setns(), unshare(), extension of clone(), ioprio_get(), ioprio_set(), SYS_ioprio_get, SYS_ioprio_set, prlimit() and extension of setrlimit()

SYS_ioprio_* syscall() subroutines: IOPRIO_WHO_PROCESS, IOPRIO_WHO_PGRP, IOPRIO_WHO_USER for who/which args

IOPRIO_PRIO_VALUE(), IOPRIO_PRIO_CLASS(), IOPRIO_PRIO_DATA()

ioctl() would need to support: NS_GET_USERNS, NS_GET_PARENT, CLONE_IO

I am quite sure this is the single strand of a woven mess, but I believe the more this can be just an exposure of the FreeBSD internals as Linux ABI and less Linux ABI implementation, the simpler it will be.

First, when perusing the archives I haven’t seen anything indicating this has been attempted before, but if there is any prior work that someone would be willing to allow my collaboration or continuation on, it would be great to know before I get started.

Second, I most likely will need access to someone that can speak eloquently to the FreeBSD IO scheduler to see how IOPRIO_CLASS_*  and Linux’s CFQ interface should be handled with rctl analogues. I have some texts I’m hoping will enlighten me. If anyone knows of a good reference short the src tree or would be willing to speak out of band expediting my understanding, I would be greatly appreciative.

Finally, if there is anyone else who has interest in this, feel free to speak up. The more the merrier.

Thanks,

Chris

Sent from FreeBSD