1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define DEBUG_SUBSYSTEM S_SM
25 #include <linux/kmod.h>
26 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <linux/string.h>
30 #include <linux/obd_class.h>
31 #include <linux/obd_support.h>
32 #include <linux/lustre_lib.h>
33 #include <linux/lustre_idl.h>
34 #include <linux/lustre_smfs.h>
35 #include "smfs_internal.h"
37 static void smfs_read_inode(struct inode *inode)
39 struct super_block *cache_sb;
40 struct inode *cache_inode;
46 CDEBUG(D_INODE, "read_inode ino %lu\n", inode->i_ino);
47 cache_sb = S2CSB(inode->i_sb);
49 cache_inode = iget(cache_sb, inode->i_ino);
51 SMFS_SET_INODE_REC(inode);
52 SMFS_SET_INODE_CACHE_HOOK(inode);
53 I2CI(inode) = cache_inode;
55 pre_smfs_inode(inode, cache_inode);
56 if (cache_sb && cache_sb->s_op->read_inode)
57 cache_sb->s_op->read_inode(cache_inode);
59 post_smfs_inode(inode, cache_inode);
60 sm_set_inode_ops(cache_inode, inode);
62 CDEBUG(D_INODE, "read_inode ino %lu icount %d \n",
63 inode->i_ino, atomic_read(&inode->i_count));
67 /* Although some filesystem(such as ext3) do not have
68 * clear_inode method, but we need it to free the
71 static void smfs_clear_inode(struct inode *inode)
73 struct super_block *cache_sb;
74 struct inode *cache_inode;
80 cache_sb = S2CSB(inode->i_sb);
81 cache_inode = I2CI(inode);
83 /*FIXME: because i_count of cache_inode may not
84 * be 0 or 1 in before smfs_delete inode, So we
85 * need to dec it to 1 before we call delete_inode
86 * of the bellow cache filesystem Check again latter*/
88 if (atomic_read(&cache_inode->i_count) < 1)
91 while (atomic_read(&cache_inode->i_count) != 1)
92 atomic_dec(&cache_inode->i_count);
96 SMFS_CLEAN_INODE_REC(inode);
101 static void smfs_delete_inode(struct inode *inode)
103 struct inode *cache_inode;
104 struct super_block *cache_sb;
107 cache_inode = I2CI(inode);
108 cache_sb = S2CSB(inode->i_sb);
110 if (!cache_inode || !cache_sb)
113 /* FIXME-WANGDI: because i_count of cache_inode may not be 0 or 1 in
114 * before smfs_delete inode, So we need to dec it to 1 before we call
115 * delete_inode of the bellow cache filesystem Check again latter. */
117 if (atomic_read(&cache_inode->i_count) < 1)
120 while (atomic_read(&cache_inode->i_count) != 1)
121 atomic_dec(&cache_inode->i_count);
123 pre_smfs_inode(inode, cache_inode);
125 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
126 list_del(&cache_inode->i_hash);
127 INIT_LIST_HEAD(&cache_inode->i_hash);
129 hlist_del_init(&cache_inode->i_hash);
132 list_del(&cache_inode->i_list);
133 INIT_LIST_HEAD(&cache_inode->i_list);
135 if (cache_inode->i_data.nrpages)
136 truncate_inode_pages(&cache_inode->i_data, 0);
138 if (cache_sb->s_op->delete_inode)
139 cache_sb->s_op->delete_inode(cache_inode);
141 post_smfs_inode(inode, cache_inode);
147 static void smfs_write_inode(struct inode *inode, int wait)
149 struct inode *cache_inode;
150 struct super_block *cache_sb;
153 cache_inode = I2CI(inode);
154 cache_sb = S2CSB(inode->i_sb);
156 if (!cache_inode || !cache_sb)
159 pre_smfs_inode(inode, cache_inode);
161 if (cache_sb->s_op->write_inode)
162 cache_sb->s_op->write_inode(cache_inode, wait);
164 post_smfs_inode(inode, cache_inode);
168 static void smfs_dirty_inode(struct inode *inode)
170 struct inode *cache_inode;
171 struct super_block *cache_sb;
174 cache_inode = I2CI(inode);
175 cache_sb = S2CSB(inode->i_sb);
177 if (!cache_inode || !cache_sb)
180 pre_smfs_inode(inode, cache_inode);
181 if (cache_sb->s_op->dirty_inode)
182 cache_sb->s_op->dirty_inode(cache_inode);
184 post_smfs_inode(inode, cache_inode);
188 static void smfs_put_inode(struct inode *inode)
190 struct inode *cache_inode;
191 struct super_block *cache_sb;
194 cache_inode = I2CI(inode);
195 cache_sb = S2CSB(inode->i_sb);
197 if (!cache_inode || !cache_sb)
199 if (cache_sb->s_op->put_inode)
200 cache_sb->s_op->put_inode(cache_inode);
204 static void smfs_write_super(struct super_block *sb)
206 struct super_block *cache_sb;
209 cache_sb = S2CSB(sb);
213 if (cache_sb->s_op->write_super)
214 cache_sb->s_op->write_super(cache_sb);
216 duplicate_sb(sb, cache_sb);
220 static void smfs_write_super_lockfs(struct super_block *sb)
222 struct super_block *cache_sb;
225 cache_sb = S2CSB(sb);
229 if (cache_sb->s_op->write_super_lockfs)
230 cache_sb->s_op->write_super_lockfs(cache_sb);
232 duplicate_sb(sb, cache_sb);
236 static void smfs_unlockfs(struct super_block *sb)
238 struct super_block *cache_sb;
241 cache_sb = S2CSB(sb);
245 if (cache_sb->s_op->unlockfs)
246 cache_sb->s_op->unlockfs(cache_sb);
248 duplicate_sb(sb, cache_sb);
252 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
253 static int smfs_statfs(struct super_block *sb, struct statfs *buf)
255 static int smfs_statfs(struct super_block *sb, struct kstatfs *buf)
258 struct super_block *cache_sb;
262 cache_sb = S2CSB(sb);
266 if (cache_sb->s_op->statfs)
267 rc = cache_sb->s_op->statfs(cache_sb, buf);
269 duplicate_sb(sb, cache_sb);
274 static int smfs_remount(struct super_block *sb, int *flags, char *data)
276 struct super_block *cache_sb;
280 cache_sb = S2CSB(sb);
285 if (cache_sb->s_op->remount_fs)
286 rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
288 duplicate_sb(sb, cache_sb);
292 struct super_operations smfs_super_ops = {
293 read_inode: smfs_read_inode,
294 clear_inode: smfs_clear_inode,
295 put_super: smfs_put_super,
296 delete_inode: smfs_delete_inode,
297 write_inode: smfs_write_inode,
298 dirty_inode: smfs_dirty_inode, /* BKL not held. We take it */
299 put_inode: smfs_put_inode, /* BKL not held. Don't need */
301 write_super: smfs_write_super, /* BKL held */
302 write_super_lockfs: smfs_write_super_lockfs, /* BKL not held. Take it */
303 unlockfs: smfs_unlockfs, /* BKL not held. We take it */
304 statfs: smfs_statfs, /* BKL held */
305 remount_fs: smfs_remount, /* BKL held */