ReiserFS file.c several bug-fix - modified version
PATCH RESEND 1/1 ReiserFS file.c several bug-fix - modified version
hi, all, in the previous patch, i accidentally typed several 'dd(vim)'
Sorry
Quoted 47 lines
Related FS:
ReiserFSRelated Files:
fs/reiserfs/file.cBug description:
Make a ReiserFS partition in USB storage HDD, create a test file
with enough size.
Write a program, do:open(O_SYNC/O_DSYNC)- read - close. After
each
operation, pause for a while, such as 3s. Between open and read, unlug the USB wire. open returns zero-filled buffer, no error returns.Bug analysis:
reiserfs_file_writewill claim some blocks, commit the I/O
request,
ifO_SYNCandO_DSYNCis used, it willif ((file->f_flags & O_SYNC) || IS_SYNC(inode)) res = generic_osync_inode(inode, file->f_mapping, OSYNC_METADATA|OSYNC_DATA);The question is, if I/O error occurs,
res =reiserfs_allocate_blocks_for_regionfails with-EIO, so
it will exit the loop, no I/O request, no page marked as dirty. If rungeneric_osync_inode, it returns 0(no dirty page), res will be overwritten from-EIOto 0, thus no error report.Also,
reiserfs_file_writecontains a serious bug, see here
blocks_to_allocate=reiserfs_prepare_file_region_for_write
(inode, pos,num_pages,write_bytes,prepared_pages);
Hereblocks_to_allocateis defined assize_t, i.e. unsigned int, butreiserfs_prepare_file_region_for_writeis declared as int, so sometimes
it will return-EIO,-ENOENT, etc, take a look at this lineif ( blocks_to_allocate < 0 ) { <- This will never happen res = blocks_to_allocate; reiserfs_release_claimed_blocks(inode->i_sb, num_pages << (PAGE_CACHE_SHIFT - inode->i_blkbits)); break; }Way around:
1) ifalready_writtenis zero, don't dogeneric_osync_inode
2) tell the result ofreiserfs_prepare_file_region_for_writewithIS_ERR
macro or cast it tosize_t
Quoted 6 lines
Signed-off-by Qu Fuping<[email protected]>Patch:
diff -uNplinux-2.6.12/fs/reiserfs/file.clinux-2.6.12-new/fs/reiserfs/file.c
fs/reiserfs/file.c +5 -1
@@ -1306,7 +1306,7 @@ static ssize_t reiserfs_file_write( struso that nobody else can access these until we are done. We get number of actual blocks needed as a result.*/ blocks_to_allocate =reiserfs_prepare_file_region_for_write (inode, pos, num_pages, write_bytes, prepared_pages); -if ( blocks_to_allocate <0 ) { +if (IS_ERROR ((const void *)blocks_to_allocate) ) { res = blocks_to_allocate;reiserfs_release_claimed_blocks (inode->i_sb, num_pages << (PAGE_CACHE_SHIFT - inode->i_blkbits));break ;
@@ -1363,6 +1363,10 @@ static ssize_t reiserfs_file_write( stru } } +/* If nothing is written, no need(actually, mustn't) to sync pages, just return res */ +if ( already_written ==0 ) + goto out; +if ((file->f_flags &O_SYNC ) ||IS_SYNC (inode)) res =generic_osync_inode (inode, file->f_mapping,OSYNC_METADATA |OSYNC_DATA );