Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[fs/lustre-release.git] / lustre / llite / super25.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre Light Super operations
5  *
6  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #define DEBUG_SUBSYSTEM S_LLITE
25
26 #include <linux/module.h>
27 #include <linux/random.h>
28 #include <linux/version.h>
29 #include <linux/lustre_lite.h>
30 #include <linux/lustre_ha.h>
31 #include <linux/lustre_dlm.h>
32 #include <linux/init.h>
33 #include <linux/fs.h>
34 #include <linux/lprocfs_status.h>
35
36 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
37 #include <asm/statfs.h>
38 kmem_cache_t *ll_file_data_slab;
39 extern struct address_space_operations ll_aops;
40 extern struct address_space_operations ll_dir_aops;
41 struct super_operations ll_super_operations;
42
43 /* /proc/lustre/llite root that tracks llite mount points */
44 struct proc_dir_entry *proc_lustre_fs_root = NULL;
45 /* lproc_llite.c */
46 extern int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
47                                        struct super_block *sb,
48                                        char *osc, char *mdc);
49
50 extern int ll_init_inodecache(void);
51 extern void ll_destroy_inodecache(void);
52 extern int ll_recover(struct recovd_data *, int);
53 extern int ll_commitcbd_setup(struct ll_sb_info *);
54 extern int ll_commitcbd_cleanup(struct ll_sb_info *);
55 int ll_read_inode2(struct inode *inode, void *opaque);
56
57 extern int ll_proc_namespace(struct super_block* sb, char* osc, char* mdc);
58
59 static char *ll_read_opt(const char *opt, char *data)
60 {
61         char *value;
62         char *retval;
63         ENTRY;
64
65         CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
66         if ( strncmp(opt, data, strlen(opt)) )
67                 RETURN(NULL);
68         if ( (value = strchr(data, '=')) == NULL )
69                 RETURN(NULL);
70
71         value++;
72         OBD_ALLOC(retval, strlen(value) + 1);
73         if ( !retval ) {
74                 CERROR("out of memory!\n");
75                 RETURN(NULL);
76         }
77
78         memcpy(retval, value, strlen(value)+1);
79         CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
80         RETURN(retval);
81 }
82
83 static int ll_set_opt(const char *opt, char *data, int fl)
84 {
85         ENTRY;
86
87         CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
88         if ( strncmp(opt, data, strlen(opt)) )
89                 RETURN(0);
90         else
91                 RETURN(fl);
92 }
93
94 static void ll_options(char *options, char **ost, char **mds, int *flags)
95 {
96         char *opt_ptr = options;
97         char *this_char;
98         ENTRY;
99
100         if (!options) {
101                 EXIT;
102                 return;
103         }
104
105         while ((this_char = strsep (&opt_ptr, ",")) != NULL) {
106                 CDEBUG(D_SUPER, "this_char %s\n", this_char);
107                 if ( (!*ost && (*ost = ll_read_opt("osc", this_char)))||
108                      (!*mds && (*mds = ll_read_opt("mdc", this_char)))||
109                      (!(*flags & LL_SBI_NOLCK) && ((*flags) = (*flags) |
110                       ll_set_opt("nolock", this_char, LL_SBI_NOLCK))) )
111                         continue;
112         }
113         EXIT;
114 }
115
116 #ifndef log2
117 #define log2(n) ffz(~(n))
118 #endif
119
120
121 static int ll_fill_super(struct super_block *sb, void *data, int silent)
122 {
123         struct inode *root = 0;
124         struct obd_device *obd;
125         struct ll_sb_info *sbi;
126         char *osc = NULL;
127         char *mdc = NULL;
128         int err;
129         struct ll_fid rootfid;
130         struct obd_statfs osfs;
131         struct ptlrpc_request *request = NULL;
132         struct ptlrpc_connection *mdc_conn;
133         struct ll_read_inode2_cookie lic;
134         class_uuid_t uuid;
135         struct obd_uuid param_uuid;
136
137         ENTRY;
138
139         OBD_ALLOC(sbi, sizeof(*sbi));
140         if (!sbi)
141                 RETURN(-ENOMEM);
142
143         INIT_LIST_HEAD(&sbi->ll_conn_chain);
144         INIT_LIST_HEAD(&sbi->ll_orphan_dentry_list);
145         generate_random_uuid(uuid);
146         class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
147
148         sb->s_fs_info = sbi;
149
150         ll_options(data, &osc, &mdc, &sbi->ll_flags);
151
152         if (!osc) {
153                 CERROR("no osc\n");
154                 GOTO(out_free, sb = NULL);
155         }
156
157         if (!mdc) {
158                 CERROR("no mdc\n");
159                 GOTO(out_free, sb = NULL);
160         }
161
162         strncpy(param_uuid.uuid, mdc, sizeof(param_uuid.uuid));
163         obd = class_uuid2obd(&param_uuid);
164         if (!obd) {
165                 CERROR("MDC %s: not setup or attached\n", mdc);
166                 GOTO(out_free, sb = NULL);
167         }
168
169         err = obd_connect(&sbi->ll_mdc_conn, obd, &sbi->ll_sb_uuid,
170                           ptlrpc_recovd, ll_recover);
171         if (err) {
172                 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
173                 GOTO(out_free, sb = NULL);
174         }
175
176         mdc_conn = sbi2mdc(sbi)->cl_import.imp_connection;
177         list_add(&mdc_conn->c_sb_chain, &sbi->ll_conn_chain);
178
179         obd = class_uuid2obd(osc);
180         if (!obd) {
181                 CERROR("OSC %s: not setup or attached\n", osc);
182                 GOTO(out_mdc, sb = NULL);
183         }
184
185         err = obd_connect(&sbi->ll_osc_conn, obd, &sbi->ll_sb_uuid,
186                           ptlrpc_recovd, ll_recover);
187         if (err) {
188                 CERROR("cannot connect to %s: rc = %d\n", osc, err);
189                 GOTO(out_mdc, sb = NULL);
190         }
191
192         err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid);
193         if (err) {
194                 CERROR("cannot mds_connect: rc = %d\n", err);
195                 GOTO(out_mdc, sb = NULL);
196         }
197         CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
198         sbi->ll_rootino = rootfid.id;
199
200         memset(&osfs, 0, sizeof(osfs));
201         err = obd_statfs(&sbi->ll_mdc_conn, &osfs);
202         sb->s_blocksize = osfs.os_bsize;
203         sb->s_blocksize_bits = log2(osfs.os_bsize);
204         sb->s_magic = LL_SUPER_MAGIC;
205         sb->s_maxbytes = (1ULL << (32 + 9)) - osfs.os_bsize;
206
207         sb->s_op = &ll_super_operations;
208
209         /* make root inode */
210         err = mdc_getattr(&sbi->ll_mdc_conn, sbi->ll_rootino, S_IFDIR,
211                           OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
212         if (err) {
213                 CERROR("mdc_getattr failed for root: rc = %d\n", err);
214                 GOTO(out_request, sb = NULL);
215         }
216
217         /* initialize committed transaction callback daemon */
218         spin_lock_init(&sbi->ll_commitcbd_lock);
219         init_waitqueue_head(&sbi->ll_commitcbd_waitq);
220         init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
221         sbi->ll_commitcbd_flags = 0;
222         err = ll_commitcbd_setup(sbi);
223         if (err) {
224                 CERROR("failed to start commit callback daemon: rc = %d\n",err);
225                 GOTO(out_request, sb = NULL);
226         }
227
228         lic.lic_body = lustre_msg_buf(request->rq_repmsg, 0);
229         lic.lic_lmm = NULL;
230         root = iget5_locked(sb, sbi->ll_rootino, NULL,
231                             ll_read_inode2, &lic);
232
233         if (root) {
234                 sb->s_root = d_alloc_root(root);
235                 root->i_state &= ~(I_LOCK | I_NEW);
236         } else {
237                 CERROR("lustre_lite: bad iget4 for root\n");
238                 GOTO(out_cdb, sb = NULL);
239         }
240
241         ptlrpc_req_finished(request);
242         request = NULL;
243
244         if (proc_lustre_fs_root) {
245                 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
246                                                   osc, mdc);
247                 if (err < 0)
248                         CERROR("could not register mount in /proc/lustre");
249         }
250
251 out_dev:
252         if (mdc)
253                 OBD_FREE(mdc, strlen(mdc) + 1);
254         if (osc)
255                 OBD_FREE(osc, strlen(osc) + 1);
256
257         RETURN(0);
258
259 out_cdb:
260         ll_commitcbd_cleanup(sbi);
261 out_request:
262         ptlrpc_req_finished(request);
263         obd_disconnect(&sbi->ll_osc_conn);
264 out_mdc:
265         obd_disconnect(&sbi->ll_mdc_conn);
266 out_free:
267         OBD_FREE(sbi, sizeof(*sbi));
268
269         goto out_dev;
270 } /* ll_fill_super */
271
272 struct super_block * ll_get_sb(struct file_system_type *fs_type,
273                                int flags, char *devname, void * data)
274 {
275         return get_sb_nodev(fs_type, flags, data, ll_fill_super);
276 }
277
278 static void ll_put_super(struct super_block *sb)
279 {
280         struct ll_sb_info *sbi = ll_s2sbi(sb);
281         struct list_head *tmp, *next;
282         struct ll_fid rootfid;
283         ENTRY;
284
285         list_del(&sbi->ll_conn_chain);
286         ll_commitcbd_cleanup(sbi);
287         obd_disconnect(&sbi->ll_osc_conn);
288
289         /* NULL request to force sync on the MDS, and get the last_committed
290          * value to flush remaining RPCs from the pending queue on client.
291          *
292          * XXX This should be an mdc_sync() call to sync the whole MDS fs,
293          *     which we can call for other reasons as well.
294          */
295         mdc_getstatus(&sbi->ll_mdc_conn, &rootfid);
296
297         if (sbi->ll_proc_root) {
298                 lprocfs_remove(sbi->ll_proc_root);
299         sbi->ll_proc_root = NULL;
300         }
301
302         obd_disconnect(&sbi->ll_mdc_conn);
303
304         spin_lock(&dcache_lock);
305         list_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list){
306                 struct dentry *dentry = list_entry(tmp, struct dentry, d_hash);
307                 shrink_dcache_parent(dentry);
308         }
309         spin_unlock(&dcache_lock);
310
311         OBD_FREE(sbi, sizeof(*sbi));
312
313         EXIT;
314 } /* ll_put_super */
315
316 static void ll_clear_inode(struct inode *inode)
317 {
318         struct ll_sb_info *sbi = ll_i2sbi(inode);
319         struct ll_inode_info *lli = ll_i2info(inode);
320         int rc;
321         ENTRY;
322
323 #warning "Is there a reason we don't do this in 2.5, but we do in 2.4?"
324 #if 0
325         rc = mdc_cancel_unused(&sbi->ll_mdc_conn, inode, LDLM_FL_NO_CALLBACK);
326         if (rc < 0) {
327                 CERROR("mdc_cancel_unused: %d\n", rc);
328                 /* XXX FIXME do something dramatic */
329         }
330
331         if (lli->lli_smd) {
332                 rc = obd_cancel_unused(&sbi->ll_osc_conn, lli->lli_smd, 0);
333                 if (rc < 0) {
334                         CERROR("obd_cancel_unused: %d\n", rc);
335                         /* XXX FIXME do something dramatic */
336                 }
337         }
338 #endif
339
340         if (atomic_read(&inode->i_count) != 0)
341                 CERROR("clearing in-use inode %lu: count = %d\n",
342                        inode->i_ino, atomic_read(&inode->i_count));
343
344         if (lli->lli_smd)
345                 obd_free_memmd(&sbi->ll_osc_conn, &lli->lli_smd);
346
347         if (lli->lli_symlink_name) {
348                 OBD_FREE(lli->lli_symlink_name,strlen(lli->lli_symlink_name)+1);
349                 lli->lli_symlink_name = NULL;
350         }
351
352         EXIT;
353 }
354
355 #if 0
356 static void ll_delete_inode(struct inode *inode)
357 {
358         ENTRY;
359         if (S_ISREG(inode->i_mode)) {
360                 int err;
361                 struct obdo *oa;
362                 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
363
364                 /* mcreate with no open */
365                 if (!lsm)
366                         GOTO(out, 0);
367
368                 if (lsm->lsm_object_id == 0) {
369                         CERROR("This really happens\n");
370                         /* No obdo was ever created */
371                         GOTO(out, 0);
372                 }
373
374                 oa = obdo_alloc();
375                 if (oa == NULL)
376                         GOTO(out, -ENOMEM);
377
378                 oa->o_id = lsm->lsm_object_id;
379                 oa->o_mode = inode->i_mode;
380                 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
381
382                 err = obd_destroy(ll_i2obdconn(inode), oa, lsm);
383                 obdo_free(oa);
384                 if (err)
385                         CDEBUG(D_SUPER, "obd destroy objid "LPX64" error %d\n",
386                                lsm->lsm_object_id, err);
387         }
388 out:
389         clear_inode(inode);
390         EXIT;
391 }
392 #endif
393
394 /* like inode_setattr, but doesn't mark the inode dirty */
395 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
396 {
397         unsigned int ia_valid = attr->ia_valid;
398         int error = 0;
399
400         if ((ia_valid & ATTR_SIZE) && trunc) {
401                 error = vmtruncate(inode, attr->ia_size);
402                 if (error)
403                         goto out;
404         } else if (ia_valid & ATTR_SIZE)
405                 inode->i_size = attr->ia_size;
406
407         if (ia_valid & ATTR_UID)
408                 inode->i_uid = attr->ia_uid;
409         if (ia_valid & ATTR_GID)
410                 inode->i_gid = attr->ia_gid;
411         if (ia_valid & ATTR_ATIME)
412                 inode->i_atime = attr->ia_atime;
413         if (ia_valid & ATTR_MTIME)
414                 inode->i_mtime = attr->ia_mtime;
415         if (ia_valid & ATTR_CTIME)
416                 inode->i_ctime = attr->ia_ctime;
417         if (ia_valid & ATTR_MODE) {
418                 inode->i_mode = attr->ia_mode;
419                 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
420                         inode->i_mode &= ~S_ISGID;
421         }
422 out:
423         return error;
424 }
425
426 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
427 {
428         struct ptlrpc_request *request = NULL;
429         struct ll_sb_info *sbi = ll_i2sbi(inode);
430         int err = 0;
431
432         ENTRY;
433
434         /* change incore inode */
435         ll_attr2inode(inode, attr, do_trunc);
436
437         /* Don't send size changes to MDS to avoid "fast EA" problems, and
438          * also avoid a pointless RPC (we get file size from OST anyways).
439          */
440         attr->ia_valid &= ~ATTR_SIZE;
441         if (attr->ia_valid) {
442                 err = mdc_setattr(&sbi->ll_mdc_conn, inode, attr, NULL, 0,
443                                   &request);
444                 if (err)
445                         CERROR("mdc_setattr fails: err = %d\n", err);
446
447                 ptlrpc_req_finished(request);
448                 if (S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_MTIME_SET) {
449                         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
450                         struct obdo oa;
451                         int err2;
452
453                         CDEBUG(D_ERROR, "setting mtime on OST\n");
454                         oa.o_id = lsm->lsm_object_id;
455                         oa.o_mode = S_IFREG;
456                         oa.o_valid = OBD_MD_FLID |OBD_MD_FLTYPE |OBD_MD_FLMTIME;
457                         oa.o_mtime = attr->ia_mtime.tv_sec;
458                         err2 = obd_setattr(&sbi->ll_osc_conn, &oa, lsm, NULL);
459                         if (err2) {
460                                 CERROR("obd_setattr fails: rc=%d\n", err);
461                                 if (!err)
462                                         err = err2;
463                         }
464                 }
465         }
466
467         RETURN(err);
468 }
469
470 int ll_setattr(struct dentry *de, struct iattr *attr)
471 {
472         int rc = inode_change_ok(de->d_inode, attr);
473
474         if (rc)
475                 return rc;
476
477         return ll_inode_setattr(de->d_inode, attr, 1);
478 }
479
480 static int ll_statfs(struct super_block *sb, struct statfs *sfs)
481 {
482         struct ll_sb_info *sbi = ll_s2sbi(sb);
483         struct obd_statfs osfs;
484         int rc;
485         ENTRY;
486
487         memset(sfs, 0, sizeof(*sfs));
488         rc = obd_statfs(&sbi->ll_mdc_conn, &osfs);
489         statfs_unpack(sfs, &osfs);
490         if (rc)
491                 CERROR("mdc_statfs fails: rc = %d\n", rc);
492         else
493                 CDEBUG(D_SUPER, "mdc_statfs shows blocks "LPU64"/"LPU64
494                        " objects "LPU64"/"LPU64"\n",
495                        osfs.os_bavail, osfs.os_blocks,
496                        osfs.os_ffree, osfs.os_files);
497
498         /* temporary until mds_statfs returns statfs info for all OSTs */
499         if (!rc) {
500                 rc = obd_statfs(&sbi->ll_osc_conn, &osfs);
501                 if (rc) {
502                         CERROR("obd_statfs fails: rc = %d\n", rc);
503                         GOTO(out, rc);
504                 }
505                 CDEBUG(D_SUPER, "obd_statfs shows blocks "LPU64"/"LPU64
506                        " objects "LPU64"/"LPU64"\n",
507                        osfs.os_bavail, osfs.os_blocks,
508                        osfs.os_ffree, osfs.os_files);
509
510                 while (osfs.os_blocks > ~0UL) {
511                         sfs->f_bsize <<= 1;
512
513                         osfs.os_blocks >>= 1;
514                         osfs.os_bfree >>= 1;
515                         osfs.os_bavail >>= 1;
516                 }
517                 sfs->f_blocks = osfs.os_blocks;
518                 sfs->f_bfree = osfs.os_bfree;
519                 sfs->f_bavail = osfs.os_bavail;
520                 if (osfs.os_ffree < (__u64)sfs->f_ffree)
521                         sfs->f_ffree = osfs.os_ffree;
522         }
523
524 out:
525         RETURN(rc);
526 }
527
528 void ll_update_inode(struct inode *inode, struct mds_body *body,
529                      struct lov_mds_md *lmm)
530 {
531         struct ll_inode_info *lli = ll_i2info(inode);
532
533         if (lmm != NULL)
534                 obd_unpackmd(ll_i2obdconn(inode), &lli->lli_smd, lmm);
535
536         if (body->valid & OBD_MD_FLID)
537                 inode->i_ino = body->ino;
538         if (body->valid & OBD_MD_FLATIME)
539                 inode->i_atime.tv_sec = body->atime;
540         if (body->valid & OBD_MD_FLMTIME)
541                 inode->i_mtime.tv_sec = body->mtime;
542         if (body->valid & OBD_MD_FLCTIME)
543                 inode->i_ctime.tv_sec = body->ctime;
544         if (body->valid & OBD_MD_FLMODE)
545                 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
546         if (body->valid & OBD_MD_FLTYPE)
547                 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
548         if (body->valid & OBD_MD_FLUID)
549                 inode->i_uid = body->uid;
550         if (body->valid & OBD_MD_FLGID)
551                 inode->i_gid = body->gid;
552         if (body->valid & OBD_MD_FLFLAGS)
553                 inode->i_flags = body->flags;
554         if (body->valid & OBD_MD_FLNLINK)
555                 inode->i_nlink = body->nlink;
556         if (body->valid & OBD_MD_FLGENER)
557                 inode->i_generation = body->generation;
558         if (body->valid & OBD_MD_FLRDEV)
559                 inode->i_rdev = to_kdev_t(body->rdev);
560         if (body->valid & OBD_MD_FLSIZE)
561                 inode->i_size = body->size;
562         if (body->valid & OBD_MD_FLBLOCKS)
563                 inode->i_blocks = body->blocks;
564 }
565
566 int ll_read_inode2(struct inode *inode, void *opaque)
567 {
568         struct ll_read_inode2_cookie *lic = opaque;
569         struct mds_body *body = lic->lic_body;
570         struct ll_inode_info *lli = ll_i2info(inode);
571         int rc = 0;
572         ENTRY;
573
574         sema_init(&lli->lli_open_sem, 1);
575
576         LASSERT(!lli->lli_smd);
577
578         /* core attributes first */
579         ll_update_inode(inode, body, lic ? lic->lic_lmm : NULL);
580
581         /* Get the authoritative file size */
582         if (lli->lli_smd && S_ISREG(inode->i_mode)) {
583                 rc = ll_file_size(inode, lli->lli_smd, NULL);
584                 if (rc) {
585                         CERROR("ll_file_size: %d\n", rc);
586                         ll_clear_inode(inode);
587                         make_bad_inode(inode);
588                         RETURN(rc);
589                 }
590         }
591
592         /* OIDEBUG(inode); */
593
594         if (S_ISREG(inode->i_mode)) {
595                 inode->i_op = &ll_file_inode_operations;
596                 inode->i_fop = &ll_file_operations;
597                 inode->i_mapping->a_ops = &ll_aops;
598                 EXIT;
599         } else if (S_ISDIR(inode->i_mode)) {
600                 inode->i_op = &ll_dir_inode_operations;
601                 inode->i_fop = &ll_dir_operations;
602                 inode->i_mapping->a_ops = &ll_dir_aops;
603                 EXIT;
604         } else if (S_ISLNK(inode->i_mode)) {
605                 inode->i_op = &ll_fast_symlink_inode_operations;
606                 EXIT;
607         } else {
608                 init_special_inode(inode, inode->i_mode,
609                                    kdev_t_to_nr(inode->i_rdev));
610                 EXIT;
611         }
612
613         return rc;
614 }
615
616 static inline void invalidate_request_list(struct list_head *req_list)
617 {
618         struct list_head *tmp, *n;
619         list_for_each_safe(tmp, n, req_list) {
620                 struct ptlrpc_request *req =
621                         list_entry(tmp, struct ptlrpc_request, rq_list);
622                 CERROR("invalidating req xid %d op %d to %s:%d\n",
623                        (unsigned long long)req->rq_xid, req->rq_reqmsg->opc,
624                        req->rq_connection->c_remote_uuid,
625                        req->rq_import->imp_client->cli_request_portal);
626                 req->rq_flags |= PTL_RPC_FL_ERR;
627                 wake_up(&req->rq_wait_for_rep);
628         }
629 }
630
631 void ll_umount_begin(struct super_block *sb)
632 {
633         struct ll_sb_info *sbi = ll_s2sbi(sb);
634         struct list_head *ctmp;
635
636         ENTRY;
637
638         list_for_each(ctmp, &sbi->ll_conn_chain) {
639                 struct ptlrpc_connection *conn;
640                 conn = list_entry(ctmp, struct ptlrpc_connection, c_sb_chain);
641
642                 spin_lock(&conn->c_lock);
643                 conn->c_flags |= CONN_INVALID;
644                 /*invalidate_request_list(&conn->c_sending_head);*/
645                 invalidate_request_list(&conn->c_delayed_head);
646                 spin_unlock(&conn->c_lock);
647         }
648
649         EXIT;
650 }
651
652
653 static kmem_cache_t *ll_inode_cachep;
654
655 static struct inode *ll_alloc_inode(struct super_block *sb)
656 {
657         struct ll_inode_info *lli;
658         lli = kmem_cache_alloc(ll_inode_cachep, SLAB_KERNEL);
659         if (!lli)
660                 return NULL;
661
662         memset(lli, 0, (char *)&lli->lli_vfs_inode - (char *)lli);
663         sema_init(&lli->lli_open_sem, 1);
664
665         return &lli->lli_vfs_inode;
666 }
667
668 static void ll_destroy_inode(struct inode *inode)
669 {
670         kmem_cache_free(ll_inode_cachep, ll_i2info(inode));
671 }
672
673 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
674 {
675         struct ll_inode_info *lli = foo;
676
677         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
678             SLAB_CTOR_CONSTRUCTOR)
679                 inode_init_once(&lli->lli_vfs_inode);
680 }
681
682 int ll_init_inodecache(void)
683 {
684         ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
685                                             sizeof(struct ll_inode_info),
686                                             0, SLAB_HWCACHE_ALIGN,
687                                             init_once, NULL);
688         if (ll_inode_cachep == NULL)
689                 return -ENOMEM;
690         return 0;
691 }
692
693 void ll_destroy_inodecache(void)
694 {
695         if (kmem_cache_destroy(ll_inode_cachep))
696                 CERROR("ll_inode_cache: not all structures were freed\n");
697 }
698
699
700
701 /* exported operations */
702 struct super_operations ll_super_operations =
703 {
704         alloc_inode: ll_alloc_inode,
705         destroy_inode: ll_destroy_inode,
706         clear_inode: ll_clear_inode,
707 //        delete_inode: ll_delete_inode,
708         put_super: ll_put_super,
709         statfs: ll_statfs,
710         umount_begin: ll_umount_begin
711 };
712
713
714 struct file_system_type lustre_lite_fs_type = {
715         .owner  = THIS_MODULE,
716         .name =   "lustre_lite",
717         .get_sb = ll_get_sb,
718         .kill_sb = kill_anon_super,
719 };
720
721 static int __init init_lustre_lite(void)
722 {
723         int rc;
724         printk(KERN_INFO "Lustre Lite Client File System; "
725                "info@clusterfs.com\n");
726         rc = ll_init_inodecache();
727         if (rc)
728                 return -ENOMEM;
729         ll_file_data_slab = kmem_cache_create("ll_file_data",
730                                               sizeof(struct ll_file_data), 0,
731                                               SLAB_HWCACHE_ALIGN, NULL, NULL);
732         if (ll_file_data_slab == NULL) {
733                 ll_destroy_inodecache();
734                 return -ENOMEM;
735         }
736
737         proc_lustre_fs_root = proc_lustre_root ?
738                               proc_mkdir("llite", proc_lustre_root) : NULL;
739
740         return register_filesystem(&lustre_lite_fs_type);
741 }
742
743 static void __exit exit_lustre_lite(void)
744 {
745         unregister_filesystem(&lustre_lite_fs_type);
746         ll_destroy_inodecache();
747         kmem_cache_destroy(ll_file_data_slab);
748         if (proc_lustre_fs_root) {
749                 lprocfs_remove(proc_lustre_fs_root);
750                 proc_lustre_fs_root = NULL;
751         }
752 }
753
754 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
755 MODULE_DESCRIPTION("Lustre Lite Client File System");
756 MODULE_LICENSE("GPL");
757
758 module_init(init_lustre_lite);
759 module_exit(exit_lustre_lite);
760 #endif