#include <linux/lustre_smfs.h>
#include "smfs_internal.h"
-static void smfs_init_inode_info (struct inode *inode, void *opaque)
+#define SMFS_IOPEN_INO 1
+
+static void smfs_init_inode_info(struct inode *inode, void *opaque)
{
- struct smfs_iget_args *sargs = (struct smfs_iget_args*)opaque;
- struct inode *cache_inode = NULL;
+ if (!I2SMI(inode)) {
+ struct inode *cache_inode = NULL;
+ struct smfs_iget_args *sargs = opaque;
+ unsigned long ino;
+
+ /* getting backing fs inode. */
+ LASSERT(sargs);
+ ino = sargs ? sargs->s_ino : inode->i_ino;
+ cache_inode = iget(S2CSB(inode->i_sb), ino);
+
+ OBD_ALLOC(inode->u.generic_ip,
+ sizeof(struct smfs_inode_info));
- cache_inode = iget(S2CSB(inode->i_sb), inode->i_ino);
-
- OBD_ALLOC(I2SMI(inode), sizeof(struct smfs_inode_info));
- LASSERT(I2SMI(inode));
- I2CI(inode) = cache_inode;
- CDEBUG(D_INODE, "cache_inode i_count ino %lu i_count %d\n",
- cache_inode->i_ino, atomic_read(&cache_inode->i_count));
- post_smfs_inode(inode, cache_inode);
- sm_set_inode_ops(cache_inode, inode);
-
- if (sargs) {
- struct inode *dir = sargs->s_inode;
-
- if (dir)
- I2SMI(inode)->smi_flags = I2SMI(dir)->smi_flags;
- }
+ LASSERT(inode->u.generic_ip);
+
+ I2CI(inode) = cache_inode;
+
+ CDEBUG(D_INODE, "cache_inode %lu i_count %d\n",
+ cache_inode->i_ino, atomic_read(&cache_inode->i_count));
+
+ post_smfs_inode(inode, cache_inode);
+ sm_set_inode_ops(cache_inode, inode);
+ //iopen stuff
+ if (ino == SMFS_IOPEN_INO) {
+ inode->i_op = &smfs_iopen_iops;
+ inode->i_fop = &smfs_iopen_fops;
+ }
+ if (sargs) {
+ struct inode *dir = sargs->s_inode;
+ if (dir)
+ I2SMI(inode)->smi_flags = I2SMI(dir)->smi_flags;
+ }
+ } else
+ LBUG();
}
static void smfs_clear_inode_info(struct inode *inode)
{
- struct inode *cache_inode = I2CI(inode);
-
- LASSERTF(atomic_read(&cache_inode->i_count) == 1,
- "cache inode %lu i_count %d not 0\n", cache_inode->i_ino,
- atomic_read(&cache_inode->i_count));
- iput(cache_inode);
- OBD_FREE(I2SMI(inode), sizeof(struct smfs_inode_info));
+ if (I2SMI(inode)) {
+ struct inode *cache_inode = I2CI(inode);
+
+ CDEBUG(D_INODE, "Clear_info: inode %p\n",
+ cache_inode);
+
+ LASSERTF(((atomic_read(&cache_inode->i_count) == 1) ||
+ cache_inode == cache_inode->i_sb->s_root->d_inode),
+ "inode %p cache inode %p #%lu i_count %d != 1 \n",
+ inode, cache_inode, cache_inode->i_ino,
+ atomic_read(&cache_inode->i_count));
+
+ iput(cache_inode);
+
+ OBD_FREE(inode->u.generic_ip, sizeof(struct smfs_inode_info));
+ inode->u.generic_ip = NULL;
+ } else
+ LBUG();
}
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
static void smfs_read_inode2(struct inode *inode, void *opaque)
{
ENTRY;
- if (!inode)
+ if (!inode) {
+ EXIT;
return;
+ }
CDEBUG(D_INODE, "read_inode ino %lu\n", inode->i_ino);
smfs_init_inode_info(inode, opaque);
CDEBUG(D_INODE, "read_inode ino %lu icount %d \n",
inode->i_ino, atomic_read(&inode->i_count));
EXIT;
- return;
}
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
static int smfs_test_inode(struct inode *inode, unsigned long ino,
- void *opaque)
+ void *opaque)
#else
static int smfs_test_inode(struct inode *inode, void *opaque)
#endif
{
struct smfs_iget_args *sargs = (struct smfs_iget_args*)opaque;
- LASSERT(sargs);
- if (!sargs)
- return 1;
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
- if (inode->i_ino != sargs->s_ino)
- return 0;
-#endif
-#ifdef CONFIG_SNAPFS
+ if (!sargs || (inode->i_ino != sargs->s_ino))
+ return 0;
+
+#ifdef CONFIG_SNAPFS
if (SMFS_DO_COW(S2SMI(inode->i_sb)) &&
!smfs_snap_test_inode(inode, opaque))
return 0;
-#endif
+#endif
+
return 1;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
int smfs_set_inode(struct inode *inode, void *opaque)
{
- smfs_read_inode2(inode, opaque);
return 0;
}
-struct inode *smfs_iget(struct super_block *sb, ino_t hash,
+static struct inode *smfs_iget(struct super_block *sb, ino_t hash,
struct smfs_iget_args *sargs)
{
struct inode *inode;
-
LASSERT(hash != 0);
- inode = iget5_locked(sb, hash, smfs_test_inode, smfs_set_inode, sargs);
+ inode = iget5_locked(sb, hash, smfs_test_inode,
+ smfs_set_inode, sargs);
if (inode) {
- if (inode->i_state & I_NEW)
+ if (inode->i_state & I_NEW) {
+ smfs_init_inode_info(inode, (void*)sargs);
unlock_new_inode(inode);
- CDEBUG(D_VFSTRACE, "inode: %lu/%u(%p)\n", inode->i_ino,
- inode->i_generation, inode);
+ }
+ //inode->i_ino = hash;
+ CDEBUG(D_INODE, "inode: %lu/%u(%p) index %d "
+ "ino %d\n", inode->i_ino, inode->i_generation,
+ inode, sargs->s_index, sargs->s_ino);
+ inode->i_ino = hash;
}
return inode;
}
LASSERT(hash != 0);
inode = iget4(sb, hash, smfs_test_inode, sargs);
-
- if (inode)
- CDEBUG(D_VFSTRACE, "inode: %lu/%u(%p)\n", inode->i_ino,
+ if (inode) {
+ struct inode *cache_inode = I2CI(inode);
+
+ CDEBUG(D_INODE, "new inode: %lu/%u(%p)\n", inode->i_ino,
inode->i_generation, inode);
+ }
return inode;
}
#endif
-struct inode *smfs_get_inode (struct super_block *sb, ino_t hash,
- struct inode *dir, int index)
+
+struct inode *smfs_get_inode(struct super_block *sb, ino_t hash,
+ struct inode *dir, int index)
{
- struct inode *inode = NULL;
- struct smfs_iget_args sargs;
+ struct smfs_iget_args sargs;
+ struct inode *inode;
ENTRY;
- sargs.s_index = index;
- sargs.s_inode = inode;
sargs.s_ino = hash;
- inode = smfs_iget(sb, hash, &sargs);
+ sargs.s_inode = dir;
+ sargs.s_index = index;
+ inode = smfs_iget(sb, hash, &sargs);
+
RETURN(inode);
}
-
-static void smfs_delete_inode(struct inode *inode)
+#ifdef FC3_KERNEL
+static int smfs_write_inode(struct inode *inode, int wait)
+#else
+static void smfs_write_inode(struct inode *inode, int wait)
+#endif
{
- struct inode *cache_inode;
-
+ struct inode *cache_inode = I2CI(inode);
+#ifdef FC3_KERNEL
+ int rc = 0;
+#endif
ENTRY;
- cache_inode = I2CI(inode);
-
- if (!cache_inode || !S2CSB(inode->i_sb))
- return;
-
- /* FIXME-WANGDI: because i_count of cache_inode may not be 0 or 1 in
- * before smfs_delete inode, So we need to dec it to 1 before we call
- * delete_inode of the bellow cache filesystem Check again latter. */
-
- if (atomic_read(&cache_inode->i_count) < 1)
- BUG();
-
- while (atomic_read(&cache_inode->i_count) != 1)
- atomic_dec(&cache_inode->i_count);
- pre_smfs_inode(inode, cache_inode);
-
- if (atomic_read(&cache_inode->i_count) < 1)
- LBUG();
-
- while (atomic_read(&cache_inode->i_count) != 1) {
- atomic_dec(&cache_inode->i_count);
- }
+ LASSERT(cache_inode);
+
+ CDEBUG(D_INODE,"Write inode %lu\n",inode->i_ino);
pre_smfs_inode(inode, cache_inode);
-
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
- list_del(&cache_inode->i_hash);
- INIT_LIST_HEAD(&cache_inode->i_hash);
+
+#ifdef FC3_KERNEL
+ rc = cache_inode->i_sb->s_op->write_inode(cache_inode, wait);
#else
- hlist_del_init(&cache_inode->i_hash);
+ cache_inode->i_sb->s_op->write_inode(cache_inode, wait);
#endif
- list_del(&cache_inode->i_list);
- INIT_LIST_HEAD(&cache_inode->i_list);
-
- if (cache_inode->i_data.nrpages)
- truncate_inode_pages(&cache_inode->i_data, 0);
-
- if (S2CSB(inode->i_sb)->s_op->delete_inode)
- S2CSB(inode->i_sb)->s_op->delete_inode(cache_inode);
-
post_smfs_inode(inode, cache_inode);
-
- I2CI(inode) = NULL;
- return;
-}
-
-static void smfs_write_inode(struct inode *inode, int wait)
-{
- struct inode *cache_inode;
-
- ENTRY;
- cache_inode = I2CI(inode);
-
- if (!cache_inode) {
- CWARN("cache inode null\n");
- return;
- }
- pre_smfs_inode(inode, cache_inode);
- if (S2CSB(inode->i_sb)->s_op->write_inode)
- S2CSB(inode->i_sb)->s_op->write_inode(cache_inode, wait);
- post_smfs_inode(inode, cache_inode);
+#ifdef FC3_KERNEL
+ RETURN(rc);
+#else
EXIT;
+#endif
}
static void smfs_dirty_inode(struct inode *inode)
{
struct inode *cache_inode;
-
ENTRY;
- cache_inode = I2CI(inode);
-
- if (!cache_inode || !S2CSB(inode->i_sb))
- return;
+ cache_inode = I2CI(inode);
+ LASSERT(cache_inode);
+
pre_smfs_inode(inode, cache_inode);
- if (S2CSB(inode->i_sb)->s_op->dirty_inode)
- S2CSB(inode->i_sb)->s_op->dirty_inode(cache_inode);
+
+ S2CSB(inode->i_sb)->s_op->dirty_inode(cache_inode);
post_smfs_inode(inode, cache_inode);
EXIT;
}
-static void smfs_put_inode(struct inode *inode)
+static void smfs_delete_inode(struct inode *inode)
{
- struct inode *cache_inode;
-
ENTRY;
- cache_inode = I2CI(inode);
-
- if (!cache_inode) {
- CWARN("cache inode null\n");
- return;
- }
-
- CDEBUG(D_INFO, "cache_inode i_count ino %lu i_count %d\n",
- inode->i_ino, atomic_read(&inode->i_count));
- if (atomic_read(&cache_inode->i_count) > 1 &&
- cache_inode != cache_inode->i_sb->s_root->d_inode) {
- CDEBUG(D_INFO, "cache_inode i_count ino %lu i_count %d\n",
- cache_inode->i_ino,
- atomic_read(&cache_inode->i_count) - 1);
- iput(cache_inode);
- }
-
- if (S2CSB(inode->i_sb)->s_op->put_inode)
- S2CSB(inode->i_sb)->s_op->put_inode(cache_inode);
-
+ clear_inode(inode);
EXIT;
}
-static void smfs_write_super(struct super_block *sb)
+static void smfs_clear_inode(struct inode *inode)
{
ENTRY;
-
- if (!S2CSB(sb))
- return;
-
- if (S2CSB(sb)->s_op->write_super)
- S2CSB(sb)->s_op->write_super(S2CSB(sb));
- duplicate_sb(sb, S2CSB(sb));
+ smfs_clear_inode_info(inode);
EXIT;
- return;
}
-static void smfs_clear_inode(struct inode *inode)
+static void smfs_write_super(struct super_block *sb)
{
- struct inode *cache_inode;
-
ENTRY;
- if (!inode) return;
-
- cache_inode = I2CI(inode);
+ LASSERT(S2CSB(sb));
- if (cache_inode != cache_inode->i_sb->s_root->d_inode)
- smfs_clear_inode_info(inode);
+ S2CSB(sb)->s_op->write_super(S2CSB(sb));
+ duplicate_sb(sb, S2CSB(sb));
EXIT;
- return;
}
static void smfs_write_super_lockfs(struct super_block *sb)
{
- struct super_block *cache_sb;
+ struct super_block * cache_sb = S2CSB(sb);
ENTRY;
- cache_sb = S2CSB(sb);
- if (!cache_sb)
- return;
-
- if (cache_sb->s_op->write_super_lockfs)
- cache_sb->s_op->write_super_lockfs(cache_sb);
+ LASSERT(cache_sb);
+ cache_sb->s_op->write_super_lockfs(cache_sb);
duplicate_sb(sb, cache_sb);
EXIT;
}
static void smfs_unlockfs(struct super_block *sb)
{
- struct super_block *cache_sb;
+ struct super_block * cache_sb = S2CSB(sb);
ENTRY;
- cache_sb = S2CSB(sb);
- if (!cache_sb)
- return;
-
- if (cache_sb->s_op->unlockfs)
- cache_sb->s_op->unlockfs(cache_sb);
+ LASSERT(cache_sb);
+
+ cache_sb->s_op->unlockfs(cache_sb);
duplicate_sb(sb, cache_sb);
EXIT;
static int smfs_statfs(struct super_block *sb, struct kstatfs *buf)
#endif
{
- struct super_block *cache_sb;
+ struct super_block *cache_sb = S2CSB(sb);
int rc = 0;
ENTRY;
- cache_sb = S2CSB(sb);
- if (!cache_sb)
- RETURN(-EINVAL);
-
- if (cache_sb->s_op->statfs)
- rc = cache_sb->s_op->statfs(cache_sb, buf);
+ LASSERT(cache_sb);
+ rc = cache_sb->s_op->statfs(cache_sb, buf);
duplicate_sb(sb, cache_sb);
RETURN(rc);
}
+
static int smfs_remount(struct super_block *sb, int *flags, char *data)
{
- struct super_block *cache_sb;
+ struct super_block *cache_sb = S2CSB(sb);
int rc = 0;
ENTRY;
- cache_sb = S2CSB(sb);
-
- if (!cache_sb)
- RETURN(-EINVAL);
-
- if (cache_sb->s_op->remount_fs)
- rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
+ LASSERT(cache_sb);
+ rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
duplicate_sb(sb, cache_sb);
+
RETURN(rc);
}
+
struct super_operations smfs_super_ops = {
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
.read_inode2 = smfs_read_inode2,
.delete_inode = smfs_delete_inode,
.write_inode = smfs_write_inode,
.dirty_inode = smfs_dirty_inode, /* BKL not held. */
- .put_inode = smfs_put_inode, /* BKL not held. */
.write_super = smfs_write_super, /* BKL held */
.write_super_lockfs = smfs_write_super_lockfs, /* BKL not held. */
.unlockfs = smfs_unlockfs, /* BKL not held. */
.remount_fs = smfs_remount, /* BKL held */
};
-int is_smfs_sb(struct super_block *sb)
-{
- return (sb->s_op->put_super == smfs_super_ops.put_super);
-}
-EXPORT_SYMBOL(is_smfs_sb);
+