This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / fs / rcfs / socket_fs.c
1 /* ckrm_socketaq.c 
2  *
3  * Copyright (C) Vivek Kashyap,      IBM Corp. 2004
4  * 
5  * Latest version, more details at http://ckrm.sf.net
6  * 
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.
11  *
12  */
13
14 /* Changes
15  * Initial version
16  */
17
18 /*******************************************************************************
19  *  Socket class type
20  *   
21  * Defines the root structure for socket based classes. Currently only inbound
22  * connection control is supported based on prioritized accept queues. 
23  ******************************************************************************/
24
25 #include <linux/rcfs.h>
26 #include <net/tcp.h>
27
28 extern int rcfs_create(struct inode *, struct dentry *, int,
29                        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 *,
36                        struct dentry *);
37
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 *);
41
42 int sock_create_noperm(struct inode *, struct dentry *, int,
43                        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);
48
49 void sock_set_directory(void);
50
51 extern struct file_operations config_fileops,
52     members_fileops, shares_fileops, stats_fileops, target_fileops;
53
54 struct inode_operations my_iops = {
55         .create = rcfs_create,
56         .lookup = simple_lookup,
57         .link = simple_link,
58         .unlink = rcfs_unlink,
59         .symlink = rcfs_symlink,
60         .mkdir = sock_mkdir,
61         .rmdir = sock_rmdir,
62         .mknod = rcfs_mknod,
63         .rename = rcfs_rename,
64 };
65
66 struct inode_operations class_iops = {
67         .create = sock_create_noperm,
68         .lookup = simple_lookup,
69         .link = simple_link,
70         .unlink = sock_unlink_noperm,
71         .symlink = rcfs_symlink,
72         .mkdir = sock_mkdir_noperm,
73         .rmdir = sock_rmdir_noperm,
74         .mknod = sock_mknod_noperm,
75         .rename = rcfs_rename,
76 };
77
78 struct inode_operations sub_iops = {
79         .create = sock_create_noperm,
80         .lookup = simple_lookup,
81         .link = simple_link,
82         .unlink = sock_unlink_noperm,
83         .symlink = rcfs_symlink,
84         .mkdir = sock_mkdir_noperm,
85         .rmdir = sock_rmdir_noperm,
86         .mknod = sock_mknod_noperm,
87         .rename = rcfs_rename,
88 };
89
90 struct rcfs_magf def_magf = {
91         .mode = RCFS_DEFAULT_DIR_MODE,
92         .i_op = &sub_iops,
93         .i_fop = NULL,
94 };
95
96 struct rcfs_magf sock_rootdesc[] = {
97         {
98          //      .name = should not be set, copy from classtype name,
99          .mode = RCFS_DEFAULT_DIR_MODE,
100          .i_op = &my_iops,
101          //.i_fop   = &simple_dir_operations,
102          .i_fop = NULL,
103          },
104         {
105          .name = "members",
106          .mode = RCFS_DEFAULT_FILE_MODE,
107          .i_op = &my_iops,
108          .i_fop = &members_fileops,
109          },
110         {
111          .name = "target",
112          .mode = RCFS_DEFAULT_FILE_MODE,
113          .i_op = &my_iops,
114          .i_fop = &target_fileops,
115          },
116 };
117
118 struct rcfs_magf sock_magf[] = {
119         {
120          .name = "config",
121          .mode = RCFS_DEFAULT_FILE_MODE,
122          .i_op = &my_iops,
123          .i_fop = &config_fileops,
124          },
125         {
126          .name = "members",
127          .mode = RCFS_DEFAULT_FILE_MODE,
128          .i_op = &my_iops,
129          .i_fop = &members_fileops,
130          },
131         {
132          .name = "shares",
133          .mode = RCFS_DEFAULT_FILE_MODE,
134          .i_op = &my_iops,
135          .i_fop = &shares_fileops,
136          },
137         {
138          .name = "stats",
139          .mode = RCFS_DEFAULT_FILE_MODE,
140          .i_op = &my_iops,
141          .i_fop = &stats_fileops,
142          },
143         {
144          .name = "target",
145          .mode = RCFS_DEFAULT_FILE_MODE,
146          .i_op = &my_iops,
147          .i_fop = &target_fileops,
148          },
149 };
150
151 struct rcfs_magf sub_magf[] = {
152         {
153          .name = "config",
154          .mode = RCFS_DEFAULT_FILE_MODE,
155          .i_op = &my_iops,
156          .i_fop = &config_fileops,
157          },
158         {
159          .name = "shares",
160          .mode = RCFS_DEFAULT_FILE_MODE,
161          .i_op = &my_iops,
162          .i_fop = &shares_fileops,
163          },
164         {
165          .name = "stats",
166          .mode = RCFS_DEFAULT_FILE_MODE,
167          .i_op = &my_iops,
168          .i_fop = &stats_fileops,
169          },
170 };
171
172 struct rcfs_mfdesc sock_mfdesc = {
173         .rootmf = sock_rootdesc,
174         .rootmflen = (sizeof(sock_rootdesc) / sizeof(struct rcfs_magf)),
175 };
176
177 #define SOCK_MAX_MAGF (sizeof(sock_magf)/sizeof(struct rcfs_magf))
178 #define LAQ_MAX_SUBMAGF (sizeof(sub_magf)/sizeof(struct rcfs_magf))
179
180 int sock_rmdir(struct inode *p, struct dentry *me)
181 {
182         struct dentry *mftmp, *mfdentry;
183         int ret = 0;
184
185         // delete all magic sub directories
186         list_for_each_entry_safe(mfdentry, mftmp, &me->d_subdirs, d_child) {
187                 if (S_ISDIR(mfdentry->d_inode->i_mode)) {
188                         ret = rcfs_rmdir(me->d_inode, mfdentry);
189                         if (ret)
190                                 return ret;
191                 }
192         }
193         // delete ourselves
194         ret = rcfs_rmdir(p, me);
195
196         return ret;
197 }
198
199 #ifdef NUM_ACCEPT_QUEUES
200 #define LAQ_NUM_ACCEPT_QUEUES NUM_ACCEPT_QUEUES
201 #else
202 #define LAQ_NUM_ACCEPT_QUEUES 0
203 #endif
204
205 int sock_mkdir(struct inode *dir, struct dentry *dentry, int mode)
206 {
207         int retval = 0;
208         int i, j;
209         struct dentry *pentry, *mfdentry;
210
211         if (_rcfs_mknod(dir, dentry, mode | S_IFDIR, 0)) {
212                 printk(KERN_ERR "rcfs_mkdir: error reaching parent\n");
213                 return retval;
214         }
215         // Needed if only _rcfs_mknod is used instead of i_op->mkdir
216         dir->i_nlink++;
217
218         retval = rcfs_create_coredir(dir, dentry);
219         if (retval)
220                 goto mkdir_err;
221
222         /* create the default set of magic files */
223         for (i = 0; i < SOCK_MAX_MAGF; i++) {
224                 mfdentry = rcfs_create_internal(dentry, &sock_magf[i], 0);
225                 mfdentry->d_fsdata = &RCFS_IS_MAGIC;
226                 RCFS_I(mfdentry->d_inode)->core = RCFS_I(dentry->d_inode)->core;
227                 if (sock_magf[i].i_fop)
228                         mfdentry->d_inode->i_fop = sock_magf[i].i_fop;
229                 if (sock_magf[i].i_op)
230                         mfdentry->d_inode->i_op = sock_magf[i].i_op;
231         }
232
233         for (i = 1; i < LAQ_NUM_ACCEPT_QUEUES; i++) {
234                 j = sprintf(def_magf.name, "%d", i);
235                 def_magf.name[j] = '\0';
236
237                 pentry = rcfs_create_internal(dentry, &def_magf, 0);
238                 retval = rcfs_create_coredir(dentry->d_inode, pentry);
239                 if (retval)
240                         goto mkdir_err;
241                 pentry->d_fsdata = &RCFS_IS_MAGIC;
242                 for (j = 0; j < LAQ_MAX_SUBMAGF; j++) {
243                         mfdentry =
244                             rcfs_create_internal(pentry, &sub_magf[j], 0);
245                         mfdentry->d_fsdata = &RCFS_IS_MAGIC;
246                         RCFS_I(mfdentry->d_inode)->core =
247                             RCFS_I(pentry->d_inode)->core;
248                         if (sub_magf[j].i_fop)
249                                 mfdentry->d_inode->i_fop = sub_magf[j].i_fop;
250                         if (sub_magf[j].i_op)
251                                 mfdentry->d_inode->i_op = sub_magf[j].i_op;
252                 }
253                 pentry->d_inode->i_op = &sub_iops;
254         }
255         dentry->d_inode->i_op = &class_iops;
256         return 0;
257
258       mkdir_err:
259         // Needed
260         dir->i_nlink--;
261         return retval;
262 }
263
264 #ifndef NUM_ACCEPT_QUEUES
265 #define NUM_ACCEPT_QUEUES 0
266 #endif
267
268 char *sock_get_name(struct ckrm_core_class *c)
269 {
270         char *p = (char *)c->name;
271
272         while (*p)
273                 p++;
274         while (*p != '/' && p != c->name)
275                 p--;
276
277         return ++p;
278 }
279
280 int
281 sock_create_noperm(struct inode *dir, struct dentry *dentry, int mode,
282                    struct nameidata *nd)
283 {
284         return -EPERM;
285 }
286
287 int sock_unlink_noperm(struct inode *dir, struct dentry *dentry)
288 {
289         return -EPERM;
290 }
291
292 int sock_mkdir_noperm(struct inode *dir, struct dentry *dentry, int mode)
293 {
294         return -EPERM;
295 }
296
297 int sock_rmdir_noperm(struct inode *dir, struct dentry *dentry)
298 {
299         return -EPERM;
300 }
301
302 int
303 sock_mknod_noperm(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
304 {
305         return -EPERM;
306 }
307
308 #if 0
309 void sock_set_directory()
310 {
311         struct dentry *pentry, *dentry;
312
313         pentry = rcfs_set_magf_byname("listen_aq", (void *)&my_dir_magf[0]);
314         if (pentry) {
315                 dentry = rcfs_create_internal(pentry, &my_dir_magf[1], 0);
316                 if (my_dir_magf[1].i_fop)
317                         dentry->d_inode->i_fop = my_dir_magf[1].i_fop;
318                 RCFS_I(dentry->d_inode)->core = RCFS_I(pentry->d_inode)->core;
319                 dentry = rcfs_create_internal(pentry, &my_dir_magf[2], 0);
320                 if (my_dir_magf[2].i_fop)
321                         dentry->d_inode->i_fop = my_dir_magf[2].i_fop;
322                 RCFS_I(dentry->d_inode)->core = RCFS_I(pentry->d_inode)->core;
323         } else {
324                 printk(KERN_ERR "Could not create /rcfs/listen_aq\n"
325                        "Perhaps /rcfs needs to be mounted\n");
326         }
327 }
328 #endif