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