Commit 9a004508 authored by Steven Whitehouse's avatar Steven Whitehouse

[GFS2] Shrink & rename di_depth

This patch forms a pair with the previous patch which shrunk
di_height. Like that patch di_depth is renamed i_depth and moved
into struct gfs2_inode directly. Also the field goes from 16 bits
to 8 bits since it is also limited to a max value which is rather
small (17 in this case). In addition we also now validate the field
against this maximum value when its read in.
Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent cf45b752
...@@ -757,7 +757,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, ...@@ -757,7 +757,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode,
if (ip->i_di.di_flags & GFS2_DIF_EXHASH) { if (ip->i_di.di_flags & GFS2_DIF_EXHASH) {
struct gfs2_leaf *leaf; struct gfs2_leaf *leaf;
unsigned hsize = 1 << ip->i_di.di_depth; unsigned hsize = 1 << ip->i_depth;
unsigned index; unsigned index;
u64 ln; u64 ln;
if (hsize * sizeof(u64) != ip->i_di.di_size) { if (hsize * sizeof(u64) != ip->i_di.di_size) {
...@@ -765,7 +765,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, ...@@ -765,7 +765,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode,
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
index = name->hash >> (32 - ip->i_di.di_depth); index = name->hash >> (32 - ip->i_depth);
error = get_first_leaf(ip, index, &bh); error = get_first_leaf(ip, index, &bh);
if (error) if (error)
return ERR_PTR(error); return ERR_PTR(error);
...@@ -910,7 +910,7 @@ static int dir_make_exhash(struct inode *inode) ...@@ -910,7 +910,7 @@ static int dir_make_exhash(struct inode *inode)
dip->i_di.di_flags |= GFS2_DIF_EXHASH; dip->i_di.di_flags |= GFS2_DIF_EXHASH;
for (x = sdp->sd_hash_ptrs, y = -1; x; x >>= 1, y++) ; for (x = sdp->sd_hash_ptrs, y = -1; x; x >>= 1, y++) ;
dip->i_di.di_depth = y; dip->i_depth = y;
gfs2_dinode_out(dip, dibh->b_data); gfs2_dinode_out(dip, dibh->b_data);
...@@ -941,7 +941,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) ...@@ -941,7 +941,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name)
int x, moved = 0; int x, moved = 0;
int error; int error;
index = name->hash >> (32 - dip->i_di.di_depth); index = name->hash >> (32 - dip->i_depth);
error = get_leaf_nr(dip, index, &leaf_no); error = get_leaf_nr(dip, index, &leaf_no);
if (error) if (error)
return error; return error;
...@@ -952,7 +952,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) ...@@ -952,7 +952,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name)
return error; return error;
oleaf = (struct gfs2_leaf *)obh->b_data; oleaf = (struct gfs2_leaf *)obh->b_data;
if (dip->i_di.di_depth == be16_to_cpu(oleaf->lf_depth)) { if (dip->i_depth == be16_to_cpu(oleaf->lf_depth)) {
brelse(obh); brelse(obh);
return 1; /* can't split */ return 1; /* can't split */
} }
...@@ -967,10 +967,10 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) ...@@ -967,10 +967,10 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name)
bn = nbh->b_blocknr; bn = nbh->b_blocknr;
/* Compute the start and len of leaf pointers in the hash table. */ /* Compute the start and len of leaf pointers in the hash table. */
len = 1 << (dip->i_di.di_depth - be16_to_cpu(oleaf->lf_depth)); len = 1 << (dip->i_depth - be16_to_cpu(oleaf->lf_depth));
half_len = len >> 1; half_len = len >> 1;
if (!half_len) { if (!half_len) {
printk(KERN_WARNING "di_depth %u lf_depth %u index %u\n", dip->i_di.di_depth, be16_to_cpu(oleaf->lf_depth), index); printk(KERN_WARNING "i_depth %u lf_depth %u index %u\n", dip->i_depth, be16_to_cpu(oleaf->lf_depth), index);
gfs2_consist_inode(dip); gfs2_consist_inode(dip);
error = -EIO; error = -EIO;
goto fail_brelse; goto fail_brelse;
...@@ -997,7 +997,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) ...@@ -997,7 +997,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name)
kfree(lp); kfree(lp);
/* Compute the divider */ /* Compute the divider */
divider = (start + half_len) << (32 - dip->i_di.di_depth); divider = (start + half_len) << (32 - dip->i_depth);
/* Copy the entries */ /* Copy the entries */
dirent_first(dip, obh, &dent); dirent_first(dip, obh, &dent);
...@@ -1082,7 +1082,7 @@ static int dir_double_exhash(struct gfs2_inode *dip) ...@@ -1082,7 +1082,7 @@ static int dir_double_exhash(struct gfs2_inode *dip)
int x; int x;
int error = 0; int error = 0;
hsize = 1 << dip->i_di.di_depth; hsize = 1 << dip->i_depth;
if (hsize * sizeof(u64) != dip->i_di.di_size) { if (hsize * sizeof(u64) != dip->i_di.di_size) {
gfs2_consist_inode(dip); gfs2_consist_inode(dip);
return -EIO; return -EIO;
...@@ -1125,7 +1125,7 @@ static int dir_double_exhash(struct gfs2_inode *dip) ...@@ -1125,7 +1125,7 @@ static int dir_double_exhash(struct gfs2_inode *dip)
error = gfs2_meta_inode_buffer(dip, &dibh); error = gfs2_meta_inode_buffer(dip, &dibh);
if (!gfs2_assert_withdraw(sdp, !error)) { if (!gfs2_assert_withdraw(sdp, !error)) {
dip->i_di.di_depth++; dip->i_depth++;
gfs2_dinode_out(dip, dibh->b_data); gfs2_dinode_out(dip, dibh->b_data);
brelse(dibh); brelse(dibh);
} }
...@@ -1370,14 +1370,14 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque, ...@@ -1370,14 +1370,14 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque,
int error = 0; int error = 0;
unsigned depth = 0; unsigned depth = 0;
hsize = 1 << dip->i_di.di_depth; hsize = 1 << dip->i_depth;
if (hsize * sizeof(u64) != dip->i_di.di_size) { if (hsize * sizeof(u64) != dip->i_di.di_size) {
gfs2_consist_inode(dip); gfs2_consist_inode(dip);
return -EIO; return -EIO;
} }
hash = gfs2_dir_offset2hash(*offset); hash = gfs2_dir_offset2hash(*offset);
index = hash >> (32 - dip->i_di.di_depth); index = hash >> (32 - dip->i_depth);
lp = kmalloc(sdp->sd_hash_bsize, GFP_KERNEL); lp = kmalloc(sdp->sd_hash_bsize, GFP_KERNEL);
if (!lp) if (!lp)
...@@ -1405,7 +1405,7 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque, ...@@ -1405,7 +1405,7 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque,
if (error) if (error)
break; break;
len = 1 << (dip->i_di.di_depth - depth); len = 1 << (dip->i_depth - depth);
index = (index & ~(len - 1)) + len; index = (index & ~(len - 1)) + len;
} }
...@@ -1549,7 +1549,7 @@ static int dir_new_leaf(struct inode *inode, const struct qstr *name) ...@@ -1549,7 +1549,7 @@ static int dir_new_leaf(struct inode *inode, const struct qstr *name)
u32 index; u32 index;
u64 bn; u64 bn;
index = name->hash >> (32 - ip->i_di.di_depth); index = name->hash >> (32 - ip->i_depth);
error = get_first_leaf(ip, index, &obh); error = get_first_leaf(ip, index, &obh);
if (error) if (error)
return error; return error;
...@@ -1641,7 +1641,7 @@ int gfs2_dir_add(struct inode *inode, const struct qstr *name, ...@@ -1641,7 +1641,7 @@ int gfs2_dir_add(struct inode *inode, const struct qstr *name,
continue; continue;
if (error < 0) if (error < 0)
break; break;
if (ip->i_di.di_depth < GFS2_DIR_MAX_DEPTH) { if (ip->i_depth < GFS2_DIR_MAX_DEPTH) {
error = dir_double_exhash(ip); error = dir_double_exhash(ip);
if (error) if (error)
break; break;
...@@ -1785,7 +1785,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) ...@@ -1785,7 +1785,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data)
u64 leaf_no; u64 leaf_no;
int error = 0; int error = 0;
hsize = 1 << dip->i_di.di_depth; hsize = 1 << dip->i_depth;
if (hsize * sizeof(u64) != dip->i_di.di_size) { if (hsize * sizeof(u64) != dip->i_di.di_size) {
gfs2_consist_inode(dip); gfs2_consist_inode(dip);
return -EIO; return -EIO;
...@@ -1817,7 +1817,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) ...@@ -1817,7 +1817,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data)
if (error) if (error)
goto out; goto out;
leaf = (struct gfs2_leaf *)bh->b_data; leaf = (struct gfs2_leaf *)bh->b_data;
len = 1 << (dip->i_di.di_depth - be16_to_cpu(leaf->lf_depth)); len = 1 << (dip->i_depth - be16_to_cpu(leaf->lf_depth));
brelse(bh); brelse(bh);
error = lc(dip, index, len, leaf_no, data); error = lc(dip, index, len, leaf_no, data);
......
...@@ -246,7 +246,6 @@ struct gfs2_dinode_host { ...@@ -246,7 +246,6 @@ struct gfs2_dinode_host {
u64 di_generation; /* generation number for NFS */ u64 di_generation; /* generation number for NFS */
u32 di_flags; /* GFS2_DIF_... */ u32 di_flags; /* GFS2_DIF_... */
/* These only apply to directories */ /* These only apply to directories */
u16 di_depth; /* Number of bits in the table */
u32 di_entries; /* The number of entries in the directory */ u32 di_entries; /* The number of entries in the directory */
u64 di_eattr; /* extended attribute block number */ u64 di_eattr; /* extended attribute block number */
}; };
...@@ -267,6 +266,7 @@ struct gfs2_inode { ...@@ -267,6 +266,7 @@ struct gfs2_inode {
struct rw_semaphore i_rw_mutex; struct rw_semaphore i_rw_mutex;
u8 i_height; u8 i_height;
u8 i_depth;
}; };
/* /*
......
...@@ -248,7 +248,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) ...@@ -248,7 +248,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
{ {
struct gfs2_dinode_host *di = &ip->i_di; struct gfs2_dinode_host *di = &ip->i_di;
const struct gfs2_dinode *str = buf; const struct gfs2_dinode *str = buf;
u16 height; u16 height, depth;
if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr))) if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr)))
goto corrupt; goto corrupt;
...@@ -293,7 +293,10 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) ...@@ -293,7 +293,10 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
goto corrupt; goto corrupt;
ip->i_height = (u8)height; ip->i_height = (u8)height;
di->di_depth = be16_to_cpu(str->di_depth); depth = be16_to_cpu(str->di_depth);
if (unlikely(depth > GFS2_DIR_MAX_DEPTH))
goto corrupt;
ip->i_depth = (u8)depth;
di->di_entries = be32_to_cpu(str->di_entries); di->di_entries = be32_to_cpu(str->di_entries);
di->di_eattr = be64_to_cpu(str->di_eattr); di->di_eattr = be64_to_cpu(str->di_eattr);
...@@ -1410,7 +1413,7 @@ void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf) ...@@ -1410,7 +1413,7 @@ void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf)
str->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) && str->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) &&
!(ip->i_di.di_flags & GFS2_DIF_EXHASH) ? !(ip->i_di.di_flags & GFS2_DIF_EXHASH) ?
GFS2_FORMAT_DE : 0); GFS2_FORMAT_DE : 0);
str->di_depth = cpu_to_be16(di->di_depth); str->di_depth = cpu_to_be16(ip->i_depth);
str->di_entries = cpu_to_be32(di->di_entries); str->di_entries = cpu_to_be32(di->di_entries);
str->di_eattr = cpu_to_be64(di->di_eattr); str->di_eattr = cpu_to_be64(di->di_eattr);
...@@ -1436,7 +1439,7 @@ void gfs2_dinode_print(const struct gfs2_inode *ip) ...@@ -1436,7 +1439,7 @@ void gfs2_dinode_print(const struct gfs2_inode *ip)
(unsigned long long)di->di_goal_data); (unsigned long long)di->di_goal_data);
printk(KERN_INFO " di_flags = 0x%.8X\n", di->di_flags); printk(KERN_INFO " di_flags = 0x%.8X\n", di->di_flags);
printk(KERN_INFO " i_height = %u\n", ip->i_height); printk(KERN_INFO " i_height = %u\n", ip->i_height);
printk(KERN_INFO " di_depth = %u\n", di->di_depth); printk(KERN_INFO " i_depth = %u\n", ip->i_depth);
printk(KERN_INFO " di_entries = %u\n", di->di_entries); printk(KERN_INFO " di_entries = %u\n", di->di_entries);
printk(KERN_INFO " di_eattr = %llu\n", printk(KERN_INFO " di_eattr = %llu\n",
(unsigned long long)di->di_eattr); (unsigned long long)di->di_eattr);
......
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