9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Namespace inheritance between processes
@ 2016-05-21  7:26 Casey Rodarmor
  2016-05-21  7:37 ` Casey Rodarmor
  0 siblings, 1 reply; 8+ messages in thread
From: Casey Rodarmor @ 2016-05-21  7:26 UTC (permalink / raw)
  To: 9fans

Hi 9 fans,

I'm trying to figure out how namespace inheritance between process groups works.

Let's say I have a process A which forks a child process B with the
RFNAMEG so it receives a copy of A's namespace.

If process A then makes a change to its namespace, will process B see
that change? Or does B receive a distinct copy that A then can't
change?

Thanks!

Best,
Casey



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Namespace inheritance between processes
  2016-05-21  7:26 [9fans] Namespace inheritance between processes Casey Rodarmor
@ 2016-05-21  7:37 ` Casey Rodarmor
  2016-05-21  8:49   ` Skip Tavakkolian
  2016-05-21 10:01   ` Anthony Martin
  0 siblings, 2 replies; 8+ messages in thread
From: Casey Rodarmor @ 2016-05-21  7:37 UTC (permalink / raw)
  To: 9fans

On Sat, May 21, 2016 at 12:26 AM, Casey Rodarmor <casey@rodarmor.com> wrote:
> Hi 9 fans,
>
> I'm trying to figure out how namespace inheritance between process groups works.
>
> Let's say I have a process A which forks a child process B with the
> RFNAMEG so it receives a copy of A's namespace.
>
> If process A then makes a change to its namespace, will process B see
> that change? Or does B receive a distinct copy that A then can't
> change?
>
> Thanks!
>
> Best,
> Casey

Also, whatever the answer is, how can I test this for myself? I was
struggling to come up with a combination of commands, short of writing
some C programs, which would let me have two interactive rc shells
that inherit from one another, since rc doesn't have job control and
new rio windows are in a new process group.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Namespace inheritance between processes
  2016-05-21  7:37 ` Casey Rodarmor
@ 2016-05-21  8:49   ` Skip Tavakkolian
  2016-05-21 10:01   ` Anthony Martin
  1 sibling, 0 replies; 8+ messages in thread
From: Skip Tavakkolian @ 2016-05-21  8:49 UTC (permalink / raw)
  To: 9fans

lets create a couple of shell scripts like this:

1) ns_shared:
	#! /bin/rc

	cat /n/tmp/foo
	ramfs -m /n/tmp	# start another ramfs in the child's namespace
	echo something > /n/tmp/foo
	cat /n/tmp/foo
	exit

2) ns_RFNAMEG
	#! /bin/rc

	rfork n
	cat /n/tmp/foo
	ramfs -m /n/tmp	# start another ramfs in the child's namespace
	echo anotherthing > /n/tmp/foo
	cat /n/tmp/foo
	exit

then in an interactive rc:

% ramfs -m /n/tmp
% echo 123 > /n/tmp/foo
% touch /n/tmp/bar
% ls -l /n/tmp
--rw-rw-r-- M 14458 fst fst 0 May 21 01:46 /n/tmp/bar
--rw-rw-r-- M 14458 fst fst 4 May 21 01:45 /n/tmp/foo
% ns_RFNAMEG
123
anotherthing
% ls -l /n/tmp
--rw-rw-r-- M 14458 fst fst 0 May 21 01:46 /n/tmp/bar
--rw-rw-r-- M 14458 fst fst 4 May 21 01:45 /n/tmp/foo
% cat /n/tmp/foo
123
% ns_shared
123
something
% ls -l /n/tmp
--rw-rw-r-- M 14462 fst fst 10 May 21 01:46 /n/tmp/foo
% cat /n/tmp/foo
something
%

> On Sat, May 21, 2016 at 12:26 AM, Casey Rodarmor <casey@rodarmor.com> wrote:
>> Hi 9 fans,
>>
>> I'm trying to figure out how namespace inheritance between process groups works.
>>
>> Let's say I have a process A which forks a child process B with the
>> RFNAMEG so it receives a copy of A's namespace.
>>
>> If process A then makes a change to its namespace, will process B see
>> that change? Or does B receive a distinct copy that A then can't
>> change?
>>
>> Thanks!
>>
>> Best,
>> Casey
>
> Also, whatever the answer is, how can I test this for myself? I was
> struggling to come up with a combination of commands, short of writing
> some C programs, which would let me have two interactive rc shells
> that inherit from one another, since rc doesn't have job control and
> new rio windows are in a new process group.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Namespace inheritance between processes
  2016-05-21  7:37 ` Casey Rodarmor
  2016-05-21  8:49   ` Skip Tavakkolian
@ 2016-05-21 10:01   ` Anthony Martin
  2016-05-21 12:06     ` Anthony Martin
  1 sibling, 1 reply; 8+ messages in thread
From: Anthony Martin @ 2016-05-21 10:01 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Casey Rodarmor <casey@rodarmor.com> once said:
> > Let's say I have a process A which forks a child process B with the
> > RFNAMEG so it receives a copy of A's namespace.
> >
> > If process A then makes a change to its namespace, will process B see
> > that change? Or does B receive a distinct copy that A then can't
> > change?

The latter. B won't observe any namespace changes made by A.

> Also, whatever the answer is, how can I test this for myself? I was
> struggling to come up with a combination of commands, short of writing
> some C programs, which would let me have two interactive rc shells
> that inherit from one another, since rc doesn't have job control and
> new rio windows are in a new process group.

In one rio window, do the following:

  % mkdir -p /tmp/wsys
  % mount $wsys /tmp/wsys 'new -r 0 0 512 512 -pid '$pid
  % { rc -i <>/tmp/wsys/cons >[1=0] >[2=0] } &

Any further changes to the namespace will be reflected in both windows.

Cheers,
  Anthony



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Namespace inheritance between processes
  2016-05-21 10:01   ` Anthony Martin
