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