diff options
Diffstat (limited to 'fs/xfs/linux-2.6/xfs_buf.c')
-rw-r--r-- | fs/xfs/linux-2.6/xfs_buf.c | 320 |
1 files changed, 274 insertions, 46 deletions
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c index 77b8be81c769..6f76ba85f193 100644 --- a/fs/xfs/linux-2.6/xfs_buf.c +++ b/fs/xfs/linux-2.6/xfs_buf.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/migrate.h> | 33 | #include <linux/migrate.h> |
34 | #include <linux/backing-dev.h> | 34 | #include <linux/backing-dev.h> |
35 | #include <linux/freezer.h> | 35 | #include <linux/freezer.h> |
36 | #include <linux/list_sort.h> | ||
36 | 37 | ||
37 | #include "xfs_sb.h" | 38 | #include "xfs_sb.h" |
38 | #include "xfs_inum.h" | 39 | #include "xfs_inum.h" |
@@ -76,6 +77,27 @@ struct workqueue_struct *xfsconvertd_workqueue; | |||
76 | #define xfs_buf_deallocate(bp) \ | 77 | #define xfs_buf_deallocate(bp) \ |
77 | kmem_zone_free(xfs_buf_zone, (bp)); | 78 | kmem_zone_free(xfs_buf_zone, (bp)); |
78 | 79 | ||
80 | static inline int | ||
81 | xfs_buf_is_vmapped( | ||
82 | struct xfs_buf *bp) | ||
83 | { | ||
84 | /* | ||
85 | * Return true if the buffer is vmapped. | ||
86 | * | ||
87 | * The XBF_MAPPED flag is set if the buffer should be mapped, but the | ||
88 | * code is clever enough to know it doesn't have to map a single page, | ||
89 | * so the check has to be both for XBF_MAPPED and bp->b_page_count > 1. | ||
90 | */ | ||
91 | return (bp->b_flags & XBF_MAPPED) && bp->b_page_count > 1; | ||
92 | } | ||
93 | |||
94 | static inline int | ||
95 | xfs_buf_vmap_len( | ||
96 | struct xfs_buf *bp) | ||
97 | { | ||
98 | return (bp->b_page_count * PAGE_SIZE) - bp->b_offset; | ||
99 | } | ||
100 | |||
79 | /* | 101 | /* |
80 | * Page Region interfaces. | 102 | * Page Region interfaces. |
81 | * | 103 | * |
@@ -314,7 +336,7 @@ xfs_buf_free( | |||
314 | if (bp->b_flags & (_XBF_PAGE_CACHE|_XBF_PAGES)) { | 336 | if (bp->b_flags & (_XBF_PAGE_CACHE|_XBF_PAGES)) { |
315 | uint i; | 337 | uint i; |
316 | 338 | ||
317 | if ((bp->b_flags & XBF_MAPPED) && (bp->b_page_count > 1)) | 339 | if (xfs_buf_is_vmapped(bp)) |
318 | free_address(bp->b_addr - bp->b_offset); | 340 | free_address(bp->b_addr - bp->b_offset); |
319 | 341 | ||
320 | for (i = 0; i < bp->b_page_count; i++) { | 342 | for (i = 0; i < bp->b_page_count; i++) { |
@@ -1051,22 +1073,30 @@ xfs_buf_ioerror( | |||
1051 | } | 1073 | } |
1052 | 1074 | ||
1053 | int | 1075 | int |
1054 | xfs_bawrite( | 1076 | xfs_bwrite( |
1055 | void *mp, | 1077 | struct xfs_mount *mp, |
1056 | struct xfs_buf *bp) | 1078 | struct xfs_buf *bp) |
1057 | { | 1079 | { |
1058 | trace_xfs_buf_bawrite(bp, _RET_IP_); | 1080 | int iowait = (bp->b_flags & XBF_ASYNC) == 0; |
1081 | int error = 0; | ||
1059 | 1082 | ||
1060 | ASSERT(bp->b_bn != XFS_BUF_DADDR_NULL); | 1083 | bp->b_strat = xfs_bdstrat_cb; |
1084 | bp->b_mount = mp; | ||
1085 | bp->b_flags |= XBF_WRITE; | ||
1086 | if (!iowait) | ||
1087 | bp->b_flags |= _XBF_RUN_QUEUES; | ||
1061 | 1088 | ||
1062 | xfs_buf_delwri_dequeue(bp); | 1089 | xfs_buf_delwri_dequeue(bp); |
1090 | xfs_buf_iostrategy(bp); | ||
1063 | 1091 | ||
1064 | bp->b_flags &= ~(XBF_READ | XBF_DELWRI | XBF_READ_AHEAD); | 1092 | if (iowait) { |
1065 | bp->b_flags |= (XBF_WRITE | XBF_ASYNC | _XBF_RUN_QUEUES); | 1093 | error = xfs_buf_iowait(bp); |
1094 | if (error) | ||
1095 | xfs_force_shutdown(mp, SHUTDOWN_META_IO_ERROR); | ||
1096 | xfs_buf_relse(bp); | ||
1097 | } | ||
1066 | 1098 | ||
1067 | bp->b_mount = mp; | 1099 | return error; |
1068 | bp->b_strat = xfs_bdstrat_cb; | ||
1069 | return xfs_bdstrat_cb(bp); | ||
1070 | } | 1100 | } |
1071 | 1101 | ||
1072 | void | 1102 | void |
@@ -1085,6 +1115,126 @@ xfs_bdwrite( | |||
1085 | xfs_buf_delwri_queue(bp, 1); | 1115 | xfs_buf_delwri_queue(bp, 1); |
1086 | } | 1116 | } |
1087 | 1117 | ||
1118 | /* | ||
1119 | * Called when we want to stop a buffer from getting written or read. | ||
1120 | * We attach the EIO error, muck with its flags, and call biodone | ||
1121 | * so that the proper iodone callbacks get called. | ||
1122 | */ | ||
1123 | STATIC int | ||
1124 | xfs_bioerror( | ||
1125 | xfs_buf_t *bp) | ||
1126 | { | ||
1127 | #ifdef XFSERRORDEBUG | ||
1128 | ASSERT(XFS_BUF_ISREAD(bp) || bp->b_iodone); | ||
1129 | #endif | ||
1130 | |||
1131 | /* | ||
1132 | * No need to wait until the buffer is unpinned, we aren't flushing it. | ||
1133 | */ | ||
1134 | XFS_BUF_ERROR(bp, EIO); | ||
1135 | |||
1136 | /* | ||
1137 | * We're calling biodone, so delete XBF_DONE flag. | ||
1138 | */ | ||
1139 | XFS_BUF_UNREAD(bp); | ||
1140 | XFS_BUF_UNDELAYWRITE(bp); | ||
1141 | XFS_BUF_UNDONE(bp); | ||
1142 | XFS_BUF_STALE(bp); | ||
1143 | |||
1144 | XFS_BUF_CLR_BDSTRAT_FUNC(bp); | ||
1145 | xfs_biodone(bp); | ||
1146 | |||
1147 | return EIO; | ||
1148 | } | ||
1149 | |||
1150 | /* | ||
1151 | * Same as xfs_bioerror, except that we are releasing the buffer | ||
1152 | * here ourselves, and avoiding the biodone call. | ||
1153 | * This is meant for userdata errors; metadata bufs come with | ||
1154 | * iodone functions attached, so that we can track down errors. | ||
1155 | */ | ||
1156 | STATIC int | ||
1157 | xfs_bioerror_relse( | ||
1158 | struct xfs_buf *bp) | ||
1159 | { | ||
1160 | int64_t fl = XFS_BUF_BFLAGS(bp); | ||
1161 | /* | ||
1162 | * No need to wait until the buffer is unpinned. | ||
1163 | * We aren't flushing it. | ||
1164 | * | ||
1165 | * chunkhold expects B_DONE to be set, whether | ||
1166 | * we actually finish the I/O or not. We don't want to | ||
1167 | * change that interface. | ||
1168 | */ | ||
1169 | XFS_BUF_UNREAD(bp); | ||
1170 | XFS_BUF_UNDELAYWRITE(bp); | ||
1171 | XFS_BUF_DONE(bp); | ||
1172 | XFS_BUF_STALE(bp); | ||
1173 | XFS_BUF_CLR_IODONE_FUNC(bp); | ||
1174 | XFS_BUF_CLR_BDSTRAT_FUNC(bp); | ||
1175 | if (!(fl & XBF_ASYNC)) { | ||
1176 | /* | ||
1177 | * Mark b_error and B_ERROR _both_. | ||
1178 | * Lot's of chunkcache code assumes that. | ||
1179 | * There's no reason to mark error for | ||
1180 | * ASYNC buffers. | ||
1181 | */ | ||
1182 | XFS_BUF_ERROR(bp, EIO); | ||
1183 | XFS_BUF_FINISH_IOWAIT(bp); | ||
1184 | } else { | ||
1185 | xfs_buf_relse(bp); | ||
1186 | } | ||
1187 | |||
1188 | return EIO; | ||
1189 | } | ||
1190 | |||
1191 | |||
1192 | /* | ||
1193 | * All xfs metadata buffers except log state machine buffers | ||
1194 | * get this attached as their b_bdstrat callback function. | ||
1195 | * This is so that we can catch a buffer | ||
1196 | * after prematurely unpinning it to forcibly shutdown the filesystem. | ||
1197 | */ | ||
1198 | int | ||
1199 | xfs_bdstrat_cb( | ||
1200 | struct xfs_buf *bp) | ||
1201 | { | ||
1202 | if (XFS_FORCED_SHUTDOWN(bp->b_mount)) { | ||
1203 | trace_xfs_bdstrat_shut(bp, _RET_IP_); | ||
1204 | /* | ||
1205 | * Metadata write that didn't get logged but | ||
1206 | * written delayed anyway. These aren't associated | ||
1207 | * with a transaction, and can be ignored. | ||
1208 | */ | ||
1209 | if (!bp->b_iodone && !XFS_BUF_ISREAD(bp)) | ||
1210 | return xfs_bioerror_relse(bp); | ||
1211 | else | ||
1212 | return xfs_bioerror(bp); | ||
1213 | } | ||
1214 | |||
1215 | xfs_buf_iorequest(bp); | ||
1216 | return 0; | ||
1217 | } | ||
1218 | |||
1219 | /* | ||
1220 | * Wrapper around bdstrat so that we can stop data from going to disk in case | ||
1221 | * we are shutting down the filesystem. Typically user data goes thru this | ||
1222 | * path; one of the exceptions is the superblock. | ||
1223 | */ | ||
1224 | void | ||
1225 | xfsbdstrat( | ||
1226 | struct xfs_mount *mp, | ||
1227 | struct xfs_buf *bp) | ||
1228 | { | ||
1229 | if (XFS_FORCED_SHUTDOWN(mp)) { | ||
1230 | trace_xfs_bdstrat_shut(bp, _RET_IP_); | ||
1231 | xfs_bioerror_relse(bp); | ||
1232 | return; | ||
1233 | } | ||
1234 | |||
1235 | xfs_buf_iorequest(bp); | ||
1236 | } | ||
1237 | |||
1088 | STATIC void | 1238 | STATIC void |
1089 | _xfs_buf_ioend( | 1239 | _xfs_buf_ioend( |
1090 | xfs_buf_t *bp, | 1240 | xfs_buf_t *bp, |
@@ -1107,6 +1257,9 @@ xfs_buf_bio_end_io( | |||
1107 | 1257 | ||
1108 | xfs_buf_ioerror(bp, -error); | 1258 | xfs_buf_ioerror(bp, -error); |
1109 | 1259 | ||
1260 | if (!error && xfs_buf_is_vmapped(bp) && (bp->b_flags & XBF_READ)) | ||
1261 | invalidate_kernel_vmap_range(bp->b_addr, xfs_buf_vmap_len(bp)); | ||
1262 | |||
1110 | do { | 1263 | do { |
1111 | struct page *page = bvec->bv_page; | 1264 | struct page *page = bvec->bv_page; |
1112 | 1265 | ||
@@ -1216,6 +1369,10 @@ next_chunk: | |||
1216 | 1369 | ||
1217 | submit_io: | 1370 | submit_io: |
1218 | if (likely(bio->bi_size)) { | 1371 | if (likely(bio->bi_size)) { |
1372 | if (xfs_buf_is_vmapped(bp)) { | ||
1373 | flush_kernel_vmap_range(bp->b_addr, | ||
1374 | xfs_buf_vmap_len(bp)); | ||
1375 | } | ||
1219 | submit_bio(rw, bio); | 1376 | submit_bio(rw, bio); |
1220 | if (size) | 1377 | if (size) |
1221 | goto next_chunk; | 1378 | goto next_chunk; |
@@ -1296,7 +1453,7 @@ xfs_buf_iomove( | |||
1296 | xfs_buf_t *bp, /* buffer to process */ | 1453 | xfs_buf_t *bp, /* buffer to process */ |
1297 | size_t boff, /* starting buffer offset */ | 1454 | size_t boff, /* starting buffer offset */ |
1298 | size_t bsize, /* length to copy */ | 1455 | size_t bsize, /* length to copy */ |
1299 | caddr_t data, /* data address */ | 1456 | void *data, /* data address */ |
1300 | xfs_buf_rw_t mode) /* read/write/zero flag */ | 1457 | xfs_buf_rw_t mode) /* read/write/zero flag */ |
1301 | { | 1458 | { |
1302 | size_t bend, cpoff, csize; | 1459 | size_t bend, cpoff, csize; |
@@ -1378,8 +1535,8 @@ xfs_alloc_bufhash( | |||
1378 | 1535 | ||
1379 | btp->bt_hashshift = external ? 3 : 8; /* 8 or 256 buckets */ | 1536 | btp->bt_hashshift = external ? 3 : 8; /* 8 or 256 buckets */ |
1380 | btp->bt_hashmask = (1 << btp->bt_hashshift) - 1; | 1537 | btp->bt_hashmask = (1 << btp->bt_hashshift) - 1; |
1381 | btp->bt_hash = kmem_zalloc((1 << btp->bt_hashshift) * | 1538 | btp->bt_hash = kmem_zalloc_large((1 << btp->bt_hashshift) * |
1382 | sizeof(xfs_bufhash_t), KM_SLEEP | KM_LARGE); | 1539 | sizeof(xfs_bufhash_t)); |
1383 | for (i = 0; i < (1 << btp->bt_hashshift); i++) { | 1540 | for (i = 0; i < (1 << btp->bt_hashshift); i++) { |
1384 | spin_lock_init(&btp->bt_hash[i].bh_lock); | 1541 | spin_lock_init(&btp->bt_hash[i].bh_lock); |
1385 | INIT_LIST_HEAD(&btp->bt_hash[i].bh_list); | 1542 | INIT_LIST_HEAD(&btp->bt_hash[i].bh_list); |
@@ -1390,7 +1547,7 @@ STATIC void | |||
1390 | xfs_free_bufhash( | 1547 | xfs_free_bufhash( |
1391 | xfs_buftarg_t *btp) | 1548 | xfs_buftarg_t *btp) |
1392 | { | 1549 | { |
1393 | kmem_free(btp->bt_hash); | 1550 | kmem_free_large(btp->bt_hash); |
1394 | btp->bt_hash = NULL; | 1551 | btp->bt_hash = NULL; |
1395 | } | 1552 | } |
1396 | 1553 | ||
@@ -1595,6 +1752,11 @@ xfs_buf_delwri_queue( | |||
1595 | list_del(&bp->b_list); | 1752 | list_del(&bp->b_list); |
1596 | } | 1753 | } |
1597 | 1754 | ||
1755 | if (list_empty(dwq)) { | ||
1756 | /* start xfsbufd as it is about to have something to do */ | ||
1757 | wake_up_process(bp->b_target->bt_task); | ||
1758 | } | ||
1759 | |||
1598 | bp->b_flags |= _XBF_DELWRI_Q; | 1760 | bp->b_flags |= _XBF_DELWRI_Q; |
1599 | list_add_tail(&bp->b_list, dwq); | 1761 | list_add_tail(&bp->b_list, dwq); |
1600 | bp->b_queuetime = jiffies; | 1762 | bp->b_queuetime = jiffies; |
@@ -1626,6 +1788,35 @@ xfs_buf_delwri_dequeue( | |||
1626 | trace_xfs_buf_delwri_dequeue(bp, _RET_IP_); | 1788 | trace_xfs_buf_delwri_dequeue(bp, _RET_IP_); |
1627 | } | 1789 | } |
1628 | 1790 | ||
1791 | /* | ||
1792 | * If a delwri buffer needs to be pushed before it has aged out, then promote | ||
1793 | * it to the head of the delwri queue so that it will be flushed on the next | ||
1794 | * xfsbufd run. We do this by resetting the queuetime of the buffer to be older | ||
1795 | * than the age currently needed to flush the buffer. Hence the next time the | ||
1796 | * xfsbufd sees it is guaranteed to be considered old enough to flush. | ||
1797 | */ | ||
1798 | void | ||
1799 | xfs_buf_delwri_promote( | ||
1800 | struct xfs_buf *bp) | ||
1801 | { | ||
1802 | struct xfs_buftarg *btp = bp->b_target; | ||
1803 | long age = xfs_buf_age_centisecs * msecs_to_jiffies(10) + 1; | ||
1804 | |||
1805 | ASSERT(bp->b_flags & XBF_DELWRI); | ||
1806 | ASSERT(bp->b_flags & _XBF_DELWRI_Q); | ||
1807 | |||
1808 | /* | ||
1809 | * Check the buffer age before locking the delayed write queue as we | ||
1810 | * don't need to promote buffers that are already past the flush age. | ||
1811 | */ | ||
1812 | if (bp->b_queuetime < jiffies - age) | ||
1813 | return; | ||
1814 | bp->b_queuetime = jiffies - age; | ||
1815 | spin_lock(&btp->bt_delwrite_lock); | ||
1816 | list_move(&bp->b_list, &btp->bt_delwrite_queue); | ||
1817 | spin_unlock(&btp->bt_delwrite_lock); | ||
1818 | } | ||
1819 | |||
1629 | STATIC void | 1820 | STATIC void |
1630 | xfs_buf_runall_queues( | 1821 | xfs_buf_runall_queues( |
1631 | struct workqueue_struct *queue) | 1822 | struct workqueue_struct *queue) |
@@ -1644,6 +1835,8 @@ xfsbufd_wakeup( | |||
1644 | list_for_each_entry(btp, &xfs_buftarg_list, bt_list) { | 1835 | list_for_each_entry(btp, &xfs_buftarg_list, bt_list) { |
1645 | if (test_bit(XBT_FORCE_SLEEP, &btp->bt_flags)) | 1836 | if (test_bit(XBT_FORCE_SLEEP, &btp->bt_flags)) |
1646 | continue; | 1837 | continue; |
1838 | if (list_empty(&btp->bt_delwrite_queue)) | ||
1839 | continue; | ||
1647 | set_bit(XBT_FORCE_FLUSH, &btp->bt_flags); | 1840 | set_bit(XBT_FORCE_FLUSH, &btp->bt_flags); |
1648 | wake_up_process(btp->bt_task); | 1841 | wake_up_process(btp->bt_task); |
1649 | } | 1842 | } |
@@ -1694,20 +1887,53 @@ xfs_buf_delwri_split( | |||
1694 | 1887 | ||
1695 | } | 1888 | } |
1696 | 1889 | ||
1890 | /* | ||
1891 | * Compare function is more complex than it needs to be because | ||
1892 | * the return value is only 32 bits and we are doing comparisons | ||
1893 | * on 64 bit values | ||
1894 | */ | ||
1895 | static int | ||
1896 | xfs_buf_cmp( | ||
1897 | void *priv, | ||
1898 | struct list_head *a, | ||
1899 | struct list_head *b) | ||
1900 | { | ||
1901 | struct xfs_buf *ap = container_of(a, struct xfs_buf, b_list); | ||
1902 | struct xfs_buf *bp = container_of(b, struct xfs_buf, b_list); | ||
1903 | xfs_daddr_t diff; | ||
1904 | |||
1905 | diff = ap->b_bn - bp->b_bn; | ||
1906 | if (diff < 0) | ||
1907 | return -1; | ||
1908 | if (diff > 0) | ||
1909 | return 1; | ||
1910 | return 0; | ||
1911 | } | ||
1912 | |||
1913 | void | ||
1914 | xfs_buf_delwri_sort( | ||
1915 | xfs_buftarg_t *target, | ||
1916 | struct list_head *list) | ||
1917 | { | ||
1918 | list_sort(NULL, list, xfs_buf_cmp); | ||
1919 | } | ||
1920 | |||
1697 | STATIC int | 1921 | STATIC int |
1698 | xfsbufd( | 1922 | xfsbufd( |
1699 | void *data) | 1923 | void *data) |
1700 | { | 1924 | { |
1701 | struct list_head tmp; | 1925 | xfs_buftarg_t *target = (xfs_buftarg_t *)data; |
1702 | xfs_buftarg_t *target = (xfs_buftarg_t *)data; | ||
1703 | int count; | ||
1704 | xfs_buf_t *bp; | ||
1705 | 1926 | ||
1706 | current->flags |= PF_MEMALLOC; | 1927 | current->flags |= PF_MEMALLOC; |
1707 | 1928 | ||
1708 | set_freezable(); | 1929 | set_freezable(); |
1709 | 1930 | ||
1710 | do { | 1931 | do { |
1932 | long age = xfs_buf_age_centisecs * msecs_to_jiffies(10); | ||
1933 | long tout = xfs_buf_timer_centisecs * msecs_to_jiffies(10); | ||
1934 | int count = 0; | ||
1935 | struct list_head tmp; | ||
1936 | |||
1711 | if (unlikely(freezing(current))) { | 1937 | if (unlikely(freezing(current))) { |
1712 | set_bit(XBT_FORCE_SLEEP, &target->bt_flags); | 1938 | set_bit(XBT_FORCE_SLEEP, &target->bt_flags); |
1713 | refrigerator(); | 1939 | refrigerator(); |
@@ -1715,17 +1941,16 @@ xfsbufd( | |||
1715 | clear_bit(XBT_FORCE_SLEEP, &target->bt_flags); | 1941 | clear_bit(XBT_FORCE_SLEEP, &target->bt_flags); |
1716 | } | 1942 | } |
1717 | 1943 | ||
1718 | schedule_timeout_interruptible( | 1944 | /* sleep for a long time if there is nothing to do. */ |
1719 | xfs_buf_timer_centisecs * msecs_to_jiffies(10)); | 1945 | if (list_empty(&target->bt_delwrite_queue)) |
1946 | tout = MAX_SCHEDULE_TIMEOUT; | ||
1947 | schedule_timeout_interruptible(tout); | ||
1720 | 1948 | ||
1721 | xfs_buf_delwri_split(target, &tmp, | 1949 | xfs_buf_delwri_split(target, &tmp, age); |
1722 | xfs_buf_age_centisecs * msecs_to_jiffies(10)); | 1950 | list_sort(NULL, &tmp, xfs_buf_cmp); |
1723 | |||
1724 | count = 0; | ||
1725 | while (!list_empty(&tmp)) { | 1951 | while (!list_empty(&tmp)) { |
1726 | bp = list_entry(tmp.next, xfs_buf_t, b_list); | 1952 | struct xfs_buf *bp; |
1727 | ASSERT(target == bp->b_target); | 1953 | bp = list_first_entry(&tmp, struct xfs_buf, b_list); |
1728 | |||
1729 | list_del_init(&bp->b_list); | 1954 | list_del_init(&bp->b_list); |
1730 | xfs_buf_iostrategy(bp); | 1955 | xfs_buf_iostrategy(bp); |
1731 | count++; | 1956 | count++; |
@@ -1751,42 +1976,45 @@ xfs_flush_buftarg( | |||
1751 | xfs_buftarg_t *target, | 1976 | xfs_buftarg_t *target, |
1752 | int wait) | 1977 | int wait) |
1753 | { | 1978 | { |
1754 | struct list_head tmp; | 1979 | xfs_buf_t *bp; |
1755 | xfs_buf_t *bp, *n; | ||
1756 | int pincount = 0; | 1980 | int pincount = 0; |
1981 | LIST_HEAD(tmp_list); | ||
1982 | LIST_HEAD(wait_list); | ||
1757 | 1983 | ||
1758 | xfs_buf_runall_queues(xfsconvertd_workqueue); | 1984 | xfs_buf_runall_queues(xfsconvertd_workqueue); |
1759 | xfs_buf_runall_queues(xfsdatad_workqueue); | 1985 | xfs_buf_runall_queues(xfsdatad_workqueue); |
1760 | xfs_buf_runall_queues(xfslogd_workqueue); | 1986 | xfs_buf_runall_queues(xfslogd_workqueue); |
1761 | 1987 | ||
1762 | set_bit(XBT_FORCE_FLUSH, &target->bt_flags); | 1988 | set_bit(XBT_FORCE_FLUSH, &target->bt_flags); |
1763 | pincount = xfs_buf_delwri_split(target, &tmp, 0); | 1989 | pincount = xfs_buf_delwri_split(target, &tmp_list, 0); |
1764 | 1990 | ||
1765 | /* | 1991 | /* |
1766 | * Dropped the delayed write list lock, now walk the temporary list | 1992 | * Dropped the delayed write list lock, now walk the temporary list. |
1993 | * All I/O is issued async and then if we need to wait for completion | ||
1994 | * we do that after issuing all the IO. | ||
1767 | */ | 1995 | */ |
1768 | list_for_each_entry_safe(bp, n, &tmp, b_list) { | 1996 | list_sort(NULL, &tmp_list, xfs_buf_cmp); |
1997 | while (!list_empty(&tmp_list)) { | ||
1998 | bp = list_first_entry(&tmp_list, struct xfs_buf, b_list); | ||
1769 | ASSERT(target == bp->b_target); | 1999 | ASSERT(target == bp->b_target); |
1770 | if (wait) | 2000 | list_del_init(&bp->b_list); |
2001 | if (wait) { | ||
1771 | bp->b_flags &= ~XBF_ASYNC; | 2002 | bp->b_flags &= ~XBF_ASYNC; |
1772 | else | 2003 | list_add(&bp->b_list, &wait_list); |
1773 | list_del_init(&bp->b_list); | 2004 | } |
1774 | |||
1775 | xfs_buf_iostrategy(bp); | 2005 | xfs_buf_iostrategy(bp); |
1776 | } | 2006 | } |
1777 | 2007 | ||
1778 | if (wait) | 2008 | if (wait) { |
2009 | /* Expedite and wait for IO to complete. */ | ||
1779 | blk_run_address_space(target->bt_mapping); | 2010 | blk_run_address_space(target->bt_mapping); |
2011 | while (!list_empty(&wait_list)) { | ||
2012 | bp = list_first_entry(&wait_list, struct xfs_buf, b_list); | ||
1780 | 2013 | ||
1781 | /* | 2014 | list_del_init(&bp->b_list); |
1782 | * Remaining list items must be flushed before returning | 2015 | xfs_iowait(bp); |
1783 | */ | 2016 | xfs_buf_relse(bp); |
1784 | while (!list_empty(&tmp)) { | 2017 | } |
1785 | bp = list_entry(tmp.next, xfs_buf_t, b_list); | ||
1786 | |||
1787 | list_del_init(&bp->b_list); | ||
1788 | xfs_iowait(bp); | ||
1789 | xfs_buf_relse(bp); | ||
1790 | } | 2018 | } |
1791 | 2019 | ||
1792 | return pincount; | 2020 | return pincount; |