GFS2: Pre-pull patch posting (merge window)
Hi,
Since the merge window is coming up soon, I'm posting the content of the GFS2 -nmw tree as usual. There is not a whole lot of change this time - there are some further changes which are in the works, but those will be held over until next time.
Here there are some clean ups to inode creation, the addition of an origin (local or remote) indicator to glock demote requests, removal of one of the remaining GFP_NOFAIL allocations during log flushes, one minor clean up, and a one liner bug fix,
Steve.
PATCH 1/8 GFS2: Clean up inode creation path
This patch cleans up the inode creation code path in GFS2. After the Orlov allocator was merged, a number of potential improvements are now possible, and this is a first set of these.
The quota handling is now updated so that it matches the point in the code where the allocation takes place. This means that the one exception in gfs2_alloc_blocks relating to quota is now no longer required, and we can use the generic code everywhere.
In addition the call to figure out whether we need to allocate any extra blocks in order to add a directory entry is moved higher up gfs2_create_inode. This means that if it returns an error, we can deal with that at a stage where it is easier to handle that case. The returned status cannot change during the function since we hold an exclusive lock on the directory.
Two calls to gfs2_rindex_update have been changed to one, again at the top of gfs2_create_inode to simplify error handling.
The time stamps are also now initialised earlier in the creation process, this is gradually moving towards being able to remove the call to gfs2_refresh_inode in gfs2_inode_create once we have all the fields covered.
fs/gfs2/inode.c +37 -62
@@ -392,11 +392,15 @@ static int alloc_dinode(struct gfs2_inode *ip, u32 flags)int error;int dblocks =1 ; - error =gfs2_inplace_reserve (ip,RES_DINODE , flags); + error =gfs2_quota_lock_check (ip);if (error) goto out; - error =gfs2_trans_begin (sdp,RES_RG_BIT +RES_STATFS ,0 ); + error =gfs2_inplace_reserve (ip,RES_DINODE , flags); +if (error) + goto out_quota; + + error =gfs2_trans_begin (sdp,RES_RG_BIT +RES_STATFS +RES_QUOTA ,0 );if (error) goto out_ipreserv;
@@ -409,6 +413,8 @@ static int alloc_dinode(struct gfs2_inode *ip, u32 flags) out_ipreserv:gfs2_inplace_release (ip); +out_quota: +gfs2_quota_unlock (ip); out:return error; }
@@ -445,7 +451,6 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,struct gfs2_sbd *sdp =GFS2_SB (&dip->i_inode);struct gfs2_dinode *di;struct buffer_head *dibh; -struct timespec tv =CURRENT_TIME ; dibh =gfs2_meta_new (ip->i_gl, ip->i_no_addr);gfs2_trans_add_meta (ip->i_gl, dibh);
@@ -461,7 +466,9 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip, di->di_nlink =0 ; di->di_size =cpu_to_be64 (ip->i_inode.i_size); di->di_blocks =cpu_to_be64 (1 ); - di->di_atime = di->di_mtime = di->di_ctime =cpu_to_be64 (tv.tv_sec); + di->di_atime =cpu_to_be64 (ip->i_inode.i_atime.tv_sec); + di->di_mtime =cpu_to_be64 (ip->i_inode.i_mtime.tv_sec); + di->di_ctime =cpu_to_be64 (ip->i_inode.i_ctime.tv_sec); di->di_major =cpu_to_be32 (MAJOR (ip->i_inode.i_rdev)); di->di_minor =cpu_to_be32 (MINOR (ip->i_inode.i_rdev)); di->di_goal_meta = di->di_goal_data =cpu_to_be64 (ip->i_no_addr);
@@ -476,9 +483,9 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip, di->di_entries =0 ;memset (&di->__pad4,0 ,sizeof (di->__pad4)); di->di_eattr =0 ; - di->di_atime_nsec =cpu_to_be32 (tv.tv_nsec); - di->di_mtime_nsec =cpu_to_be32 (tv.tv_nsec); - di->di_ctime_nsec =cpu_to_be32 (tv.tv_nsec); + di->di_atime_nsec =cpu_to_be32 (ip->i_inode.i_atime.tv_nsec); + di->di_mtime_nsec =cpu_to_be32 (ip->i_inode.i_mtime.tv_nsec); + di->di_ctime_nsec =cpu_to_be32 (ip->i_inode.i_ctime.tv_nsec);memset (&di->di_reserved,0 ,sizeof (di->di_reserved));switch (ip->i_inode.i_mode &S_IFMT ) {
@@ -505,58 +512,18 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip, *bhp = dibh; } -static int make_dinode (struct gfs2_inode *dip,struct gfs2_inode *ip, -const char *symname,struct buffer_head **bhp) -{ -struct inode *inode = &ip->i_inode; -struct gfs2_sbd *sdp =GFS2_SB (&dip->i_inode); -int error; - - error =gfs2_rindex_update (sdp); -if (error) -return error; - - error =gfs2_quota_lock (dip, inode->i_uid, inode->i_gid); -if (error) -return error; - - error =gfs2_quota_check (dip, inode->i_uid, inode->i_gid); -if (error) - goto out_quota; - - error =gfs2_trans_begin (sdp,RES_DINODE +RES_QUOTA ,0 ); -if (error) - goto out_quota; - -init_dinode (dip, ip, symname, bhp); -gfs2_quota_change (dip,+1 , inode->i_uid, inode->i_gid); -gfs2_trans_end (sdp); - -out_quota: -gfs2_quota_unlock (dip); -return error; -} -static int link_dinode (struct gfs2_inode *dip,const struct qstr *name, -struct gfs2_inode *ip) +struct gfs2_inode *ip,int arq) {struct gfs2_sbd *sdp =GFS2_SB (&dip->i_inode); -int alloc_required;struct buffer_head *dibh;int error; - error =gfs2_rindex_update (sdp); -if (error) -return error; - error =gfs2_quota_lock (dip,NO_UID_QUOTA_CHANGE ,NO_GID_QUOTA_CHANGE );if (error) - goto fail; +return error; - error = alloc_required =gfs2_diradd_alloc_required (&dip->i_inode, name); -if (alloc_required <0 ) - goto fail_quota_locks; -if (alloc_required) { +if (arq) { error =gfs2_quota_check (dip, dip->i_inode.i_uid, dip->i_inode.i_gid);if (error) goto fail_quota_locks;
@@ -592,15 +559,10 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, fail_end_trans:gfs2_trans_end (sdp); - fail_ipreserv: -if (alloc_required) -gfs2_inplace_release (dip); - +gfs2_inplace_release (dip); fail_quota_locks:gfs2_quota_unlock (dip); - -fail:return error; }
@@ -652,6 +614,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,int error;struct buffer_head *bh =NULL ;u32 aflags =0 ; +int arq;if (!name->len || name->len >GFS2_FNAMESIZE )return -ENAMETOOLONG ;
@@ -660,6 +623,10 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,if (error)return error; + error =gfs2_rindex_update (sdp); +if (error) +return error; + error =gfs2_glock_nq_init (dip->i_gl,LM_ST_EXCLUSIVE ,0 , ghs);if (error) goto fail;
@@ -674,11 +641,15 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,if (error) goto fail_gunlock; + arq = error =gfs2_diradd_alloc_required (dir, name); +if (error <0 ) + goto fail_gunlock; + inode =new_inode (sdp->sd_vfs); -if (!inode) { -gfs2_glock_dq_uninit (ghs); -return -ENOMEM ; - } + error = -ENOMEM ; +if (!inode) + goto fail_gunlock; + ip =GFS2_I (inode); error =gfs2_rs_alloc (ip);if (error)
@@ -688,6 +659,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, inode->i_mode = mode; inode->i_rdev = dev; inode->i_size = size; + inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;munge_mode_uid_gid (dip, inode); ip->i_goal = dip->i_goal;
@@ -708,10 +680,13 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,if (error) goto fail_free_inode; - error =make_dinode (dip, ip, symname, &bh); + error =gfs2_trans_begin (sdp,RES_DINODE ,0 );if (error) goto fail_gunlock2; +init_dinode (dip, ip, symname, &bh); +gfs2_trans_end (sdp); + error =gfs2_glock_get (sdp, ip->i_no_addr, &gfs2_iopen_glops,CREATE , &io_gl);if (error) goto fail_gunlock2;
@@ -737,7 +712,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,if (error) goto fail_gunlock3; - error =link_dinode (dip, name, ip); + error =link_dinode (dip, name, ip, arq);if (error) goto fail_gunlock3;
fs/gfs2/rgrp.c +1 -7
@@ -2180,13 +2180,7 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,if (dinode)gfs2_trans_add_unrevoke (sdp, block,1 ); -/* -* This needs reviewing to see why we cannot do the quota change -* at this point in the dinode case. -*/ -if (ndata) -gfs2_quota_change (ip, ndata, ip->i_inode.i_uid, - ip->i_inode.i_gid); +gfs2_quota_change (ip, *nblocks, ip->i_inode.i_uid, ip->i_inode.i_gid); rbm.rgd->rd_free_clone -= *nblocks; trace_gfs2_block_alloc(ip, rbm.rgd, block, *nblocks,
Signature · 1 line
1.7.4
PATCH 2/8 GFS2: Remove gfs2_refresh_inode from inode creation path
In reply to Steven WhitehouseThe original method for creating inodes used in GFS2 was to fill out a buffer, with all the information, and then to read that buffer into the in-core inode, using gfs2_refresh_inode()
The problem with this approach is that all the inode's fields need to be calculated ahead of time, and were stored in various variables making the code rather complicated.
The new approach is simply to allocate the in-core inode earlier and fill in as many fields as possible ahead of time. These can then be used to initilise the on disk representation. The code has been working towards the point where it is possible to remove gfs2_refresh_inode() because all the fields are correctly initialised ahead of time. We've now reached that milestone, and have reversed the order of setting up the in core and on disk inodes.
fs/gfs2/glock.c +0 -13
@@ -1279,19 +1279,6 @@ void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs)gfs2_glock_dq (&ghs[num_gh]); } -/** -* gfs2_glock_dq_uninit_m - release multiple glocks -* @num_gh: the number of structures -* @ghs: an array of struct gfs2_holder structures -* -*/ - -void gfs2_glock_dq_uninit_m (unsigned int num_gh,struct gfs2_holder *ghs) -{ -while (num_gh--) -gfs2_glock_dq_uninit (&ghs[num_gh]); -} -void gfs2_glock_cb (struct gfs2_glock *gl,unsigned int state) {unsigned long delay =0 ;
fs/gfs2/glock.h +0 -1
@@ -201,7 +201,6 @@ extern int gfs2_glock_nq_num(struct gfs2_sbd *sdp, u64 number, struct gfs2_holder *gh);extern int gfs2_glock_nq_m (unsigned int num_gh,struct gfs2_holder *ghs);extern void gfs2_glock_dq_m (unsigned int num_gh,struct gfs2_holder *ghs); -extern void gfs2_glock_dq_uninit_m (unsigned int num_gh,struct gfs2_holder *ghs);extern int gfs2_dump_glock (struct seq_file *seq,const struct gfs2_glock *gl);#define GLOCK_BUG_ON (gl,x) do { if (unlikely(x)) { gfs2_dump_glock(NULL, gl); BUG(); } } while(0) extern __printf(2, 3)
fs/gfs2/inode.c +35 -44
155 lines not on this page · raw message
Signature · 1 line
1.7.4
PATCH 3/8 GFS2: Use gfs2_dinode_out() in the inode create path
In reply to Steven WhitehouseOver the previous two patches relating to inode creation, the content of init_dinode() has been looking more and more like gfs2_dinode_out(). This is not an accident! This patch replaces the parts of init_dinode() which are duplicated in gfs2_dinode_out() with a call to that function.
Mostly that is straightforward, but there is one issue which needed to be resolved relating to the link count. The link count has to be set to zero in a certain error handling code path, which lands up calling iput(). This is now done specifically in that code path allowing the link count to be set earlier and written into the on disk inode by gfs2_dinode_put() in the normal way.
fs/gfs2/inode.c +9 -35
@@ -446,46 +446,24 @@ static void gfs2_init_dir(struct buffer_head *dibh,*/ static void init_dinode (struct gfs2_inode *dip,struct gfs2_inode *ip, -const char *symname,struct buffer_head **bhp) +const char *symname) {struct gfs2_dinode *di;struct buffer_head *dibh; dibh =gfs2_meta_new (ip->i_gl, ip->i_no_addr);gfs2_trans_add_meta (ip->i_gl, dibh); -gfs2_metatype_set (dibh,GFS2_METATYPE_DI ,GFS2_FORMAT_DI ); -gfs2_buffer_clear_tail (dibh,sizeof (struct gfs2_dinode )); di = (struct gfs2_dinode *)dibh->b_data; +gfs2_dinode_out (ip, di); - di->di_num.no_formal_ino =cpu_to_be64 (ip->i_no_formal_ino); - di->di_num.no_addr =cpu_to_be64 (ip->i_no_addr); - di->di_mode =cpu_to_be32 (ip->i_inode.i_mode); - di->di_uid =cpu_to_be32 (i_uid_read (&ip->i_inode)); - di->di_gid =cpu_to_be32 (i_gid_read (&ip->i_inode)); - di->di_nlink =0 ; - di->di_size =cpu_to_be64 (ip->i_inode.i_size); - di->di_blocks =cpu_to_be64 (gfs2_get_inode_blocks (&ip->i_inode)); - di->di_atime =cpu_to_be64 (ip->i_inode.i_atime.tv_sec); - di->di_mtime =cpu_to_be64 (ip->i_inode.i_mtime.tv_sec); - di->di_ctime =cpu_to_be64 (ip->i_inode.i_ctime.tv_sec); di->di_major =cpu_to_be32 (MAJOR (ip->i_inode.i_rdev)); di->di_minor =cpu_to_be32 (MINOR (ip->i_inode.i_rdev)); - di->di_goal_meta = di->di_goal_data =cpu_to_be64 (ip->i_no_addr); - di->di_generation =cpu_to_be64 (ip->i_generation); - di->di_flags =cpu_to_be32 (ip->i_diskflags); di->__pad1 =0 ; - di->di_payload_format =cpu_to_be32 (S_ISDIR (ip->i_inode.i_mode) ?GFS2_FORMAT_DE :0 ); - di->di_height =cpu_to_be16 (ip->i_height); di->__pad2 =0 ; di->__pad3 =0 ; - di->di_depth =cpu_to_be16 (ip->i_depth); - di->di_entries =cpu_to_be32 (ip->i_entries);memset (&di->__pad4,0 ,sizeof (di->__pad4)); - di->di_eattr =cpu_to_be64 (ip->i_eattr); - di->di_atime_nsec =cpu_to_be32 (ip->i_inode.i_atime.tv_nsec); - di->di_mtime_nsec =cpu_to_be32 (ip->i_inode.i_mtime.tv_nsec); - di->di_ctime_nsec =cpu_to_be32 (ip->i_inode.i_ctime.tv_nsec);memset (&di->di_reserved,0 ,sizeof (di->di_reserved)); +gfs2_buffer_clear_tail (dibh,sizeof (struct gfs2_dinode ));switch (ip->i_inode.i_mode &S_IFMT ) {case S_IFDIR :
@@ -497,8 +475,7 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip, }set_buffer_uptodate (dibh); - - *bhp = dibh; +brelse (dibh); } static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
@@ -532,9 +509,6 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,if (error) goto fail_end_trans; -set_nlink (&ip->i_inode,S_ISDIR (ip->i_inode.i_mode) ?2 :1 ); -mark_inode_dirty (&ip->i_inode); - fail_end_trans:gfs2_trans_end (sdp); fail_ipreserv:
@@ -590,7 +564,6 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,struct gfs2_sbd *sdp =GFS2_SB (&dip->i_inode);struct gfs2_glock *io_gl;int error; -struct buffer_head *bh =NULL ;u32 aflags =0 ;int arq;
@@ -634,6 +607,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, goto fail_free_inode; inode->i_mode = mode; +set_nlink (inode,S_ISDIR (mode) ?2 :1 ); inode->i_rdev = dev; inode->i_size = size; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;
@@ -682,7 +656,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,if (error) goto fail_gunlock2; -init_dinode (dip, ip, symname, &bh); +init_dinode (dip, ip, symname);gfs2_trans_end (sdp); error =gfs2_glock_get (sdp, ip->i_no_addr, &gfs2_iopen_glops,CREATE , &io_gl);
@@ -710,7 +684,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,if (error) goto fail_gunlock3; -brelse (bh); +mark_inode_dirty (inode);gfs2_glock_dq_uninit (ghs);gfs2_glock_dq_uninit (ghs +1 );d_instantiate (dentry, inode);
@@ -733,12 +707,12 @@ fail_free_inode: fail_gunlock:gfs2_glock_dq_uninit (ghs);if (inode && !IS_ERR (inode)) { +clear_nlink (inode); +mark_inode_dirty (inode);set_bit (GIF_ALLOC_FAILED , &GFS2_I (inode)->i_flags);iput (inode); } fail: -if (bh) -brelse (bh);return error; }
Signature · 1 line
1.7.4
PATCH 4/8 GFS2: Remove vestigial parameter ip from function rs_deltree
In reply to Steven WhitehouseFrom: Bob Peterson <[email protected]>
The functions that delete block reservations from the rgrp block reservations rbtree no longer use the ip parameter. This patch eliminates the parameter.
fs/gfs2/bmap.c +1 -1
@@ -787,7 +787,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, goto out_rlist;if (gfs2_rs_active (ip->i_res))/* needs to be done with the rgrp glock held */ -gfs2_rs_deltree (ip, ip->i_res); +gfs2_rs_deltree (ip->i_res); error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + RES_INDIRECT + RES_STATFS + RES_QUOTA,
fs/gfs2/rgrp.c +8 -8
@@ -592,7 +592,7 @@ static void dump_rs(struct seq_file *seq, const struct gfs2_blkreserv *rs)* @rs: The reservation to remove * */ -static void __rs_deltree (struct gfs2_inode *ip,struct gfs2_blkreserv *rs) +static void __rs_deltree (struct gfs2_blkreserv *rs) {struct gfs2_rgrpd *rgd;
@@ -605,7 +605,7 @@ static void __rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs)RB_CLEAR_NODE (&rs->rs_node);if (rs->rs_free) { -/* return reserved blocks to the rgrp and the ip */ +/* return reserved blocks to the rgrp */ BUG_ON (rs->rs_rbm.rgd->rd_reserved < rs->rs_free); rs->rs_rbm.rgd->rd_reserved -= rs->rs_free; rs->rs_free =0 ;
@@ -619,14 +619,14 @@ static void __rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs)* @rs: The reservation to remove * */ -void gfs2_rs_deltree (struct gfs2_inode *ip,struct gfs2_blkreserv *rs) +void gfs2_rs_deltree (struct gfs2_blkreserv *rs) {struct gfs2_rgrpd *rgd; rgd = rs->rs_rbm.rgd;if (rgd) {spin_lock (&rgd->rd_rsspin); -__rs_deltree (ip, rs); +__rs_deltree (rs);spin_unlock (&rgd->rd_rsspin); } }
@@ -640,7 +640,7 @@ void gfs2_rs_delete(struct gfs2_inode *ip) {down_write (&ip->i_rw_mutex);if (ip->i_res) { -gfs2_rs_deltree (ip, ip->i_res); +gfs2_rs_deltree (ip->i_res);BUG_ON (ip->i_res->rs_free);kmem_cache_free (gfs2_rsrv_cachep, ip->i_res); ip->i_res =NULL ;
@@ -664,7 +664,7 @@ static void return_all_reservations(struct gfs2_rgrpd *rgd)spin_lock (&rgd->rd_rsspin);while ((n =rb_first (&rgd->rd_rstree))) { rs = rb_entry(n, struct gfs2_blkreserv, rs_node); -__rs_deltree (NULL , rs); +__rs_deltree (rs); }spin_unlock (&rgd->rd_rsspin); }
@@ -1874,7 +1874,7 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested, u32 aflags)/* Drop reservation, if we couldn't use reserved rgrp */ if (gfs2_rs_active (rs)) -gfs2_rs_deltree (ip, rs); +gfs2_rs_deltree (rs); check_rgrp:/* Check for unlinked inodes which can be reclaimed */ if (rs->rs_rbm.rgd->rd_flags &GFS2_RDF_CHECK )
@@ -2087,7 +2087,7 @@ static void gfs2_adjust_reservation(struct gfs2_inode *ip,if (rs->rs_free && !ret) goto out; } -__rs_deltree (ip, rs); +__rs_deltree (rs); } out:spin_unlock (&rgd->rd_rsspin);
fs/gfs2/rgrp.h +1 -1
@@ -47,7 +47,7 @@ extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n, bool dinode, u64 *generation);extern int gfs2_rs_alloc (struct gfs2_inode *ip); -extern void gfs2_rs_deltree (struct gfs2_inode *ip,struct gfs2_blkreserv *rs); +extern void gfs2_rs_deltree (struct gfs2_blkreserv *rs);extern void gfs2_rs_delete (struct gfs2_inode *ip);extern void __gfs2_free_blocks (struct gfs2_inode *ip,u64 bstart,u32 blen,int meta);extern void gfs2_free_meta (struct gfs2_inode *ip,u64 bstart,u32 blen);
fs/gfs2/super.c +1 -1
@@ -1512,7 +1512,7 @@ out_truncate: out_unlock:/* Error path for case 1 */ if (gfs2_rs_active (ip->i_res)) -gfs2_rs_deltree (ip, ip->i_res); +gfs2_rs_deltree (ip->i_res);if (test_bit (HIF_HOLDER , &ip->i_iopen_gh.gh_iflags))gfs2_glock_dq (&ip->i_iopen_gh);
Signature · 1 line
1.7.4
PATCH 5/8 GFS2: replace gfs2_ail structure with gfs2_trans
In reply to Steven WhitehouseFrom: Benjamin Marzinski <[email protected]>
In order to allow transactions and log flushes to happen at the same time, gfs2 needs to move the transaction accounting and active items list code into the gfs2_trans structure. As a first step toward this, this patch removes the gfs2_ail structure, and handles the active items list in the gfs_trans structure. This keeps gfs2 from allocating an ail structure on log flushes, and gives us a struture that can later be used to store the transaction accounting outside of the gfs2 superblock structure.
With this patch, at the end of a transaction, gfs2 will add the gfs2_trans structure to the superblock if there is not one already. This structure now has the active items fields that were previously in gfs2_ail. This is not necessary in the case where the transaction was simply used to add revokes, since these are never written outside of the journal, and thus, don't need an active items list.
Also, in order to make sure that the transaction structure is not removed while it's still in use by gfs2_trans_end, unlocking the sd_log_flush_lock has to happen slightly later in ending the transaction.
fs/gfs2/aops.c +1 -1
@@ -1055,7 +1055,7 @@ int gfs2_releasepage(struct page *page, gfp_t gfp_mask)if (atomic_read (&bh->b_count)) goto cannot_release; bd = bh->b_private; -if (bd && bd->bd_ail) +if (bd && bd->bd_tr) goto cannot_release;if (buffer_pinned (bh) ||buffer_dirty (bh)) goto not_possible;
fs/gfs2/incore.h +8 -9
@@ -31,7 +31,6 @@ struct gfs2_holder;struct gfs2_glock ;struct gfs2_quota_data ;struct gfs2_trans ; -struct gfs2_ail ;struct gfs2_jdesc ;struct gfs2_sbd ;struct lm_lockops ;
@@ -53,7 +52,7 @@ struct gfs2_log_header_host {struct gfs2_log_operations {void (*lo_before_commit) (struct gfs2_sbd *sdp); -void (*lo_after_commit) (struct gfs2_sbd *sdp,struct gfs2_ail *ai); +void (*lo_after_commit) (struct gfs2_sbd *sdp,struct gfs2_trans *tr);void (*lo_before_scan) (struct gfs2_jdesc *jd,struct gfs2_log_header_host *head,int pass); int (*lo_scan_elements) (struct gfs2_jdesc *jd, unsigned int start,
@@ -139,7 +138,7 @@ struct gfs2_bufdata {struct list_head bd_list;const struct gfs2_log_operations *bd_ops; -struct gfs2_ail *bd_ail; +struct gfs2_trans *bd_tr;struct list_head bd_ail_st_list;struct list_head bd_ail_gl_list; };
@@ -433,6 +432,7 @@ struct gfs2_trans {struct gfs2_holder tr_t_gh;int tr_touched; +int tr_attached;unsigned int tr_num_buf_new;unsigned int tr_num_databuf_new;
@@ -440,14 +440,12 @@ struct gfs2_trans {unsigned int tr_num_databuf_rm;unsigned int tr_num_revoke;unsigned int tr_num_revoke_rm; -}; -struct gfs2_ail { -struct list_head ai_list; +struct list_head tr_list; -unsigned int ai_first; -struct list_head ai_ail1_list; -struct list_head ai_ail2_list; +unsigned int tr_first; +struct list_head tr_ail1_list; +struct list_head tr_ail2_list; };struct gfs2_journal_extent {
@@ -710,6 +708,7 @@ struct gfs2_sbd {spinlock_t sd_log_lock; +struct gfs2_trans *sd_log_tr;unsigned int sd_log_blks_reserved;unsigned int sd_log_commited_buf;unsigned int sd_log_commited_databuf;
fs/gfs2/log.c +57 -47
269 lines not on this page · raw message
fs/gfs2/lops.c +21 -11
@@ -53,8 +53,8 @@ void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh)* to in-place disk block, remove it from the AIL. */ spin_lock (&sdp->sd_ail_lock); -if (bd->bd_ail) -list_move (&bd->bd_ail_st_list, &bd->bd_ail->ai_ail2_list); +if (bd->bd_tr) +list_move (&bd->bd_ail_st_list, &bd->bd_tr->tr_ail2_list);spin_unlock (&sdp->sd_ail_lock);get_bh (bh);atomic_inc (&sdp->sd_log_pinned);
@@ -94,7 +94,7 @@ static void maybe_release_space(struct gfs2_bufdata *bd)*/ static void gfs2_unpin (struct gfs2_sbd *sdp,struct buffer_head *bh, -struct gfs2_ail *ai) +struct gfs2_trans *tr) {struct gfs2_bufdata *bd = bh->b_private;
@@ -109,7 +109,7 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,maybe_release_space (bd);spin_lock (&sdp->sd_ail_lock); -if (bd->bd_ail) { +if (bd->bd_tr) {list_del (&bd->bd_ail_st_list);brelse (bh); }else {
@@ -117,8 +117,8 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,list_add (&bd->bd_ail_gl_list, &gl->gl_ail_list);atomic_inc (&gl->gl_ail_count); } - bd->bd_ail = ai; -list_add (&bd->bd_ail_st_list, &ai->ai_ail1_list); + bd->bd_tr = tr; +list_add (&bd->bd_ail_st_list, &tr->tr_ail1_list);spin_unlock (&sdp->sd_ail_lock);clear_bit (GLF_LFLUSH , &bd->bd_gl->gl_flags);
@@ -480,17 +480,22 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp) &sdp->sd_log_le_buf, 0); } -static void buf_lo_after_commit (struct gfs2_sbd *sdp,struct gfs2_ail *ai) +static void buf_lo_after_commit (struct gfs2_sbd *sdp,struct gfs2_trans *tr) {struct list_head *head = &sdp->sd_log_le_buf;struct gfs2_bufdata *bd; +if (tr ==NULL ) { +gfs2_assert (sdp,list_empty (head)); +return ; + } +while (!list_empty (head)) { bd = list_entry(head->next, struct gfs2_bufdata, bd_list);list_del_init (&bd->bd_list); sdp->sd_log_num_buf--; -gfs2_unpin (sdp, bd->bd_bh, ai); +gfs2_unpin (sdp, bd->bd_bh, tr); }gfs2_assert_warn (sdp, !sdp->sd_log_num_buf); }
@@ -613,7 +618,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp)gfs2_log_write_page (sdp, page); } -static void revoke_lo_after_commit (struct gfs2_sbd *sdp,struct gfs2_ail *ai) +static void revoke_lo_after_commit (struct gfs2_sbd *sdp,struct gfs2_trans *tr) {struct list_head *head = &sdp->sd_log_le_revoke;struct gfs2_bufdata *bd;
@@ -791,16 +796,21 @@ static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); } -static void databuf_lo_after_commit (struct gfs2_sbd *sdp,struct gfs2_ail *ai) +static void databuf_lo_after_commit (struct gfs2_sbd *sdp,struct gfs2_trans *tr) {struct list_head *head = &sdp->sd_log_le_databuf;struct gfs2_bufdata *bd; +if (tr ==NULL ) { +gfs2_assert (sdp,list_empty (head)); +return ; + } +while (!list_empty (head)) { bd = list_entry(head->next, struct gfs2_bufdata, bd_list);list_del_init (&bd->bd_list); sdp->sd_log_num_databuf--; -gfs2_unpin (sdp, bd->bd_bh, ai); +gfs2_unpin (sdp, bd->bd_bh, tr); }gfs2_assert_warn (sdp, !sdp->sd_log_num_databuf); }
fs/gfs2/lops.h +3 -2
@@ -55,12 +55,13 @@ static inline void lops_before_commit(struct gfs2_sbd *sdp) gfs2_log_ops[x]->lo_before_commit (sdp); } -static inline void lops_after_commit (struct gfs2_sbd *sdp,struct gfs2_ail *ai) +static inline void lops_after_commit (struct gfs2_sbd *sdp, +struct gfs2_trans *tr) {int x;for (x =0 ; gfs2_log_ops[x]; x++)if (gfs2_log_ops[x]->lo_after_commit) - gfs2_log_ops[x]->lo_after_commit (sdp, ai); + gfs2_log_ops[x]->lo_after_commit (sdp, tr); } static inline void lops_before_scan(struct gfs2_jdesc *jd,
fs/gfs2/meta_io.c +1 -1
@@ -295,7 +295,7 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int }if (bd) {spin_lock (&sdp->sd_ail_lock); -if (bd->bd_ail) { +if (bd->bd_tr) {gfs2_remove_from_ail (bd); bh->b_private =NULL ; bd->bd_bh =NULL ;
fs/gfs2/trans.c +3 -1
@@ -135,8 +135,10 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)if (tr->tr_t_gh.gh_gl) {gfs2_glock_dq (&tr->tr_t_gh);gfs2_holder_uninit (&tr->tr_t_gh); -kfree (tr); +if (!tr->tr_attached) +kfree (tr); } +up_read (&sdp->sd_log_flush_lock);if (sdp->sd_vfs->s_flags &MS_SYNCHRONOUS )gfs2_log_flush (sdp,NULL );
Signature · 1 line
1.7.4
PATCH 6/8 GFS2: Add origin indicator to glock callbacks
In reply to Steven WhitehouseThis patch adds a bool indicating whether the demote request was originated locally or remotely. This is then used by the iopen ->go_callback() to make 100% sure that it will only respond to remote callbacks.
Since ->evict_inode() uses GL_NOCACHE when it attempts to get an exclusive lock on the iopen lock, this may result in extra scheduling of the workqueue in case that the exclusive promotion request failed. This patch prevents that from happening.
fs/gfs2/glock.c +6 -6
@@ -912,7 +912,7 @@ int gfs2_glock_wait(struct gfs2_holder *gh)*/ static void handle_callback (struct gfs2_glock *gl,unsigned int state, -unsigned long delay) +unsigned long delay,bool remote) {int bit = delay ?GLF_PENDING_DEMOTE :GLF_DEMOTE ;
@@ -925,7 +925,7 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state, gl->gl_demote_state =LM_ST_UNLOCKED ; }if (gl->gl_ops->go_callback) - gl->gl_ops->go_callback (gl); + gl->gl_ops->go_callback (gl, remote);trace_gfs2_demote_rq (gl); }
@@ -1091,7 +1091,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh)spin_lock (&gl->gl_spin);if (gh->gh_flags &GL_NOCACHE ) -handle_callback (gl,LM_ST_UNLOCKED ,0 ); +handle_callback (gl,LM_ST_UNLOCKED ,0 , false);list_del_init (&gh->gh_list);if (find_first_holder (gl) ==NULL ) {
@@ -1296,7 +1296,7 @@ void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state) }spin_lock (&gl->gl_spin); -handle_callback (gl, state, delay); +handle_callback (gl, state, delay, true);spin_unlock (&gl->gl_spin);if (queue_delayed_work (glock_workqueue, &gl->gl_work, delay) ==0 )gfs2_glock_put (gl);
@@ -1409,7 +1409,7 @@ __acquires(&lru_lock)spin_unlock (&lru_lock);spin_lock (&gl->gl_spin);if (demote_ok (gl)) -handle_callback (gl,LM_ST_UNLOCKED ,0 ); +handle_callback (gl,LM_ST_UNLOCKED ,0 , false);WARN_ON (!test_and_clear_bit (GLF_LOCK , &gl->gl_flags));smp_mb__after_clear_bit ();if (queue_delayed_work (glock_workqueue, &gl->gl_work,0 ) ==0 )
@@ -1534,7 +1534,7 @@ static void clear_glock(struct gfs2_glock *gl)spin_lock (&gl->gl_spin);if (gl->gl_state !=LM_ST_UNLOCKED ) -handle_callback (gl,LM_ST_UNLOCKED ,0 ); +handle_callback (gl,LM_ST_UNLOCKED ,0 , false);spin_unlock (&gl->gl_spin);gfs2_glock_hold (gl);if (queue_delayed_work (glock_workqueue, &gl->gl_work,0 ) ==0 )
fs/gfs2/glops.c +2 -2
@@ -515,12 +515,12 @@ static int trans_go_demote_ok(const struct gfs2_glock *gl)* * gl_spin lock is held while calling this */ -static void iopen_go_callback (struct gfs2_glock *gl) +static void iopen_go_callback (struct gfs2_glock *gl,bool remote) {struct gfs2_inode *ip = (struct gfs2_inode *)gl->gl_object;struct gfs2_sbd *sdp = gl->gl_sbd; -if (sdp->sd_vfs->s_flags &MS_RDONLY ) +if (!remote || (sdp->sd_vfs->s_flags &MS_RDONLY ))return ; if (gl->gl_demote_state == LM_ST_UNLOCKED &&
fs/gfs2/incore.h +1 -1
@@ -210,7 +210,7 @@ struct gfs2_glock_operations {int (*go_lock) (struct gfs2_holder *gh);void (*go_unlock) (struct gfs2_holder *gh);int (*go_dump)(struct seq_file *seq,const struct gfs2_glock *gl); -void (*go_callback) (struct gfs2_glock *gl); +void (*go_callback)(struct gfs2_glock *gl,bool remote);const int go_type;const unsigned long go_flags;#define GLOF_ASPACE 1
Signature · 1 line
1.7.4
PATCH 7/8 GFS2: Add origin indicator to glock demote tracing
In reply to Steven WhitehouseThis adds the origin indicator to the trace point for glock demotion, so that it is possible to see where demote requests have come from.
Note that requests generated from the demote_rq sysfs interface will show as remote, since they are intended to replicate exactly the effect of a demote reuqest from a remote node. It is still possible to tell these apart by looking at the process which initiated the demote request.
fs/gfs2/glock.c +1 -1
@@ -926,7 +926,7 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state, }if (gl->gl_ops->go_callback) gl->gl_ops->go_callback (gl, remote); -trace_gfs2_demote_rq (gl); +trace_gfs2_demote_rq (gl, remote); }void gfs2_print_dbg (struct seq_file *seq,const char *fmt, ...)
fs/gfs2/trace_gfs2.h +7 -4
@@ -159,9 +159,9 @@ TRACE_EVENT(gfs2_glock_put,/* Callback (local or remote) requesting lock demotion */ TRACE_EVENT(gfs2_demote_rq, - TP_PROTO(const struct gfs2_glock *gl), + TP_PROTO(const struct gfs2_glock *gl, bool remote), - TP_ARGS(gl), + TP_ARGS(gl, remote), TP_STRUCT__entry( __field( dev_t, dev )
@@ -170,6 +170,7 @@ TRACE_EVENT(gfs2_demote_rq, __field( u8, cur_state ) __field( u8, dmt_state ) __field( unsigned long, flags ) +__field (bool , remote ) ), TP_fast_assign(
@@ -179,14 +180,16 @@ TRACE_EVENT(gfs2_demote_rq, __entry->cur_state =glock_trace_state (gl->gl_state); __entry->dmt_state =glock_trace_state (gl->gl_demote_state); __entry->flags = gl->gl_flags | (gl->gl_object ? (1UL <<GLF_OBJECT ) :0 ); + __entry->remote = remote; ), -TP_printk ("%u,%u glock %d:%lld demote %s to %s flags:%s" , +TP_printk ("%u,%u glock %d:%lld demote %s to %s flags:%s %s" ,MAJOR (__entry->dev),MINOR (__entry->dev), __entry->gltype, (unsigned long long )__entry->glnum,glock_trace_name (__entry->cur_state),glock_trace_name (__entry->dmt_state), -show_glock_flags (__entry->flags)) +show_glock_flags (__entry->flags), + __entry->remote ?"remote" :"local" ) );
Signature · 1 line
1.7.4
PATCH 8/8 GFS2: Flush work queue before clearing glock hash tables
In reply to Steven WhitehouseFrom: Bob Peterson <[email protected]>
There was a timing window when a GFS2 file system was unmounted that caused GFS2 to call BUG() and panic the kernel. The call to BUG() is meant to ensure that the glock reference count, gl_ref, never gets down to zero and bounce back up again. What was happening during umount is that function gfs2_put_super was dequeing its glocks for well-known files. In particular, we saw it on the journal glock, sd_jinode_gh. The dequeue caused delayed work to be queued for the glock state machine, to transition the lock to an "unlocked" state. While the work was still queued, gfs2_put_super called gfs2_gl_hash_clear to clear out the glock hash tables. If the timing was just so, the glock work function would drop the reference count at the time when it was being checked for zero, and that caused BUG() to be called. This patch calls flush_workqueue before clearing the glock hash tables, thereby ensuring that the delayed work is executed before the hash tables are cleared, and therefore the reference count never goes to zero until the glock is cleared.
fs/gfs2/glock.c +1 -0
@@ -1577,6 +1577,7 @@ static void dump_glock_func(struct gfs2_glock *gl)void gfs2_gl_hash_clear (struct gfs2_sbd *sdp) {set_bit (SDF_SKIP_DLM_UNLOCK , &sdp->sd_flags); +flush_workqueue (glock_workqueue);glock_hash_walk (clear_glock, sdp);flush_workqueue (glock_workqueue);wait_event (sdp->sd_glock_wait,atomic_read (&sdp->sd_glock_disposal) ==0 );
Signature · 1 line
1.7.4