4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/obd_mount.c
38 * Client mount routines
40 * Author: Nathan Rutman <nathan@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_CLASS
44 #define D_MOUNT (D_SUPER|D_CONFIG/*|D_WARNING */)
45 #define PRINT_CMD CDEBUG
47 #include "../include/obd.h"
48 #include "../include/linux/lustre_compat25.h"
49 #include "../include/obd_class.h"
50 #include "../include/lustre/lustre_user.h"
51 #include "../include/lustre_log.h"
52 #include "../include/lustre_disk.h"
53 #include "../include/lustre_param.h"
55 static int (*client_fill_super)(struct super_block *sb,
56 struct vfsmount *mnt);
58 static void (*kill_super_cb)(struct super_block *sb);
60 /**************** config llog ********************/
62 /** Get a config log from the MGS and process it.
63 * This func is called for both clients and servers.
64 * Continue to process new statements appended to the logs
65 * (whenever the config lock is revoked) until lustre_end_log
67 * @param sb The superblock is used by the MGC to write to the local copy of
69 * @param logname The name of the llog to replicate from the MGS
70 * @param cfg Since the same mgc may be used to follow multiple config logs
71 * (e.g. ost1, ost2, client), the config_llog_instance keeps the state for
72 * this log, and is added to the mgc's list of logs to follow.
74 int lustre_process_log(struct super_block *sb, char *logname,
75 struct config_llog_instance *cfg)
77 struct lustre_cfg *lcfg;
78 struct lustre_cfg_bufs *bufs;
79 struct lustre_sb_info *lsi = s2lsi(sb);
80 struct obd_device *mgc = lsi->lsi_mgc;
86 bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
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 lcfg = lustre_cfg_new(LCFG_LOG_START, bufs);
96 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
97 lustre_cfg_free(lcfg);
102 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",
103 mgc->obd_name, logname, rc);
106 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",
107 mgc->obd_name, logname,
110 /* class_obd_list(); */
113 EXPORT_SYMBOL(lustre_process_log);
115 /* Stop watching this config log for updates */
116 int lustre_end_log(struct super_block *sb, char *logname,
117 struct config_llog_instance *cfg)
119 struct lustre_cfg *lcfg;
120 struct lustre_cfg_bufs bufs;
121 struct lustre_sb_info *lsi = s2lsi(sb);
122 struct obd_device *mgc = lsi->lsi_mgc;
128 /* mgc_process_config */
129 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
130 lustre_cfg_bufs_set_string(&bufs, 1, logname);
132 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
133 lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
134 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
135 lustre_cfg_free(lcfg);
138 EXPORT_SYMBOL(lustre_end_log);
140 /**************** obd start *******************/
142 /** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
143 * lctl (and do for echo cli/srv.
145 static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
146 char *s1, char *s2, char *s3, char *s4)
148 struct lustre_cfg_bufs bufs;
149 struct lustre_cfg *lcfg = NULL;
152 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
153 cmd, s1, s2, s3, s4);
155 lustre_cfg_bufs_reset(&bufs, cfgname);
157 lustre_cfg_bufs_set_string(&bufs, 1, s1);
159 lustre_cfg_bufs_set_string(&bufs, 2, s2);
161 lustre_cfg_bufs_set_string(&bufs, 3, s3);
163 lustre_cfg_bufs_set_string(&bufs, 4, s4);
165 lcfg = lustre_cfg_new(cmd, &bufs);
166 lcfg->lcfg_nid = nid;
167 rc = class_process_config(lcfg);
168 lustre_cfg_free(lcfg);
172 /** Call class_attach and class_setup. These methods in turn call
173 * obd type-specific methods.
175 static int lustre_start_simple(char *obdname, char *type, char *uuid,
176 char *s1, char *s2, char *s3, char *s4)
180 CDEBUG(D_MOUNT, "Starting obd %s (typ=%s)\n", obdname, type);
182 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
184 CERROR("%s attach error %d\n", obdname, rc);
187 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
189 CERROR("%s setup error %d\n", obdname, rc);
190 do_lcfg(obdname, 0, LCFG_DETACH, NULL, NULL, NULL, NULL);
195 DEFINE_MUTEX(mgc_start_lock);
197 /** Set up a mgc obd to process startup logs
199 * \param sb [in] super block of the mgc obd
201 * \retval 0 success, otherwise error code
203 int lustre_start_mgc(struct super_block *sb)
205 struct obd_connect_data *data = NULL;
206 struct lustre_sb_info *lsi = s2lsi(sb);
207 struct obd_device *obd;
208 struct obd_export *exp;
209 struct obd_uuid *uuid;
212 char nidstr[LNET_NIDSTR_SIZE];
213 char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
215 int rc = 0, i = 0, j;
217 LASSERT(lsi->lsi_lmd);
219 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
220 ptr = lsi->lsi_lmd->lmd_dev;
221 if (class_parse_nid(ptr, &nid, &ptr) == 0)
224 CERROR("No valid MGS nids found.\n");
228 mutex_lock(&mgc_start_lock);
230 libcfs_nid2str_r(nid, nidstr, sizeof(nidstr));
231 mgcname = kasprintf(GFP_NOFS,
232 "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
233 niduuid = kasprintf(GFP_NOFS, "%s_%x", mgcname, i);
234 if (!mgcname || !niduuid) {
239 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
241 data = kzalloc(sizeof(*data), GFP_NOFS);
247 obd = class_name2obd(mgcname);
248 if (obd && !obd->obd_stopping) {
251 rc = obd_set_info_async(NULL, obd->obd_self_export,
252 strlen(KEY_MGSSEC), KEY_MGSSEC,
253 strlen(mgssec), mgssec, NULL);
257 /* Re-using an existing MGC */
258 atomic_inc(&obd->u.cli.cl_mgc_refcount);
260 /* IR compatibility check, only for clients */
261 if (lmd_is_client(lsi->lsi_lmd)) {
263 int vallen = sizeof(*data);
264 __u32 *flags = &lsi->lsi_lmd->lmd_flags;
266 rc = obd_get_info(NULL, obd->obd_self_export,
267 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
268 &vallen, data, NULL);
270 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
271 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
272 /* LMD_FLG_NOIR is for test purpose only */
274 "Trying to mount a client with IR setting not compatible with current mgc. Force to use current mgc setting that is IR %s.\n",
275 has_ir ? "enabled" : "disabled");
277 *flags &= ~LMD_FLG_NOIR;
279 *flags |= LMD_FLG_NOIR;
285 /* Try all connections, but only once (again).
286 * We don't want to block another target from starting
287 * (using its local copy of the log), but we do want to connect
288 * if at all possible.
291 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,
293 rc = obd_set_info_async(NULL, obd->obd_self_export,
294 sizeof(KEY_INIT_RECOV_BACKUP),
295 KEY_INIT_RECOV_BACKUP,
296 sizeof(recov_bk), &recov_bk, NULL);
301 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
303 /* Add the primary nids for the MGS */
305 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
306 ptr = lsi->lsi_lmd->lmd_dev;
307 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
308 rc = do_lcfg(mgcname, nid,
309 LCFG_ADD_UUID, niduuid, NULL, NULL, NULL);
312 /* Stop at the first failover nid */
317 CERROR("No valid MGS nids found.\n");
321 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
323 /* Random uuid for MGC allows easier reconnects */
324 uuid = kzalloc(sizeof(*uuid), GFP_NOFS);
330 ll_generate_random_uuid(uuidc);
331 class_uuid_unparse(uuidc, uuid);
334 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
335 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
336 niduuid, NULL, NULL);
341 /* Add any failover MGS nids */
343 while (ptr && ((*ptr == ':' ||
344 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
345 /* New failover node */
346 sprintf(niduuid, "%s_%x", mgcname, i);
348 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
349 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID, niduuid,
357 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
358 niduuid, NULL, NULL, NULL);
366 lsi->lsi_lmd->lmd_mgs_failnodes = i;
368 obd = class_name2obd(mgcname);
370 CERROR("Can't find mgcobd %s\n", mgcname);
375 rc = obd_set_info_async(NULL, obd->obd_self_export,
376 strlen(KEY_MGSSEC), KEY_MGSSEC,
377 strlen(mgssec), mgssec, NULL);
381 /* Keep a refcount of servers/clients who started with "mount",
382 * so we know when we can get rid of the mgc.
384 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
386 /* We connect to the MGS at setup, and don't disconnect until cleanup */
387 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
388 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
389 OBD_CONNECT_LVB_TYPE;
391 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
392 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
394 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
397 if (lmd_is_client(lsi->lsi_lmd) &&
398 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
399 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
400 data->ocd_version = LUSTRE_VERSION_CODE;
401 rc = obd_connect(NULL, &exp, obd, &(obd->obd_uuid), data, NULL);
403 CERROR("connect failed %d\n", rc);
407 obd->u.cli.cl_mgc_mgsexp = exp;
410 /* Keep the mgc info in the sb. Note that many lsi's can point
415 mutex_unlock(&mgc_start_lock);
423 static int lustre_stop_mgc(struct super_block *sb)
425 struct lustre_sb_info *lsi = s2lsi(sb);
426 struct obd_device *obd;
427 char *niduuid = NULL, *ptr = NULL;
428 int i, rc = 0, len = 0;
437 mutex_lock(&mgc_start_lock);
438 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
439 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
440 /* This is not fatal, every client that stops
443 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
444 atomic_read(&obd->u.cli.cl_mgc_refcount));
449 /* The MGC has no recoverable data in any case.
450 * force shutdown set in umount_begin
452 obd->obd_no_recov = 1;
454 if (obd->u.cli.cl_mgc_mgsexp) {
455 /* An error is not fatal, if we are unable to send the
456 * disconnect mgs ping evictor cleans up the export
458 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
460 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
463 /* Save the obdname for cleaning the nid uuids, which are obdname_XX */
464 len = strlen(obd->obd_name) + 6;
465 niduuid = kzalloc(len, GFP_NOFS);
467 strcpy(niduuid, obd->obd_name);
468 ptr = niduuid + strlen(niduuid);
471 rc = class_manual_cleanup(obd);
475 /* Clean the nid uuids */
481 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
482 sprintf(ptr, "_%x", i);
483 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
484 niduuid, NULL, NULL, NULL);
486 CERROR("del MDC UUID %s failed: rc = %d\n",
492 /* class_import_put will get rid of the additional connections */
493 mutex_unlock(&mgc_start_lock);
497 /***************** lustre superblock **************/
499 static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
501 struct lustre_sb_info *lsi;
503 lsi = kzalloc(sizeof(*lsi), GFP_NOFS);
506 lsi->lsi_lmd = kzalloc(sizeof(*lsi->lsi_lmd), GFP_NOFS);
512 lsi->lsi_lmd->lmd_exclude_count = 0;
513 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
514 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
515 s2lsi_nocast(sb) = lsi;
516 /* we take 1 extra ref for our setup */
517 atomic_set(&lsi->lsi_mounts, 1);
519 /* Default umount style */
520 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
525 static int lustre_free_lsi(struct super_block *sb)
527 struct lustre_sb_info *lsi = s2lsi(sb);
529 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
531 /* someone didn't call server_put_mount. */
532 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
535 kfree(lsi->lsi_lmd->lmd_dev);
536 kfree(lsi->lsi_lmd->lmd_profile);
537 kfree(lsi->lsi_lmd->lmd_mgssec);
538 kfree(lsi->lsi_lmd->lmd_opts);
539 if (lsi->lsi_lmd->lmd_exclude_count)
540 kfree(lsi->lsi_lmd->lmd_exclude);
541 kfree(lsi->lsi_lmd->lmd_mgs);
542 kfree(lsi->lsi_lmd->lmd_osd_type);
543 kfree(lsi->lsi_lmd->lmd_params);
548 LASSERT(!lsi->lsi_llsbi);
550 s2lsi_nocast(sb) = NULL;
555 /* The lsi has one reference for every server that is using the disk -
556 * e.g. MDT, MGS, and potentially MGC
558 static int lustre_put_lsi(struct super_block *sb)
560 struct lustre_sb_info *lsi = s2lsi(sb);
562 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
563 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
571 * <FSNAME><SEPARATOR><TYPE><INDEX>
572 * FSNAME is between 1 and 8 characters (inclusive).
573 * Excluded characters are '/' and ':'
574 * SEPARATOR is either ':' or '-'
575 * TYPE: "OST", "MDT", etc.
576 * INDEX: Hex representation of the index
579 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
580 * @param [in] svname server name including type and index
581 * @param [out] fsname Buffer to copy filesystem name prefix into.
582 * Must have at least 'strlen(fsname) + 1' chars.
583 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
586 static int server_name2fsname(const char *svname, char *fsname,
591 dash = svname + strnlen(svname, 8); /* max fsname length is 8 */
592 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
598 strncpy(fsname, svname, dash - svname);
599 fsname[dash - svname] = '\0';
608 /* Get the index from the obd name.
609 * rc = server type, or
611 * if endptr isn't NULL it is set to end of name
613 static int server_name2index(const char *svname, __u32 *idx,
620 /* We use server_name2fsname() just for parsing */
621 rc = server_name2fsname(svname, NULL, &dash);
627 if (strncmp(dash, "MDT", 3) == 0)
628 rc = LDD_F_SV_TYPE_MDT;
629 else if (strncmp(dash, "OST", 3) == 0)
630 rc = LDD_F_SV_TYPE_OST;
636 if (strncmp(dash, "all", 3) == 0) {
639 return rc | LDD_F_SV_ALL;
642 index = simple_strtoul(dash, (char **)endptr, 16);
646 /* Account for -mdc after index that is possible when specifying mdt */
647 if (endptr && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
648 sizeof(LUSTRE_MDC_NAME) - 1) == 0)
649 *endptr += sizeof(LUSTRE_MDC_NAME);
654 /*************** mount common between server and client ***************/
657 int lustre_common_put_super(struct super_block *sb)
661 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
663 /* Drop a ref to the MGC */
664 rc = lustre_stop_mgc(sb);
665 if (rc && (rc != -ENOENT)) {
667 CERROR("Can't stop MGC: %d\n", rc);
670 /* BUSY just means that there's some other obd that
671 * needs the mgc. Let him clean it up.
673 CDEBUG(D_MOUNT, "MGC still in use\n");
675 /* Drop a ref to the mounted disk */
680 EXPORT_SYMBOL(lustre_common_put_super);
682 static void lmd_print(struct lustre_mount_data *lmd)
686 PRINT_CMD(D_MOUNT, " mount data:\n");
687 if (lmd_is_client(lmd))
688 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
689 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
690 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
693 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
695 if (lmd->lmd_recovery_time_soft)
696 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
697 lmd->lmd_recovery_time_soft);
699 if (lmd->lmd_recovery_time_hard)
700 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
701 lmd->lmd_recovery_time_hard);
703 for (i = 0; i < lmd->lmd_exclude_count; i++) {
704 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
705 lmd->lmd_exclude[i]);
709 /* Is this server on the exclusion list */
710 int lustre_check_exclusion(struct super_block *sb, char *svname)
712 struct lustre_sb_info *lsi = s2lsi(sb);
713 struct lustre_mount_data *lmd = lsi->lsi_lmd;
717 rc = server_name2index(svname, &index, NULL);
718 if (rc != LDD_F_SV_TYPE_OST)
719 /* Only exclude OSTs */
722 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
723 index, lmd->lmd_exclude_count, lmd->lmd_dev);
725 for (i = 0; i < lmd->lmd_exclude_count; i++) {
726 if (index == lmd->lmd_exclude[i]) {
727 CWARN("Excluding %s (on exclusion list)\n", svname);
734 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
735 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
737 const char *s1 = ptr, *s2;
738 __u32 index, *exclude_list;
741 /* The shortest an ost name can be is 8 chars: -OST0000.
742 * We don't actually know the fsname at this time, so in fact
743 * a user could specify any fsname.
745 devmax = strlen(ptr) / 8 + 1;
747 /* temp storage until we figure out how many we have */
748 exclude_list = kcalloc(devmax, sizeof(index), GFP_NOFS);
752 /* we enter this fn pointing at the '=' */
753 while (*s1 && *s1 != ' ' && *s1 != ',') {
755 rc = server_name2index(s1, &index, &s2);
757 CERROR("Can't parse server name '%s': rc = %d\n",
761 if (rc == LDD_F_SV_TYPE_OST)
762 exclude_list[lmd->lmd_exclude_count++] = index;
764 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
765 (uint)(s2-s1), s1, rc);
767 /* now we are pointing at ':' (next exclude)
768 * or ',' (end of excludes)
770 if (lmd->lmd_exclude_count >= devmax)
773 if (rc >= 0) /* non-err */
776 if (lmd->lmd_exclude_count) {
777 /* permanent, freed in lustre_free_lsi */
778 lmd->lmd_exclude = kcalloc(lmd->lmd_exclude_count,
779 sizeof(index), GFP_NOFS);
780 if (lmd->lmd_exclude) {
781 memcpy(lmd->lmd_exclude, exclude_list,
782 sizeof(index) * lmd->lmd_exclude_count);
785 lmd->lmd_exclude_count = 0;
792 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
797 kfree(lmd->lmd_mgssec);
798 lmd->lmd_mgssec = NULL;
800 tail = strchr(ptr, ',');
802 length = strlen(ptr);
806 lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS);
807 if (!lmd->lmd_mgssec)
810 memcpy(lmd->lmd_mgssec, ptr, length);
811 lmd->lmd_mgssec[length] = '\0';
815 static int lmd_parse_string(char **handle, char *ptr)
826 tail = strchr(ptr, ',');
828 length = strlen(ptr);
832 *handle = kzalloc(length + 1, GFP_NOFS);
836 memcpy(*handle, ptr, length);
837 (*handle)[length] = '\0';
842 /* Collect multiple values for mgsnid specifiers */
843 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
851 /* Find end of nidlist */
852 while (class_parse_nid_quiet(tail, &nid, &tail) == 0)
854 length = tail - *ptr;
856 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
861 oldlen = strlen(lmd->lmd_mgs) + 1;
863 mgsnid = kzalloc(oldlen + length + 1, GFP_NOFS);
868 /* Multiple mgsnid= are taken to mean failover locations */
869 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
870 mgsnid[oldlen - 1] = ':';
873 memcpy(mgsnid + oldlen, *ptr, length);
874 mgsnid[oldlen + length] = '\0';
875 lmd->lmd_mgs = mgsnid;
881 /** Parse mount line options
882 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
883 * dev is passed as device=uml1:/lustre by mount.lustre
885 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
887 char *s1, *s2, *devname = NULL;
888 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
893 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that /sbin/mount.lustre is installed.\n");
897 /* Options should be a string - try to detect old lmd data */
898 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
899 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of /sbin/mount.lustre. Please install version %s\n",
900 LUSTRE_VERSION_STRING);
903 lmd->lmd_magic = LMD_MAGIC;
905 lmd->lmd_params = kzalloc(LMD_PARAMS_MAXLEN, GFP_NOFS);
906 if (!lmd->lmd_params)
908 lmd->lmd_params[0] = '\0';
910 /* Set default flags here */
915 int time_min = OBD_RECOVERY_TIME_MIN;
917 /* Skip whitespace and extra commas */
918 while (*s1 == ' ' || *s1 == ',')
921 /* Client options are parsed in ll_options: eg. flock,
925 /* Parse non-ldiskfs options here. Rather than modifying
926 * ldiskfs, we just zero these out here
928 if (strncmp(s1, "abort_recov", 11) == 0) {
929 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
931 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
932 lmd->lmd_recovery_time_soft = max_t(int,
933 simple_strtoul(s1 + 19, NULL, 10), time_min);
935 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
936 lmd->lmd_recovery_time_hard = max_t(int,
937 simple_strtoul(s1 + 19, NULL, 10), time_min);
939 } else if (strncmp(s1, "noir", 4) == 0) {
940 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
942 } else if (strncmp(s1, "nosvc", 5) == 0) {
943 lmd->lmd_flags |= LMD_FLG_NOSVC;
945 } else if (strncmp(s1, "nomgs", 5) == 0) {
946 lmd->lmd_flags |= LMD_FLG_NOMGS;
948 } else if (strncmp(s1, "noscrub", 7) == 0) {
949 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
951 } else if (strncmp(s1, PARAM_MGSNODE,
952 sizeof(PARAM_MGSNODE) - 1) == 0) {
953 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
954 /* Assume the next mount opt is the first
955 * invalid nid we get to.
957 rc = lmd_parse_mgs(lmd, &s2);
961 } else if (strncmp(s1, "writeconf", 9) == 0) {
962 lmd->lmd_flags |= LMD_FLG_WRITECONF;
964 } else if (strncmp(s1, "update", 6) == 0) {
965 lmd->lmd_flags |= LMD_FLG_UPDATE;
967 } else if (strncmp(s1, "virgin", 6) == 0) {
968 lmd->lmd_flags |= LMD_FLG_VIRGIN;
970 } else if (strncmp(s1, "noprimnode", 10) == 0) {
971 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
973 } else if (strncmp(s1, "mgssec=", 7) == 0) {
974 rc = lmd_parse_mgssec(lmd, s1 + 7);
978 /* ost exclusion list */
979 } else if (strncmp(s1, "exclude=", 8) == 0) {
980 rc = lmd_make_exclusion(lmd, s1 + 7);
984 } else if (strncmp(s1, "mgs", 3) == 0) {
986 lmd->lmd_flags |= LMD_FLG_MGS;
988 } else if (strncmp(s1, "svname=", 7) == 0) {
989 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
993 } else if (strncmp(s1, "param=", 6) == 0) {
994 size_t length, params_length;
995 char *tail = strchr(s1 + 6, ',');
1002 params_length = strlen(lmd->lmd_params);
1003 if (params_length + length + 1 >= LMD_PARAMS_MAXLEN)
1005 strncat(lmd->lmd_params, s1 + 6, length);
1006 lmd->lmd_params[params_length + length] = '\0';
1007 strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
1009 } else if (strncmp(s1, "osd=", 4) == 0) {
1010 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1015 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1016 * end of the options.
1018 else if (strncmp(s1, "device=", 7) == 0) {
1020 /* terminate options right before device. device
1021 * must be the last one.
1028 s2 = strchr(s1, ',');
1036 memmove(s1, s2, strlen(s2) + 1);
1042 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name (need mount option 'device=...')\n");
1046 s1 = strstr(devname, ":/");
1049 lmd->lmd_flags |= LMD_FLG_CLIENT;
1050 /* Remove leading /s from fsname */
1051 while (*++s1 == '/')
1053 /* Freed in lustre_free_lsi */
1054 lmd->lmd_profile = kasprintf(GFP_NOFS, "%s-client", s1);
1055 if (!lmd->lmd_profile)
1059 /* Freed in lustre_free_lsi */
1060 lmd->lmd_dev = kzalloc(strlen(devname) + 1, GFP_NOFS);
1063 strcpy(lmd->lmd_dev, devname);
1065 /* Save mount options */
1066 s1 = options + strlen(options) - 1;
1067 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1069 if (*options != 0) {
1070 /* Freed in lustre_free_lsi */
1071 lmd->lmd_opts = kzalloc(strlen(options) + 1, GFP_NOFS);
1074 strcpy(lmd->lmd_opts, options);
1078 lmd->lmd_magic = LMD_MAGIC;
1083 CERROR("Bad mount options %s\n", options);
1087 struct lustre_mount_data2 {
1089 struct vfsmount *lmd2_mnt;
1092 /** This is the entry point for the mount call into Lustre.
1093 * This is called when a server or client is mounted,
1094 * and this is where we start setting things up.
1095 * @param data Mount options (e.g. -o flock,abort_recov)
1097 static int lustre_fill_super(struct super_block *sb, void *data, int silent)
1099 struct lustre_mount_data *lmd;
1100 struct lustre_mount_data2 *lmd2 = data;
1101 struct lustre_sb_info *lsi;
1104 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
1106 lsi = lustre_init_lsi(sb);
1112 * Disable lockdep during mount, because mount locking patterns are
1118 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1120 obd_zombie_barrier();
1122 /* Figure out the lmd from the mount options */
1123 if (lmd_parse((lmd2->lmd2_data), lmd)) {
1129 if (lmd_is_client(lmd)) {
1130 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1131 if (!client_fill_super)
1132 request_module("lustre");
1133 if (!client_fill_super) {
1134 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for client mount! Is the 'lustre' module loaded?\n");
1138 rc = lustre_start_mgc(sb);
1143 /* Connect and start */
1144 /* (should always be ll_fill_super) */
1145 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1146 /* c_f_s will call lustre_common_put_super on failure */
1149 CERROR("This is client-side-only module, cannot handle server mount.\n");
1153 /* If error happens in fill_super() call, @lsi will be killed there.
1154 * This is why we do not put it here.
1159 CERROR("Unable to mount %s (%d)\n",
1160 s2lsi(sb) ? lmd->lmd_dev : "", rc);
1162 CDEBUG(D_SUPER, "Mount %s complete\n",
1169 /* We can't call ll_fill_super by name because it lives in a module that
1170 * must be loaded after this one.
1172 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1173 struct vfsmount *mnt))
1175 client_fill_super = cfs;
1177 EXPORT_SYMBOL(lustre_register_client_fill_super);
1179 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1181 kill_super_cb = cfs;
1183 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1185 /***************** FS registration ******************/
1186 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1187 const char *devname, void *data)
1189 struct lustre_mount_data2 lmd2 = {
1194 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1197 static void lustre_kill_super(struct super_block *sb)
1199 struct lustre_sb_info *lsi = s2lsi(sb);
1201 if (kill_super_cb && lsi)
1202 (*kill_super_cb)(sb);
1204 kill_anon_super(sb);
1207 /** Register the "lustre" fs type
1209 static struct file_system_type lustre_fs_type = {
1210 .owner = THIS_MODULE,
1212 .mount = lustre_mount,
1213 .kill_sb = lustre_kill_super,
1214 .fs_flags = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV |
1215 FS_RENAME_DOES_D_MOVE,
1217 MODULE_ALIAS_FS("lustre");
1219 int lustre_register_fs(void)
1221 return register_filesystem(&lustre_fs_type);
1224 int lustre_unregister_fs(void)
1226 return unregister_filesystem(&lustre_fs_type);