Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1450461 > unrolled thread
| Started by | "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> |
|---|---|
| First post | 2016-07-26 10:10 +0200 |
| Last post | 2016-07-31 23:40 +0200 |
| Articles | 8 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-07-26 10:10 +0200
Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces "W. Trevor King" <wking@tremily.us> - 2016-07-26 20:40 +0200
Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-07-26 21:20 +0200
Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-07-28 12:50 +0200
Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces ebiederm@xmission.com (Eric W. Biederman) - 2016-07-28 15:20 +0200
Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-07-28 21:10 +0200
Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces ebiederm@xmission.com (Eric W. Biederman) - 2016-07-29 20:20 +0200
Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-07-31 23:40 +0200
| From | "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> |
|---|---|
| Date | 2016-07-26 10:10 +0200 |
| Subject | Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces |
| Message-ID | <rZ5B8-7Yz-25@gated-at.bofh.it> |
On 07/26/2016 04:54 AM, Andrew Vagin wrote:
> On Mon, Jul 25, 2016 at 09:59:43AM -0500, Eric W. Biederman wrote:
>> "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes:
>
> [snip]
>
>> [snip]
>>>>> So, from my point of view, the important piece that was missing from
>>>>> your commit message was the note to use readlink("/proc/self/fd/%d")
>>>>> on the returned FDs. I think that detail needs to be part of the
>>>>> commit message (and also the man page text). I think it even be
>>>>> helpful to include the above program as part of the commit message:
>>>>> it helps people more quickly grasp the API.
>>>>
>>>> Please, please make the standard way to compare these things fstat.
>>>> That is much less magic than a symlink, and a little more future proof.
>>>> Possibly even kcmp.
>
> I like the idea to use kcmp to compare namespaces. I am going to add this
> functionality to kcmp and describe all these in the man page.
Hi Andrey,
Can you briefly sketch out the proposed API and how it would be used?
I'd find it useful to see that even before the implementation.
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
[toc] | [next] | [standalone]
| From | "W. Trevor King" <wking@tremily.us> |
|---|---|
| Date | 2016-07-26 20:40 +0200 |
| Message-ID | <rZfqN-5ya-3@gated-at.bofh.it> |
| In reply to | #1450461 |
[Multipart message — attachments visible in raw view] — view raw
On Tue, Jul 26, 2016 at 11:25:24AM -0700, Andrew Vagin wrote: > Sure. If a process wants to compare two namespaces, it needs to get file > descriptors for them (open /proc/PID/ns/XXX, use new ioctl-s, find a > process which has them), > and then it calls kcmp(pid1, pid2, KCMP_NSFD, ns_fd1, ns_fd2) If you use the new ioctl-s to get ns_fd2, do you walk your local /proc to find pid2? Cheers, Trevor -- This email may be signed or encrypted with GnuPG (http://www.gnupg.org). For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy
[toc] | [prev] | [next] | [standalone]
| From | "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> |
|---|---|
| Date | 2016-07-26 21:20 +0200 |
| Message-ID | <rZg3v-616-19@gated-at.bofh.it> |
| In reply to | #1450461 |
Hello Andrew,
On 26 July 2016 at 20:25, Andrew Vagin <avagin@virtuozzo.com> wrote:
> On Tue, Jul 26, 2016 at 10:03:25AM +0200, Michael Kerrisk (man-pages) wrote:
>> On 07/26/2016 04:54 AM, Andrew Vagin wrote:
>> > On Mon, Jul 25, 2016 at 09:59:43AM -0500, Eric W. Biederman wrote:
>> > > "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes:
>> >
>> > [snip]
>> >
>> > > [snip]
>> > > > > > So, from my point of view, the important piece that was missing from
>> > > > > > your commit message was the note to use readlink("/proc/self/fd/%d")
>> > > > > > on the returned FDs. I think that detail needs to be part of the
>> > > > > > commit message (and also the man page text). I think it even be
>> > > > > > helpful to include the above program as part of the commit message:
>> > > > > > it helps people more quickly grasp the API.
>> > > > >
>> > > > > Please, please make the standard way to compare these things fstat.
>> > > > > That is much less magic than a symlink, and a little more future proof.
>> > > > > Possibly even kcmp.
>> >
>> > I like the idea to use kcmp to compare namespaces. I am going to add this
>> > functionality to kcmp and describe all these in the man page.
>>
>> Hi Andrey,
>>
>> Can you briefly sketch out the proposed API and how it would be used?
>> I'd find it useful to see that even before the implementation.
>
> Sure. If a process wants to compare two namespaces, it needs to get file
> descriptors for them (open /proc/PID/ns/XXX, use new ioctl-s, find a
> process which has them),
> and then it calls kcmp(pid1, pid2, KCMP_NSFD, ns_fd1, ns_fd2)
>
> For example, if we want to compare pid namespaces for 1 and 2 processes:
>
What's the purpose of the following line, and the use of 'pid' in the
kcmp() call?:
> pid = getpid();
> ns_fd1 = open("/proc/1/ns/pid")
> ns_fd2 = open("/proc/2/ns/pid")
>
> if (!kcmp(pid, pid, KCMP_NSFD, ns_fd1, ns_fd2))
> printf("Both processes live in the same pid namespace\n");
Thanks,
Michael
[toc] | [prev] | [next] | [standalone]
| From | "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> |
|---|---|
| Date | 2016-07-28 12:50 +0200 |
| Message-ID | <rZR33-53d-1@gated-at.bofh.it> |
| In reply to | #1450806 |
On 07/26/2016 10:39 PM, Andrew Vagin wrote:
> On Tue, Jul 26, 2016 at 09:17:31PM +0200, Michael Kerrisk (man-pages) wrote:
>> Hello Andrew,
>>
>> On 26 July 2016 at 20:25, Andrew Vagin <avagin@virtuozzo.com> wrote:
>>> On Tue, Jul 26, 2016 at 10:03:25AM +0200, Michael Kerrisk (man-pages) wrote:
>>>> On 07/26/2016 04:54 AM, Andrew Vagin wrote:
>>>>> On Mon, Jul 25, 2016 at 09:59:43AM -0500, Eric W. Biederman wrote:
>>>>>> "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes:
>>>>>
>>>>> [snip]
>>>>>
>>>>>> [snip]
>>>>>>>>> So, from my point of view, the important piece that was missing from
>>>>>>>>> your commit message was the note to use readlink("/proc/self/fd/%d")
>>>>>>>>> on the returned FDs. I think that detail needs to be part of the
>>>>>>>>> commit message (and also the man page text). I think it even be
>>>>>>>>> helpful to include the above program as part of the commit message:
>>>>>>>>> it helps people more quickly grasp the API.
>>>>>>>>
>>>>>>>> Please, please make the standard way to compare these things fstat.
>>>>>>>> That is much less magic than a symlink, and a little more future proof.
>>>>>>>> Possibly even kcmp.
>>>>>
>>>>> I like the idea to use kcmp to compare namespaces. I am going to add this
>>>>> functionality to kcmp and describe all these in the man page.
>>>>
>>>> Hi Andrey,
>>>>
>>>> Can you briefly sketch out the proposed API and how it would be used?
>>>> I'd find it useful to see that even before the implementation.
>>>
>>> Sure. If a process wants to compare two namespaces, it needs to get file
>>> descriptors for them (open /proc/PID/ns/XXX, use new ioctl-s, find a
>>> process which has them),
>>> and then it calls kcmp(pid1, pid2, KCMP_NSFD, ns_fd1, ns_fd2)
>>>
>>> For example, if we want to compare pid namespaces for 1 and 2 processes:
>>>
>>
>> What's the purpose of the following line, and the use of 'pid' in the
>> kcmp() call?:
>
> It's the existing interface of kcmp. It's used to check whether the
> two processes identified by pid1 and pid2 share a kernel resource
> such as virtual memory, file descriptors, and so on.
Yes, understood, but it seems a slightly weird use of the interface,
since in general pid1 will be the same as pid2 in this use case,
whereas in the other use cases, pid1 and pid2 are generally not
equal.
> If we want to compare two file descriptors of the current process,
> it is one of cases for which kcmp can be used. We can call kcmp to
> compare two namespaces which are opened in other processes.
Is there really a use case there? I assume we're talking about the
scenario where a process in one namespace opens a /proc/PID/ns/*
file descriptor and passes that FD to another process via a UNIX
domain socket. Is that correct?
So, supposing that we want to build a map of the relationships
between namespaces using the proposed kcmp() API, and there are
say N namespaces? Does this mena we make (N * (N-1) / 2) calls
to kcmp()?
Cheers,
Michael
>>> pid = getpid();
>>> ns_fd1 = open("/proc/1/ns/pid")
>>> ns_fd2 = open("/proc/2/ns/pid")
>>>
>>> if (!kcmp(pid, pid, KCMP_NSFD, ns_fd1, ns_fd2))
>>> printf("Both processes live in the same pid namespace\n");
>>
>> Thanks,
>>
>> Michael
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
[toc] | [prev] | [next] | [standalone]
| From | ebiederm@xmission.com (Eric W. Biederman) |
|---|---|
| Date | 2016-07-28 15:20 +0200 |
| Subject | Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces |
| Message-ID | <rZTod-6L3-15@gated-at.bofh.it> |
| In reply to | #1451872 |
"Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes: > On 07/26/2016 10:39 PM, Andrew Vagin wrote: >> On Tue, Jul 26, 2016 at 09:17:31PM +0200, Michael Kerrisk (man-pages) wrote: >> If we want to compare two file descriptors of the current process, >> it is one of cases for which kcmp can be used. We can call kcmp to >> compare two namespaces which are opened in other processes. > > Is there really a use case there? I assume we're talking about the > scenario where a process in one namespace opens a /proc/PID/ns/* > file descriptor and passes that FD to another process via a UNIX > domain socket. Is that correct? > > So, supposing that we want to build a map of the relationships > between namespaces using the proposed kcmp() API, and there are > say N namespaces? Does this mena we make (N * (N-1) / 2) calls > to kcmp()? Potentially. The numbers are small enough O(N^2) isn't fatal. Where kcmp shines is that it allows migration to happen. Inode numbers to change (which they very much will today), and still have things work. We can keep it O(Nlog(N)) by taking advantage of not just the equality but the ordering relationship. Although Ugh. One disadvantage of kcmp currently is that the way the ordering relationship is defined the order is not preserved over migration :( Eric
[toc] | [prev] | [next] | [standalone]
| From | "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> |
|---|---|
| Date | 2016-07-28 21:10 +0200 |
| Message-ID | <rZYQV-20O-1@gated-at.bofh.it> |
| In reply to | #1451919 |
Hi Eric, On 07/28/2016 02:56 PM, Eric W. Biederman wrote: > "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes: > >> On 07/26/2016 10:39 PM, Andrew Vagin wrote: >>> On Tue, Jul 26, 2016 at 09:17:31PM +0200, Michael Kerrisk (man-pages) wrote: > >>> If we want to compare two file descriptors of the current process, >>> it is one of cases for which kcmp can be used. We can call kcmp to >>> compare two namespaces which are opened in other processes. >> >> Is there really a use case there? I assume we're talking about the >> scenario where a process in one namespace opens a /proc/PID/ns/* >> file descriptor and passes that FD to another process via a UNIX >> domain socket. Is that correct? >> >> So, supposing that we want to build a map of the relationships >> between namespaces using the proposed kcmp() API, and there are >> say N namespaces? Does this mena we make (N * (N-1) / 2) calls >> to kcmp()? > > Potentially. The numbers are small enough O(N^2) isn't fatal. Define "small", please. O(N^2) makes me nervous about what other use cases lurk out there that may get bitten by this. > Where kcmp shines is that it allows migration to happen. Inode numbers > to change (which they very much will today), and still have things work. > We can keep it O(Nlog(N)) by taking advantage of not just the equality > but the ordering relationship. Although Ugh. Yes, that sounds pretty ugly... >One disadvantage of > kcmp currently is that the way the ordering relationship is defined > the order is not preserved over migration :( So, does kcmp() fully solve the proble(s) at hand? It sounds like not, if I understand your last point correctly. -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
[toc] | [prev] | [next] | [standalone]
| From | ebiederm@xmission.com (Eric W. Biederman) |
|---|---|
| Date | 2016-07-29 20:20 +0200 |
| Subject | Re: [PATCH 0/5 RFC] Add an interface to discover relationships between namespaces |
| Message-ID | <s0ky6-8fT-3@gated-at.bofh.it> |
| In reply to | #1452055 |
"Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes: > Hi Eric, > > On 07/28/2016 02:56 PM, Eric W. Biederman wrote: >> "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes: >> >>> On 07/26/2016 10:39 PM, Andrew Vagin wrote: >>>> On Tue, Jul 26, 2016 at 09:17:31PM +0200, Michael Kerrisk (man-pages) wrote: >> >>>> If we want to compare two file descriptors of the current process, >>>> it is one of cases for which kcmp can be used. We can call kcmp to >>>> compare two namespaces which are opened in other processes. >>> >>> Is there really a use case there? I assume we're talking about the >>> scenario where a process in one namespace opens a /proc/PID/ns/* >>> file descriptor and passes that FD to another process via a UNIX >>> domain socket. Is that correct? >>> >>> So, supposing that we want to build a map of the relationships >>> between namespaces using the proposed kcmp() API, and there are >>> say N namespaces? Does this mena we make (N * (N-1) / 2) calls >>> to kcmp()? >> >> Potentially. The numbers are small enough O(N^2) isn't fatal. > > Define "small", please. > > O(N^2) makes me nervous about what other use cases lurk out > there that may get bitten by this. Worst case for N (One namespace per thread) is about 60k. A typical heavy use case may be 1000 namespaces of any type. So we are talking about O(N^2) that rarely happens and should be done in a couple of seconds. >> Where kcmp shines is that it allows migration to happen. Inode numbers >> to change (which they very much will today), and still have things work. > > >> We can keep it O(Nlog(N)) by taking advantage of not just the equality >> but the ordering relationship. Although Ugh. > > Yes, that sounds pretty ugly... Actually having thought about this a little more if kcmp returns an ordering by inode and migration preserves the relative order of the inodes (which should just be a creation order) it should be quite solvable. Switch from an order by inode number to an order by object creation time, and guarantee that all creations are have an order (which with task_list_lock we practically already have) and it should be even easier to create. (A 64bit nanosecond resolution timestamp is good for 544 years of uptime). A 64bit number that increments each time an object is created should have an even better lifespan. I don't know if we can find a way to give that guarantee for other kcmp comparisons but it is worth a thought. >>One disadvantage of >> kcmp currently is that the way the ordering relationship is defined >> the order is not preserved over migration :( > > So, does kcmp() fully solve the proble(s) at hand? It sounds like > not, if I understand your last point correctly. There are 3 possibilities I see for migration in migration, ordered in order of implementation difficulty. 1) Have a clear signal that migration happened and a nested migration needs to restart. 2) Use kcmp so that only the relative order needs to be preserved. 3) Preserve the device number and inode numbers. At a practical level I think (2) may actually in net be the simplest. It requires a little more care to implement and you have to opt in, but it should not require any rolling back of activity (merely careful ordering of object creation). I definititely like kcmp knowing how to compare things by inode (aka st_dev, st_inode) because then even if you have to restart the comparisons after a migration the exact details you are comparing are hidden and so it is easier to support and harder to get wrong. I can imagine how to preserve inode numbers by creating a new instance of nsfs instance and using the old inode numbers upon restore. I don't currently see how we could possibly preserve st_dev over migration short of a device number namespace. So if we are going to continue with making device numbers be a legacy attribute applications should not care about we need a way to compare things by not looking at st_dev. Which brings us back to kcmp. Hmm. Hotplugging as disk and plugging it back likely will change the device number and give the same kind of challenge with st_dev (although you can't keep a file descriptor open across that kind of event). So certainly a hotplug event on a device should be enough to say don't care about the device number. Eric
[toc] | [prev] | [next] | [standalone]
| From | "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> |
|---|---|
| Date | 2016-07-31 23:40 +0200 |
| Message-ID | <s16CJ-5vO-1@gated-at.bofh.it> |
| In reply to | #1452507 |
Hi Eric, On 07/29/2016 08:05 PM, Eric W. Biederman wrote: > "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes: > >> Hi Eric, >> >> On 07/28/2016 02:56 PM, Eric W. Biederman wrote: >>> "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes: >>> >>>> On 07/26/2016 10:39 PM, Andrew Vagin wrote: >>>>> On Tue, Jul 26, 2016 at 09:17:31PM +0200, Michael Kerrisk (man-pages) wrote: >>> >>>>> If we want to compare two file descriptors of the current process, >>>>> it is one of cases for which kcmp can be used. We can call kcmp to >>>>> compare two namespaces which are opened in other processes. >>>> >>>> Is there really a use case there? I assume we're talking about the >>>> scenario where a process in one namespace opens a /proc/PID/ns/* >>>> file descriptor and passes that FD to another process via a UNIX >>>> domain socket. Is that correct? >>>> >>>> So, supposing that we want to build a map of the relationships >>>> between namespaces using the proposed kcmp() API, and there are >>>> say N namespaces? Does this mena we make (N * (N-1) / 2) calls >>>> to kcmp()? >>> >>> Potentially. The numbers are small enough O(N^2) isn't fatal. >> >> Define "small", please. >> >> O(N^2) makes me nervous about what other use cases lurk out >> there that may get bitten by this. > > Worst case for N (One namespace per thread) is about 60k. I'm getting an education here: where does the 60k number come from? > A typical heavy use case may be 1000 namespaces of any type. > So we are talking about O(N^2) that rarely happens and should be done in > a couple of seconds. I don't know whether that's acceptable for the migration use case, but seems quite bad for the visualization use case. >>> Where kcmp shines is that it allows migration to happen. Inode numbers >>> to change (which they very much will today), and still have things work. >> >> >>> We can keep it O(Nlog(N)) by taking advantage of not just the equality >>> but the ordering relationship. Although Ugh. >> >> Yes, that sounds pretty ugly... > > Actually having thought about this a little more if kcmp returns an > ordering by inode and migration preserves the relative order of > the inodes (which should just be a creation order) it should be quite > solvable. > > Switch from an order by inode number to an order by object creation > time, and guarantee that all creations are have an order (which with > task_list_lock we practically already have) and it should be even easier > to create. (A 64bit nanosecond resolution timestamp is good for 544 > years of uptime). A 64bit number that increments each time an object is > created should have an even better lifespan. > > I don't know if we can find a way to give that guarantee for other kcmp > comparisons but it is worth a thought. Okay. So, this is a pathway to O(Nlog(N)) at least then? >>> One disadvantage of >>> kcmp currently is that the way the ordering relationship is defined >>> the order is not preserved over migration :( >> >> So, does kcmp() fully solve the proble(s) at hand? It sounds like >> not, if I understand your last point correctly. > > There are 3 possibilities I see for migration in migration, ordered > in order of implementation difficulty. > 1) Have a clear signal that migration happened and a nested migration > needs to restart. > 2) Use kcmp so that only the relative order needs to be preserved. > 3) Preserve the device number and inode numbers. > > At a practical level I think (2) may actually in net be the simplest. > It requires a little more care to implement and you have to opt in, > but it should not require any rolling back of activity (merely careful > ordering of object creation). > > I definititely like kcmp knowing how to compare things by inode > (aka st_dev, st_inode) because then even if you have to restart > the comparisons after a migration the exact details you are comparing > are hidden and so it is easier to support and harder to get wrong. > > I can imagine how to preserve inode numbers by creating a new instance > of nsfs instance and using the old inode numbers upon restore. I don't > currently see how we could possibly preserve st_dev over migration short of > a device number namespace. > > So if we are going to continue with making device numbers be a legacy > attribute applications should not care about we need a way to compare > things by not looking at st_dev. Which brings us back to kcmp. > > Hmm. Hotplugging as disk and plugging it back likely will change the > device number and give the same kind of challenge with st_dev (although > you can't keep a file descriptor open across that kind of event). So > certainly a hotplug event on a device should be enough to say don't care > about the device number. Okay. Thanks, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web