Skip to content

Commit a2e0f79

Browse files
committed
GFS2: Remove i_disksize
With the update of the truncate code, ip->i_disksize and inode->i_size are merely copies of each other. This means we can remove ip->i_disksize and use inode->i_size exclusively reducing the size of a GFS2 inode by 8 bytes. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent ff8f33c commit a2e0f79

13 files changed

Lines changed: 60 additions & 58 deletions

File tree

‎fs/gfs2/aops.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,8 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
800800
page_cache_release(page);
801801

802802
if (copied) {
803-
if (inode->i_size < to) {
803+
if (inode->i_size < to)
804804
i_size_write(inode, to);
805-
ip->i_disksize = inode->i_size;
806-
}
807805
gfs2_dinode_out(ip, di);
808806
mark_inode_dirty(inode);
809807
}
@@ -874,8 +872,6 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
874872

875873
ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
876874
if (ret > 0) {
877-
if (inode->i_size > ip->i_disksize)
878-
ip->i_disksize = inode->i_size;
879875
gfs2_dinode_out(ip, dibh->b_data);
880876
mark_inode_dirty(inode);
881877
}

‎fs/gfs2/bmap.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
131131
if (error)
132132
goto out;
133133

134-
if (ip->i_disksize) {
134+
if (i_size_read(&ip->i_inode)) {
135135
/* Get a free block, fill it with the stuffed data,
136136
and write it out to disk */
137137

@@ -160,7 +160,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
160160
di = (struct gfs2_dinode *)dibh->b_data;
161161
gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
162162

163-
if (ip->i_disksize) {
163+
if (i_size_read(&ip->i_inode)) {
164164
*(__be64 *)(di + 1) = cpu_to_be64(block);
165165
gfs2_add_inode_blocks(&ip->i_inode, 1);
166166
di->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode));
@@ -985,7 +985,6 @@ static int trunc_start(struct inode *inode, u64 oldsize, u64 newsize)
985985
}
986986

987987
i_size_write(inode, newsize);
988-
ip->i_disksize = newsize;
989988
ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
990989
gfs2_dinode_out(ip, dibh->b_data);
991990

@@ -1051,7 +1050,7 @@ static int trunc_end(struct gfs2_inode *ip)
10511050
if (error)
10521051
goto out;
10531052

1054-
if (!ip->i_disksize) {
1053+
if (!i_size_read(&ip->i_inode)) {
10551054
ip->i_height = 0;
10561055
ip->i_goal = ip->i_no_addr;
10571056
gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
@@ -1167,7 +1166,6 @@ static int do_grow(struct inode *inode, u64 size)
11671166
goto do_end_trans;
11681167

11691168
i_size_write(inode, size);
1170-
ip->i_disksize = size;
11711169
ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
11721170
gfs2_trans_add_bh(ip->i_gl, dibh, 1);
11731171
gfs2_dinode_out(ip, dibh->b_data);
@@ -1219,7 +1217,7 @@ int gfs2_setattr_size(struct inode *inode, u64 newsize)
12191217
int gfs2_truncatei_resume(struct gfs2_inode *ip)
12201218
{
12211219
int error;
1222-
error = trunc_dealloc(ip, ip->i_disksize);
1220+
error = trunc_dealloc(ip, i_size_read(&ip->i_inode));
12231221
if (!error)
12241222
error = trunc_end(ip);
12251223
return error;
@@ -1260,7 +1258,7 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
12601258

12611259
shift = sdp->sd_sb.sb_bsize_shift;
12621260
BUG_ON(gfs2_is_dir(ip));
1263-
end_of_file = (ip->i_disksize + sdp->sd_sb.sb_bsize - 1) >> shift;
1261+
end_of_file = (i_size_read(&ip->i_inode) + sdp->sd_sb.sb_bsize - 1) >> shift;
12641262
lblock = offset >> shift;
12651263
lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift;
12661264
if (lblock_stop > end_of_file)

‎fs/gfs2/dir.c‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf,
127127

128128
gfs2_trans_add_bh(ip->i_gl, dibh, 1);
129129
memcpy(dibh->b_data + offset + sizeof(struct gfs2_dinode), buf, size);
130-
if (ip->i_disksize < offset + size)
131-
ip->i_disksize = offset + size;
130+
if (ip->i_inode.i_size < offset + size)
131+
i_size_write(&ip->i_inode, offset + size);
132132
ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
133133
gfs2_dinode_out(ip, dibh->b_data);
134134

@@ -225,8 +225,8 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf,
225225
if (error)
226226
return error;
227227

228-
if (ip->i_disksize < offset + copied)
229-
ip->i_disksize = offset + copied;
228+
if (ip->i_inode.i_size < offset + copied)
229+
i_size_write(&ip->i_inode, offset + copied);
230230
ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
231231

232232
gfs2_trans_add_bh(ip->i_gl, dibh, 1);
@@ -275,12 +275,13 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, u64 offset,
275275
unsigned int o;
276276
int copied = 0;
277277
int error = 0;
278+
u64 disksize = i_size_read(&ip->i_inode);
278279

279-
if (offset >= ip->i_disksize)
280+
if (offset >= disksize)
280281
return 0;
281282

282-
if (offset + size > ip->i_disksize)
283-
size = ip->i_disksize - offset;
283+
if (offset + size > disksize)
284+
size = disksize - offset;
284285

285286
if (!size)
286287
return 0;
@@ -727,7 +728,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode,
727728
unsigned hsize = 1 << ip->i_depth;
728729
unsigned index;
729730
u64 ln;
730-
if (hsize * sizeof(u64) != ip->i_disksize) {
731+
if (hsize * sizeof(u64) != i_size_read(inode)) {
731732
gfs2_consist_inode(ip);
732733
return ERR_PTR(-EIO);
733734
}
@@ -879,7 +880,7 @@ static int dir_make_exhash(struct inode *inode)
879880
for (x = sdp->sd_hash_ptrs; x--; lp++)
880881
*lp = cpu_to_be64(bn);
881882

882-
dip->i_disksize = sdp->sd_sb.sb_bsize / 2;
883+
i_size_write(inode, sdp->sd_sb.sb_bsize / 2);
883884
gfs2_add_inode_blocks(&dip->i_inode, 1);
884885
dip->i_diskflags |= GFS2_DIF_EXHASH;
885886

@@ -1057,11 +1058,12 @@ static int dir_double_exhash(struct gfs2_inode *dip)
10571058
u64 *buf;
10581059
u64 *from, *to;
10591060
u64 block;
1061+
u64 disksize = i_size_read(&dip->i_inode);
10601062
int x;
10611063
int error = 0;
10621064

10631065
hsize = 1 << dip->i_depth;
1064-
if (hsize * sizeof(u64) != dip->i_disksize) {
1066+
if (hsize * sizeof(u64) != disksize) {
10651067
gfs2_consist_inode(dip);
10661068
return -EIO;
10671069
}
@@ -1072,7 +1074,7 @@ static int dir_double_exhash(struct gfs2_inode *dip)
10721074
if (!buf)
10731075
return -ENOMEM;
10741076

1075-
for (block = dip->i_disksize >> sdp->sd_hash_bsize_shift; block--;) {
1077+
for (block = disksize >> sdp->sd_hash_bsize_shift; block--;) {
10761078
error = gfs2_dir_read_data(dip, (char *)buf,
10771079
block * sdp->sd_hash_bsize,
10781080
sdp->sd_hash_bsize, 1);
@@ -1370,7 +1372,7 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque,
13701372
unsigned depth = 0;
13711373

13721374
hsize = 1 << dip->i_depth;
1373-
if (hsize * sizeof(u64) != dip->i_disksize) {
1375+
if (hsize * sizeof(u64) != i_size_read(inode)) {
13741376
gfs2_consist_inode(dip);
13751377
return -EIO;
13761378
}
@@ -1784,7 +1786,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data)
17841786
int error = 0;
17851787

17861788
hsize = 1 << dip->i_depth;
1787-
if (hsize * sizeof(u64) != dip->i_disksize) {
1789+
if (hsize * sizeof(u64) != i_size_read(&dip->i_inode)) {
17881790
gfs2_consist_inode(dip);
17891791
return -EIO;
17901792
}

‎fs/gfs2/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ static int gfs2_open(struct inode *inode, struct file *file)
491491
goto fail;
492492

493493
if (!(file->f_flags & O_LARGEFILE) &&
494-
ip->i_disksize > MAX_NON_LFS) {
494+
i_size_read(inode) > MAX_NON_LFS) {
495495
error = -EOVERFLOW;
496496
goto fail_gunlock;
497497
}

‎fs/gfs2/glops.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,12 @@ static int inode_go_dump(struct seq_file *seq, const struct gfs2_glock *gl)
262262
const struct gfs2_inode *ip = gl->gl_object;
263263
if (ip == NULL)
264264
return 0;
265-
gfs2_print_dbg(seq, " I: n:%llu/%llu t:%u f:0x%02lx d:0x%08x s:%llu/%llu\n",
265+
gfs2_print_dbg(seq, " I: n:%llu/%llu t:%u f:0x%02lx d:0x%08x s:%llu\n",
266266
(unsigned long long)ip->i_no_formal_ino,
267267
(unsigned long long)ip->i_no_addr,
268268
IF2DT(ip->i_inode.i_mode), ip->i_flags,
269269
(unsigned int)ip->i_diskflags,
270-
(unsigned long long)ip->i_inode.i_size,
271-
(unsigned long long)ip->i_disksize);
270+
(unsigned long long)i_size_read(&ip->i_inode));
272271
return 0;
273272
}
274273

‎fs/gfs2/incore.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ struct gfs2_inode {
267267
u64 i_no_formal_ino;
268268
u64 i_generation;
269269
u64 i_eattr;
270-
loff_t i_disksize;
271270
unsigned long i_flags; /* GIF_... */
272271
struct gfs2_glock *i_gl; /* Move into i_gh? */
273272
struct gfs2_holder i_iopen_gh;

‎fs/gfs2/inode.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
359359
* to do that.
360360
*/
361361
ip->i_inode.i_nlink = be32_to_cpu(str->di_nlink);
362-
ip->i_disksize = be64_to_cpu(str->di_size);
363-
i_size_write(&ip->i_inode, ip->i_disksize);
362+
i_size_write(&ip->i_inode, be64_to_cpu(str->di_size));
364363
gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks));
365364
atime.tv_sec = be64_to_cpu(str->di_atime);
366365
atime.tv_nsec = be32_to_cpu(str->di_atime_nsec);
@@ -1055,7 +1054,7 @@ void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf)
10551054
str->di_uid = cpu_to_be32(ip->i_inode.i_uid);
10561055
str->di_gid = cpu_to_be32(ip->i_inode.i_gid);
10571056
str->di_nlink = cpu_to_be32(ip->i_inode.i_nlink);
1058-
str->di_size = cpu_to_be64(ip->i_disksize);
1057+
str->di_size = cpu_to_be64(i_size_read(&ip->i_inode));
10591058
str->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode));
10601059
str->di_atime = cpu_to_be64(ip->i_inode.i_atime.tv_sec);
10611060
str->di_mtime = cpu_to_be64(ip->i_inode.i_mtime.tv_sec);
@@ -1085,8 +1084,8 @@ void gfs2_dinode_print(const struct gfs2_inode *ip)
10851084
(unsigned long long)ip->i_no_formal_ino);
10861085
printk(KERN_INFO " no_addr = %llu\n",
10871086
(unsigned long long)ip->i_no_addr);
1088-
printk(KERN_INFO " i_disksize = %llu\n",
1089-
(unsigned long long)ip->i_disksize);
1087+
printk(KERN_INFO " i_size = %llu\n",
1088+
(unsigned long long)i_size_read(&ip->i_inode));
10901089
printk(KERN_INFO " blocks = %llu\n",
10911090
(unsigned long long)gfs2_get_inode_blocks(&ip->i_inode));
10921091
printk(KERN_INFO " i_goal = %llu\n",

‎fs/gfs2/inode.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ static inline void gfs2_inum_out(const struct gfs2_inode *ip,
8080
dent->de_inum.no_addr = cpu_to_be64(ip->i_no_addr);
8181
}
8282

83+
static inline int gfs2_check_internal_file_size(struct inode *inode,
84+
u64 minsize, u64 maxsize)
85+
{
86+
u64 size = i_size_read(inode);
87+
if (size < minsize || size > maxsize)
88+
goto err;
89+
if (size & ((1 << inode->i_blkbits) - 1))
90+
goto err;
91+
return 0;
92+
err:
93+
gfs2_consist_inode(GFS2_I(inode));
94+
return -EIO;
95+
}
8396

8497
extern void gfs2_set_iop(struct inode *inode);
8598
extern struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type,

‎fs/gfs2/ops_fstype.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ static int map_journal_extents(struct gfs2_sbd *sdp)
586586

587587
prev_db = 0;
588588

589-
for (lb = 0; lb < ip->i_disksize >> sdp->sd_sb.sb_bsize_shift; lb++) {
589+
for (lb = 0; lb < i_size_read(jd->jd_inode) >> sdp->sd_sb.sb_bsize_shift; lb++) {
590590
bh.b_state = 0;
591591
bh.b_blocknr = 0;
592592
bh.b_size = 1 << ip->i_inode.i_blkbits;

‎fs/gfs2/ops_inode.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
406406

407407
ip = ghs[1].gh_gl->gl_object;
408408

409-
ip->i_disksize = size;
410409
i_size_write(inode, size);
411410

412411
error = gfs2_meta_inode_buffer(ip, &dibh);
@@ -461,7 +460,7 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
461460
ip = ghs[1].gh_gl->gl_object;
462461

463462
ip->i_inode.i_nlink = 2;
464-
ip->i_disksize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
463+
i_size_write(inode, sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode));
465464
ip->i_diskflags |= GFS2_DIF_JDATA;
466465
ip->i_entries = 2;
467466

@@ -990,7 +989,7 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
990989
struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
991990
struct gfs2_holder i_gh;
992991
struct buffer_head *dibh;
993-
unsigned int x;
992+
unsigned int x, size;
994993
char *buf;
995994
int error;
996995

@@ -1002,7 +1001,8 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
10021001
return NULL;
10031002
}
10041003

1005-
if (!ip->i_disksize) {
1004+
size = (unsigned int)i_size_read(&ip->i_inode);
1005+
if (size == 0) {
10061006
gfs2_consist_inode(ip);
10071007
buf = ERR_PTR(-EIO);
10081008
goto out;
@@ -1014,7 +1014,7 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
10141014
goto out;
10151015
}
10161016

1017-
x = ip->i_disksize + 1;
1017+
x = size + 1;
10181018
buf = kmalloc(x, GFP_NOFS);
10191019
if (!buf)
10201020
buf = ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)