Register classtype (CKRM RCFS rewrite)

Functions to register/deregister classtypes with RCFS. These lead to creation of 
classtype specific directories and virtual files etc. Move the functions to inode.c

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

 fs/rcfs/inode.c      |  105 +++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/rcfs/rootdir.c    |   85 -----------------------------------------
 include/linux/rcfs.h |    9 ++--
 3 files changed, 111 insertions(+), 88 deletions(-)

Index: linux-2.6.12/fs/rcfs/inode.c
===================================================================
--- linux-2.6.12.orig/fs/rcfs/inode.c	2005-08-09 15:30:39.434905704 -0400
+++ linux-2.6.12/fs/rcfs/inode.c	2005-08-09 15:30:39.508894456 -0400
@@ -532,6 +532,102 @@ out_files:
 	return (PTR_ERR(dentry));
 }
 
+/******************************
+ *
+ * Classtypes
+ *
+ ******************************/
+
+/* Common root and virtual file entries.
+ * root name, root permissions, virtual file names and virtual file permissions
+ * are needed by all entities (classtypes and classification engines) existing
+ * under the rcfs mount point
+ *
+ * The common sets of these attributes are listed here as a table. Individual
+ * classtypes and classification engines can simple specify the index into the
+ * table to initialize their magf entries.
+ */
+
+struct rcfs_mfdesc *genmfdesc[CKRM_MAX_CLASSTYPES] = {
+	NULL,
+	NULL,
+};
+
+int rcfs_register_classtype(struct ckrm_classtype *clstype)
+{
+	int rc,rc2;
+	struct rcfs_inode_info *ri;
+	struct rcfs_magf *mfdesc;
+
+	if (genmfdesc[clstype->mfidx] == NULL) {
+		return -EINVAL;
+	}
+
+	clstype->mfdesc = (void *)genmfdesc[clstype->mfidx]->rootmf;
+	clstype->mfcount = genmfdesc[clstype->mfidx]->rootmflen;
+
+	mfdesc = (struct rcfs_magf *)clstype->mfdesc;
+
+	/* Directory name same as classtype's */
+	strncpy(mfdesc->name, clstype->name, RCFS_MAGF_NAMELEN);
+
+	clstype->rootde = rcfs_create_file(mfdesc->name, mfdesc->mode,
+					   rcfs_root_dentry, mfdesc->i_fop,
+					   mfdesc->i_op, NULL);
+	if (IS_ERR(clstype->rootde))
+		return PTR_ERR(clstype->rootde);
+
+	rc = rcfs_name(rcfs_root_dentry, ((struct dentry *)clstype->rootde)->d_inode, mfdesc->name);
+	if (rc)
+		goto out_name;
+
+	ri = rcfs_get_inode_info(((struct dentry *)clstype->rootde)->d_inode);
+	ri->core = clstype->default_class;
+	clstype->default_class->name = ri->name;
+	ckrm_core_grab(clstype->default_class);
+
+	/* Create magic files under root */
+	rc = rcfs_create_virtual(clstype->rootde, &mfdesc[1], clstype->mfcount - 1);
+	if (rc)
+		goto out_magic;
+
+	return rc;
+
+out_magic:
+	kfree(ri->name);
+out_name:
+	rc2 = rcfs_destroy_file(clstype->rootde);
+	if (rc2)
+		err("Failed file destroy %d on bailout\n",rc2);
+	return rc;
+}
+
+int rcfs_deregister_classtype(struct ckrm_classtype * clstype)
+{
+	int rc;
+	struct rcfs_inode_info *ri;
+
+	rc = rcfs_destroy_virtual(clstype->rootde);
+	if (rc) {
+		err("Magic file destroy failed %d\n", rc);
+		goto out;
+	}
+
+	ri = rcfs_get_inode_info(((struct dentry *)clstype->rootde)->d_inode);
+	kfree(ri->name);
+
+	rc = rcfs_destroy_file(clstype->rootde);
+	if (rc) {
+		err("Failed file destroy %d on bailout\n",rc);
+		goto out;
+	}
+
+	clstype->default_class->name = NULL;
+	ckrm_core_drop(clstype->default_class);
+
+out:
+	return rc;
+}
 
 
 static struct file_system_type rcfs_fs_type = {
@@ -541,6 +637,13 @@ static struct file_system_type rcfs_fs_t
 	.kill_sb =	rcfs_kill_sb,
 };
 
