[XFS] consolidate some code in xfs_page_state_convert The unmapped buffer case is very similar to delayed and unwritten extends. Reorganize the code to share some code for these cases.

SGI-PV: 947118
SGI-Modid: xfs-linux-melb:xfs-kern:203827a

Signed-off-by: Christoph Hellwig <hch@sgi.com>
Signed-off-by: Nathan Scott <nathans@sgi.com>

authored by Christoph Hellwig and committed by Nathan Scott d5cb48aa 9260dc6b

+33 -56
+33 -56
fs/xfs/linux-2.6/xfs_aops.c
··· 806 806 unsigned int type; 807 807 __uint64_t end_offset; 808 808 pgoff_t end_index, last_index, tlast; 809 - int flags, len, err, iomap_valid = 0, uptodate = 1; 809 + ssize_t size, len; 810 + int flags, err, iomap_valid = 0, uptodate = 1; 810 811 int page_dirty, count = 0, trylock_flag = 0; 811 812 812 813 /* wait for other IO threads? */ ··· 876 875 * 877 876 * Second case, allocate space for a delalloc buffer. 878 877 * We can return EAGAIN here in the release page case. 879 - */ 880 - if (buffer_unwritten(bh) || buffer_delay(bh)) { 878 + * 879 + * Third case, an unmapped buffer was found, and we are 880 + * in a path where we need to write the whole page out. 881 + */ 882 + if (buffer_unwritten(bh) || buffer_delay(bh) || 883 + ((buffer_uptodate(bh) || PageUptodate(page)) && 884 + !buffer_mapped(bh) && (unmapped || startio))) { 881 885 if (buffer_unwritten(bh)) { 882 886 type = IOMAP_UNWRITTEN; 883 887 flags = BMAPI_WRITE|BMAPI_IGNSTATE; 884 - } else { 888 + } else if (buffer_delay(bh)) { 885 889 type = IOMAP_DELAY; 886 890 flags = BMAPI_ALLOCATE; 887 891 if (!startio) 888 892 flags |= trylock_flag; 893 + } else { 894 + type = 0; 895 + flags = BMAPI_WRITE|BMAPI_MMAP; 889 896 } 890 897 891 898 if (!iomap_valid) { 892 - err = xfs_map_blocks(inode, offset, len, &iomap, 893 - flags); 899 + if (type == 0) { 900 + size = xfs_probe_unmapped_cluster(inode, 901 + page, bh, head); 902 + } else { 903 + size = len; 904 + } 905 + 906 + err = xfs_map_blocks(inode, offset, size, 907 + &iomap, flags); 894 908 if (err) 895 909 goto error; 896 910 iomap_valid = xfs_iomap_valid(&iomap, offset); ··· 925 909 page_dirty--; 926 910 count++; 927 911 } 928 - } else if ((buffer_uptodate(bh) || PageUptodate(page)) && 929 - (unmapped || startio)) { 930 - 912 + } else if (buffer_uptodate(bh) && startio) { 931 913 type = 0; 932 - if (!buffer_mapped(bh)) { 933 914 934 - /* 935 - * Getting here implies an unmapped buffer 936 - * was found, and we are in a path where we 937 - * need to write the whole page out. 938 - */ 939 - if (!iomap_valid) { 940 - int size; 941 - 942 - size = xfs_probe_unmapped_cluster( 943 - inode, page, bh, head); 944 - err = xfs_map_blocks(inode, offset, 945 - size, &iomap, 946 - BMAPI_WRITE|BMAPI_MMAP); 947 - if (err) 948 - goto error; 949 - iomap_valid = xfs_iomap_valid(&iomap, 950 - offset); 951 - } 952 - if (iomap_valid) { 953 - xfs_map_at_offset(bh, offset, 954 - inode->i_blkbits, 955 - &iomap); 956 - if (startio) { 957 - xfs_add_to_ioend(inode, 958 - bh, p_offset, type, 959 - &ioend, !iomap_valid); 960 - } else { 961 - set_buffer_dirty(bh); 962 - unlock_buffer(bh); 963 - mark_buffer_dirty(bh); 964 - } 965 - page_dirty--; 966 - count++; 967 - } 968 - } else if (startio) { 969 - if (buffer_uptodate(bh) && 970 - !test_and_set_bit(BH_Lock, &bh->b_state)) { 971 - ASSERT(buffer_mapped(bh)); 972 - xfs_add_to_ioend(inode, 973 - bh, p_offset, type, 974 - &ioend, !iomap_valid); 975 - page_dirty--; 976 - count++; 977 - } else { 978 - iomap_valid = 0; 979 - } 915 + if (!test_and_set_bit(BH_Lock, &bh->b_state)) { 916 + ASSERT(buffer_mapped(bh)); 917 + xfs_add_to_ioend(inode, 918 + bh, p_offset, type, 919 + &ioend, !iomap_valid); 920 + page_dirty--; 921 + count++; 980 922 } else { 981 923 iomap_valid = 0; 982 924 } 925 + } else if ((buffer_uptodate(bh) || PageUptodate(page)) && 926 + (unmapped || startio)) { 927 + iomap_valid = 0; 983 928 } 984 929 985 930 if (!iohead)