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
44 #include <lustre_compat.h>
45 #include <obd_class.h>
46 #include <uapi/linux/lustre/lustre_idl.h>
47 #include <lustre_log.h>
48 #include <lustre_disk.h>
49 #include <uapi/linux/lustre/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 = kzalloc(lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen),
97 lustre_cfg_init(lcfg, LCFG_LOG_START, bufs);
99 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
105 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",
106 mgc->obd_name, logname, rc);
109 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",
110 mgc->obd_name, logname,
113 /* class_obd_list(); */
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;
131 /* mgc_process_config */
132 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
133 lustre_cfg_bufs_set_string(&bufs, 1, logname);
135 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
136 lcfg = kzalloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen),
140 lustre_cfg_init(lcfg, LCFG_LOG_END, &bufs);
142 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
146 EXPORT_SYMBOL(lustre_end_log);
148 /**************** obd start *******************/
150 /** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
151 * lctl (and do for echo cli/srv.
153 static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
154 char *s1, char *s2, char *s3, char *s4)
156 struct lustre_cfg_bufs bufs;
157 struct lustre_cfg *lcfg = NULL;
160 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
161 cmd, s1, s2, s3, s4);
163 lustre_cfg_bufs_reset(&bufs, cfgname);
165 lustre_cfg_bufs_set_string(&bufs, 1, s1);
167 lustre_cfg_bufs_set_string(&bufs, 2, s2);
169 lustre_cfg_bufs_set_string(&bufs, 3, s3);
171 lustre_cfg_bufs_set_string(&bufs, 4, s4);
173 lcfg = kzalloc(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);
184 /** Call class_attach and class_setup. These methods in turn call
185 * obd type-specific methods.
187 static int lustre_start_simple(char *obdname, char *type, char *uuid,
188 char *s1, char *s2, char *s3, char *s4)
192 CDEBUG(D_MOUNT, "Starting obd %s (typ=%s)\n", obdname, type);
194 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
196 CERROR("%s attach error %d\n", obdname, rc);
199 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
201 CERROR("%s setup error %d\n", obdname, rc);
202 do_lcfg(obdname, 0, LCFG_DETACH, NULL, NULL, NULL, NULL);
207 static DEFINE_MUTEX(mgc_start_lock);
209 /** Set up a mgc obd to process startup logs
211 * \param sb [in] super block of the mgc obd
213 * \retval 0 success, otherwise error code
215 int lustre_start_mgc(struct super_block *sb)
217 struct obd_connect_data *data = NULL;
218 struct lustre_sb_info *lsi = s2lsi(sb);
219 struct obd_device *obd;
220 struct obd_export *exp;
221 struct obd_uuid *uuid;
224 char nidstr[LNET_NIDSTR_SIZE];
225 char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
227 int rc = 0, i = 0, j;
229 LASSERT(lsi->lsi_lmd);
231 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
232 ptr = lsi->lsi_lmd->lmd_dev;
233 if (class_parse_nid(ptr, &nid, &ptr) == 0)
236 CERROR("No valid MGS nids found.\n");
240 mutex_lock(&mgc_start_lock);
242 libcfs_nid2str_r(nid, nidstr, sizeof(nidstr));
243 mgcname = kasprintf(GFP_NOFS,
244 "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
245 niduuid = kasprintf(GFP_NOFS, "%s_%x", mgcname, i);
246 if (!mgcname || !niduuid) {
251 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
253 data = kzalloc(sizeof(*data), GFP_NOFS);
259 obd = class_name2obd(mgcname);
260 if (obd && !obd->obd_stopping) {
263 rc = obd_set_info_async(NULL, obd->obd_self_export,
264 strlen(KEY_MGSSEC), KEY_MGSSEC,
265 strlen(mgssec), mgssec, NULL);
269 /* Re-using an existing MGC */
270 atomic_inc(&obd->u.cli.cl_mgc_refcount);
272 /* IR compatibility check, only for clients */
273 if (lmd_is_client(lsi->lsi_lmd)) {
275 int vallen = sizeof(*data);
276 __u32 *flags = &lsi->lsi_lmd->lmd_flags;
278 rc = obd_get_info(NULL, obd->obd_self_export,
279 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
282 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
283 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
284 /* LMD_FLG_NOIR is for test purpose only */
286 "Trying to mount a client with IR setting not compatible with current mgc. Force to use current mgc setting that is IR %s.\n",
287 has_ir ? "enabled" : "disabled");
289 *flags &= ~LMD_FLG_NOIR;
291 *flags |= LMD_FLG_NOIR;
297 /* Try all connections, but only once (again).
298 * We don't want to block another target from starting
299 * (using its local copy of the log), but we do want to connect
300 * if at all possible.
303 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,
305 rc = obd_set_info_async(NULL, obd->obd_self_export,
306 sizeof(KEY_INIT_RECOV_BACKUP),
307 KEY_INIT_RECOV_BACKUP,
308 sizeof(recov_bk), &recov_bk, NULL);
313 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
315 /* Add the primary nids for the MGS */
317 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
318 ptr = lsi->lsi_lmd->lmd_dev;
319 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
320 rc = do_lcfg(mgcname, nid,
321 LCFG_ADD_UUID, niduuid, NULL, NULL, NULL);
324 /* Stop at the first failover nid */
329 CERROR("No valid MGS nids found.\n");
333 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
335 /* Random uuid for MGC allows easier reconnects */
336 uuid = kzalloc(sizeof(*uuid), GFP_NOFS);
342 ll_generate_random_uuid(uuidc);
343 class_uuid_unparse(uuidc, uuid);
346 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
347 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
348 niduuid, NULL, NULL);
353 /* Add any failover MGS nids */
355 while (ptr && ((*ptr == ':' ||
356 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
357 /* New failover node */
358 sprintf(niduuid, "%s_%x", mgcname, i);
360 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
361 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID, niduuid,
369 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
370 niduuid, NULL, NULL, NULL);
378 lsi->lsi_lmd->lmd_mgs_failnodes = i;
380 obd = class_name2obd(mgcname);
382 CERROR("Can't find mgcobd %s\n", mgcname);
387 rc = obd_set_info_async(NULL, obd->obd_self_export,
388 strlen(KEY_MGSSEC), KEY_MGSSEC,
389 strlen(mgssec), mgssec, NULL);
393 /* Keep a refcount of servers/clients who started with "mount",
394 * so we know when we can get rid of the mgc.
396 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
398 /* We connect to the MGS at setup, and don't disconnect until cleanup */
399 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
400 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
401 OBD_CONNECT_LVB_TYPE | OBD_CONNECT_BULK_MBITS;
403 #if OBD_OCD_VERSION(3, 0, 53, 0) > LUSTRE_VERSION_CODE
404 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
407 if (lmd_is_client(lsi->lsi_lmd) &&
408 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
409 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
410 data->ocd_version = LUSTRE_VERSION_CODE;
411 rc = obd_connect(NULL, &exp, obd, &obd->obd_uuid, data, NULL);
413 CERROR("connect failed %d\n", rc);
417 obd->u.cli.cl_mgc_mgsexp = exp;
420 /* Keep the mgc info in the sb. Note that many lsi's can point
425 mutex_unlock(&mgc_start_lock);
433 static int lustre_stop_mgc(struct super_block *sb)
435 struct lustre_sb_info *lsi = s2lsi(sb);
436 struct obd_device *obd;
437 char *niduuid = NULL, *ptr = NULL;
438 int i, rc = 0, len = 0;
447 mutex_lock(&mgc_start_lock);
448 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
449 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
450 /* This is not fatal, every client that stops
453 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
454 atomic_read(&obd->u.cli.cl_mgc_refcount));
459 /* The MGC has no recoverable data in any case.
460 * force shutdown set in umount_begin
462 obd->obd_no_recov = 1;
464 if (obd->u.cli.cl_mgc_mgsexp) {
465 /* An error is not fatal, if we are unable to send the
466 * disconnect mgs ping evictor cleans up the export
468 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
470 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
473 /* Save the obdname for cleaning the nid uuids, which are obdname_XX */
474 len = strlen(obd->obd_name) + 6;
475 niduuid = kzalloc(len, GFP_NOFS);
477 strcpy(niduuid, obd->obd_name);
478 ptr = niduuid + strlen(niduuid);
481 rc = class_manual_cleanup(obd);
485 /* Clean the nid uuids */
491 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
492 sprintf(ptr, "_%x", i);
493 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
494 niduuid, NULL, NULL, NULL);
496 CERROR("del MDC UUID %s failed: rc = %d\n",
502 /* class_import_put will get rid of the additional connections */
503 mutex_unlock(&mgc_start_lock);
507 /***************** lustre superblock **************/
509 static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
511 struct lustre_sb_info *lsi;
513 lsi = kzalloc(sizeof(*lsi), GFP_NOFS);
516 lsi->lsi_lmd = kzalloc(sizeof(*lsi->lsi_lmd), GFP_NOFS);
522 lsi->lsi_lmd->lmd_exclude_count = 0;
523 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
524 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
525 s2lsi_nocast(sb) = lsi;
526 /* we take 1 extra ref for our setup */
527 atomic_set(&lsi->lsi_mounts, 1);
529 /* Default umount style */
530 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
535 static int lustre_free_lsi(struct super_block *sb)
537 struct lustre_sb_info *lsi = s2lsi(sb);
539 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
541 /* someone didn't call server_put_mount. */
542 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
545 kfree(lsi->lsi_lmd->lmd_dev);
546 kfree(lsi->lsi_lmd->lmd_profile);
547 kfree(lsi->lsi_lmd->lmd_mgssec);
548 kfree(lsi->lsi_lmd->lmd_opts);
549 if (lsi->lsi_lmd->lmd_exclude_count)
550 kfree(lsi->lsi_lmd->lmd_exclude);
551 kfree(lsi->lsi_lmd->lmd_mgs);
552 kfree(lsi->lsi_lmd->lmd_osd_type);
553 kfree(lsi->lsi_lmd->lmd_params);
558 LASSERT(!lsi->lsi_llsbi);
560 s2lsi_nocast(sb) = NULL;
565 /* The lsi has one reference for every server that is using the disk -
566 * e.g. MDT, MGS, and potentially MGC
568 static int lustre_put_lsi(struct super_block *sb)
570 struct lustre_sb_info *lsi = s2lsi(sb);
572 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
573 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
581 * <FSNAME><SEPARATOR><TYPE><INDEX>
582 * FSNAME is between 1 and 8 characters (inclusive).
583 * Excluded characters are '/' and ':'
584 * SEPARATOR is either ':' or '-'
585 * TYPE: "OST", "MDT", etc.
586 * INDEX: Hex representation of the index
589 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
590 * @param [in] svname server name including type and index
591 * @param [out] fsname Buffer to copy filesystem name prefix into.
592 * Must have at least 'strlen(fsname) + 1' chars.
593 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
596 static int server_name2fsname(const char *svname, char *fsname,
601 dash = svname + strnlen(svname, 8); /* max fsname length is 8 */
602 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
608 strncpy(fsname, svname, dash - svname);
609 fsname[dash - svname] = '\0';
618 /* Get the index from the obd name.
619 * rc = server type, or
621 * if endptr isn't NULL it is set to end of name
623 static int server_name2index(const char *svname, __u32 *idx,
630 /* We use server_name2fsname() just for parsing */
631 rc = server_name2fsname(svname, NULL, &dash);
637 if (strncmp(dash, "MDT", 3) == 0)
638 rc = LDD_F_SV_TYPE_MDT;
639 else if (strncmp(dash, "OST", 3) == 0)
640 rc = LDD_F_SV_TYPE_OST;
646 if (strncmp(dash, "all", 3) == 0) {
649 return rc | LDD_F_SV_ALL;
652 index = simple_strtoul(dash, (char **)endptr, 16);
656 /* Account for -mdc after index that is possible when specifying mdt */
657 if (endptr && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
658 sizeof(LUSTRE_MDC_NAME) - 1) == 0)
659 *endptr += sizeof(LUSTRE_MDC_NAME);
664 /*************** mount common between server and client ***************/
667 int lustre_common_put_super(struct super_block *sb)
671 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
673 /* Drop a ref to the MGC */
674 rc = lustre_stop_mgc(sb);
675 if (rc && (rc != -ENOENT)) {
677 CERROR("Can't stop MGC: %d\n", rc);
680 /* BUSY just means that there's some other obd that
681 * needs the mgc. Let him clean it up.
683 CDEBUG(D_MOUNT, "MGC still in use\n");
685 /* Drop a ref to the mounted disk */
689 EXPORT_SYMBOL(lustre_common_put_super);
691 static void lmd_print(struct lustre_mount_data *lmd)
695 PRINT_CMD(D_MOUNT, " mount data:\n");
696 if (lmd_is_client(lmd))
697 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
698 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
699 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
702 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
704 if (lmd->lmd_recovery_time_soft)
705 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
706 lmd->lmd_recovery_time_soft);
708 if (lmd->lmd_recovery_time_hard)
709 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
710 lmd->lmd_recovery_time_hard);
712 for (i = 0; i < lmd->lmd_exclude_count; i++) {
713 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
714 lmd->lmd_exclude[i]);
718 /* Is this server on the exclusion list */
719 int lustre_check_exclusion(struct super_block *sb, char *svname)
721 struct lustre_sb_info *lsi = s2lsi(sb);
722 struct lustre_mount_data *lmd = lsi->lsi_lmd;
726 rc = server_name2index(svname, &index, NULL);
727 if (rc != LDD_F_SV_TYPE_OST)
728 /* Only exclude OSTs */
731 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
732 index, lmd->lmd_exclude_count, lmd->lmd_dev);
734 for (i = 0; i < lmd->lmd_exclude_count; i++) {
735 if (index == lmd->lmd_exclude[i]) {
736 CWARN("Excluding %s (on exclusion list)\n", svname);
743 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
744 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
746 const char *s1 = ptr, *s2;
747 __u32 index = 0, *exclude_list;
750 /* The shortest an ost name can be is 8 chars: -OST0000.
751 * We don't actually know the fsname at this time, so in fact
752 * a user could specify any fsname.
754 devmax = strlen(ptr) / 8 + 1;
756 /* temp storage until we figure out how many we have */
757 exclude_list = kcalloc(devmax, sizeof(index), GFP_NOFS);
761 /* we enter this fn pointing at the '=' */
762 while (*s1 && *s1 != ' ' && *s1 != ',') {
764 rc = server_name2index(s1, &index, &s2);
766 CERROR("Can't parse server name '%s': rc = %d\n",
770 if (rc == LDD_F_SV_TYPE_OST)
771 exclude_list[lmd->lmd_exclude_count++] = index;
773 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
774 (uint)(s2 - s1), s1, rc);
776 /* now we are pointing at ':' (next exclude)
777 * or ',' (end of excludes)
779 if (lmd->lmd_exclude_count >= devmax)
782 if (rc >= 0) /* non-err */
785 if (lmd->lmd_exclude_count) {
786 /* permanent, freed in lustre_free_lsi */
787 lmd->lmd_exclude = kcalloc(lmd->lmd_exclude_count,
788 sizeof(index), GFP_NOFS);
789 if (lmd->lmd_exclude) {
790 memcpy(lmd->lmd_exclude, exclude_list,
791 sizeof(index) * lmd->lmd_exclude_count);
794 lmd->lmd_exclude_count = 0;
801 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
806 kfree(lmd->lmd_mgssec);
807 lmd->lmd_mgssec = NULL;
809 tail = strchr(ptr, ',');
811 length = strlen(ptr);
815 lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS);
816 if (!lmd->lmd_mgssec)
819 memcpy(lmd->lmd_mgssec, ptr, length);
820 lmd->lmd_mgssec[length] = '\0';
824 static int lmd_parse_string(char **handle, char *ptr)
835 tail = strchr(ptr, ',');
837 length = strlen(ptr);
841 *handle = kzalloc(length + 1, GFP_NOFS);
845 memcpy(*handle, ptr, length);
846 (*handle)[length] = '\0';
851 /* Collect multiple values for mgsnid specifiers */
852 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
860 /* Find end of nidlist */
861 while (class_parse_nid_quiet(tail, &nid, &tail) == 0)
863 length = tail - *ptr;
865 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
870 oldlen = strlen(lmd->lmd_mgs) + 1;
872 mgsnid = kzalloc(oldlen + length + 1, GFP_NOFS);
877 /* Multiple mgsnid= are taken to mean failover locations */
878 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
879 mgsnid[oldlen - 1] = ':';
882 memcpy(mgsnid + oldlen, *ptr, length);
883 mgsnid[oldlen + length] = '\0';
884 lmd->lmd_mgs = mgsnid;
890 /** Parse mount line options
891 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
892 * dev is passed as device=uml1:/lustre by mount.lustre
894 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
896 char *s1, *s2, *devname = NULL;
897 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
902 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that /sbin/mount.lustre is installed.\n");
906 /* Options should be a string - try to detect old lmd data */
907 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
908 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of /sbin/mount.lustre. Please install version %s\n",
909 LUSTRE_VERSION_STRING);
912 lmd->lmd_magic = LMD_MAGIC;
914 lmd->lmd_params = kzalloc(LMD_PARAMS_MAXLEN, GFP_NOFS);
915 if (!lmd->lmd_params)
917 lmd->lmd_params[0] = '\0';
919 /* Set default flags here */
924 int time_min = OBD_RECOVERY_TIME_MIN;
927 /* Skip whitespace and extra commas */
928 while (*s1 == ' ' || *s1 == ',')
932 /* Client options are parsed in ll_options: eg. flock,
936 /* Parse non-ldiskfs options here. Rather than modifying
937 * ldiskfs, we just zero these out here
939 if (strncmp(s1, "abort_recov", 11) == 0) {
940 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
942 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
943 lmd->lmd_recovery_time_soft = max_t(int,
944 simple_strtoul(s1 + 19, NULL, 10), time_min);
946 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
947 lmd->lmd_recovery_time_hard = max_t(int,
948 simple_strtoul(s1 + 19, NULL, 10), time_min);
950 } else if (strncmp(s1, "noir", 4) == 0) {
951 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
953 } else if (strncmp(s1, "nosvc", 5) == 0) {
954 lmd->lmd_flags |= LMD_FLG_NOSVC;
956 } else if (strncmp(s1, "nomgs", 5) == 0) {
957 lmd->lmd_flags |= LMD_FLG_NOMGS;
959 } else if (strncmp(s1, "noscrub", 7) == 0) {
960 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
962 } else if (strncmp(s1, PARAM_MGSNODE,
963 sizeof(PARAM_MGSNODE) - 1) == 0) {
964 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
965 /* Assume the next mount opt is the first
966 * invalid nid we get to.
968 rc = lmd_parse_mgs(lmd, &s2);
972 } else if (strncmp(s1, "writeconf", 9) == 0) {
973 lmd->lmd_flags |= LMD_FLG_WRITECONF;
975 } else if (strncmp(s1, "update", 6) == 0) {
976 lmd->lmd_flags |= LMD_FLG_UPDATE;
978 } else if (strncmp(s1, "virgin", 6) == 0) {
979 lmd->lmd_flags |= LMD_FLG_VIRGIN;
981 } else if (strncmp(s1, "noprimnode", 10) == 0) {
982 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
984 } else if (strncmp(s1, "mgssec=", 7) == 0) {
985 rc = lmd_parse_mgssec(lmd, s1 + 7);
990 /* ost exclusion list */
991 } else if (strncmp(s1, "exclude=", 8) == 0) {
992 rc = lmd_make_exclusion(lmd, s1 + 7);
996 } else if (strncmp(s1, "mgs", 3) == 0) {
998 lmd->lmd_flags |= LMD_FLG_MGS;
1000 } else if (strncmp(s1, "svname=", 7) == 0) {
1001 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
1005 } else if (strncmp(s1, "param=", 6) == 0) {
1006 size_t length, params_length;
1007 char *tail = strchr(s1 + 6, ',');
1010 length = strlen(s1);
1013 char *param_str = tail + 1;
1014 int supplementary = 1;
1016 while (!class_parse_nid_quiet(param_str, &nid,
1020 length = param_str - s1 - supplementary;
1023 params_length = strlen(lmd->lmd_params);
1024 if (params_length + length + 1 >= LMD_PARAMS_MAXLEN)
1026 strncat(lmd->lmd_params, s1 + 6, length);
1027 lmd->lmd_params[params_length + length] = '\0';
1028 strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
1029 s3 = s1 + 6 + length;
1031 } else if (strncmp(s1, "osd=", 4) == 0) {
1032 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1037 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1038 * end of the options.
1040 else if (strncmp(s1, "device=", 7) == 0) {
1042 /* terminate options right before device. device
1043 * must be the last one.
1050 s2 = strchr(s1, ',');
1058 memmove(s1, s2, strlen(s2) + 1);
1064 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name (need mount option 'device=...')\n");
1068 s1 = strstr(devname, ":/");
1071 lmd->lmd_flags |= LMD_FLG_CLIENT;
1072 /* Remove leading /s from fsname */
1073 while (*++s1 == '/')
1075 /* Freed in lustre_free_lsi */
1076 lmd->lmd_profile = kasprintf(GFP_NOFS, "%s-client", s1);
1077 if (!lmd->lmd_profile)
1081 /* Freed in lustre_free_lsi */
1082 lmd->lmd_dev = kzalloc(strlen(devname) + 1, GFP_NOFS);
1085 strcpy(lmd->lmd_dev, devname);
1087 /* Save mount options */
1088 s1 = options + strlen(options) - 1;
1089 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1091 if (*options != 0) {
1092 /* Freed in lustre_free_lsi */
1093 lmd->lmd_opts = kzalloc(strlen(options) + 1, GFP_NOFS);
1096 strcpy(lmd->lmd_opts, options);
1100 lmd->lmd_magic = LMD_MAGIC;
1105 CERROR("Bad mount options %s\n", options);
1109 struct lustre_mount_data2 {
1111 struct vfsmount *lmd2_mnt;
1114 /** This is the entry point for the mount call into Lustre.
1115 * This is called when a server or client is mounted,
1116 * and this is where we start setting things up.
1117 * @param data Mount options (e.g. -o flock,abort_recov)
1119 static int lustre_fill_super(struct super_block *sb, void *data, int silent)
1121 struct lustre_mount_data *lmd;
1122 struct lustre_mount_data2 *lmd2 = data;
1123 struct lustre_sb_info *lsi;
1126 CDEBUG(D_MOUNT | D_VFSTRACE, "VFS Op: sb %p\n", sb);
1128 lsi = lustre_init_lsi(sb);
1134 * Disable lockdep during mount, because mount locking patterns are
1140 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1142 obd_zombie_barrier();
1144 /* Figure out the lmd from the mount options */
1145 if (lmd_parse((lmd2->lmd2_data), lmd)) {
1151 if (lmd_is_client(lmd)) {
1152 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1153 if (!client_fill_super)
1154 request_module("lustre");
1155 if (!client_fill_super) {
1156 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for client mount! Is the 'lustre' module loaded?\n");
1160 rc = lustre_start_mgc(sb);
1162 lustre_common_put_super(sb);
1165 /* Connect and start */
1166 /* (should always be ll_fill_super) */
1167 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1168 /* c_f_s will call lustre_common_put_super on failure */
1171 CERROR("This is client-side-only module, cannot handle server mount.\n");
1175 /* If error happens in fill_super() call, @lsi will be killed there.
1176 * This is why we do not put it here.
1181 CERROR("Unable to mount %s (%d)\n",
1182 s2lsi(sb) ? lmd->lmd_dev : "", rc);
1184 CDEBUG(D_SUPER, "Mount %s complete\n",
1191 /* We can't call ll_fill_super by name because it lives in a module that
1192 * must be loaded after this one.
1194 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1195 struct vfsmount *mnt))
1197 client_fill_super = cfs;
1199 EXPORT_SYMBOL(lustre_register_client_fill_super);
1201 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1203 kill_super_cb = cfs;
1205 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1207 /***************** FS registration ******************/
1208 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1209 const char *devname, void *data)
1211 struct lustre_mount_data2 lmd2 = {
1216 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1219 static void lustre_kill_super(struct super_block *sb)
1221 struct lustre_sb_info *lsi = s2lsi(sb);
1223 if (kill_super_cb && lsi)
1224 (*kill_super_cb)(sb);
1226 kill_anon_super(sb);
1229 /** Register the "lustre" fs type
1231 static struct file_system_type lustre_fs_type = {
1232 .owner = THIS_MODULE,
1234 .mount = lustre_mount,
1235 .kill_sb = lustre_kill_super,
1236 .fs_flags = FS_REQUIRES_DEV | FS_RENAME_DOES_D_MOVE,
1238 MODULE_ALIAS_FS("lustre");
1240 int lustre_register_fs(void)
1242 return register_filesystem(&lustre_fs_type);
1245 int lustre_unregister_fs(void)
1247 return unregister_filesystem(&lustre_fs_type);