1ccd979bdSMark Fasheh /* -*- mode: c; c-basic-offset: 8; -*- 2ccd979bdSMark Fasheh * vim: noexpandtab sw=8 ts=8 sts=0: 3ccd979bdSMark Fasheh * 4ccd979bdSMark Fasheh * inode.c 5ccd979bdSMark Fasheh * 6ccd979bdSMark Fasheh * vfs' aops, fops, dops and iops 7ccd979bdSMark Fasheh * 8ccd979bdSMark Fasheh * Copyright (C) 2002, 2004 Oracle. All rights reserved. 9ccd979bdSMark Fasheh * 10ccd979bdSMark Fasheh * This program is free software; you can redistribute it and/or 11ccd979bdSMark Fasheh * modify it under the terms of the GNU General Public 12ccd979bdSMark Fasheh * License as published by the Free Software Foundation; either 13ccd979bdSMark Fasheh * version 2 of the License, or (at your option) any later version. 14ccd979bdSMark Fasheh * 15ccd979bdSMark Fasheh * This program is distributed in the hope that it will be useful, 16ccd979bdSMark Fasheh * but WITHOUT ANY WARRANTY; without even the implied warranty of 17ccd979bdSMark Fasheh * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18ccd979bdSMark Fasheh * General Public License for more details. 19ccd979bdSMark Fasheh * 20ccd979bdSMark Fasheh * You should have received a copy of the GNU General Public 21ccd979bdSMark Fasheh * License along with this program; if not, write to the 22ccd979bdSMark Fasheh * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23ccd979bdSMark Fasheh * Boston, MA 021110-1307, USA. 24ccd979bdSMark Fasheh */ 25ccd979bdSMark Fasheh 26ccd979bdSMark Fasheh #include <linux/fs.h> 27ccd979bdSMark Fasheh #include <linux/types.h> 28ccd979bdSMark Fasheh #include <linux/slab.h> 29ccd979bdSMark Fasheh #include <linux/highmem.h> 30ccd979bdSMark Fasheh #include <linux/pagemap.h> 31a90714c1SJan Kara #include <linux/quotaops.h> 32ccd979bdSMark Fasheh 33ccd979bdSMark Fasheh #include <asm/byteorder.h> 34ccd979bdSMark Fasheh 35ccd979bdSMark Fasheh #define MLOG_MASK_PREFIX ML_INODE 36ccd979bdSMark Fasheh #include <cluster/masklog.h> 37ccd979bdSMark Fasheh 38ccd979bdSMark Fasheh #include "ocfs2.h" 39ccd979bdSMark Fasheh 40ccd979bdSMark Fasheh #include "alloc.h" 419b7895efSMark Fasheh #include "dir.h" 42d6b32bbbSJoel Becker #include "blockcheck.h" 43ccd979bdSMark Fasheh #include "dlmglue.h" 44ccd979bdSMark Fasheh #include "extent_map.h" 45ccd979bdSMark Fasheh #include "file.h" 46b4df6ed8SMark Fasheh #include "heartbeat.h" 47ccd979bdSMark Fasheh #include "inode.h" 48ccd979bdSMark Fasheh #include "journal.h" 49ccd979bdSMark Fasheh #include "namei.h" 50ccd979bdSMark Fasheh #include "suballoc.h" 51ccd979bdSMark Fasheh #include "super.h" 52ccd979bdSMark Fasheh #include "symlink.h" 53ccd979bdSMark Fasheh #include "sysfile.h" 54ccd979bdSMark Fasheh #include "uptodate.h" 55cf1d6c76STiger Yang #include "xattr.h" 568b2c0dbaSTao Ma #include "refcounttree.h" 57ccd979bdSMark Fasheh 58ccd979bdSMark Fasheh #include "buffer_head_io.h" 59ccd979bdSMark Fasheh 60ccd979bdSMark Fasheh struct ocfs2_find_inode_args 61ccd979bdSMark Fasheh { 62ccd979bdSMark Fasheh u64 fi_blkno; 63ccd979bdSMark Fasheh unsigned long fi_ino; 64ccd979bdSMark Fasheh unsigned int fi_flags; 655fa0613eSJan Kara unsigned int fi_sysfile_type; 66ccd979bdSMark Fasheh }; 67ccd979bdSMark Fasheh 685fa0613eSJan Kara static struct lock_class_key ocfs2_sysfile_lock_key[NUM_SYSTEM_INODES]; 695fa0613eSJan Kara 70ccd979bdSMark Fasheh static int ocfs2_read_locked_inode(struct inode *inode, 71ccd979bdSMark Fasheh struct ocfs2_find_inode_args *args); 72ccd979bdSMark Fasheh static int ocfs2_init_locked_inode(struct inode *inode, void *opaque); 73ccd979bdSMark Fasheh static int ocfs2_find_actor(struct inode *inode, void *opaque); 74ccd979bdSMark Fasheh static int ocfs2_truncate_for_delete(struct ocfs2_super *osb, 75ccd979bdSMark Fasheh struct inode *inode, 76ccd979bdSMark Fasheh struct buffer_head *fe_bh); 77ccd979bdSMark Fasheh 78ca4d147eSHerbert Poetzl void ocfs2_set_inode_flags(struct inode *inode) 79ca4d147eSHerbert Poetzl { 80ca4d147eSHerbert Poetzl unsigned int flags = OCFS2_I(inode)->ip_attr; 81ca4d147eSHerbert Poetzl 82ca4d147eSHerbert Poetzl inode->i_flags &= ~(S_IMMUTABLE | 83ca4d147eSHerbert Poetzl S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC); 84ca4d147eSHerbert Poetzl 85ca4d147eSHerbert Poetzl if (flags & OCFS2_IMMUTABLE_FL) 86ca4d147eSHerbert Poetzl inode->i_flags |= S_IMMUTABLE; 87ca4d147eSHerbert Poetzl 88ca4d147eSHerbert Poetzl if (flags & OCFS2_SYNC_FL) 89ca4d147eSHerbert Poetzl inode->i_flags |= S_SYNC; 90ca4d147eSHerbert Poetzl if (flags & OCFS2_APPEND_FL) 91ca4d147eSHerbert Poetzl inode->i_flags |= S_APPEND; 92ca4d147eSHerbert Poetzl if (flags & OCFS2_NOATIME_FL) 93ca4d147eSHerbert Poetzl inode->i_flags |= S_NOATIME; 94ca4d147eSHerbert Poetzl if (flags & OCFS2_DIRSYNC_FL) 95ca4d147eSHerbert Poetzl inode->i_flags |= S_DIRSYNC; 96ca4d147eSHerbert Poetzl } 97ca4d147eSHerbert Poetzl 986e4b0d56SJan Kara /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */ 996e4b0d56SJan Kara void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi) 1006e4b0d56SJan Kara { 1016e4b0d56SJan Kara unsigned int flags = oi->vfs_inode.i_flags; 1026e4b0d56SJan Kara 1036e4b0d56SJan Kara oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL| 1046e4b0d56SJan Kara OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL); 1056e4b0d56SJan Kara if (flags & S_SYNC) 1066e4b0d56SJan Kara oi->ip_attr |= OCFS2_SYNC_FL; 1076e4b0d56SJan Kara if (flags & S_APPEND) 1086e4b0d56SJan Kara oi->ip_attr |= OCFS2_APPEND_FL; 1096e4b0d56SJan Kara if (flags & S_IMMUTABLE) 1106e4b0d56SJan Kara oi->ip_attr |= OCFS2_IMMUTABLE_FL; 1116e4b0d56SJan Kara if (flags & S_NOATIME) 1126e4b0d56SJan Kara oi->ip_attr |= OCFS2_NOATIME_FL; 1136e4b0d56SJan Kara if (flags & S_DIRSYNC) 1146e4b0d56SJan Kara oi->ip_attr |= OCFS2_DIRSYNC_FL; 1156e4b0d56SJan Kara } 1166e4b0d56SJan Kara 1176ca497a8Swengang wang struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno) 1186ca497a8Swengang wang { 1196ca497a8Swengang wang struct ocfs2_find_inode_args args; 1206ca497a8Swengang wang 1216ca497a8Swengang wang args.fi_blkno = blkno; 1226ca497a8Swengang wang args.fi_flags = 0; 1236ca497a8Swengang wang args.fi_ino = ino_from_blkno(sb, blkno); 1246ca497a8Swengang wang args.fi_sysfile_type = 0; 1256ca497a8Swengang wang 1266ca497a8Swengang wang return ilookup5(sb, blkno, ocfs2_find_actor, &args); 1276ca497a8Swengang wang } 1285fa0613eSJan Kara struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags, 1295fa0613eSJan Kara int sysfile_type) 130ccd979bdSMark Fasheh { 131ccd979bdSMark Fasheh struct inode *inode = NULL; 132ccd979bdSMark Fasheh struct super_block *sb = osb->sb; 133ccd979bdSMark Fasheh struct ocfs2_find_inode_args args; 134ccd979bdSMark Fasheh 135b0697053SMark Fasheh mlog_entry("(blkno = %llu)\n", (unsigned long long)blkno); 136ccd979bdSMark Fasheh 137ccd979bdSMark Fasheh /* Ok. By now we've either got the offsets passed to us by the 138ccd979bdSMark Fasheh * caller, or we just pulled them off the bh. Lets do some 139ccd979bdSMark Fasheh * sanity checks to make sure they're OK. */ 140ccd979bdSMark Fasheh if (blkno == 0) { 141ccd979bdSMark Fasheh inode = ERR_PTR(-EINVAL); 142ccd979bdSMark Fasheh mlog_errno(PTR_ERR(inode)); 143ccd979bdSMark Fasheh goto bail; 144ccd979bdSMark Fasheh } 145ccd979bdSMark Fasheh 146ccd979bdSMark Fasheh args.fi_blkno = blkno; 14724c19ef4SMark Fasheh args.fi_flags = flags; 148ccd979bdSMark Fasheh args.fi_ino = ino_from_blkno(sb, blkno); 1495fa0613eSJan Kara args.fi_sysfile_type = sysfile_type; 150ccd979bdSMark Fasheh 151ccd979bdSMark Fasheh inode = iget5_locked(sb, args.fi_ino, ocfs2_find_actor, 152ccd979bdSMark Fasheh ocfs2_init_locked_inode, &args); 153ccd979bdSMark Fasheh /* inode was *not* in the inode cache. 2.6.x requires 154ccd979bdSMark Fasheh * us to do our own read_inode call and unlock it 155ccd979bdSMark Fasheh * afterwards. */ 156ccd979bdSMark Fasheh if (inode && inode->i_state & I_NEW) { 157ccd979bdSMark Fasheh mlog(0, "Inode was not in inode cache, reading it.\n"); 158ccd979bdSMark Fasheh ocfs2_read_locked_inode(inode, &args); 159ccd979bdSMark Fasheh unlock_new_inode(inode); 160ccd979bdSMark Fasheh } 161ccd979bdSMark Fasheh if (inode == NULL) { 162ccd979bdSMark Fasheh inode = ERR_PTR(-ENOMEM); 163ccd979bdSMark Fasheh mlog_errno(PTR_ERR(inode)); 164ccd979bdSMark Fasheh goto bail; 165ccd979bdSMark Fasheh } 166ccd979bdSMark Fasheh if (is_bad_inode(inode)) { 167ccd979bdSMark Fasheh iput(inode); 168ccd979bdSMark Fasheh inode = ERR_PTR(-ESTALE); 169ccd979bdSMark Fasheh goto bail; 170ccd979bdSMark Fasheh } 171ccd979bdSMark Fasheh 172ccd979bdSMark Fasheh bail: 173ccd979bdSMark Fasheh if (!IS_ERR(inode)) { 174b0697053SMark Fasheh mlog(0, "returning inode with number %llu\n", 175b0697053SMark Fasheh (unsigned long long)OCFS2_I(inode)->ip_blkno); 176ccd979bdSMark Fasheh mlog_exit_ptr(inode); 1776a1bd4a5SMark Fasheh } 178ccd979bdSMark Fasheh 179ccd979bdSMark Fasheh return inode; 180ccd979bdSMark Fasheh } 181ccd979bdSMark Fasheh 182ccd979bdSMark Fasheh 183ccd979bdSMark Fasheh /* 184ccd979bdSMark Fasheh * here's how inodes get read from disk: 185ccd979bdSMark Fasheh * iget5_locked -> find_actor -> OCFS2_FIND_ACTOR 186ccd979bdSMark Fasheh * found? : return the in-memory inode 187ccd979bdSMark Fasheh * not found? : get_new_inode -> OCFS2_INIT_LOCKED_INODE 188ccd979bdSMark Fasheh */ 189ccd979bdSMark Fasheh 190ccd979bdSMark Fasheh static int ocfs2_find_actor(struct inode *inode, void *opaque) 191ccd979bdSMark Fasheh { 192ccd979bdSMark Fasheh struct ocfs2_find_inode_args *args = NULL; 193ccd979bdSMark Fasheh struct ocfs2_inode_info *oi = OCFS2_I(inode); 194ccd979bdSMark Fasheh int ret = 0; 195ccd979bdSMark Fasheh 196ccd979bdSMark Fasheh mlog_entry("(0x%p, %lu, 0x%p)\n", inode, inode->i_ino, opaque); 197ccd979bdSMark Fasheh 198ccd979bdSMark Fasheh args = opaque; 199ccd979bdSMark Fasheh 200ccd979bdSMark Fasheh mlog_bug_on_msg(!inode, "No inode in find actor!\n"); 201ccd979bdSMark Fasheh 202ccd979bdSMark Fasheh if (oi->ip_blkno != args->fi_blkno) 203ccd979bdSMark Fasheh goto bail; 204ccd979bdSMark Fasheh 205ccd979bdSMark Fasheh ret = 1; 206ccd979bdSMark Fasheh bail: 207ccd979bdSMark Fasheh mlog_exit(ret); 208ccd979bdSMark Fasheh return ret; 209ccd979bdSMark Fasheh } 210ccd979bdSMark Fasheh 211ccd979bdSMark Fasheh /* 212ccd979bdSMark Fasheh * initialize the new inode, but don't do anything that would cause 213ccd979bdSMark Fasheh * us to sleep. 214ccd979bdSMark Fasheh * return 0 on success, 1 on failure 215ccd979bdSMark Fasheh */ 216ccd979bdSMark Fasheh static int ocfs2_init_locked_inode(struct inode *inode, void *opaque) 217ccd979bdSMark Fasheh { 218ccd979bdSMark Fasheh struct ocfs2_find_inode_args *args = opaque; 219cb25797dSJan Kara static struct lock_class_key ocfs2_quota_ip_alloc_sem_key, 220cb25797dSJan Kara ocfs2_file_ip_alloc_sem_key; 221ccd979bdSMark Fasheh 222ccd979bdSMark Fasheh mlog_entry("inode = %p, opaque = %p\n", inode, opaque); 223ccd979bdSMark Fasheh 224ccd979bdSMark Fasheh inode->i_ino = args->fi_ino; 225ccd979bdSMark Fasheh OCFS2_I(inode)->ip_blkno = args->fi_blkno; 2265fa0613eSJan Kara if (args->fi_sysfile_type != 0) 2275fa0613eSJan Kara lockdep_set_class(&inode->i_mutex, 2285fa0613eSJan Kara &ocfs2_sysfile_lock_key[args->fi_sysfile_type]); 229cb25797dSJan Kara if (args->fi_sysfile_type == USER_QUOTA_SYSTEM_INODE || 230cb25797dSJan Kara args->fi_sysfile_type == GROUP_QUOTA_SYSTEM_INODE || 231cb25797dSJan Kara args->fi_sysfile_type == LOCAL_USER_QUOTA_SYSTEM_INODE || 232cb25797dSJan Kara args->fi_sysfile_type == LOCAL_GROUP_QUOTA_SYSTEM_INODE) 233cb25797dSJan Kara lockdep_set_class(&OCFS2_I(inode)->ip_alloc_sem, 234cb25797dSJan Kara &ocfs2_quota_ip_alloc_sem_key); 235cb25797dSJan Kara else 236cb25797dSJan Kara lockdep_set_class(&OCFS2_I(inode)->ip_alloc_sem, 237cb25797dSJan Kara &ocfs2_file_ip_alloc_sem_key); 238ccd979bdSMark Fasheh 239ccd979bdSMark Fasheh mlog_exit(0); 240ccd979bdSMark Fasheh return 0; 241ccd979bdSMark Fasheh } 242ccd979bdSMark Fasheh 243b657c95cSJoel Becker void ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe, 244ccd979bdSMark Fasheh int create_ino) 245ccd979bdSMark Fasheh { 246ccd979bdSMark Fasheh struct super_block *sb; 247ccd979bdSMark Fasheh struct ocfs2_super *osb; 24853da4939SMark Fasheh int use_plocks = 1; 249ccd979bdSMark Fasheh 250b0697053SMark Fasheh mlog_entry("(0x%p, size:%llu)\n", inode, 2511ca1a111SMark Fasheh (unsigned long long)le64_to_cpu(fe->i_size)); 252ccd979bdSMark Fasheh 253ccd979bdSMark Fasheh sb = inode->i_sb; 254ccd979bdSMark Fasheh osb = OCFS2_SB(sb); 255ccd979bdSMark Fasheh 25653da4939SMark Fasheh if ((osb->s_mount_opt & OCFS2_MOUNT_LOCALFLOCKS) || 25753da4939SMark Fasheh ocfs2_mount_local(osb) || !ocfs2_stack_supports_plocks()) 25853da4939SMark Fasheh use_plocks = 0; 25953da4939SMark Fasheh 260b657c95cSJoel Becker /* 261b657c95cSJoel Becker * These have all been checked by ocfs2_read_inode_block() or set 262b657c95cSJoel Becker * by ocfs2_mknod_locked(), so a failure is a code bug. 263b657c95cSJoel Becker */ 264b657c95cSJoel Becker BUG_ON(!OCFS2_IS_VALID_DINODE(fe)); /* This means that read_inode 265b657c95cSJoel Becker cannot create a superblock 266b657c95cSJoel Becker inode today. change if 267b657c95cSJoel Becker that is needed. */ 268b657c95cSJoel Becker BUG_ON(!(fe->i_flags & cpu_to_le32(OCFS2_VALID_FL))); 269b657c95cSJoel Becker BUG_ON(le32_to_cpu(fe->i_fs_generation) != osb->fs_generation); 270ccd979bdSMark Fasheh 271ccd979bdSMark Fasheh 2728110b073SMark Fasheh OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters); 2738110b073SMark Fasheh OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr); 27415b1e36bSMark Fasheh OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features); 2758110b073SMark Fasheh 276ccd979bdSMark Fasheh inode->i_version = 1; 277ccd979bdSMark Fasheh inode->i_generation = le32_to_cpu(fe->i_generation); 278ccd979bdSMark Fasheh inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev)); 279ccd979bdSMark Fasheh inode->i_mode = le16_to_cpu(fe->i_mode); 280ccd979bdSMark Fasheh inode->i_uid = le32_to_cpu(fe->i_uid); 281ccd979bdSMark Fasheh inode->i_gid = le32_to_cpu(fe->i_gid); 282ccd979bdSMark Fasheh 283ccd979bdSMark Fasheh /* Fast symlinks will have i_size but no allocated clusters. */ 284ccd979bdSMark Fasheh if (S_ISLNK(inode->i_mode) && !fe->i_clusters) 285ccd979bdSMark Fasheh inode->i_blocks = 0; 286ccd979bdSMark Fasheh else 2878110b073SMark Fasheh inode->i_blocks = ocfs2_inode_sector_count(inode); 288ccd979bdSMark Fasheh inode->i_mapping->a_ops = &ocfs2_aops; 289ccd979bdSMark Fasheh inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime); 290ccd979bdSMark Fasheh inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec); 291ccd979bdSMark Fasheh inode->i_mtime.tv_sec = le64_to_cpu(fe->i_mtime); 292ccd979bdSMark Fasheh inode->i_mtime.tv_nsec = le32_to_cpu(fe->i_mtime_nsec); 293ccd979bdSMark Fasheh inode->i_ctime.tv_sec = le64_to_cpu(fe->i_ctime); 294ccd979bdSMark Fasheh inode->i_ctime.tv_nsec = le32_to_cpu(fe->i_ctime_nsec); 295ccd979bdSMark Fasheh 296ccd979bdSMark Fasheh if (OCFS2_I(inode)->ip_blkno != le64_to_cpu(fe->i_blkno)) 297ccd979bdSMark Fasheh mlog(ML_ERROR, 298b0697053SMark Fasheh "ip_blkno %llu != i_blkno %llu!\n", 299b0697053SMark Fasheh (unsigned long long)OCFS2_I(inode)->ip_blkno, 3001ca1a111SMark Fasheh (unsigned long long)le64_to_cpu(fe->i_blkno)); 301ccd979bdSMark Fasheh 302198a1ca3SMark Fasheh inode->i_nlink = ocfs2_read_links_count(fe); 303ccd979bdSMark Fasheh 304bbbd0eb3SJan Kara if (fe->i_flags & cpu_to_le32(OCFS2_SYSTEM_FL)) { 30524c19ef4SMark Fasheh OCFS2_I(inode)->ip_flags |= OCFS2_INODE_SYSTEM_FILE; 306bbbd0eb3SJan Kara inode->i_flags |= S_NOQUOTA; 307bbbd0eb3SJan Kara } 30824c19ef4SMark Fasheh 309ccd979bdSMark Fasheh if (fe->i_flags & cpu_to_le32(OCFS2_LOCAL_ALLOC_FL)) { 310ccd979bdSMark Fasheh OCFS2_I(inode)->ip_flags |= OCFS2_INODE_BITMAP; 311ccd979bdSMark Fasheh mlog(0, "local alloc inode: i_ino=%lu\n", inode->i_ino); 312ccd979bdSMark Fasheh } else if (fe->i_flags & cpu_to_le32(OCFS2_BITMAP_FL)) { 313ccd979bdSMark Fasheh OCFS2_I(inode)->ip_flags |= OCFS2_INODE_BITMAP; 3141a224ad1SJan Kara } else if (fe->i_flags & cpu_to_le32(OCFS2_QUOTA_FL)) { 3151a224ad1SJan Kara inode->i_flags |= S_NOQUOTA; 316ccd979bdSMark Fasheh } else if (fe->i_flags & cpu_to_le32(OCFS2_SUPER_BLOCK_FL)) { 317ccd979bdSMark Fasheh mlog(0, "superblock inode: i_ino=%lu\n", inode->i_ino); 318ccd979bdSMark Fasheh /* we can't actually hit this as read_inode can't 319ccd979bdSMark Fasheh * handle superblocks today ;-) */ 320ccd979bdSMark Fasheh BUG(); 321ccd979bdSMark Fasheh } 322ccd979bdSMark Fasheh 323ccd979bdSMark Fasheh switch (inode->i_mode & S_IFMT) { 324ccd979bdSMark Fasheh case S_IFREG: 32553da4939SMark Fasheh if (use_plocks) 326ccd979bdSMark Fasheh inode->i_fop = &ocfs2_fops; 32753da4939SMark Fasheh else 32853da4939SMark Fasheh inode->i_fop = &ocfs2_fops_no_plocks; 329ccd979bdSMark Fasheh inode->i_op = &ocfs2_file_iops; 330ccd979bdSMark Fasheh i_size_write(inode, le64_to_cpu(fe->i_size)); 331ccd979bdSMark Fasheh break; 332ccd979bdSMark Fasheh case S_IFDIR: 333ccd979bdSMark Fasheh inode->i_op = &ocfs2_dir_iops; 33453da4939SMark Fasheh if (use_plocks) 335ccd979bdSMark Fasheh inode->i_fop = &ocfs2_dops; 33653da4939SMark Fasheh else 33753da4939SMark Fasheh inode->i_fop = &ocfs2_dops_no_plocks; 338ccd979bdSMark Fasheh i_size_write(inode, le64_to_cpu(fe->i_size)); 339ccd979bdSMark Fasheh break; 340ccd979bdSMark Fasheh case S_IFLNK: 341ccd979bdSMark Fasheh if (ocfs2_inode_is_fast_symlink(inode)) 342ccd979bdSMark Fasheh inode->i_op = &ocfs2_fast_symlink_inode_operations; 343ccd979bdSMark Fasheh else 344ccd979bdSMark Fasheh inode->i_op = &ocfs2_symlink_inode_operations; 345ccd979bdSMark Fasheh i_size_write(inode, le64_to_cpu(fe->i_size)); 346ccd979bdSMark Fasheh break; 347ccd979bdSMark Fasheh default: 348ccd979bdSMark Fasheh inode->i_op = &ocfs2_special_file_iops; 349ccd979bdSMark Fasheh init_special_inode(inode, inode->i_mode, 350ccd979bdSMark Fasheh inode->i_rdev); 351ccd979bdSMark Fasheh break; 352ccd979bdSMark Fasheh } 353ccd979bdSMark Fasheh 35424c19ef4SMark Fasheh if (create_ino) { 35524c19ef4SMark Fasheh inode->i_ino = ino_from_blkno(inode->i_sb, 35624c19ef4SMark Fasheh le64_to_cpu(fe->i_blkno)); 35724c19ef4SMark Fasheh 35824c19ef4SMark Fasheh /* 35924c19ef4SMark Fasheh * If we ever want to create system files from kernel, 36024c19ef4SMark Fasheh * the generation argument to 36124c19ef4SMark Fasheh * ocfs2_inode_lock_res_init() will have to change. 36224c19ef4SMark Fasheh */ 3631ca1a111SMark Fasheh BUG_ON(le32_to_cpu(fe->i_flags) & OCFS2_SYSTEM_FL); 36424c19ef4SMark Fasheh 365e63aecb6SMark Fasheh ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_inode_lockres, 36624c19ef4SMark Fasheh OCFS2_LOCK_TYPE_META, 0, inode); 36750008630STiger Yang 36850008630STiger Yang ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_open_lockres, 36950008630STiger Yang OCFS2_LOCK_TYPE_OPEN, 0, inode); 37024c19ef4SMark Fasheh } 37124c19ef4SMark Fasheh 37224c19ef4SMark Fasheh ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_rw_lockres, 37324c19ef4SMark Fasheh OCFS2_LOCK_TYPE_RW, inode->i_generation, 37424c19ef4SMark Fasheh inode); 37524c19ef4SMark Fasheh 376ca4d147eSHerbert Poetzl ocfs2_set_inode_flags(inode); 377ca4d147eSHerbert Poetzl 37813821151STao Ma OCFS2_I(inode)->ip_last_used_slot = 0; 37913821151STao Ma OCFS2_I(inode)->ip_last_used_group = 0; 380b657c95cSJoel Becker mlog_exit_void(); 381ccd979bdSMark Fasheh } 382ccd979bdSMark Fasheh 383ccd979bdSMark Fasheh static int ocfs2_read_locked_inode(struct inode *inode, 384ccd979bdSMark Fasheh struct ocfs2_find_inode_args *args) 385ccd979bdSMark Fasheh { 386ccd979bdSMark Fasheh struct super_block *sb; 387ccd979bdSMark Fasheh struct ocfs2_super *osb; 388ccd979bdSMark Fasheh struct ocfs2_dinode *fe; 389ccd979bdSMark Fasheh struct buffer_head *bh = NULL; 39024c19ef4SMark Fasheh int status, can_lock; 39124c19ef4SMark Fasheh u32 generation = 0; 392ccd979bdSMark Fasheh 393ccd979bdSMark Fasheh mlog_entry("(0x%p, 0x%p)\n", inode, args); 394ccd979bdSMark Fasheh 395ccd979bdSMark Fasheh status = -EINVAL; 396ccd979bdSMark Fasheh if (inode == NULL || inode->i_sb == NULL) { 397ccd979bdSMark Fasheh mlog(ML_ERROR, "bad inode\n"); 39824c19ef4SMark Fasheh return status; 399ccd979bdSMark Fasheh } 400ccd979bdSMark Fasheh sb = inode->i_sb; 401ccd979bdSMark Fasheh osb = OCFS2_SB(sb); 402ccd979bdSMark Fasheh 403ccd979bdSMark Fasheh if (!args) { 404ccd979bdSMark Fasheh mlog(ML_ERROR, "bad inode args\n"); 405ccd979bdSMark Fasheh make_bad_inode(inode); 40624c19ef4SMark Fasheh return status; 407ccd979bdSMark Fasheh } 408ccd979bdSMark Fasheh 40924c19ef4SMark Fasheh /* 41024c19ef4SMark Fasheh * To improve performance of cold-cache inode stats, we take 41124c19ef4SMark Fasheh * the cluster lock here if possible. 41224c19ef4SMark Fasheh * 41324c19ef4SMark Fasheh * Generally, OCFS2 never trusts the contents of an inode 41424c19ef4SMark Fasheh * unless it's holding a cluster lock, so taking it here isn't 41524c19ef4SMark Fasheh * a correctness issue as much as it is a performance 41624c19ef4SMark Fasheh * improvement. 41724c19ef4SMark Fasheh * 41824c19ef4SMark Fasheh * There are three times when taking the lock is not a good idea: 41924c19ef4SMark Fasheh * 42024c19ef4SMark Fasheh * 1) During startup, before we have initialized the DLM. 42124c19ef4SMark Fasheh * 42224c19ef4SMark Fasheh * 2) If we are reading certain system files which never get 42324c19ef4SMark Fasheh * cluster locks (local alloc, truncate log). 42424c19ef4SMark Fasheh * 42524c19ef4SMark Fasheh * 3) If the process doing the iget() is responsible for 42624c19ef4SMark Fasheh * orphan dir recovery. We're holding the orphan dir lock and 42724c19ef4SMark Fasheh * can get into a deadlock with another process on another 42824c19ef4SMark Fasheh * node in ->delete_inode(). 42924c19ef4SMark Fasheh * 43024c19ef4SMark Fasheh * #1 and #2 can be simply solved by never taking the lock 43124c19ef4SMark Fasheh * here for system files (which are the only type we read 43224c19ef4SMark Fasheh * during mount). It's a heavier approach, but our main 43324c19ef4SMark Fasheh * concern is user-accesible files anyway. 43424c19ef4SMark Fasheh * 43524c19ef4SMark Fasheh * #3 works itself out because we'll eventually take the 43624c19ef4SMark Fasheh * cluster lock before trusting anything anyway. 43724c19ef4SMark Fasheh */ 43824c19ef4SMark Fasheh can_lock = !(args->fi_flags & OCFS2_FI_FLAG_SYSFILE) 43950008630STiger Yang && !(args->fi_flags & OCFS2_FI_FLAG_ORPHAN_RECOVERY) 440c271c5c2SSunil Mushran && !ocfs2_mount_local(osb); 44124c19ef4SMark Fasheh 44224c19ef4SMark Fasheh /* 44324c19ef4SMark Fasheh * To maintain backwards compatibility with older versions of 44424c19ef4SMark Fasheh * ocfs2-tools, we still store the generation value for system 44524c19ef4SMark Fasheh * files. The only ones that actually matter to userspace are 44624c19ef4SMark Fasheh * the journals, but it's easier and inexpensive to just flag 44724c19ef4SMark Fasheh * all system files similarly. 44824c19ef4SMark Fasheh */ 44924c19ef4SMark Fasheh if (args->fi_flags & OCFS2_FI_FLAG_SYSFILE) 45024c19ef4SMark Fasheh generation = osb->fs_generation; 45124c19ef4SMark Fasheh 452e63aecb6SMark Fasheh ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_inode_lockres, 45324c19ef4SMark Fasheh OCFS2_LOCK_TYPE_META, 45424c19ef4SMark Fasheh generation, inode); 45524c19ef4SMark Fasheh 45650008630STiger Yang ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_open_lockres, 45750008630STiger Yang OCFS2_LOCK_TYPE_OPEN, 45850008630STiger Yang 0, inode); 45950008630STiger Yang 46024c19ef4SMark Fasheh if (can_lock) { 46150008630STiger Yang status = ocfs2_open_lock(inode); 46250008630STiger Yang if (status) { 46350008630STiger Yang make_bad_inode(inode); 46450008630STiger Yang mlog_errno(status); 46550008630STiger Yang return status; 46650008630STiger Yang } 467e63aecb6SMark Fasheh status = ocfs2_inode_lock(inode, NULL, 0); 46824c19ef4SMark Fasheh if (status) { 46924c19ef4SMark Fasheh make_bad_inode(inode); 47024c19ef4SMark Fasheh mlog_errno(status); 47124c19ef4SMark Fasheh return status; 47224c19ef4SMark Fasheh } 47324c19ef4SMark Fasheh } 47424c19ef4SMark Fasheh 47550008630STiger Yang if (args->fi_flags & OCFS2_FI_FLAG_ORPHAN_RECOVERY) { 47650008630STiger Yang status = ocfs2_try_open_lock(inode, 0); 47750008630STiger Yang if (status) { 47850008630STiger Yang make_bad_inode(inode); 47950008630STiger Yang return status; 48050008630STiger Yang } 48150008630STiger Yang } 48250008630STiger Yang 483b657c95cSJoel Becker if (can_lock) { 484b657c95cSJoel Becker status = ocfs2_read_inode_block_full(inode, &bh, 485d4a8c93cSJoel Becker OCFS2_BH_IGNORE_CACHE); 486b657c95cSJoel Becker } else { 487da1e9098SJoel Becker status = ocfs2_read_blocks_sync(osb, args->fi_blkno, 1, &bh); 488b657c95cSJoel Becker if (!status) 489b657c95cSJoel Becker status = ocfs2_validate_inode_block(osb->sb, bh); 490b657c95cSJoel Becker } 491ccd979bdSMark Fasheh if (status < 0) { 492ccd979bdSMark Fasheh mlog_errno(status); 493ccd979bdSMark Fasheh goto bail; 494ccd979bdSMark Fasheh } 495ccd979bdSMark Fasheh 49624c19ef4SMark Fasheh status = -EINVAL; 497ccd979bdSMark Fasheh fe = (struct ocfs2_dinode *) bh->b_data; 498ccd979bdSMark Fasheh 49924c19ef4SMark Fasheh /* 50024c19ef4SMark Fasheh * This is a code bug. Right now the caller needs to 50124c19ef4SMark Fasheh * understand whether it is asking for a system file inode or 50224c19ef4SMark Fasheh * not so the proper lock names can be built. 50324c19ef4SMark Fasheh */ 50424c19ef4SMark Fasheh mlog_bug_on_msg(!!(fe->i_flags & cpu_to_le32(OCFS2_SYSTEM_FL)) != 50524c19ef4SMark Fasheh !!(args->fi_flags & OCFS2_FI_FLAG_SYSFILE), 50624c19ef4SMark Fasheh "Inode %llu: system file state is ambigous\n", 50724c19ef4SMark Fasheh (unsigned long long)args->fi_blkno); 508ccd979bdSMark Fasheh 509ccd979bdSMark Fasheh if (S_ISCHR(le16_to_cpu(fe->i_mode)) || 510ccd979bdSMark Fasheh S_ISBLK(le16_to_cpu(fe->i_mode))) 511ccd979bdSMark Fasheh inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev)); 512ccd979bdSMark Fasheh 513b657c95cSJoel Becker ocfs2_populate_inode(inode, fe, 0); 514ccd979bdSMark Fasheh 515ccd979bdSMark Fasheh BUG_ON(args->fi_blkno != le64_to_cpu(fe->i_blkno)); 516ccd979bdSMark Fasheh 517ccd979bdSMark Fasheh status = 0; 518ccd979bdSMark Fasheh 519ccd979bdSMark Fasheh bail: 52024c19ef4SMark Fasheh if (can_lock) 521e63aecb6SMark Fasheh ocfs2_inode_unlock(inode, 0); 52224c19ef4SMark Fasheh 52324c19ef4SMark Fasheh if (status < 0) 52424c19ef4SMark Fasheh make_bad_inode(inode); 52524c19ef4SMark Fasheh 526ccd979bdSMark Fasheh if (args && bh) 527ccd979bdSMark Fasheh brelse(bh); 528ccd979bdSMark Fasheh 529ccd979bdSMark Fasheh mlog_exit(status); 530ccd979bdSMark Fasheh return status; 531ccd979bdSMark Fasheh } 532ccd979bdSMark Fasheh 533ccd979bdSMark Fasheh void ocfs2_sync_blockdev(struct super_block *sb) 534ccd979bdSMark Fasheh { 535ccd979bdSMark Fasheh sync_blockdev(sb->s_bdev); 536ccd979bdSMark Fasheh } 537ccd979bdSMark Fasheh 538ccd979bdSMark Fasheh static int ocfs2_truncate_for_delete(struct ocfs2_super *osb, 539ccd979bdSMark Fasheh struct inode *inode, 540ccd979bdSMark Fasheh struct buffer_head *fe_bh) 541ccd979bdSMark Fasheh { 542ccd979bdSMark Fasheh int status = 0; 543ccd979bdSMark Fasheh struct ocfs2_truncate_context *tc = NULL; 544ccd979bdSMark Fasheh struct ocfs2_dinode *fe; 54560b11392SMark Fasheh handle_t *handle = NULL; 546ccd979bdSMark Fasheh 547ccd979bdSMark Fasheh mlog_entry_void(); 548ccd979bdSMark Fasheh 549ccd979bdSMark Fasheh fe = (struct ocfs2_dinode *) fe_bh->b_data; 550ccd979bdSMark Fasheh 5511afc32b9SMark Fasheh /* 5521afc32b9SMark Fasheh * This check will also skip truncate of inodes with inline 5531afc32b9SMark Fasheh * data and fast symlinks. 5541afc32b9SMark Fasheh */ 5553a0782d0SMark Fasheh if (fe->i_clusters) { 5562b4e30fbSJoel Becker if (ocfs2_should_order_data(inode)) 5572b4e30fbSJoel Becker ocfs2_begin_ordered_truncate(inode, 0); 5582b4e30fbSJoel Becker 55960b11392SMark Fasheh handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS); 56060b11392SMark Fasheh if (IS_ERR(handle)) { 56160b11392SMark Fasheh status = PTR_ERR(handle); 56260b11392SMark Fasheh mlog_errno(status); 56360b11392SMark Fasheh goto out; 56460b11392SMark Fasheh } 56560b11392SMark Fasheh 5660cf2f763SJoel Becker status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), 5670cf2f763SJoel Becker fe_bh, 56860b11392SMark Fasheh OCFS2_JOURNAL_ACCESS_WRITE); 56960b11392SMark Fasheh if (status < 0) { 57060b11392SMark Fasheh mlog_errno(status); 57160b11392SMark Fasheh goto out; 57260b11392SMark Fasheh } 57360b11392SMark Fasheh 57460b11392SMark Fasheh i_size_write(inode, 0); 57560b11392SMark Fasheh 57660b11392SMark Fasheh status = ocfs2_mark_inode_dirty(handle, inode, fe_bh); 57760b11392SMark Fasheh if (status < 0) { 57860b11392SMark Fasheh mlog_errno(status); 57960b11392SMark Fasheh goto out; 58060b11392SMark Fasheh } 58160b11392SMark Fasheh 58260b11392SMark Fasheh ocfs2_commit_trans(osb, handle); 58360b11392SMark Fasheh handle = NULL; 58460b11392SMark Fasheh 585ccd979bdSMark Fasheh status = ocfs2_prepare_truncate(osb, inode, fe_bh, &tc); 586ccd979bdSMark Fasheh if (status < 0) { 587ccd979bdSMark Fasheh mlog_errno(status); 5883a0782d0SMark Fasheh goto out; 589ccd979bdSMark Fasheh } 590ccd979bdSMark Fasheh 591ccd979bdSMark Fasheh status = ocfs2_commit_truncate(osb, inode, fe_bh, tc); 592ccd979bdSMark Fasheh if (status < 0) { 593ccd979bdSMark Fasheh mlog_errno(status); 5943a0782d0SMark Fasheh goto out; 595ccd979bdSMark Fasheh } 5963a0782d0SMark Fasheh } 597ccd979bdSMark Fasheh 59860b11392SMark Fasheh out: 59960b11392SMark Fasheh if (handle) 60060b11392SMark Fasheh ocfs2_commit_trans(osb, handle); 601ccd979bdSMark Fasheh mlog_exit(status); 602ccd979bdSMark Fasheh return status; 603ccd979bdSMark Fasheh } 604ccd979bdSMark Fasheh 605ccd979bdSMark Fasheh static int ocfs2_remove_inode(struct inode *inode, 606ccd979bdSMark Fasheh struct buffer_head *di_bh, 607ccd979bdSMark Fasheh struct inode *orphan_dir_inode, 608ccd979bdSMark Fasheh struct buffer_head *orphan_dir_bh) 609ccd979bdSMark Fasheh { 610ccd979bdSMark Fasheh int status; 611ccd979bdSMark Fasheh struct inode *inode_alloc_inode = NULL; 612ccd979bdSMark Fasheh struct buffer_head *inode_alloc_bh = NULL; 6131fabe148SMark Fasheh handle_t *handle; 614ccd979bdSMark Fasheh struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 615ccd979bdSMark Fasheh struct ocfs2_dinode *di = (struct ocfs2_dinode *) di_bh->b_data; 616ccd979bdSMark Fasheh 617ccd979bdSMark Fasheh inode_alloc_inode = 618ccd979bdSMark Fasheh ocfs2_get_system_file_inode(osb, INODE_ALLOC_SYSTEM_INODE, 619ccd979bdSMark Fasheh le16_to_cpu(di->i_suballoc_slot)); 620ccd979bdSMark Fasheh if (!inode_alloc_inode) { 621ccd979bdSMark Fasheh status = -EEXIST; 622ccd979bdSMark Fasheh mlog_errno(status); 623ccd979bdSMark Fasheh goto bail; 624ccd979bdSMark Fasheh } 625ccd979bdSMark Fasheh 6261b1dcc1bSJes Sorensen mutex_lock(&inode_alloc_inode->i_mutex); 627e63aecb6SMark Fasheh status = ocfs2_inode_lock(inode_alloc_inode, &inode_alloc_bh, 1); 628ccd979bdSMark Fasheh if (status < 0) { 6291b1dcc1bSJes Sorensen mutex_unlock(&inode_alloc_inode->i_mutex); 630ccd979bdSMark Fasheh 631ccd979bdSMark Fasheh mlog_errno(status); 632ccd979bdSMark Fasheh goto bail; 633ccd979bdSMark Fasheh } 634ccd979bdSMark Fasheh 635a90714c1SJan Kara handle = ocfs2_start_trans(osb, OCFS2_DELETE_INODE_CREDITS + 636a90714c1SJan Kara ocfs2_quota_trans_credits(inode->i_sb)); 637ccd979bdSMark Fasheh if (IS_ERR(handle)) { 638ccd979bdSMark Fasheh status = PTR_ERR(handle); 639ccd979bdSMark Fasheh mlog_errno(status); 640ccd979bdSMark Fasheh goto bail_unlock; 641ccd979bdSMark Fasheh } 642ccd979bdSMark Fasheh 643ccd979bdSMark Fasheh status = ocfs2_orphan_del(osb, handle, orphan_dir_inode, inode, 644ccd979bdSMark Fasheh orphan_dir_bh); 645ccd979bdSMark Fasheh if (status < 0) { 646ccd979bdSMark Fasheh mlog_errno(status); 647ccd979bdSMark Fasheh goto bail_commit; 648ccd979bdSMark Fasheh } 649ccd979bdSMark Fasheh 650ccd979bdSMark Fasheh /* set the inodes dtime */ 6510cf2f763SJoel Becker status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh, 652ccd979bdSMark Fasheh OCFS2_JOURNAL_ACCESS_WRITE); 653ccd979bdSMark Fasheh if (status < 0) { 654ccd979bdSMark Fasheh mlog_errno(status); 655ccd979bdSMark Fasheh goto bail_commit; 656ccd979bdSMark Fasheh } 657ccd979bdSMark Fasheh 658ccd979bdSMark Fasheh di->i_dtime = cpu_to_le64(CURRENT_TIME.tv_sec); 6594092d49fSMarcin Slusarz di->i_flags &= cpu_to_le32(~(OCFS2_VALID_FL | OCFS2_ORPHANED_FL)); 660ec20cec7SJoel Becker ocfs2_journal_dirty(handle, di_bh); 661ccd979bdSMark Fasheh 6628cb471e8SJoel Becker ocfs2_remove_from_cache(INODE_CACHE(inode), di_bh); 66363936ddaSChristoph Hellwig dquot_free_inode(inode); 664ccd979bdSMark Fasheh 665ccd979bdSMark Fasheh status = ocfs2_free_dinode(handle, inode_alloc_inode, 666ccd979bdSMark Fasheh inode_alloc_bh, di); 667ccd979bdSMark Fasheh if (status < 0) 668ccd979bdSMark Fasheh mlog_errno(status); 669ccd979bdSMark Fasheh 670ccd979bdSMark Fasheh bail_commit: 67102dc1af4SMark Fasheh ocfs2_commit_trans(osb, handle); 672ccd979bdSMark Fasheh bail_unlock: 673e63aecb6SMark Fasheh ocfs2_inode_unlock(inode_alloc_inode, 1); 6741b1dcc1bSJes Sorensen mutex_unlock(&inode_alloc_inode->i_mutex); 675ccd979bdSMark Fasheh brelse(inode_alloc_bh); 676ccd979bdSMark Fasheh bail: 677ccd979bdSMark Fasheh iput(inode_alloc_inode); 678ccd979bdSMark Fasheh 679ccd979bdSMark Fasheh return status; 680ccd979bdSMark Fasheh } 681ccd979bdSMark Fasheh 682b4df6ed8SMark Fasheh /* 683b4df6ed8SMark Fasheh * Serialize with orphan dir recovery. If the process doing 684b4df6ed8SMark Fasheh * recovery on this orphan dir does an iget() with the dir 685b4df6ed8SMark Fasheh * i_mutex held, we'll deadlock here. Instead we detect this 686b4df6ed8SMark Fasheh * and exit early - recovery will wipe this inode for us. 687b4df6ed8SMark Fasheh */ 688b4df6ed8SMark Fasheh static int ocfs2_check_orphan_recovery_state(struct ocfs2_super *osb, 689b4df6ed8SMark Fasheh int slot) 690b4df6ed8SMark Fasheh { 691b4df6ed8SMark Fasheh int ret = 0; 692b4df6ed8SMark Fasheh 693b4df6ed8SMark Fasheh spin_lock(&osb->osb_lock); 694b4df6ed8SMark Fasheh if (ocfs2_node_map_test_bit(osb, &osb->osb_recovering_orphan_dirs, slot)) { 695b4df6ed8SMark Fasheh mlog(0, "Recovery is happening on orphan dir %d, will skip " 696b4df6ed8SMark Fasheh "this inode\n", slot); 697b4df6ed8SMark Fasheh ret = -EDEADLK; 698b4df6ed8SMark Fasheh goto out; 699b4df6ed8SMark Fasheh } 700b4df6ed8SMark Fasheh /* This signals to the orphan recovery process that it should 701b4df6ed8SMark Fasheh * wait for us to handle the wipe. */ 702b4df6ed8SMark Fasheh osb->osb_orphan_wipes[slot]++; 703b4df6ed8SMark Fasheh out: 704b4df6ed8SMark Fasheh spin_unlock(&osb->osb_lock); 705b4df6ed8SMark Fasheh return ret; 706b4df6ed8SMark Fasheh } 707b4df6ed8SMark Fasheh 708b4df6ed8SMark Fasheh static void ocfs2_signal_wipe_completion(struct ocfs2_super *osb, 709b4df6ed8SMark Fasheh int slot) 710b4df6ed8SMark Fasheh { 711b4df6ed8SMark Fasheh spin_lock(&osb->osb_lock); 712b4df6ed8SMark Fasheh osb->osb_orphan_wipes[slot]--; 713b4df6ed8SMark Fasheh spin_unlock(&osb->osb_lock); 714b4df6ed8SMark Fasheh 715b4df6ed8SMark Fasheh wake_up(&osb->osb_wipe_event); 716b4df6ed8SMark Fasheh } 717b4df6ed8SMark Fasheh 718ccd979bdSMark Fasheh static int ocfs2_wipe_inode(struct inode *inode, 719ccd979bdSMark Fasheh struct buffer_head *di_bh) 720ccd979bdSMark Fasheh { 721ccd979bdSMark Fasheh int status, orphaned_slot; 722ccd979bdSMark Fasheh struct inode *orphan_dir_inode = NULL; 723ccd979bdSMark Fasheh struct buffer_head *orphan_dir_bh = NULL; 724ccd979bdSMark Fasheh struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 72550008630STiger Yang struct ocfs2_dinode *di; 726ccd979bdSMark Fasheh 72750008630STiger Yang di = (struct ocfs2_dinode *) di_bh->b_data; 72850008630STiger Yang orphaned_slot = le16_to_cpu(di->i_orphaned_slot); 729b4df6ed8SMark Fasheh 730b4df6ed8SMark Fasheh status = ocfs2_check_orphan_recovery_state(osb, orphaned_slot); 731b4df6ed8SMark Fasheh if (status) 732b4df6ed8SMark Fasheh return status; 733b4df6ed8SMark Fasheh 734ccd979bdSMark Fasheh orphan_dir_inode = ocfs2_get_system_file_inode(osb, 735ccd979bdSMark Fasheh ORPHAN_DIR_SYSTEM_INODE, 736ccd979bdSMark Fasheh orphaned_slot); 737ccd979bdSMark Fasheh if (!orphan_dir_inode) { 738ccd979bdSMark Fasheh status = -EEXIST; 739ccd979bdSMark Fasheh mlog_errno(status); 740ccd979bdSMark Fasheh goto bail; 741ccd979bdSMark Fasheh } 742ccd979bdSMark Fasheh 743ccd979bdSMark Fasheh /* Lock the orphan dir. The lock will be held for the entire 744ccd979bdSMark Fasheh * delete_inode operation. We do this now to avoid races with 745ccd979bdSMark Fasheh * recovery completion on other nodes. */ 7461b1dcc1bSJes Sorensen mutex_lock(&orphan_dir_inode->i_mutex); 747e63aecb6SMark Fasheh status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1); 748ccd979bdSMark Fasheh if (status < 0) { 7491b1dcc1bSJes Sorensen mutex_unlock(&orphan_dir_inode->i_mutex); 750ccd979bdSMark Fasheh 751ccd979bdSMark Fasheh mlog_errno(status); 752ccd979bdSMark Fasheh goto bail; 753ccd979bdSMark Fasheh } 754ccd979bdSMark Fasheh 755ccd979bdSMark Fasheh /* we do this while holding the orphan dir lock because we 75634d024f8SMark Fasheh * don't want recovery being run from another node to try an 75734d024f8SMark Fasheh * inode delete underneath us -- this will result in two nodes 758ccd979bdSMark Fasheh * truncating the same file! */ 759ccd979bdSMark Fasheh status = ocfs2_truncate_for_delete(osb, inode, di_bh); 760ccd979bdSMark Fasheh if (status < 0) { 761ccd979bdSMark Fasheh mlog_errno(status); 762ccd979bdSMark Fasheh goto bail_unlock_dir; 763ccd979bdSMark Fasheh } 764ccd979bdSMark Fasheh 7659b7895efSMark Fasheh /* Remove any dir index tree */ 7669b7895efSMark Fasheh if (S_ISDIR(inode->i_mode)) { 7679b7895efSMark Fasheh status = ocfs2_dx_dir_truncate(inode, di_bh); 7689b7895efSMark Fasheh if (status) { 7699b7895efSMark Fasheh mlog_errno(status); 7709b7895efSMark Fasheh goto bail_unlock_dir; 7719b7895efSMark Fasheh } 7729b7895efSMark Fasheh } 7739b7895efSMark Fasheh 774cf1d6c76STiger Yang /*Free extended attribute resources associated with this inode.*/ 775cf1d6c76STiger Yang status = ocfs2_xattr_remove(inode, di_bh); 776cf1d6c76STiger Yang if (status < 0) { 777cf1d6c76STiger Yang mlog_errno(status); 778cf1d6c76STiger Yang goto bail_unlock_dir; 779cf1d6c76STiger Yang } 780cf1d6c76STiger Yang 7818b2c0dbaSTao Ma status = ocfs2_remove_refcount_tree(inode, di_bh); 7828b2c0dbaSTao Ma if (status < 0) { 7838b2c0dbaSTao Ma mlog_errno(status); 7848b2c0dbaSTao Ma goto bail_unlock_dir; 7858b2c0dbaSTao Ma } 7868b2c0dbaSTao Ma 787ccd979bdSMark Fasheh status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode, 788ccd979bdSMark Fasheh orphan_dir_bh); 789ccd979bdSMark Fasheh if (status < 0) 790ccd979bdSMark Fasheh mlog_errno(status); 791ccd979bdSMark Fasheh 792ccd979bdSMark Fasheh bail_unlock_dir: 793e63aecb6SMark Fasheh ocfs2_inode_unlock(orphan_dir_inode, 1); 7941b1dcc1bSJes Sorensen mutex_unlock(&orphan_dir_inode->i_mutex); 795ccd979bdSMark Fasheh brelse(orphan_dir_bh); 796ccd979bdSMark Fasheh bail: 797ccd979bdSMark Fasheh iput(orphan_dir_inode); 798b4df6ed8SMark Fasheh ocfs2_signal_wipe_completion(osb, orphaned_slot); 799ccd979bdSMark Fasheh 800ccd979bdSMark Fasheh return status; 801ccd979bdSMark Fasheh } 802ccd979bdSMark Fasheh 803ccd979bdSMark Fasheh /* There is a series of simple checks that should be done before a 80434d024f8SMark Fasheh * trylock is even considered. Encapsulate those in this function. */ 805ccd979bdSMark Fasheh static int ocfs2_inode_is_valid_to_delete(struct inode *inode) 806ccd979bdSMark Fasheh { 807ccd979bdSMark Fasheh int ret = 0; 808ccd979bdSMark Fasheh struct ocfs2_inode_info *oi = OCFS2_I(inode); 809ccd979bdSMark Fasheh struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 810ccd979bdSMark Fasheh 811ccd979bdSMark Fasheh /* We shouldn't be getting here for the root directory 812ccd979bdSMark Fasheh * inode.. */ 813ccd979bdSMark Fasheh if (inode == osb->root_inode) { 814ccd979bdSMark Fasheh mlog(ML_ERROR, "Skipping delete of root inode.\n"); 815ccd979bdSMark Fasheh goto bail; 816ccd979bdSMark Fasheh } 817ccd979bdSMark Fasheh 81834d024f8SMark Fasheh /* If we're coming from downconvert_thread we can't go into our own 819ccd979bdSMark Fasheh * voting [hello, deadlock city!], so unforuntately we just 820ccd979bdSMark Fasheh * have to skip deleting this guy. That's OK though because 821ccd979bdSMark Fasheh * the node who's doing the actual deleting should handle it 822ccd979bdSMark Fasheh * anyway. */ 82334d024f8SMark Fasheh if (current == osb->dc_task) { 824ccd979bdSMark Fasheh mlog(0, "Skipping delete of %lu because we're currently " 82534d024f8SMark Fasheh "in downconvert\n", inode->i_ino); 826ccd979bdSMark Fasheh goto bail; 827ccd979bdSMark Fasheh } 828ccd979bdSMark Fasheh 829ccd979bdSMark Fasheh spin_lock(&oi->ip_lock); 830ccd979bdSMark Fasheh /* OCFS2 *never* deletes system files. This should technically 831ccd979bdSMark Fasheh * never get here as system file inodes should always have a 832ccd979bdSMark Fasheh * positive link count. */ 833ccd979bdSMark Fasheh if (oi->ip_flags & OCFS2_INODE_SYSTEM_FILE) { 834b0697053SMark Fasheh mlog(ML_ERROR, "Skipping delete of system file %llu\n", 835b0697053SMark Fasheh (unsigned long long)oi->ip_blkno); 836ccd979bdSMark Fasheh goto bail_unlock; 837ccd979bdSMark Fasheh } 838ccd979bdSMark Fasheh 83934d024f8SMark Fasheh /* If we have allowd wipe of this inode for another node, it 84034d024f8SMark Fasheh * will be marked here so we can safely skip it. Recovery will 84134d024f8SMark Fasheh * cleanup any inodes we might inadvertantly skip here. */ 842ccd979bdSMark Fasheh if (oi->ip_flags & OCFS2_INODE_SKIP_DELETE) { 843ccd979bdSMark Fasheh mlog(0, "Skipping delete of %lu because another node " 844ccd979bdSMark Fasheh "has done this for us.\n", inode->i_ino); 845ccd979bdSMark Fasheh goto bail_unlock; 846ccd979bdSMark Fasheh } 847ccd979bdSMark Fasheh 848ccd979bdSMark Fasheh ret = 1; 849ccd979bdSMark Fasheh bail_unlock: 850ccd979bdSMark Fasheh spin_unlock(&oi->ip_lock); 851ccd979bdSMark Fasheh bail: 852ccd979bdSMark Fasheh return ret; 853ccd979bdSMark Fasheh } 854ccd979bdSMark Fasheh 855ccd979bdSMark Fasheh /* Query the cluster to determine whether we should wipe an inode from 856ccd979bdSMark Fasheh * disk or not. 857ccd979bdSMark Fasheh * 858ccd979bdSMark Fasheh * Requires the inode to have the cluster lock. */ 859ccd979bdSMark Fasheh static int ocfs2_query_inode_wipe(struct inode *inode, 860ccd979bdSMark Fasheh struct buffer_head *di_bh, 861ccd979bdSMark Fasheh int *wipe) 862ccd979bdSMark Fasheh { 863ccd979bdSMark Fasheh int status = 0; 864ccd979bdSMark Fasheh struct ocfs2_inode_info *oi = OCFS2_I(inode); 865ccd979bdSMark Fasheh struct ocfs2_dinode *di; 866ccd979bdSMark Fasheh 867ccd979bdSMark Fasheh *wipe = 0; 868ccd979bdSMark Fasheh 869ccd979bdSMark Fasheh /* While we were waiting for the cluster lock in 870ccd979bdSMark Fasheh * ocfs2_delete_inode, another node might have asked to delete 871ccd979bdSMark Fasheh * the inode. Recheck our flags to catch this. */ 872ccd979bdSMark Fasheh if (!ocfs2_inode_is_valid_to_delete(inode)) { 873b0697053SMark Fasheh mlog(0, "Skipping delete of %llu because flags changed\n", 874b0697053SMark Fasheh (unsigned long long)oi->ip_blkno); 875ccd979bdSMark Fasheh goto bail; 876ccd979bdSMark Fasheh } 877ccd979bdSMark Fasheh 878ccd979bdSMark Fasheh /* Now that we have an up to date inode, we can double check 879ccd979bdSMark Fasheh * the link count. */ 880ccd979bdSMark Fasheh if (inode->i_nlink) { 881b0697053SMark Fasheh mlog(0, "Skipping delete of %llu because nlink = %u\n", 882b0697053SMark Fasheh (unsigned long long)oi->ip_blkno, inode->i_nlink); 883ccd979bdSMark Fasheh goto bail; 884ccd979bdSMark Fasheh } 885ccd979bdSMark Fasheh 886ccd979bdSMark Fasheh /* Do some basic inode verification... */ 887ccd979bdSMark Fasheh di = (struct ocfs2_dinode *) di_bh->b_data; 888ccd979bdSMark Fasheh if (!(di->i_flags & cpu_to_le32(OCFS2_ORPHANED_FL))) { 889ccd979bdSMark Fasheh /* for lack of a better error? */ 890ccd979bdSMark Fasheh status = -EEXIST; 891ccd979bdSMark Fasheh mlog(ML_ERROR, 892b0697053SMark Fasheh "Inode %llu (on-disk %llu) not orphaned! " 893ccd979bdSMark Fasheh "Disk flags 0x%x, inode flags 0x%x\n", 894b0697053SMark Fasheh (unsigned long long)oi->ip_blkno, 8951ca1a111SMark Fasheh (unsigned long long)le64_to_cpu(di->i_blkno), 8961ca1a111SMark Fasheh le32_to_cpu(di->i_flags), oi->ip_flags); 897ccd979bdSMark Fasheh goto bail; 898ccd979bdSMark Fasheh } 899ccd979bdSMark Fasheh 900ccd979bdSMark Fasheh /* has someone already deleted us?! baaad... */ 901ccd979bdSMark Fasheh if (di->i_dtime) { 902ccd979bdSMark Fasheh status = -EEXIST; 903ccd979bdSMark Fasheh mlog_errno(status); 904ccd979bdSMark Fasheh goto bail; 905ccd979bdSMark Fasheh } 906ccd979bdSMark Fasheh 9076f16bf65SMark Fasheh /* 9086f16bf65SMark Fasheh * This is how ocfs2 determines whether an inode is still live 9096f16bf65SMark Fasheh * within the cluster. Every node takes a shared read lock on 9106f16bf65SMark Fasheh * the inode open lock in ocfs2_read_locked_inode(). When we 9116f16bf65SMark Fasheh * get to ->delete_inode(), each node tries to convert it's 9126f16bf65SMark Fasheh * lock to an exclusive. Trylocks are serialized by the inode 9136f16bf65SMark Fasheh * meta data lock. If the upconvert suceeds, we know the inode 9146f16bf65SMark Fasheh * is no longer live and can be deleted. 9156f16bf65SMark Fasheh * 9166f16bf65SMark Fasheh * Though we call this with the meta data lock held, the 9176f16bf65SMark Fasheh * trylock keeps us from ABBA deadlock. 9186f16bf65SMark Fasheh */ 9196f16bf65SMark Fasheh status = ocfs2_try_open_lock(inode, 1); 92050008630STiger Yang if (status == -EAGAIN) { 921ccd979bdSMark Fasheh status = 0; 922b0697053SMark Fasheh mlog(0, "Skipping delete of %llu because it is in use on " 923b0697053SMark Fasheh "other nodes\n", (unsigned long long)oi->ip_blkno); 924ccd979bdSMark Fasheh goto bail; 925ccd979bdSMark Fasheh } 926ccd979bdSMark Fasheh if (status < 0) { 927ccd979bdSMark Fasheh mlog_errno(status); 928ccd979bdSMark Fasheh goto bail; 929ccd979bdSMark Fasheh } 930ccd979bdSMark Fasheh 931ccd979bdSMark Fasheh *wipe = 1; 93250008630STiger Yang mlog(0, "Inode %llu is ok to wipe from orphan dir %u\n", 93350008630STiger Yang (unsigned long long)oi->ip_blkno, 93450008630STiger Yang le16_to_cpu(di->i_orphaned_slot)); 935ccd979bdSMark Fasheh 936ccd979bdSMark Fasheh bail: 937ccd979bdSMark Fasheh return status; 938ccd979bdSMark Fasheh } 939ccd979bdSMark Fasheh 940ccd979bdSMark Fasheh /* Support function for ocfs2_delete_inode. Will help us keep the 941ccd979bdSMark Fasheh * inode data in a consistent state for clear_inode. Always truncates 942ccd979bdSMark Fasheh * pages, optionally sync's them first. */ 943ccd979bdSMark Fasheh static void ocfs2_cleanup_delete_inode(struct inode *inode, 944ccd979bdSMark Fasheh int sync_data) 945ccd979bdSMark Fasheh { 946b0697053SMark Fasheh mlog(0, "Cleanup inode %llu, sync = %d\n", 947b0697053SMark Fasheh (unsigned long long)OCFS2_I(inode)->ip_blkno, sync_data); 948ccd979bdSMark Fasheh if (sync_data) 949ccd979bdSMark Fasheh write_inode_now(inode, 1); 950ccd979bdSMark Fasheh truncate_inode_pages(&inode->i_data, 0); 951ccd979bdSMark Fasheh } 952ccd979bdSMark Fasheh 953ccd979bdSMark Fasheh void ocfs2_delete_inode(struct inode *inode) 954ccd979bdSMark Fasheh { 955ccd979bdSMark Fasheh int wipe, status; 956ccd979bdSMark Fasheh sigset_t blocked, oldset; 957ccd979bdSMark Fasheh struct buffer_head *di_bh = NULL; 958ccd979bdSMark Fasheh 959ccd979bdSMark Fasheh mlog_entry("(inode->i_ino = %lu)\n", inode->i_ino); 960ccd979bdSMark Fasheh 961a90714c1SJan Kara /* When we fail in read_inode() we mark inode as bad. The second test 962a90714c1SJan Kara * catches the case when inode allocation fails before allocating 963a90714c1SJan Kara * a block for inode. */ 964a90714c1SJan Kara if (is_bad_inode(inode) || !OCFS2_I(inode)->ip_blkno) { 965ccd979bdSMark Fasheh mlog(0, "Skipping delete of bad inode\n"); 966ccd979bdSMark Fasheh goto bail; 967ccd979bdSMark Fasheh } 968ccd979bdSMark Fasheh 969871a2931SChristoph Hellwig dquot_initialize(inode); 970907f4554SChristoph Hellwig 971ccd979bdSMark Fasheh if (!ocfs2_inode_is_valid_to_delete(inode)) { 972ccd979bdSMark Fasheh /* It's probably not necessary to truncate_inode_pages 973ccd979bdSMark Fasheh * here but we do it for safety anyway (it will most 974ccd979bdSMark Fasheh * likely be a no-op anyway) */ 975ccd979bdSMark Fasheh ocfs2_cleanup_delete_inode(inode, 0); 976ccd979bdSMark Fasheh goto bail; 977ccd979bdSMark Fasheh } 978ccd979bdSMark Fasheh 979ccd979bdSMark Fasheh /* We want to block signals in delete_inode as the lock and 980ccd979bdSMark Fasheh * messaging paths may return us -ERESTARTSYS. Which would 981ccd979bdSMark Fasheh * cause us to exit early, resulting in inodes being orphaned 982ccd979bdSMark Fasheh * forever. */ 983ccd979bdSMark Fasheh sigfillset(&blocked); 984ccd979bdSMark Fasheh status = sigprocmask(SIG_BLOCK, &blocked, &oldset); 985ccd979bdSMark Fasheh if (status < 0) { 986ccd979bdSMark Fasheh mlog_errno(status); 987ccd979bdSMark Fasheh ocfs2_cleanup_delete_inode(inode, 1); 988ccd979bdSMark Fasheh goto bail; 989ccd979bdSMark Fasheh } 990ccd979bdSMark Fasheh 9916ca497a8Swengang wang /* 9926ca497a8Swengang wang * Synchronize us against ocfs2_get_dentry. We take this in 9936ca497a8Swengang wang * shared mode so that all nodes can still concurrently 9946ca497a8Swengang wang * process deletes. 9956ca497a8Swengang wang */ 9966ca497a8Swengang wang status = ocfs2_nfs_sync_lock(OCFS2_SB(inode->i_sb), 0); 9976ca497a8Swengang wang if (status < 0) { 9986ca497a8Swengang wang mlog(ML_ERROR, "getting nfs sync lock(PR) failed %d\n", status); 9996ca497a8Swengang wang ocfs2_cleanup_delete_inode(inode, 0); 10006ca497a8Swengang wang goto bail_unblock; 10016ca497a8Swengang wang } 1002ccd979bdSMark Fasheh /* Lock down the inode. This gives us an up to date view of 1003ccd979bdSMark Fasheh * it's metadata (for verification), and allows us to 100434d024f8SMark Fasheh * serialize delete_inode on multiple nodes. 1005ccd979bdSMark Fasheh * 1006ccd979bdSMark Fasheh * Even though we might be doing a truncate, we don't take the 1007ccd979bdSMark Fasheh * allocation lock here as it won't be needed - nobody will 1008ccd979bdSMark Fasheh * have the file open. 1009ccd979bdSMark Fasheh */ 1010e63aecb6SMark Fasheh status = ocfs2_inode_lock(inode, &di_bh, 1); 1011ccd979bdSMark Fasheh if (status < 0) { 1012ccd979bdSMark Fasheh if (status != -ENOENT) 1013ccd979bdSMark Fasheh mlog_errno(status); 1014ccd979bdSMark Fasheh ocfs2_cleanup_delete_inode(inode, 0); 10156ca497a8Swengang wang goto bail_unlock_nfs_sync; 1016ccd979bdSMark Fasheh } 1017ccd979bdSMark Fasheh 1018ccd979bdSMark Fasheh /* Query the cluster. This will be the final decision made 1019ccd979bdSMark Fasheh * before we go ahead and wipe the inode. */ 1020ccd979bdSMark Fasheh status = ocfs2_query_inode_wipe(inode, di_bh, &wipe); 1021ccd979bdSMark Fasheh if (!wipe || status < 0) { 102234d024f8SMark Fasheh /* Error and remote inode busy both mean we won't be 1023ccd979bdSMark Fasheh * removing the inode, so they take almost the same 1024ccd979bdSMark Fasheh * path. */ 1025ccd979bdSMark Fasheh if (status < 0) 1026ccd979bdSMark Fasheh mlog_errno(status); 1027ccd979bdSMark Fasheh 102834d024f8SMark Fasheh /* Someone in the cluster has disallowed a wipe of 102934d024f8SMark Fasheh * this inode, or it was never completely 103034d024f8SMark Fasheh * orphaned. Write out the pages and exit now. */ 1031ccd979bdSMark Fasheh ocfs2_cleanup_delete_inode(inode, 1); 1032ccd979bdSMark Fasheh goto bail_unlock_inode; 1033ccd979bdSMark Fasheh } 1034ccd979bdSMark Fasheh 1035ccd979bdSMark Fasheh ocfs2_cleanup_delete_inode(inode, 0); 1036ccd979bdSMark Fasheh 1037ccd979bdSMark Fasheh status = ocfs2_wipe_inode(inode, di_bh); 1038ccd979bdSMark Fasheh if (status < 0) { 1039b4df6ed8SMark Fasheh if (status != -EDEADLK) 1040ccd979bdSMark Fasheh mlog_errno(status); 1041ccd979bdSMark Fasheh goto bail_unlock_inode; 1042ccd979bdSMark Fasheh } 1043ccd979bdSMark Fasheh 104424c19ef4SMark Fasheh /* 104524c19ef4SMark Fasheh * Mark the inode as successfully deleted. 104624c19ef4SMark Fasheh * 104724c19ef4SMark Fasheh * This is important for ocfs2_clear_inode() as it will check 104824c19ef4SMark Fasheh * this flag and skip any checkpointing work 104924c19ef4SMark Fasheh * 105024c19ef4SMark Fasheh * ocfs2_stuff_meta_lvb() also uses this flag to invalidate 105124c19ef4SMark Fasheh * the LVB for other nodes. 105224c19ef4SMark Fasheh */ 1053ccd979bdSMark Fasheh OCFS2_I(inode)->ip_flags |= OCFS2_INODE_DELETED; 1054ccd979bdSMark Fasheh 1055ccd979bdSMark Fasheh bail_unlock_inode: 1056e63aecb6SMark Fasheh ocfs2_inode_unlock(inode, 1); 1057ccd979bdSMark Fasheh brelse(di_bh); 10586ca497a8Swengang wang 10596ca497a8Swengang wang bail_unlock_nfs_sync: 10606ca497a8Swengang wang ocfs2_nfs_sync_unlock(OCFS2_SB(inode->i_sb), 0); 10616ca497a8Swengang wang 1062ccd979bdSMark Fasheh bail_unblock: 1063ccd979bdSMark Fasheh status = sigprocmask(SIG_SETMASK, &oldset, NULL); 1064ccd979bdSMark Fasheh if (status < 0) 1065ccd979bdSMark Fasheh mlog_errno(status); 1066ccd979bdSMark Fasheh bail: 1067ccd979bdSMark Fasheh clear_inode(inode); 1068ccd979bdSMark Fasheh mlog_exit_void(); 1069ccd979bdSMark Fasheh } 1070ccd979bdSMark Fasheh 1071ccd979bdSMark Fasheh void ocfs2_clear_inode(struct inode *inode) 1072ccd979bdSMark Fasheh { 1073ccd979bdSMark Fasheh int status; 1074ccd979bdSMark Fasheh struct ocfs2_inode_info *oi = OCFS2_I(inode); 1075ccd979bdSMark Fasheh 1076ccd979bdSMark Fasheh mlog_entry_void(); 1077ccd979bdSMark Fasheh 1078ccd979bdSMark Fasheh if (!inode) 1079ccd979bdSMark Fasheh goto bail; 1080ccd979bdSMark Fasheh 1081b0697053SMark Fasheh mlog(0, "Clearing inode: %llu, nlink = %u\n", 1082b0697053SMark Fasheh (unsigned long long)OCFS2_I(inode)->ip_blkno, inode->i_nlink); 1083ccd979bdSMark Fasheh 1084ccd979bdSMark Fasheh mlog_bug_on_msg(OCFS2_SB(inode->i_sb) == NULL, 1085ccd979bdSMark Fasheh "Inode=%lu\n", inode->i_ino); 1086ccd979bdSMark Fasheh 10879f754758SChristoph Hellwig dquot_drop(inode); 1088257ba15cSChristoph Hellwig 108934d024f8SMark Fasheh /* To preven remote deletes we hold open lock before, now it 109034d024f8SMark Fasheh * is time to unlock PR and EX open locks. */ 109150008630STiger Yang ocfs2_open_unlock(inode); 109250008630STiger Yang 1093ccd979bdSMark Fasheh /* Do these before all the other work so that we don't bounce 109434d024f8SMark Fasheh * the downconvert thread while waiting to destroy the locks. */ 1095ccd979bdSMark Fasheh ocfs2_mark_lockres_freeing(&oi->ip_rw_lockres); 1096e63aecb6SMark Fasheh ocfs2_mark_lockres_freeing(&oi->ip_inode_lockres); 109750008630STiger Yang ocfs2_mark_lockres_freeing(&oi->ip_open_lockres); 1098ccd979bdSMark Fasheh 1099*4fe370afSMark Fasheh ocfs2_resv_discard(&OCFS2_SB(inode->i_sb)->osb_la_resmap, 1100*4fe370afSMark Fasheh &oi->ip_la_data_resv); 1101*4fe370afSMark Fasheh ocfs2_resv_init_once(&oi->ip_la_data_resv); 1102*4fe370afSMark Fasheh 1103ccd979bdSMark Fasheh /* We very well may get a clear_inode before all an inodes 1104ccd979bdSMark Fasheh * metadata has hit disk. Of course, we can't drop any cluster 1105ccd979bdSMark Fasheh * locks until the journal has finished with it. The only 1106ccd979bdSMark Fasheh * exception here are successfully wiped inodes - their 1107ccd979bdSMark Fasheh * metadata can now be considered to be part of the system 1108ccd979bdSMark Fasheh * inodes from which it came. */ 1109ccd979bdSMark Fasheh if (!(OCFS2_I(inode)->ip_flags & OCFS2_INODE_DELETED)) 1110ccd979bdSMark Fasheh ocfs2_checkpoint_inode(inode); 1111ccd979bdSMark Fasheh 1112ccd979bdSMark Fasheh mlog_bug_on_msg(!list_empty(&oi->ip_io_markers), 1113b0697053SMark Fasheh "Clear inode of %llu, inode has io markers\n", 1114b0697053SMark Fasheh (unsigned long long)oi->ip_blkno); 1115ccd979bdSMark Fasheh 111683418978SMark Fasheh ocfs2_extent_map_trunc(inode, 0); 111783418978SMark Fasheh 1118ccd979bdSMark Fasheh status = ocfs2_drop_inode_locks(inode); 1119ccd979bdSMark Fasheh if (status < 0) 1120ccd979bdSMark Fasheh mlog_errno(status); 1121ccd979bdSMark Fasheh 1122ccd979bdSMark Fasheh ocfs2_lock_res_free(&oi->ip_rw_lockres); 1123e63aecb6SMark Fasheh ocfs2_lock_res_free(&oi->ip_inode_lockres); 112450008630STiger Yang ocfs2_lock_res_free(&oi->ip_open_lockres); 1125ccd979bdSMark Fasheh 112666fb345dSJoel Becker ocfs2_metadata_cache_exit(INODE_CACHE(inode)); 1127ccd979bdSMark Fasheh 11288cb471e8SJoel Becker mlog_bug_on_msg(INODE_CACHE(inode)->ci_num_cached, 1129b0697053SMark Fasheh "Clear inode of %llu, inode has %u cache items\n", 11308cb471e8SJoel Becker (unsigned long long)oi->ip_blkno, 11318cb471e8SJoel Becker INODE_CACHE(inode)->ci_num_cached); 1132ccd979bdSMark Fasheh 11338cb471e8SJoel Becker mlog_bug_on_msg(!(INODE_CACHE(inode)->ci_flags & OCFS2_CACHE_FL_INLINE), 1134b0697053SMark Fasheh "Clear inode of %llu, inode has a bad flag\n", 1135b0697053SMark Fasheh (unsigned long long)oi->ip_blkno); 1136ccd979bdSMark Fasheh 1137ccd979bdSMark Fasheh mlog_bug_on_msg(spin_is_locked(&oi->ip_lock), 1138b0697053SMark Fasheh "Clear inode of %llu, inode is locked\n", 1139b0697053SMark Fasheh (unsigned long long)oi->ip_blkno); 1140ccd979bdSMark Fasheh 1141251b6eccSMark Fasheh mlog_bug_on_msg(!mutex_trylock(&oi->ip_io_mutex), 1142b0697053SMark Fasheh "Clear inode of %llu, io_mutex is locked\n", 1143b0697053SMark Fasheh (unsigned long long)oi->ip_blkno); 1144251b6eccSMark Fasheh mutex_unlock(&oi->ip_io_mutex); 1145ccd979bdSMark Fasheh 1146ccd979bdSMark Fasheh /* 1147ccd979bdSMark Fasheh * down_trylock() returns 0, down_write_trylock() returns 1 1148ccd979bdSMark Fasheh * kernel 1, world 0 1149ccd979bdSMark Fasheh */ 1150ccd979bdSMark Fasheh mlog_bug_on_msg(!down_write_trylock(&oi->ip_alloc_sem), 1151b0697053SMark Fasheh "Clear inode of %llu, alloc_sem is locked\n", 1152b0697053SMark Fasheh (unsigned long long)oi->ip_blkno); 1153ccd979bdSMark Fasheh up_write(&oi->ip_alloc_sem); 1154ccd979bdSMark Fasheh 1155ccd979bdSMark Fasheh mlog_bug_on_msg(oi->ip_open_count, 1156b0697053SMark Fasheh "Clear inode of %llu has open count %d\n", 1157b0697053SMark Fasheh (unsigned long long)oi->ip_blkno, oi->ip_open_count); 1158ccd979bdSMark Fasheh 1159ccd979bdSMark Fasheh /* Clear all other flags. */ 116047460d65SJoel Becker oi->ip_flags = 0; 1161ccd979bdSMark Fasheh oi->ip_dir_start_lookup = 0; 1162ccd979bdSMark Fasheh oi->ip_blkno = 0ULL; 1163ae0dff68SSunil Mushran 1164ae0dff68SSunil Mushran /* 1165ae0dff68SSunil Mushran * ip_jinode is used to track txns against this inode. We ensure that 1166ae0dff68SSunil Mushran * the journal is flushed before journal shutdown. Thus it is safe to 1167ae0dff68SSunil Mushran * have inodes get cleaned up after journal shutdown. 1168ae0dff68SSunil Mushran */ 11692b4e30fbSJoel Becker jbd2_journal_release_jbd_inode(OCFS2_SB(inode->i_sb)->journal->j_journal, 11702b4e30fbSJoel Becker &oi->ip_jinode); 1171ccd979bdSMark Fasheh 1172ccd979bdSMark Fasheh bail: 1173ccd979bdSMark Fasheh mlog_exit_void(); 1174ccd979bdSMark Fasheh } 1175ccd979bdSMark Fasheh 1176ccd979bdSMark Fasheh /* Called under inode_lock, with no more references on the 1177ccd979bdSMark Fasheh * struct inode, so it's safe here to check the flags field 1178ccd979bdSMark Fasheh * and to manipulate i_nlink without any other locks. */ 1179ccd979bdSMark Fasheh void ocfs2_drop_inode(struct inode *inode) 1180ccd979bdSMark Fasheh { 1181ccd979bdSMark Fasheh struct ocfs2_inode_info *oi = OCFS2_I(inode); 1182ccd979bdSMark Fasheh 1183ccd979bdSMark Fasheh mlog_entry_void(); 1184ccd979bdSMark Fasheh 1185b0697053SMark Fasheh mlog(0, "Drop inode %llu, nlink = %u, ip_flags = 0x%x\n", 1186b0697053SMark Fasheh (unsigned long long)oi->ip_blkno, inode->i_nlink, oi->ip_flags); 1187ccd979bdSMark Fasheh 1188379dfe9dSMark Fasheh if (oi->ip_flags & OCFS2_INODE_MAYBE_ORPHANED) 1189379dfe9dSMark Fasheh generic_delete_inode(inode); 1190379dfe9dSMark Fasheh else 1191ccd979bdSMark Fasheh generic_drop_inode(inode); 1192ccd979bdSMark Fasheh 1193ccd979bdSMark Fasheh mlog_exit_void(); 1194ccd979bdSMark Fasheh } 1195ccd979bdSMark Fasheh 1196ccd979bdSMark Fasheh /* 1197ccd979bdSMark Fasheh * This is called from our getattr. 1198ccd979bdSMark Fasheh */ 1199ccd979bdSMark Fasheh int ocfs2_inode_revalidate(struct dentry *dentry) 1200ccd979bdSMark Fasheh { 1201ccd979bdSMark Fasheh struct inode *inode = dentry->d_inode; 1202ccd979bdSMark Fasheh int status = 0; 1203ccd979bdSMark Fasheh 1204b0697053SMark Fasheh mlog_entry("(inode = 0x%p, ino = %llu)\n", inode, 1205b0697053SMark Fasheh inode ? (unsigned long long)OCFS2_I(inode)->ip_blkno : 0ULL); 1206ccd979bdSMark Fasheh 1207ccd979bdSMark Fasheh if (!inode) { 1208ccd979bdSMark Fasheh mlog(0, "eep, no inode!\n"); 1209ccd979bdSMark Fasheh status = -ENOENT; 1210ccd979bdSMark Fasheh goto bail; 1211ccd979bdSMark Fasheh } 1212ccd979bdSMark Fasheh 1213ccd979bdSMark Fasheh spin_lock(&OCFS2_I(inode)->ip_lock); 1214ccd979bdSMark Fasheh if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_DELETED) { 1215ccd979bdSMark Fasheh spin_unlock(&OCFS2_I(inode)->ip_lock); 1216ccd979bdSMark Fasheh mlog(0, "inode deleted!\n"); 1217ccd979bdSMark Fasheh status = -ENOENT; 1218ccd979bdSMark Fasheh goto bail; 1219ccd979bdSMark Fasheh } 1220ccd979bdSMark Fasheh spin_unlock(&OCFS2_I(inode)->ip_lock); 1221ccd979bdSMark Fasheh 1222e63aecb6SMark Fasheh /* Let ocfs2_inode_lock do the work of updating our struct 1223ccd979bdSMark Fasheh * inode for us. */ 1224e63aecb6SMark Fasheh status = ocfs2_inode_lock(inode, NULL, 0); 1225ccd979bdSMark Fasheh if (status < 0) { 1226ccd979bdSMark Fasheh if (status != -ENOENT) 1227ccd979bdSMark Fasheh mlog_errno(status); 1228ccd979bdSMark Fasheh goto bail; 1229ccd979bdSMark Fasheh } 1230e63aecb6SMark Fasheh ocfs2_inode_unlock(inode, 0); 1231ccd979bdSMark Fasheh bail: 1232ccd979bdSMark Fasheh mlog_exit(status); 1233ccd979bdSMark Fasheh 1234ccd979bdSMark Fasheh return status; 1235ccd979bdSMark Fasheh } 1236ccd979bdSMark Fasheh 1237ccd979bdSMark Fasheh /* 1238ccd979bdSMark Fasheh * Updates a disk inode from a 1239ccd979bdSMark Fasheh * struct inode. 1240ccd979bdSMark Fasheh * Only takes ip_lock. 1241ccd979bdSMark Fasheh */ 12421fabe148SMark Fasheh int ocfs2_mark_inode_dirty(handle_t *handle, 1243ccd979bdSMark Fasheh struct inode *inode, 1244ccd979bdSMark Fasheh struct buffer_head *bh) 1245ccd979bdSMark Fasheh { 1246ccd979bdSMark Fasheh int status; 1247ccd979bdSMark Fasheh struct ocfs2_dinode *fe = (struct ocfs2_dinode *) bh->b_data; 1248ccd979bdSMark Fasheh 1249b0697053SMark Fasheh mlog_entry("(inode %llu)\n", 1250b0697053SMark Fasheh (unsigned long long)OCFS2_I(inode)->ip_blkno); 1251ccd979bdSMark Fasheh 12520cf2f763SJoel Becker status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), bh, 1253ccd979bdSMark Fasheh OCFS2_JOURNAL_ACCESS_WRITE); 1254ccd979bdSMark Fasheh if (status < 0) { 1255ccd979bdSMark Fasheh mlog_errno(status); 1256ccd979bdSMark Fasheh goto leave; 1257ccd979bdSMark Fasheh } 1258ccd979bdSMark Fasheh 1259ccd979bdSMark Fasheh spin_lock(&OCFS2_I(inode)->ip_lock); 1260ccd979bdSMark Fasheh fe->i_clusters = cpu_to_le32(OCFS2_I(inode)->ip_clusters); 12616e4b0d56SJan Kara ocfs2_get_inode_flags(OCFS2_I(inode)); 1262ca4d147eSHerbert Poetzl fe->i_attr = cpu_to_le32(OCFS2_I(inode)->ip_attr); 126315b1e36bSMark Fasheh fe->i_dyn_features = cpu_to_le16(OCFS2_I(inode)->ip_dyn_features); 1264ccd979bdSMark Fasheh spin_unlock(&OCFS2_I(inode)->ip_lock); 1265ccd979bdSMark Fasheh 1266ccd979bdSMark Fasheh fe->i_size = cpu_to_le64(i_size_read(inode)); 1267198a1ca3SMark Fasheh ocfs2_set_links_count(fe, inode->i_nlink); 1268ccd979bdSMark Fasheh fe->i_uid = cpu_to_le32(inode->i_uid); 1269ccd979bdSMark Fasheh fe->i_gid = cpu_to_le32(inode->i_gid); 1270ccd979bdSMark Fasheh fe->i_mode = cpu_to_le16(inode->i_mode); 1271ccd979bdSMark Fasheh fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec); 1272ccd979bdSMark Fasheh fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec); 1273ccd979bdSMark Fasheh fe->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec); 1274ccd979bdSMark Fasheh fe->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec); 1275ccd979bdSMark Fasheh fe->i_mtime = cpu_to_le64(inode->i_mtime.tv_sec); 1276ccd979bdSMark Fasheh fe->i_mtime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec); 1277ccd979bdSMark Fasheh 1278ec20cec7SJoel Becker ocfs2_journal_dirty(handle, bh); 1279ccd979bdSMark Fasheh leave: 1280ccd979bdSMark Fasheh mlog_exit(status); 1281ccd979bdSMark Fasheh return status; 1282ccd979bdSMark Fasheh } 1283ccd979bdSMark Fasheh 1284ccd979bdSMark Fasheh /* 1285ccd979bdSMark Fasheh * 1286ccd979bdSMark Fasheh * Updates a struct inode from a disk inode. 1287ccd979bdSMark Fasheh * does no i/o, only takes ip_lock. 1288ccd979bdSMark Fasheh */ 1289ccd979bdSMark Fasheh void ocfs2_refresh_inode(struct inode *inode, 1290ccd979bdSMark Fasheh struct ocfs2_dinode *fe) 1291ccd979bdSMark Fasheh { 1292ccd979bdSMark Fasheh spin_lock(&OCFS2_I(inode)->ip_lock); 1293ccd979bdSMark Fasheh 1294ccd979bdSMark Fasheh OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters); 1295ca4d147eSHerbert Poetzl OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr); 129615b1e36bSMark Fasheh OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features); 1297ca4d147eSHerbert Poetzl ocfs2_set_inode_flags(inode); 1298ccd979bdSMark Fasheh i_size_write(inode, le64_to_cpu(fe->i_size)); 1299198a1ca3SMark Fasheh inode->i_nlink = ocfs2_read_links_count(fe); 1300ccd979bdSMark Fasheh inode->i_uid = le32_to_cpu(fe->i_uid); 1301ccd979bdSMark Fasheh inode->i_gid = le32_to_cpu(fe->i_gid); 1302ccd979bdSMark Fasheh inode->i_mode = le16_to_cpu(fe->i_mode); 1303ccd979bdSMark Fasheh if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0) 1304ccd979bdSMark Fasheh inode->i_blocks = 0; 1305ccd979bdSMark Fasheh else 13068110b073SMark Fasheh inode->i_blocks = ocfs2_inode_sector_count(inode); 1307ccd979bdSMark Fasheh inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime); 1308ccd979bdSMark Fasheh inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec); 1309ccd979bdSMark Fasheh inode->i_mtime.tv_sec = le64_to_cpu(fe->i_mtime); 1310ccd979bdSMark Fasheh inode->i_mtime.tv_nsec = le32_to_cpu(fe->i_mtime_nsec); 1311ccd979bdSMark Fasheh inode->i_ctime.tv_sec = le64_to_cpu(fe->i_ctime); 1312ccd979bdSMark Fasheh inode->i_ctime.tv_nsec = le32_to_cpu(fe->i_ctime_nsec); 1313ccd979bdSMark Fasheh 1314ccd979bdSMark Fasheh spin_unlock(&OCFS2_I(inode)->ip_lock); 1315ccd979bdSMark Fasheh } 1316b657c95cSJoel Becker 1317b657c95cSJoel Becker int ocfs2_validate_inode_block(struct super_block *sb, 1318b657c95cSJoel Becker struct buffer_head *bh) 1319b657c95cSJoel Becker { 1320d6b32bbbSJoel Becker int rc; 1321b657c95cSJoel Becker struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data; 1322b657c95cSJoel Becker 1323970e4936SJoel Becker mlog(0, "Validating dinode %llu\n", 1324970e4936SJoel Becker (unsigned long long)bh->b_blocknr); 1325970e4936SJoel Becker 1326b657c95cSJoel Becker BUG_ON(!buffer_uptodate(bh)); 1327b657c95cSJoel Becker 1328d6b32bbbSJoel Becker /* 1329d6b32bbbSJoel Becker * If the ecc fails, we return the error but otherwise 1330d6b32bbbSJoel Becker * leave the filesystem running. We know any error is 1331d6b32bbbSJoel Becker * local to this block. 1332d6b32bbbSJoel Becker */ 1333d6b32bbbSJoel Becker rc = ocfs2_validate_meta_ecc(sb, bh->b_data, &di->i_check); 133413723d00SJoel Becker if (rc) { 133513723d00SJoel Becker mlog(ML_ERROR, "Checksum failed for dinode %llu\n", 133613723d00SJoel Becker (unsigned long long)bh->b_blocknr); 1337d6b32bbbSJoel Becker goto bail; 133813723d00SJoel Becker } 1339d6b32bbbSJoel Becker 1340d6b32bbbSJoel Becker /* 1341d6b32bbbSJoel Becker * Errors after here are fatal. 1342d6b32bbbSJoel Becker */ 1343d6b32bbbSJoel Becker 1344d6b32bbbSJoel Becker rc = -EINVAL; 1345d6b32bbbSJoel Becker 1346b657c95cSJoel Becker if (!OCFS2_IS_VALID_DINODE(di)) { 1347b657c95cSJoel Becker ocfs2_error(sb, "Invalid dinode #%llu: signature = %.*s\n", 1348b657c95cSJoel Becker (unsigned long long)bh->b_blocknr, 7, 1349b657c95cSJoel Becker di->i_signature); 1350b657c95cSJoel Becker goto bail; 1351b657c95cSJoel Becker } 1352b657c95cSJoel Becker 1353b657c95cSJoel Becker if (le64_to_cpu(di->i_blkno) != bh->b_blocknr) { 1354b657c95cSJoel Becker ocfs2_error(sb, "Invalid dinode #%llu: i_blkno is %llu\n", 1355b657c95cSJoel Becker (unsigned long long)bh->b_blocknr, 1356b657c95cSJoel Becker (unsigned long long)le64_to_cpu(di->i_blkno)); 1357b657c95cSJoel Becker goto bail; 1358b657c95cSJoel Becker } 1359b657c95cSJoel Becker 1360b657c95cSJoel Becker if (!(di->i_flags & cpu_to_le32(OCFS2_VALID_FL))) { 1361b657c95cSJoel Becker ocfs2_error(sb, 1362b657c95cSJoel Becker "Invalid dinode #%llu: OCFS2_VALID_FL not set\n", 1363b657c95cSJoel Becker (unsigned long long)bh->b_blocknr); 1364b657c95cSJoel Becker goto bail; 1365b657c95cSJoel Becker } 1366b657c95cSJoel Becker 1367b657c95cSJoel Becker if (le32_to_cpu(di->i_fs_generation) != 1368b657c95cSJoel Becker OCFS2_SB(sb)->fs_generation) { 1369b657c95cSJoel Becker ocfs2_error(sb, 1370b657c95cSJoel Becker "Invalid dinode #%llu: fs_generation is %u\n", 1371b657c95cSJoel Becker (unsigned long long)bh->b_blocknr, 1372b657c95cSJoel Becker le32_to_cpu(di->i_fs_generation)); 1373b657c95cSJoel Becker goto bail; 1374b657c95cSJoel Becker } 1375b657c95cSJoel Becker 1376b657c95cSJoel Becker rc = 0; 1377b657c95cSJoel Becker 1378b657c95cSJoel Becker bail: 1379b657c95cSJoel Becker return rc; 1380b657c95cSJoel Becker } 1381b657c95cSJoel Becker 1382b657c95cSJoel Becker int ocfs2_read_inode_block_full(struct inode *inode, struct buffer_head **bh, 1383b657c95cSJoel Becker int flags) 1384b657c95cSJoel Becker { 1385b657c95cSJoel Becker int rc; 1386b657c95cSJoel Becker struct buffer_head *tmp = *bh; 1387b657c95cSJoel Becker 13888cb471e8SJoel Becker rc = ocfs2_read_blocks(INODE_CACHE(inode), OCFS2_I(inode)->ip_blkno, 13898cb471e8SJoel Becker 1, &tmp, flags, ocfs2_validate_inode_block); 1390b657c95cSJoel Becker 1391b657c95cSJoel Becker /* If ocfs2_read_blocks() got us a new bh, pass it up. */ 1392970e4936SJoel Becker if (!rc && !*bh) 1393b657c95cSJoel Becker *bh = tmp; 1394b657c95cSJoel Becker 1395b657c95cSJoel Becker return rc; 1396b657c95cSJoel Becker } 1397b657c95cSJoel Becker 1398b657c95cSJoel Becker int ocfs2_read_inode_block(struct inode *inode, struct buffer_head **bh) 1399b657c95cSJoel Becker { 1400b657c95cSJoel Becker return ocfs2_read_inode_block_full(inode, bh, 0); 1401b657c95cSJoel Becker } 14026e5a3d75SJoel Becker 14036e5a3d75SJoel Becker 14046e5a3d75SJoel Becker static u64 ocfs2_inode_cache_owner(struct ocfs2_caching_info *ci) 14056e5a3d75SJoel Becker { 14066e5a3d75SJoel Becker struct ocfs2_inode_info *oi = cache_info_to_inode(ci); 14076e5a3d75SJoel Becker 14086e5a3d75SJoel Becker return oi->ip_blkno; 14096e5a3d75SJoel Becker } 14106e5a3d75SJoel Becker 14118cb471e8SJoel Becker static struct super_block *ocfs2_inode_cache_get_super(struct ocfs2_caching_info *ci) 14128cb471e8SJoel Becker { 14138cb471e8SJoel Becker struct ocfs2_inode_info *oi = cache_info_to_inode(ci); 14148cb471e8SJoel Becker 14158cb471e8SJoel Becker return oi->vfs_inode.i_sb; 14168cb471e8SJoel Becker } 14178cb471e8SJoel Becker 14186e5a3d75SJoel Becker static void ocfs2_inode_cache_lock(struct ocfs2_caching_info *ci) 14196e5a3d75SJoel Becker { 14206e5a3d75SJoel Becker struct ocfs2_inode_info *oi = cache_info_to_inode(ci); 14216e5a3d75SJoel Becker 14226e5a3d75SJoel Becker spin_lock(&oi->ip_lock); 14236e5a3d75SJoel Becker } 14246e5a3d75SJoel Becker 14256e5a3d75SJoel Becker static void ocfs2_inode_cache_unlock(struct ocfs2_caching_info *ci) 14266e5a3d75SJoel Becker { 14276e5a3d75SJoel Becker struct ocfs2_inode_info *oi = cache_info_to_inode(ci); 14286e5a3d75SJoel Becker 14296e5a3d75SJoel Becker spin_unlock(&oi->ip_lock); 14306e5a3d75SJoel Becker } 14316e5a3d75SJoel Becker 14326e5a3d75SJoel Becker static void ocfs2_inode_cache_io_lock(struct ocfs2_caching_info *ci) 14336e5a3d75SJoel Becker { 14346e5a3d75SJoel Becker struct ocfs2_inode_info *oi = cache_info_to_inode(ci); 14356e5a3d75SJoel Becker 14366e5a3d75SJoel Becker mutex_lock(&oi->ip_io_mutex); 14376e5a3d75SJoel Becker } 14386e5a3d75SJoel Becker 14396e5a3d75SJoel Becker static void ocfs2_inode_cache_io_unlock(struct ocfs2_caching_info *ci) 14406e5a3d75SJoel Becker { 14416e5a3d75SJoel Becker struct ocfs2_inode_info *oi = cache_info_to_inode(ci); 14426e5a3d75SJoel Becker 14436e5a3d75SJoel Becker mutex_unlock(&oi->ip_io_mutex); 14446e5a3d75SJoel Becker } 14456e5a3d75SJoel Becker 14466e5a3d75SJoel Becker const struct ocfs2_caching_operations ocfs2_inode_caching_ops = { 14476e5a3d75SJoel Becker .co_owner = ocfs2_inode_cache_owner, 14488cb471e8SJoel Becker .co_get_super = ocfs2_inode_cache_get_super, 14496e5a3d75SJoel Becker .co_cache_lock = ocfs2_inode_cache_lock, 14506e5a3d75SJoel Becker .co_cache_unlock = ocfs2_inode_cache_unlock, 14516e5a3d75SJoel Becker .co_io_lock = ocfs2_inode_cache_io_lock, 14526e5a3d75SJoel Becker .co_io_unlock = ocfs2_inode_cache_io_unlock, 14536e5a3d75SJoel Becker }; 14546e5a3d75SJoel Becker 1455