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_device *obd = class_exp2obd(sbi->ll_mdc_exp);
128 struct client_obd *cl_obd = &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);
135 cl_obd->cl_clone_info->cl_clone_info->clone_magic =
136 cpu_to_le32(CLONE_INFO_MAGI);
139 if (sbi->ll_osc_exp) {
140 struct obd_device *obd = class_exp2obd(sbi->ll_osc_exp);
141 struct client_obd *cl_obd = &obd->u.cli;
143 OBD_ALLOC(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
144 if (!cl_obd->cl_clone_info)
146 SET_CLONE_INDEX(cl_obd->cl_clone_info, clone_index);
147 SET_CLONE_FLAGS(cl_obd->cl_clone_info, SM_CLONE_FS);
148 cl_obd->cl_clone_info->cl_clone_info->clone_magic =
149 cpu_to_le32(CLONE_INFO_MAGI);
154 int lustre_cleanup_clone_info(struct super_block *sb)
156 struct ll_sb_info *sbi = ll_s2sbi(sb);
160 if (sbi->ll_mdc_exp) {
161 struct obd_device *obd = class_exp2obd(sbi->ll_mdc_exp);
162 struct client_obd *cl_obd = &obd->u.cli;
164 if (!cl_obd->cl_clone_info)
166 CDEBUG(D_INFO, "clean clone info %p\n", cl_obd->cl_clone_info);
167 OBD_FREE(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
170 if (sbi->ll_osc_exp) {
171 struct obd_device *obd = class_exp2obd(sbi->ll_osc_exp);
172 struct client_obd *cl_obd = &obd->u.cli;
174 if (!cl_obd->cl_clone_info)
176 CDEBUG(D_INFO, "clean clone info %p\n", cl_obd->cl_clone_info);
177 OBD_FREE(cl_obd->cl_clone_info, sizeof(struct clonefs_info));
184 int lustre_common_fill_super(struct super_block *sb, char *mdc, char *osc)
186 struct inode *root = 0;
187 struct ll_sb_info *sbi = ll_s2sbi(sb);
188 struct obd_device *obd;
189 struct ll_fid rootfid;
190 struct obd_statfs osfs;
191 struct ptlrpc_request *request = NULL;
192 struct lustre_handle osc_conn = {0, };
193 struct lustre_handle mdc_conn = {0, };
198 obd = class_name2obd(mdc);
200 CERROR("MDC %s: not setup or attached\n", mdc);
204 if (proc_lustre_fs_root) {
205 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
208 CERROR("could not register mount in /proc/lustre");
211 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid);
213 CERROR("An MDS (mdc %s) is performing recovery, of which this"
214 " client is not a part. Please wait for recovery to "
215 "complete, abort, or time out.\n", mdc);
218 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
221 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
223 err = obd_statfs(obd, &osfs, jiffies - HZ);
227 LASSERT(osfs.os_bsize);
228 sb->s_blocksize = osfs.os_bsize;
229 sb->s_blocksize_bits = log2(osfs.os_bsize);
230 sb->s_magic = LL_SUPER_MAGIC;
231 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
233 devno = get_uuid2int(sbi->ll_mdc_exp->exp_obd->obd_uuid.uuid,
234 strlen(sbi->ll_mdc_exp->exp_obd->obd_uuid.uuid));
238 obd = class_name2obd(osc);
240 CERROR("OSC %s: not setup or attached\n", osc);
244 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid);
246 CERROR("An OST (osc %s) is performing recovery, of which this"
247 " client is not a part. Please wait for recovery to "
248 "complete, abort, or time out.\n", osc);
251 CERROR("cannot connect to %s: rc = %d\n", osc, err);
254 sbi->ll_osc_exp = class_conn2export(&osc_conn);
256 lustre_init_ea_size(sbi);
258 err = md_getstatus(sbi->ll_mdc_exp, &rootfid);
260 CERROR("cannot mds_connect: rc = %d\n", err);
263 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
264 sbi->ll_rootino = rootfid.id;
266 sb->s_op = &lustre_super_operations;
269 * XXX: move this to after cbd setup? */
270 err = md_getattr(sbi->ll_mdc_exp, &rootfid,
271 OBD_MD_FLNOTOBD | OBD_MD_FLBLOCKS, 0, &request);
273 CERROR("md_getattr failed for root: rc = %d\n", err);
277 err = mdc_req2lustre_md(sbi->ll_mdc_exp, request, 0,
278 sbi->ll_osc_exp, &md);
280 CERROR("failed to understand root inode md: rc = %d\n",err);
281 ptlrpc_req_finished (request);
285 LASSERT(sbi->ll_rootino != 0);
286 root = ll_iget(sb, sbi->ll_rootino, &md);
288 ptlrpc_req_finished(request);
290 if (root == NULL || is_bad_inode(root)) {
291 /* XXX might need iput() for bad inode */
292 CERROR("lustre_lite: bad iget4 for root\n");
293 GOTO(out_root, err = -EBADF);
296 err = ll_close_thread_start(&sbi->ll_lcq);
298 CERROR("cannot start close thread: rc %d\n", err);
302 ll_gns_add_timer(sbi);
304 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
305 backing dev info assigned to inode mapping is used for
306 determining maximal readahead. */
307 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
308 /* bug 2805 - set VM readahead to zero */
309 vm_max_readahead = vm_min_readahead = 0;
312 sb->s_root = d_alloc_root(root);
315 CWARN("Enabling PDIROPS\n");
316 sb->s_flags |= S_PDIROPS;
325 obd_disconnect(sbi->ll_osc_exp, 0);
327 obd_disconnect(sbi->ll_mdc_exp, 0);
329 lprocfs_unregister_mountpoint(sbi);
333 void lustre_common_put_super(struct super_block *sb)
335 struct ll_sb_info *sbi = ll_s2sbi(sb);
336 struct hlist_node *tmp, *next;
339 ll_gns_del_timer(sbi);
341 ll_close_thread_shutdown(sbi->ll_lcq);
343 list_del(&sbi->ll_conn_chain);
344 obd_disconnect(sbi->ll_osc_exp, 0);
346 lprocfs_unregister_mountpoint(sbi);
347 if (sbi->ll_proc_root) {
348 lprocfs_remove(sbi->ll_proc_root);
349 sbi->ll_proc_root = NULL;
352 obd_disconnect(sbi->ll_mdc_exp, 0);
354 // We do this to get rid of orphaned dentries. That is not really trw.
355 spin_lock(&dcache_lock);
356 hlist_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list) {
357 struct dentry *dentry = hlist_entry(tmp, struct dentry, d_hash);
358 CWARN("orphan dentry %*s (%p) at unmount\n",
359 dentry->d_name.len, dentry->d_name.name, dentry);
360 shrink_dcache_parent(dentry);
362 spin_unlock(&dcache_lock);
367 char *ll_read_opt(const char *opt, char *data)
373 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
374 if (strncmp(opt, data, strlen(opt)))
376 if ((value = strchr(data, '=')) == NULL)
380 OBD_ALLOC(retval, strlen(value) + 1);
382 CERROR("out of memory!\n");
386 memcpy(retval, value, strlen(value)+1);
387 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
391 int ll_set_opt(const char *opt, char *data, int fl)
395 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
396 if (strncmp(opt, data, strlen(opt)))
402 void ll_options(char *options, char **ost, char **mdc, int *flags,
406 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
407 char *opt_ptr = options;
416 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
417 for (this_char = strtok (options, ",");
419 this_char = strtok (NULL, ",")) {
421 while ((this_char = strsep (&opt_ptr, ",")) != NULL) {
423 CDEBUG(D_SUPER, "this_char %s\n", this_char);
424 if (!*ost && (*ost = ll_read_opt("osc", this_char)))
426 if (!*mdc && (*mdc = ll_read_opt("mdc", this_char)))
428 if (!*clone_opts && (*clone_opts = ll_read_opt("clone",
431 if (!(*flags & LL_SBI_NOLCK) &&
432 ((*flags) = (*flags) |
433 ll_set_opt("nolock", this_char,
441 void ll_lli_init(struct ll_inode_info *lli)
443 sema_init(&lli->lli_open_sem, 1);
445 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
446 spin_lock_init(&lli->lli_lock);
447 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
448 lli->lli_inode_magic = LLI_INODE_MAGIC;
451 int ll_fill_super(struct super_block *sb, void *data, int silent)
453 struct ll_sb_info *sbi;
456 char *clone_opts = NULL;
460 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
462 sbi = lustre_init_sbi(sb);
466 sbi->ll_flags |= LL_SBI_READAHEAD;
467 ll_options(data, &osc, &mdc, &sbi->ll_flags, &clone_opts);
471 GOTO(out, err = -EINVAL);
476 GOTO(out, err = -EINVAL);
479 err = lustre_common_fill_super(sb, mdc, osc);
485 /*set clone info to the super block*/
486 clone_index = simple_strtoul(clone_opts, &endp, 0);
487 err = lustre_set_clone_info(sb, clone_index);
495 OBD_FREE(mdc, strlen(mdc) + 1);
497 OBD_FREE(osc, strlen(osc) + 1);
499 OBD_FREE(clone_opts, strlen(clone_opts) + 1);
502 } /* ll_read_super */
504 static int lustre_process_log(struct lustre_mount_data *lmd, char *profile,
505 struct config_llog_instance *cfg, int allow_recov)
507 struct lustre_cfg lcfg;
508 struct portals_cfg pcfg;
509 char * peer = "MDS_PEER_UUID";
510 struct obd_device *obd;
511 struct lustre_handle mdc_conn = {0, };
512 struct obd_export *exp;
513 char * name = "mdc_dev";
515 struct obd_uuid mdc_uuid;
516 struct llog_ctxt *ctxt;
521 if (lmd_bad_magic(lmd))
524 generate_random_uuid(uuid);
525 class_uuid_unparse(uuid, &mdc_uuid);
527 if (lmd->lmd_local_nid) {
528 PCFG_INIT(pcfg, NAL_CMD_REGISTER_MYNID);
529 pcfg.pcfg_nal = lmd->lmd_nal;
530 pcfg.pcfg_nid = lmd->lmd_local_nid;
531 err = libcfs_nal_cmd(&pcfg);
536 if (lmd->lmd_nal == SOCKNAL) {
537 PCFG_INIT(pcfg, NAL_CMD_ADD_AUTOCONN);
538 pcfg.pcfg_nal = lmd->lmd_nal;
539 pcfg.pcfg_nid = lmd->lmd_server_nid;
540 pcfg.pcfg_id = lmd->lmd_server_ipaddr;
541 pcfg.pcfg_misc = lmd->lmd_port;
542 pcfg.pcfg_size = 8388608;
543 pcfg.pcfg_flags = 0x4; /*share*/
544 err = libcfs_nal_cmd(&pcfg);
549 LCFG_INIT(lcfg, LCFG_ADD_UUID, name);
550 lcfg.lcfg_nid = lmd->lmd_server_nid;
551 lcfg.lcfg_inllen1 = strlen(peer) + 1;
552 lcfg.lcfg_inlbuf1 = peer;
553 lcfg.lcfg_nal = lmd->lmd_nal;
554 err = class_process_config(&lcfg);
556 GOTO(out_del_conn, err);
558 LCFG_INIT(lcfg, LCFG_ATTACH, name);
559 lcfg.lcfg_inlbuf1 = "mdc";
560 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
561 lcfg.lcfg_inlbuf2 = mdc_uuid.uuid;
562 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
563 err = class_process_config(&lcfg);
565 GOTO(out_del_uuid, err);
567 LCFG_INIT(lcfg, LCFG_SETUP, name);
568 lcfg.lcfg_inlbuf1 = lmd->lmd_mds;
569 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
570 lcfg.lcfg_inlbuf2 = peer;
571 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
572 err = class_process_config(&lcfg);
574 GOTO(out_detach, err);
576 obd = class_name2obd(name);
578 GOTO(out_cleanup, err = -EINVAL);
580 /* Disable initial recovery on this import */
581 err = obd_set_info(obd->obd_self_export,
582 strlen("initial_recov"), "initial_recov",
583 sizeof(allow_recov), &allow_recov);
585 GOTO(out_cleanup, err);
587 err = obd_connect(&mdc_conn, obd, &mdc_uuid);
589 CERROR("cannot connect to %s: rc = %d\n", lmd->lmd_mds, err);
590 GOTO(out_cleanup, err);
593 exp = class_conn2export(&mdc_conn);
595 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,LLOG_CONFIG_REPL_CTXT);
596 rc = class_config_process_llog(ctxt, profile, cfg);
598 CERROR("class_config_process_llog failed: rc = %d\n", rc);
600 err = obd_disconnect(exp, 0);
603 LCFG_INIT(lcfg, LCFG_CLEANUP, name);
604 err = class_process_config(&lcfg);
609 LCFG_INIT(lcfg, LCFG_DETACH, name);
610 err = class_process_config(&lcfg);
615 LCFG_INIT(lcfg, LCFG_DEL_UUID, name);
616 lcfg.lcfg_inllen1 = strlen(peer) + 1;
617 lcfg.lcfg_inlbuf1 = peer;
618 err = class_process_config(&lcfg);
621 if (lmd->lmd_nal == SOCKNAL) {
622 PCFG_INIT(pcfg, NAL_CMD_DEL_AUTOCONN);
623 pcfg.pcfg_nal = lmd->lmd_nal;
624 pcfg.pcfg_nid = lmd->lmd_server_nid;
625 pcfg.pcfg_id = lmd->lmd_server_ipaddr;
626 pcfg.pcfg_flags = 1; /*share*/
627 err = libcfs_nal_cmd(&pcfg);
638 int lustre_fill_super(struct super_block *sb, void *data, int silent)
640 struct lustre_mount_data * lmd = data;
641 struct ll_sb_info *sbi;
647 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
648 if (lmd_bad_magic(lmd))
651 sbi = lustre_init_sbi(sb);
655 sbi->ll_flags |= LL_SBI_READAHEAD;
657 if (lmd->lmd_profile) {
658 struct lustre_profile *lprof;
659 struct config_llog_instance cfg;
662 if (lmd->lmd_mds[0] == '\0') {
663 CERROR("no mds name\n");
664 GOTO(out_free, err = -EINVAL);
667 OBD_ALLOC(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
668 if (sbi->ll_lmd == NULL)
669 GOTO(out_free, err = -ENOMEM);
670 memcpy(sbi->ll_lmd, lmd, sizeof(*lmd));
672 /* generate a string unique to this super, let's try
673 the address of the super itself.*/
674 len = (sizeof(sb) * 2) + 1;
675 OBD_ALLOC(sbi->ll_instance, len);
676 if (sbi->ll_instance == NULL)
677 GOTO(out_free, err = -ENOMEM);
678 sprintf(sbi->ll_instance, "%p", sb);
680 cfg.cfg_instance = sbi->ll_instance;
681 cfg.cfg_uuid = sbi->ll_sb_uuid;
682 cfg.cfg_local_nid = lmd->lmd_local_nid;
683 err = lustre_process_log(lmd, lmd->lmd_profile, &cfg, 0);
685 CERROR("Unable to process log: %s\n", lmd->lmd_profile);
689 lprof = class_get_profile(lmd->lmd_profile);
691 CERROR("No profile found: %s\n", lmd->lmd_profile);
692 GOTO(out_free, err = -EINVAL);
695 OBD_FREE(osc, strlen(osc) + 1);
696 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
697 strlen(sbi->ll_instance) + 2);
698 sprintf(osc, "%s-%s", lprof->lp_osc, sbi->ll_instance);
701 OBD_FREE(mdc, strlen(mdc) + 1);
702 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
703 strlen(sbi->ll_instance) + 2);
704 sprintf(mdc, "%s-%s", lprof->lp_mdc, sbi->ll_instance);
709 GOTO(out_free, err = -EINVAL);
714 GOTO(out_free, err = -EINVAL);
717 err = lustre_common_fill_super(sb, mdc, osc);
723 if (lmd->lmd_clone_index) {
724 err = lustre_set_clone_info(sb, lmd->lmd_clone_index);
733 OBD_FREE(mdc, strlen(mdc) + 1);
735 OBD_FREE(osc, strlen(osc) + 1);
741 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
744 if (sbi->ll_instance != NULL) {
745 struct lustre_mount_data *lmd = sbi->ll_lmd;
747 struct config_llog_instance cfg;
749 cfg.cfg_instance = sbi->ll_instance;
750 cfg.cfg_uuid = sbi->ll_sb_uuid;
752 OBD_ALLOC(cln_prof, len);
753 sprintf(cln_prof, "%s-clean", lmd->lmd_profile);
755 err = lustre_process_log(lmd, cln_prof, &cfg, 0);
757 CERROR("Unable to process log: %s\n", cln_prof);
758 OBD_FREE(cln_prof, len);
759 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance)+ 1);
761 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
764 lustre_cleanup_clone_info(sb);
769 } /* lustre_fill_super */
771 static void lustre_manual_cleanup(struct ll_sb_info *sbi)
773 struct lustre_cfg lcfg;
774 struct obd_device *obd;
777 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) != NULL)
781 LCFG_INIT(lcfg, LCFG_CLEANUP, obd->obd_name);
782 err = class_process_config(&lcfg);
784 CERROR("cleanup failed: %s\n", obd->obd_name);
788 LCFG_INIT(lcfg, LCFG_DETACH, obd->obd_name);
789 err = class_process_config(&lcfg);
791 CERROR("detach failed: %s\n", obd->obd_name);
796 if (sbi->ll_lmd != NULL)
797 class_del_profile(sbi->ll_lmd->lmd_profile);
800 void lustre_put_super(struct super_block *sb)
802 struct obd_device *obd;
803 struct ll_sb_info *sbi = ll_s2sbi(sb);
804 int force_umount = 0;
807 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
808 obd = class_exp2obd(sbi->ll_mdc_exp);
810 force_umount = obd->obd_no_recov;
814 lustre_cleanup_clone_info(sb);
817 lustre_common_put_super(sb);
818 if (sbi->ll_lmd != NULL) {
820 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
822 struct config_llog_instance cfg;
825 CERROR("force umount, doing manual cleanup\n");
826 lustre_manual_cleanup(sbi);
830 cfg.cfg_instance = sbi->ll_instance;
831 cfg.cfg_uuid = sbi->ll_sb_uuid;
833 OBD_ALLOC(cln_prof, len);
834 sprintf(cln_prof, "%s-clean", sbi->ll_lmd->lmd_profile);
836 err = lustre_process_log(sbi->ll_lmd, cln_prof, &cfg, 0);
838 CERROR("Unable to process log: %s, doing manual cleanup"
840 lustre_manual_cleanup(sbi);
843 OBD_FREE(cln_prof, len);
845 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
846 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance) + 1);
852 } /* lustre_put_super */
854 int ll_process_config_update(struct ll_sb_info *sbi, int clean)
856 struct obd_export *mdc_exp = sbi->ll_mdc_exp;
857 struct lustre_mount_data *lmd = sbi->ll_lmd;
858 struct llog_ctxt *ctxt;
859 struct config_llog_instance cfg;
860 char *profile = lmd->lmd_profile, *name = NULL;
861 int rc, namelen = 0, version;
867 CERROR("Client not mounted with zero-conf; cannot process "
872 rc = ldlm_cli_cancel_unused(mdc_exp->exp_obd->obd_namespace, NULL,
873 LDLM_FL_CONFIG_CHANGE, NULL);
875 CWARN("ldlm_cli_cancel_unused(mdc): %d\n", rc);
877 rc = obd_cancel_unused(sbi->ll_osc_exp, NULL, LDLM_FL_CONFIG_CHANGE,
880 CWARN("obd_cancel_unused(lov): %d\n", rc);
882 cfg.cfg_instance = sbi->ll_instance;
883 cfg.cfg_uuid = sbi->ll_sb_uuid;
884 cfg.cfg_local_nid = lmd->lmd_local_nid;
886 namelen = strlen(profile) + 20; /* -clean-######### */
887 OBD_ALLOC(name, namelen);
892 version = sbi->ll_config_version - 1;
893 sprintf(name, "%s-clean-%d", profile, version);
895 version = sbi->ll_config_version + 1;
896 sprintf(name, "%s-%d", profile, version);
899 CWARN("Applying configuration log %s\n", name);
901 ctxt = llog_get_context(&mdc_exp->exp_obd->obd_llogs,
902 LLOG_CONFIG_REPL_CTXT);
903 rc = class_config_process_llog(ctxt, name, &cfg);
905 sbi->ll_config_version = version;
906 CWARN("Finished applying configuration log %s: %d\n", name, rc);
908 if (rc == 0 && clean == 0) {
909 struct lov_desc desc;
911 valsize = sizeof(desc);
912 rc = obd_get_info(sbi->ll_osc_exp, strlen("lovdesc") + 1,
913 "lovdesc", &valsize, &desc);
915 rc = obd_init_ea_size(mdc_exp,
916 obd_size_diskmd(sbi->ll_osc_exp, NULL),
918 sizeof(struct llog_cookie)));
920 OBD_FREE(name, namelen);
924 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
926 struct inode *inode = NULL;
927 l_lock(&lock->l_resource->lr_namespace->ns_lock);
928 if (lock->l_ast_data) {
929 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
930 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
931 inode = igrab(lock->l_ast_data);
933 CERROR("DEBUG: l_ast_data %p is bogus: magic %x\n",
934 lock->l_ast_data, lli->lli_inode_magic);
937 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
941 int null_if_equal(struct ldlm_lock *lock, void *data)
943 if (data == lock->l_ast_data)
944 lock->l_ast_data = NULL;
946 if (lock->l_req_mode != lock->l_granted_mode)
947 return LDLM_ITER_STOP;
949 return LDLM_ITER_CONTINUE;
952 void ll_clear_inode(struct inode *inode)
955 struct ll_inode_info *lli = ll_i2info(inode);
956 struct ll_sb_info *sbi = ll_i2sbi(inode);
959 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
960 inode->i_generation, inode);
962 lli->lli_inode_magic = LLI_INODE_DEAD;
963 ll_inode2fid(&fid, inode);
964 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(ll_i2info(inode)->lli_flags));
965 md_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
968 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
969 null_if_equal, inode);
972 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
977 /* FIXME: change cbdata for mea here */
978 obd_free_memmd(sbi->ll_mdc_exp,
979 (struct lov_stripe_md **) &lli->lli_mea);
983 if (lli->lli_symlink_name) {
984 OBD_FREE(lli->lli_symlink_name,
985 strlen(lli->lli_symlink_name) + 1);
986 lli->lli_symlink_name = NULL;
992 /* If this inode has objects allocated to it (lsm != NULL), then the OST
993 * object(s) determine the file size and mtime. Otherwise, the MDS will
994 * keep these values until such a time that objects are allocated for it.
995 * We do the MDS operations first, as it is checking permissions for us.
996 * We don't to the MDS RPC if there is nothing that we want to store there,
997 * otherwise there is no harm in updating mtime/atime on the MDS if we are
998 * going to do an RPC anyways.
1000 * If we are doing a truncate, we will send the mtime and ctime updates
1001 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1002 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1005 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1007 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1008 struct ll_sb_info *sbi = ll_i2sbi(inode);
1009 struct ptlrpc_request *request = NULL;
1010 struct mdc_op_data op_data;
1011 int ia_valid = attr->ia_valid;
1015 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
1016 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
1018 if (ia_valid & ATTR_SIZE) {
1019 if (attr->ia_size > ll_file_maxbytes(inode)) {
1020 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1021 attr->ia_size, ll_file_maxbytes(inode));
1025 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1028 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1029 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1030 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1034 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1035 if (attr->ia_valid & ATTR_CTIME) {
1036 attr->ia_ctime = CURRENT_TIME;
1037 attr->ia_valid |= ATTR_CTIME_SET;
1039 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1040 attr->ia_atime = CURRENT_TIME;
1041 attr->ia_valid |= ATTR_ATIME_SET;
1043 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1044 attr->ia_mtime = CURRENT_TIME;
1045 attr->ia_valid |= ATTR_MTIME_SET;
1048 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1049 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1050 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1051 LTIME_S(CURRENT_TIME));
1053 attr->ia_valid &= ~ATTR_SIZE;
1055 /* If only OST attributes being set on objects, don't do MDS RPC.
1056 * In that case, we need to check permissions and update the local
1057 * inode ourselves so we can call obdo_from_inode() always. */
1058 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
1059 struct lustre_md md;
1060 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1062 rc = md_setattr(sbi->ll_mdc_exp, &op_data,
1063 attr, NULL, 0, NULL, 0, &request);
1065 ptlrpc_req_finished(request);
1066 if (rc != -EPERM && rc != -EACCES)
1067 CERROR("md_setattr fails: rc = %d\n", rc);
1071 rc = mdc_req2lustre_md(sbi->ll_mdc_exp, request, 0,
1072 sbi->ll_osc_exp, &md);
1074 ptlrpc_req_finished(request);
1078 /* Won't invoke vmtruncate as we already cleared ATTR_SIZE,
1079 * but needed to set timestamps backwards on utime. */
1080 inode_setattr(inode, attr);
1081 ll_update_inode(inode, &md);
1082 ptlrpc_req_finished(request);
1084 if (!lsm || !S_ISREG(inode->i_mode)) {
1085 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1089 /* The OST doesn't check permissions, but the alternative is
1090 * a gratuitous RPC to the MDS. We already rely on the client
1091 * to do read/write/truncate permission checks, so is mtime OK?
1093 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
1094 /* from sys_utime() */
1095 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
1096 if (current->fsuid != inode->i_uid &&
1097 (rc=ll_permission(inode,MAY_WRITE,NULL))!=0)
1100 /* from inode_change_ok() */
1101 if (current->fsuid != inode->i_uid &&
1102 !capable(CAP_FOWNER))
1107 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
1108 inode_setattr(inode, attr);
1111 /* We really need to get our PW lock before we change inode->i_size.
1112 * If we don't we can race with other i_size updaters on our node, like
1113 * ll_file_read. We can also race with i_size propogation to other
1114 * nodes through dirtying and writeback of final cached pages. This
1115 * last one is especially bad for racing o_append users on other
1117 if (ia_valid & ATTR_SIZE) {
1118 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
1120 struct lustre_handle lockh = { 0 };
1121 int err, ast_flags = 0;
1122 /* XXX when we fix the AST intents to pass the discard-range
1123 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1125 if (attr->ia_size == 0)
1126 ast_flags = LDLM_AST_DISCARD_DATA;
1128 /* bug 1639: avoid write/truncate i_sem/DLM deadlock */
1129 LASSERT(atomic_read(&inode->i_sem.count) <= 0);
1131 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy, &lockh,
1133 down(&inode->i_sem);
1137 rc = vmtruncate(inode, attr->ia_size);
1139 /* We need to drop the semaphore here, because this unlock may
1140 * result in a cancellation, which will need the i_sem */
1142 /* unlock now as we don't mind others file lockers racing with
1143 * the mds updates below? */
1144 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1145 down(&inode->i_sem);
1147 CERROR("ll_extent_unlock failed: %d\n", err);
1151 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1154 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1155 inode->i_ino, LTIME_S(attr->ia_mtime));
1156 oa.o_id = lsm->lsm_object_id;
1157 oa.o_gr = lsm->lsm_object_gr;
1158 oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1159 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
1160 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
1161 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
1163 CERROR("obd_setattr fails: rc=%d\n", rc);
1168 int ll_setattr(struct dentry *de, struct iattr *attr)
1170 LBUG(); /* code is unused, but leave this in case of VFS changes */
1174 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1175 unsigned long max_age)
1177 struct ll_sb_info *sbi = ll_s2sbi(sb);
1178 struct obd_statfs obd_osfs;
1182 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1184 CERROR("mdc_statfs fails: rc = %d\n", rc);
1188 osfs->os_type = sb->s_magic;
1190 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1191 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1193 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1195 CERROR("obd_statfs fails: rc = %d\n", rc);
1199 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1200 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1203 osfs->os_blocks = obd_osfs.os_blocks;
1204 osfs->os_bfree = obd_osfs.os_bfree;
1205 osfs->os_bavail = obd_osfs.os_bavail;
1207 /* If we don't have as many objects free on the OST as inodes
1208 * on the MDS, we reduce the total number of inodes to
1209 * compensate, so that the "inodes in use" number is correct.
1211 if (obd_osfs.os_ffree < osfs->os_ffree) {
1212 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1214 osfs->os_ffree = obd_osfs.os_ffree;
1220 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1222 struct obd_statfs osfs;
1225 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1226 lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
1228 /* For now we will always get up-to-date statfs values, but in the
1229 * future we may allow some amount of caching on the client (e.g.
1230 * from QOS or lprocfs updates). */
1231 rc = ll_statfs_internal(sb, &osfs, jiffies - 1);
1235 statfs_unpack(sfs, &osfs);
1237 if (sizeof(sfs->f_blocks) == 4) {
1238 while (osfs.os_blocks > ~0UL) {
1241 osfs.os_blocks >>= 1;
1242 osfs.os_bfree >>= 1;
1243 osfs.os_bavail >>= 1;
1247 sfs->f_blocks = osfs.os_blocks;
1248 sfs->f_bfree = osfs.os_bfree;
1249 sfs->f_bavail = osfs.os_bavail;
1254 void dump_lsm(int level, struct lov_stripe_md *lsm)
1256 CDEBUG(level, "objid "LPX64", maxbytes "LPX64", magic 0x%08X, "
1257 "stripe_size %u, stripe_count %u\n",
1258 lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
1259 lsm->lsm_stripe_size, lsm->lsm_stripe_count);
1262 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1264 struct ll_inode_info *lli = ll_i2info(inode);
1265 struct mds_body *body = md->body;
1266 struct lov_stripe_md *lsm = md->lsm;
1267 struct mea *mea = md->mea;
1270 LASSERT((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1271 LASSERT((mea != NULL) == ((body->valid & OBD_MD_FLDIREA) != 0));
1273 LASSERT(lsm->lsm_object_gr > 0);
1274 if (lli->lli_smd == NULL) {
1276 lli->lli_maxbytes = lsm->lsm_maxbytes;
1277 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1278 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1281 if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
1282 CERROR("lsm mismatch for inode %ld\n",
1284 CERROR("lli_smd:\n");
1285 dump_lsm(D_ERROR, lli->lli_smd);
1287 dump_lsm(D_ERROR, lsm);
1290 /* XXX FIXME -- We should decide on a safer (atomic) and
1291 * more elegant way to update the lsm */
1292 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1293 lli->lli_smd->lsm_oinfo[i].loi_id =
1294 lsm->lsm_oinfo[i].loi_id;
1295 lli->lli_smd->lsm_oinfo[i].loi_gr =
1296 lsm->lsm_oinfo[i].loi_gr;
1297 lli->lli_smd->lsm_oinfo[i].loi_ost_idx =
1298 lsm->lsm_oinfo[i].loi_ost_idx;
1299 lli->lli_smd->lsm_oinfo[i].loi_ost_gen =
1300 lsm->lsm_oinfo[i].loi_ost_gen;
1303 /* bug 2844 - limit i_blksize for broken user-space apps */
1304 LASSERTF(lsm->lsm_xfersize != 0, "%lu\n", lsm->lsm_xfersize);
1305 inode->i_blksize = min(lsm->lsm_xfersize, LL_MAX_BLKSIZE);
1306 if (lli->lli_smd != lsm)
1307 obd_free_memmd(ll_i2obdexp(inode), &lsm);
1311 if (lli->lli_mea == NULL) {
1314 if (memcmp(lli->lli_mea, mea, body->eadatasize)) {
1315 CERROR("mea mismatch for inode %lu\n",
1320 if (lli->lli_mea != mea)
1321 obd_free_memmd(ll_i2mdcexp(inode),
1322 (struct lov_stripe_md **) &mea);
1326 if (body->valid & OBD_MD_FLID)
1327 inode->i_ino = body->ino;
1328 if (body->valid & OBD_MD_FLATIME)
1329 LTIME_S(inode->i_atime) = body->atime;
1330 if (body->valid & OBD_MD_FLMTIME &&
1331 body->mtime > LTIME_S(inode->i_mtime)) {
1332 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %u\n",
1333 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
1334 LTIME_S(inode->i_mtime) = body->mtime;
1336 if (body->valid & OBD_MD_FLCTIME &&
1337 body->ctime > LTIME_S(inode->i_ctime))
1338 LTIME_S(inode->i_ctime) = body->ctime;
1339 if (body->valid & OBD_MD_FLMODE)
1340 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1341 if (body->valid & OBD_MD_FLTYPE)
1342 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1343 if (body->valid & OBD_MD_FLUID)
1344 inode->i_uid = body->uid;
1345 if (body->valid & OBD_MD_FLGID)
1346 inode->i_gid = body->gid;
1347 if (body->valid & OBD_MD_FLFLAGS)
1348 inode->i_flags = body->flags;
1349 if (body->valid & OBD_MD_FLNLINK)
1350 inode->i_nlink = body->nlink;
1351 if (body->valid & OBD_MD_FLGENER)
1352 inode->i_generation = body->generation;
1353 if (body->valid & OBD_MD_FLRDEV)
1354 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1355 inode->i_rdev = body->rdev;
1357 inode->i_rdev = old_decode_dev(body->rdev);
1359 if (body->valid & OBD_MD_FLSIZE)
1360 inode->i_size = body->size;
1361 if (body->valid & OBD_MD_FLBLOCKS)
1362 inode->i_blocks = body->blocks;
1364 if (body->valid & OBD_MD_FLSIZE)
1365 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1367 lli->lli_mds = body->mds;
1368 inode->i_dev = (kdev_t) body->mds;
1369 LASSERT(body->mds < 1000);
1372 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1373 static struct backing_dev_info ll_backing_dev_info = {
1374 .ra_pages = 0, /* No readahead */
1375 .memory_backed = 0, /* Does contribute to dirty memory */
1379 void ll_read_inode2(struct inode *inode, void *opaque)
1381 struct lustre_md *md = opaque;
1382 struct ll_inode_info *lli = ll_i2info(inode);
1385 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1386 inode->i_generation, inode);
1390 LASSERT(!lli->lli_smd);
1392 /* Core attributes from the MDS first. This is a new inode, and
1393 * the VFS doesn't zero times in the core inode so we have to do
1394 * it ourselves. They will be overwritten by either MDS or OST
1395 * attributes - we just need to make sure they aren't newer. */
1396 LTIME_S(inode->i_mtime) = 0;
1397 LTIME_S(inode->i_atime) = 0;
1398 LTIME_S(inode->i_ctime) = 0;
1401 ll_update_inode(inode, md);
1403 /* OIDEBUG(inode); */
1405 if (S_ISREG(inode->i_mode)) {
1406 inode->i_op = &ll_file_inode_operations;
1407 inode->i_fop = &ll_file_operations;
1408 inode->i_mapping->a_ops = &ll_aops;
1410 } else if (S_ISDIR(inode->i_mode)) {
1411 inode->i_op = &ll_dir_inode_operations;
1412 inode->i_fop = &ll_dir_operations;
1413 inode->i_mapping->a_ops = &ll_dir_aops;
1415 } else if (S_ISLNK(inode->i_mode)) {
1416 inode->i_op = &ll_fast_symlink_inode_operations;
1419 inode->i_op = &ll_special_inode_operations;
1421 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1422 init_special_inode(inode, inode->i_mode,
1423 kdev_t_to_nr(inode->i_rdev));
1425 /* initializing backing dev info. */
1426 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1428 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1430 lli->ll_save_ifop = inode->i_fop;
1432 if (S_ISCHR(inode->i_mode))
1433 inode->i_fop = &ll_special_chr_inode_fops;
1434 else if (S_ISBLK(inode->i_mode))
1435 inode->i_fop = &ll_special_blk_inode_fops;
1436 else if (S_ISFIFO(inode->i_mode))
1437 inode->i_fop = &ll_special_fifo_inode_fops;
1438 else if (S_ISSOCK(inode->i_mode))
1439 inode->i_fop = &ll_special_sock_inode_fops;
1441 CWARN("saved %p, replaced with %p\n", lli->ll_save_ifop,
1444 if (lli->ll_save_ifop->owner) {
1445 CWARN("%p has owner %p\n", lli->ll_save_ifop,
1446 lli->ll_save_ifop->owner);
1452 void ll_delete_inode(struct inode *inode)
1456 struct ll_sb_info *sbi = ll_i2sbi(inode);
1459 ll_inode2fid(&fid, inode);
1461 rc = md_delete_object(sbi->ll_mdc_exp, &fid);
1463 CERROR("md_delete_object() failed, error %d.\n",
1471 int ll_iocontrol(struct inode *inode, struct file *file,
1472 unsigned int cmd, unsigned long arg)
1474 struct ll_sb_info *sbi = ll_i2sbi(inode);
1475 struct ptlrpc_request *req = NULL;
1480 case EXT3_IOC_GETFLAGS: {
1482 unsigned long valid = OBD_MD_FLFLAGS;
1483 struct mds_body *body;
1485 ll_inode2fid(&fid, inode);
1486 rc = md_getattr(sbi->ll_mdc_exp, &fid, valid, 0, &req);
1488 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1492 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
1494 if (body->flags & S_APPEND)
1495 flags |= EXT3_APPEND_FL;
1496 if (body->flags & S_IMMUTABLE)
1497 flags |= EXT3_IMMUTABLE_FL;
1498 if (body->flags & S_NOATIME)
1499 flags |= EXT3_NOATIME_FL;
1501 ptlrpc_req_finished (req);
1503 RETURN(put_user(flags, (int *)arg));
1505 case EXT3_IOC_SETFLAGS: {
1506 struct mdc_op_data op_data;
1509 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1511 if (get_user(flags, (int *)arg))
1518 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1520 memset(&attr, 0x0, sizeof(attr));
1521 attr.ia_attr_flags = flags;
1522 attr.ia_valid |= ATTR_ATTR_FLAG;
1524 rc = md_setattr(sbi->ll_mdc_exp, &op_data,
1525 &attr, NULL, 0, NULL, 0, &req);
1527 ptlrpc_req_finished(req);
1528 if (rc != -EPERM && rc != -EACCES)
1529 CERROR("md_setattr fails: rc = %d\n", rc);
1533 ptlrpc_req_finished(req);
1535 oa->o_id = lsm->lsm_object_id;
1536 oa->o_gr = lsm->lsm_object_gr;
1537 oa->o_flags = flags;
1538 oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
1540 rc = obd_setattr(sbi->ll_osc_exp, oa, lsm, NULL);
1543 if (rc != -EPERM && rc != -EACCES)
1544 CERROR("md_setattr fails: rc = %d\n", rc);
1548 if (flags & EXT3_APPEND_FL)
1549 inode->i_flags |= S_APPEND;
1551 inode->i_flags &= ~S_APPEND;
1552 if (flags & EXT3_IMMUTABLE_FL)
1553 inode->i_flags |= S_IMMUTABLE;
1555 inode->i_flags &= ~S_IMMUTABLE;
1556 if (flags & EXT3_NOATIME_FL)
1557 inode->i_flags |= S_NOATIME;
1559 inode->i_flags &= ~S_NOATIME;
1570 void ll_umount_begin(struct super_block *sb)
1572 struct ll_sb_info *sbi = ll_s2sbi(sb);
1573 struct obd_device *obd;
1574 struct obd_ioctl_data ioc_data = { 0 };
1576 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1578 obd = class_exp2obd(sbi->ll_mdc_exp);
1580 CERROR("Invalid MDC connection handle "LPX64"\n",
1581 sbi->ll_mdc_exp->exp_handle.h_cookie);
1585 obd->obd_no_recov = 1;
1586 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
1589 obd = class_exp2obd(sbi->ll_osc_exp);
1591 CERROR("Invalid LOV connection handle "LPX64"\n",
1592 sbi->ll_osc_exp->exp_handle.h_cookie);
1597 obd->obd_no_recov = 1;
1598 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
1601 /* Really, we'd like to wait until there are no requests outstanding,
1602 * and then continue. For now, we just invalidate the requests,
1603 * schedule, and hope.
1610 int ll_prep_inode(struct obd_export *osc_exp, struct obd_export *mdc_exp,
1611 struct inode **inode, struct ptlrpc_request *req,
1612 int offset, struct super_block *sb)
1614 struct lustre_md md;
1617 rc = mdc_req2lustre_md(mdc_exp, req, offset, osc_exp, &md);
1622 ll_update_inode(*inode, &md);
1625 *inode = ll_iget(sb, md.body->ino, &md);
1626 if (*inode == NULL || is_bad_inode(*inode)) {
1627 /* free the lsm if we allocated one above */
1629 obd_free_memmd(osc_exp, &md.lsm);
1631 obd_free_memmd(mdc_exp,
1632 (struct lov_stripe_md**)&md.mea);
1634 CERROR("new_inode -fatal: rc %d\n", rc);