Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hpfs: don't truncate the file when delete fails

The delete opration can allocate additional space on the HPFS filesystem
due to btree split. The HPFS driver checks in advance if there is
available space, so that it won't corrupt the btree if we run out of space
during splitting.

If there is not enough available space, the HPFS driver attempted to
truncate the file, but this results in a deadlock since the commit
7dd29d8d865efdb00c0542a5d2c87af8c52ea6c7 ("HPFS: Introduce a global mutex
and lock it on every callback from VFS").

This patch removes the code that tries to truncate the file and -ENOSPC is
returned instead. If the user hits -ENOSPC on delete, he should try to
delete other files (that are stored in a leaf btree node), so that the
delete operation will make some space for deleting the file stored in
non-leaf btree node.

Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
Cc: stable@vger.kernel.org # 2.6.39+
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

Mikulas Patocka and committed by
Al Viro
b6853f78 7ae8fd03

+3 -28
+3 -28
fs/hpfs/namei.c
··· 376 376 struct inode *inode = d_inode(dentry); 377 377 dnode_secno dno; 378 378 int r; 379 - int rep = 0; 380 379 int err; 381 380 382 381 hpfs_lock(dir->i_sb); 383 382 hpfs_adjust_length(name, &len); 384 - again: 383 + 385 384 err = -ENOENT; 386 385 de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, &dno, &qbh); 387 386 if (!de) ··· 400 401 hpfs_error(dir->i_sb, "there was error when removing dirent"); 401 402 err = -EFSERROR; 402 403 break; 403 - case 2: /* no space for deleting, try to truncate file */ 404 - 404 + case 2: /* no space for deleting */ 405 405 err = -ENOSPC; 406 - if (rep++) 407 - break; 408 - 409 - dentry_unhash(dentry); 410 - if (!d_unhashed(dentry)) { 411 - hpfs_unlock(dir->i_sb); 412 - return -ENOSPC; 413 - } 414 - if (generic_permission(inode, MAY_WRITE) || 415 - !S_ISREG(inode->i_mode) || 416 - get_write_access(inode)) { 417 - d_rehash(dentry); 418 - } else { 419 - struct iattr newattrs; 420 - /*pr_info("truncating file before delete.\n");*/ 421 - newattrs.ia_size = 0; 422 - newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; 423 - err = notify_change(dentry, &newattrs, NULL); 424 - put_write_access(inode); 425 - if (!err) 426 - goto again; 427 - } 428 - hpfs_unlock(dir->i_sb); 429 - return -ENOSPC; 406 + break; 430 407 default: 431 408 drop_nlink(inode); 432 409 err = 0;