Commit 6a3b37e0 authored by Jan Kara's avatar Jan Kara

udf: Push i_data_sem locking into udf_expand_file_adinicb()

The checks we do in udf_setsize() and udf_file_write_iter() are safe to
do only with i_rwsem locked as it stabilizes both file type and file
size. Hence we don't need to lock i_data_sem before we enter
udf_expand_file_adinicb() which simplifies the locking somewhat.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent f950fd05
...@@ -148,7 +148,6 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -148,7 +148,6 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
if (retval <= 0) if (retval <= 0)
goto out; goto out;
down_write(&iinfo->i_data_sem);
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB &&
inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
iocb->ki_pos + iov_iter_count(from))) { iocb->ki_pos + iov_iter_count(from))) {
...@@ -158,15 +157,15 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -158,15 +157,15 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
udf_debug("udf_expand_adinicb: err=%d\n", err); udf_debug("udf_expand_adinicb: err=%d\n", err);
return err; return err;
} }
} else }
up_write(&iinfo->i_data_sem);
retval = __generic_file_write_iter(iocb, from); retval = __generic_file_write_iter(iocb, from);
out: out:
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && retval > 0) {
down_write(&iinfo->i_data_sem); down_write(&iinfo->i_data_sem);
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && retval > 0)
iinfo->i_lenAlloc = inode->i_size; iinfo->i_lenAlloc = inode->i_size;
up_write(&iinfo->i_data_sem); up_write(&iinfo->i_data_sem);
}
inode_unlock(inode); inode_unlock(inode);
if (retval > 0) { if (retval > 0) {
......
...@@ -247,7 +247,6 @@ const struct address_space_operations udf_aops = { ...@@ -247,7 +247,6 @@ const struct address_space_operations udf_aops = {
/* /*
* Expand file stored in ICB to a normal one-block-file * Expand file stored in ICB to a normal one-block-file
* *
* This function requires i_data_sem for writing and releases it.
* This function requires i_mutex held * This function requires i_mutex held
*/ */
int udf_expand_file_adinicb(struct inode *inode) int udf_expand_file_adinicb(struct inode *inode)
...@@ -259,6 +258,7 @@ int udf_expand_file_adinicb(struct inode *inode) ...@@ -259,6 +258,7 @@ int udf_expand_file_adinicb(struct inode *inode)
WARN_ON_ONCE(!inode_is_locked(inode)); WARN_ON_ONCE(!inode_is_locked(inode));
if (!iinfo->i_lenAlloc) { if (!iinfo->i_lenAlloc) {
down_write(&iinfo->i_data_sem);
if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT; iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
else else
...@@ -269,11 +269,6 @@ int udf_expand_file_adinicb(struct inode *inode) ...@@ -269,11 +269,6 @@ int udf_expand_file_adinicb(struct inode *inode)
mark_inode_dirty(inode); mark_inode_dirty(inode);
return 0; return 0;
} }
/*
* Release i_data_sem so that we can lock a page - page lock ranks
* above i_data_sem. i_mutex still protects us against file changes.
*/
up_write(&iinfo->i_data_sem);
page = find_or_create_page(inode->i_mapping, 0, GFP_NOFS); page = find_or_create_page(inode->i_mapping, 0, GFP_NOFS);
if (!page) if (!page)
...@@ -1160,19 +1155,18 @@ int udf_setsize(struct inode *inode, loff_t newsize) ...@@ -1160,19 +1155,18 @@ int udf_setsize(struct inode *inode, loff_t newsize)
iinfo = UDF_I(inode); iinfo = UDF_I(inode);
if (newsize > inode->i_size) { if (newsize > inode->i_size) {
down_write(&iinfo->i_data_sem);
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
if (bsize < if (bsize >=
(udf_file_entry_alloc_offset(inode) + newsize)) { (udf_file_entry_alloc_offset(inode) + newsize)) {
err = udf_expand_file_adinicb(inode);
if (err)
return err;
down_write(&iinfo->i_data_sem); down_write(&iinfo->i_data_sem);
} else {
iinfo->i_lenAlloc = newsize; iinfo->i_lenAlloc = newsize;
goto set_size; goto set_size;
} }
err = udf_expand_file_adinicb(inode);
if (err)
return err;
} }
down_write(&iinfo->i_data_sem);
err = udf_extend_file(inode, newsize); err = udf_extend_file(inode, newsize);
if (err) { if (err) {
up_write(&iinfo->i_data_sem); up_write(&iinfo->i_data_sem);
......
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