}
-+#if EXT3_INVARIANT
++#if EXT3_INVARIANT_ON
int ext3_check_dir_entry (const char * function, struct inode * dir,
struct ext3_dir_entry_2 * de,
struct buffer_head * bh,
/*
* linux/include/linux/lustre_iam.h
*/
-@@ -57,14 +54,64 @@ enum {
+@@ -57,14 +54,95 @@ enum {
* [2] reserved for leaf node operations.
*
* [3] reserved for index operations.
+ * Various debugging levels.
+ */
+
++#if 0
++/*
++ * Following macros are defined in config.h and are tunable through
++ * appropriate configure switches (indicated below).
++ */
++
+/*
+ * Compile basic assertions in. You want this most of the time.
++ *
++ * --{enable,disable}-ldiskfs-assert (on by default).
+ */
+#define EXT3_ASSERT (1)
+
+/*
+ * Compile heavier correctness checks in. You want this during development
+ * cycle.
++ *
++ * --{enable,disable}-ldiskfs-correctness (off by default).
+ */
+#define EXT3_CORRECTNESS (1)
+
+/*
+ * Compile heavy invariant checking in. You want this early during development
+ * or when chasing a bug.
++ *
++ * --{enable,disable}-ldiskfs-invariant (off by default).
+ */
+#define EXT3_INVARIANT (1)
++#endif
++
++#if defined(EXT3_ASSERT)
++#define EXT3_ASSERT_ON (1)
++#else
++#define EXT3_ASSERT_ON (0)
++#endif
++
++#if defined(EXT3_CORRECTNESS)
++#define EXT3_CORRECTNESS_ON (1)
++#else
++#define EXT3_CORRECTNESS_ON (0)
++#endif
++
++#if defined(EXT3_INVARIANT)
++#define EXT3_INVARIANT_ON (1)
++#else
++#define EXT3_INVARIANT_ON (0)
++#endif
+
+#ifndef assert
-+#if EXT3_ASSERT
++#if EXT3_ASSERT_ON
+#define assert(test) J_ASSERT(test)
+#else
+#define assert(test) ((void)(test))
+#endif
+#endif
+
-+#if EXT3_CORRECTNESS
++#if EXT3_CORRECTNESS_ON
+#define assert_corr(test) J_ASSERT(test)
+#else
+#define assert_corr(test) do {;} while (0)
+#endif
+
-+#if EXT3_INVARIANT
++#if EXT3_INVARIANT_ON
+#define assert_inv(test) J_ASSERT(test)
+#else
+#define assert_inv(test) do {;} while (0)
/*
* Entry within index tree node. Consists of a key immediately followed
* (without padding) by a pointer to the child node.
-@@ -86,14 +133,21 @@ struct iam_entry_compat {
+@@ -86,14 +164,21 @@ struct iam_entry_compat {
*/
struct iam_key;
typedef __u64 iam_ptr_t;
/*
-@@ -123,6 +177,31 @@ struct iam_leaf {
+@@ -123,6 +208,31 @@ struct iam_leaf {
void *il_descr_data;
};
struct iam_operations {
/*
* Returns pointer (in the same sense as pointer in index entry) to
-@@ -131,11 +210,15 @@ struct iam_operations {
+@@ -131,11 +241,15 @@ struct iam_operations {
__u32 (*id_root_ptr)(struct iam_container *c);
/*
* Initialize new node (stored in @bh) that is going to be added into
* tree.
*/
-@@ -144,23 +227,33 @@ struct iam_operations {
+@@ -144,23 +258,33 @@ struct iam_operations {
int (*id_node_read)(struct iam_container *c, iam_ptr_t ptr,
handle_t *h, struct buffer_head **bh);
/*
struct iam_leaf_operations {
/*
* leaf operations.
-@@ -186,7 +279,8 @@ struct iam_leaf_operations {
+@@ -186,7 +310,8 @@ struct iam_leaf_operations {
void (*start)(struct iam_leaf *l);
/* more leaf to the next entry. */
void (*next)(struct iam_leaf *l);
* either pointer to the key stored in node, or copy key into
* @k buffer supplied by caller and return pointer to this
* buffer. The latter approach is used when keys in nodes are
-@@ -194,8 +288,10 @@ struct iam_leaf_operations {
+@@ -194,8 +319,10 @@ struct iam_leaf_operations {
* all).
*
* Caller should assume that returned pointer is only valid
/* return pointer to entry body. Pointer is valid while
corresponding leaf node is locked and pinned. */
struct iam_rec *(*rec)(const struct iam_leaf *l);
-@@ -203,6 +299,9 @@ struct iam_leaf_operations {
+@@ -203,6 +330,9 @@ struct iam_leaf_operations {
void (*key_set)(struct iam_leaf *l, const struct iam_key *k);
void (*rec_set)(struct iam_leaf *l, const struct iam_rec *r);
/*
* Search leaf @l for a record with key @k or for a place
* where such record is to be inserted.
-@@ -210,6 +309,7 @@ struct iam_leaf_operations {
+@@ -210,6 +340,7 @@ struct iam_leaf_operations {
* Scratch keys from @path can be used.
*/
int (*lookup)(struct iam_leaf *l, const struct iam_key *k);
int (*can_add)(const struct iam_leaf *l,
const struct iam_key *k, const struct iam_rec *r);
-@@ -221,12 +321,13 @@ struct iam_leaf_operations {
+@@ -221,12 +352,13 @@ struct iam_leaf_operations {
/*
* remove rec for a leaf
*/
};
struct iam_path *iam_leaf_path(const struct iam_leaf *leaf);
-@@ -241,6 +342,10 @@ struct iam_descr {
+@@ -241,6 +373,10 @@ struct iam_descr {
*/
size_t id_key_size;
/*
* Size of a pointer to the next level (stored in index nodes), in
* bytes.
*/
-@@ -264,6 +369,9 @@ struct iam_descr {
+@@ -264,6 +400,9 @@ struct iam_descr {
struct iam_leaf_operations *id_leaf_ops;
};
struct iam_container {
/*
* Underlying flat file. IO against this object is issued to
-@@ -284,7 +392,7 @@ struct iam_path_descr {
+@@ -284,7 +423,7 @@ struct iam_path_descr {
/*
* Scratch-pad area for temporary keys.
*/
};
/*
-@@ -316,6 +424,7 @@ struct iam_path {
+@@ -316,6 +455,7 @@ struct iam_path {
* Key searched for.
*/
const struct iam_key *ip_key_target;
/*
* Description-specific data.
*/
-@@ -334,6 +443,7 @@ struct iam_path_compat {
+@@ -334,6 +474,7 @@ struct iam_path_compat {
struct dx_hash_info *ipc_hinfo;
struct dentry *ipc_dentry;
struct iam_path_descr ipc_descr;
};
/*
-@@ -347,7 +457,9 @@ enum iam_it_state {
+@@ -347,7 +488,9 @@ enum iam_it_state {
/* initial state */
IAM_IT_DETACHED,
/* iterator is above particular record in the container */
};
/*
-@@ -355,7 +467,7 @@ enum iam_it_state {
+@@ -355,7 +498,7 @@ enum iam_it_state {
*/
enum iam_it_flags {
/*
*/
IAM_IT_MOVE = (1 << 0),
/*
-@@ -372,15 +484,26 @@ enum iam_it_flags {
+@@ -372,15 +515,26 @@ enum iam_it_flags {
* doesn't point to any particular record in this container.
*
* After successful call to iam_it_get() and until corresponding call to
*
*/
struct iam_iterator {
-@@ -390,7 +513,8 @@ struct iam_iterator {
+@@ -390,7 +544,8 @@ struct iam_iterator {
__u32 ii_flags;
enum iam_it_state ii_state;
/*
*/
struct iam_path ii_path;
};
-@@ -405,133 +529,26 @@ void iam_path_compat_fini(struct iam_pat
+@@ -405,133 +560,26 @@ void iam_path_compat_fini(struct iam_pat
struct iam_path_descr *iam_ipd_alloc(int keysize);
void iam_ipd_free(struct iam_path_descr *ipd);
int iam_it_load(struct iam_iterator *it, iam_pos_t pos);
int iam_lookup(struct iam_container *c, const struct iam_key *k,
-@@ -539,10 +556,10 @@ int iam_lookup(struct iam_container *c,
+@@ -539,10 +587,10 @@ int iam_lookup(struct iam_container *c,
int iam_delete(handle_t *h, struct iam_container *c, const struct iam_key *k,
struct iam_path_descr *pd);
int iam_update(handle_t *h, struct iam_container *c, const struct iam_key *k,
/*
* Initialize container @c.
*/
-@@ -558,10 +575,6 @@ void iam_container_fini(struct iam_conta
+@@ -558,10 +606,6 @@ void iam_container_fini(struct iam_conta
*/
int iam_container_setup(struct iam_container *c);
static inline struct iam_descr *iam_container_descr(struct iam_container *c)
{
return c->ic_descr;
-@@ -577,16 +590,65 @@ static inline struct inode *iam_path_obj
+@@ -577,16 +621,65 @@ static inline struct inode *iam_path_obj
return p->ip_container->ic_object;
}
- struct iam_key *k1, const struct iam_key *k2)
+static inline void iam_ikeycpy(const struct iam_container *c,
+ struct iam_ikey *k1, const struct iam_ikey *k2)
-+{
+ {
+- memcpy(k1, k2, c->ic_descr->id_key_size);
+ memcpy(k1, k2, c->ic_descr->id_ikey_size);
-+}
-+
+ }
+
+-static inline int iam_keycmp(const struct iam_container *c,
+- const struct iam_key *k1, const struct iam_key *k2)
+static inline size_t iam_entry_size(struct iam_path *p)
-+{
+ {
+- return c->ic_descr->id_ops->id_keycmp(c, k1, k2);
+ return iam_path_descr(p)->id_ikey_size + iam_path_descr(p)->id_ptr_size;
+}
+
+static inline struct iam_ikey *iam_get_ikey(struct iam_path *p,
+ struct iam_entry *entry,
+ struct iam_ikey *key)
- {
-- memcpy(k1, k2, c->ic_descr->id_key_size);
++{
+ return memcpy(key, entry, iam_path_descr(p)->id_ikey_size);
- }
-
--static inline int iam_keycmp(const struct iam_container *c,
-- const struct iam_key *k1, const struct iam_key *k2)
++}
++
+static inline struct iam_ikey *iam_ikey_at(struct iam_path *p,
+ struct iam_entry *entry)
- {
-- return c->ic_descr->id_ops->id_keycmp(c, k1, k2);
++{
+ return (struct iam_ikey *)entry;
+}
+
}
static inline void iam_reccpy(const struct iam_path *p, struct iam_rec *rec_dst,
-@@ -604,7 +666,7 @@ static inline void *iam_entry_off(struct
+@@ -604,7 +697,7 @@ static inline void *iam_entry_off(struct
static inline unsigned dx_get_block(struct iam_path *p, struct iam_entry *entry)
{
return le32_to_cpu(*(u32*)iam_entry_off(entry,
& 0x00ffffff;
}
-@@ -612,21 +674,64 @@ static inline void dx_set_block(struct i
+@@ -612,21 +705,64 @@ static inline void dx_set_block(struct i
struct iam_entry *entry, unsigned value)
{
*(u32*)iam_entry_off(entry,
static inline unsigned dx_get_count(struct iam_entry *entries)
{
return le16_to_cpu(((struct dx_countlimit *) entries)->count);
-@@ -647,9 +752,21 @@ static inline unsigned dx_node_limit(str
+@@ -647,9 +783,21 @@ static inline unsigned dx_node_limit(str
struct iam_descr *param = iam_path_descr(p);
unsigned entry_space = iam_path_obj(p)->i_sb->s_blocksize -
param->id_node_gap;
static inline struct iam_entry *dx_get_entries(struct iam_path *path,
void *data, int root)
{
-@@ -665,7 +782,8 @@ static inline struct iam_entry *dx_node_
+@@ -665,7 +813,8 @@ static inline struct iam_entry *dx_node_
frame->bh->b_data, frame == path->ip_frames);
}
{
assert(0 <= nr && nr < ARRAY_SIZE(path->ip_data->ipd_key_scratch));
return path->ip_data->ipd_key_scratch[nr];
-@@ -674,6 +792,7 @@ static inline struct iam_key *iam_path_k
+@@ -674,6 +823,7 @@ static inline struct iam_key *iam_path_k
int dx_lookup(struct iam_path *path);
void dx_insert_block(struct iam_path *path, struct iam_frame *frame,
u32 hash, u32 block);
int ext3_htree_next_block(struct inode *dir, __u32 hash,
struct iam_path *path, __u32 *start_hash);
-@@ -681,6 +800,20 @@ int ext3_htree_next_block(struct inode *
+@@ -681,6 +831,20 @@ int ext3_htree_next_block(struct inode *
struct buffer_head *ext3_append(handle_t *handle, struct inode *inode,
u32 *block, int *err);
int split_index_node(handle_t *handle, struct iam_path *path);
/*
* external
-@@ -698,10 +831,12 @@ int iam_node_read(struct iam_container *
+@@ -698,10 +862,12 @@ int iam_node_read(struct iam_container *
handle_t *handle, struct buffer_head **bh);
void iam_insert_key(struct iam_path *path, struct iam_frame *frame,
struct iam_path *iam_leaf_path(const struct iam_leaf *leaf);
struct iam_container *iam_leaf_container(const struct iam_leaf *leaf);
-@@ -709,14 +844,95 @@ struct iam_descr *iam_leaf_descr(const s
+@@ -709,14 +875,95 @@ struct iam_descr *iam_leaf_descr(const s
struct iam_leaf_operations *iam_leaf_ops(const struct iam_leaf *leaf);
+ unsigned long arg);
+
+/* dir.c */
-+#if EXT3_INVARIANT
++#if EXT3_INVARIANT_ON
+extern int ext3_check_dir_entry(const char *, struct inode *,
+ struct ext3_dir_entry_2 *,
+ struct buffer_head *, unsigned long);