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, 2012, 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. */
290 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,
292 rc = obd_set_info_async(NULL, obd->obd_self_export,
293 sizeof(KEY_INIT_RECOV_BACKUP),
294 KEY_INIT_RECOV_BACKUP,
295 sizeof(recov_bk), &recov_bk, NULL);
300 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
302 /* Add the primary nids for the MGS */
304 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
305 ptr = lsi->lsi_lmd->lmd_dev;
306 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
307 rc = do_lcfg(mgcname, nid,
308 LCFG_ADD_UUID, niduuid, NULL, NULL, NULL);
310 /* Stop at the first failover nid */
315 CERROR("No valid MGS nids found.\n");
319 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
321 /* Random uuid for MGC allows easier reconnects */
322 uuid = kzalloc(sizeof(*uuid), GFP_NOFS);
328 ll_generate_random_uuid(uuidc);
329 class_uuid_unparse(uuidc, uuid);
332 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
333 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
334 niduuid, NULL, NULL);
339 /* Add any failover MGS nids */
341 while (ptr && ((*ptr == ':' ||
342 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
343 /* New failover node */
344 sprintf(niduuid, "%s_%x", mgcname, i);
346 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
348 rc = do_lcfg(mgcname, nid,
349 LCFG_ADD_UUID, niduuid, NULL, NULL, NULL);
354 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
355 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. */
379 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
381 /* We connect to the MGS at setup, and don't disconnect until cleanup */
382 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
383 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
384 OBD_CONNECT_LVB_TYPE;
386 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
387 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
389 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
392 if (lmd_is_client(lsi->lsi_lmd) &&
393 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
394 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
395 data->ocd_version = LUSTRE_VERSION_CODE;
396 rc = obd_connect(NULL, &exp, obd, &(obd->obd_uuid), data, NULL);
398 CERROR("connect failed %d\n", rc);
402 obd->u.cli.cl_mgc_mgsexp = exp;
405 /* 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
435 will call in here. */
436 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
437 atomic_read(&obd->u.cli.cl_mgc_refcount));
442 /* The MGC has no recoverable data in any case.
443 * force shutdown set in umount_begin */
444 obd->obd_no_recov = 1;
446 if (obd->u.cli.cl_mgc_mgsexp) {
447 /* An error is not fatal, if we are unable to send the
448 disconnect mgs ping evictor cleans up the export */
449 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
451 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
454 /* Save the obdname for cleaning the nid uuids, which are
456 len = strlen(obd->obd_name) + 6;
457 niduuid = kzalloc(len, GFP_NOFS);
459 strcpy(niduuid, obd->obd_name);
460 ptr = niduuid + strlen(niduuid);
463 rc = class_manual_cleanup(obd);
467 /* Clean the nid uuids */
473 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
474 sprintf(ptr, "_%x", i);
475 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
476 niduuid, NULL, NULL, NULL);
478 CERROR("del MDC UUID %s failed: rc = %d\n",
484 /* class_import_put will get rid of the additional connections */
485 mutex_unlock(&mgc_start_lock);
489 /***************** lustre superblock **************/
491 static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
493 struct lustre_sb_info *lsi;
495 lsi = kzalloc(sizeof(*lsi), GFP_NOFS);
498 lsi->lsi_lmd = kzalloc(sizeof(*lsi->lsi_lmd), GFP_NOFS);
504 lsi->lsi_lmd->lmd_exclude_count = 0;
505 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
506 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
507 s2lsi_nocast(sb) = lsi;
508 /* we take 1 extra ref for our setup */
509 atomic_set(&lsi->lsi_mounts, 1);
511 /* Default umount style */
512 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
517 static int lustre_free_lsi(struct super_block *sb)
519 struct lustre_sb_info *lsi = s2lsi(sb);
521 LASSERT(lsi != NULL);
522 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
524 /* someone didn't call server_put_mount. */
525 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
527 if (lsi->lsi_lmd != NULL) {
528 kfree(lsi->lsi_lmd->lmd_dev);
529 kfree(lsi->lsi_lmd->lmd_profile);
530 kfree(lsi->lsi_lmd->lmd_mgssec);
531 kfree(lsi->lsi_lmd->lmd_opts);
532 if (lsi->lsi_lmd->lmd_exclude_count)
533 kfree(lsi->lsi_lmd->lmd_exclude);
534 kfree(lsi->lsi_lmd->lmd_mgs);
535 kfree(lsi->lsi_lmd->lmd_osd_type);
536 kfree(lsi->lsi_lmd->lmd_params);
541 LASSERT(lsi->lsi_llsbi == NULL);
543 s2lsi_nocast(sb) = NULL;
548 /* The lsi has one reference for every server that is using the disk -
549 e.g. MDT, MGS, and potentially MGC */
550 static int lustre_put_lsi(struct super_block *sb)
552 struct lustre_sb_info *lsi = s2lsi(sb);
554 LASSERT(lsi != NULL);
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--)
591 if (fsname != NULL) {
592 strncpy(fsname, svname, dash - svname);
593 fsname[dash - svname] = '\0';
602 /* Get the index from the obd name.
605 if endptr isn't NULL it is set to end of name */
606 static int server_name2index(const char *svname, __u32 *idx,
613 /* We use server_name2fsname() just for parsing */
614 rc = server_name2fsname(svname, NULL, &dash);
620 if (strncmp(dash, "MDT", 3) == 0)
621 rc = LDD_F_SV_TYPE_MDT;
622 else if (strncmp(dash, "OST", 3) == 0)
623 rc = LDD_F_SV_TYPE_OST;
629 if (strncmp(dash, "all", 3) == 0) {
632 return rc | LDD_F_SV_ALL;
635 index = simple_strtoul(dash, (char **)endptr, 16);
639 /* Account for -mdc after index that is possible when specifying mdt */
640 if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
641 sizeof(LUSTRE_MDC_NAME)-1) == 0)
642 *endptr += sizeof(LUSTRE_MDC_NAME);
647 /*************** mount common between server and client ***************/
650 int lustre_common_put_super(struct super_block *sb)
654 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
656 /* Drop a ref to the MGC */
657 rc = lustre_stop_mgc(sb);
658 if (rc && (rc != -ENOENT)) {
660 CERROR("Can't stop MGC: %d\n", rc);
663 /* BUSY just means that there's some other obd that
664 needs the mgc. Let him clean it up. */
665 CDEBUG(D_MOUNT, "MGC still in use\n");
667 /* Drop a ref to the mounted disk */
672 EXPORT_SYMBOL(lustre_common_put_super);
674 static void lmd_print(struct lustre_mount_data *lmd)
678 PRINT_CMD(D_MOUNT, " mount data:\n");
679 if (lmd_is_client(lmd))
680 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
681 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
682 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
685 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
687 if (lmd->lmd_recovery_time_soft)
688 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
689 lmd->lmd_recovery_time_soft);
691 if (lmd->lmd_recovery_time_hard)
692 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
693 lmd->lmd_recovery_time_hard);
695 for (i = 0; i < lmd->lmd_exclude_count; i++) {
696 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
697 lmd->lmd_exclude[i]);
701 /* Is this server on the exclusion list */
702 int lustre_check_exclusion(struct super_block *sb, char *svname)
704 struct lustre_sb_info *lsi = s2lsi(sb);
705 struct lustre_mount_data *lmd = lsi->lsi_lmd;
709 rc = server_name2index(svname, &index, NULL);
710 if (rc != LDD_F_SV_TYPE_OST)
711 /* Only exclude OSTs */
714 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
715 index, lmd->lmd_exclude_count, lmd->lmd_dev);
717 for (i = 0; i < lmd->lmd_exclude_count; i++) {
718 if (index == lmd->lmd_exclude[i]) {
719 CWARN("Excluding %s (on exclusion list)\n", svname);
726 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
727 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
729 const char *s1 = ptr, *s2;
730 __u32 index, *exclude_list;
733 /* The shortest an ost name can be is 8 chars: -OST0000.
734 We don't actually know the fsname at this time, so in fact
735 a user could specify any fsname. */
736 devmax = strlen(ptr) / 8 + 1;
738 /* temp storage until we figure out how many we have */
739 exclude_list = kcalloc(devmax, sizeof(index), GFP_NOFS);
743 /* we enter this fn pointing at the '=' */
744 while (*s1 && *s1 != ' ' && *s1 != ',') {
746 rc = server_name2index(s1, &index, &s2);
748 CERROR("Can't parse server name '%s': rc = %d\n",
752 if (rc == LDD_F_SV_TYPE_OST)
753 exclude_list[lmd->lmd_exclude_count++] = index;
755 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
756 (uint)(s2-s1), s1, rc);
758 /* now we are pointing at ':' (next exclude)
759 or ',' (end of excludes) */
760 if (lmd->lmd_exclude_count >= devmax)
763 if (rc >= 0) /* non-err */
766 if (lmd->lmd_exclude_count) {
767 /* permanent, freed in lustre_free_lsi */
768 lmd->lmd_exclude = kcalloc(lmd->lmd_exclude_count,
769 sizeof(index), GFP_NOFS);
770 if (lmd->lmd_exclude) {
771 memcpy(lmd->lmd_exclude, exclude_list,
772 sizeof(index) * lmd->lmd_exclude_count);
775 lmd->lmd_exclude_count = 0;
782 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
787 kfree(lmd->lmd_mgssec);
788 lmd->lmd_mgssec = NULL;
790 tail = strchr(ptr, ',');
792 length = strlen(ptr);
796 lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS);
797 if (!lmd->lmd_mgssec)
800 memcpy(lmd->lmd_mgssec, ptr, length);
801 lmd->lmd_mgssec[length] = '\0';
805 static int lmd_parse_string(char **handle, char *ptr)
810 if ((handle == NULL) || (ptr == NULL))
816 tail = strchr(ptr, ',');
818 length = strlen(ptr);
822 *handle = kzalloc(length + 1, GFP_NOFS);
826 memcpy(*handle, ptr, length);
827 (*handle)[length] = '\0';
832 /* Collect multiple values for mgsnid specifiers */
833 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
841 /* Find end of nidlist */
842 while (class_parse_nid_quiet(tail, &nid, &tail) == 0)
844 length = tail - *ptr;
846 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
850 if (lmd->lmd_mgs != NULL)
851 oldlen = strlen(lmd->lmd_mgs) + 1;
853 mgsnid = kzalloc(oldlen + length + 1, GFP_NOFS);
857 if (lmd->lmd_mgs != NULL) {
858 /* Multiple mgsnid= are taken to mean failover locations */
859 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
860 mgsnid[oldlen - 1] = ':';
863 memcpy(mgsnid + oldlen, *ptr, length);
864 mgsnid[oldlen + length] = '\0';
865 lmd->lmd_mgs = mgsnid;
871 /** Parse mount line options
872 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
873 * dev is passed as device=uml1:/lustre by mount.lustre
875 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
877 char *s1, *s2, *devname = NULL;
878 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
883 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that /sbin/mount.lustre is installed.\n");
887 /* Options should be a string - try to detect old lmd data */
888 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
889 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of /sbin/mount.lustre. Please install version %s\n",
890 LUSTRE_VERSION_STRING);
893 lmd->lmd_magic = LMD_MAGIC;
895 lmd->lmd_params = kzalloc(4096, GFP_NOFS);
896 if (!lmd->lmd_params)
898 lmd->lmd_params[0] = '\0';
900 /* Set default flags here */
905 int time_min = OBD_RECOVERY_TIME_MIN;
907 /* Skip whitespace and extra commas */
908 while (*s1 == ' ' || *s1 == ',')
911 /* Client options are parsed in ll_options: eg. flock,
914 /* Parse non-ldiskfs options here. Rather than modifying
915 ldiskfs, we just zero these out here */
916 if (strncmp(s1, "abort_recov", 11) == 0) {
917 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
919 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
920 lmd->lmd_recovery_time_soft = max_t(int,
921 simple_strtoul(s1 + 19, NULL, 10), time_min);
923 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
924 lmd->lmd_recovery_time_hard = max_t(int,
925 simple_strtoul(s1 + 19, NULL, 10), time_min);
927 } else if (strncmp(s1, "noir", 4) == 0) {
928 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
930 } else if (strncmp(s1, "nosvc", 5) == 0) {
931 lmd->lmd_flags |= LMD_FLG_NOSVC;
933 } else if (strncmp(s1, "nomgs", 5) == 0) {
934 lmd->lmd_flags |= LMD_FLG_NOMGS;
936 } else if (strncmp(s1, "noscrub", 7) == 0) {
937 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
939 } else if (strncmp(s1, PARAM_MGSNODE,
940 sizeof(PARAM_MGSNODE) - 1) == 0) {
941 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
942 /* Assume the next mount opt is the first
943 invalid nid we get to. */
944 rc = lmd_parse_mgs(lmd, &s2);
948 } else if (strncmp(s1, "writeconf", 9) == 0) {
949 lmd->lmd_flags |= LMD_FLG_WRITECONF;
951 } else if (strncmp(s1, "update", 6) == 0) {
952 lmd->lmd_flags |= LMD_FLG_UPDATE;
954 } else if (strncmp(s1, "virgin", 6) == 0) {
955 lmd->lmd_flags |= LMD_FLG_VIRGIN;
957 } else if (strncmp(s1, "noprimnode", 10) == 0) {
958 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
960 } else if (strncmp(s1, "mgssec=", 7) == 0) {
961 rc = lmd_parse_mgssec(lmd, s1 + 7);
965 /* ost exclusion list */
966 } else if (strncmp(s1, "exclude=", 8) == 0) {
967 rc = lmd_make_exclusion(lmd, s1 + 7);
971 } else if (strncmp(s1, "mgs", 3) == 0) {
973 lmd->lmd_flags |= LMD_FLG_MGS;
975 } else if (strncmp(s1, "svname=", 7) == 0) {
976 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
980 } else if (strncmp(s1, "param=", 6) == 0) {
982 char *tail = strchr(s1 + 6, ',');
989 strncat(lmd->lmd_params, s1 + 6, length);
990 strcat(lmd->lmd_params, " ");
992 } else if (strncmp(s1, "osd=", 4) == 0) {
993 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
998 /* Linux 2.4 doesn't pass the device, so we stuck it at the
999 end of the options. */
1000 else if (strncmp(s1, "device=", 7) == 0) {
1002 /* terminate options right before device. device
1003 must be the last one. */
1009 s2 = strchr(s1, ',');
1017 memmove(s1, s2, strlen(s2) + 1);
1023 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name (need mount option 'device=...')\n");
1027 s1 = strstr(devname, ":/");
1030 lmd->lmd_flags |= LMD_FLG_CLIENT;
1031 /* Remove leading /s from fsname */
1032 while (*++s1 == '/')
1034 /* Freed in lustre_free_lsi */
1035 lmd->lmd_profile = kasprintf(GFP_NOFS, "%s-client", s1);
1036 if (!lmd->lmd_profile)
1040 /* Freed in lustre_free_lsi */
1041 lmd->lmd_dev = kzalloc(strlen(devname) + 1, GFP_NOFS);
1044 strcpy(lmd->lmd_dev, devname);
1046 /* Save mount options */
1047 s1 = options + strlen(options) - 1;
1048 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1050 if (*options != 0) {
1051 /* Freed in lustre_free_lsi */
1052 lmd->lmd_opts = kzalloc(strlen(options) + 1, GFP_NOFS);
1055 strcpy(lmd->lmd_opts, options);
1059 lmd->lmd_magic = LMD_MAGIC;
1064 CERROR("Bad mount options %s\n", options);
1068 struct lustre_mount_data2 {
1070 struct vfsmount *lmd2_mnt;
1073 /** This is the entry point for the mount call into Lustre.
1074 * This is called when a server or client is mounted,
1075 * and this is where we start setting things up.
1076 * @param data Mount options (e.g. -o flock,abort_recov)
1078 static int lustre_fill_super(struct super_block *sb, void *data, int silent)
1080 struct lustre_mount_data *lmd;
1081 struct lustre_mount_data2 *lmd2 = data;
1082 struct lustre_sb_info *lsi;
1085 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
1087 lsi = lustre_init_lsi(sb);
1093 * Disable lockdep during mount, because mount locking patterns are
1099 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1101 obd_zombie_barrier();
1103 /* Figure out the lmd from the mount options */
1104 if (lmd_parse((lmd2->lmd2_data), lmd)) {
1110 if (lmd_is_client(lmd)) {
1111 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1112 if (client_fill_super == NULL)
1113 request_module("lustre");
1114 if (client_fill_super == NULL) {
1115 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for client mount! Is the 'lustre' module loaded?\n");
1119 rc = lustre_start_mgc(sb);
1124 /* Connect and start */
1125 /* (should always be ll_fill_super) */
1126 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1127 /* c_f_s will call lustre_common_put_super on failure */
1130 CERROR("This is client-side-only module, cannot handle server mount.\n");
1134 /* If error happens in fill_super() call, @lsi will be killed there.
1135 * This is why we do not put it here. */
1139 CERROR("Unable to mount %s (%d)\n",
1140 s2lsi(sb) ? lmd->lmd_dev : "", rc);
1142 CDEBUG(D_SUPER, "Mount %s complete\n",
1149 /* We can't call ll_fill_super by name because it lives in a module that
1150 must be loaded after this one. */
1151 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1152 struct vfsmount *mnt))
1154 client_fill_super = cfs;
1156 EXPORT_SYMBOL(lustre_register_client_fill_super);
1158 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1160 kill_super_cb = cfs;
1162 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1164 /***************** FS registration ******************/
1165 struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1166 const char *devname, void *data)
1168 struct lustre_mount_data2 lmd2 = {
1173 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1176 static void lustre_kill_super(struct super_block *sb)
1178 struct lustre_sb_info *lsi = s2lsi(sb);
1180 if (kill_super_cb && lsi)
1181 (*kill_super_cb)(sb);
1183 kill_anon_super(sb);
1186 /** Register the "lustre" fs type
1188 static struct file_system_type lustre_fs_type = {
1189 .owner = THIS_MODULE,
1191 .mount = lustre_mount,
1192 .kill_sb = lustre_kill_super,
1193 .fs_flags = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV |
1194 FS_RENAME_DOES_D_MOVE,
1196 MODULE_ALIAS_FS("lustre");
1198 int lustre_register_fs(void)
1200 return register_filesystem(&lustre_fs_type);
1203 int lustre_unregister_fs(void)
1205 return unregister_filesystem(&lustre_fs_type);