hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/xfs/xfs_rtalloc.c
....@@ -11,20 +11,14 @@
1111 #include "xfs_trans_resv.h"
1212 #include "xfs_bit.h"
1313 #include "xfs_mount.h"
14
-#include "xfs_defer.h"
1514 #include "xfs_inode.h"
1615 #include "xfs_bmap.h"
17
-#include "xfs_bmap_util.h"
1816 #include "xfs_bmap_btree.h"
19
-#include "xfs_alloc.h"
20
-#include "xfs_error.h"
2117 #include "xfs_trans.h"
2218 #include "xfs_trans_space.h"
23
-#include "xfs_trace.h"
24
-#include "xfs_buf.h"
2519 #include "xfs_icache.h"
2620 #include "xfs_rtalloc.h"
27
-
21
+#include "xfs_sb.h"
2822
2923 /*
3024 * Read and return the summary information for a given extent size,
....@@ -64,8 +58,12 @@
6458 int log; /* loop counter, log2 of ext. size */
6559 xfs_suminfo_t sum; /* summary data */
6660
61
+ /* There are no extents at levels < m_rsum_cache[bbno]. */
62
+ if (mp->m_rsum_cache && low < mp->m_rsum_cache[bbno])
63
+ low = mp->m_rsum_cache[bbno];
64
+
6765 /*
68
- * Loop over logs of extent sizes. Order is irrelevant.
66
+ * Loop over logs of extent sizes.
6967 */
7068 for (log = low; log <= high; log++) {
7169 /*
....@@ -80,13 +78,17 @@
8078 */
8179 if (sum) {
8280 *stat = 1;
83
- return 0;
81
+ goto out;
8482 }
8583 }
8684 /*
8785 * Found nothing, return failure.
8886 */
8987 *stat = 0;
88
+out:
89
+ /* There were no extents at levels < log. */
90
+ if (mp->m_rsum_cache && log > mp->m_rsum_cache[bbno])
91
+ mp->m_rsum_cache[bbno] = log;
9092 return 0;
9193 }
9294
....@@ -776,7 +778,13 @@
776778 struct xfs_bmbt_irec map; /* block map output */
777779 int nmap; /* number of block maps */
778780 int resblks; /* space reservation */
781
+ enum xfs_blft buf_type;
779782 struct xfs_trans *tp;
783
+
784
+ if (ip == mp->m_rsumip)
785
+ buf_type = XFS_BLFT_RTSUMMARY_BUF;
786
+ else
787
+ buf_type = XFS_BLFT_RTBITMAP_BUF;
780788
781789 /*
782790 * Allocate space to the file, as necessary.
....@@ -801,8 +809,7 @@
801809 */
802810 nmap = 1;
803811 error = xfs_bmapi_write(tp, ip, oblocks, nblocks - oblocks,
804
- XFS_BMAPI_METADATA, resblks, &map,
805
- &nmap);
812
+ XFS_BMAPI_METADATA, 0, &map, &nmap);
806813 if (!error && nmap < 1)
807814 error = -ENOSPC;
808815 if (error)
....@@ -836,12 +843,13 @@
836843 * Get a buffer for the block.
837844 */
838845 d = XFS_FSB_TO_DADDR(mp, fsbno);
839
- bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
840
- mp->m_bsize, 0);
841
- if (bp == NULL) {
842
- error = -EIO;
846
+ error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
847
+ mp->m_bsize, 0, &bp);
848
+ if (error)
843849 goto out_trans_cancel;
844
- }
850
+
851
+ xfs_trans_buf_set_type(tp, bp, buf_type);
852
+ bp->b_ops = &xfs_rtbuf_ops;
845853 memset(bp->b_addr, 0, mp->m_sb.sb_blocksize);
846854 xfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1);
847855 /*
....@@ -862,6 +870,21 @@
862870 out_trans_cancel:
863871 xfs_trans_cancel(tp);
864872 return error;
873
+}
874
+
875
+static void
876
+xfs_alloc_rsum_cache(
877
+ xfs_mount_t *mp, /* file system mount structure */
878
+ xfs_extlen_t rbmblocks) /* number of rt bitmap blocks */
879
+{
880
+ /*
881
+ * The rsum cache is initialized to all zeroes, which is trivially a
882
+ * lower bound on the minimum level with any free extents. We can
883
+ * continue without the cache if it couldn't be allocated.
884
+ */
885
+ mp->m_rsum_cache = kvzalloc(rbmblocks, GFP_KERNEL);
886
+ if (!mp->m_rsum_cache)
887
+ xfs_warn(mp, "could not allocate realtime summary cache");
865888 }
866889
867890 /*
....@@ -892,6 +915,7 @@
892915 xfs_extlen_t rsumblocks; /* current number of rt summary blks */
893916 xfs_sb_t *sbp; /* old superblock */
894917 xfs_fsblock_t sumbno; /* summary block number */
918
+ uint8_t *rsum_cache; /* old summary cache */
895919
896920 sbp = &mp->m_sb;
897921 /*
....@@ -948,10 +972,15 @@
948972 error = xfs_growfs_rt_alloc(mp, rsumblocks, nrsumblocks, mp->m_rsumip);
949973 if (error)
950974 return error;
975
+
976
+ rsum_cache = mp->m_rsum_cache;
977
+ if (nrbmblocks != sbp->sb_rbmblocks)
978
+ xfs_alloc_rsum_cache(mp, nrbmblocks);
979
+
951980 /*
952981 * Allocate a new (fake) mount/sb.
953982 */
954
- nmp = kmem_alloc(sizeof(*nmp), KM_SLEEP);
983
+ nmp = kmem_alloc(sizeof(*nmp), 0);
955984 /*
956985 * Loop over the bitmap blocks.
957986 * We will do everything one bitmap block at a time.
....@@ -995,7 +1024,7 @@
9951024 /*
9961025 * Lock out other callers by grabbing the bitmap inode lock.
9971026 */
998
- xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL);
1027
+ xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP);
9991028 xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL);
10001029 /*
10011030 * Update the bitmap inode's size ondisk and incore. We need
....@@ -1009,7 +1038,7 @@
10091038 /*
10101039 * Get the summary inode into the transaction.
10111040 */
1012
- xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL);
1041
+ xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM);
10131042 xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL);
10141043 /*
10151044 * Update the summary inode's size. We need to update the
....@@ -1073,11 +1102,31 @@
10731102 if (error)
10741103 break;
10751104 }
1105
+ if (error)
1106
+ goto out_free;
10761107
1108
+ /* Update secondary superblocks now the physical grow has completed */
1109
+ error = xfs_update_secondary_sbs(mp);
1110
+
1111
+out_free:
10771112 /*
10781113 * Free the fake mp structure.
10791114 */
10801115 kmem_free(nmp);
1116
+
1117
+ /*
1118
+ * If we had to allocate a new rsum_cache, we either need to free the
1119
+ * old one (if we succeeded) or free the new one and restore the old one
1120
+ * (if there was an error).
1121
+ */
1122
+ if (rsum_cache != mp->m_rsum_cache) {
1123
+ if (error) {
1124
+ kmem_free(mp->m_rsum_cache);
1125
+ mp->m_rsum_cache = rsum_cache;
1126
+ } else {
1127
+ kmem_free(rsum_cache);
1128
+ }
1129
+ }
10811130
10821131 return error;
10831132 }
....@@ -1204,8 +1253,8 @@
12041253 }
12051254
12061255 /*
1207
- * Get the bitmap and summary inodes into the mount structure
1208
- * at mount time.
1256
+ * Get the bitmap and summary inodes and the summary cache into the mount
1257
+ * structure at mount time.
12091258 */
12101259 int /* error */
12111260 xfs_rtmount_inodes(
....@@ -1226,6 +1275,7 @@
12261275 return error;
12271276 }
12281277 ASSERT(mp->m_rsumip != NULL);
1278
+ xfs_alloc_rsum_cache(mp, sbp->sb_rbmblocks);
12291279 return 0;
12301280 }
12311281
....@@ -1233,6 +1283,7 @@
12331283 xfs_rtunmount_inodes(
12341284 struct xfs_mount *mp)
12351285 {
1286
+ kmem_free(mp->m_rsum_cache);
12361287 if (mp->m_rbmip)
12371288 xfs_irele(mp->m_rbmip);
12381289 if (mp->m_rsumip)