27 #include <linux/types.h>
32 #include <asm/byteorder.h>
69 static int ocfs2_read_locked_inode(
struct inode *
inode,
71 static int ocfs2_init_locked_inode(
struct inode *
inode,
void *opaque);
72 static int ocfs2_find_actor(
struct inode *
inode,
void *opaque);
73 static int ocfs2_truncate_for_delete(
struct ocfs2_super *osb,
75 struct buffer_head *fe_bh);
79 unsigned int flags = OCFS2_I(inode)->ip_attr;
122 args.
fi_ino = ino_from_blkno(sb, blkno);
125 return ilookup5(sb, blkno, ocfs2_find_actor, &args);
134 trace_ocfs2_iget_begin((
unsigned long long)blkno, flags,
148 args.
fi_ino = ino_from_blkno(sb, blkno);
152 ocfs2_init_locked_inode, &args);
161 trace_ocfs2_iget5_locked(inode->
i_state);
163 ocfs2_read_locked_inode(inode, &args);
173 if (!IS_ERR(inode)) {
174 trace_ocfs2_iget_end(inode,
175 (
unsigned long long)OCFS2_I(inode)->ip_blkno);
189 static int ocfs2_find_actor(
struct inode *
inode,
void *opaque)
199 trace_ocfs2_find_actor(inode, inode->
i_ino, opaque, args->
fi_blkno);
214 static int ocfs2_init_locked_inode(
struct inode *inode,
void *opaque)
218 ocfs2_file_ip_alloc_sem_key;
221 OCFS2_I(inode)->ip_blkno = args->
fi_blkno;
230 &ocfs2_quota_ip_alloc_sem_key);
233 &ocfs2_file_ip_alloc_sem_key);
280 inode->
i_blocks = ocfs2_inode_sector_count(inode);
292 "ip_blkno %llu != i_blkno %llu!\n",
293 (
unsigned long long)OCFS2_I(inode)->ip_blkno,
296 set_nlink(inode, ocfs2_read_links_count(fe));
298 trace_ocfs2_populate_inode(OCFS2_I(inode)->ip_blkno,
333 OCFS2_I(inode)->ip_dir_lock_gen = 1;
347 inode->
i_ino = ino_from_blkno(inode->
i_sb,
370 OCFS2_I(inode)->ip_last_used_slot = 0;
371 OCFS2_I(inode)->ip_last_used_group = 0;
378 static int ocfs2_read_locked_inode(
struct inode *inode,
384 struct buffer_head *bh =
NULL;
433 && !ocfs2_mount_local(osb);
435 trace_ocfs2_read_locked_inode(
436 (
unsigned long long)OCFS2_I(inode)->ip_blkno, can_lock);
488 if (!status && !buffer_jbd(bh))
506 "Inode %llu: system file state is ambigous\n",
507 (
unsigned long long)args->
fi_blkno);
537 static int ocfs2_truncate_for_delete(
struct ocfs2_super *osb,
539 struct buffer_head *fe_bh)
552 if (ocfs2_should_order_data(inode))
553 ocfs2_begin_ordered_truncate(inode, 0);
556 if (IS_ERR(handle)) {
557 status = PTR_ERR(handle);
571 i_size_write(inode, 0);
595 static int ocfs2_remove_inode(
struct inode *inode,
596 struct buffer_head *di_bh,
597 struct inode *orphan_dir_inode,
598 struct buffer_head *orphan_dir_bh)
601 struct inode *inode_alloc_inode =
NULL;
602 struct buffer_head *inode_alloc_bh =
NULL;
610 if (!inode_alloc_inode) {
626 ocfs2_quota_trans_credits(inode->
i_sb));
627 if (IS_ERR(handle)) {
628 status = PTR_ERR(handle);
667 brelse(inode_alloc_bh);
669 iput(inode_alloc_inode);
680 static int ocfs2_check_orphan_recovery_state(
struct ocfs2_super *osb,
695 trace_ocfs2_check_orphan_recovery_state(slot, ret);
699 static void ocfs2_signal_wipe_completion(
struct ocfs2_super *osb,
709 static int ocfs2_wipe_inode(
struct inode *inode,
710 struct buffer_head *di_bh)
712 int status, orphaned_slot = -1;
713 struct inode *orphan_dir_inode =
NULL;
714 struct buffer_head *orphan_dir_bh =
NULL;
718 if (!(OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)) {
721 status = ocfs2_check_orphan_recovery_state(osb, orphaned_slot);
728 if (!orphan_dir_inode) {
751 status = ocfs2_truncate_for_delete(osb, inode, di_bh);
754 goto bail_unlock_dir;
762 goto bail_unlock_dir;
770 goto bail_unlock_dir;
776 goto bail_unlock_dir;
779 status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode,
785 if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)
790 brelse(orphan_dir_bh);
792 iput(orphan_dir_inode);
793 ocfs2_signal_wipe_completion(osb, orphaned_slot);
800 static int ocfs2_inode_is_valid_to_delete(
struct inode *inode)
852 static int ocfs2_query_inode_wipe(
struct inode *inode,
853 struct buffer_head *di_bh,
856 int status = 0,
reason = 0;
862 trace_ocfs2_query_inode_wipe_begin((
unsigned long long)oi->
ip_blkno,
868 if (!ocfs2_inode_is_valid_to_delete(inode)) {
898 "Inode %llu (on-disk %llu) not orphaned! "
899 "Disk flags 0x%x, inode flags 0x%x\n",
940 trace_ocfs2_query_inode_wipe_end(status,
reason);
947 static void ocfs2_cleanup_delete_inode(
struct inode *inode,
950 trace_ocfs2_cleanup_delete_inode(
951 (
unsigned long long)OCFS2_I(inode)->ip_blkno, sync_data);
957 static void ocfs2_delete_inode(
struct inode *inode)
961 struct buffer_head *di_bh =
NULL;
963 trace_ocfs2_delete_inode(inode->
i_ino,
964 (
unsigned long long)OCFS2_I(inode)->ip_blkno,
975 if (!ocfs2_inode_is_valid_to_delete(inode)) {
979 ocfs2_cleanup_delete_inode(inode, 0);
996 mlog(
ML_ERROR,
"getting nfs sync lock(PR) failed %d\n", status);
997 ocfs2_cleanup_delete_inode(inode, 0);
1012 ocfs2_cleanup_delete_inode(inode, 0);
1013 goto bail_unlock_nfs_sync;
1018 status = ocfs2_query_inode_wipe(inode, di_bh, &wipe);
1019 if (!wipe || status < 0) {
1029 ocfs2_cleanup_delete_inode(inode, 1);
1030 goto bail_unlock_inode;
1033 ocfs2_cleanup_delete_inode(inode, 0);
1035 status = ocfs2_wipe_inode(inode, di_bh);
1039 goto bail_unlock_inode;
1057 bail_unlock_nfs_sync:
1066 static void ocfs2_clear_inode(
struct inode *inode)
1072 trace_ocfs2_clear_inode((
unsigned long long)oi->
ip_blkno,
1076 "Inode=%lu\n", inode->
i_ino);
1101 ocfs2_checkpoint_inode(inode);
1104 "Clear inode of %llu, inode has io markers\n",
1120 "Clear inode of %llu, inode has %u cache items\n",
1122 INODE_CACHE(inode)->ci_num_cached);
1125 "Clear inode of %llu, inode has a bad flag\n",
1129 "Clear inode of %llu, inode is locked\n",
1133 "Clear inode of %llu, io_mutex is locked\n",
1142 "Clear inode of %llu, alloc_sem is locked\n",
1147 "Clear inode of %llu has open count %d\n",
1168 ocfs2_delete_inode(inode);
1172 ocfs2_clear_inode(inode);
1183 trace_ocfs2_drop_inode((
unsigned long long)oi->
ip_blkno,
1189 res = generic_drop_inode(inode);
1199 struct inode *inode = dentry->
d_inode;
1202 trace_ocfs2_inode_revalidate(inode,
1203 inode ? (
unsigned long long)OCFS2_I(inode)->ip_blkno : 0ULL,
1204 inode ? (
unsigned long long)OCFS2_I(inode)->ip_flags : 0);
1211 spin_lock(&OCFS2_I(inode)->ip_lock);
1212 if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_DELETED) {
1213 spin_unlock(&OCFS2_I(inode)->ip_lock);
1217 spin_unlock(&OCFS2_I(inode)->ip_lock);
1238 struct inode *inode,
1239 struct buffer_head *bh)
1244 trace_ocfs2_mark_inode_dirty((
unsigned long long)OCFS2_I(inode)->ip_blkno);
1253 spin_lock(&OCFS2_I(inode)->ip_lock);
1258 spin_unlock(&OCFS2_I(inode)->ip_lock);
1261 ocfs2_set_links_count(fe, inode->
i_nlink);
1285 spin_lock(&OCFS2_I(inode)->ip_lock);
1292 set_nlink(inode, ocfs2_read_links_count(fe));
1299 inode->
i_blocks = ocfs2_inode_sector_count(inode);
1307 spin_unlock(&OCFS2_I(inode)->ip_lock);
1311 struct buffer_head *bh)
1316 trace_ocfs2_validate_inode_block((
unsigned long long)bh->b_blocknr);
1318 BUG_ON(!buffer_uptodate(bh));
1328 (
unsigned long long)bh->b_blocknr);
1339 ocfs2_error(sb,
"Invalid dinode #%llu: signature = %.*s\n",
1340 (
unsigned long long)bh->b_blocknr, 7,
1346 ocfs2_error(sb,
"Invalid dinode #%llu: i_blkno is %llu\n",
1347 (
unsigned long long)bh->b_blocknr,
1354 "Invalid dinode #%llu: OCFS2_VALID_FL not set\n",
1355 (
unsigned long long)bh->b_blocknr);
1362 "Invalid dinode #%llu: fs_generation is %u\n",
1363 (
unsigned long long)bh->b_blocknr,
1378 struct buffer_head *
tmp = *bh;
1439 .co_owner = ocfs2_inode_cache_owner,
1440 .co_get_super = ocfs2_inode_cache_get_super,
1441 .co_cache_lock = ocfs2_inode_cache_lock,
1442 .co_cache_unlock = ocfs2_inode_cache_unlock,
1443 .co_io_lock = ocfs2_inode_cache_io_lock,
1444 .co_io_unlock = ocfs2_inode_cache_io_unlock,