1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/lvfs/lvfs_mount.c
5 * Client/server mount routines
7 * Copyright (c) 2005 Cluster File Systems, Inc.
8 * Author: Nathan Rutman <nathan@clusterfs.com>
10 * This file is part of Lustre, http://www.lustre.org/
12 * Lustre is free software; you can redistribute it and/or
13 * modify it under the terms of version 2 of the GNU General Public
14 * License as published by the Free Software Foundation.
16 * Lustre is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Lustre; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #define DEBUG_SUBSYSTEM S_MGMT
28 #define D_MOUNT D_SUPER|D_CONFIG|D_WARNING
29 #define PRINT_CMD LCONSOLE
30 #define PRINT_MASK D_WARNING
32 #include <linux/obd.h>
33 #include <linux/lvfs.h>
34 #include <linux/lustre_fsfilt.h>
35 #include <linux/obd_class.h>
36 #include <lustre/lustre_user.h>
37 #include <linux/version.h>
38 #include <linux/lustre_log.h>
39 #include <linux/lustre_disk.h>
41 static int (*client_fill_super)(struct super_block *sb) = NULL;
44 /*********** mount lookup *********/
46 DECLARE_MUTEX(lustre_mount_info_lock);
47 struct list_head server_mount_info_list = LIST_HEAD_INIT(server_mount_info_list);
49 static struct lustre_mount_info *server_find_mount(char *name)
51 struct list_head *tmp;
52 struct lustre_mount_info *lmi;
54 list_for_each(tmp, &server_mount_info_list) {
55 lmi = list_entry(tmp, struct lustre_mount_info, lmi_list_chain);
56 if (strcmp(name, lmi->lmi_name) == 0)
62 /* we must register an obd for a mount before we call the setup routine.
63 *_setup will call lustre_get_mount to get the mnt struct
64 by obd_name, since we can't pass the pointer to setup. */
65 static int server_register_mount(char *name, struct super_block *sb,
68 struct lustre_mount_info *lmi;
75 OBD_ALLOC(lmi, sizeof(*lmi));
78 OBD_ALLOC(name_cp, strlen(name) + 1);
80 OBD_FREE(lmi, sizeof(*lmi));
83 strcpy(name_cp, name);
85 down(&lustre_mount_info_lock);
87 if (server_find_mount(name)) {
88 up(&lustre_mount_info_lock);
89 OBD_FREE(lmi, sizeof(*lmi));
90 OBD_FREE(name_cp, strlen(name) + 1);
91 CERROR("Already registered %s\n", name);
94 lmi->lmi_name = name_cp;
97 list_add(&lmi->lmi_list_chain, &server_mount_info_list);
99 up(&lustre_mount_info_lock);
101 CDEBUG(D_MOUNT, "reg_mnt %p from %s, vfscount=%d\n",
102 lmi->lmi_mnt, name, atomic_read(&lmi->lmi_mnt->mnt_count));
107 /* when an obd no longer needs a mount */
108 static int server_deregister_mount(char *name)
110 struct lustre_mount_info *lmi;
113 down(&lustre_mount_info_lock);
114 lmi = server_find_mount(name);
116 up(&lustre_mount_info_lock);
117 CERROR("%s not registered\n", name);
121 CDEBUG(D_MOUNT, "dereg_mnt %p from %s, vfscount=%d\n",
122 lmi->lmi_mnt, name, atomic_read(&lmi->lmi_mnt->mnt_count));
124 OBD_FREE(lmi->lmi_name, strlen(lmi->lmi_name) + 1);
125 list_del(&lmi->lmi_list_chain);
126 OBD_FREE(lmi, sizeof(*lmi));
127 up(&lustre_mount_info_lock);
132 /* Deregister anyone referencing the mnt. Everyone should have
133 put_mount in *_cleanup, but this is a catch-all in case of err... */
134 static void server_deregister_mount_all(struct vfsmount *mnt)
136 struct list_head *tmp, *n;
137 struct lustre_mount_info *lmi;
142 down(&lustre_mount_info_lock);
143 list_for_each_safe(tmp, n, &server_mount_info_list) {
144 lmi = list_entry(tmp, struct lustre_mount_info, lmi_list_chain);
145 if (lmi->lmi_mnt == mnt) {
146 CERROR("Deregister failsafe %s\n", lmi->lmi_name);
147 OBD_FREE(lmi->lmi_name, strlen(lmi->lmi_name) + 1);
148 list_del(&lmi->lmi_list_chain);
149 OBD_FREE(lmi, sizeof(*lmi));
152 up(&lustre_mount_info_lock);
155 /* obd's look up a registered mount using their name. This is just
156 for initial obd setup to find the mount struct. It should not be
157 called every time you want to mntget. */
158 struct lustre_mount_info *server_get_mount(char *name)
160 struct lustre_mount_info *lmi;
161 struct lustre_sb_info *lsi;
164 down(&lustre_mount_info_lock);
166 lmi = server_find_mount(name);
168 up(&lustre_mount_info_lock);
169 CERROR("Can't find mount for %s\n", name);
172 lsi = s2lsi(lmi->lmi_sb);
173 mntget(lmi->lmi_mnt);
174 atomic_inc(&lsi->lsi_mounts);
176 up(&lustre_mount_info_lock);
178 CDEBUG(D_MOUNT, "get_mnt %p from %s, refs=%d, vfscount=%d\n",
179 lmi->lmi_mnt, name, atomic_read(&lsi->lsi_mounts),
180 atomic_read(&lmi->lmi_mnt->mnt_count));
185 static void unlock_mntput(struct vfsmount *mnt)
187 if (kernel_locked()) {
196 static int lustre_put_lsi(struct super_block *sb);
198 /* to be called from obd_cleanup methods */
199 int server_put_mount(char *name, struct vfsmount *mnt)
201 struct lustre_mount_info *lmi;
202 struct lustre_sb_info *lsi;
205 down(&lustre_mount_info_lock);
206 lmi = server_find_mount(name);
208 up(&lustre_mount_info_lock);
209 CERROR("Can't find mount for %s\n", name);
212 lsi = s2lsi(lmi->lmi_sb);
213 LASSERT(lmi->lmi_mnt == mnt);
214 unlock_mntput(lmi->lmi_mnt);
216 CDEBUG(D_MOUNT, "put_mnt %p from %s, refs=%d, vfscount=%d\n",
217 lmi->lmi_mnt, name, atomic_read(&lsi->lsi_mounts),
218 atomic_read(&lmi->lmi_mnt->mnt_count));
220 if (lustre_put_lsi(lmi->lmi_sb)) {
221 CDEBUG(D_MOUNT, "Last put of mnt %p from %s, vfscount=%d\n",
223 atomic_read(&lmi->lmi_mnt->mnt_count));
224 /* last mount is the One True Mount */
225 if (atomic_read(&lmi->lmi_mnt->mnt_count) > 1)
226 CERROR("%s: mount busy, vfscount=%d!\n", name,
227 atomic_read(&lmi->lmi_mnt->mnt_count));
229 up(&lustre_mount_info_lock);
231 /* this obd should never need the mount again */
232 server_deregister_mount(name);
238 /******* mount helper utilities *********/
240 static void ldd_print(struct lustre_disk_data *ldd)
244 PRINT_CMD(PRINT_MASK, " disk data:\n");
245 PRINT_CMD(PRINT_MASK, "config: %d\n", ldd->ldd_config_ver);
246 PRINT_CMD(PRINT_MASK, "fs: %s\n", ldd->ldd_fsname);
247 PRINT_CMD(PRINT_MASK, "server: %s\n", ldd->ldd_svname);
248 PRINT_CMD(PRINT_MASK, "index: %04x\n", ldd->ldd_svindex);
249 PRINT_CMD(PRINT_MASK, "flags: %#x\n", ldd->ldd_flags);
250 PRINT_CMD(PRINT_MASK, "diskfs: %s\n", MT_STR(ldd));
251 PRINT_CMD(PRINT_MASK, "options: %s\n", ldd->ldd_mount_opts);
252 if (!ldd->ldd_mgsnid_count)
253 PRINT_CMD(PRINT_MASK, "no MGS nids\n");
254 else for (i = 0; i < ldd->ldd_mgsnid_count; i++) {
255 PRINT_CMD(PRINT_MASK, "mgs nid %d: %s\n", i,
256 libcfs_nid2str(ldd->ldd_mgsnid[i]));
258 if (!ldd->ldd_failnid_count)
259 PRINT_CMD(PRINT_MASK, "no failover nids\n");
260 else for (i = 0; i < ldd->ldd_failnid_count; i++) {
261 PRINT_CMD(PRINT_MASK, "failover nid %d: %s\n", i,
262 libcfs_nid2str(ldd->ldd_failnid[i]));
266 static int ldd_parse(struct lvfs_run_ctxt *mount_ctxt,
267 struct lustre_disk_data *ldd)
269 struct lvfs_run_ctxt saved;
276 push_ctxt(&saved, mount_ctxt, NULL);
278 file = filp_open(MOUNT_DATA_FILE, O_RDONLY, 0644);
281 CERROR("cannot open %s: rc = %d\n", MOUNT_DATA_FILE, rc);
285 len = file->f_dentry->d_inode->i_size;
286 CDEBUG(D_MOUNT, "Have %s, size %lu\n", MOUNT_DATA_FILE, len);
287 if (len != sizeof(*ldd)) {
288 CERROR("disk data size does not match: see %lu expect %u\n",
290 GOTO(out_close, rc = -EINVAL);
293 rc = lustre_fread(file, ldd, len, &off);
295 CERROR("error reading %s: read %d of %lu\n",
296 MOUNT_DATA_FILE, rc, len);
297 GOTO(out_close, rc = -EINVAL);
301 if (ldd->ldd_magic != LDD_MAGIC) {
302 /* FIXME add swabbing support */
303 CERROR("Bad magic in %s: %x!=%x\n", MOUNT_DATA_FILE,
304 ldd->ldd_magic, LDD_MAGIC);
305 GOTO(out_close, rc = -EINVAL);
308 if (ldd->ldd_feature_incompat & ~LDD_INCOMPAT_SUPP) {
309 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
311 ldd->ldd_feature_incompat & ~LDD_INCOMPAT_SUPP);
312 GOTO(out_close, rc = -EINVAL);
314 if (ldd->ldd_feature_rocompat & ~LDD_ROCOMPAT_SUPP) {
315 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
317 ldd->ldd_feature_rocompat & ~LDD_ROCOMPAT_SUPP);
318 /* Do something like remount filesystem read-only */
319 GOTO(out_close, rc = -EINVAL);
327 pop_ctxt(&saved, mount_ctxt, NULL);
331 static int ldd_write(struct lvfs_run_ctxt *mount_ctxt,
332 struct lustre_disk_data *ldd)
334 struct lvfs_run_ctxt saved;
337 unsigned long len = sizeof(struct lustre_disk_data);
341 LASSERT(ldd->ldd_magic == LDD_MAGIC);
343 ldd->ldd_config_ver++;
345 push_ctxt(&saved, mount_ctxt, NULL);
347 file = filp_open(MOUNT_DATA_FILE, O_RDWR, 0644);
350 CERROR("cannot open %s: rc = %d\n", MOUNT_DATA_FILE, rc);
354 rc = lustre_fwrite(file, ldd, len, &off);
356 CERROR("error writing %s: read %d of %lu\n",
357 MOUNT_DATA_FILE, rc, len);
358 GOTO(out_close, rc = -EINVAL);
367 pop_ctxt(&saved, mount_ctxt, NULL);
372 /**************** config llog ********************/
374 /* Get a config log from the MGS and process it.
375 This func is called for both clients and servers. */
376 int lustre_process_log(struct super_block *sb, char *logname,
377 struct config_llog_instance *cfg)
379 struct lustre_cfg *lcfg;
380 struct lustre_cfg_bufs bufs;
381 struct lustre_sb_info *lsi = s2lsi(sb);
382 struct obd_device *mgc = lsi->lsi_mgc;
389 /* mgc_process_config */
390 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
391 lustre_cfg_bufs_set_string(&bufs, 1, logname);
392 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
393 lustre_cfg_bufs_set(&bufs, 3, &sb, sizeof(sb));
394 lcfg = lustre_cfg_new(LCFG_LOG_START, &bufs);
395 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
396 lustre_cfg_free(lcfg);
399 LCONSOLE_ERROR("%s: The configuration '%s' could not be read "
400 "(%d), mount will fail.\n",
401 mgc->obd_name, logname, rc);
408 int lustre_end_log(struct super_block *sb, char *logname,
409 struct config_llog_instance *cfg)
411 struct lustre_cfg *lcfg;
412 struct lustre_cfg_bufs bufs;
413 struct lustre_sb_info *lsi = s2lsi(sb);
414 struct obd_device *mgc = lsi->lsi_mgc;
420 /* mgc_process_config */
421 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
422 lustre_cfg_bufs_set_string(&bufs, 1, logname);
424 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
425 lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
426 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
427 lustre_cfg_free(lcfg);
431 /**************** obd start *******************/
433 static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
434 char *s1, char *s2, char *s3, char *s4)
436 struct lustre_cfg_bufs bufs;
437 struct lustre_cfg * lcfg = NULL;
440 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
441 cmd, s1, s2, s3, s4);
443 lustre_cfg_bufs_reset(&bufs, cfgname);
445 lustre_cfg_bufs_set_string(&bufs, 1, s1);
447 lustre_cfg_bufs_set_string(&bufs, 2, s2);
449 lustre_cfg_bufs_set_string(&bufs, 3, s3);
451 lustre_cfg_bufs_set_string(&bufs, 4, s4);
453 lcfg = lustre_cfg_new(cmd, &bufs);
454 lcfg->lcfg_nid = nid;
455 rc = class_process_config(lcfg);
456 lustre_cfg_free(lcfg);
460 static int lustre_start_simple(char *obdname, char *type, char *uuid,
464 CDEBUG(D_MOUNT, "Starting obd %s (typ=%s)\n", obdname, type);
466 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, 0, 0);
468 CERROR("%s attach error %d\n", obdname, rc);
471 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, 0, 0);
473 CERROR("%s setup error %d\n", obdname, rc);
474 do_lcfg(obdname, 0, LCFG_DETACH, 0, 0, 0, 0);
479 /* Set up a MGS to serve startup logs */
480 static int server_start_mgs(struct super_block *sb)
482 struct lustre_sb_info *lsi = s2lsi(sb);
483 struct vfsmount *mnt = lsi->lsi_srv_mnt;
484 struct lustre_mount_info *lmi;
489 /* It is impossible to have more than 1 MGS per node, since
490 MGC wouldn't know which to connect to */
491 lmi = server_find_mount(LUSTRE_MGS_OBDNAME);
493 lsi = s2lsi(lmi->lmi_sb);
494 LCONSOLE_ERROR("The MGS service was already started from "
495 "server %s\n", lsi->lsi_ldd->ldd_svname);
499 CDEBUG(D_CONFIG, "Start MGS service %s\n", LUSTRE_MGS_OBDNAME);
501 rc = server_register_mount(LUSTRE_MGS_OBDNAME, sb, mnt);
504 ((rc = lustre_start_simple(LUSTRE_MGS_OBDNAME, LUSTRE_MGS_NAME,
505 LUSTRE_MGS_OBDNAME, 0, 0))))
506 server_deregister_mount(LUSTRE_MGS_OBDNAME);
509 LCONSOLE_ERROR("Failed to start MGS '%s' (%d). Is the 'mgs' "
510 "module loaded?\n", LUSTRE_MGS_OBDNAME, rc);
515 static int server_stop_mgs(struct super_block *sb)
517 struct obd_device *obd;
521 CDEBUG(D_MOUNT, "Stop MGS service %s\n", LUSTRE_MGS_OBDNAME);
523 /* There better be only one MGS */
524 obd = class_name2obd(LUSTRE_MGS_OBDNAME);
526 CDEBUG(D_CONFIG, "mgs %s not running\n", LUSTRE_MGS_OBDNAME);
530 /* The MGS should always stop when we say so */
532 rc = class_manual_cleanup(obd);
536 /* Set up a mgcobd to process startup logs */
537 static int lustre_start_mgc(struct super_block *sb)
539 struct lustre_handle mgc_conn = {0, };
540 struct obd_connect_data ocd = { 0 };
541 struct lustre_sb_info *lsi = s2lsi(sb);
542 struct obd_device *obd;
543 struct obd_export *exp;
546 lnet_process_id_t id;
551 LASSERT(lsi->lsi_lmd);
553 obd = class_name2obd(LUSTRE_MGC_OBDNAME);
555 atomic_inc(&obd->u.cli.cl_mgc_refcount);
556 /* FIXME There's only one MGC, but users could give different
557 MGS nids on the mount line. So now do we add new MGS uuids
558 or not? If there's truly one MGS per site, the MGS uuids
559 _should_ all be the same. Maybe check here?
562 /* Try all connections, but only once (again).
563 We don't want to block another target from starting
564 (using its local copy of the log), but we do want to connect
565 if at all possible. */
566 CDEBUG(D_MOUNT, "Set MGS reconnect\n");
568 rc = obd_set_info(obd->obd_self_export,
569 strlen(KEY_INIT_RECOV_BACKUP),
570 KEY_INIT_RECOV_BACKUP,
571 sizeof(recov_bk), &recov_bk);
575 if (lsi->lsi_lmd->lmd_mgsnid_count == 0) {
576 LCONSOLE_ERROR("No NIDs for the MGS were given.\n");
580 CDEBUG(D_MOUNT, "Start MGC '%s'\n", LUSTRE_MGC_OBDNAME);
582 /* Add the first uuid for the MGS */
583 nid = lsi->lsi_lmd->lmd_mgsnid[0];
584 rc = do_lcfg(LUSTRE_MGC_OBDNAME, nid, LCFG_ADD_UUID,
585 libcfs_nid2str(nid), 0,0,0);
589 /* Generate a unique uuid for each MGC - use the 1st non-loopback nid */
591 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
592 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
596 OBD_ALLOC(uuid, sizeof(struct obd_uuid));
597 sprintf(uuid, "mgc_"LPX64, id.nid);
599 rc = lustre_start_simple(LUSTRE_MGC_OBDNAME, LUSTRE_MGC_NAME,
600 uuid, LUSTRE_MGS_OBDNAME, libcfs_nid2str(nid));
601 OBD_FREE(uuid, sizeof(struct obd_uuid));
605 /* Add the redundant MGS nids */
606 for (i = 1; i < lsi->lsi_lmd->lmd_mgsnid_count; i++) {
607 nid = lsi->lsi_lmd->lmd_mgsnid[i];
608 rc = do_lcfg(LUSTRE_MGC_OBDNAME, nid, LCFG_ADD_UUID,
609 libcfs_nid2str(nid), 0, 0, 0);
611 CERROR("Add uuid for %s failed %d\n",
612 libcfs_nid2str(nid), rc);
615 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_ADD_CONN,
616 libcfs_nid2str(nid), 0, 0, 0);
618 CERROR("Add conn for %s failed %d\n",
619 libcfs_nid2str(nid), rc);
622 obd = class_name2obd(LUSTRE_MGC_OBDNAME);
624 CERROR("Can't find mgcobd %s\n", LUSTRE_MGC_OBDNAME);
628 /* Try all connections, but only once. */
630 rc = obd_set_info(obd->obd_self_export,
631 strlen(KEY_INIT_RECOV_BACKUP), KEY_INIT_RECOV_BACKUP,
632 sizeof(recov_bk), &recov_bk);
635 CERROR("can't set %s %d\n", KEY_INIT_RECOV_BACKUP, rc);
637 /* FIXME add ACL support? */
638 //ocd.ocd_connect_flags = OBD_CONNECT_ACL;
640 /* We connect to the MGS at setup, and don't disconnect until cleanup */
641 rc = obd_connect(&mgc_conn, obd, &(obd->obd_uuid), &ocd);
643 CERROR("connect failed %d\n", rc);
647 exp = class_conn2export(&mgc_conn);
648 obd->u.cli.cl_mgc_mgsexp = exp;
650 /* And keep a refcount of servers/clients who started with "mount",
651 so we know when we can get rid of the mgc. */
652 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
655 /* Keep the mgc info in the sb. Note that many lsi's can point
661 static int lustre_stop_mgc(struct super_block *sb)
663 struct lustre_sb_info *lsi = s2lsi(sb);
664 struct obd_device *obd;
676 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
677 /* This is not fatal, every client that stops
678 will call in here. */
679 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
680 atomic_read(&obd->u.cli.cl_mgc_refcount));
684 if (obd->u.cli.cl_mgc_mgsexp)
685 obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
687 rc = class_manual_cleanup(obd);
691 /* class_add_uuid adds a nid even if the same uuid exists; we might
692 delete any copy here. So they all better match. */
693 for (i = 0; i < lsi->lsi_lmd->lmd_mgsnid_count; i++) {
694 nid = lsi->lsi_lmd->lmd_mgsnid[i];
695 rc = do_lcfg(obd->obd_name, nid, LCFG_DEL_UUID,
696 libcfs_nid2str(nid), 0, 0, 0);
698 CERROR("del MDC UUID %s failed: rc = %d\n",
699 libcfs_nid2str(nid), rc);
701 /* class_import_put will get rid of the additional connections */
706 /* Since there's only one mgc per node, we have to change it's fs to get
707 access to the right disk. */
708 static int server_mgc_set_fs(struct obd_device *mgc, struct super_block *sb)
710 struct lustre_sb_info *lsi = s2lsi(sb);
714 CDEBUG(D_MOUNT, "Set mgc disk for %s\n", lsi->lsi_lmd->lmd_dev);
716 /* cl_mgc_sem in mgc insures we sleep if the mgc_fs is busy */
717 rc = obd_set_info(mgc->obd_self_export,
718 strlen("set_fs"), "set_fs",
721 CERROR("can't set_fs %d\n", rc);
727 static int server_mgc_clear_fs(struct obd_device *mgc)
732 CDEBUG(D_MOUNT, "Unassign mgc disk\n");
734 rc = obd_set_info(mgc->obd_self_export,
735 strlen("clear_fs"), "clear_fs", 0, NULL);
739 /* Stop MDS/OSS if nobody is using them */
740 static int server_stop_servers(struct super_block *sb)
742 struct lustre_sb_info *lsi = s2lsi(sb);
743 struct obd_device *obd;
747 /* if this was an MDT, and there are no more MDT's, clean up the MDS */
748 if (IS_MDT(lsi->lsi_ldd) && (obd = class_name2obd("MDS"))) {
749 //FIXME pre-rename, should eventually be LUSTRE_MDT_NAME
750 struct obd_type *type = class_search_type(LUSTRE_MDS_NAME);
751 if (!type || !type->typ_refcnt) {
752 /* nobody is using the MDT type, clean the MDS */
753 if (lsi->lsi_flags & LSI_UMOUNT_FORCE)
755 if (lsi->lsi_flags & LSI_UMOUNT_FAILOVER)
757 rc = class_manual_cleanup(obd);
761 /* if this was an OST, and there are no more OST's, clean up the OSS */
762 if (IS_OST(lsi->lsi_ldd) && (obd = class_name2obd("OSS"))) {
763 struct obd_type *type = class_search_type(LUSTRE_OST_NAME);
764 if (!type || !type->typ_refcnt) {
766 /* nobody is using the OST type, clean the OSS */
767 if (lsi->lsi_flags & LSI_UMOUNT_FORCE)
769 if (lsi->lsi_flags & LSI_UMOUNT_FAILOVER)
771 err = class_manual_cleanup(obd);
779 static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti)
781 struct lustre_sb_info *lsi = s2lsi(sb);
782 struct lustre_disk_data *ldd = lsi->lsi_ldd;
783 lnet_process_id_t id;
789 if (!(lsi->lsi_flags & LSI_SERVER))
792 strncpy(mti->mti_fsname, ldd->ldd_fsname,
793 sizeof(mti->mti_fsname));
794 strncpy(mti->mti_svname, ldd->ldd_svname,
795 sizeof(mti->mti_svname));
797 mti->mti_nid_count = 0;
798 while (LNetGetId(i++, &id) != -ENOENT) {
799 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
801 mti->mti_nids[mti->mti_nid_count] = id.nid;
802 mti->mti_nid_count++;
803 if (mti->mti_nid_count >= MTI_NIDS_MAX) {
804 CWARN("Only using first %d nids for %s\n",
805 mti->mti_nid_count, mti->mti_svname);
810 mti->mti_failnid_count = ldd->ldd_failnid_count;
811 memcpy(mti->mti_failnids, ldd->ldd_failnid, sizeof(mti->mti_failnids));
812 mti->mti_config_ver = 0;
813 mti->mti_flags = ldd->ldd_flags;
814 mti->mti_stripe_index = ldd->ldd_svindex;
815 mti->mti_stripe_count = ldd->ldd_stripe_count;
816 mti->mti_stripe_pattern = ldd->ldd_stripe_pattern;
817 mti->mti_stripe_size = ldd->ldd_stripe_sz;
818 mti->mti_stripe_offset = ldd->ldd_stripe_offset;
822 /* Register an old or new target with the MGS. If needed MGS will construct
823 startup logs and assign index */
824 int server_register_target(struct super_block *sb)
826 struct lustre_sb_info *lsi = s2lsi(sb);
827 struct obd_device *mgc = lsi->lsi_mgc;
828 struct lustre_disk_data *ldd = lsi->lsi_ldd;
829 struct mgs_target_info *mti = NULL;
835 if (!(lsi->lsi_flags & LSI_SERVER))
839 rc = server_sb2mti(sb, mti);
843 CDEBUG(D_MOUNT, "%sregistration %s, fs=%s, %s, index=%04x, flags=%#x\n",
844 mti->mti_flags & LDD_F_NEED_REGISTER ? "Initial " : "",
845 mti->mti_svname, mti->mti_fsname,
846 libcfs_nid2str(mti->mti_nids[0]), mti->mti_stripe_index,
849 /* Register the target */
850 /* FIXME use mdc_process_config instead */
851 rc = obd_set_info(mgc->u.cli.cl_mgc_mgsexp,
852 strlen("add_target"), "add_target",
855 CERROR("registration with the MGS failed (%d)\n", rc);
859 /* If this flag is set, it means the MGS wants us to change our
860 on-disk data. (So far this means just the index.) */
861 if (mti->mti_flags & LDD_F_REWRITE) {
862 CDEBUG(D_MOUNT, "Must change on-disk index from %#x to %#x for "
864 ldd->ldd_svindex, mti->mti_stripe_index,
866 ldd->ldd_svindex = mti->mti_stripe_index;
867 strncpy(ldd->ldd_svname, mti->mti_svname,
868 sizeof(ldd->ldd_svname));
869 /* or ldd_make_sv_name(ldd); */
870 ldd->ldd_flags = mti->mti_flags & ~LDD_F_REWRITE;
871 ldd_write(&mgc->obd_lvfs_ctxt, ldd);
873 /* FIXME write last_rcvd?, disk label? */
883 static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
885 struct obd_device *obd;
886 struct lustre_sb_info *lsi = s2lsi(sb);
887 struct config_llog_instance cfg;
891 CDEBUG(D_MOUNT, "starting target %s\n", lsi->lsi_ldd->ldd_svname);
893 /* If we're an MDT, make sure the global MDS is running */
894 if (lsi->lsi_ldd->ldd_flags & LDD_F_SV_TYPE_MDT) {
895 /* make sure (what will be called) the MDS is started */
896 obd = class_name2obd("MDS");
898 //FIXME pre-rename, should eventually be LUSTRE_MDS_NAME
899 rc = lustre_start_simple("MDS", LUSTRE_MDT_NAME,
902 CERROR("failed to start MDS: %d\n", rc);
903 GOTO(out_servers, rc);
908 /* If we're an OST, make sure the global OSS is running */
909 if (lsi->lsi_ldd->ldd_flags & LDD_F_SV_TYPE_OST) {
910 /* make sure OSS is started */
911 obd = class_name2obd("OSS");
913 rc = lustre_start_simple("OSS", LUSTRE_OSS_NAME,
916 CERROR("failed to start OSS: %d\n", rc);
917 GOTO(out_servers, rc);
922 /* Set the mgc fs to our server disk. This allows the MGC
923 to read and write configs locally. */
924 server_mgc_set_fs(lsi->lsi_mgc, sb);
926 /* Register with MGS */
927 rc = server_register_target(sb);
928 if (rc && (lsi->lsi_ldd->ldd_flags &
929 (LDD_F_NEED_INDEX | LDD_F_NEED_REGISTER | LDD_F_UPGRADE14))){
930 CERROR("Required refistration failed for %s: %d\n",
931 lsi->lsi_ldd->ldd_svname, rc);
935 if (class_name2obd(lsi->lsi_ldd->ldd_svname)) {
936 LCONSOLE_ERROR("The target named %s is already running\n",
937 lsi->lsi_ldd->ldd_svname);
938 GOTO(out, rc = -EBUSY);
941 /* Let the target look up the mount using the target's name
942 (we can't pass the sb or mnt through class_process_config.) */
943 rc = server_register_mount(lsi->lsi_ldd->ldd_svname, sb, mnt);
947 /* Start targets using the llog named for the target */
948 memset(&cfg, 0, sizeof(cfg));
949 rc = lustre_process_log(sb, lsi->lsi_ldd->ldd_svname, &cfg);
951 CERROR("failed to start server %s: %d\n",
952 lsi->lsi_ldd->ldd_svname, rc);
956 if (!class_name2obd(lsi->lsi_ldd->ldd_svname)) {
957 CERROR("no server named %s was started\n",
958 lsi->lsi_ldd->ldd_svname);
963 /* Release the mgc fs for others to use */
964 server_mgc_clear_fs(lsi->lsi_mgc);
970 /***************** mount **************/
972 struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
974 struct lustre_sb_info *lsi = NULL;
977 OBD_ALLOC(lsi, sizeof(*lsi));
980 OBD_ALLOC(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
982 OBD_FREE(lsi, sizeof(*lsi));
986 s2lsi_nocast(sb) = lsi;
987 /* we take 1 extra ref for our setup */
988 atomic_set(&lsi->lsi_mounts, 1);
992 static int lustre_free_lsi(struct super_block *sb)
994 struct lustre_sb_info *lsi = s2lsi(sb);
1000 CDEBUG(D_MOUNT, "Freeing lsi\n");
1002 /* someone didn't call server_put_mount. */
1003 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
1005 if (lsi->lsi_ldd != NULL)
1006 OBD_FREE(lsi->lsi_ldd, sizeof(*lsi->lsi_ldd));
1008 if (lsi->lsi_lmd != NULL) {
1009 if (lsi->lsi_lmd->lmd_dev != NULL)
1010 OBD_FREE(lsi->lsi_lmd->lmd_dev,
1011 strlen(lsi->lsi_lmd->lmd_dev) + 1);
1012 if (lsi->lsi_lmd->lmd_opts != NULL)
1013 OBD_FREE(lsi->lsi_lmd->lmd_opts,
1014 strlen(lsi->lsi_lmd->lmd_opts) + 1);
1015 OBD_FREE(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
1018 LASSERT(lsi->lsi_llsbi == NULL);
1020 server_deregister_mount_all(lsi->lsi_srv_mnt);
1022 OBD_FREE(lsi, sizeof(*lsi));
1023 s2lsi_nocast(sb) = NULL;
1028 static int lustre_put_lsi(struct super_block *sb)
1030 struct lustre_sb_info *lsi = s2lsi(sb);
1035 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
1037 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
1038 lustre_free_lsi(sb);
1044 /*************** server mount ******************/
1046 /* Kernel mount using mount options in MOUNT_DATA_FILE */
1047 static struct vfsmount *server_kernel_mount(struct super_block *sb)
1049 struct lvfs_run_ctxt mount_ctxt;
1050 struct lustre_sb_info *lsi = s2lsi(sb);
1051 struct lustre_disk_data *ldd;
1052 struct lustre_mount_data *lmd = lsi->lsi_lmd;
1053 struct vfsmount *mnt;
1054 char *options = NULL;
1055 unsigned long page, s_flags;
1059 OBD_ALLOC(ldd, sizeof(*ldd));
1061 RETURN(ERR_PTR(-ENOMEM));
1063 /* In the past, we have always used flags = 0.
1064 Note ext3/ldiskfs can't be mounted ro. */
1065 s_flags = sb->s_flags;
1067 /* Pre-mount ext3 to read the MOUNT_DATA_FILE */
1068 CDEBUG(D_MOUNT, "Pre-mount ext3 %s\n", lmd->lmd_dev);
1069 mnt = do_kern_mount("ext3", s_flags, lmd->lmd_dev, 0);
1072 CERROR("premount ext3 failed (%d), trying ldiskfs\n", rc);
1073 /* If ext3 fails (bec. of mballoc, extents), try ldiskfs */
1074 mnt = do_kern_mount("ldiskfs", s_flags, lmd->lmd_dev, 0);
1077 CERROR("premount ldiskfs failed: rc = %d\n", rc);
1082 OBD_SET_CTXT_MAGIC(&mount_ctxt);
1083 mount_ctxt.pwdmnt = mnt;
1084 mount_ctxt.pwd = mnt->mnt_root;
1085 mount_ctxt.fs = get_ds();
1087 rc = ldd_parse(&mount_ctxt, ldd);
1091 CERROR("premount parse options failed: rc = %d\n", rc);
1095 /* Done with our pre-mount, now do the real mount. */
1097 /* Glom up mount options */
1098 page = __get_free_page(GFP_KERNEL);
1100 GOTO(out_free, rc = -ENOMEM);
1102 options = (char *)page;
1103 memset(options, 0, PAGE_SIZE);
1104 strncpy(options, ldd->ldd_mount_opts, PAGE_SIZE - 2);
1106 /* Add in any mount-line options */
1107 if (lmd->lmd_opts && (*(lmd->lmd_opts) != 0)) {
1108 int len = PAGE_SIZE - strlen(options) - 2;
1110 strcat(options, ",");
1111 strncat(options, lmd->lmd_opts, len);
1114 /* Special permanent mount flags */
1116 s_flags |= MS_NOATIME | MS_NODIRATIME;
1118 CDEBUG(D_MOUNT, "kern_mount: %s %s %s\n",
1119 MT_STR(ldd), lmd->lmd_dev, options);
1120 mnt = do_kern_mount(MT_STR(ldd), s_flags, lmd->lmd_dev,
1125 CERROR("do_kern_mount failed: rc = %d\n", rc);
1129 lsi->lsi_ldd = ldd; /* freed at lsi cleanup */
1130 CDEBUG(D_SUPER, "%s: mnt = %p\n", lmd->lmd_dev, mnt);
1134 OBD_FREE(ldd, sizeof(*ldd));
1135 lsi->lsi_ldd = NULL;
1136 RETURN(ERR_PTR(rc));
1139 static void server_put_super(struct super_block *sb)
1141 struct lustre_sb_info *lsi = s2lsi(sb);
1142 struct obd_device *obd;
1143 struct vfsmount *mnt = lsi->lsi_srv_mnt;
1147 CDEBUG(D_MOUNT, "server put_super %s\n", lsi->lsi_ldd->ldd_svname);
1149 /* tell the mgc to drop the config log */
1150 lustre_end_log(sb, lsi->lsi_ldd->ldd_svname, NULL);
1152 obd = class_name2obd(lsi->lsi_ldd->ldd_svname);
1154 CDEBUG(D_MOUNT, "stopping %s\n", obd->obd_name);
1155 if (lsi->lsi_flags & LSI_UMOUNT_FORCE)
1157 if (lsi->lsi_flags & LSI_UMOUNT_FAILOVER)
1159 /* We can't seem to give an error return code
1160 to .put_super, so we better make sure we clean up!
1161 FIXME is there a way to get around this? */
1163 class_manual_cleanup(obd);
1165 CERROR("no obd %s\n", lsi->lsi_ldd->ldd_svname);
1166 server_deregister_mount(lsi->lsi_ldd->ldd_svname);
1169 server_stop_servers(sb);
1171 /* If they wanted the mgs to stop separately from the mdt, they
1172 should have put it on a different device. */
1173 if (IS_MGS(lsi->lsi_ldd)) {
1174 /* stop the mgc before the mgs so the connection gets cleaned
1176 lustre_stop_mgc(sb);
1177 server_stop_mgs(sb);
1180 /* clean the mgc and sb */
1181 rc = lustre_common_put_super(sb);
1182 // FIXME how do I return a failure?
1184 /* drop the One True Mount */
1187 CDEBUG(D_MOUNT, "umount done\n");
1191 static void server_umount_begin(struct super_block *sb)
1193 struct lustre_sb_info *lsi = s2lsi(sb);
1196 CDEBUG(D_MOUNT, "umount -f\n");
1198 umount -f = failover
1199 no third way to do LSI_UMOUNT_FORCE */
1200 lsi->lsi_flags |= LSI_UMOUNT_FAILOVER;
1204 static int server_statfs (struct super_block *sb, struct kstatfs *buf)
1206 struct vfsmount *mnt = s2lsi(sb)->lsi_srv_mnt;
1209 if (mnt && mnt->mnt_sb && mnt->mnt_sb->s_op->statfs) {
1210 int rc = mnt->mnt_sb->s_op->statfs(mnt->mnt_sb, buf);
1212 buf->f_type = sb->s_magic;
1218 buf->f_type = sb->s_magic;
1219 buf->f_bsize = sb->s_blocksize;
1225 buf->f_namelen = NAME_MAX;
1229 static struct super_operations server_ops =
1231 .put_super = server_put_super,
1232 .umount_begin = server_umount_begin, /* umount -f */
1233 .statfs = server_statfs,
1236 #define log2(n) ffz(~(n))
1237 #define LUSTRE_SUPER_MAGIC 0x0BD00BD1
1239 static int server_fill_super_common(struct super_block *sb)
1241 struct inode *root = 0;
1244 CDEBUG(D_MOUNT, "Server sb, dev=%d\n", (int)sb->s_dev);
1246 sb->s_blocksize = 4096;
1247 sb->s_blocksize_bits = log2(sb->s_blocksize);
1248 sb->s_magic = LUSTRE_SUPER_MAGIC;
1249 sb->s_maxbytes = 0; //PAGE_CACHE_MAXBYTES;
1250 sb->s_flags |= MS_RDONLY;
1251 sb->s_op = &server_ops;
1253 root = new_inode(sb);
1255 CERROR("Can't make root inode\n");
1259 /* returns -EIO for every operation */
1260 /* make_bad_inode(root); -- badness - can't umount */
1261 /* apparently we need to be a directory for the mount to finish */
1262 root->i_mode = S_IFDIR;
1264 sb->s_root = d_alloc_root(root);
1266 CERROR("Can't make root dentry\n");
1274 static int server_fill_super(struct super_block *sb)
1276 struct lustre_sb_info *lsi = s2lsi(sb);
1277 struct vfsmount *mnt;
1278 int mgs_service = 0, i = 0, rc;
1281 /* the One True Mount */
1282 mnt = server_kernel_mount(sb);
1285 CERROR("Unable to mount device %s: %d\n",
1286 lsi->lsi_lmd->lmd_dev, rc);
1289 lsi->lsi_srv_mnt = mnt;
1291 LASSERT(lsi->lsi_ldd);
1292 CDEBUG(D_MOUNT, "Found service %s for fs '%s' on device %s\n",
1293 lsi->lsi_ldd->ldd_svname, lsi->lsi_ldd->ldd_fsname,
1294 lsi->lsi_lmd->lmd_dev);
1296 /* append on-disk MGS nids to mount-line MGS nids */
1297 for (i = 0; (i < lsi->lsi_ldd->ldd_mgsnid_count) &&
1298 (lsi->lsi_lmd->lmd_mgsnid_count < MTI_NIDS_MAX); i++) {
1299 lsi->lsi_lmd->lmd_mgsnid[lsi->lsi_lmd->lmd_mgsnid_count++] =
1300 lsi->lsi_ldd->ldd_mgsnid[i];
1303 /* start MGS before MGC */
1304 if (IS_MGS(lsi->lsi_ldd)) {
1305 rc = server_start_mgs(sb);
1307 CERROR("ignoring Failed MGS start!!\n");
1308 //GOTO(out_mnt, rc);
1310 /* add local nids (including LO) to MGS nids */
1311 lnet_process_id_t id;
1312 int j = lsi->lsi_lmd->lmd_mgsnid_count;
1314 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
1315 if (j >= MTI_NIDS_MAX)
1317 lsi->lsi_lmd->lmd_mgsnid[j++] = id.nid;
1319 lsi->lsi_lmd->lmd_mgsnid_count = j;
1325 rc = lustre_start_mgc(sb);
1329 /* Set up all obd devices for service */
1330 if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC) &&
1331 (IS_OST(lsi->lsi_ldd) || IS_MDT(lsi->lsi_ldd))) {
1332 rc = server_start_targets(sb, mnt);
1334 CERROR("Unable to start targets: %d\n", rc);
1337 /* FIXME overmount client here,
1338 or can we just start a client log and client_fill_super on this sb?
1339 We need to make sure server_put_super gets called too - ll_put_super
1340 calls lustre_common_put_super; check there for LSI_SERVER flag,
1342 Probably should start client from new thread so we can return.
1343 Client will not finish until all servers are connected.
1344 Note - MGMT-only server does NOT get a client, since there is no
1345 lustre fs associated - the MGMT is for all lustre fs's */
1348 rc = server_fill_super_common(sb);
1355 server_put_super(sb);
1361 /*************** mount common betweeen server and client ***************/
1364 int lustre_common_put_super(struct super_block *sb)
1369 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
1371 rc = lustre_stop_mgc(sb);
1372 if (rc && (rc != -ENOENT)) {
1374 CERROR("Can't stop MGC: %d\n", rc);
1377 /* BUSY just means that there's some other obd that
1378 needs the mgc. Let him clean it up. */
1379 CDEBUG(D_MOUNT, "MGC busy, will stop later\n");
1385 static void lmd_print(struct lustre_mount_data *lmd)
1389 PRINT_CMD(PRINT_MASK, " mount data:\n");
1390 if (!lmd->lmd_mgsnid_count)
1391 PRINT_CMD(PRINT_MASK, "no MGS nids\n");
1392 else for (i = 0; i < lmd->lmd_mgsnid_count; i++) {
1393 PRINT_CMD(PRINT_MASK, "nid %d: %s\n", i,
1394 libcfs_nid2str(lmd->lmd_mgsnid[i]));
1396 if (lmd_is_client(lmd))
1397 PRINT_CMD(PRINT_MASK, "fsname: %s\n", lmd->lmd_dev);
1399 PRINT_CMD(PRINT_MASK, "device: %s\n", lmd->lmd_dev);
1400 PRINT_CMD(PRINT_MASK, "flags: %x\n", lmd->lmd_flags);
1402 PRINT_CMD(PRINT_MASK, "options: %s\n", lmd->lmd_opts);
1405 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
1407 char *s1, *s2, *devname = NULL;
1408 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
1413 LCONSOLE_ERROR("Missing mount data: check that "
1414 "/sbin/mount.lustre is installed.\n");
1418 /* Options should be a string - try to detect old lmd data */
1419 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1420 LCONSOLE_ERROR("You're using an old version of "
1421 "/sbin/mount.lustre. Please install version "
1422 "1.%d\n", LMD_MAGIC & 0xFF);
1425 lmd->lmd_magic = LMD_MAGIC;
1428 lmd->lmd_flags |= LMD_FLG_RECOVER;
1432 while (*s1 == ' ' || *s1 == ',')
1434 /* Client options are parsed in ll_options: eg. flock,
1437 if (strncmp(s1, "recov", 5) == 0)
1438 /* FIXME do something with the RECOVER flag - see lconf */
1439 lmd->lmd_flags |= LMD_FLG_RECOVER;
1440 else if (strncmp(s1, "norecov", 7) == 0)
1441 lmd->lmd_flags &= ~LMD_FLG_RECOVER;
1442 else if (strncmp(s1, "nosvc", 5) == 0)
1443 lmd->lmd_flags |= LMD_FLG_NOSVC;
1445 else if (strncmp(s1, "exclude=", 8) == 0) {
1446 CERROR("Exclude: %s\n", s1);
1447 /* FIXME implement */
1448 /* store exlusion list in lmd_exclude, mdt & client
1452 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1453 end of the options. */
1454 else if (strncmp(s1, "device=", 7) == 0) {
1456 /* terminate options right before device. device
1457 must be the last one. */
1460 s2 = strstr(s1, ",");
1467 LCONSOLE_ERROR("Can't find the device name "
1468 "(need mount option 'device=...')\n");
1472 if (strchr(devname, ',')) {
1473 LCONSOLE_ERROR("Device name must be the final option\n");
1478 /* Get MGS nids if client mount: uml1@tcp:uml2@tcp:/fsname-client */
1479 while ((s2 = strchr(s1, ':'))) {
1482 lmd->lmd_flags = LMD_FLG_CLIENT;
1483 nid = libcfs_str2nid(s1);
1484 if (nid == LNET_NID_ANY) {
1485 LCONSOLE_ERROR("Can't parse NID '%s'\n", s1);
1488 if (lmd->lmd_mgsnid_count >= MTI_NIDS_MAX) {
1489 LCONSOLE_ERROR("Too many NIDs: '%s'\n", s1);
1492 lmd->lmd_mgsnid[lmd->lmd_mgsnid_count++] = nid;
1496 if (lmd_is_client(lmd)) {
1497 /* Remove leading /s from fsname */
1498 while (*++s1 == '/')
1503 LCONSOLE_ERROR("No filesytem specified\n");
1507 /* freed in lustre_free_lsi */
1508 OBD_ALLOC(lmd->lmd_dev, strlen(s1) + 1);
1511 strcpy(lmd->lmd_dev, s1);
1513 /* save mount options */
1514 s1 = options + strlen(options) - 1;
1515 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1517 if (*options != 0) {
1518 /* freed in lustre_free_lsi */
1519 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
1522 strcpy(lmd->lmd_opts, options);
1525 lmd->lmd_magic = LMD_MAGIC;
1531 CERROR("Bad mount options %s\n", options);
1537 int lustre_fill_super(struct super_block *sb, void *data, int silent)
1539 struct lustre_mount_data *lmd;
1540 struct lustre_sb_info *lsi;
1544 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
1546 lsi = lustre_init_lsi(sb);
1551 /* Figure out the lmd from the mount options */
1552 if (lmd_parse((char *)data, lmd)) {
1557 if (lmd_is_client(lmd)) {
1558 CDEBUG(D_MOUNT, "Mounting client for fs %s\n", lmd->lmd_dev);
1559 if (!client_fill_super) {
1560 LCONSOLE_ERROR("Nothing registered for client mount!"
1561 " Is llite module loaded?\n");
1564 rc = lustre_start_mgc(sb);
1567 /* Connect and start */
1568 /* (should always be ll_fill_super) */
1569 rc = (*client_fill_super)(sb);
1571 lustre_common_put_super(sb);
1574 CDEBUG(D_MOUNT, "Mounting server from %s\n", lmd->lmd_dev);
1575 lsi->lsi_flags |= LSI_SERVER;
1576 rc = server_fill_super(sb);
1577 /* s_f_s calls lustre_start_mgc after the mount because we need
1578 the MGS nids which are stored on disk. Plus, we may
1579 need to start the MGS first. */
1580 /* s_f_s will call server_put_super on failure */
1585 CERROR("Unable to mount %s\n",
1586 s2lsi(sb) ? lmd->lmd_dev : "");
1588 CDEBUG(D_MOUNT, "Successfully mounted %s\n", lmd->lmd_dev);
1594 /* We can't call ll_fill_super by name because it lives in a module that
1595 must be loaded after this one. */
1596 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb))
1598 client_fill_super = cfs;
1601 /***************** FS registration ******************/
1603 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1605 struct super_block * lustre_get_sb(struct file_system_type *fs_type,
1606 int flags, const char *devname, void * data)
1608 /* calls back in fill super */
1609 /* we could append devname= onto options (*data) here,
1610 but 2.4 doesn't get devname. So we do it in mount_lustre.c */
1611 return get_sb_nodev(fs_type, flags, data, lustre_fill_super);
1614 struct file_system_type lustre_fs_type = {
1615 .owner = THIS_MODULE,
1617 .get_sb = lustre_get_sb,
1618 .kill_sb = kill_anon_super,
1619 .fs_flags = FS_BINARY_MOUNTDATA,
1624 static struct super_block *lustre_read_super(struct super_block *sb,
1625 void *data, int silent)
1630 rc = lustre_fill_super(sb, data, silent);
1636 static struct file_system_type lustre_fs_type = {
1637 .owner = THIS_MODULE,
1639 .fs_flags = FS_NFSEXP_FSID,
1640 .read_super = lustre_read_super,
1644 int lustre_register_fs(void)
1646 return register_filesystem(&lustre_fs_type);
1649 int lustre_unregister_fs(void)
1651 return unregister_filesystem(&lustre_fs_type);
1654 EXPORT_SYMBOL(lustre_register_client_fill_super);
1655 EXPORT_SYMBOL(lustre_common_put_super);
1656 EXPORT_SYMBOL(lustre_process_log);
1657 EXPORT_SYMBOL(lustre_end_log);
1658 EXPORT_SYMBOL(server_get_mount);
1659 EXPORT_SYMBOL(server_put_mount);
1660 EXPORT_SYMBOL(server_register_target);