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/linux/lustre_compat25.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 LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
388 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
390 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
393 if (lmd_is_client(lsi->lsi_lmd) &&
394 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
395 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
396 data->ocd_version = LUSTRE_VERSION_CODE;
397 rc = obd_connect(NULL, &exp, obd, &(obd->obd_uuid), data, NULL);
399 CERROR("connect failed %d\n", rc);
403 obd->u.cli.cl_mgc_mgsexp = exp;
406 /* Keep the mgc info in the sb. Note that many lsi's can point
411 mutex_unlock(&mgc_start_lock);
419 static int lustre_stop_mgc(struct super_block *sb)
421 struct lustre_sb_info *lsi = s2lsi(sb);
422 struct obd_device *obd;
423 char *niduuid = NULL, *ptr = NULL;
424 int i, rc = 0, len = 0;
433 mutex_lock(&mgc_start_lock);
434 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
435 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
436 /* This is not fatal, every client that stops
439 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
440 atomic_read(&obd->u.cli.cl_mgc_refcount));
445 /* The MGC has no recoverable data in any case.
446 * force shutdown set in umount_begin
448 obd->obd_no_recov = 1;
450 if (obd->u.cli.cl_mgc_mgsexp) {
451 /* An error is not fatal, if we are unable to send the
452 * disconnect mgs ping evictor cleans up the export
454 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
456 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
459 /* Save the obdname for cleaning the nid uuids, which are obdname_XX */
460 len = strlen(obd->obd_name) + 6;
461 niduuid = kzalloc(len, GFP_NOFS);
463 strcpy(niduuid, obd->obd_name);
464 ptr = niduuid + strlen(niduuid);
467 rc = class_manual_cleanup(obd);
471 /* Clean the nid uuids */
477 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
478 sprintf(ptr, "_%x", i);
479 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
480 niduuid, NULL, NULL, NULL);
482 CERROR("del MDC UUID %s failed: rc = %d\n",
488 /* class_import_put will get rid of the additional connections */
489 mutex_unlock(&mgc_start_lock);
493 /***************** lustre superblock **************/
495 static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
497 struct lustre_sb_info *lsi;
499 lsi = kzalloc(sizeof(*lsi), GFP_NOFS);
502 lsi->lsi_lmd = kzalloc(sizeof(*lsi->lsi_lmd), GFP_NOFS);
508 lsi->lsi_lmd->lmd_exclude_count = 0;
509 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
510 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
511 s2lsi_nocast(sb) = lsi;
512 /* we take 1 extra ref for our setup */
513 atomic_set(&lsi->lsi_mounts, 1);
515 /* Default umount style */
516 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
521 static int lustre_free_lsi(struct super_block *sb)
523 struct lustre_sb_info *lsi = s2lsi(sb);
525 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
527 /* someone didn't call server_put_mount. */
528 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
531 kfree(lsi->lsi_lmd->lmd_dev);
532 kfree(lsi->lsi_lmd->lmd_profile);
533 kfree(lsi->lsi_lmd->lmd_mgssec);
534 kfree(lsi->lsi_lmd->lmd_opts);
535 if (lsi->lsi_lmd->lmd_exclude_count)
536 kfree(lsi->lsi_lmd->lmd_exclude);
537 kfree(lsi->lsi_lmd->lmd_mgs);
538 kfree(lsi->lsi_lmd->lmd_osd_type);
539 kfree(lsi->lsi_lmd->lmd_params);
544 LASSERT(!lsi->lsi_llsbi);
546 s2lsi_nocast(sb) = NULL;
551 /* The lsi has one reference for every server that is using the disk -
552 * e.g. MDT, MGS, and potentially MGC
554 static int lustre_put_lsi(struct super_block *sb)
556 struct lustre_sb_info *lsi = s2lsi(sb);
558 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
559 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
567 * <FSNAME><SEPARATOR><TYPE><INDEX>
568 * FSNAME is between 1 and 8 characters (inclusive).
569 * Excluded characters are '/' and ':'
570 * SEPARATOR is either ':' or '-'
571 * TYPE: "OST", "MDT", etc.
572 * INDEX: Hex representation of the index
575 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
576 * @param [in] svname server name including type and index
577 * @param [out] fsname Buffer to copy filesystem name prefix into.
578 * Must have at least 'strlen(fsname) + 1' chars.
579 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
582 static int server_name2fsname(const char *svname, char *fsname,
587 dash = svname + strnlen(svname, 8); /* max fsname length is 8 */
588 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
594 strncpy(fsname, svname, dash - svname);
595 fsname[dash - svname] = '\0';
604 /* Get the index from the obd name.
605 * rc = server type, or
607 * if endptr isn't NULL it is set to end of name
609 static int server_name2index(const char *svname, __u32 *idx,
616 /* We use server_name2fsname() just for parsing */
617 rc = server_name2fsname(svname, NULL, &dash);
623 if (strncmp(dash, "MDT", 3) == 0)
624 rc = LDD_F_SV_TYPE_MDT;
625 else if (strncmp(dash, "OST", 3) == 0)
626 rc = LDD_F_SV_TYPE_OST;
632 if (strncmp(dash, "all", 3) == 0) {
635 return rc | LDD_F_SV_ALL;
638 index = simple_strtoul(dash, (char **)endptr, 16);
642 /* Account for -mdc after index that is possible when specifying mdt */
643 if (endptr && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
644 sizeof(LUSTRE_MDC_NAME) - 1) == 0)
645 *endptr += sizeof(LUSTRE_MDC_NAME);
650 /*************** mount common between server and client ***************/
653 int lustre_common_put_super(struct super_block *sb)
657 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
659 /* Drop a ref to the MGC */
660 rc = lustre_stop_mgc(sb);
661 if (rc && (rc != -ENOENT)) {
663 CERROR("Can't stop MGC: %d\n", rc);
666 /* BUSY just means that there's some other obd that
667 * needs the mgc. Let him clean it up.
669 CDEBUG(D_MOUNT, "MGC still in use\n");
671 /* Drop a ref to the mounted disk */
676 EXPORT_SYMBOL(lustre_common_put_super);
678 static void lmd_print(struct lustre_mount_data *lmd)
682 PRINT_CMD(D_MOUNT, " mount data:\n");
683 if (lmd_is_client(lmd))
684 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
685 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
686 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
689 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
691 if (lmd->lmd_recovery_time_soft)
692 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
693 lmd->lmd_recovery_time_soft);
695 if (lmd->lmd_recovery_time_hard)
696 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
697 lmd->lmd_recovery_time_hard);
699 for (i = 0; i < lmd->lmd_exclude_count; i++) {
700 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
701 lmd->lmd_exclude[i]);
705 /* Is this server on the exclusion list */
706 int lustre_check_exclusion(struct super_block *sb, char *svname)
708 struct lustre_sb_info *lsi = s2lsi(sb);
709 struct lustre_mount_data *lmd = lsi->lsi_lmd;
713 rc = server_name2index(svname, &index, NULL);
714 if (rc != LDD_F_SV_TYPE_OST)
715 /* Only exclude OSTs */
718 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
719 index, lmd->lmd_exclude_count, lmd->lmd_dev);
721 for (i = 0; i < lmd->lmd_exclude_count; i++) {
722 if (index == lmd->lmd_exclude[i]) {
723 CWARN("Excluding %s (on exclusion list)\n", svname);
730 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
731 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
733 const char *s1 = ptr, *s2;
734 __u32 index, *exclude_list;
737 /* The shortest an ost name can be is 8 chars: -OST0000.
738 * We don't actually know the fsname at this time, so in fact
739 * a user could specify any fsname.
741 devmax = strlen(ptr) / 8 + 1;
743 /* temp storage until we figure out how many we have */
744 exclude_list = kcalloc(devmax, sizeof(index), GFP_NOFS);
748 /* we enter this fn pointing at the '=' */
749 while (*s1 && *s1 != ' ' && *s1 != ',') {
751 rc = server_name2index(s1, &index, &s2);
753 CERROR("Can't parse server name '%s': rc = %d\n",
757 if (rc == LDD_F_SV_TYPE_OST)
758 exclude_list[lmd->lmd_exclude_count++] = index;
760 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
761 (uint)(s2-s1), s1, rc);
763 /* now we are pointing at ':' (next exclude)
764 * or ',' (end of excludes)
766 if (lmd->lmd_exclude_count >= devmax)
769 if (rc >= 0) /* non-err */
772 if (lmd->lmd_exclude_count) {
773 /* permanent, freed in lustre_free_lsi */
774 lmd->lmd_exclude = kcalloc(lmd->lmd_exclude_count,
775 sizeof(index), GFP_NOFS);
776 if (lmd->lmd_exclude) {
777 memcpy(lmd->lmd_exclude, exclude_list,
778 sizeof(index) * lmd->lmd_exclude_count);
781 lmd->lmd_exclude_count = 0;
788 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
793 kfree(lmd->lmd_mgssec);
794 lmd->lmd_mgssec = NULL;
796 tail = strchr(ptr, ',');
798 length = strlen(ptr);
802 lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS);
803 if (!lmd->lmd_mgssec)
806 memcpy(lmd->lmd_mgssec, ptr, length);
807 lmd->lmd_mgssec[length] = '\0';
811 static int lmd_parse_string(char **handle, char *ptr)
822 tail = strchr(ptr, ',');
824 length = strlen(ptr);
828 *handle = kzalloc(length + 1, GFP_NOFS);
832 memcpy(*handle, ptr, length);
833 (*handle)[length] = '\0';
838 /* Collect multiple values for mgsnid specifiers */
839 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
847 /* Find end of nidlist */
848 while (class_parse_nid_quiet(tail, &nid, &tail) == 0)
850 length = tail - *ptr;
852 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
857 oldlen = strlen(lmd->lmd_mgs) + 1;
859 mgsnid = kzalloc(oldlen + length + 1, GFP_NOFS);
864 /* Multiple mgsnid= are taken to mean failover locations */
865 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
866 mgsnid[oldlen - 1] = ':';
869 memcpy(mgsnid + oldlen, *ptr, length);
870 mgsnid[oldlen + length] = '\0';
871 lmd->lmd_mgs = mgsnid;
877 /** Parse mount line options
878 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
879 * dev is passed as device=uml1:/lustre by mount.lustre
881 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
883 char *s1, *s2, *devname = NULL;
884 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
889 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that /sbin/mount.lustre is installed.\n");
893 /* Options should be a string - try to detect old lmd data */
894 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
895 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of /sbin/mount.lustre. Please install version %s\n",
896 LUSTRE_VERSION_STRING);
899 lmd->lmd_magic = LMD_MAGIC;
901 lmd->lmd_params = kzalloc(LMD_PARAMS_MAXLEN, GFP_NOFS);
902 if (!lmd->lmd_params)
904 lmd->lmd_params[0] = '\0';
906 /* Set default flags here */
911 int time_min = OBD_RECOVERY_TIME_MIN;
913 /* Skip whitespace and extra commas */
914 while (*s1 == ' ' || *s1 == ',')
917 /* Client options are parsed in ll_options: eg. flock,
921 /* Parse non-ldiskfs options here. Rather than modifying
922 * ldiskfs, we just zero these out here
924 if (strncmp(s1, "abort_recov", 11) == 0) {
925 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
927 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
928 lmd->lmd_recovery_time_soft = max_t(int,
929 simple_strtoul(s1 + 19, NULL, 10), time_min);
931 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
932 lmd->lmd_recovery_time_hard = max_t(int,
933 simple_strtoul(s1 + 19, NULL, 10), time_min);
935 } else if (strncmp(s1, "noir", 4) == 0) {
936 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
938 } else if (strncmp(s1, "nosvc", 5) == 0) {
939 lmd->lmd_flags |= LMD_FLG_NOSVC;
941 } else if (strncmp(s1, "nomgs", 5) == 0) {
942 lmd->lmd_flags |= LMD_FLG_NOMGS;
944 } else if (strncmp(s1, "noscrub", 7) == 0) {
945 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
947 } else if (strncmp(s1, PARAM_MGSNODE,
948 sizeof(PARAM_MGSNODE) - 1) == 0) {
949 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
950 /* Assume the next mount opt is the first
951 * invalid nid we get to.
953 rc = lmd_parse_mgs(lmd, &s2);
957 } else if (strncmp(s1, "writeconf", 9) == 0) {
958 lmd->lmd_flags |= LMD_FLG_WRITECONF;
960 } else if (strncmp(s1, "update", 6) == 0) {
961 lmd->lmd_flags |= LMD_FLG_UPDATE;
963 } else if (strncmp(s1, "virgin", 6) == 0) {
964 lmd->lmd_flags |= LMD_FLG_VIRGIN;
966 } else if (strncmp(s1, "noprimnode", 10) == 0) {
967 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
969 } else if (strncmp(s1, "mgssec=", 7) == 0) {
970 rc = lmd_parse_mgssec(lmd, s1 + 7);
974 /* ost exclusion list */
975 } else if (strncmp(s1, "exclude=", 8) == 0) {
976 rc = lmd_make_exclusion(lmd, s1 + 7);
980 } else if (strncmp(s1, "mgs", 3) == 0) {
982 lmd->lmd_flags |= LMD_FLG_MGS;
984 } else if (strncmp(s1, "svname=", 7) == 0) {
985 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
989 } else if (strncmp(s1, "param=", 6) == 0) {
990 size_t length, params_length;
991 char *tail = strchr(s1 + 6, ',');
998 params_length = strlen(lmd->lmd_params);
999 if (params_length + length + 1 >= LMD_PARAMS_MAXLEN)
1001 strncat(lmd->lmd_params, s1 + 6, length);
1002 lmd->lmd_params[params_length + length] = '\0';
1003 strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
1005 } else if (strncmp(s1, "osd=", 4) == 0) {
1006 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1011 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1012 * end of the options.
1014 else if (strncmp(s1, "device=", 7) == 0) {
1016 /* terminate options right before device. device
1017 * must be the last one.
1024 s2 = strchr(s1, ',');
1032 memmove(s1, s2, strlen(s2) + 1);
1038 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name (need mount option 'device=...')\n");
1042 s1 = strstr(devname, ":/");
1045 lmd->lmd_flags |= LMD_FLG_CLIENT;
1046 /* Remove leading /s from fsname */
1047 while (*++s1 == '/')
1049 /* Freed in lustre_free_lsi */
1050 lmd->lmd_profile = kasprintf(GFP_NOFS, "%s-client", s1);
1051 if (!lmd->lmd_profile)
1055 /* Freed in lustre_free_lsi */
1056 lmd->lmd_dev = kzalloc(strlen(devname) + 1, GFP_NOFS);
1059 strcpy(lmd->lmd_dev, devname);
1061 /* Save mount options */
1062 s1 = options + strlen(options) - 1;
1063 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1065 if (*options != 0) {
1066 /* Freed in lustre_free_lsi */
1067 lmd->lmd_opts = kzalloc(strlen(options) + 1, GFP_NOFS);
1070 strcpy(lmd->lmd_opts, options);
1074 lmd->lmd_magic = LMD_MAGIC;
1079 CERROR("Bad mount options %s\n", options);
1083 struct lustre_mount_data2 {
1085 struct vfsmount *lmd2_mnt;
1088 /** This is the entry point for the mount call into Lustre.
1089 * This is called when a server or client is mounted,
1090 * and this is where we start setting things up.
1091 * @param data Mount options (e.g. -o flock,abort_recov)
1093 static int lustre_fill_super(struct super_block *sb, void *data, int silent)
1095 struct lustre_mount_data *lmd;
1096 struct lustre_mount_data2 *lmd2 = data;
1097 struct lustre_sb_info *lsi;
1100 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
1102 lsi = lustre_init_lsi(sb);
1108 * Disable lockdep during mount, because mount locking patterns are
1114 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1116 obd_zombie_barrier();
1118 /* Figure out the lmd from the mount options */
1119 if (lmd_parse((lmd2->lmd2_data), lmd)) {
1125 if (lmd_is_client(lmd)) {
1126 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1127 if (!client_fill_super)
1128 request_module("lustre");
1129 if (!client_fill_super) {
1130 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for client mount! Is the 'lustre' module loaded?\n");
1134 rc = lustre_start_mgc(sb);
1139 /* Connect and start */
1140 /* (should always be ll_fill_super) */
1141 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1142 /* c_f_s will call lustre_common_put_super on failure */
1145 CERROR("This is client-side-only module, cannot handle server mount.\n");
1149 /* If error happens in fill_super() call, @lsi will be killed there.
1150 * This is why we do not put it here.
1155 CERROR("Unable to mount %s (%d)\n",
1156 s2lsi(sb) ? lmd->lmd_dev : "", rc);
1158 CDEBUG(D_SUPER, "Mount %s complete\n",
1165 /* We can't call ll_fill_super by name because it lives in a module that
1166 * must be loaded after this one.
1168 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1169 struct vfsmount *mnt))
1171 client_fill_super = cfs;
1173 EXPORT_SYMBOL(lustre_register_client_fill_super);
1175 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1177 kill_super_cb = cfs;
1179 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1181 /***************** FS registration ******************/
1182 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1183 const char *devname, void *data)
1185 struct lustre_mount_data2 lmd2 = {
1190 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1193 static void lustre_kill_super(struct super_block *sb)
1195 struct lustre_sb_info *lsi = s2lsi(sb);
1197 if (kill_super_cb && lsi)
1198 (*kill_super_cb)(sb);
1200 kill_anon_super(sb);
1203 /** Register the "lustre" fs type
1205 static struct file_system_type lustre_fs_type = {
1206 .owner = THIS_MODULE,
1208 .mount = lustre_mount,
1209 .kill_sb = lustre_kill_super,
1210 .fs_flags = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV |
1211 FS_RENAME_DOES_D_MOVE,
1213 MODULE_ALIAS_FS("lustre");
1215 int lustre_register_fs(void)
1217 return register_filesystem(&lustre_fs_type);
1220 int lustre_unregister_fs(void)
1222 return unregister_filesystem(&lustre_fs_type);