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",
104 obd_init_ea_size(sbi->ll_mdc_exp, obd_size_diskmd(sbi->ll_osc_exp, NULL),
105 desc.ld_tgt_count*sizeof(struct llog_cookie));
110 int lustre_set_clone_info(struct super_block *sb, int clone_index)
112 struct ll_sb_info *sbi = ll_s2sbi(sb);
116 CDEBUG(D_INFO, "set clone index %d\n", clone_index);
120 if (sbi->ll_mdc_exp) {
121 struct obd_device *obd = class_exp2obd(sbi->ll_mdc_exp);
122 struct client_obd *cl_obd = &obd->u.cli;
124 OBD_ALLOC(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
125 if (!cl_obd->cl_clone_info)
127 SET_CLONE_INDEX(cl_obd->cl_clone_info, clone_index);
128 SET_CLONE_FLAGS(cl_obd->cl_clone_info, SM_CLONE_FS);
129 cl_obd->cl_clone_info->cl_clone_info->clone_magic =
130 cpu_to_le32(CLONE_INFO_MAGI);
133 if (sbi->ll_osc_exp) {
134 struct obd_device *obd = class_exp2obd(sbi->ll_osc_exp);
135 struct client_obd *cl_obd = &obd->u.cli;
137 OBD_ALLOC(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
138 if (!cl_obd->cl_clone_info)
140 SET_CLONE_INDEX(cl_obd->cl_clone_info, clone_index);
141 SET_CLONE_FLAGS(cl_obd->cl_clone_info, SM_CLONE_FS);
142 cl_obd->cl_clone_info->cl_clone_info->clone_magic =
143 cpu_to_le32(CLONE_INFO_MAGI);
148 int lustre_cleanup_clone_info(struct super_block *sb)
150 struct ll_sb_info *sbi = ll_s2sbi(sb);
154 if (sbi->ll_mdc_exp) {
155 struct obd_device *obd = class_exp2obd(sbi->ll_mdc_exp);
156 struct client_obd *cl_obd = &obd->u.cli;
158 if (!cl_obd->cl_clone_info)
160 CDEBUG(D_INFO, "clean clone info %p\n", cl_obd->cl_clone_info);
161 OBD_FREE(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
164 if (sbi->ll_osc_exp) {
165 struct obd_device *obd = class_exp2obd(sbi->ll_osc_exp);
166 struct client_obd *cl_obd = &obd->u.cli;
168 if (!cl_obd->cl_clone_info)
170 CDEBUG(D_INFO, "clean clone info %p\n", cl_obd->cl_clone_info);
171 OBD_FREE(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
178 int lustre_common_fill_super(struct super_block *sb, char *mdc, char *osc)
180 struct inode *root = 0;
181 struct ll_sb_info *sbi = ll_s2sbi(sb);
182 struct obd_device *obd;
183 struct ll_fid rootfid;
184 struct obd_statfs osfs;
185 struct ptlrpc_request *request = NULL;
186 struct lustre_handle osc_conn = {0, };
187 struct lustre_handle mdc_conn = {0, };
192 obd = class_name2obd(mdc);
194 CERROR("MDC %s: not setup or attached\n", mdc);
198 if (proc_lustre_fs_root) {
199 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
202 CERROR("could not register mount in /proc/lustre");
205 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, 0);
207 CERROR("An MDS (mdc %s) is performing recovery, of which this"
208 " client is not a part. Please wait for recovery to "
209 "complete, abort, or time out.\n", mdc);
212 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
215 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
217 err = obd_statfs(obd, &osfs, jiffies - HZ);
221 LASSERT(osfs.os_bsize);
222 sb->s_blocksize = osfs.os_bsize;
223 sb->s_blocksize_bits = log2(osfs.os_bsize);
224 sb->s_magic = LL_SUPER_MAGIC;
225 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
227 devno = get_uuid2int(sbi->ll_mdc_exp->exp_obd->obd_uuid.uuid,
228 strlen(sbi->ll_mdc_exp->exp_obd->obd_uuid.uuid));
232 obd = class_name2obd(osc);
234 CERROR("OSC %s: not setup or attached\n", osc);
238 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, 0);
240 CERROR("An OST (osc %s) is performing recovery, of which this"
241 " client is not a part. Please wait for recovery to "
242 "complete, abort, or time out.\n", osc);
245 CERROR("cannot connect to %s: rc = %d\n", osc, err);
248 sbi->ll_osc_exp = class_conn2export(&osc_conn);
250 lustre_init_ea_size(sbi);
252 err = md_getstatus(sbi->ll_mdc_exp, &rootfid);
254 CERROR("cannot mds_connect: rc = %d\n", err);
257 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
258 sbi->ll_rootino = rootfid.id;
260 sb->s_op = &lustre_super_operations;
263 * XXX: move this to after cbd setup? */
264 err = md_getattr(sbi->ll_mdc_exp, &rootfid,
265 OBD_MD_FLNOTOBD | OBD_MD_FLBLOCKS, 0, &request);
267 CERROR("md_getattr failed for root: rc = %d\n", err);
271 err = mdc_req2lustre_md(sbi->ll_mdc_exp, request, 0,
272 sbi->ll_osc_exp, &md);
274 CERROR("failed to understand root inode md: rc = %d\n",err);
275 ptlrpc_req_finished (request);
279 LASSERT(sbi->ll_rootino != 0);
280 root = ll_iget(sb, sbi->ll_rootino, &md);
282 ptlrpc_req_finished(request);
284 if (root == NULL || is_bad_inode(root)) {
285 /* XXX might need iput() for bad inode */
286 CERROR("lustre_lite: bad iget4 for root\n");
287 GOTO(out_root, err = -EBADF);
290 err = ll_close_thread_start(&sbi->ll_lcq);
292 CERROR("cannot start close thread: rc %d\n", err);
296 ll_gns_add_timer(sbi);
298 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
299 backing dev info assigned to inode mapping is used for
300 determining maximal readahead. */
301 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
302 /* bug 2805 - set VM readahead to zero */
303 vm_max_readahead = vm_min_readahead = 0;
306 sb->s_root = d_alloc_root(root);
309 CWARN("Enabling PDIROPS\n");
310 sb->s_flags |= S_PDIROPS;
319 obd_disconnect(sbi->ll_osc_exp, 0);
321 obd_disconnect(sbi->ll_mdc_exp, 0);
323 lprocfs_unregister_mountpoint(sbi);
327 void lustre_common_put_super(struct super_block *sb)
329 struct ll_sb_info *sbi = ll_s2sbi(sb);
330 struct hlist_node *tmp, *next;
333 ll_gns_del_timer(sbi);
335 ll_close_thread_shutdown(sbi->ll_lcq);
337 list_del(&sbi->ll_conn_chain);
338 obd_disconnect(sbi->ll_osc_exp, 0);
340 lprocfs_unregister_mountpoint(sbi);
341 if (sbi->ll_proc_root) {
342 lprocfs_remove(sbi->ll_proc_root);
343 sbi->ll_proc_root = NULL;
346 obd_disconnect(sbi->ll_mdc_exp, 0);
348 // We do this to get rid of orphaned dentries. That is not really trw.
349 spin_lock(&dcache_lock);
350 hlist_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list) {
351 struct dentry *dentry = hlist_entry(tmp, struct dentry, d_hash);
352 CWARN("orphan dentry %*s (%p) at unmount\n",
353 dentry->d_name.len, dentry->d_name.name, dentry);
354 shrink_dcache_parent(dentry);
356 spin_unlock(&dcache_lock);
361 char *ll_read_opt(const char *opt, char *data)
367 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
368 if (strncmp(opt, data, strlen(opt)))
370 if ((value = strchr(data, '=')) == NULL)
374 OBD_ALLOC(retval, strlen(value) + 1);
376 CERROR("out of memory!\n");
380 memcpy(retval, value, strlen(value)+1);
381 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
385 int ll_set_opt(const char *opt, char *data, int fl)
389 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
390 if (strncmp(opt, data, strlen(opt)))
396 void ll_options(char *options, char **ost, char **mdc, int *flags,
400 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
401 char *opt_ptr = options;
410 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
411 for (this_char = strtok (options, ",");
413 this_char = strtok (NULL, ",")) {
415 while ((this_char = strsep (&opt_ptr, ",")) != NULL) {
417 CDEBUG(D_SUPER, "this_char %s\n", this_char);
418 if (!*ost && (*ost = ll_read_opt("osc", this_char)))
420 if (!*mdc && (*mdc = ll_read_opt("mdc", this_char)))
422 if (!*clone_opts && (*clone_opts = ll_read_opt("clone",
425 if (!(*flags & LL_SBI_NOLCK) &&
426 ((*flags) = (*flags) |
427 ll_set_opt("nolock", this_char,
435 void ll_lli_init(struct ll_inode_info *lli)
437 sema_init(&lli->lli_open_sem, 1);
439 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
440 spin_lock_init(&lli->lli_lock);
441 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
442 lli->lli_inode_magic = LLI_INODE_MAGIC;
445 int ll_fill_super(struct super_block *sb, void *data, int silent)
447 struct ll_sb_info *sbi;
450 char *clone_opts = NULL;
454 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
456 sbi = lustre_init_sbi(sb);
460 sbi->ll_flags |= LL_SBI_READAHEAD;
461 ll_options(data, &osc, &mdc, &sbi->ll_flags, &clone_opts);
465 GOTO(out, err = -EINVAL);
470 GOTO(out, err = -EINVAL);
473 err = lustre_common_fill_super(sb, mdc, osc);
479 /*set clone info to the super block*/
480 clone_index = simple_strtoul(clone_opts, &endp, 0);
481 err = lustre_set_clone_info(sb, clone_index);
489 OBD_FREE(mdc, strlen(mdc) + 1);
491 OBD_FREE(osc, strlen(osc) + 1);
493 OBD_FREE(clone_opts, strlen(clone_opts) + 1);
496 } /* ll_read_super */
498 static int lustre_process_log(struct lustre_mount_data *lmd, char *profile,
499 struct config_llog_instance *cfg, int allow_recov)
501 struct lustre_cfg lcfg;
502 struct portals_cfg pcfg;
503 char * peer = "MDS_PEER_UUID";
504 struct obd_device *obd;
505 struct lustre_handle mdc_conn = {0, };
506 struct obd_export *exp;
507 char * name = "mdc_dev";
509 struct obd_uuid mdc_uuid;
510 struct llog_ctxt *ctxt;
515 if (lmd_bad_magic(lmd))
518 generate_random_uuid(uuid);
519 class_uuid_unparse(uuid, &mdc_uuid);
521 if (lmd->lmd_local_nid) {
522 PCFG_INIT(pcfg, NAL_CMD_REGISTER_MYNID);
523 pcfg.pcfg_nal = lmd->lmd_nal;
524 pcfg.pcfg_nid = lmd->lmd_local_nid;
525 err = libcfs_nal_cmd(&pcfg);
530 if (lmd->lmd_nal == SOCKNAL) {
531 PCFG_INIT(pcfg, NAL_CMD_ADD_AUTOCONN);
532 pcfg.pcfg_nal = lmd->lmd_nal;
533 pcfg.pcfg_nid = lmd->lmd_server_nid;
534 pcfg.pcfg_id = lmd->lmd_server_ipaddr;
535 pcfg.pcfg_misc = lmd->lmd_port;
536 pcfg.pcfg_size = 8388608;
537 pcfg.pcfg_flags = 0x4; /*share*/
538 err = libcfs_nal_cmd(&pcfg);
543 LCFG_INIT(lcfg, LCFG_ADD_UUID, name);
544 lcfg.lcfg_nid = lmd->lmd_server_nid;
545 lcfg.lcfg_inllen1 = strlen(peer) + 1;
546 lcfg.lcfg_inlbuf1 = peer;
547 lcfg.lcfg_nal = lmd->lmd_nal;
548 err = class_process_config(&lcfg);
550 GOTO(out_del_conn, err);
552 LCFG_INIT(lcfg, LCFG_ATTACH, name);
553 lcfg.lcfg_inlbuf1 = "mdc";
554 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
555 lcfg.lcfg_inlbuf2 = mdc_uuid.uuid;
556 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
557 err = class_process_config(&lcfg);
559 GOTO(out_del_uuid, err);
561 LCFG_INIT(lcfg, LCFG_SETUP, name);
562 lcfg.lcfg_inlbuf1 = lmd->lmd_mds;
563 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
564 lcfg.lcfg_inlbuf2 = peer;
565 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
566 err = class_process_config(&lcfg);
568 GOTO(out_detach, err);
570 obd = class_name2obd(name);
572 GOTO(out_cleanup, err = -EINVAL);
574 /* Disable initial recovery on this import */
575 err = obd_set_info(obd->obd_self_export,
576 strlen("initial_recov"), "initial_recov",
577 sizeof(allow_recov), &allow_recov);
579 GOTO(out_cleanup, err);
581 err = obd_connect(&mdc_conn, obd, &mdc_uuid, 0);
583 CERROR("cannot connect to %s: rc = %d\n", lmd->lmd_mds, err);
584 GOTO(out_cleanup, err);
587 exp = class_conn2export(&mdc_conn);
589 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,LLOG_CONFIG_REPL_CTXT);
590 rc = class_config_process_llog(ctxt, profile, cfg);
592 CERROR("class_config_process_llog failed: rc = %d\n", rc);
594 err = obd_disconnect(exp, 0);
597 LCFG_INIT(lcfg, LCFG_CLEANUP, name);
598 err = class_process_config(&lcfg);
603 LCFG_INIT(lcfg, LCFG_DETACH, name);
604 err = class_process_config(&lcfg);
609 LCFG_INIT(lcfg, LCFG_DEL_UUID, name);
610 lcfg.lcfg_inllen1 = strlen(peer) + 1;
611 lcfg.lcfg_inlbuf1 = peer;
612 err = class_process_config(&lcfg);
615 if (lmd->lmd_nal == SOCKNAL) {
616 PCFG_INIT(pcfg, NAL_CMD_DEL_AUTOCONN);
617 pcfg.pcfg_nal = lmd->lmd_nal;
618 pcfg.pcfg_nid = lmd->lmd_server_nid;
619 pcfg.pcfg_id = lmd->lmd_server_ipaddr;
620 pcfg.pcfg_flags = 1; /*share*/
621 err = libcfs_nal_cmd(&pcfg);
632 int lustre_fill_super(struct super_block *sb, void *data, int silent)
634 struct lustre_mount_data * lmd = data;
635 struct ll_sb_info *sbi;
641 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
642 if (lmd_bad_magic(lmd))
645 sbi = lustre_init_sbi(sb);
649 sbi->ll_flags |= LL_SBI_READAHEAD;
651 if (lmd->lmd_profile) {
652 struct lustre_profile *lprof;
653 struct config_llog_instance cfg;
656 if (lmd->lmd_mds[0] == '\0') {
657 CERROR("no mds name\n");
658 GOTO(out_free, err = -EINVAL);
661 OBD_ALLOC(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
662 if (sbi->ll_lmd == NULL)
663 GOTO(out_free, err = -ENOMEM);
664 memcpy(sbi->ll_lmd, lmd, sizeof(*lmd));
666 /* generate a string unique to this super, let's try
667 the address of the super itself.*/
668 len = (sizeof(sb) * 2) + 1;
669 OBD_ALLOC(sbi->ll_instance, len);
670 if (sbi->ll_instance == NULL)
671 GOTO(out_free, err = -ENOMEM);
672 sprintf(sbi->ll_instance, "%p", sb);
674 cfg.cfg_instance = sbi->ll_instance;
675 cfg.cfg_uuid = sbi->ll_sb_uuid;
676 cfg.cfg_local_nid = lmd->lmd_local_nid;
677 err = lustre_process_log(lmd, lmd->lmd_profile, &cfg, 0);
679 CERROR("Unable to process log: %s\n", lmd->lmd_profile);
683 lprof = class_get_profile(lmd->lmd_profile);
685 CERROR("No profile found: %s\n", lmd->lmd_profile);
686 GOTO(out_free, err = -EINVAL);
689 OBD_FREE(osc, strlen(osc) + 1);
690 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
691 strlen(sbi->ll_instance) + 2);
692 sprintf(osc, "%s-%s", lprof->lp_osc, sbi->ll_instance);
695 OBD_FREE(mdc, strlen(mdc) + 1);
696 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
697 strlen(sbi->ll_instance) + 2);
698 sprintf(mdc, "%s-%s", lprof->lp_mdc, sbi->ll_instance);
703 GOTO(out_free, err = -EINVAL);
708 GOTO(out_free, err = -EINVAL);
711 err = lustre_common_fill_super(sb, mdc, osc);
717 if (lmd->lmd_clone_index) {
718 err = lustre_set_clone_info(sb, lmd->lmd_clone_index);
727 OBD_FREE(mdc, strlen(mdc) + 1);
729 OBD_FREE(osc, strlen(osc) + 1);
735 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
738 if (sbi->ll_instance != NULL) {
739 struct lustre_mount_data *lmd = sbi->ll_lmd;
741 struct config_llog_instance cfg;
743 cfg.cfg_instance = sbi->ll_instance;
744 cfg.cfg_uuid = sbi->ll_sb_uuid;
746 OBD_ALLOC(cln_prof, len);
747 sprintf(cln_prof, "%s-clean", lmd->lmd_profile);
749 err = lustre_process_log(lmd, cln_prof, &cfg, 0);
751 CERROR("Unable to process log: %s\n", cln_prof);
752 OBD_FREE(cln_prof, len);
753 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance)+ 1);
755 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
758 lustre_cleanup_clone_info(sb);
763 } /* lustre_fill_super */
765 static void lustre_manual_cleanup(struct ll_sb_info *sbi)
767 struct lustre_cfg lcfg;
768 struct obd_device *obd;
771 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) != NULL)
775 LCFG_INIT(lcfg, LCFG_CLEANUP, obd->obd_name);
776 err = class_process_config(&lcfg);
778 CERROR("cleanup failed: %s\n", obd->obd_name);
782 LCFG_INIT(lcfg, LCFG_DETACH, obd->obd_name);
783 err = class_process_config(&lcfg);
785 CERROR("detach failed: %s\n", obd->obd_name);
790 if (sbi->ll_lmd != NULL)
791 class_del_profile(sbi->ll_lmd->lmd_profile);
794 void lustre_put_super(struct super_block *sb)
796 struct obd_device *obd;
797 struct ll_sb_info *sbi = ll_s2sbi(sb);
798 int force_umount = 0;
801 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
802 obd = class_exp2obd(sbi->ll_mdc_exp);
804 force_umount = obd->obd_no_recov;
808 lustre_cleanup_clone_info(sb);
811 lustre_common_put_super(sb);
812 if (sbi->ll_lmd != NULL) {
814 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
816 struct config_llog_instance cfg;
819 CERROR("force umount, doing manual cleanup\n");
820 lustre_manual_cleanup(sbi);
824 cfg.cfg_instance = sbi->ll_instance;
825 cfg.cfg_uuid = sbi->ll_sb_uuid;
827 OBD_ALLOC(cln_prof, len);
828 sprintf(cln_prof, "%s-clean", sbi->ll_lmd->lmd_profile);
830 err = lustre_process_log(sbi->ll_lmd, cln_prof, &cfg, 0);
832 CERROR("Unable to process log: %s, doing manual cleanup"
834 lustre_manual_cleanup(sbi);
837 OBD_FREE(cln_prof, len);
839 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
840 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance) + 1);
846 } /* lustre_put_super */
848 int ll_process_config_update(struct ll_sb_info *sbi, int clean)
850 struct obd_export *mdc_exp = sbi->ll_mdc_exp;
851 struct lustre_mount_data *lmd = sbi->ll_lmd;
852 struct llog_ctxt *ctxt;
853 struct config_llog_instance cfg;
854 char *profile = lmd->lmd_profile, *name = NULL;
855 int rc, namelen = 0, version;
861 CERROR("Client not mounted with zero-conf; cannot process "
866 rc = ldlm_cli_cancel_unused(mdc_exp->exp_obd->obd_namespace, NULL,
867 LDLM_FL_CONFIG_CHANGE, NULL);
869 CWARN("ldlm_cli_cancel_unused(mdc): %d\n", rc);
871 rc = obd_cancel_unused(sbi->ll_osc_exp, NULL, LDLM_FL_CONFIG_CHANGE,
874 CWARN("obd_cancel_unused(lov): %d\n", rc);
876 cfg.cfg_instance = sbi->ll_instance;
877 cfg.cfg_uuid = sbi->ll_sb_uuid;
878 cfg.cfg_local_nid = lmd->lmd_local_nid;
880 namelen = strlen(profile) + 20; /* -clean-######### */
881 OBD_ALLOC(name, namelen);
886 version = sbi->ll_config_version - 1;
887 sprintf(name, "%s-clean-%d", profile, version);
889 version = sbi->ll_config_version + 1;
890 sprintf(name, "%s-%d", profile, version);
893 CWARN("Applying configuration log %s\n", name);
895 ctxt = llog_get_context(&mdc_exp->exp_obd->obd_llogs,
896 LLOG_CONFIG_REPL_CTXT);
897 rc = class_config_process_llog(ctxt, name, &cfg);
899 sbi->ll_config_version = version;
900 CWARN("Finished applying configuration log %s: %d\n", name, rc);
902 if (rc == 0 && clean == 0) {
903 struct lov_desc desc;
905 valsize = sizeof(desc);
906 rc = obd_get_info(sbi->ll_osc_exp, strlen("lovdesc") + 1,
907 "lovdesc", &valsize, &desc);
909 rc = obd_init_ea_size(mdc_exp,
910 obd_size_diskmd(sbi->ll_osc_exp, NULL),
912 sizeof(struct llog_cookie)));
914 OBD_FREE(name, namelen);
918 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
920 struct inode *inode = NULL;
921 l_lock(&lock->l_resource->lr_namespace->ns_lock);
922 if (lock->l_ast_data) {
923 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
924 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
925 inode = igrab(lock->l_ast_data);
927 CERROR("DEBUG: l_ast_data %p is bogus: magic %x\n",
928 lock->l_ast_data, lli->lli_inode_magic);
931 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
935 int null_if_equal(struct ldlm_lock *lock, void *data)
937 if (data == lock->l_ast_data)
938 lock->l_ast_data = NULL;
940 if (lock->l_req_mode != lock->l_granted_mode)
941 return LDLM_ITER_STOP;
943 return LDLM_ITER_CONTINUE;
946 void ll_clear_inode(struct inode *inode)
949 struct ll_inode_info *lli = ll_i2info(inode);
950 struct ll_sb_info *sbi = ll_i2sbi(inode);
953 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
954 inode->i_generation, inode);
956 lli->lli_inode_magic = LLI_INODE_DEAD;
957 ll_inode2fid(&fid, inode);
958 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(ll_i2info(inode)->lli_flags));
959 md_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
962 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
963 null_if_equal, inode);
966 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
971 /* FIXME: change cbdata for mea here */
972 obd_free_memmd(sbi->ll_mdc_exp,
973 (struct lov_stripe_md **) &lli->lli_mea);
977 if (lli->lli_symlink_name) {
978 OBD_FREE(lli->lli_symlink_name,
979 strlen(lli->lli_symlink_name) + 1);
980 lli->lli_symlink_name = NULL;
986 /* If this inode has objects allocated to it (lsm != NULL), then the OST
987 * object(s) determine the file size and mtime. Otherwise, the MDS will
988 * keep these values until such a time that objects are allocated for it.
989 * We do the MDS operations first, as it is checking permissions for us.
990 * We don't to the MDS RPC if there is nothing that we want to store there,
991 * otherwise there is no harm in updating mtime/atime on the MDS if we are
992 * going to do an RPC anyways.
994 * If we are doing a truncate, we will send the mtime and ctime updates
995 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
996 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
999 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1001 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1002 struct ll_sb_info *sbi = ll_i2sbi(inode);
1003 struct ptlrpc_request *request = NULL;
1004 struct mdc_op_data op_data;
1005 int ia_valid = attr->ia_valid;
1009 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
1010 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
1012 if (ia_valid & ATTR_SIZE) {
1013 if (attr->ia_size > ll_file_maxbytes(inode)) {
1014 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1015 attr->ia_size, ll_file_maxbytes(inode));
1019 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1022 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1023 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1024 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1028 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1029 if (attr->ia_valid & ATTR_CTIME) {
1030 attr->ia_ctime = CURRENT_TIME;
1031 attr->ia_valid |= ATTR_CTIME_SET;
1033 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1034 attr->ia_atime = CURRENT_TIME;
1035 attr->ia_valid |= ATTR_ATIME_SET;
1037 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1038 attr->ia_mtime = CURRENT_TIME;
1039 attr->ia_valid |= ATTR_MTIME_SET;
1042 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1043 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1044 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1045 LTIME_S(CURRENT_TIME));
1047 attr->ia_valid &= ~ATTR_SIZE;
1049 /* If only OST attributes being set on objects, don't do MDS RPC.
1050 * In that case, we need to check permissions and update the local
1051 * inode ourselves so we can call obdo_from_inode() always. */
1052 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
1053 struct lustre_md md;
1054 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1056 rc = md_setattr(sbi->ll_mdc_exp, &op_data,
1057 attr, NULL, 0, NULL, 0, &request);
1059 ptlrpc_req_finished(request);
1060 if (rc != -EPERM && rc != -EACCES)
1061 CERROR("md_setattr fails: rc = %d\n", rc);
1065 rc = mdc_req2lustre_md(sbi->ll_mdc_exp, request, 0,
1066 sbi->ll_osc_exp, &md);
1068 ptlrpc_req_finished(request);
1072 /* Won't invoke vmtruncate as we already cleared ATTR_SIZE,
1073 * but needed to set timestamps backwards on utime. */
1074 inode_setattr(inode, attr);
1075 ll_update_inode(inode, &md);
1076 ptlrpc_req_finished(request);
1078 if (!lsm || !S_ISREG(inode->i_mode)) {
1079 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1083 /* The OST doesn't check permissions, but the alternative is
1084 * a gratuitous RPC to the MDS. We already rely on the client
1085 * to do read/write/truncate permission checks, so is mtime OK?
1087 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
1088 /* from sys_utime() */
1089 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
1090 if (current->fsuid != inode->i_uid &&
1091 (rc=ll_permission(inode,MAY_WRITE,NULL))!=0)
1094 /* from inode_change_ok() */
1095 if (current->fsuid != inode->i_uid &&
1096 !capable(CAP_FOWNER))
1101 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
1102 inode_setattr(inode, attr);
1105 /* We really need to get our PW lock before we change inode->i_size.
1106 * If we don't we can race with other i_size updaters on our node, like
1107 * ll_file_read. We can also race with i_size propogation to other
1108 * nodes through dirtying and writeback of final cached pages. This
1109 * last one is especially bad for racing o_append users on other
1111 if (ia_valid & ATTR_SIZE) {
1112 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
1114 struct lustre_handle lockh = { 0 };
1115 int err, ast_flags = 0;
1116 /* XXX when we fix the AST intents to pass the discard-range
1117 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1119 if (attr->ia_size == 0)
1120 ast_flags = LDLM_AST_DISCARD_DATA;
1122 /* bug 1639: avoid write/truncate i_sem/DLM deadlock */
1123 LASSERT(atomic_read(&inode->i_sem.count) <= 0);
1125 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy, &lockh,
1127 down(&inode->i_sem);
1131 rc = vmtruncate(inode, attr->ia_size);
1133 /* We need to drop the semaphore here, because this unlock may
1134 * result in a cancellation, which will need the i_sem */
1136 /* unlock now as we don't mind others file lockers racing with
1137 * the mds updates below? */
1138 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1139 down(&inode->i_sem);
1141 CERROR("ll_extent_unlock failed: %d\n", err);
1145 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1148 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1149 inode->i_ino, LTIME_S(attr->ia_mtime));
1150 oa.o_id = lsm->lsm_object_id;
1151 oa.o_gr = lsm->lsm_object_gr;
1152 oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1153 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
1154 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
1155 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
1157 CERROR("obd_setattr fails: rc=%d\n", rc);
1162 int ll_setattr(struct dentry *de, struct iattr *attr)
1164 LBUG(); /* code is unused, but leave this in case of VFS changes */
1168 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1169 unsigned long max_age)
1171 struct ll_sb_info *sbi = ll_s2sbi(sb);
1172 struct obd_statfs obd_osfs;
1176 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1178 CERROR("mdc_statfs fails: rc = %d\n", rc);
1182 osfs->os_type = sb->s_magic;
1184 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1185 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1187 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1189 CERROR("obd_statfs fails: rc = %d\n", rc);
1193 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1194 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1197 osfs->os_blocks = obd_osfs.os_blocks;
1198 osfs->os_bfree = obd_osfs.os_bfree;
1199 osfs->os_bavail = obd_osfs.os_bavail;
1201 /* If we don't have as many objects free on the OST as inodes
1202 * on the MDS, we reduce the total number of inodes to
1203 * compensate, so that the "inodes in use" number is correct.
1205 if (obd_osfs.os_ffree < osfs->os_ffree) {
1206 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1208 osfs->os_ffree = obd_osfs.os_ffree;
1214 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1216 struct obd_statfs osfs;
1219 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1220 lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
1222 /* For now we will always get up-to-date statfs values, but in the
1223 * future we may allow some amount of caching on the client (e.g.
1224 * from QOS or lprocfs updates). */
1225 rc = ll_statfs_internal(sb, &osfs, jiffies - 1);
1229 statfs_unpack(sfs, &osfs);
1231 if (sizeof(sfs->f_blocks) == 4) {
1232 while (osfs.os_blocks > ~0UL) {
1235 osfs.os_blocks >>= 1;
1236 osfs.os_bfree >>= 1;
1237 osfs.os_bavail >>= 1;
1241 sfs->f_blocks = osfs.os_blocks;
1242 sfs->f_bfree = osfs.os_bfree;
1243 sfs->f_bavail = osfs.os_bavail;
1248 void dump_lsm(int level, struct lov_stripe_md *lsm)
1250 CDEBUG(level, "objid "LPX64", maxbytes "LPX64", magic 0x%08X, "
1251 "stripe_size %u, stripe_count %u\n",
1252 lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
1253 lsm->lsm_stripe_size, lsm->lsm_stripe_count);
1256 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1258 struct ll_inode_info *lli = ll_i2info(inode);
1259 struct mds_body *body = md->body;
1260 struct lov_stripe_md *lsm = md->lsm;
1261 struct mea *mea = md->mea;
1264 LASSERT((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1265 LASSERT((mea != NULL) == ((body->valid & OBD_MD_FLDIREA) != 0));
1267 LASSERT(lsm->lsm_object_gr > 0);
1268 if (lli->lli_smd == NULL) {
1270 lli->lli_maxbytes = lsm->lsm_maxbytes;
1271 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1272 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1275 if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
1276 CERROR("lsm mismatch for inode %ld\n",
1278 CERROR("lli_smd:\n");
1279 dump_lsm(D_ERROR, lli->lli_smd);
1281 dump_lsm(D_ERROR, lsm);
1284 /* XXX FIXME -- We should decide on a safer (atomic) and
1285 * more elegant way to update the lsm */
1286 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1287 lli->lli_smd->lsm_oinfo[i].loi_id =
1288 lsm->lsm_oinfo[i].loi_id;
1289 lli->lli_smd->lsm_oinfo[i].loi_gr =
1290 lsm->lsm_oinfo[i].loi_gr;
1291 lli->lli_smd->lsm_oinfo[i].loi_ost_idx =
1292 lsm->lsm_oinfo[i].loi_ost_idx;
1293 lli->lli_smd->lsm_oinfo[i].loi_ost_gen =
1294 lsm->lsm_oinfo[i].loi_ost_gen;
1297 /* bug 2844 - limit i_blksize for broken user-space apps */
1298 LASSERTF(lsm->lsm_xfersize != 0, "%lu\n", lsm->lsm_xfersize);
1299 inode->i_blksize = min(lsm->lsm_xfersize, LL_MAX_BLKSIZE);
1300 if (lli->lli_smd != lsm)
1301 obd_free_memmd(ll_i2obdexp(inode), &lsm);
1305 if (lli->lli_mea == NULL) {
1308 if (memcmp(lli->lli_mea, mea, body->eadatasize)) {
1309 CERROR("mea mismatch for inode %lu\n",
1314 if (lli->lli_mea != mea)
1315 obd_free_memmd(ll_i2mdcexp(inode),
1316 (struct lov_stripe_md **) &mea);
1320 if (body->valid & OBD_MD_FLID)
1321 inode->i_ino = body->ino;
1322 if (body->valid & OBD_MD_FLATIME)
1323 LTIME_S(inode->i_atime) = body->atime;
1324 if (body->valid & OBD_MD_FLMTIME &&
1325 body->mtime > LTIME_S(inode->i_mtime)) {
1326 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %u\n",
1327 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
1328 LTIME_S(inode->i_mtime) = body->mtime;
1330 if (body->valid & OBD_MD_FLCTIME &&
1331 body->ctime > LTIME_S(inode->i_ctime))
1332 LTIME_S(inode->i_ctime) = body->ctime;
1333 if (body->valid & OBD_MD_FLMODE)
1334 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1335 if (body->valid & OBD_MD_FLTYPE)
1336 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1337 if (body->valid & OBD_MD_FLUID)
1338 inode->i_uid = body->uid;
1339 if (body->valid & OBD_MD_FLGID)
1340 inode->i_gid = body->gid;
1341 if (body->valid & OBD_MD_FLFLAGS)
1342 inode->i_flags = body->flags;
1343 if (body->valid & OBD_MD_FLNLINK)
1344 inode->i_nlink = body->nlink;
1345 if (body->valid & OBD_MD_FLGENER)
1346 inode->i_generation = body->generation;
1347 if (body->valid & OBD_MD_FLRDEV)
1348 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1349 inode->i_rdev = body->rdev;
1351 inode->i_rdev = old_decode_dev(body->rdev);
1353 if (body->valid & OBD_MD_FLSIZE)
1354 inode->i_size = body->size;
1355 if (body->valid & OBD_MD_FLBLOCKS)
1356 inode->i_blocks = body->blocks;
1358 if (body->valid & OBD_MD_FLSIZE)
1359 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1361 lli->lli_mds = body->mds;
1362 inode->i_dev = (kdev_t) body->mds;
1363 LASSERT(body->mds < 1000);
1366 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1367 static struct backing_dev_info ll_backing_dev_info = {
1368 .ra_pages = 0, /* No readahead */
1369 .memory_backed = 0, /* Does contribute to dirty memory */
1373 void ll_read_inode2(struct inode *inode, void *opaque)
1375 struct lustre_md *md = opaque;
1376 struct ll_inode_info *lli = ll_i2info(inode);
1379 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1380 inode->i_generation, inode);
1384 LASSERT(!lli->lli_smd);
1386 /* Core attributes from the MDS first. This is a new inode, and
1387 * the VFS doesn't zero times in the core inode so we have to do
1388 * it ourselves. They will be overwritten by either MDS or OST
1389 * attributes - we just need to make sure they aren't newer. */
1390 LTIME_S(inode->i_mtime) = 0;
1391 LTIME_S(inode->i_atime) = 0;
1392 LTIME_S(inode->i_ctime) = 0;
1395 ll_update_inode(inode, md);
1397 /* OIDEBUG(inode); */
1399 if (S_ISREG(inode->i_mode)) {
1400 inode->i_op = &ll_file_inode_operations;
1401 inode->i_fop = &ll_file_operations;
1402 inode->i_mapping->a_ops = &ll_aops;
1404 } else if (S_ISDIR(inode->i_mode)) {
1405 inode->i_op = &ll_dir_inode_operations;
1406 inode->i_fop = &ll_dir_operations;
1407 inode->i_mapping->a_ops = &ll_dir_aops;
1409 } else if (S_ISLNK(inode->i_mode)) {
1410 inode->i_op = &ll_fast_symlink_inode_operations;
1413 inode->i_op = &ll_special_inode_operations;
1415 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1416 init_special_inode(inode, inode->i_mode,
1417 kdev_t_to_nr(inode->i_rdev));
1419 /* initializing backing dev info. */
1420 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1422 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1424 lli->ll_save_ifop = inode->i_fop;
1426 if (S_ISCHR(inode->i_mode))
1427 inode->i_fop = &ll_special_chr_inode_fops;
1428 else if (S_ISBLK(inode->i_mode))
1429 inode->i_fop = &ll_special_blk_inode_fops;
1430 else if (S_ISFIFO(inode->i_mode))
1431 inode->i_fop = &ll_special_fifo_inode_fops;
1432 else if (S_ISSOCK(inode->i_mode))
1433 inode->i_fop = &ll_special_sock_inode_fops;
1435 CWARN("saved %p, replaced with %p\n", lli->ll_save_ifop,
1438 if (lli->ll_save_ifop->owner) {
1439 CWARN("%p has owner %p\n", lli->ll_save_ifop,
1440 lli->ll_save_ifop->owner);
1446 void ll_delete_inode(struct inode *inode)
1450 struct ll_sb_info *sbi = ll_i2sbi(inode);
1453 ll_inode2fid(&fid, inode);
1455 rc = md_delete_object(sbi->ll_mdc_exp, &fid);
1457 CERROR("md_delete_object() failed, error %d.\n",
1465 int ll_iocontrol(struct inode *inode, struct file *file,
1466 unsigned int cmd, unsigned long arg)
1468 struct ll_sb_info *sbi = ll_i2sbi(inode);
1469 struct ptlrpc_request *req = NULL;
1474 case EXT3_IOC_GETFLAGS: {
1476 unsigned long valid = OBD_MD_FLFLAGS;
1477 struct mds_body *body;
1479 ll_inode2fid(&fid, inode);
1480 rc = md_getattr(sbi->ll_mdc_exp, &fid, valid, 0, &req);
1482 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1486 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
1488 if (body->flags & S_APPEND)
1489 flags |= EXT3_APPEND_FL;
1490 if (body->flags & S_IMMUTABLE)
1491 flags |= EXT3_IMMUTABLE_FL;
1492 if (body->flags & S_NOATIME)
1493 flags |= EXT3_NOATIME_FL;
1495 ptlrpc_req_finished (req);
1497 RETURN(put_user(flags, (int *)arg));
1499 case EXT3_IOC_SETFLAGS: {
1500 struct mdc_op_data op_data;
1503 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1505 if (get_user(flags, (int *)arg))
1512 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1514 memset(&attr, 0x0, sizeof(attr));
1515 attr.ia_attr_flags = flags;
1516 attr.ia_valid |= ATTR_ATTR_FLAG;
1518 rc = md_setattr(sbi->ll_mdc_exp, &op_data,
1519 &attr, NULL, 0, NULL, 0, &req);
1521 ptlrpc_req_finished(req);
1522 if (rc != -EPERM && rc != -EACCES)
1523 CERROR("md_setattr fails: rc = %d\n", rc);
1527 ptlrpc_req_finished(req);
1529 oa->o_id = lsm->lsm_object_id;
1530 oa->o_gr = lsm->lsm_object_gr;
1531 oa->o_flags = flags;
1532 oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
1534 rc = obd_setattr(sbi->ll_osc_exp, oa, lsm, NULL);
1537 if (rc != -EPERM && rc != -EACCES)
1538 CERROR("md_setattr fails: rc = %d\n", rc);
1542 if (flags & EXT3_APPEND_FL)
1543 inode->i_flags |= S_APPEND;
1545 inode->i_flags &= ~S_APPEND;
1546 if (flags & EXT3_IMMUTABLE_FL)
1547 inode->i_flags |= S_IMMUTABLE;
1549 inode->i_flags &= ~S_IMMUTABLE;
1550 if (flags & EXT3_NOATIME_FL)
1551 inode->i_flags |= S_NOATIME;
1553 inode->i_flags &= ~S_NOATIME;
1564 void ll_umount_begin(struct super_block *sb)
1566 struct ll_sb_info *sbi = ll_s2sbi(sb);
1567 struct obd_device *obd;
1568 struct obd_ioctl_data ioc_data = { 0 };
1570 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1572 obd = class_exp2obd(sbi->ll_mdc_exp);
1574 CERROR("Invalid MDC connection handle "LPX64"\n",
1575 sbi->ll_mdc_exp->exp_handle.h_cookie);
1579 obd->obd_no_recov = 1;
1580 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
1583 obd = class_exp2obd(sbi->ll_osc_exp);
1585 CERROR("Invalid LOV connection handle "LPX64"\n",
1586 sbi->ll_osc_exp->exp_handle.h_cookie);
1591 obd->obd_no_recov = 1;
1592 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
1595 /* Really, we'd like to wait until there are no requests outstanding,
1596 * and then continue. For now, we just invalidate the requests,
1597 * schedule, and hope.
1604 int ll_prep_inode(struct obd_export *osc_exp, struct obd_export *mdc_exp,
1605 struct inode **inode, struct ptlrpc_request *req,
1606 int offset, struct super_block *sb)
1608 struct lustre_md md;
1611 rc = mdc_req2lustre_md(mdc_exp, req, offset, osc_exp, &md);
1616 ll_update_inode(*inode, &md);
1619 *inode = ll_iget(sb, md.body->ino, &md);
1620 if (*inode == NULL || is_bad_inode(*inode)) {
1621 /* free the lsm if we allocated one above */
1623 obd_free_memmd(osc_exp, &md.lsm);
1625 obd_free_memmd(mdc_exp,
1626 (struct lov_stripe_md**)&md.mea);
1628 CERROR("new_inode -fatal: rc %d\n", rc);