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