+struct rcfs_functions my_rcfs_fn = {
+	.register_classtype = rcfs_register_classtype,
+	.deregister_classtype = rcfs_deregister_classtype,
+};
+
+extern struct rcfs_functions rcfs_fn;
+
 static int __init init_rcfs_fs(void)
 {
 	int ret;
@@ -553,6 +656,8 @@ static int __init init_rcfs_fs(void)
 	if (ret)
 		goto out_register;
 
+	rcfs_fn = my_rcfs_fn ;
+
 	/*
 	 * Due to tight coupling of this module with ckrm
 	 * do not allow this module to be removed.
Index: linux-2.6.12/fs/rcfs/rootdir.c
===================================================================
--- linux-2.6.12.orig/fs/rcfs/rootdir.c	2005-08-09 15:30:39.434905704 -0400
+++ linux-2.6.12/fs/rcfs/rootdir.c	2005-08-09 15:30:39.508894456 -0400
@@ -60,88 +60,3 @@ int rcfs_unregister_engine(struct rbce_e
 
 EXPORT_SYMBOL_GPL(rcfs_unregister_engine);
 
-int rcfs_register_classtype(struct ckrm_classtype * clstype)
-{
-	int rc;
-	struct rcfs_inode_info *rootri;
-	struct rcfs_magf *mfdesc;
-
-	if (genmfdesc[clstype->mfidx] == NULL) {
-		return -ENOMEM;
-	}
-
-	clstype->mfdesc = (void *)genmfdesc[clstype->mfidx]->rootmf;
-	clstype->mfcount = genmfdesc[clstype->mfidx]->rootmflen;
-
-	mfdesc = (struct rcfs_magf *)clstype->mfdesc;
-
-	/* rcfs root entry has the same name as the classtype */
-	strncpy(mfdesc[0].name, clstype->name, RCFS_MAGF_NAMELEN);
-
-	rc = rcfs_mkroot(mfdesc, clstype->mfcount,
-			 (struct dentry **)&(clstype->rootde));
-	if (rc)
-		return rc;
-	rootri = rcfs_get_inode_info(((struct dentry *)(clstype->rootde))->d_inode);
-	rootri->core = clstype->default_class;
-	clstype->default_class->name = rootri->name;
-	ckrm_core_grab(clstype->default_class);
-
-	/* Create magic files under root */
-	if ((rc = rcfs_create_magic(clstype->rootde, &mfdesc[1],
-				    clstype->mfcount - 1))) {
-		kfree(rootri->name);
-		rootri->name = NULL;
-		rcfs_delete_internal(clstype->rootde);
-		return rc;
-	}
-	return rc;
-}
-
-EXPORT_SYMBOL_GPL(rcfs_register_classtype);
-
-int rcfs_deregister_classtype(struct ckrm_classtype * clstype)
-{
-	int rc;
-
-	rc = rcfs_rmroot((struct dentry *)clstype->rootde);
-	if (!rc) {
-		clstype->default_class->name = NULL;
-		ckrm_core_drop(clstype->default_class);
-	}
-	return rc;
-}
-
-EXPORT_SYMBOL_GPL(rcfs_deregister_classtype);
-
-#ifdef CONFIG_CKRM_TYPE_TASKCLASS
-extern struct rcfs_mfdesc tc_mfdesc;
-#endif
-
-#ifdef CONFIG_CKRM_TYPE_SOCKETCLASS
-extern struct rcfs_mfdesc rcfs_sock_mfdesc;
-#endif
-
-/* Common root and magic file entries.
- * root name, root permissions, magic file names and magic file permissions
- * are needed by all entities (classtypes and classification engines) existing
- * under the rcfs mount point
- *
- * The common sets of these attributes are listed here as a table. Individual
- * classtypes and classification engines can simple specify the index into the
- * table to initialize their magf entries.
- */
-
-struct rcfs_mfdesc *genmfdesc[CKRM_MAX_CLASSTYPES] = {
-#ifdef CONFIG_CKRM_TYPE_TASKCLASS
-	&tc_mfdesc,
-#else
-	NULL,
-#endif
-#ifdef CONFIG_CKRM_TYPE_SOCKETCLASS
-	&rcfs_sock_mfdesc,
-#else
-	NULL,
-#endif
-
-};
Index: linux-2.6.12/include/linux/rcfs.h
===================================================================
--- linux-2.6.12.orig/include/linux/rcfs.h	2005-08-09 15:30:39.434905704 -0400
+++ linux-2.6.12/include/linux/rcfs.h	2005-08-09 15:30:39.508894456 -0400
@@ -72,13 +72,16 @@ extern struct file_operations members_fi
 extern struct file_operations reclassify_fileops;
 extern struct file_operations rcfs_file_operations;
 
-int rcfs_register_classtype(struct ckrm_classtype *);
-int rcfs_deregister_classtype(struct ckrm_classtype *);
-
 #define RCFS_ROOT "/rcfs"  	/* TODO:  Should use the mount point */
 extern struct dentry *rcfs_rootde;
 extern struct rbce_eng_callback rcfs_eng_callbacks;
 
+/* Callbacks into rcfs from ckrm */
+struct rcfs_functions {
+	int (*register_classtype) (struct ckrm_classtype *);
+	int (*deregister_classtype) (struct ckrm_classtype *);
+};
+
 /* Helper functions */
 extern int rcfs_mkdir(struct inode *, struct dentry *, int);
 extern int rcfs_rmdir(struct inode *, struct dentry *);

Reply via email to