Skip to content

Commit ab9bbda

Browse files
committed
GFS2: Use ->dirty_inode()
The aim of this patch is to use the newly enhanced ->dirty_inode() super block operation to deal with atime updates, rather than piggy backing that code into ->write_inode() as is currently done. The net result is a simplification of the code in various places and a reduction of the number of gfs2_dinode_out() calls since this is now implied by ->dirty_inode(). Some of the mark_inode_dirty() calls have been moved under glocks in order to take advantage of then being able to avoid locking in ->dirty_inode() when we already have suitable locks. One consequence is that generic_write_end() now correctly deals with file size updates, so that we do not need a separate check for that afterwards. This also, indirectly, means that fdatasync should work correctly on GFS2 - the current code always syncs the metadata whether it needs to or not. Has survived testing with postmark (with and without atime) and also fsx. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent f181852 commit ab9bbda

9 files changed

Lines changed: 85 additions & 97 deletions

File tree

‎fs/gfs2/acl.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int gfs2_set_mode(struct inode *inode, umode_t mode)
8282
iattr.ia_valid = ATTR_MODE;
8383
iattr.ia_mode = mode;
8484

85-
error = gfs2_setattr_simple(GFS2_I(inode), &iattr);
85+
error = gfs2_setattr_simple(inode, &iattr);
8686
}
8787

8888
return error;
@@ -160,6 +160,7 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct inode *inode)
160160

161161
int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
162162
{
163+
struct inode *inode = &ip->i_inode;
163164
struct posix_acl *acl;
164165
char *data;
165166
unsigned int len;
@@ -169,7 +170,7 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
169170
if (IS_ERR(acl))
170171
return PTR_ERR(acl);
171172
if (!acl)
172-
return gfs2_setattr_simple(ip, attr);
173+
return gfs2_setattr_simple(inode, attr);
173174

174175
error = posix_acl_chmod(&acl, GFP_NOFS, attr->ia_mode);
175176
if (error)

‎fs/gfs2/aops.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
787787
u64 to = pos + copied;
788788
void *kaddr;
789789
unsigned char *buf = dibh->b_data + sizeof(struct gfs2_dinode);
790-
struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
791790

792791
BUG_ON((pos + len) > (dibh->b_size - sizeof(struct gfs2_dinode)));
793792
kaddr = kmap_atomic(page, KM_USER0);
@@ -804,7 +803,6 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
804803
if (copied) {
805804
if (inode->i_size < to)
806805
i_size_write(inode, to);
807-
gfs2_dinode_out(ip, di);
808806
mark_inode_dirty(inode);
809807
}
810808

@@ -873,10 +871,6 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
873871
gfs2_page_add_databufs(ip, page, from, to);
874872

875873
ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
876-
if (ret > 0) {
877-
gfs2_dinode_out(ip, dibh->b_data);
878-
mark_inode_dirty(inode);
879-
}
880874

881875
if (inode == sdp->sd_rindex) {
882876
adjust_fs_space(inode);

‎fs/gfs2/dir.c‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,6 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry)
16811681
const struct qstr *name = &dentry->d_name;
16821682
struct gfs2_dirent *dent, *prev = NULL;
16831683
struct buffer_head *bh;
1684-
int error;
16851684

16861685
/* Returns _either_ the entry (if its first in block) or the
16871686
previous entry otherwise */
@@ -1710,22 +1709,15 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry)
17101709
}
17111710
brelse(bh);
17121711

1713-
error = gfs2_meta_inode_buffer(dip, &bh);
1714-
if (error)
1715-
return error;
1716-
17171712
if (!dip->i_entries)
17181713
gfs2_consist_inode(dip);
1719-
gfs2_trans_add_bh(dip->i_gl, bh, 1);
17201714
dip->i_entries--;
17211715
dip->i_inode.i_mtime = dip->i_inode.i_ctime = CURRENT_TIME;
17221716
if (S_ISDIR(dentry->d_inode->i_mode))
17231717
drop_nlink(&dip->i_inode);
1724-
gfs2_dinode_out(dip, bh->b_data);
1725-
brelse(bh);
17261718
mark_inode_dirty(&dip->i_inode);
17271719

