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>
30 #include <linux/seq_file.h>
32 #include <linux/lustre_lite.h>
33 #include <linux/lustre_ha.h>
34 #include <linux/lustre_dlm.h>
35 #include <linux/lprocfs_status.h>
36 #include <linux/lustre_acl.h>
37 #include <linux/lustre_gs.h>
38 #include <linux/lustre_sec.h>
39 #include "llite_internal.h"
41 kmem_cache_t *ll_file_data_slab;
42 kmem_cache_t *ll_intent_slab;
44 extern struct address_space_operations ll_aops;
45 extern struct address_space_operations ll_dir_aops;
48 #define log2(n) ffz(~(n))
51 struct ll_sb_info *lustre_init_sbi(struct super_block *sb)
53 struct ll_sb_info *sbi = NULL;
57 OBD_ALLOC(sbi, sizeof(*sbi));
61 spin_lock_init(&sbi->ll_lock);
62 INIT_LIST_HEAD(&sbi->ll_pglist);
63 sbi->ll_pglist_gen = 0;
64 if (num_physpages < SBI_DEFAULT_RA_MAX / 4)
65 sbi->ll_ra_info.ra_max_pages = num_physpages / 4;
67 sbi->ll_ra_info.ra_max_pages = SBI_DEFAULT_RA_MAX;
68 INIT_LIST_HEAD(&sbi->ll_conn_chain);
69 INIT_HLIST_HEAD(&sbi->ll_orphan_dentry_list);
70 INIT_LIST_HEAD(&sbi->ll_mnt_list);
72 sema_init(&sbi->ll_gns_sem, 1);
73 spin_lock_init(&sbi->ll_gns_lock);
74 INIT_LIST_HEAD(&sbi->ll_gns_sbi_head);
75 init_waitqueue_head(&sbi->ll_gns_waitq);
76 init_completion(&sbi->ll_gns_mount_finished);
78 /* this later may be reset via /proc/fs/... */
79 memcpy(sbi->ll_gns_oname, ".mntinfo", strlen(".mntinfo"));
80 sbi->ll_gns_oname[strlen(sbi->ll_gns_oname)] = '\0';
82 /* this later may be reset via /proc/fs/... */
83 memcpy(sbi->ll_gns_upcall, "/usr/sbin/gns_upcall",
84 strlen("/usr/sbin/gns_upcall"));
85 sbi->ll_gns_upcall[strlen(sbi->ll_gns_upcall)] = '\0';
87 /* default values, may be changed via /proc/fs/... */
88 sbi->ll_gns_state = LL_GNS_IDLE;
89 sbi->ll_gns_pending_dentry = NULL;
90 atomic_set(&sbi->ll_gns_enabled, 1);
91 sbi->ll_gns_tick = GNS_TICK_TIMEOUT;
92 sbi->ll_gns_timeout = GNS_MOUNT_TIMEOUT;
94 sbi->ll_gns_timer.data = (unsigned long)sbi;
95 sbi->ll_gns_timer.function = ll_gns_timer_callback;
96 init_timer(&sbi->ll_gns_timer);
100 generate_random_uuid(uuid);
101 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
105 void lustre_free_sbi(struct super_block *sb)
107 struct ll_sb_info *sbi = ll_s2sbi(sb);
111 list_del(&sbi->ll_gns_sbi_head);
112 del_timer(&sbi->ll_gns_timer);
113 OBD_FREE(sbi, sizeof(*sbi));
115 ll_set_sbi(sb, NULL);
119 int lustre_init_dt_desc(struct ll_sb_info *sbi)
125 valsize = sizeof(sbi->ll_dt_desc);
126 memset(&sbi->ll_dt_desc, 0, sizeof(sbi->ll_dt_desc));
127 rc = obd_get_info(sbi->ll_dt_exp, strlen("lovdesc") + 1,
128 "lovdesc", &valsize, &sbi->ll_dt_desc);
132 static int lustre_connect_mds(struct super_block *sb, char *lmv,
133 struct obd_connect_data *data,
134 char *mds_security, int async, int pag)
136 struct ll_sb_info *sbi = ll_s2sbi(sb);
137 struct lustre_handle md_conn = {0, };
138 struct obd_device *md_obd;
139 struct obd_statfs osfs;
140 unsigned long sec_flags;
145 md_obd = class_name2obd(lmv);
147 CERROR("MDC %s: not setup or attached\n", lmv);
151 obd_set_info(md_obd->obd_self_export, strlen("async"), "async",
152 sizeof(async), &async);
154 err = obd_set_info(md_obd->obd_self_export, strlen("sec"), "sec",
155 strlen(mds_security), mds_security);
158 CERROR("LMV %s: failed to set security %s, err %d\n",
159 lmv, mds_security, err);
164 sec_flags = PTLRPC_SEC_FL_PAG;
165 err = obd_set_info(md_obd->obd_self_export,
166 strlen("sec_flags"), "sec_flags",
167 sizeof(sec_flags), &sec_flags);
169 OBD_FREE(data, sizeof(*data));
174 err = obd_connect(&md_conn, md_obd, &sbi->ll_sb_uuid, data,
175 OBD_OPT_REAL_CLIENT);
177 CERROR("An MDS (lmv %s) is performing recovery, of which this"
178 " client is not a part. Please wait for recovery to "
179 "complete, abort, or time out.\n", lmv);
182 CERROR("cannot connect to %s: rc = %d\n", lmv, err);
186 sbi->ll_md_exp = class_conn2export(&md_conn);
188 err = obd_statfs(md_obd, &osfs, jiffies - HZ);
190 GOTO(out_disconnect, err);
192 if (!osfs.os_bsize) {
193 CERROR("Invalid block size is detected.");
194 GOTO(out_disconnect, err);
197 sb->s_magic = LL_SUPER_MAGIC;
198 sb->s_blocksize = osfs.os_bsize;
199 sb->s_blocksize_bits = log2(osfs.os_bsize);
200 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
202 /* in 2.6.x FS is not allowed to form s_dev */
203 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
207 devno = get_uuid2int((char *)sbi->ll_md_exp->exp_obd->obd_uuid.uuid,
208 strlen((char *)sbi->ll_md_exp->exp_obd->obd_uuid.uuid));
214 /* after statfs, we are supposed to have connected to MDSs,
215 * so it's ok to check remote flag returned.
217 valsize = sizeof(&sbi->ll_remote);
218 err = obd_get_info(sbi->ll_md_exp, strlen("remote_flag"), "remote_flag",
219 &valsize, &sbi->ll_remote);
221 CERROR("fail to obtain remote flag\n");
222 GOTO(out_disconnect, err);
227 obd_disconnect(sbi->ll_md_exp, 0);
231 static int lustre_connect_ost(struct super_block *sb, char *lov,
232 struct obd_connect_data *data,
233 char *oss_security, int async, int pag)
235 struct ll_sb_info *sbi = ll_s2sbi(sb);
236 struct lustre_handle dt_conn = {0, };
237 struct obd_device *obd = NULL;
238 unsigned long sec_flags;
241 obd = class_name2obd(lov);
243 CERROR("OSC %s: not setup or attached\n", lov);
244 GOTO(out, err = -EINVAL);
246 obd_set_info(obd->obd_self_export, strlen("async"), "async",
247 sizeof(async), &async);
249 if (oss_security == NULL)
250 oss_security = "null";
252 err = obd_set_info(obd->obd_self_export, strlen("sec"), "sec",
253 strlen(oss_security), oss_security);
255 CERROR("LOV %s: failed to set security %s, err %d\n",
256 lov, oss_security, err);
261 sec_flags = PTLRPC_SEC_FL_PAG;
262 err = obd_set_info(obd->obd_self_export,
263 strlen("sec_flags"), "sec_flags",
264 sizeof(sec_flags), &sec_flags);
266 OBD_FREE(data, sizeof(*data));
271 err = obd_connect(&dt_conn, obd, &sbi->ll_sb_uuid, data, 0);
273 CERROR("An OST (lov %s) is performing recovery, of which this"
274 " client is not a part. Please wait for recovery to "
275 "complete, abort, or time out.\n", lov);
278 CERROR("cannot connect to %s: rc = %d\n", lov, err);
281 sbi->ll_dt_exp = class_conn2export(&dt_conn);
283 err = lustre_init_dt_desc(sbi);
286 CWARN("init dt_desc error %d \n", err);
289 mdsize = obd_size_diskmd(sbi->ll_dt_exp, NULL);
290 obd_init_ea_size(sbi->ll_md_exp, mdsize, sbi->ll_dt_desc.ld_tgt_count *
291 sizeof(struct llog_cookie));
296 extern struct dentry_operations ll_d_ops;
298 static int lustre_init_root_inode(struct super_block *sb)
300 struct ll_sb_info *sbi = ll_s2sbi(sb);
301 struct ptlrpc_request *request = NULL;
302 struct inode *root = NULL;
307 err = md_getstatus(sbi->ll_md_exp, &sbi->ll_rootid);
309 CERROR("cannot mds_connect: rc = %d\n", err);
312 CDEBUG(D_SUPER, "rootid "DLID4"\n", OLID4(&sbi->ll_rootid));
314 sb->s_op = &lustre_super_operations;
316 /* make root inode */
317 err = md_getattr(sbi->ll_md_exp, &sbi->ll_rootid,
318 (OBD_MD_FLNOTOBD | OBD_MD_FLBLOCKS | OBD_MD_FID),
319 NULL, NULL, 0, 0, &request);
321 CERROR("md_getattr failed for root: rc = %d\n", err);
325 err = mdc_req2lustre_md(sbi->ll_md_exp, request, 0,
326 sbi->ll_dt_exp, &md);
328 CERROR("failed to understand root inode md: rc = %d\n", err);
329 ptlrpc_req_finished(request);
333 LASSERT(id_ino(&sbi->ll_rootid) != 0);
334 root = ll_iget(sb, id_ino(&sbi->ll_rootid), &md);
336 ptlrpc_req_finished(request);
338 if (root == NULL || is_bad_inode(root)) {
340 obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
342 obd_free_memmd(sbi->ll_md_exp,
343 (struct lov_stripe_md**)&md.mea);
344 CERROR("lustre_lite: bad iget4 for root\n");
345 GOTO(out_root, err = -EBADF);
347 sb->s_root = d_alloc_root(root);
348 sb->s_root->d_op = &ll_d_ops;
356 int lustre_common_fill_super(struct super_block *sb, char *lmv, char *lov,
357 char *gkc, int async, char *mds_security,
358 char *oss_security, __u32 *nllu, int pag,
361 struct ll_sb_info *sbi = ll_s2sbi(sb);
362 struct obd_connect_data *data;
366 /*process the connect flags*/
367 if ((*remote & (OBD_CONNECT_LOCAL | OBD_CONNECT_REMOTE)) ==
368 (OBD_CONNECT_LOCAL | OBD_CONNECT_REMOTE)) {
369 CERROR("wrong remote flag "LPX64"\n", *remote);
373 OBD_ALLOC(data, sizeof(*data));
377 data->ocd_connect_flags |= *remote & (OBD_CONNECT_LOCAL |
379 memcpy(data->ocd_nllu, nllu, sizeof(data->ocd_nllu));
381 if (proc_lustre_fs_root) {
382 err = lprocfs_register_mountpoint(proc_lustre_fs_root,
385 CERROR("could not register mount in /proc/lustre");
389 err = lustre_connect_mds(sb, lmv, data, mds_security, async, pag);
394 err = lustre_connect_ost(sb, lov, data, oss_security, async, pag);
398 err = lustre_init_crypto(sb, gkc, data, async);
400 CERROR("Could not connect to GSS err %d\n", err);
404 err = lustre_init_root_inode(sb);
408 err = ll_close_thread_start(&sbi->ll_lcq);
410 CERROR("cannot start close thread: rc %d\n", err);
414 ll_gns_add_timer(sbi);
416 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
417 backing dev info assigned to inode mapping is used for
418 determining maximal readahead. */
419 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && \
420 !defined(KERNEL_HAS_AS_MAX_READAHEAD)
421 /* bug 2805 - set VM readahead to zero */
422 vm_max_readahead = vm_min_readahead = 0;
424 sb->s_flags |= MS_POSIXACL;
426 CWARN("Enabling PDIROPS\n");
427 sb->s_flags |= S_PDIROPS;
430 OBD_FREE(data, sizeof(*data));
436 lustre_destroy_crypto(sb);
438 obd_disconnect(sbi->ll_md_exp, 0);
441 OBD_FREE(data, sizeof(*data));
442 lprocfs_unregister_mountpoint(sbi);
446 void lustre_common_put_super(struct super_block *sb)
448 struct ll_sb_info *sbi = ll_s2sbi(sb);
449 struct hlist_node *tmp, *next;
452 ll_gns_del_timer(sbi);
453 ll_close_thread_shutdown(sbi->ll_lcq);
455 lustre_destroy_crypto(sb);
457 list_del(&sbi->ll_conn_chain);
458 obd_disconnect(sbi->ll_dt_exp, 0);
460 lprocfs_unregister_mountpoint(sbi);
461 if (sbi->ll_proc_root) {
462 lprocfs_remove(sbi->ll_proc_root);
463 sbi->ll_proc_root = NULL;
466 obd_disconnect(sbi->ll_md_exp, 0);
468 // We do this to get rid of orphaned dentries. That is not really trw.
469 hlist_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list) {
470 struct dentry *dentry = hlist_entry(tmp, struct dentry, d_hash);
471 CWARN("orphan dentry %.*s (%p->%p) at unmount\n",
472 dentry->d_name.len, dentry->d_name.name, dentry, next);
473 shrink_dcache_parent(dentry);
478 char *ll_read_opt(const char *opt, char *data)
484 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
485 if (strncmp(opt, data, strlen(opt)))
487 if ((value = strchr(data, '=')) == NULL)
491 OBD_ALLOC(retval, strlen(value) + 1);
493 CERROR("out of memory!\n");
497 memcpy(retval, value, strlen(value)+1);
498 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
502 int ll_set_opt(const char *opt, char *data, int fl)
506 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
507 if (strncmp(opt, data, strlen(opt)))
513 void ll_options(char *options, char **lov, char **lmv, char **gkc,
514 char **mds_sec, char **oss_sec, int *async, int *flags)
517 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
518 char *opt_ptr = options;
528 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
529 for (this_char = strtok (options, ",");
531 this_char = strtok (NULL, ",")) {
533 while ((this_char = strsep (&opt_ptr, ",")) != NULL) {
535 CDEBUG(D_SUPER, "this_char %s\n", this_char);
536 if (!*lov && (*lov = ll_read_opt("osc", this_char)))
538 if (!*lmv && (*lmv = ll_read_opt("mdc", this_char)))
540 if (!*gkc && (*gkc = ll_read_opt("gkc", this_char)))
542 if (!strncmp(this_char, "lasync", strlen("lasync"))) {
546 if (!*mds_sec && (*mds_sec = ll_read_opt("mds_sec", this_char)))
548 if (!*oss_sec && (*oss_sec = ll_read_opt("oss_sec", this_char)))
550 if (!(*flags & LL_SBI_NOLCK) &&
551 ((*flags) = (*flags) |
552 ll_set_opt("nolock", this_char,
560 void ll_lli_init(struct ll_inode_info *lli)
562 sema_init(&lli->lli_open_sem, 1);
563 sema_init(&lli->lli_size_sem, 1);
565 lli->lli_size_pid = 0;
566 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
567 spin_lock_init(&lli->lli_lock);
568 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
569 INIT_LIST_HEAD(&lli->lli_close_item);
570 lli->lli_inode_magic = LLI_INODE_MAGIC;
571 memset(&lli->lli_id, 0, sizeof(lli->lli_id));
572 sema_init(&lli->lli_och_sem, 1);
573 lli->lli_mds_read_och = lli->lli_mds_write_och = NULL;
574 lli->lli_mds_exec_och = NULL;
575 lli->lli_open_fd_read_count = lli->lli_open_fd_write_count = 0;
576 lli->lli_open_fd_exec_count = 0;
577 lli->lli_key_info = NULL;
580 int ll_fill_super(struct super_block *sb, void *data, int silent)
582 struct ll_sb_info *sbi;
583 char *lov = NULL, *lmv = NULL, *gkc = NULL;
584 char *mds_sec = NULL;
585 char *oss_sec = NULL;
587 __u32 nllu[2] = { NOBODY_UID, NOBODY_GID };
588 __u64 remote_flag = 0;
591 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
593 sbi = lustre_init_sbi(sb);
597 sbi->ll_flags |= LL_SBI_READAHEAD;
598 ll_options(data, &lov, &lmv, &gkc, &mds_sec, &oss_sec,
599 &async, &sbi->ll_flags);
602 CERROR("no osc %p or no mdc %p\n", lov, lmv);
603 GOTO(out, err = -EINVAL);
606 err = lustre_common_fill_super(sb, lmv, lov, gkc, async, mds_sec,
607 oss_sec, nllu, 0, &remote_flag);
614 OBD_FREE(lmv, strlen(lmv) + 1);
616 OBD_FREE(lov, strlen(lov) + 1);
618 OBD_FREE(mds_sec, strlen(mds_sec) + 1);
620 OBD_FREE(oss_sec, strlen(oss_sec) + 1);
623 } /* ll_read_super */
625 static int lustre_process_log(struct lustre_mount_data *lmd, char *profile,
626 struct config_llog_instance *cfg, int allow_recov)
628 struct lustre_cfg *lcfg = NULL;
629 struct lustre_cfg_bufs bufs;
630 struct portals_cfg pcfg;
631 char *peer = "MDS_PEER_UUID";
632 struct obd_device *obd;
633 struct lustre_handle md_conn = {0, };
634 struct obd_export *exp;
635 char *name = "mdc_dev";
637 struct obd_uuid lmv_uuid;
638 struct llog_ctxt *ctxt;
642 if (lmd_bad_magic(lmd))
645 generate_random_uuid(uuid);
646 class_uuid_unparse(uuid, &lmv_uuid);
648 if (lmd->lmd_local_nid) {
649 PCFG_INIT(pcfg, NAL_CMD_REGISTER_MYNID);
650 pcfg.pcfg_nal = lmd->lmd_nal;
651 pcfg.pcfg_nid = lmd->lmd_local_nid;
652 rc = libcfs_nal_cmd(&pcfg);
657 if (lmd->lmd_nal == SOCKNAL ||
658 lmd->lmd_nal == OPENIBNAL ||
659 lmd->lmd_nal == IIBNAL ||
660 lmd->lmd_nal == VIBNAL ||
661 lmd->lmd_nal == RANAL) {
662 PCFG_INIT(pcfg, NAL_CMD_ADD_PEER);
663 pcfg.pcfg_nal = lmd->lmd_nal;
664 pcfg.pcfg_nid = lmd->lmd_server_nid;
665 pcfg.pcfg_id = lmd->lmd_server_ipaddr;
666 pcfg.pcfg_misc = lmd->lmd_port;
667 rc = libcfs_nal_cmd(&pcfg);
671 lustre_cfg_bufs_reset(&bufs, name);
672 lustre_cfg_bufs_set_string(&bufs, 1, peer);
674 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
675 lcfg->lcfg_nal = lmd->lmd_nal;
676 lcfg->lcfg_nid = lmd->lmd_server_nid;
677 LASSERT(lcfg->lcfg_nal);
678 LASSERT(lcfg->lcfg_nid);
679 err = class_process_config(lcfg);
680 lustre_cfg_free(lcfg);
682 GOTO(out_del_conn, err);
684 lustre_cfg_bufs_reset(&bufs, name);
685 lustre_cfg_bufs_set_string(&bufs, 1, OBD_MDC_DEVICENAME);
686 lustre_cfg_bufs_set_string(&bufs, 2, (char *)lmv_uuid.uuid);
688 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
689 err = class_process_config(lcfg);
690 lustre_cfg_free(lcfg);
692 GOTO(out_del_uuid, err);
694 lustre_cfg_bufs_reset(&bufs, name);
695 lustre_cfg_bufs_set_string(&bufs, 1, lmd->lmd_mds);
696 lustre_cfg_bufs_set_string(&bufs, 2, peer);
698 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
699 err = class_process_config(lcfg);
700 lustre_cfg_free(lcfg);
702 GOTO(out_detach, err);
704 obd = class_name2obd(name);
706 GOTO(out_cleanup, rc = -EINVAL);
708 rc = obd_set_info(obd->obd_self_export, strlen("sec"), "sec",
709 strlen(lmd->lmd_mds_security), lmd->lmd_mds_security);
711 GOTO(out_cleanup, rc);
714 unsigned long sec_flags = PTLRPC_SEC_FL_PAG;
715 rc = obd_set_info(obd->obd_self_export,
716 strlen("sec_flags"), "sec_flags",
717 sizeof(sec_flags), &sec_flags);
719 GOTO(out_cleanup, rc);
722 /* Disable initial recovery on this import */
723 rc = obd_set_info(obd->obd_self_export,
724 strlen("initial_recov"), "initial_recov",
725 sizeof(allow_recov), &allow_recov);
727 GOTO(out_cleanup, rc);
729 rc = obd_connect(&md_conn, obd, &lmv_uuid, NULL, 0);
731 CERROR("cannot connect to %s: rc = %d\n", lmd->lmd_mds, rc);
732 GOTO(out_cleanup, rc);
735 exp = class_conn2export(&md_conn);
737 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,LLOG_CONFIG_REPL_CTXT);
738 rc = class_config_process_llog(ctxt, profile, cfg);
740 CERROR("class_config_process_llog failed: rc = %d\n", rc);
742 err = obd_disconnect(exp, 0);
746 lustre_cfg_bufs_reset(&bufs, name);
747 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
748 err = class_process_config(lcfg);
749 lustre_cfg_free(lcfg);
753 lustre_cfg_bufs_reset(&bufs, name);
754 lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
755 err = class_process_config(lcfg);
756 lustre_cfg_free(lcfg);
761 lustre_cfg_bufs_reset(&bufs, name);
762 lustre_cfg_bufs_set_string(&bufs, 1, peer);
763 lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
764 err = class_process_config(lcfg);
765 lustre_cfg_free(lcfg);
768 if (lmd->lmd_nal == SOCKNAL ||
769 lmd->lmd_nal == OPENIBNAL ||
770 lmd->lmd_nal == IIBNAL ||
771 lmd->lmd_nal == VIBNAL ||
772 lmd->lmd_nal == RANAL) {
775 PCFG_INIT(pcfg, NAL_CMD_DEL_PEER);
776 pcfg.pcfg_nal = lmd->lmd_nal;
777 pcfg.pcfg_nid = lmd->lmd_server_nid;
778 pcfg.pcfg_flags = 1; /* single_share */
779 err2 = libcfs_nal_cmd(&pcfg);
792 static void lustre_manual_cleanup(struct ll_sb_info *sbi)
794 struct lustre_cfg *lcfg;
795 struct lustre_cfg_bufs bufs;
796 struct obd_device *obd;
799 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) != NULL) {
802 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
803 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
804 err = class_process_config(lcfg);
806 CERROR("cleanup failed: %s\n", obd->obd_name);
810 lcfg->lcfg_command = LCFG_DETACH;
811 err = class_process_config(lcfg);
812 lustre_cfg_free(lcfg);
814 CERROR("detach failed: %s\n", obd->obd_name);
819 if (sbi->ll_lmd != NULL)
820 class_del_profile(sbi->ll_lmd->lmd_profile);
823 static int lustre_process_profile(struct super_block *sb,
824 struct lustre_mount_data *lmd,
825 char **lov, char **lmv, char **gkc)
827 struct ll_sb_info *sbi = ll_s2sbi(sb);
828 struct lustre_profile *lprof;
829 struct config_llog_instance cfg;
834 if (!lmd->lmd_profile)
837 if (lmd->lmd_mds[0] == '\0') {
838 CERROR("no mds name\n");
839 GOTO(out, err = -EINVAL);
841 lmd->lmd_mds_security[sizeof(lmd->lmd_mds_security) - 1] = 0;
842 lmd->lmd_oss_security[sizeof(lmd->lmd_oss_security) - 1] = 0;
844 OBD_ALLOC(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
845 if (sbi->ll_lmd == NULL)
846 GOTO(out, err = -ENOMEM);
847 memcpy(sbi->ll_lmd, lmd, sizeof(*lmd));
849 /* generate a string unique to this super, let's try
850 the address of the super itself.*/
851 len = (sizeof(sb) * 2) + 1;
852 OBD_ALLOC(sbi->ll_instance, len);
853 if (sbi->ll_instance == NULL)
854 GOTO(out, err = -ENOMEM);
855 sprintf(sbi->ll_instance, "%p", sb);
857 cfg.cfg_instance = sbi->ll_instance;
858 cfg.cfg_uuid = sbi->ll_sb_uuid;
859 cfg.cfg_local_nid = lmd->lmd_local_nid;
860 err = lustre_process_log(lmd, lmd->lmd_profile, &cfg, 0);
862 CERROR("Unable to process log: %s\n", lmd->lmd_profile);
866 lprof = class_get_profile(lmd->lmd_profile);
868 CERROR("No profile found: %s\n", lmd->lmd_profile);
869 GOTO(out, err = -EINVAL);
872 OBD_ALLOC(*lov, strlen(lprof->lp_lov) +
873 strlen(sbi->ll_instance) + 2);
874 sprintf(*lov, "%s-%s", lprof->lp_lov, sbi->ll_instance);
876 OBD_ALLOC(*lmv, strlen(lprof->lp_lmv) +
877 strlen(sbi->ll_instance) + 2);
878 sprintf(*lmv, "%s-%s", lprof->lp_lmv, sbi->ll_instance);
881 OBD_ALLOC(*gkc, strlen(lprof->lp_gkc) +
882 strlen(sbi->ll_instance) + 2);
883 sprintf(*gkc, "%s-%s", lprof->lp_gkc, sbi->ll_instance);
889 static int lustre_clean_profile(struct ll_sb_info *sbi, int force_umount)
891 struct lustre_mount_data *lmd = sbi->ll_lmd;
892 struct config_llog_instance cfg;
900 len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean") + 1;
903 CERROR("force umount, doing manual cleanup\n");
904 lustre_manual_cleanup(sbi);
908 if (sbi->ll_instance != NULL) {
909 cfg.cfg_instance = sbi->ll_instance;
910 cfg.cfg_uuid = sbi->ll_sb_uuid;
912 OBD_ALLOC(cl_prof, len);
913 sprintf(cl_prof, "%s-clean", lmd->lmd_profile);
914 err = lustre_process_log(lmd, cl_prof, &cfg, 0);
916 CERROR("Unable to process log: %s\n", cl_prof);
917 lustre_manual_cleanup(sbi);
919 OBD_FREE(cl_prof, len);
922 if (sbi->ll_instance)
923 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance) + 1);
924 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
928 int lustre_fill_super(struct super_block *sb, void *data, int silent)
930 struct lustre_mount_data * lmd = data;
931 char *lov = NULL, *lmv = NULL, *gkc = NULL;
932 struct ll_sb_info *sbi;
936 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
937 if (lmd_bad_magic(lmd))
940 sbi = lustre_init_sbi(sb);
944 sbi->ll_flags |= LL_SBI_READAHEAD;
946 err = lustre_process_profile(sb, lmd, &lov, &lmv, &gkc);
948 CERROR("Can not process the profile err %d \n", err);
952 CERROR("no osc %p or no mdc %p \n", lov, lmv);
953 GOTO(out_free, err = -EINVAL);
956 err = lustre_common_fill_super(sb, lmv, lov, gkc, lmd->lmd_async,
957 lmd->lmd_mds_security,
958 lmd->lmd_oss_security,
959 &lmd->lmd_nllu, lmd->lmd_pag,
960 &lmd->lmd_remote_flag);
967 OBD_FREE(lmv, strlen(lmv) + 1);
969 OBD_FREE(lov, strlen(lov) + 1);
971 OBD_FREE(gkc, strlen(gkc) + 1);
975 lustre_clean_profile(sbi, 0);
979 } /* lustre_fill_super */
981 void lustre_put_super(struct super_block *sb)
983 struct obd_device *obd;
984 struct ll_sb_info *sbi = ll_s2sbi(sb);
985 int force_umount = 0;
988 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
989 obd = class_exp2obd(sbi->ll_md_exp);
991 force_umount = obd->obd_no_recov;
994 lustre_common_put_super(sb);
995 lustre_clean_profile(sbi, force_umount);
999 } /* lustre_put_super */
1001 int ll_process_config_update(struct ll_sb_info *sbi, int clean)
1003 struct lustre_mount_data *lmd = sbi->ll_lmd;
1004 char *profile = lmd->lmd_profile, *name = NULL;
1005 struct config_llog_instance cfg;
1006 int rc, namelen = 0, version;
1007 struct llog_ctxt *ctxt;
1010 if (profile == NULL)
1013 CERROR("Client not mounted with zero-conf; cannot "
1014 "process update log.\n");
1018 rc = obd_cancel_unused(sbi->ll_md_exp, NULL,
1019 LDLM_FL_CONFIG_CHANGE, NULL);
1021 CWARN("obd_cancel_unused(mdc): %d\n", rc);
1023 rc = obd_cancel_unused(sbi->ll_dt_exp, NULL,
1024 LDLM_FL_CONFIG_CHANGE, NULL);
1026 CWARN("obd_cancel_unused(lov): %d\n", rc);
1028 cfg.cfg_instance = sbi->ll_instance;
1029 cfg.cfg_uuid = sbi->ll_sb_uuid;
1030 cfg.cfg_local_nid = lmd->lmd_local_nid;
1032 namelen = strlen(profile) + 20; /* -clean-######### */
1033 OBD_ALLOC(name, namelen);
1038 version = sbi->ll_config_version - 1;
1039 sprintf(name, "%s-clean-%d", profile, version);
1041 version = sbi->ll_config_version + 1;
1042 sprintf(name, "%s-%d", profile, version);
1045 CWARN("Applying configuration log %s\n", name);
1047 ctxt = llog_get_context(&sbi->ll_md_exp->exp_obd->obd_llogs,
1048 LLOG_CONFIG_REPL_CTXT);
1049 rc = class_config_process_llog(ctxt, name, &cfg);
1051 sbi->ll_config_version = version;
1052 CWARN("Finished applying configuration log %s: %d\n", name, rc);
1054 if (rc == 0 && clean == 0) {
1055 struct lov_desc desc;
1059 valsize = sizeof(desc);
1060 rc = obd_get_info(sbi->ll_dt_exp, strlen("lovdesc") + 1,
1061 "lovdesc", &valsize, &desc);
1063 rc = obd_init_ea_size(sbi->ll_md_exp,
1064 obd_size_diskmd(sbi->ll_dt_exp, NULL),
1065 (desc.ld_tgt_count *
1066 sizeof(struct llog_cookie)));
1068 OBD_FREE(name, namelen);
1072 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
1074 struct inode *inode = NULL;
1076 /* NOTE: we depend on atomic igrab() -bzzz */
1077 lock_res_and_lock(lock);
1078 if (lock->l_ast_data) {
1079 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
1080 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1081 inode = igrab(lock->l_ast_data);
1084 do_gettimeofday(&now);
1085 inode = lock->l_ast_data;
1086 LDLM_ERROR(lock, "granted at %lu.%lu, now %lu.%lu",
1087 lock->l_enqueued_time.tv_sec,
1088 lock->l_enqueued_time.tv_usec,
1089 now.tv_sec, now.tv_usec);
1090 CDEBUG(inode->i_state & I_FREEING ? D_INFO : D_WARNING,
1091 "l_ast_data %p is bogus: magic %0x8\n",
1092 lock->l_ast_data, lli->lli_inode_magic);
1093 CDEBUG(D_ERROR, "i_state = 0x%lx, l_ast_data %p is bogus: magic %0x8\n",
1094 inode->i_state, lock->l_ast_data, lli->lli_inode_magic);
1096 unlock_res_and_lock(lock);
1100 unlock_res_and_lock(lock);
1104 int null_if_equal(struct ldlm_lock *lock, void *data)
1106 if (data == lock->l_ast_data) {
1107 lock->l_ast_data = NULL;
1109 if (lock->l_req_mode != lock->l_granted_mode)
1110 LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
1113 return LDLM_ITER_CONTINUE;
1116 static void remote_acl_free(struct remote_acl *racl);
1118 void ll_clear_inode(struct inode *inode)
1120 struct lustre_id id;
1121 struct ll_inode_info *lli = ll_i2info(inode);
1122 struct ll_sb_info *sbi = ll_i2sbi(inode);
1125 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1126 inode->i_generation, inode);
1128 ll_inode2id(&id, inode);
1130 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(ll_i2info(inode)->lli_flags));
1131 md_change_cbdata(sbi->ll_md_exp, &id, null_if_equal, inode);
1133 LASSERT(!lli->lli_open_fd_write_count);
1134 LASSERT(!lli->lli_open_fd_read_count);
1135 LASSERT(!lli->lli_open_fd_exec_count);
1136 if (lli->lli_mds_write_och)
1137 ll_md_real_close(sbi->ll_md_exp, inode, FMODE_WRITE);
1138 if (lli->lli_mds_exec_och)
1139 ll_md_real_close(sbi->ll_md_exp, inode, FMODE_EXEC);
1140 if (lli->lli_mds_read_och)
1141 ll_md_real_close(sbi->ll_md_exp, inode, FMODE_READ);
1143 obd_change_cbdata(sbi->ll_dt_exp, lli->lli_smd,
1144 null_if_equal, inode);
1147 obd_free_memmd(sbi->ll_dt_exp, &lli->lli_smd);
1148 lli->lli_smd = NULL;
1152 obd_free_memmd(sbi->ll_md_exp,
1153 (struct lov_stripe_md **) &lli->lli_mea);
1154 lli->lli_mea = NULL;
1156 ll_crypto_destroy_inode_key(inode);
1157 if (lli->lli_symlink_name) {
1158 OBD_FREE(lli->lli_symlink_name,
1159 strlen(lli->lli_symlink_name) + 1);
1160 lli->lli_symlink_name = NULL;
1163 if (lli->lli_posix_acl) {
1164 LASSERT(lli->lli_remote_acl == NULL);
1165 posix_acl_release(lli->lli_posix_acl);
1166 lli->lli_posix_acl = NULL;
1169 if (lli->lli_remote_acl) {
1170 LASSERT(lli->lli_posix_acl == NULL);
1171 remote_acl_free(lli->lli_remote_acl);
1172 lli->lli_remote_acl = NULL;
1175 lli->lli_inode_magic = LLI_INODE_DEAD;
1180 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1181 * object(s) determine the file size and mtime. Otherwise, the MDS will
1182 * keep these values until such a time that objects are allocated for it.
1183 * We do the MDS operations first, as it is checking permissions for us.
1184 * We don't to the MDS RPC if there is nothing that we want to store there,
1185 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1186 * going to do an RPC anyways.
1188 * If we are doing a truncate, we will send the mtime and ctime updates
1189 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1190 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1193 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1195 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1196 struct ll_inode_info *lli = ll_i2info(inode);
1197 struct ll_sb_info *sbi = ll_i2sbi(inode);
1198 struct ptlrpc_request *request = NULL;
1199 struct mdc_op_data *op_data;
1200 int ia_valid = attr->ia_valid;
1204 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
1205 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
1207 if (ia_valid & ATTR_SIZE) {
1208 if (attr->ia_size > ll_file_maxbytes(inode)) {
1209 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1210 attr->ia_size, ll_file_maxbytes(inode));
1214 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1217 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1218 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1219 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1223 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1224 if (attr->ia_valid & ATTR_CTIME) {
1225 attr->ia_ctime = CURRENT_TIME;
1226 attr->ia_valid |= ATTR_CTIME_SET;
1228 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1229 attr->ia_atime = CURRENT_TIME;
1230 attr->ia_valid |= ATTR_ATIME_SET;
1232 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1233 attr->ia_mtime = CURRENT_TIME;
1234 attr->ia_valid |= ATTR_MTIME_SET;
1237 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1238 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1239 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1240 LTIME_S(CURRENT_TIME));
1243 attr->ia_valid &= ~ATTR_SIZE;
1245 /* If only OST attributes being set on objects, don't do MDS RPC.
1246 * In that case, we need to check permissions and update the local
1247 * inode ourselves so we can call obdo_from_inode() always. */
1248 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN /*| ATTR_RAW*/) : ~0)) {
1249 struct lustre_md md;
1253 OBD_ALLOC(op_data, sizeof(*op_data));
1254 if (op_data == NULL)
1256 ll_prepare_mdc_data(op_data, inode, NULL, NULL, 0, 0);
1258 if (ia_valid & (ATTR_UID | ATTR_GID)) {
1259 rc = ll_crypto_get_mac(inode, attr, NULL, 0, &key,
1262 rc = md_setattr(sbi->ll_md_exp, op_data,
1263 attr, key, key_size, NULL, 0, NULL,
1265 OBD_FREE(op_data, sizeof(*op_data));
1267 if (key && key_size)
1268 OBD_FREE(key, key_size);
1270 ptlrpc_req_finished(request);
1271 if (rc != -EPERM && rc != -EACCES)
1272 CERROR("md_setattr fails: rc = %d\n", rc);
1275 rc = mdc_req2lustre_md(sbi->ll_md_exp, request, 0,
1276 sbi->ll_dt_exp, &md);
1278 ptlrpc_req_finished(request);
1282 /* We call inode_setattr to adjust timestamps, but we first
1283 * clear ATTR_SIZE to avoid invoking vmtruncate.
1285 * NB: ATTR_SIZE will only be set at this point if the size
1286 * resides on the MDS, ie, this file has no objects. */
1287 attr->ia_valid &= ~ATTR_SIZE;
1290 * assigning inode_setattr() to @err to disable warning that
1291 * function's result should be checked by by caller. error is
1292 * impossible here, as vmtruncate() control path is disabled.
1294 err = inode_setattr(inode, attr);
1295 ll_update_inode(inode, &md);
1296 ptlrpc_req_finished(request);
1298 if (!lsm || !S_ISREG(inode->i_mode)) {
1299 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1303 /* The OST doesn't check permissions, but the alternative is
1304 * a gratuitous RPC to the MDS. We already rely on the client
1305 * to do read/write/truncate permission checks, so is mtime OK?
1307 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
1308 /* from sys_utime() */
1309 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
1310 if (current->fsuid != inode->i_uid &&
1311 (rc = ll_permission(inode, MAY_WRITE, NULL)) != 0)
1314 /* from inode_change_ok() */
1315 if (current->fsuid != inode->i_uid &&
1316 !capable(CAP_FOWNER))
1321 /* won't invoke vmtruncate, as we already cleared ATTR_SIZE */
1322 err = inode_setattr(inode, attr);
1324 * assigning inode_setattr() to @err to disable warning that
1325 * function's result should be checked by by caller. error is
1326 * impossible here, as vmtruncate() control path is disabled.
1330 /* We really need to get our PW lock before we change inode->i_size.
1331 * If we don't we can race with other i_size updaters on our node, like
1332 * ll_file_read. We can also race with i_size propogation to other
1333 * nodes through dirtying and writeback of final cached pages. This
1334 * last one is especially bad for racing o_append users on other
1336 if (ia_valid & ATTR_SIZE) {
1337 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
1339 struct lustre_handle lockh = { 0 };
1340 int err, ast_flags = 0;
1341 /* XXX when we fix the AST intents to pass the discard-range
1342 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1344 if (attr->ia_size == 0)
1345 ast_flags = LDLM_AST_DISCARD_DATA;
1347 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy, &lockh,
1348 ast_flags, &ll_i2sbi(inode)->ll_seek_stime);
1353 down(&lli->lli_size_sem);
1354 lli->lli_size_pid = current->pid;
1355 rc = vmtruncate(inode, attr->ia_size);
1357 LASSERT(atomic_read(&lli->lli_size_sem.count) <= 0);
1358 lli->lli_size_pid = 0;
1359 up(&lli->lli_size_sem);
1362 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1364 CERROR("ll_extent_unlock failed: %d\n", err);
1368 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET | ATTR_UID | ATTR_GID)) {
1369 struct obdo *oa = NULL;
1371 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1372 inode->i_ino, LTIME_S(attr->ia_mtime));
1378 oa->o_id = lsm->lsm_object_id;
1379 oa->o_gr = lsm->lsm_object_gr;
1380 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1382 /* adding uid and gid, needed for quota */
1383 if (ia_valid & ATTR_UID) {
1384 oa->o_uid = inode->i_uid;
1385 oa->o_valid |= OBD_MD_FLUID;
1388 if (ia_valid & ATTR_GID) {
1389 oa->o_gid = inode->i_gid;
1390 oa->o_valid |= OBD_MD_FLGID;
1393 *(obdo_id(oa)) = lli->lli_id;
1394 oa->o_valid |= OBD_MD_FLIFID;
1396 obdo_from_inode(oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
1397 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
1398 rc = obd_setattr(sbi->ll_dt_exp, oa, lsm, NULL);
1401 CERROR("obd_setattr fails: rc = %d\n", rc);
1407 int ll_setattr(struct dentry *de, struct iattr *attr)
1409 LASSERT(de->d_inode);
1410 return ll_setattr_raw(de->d_inode, attr);
1413 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1414 unsigned long max_age)
1416 struct ll_sb_info *sbi = ll_s2sbi(sb);
1417 struct obd_statfs obd_osfs;
1421 rc = obd_statfs(class_exp2obd(sbi->ll_md_exp), osfs, max_age);
1423 CERROR("obd_statfs fails: rc = %d\n", rc);
1427 osfs->os_type = sb->s_magic;
1429 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1430 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1432 rc = obd_statfs(class_exp2obd(sbi->ll_dt_exp), &obd_osfs, max_age);
1434 CERROR("obd_statfs fails: rc = %d\n", rc);
1438 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1439 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1442 osfs->os_blocks = obd_osfs.os_blocks;
1443 osfs->os_bfree = obd_osfs.os_bfree;
1444 osfs->os_bavail = obd_osfs.os_bavail;
1446 /* If we don't have as many objects free on the OST as inodes
1447 * on the MDS, we reduce the total number of inodes to
1448 * compensate, so that the "inodes in use" number is correct.
1450 if (obd_osfs.os_ffree < osfs->os_ffree) {
1451 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1453 osfs->os_ffree = obd_osfs.os_ffree;
1459 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1461 struct obd_statfs osfs;
1464 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p\n", sb);
1465 lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
1467 /* For now we will always get up-to-date statfs values, but in the
1468 * future we may allow some amount of caching on the client (e.g.
1469 * from QOS or lprocfs updates). */
1470 rc = ll_statfs_internal(sb, &osfs, jiffies - 1);
1474 statfs_unpack(sfs, &osfs);
1476 if (sizeof(sfs->f_blocks) == 4) {
1477 while (osfs.os_blocks > ~0UL) {
1480 osfs.os_blocks >>= 1;
1481 osfs.os_bfree >>= 1;
1482 osfs.os_bavail >>= 1;
1486 sfs->f_blocks = osfs.os_blocks;
1487 sfs->f_bfree = osfs.os_bfree;
1488 sfs->f_bavail = osfs.os_bavail;
1494 /********************************
1496 ********************************/
1498 static struct remote_acl *remote_acl_alloc(void)
1500 struct remote_acl *racl;
1503 OBD_ALLOC(racl, sizeof(*racl));
1507 spin_lock_init(&racl->ra_lock);
1508 init_MUTEX(&racl->ra_update_sem);
1510 for (i = 0; i < REMOTE_ACL_HASHSIZE; i++)
1511 INIT_LIST_HEAD(&racl->ra_perm_cache[i]);
1517 * caller should guarantee no race here.
1519 static void remote_perm_flush_xperms(struct lustre_remote_perm *perm)
1521 struct remote_perm_setxid *xperm;
1523 while (!list_empty(&perm->lrp_setxid_perms)) {
1524 xperm = list_entry(perm->lrp_setxid_perms.next,
1525 struct remote_perm_setxid,
1527 list_del(&xperm->list);
1528 OBD_FREE(xperm, sizeof(*xperm));
1533 * caller should guarantee no race here.
1535 static void remote_acl_flush(struct remote_acl *racl)
1537 struct list_head *head;
1538 struct lustre_remote_perm *perm, *tmp;
1541 for (i = 0; i < REMOTE_ACL_HASHSIZE; i++) {
1542 head = &racl->ra_perm_cache[i];
1544 list_for_each_entry_safe(perm, tmp, head, lrp_list) {
1545 remote_perm_flush_xperms(perm);
1546 list_del(&perm->lrp_list);
1547 OBD_FREE(perm, sizeof(*perm));
1552 static void remote_acl_free(struct remote_acl *racl)
1557 down(&racl->ra_update_sem);
1558 spin_lock(&racl->ra_lock);
1559 remote_acl_flush(racl);
1560 spin_unlock(&racl->ra_lock);
1561 up(&racl->ra_update_sem);
1563 OBD_FREE(racl, sizeof(*racl));
1566 static inline int remote_acl_hashfunc(__u32 id)
1568 return (id & (REMOTE_ACL_HASHSIZE - 1));
1572 int __remote_acl_check(struct remote_acl *racl, unsigned int *perm)
1574 struct list_head *head;
1575 struct lustre_remote_perm *lperm;
1576 struct remote_perm_setxid *xperm;
1577 int found = 0, rc = -ENOENT;
1580 head = &racl->ra_perm_cache[remote_acl_hashfunc(current->uid)];
1581 spin_lock(&racl->ra_lock);
1583 list_for_each_entry(lperm, head, lrp_list) {
1584 if (lperm->lrp_auth_uid == current->uid) {
1593 if (lperm->lrp_auth_uid == current->fsuid &&
1594 lperm->lrp_auth_gid == current->fsgid) {
1595 if (lperm->lrp_valid) {
1596 *perm = lperm->lrp_perm;
1600 } else if ((!lperm->lrp_setuid &&
1601 lperm->lrp_auth_uid != current->fsuid) ||
1602 (!lperm->lrp_setgid &&
1603 lperm->lrp_auth_gid != current->fsgid)) {
1609 list_for_each_entry(xperm, &lperm->lrp_setxid_perms, list) {
1610 if (xperm->uid == current->fsuid &&
1611 xperm->gid == current->fsgid) {
1612 *perm = xperm->perm;
1619 spin_unlock(&racl->ra_lock);
1624 int __remote_acl_update(struct remote_acl *racl,
1625 struct mds_remote_perm *mperm,
1626 struct lustre_remote_perm *lperm,
1627 struct remote_perm_setxid *xperm)
1629 struct list_head *head;
1630 struct lustre_remote_perm *lp;
1631 struct remote_perm_setxid *xp;
1632 int found = 0, setuid = 0, setgid = 0;
1637 LASSERT(current->uid == mperm->mrp_auth_uid);
1639 if (current->fsuid != mperm->mrp_auth_uid)
1641 if (current->fsgid != mperm->mrp_auth_gid)
1644 head = &racl->ra_perm_cache[remote_acl_hashfunc(current->uid)];
1645 spin_lock(&racl->ra_lock);
1647 list_for_each_entry(lp, head, lrp_list) {
1648 if (lp->lrp_auth_uid == current->uid) {
1655 OBD_FREE(lperm, sizeof(*lperm));
1657 if (!lp->lrp_valid && !setuid && !setgid) {
1658 lp->lrp_perm = mperm->mrp_perm;
1662 /* sanity check for changes of setxid rules */
1663 if ((lp->lrp_setuid != 0) != (mperm->mrp_allow_setuid != 0)) {
1664 CWARN("setuid changes: %d => %d\n",
1665 (lp->lrp_setuid != 0),
1666 (mperm->mrp_allow_setuid != 0));
1667 lp->lrp_setuid = (mperm->mrp_allow_setuid != 0);
1670 if ((lp->lrp_setgid != 0) != (mperm->mrp_allow_setgid != 0)) {
1671 CWARN("setgid changes: %d => %d\n",
1672 (lp->lrp_setgid != 0),
1673 (mperm->mrp_allow_setgid != 0));
1674 lp->lrp_setgid = (mperm->mrp_allow_setgid != 0);
1677 if (!lp->lrp_setuid && !lp->lrp_setgid &&
1678 !list_empty(&lp->lrp_setxid_perms)) {
1679 remote_perm_flush_xperms(lp);
1682 /* initialize lperm and linked into hashtable
1684 INIT_LIST_HEAD(&lperm->lrp_setxid_perms);
1685 lperm->lrp_auth_uid = mperm->mrp_auth_uid;
1686 lperm->lrp_auth_gid = mperm->mrp_auth_gid;
1687 lperm->lrp_setuid = (mperm->mrp_allow_setuid != 0);
1688 lperm->lrp_setgid = (mperm->mrp_allow_setgid != 0);
1689 list_add(&lperm->lrp_list, head);
1691 if (!setuid && !setgid) {
1692 /* in this case, i'm the authenticated user,
1693 * and mrp_perm is for me.
1695 lperm->lrp_perm = mperm->mrp_perm;
1696 lperm->lrp_valid = 1;
1697 spin_unlock(&racl->ra_lock);
1700 OBD_FREE(xperm, sizeof(*xperm));
1708 LASSERT(lp->lrp_setuid || lp->lrp_setgid ||
1709 list_empty(&lp->lrp_setxid_perms));
1711 /* if no xperm supplied, we are all done here */
1713 spin_unlock(&racl->ra_lock);
1717 /* whether we allow setuid/setgid */
1718 if ((!lp->lrp_setuid && setuid) || (!lp->lrp_setgid && setgid)) {
1719 OBD_FREE(xperm, sizeof(*xperm));
1720 spin_unlock(&racl->ra_lock);
1724 /* traverse xperm list */
1725 list_for_each_entry(xp, &lp->lrp_setxid_perms, list) {
1726 if (xp->uid == current->fsuid &&
1727 xp->gid == current->fsgid) {
1728 if (xp->perm != mperm->mrp_perm) {
1729 /* actually this should not happen */
1730 CWARN("perm changed: %o => %o\n",
1731 xp->perm, mperm->mrp_perm);
1732 xp->perm = mperm->mrp_perm;
1734 OBD_FREE(xperm, sizeof(*xperm));
1735 spin_unlock(&racl->ra_lock);
1740 /* finally insert this xperm */
1741 xperm->uid = current->fsuid;
1742 xperm->gid = current->fsgid;
1743 xperm->perm = mperm->mrp_perm;
1744 list_add(&xperm->list, &lp->lrp_setxid_perms);
1746 spin_unlock(&racl->ra_lock);
1751 * remote_acl semaphore must be held by caller
1754 int remote_acl_update_locked(struct remote_acl *racl,
1755 struct mds_remote_perm *mperm)
1757 struct lustre_remote_perm *lperm;
1758 struct remote_perm_setxid *xperm;
1759 int setuid = 0, setgid = 0;
1763 if (current->uid != mperm->mrp_auth_uid) {
1764 CERROR("current uid %u while authenticated as %u\n",
1765 current->uid, mperm->mrp_auth_uid);
1769 if (current->fsuid != mperm->mrp_auth_uid)
1771 if (current->fsgid == mperm->mrp_auth_gid)
1774 OBD_ALLOC(lperm, sizeof(*lperm));
1778 if ((setuid || setgid) &&
1779 !(setuid && !mperm->mrp_allow_setuid) &&
1780 !(setgid && !mperm->mrp_allow_setgid)) {
1781 OBD_ALLOC(xperm, sizeof(*xperm));
1783 OBD_FREE(lperm, sizeof(*lperm));
1789 return __remote_acl_update(racl, mperm, lperm, xperm);
1793 * return -EACCES at any error cases
1795 int ll_remote_acl_permission(struct inode *inode, int mode)
1797 struct ll_sb_info *sbi = ll_i2sbi(inode);
1798 struct remote_acl *racl = ll_i2info(inode)->lli_remote_acl;
1799 struct ptlrpc_request *req = NULL;
1800 struct lustre_id id;
1801 struct mds_remote_perm *mperm;
1802 int rc = -EACCES, perm;
1807 if (__remote_acl_check(racl, &perm) == 0) {
1808 return ((perm & mode) == mode ? 0 : -EACCES);
1815 down(&racl->ra_update_sem);
1817 /* we might lose the race when obtain semaphore,
1820 if (__remote_acl_check(racl, &perm) == 0) {
1821 if ((perm & mode) == mode)
1826 /* really fetch from mds
1828 ll_inode2id(&id, inode);
1829 if (md_access_check(sbi->ll_md_exp, &id, &req))
1832 /* status non-zero indicate there's more apparent error
1833 * detected by mds, e.g. didn't allow this user at all.
1834 * we simply ignore and didn't cache it.
1836 if (req->rq_repmsg->status)
1839 mperm = lustre_swab_repbuf(req, 1, sizeof(*mperm),
1840 lustre_swab_remote_perm);
1842 LASSERT_REPSWABBED(req, 1);
1844 if ((mperm->mrp_perm & mode) == mode)
1847 remote_acl_update_locked(racl, mperm);
1850 ptlrpc_req_finished(req);
1852 up(&racl->ra_update_sem);
1856 int ll_remote_acl_update(struct inode *inode, struct mds_remote_perm *perm)
1858 struct remote_acl *racl = ll_i2info(inode)->lli_remote_acl;
1866 down(&racl->ra_update_sem);
1867 rc = remote_acl_update_locked(racl, perm);
1868 up(&racl->ra_update_sem);
1873 void ll_inode_invalidate_acl(struct inode *inode)
1875 struct ll_sb_info *sbi = ll_i2sbi(inode);
1876 struct ll_inode_info *lli = ll_i2info(inode);
1878 if (sbi->ll_remote) {
1879 struct remote_acl *racl = lli->lli_remote_acl;
1881 LASSERT(!lli->lli_posix_acl);
1883 down(&racl->ra_update_sem);
1884 spin_lock(&racl->ra_lock);
1885 remote_acl_flush(lli->lli_remote_acl);
1886 spin_unlock(&racl->ra_lock);
1887 up(&racl->ra_update_sem);
1890 LASSERT(!lli->lli_remote_acl);
1891 spin_lock(&lli->lli_lock);
1892 posix_acl_release(lli->lli_posix_acl);
1893 lli->lli_posix_acl = NULL;
1894 spin_unlock(&lli->lli_lock);
1898 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1900 struct ll_inode_info *lli = ll_i2info(inode);
1901 struct lov_stripe_md *lsm = md->lsm;
1902 struct mds_body *body = md->body;
1903 struct mea *mea = md->mea;
1904 struct posix_acl *posix_acl = md->posix_acl;
1905 struct ll_sb_info *sbi = ll_i2sbi(inode);
1906 struct lustre_key *mkey = md->key;
1909 LASSERT((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1911 if (md->lsm && md->lsm->lsm_magic != LOV_MAGIC) {
1912 /* check for default striping info for dir. */
1913 LASSERT((mea != NULL) == ((body->valid & OBD_MD_FLDIREA) != 0));
1917 LASSERT(lsm->lsm_object_gr > 0);
1918 if (lli->lli_smd == NULL) {
1920 lli->lli_maxbytes = lsm->lsm_maxbytes;
1921 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1922 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1925 if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
1926 CERROR("lsm mismatch for inode %ld\n",
1928 CERROR("lli_smd:\n");
1929 dump_lsm(D_ERROR, lli->lli_smd);
1931 dump_lsm(D_ERROR, lsm);
1934 /* XXX FIXME -- We should decide on a safer (atomic) and
1935 * more elegant way to update the lsm */
1936 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1937 lli->lli_smd->lsm_oinfo[i].loi_id =
1938 lsm->lsm_oinfo[i].loi_id;
1939 lli->lli_smd->lsm_oinfo[i].loi_gr =
1940 lsm->lsm_oinfo[i].loi_gr;
1941 lli->lli_smd->lsm_oinfo[i].loi_ost_idx =
1942 lsm->lsm_oinfo[i].loi_ost_idx;
1943 lli->lli_smd->lsm_oinfo[i].loi_ost_gen =
1944 lsm->lsm_oinfo[i].loi_ost_gen;
1947 /* bug 2844 - limit i_blksize for broken user-space apps */
1948 LASSERTF(lsm->lsm_xfersize != 0, "%lu\n", lsm->lsm_xfersize);
1949 inode->i_blksize = min(lsm->lsm_xfersize, LL_MAX_BLKSIZE);
1950 if (lli->lli_smd != lsm)
1951 obd_free_memmd(ll_i2dtexp(inode), &lsm);
1955 if (lli->lli_mea == NULL) {
1958 if (memcmp(lli->lli_mea, mea, body->eadatasize)) {
1959 CERROR("mea mismatch for inode %lu\n",
1964 if (lli->lli_mea != mea)
1965 obd_free_memmd(ll_i2mdexp(inode),
1966 (struct lov_stripe_md **) &mea);
1969 if (body->valid & OBD_MD_FID)
1970 id_assign_fid(&lli->lli_id, &body->id1);
1972 if (body->valid & OBD_MD_FLID)
1973 id_ino(&lli->lli_id) = id_ino(&body->id1);
1975 if (body->valid & OBD_MD_FLGENER)
1976 id_gen(&lli->lli_id) = id_gen(&body->id1);
1978 /* local/remote ACL */
1979 if (sbi->ll_remote) {
1980 LASSERT(md->posix_acl == NULL);
1981 if (md->remote_perm) {
1982 ll_remote_acl_update(inode, md->remote_perm);
1983 OBD_FREE(md->remote_perm, sizeof(*md->remote_perm));
1984 md->remote_perm = NULL;
1987 LASSERT(md->remote_perm == NULL);
1988 spin_lock(&lli->lli_lock);
1989 if (posix_acl != NULL) {
1990 if (lli->lli_posix_acl != NULL)
1991 posix_acl_release(lli->lli_posix_acl);
1992 lli->lli_posix_acl = posix_acl;
1994 spin_unlock(&lli->lli_lock);
1997 if (body->valid & OBD_MD_FLID)
1998 inode->i_ino = id_ino(&body->id1);
1999 if (body->valid & OBD_MD_FLGENER)
2000 inode->i_generation = id_gen(&body->id1);
2001 if (body->valid & OBD_MD_FLATIME)
2002 LTIME_S(inode->i_atime) = body->atime;
2003 if (body->valid & OBD_MD_FLMTIME &&
2004 body->mtime > LTIME_S(inode->i_mtime)) {
2005 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %u\n",
2006 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
2007 LTIME_S(inode->i_mtime) = body->mtime;
2009 if (body->valid & OBD_MD_FLCTIME &&
2010 body->ctime > LTIME_S(inode->i_ctime))
2011 LTIME_S(inode->i_ctime) = body->ctime;
2012 if (body->valid & OBD_MD_FLMODE) {
2013 inode->i_mode = (inode->i_mode & S_IFMT) |
2014 (body->mode & ~S_IFMT);
2016 if (body->valid & OBD_MD_FLTYPE) {
2017 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2018 (body->mode & S_IFMT);
2020 if (body->valid & OBD_MD_FLUID)
2021 inode->i_uid = body->uid;
2022 if (body->valid & OBD_MD_FLGID)
2023 inode->i_gid = body->gid;
2024 if (body->valid & OBD_MD_FLFLAGS)
2025 inode->i_flags = body->flags;
2026 if (body->valid & OBD_MD_FLNLINK)
2027 inode->i_nlink = body->nlink;
2028 if (body->valid & OBD_MD_FLRDEV)
2029 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2030 inode->i_rdev = body->rdev;
2032 inode->i_rdev = old_decode_dev(body->rdev);
2034 if (body->valid & OBD_MD_FLSIZE)
2035 inode->i_size = body->size;
2036 if (body->valid & OBD_MD_FLBLOCKS)
2037 inode->i_blocks = body->blocks;
2039 if (body->valid & OBD_MD_FLSIZE)
2040 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
2043 LASSERT(body->valid & OBD_MD_FLKEY);
2044 ll_crypto_init_inode_key(inode, mkey);
2047 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2048 inode->i_dev = (kdev_t)id_group(&lli->lli_id);
2050 LASSERT(id_fid(&lli->lli_id) != 0);
2053 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
2054 static struct backing_dev_info ll_backing_dev_info = {
2055 .ra_pages = 0, /* No readahead */
2056 .memory_backed = 0, /* Does contribute to dirty memory */
2060 void ll_read_inode2(struct inode *inode, void *opaque)
2062 struct lustre_md *md = opaque;
2063 struct ll_inode_info *lli = ll_i2info(inode);
2066 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
2067 inode->i_generation, inode);
2071 LASSERT(!lli->lli_smd);
2073 if (ll_i2sbi(inode)->ll_remote) {
2074 lli->lli_remote_acl = remote_acl_alloc();
2075 /* if failed alloc, nobody will be able to access this inode */
2078 /* Core attributes from the MDS first. This is a new inode, and
2079 * the VFS doesn't zero times in the core inode so we have to do
2080 * it ourselves. They will be overwritten by either MDS or OST
2081 * attributes - we just need to make sure they aren't newer. */
2082 LTIME_S(inode->i_mtime) = 0;
2083 LTIME_S(inode->i_atime) = 0;
2084 LTIME_S(inode->i_ctime) = 0;
2087 ll_update_inode(inode, md);
2089 /* OIDEBUG(inode); */
2091 if (S_ISREG(inode->i_mode)) {
2092 inode->i_op = &ll_file_inode_operations;
2093 inode->i_fop = &ll_file_operations;
2094 inode->i_mapping->a_ops = &ll_aops;
2096 } else if (S_ISDIR(inode->i_mode)) {
2097 inode->i_op = &ll_dir_inode_operations;
2098 inode->i_fop = &ll_dir_operations;
2099 inode->i_mapping->a_ops = &ll_dir_aops;
2101 } else if (S_ISLNK(inode->i_mode)) {
2102 inode->i_op = &ll_fast_symlink_inode_operations;
2105 inode->i_op = &ll_special_inode_operations;
2107 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2108 init_special_inode(inode, inode->i_mode,
2109 kdev_t_to_nr(inode->i_rdev));
2111 /* initializing backing dev info. */
2112 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
2114 init_special_inode(inode, inode->i_mode, inode->i_rdev);
2116 lli->ll_save_ifop = inode->i_fop;
2118 if (S_ISCHR(inode->i_mode))
2119 inode->i_fop = &ll_special_chr_inode_fops;
2120 else if (S_ISBLK(inode->i_mode))
2121 inode->i_fop = &ll_special_blk_inode_fops;
2122 else if (S_ISFIFO(inode->i_mode))
2123 inode->i_fop = &ll_special_fifo_inode_fops;
2124 else if (S_ISSOCK(inode->i_mode))
2125 inode->i_fop = &ll_special_sock_inode_fops;
2127 CWARN("saved %p, replaced with %p\n", lli->ll_save_ifop,
2130 if (lli->ll_save_ifop->owner) {
2131 CWARN("%p has owner %p\n", lli->ll_save_ifop,
2132 lli->ll_save_ifop->owner);
2138 void ll_delete_inode(struct inode *inode)
2140 struct ll_sb_info *sbi = ll_i2sbi(inode);
2141 struct lustre_id id;
2145 ll_inode2id(&id, inode);
2147 rc = md_delete_inode(sbi->ll_md_exp, &id);
2149 CERROR("md_delete_inode() failed, error %d\n",
2157 int ll_iocontrol(struct inode *inode, struct file *file,
2158 unsigned int cmd, unsigned long arg)
2160 struct ll_sb_info *sbi = ll_i2sbi(inode);
2161 struct ptlrpc_request *req = NULL;
2166 case EXT3_IOC_GETFLAGS: {
2167 struct lustre_id id;
2168 __u64 valid = OBD_MD_FLFLAGS;
2169 struct mds_body *body;
2171 ll_inode2id(&id, inode);
2172 rc = md_getattr(sbi->ll_md_exp, &id, valid, NULL, NULL, 0, 0,
2175 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
2179 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
2181 if (body->flags & S_APPEND)
2182 flags |= EXT3_APPEND_FL;
2183 if (body->flags & S_IMMUTABLE)
2184 flags |= EXT3_IMMUTABLE_FL;
2185 if (body->flags & S_NOATIME)
2186 flags |= EXT3_NOATIME_FL;
2188 ptlrpc_req_finished (req);
2190 RETURN(put_user(flags, (int *)arg));
2192 case EXT3_IOC_SETFLAGS: {
2193 struct mdc_op_data *op_data;
2196 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
2198 if (get_user(flags, (int *)arg))
2205 OBD_ALLOC(op_data, sizeof(*op_data));
2206 if (op_data == NULL) {
2210 ll_prepare_mdc_data(op_data, inode, NULL, NULL, 0, 0);
2212 memset(&attr, 0x0, sizeof(attr));
2213 attr.ia_attr_flags = flags;
2214 attr.ia_valid |= ATTR_ATTR_FLAG;
2216 rc = md_setattr(sbi->ll_md_exp, op_data,
2217 &attr, NULL, 0, NULL, 0, NULL, 0, &req);
2218 OBD_FREE(op_data, sizeof(*op_data));
2220 ptlrpc_req_finished(req);
2221 if (rc != -EPERM && rc != -EACCES)
2222 CERROR("md_setattr fails: rc = %d\n", rc);
2226 ptlrpc_req_finished(req);
2228 oa->o_id = lsm->lsm_object_id;
2229 oa->o_gr = lsm->lsm_object_gr;
2230 oa->o_flags = flags;
2231 *(obdo_id(oa)) = ll_i2info(inode)->lli_id;
2232 oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP
2235 rc = obd_setattr(sbi->ll_dt_exp, oa, lsm, NULL);
2238 if (rc != -EPERM && rc != -EACCES)
2239 CERROR("md_setattr fails: rc = %d\n", rc);
2243 if (flags & EXT3_APPEND_FL)
2244 inode->i_flags |= S_APPEND;
2246 inode->i_flags &= ~S_APPEND;
2247 if (flags & EXT3_IMMUTABLE_FL)
2248 inode->i_flags |= S_IMMUTABLE;
2250 inode->i_flags &= ~S_IMMUTABLE;
2251 if (flags & EXT3_NOATIME_FL)
2252 inode->i_flags |= S_NOATIME;
2254 inode->i_flags &= ~S_NOATIME;
2265 /* this is only called in the case of forced umount. */
2266 void ll_umount_begin(struct super_block *sb)
2268 struct ll_sb_info *sbi = ll_s2sbi(sb);
2269 struct obd_ioctl_data ioc_data = { 0 };
2270 struct obd_device *obd;
2273 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2274 sb->s_count, atomic_read(&sb->s_active));
2276 obd = class_exp2obd(sbi->ll_md_exp);
2278 CERROR("Invalid MDC connection handle "LPX64"\n",
2279 sbi->ll_md_exp->exp_handle.h_cookie);
2283 obd->obd_no_recov = 1;
2284 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2285 sizeof(ioc_data), &ioc_data, NULL);
2287 obd = class_exp2obd(sbi->ll_dt_exp);
2289 CERROR("Invalid LOV connection handle "LPX64"\n",
2290 sbi->ll_dt_exp->exp_handle.h_cookie);
2295 obd->obd_no_recov = 1;
2296 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2297 sizeof(ioc_data), &ioc_data, NULL);
2300 * really, we'd like to wait until there are no requests outstanding,
2301 * and then continue. For now, we just invalidate the requests,
2302 * schedule, and hope.
2309 int ll_prep_inode(struct obd_export *dt_exp, struct obd_export *md_exp,
2310 struct inode **inode, struct ptlrpc_request *req,
2311 int offset, struct super_block *sb)
2313 struct lustre_md md;
2316 rc = mdc_req2lustre_md(md_exp, req, offset, dt_exp, &md);
2321 ll_update_inode(*inode, &md);
2324 *inode = ll_iget(sb, id_ino(&md.body->id1), &md);
2325 if (*inode == NULL || is_bad_inode(*inode)) {
2326 /* free the lsm if we allocated one above */
2328 obd_free_memmd(dt_exp, &md.lsm);
2330 obd_free_memmd(md_exp,
2331 (struct lov_stripe_md**)&md.mea);
2333 CERROR("new_inode -fatal: rc %d\n", rc);
2340 int ll_show_options(struct seq_file *m, struct vfsmount *mnt)
2342 struct ll_sb_info *sbi = ll_s2sbi(mnt->mnt_sb);
2343 struct lustre_mount_data *lmd = sbi->ll_lmd;
2346 seq_printf(m, ",mds_sec=%s,oss_sec=%s",
2347 lmd->lmd_mds_security, lmd->lmd_oss_security);
2349 seq_printf(m, ",%s", sbi->ll_remote ? "remote" : "local");
2350 if (sbi->ll_remote && lmd)
2351 seq_printf(m, ",nllu=%u:%u", lmd->lmd_nllu, lmd->lmd_nllg);
2353 if (lmd && lmd->lmd_pag)
2354 seq_printf(m, ",pag");
2359 int ll_get_fid(struct obd_export *exp, struct lustre_id *idp,
2360 char *filename, struct lustre_id *ret)
2362 struct ptlrpc_request *request = NULL;
2363 struct mds_body *body;
2366 rc = md_getattr_lock(exp, idp, filename, strlen(filename) + 1,
2367 OBD_MD_FID, 0, &request);
2369 CDEBUG(D_INFO, "md_getattr_lock failed on %s: rc %d\n",
2374 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body));
2375 LASSERT(body != NULL);
2376 LASSERT_REPSWABBED(request, 0);
2379 ptlrpc_req_finished(request);
2383 int ll_flush_cred(struct inode *inode)
2385 struct ll_sb_info *sbi = ll_i2sbi(inode);
2388 /* XXX to avoid adding api, we simply use set_info() interface
2389 * to notify underlying obds. set_info() is more like a ioctl() now...
2391 if (sbi->ll_md_exp) {
2392 rc = obd_set_info(sbi->ll_md_exp,
2393 strlen("flush_cred"), "flush_cred",
2399 if (sbi->ll_dt_exp) {
2400 rc = obd_set_info(sbi->ll_dt_exp,
2401 strlen("flush_cred"), "flush_cred",