aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ocfs2/alloc.c')
-rw-r--r--fs/ocfs2/alloc.c99
1 files changed, 45 insertions, 54 deletions
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index f43bc5f18a35..edc91ca3792a 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -52,14 +52,14 @@ static int ocfs2_extent_contig(struct inode *inode,
52 u64 blkno); 52 u64 blkno);
53 53
54static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb, 54static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb,
55 struct ocfs2_journal_handle *handle, 55 handle_t *handle,
56 struct inode *inode, 56 struct inode *inode,
57 int wanted, 57 int wanted,
58 struct ocfs2_alloc_context *meta_ac, 58 struct ocfs2_alloc_context *meta_ac,
59 struct buffer_head *bhs[]); 59 struct buffer_head *bhs[]);
60 60
61static int ocfs2_add_branch(struct ocfs2_super *osb, 61static int ocfs2_add_branch(struct ocfs2_super *osb,
62 struct ocfs2_journal_handle *handle, 62 handle_t *handle,
63 struct inode *inode, 63 struct inode *inode,
64 struct buffer_head *fe_bh, 64 struct buffer_head *fe_bh,
65 struct buffer_head *eb_bh, 65 struct buffer_head *eb_bh,
@@ -67,14 +67,14 @@ static int ocfs2_add_branch(struct ocfs2_super *osb,
67 struct ocfs2_alloc_context *meta_ac); 67 struct ocfs2_alloc_context *meta_ac);
68 68
69static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, 69static int ocfs2_shift_tree_depth(struct ocfs2_super *osb,
70 struct ocfs2_journal_handle *handle, 70 handle_t *handle,
71 struct inode *inode, 71 struct inode *inode,
72 struct buffer_head *fe_bh, 72 struct buffer_head *fe_bh,
73 struct ocfs2_alloc_context *meta_ac, 73 struct ocfs2_alloc_context *meta_ac,
74 struct buffer_head **ret_new_eb_bh); 74 struct buffer_head **ret_new_eb_bh);
75 75
76static int ocfs2_do_insert_extent(struct ocfs2_super *osb, 76static int ocfs2_do_insert_extent(struct ocfs2_super *osb,
77 struct ocfs2_journal_handle *handle, 77 handle_t *handle,
78 struct inode *inode, 78 struct inode *inode,
79 struct buffer_head *fe_bh, 79 struct buffer_head *fe_bh,
80 u64 blkno, 80 u64 blkno,
@@ -152,7 +152,7 @@ bail:
152 * l_count for you 152 * l_count for you
153 */ 153 */
154static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb, 154static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb,
155 struct ocfs2_journal_handle *handle, 155 handle_t *handle,
156 struct inode *inode, 156 struct inode *inode,
157 int wanted, 157 int wanted,
158 struct ocfs2_alloc_context *meta_ac, 158 struct ocfs2_alloc_context *meta_ac,
@@ -253,7 +253,7 @@ bail:
253 * contain a single record with e_clusters == 0. 253 * contain a single record with e_clusters == 0.
254 */ 254 */
255static int ocfs2_add_branch(struct ocfs2_super *osb, 255static int ocfs2_add_branch(struct ocfs2_super *osb,
256 struct ocfs2_journal_handle *handle, 256 handle_t *handle,
257 struct inode *inode, 257 struct inode *inode,
258 struct buffer_head *fe_bh, 258 struct buffer_head *fe_bh,
259 struct buffer_head *eb_bh, 259 struct buffer_head *eb_bh,
@@ -418,7 +418,7 @@ bail:
418 * after this call. 418 * after this call.
419 */ 419 */
420static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, 420static int ocfs2_shift_tree_depth(struct ocfs2_super *osb,
421 struct ocfs2_journal_handle *handle, 421 handle_t *handle,
422 struct inode *inode, 422 struct inode *inode,
423 struct buffer_head *fe_bh, 423 struct buffer_head *fe_bh,
424 struct ocfs2_alloc_context *meta_ac, 424 struct ocfs2_alloc_context *meta_ac,
@@ -520,7 +520,7 @@ bail:
520 * down. 520 * down.
521 */ 521 */
522static int ocfs2_do_insert_extent(struct ocfs2_super *osb, 522static int ocfs2_do_insert_extent(struct ocfs2_super *osb,
523 struct ocfs2_journal_handle *handle, 523 handle_t *handle,
524 struct inode *inode, 524 struct inode *inode,
525 struct buffer_head *fe_bh, 525 struct buffer_head *fe_bh,
526 u64 start_blk, 526 u64 start_blk,
@@ -809,7 +809,7 @@ bail:
809 809
810/* the caller needs to update fe->i_clusters */ 810/* the caller needs to update fe->i_clusters */
811int ocfs2_insert_extent(struct ocfs2_super *osb, 811int ocfs2_insert_extent(struct ocfs2_super *osb,
812 struct ocfs2_journal_handle *handle, 812 handle_t *handle,
813 struct inode *inode, 813 struct inode *inode,
814 struct buffer_head *fe_bh, 814 struct buffer_head *fe_bh,
815 u64 start_blk, 815 u64 start_blk,
@@ -951,7 +951,7 @@ static int ocfs2_truncate_log_can_coalesce(struct ocfs2_truncate_log *tl,
951} 951}
952 952
953static int ocfs2_truncate_log_append(struct ocfs2_super *osb, 953static int ocfs2_truncate_log_append(struct ocfs2_super *osb,
954 struct ocfs2_journal_handle *handle, 954 handle_t *handle,
955 u64 start_blk, 955 u64 start_blk,
956 unsigned int num_clusters) 956 unsigned int num_clusters)
957{ 957{
@@ -1034,7 +1034,7 @@ bail:
1034} 1034}
1035 1035
1036static int ocfs2_replay_truncate_records(struct ocfs2_super *osb, 1036static int ocfs2_replay_truncate_records(struct ocfs2_super *osb,
1037 struct ocfs2_journal_handle *handle, 1037 handle_t *handle,
1038 struct inode *data_alloc_inode, 1038 struct inode *data_alloc_inode,
1039 struct buffer_head *data_alloc_bh) 1039 struct buffer_head *data_alloc_bh)
1040{ 1040{
@@ -1113,7 +1113,7 @@ static int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
1113{ 1113{
1114 int status; 1114 int status;
1115 unsigned int num_to_flush; 1115 unsigned int num_to_flush;
1116 struct ocfs2_journal_handle *handle = NULL; 1116 handle_t *handle;
1117 struct inode *tl_inode = osb->osb_tl_inode; 1117 struct inode *tl_inode = osb->osb_tl_inode;
1118 struct inode *data_alloc_inode = NULL; 1118 struct inode *data_alloc_inode = NULL;
1119 struct buffer_head *tl_bh = osb->osb_tl_bh; 1119 struct buffer_head *tl_bh = osb->osb_tl_bh;
@@ -1130,7 +1130,7 @@ static int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
1130 if (!OCFS2_IS_VALID_DINODE(di)) { 1130 if (!OCFS2_IS_VALID_DINODE(di)) {
1131 OCFS2_RO_ON_INVALID_DINODE(osb->sb, di); 1131 OCFS2_RO_ON_INVALID_DINODE(osb->sb, di);
1132 status = -EIO; 1132 status = -EIO;
1133 goto bail; 1133 goto out;
1134 } 1134 }
1135 1135
1136 num_to_flush = le16_to_cpu(tl->tl_used); 1136 num_to_flush = le16_to_cpu(tl->tl_used);
@@ -1138,14 +1138,7 @@ static int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
1138 num_to_flush, (unsigned long long)OCFS2_I(tl_inode)->ip_blkno); 1138 num_to_flush, (unsigned long long)OCFS2_I(tl_inode)->ip_blkno);
1139 if (!num_to_flush) { 1139 if (!num_to_flush) {
1140 status = 0; 1140 status = 0;
1141 goto bail; 1141 goto out;
1142 }
1143
1144 handle = ocfs2_alloc_handle(osb);
1145 if (!handle) {
1146 status = -ENOMEM;
1147 mlog_errno(status);
1148 goto bail;
1149 } 1142 }
1150 1143
1151 data_alloc_inode = ocfs2_get_system_file_inode(osb, 1144 data_alloc_inode = ocfs2_get_system_file_inode(osb,
@@ -1154,41 +1147,40 @@ static int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
1154 if (!data_alloc_inode) { 1147 if (!data_alloc_inode) {
1155 status = -EINVAL; 1148 status = -EINVAL;
1156 mlog(ML_ERROR, "Could not get bitmap inode!\n"); 1149 mlog(ML_ERROR, "Could not get bitmap inode!\n");
1157 goto bail; 1150 goto out;
1158 } 1151 }
1159 1152
1160 ocfs2_handle_add_inode(handle, data_alloc_inode); 1153 mutex_lock(&data_alloc_inode->i_mutex);
1161 status = ocfs2_meta_lock(data_alloc_inode, handle, &data_alloc_bh, 1); 1154
1155 status = ocfs2_meta_lock(data_alloc_inode, &data_alloc_bh, 1);
1162 if (status < 0) { 1156 if (status < 0) {
1163 mlog_errno(status); 1157 mlog_errno(status);
1164 goto bail; 1158 goto out_mutex;
1165 } 1159 }
1166 1160
1167 handle = ocfs2_start_trans(osb, handle, OCFS2_TRUNCATE_LOG_UPDATE); 1161 handle = ocfs2_start_trans(osb, OCFS2_TRUNCATE_LOG_UPDATE);
1168 if (IS_ERR(handle)) { 1162 if (IS_ERR(handle)) {
1169 status = PTR_ERR(handle); 1163 status = PTR_ERR(handle);
1170 handle = NULL;
1171 mlog_errno(status); 1164 mlog_errno(status);
1172 goto bail; 1165 goto out_unlock;
1173 } 1166 }
1174 1167
1175 status = ocfs2_replay_truncate_records(osb, handle, data_alloc_inode, 1168 status = ocfs2_replay_truncate_records(osb, handle, data_alloc_inode,
1176 data_alloc_bh); 1169 data_alloc_bh);
1177 if (status < 0) { 1170 if (status < 0)
1178 mlog_errno(status); 1171 mlog_errno(status);
1179 goto bail;
1180 }
1181 1172
1182bail: 1173 ocfs2_commit_trans(osb, handle);
1183 if (handle)
1184 ocfs2_commit_trans(handle);
1185 1174
1186 if (data_alloc_inode) 1175out_unlock:
1187 iput(data_alloc_inode); 1176 brelse(data_alloc_bh);
1177 ocfs2_meta_unlock(data_alloc_inode, 1);
1188 1178
1189 if (data_alloc_bh) 1179out_mutex:
1190 brelse(data_alloc_bh); 1180 mutex_unlock(&data_alloc_inode->i_mutex);
1181 iput(data_alloc_inode);
1191 1182
1183out:
1192 mlog_exit(status); 1184 mlog_exit(status);
1193 return status; 1185 return status;
1194} 1186}
@@ -1205,10 +1197,12 @@ int ocfs2_flush_truncate_log(struct ocfs2_super *osb)
1205 return status; 1197 return status;
1206} 1198}
1207 1199
1208static void ocfs2_truncate_log_worker(void *data) 1200static void ocfs2_truncate_log_worker(struct work_struct *work)
1209{ 1201{
1210 int status; 1202 int status;
1211 struct ocfs2_super *osb = data; 1203 struct ocfs2_super *osb =
1204 container_of(work, struct ocfs2_super,
1205 osb_truncate_log_wq.work);
1212 1206
1213 mlog_entry_void(); 1207 mlog_entry_void();
1214 1208
@@ -1347,7 +1341,7 @@ int ocfs2_complete_truncate_log_recovery(struct ocfs2_super *osb,
1347 int i; 1341 int i;
1348 unsigned int clusters, num_recs, start_cluster; 1342 unsigned int clusters, num_recs, start_cluster;
1349 u64 start_blk; 1343 u64 start_blk;
1350 struct ocfs2_journal_handle *handle; 1344 handle_t *handle;
1351 struct inode *tl_inode = osb->osb_tl_inode; 1345 struct inode *tl_inode = osb->osb_tl_inode;
1352 struct ocfs2_truncate_log *tl; 1346 struct ocfs2_truncate_log *tl;
1353 1347
@@ -1373,8 +1367,7 @@ int ocfs2_complete_truncate_log_recovery(struct ocfs2_super *osb,
1373 } 1367 }
1374 } 1368 }
1375 1369
1376 handle = ocfs2_start_trans(osb, NULL, 1370 handle = ocfs2_start_trans(osb, OCFS2_TRUNCATE_LOG_UPDATE);
1377 OCFS2_TRUNCATE_LOG_UPDATE);
1378 if (IS_ERR(handle)) { 1371 if (IS_ERR(handle)) {
1379 status = PTR_ERR(handle); 1372 status = PTR_ERR(handle);
1380 mlog_errno(status); 1373 mlog_errno(status);
@@ -1387,7 +1380,7 @@ int ocfs2_complete_truncate_log_recovery(struct ocfs2_super *osb,
1387 1380
1388 status = ocfs2_truncate_log_append(osb, handle, 1381 status = ocfs2_truncate_log_append(osb, handle,
1389 start_blk, clusters); 1382 start_blk, clusters);
1390 ocfs2_commit_trans(handle); 1383 ocfs2_commit_trans(osb, handle);
1391 if (status < 0) { 1384 if (status < 0) {
1392 mlog_errno(status); 1385 mlog_errno(status);
1393 goto bail_up; 1386 goto bail_up;
@@ -1441,7 +1434,8 @@ int ocfs2_truncate_log_init(struct ocfs2_super *osb)
1441 /* ocfs2_truncate_log_shutdown keys on the existence of 1434 /* ocfs2_truncate_log_shutdown keys on the existence of
1442 * osb->osb_tl_inode so we don't set any of the osb variables 1435 * osb->osb_tl_inode so we don't set any of the osb variables
1443 * until we're sure all is well. */ 1436 * until we're sure all is well. */
1444 INIT_WORK(&osb->osb_truncate_log_wq, ocfs2_truncate_log_worker, osb); 1437 INIT_DELAYED_WORK(&osb->osb_truncate_log_wq,
1438 ocfs2_truncate_log_worker);
1445 osb->osb_tl_bh = tl_bh; 1439 osb->osb_tl_bh = tl_bh;
1446 osb->osb_tl_inode = tl_inode; 1440 osb->osb_tl_inode = tl_inode;
1447 1441
@@ -1543,7 +1537,7 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb,
1543 struct inode *inode, 1537 struct inode *inode,
1544 struct buffer_head *fe_bh, 1538 struct buffer_head *fe_bh,
1545 struct buffer_head *old_last_eb_bh, 1539 struct buffer_head *old_last_eb_bh,
1546 struct ocfs2_journal_handle *handle, 1540 handle_t *handle,
1547 struct ocfs2_truncate_context *tc) 1541 struct ocfs2_truncate_context *tc)
1548{ 1542{
1549 int status, i, depth; 1543 int status, i, depth;
@@ -1782,7 +1776,7 @@ int ocfs2_commit_truncate(struct ocfs2_super *osb,
1782 struct ocfs2_extent_block *eb; 1776 struct ocfs2_extent_block *eb;
1783 struct ocfs2_extent_list *el; 1777 struct ocfs2_extent_list *el;
1784 struct buffer_head *last_eb_bh; 1778 struct buffer_head *last_eb_bh;
1785 struct ocfs2_journal_handle *handle = NULL; 1779 handle_t *handle = NULL;
1786 struct inode *tl_inode = osb->osb_tl_inode; 1780 struct inode *tl_inode = osb->osb_tl_inode;
1787 1781
1788 mlog_entry_void(); 1782 mlog_entry_void();
@@ -1868,7 +1862,7 @@ start:
1868 1862
1869 credits = ocfs2_calc_tree_trunc_credits(osb->sb, clusters_to_del, 1863 credits = ocfs2_calc_tree_trunc_credits(osb->sb, clusters_to_del,
1870 fe, el); 1864 fe, el);
1871 handle = ocfs2_start_trans(osb, NULL, credits); 1865 handle = ocfs2_start_trans(osb, credits);
1872 if (IS_ERR(handle)) { 1866 if (IS_ERR(handle)) {
1873 status = PTR_ERR(handle); 1867 status = PTR_ERR(handle);
1874 handle = NULL; 1868 handle = NULL;
@@ -1891,7 +1885,7 @@ start:
1891 mutex_unlock(&tl_inode->i_mutex); 1885 mutex_unlock(&tl_inode->i_mutex);
1892 tl_sem = 0; 1886 tl_sem = 0;
1893 1887
1894 ocfs2_commit_trans(handle); 1888 ocfs2_commit_trans(osb, handle);
1895 handle = NULL; 1889 handle = NULL;
1896 1890
1897 BUG_ON(le32_to_cpu(fe->i_clusters) < target_i_clusters); 1891 BUG_ON(le32_to_cpu(fe->i_clusters) < target_i_clusters);
@@ -1906,7 +1900,7 @@ bail:
1906 mutex_unlock(&tl_inode->i_mutex); 1900 mutex_unlock(&tl_inode->i_mutex);
1907 1901
1908 if (handle) 1902 if (handle)
1909 ocfs2_commit_trans(handle); 1903 ocfs2_commit_trans(osb, handle);
1910 1904
1911 if (last_eb_bh) 1905 if (last_eb_bh)
1912 brelse(last_eb_bh); 1906 brelse(last_eb_bh);
@@ -2011,10 +2005,7 @@ int ocfs2_prepare_truncate(struct ocfs2_super *osb,
2011 mutex_lock(&ext_alloc_inode->i_mutex); 2005 mutex_lock(&ext_alloc_inode->i_mutex);
2012 (*tc)->tc_ext_alloc_inode = ext_alloc_inode; 2006 (*tc)->tc_ext_alloc_inode = ext_alloc_inode;
2013 2007
2014 status = ocfs2_meta_lock(ext_alloc_inode, 2008 status = ocfs2_meta_lock(ext_alloc_inode, &ext_alloc_bh, 1);
2015 NULL,
2016 &ext_alloc_bh,
2017 1);
2018 if (status < 0) { 2009 if (status < 0) {
2019 mlog_errno(status); 2010 mlog_errno(status);
2020 goto bail; 2011 goto bail;