1728-
return error;
1720+
return 0;
17291721
}
17301722

17311723
/**

‎fs/gfs2/file.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,6 @@ static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,
802802
from = 0;
803803
}
804804

805-
gfs2_dinode_out(ip, dibh->b_data);
806805
mark_inode_dirty(inode);
807806

808807
brelse(dibh);

‎fs/gfs2/inode.c‎

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
729729
gfs2_inplace_release(dip);
730730
gfs2_quota_unlock(dip);
731731
gfs2_alloc_put(dip);
732-
gfs2_glock_dq_uninit_m(2, ghs);
733732
mark_inode_dirty(inode);
733+
gfs2_glock_dq_uninit_m(2, ghs);
734734
d_instantiate(dentry, inode);
735735
return 0;
736736

@@ -926,8 +926,9 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
926926
gfs2_trans_add_bh(ip->i_gl, dibh, 1);
927927
inc_nlink(&ip->i_inode);
928928
ip->i_inode.i_ctime = CURRENT_TIME;
929-
gfs2_dinode_out(ip, dibh->b_data);
930-
mark_inode_dirty(&ip->i_inode);
929+
ihold(inode);
930+
d_instantiate(dentry, inode);
931+
mark_inode_dirty(inode);
931932

932933
out_brelse:
933934
brelse(dibh);
@@ -949,11 +950,6 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
949950
out_parent:
950951
gfs2_holder_uninit(ghs);
951952
gfs2_holder_uninit(ghs + 1);
952-
if (!error) {
953-
ihold(inode);
954-
d_instantiate(dentry, inode);
955-
mark_inode_dirty(inode);
956-
}
957953
return error;
958954
}
959955

@@ -1026,8 +1022,6 @@ static int gfs2_unlink_inode(struct gfs2_inode *dip,
10261022
clear_nlink(inode);
10271023
else
10281024
drop_nlink(inode);
1029-
gfs2_trans_add_bh(ip->i_gl, bh, 1);
1030-
gfs2_dinode_out(ip, bh->b_data);
10311025
mark_inode_dirty(inode);
10321026
if (inode->i_nlink == 0)
10331027
gfs2_unlink_di(inode);
@@ -1565,21 +1559,10 @@ int gfs2_permission(struct inode *inode, int mask)
15651559
return error;
15661560
}
15671561

1568-
static int __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
1562+
static int __gfs2_setattr_simple(struct inode *inode, struct iattr *attr)
15691563
{
1570-
struct inode *inode = &ip->i_inode;
1571-
struct buffer_head *dibh;
1572-
int error;
1573-
1574-
error = gfs2_meta_inode_buffer(ip, &dibh);
1575-
if (error)
1576-
return error;
1577-
15781564
setattr_copy(inode, attr);
15791565
mark_inode_dirty(inode);
1580-
gfs2_trans_add_bh(ip->i_gl, dibh, 1);
1581-
gfs2_dinode_out(ip, dibh->b_data);
1582-
brelse(dibh);
15831566
return 0;
15841567
}
15851568

@@ -1591,19 +1574,19 @@ static int __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
15911574
* Returns: errno
15921575
*/
15931576

1594-
int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
1577+
int gfs2_setattr_simple(struct inode *inode, struct iattr *attr)
15951578
{
15961579
int error;
15971580

15981581
if (current->journal_info)
1599-
return __gfs2_setattr_simple(ip, attr);
1582+
return __gfs2_setattr_simple(inode, attr);
16001583

1601-
error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE, 0);
1584+
error = gfs2_trans_begin(GFS2_SB(inode), RES_DINODE, 0);
16021585
if (error)
16031586
return error;
16041587

1605-
error = __gfs2_setattr_simple(ip, attr);
1606-
gfs2_trans_end(GFS2_SB(&ip->i_inode));
1588+
error = __gfs2_setattr_simple(inode, attr);
1589+
gfs2_trans_end(GFS2_SB(inode));
16071590
return error;
16081591
}
16091592

