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

[PATCH] JFS: return correct error when i-node allocation failed

I have seen confusing behavior on JFS when I injected many intentional
slab allocation errors. The cp command failed with no disk space error
with enough disk space.

This patch makes:

- change the return value in case slab allocation failures happen
from -ENOSPC to -ENOMEM

- ialloc() return error code so that the caller can know the reason
of failures

Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
Signed-off-by: Dave Kleikamp <shaggy@austin.ibm.com>
(cherry picked from 2b46f77976f798f3fe800809a1d0ed38763c71c8 commit)

authored by

Akinobu Mita and committed by
Dave Kleikamp
087387f9 2a6968a9

+17 -17
+2 -2
fs/jfs/jfs_dtree.c
··· 3780 3780 lkey.name = (wchar_t *) kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t), 3781 3781 GFP_KERNEL); 3782 3782 if (lkey.name == NULL) 3783 - return -ENOSPC; 3783 + return -ENOMEM; 3784 3784 3785 3785 rkey.name = (wchar_t *) kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t), 3786 3786 GFP_KERNEL); 3787 3787 if (rkey.name == NULL) { 3788 3788 kfree(lkey.name); 3789 - return -ENOSPC; 3789 + return -ENOMEM; 3790 3790 } 3791 3791 3792 3792 /* get left and right key */
+5 -4
fs/jfs/jfs_inode.c
··· 61 61 inode = new_inode(sb); 62 62 if (!inode) { 63 63 jfs_warn("ialloc: new_inode returned NULL!"); 64 - return inode; 64 + return ERR_PTR(-ENOMEM); 65 65 } 66 66 67 67 jfs_inode = JFS_IP(inode); ··· 69 69 rc = diAlloc(parent, S_ISDIR(mode), inode); 70 70 if (rc) { 71 71 jfs_warn("ialloc: diAlloc returned %d!", rc); 72 - make_bad_inode(inode); 72 + if (rc == -EIO) 73 + make_bad_inode(inode); 73 74 iput(inode); 74 - return NULL; 75 + return ERR_PTR(rc); 75 76 } 76 77 77 78 inode->i_uid = current->fsuid; ··· 98 97 inode->i_flags |= S_NOQUOTA; 99 98 inode->i_nlink = 0; 100 99 iput(inode); 101 - return NULL; 100 + return ERR_PTR(-EDQUOT); 102 101 } 103 102 104 103 inode->i_mode = mode;
+1 -1
fs/jfs/jfs_unicode.c
··· 124 124 kmalloc((length + 1) * sizeof(wchar_t), GFP_NOFS); 125 125 126 126 if (uniName->name == NULL) 127 - return -ENOSPC; 127 + return -ENOMEM; 128 128 129 129 uniName->namlen = jfs_strtoUCS(uniName->name, dentry->d_name.name, 130 130 length, nls_tab);
+8 -9
fs/jfs/namei.c
··· 97 97 * begin the transaction before we search the directory. 98 98 */ 99 99 ip = ialloc(dip, mode); 100 - if (ip == NULL) { 101 - rc = -ENOSPC; 100 + if (IS_ERR(ip)) { 101 + rc = PTR_ERR(ip); 102 102 goto out2; 103 103 } 104 104 ··· 231 231 * begin the transaction before we search the directory. 232 232 */ 233 233 ip = ialloc(dip, S_IFDIR | mode); 234 - if (ip == NULL) { 235 - rc = -ENOSPC; 234 + if (IS_ERR(ip)) { 235 + rc = PTR_ERR(ip); 236 236 goto out2; 237 237 } 238 238 ··· 906 906 * (iAlloc() returns new, locked inode) 907 907 */ 908 908 ip = ialloc(dip, S_IFLNK | 0777); 909 - if (ip == NULL) { 910 - rc = -ENOSPC; 909 + if (IS_ERR(ip)) { 910 + rc = PTR_ERR(ip); 911 911 goto out2; 912 912 } 913 913 ··· 978 978 xlen = xsize >> JFS_SBI(sb)->l2bsize; 979 979 if ((rc = xtInsert(tid, ip, 0, 0, xlen, &xaddr, 0))) { 980 980 txAbort(tid, 0); 981 - rc = -ENOSPC; 982 981 goto out3; 983 982 } 984 983 extent = xaddr; ··· 1349 1350 goto out; 1350 1351 1351 1352 ip = ialloc(dir, mode); 1352 - if (ip == NULL) { 1353 - rc = -ENOSPC; 1353 + if (IS_ERR(ip)) { 1354 + rc = PTR_ERR(ip); 1354 1355 goto out1; 1355 1356 } 1356 1357 jfs_ip = JFS_IP(ip);
+1 -1
fs/jfs/super.c
··· 422 422 423 423 sbi = kzalloc(sizeof (struct jfs_sb_info), GFP_KERNEL); 424 424 if (!sbi) 425 - return -ENOSPC; 425 + return -ENOMEM; 426 426 sb->s_fs_info = sbi; 427 427 sbi->sb = sb; 428 428 sbi->uid = sbi->gid = sbi->umask = -1;