Superblock operations (CKRM RCFS rewrite)

Move functions for creating/filling the RCFS superblock to inode.c. 
fill_super depends on  functionality introduced in patches earlier in the series. 

Signed-off-by: Shailabh Nagar <[EMAIL PROTECTED]>

 fs/rcfs/super.c      |  185 ---------------------------------------------------
 fs/rcfs/inode.c      |  151 +++++++++++++++++++++++++++++++++++++++++
 include/linux/rcfs.h |    2 
 3 files changed, 152 insertions(+), 186 deletions(-)

Index: linux-2.6.12/fs/rcfs/inode.c
===================================================================
--- linux-2.6.12.orig/fs/rcfs/inode.c	2005-08-09 15:30:41.580579512 -0400
+++ linux-2.6.12/fs/rcfs/inode.c	2005-08-09 15:30:41.655568112 -0400
@@ -665,6 +665,157 @@ int rcfs_unregister_engine(struct rbce_e
 EXPORT_SYMBOL_GPL(rcfs_unregister_engine);
 
 
+/*******************************
+ *
+ * Superblock, fs initialization
+ *
+ *******************************/
+
+static int rcfs_mount_count;
+struct dentry *rcfs_root_dentry;
+
+struct super_operations rcfs_super_ops = {
+	.alloc_inode = rcfs_alloc_inode,
+	.destroy_inode = rcfs_destroy_inode,
+	.statfs = simple_statfs,
+	.drop_inode = generic_delete_inode,
+};
+
+static int rcfs_fill_super(struct super_block *sb, void *data, int silent)
+{
+	struct inode *inode;
+	struct dentry *root;
+	struct rcfs_inode_info *sbi;
+	int rc, ret, sz, i;
+	struct ckrm_classtype *clstype;
+
+
+	/* Prevent repeat mounts */
+	if (rcfs_mount_count) {
+		return -EPERM;
+	}
+	rcfs_mount_count++;
+
+
+	/* Standard fs requirements */
+	sb->s_blocksize = PAGE_CACHE_SIZE;
+	sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
+	sb->s_magic = RCFS_MAGIC;
+	sb->s_op = &rcfs_super_ops;
+	sb->s_time_gran = 1;
+
+	/* Get root inode */
+	rc = -ENOMEM;
+	inode = rcfs_get_inode(sb, S_IFDIR | 0755, 0);
+	if (!inode)
+		goto out;
+
+	sbi = rcfs_get_inode_info(inode);
+	sb->s_fs_info = sbi;
+
+	/* Fill inode_info */
+	sz  = strlen(RCFS_ROOT) + 1;
+	sbi->name = kmalloc(sz, GFP_KERNEL);
+	if (!sbi->name)
+	    goto out_inode;
+
+	strncpy(sbi->name, RCFS_ROOT, sz);
+	sbi->core = NULL;
+
+	root = d_alloc_root(inode);
+	if (!root)
+		goto out_sbi;
+
+	sb->s_root = root;
+	rcfs_root_dentry = root;
+
+	/* Register classtypes */
+	for (i = 0; i < CKRM_MAX_CLASSTYPES; i++) {
+		clstype = ckrm_classtypes[i];
+		if (clstype == NULL)
+			continue;
+		if ((rc = rcfs_register_classtype(clstype))) {
+			err("classtype %s regn failed", clstype->name);
+			goto out_classtype;
+		}
+	}
+
+	/* Register classification engine */
+	if (rcfs_engine_regd) {
+		if (rcfs_eng_callbacks.mnt)
+			if ((rc = (*rcfs_eng_callbacks.mnt) ())) {
+				err("Error in CE mnt %d\n", rc);
+				goto out_classtype;
+			}
+	}
+
+	return 0;
+
+out_classtype:
+
+	for (--i ; i >= 0; i--) {
+		clstype = ckrm_classtypes[i];
+		if (clstype == NULL || clstype->rootde == NULL)
+			continue;
+		if ((ret = rcfs_deregister_classtype(clstype))) {
+			err("classtype %s dereg failed", clstype->name);
+			rc = ret;
+		}
+	}
+
+	kfree(sbi->name);
+	dput(root);
+	sb->s_root = NULL;
+	sb->s_fs_info = NULL;
+	return rc;
+
+out_sbi:
+	kfree(sbi->name);
+out_inode:
+	sb->s_fs_info = NULL;
+	iput(inode);
+out:
+	return rc;
+}
+
+
+static struct super_block *rcfs_get_sb(struct file_system_type *fs_type,
+				       int flags, const char *dev_name,
+				       void *data)
+{
+	return get_sb_nodev(fs_type, flags, data, rcfs_fill_super);
+}
+
+static void rcfs_kill_sb(struct super_block *sb)
+{
+	int i, rc;
+	struct ckrm_classtype *clstype;
+
+	rcfs_mount_count--;
+
+	for (i = 0; i < CKRM_MAX_CLASSTYPES; i++) {
+		clstype = ckrm_classtypes[i];
+		if (clstype == NULL || clstype->rootde == NULL)
+			continue;
+
+		if ((rcfs_deregister_classtype(clstype)))
+			err("classtype %s dereg failed", clstype->name);
+	}
+
+	/*
+	 * do pre-umount shutdown needed by CE
+	 * this is distinct from CE deregistration done on rcfs module unload
+	 */
+	if (rcfs_engine_regd) {
+		if (rcfs_eng_callbacks.umnt)
+			if ((rc = (*rcfs_eng_callbacks.umnt) ())) {
+				err("Error in CE umnt %d\n", rc);
+			}
+	}
+	/* sbi will be deleted through destroy_inode of root inode */
+	generic_shutdown_super(sb);
+}
+
 static struct file_system_type rcfs_fs_type = {
 	.owner =	THIS_MODULE,
 	.name =		"rcfs",
Index: linux-2.6.12/fs/rcfs/super.c
===================================================================
--- linux-2.6.12.orig/fs/rcfs/super.c	2005-08-09 15:30:41.580579512 -0400
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,185 +0,0 @@
-/*
- * fs/rcfs/super.c
- *
- * Copyright (C) Shailabh Nagar,  IBM Corp. 2004
- *		 Vivek Kashyap,   IBM Corp. 2004
- *
- * Super block operations for rcfs
- *
- *
- * Latest version, more details at http://ckrm.sf.net
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-#include <linux/module.h>
-#include <linux/fs.h>
-#include <linux/namei.h>
-#include <linux/namespace.h>
-#include <linux/dcache.h>
-#include <linux/seq_file.h>
-#include <linux/pagemap.h>
-#include <linux/highmem.h>
-#include <linux/init.h>
-#include <linux/string.h>
-#include <linux/smp_lock.h>
-#include <linux/backing-dev.h>
-#include <linux/parser.h>
-#include <linux/rcfs.h>
-#include <linux/ckrm_rc.h>
-#include <linux/ckrm_ce.h>
-#include <asm/uaccess.h>
-
-struct super_operations rcfs_super_ops = {
-	.alloc_inode = rcfs_alloc_inode,
-	.destroy_inode = rcfs_destroy_inode,
-	.statfs = simple_statfs,
-	.drop_inode = generic_delete_inode,
-};
-
-struct dentry *rcfs_rootde;	/* redundant; can also get it from sb */
-static struct inode *rcfs_root;
-static struct rcfs_inode_info *rcfs_rootri;
-
-static int rcfs_fill_super(struct super_block *sb, void *data, int silent)
-{
-	struct inode *inode;
-	struct dentry *root;
-	struct rcfs_inode_info *rootri;
-	struct ckrm_classtype *clstype;
-	int i, rc;
-
-	sb->s_fs_info = NULL;
-	if (rcfs_mounted) {
-		return -EPERM;
-	}
-	rcfs_mounted++;
-
-	sb->s_blocksize = PAGE_CACHE_SIZE;
-	sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
-	sb->s_magic = RCFS_MAGIC;
-	sb->s_op = &rcfs_super_ops;
-	inode = rcfs_get_inode(sb, S_IFDIR | 0755, 0);
-	if (!inode)
-		return -ENOMEM;
-	inode->i_op = &rcfs_rootdir_inode_operations;
-
-	root = d_alloc_root(inode);
-	if (!root) {
-		iput(inode);
-		return -ENOMEM;
-	}
-	sb->s_root = root;
-
-	/* Link inode and core class */
-	rootri = rcfs_get_inode_info(inode);
-	rootri->name = kmalloc(strlen(RCFS_ROOT) + 1, GFP_KERNEL);
-	if (!rootri->name) {
-		d_delete(root);
-		iput(inode);
-		return -ENOMEM;
-	}
-	strcpy(rootri->name, RCFS_ROOT);
-	rootri->core = NULL;
-
-	rcfs_root = inode;
-	sb->s_fs_info = rcfs_root = inode;
-	rcfs_rootde = root;
-	rcfs_rootri = rootri;
-
-	/* register metatypes */
-	for (i = 0; i < CKRM_MAX_CLASSTYPES; i++) {
-		clstype = ckrm_classtypes[i];
-		if (clstype == NULL)
-			continue;
-		printk("A non null classtype\n");
-
-		if ((rc = rcfs_register_classtype(clstype)))
-			continue;	/* could return with an error too */
-	}
-
-	/*
-	 * do post-mount initializations needed by CE
-	 * this is distinct from CE registration done on rcfs module load
-	 */
-	if (rcfs_engine_regd) {
-		if (rcfs_eng_callbacks.mnt)
-			if ((rc = (*rcfs_eng_callbacks.mnt) ())) {
-				printk(KERN_ERR "Error in CE mnt %d\n", rc);
-			}
-	}
-	/*
-	 * Following comment handled by code above; keep nonetheless if it
-	 * can be done better
-	 *
-	 * register CE's with rcfs
-	 * check if CE loaded
-	 * call rcfs_register_engine for each classtype
-	 * AND rcfs_mkroot (preferably subsume latter in former)
-	 */
-	return 0;
-}
-
-static struct super_block *rcfs_get_sb(struct file_system_type *fs_type,
-				       int flags, const char *dev_name,
-				       void *data)
-{
-	return get_sb_nodev(fs_type, flags, data, rcfs_fill_super);
-}
-
-void rcfs_kill_sb(struct super_block *sb)
-{
-	int i, rc;
-	struct ckrm_classtype *clstype;
-
-	if (sb->s_fs_info != rcfs_root) {
-		generic_shutdown_super(sb);
-		return;
-	}
-	rcfs_mounted--;
-
-	for (i = 0; i < CKRM_MAX_CLASSTYPES; i++) {
-		clstype = ckrm_classtypes[i];
-		if (clstype == NULL || clstype->rootde == NULL)
-			continue;
-
-		if ((rc = rcfs_deregister_classtype(clstype))) {
-			printk(KERN_ERR "Error removing classtype %s\n",
-			       clstype->name);
-		}
-	}
-
-	/*
-	 * do pre-umount shutdown needed by CE
-	 * this is distinct from CE deregistration done on rcfs module unload
-	 */
-	if (rcfs_engine_regd) {
-		if (rcfs_eng_callbacks.umnt)
-			if ((rc = (*rcfs_eng_callbacks.umnt) ())) {
-				printk(KERN_ERR "Error in CE umnt %d\n", rc);
-				/* TODO: return ; until error handling improves */
-			}
-	}
-	/*
-	 * Following comment handled by code above; keep nonetheless if it
-	 * can be done better
-	 *
-	 * deregister CE with rcfs
-	 * Check if loaded
-	 * if ce is in  one directory /rcfs/ce,
-	 *       rcfs_deregister_engine for all classtypes within above
-	 *             codebase
-	 *       followed by
-	 *       rcfs_rmroot here
-	 * if ce in multiple (per-classtype) directories
-	 *       call rbce_deregister_engine within ckrm_deregister_classtype
-	 *
-	 * following will automatically clear rcfs root entry including its
-	 *  rcfs_inode_info
-	 */
-
-	generic_shutdown_super(sb);
-}
-
Index: linux-2.6.12/include/linux/rcfs.h
===================================================================
--- linux-2.6.12.orig/include/linux/rcfs.h	2005-08-09 15:30:41.580579512 -0400
+++ linux-2.6.12/include/linux/rcfs.h	2005-08-09 15:30:41.655568112 -0400
@@ -73,7 +73,7 @@ extern struct file_operations reclassify
 extern struct file_operations rcfs_file_operations;
 
 #define RCFS_ROOT "/rcfs"  	/* TODO:  Should use the mount point */
-extern struct dentry *rcfs_rootde;
+extern struct dentry *rcfs_root_dentry;
 extern struct rbce_eng_callback rcfs_eng_callbacks;
 
 /* Callbacks into rcfs from ckrm */

Reply via email to