9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Two ramfs?
@ 2008-02-04 16:02 Lluís Batlle
  2008-02-04 20:34 ` Russ Cox
  0 siblings, 1 reply; 6+ messages in thread
From: Lluís Batlle @ 2008-02-04 16:02 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

I'd like to write a small simple fileserver, and I've been advised
everywhere to look at ramfs.c.

I saw the src/cmd/ramfs.c, and I think I should be able to write mine
simpler... For example, I'd like to take advantage of the File/Tree
interface (createfile(), ...), having all the files of the fs in
memory.

I found also src/lib9p/ramfs.c, which looks pretty much as what I
want, but this doesn't tollerate remounting well at all (I guess).

I tried it with some modifications (to get it compiled) in plan9port
over linux (./ramfs -D -s test)  and two "9p ls test" in a row makes
the server die.

Where can I see an example of a working fileserver which uses File,
Tree, and the related functions?

Thank you,
Lluís.

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

* Re: [9fans] Two ramfs?
  2008-02-04 16:02 [9fans] Two ramfs? Lluís Batlle
@ 2008-02-04 20:34 ` Russ Cox
  2008-02-04 21:38   ` Lluís Batlle
  2008-02-06 22:22   ` Lluís Batlle
  0 siblings, 2 replies; 6+ messages in thread
From: Russ Cox @ 2008-02-04 20:34 UTC (permalink / raw)
  To: 9fans

> I saw the src/cmd/ramfs.c, and I think I should be able to write mine
> simpler... For example, I'd like to take advantage of the File/Tree
> interface (createfile(), ...), having all the files of the fs in
> memory.
>
> I found also src/lib9p/ramfs.c, which looks pretty much as what I
> want, but this doesn't tollerate remounting well at all (I guess).
>
> I tried it with some modifications (to get it compiled) in plan9port
> over linux (./ramfs -D -s test)  and two "9p ls test" in a row makes
> the server die.
>
> Where can I see an example of a working fileserver which uses File,
> Tree, and the related functions?

It's been a long time since I looked at that code, but it appears
that the problem is that Tattach doesn't increment the reference
count on its directory.  Reattaching isn't very common in Plan 9
(but is on p9p) so it's easy to believe this bug went unnoticed.

Here is the fix, now in p9p:

diff -r bcad073690c5 src/lib9p/srv.c
--- a/src/lib9p/srv.c	Fri Feb 01 07:54:19 2008 -0500
+++ b/src/lib9p/srv.c	Mon Feb 04 15:32:28 2008 -0500
@@ -227,7 +227,7 @@ sattach(Srv *srv, Req *r)
 	r->fid->uid = estrdup9p(r->ifcall.uname);
 	if(srv->tree){
 		r->fid->file = srv->tree->root;
-		/* BUG? incref(r->fid->file) ??? */
+		incref(&r->fid->file->ref);
 		r->ofcall.qid = r->fid->file->dir.qid;
 		r->fid->qid = r->ofcall.qid;
 	}

Russ


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

