Bug 9364 - BFS: Deleting an empty file erroneously increases the number of free blocks reported by statfs().
Summary: BFS: Deleting an empty file erroneously increases the number of free blocks r...
Status: RESOLVED CODE_FIX
Alias: None
Product: File System
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 high
Assignee: Dmitri Vorobiev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-13 06:45 UTC by Dmitri Vorobiev
Modified: 2007-11-13 11:53 UTC (History)
1 user (show)

See Also:
Kernel Version: 2.6.24-rc2
Subsystem:
Regression: ---
Bisected commit-id:


Attachments

Description Dmitri Vorobiev 2007-11-13 06:45:04 UTC
Most recent kernel where this bug did not occur: N/A
Distribution: this bug does not depend on distribution.
Hardware Environment: x86
Software Environment:

>>>

# lsmod
Module                  Size  Used by
bfs                    14008  1
#

<<<

Problem Description:

When deleting an inode, the BFS driver adds a free disk block even when the inode did not use any disk blocks.

Steps to reproduce:

1. Mount a BFS partition.

2. Create an empty file on this partition, delete this file, repeat:

>>>

root@codedot:/mnt# mount | grep mnt
/dev/loop0 on /mnt type bfs (rw)
root@codedot:/mnt# df -B 512 | grep loop
/dev/loop0               65536        81     65455   1% /mnt
root@codedot:/mnt# touch file
root@codedot:/mnt# rm file
root@codedot:/mnt# df -B 512 | grep loop
/dev/loop0               65536        80     65456   1% /mnt
root@codedot:/mnt# for i in `seq 1 100`; do touch file; rm file; done
root@codedot:/mnt# df -B 512 | grep loop
/dev/loop0               65536       -20     65556   0% /mnt
root@codedot:/mnt# 

<<<

The number of occupied blocks reported by statfs() becomes negative if an empty file gets created and subsequently removed sufficient number of times.
Comment 1 Dmitri Vorobiev 2007-11-13 06:46:07 UTC
The bfs_get_block() function located in `fs/bfs/file.c' does not compare the number of the physical block, which it tries to access when extending the file, against the size of the block device. Checks against the block device size need to be introduced into the filesystem driver, and -ENOSPC error should be returned every time the partition runs out of free space when writing a growing file.

I am working on a fix for the BFS driver, that's why I am assigning this bug to myself now.
Comment 2 Dmitri Vorobiev 2007-11-13 08:47:02 UTC
The patch proposed in the following LKML message

http://lkml.org/lkml/2007/11/13/185

fixes the error reported in the context of this bug. What follows is a console session, which proves that the error is gone:

>>>

debian:~# mount -t bfs /dev/loop0 /mnt
debian:~# cd /mnt/
debian:/mnt# df -B 512 | grep loop
/dev/loop0               65536        81     65455   1% /mnt
debian:/mnt# for i in `seq 1 100`; do touch file; rm file; done
debian:/mnt# df -B 512 | grep loop
/dev/loop0               65536        81     65455   1% /mnt
debian:/mnt#

<<<
Comment 3 Andrew Morton 2007-11-13 11:53:28 UTC
I merged Dmitry's fix

Note You need to log in before you can comment on or make changes to this bug.