Skip to content

Commit 87e9951

Browse files
Christoph HellwigAl Viro
authored andcommitted
kill BH_Ordered flag
Instead of abusing a buffer_head flag just add a variant of sync_dirty_buffer which allows passing the exact type of write flag required. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent dad5eb6 commit 87e9951

5 files changed

Lines changed: 63 additions & 73 deletions

File tree

‎fs/buffer.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,13 +2911,6 @@ int submit_bh(int rw, struct buffer_head * bh)
29112911
BUG_ON(buffer_delay(bh));
29122912
BUG_ON(buffer_unwritten(bh));
29132913

2914-
/*
2915-
* Mask in barrier bit for a write (could be either a WRITE or a
2916-
* WRITE_SYNC
2917-
*/
2918-
if (buffer_ordered(bh) && (rw & WRITE))
2919-
rw |= WRITE_BARRIER;
2920-
29212914
/*
29222915
* Only clear out a write error when rewriting
29232916
*/
@@ -3021,7 +3014,7 @@ EXPORT_SYMBOL(ll_rw_block);
30213014
* and then start new I/O and then wait upon it. The caller must have a ref on
30223015
* the buffer_head.
30233016
*/
3024-
int sync_dirty_buffer(struct buffer_head *bh)
3017+
int __sync_dirty_buffer(struct buffer_head *bh, int rw)
30253018
{
30263019
int ret = 0;
30273020

@@ -3030,7 +3023,7 @@ int sync_dirty_buffer(struct buffer_head *bh)
30303023
if (test_clear_buffer_dirty(bh)) {
30313024
get_bh(bh);
30323025
bh->b_end_io = end_buffer_write_sync;
3033-
ret = submit_bh(WRITE_SYNC, bh);
3026+
ret = submit_bh(rw, bh);
30343027
wait_on_buffer(bh);
30353028
if (buffer_eopnotsupp(bh)) {
30363029
clear_buffer_eopnotsupp(bh);
@@ -3043,6 +3036,12 @@ int sync_dirty_buffer(struct buffer_head *bh)
30433036
}
30443037
return ret;
30453038
}
3039+
EXPORT_SYMBOL(__sync_dirty_buffer);
3040+
3041+
int sync_dirty_buffer(struct buffer_head *bh)
3042+
{
3043+
return __sync_dirty_buffer(bh, WRITE_SYNC);
3044+
}
30463045
EXPORT_SYMBOL(sync_dirty_buffer);
30473046

30483047
/*

‎fs/jbd/commit.c‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ static int journal_write_commit_record(journal_t *journal,
119119
struct buffer_head *bh;
120120
journal_header_t *header;
121121
int ret;
122-
int barrier_done = 0;
123122

124123
if (is_journal_aborted(journal))
125124
return 0;
@@ -137,34 +136,36 @@ static int journal_write_commit_record(journal_t *journal,
137136

138137
JBUFFER_TRACE(descriptor, "write commit block");
139138
set_buffer_dirty(bh);
139+
140140
if (journal->j_flags & JFS_BARRIER) {
141-
set_buffer_ordered(bh);
142-
barrier_done = 1;
143-
}
144-
ret = sync_dirty_buffer(bh);
145-
if (barrier_done)
146-
clear_buffer_ordered(bh);
147-
/* is it possible for another commit to fail at roughly
148-
* the same time as this one? If so, we don't want to
149-
* trust the barrier flag in the super, but instead want
150-
* to remember if we sent a barrier request
151-
*/
152-
if (ret == -EOPNOTSUPP && barrier_done) {
153-
char b[BDEVNAME_SIZE];
141+
ret = __sync_dirty_buffer(bh, WRITE_SYNC | WRITE_BARRIER);
154142

155-
printk(KERN_WARNING
156-
"JBD: barrier-based sync failed on %s - "
157-
"disabling barriers\n",
158-
bdevname(journal->j_dev, b));
159-
spin_lock(&journal->j_state_lock);
160-
journal->j_flags &= ~JFS_BARRIER;
161-
spin_unlock(&journal->j_state_lock);
143+
/*
144+
* Is it possible for another commit to fail at roughly
145+
* the same time as this one? If so, we don't want to
146+
* trust the barrier flag in the super, but instead want
147+
* to remember if we sent a barrier request
148+
*/
149+
if (ret == -EOPNOTSUPP) {
150+
char b[BDEVNAME_SIZE];
162151

163-
/* And try again, without the barrier */
164-
set_buffer_uptodate(bh);
165-
set_buffer_dirty(bh);
152+
printk(KERN_WARNING
153+
"JBD: barrier-based sync failed on %s - "
154+
"disabling barriers\n",
155+
bdevname(journal->j_dev, b));
156+
spin_lock(&journal->j_state_lock);
157+
journal->j_flags &= ~JFS_BARRIER;
158+
spin_unlock(&journal->j_state_lock);
159+
160+
/* And try again, without the barrier */
161+
set_buffer_uptodate(bh);
162+
set_buffer_dirty(bh);
163+
ret = sync_dirty_buffer(bh);
164+
}
165+
} else {
166166
ret = sync_dirty_buffer(bh);
167167
}
168+
168169
put_bh(bh); /* One for getblk() */
169170
journal_put_journal_head(descriptor);
170171

‎fs/jbd2/commit.c‎

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ static int journal_submit_commit_record(journal_t *journal,
101101
struct commit_header *tmp;
102102
struct buffer_head *bh;
103103
int ret;
104-
int barrier_done = 0;
105104
struct timespec now = current_kernel_time();
106105

107106
if (is_journal_aborted(journal))
@@ -136,30 +135,22 @@ static int journal_submit_commit_record(journal_t *journal,
136135
if (journal->j_flags & JBD2_BARRIER &&
137136
!JBD2_HAS_INCOMPAT_FEATURE(journal,
138137
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
139-
set_buffer_ordered(bh);
140-
barrier_done = 1;
141-
}
142-
ret = submit_bh(WRITE_SYNC_PLUG, bh);
143-
if (barrier_done)
144-
clear_buffer_ordered(bh);
145-
146-
/* is it possible for another commit to fail at roughly
147-
* the same time as this one? If so, we don't want to
148-
* trust the barrier flag in the super, but instead want
149-
* to remember if we sent a barrier request
150-
*/
151-
if (ret == -EOPNOTSUPP && barrier_done) {
152-
printk(KERN_WARNING
153-
"JBD2: Disabling barriers on %s, "
154-
"not supported by device\n", journal->j_devname);
155-
write_lock(&journal->j_state_lock);
156-
journal->j_flags &= ~JBD2_BARRIER;
157-
write_unlock(&journal->j_state_lock);
138+
ret = submit_bh(WRITE_SYNC_PLUG | WRITE_BARRIER, bh);
139+
if (ret == -EOPNOTSUPP) {
140+
printk(KERN_WARNING
141+
"JBD2: Disabling barriers on %s, "
142+
"not supported by device\n", journal->j_devname);
143+
write_lock(&journal->j_state_lock);
144+
journal->j_flags &= ~JBD2_BARRIER;
145+
write_unlock(&journal->j_state_lock);
158146

159-
/* And try again, without the barrier */
160-
lock_buffer(bh);
161-
set_buffer_uptodate(bh);
162-
clear_buffer_dirty(bh);
147+
/* And try again, without the barrier */
148+
lock_buffer(bh);
149+
set_buffer_uptodate(bh);
150+
clear_buffer_dirty(bh);
151+
ret = submit_bh(WRITE_SYNC_PLUG, bh);
152+
}
153+
} else {
163154
ret = submit_bh(WRITE_SYNC_PLUG, bh);
164155
}
165156
*cbh = bh;

‎fs/nilfs2/super.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,24 +175,24 @@ static int nilfs_sync_super(struct nilfs_sb_info *sbi, int flag)
175175
{
176176
struct the_nilfs *nilfs = sbi->s_nilfs;
177177
int err;
178-
int barrier_done = 0;
179178

180-
if (nilfs_test_opt(sbi, BARRIER)) {
181-
set_buffer_ordered(nilfs->ns_sbh[0]);
182-
barrier_done = 1;
183-
}
184179
retry:
185180
set_buffer_dirty(nilfs->ns_sbh[0]);
186-
err = sync_dirty_buffer(nilfs->ns_sbh[0]);
187-
if (err == -EOPNOTSUPP && barrier_done) {
188-
nilfs_warning(sbi->s_super, __func__,
189-
"barrier-based sync failed. "
190-
"disabling barriers\n");
191-
nilfs_clear_opt(sbi, BARRIER);
192-
barrier_done = 0;
193-
clear_buffer_ordered(nilfs->ns_sbh[0]);
194-
goto retry;
181+
182+
if (nilfs_test_opt(sbi, BARRIER)) {
183+
err = __sync_dirty_buffer(nilfs->ns_sbh[0],
184+
WRITE_SYNC | WRITE_BARRIER);
185+
if (err == -EOPNOTSUPP) {
186+
nilfs_warning(sbi->s_super, __func__,
187+
"barrier-based sync failed. "
188+
"disabling barriers\n");
189+
nilfs_clear_opt(sbi, BARRIER);
190+
goto retry;
191+
}
192+
} else {
193+
err = sync_dirty_buffer(nilfs->ns_sbh[0]);
195194
}
195+
196196
if (unlikely(err)) {
197197
printk(KERN_ERR
198198
"NILFS: unable to write superblock (err=%d)\n", err);

‎include/linux/buffer_head.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ enum bh_state_bits {
3232
BH_Delay, /* Buffer is not yet allocated on disk */
3333
BH_Boundary, /* Block is followed by a discontiguity */
3434
BH_Write_EIO, /* I/O error on write */
35-
BH_Ordered, /* ordered write */
3635
BH_Eopnotsupp, /* operation not supported (barrier) */
3736
BH_Unwritten, /* Buffer is allocated on disk but not written */
3837
BH_Quiet, /* Buffer Error Prinks to be quiet */
@@ -125,7 +124,6 @@ BUFFER_FNS(Async_Write, async_write)
125124
BUFFER_FNS(Delay, delay)
126125
BUFFER_FNS(Boundary, boundary)
127126
BUFFER_FNS(Write_EIO, write_io_error)
128-
BUFFER_FNS(Ordered, ordered)
129127
BUFFER_FNS(Eopnotsupp, eopnotsupp)
130128
BUFFER_FNS(Unwritten, unwritten)
131129

@@ -183,6 +181,7 @@ void unlock_buffer(struct buffer_head *bh);
183181
void __lock_buffer(struct buffer_head *bh);
184182
void ll_rw_block(int, int, struct buffer_head * bh[]);
185183
int sync_dirty_buffer(struct buffer_head *bh);
184+
int __sync_dirty_buffer(struct buffer_head *bh, int rw);
186185
int submit_bh(int, struct buffer_head *);
187186
void write_boundary_block(struct block_device *bdev,
188187
sector_t bblock, unsigned blocksize);

0 commit comments

Comments
 (0)