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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/obd_mount.c
38 * Client mount routines
40 * Author: Nathan Rutman <nathan@clusterfs.com>
44 #define DEBUG_SUBSYSTEM S_CLASS
45 #define D_MOUNT (D_SUPER|D_CONFIG/*|D_WARNING */)
46 #define PRINT_CMD CDEBUG
49 #include <obd_class.h>
50 #include <lustre/lustre_user.h>
51 #include <linux/version.h>
52 #include <lustre_log.h>
53 #include <lustre_disk.h>
54 #include <lustre_param.h>
56 static int (*client_fill_super)(struct super_block *sb,
57 struct vfsmount *mnt);
59 static void (*kill_super_cb)(struct super_block *sb);
61 /**************** config llog ********************/
63 /** Get a config log from the MGS and process it.
64 * This func is called for both clients and servers.
65 * Continue to process new statements appended to the logs
66 * (whenever the config lock is revoked) until lustre_end_log
68 * @param sb The superblock is used by the MGC to write to the local copy of
70 * @param logname The name of the llog to replicate from the MGS
71 * @param cfg Since the same mgc may be used to follow multiple config logs
72 * (e.g. ost1, ost2, client), the config_llog_instance keeps the state for
73 * this log, and is added to the mgc's list of logs to follow.
75 int lustre_process_log(struct super_block *sb, char *logname,
76 struct config_llog_instance *cfg)
78 struct lustre_cfg *lcfg;
79 struct lustre_cfg_bufs *bufs;
80 struct lustre_sb_info *lsi = s2lsi(sb);
81 struct obd_device *mgc = lsi->lsi_mgc;
92 /* mgc_process_config */
93 lustre_cfg_bufs_reset(bufs, mgc->obd_name);
94 lustre_cfg_bufs_set_string(bufs, 1, logname);
95 lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
96 lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
97 lcfg = lustre_cfg_new(LCFG_LOG_START, bufs);
98 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
99 lustre_cfg_free(lcfg);
104 LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s'"
105 "failed from the MGS (%d). Make sure this "
106 "client and the MGS are running compatible "
107 "versions of Lustre.\n",
108 mgc->obd_name, logname, rc);
111 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' "
112 "failed (%d). This may be the result of "
113 "communication errors between this node and "
114 "the MGS, a bad configuration, or other "
115 "errors. See the syslog for more "
116 "information.\n", mgc->obd_name, logname,
119 /* class_obd_list(); */
122 EXPORT_SYMBOL(lustre_process_log);
124 /* Stop watching this config log for updates */
125 int lustre_end_log(struct super_block *sb, char *logname,
126 struct config_llog_instance *cfg)
128 struct lustre_cfg *lcfg;
129 struct lustre_cfg_bufs bufs;
130 struct lustre_sb_info *lsi = s2lsi(sb);
131 struct obd_device *mgc = lsi->lsi_mgc;
138 /* mgc_process_config */
139 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
140 lustre_cfg_bufs_set_string(&bufs, 1, logname);
142 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
143 lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
144 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
145 lustre_cfg_free(lcfg);
148 EXPORT_SYMBOL(lustre_end_log);
150 /**************** obd start *******************/
152 /** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
153 * lctl (and do for echo cli/srv.
155 int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
156 char *s1, char *s2, char *s3, char *s4)
158 struct lustre_cfg_bufs bufs;
159 struct lustre_cfg * lcfg = NULL;
162 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
163 cmd, s1, s2, s3, s4);
165 lustre_cfg_bufs_reset(&bufs, cfgname);
167 lustre_cfg_bufs_set_string(&bufs, 1, s1);
169 lustre_cfg_bufs_set_string(&bufs, 2, s2);
171 lustre_cfg_bufs_set_string(&bufs, 3, s3);
173 lustre_cfg_bufs_set_string(&bufs, 4, s4);
175 lcfg = lustre_cfg_new(cmd, &bufs);
176 lcfg->lcfg_nid = nid;
177 rc = class_process_config(lcfg);
178 lustre_cfg_free(lcfg);
181 EXPORT_SYMBOL(do_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, 0, 0);
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, 0, 0, 0, 0);
205 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 *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
225 int rc = 0, i = 0, j, len;
228 LASSERT(lsi->lsi_lmd);
230 /* Find the first non-lo MGS nid for our MGC name */
231 if (IS_SERVER(lsi)) {
232 /* mount -o mgsnode=nid */
233 ptr = lsi->lsi_lmd->lmd_mgs;
234 if (lsi->lsi_lmd->lmd_mgs &&
235 (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) {
237 } else if (IS_MGS(lsi)) {
238 lnet_process_id_t id;
239 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
240 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
247 } else { /* client */
248 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
249 ptr = lsi->lsi_lmd->lmd_dev;
250 if (class_parse_nid(ptr, &nid, &ptr) == 0)
254 CERROR("No valid MGS nids found.\n");
258 mutex_lock(&mgc_start_lock);
260 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
261 OBD_ALLOC(mgcname, len);
262 OBD_ALLOC(niduuid, len + 2);
263 if (!mgcname || !niduuid)
264 GOTO(out_free, rc = -ENOMEM);
265 sprintf(mgcname, "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
267 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
271 GOTO(out_free, rc = -ENOMEM);
273 obd = class_name2obd(mgcname);
274 if (obd && !obd->obd_stopping) {
275 rc = obd_set_info_async(NULL, obd->obd_self_export,
276 strlen(KEY_MGSSEC), KEY_MGSSEC,
277 strlen(mgssec), mgssec, NULL);
281 /* Re-using an existing MGC */
282 cfs_atomic_inc(&obd->u.cli.cl_mgc_refcount);
284 /* IR compatibility check, only for clients */
285 if (lmd_is_client(lsi->lsi_lmd)) {
287 int vallen = sizeof(*data);
288 __u32 *flags = &lsi->lsi_lmd->lmd_flags;
290 rc = obd_get_info(NULL, obd->obd_self_export,
291 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
292 &vallen, data, NULL);
294 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
295 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
296 /* LMD_FLG_NOIR is for test purpose only */
298 "Trying to mount a client with IR setting "
299 "not compatible with current mgc. "
300 "Force to use current mgc setting that is "
302 has_ir ? "enabled" : "disabled");
304 *flags &= ~LMD_FLG_NOIR;
306 *flags |= LMD_FLG_NOIR;
311 /* If we are restarting the MGS, don't try to keep the MGC's
312 old connection, or registration will fail. */
314 CDEBUG(D_MOUNT, "New MGS with live MGC\n");
318 /* Try all connections, but only once (again).
319 We don't want to block another target from starting
320 (using its local copy of the log), but we do want to connect
321 if at all possible. */
323 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,recov_bk);
324 rc = obd_set_info_async(NULL, obd->obd_self_export,
325 sizeof(KEY_INIT_RECOV_BACKUP),
326 KEY_INIT_RECOV_BACKUP,
327 sizeof(recov_bk), &recov_bk, NULL);
331 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
333 /* Add the primary nids for the MGS */
335 sprintf(niduuid, "%s_%x", mgcname, i);
336 if (IS_SERVER(lsi)) {
337 ptr = lsi->lsi_lmd->lmd_mgs;
338 CDEBUG(D_MOUNT, "mgs nids %s.\n", ptr);
340 /* Use local nids (including LO) */
341 lnet_process_id_t id;
342 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
343 rc = do_lcfg(mgcname, id.nid, LCFG_ADD_UUID,
347 /* Use mgsnode= nids */
348 /* mount -o mgsnode=nid */
349 if (lsi->lsi_lmd->lmd_mgs) {
350 ptr = lsi->lsi_lmd->lmd_mgs;
351 } else if (class_find_param(ptr, PARAM_MGSNODE,
353 CERROR("No MGS nids given.\n");
354 GOTO(out_free, rc = -EINVAL);
358 * Here we only take the first mgsnid as its primary
359 * serving mgs node, the rest mgsnid will be taken as
360 * failover mgs node, otherwise they would be takens
361 * as multiple nids of a single mgs node.
363 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
364 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
372 } else { /* client */
373 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
374 ptr = lsi->lsi_lmd->lmd_dev;
375 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
376 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
380 /* Stop at the first failover nid */
386 CERROR("No valid MGS nids found.\n");
387 GOTO(out_free, rc = -EINVAL);
389 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
391 /* Random uuid for MGC allows easier reconnects */
393 ll_generate_random_uuid(uuidc);
394 class_uuid_unparse(uuidc, uuid);
397 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
398 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
404 /* Add any failover MGS nids */
406 while (ptr && ((*ptr == ':' ||
407 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
408 /* New failover node */
409 sprintf(niduuid, "%s_%x", mgcname, i);
411 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
412 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
420 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
429 lsi->lsi_lmd->lmd_mgs_failnodes = i;
431 obd = class_name2obd(mgcname);
433 CERROR("Can't find mgcobd %s\n", mgcname);
434 GOTO(out_free, rc = -ENOTCONN);
437 rc = obd_set_info_async(NULL, obd->obd_self_export,
438 strlen(KEY_MGSSEC), KEY_MGSSEC,
439 strlen(mgssec), mgssec, NULL);
443 /* Keep a refcount of servers/clients who started with "mount",
444 so we know when we can get rid of the mgc. */
445 cfs_atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
447 /* Try all connections, but only once. */
449 rc = obd_set_info_async(NULL, obd->obd_self_export,
450 sizeof(KEY_INIT_RECOV_BACKUP),
451 KEY_INIT_RECOV_BACKUP,
452 sizeof(recov_bk), &recov_bk, NULL);
455 CWARN("can't set %s %d\n", KEY_INIT_RECOV_BACKUP, rc);
457 /* We connect to the MGS at setup, and don't disconnect until cleanup */
458 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
459 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
460 OBD_CONNECT_LVB_TYPE;
462 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
463 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
465 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
468 if (lmd_is_client(lsi->lsi_lmd) &&
469 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
470 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
471 data->ocd_version = LUSTRE_VERSION_CODE;
472 rc = obd_connect(NULL, &exp, obd, &(obd->obd_uuid), data, NULL);
474 CERROR("connect failed %d\n", rc);
478 obd->u.cli.cl_mgc_mgsexp = exp;
481 /* Keep the mgc info in the sb. Note that many lsi's can point
485 mutex_unlock(&mgc_start_lock);
490 OBD_FREE(mgcname, len);
492 OBD_FREE(niduuid, len + 2);
496 static int lustre_stop_mgc(struct super_block *sb)
498 struct lustre_sb_info *lsi = s2lsi(sb);
499 struct obd_device *obd;
500 char *niduuid = 0, *ptr = 0;
501 int i, rc = 0, len = 0;
511 mutex_lock(&mgc_start_lock);
512 LASSERT(cfs_atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
513 if (!cfs_atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
514 /* This is not fatal, every client that stops
515 will call in here. */
516 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
517 cfs_atomic_read(&obd->u.cli.cl_mgc_refcount));
518 GOTO(out, rc = -EBUSY);
521 /* The MGC has no recoverable data in any case.
522 * force shotdown set in umount_begin */
523 obd->obd_no_recov = 1;
525 if (obd->u.cli.cl_mgc_mgsexp) {
526 /* An error is not fatal, if we are unable to send the
527 disconnect mgs ping evictor cleans up the export */
528 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
530 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
533 /* Save the obdname for cleaning the nid uuids, which are
535 len = strlen(obd->obd_name) + 6;
536 OBD_ALLOC(niduuid, len);
538 strcpy(niduuid, obd->obd_name);
539 ptr = niduuid + strlen(niduuid);
542 rc = class_manual_cleanup(obd);
546 /* Clean the nid uuids */
548 GOTO(out, rc = -ENOMEM);
550 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
551 sprintf(ptr, "_%x", i);
552 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
555 CERROR("del MDC UUID %s failed: rc = %d\n",
560 OBD_FREE(niduuid, len);
562 /* class_import_put will get rid of the additional connections */
563 mutex_unlock(&mgc_start_lock);
567 /***************** lustre superblock **************/
569 struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
571 struct lustre_sb_info *lsi;
577 OBD_ALLOC_PTR(lsi->lsi_lmd);
583 lsi->lsi_lmd->lmd_exclude_count = 0;
584 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
585 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
586 s2lsi_nocast(sb) = lsi;
587 /* we take 1 extra ref for our setup */
588 cfs_atomic_set(&lsi->lsi_mounts, 1);
590 /* Default umount style */
591 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
596 static int lustre_free_lsi(struct super_block *sb)
598 struct lustre_sb_info *lsi = s2lsi(sb);
601 LASSERT(lsi != NULL);
602 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
604 /* someone didn't call server_put_mount. */
605 LASSERT(cfs_atomic_read(&lsi->lsi_mounts) == 0);
607 if (lsi->lsi_lmd != NULL) {
608 if (lsi->lsi_lmd->lmd_dev != NULL)
609 OBD_FREE(lsi->lsi_lmd->lmd_dev,
610 strlen(lsi->lsi_lmd->lmd_dev) + 1);
611 if (lsi->lsi_lmd->lmd_profile != NULL)
612 OBD_FREE(lsi->lsi_lmd->lmd_profile,
613 strlen(lsi->lsi_lmd->lmd_profile) + 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);
633 OBD_FREE(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
636 LASSERT(lsi->lsi_llsbi == NULL);
637 OBD_FREE(lsi, sizeof(*lsi));
638 s2lsi_nocast(sb) = NULL;
643 /* The lsi has one reference for every server that is using the disk -
644 e.g. MDT, MGS, and potentially MGC */
645 int lustre_put_lsi(struct super_block *sb)
647 struct lustre_sb_info *lsi = s2lsi(sb);
650 LASSERT(lsi != NULL);
652 CDEBUG(D_MOUNT, "put %p %d\n", sb, cfs_atomic_read(&lsi->lsi_mounts));
653 if (cfs_atomic_dec_and_test(&lsi->lsi_mounts)) {
654 if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
655 lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
656 lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
657 lsi->lsi_dt_dev = NULL;
658 obd_disconnect(lsi->lsi_osd_exp);
659 /* wait till OSD is gone */
660 obd_zombie_barrier();
669 * <FSNAME><SEPERATOR><TYPE><INDEX>
670 * FSNAME is between 1 and 8 characters (inclusive).
671 * Excluded characters are '/' and ':'
672 * SEPERATOR is either ':' or '-'
673 * TYPE: "OST", "MDT", etc.
674 * INDEX: Hex representation of the index
677 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
678 * @param [in] svname server name including type and index
679 * @param [out] fsname Buffer to copy filesystem name prefix into.
680 * Must have at least 'strlen(fsname) + 1' chars.
681 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
684 int server_name2fsname(const char *svname, char *fsname, const char **endptr)
688 dash = svname + strnlen(svname, 8); /* max fsname length is 8 */
689 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
694 if (fsname != NULL) {
695 strncpy(fsname, svname, dash - svname);
696 fsname[dash - svname] = '\0';
704 EXPORT_SYMBOL(server_name2fsname);
707 * Get service name (svname) from string
709 * if endptr isn't NULL it is set to end of fsname *
711 int server_name2svname(const char *label, char *svname, const char **endptr,
717 /* We use server_name2fsname() just for parsing */
718 rc = server_name2fsname(label, NULL, &dash);
725 if (strlcpy(svname, dash + 1, svsize) >= svsize)
730 EXPORT_SYMBOL(server_name2svname);
733 * check server name is OST.
735 int server_name_is_ost(const char *svname)
740 /* We use server_name2fsname() just for parsing */
741 rc = server_name2fsname(svname, NULL, &dash);
747 if (strncmp(dash, "OST", 3) == 0)
751 EXPORT_SYMBOL(server_name_is_ost);
753 /* Get the index from the obd name.
756 if endptr isn't NULL it is set to end of name */
757 int server_name2index(const char *svname, __u32 *idx, const char **endptr)
763 /* We use server_name2fsname() just for parsing */
764 rc = server_name2fsname(svname, NULL, &dash);
770 if (strncmp(dash, "MDT", 3) == 0)
771 rc = LDD_F_SV_TYPE_MDT;
772 else if (strncmp(dash, "OST", 3) == 0)
773 rc = LDD_F_SV_TYPE_OST;
779 if (strncmp(dash, "all", 3) == 0) {
782 return rc | LDD_F_SV_ALL;
785 index = simple_strtoul(dash, (char **)endptr, 16);
789 /* Account for -mdc after index that is possible when specifying mdt */
790 if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
791 sizeof(LUSTRE_MDC_NAME)-1) == 0)
792 *endptr += sizeof(LUSTRE_MDC_NAME);
796 EXPORT_SYMBOL(server_name2index);
798 /*************** mount common betweeen server and client ***************/
801 int lustre_common_put_super(struct super_block *sb)
806 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
808 /* Drop a ref to the MGC */
809 rc = lustre_stop_mgc(sb);
810 if (rc && (rc != -ENOENT)) {
812 CERROR("Can't stop MGC: %d\n", rc);
815 /* BUSY just means that there's some other obd that
816 needs the mgc. Let him clean it up. */
817 CDEBUG(D_MOUNT, "MGC still in use\n");
819 /* Drop a ref to the mounted disk */
824 EXPORT_SYMBOL(lustre_common_put_super);
826 static void lmd_print(struct lustre_mount_data *lmd)
830 PRINT_CMD(D_MOUNT, " mount data:\n");
831 if (lmd_is_client(lmd))
832 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
833 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
834 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
837 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
839 if (lmd->lmd_recovery_time_soft)
840 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
841 lmd->lmd_recovery_time_soft);
843 if (lmd->lmd_recovery_time_hard)
844 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
845 lmd->lmd_recovery_time_hard);
847 for (i = 0; i < lmd->lmd_exclude_count; i++) {
848 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
849 lmd->lmd_exclude[i]);
853 /* Is this server on the exclusion list */
854 int lustre_check_exclusion(struct super_block *sb, char *svname)
856 struct lustre_sb_info *lsi = s2lsi(sb);
857 struct lustre_mount_data *lmd = lsi->lsi_lmd;
862 rc = server_name2index(svname, &index, NULL);
863 if (rc != LDD_F_SV_TYPE_OST)
864 /* Only exclude OSTs */
867 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
868 index, lmd->lmd_exclude_count, lmd->lmd_dev);
870 for(i = 0; i < lmd->lmd_exclude_count; i++) {
871 if (index == lmd->lmd_exclude[i]) {
872 CWARN("Excluding %s (on exclusion list)\n", svname);
879 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
880 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
882 const char *s1 = ptr, *s2;
883 __u32 index, *exclude_list;
887 /* The shortest an ost name can be is 8 chars: -OST0000.
888 We don't actually know the fsname at this time, so in fact
889 a user could specify any fsname. */
890 devmax = strlen(ptr) / 8 + 1;
892 /* temp storage until we figure out how many we have */
893 OBD_ALLOC(exclude_list, sizeof(index) * devmax);
897 /* we enter this fn pointing at the '=' */
898 while (*s1 && *s1 != ' ' && *s1 != ',') {
900 rc = server_name2index(s1, &index, &s2);
902 CERROR("Can't parse server name '%s': rc = %d\n",
906 if (rc == LDD_F_SV_TYPE_OST)
907 exclude_list[lmd->lmd_exclude_count++] = index;
909 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
910 (uint)(s2-s1), s1, rc);
912 /* now we are pointing at ':' (next exclude)
913 or ',' (end of excludes) */
914 if (lmd->lmd_exclude_count >= devmax)
917 if (rc >= 0) /* non-err */
920 if (lmd->lmd_exclude_count) {
921 /* permanent, freed in lustre_free_lsi */
922 OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
923 lmd->lmd_exclude_count);
924 if (lmd->lmd_exclude) {
925 memcpy(lmd->lmd_exclude, exclude_list,
926 sizeof(index) * lmd->lmd_exclude_count);
929 lmd->lmd_exclude_count = 0;
932 OBD_FREE(exclude_list, sizeof(index) * devmax);
936 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
941 if (lmd->lmd_mgssec != NULL) {
942 OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
943 lmd->lmd_mgssec = NULL;
946 tail = strchr(ptr, ',');
948 length = strlen(ptr);
952 OBD_ALLOC(lmd->lmd_mgssec, length + 1);
953 if (lmd->lmd_mgssec == NULL)
956 memcpy(lmd->lmd_mgssec, ptr, length);
957 lmd->lmd_mgssec[length] = '\0';
961 static int lmd_parse_string(char **handle, char *ptr)
966 if ((handle == NULL) || (ptr == NULL))
969 if (*handle != NULL) {
970 OBD_FREE(*handle, strlen(*handle) + 1);
974 tail = strchr(ptr, ',');
976 length = strlen(ptr);
980 OBD_ALLOC(*handle, length + 1);
984 memcpy(*handle, ptr, length);
985 (*handle)[length] = '\0';
990 /* Collect multiple values for mgsnid specifiers */
991 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
999 /* Find end of nidlist */
1000 while (class_parse_nid_quiet(tail, &nid, &tail) == 0) {}
1001 length = tail - *ptr;
1003 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
1007 if (lmd->lmd_mgs != NULL)
1008 oldlen = strlen(lmd->lmd_mgs) + 1;
1010 OBD_ALLOC(mgsnid, oldlen + length + 1);
1014 if (lmd->lmd_mgs != NULL) {
1015 /* Multiple mgsnid= are taken to mean failover locations */
1016 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
1017 mgsnid[oldlen - 1] = ':';
1018 OBD_FREE(lmd->lmd_mgs, oldlen);
1020 memcpy(mgsnid + oldlen, *ptr, length);
1021 mgsnid[oldlen + length] = '\0';
1022 lmd->lmd_mgs = mgsnid;
1028 /** Parse mount line options
1029 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
1030 * dev is passed as device=uml1:/lustre by mount.lustre
1032 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
1034 char *s1, *s2, *devname = NULL;
1035 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
1041 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that "
1042 "/sbin/mount.lustre is installed.\n");
1046 /* Options should be a string - try to detect old lmd data */
1047 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1048 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of "
1049 "/sbin/mount.lustre. Please install "
1050 "version %s\n", LUSTRE_VERSION_STRING);
1053 lmd->lmd_magic = LMD_MAGIC;
1055 OBD_ALLOC(lmd->lmd_params, 4096);
1056 if (lmd->lmd_params == NULL)
1058 lmd->lmd_params[0] = '\0';
1060 /* Set default flags here */
1065 int time_min = OBD_RECOVERY_TIME_MIN;
1067 /* Skip whitespace and extra commas */
1068 while (*s1 == ' ' || *s1 == ',')
1071 /* Client options are parsed in ll_options: eg. flock,
1074 /* Parse non-ldiskfs options here. Rather than modifying
1075 ldiskfs, we just zero these out here */
1076 if (strncmp(s1, "abort_recov", 11) == 0) {
1077 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
1079 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
1080 lmd->lmd_recovery_time_soft = max_t(int,
1081 simple_strtoul(s1 + 19, NULL, 10), time_min);
1083 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
1084 lmd->lmd_recovery_time_hard = max_t(int,
1085 simple_strtoul(s1 + 19, NULL, 10), time_min);
1087 } else if (strncmp(s1, "noir", 4) == 0) {
1088 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
1090 } else if (strncmp(s1, "nosvc", 5) == 0) {
1091 lmd->lmd_flags |= LMD_FLG_NOSVC;
1093 } else if (strncmp(s1, "nomgs", 5) == 0) {
1094 lmd->lmd_flags |= LMD_FLG_NOMGS;
1096 } else if (strncmp(s1, "noscrub", 7) == 0) {
1097 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
1099 } else if (strncmp(s1, PARAM_MGSNODE,
1100 sizeof(PARAM_MGSNODE) - 1) == 0) {
1101 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
1102 /* Assume the next mount opt is the first
1103 invalid nid we get to. */
1104 rc = lmd_parse_mgs(lmd, &s2);
1108 } else if (strncmp(s1, "writeconf", 9) == 0) {
1109 lmd->lmd_flags |= LMD_FLG_WRITECONF;
1111 } else if (strncmp(s1, "update", 6) == 0) {
1112 lmd->lmd_flags |= LMD_FLG_UPDATE;
1114 } else if (strncmp(s1, "virgin", 6) == 0) {
1115 lmd->lmd_flags |= LMD_FLG_VIRGIN;
1117 } else if (strncmp(s1, "noprimnode", 10) == 0) {
1118 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
1120 } else if (strncmp(s1, "mgssec=", 7) == 0) {
1121 rc = lmd_parse_mgssec(lmd, s1 + 7);
1125 /* ost exclusion list */
1126 } else if (strncmp(s1, "exclude=", 8) == 0) {
1127 rc = lmd_make_exclusion(lmd, s1 + 7);
1131 } else if (strncmp(s1, "mgs", 3) == 0) {
1133 lmd->lmd_flags |= LMD_FLG_MGS;
1135 } else if (strncmp(s1, "svname=", 7) == 0) {
1136 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
1140 } else if (strncmp(s1, "param=", 6) == 0) {
1142 char *tail = strchr(s1 + 6, ',');
1144 length = strlen(s1);
1148 strncat(lmd->lmd_params, s1 + 6, length);
1149 strcat(lmd->lmd_params, " ");
1151 } else if (strncmp(s1, "osd=", 4) == 0) {
1152 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1157 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1158 end of the options. */
1159 else if (strncmp(s1, "device=", 7) == 0) {
1161 /* terminate options right before device. device
1162 must be the last one. */
1168 s2 = strchr(s1, ',');
1176 memmove(s1, s2, strlen(s2) + 1);
1182 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name "
1183 "(need mount option 'device=...')\n");
1187 s1 = strstr(devname, ":/");
1190 lmd->lmd_flags |= LMD_FLG_CLIENT;
1191 /* Remove leading /s from fsname */
1192 while (*++s1 == '/') ;
1193 /* Freed in lustre_free_lsi */
1194 OBD_ALLOC(lmd->lmd_profile, strlen(s1) + 8);
1195 if (!lmd->lmd_profile)
1197 sprintf(lmd->lmd_profile, "%s-client", s1);
1200 /* Freed in lustre_free_lsi */
1201 OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
1204 strcpy(lmd->lmd_dev, devname);
1206 /* Save mount options */
1207 s1 = options + strlen(options) - 1;
1208 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1210 if (*options != 0) {
1211 /* Freed in lustre_free_lsi */
1212 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
1215 strcpy(lmd->lmd_opts, options);
1219 lmd->lmd_magic = LMD_MAGIC;
1224 CERROR("Bad mount options %s\n", options);
1228 struct lustre_mount_data2 {
1230 struct vfsmount *lmd2_mnt;
1233 /** This is the entry point for the mount call into Lustre.
1234 * This is called when a server or client is mounted,
1235 * and this is where we start setting things up.
1236 * @param data Mount options (e.g. -o flock,abort_recov)
1238 int lustre_fill_super(struct super_block *sb, void *data, int silent)
1240 struct lustre_mount_data *lmd;
1241 struct lustre_mount_data2 *lmd2 = data;
1242 struct lustre_sb_info *lsi;
1246 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
1248 lsi = lustre_init_lsi(sb);
1254 * Disable lockdep during mount, because mount locking patterns are
1260 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1262 obd_zombie_barrier();
1264 /* Figure out the lmd from the mount options */
1265 if (lmd_parse((char *)(lmd2->lmd2_data), lmd)) {
1267 GOTO(out, rc = -EINVAL);
1270 if (lmd_is_client(lmd)) {
1271 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1272 if (!client_fill_super) {
1273 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for "
1274 "client mount! Is the 'lustre' "
1275 "module loaded?\n");
1279 rc = lustre_start_mgc(sb);
1284 /* Connect and start */
1285 /* (should always be ll_fill_super) */
1286 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1287 /* c_f_s will call lustre_common_put_super on failure */
1290 #ifdef HAVE_SERVER_SUPPORT
1291 CDEBUG(D_MOUNT, "Mounting server from %s\n", lmd->lmd_dev);
1292 rc = server_fill_super(sb);
1293 /* s_f_s calls lustre_start_mgc after the mount because we need
1294 the MGS nids which are stored on disk. Plus, we may
1295 need to start the MGS first. */
1296 /* s_f_s will call server_put_super on failure */
1298 CERROR("This is client-side-only module, "
1299 "cannot handle server mount.\n");
1304 /* If error happens in fill_super() call, @lsi will be killed there.
1305 * This is why we do not put it here. */
1309 CERROR("Unable to mount %s (%d)\n",
1310 s2lsi(sb) ? lmd->lmd_dev : "", rc);
1312 CDEBUG(D_SUPER, "Mount %s complete\n",
1320 /* We can't call ll_fill_super by name because it lives in a module that
1321 must be loaded after this one. */
1322 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1323 struct vfsmount *mnt))
1325 client_fill_super = cfs;
1327 EXPORT_SYMBOL(lustre_register_client_fill_super);
1329 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1331 kill_super_cb = cfs;
1333 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1335 /***************** FS registration ******************/
1336 #ifdef HAVE_FSTYPE_MOUNT
1337 struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1338 const char *devname, void *data)
1340 struct lustre_mount_data2 lmd2 = { data, NULL };
1342 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1345 int lustre_get_sb(struct file_system_type *fs_type, int flags,
1346 const char *devname, void * data, struct vfsmount *mnt)
1348 struct lustre_mount_data2 lmd2 = { data, mnt };
1350 return get_sb_nodev(fs_type, flags, &lmd2, lustre_fill_super, mnt);
1354 void lustre_kill_super(struct super_block *sb)
1356 struct lustre_sb_info *lsi = s2lsi(sb);
1358 if (kill_super_cb && lsi && !IS_SERVER(lsi))
1359 (*kill_super_cb)(sb);
1361 kill_anon_super(sb);
1364 /** Register the "lustre" fs type
1366 struct file_system_type lustre_fs_type = {
1367 .owner = THIS_MODULE,
1369 #ifdef HAVE_FSTYPE_MOUNT
1370 .mount = lustre_mount,
1372 .get_sb = lustre_get_sb,
1374 .kill_sb = lustre_kill_super,
1375 .fs_flags = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV |
1376 FS_HAS_FIEMAP | FS_RENAME_DOES_D_MOVE,
1379 int lustre_register_fs(void)
1381 return register_filesystem(&lustre_fs_type);
1384 int lustre_unregister_fs(void)
1386 return unregister_filesystem(&lustre_fs_type);