Skip to content

Commit 6c337ad

Browse files
committed
Merge tag 'gfs2-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw
Pull GFS2 updates from Steven Whitehouse: "This is possibly the smallest ever set of GFS2 patches for a merge window. Also, most of them are bug fixes this time. Two of my three patches (moving gfs2_sync_meta and merging the two writepage implementations) are clean ups with the third (taking the glock ref in examine_bucket) being a fix for a difficult to hit race condition. The removal of an unused memory barrier is a clean up from Bob Peterson, and the "spectator" relates to a rarely used mount option. Ben Marzinski's patch fixes a corner case where the incorrect inode flags were being set, resulting in incorrect behaviour on fsync" * tag 'gfs2-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw: GFS2: dirty inode correctly in gfs2_write_end GFS2: Don't flag consistency error if first mounter is a spectator GFS2: Remove unnecessary memory barrier GFS2: Merge ordered and writeback writepage GFS2: Take glock reference in examine_bucket() GFS2: Move gfs2_sync_meta to lops.c
2 parents 6cccc7d + 0c90180 commit 6c337ad

File tree

7 files changed

+99
-77
lines changed

7 files changed

+99
-77
lines changed

fs/gfs2/aops.c

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,13 @@ static int gfs2_writepage_common(struct page *page,
122122
}
123123

124124
/**
125-
* gfs2_writeback_writepage - Write page for writeback mappings
125+
* gfs2_writepage - Write page for writeback mappings
126126
* @page: The page
127127
* @wbc: The writeback control
128128
*
129129
*/
130130

