1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/obdclass/obd_mount.c
5 * Client/server mount routines
7 * Copyright (c) 2006 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_CLASS
28 #define D_MOUNT D_SUPER|D_CONFIG /*|D_WARNING */
29 #define PRINT_CMD CDEBUG
30 #define PRINT_MASK D_SUPER|D_CONFIG
34 #include <lustre_fsfilt.h>
35 #include <obd_class.h>
36 #include <lustre/lustre_user.h>
37 #include <linux/version.h>
38 #include <lustre_log.h>
39 #include <lustre_disk.h>
40 #include <lustre_param.h>
42 static int (*client_fill_super)(struct super_block *sb) = NULL;
43 static void (*kill_super_cb)(struct super_block *sb) = NULL;
45 /*********** mount lookup *********/
47 DECLARE_MUTEX(lustre_mount_info_lock);
48 struct list_head server_mount_info_list = LIST_HEAD_INIT(server_mount_info_list);
50 static struct lustre_mount_info *server_find_mount(const char *name)
52 struct list_head *tmp;
53 struct lustre_mount_info *lmi;
56 list_for_each(tmp, &server_mount_info_list) {
57 lmi = list_entry(tmp, struct lustre_mount_info, lmi_list_chain);
58 if (strcmp(name, lmi->lmi_name) == 0)
64 /* we must register an obd for a mount before we call the setup routine.
65 *_setup will call lustre_get_mount to get the mnt struct
66 by obd_name, since we can't pass the pointer to setup. */
67 static int server_register_mount(const char *name, struct super_block *sb,
70 struct lustre_mount_info *lmi;
77 OBD_ALLOC(lmi, sizeof(*lmi));
80 OBD_ALLOC(name_cp, strlen(name) + 1);
82 OBD_FREE(lmi, sizeof(*lmi));
85 strcpy(name_cp, name);
87 down(&lustre_mount_info_lock);
89 if (server_find_mount(name)) {
90 up(&lustre_mount_info_lock);
91 OBD_FREE(lmi, sizeof(*lmi));
92 OBD_FREE(name_cp, strlen(name) + 1);
93 CERROR("Already registered %s\n", name);
96 lmi->lmi_name = name_cp;
99 list_add(&lmi->lmi_list_chain, &server_mount_info_list);
101 up(&lustre_mount_info_lock);
103 CDEBUG(D_MOUNT, "reg_mnt %p from %s, vfscount=%d\n",
104 lmi->lmi_mnt, name, atomic_read(&lmi->lmi_mnt->mnt_count));
109 /* when an obd no longer needs a mount */
110 static int server_deregister_mount(const char *name)
112 struct lustre_mount_info *lmi;
115 down(&lustre_mount_info_lock);
116 lmi = server_find_mount(name);
118 up(&lustre_mount_info_lock);
119 CERROR("%s not registered\n", name);
123 CDEBUG(D_MOUNT, "dereg_mnt %p from %s, vfscount=%d\n",
124 lmi->lmi_mnt, name, atomic_read(&lmi->lmi_mnt->mnt_count));
126 OBD_FREE(lmi->lmi_name, strlen(lmi->lmi_name) + 1);
127 list_del(&lmi->lmi_list_chain);
128 OBD_FREE(lmi, sizeof(*lmi));
129 up(&lustre_mount_info_lock);
134 /* obd's look up a registered mount using their obdname. This is just
135 for initial obd setup to find the mount struct. It should not be
136 called every time you want to mntget. */
137 struct lustre_mount_info *server_get_mount(const char *name)
139 struct lustre_mount_info *lmi;
140 struct lustre_sb_info *lsi;
143 down(&lustre_mount_info_lock);
144 lmi = server_find_mount(name);
145 up(&lustre_mount_info_lock);
147 CERROR("Can't find mount for %s\n", name);
150 lsi = s2lsi(lmi->lmi_sb);
151 mntget(lmi->lmi_mnt);
152 atomic_inc(&lsi->lsi_mounts);
154 CDEBUG(D_MOUNT, "get_mnt %p from %s, refs=%d, vfscount=%d\n",
155 lmi->lmi_mnt, name, atomic_read(&lsi->lsi_mounts),
156 atomic_read(&lmi->lmi_mnt->mnt_count));
162 * Used by mdt to get mount_info from obdname.
163 * There are no blocking when using the mount_info.
164 * Do not use server_get_mount for this purpose.
166 struct lustre_mount_info *server_get_mount_2(const char *name)
168 struct lustre_mount_info *lmi;
171 down(&lustre_mount_info_lock);
172 lmi = server_find_mount(name);
173 up(&lustre_mount_info_lock);
175 CERROR("Can't find mount for %s\n", name);
180 static void unlock_mntput(struct vfsmount *mnt)
182 if (kernel_locked()) {
191 static int lustre_put_lsi(struct super_block *sb);
193 /* to be called from obd_cleanup methods */
194 int server_put_mount(const char *name, struct vfsmount *mnt)
196 struct lustre_mount_info *lmi;
197 struct lustre_sb_info *lsi;
198 int count = atomic_read(&mnt->mnt_count) - 1;
201 /* This might be the last one, can't deref after this */
204 down(&lustre_mount_info_lock);
205 lmi = server_find_mount(name);
206 up(&lustre_mount_info_lock);
208 CERROR("Can't find mount for %s\n", name);
211 lsi = s2lsi(lmi->lmi_sb);
212 LASSERT(lmi->lmi_mnt == mnt);
214 CDEBUG(D_MOUNT, "put_mnt %p from %s, refs=%d, vfscount=%d\n",
215 lmi->lmi_mnt, name, atomic_read(&lsi->lsi_mounts), count);
217 if (lustre_put_lsi(lmi->lmi_sb)) {
218 CDEBUG(D_MOUNT, "Last put of mnt %p from %s, vfscount=%d\n",
219 lmi->lmi_mnt, name, count);
220 /* last mount is the One True Mount */
222 CERROR("%s: mount busy, vfscount=%d!\n", name, count);
225 /* this obd should never need the mount again */
226 server_deregister_mount(name);
231 /* Corresponding to server_get_mount_2 */
232 int server_put_mount_2(const char *name, struct vfsmount *mnt)
238 /******* mount helper utilities *********/
241 static void ldd_print(struct lustre_disk_data *ldd)
243 PRINT_CMD(PRINT_MASK, " disk data:\n");
244 PRINT_CMD(PRINT_MASK, "server: %s\n", ldd->ldd_svname);
245 PRINT_CMD(PRINT_MASK, "uuid: %s\n", (char *)ldd->ldd_uuid);
246 PRINT_CMD(PRINT_MASK, "fs: %s\n", ldd->ldd_fsname);
247 PRINT_CMD(PRINT_MASK, "index: %04x\n", ldd->ldd_svindex);
248 PRINT_CMD(PRINT_MASK, "config: %d\n", ldd->ldd_config_ver);
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 PRINT_CMD(PRINT_MASK, "params: %s\n", ldd->ldd_params);
253 PRINT_CMD(PRINT_MASK, "comment: %s\n", ldd->ldd_userdata);
257 static int ldd_parse(struct lvfs_run_ctxt *mount_ctxt,
258 struct lustre_disk_data *ldd)
260 struct lvfs_run_ctxt saved;
267 push_ctxt(&saved, mount_ctxt, NULL);
269 file = filp_open(MOUNT_DATA_FILE, O_RDONLY, 0644);
272 CERROR("cannot open %s: rc = %d\n", MOUNT_DATA_FILE, rc);
276 len = i_size_read(file->f_dentry->d_inode);
277 CDEBUG(D_MOUNT, "Have %s, size %lu\n", MOUNT_DATA_FILE, len);
278 if (len != sizeof(*ldd)) {
279 CERROR("disk data size does not match: see %lu expect "LPSZ"\n",
281 GOTO(out_close, rc = -EINVAL);
284 rc = lustre_fread(file, ldd, len, &off);
286 CERROR("error reading %s: read %d of %lu\n",
287 MOUNT_DATA_FILE, rc, len);
288 GOTO(out_close, rc = -EINVAL);
292 if (ldd->ldd_magic != LDD_MAGIC) {
293 /* FIXME add swabbing support */
294 CERROR("Bad magic in %s: %x!=%x\n", MOUNT_DATA_FILE,
295 ldd->ldd_magic, LDD_MAGIC);
296 GOTO(out_close, rc = -EINVAL);
299 if (ldd->ldd_feature_incompat & ~LDD_INCOMPAT_SUPP) {
300 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
302 ldd->ldd_feature_incompat & ~LDD_INCOMPAT_SUPP);
303 GOTO(out_close, rc = -EINVAL);
305 if (ldd->ldd_feature_rocompat & ~LDD_ROCOMPAT_SUPP) {
306 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
308 ldd->ldd_feature_rocompat & ~LDD_ROCOMPAT_SUPP);
309 /* Do something like remount filesystem read-only */
310 GOTO(out_close, rc = -EINVAL);
316 pop_ctxt(&saved, mount_ctxt, NULL);
320 static int ldd_write(struct lvfs_run_ctxt *mount_ctxt,
321 struct lustre_disk_data *ldd)
323 struct lvfs_run_ctxt saved;
326 unsigned long len = sizeof(struct lustre_disk_data);
330 LASSERT(ldd->ldd_magic == LDD_MAGIC);
332 ldd->ldd_config_ver++;
334 push_ctxt(&saved, mount_ctxt, NULL);
336 file = filp_open(MOUNT_DATA_FILE, O_RDWR, 0644);
339 CERROR("cannot open %s: rc = %d\n", MOUNT_DATA_FILE, rc);
343 rc = lustre_fwrite(file, ldd, len, &off);
345 CERROR("error writing %s: read %d of %lu\n",
346 MOUNT_DATA_FILE, rc, len);
347 GOTO(out_close, rc = -EINVAL);
355 pop_ctxt(&saved, mount_ctxt, NULL);
360 /**************** config llog ********************/
362 /* Get a config log from the MGS and process it.
363 This func is called for both clients and servers.
364 Continue to process new statements appended to the logs
365 (whenever the config lock is revoked) until lustre_end_log
367 int lustre_process_log(struct super_block *sb, char *logname,
368 struct config_llog_instance *cfg)
370 struct lustre_cfg *lcfg;
371 struct lustre_cfg_bufs bufs;
372 struct lustre_sb_info *lsi = s2lsi(sb);
373 struct obd_device *mgc = lsi->lsi_mgc;
380 /* mgc_process_config */
381 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
382 lustre_cfg_bufs_set_string(&bufs, 1, logname);
383 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
384 lustre_cfg_bufs_set(&bufs, 3, &sb, sizeof(sb));
385 lcfg = lustre_cfg_new(LCFG_LOG_START, &bufs);
386 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
387 lustre_cfg_free(lcfg);
390 LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s'"
391 "failed from the MGS (%d). Make sure this "
392 "client and the MGS are running compatible "
393 "versions of Lustre.\n",
394 mgc->obd_name, logname, rc);
397 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' "
398 "failed (%d). This may be the result of "
399 "communication errors between this node and "
400 "the MGS, a bad configuration, or other "
401 "errors. See the syslog for more "
402 "information.\n", mgc->obd_name, logname,
405 /* class_obd_list(); */
409 /* Stop watching this config log for updates */
410 int lustre_end_log(struct super_block *sb, char *logname,
411 struct config_llog_instance *cfg)
413 struct lustre_cfg *lcfg;
414 struct lustre_cfg_bufs bufs;
415 struct lustre_sb_info *lsi = s2lsi(sb);
416 struct obd_device *mgc = lsi->lsi_mgc;
423 /* mgc_process_config */
424 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
425 lustre_cfg_bufs_set_string(&bufs, 1, logname);
427 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
428 lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
429 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
430 lustre_cfg_free(lcfg);
434 /**************** obd start *******************/
436 int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
437 char *s1, char *s2, char *s3, char *s4)
439 struct lustre_cfg_bufs bufs;
440 struct lustre_cfg * lcfg = NULL;
443 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
444 cmd, s1, s2, s3, s4);
446 lustre_cfg_bufs_reset(&bufs, cfgname);
448 lustre_cfg_bufs_set_string(&bufs, 1, s1);
450 lustre_cfg_bufs_set_string(&bufs, 2, s2);
452 lustre_cfg_bufs_set_string(&bufs, 3, s3);
454 lustre_cfg_bufs_set_string(&bufs, 4, s4);
456 lcfg = lustre_cfg_new(cmd, &bufs);
457 lcfg->lcfg_nid = nid;
458 rc = class_process_config(lcfg);
459 lustre_cfg_free(lcfg);
463 static int lustre_start_simple(char *obdname, char *type, char *uuid,
467 CDEBUG(D_MOUNT, "Starting obd %s (typ=%s)\n", obdname, type);
469 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, 0, 0);
471 CERROR("%s attach error %d\n", obdname, rc);
474 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, 0, 0);
476 CERROR("%s setup error %d\n", obdname, rc);
477 do_lcfg(obdname, 0, LCFG_DETACH, 0, 0, 0, 0);
482 /* Set up a MGS to serve startup logs */
483 static int server_start_mgs(struct super_block *sb)
485 struct lustre_sb_info *lsi = s2lsi(sb);
486 struct vfsmount *mnt = lsi->lsi_srv_mnt;
487 struct lustre_mount_info *lmi;
492 /* It is impossible to have more than 1 MGS per node, since
493 MGC wouldn't know which to connect to */
494 lmi = server_find_mount(LUSTRE_MGS_OBDNAME);
496 lsi = s2lsi(lmi->lmi_sb);
497 LCONSOLE_ERROR_MSG(0x15d, "The MGS service was already started"
499 lsi->lsi_ldd->ldd_svname);
503 CDEBUG(D_CONFIG, "Start MGS service %s\n", LUSTRE_MGS_OBDNAME);
505 rc = server_register_mount(LUSTRE_MGS_OBDNAME, sb, mnt);
508 ((rc = lustre_start_simple(LUSTRE_MGS_OBDNAME, LUSTRE_MGS_NAME,
509 LUSTRE_MGS_OBDNAME, 0, 0))))
510 server_deregister_mount(LUSTRE_MGS_OBDNAME);
513 LCONSOLE_ERROR_MSG(0x15e, "Failed to start MGS '%s' (%d). "
514 "Is the 'mgs' module loaded?\n",
515 LUSTRE_MGS_OBDNAME, rc);
519 static int server_stop_mgs(struct super_block *sb)
521 struct obd_device *obd;
525 CDEBUG(D_MOUNT, "Stop MGS service %s\n", LUSTRE_MGS_OBDNAME);
527 /* There better be only one MGS */
528 obd = class_name2obd(LUSTRE_MGS_OBDNAME);
530 CDEBUG(D_CONFIG, "mgs %s not running\n", LUSTRE_MGS_OBDNAME);
534 /* The MGS should always stop when we say so */
536 rc = class_manual_cleanup(obd);
540 DECLARE_MUTEX(mgc_start_lock);
542 /* Set up a mgcobd to process startup logs */
543 static int lustre_start_mgc(struct super_block *sb)
545 struct lustre_handle mgc_conn = {0, };
546 struct obd_connect_data ocd = { 0 };
547 struct lustre_sb_info *lsi = s2lsi(sb);
548 struct obd_device *obd;
549 struct obd_export *exp;
550 struct obd_uuid *uuid;
553 char *mgcname, *niduuid;
556 int rc = 0, i = 0, j, len;
559 LASSERT(lsi->lsi_lmd);
561 /* Find the first non-lo MGS nid for our MGC name */
562 if (lsi->lsi_flags & LSI_SERVER) {
563 ptr = lsi->lsi_ldd->ldd_params;
564 /* Use mgsnode= nids */
565 if ((class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0) &&
566 (class_parse_nid(ptr, &nid, &ptr) == 0)) {
568 } else if (IS_MGS(lsi->lsi_ldd)) {
569 lnet_process_id_t id;
570 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
571 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
578 } else { /* client */
579 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
580 ptr = lsi->lsi_lmd->lmd_dev;
581 if (class_parse_nid(ptr, &nid, &ptr) == 0)
585 CERROR("No valid MGS nids found.\n");
589 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
590 OBD_ALLOC(mgcname, len);
591 OBD_ALLOC(niduuid, len + 2);
592 if (!mgcname || !niduuid)
593 GOTO(out_free, rc = -ENOMEM);
594 sprintf(mgcname, "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
596 mutex_down(&mgc_start_lock);
598 obd = class_name2obd(mgcname);
600 /* Re-using an existing MGC */
601 atomic_inc(&obd->u.cli.cl_mgc_refcount);
604 /* If we are restarting the MGS, don't try to keep the MGC's
605 old connection, or registration will fail. */
606 if ((lsi->lsi_flags & LSI_SERVER) && IS_MGS(lsi->lsi_ldd)) {
607 CDEBUG(D_MOUNT, "New MGS with live MGC\n");
611 /* Try all connections, but only once (again).
612 We don't want to block another target from starting
613 (using its local copy of the log), but we do want to connect
614 if at all possible. */
616 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,recov_bk);
617 rc = obd_set_info_async(obd->obd_self_export,
618 strlen(KEY_INIT_RECOV_BACKUP),
619 KEY_INIT_RECOV_BACKUP,
620 sizeof(recov_bk), &recov_bk, NULL);
624 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
626 /* Add the primary nids for the MGS */
628 sprintf(niduuid, "%s_%x", mgcname, i);
629 if (lsi->lsi_flags & LSI_SERVER) {
630 ptr = lsi->lsi_ldd->ldd_params;
631 if (IS_MGS(lsi->lsi_ldd)) {
632 /* Use local nids (including LO) */
633 lnet_process_id_t id;
634 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
635 rc = do_lcfg(mgcname, id.nid,
636 LCFG_ADD_UUID, niduuid, 0,0,0);
639 /* Use mgsnode= nids */
640 if (class_find_param(ptr, PARAM_MGSNODE, &ptr) != 0) {
641 CERROR("No MGS nids given.\n");
642 GOTO(out_free, rc = -EINVAL);
644 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
645 rc = do_lcfg(mgcname, nid,
646 LCFG_ADD_UUID, niduuid, 0,0,0);
650 } else { /* client */
651 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
652 ptr = lsi->lsi_lmd->lmd_dev;
653 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
654 rc = do_lcfg(mgcname, nid,
655 LCFG_ADD_UUID, niduuid, 0,0,0);
657 /* Stop at the first failover nid */
663 CERROR("No valid MGS nids found.\n");
664 GOTO(out_free, rc = -EINVAL);
666 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
668 /* Random uuid for MGC allows easier reconnects */
670 ll_generate_random_uuid(uuidc);
671 class_uuid_unparse(uuidc, uuid);
674 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
675 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
681 /* Add any failover MGS nids */
683 while ((*ptr == ':' ||
684 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0)) {
685 /* New failover node */
686 sprintf(niduuid, "%s_%x", mgcname, i);
688 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
690 rc = do_lcfg(mgcname, nid,
691 LCFG_ADD_UUID, niduuid, 0,0,0);
696 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
704 lsi->lsi_lmd->lmd_mgs_failnodes = i;
706 obd = class_name2obd(mgcname);
708 CERROR("Can't find mgcobd %s\n", mgcname);
709 GOTO(out_free, rc = -ENOTCONN);
712 /* Keep a refcount of servers/clients who started with "mount",
713 so we know when we can get rid of the mgc. */
714 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
716 /* Try all connections, but only once. */
718 rc = obd_set_info_async(obd->obd_self_export,
719 strlen(KEY_INIT_RECOV_BACKUP),
720 KEY_INIT_RECOV_BACKUP,
721 sizeof(recov_bk), &recov_bk, NULL);
724 CERROR("can't set %s %d\n", KEY_INIT_RECOV_BACKUP, rc);
725 /* We connect to the MGS at setup, and don't disconnect until cleanup */
726 rc = obd_connect(NULL, &mgc_conn, obd, &(obd->obd_uuid), &ocd);
728 CERROR("connect failed %d\n", rc);
732 exp = class_conn2export(&mgc_conn);
733 obd->u.cli.cl_mgc_mgsexp = exp;
736 /* Keep the mgc info in the sb. Note that many lsi's can point
740 mutex_up(&mgc_start_lock);
743 OBD_FREE(mgcname, len);
745 OBD_FREE(niduuid, len + 2);
749 static int lustre_stop_mgc(struct super_block *sb)
751 struct lustre_sb_info *lsi = s2lsi(sb);
752 struct obd_device *obd;
753 char *niduuid = 0, *ptr = 0;
754 int i, rc = 0, len = 0;
764 mutex_down(&mgc_start_lock);
765 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
766 /* This is not fatal, every client that stops
767 will call in here. */
768 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
769 atomic_read(&obd->u.cli.cl_mgc_refcount));
770 GOTO(out, rc = -EBUSY);
773 /* The MGC has no recoverable data in any case.
774 * force shotdown set in umount_begin */
775 obd->obd_no_recov = 1;
777 if (obd->u.cli.cl_mgc_mgsexp)
778 obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
780 /* Save the obdname for cleaning the nid uuids, which are
782 len = strlen(obd->obd_name) + 6;
783 OBD_ALLOC(niduuid, len);
785 strcpy(niduuid, obd->obd_name);
786 ptr = niduuid + strlen(niduuid);
789 rc = class_manual_cleanup(obd);
793 /* Clean the nid uuids */
796 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
797 sprintf(ptr, "_%x", i);
798 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
801 CERROR("del MDC UUID %s failed: rc = %d\n",
804 OBD_FREE(niduuid, len);
805 /* class_import_put will get rid of the additional connections */
808 mutex_up(&mgc_start_lock);
812 /* Since there's only one mgc per node, we have to change it's fs to get
813 access to the right disk. */
814 static int server_mgc_set_fs(struct obd_device *mgc, struct super_block *sb)
816 struct lustre_sb_info *lsi = s2lsi(sb);
820 CDEBUG(D_MOUNT, "Set mgc disk for %s\n", lsi->lsi_lmd->lmd_dev);
822 /* cl_mgc_sem in mgc insures we sleep if the mgc_fs is busy */
823 rc = obd_set_info_async(mgc->obd_self_export,
824 strlen("set_fs"), "set_fs",
825 sizeof(*sb), sb, NULL);
827 CERROR("can't set_fs %d\n", rc);
833 static int server_mgc_clear_fs(struct obd_device *mgc)
838 CDEBUG(D_MOUNT, "Unassign mgc disk\n");
840 rc = obd_set_info_async(mgc->obd_self_export,
841 strlen("clear_fs"), "clear_fs",
846 DECLARE_MUTEX(server_start_lock);
848 /* Stop MDS/OSS if nobody is using them */
849 static int server_stop_servers(int lddflags, int lsiflags)
851 struct obd_device *obd = NULL;
852 struct obd_type *type = NULL;
856 mutex_down(&server_start_lock);
858 /* Either an MDT or an OST or neither */
859 /* if this was an MDT, and there are no more MDT's, clean up the MDS */
860 if ((lddflags & LDD_F_SV_TYPE_MDT) &&
861 (obd = class_name2obd(LUSTRE_MDS_OBDNAME))) {
862 /*FIXME pre-rename, should eventually be LUSTRE_MDT_NAME*/
863 type = class_search_type(LUSTRE_MDS_NAME);
865 /* if this was an OST, and there are no more OST's, clean up the OSS */
866 if ((lddflags & LDD_F_SV_TYPE_OST) &&
867 (obd = class_name2obd(LUSTRE_OSS_OBDNAME))) {
868 type = class_search_type(LUSTRE_OST_NAME);
871 if (obd && (!type || !type->typ_refcnt)) {
874 /* obd_fail doesn't mean much on a server obd */
875 err = class_manual_cleanup(obd);
880 mutex_up(&server_start_lock);
885 int server_mti_print(char *title, struct mgs_target_info *mti)
887 PRINT_CMD(PRINT_MASK, "mti %s\n", title);
888 PRINT_CMD(PRINT_MASK, "server: %s\n", mti->mti_svname);
889 PRINT_CMD(PRINT_MASK, "fs: %s\n", mti->mti_fsname);
890 PRINT_CMD(PRINT_MASK, "uuid: %s\n", mti->mti_uuid);
891 PRINT_CMD(PRINT_MASK, "ver: %d flags: %#x\n",
892 mti->mti_config_ver, mti->mti_flags);
897 int mti_set_sec_opts(struct mgs_target_info *mti, struct lustre_mount_data *lmd)
901 if (lmd->lmd_sec_mdt == NULL && lmd->lmd_sec_cli == NULL) {
902 /* just let on-disk params do its work. but we have an
903 * assumption that any changes of on-disk data by tune2fs
904 * should lead to server rewrite log.
909 /* filter out existing sec options */
910 s1 = mti->mti_params;
917 if (strncmp(s1, PARAM_SEC_RPC_MDT,
918 sizeof(PARAM_SEC_RPC_MDT) - 1) == 0 ||
919 strncmp(s1, PARAM_SEC_RPC_CLI,
920 sizeof(PARAM_SEC_RPC_CLI) - 1) == 0)
925 s2 = strchr(s1, ' ');
933 memmove(s1, s2, strlen(s2) + 1);
938 /* append sec options from lmd */
939 /* FIXME add flag LDD_F_UPDATE after mountconf start supporting
942 if (lmd->lmd_sec_mdt) {
943 if (strlen(mti->mti_params) + strlen(lmd->lmd_sec_mdt) +
944 sizeof(PARAM_SEC_RPC_MDT) + 1 >= sizeof(mti->mti_params)) {
945 CERROR("security params too big for mti\n");
948 strcat(mti->mti_params, " "PARAM_SEC_RPC_MDT);
949 strcat(mti->mti_params, lmd->lmd_sec_mdt);
950 //mti->mti_flags |= LDD_F_UPDATE;
952 if (lmd->lmd_sec_cli) {
953 if (strlen(mti->mti_params) + strlen(lmd->lmd_sec_cli) +
954 sizeof(PARAM_SEC_RPC_CLI) + 2 > sizeof(mti->mti_params)) {
955 CERROR("security params too big for mti\n");
958 strcat(mti->mti_params, " "PARAM_SEC_RPC_CLI);
959 strcat(mti->mti_params, lmd->lmd_sec_cli);
960 //mti->mti_flags |= LDD_F_UPDATE;
966 static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti)
968 struct lustre_sb_info *lsi = s2lsi(sb);
969 struct lustre_disk_data *ldd = lsi->lsi_ldd;
970 struct lustre_mount_data *lmd = lsi->lsi_lmd;
971 lnet_process_id_t id;
975 if (!(lsi->lsi_flags & LSI_SERVER))
978 strncpy(mti->mti_fsname, ldd->ldd_fsname,
979 sizeof(mti->mti_fsname));
980 strncpy(mti->mti_svname, ldd->ldd_svname,
981 sizeof(mti->mti_svname));
983 mti->mti_nid_count = 0;
984 while (LNetGetId(i++, &id) != -ENOENT) {
985 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
987 mti->mti_nids[mti->mti_nid_count] = id.nid;
988 mti->mti_nid_count++;
989 if (mti->mti_nid_count >= MTI_NIDS_MAX) {
990 CWARN("Only using first %d nids for %s\n",
991 mti->mti_nid_count, mti->mti_svname);
996 mti->mti_lustre_ver = LUSTRE_VERSION_CODE;
997 mti->mti_config_ver = 0;
998 mti->mti_flags = ldd->ldd_flags;
999 mti->mti_stripe_index = ldd->ldd_svindex;
1000 memcpy(mti->mti_uuid, ldd->ldd_uuid, sizeof(mti->mti_uuid));
1001 if (strlen(ldd->ldd_params) > sizeof(mti->mti_params)) {
1002 CERROR("params too big for mti\n");
1005 memcpy(mti->mti_params, ldd->ldd_params, sizeof(mti->mti_params));
1007 RETURN(mti_set_sec_opts(mti, lmd));
1010 /* Register an old or new target with the MGS. If needed MGS will construct
1011 startup logs and assign index */
1012 int server_register_target(struct super_block *sb)
1014 struct lustre_sb_info *lsi = s2lsi(sb);
1015 struct obd_device *mgc = lsi->lsi_mgc;
1016 struct lustre_disk_data *ldd = lsi->lsi_ldd;
1017 struct mgs_target_info *mti = NULL;
1023 if (!(lsi->lsi_flags & LSI_SERVER))
1029 rc = server_sb2mti(sb, mti);
1033 CDEBUG(D_MOUNT, "Registration %s, fs=%s, %s, index=%04x, flags=%#x\n",
1034 mti->mti_svname, mti->mti_fsname,
1035 libcfs_nid2str(mti->mti_nids[0]), mti->mti_stripe_index,
1038 /* Register the target */
1039 /* FIXME use mgc_process_config instead */
1040 rc = obd_set_info_async(mgc->u.cli.cl_mgc_mgsexp,
1041 strlen("register_target"), "register_target",
1042 sizeof(*mti), mti, NULL);
1044 CERROR("registration with the MGS failed (%d)\n", rc);
1048 /* Always update our flags */
1049 ldd->ldd_flags = mti->mti_flags & ~LDD_F_REWRITE_LDD;
1051 /* If this flag is set, it means the MGS wants us to change our
1052 on-disk data. (So far this means just the index.) */
1053 if (mti->mti_flags & LDD_F_REWRITE_LDD) {
1056 CDEBUG(D_MOUNT, "Changing on-disk index from %#x to %#x "
1057 "for %s\n", ldd->ldd_svindex, mti->mti_stripe_index,
1059 ldd->ldd_svindex = mti->mti_stripe_index;
1060 strncpy(ldd->ldd_svname, mti->mti_svname,
1061 sizeof(ldd->ldd_svname));
1062 /* or ldd_make_sv_name(ldd); */
1063 ldd_write(&mgc->obd_lvfs_ctxt, ldd);
1064 err = fsfilt_set_label(mgc, lsi->lsi_srv_mnt->mnt_sb,
1067 CERROR("Label set error %d\n", err);
1068 label = fsfilt_get_label(mgc, lsi->lsi_srv_mnt->mnt_sb);
1070 CDEBUG(D_MOUNT, "Disk label changed to %s\n", label);
1072 /* Flush the new ldd to disk */
1073 fsfilt_sync(mgc, lsi->lsi_srv_mnt->mnt_sb);
1083 static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
1085 struct obd_device *obd;
1086 struct lustre_sb_info *lsi = s2lsi(sb);
1087 struct config_llog_instance cfg;
1091 CDEBUG(D_MOUNT, "starting target %s\n", lsi->lsi_ldd->ldd_svname);
1094 /* If we're an MDT, make sure the global MDS is running */
1095 if (lsi->lsi_ldd->ldd_flags & LDD_F_SV_TYPE_MDT) {
1096 /* make sure the MDS is started */
1097 mutex_down(&server_start_lock);
1098 obd = class_name2obd(LUSTRE_MDS_OBDNAME);
1100 rc = lustre_start_simple(LUSTRE_MDS_OBDNAME,
1101 /* FIXME pre-rename, should eventually be LUSTRE_MDS_NAME */
1103 LUSTRE_MDS_OBDNAME"_uuid",
1106 mutex_up(&server_start_lock);
1107 CERROR("failed to start MDS: %d\n", rc);
1111 mutex_up(&server_start_lock);
1115 /* If we're an OST, make sure the global OSS is running */
1116 if (lsi->lsi_ldd->ldd_flags & LDD_F_SV_TYPE_OST) {
1117 /* make sure OSS is started */
1118 mutex_down(&server_start_lock);
1119 obd = class_name2obd(LUSTRE_OSS_OBDNAME);
1121 rc = lustre_start_simple(LUSTRE_OSS_OBDNAME,
1123 LUSTRE_OSS_OBDNAME"_uuid",
1126 mutex_up(&server_start_lock);
1127 CERROR("failed to start OSS: %d\n", rc);
1131 mutex_up(&server_start_lock);
1134 /* Set the mgc fs to our server disk. This allows the MGC
1135 to read and write configs locally. */
1136 rc = server_mgc_set_fs(lsi->lsi_mgc, sb);
1140 /* Register with MGS */
1141 rc = server_register_target(sb);
1142 if (rc && (lsi->lsi_ldd->ldd_flags &
1143 (LDD_F_NEED_INDEX | LDD_F_UPDATE | LDD_F_UPGRADE14))){
1144 CERROR("Required registration failed for %s: %d\n",
1145 lsi->lsi_ldd->ldd_svname, rc);
1147 LCONSOLE_ERROR_MSG(0x15f, "Communication error with "
1148 "the MGS. Is the MGS running?\n");
1152 if (rc == -EINVAL) {
1153 LCONSOLE_ERROR_MSG(0x160, "The MGS is refusing to allow this "
1154 "server (%s) to start. Please see messages"
1155 " on the MGS node.\n",
1156 lsi->lsi_ldd->ldd_svname);
1160 /* Let the target look up the mount using the target's name
1161 (we can't pass the sb or mnt through class_process_config.) */
1162 rc = server_register_mount(lsi->lsi_ldd->ldd_svname, sb, mnt);
1166 /* Start targets using the llog named for the target */
1167 memset(&cfg, 0, sizeof(cfg));
1168 rc = lustre_process_log(sb, lsi->lsi_ldd->ldd_svname, &cfg);
1170 CERROR("failed to start server %s: %d\n",
1171 lsi->lsi_ldd->ldd_svname, rc);
1176 /* Release the mgc fs for others to use */
1177 server_mgc_clear_fs(lsi->lsi_mgc);
1180 obd = class_name2obd(lsi->lsi_ldd->ldd_svname);
1182 CERROR("no server named %s was started\n",
1183 lsi->lsi_ldd->ldd_svname);
1187 if ((lsi->lsi_lmd->lmd_flags & LMD_FLG_ABORT_RECOV) &&
1188 (OBP(obd, iocontrol))) {
1189 obd_iocontrol(OBD_IOC_ABORT_RECOVERY,
1190 obd->obd_self_export, 0, NULL, NULL);
1193 /* log has been fully processed */
1194 obd_notify(obd, NULL, OBD_NOTIFY_CONFIG, (void *)CONFIG_LOG);
1200 /***************** lustre superblock **************/
1202 struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
1204 struct lustre_sb_info *lsi = NULL;
1207 OBD_ALLOC(lsi, sizeof(*lsi));
1210 OBD_ALLOC(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
1211 if (!lsi->lsi_lmd) {
1212 OBD_FREE(lsi, sizeof(*lsi));
1216 lsi->lsi_lmd->lmd_exclude_count = 0;
1217 s2lsi_nocast(sb) = lsi;
1218 /* we take 1 extra ref for our setup */
1219 atomic_set(&lsi->lsi_mounts, 1);
1221 /* Default umount style */
1222 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
1224 lsi->lsi_lmd->lmd_nllu = NOBODY_UID;
1225 lsi->lsi_lmd->lmd_nllg = NOBODY_GID;
1229 static int lustre_free_lsi(struct super_block *sb)
1231 struct lustre_sb_info *lsi = s2lsi(sb);
1237 CDEBUG(D_MOUNT, "Freeing lsi\n");
1239 /* someone didn't call server_put_mount. */
1240 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
1242 if (lsi->lsi_ldd != NULL)
1243 OBD_FREE(lsi->lsi_ldd, sizeof(*lsi->lsi_ldd));
1245 if (lsi->lsi_lmd != NULL) {
1246 if (lsi->lsi_lmd->lmd_dev != NULL)
1247 OBD_FREE(lsi->lsi_lmd->lmd_dev,
1248 strlen(lsi->lsi_lmd->lmd_dev) + 1);
1249 if (lsi->lsi_lmd->lmd_profile != NULL)
1250 OBD_FREE(lsi->lsi_lmd->lmd_profile,
1251 strlen(lsi->lsi_lmd->lmd_profile) + 1);
1252 if (lsi->lsi_lmd->lmd_sec_mdt != NULL)
1253 OBD_FREE(lsi->lsi_lmd->lmd_sec_mdt,
1254 strlen(lsi->lsi_lmd->lmd_sec_mdt) + 1);
1255 if (lsi->lsi_lmd->lmd_sec_cli != NULL)
1256 OBD_FREE(lsi->lsi_lmd->lmd_sec_cli,
1257 strlen(lsi->lsi_lmd->lmd_sec_cli) + 1);
1258 if (lsi->lsi_lmd->lmd_opts != NULL)
1259 OBD_FREE(lsi->lsi_lmd->lmd_opts,
1260 strlen(lsi->lsi_lmd->lmd_opts) + 1);
1261 if (lsi->lsi_lmd->lmd_exclude_count)
1262 OBD_FREE(lsi->lsi_lmd->lmd_exclude,
1263 sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
1264 lsi->lsi_lmd->lmd_exclude_count);
1265 OBD_FREE(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
1268 LASSERT(lsi->lsi_llsbi == NULL);
1269 OBD_FREE(lsi, sizeof(*lsi));
1270 s2lsi_nocast(sb) = NULL;
1275 /* The lsi has one reference for every server that is using the disk -
1276 e.g. MDT, MGS, and potentially MGC */
1277 static int lustre_put_lsi(struct super_block *sb)
1279 struct lustre_sb_info *lsi = s2lsi(sb);
1284 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
1286 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
1287 lustre_free_lsi(sb);
1293 /*************** server mount ******************/
1295 /* Kernel mount using mount options in MOUNT_DATA_FILE */
1296 static struct vfsmount *server_kernel_mount(struct super_block *sb)
1298 struct lvfs_run_ctxt mount_ctxt;
1299 struct lustre_sb_info *lsi = s2lsi(sb);
1300 struct lustre_disk_data *ldd;
1301 struct lustre_mount_data *lmd = lsi->lsi_lmd;
1302 struct vfsmount *mnt;
1303 char *options = NULL;
1304 unsigned long page, s_flags;
1305 struct page *__page;
1309 OBD_ALLOC(ldd, sizeof(*ldd));
1311 RETURN(ERR_PTR(-ENOMEM));
1313 /* In the past, we have always used flags = 0.
1314 Note ext3/ldiskfs can't be mounted ro. */
1315 s_flags = sb->s_flags;
1317 /* Pre-mount ldiskfs to read the MOUNT_DATA_FILE */
1318 CDEBUG(D_MOUNT, "Pre-mount ldiskfs %s\n", lmd->lmd_dev);
1319 mnt = ll_kern_mount("ldiskfs", s_flags, lmd->lmd_dev, 0);
1322 CERROR("premount %s:%#lx ldiskfs failed: %d "
1323 "Is the ldiskfs module available?\n",
1324 lmd->lmd_dev, s_flags, rc );
1328 OBD_SET_CTXT_MAGIC(&mount_ctxt);
1329 mount_ctxt.pwdmnt = mnt;
1330 mount_ctxt.pwd = mnt->mnt_root;
1331 mount_ctxt.fs = get_ds();
1333 rc = ldd_parse(&mount_ctxt, ldd);
1337 CERROR("premount parse options failed: rc = %d\n", rc);
1341 /* Done with our pre-mount, now do the real mount. */
1343 /* Glom up mount options */
1344 OBD_PAGE_ALLOC(__page, CFS_ALLOC_STD);
1346 GOTO(out_free, rc = -ENOMEM);
1347 page = (unsigned long)cfs_page_address(__page);
1349 options = (char *)page;
1350 memset(options, 0, CFS_PAGE_SIZE);
1351 strncpy(options, ldd->ldd_mount_opts, CFS_PAGE_SIZE - 2);
1353 /* Add in any mount-line options */
1354 if (lmd->lmd_opts && (*(lmd->lmd_opts) != 0)) {
1355 int len = CFS_PAGE_SIZE - strlen(options) - 2;
1357 strcat(options, ",");
1358 strncat(options, lmd->lmd_opts, len);
1361 /* Special permanent mount flags */
1363 s_flags |= MS_NOATIME | MS_NODIRATIME;
1365 CDEBUG(D_MOUNT, "kern_mount: %s %s %s\n",
1366 MT_STR(ldd), lmd->lmd_dev, options);
1367 mnt = ll_kern_mount(MT_STR(ldd), s_flags, lmd->lmd_dev,
1369 OBD_PAGE_FREE(__page);
1372 CERROR("ll_kern_mount failed: rc = %d\n", rc);
1376 lsi->lsi_ldd = ldd; /* freed at lsi cleanup */
1377 CDEBUG(D_SUPER, "%s: mnt = %p\n", lmd->lmd_dev, mnt);
1381 OBD_FREE(ldd, sizeof(*ldd));
1382 lsi->lsi_ldd = NULL;
1383 RETURN(ERR_PTR(rc));
1386 static void server_wait_finished(struct vfsmount *mnt)
1388 wait_queue_head_t waitq;
1389 struct l_wait_info lwi;
1392 init_waitqueue_head(&waitq);
1394 while ((atomic_read(&mnt->mnt_count) > 1) && (retries > 0)) {
1395 LCONSOLE_WARN("Mount still busy with %d refs, waiting for "
1397 atomic_read(&mnt->mnt_count), retries);
1399 /* Wait for a bit */
1401 lwi = LWI_TIMEOUT(5 * HZ, NULL, NULL);
1402 l_wait_event(waitq, 0, &lwi);
1404 if (atomic_read(&mnt->mnt_count) > 1) {
1405 CERROR("Mount %p is still busy (%d refs), giving up.\n",
1406 mnt, atomic_read(&mnt->mnt_count));
1410 static void server_put_super(struct super_block *sb)
1412 struct lustre_sb_info *lsi = s2lsi(sb);
1413 struct obd_device *obd;
1414 struct vfsmount *mnt = lsi->lsi_srv_mnt;
1415 char *tmpname, *extraname = NULL;
1417 int lddflags = lsi->lsi_ldd->ldd_flags;
1418 int lsiflags = lsi->lsi_flags;
1422 LASSERT(lsiflags & LSI_SERVER);
1424 tmpname_sz = strlen(lsi->lsi_ldd->ldd_svname) + 1;
1425 OBD_ALLOC(tmpname, tmpname_sz);
1426 memcpy(tmpname, lsi->lsi_ldd->ldd_svname, tmpname_sz);
1427 CDEBUG(D_MOUNT, "server put_super %s\n", tmpname);
1429 /* Stop the target */
1430 if (IS_MDT(lsi->lsi_ldd) || IS_OST(lsi->lsi_ldd)) {
1431 struct lustre_profile *lprof = NULL;
1433 /* tell the mgc to drop the config log */
1434 lustre_end_log(sb, lsi->lsi_ldd->ldd_svname, NULL);
1436 /* COMPAT_146 - profile may get deleted in mgc_cleanup.
1437 If there are any setup/cleanup errors, save the lov
1438 name for safety cleanup later. */
1439 lprof = class_get_profile(lsi->lsi_ldd->ldd_svname);
1440 if (lprof && lprof->lp_dt) {
1441 OBD_ALLOC(extraname, strlen(lprof->lp_dt) + 1);
1442 strcpy(extraname, lprof->lp_dt);
1445 obd = class_name2obd(lsi->lsi_ldd->ldd_svname);
1447 CDEBUG(D_MOUNT, "stopping %s\n", obd->obd_name);
1448 if (lsi->lsi_flags & LSI_UMOUNT_FAILOVER)
1450 /* We can't seem to give an error return code
1451 * to .put_super, so we better make sure we clean up! */
1453 class_manual_cleanup(obd);
1455 CERROR("no obd %s\n", lsi->lsi_ldd->ldd_svname);
1456 server_deregister_mount(lsi->lsi_ldd->ldd_svname);
1460 /* If they wanted the mgs to stop separately from the mdt, they
1461 should have put it on a different device. */
1462 if (IS_MGS(lsi->lsi_ldd)) {
1463 /* stop the mgc before the mgs so the connection gets cleaned
1465 lustre_stop_mgc(sb);
1466 server_stop_mgs(sb);
1469 /* Clean the mgc and sb */
1470 rc = lustre_common_put_super(sb);
1471 /* FIXME how can I report a failure to umount? */
1473 /* Wait for the targets to really clean up - can't exit (and let the
1474 sb get destroyed) while the mount is still in use */
1475 server_wait_finished(mnt);
1477 /* drop the One True Mount */
1480 /* Stop the servers (MDS, OSS) if no longer needed. We must wait
1481 until the target is really gone so that our type refcount check
1483 server_stop_servers(lddflags, lsiflags);
1485 /* In case of startup or cleanup err, stop related obds */
1487 obd = class_name2obd(extraname);
1489 CWARN("Cleaning orphaned obd %s\n", extraname);
1491 class_manual_cleanup(obd);
1493 OBD_FREE(extraname, strlen(extraname) + 1);
1496 LCONSOLE_WARN("server umount %s complete\n", tmpname);
1497 OBD_FREE(tmpname, tmpname_sz);
1501 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1502 static void server_umount_begin(struct vfsmount *vfsmnt, int flags)
1504 struct super_block *sb = vfsmnt->mnt_sb;
1506 static void server_umount_begin(struct super_block *sb)
1509 struct lustre_sb_info *lsi = s2lsi(sb);
1512 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1513 if (!(flags & MNT_FORCE)) {
1519 CDEBUG(D_MOUNT, "umount -f\n");
1520 /* umount = failover
1522 no third way to do non-force, non-failover */
1523 lsi->lsi_flags &= ~LSI_UMOUNT_FAILOVER;
1524 lsi->lsi_flags |= LSI_UMOUNT_FORCE;
1528 #ifndef HAVE_STATFS_DENTRY_PARAM
1529 static int server_statfs (struct super_block *sb, struct kstatfs *buf)
1532 static int server_statfs (struct dentry *dentry, struct kstatfs *buf)
1534 struct super_block *sb = dentry->d_sb;
1536 struct vfsmount *mnt = s2lsi(sb)->lsi_srv_mnt;
1539 if (mnt && mnt->mnt_sb && mnt->mnt_sb->s_op->statfs) {
1540 #ifdef HAVE_STATFS_DENTRY_PARAM
1541 int rc = mnt->mnt_sb->s_op->statfs(mnt->mnt_root, buf);
1543 int rc = mnt->mnt_sb->s_op->statfs(mnt->mnt_sb, buf);
1546 buf->f_type = sb->s_magic;
1552 buf->f_type = sb->s_magic;
1553 buf->f_bsize = sb->s_blocksize;
1559 buf->f_namelen = NAME_MAX;
1563 static struct super_operations server_ops =
1565 .put_super = server_put_super,
1566 .umount_begin = server_umount_begin, /* umount -f */
1567 .statfs = server_statfs,
1570 #define log2(n) ffz(~(n))
1571 #define LUSTRE_SUPER_MAGIC 0x0BD00BD1
1573 static int server_fill_super_common(struct super_block *sb)
1575 struct inode *root = 0;
1578 CDEBUG(D_MOUNT, "Server sb, dev=%d\n", (int)sb->s_dev);
1580 sb->s_blocksize = 4096;
1581 sb->s_blocksize_bits = log2(sb->s_blocksize);
1582 sb->s_magic = LUSTRE_SUPER_MAGIC;
1583 sb->s_maxbytes = 0; //PAGE_CACHE_MAXBYTES;
1584 sb->s_flags |= MS_RDONLY;
1585 sb->s_op = &server_ops;
1587 root = new_inode(sb);
1589 CERROR("Can't make root inode\n");
1593 /* returns -EIO for every operation */
1594 /* make_bad_inode(root); -- badness - can't umount */
1595 /* apparently we need to be a directory for the mount to finish */
1596 root->i_mode = S_IFDIR;
1598 sb->s_root = d_alloc_root(root);
1600 CERROR("Can't make root dentry\n");
1608 static int server_fill_super(struct super_block *sb)
1610 struct lustre_sb_info *lsi = s2lsi(sb);
1611 struct vfsmount *mnt;
1615 /* the One True Mount */
1616 mnt = server_kernel_mount(sb);
1619 CERROR("Unable to mount device %s: %d\n",
1620 lsi->lsi_lmd->lmd_dev, rc);
1624 lsi->lsi_srv_mnt = mnt;
1626 LASSERT(lsi->lsi_ldd);
1627 CDEBUG(D_MOUNT, "Found service %s for fs '%s' on device %s\n",
1628 lsi->lsi_ldd->ldd_svname, lsi->lsi_ldd->ldd_fsname,
1629 lsi->lsi_lmd->lmd_dev);
1631 if (class_name2obd(lsi->lsi_ldd->ldd_svname)) {
1632 LCONSOLE_ERROR_MSG(0x161, "The target named %s is already "
1633 "running. Double-mount may have compromised"
1634 " the disk journal.\n",
1635 lsi->lsi_ldd->ldd_svname);
1638 GOTO(out, rc = -EALREADY);
1641 /* start MGS before MGC */
1642 if (IS_MGS(lsi->lsi_ldd)) {
1643 rc = server_start_mgs(sb);
1648 rc = lustre_start_mgc(sb);
1652 /* Set up all obd devices for service */
1653 if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC) &&
1654 (IS_OST(lsi->lsi_ldd) || IS_MDT(lsi->lsi_ldd))) {
1655 rc = server_start_targets(sb, mnt);
1657 CERROR("Unable to start targets: %d\n", rc);
1660 /* FIXME overmount client here,
1661 or can we just start a client log and client_fill_super on this sb?
1662 We need to make sure server_put_super gets called too - ll_put_super
1663 calls lustre_common_put_super; check there for LSI_SERVER flag,
1665 Probably should start client from new thread so we can return.
1666 Client will not finish until all servers are connected.
1667 Note - MGS-only server does NOT get a client, since there is no
1668 lustre fs associated - the MGS is for all lustre fs's */
1671 rc = server_fill_super_common(sb);
1675 LCONSOLE_WARN("Server %s on device %s has started\n",
1676 lsi->lsi_ldd->ldd_svname, lsi->lsi_lmd->lmd_dev);
1681 server_put_super(sb);
1686 /* Get the index from the obd name.
1687 rc = server type, or
1689 if endptr isn't NULL it is set to end of name */
1690 int server_name2index(char *svname, __u32 *idx, char **endptr)
1692 unsigned long index;
1694 char *dash = strchr(svname, '-');
1698 if (strncmp(dash + 1, "MDT", 3) == 0)
1699 rc = LDD_F_SV_TYPE_MDT;
1700 else if (strncmp(dash + 1, "OST", 3) == 0)
1701 rc = LDD_F_SV_TYPE_OST;
1705 index = simple_strtoul(dash + 4, endptr, 16);
1710 /*************** mount common betweeen server and client ***************/
1713 int lustre_common_put_super(struct super_block *sb)
1718 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
1720 /* Drop a ref to the MGC */
1721 rc = lustre_stop_mgc(sb);
1722 if (rc && (rc != -ENOENT)) {
1724 CERROR("Can't stop MGC: %d\n", rc);
1727 /* BUSY just means that there's some other obd that
1728 needs the mgc. Let him clean it up. */
1729 CDEBUG(D_MOUNT, "MGC still in use\n");
1731 /* Drop a ref to the mounted disk */
1737 static void lmd_print(struct lustre_mount_data *lmd)
1741 PRINT_CMD(PRINT_MASK, " mount data:\n");
1742 if (lmd_is_client(lmd))
1743 PRINT_CMD(PRINT_MASK, "profile: %s\n", lmd->lmd_profile);
1744 PRINT_CMD(PRINT_MASK, "device: %s\n", lmd->lmd_dev);
1745 PRINT_CMD(PRINT_MASK, "flags: %x\n", lmd->lmd_flags);
1746 if (lmd->lmd_sec_mdt)
1747 PRINT_CMD(PRINT_MASK, "sec_mdt: %s\n", lmd->lmd_sec_mdt);
1748 if (lmd->lmd_sec_cli)
1749 PRINT_CMD(PRINT_MASK, "sec_cli: %s\n", lmd->lmd_sec_cli);
1751 PRINT_CMD(PRINT_MASK, "options: %s\n", lmd->lmd_opts);
1752 for (i = 0; i < lmd->lmd_exclude_count; i++) {
1753 PRINT_CMD(PRINT_MASK, "exclude %d: OST%04x\n", i,
1754 lmd->lmd_exclude[i]);
1759 /* Is this server on the exclusion list */
1760 int lustre_check_exclusion(struct super_block *sb, char *svname)
1762 struct lustre_sb_info *lsi = s2lsi(sb);
1763 struct lustre_mount_data *lmd = lsi->lsi_lmd;
1768 rc = server_name2index(svname, &index, NULL);
1769 if (rc != LDD_F_SV_TYPE_OST)
1770 /* Only exclude OSTs */
1773 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
1774 index, lmd->lmd_exclude_count, lmd->lmd_dev);
1776 for(i = 0; i < lmd->lmd_exclude_count; i++) {
1777 if (index == lmd->lmd_exclude[i]) {
1778 CWARN("Excluding %s (on exclusion list)\n", svname);
1785 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
1786 static int lmd_make_exclusion(struct lustre_mount_data *lmd, char *ptr)
1788 char *s1 = ptr, *s2;
1789 __u32 index, *exclude_list;
1793 /* The shortest an ost name can be is 8 chars: -OST0000.
1794 We don't actually know the fsname at this time, so in fact
1795 a user could specify any fsname. */
1796 devmax = strlen(ptr) / 8 + 1;
1798 /* temp storage until we figure out how many we have */
1799 OBD_ALLOC(exclude_list, sizeof(index) * devmax);
1803 /* we enter this fn pointing at the '=' */
1804 while (*s1 && *s1 != ' ' && *s1 != ',') {
1806 rc = server_name2index(s1, &index, &s2);
1808 CERROR("Can't parse server name '%s'\n", s1);
1811 if (rc == LDD_F_SV_TYPE_OST)
1812 exclude_list[lmd->lmd_exclude_count++] = index;
1814 CDEBUG(D_MOUNT, "ignoring exclude %.7s\n", s1);
1816 /* now we are pointing at ':' (next exclude)
1817 or ',' (end of excludes) */
1818 if (lmd->lmd_exclude_count >= devmax)
1821 if (rc >= 0) /* non-err */
1824 if (lmd->lmd_exclude_count) {
1825 /* permanent, freed in lustre_free_lsi */
1826 OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
1827 lmd->lmd_exclude_count);
1828 if (lmd->lmd_exclude) {
1829 memcpy(lmd->lmd_exclude, exclude_list,
1830 sizeof(index) * lmd->lmd_exclude_count);
1833 lmd->lmd_exclude_count = 0;
1836 OBD_FREE(exclude_list, sizeof(index) * devmax);
1841 int lmd_set_sec_opts(char **set, char *opts, int length)
1844 OBD_FREE(*set, strlen(*set) + 1);
1846 OBD_ALLOC(*set, length + 1);
1850 memcpy(*set, opts, length);
1851 (*set)[length] = '\0';
1857 int lmd_parse_sec_opts(struct lustre_mount_data *lmd, char *ptr)
1863 /* check peer name */
1864 if (strncmp(ptr, "sec_mdt=", 8) == 0) {
1865 set = &lmd->lmd_sec_mdt;
1867 } else if (strncmp(ptr, "sec_cli=", 8) == 0) {
1868 set = &lmd->lmd_sec_cli;
1870 } else if (strncmp(ptr, "sec=", 4) == 0) {
1871 /* leave 'set' be null */
1874 CERROR("invalid security options: %s\n", ptr);
1878 tail = strchr(ptr, ',');
1880 length = strlen(ptr);
1882 length = tail - ptr;
1885 if (lmd_set_sec_opts(set, ptr, length))
1888 if (lmd->lmd_sec_mdt == NULL &&
1889 lmd_set_sec_opts(&lmd->lmd_sec_mdt, ptr, length))
1892 if (lmd->lmd_sec_cli == NULL &&
1893 lmd_set_sec_opts(&lmd->lmd_sec_cli, ptr, length))
1900 /* mount -v -t lustre uml1:uml2:/lustre-client /mnt/lustre */
1901 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
1903 char *s1, *s2, *devname = NULL;
1904 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
1910 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that "
1911 "/sbin/mount.lustre is installed.\n");
1915 /* Options should be a string - try to detect old lmd data */
1916 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1917 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of "
1918 "/sbin/mount.lustre. Please install "
1919 "version %s\n", LUSTRE_VERSION_STRING);
1922 lmd->lmd_magic = LMD_MAGIC;
1924 /* Set default flags here */
1929 /* Skip whitespace and extra commas */
1930 while (*s1 == ' ' || *s1 == ',')
1933 /* Client options are parsed in ll_options: eg. flock,
1936 /* Parse non-ldiskfs options here. Rather than modifying
1937 ldiskfs, we just zero these out here */
1938 if (strncmp(s1, "abort_recov", 11) == 0) {
1939 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
1941 } else if (strncmp(s1, "nosvc", 5) == 0) {
1942 lmd->lmd_flags |= LMD_FLG_NOSVC;
1944 /* ost exclusion list */
1945 } else if (strncmp(s1, "exclude=", 8) == 0) {
1946 rc = lmd_make_exclusion(lmd, s1 + 7);
1950 } else if (strncmp(s1, "nllu=", 5) == 0) {
1951 lmd->lmd_nllu = simple_strtoul(s1 + 5, NULL, 10);
1953 } else if (strncmp(s1, "nllg=", 5) == 0) {
1954 lmd->lmd_nllg = simple_strtoul(s1 + 5, NULL, 10);
1956 } else if (strncmp(s1, "sec", 3) == 0) {
1957 rc = lmd_parse_sec_opts(lmd, s1);
1962 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1963 end of the options. */
1964 else if (strncmp(s1, "device=", 7) == 0) {
1966 /* terminate options right before device. device
1967 must be the last one. */
1973 s2 = strchr(s1, ',');
1981 memmove(s1, s2, strlen(s2) + 1);
1987 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name "
1988 "(need mount option 'device=...')\n");
1992 s1 = strrchr(devname, ':');
1994 lmd->lmd_flags = LMD_FLG_CLIENT;
1995 /* Remove leading /s from fsname */
1996 while (*++s1 == '/') ;
1997 /* Freed in lustre_free_lsi */
1998 OBD_ALLOC(lmd->lmd_profile, strlen(s1) + 8);
1999 if (!lmd->lmd_profile)
2001 sprintf(lmd->lmd_profile, "%s-client", s1);
2004 /* Freed in lustre_free_lsi */
2005 OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
2008 strcpy(lmd->lmd_dev, devname);
2010 /* Save mount options */
2011 s1 = options + strlen(options) - 1;
2012 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
2014 if (*options != 0) {
2015 /* Freed in lustre_free_lsi */
2016 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
2019 strcpy(lmd->lmd_opts, options);
2022 lmd->lmd_magic = LMD_MAGIC;
2027 CERROR("Bad mount options %s\n", options);
2033 int lustre_fill_super(struct super_block *sb, void *data, int silent)
2035 struct lustre_mount_data *lmd;
2036 struct lustre_sb_info *lsi;
2040 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
2042 lsi = lustre_init_lsi(sb);
2047 /* Figure out the lmd from the mount options */
2048 if (lmd_parse((char *)data, lmd)) {
2053 if (lmd_is_client(lmd)) {
2054 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
2055 if (!client_fill_super) {
2056 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for "
2057 "client mount! Is the 'lustre' "
2058 "module loaded?\n");
2061 rc = lustre_start_mgc(sb);
2063 lustre_stop_mgc(sb);
2066 /* Connect and start */
2067 /* (should always be ll_fill_super) */
2068 rc = (*client_fill_super)(sb);
2069 /* c_f_s will call lustre_common_put_super on failure */
2072 CDEBUG(D_MOUNT, "Mounting server from %s\n", lmd->lmd_dev);
2073 lsi->lsi_flags |= LSI_SERVER;
2074 rc = server_fill_super(sb);
2075 /* s_f_s calls lustre_start_mgc after the mount because we need
2076 the MGS nids which are stored on disk. Plus, we may
2077 need to start the MGS first. */
2078 /* s_f_s will call server_put_super on failure */
2083 CERROR("Unable to mount %s (%d)\n",
2084 s2lsi(sb) ? lmd->lmd_dev : "", rc);
2086 CDEBUG(D_SUPER, "mount %s complete\n", lmd->lmd_dev);
2092 /* We can't call ll_fill_super by name because it lives in a module that
2093 must be loaded after this one. */
2094 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb))
2096 client_fill_super = cfs;
2099 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
2101 kill_super_cb = cfs;
2104 /***************** FS registration ******************/
2106 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
2107 struct super_block * lustre_get_sb(struct file_system_type *fs_type,
2108 int flags, const char *devname, void * data)
2110 /* calls back in fill super */
2111 /* we could append devname= onto options (*data) here,
2112 but 2.4 doesn't get devname. So we do it in mount_lustre.c */
2113 return get_sb_nodev(fs_type, flags, data, lustre_fill_super);
2116 int lustre_get_sb(struct file_system_type *fs_type,
2117 int flags, const char *devname, void * data,
2118 struct vfsmount *mnt)
2120 /* calls back in fill super */
2121 /* we could append devname= onto options (*data) here,
2122 but 2.4 doesn't get devname. So we do it in mount_lustre.c */
2123 return get_sb_nodev(fs_type, flags, data, lustre_fill_super, mnt);
2127 void lustre_kill_super(struct super_block *sb)
2129 struct lustre_sb_info *lsi = s2lsi(sb);
2131 if (kill_super_cb && lsi &&(lsi->lsi_flags & LSI_SERVER))
2132 (*kill_super_cb)(sb);
2134 kill_anon_super(sb);
2137 struct file_system_type lustre_fs_type = {
2138 .owner = THIS_MODULE,
2140 .get_sb = lustre_get_sb,
2141 .kill_sb = lustre_kill_super,
2142 .fs_flags = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV,
2145 int lustre_register_fs(void)
2147 return register_filesystem(&lustre_fs_type);
2150 int lustre_unregister_fs(void)
2152 return unregister_filesystem(&lustre_fs_type);
2155 EXPORT_SYMBOL(lustre_register_client_fill_super);
2156 EXPORT_SYMBOL(lustre_register_kill_super_cb);
2157 EXPORT_SYMBOL(lustre_common_put_super);
2158 EXPORT_SYMBOL(lustre_process_log);
2159 EXPORT_SYMBOL(lustre_end_log);
2160 EXPORT_SYMBOL(server_get_mount);
2161 EXPORT_SYMBOL(server_get_mount_2);
2162 EXPORT_SYMBOL(server_put_mount);
2163 EXPORT_SYMBOL(server_put_mount_2);
2164 EXPORT_SYMBOL(server_register_target);
2165 EXPORT_SYMBOL(server_name2index);
2166 EXPORT_SYMBOL(server_mti_print);
2167 EXPORT_SYMBOL(do_lcfg);