: ufs: allocate last block in ufs_truncate
RFC PATCH 3/3 : ufs: allocate last block in ufs_truncate
This patch fixes buggy behaviour of UFS
in such kind of scenario:open(, O_TRUNC...)ftruncate(, 1024)ftruncate(, 0)
such scenario causes ufs_panic and remount read-only. This happen because of according to specification UFS should always allocate block for last byte, and many parts of our implementation rely on this, but `ufs_truncate' doesn't care about this.
In `ufs_truncate' I make several assumptions about VFS service functions behaviour, may be I missed something, see patch bellow.
Signed-off-by Evgeniy Dushistov <[email protected]>
---
fs/ufs/balloc.c +2 -46
@@ -217,48 +217,6 @@ failed:return ; } -static struct page *ufs_get_locked_page (struct address_space *mapping, -unsigned long index) -{ -struct page *page; - -try_again: - page =find_lock_page (mapping, index); -if (!page) { - page =read_cache_page (mapping, index, - (filler_t *)mapping->a_ops->readpage, -NULL ); -if (IS_ERR (page)) { -printk (KERN_ERR "ufs_change_blocknr: " -"read_cache_page error: ino %lu, index: %lu\n" , - mapping->host->i_ino, index); - goto out; - } - -lock_page (page); - -if (!PageUptodate (page) ||PageError (page)) { -unlock_page (page); -page_cache_release (page); - -printk (KERN_ERR "ufs_change_blocknr: " -"can not read page: ino %lu, index: %lu\n" , - mapping->host->i_ino, index); - - page =ERR_PTR (-EIO ); - goto out; - } - } - -if (unlikely (!page->mapping || !page_has_buffers (page))) { -unlock_page (page); -page_cache_release (page); - goto try_again;/*we really need these buffers*/ - } -out: -return page; -} -/* * Modify inode page cache in such way: * have - blocks with b_blocknr equal to oldb...oldb+count-1
@@ -311,10 +269,8 @@ static void ufs_change_blocknr(struct inset_page_dirty (page); -if (likely (cur_index != index)) { -unlock_page (page); -page_cache_release (page); - } +if (likely (cur_index != index)) +ufs_put_locked_page (page); }UFSD ("EXIT\n" ); }
fs/ufs/truncate.c +98 -8
131 lines not on this page · raw message
fs/ufs/util.c +53 -0
56 lines not on this page · raw message
fs/ufs/util.h +8 -0
@@ -251,6 +251,14 @@ extern void _ubh_ubhcpymem_(struct ufs_s#define ubh_memcpyubh (ubh,mem,size) _ubh_memcpyubh_(uspi,ubh,mem,size)extern void _ubh_memcpyubh_ (struct ufs_sb_private_info *,struct ufs_buffer_head *,unsigned char *,unsigned ); +/* This functions works with cache pages*/ +extern struct page *ufs_get_locked_page (struct address_space *mapping, +pgoff_t index); +static inline void ufs_put_locked_page (struct page *page) +{ +unlock_page (page); +page_cache_release (page); +}/*
Signature · 1 line
/Evgeniy