Commit ef75bd71 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'gfs2-for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2

Pull GFS2 updates from Andreas Gruenbacher:
 "We've got the following patches ready for this merge window:

   - "gfs2: Fix loop in gfs2_rbm_find (v2)"

      A rework of a fix we ended up reverting in 5.0 because of an
      iozone performance regression.

   - "gfs2: read journal in large chunks"
     "gfs2: fix race between gfs2_freeze_func and unmount"

      An improved version of a commit we also ended up reverting in 5.0
      because of a regression in xfstest generic/311. It turns out that
      the journal changes were mostly innocent and that unfreeze didn't
      wait for the freeze to complete, which caused the filesystem to be
      unmounted before it was actually idle.

   - "gfs2: Fix occasional glock use-after-free"
     "gfs2: Fix iomap write page reclaim deadlock"
     "gfs2: Fix lru_count going negative"

      Fixes for various problems reported and partially fixed by Citrix
      engineers. Thank you very much.

   - "gfs2: clean_journal improperly set sd_log_flush_head"

      Another fix from Bob.

   - .. and a few other minor cleanups"

* tag 'gfs2-for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2:
  gfs2: read journal in large chunks
  gfs2: Fix iomap write page reclaim deadlock
  gfs2: fix race between gfs2_freeze_func and unmount
  gfs2: Rename gfs2_trans_{add_unrevoke => remove_revoke}
  gfs2: Rename sd_log_le_{revoke,ordered}
  gfs2: Remove unnecessary extern declarations
  gfs2: Remove misleading comments in gfs2_evict_inode
  gfs2: Replace gl_revokes with a GLF flag
  gfs2: Fix occasional glock use-after-free
  gfs2: clean_journal improperly set sd_log_flush_head
  gfs2: Fix lru_count going negative
  gfs2: Fix loop in gfs2_rbm_find (v2)
