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, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/obdclass/obd_mount.c
34 * Client mount routines
36 * Author: Nathan Rutman <nathan@clusterfs.com>
39 #define DEBUG_SUBSYSTEM S_CLASS
40 #define D_MOUNT (D_SUPER | D_CONFIG/*|D_WARNING */)
41 #define PRINT_CMD CDEBUG
43 #include "../include/obd.h"
44 #include "../include/lustre_compat.h"
45 #include "../include/obd_class.h"
46 #include "../include/lustre/lustre_user.h"
47 #include "../include/lustre_log.h"
48 #include "../include/lustre_disk.h"
49 #include "../include/lustre_param.h"
51 static int (*client_fill_super)(struct super_block *sb,
52 struct vfsmount *mnt);
54 static void (*kill_super_cb)(struct super_block *sb);
56 /**************** config llog ********************/
58 /** Get a config log from the MGS and process it.
59 * This func is called for both clients and servers.
60 * Continue to process new statements appended to the logs
61 * (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;
82 bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
86 /* mgc_process_config */
87 lustre_cfg_bufs_reset(bufs, mgc->obd_name);
88 lustre_cfg_bufs_set_string(bufs, 1, logname);
89 lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
90 lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
91 lcfg = lustre_cfg_new(LCFG_LOG_START, bufs);
92 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
93 lustre_cfg_free(lcfg);
98 LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s' failed from the MGS (%d). Make sure this client and the MGS are running compatible versions of Lustre.\n",
99 mgc->obd_name, logname, rc);
102 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' failed (%d). This may be the result of communication errors between this node and the MGS, a bad configuration, or other errors. See the syslog for more information.\n",
103 mgc->obd_name, logname,
106 /* class_obd_list(); */
109 EXPORT_SYMBOL(lustre_process_log);
111 /* Stop watching this config log for updates */
112 int lustre_end_log(struct super_block *sb, char *logname,
113 struct config_llog_instance *cfg)
115 struct lustre_cfg *lcfg;
116 struct lustre_cfg_bufs bufs;
117 struct lustre_sb_info *lsi = s2lsi(sb);
118 struct obd_device *mgc = lsi->lsi_mgc;
124 /* mgc_process_config */
125 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
126 lustre_cfg_bufs_set_string(&bufs, 1, logname);
128 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
129 lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
130 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
131 lustre_cfg_free(lcfg);
134 EXPORT_SYMBOL(lustre_end_log);
136 /**************** obd start *******************/
138 /** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
139 * lctl (and do for echo cli/srv.
141 static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
142 char *s1, char *s2, char *s3, char *s4)
144 struct lustre_cfg_bufs bufs;
145 struct lustre_cfg *lcfg = NULL;
148 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
149 cmd, s1, s2, s3, s4);
151 lustre_cfg_bufs_reset(&bufs, cfgname);
153 lustre_cfg_bufs_set_string(&bufs, 1, s1);
155 lustre_cfg_bufs_set_string(&bufs, 2, s2);
157 lustre_cfg_bufs_set_string(&bufs, 3, s3);
159 lustre_cfg_bufs_set_string(&bufs, 4, s4);
161 lcfg = lustre_cfg_new(cmd, &bufs);
162 lcfg->lcfg_nid = nid;
163 rc = class_process_config(lcfg);
164 lustre_cfg_free(lcfg);
168 /** Call class_attach and class_setup. These methods in turn call
169 * obd type-specific methods.
171 static int lustre_start_simple(char *obdname, char *type, char *uuid,
172 char *s1, char *s2, char *s3, char *s4)
176 CDEBUG(D_MOUNT, "Starting obd %s (typ=%s)\n", obdname, type);
178 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
180 CERROR("%s attach error %d\n", obdname, rc);
183 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
185 CERROR("%s setup error %d\n", obdname, rc);
186 do_lcfg(obdname, 0, LCFG_DETACH, NULL, NULL, NULL, NULL);
191 static DEFINE_MUTEX(mgc_start_lock);
193 /** Set up a mgc obd to process startup logs
195 * \param sb [in] super block of the mgc obd
197 * \retval 0 success, otherwise error code
199 int lustre_start_mgc(struct super_block *sb)
201 struct obd_connect_data *data = NULL;
202 struct lustre_sb_info *lsi = s2lsi(sb);
203 struct obd_device *obd;
204 struct obd_export *exp;
205 struct obd_uuid *uuid;
208 char nidstr[LNET_NIDSTR_SIZE];
209 char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
211 int rc = 0, i = 0, j;
213 LASSERT(lsi->lsi_lmd);
215 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
216 ptr = lsi->lsi_lmd->lmd_dev;
217 if (class_parse_nid(ptr, &nid, &ptr) == 0)
220 CERROR("No valid MGS nids found.\n");
224 mutex_lock(&mgc_start_lock);
226 libcfs_nid2str_r(nid, nidstr, sizeof(nidstr));
227 mgcname = kasprintf(GFP_NOFS,
228 "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
229 niduuid = kasprintf(GFP_NOFS, "%s_%x", mgcname, i);
230 if (!mgcname || !niduuid) {
235 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
237 data = kzalloc(sizeof(*data), GFP_NOFS);
243 obd = class_name2obd(mgcname);
244 if (obd && !obd->obd_stopping) {
247 rc = obd_set_info_async(NULL, obd->obd_self_export,
248 strlen(KEY_MGSSEC), KEY_MGSSEC,
249 strlen(mgssec), mgssec, NULL);
253 /* Re-using an existing MGC */
254 atomic_inc(&obd->u.cli.cl_mgc_refcount);
256 /* IR compatibility check, only for clients */
257 if (lmd_is_client(lsi->lsi_lmd)) {
259 int vallen = sizeof(*data);
260 __u32 *flags = &lsi->lsi_lmd->lmd_flags;
262 rc = obd_get_info(NULL, obd->obd_self_export,
263 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
264 &vallen, data, NULL);
266 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
267 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
268 /* LMD_FLG_NOIR is for test purpose only */
270 "Trying to mount a client with IR setting not compatible with current mgc. Force to use current mgc setting that is IR %s.\n",
271 has_ir ? "enabled" : "disabled");
273 *flags &= ~LMD_FLG_NOIR;
275 *flags |= LMD_FLG_NOIR;
281 /* Try all connections, but only once (again).
282 * We don't want to block another target from starting
283 * (using its local copy of the log), but we do want to connect
284 * if at all possible.
287 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,
289 rc = obd_set_info_async(NULL, obd->obd_self_export,
290 sizeof(KEY_INIT_RECOV_BACKUP),
291 KEY_INIT_RECOV_BACKUP,
292 sizeof(recov_bk), &recov_bk, NULL);
297 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
299 /* Add the primary nids for the MGS */
301 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
302 ptr = lsi->lsi_lmd->lmd_dev;
303 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
304 rc = do_lcfg(mgcname, nid,
305 LCFG_ADD_UUID, niduuid, NULL, NULL, NULL);
308 /* Stop at the first failover nid */
313 CERROR("No valid MGS nids found.\n");
317 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
319 /* Random uuid for MGC allows easier reconnects */
320 uuid = kzalloc(sizeof(*uuid), GFP_NOFS);
326 ll_generate_random_uuid(uuidc);
327 class_uuid_unparse(uuidc, uuid);
330 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
331 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
332 niduuid, NULL, NULL);
337 /* Add any failover MGS nids */
339 while (ptr && ((*ptr == ':' ||
340 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
341 /* New failover node */
342 sprintf(niduuid, "%s_%x", mgcname, i);
344 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
345 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID, niduuid,
353 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
354 niduuid, NULL, NULL, NULL);
362 lsi->lsi_lmd->lmd_mgs_failnodes = i;
364 obd = class_name2obd(mgcname);
366 CERROR("Can't find mgcobd %s\n", mgcname);
371 rc = obd_set_info_async(NULL, obd->obd_self_export,
372 strlen(KEY_MGSSEC), KEY_MGSSEC,
373 strlen(mgssec), mgssec, NULL);
377 /* Keep a refcount of servers/clients who started with "mount",
378 * so we know when we can get rid of the mgc.
380 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
382 /* We connect to the MGS at setup, and don't disconnect until cleanup */
383 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
384 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
385 OBD_CONNECT_LVB_TYPE;
387 #if OBD_OCD_VERSION(3, 0, 53, 0) > LUSTRE_VERSION_CODE
388 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
391 if (lmd_is_client(lsi->lsi_lmd) &&
392 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
393 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
394 data->ocd_version = LUSTRE_VERSION_CODE;
395 rc = obd_connect(NULL, &exp, obd, &obd->obd_uuid, data, NULL);
397 CERROR("connect failed %d\n", rc);
401 obd->u.cli.cl_mgc_mgsexp = exp;
404 /* Keep the mgc info in the sb. Note that many lsi's can point
409 mutex_unlock(&mgc_start_lock);
417 static int lustre_stop_mgc(struct super_block *sb)
419 struct lustre_sb_info *lsi = s2lsi(sb);
420 struct obd_device *obd;
421 char *niduuid = NULL, *ptr = NULL;
422 int i, rc = 0, len = 0;
431 mutex_lock(&mgc_start_lock);
432 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
433 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
434 /* This is not fatal, every client that stops
437 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
438 atomic_read(&obd->u.cli.cl_mgc_refcount));
443 /* The MGC has no recoverable data in any case.
444 * force shutdown set in umount_begin
446 obd->obd_no_recov = 1;
448 if (obd->u.cli.cl_mgc_mgsexp) {
449 /* An error is not fatal, if we are unable to send the
450 * disconnect mgs ping evictor cleans up the export
452 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
454 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
457 /* Save the obdname for cleaning the nid uuids, which are obdname_XX */
458 len = strlen(obd->obd_name) + 6;
459 niduuid = kzalloc(len, GFP_NOFS);
461 strcpy(niduuid, obd->obd_name);
462 ptr = niduuid + strlen(niduuid);
465 rc = class_manual_cleanup(obd);
469 /* Clean the nid uuids */
475 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
476 sprintf(ptr, "_%x", i);
477 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
478 niduuid, NULL, NULL, NULL);
480 CERROR("del MDC UUID %s failed: rc = %d\n",
486 /* class_import_put will get rid of the additional connections */
487 mutex_unlock(&mgc_start_lock);
491 /***************** lustre superblock **************/
493 static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
495 struct lustre_sb_info *lsi;
497 lsi = kzalloc(sizeof(*lsi), GFP_NOFS);
500 lsi->lsi_lmd = kzalloc(sizeof(*lsi->lsi_lmd), GFP_NOFS);
506 lsi->lsi_lmd->lmd_exclude_count = 0;
507 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
508 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
509 s2lsi_nocast(sb) = lsi;
510 /* we take 1 extra ref for our setup */
511 atomic_set(&lsi->lsi_mounts, 1);
513 /* Default umount style */
514 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
519 static int lustre_free_lsi(struct super_block *sb)
521 struct lustre_sb_info *lsi = s2lsi(sb);
523 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
525 /* someone didn't call server_put_mount. */
526 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
529 kfree(lsi->lsi_lmd->lmd_dev);
530 kfree(lsi->lsi_lmd->lmd_profile);
531 kfree(lsi->lsi_lmd->lmd_mgssec);
532 kfree(lsi->lsi_lmd->lmd_opts);
533 if (lsi->lsi_lmd->lmd_exclude_count)
534 kfree(lsi->lsi_lmd->lmd_exclude);
535 kfree(lsi->lsi_lmd->lmd_mgs);
536 kfree(lsi->lsi_lmd->lmd_osd_type);
537 kfree(lsi->lsi_lmd->lmd_params);
542 LASSERT(!lsi->lsi_llsbi);
544 s2lsi_nocast(sb) = NULL;
549 /* The lsi has one reference for every server that is using the disk -
550 * e.g. MDT, MGS, and potentially MGC
552 static int lustre_put_lsi(struct super_block *sb)
554 struct lustre_sb_info *lsi = s2lsi(sb);
556 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
557 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
565 * <FSNAME><SEPARATOR><TYPE><INDEX>
566 * FSNAME is between 1 and 8 characters (inclusive).
567 * Excluded characters are '/' and ':'
568 * SEPARATOR is either ':' or '-'
569 * TYPE: "OST", "MDT", etc.
570 * INDEX: Hex representation of the index
573 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
574 * @param [in] svname server name including type and index
575 * @param [out] fsname Buffer to copy filesystem name prefix into.
576 * Must have at least 'strlen(fsname) + 1' chars.
577 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
580 static int server_name2fsname(const char *svname, char *fsname,
585 dash = svname + strnlen(svname, 8); /* max fsname length is 8 */
586 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
592 strncpy(fsname, svname, dash - svname);
593 fsname[dash - svname] = '\0';
602 /* Get the index from the obd name.
603 * rc = server type, or
605 * if endptr isn't NULL it is set to end of name
607 static int server_name2index(const char *svname, __u32 *idx,
614 /* We use server_name2fsname() just for parsing */
615 rc = server_name2fsname(svname, NULL, &dash);
621 if (strncmp(dash, "MDT", 3) == 0)
622 rc = LDD_F_SV_TYPE_MDT;
623 else if (strncmp(dash, "OST", 3) == 0)
624 rc = LDD_F_SV_TYPE_OST;
630 if (strncmp(dash, "all", 3) == 0) {
633 return rc | LDD_F_SV_ALL;
636 index = simple_strtoul(dash, (char **)endptr, 16);
640 /* Account for -mdc after index that is possible when specifying mdt */
641 if (endptr && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
642 sizeof(LUSTRE_MDC_NAME) - 1) == 0)
643 *endptr += sizeof(LUSTRE_MDC_NAME);
648 /*************** mount common between server and client ***************/
651 int lustre_common_put_super(struct super_block *sb)
655 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
657 /* Drop a ref to the MGC */
658 rc = lustre_stop_mgc(sb);
659 if (rc && (rc != -ENOENT)) {
661 CERROR("Can't stop MGC: %d\n", rc);
664 /* BUSY just means that there's some other obd that
665 * needs the mgc. Let him clean it up.
667 CDEBUG(D_MOUNT, "MGC still in use\n");
669 /* Drop a ref to the mounted disk */
673 EXPORT_SYMBOL(lustre_common_put_super);
675 static void lmd_print(struct lustre_mount_data *lmd)
679 PRINT_CMD(D_MOUNT, " mount data:\n");
680 if (lmd_is_client(lmd))
681 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
682 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
683 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
686 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
688 if (lmd->lmd_recovery_time_soft)
689 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
690 lmd->lmd_recovery_time_soft);
692 if (lmd->lmd_recovery_time_hard)
693 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
694 lmd->lmd_recovery_time_hard);
696 for (i = 0; i < lmd->lmd_exclude_count; i++) {
697 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
698 lmd->lmd_exclude[i]);
702 /* Is this server on the exclusion list */
703 int lustre_check_exclusion(struct super_block *sb, char *svname)
705 struct lustre_sb_info *lsi = s2lsi(sb);
706 struct lustre_mount_data *lmd = lsi->lsi_lmd;
710 rc = server_name2index(svname, &index, NULL);
711 if (rc != LDD_F_SV_TYPE_OST)
712 /* Only exclude OSTs */
715 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
716 index, lmd->lmd_exclude_count, lmd->lmd_dev);
718 for (i = 0; i < lmd->lmd_exclude_count; i++) {
719 if (index == lmd->lmd_exclude[i]) {
720 CWARN("Excluding %s (on exclusion list)\n", svname);
727 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
728 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
730 const char *s1 = ptr, *s2;
731 __u32 index = 0, *exclude_list;
734 /* The shortest an ost name can be is 8 chars: -OST0000.
735 * We don't actually know the fsname at this time, so in fact
736 * a user could specify any fsname.
738 devmax = strlen(ptr) / 8 + 1;
740 /* temp storage until we figure out how many we have */
741 exclude_list = kcalloc(devmax, sizeof(index), GFP_NOFS);
745 /* we enter this fn pointing at the '=' */
746 while (*s1 && *s1 != ' ' && *s1 != ',') {
748 rc = server_name2index(s1, &index, &s2);
750 CERROR("Can't parse server name '%s': rc = %d\n",
754 if (rc == LDD_F_SV_TYPE_OST)
755 exclude_list[lmd->lmd_exclude_count++] = index;
757 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
758 (uint)(s2 - s1), s1, rc);
760 /* now we are pointing at ':' (next exclude)
761 * or ',' (end of excludes)
763 if (lmd->lmd_exclude_count >= devmax)
766 if (rc >= 0) /* non-err */
769 if (lmd->lmd_exclude_count) {
770 /* permanent, freed in lustre_free_lsi */
771 lmd->lmd_exclude = kcalloc(lmd->lmd_exclude_count,
772 sizeof(index), GFP_NOFS);
773 if (lmd->lmd_exclude) {
774 memcpy(lmd->lmd_exclude, exclude_list,
775 sizeof(index) * lmd->lmd_exclude_count);
778 lmd->lmd_exclude_count = 0;
785 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
790 kfree(lmd->lmd_mgssec);
791 lmd->lmd_mgssec = NULL;
793 tail = strchr(ptr, ',');
795 length = strlen(ptr);
799 lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS);
800 if (!lmd->lmd_mgssec)
803 memcpy(lmd->lmd_mgssec, ptr, length);
804 lmd->lmd_mgssec[length] = '\0';
808 static int lmd_parse_string(char **handle, char *ptr)
819 tail = strchr(ptr, ',');
821 length = strlen(ptr);
825 *handle = kzalloc(length + 1, GFP_NOFS);
829 memcpy(*handle, ptr, length);
830 (*handle)[length] = '\0';
835 /* Collect multiple values for mgsnid specifiers */
836 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
844 /* Find end of nidlist */
845 while (class_parse_nid_quiet(tail, &nid, &tail) == 0)
847 length = tail - *ptr;
849 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
854 oldlen = strlen(lmd->lmd_mgs) + 1;
856 mgsnid = kzalloc(oldlen + length + 1, GFP_NOFS);
861 /* Multiple mgsnid= are taken to mean failover locations */
862 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
863 mgsnid[oldlen - 1] = ':';
866 memcpy(mgsnid + oldlen, *ptr, length);
867 mgsnid[oldlen + length] = '\0';
868 lmd->lmd_mgs = mgsnid;
874 /** Parse mount line options
875 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
876 * dev is passed as device=uml1:/lustre by mount.lustre
878 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
880 char *s1, *s2, *s3, *devname = NULL;
881 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
886 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that /sbin/mount.lustre is installed.\n");
890 /* Options should be a string - try to detect old lmd data */
891 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
892 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of /sbin/mount.lustre. Please install version %s\n",
893 LUSTRE_VERSION_STRING);
896 lmd->lmd_magic = LMD_MAGIC;
898 lmd->lmd_params = kzalloc(LMD_PARAMS_MAXLEN, GFP_NOFS);
899 if (!lmd->lmd_params)
901 lmd->lmd_params[0] = '\0';
903 /* Set default flags here */
908 int time_min = OBD_RECOVERY_TIME_MIN;
910 /* Skip whitespace and extra commas */
911 while (*s1 == ' ' || *s1 == ',')
915 /* Client options are parsed in ll_options: eg. flock,
919 /* Parse non-ldiskfs options here. Rather than modifying
920 * ldiskfs, we just zero these out here
922 if (strncmp(s1, "abort_recov", 11) == 0) {
923 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
925 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
926 lmd->lmd_recovery_time_soft = max_t(int,
927 simple_strtoul(s1 + 19, NULL, 10), time_min);
929 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
930 lmd->lmd_recovery_time_hard = max_t(int,
931 simple_strtoul(s1 + 19, NULL, 10), time_min);
933 } else if (strncmp(s1, "noir", 4) == 0) {
934 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
936 } else if (strncmp(s1, "nosvc", 5) == 0) {
937 lmd->lmd_flags |= LMD_FLG_NOSVC;
939 } else if (strncmp(s1, "nomgs", 5) == 0) {
940 lmd->lmd_flags |= LMD_FLG_NOMGS;
942 } else if (strncmp(s1, "noscrub", 7) == 0) {
943 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
945 } else if (strncmp(s1, PARAM_MGSNODE,
946 sizeof(PARAM_MGSNODE) - 1) == 0) {
947 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
948 /* Assume the next mount opt is the first
949 * invalid nid we get to.
951 rc = lmd_parse_mgs(lmd, &s2);
955 } else if (strncmp(s1, "writeconf", 9) == 0) {
956 lmd->lmd_flags |= LMD_FLG_WRITECONF;
958 } else if (strncmp(s1, "update", 6) == 0) {
959 lmd->lmd_flags |= LMD_FLG_UPDATE;
961 } else if (strncmp(s1, "virgin", 6) == 0) {
962 lmd->lmd_flags |= LMD_FLG_VIRGIN;
964 } else if (strncmp(s1, "noprimnode", 10) == 0) {
965 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
967 } else if (strncmp(s1, "mgssec=", 7) == 0) {
968 rc = lmd_parse_mgssec(lmd, s1 + 7);
973 /* ost exclusion list */
974 } else if (strncmp(s1, "exclude=", 8) == 0) {
975 rc = lmd_make_exclusion(lmd, s1 + 7);
979 } else if (strncmp(s1, "mgs", 3) == 0) {
981 lmd->lmd_flags |= LMD_FLG_MGS;
983 } else if (strncmp(s1, "svname=", 7) == 0) {
984 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
988 } else if (strncmp(s1, "param=", 6) == 0) {
989 size_t length, params_length;
990 char *tail = strchr(s1 + 6, ',');
996 char *param_str = tail + 1;
997 int supplementary = 1;
999 while (!class_parse_nid_quiet(param_str, &nid,
1003 length = param_str - s1 - supplementary;
1006 params_length = strlen(lmd->lmd_params);
1007 if (params_length + length + 1 >= LMD_PARAMS_MAXLEN)
1009 strncat(lmd->lmd_params, s1 + 6, length);
1010 lmd->lmd_params[params_length + length] = '\0';
1011 strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
1012 s3 = s1 + 6 + length;
1014 } else if (strncmp(s1, "osd=", 4) == 0) {
1015 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1020 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1021 * end of the options.
1023 else if (strncmp(s1, "device=", 7) == 0) {
1025 /* terminate options right before device. device
1026 * must be the last one.
1033 s2 = strchr(s1, ',');
1041 memmove(s1, s2, strlen(s2) + 1);
1047 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name (need mount option 'device=...')\n");
1051 s1 = strstr(devname, ":/");
1054 lmd->lmd_flags |= LMD_FLG_CLIENT;
1055 /* Remove leading /s from fsname */
1056 while (*++s1 == '/')
1058 /* Freed in lustre_free_lsi */
1059 lmd->lmd_profile = kasprintf(GFP_NOFS, "%s-client", s1);
1060 if (!lmd->lmd_profile)
1064 /* Freed in lustre_free_lsi */
1065 lmd->lmd_dev = kzalloc(strlen(devname) + 1, GFP_NOFS);
1068 strcpy(lmd->lmd_dev, devname);
1070 /* Save mount options */
1071 s1 = options + strlen(options) - 1;
1072 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1074 if (*options != 0) {
1075 /* Freed in lustre_free_lsi */
1076 lmd->lmd_opts = kzalloc(strlen(options) + 1, GFP_NOFS);
1079 strcpy(lmd->lmd_opts, options);
1083 lmd->lmd_magic = LMD_MAGIC;
1088 CERROR("Bad mount options %s\n", options);
1092 struct lustre_mount_data2 {
1094 struct vfsmount *lmd2_mnt;
1097 /** This is the entry point for the mount call into Lustre.
1098 * This is called when a server or client is mounted,
1099 * and this is where we start setting things up.
1100 * @param data Mount options (e.g. -o flock,abort_recov)
1102 static int lustre_fill_super(struct super_block *sb, void *data, int silent)
1104 struct lustre_mount_data *lmd;
1105 struct lustre_mount_data2 *lmd2 = data;
1106 struct lustre_sb_info *lsi;
1109 CDEBUG(D_MOUNT | D_VFSTRACE, "VFS Op: sb %p\n", sb);
1111 lsi = lustre_init_lsi(sb);
1117 * Disable lockdep during mount, because mount locking patterns are
1123 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1125 obd_zombie_barrier();
1127 /* Figure out the lmd from the mount options */
1128 if (lmd_parse((lmd2->lmd2_data), lmd)) {
1134 if (lmd_is_client(lmd)) {
1135 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1136 if (!client_fill_super)
1137 request_module("lustre");
1138 if (!client_fill_super) {
1139 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for client mount! Is the 'lustre' module loaded?\n");
1143 rc = lustre_start_mgc(sb);
1145 lustre_common_put_super(sb);
1148 /* Connect and start */
1149 /* (should always be ll_fill_super) */
1150 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1151 /* c_f_s will call lustre_common_put_super on failure */
1154 CERROR("This is client-side-only module, cannot handle server mount.\n");
1158 /* If error happens in fill_super() call, @lsi will be killed there.
1159 * This is why we do not put it here.
1164 CERROR("Unable to mount %s (%d)\n",
1165 s2lsi(sb) ? lmd->lmd_dev : "", rc);
1167 CDEBUG(D_SUPER, "Mount %s complete\n",
1174 /* We can't call ll_fill_super by name because it lives in a module that
1175 * must be loaded after this one.
1177 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1178 struct vfsmount *mnt))
1180 client_fill_super = cfs;
1182 EXPORT_SYMBOL(lustre_register_client_fill_super);
1184 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1186 kill_super_cb = cfs;
1188 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1190 /***************** FS registration ******************/
1191 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1192 const char *devname, void *data)
1194 struct lustre_mount_data2 lmd2 = {
1199 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1202 static void lustre_kill_super(struct super_block *sb)
1204 struct lustre_sb_info *lsi = s2lsi(sb);
1206 if (kill_super_cb && lsi)
1207 (*kill_super_cb)(sb);
1209 kill_anon_super(sb);
1212 /** Register the "lustre" fs type
1214 static struct file_system_type lustre_fs_type = {
1215 .owner = THIS_MODULE,
1217 .mount = lustre_mount,
1218 .kill_sb = lustre_kill_super,
1219 .fs_flags = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV |
1220 FS_RENAME_DOES_D_MOVE,
1222 MODULE_ALIAS_FS("lustre");
1224 int lustre_register_fs(void)
1226 return register_filesystem(&lustre_fs_type);
1229 int lustre_unregister_fs(void)
1231 return unregister_filesystem(&lustre_fs_type);