kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: fs.rajat@gmail.com (Rajat Sharma)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Kernel-space flirting with user-space
Date: Thu, 10 Jan 2013 19:05:03 -0800	[thread overview]
Message-ID: <-8792976353014721723@unknownmsgid> (raw)

If you do not have much dependency to be in kernel mode, you can implement,
or atleast initially, a user mode filesystem using fuse.
------------------------------
From: Simon
Sent: 11-01-2013 02:45
To: kernelnewbies at kernelnewbies.org
Subject: Kernel-space flirting with user-space

Hi there,

  I'm rather new to kernel development, but I am somewhat experienced with
Linux, kernel compilation, etc.  I'm just passed writing a helloworld
module, dummy filesystem (ramfs wrapper) and proc entry.  I would like to
know how communication between kernel & user-space is done (the standard)
for a high number of tiny and large messages going in both directions
(large messages would need to be transfered incrementally, in chunks, can
be sequential or random access).  I plan on developping a network
filesystem.  I would appreciate if someone could clarify where I'm wrong
and confirm where I'm right, and ideally suggest some vocabulary, source
files to lookup, online docs or even books.  The minimum you can give will
be most appreciated!  =)

  Firstly, I was wondering if it would be possible to implement the
filesystem entirely as a kernel module.  I would need TCP/UDP sockets.  I
think this is really not the recommended approach, but an advantage I see
is it could be used to mount the root filesystem before calling init (that
would be before user-space exists, right?).  On the other hand, separating
the work to have a program/daemon in user-space do the communication and
processing would allow me to write that part in C++ (which I personally
prefer).

  Secondly, I wonder how I can "bind" a user-space program/daemon with the
kernel-space of the module.

  Using procfs:  It seems technically possible to achieve my goal with it,
but I feel this would not be the standard approach.  I would rather keep it
for live config & live status reporting.
  Using sysfs:  I've read too much misleading information that I'm not sure
anymore what it's for or even if it's still used or deprecated!  Can
someone clarify?  It looks technically identical to procfs, but it's
mission is a different one, correct?
  Using pipes:  This may be a good way, but again, I'm not sure if it's the
standard way.
  Using IPC:  As far as I understand, IPC would be the way if we'd be
talking of two threads within the same process, or at least within
kernel-space.  Though I am likely to be wrong.
  Using a char device:  It seems technically possible as well, but it may
be difficult to deal with if I ever have more than one user-space process.
  Using a block device:  My file system works with files and their
metadata, but not with blocks, so this is not suitable.  Though it might be
a nice experiment to build a network block device containing an ext2
filesystem (which I think would be similar to iSCSI).
  Using net interface: Not applicable.  And an experiment to try to make it
applicable doesn't even seem remotely fun.  ;)

  I've seen the functions copy_to/from_user() or something like that, but I
haven't seen the user-space counter-part of these.  I think this may
actually be the best approach by far, but I really lack info/docs to go
that way.  The truly best way might be to use shared memory to avoid
copying data internally, but I haven't looked into that much yet.

  Finally, is it possible/correct/standard to do something similar to the
following for the local kernel & user-space communication?  (I haven't
reviewed the syntax, so take it as some kind of pseudo-code!)

struct foo {...} outgoingFoo;
// foo contains no pointers, so it is of a fixed size always.
fwrite(&outgoingFoo, 1, sizeof(outgoingFoo), output);
  [...then on the other end...]
if(sizeof(fread( buffer, 1, buffer_size, input);
struct foo * incomingFoo = (struct foo *) buffer;

Regards,
  Simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130110/44cd14aa/attachment-0001.html 

             reply	other threads:[~2013-01-11  3:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-11  3:05 Rajat Sharma [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-01-10 21:09 Kernel-space flirting with user-space Simon
2013-01-10 21:31 ` devendra.aaru
2013-01-16 17:22   ` Simon
2013-01-11  3:05 ` Henrique Rodrigues
2013-01-16 17:28   ` Simon
2013-01-11 15:32 ` Kristof Provost
2013-01-16 18:04   ` Simon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=-8792976353014721723@unknownmsgid \
    --to=fs.rajat@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).