Merge git://oss.sgi.com:8090/xfs/xfs-2.6

* git://oss.sgi.com:8090/xfs/xfs-2.6:
[XFS] Fix a bad pointer dereference in the quota statvfs handling.
[XFS] Fix xfs_splice_write() so appended data gets to disk.
[XFS] Fix ABBA deadlock between i_mutex and iolock. Avoid calling
[XFS] Prevent free space oversubscription and xfssyncd looping.

+76 -42
+13 -5
fs/xfs/linux-2.6/xfs_aops.c
··· 1390 1390 1391 1391 iocb->private = xfs_alloc_ioend(inode, IOMAP_UNWRITTEN); 1392 1392 1393 - ret = blockdev_direct_IO_own_locking(rw, iocb, inode, 1394 - iomap.iomap_target->bt_bdev, 1395 - iov, offset, nr_segs, 1396 - xfs_get_blocks_direct, 1397 - xfs_end_io_direct); 1393 + if (rw == WRITE) { 1394 + ret = blockdev_direct_IO_own_locking(rw, iocb, inode, 1395 + iomap.iomap_target->bt_bdev, 1396 + iov, offset, nr_segs, 1397 + xfs_get_blocks_direct, 1398 + xfs_end_io_direct); 1399 + } else { 1400 + ret = blockdev_direct_IO_no_locking(rw, iocb, inode, 1401 + iomap.iomap_target->bt_bdev, 1402 + iov, offset, nr_segs, 1403 + xfs_get_blocks_direct, 1404 + xfs_end_io_direct); 1405 + } 1398 1406 1399 1407 if (unlikely(ret <= 0 && iocb->private)) 1400 1408 xfs_destroy_ioend(iocb->private);
+22 -5
fs/xfs/linux-2.6/xfs_lrw.c
··· 264 264 dmflags, &locktype); 265 265 if (ret) { 266 266 xfs_iunlock(ip, XFS_IOLOCK_SHARED); 267 - goto unlock_mutex; 267 + if (unlikely(ioflags & IO_ISDIRECT)) 268 + mutex_unlock(&inode->i_mutex); 269 + return ret; 268 270 } 269 271 } 270 272 271 273 if (unlikely((ioflags & IO_ISDIRECT) && VN_CACHED(vp))) 272 274 bhv_vop_flushinval_pages(vp, ctooff(offtoct(*offset)), 273 275 -1, FI_REMAPF_LOCKED); 276 + 277 + if (unlikely(ioflags & IO_ISDIRECT)) 278 + mutex_unlock(&inode->i_mutex); 274 279 275 280 xfs_rw_enter_trace(XFS_READ_ENTER, &ip->i_iocore, 276 281 (void *)iovp, segs, *offset, ioflags); ··· 286 281 XFS_STATS_ADD(xs_read_bytes, ret); 287 282 288 283 xfs_iunlock(ip, XFS_IOLOCK_SHARED); 289 - 290 - unlock_mutex: 291 - if (unlikely(ioflags & IO_ISDIRECT)) 292 - mutex_unlock(&inode->i_mutex); 293 284 return ret; 294 285 } 295 286 ··· 391 390 xfs_inode_t *ip = XFS_BHVTOI(bdp); 392 391 xfs_mount_t *mp = ip->i_mount; 393 392 ssize_t ret; 393 + struct inode *inode = outfilp->f_mapping->host; 394 + xfs_fsize_t isize; 394 395 395 396 XFS_STATS_INC(xs_write_calls); 396 397 if (XFS_FORCED_SHUTDOWN(ip->i_mount)) ··· 419 416 if (ret > 0) 420 417 XFS_STATS_ADD(xs_write_bytes, ret); 421 418 419 + isize = i_size_read(inode); 420 + if (unlikely(ret < 0 && ret != -EFAULT && *ppos > isize)) 421 + *ppos = isize; 422 + 423 + if (*ppos > ip->i_d.di_size) { 424 + xfs_ilock(ip, XFS_ILOCK_EXCL); 425 + if (*ppos > ip->i_d.di_size) { 426 + ip->i_d.di_size = *ppos; 427 + i_size_write(inode, *ppos); 428 + ip->i_update_core = 1; 429 + ip->i_update_size = 1; 430 + } 431 + xfs_iunlock(ip, XFS_ILOCK_EXCL); 432 + } 422 433 xfs_iunlock(ip, XFS_IOLOCK_EXCL); 423 434 return ret; 424 435 }
+1 -1
fs/xfs/quota/xfs_qm_bhv.c
··· 203 203 if (error || !vnode) 204 204 return error; 205 205 206 - mp = XFS_BHVTOM(bhv); 206 + mp = xfs_vfstom(bhvtovfs(bhv)); 207 207 ip = xfs_vtoi(vnode); 208 208 209 209 if (!(ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT))
+20
fs/xfs/xfs_alloc.h
··· 44 44 #define XFS_ALLOC_FLAG_FREEING 0x00000002 /* indicate caller is freeing extents*/ 45 45 46 46 /* 47 + * In order to avoid ENOSPC-related deadlock caused by 48 + * out-of-order locking of AGF buffer (PV 947395), we place 49 + * constraints on the relationship among actual allocations for 50 + * data blocks, freelist blocks, and potential file data bmap 51 + * btree blocks. However, these restrictions may result in no 52 + * actual space allocated for a delayed extent, for example, a data 53 + * block in a certain AG is allocated but there is no additional 54 + * block for the additional bmap btree block due to a split of the 55 + * bmap btree of the file. The result of this may lead to an 56 + * infinite loop in xfssyncd when the file gets flushed to disk and 57 + * all delayed extents need to be actually allocated. To get around 58 + * this, we explicitly set aside a few blocks which will not be 59 + * reserved in delayed allocation. Considering the minimum number of 60 + * needed freelist blocks is 4 fsbs _per AG_, a potential split of file's bmap 61 + * btree requires 1 fsb, so we set the number of set-aside blocks 62 + * to 4 + 4*agcount. 63 + */ 64 + #define XFS_ALLOC_SET_ASIDE(mp) (4 + ((mp)->m_sb.sb_agcount * 4)) 65 + 66 + /* 47 67 * Argument structure for xfs_alloc routines. 48 68 * This is turned into a structure to avoid having 20 arguments passed 49 69 * down several levels of the stack.
+10 -6
fs/xfs/xfs_fsops.c
··· 462 462 463 463 xfs_icsb_sync_counters_lazy(mp); 464 464 s = XFS_SB_LOCK(mp); 465 - cnt->freedata = mp->m_sb.sb_fdblocks; 465 + cnt->freedata = mp->m_sb.sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); 466 466 cnt->freertx = mp->m_sb.sb_frextents; 467 467 cnt->freeino = mp->m_sb.sb_ifree; 468 468 cnt->allocino = mp->m_sb.sb_icount; ··· 519 519 } 520 520 mp->m_resblks = request; 521 521 } else { 522 + __int64_t free; 523 + 524 + free = mp->m_sb.sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); 522 525 delta = request - mp->m_resblks; 523 - lcounter = mp->m_sb.sb_fdblocks - delta; 526 + lcounter = free - delta; 524 527 if (lcounter < 0) { 525 528 /* We can't satisfy the request, just get what we can */ 526 - mp->m_resblks += mp->m_sb.sb_fdblocks; 527 - mp->m_resblks_avail += mp->m_sb.sb_fdblocks; 528 - mp->m_sb.sb_fdblocks = 0; 529 + mp->m_resblks += free; 530 + mp->m_resblks_avail += free; 531 + mp->m_sb.sb_fdblocks = XFS_ALLOC_SET_ASIDE(mp); 529 532 } else { 530 - mp->m_sb.sb_fdblocks = lcounter; 533 + mp->m_sb.sb_fdblocks = 534 + lcounter + XFS_ALLOC_SET_ASIDE(mp); 531 535 mp->m_resblks = request; 532 536 mp->m_resblks_avail += delta; 533 537 }
+8 -24
fs/xfs/xfs_mount.c
··· 1243 1243 xfs_trans_log_buf(tp, bp, first, last); 1244 1244 } 1245 1245 1246 - /* 1247 - * In order to avoid ENOSPC-related deadlock caused by 1248 - * out-of-order locking of AGF buffer (PV 947395), we place 1249 - * constraints on the relationship among actual allocations for 1250 - * data blocks, freelist blocks, and potential file data bmap 1251 - * btree blocks. However, these restrictions may result in no 1252 - * actual space allocated for a delayed extent, for example, a data 1253 - * block in a certain AG is allocated but there is no additional 1254 - * block for the additional bmap btree block due to a split of the 1255 - * bmap btree of the file. The result of this may lead to an 1256 - * infinite loop in xfssyncd when the file gets flushed to disk and 1257 - * all delayed extents need to be actually allocated. To get around 1258 - * this, we explicitly set aside a few blocks which will not be 1259 - * reserved in delayed allocation. Considering the minimum number of 1260 - * needed freelist blocks is 4 fsbs, a potential split of file's bmap 1261 - * btree requires 1 fsb, so we set the number of set-aside blocks to 8. 1262 - */ 1263 - #define SET_ASIDE_BLOCKS 8 1264 1246 1265 1247 /* 1266 1248 * xfs_mod_incore_sb_unlocked() is a utility routine common used to apply ··· 1288 1306 return 0; 1289 1307 case XFS_SBS_FDBLOCKS: 1290 1308 1291 - lcounter = (long long)mp->m_sb.sb_fdblocks - SET_ASIDE_BLOCKS; 1309 + lcounter = (long long) 1310 + mp->m_sb.sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); 1292 1311 res_used = (long long)(mp->m_resblks - mp->m_resblks_avail); 1293 1312 1294 1313 if (delta > 0) { /* Putting blocks back */ ··· 1323 1340 } 1324 1341 } 1325 1342 1326 - mp->m_sb.sb_fdblocks = lcounter + SET_ASIDE_BLOCKS; 1343 + mp->m_sb.sb_fdblocks = lcounter + XFS_ALLOC_SET_ASIDE(mp); 1327 1344 return 0; 1328 1345 case XFS_SBS_FREXTENTS: 1329 1346 lcounter = (long long)mp->m_sb.sb_frextents; ··· 2004 2021 * when we get near ENOSPC. 2005 2022 */ 2006 2023 #define XFS_ICSB_INO_CNTR_REENABLE 64 2007 - #define XFS_ICSB_FDBLK_CNTR_REENABLE 512 2024 + #define XFS_ICSB_FDBLK_CNTR_REENABLE(mp) \ 2025 + (512 + XFS_ALLOC_SET_ASIDE(mp)) 2008 2026 STATIC void 2009 2027 xfs_icsb_balance_counter( 2010 2028 xfs_mount_t *mp, ··· 2039 2055 case XFS_SBS_FDBLOCKS: 2040 2056 count = mp->m_sb.sb_fdblocks; 2041 2057 resid = do_div(count, weight); 2042 - if (count < XFS_ICSB_FDBLK_CNTR_REENABLE) 2058 + if (count < XFS_ICSB_FDBLK_CNTR_REENABLE(mp)) 2043 2059 goto out; 2044 2060 break; 2045 2061 default: ··· 2094 2110 case XFS_SBS_FDBLOCKS: 2095 2111 BUG_ON((mp->m_resblks - mp->m_resblks_avail) != 0); 2096 2112 2097 - lcounter = icsbp->icsb_fdblocks; 2113 + lcounter = icsbp->icsb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); 2098 2114 lcounter += delta; 2099 2115 if (unlikely(lcounter < 0)) 2100 2116 goto slow_path; 2101 - icsbp->icsb_fdblocks = lcounter; 2117 + icsbp->icsb_fdblocks = lcounter + XFS_ALLOC_SET_ASIDE(mp); 2102 2118 break; 2103 2119 default: 2104 2120 BUG();
+2 -1
fs/xfs/xfs_vfsops.c
··· 811 811 statp->f_bsize = sbp->sb_blocksize; 812 812 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0; 813 813 statp->f_blocks = sbp->sb_dblocks - lsize; 814 - statp->f_bfree = statp->f_bavail = sbp->sb_fdblocks; 814 + statp->f_bfree = statp->f_bavail = 815 + sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); 815 816 fakeinos = statp->f_bfree << sbp->sb_inopblog; 816 817 #if XFS_BIG_INUMS 817 818 fakeinos += mp->m_inoadd;