* Re: [9fans] Two ramfs?
  2008-02-04 20:34 ` Russ Cox
@ 2008-02-04 21:38   ` Lluís Batlle
  2008-02-06 22:22   ` Lluís Batlle
  1 sibling, 0 replies; 6+ messages in thread
From: Lluís Batlle @ 2008-02-04 21:38 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Thank you. I'll try to play with File and Tree now.

btw, I had some problems on /tmp due to free space, getting messages
from ./INSTALL as these:
...
copy.o: No space left on device
/tmp/cc2IGQH6.s: Assembler messages:
/tmp/cc2IGQH6.s:3059: FATAL: Can't write copy.o: Invalid argument
mk: 9c  copy.c  : exit status=exit(1)
mk: for i in ...  : exit status=exit(1)
mk: for i in ...  : exit status=exit(1)
...

nevertheless, the INSTALL script returned errorlevel 0.

I don't think this bothers many people, but I wasn't watching the
command output, and I trusted the errorlevel.

Regards.

2008/2/4, Russ Cox <rsc@swtch.com>:
> > I saw the src/cmd/ramfs.c, and I think I should be able to write mine
> > simpler... For example, I'd like to take advantage of the File/Tree
> > interface (createfile(), ...), having all the files of the fs in
> > memory.
> >
> > I found also src/lib9p/ramfs.c, which looks pretty much as what I
> > want, but this doesn't tollerate remounting well at all (I guess).
> >
> > I tried it with some modifications (to get it compiled) in plan9port
> > over linux (./ramfs -D -s test)  and two "9p ls test" in a row makes
> > the server die.
> >
> > Where can I see an example of a working fileserver which uses File,
> > Tree, and the related functions?
>
> It's been a long time since I looked at that code, but it appears
> that the problem is that Tattach doesn't increment the reference
> count on its directory.  Reattaching isn't very common in Plan 9
> (but is on p9p) so it's easy to believe this bug went unnoticed.
>
> Here is the fix, now in p9p:
>
> diff -r bcad073690c5 src/lib9p/srv.c
> --- a/src/lib9p/srv.c   Fri Feb 01 07:54:19 2008 -0500
> +++ b/src/lib9p/srv.c   Mon Feb 04 15:32:28 2008 -0500
> @@ -227,7 +227,7 @@ sattach(Srv *srv, Req *r)
>         r->fid->uid = estrdup9p(r->ifcall.uname);
>         if(srv->tree){
>                 r->fid->file = srv->tree->root;
> -               /* BUG? incref(r->fid->file) ??? */
> +               incref(&r->fid->file->ref);
>                 r->ofcall.qid = r->fid->file->dir.qid;
>                 r->fid->qid = r->ofcall.qid;
>         }
>
> Russ
>
>


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

* Re: [9fans] Two ramfs?
  2008-02-04 20:34 ` Russ Cox
  2008-02-04 21:38   ` Lluís Batlle
@ 2008-02-06 22:22   ` Lluís Batlle
  2008-02-07  1:43     ` sqweek
  1 sibling, 1 reply; 6+ messages in thread
From: Lluís Batlle @ 2008-02-06 22:22 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello Russ,

before trying to code something from scrach using createfile & co., I
wanted to get ramfs working (that of lib9p/, the only example of
Tree/File I found in plan9port). After your fix related to a proper
unmount/remount, now I see that the 9pserve process exits hardly if I
try to create a file in the ramfs filesystem. It doesn't die because
of a signal. I tried gdb on it, breakpointing at exits/threadexits,
but I don't understand the makecontext() game of libthread. I put a
stderr trace in the fscreate() function of ramfs.c, and it doesn't
even appear. I guess fscreate() is not called.

Maybe that part of the lib9p api is generally broken/not-tested?

Thank you,
Lluís.

2008/2/4, Russ Cox <rsc@swtch.com>:
> > I saw the src/cmd/ramfs.c, and I think I should be able to write mine
> > simpler... For example, I'd like to take advantage of the File/Tree
> > interface (createfile(), ...), having all the files of the fs in
> > memory.
> >
> > I found also src/lib9p/ramfs.c, which looks pretty much as what I
> > want, but this doesn't tollerate remounting well at all (I guess).
> >
> > I tried it with some modifications (to get it compiled) in plan9port
> > over linux (./ramfs -D -s test)  and two "9p ls test" in a row makes
> > the server die.
> >
> > Where can I see an example of a working fileserver which uses File,
> > Tree, and the related functions?
>
> It's been a long time since I looked at that code, but it appears
> that the problem is that Tattach doesn't increment the reference
> count on its directory.  Reattaching isn't very common in Plan 9
> (but is on p9p) so it's easy to believe this bug went unnoticed.
>
> Here is the fix, now in p9p:
>
> diff -r bcad073690c5 src/lib9p/srv.c
> --- a/src/lib9p/srv.c   Fri Feb 01 07:54:19 2008 -0500
> +++ b/src/lib9p/srv.c   Mon Feb 04 15:32:28 2008 -0500
> @@ -227,7 +227,7 @@ sattach(Srv *srv, Req *r)
>         r->fid->uid = estrdup9p(r->ifcall.uname);
>         if(srv->tree){
>                 r->fid->file = srv->tree->root;
> -               /* BUG? incref(r->fid->file) ??? */
> +               incref(&r->fid->file->ref);
>                 r->ofcall.qid = r->fid->file->dir.qid;
>                 r->fid->qid = r->ofcall.qid;
>         }
>
> Russ
>
>

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

* Re: [9fans] Two ramfs?
  2008-02-06 22:22   ` Lluís Batlle
