1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
24 #define DEBUG_SUBSYSTEM S_LLITE
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/random.h>
29 #include <linux/version.h>
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 <linux/lustre_snap.h>
36 #include "llite_internal.h"
38 kmem_cache_t *ll_file_data_slab;
40 extern struct address_space_operations ll_aops;
41 extern struct address_space_operations ll_dir_aops;
44 #define log2(n) ffz(~(n))
47 struct ll_sb_info *lustre_init_sbi(struct super_block *sb)
49 struct ll_sb_info *sbi = NULL;
53 OBD_ALLOC(sbi, sizeof(*sbi));
57 spin_lock_init(&sbi->ll_lock);
58 INIT_LIST_HEAD(&sbi->ll_pglist);
59 sbi->ll_pglist_gen = 0;
60 sbi->ll_max_read_ahead_pages = SBI_DEFAULT_RA_MAX;
61 INIT_LIST_HEAD(&sbi->ll_conn_chain);
62 INIT_HLIST_HEAD(&sbi->ll_orphan_dentry_list);
63 INIT_LIST_HEAD(&sbi->ll_mnt_list);
64 sema_init(&sbi->ll_gns_sem, 1);
65 init_completion(&sbi->ll_gns_completion);
66 sbi->ll_gns_state = LL_GNS_STATE_IDLE;
67 sbi->ll_gns_timer.data = (unsigned long)sbi;
68 sbi->ll_gns_timer.function = ll_gns_timer_callback;
69 init_timer(&sbi->ll_gns_timer);
70 INIT_LIST_HEAD(&sbi->ll_gns_sbi_head);
74 generate_random_uuid(uuid);
75 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
79 void lustre_free_sbi(struct super_block *sb)
81 struct ll_sb_info *sbi = ll_s2sbi(sb);
85 list_del(&sbi->ll_gns_sbi_head);
86 del_timer(&sbi->ll_gns_timer);
87 OBD_FREE(sbi, sizeof(*sbi));
93 int lustre_init_ea_size(struct ll_sb_info *sbi)
98 /* OSC may have larger ea size */
99 valsize = sizeof(desc);
100 rc = obd_get_info(sbi->ll_osc_exp, strlen("lovdesc") + 1, "lovdesc",
103 obd_init_ea_size(sbi->ll_mdc_exp,
104 obd_size_diskmd(sbi->ll_osc_exp, NULL),
105 desc.ld_tgt_count*sizeof(struct llog_cookie));
107 /* declare ourself as real client. not connection
109 * FIXME: remove fake valsize, mdsize --bzzz */
110 rc = obd_set_info(sbi->ll_mdc_exp, strlen("client"),
111 "client", valsize, &desc);
116 int lustre_set_clone_info(struct super_block *sb, int clone_index)
118 struct ll_sb_info *sbi = ll_s2sbi(sb);
122 CDEBUG(D_INFO, "set clone index %d\n", clone_index);
126 if (sbi->ll_mdc_exp) {
127 struct obd_import *climp = class_exp2cliimp(sbi->ll_mdc_exp);
128 struct client_obd *cl_obd = &climp->imp_obd->u.cli;
130 OBD_ALLOC(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
131 if (!cl_obd->cl_clone_info)
133 SET_CLONE_INDEX(cl_obd->cl_clone_info, clone_index);
134 SET_CLONE_FLAGS(cl_obd->cl_clone_info, SM_CLONE_FS);
137 if (sbi->ll_osc_exp) {
138 struct obd_import *climp = class_exp2cliimp(sbi->ll_osc_exp);
139 struct client_obd *cl_obd = &climp->imp_obd->u.cli;
141 OBD_ALLOC(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
142 if (!cl_obd->cl_clone_info)
144 SET_CLONE_INDEX(cl_obd->cl_clone_info, clone_index);
145 SET_CLONE_FLAGS(cl_obd->cl_clone_info, SM_CLONE_FS);
150 int lustre_cleanup_clone_info(struct super_block *sb)
152 struct ll_sb_info *sbi = ll_s2sbi(sb);
156 if (sbi->ll_mdc_exp) {
157 struct obd_import *climp = class_exp2cliimp(sbi->ll_mdc_exp);
158 struct client_obd *cl_obd = &climp->imp_obd->u.cli;
160 if (!cl_obd->cl_clone_info)
162 CDEBUG(D_INFO, "clean clone info %p\n", cl_obd->cl_clone_info);
163 OBD_FREE(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
166 if (sbi->ll_osc_exp) {
167 struct obd_import *climp = class_exp2cliimp(sbi->ll_osc_exp);
168 struct client_obd *cl_obd = &climp->imp_obd->u.cli;
170 if (!cl_obd->cl_clone_info)
172 CDEBUG(D_INFO, "clean clone info %p\n", cl_obd->cl_clone_info);
173 OBD_FREE(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
180 int lustre_common_fill_super(struct super_block *sb, char *mdc, char *osc)
182 struct inode *root = 0;
183 struct ll_sb_info *sbi = ll_s2sbi(sb);
184 struct obd_device *obd;
185 struct ll_fid rootfid;
186 struct obd_statfs osfs;
187 struct ptlrpc_request *request = NULL;
188 struct lustre_handle osc_conn = {0, };
189 struct lustre_handle mdc_conn = {0, };
194 obd = class_name2obd(mdc);
196 CERROR("MDC %s: not setup or attached\n", mdc);
200 if (proc_lustre_fs_root) {
201 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
204 CERROR("could not register mount in /proc/lustre");
207 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid);
209 CERROR("An MDS (mdc %s) is performing recovery, of which this"
210 " client is not a part. Please wait for recovery to "
211 "complete, abort, or time out.\n", mdc);
214 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
217 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
219 err = obd_statfs(obd, &osfs, jiffies - HZ);
223 LASSERT(osfs.os_bsize);
224 sb->s_blocksize = osfs.os_bsize;
225 sb->s_blocksize_bits = log2(osfs.os_bsize);
226 sb->s_magic = LL_SUPER_MAGIC;
227 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
229 devno = get_uuid2int(sbi->ll_mdc_exp->exp_obd->obd_uuid.uuid,
230 strlen(sbi->ll_mdc_exp->exp_obd->obd_uuid.uuid));
234 obd = class_name2obd(osc);
236 CERROR("OSC %s: not setup or attached\n", osc);
240 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid);
242 CERROR("An OST (osc %s) is performing recovery, of which this"
243 " client is not a part. Please wait for recovery to "
244 "complete, abort, or time out.\n", osc);
247 CERROR("cannot connect to %s: rc = %d\n", osc, err);
250 sbi->ll_osc_exp = class_conn2export(&osc_conn);
252 lustre_init_ea_size(sbi);
254 err = md_getstatus(sbi->ll_mdc_exp, &rootfid);
256 CERROR("cannot mds_connect: rc = %d\n", err);
259 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
260 sbi->ll_rootino = rootfid.id;
262 sb->s_op = &lustre_super_operations;
265 * XXX: move this to after cbd setup? */
266 err = md_getattr(sbi->ll_mdc_exp, &rootfid,
267 OBD_MD_FLNOTOBD | OBD_MD_FLBLOCKS, 0, &request);
269 CERROR("md_getattr failed for root: rc = %d\n", err);
273 err = mdc_req2lustre_md(sbi->ll_mdc_exp, request, 0,
274 sbi->ll_osc_exp, &md);
276 CERROR("failed to understand root inode md: rc = %d\n",err);
277 ptlrpc_req_finished (request);
281 LASSERT(sbi->ll_rootino != 0);
282 root = ll_iget(sb, sbi->ll_rootino, &md);
284 ptlrpc_req_finished(request);
286 if (root == NULL || is_bad_inode(root)) {
287 /* XXX might need iput() for bad inode */
288 CERROR("lustre_lite: bad iget4 for root\n");
289 GOTO(out_root, err = -EBADF);
292 err = ll_close_thread_start(&sbi->ll_lcq);
294 CERROR("cannot start close thread: rc %d\n", err);
298 ll_gns_add_timer(sbi);
300 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
301 backing dev info assigned to inode mapping is used for
302 determining maximal readahead. */
303 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
304 /* bug 2805 - set VM readahead to zero */
305 vm_max_readahead = vm_min_readahead = 0;
308 sb->s_root = d_alloc_root(root);
311 CWARN("Enabling PDIROPS\n");
312 sb->s_flags |= S_PDIROPS;
321 obd_disconnect(sbi->ll_osc_exp, 0);
323 obd_disconnect(sbi->ll_mdc_exp, 0);
325 lprocfs_unregister_mountpoint(sbi);
329 void lustre_common_put_super(struct super_block *sb)
331 struct ll_sb_info *sbi = ll_s2sbi(sb);
332 struct hlist_node *tmp, *next;
335 ll_gns_del_timer(sbi);
337 ll_close_thread_shutdown(sbi->ll_lcq);
339 list_del(&sbi->ll_conn_chain);
340 obd_disconnect(sbi->ll_osc_exp, 0);
342 lprocfs_unregister_mountpoint(sbi);
343 if (sbi->ll_proc_root) {
344 lprocfs_remove(sbi->ll_proc_root);
345 sbi->ll_proc_root = NULL;
348 obd_disconnect(sbi->ll_mdc_exp, 0);
350 // We do this to get rid of orphaned dentries. That is not really trw.
351 spin_lock(&dcache_lock);
352 hlist_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list) {
353 struct dentry *dentry = hlist_entry(tmp, struct dentry, d_hash);
354 CWARN("orphan dentry %*s (%p) at unmount\n",
355 dentry->d_name.len, dentry->d_name.name, dentry);
356 shrink_dcache_parent(dentry);
358 spin_unlock(&dcache_lock);
363 char *ll_read_opt(const char *opt, char *data)
369 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
370 if (strncmp(opt, data, strlen(opt)))
372 if ((value = strchr(data, '=')) == NULL)
376 OBD_ALLOC(retval, strlen(value) + 1);
378 CERROR("out of memory!\n");
382 memcpy(retval, value, strlen(value)+1);
383 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
387 int ll_set_opt(const char *opt, char *data, int fl)
391 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
392 if (strncmp(opt, data, strlen(opt)))
398 void ll_options(char *options, char **ost, char **mdc, int *flags,
402 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
403 char *opt_ptr = options;
412 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
413 for (this_char = strtok (options, ",");
415 this_char = strtok (NULL, ",")) {
417 while ((this_char = strsep (&opt_ptr, ",")) != NULL) {
419 CDEBUG(D_SUPER, "this_char %s\n", this_char);
420 if (!*ost && (*ost = ll_read_opt("osc", this_char)))
422 if (!*mdc && (*mdc = ll_read_opt("mdc", this_char)))
424 if (!*clone_opts && (*clone_opts = ll_read_opt("clone",
427 if (!(*flags & LL_SBI_NOLCK) &&
428 ((*flags) = (*flags) |
429 ll_set_opt("nolock", this_char,
437 void ll_lli_init(struct ll_inode_info *lli)
439 sema_init(&lli->lli_open_sem, 1);
441 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
442 spin_lock_init(&lli->lli_lock);
443 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
444 lli->lli_inode_magic = LLI_INODE_MAGIC;
447 int ll_fill_super(struct super_block *sb, void *data, int silent)
449 struct ll_sb_info *sbi;
452 char *clone_opts = NULL;
456 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
458 sbi = lustre_init_sbi(sb);
462 sbi->ll_flags |= LL_SBI_READAHEAD;
463 ll_options(data, &osc, &mdc, &sbi->ll_flags, &clone_opts);
467 GOTO(out, err = -EINVAL);
472 GOTO(out, err = -EINVAL);
475 err = lustre_common_fill_super(sb, mdc, osc);
481 /*set clone info to the super block*/
482 clone_index = simple_strtoul(clone_opts, &endp, 0);
483 err = lustre_set_clone_info(sb, clone_index);
491 OBD_FREE(mdc, strlen(mdc) + 1);
493 OBD_FREE(osc, strlen(osc) + 1);
495 OBD_FREE(clone_opts, strlen(clone_opts) + 1);
498 } /* ll_read_super */
500 static int lustre_process_log(struct lustre_mount_data *lmd, char *profile,
501 struct config_llog_instance *cfg, int allow_recov)
503 struct lustre_cfg lcfg;
504 struct portals_cfg pcfg;
505 char * peer = "MDS_PEER_UUID";
506 struct obd_device *obd;
507 struct lustre_handle mdc_conn = {0, };
508 struct obd_export *exp;
509 char * name = "mdc_dev";
511 struct obd_uuid mdc_uuid;
512 struct llog_ctxt *ctxt;
517 if (lmd_bad_magic(lmd))
520 generate_random_uuid(uuid);
521 class_uuid_unparse(uuid, &mdc_uuid);
523 if (lmd->lmd_local_nid) {
524 PCFG_INIT(pcfg, NAL_CMD_REGISTER_MYNID);
525 pcfg.pcfg_nal = lmd->lmd_nal;
526 pcfg.pcfg_nid = lmd->lmd_local_nid;
527 err = libcfs_nal_cmd(&pcfg);
532 if (lmd->lmd_nal == SOCKNAL) {
533 PCFG_INIT(pcfg, NAL_CMD_ADD_AUTOCONN);
534 pcfg.pcfg_nal = lmd->lmd_nal;
535 pcfg.pcfg_nid = lmd->lmd_server_nid;
536 pcfg.pcfg_id = lmd->lmd_server_ipaddr;
537 pcfg.pcfg_misc = lmd->lmd_port;
538 pcfg.pcfg_size = 8388608;
539 pcfg.pcfg_flags = 0x4; /*share*/
540 err = libcfs_nal_cmd(&pcfg);
545 LCFG_INIT(lcfg, LCFG_ADD_UUID, name);
546 lcfg.lcfg_nid = lmd->lmd_server_nid;
547 lcfg.lcfg_inllen1 = strlen(peer) + 1;
548 lcfg.lcfg_inlbuf1 = peer;
549 lcfg.lcfg_nal = lmd->lmd_nal;
550 err = class_process_config(&lcfg);
552 GOTO(out_del_conn, err);
554 LCFG_INIT(lcfg, LCFG_ATTACH, name);
555 lcfg.lcfg_inlbuf1 = "mdc";
556 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
557 lcfg.lcfg_inlbuf2 = mdc_uuid.uuid;
558 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
559 err = class_process_config(&lcfg);
561 GOTO(out_del_uuid, err);
563 LCFG_INIT(lcfg, LCFG_SETUP, name);
564 lcfg.lcfg_inlbuf1 = lmd->lmd_mds;
565 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
566 lcfg.lcfg_inlbuf2 = peer;
567 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
568 err = class_process_config(&lcfg);
570 GOTO(out_detach, err);
572 obd = class_name2obd(name);
574 GOTO(out_cleanup, err = -EINVAL);
576 /* Disable initial recovery on this import */
577 err = obd_set_info(obd->obd_self_export,
578 strlen("initial_recov"), "initial_recov",
579 sizeof(allow_recov), &allow_recov);
581 GOTO(out_cleanup, err);
583 err = obd_connect(&mdc_conn, obd, &mdc_uuid);
585 CERROR("cannot connect to %s: rc = %d\n", lmd->lmd_mds, err);
586 GOTO(out_cleanup, err);
589 exp = class_conn2export(&mdc_conn);
591 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,LLOG_CONFIG_REPL_CTXT);
592 rc = class_config_process_llog(ctxt, profile, cfg);
594 CERROR("class_config_process_llog failed: rc = %d\n", rc);
596 err = obd_disconnect(exp, 0);
599 LCFG_INIT(lcfg, LCFG_CLEANUP, name);
600 err = class_process_config(&lcfg);
605 LCFG_INIT(lcfg, LCFG_DETACH, name);
606 err = class_process_config(&lcfg);
611 LCFG_INIT(lcfg, LCFG_DEL_UUID, name);
612 lcfg.lcfg_inllen1 = strlen(peer) + 1;
613 lcfg.lcfg_inlbuf1 = peer;
614 err = class_process_config(&lcfg);
617 if (lmd->lmd_nal == SOCKNAL) {
618 PCFG_INIT(pcfg, NAL_CMD_DEL_AUTOCONN);
619 pcfg.pcfg_nal = lmd->lmd_nal;
620 pcfg.pcfg_nid = lmd->lmd_server_nid;
621 pcfg.pcfg_id = lmd->lmd_server_ipaddr;
622 pcfg.pcfg_flags = 1; /*share*/
623 err = libcfs_nal_cmd(&pcfg);
634 int lustre_fill_super(struct super_block *sb, void *data, int silent)
636 struct lustre_mount_data * lmd = data;
637 struct ll_sb_info *sbi;
643 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
644 if (lmd_bad_magic(lmd))
647 sbi = lustre_init_sbi(sb);
651 sbi->ll_flags |= LL_SBI_READAHEAD;
653 if (lmd->lmd_profile) {
654 struct lustre_profile *lprof;
655 struct config_llog_instance cfg;
658 if (lmd->lmd_mds[0] == '\0') {
659 CERROR("no mds name\n");
660 GOTO(out_free, err = -EINVAL);
663 OBD_ALLOC(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
664 if (sbi->ll_lmd == NULL)
665 GOTO(out_free, err = -ENOMEM);
666 memcpy(sbi->ll_lmd, lmd, sizeof(*lmd));
668 /* generate a string unique to this super, let's try
669 the address of the super itself.*/
670 len = (sizeof(sb) * 2) + 1;
671 OBD_ALLOC(sbi->ll_instance, len);
672 if (sbi->ll_instance == NULL)
673 GOTO(out_free, err = -ENOMEM);
674 sprintf(sbi->ll_instance, "%p", sb);
676 cfg.cfg_instance = sbi->ll_instance;
677 cfg.cfg_uuid = sbi->ll_sb_uuid;
678 cfg.cfg_local_nid = lmd->lmd_local_nid;
679 err = lustre_process_log(lmd, lmd->lmd_profile, &cfg, 0);
681 CERROR("Unable to process log: %s\n", lmd->lmd_profile);
685 lprof = class_get_profile(lmd->lmd_profile);
687 CERROR("No profile found: %s\n", lmd->lmd_profile);
688 GOTO(out_free, err = -EINVAL);
691 OBD_FREE(osc, strlen(osc) + 1);
692 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
693 strlen(sbi->ll_instance) + 2);
694 sprintf(osc, "%s-%s", lprof->lp_osc, sbi->ll_instance);
697 OBD_FREE(mdc, strlen(mdc) + 1);
698 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
699 strlen(sbi->ll_instance) + 2);
700 sprintf(mdc, "%s-%s", lprof->lp_mdc, sbi->ll_instance);
705 GOTO(out_free, err = -EINVAL);
710 GOTO(out_free, err = -EINVAL);
713 err = lustre_common_fill_super(sb, mdc, osc);
719 if (lmd->lmd_clone_index) {
720 err = lustre_set_clone_info(sb, lmd->lmd_clone_index);
729 OBD_FREE(mdc, strlen(mdc) + 1);
731 OBD_FREE(osc, strlen(osc) + 1);
737 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
740 if (sbi->ll_instance != NULL) {
741 struct lustre_mount_data *lmd = sbi->ll_lmd;
743 struct config_llog_instance cfg;
745 cfg.cfg_instance = sbi->ll_instance;
746 cfg.cfg_uuid = sbi->ll_sb_uuid;
748 OBD_ALLOC(cln_prof, len);
749 sprintf(cln_prof, "%s-clean", lmd->lmd_profile);
751 err = lustre_process_log(lmd, cln_prof, &cfg, 0);
753 CERROR("Unable to process log: %s\n", cln_prof);
754 OBD_FREE(cln_prof, len);
755 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance)+ 1);
757 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
760 lustre_cleanup_clone_info(sb);
765 } /* lustre_fill_super */
767 static void lustre_manual_cleanup(struct ll_sb_info *sbi)
769 struct lustre_cfg lcfg;
770 struct obd_device *obd;
773 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) != NULL)
777 LCFG_INIT(lcfg, LCFG_CLEANUP, obd->obd_name);
778 err = class_process_config(&lcfg);
780 CERROR("cleanup failed: %s\n", obd->obd_name);
784 LCFG_INIT(lcfg, LCFG_DETACH, obd->obd_name);
785 err = class_process_config(&lcfg);
787 CERROR("detach failed: %s\n", obd->obd_name);
792 if (sbi->ll_lmd != NULL)
793 class_del_profile(sbi->ll_lmd->lmd_profile);
796 void lustre_put_super(struct super_block *sb)
798 struct obd_device *obd;
799 struct ll_sb_info *sbi = ll_s2sbi(sb);
800 int force_umount = 0;
803 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
804 obd = class_exp2obd(sbi->ll_mdc_exp);
806 force_umount = obd->obd_no_recov;
810 lustre_cleanup_clone_info(sb);
813 lustre_common_put_super(sb);
814 if (sbi->ll_lmd != NULL) {
816 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
818 struct config_llog_instance cfg;
821 CERROR("force umount, doing manual cleanup\n");
822 lustre_manual_cleanup(sbi);
826 cfg.cfg_instance = sbi->ll_instance;
827 cfg.cfg_uuid = sbi->ll_sb_uuid;
829 OBD_ALLOC(cln_prof, len);
830 sprintf(cln_prof, "%s-clean", sbi->ll_lmd->lmd_profile);
832 err = lustre_process_log(sbi->ll_lmd, cln_prof, &cfg, 0);
834 CERROR("Unable to process log: %s, doing manual cleanup"
836 lustre_manual_cleanup(sbi);
839 OBD_FREE(cln_prof, len);
841 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
842 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance) + 1);
848 } /* lustre_put_super */
850 int ll_process_config_update(struct ll_sb_info *sbi, int clean)
852 struct obd_export *mdc_exp = sbi->ll_mdc_exp;
853 struct lustre_mount_data *lmd = sbi->ll_lmd;
854 struct llog_ctxt *ctxt;
855 struct config_llog_instance cfg;
856 char *profile = lmd->lmd_profile, *name = NULL;
857 int rc, namelen = 0, version;
863 CERROR("Client not mounted with zero-conf; cannot process "
868 rc = ldlm_cli_cancel_unused(mdc_exp->exp_obd->obd_namespace, NULL,
869 LDLM_FL_CONFIG_CHANGE, NULL);
871 CWARN("ldlm_cli_cancel_unused(mdc): %d\n", rc);
873 rc = obd_cancel_unused(sbi->ll_osc_exp, NULL, LDLM_FL_CONFIG_CHANGE,
876 CWARN("obd_cancel_unused(lov): %d\n", rc);
878 cfg.cfg_instance = sbi->ll_instance;
879 cfg.cfg_uuid = sbi->ll_sb_uuid;
880 cfg.cfg_local_nid = lmd->lmd_local_nid;
882 namelen = strlen(profile) + 20; /* -clean-######### */
883 OBD_ALLOC(name, namelen);
888 version = sbi->ll_config_version - 1;
889 sprintf(name, "%s-clean-%d", profile, version);
891 version = sbi->ll_config_version + 1;
892 sprintf(name, "%s-%d", profile, version);
895 CWARN("Applying configuration log %s\n", name);
897 ctxt = llog_get_context(&mdc_exp->exp_obd->obd_llogs,
898 LLOG_CONFIG_REPL_CTXT);
899 rc = class_config_process_llog(ctxt, name, &cfg);
901 sbi->ll_config_version = version;
902 CWARN("Finished applying configuration log %s: %d\n", name, rc);
904 if (rc == 0 && clean == 0) {
905 struct lov_desc desc;
907 valsize = sizeof(desc);
908 rc = obd_get_info(sbi->ll_osc_exp, strlen("lovdesc") + 1,
909 "lovdesc", &valsize, &desc);
911 rc = obd_init_ea_size(mdc_exp,
912 obd_size_diskmd(sbi->ll_osc_exp, NULL),
914 sizeof(struct llog_cookie)));
916 OBD_FREE(name, namelen);
920 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
922 struct inode *inode = NULL;
923 l_lock(&lock->l_resource->lr_namespace->ns_lock);
924 if (lock->l_ast_data) {
925 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
926 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
927 inode = igrab(lock->l_ast_data);
929 CERROR("DEBUG: l_ast_data %p is bogus: magic %x\n",
930 lock->l_ast_data, lli->lli_inode_magic);
933 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
937 int null_if_equal(struct ldlm_lock *lock, void *data)
939 if (data == lock->l_ast_data)
940 lock->l_ast_data = NULL;
942 if (lock->l_req_mode != lock->l_granted_mode)
943 return LDLM_ITER_STOP;
945 return LDLM_ITER_CONTINUE;
948 void ll_clear_inode(struct inode *inode)
951 struct ll_inode_info *lli = ll_i2info(inode);
952 struct ll_sb_info *sbi = ll_i2sbi(inode);
955 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
956 inode->i_generation, inode);
958 lli->lli_inode_magic = LLI_INODE_DEAD;
959 ll_inode2fid(&fid, inode);
960 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(ll_i2info(inode)->lli_flags));
961 md_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
964 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
965 null_if_equal, inode);
968 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
973 /* FIXME: change cbdata for mea here */
974 obd_free_memmd(sbi->ll_mdc_exp,
975 (struct lov_stripe_md **) &lli->lli_mea);
979 if (lli->lli_symlink_name) {
980 OBD_FREE(lli->lli_symlink_name,
981 strlen(lli->lli_symlink_name) + 1);
982 lli->lli_symlink_name = NULL;
988 /* If this inode has objects allocated to it (lsm != NULL), then the OST
989 * object(s) determine the file size and mtime. Otherwise, the MDS will
990 * keep these values until such a time that objects are allocated for it.
991 * We do the MDS operations first, as it is checking permissions for us.
992 * We don't to the MDS RPC if there is nothing that we want to store there,
993 * otherwise there is no harm in updating mtime/atime on the MDS if we are
994 * going to do an RPC anyways.
996 * If we are doing a truncate, we will send the mtime and ctime updates
997 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
998 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1001 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1003 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1004 struct ll_sb_info *sbi = ll_i2sbi(inode);
1005 struct ptlrpc_request *request = NULL;
1006 struct mdc_op_data op_data;
1007 int ia_valid = attr->ia_valid;
1011 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
1012 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
1014 if (ia_valid & ATTR_SIZE) {
1015 if (attr->ia_size > ll_file_maxbytes(inode)) {
1016 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1017 attr->ia_size, ll_file_maxbytes(inode));
1021 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1024 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1025 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1026 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1030 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1031 if (attr->ia_valid & ATTR_CTIME) {
1032 attr->ia_ctime = CURRENT_TIME;
1033 attr->ia_valid |= ATTR_CTIME_SET;
1035 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1036 attr->ia_atime = CURRENT_TIME;
1037 attr->ia_valid |= ATTR_ATIME_SET;
1039 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1040 attr->ia_mtime = CURRENT_TIME;
1041 attr->ia_valid |= ATTR_MTIME_SET;
1044 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1045 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1046 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1047 LTIME_S(CURRENT_TIME));
1049 attr->ia_valid &= ~ATTR_SIZE;
1051 /* If only OST attributes being set on objects, don't do MDS RPC.
1052 * In that case, we need to check permissions and update the local
1053 * inode ourselves so we can call obdo_from_inode() always. */
1054 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
1055 struct lustre_md md;
1056 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1058 rc = md_setattr(sbi->ll_mdc_exp, &op_data,
1059 attr, NULL, 0, NULL, 0, &request);
1061 ptlrpc_req_finished(request);
1062 if (rc != -EPERM && rc != -EACCES)
1063 CERROR("md_setattr fails: rc = %d\n", rc);
1067 rc = mdc_req2lustre_md(sbi->ll_mdc_exp, request, 0,
1068 sbi->ll_osc_exp, &md);
1070 ptlrpc_req_finished(request);
1074 /* Won't invoke vmtruncate as we already cleared ATTR_SIZE,
1075 * but needed to set timestamps backwards on utime. */
1076 inode_setattr(inode, attr);
1077 ll_update_inode(inode, &md);
1078 ptlrpc_req_finished(request);
1080 if (!lsm || !S_ISREG(inode->i_mode)) {
1081 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1085 /* The OST doesn't check permissions, but the alternative is
1086 * a gratuitous RPC to the MDS. We already rely on the client
1087 * to do read/write/truncate permission checks, so is mtime OK?
1089 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
1090 /* from sys_utime() */
1091 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
1092 if (current->fsuid != inode->i_uid &&
1093 (rc=ll_permission(inode,MAY_WRITE,NULL))!=0)
1096 /* from inode_change_ok() */
1097 if (current->fsuid != inode->i_uid &&
1098 !capable(CAP_FOWNER))
1103 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
1104 inode_setattr(inode, attr);
1107 /* We really need to get our PW lock before we change inode->i_size.
1108 * If we don't we can race with other i_size updaters on our node, like
1109 * ll_file_read. We can also race with i_size propogation to other
1110 * nodes through dirtying and writeback of final cached pages. This
1111 * last one is especially bad for racing o_append users on other
1113 if (ia_valid & ATTR_SIZE) {
1114 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
1116 struct lustre_handle lockh = { 0 };
1117 int err, ast_flags = 0;
1118 /* XXX when we fix the AST intents to pass the discard-range
1119 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1121 if (attr->ia_size == 0)
1122 ast_flags = LDLM_AST_DISCARD_DATA;
1124 /* bug 1639: avoid write/truncate i_sem/DLM deadlock */
1125 LASSERT(atomic_read(&inode->i_sem.count) <= 0);
1127 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy, &lockh,
1129 down(&inode->i_sem);
1133 rc = vmtruncate(inode, attr->ia_size);
1135 /* We need to drop the semaphore here, because this unlock may
1136 * result in a cancellation, which will need the i_sem */
1138 /* unlock now as we don't mind others file lockers racing with
1139 * the mds updates below? */
1140 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1141 down(&inode->i_sem);
1143 CERROR("ll_extent_unlock failed: %d\n", err);
1147 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1150 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1151 inode->i_ino, LTIME_S(attr->ia_mtime));
1152 oa.o_id = lsm->lsm_object_id;
1153 oa.o_gr = lsm->lsm_object_gr;
1154 oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1155 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
1156 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
1157 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
1159 CERROR("obd_setattr fails: rc=%d\n", rc);
1164 int ll_setattr(struct dentry *de, struct iattr *attr)
1166 LBUG(); /* code is unused, but leave this in case of VFS changes */
1170 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1171 unsigned long max_age)
1173 struct ll_sb_info *sbi = ll_s2sbi(sb);
1174 struct obd_statfs obd_osfs;
1178 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1180 CERROR("mdc_statfs fails: rc = %d\n", rc);
1184 osfs->os_type = sb->s_magic;
1186 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1187 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1189 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1191 CERROR("obd_statfs fails: rc = %d\n", rc);
1195 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1196 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1199 osfs->os_blocks = obd_osfs.os_blocks;
1200 osfs->os_bfree = obd_osfs.os_bfree;
1201 osfs->os_bavail = obd_osfs.os_bavail;
1203 /* If we don't have as many objects free on the OST as inodes
1204 * on the MDS, we reduce the total number of inodes to
1205 * compensate, so that the "inodes in use" number is correct.
1207 if (obd_osfs.os_ffree < osfs->os_ffree) {
1208 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1210 osfs->os_ffree = obd_osfs.os_ffree;
1216 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1218 struct obd_statfs osfs;
1221 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1222 lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
1224 /* For now we will always get up-to-date statfs values, but in the
1225 * future we may allow some amount of caching on the client (e.g.
1226 * from QOS or lprocfs updates). */
1227 rc = ll_statfs_internal(sb, &osfs, jiffies - 1);
1231 statfs_unpack(sfs, &osfs);
1233 if (sizeof(sfs->f_blocks) == 4) {
1234 while (osfs.os_blocks > ~0UL) {
1237 osfs.os_blocks >>= 1;
1238 osfs.os_bfree >>= 1;
1239 osfs.os_bavail >>= 1;
1243 sfs->f_blocks = osfs.os_blocks;
1244 sfs->f_bfree = osfs.os_bfree;
1245 sfs->f_bavail = osfs.os_bavail;
1250 void dump_lsm(int level, struct lov_stripe_md *lsm)
1252 CDEBUG(level, "objid "LPX64", maxbytes "LPX64", magic 0x%08X, "
1253 "stripe_size %u, stripe_count %u\n",
1254 lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
1255 lsm->lsm_stripe_size, lsm->lsm_stripe_count);
1258 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1260 struct ll_inode_info *lli = ll_i2info(inode);
1261 struct mds_body *body = md->body;
1262 struct lov_stripe_md *lsm = md->lsm;
1263 struct mea *mea = md->mea;
1266 LASSERT((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1267 LASSERT((mea != NULL) == ((body->valid & OBD_MD_FLDIREA) != 0));
1269 LASSERT(lsm->lsm_object_gr > 0);
1270 if (lli->lli_smd == NULL) {
1272 lli->lli_maxbytes = lsm->lsm_maxbytes;
1273 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1274 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1277 if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
1278 CERROR("lsm mismatch for inode %ld\n",
1280 CERROR("lli_smd:\n");
1281 dump_lsm(D_ERROR, lli->lli_smd);
1283 dump_lsm(D_ERROR, lsm);
1286 /* XXX FIXME -- We should decide on a safer (atomic) and
1287 * more elegant way to update the lsm */
1288 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1289 lli->lli_smd->lsm_oinfo[i].loi_id =
1290 lsm->lsm_oinfo[i].loi_id;
1291 lli->lli_smd->lsm_oinfo[i].loi_gr =
1292 lsm->lsm_oinfo[i].loi_gr;
1293 lli->lli_smd->lsm_oinfo[i].loi_ost_idx =
1294 lsm->lsm_oinfo[i].loi_ost_idx;
1295 lli->lli_smd->lsm_oinfo[i].loi_ost_gen =
1296 lsm->lsm_oinfo[i].loi_ost_gen;
1299 /* bug 2844 - limit i_blksize for broken user-space apps */
1300 LASSERTF(lsm->lsm_xfersize != 0, "%lu\n", lsm->lsm_xfersize);
1301 inode->i_blksize = min(lsm->lsm_xfersize, LL_MAX_BLKSIZE);
1302 if (lli->lli_smd != lsm)
1303 obd_free_memmd(ll_i2obdexp(inode), &lsm);
1307 if (lli->lli_mea == NULL) {
1310 if (memcmp(lli->lli_mea, mea, body->eadatasize)) {
1311 CERROR("mea mismatch for inode %lu\n",
1316 if (lli->lli_mea != mea)
1317 obd_free_memmd(ll_i2mdcexp(inode),
1318 (struct lov_stripe_md **) &mea);
1322 if (body->valid & OBD_MD_FLID)
1323 inode->i_ino = body->ino;
1324 if (body->valid & OBD_MD_FLATIME)
1325 LTIME_S(inode->i_atime) = body->atime;
1326 if (body->valid & OBD_MD_FLMTIME &&
1327 body->mtime > LTIME_S(inode->i_mtime)) {
1328 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %u\n",
1329 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
1330 LTIME_S(inode->i_mtime) = body->mtime;
1332 if (body->valid & OBD_MD_FLCTIME &&
1333 body->ctime > LTIME_S(inode->i_ctime))
1334 LTIME_S(inode->i_ctime) = body->ctime;
1335 if (body->valid & OBD_MD_FLMODE)
1336 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1337 if (body->valid & OBD_MD_FLTYPE)
1338 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1339 if (body->valid & OBD_MD_FLUID)
1340 inode->i_uid = body->uid;
1341 if (body->valid & OBD_MD_FLGID)
1342 inode->i_gid = body->gid;
1343 if (body->valid & OBD_MD_FLFLAGS)
1344 inode->i_flags = body->flags;
1345 if (body->valid & OBD_MD_FLNLINK)
1346 inode->i_nlink = body->nlink;
1347 if (body->valid & OBD_MD_FLGENER)
1348 inode->i_generation = body->generation;
1349 if (body->valid & OBD_MD_FLRDEV)
1350 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1351 inode->i_rdev = body->rdev;
1353 inode->i_rdev = old_decode_dev(body->rdev);
1355 if (body->valid & OBD_MD_FLSIZE)
1356 inode->i_size = body->size;
1357 if (body->valid & OBD_MD_FLBLOCKS)
1358 inode->i_blocks = body->blocks;
1360 if (body->valid & OBD_MD_FLSIZE)
1361 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1363 lli->lli_mds = body->mds;
1364 inode->i_dev = (kdev_t) body->mds;
1365 LASSERT(body->mds < 1000);
1368 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1369 static struct backing_dev_info ll_backing_dev_info = {
1370 .ra_pages = 0, /* No readahead */
1371 .memory_backed = 0, /* Does contribute to dirty memory */
1375 void ll_read_inode2(struct inode *inode, void *opaque)
1377 struct lustre_md *md = opaque;
1378 struct ll_inode_info *lli = ll_i2info(inode);
1381 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1382 inode->i_generation, inode);
1386 LASSERT(!lli->lli_smd);
1388 /* Core attributes from the MDS first. This is a new inode, and
1389 * the VFS doesn't zero times in the core inode so we have to do
1390 * it ourselves. They will be overwritten by either MDS or OST
1391 * attributes - we just need to make sure they aren't newer. */
1392 LTIME_S(inode->i_mtime) = 0;
1393 LTIME_S(inode->i_atime) = 0;
1394 LTIME_S(inode->i_ctime) = 0;
1397 ll_update_inode(inode, md);
1399 /* OIDEBUG(inode); */
1401 if (S_ISREG(inode->i_mode)) {
1402 inode->i_op = &ll_file_inode_operations;
1403 inode->i_fop = &ll_file_operations;
1404 inode->i_mapping->a_ops = &ll_aops;
1406 } else if (S_ISDIR(inode->i_mode)) {
1407 inode->i_op = &ll_dir_inode_operations;
1408 inode->i_fop = &ll_dir_operations;
1409 inode->i_mapping->a_ops = &ll_dir_aops;
1411 } else if (S_ISLNK(inode->i_mode)) {
1412 inode->i_op = &ll_fast_symlink_inode_operations;
1415 inode->i_op = &ll_special_inode_operations;
1417 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1418 init_special_inode(inode, inode->i_mode,
1419 kdev_t_to_nr(inode->i_rdev));
1421 /* initializing backing dev info. */
1422 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1424 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1426 lli->ll_save_ifop = inode->i_fop;
1428 if (S_ISCHR(inode->i_mode))
1429 inode->i_fop = &ll_special_chr_inode_fops;
1430 else if (S_ISBLK(inode->i_mode))
1431 inode->i_fop = &ll_special_blk_inode_fops;
1432 else if (S_ISFIFO(inode->i_mode))
1433 inode->i_fop = &ll_special_fifo_inode_fops;
1434 else if (S_ISSOCK(inode->i_mode))
1435 inode->i_fop = &ll_special_sock_inode_fops;
1437 CWARN("saved %p, replaced with %p\n", lli->ll_save_ifop,
1440 if (lli->ll_save_ifop->owner) {
1441 CWARN("%p has owner %p\n", lli->ll_save_ifop,
1442 lli->ll_save_ifop->owner);
1448 void ll_delete_inode(struct inode *inode)
1452 struct ll_sb_info *sbi = ll_i2sbi(inode);
1455 ll_inode2fid(&fid, inode);
1457 rc = md_delete_object(sbi->ll_mdc_exp, &fid);
1459 CERROR("md_delete_object() failed, error %d.\n",
1467 int ll_iocontrol(struct inode *inode, struct file *file,
1468 unsigned int cmd, unsigned long arg)
1470 struct ll_sb_info *sbi = ll_i2sbi(inode);
1471 struct ptlrpc_request *req = NULL;
1476 case EXT3_IOC_GETFLAGS: {
1478 unsigned long valid = OBD_MD_FLFLAGS;
1479 struct mds_body *body;
1481 ll_inode2fid(&fid, inode);
1482 rc = md_getattr(sbi->ll_mdc_exp, &fid, valid, 0, &req);
1484 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1488 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
1490 if (body->flags & S_APPEND)
1491 flags |= EXT3_APPEND_FL;
1492 if (body->flags & S_IMMUTABLE)
1493 flags |= EXT3_IMMUTABLE_FL;
1494 if (body->flags & S_NOATIME)
1495 flags |= EXT3_NOATIME_FL;
1497 ptlrpc_req_finished (req);
1499 RETURN(put_user(flags, (int *)arg));
1501 case EXT3_IOC_SETFLAGS: {
1502 struct mdc_op_data op_data;
1505 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1507 if (get_user(flags, (int *)arg))
1514 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1516 memset(&attr, 0x0, sizeof(attr));
1517 attr.ia_attr_flags = flags;
1518 attr.ia_valid |= ATTR_ATTR_FLAG;
1520 rc = md_setattr(sbi->ll_mdc_exp, &op_data,
1521 &attr, NULL, 0, NULL, 0, &req);
1523 ptlrpc_req_finished(req);
1524 if (rc != -EPERM && rc != -EACCES)
1525 CERROR("md_setattr fails: rc = %d\n", rc);
1529 ptlrpc_req_finished(req);
1531 oa->o_id = lsm->lsm_object_id;
1532 oa->o_gr = lsm->lsm_object_gr;
1533 oa->o_flags = flags;
1534 oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
1536 rc = obd_setattr(sbi->ll_osc_exp, oa, lsm, NULL);
1539 if (rc != -EPERM && rc != -EACCES)
1540 CERROR("md_setattr fails: rc = %d\n", rc);
1544 if (flags & EXT3_APPEND_FL)
1545 inode->i_flags |= S_APPEND;
1547 inode->i_flags &= ~S_APPEND;
1548 if (flags & EXT3_IMMUTABLE_FL)
1549 inode->i_flags |= S_IMMUTABLE;
1551 inode->i_flags &= ~S_IMMUTABLE;
1552 if (flags & EXT3_NOATIME_FL)
1553 inode->i_flags |= S_NOATIME;
1555 inode->i_flags &= ~S_NOATIME;
1566 void ll_umount_begin(struct super_block *sb)
1568 struct ll_sb_info *sbi = ll_s2sbi(sb);
1569 struct obd_device *obd;
1570 struct obd_ioctl_data ioc_data = { 0 };
1572 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1574 obd = class_exp2obd(sbi->ll_mdc_exp);
1576 CERROR("Invalid MDC connection handle "LPX64"\n",
1577 sbi->ll_mdc_exp->exp_handle.h_cookie);
1581 obd->obd_no_recov = 1;
1582 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
1585 obd = class_exp2obd(sbi->ll_osc_exp);
1587 CERROR("Invalid LOV connection handle "LPX64"\n",
1588 sbi->ll_osc_exp->exp_handle.h_cookie);
1593 obd->obd_no_recov = 1;
1594 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
1597 /* Really, we'd like to wait until there are no requests outstanding,
1598 * and then continue. For now, we just invalidate the requests,
1599 * schedule, and hope.
1606 int ll_prep_inode(struct obd_export *osc_exp, struct obd_export *mdc_exp,
1607 struct inode **inode, struct ptlrpc_request *req,
1608 int offset, struct super_block *sb)
1610 struct lustre_md md;
1613 rc = mdc_req2lustre_md(mdc_exp, req, offset, osc_exp, &md);
1618 ll_update_inode(*inode, &md);
1621 *inode = ll_iget(sb, md.body->ino, &md);
1622 if (*inode == NULL || is_bad_inode(*inode)) {
1623 /* free the lsm if we allocated one above */
1625 obd_free_memmd(osc_exp, &md.lsm);
1627 obd_free_memmd(mdc_exp,
1628 (struct lov_stripe_md**)&md.mea);
1630 CERROR("new_inode -fatal: rc %d\n", rc);