@ 2016-05-21 12:06     ` Anthony Martin
  2016-05-22  3:01       ` Casey Rodarmor
  0 siblings, 1 reply; 8+ messages in thread
From: Anthony Martin @ 2016-05-21 12:06 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Anthony Martin <ality@pbrane.org> once said:
> Casey Rodarmor <casey@rodarmor.com> once said:
> > Also, whatever the answer is, how can I test this for myself? I was
> > struggling to come up with a combination of commands, short of writing
> > some C programs, which would let me have two interactive rc shells
> > that inherit from one another, since rc doesn't have job control and
> > new rio windows are in a new process group.
>
> In one rio window, do the following:
>
>   % mkdir -p /tmp/wsys
>   % mount $wsys /tmp/wsys 'new -r 0 0 512 512 -pid '$pid
>   % { rc -i <>/tmp/wsys/cons >[1=0] >[2=0] } &
>
> Any further changes to the namespace will be reflected in both windows.

I was playing around with this a bit more and I came
up with something a bit cleaner. The following command
will create an interactive shell in a new window that
shares the namespace of it's parent and acts like a
normal rio window (as much as possible).

Cheers,
  Anthony

#!/bin/rc

rfork e

mkdir -p /tmp/wsys
mount $wsys /tmp/wsys 'new -r 0 0 640 480 -pid -1'
{
	rc -i </tmp/wsys/cons >/tmp/wsys/cons >[2=1] &
	rcpid = $apid
	echo set -pid $rcpid >/tmp/wsys/wctl
	echo -n rc $rcpid >/tmp/wsys/label
	wait $rcpid
	echo delete >/tmp/wsys/wctl
} &



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Namespace inheritance between processes
  2016-05-21 12:06     ` Anthony Martin
@ 2016-05-22  3:01       ` Casey Rodarmor
  2016-05-22  5:28         ` Skip Tavakkolian
  0 siblings, 1 reply; 8+ messages in thread
From: Casey Rodarmor @ 2016-05-22  3:01 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Thanks Skip and Anthony for the scripts!

Okay, that makes sense. What is the reason for performing namespace
inheritance by copy as opposed to namespace inheritance by reference?
Is it just to simplify the implementation?

It seems like it might be useful. For example, if you had a daemon
that automatically reacted to devices, like USB drives and CDs being
attached and mounted them in the namespace, then you might want
processes to inherit from it so they would see new mounts.

Also, a totally random question: It seems like poor ergonomics that
one must create empty directories in order to serve as mount points.
Why not just allow mounting to names that don't exist yet?

On Sat, May 21, 2016 at 5:06 AM, Anthony Martin <ality@pbrane.org> wrote:
> Anthony Martin <ality@pbrane.org> once said:
>> Casey Rodarmor <casey@rodarmor.com> once said:
>> > Also, whatever the answer is, how can I test this for myself? I was
>> > struggling to come up with a combination of commands, short of writing
>> > some C programs, which would let me have two interactive rc shells
>> > that inherit from one another, since rc doesn't have job control and
>> > new rio windows are in a new process group.
>>
>> In one rio window, do the following:
>>
>>   % mkdir -p /tmp/wsys
>>   % mount $wsys /tmp/wsys 'new -r 0 0 512 512 -pid '$pid
>>   % { rc -i <>/tmp/wsys/cons >[1=0] >[2=0] } &
>>
>> Any further changes to the namespace will be reflected in both windows.
>
> I was playing around with this a bit more and I came
> up with something a bit cleaner. The following command
> will create an interactive shell in a new window that
> shares the namespace of it's parent and acts like a
> normal rio window (as much as possible).
>
> Cheers,
>   Anthony
>
> #!/bin/rc
>
> rfork e
>
> mkdir -p /tmp/wsys
> mount $wsys /tmp/wsys 'new -r 0 0 640 480 -pid -1'
> {
>         rc -i </tmp/wsys/cons >/tmp/wsys/cons >[2=1] &
>         rcpid = $apid
>         echo set -pid $rcpid >/tmp/wsys/wctl
>         echo -n rc $rcpid >/tmp/wsys/label
>         wait $rcpid
>         echo delete >/tmp/wsys/wctl
> } &
>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Namespace inheritance between processes
  2016-05-22  3:01       ` Casey Rodarmor
