4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/obdclass/obd_mount.c
34 * Client mount routines
36 * Author: Nathan Rutman <nathan@clusterfs.com>
40 #define DEBUG_SUBSYSTEM S_CLASS
41 #define D_MOUNT (D_SUPER|D_CONFIG/*|D_WARNING */)
42 #define PRINT_CMD CDEBUG
45 #include <obd_class.h>
46 #include <lustre/lustre_user.h>
47 #include <linux/version.h>
48 #include <lustre_log.h>
49 #include <lustre_disk.h>
50 #include <lustre_param.h>
52 static int (*client_fill_super)(struct super_block *sb,
53 struct vfsmount *mnt);
55 static void (*kill_super_cb)(struct super_block *sb);
57 /**************** config llog ********************/
59 /** Get a config log from the MGS and process it.
60 * This func is called for both clients and servers.
61 * Continue to process new statements appended to the logs
62 * (whenever the config lock is revoked) until lustre_end_log
64 * @param sb The superblock is used by the MGC to write to the local copy of
66 * @param logname The name of the llog to replicate from the MGS
67 * @param cfg Since the same mgc may be used to follow multiple config logs
68 * (e.g. ost1, ost2, client), the config_llog_instance keeps the state for
69 * this log, and is added to the mgc's list of logs to follow.
71 int lustre_process_log(struct super_block *sb, char *logname,
72 struct config_llog_instance *cfg)
74 struct lustre_cfg *lcfg;
75 struct lustre_cfg_bufs *bufs;
76 struct lustre_sb_info *lsi = s2lsi(sb);
77 struct obd_device *mgc = lsi->lsi_mgc;
88 /* mgc_process_config */
89 lustre_cfg_bufs_reset(bufs, mgc->obd_name);
90 lustre_cfg_bufs_set_string(bufs, 1, logname);
91 lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
92 lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
93 lcfg = lustre_cfg_new(LCFG_LOG_START, bufs);
95 GOTO(out, rc = -ENOMEM);
96 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
97 lustre_cfg_free(lcfg);
102 LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s'"
103 "failed from the MGS (%d). Make sure this "
104 "client and the MGS are running compatible "
105 "versions of Lustre.\n",
106 mgc->obd_name, logname, rc);
108 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' "
109 "failed (%d). This may be the result of "
110 "communication errors between this node and "
111 "the MGS, a bad configuration, or other "
112 "errors. See the syslog for more "
113 "information.\n", mgc->obd_name, logname,
116 /* class_obd_list(); */
119 EXPORT_SYMBOL(lustre_process_log);
121 /* Stop watching this config log for updates */
122 int lustre_end_log(struct super_block *sb, char *logname,
123 struct config_llog_instance *cfg)
125 struct lustre_cfg *lcfg;
126 struct lustre_cfg_bufs bufs;
127 struct lustre_sb_info *lsi = s2lsi(sb);
128 struct obd_device *mgc = lsi->lsi_mgc;
135 /* mgc_process_config */
136 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
137 lustre_cfg_bufs_set_string(&bufs, 1, logname);
139 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
140 lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
143 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
144 lustre_cfg_free(lcfg);
147 EXPORT_SYMBOL(lustre_end_log);
149 /**************** obd start *******************/
151 /** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
152 * lctl (and do for echo cli/srv.
154 int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
155 char *s1, char *s2, char *s3, char *s4)
157 struct lustre_cfg_bufs bufs;
158 struct lustre_cfg * lcfg = NULL;
161 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
162 cmd, s1, s2, s3, s4);
164 lustre_cfg_bufs_reset(&bufs, cfgname);
166 lustre_cfg_bufs_set_string(&bufs, 1, s1);
168 lustre_cfg_bufs_set_string(&bufs, 2, s2);
170 lustre_cfg_bufs_set_string(&bufs, 3, s3);
172 lustre_cfg_bufs_set_string(&bufs, 4, s4);
174 lcfg = lustre_cfg_new(cmd, &bufs);
177 lcfg->lcfg_nid = nid;
178 rc = class_process_config(lcfg);
179 lustre_cfg_free(lcfg);
183 /** Call class_attach and class_setup. These methods in turn call
184 * obd type-specific methods.
186 int lustre_start_simple(char *obdname, char *type, char *uuid,
187 char *s1, char *s2, char *s3, char *s4)
190 CDEBUG(D_MOUNT, "Starting obd %s (typ=%s)\n", obdname, type);
192 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
194 CERROR("%s attach error %d\n", obdname, rc);
197 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
199 CERROR("%s setup error %d\n", obdname, rc);
200 do_lcfg(obdname, 0, LCFG_DETACH, NULL, NULL, NULL, NULL);
205 static DEFINE_MUTEX(mgc_start_lock);
207 /** Set up a mgc obd to process startup logs
209 * \param sb [in] super block of the mgc obd
211 * \retval 0 success, otherwise error code
213 int lustre_start_mgc(struct super_block *sb)
215 struct obd_connect_data *data = NULL;
216 struct lustre_sb_info *lsi = s2lsi(sb);
217 struct obd_device *obd;
218 struct obd_export *exp;
219 struct obd_uuid *uuid;
222 char nidstr[LNET_NIDSTR_SIZE];
223 char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
225 int rc = 0, i = 0, j;
229 LASSERT(lsi->lsi_lmd);
231 /* Find the first non-lo MGS nid for our MGC name */
232 if (IS_SERVER(lsi)) {
233 /* mount -o mgsnode=nid */
234 ptr = lsi->lsi_lmd->lmd_mgs;
235 if (lsi->lsi_lmd->lmd_mgs &&
236 (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) {
238 } else if (IS_MGS(lsi)) {
239 struct lnet_process_id id;
241 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
242 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
249 } else { /* client */
250 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
251 ptr = lsi->lsi_lmd->lmd_dev;
252 if (class_parse_nid(ptr, &nid, &ptr) == 0)
256 CERROR("No valid MGS nids found.\n");
260 mutex_lock(&mgc_start_lock);
262 libcfs_nid2str_r(nid, nidstr, sizeof(nidstr));
263 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(nidstr) + 1;
264 OBD_ALLOC(mgcname, len);
265 OBD_ALLOC(niduuid, len + 2);
266 if (mgcname == NULL || niduuid == NULL)
267 GOTO(out_free, rc = -ENOMEM);
268 snprintf(mgcname, len, "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
270 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
274 GOTO(out_free, rc = -ENOMEM);
276 obd = class_name2obd(mgcname);
277 if (obd && !obd->obd_stopping) {
280 rc = obd_set_info_async(NULL, obd->obd_self_export,
281 strlen(KEY_MGSSEC), KEY_MGSSEC,
282 strlen(mgssec), mgssec, NULL);
286 /* Re-using an existing MGC */
287 atomic_inc(&obd->u.cli.cl_mgc_refcount);
289 /* IR compatibility check, only for clients */
290 if (lmd_is_client(lsi->lsi_lmd)) {
292 int vallen = sizeof(*data);
293 __u32 *flags = &lsi->lsi_lmd->lmd_flags;
295 rc = obd_get_info(NULL, obd->obd_self_export,
296 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
299 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
300 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
301 /* LMD_FLG_NOIR is for test purpose only */
303 "Trying to mount a client with IR setting "
304 "not compatible with current mgc. "
305 "Force to use current mgc setting that is "
307 has_ir ? "enabled" : "disabled");
309 *flags &= ~LMD_FLG_NOIR;
311 *flags |= LMD_FLG_NOIR;
316 /* If we are restarting the MGS, don't try to keep the MGC's
317 old connection, or registration will fail. */
319 CDEBUG(D_MOUNT, "New MGS with live MGC\n");
323 /* Try all connections, but only once (again).
324 We don't want to block another target from starting
325 (using its local copy of the log), but we do want to connect
326 if at all possible. */
328 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,recov_bk);
329 rc = obd_set_info_async(NULL, obd->obd_self_export,
330 sizeof(KEY_INIT_RECOV_BACKUP),
331 KEY_INIT_RECOV_BACKUP,
332 sizeof(recov_bk), &recov_bk, NULL);
336 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
338 /* Add the primary nids for the MGS */
340 snprintf(niduuid, len + 2, "%s_%x", mgcname, i);
341 if (IS_SERVER(lsi)) {
342 ptr = lsi->lsi_lmd->lmd_mgs;
343 CDEBUG(D_MOUNT, "mgs nids %s.\n", ptr);
345 /* Use local nids (including LO) */
346 struct lnet_process_id id;
348 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
349 rc = do_lcfg(mgcname, id.nid, LCFG_ADD_UUID,
350 niduuid, NULL, NULL, NULL);
353 /* Use mgsnode= nids */
354 /* mount -o mgsnode=nid */
355 if (lsi->lsi_lmd->lmd_mgs) {
356 ptr = lsi->lsi_lmd->lmd_mgs;
357 } else if (class_find_param(ptr, PARAM_MGSNODE,
359 CERROR("No MGS nids given.\n");
360 GOTO(out_free, rc = -EINVAL);
364 * Here we only take the first mgsnid as its primary
365 * serving mgs node, the rest mgsnid will be taken as
366 * failover mgs node, otherwise they would be takens
367 * as multiple nids of a single mgs node.
369 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
370 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
371 niduuid, NULL, NULL, NULL);
378 } else { /* client */
379 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
380 ptr = lsi->lsi_lmd->lmd_dev;
381 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
382 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
383 niduuid, NULL, NULL, NULL);
386 /* Stop at the first failover nid */
392 CERROR("No valid MGS nids found.\n");
393 GOTO(out_free, rc = -EINVAL);
395 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
397 /* Random uuid for MGC allows easier reconnects */
400 GOTO(out_free, rc = -ENOMEM);
402 ll_generate_random_uuid(uuidc);
403 class_uuid_unparse(uuidc, uuid);
406 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
407 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
408 niduuid, NULL, NULL);
413 /* Add any failover MGS nids */
415 while (ptr && ((*ptr == ':' ||
416 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
417 /* New failover node */
418 sprintf(niduuid, "%s_%x", mgcname, i);
420 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
421 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
422 niduuid, NULL, NULL, NULL);
429 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
430 niduuid, NULL, NULL, NULL);
438 lsi->lsi_lmd->lmd_mgs_failnodes = i;
440 obd = class_name2obd(mgcname);
442 CERROR("Can't find mgcobd %s\n", mgcname);
443 GOTO(out_free, rc = -ENOTCONN);
446 rc = obd_set_info_async(NULL, obd->obd_self_export,
447 strlen(KEY_MGSSEC), KEY_MGSSEC,
448 strlen(mgssec), mgssec, NULL);
452 /* Keep a refcount of servers/clients who started with "mount",
453 so we know when we can get rid of the mgc. */
454 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
456 /* We connect to the MGS at setup, and don't disconnect until cleanup */
457 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
458 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
459 OBD_CONNECT_LVB_TYPE | OBD_CONNECT_BULK_MBITS;
461 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
462 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
465 if (lmd_is_client(lsi->lsi_lmd) &&
466 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
467 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
468 data->ocd_version = LUSTRE_VERSION_CODE;
469 rc = obd_connect(NULL, &exp, obd, &(obd->obd_uuid), data, NULL);
471 CERROR("connect failed %d\n", rc);
475 obd->u.cli.cl_mgc_mgsexp = exp;
478 /* Keep the mgc info in the sb. Note that many lsi's can point
482 mutex_unlock(&mgc_start_lock);
487 OBD_FREE(mgcname, len);
489 OBD_FREE(niduuid, len + 2);
493 static int lustre_stop_mgc(struct super_block *sb)
495 struct lustre_sb_info *lsi = s2lsi(sb);
496 struct obd_device *obd;
497 char *niduuid = NULL, *ptr = NULL;
498 int i, rc = 0, len = 0;
508 mutex_lock(&mgc_start_lock);
509 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
510 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
511 /* This is not fatal, every client that stops
512 will call in here. */
513 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
514 atomic_read(&obd->u.cli.cl_mgc_refcount));
515 GOTO(out, rc = -EBUSY);
518 /* The MGC has no recoverable data in any case.
519 * force shotdown set in umount_begin */
520 obd->obd_no_recov = 1;
522 if (obd->u.cli.cl_mgc_mgsexp) {
523 /* An error is not fatal, if we are unable to send the
524 disconnect mgs ping evictor cleans up the export */
525 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
527 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
530 /* Save the obdname for cleaning the nid uuids, which are
532 len = strlen(obd->obd_name) + 6;
533 OBD_ALLOC(niduuid, len);
535 strcpy(niduuid, obd->obd_name);
536 ptr = niduuid + strlen(niduuid);
539 rc = class_manual_cleanup(obd);
543 /* Clean the nid uuids */
545 GOTO(out, rc = -ENOMEM);
547 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
548 sprintf(ptr, "_%x", i);
549 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
550 niduuid, NULL, NULL, NULL);
552 CERROR("del MDC UUID %s failed: rc = %d\n",
557 OBD_FREE(niduuid, len);
559 /* class_import_put will get rid of the additional connections */
560 mutex_unlock(&mgc_start_lock);
564 /***************** lustre superblock **************/
566 static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
568 struct lustre_sb_info *lsi;
574 OBD_ALLOC_PTR(lsi->lsi_lmd);
580 lsi->lsi_lmd->lmd_exclude_count = 0;
581 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
582 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
583 s2lsi_nocast(sb) = lsi;
584 /* we take 1 extra ref for our setup */
585 atomic_set(&lsi->lsi_mounts, 1);
587 /* Default umount style */
588 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
589 INIT_LIST_HEAD(&lsi->lsi_lwp_list);
590 spin_lock_init(&lsi->lsi_lwp_lock);
595 static int lustre_free_lsi(struct super_block *sb)
597 struct lustre_sb_info *lsi = s2lsi(sb);
600 LASSERT(lsi != NULL);
601 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
603 /* someone didn't call server_put_mount. */
604 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
606 if (lsi->lsi_lmd != NULL) {
607 if (lsi->lsi_lmd->lmd_dev != NULL)
608 OBD_FREE(lsi->lsi_lmd->lmd_dev,
609 strlen(lsi->lsi_lmd->lmd_dev) + 1);
610 if (lsi->lsi_lmd->lmd_profile != NULL)
611 OBD_FREE(lsi->lsi_lmd->lmd_profile,
612 strlen(lsi->lsi_lmd->lmd_profile) + 1);
613 if (lsi->lsi_lmd->lmd_fileset != NULL)
614 OBD_FREE(lsi->lsi_lmd->lmd_fileset,
615 strlen(lsi->lsi_lmd->lmd_fileset) + 1);
616 if (lsi->lsi_lmd->lmd_mgssec != NULL)
617 OBD_FREE(lsi->lsi_lmd->lmd_mgssec,
618 strlen(lsi->lsi_lmd->lmd_mgssec) + 1);
619 if (lsi->lsi_lmd->lmd_opts != NULL)
620 OBD_FREE(lsi->lsi_lmd->lmd_opts,
621 strlen(lsi->lsi_lmd->lmd_opts) + 1);
622 if (lsi->lsi_lmd->lmd_exclude_count)
623 OBD_FREE(lsi->lsi_lmd->lmd_exclude,
624 sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
625 lsi->lsi_lmd->lmd_exclude_count);
626 if (lsi->lsi_lmd->lmd_mgs != NULL)
627 OBD_FREE(lsi->lsi_lmd->lmd_mgs,
628 strlen(lsi->lsi_lmd->lmd_mgs) + 1);
629 if (lsi->lsi_lmd->lmd_osd_type != NULL)
630 OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
631 strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
632 if (lsi->lsi_lmd->lmd_params != NULL)
633 OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
634 if (lsi->lsi_lmd->lmd_nidnet != NULL)
635 OBD_FREE(lsi->lsi_lmd->lmd_nidnet,
636 strlen(lsi->lsi_lmd->lmd_nidnet) + 1);
638 OBD_FREE_PTR(lsi->lsi_lmd);
641 LASSERT(lsi->lsi_llsbi == NULL);
643 s2lsi_nocast(sb) = NULL;
648 /* The lsi has one reference for every server that is using the disk -
649 e.g. MDT, MGS, and potentially MGC */
650 int lustre_put_lsi(struct super_block *sb)
652 struct lustre_sb_info *lsi = s2lsi(sb);
655 LASSERT(lsi != NULL);
657 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
658 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
659 if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
660 lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
661 lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
662 lsi->lsi_dt_dev = NULL;
663 obd_disconnect(lsi->lsi_osd_exp);
664 /* wait till OSD is gone */
665 obd_zombie_barrier();
674 * <FSNAME><SEPARATOR><TYPE><INDEX>
675 * FSNAME is between 1 and 8 characters (inclusive).
676 * Excluded characters are '/' and ':'
677 * SEPARATOR is either ':' or '-'
678 * TYPE: "OST", "MDT", etc.
679 * INDEX: Hex representation of the index
682 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
683 * @param [in] svname server name including type and index
684 * @param [out] fsname Buffer to copy filesystem name prefix into.
685 * Must have at least 'strlen(fsname) + 1' chars.
686 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
689 int server_name2fsname(const char *svname, char *fsname, const char **endptr)
693 dash = svname + strnlen(svname, 8); /* max fsname length is 8 */
694 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
699 if (fsname != NULL) {
700 strncpy(fsname, svname, dash - svname);
701 fsname[dash - svname] = '\0';
709 EXPORT_SYMBOL(server_name2fsname);
712 * Get service name (svname) from string
714 * if endptr isn't NULL it is set to end of fsname *
716 int server_name2svname(const char *label, char *svname, const char **endptr,
722 /* We use server_name2fsname() just for parsing */
723 rc = server_name2fsname(label, NULL, &dash);
730 if (strlcpy(svname, dash + 1, svsize) >= svsize)
735 EXPORT_SYMBOL(server_name2svname);
738 * check server name is OST.
740 int server_name_is_ost(const char *svname)
745 /* We use server_name2fsname() just for parsing */
746 rc = server_name2fsname(svname, NULL, &dash);
752 if (strncmp(dash, "OST", 3) == 0)
756 EXPORT_SYMBOL(server_name_is_ost);
759 * Get the index from the target name MDTXXXX/OSTXXXX
760 * rc = server type, or rc < 0 on error
762 int target_name2index(const char *tgtname, __u32 *idx, const char **endptr)
764 const char *dash = tgtname;
768 if (strncmp(dash, "MDT", 3) == 0)
769 rc = LDD_F_SV_TYPE_MDT;
770 else if (strncmp(dash, "OST", 3) == 0)
771 rc = LDD_F_SV_TYPE_OST;
777 if (strncmp(dash, "all", 3) == 0) {
780 return rc | LDD_F_SV_ALL;
783 index = simple_strtoul(dash, (char **)endptr, 16);
788 EXPORT_SYMBOL(target_name2index);
790 /* Get the index from the obd name.
793 if endptr isn't NULL it is set to end of name */
794 int server_name2index(const char *svname, __u32 *idx, const char **endptr)
799 /* We use server_name2fsname() just for parsing */
800 rc = server_name2fsname(svname, NULL, &dash);
805 rc = target_name2index(dash, idx, endptr);
809 /* Account for -mdc after index that is possible when specifying mdt */
810 if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
811 sizeof(LUSTRE_MDC_NAME)-1) == 0)
812 *endptr += sizeof(LUSTRE_MDC_NAME);
816 EXPORT_SYMBOL(server_name2index);
818 /*************** mount common betweeen server and client ***************/
821 int lustre_common_put_super(struct super_block *sb)
826 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
828 /* Drop a ref to the MGC */
829 rc = lustre_stop_mgc(sb);
830 if (rc && (rc != -ENOENT)) {
832 CERROR("Can't stop MGC: %d\n", rc);
835 /* BUSY just means that there's some other obd that
836 needs the mgc. Let him clean it up. */
837 CDEBUG(D_MOUNT, "MGC still in use\n");
839 /* Drop a ref to the mounted disk */
844 EXPORT_SYMBOL(lustre_common_put_super);
846 static void lmd_print(struct lustre_mount_data *lmd)
850 PRINT_CMD(D_MOUNT, " mount data:\n");
851 if (lmd_is_client(lmd))
852 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
853 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
854 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
857 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
859 if (lmd->lmd_recovery_time_soft)
860 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
861 lmd->lmd_recovery_time_soft);
863 if (lmd->lmd_recovery_time_hard)
864 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
865 lmd->lmd_recovery_time_hard);
867 for (i = 0; i < lmd->lmd_exclude_count; i++) {
868 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
869 lmd->lmd_exclude[i]);
873 /* Is this server on the exclusion list */
874 int lustre_check_exclusion(struct super_block *sb, char *svname)
876 struct lustre_sb_info *lsi = s2lsi(sb);
877 struct lustre_mount_data *lmd = lsi->lsi_lmd;
882 rc = server_name2index(svname, &index, NULL);
883 if (rc != LDD_F_SV_TYPE_OST)
884 /* Only exclude OSTs */
887 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
888 index, lmd->lmd_exclude_count, lmd->lmd_dev);
890 for(i = 0; i < lmd->lmd_exclude_count; i++) {
891 if (index == lmd->lmd_exclude[i]) {
892 CWARN("Excluding %s (on exclusion list)\n", svname);
899 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
900 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
902 const char *s1 = ptr, *s2;
908 /* The shortest an ost name can be is 8 chars: -OST0000.
909 We don't actually know the fsname at this time, so in fact
910 a user could specify any fsname. */
911 devmax = strlen(ptr) / 8 + 1;
913 /* temp storage until we figure out how many we have */
914 OBD_ALLOC(exclude_list, sizeof(index) * devmax);
918 /* we enter this fn pointing at the '=' */
919 while (*s1 && *s1 != ' ' && *s1 != ',') {
921 rc = server_name2index(s1, &index, &s2);
923 CERROR("Can't parse server name '%s': rc = %d\n",
927 if (rc == LDD_F_SV_TYPE_OST)
928 exclude_list[lmd->lmd_exclude_count++] = index;
930 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
931 (uint)(s2-s1), s1, rc);
933 /* now we are pointing at ':' (next exclude)
934 or ',' (end of excludes) */
935 if (lmd->lmd_exclude_count >= devmax)
938 if (rc >= 0) /* non-err */
941 if (lmd->lmd_exclude_count) {
942 /* permanent, freed in lustre_free_lsi */
943 OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
944 lmd->lmd_exclude_count);
945 if (lmd->lmd_exclude) {
946 memcpy(lmd->lmd_exclude, exclude_list,
947 sizeof(index) * lmd->lmd_exclude_count);
950 lmd->lmd_exclude_count = 0;
953 OBD_FREE(exclude_list, sizeof(index) * devmax);
957 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
962 if (lmd->lmd_mgssec != NULL) {
963 OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
964 lmd->lmd_mgssec = NULL;
967 tail = strchr(ptr, ',');
969 length = strlen(ptr);
973 OBD_ALLOC(lmd->lmd_mgssec, length + 1);
974 if (lmd->lmd_mgssec == NULL)
977 memcpy(lmd->lmd_mgssec, ptr, length);
978 lmd->lmd_mgssec[length] = '\0';
982 static int lmd_parse_network(struct lustre_mount_data *lmd, char *ptr)
987 if (lmd->lmd_nidnet != NULL) {
988 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
989 lmd->lmd_nidnet = NULL;
992 tail = strchr(ptr, ',');
994 length = strlen(ptr);
998 OBD_ALLOC(lmd->lmd_nidnet, length + 1);
999 if (lmd->lmd_nidnet == NULL)
1002 memcpy(lmd->lmd_nidnet, ptr, length);
1003 lmd->lmd_nidnet[length] = '\0';
1007 static int lmd_parse_string(char **handle, char *ptr)
1012 if ((handle == NULL) || (ptr == NULL))
1015 if (*handle != NULL) {
1016 OBD_FREE(*handle, strlen(*handle) + 1);
1020 tail = strchr(ptr, ',');
1022 length = strlen(ptr);
1024 length = tail - ptr;
1026 OBD_ALLOC(*handle, length + 1);
1027 if (*handle == NULL)
1030 memcpy(*handle, ptr, length);
1031 (*handle)[length] = '\0';
1036 /* Collect multiple values for mgsnid specifiers */
1037 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
1045 /* Find end of nidlist */
1046 while (class_parse_nid_quiet(tail, &nid, &tail) == 0) {}
1047 length = tail - *ptr;
1049 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
1053 if (lmd->lmd_mgs != NULL)
1054 oldlen = strlen(lmd->lmd_mgs) + 1;
1056 OBD_ALLOC(mgsnid, oldlen + length + 1);
1060 if (lmd->lmd_mgs != NULL) {
1061 /* Multiple mgsnid= are taken to mean failover locations */
1062 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
1063 mgsnid[oldlen - 1] = ':';
1064 OBD_FREE(lmd->lmd_mgs, oldlen);
1066 memcpy(mgsnid + oldlen, *ptr, length);
1067 mgsnid[oldlen + length] = '\0';
1068 lmd->lmd_mgs = mgsnid;
1075 * Find the first delimiter (comma or colon) from the specified \a buf and
1076 * make \a *endh point to the string starting with the delimiter. The commas
1077 * in expression list [...] will be skipped.
1079 * \param[in] buf a delimiter-separated string
1080 * \param[in] endh a pointer to a pointer that will point to the string
1081 * starting with the delimiter
1083 * \retval 0 if delimiter is found
1084 * \retval 1 if delimiter is not found
1086 static int lmd_find_delimiter(char *buf, char **endh)
1094 while (*c != '\0') {
1100 if ((*c == ',' || *c == ':') && skip == 0) {
1113 * Find the first valid string delimited by comma or colon from the specified
1114 * \a buf and parse it to see whether it's a valid nid list. If yes, \a *endh
1115 * will point to the next string starting with the delimiter.
1117 * \param[in] buf a delimiter-separated string
1118 * \param[in] endh a pointer to a pointer that will point to the string
1119 * starting with the delimiter
1121 * \retval 0 if the string is a valid nid list
1122 * \retval 1 if the string is not a valid nid list
1124 static int lmd_parse_nidlist(char *buf, char **endh)
1126 struct list_head nidlist;
1133 while (*buf == ',' || *buf == ':')
1135 if (*buf == ' ' || *buf == '/' || *buf == '\0')
1138 if (lmd_find_delimiter(buf, &endp) != 0)
1139 endp = buf + strlen(buf);
1144 INIT_LIST_HEAD(&nidlist);
1145 if (cfs_parse_nidlist(buf, strlen(buf), &nidlist) <= 0)
1147 cfs_free_nidlist(&nidlist);
1157 /** Parse mount line options
1158 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
1159 * dev is passed as device=uml1:/lustre by mount.lustre
1161 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
1163 char *s1, *s2, *devname = NULL;
1164 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
1170 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that "
1171 "/sbin/mount.lustre is installed.\n");
1175 /* Options should be a string - try to detect old lmd data */
1176 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1177 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of "
1178 "/sbin/mount.lustre. Please install "
1179 "version %s\n", LUSTRE_VERSION_STRING);
1182 lmd->lmd_magic = LMD_MAGIC;
1184 OBD_ALLOC(lmd->lmd_params, LMD_PARAMS_MAXLEN);
1185 if (lmd->lmd_params == NULL)
1187 lmd->lmd_params[0] = '\0';
1189 /* Set default flags here */
1194 int time_min = OBD_RECOVERY_TIME_MIN;
1197 /* Skip whitespace and extra commas */
1198 while (*s1 == ' ' || *s1 == ',')
1202 /* Client options are parsed in ll_options: eg. flock,
1205 /* Parse non-ldiskfs options here. Rather than modifying
1206 ldiskfs, we just zero these out here */
1207 if (strncmp(s1, "abort_recov", 11) == 0) {
1208 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
1210 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
1211 lmd->lmd_recovery_time_soft =
1212 max_t(int, simple_strtoul(s1 + 19, NULL, 10),
1215 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
1216 lmd->lmd_recovery_time_hard =
1217 max_t(int, simple_strtoul(s1 + 19, NULL, 10),
1220 } else if (strncmp(s1, "noir", 4) == 0) {
1221 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
1223 } else if (strncmp(s1, "nosvc", 5) == 0) {
1224 lmd->lmd_flags |= LMD_FLG_NOSVC;
1226 } else if (strncmp(s1, "nomgs", 5) == 0) {
1227 lmd->lmd_flags |= LMD_FLG_NOMGS;
1229 } else if (strncmp(s1, "noscrub", 7) == 0) {
1230 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
1232 } else if (strncmp(s1, "skip_lfsck", 10) == 0) {
1233 lmd->lmd_flags |= LMD_FLG_SKIP_LFSCK;
1235 } else if (strncmp(s1, PARAM_MGSNODE,
1236 sizeof(PARAM_MGSNODE) - 1) == 0) {
1237 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
1238 /* Assume the next mount opt is the first
1239 invalid nid we get to. */
1240 rc = lmd_parse_mgs(lmd, &s2);
1245 } else if (strncmp(s1, "writeconf", 9) == 0) {
1246 lmd->lmd_flags |= LMD_FLG_WRITECONF;
1248 } else if (strncmp(s1, "update", 6) == 0) {
1249 lmd->lmd_flags |= LMD_FLG_UPDATE;
1251 } else if (strncmp(s1, "virgin", 6) == 0) {
1252 lmd->lmd_flags |= LMD_FLG_VIRGIN;
1254 } else if (strncmp(s1, "noprimnode", 10) == 0) {
1255 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
1257 } else if (strncmp(s1, "mgssec=", 7) == 0) {
1258 rc = lmd_parse_mgssec(lmd, s1 + 7);
1262 /* ost exclusion list */
1263 } else if (strncmp(s1, "exclude=", 8) == 0) {
1264 rc = lmd_make_exclusion(lmd, s1 + 7);
1268 } else if (strncmp(s1, "mgs", 3) == 0) {
1270 lmd->lmd_flags |= LMD_FLG_MGS;
1272 } else if (strncmp(s1, "svname=", 7) == 0) {
1273 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
1277 } else if (strncmp(s1, "param=", 6) == 0) {
1278 size_t length, params_length;
1280 if (lmd_find_delimiter(s1 + 6, &tail) != 0)
1281 length = strlen(s1);
1283 char *param_str = tail + 1;
1284 int supplementary = 1;
1285 while (lmd_parse_nidlist(param_str,
1289 length = param_str - s1 - supplementary;
1292 params_length = strlen(lmd->lmd_params);
1293 if (params_length + length + 1 >= LMD_PARAMS_MAXLEN)
1295 strncat(lmd->lmd_params, s1 + 6, length);
1296 lmd->lmd_params[params_length + length] = '\0';
1297 strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
1298 s3 = s1 + 6 + length;
1300 } else if (strncmp(s1, "osd=", 4) == 0) {
1301 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1306 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1307 end of the options. */
1308 else if (strncmp(s1, "device=", 7) == 0) {
1310 /* terminate options right before device. device
1311 must be the last one. */
1314 } else if (strncmp(s1, "network=", 8) == 0) {
1315 rc = lmd_parse_network(lmd, s1 + 8);
1322 s2 = strchr(s3, ',');
1330 memmove(s1, s2, strlen(s2) + 1);
1336 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name "
1337 "(need mount option 'device=...')\n");
1341 s1 = strstr(devname, ":/");
1344 lmd->lmd_flags |= LMD_FLG_CLIENT;
1345 /* Remove leading /s from fsname */
1346 while (*++s1 == '/')
1349 while (*s2 != '/' && *s2 != '\0')
1351 /* Freed in lustre_free_lsi */
1352 OBD_ALLOC(lmd->lmd_profile, s2 - s1 + 8);
1353 if (!lmd->lmd_profile)
1356 strncat(lmd->lmd_profile, s1, s2 - s1);
1357 strncat(lmd->lmd_profile, "-client", 7);
1360 s2 = s1 + strlen(s1) - 1;
1361 /* Remove padding /s from fileset */
1365 OBD_ALLOC(lmd->lmd_fileset, s2 - s1 + 2);
1366 if (lmd->lmd_fileset == NULL) {
1367 OBD_FREE(lmd->lmd_profile,
1368 strlen(lmd->lmd_profile) + 1);
1371 strncat(lmd->lmd_fileset, s1, s2 - s1 + 1);
1375 if (lmd->lmd_nidnet != NULL) {
1376 /* 'network=' mount option forbidden for server */
1377 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
1378 lmd->lmd_nidnet = NULL;
1380 CERROR("%s: option 'network=' not allowed for Lustre "
1381 "servers: rc = %d\n", devname, rc);
1386 /* Freed in lustre_free_lsi */
1387 OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
1390 strncpy(lmd->lmd_dev, devname, strlen(devname)+1);
1392 /* Save mount options */
1393 s1 = options + strlen(options) - 1;
1394 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1396 if (*options != 0) {
1397 /* Freed in lustre_free_lsi */
1398 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
1401 strncpy(lmd->lmd_opts, options, strlen(options)+1);
1405 lmd->lmd_magic = LMD_MAGIC;
1410 CERROR("Bad mount options %s\n", options);
1414 struct lustre_mount_data2 {
1416 struct vfsmount *lmd2_mnt;
1419 /** This is the entry point for the mount call into Lustre.
1420 * This is called when a server or client is mounted,
1421 * and this is where we start setting things up.
1422 * @param data Mount options (e.g. -o flock,abort_recov)
1424 static int lustre_fill_super(struct super_block *sb, void *data, int silent)
1426 struct lustre_mount_data *lmd;
1427 struct lustre_mount_data2 *lmd2 = data;
1428 struct lustre_sb_info *lsi;
1432 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
1434 lsi = lustre_init_lsi(sb);
1440 * Disable lockdep during mount, because mount locking patterns are
1446 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1448 obd_zombie_barrier();
1450 /* Figure out the lmd from the mount options */
1451 if (lmd_parse((char *)(lmd2->lmd2_data), lmd)) {
1453 GOTO(out, rc = -EINVAL);
1456 if (lmd_is_client(lmd)) {
1457 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1458 if (client_fill_super == NULL)
1459 request_module("lustre");
1460 if (client_fill_super == NULL) {
1461 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for "
1462 "client mount! Is the 'lustre' "
1463 "module loaded?\n");
1467 rc = lustre_start_mgc(sb);
1469 lustre_common_put_super(sb);
1472 /* Connect and start */
1473 /* (should always be ll_fill_super) */
1474 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1475 /* c_f_s will call lustre_common_put_super on failure */
1478 #ifdef HAVE_SERVER_SUPPORT
1479 CDEBUG(D_MOUNT, "Mounting server from %s\n", lmd->lmd_dev);
1480 rc = server_fill_super(sb);
1481 /* s_f_s calls lustre_start_mgc after the mount because we need
1482 the MGS nids which are stored on disk. Plus, we may
1483 need to start the MGS first. */
1484 /* s_f_s will call server_put_super on failure */
1486 CERROR("This is client-side-only module, "
1487 "cannot handle server mount.\n");
1492 /* If error happens in fill_super() call, @lsi will be killed there.
1493 * This is why we do not put it here. */
1497 CERROR("Unable to mount %s (%d)\n",
1498 s2lsi(sb) ? lmd->lmd_dev : "", rc);
1500 CDEBUG(D_SUPER, "Mount %s complete\n",
1508 /* We can't call ll_fill_super by name because it lives in a module that
1509 must be loaded after this one. */
1510 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1511 struct vfsmount *mnt))
1513 client_fill_super = cfs;
1515 EXPORT_SYMBOL(lustre_register_client_fill_super);
1517 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1519 kill_super_cb = cfs;
1521 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1523 /***************** FS registration ******************/
1524 #ifdef HAVE_FSTYPE_MOUNT
1525 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1526 const char *devname, void *data)
1528 struct lustre_mount_data2 lmd2 = {
1532 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1535 static int lustre_get_sb(struct file_system_type *fs_type, int flags,
1536 const char *devname, void *data, struct vfsmount *mnt)
1538 struct lustre_mount_data2 lmd2 = {
1543 return get_sb_nodev(fs_type, flags, &lmd2, lustre_fill_super, mnt);
1547 static void lustre_kill_super(struct super_block *sb)
1549 struct lustre_sb_info *lsi = s2lsi(sb);
1551 if (kill_super_cb && lsi && !IS_SERVER(lsi))
1552 (*kill_super_cb)(sb);
1554 kill_anon_super(sb);
1557 /** Register the "lustre" fs type
1559 static struct file_system_type lustre_fs_type = {
1560 .owner = THIS_MODULE,
1562 #ifdef HAVE_FSTYPE_MOUNT
1563 .mount = lustre_mount,
1565 .get_sb = lustre_get_sb,
1567 .kill_sb = lustre_kill_super,
1568 .fs_flags = FS_REQUIRES_DEV | FS_HAS_FIEMAP | FS_RENAME_DOES_D_MOVE,
1570 MODULE_ALIAS_FS("lustre");
1572 int lustre_register_fs(void)
1574 return register_filesystem(&lustre_fs_type);
1577 int lustre_unregister_fs(void)
1579 return unregister_filesystem(&lustre_fs_type);