131-
static int gfs2_writeback_writepage(struct page *page,
132-
struct writeback_control *wbc)
131+
static int gfs2_writepage(struct page *page, struct writeback_control *wbc)
133132
{
134133
int ret;
135134

@@ -140,32 +139,6 @@ static int gfs2_writeback_writepage(struct page *page,
140139
return nobh_writepage(page, gfs2_get_block_noalloc, wbc);
141140
}
142141

143-
/**
144-
* gfs2_ordered_writepage - Write page for ordered data files
145-
* @page: The page to write
146-
* @wbc: The writeback control
147-
*
148-
*/
149-
150-
static int gfs2_ordered_writepage(struct page *page,
151-
struct writeback_control *wbc)
152-
{
153-
struct inode *inode = page->mapping->host;
154-
struct gfs2_inode *ip = GFS2_I(inode);
155-
int ret;
156-
157-
ret = gfs2_writepage_common(page, wbc);
158-
if (ret <= 0)
159-
return ret;
160-
161-
if (!page_has_buffers(page)) {
162-
create_empty_buffers(page, inode->i_sb->s_blocksize,
163-
(1 << BH_Dirty)|(1 << BH_Uptodate));
164-
}
165-
gfs2_page_add_databufs(ip, page, 0, inode->i_sb->s_blocksize-1);
166-
return block_write_full_page(page, gfs2_get_block_noalloc, wbc);
167-
}
168-
169142
/**
170143
* __gfs2_jdata_writepage - The core of jdata writepage
171144
* @page: The page to write
@@ -842,6 +815,8 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
842815
unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
843816
unsigned int to = from + len;
844817
int ret;
818+
struct gfs2_trans *tr = current->journal_info;
819+
BUG_ON(!tr);
845820

846821
BUG_ON(gfs2_glock_is_locked_by_me(ip->i_gl) == NULL);
847822

@@ -852,15 +827,18 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
852827
goto failed;
853828
}
854829

855-
gfs2_trans_add_meta(ip->i_gl, dibh);
856-
857830
if (gfs2_is_stuffed(ip))
858831
return gfs2_stuffed_write_end(inode, dibh, pos, len, copied, page);
859832

860833
if (!gfs2_is_writeback(ip))
861834
gfs2_page_add_databufs(ip, page, from, to);
862835

863836
ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
837+
if (tr->tr_num_buf_new)
838+
__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
839+
else
840+
gfs2_trans_add_meta(ip->i_gl, dibh);
841+
864842

865843
if (inode == sdp->sd_rindex) {
866844
adjust_fs_space(inode);
@@ -1107,7 +1085,7 @@ int gfs2_releasepage(struct page *page, gfp_t gfp_mask)
11071085
}
11081086

11091087
static const struct address_space_operations gfs2_writeback_aops = {
1110-
.writepage = gfs2_writeback_writepage,
1088+
.writepage = gfs2_writepage,
11111089
.writepages = gfs2_writepages,
11121090
.readpage = gfs2_readpage,
11131091
.readpages = gfs2_readpages,
@@ -1123,7 +1101,7 @@ static const struct address_space_operations gfs2_writeback_aops = {
11231101
};
11241102

11251103
static const struct address_space_operations gfs2_ordered_aops = {
1126-
.writepage = gfs2_ordered_writepage,
1104+
.writepage = gfs2_writepage,
11271105
.writepages = gfs2_writepages,
11281106
.readpage = gfs2_readpage,
11291107
.readpages = gfs2_readpages,

fs/gfs2/file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
650650
{
651651
struct address_space *mapping = file->f_mapping;
652652
struct inode *inode = mapping->host;
653-
int sync_state = inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC);
653+
int sync_state = inode->i_state & I_DIRTY;
654654
struct gfs2_inode *ip = GFS2_I(inode);
655655
int ret = 0, ret1 = 0;
656656

@@ -660,6 +660,8 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
660660
return ret1;
661661
}
662662

663+
if (!gfs2_is_jdata(ip))
664+
sync_state &= ~I_DIRTY_PAGES;
663665
if (datasync)
664666
sync_state &= ~I_DIRTY_SYNC;
665667

fs/gfs2/glock.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,6 @@ __acquires(&lru_lock)
14111411
if (demote_ok(gl))
14121412
handle_callback(gl, LM_ST_UNLOCKED, 0, false);
14131413
WARN_ON(!test_and_clear_bit(GLF_LOCK, &gl->gl_flags));
1414-
smp_mb__after_clear_bit();
14151414
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
14161415
gfs2_glock_put_nolock(gl);
14171416
spin_unlock(&gl->gl_spin);
@@ -1488,7 +1487,7 @@ static void examine_bucket(glock_examiner examiner, const struct gfs2_sbd *sdp,
14881487

14891488
rcu_read_lock();
14901489
hlist_bl_for_each_entry_rcu(gl, pos, head, gl_list) {
1491-
if ((gl->gl_sbd == sdp) && atomic_read(&gl->gl_ref))
1490+
if ((gl->gl_sbd == sdp) && atomic_inc_not_zero(&gl->gl_ref))
14921491
examiner(gl);
14931492
}
14941493
rcu_read_unlock();
@@ -1508,18 +1507,17 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
15081507
* thaw_glock - thaw out a glock which has an unprocessed reply waiting
15091508
* @gl: The glock to thaw
15101509
*
1511-
* N.B. When we freeze a glock, we leave a ref to the glock outstanding,
1512-
* so this has to result in the ref count being dropped by one.
15131510
*/
15141511

15151512
static void thaw_glock(struct gfs2_glock *gl)
15161513
{
15171514
if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))
1518-
return;
1515+
goto out;
15191516
set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1520-
gfs2_glock_hold(gl);
1521-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1517+
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0) {
1518+
out:
15221519
gfs2_glock_put(gl);
1520+
}
15231521
}
15241522

