mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Davide Libenzi <davidel@xmailserver.org>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Ulrich Drepper <drepper@gmail.com>, Ingo Molnar <mingo@elte.hu>
Subject: [patch 6/6] sys_indirect RFC - example usage from kernel POV
Date: Fri, 29 Jun 2007 14:48:52 -0700	[thread overview]
Message-ID: <send-serie.davidel@xmailserver.org.28360.1183153739.6> (raw)

This is an example of how to add a context set/unset wrapper inside
the kernel, for something like open flags:

1) Alloc a new SYSIND_CTX_* sequential index inside linux/indirect.h

2) Define a new "struct sysind_ctx_*" to be used by userspace

3) Define proper set/unset functions inside kernel/sys_indirect.c



Signed-off-by: Davide Libenzi <davidel@xmailserver.org>


- Davide



---
 include/linux/indirect.h |    7 +++++++
 kernel/sys_indirect.c    |   32 +++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

Index: linux-2.6.mod/include/linux/indirect.h
===================================================================
--- linux-2.6.mod.orig/include/linux/indirect.h	2007-06-29 12:58:11.000000000 -0700
+++ linux-2.6.mod/include/linux/indirect.h	2007-06-29 12:58:11.000000000 -0700
@@ -8,10 +8,17 @@
 #ifndef _LINUX_INDIRECT_H
 #define _LINUX_INDIRECT_H
 
+#define SYSIND_CTX_OPENFLAGS	0
+
 struct indirect_ctx {
 	__u32 ctx;
 };
 
+struct sysind_ctx_OPENFLAGS {
+	__u32 ctx;
+	__u32 flags;
+};
+
 #ifdef __KERNEL__
 
 #include <linux/fsalloc.h>
Index: linux-2.6.mod/kernel/sys_indirect.c
===================================================================
--- linux-2.6.mod.orig/kernel/sys_indirect.c	2007-06-29 12:58:11.000000000 -0700
+++ linux-2.6.mod/kernel/sys_indirect.c	2007-06-29 12:58:11.000000000 -0700
@@ -24,9 +24,39 @@
 	void (*unset)(struct indirect_op *);
 };
 
+struct indirect_op_OPENFLAGS {
+	struct indirect_op op;
+	unsigned long flags;
+};
+
+static int set_OPENFLAGS(struct fsa_context *ator,
+			 const struct indirect_ctx __user *uctx,
+			 struct indirect_op **pnew)
+{
+	struct indirect_op_OPENFLAGS *iop;
+	struct sysind_ctx_OPENFLAGS kctx;
+
+	if (copy_from_user(&kctx, uctx, sizeof(*uctx)))
+		return -EFAULT;
+	iop = fsa_alloc(ator, sizeof(struct indirect_op_OPENFLAGS));
+	if (unlikely(!iop))
+		return -ENOMEM;
+	iop->op.ctx = kctx.ctx;
+	/* iop->flags = current->def_open_flags; */
+	/* current->def_open_flags = kctx.flags; */
+	*pnew = (struct indirect_op *) iop;
+
+	return 0;
+}
+
+static void unset_OPENFLAGS(struct indirect_op *iop)
+{
+	/* current->def_open_flags = ((struct indirect_op_OPENFLAGS *) iop)->flags; */
+}
+
 static const struct indirect_procs inprocs[] =
 {
-	{ NULL, NULL },
+	[SYSIND_CTX_OPENFLAGS] =	{ set_OPENFLAGS, unset_OPENFLAGS },
 };
 
 /**


                 reply	other threads:[~2007-06-29 21:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=send-serie.davidel@xmailserver.org.28360.1183153739.6 \
    --to=davidel@xmailserver.org \
    --cc=akpm@linux-foundation.org \
    --cc=drepper@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®