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 lnet_process_id_t id;
240 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
241 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
248 } else { /* client */
249 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
250 ptr = lsi->lsi_lmd->lmd_dev;
251 if (class_parse_nid(ptr, &nid, &ptr) == 0)
255 CERROR("No valid MGS nids found.\n");
259 mutex_lock(&mgc_start_lock);
261 libcfs_nid2str_r(nid, nidstr, sizeof(nidstr));
262 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(nidstr) + 1;
263 OBD_ALLOC(mgcname, len);
264 OBD_ALLOC(niduuid, len + 2);
265 if (mgcname == NULL || niduuid == NULL)
266 GOTO(out_free, rc = -ENOMEM);
267 snprintf(mgcname, len, "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
269 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
273 GOTO(out_free, rc = -ENOMEM);
275 obd = class_name2obd(mgcname);
276 if (obd && !obd->obd_stopping) {
279 rc = obd_set_info_async(NULL, obd->obd_self_export,
280 strlen(KEY_MGSSEC), KEY_MGSSEC,
281 strlen(mgssec), mgssec, NULL);
285 /* Re-using an existing MGC */
286 atomic_inc(&obd->u.cli.cl_mgc_refcount);
288 /* IR compatibility check, only for clients */
289 if (lmd_is_client(lsi->lsi_lmd)) {
291 int vallen = sizeof(*data);
292 __u32 *flags = &lsi->lsi_lmd->lmd_flags;
294 rc = obd_get_info(NULL, obd->obd_self_export,
295 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
298 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
299 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
300 /* LMD_FLG_NOIR is for test purpose only */
302 "Trying to mount a client with IR setting "
303 "not compatible with current mgc. "
304 "Force to use current mgc setting that is "
306 has_ir ? "enabled" : "disabled");
308 *flags &= ~LMD_FLG_NOIR;
310 *flags |= LMD_FLG_NOIR;
315 /* If we are restarting the MGS, don't try to keep the MGC's
316 old connection, or registration will fail. */
318 CDEBUG(D_MOUNT, "New MGS with live MGC\n");
322 /* Try all connections, but only once (again).
323 We don't want to block another target from starting
324 (using its local copy of the log), but we do want to connect
325 if at all possible. */
327 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,recov_bk);
328 rc = obd_set_info_async(NULL, obd->obd_self_export,
329 sizeof(KEY_INIT_RECOV_BACKUP),
330 KEY_INIT_RECOV_BACKUP,
331 sizeof(recov_bk), &recov_bk, NULL);
335 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
337 /* Add the primary nids for the MGS */
339 snprintf(niduuid, len + 2, "%s_%x", mgcname, i);
340 if (IS_SERVER(lsi)) {
341 ptr = lsi->lsi_lmd->lmd_mgs;
342 CDEBUG(D_MOUNT, "mgs nids %s.\n", ptr);
344 /* Use local nids (including LO) */
345 lnet_process_id_t id;
346 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
347 rc = do_lcfg(mgcname, id.nid, LCFG_ADD_UUID,
348 niduuid, NULL, NULL, NULL);
351 /* Use mgsnode= nids */
352 /* mount -o mgsnode=nid */
353 if (lsi->lsi_lmd->lmd_mgs) {
354 ptr = lsi->lsi_lmd->lmd_mgs;
355 } else if (class_find_param(ptr, PARAM_MGSNODE,
357 CERROR("No MGS nids given.\n");
358 GOTO(out_free, rc = -EINVAL);
362 * Here we only take the first mgsnid as its primary
363 * serving mgs node, the rest mgsnid will be taken as
364 * failover mgs node, otherwise they would be takens
365 * as multiple nids of a single mgs node.
367 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
368 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
369 niduuid, NULL, NULL, NULL);
376 } else { /* client */
377 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
378 ptr = lsi->lsi_lmd->lmd_dev;
379 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
380 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
381 niduuid, NULL, NULL, NULL);
384 /* Stop at the first failover nid */
390 CERROR("No valid MGS nids found.\n");
391 GOTO(out_free, rc = -EINVAL);
393 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
395 /* Random uuid for MGC allows easier reconnects */
398 GOTO(out_free, rc = -ENOMEM);
400 ll_generate_random_uuid(uuidc);
401 class_uuid_unparse(uuidc, uuid);
404 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
405 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
406 niduuid, NULL, NULL);
411 /* Add any failover MGS nids */
413 while (ptr && ((*ptr == ':' ||
414 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
415 /* New failover node */
416 sprintf(niduuid, "%s_%x", mgcname, i);
418 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
419 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
420 niduuid, NULL, NULL, NULL);
427 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
428 niduuid, NULL, NULL, NULL);
436 lsi->lsi_lmd->lmd_mgs_failnodes = i;
438 obd = class_name2obd(mgcname);
440 CERROR("Can't find mgcobd %s\n", mgcname);
441 GOTO(out_free, rc = -ENOTCONN);
444 rc = obd_set_info_async(NULL, obd->obd_self_export,
445 strlen(KEY_MGSSEC), KEY_MGSSEC,
446 strlen(mgssec), mgssec, NULL);
450 /* Keep a refcount of servers/clients who started with "mount",
451 so we know when we can get rid of the mgc. */
452 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
454 /* We connect to the MGS at setup, and don't disconnect until cleanup */
455 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
456 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
457 OBD_CONNECT_LVB_TYPE | OBD_CONNECT_BULK_MBITS;
459 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
460 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
463 if (lmd_is_client(lsi->lsi_lmd) &&
464 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
465 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
466 data->ocd_version = LUSTRE_VERSION_CODE;
467 rc = obd_connect(NULL, &exp, obd, &(obd->obd_uuid), data, NULL);
469 CERROR("connect failed %d\n", rc);
473 obd->u.cli.cl_mgc_mgsexp = exp;
476 /* Keep the mgc info in the sb. Note that many lsi's can point
480 mutex_unlock(&mgc_start_lock);
485 OBD_FREE(mgcname, len);
487 OBD_FREE(niduuid, len + 2);
491 static int lustre_stop_mgc(struct super_block *sb)
493 struct lustre_sb_info *lsi = s2lsi(sb);
494 struct obd_device *obd;
495 char *niduuid = NULL, *ptr = NULL;
496 int i, rc = 0, len = 0;
506 mutex_lock(&mgc_start_lock);
507 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
508 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
509 /* This is not fatal, every client that stops
510 will call in here. */
511 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
512 atomic_read(&obd->u.cli.cl_mgc_refcount));
513 GOTO(out, rc = -EBUSY);
516 /* The MGC has no recoverable data in any case.
517 * force shotdown set in umount_begin */
518 obd->obd_no_recov = 1;
520 if (obd->u.cli.cl_mgc_mgsexp) {
521 /* An error is not fatal, if we are unable to send the
522 disconnect mgs ping evictor cleans up the export */
523 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
525 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
528 /* Save the obdname for cleaning the nid uuids, which are
530 len = strlen(obd->obd_name) + 6;
531 OBD_ALLOC(niduuid, len);
533 strcpy(niduuid, obd->obd_name);
534 ptr = niduuid + strlen(niduuid);
537 rc = class_manual_cleanup(obd);
541 /* Clean the nid uuids */
543 GOTO(out, rc = -ENOMEM);
545 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
546 sprintf(ptr, "_%x", i);
547 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
548 niduuid, NULL, NULL, NULL);
550 CERROR("del MDC UUID %s failed: rc = %d\n",
555 OBD_FREE(niduuid, len);
557 /* class_import_put will get rid of the additional connections */
558 mutex_unlock(&mgc_start_lock);
562 /***************** lustre superblock **************/
564 static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
566 struct lustre_sb_info *lsi;
572 OBD_ALLOC_PTR(lsi->lsi_lmd);
578 lsi->lsi_lmd->lmd_exclude_count = 0;
579 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
580 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
581 s2lsi_nocast(sb) = lsi;
582 /* we take 1 extra ref for our setup */
583 atomic_set(&lsi->lsi_mounts, 1);
585 /* Default umount style */
586 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
587 INIT_LIST_HEAD(&lsi->lsi_lwp_list);
588 spin_lock_init(&lsi->lsi_lwp_lock);
593 static int lustre_free_lsi(struct super_block *sb)
595 struct lustre_sb_info *lsi = s2lsi(sb);
598 LASSERT(lsi != NULL);
599 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
601 /* someone didn't call server_put_mount. */
602 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
604 if (lsi->lsi_lmd != NULL) {
605 if (lsi->lsi_lmd->lmd_dev != NULL)
606 OBD_FREE(lsi->lsi_lmd->lmd_dev,
607 strlen(lsi->lsi_lmd->lmd_dev) + 1);
608 if (lsi->lsi_lmd->lmd_profile != NULL)
609 OBD_FREE(lsi->lsi_lmd->lmd_profile,
610 strlen(lsi->lsi_lmd->lmd_profile) + 1);
611 if (lsi->lsi_lmd->lmd_fileset != NULL)
612 OBD_FREE(lsi->lsi_lmd->lmd_fileset,
613 strlen(lsi->lsi_lmd->lmd_fileset) + 1);
614 if (lsi->lsi_lmd->lmd_mgssec != NULL)
615 OBD_FREE(lsi->lsi_lmd->lmd_mgssec,
616 strlen(lsi->lsi_lmd->lmd_mgssec) + 1);
617 if (lsi->lsi_lmd->lmd_opts != NULL)
618 OBD_FREE(lsi->lsi_lmd->lmd_opts,
619 strlen(lsi->lsi_lmd->lmd_opts) + 1);
620 if (lsi->lsi_lmd->lmd_exclude_count)
621 OBD_FREE(lsi->lsi_lmd->lmd_exclude,
622 sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
623 lsi->lsi_lmd->lmd_exclude_count);
624 if (lsi->lsi_lmd->lmd_mgs != NULL)
625 OBD_FREE(lsi->lsi_lmd->lmd_mgs,
626 strlen(lsi->lsi_lmd->lmd_mgs) + 1);
627 if (lsi->lsi_lmd->lmd_osd_type != NULL)
628 OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
629 strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
630 if (lsi->lsi_lmd->lmd_params != NULL)
631 OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
632 if (lsi->lsi_lmd->lmd_nidnet != NULL)
633 OBD_FREE(lsi->lsi_lmd->lmd_nidnet,
634 strlen(lsi->lsi_lmd->lmd_nidnet) + 1);
636 OBD_FREE_PTR(lsi->lsi_lmd);
639 LASSERT(lsi->lsi_llsbi == NULL);
641 s2lsi_nocast(sb) = NULL;
646 /* The lsi has one reference for every server that is using the disk -
647 e.g. MDT, MGS, and potentially MGC */
648 int lustre_put_lsi(struct super_block *sb)
650 struct lustre_sb_info *lsi = s2lsi(sb);
653 LASSERT(lsi != NULL);
655 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
656 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
657 if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
658 lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
659 lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
660 lsi->lsi_dt_dev = NULL;
661 obd_disconnect(lsi->lsi_osd_exp);
662 /* wait till OSD is gone */
663 obd_zombie_barrier();
672 * <FSNAME><SEPARATOR><TYPE><INDEX>
673 * FSNAME is between 1 and 8 characters (inclusive).
674 * Excluded characters are '/' and ':'
675 * SEPARATOR is either ':' or '-'
676 * TYPE: "OST", "MDT", etc.
677 * INDEX: Hex representation of the index
680 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
681 * @param [in] svname server name including type and index
682 * @param [out] fsname Buffer to copy filesystem name prefix into.
683 * Must have at least 'strlen(fsname) + 1' chars.
684 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
687 int server_name2fsname(const char *svname, char *fsname, const char **endptr)
691 dash = svname + strnlen(svname, 8); /* max fsname length is 8 */
692 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
697 if (fsname != NULL) {
698 strncpy(fsname, svname, dash - svname);
699 fsname[dash - svname] = '\0';
707 EXPORT_SYMBOL(server_name2fsname);
710 * Get service name (svname) from string
712 * if endptr isn't NULL it is set to end of fsname *
714 int server_name2svname(const char *label, char *svname, const char **endptr,
720 /* We use server_name2fsname() just for parsing */
721 rc = server_name2fsname(label, NULL, &dash);
728 if (strlcpy(svname, dash + 1, svsize) >= svsize)
733 EXPORT_SYMBOL(server_name2svname);
736 * check server name is OST.
738 int server_name_is_ost(const char *svname)
743 /* We use server_name2fsname() just for parsing */
744 rc = server_name2fsname(svname, NULL, &dash);
750 if (strncmp(dash, "OST", 3) == 0)
754 EXPORT_SYMBOL(server_name_is_ost);
757 * Get the index from the target name MDTXXXX/OSTXXXX
758 * rc = server type, or rc < 0 on error
760 int target_name2index(const char *tgtname, __u32 *idx, const char **endptr)
762 const char *dash = tgtname;
766 if (strncmp(dash, "MDT", 3) == 0)
767 rc = LDD_F_SV_TYPE_MDT;
768 else if (strncmp(dash, "OST", 3) == 0)
769 rc = LDD_F_SV_TYPE_OST;
775 if (strncmp(dash, "all", 3) == 0) {
778 return rc | LDD_F_SV_ALL;
781 index = simple_strtoul(dash, (char **)endptr, 16);
786 EXPORT_SYMBOL(target_name2index);
788 /* Get the index from the obd name.
791 if endptr isn't NULL it is set to end of name */
792 int server_name2index(const char *svname, __u32 *idx, const char **endptr)
797 /* We use server_name2fsname() just for parsing */
798 rc = server_name2fsname(svname, NULL, &dash);
803 rc = target_name2index(dash, idx, endptr);
807 /* Account for -mdc after index that is possible when specifying mdt */
808 if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
809 sizeof(LUSTRE_MDC_NAME)-1) == 0)
810 *endptr += sizeof(LUSTRE_MDC_NAME);
814 EXPORT_SYMBOL(server_name2index);
816 /*************** mount common betweeen server and client ***************/
819 int lustre_common_put_super(struct super_block *sb)
824 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
826 /* Drop a ref to the MGC */
827 rc = lustre_stop_mgc(sb);
828 if (rc && (rc != -ENOENT)) {
830 CERROR("Can't stop MGC: %d\n", rc);
833 /* BUSY just means that there's some other obd that
834 needs the mgc. Let him clean it up. */
835 CDEBUG(D_MOUNT, "MGC still in use\n");
837 /* Drop a ref to the mounted disk */
842 EXPORT_SYMBOL(lustre_common_put_super);
844 static void lmd_print(struct lustre_mount_data *lmd)
848 PRINT_CMD(D_MOUNT, " mount data:\n");
849 if (lmd_is_client(lmd))
850 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
851 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
852 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
855 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
857 if (lmd->lmd_recovery_time_soft)
858 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
859 lmd->lmd_recovery_time_soft);
861 if (lmd->lmd_recovery_time_hard)
862 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
863 lmd->lmd_recovery_time_hard);
865 for (i = 0; i < lmd->lmd_exclude_count; i++) {
866 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
867 lmd->lmd_exclude[i]);
871 /* Is this server on the exclusion list */
872 int lustre_check_exclusion(struct super_block *sb, char *svname)
874 struct lustre_sb_info *lsi = s2lsi(sb);
875 struct lustre_mount_data *lmd = lsi->lsi_lmd;
880 rc = server_name2index(svname, &index, NULL);
881 if (rc != LDD_F_SV_TYPE_OST)
882 /* Only exclude OSTs */
885 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
886 index, lmd->lmd_exclude_count, lmd->lmd_dev);
888 for(i = 0; i < lmd->lmd_exclude_count; i++) {
889 if (index == lmd->lmd_exclude[i]) {
890 CWARN("Excluding %s (on exclusion list)\n", svname);
897 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
898 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
900 const char *s1 = ptr, *s2;
906 /* The shortest an ost name can be is 8 chars: -OST0000.
907 We don't actually know the fsname at this time, so in fact
908 a user could specify any fsname. */
909 devmax = strlen(ptr) / 8 + 1;
911 /* temp storage until we figure out how many we have */
912 OBD_ALLOC(exclude_list, sizeof(index) * devmax);
916 /* we enter this fn pointing at the '=' */
917 while (*s1 && *s1 != ' ' && *s1 != ',') {
919 rc = server_name2index(s1, &index, &s2);
921 CERROR("Can't parse server name '%s': rc = %d\n",
925 if (rc == LDD_F_SV_TYPE_OST)
926 exclude_list[lmd->lmd_exclude_count++] = index;
928 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
929 (uint)(s2-s1), s1, rc);
931 /* now we are pointing at ':' (next exclude)
932 or ',' (end of excludes) */
933 if (lmd->lmd_exclude_count >= devmax)
936 if (rc >= 0) /* non-err */
939 if (lmd->lmd_exclude_count) {
940 /* permanent, freed in lustre_free_lsi */
941 OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
942 lmd->lmd_exclude_count);
943 if (lmd->lmd_exclude) {
944 memcpy(lmd->lmd_exclude, exclude_list,
945 sizeof(index) * lmd->lmd_exclude_count);
948 lmd->lmd_exclude_count = 0;
951 OBD_FREE(exclude_list, sizeof(index) * devmax);
955 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
960 if (lmd->lmd_mgssec != NULL) {
961 OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
962 lmd->lmd_mgssec = NULL;
965 tail = strchr(ptr, ',');
967 length = strlen(ptr);
971 OBD_ALLOC(lmd->lmd_mgssec, length + 1);
972 if (lmd->lmd_mgssec == NULL)
975 memcpy(lmd->lmd_mgssec, ptr, length);
976 lmd->lmd_mgssec[length] = '\0';
980 static int lmd_parse_network(struct lustre_mount_data *lmd, char *ptr)
985 if (lmd->lmd_nidnet != NULL) {
986 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
987 lmd->lmd_nidnet = NULL;
990 tail = strchr(ptr, ',');
992 length = strlen(ptr);
996 OBD_ALLOC(lmd->lmd_nidnet, length + 1);
997 if (lmd->lmd_nidnet == NULL)
1000 memcpy(lmd->lmd_nidnet, ptr, length);
1001 lmd->lmd_nidnet[length] = '\0';
1005 static int lmd_parse_string(char **handle, char *ptr)
1010 if ((handle == NULL) || (ptr == NULL))
1013 if (*handle != NULL) {
1014 OBD_FREE(*handle, strlen(*handle) + 1);
1018 tail = strchr(ptr, ',');
1020 length = strlen(ptr);
1022 length = tail - ptr;
1024 OBD_ALLOC(*handle, length + 1);
1025 if (*handle == NULL)
1028 memcpy(*handle, ptr, length);
1029 (*handle)[length] = '\0';
1034 /* Collect multiple values for mgsnid specifiers */
1035 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
1043 /* Find end of nidlist */
1044 while (class_parse_nid_quiet(tail, &nid, &tail) == 0) {}
1045 length = tail - *ptr;
1047 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
1051 if (lmd->lmd_mgs != NULL)
1052 oldlen = strlen(lmd->lmd_mgs) + 1;
1054 OBD_ALLOC(mgsnid, oldlen + length + 1);
1058 if (lmd->lmd_mgs != NULL) {
1059 /* Multiple mgsnid= are taken to mean failover locations */
1060 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
1061 mgsnid[oldlen - 1] = ':';
1062 OBD_FREE(lmd->lmd_mgs, oldlen);
1064 memcpy(mgsnid + oldlen, *ptr, length);
1065 mgsnid[oldlen + length] = '\0';
1066 lmd->lmd_mgs = mgsnid;
1073 * Find the first delimiter (comma or colon) from the specified \a buf and
1074 * make \a *endh point to the string starting with the delimiter. The commas
1075 * in expression list [...] will be skipped.
1077 * \param[in] buf a delimiter-separated string
1078 * \param[in] endh a pointer to a pointer that will point to the string
1079 * starting with the delimiter
1081 * \retval 0 if delimiter is found
1082 * \retval 1 if delimiter is not found
1084 static int lmd_find_delimiter(char *buf, char **endh)
1092 while (*c != '\0') {
1098 if ((*c == ',' || *c == ':') && skip == 0) {
1111 * Find the first valid string delimited by comma or colon from the specified
1112 * \a buf and parse it to see whether it's a valid nid list. If yes, \a *endh
1113 * will point to the next string starting with the delimiter.
1115 * \param[in] buf a delimiter-separated string
1116 * \param[in] endh a pointer to a pointer that will point to the string
1117 * starting with the delimiter
1119 * \retval 0 if the string is a valid nid list
1120 * \retval 1 if the string is not a valid nid list
1122 static int lmd_parse_nidlist(char *buf, char **endh)
1124 struct list_head nidlist;
1131 while (*buf == ',' || *buf == ':')
1133 if (*buf == ' ' || *buf == '/' || *buf == '\0')
1136 if (lmd_find_delimiter(buf, &endp) != 0)
1137 endp = buf + strlen(buf);
1142 INIT_LIST_HEAD(&nidlist);
1143 if (cfs_parse_nidlist(buf, strlen(buf), &nidlist) <= 0)
1145 cfs_free_nidlist(&nidlist);
1155 /** Parse mount line options
1156 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
1157 * dev is passed as device=uml1:/lustre by mount.lustre
1159 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
1161 char *s1, *s2, *s3, *devname = NULL;
1162 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
1168 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that "
1169 "/sbin/mount.lustre is installed.\n");
1173 /* Options should be a string - try to detect old lmd data */
1174 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1175 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of "
1176 "/sbin/mount.lustre. Please install "
1177 "version %s\n", LUSTRE_VERSION_STRING);
1180 lmd->lmd_magic = LMD_MAGIC;
1182 OBD_ALLOC(lmd->lmd_params, LMD_PARAMS_MAXLEN);
1183 if (lmd->lmd_params == NULL)
1185 lmd->lmd_params[0] = '\0';
1187 /* Set default flags here */
1192 int time_min = OBD_RECOVERY_TIME_MIN;
1194 /* Skip whitespace and extra commas */
1195 while (*s1 == ' ' || *s1 == ',')
1199 /* Client options are parsed in ll_options: eg. flock,
1202 /* Parse non-ldiskfs options here. Rather than modifying
1203 ldiskfs, we just zero these out here */
1204 if (strncmp(s1, "abort_recov", 11) == 0) {
1205 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
1207 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
1208 lmd->lmd_recovery_time_soft =
1209 max_t(int, simple_strtoul(s1 + 19, NULL, 10),
1212 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
1213 lmd->lmd_recovery_time_hard =
1214 max_t(int, simple_strtoul(s1 + 19, NULL, 10),
1217 } else if (strncmp(s1, "noir", 4) == 0) {
1218 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
1220 } else if (strncmp(s1, "nosvc", 5) == 0) {
1221 lmd->lmd_flags |= LMD_FLG_NOSVC;
1223 } else if (strncmp(s1, "nomgs", 5) == 0) {
1224 lmd->lmd_flags |= LMD_FLG_NOMGS;
1226 } else if (strncmp(s1, "noscrub", 7) == 0) {
1227 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
1229 } else if (strncmp(s1, "skip_lfsck", 10) == 0) {
1230 lmd->lmd_flags |= LMD_FLG_SKIP_LFSCK;
1232 } else if (strncmp(s1, PARAM_MGSNODE,
1233 sizeof(PARAM_MGSNODE) - 1) == 0) {
1234 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
1235 /* Assume the next mount opt is the first
1236 invalid nid we get to. */
1237 rc = lmd_parse_mgs(lmd, &s2);
1242 } else if (strncmp(s1, "writeconf", 9) == 0) {
1243 lmd->lmd_flags |= LMD_FLG_WRITECONF;
1245 } else if (strncmp(s1, "update", 6) == 0) {
1246 lmd->lmd_flags |= LMD_FLG_UPDATE;
1248 } else if (strncmp(s1, "virgin", 6) == 0) {
1249 lmd->lmd_flags |= LMD_FLG_VIRGIN;
1251 } else if (strncmp(s1, "noprimnode", 10) == 0) {
1252 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
1254 } else if (strncmp(s1, "mgssec=", 7) == 0) {
1255 rc = lmd_parse_mgssec(lmd, s1 + 7);
1259 /* ost exclusion list */
1260 } else if (strncmp(s1, "exclude=", 8) == 0) {
1261 rc = lmd_make_exclusion(lmd, s1 + 7);
1265 } else if (strncmp(s1, "mgs", 3) == 0) {
1267 lmd->lmd_flags |= LMD_FLG_MGS;
1269 } else if (strncmp(s1, "svname=", 7) == 0) {
1270 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
1274 } else if (strncmp(s1, "param=", 6) == 0) {
1275 size_t length, params_length;
1277 if (lmd_find_delimiter(s1 + 6, &tail) != 0)
1278 length = strlen(s1);
1280 char *param_str = tail + 1;
1281 int supplementary = 1;
1282 while (lmd_parse_nidlist(param_str,
1286 length = param_str - s1 - supplementary;
1289 params_length = strlen(lmd->lmd_params);
1290 if (params_length + length + 1 >= LMD_PARAMS_MAXLEN)
1292 strncat(lmd->lmd_params, s1 + 6, length);
1293 lmd->lmd_params[params_length + length] = '\0';
1294 strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
1295 s3 = s1 + 6 + length;
1297 } else if (strncmp(s1, "osd=", 4) == 0) {
1298 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1303 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1304 end of the options. */
1305 else if (strncmp(s1, "device=", 7) == 0) {
1307 /* terminate options right before device. device
1308 must be the last one. */
1311 } else if (strncmp(s1, "network=", 8) == 0) {
1312 rc = lmd_parse_network(lmd, s1 + 8);
1319 s2 = strchr(s3, ',');
1327 memmove(s1, s2, strlen(s2) + 1);
1333 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name "
1334 "(need mount option 'device=...')\n");
1338 s1 = strstr(devname, ":/");
1341 lmd->lmd_flags |= LMD_FLG_CLIENT;
1342 /* Remove leading /s from fsname */
1343 while (*++s1 == '/')
1346 while (*s2 != '/' && *s2 != '\0')
1348 /* Freed in lustre_free_lsi */
1349 OBD_ALLOC(lmd->lmd_profile, s2 - s1 + 8);
1350 if (!lmd->lmd_profile)
1353 strncat(lmd->lmd_profile, s1, s2 - s1);
1354 strncat(lmd->lmd_profile, "-client", 7);
1357 s2 = s1 + strlen(s1) - 1;
1358 /* Remove padding /s from fileset */
1362 OBD_ALLOC(lmd->lmd_fileset, s2 - s1 + 2);
1363 if (lmd->lmd_fileset == NULL) {
1364 OBD_FREE(lmd->lmd_profile,
1365 strlen(lmd->lmd_profile) + 1);
1368 strncat(lmd->lmd_fileset, s1, s2 - s1 + 1);
1372 if (lmd->lmd_nidnet != NULL) {
1373 /* 'network=' mount option forbidden for server */
1374 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
1375 lmd->lmd_nidnet = NULL;
1377 CERROR("%s: option 'network=' not allowed for Lustre "
1378 "servers: rc = %d\n", devname, rc);
1383 /* Freed in lustre_free_lsi */
1384 OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
1387 strncpy(lmd->lmd_dev, devname, strlen(devname)+1);
1389 /* Save mount options */
1390 s1 = options + strlen(options) - 1;
1391 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1393 if (*options != 0) {
1394 /* Freed in lustre_free_lsi */
1395 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
1398 strncpy(lmd->lmd_opts, options, strlen(options)+1);
1402 lmd->lmd_magic = LMD_MAGIC;
1407 CERROR("Bad mount options %s\n", options);
1411 struct lustre_mount_data2 {
1413 struct vfsmount *lmd2_mnt;
1416 /** This is the entry point for the mount call into Lustre.
1417 * This is called when a server or client is mounted,
1418 * and this is where we start setting things up.
1419 * @param data Mount options (e.g. -o flock,abort_recov)
1421 static int lustre_fill_super(struct super_block *sb, void *data, int silent)
1423 struct lustre_mount_data *lmd;
1424 struct lustre_mount_data2 *lmd2 = data;
1425 struct lustre_sb_info *lsi;
1429 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
1431 lsi = lustre_init_lsi(sb);
1437 * Disable lockdep during mount, because mount locking patterns are
1443 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1445 obd_zombie_barrier();
1447 /* Figure out the lmd from the mount options */
1448 if (lmd_parse((char *)(lmd2->lmd2_data), lmd)) {
1450 GOTO(out, rc = -EINVAL);
1453 if (lmd_is_client(lmd)) {
1454 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1455 if (client_fill_super == NULL)
1456 request_module("lustre");
1457 if (client_fill_super == NULL) {
1458 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for "
1459 "client mount! Is the 'lustre' "
1460 "module loaded?\n");
1464 rc = lustre_start_mgc(sb);
1466 lustre_common_put_super(sb);
1469 /* Connect and start */
1470 /* (should always be ll_fill_super) */
1471 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1472 /* c_f_s will call lustre_common_put_super on failure */
1475 #ifdef HAVE_SERVER_SUPPORT
1476 CDEBUG(D_MOUNT, "Mounting server from %s\n", lmd->lmd_dev);
1477 rc = server_fill_super(sb);
1478 /* s_f_s calls lustre_start_mgc after the mount because we need
1479 the MGS nids which are stored on disk. Plus, we may
1480 need to start the MGS first. */
1481 /* s_f_s will call server_put_super on failure */
1483 CERROR("This is client-side-only module, "
1484 "cannot handle server mount.\n");
1489 /* If error happens in fill_super() call, @lsi will be killed there.
1490 * This is why we do not put it here. */
1494 CERROR("Unable to mount %s (%d)\n",
1495 s2lsi(sb) ? lmd->lmd_dev : "", rc);
1497 CDEBUG(D_SUPER, "Mount %s complete\n",
1505 /* We can't call ll_fill_super by name because it lives in a module that
1506 must be loaded after this one. */
1507 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1508 struct vfsmount *mnt))
1510 client_fill_super = cfs;
1512 EXPORT_SYMBOL(lustre_register_client_fill_super);
1514 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1516 kill_super_cb = cfs;
1518 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1520 /***************** FS registration ******************/
1521 #ifdef HAVE_FSTYPE_MOUNT
1522 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1523 const char *devname, void *data)
1525 struct lustre_mount_data2 lmd2 = { data, NULL };
1527 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1530 static int lustre_get_sb(struct file_system_type *fs_type, int flags,
1531 const char *devname, void *data, struct vfsmount *mnt)
1533 struct lustre_mount_data2 lmd2 = { data, mnt };
1535 return get_sb_nodev(fs_type, flags, &lmd2, lustre_fill_super, mnt);
1539 static void lustre_kill_super(struct super_block *sb)
1541 struct lustre_sb_info *lsi = s2lsi(sb);
1543 if (kill_super_cb && lsi && !IS_SERVER(lsi))
1544 (*kill_super_cb)(sb);
1546 kill_anon_super(sb);
1549 /** Register the "lustre" fs type
1551 static struct file_system_type lustre_fs_type = {
1552 .owner = THIS_MODULE,
1554 #ifdef HAVE_FSTYPE_MOUNT
1555 .mount = lustre_mount,
1557 .get_sb = lustre_get_sb,
1559 .kill_sb = lustre_kill_super,
1560 .fs_flags = FS_REQUIRES_DEV | FS_HAS_FIEMAP | FS_RENAME_DOES_D_MOVE,
1562 MODULE_ALIAS_FS("lustre");
1564 int lustre_register_fs(void)
1566 return register_filesystem(&lustre_fs_type);
1569 int lustre_unregister_fs(void)
1571 return unregister_filesystem(&lustre_fs_type);