@ 2016-05-22  5:28         ` Skip Tavakkolian
  2016-05-22  6:14           ` erik quanstrom
  0 siblings, 1 reply; 8+ messages in thread
From: Skip Tavakkolian @ 2016-05-22  5:28 UTC (permalink / raw)
  To: 9fans

> What is the reason for performing namespace
> inheritance by copy as opposed to namespace inheritance by reference?
> Is it just to simplify the implementation?

i assume by reference you mean shared between parent and child.  most
of the time you don't want the child process to change the namespace
of the parent.

>
> It seems like it might be useful. For example, if you had a daemon
> that automatically reacted to devices, like USB drives and CDs being
> attached and mounted them in the namespace, then you might want
> processes to inherit from it so they would see new mounts.
>

for unrelated processes the way to import a namespace from a server is
for the server to post the client end of the 9P to /srv; any process needing the
service can mount the connection into its namespace.  that way access
permissions are also enforced.  see srv(3)

> Also, a totally random question: It seems like poor ergonomics that
> one must create empty directories in order to serve as mount points.
> Why not just allow mounting to names that don't exist yet?

mntgen(4)




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Namespace inheritance between processes
  2016-05-22  5:28         ` Skip Tavakkolian
@ 2016-05-22  6:14           ` erik quanstrom
  0 siblings, 0 replies; 8+ messages in thread
From: erik quanstrom @ 2016-05-22  6:14 UTC (permalink / raw)
  To: 9fans

> > Also, a totally random question: It seems like poor ergonomics that
> > one must create empty directories in order to serve as mount points.
> > Why not just allow mounting to names that don't exist yet?
>
> mntgen(4)

linux has the same restriction, and no mntgen.  :-)

- erik



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-05-22  6:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-21  7:26 [9fans] Namespace inheritance between processes Casey Rodarmor
2016-05-21  7:37 ` Casey Rodarmor
2016-05-21  8:49   ` Skip Tavakkolian
2016-05-21 10:01   ` Anthony Martin
2016-05-21 12:06     ` Anthony Martin
2016-05-22  3:01       ` Casey Rodarmor
2016-05-22  5:28         ` Skip Tavakkolian
2016-05-22  6:14           ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).