gfs2: non-recursive delete
PATCH 1/1 gfs2: non-recursive delete
In reply to a message not in the archiveHi,
This is my latest implementation of non-recursive delete for RHEL7 (upstream should be nearly the same).
The algorithm has undergone massive changes since I last posted it.
One of the key concepts here is to free affected blocks one RGRP at a time so that while a delete is going on, only one rgrp glock is tied up, thus allowing all other processes in the file system to run better and faster.
The idea here is to process the lowest height of metadata, the inode, and build a linked list of metadata buffers. Then, traverse each buffer finding the first rgrp pointed to by that buffer. We lock the glock for that rgrp. Then, for all buffers in the list, we look for references to that rgrp, and remove them in spans. If a buffer references *ONLY* that rgrp, it's removed from the list. Then the process repeats starting with the first buffer that hasn't been completely cleaned of all rgrp references.
This way, we can keep only a single rgrp locked at one time, thus allowing other processes to allocate and use the others. We also need to allocate fewer blocks in the journal each iteration, allowing us to delete very large files in smaller chunks, which turns out to be more efficient.
WARNING: This algorithm seems to work, and work efficiently, even when done in parallel on up to six nodes, but it seems to cause file system corruption if given enough pressure. All the right locks are taken in all the right places, so I fail to see the cause of the corruption. The corruption is: Every once in a while, dinodes seem to magically disappear and get:
GFS2: fsid=afc_cluster:work.3: fatal: invalid metadata block
GFS2: fsid=afc_cluster:work.3: bh = 71412755 (magic number) == 0x441ac13
GFS2: fsid=afc_cluster:work.3: function = gfs2_meta_indirect_buffer, file = fs/gfs2/meta_io.c, line = 431
If anyone can spot problems with the patch, I'd appreciate it.
---
fs/gfs2/bmap.c +381 -202
@@ -19,6 +19,7 @@#include "bmap.h" #include "glock.h" #include "inode.h" +#include "log.h" #include "meta_io.h" #include "quota.h" #include "rgrp.h"
@@ -29,6 +30,8 @@#include "util.h" #include "trace_gfs2.h" +#define MAX_BH_RGRP_MISSES 3 +/* This doesn't need to be that large as max 64 bit pointers in a 4k * block is 512, so __u16 is fine for that. It saves stack space to * keep it small.
@@ -38,9 +41,9 @@ struct metapath {__u16 mp_list[GFS2_MAX_META_HEIGHT ]; }; -struct strip_mine { -int sm_first; -unsigned int sm_height; +struct gfs2_buflist { +struct list_head bl_list; +struct buffer_head *bl_bh; };/**
@@ -700,58 +703,43 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsireturn ret; } -/** -* do_strip - Look for a layer a particular layer of the file and strip it off -* @ip: the inode -* @dibh: the dinode buffer -* @bh: A buffer of pointers -* @top: The first pointer in the buffer -* @bottom: One more than the last pointer -* @height: the height this buffer is at -* @data: a pointer to a struct strip_mine +/* +* free_for_rgrp - free all blocks inside the rgrp * -* Returns: errno +* Returns: error +* 0 - All is well, keep processing buffers +* -ENOENT - No references to this rgrp in this buffer. +* -EAGAIN - We filled up our transaction. Close it and loop again. +* Or other error */ - -static int do_strip (struct gfs2_inode *ip,struct buffer_head *dibh, -struct buffer_head *bh,__be64 *top,__be64 *bottom, -unsigned int height,struct strip_mine *sm) +/* static */ +noinline +int free_for_rgrp(struct gfs2_inode *ip, struct metapath *mp, int h, +struct gfs2_buflist *cur,int del_all,int first, +struct gfs2_rgrpd *rgd,int *jblocks_left, +int *freed) { +struct buffer_head *bh;struct gfs2_sbd *sdp =GFS2_SB (&ip->i_inode); -struct gfs2_rgrp_list rlist; -struct gfs2_trans *tr; -u64 bn, bstart; -u32 blen, btotal; -__be64 *p; -unsigned int rg_blocks =0 ; -int metadata; -unsigned int revokes =0 ; -int x; -int error; -int jblocks_rqsted; - - error =gfs2_rindex_update (sdp); -if (error) -return error; - -if (!*top) - sm->sm_first =0 ; - -if (height != sm->sm_height) -return 0 ; - -if (sm->sm_first) { - top++; - sm->sm_first =0 ; +__be64 *p, *top, *bottom; +int meta, error =0 ; +u64 bn, bstart =0 ; +s64 blen =0 ; +bool bh_added_to_trans = false; + + bh = cur->bl_bh; + bh_added_to_trans = false; +if (h ==0 ) { + top = (__be64 *)(bh->b_data +sizeof (struct gfs2_dinode )); + bottom = top + sdp->sd_diptrs; + top += mp->mp_list[0 ]; + }else { + top = (__be64 *)(bh->b_data +sizeof (struct gfs2_meta_header )); + bottom = top + sdp->sd_inptrs; +if (first) + top += mp->mp_list[h]; } - - metadata = (height != ip->i_height -1 ); -if (metadata) - revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs; -else if (ip->i_depth) - revokes = sdp->sd_inptrs; - -memset (&rlist,0 ,sizeof (struct gfs2_rgrp_list )); + meta = (h != ip->i_height -1 ); bstart =0 ; blen =0 ;
@@ -760,188 +748,389 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,continue ; bn =be64_to_cpu (*p); +if (!rgrp_contains_block (rgd, bn)) +continue ; +if (!bh_added_to_trans) { +BUG_ON (*jblocks_left ==0 ); + (*jblocks_left)--; +/* If last meta block for the transaction, return +-EAGAIN to make it end the current transaction and +start a new one. */ +if (*jblocks_left ==0 ) + error = -EAGAIN ; + +gfs2_trans_add_meta (ip->i_gl, bh); + bh_added_to_trans = true; + } + *p =0 ; -if (bstart + blen == bn) +if (bstart + blen == bn) { blen++; -else { -if (bstart) -gfs2_rlist_add (ip, &rlist, bstart); - - bstart = bn; - blen =1 ; +continue ; + } +if (bstart) { +__gfs2_free_blocks (ip, bstart, (u32 )blen, meta); + (*freed) += blen; +gfs2_add_inode_blocks (&ip->i_inode, -blen); } - } - -if (bstart) -gfs2_rlist_add (ip, &rlist, bstart); -else - goto out;/* Nothing to do */ - -gfs2_rlist_alloc (&rlist,LM_ST_EXCLUSIVE ); -for (x =0 ; x < rlist.rl_rgrps; x++) { -struct gfs2_rgrpd *rgd; - rgd = rlist.rl_ghs[x].gh_gl->gl_object; - rg_blocks += rgd->rd_length; + bstart = bn; + blen =1 ; } +if (bstart) { +__gfs2_free_blocks (ip, bstart, (u32 )blen, meta); + (*freed) += blen; +gfs2_add_inode_blocks (&ip->i_inode, -blen); + } +if (!bh_added_to_trans)/* no hits? */ + error = -ENOENT ; +return error; +} - error =gfs2_glock_nq_m (rlist.rl_rgrps, rlist.rl_ghs); -if (error) - goto out_rlist; - -if (gfs2_rs_active (&ip->i_res))/* needs to be done with the rgrp glock held */ -gfs2_rs_deltree (&ip->i_res); - -restart: - jblocks_rqsted = rg_blocks +RES_DINODE + -RES_INDIRECT +RES_STATFS +RES_QUOTA + -gfs2_struct2blk (sdp, revokes,sizeof (u64)); -if (jblocks_rqsted >atomic_read (&sdp->sd_log_thresh2)) - jblocks_rqsted =atomic_read (&sdp->sd_log_thresh2); - error =gfs2_trans_begin (sdp, jblocks_rqsted, revokes); -if (error) - goto out_rg_gunlock; - - tr = current->journal_info; -down_write (&ip->i_rw_mutex); - -gfs2_trans_add_meta (ip->i_gl, dibh); -gfs2_trans_add_meta (ip->i_gl, bh); - - bstart =0 ; - blen =0 ; - btotal =0 ; - +/* process_buf - process a buffer with pointers +* +* This function examines a buffer from top to bottom, looking for a +* non-zero block pointer. From that it extrapolates its corresponding rgrp. +* Then it proceeds to free all buffers in the list (starting with head) +* that reference the same rgrp. +* +* Returns: -ENOENT - The buffer is devoid of rgrps +* 0 - We freed all blocks from the given rgrp +* Other error has occurred +* Sets: remblks - remaining blocks in this buffer that aren't in rgrp +*/ +/* static */ +noinline +int process_buf(struct gfs2_inode *ip, struct metapath *mp, int h, +struct gfs2_buflist *cur,struct list_head *head,int del_all, +int buflist_mallocs,u32 *freed,int first,u32 *remblks) +{ +struct gfs2_sbd *sdp =GFS2_SB (&ip->i_inode); +struct gfs2_rgrpd *rgd =NULL ; +struct gfs2_holder gh; +struct gfs2_buflist *pos, *n; +u64 bn; +__be64 *p, *top, *bottom; +unsigned int jblocks_rqsted, jblocks_left, max_meta; +int miss_count =0 , hit_count =0 ; +int error = -ENOENT ; + + *remblks =0 ; +if (h ==0 ) { + top = (__be64 *)(cur->bl_bh->b_data +sizeof (struct gfs2_dinode )); + bottom = top + sdp->sd_diptrs; + top += mp->mp_list[0 ]; + }else { + top = (__be64 *)(cur->bl_bh->b_data +sizeof (struct gfs2_meta_header )); + bottom = top + sdp->sd_inptrs; +if (first) + top += mp->mp_list[h]; + } +/* find the first rgrp referenced by the buflist's buffer and count +the block refs contained within that rgrp. */ for (p = top; p < bottom; p++) { -if (!*p) +if (*p ==0 )continue ; -/* check for max reasonable journal transaction blocks */ -if (tr->tr_num_buf_new +RES_STATFS + -RES_QUOTA >=atomic_read (&sdp->sd_log_thresh2)) { -if (rg_blocks >= tr->tr_num_buf_new) - rg_blocks -= tr->tr_num_buf_new; -else - rg_blocks =0 ; -break ; - } - bn =be64_to_cpu (*p); +if (rgd ==NULL ) + rgd =gfs2_blk2rgrpd (sdp, bn, false); +if (rgrp_contains_block (rgd, bn)) + hit_count++; +else + (*remblks)++; + } +if (rgd ==NULL ) + goto out; -if (bstart + blen == bn) - blen++; -else { -if (bstart) { -__gfs2_free_blocks (ip, bstart, blen, metadata); - btotal += blen; - } + error =gfs2_glock_nq_init (rgd->rd_gl,LM_ST_EXCLUSIVE ,0 , &gh); +if (error) + goto out; - bstart = bn; - blen =1 ; - } +/* needs to be done with the proper rgrp glock held: */ +if (rgd == ip->i_rgd &&gfs2_rs_active (&ip->i_res)) +gfs2_rs_deltree (&ip->i_res); - *p =0 ; -gfs2_add_inode_blocks (&ip->i_inode,-1 ); +/* Calculate the max number of metadata blocks we can add to the log. +Every metablock potentially could be revoked. At this point we know +we're working with a single rgrp, but there may be thousands of +buffers referencing blocks therein. There's no good way to know +without traversing them. The most we could have is the number of +blocks in the rgrp, ri_data. It seems wrong to request the max in +the rgrp. It also seems wrong to request the most we can fit in a +transaction. For now, estimate it to be: the number of metablocks +referenced by _this_ buffer TIMES the number of buffers. +If we guess too many, it will be curtailed by the max. If we guess +too few, it will be broken into smaller transactions regardless. */ + jblocks_rqsted = rgd->rd_length +RES_DINODE +RES_INDIRECT + + (hit_count * buflist_mallocs) + +gfs2_struct2blk (sdp, hit_count,sizeof (u64)); +if (jblocks_rqsted >atomic_read (&sdp->sd_log_thresh2)) { + max_meta =atomic_read (&sdp->sd_log_thresh2) - + (RES_DINODE +RES_INDIRECT ); + max_meta -=gfs2_struct2blk (sdp, max_meta,sizeof (u64)); + jblocks_rqsted = max_meta; } -if (p == bottom) - rg_blocks =0 ; - -if (bstart) { -__gfs2_free_blocks (ip, bstart, blen, metadata); - btotal += blen; + error =gfs2_trans_begin (sdp, jblocks_rqsted, jblocks_rqsted); + jblocks_left = jblocks_rqsted; +if (error) + goto out_uninit; +/* Process and free all buffers contained in this rgrp starting with +current. */ + pos = cur; +list_for_each_entry_safe_from (pos, n, head, bl_list) { + error =free_for_rgrp (ip, mp, h, pos, del_all, first, rgd, + &jblocks_left, freed); +/* Optimization: if we've encountered X blocks that don't +reference this rgrp at all, skip looking through the rest. +If we missed a couple references, they'll be removed later +at the expense of an extra transaction. But if we +meticulously comb all buffers for this rgrp, we may waste +the majority of our time checking thousands of buffers for +every rgrp ref. The time to delete a 500GB file goes from +2m35s to 26s. */ +if (error == -ENOENT ) { + miss_count++; +if (miss_count <MAX_BH_RGRP_MISSES ) + error =0 ; + } +if (error) +break ; } - -gfs2_statfs_change (sdp,0 , +btotal,0 ); -gfs2_quota_change (ip, -(s64 )btotal, ip->i_inode.i_uid, - ip->i_inode.i_gid); - - ip->i_inode.i_mtime = ip->i_inode.i_ctime =CURRENT_TIME ; - -gfs2_dinode_out (ip, dibh->b_data); - -up_write (&ip->i_rw_mutex); -gfs2_trans_end (sdp); -if (rg_blocks) - goto restart; - -out_rg_gunlock: -gfs2_glock_dq_m (rlist.rl_rgrps, rlist.rl_ghs); -out_rlist: -gfs2_rlist_free (&rlist); +out_uninit: +gfs2_glock_dq_uninit (&gh); +/* Give other processes a chance to run */ +cond_resched (); out:return error; }/** -* recursive_scan - recursively scan through the end of a file +* trunc_buflist - delete / truncate a file's metadata and data blocks * @ip: the inode -* @dibh: the dinode buffer -* @mp: the path through the metadata to the point to start -* @height: the height the recursion is at -* @block: the indirect block to look at -* @first: 1 if this is the first block -* @sm: data opaque to this function to pass to @bc -* -* When this is first called @height and @block should be zero and -* @first should be 1. +* @mp: a metapath corresponding to the truncation point +* @del_all: true if we're supposed to delete everything, false for truncate * * Returns: errno */ - -static int recursive_scan (struct gfs2_inode *ip,struct buffer_head *dibh, -struct metapath *mp,unsigned int height, -u64 block,int first,struct strip_mine *sm) +static int trunc_buflist (struct gfs2_inode *ip,struct metapath *mp, +int del_all) {struct gfs2_sbd *sdp =GFS2_SB (&ip->i_inode); -struct buffer_head *bh =NULL ; -__be64 *top, *bottom; +struct gfs2_buflist *cur, *fwd, *buf1; +struct buffer_head *bh, *dibh =NULL ; +struct list_head blist[GFS2_MAX_META_HEIGHT ]; +unsigned int metablocks[GFS2_MAX_META_HEIGHT ] = {0 , }; +LIST_HEAD (new_batch);u64 bn; -int error; -int mh_size =sizeof (struct gfs2_meta_header ); - -if (!height) { - error =gfs2_meta_inode_buffer (ip, &bh); -if (error) -return error; - dibh = bh; - - top = (__be64 *)(bh->b_data +sizeof (struct gfs2_dinode )) + mp->mp_list[0 ]; - bottom = (__be64 *)(bh->b_data +sizeof (struct gfs2_dinode )) + sdp->sd_diptrs; - }else { - error =gfs2_meta_indirect_buffer (ip, height, block, &bh); -if (error) -return error; +u32 btotal =0 , freed =0 , remblks; +__be64 *p, *top, *bottom; +int error, h, first; +int ptrcnt;/* non-zero block pointer count */ +int buflist_mallocs =1 , buflist_frees =0 ; - top = (__be64 *)(bh->b_data + mh_size) + - (first ? mp->mp_list[height] :0 ); +for (h =0 ; h < ip->i_height; h++) +INIT_LIST_HEAD (&blist[h]); - bottom = (__be64 *)(bh->b_data + mh_size) + sdp->sd_inptrs; - } + cur =kmalloc (sizeof (struct gfs2_buflist ),GFP_NOFS ); +if (!cur) +return -ENOMEM ; - error =do_strip (ip, dibh, bh, top, bottom, height, sm); +/* build the list of metadata buffers, and rgrp list and count +the revokes. */ + error =gfs2_meta_inode_buffer (ip, &dibh);if (error) - goto out; +return -ENOMEM ; + + cur->bl_bh = dibh; + metablocks[0 ] =1 ; +list_add_tail (&cur->bl_list, &blist[0 ]); + +for (h =0 ; h < ip->i_height -1 ; h++) { +/* Can't use list_for_each_entry_safe here because it relies +upon the list being built outward, so next won't exist +until later. */ + buf1 = list_first_entry_or_null(&blist[h], struct gfs2_buflist, + bl_list); + first =1 ; +list_for_each_entry (cur, &blist[h], bl_list) { +deleted_cur: + bh = cur->bl_bh; +if (h ==0 ) { + top = (__be64 *)(bh->b_data + +sizeof (struct gfs2_dinode )); + bottom = (__be64 *)top + sdp->sd_diptrs; + top += mp->mp_list[0 ]; + }else { + top = (__be64 *)(bh->b_data + +sizeof (struct gfs2_meta_header )); + bottom = top + sdp->sd_inptrs; +/* If we changed heights, start where metapath +says. */ +if (cur == buf1) { + top += mp->mp_list[h]; + first =0 ; + } + } -if (height < ip->i_height -1 ) { +gfs2_metapath_ra (ip->i_gl, bh, top); +BUG_ON (!list_empty (&new_batch)); + ptrcnt =0 ; + fwd =NULL ; +for (p = top; p < bottom; p++) { +if (!*p) +continue ; + + ptrcnt++; + bn =be64_to_cpu (*p); + fwd =kmalloc (sizeof (struct gfs2_buflist ), +GFP_NOFS ); +if (fwd ==NULL ) { + error = -ENOMEM ; +/* We encountered an error, so splice +the new batch onto the blist so the +new batch gets freed. */ +list_splice_tail_init (&new_batch, + &blist[h +1 ]); + goto out; + } -gfs2_metapath_ra (ip->i_gl, bh, top); + buflist_mallocs++; + metablocks[h +1 ]++; + error =gfs2_meta_indirect_buffer (ip, h +1 , + bn, &fwd->bl_bh); +if (error) { +kfree (fwd); + buflist_frees++; +list_splice_tail_init (&new_batch, + &blist[h +1 ]); + goto out; + } -for (; top < bottom; top++, first =0 ) { -if (!*top) -continue ; +BUG_ON (!buffer_uptodate (fwd->bl_bh)); +list_add_tail (&fwd->bl_list, &new_batch); + } +/* Optimization to keep the list from getting too long: +If we just added meta blocks of the highest height +(which only point to data blocks) process it and +free the blocks immediately. A 500GB file has +di_height 4, and di_blocks 131330018, but 131072000 +of them are data. There are really only 258018 +metadata buffers. This trims it down to more +reasonable 65837. We do this after we build the +list, so we're not freeing blocks in too small of +transactions. */ +if (ptrcnt && h +1 == ip->i_height -1 ) { +down_write (&ip->i_rw_mutex); + freed =0 ; + fwd =list_first_entry (&new_batch, + struct gfs2_buflist, + bl_list); +do { + error =process_buf (ip, mp, h +1 , fwd, + &new_batch, + del_all, + buflist_mallocs, + &freed, false, + &remblks); + }while (error == -EAGAIN || remblks); + btotal += freed; +up_write (&ip->i_rw_mutex); + } +/* Add the new batch to the tail of blist (build the +list out) so they are processed as we traverse. */ +list_splice_tail_init (&new_batch, &blist[h +1 ]); +if (ptrcnt ==0 ) { +/* Tricky: We ran out of pointers in the cur +buffer. We need to free it, then go to the +next, but list_for_each_entry_safe gets +its next pointer too late early in the cycle +because we build the list as we go. */ +if (cur->bl_list.next == &blist[h]) + fwd =NULL ; +else + fwd =list_entry (cur->bl_list.next, + struct gfs2_buflist, bl_list); +if (cur->bl_bh != dibh) +brelse (cur->bl_bh); +list_del (&cur->bl_list); +kfree (cur); + buflist_frees++; +if (fwd) { + cur = fwd; + goto deleted_cur; + } +break ; + } +if (error) + goto out; + } + } - bn =be64_to_cpu (*top); +down_write (&ip->i_rw_mutex); - error =recursive_scan (ip, dibh, mp, height +1 , bn, - first, sm); -if (error) -break ; +/* We traverse the buffer list by height, with highest first. That +makes it impossible to have block dependency problems. In other +words, when block X is freed before the blocks it points to are, +block X may be reused and reassigned by another process, and its +buffer_head overwritten with something we can't use for freeing. */ +for (h = ip->i_height -1 ; h >=0 ; h--) { + first =1 ; +while (!error && !list_empty (&blist[h])) { + cur = list_entry(blist[h].next, struct gfs2_buflist, + bl_list); + freed =0 ; + error =process_buf (ip, mp, h, cur, &blist[h], del_all, + buflist_mallocs, &freed, first, + &remblks); +if (error == -EAGAIN || error == -ENOENT ) + error =0 ; + first =0 ; + btotal += freed; +if (remblks ==0 ) {/* if no more blocks remaining */ +if (cur->bl_bh != dibh) +brelse (cur->bl_bh); +list_del (&cur->bl_list); +kfree (cur); + buflist_frees++; + } + } + } + +if (btotal) { + error =gfs2_trans_begin (sdp,RES_DINODE +RES_STATFS + +RES_QUOTA ,0 ); +if (error ==0 ) { +gfs2_statfs_change (sdp,0 , +btotal,0 ); +gfs2_quota_change (ip, -(s64 )btotal, ip->i_inode.i_uid, + ip->i_inode.i_gid); + ip->i_inode.i_mtime = ip->i_inode.i_ctime = +CURRENT_TIME ; +gfs2_trans_add_meta (ip->i_gl, dibh); +gfs2_dinode_out (ip, dibh->b_data); +gfs2_trans_end (sdp); } } +up_write (&ip->i_rw_mutex); + + out: -brelse (bh); +/* In the normal non-error code path, the list is already empty. */ +for (h =0 ; h < ip->i_height; h++) { +while (!list_empty (&blist[h])) { + cur = list_entry(blist[h].next, struct gfs2_buflist, + bl_list); +list_del (&cur->bl_list); +if (cur->bl_bh != dibh) +brelse (cur->bl_bh); +kfree (cur); + buflist_frees++; + } + } +brelse (dibh); +BUG_ON (buflist_mallocs != buflist_frees);return error; }
@@ -1108,7 +1297,6 @@ out:static int trunc_dealloc (struct gfs2_inode *ip,u64 size) {struct gfs2_sbd *sdp =GFS2_SB (&ip->i_inode); -unsigned int height = ip->i_height;u64 lblock;struct metapath mp;int error;
@@ -1127,16 +1315,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, u64 size)if (error)return error; -while (height--) { -struct strip_mine sm; - sm.sm_first = !!size; - sm.sm_height = height; - - error =recursive_scan (ip,NULL , &mp,0 ,0 ,1 , &sm); -if (error) -break ; - } - + error =trunc_buflist (ip, &mp, size ==0 );gfs2_quota_unhold (ip);return error;
fs/gfs2/lops.c +2 -1
@@ -97,12 +97,13 @@ static void maybe_release_space(struct gfs2_bufdata *bd)static void gfs2_unpin (struct gfs2_sbd *sdp,struct buffer_head *bh,struct gfs2_trans *tr) { -struct gfs2_bufdata *bd = bh->b_private; +struct gfs2_bufdata *bd;BUG_ON (!buffer_uptodate (bh));BUG_ON (!buffer_pinned (bh));lock_buffer (bh); + bd = bh->b_private;mark_buffer_dirty (bh);clear_buffer_pinned (bh);
fs/gfs2/rgrp.c +0 -7
@@ -457,13 +457,6 @@ void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd) } } -static inline int rgrp_contains_block (struct gfs2_rgrpd *rgd,u64 block) -{ -u64 first = rgd->rd_data0; -u64 last = first + rgd->rd_data; -return first <= block && block < last; -} -/** * gfs2_blk2rgrpd - Find resource group for a given data/meta block number * @sdp: The GFS2 superblock
fs/gfs2/rgrp.h +7 -0
@@ -83,5 +83,12 @@ static inline bool gfs2_rs_active(const struct gfs2_blkreserv *rs) return rs && !RB_EMPTY_NODE(&rs->rs_node); } +static inline int rgrp_contains_block (struct gfs2_rgrpd *rgd,u64 block) +{ +u64 first = rgd->rd_data0; +u64 last = first + rgd->rd_data; +return first <= block && block < last; +} +extern void check_and_update_goal (struct gfs2_inode *ip);#endif /* __RGRP_DOT_H__ */
fs/gfs2/util.c +5 -0
@@ -16,6 +16,7 @@#include "gfs2.h" #include "incore.h" +#include "inode.h" #include "glock.h" #include "util.h"
@@ -160,10 +161,14 @@ int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, rv =gfs2_lm_withdraw (sdp,"GFS2: fsid=%s: fatal: filesystem consistency error\n" "GFS2: fsid=%s: inode = %llu %llu\n" +"GFS2: fsid=%s: di_size = %llu\n" +"GFS2: fsid=%s: di_blocks = %llu\n" "GFS2: fsid=%s: function = %s, file = %s, line = %u\n" , sdp->sd_fsname, sdp->sd_fsname, (unsigned long long )ip->i_no_formal_ino, (unsigned long long )ip->i_no_addr, + (unsigned long long )i_size_read (&ip->i_inode), + (unsigned long long )gfs2_get_inode_blocks (&ip->i_inode), sdp->sd_fsname, function, file, line);return rv; }
PATCH 1/1 gfs2: non-recursive delete
Hi,
Quoted 11 lines · Bob Peterson
Hi,
This is my latest implementation of non-recursive delete for RHEL7 (upstream should be nearly the same).
The algorithm has undergone massive changes since I last posted it.
One of the key concepts here is to free affected blocks one RGRP at a time so that while a delete is going on, only one rgrp glock is tied up, thus allowing all other processes in the file system to run better and faster.
There is no option about that either. To do anything else would introduce dependencies between the rgrp glocks with various deadlock cases that would result. That is ok too, since we would expect in almost every case to see contiguous runs of allocated blocks from the same rgrp, with occasional changes to a new rgrp, and we need to optimise for the common case here.
Quoted 9 lines
The idea here is to process the lowest height of metadata, the inode, and build a linked list of metadata buffers. Then, traverse each buffer finding the first rgrp pointed to by that buffer. We lock the glock for that rgrp. Then, for all buffers in the list, we look for references to that rgrp, and remove them in spans. If a buffer references *ONLY* that rgrp, it's removed from the list. Then the process repeats starting with the first buffer that hasn't been completely cleaned of all rgrp references.
Please don't create linked lists of buffers. There is no need. The metadata itself already has the information that is required, and the struct metapath can be used to track the current position. This is exactly the reverse of allocation, where we also don't use linked lists.
Quoted 13 lines
This way, we can keep only a single rgrp locked at one time, thus allowing other processes to allocate and use the others. We also need to allocate fewer blocks in the journal each iteration, allowing us to delete very large files in smaller chunks, which turns out to be more efficient.
WARNING: This algorithm seems to work, and work efficiently, even when done in parallel on up to six nodes, but it seems to cause file system corruption if given enough pressure. All the right locks are taken in all the right places, so I fail to see the cause of the corruption. The corruption is: Every once in a while, dinodes seem to magically disappear and get:
Quoted 3 lines
GFS2: fsid=afc_cluster:work.3: fatal: invalid metadata block
GFS2: fsid=afc_cluster:work.3: bh = 71412755 (magic number) ==0x441ac13
GFS2: fsid=afc_cluster:work.3: function =gfs2_meta_indirect_buffer, file =fs/gfs2/meta_io.c, line = 431
I can't immediately spot the problem, however something must be touching the inode block, so if you can reproduce this consistently with the same inode number, then it should be easy to trace the activity both in gfs2 and on the block device for that inode/block,
Steve.
Quoted 768 lines
If anyone can spot problems with the patch, I'd appreciate it.
Signed-off-by Bob Peterson <[email protected]>---
fs/gfs2/bmap.c +381
-202@@ -19,6 +19,7 @@#include "bmap.h" #include "glock.h" #include "inode.h" +#include "log.h" #include "meta_io.h" #include "quota.h" #include "rgrp.h" @@ -29,6 +30,8 @@#include "util.h" #include "trace_gfs2.h" +#define MAX_BH_RGRP_MISSES 3 +/* This doesn't need to be that large as max 64 bit pointers in a 4k * block is 512, so __u16 is fine for that. It saves stack space to * keep it small. @@ -38,9 +41,9 @@ struct metapath {__u16 mp_list[GFS2_MAX_META_HEIGHT ]; }; -struct strip_mine { -int sm_first; -unsigned int sm_height; +struct gfs2_buflist { +struct list_head bl_list; +struct buffer_head *bl_bh; };/** @@ -700,58 +703,43 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsireturn ret; } -/** -* do_strip - Look for a layer a particular layer of the file and strip it off -* @ip: the inode -* @dibh: the dinode buffer -* @bh: A buffer of pointers -* @top: The first pointer in the buffer -* @bottom: One more than the last pointer -* @height: the height this buffer is at -* @data: a pointer to a struct strip_mine +/* +* free_for_rgrp - free all blocks inside the rgrp * -* Returns: errno +* Returns: error +* 0 - All is well, keep processing buffers +* -ENOENT - No references to this rgrp in this buffer. +* -EAGAIN - We filled up our transaction. Close it and loop again. +* Or other error */ - -static int do_strip (struct gfs2_inode *ip,struct buffer_head *dibh, -struct buffer_head *bh,__be64 *top,__be64 *bottom, -unsigned int height,struct strip_mine *sm) +/* static */ +noinline +int free_for_rgrp(struct gfs2_inode *ip, struct metapath *mp, int h, +struct gfs2_buflist *cur,int del_all,int first, +struct gfs2_rgrpd *rgd,int *jblocks_left, +int *freed) { +struct buffer_head *bh;struct gfs2_sbd *sdp =GFS2_SB (&ip->i_inode); -struct gfs2_rgrp_list rlist; -struct gfs2_trans *tr; -u64 bn, bstart; -u32 blen, btotal; -__be64 *p; -unsigned int rg_blocks =0 ; -int metadata; -unsigned int revokes =0 ; -int x; -int error; -int jblocks_rqsted; - - error =gfs2_rindex_update (sdp); -if (error) -return error; - -if (!*top) - sm->sm_first =0 ; - -if (height != sm->sm_height) -return 0 ; - -if (sm->sm_first) { - top++; - sm->sm_first =0 ; +__be64 *p, *top, *bottom; +int meta, error =0 ; +u64 bn, bstart =0 ; +s64 blen =0 ; +bool bh_added_to_trans = false; + + bh = cur->bl_bh; + bh_added_to_trans = false; +if (h ==0 ) { + top = (__be64 *)(bh->b_data +sizeof (struct gfs2_dinode )); + bottom = top + sdp->sd_diptrs; + top += mp->mp_list[0 ]; + }else { + top = (__be64 *)(bh->b_data +sizeof (struct gfs2_meta_header )); + bottom = top + sdp->sd_inptrs; +if (first) + top += mp->mp_list[h]; } - - metadata = (height != ip->i_height -1 ); -if (metadata) - revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs; -else if (ip->i_depth) - revokes = sdp->sd_inptrs; - -memset (&rlist,0 ,sizeof (struct gfs2_rgrp_list )); + meta = (h != ip->i_height -1 ); bstart =0 ; blen =0 ;@@ -760,188 +748,389 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,continue ; bn =be64_to_cpu (*p); +if (!rgrp_contains_block (rgd, bn)) +continue ; +if (!bh_added_to_trans) { +BUG_ON (*jblocks_left ==0 ); + (*jblocks_left)--; +/* If last meta block for the transaction, return +-EAGAIN to make it end the current transaction and +start a new one. */ +if (*jblocks_left ==0 ) + error = -EAGAIN ; + +gfs2_trans_add_meta (ip->i_gl, bh); + bh_added_to_trans = true; + } + *p =0 ; -if (bstart + blen == bn) +if (bstart + blen == bn) { blen++; -else { -if (bstart) -gfs2_rlist_add (ip, &rlist, bstart); - - bstart = bn; - blen =1 ; +continue ; + } +if (bstart) { +__gfs2_free_blocks (ip, bstart, (u32 )blen, meta); + (*freed) += blen; +gfs2_add_inode_blocks (&ip->i_inode, -blen); } - } - -if (bstart) -gfs2_rlist_add (ip, &rlist, bstart); -else - goto out;/* Nothing to do */ - -gfs2_rlist_alloc (&rlist,LM_ST_EXCLUSIVE ); -for (x =0 ; x < rlist.rl_rgrps; x++) { -struct gfs2_rgrpd *rgd; - rgd = rlist.rl_ghs[x].gh_gl->gl_object; - rg_blocks += rgd->rd_length; + bstart = bn; + blen =1 ; } +if (bstart) { +__gfs2_free_blocks (ip, bstart, (u32 )blen, meta); + (*freed) += blen; +gfs2_add_inode_blocks (&ip->i_inode, -blen); + } +if (!bh_added_to_trans)/* no hits? */ + error = -ENOENT ; +return error; +} - error =gfs2_glock_nq_m (rlist.rl_rgrps, rlist.rl_ghs); -if (error) - goto out_rlist; - -if (gfs2_rs_active (&ip->i_res))/* needs to be done with the rgrp glock held */ -gfs2_rs_deltree (&ip->i_res); - -restart: - jblocks_rqsted = rg_blocks +RES_DINODE + -RES_INDIRECT +RES_STATFS +RES_QUOTA + -gfs2_struct2blk (sdp, revokes,sizeof (u64)); -if (jblocks_rqsted >atomic_read (&sdp->sd_log_thresh2)) - jblocks_rqsted =atomic_read (&sdp->sd_log_thresh2); - error =gfs2_trans_begin (sdp, jblocks_rqsted, revokes); -if (error) - goto out_rg_gunlock; - - tr = current->journal_info; -down_write (&ip->i_rw_mutex); - -gfs2_trans_add_meta (ip->i_gl, dibh); -gfs2_trans_add_meta (ip->i_gl, bh); - - bstart =0 ; - blen =0 ; - btotal =0 ; - +/* process_buf - process a buffer with pointers +* +* This function examines a buffer from top to bottom, looking for a +* non-zero block pointer. From that it extrapolates its corresponding rgrp. +* Then it proceeds to free all buffers in the list (starting with head) +* that reference the same rgrp. +* +* Returns: -ENOENT - The buffer is devoid of rgrps +* 0 - We freed all blocks from the given rgrp +* Other error has occurred +* Sets: remblks - remaining blocks in this buffer that aren't in rgrp +*/ +/* static */ +noinline +int process_buf(struct gfs2_inode *ip, struct metapath *mp, int h, +struct gfs2_buflist *cur,struct list_head *head,int del_all, +int buflist_mallocs,u32 *freed,int first,u32 *remblks) +{ +struct gfs2_sbd *sdp =GFS2_SB (&ip->i_inode); +struct gfs2_rgrpd *rgd =NULL ; +struct gfs2_holder gh; +struct gfs2_buflist *pos, *n; +u64 bn; +__be64 *p, *top, *bottom; +unsigned int jblocks_rqsted, jblocks_left, max_meta; +int miss_count =0 , hit_count =0 ; +int error = -ENOENT ; + + *remblks =0 ; +if (h ==0 ) { + top = (__be64 *)(cur->bl_bh->b_data +sizeof (struct gfs2_dinode )); + bottom = top + sdp->sd_diptrs; + top += mp->mp_list[0 ]; + }else { + top = (__be64 *)(cur->bl_bh->b_data +sizeof (struct gfs2_meta_header )); + bottom = top + sdp->sd_inptrs; +if (first) + top += mp->mp_list[h]; + } +/* find the first rgrp referenced by the buflist's buffer and count +the block refs contained within that rgrp. */ for (p = top; p < bottom; p++) { -if (!*p) +if (*p ==0 )continue ; -/* check for max reasonable journal transaction blocks */ -if (tr->tr_num_buf_new +RES_STATFS + -RES_QUOTA >=atomic_read (&sdp->sd_log_thresh2)) { -if (rg_blocks >= tr->tr_num_buf_new) - rg_blocks -= tr->tr_num_buf_new; -else - rg_blocks =0 ; -break ; - } - bn =be64_to_cpu (*p); +if (rgd ==NULL ) + rgd =gfs2_blk2rgrpd (sdp, bn, false); +if (rgrp_contains_block (rgd, bn)) + hit_count++; +else + (*remblks)++; + } +if (rgd ==NULL ) + goto out; -if (bstart + blen == bn) - blen++; -else { -if (bstart) { -__gfs2_free_blocks (ip, bstart, blen, metadata); - btotal += blen; - } + error =gfs2_glock_nq_init (rgd->rd_gl,LM_ST_EXCLUSIVE ,0 , &gh); +if (error) + goto out; - bstart = bn; - blen =1 ; - } +/* needs to be done with the proper rgrp glock held: */ +if (rgd == ip->i_rgd &&gfs2_rs_active (&ip->i_res)) +gfs2_rs_deltree (&ip->i_res); - *p =0 ; -gfs2_add_inode_blocks (&ip->i_inode,-1 ); +/* Calculate the max number of metadata blocks we can add to the log. +Every metablock potentially could be revoked. At this point we know +we're working with a single rgrp, but there may be thousands of +buffers referencing blocks therein. There's no good way to know +without traversing them. The most we could have is the number of +blocks in the rgrp, ri_data. It seems wrong to request the max in +the rgrp. It also seems wrong to request the most we can fit in a +transaction. For now, estimate it to be: the number of metablocks +referenced by _this_ buffer TIMES the number of buffers. +If we guess too many, it will be curtailed by the max. If we guess +too few, it will be broken into smaller transactions regardless. */ + jblocks_rqsted = rgd->rd_length +RES_DINODE +RES_INDIRECT + + (hit_count * buflist_mallocs) + +gfs2_struct2blk (sdp, hit_count,sizeof (u64)); +if (jblocks_rqsted >atomic_read (&sdp->sd_log_thresh2)) { + max_meta =atomic_read (&sdp->sd_log_thresh2) - + (RES_DINODE +RES_INDIRECT ); + max_meta -=gfs2_struct2blk (sdp, max_meta,sizeof (u64)); + jblocks_rqsted = max_meta; } -if (p == bottom) - rg_blocks =0 ; - -if (bstart) { -__gfs2_free_blocks (ip, bstart, blen, metadata); - btotal += blen; + error =gfs2_trans_begin (sdp, jblocks_rqsted, jblocks_rqsted); + jblocks_left = jblocks_rqsted; +if (error) + goto out_uninit; +/* Process and free all buffers contained in this rgrp starting with +current. */ + pos = cur; +list_for_each_entry_safe_from (pos, n, head, bl_list) { + error =free_for_rgrp (ip, mp, h, pos, del_all, first, rgd, + &jblocks_left, freed); +/* Optimization: if we've encountered X blocks that don't +reference this rgrp at all, skip looking through the rest. +If we missed a couple references, they'll be removed later +at the expense of an extra transaction. But if we +meticulously comb all buffers for this rgrp, we may waste +the majority of our time checking thousands of buffers for +every rgrp ref. The time to delete a 500GB file goes from +2m35s to 26s. */ +if (error == -ENOENT ) { + miss_count++; +if (miss_count <MAX_BH_RGRP_MISSES ) + error =0 ; + } +if (error) +break ; } - -gfs2_statfs_change (sdp,0 , +btotal,0 ); -gfs2_quota_change (ip, -(s64 )btotal, ip->i_inode.i_uid, - ip->i_inode.i_gid); - - ip->i_inode.i_mtime = ip->i_inode.i_ctime =CURRENT_TIME ; - -gfs2_dinode_out (ip, dibh->b_data); - -up_write (&ip->i_rw_mutex); -gfs2_trans_end (sdp); -if (rg_blocks) - goto restart; - -out_rg_gunlock: -gfs2_glock_dq_m (rlist.rl_rgrps, rlist.rl_ghs); -out_rlist: -gfs2_rlist_free (&rlist); +out_uninit: +gfs2_glock_dq_uninit (&gh); +/* Give other processes a chance to run */ +cond_resched (); out:return error; }/** -* recursive_scan - recursively scan through the end of a file +* trunc_buflist - delete / truncate a file's metadata and data blocks * @ip: the inode -* @dibh: the dinode buffer -* @mp: the path through the metadata to the point to start -* @height: the height the recursion is at -* @block: the indirect block to look at -* @first: 1 if this is the first block -* @sm: data opaque to this function to pass to @bc -* -* When this is first called @height and @block should be zero and -* @first should be 1. +* @mp: a metapath corresponding to the truncation point +* @del_all: true if we're supposed to delete everything, false for truncate * * Returns: errno */ - -static int recursive_scan (struct gfs2_inode *ip,struct buffer_head *dibh, -struct metapath *mp,unsigned int height, -u64 block,int first,struct strip_mine *sm) +static int trunc_buflist (struct gfs2_inode *ip,struct metapath *mp, +int del_all) {struct gfs2_sbd *sdp =GFS2_SB (&ip->i_inode); -struct buffer_head *bh =NULL ; -__be64 *top, *bottom; +struct gfs2_buflist *cur, *fwd, *buf1; +struct buffer_head *bh, *dibh =NULL ; +struct list_head blist[GFS2_MAX_META_HEIGHT ]; +unsigned int metablocks[GFS2_MAX_META_HEIGHT ] = {0 , }; +LIST_HEAD (new_batch);u64 bn; -int error; -int mh_size =sizeof (struct gfs2_meta_header ); - -if (!height) { - error =gfs2_meta_inode_buffer (ip, &bh); -if (error) -return error; - dibh = bh; - - top = (__be64 *)(bh->b_data +sizeof (struct gfs2_dinode )) + mp->mp_list[0 ]; - bottom = (__be64 *)(bh->b_data +sizeof (struct gfs2_dinode )) + sdp->sd_diptrs; - }else { - error =gfs2_meta_indirect_buffer (ip, height, block, &bh); -if (error) -return error; +u32 btotal =0 , freed =0 , remblks; +__be64 *p, *top, *bottom; +int error, h, first; +int ptrcnt;/* non-zero block pointer count */ +int buflist_mallocs =1 , buflist_frees =0 ; - top = (__be64 *)(bh->b_data + mh_size) + - (first ? mp->mp_list[height] :0 ); +for (h =0 ; h < ip->i_height; h++) +INIT_LIST_HEAD (&blist[h]); - bottom = (__be64 *)(bh->b_data + mh_size) + sdp->sd_inptrs; - } + cur =kmalloc (sizeof (struct gfs2_buflist ),GFP_NOFS ); +if (!cur) +return -ENOMEM ; - error =do_strip (ip, dibh, bh, top, bottom, height, sm); +/* build the list of metadata buffers, and rgrp list and count +the revokes. */ + error =gfs2_meta_inode_buffer (ip, &dibh);if (error) - goto out; +return -ENOMEM ; + + cur->bl_bh = dibh; + metablocks[0 ] =1 ; +list_add_tail (&cur->bl_list, &blist[0 ]); + +for (h =0 ; h < ip->i_height -1 ; h++) { +/* Can't use list_for_each_entry_safe here because it relies +upon the list being built outward, so next won't exist +until later. */ + buf1 = list_first_entry_or_null(&blist[h], struct gfs2_buflist, + bl_list); + first =1 ; +list_for_each_entry (cur, &blist[h], bl_list) { +deleted_cur: + bh = cur->bl_bh; +if (h ==0 ) { + top = (__be64 *)(bh->b_data + +sizeof (struct gfs2_dinode )); + bottom = (__be64 *)top + sdp->sd_diptrs; + top += mp->mp_list[0 ]; + }else { + top = (__be64 *)(bh->b_data + +sizeof (struct gfs2_meta_header )); + bottom = top + sdp->sd_inptrs; +/* If we changed heights, start where metapath +says. */ +if (cur == buf1) { + top += mp->mp_list[h]; + first =0 ; + } + } -if (height < ip->i_height -1 ) { +gfs2_metapath_ra (ip->i_gl, bh, top); +BUG_ON (!list_empty (&new_batch)); + ptrcnt =0 ; + fwd =NULL ; +for (p = top; p < bottom; p++) { +if (!*p) +continue ; + + ptrcnt++; + bn =be64_to_cpu (*p); + fwd =kmalloc (sizeof (struct gfs2_buflist ), +GFP_NOFS ); +if (fwd ==NULL ) { + error = -ENOMEM ; +/* We encountered an error, so splice +the new batch onto the blist so the +new batch gets freed. */ +list_splice_tail_init (&new_batch, + &blist[h +1 ]); + goto out; + } -gfs2_metapath_ra (ip->i_gl, bh, top); + buflist_mallocs++; + metablocks[h +1 ]++; + error =gfs2_meta_indirect_buffer (ip, h +1 , + bn, &fwd->bl_bh); +if (error) { +kfree (fwd); + buflist_frees++; +list_splice_tail_init (&new_batch, + &blist[h +1 ]); + goto out; + } -for (; top < bottom; top++, first =0 ) { -if (!*top) -continue ; +BUG_ON (!buffer_uptodate (fwd->bl_bh)); +list_add_tail (&fwd->bl_list, &new_batch); + } +/* Optimization to keep the list from getting too long: +If we just added meta blocks of the highest height +(which only point to data blocks) process it and +free the blocks immediately. A 500GB file has +di_height 4, and di_blocks 131330018, but 131072000 +of them are data. There are really only 258018 +metadata buffers. This trims it down to more +reasonable 65837. We do this after we build the +list, so we're not freeing blocks in too small of +transactions. */ +if (ptrcnt && h +1 == ip->i_height -1 ) { +down_write (&ip->i_rw_mutex); + freed =0 ; + fwd =list_first_entry (&new_batch, + struct gfs2_buflist, + bl_list); +do { + error =process_buf (ip, mp, h +1 , fwd, + &new_batch, + del_all, + buflist_mallocs, + &freed, false, + &remblks); + }while (error == -EAGAIN || remblks); + btotal += freed; +up_write (&ip->i_rw_mutex); + } +/* Add the new batch to the tail of blist (build the +list out) so they are processed as we traverse. */ +list_splice_tail_init (&new_batch, &blist[h +1 ]); +if (ptrcnt ==0 ) { +/* Tricky: We ran out of pointers in the cur +buffer. We need to free it, then go to the +next, but list_for_each_entry_safe gets +its next pointer too late early in the cycle +because we build the list as we go. */ +if (cur->bl_list.next == &blist[h]) + fwd =NULL ; +else + fwd =list_entry (cur->bl_list.next, + struct gfs2_buflist, bl_list); +if (cur->bl_bh != dibh) +brelse (cur->bl_bh); +list_del (&cur->bl_list); +kfree (cur); + buflist_frees++; +if (fwd) { + cur = fwd; + goto deleted_cur; + } +break ; + } +if (error) + goto out; + } + } - bn =be64_to_cpu (*top); +down_write (&ip->i_rw_mutex); - error =recursive_scan (ip, dibh, mp, height +1 , bn, - first, sm); -if (error) -break ; +/* We traverse the buffer list by height, with highest first. That +makes it impossible to have block dependency problems. In other +words, when block X is freed before the blocks it points to are, +block X may be reused and reassigned by another process, and its +buffer_head overwritten with something we can't use for freeing. */ +for (h = ip->i_height -1 ; h >=0 ; h--) { + first =1 ; +while (!error && !list_empty (&blist[h])) { + cur = list_entry(blist[h].next, struct gfs2_buflist, + bl_list); + freed =0 ; + error =process_buf (ip, mp, h, cur, &blist[h], del_all, + buflist_mallocs, &freed, first, + &remblks); +if (error == -EAGAIN || error == -ENOENT ) + error =0 ; + first =0 ; + btotal += freed; +if (remblks ==0 ) {/* if no more blocks remaining */ +if (cur->bl_bh != dibh) +brelse (cur->bl_bh); +list_del (&cur->bl_list); +kfree (cur); + buflist_frees++; + } + } + } + +if (btotal) { + error =gfs2_trans_begin (sdp,RES_DINODE +RES_STATFS + +RES_QUOTA ,0 ); +if (error ==0 ) { +gfs2_statfs_change (sdp,0 , +btotal,0 ); +gfs2_quota_change (ip, -(s64 )btotal, ip->i_inode.i_uid, + ip->i_inode.i_gid); + ip->i_inode.i_mtime = ip->i_inode.i_ctime = +CURRENT_TIME ; +gfs2_trans_add_meta (ip->i_gl, dibh); +gfs2_dinode_out (ip, dibh->b_data); +gfs2_trans_end (sdp); } } +up_write (&ip->i_rw_mutex); + + out: -brelse (bh); +/* In the normal non-error code path, the list is already empty. */ +for (h =0 ; h < ip->i_height; h++) { +while (!list_empty (&blist[h])) { + cur = list_entry(blist[h].next, struct gfs2_buflist, + bl_list); +list_del (&cur->bl_list); +if (cur->bl_bh != dibh) +brelse (cur->bl_bh); +kfree (cur); + buflist_frees++; + } + } +brelse (dibh); +BUG_ON (buflist_mallocs != buflist_frees);return error; }@@ -1108,7 +1297,6 @@ out:static int trunc_dealloc (struct gfs2_inode *ip,u64 size) {struct gfs2_sbd *sdp =GFS2_SB (&ip->i_inode); -unsigned int height = ip->i_height;u64 lblock;struct metapath mp;int error;@@ -1127,16 +1315,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, u64 size)if (error)return error; -while (height--) { -struct strip_mine sm; - sm.sm_first = !!size; - sm.sm_height = height; - - error =recursive_scan (ip,NULL , &mp,0 ,0 ,1 , &sm); -if (error) -break ; - } - + error =trunc_buflist (ip, &mp, size ==0 );gfs2_quota_unhold (ip);return error;fs/gfs2/lops.c +2
-1@@ -97,12 +97,13 @@ static void maybe_release_space(struct gfs2_bufdata *bd)static void gfs2_unpin (struct gfs2_sbd *sdp,struct buffer_head *bh,struct gfs2_trans *tr) { -struct gfs2_bufdata *bd = bh->b_private; +struct gfs2_bufdata *bd;BUG_ON (!buffer_uptodate (bh));BUG_ON (!buffer_pinned (bh));lock_buffer (bh); + bd = bh->b_private;mark_buffer_dirty (bh);clear_buffer_pinned (bh);fs/gfs2/rgrp.c +0
-7@@ -457,13 +457,6 @@ void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd) } } -static inline int rgrp_contains_block (struct gfs2_rgrpd *rgd,u64 block) -{ -u64 first = rgd->rd_data0; -u64 last = first + rgd->rd_data; -return first <= block && block < last; -} -/** * gfs2_blk2rgrpd - Find resource group for a given data/meta block number * @sdp: The GFS2 superblock fs/gfs2/rgrp.h +7
-0@@ -83,5 +83,12 @@ static inline bool gfs2_rs_active(const struct gfs2_blkreserv *rs) return rs && !RB_EMPTY_NODE(&rs->rs_node); } +static inline int rgrp_contains_block (struct gfs2_rgrpd *rgd,u64 block) +{ +u64 first = rgd->rd_data0; +u64 last = first + rgd->rd_data; +return first <= block && block < last; +} +extern void check_and_update_goal (struct gfs2_inode *ip);#endif /* __RGRP_DOT_H__ */ fs/gfs2/util.c +5
-0@@ -16,6 +16,7 @@#include "gfs2.h" #include "incore.h" +#include "inode.h" #include "glock.h" #include "util.h" @@ -160,10 +161,14 @@ int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, rv =gfs2_lm_withdraw (sdp,"GFS2: fsid=%s: fatal: filesystem consistency error\n" "GFS2: fsid=%s: inode = %llu %llu\n" +"GFS2: fsid=%s: di_size = %llu\n" +"GFS2: fsid=%s: di_blocks = %llu\n" "GFS2: fsid=%s: function = %s, file = %s, line = %u\n" , sdp->sd_fsname, sdp->sd_fsname, (unsigned long long )ip->i_no_formal_ino, (unsigned long long )ip->i_no_addr, + (unsigned long long )i_size_read (&ip->i_inode), + (unsigned long long )gfs2_get_inode_blocks (&ip->i_inode), sdp->sd_fsname, function, file, line);return rv; }