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