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