@@ -1641,7 +1624,7 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
16411624
if (error)
16421625
goto out_gunlock_q;
16431626

1644-
error = gfs2_setattr_simple(ip, attr);
1627+
error = gfs2_setattr_simple(inode, attr);
16451628
if (error)
16461629
goto out_end_trans;
16471630

@@ -1697,12 +1680,12 @@ static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
16971680
else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
16981681
error = gfs2_acl_chmod(ip, attr);
16991682
else
1700-
error = gfs2_setattr_simple(ip, attr);
1683+
error = gfs2_setattr_simple(inode, attr);
17011684

17021685
out:
1703-
gfs2_glock_dq_uninit(&i_gh);
17041686
if (!error)
17051687
mark_inode_dirty(inode);
1688+
gfs2_glock_dq_uninit(&i_gh);
17061689
return error;
17071690
}
17081691

‎fs/gfs2/inode.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ extern int gfs2_inode_refresh(struct gfs2_inode *ip);
109109
extern struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
110110
int is_root);
111111
extern int gfs2_permission(struct inode *inode, int mask);
112-
extern int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr);
112+
extern int gfs2_setattr_simple(struct inode *inode, struct iattr *attr);
113113
extern struct inode *gfs2_lookup_simple(struct inode *dip, const char *name);
114114
extern void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf);
115115

‎fs/gfs2/quota.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
638638
unsigned long index = loc >> PAGE_CACHE_SHIFT;
639639
unsigned offset = loc & (PAGE_CACHE_SIZE - 1);
640640
unsigned blocksize, iblock, pos;
641-
struct buffer_head *bh, *dibh;
641+
struct buffer_head *bh;
642642
struct page *page;
643643
void *kaddr, *ptr;
644644
struct gfs2_quota q, *qp;
@@ -736,22 +736,13 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
736736
goto get_a_page;
737737
}
738738

739-
/* Update the disk inode timestamp and size (if extended) */
740-
err = gfs2_meta_inode_buffer(ip, &dibh);
741-
if (err)
742-
goto out;
743-
744739
size = loc + sizeof(struct gfs2_quota);
745740
if (size > inode->i_size)
746741
i_size_write(inode, size);
747742
inode->i_mtime = inode->i_atime = CURRENT_TIME;
748-
gfs2_trans_add_bh(ip->i_gl, dibh, 1);
749-
gfs2_dinode_out(ip, dibh->b_data);
750-
brelse(dibh);
751743
mark_inode_dirty(inode);
752-
753-
out:
754744
return err;
745+
755746
unlock_out:
756747
unlock_page(page);
757748
page_cache_release(page);

‎fs/gfs2/super.c‎

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -752,53 +752,79 @@ static int gfs2_write_inode(struct inode *inode, struct writeback_control *wbc)
752752
struct gfs2_sbd *sdp = GFS2_SB(inode);
753753
struct address_space *metamapping = gfs2_glock2aspace(ip->i_gl);
754754
struct backing_dev_info *bdi = metamapping->backing_dev_info;
755-
struct gfs2_holder gh;
756-
struct buffer_head *bh;
757-
struct timespec atime;
758-
struct gfs2_dinode *di;
759-
int ret = -EAGAIN;
760-
int unlock_required = 0;
761-
762-
/* Skip timestamp update, if this is from a memalloc */
763-
if (current->flags & PF_MEMALLOC)
764-
goto do_flush;
765-
if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
766-
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
767-
if (ret)
768-
goto do_flush;
769-
unlock_required = 1;
770-
}
771-
ret = gfs2_meta_inode_buffer(ip, &bh);
772-
if (ret == 0) {
773-
di = (struct gfs2_dinode *)bh->b_data;
774-
atime.tv_sec = be64_to_cpu(di->di_atime);
775-
atime.tv_nsec = be32_to_cpu(di->di_atime_nsec);
776-
if (timespec_compare(&inode->i_atime, &atime) > 0) {
777-
ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
778-
if (ret == 0) {
779-
gfs2_trans_add_bh(ip->i_gl, bh, 1);
780-
gfs2_dinode_out(ip, bh->b_data);
781-
gfs2_trans_end(sdp);
782-
}
783-
}
784-
brelse(bh);
785-
}
786-
if (unlock_required)
787-
gfs2_glock_dq_uninit(&gh);
788-
do_flush:
755+
int ret = 0;
756+
789757
if (wbc->sync_mode == WB_SYNC_ALL)
790758
gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
791759
if (bdi->dirty_exceeded)
792760
gfs2_ail1_flush(sdp, wbc);
793761
else
794762
filemap_fdatawrite(metamapping);
795-
if (!ret && (wbc->sync_mode == WB_SYNC_ALL))
763+
if (wbc->sync_mode == WB_SYNC_ALL)
796764
ret = filemap_fdatawait(metamapping);
797765
if (ret)
798766
mark_inode_dirty_sync(inode);
799767
return ret;
800768
}
801769

