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.
25 #include <linux/module.h>
27 #include <linux/namei.h>
28 #include <linux/namespace.h>
29 #include <linux/dcache.h>
30 #include <linux/seq_file.h>
31 #include <linux/pagemap.h>
32 #include <linux/highmem.h>
33 #include <linux/init.h>
34 #include <linux/string.h>
35 #include <linux/smp_lock.h>
36 #include <linux/backing-dev.h>
37 #include <linux/parser.h>
39 #include <asm/uaccess.h>
41 #include <linux/rcfs.h>
43 rbce_eng_callback_t rcfs_eng_callbacks = {
47 int rcfs_register_engine(rbce_eng_callback_t * rcbs)
49 if (!rcbs->mkdir || rcfs_eng_callbacks.mkdir) {
52 rcfs_eng_callbacks = *rcbs;
57 EXPORT_SYMBOL(rcfs_register_engine);
59 int rcfs_unregister_engine(rbce_eng_callback_t * rcbs)
61 if (!rcbs->mkdir || !rcfs_eng_callbacks.mkdir ||
62 (rcbs->mkdir != rcfs_eng_callbacks.mkdir)) {
65 rcfs_eng_callbacks.mkdir = NULL;
66 rcfs_eng_callbacks.rmdir = NULL;
71 EXPORT_SYMBOL(rcfs_unregister_engine);
74 * Create and return a "root" dentry under /rcfs.
75 * Also create associated magic files
77 * @mfdesc: array of rcfs_magf describing root dir and its magic files
78 * @count: number of entries in mfdesc
79 * @core: core class to be associated with root
80 * @rootde: output parameter to return the newly created root dentry
83 int rcfs_mkroot(struct rcfs_magf *mfdesc, int mfcount, struct dentry **rootde)
86 struct rcfs_magf *rootdesc = &mfdesc[0];
87 struct dentry *dentry;
88 struct rcfs_inode_info *rootri;
90 if ((mfcount < 0) || (!mfdesc))
93 rootdesc = &mfdesc[0];
94 printk(KERN_DEBUG "allocating classtype root <%s>\n", rootdesc->name);
95 dentry = rcfs_create_internal(rcfs_rootde, rootdesc, 0);
98 printk(KERN_ERR "Could not create %s\n", rootdesc->name);
102 rootri = RCFS_I(dentry->d_inode);
103 sz = strlen(rootdesc->name) + strlen(RCFS_ROOT) + 2;
104 rootri->name = kmalloc(sz, GFP_KERNEL);
106 printk(KERN_ERR "Error allocating name for %s\n",
108 rcfs_delete_internal(dentry);
111 snprintf(rootri->name, sz, "%s/%s", RCFS_ROOT, rootdesc->name);
114 dentry->d_inode->i_fop = rootdesc->i_fop;
116 dentry->d_inode->i_op = rootdesc->i_op;
118 // set output parameters
124 EXPORT_SYMBOL(rcfs_mkroot);
126 int rcfs_rmroot(struct dentry *rootde)
128 struct rcfs_inode_info *ri;
133 rcfs_clear_magic(rootde);
134 ri = RCFS_I(rootde->d_inode);
137 rcfs_delete_internal(rootde);
141 EXPORT_SYMBOL(rcfs_rmroot);
143 int rcfs_register_classtype(ckrm_classtype_t * clstype)
146 struct rcfs_inode_info *rootri;
147 struct rcfs_magf *mfdesc;
149 // Initialize mfdesc, mfcount
150 clstype->mfdesc = (void *)genmfdesc[clstype->mfidx]->rootmf;
151 clstype->mfcount = genmfdesc[clstype->mfidx]->rootmflen;
153 mfdesc = (struct rcfs_magf *)clstype->mfdesc;
155 /* rcfs root entry has the same name as the classtype */
156 strncpy(mfdesc[0].name, clstype->name, RCFS_MAGF_NAMELEN);
158 rc = rcfs_mkroot(mfdesc, clstype->mfcount,
159 (struct dentry **)&(clstype->rootde));
163 rootri = RCFS_I(((struct dentry *)(clstype->rootde))->d_inode);
164 rootri->core = clstype->default_class;
165 clstype->default_class->name = rootri->name;
166 ckrm_core_grab(clstype->default_class);
168 // Create magic files under root
169 if ((rc = rcfs_create_magic(clstype->rootde, &mfdesc[1],
170 clstype->mfcount - 1))) {
173 rcfs_delete_internal(clstype->rootde);
180 EXPORT_SYMBOL(rcfs_register_classtype);
182 int rcfs_deregister_classtype(ckrm_classtype_t * clstype)
186 rc = rcfs_rmroot((struct dentry *)clstype->rootde);
188 clstype->default_class->name = NULL;
189 ckrm_core_drop(clstype->default_class);
194 EXPORT_SYMBOL(rcfs_deregister_classtype);
196 // Common root and magic file entries.
197 // root name, root permissions, magic file names and magic file permissions
198 // are needed by all entities (classtypes and classification engines) existing
199 // under the rcfs mount point
201 // The common sets of these attributes are listed here as a table. Individual
202 // classtypes and classification engines can simple specify the index into the
203 // table to initialize their magf entries.
206 #ifdef CONFIG_CKRM_TYPE_TASKCLASS
207 extern struct rcfs_mfdesc tc_mfdesc;
210 #ifdef CONFIG_CKRM_TYPE_TASKCLASS
211 extern struct rcfs_mfdesc sock_mfdesc;
214 // extern struct rcfs_magf rbce_mfdesc;
216 struct rcfs_mfdesc *genmfdesc[] = {
217 #ifdef CONFIG_CKRM_TYPE_TASKCLASS
222 #ifdef CONFIG_CKRM_TYPE_SOCKETCLASS