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