770+
/**
771+
* gfs2_dirty_inode - check for atime updates
772+
* @inode: The inode in question
773+
* @flags: The type of dirty
774+
*
775+
* Unfortunately it can be called under any combination of inode
776+
* glock and transaction lock, so we have to check carefully.
777+
*
778+
* At the moment this deals only with atime - it should be possible
779+
* to expand that role in future, once a review of the locking has
780+
* been carried out.
781+
*/
782+
783+
static void gfs2_dirty_inode(struct inode *inode, int flags)
784+
{
785+
struct gfs2_inode *ip = GFS2_I(inode);
786+
struct gfs2_sbd *sdp = GFS2_SB(inode);
787+
struct buffer_head *bh;
788+
struct gfs2_holder gh;
789+
int need_unlock = 0;
790+
int need_endtrans = 0;
791+
int ret;
792+
793+
if (!(flags & (I_DIRTY_DATASYNC|I_DIRTY_SYNC)))
794+
return;
795+
796+
if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
797+
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
798+
if (ret) {
799+
fs_err(sdp, "dirty_inode: glock %d\n", ret);
800+
return;
801+
}
802+
need_unlock = 1;
803+
}
804+
805+
if (current->journal_info == NULL) {
806+
ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
807+
if (ret) {
808+
fs_err(sdp, "dirty_inode: gfs2_trans_begin %d\n", ret);
809+
goto out;
810+
}
811+
need_endtrans = 1;
812+
}
813+
814+
ret = gfs2_meta_inode_buffer(ip, &bh);
815+
if (ret == 0) {
816+
gfs2_trans_add_bh(ip->i_gl, bh, 1);
817+
gfs2_dinode_out(ip, bh->b_data);
818+
brelse(bh);
819+
}
820+
821+
if (need_endtrans)
822+
gfs2_trans_end(sdp);
823+
out:
824+
if (need_unlock)
825+
gfs2_glock_dq_uninit(&gh);
826+
}
827+
802828
/**
803829
* gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
804830
* @sdp: the filesystem
@@ -1578,6 +1604,7 @@ const struct super_operations gfs2_super_ops = {
15781604
.alloc_inode = gfs2_alloc_inode,
15791605
.destroy_inode = gfs2_destroy_inode,
15801606
.write_inode = gfs2_write_inode,
1607+
.dirty_inode = gfs2_dirty_inode,
15811608
.evict_inode = gfs2_evict_inode,
15821609
.put_super = gfs2_put_super,
15831610
.sync_fs = gfs2_sync_fs,

‎fs/gfs2/xattr.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,8 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip,
12961296

12971297
int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data)
12981298
{
1299-
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1299+
struct inode *inode = &ip->i_inode;
1300+
struct gfs2_sbd *sdp = GFS2_SB(inode);
13001301
struct gfs2_ea_location el;
13011302
int error;
13021303

@@ -1319,7 +1320,7 @@ int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data)
13191320
if (error)
13201321
return error;
13211322

1322-
error = gfs2_setattr_simple(ip, attr);
1323+
error = gfs2_setattr_simple(inode, attr);
13231324
gfs2_trans_end(sdp);
13241325
return error;
13251326
}

0 commit comments

Comments
 (0)