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
43 #include <linux/random.h>
44 #include <linux/uuid.h>
45 #include <linux/version.h>
48 #include <obd_class.h>
49 #include <lustre_crypto.h>
50 #include <lustre_log.h>
51 #include <lustre_disk.h>
52 #include <uapi/linux/lustre/lustre_param.h>
54 /**************** config llog ********************/
57 * Get a config log from the MGS and process it.
58 * This func is called for both clients and servers.
59 * Continue to process new statements appended to the logs
60 * (whenever the config lock is revoked) until lustre_end_log
63 * @param sb The superblock is used by the MGC to write to the local copy of
65 * @param logname The name of the llog to replicate from the MGS
66 * @param cfg Since the same MGC may be used to follow multiple config logs
67 * (e.g. ost1, ost2, client), the config_llog_instance keeps the state for
68 * this log, and is added to the mgc's list of logs to follow.
70 int lustre_process_log(struct super_block *sb, char *logname,
71 struct config_llog_instance *cfg)
73 struct lustre_cfg *lcfg;
74 struct lustre_cfg_bufs *bufs;
75 struct lustre_sb_info *lsi = s2lsi(sb);
76 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 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
95 GOTO(out, rc = -ENOMEM);
96 lustre_cfg_init(lcfg, LCFG_LOG_START, bufs);
98 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
99 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
104 LCONSOLE_ERROR_MSG(0x15b,
105 "%s: Configuration from log %s failed from MGS %d. Check client and MGS are on compatible version.\n",
106 mgc->obd_name, logname, rc);
108 LCONSOLE_ERROR_MSG(0x15c,
109 "%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",
110 mgc->obd_name, logname, rc);
112 /* class_obd_list(); */
115 EXPORT_SYMBOL(lustre_process_log);
117 /* Stop watching this config log for updates */
118 int lustre_end_log(struct super_block *sb, char *logname,
119 struct config_llog_instance *cfg)
121 struct lustre_cfg *lcfg;
122 struct lustre_cfg_bufs bufs;
123 struct lustre_sb_info *lsi = s2lsi(sb);
124 struct obd_device *mgc = lsi->lsi_mgc;
132 /* mgc_process_config */
133 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
134 lustre_cfg_bufs_set_string(&bufs, 1, logname);
136 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
137 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
140 lustre_cfg_init(lcfg, LCFG_LOG_END, &bufs);
141 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
142 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
145 EXPORT_SYMBOL(lustre_end_log);
147 /**************** OBD start *******************/
150 * lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
151 * lctl (and do for echo cli/srv.
153 static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
154 char *s1, char *s2, char *s3, char *s4)
156 struct lustre_cfg_bufs bufs;
157 struct lustre_cfg *lcfg = NULL;
160 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
161 cmd, s1, s2, s3, s4);
163 lustre_cfg_bufs_reset(&bufs, cfgname);
165 lustre_cfg_bufs_set_string(&bufs, 1, s1);
167 lustre_cfg_bufs_set_string(&bufs, 2, s2);
169 lustre_cfg_bufs_set_string(&bufs, 3, s3);
171 lustre_cfg_bufs_set_string(&bufs, 4, s4);
173 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
176 lustre_cfg_init(lcfg, cmd, &bufs);
177 lcfg->lcfg_nid = nid;
178 rc = class_process_config(lcfg);
179 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
183 static int do_lcfg_nid(char *cfgname, struct lnet_nid *nid, int cmd,
189 if (nid_is_nid4(nid))
190 nid4 = lnet_nid_to_nid4(nid);
192 nidstr = libcfs_nidstr(nid);
193 return do_lcfg(cfgname, nid4, cmd, s1, nidstr, NULL, NULL);
197 * Call class_attach and class_setup. These methods in turn call
198 * OBD type-specific methods.
200 int lustre_start_simple(char *obdname, char *type, char *uuid,
201 char *s1, char *s2, char *s3, char *s4)
205 CDEBUG(D_MOUNT, "Starting OBD %s (typ=%s)\n", obdname, type);
207 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
209 CERROR("%s attach error %d\n", obdname, rc);
212 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
214 CERROR("%s setup error %d\n", obdname, rc);
215 do_lcfg(obdname, 0, LCFG_DETACH, NULL, NULL, NULL, NULL);
219 EXPORT_SYMBOL(lustre_start_simple);
221 static DEFINE_MUTEX(mgc_start_lock);
224 * Set up a MGC OBD to process startup logs
226 * \param sb [in] super block of the MGC OBD
228 * \retval 0 success, otherwise error code
230 int lustre_start_mgc(struct super_block *sb)
232 struct obd_connect_data *data = NULL;
233 struct lustre_sb_info *lsi = s2lsi(sb);
234 struct obd_device *obd;
235 struct obd_export *exp;
236 struct obd_uuid *uuid = NULL;
239 char nidstr[LNET_NIDSTR_SIZE];
240 char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
242 int rc = 0, i = 0, j;
247 LASSERT(lsi->lsi_lmd);
249 /* Find the first non-lo MGS NID for our MGC name */
250 if (IS_SERVER(lsi)) {
251 /* mount -o mgsnode=nid */
252 ptr = lsi->lsi_lmd->lmd_mgs;
253 if (lsi->lsi_lmd->lmd_mgs &&
254 (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) {
256 } else if (IS_MGS(lsi)) {
257 struct lnet_processid id;
259 while ((rc = LNetGetId(i++, &id, true)) != -ENOENT) {
260 if (nid_is_lo0(&id.nid))
267 } else { /* client */
268 /* Use NIDs from mount line: uml1,1@elan:uml2,2@elan:/lustre */
269 ptr = lsi->lsi_lmd->lmd_dev;
270 if (class_parse_nid(ptr, &nid, &ptr) == 0)
274 CERROR("No valid MGS NIDs found.\n");
278 mutex_lock(&mgc_start_lock);
280 libcfs_nidstr_r(&nid, nidstr, sizeof(nidstr));
281 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(nidstr) + 1;
282 OBD_ALLOC(mgcname, len);
283 OBD_ALLOC(niduuid, len + 2);
284 if (mgcname == NULL || niduuid == NULL)
285 GOTO(out_free, rc = -ENOMEM);
286 snprintf(mgcname, len, "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
288 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
292 GOTO(out_free, rc = -ENOMEM);
294 obd = class_name2obd(mgcname);
295 if (obd && !obd->obd_stopping) {
298 rc = obd_set_info_async(NULL, obd->obd_self_export,
299 strlen(KEY_MGSSEC), KEY_MGSSEC,
300 strlen(mgssec), mgssec, NULL);
304 /* Re-using an existing MGC */
305 atomic_inc(&obd->u.cli.cl_mgc_refcount);
307 /* IR compatibility check, only for clients */
308 if (lmd_is_client(lsi->lsi_lmd)) {
310 int vallen = sizeof(*data);
312 rc = obd_get_info(NULL, obd->obd_self_export,
313 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
316 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
317 if (has_ir ^ !test_bit(LMD_FLG_NOIR,
318 lsi->lsi_lmd->lmd_flags)) {
319 /* LMD_FLG_NOIR is for test purpose only */
321 "Mounting client with IR setting not compatible with current MGC. Using MGC setting that is IR %s",
322 has_ir ? "enabled" : "disabled");
324 clear_bit(LMD_FLG_NOIR,
325 lsi->lsi_lmd->lmd_flags);
327 set_bit(LMD_FLG_NOIR,
328 lsi->lsi_lmd->lmd_flags);
335 * If we are restarting the MGS, don't try to keep the MGC's
336 * old connection, or registration will fail.
339 CDEBUG(D_MOUNT, "New MGS with live MGC\n");
344 * Try all connections, but only once (again).
345 * We don't want to block another target from starting
346 * (using its local copy of the log), but we do want to connect
347 * if at all possible.
350 CDEBUG(D_MOUNT, "%s:Set MGC reconnect %d\n", mgcname, recov_bk);
351 rc = obd_set_info_async(NULL, obd->obd_self_export,
352 sizeof(KEY_INIT_RECOV_BACKUP),
353 KEY_INIT_RECOV_BACKUP,
354 sizeof(recov_bk), &recov_bk, NULL);
358 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
360 /* Add the primary NIDs for the MGS */
362 snprintf(niduuid, len + 2, "%s_%x", mgcname, i);
363 if (IS_SERVER(lsi)) {
364 ptr = lsi->lsi_lmd->lmd_mgs;
365 CDEBUG(D_MOUNT, "mgs NIDs %s.\n", ptr);
367 /* Use local NIDs (including LO) */
368 struct lnet_processid id;
370 while ((rc = LNetGetId(i++, &id, true)) != -ENOENT) {
371 rc = do_lcfg_nid(mgcname, &id.nid,
376 /* Use mgsnode= nids */
377 /* mount -o mgsnode=nid */
378 if (lsi->lsi_lmd->lmd_mgs) {
379 ptr = lsi->lsi_lmd->lmd_mgs;
380 } else if (class_find_param(ptr, PARAM_MGSNODE,
382 CERROR("No MGS NIDs given.\n");
383 GOTO(out_free, rc = -EINVAL);
386 * Add primary MGS NID(s).
387 * Multiple NIDs on one MGS node are separated
390 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
391 rc = do_lcfg_nid(mgcname, &nid,
396 /* Stop at the first failover NID */
401 } else { /* client */
402 /* Use NIDs from mount line: uml1,1@elan:uml2,2@elan:/lustre */
403 ptr = lsi->lsi_lmd->lmd_dev;
404 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
405 rc = do_lcfg_nid(mgcname, &nid, LCFG_ADD_UUID,
409 /* Stop at the first failover NID */
415 CERROR("No valid MGS NIDs found.\n");
416 GOTO(out_free, rc = -EINVAL);
418 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
420 /* Random uuid for MGC allows easier reconnects */
423 GOTO(out_free, rc = -ENOMEM);
425 generate_random_uuid(uuidc.b);
426 snprintf(uuid->uuid, sizeof(*uuid), "%pU", uuidc.b);
429 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
430 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
431 niduuid, NULL, NULL);
435 /* Add any failover MGS NIDs */
437 while (ptr && ((*ptr == ':' ||
438 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
439 /* New failover node */
440 sprintf(niduuid, "%s_%x", mgcname, i);
442 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
443 rc = do_lcfg_nid(mgcname, &nid, LCFG_ADD_UUID,
451 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
452 niduuid, NULL, NULL, NULL);
460 lsi->lsi_lmd->lmd_mgs_failnodes = i;
462 obd = class_name2obd(mgcname);
464 CERROR("Can't find mgcobd %s\n", mgcname);
465 GOTO(out_free, rc = -ENOTCONN);
468 rc = obd_set_info_async(NULL, obd->obd_self_export,
469 strlen(KEY_MGSSEC), KEY_MGSSEC,
470 strlen(mgssec), mgssec, NULL);
475 * Keep a refcount of servers/clients who started with "mount",
476 * so we know when we can get rid of the mgc.
478 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
480 /* We connect to the MGS at setup, and don't disconnect until cleanup */
481 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
482 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
483 OBD_CONNECT_LVB_TYPE |
484 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_BARRIER |
486 data->ocd_connect_flags2 = OBD_CONNECT2_REP_MBITS |
487 OBD_CONNECT2_LARGE_NID;
489 if (lmd_is_client(lsi->lsi_lmd) &&
490 test_bit(LMD_FLG_NOIR, lsi->lsi_lmd->lmd_flags))
491 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
492 data->ocd_version = LUSTRE_VERSION_CODE;
493 rc = obd_connect(NULL, &exp, obd, uuid, data, NULL);
495 CERROR("connect failed %d\n", rc);
499 obd->u.cli.cl_mgc_mgsexp = exp;
503 * Keep the MGC info in the sb. Note that many lsi's can point
508 mutex_unlock(&mgc_start_lock);
515 OBD_FREE(mgcname, len);
517 OBD_FREE(niduuid, len + 2);
520 EXPORT_SYMBOL(lustre_start_mgc);
522 int lustre_stop_mgc(struct super_block *sb)
524 struct lustre_sb_info *lsi = s2lsi(sb);
525 struct obd_device *obd;
526 char niduuid[MAX_OBD_NAME + 6], *ptr = NULL;
538 mutex_lock(&mgc_start_lock);
539 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
540 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
542 * This is not fatal, every client that stops
545 CDEBUG(D_MOUNT, "MGC still has %d references.\n",
546 atomic_read(&obd->u.cli.cl_mgc_refcount));
547 GOTO(out, rc = -EBUSY);
551 * The MGC has no recoverable data in any case.
552 * force shotdown set in umount_begin
554 obd->obd_no_recov = 1;
556 if (obd->u.cli.cl_mgc_mgsexp) {
558 * An error is not fatal, if we are unable to send the
559 * disconnect mgs ping evictor cleans up the export
561 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
563 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
567 * Cache the obdname for cleaning the nid uuids, which are
568 * obdname_XX before calling class_manual_cleanup
570 strcpy(niduuid, obd->obd_name);
571 ptr = niduuid + strlen(niduuid);
573 rc = class_manual_cleanup(obd);
577 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
578 sprintf(ptr, "_%x", i);
579 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
580 niduuid, NULL, NULL, NULL);
582 CERROR("del MDC UUID %s failed: rc = %d\n",
586 /* class_import_put will get rid of the additional connections */
587 mutex_unlock(&mgc_start_lock);
590 EXPORT_SYMBOL(lustre_stop_mgc);
592 /***************** lustre superblock **************/
594 struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
596 struct lustre_sb_info *lsi;
603 OBD_ALLOC_PTR(lsi->lsi_lmd);
609 s2lsi_nocast(sb) = lsi;
610 /* we take 1 extra ref for our setup */
611 atomic_set(&lsi->lsi_mounts, 1);
613 /* Default umount style */
614 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
615 INIT_LIST_HEAD(&lsi->lsi_lwp_list);
616 mutex_init(&lsi->lsi_lwp_mutex);
620 EXPORT_SYMBOL(lustre_init_lsi);
622 static int lustre_free_lsi(struct super_block *sb)
624 struct lustre_sb_info *lsi = s2lsi(sb);
628 LASSERT(lsi != NULL);
629 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
631 /* someone didn't call server_put_mount. */
632 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
635 if (lsi->lsi_lmd != NULL) {
636 if (lsi->lsi_lmd->lmd_dev != NULL)
637 OBD_FREE(lsi->lsi_lmd->lmd_dev,
638 strlen(lsi->lsi_lmd->lmd_dev) + 1);
639 if (lsi->lsi_lmd->lmd_profile != NULL)
640 OBD_FREE(lsi->lsi_lmd->lmd_profile,
641 strlen(lsi->lsi_lmd->lmd_profile) + 1);
642 if (lsi->lsi_lmd->lmd_fileset != NULL)
643 OBD_FREE(lsi->lsi_lmd->lmd_fileset,
644 strlen(lsi->lsi_lmd->lmd_fileset) + 1);
645 if (lsi->lsi_lmd->lmd_mgssec != NULL)
646 OBD_FREE(lsi->lsi_lmd->lmd_mgssec,
647 strlen(lsi->lsi_lmd->lmd_mgssec) + 1);
648 if (lsi->lsi_lmd->lmd_opts != NULL)
649 OBD_FREE(lsi->lsi_lmd->lmd_opts,
650 strlen(lsi->lsi_lmd->lmd_opts) + 1);
651 if (lsi->lsi_lmd->lmd_exclude_count)
652 OBD_FREE(lsi->lsi_lmd->lmd_exclude,
653 sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
654 lsi->lsi_lmd->lmd_exclude_count);
655 if (lsi->lsi_lmd->lmd_mgs != NULL)
656 OBD_FREE(lsi->lsi_lmd->lmd_mgs,
657 strlen(lsi->lsi_lmd->lmd_mgs) + 1);
658 if (lsi->lsi_lmd->lmd_osd_type != NULL)
659 OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
660 strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
661 if (lsi->lsi_lmd->lmd_params != NULL)
662 OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
663 if (lsi->lsi_lmd->lmd_nidnet != NULL)
664 OBD_FREE(lsi->lsi_lmd->lmd_nidnet,
665 strlen(lsi->lsi_lmd->lmd_nidnet) + 1);
667 OBD_FREE_PTR(lsi->lsi_lmd);
670 LASSERT(lsi->lsi_llsbi == NULL);
672 s2lsi_nocast(sb) = NULL;
678 * The lsi has one reference for every server that is using the disk -
679 * e.g. MDT, MGS, and potentially MGC
681 int lustre_put_lsi(struct super_block *sb)
683 struct lustre_sb_info *lsi = s2lsi(sb);
687 LASSERT(lsi != NULL);
689 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
690 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
691 if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
692 lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
693 lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
694 lsi->lsi_dt_dev = NULL;
695 obd_disconnect(lsi->lsi_osd_exp);
696 /* wait till OSD is gone */
697 obd_zombie_barrier();
704 EXPORT_SYMBOL(lustre_put_lsi);
707 * The goal of this function is to extract the file system name
708 * from the OBD name. This can come in two flavors. One is
709 * fsname-MDTXXXX or fsname-XXXXXXX were X is a hexadecimal
710 * number. In both cases we should return fsname. If it is
711 * not a valid OBD name it is assumed to be the file system
714 void obdname2fsname(const char *tgt, char *fsname, size_t buflen)
721 * First we have to see if the @tgt has '-' at all. It is
722 * valid for the user to request something like
723 * lctl set_param -P llite.lustre*.xattr_cache=0
725 ptr = strrchr(tgt, '-');
727 /* No '-' means it could end in '*' */
728 ptr = strchr(tgt, '*');
730 /* No '*' either. Assume tgt = fsname */
738 /* tgt format fsname-MDT0000-* */
739 if ((!strncmp(ptr, "-MDT", 4) ||
740 !strncmp(ptr, "-OST", 4)) &&
741 (isxdigit(ptr[4]) && isxdigit(ptr[5]) &&
742 isxdigit(ptr[6]) && isxdigit(ptr[7]))) {
748 * tgt_format fsname-cli'dev'-'uuid' except for the llite case
749 * which are named fsname-'uuid'. Examples:
751 * lustre-clilov-ffff88104db5b800
752 * lustre-ffff88104db5b800 (for llite device)
754 * The length of the OBD uuid can vary on different platforms.
755 * This test if any invalid characters are in string. Allow
756 * wildcards with '*' character.
759 if (!strspn(ptr, "0123456789abcdefABCDEF*")) {
765 * Now that we validated the device name lets extract the
766 * file system name. Most of the names in this class will
767 * have '-cli' in its name which needs to be dropped. If
768 * it doesn't have '-cli' then its a llite device which
769 * ptr already points to the start of the uuid string.
771 tmp = strstr(tgt, "-cli");
778 len = min_t(size_t, len, LUSTRE_MAXFSNAME);
779 snprintf(fsname, buflen, "%.*s", (int)len, tgt);
783 EXPORT_SYMBOL(obdname2fsname);
787 * <FSNAME><SEPARATOR><TYPE><INDEX>
788 * FSNAME is between 1 and 8 characters (inclusive).
789 * Excluded characters are '/' and ':'
790 * SEPARATOR is either ':' or '-'
791 * TYPE: "OST", "MDT", etc.
792 * INDEX: Hex representation of the index
796 * Get the fsname ("lustre") from the server name ("lustre-OST003F").
797 * @param [in] svname server name including type and index
798 * @param [out] fsname Buffer to copy filesystem name prefix into.
799 * Must have at least 'strlen(fsname) + 1' chars.
800 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
803 int server_name2fsname(const char *svname, char *fsname, const char **endptr)
807 dash = svname + strnlen(svname, LUSTRE_MAXFSNAME);
808 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
813 if (fsname != NULL) {
814 strncpy(fsname, svname, dash - svname);
815 fsname[dash - svname] = '\0';
823 EXPORT_SYMBOL(server_name2fsname);
825 #ifdef HAVE_SERVER_SUPPORT
827 * Get service name (svname) from string
829 * if endptr isn't NULL it is set to end of fsname *
831 int server_name2svname(const char *label, char *svname, const char **endptr,
837 /* We use server_name2fsname() just for parsing */
838 rc = server_name2fsname(label, NULL, &dash);
845 if (strlcpy(svname, dash + 1, svsize) >= svsize)
850 EXPORT_SYMBOL(server_name2svname);
851 #endif /* HAVE_SERVER_SUPPORT */
854 * check server name is OST.
856 int server_name_is_ost(const char *svname)
861 /* We use server_name2fsname() just for parsing */
862 rc = server_name2fsname(svname, NULL, &dash);
868 if (strncmp(dash, "OST", 3) == 0)
872 EXPORT_SYMBOL(server_name_is_ost);
875 * Get the index from the target name MDTXXXX/OSTXXXX
876 * rc = server type, or rc < 0 on error
878 int target_name2index(const char *tgtname, u32 *idx, const char **endptr)
880 const char *dash = tgtname;
884 if (strncmp(dash, "MDT", 3) == 0)
885 type = LDD_F_SV_TYPE_MDT;
886 else if (strncmp(dash, "OST", 3) == 0)
887 type = LDD_F_SV_TYPE_OST;
893 if (strncmp(dash, "all", 3) == 0) {
896 return type | LDD_F_SV_ALL;
899 len = strspn(dash, "0123456789ABCDEFabcdef");
903 if (strlen(dash) != len) {
907 memcpy(num, dash, sizeof(num) - 1);
908 rc = kstrtou16(num, 16, &index);
912 rc = kstrtou16(dash, 16, &index);
921 *endptr = dash + len;
925 EXPORT_SYMBOL(target_name2index);
928 * Get the index from the OBD name.
929 * rc = server type, or
931 * if endptr isn't NULL it is set to end of name
933 int server_name2index(const char *svname, __u32 *idx, const char **endptr)
938 /* We use server_name2fsname() just for parsing */
939 rc = server_name2fsname(svname, NULL, &dash);
944 rc = target_name2index(dash, idx, endptr);
948 /* Account for -mdc after index that is possible when specifying mdt */
949 if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
950 sizeof(LUSTRE_MDC_NAME)-1) == 0)
951 *endptr += sizeof(LUSTRE_MDC_NAME);
955 EXPORT_SYMBOL(server_name2index);
957 /*************** mount common betweeen server and client ***************/
960 int lustre_common_put_super(struct super_block *sb)
966 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
968 /* Drop a ref to the MGC */
969 rc = lustre_stop_mgc(sb);
970 if (rc && (rc != -ENOENT)) {
972 CERROR("Can't stop MGC: %d\n", rc);
976 * BUSY just means that there's some other OBD that
977 * needs the mgc. Let him clean it up.
979 CDEBUG(D_MOUNT, "MGC still in use\n");
981 /* Drop a ref to the mounted disk */
986 EXPORT_SYMBOL(lustre_common_put_super);
988 static void lmd_print(struct lustre_mount_data *lmd)
992 PRINT_CMD(D_MOUNT, " mount data:\n");
993 if (lmd_is_client(lmd))
994 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
995 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
998 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
1000 if (lmd->lmd_recovery_time_soft)
1001 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
1002 lmd->lmd_recovery_time_soft);
1004 if (lmd->lmd_recovery_time_hard)
1005 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
1006 lmd->lmd_recovery_time_hard);
1008 for (i = 0; i < lmd->lmd_exclude_count; i++) {
1009 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
1010 lmd->lmd_exclude[i]);
1014 /* Is this server on the exclusion list */
1015 int lustre_check_exclusion(struct super_block *sb, char *svname)
1017 struct lustre_sb_info *lsi = s2lsi(sb);
1018 struct lustre_mount_data *lmd = lsi->lsi_lmd;
1024 rc = server_name2index(svname, &index, NULL);
1025 if (rc != LDD_F_SV_TYPE_OST)
1026 /* Only exclude OSTs */
1029 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
1030 index, lmd->lmd_exclude_count, lmd->lmd_dev);
1032 for (i = 0; i < lmd->lmd_exclude_count; i++) {
1033 if (index == lmd->lmd_exclude[i]) {
1034 CWARN("Excluding %s (on exclusion list)\n", svname);
1041 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
1042 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
1044 const char *s1 = ptr, *s2;
1045 __u32 *exclude_list;
1052 * The shortest an ost name can be is 8 chars: -OST0000.
1053 * We don't actually know the fsname at this time, so in fact
1054 * a user could specify any fsname.
1056 devmax = strlen(ptr) / 8 + 1;
1058 /* temp storage until we figure out how many we have */
1059 OBD_ALLOC_PTR_ARRAY(exclude_list, devmax);
1063 /* we enter this fn pointing at the '=' */
1064 while (*s1 && *s1 != ' ' && *s1 != ',') {
1066 rc = server_name2index(s1, &index, &s2);
1068 CERROR("Can't parse server name '%s': rc = %d\n",
1072 if (rc == LDD_F_SV_TYPE_OST)
1073 exclude_list[lmd->lmd_exclude_count++] = index;
1075 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
1076 (uint)(s2-s1), s1, rc);
1079 * now we are pointing at ':' (next exclude)
1080 * or ',' (end of excludes)
1082 if (lmd->lmd_exclude_count >= devmax)
1085 if (rc >= 0) /* non-err */
1088 if (lmd->lmd_exclude_count) {
1089 /* permanent, freed in lustre_free_lsi */
1090 OBD_ALLOC_PTR_ARRAY(lmd->lmd_exclude,
1091 lmd->lmd_exclude_count);
1092 if (lmd->lmd_exclude) {
1093 memcpy(lmd->lmd_exclude, exclude_list,
1094 sizeof(index) * lmd->lmd_exclude_count);
1097 lmd->lmd_exclude_count = 0;
1100 OBD_FREE_PTR_ARRAY(exclude_list, devmax);
1104 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
1109 if (lmd->lmd_mgssec != NULL) {
1110 OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
1111 lmd->lmd_mgssec = NULL;
1114 tail = strchr(ptr, ',');
1116 length = strlen(ptr);
1118 length = tail - ptr;
1120 OBD_ALLOC(lmd->lmd_mgssec, length + 1);
1121 if (lmd->lmd_mgssec == NULL)
1124 memcpy(lmd->lmd_mgssec, ptr, length);
1125 lmd->lmd_mgssec[length] = '\0';
1129 static int lmd_parse_network(struct lustre_mount_data *lmd, char *ptr)
1134 if (lmd->lmd_nidnet != NULL) {
1135 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
1136 lmd->lmd_nidnet = NULL;
1139 tail = strchr(ptr, ',');
1141 length = strlen(ptr);
1143 length = tail - ptr;
1145 OBD_ALLOC(lmd->lmd_nidnet, length + 1);
1146 if (lmd->lmd_nidnet == NULL)
1149 memcpy(lmd->lmd_nidnet, ptr, length);
1150 lmd->lmd_nidnet[length] = '\0';
1154 static int lmd_parse_string(char **handle, char *ptr)
1159 if ((handle == NULL) || (ptr == NULL))
1162 if (*handle != NULL) {
1163 OBD_FREE(*handle, strlen(*handle) + 1);
1167 tail = strchr(ptr, ',');
1169 length = strlen(ptr);
1171 length = tail - ptr;
1173 OBD_ALLOC(*handle, length + 1);
1174 if (*handle == NULL)
1177 memcpy(*handle, ptr, length);
1178 (*handle)[length] = '\0';
1183 /* Collect multiple values for mgsnid specifiers */
1184 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
1186 struct lnet_nid nid;
1192 /* Find end of NID-list */
1193 while (class_parse_nid_quiet(tail, &nid, &tail) == 0)
1196 length = tail - *ptr;
1198 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
1202 if (lmd->lmd_mgs != NULL)
1203 oldlen = strlen(lmd->lmd_mgs) + 1;
1205 OBD_ALLOC(mgsnid, oldlen + length + 1);
1209 if (lmd->lmd_mgs != NULL) {
1210 /* Multiple mgsnid= are taken to mean failover locations */
1211 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
1212 mgsnid[oldlen - 1] = ':';
1213 OBD_FREE(lmd->lmd_mgs, oldlen);
1215 memcpy(mgsnid + oldlen, *ptr, length);
1216 mgsnid[oldlen + length] = '\0';
1217 lmd->lmd_mgs = mgsnid;
1224 * Find the first delimiter (comma or colon) from the specified \a buf and
1225 * make \a *endh point to the string starting with the delimiter. The commas
1226 * in expression list [...] will be skipped.
1228 * @buf a delimiter-separated string
1229 * @endh a pointer to a pointer that will point to the string
1230 * starting with the delimiter
1232 * RETURNS true if delimiter is found, false if delimiter is not found
1234 static bool lmd_find_delimiter(char *buf, char **endh)
1243 if (*c == ',' || *c == ':')
1246 pos = strcspn(c, "[:,]");
1250 /* Not a valid mount string */
1252 CWARN("invalid mount string format\n");
1260 /* invalid mount string */
1262 CWARN("invalid mount string format\n");
1277 * Find the first valid string delimited by comma or colon from the specified
1278 * \a buf and parse it to see whether it's a valid NID list. If yes, \a *endh
1279 * will point to the next string starting with the delimiter.
1281 * \param[in] buf a delimiter-separated string
1282 * \param[in] endh a pointer to a pointer that will point to the string
1283 * starting with the delimiter
1285 * \retval 0 if the string is a valid NID list
1286 * \retval 1 if the string is not a valid NID list
1288 static int lmd_parse_nidlist(char *buf, char **endh)
1297 while (*buf == ',' || *buf == ':')
1299 if (*buf == ' ' || *buf == '/' || *buf == '\0')
1302 if (!lmd_find_delimiter(buf, &endp))
1303 endp = buf + strlen(buf);
1308 if (cfs_parse_nidlist(buf, strlen(buf), &nidlist) <= 0)
1310 cfs_free_nidlist(&nidlist);
1321 * Parse mount line options
1322 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
1323 * dev is passed as device=uml1:/lustre by mount.lustre_tgt
1325 int lmd_parse(char *options, struct lustre_mount_data *lmd)
1327 char *s1, *s2, *devname = NULL;
1328 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
1335 LCONSOLE_ERROR_MSG(0x162,
1336 "Missing mount data: check /sbin/mount.lustre_tgt is installed.\n");
1340 /* Options should be a string - try to detect old lmd data */
1341 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1342 LCONSOLE_ERROR_MSG(0x163,
1343 "Using an old version of /sbin/mount.lustre. Please install version %s\n",
1344 LUSTRE_VERSION_STRING);
1347 lmd->lmd_magic = LMD_MAGIC;
1349 OBD_ALLOC(lmd->lmd_params, LMD_PARAMS_MAXLEN);
1350 if (lmd->lmd_params == NULL)
1352 lmd->lmd_params[0] = '\0';
1354 /* Set default flags here */
1359 int time_min = OBD_RECOVERY_TIME_MIN;
1362 /* Skip whitespace and extra commas */
1363 while (*s1 == ' ' || *s1 == ',')
1368 * Client options are parsed in ll_options: eg. flock,
1373 * Parse non-ldiskfs options here. Rather than modifying
1374 * ldiskfs, we just zero these out here
1376 if (!strncmp(s1, "abort_recov_mdt", 15) ||
1377 !strncmp(s1, "abort_recovery_mdt", 18)) {
1378 set_bit(LMD_FLG_ABORT_RECOV_MDT, lmd->lmd_flags);
1380 } else if (strncmp(s1, "abort_recov", 11) == 0) {
1381 set_bit(LMD_FLG_ABORT_RECOV, lmd->lmd_flags);
1383 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
1384 lmd->lmd_recovery_time_soft =
1385 max_t(int, simple_strtoul(s1 + 19, NULL, 10),
1388 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
1389 lmd->lmd_recovery_time_hard =
1390 max_t(int, simple_strtoul(s1 + 19, NULL, 10),
1393 } else if (strncmp(s1, "no_precreate", 12) == 0) {
1394 set_bit(LMD_FLG_NO_PRECREATE, lmd->lmd_flags);
1396 } else if (strncmp(s1, "noir", 4) == 0) { /* test case only */
1397 set_bit(LMD_FLG_NOIR, lmd->lmd_flags);
1399 } else if (strncmp(s1, "nosvc", 5) == 0) {
1400 set_bit(LMD_FLG_NOSVC, lmd->lmd_flags);
1402 } else if (strncmp(s1, "nomgs", 5) == 0) {
1403 set_bit(LMD_FLG_NOMGS, lmd->lmd_flags);
1405 } else if (strncmp(s1, "noscrub", 7) == 0) {
1406 set_bit(LMD_FLG_NOSCRUB, lmd->lmd_flags);
1408 } else if (strncmp(s1, "skip_lfsck", 10) == 0) {
1409 set_bit(LMD_FLG_SKIP_LFSCK, lmd->lmd_flags);
1411 } else if (strncmp(s1, "rdonly_dev", 10) == 0) {
1412 set_bit(LMD_FLG_DEV_RDONLY, lmd->lmd_flags);
1414 } else if (strncmp(s1, PARAM_MGSNODE,
1415 sizeof(PARAM_MGSNODE) - 1) == 0) {
1416 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
1418 * Assume the next mount opt is the first
1419 * invalid NID we get to.
1421 rc = lmd_parse_mgs(lmd, &s2);
1426 } else if (strncmp(s1, "writeconf", 9) == 0) {
1427 set_bit(LMD_FLG_WRITECONF, lmd->lmd_flags);
1429 } else if (strncmp(s1, "nolocallogs", 11) == 0) {
1430 set_bit(LMD_FLG_NO_LOCAL_LOGS, lmd->lmd_flags);
1432 } else if (strncmp(s1, "update", 6) == 0) {
1433 set_bit(LMD_FLG_UPDATE, lmd->lmd_flags);
1435 } else if (strncmp(s1, "virgin", 6) == 0) {
1436 set_bit(LMD_FLG_VIRGIN, lmd->lmd_flags);
1438 } else if (strncmp(s1, "noprimnode", 10) == 0) {
1439 set_bit(LMD_FLG_NO_PRIMNODE, lmd->lmd_flags);
1441 } else if (strncmp(s1, "mgssec=", 7) == 0) {
1442 rc = lmd_parse_mgssec(lmd, s1 + 7);
1446 /* ost exclusion list */
1447 } else if (strncmp(s1, "exclude=", 8) == 0) {
1448 rc = lmd_make_exclusion(lmd, s1 + 7);
1452 } else if (strncmp(s1, "mgs", 3) == 0) {
1454 set_bit(LMD_FLG_MGS, lmd->lmd_flags);
1456 } else if (strncmp(s1, "svname=", 7) == 0) {
1457 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
1461 } else if (strncmp(s1, "param=", 6) == 0) {
1462 size_t length, params_length;
1465 if (lmd_find_delimiter(s1 + 6, &tail)) {
1466 char *param_str = tail + 1;
1467 int supplementary = 1;
1469 while (lmd_parse_nidlist(param_str,
1473 length = param_str - s1 - supplementary;
1475 length = strlen(s1);
1478 params_length = strlen(lmd->lmd_params);
1479 if (params_length + length + 1 >= LMD_PARAMS_MAXLEN)
1481 strncat(lmd->lmd_params, s1 + 6, length);
1482 lmd->lmd_params[params_length + length] = '\0';
1483 strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
1484 s3 = s1 + 6 + length;
1486 } else if (strncmp(s1, "localrecov", 10) == 0) {
1487 set_bit(LMD_FLG_LOCAL_RECOV, lmd->lmd_flags);
1489 } else if (strncmp(s1, "osd=", 4) == 0) {
1490 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1496 * Linux 2.4 doesn't pass the device, so we stuck it at
1497 * the end of the options.
1499 else if (strncmp(s1, "device=", 7) == 0) {
1502 * terminate options right before device. device
1503 * must be the last one.
1507 } else if (strncmp(s1, "network=", 8) == 0) {
1508 rc = lmd_parse_network(lmd, s1 + 8);
1512 /* check if LNet dynamic peer discovery is activated */
1513 if (LNetGetPeerDiscoveryStatus()) {
1514 CERROR("LNet Dynamic Peer Discovery is enabled "
1515 "on this node. 'network' mount option "
1516 "cannot be taken into account.\n");
1524 s2 = strchr(s3, ',');
1532 memmove(s1, s2, strlen(s2) + 1);
1538 LCONSOLE_ERROR_MSG(0x164,
1539 "Can't find device name (need mount option 'device=...')\n");
1543 s1 = strstr(devname, ":/");
1546 set_bit(LMD_FLG_CLIENT, lmd->lmd_flags);
1547 /* Remove leading /s from fsname */
1548 while (*++s1 == '/')
1551 while (*s2 != '/' && *s2 != '\0')
1553 /* Freed in lustre_free_lsi */
1554 OBD_ALLOC(lmd->lmd_profile, s2 - s1 + 8);
1555 if (!lmd->lmd_profile)
1558 strncat(lmd->lmd_profile, s1, s2 - s1);
1559 strncat(lmd->lmd_profile, "-client", 7);
1562 s2 = s1 + strlen(s1) - 1;
1563 /* Remove padding /s from fileset */
1567 OBD_ALLOC(lmd->lmd_fileset, s2 - s1 + 2);
1568 if (lmd->lmd_fileset == NULL) {
1569 OBD_FREE(lmd->lmd_profile,
1570 strlen(lmd->lmd_profile) + 1);
1573 strncat(lmd->lmd_fileset, s1, s2 - s1 + 1);
1577 if (lmd->lmd_nidnet != NULL) {
1578 /* 'network=' mount option forbidden for server */
1579 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
1580 lmd->lmd_nidnet = NULL;
1583 "%s: option 'network=' not allowed for Lustre servers: rc = %d\n",
1589 /* Freed in lustre_free_lsi */
1590 OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
1593 strncpy(lmd->lmd_dev, devname, strlen(devname)+1);
1595 /* Save mount options */
1596 s1 = options + strlen(options) - 1;
1597 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1599 while (*options && (*options == ',' || *options == ' '))
1601 if (*options != 0) {
1602 /* Freed in lustre_free_lsi */
1603 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
1606 strncpy(lmd->lmd_opts, options, strlen(options)+1);
1614 CERROR("Bad mount options %s\n", options);
1617 EXPORT_SYMBOL(lmd_parse);