@ 2008-02-07  1:43     ` sqweek
  2008-02-07  8:41       ` Lluís Batlle
  0 siblings, 1 reply; 6+ messages in thread
From: sqweek @ 2008-02-07  1:43 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Feb 7, 2008 7:22 AM, Lluís Batlle <viriketo@gmail.com> wrote:
> Hello Russ,
>
> before trying to code something from scrach using createfile & co., I
> wanted to get ramfs working (that of lib9p/, the only example of
> Tree/File I found in plan9port). After your fix related to a proper
> unmount/remount, now I see that the 9pserve process exits hardly if I
> try to create a file in the ramfs filesystem. It doesn't die because
> of a signal. I tried gdb on it, breakpointing at exits/threadexits,
> but I don't understand the makecontext() game of libthread. I put a
> stderr trace in the fscreate() function of ramfs.c, and it doesn't
> even appear. I guess fscreate() is not called.

 libthread in p9p forks. By default, gdb follows the parent process,
which for libthread is not what you're interested in. Try:

(gdb) break fscreate
(gdb) set follow-fork-mode child
(gdb) run

 Oh wait, I see now you put a print in fscreate(). Well, maybe this is
a useful tip anyway :)
-sqweek

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

* Re: [9fans] Two ramfs?
  2008-02-07  1:43     ` sqweek
@ 2008-02-07  8:41       ` Lluís Batlle
  0 siblings, 0 replies; 6+ messages in thread
From: Lluís Batlle @ 2008-02-07  8:41 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I saw the ramfs forks and execs 9pserve, that's why I tried gdb on the
9pserve process, not in ramfs.
But I could not understand the makecontext() kind of context switching
of libpthread used in 9pserve.

I'd have used 'acid', but I understand that it still doesn't allow
breakpoints on Linux, and I don't know how to inspect many things with
it. I can barely type a lstk(). :)
I'd appreciate a "gdb to acid" mapping tutorial, for example.

I guess most of the power of acid comes from acid-programs, which many
people may have in their $home. :)

Thanks,
Lluís.

2008/2/7, sqweek <sqweek@gmail.com>:
> On Feb 7, 2008 7:22 AM, Lluís Batlle <viriketo@gmail.com> wrote:
> > Hello Russ,
> >
> > before trying to code something from scrach using createfile & co., I
> > wanted to get ramfs working (that of lib9p/, the only example of
> > Tree/File I found in plan9port). After your fix related to a proper
> > unmount/remount, now I see that the 9pserve process exits hardly if I
> > try to create a file in the ramfs filesystem. It doesn't die because
> > of a signal. I tried gdb on it, breakpointing at exits/threadexits,
> > but I don't understand the makecontext() game of libthread. I put a
> > stderr trace in the fscreate() function of ramfs.c, and it doesn't
> > even appear. I guess fscreate() is not called.
>
>  libthread in p9p forks. By default, gdb follows the parent process,
> which for libthread is not what you're interested in. Try:
>
> (gdb) break fscreate
> (gdb) set follow-fork-mode child
> (gdb) run
>
>  Oh wait, I see now you put a print in fscreate(). Well, maybe this is
> a useful tip anyway :)
> -sqweek
>

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

end of thread, other threads:[~2008-02-07  8:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-04 16:02 [9fans] Two ramfs? Lluís Batlle
2008-02-04 20:34 ` Russ Cox
2008-02-04 21:38   ` Lluís Batlle
2008-02-06 22:22   ` Lluís Batlle
2008-02-07  1:43     ` sqweek
2008-02-07  8:41       ` Lluís Batlle

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).