Commit 6b9f5829 authored by Al Viro's avatar Al Viro Committed by Linus Torvalds

[PATCH] reiserfs endianness: comp_short_keys() cleanup

comp_short_keys() massaged into sane form, which kills the last place where
pointer to in_core_key (or any object containing such) would be cast to or
from something else.  At that point we are free to change layout of
in_core_key - nothing depends on it anymore.

So we drop the mess with union in there and simply use (unconditional) __u64
k_offset and __u8 k_type instead; places using in_core_key switched to those.
That gives _far_ better code than current mess - on all platforms.
Signed-off-by: default avatarAl Viro <viro@parcelfarce.linux.theplanet.co.uk>
Cc: <reiserfs-dev@namesys.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent b8cc936f
...@@ -1341,8 +1341,8 @@ void reiserfs_read_locked_inode (struct inode * inode, struct reiserfs_iget_args ...@@ -1341,8 +1341,8 @@ void reiserfs_read_locked_inode (struct inode * inode, struct reiserfs_iget_args
key.version = KEY_FORMAT_3_5; key.version = KEY_FORMAT_3_5;
key.on_disk_key.k_dir_id = dirino; key.on_disk_key.k_dir_id = dirino;
key.on_disk_key.k_objectid = inode->i_ino; key.on_disk_key.k_objectid = inode->i_ino;
key.on_disk_key.u.k_offset_v1.k_offset = SD_OFFSET; key.on_disk_key.k_offset = 0;
key.on_disk_key.u.k_offset_v1.k_uniqueness = SD_UNIQUENESS; key.on_disk_key.k_type = 0;
/* look for the object's stat data */ /* look for the object's stat data */
retval = search_item (inode->i_sb, &key, &path_to_sd); retval = search_item (inode->i_sb, &key, &path_to_sd);
......
...@@ -87,23 +87,20 @@ inline void copy_item_head(struct item_head * p_v_to, ...@@ -87,23 +87,20 @@ inline void copy_item_head(struct item_head * p_v_to,
inline int comp_short_keys (const struct reiserfs_key * le_key, inline int comp_short_keys (const struct reiserfs_key * le_key,
const struct cpu_key * cpu_key) const struct cpu_key * cpu_key)
{ {
__le32 * p_s_le_u32; __u32 n;
__u32 * p_s_cpu_u32; n = le32_to_cpu(le_key->k_dir_id);
int n_key_length = REISERFS_SHORT_KEY_LEN; if (n < cpu_key->on_disk_key.k_dir_id)
p_s_le_u32 = (__le32 *)le_key;
p_s_cpu_u32 = (__u32 *)&cpu_key->on_disk_key;
for( ; n_key_length--; ++p_s_le_u32, ++p_s_cpu_u32 ) {
if ( le32_to_cpu (*p_s_le_u32) < *p_s_cpu_u32 )
return -1; return -1;
if ( le32_to_cpu (*p_s_le_u32) > *p_s_cpu_u32 ) if (n > cpu_key->on_disk_key.k_dir_id)
return 1;
n = le32_to_cpu(le_key->k_objectid);
if (n < cpu_key->on_disk_key.k_objectid)
return -1;
if (n > cpu_key->on_disk_key.k_objectid)
return 1; return 1;
}
return 0; return 0;
} }
/* k1 is pointer to on-disk structure which is stored in little-endian /* k1 is pointer to on-disk structure which is stored in little-endian
form. k2 is pointer to cpu variable. form. k2 is pointer to cpu variable.
Compare keys using all 4 key fields. Compare keys using all 4 key fields.
...@@ -153,18 +150,15 @@ inline int comp_short_le_keys (const struct reiserfs_key * key1, const struct re ...@@ -153,18 +150,15 @@ inline int comp_short_le_keys (const struct reiserfs_key * key1, const struct re
inline void le_key2cpu_key (struct cpu_key * to, const struct reiserfs_key * from) inline void le_key2cpu_key (struct cpu_key * to, const struct reiserfs_key * from)
{ {
int version;
to->on_disk_key.k_dir_id = le32_to_cpu (from->k_dir_id); to->on_disk_key.k_dir_id = le32_to_cpu (from->k_dir_id);
to->on_disk_key.k_objectid = le32_to_cpu (from->k_objectid); to->on_disk_key.k_objectid = le32_to_cpu (from->k_objectid);
// find out version of the key // find out version of the key
to->version = le_key_version (from); version = le_key_version (from);
if (to->version == KEY_FORMAT_3_5) { to->version = version;
to->on_disk_key.u.k_offset_v1.k_offset = le32_to_cpu (from->u.k_offset_v1.k_offset); to->on_disk_key.k_offset = le_key_k_offset(version, from);
to->on_disk_key.u.k_offset_v1.k_uniqueness = le32_to_cpu (from->u.k_offset_v1.k_uniqueness); to->on_disk_key.k_type = le_key_k_type(version, from);
} else {
to->on_disk_key.u.k_offset_v2.k_offset = offset_v2_k_offset(&from->u.k_offset_v2);
to->on_disk_key.u.k_offset_v2.k_type = offset_v2_k_type(&from->u.k_offset_v2);
}
} }
...@@ -235,8 +229,8 @@ const struct reiserfs_key MAX_KEY = { ...@@ -235,8 +229,8 @@ const struct reiserfs_key MAX_KEY = {
{{__constant_cpu_to_le32(0xffffffff), {{__constant_cpu_to_le32(0xffffffff),
__constant_cpu_to_le32(0xffffffff)},} __constant_cpu_to_le32(0xffffffff)},}
}; };
const struct in_core_key MAX_IN_CORE_KEY = {0xffffffff, 0xffffffff, {{0xffffffff, 0xffffffff},}};
const struct in_core_key MAX_IN_CORE_KEY = {~0U, ~0U, ~0ULL>>4, 15};
/* Get delimiting key of the buffer by looking for it in the buffers in the path, starting from the bottom /* Get delimiting key of the buffer by looking for it in the buffers in the path, starting from the bottom
of the path, and going upwards. We must check the path's validity at each step. If the key is not in of the path, and going upwards. We must check the path's validity at each step. If the key is not in
......
...@@ -218,8 +218,8 @@ static int finish_unfinished (struct super_block * s) ...@@ -218,8 +218,8 @@ static int finish_unfinished (struct super_block * s)
item = B_I_PITEM (bh, ih); item = B_I_PITEM (bh, ih);
obj_key.on_disk_key.k_dir_id = le32_to_cpu (*(__le32 *)item); obj_key.on_disk_key.k_dir_id = le32_to_cpu (*(__le32 *)item);
obj_key.on_disk_key.k_objectid = le32_to_cpu (ih->ih_key.k_objectid); obj_key.on_disk_key.k_objectid = le32_to_cpu (ih->ih_key.k_objectid);
obj_key.on_disk_key.u.k_offset_v1.k_offset = 0; obj_key.on_disk_key.k_offset = 0;
obj_key.on_disk_key.u.k_offset_v1.k_uniqueness = 0; obj_key.on_disk_key.k_type = 0;
pathrelse (&path); pathrelse (&path);
......
...@@ -433,23 +433,6 @@ static inline void set_offset_v2_k_offset( struct offset_v2 *v2, loff_t offset ) ...@@ -433,23 +433,6 @@ static inline void set_offset_v2_k_offset( struct offset_v2 *v2, loff_t offset )
# define set_offset_v2_k_offset(v2,val) (offset_v2_k_offset(v2) = (val)) # define set_offset_v2_k_offset(v2,val) (offset_v2_k_offset(v2) = (val))
#endif #endif
struct in_core_offset_v1 {
__u32 k_offset;
__u32 k_uniqueness;
} __attribute__ ((__packed__));
struct in_core_offset_v2 {
#ifdef __LITTLE_ENDIAN
/* little endian version */
__u64 k_offset:60;
__u64 k_type: 4;
#else
/* big endian version */
__u64 k_type: 4;
__u64 k_offset:60;
#endif
} __attribute__ ((__packed__));
/* Key of an item determines its location in the S+tree, and /* Key of an item determines its location in the S+tree, and
is composed of 4 components */ is composed of 4 components */
struct reiserfs_key { struct reiserfs_key {
...@@ -466,11 +449,9 @@ struct in_core_key { ...@@ -466,11 +449,9 @@ struct in_core_key {
__u32 k_dir_id; /* packing locality: by default parent __u32 k_dir_id; /* packing locality: by default parent
directory object id */ directory object id */
__u32 k_objectid; /* object identifier */ __u32 k_objectid; /* object identifier */
union { __u64 k_offset;
struct in_core_offset_v1 k_offset_v1; __u8 k_type;
struct in_core_offset_v2 k_offset_v2; };
} __attribute__ ((__packed__)) u;
} __attribute__ ((__packed__));
struct cpu_key { struct cpu_key {
struct in_core_key on_disk_key; struct in_core_key on_disk_key;
...@@ -696,43 +677,29 @@ static inline void set_le_ih_k_type (struct item_head * ih, int type) ...@@ -696,43 +677,29 @@ static inline void set_le_ih_k_type (struct item_head * ih, int type)
// //
static inline loff_t cpu_key_k_offset (const struct cpu_key * key) static inline loff_t cpu_key_k_offset (const struct cpu_key * key)
{ {
return (key->version == KEY_FORMAT_3_5) ? return key->on_disk_key.k_offset;
key->on_disk_key.u.k_offset_v1.k_offset :
key->on_disk_key.u.k_offset_v2.k_offset;
} }
static inline loff_t cpu_key_k_type (const struct cpu_key * key) static inline loff_t cpu_key_k_type (const struct cpu_key * key)
{ {
return (key->version == KEY_FORMAT_3_5) ? return key->on_disk_key.k_type;
uniqueness2type (key->on_disk_key.u.k_offset_v1.k_uniqueness) :
key->on_disk_key.u.k_offset_v2.k_type;
} }
static inline void set_cpu_key_k_offset (struct cpu_key * key, loff_t offset) static inline void set_cpu_key_k_offset (struct cpu_key * key, loff_t offset)
{ {
(key->version == KEY_FORMAT_3_5) ? key->on_disk_key.k_offset = offset;
(key->on_disk_key.u.k_offset_v1.k_offset = offset) :
(key->on_disk_key.u.k_offset_v2.k_offset = offset);
} }
static inline void set_cpu_key_k_type (struct cpu_key * key, int type) static inline void set_cpu_key_k_type (struct cpu_key * key, int type)
{ {
(key->version == KEY_FORMAT_3_5) ? key->on_disk_key.k_type = type;
(key->on_disk_key.u.k_offset_v1.k_uniqueness = type2uniqueness (type)):
(key->on_disk_key.u.k_offset_v2.k_type = type);
} }
static inline void cpu_key_k_offset_dec (struct cpu_key * key) static inline void cpu_key_k_offset_dec (struct cpu_key * key)
{ {
if (key->version == KEY_FORMAT_3_5) key->on_disk_key.k_offset --;
key->on_disk_key.u.k_offset_v1.k_offset --;
else
key->on_disk_key.u.k_offset_v2.k_offset --;
} }
#define is_direntry_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRENTRY) #define is_direntry_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRENTRY)
#define is_direct_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRECT) #define is_direct_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRECT)
#define is_indirect_cpu_key(key) (cpu_key_k_type (key) == TYPE_INDIRECT) #define is_indirect_cpu_key(key) (cpu_key_k_type (key) == TYPE_INDIRECT)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment