Skip to content

Commit e1cc485

Browse files
committed
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
Pull ext3 & udf fixes from Jan Kara: "Shortlog pretty much says it all. The interesting bits are UDF support for direct IO and ext3 fix for a long standing oops in data=journal mode." * 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: jbd: Fix assertion failure in commit code due to lacking transaction credits UDF: Add support for O_DIRECT ext3: Replace 0 with NULL for pointer in super.c file udf: add writepages support for udf ext3: don't clear orphan list on ro mount with errors reiserfs: Make reiserfs_xattr_handlers static
2 parents 4d6d367 + 09e05d4 commit e1cc485

6 files changed

Lines changed: 136 additions & 51 deletions

File tree

‎fs/ext3/super.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ static int parse_options (char *options, struct super_block *sb,
980980
* Initialize args struct so we know whether arg was
981981
* found; some options take optional arguments.
982982
*/
983-
args[0].to = args[0].from = 0;
983+
args[0].to = args[0].from = NULL;
984984
token = match_token(p, tokens, args);
985985
switch (token) {
986986
case Opt_bsd_df:
@@ -1484,10 +1484,12 @@ static void ext3_orphan_cleanup (struct super_block * sb,
14841484
}
14851485

14861486
if (EXT3_SB(sb)->s_mount_state & EXT3_ERROR_FS) {
1487-
if (es->s_last_orphan)
1487+
/* don't clear list on RO mount w/ errors */
1488+
if (es->s_last_orphan && !(s_flags & MS_RDONLY)) {
14881489
jbd_debug(1, "Errors on filesystem, "
14891490
"clearing orphan list.\n");
1490-
es->s_last_orphan = 0;
1491+
es->s_last_orphan = 0;
1492+
}
14911493
jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
14921494
return;
14931495
}

‎fs/jbd/commit.c‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ static void release_buffer_page(struct buffer_head *bh)
8686
static void release_data_buffer(struct buffer_head *bh)
8787
{
8888
if (buffer_freed(bh)) {
89+
WARN_ON_ONCE(buffer_dirty(bh));
8990
clear_buffer_freed(bh);
91+
clear_buffer_mapped(bh);
92+
clear_buffer_new(bh);
93+
clear_buffer_req(bh);
94+
bh->b_bdev = NULL;
9095
release_buffer_page(bh);
9196
} else
9297
put_bh(bh);
@@ -866,17 +871,35 @@ void journal_commit_transaction(journal_t *journal)
866871
* there's no point in keeping a checkpoint record for
867872
* it. */
868873

869-
/* A buffer which has been freed while still being
870-
* journaled by a previous transaction may end up still
871-
* being dirty here, but we want to avoid writing back
872-
* that buffer in the future after the "add to orphan"
873-
* operation been committed, That's not only a performance
874-
* gain, it also stops aliasing problems if the buffer is
875-
* left behind for writeback and gets reallocated for another
876-
* use in a different page. */
877-
if (buffer_freed(bh) && !jh->b_next_transaction) {
878-
clear_buffer_freed(bh);
879-
clear_buffer_jbddirty(bh);
874+
/*
875+
* A buffer which has been freed while still being journaled by
876+
* a previous transaction.
877+
*/
878+
if (buffer_freed(bh)) {
879+
/*
880+
* If the running transaction is the one containing
881+
* "add to orphan" operation (b_next_transaction !=
882+
* NULL), we have to wait for that transaction to
883+
* commit before we can really get rid of the buffer.
884+
* So just clear b_modified to not confuse transaction
885+
* credit accounting and refile the buffer to
886+
* BJ_Forget of the running transaction. If the just
887+
* committed transaction contains "add to orphan"
888+
* operation, we can completely invalidate the buffer
889+
* now. We are rather throughout in that since the
890+
* buffer may be still accessible when blocksize <
891+
* pagesize and it is attached to the last partial
892+
* page.
893+
*/
894+
jh->b_modified = 0;
895+
if (!jh->b_next_transaction) {
896+
clear_buffer_freed(bh);
897+
clear_buffer_jbddirty(bh);
898+
clear_buffer_mapped(bh);
899+
clear_buffer_new(bh);
900+
clear_buffer_req(bh);
901+
bh->b_bdev = NULL;
902+
}
880903
}
881904

882905
if (buffer_jbddirty(bh)) {

‎fs/jbd/transaction.c‎

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,15 +1843,16 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
18431843
* We're outside-transaction here. Either or both of j_running_transaction
18441844
* and j_committing_transaction may be NULL.
18451845
*/
1846-
static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1846+
static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh,
1847+
int partial_page)
18471848
{
18481849
transaction_t *transaction;
18491850
struct journal_head *jh;
18501851
int may_free = 1;
1851-
int ret;
18521852

18531853
BUFFER_TRACE(bh, "entry");
18541854

1855+
retry:
18551856
/*
18561857
* It is safe to proceed here without the j_list_lock because the
18571858
* buffers cannot be stolen by try_to_free_buffers as long as we are
@@ -1879,10 +1880,18 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
18791880
* clear the buffer dirty bit at latest at the moment when the
18801881
* transaction marking the buffer as freed in the filesystem
18811882
* structures is committed because from that moment on the
1882-
* buffer can be reallocated and used by a different page.
1883+
* block can be reallocated and used by a different page.
18831884
* Since the block hasn't been freed yet but the inode has
18841885
* already been added to orphan list, it is safe for us to add
18851886
* the buffer to BJ_Forget list of the newest transaction.
1887+
*
1888+
* Also we have to clear buffer_mapped flag of a truncated buffer
1889+
* because the buffer_head may be attached to the page straddling
1890+
* i_size (can happen only when blocksize < pagesize) and thus the
1891+
* buffer_head can be reused when the file is extended again. So we end
1892+
* up keeping around invalidated buffers attached to transactions'
1893+
* BJ_Forget list just to stop checkpointing code from cleaning up
1894+
* the transaction this buffer was modified in.
18861895
*/
18871896
transaction = jh->b_transaction;
18881897
if (transaction == NULL) {
@@ -1909,27 +1918,19 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
19091918
* committed, the buffer won't be needed any
19101919
* longer. */
19111920
JBUFFER_TRACE(jh, "checkpointed: add to BJ_Forget");
1912-
ret = __dispose_buffer(jh,
1921+
may_free = __dispose_buffer(jh,
19131922
journal->j_running_transaction);
1914-
journal_put_journal_head(jh);
1915-
spin_unlock(&journal->j_list_lock);
1916-
jbd_unlock_bh_state(bh);
1917-
spin_unlock(&journal->j_state_lock);
1918-
return ret;
1923+
goto zap_buffer;
19191924
} else {
19201925
/* There is no currently-running transaction. So the
19211926
* orphan record which we wrote for this file must have
19221927
* passed into commit. We must attach this buffer to
19231928
* the committing transaction, if it exists. */
19241929
if (journal->j_committing_transaction) {
19251930
JBUFFER_TRACE(jh, "give to committing trans");
1926-
ret = __dispose_buffer(jh,
1931+
may_free = __dispose_buffer(jh,
19271932
journal->j_committing_transaction);
1928-
journal_put_journal_head(jh);
1929-
spin_unlock(&journal->j_list_lock);
1930-
jbd_unlock_bh_state(bh);
1931-
spin_unlock(&journal->j_state_lock);
1932-
return ret;
1933+
goto zap_buffer;
19331934
} else {
19341935
/* The orphan record's transaction has
19351936
* committed. We can cleanse this buffer */
@@ -1950,10 +1951,24 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
19501951
}
19511952
/*
19521953
* The buffer is committing, we simply cannot touch
1953-
* it. So we just set j_next_transaction to the
1954-
* running transaction (if there is one) and mark
1955-
* buffer as freed so that commit code knows it should
1956-
* clear dirty bits when it is done with the buffer.
1954+
* it. If the page is straddling i_size we have to wait
1955+
* for commit and try again.
1956+
*/
1957+
if (partial_page) {
1958+
tid_t tid = journal->j_committing_transaction->t_tid;
1959+
1960+
journal_put_journal_head(jh);
1961+
spin_unlock(&journal->j_list_lock);
1962+
jbd_unlock_bh_state(bh);
1963+
spin_unlock(&journal->j_state_lock);
1964+
log_wait_commit(journal, tid);
1965+
goto retry;
1966+
}
1967+
/*
1968+
* OK, buffer won't be reachable after truncate. We just set
1969+
* j_next_transaction to the running transaction (if there is
1970+
* one) and mark buffer as freed so that commit code knows it
1971+
* should clear dirty bits when it is done with the buffer.
19571972
*/
19581973
set_buffer_freed(bh);
19591974
if (journal->j_running_transaction && buffer_jbddirty(bh))
@@ -1976,6 +1991,14 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
19761991
}
19771992

19781993
zap_buffer:
1994+
/*
1995+
* This is tricky. Although the buffer is truncated, it may be reused
1996+
* if blocksize < pagesize and it is attached to the page straddling
1997+
* EOF. Since the buffer might have been added to BJ_Forget list of the
1998+
* running transaction, journal_get_write_access() won't clear
1999+
* b_modified and credit accounting gets confused. So clear b_modified
2000+
* here. */
2001+
jh->b_modified = 0;
19792002
journal_put_journal_head(jh);
19802003
zap_buffer_no_jh:
19812004
spin_unlock(&journal->j_list_lock);
@@ -2024,7 +2047,8 @@ void journal_invalidatepage(journal_t *journal,
20242047
if (offset <= curr_off) {
20252048
/* This block is wholly outside the truncation point */
20262049
lock_buffer(bh);
2027-
may_free &= journal_unmap_buffer(journal, bh);
2050+
may_free &= journal_unmap_buffer(journal, bh,
2051+
offset > 0);
20282052
unlock_buffer(bh);
20292053
}
20302054
curr_off = next_off;

‎fs/reiserfs/xattr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ static int create_privroot(struct dentry *dentry) { return 0; }
896896
#endif
897897

898898
/* Actual operations that are exported to VFS-land */
899-
const struct xattr_handler *reiserfs_xattr_handlers[] = {
899+
static const struct xattr_handler *reiserfs_xattr_handlers[] = {
900900
#ifdef CONFIG_REISERFS_FS_XATTR
901901
&reiserfs_xattr_user_handler,
902902
&reiserfs_xattr_trusted_handler,

‎fs/udf/file.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,20 @@ static int udf_adinicb_write_end(struct file *file,
118118
return simple_write_end(file, mapping, pos, len, copied, page, fsdata);
119119
}
120120

121+
static ssize_t udf_adinicb_direct_IO(int rw, struct kiocb *iocb,
122+
const struct iovec *iov,
123+
loff_t offset, unsigned long nr_segs)
124+
{
125+
/* Fallback to buffered I/O. */
126+
return 0;
127+
}
128+
121129
const struct address_space_operations udf_adinicb_aops = {
122130
.readpage = udf_adinicb_readpage,
123131
.writepage = udf_adinicb_writepage,
124132
.write_begin = udf_adinicb_write_begin,
125133
.write_end = udf_adinicb_write_end,
134+
.direct_IO = udf_adinicb_direct_IO,
126135
};
127136

128137
static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,

‎fs/udf/inode.c‎

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,33 @@ void udf_evict_inode(struct inode *inode)
9595
}
9696
}
9797

98+
static void udf_write_failed(struct address_space *mapping, loff_t to)
99+
{
100+
struct inode *inode = mapping->host;
101+
struct udf_inode_info *iinfo = UDF_I(inode);
102+
loff_t isize = inode->i_size;
103+
104+
if (to > isize) {
105+
truncate_pagecache(inode, to, isize);
106+
if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
107+
down_write(&iinfo->i_data_sem);
108+
udf_truncate_extents(inode);
109+
up_write(&iinfo->i_data_sem);
110+
}
111+
}
112+
}
113+
98114
static int udf_writepage(struct page *page, struct writeback_control *wbc)
99115
{
100116
return block_write_full_page(page, udf_get_block, wbc);
101117
}
102118

119+
static int udf_writepages(struct address_space *mapping,
120+
struct writeback_control *wbc)
121+
{
122+
return mpage_writepages(mapping, wbc, udf_get_block);
123+
}
124+
103125
static int udf_readpage(struct file *file, struct page *page)
104126
{
105127
return mpage_readpage(page, udf_get_block);
@@ -118,21 +140,24 @@ static int udf_write_begin(struct file *file, struct address_space *mapping,
118140
int ret;
119141

120142
ret = block_write_begin(mapping, pos, len, flags, pagep, udf_get_block);
121-
if (unlikely(ret)) {
122-
struct inode *inode = mapping->host;
123-
struct udf_inode_info *iinfo = UDF_I(inode);
124-
loff_t isize = inode->i_size;
125-
126-
if (pos + len > isize) {
127-
truncate_pagecache(inode, pos + len, isize);
128-
if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
129-
down_write(&iinfo->i_data_sem);
130-
udf_truncate_extents(inode);
131-
up_write(&iinfo->i_data_sem);
132-
}
133-
}
134-
}
143+
if (unlikely(ret))
144+
udf_write_failed(mapping, pos + len);
145+
return ret;
146+
}
135147

148+
static ssize_t udf_direct_IO(int rw, struct kiocb *iocb,
149+
const struct iovec *iov,
150+
loff_t offset, unsigned long nr_segs)
151+
{
152+
struct file *file = iocb->ki_filp;
153+
struct address_space *mapping = file->f_mapping;
154+
struct inode *inode = mapping->host;
155+
ssize_t ret;
156+
157+
ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs,
158+
udf_get_block);
159+
if (unlikely(ret < 0 && (rw & WRITE)))
160+
udf_write_failed(mapping, offset + iov_length(iov, nr_segs));
136161
return ret;
137162
}
138163

@@ -145,8 +170,10 @@ const struct address_space_operations udf_aops = {
145170
.readpage = udf_readpage,
146171
.readpages = udf_readpages,
147172
.writepage = udf_writepage,
148-
.write_begin = udf_write_begin,
149-
.write_end = generic_write_end,
173+
.writepages = udf_writepages,
174+
.write_begin = udf_write_begin,
175+
.write_end = generic_write_end,
176+
.direct_IO = udf_direct_IO,
150177
.bmap = udf_bmap,
151178
};
152179

0 commit comments

Comments
 (0)