50
50
#include "sysfile.h"
51
51
#include "uptodate.h"
52
52
#include "quota.h"
53
+ #include "file.h"
54
+ #include "namei.h"
53
55
54
56
#include "buffer_head_io.h"
55
57
#include "ocfs2_trace.h"
@@ -69,13 +71,15 @@ static int ocfs2_journal_toggle_dirty(struct ocfs2_super *osb,
69
71
static int ocfs2_trylock_journal (struct ocfs2_super * osb ,
70
72
int slot_num );
71
73
static int ocfs2_recover_orphans (struct ocfs2_super * osb ,
72
- int slot );
74
+ int slot ,
75
+ enum ocfs2_orphan_reco_type orphan_reco_type );
73
76
static int ocfs2_commit_thread (void * arg );
74
77
static void ocfs2_queue_recovery_completion (struct ocfs2_journal * journal ,
75
78
int slot_num ,
76
79
struct ocfs2_dinode * la_dinode ,
77
80
struct ocfs2_dinode * tl_dinode ,
78
- struct ocfs2_quota_recovery * qrec );
81
+ struct ocfs2_quota_recovery * qrec ,
82
+ enum ocfs2_orphan_reco_type orphan_reco_type );
79
83
80
84
static inline int ocfs2_wait_on_mount (struct ocfs2_super * osb )
81
85
{
@@ -149,7 +153,8 @@ int ocfs2_compute_replay_slots(struct ocfs2_super *osb)
149
153
return 0 ;
150
154
}
151
155
152
- void ocfs2_queue_replay_slots (struct ocfs2_super * osb )
156
+ void ocfs2_queue_replay_slots (struct ocfs2_super * osb ,
157
+ enum ocfs2_orphan_reco_type orphan_reco_type )
153
158
{
154
159
struct ocfs2_replay_map * replay_map = osb -> replay_map ;
155
160
int i ;
@@ -163,7 +168,8 @@ void ocfs2_queue_replay_slots(struct ocfs2_super *osb)
163
168
for (i = 0 ; i < replay_map -> rm_slots ; i ++ )
164
169
if (replay_map -> rm_replay_slots [i ])
165
170
ocfs2_queue_recovery_completion (osb -> journal , i , NULL ,
166
- NULL , NULL );
171
+ NULL , NULL ,
172
+ orphan_reco_type );
167
173
replay_map -> rm_state = REPLAY_DONE ;
168
174
}
169
175
@@ -1174,6 +1180,7 @@ struct ocfs2_la_recovery_item {
1174
1180
struct ocfs2_dinode * lri_la_dinode ;
1175
1181
struct ocfs2_dinode * lri_tl_dinode ;
1176
1182
struct ocfs2_quota_recovery * lri_qrec ;
1183
+ enum ocfs2_orphan_reco_type lri_orphan_reco_type ;
1177
1184
};
1178
1185
1179
1186
/* Does the second half of the recovery process. By this point, the
@@ -1195,6 +1202,7 @@ void ocfs2_complete_recovery(struct work_struct *work)
1195
1202
struct ocfs2_dinode * la_dinode , * tl_dinode ;
1196
1203
struct ocfs2_la_recovery_item * item , * n ;
1197
1204
struct ocfs2_quota_recovery * qrec ;
1205
+ enum ocfs2_orphan_reco_type orphan_reco_type ;
1198
1206
LIST_HEAD (tmp_la_list );
1199
1207
1200
1208
trace_ocfs2_complete_recovery (
@@ -1212,6 +1220,7 @@ void ocfs2_complete_recovery(struct work_struct *work)
1212
1220
la_dinode = item -> lri_la_dinode ;
1213
1221
tl_dinode = item -> lri_tl_dinode ;
1214
1222
qrec = item -> lri_qrec ;
1223
+ orphan_reco_type = item -> lri_orphan_reco_type ;
1215
1224
1216
1225
trace_ocfs2_complete_recovery_slot (item -> lri_slot ,
1217
1226
la_dinode ? le64_to_cpu (la_dinode -> i_blkno ) : 0 ,
@@ -1236,7 +1245,8 @@ void ocfs2_complete_recovery(struct work_struct *work)
1236
1245
kfree (tl_dinode );
1237
1246
}
1238
1247
1239
- ret = ocfs2_recover_orphans (osb , item -> lri_slot );
1248
+ ret = ocfs2_recover_orphans (osb , item -> lri_slot ,
1249
+ orphan_reco_type );
1240
1250
if (ret < 0 )
1241
1251
mlog_errno (ret );
1242
1252
@@ -1261,7 +1271,8 @@ static void ocfs2_queue_recovery_completion(struct ocfs2_journal *journal,
1261
1271
int slot_num ,
1262
1272
struct ocfs2_dinode * la_dinode ,
1263
1273
struct ocfs2_dinode * tl_dinode ,
1264
- struct ocfs2_quota_recovery * qrec )
1274
+ struct ocfs2_quota_recovery * qrec ,
1275
+ enum ocfs2_orphan_reco_type orphan_reco_type )
1265
1276
{
1266
1277
struct ocfs2_la_recovery_item * item ;
1267
1278
@@ -1285,6 +1296,7 @@ static void ocfs2_queue_recovery_completion(struct ocfs2_journal *journal,
1285
1296
item -> lri_slot = slot_num ;
1286
1297
item -> lri_tl_dinode = tl_dinode ;
1287
1298
item -> lri_qrec = qrec ;
1299
+ item -> lri_orphan_reco_type = orphan_reco_type ;
1288
1300
1289
1301
spin_lock (& journal -> j_lock );
1290
1302
list_add_tail (& item -> lri_list , & journal -> j_la_cleanups );
@@ -1304,15 +1316,16 @@ void ocfs2_complete_mount_recovery(struct ocfs2_super *osb)
1304
1316
/* No need to queue up our truncate_log as regular cleanup will catch
1305
1317
* that */
1306
1318
ocfs2_queue_recovery_completion (journal , osb -> slot_num ,
1307
- osb -> local_alloc_copy , NULL , NULL );
1319
+ osb -> local_alloc_copy , NULL , NULL ,
1320
+ ORPHAN_NEED_TRUNCATE );
1308
1321
ocfs2_schedule_truncate_log_flush (osb , 0 );
1309
1322
1310
1323
osb -> local_alloc_copy = NULL ;
1311
1324
osb -> dirty = 0 ;
1312
1325
1313
1326
/* queue to recover orphan slots for all offline slots */
1314
1327
ocfs2_replay_map_set_state (osb , REPLAY_NEEDED );
1315
- ocfs2_queue_replay_slots (osb );
1328
+ ocfs2_queue_replay_slots (osb , ORPHAN_NEED_TRUNCATE );
1316
1329
ocfs2_free_replay_slots (osb );
1317
1330
}
1318
1331
@@ -1323,7 +1336,8 @@ void ocfs2_complete_quota_recovery(struct ocfs2_super *osb)
1323
1336
osb -> slot_num ,
1324
1337
NULL ,
1325
1338
NULL ,
1326
- osb -> quota_rec );
1339
+ osb -> quota_rec ,
1340
+ ORPHAN_NEED_TRUNCATE );
1327
1341
osb -> quota_rec = NULL ;
1328
1342
}
1329
1343
}
@@ -1360,7 +1374,7 @@ static int __ocfs2_recovery_thread(void *arg)
1360
1374
1361
1375
/* queue recovery for our own slot */
1362
1376
ocfs2_queue_recovery_completion (osb -> journal , osb -> slot_num , NULL ,
1363
- NULL , NULL );
1377
+ NULL , NULL , ORPHAN_NO_NEED_TRUNCATE );
1364
1378
1365
1379
spin_lock (& osb -> osb_lock );
1366
1380
while (rm -> rm_used ) {
@@ -1419,13 +1433,14 @@ static int __ocfs2_recovery_thread(void *arg)
1419
1433
continue ;
1420
1434
}
1421
1435
ocfs2_queue_recovery_completion (osb -> journal , rm_quota [i ],
1422
- NULL , NULL , qrec );
1436
+ NULL , NULL , qrec ,
1437
+ ORPHAN_NEED_TRUNCATE );
1423
1438
}
1424
1439
1425
1440
ocfs2_super_unlock (osb , 1 );
1426
1441
1427
1442
/* queue recovery for offline slots */
1428
- ocfs2_queue_replay_slots (osb );
1443
+ ocfs2_queue_replay_slots (osb , ORPHAN_NEED_TRUNCATE );
1429
1444
1430
1445
bail :
1431
1446
mutex_lock (& osb -> recovery_lock );
@@ -1711,7 +1726,7 @@ static int ocfs2_recover_node(struct ocfs2_super *osb,
1711
1726
1712
1727
/* This will kfree the memory pointed to by la_copy and tl_copy */
1713
1728
ocfs2_queue_recovery_completion (osb -> journal , slot_num , la_copy ,
1714
- tl_copy , NULL );
1729
+ tl_copy , NULL , ORPHAN_NEED_TRUNCATE );
1715
1730
1716
1731
status = 0 ;
1717
1732
done :
@@ -1901,7 +1916,7 @@ void ocfs2_queue_orphan_scan(struct ocfs2_super *osb)
1901
1916
1902
1917
for (i = 0 ; i < osb -> max_slots ; i ++ )
1903
1918
ocfs2_queue_recovery_completion (osb -> journal , i , NULL , NULL ,
1904
- NULL );
1919
+ NULL , ORPHAN_NO_NEED_TRUNCATE );
1905
1920
/*
1906
1921
* We queued a recovery on orphan slots, increment the sequence
1907
1922
* number and update LVB so other node will skip the scan for a while
@@ -2000,6 +2015,13 @@ static int ocfs2_orphan_filldir(struct dir_context *ctx, const char *name,
2000
2015
if (IS_ERR (iter ))
2001
2016
return 0 ;
2002
2017
2018
+ /* Skip inodes which are already added to recover list, since dio may
2019
+ * happen concurrently with unlink/rename */
2020
+ if (OCFS2_I (iter )-> ip_next_orphan ) {
2021
+ iput (iter );
2022
+ return 0 ;
2023
+ }
2024
+
2003
2025
trace_ocfs2_orphan_filldir ((unsigned long long )OCFS2_I (iter )-> ip_blkno );
2004
2026
/* No locking is required for the next_orphan queue as there
2005
2027
* is only ever a single process doing orphan recovery. */
@@ -2108,7 +2130,8 @@ static void ocfs2_clear_recovering_orphan_dir(struct ocfs2_super *osb,
2108
2130
* advertising our state to ocfs2_delete_inode().
2109
2131
*/
2110
2132
static int ocfs2_recover_orphans (struct ocfs2_super * osb ,
2111
- int slot )
2133
+ int slot ,
2134
+ enum ocfs2_orphan_reco_type orphan_reco_type )
2112
2135
{
2113
2136
int ret = 0 ;
2114
2137
struct inode * inode = NULL ;
@@ -2132,13 +2155,58 @@ static int ocfs2_recover_orphans(struct ocfs2_super *osb,
2132
2155
(unsigned long long )oi -> ip_blkno );
2133
2156
2134
2157
iter = oi -> ip_next_orphan ;
2158
+ oi -> ip_next_orphan = NULL ;
2159
+
2160
+ /*
2161
+ * We need to take and drop the inode lock to
2162
+ * force read inode from disk.
2163
+ */
2164
+ ret = ocfs2_inode_lock (inode , NULL , 0 );
2165
+ if (ret ) {
2166
+ mlog_errno (ret );
2167
+ goto next ;
2168
+ }
2169
+ ocfs2_inode_unlock (inode , 0 );
2170
+
2171
+ if (inode -> i_nlink == 0 ) {
2172
+ spin_lock (& oi -> ip_lock );
2173
+ /* Set the proper information to get us going into
2174
+ * ocfs2_delete_inode. */
2175
+ oi -> ip_flags |= OCFS2_INODE_MAYBE_ORPHANED ;
2176
+ spin_unlock (& oi -> ip_lock );
2177
+ } else if (orphan_reco_type == ORPHAN_NEED_TRUNCATE ) {
2178
+ struct buffer_head * di_bh = NULL ;
2179
+
2180
+ ret = ocfs2_rw_lock (inode , 1 );
2181
+ if (ret ) {
2182
+ mlog_errno (ret );
2183
+ goto next ;
2184
+ }
2135
2185
2136
- spin_lock (& oi -> ip_lock );
2137
- /* Set the proper information to get us going into
2138
- * ocfs2_delete_inode. */
2139
- oi -> ip_flags |= OCFS2_INODE_MAYBE_ORPHANED ;
2140
- spin_unlock (& oi -> ip_lock );
2186
+ ret = ocfs2_inode_lock (inode , & di_bh , 1 );
2187
+ if (ret < 0 ) {
2188
+ ocfs2_rw_unlock (inode , 1 );
2189
+ mlog_errno (ret );
2190
+ goto next ;
2191
+ }
2192
+
2193
+ ret = ocfs2_truncate_file (inode , di_bh ,
2194
+ i_size_read (inode ));
2195
+ ocfs2_inode_unlock (inode , 1 );
2196
+ ocfs2_rw_unlock (inode , 1 );
2197
+ brelse (di_bh );
2198
+ if (ret < 0 ) {
2199
+ if (ret != - ENOSPC )
2200
+ mlog_errno (ret );
2201
+ goto next ;
2202
+ }
2203
+
2204
+ ret = ocfs2_del_inode_from_orphan (osb , inode , 0 , 0 );
2205
+ if (ret )
2206
+ mlog_errno (ret );
2207
+ } /* else if ORPHAN_NO_NEED_TRUNCATE, do nothing */
2141
2208
2209
+ next :
2142
2210
iput (inode );
2143
2211
2144
2212
inode = iter ;
0 commit comments