Re: Accessing filesystem from a KLD

2005-07-02 Thread Seb
Andrey Simonenko wrote :
 You got page fault from namei(), which is called from vn_open() to lookup
 a path name.  namei() tries to obtain a reference on current directory for
 the current thread.  This current directory (fd_cdir field) is NULL in
 your kthread.  At this point a page fault in kernel address space is
 generated.

You were right :) It works now.

 Can you change fd_cdir in kthread to rootvnode I don't know, haven't
 checked this yet.  

It works - and that's what NDISulator does. You also need to set fd_rdir.

Thanks !

Mike Silbersack wrote :
 Ask [EMAIL PROTECTED] for his code that does exactly what you're 
 asking for. :)

I've looked at Damien's source, but AFAIK in his driver, the firmware is 
loaded from userspace through an ioctl call on the network interface.

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Accessing filesystem from a KLD

2005-06-29 Thread Seb
 There's also a desire to provide an easier to use interface for
 drivers to load, for example, firmware.

Is there an existing development ?
I think I'll separate retreiving firmware from the filesystem in another KLD, 
so maybe I should contact the developers...

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Accessing filesystem from a KLD

2005-06-29 Thread Seb
 Why not to use VOP_READ?  See how it is called in dev/md.c:mdstart_vnode,
 check kern/vfs_vnops.c:vn_open_cred for information how to lookup a file
 name and open it.

That's what I do, however I use the wrapper functions vn_open(), vn_rdwr() and 
so.

But I have a problem, when I call this code :

void *request_firmware(const char *name, size_t *size)
{
int flags;
char filename[40];
struct nameidata nd;
struct thread *td = curthread;
[...]
NDINIT(nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename[0], td);
flags = FREAD;
vn_open(nd, flags, 0, -1);
[...]
}

from the KLD handler function (for testing) it works. But when I call it from 
a thread created by kthread_create() in another KLD, I have a page fault.
A few printfs show that the call to vn_open() is responsible for the fault.
I have not forgotten to lock Giant in my kernel thread.
Any ideas ?
Thanks,
Sebastien

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Accessing filesystem from a KLD

2005-06-29 Thread Andrey Simonenko
On Wed, Jun 29, 2005 at 11:55:50AM +0200, Seb wrote:
  Why not to use VOP_READ?  See how it is called in dev/md.c:mdstart_vnode,
  check kern/vfs_vnops.c:vn_open_cred for information how to lookup a file
  name and open it.
 
 That's what I do, however I use the wrapper functions vn_open(), vn_rdwr() 
 and 
 so.
 
 But I have a problem, when I call this code :
 
 void *request_firmware(const char *name, size_t *size)
 {
 int flags;
 char filename[40];
 struct nameidata nd;
 struct thread *td = curthread;
 [...]
 NDINIT(nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename[0], td);
 flags = FREAD;
 vn_open(nd, flags, 0, -1);
 [...]
 }
 
 from the KLD handler function (for testing) it works. But when I call it from 
 a thread created by kthread_create() in another KLD, I have a page fault.
 A few printfs show that the call to vn_open() is responsible for the fault.
 I have not forgotten to lock Giant in my kernel thread.
 Any ideas ?

You got page fault from namei(), which is called from vn_open() to lookup
a path name.  namei() tries to obtain a reference on current directory for
the current thread.  This current directory (fd_cdir field) is NULL in
your kthread.  At this point a page fault in kernel address space is
generated.

More detail:  Check in kthread_create() how new kthread is created,
check flag RFFDG in fork1().  Since new kthread is created from thread0
and RFFDG is on, then new kthread will copy descriptor table from proc0.
proc0 has descriptor table created by fdinit() in proc0_init().  fdinit()
sets fd_cdir (current directory) to 0 (the same as NULL in /sys).

Can you change fd_cdir in kthread to rootvnode I don't know, haven't
checked this yet.  But you can open a file in syscall and then use
obtained vp in your kthread for VOP_READ call.

It would be better to see backtrace of above mentioned page fault.
But I guess that everything happened as I described.

Hope this can help.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Accessing filesystem from a KLD

2005-06-25 Thread Seb
Hello,
How can I access the filesystem from a kernel module ?
In fact, I want my device driver to retreive a firmware image stored on the 
filesystem (instead of putting the firmware data in a static array at 
compile-time) for memory usage and legal concerns. Blocking calls are OK.
I have searched the manpages and the web, but I haven't found anything 
relevant.
Thanks,
Sebastien

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Accessing filesystem from a KLD

2005-06-25 Thread Suleiman Souhlal

Hi,

On Jun 25, 2005, at 6:03 AM, Seb wrote:


Hello,
How can I access the filesystem from a kernel module ?
In fact, I want my device driver to retreive a firmware image  
stored on the

filesystem (instead of putting the firmware data in a static array at
compile-time) for memory usage and legal concerns. Blocking calls  
are OK.

I have searched the manpages and the web, but I haven't found anything
relevant.
Thanks,
Sebastien


You can use vn_open() to open the file, and then read it using vn_rdwr 
(), and finally, vn_close() to close it. Look at src/sys/kern/ 
link_elf_obj.c for an example.


--
Suleiman Souhlal | [EMAIL PROTECTED]
The FreeBSD Project  | [EMAIL PROTECTED]

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Accessing filesystem from a KLD

2005-06-25 Thread M. Warner Losh
In message: [EMAIL PROTECTED]
Suleiman Souhlal [EMAIL PROTECTED] writes:
: You can use vn_open() to open the file, and then read it using vn_rdwr 
: (), and finally, vn_close() to close it. Look at src/sys/kern/ 
: link_elf_obj.c for an example.

There's also a desire to provide an easier to use interface for
drivers to load, for example, firmware.

Warner
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]