Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mfasheh/ocfs2

* 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mfasheh/ocfs2:
ocfs2: set non-default s_time_gran during mount
ocfs2: Retry sendpage() if it returns EAGAIN
ocfs2: Fix rename/extend race
[2.6 patch] ocfs2_insert_extent(): remove dead code
ocfs2: Fix max offset calculations
ocfs2: check ia_size limits in setattr
ocfs2: Fix some casting errors related to file writes
ocfs2: use s_maxbytes directly in ocfs2_change_file_space()
ocfs2: Restrict inode changes in ocfs2_update_inode_atime()

+100 -49
-4
fs/ocfs2/alloc.c
··· 3731 3731 { 3732 3732 int status; 3733 3733 struct buffer_head *last_eb_bh = NULL; 3734 - struct buffer_head *bh = NULL; 3735 3734 struct ocfs2_insert_type insert = {0, }; 3736 3735 struct ocfs2_extent_rec rec; 3737 3736 ··· 3782 3783 ocfs2_extent_map_insert_rec(inode, &rec); 3783 3784 3784 3785 bail: 3785 - if (bh) 3786 - brelse(bh); 3787 - 3788 3786 if (last_eb_bh) 3789 3787 brelse(last_eb_bh); 3790 3788
+16 -8
fs/ocfs2/cluster/tcp.c
··· 854 854 struct o2net_node *nn = o2net_nn_from_num(sc->sc_node->nd_num); 855 855 ssize_t ret; 856 856 857 - 858 - mutex_lock(&sc->sc_send_lock); 859 - ret = sc->sc_sock->ops->sendpage(sc->sc_sock, 860 - virt_to_page(kmalloced_virt), 861 - (long)kmalloced_virt & ~PAGE_MASK, 862 - size, MSG_DONTWAIT); 863 - mutex_unlock(&sc->sc_send_lock); 864 - if (ret != size) { 857 + while (1) { 858 + mutex_lock(&sc->sc_send_lock); 859 + ret = sc->sc_sock->ops->sendpage(sc->sc_sock, 860 + virt_to_page(kmalloced_virt), 861 + (long)kmalloced_virt & ~PAGE_MASK, 862 + size, MSG_DONTWAIT); 863 + mutex_unlock(&sc->sc_send_lock); 864 + if (ret == size) 865 + break; 866 + if (ret == (ssize_t)-EAGAIN) { 867 + mlog(0, "sendpage of size %zu to " SC_NODEF_FMT 868 + " returned EAGAIN\n", size, SC_NODEF_ARGS(sc)); 869 + cond_resched(); 870 + continue; 871 + } 865 872 mlog(ML_ERROR, "sendpage of size %zu to " SC_NODEF_FMT 866 873 " failed with %zd\n", size, SC_NODEF_ARGS(sc), ret); 867 874 o2net_ensure_shutdown(nn, sc, 0); 875 + break; 868 876 } 869 877 } 870 878
+25 -3
fs/ocfs2/file.c
··· 187 187 int ret; 188 188 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 189 189 handle_t *handle; 190 + struct ocfs2_dinode *di = (struct ocfs2_dinode *) bh->b_data; 190 191 191 192 mlog_entry_void(); 192 193 ··· 198 197 goto out; 199 198 } 200 199 200 + ret = ocfs2_journal_access(handle, inode, bh, 201 + OCFS2_JOURNAL_ACCESS_WRITE); 202 + if (ret) { 203 + mlog_errno(ret); 204 + goto out_commit; 205 + } 206 + 207 + /* 208 + * Don't use ocfs2_mark_inode_dirty() here as we don't always 209 + * have i_mutex to guard against concurrent changes to other 210 + * inode fields. 211 + */ 201 212 inode->i_atime = CURRENT_TIME; 202 - ret = ocfs2_mark_inode_dirty(handle, inode, bh); 213 + di->i_atime = cpu_to_le64(inode->i_atime.tv_sec); 214 + di->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec); 215 + 216 + ret = ocfs2_journal_dirty(handle, bh); 203 217 if (ret < 0) 204 218 mlog_errno(ret); 205 219 220 + out_commit: 206 221 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); 207 222 out: 208 223 mlog_exit(ret); ··· 1028 1011 } 1029 1012 1030 1013 if (size_change && attr->ia_size != i_size_read(inode)) { 1014 + if (attr->ia_size > sb->s_maxbytes) { 1015 + status = -EFBIG; 1016 + goto bail_unlock; 1017 + } 1018 + 1031 1019 if (i_size_read(inode) > attr->ia_size) 1032 1020 status = ocfs2_truncate_file(inode, bh, attr->ia_size); 1033 1021 else ··· 1538 1516 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 1539 1517 struct buffer_head *di_bh = NULL; 1540 1518 handle_t *handle; 1541 - unsigned long long max_off = ocfs2_max_file_offset(inode->i_sb->s_blocksize_bits); 1519 + unsigned long long max_off = inode->i_sb->s_maxbytes; 1542 1520 1543 1521 if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) 1544 1522 return -EROFS; ··· 1964 1942 } 1965 1943 1966 1944 dst = kmap_atomic(page, KM_USER0); 1967 - memcpy(dst + (pos & (PAGE_CACHE_SIZE - 1)), buf, bytes); 1945 + memcpy(dst + (pos & (loff_t)(PAGE_CACHE_SIZE - 1)), buf, bytes); 1968 1946 kunmap_atomic(dst, KM_USER0); 1969 1947 flush_dcache_page(page); 1970 1948 ocfs2_put_write_source(user_page);
+15 -1
fs/ocfs2/namei.c
··· 1080 1080 struct buffer_head *old_inode_de_bh = NULL; // if old_dentry is a dir, 1081 1081 // this is the 1st dirent bh 1082 1082 nlink_t old_dir_nlink = old_dir->i_nlink; 1083 + struct ocfs2_dinode *old_di; 1083 1084 1084 1085 /* At some point it might be nice to break this function up a 1085 1086 * bit. */ ··· 1355 1354 1356 1355 old_inode->i_ctime = CURRENT_TIME; 1357 1356 mark_inode_dirty(old_inode); 1358 - ocfs2_mark_inode_dirty(handle, old_inode, old_inode_bh); 1357 + 1358 + status = ocfs2_journal_access(handle, old_inode, old_inode_bh, 1359 + OCFS2_JOURNAL_ACCESS_WRITE); 1360 + if (status >= 0) { 1361 + old_di = (struct ocfs2_dinode *) old_inode_bh->b_data; 1362 + 1363 + old_di->i_ctime = cpu_to_le64(old_inode->i_ctime.tv_sec); 1364 + old_di->i_ctime_nsec = cpu_to_le32(old_inode->i_ctime.tv_nsec); 1365 + 1366 + status = ocfs2_journal_dirty(handle, old_inode_bh); 1367 + if (status < 0) 1368 + mlog_errno(status); 1369 + } else 1370 + mlog_errno(status); 1359 1371 1360 1372 /* now that the name has been added to new_dir, remove the old name */ 1361 1373 status = ocfs2_delete_entry(handle, old_dir, old_de, old_de_bh);
+4 -4
fs/ocfs2/ocfs2.h
··· 494 494 /* 495 495 * Find the 1st page index which covers the given clusters. 496 496 */ 497 - static inline unsigned long ocfs2_align_clusters_to_page_index(struct super_block *sb, 497 + static inline pgoff_t ocfs2_align_clusters_to_page_index(struct super_block *sb, 498 498 u32 clusters) 499 499 { 500 500 unsigned int cbits = OCFS2_SB(sb)->s_clustersize_bits; 501 - unsigned long index = clusters; 501 + pgoff_t index = clusters; 502 502 503 503 if (PAGE_CACHE_SHIFT > cbits) { 504 - index = clusters >> (PAGE_CACHE_SHIFT - cbits); 504 + index = (pgoff_t)clusters >> (PAGE_CACHE_SHIFT - cbits); 505 505 } else if (PAGE_CACHE_SHIFT < cbits) { 506 - index = clusters << (cbits - PAGE_CACHE_SHIFT); 506 + index = (pgoff_t)clusters << (cbits - PAGE_CACHE_SHIFT); 507 507 } 508 508 509 509 return index;
+40 -27
fs/ocfs2/super.c
··· 316 316 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode)); 317 317 } 318 318 319 - /* From xfs_super.c:xfs_max_file_offset 320 - * Copyright (c) 2000-2004 Silicon Graphics, Inc. 321 - */ 322 - unsigned long long ocfs2_max_file_offset(unsigned int blockshift) 319 + static unsigned long long ocfs2_max_file_offset(unsigned int bbits, 320 + unsigned int cbits) 323 321 { 324 - unsigned int pagefactor = 1; 325 - unsigned int bitshift = BITS_PER_LONG - 1; 322 + unsigned int bytes = 1 << cbits; 323 + unsigned int trim = bytes; 324 + unsigned int bitshift = 32; 326 325 327 - /* Figure out maximum filesize, on Linux this can depend on 328 - * the filesystem blocksize (on 32 bit platforms). 329 - * __block_prepare_write does this in an [unsigned] long... 330 - * page->index << (PAGE_CACHE_SHIFT - bbits) 331 - * So, for page sized blocks (4K on 32 bit platforms), 332 - * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is 333 - * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) 334 - * but for smaller blocksizes it is less (bbits = log2 bsize). 335 - * Note1: get_block_t takes a long (implicit cast from above) 336 - * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch 337 - * can optionally convert the [unsigned] long from above into 338 - * an [unsigned] long long. 326 + /* 327 + * i_size and all block offsets in ocfs2 are always 64 bits 328 + * wide. i_clusters is 32 bits, in cluster-sized units. So on 329 + * 64 bit platforms, cluster size will be the limiting factor. 339 330 */ 340 331 341 332 #if BITS_PER_LONG == 32 342 333 # if defined(CONFIG_LBD) 343 334 BUILD_BUG_ON(sizeof(sector_t) != 8); 344 - pagefactor = PAGE_CACHE_SIZE; 345 - bitshift = BITS_PER_LONG; 335 + /* 336 + * We might be limited by page cache size. 337 + */ 338 + if (bytes > PAGE_CACHE_SIZE) { 339 + bytes = PAGE_CACHE_SIZE; 340 + trim = 1; 341 + /* 342 + * Shift by 31 here so that we don't get larger than 343 + * MAX_LFS_FILESIZE 344 + */ 345 + bitshift = 31; 346 + } 346 347 # else 347 - pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift); 348 + /* 349 + * We are limited by the size of sector_t. Use block size, as 350 + * that's what we expose to the VFS. 351 + */ 352 + bytes = 1 << bbits; 353 + trim = 1; 354 + bitshift = 31; 348 355 # endif 349 356 #endif 350 357 351 - return (((unsigned long long)pagefactor) << bitshift) - 1; 358 + /* 359 + * Trim by a whole cluster when we can actually approach the 360 + * on-disk limits. Otherwise we can overflow i_clusters when 361 + * an extent start is at the max offset. 362 + */ 363 + return (((unsigned long long)bytes) << bitshift) - trim; 352 364 } 353 365 354 366 static int ocfs2_remount(struct super_block *sb, int *flags, char *data) ··· 1271 1259 int sector_size) 1272 1260 { 1273 1261 int status = 0; 1274 - int i; 1275 - struct ocfs2_dinode *di = NULL; 1262 + int i, cbits, bbits; 1263 + struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data; 1276 1264 struct inode *inode = NULL; 1277 1265 struct buffer_head *bitmap_bh = NULL; 1278 1266 struct ocfs2_journal *journal; ··· 1291 1279 sb->s_fs_info = osb; 1292 1280 sb->s_op = &ocfs2_sops; 1293 1281 sb->s_export_op = &ocfs2_export_ops; 1282 + sb->s_time_gran = 1; 1294 1283 sb->s_flags |= MS_NOATIME; 1295 1284 /* this is needed to support O_LARGEFILE */ 1296 - sb->s_maxbytes = ocfs2_max_file_offset(sb->s_blocksize_bits); 1285 + cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits); 1286 + bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits); 1287 + sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits); 1297 1288 1298 1289 osb->sb = sb; 1299 1290 /* Save off for ocfs2_rw_direct */ ··· 1355 1340 status = -ENOMEM; 1356 1341 goto bail; 1357 1342 } 1358 - 1359 - di = (struct ocfs2_dinode *)bh->b_data; 1360 1343 1361 1344 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots); 1362 1345 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
-2
fs/ocfs2/super.h
··· 45 45 46 46 #define ocfs2_abort(sb, fmt, args...) __ocfs2_abort(sb, __PRETTY_FUNCTION__, fmt, ##args) 47 47 48 - unsigned long long ocfs2_max_file_offset(unsigned int blockshift); 49 - 50 48 #endif /* OCFS2_SUPER_H */