mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>, Jan Kara <jack@suse.cz>
Subject: [PATCH 1/2] Implement trivial struct feature macros
Date: Thu, 30 Apr 2009 19:31:17 +0200	[thread overview]
Message-ID: <1241112678-6615-2-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1241112678-6615-1-git-send-email-jack@suse.cz>

Sometimes it is useful to have a generic main structure (like struct inode)
and then with some of these structures you want to associate additional
information (like quota information, block device information etc.).
Traditionally, we solved this by having a pointer to associated data in
the generic structure. This gets inefficient when there are lots of
various kinds of data that can be associated with the generic structure
(we need one pointer per type of associated information). This is an
attempt to address the issue.

The idea is simple. There is some chunk of allocated memory that contains
the generic structure and all the associated information. The generic
structure has a pointer to the (usually static) table of offsets (from
the beginning of the generic structure) of associated structures for
each possible associated structure type.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 include/linux/fs.h             |    5 +++++
 include/linux/struct_feature.h |   12 ++++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/struct_feature.h

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 5bed436..2404b16 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -710,6 +710,10 @@ static inline int mapping_writably_mapped(struct address_space *mapping)
 #define i_size_ordered_init(inode) do { } while (0)
 #endif
 
+enum {
+	INODE_FEATURES
+};
+
 struct inode {
 	struct hlist_node	i_hash;
 	struct list_head	i_list;
@@ -775,6 +779,7 @@ struct inode {
 	void			*i_security;
 #endif
 	void			*i_private; /* fs or device private pointer */
+	int			*feature_table;
 };
 
 /*
diff --git a/include/linux/struct_feature.h b/include/linux/struct_feature.h
new file mode 100644
index 0000000..0849d3d
--- /dev/null
+++ b/include/linux/struct_feature.h
@@ -0,0 +1,12 @@
+#ifndef _LINUX_STRUCT_FEATURE_H
+#define _LINUX_STRUCT_FEATURE_H
+
+
+#define FEATURE_OFFSET(str, generic, feature) (offsetof(str, feature) - offsetof(str, generic))
+
+#define GET_FEATURE(generic, feature) \
+	((generic)->feature_table && (generic)->feature_table[feature] ? \
+	((void *)(((char *)(generic)) + (generic)->feature_table[feature])) : \
+	NULL)
+
+#endif
-- 
1.6.0.2


  reply	other threads:[~2009-04-30 17:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-30 17:31 [RFC PATCH 0/2] A new way of attaching information to inodes Jan Kara
2009-04-30 17:31 ` Jan Kara [this message]
2009-05-01  9:14   ` [PATCH 1/2] Implement trivial struct feature macros Christoph Hellwig
2009-04-30 17:31 ` [PATCH 2/2] Use feature code to eliminate quota pointers from inodes for filesystems that don't need it Jan Kara
2009-05-02  3:23   ` Ryusuke Konishi
2009-04-30 19:43 ` [RFC PATCH 0/2] A new way of attaching information to inodes Theodore Tso
2009-05-01  9:08   ` Christoph Hellwig

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=1241112678-6615-2-git-send-email-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.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®