3 * Copyright (C) Vivek Kashyap, IBM Corp. 2004
5 * Latest version, more details at http://ckrm.sf.net
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
18 /*******************************************************************************
21 * Defines the root structure for socket based classes. Currently only inbound
22 * connection control is supported based on prioritized accept queues.
23 ******************************************************************************/
26 #include <linux/rcfs.h>
29 extern int rcfs_create(struct inode *,struct dentry *, int, struct nameidata *);
30 extern int rcfs_unlink(struct inode *, struct dentry *);
31 extern int rcfs_symlink(struct inode *, struct dentry *, const char *);
32 extern int rcfs_mknod(struct inode *, struct dentry *, int mode, dev_t);
33 extern int rcfs_mkdir(struct inode *, struct dentry *, int);
34 extern int rcfs_rmdir(struct inode *, struct dentry *);
35 extern int rcfs_rename(struct inode *, struct dentry *, struct inode *,
38 extern int rcfs_create_coredir(struct inode *, struct dentry *);
39 int sock_mkdir(struct inode *, struct dentry *, int mode);
40 int sock_rmdir(struct inode *, struct dentry *);
43 int sock_create_noperm(struct inode *, struct dentry *,int, struct nameidata *);
44 int sock_unlink_noperm(struct inode *,struct dentry *);
45 int sock_mkdir_noperm(struct inode *,struct dentry *,int);
46 int sock_rmdir_noperm(struct inode *,struct dentry *);
47 int sock_mknod_noperm(struct inode *,struct dentry *,int, dev_t);
49 void sock_set_directory(void);
51 extern struct file_operations config_fileops,
58 struct inode_operations my_iops = {
59 .create = rcfs_create,
60 .lookup = simple_lookup,
62 .unlink = rcfs_unlink,
63 .symlink = rcfs_symlink,
67 .rename = rcfs_rename,
70 struct inode_operations class_iops = {
71 .create = sock_create_noperm,
72 .lookup = simple_lookup,
74 .unlink = sock_unlink_noperm,
75 .symlink = rcfs_symlink,
76 .mkdir = sock_mkdir_noperm,
77 .rmdir = sock_rmdir_noperm,
78 .mknod = sock_mknod_noperm,
79 .rename = rcfs_rename,
82 struct inode_operations sub_iops = {
83 .create = sock_create_noperm,
84 .lookup = simple_lookup,
86 .unlink = sock_unlink_noperm,
87 .symlink = rcfs_symlink,
88 .mkdir = sock_mkdir_noperm,
89 .rmdir = sock_rmdir_noperm,
90 .mknod = sock_mknod_noperm,
91 .rename = rcfs_rename,
94 struct rcfs_magf def_magf = {
95 .mode = RCFS_DEFAULT_DIR_MODE,
100 struct rcfs_magf sock_rootdesc[] = {
102 // .name = should not be set, copy from classtype name,
103 .mode = RCFS_DEFAULT_DIR_MODE,
105 //.i_fop = &simple_dir_operations,
110 .mode = RCFS_DEFAULT_FILE_MODE,
112 .i_fop = &members_fileops,
116 .mode = RCFS_DEFAULT_FILE_MODE,
118 .i_fop = &target_fileops,
122 struct rcfs_magf sock_magf[] = {
125 .mode = RCFS_DEFAULT_FILE_MODE,
127 .i_fop = &config_fileops,
131 .mode = RCFS_DEFAULT_FILE_MODE,
133 .i_fop =&members_fileops,
137 .mode = RCFS_DEFAULT_FILE_MODE,
139 .i_fop = &shares_fileops,
143 .mode = RCFS_DEFAULT_FILE_MODE,
145 .i_fop = &stats_fileops,
149 .mode = RCFS_DEFAULT_FILE_MODE,
151 .i_fop = &target_fileops,
155 struct rcfs_magf sub_magf[] = {
158 .mode = RCFS_DEFAULT_FILE_MODE,
160 .i_fop = &config_fileops,
164 .mode = RCFS_DEFAULT_FILE_MODE,
166 .i_fop = &shares_fileops,
170 .mode = RCFS_DEFAULT_FILE_MODE,
172 .i_fop = &stats_fileops,
176 struct rcfs_mfdesc sock_mfdesc = {
177 .rootmf = sock_rootdesc,
178 .rootmflen = (sizeof(sock_rootdesc)/sizeof(struct rcfs_magf)),
182 #define SOCK_MAX_MAGF (sizeof(sock_magf)/sizeof(struct rcfs_magf))
183 #define LAQ_MAX_SUBMAGF (sizeof(sub_magf)/sizeof(struct rcfs_magf))
186 sock_rmdir(struct inode *p, struct dentry *me)
188 struct dentry *mftmp, *mfdentry ;
190 // delete all magic sub directories
191 list_for_each_entry_safe(mfdentry, mftmp, &me->d_subdirs, d_child) {
192 if (S_ISDIR(mfdentry->d_inode->i_mode))
193 rcfs_rmdir(me->d_inode, mfdentry);
201 #ifdef NUM_ACCEPT_QUEUES
202 #define LAQ_NUM_ACCEPT_QUEUES NUM_ACCEPT_QUEUES
204 #define LAQ_NUM_ACCEPT_QUEUES 0
208 sock_mkdir(struct inode *dir, struct dentry *dentry, int mode)
212 struct dentry *pentry, *mfdentry;
214 if (_rcfs_mknod(dir, dentry, mode | S_IFDIR, 0)) {
215 printk(KERN_ERR "rcfs_mkdir: error reaching parent\n");
219 // Needed if only _rcfs_mknod is used instead of i_op->mkdir
222 retval = rcfs_create_coredir(dir, dentry);
226 /* create the default set of magic files */
227 for (i =0; i < SOCK_MAX_MAGF; i++) {
228 mfdentry = rcfs_create_internal(dentry, &sock_magf[i],0);
229 mfdentry->d_fsdata = &RCFS_IS_MAGIC;
230 RCFS_I(mfdentry->d_inode)->core =
231 RCFS_I(dentry->d_inode)->core;
232 if (sock_magf[i].i_fop)
233 mfdentry->d_inode->i_fop = sock_magf[i].i_fop;
234 if (sock_magf[i].i_op)
235 mfdentry->d_inode->i_op = sock_magf[i].i_op;
238 for (i=1; i < LAQ_NUM_ACCEPT_QUEUES; i++) {
239 j = sprintf(def_magf.name, "%d",i);
240 def_magf.name[j] = '\0';
242 pentry = rcfs_create_internal(dentry, &def_magf,0);
243 retval = rcfs_create_coredir(dentry->d_inode, pentry);
246 for (j=0; j < LAQ_MAX_SUBMAGF; j++) {
247 mfdentry = rcfs_create_internal(pentry, &sub_magf[j],0);
248 mfdentry->d_fsdata = &RCFS_IS_MAGIC;
249 RCFS_I(mfdentry->d_inode)->core =
250 RCFS_I(pentry->d_inode)->core;
251 if (sub_magf[j].i_fop)
252 mfdentry->d_inode->i_fop = sub_magf[j].i_fop;
253 if (sub_magf[j].i_op)
254 mfdentry->d_inode->i_op = sub_magf[j].i_op;
256 pentry->d_inode->i_op = &sub_iops;
258 dentry->d_inode->i_op = &class_iops;
266 #ifndef NUM_ACCEPT_QUEUES
267 #define NUM_ACCEPT_QUEUES 0
271 sock_get_name(struct ckrm_core_class *c)
273 char *p = (char *)c->name;
277 while( *p != '/' && p != c->name)
284 sock_create_noperm(struct inode *dir,struct dentry *dentry,int mode, struct nameidata *nd)
290 sock_unlink_noperm(struct inode *dir,struct dentry *dentry)
296 sock_mkdir_noperm(struct inode *dir,struct dentry *dentry, int mode)
302 sock_rmdir_noperm(struct inode *dir,struct dentry *dentry)
308 sock_mknod_noperm(struct inode *dir,struct dentry *dentry,int mode, dev_t dev)
317 struct dentry *pentry, *dentry;
319 pentry = rcfs_set_magf_byname("listen_aq", (void *)&my_dir_magf[0]);
321 dentry = rcfs_create_internal(pentry, &my_dir_magf[1],0);
322 if (my_dir_magf[1].i_fop)
323 dentry->d_inode->i_fop = my_dir_magf[1].i_fop;
324 RCFS_I(dentry->d_inode)->core =
325 RCFS_I(pentry->d_inode)->core;
326 dentry = rcfs_create_internal(pentry, &my_dir_magf[2],0);
327 if (my_dir_magf[2].i_fop)
328 dentry->d_inode->i_fop = my_dir_magf[2].i_fop;
329 RCFS_I(dentry->d_inode)->core =
330 RCFS_I(pentry->d_inode)->core;
333 printk(KERN_ERR "Could not create /rcfs/listen_aq\n"
334 "Perhaps /rcfs needs to be mounted\n");