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, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/obdclass/obd_mount.c
33 * Client mount routines
35 * Author: Nathan Rutman <nathan@clusterfs.com>
39 #define DEBUG_SUBSYSTEM S_CLASS
40 #define D_MOUNT (D_SUPER|D_CONFIG/*|D_WARNING */)
41 #define PRINT_CMD CDEBUG
44 #include <obd_class.h>
45 #include <linux/random.h>
46 #include <libcfs/linux/linux-uuid.h>
47 #include <linux/version.h>
48 #include <lustre_log.h>
49 #include <lustre_disk.h>
50 #include <uapi/linux/lustre/lustre_param.h>
51 #include <lustre_crypto.h>
53 /**************** config llog ********************/
56 * Get a config log from the MGS and process it.
57 * This func is called for both clients and servers.
58 * Continue to process new statements appended to the logs
59 * (whenever the config lock is revoked) until lustre_end_log
62 * @param sb The superblock is used by the MGC to write to the local copy of
64 * @param logname The name of the llog to replicate from the MGS
65 * @param cfg Since the same MGC may be used to follow multiple config logs
66 * (e.g. ost1, ost2, client), the config_llog_instance keeps the state for
67 * this log, and is added to the mgc's list of logs to follow.
69 int lustre_process_log(struct super_block *sb, char *logname,
70 struct config_llog_instance *cfg)
72 struct lustre_cfg *lcfg;
73 struct lustre_cfg_bufs *bufs;
74 struct lustre_sb_info *lsi = s2lsi(sb);
75 struct obd_device *mgc = lsi->lsi_mgc;
87 /* mgc_process_config */
88 lustre_cfg_bufs_reset(bufs, mgc->obd_name);
89 lustre_cfg_bufs_set_string(bufs, 1, logname);
90 lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
91 lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
92 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
94 GOTO(out, rc = -ENOMEM);
95 lustre_cfg_init(lcfg, LCFG_LOG_START, bufs);
97 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
98 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
103 LCONSOLE_ERROR_MSG(0x15b,
104 "%s: Configuration from log %s failed from MGS %d. Check client and MGS are on compatible version.\n",
105 mgc->obd_name, logname, rc);
107 LCONSOLE_ERROR_MSG(0x15c,
108 "%s: Confguration from log %s failed from MGS %d. Communication error between node & MGS, a bad configuration, or other errors. See syslog for more info\n",
109 mgc->obd_name, logname, rc);
111 /* class_obd_list(); */
114 EXPORT_SYMBOL(lustre_process_log);
116 /* Stop watching this config log for updates */
117 int lustre_end_log(struct super_block *sb, char *logname,
118 struct config_llog_instance *cfg)
120 struct lustre_cfg *lcfg;
121 struct lustre_cfg_bufs bufs;
122 struct lustre_sb_info *lsi = s2lsi(sb);
123 struct obd_device *mgc = lsi->lsi_mgc;
131 /* mgc_process_config */
132 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
133 lustre_cfg_bufs_set_string(&bufs, 1, logname);
135 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
136 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
139 lustre_cfg_init(lcfg, LCFG_LOG_END, &bufs);
140 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
141 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
144 EXPORT_SYMBOL(lustre_end_log);
146 /**************** OBD start *******************/
149 * lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
150 * lctl (and do for echo cli/srv.
152 static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
153 char *s1, char *s2, char *s3, char *s4)
155 struct lustre_cfg_bufs bufs;
156 struct lustre_cfg *lcfg = NULL;
159 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
160 cmd, s1, s2, s3, s4);
162 lustre_cfg_bufs_reset(&bufs, cfgname);
164 lustre_cfg_bufs_set_string(&bufs, 1, s1);
166 lustre_cfg_bufs_set_string(&bufs, 2, s2);
168 lustre_cfg_bufs_set_string(&bufs, 3, s3);
170 lustre_cfg_bufs_set_string(&bufs, 4, s4);
172 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
175 lustre_cfg_init(lcfg, cmd, &bufs);
176 lcfg->lcfg_nid = nid;
177 rc = class_process_config(lcfg);
178 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
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)
191 CDEBUG(D_MOUNT, "Starting OBD %s (typ=%s)\n", obdname, type);
193 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
195 CERROR("%s attach error %d\n", obdname, rc);
198 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
200 CERROR("%s setup error %d\n", obdname, rc);
201 do_lcfg(obdname, 0, LCFG_DETACH, NULL, NULL, NULL, NULL);
205 EXPORT_SYMBOL(lustre_start_simple);
207 static DEFINE_MUTEX(mgc_start_lock);
210 * Set up a MGC OBD to process startup logs
212 * \param sb [in] super block of the MGC OBD
214 * \retval 0 success, otherwise error code
216 int lustre_start_mgc(struct super_block *sb)
218 struct obd_connect_data *data = NULL;
219 struct lustre_sb_info *lsi = s2lsi(sb);
220 struct obd_device *obd;
221 struct obd_export *exp;
222 struct obd_uuid *uuid = NULL;
225 char nidstr[LNET_NIDSTR_SIZE];
226 char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
228 int rc = 0, i = 0, j;
233 LASSERT(lsi->lsi_lmd);
235 /* Find the first non-lo MGS NID for our MGC name */
236 if (IS_SERVER(lsi)) {
237 /* mount -o mgsnode=nid */
238 ptr = lsi->lsi_lmd->lmd_mgs;
239 if (lsi->lsi_lmd->lmd_mgs &&
240 (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) {
242 } else if (IS_MGS(lsi)) {
243 struct lnet_processid id;
245 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
246 if (nid_is_lo0(&id.nid))
248 nid = lnet_nid_to_nid4(&id.nid);
253 } else { /* client */
254 /* Use NIDs from mount line: uml1,1@elan:uml2,2@elan:/lustre */
255 ptr = lsi->lsi_lmd->lmd_dev;
256 if (class_parse_nid(ptr, &nid, &ptr) == 0)
260 CERROR("No valid MGS NIDs found.\n");
264 mutex_lock(&mgc_start_lock);
266 libcfs_nid2str_r(nid, nidstr, sizeof(nidstr));
267 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(nidstr) + 1;
268 OBD_ALLOC(mgcname, len);
269 OBD_ALLOC(niduuid, len + 2);
270 if (mgcname == NULL || niduuid == NULL)
271 GOTO(out_free, rc = -ENOMEM);
272 snprintf(mgcname, len, "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
274 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
278 GOTO(out_free, rc = -ENOMEM);
280 obd = class_name2obd(mgcname);
281 if (obd && !obd->obd_stopping) {
284 rc = obd_set_info_async(NULL, obd->obd_self_export,
285 strlen(KEY_MGSSEC), KEY_MGSSEC,
286 strlen(mgssec), mgssec, NULL);
290 /* Re-using an existing MGC */
291 atomic_inc(&obd->u.cli.cl_mgc_refcount);
293 /* IR compatibility check, only for clients */
294 if (lmd_is_client(lsi->lsi_lmd)) {
296 int vallen = sizeof(*data);
297 __u32 *flags = &lsi->lsi_lmd->lmd_flags;
299 rc = obd_get_info(NULL, obd->obd_self_export,
300 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
303 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
304 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
305 /* LMD_FLG_NOIR is for test purpose only */
307 "Mounting client with IR setting not compatible with current MGC. Using MGC setting that is IR %s",
308 has_ir ? "enabled" : "disabled");
310 *flags &= ~LMD_FLG_NOIR;
312 *flags |= LMD_FLG_NOIR;
318 * If we are restarting the MGS, don't try to keep the MGC's
319 * old connection, or registration will fail.
322 CDEBUG(D_MOUNT, "New MGS with live MGC\n");
327 * Try all connections, but only once (again).
328 * We don't want to block another target from starting
329 * (using its local copy of the log), but we do want to connect
330 * if at all possible.
333 CDEBUG(D_MOUNT, "%s:Set MGC reconnect %d\n", mgcname, recov_bk);
334 rc = obd_set_info_async(NULL, obd->obd_self_export,
335 sizeof(KEY_INIT_RECOV_BACKUP),
336 KEY_INIT_RECOV_BACKUP,
337 sizeof(recov_bk), &recov_bk, NULL);
341 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
343 /* Add the primary NIDs for the MGS */
345 snprintf(niduuid, len + 2, "%s_%x", mgcname, i);
346 if (IS_SERVER(lsi)) {
347 ptr = lsi->lsi_lmd->lmd_mgs;
348 CDEBUG(D_MOUNT, "mgs NIDs %s.\n", ptr);
350 /* Use local NIDs (including LO) */
351 struct lnet_processid id;
353 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
354 rc = do_lcfg(mgcname, lnet_nid_to_nid4(&id.nid),
356 niduuid, NULL, NULL, NULL);
359 /* Use mgsnode= nids */
360 /* mount -o mgsnode=nid */
361 if (lsi->lsi_lmd->lmd_mgs) {
362 ptr = lsi->lsi_lmd->lmd_mgs;
363 } else if (class_find_param(ptr, PARAM_MGSNODE,
365 CERROR("No MGS NIDs given.\n");
366 GOTO(out_free, rc = -EINVAL);
369 * Add primary MGS NID(s).
370 * Multiple NIDs on one MGS node are separated
373 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
374 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
375 niduuid, NULL, NULL, NULL);
378 /* Stop at the first failover NID */
383 } else { /* client */
384 /* Use NIDs from mount line: uml1,1@elan:uml2,2@elan:/lustre */
385 ptr = lsi->lsi_lmd->lmd_dev;
386 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
387 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
388 niduuid, NULL, NULL, NULL);
391 /* Stop at the first failover NID */
397 CERROR("No valid MGS NIDs found.\n");
398 GOTO(out_free, rc = -EINVAL);
400 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
402 /* Random uuid for MGC allows easier reconnects */
405 GOTO(out_free, rc = -ENOMEM);
407 generate_random_uuid(uuidc.b);
408 snprintf(uuid->uuid, sizeof(*uuid), "%pU", uuidc.b);
411 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
412 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
413 niduuid, NULL, NULL);
417 /* Add any failover MGS NIDs */
419 while (ptr && ((*ptr == ':' ||
420 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
421 /* New failover node */
422 sprintf(niduuid, "%s_%x", mgcname, i);
424 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
425 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
426 niduuid, NULL, NULL, NULL);
433 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
434 niduuid, NULL, NULL, NULL);
442 lsi->lsi_lmd->lmd_mgs_failnodes = i;
444 obd = class_name2obd(mgcname);
446 CERROR("Can't find mgcobd %s\n", mgcname);
447 GOTO(out_free, rc = -ENOTCONN);
450 rc = obd_set_info_async(NULL, obd->obd_self_export,
451 strlen(KEY_MGSSEC), KEY_MGSSEC,
452 strlen(mgssec), mgssec, NULL);
457 * Keep a refcount of servers/clients who started with "mount",
458 * so we know when we can get rid of the mgc.
460 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
462 /* We connect to the MGS at setup, and don't disconnect until cleanup */
463 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
464 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
465 OBD_CONNECT_LVB_TYPE |
466 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_BARRIER |
468 data->ocd_connect_flags2 = OBD_CONNECT2_REP_MBITS;
470 if (lmd_is_client(lsi->lsi_lmd) &&
471 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
472 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
473 data->ocd_version = LUSTRE_VERSION_CODE;
474 rc = obd_connect(NULL, &exp, obd, uuid, data, NULL);
476 CERROR("connect failed %d\n", rc);
480 obd->u.cli.cl_mgc_mgsexp = exp;
484 * Keep the MGC info in the sb. Note that many lsi's can point
489 mutex_unlock(&mgc_start_lock);
496 OBD_FREE(mgcname, len);
498 OBD_FREE(niduuid, len + 2);
501 EXPORT_SYMBOL(lustre_start_mgc);
503 static int lustre_stop_mgc(struct super_block *sb)
505 struct lustre_sb_info *lsi = s2lsi(sb);
506 struct obd_device *obd;
507 char niduuid[MAX_OBD_NAME + 6], *ptr = NULL;
519 mutex_lock(&mgc_start_lock);
520 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
521 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
523 * This is not fatal, every client that stops
526 CDEBUG(D_MOUNT, "MGC still has %d references.\n",
527 atomic_read(&obd->u.cli.cl_mgc_refcount));
528 GOTO(out, rc = -EBUSY);
532 * The MGC has no recoverable data in any case.
533 * force shotdown set in umount_begin
535 obd->obd_no_recov = 1;
537 if (obd->u.cli.cl_mgc_mgsexp) {
539 * An error is not fatal, if we are unable to send the
540 * disconnect mgs ping evictor cleans up the export
542 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
544 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
548 * Cache the obdname for cleaning the nid uuids, which are
549 * obdname_XX before calling class_manual_cleanup
551 strcpy(niduuid, obd->obd_name);
552 ptr = niduuid + strlen(niduuid);
554 rc = class_manual_cleanup(obd);
558 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
559 sprintf(ptr, "_%x", i);
560 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
561 niduuid, NULL, NULL, NULL);
563 CERROR("del MDC UUID %s failed: rc = %d\n",
567 /* class_import_put will get rid of the additional connections */
568 mutex_unlock(&mgc_start_lock);
572 /***************** lustre superblock **************/
574 struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
576 struct lustre_sb_info *lsi;
583 OBD_ALLOC_PTR(lsi->lsi_lmd);
589 s2lsi_nocast(sb) = lsi;
590 /* we take 1 extra ref for our setup */
591 atomic_set(&lsi->lsi_mounts, 1);
593 /* Default umount style */
594 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
595 INIT_LIST_HEAD(&lsi->lsi_lwp_list);
596 mutex_init(&lsi->lsi_lwp_mutex);
600 EXPORT_SYMBOL(lustre_init_lsi);
602 static int lustre_free_lsi(struct super_block *sb)
604 struct lustre_sb_info *lsi = s2lsi(sb);
608 LASSERT(lsi != NULL);
609 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
611 /* someone didn't call server_put_mount. */
612 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
615 if (lsi->lsi_lmd != NULL) {
616 if (lsi->lsi_lmd->lmd_dev != NULL)
617 OBD_FREE(lsi->lsi_lmd->lmd_dev,
618 strlen(lsi->lsi_lmd->lmd_dev) + 1);
619 if (lsi->lsi_lmd->lmd_profile != NULL)
620 OBD_FREE(lsi->lsi_lmd->lmd_profile,
621 strlen(lsi->lsi_lmd->lmd_profile) + 1);
622 if (lsi->lsi_lmd->lmd_fileset != NULL)
623 OBD_FREE(lsi->lsi_lmd->lmd_fileset,
624 strlen(lsi->lsi_lmd->lmd_fileset) + 1);
625 if (lsi->lsi_lmd->lmd_mgssec != NULL)
626 OBD_FREE(lsi->lsi_lmd->lmd_mgssec,
627 strlen(lsi->lsi_lmd->lmd_mgssec) + 1);
628 if (lsi->lsi_lmd->lmd_opts != NULL)
629 OBD_FREE(lsi->lsi_lmd->lmd_opts,
630 strlen(lsi->lsi_lmd->lmd_opts) + 1);
631 if (lsi->lsi_lmd->lmd_exclude_count)
632 OBD_FREE(lsi->lsi_lmd->lmd_exclude,
633 sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
634 lsi->lsi_lmd->lmd_exclude_count);
635 if (lsi->lsi_lmd->lmd_mgs != NULL)
636 OBD_FREE(lsi->lsi_lmd->lmd_mgs,
637 strlen(lsi->lsi_lmd->lmd_mgs) + 1);
638 if (lsi->lsi_lmd->lmd_osd_type != NULL)
639 OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
640 strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
641 if (lsi->lsi_lmd->lmd_params != NULL)
642 OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
643 if (lsi->lsi_lmd->lmd_nidnet != NULL)
644 OBD_FREE(lsi->lsi_lmd->lmd_nidnet,
645 strlen(lsi->lsi_lmd->lmd_nidnet) + 1);
647 OBD_FREE_PTR(lsi->lsi_lmd);
650 LASSERT(lsi->lsi_llsbi == NULL);
652 s2lsi_nocast(sb) = NULL;
658 * The lsi has one reference for every server that is using the disk -
659 * e.g. MDT, MGS, and potentially MGC
661 int lustre_put_lsi(struct super_block *sb)
663 struct lustre_sb_info *lsi = s2lsi(sb);
667 LASSERT(lsi != NULL);
669 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
670 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
671 if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
672 lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
673 lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
674 lsi->lsi_dt_dev = NULL;
675 obd_disconnect(lsi->lsi_osd_exp);
676 /* wait till OSD is gone */
677 obd_zombie_barrier();
684 EXPORT_SYMBOL(lustre_put_lsi);
687 * The goal of this function is to extract the file system name
688 * from the OBD name. This can come in two flavors. One is
689 * fsname-MDTXXXX or fsname-XXXXXXX were X is a hexadecimal
690 * number. In both cases we should return fsname. If it is
691 * not a valid OBD name it is assumed to be the file system
694 void obdname2fsname(const char *tgt, char *fsname, size_t buflen)
701 * First we have to see if the @tgt has '-' at all. It is
702 * valid for the user to request something like
703 * lctl set_param -P llite.lustre*.xattr_cache=0
705 ptr = strrchr(tgt, '-');
707 /* No '-' means it could end in '*' */
708 ptr = strchr(tgt, '*');
710 /* No '*' either. Assume tgt = fsname */
718 /* tgt format fsname-MDT0000-* */
719 if ((!strncmp(ptr, "-MDT", 4) ||
720 !strncmp(ptr, "-OST", 4)) &&
721 (isxdigit(ptr[4]) && isxdigit(ptr[5]) &&
722 isxdigit(ptr[6]) && isxdigit(ptr[7]))) {
728 * tgt_format fsname-cli'dev'-'uuid' except for the llite case
729 * which are named fsname-'uuid'. Examples:
731 * lustre-clilov-ffff88104db5b800
732 * lustre-ffff88104db5b800 (for llite device)
734 * The length of the OBD uuid can vary on different platforms.
735 * This test if any invalid characters are in string. Allow
736 * wildcards with '*' character.
739 if (!strspn(ptr, "0123456789abcdefABCDEF*")) {
745 * Now that we validated the device name lets extract the
746 * file system name. Most of the names in this class will
747 * have '-cli' in its name which needs to be dropped. If
748 * it doesn't have '-cli' then its a llite device which
749 * ptr already points to the start of the uuid string.
751 tmp = strstr(tgt, "-cli");
758 len = min_t(size_t, len, LUSTRE_MAXFSNAME);
759 snprintf(fsname, buflen, "%.*s", (int)len, tgt);
763 EXPORT_SYMBOL(obdname2fsname);
767 * <FSNAME><SEPARATOR><TYPE><INDEX>
768 * FSNAME is between 1 and 8 characters (inclusive).
769 * Excluded characters are '/' and ':'
770 * SEPARATOR is either ':' or '-'
771 * TYPE: "OST", "MDT", etc.
772 * INDEX: Hex representation of the index
776 * Get the fsname ("lustre") from the server name ("lustre-OST003F").
777 * @param [in] svname server name including type and index
778 * @param [out] fsname Buffer to copy filesystem name prefix into.
779 * Must have at least 'strlen(fsname) + 1' chars.
780 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
783 int server_name2fsname(const char *svname, char *fsname, const char **endptr)
787 dash = svname + strnlen(svname, LUSTRE_MAXFSNAME);
788 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
793 if (fsname != NULL) {
794 strncpy(fsname, svname, dash - svname);
795 fsname[dash - svname] = '\0';
803 EXPORT_SYMBOL(server_name2fsname);
805 #ifdef HAVE_SERVER_SUPPORT
807 * Get service name (svname) from string
809 * if endptr isn't NULL it is set to end of fsname *
811 int server_name2svname(const char *label, char *svname, const char **endptr,
817 /* We use server_name2fsname() just for parsing */
818 rc = server_name2fsname(label, NULL, &dash);
825 if (strlcpy(svname, dash + 1, svsize) >= svsize)
830 EXPORT_SYMBOL(server_name2svname);
831 #endif /* HAVE_SERVER_SUPPORT */
834 * check server name is OST.
836 int server_name_is_ost(const char *svname)
841 /* We use server_name2fsname() just for parsing */
842 rc = server_name2fsname(svname, NULL, &dash);
848 if (strncmp(dash, "OST", 3) == 0)
852 EXPORT_SYMBOL(server_name_is_ost);
855 * Get the index from the target name MDTXXXX/OSTXXXX
856 * rc = server type, or rc < 0 on error
858 int target_name2index(const char *tgtname, __u32 *idx, const char **endptr)
860 const char *dash = tgtname;
864 if (strncmp(dash, "MDT", 3) == 0)
865 rc = LDD_F_SV_TYPE_MDT;
866 else if (strncmp(dash, "OST", 3) == 0)
867 rc = LDD_F_SV_TYPE_OST;
873 if (strncmp(dash, "all", 3) == 0) {
876 return rc | LDD_F_SV_ALL;
879 index = simple_strtoul(dash, (char **)endptr, 16);
888 EXPORT_SYMBOL(target_name2index);
891 * Get the index from the OBD name.
892 * rc = server type, or
894 * if endptr isn't NULL it is set to end of name
896 int server_name2index(const char *svname, __u32 *idx, const char **endptr)
901 /* We use server_name2fsname() just for parsing */
902 rc = server_name2fsname(svname, NULL, &dash);
907 rc = target_name2index(dash, idx, endptr);
911 /* Account for -mdc after index that is possible when specifying mdt */
912 if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
913 sizeof(LUSTRE_MDC_NAME)-1) == 0)
914 *endptr += sizeof(LUSTRE_MDC_NAME);
918 EXPORT_SYMBOL(server_name2index);
920 /*************** mount common betweeen server and client ***************/
923 int lustre_common_put_super(struct super_block *sb)
929 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
931 /* Drop a ref to the MGC */
932 rc = lustre_stop_mgc(sb);
933 if (rc && (rc != -ENOENT)) {
935 CERROR("Can't stop MGC: %d\n", rc);
939 * BUSY just means that there's some other OBD that
940 * needs the mgc. Let him clean it up.
942 CDEBUG(D_MOUNT, "MGC still in use\n");
944 /* Drop a ref to the mounted disk */
949 EXPORT_SYMBOL(lustre_common_put_super);
951 static void lmd_print(struct lustre_mount_data *lmd)
955 PRINT_CMD(D_MOUNT, " mount data:\n");
956 if (lmd_is_client(lmd))
957 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
958 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
959 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
962 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
964 if (lmd->lmd_recovery_time_soft)
965 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
966 lmd->lmd_recovery_time_soft);
968 if (lmd->lmd_recovery_time_hard)
969 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
970 lmd->lmd_recovery_time_hard);
972 for (i = 0; i < lmd->lmd_exclude_count; i++) {
973 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
974 lmd->lmd_exclude[i]);
978 /* Is this server on the exclusion list */
979 int lustre_check_exclusion(struct super_block *sb, char *svname)
981 struct lustre_sb_info *lsi = s2lsi(sb);
982 struct lustre_mount_data *lmd = lsi->lsi_lmd;
988 rc = server_name2index(svname, &index, NULL);
989 if (rc != LDD_F_SV_TYPE_OST)
990 /* Only exclude OSTs */
993 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
994 index, lmd->lmd_exclude_count, lmd->lmd_dev);
996 for (i = 0; i < lmd->lmd_exclude_count; i++) {
997 if (index == lmd->lmd_exclude[i]) {
998 CWARN("Excluding %s (on exclusion list)\n", svname);
1005 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
1006 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
1008 const char *s1 = ptr, *s2;
1009 __u32 *exclude_list;
1016 * The shortest an ost name can be is 8 chars: -OST0000.
1017 * We don't actually know the fsname at this time, so in fact
1018 * a user could specify any fsname.
1020 devmax = strlen(ptr) / 8 + 1;
1022 /* temp storage until we figure out how many we have */
1023 OBD_ALLOC_PTR_ARRAY(exclude_list, devmax);
1027 /* we enter this fn pointing at the '=' */
1028 while (*s1 && *s1 != ' ' && *s1 != ',') {
1030 rc = server_name2index(s1, &index, &s2);
1032 CERROR("Can't parse server name '%s': rc = %d\n",
1036 if (rc == LDD_F_SV_TYPE_OST)
1037 exclude_list[lmd->lmd_exclude_count++] = index;
1039 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
1040 (uint)(s2-s1), s1, rc);
1043 * now we are pointing at ':' (next exclude)
1044 * or ',' (end of excludes)
1046 if (lmd->lmd_exclude_count >= devmax)
1049 if (rc >= 0) /* non-err */
1052 if (lmd->lmd_exclude_count) {
1053 /* permanent, freed in lustre_free_lsi */
1054 OBD_ALLOC_PTR_ARRAY(lmd->lmd_exclude,
1055 lmd->lmd_exclude_count);
1056 if (lmd->lmd_exclude) {
1057 memcpy(lmd->lmd_exclude, exclude_list,
1058 sizeof(index) * lmd->lmd_exclude_count);
1061 lmd->lmd_exclude_count = 0;
1064 OBD_FREE_PTR_ARRAY(exclude_list, devmax);
1068 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
1073 if (lmd->lmd_mgssec != NULL) {
1074 OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
1075 lmd->lmd_mgssec = NULL;
1078 tail = strchr(ptr, ',');
1080 length = strlen(ptr);
1082 length = tail - ptr;
1084 OBD_ALLOC(lmd->lmd_mgssec, length + 1);
1085 if (lmd->lmd_mgssec == NULL)
1088 memcpy(lmd->lmd_mgssec, ptr, length);
1089 lmd->lmd_mgssec[length] = '\0';
1093 static int lmd_parse_network(struct lustre_mount_data *lmd, char *ptr)
1098 if (lmd->lmd_nidnet != NULL) {
1099 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
1100 lmd->lmd_nidnet = NULL;
1103 tail = strchr(ptr, ',');
1105 length = strlen(ptr);
1107 length = tail - ptr;
1109 OBD_ALLOC(lmd->lmd_nidnet, length + 1);
1110 if (lmd->lmd_nidnet == NULL)
1113 memcpy(lmd->lmd_nidnet, ptr, length);
1114 lmd->lmd_nidnet[length] = '\0';
1118 static int lmd_parse_string(char **handle, char *ptr)
1123 if ((handle == NULL) || (ptr == NULL))
1126 if (*handle != NULL) {
1127 OBD_FREE(*handle, strlen(*handle) + 1);
1131 tail = strchr(ptr, ',');
1133 length = strlen(ptr);
1135 length = tail - ptr;
1137 OBD_ALLOC(*handle, length + 1);
1138 if (*handle == NULL)
1141 memcpy(*handle, ptr, length);
1142 (*handle)[length] = '\0';
1147 /* Collect multiple values for mgsnid specifiers */
1148 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
1156 /* Find end of NID-list */
1157 while (class_parse_nid_quiet(tail, &nid, &tail) == 0)
1160 length = tail - *ptr;
1162 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
1166 if (lmd->lmd_mgs != NULL)
1167 oldlen = strlen(lmd->lmd_mgs) + 1;
1169 OBD_ALLOC(mgsnid, oldlen + length + 1);
1173 if (lmd->lmd_mgs != NULL) {
1174 /* Multiple mgsnid= are taken to mean failover locations */
1175 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
1176 mgsnid[oldlen - 1] = ':';
1177 OBD_FREE(lmd->lmd_mgs, oldlen);
1179 memcpy(mgsnid + oldlen, *ptr, length);
1180 mgsnid[oldlen + length] = '\0';
1181 lmd->lmd_mgs = mgsnid;
1188 * Find the first delimiter (comma or colon) from the specified \a buf and
1189 * make \a *endh point to the string starting with the delimiter. The commas
1190 * in expression list [...] will be skipped.
1192 * @buf a delimiter-separated string
1193 * @endh a pointer to a pointer that will point to the string
1194 * starting with the delimiter
1196 * RETURNS true if delimiter is found, false if delimiter is not found
1198 static bool lmd_find_delimiter(char *buf, char **endh)
1207 if (*c == ',' || *c == ':')
1210 pos = strcspn(c, "[:,]");
1214 /* Not a valid mount string */
1216 CWARN("invalid mount string format\n");
1224 /* invalid mount string */
1226 CWARN("invalid mount string format\n");
1241 * Find the first valid string delimited by comma or colon from the specified
1242 * \a buf and parse it to see whether it's a valid NID list. If yes, \a *endh
1243 * will point to the next string starting with the delimiter.
1245 * \param[in] buf a delimiter-separated string
1246 * \param[in] endh a pointer to a pointer that will point to the string
1247 * starting with the delimiter
1249 * \retval 0 if the string is a valid NID list
1250 * \retval 1 if the string is not a valid NID list
1252 static int lmd_parse_nidlist(char *buf, char **endh)
1261 while (*buf == ',' || *buf == ':')
1263 if (*buf == ' ' || *buf == '/' || *buf == '\0')
1266 if (!lmd_find_delimiter(buf, &endp))
1267 endp = buf + strlen(buf);
1272 if (cfs_parse_nidlist(buf, strlen(buf), &nidlist) <= 0)
1274 cfs_free_nidlist(&nidlist);
1285 * Parse mount line options
1286 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
1287 * dev is passed as device=uml1:/lustre by mount.lustre_tgt
1289 int lmd_parse(char *options, struct lustre_mount_data *lmd)
1291 char *s1, *s2, *devname = NULL;
1292 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
1299 LCONSOLE_ERROR_MSG(0x162,
1300 "Missing mount data: check /sbin/mount.lustre_tgt is installed.\n");
1304 /* Options should be a string - try to detect old lmd data */
1305 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1306 LCONSOLE_ERROR_MSG(0x163,
1307 "Using an old version of /sbin/mount.lustre. Please install version %s\n",
1308 LUSTRE_VERSION_STRING);
1311 lmd->lmd_magic = LMD_MAGIC;
1313 OBD_ALLOC(lmd->lmd_params, LMD_PARAMS_MAXLEN);
1314 if (lmd->lmd_params == NULL)
1316 lmd->lmd_params[0] = '\0';
1318 /* Set default flags here */
1323 int time_min = OBD_RECOVERY_TIME_MIN;
1326 /* Skip whitespace and extra commas */
1327 while (*s1 == ' ' || *s1 == ',')
1332 * Client options are parsed in ll_options: eg. flock,
1337 * Parse non-ldiskfs options here. Rather than modifying
1338 * ldiskfs, we just zero these out here
1340 if (!strncmp(s1, "abort_recov_mdt", 15) ||
1341 !strncmp(s1, "abort_recovery_mdt", 18)) {
1342 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV_MDT;
1344 } else if (strncmp(s1, "abort_recov", 11) == 0) {
1345 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
1347 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
1348 lmd->lmd_recovery_time_soft =
1349 max_t(int, simple_strtoul(s1 + 19, NULL, 10),
1352 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
1353 lmd->lmd_recovery_time_hard =
1354 max_t(int, simple_strtoul(s1 + 19, NULL, 10),
1357 } else if (strncmp(s1, "no_precreate", 12) == 0) {
1358 lmd->lmd_flags |= LMD_FLG_NO_PRECREATE;
1360 } else if (strncmp(s1, "noir", 4) == 0) {
1361 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
1363 } else if (strncmp(s1, "nosvc", 5) == 0) {
1364 lmd->lmd_flags |= LMD_FLG_NOSVC;
1366 } else if (strncmp(s1, "nomgs", 5) == 0) {
1367 lmd->lmd_flags |= LMD_FLG_NOMGS;
1369 } else if (strncmp(s1, "noscrub", 7) == 0) {
1370 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
1372 } else if (strncmp(s1, "skip_lfsck", 10) == 0) {
1373 lmd->lmd_flags |= LMD_FLG_SKIP_LFSCK;
1375 } else if (strncmp(s1, "rdonly_dev", 10) == 0) {
1376 lmd->lmd_flags |= LMD_FLG_DEV_RDONLY;
1378 } else if (strncmp(s1, PARAM_MGSNODE,
1379 sizeof(PARAM_MGSNODE) - 1) == 0) {
1380 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
1382 * Assume the next mount opt is the first
1383 * invalid NID we get to.
1385 rc = lmd_parse_mgs(lmd, &s2);
1390 } else if (strncmp(s1, "writeconf", 9) == 0) {
1391 lmd->lmd_flags |= LMD_FLG_WRITECONF;
1393 } else if (strncmp(s1, "nolocallogs", 11) == 0) {
1394 lmd->lmd_flags |= LMD_FLG_NO_LOCAL_LOGS;
1396 } else if (strncmp(s1, "update", 6) == 0) {
1397 lmd->lmd_flags |= LMD_FLG_UPDATE;
1399 } else if (strncmp(s1, "virgin", 6) == 0) {
1400 lmd->lmd_flags |= LMD_FLG_VIRGIN;
1402 } else if (strncmp(s1, "noprimnode", 10) == 0) {
1403 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
1405 } else if (strncmp(s1, "mgssec=", 7) == 0) {
1406 rc = lmd_parse_mgssec(lmd, s1 + 7);
1410 /* ost exclusion list */
1411 } else if (strncmp(s1, "exclude=", 8) == 0) {
1412 rc = lmd_make_exclusion(lmd, s1 + 7);
1416 } else if (strncmp(s1, "mgs", 3) == 0) {
1418 lmd->lmd_flags |= LMD_FLG_MGS;
1420 } else if (strncmp(s1, "svname=", 7) == 0) {
1421 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
1425 } else if (strncmp(s1, "param=", 6) == 0) {
1426 size_t length, params_length;
1429 if (lmd_find_delimiter(s1 + 6, &tail)) {
1430 char *param_str = tail + 1;
1431 int supplementary = 1;
1433 while (lmd_parse_nidlist(param_str,
1437 length = param_str - s1 - supplementary;
1439 length = strlen(s1);
1442 params_length = strlen(lmd->lmd_params);
1443 if (params_length + length + 1 >= LMD_PARAMS_MAXLEN)
1445 strncat(lmd->lmd_params, s1 + 6, length);
1446 lmd->lmd_params[params_length + length] = '\0';
1447 strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
1448 s3 = s1 + 6 + length;
1450 } else if (strncmp(s1, "localrecov", 10) == 0) {
1451 lmd->lmd_flags |= LMD_FLG_LOCAL_RECOV;
1453 } else if (strncmp(s1, "osd=", 4) == 0) {
1454 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1460 * Linux 2.4 doesn't pass the device, so we stuck it at
1461 * the end of the options.
1463 else if (strncmp(s1, "device=", 7) == 0) {
1466 * terminate options right before device. device
1467 * must be the last one.
1471 } else if (strncmp(s1, "network=", 8) == 0) {
1472 rc = lmd_parse_network(lmd, s1 + 8);
1476 /* check if LNet dynamic peer discovery is activated */
1477 if (LNetGetPeerDiscoveryStatus()) {
1478 CERROR("LNet Dynamic Peer Discovery is enabled "
1479 "on this node. 'network' mount option "
1480 "cannot be taken into account.\n");
1488 s2 = strchr(s3, ',');
1496 memmove(s1, s2, strlen(s2) + 1);
1502 LCONSOLE_ERROR_MSG(0x164,
1503 "Can't find device name (need mount option 'device=...')\n");
1507 s1 = strstr(devname, ":/");
1510 lmd->lmd_flags |= LMD_FLG_CLIENT;
1511 /* Remove leading /s from fsname */
1512 while (*++s1 == '/')
1515 while (*s2 != '/' && *s2 != '\0')
1517 /* Freed in lustre_free_lsi */
1518 OBD_ALLOC(lmd->lmd_profile, s2 - s1 + 8);
1519 if (!lmd->lmd_profile)
1522 strncat(lmd->lmd_profile, s1, s2 - s1);
1523 strncat(lmd->lmd_profile, "-client", 7);
1526 s2 = s1 + strlen(s1) - 1;
1527 /* Remove padding /s from fileset */
1531 OBD_ALLOC(lmd->lmd_fileset, s2 - s1 + 2);
1532 if (lmd->lmd_fileset == NULL) {
1533 OBD_FREE(lmd->lmd_profile,
1534 strlen(lmd->lmd_profile) + 1);
1537 strncat(lmd->lmd_fileset, s1, s2 - s1 + 1);
1541 if (lmd->lmd_nidnet != NULL) {
1542 /* 'network=' mount option forbidden for server */
1543 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
1544 lmd->lmd_nidnet = NULL;
1547 "%s: option 'network=' not allowed for Lustre servers: rc = %d\n",
1553 /* Freed in lustre_free_lsi */
1554 OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
1557 strncpy(lmd->lmd_dev, devname, strlen(devname)+1);
1559 /* Save mount options */
1560 s1 = options + strlen(options) - 1;
1561 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1563 while (*options && (*options == ',' || *options == ' '))
1565 if (*options != 0) {
1566 /* Freed in lustre_free_lsi */
1567 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
1570 strncpy(lmd->lmd_opts, options, strlen(options)+1);
1574 lmd->lmd_magic = LMD_MAGIC;
1579 CERROR("Bad mount options %s\n", options);
1582 EXPORT_SYMBOL(lmd_parse);