Whamcloud - gitweb
b=2334
[fs/lustre-release.git] / lustre / llite / llite_lib.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
30 #include <linux/lustre_lite.h>
31 #include <linux/lustre_ha.h>
32 #include <linux/lustre_dlm.h>
33 #include <linux/lprocfs_status.h>
34 #include "llite_internal.h"
35
36 kmem_cache_t *ll_file_data_slab;
37
38 extern struct address_space_operations ll_aops;
39 extern struct address_space_operations ll_dir_aops;
40 extern struct super_operations ll_super_operations;
41
42 #ifndef log2
43 #define log2(n) ffz(~(n))
44 #endif
45
46 struct ll_sb_info *lustre_init_sbi(struct super_block *sb) 
47 {
48         struct ll_sb_info *sbi = NULL;
49         class_uuid_t uuid;
50         ENTRY;
51
52         OBD_ALLOC(sbi, sizeof(*sbi));
53         if (!sbi)
54                 RETURN(NULL);
55
56         INIT_LIST_HEAD(&sbi->ll_conn_chain);
57         INIT_HLIST_HEAD(&sbi->ll_orphan_dentry_list);
58         ll_s2sbi(sb) = sbi;
59
60         generate_random_uuid(uuid);
61         class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
62         RETURN(sbi);
63 }
64
65 void lustre_free_sbi(struct super_block *sb) 
66 {
67         struct ll_sb_info *sbi = ll_s2sbi(sb);
68         ENTRY;
69
70         if (sbi != NULL)
71                 OBD_FREE(sbi, sizeof(*sbi));
72         ll_s2sbi(sb) = NULL;
73         EXIT;
74 }
75
76 int lustre_common_fill_super(struct super_block *sb, char *mdc, char *osc)
77 {
78         struct inode *root = 0;
79         struct ll_sb_info *sbi = ll_s2sbi(sb);
80         struct obd_device *obd;
81         struct ll_fid rootfid;
82         struct obd_statfs osfs;
83         struct ptlrpc_request *request = NULL;
84         struct lustre_handle osc_conn = {0, };
85         struct lustre_handle mdc_conn = {0, };
86         struct lustre_md md;
87         kdev_t devno;
88         int err;
89
90         obd = class_name2obd(mdc);
91         if (!obd) {
92                 CERROR("MDC %s: not setup or attached\n", mdc);
93                 RETURN(-EINVAL);
94         }
95
96         if (proc_lustre_fs_root) {
97                 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
98                                                   osc, mdc);
99                 if (err < 0)
100                         CERROR("could not register mount in /proc/lustre");
101         }
102
103         mdc_init_ea_size(obd, osc);
104
105         err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid);
106         if (err == -EBUSY) {
107                 CERROR("An MDS (mdc %s) is performing recovery, of which this"
108                        " client is not a part.  Please wait for recovery to "
109                        "complete, abort, or time out.\n", mdc);
110                 GOTO(out, err);
111         } else if (err) {
112                 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
113                 GOTO(out, err);
114         }
115         sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
116
117         err = obd_statfs(obd, &osfs, jiffies - HZ);
118         if (err)
119                 GOTO(out_mdc, err);
120
121         LASSERT(osfs.os_bsize);
122         sb->s_blocksize = osfs.os_bsize;
123         sb->s_blocksize_bits = log2(osfs.os_bsize);
124         sb->s_magic = LL_SUPER_MAGIC;
125         sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
126         
127         devno = get_uuid2int(sbi2mdc(sbi)->cl_import->imp_target_uuid.uuid, 
128                              strlen(sbi2mdc(sbi)->cl_import->imp_target_uuid.uuid));
129         sb->s_dev = devno;
130
131         obd = class_name2obd(osc);
132         if (!obd) {
133                 CERROR("OSC %s: not setup or attached\n", osc);
134                 GOTO(out_mdc, err);
135         }
136
137         err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid);
138         if (err == -EBUSY) {
139                 CERROR("An OST (osc %s) is performing recovery, of which this"
140                        " client is not a part.  Please wait for recovery to "
141                        "complete, abort, or time out.\n", osc);
142                 GOTO(out, err);
143         } else if (err) {
144                 CERROR("cannot connect to %s: rc = %d\n", osc, err);
145                 GOTO(out_mdc, err);
146         }
147         sbi->ll_osc_exp = class_conn2export(&osc_conn);
148
149         err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
150         if (err) {
151                 CERROR("cannot mds_connect: rc = %d\n", err);
152                 GOTO(out_osc, err);
153         }
154         CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
155         sbi->ll_rootino = rootfid.id;
156
157         sb->s_op = &lustre_super_operations;
158
159         /* make root inode 
160          * XXX: move this to after cbd setup? */
161         err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
162                           OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
163         if (err) {
164                 CERROR("mdc_getattr failed for root: rc = %d\n", err);
165                 GOTO(out_osc, err);
166         }
167
168         err = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
169         if (err) {
170                 CERROR("failed to understand root inode md: rc = %d\n",err);
171                 ptlrpc_req_finished (request);
172                 GOTO(out_osc, err);
173         }
174
175         LASSERT(sbi->ll_rootino != 0);
176         root = ll_iget(sb, sbi->ll_rootino, &md);
177
178         ptlrpc_req_finished(request);
179
180         if (root == NULL || is_bad_inode(root)) {
181                 /* XXX might need iput() for bad inode */
182                 CERROR("lustre_lite: bad iget4 for root\n");
183                 GOTO(out_root, err = -EBADF);
184         }
185
186         err = ll_close_thread_start(&sbi->ll_lcq);
187         if (err) {
188                 CERROR("cannot start close thread: rc %d\n", err);
189                 GOTO(out_root, err);
190         }
191
192         sb->s_root = d_alloc_root(root);
193         RETURN(err);
194
195 out_root:
196         if (root)
197                 iput(root);
198 out_osc:
199         obd_disconnect(sbi->ll_osc_exp, 0);
200 out_mdc:
201         obd_disconnect(sbi->ll_mdc_exp, 0);
202 out:
203         lprocfs_unregister_mountpoint(sbi);
204         RETURN(err);
205 }
206
207 void lustre_common_put_super(struct super_block *sb)
208 {
209         struct ll_sb_info *sbi = ll_s2sbi(sb);
210         struct hlist_node *tmp, *next;
211         ENTRY;
212
213         ll_close_thread_shutdown(sbi->ll_lcq);
214
215         list_del(&sbi->ll_conn_chain);
216         obd_disconnect(sbi->ll_osc_exp, 0);
217
218         lprocfs_unregister_mountpoint(sbi);
219         if (sbi->ll_proc_root) {
220                 lprocfs_remove(sbi->ll_proc_root);
221                 sbi->ll_proc_root = NULL;
222         }
223
224         obd_disconnect(sbi->ll_mdc_exp, 0);
225
226         // We do this to get rid of orphaned dentries. That is not really trw.
227         spin_lock(&dcache_lock);
228         hlist_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list) {
229                 struct dentry *dentry = hlist_entry(tmp, struct dentry, d_hash);
230                 shrink_dcache_parent(dentry);
231         }
232         spin_unlock(&dcache_lock);
233         EXIT;
234 }
235
236
237 char *ll_read_opt(const char *opt, char *data)
238 {
239         char *value;
240         char *retval;
241         ENTRY;
242
243         CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
244         if (strncmp(opt, data, strlen(opt)))
245                 RETURN(NULL);
246         if ((value = strchr(data, '=')) == NULL)
247                 RETURN(NULL);
248
249         value++;
250         OBD_ALLOC(retval, strlen(value) + 1);
251         if (!retval) {
252                 CERROR("out of memory!\n");
253                 RETURN(NULL);
254         }
255
256         memcpy(retval, value, strlen(value)+1);
257         CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
258         RETURN(retval);
259 }
260
261 int ll_set_opt(const char *opt, char *data, int fl)
262 {
263         ENTRY;
264
265         CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
266         if (strncmp(opt, data, strlen(opt)))
267                 RETURN(0);
268         else
269                 RETURN(fl);
270 }
271
272 void ll_options(char *options, char **ost, char **mdc, int *flags)
273 {
274         char *this_char;
275 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
276         char *opt_ptr = options;
277 #endif
278         ENTRY;
279
280         if (!options) {
281                 EXIT;
282                 return;
283         }
284
285 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
286         for (this_char = strtok (options, ",");
287              this_char != NULL;
288              this_char = strtok (NULL, ",")) {
289 #else
290         while ((this_char = strsep (&opt_ptr, ",")) != NULL) {
291 #endif
292                 CDEBUG(D_SUPER, "this_char %s\n", this_char);
293                 if (!*ost && (*ost = ll_read_opt("osc", this_char)))
294                         continue;
295                 if (!*mdc && (*mdc = ll_read_opt("mdc", this_char)))
296                         continue;
297                 if (!(*flags & LL_SBI_NOLCK) &&
298                     ((*flags) = (*flags) |
299                                 ll_set_opt("nolock", this_char,
300                                            LL_SBI_NOLCK)))
301                         continue;
302         }
303         EXIT;
304 }
305
306 void ll_lli_init(struct ll_inode_info *lli)
307 {
308         sema_init(&lli->lli_open_sem, 1);
309         lli->lli_flags = 0;
310         lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
311         spin_lock_init(&lli->lli_lock);
312         INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
313 }
314
315 int ll_fill_super(struct super_block *sb, void *data, int silent)
316 {
317         struct ll_sb_info *sbi;
318         char *osc = NULL;
319         char *mdc = NULL;
320         int err;
321         ENTRY;
322
323         CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
324
325         sbi = lustre_init_sbi(sb);
326         if (!sbi)
327                 RETURN(-ENOMEM);
328
329         sbi->ll_flags |= LL_SBI_READAHEAD;
330         ll_options(data, &osc, &mdc, &sbi->ll_flags);
331
332         if (!osc) {
333                 CERROR("no osc\n");
334                 GOTO(out, err = -EINVAL);
335         }
336
337         if (!mdc) {
338                 CERROR("no mdc\n");
339                 GOTO(out, err = -EINVAL);
340         }
341
342         err = lustre_common_fill_super(sb, mdc, osc);
343 out:
344         if (err)
345                 lustre_free_sbi(sb);
346
347         if (mdc)
348                 OBD_FREE(mdc, strlen(mdc) + 1);
349         if (osc)
350                 OBD_FREE(osc, strlen(osc) + 1);
351
352         RETURN(err);
353 } /* ll_read_super */
354
355 void ll_put_super(struct super_block *sb)
356 {
357         ENTRY;
358
359         CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
360
361         lustre_common_put_super(sb);
362
363         lustre_free_sbi(sb);
364
365         EXIT;
366 } /* ll_put_super */
367
368 int lustre_process_log(struct lustre_mount_data *lmd, char * profile,
369                        struct config_llog_instance *cfg)
370 {
371         struct lustre_cfg lcfg;
372         struct portals_cfg pcfg;
373         char * peer = "MDS_PEER_UUID";
374         struct obd_device *obd;
375         struct lustre_handle mdc_conn = {0, };
376         struct obd_export *exp;
377         char * name = "mdc_dev";
378         class_uuid_t uuid;
379         struct obd_uuid mdc_uuid;
380         struct llog_ctxt *ctxt;
381         int rc = 0;
382         int err;
383         ENTRY;
384
385         generate_random_uuid(uuid);
386         class_uuid_unparse(uuid, &mdc_uuid);
387
388         if (lmd->lmd_local_nid) {
389                 PCFG_INIT(pcfg, NAL_CMD_REGISTER_MYNID);
390                 pcfg.pcfg_nal = lmd->lmd_nal;
391                 pcfg.pcfg_nid = lmd->lmd_local_nid;
392                 err = kportal_nal_cmd(&pcfg);
393                 if (err <0)
394                         GOTO(out, err);
395         }
396
397         if (lmd->lmd_nal == SOCKNAL) {
398                 PCFG_INIT(pcfg, NAL_CMD_ADD_AUTOCONN);
399                 pcfg.pcfg_nal     = lmd->lmd_nal;
400                 pcfg.pcfg_nid     = lmd->lmd_server_nid;
401                 pcfg.pcfg_id      = lmd->lmd_server_ipaddr;
402                 pcfg.pcfg_misc    = lmd->lmd_port;
403                 pcfg.pcfg_size    = 0;
404                 pcfg.pcfg_flags   = 0x4; /*share*/
405                 err = kportal_nal_cmd(&pcfg);
406                 if (err <0)
407                         GOTO(out, err);
408         }
409
410         LCFG_INIT(lcfg, LCFG_ADD_UUID, name);
411         lcfg.lcfg_nid = lmd->lmd_server_nid;
412         lcfg.lcfg_inllen1 = strlen(peer) + 1;
413         lcfg.lcfg_inlbuf1 = peer;
414         lcfg.lcfg_nal = lmd->lmd_nal;
415         err = class_process_config(&lcfg);
416         if (err < 0)
417                 GOTO(out_del_conn, err);
418
419         LCFG_INIT(lcfg, LCFG_ATTACH, name);
420         lcfg.lcfg_inlbuf1 = "mdc";
421         lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
422         lcfg.lcfg_inlbuf2 = mdc_uuid.uuid;
423         lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
424         err = class_process_config(&lcfg);
425         if (err < 0)
426                 GOTO(out_del_uuid, err);
427
428         LCFG_INIT(lcfg, LCFG_SETUP, name);
429         lcfg.lcfg_inlbuf1 = lmd->lmd_mds;
430         lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
431         lcfg.lcfg_inlbuf2 = peer;
432         lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
433         err = class_process_config(&lcfg);
434         if (err < 0)
435                 GOTO(out_detach, err);
436         
437         obd = class_name2obd(name);
438         if (obd == NULL)
439                 GOTO(out_cleanup, err = -EINVAL);
440
441         err = obd_connect(&mdc_conn, obd, &mdc_uuid);
442         if (err) {
443                 CERROR("cannot connect to %s: rc = %d\n", lmd->lmd_mds, err);
444                 GOTO(out_cleanup, err);
445         }
446         
447         exp = class_conn2export(&mdc_conn);
448         
449         ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
450         rc = class_config_parse_llog(ctxt, profile, cfg);
451         if (rc) {
452                 CERROR("class_config_parse_llog failed: rc = %d\n", rc);
453         }
454
455         err = obd_disconnect(exp, 0);
456
457 out_cleanup:
458         LCFG_INIT(lcfg, LCFG_CLEANUP, name);
459         err = class_process_config(&lcfg);
460         if (err < 0)
461                 GOTO(out, err);
462
463 out_detach:
464         LCFG_INIT(lcfg, LCFG_DETACH, name);
465         err = class_process_config(&lcfg);
466         if (err < 0)
467                 GOTO(out, err);
468
469 out_del_uuid:
470         LCFG_INIT(lcfg, LCFG_DEL_UUID, name);
471         lcfg.lcfg_inllen1 = strlen(peer) + 1;
472         lcfg.lcfg_inlbuf1 = peer;
473         err = class_process_config(&lcfg);
474
475 out_del_conn:
476         if (lmd->lmd_nal == SOCKNAL) {
477                 PCFG_INIT(pcfg, NAL_CMD_DEL_AUTOCONN);
478                 pcfg.pcfg_nal     = lmd->lmd_nal;
479                 pcfg.pcfg_nid     = lmd->lmd_server_nid;
480                 pcfg.pcfg_id      = lmd->lmd_server_ipaddr;
481                 pcfg.pcfg_flags   = 1; /*share*/
482                 err = kportal_nal_cmd(&pcfg);
483                 if (err <0)
484                         GOTO(out, err);
485         }
486 out:
487         if (rc == 0)
488                 rc = err;
489         
490         RETURN(rc);
491 }
492
493 int lustre_fill_super(struct super_block *sb, void *data, int silent)
494 {
495         struct lustre_mount_data * lmd = data;
496         struct ll_sb_info *sbi;
497         char *osc = NULL;
498         char *mdc = NULL;
499         int err;
500         ENTRY;
501
502         CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
503         sbi = lustre_init_sbi(sb);
504         if (!sbi)
505                 RETURN(-ENOMEM);
506
507         sbi->ll_flags |= LL_SBI_READAHEAD;
508
509         if (lmd->lmd_profile) {
510                 struct lustre_profile *lprof;
511                 struct config_llog_instance cfg;
512                 int len;
513
514                 if (!lmd->lmd_mds) {
515                         CERROR("no mds name\n");
516                         GOTO(out_free, err = -EINVAL);
517                 }
518
519                 OBD_ALLOC(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
520                 if (sbi->ll_lmd == NULL) 
521                         GOTO(out_free, err = -ENOMEM);
522                 memcpy(sbi->ll_lmd, lmd, sizeof(*lmd));
523
524                 /* generate a string unique to this super, let's try
525                  the address of the super itself.*/
526                 len = (sizeof(sb) * 2) + 1; 
527                 OBD_ALLOC(sbi->ll_instance, len);
528                 if (sbi->ll_instance == NULL) 
529                         GOTO(out_free, err = -ENOMEM);
530                 sprintf(sbi->ll_instance, "%p", sb);
531
532                 cfg.cfg_instance = sbi->ll_instance;
533                 cfg.cfg_uuid = sbi->ll_sb_uuid;
534                 cfg.cfg_local_nid = lmd->lmd_local_nid;
535                 err = lustre_process_log(lmd, lmd->lmd_profile, &cfg);
536                 if (err < 0) {
537                         CERROR("Unable to process log: %s\n", lmd->lmd_profile);
538
539                         GOTO(out_free, err);
540                 }
541
542                 lprof = class_get_profile(lmd->lmd_profile);
543                 if (lprof == NULL) {
544                         CERROR("No profile found: %s\n", lmd->lmd_profile);
545                         GOTO(out_free, err = -EINVAL);
546                 }
547                 if (osc)
548                         OBD_FREE(osc, strlen(osc) + 1);
549                 OBD_ALLOC(osc, strlen(lprof->lp_osc) + 
550                           strlen(sbi->ll_instance) + 2);
551                 sprintf(osc, "%s-%s", lprof->lp_osc, sbi->ll_instance);
552
553                 if (mdc)
554                         OBD_FREE(mdc, strlen(mdc) + 1);
555                 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) + 
556                           strlen(sbi->ll_instance) + 2);
557                 sprintf(mdc, "%s-%s", lprof->lp_mdc, sbi->ll_instance);
558         }
559
560         if (!osc) {
561                 CERROR("no osc\n");
562                 GOTO(out_free, err = -EINVAL);
563         }
564
565         if (!mdc) {
566                 CERROR("no mdc\n");
567                 GOTO(out_free, err = -EINVAL);
568         }
569         
570         err = lustre_common_fill_super(sb, mdc, osc);
571         
572         if (err)
573                 GOTO(out_free, err);
574
575 out_dev:
576         if (mdc)
577                 OBD_FREE(mdc, strlen(mdc) + 1);
578         if (osc)
579                 OBD_FREE(osc, strlen(osc) + 1);
580
581         RETURN(err);
582
583 out_free:
584         if (sbi->ll_lmd) {
585                 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
586                 int err;
587
588                 if (sbi->ll_instance != NULL) {
589                         char * cln_prof;
590                         struct config_llog_instance cfg;
591
592                         cfg.cfg_instance = sbi->ll_instance;
593                         cfg.cfg_uuid = sbi->ll_sb_uuid;
594
595                         OBD_ALLOC(cln_prof, len);
596                         sprintf(cln_prof, "%s-clean", sbi->ll_lmd->lmd_profile);
597
598                         err = lustre_process_log(sbi->ll_lmd, cln_prof, &cfg);
599                         if (err < 0) 
600                                 CERROR("Unable to process log: %s\n", cln_prof);
601                         OBD_FREE(cln_prof, len);
602                         OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance)+ 1);
603                 }
604                 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
605         }
606         lustre_free_sbi(sb);
607
608         goto out_dev;
609 } /* lustre_fill_super */
610
611 void lustre_put_super(struct super_block *sb)
612 {
613         struct ll_sb_info *sbi = ll_s2sbi(sb);
614         ENTRY;
615
616         CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
617
618         lustre_common_put_super(sb);
619
620         if (sbi->ll_lmd != NULL) {
621                 char * cln_prof;
622                 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
623                 int err;
624                 struct config_llog_instance cfg;
625
626                 cfg.cfg_instance = sbi->ll_instance;
627                 cfg.cfg_uuid = sbi->ll_sb_uuid;
628
629                 OBD_ALLOC(cln_prof, len);
630                 sprintf(cln_prof, "%s-clean", sbi->ll_lmd->lmd_profile);
631
632                 err = lustre_process_log(sbi->ll_lmd, cln_prof, &cfg);
633                 if (err < 0)
634                         CERROR("Unable to process log: %s\n", cln_prof);
635
636                 OBD_FREE(cln_prof, len);
637                 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
638                 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance) + 1);
639         }
640
641         lustre_free_sbi(sb);
642
643         EXIT;
644 } /* lustre_put_super */
645
646
647 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
648 {
649         struct inode *inode;
650         l_lock(&lock->l_resource->lr_namespace->ns_lock);
651         if (lock->l_ast_data)
652                 inode = igrab(lock->l_ast_data);
653         else
654                 inode = NULL;
655         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
656         return inode;
657 }
658
659 static int null_if_equal(struct ldlm_lock *lock, void *data)
660 {
661         if (data == lock->l_ast_data)
662                 lock->l_ast_data = NULL;
663
664         if (lock->l_req_mode != lock->l_granted_mode)
665                 return LDLM_ITER_STOP;
666
667         return LDLM_ITER_CONTINUE;
668 }
669
670 void ll_clear_inode(struct inode *inode)
671 {
672         struct ll_fid fid;
673         struct ll_inode_info *lli = ll_i2info(inode);
674         struct ll_sb_info *sbi = ll_i2sbi(inode);
675         ENTRY;
676
677         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
678                inode->i_generation, inode);
679
680         ll_inode2fid(&fid, inode);
681         clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(ll_i2info(inode)->lli_flags));
682         mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
683
684         if (lli->lli_smd)
685                 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
686                                   null_if_equal, inode);
687
688         if (lli->lli_smd) {
689                 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
690                 lli->lli_smd = NULL;
691         }
692
693         if (lli->lli_symlink_name) {
694                 OBD_FREE(lli->lli_symlink_name,
695                          strlen(lli->lli_symlink_name) + 1);
696                 lli->lli_symlink_name = NULL;
697         }
698
699         EXIT;
700 }
701
702 /* If this inode has objects allocated to it (lsm != NULL), then the OST
703  * object(s) determine the file size and mtime.  Otherwise, the MDS will
704  * keep these values until such a time that objects are allocated for it.
705  * We do the MDS operations first, as it is checking permissions for us.
706  * We don't to the MDS RPC if there is nothing that we want to store there,
707  * otherwise there is no harm in updating mtime/atime on the MDS if we are
708  * going to do an RPC anyways.
709  *
710  * If we are doing a truncate, we will send the mtime and ctime updates
711  * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
712  * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
713  * at the same time.
714  */
715 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
716 {
717         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
718         struct ll_sb_info *sbi = ll_i2sbi(inode);
719         struct ptlrpc_request *request = NULL;
720         struct mdc_op_data op_data;
721         int ia_valid = attr->ia_valid;
722         int rc = 0;
723         ENTRY;
724
725         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
726         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
727
728         if (ia_valid & ATTR_SIZE) {
729                 if (attr->ia_size > ll_file_maxbytes(inode)) {
730                         CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
731                                attr->ia_size, ll_file_maxbytes(inode));
732                         RETURN(-EFBIG);
733                 }
734
735                 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
736         }
737
738         /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
739         if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
740                 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
741                         RETURN(-EPERM);
742         }
743
744         /* We mark all of the fields "set" so MDS/OST does not re-set them */
745         if (attr->ia_valid & ATTR_CTIME) {
746                 attr->ia_ctime = CURRENT_TIME;
747                 attr->ia_valid |= ATTR_CTIME_SET;
748         }
749         if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
750                 attr->ia_atime = CURRENT_TIME;
751                 attr->ia_valid |= ATTR_ATIME_SET;
752         }
753         if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
754                 attr->ia_mtime = CURRENT_TIME;
755                 attr->ia_valid |= ATTR_MTIME_SET;
756         }
757
758         if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
759                 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
760                        LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
761                        LTIME_S(CURRENT_TIME));
762         if (lsm)
763                 attr->ia_valid &= ~ATTR_SIZE;
764
765         /* If only OST attributes being set on objects, don't do MDS RPC.
766          * In that case, we need to check permissions and update the local
767          * inode ourselves so we can call obdo_from_inode() always. */
768         if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
769                 struct lustre_md md;
770                 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
771
772                 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
773                                  attr, NULL, 0, NULL, 0, &request);
774
775                 if (rc) {
776                         ptlrpc_req_finished(request);
777                         if (rc != -EPERM && rc != -EACCES)
778                                 CERROR("mdc_setattr fails: rc = %d\n", rc);
779                         RETURN(rc);
780                 }
781
782                 rc = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
783                 if (rc) {
784                         ptlrpc_req_finished(request);
785                         RETURN(rc);
786                 }
787
788                 /* Won't invoke vmtruncate as we already cleared ATTR_SIZE,
789                  * but needed to set timestamps backwards on utime. */
790                 inode_setattr(inode, attr);
791                 ll_update_inode(inode, md.body, md.lsm);
792                 ptlrpc_req_finished(request);
793
794                 if (!lsm || !S_ISREG(inode->i_mode)) {
795                         CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
796                         RETURN(0);
797                 }
798         } else {
799                 /* The OST doesn't check permissions, but the alternative is
800                  * a gratuitous RPC to the MDS.  We already rely on the client
801                  * to do read/write/truncate permission checks, so is mtime OK?
802                  */
803                 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
804                         /* from sys_utime() */
805                         if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
806                                 if (current->fsuid != inode->i_uid &&
807                                     (rc = ll_permission(inode, MAY_WRITE, NULL)) != 0)
808                                         RETURN(rc);
809                         } else {
810                                 /* from inode_change_ok() */
811                                 if (current->fsuid != inode->i_uid &&
812                                     !capable(CAP_FOWNER))
813                                         RETURN(-EPERM);
814                         }
815                 }
816
817                 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
818                 inode_setattr(inode, attr);
819         }
820
821         /* We really need to get our PW lock before we change inode->i_size.
822          * If we don't we can race with other i_size updaters on our node, like
823          * ll_file_read.  We can also race with i_size propogation to other
824          * nodes through dirtying and writeback of final cached pages.  This
825          * last one is especially bad for racing o_append users on other 
826          * nodes. */
827         if (ia_valid & ATTR_SIZE) {
828                 struct ldlm_extent extent = { .start = attr->ia_size,
829                                               .end = OBD_OBJECT_EOF };
830                 struct lustre_handle lockh = { 0 };
831                 int err, ast_flags = 0;
832                 /* XXX when we fix the AST intents to pass the discard-range
833                  * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
834                  * XXX here. */
835                 if (attr->ia_size == 0)
836                         ast_flags = LDLM_AST_DISCARD_DATA;
837
838                 /* bug 1639: avoid write/truncate i_sem/DLM deadlock */
839                 LASSERT(atomic_read(&inode->i_sem.count) <= 0);
840                 up(&inode->i_sem);
841                 rc = ll_extent_lock_no_validate(NULL, inode, lsm, LCK_PW,
842                                                 &extent, &lockh, ast_flags);
843                 down(&inode->i_sem);
844                 if (rc != ELDLM_OK)
845                         RETURN(rc);
846
847                 rc = vmtruncate(inode, attr->ia_size);
848                 if (rc == 0)
849                         set_bit(LLI_F_HAVE_OST_SIZE_LOCK,
850                                 &ll_i2info(inode)->lli_flags);
851
852                 //ll_try_done_writing(inode);
853
854                 /* unlock now as we don't mind others file lockers racing with
855                  * the mds updates below? */
856                 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
857                 if (err) {
858                         CERROR("ll_extent_unlock failed: %d\n", err);
859                         if (!rc)
860                                 rc = err;
861                 }
862         } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
863                 struct obdo oa;
864
865                 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
866                        inode->i_ino, LTIME_S(attr->ia_mtime));
867                 oa.o_id = lsm->lsm_object_id;
868                 oa.o_valid = OBD_MD_FLID;
869                 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
870                                             OBD_MD_FLMTIME | OBD_MD_FLCTIME);
871                 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
872                 if (rc)
873                         CERROR("obd_setattr fails: rc=%d\n", rc);
874         }
875         RETURN(rc);
876 }
877
878 int ll_setattr(struct dentry *de, struct iattr *attr)
879 {
880         LBUG(); /* code is unused, but leave this in case of VFS changes */
881         RETURN(-ENOSYS);
882 }
883
884 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
885                        unsigned long max_age)
886 {
887         struct ll_sb_info *sbi = ll_s2sbi(sb);
888         struct obd_statfs obd_osfs;
889         int rc;
890         ENTRY;
891
892         rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
893         if (rc) {
894                 CERROR("mdc_statfs fails: rc = %d\n", rc);
895                 RETURN(rc);
896         }
897
898         CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
899                osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
900
901         rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
902         if (rc) {
903                 CERROR("obd_statfs fails: rc = %d\n", rc);
904                 RETURN(rc);
905         }
906
907         CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
908                obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
909                obd_osfs.os_files);
910
911         osfs->os_blocks = obd_osfs.os_blocks;
912         osfs->os_bfree = obd_osfs.os_bfree;
913         osfs->os_bavail = obd_osfs.os_bavail;
914
915         /* If we don't have as many objects free on the OST as inodes
916          * on the MDS, we reduce the total number of inodes to
917          * compensate, so that the "inodes in use" number is correct.
918          */
919         if (obd_osfs.os_ffree < osfs->os_ffree) {
920                 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
921                         obd_osfs.os_ffree;
922                 osfs->os_ffree = obd_osfs.os_ffree;
923         }
924
925         RETURN(rc);
926 }
927
928 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
929 {
930         struct obd_statfs osfs;
931         int rc;
932
933         CDEBUG(D_VFSTRACE, "VFS Op:\n");
934         lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
935
936         /* For now we will always get up-to-date statfs values, but in the
937          * future we may allow some amount of caching on the client (e.g.
938          * from QOS or lprocfs updates). */
939         rc = ll_statfs_internal(sb, &osfs, jiffies - 1);
940         if (rc)
941                 return rc;
942
943         statfs_unpack(sfs, &osfs);
944
945         if (sizeof(sfs->f_blocks) == 4) {
946                 while (osfs.os_blocks > ~0UL) {
947                         sfs->f_bsize <<= 1;
948
949                         osfs.os_blocks >>= 1;
950                         osfs.os_bfree >>= 1;
951                         osfs.os_bavail >>= 1;
952                 }
953         }
954
955         sfs->f_blocks = osfs.os_blocks;
956         sfs->f_bfree = osfs.os_bfree;
957         sfs->f_bavail = osfs.os_bavail;
958
959         return 0;
960 }
961
962 void dump_lsm(int level, struct lov_stripe_md *lsm)
963 {
964         CDEBUG(level, "objid "LPX64", maxbytes "LPX64", magic 0x%08X, "
965                "stripe_size %u, stripe_count %u\n",
966                lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
967                lsm->lsm_stripe_size, lsm->lsm_stripe_count);
968 }
969
970 void ll_update_inode(struct inode *inode, struct mds_body *body,
971                      struct lov_stripe_md *lsm)
972 {
973         struct ll_inode_info *lli = ll_i2info(inode);
974
975         LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
976         if (lsm != NULL) {
977                 if (lli->lli_smd == NULL) {
978                         lli->lli_smd = lsm;
979                         lli->lli_maxbytes = lsm->lsm_maxbytes;
980                         if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
981                                 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
982                 } else {
983                         if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
984                                 CERROR("lsm mismatch for inode %ld\n",
985                                        inode->i_ino);
986                                 CERROR("lli_smd:\n");
987                                 dump_lsm(D_ERROR, lli->lli_smd);
988                                 CERROR("lsm:\n");
989                                 dump_lsm(D_ERROR, lsm);
990                                 LBUG();
991                         }
992                 }
993                 if (lli->lli_smd != lsm)
994                         obd_free_memmd(ll_i2obdexp(inode), &lsm);
995         }
996
997         if (body->valid & OBD_MD_FLID)
998                 inode->i_ino = body->ino;
999         if (body->valid & OBD_MD_FLATIME)
1000                 LTIME_S(inode->i_atime) = body->atime;
1001         if (body->valid & OBD_MD_FLMTIME &&
1002             body->mtime > LTIME_S(inode->i_mtime)) {
1003                 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %u\n",
1004                        inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
1005                 LTIME_S(inode->i_mtime) = body->mtime;
1006         }
1007         if (body->valid & OBD_MD_FLCTIME &&
1008             body->ctime > LTIME_S(inode->i_ctime))
1009                 LTIME_S(inode->i_ctime) = body->ctime;
1010         if (body->valid & OBD_MD_FLMODE)
1011                 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1012         if (body->valid & OBD_MD_FLTYPE)
1013                 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1014         if (body->valid & OBD_MD_FLUID)
1015                 inode->i_uid = body->uid;
1016         if (body->valid & OBD_MD_FLGID)
1017                 inode->i_gid = body->gid;
1018         if (body->valid & OBD_MD_FLFLAGS)
1019                 inode->i_flags = body->flags;
1020         if (body->valid & OBD_MD_FLNLINK)
1021                 inode->i_nlink = body->nlink;
1022         if (body->valid & OBD_MD_FLGENER)
1023                 inode->i_generation = body->generation;
1024         if (body->valid & OBD_MD_FLRDEV)
1025 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1026                 inode->i_rdev = body->rdev;
1027 #else
1028                 inode->i_rdev = old_encode_dev(body->rdev);
1029 #endif
1030         if (body->valid & OBD_MD_FLSIZE)
1031                 inode->i_size = body->size;
1032         if (body->valid & OBD_MD_FLBLOCKS)
1033                 inode->i_blocks = body->blocks;
1034
1035         if (body->valid & OBD_MD_FLSIZE)
1036                 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1037 }
1038
1039 void ll_read_inode2(struct inode *inode, void *opaque)
1040 {
1041         struct lustre_md *md = opaque;
1042         struct ll_inode_info *lli = ll_i2info(inode);
1043         ENTRY;
1044
1045         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1046                inode->i_generation, inode);
1047
1048         ll_lli_init(lli);
1049
1050         LASSERT(!lli->lli_smd);
1051
1052         /* Core attributes from the MDS first.  This is a new inode, and
1053          * the VFS doesn't zero times in the core inode so we have to do
1054          * it ourselves.  They will be overwritten by either MDS or OST
1055          * attributes - we just need to make sure they aren't newer. */
1056         LTIME_S(inode->i_mtime) = 0;
1057         LTIME_S(inode->i_atime) = 0;
1058         LTIME_S(inode->i_ctime) = 0;
1059         ll_update_inode(inode, md->body, md->lsm);
1060
1061         /* OIDEBUG(inode); */
1062
1063         if (S_ISREG(inode->i_mode)) {
1064                 inode->i_op = &ll_file_inode_operations;
1065                 inode->i_fop = &ll_file_operations;
1066                 inode->i_mapping->a_ops = &ll_aops;
1067                 EXIT;
1068         } else if (S_ISDIR(inode->i_mode)) {
1069                 inode->i_op = &ll_dir_inode_operations;
1070                 inode->i_fop = &ll_dir_operations;
1071                 inode->i_mapping->a_ops = &ll_dir_aops;
1072                 EXIT;
1073         } else if (S_ISLNK(inode->i_mode)) {
1074                 inode->i_op = &ll_fast_symlink_inode_operations;
1075                 EXIT;
1076         } else {
1077                 inode->i_op = &ll_special_inode_operations;
1078 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1079                 init_special_inode(inode, inode->i_mode,
1080                                    kdev_t_to_nr(inode->i_rdev));
1081 #else
1082                 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1083
1084                 lli->ll_save_ifop = inode->i_fop;
1085                 if (S_ISCHR(inode->i_mode)) {
1086                         inode->i_fop = &ll_special_chr_inode_fops;
1087                 } else if (S_ISBLK(inode->i_mode)) {
1088                         inode->i_fop = &ll_special_blk_inode_fops;
1089                 } else if (S_ISFIFO(inode->i_mode)) {
1090                         inode->i_fop = &ll_special_fifo_inode_fops;
1091                 } else if (S_ISSOCK(inode->i_mode)) {
1092                         inode->i_fop = &ll_special_sock_inode_fops;
1093                 }
1094                 inode->i_fop->owner = lli->ll_save_ifop->owner;
1095 #endif
1096                 EXIT;
1097         }
1098 }
1099
1100 int ll_iocontrol(struct inode *inode, struct file *file,
1101                  unsigned int cmd, unsigned long arg)
1102 {
1103         struct ll_sb_info *sbi = ll_i2sbi(inode);
1104         struct ptlrpc_request *req = NULL;
1105         int rc, flags = 0;
1106         ENTRY;
1107
1108         switch(cmd) {
1109         case EXT3_IOC_GETFLAGS: {
1110                 struct ll_fid fid;
1111                 unsigned long valid = OBD_MD_FLFLAGS;
1112                 struct mds_body *body;
1113
1114                 ll_inode2fid(&fid, inode);
1115                 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, 0, &req);
1116                 if (rc) {
1117                         CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1118                         RETURN(-abs(rc));
1119                 }
1120
1121                 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
1122
1123                 if (body->flags & S_APPEND)
1124                         flags |= EXT3_APPEND_FL;
1125                 if (body->flags & S_IMMUTABLE)
1126                         flags |= EXT3_IMMUTABLE_FL;
1127                 if (body->flags & S_NOATIME)
1128                         flags |= EXT3_NOATIME_FL;
1129
1130                 ptlrpc_req_finished (req);
1131
1132                 RETURN(put_user(flags, (int *)arg));
1133         }
1134         case EXT3_IOC_SETFLAGS: {
1135                 struct mdc_op_data op_data;
1136                 struct iattr attr;
1137                 struct obdo *oa;
1138                 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1139
1140                 if (get_user(flags, (int *)arg))
1141                         RETURN(-EFAULT);
1142
1143                 oa = obdo_alloc();
1144                 if (!oa)
1145                         RETURN(-ENOMEM);
1146
1147                 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1148
1149                 memset(&attr, 0x0, sizeof(attr));
1150                 attr.ia_attr_flags = flags;
1151                 attr.ia_valid |= ATTR_ATTR_FLAG;
1152
1153                 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1154                                  &attr, NULL, 0, NULL, 0, &req);
1155                 if (rc) {
1156                         ptlrpc_req_finished(req);
1157                         if (rc != -EPERM && rc != -EACCES)
1158                                 CERROR("mdc_setattr fails: rc = %d\n", rc);
1159                         obdo_free(oa);
1160                         RETURN(rc);
1161                 }
1162                 ptlrpc_req_finished(req);
1163
1164                 oa->o_id = lsm->lsm_object_id;
1165                 oa->o_flags = flags;
1166                 oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
1167
1168                 rc = obd_setattr(sbi->ll_osc_exp, oa, lsm, NULL);
1169                 obdo_free(oa);
1170                 if (rc) {
1171                         if (rc != -EPERM && rc != -EACCES)
1172                                 CERROR("mdc_setattr fails: rc = %d\n", rc);
1173                         RETURN(rc);
1174                 }
1175
1176                 if (flags & EXT3_APPEND_FL)
1177                         inode->i_flags |= S_APPEND;
1178                 else
1179                         inode->i_flags &= ~S_APPEND;
1180                 if (flags & EXT3_IMMUTABLE_FL)
1181                         inode->i_flags |= S_IMMUTABLE;
1182                 else
1183                         inode->i_flags &= ~S_IMMUTABLE;
1184                 if (flags & EXT3_NOATIME_FL)
1185                         inode->i_flags |= S_NOATIME;
1186                 else
1187                         inode->i_flags &= ~S_NOATIME;
1188
1189                 RETURN(0);
1190         }
1191         default:
1192                 RETURN(-ENOSYS);
1193         }
1194
1195         RETURN(0);
1196 }
1197
1198 void ll_umount_begin(struct super_block *sb)
1199 {
1200         struct ll_sb_info *sbi = ll_s2sbi(sb);
1201         struct obd_device *obd;
1202         struct obd_ioctl_data ioc_data = { 0 };
1203         ENTRY;
1204         CDEBUG(D_VFSTRACE, "VFS Op:\n");
1205
1206         obd = class_exp2obd(sbi->ll_mdc_exp);
1207         if (obd == NULL) {
1208                 CERROR("Invalid MDC connection handle "LPX64"\n",
1209                        sbi->ll_mdc_exp->exp_handle.h_cookie);
1210                 EXIT;
1211                 return;
1212         }
1213         obd->obd_no_recov = 1;
1214         obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
1215                       &ioc_data, NULL);
1216
1217         obd = class_exp2obd(sbi->ll_osc_exp);
1218         if (obd == NULL) {
1219                 CERROR("Invalid LOV connection handle "LPX64"\n",
1220                        sbi->ll_osc_exp->exp_handle.h_cookie);
1221                 EXIT;
1222                 return;
1223         }
1224
1225         obd->obd_no_recov = 1;
1226         obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
1227                       &ioc_data, NULL);
1228
1229         /* Really, we'd like to wait until there are no requests outstanding,
1230          * and then continue.  For now, we just invalidate the requests,
1231          * schedule, and hope.
1232          */
1233         schedule();
1234
1235         EXIT;
1236 }
1237
1238 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
1239                   struct ptlrpc_request *req, int offset,struct super_block *sb)
1240 {
1241         struct lustre_md md;
1242         int rc = 0;
1243
1244         rc = mdc_req2lustre_md(req, offset, exp, &md);
1245         if (rc)
1246                 RETURN(rc);
1247
1248         if (*inode) {
1249                 ll_update_inode(*inode, md.body, md.lsm);
1250         } else {
1251                 LASSERT(sb);
1252                 *inode = ll_iget(sb, md.body->ino, &md);
1253                 if (*inode == NULL || is_bad_inode(*inode)) {
1254                         /* free the lsm if we allocated one above */
1255                         if (md.lsm != NULL)
1256                                 obd_free_memmd(exp, &md.lsm);
1257                         rc = -ENOMEM;
1258                         CERROR("new_inode -fatal: rc %d\n", rc);
1259                 }
1260         }
1261
1262         RETURN(rc);
1263 }