parents 78d9affb f4686c26
...@@ -649,7 +649,7 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping, ...@@ -649,7 +649,7 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping,
*/ */
void adjust_fs_space(struct inode *inode) void adjust_fs_space(struct inode *inode)
{ {
struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; struct gfs2_sbd *sdp = GFS2_SB(inode);
struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
...@@ -657,10 +657,13 @@ void adjust_fs_space(struct inode *inode) ...@@ -657,10 +657,13 @@ void adjust_fs_space(struct inode *inode)
struct buffer_head *m_bh, *l_bh; struct buffer_head *m_bh, *l_bh;
u64 fs_total, new_free; u64 fs_total, new_free;
if (gfs2_trans_begin(sdp, 2 * RES_STATFS, 0) != 0)
return;
/* Total up the file system space, according to the latest rindex. */ /* Total up the file system space, according to the latest rindex. */
fs_total = gfs2_ri_total(sdp); fs_total = gfs2_ri_total(sdp);
if (gfs2_meta_inode_buffer(m_ip, &m_bh) != 0) if (gfs2_meta_inode_buffer(m_ip, &m_bh) != 0)
return; goto out;
spin_lock(&sdp->sd_statfs_spin); spin_lock(&sdp->sd_statfs_spin);
gfs2_statfs_change_in(m_sc, m_bh->b_data + gfs2_statfs_change_in(m_sc, m_bh->b_data +
...@@ -675,11 +678,14 @@ void adjust_fs_space(struct inode *inode) ...@@ -675,11 +678,14 @@ void adjust_fs_space(struct inode *inode)
gfs2_statfs_change(sdp, new_free, new_free, 0); gfs2_statfs_change(sdp, new_free, new_free, 0);
if (gfs2_meta_inode_buffer(l_ip, &l_bh) != 0) if (gfs2_meta_inode_buffer(l_ip, &l_bh) != 0)
goto out; goto out2;
update_statfs(sdp, m_bh, l_bh); update_statfs(sdp, m_bh, l_bh);
brelse(l_bh); brelse(l_bh);
out: out2:
brelse(m_bh); brelse(m_bh);
out:
sdp->sd_rindex_uptodate = 0;
gfs2_trans_end(sdp);
} }
/** /**
......
...@@ -142,7 +142,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) ...@@ -142,7 +142,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
if (error) if (error)
goto out_brelse; goto out_brelse;
if (isdir) { if (isdir) {
gfs2_trans_add_unrevoke(GFS2_SB(&ip->i_inode), block, 1); gfs2_trans_remove_revoke(GFS2_SB(&ip->i_inode), block, 1);
error = gfs2_dir_get_new_buffer(ip, block, &bh); error = gfs2_dir_get_new_buffer(ip, block, &bh);
if (error) if (error)
goto out_brelse; goto out_brelse;
...@@ -676,7 +676,7 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap, ...@@ -676,7 +676,7 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap,
goto out; goto out;
alloced += n; alloced += n;
if (state != ALLOC_DATA || gfs2_is_jdata(ip)) if (state != ALLOC_DATA || gfs2_is_jdata(ip))
gfs2_trans_add_unrevoke(sdp, bn, n); gfs2_trans_remove_revoke(sdp, bn, n);
switch (state) { switch (state) {
/* Growing height of tree */ /* Growing height of tree */
case ALLOC_GROW_HEIGHT: case ALLOC_GROW_HEIGHT:
...@@ -925,6 +925,32 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, ...@@ -925,6 +925,32 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
goto out; goto out;
} }
/**
* gfs2_lblk_to_dblk - convert logical block to disk block
* @inode: the inode of the file we're mapping
* @lblock: the block relative to the start of the file
* @dblock: the returned dblock, if no error
*
* This function maps a single block from a file logical block (relative to
* the start of the file) to a file system absolute block using iomap.
*
* Returns: the absolute file system block, or an error
*/
int gfs2_lblk_to_dblk(struct inode *inode, u32 lblock, u64 *dblock)
{
struct iomap iomap = { };
struct metapath mp = { .mp_aheight = 1, };
loff_t pos = (loff_t)lblock << inode->i_blkbits;
int ret;
ret = gfs2_iomap_get(inode, pos, i_blocksize(inode), 0, &iomap, &mp);
release_metapath(&mp);
if (ret == 0)
*dblock = iomap.addr >> inode->i_blkbits;
return ret;
}
static int gfs2_write_lock(struct inode *inode) static int gfs2_write_lock(struct inode *inode)
{ {
struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_inode *ip = GFS2_I(inode);
...@@ -965,17 +991,28 @@ static void gfs2_write_unlock(struct inode *inode) ...@@ -965,17 +991,28 @@ static void gfs2_write_unlock(struct inode *inode)
gfs2_glock_dq_uninit(&ip->i_gh); gfs2_glock_dq_uninit(&ip->i_gh);
} }
static int gfs2_iomap_page_prepare(struct inode *inode, loff_t pos,
unsigned len, struct iomap *iomap)
{
struct gfs2_sbd *sdp = GFS2_SB(inode);
return gfs2_trans_begin(sdp, RES_DINODE + (len >> inode->i_blkbits), 0);
}
static void gfs2_iomap_page_done(struct inode *inode, loff_t pos, static void gfs2_iomap_page_done(struct inode *inode, loff_t pos,
unsigned copied, struct page *page, unsigned copied, struct page *page,
struct iomap *iomap) struct iomap *iomap)
{ {
struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_inode *ip = GFS2_I(inode);
struct gfs2_sbd *sdp = GFS2_SB(inode);
if (page) if (page && !gfs2_is_stuffed(ip))
gfs2_page_add_databufs(ip, page, offset_in_page(pos), copied); gfs2_page_add_databufs(ip, page, offset_in_page(pos), copied);
gfs2_trans_end(sdp);
} }
static const struct iomap_page_ops gfs2_iomap_page_ops = { static const struct iomap_page_ops gfs2_iomap_page_ops = {
.page_prepare = gfs2_iomap_page_prepare,
.page_done = gfs2_iomap_page_done, .page_done = gfs2_iomap_page_done,
}; };
...@@ -1031,7 +1068,11 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, ...@@ -1031,7 +1068,11 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
if (alloc_required) if (alloc_required)
rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks); rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks);
ret = gfs2_trans_begin(sdp, rblocks, iomap->length >> inode->i_blkbits); if (unstuff || iomap->type == IOMAP_HOLE) {
struct gfs2_trans *tr;
ret = gfs2_trans_begin(sdp, rblocks,
iomap->length >> inode->i_blkbits);
if (ret) if (ret)
goto out_trans_fail; goto out_trans_fail;
...@@ -1040,8 +1081,8 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, ...@@ -1040,8 +1081,8 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
if (ret) if (ret)
goto out_trans_end; goto out_trans_end;
release_metapath(mp); release_metapath(mp);
ret = gfs2_iomap_get(inode, iomap->offset, iomap->length, ret = gfs2_iomap_get(inode, iomap->offset,
flags, iomap, mp); iomap->length, flags, iomap, mp);
if (ret) if (ret)
goto out_trans_end; goto out_trans_end;
} }
...@@ -1055,7 +1096,17 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, ...@@ -1055,7 +1096,17 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
goto out_qunlock; goto out_qunlock;
} }
} }
if (!gfs2_is_stuffed(ip) && gfs2_is_jdata(ip))
tr = current->journal_info;
if (tr->tr_num_buf_new)
__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
else
gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[0]);
gfs2_trans_end(sdp);
}
if (gfs2_is_stuffed(ip) || gfs2_is_jdata(ip))
iomap->page_ops = &gfs2_iomap_page_ops; iomap->page_ops = &gfs2_iomap_page_ops;
return 0; return 0;
...@@ -1095,10 +1146,6 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, ...@@ -1095,10 +1146,6 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
iomap->type != IOMAP_MAPPED) iomap->type != IOMAP_MAPPED)
ret = -ENOTBLK; ret = -ENOTBLK;
} }
if (!ret) {
get_bh(mp.mp_bh[0]);
iomap->private = mp.mp_bh[0];
}
release_metapath(&mp); release_metapath(&mp);
trace_gfs2_iomap_end(ip, iomap, ret); trace_gfs2_iomap_end(ip, iomap, ret);
return ret; return ret;
...@@ -1109,27 +1156,16 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length, ...@@ -1109,27 +1156,16 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
{ {
struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_inode *ip = GFS2_I(inode);
struct gfs2_sbd *sdp = GFS2_SB(inode); struct gfs2_sbd *sdp = GFS2_SB(inode);
struct gfs2_trans *tr = current->journal_info;
struct buffer_head *dibh = iomap->private;
if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) != IOMAP_WRITE) if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) != IOMAP_WRITE)
goto out; goto out;
if (iomap->type != IOMAP_INLINE) { if (!gfs2_is_stuffed(ip))
gfs2_ordered_add_inode(ip); gfs2_ordered_add_inode(ip);
if (tr->tr_num_buf_new) if (inode == sdp->sd_rindex)
__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
else
gfs2_trans_add_meta(ip->i_gl, dibh);
}
if (inode == sdp->sd_rindex) {
adjust_fs_space(inode); adjust_fs_space(inode);
sdp->sd_rindex_uptodate = 0;
}
gfs2_trans_end(sdp);
gfs2_inplace_release(ip); gfs2_inplace_release(ip);
if (length != written && (iomap->flags & IOMAP_F_NEW)) { if (length != written && (iomap->flags & IOMAP_F_NEW)) {
...@@ -1149,8 +1185,6 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length, ...@@ -1149,8 +1185,6 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
gfs2_write_unlock(inode); gfs2_write_unlock(inode);
out: out:
if (dibh)
brelse(dibh);
return 0; return 0;
} }
......
...@@ -64,5 +64,6 @@ extern int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset, ...@@ -64,5 +64,6 @@ extern int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
extern int gfs2_map_journal_extents(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd); extern int gfs2_map_journal_extents(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd);
extern void gfs2_free_journal_extents(struct gfs2_jdesc *jd); extern void gfs2_free_journal_extents(struct gfs2_jdesc *jd);
extern int __gfs2_punch_hole(struct file *file, loff_t offset, loff_t length); extern int __gfs2_punch_hole(struct file *file, loff_t offset, loff_t length);
extern int gfs2_lblk_to_dblk(struct inode *inode, u32 lblock, u64 *dblock);
#endif /* __BMAP_DOT_H__ */ #endif /* __BMAP_DOT_H__ */
...@@ -883,7 +883,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, ...@@ -883,7 +883,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
if (!bh) if (!bh)
return NULL; return NULL;
gfs2_trans_add_unrevoke(GFS2_SB(inode), bn, 1); gfs2_trans_remove_revoke(GFS2_SB(inode), bn, 1);
gfs2_trans_add_meta(ip->i_gl, bh); gfs2_trans_add_meta(ip->i_gl, bh);
gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF);
leaf = (struct gfs2_leaf *)bh->b_data; leaf = (struct gfs2_leaf *)bh->b_data;
......
...@@ -140,6 +140,7 @@ void gfs2_glock_free(struct gfs2_glock *gl) ...@@ -140,6 +140,7 @@ void gfs2_glock_free(struct gfs2_glock *gl)
{ {
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
BUG_ON(test_bit(GLF_REVOKES, &gl->gl_flags));
rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms); rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms);
smp_mb(); smp_mb();
wake_up_glock(gl); wake_up_glock(gl);
...@@ -183,15 +184,19 @@ static int demote_ok(const struct gfs2_glock *gl) ...@@ -183,15 +184,19 @@ static int demote_ok(const struct gfs2_glock *gl)
void gfs2_glock_add_to_lru(struct gfs2_glock *gl) void gfs2_glock_add_to_lru(struct gfs2_glock *gl)
{ {
spin_lock(&lru_lock); if (!(gl->gl_ops->go_flags & GLOF_LRU))
return;
if (!list_empty(&gl->gl_lru)) spin_lock(&lru_lock);
list_del_init(&gl->gl_lru);
else
atomic_inc(&lru_count);
list_del(&gl->gl_lru);
list_add_tail(&gl->gl_lru, &lru_list); list_add_tail(&gl->gl_lru, &lru_list);
if (!test_bit(GLF_LRU, &gl->gl_flags)) {
set_bit(GLF_LRU, &gl->gl_flags); set_bit(GLF_LRU, &gl->gl_flags);
atomic_inc(&lru_count);
}
spin_unlock(&lru_lock); spin_unlock(&lru_lock);
} }
...@@ -201,7 +206,7 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl) ...@@ -201,7 +206,7 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
return; return;
spin_lock(&lru_lock); spin_lock(&lru_lock);
if (!list_empty(&gl->gl_lru)) { if (test_bit(GLF_LRU, &gl->gl_flags)) {
list_del_init(&gl->gl_lru); list_del_init(&gl->gl_lru);
atomic_dec(&lru_count); atomic_dec(&lru_count);
clear_bit(GLF_LRU, &gl->gl_flags); clear_bit(GLF_LRU, &gl->gl_flags);
...@@ -1159,8 +1164,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh) ...@@ -1159,8 +1164,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
!test_bit(GLF_DEMOTE, &gl->gl_flags)) !test_bit(GLF_DEMOTE, &gl->gl_flags))
fast_path = 1; fast_path = 1;
} }
if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl) && if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl))
(glops->go_flags & GLOF_LRU))
gfs2_glock_add_to_lru(gl); gfs2_glock_add_to_lru(gl);
trace_gfs2_glock_queue(gh, 0); trace_gfs2_glock_queue(gh, 0);
...@@ -1456,6 +1460,7 @@ __acquires(&lru_lock) ...@@ -1456,6 +1460,7 @@ __acquires(&lru_lock)
if (!spin_trylock(&gl->gl_lockref.lock)) { if (!spin_trylock(&gl->gl_lockref.lock)) {
add_back_to_lru: add_back_to_lru:
list_add(&gl->gl_lru, &lru_list); list_add(&gl->gl_lru, &lru_list);
set_bit(GLF_LRU, &gl->gl_flags);
atomic_inc(&lru_count); atomic_inc(&lru_count);
continue; continue;
} }
...@@ -1463,7 +1468,6 @@ __acquires(&lru_lock) ...@@ -1463,7 +1468,6 @@ __acquires(&lru_lock)
spin_unlock(&gl->gl_lockref.lock); spin_unlock(&gl->gl_lockref.lock);
goto add_back_to_lru; goto add_back_to_lru;
} }
clear_bit(GLF_LRU, &gl->gl_flags);
gl->gl_lockref.count++; gl->gl_lockref.count++;
if (demote_ok(gl)) if (demote_ok(gl))
handle_callback(gl, LM_ST_UNLOCKED, 0, false); handle_callback(gl, LM_ST_UNLOCKED, 0, false);
...@@ -1498,6 +1502,7 @@ static long gfs2_scan_glock_lru(int nr) ...@@ -1498,6 +1502,7 @@ static long gfs2_scan_glock_lru(int nr)
if (!test_bit(GLF_LOCK, &gl->gl_flags)) { if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
list_move(&gl->gl_lru, &dispose); list_move(&gl->gl_lru, &dispose);
atomic_dec(&lru_count); atomic_dec(&lru_count);
clear_bit(GLF_LRU, &gl->gl_flags);
freed++; freed++;
continue; continue;
} }
...@@ -1796,7 +1801,7 @@ void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl) ...@@ -1796,7 +1801,7 @@ void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl)
state2str(gl->gl_target), state2str(gl->gl_target),
state2str(gl->gl_demote_state), dtime, state2str(gl->gl_demote_state), dtime,
atomic_read(&gl->gl_ail_count), atomic_read(&gl->gl_ail_count),
atomic_read(&gl->gl_revokes), test_bit(GLF_REVOKES, &gl->gl_flags) ? 1 : 0,
(int)gl->gl_lockref.count, gl->gl_hold_time); (int)gl->gl_lockref.count, gl->gl_hold_time);
list_for_each_entry(gh, &gl->gl_holders, gh_list) list_for_each_entry(gh, &gl->gl_holders, gh_list)
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "util.h" #include "util.h"
#include "trans.h" #include "trans.h"
#include "dir.h" #include "dir.h"
#include "lops.h"
struct workqueue_struct *gfs2_freeze_wq; struct workqueue_struct *gfs2_freeze_wq;
...@@ -531,7 +532,7 @@ static int freeze_go_xmote_bh(struct gfs2_glock *gl, struct gfs2_holder *gh) ...@@ -531,7 +532,7 @@ static int freeze_go_xmote_bh(struct gfs2_glock *gl, struct gfs2_holder *gh)
if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
error = gfs2_find_jhead(sdp->sd_jdesc, &head); error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
if (error) if (error)
gfs2_consist(sdp); gfs2_consist(sdp);
if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT))
......
...@@ -345,6 +345,7 @@ enum { ...@@ -345,6 +345,7 @@ enum {
GLF_OBJECT = 14, /* Used only for tracing */ GLF_OBJECT = 14, /* Used only for tracing */
GLF_BLOCKING = 15, GLF_BLOCKING = 15,
GLF_INODE_CREATING = 16, /* Inode creation occurring */ GLF_INODE_CREATING = 16, /* Inode creation occurring */
GLF_REVOKES = 17, /* Glock has revokes in queue */
}; };
struct gfs2_glock { struct gfs2_glock {
...@@ -374,7 +375,6 @@ struct gfs2_glock { ...@@ -374,7 +375,6 @@ struct gfs2_glock {
struct list_head gl_lru; struct list_head gl_lru;
struct list_head gl_ail_list; struct list_head gl_ail_list;
atomic_t gl_ail_count; atomic_t gl_ail_count;
atomic_t gl_revokes;
struct delayed_work gl_work; struct delayed_work gl_work;
union { union {
/* For inode and iopen glocks only */ /* For inode and iopen glocks only */
...@@ -535,7 +535,7 @@ struct gfs2_jdesc { ...@@ -535,7 +535,7 @@ struct gfs2_jdesc {
unsigned long jd_flags; unsigned long jd_flags;
#define JDF_RECOVERY 1 #define JDF_RECOVERY 1
unsigned int jd_jid; unsigned int jd_jid;
unsigned int jd_blocks; u32 jd_blocks;
int jd_recover_error; int jd_recover_error;
/* Replay stuff */ /* Replay stuff */
...@@ -621,6 +621,7 @@ enum { ...@@ -621,6 +621,7 @@ enum {
SDF_SKIP_DLM_UNLOCK = 8, SDF_SKIP_DLM_UNLOCK = 8,
SDF_FORCE_AIL_FLUSH = 9, SDF_FORCE_AIL_FLUSH = 9,
SDF_AIL1_IO_ERROR = 10, SDF_AIL1_IO_ERROR = 10,
SDF_FS_FROZEN = 11,
}; };
enum gfs2_freeze_state { enum gfs2_freeze_state {
...@@ -809,8 +810,8 @@ struct gfs2_sbd { ...@@ -809,8 +810,8 @@ struct gfs2_sbd {
atomic_t sd_log_pinned; atomic_t sd_log_pinned;
unsigned int sd_log_num_revoke; unsigned int sd_log_num_revoke;
struct list_head sd_log_le_revoke; struct list_head sd_log_revokes;
struct list_head sd_log_le_ordered; struct list_head sd_log_ordered;
spinlock_t sd_ordered_lock; spinlock_t sd_ordered_lock;
atomic_t sd_log_thresh1; atomic_t sd_log_thresh1;
......
...@@ -551,9 +551,9 @@ static void gfs2_ordered_write(struct gfs2_sbd *sdp) ...@@ -551,9 +551,9 @@ static void gfs2_ordered_write(struct gfs2_sbd *sdp)
LIST_HEAD(written); LIST_HEAD(written);
spin_lock(&sdp->sd_ordered_lock); spin_lock(&sdp->sd_ordered_lock);
list_sort(NULL, &sdp->sd_log_le_ordered, &ip_cmp); list_sort(NULL, &sdp->sd_log_ordered, &ip_cmp);
while (!list_empty(&sdp->sd_log_le_ordered)) { while (!list_empty(&sdp->sd_log_ordered)) {
ip = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_inode, i_ordered); ip = list_entry(sdp->sd_log_ordered.next, struct gfs2_inode, i_ordered);
if (ip->i_inode.i_mapping->nrpages == 0) { if (ip->i_inode.i_mapping->nrpages == 0) {
test_and_clear_bit(GIF_ORDERED, &ip->i_flags); test_and_clear_bit(GIF_ORDERED, &ip->i_flags);
list_del(&ip->i_ordered); list_del(&ip->i_ordered);
...@@ -564,7 +564,7 @@ static void gfs2_ordered_write(struct gfs2_sbd *sdp) ...@@ -564,7 +564,7 @@ static void gfs2_ordered_write(struct gfs2_sbd *sdp)
filemap_fdatawrite(ip->i_inode.i_mapping); filemap_fdatawrite(ip->i_inode.i_mapping);
spin_lock(&sdp->sd_ordered_lock); spin_lock(&sdp->sd_ordered_lock);
} }
list_splice(&written, &sdp->sd_log_le_ordered); list_splice(&written, &sdp->sd_log_ordered);
spin_unlock(&sdp->sd_ordered_lock); spin_unlock(&sdp->sd_ordered_lock);
} }
...@@ -573,8 +573,8 @@ static void gfs2_ordered_wait(struct gfs2_sbd *sdp) ...@@ -573,8 +573,8 @@ static void gfs2_ordered_wait(struct gfs2_sbd *sdp)
struct gfs2_inode *ip; struct gfs2_inode *ip;
spin_lock(&sdp->sd_ordered_lock); spin_lock(&sdp->sd_ordered_lock);
while (!list_empty(&sdp->sd_log_le_ordered)) { while (!list_empty(&sdp->sd_log_ordered)) {
ip = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_inode, i_ordered); ip = list_entry(sdp->sd_log_ordered.next, struct gfs2_inode, i_ordered);
list_del(&ip->i_ordered); list_del(&ip->i_ordered);
WARN_ON(!test_and_clear_bit(GIF_ORDERED, &ip->i_flags)); WARN_ON(!test_and_clear_bit(GIF_ORDERED, &ip->i_flags));
if (ip->i_inode.i_mapping->nrpages == 0) if (ip->i_inode.i_mapping->nrpages == 0)
...@@ -606,9 +606,12 @@ void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd) ...@@ -606,9 +606,12 @@ void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
gfs2_remove_from_ail(bd); /* drops ref on bh */ gfs2_remove_from_ail(bd); /* drops ref on bh */
bd->bd_bh = NULL; bd->bd_bh = NULL;
sdp->sd_log_num_revoke++; sdp->sd_log_num_revoke++;
atomic_inc(&gl->gl_revokes); if (!test_bit(GLF_REVOKES, &gl->gl_flags)) {
set_bit(GLF_REVOKES, &gl->gl_flags);
gfs2_glock_hold(gl);
}
set_bit(GLF_LFLUSH, &gl->gl_flags); set_bit(GLF_LFLUSH, &gl->gl_flags);
list_add(&bd->bd_list, &sdp->sd_log_le_revoke); list_add(&bd->bd_list, &sdp->sd_log_revokes);
} }
void gfs2_write_revokes(struct gfs2_sbd *sdp) void gfs2_write_revokes(struct gfs2_sbd *sdp)
...@@ -666,11 +669,12 @@ void gfs2_write_revokes(struct gfs2_sbd *sdp) ...@@ -666,11 +669,12 @@ void gfs2_write_revokes(struct gfs2_sbd *sdp)
} }
/** /**
* write_log_header - Write a journal log header buffer at sd_log_flush_head * gfs2_write_log_header - Write a journal log header buffer at lblock
* @sdp: The GFS2 superblock * @sdp: The GFS2 superblock
* @jd: journal descriptor of the journal to which we are writing * @jd: journal descriptor of the journal to which we are writing
* @seq: sequence number * @seq: sequence number
* @tail: tail of the log * @tail: tail of the log
* @lblock: value for lh_blkno (block number relative to start of journal)
* @flags: log header flags GFS2_LOG_HEAD_* * @flags: log header flags GFS2_LOG_HEAD_*
* @op_flags: flags to pass to the bio * @op_flags: flags to pass to the bio
* *
...@@ -678,7 +682,8 @@ void gfs2_write_revokes(struct gfs2_sbd *sdp) ...@@ -678,7 +682,8 @@ void gfs2_write_revokes(struct gfs2_sbd *sdp)
*/ */
void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
u64 seq, u32 tail, u32 flags, int op_flags) u64 seq, u32 tail, u32 lblock, u32 flags,
int op_flags)
{ {
struct gfs2_log_header *lh; struct gfs2_log_header *lh;
u32 hash, crc; u32 hash, crc;
...@@ -686,7 +691,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, ...@@ -686,7 +691,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
struct timespec64 tv; struct timespec64 tv;
struct super_block *sb = sdp->sd_vfs; struct super_block *sb = sdp->sd_vfs;
u64 addr; u64 dblock;
lh = page_address(page); lh = page_address(page);
clear_page(lh); clear_page(lh);
...@@ -699,15 +704,21 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, ...@@ -699,15 +704,21 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
lh->lh_sequence = cpu_to_be64(seq); lh->lh_sequence = cpu_to_be64(seq);
lh->lh_flags = cpu_to_be32(flags); lh->lh_flags = cpu_to_be32(flags);
lh->lh_tail = cpu_to_be32(tail); lh->lh_tail = cpu_to_be32(tail);
lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head); lh->lh_blkno = cpu_to_be32(lblock);
hash = ~crc32(~0, lh, LH_V1_SIZE); hash = ~crc32(~0, lh, LH_V1_SIZE);
lh->lh_hash = cpu_to_be32(hash); lh->lh_hash = cpu_to_be32(hash);
ktime_get_coarse_real_ts64(&tv); ktime_get_coarse_real_ts64(&tv);
lh->lh_nsec = cpu_to_be32(tv.tv_nsec); lh->lh_nsec = cpu_to_be32(tv.tv_nsec);
lh->lh_sec = cpu_to_be64(tv.tv_sec); lh->lh_sec = cpu_to_be64(tv.tv_sec);
addr = gfs2_log_bmap(sdp); if (!list_empty(&jd->extent_list))
lh->lh_addr = cpu_to_be64(addr); dblock = gfs2_log_bmap(sdp);
else {
int ret = gfs2_lblk_to_dblk(jd->jd_inode, lblock, &dblock);
if (gfs2_assert_withdraw(sdp, ret == 0))
return;
}
lh->lh_addr = cpu_to_be64(dblock);
lh->lh_jinode = cpu_to_be64(GFS2_I(jd->jd_inode)->i_no_addr); lh->lh_jinode = cpu_to_be64(GFS2_I(jd->jd_inode)->i_no_addr);
/* We may only write local statfs, quota, etc., when writing to our /* We may only write local statfs, quota, etc., when writing to our
...@@ -732,8 +743,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, ...@@ -732,8 +743,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
sb->s_blocksize - LH_V1_SIZE - 4); sb->s_blocksize - LH_V1_SIZE - 4);
lh->lh_crc = cpu_to_be32(crc); lh->lh_crc = cpu_to_be32(crc);
gfs2_log_write(sdp, page, sb->s_blocksize, 0, addr); gfs2_log_write(sdp, page, sb->s_blocksize, 0, dblock);
gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE, op_flags); gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE | op_flags);
log_flush_wait(sdp); log_flush_wait(sdp);
} }
...@@ -761,7 +772,7 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags) ...@@ -761,7 +772,7 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
} }
sdp->sd_log_idle = (tail == sdp->sd_log_flush_head); sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
gfs2_write_log_header(sdp, sdp->sd_jdesc, sdp->sd_log_sequence++, tail, gfs2_write_log_header(sdp, sdp->sd_jdesc, sdp->sd_log_sequence++, tail,
flags, op_flags); sdp->sd_log_flush_head, flags, op_flags);
if (sdp->sd_log_tail != tail) if (sdp->sd_log_tail != tail)
log_pull_tail(sdp, tail); log_pull_tail(sdp, tail);
...@@ -810,7 +821,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags) ...@@ -810,7 +821,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
gfs2_ordered_write(sdp); gfs2_ordered_write(sdp);
lops_before_commit(sdp, tr); lops_before_commit(sdp, tr);
gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE, 0); gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE);
if (sdp->sd_log_head != sdp->sd_log_flush_head) { if (sdp->sd_log_head != sdp->sd_log_flush_head) {
log_flush_wait(sdp); log_flush_wait(sdp);
......
...@@ -59,7 +59,7 @@ static inline void gfs2_ordered_add_inode(struct gfs2_inode *ip) ...@@ -59,7 +59,7 @@ static inline void gfs2_ordered_add_inode(struct gfs2_inode *ip)
if (!test_bit(GIF_ORDERED, &ip->i_flags)) { if (!test_bit(GIF_ORDERED, &ip->i_flags)) {
spin_lock(&sdp->sd_ordered_lock); spin_lock(&sdp->sd_ordered_lock);
if (!test_and_set_bit(GIF_ORDERED, &ip->i_flags)) if (!test_and_set_bit(GIF_ORDERED, &ip->i_flags))
list_add(&ip->i_ordered, &sdp->sd_log_le_ordered); list_add(&ip->i_ordered, &sdp->sd_log_ordered);
spin_unlock(&sdp->sd_ordered_lock); spin_unlock(&sdp->sd_ordered_lock);
} }
} }
...@@ -70,7 +70,8 @@ extern unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, ...@@ -70,7 +70,8 @@ extern unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
extern void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks); extern void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks);
extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks); extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks);
extern void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, extern void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
u64 seq, u32 tail, u32 flags, int op_flags); u64 seq, u32 tail, u32 lblock, u32 flags,
int op_flags);
extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
u32 type); u32 type);
extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans); extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
......
This diff is collapsed.
...@@ -20,18 +20,15 @@ ...@@ -20,18 +20,15 @@
((sizeof(struct gfs2_log_descriptor) + (2 * sizeof(__be64) - 1)) & \ ((sizeof(struct gfs2_log_descriptor) + (2 * sizeof(__be64) - 1)) & \
~(2 * sizeof(__be64) - 1)) ~(2 * sizeof(__be64) - 1))
extern const struct gfs2_log_operations gfs2_glock_lops;
extern const struct gfs2_log_operations gfs2_buf_lops;
extern const struct gfs2_log_operations gfs2_revoke_lops;
extern const struct gfs2_log_operations gfs2_databuf_lops;
extern const struct gfs2_log_operations *gfs2_log_ops[]; extern const struct gfs2_log_operations *gfs2_log_ops[];
extern u64 gfs2_log_bmap(struct gfs2_sbd *sdp); extern u64 gfs2_log_bmap(struct gfs2_sbd *sdp);
extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page, extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
unsigned size, unsigned offset, u64 blkno); unsigned size, unsigned offset, u64 blkno);
extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page); extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page);
extern void gfs2_log_submit_bio(struct bio **biop, int op, int op_flags); extern void gfs2_log_submit_bio(struct bio **biop, int opf);
extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
extern int gfs2_find_jhead(struct gfs2_jdesc *jd,
struct gfs2_log_header_host *head, bool keep_cache);
static inline unsigned int buf_limit(struct gfs2_sbd *sdp) static inline unsigned int buf_limit(struct gfs2_sbd *sdp)
{ {
...@@ -77,7 +74,7 @@ static inline void lops_before_scan(struct gfs2_jdesc *jd, ...@@ -77,7 +74,7 @@ static inline void lops_before_scan(struct gfs2_jdesc *jd,
gfs2_log_ops[x]->lo_before_scan(jd, head, pass); gfs2_log_ops[x]->lo_before_scan(jd, head, pass);
} }
static inline int lops_scan_elements(struct gfs2_jdesc *jd, unsigned int start, static inline int lops_scan_elements(struct gfs2_jdesc *jd, u32 start,
struct gfs2_log_descriptor *ld, struct gfs2_log_descriptor *ld,
__be64 *ptr, __be64 *ptr,
unsigned int pass) unsigned int pass)
......
...@@ -59,7 +59,6 @@ static void gfs2_init_glock_once(void *foo) ...@@ -59,7 +59,6 @@ static void gfs2_init_glock_once(void *foo)
INIT_LIST_HEAD(&gl->gl_lru); INIT_LIST_HEAD(&gl->gl_lru);
INIT_LIST_HEAD(&gl->gl_ail_list); INIT_LIST_HEAD(&gl->gl_ail_list);
atomic_set(&gl->gl_ail_count, 0); atomic_set(&gl->gl_ail_count, 0);
atomic_set(&gl->gl_revokes, 0);
} }
static void gfs2_init_gl_aspace_once(void *foo) static void gfs2_init_gl_aspace_once(void *foo)
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "dir.h" #include "dir.h"
#include "meta_io.h" #include "meta_io.h"
#include "trace_gfs2.h" #include "trace_gfs2.h"
#include "lops.h"
#define DO 0 #define DO 0
#define UNDO 1 #define UNDO 1
...@@ -117,8 +118,8 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) ...@@ -117,8 +118,8 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
spin_lock_init(&sdp->sd_log_lock); spin_lock_init(&sdp->sd_log_lock);
atomic_set(&sdp->sd_log_pinned, 0); atomic_set(&sdp->sd_log_pinned, 0);
INIT_LIST_HEAD(&sdp->sd_log_le_revoke); INIT_LIST_HEAD(&sdp->sd_log_revokes);
INIT_LIST_HEAD(&sdp->sd_log_le_ordered); INIT_LIST_HEAD(&sdp->sd_log_ordered);
spin_lock_init(&sdp->sd_ordered_lock); spin_lock_init(&sdp->sd_ordered_lock);
init_waitqueue_head(&sdp->sd_log_waitq); init_waitqueue_head(&sdp->sd_log_waitq);
...@@ -616,7 +617,7 @@ static int check_journal_clean(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd) ...@@ -616,7 +617,7 @@ static int check_journal_clean(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd)
fs_err(sdp, "Error checking journal for spectator mount.\n"); fs_err(sdp, "Error checking journal for spectator mount.\n");
goto out_unlock; goto out_unlock;
} }
error = gfs2_find_jhead(jd, &head); error = gfs2_find_jhead(jd, &head, false);
if (error) { if (error) {
fs_err(sdp, "Error parsing journal for spectator mount.\n"); fs_err(sdp, "Error parsing journal for spectator mount.\n");
goto out_unlock; goto out_unlock;
......
...@@ -181,129 +181,6 @@ static int get_log_header(struct gfs2_jdesc *jd, unsigned int blk, ...@@ -181,129 +181,6 @@ static int get_log_header(struct gfs2_jdesc *jd, unsigned int blk,
return error; return error;
} }
/**
* find_good_lh - find a good log header
* @jd: the journal
* @blk: the segment to start searching from
* @lh: the log header to fill in
* @forward: if true search forward in the log, else search backward
*
* Call get_log_header() to get a log header for a segment, but if the
* segment is bad, either scan forward or backward until we find a good one.
*
* Returns: errno
*/
static int find_good_lh(struct gfs2_jdesc *jd, unsigned int *blk,
struct gfs2_log_header_host *head)
{
unsigned int orig_blk = *blk;
int error;
for (;;) {
error = get_log_header(jd, *blk, head);
if (error <= 0)
return error;
if (++*blk == jd->jd_blocks)
*blk = 0;
if (*blk == orig_blk) {
gfs2_consist_inode(GFS2_I(jd->jd_inode));
return -EIO;
}
}
}
/**
* jhead_scan - make sure we've found the head of the log
* @jd: the journal
* @head: this is filled in with the log descriptor of the head
*
* At this point, seg and lh should be either the head of the log or just
* before. Scan forward until we find the head.
*
* Returns: errno
*/
static int jhead_scan(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
{
unsigned int blk = head->lh_blkno;
struct gfs2_log_header_host lh;
int error;
for (;;) {
if (++blk == jd->jd_blocks)
blk = 0;
error = get_log_header(jd, blk, &lh);
if (error < 0)
return error;
if (error == 1)
continue;
if (lh.lh_sequence == head->lh_sequence) {
gfs2_consist_inode(GFS2_I(jd->jd_inode));
return -EIO;
}
if (lh.lh_sequence < head->lh_sequence)
break;
*head = lh;
}
return 0;
}
/**
* gfs2_find_jhead - find the head of a log
* @jd: the journal
* @head: the log descriptor for the head of the log is returned here
*
* Do a binary search of a journal and find the valid log entry with the
* highest sequence number. (i.e. the log head)
*
* Returns: errno
*/
int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
{
struct gfs2_log_header_host lh_1, lh_m;
u32 blk_1, blk_2, blk_m;
int error;
blk_1 = 0;
blk_2 = jd->jd_blocks - 1;
for (;;) {
blk_m = (blk_1 + blk_2) / 2;
error = find_good_lh(jd, &blk_1, &lh_1);
if (error)
return error;
error = find_good_lh(jd, &blk_m, &lh_m);
if (error)
return error;
if (blk_1 == blk_m || blk_m == blk_2)
break;
if (lh_1.lh_sequence <= lh_m.lh_sequence)
blk_1 = blk_m;
else
blk_2 = blk_m;
}
error = jhead_scan(jd, &lh_1);
if (error)
return error;
*head = lh_1;
return error;
}
/** /**
* foreach_descriptor - go through the active part of the log * foreach_descriptor - go through the active part of the log
* @jd: the journal * @jd: the journal
...@@ -316,7 +193,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head) ...@@ -316,7 +193,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
* Returns: errno * Returns: errno
*/ */
static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, static int foreach_descriptor(struct gfs2_jdesc *jd, u32 start,
unsigned int end, int pass) unsigned int end, int pass)
{ {
struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
...@@ -386,10 +263,12 @@ static void clean_journal(struct gfs2_jdesc *jd, ...@@ -386,10 +263,12 @@ static void clean_journal(struct gfs2_jdesc *jd,
struct gfs2_log_header_host *head) struct gfs2_log_header_host *head)
{ {
struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
u32 lblock = head->lh_blkno;
sdp->sd_log_flush_head = head->lh_blkno; gfs2_replay_incr_blk(jd, &lblock);
gfs2_replay_incr_blk(jd, &sdp->sd_log_flush_head); if (jd->jd_jid == sdp->sd_lockstruct.ls_jid)
gfs2_write_log_header(sdp, jd, head->lh_sequence + 1, 0, sdp->sd_log_flush_head = lblock;
gfs2_write_log_header(sdp, jd, head->lh_sequence + 1, 0, lblock,
GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY, GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY,
REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC); REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC);
} }
...@@ -467,7 +346,7 @@ void gfs2_recover_func(struct work_struct *work) ...@@ -467,7 +346,7 @@ void gfs2_recover_func(struct work_struct *work)
if (error) if (error)
goto fail_gunlock_ji; goto fail_gunlock_ji;
error = gfs2_find_jhead(jd, &head); error = gfs2_find_jhead(jd, &head, true);
if (error) if (error)
goto fail_gunlock_ji; goto fail_gunlock_ji;
t_jhd = ktime_get(); t_jhd = ktime_get();
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
extern struct workqueue_struct *gfs_recovery_wq; extern struct workqueue_struct *gfs_recovery_wq;
static inline void gfs2_replay_incr_blk(struct gfs2_jdesc *jd, unsigned int *blk) static inline void gfs2_replay_incr_blk(struct gfs2_jdesc *jd, u32 *blk)
{ {
if (++*blk == jd->jd_blocks) if (++*blk == jd->jd_blocks)
*blk = 0; *blk = 0;
...@@ -27,8 +27,6 @@ extern int gfs2_revoke_add(struct gfs2_jdesc *jd, u64 blkno, unsigned int where) ...@@ -27,8 +27,6 @@ extern int gfs2_revoke_add(struct gfs2_jdesc *jd, u64 blkno, unsigned int where)
extern int gfs2_revoke_check(struct gfs2_jdesc *jd, u64 blkno, unsigned int where); extern int gfs2_revoke_check(struct gfs2_jdesc *jd, u64 blkno, unsigned int where);
extern void gfs2_revoke_clean(struct gfs2_jdesc *jd); extern void gfs2_revoke_clean(struct gfs2_jdesc *jd);
extern int gfs2_find_jhead(struct gfs2_jdesc *jd,
struct gfs2_log_header_host *head);
extern int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd, bool wait); extern int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd, bool wait);
extern void gfs2_recover_func(struct work_struct *work); extern void gfs2_recover_func(struct work_struct *work);
extern int __get_log_header(struct gfs2_sbd *sdp, extern int __get_log_header(struct gfs2_sbd *sdp,
......
...@@ -1729,25 +1729,22 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm, ...@@ -1729,25 +1729,22 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,
static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext, static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
const struct gfs2_inode *ip, bool nowrap) const struct gfs2_inode *ip, bool nowrap)
{ {
bool scan_from_start = rbm->bii == 0 && rbm->offset == 0;
struct buffer_head *bh; struct buffer_head *bh;
int initial_bii; int last_bii;
u32 initial_offset;
int first_bii = rbm->bii;
u32 first_offset = rbm->offset;
u32 offset; u32 offset;
u8 *buffer; u8 *buffer;
int n = 0; bool wrapped = false;
int iters = rbm->rgd->rd_length;
int ret; int ret;
struct gfs2_bitmap *bi; struct gfs2_bitmap *bi;
struct gfs2_extent maxext = { .rbm.rgd = rbm->rgd, }; struct gfs2_extent maxext = { .rbm.rgd = rbm->rgd, };
/* If we are not starting at the beginning of a bitmap, then we /*
* need to add one to the bitmap count to ensure that we search * Determine the last bitmap to search. If we're not starting at the
* the starting bitmap twice. * beginning of a bitmap, we need to search that bitmap twice to scan
* the entire resource group.
*/ */
if (rbm->offset != 0) last_bii = rbm->bii - (rbm->offset == 0);
iters++;
while(1) { while(1) {
bi = rbm_bi(rbm); bi = rbm_bi(rbm);
...@@ -1761,47 +1758,46 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext, ...@@ -1761,47 +1758,46 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
WARN_ON(!buffer_uptodate(bh)); WARN_ON(!buffer_uptodate(bh));
if (state != GFS2_BLKST_UNLINKED && bi->bi_clone) if (state != GFS2_BLKST_UNLINKED && bi->bi_clone)
buffer = bi->bi_clone + bi->bi_offset; buffer = bi->bi_clone + bi->bi_offset;
initial_offset = rbm->offset;
offset = gfs2_bitfit(buffer, bi->bi_bytes, rbm->offset, state); offset = gfs2_bitfit(buffer, bi->bi_bytes, rbm->offset, state);
if (offset == BFITNOENT) if (offset == BFITNOENT) {
goto bitmap_full; if (state == GFS2_BLKST_FREE && rbm->offset == 0)
set_bit(GBF_FULL, &bi->bi_flags);
goto next_bitmap;
}
rbm->offset = offset; rbm->offset = offset;
if (ip == NULL) if (ip == NULL)
return 0; return 0;
initial_bii = rbm->bii;
ret = gfs2_reservation_check_and_update(rbm, ip, ret = gfs2_reservation_check_and_update(rbm, ip,
minext ? *minext : 0, minext ? *minext : 0,
&maxext); &maxext);
if (ret == 0) if (ret == 0)
return 0; return 0;
if (ret > 0) { if (ret > 0)
n += (rbm->bii - initial_bii);
goto next_iter; goto next_iter;
}
if (ret == -E2BIG) { if (ret == -E2BIG) {
rbm->bii = 0; rbm->bii = 0;
rbm->offset = 0; rbm->offset = 0;
n += (rbm->bii - initial_bii);
goto res_covered_end_of_rgrp; goto res_covered_end_of_rgrp;
} }
return ret; return ret;
bitmap_full: /* Mark bitmap as full and fall through */
if ((state == GFS2_BLKST_FREE) && initial_offset == 0)
set_bit(GBF_FULL, &bi->bi_flags);
next_bitmap: /* Find next bitmap in the rgrp */ next_bitmap: /* Find next bitmap in the rgrp */
rbm->offset = 0; rbm->offset = 0;
rbm->bii++; rbm->bii++;
if (rbm->bii == rbm->rgd->rd_length) if (rbm->bii == rbm->rgd->rd_length)
rbm->bii = 0; rbm->bii = 0;
res_covered_end_of_rgrp: res_covered_end_of_rgrp:
if ((rbm->bii == 0) && nowrap) if (rbm->bii == 0) {
if (wrapped)
break; break;
n++; wrapped = true;
if (nowrap)
break;
}
next_iter: next_iter:
if (n >= iters) /* Have we scanned the entire resource group? */
if (wrapped && rbm->bii > last_bii)
break; break;
} }
...@@ -1811,8 +1807,8 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext, ...@@ -1811,8 +1807,8 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
/* If the extent was too small, and it's smaller than the smallest /* If the extent was too small, and it's smaller than the smallest
to have failed before, remember for future reference that it's to have failed before, remember for future reference that it's
useless to search this rgrp again for this amount or more. */ useless to search this rgrp again for this amount or more. */
if ((first_offset == 0) && (first_bii == 0) && if (wrapped && (scan_from_start || rbm->bii > last_bii) &&
(*minext < rbm->rgd->rd_extfail_pt)) *minext < rbm->rgd->rd_extfail_pt)
rbm->rgd->rd_extfail_pt = *minext; rbm->rgd->rd_extfail_pt = *minext;
/* If the maximum extent we found is big enough to fulfill the /* If the maximum extent we found is big enough to fulfill the
...@@ -2444,7 +2440,7 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks, ...@@ -2444,7 +2440,7 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0); gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0);
if (dinode) if (dinode)
gfs2_trans_add_unrevoke(sdp, block, *nblocks); gfs2_trans_remove_revoke(sdp, block, *nblocks);
gfs2_quota_change(ip, *nblocks, 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);
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "util.h" #include "util.h"
#include "sys.h" #include "sys.h"
#include "xattr.h" #include "xattr.h"
#include "lops.h"
#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x) #define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
...@@ -425,7 +426,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp) ...@@ -425,7 +426,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
error = gfs2_find_jhead(sdp->sd_jdesc, &head); error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
if (error) if (error)
goto fail; goto fail;
...@@ -680,7 +681,7 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, ...@@ -680,7 +681,7 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp,
error = gfs2_jdesc_check(jd); error = gfs2_jdesc_check(jd);
if (error) if (error)
break; break;
error = gfs2_find_jhead(jd, &lh); error = gfs2_find_jhead(jd, &lh, false);
if (error) if (error)
break; break;
if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
...@@ -973,8 +974,7 @@ void gfs2_freeze_func(struct work_struct *work) ...@@ -973,8 +974,7 @@ void gfs2_freeze_func(struct work_struct *work)
if (error) { if (error) {
printk(KERN_INFO "GFS2: couldn't get freeze lock : %d\n", error); printk(KERN_INFO "GFS2: couldn't get freeze lock : %d\n", error);
gfs2_assert_withdraw(sdp, 0); gfs2_assert_withdraw(sdp, 0);
} } else {
else {
atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN); atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
error = thaw_super(sb); error = thaw_super(sb);
if (error) { if (error) {
...@@ -987,6 +987,8 @@ void gfs2_freeze_func(struct work_struct *work) ...@@ -987,6 +987,8 @@ void gfs2_freeze_func(struct work_struct *work)
gfs2_glock_dq_uninit(&freeze_gh); gfs2_glock_dq_uninit(&freeze_gh);
} }
deactivate_super(sb); deactivate_super(sb);
clear_bit_unlock(SDF_FS_FROZEN, &sdp->sd_flags);
wake_up_bit(&sdp->sd_flags, SDF_FS_FROZEN);
return; return;
} }
...@@ -1029,6 +1031,7 @@ static int gfs2_freeze(struct super_block *sb) ...@@ -1029,6 +1031,7 @@ static int gfs2_freeze(struct super_block *sb)
msleep(1000); msleep(1000);
} }
error = 0; error = 0;
set_bit(SDF_FS_FROZEN, &sdp->sd_flags);
out: out:
mutex_unlock(&sdp->sd_freeze_mutex); mutex_unlock(&sdp->sd_freeze_mutex);
return error; return error;
...@@ -1053,7 +1056,7 @@ static int gfs2_unfreeze(struct super_block *sb) ...@@ -1053,7 +1056,7 @@ static int gfs2_unfreeze(struct super_block *sb)
gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
mutex_unlock(&sdp->sd_freeze_mutex); mutex_unlock(&sdp->sd_freeze_mutex);
return 0; return wait_on_bit(&sdp->sd_flags, SDF_FS_FROZEN, TASK_INTERRUPTIBLE);
} }
/** /**
...@@ -1474,7 +1477,7 @@ static void gfs2_final_release_pages(struct gfs2_inode *ip) ...@@ -1474,7 +1477,7 @@ static void gfs2_final_release_pages(struct gfs2_inode *ip)
truncate_inode_pages(gfs2_glock2aspace(ip->i_gl), 0); truncate_inode_pages(gfs2_glock2aspace(ip->i_gl), 0);
truncate_inode_pages(&inode->i_data, 0); truncate_inode_pages(&inode->i_data, 0);
if (atomic_read(&gl->gl_revokes) == 0) { if (!test_bit(GLF_REVOKES, &gl->gl_flags)) {
clear_bit(GLF_LFLUSH, &gl->gl_flags); clear_bit(GLF_LFLUSH, &gl->gl_flags);
clear_bit(GLF_DIRTY, &gl->gl_flags); clear_bit(GLF_DIRTY, &gl->gl_flags);
} }
...@@ -1630,8 +1633,6 @@ static void gfs2_evict_inode(struct inode *inode) ...@@ -1630,8 +1633,6 @@ static void gfs2_evict_inode(struct inode *inode)
goto out_truncate; goto out_truncate;
} }
/* Case 1 starts here */
if (S_ISDIR(inode->i_mode) && if (S_ISDIR(inode->i_mode) &&
(ip->i_diskflags & GFS2_DIF_EXHASH)) { (ip->i_diskflags & GFS2_DIF_EXHASH)) {
error = gfs2_dir_exhash_dealloc(ip); error = gfs2_dir_exhash_dealloc(ip);
...@@ -1670,7 +1671,6 @@ static void gfs2_evict_inode(struct inode *inode) ...@@ -1670,7 +1671,6 @@ static void gfs2_evict_inode(struct inode *inode)
write_inode_now(inode, 1); write_inode_now(inode, 1);
gfs2_ail_flush(ip->i_gl, 0); gfs2_ail_flush(ip->i_gl, 0);
/* Case 2 starts here */
error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
if (error) if (error)
goto out_unlock; goto out_unlock;
...@@ -1680,7 +1680,6 @@ static void gfs2_evict_inode(struct inode *inode) ...@@ -1680,7 +1680,6 @@ static void gfs2_evict_inode(struct inode *inode)
gfs2_trans_end(sdp); gfs2_trans_end(sdp);
out_unlock: out_unlock:
/* Error path for case 1 */
if (gfs2_rs_active(&ip->i_res)) if (gfs2_rs_active(&ip->i_res))
gfs2_rs_deltree(&ip->i_res); gfs2_rs_deltree(&ip->i_res);
...@@ -1699,7 +1698,6 @@ static void gfs2_evict_inode(struct inode *inode) ...@@ -1699,7 +1698,6 @@ static void gfs2_evict_inode(struct inode *inode)
if (error && error != GLR_TRYFAILED && error != -EROFS) if (error && error != GLR_TRYFAILED && error != -EROFS)
fs_warn(sdp, "gfs2_evict_inode: %d\n", error); fs_warn(sdp, "gfs2_evict_inode: %d\n", error);
out: out:
/* Case 3 starts here */
truncate_inode_pages_final(&inode->i_data); truncate_inode_pages_final(&inode->i_data);
gfs2_rsqa_delete(ip, NULL); gfs2_rsqa_delete(ip, NULL);
gfs2_ordered_del_inode(ip); gfs2_ordered_del_inode(ip);
......
...@@ -253,14 +253,14 @@ void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd) ...@@ -253,14 +253,14 @@ void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
tr->tr_num_revoke++; tr->tr_num_revoke++;
} }
void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len) void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len)
{ {
struct gfs2_bufdata *bd, *tmp; struct gfs2_bufdata *bd, *tmp;
struct gfs2_trans *tr = current->journal_info; struct gfs2_trans *tr = current->journal_info;
unsigned int n = len; unsigned int n = len;
gfs2_log_lock(sdp); gfs2_log_lock(sdp);
list_for_each_entry_safe(bd, tmp, &sdp->sd_log_le_revoke, bd_list) { list_for_each_entry_safe(bd, tmp, &sdp->sd_log_revokes, bd_list) {
if ((bd->bd_blkno >= blkno) && (bd->bd_blkno < (blkno + len))) { if ((bd->bd_blkno >= blkno) && (bd->bd_blkno < (blkno + len))) {
list_del_init(&bd->bd_list); list_del_init(&bd->bd_list);
gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke); gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke);
......
...@@ -44,6 +44,6 @@ extern void gfs2_trans_end(struct gfs2_sbd *sdp); ...@@ -44,6 +44,6 @@ extern void gfs2_trans_end(struct gfs2_sbd *sdp);
extern void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh); extern void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh);
extern void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh); extern void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh);
extern void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd); extern void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd);
extern void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len); extern void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len);
#endif /* __TRANS_DOT_H__ */ #endif /* __TRANS_DOT_H__ */
...@@ -631,7 +631,7 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp) ...@@ -631,7 +631,7 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp)
error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL); error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL);
if (error) if (error)
return error; return error;
gfs2_trans_add_unrevoke(sdp, block, 1); gfs2_trans_remove_revoke(sdp, block, 1);
*bhp = gfs2_meta_new(ip->i_gl, block); *bhp = gfs2_meta_new(ip->i_gl, block);
gfs2_trans_add_meta(ip->i_gl, *bhp); gfs2_trans_add_meta(ip->i_gl, *bhp);
gfs2_metatype_set(*bhp, GFS2_METATYPE_EA, GFS2_FORMAT_EA); gfs2_metatype_set(*bhp, GFS2_METATYPE_EA, GFS2_FORMAT_EA);
...@@ -693,7 +693,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, ...@@ -693,7 +693,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL); error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL);
if (error) if (error)
return error; return error;
gfs2_trans_add_unrevoke(sdp, block, 1); gfs2_trans_remove_revoke(sdp, block, 1);
bh = gfs2_meta_new(ip->i_gl, block); bh = gfs2_meta_new(ip->i_gl, block);
gfs2_trans_add_meta(ip->i_gl, bh); gfs2_trans_add_meta(ip->i_gl, bh);
gfs2_metatype_set(bh, GFS2_METATYPE_ED, GFS2_FORMAT_ED); gfs2_metatype_set(bh, GFS2_METATYPE_ED, GFS2_FORMAT_ED);
...@@ -997,7 +997,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, ...@@ -997,7 +997,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er,
error = gfs2_alloc_blocks(ip, &blk, &n, 0, NULL); error = gfs2_alloc_blocks(ip, &blk, &n, 0, NULL);
if (error) if (error)
return error; return error;
gfs2_trans_add_unrevoke(sdp, blk, 1); gfs2_trans_remove_revoke(sdp, blk, 1);
indbh = gfs2_meta_new(ip->i_gl, blk); indbh = gfs2_meta_new(ip->i_gl, blk);
gfs2_trans_add_meta(ip->i_gl, indbh); gfs2_trans_add_meta(ip->i_gl, indbh);
gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment