4 * Copyright (C) Vivek Kashyap, IBM Corp. 2004
7 * Functions for creating root directories and magic files
8 * for classtypes and classification engines under rcfs
10 * Latest version, more details at http://ckrm.sf.net
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
26 #include <linux/module.h>
28 #include <linux/namei.h>
29 #include <asm/namei.h>
30 #include <linux/namespace.h>
31 #include <linux/dcache.h>
32 #include <linux/seq_file.h>
33 #include <linux/pagemap.h>
34 #include <linux/highmem.h>
35 #include <linux/init.h>
36 #include <linux/string.h>
37 #include <linux/smp_lock.h>
38 #include <linux/backing-dev.h>
39 #include <linux/parser.h>
41 #include <asm/uaccess.h>
43 #include <linux/rcfs.h>
47 rbce_eng_callback_t rcfs_eng_callbacks = {
52 rcfs_register_engine(rbce_eng_callback_t *rcbs)
54 if (!rcbs->mkdir || rcfs_eng_callbacks.mkdir) {
57 rcfs_eng_callbacks = *rcbs;
60 EXPORT_SYMBOL(rcfs_register_engine);
65 rcfs_unregister_engine(rbce_eng_callback_t *rcbs)
67 if (!rcbs->mkdir || !rcfs_eng_callbacks.mkdir ||
68 (rcbs->mkdir != rcfs_eng_callbacks.mkdir)) {
71 rcfs_eng_callbacks.mkdir = NULL;
72 rcfs_eng_callbacks.rmdir = NULL;
75 EXPORT_SYMBOL(rcfs_unregister_engine);
81 * Create and return a "root" dentry under /rcfs. Also create associated magic files
83 * @mfdesc: array of rcfs_magf describing root dir and its magic files
84 * @count: number of entries in mfdesc
85 * @core: core class to be associated with root
86 * @rootde: output parameter to return the newly created root dentry
90 rcfs_mkroot(struct rcfs_magf *mfdesc, int mfcount, struct dentry **rootde)
93 struct rcfs_magf *rootdesc = &mfdesc[0];
94 struct dentry *dentry ;
95 struct rcfs_inode_info *rootri;
97 if ((mfcount < 0) || (!mfdesc))
100 rootdesc = &mfdesc[0];
101 printk("allocating classtype root <%s>\n",rootdesc->name);
102 dentry = rcfs_create_internal(rcfs_rootde, rootdesc,0);
105 printk(KERN_ERR "Could not create %s\n",rootdesc->name);
109 rootri = RCFS_I(dentry->d_inode);
110 sz = strlen(rootdesc->name) + strlen(RCFS_ROOT) + 2;
111 rootri->name = kmalloc(sz, GFP_KERNEL);
113 printk(KERN_ERR "Error allocating name for %s\n",
115 rcfs_delete_internal(dentry);
118 snprintf(rootri->name,sz,"%s/%s",RCFS_ROOT,rootdesc->name);
121 dentry->d_inode->i_fop = rootdesc->i_fop;
123 dentry->d_inode->i_op = rootdesc->i_op;
125 // set output parameters
130 EXPORT_SYMBOL(rcfs_mkroot);
134 rcfs_rmroot(struct dentry *rootde)
139 rcfs_clear_magic(rootde);
140 kfree(RCFS_I(rootde->d_inode)->name);
141 rcfs_delete_internal(rootde);
144 EXPORT_SYMBOL(rcfs_rmroot);
148 rcfs_register_classtype(ckrm_classtype_t *clstype)
151 struct rcfs_inode_info *rootri;
152 struct rcfs_magf *mfdesc;
154 // Initialize mfdesc, mfcount
155 clstype->mfdesc = (void *) genmfdesc[clstype->mfidx]->rootmf;
156 clstype->mfcount = genmfdesc[clstype->mfidx]->rootmflen;
158 mfdesc = (struct rcfs_magf *)clstype->mfdesc;
160 /* rcfs root entry has the same name as the classtype */
161 strncpy(mfdesc[0].name,clstype->name,RCFS_MAGF_NAMELEN) ;
163 rc = rcfs_mkroot(mfdesc,clstype->mfcount,
164 (struct dentry **)&(clstype->rootde));
168 rootri = RCFS_I(((struct dentry *)(clstype->rootde))->d_inode);
169 rootri->core = clstype->default_class;
170 clstype->default_class->name = rootri->name;
171 ckrm_core_grab(clstype->default_class);
173 // Create magic files under root
174 if ((rc = rcfs_create_magic(clstype->rootde, &mfdesc[1],
175 clstype->mfcount-1))) {
177 rcfs_delete_internal(clstype->rootde);
183 EXPORT_SYMBOL(rcfs_register_classtype);
187 rcfs_deregister_classtype(ckrm_classtype_t *clstype)
191 rc = rcfs_rmroot((struct dentry *)clstype->rootde);
193 clstype->default_class->name = NULL ;
194 ckrm_core_drop(clstype->default_class);
198 EXPORT_SYMBOL(rcfs_deregister_classtype);
202 // Common root and magic file entries.
203 // root name, root permissions, magic file names and magic file permissions are needed by
204 // all entities (classtypes and classification engines) existing under the rcfs mount point
206 // The common sets of these attributes are listed here as a table. Individual classtypes and
207 // classification engines can simple specify the index into the table to initialize their
211 #ifdef CONFIG_CKRM_TYPE_TASKCLASS
212 extern struct rcfs_mfdesc tc_mfdesc;
215 #ifdef CONFIG_CKRM_TYPE_TASKCLASS
216 extern struct rcfs_mfdesc sock_mfdesc;
219 // extern struct rcfs_magf rbce_mfdesc;
222 struct rcfs_mfdesc *genmfdesc[]={
223 #ifdef CONFIG_CKRM_TYPE_TASKCLASS
228 #ifdef CONFIG_CKRM_TYPE_SOCKETCLASS
233 // Create similar entry for RBCE ?
234 //#ifdef CONFIG_CKRM_CE