Whamcloud - gitweb
merge b_devel into HEAD (20030703)
[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 #include "llite_internal.h"
36
37 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
38 #include <asm/statfs.h>
39 kmem_cache_t *ll_file_data_slab;
40 extern struct address_space_operations ll_aops;
41 extern struct address_space_operations ll_dir_aops;
42 struct super_operations ll_super_operations;
43
44 /* /proc/lustre/llite root that tracks llite mount points */
45 struct proc_dir_entry *proc_lustre_fs_root = NULL;
46 /* lproc_llite.c */
47 extern int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
48                                        struct super_block *sb,
49                                        char *osc, char *mdc);
50
51 extern int ll_init_inodecache(void);
52 extern void ll_destroy_inodecache(void);
53 extern int ll_recover(struct recovd_data *, int);
54 extern int ll_commitcbd_setup(struct ll_sb_info *);
55 extern int ll_commitcbd_cleanup(struct ll_sb_info *);
56 int ll_read_inode2(struct inode *inode, void *opaque);
57
58 extern int ll_proc_namespace(struct super_block* sb, char* osc, char* mdc);
59
60 static char *ll_read_opt(const char *opt, char *data)
61 {
62         char *value;
63         char *retval;
64         ENTRY;
65
66         CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
67         if (strncmp(opt, data, strlen(opt)))
68                 RETURN(NULL);
69         if ((value = strchr(data, '=')) == NULL)
70                 RETURN(NULL);
71
72         value++;
73         OBD_ALLOC(retval, strlen(value) + 1);
74         if (!retval) {
75                 CERROR("out of memory!\n");
76                 RETURN(NULL);
77         }
78
79         memcpy(retval, value, strlen(value)+1);
80         CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
81         RETURN(retval);
82 }
83
84 static int ll_set_opt(const char *opt, char *data, int fl)
85 {
86         ENTRY;
87
88         CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
89         if (strncmp(opt, data, strlen(opt)))
90                 RETURN(0);
91         else
92                 RETURN(fl);
93 }
94
95 static void ll_options(char *options, char **ost, char **mds, int *flags)
96 {
97         char *opt_ptr = options;
98         char *this_char;
99         ENTRY;
100
101         if (!options) {
102                 EXIT;
103                 return;
104         }
105
106         while ((this_char = strsep (&opt_ptr, ",")) != NULL) {
107                 CDEBUG(D_SUPER, "this_char %s\n", this_char);
108                 if ((!*ost && (*ost = ll_read_opt("osc", this_char)))||
109                     (!*mds && (*mds = ll_read_opt("mdc", this_char)))||
110                     (!(*flags & LL_SBI_NOLCK) &&
111                      ((*flags) = (*flags) |
112                       ll_set_opt("nolock", this_char, LL_SBI_NOLCK))))
113                         continue;
114         }
115         EXIT;
116 }
117
118 #ifndef log2
119 #define log2(n) ffz(~(n))
120 #endif
121
122
123 static int ll_fill_super(struct super_block *sb, void *data, int silent)
124 {
125         struct inode *root = 0;
126         struct obd_device *obd;
127         struct ll_sb_info *sbi;
128         char *osc = NULL;
129         char *mdc = NULL;
130         int err;
131         struct ll_fid rootfid;
132         struct obd_statfs osfs;
133         struct ptlrpc_request *request = NULL;
134         struct ptlrpc_connection *mdc_conn;
135         struct ll_read_inode2_cookie lic;
136         class_uuid_t uuid;
137
138         ENTRY;
139         CDEBUG(D_VFSTRACE, "VFS Op:\n");
140
141         OBD_ALLOC(sbi, sizeof(*sbi));
142         if (!sbi)
143                 RETURN(-ENOMEM);
144
145         INIT_LIST_HEAD(&sbi->ll_conn_chain);
146         INIT_LIST_HEAD(&sbi->ll_orphan_dentry_list);
147         generate_random_uuid(uuid);
148         class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
149
150         sb->s_fs_info = sbi;
151
152         ll_options(data, &osc, &mdc, &sbi->ll_flags);
153
154         if (!osc) {
155                 CERROR("no osc\n");
156                 GOTO(out_free, sb = NULL);
157         }
158
159         if (!mdc) {
160                 CERROR("no mdc\n");
161                 GOTO(out_free, sb = NULL);
162         }
163
164         obd = class_name2obd(mdc);
165         if (!obd) {
166                 CERROR("MDC %s: not setup or attached\n", mdc);
167                 GOTO(out_free, sb = NULL);
168         }
169
170         err = obd_connect(&sbi->ll_mdc_conn, obd, &sbi->ll_sb_uuid);
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
178         obd = class_name2obd(osc);
179         if (!obd) {
180                 CERROR("OSC %s: not setup or attached\n", osc);
181                 GOTO(out_mdc, sb = NULL);
182         }
183
184         err = obd_connect(&sbi->ll_osc_conn, obd, &sbi->ll_sb_uuid);
185         if (err) {
186                 CERROR("cannot connect to %s: rc = %d\n", osc, err);
187                 GOTO(out_mdc, sb = NULL);
188         }
189
190         err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid);
191         if (err) {
192                 CERROR("cannot mds_connect: rc = %d\n", err);
193                 GOTO(out_osc, sb = NULL);
194         }
195         CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
196         sbi->ll_rootino = rootfid.id;
197
198         memset(&osfs, 0, sizeof(osfs));
199         err = obd_statfs(&sbi->ll_mdc_conn, &osfs);
200         sb->s_blocksize = osfs.os_bsize;
201         sb->s_blocksize_bits = log2(osfs.os_bsize);
202         sb->s_magic = LL_SUPER_MAGIC;
203         sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
204
205         sb->s_op = &ll_super_operations;
206
207         /* make root inode 
208          * XXX: move this to after cbd setup? */
209         err = mdc_getattr(&sbi->ll_mdc_conn, &rootfid,
210                           OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
211         if (err) {
212                 CERROR("mdc_getattr failed for root: rc = %d\n", err);
213                 GOTO(out_osc, sb = NULL);
214         }
215
216         /* initialize committed transaction callback daemon */
217         spin_lock_init(&sbi->ll_commitcbd_lock);
218         init_waitqueue_head(&sbi->ll_commitcbd_waitq);
219         init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
220         sbi->ll_commitcbd_flags = 0;
221         err = ll_commitcbd_setup(sbi);
222         if (err) {
223                 CERROR("failed to start commit callback daemon: rc = %d\n",err);
224                 ptlrpc_req_finished (request);
225                 GOTO(out_osc, sb = NULL);
226         }
227
228         lic.lic_body = lustre_msg_buf(request->rq_repmsg, 0, sizeof (*lic.lic_body));
229         LASSERT (lic.lic_body != NULL);         /* checked by mdc_getattr() */
230         LASSERT_REPSWABBED (request, 0);        /* swabbed by mdc_getattr() */
231
232         lic.lic_lsm = NULL;
233
234         root = iget5_locked(sb, sbi->ll_rootino, NULL,
235                             ll_read_inode2, &lic);
236
237         ptlrpc_req_finished(request);
238
239         if (root == NULL || is_bad_inode(root)) {
240                 /* XXX might need iput() for bad inode */
241                 CERROR("lustre_lite: bad iget5 for root\n");
242                 GOTO(out_cbd, sb = NULL);
243         }
244
245         sb->s_root = d_alloc_root(root);
246         root->i_state &= ~(I_LOCK | I_NEW);
247         printk("AMRUT 1\n");
248         if (proc_lustre_fs_root) {
249                 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
250                                                   osc, mdc);
251                 if (err < 0)
252                         CERROR("could not register mount in /proc/lustre");
253         }
254
255 out_dev:
256         if (mdc)
257                 OBD_FREE(mdc, strlen(mdc) + 1);
258         if (osc)
259                 OBD_FREE(osc, strlen(osc) + 1);
260         printk("AMRUT 2\n");
261
262         RETURN(0);
263
264 out_cbd:
265         ll_commitcbd_cleanup(sbi);
266 out_osc:
267         obd_disconnect(&sbi->ll_osc_conn, 0);
268 out_mdc:
269         obd_disconnect(&sbi->ll_mdc_conn, 0);
270 out_free:
271         lprocfs_unregister_mountpoint(sbi);
272         OBD_FREE(sbi, sizeof(*sbi));
273
274         goto out_dev;
275 } /* ll_fill_super */
276
277
278 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
279 {
280         struct ptlrpc_request *request = NULL;
281         struct ll_sb_info *sbi = ll_i2sbi(inode);
282         struct mdc_op_data op_data;
283         int err = 0;
284         ENTRY;
285         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
286
287         LPROC_COUNTER_INODE_INCBY1(inode, LPROC_LL_SETATTR);
288         if ((attr->ia_valid & ATTR_SIZE)) {
289                 /* writeback uses inode->i_size to determine how far out
290                  * its cached pages go.  ll_truncate gets a PW lock, canceling
291                  * our lock, _after_ it has updated i_size.  this can confuse
292                  * us into zero extending the file to the newly truncated
293                  * size, and this has bad implications for a racing o_append.
294                  * if we're extending our size we need to flush the pages
295                  * with the correct i_size before vmtruncate stomps on
296                  * the new i_size.  again, this can only find pages to
297                  * purge if the PW lock that generated them is still held.
298                  */
299                 if ( attr->ia_size > inode->i_size ) {
300                         filemap_fdatasync(inode->i_mapping);
301                         filemap_fdatawait(inode->i_mapping);
302                 }
303                 err = vmtruncate(inode, attr->ia_size);
304                 if (err)
305                         RETURN(err);
306         }
307
308         /* Don't send size changes to MDS to avoid "fast EA" problems, and
309          * also avoid a pointless RPC (we get file size from OST anyways).
310          */
311         attr->ia_valid &= ~ATTR_SIZE;
312         if (!attr->ia_valid)
313                 RETURN(0);
314
315         ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
316
317         err = mdc_setattr(&sbi->ll_mdc_conn, &op_data,
318                           attr, NULL, 0, &request);
319         if (err)
320                 CERROR("mdc_setattr fails: err = %d\n", err);
321
322         ptlrpc_req_finished(request);
323
324         if (S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_MTIME_SET) {
325                 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
326                 struct obdo oa;
327                 int err2;
328
329                 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
330                        inode->i_ino, attr->ia_mtime);
331                 oa.o_id = lsm->lsm_object_id;
332                 oa.o_mode = S_IFREG;
333                 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMTIME;
334                 oa.o_mtime = LTIME_S(attr->ia_mtime);
335                 err2 = obd_setattr(&sbi->ll_osc_conn, &oa, lsm, NULL);
336                 if (err2) {
337                         CERROR("obd_setattr fails: rc=%d\n", err);
338                         if (!err)
339                                 err = err2;
340                 }
341         }
342         RETURN(err);
343 }
344 struct super_block * ll_get_sb(struct file_system_type *fs_type,
345                                int flags, char *devname, void * data)
346 {
347         return get_sb_nodev(fs_type, flags, data, ll_fill_super);
348 }
349
350 static void ll_put_super(struct super_block *sb)
351 {
352         struct ll_sb_info *sbi = ll_s2sbi(sb);
353         struct list_head *tmp, *next;
354         struct ll_fid rootfid;
355         ENTRY;
356         CDEBUG(D_VFSTRACE, "VFS Op:\n");
357
358         list_del(&sbi->ll_conn_chain);
359         ll_commitcbd_cleanup(sbi);
360         obd_disconnect(&sbi->ll_osc_conn, 0);
361
362         /* NULL request to force sync on the MDS, and get the last_committed
363          * value to flush remaining RPCs from the pending queue on client.
364          *
365          * XXX This should be an mdc_sync() call to sync the whole MDS fs,
366          *     which we can call for other reasons as well.
367          */
368         mdc_getstatus(&sbi->ll_mdc_conn, &rootfid);
369
370         lprocfs_unregister_mountpoint(sbi);
371         if (sbi->ll_proc_root) {
372                 lprocfs_remove(sbi->ll_proc_root);
373         sbi->ll_proc_root = NULL;
374         }
375
376         obd_disconnect(&sbi->ll_mdc_conn, 0);
377
378         spin_lock(&dcache_lock);
379         list_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list){
380                 struct dentry *dentry = list_entry(tmp, struct dentry, d_hash);
381                 shrink_dcache_parent(dentry);
382         }
383         spin_unlock(&dcache_lock);
384
385         OBD_FREE(sbi, sizeof(*sbi));
386
387         EXIT;
388 } /* ll_put_super */
389
390 static void ll_clear_inode(struct inode *inode)
391 {
392         struct ll_sb_info *sbi = ll_i2sbi(inode);
393         struct ll_inode_info *lli = ll_i2info(inode);
394         int rc;
395         ENTRY;
396         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
397
398 #warning "Is there a reason we don't do this in 2.5, but we do in 2.4?"
399 #if 0
400         rc = ll_mdc_cancel_unused(&sbi->ll_mdc_conn, inode, LDLM_FL_NO_CALLBACK);
401         if (rc < 0) {
402                 CERROR("ll_mdc_cancel_unused: %d\n", rc);
403                 /* XXX FIXME do something dramatic */
404         }
405
406         if (lli->lli_smd) {
407                 rc = obd_cancel_unused(&sbi->ll_osc_conn, lli->lli_smd, 0);
408                 if (rc < 0) {
409                         CERROR("obd_cancel_unused: %d\n", rc);
410                         /* XXX FIXME do something dramatic */
411                 }
412         }
413 #endif
414
415         if (atomic_read(&inode->i_count) != 0)
416                 CERROR("clearing in-use inode %lu: count = %d\n",
417                        inode->i_ino, atomic_read(&inode->i_count));
418
419         if (lli->lli_smd) {
420                 obd_free_memmd(&sbi->ll_osc_conn, &lli->lli_smd);
421                 lli->lli_smd = NULL;
422         }
423
424         if (lli->lli_symlink_name) {
425                 OBD_FREE(lli->lli_symlink_name,strlen(lli->lli_symlink_name)+1);
426                 lli->lli_symlink_name = NULL;
427         }
428
429         EXIT;
430 }
431
432 #if 0
433 static void ll_delete_inode(struct inode *inode)
434 {
435         ENTRY;
436         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
437         if (S_ISREG(inode->i_mode)) {
438                 int err;
439                 struct obdo *oa;
440                 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
441
442                 /* mcreate with no open */
443                 if (!lsm)
444                         GOTO(out, 0);
445
446                 if (lsm->lsm_object_id == 0) {
447                         CERROR("This really happens\n");
448                         /* No obdo was ever created */
449                         GOTO(out, 0);
450                 }
451
452                 oa = obdo_alloc();
453                 if (oa == NULL)
454                         GOTO(out, -ENOMEM);
455
456                 oa->o_id = lsm->lsm_object_id;
457                 oa->o_mode = inode->i_mode;
458                 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
459
460                 err = obd_destroy(ll_i2obdconn(inode), oa, lsm);
461                 obdo_free(oa);
462                 if (err)
463                         CDEBUG(D_SUPER, "obd destroy objid "LPX64" error %d\n",
464                                lsm->lsm_object_id, err);
465         }
466 out:
467         clear_inode(inode);
468         EXIT;
469 }
470 #endif
471
472 /* like inode_setattr, but doesn't mark the inode dirty */
473 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
474 {
475         unsigned int ia_valid = attr->ia_valid;
476         int error = 0;
477
478         if ((ia_valid & ATTR_SIZE) && trunc) {
479                 if (attr->ia_size > ll_file_maxbytes(inode)) {
480                         error = -EFBIG;
481                         goto out;
482                 }
483                 error = vmtruncate(inode, attr->ia_size);
484                 if (error)
485                         goto out;
486         } else if (ia_valid & ATTR_SIZE)
487                 inode->i_size = attr->ia_size;
488
489         if (ia_valid & ATTR_UID)
490                 inode->i_uid = attr->ia_uid;
491         if (ia_valid & ATTR_GID)
492                 inode->i_gid = attr->ia_gid;
493         if (ia_valid & ATTR_ATIME)
494                 inode->i_atime = attr->ia_atime;
495         if (ia_valid & ATTR_MTIME)
496                 inode->i_mtime = attr->ia_mtime;
497         if (ia_valid & ATTR_CTIME)
498                 inode->i_ctime = attr->ia_ctime;
499         if (ia_valid & ATTR_MODE) {
500                 inode->i_mode = attr->ia_mode;
501                 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
502                         inode->i_mode &= ~S_ISGID;
503         }
504 out:
505         return error;
506 }
507
508 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
509 {
510         struct ptlrpc_request *request = NULL;
511         struct ll_sb_info *sbi = ll_i2sbi(inode);
512         int err = 0;
513
514         ENTRY;
515
516         /* change incore inode */
517         err = ll_attr2inode(inode, attr, do_trunc);
518         if (err)
519                 RETURN(err);
520
521         /* Don't send size changes to MDS to avoid "fast EA" problems, and
522          * also avoid a pointless RPC (we get file size from OST anyways).
523          */
524         attr->ia_valid &= ~ATTR_SIZE;
525         if (attr->ia_valid) {
526                 struct mdc_op_data op_data;
527
528                 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
529
530                 err = mdc_setattr(&sbi->ll_mdc_conn, &op_data,
531                                   attr, NULL, 0, &request);
532                 if (err)
533                         CERROR("mdc_setattr fails: err = %d\n", err);
534
535                 ptlrpc_req_finished(request);
536                 if (S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_MTIME_SET) {
537                         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
538                         struct obdo oa;
539                         int err2;
540
541                         CDEBUG(D_ERROR, "setting mtime on OST\n");
542                         oa.o_id = lsm->lsm_object_id;
543                         oa.o_mode = S_IFREG;
544                         oa.o_valid = OBD_MD_FLID |OBD_MD_FLTYPE |OBD_MD_FLMTIME;
545                         oa.o_mtime = LTIME_S(attr->ia_mtime);
546                         err2 = obd_setattr(&sbi->ll_osc_conn, &oa, lsm, NULL);
547                         if (err2) {
548                                 CERROR("obd_setattr fails: rc=%d\n", err);
549                                 if (!err)
550                                         err = err2;
551                         }
552                 }
553         }
554
555         RETURN(err);
556 }
557
558 int ll_setattr(struct dentry *de, struct iattr *attr)
559 {
560         int rc = inode_change_ok(de->d_inode, attr);
561         CDEBUG(D_VFSTRACE, "VFS Op:name=%s\n", de->d_name.name);
562         if (rc)
563                 return rc;
564
565         LPROC_COUNTER_INODE_INCBY1((de->d_inode), LPROC_LL_SETATTR);
566         return ll_inode_setattr(de->d_inode, attr, 1);
567 }
568
569 static int ll_statfs(struct super_block *sb, struct statfs *sfs)
570 {
571         struct ll_sb_info *sbi = ll_s2sbi(sb);
572         struct obd_statfs osfs;
573         int rc;
574         ENTRY;
575         CDEBUG(D_VFSTRACE, "VFS Op:\n");
576
577         LPROC_COUNTER_SBI_INCBY1(sbi, LPROC_LL_STAFS);
578         memset(sfs, 0, sizeof(*sfs));
579         rc = obd_statfs(&sbi->ll_mdc_conn, &osfs);
580         statfs_unpack(sfs, &osfs);
581         if (rc)
582                 CERROR("mdc_statfs fails: rc = %d\n", rc);
583         else
584                 CDEBUG(D_SUPER, "mdc_statfs shows blocks "LPU64"/"LPU64
585                        " objects "LPU64"/"LPU64"\n",
586                        osfs.os_bavail, osfs.os_blocks,
587                        osfs.os_ffree, osfs.os_files);
588
589         /* temporary until mds_statfs returns statfs info for all OSTs */
590         if (!rc) {
591                 rc = obd_statfs(&sbi->ll_osc_conn, &osfs);
592                 if (rc) {
593                         CERROR("obd_statfs fails: rc = %d\n", rc);
594                         GOTO(out, rc);
595                 }
596                 CDEBUG(D_SUPER, "obd_statfs shows blocks "LPU64"/"LPU64
597                        " objects "LPU64"/"LPU64"\n",
598                        osfs.os_bavail, osfs.os_blocks,
599                        osfs.os_ffree, osfs.os_files);
600
601                 while (osfs.os_blocks > ~0UL) {
602                         sfs->f_bsize <<= 1;
603
604                         osfs.os_blocks >>= 1;
605                         osfs.os_bfree >>= 1;
606                         osfs.os_bavail >>= 1;
607                 }
608                 sfs->f_blocks = osfs.os_blocks;
609                 sfs->f_bfree = osfs.os_bfree;
610                 sfs->f_bavail = osfs.os_bavail;
611                 if (osfs.os_ffree < (__u64)sfs->f_ffree) {
612                         sfs->f_files = (sfs->f_files - sfs->f_ffree) +
613                                        osfs.os_ffree;
614                         sfs->f_ffree = osfs.os_ffree;
615                 }
616         }
617
618 out:
619         RETURN(rc);
620 }
621
622 void ll_update_inode(struct inode *inode, struct mds_body *body,
623                      struct lov_stripe_md *lsm)
624 {
625         struct ll_inode_info *lli = ll_i2info(inode);
626
627         LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
628         if (lsm != NULL) {
629                 if (lli->lli_smd == NULL) {
630                         lli->lli_smd = lsm;
631                         lli->lli_maxbytes = lsm->lsm_maxbytes;
632                         if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
633                                 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
634                 } else {
635                         LASSERT (!memcmp (lli->lli_smd, lsm, sizeof (*lsm)));
636                 }
637         }
638
639         if (body->valid & OBD_MD_FLID)
640                 inode->i_ino = body->ino;
641         if (body->valid & OBD_MD_FLATIME)
642                 LTIME_S(inode->i_atime) = body->atime;
643         if (body->valid & OBD_MD_FLMTIME)
644                 LTIME_S(inode->i_mtime) = body->mtime;
645         if (body->valid & OBD_MD_FLCTIME)
646                 LTIME_S(inode->i_ctime) = body->ctime;
647         if (body->valid & OBD_MD_FLMODE)
648                 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
649         if (body->valid & OBD_MD_FLTYPE)
650                 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
651         if (body->valid & OBD_MD_FLUID)
652                 inode->i_uid = body->uid;
653         if (body->valid & OBD_MD_FLGID)
654                 inode->i_gid = body->gid;
655         if (body->valid & OBD_MD_FLFLAGS)
656                 inode->i_flags = body->flags;
657         if (body->valid & OBD_MD_FLNLINK)
658                 inode->i_nlink = body->nlink;
659         if (body->valid & OBD_MD_FLGENER)
660                 inode->i_generation = body->generation;
661         if (body->valid & OBD_MD_FLRDEV)
662                 inode->i_rdev = to_kdev_t(body->rdev);
663         if (body->valid & OBD_MD_FLSIZE)
664                 inode->i_size = body->size;
665         if (body->valid & OBD_MD_FLBLOCKS)
666                 inode->i_blocks = body->blocks;
667 }
668
669 int ll_read_inode2(struct inode *inode, void *opaque)
670 {
671         struct ll_read_inode2_cookie *lic = opaque;
672         struct mds_body *body = lic->lic_body;
673         struct ll_inode_info *lli = ll_i2info(inode);
674         int rc = 0;
675         ENTRY;
676         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
677
678         sema_init(&lli->lli_open_sem, 1);
679         /* these are 2.4 only, but putting them here for consistency.. */
680         spin_lock_init(&lli->lli_read_extent_lock);
681         INIT_LIST_HEAD(&lli->lli_read_extents);
682         ll_lldo_init(&lli->lli_dirty);
683         lli->lli_flags = 0;
684         lli->lli_maxbytes = LUSTRE_STRIPE_MAXBYTES;
685
686         LASSERT(!lli->lli_smd);
687
688         /* core attributes first */
689         ll_update_inode(inode, body, lic ? lic->lic_lsm : NULL);
690
691         /* OIDEBUG(inode); */
692
693         if (S_ISREG(inode->i_mode)) {
694                 inode->i_op = &ll_file_inode_operations;
695                 inode->i_fop = &ll_file_operations;
696                 inode->i_mapping->a_ops = &ll_aops;
697                 EXIT;
698         } else if (S_ISDIR(inode->i_mode)) {
699                 inode->i_op = &ll_dir_inode_operations;
700                 inode->i_fop = &ll_dir_operations;
701                 inode->i_mapping->a_ops = &ll_dir_aops;
702                 EXIT;
703         } else if (S_ISLNK(inode->i_mode)) {
704                 inode->i_op = &ll_fast_symlink_inode_operations;
705                 EXIT;
706         } else {
707                 inode->i_op = &ll_special_inode_operations;
708                 init_special_inode(inode, inode->i_mode,
709                                    kdev_t_to_nr(inode->i_rdev));
710                 EXIT;
711         }
712
713         return rc;
714 }
715
716
717 void ll_umount_begin(struct super_block *sb)
718 {
719         struct ll_sb_info *sbi = ll_s2sbi(sb);
720         struct obd_device *obd;
721         struct obd_ioctl_data ioc_data = { 0 };
722
723         ENTRY;
724         CDEBUG(D_VFSTRACE, "VFS Op:\n");
725
726         obd = class_conn2obd(&sbi->ll_mdc_conn);
727         obd->obd_no_recov = 1;
728         obd_iocontrol(IOC_OSC_SET_ACTIVE, &sbi->ll_mdc_conn, sizeof ioc_data,
729                       &ioc_data, NULL);
730
731         obd = class_conn2obd(&sbi->ll_osc_conn);
732         obd->obd_no_recov = 1;
733         obd_iocontrol(IOC_OSC_SET_ACTIVE, &sbi->ll_osc_conn, sizeof ioc_data,
734                       &ioc_data, NULL);
735         
736         /* Really, we'd like to wait until there are no requests outstanding,
737          * and then continue.  For now, we just invalidate the requests,
738          * schedule, and hope.
739          */
740         schedule();
741
742         EXIT;
743 }
744
745 static kmem_cache_t *ll_inode_cachep;
746
747 static struct inode *ll_alloc_inode(struct super_block *sb)
748 {
749         struct ll_inode_info *lli;
750         LPROC_COUNTER_SBI_INCBY1((ll_s2sbi(sb)), LL_ALLOC_INODE);
751         OBD_SLAB_ALLOC(lli, ll_inode_cachep, SLAB_KERNEL, sizeof *lli);
752         if (lli == NULL)
753                 return NULL;
754
755         memset(lli, 0, (char *)&lli->lli_vfs_inode - (char *)lli);
756         sema_init(&lli->lli_open_sem, 1);
757         init_MUTEX(&lli->lli_size_valid_sem);
758         lli->lli_maxbytes = LUSTRE_STRIPE_MAXBYTES;
759
760         return &lli->lli_vfs_inode;
761 }
762
763 static void ll_destroy_inode(struct inode *inode)
764 {
765         OBD_SLAB_FREE(ll_inode_cachep, ll_i2info(inode),
766                       sizeof(struct ll_inode_info));
767 }
768
769 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
770 {
771         struct ll_inode_info *lli = foo;
772
773         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
774             SLAB_CTOR_CONSTRUCTOR)
775                 inode_init_once(&lli->lli_vfs_inode);
776 }
777
778 int ll_init_inodecache(void)
779 {
780         ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
781                                             sizeof(struct ll_inode_info),
782                                             0, SLAB_HWCACHE_ALIGN,
783                                             init_once, NULL);
784         if (ll_inode_cachep == NULL)
785                 return -ENOMEM;
786         return 0;
787 }
788
789 void ll_destroy_inodecache(void)
790 {
791         if (kmem_cache_destroy(ll_inode_cachep))
792                 CERROR("ll_inode_cache: not all structures were freed\n");
793 }
794
795
796
797 /* exported operations */
798 struct super_operations ll_super_operations =
799 {
800         alloc_inode: ll_alloc_inode,
801         destroy_inode: ll_destroy_inode,
802         clear_inode: ll_clear_inode,
803 //        delete_inode: ll_delete_inode,
804         put_super: ll_put_super,
805         statfs: ll_statfs,
806         umount_begin: ll_umount_begin
807 };
808
809
810 struct file_system_type lustre_lite_fs_type = {
811         .owner  = THIS_MODULE,
812         .name =   "lustre_lite",
813         .get_sb = ll_get_sb,
814         .kill_sb = kill_anon_super,
815 };
816
817 static int __init init_lustre_lite(void)
818 {
819         int rc;
820         printk(KERN_INFO "Lustre Lite Client File System; "
821                "info@clusterfs.com\n");
822         rc = ll_init_inodecache();
823         if (rc)
824                 return -ENOMEM;
825         ll_file_data_slab = kmem_cache_create("ll_file_data",
826                                               sizeof(struct ll_file_data), 0,
827                                               SLAB_HWCACHE_ALIGN, NULL, NULL);
828         if (ll_file_data_slab == NULL) {
829                 ll_destroy_inodecache();
830                 return -ENOMEM;
831         }
832
833         proc_lustre_fs_root = proc_lustre_root ?
834                               proc_mkdir("llite", proc_lustre_root) : NULL;
835
836         return register_filesystem(&lustre_lite_fs_type);
837 }
838
839 static void __exit exit_lustre_lite(void)
840 {
841         unregister_filesystem(&lustre_lite_fs_type);
842         ll_destroy_inodecache();
843         kmem_cache_destroy(ll_file_data_slab);
844         if (proc_lustre_fs_root) {
845                 lprocfs_remove(proc_lustre_fs_root);
846                 proc_lustre_fs_root = NULL;
847         }
848 }
849
850 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
851 MODULE_DESCRIPTION("Lustre Lite Client File System");
852 MODULE_LICENSE("GPL");
853
854 module_init(init_lustre_lite);
855 module_exit(exit_lustre_lite);
856 #endif