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/types.h>
44 #include <linux/parser.h>
45 #include <linux/random.h>
46 #include <linux/uuid.h>
47 #include <linux/version.h>
50 #include <obd_class.h>
51 #include <lustre_crypto.h>
52 #include <lustre_log.h>
53 #include <lustre_disk.h>
54 #include <uapi/linux/lustre/lustre_param.h>
56 /**************** config llog ********************/
59 * Get a config log from the MGS and process it.
60 * This func is called for both clients and servers.
61 * Continue to process new statements appended to the logs
62 * (whenever the config lock is revoked) until lustre_end_log
65 * @param sb The superblock is used by the MGC to write to the local copy of
67 * @param logname The name of the llog to replicate from the MGS
68 * @param cfg Since the same MGC may be used to follow multiple config logs
69 * (e.g. ost1, ost2, client), the config_llog_instance keeps the state for
70 * this log, and is added to the mgc's list of logs to follow.
72 int lustre_process_log(struct super_block *sb, char *logname,
73 struct config_llog_instance *cfg)
75 struct lustre_cfg *lcfg;
76 struct lustre_cfg_bufs *bufs;
77 struct lustre_sb_info *lsi = s2lsi(sb);
78 struct obd_device *mgc = lsi->lsi_mgc;
90 /* mgc_process_config */
91 lustre_cfg_bufs_reset(bufs, mgc->obd_name);
92 lustre_cfg_bufs_set_string(bufs, 1, logname);
93 lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
94 lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
95 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
97 GOTO(out, rc = -ENOMEM);
98 lustre_cfg_init(lcfg, LCFG_LOG_START, bufs);
100 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
101 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
106 LCONSOLE_ERROR_MSG(0x15b,
107 "%s: Configuration from log %s failed from MGS %d. Check client and MGS are on compatible version.\n",
108 mgc->obd_name, logname, rc);
110 LCONSOLE_ERROR_MSG(0x15c,
111 "%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",
112 mgc->obd_name, logname, rc);
116 EXPORT_SYMBOL(lustre_process_log);
118 /* Stop watching this config log for updates */
119 int lustre_end_log(struct super_block *sb, char *logname,
120 struct config_llog_instance *cfg)
122 struct lustre_cfg *lcfg;
123 struct lustre_cfg_bufs bufs;
124 struct lustre_sb_info *lsi = s2lsi(sb);
125 struct obd_device *mgc = lsi->lsi_mgc;
133 /* mgc_process_config */
134 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
135 lustre_cfg_bufs_set_string(&bufs, 1, logname);
137 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
138 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
141 lustre_cfg_init(lcfg, LCFG_LOG_END, &bufs);
142 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
143 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
146 EXPORT_SYMBOL(lustre_end_log);
148 /**************** OBD start *******************/
151 * lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
152 * lctl (and do for echo cli/srv.
154 static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
155 char *s1, char *s2, char *s3, char *s4)
157 struct lustre_cfg_bufs bufs;
158 struct lustre_cfg *lcfg = NULL;
161 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
162 cmd, s1, s2, s3, s4);
164 lustre_cfg_bufs_reset(&bufs, cfgname);
166 lustre_cfg_bufs_set_string(&bufs, 1, s1);
168 lustre_cfg_bufs_set_string(&bufs, 2, s2);
170 lustre_cfg_bufs_set_string(&bufs, 3, s3);
172 lustre_cfg_bufs_set_string(&bufs, 4, s4);
174 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
177 lustre_cfg_init(lcfg, cmd, &bufs);
178 lcfg->lcfg_nid = nid;
179 rc = class_process_config(lcfg);
180 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
184 static int do_lcfg_nid(char *cfgname, struct lnet_nid *nid, int cmd,
190 if (nid_is_nid4(nid))
191 nid4 = lnet_nid_to_nid4(nid);
193 nidstr = libcfs_nidstr(nid);
194 return do_lcfg(cfgname, nid4, cmd, s1, nidstr, NULL, NULL);
198 * Call class_attach and class_setup. These methods in turn call
199 * OBD type-specific methods.
202 int lustre_start_simple(char *obdname, char *type, char *uuid,
203 char *s1, char *s2, char *s3, char *s4)
207 CDEBUG(D_MOUNT, "Starting OBD %s (typ=%s)\n", obdname, type);
209 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
211 CERROR("%s attach error %d\n", obdname, rc);
214 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
216 CERROR("%s setup error %d\n", obdname, rc);
217 do_lcfg(obdname, 0, LCFG_DETACH, NULL, NULL, NULL, NULL);
221 SERVER_ONLY_EXPORT_SYMBOL(lustre_start_simple);
223 static DEFINE_MUTEX(mgc_start_lock);
226 * Set up a MGC OBD to process startup logs
228 * \param sb [in] super block of the MGC OBD
230 * \retval 0 success, otherwise error code
232 int lustre_start_mgc(struct super_block *sb)
234 struct obd_connect_data *data = NULL;
235 struct lustre_sb_info *lsi = s2lsi(sb);
236 struct obd_device *obd;
237 struct obd_export *exp;
238 struct obd_uuid *uuid = NULL;
241 char nidstr[LNET_NIDSTR_SIZE];
242 char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
244 int rc = 0, i = 0, j;
249 LASSERT(lsi->lsi_lmd);
251 /* Find the first non-lo MGS NID for our MGC name */
252 if (IS_SERVER(lsi)) {
253 /* mount -o mgsnode=nid */
254 ptr = lsi->lsi_lmd->lmd_mgs;
255 if (lsi->lsi_lmd->lmd_mgs &&
256 (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) {
258 } else if (IS_MGS(lsi)) {
259 struct lnet_processid id;
261 while ((rc = LNetGetId(i++, &id, true)) != -ENOENT) {
262 if (nid_is_lo0(&id.nid))
269 } else { /* client */
270 /* Use NIDs from mount line: uml1,1@elan:uml2,2@elan:/lustre */
271 ptr = lsi->lsi_lmd->lmd_dev;
272 if (class_parse_nid(ptr, &nid, &ptr) == 0)
276 CERROR("No valid MGS NIDs found.\n");
280 mutex_lock(&mgc_start_lock);
282 libcfs_nidstr_r(&nid, nidstr, sizeof(nidstr));
283 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(nidstr) + 1;
284 OBD_ALLOC(mgcname, len);
285 OBD_ALLOC(niduuid, len + 2);
286 if (mgcname == NULL || niduuid == NULL)
287 GOTO(out_free, rc = -ENOMEM);
288 snprintf(mgcname, len, "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
290 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
294 GOTO(out_free, rc = -ENOMEM);
296 obd = class_name2obd(mgcname);
297 if (obd && !obd->obd_stopping) {
300 rc = obd_set_info_async(NULL, obd->obd_self_export,
301 strlen(KEY_MGSSEC), KEY_MGSSEC,
302 strlen(mgssec), mgssec, NULL);
306 /* Re-using an existing MGC */
307 atomic_inc(&obd->u.cli.cl_mgc_refcount);
309 /* IR compatibility check, only for clients */
310 if (lmd_is_client(lsi->lsi_lmd)) {
312 int vallen = sizeof(*data);
314 rc = obd_get_info(NULL, obd->obd_self_export,
315 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
318 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
319 if (has_ir ^ !test_bit(LMD_FLG_NOIR,
320 lsi->lsi_lmd->lmd_flags)) {
321 /* LMD_FLG_NOIR is for test purpose only */
323 "Mounting client with IR setting not compatible with current MGC. Using MGC setting that is IR %s",
324 has_ir ? "enabled" : "disabled");
326 clear_bit(LMD_FLG_NOIR,
327 lsi->lsi_lmd->lmd_flags);
329 set_bit(LMD_FLG_NOIR,
330 lsi->lsi_lmd->lmd_flags);
337 * If we are restarting the MGS, don't try to keep the MGC's
338 * old connection, or registration will fail.
341 CDEBUG(D_MOUNT, "New MGS with live MGC\n");
346 * Try all connections, but only once (again).
347 * We don't want to block another target from starting
348 * (using its local copy of the log), but we do want to connect
349 * if at all possible.
352 CDEBUG(D_MOUNT, "%s:Set MGC reconnect %d\n", mgcname, recov_bk);
353 rc = obd_set_info_async(NULL, obd->obd_self_export,
354 sizeof(KEY_INIT_RECOV_BACKUP),
355 KEY_INIT_RECOV_BACKUP,
356 sizeof(recov_bk), &recov_bk, NULL);
360 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
362 /* Add the primary NIDs for the MGS */
364 snprintf(niduuid, len + 2, "%s_%x", mgcname, i);
365 if (IS_SERVER(lsi)) {
366 ptr = lsi->lsi_lmd->lmd_mgs;
367 CDEBUG(D_MOUNT, "mgs NIDs %s.\n", ptr);
369 /* Use local NIDs (including LO) */
370 struct lnet_processid id;
372 while ((rc = LNetGetId(i++, &id, true)) != -ENOENT) {
373 rc = do_lcfg_nid(mgcname, &id.nid,
378 /* Use mgsnode= nids */
379 /* mount -o mgsnode=nid */
380 if (lsi->lsi_lmd->lmd_mgs) {
381 ptr = lsi->lsi_lmd->lmd_mgs;
382 } else if (class_find_param(ptr, PARAM_MGSNODE,
384 CERROR("No MGS NIDs given.\n");
385 GOTO(out_free, rc = -EINVAL);
388 * Add primary MGS NID(s).
389 * Multiple NIDs on one MGS node are separated
392 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
393 rc = do_lcfg_nid(mgcname, &nid,
398 /* Stop at the first failover NID */
403 } else { /* client */
404 /* Use NIDs from mount line: uml1,1@elan:uml2,2@elan:/lustre */
405 ptr = lsi->lsi_lmd->lmd_dev;
406 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
407 rc = do_lcfg_nid(mgcname, &nid, LCFG_ADD_UUID,
411 /* Stop at the first failover NID */
417 CERROR("No valid MGS NIDs found.\n");
418 GOTO(out_free, rc = -EINVAL);
420 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
422 /* Random uuid for MGC allows easier reconnects */
425 GOTO(out_free, rc = -ENOMEM);
427 generate_random_uuid(uuidc.b);
428 snprintf(uuid->uuid, sizeof(*uuid), "%pU", uuidc.b);
431 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
432 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
433 niduuid, NULL, NULL);
437 /* Add any failover MGS NIDs */
439 while (ptr && ((*ptr == ':' ||
440 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
441 /* New failover node */
442 sprintf(niduuid, "%s_%x", mgcname, i);
444 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
445 rc = do_lcfg_nid(mgcname, &nid, LCFG_ADD_UUID,
453 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
454 niduuid, NULL, NULL, NULL);
462 lsi->lsi_lmd->lmd_mgs_failnodes = i;
464 obd = class_name2obd(mgcname);
466 CERROR("Can't find mgcobd %s\n", mgcname);
467 GOTO(out_free, rc = -ENOTCONN);
470 rc = obd_set_info_async(NULL, obd->obd_self_export,
471 strlen(KEY_MGSSEC), KEY_MGSSEC,
472 strlen(mgssec), mgssec, NULL);
477 * Keep a refcount of servers/clients who started with "mount",
478 * so we know when we can get rid of the mgc.
480 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
482 /* We connect to the MGS at setup, and don't disconnect until cleanup */
483 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
484 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
485 OBD_CONNECT_LVB_TYPE |
486 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_BARRIER |
488 data->ocd_connect_flags2 = OBD_CONNECT2_REP_MBITS |
489 OBD_CONNECT2_LARGE_NID;
491 if (lmd_is_client(lsi->lsi_lmd) &&
492 test_bit(LMD_FLG_NOIR, lsi->lsi_lmd->lmd_flags))
493 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
494 data->ocd_version = LUSTRE_VERSION_CODE;
495 rc = obd_connect(NULL, &exp, obd, uuid, data, NULL);
497 CERROR("connect failed %d\n", rc);
501 obd->u.cli.cl_mgc_mgsexp = exp;
505 * Keep the MGC info in the sb. Note that many lsi's can point
510 mutex_unlock(&mgc_start_lock);
517 OBD_FREE(mgcname, len);
519 OBD_FREE(niduuid, len + 2);
522 EXPORT_SYMBOL(lustre_start_mgc);
524 SERVER_ONLY int lustre_stop_mgc(struct super_block *sb)
526 struct lustre_sb_info *lsi = s2lsi(sb);
527 struct obd_device *obd;
528 char niduuid[MAX_OBD_NAME + 6], *ptr = NULL;
540 mutex_lock(&mgc_start_lock);
541 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
542 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
544 * This is not fatal, every client that stops
547 CDEBUG(D_MOUNT, "MGC still has %d references.\n",
548 atomic_read(&obd->u.cli.cl_mgc_refcount));
549 GOTO(out, rc = -EBUSY);
553 * The MGC has no recoverable data in any case.
554 * force shotdown set in umount_begin
556 obd->obd_no_recov = 1;
558 if (obd->u.cli.cl_mgc_mgsexp) {
560 * An error is not fatal, if we are unable to send the
561 * disconnect mgs ping evictor cleans up the export
563 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
565 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
569 * Cache the obdname for cleaning the nid uuids, which are
570 * obdname_XX before calling class_manual_cleanup
572 strcpy(niduuid, obd->obd_name);
573 ptr = niduuid + strlen(niduuid);
575 rc = class_manual_cleanup(obd);
579 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
580 sprintf(ptr, "_%x", i);
581 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
582 niduuid, NULL, NULL, NULL);
584 CERROR("del MDC UUID %s failed: rc = %d\n",
588 /* class_import_put will get rid of the additional connections */
589 mutex_unlock(&mgc_start_lock);
592 SERVER_ONLY_EXPORT_SYMBOL(lustre_stop_mgc);
594 /***************** lustre superblock **************/
596 struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
598 struct lustre_sb_info *lsi;
605 OBD_ALLOC_PTR(lsi->lsi_lmd);
611 s2lsi_nocast(sb) = lsi;
612 /* we take 1 extra ref for our setup */
613 kref_init(&lsi->lsi_mounts);
615 /* Default umount style */
616 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
617 INIT_LIST_HEAD(&lsi->lsi_lwp_list);
618 mutex_init(&lsi->lsi_lwp_mutex);
622 EXPORT_SYMBOL(lustre_init_lsi);
624 static int lustre_free_lsi(struct lustre_sb_info *lsi)
628 LASSERT(lsi != NULL);
629 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
631 /* someone didn't call server_put_mount. */
632 LASSERT(kref_read(&lsi->lsi_mounts) == 0);
634 llcrypt_sb_free(lsi);
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);
676 static void lustre_put_lsi_free(struct kref *kref)
678 struct lustre_sb_info *lsi = container_of(kref, struct lustre_sb_info,
681 if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
682 lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
683 lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
684 lsi->lsi_dt_dev = NULL;
685 obd_disconnect(lsi->lsi_osd_exp);
686 /* wait till OSD is gone */
687 obd_zombie_barrier();
689 lustre_free_lsi(lsi);
693 * The lsi has one reference for every server that is using the disk -
694 * e.g. MDT, MGS, and potentially MGC
696 int lustre_put_lsi(struct super_block *sb)
698 struct lustre_sb_info *lsi = s2lsi(sb);
702 LASSERT(lsi != NULL);
704 CDEBUG(D_MOUNT, "put %p %d\n", sb, kref_read(&lsi->lsi_mounts));
705 if (kref_put(&lsi->lsi_mounts, lustre_put_lsi_free)) {
706 s2lsi_nocast(sb) = NULL;
711 EXPORT_SYMBOL(lustre_put_lsi);
714 * The goal of this function is to extract the file system name
715 * from the OBD name. This can come in two flavors. One is
716 * fsname-MDTXXXX or fsname-XXXXXXX were X is a hexadecimal
717 * number. In both cases we should return fsname. If it is
718 * not a valid OBD name it is assumed to be the file system
721 void obdname2fsname(const char *tgt, char *fsname, size_t buflen)
728 * First we have to see if the @tgt has '-' at all. It is
729 * valid for the user to request something like
730 * lctl set_param -P llite.lustre*.xattr_cache=0
732 ptr = strrchr(tgt, '-');
734 /* No '-' means it could end in '*' */
735 ptr = strchr(tgt, '*');
737 /* No '*' either. Assume tgt = fsname */
745 /* tgt format fsname-MDT0000-* */
746 if ((!strncmp(ptr, "-MDT", 4) ||
747 !strncmp(ptr, "-OST", 4)) &&
748 (isxdigit(ptr[4]) && isxdigit(ptr[5]) &&
749 isxdigit(ptr[6]) && isxdigit(ptr[7]))) {
755 * tgt_format fsname-cli'dev'-'uuid' except for the llite case
756 * which are named fsname-'uuid'. Examples:
758 * lustre-clilov-ffff88104db5b800
759 * lustre-ffff88104db5b800 (for llite device)
761 * The length of the OBD uuid can vary on different platforms.
762 * This test if any invalid characters are in string. Allow
763 * wildcards with '*' character.
766 if (!strspn(ptr, "0123456789abcdefABCDEF*")) {
772 * Now that we validated the device name lets extract the
773 * file system name. Most of the names in this class will
774 * have '-cli' in its name which needs to be dropped. If
775 * it doesn't have '-cli' then its a llite device which
776 * ptr already points to the start of the uuid string.
778 tmp = strstr(tgt, "-cli");
785 len = min_t(size_t, len, LUSTRE_MAXFSNAME);
786 snprintf(fsname, buflen, "%.*s", (int)len, tgt);
790 EXPORT_SYMBOL(obdname2fsname);
794 * <FSNAME><SEPARATOR><TYPE><INDEX>
795 * FSNAME is between 1 and 8 characters (inclusive).
796 * Excluded characters are '/' and ':'
797 * SEPARATOR is either ':' or '-'
798 * TYPE: "OST", "MDT", etc.
799 * INDEX: Hex representation of the index
803 * Get the fsname ("lustre") from the server name ("lustre-OST003F").
804 * @param [in] svname server name including type and index
805 * @param [out] fsname Buffer to copy filesystem name prefix into.
806 * Must have at least 'strlen(fsname) + 1' chars.
807 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
810 int server_name2fsname(const char *svname, char *fsname, const char **endptr)
814 dash = svname + strnlen(svname, LUSTRE_MAXFSNAME);
815 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
820 if (fsname != NULL) {
821 strncpy(fsname, svname, dash - svname);
822 fsname[dash - svname] = '\0';
830 EXPORT_SYMBOL(server_name2fsname);
832 #ifdef HAVE_SERVER_SUPPORT
834 * Get service name (svname) from string
836 * if endptr isn't NULL it is set to end of fsname *
838 int server_name2svname(const char *label, char *svname, const char **endptr,
844 /* We use server_name2fsname() just for parsing */
845 rc = server_name2fsname(label, NULL, &dash);
852 rc = strscpy(svname, dash + 1, svsize);
858 EXPORT_SYMBOL(server_name2svname);
859 #endif /* HAVE_SERVER_SUPPORT */
861 #ifdef HAVE_SERVER_SUPPORT
863 * check server name is OST.
865 int server_name_is_ost(const char *svname)
870 /* We use server_name2fsname() just for parsing */
871 rc = server_name2fsname(svname, NULL, &dash);
877 if (strncmp(dash, "OST", 3) == 0)
881 EXPORT_SYMBOL(server_name_is_ost);
882 #endif /* HAVE_SERVER_SUPPORT */
885 * Get the index from the target name MDTXXXX/OSTXXXX
886 * rc = server type, or rc < 0 on error
888 SERVER_ONLY int target_name2index(const char *tgtname, u32 *idx, const char **endptr)
890 const char *dash = tgtname;
894 if (strncmp(dash, "MDT", 3) == 0)
895 type = LDD_F_SV_TYPE_MDT;
896 else if (strncmp(dash, "OST", 3) == 0)
897 type = LDD_F_SV_TYPE_OST;
903 if (strncmp(dash, "all", 3) == 0) {
906 return type | LDD_F_SV_ALL;
909 len = strspn(dash, "0123456789ABCDEFabcdef");
913 if (strlen(dash) != len) {
917 memcpy(num, dash, sizeof(num) - 1);
918 rc = kstrtou16(num, 16, &index);
922 rc = kstrtou16(dash, 16, &index);
931 *endptr = dash + len;
935 SERVER_ONLY_EXPORT_SYMBOL(target_name2index);
938 * Get the index from the OBD name.
939 * rc = server type, or
941 * if endptr isn't NULL it is set to end of name
943 int server_name2index(const char *svname, __u32 *idx, const char **endptr)
948 /* We use server_name2fsname() just for parsing */
949 rc = server_name2fsname(svname, NULL, &dash);
954 rc = target_name2index(dash, idx, endptr);
958 /* Account for -mdc after index that is possible when specifying mdt */
959 if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
960 sizeof(LUSTRE_MDC_NAME)-1) == 0)
961 *endptr += sizeof(LUSTRE_MDC_NAME);
965 EXPORT_SYMBOL(server_name2index);
967 /*************** mount common betweeen server and client ***************/
970 int lustre_common_put_super(struct super_block *sb)
976 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
978 /* Drop a ref to the MGC */
979 rc = lustre_stop_mgc(sb);
980 if (rc && (rc != -ENOENT)) {
982 CERROR("Can't stop MGC: %d\n", rc);
986 * BUSY just means that there's some other OBD that
987 * needs the mgc. Let him clean it up.
989 CDEBUG(D_MOUNT, "MGC still in use\n");
991 /* Drop a ref to the mounted disk */
996 EXPORT_SYMBOL(lustre_common_put_super);
998 static void lmd_print(struct lustre_mount_data *lmd)
1002 PRINT_CMD(D_MOUNT, " mount data:\n");
1003 if (lmd_is_client(lmd))
1004 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
1005 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
1008 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
1010 if (lmd->lmd_recovery_time_soft)
1011 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
1012 lmd->lmd_recovery_time_soft);
1014 if (lmd->lmd_recovery_time_hard)
1015 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
1016 lmd->lmd_recovery_time_hard);
1018 for (i = 0; i < lmd->lmd_exclude_count; i++) {
1019 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
1020 lmd->lmd_exclude[i]);
1024 /* Is this server on the exclusion list */
1025 int lustre_check_exclusion(struct super_block *sb, char *svname)
1027 struct lustre_sb_info *lsi = s2lsi(sb);
1028 struct lustre_mount_data *lmd = lsi->lsi_lmd;
1034 rc = server_name2index(svname, &index, NULL);
1035 if (rc != LDD_F_SV_TYPE_OST)
1036 /* Only exclude OSTs */
1039 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
1040 index, lmd->lmd_exclude_count, lmd->lmd_dev);
1042 for (i = 0; i < lmd->lmd_exclude_count; i++) {
1043 if (index == lmd->lmd_exclude[i]) {
1044 CWARN("Excluding %s (on exclusion list)\n", svname);
1051 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
1052 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
1054 const char *s1 = ptr, *s2;
1055 __u32 *exclude_list;
1062 * The shortest an ost name can be is 8 chars: -OST0000.
1063 * We don't actually know the fsname at this time, so in fact
1064 * a user could specify any fsname.
1066 devmax = strlen(ptr) / 8 + 1;
1068 /* temp storage until we figure out how many we have */
1069 OBD_ALLOC_PTR_ARRAY(exclude_list, devmax);
1073 /* we enter this fn pointing at the '=' */
1074 while (*s1 && *s1 != ' ' && *s1 != ',') {
1076 rc = server_name2index(s1, &index, &s2);
1078 CERROR("Can't parse server name '%s': rc = %d\n",
1082 if (rc == LDD_F_SV_TYPE_OST)
1083 exclude_list[lmd->lmd_exclude_count++] = index;
1085 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
1086 (uint)(s2-s1), s1, rc);
1089 * now we are pointing at ':' (next exclude)
1090 * or ',' (end of excludes)
1092 if (lmd->lmd_exclude_count >= devmax)
1095 if (rc >= 0) /* non-err */
1098 if (lmd->lmd_exclude_count) {
1099 /* permanent, freed in lustre_free_lsi */
1100 OBD_ALLOC_PTR_ARRAY(lmd->lmd_exclude,
1101 lmd->lmd_exclude_count);
1102 if (lmd->lmd_exclude) {
1103 memcpy(lmd->lmd_exclude, exclude_list,
1104 sizeof(index) * lmd->lmd_exclude_count);
1107 lmd->lmd_exclude_count = 0;
1110 OBD_FREE_PTR_ARRAY(exclude_list, devmax);
1114 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
1116 int length = strlen(ptr);
1118 if (lmd->lmd_mgssec != NULL) {
1119 OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
1120 lmd->lmd_mgssec = NULL;
1123 OBD_ALLOC(lmd->lmd_mgssec, length + 1);
1124 if (lmd->lmd_mgssec == NULL)
1127 memcpy(lmd->lmd_mgssec, ptr, length);
1128 lmd->lmd_mgssec[length] = '\0';
1132 static int lmd_parse_network(struct lustre_mount_data *lmd, char *ptr)
1134 int length = strlen(ptr);
1136 if (lmd->lmd_nidnet != NULL) {
1137 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
1138 lmd->lmd_nidnet = NULL;
1141 OBD_ALLOC(lmd->lmd_nidnet, length + 1);
1142 if (lmd->lmd_nidnet == NULL)
1145 memcpy(lmd->lmd_nidnet, ptr, length);
1146 lmd->lmd_nidnet[length] = '\0';
1150 static int lmd_parse_string(char **handle, char *ptr)
1152 if (!handle || !ptr)
1155 OBD_FREE(*handle, strlen(*handle) + 1);
1158 *handle = kstrdup(ptr, GFP_NOFS);
1162 OBD_ALLOC_POST(*handle, strlen(ptr) + 1, "kmalloced");
1167 /* Collect multiple values for mgsnid specifiers */
1168 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char *ptr, char **tail)
1170 int length = strlen(ptr);
1171 struct lnet_nid nid;
1176 /* Find end of NID-list */
1177 while (class_parse_nid_quiet(*tail, &nid, tail) == 0)
1180 if (next && next != *tail)
1181 length += *tail - next + 1;
1183 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", ptr);
1187 if (lmd->lmd_mgs != NULL)
1188 oldlen = strlen(lmd->lmd_mgs) + 1;
1190 OBD_ALLOC(mgsnid, oldlen + length + 1);
1194 if (lmd->lmd_mgs != NULL) {
1195 /* Multiple mgsnid= are taken to mean failover locations */
1196 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
1197 mgsnid[oldlen - 1] = ':';
1198 OBD_FREE(lmd->lmd_mgs, oldlen);
1201 if (next && next != *tail)
1202 snprintf(mgsnid + oldlen, length + 1, "%s,%.*s", ptr,
1203 (int)(*tail - next + 1), next);
1205 snprintf(mgsnid + oldlen, length + 1, "%s", ptr);
1206 lmd->lmd_mgs = mgsnid;
1211 enum lmd_mnt_flags {
1212 LMD_OPT_RECOVERY_TIME_SOFT = LMD_FLG_NUM_FLAGS + 1,
1213 LMD_OPT_RECOVERY_TIME_HARD,
1225 static const match_table_t lmd_flags_table = {
1226 {LMD_FLG_SKIP_LFSCK, "skip_lfsck"},
1227 {LMD_FLG_ABORT_RECOV, "abort_recov"},
1228 {LMD_FLG_ABORT_RECOV, "abort_recovery"},
1229 {LMD_FLG_NOSVC, "nosvc"},
1230 {LMD_FLG_MGS, "mgs"},
1231 {LMD_FLG_NOMGS, "nomgs"},
1232 {LMD_FLG_WRITECONF, "writeconf"},
1233 {LMD_FLG_NOIR, "noir"},
1234 {LMD_FLG_NOSCRUB, "noscrub"},
1235 {LMD_FLG_NO_PRIMNODE, "noprimnode"},
1236 {LMD_FLG_VIRGIN, "virgin"},
1237 {LMD_FLG_UPDATE, "update"},
1238 {LMD_FLG_DEV_RDONLY, "rdonly_dev"},
1239 {LMD_FLG_NO_CREATE, "no_create"},
1240 {LMD_FLG_NO_CREATE, "no_precreate"},
1241 {LMD_FLG_LOCAL_RECOV, "localrecov"},
1242 {LMD_FLG_ABORT_RECOV_MDT, "abort_recov_mdt"},
1243 {LMD_FLG_ABORT_RECOV_MDT, "abort_recovery_mdt"},
1244 {LMD_FLG_NO_LOCAL_LOGS, "nolocallogs"},
1246 {LMD_OPT_RECOVERY_TIME_SOFT, "recovery_time_soft=%u"},
1247 {LMD_OPT_RECOVERY_TIME_HARD, "recovery_time_hard=%u"},
1248 {LMD_OPT_MGSNODE, "mgsnode=%s"},
1249 {LMD_OPT_MGSSEC, "mgssec=%s"},
1250 {LMD_OPT_EXCLUDE, "exclude=%s"},
1251 {LMD_OPT_SVNAME, "svname=%s"},
1252 {LMD_OPT_PARAM, "param=%s"},
1253 {LMD_OPT_OSD, "osd=%s"},
1254 {LMD_OPT_NETWORK, "network=%s"},
1255 {LMD_OPT_DEVICE, "device=%s"}, /* should be last */
1256 {LMD_NUM_MOUNT_OPT, NULL}
1260 * Find the first delimiter; comma; from the specified \a buf and
1261 * make \a *endh point to the string starting with the delimiter.
1262 * The character ':' is also a delimiter for Lustre but not match_table
1263 * so the string is not split on it. Making it safe to ignore.
1265 * @buf a delimiter-separated string
1266 * @endh a pointer to a pointer that will point to the string
1267 * starting with the delimiter
1269 * Returns: true if delimiter is found, false if delimiter is not found
1271 static bool lmd_find_delimiter(char *buf, char **endh)
1273 substring_t args[LMD_NUM_MOUNT_OPT];
1281 /* No more options so we are done */
1282 end = strchr(buf, ',');
1287 tmp = kstrndup(buf, len, GFP_KERNEL);
1292 args[0].from = NULL;
1293 token = match_token(tmp, lmd_flags_table, args);
1295 if (token != LMD_NUM_MOUNT_OPT)
1305 * Make sure the string in \a buf is of a valid formt.
1307 * @buf a delimiter-separated string
1309 * Returns: true if string valid, false if string contains errors
1311 static bool lmd_validate_param(char *buf)
1319 pos = strcspn(c, "[]");
1324 /* Not a valid mount string */
1326 CWARN("invalid mount string format\n");
1331 char *right = strchr(c, ']'), *tmp;
1333 /* invalid mount string */
1335 CWARN("invalid mount string format\n");
1340 /* Test for [ .. [ .. ] */
1341 tmp = strchr(c, '[');
1342 if (tmp && tmp < right) {
1343 CWARN("invalid mount string format\n");
1347 /* Test for [ .. @ .. ] which means brackets
1348 * span more than one NID string.
1350 tmp = strchr(c, '@');
1351 if (tmp && tmp < right) {
1352 CWARN("invalid mount string format\n");
1364 * Find the first valid string delimited by comma or colon from the specified
1365 * @buf and parse it to see whether it's a valid nid list. If yes, @*endh
1366 * will point to the next string starting with the delimiter.
1368 * @buf: a delimiter-separated string
1370 * Returns: false if the string is a valid nid list
1371 * true if the string is not a valid nid list
1373 static bool lmd_parse_nidlist(char *buf)
1382 end = strchr(buf, '=');
1386 while ((end = strchr(buf, '@')) != NULL) {
1387 size_t pos = strcspn(end, ":,");
1393 /* FIXME !!! Add IPv6 support to cfs_parse_nidlist */
1394 if (strchr(buf, ':')) {
1395 struct lnet_nid nid;
1397 if (libcfs_strnid(&nid, buf) < 0) {
1402 if (cfs_parse_nidlist(buf, &nidlist) < 0) {
1406 cfs_free_nidlist(&nidlist);
1419 * Parse mount line options
1420 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
1421 * dev is passed as device=uml1:/lustre by mount.lustre_tgt
1423 int lmd_parse(char *options, struct lustre_mount_data *lmd)
1425 char *s1, *s2, *opts, *orig_opts, *devname = NULL;
1426 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
1432 LCONSOLE_ERROR_MSG(0x162,
1433 "Missing mount data: check /sbin/mount.lustre_tgt is installed.\n");
1437 /* Options should be a string - try to detect old lmd data */
1438 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1439 LCONSOLE_ERROR_MSG(0x163,
1440 "Using an old version of /sbin/mount.lustre. Please install version %s\n",
1441 LUSTRE_VERSION_STRING);
1444 lmd->lmd_magic = LMD_MAGIC;
1446 /* Don't stomp on lmd_opts */
1447 opts = kstrdup(options, GFP_KERNEL);
1453 OBD_ALLOC(lmd->lmd_params, LMD_PARAMS_MAXLEN);
1454 if (!lmd->lmd_params)
1455 GOTO(invalid, rc = -ENOMEM);
1456 lmd->lmd_params[0] = '\0';
1458 /* Set default flags here */
1459 while ((s1 = strsep(&opts, ",")) != NULL) {
1460 int time_min = OBD_RECOVERY_TIME_MIN, tmp;
1461 substring_t args[LMD_NUM_MOUNT_OPT];
1467 * Initialize args struct so we know whether arg was
1468 * found; some options take optional arguments.
1471 args[0].from = NULL;
1472 token = match_token(s1, lmd_flags_table, args);
1473 if (token == LMD_NUM_MOUNT_OPT) {
1474 if (match_wildcard("iam", s1) ||
1475 match_wildcard("hsm", s1))
1478 /* Normally we would error but client and
1479 * server mounting is intertwine. So pass
1480 * off unknown args to ll_options instead.
1484 /* We found a known server option. Filter out
1485 * the result out of the options string. The
1486 * reset will be stored in lmd_opts.
1488 char *tmp = strstr(options, s1);
1490 if (strcmp(tmp, s1) != 0) {
1491 s2 = tmp + strlen(s1) + 1;
1492 memmove(tmp, s2, strlen(s2) + 1);
1499 * Client options are parsed in ll_options: eg. flock,
1504 * Parse non-ldiskfs options here. Rather than modifying
1505 * ldiskfs, we just zero these out here
1508 case LMD_FLG_ABORT_RECOV_MDT:
1509 case LMD_FLG_ABORT_RECOV:
1510 case LMD_FLG_NO_CREATE:
1511 case LMD_FLG_NOIR: /* test purpose only. */
1514 case LMD_FLG_NOSCRUB:
1515 case LMD_FLG_SKIP_LFSCK:
1516 case LMD_FLG_DEV_RDONLY:
1517 case LMD_FLG_WRITECONF:
1518 case LMD_FLG_NO_LOCAL_LOGS:
1519 case LMD_FLG_UPDATE:
1520 case LMD_FLG_VIRGIN:
1521 case LMD_FLG_NO_PRIMNODE:
1522 case LMD_FLG_MGS: /* We are an MGS */
1523 case LMD_FLG_LOCAL_RECOV:
1524 set_bit(token, lmd->lmd_flags);
1526 case LMD_OPT_RECOVERY_TIME_SOFT:
1527 rc = match_int(args, &tmp);
1529 lmd->lmd_recovery_time_soft = max_t(int, tmp,
1532 case LMD_OPT_RECOVERY_TIME_HARD:
1533 rc = match_int(args, &tmp);
1535 lmd->lmd_recovery_time_hard = max_t(int, tmp,
1538 case LMD_OPT_MGSNODE:
1539 /* Assume the next mount opt is the first
1540 * invalid NID we get to.
1542 rc = lmd_parse_mgs(lmd, args->from, &opts);
1546 if (strcmp(options, opts) != 0) {
1547 s2 = strstr(options, opts);
1552 case LMD_OPT_MGSSEC:
1553 rc = lmd_parse_mgssec(lmd, args->from);
1555 case LMD_OPT_EXCLUDE:
1556 /* ost exclusion list */
1557 rc = lmd_make_exclusion(lmd, args->from);
1559 case LMD_OPT_SVNAME:
1560 rc = lmd_parse_string(&lmd->lmd_profile, args->from);
1562 case LMD_OPT_PARAM: {
1563 size_t length = strlen(args->from), params_length;
1564 char *tail = NULL, *entry;
1566 params_length = strlen(lmd->lmd_params);
1567 if (params_length + length + 1 >= LMD_PARAMS_MAXLEN) {
1571 entry = lmd->lmd_params + params_length;
1572 strncat(lmd->lmd_params, args->from, length);
1574 /* Find end of param string */
1575 while (lmd_find_delimiter(opts, &tail)) {
1576 params_length = strlen(lmd->lmd_params);
1577 /* match_table splits by ',' so fill it in */
1578 lmd->lmd_params[params_length++] = ',';
1580 length = tail - opts + 1;
1583 if (params_length + length + 1 >=
1584 LMD_PARAMS_MAXLEN) {
1589 strscpy(lmd->lmd_params + params_length,
1594 lmd->lmd_params[params_length + length] = '\0';
1596 if (!lmd_validate_param(entry)) {
1601 /* param contains NIDs */
1602 if (strchr(entry, '@') && lmd_parse_nidlist(entry)) {
1607 /* remove params from opts string from options string */
1608 if (strlen(args->from) != strlen(entry)) {
1609 char *tmp = entry + strlen(args->from) + 1;
1611 s2 = strstr(options, tmp);
1613 size_t len = strlen(s2) - strlen(tmp);
1615 memmove(s2, s2 + strlen(tmp) + 1, len);
1619 strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
1626 rc = lmd_parse_string(&lmd->lmd_osd_type, args->from);
1628 case LMD_OPT_DEVICE: {
1631 /* match_table splits strings at ',' so we need to
1632 * piece things back together.
1635 len = strlen(opts) + 1;
1637 /* Move to last part of device string */
1638 s2 = strchr(opts, '/');
1640 GOTO(invalid, rc = -EINVAL);
1642 /* See if more options exist */
1643 s2 = strchr(s2, ',');
1647 len += strlen(args->from) + 1;
1649 /* Freed in lustre_free_lsi */
1650 OBD_ALLOC(lmd->lmd_dev, len);
1652 GOTO(invalid, rc = -ENOMEM);
1655 snprintf(lmd->lmd_dev, len, "%s,%s",
1658 strscpy(lmd->lmd_dev, args->from, len);
1660 devname = lmd->lmd_dev;
1662 /* remove the split string 'opts' from options */
1664 s1 = strstr(options, opts);
1666 /* opts start after args->from so
1669 len -= strlen(args->from) + 2;
1671 memmove(options, s2, strlen(s2) + 1);
1677 case LMD_OPT_NETWORK:
1678 rc = lmd_parse_network(lmd, args->from);
1679 /* check if LNet dynamic peer discovery is activated */
1680 if (LNetGetPeerDiscoveryStatus()) {
1681 CERROR("LNet Dynamic Peer Discovery is enabled on this node. 'network' mount option cannot be taken into account.\n");
1691 LCONSOLE_ERROR_MSG(0x164,
1692 "Can't find device name (need mount option 'device=...')\n");
1693 GOTO(invalid, rc = -ENODEV);
1696 s1 = strstr(devname, ":/");
1699 set_bit(LMD_FLG_CLIENT, lmd->lmd_flags);
1700 /* Remove leading /s from fsname */
1701 while (*++s1 == '/')
1704 while (*s2 != '/' && *s2 != '\0')
1706 /* Freed in lustre_free_lsi */
1707 OBD_ALLOC(lmd->lmd_profile, s2 - s1 + 8);
1708 if (!lmd->lmd_profile)
1709 GOTO(invalid, rc = -ENOMEM);
1711 strncat(lmd->lmd_profile, s1, s2 - s1);
1712 strncat(lmd->lmd_profile, "-client", 7);
1715 s2 = s1 + strlen(s1) - 1;
1716 /* Remove padding /s from fileset */
1720 OBD_ALLOC(lmd->lmd_fileset, s2 - s1 + 2);
1721 if (!lmd->lmd_fileset)
1722 GOTO(invalid, rc = -ENOMEM);
1723 strncat(lmd->lmd_fileset, s1, s2 - s1 + 1);
1727 if (lmd->lmd_nidnet != NULL) {
1728 /* 'network=' mount option forbidden for server */
1729 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
1730 lmd->lmd_nidnet = NULL;
1732 CERROR("%s: option 'network=' not allowed for Lustre servers: rc = %d\n",
1738 /* Save mount options */
1739 s1 = options + strlen(options) - 1;
1740 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1742 while (*options && (*options == ',' || *options == ' '))
1744 if (*options != 0) {
1745 /* Freed in lustre_free_lsi */
1746 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
1748 GOTO(invalid, rc = -ENOMEM);
1749 strncpy(lmd->lmd_opts, options, strlen(options));
1755 CERROR("Bad mount options %s\n", options);
1760 EXPORT_SYMBOL(lmd_parse);