1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre filesystem abstraction routines
7 * Copyright (C) 2004 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define DEBUG_SUBSYSTEM S_SM
27 #include <linux/kmod.h>
28 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <linux/string.h>
32 #include <linux/obd_class.h>
33 #include <linux/obd_support.h>
34 #include <linux/lustre_lib.h>
35 #include <linux/lustre_idl.h>
36 #include <linux/lustre_fsfilt.h>
37 #include <linux/lustre_smfs.h>
38 #include "smfs_internal.h"
40 static void smfs_init_inode_info(struct inode *inode, void *opaque)
43 struct inode *cache_inode = NULL;
44 struct smfs_iget_args *sargs = opaque;
47 /* getting backing fs inode. */
48 ino = sargs ? sargs->s_ino : inode->i_ino;
49 cache_inode = iget(S2CSB(inode->i_sb), ino);
51 OBD_ALLOC(inode->u.generic_ip,
52 sizeof(struct smfs_inode_info));
54 LASSERT(inode->u.generic_ip);
55 I2CI(inode) = cache_inode;
57 CDEBUG(D_INODE, "cache_inode %lu i_count %d\n",
58 cache_inode->i_ino, atomic_read(&cache_inode->i_count));
60 post_smfs_inode(inode, cache_inode);
61 sm_set_inode_ops(cache_inode, inode);
64 struct inode *dir = sargs->s_inode;
66 I2SMI(inode)->smi_flags = I2SMI(dir)->smi_flags;
71 static void smfs_clear_inode_info(struct inode *inode)
74 struct inode *cache_inode = I2CI(inode);
76 //CDEBUG(D_INODE, "Clear_info: cache_inode %lu\n", cache_inode->i_ino);
78 LASSERTF(((atomic_read(&cache_inode->i_count) == 1) ||
79 cache_inode == cache_inode->i_sb->s_root->d_inode),
80 "inode %p cache inode %p #%lu i_count %d != 1 \n",
81 inode, cache_inode, cache_inode->i_ino,
82 atomic_read(&cache_inode->i_count));
84 //if (cache_inode != cache_inode->i_sb->s_root->d_inode)
87 OBD_FREE(inode->u.generic_ip,
88 sizeof(struct smfs_inode_info));
89 inode->u.generic_ip = NULL;
93 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
94 static void smfs_read_inode2(struct inode *inode, void *opaque)
103 CDEBUG(D_INODE, "read_inode ino %lu\n", inode->i_ino);
104 smfs_init_inode_info(inode, opaque);
105 CDEBUG(D_INODE, "read_inode ino %lu icount %d \n",
106 inode->i_ino, atomic_read(&inode->i_count));
110 static int smfs_test_inode(struct inode *inode, unsigned long ino,
113 static int smfs_test_inode(struct inode *inode, void *opaque)
116 struct smfs_iget_args *sargs = (struct smfs_iget_args*)opaque;
118 if (!sargs || (inode->i_ino != sargs->s_ino))
122 if (SMFS_DO_COW(S2SMI(inode->i_sb)) &&
123 !smfs_snap_test_inode(inode, opaque))
129 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
130 int smfs_set_inode(struct inode *inode, void *opaque)
135 static struct inode *smfs_iget(struct super_block *sb, ino_t hash,
136 struct smfs_iget_args *sargs)
141 inode = iget5_locked(sb, hash, smfs_test_inode,
142 smfs_set_inode, sargs);
144 if (inode->i_state & I_NEW) {
145 smfs_init_inode_info(inode, (void*)sargs);
146 unlock_new_inode(inode);
149 CDEBUG(D_VFSTRACE, "inode: %lu/%u(%p) index %d "
150 "ino %d\n", inode->i_ino, inode->i_generation,
151 inode, sargs->s_index, sargs->s_ino);
157 struct inode *smfs_iget(struct super_block *sb, ino_t hash,
158 struct smfs_iget_args *sargs)
163 inode = iget4(sb, hash, smfs_test_inode, sargs);
165 struct inode *cache_inode = I2CI(inode);
167 CDEBUG(D_VFSTRACE, "new inode: %lu/%u(%p)\n", inode->i_ino,
168 inode->i_generation, inode);
174 struct inode *smfs_get_inode(struct super_block *sb, ino_t hash,
175 struct inode *dir, int index)
177 struct smfs_iget_args sargs;
183 sargs.s_index = index;
184 CDEBUG(D_VFSTRACE, "get_inode: %lu\n", hash);
185 inode = smfs_iget(sb, hash, &sargs);
189 static void smfs_write_inode(struct inode *inode, int wait)
191 struct inode *cache_inode;
195 cache_inode = I2CI(inode);
196 LASSERT(cache_inode);
198 CDEBUG(D_INODE,"Write inode %lu\n",inode->i_ino);
200 pre_smfs_inode(inode, cache_inode);
202 cache_inode->i_sb->s_op->write_inode(cache_inode, wait);
204 post_smfs_inode(inode, cache_inode);
209 static void smfs_dirty_inode(struct inode *inode)
211 struct inode *cache_inode;
214 cache_inode = I2CI(inode);
215 LASSERT(cache_inode);
217 pre_smfs_inode(inode, cache_inode);
218 S2CSB(inode->i_sb)->s_op->dirty_inode(cache_inode);
220 post_smfs_inode(inode, cache_inode);
224 static void smfs_delete_inode(struct inode *inode)
231 static void smfs_clear_inode(struct inode *inode)
234 smfs_clear_inode_info(inode);
238 static void smfs_write_super(struct super_block *sb)
244 S2CSB(sb)->s_op->write_super(S2CSB(sb));
245 duplicate_sb(sb, S2CSB(sb));
249 static void smfs_write_super_lockfs(struct super_block *sb)
251 struct super_block * cache_sb = S2CSB(sb);
256 cache_sb->s_op->write_super_lockfs(cache_sb);
257 duplicate_sb(sb, cache_sb);
261 static void smfs_unlockfs(struct super_block *sb)
263 struct super_block * cache_sb = S2CSB(sb);
268 cache_sb->s_op->unlockfs(cache_sb);
270 duplicate_sb(sb, cache_sb);
274 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
275 static int smfs_statfs(struct super_block *sb, struct statfs *buf)
277 static int smfs_statfs(struct super_block *sb, struct kstatfs *buf)
280 struct super_block *cache_sb = S2CSB(sb);
286 rc = cache_sb->s_op->statfs(cache_sb, buf);
287 duplicate_sb(sb, cache_sb);
292 static int smfs_remount(struct super_block *sb, int *flags, char *data)
294 struct super_block *cache_sb = S2CSB(sb);
300 rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
301 duplicate_sb(sb, cache_sb);
306 struct super_operations smfs_super_ops = {
307 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
308 .read_inode2 = smfs_read_inode2,
310 .clear_inode = smfs_clear_inode,
311 .put_super = smfs_put_super,
312 .delete_inode = smfs_delete_inode,
313 .write_inode = smfs_write_inode,
314 .dirty_inode = smfs_dirty_inode, /* BKL not held. */
315 .write_super = smfs_write_super, /* BKL held */
316 .write_super_lockfs = smfs_write_super_lockfs, /* BKL not held. */
317 .unlockfs = smfs_unlockfs, /* BKL not held. */
318 .statfs = smfs_statfs, /* BKL held */
319 .remount_fs = smfs_remount, /* BKL held */