15251523
/**
@@ -1536,7 +1534,6 @@ static void clear_glock(struct gfs2_glock *gl)
15361534
if (gl->gl_state != LM_ST_UNLOCKED)
15371535
handle_callback(gl, LM_ST_UNLOCKED, 0, false);
15381536
spin_unlock(&gl->gl_spin);
1539-
gfs2_glock_hold(gl);
15401537
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
15411538
gfs2_glock_put(gl);
15421539
}

fs/gfs2/lops.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,24 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
579579
return error;
580580
}
581581

582+
/**
583+
* gfs2_meta_sync - Sync all buffers associated with a glock
584+
* @gl: The glock
585+
*
586+
*/
587+
588+
static void gfs2_meta_sync(struct gfs2_glock *gl)
589+
{
590+
struct address_space *mapping = gfs2_glock2aspace(gl);
591+
int error;
592+
593+
filemap_fdatawrite(mapping);
594+
error = filemap_fdatawait(mapping);
595+
596+
if (error)
597+
gfs2_io_error(gl->gl_sbd);
598+
}
599+
582600
static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
583601
{
584602
struct gfs2_inode *ip = GFS2_I(jd->jd_inode);

fs/gfs2/meta_io.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,6 @@ const struct address_space_operations gfs2_meta_aops = {
9797
.releasepage = gfs2_releasepage,
9898
};
9999

100-
/**
101-
* gfs2_meta_sync - Sync all buffers associated with a glock
102-
* @gl: The glock
103-
*
104-
*/
105-
106-
void gfs2_meta_sync(struct gfs2_glock *gl)
107-
{
108-
struct address_space *mapping = gfs2_glock2aspace(gl);
109-
int error;
110-
111-
filemap_fdatawrite(mapping);
112-
error = filemap_fdatawait(mapping);
113-
114-
if (error)
115-
gfs2_io_error(gl->gl_sbd);
116-
}
117-
118100
/**
119101
* gfs2_getbuf - Get a buffer with a given address space
120102
* @gl: the glock

fs/gfs2/meta_io.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,17 @@ static inline struct gfs2_sbd *gfs2_mapping2sbd(struct address_space *mapping)
4848
return inode->i_sb->s_fs_info;
4949
}
5050

51-
void gfs2_meta_sync(struct gfs2_glock *gl);
52-
53-
struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno);
54-
int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno,
55-
int flags, struct buffer_head **bhp);
56-
int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh);
57-
struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create);
58-
59-
void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr,
60-
int meta);
61-
62-
void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen);
63-
64-
int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num,
65-
struct buffer_head **bhp);
51+
extern struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno);
52+
extern int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags,
53+
struct buffer_head **bhp);
54+
extern int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh);
55+
extern struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno,
56+
int create);
57+
extern void gfs2_remove_from_journal(struct buffer_head *bh,
58+
struct gfs2_trans *tr, int meta);
59+
extern void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen);
60+
extern int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num,
61+
struct buffer_head **bhp);
6662

6763
static inline int gfs2_meta_inode_buffer(struct gfs2_inode *ip,
6864
struct buffer_head **bhp)

fs/gfs2/ops_fstype.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,48 @@ static int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
646646
return error;
647647
}
648648

649+
/**
650+
* check_journal_clean - Make sure a journal is clean for a spectator mount
651+
* @sdp: The GFS2 superblock
652+
* @jd: The journal descriptor
653+
*
654+
* Returns: 0 if the journal is clean or locked, else an error
655+
*/
656+
static int check_journal_clean(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd)
657+
{
658+
int error;
659+
struct gfs2_holder j_gh;
660+
struct gfs2_log_header_host head;
661+
struct gfs2_inode *ip;
662+
663+
ip = GFS2_I(jd->jd_inode);
664+
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_NOEXP |
665+
GL_EXACT | GL_NOCACHE, &j_gh);
666+
if (error) {
667+
fs_err(sdp, "Error locking journal for spectator mount.\n");
668+
return -EPERM;
669+
}
670+
error = gfs2_jdesc_check(jd);
671+
if (error) {
672+
fs_err(sdp, "Error checking journal for spectator mount.\n");
673+
goto out_unlock;
674+
}
675+
error = gfs2_find_jhead(jd, &head);
676+
if (error) {
677+
fs_err(sdp, "Error parsing journal for spectator mount.\n");
678+
goto out_unlock;
679+
}
680+
if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
681+
error = -EPERM;
682+
fs_err(sdp, "jid=%u: Journal is dirty, so the first mounter "
683+
"must not be a spectator.\n", jd->jd_jid);
684+
}
685+
686+
out_unlock:
687+
gfs2_glock_dq_uninit(&j_gh);
688+
return error;
689+
}
690+
649691
static int init_journal(struct gfs2_sbd *sdp, int undo)
650692
{
651693
struct inode *master = sdp->sd_master_dir->d_inode;
@@ -732,8 +774,15 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
732774
if (sdp->sd_lockstruct.ls_first) {
733775
unsigned int x;
734776
for (x = 0; x < sdp->sd_journals; x++) {
735-
error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x),
736-
true);
777+
struct gfs2_jdesc *jd = gfs2_jdesc_find(sdp, x);
778+
779+
if (sdp->sd_args.ar_spectator) {
780+
error = check_journal_clean(sdp, jd);
781+
if (error)
782+
goto fail_jinode_gh;
783+
continue;
784+
}
785+
error = gfs2_recover_journal(jd, true);
737786
if (error) {
738787
fs_err(sdp, "error recovering journal %u: %d\n",
739788
x, error);

0 commit comments

Comments
 (0)