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>
44 #define DEBUG_SUBSYSTEM S_CLASS
45 #define D_MOUNT (D_SUPER|D_CONFIG/*|D_WARNING */)
46 #define PRINT_CMD CDEBUG
50 #include <obd_class.h>
51 #include <lustre/lustre_user.h>
52 #include <lustre_log.h>
53 #include <lustre_disk.h>
54 #include <lustre_param.h>
56 static int (*client_fill_super
)(struct super_block
*sb
,
57 struct vfsmount
*mnt
);
59 static void (*kill_super_cb
)(struct super_block
*sb
);
61 /**************** config llog ********************/
63 /** Get a config log from the MGS and process it.
64 * This func is called for both clients and servers.
65 * Continue to process new statements appended to the logs
66 * (whenever the config lock is revoked) until lustre_end_log
68 * @param sb The superblock is used by the MGC to write to the local copy of
70 * @param logname The name of the llog to replicate from the MGS
71 * @param cfg Since the same mgc may be used to follow multiple config logs
72 * (e.g. ost1, ost2, client), the config_llog_instance keeps the state for
73 * this log, and is added to the mgc's list of logs to follow.
75 int lustre_process_log(struct super_block
*sb
, char *logname
,
76 struct config_llog_instance
*cfg
)
78 struct lustre_cfg
*lcfg
;
79 struct lustre_cfg_bufs
*bufs
;
80 struct lustre_sb_info
*lsi
= s2lsi(sb
);
81 struct obd_device
*mgc
= lsi
->lsi_mgc
;
92 /* mgc_process_config */
93 lustre_cfg_bufs_reset(bufs
, mgc
->obd_name
);
94 lustre_cfg_bufs_set_string(bufs
, 1, logname
);
95 lustre_cfg_bufs_set(bufs
, 2, cfg
, sizeof(*cfg
));
96 lustre_cfg_bufs_set(bufs
, 3, &sb
, sizeof(sb
));
97 lcfg
= lustre_cfg_new(LCFG_LOG_START
, bufs
);
98 rc
= obd_process_config(mgc
, sizeof(*lcfg
), lcfg
);
99 lustre_cfg_free(lcfg
);
104 LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s'"
105 "failed from the MGS (%d). Make sure this "
106 "client and the MGS are running compatible "
107 "versions of Lustre.\n",
108 mgc
->obd_name
, logname
, rc
);
111 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' "
112 "failed (%d). This may be the result of "
113 "communication errors between this node and "
114 "the MGS, a bad configuration, or other "
115 "errors. See the syslog for more "
116 "information.\n", mgc
->obd_name
, logname
,
119 /* class_obd_list(); */
122 EXPORT_SYMBOL(lustre_process_log
);
124 /* Stop watching this config log for updates */
125 int lustre_end_log(struct super_block
*sb
, char *logname
,
126 struct config_llog_instance
*cfg
)
128 struct lustre_cfg
*lcfg
;
129 struct lustre_cfg_bufs bufs
;
130 struct lustre_sb_info
*lsi
= s2lsi(sb
);
131 struct obd_device
*mgc
= lsi
->lsi_mgc
;
138 /* mgc_process_config */
139 lustre_cfg_bufs_reset(&bufs
, mgc
->obd_name
);
140 lustre_cfg_bufs_set_string(&bufs
, 1, logname
);
142 lustre_cfg_bufs_set(&bufs
, 2, cfg
, sizeof(*cfg
));
143 lcfg
= lustre_cfg_new(LCFG_LOG_END
, &bufs
);
144 rc
= obd_process_config(mgc
, sizeof(*lcfg
), lcfg
);
145 lustre_cfg_free(lcfg
);
148 EXPORT_SYMBOL(lustre_end_log
);
150 /**************** obd start *******************/
152 /** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
153 * lctl (and do for echo cli/srv.
155 int do_lcfg(char *cfgname
, lnet_nid_t nid
, int cmd
,
156 char *s1
, char *s2
, char *s3
, char *s4
)
158 struct lustre_cfg_bufs bufs
;
159 struct lustre_cfg
* lcfg
= NULL
;
162 CDEBUG(D_TRACE
, "lcfg %s %#x %s %s %s %s\n", cfgname
,
163 cmd
, s1
, s2
, s3
, s4
);
165 lustre_cfg_bufs_reset(&bufs
, cfgname
);
167 lustre_cfg_bufs_set_string(&bufs
, 1, s1
);
169 lustre_cfg_bufs_set_string(&bufs
, 2, s2
);
171 lustre_cfg_bufs_set_string(&bufs
, 3, s3
);
173 lustre_cfg_bufs_set_string(&bufs
, 4, s4
);
175 lcfg
= lustre_cfg_new(cmd
, &bufs
);
176 lcfg
->lcfg_nid
= nid
;
177 rc
= class_process_config(lcfg
);
178 lustre_cfg_free(lcfg
);
181 EXPORT_SYMBOL(do_lcfg
);
183 /** Call class_attach and class_setup. These methods in turn call
184 * obd type-specific methods.
186 int lustre_start_simple(char *obdname
, char *type
, char *uuid
,
187 char *s1
, char *s2
, char *s3
, char *s4
)
190 CDEBUG(D_MOUNT
, "Starting obd %s (typ=%s)\n", obdname
, type
);
192 rc
= do_lcfg(obdname
, 0, LCFG_ATTACH
, type
, uuid
, 0, 0);
194 CERROR("%s attach error %d\n", obdname
, rc
);
197 rc
= do_lcfg(obdname
, 0, LCFG_SETUP
, s1
, s2
, s3
, s4
);
199 CERROR("%s setup error %d\n", obdname
, rc
);
200 do_lcfg(obdname
, 0, LCFG_DETACH
, 0, 0, 0, 0);
205 DEFINE_MUTEX(mgc_start_lock
);
207 /** Set up a mgc obd to process startup logs
209 * \param sb [in] super block of the mgc obd
211 * \retval 0 success, otherwise error code
213 int lustre_start_mgc(struct super_block
*sb
)
215 struct obd_connect_data
*data
= NULL
;
216 struct lustre_sb_info
*lsi
= s2lsi(sb
);
217 struct obd_device
*obd
;
218 struct obd_export
*exp
;
219 struct obd_uuid
*uuid
;
222 char *mgcname
= NULL
, *niduuid
= NULL
, *mgssec
= NULL
;
225 int rc
= 0, i
= 0, j
, len
;
228 LASSERT(lsi
->lsi_lmd
);
230 /* Find the first non-lo MGS nid for our MGC name */
231 if (IS_SERVER(lsi
)) {
232 /* mount -o mgsnode=nid */
233 ptr
= lsi
->lsi_lmd
->lmd_mgs
;
234 if (lsi
->lsi_lmd
->lmd_mgs
&&
235 (class_parse_nid(lsi
->lsi_lmd
->lmd_mgs
, &nid
, &ptr
) == 0)) {
237 } else if (IS_MGS(lsi
)) {
238 lnet_process_id_t id
;
239 while ((rc
= LNetGetId(i
++, &id
)) != -ENOENT
) {
240 if (LNET_NETTYP(LNET_NIDNET(id
.nid
)) == LOLND
)
247 } else { /* client */
248 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
249 ptr
= lsi
->lsi_lmd
->lmd_dev
;
250 if (class_parse_nid(ptr
, &nid
, &ptr
) == 0)
254 CERROR("No valid MGS nids found.\n");
258 mutex_lock(&mgc_start_lock
);
260 len
= strlen(LUSTRE_MGC_OBDNAME
) + strlen(libcfs_nid2str(nid
)) + 1;
261 OBD_ALLOC(mgcname
, len
);
262 OBD_ALLOC(niduuid
, len
+ 2);
263 if (!mgcname
|| !niduuid
)
264 GOTO(out_free
, rc
= -ENOMEM
);
265 sprintf(mgcname
, "%s%s", LUSTRE_MGC_OBDNAME
, libcfs_nid2str(nid
));
267 mgssec
= lsi
->lsi_lmd
->lmd_mgssec
? lsi
->lsi_lmd
->lmd_mgssec
: "";
271 GOTO(out_free
, rc
= -ENOMEM
);
273 obd
= class_name2obd(mgcname
);
274 if (obd
&& !obd
->obd_stopping
) {
275 rc
= obd_set_info_async(NULL
, obd
->obd_self_export
,
276 strlen(KEY_MGSSEC
), KEY_MGSSEC
,
277 strlen(mgssec
), mgssec
, NULL
);
281 /* Re-using an existing MGC */
282 atomic_inc(&obd
->u
.cli
.cl_mgc_refcount
);
284 /* IR compatibility check, only for clients */
285 if (lmd_is_client(lsi
->lsi_lmd
)) {
287 int vallen
= sizeof(*data
);
288 __u32
*flags
= &lsi
->lsi_lmd
->lmd_flags
;
290 rc
= obd_get_info(NULL
, obd
->obd_self_export
,
291 strlen(KEY_CONN_DATA
), KEY_CONN_DATA
,
292 &vallen
, data
, NULL
);
294 has_ir
= OCD_HAS_FLAG(data
, IMP_RECOV
);
295 if (has_ir
^ !(*flags
& LMD_FLG_NOIR
)) {
296 /* LMD_FLG_NOIR is for test purpose only */
298 "Trying to mount a client with IR setting "
299 "not compatible with current mgc. "
300 "Force to use current mgc setting that is "
302 has_ir
? "enabled" : "disabled");
304 *flags
&= ~LMD_FLG_NOIR
;
306 *flags
|= LMD_FLG_NOIR
;
311 /* If we are restarting the MGS, don't try to keep the MGC's
312 old connection, or registration will fail. */
314 CDEBUG(D_MOUNT
, "New MGS with live MGC\n");
318 /* Try all connections, but only once (again).
319 We don't want to block another target from starting
320 (using its local copy of the log), but we do want to connect
321 if at all possible. */
323 CDEBUG(D_MOUNT
, "%s: Set MGC reconnect %d\n", mgcname
,recov_bk
);
324 rc
= obd_set_info_async(NULL
, obd
->obd_self_export
,
325 sizeof(KEY_INIT_RECOV_BACKUP
),
326 KEY_INIT_RECOV_BACKUP
,
327 sizeof(recov_bk
), &recov_bk
, NULL
);
331 CDEBUG(D_MOUNT
, "Start MGC '%s'\n", mgcname
);
333 /* Add the primary nids for the MGS */
335 sprintf(niduuid
, "%s_%x", mgcname
, i
);
336 if (IS_SERVER(lsi
)) {
337 ptr
= lsi
->lsi_lmd
->lmd_mgs
;
339 /* Use local nids (including LO) */
340 lnet_process_id_t id
;
341 while ((rc
= LNetGetId(i
++, &id
)) != -ENOENT
) {
342 rc
= do_lcfg(mgcname
, id
.nid
,
343 LCFG_ADD_UUID
, niduuid
, 0,0,0);
346 /* Use mgsnode= nids */
347 /* mount -o mgsnode=nid */
348 if (lsi
->lsi_lmd
->lmd_mgs
) {
349 ptr
= lsi
->lsi_lmd
->lmd_mgs
;
350 } else if (class_find_param(ptr
, PARAM_MGSNODE
,
352 CERROR("No MGS nids given.\n");
353 GOTO(out_free
, rc
= -EINVAL
);
355 while (class_parse_nid(ptr
, &nid
, &ptr
) == 0) {
356 rc
= do_lcfg(mgcname
, nid
,
357 LCFG_ADD_UUID
, niduuid
, 0,0,0);
361 } else { /* client */
362 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
363 ptr
= lsi
->lsi_lmd
->lmd_dev
;
364 while (class_parse_nid(ptr
, &nid
, &ptr
) == 0) {
365 rc
= do_lcfg(mgcname
, nid
,
366 LCFG_ADD_UUID
, niduuid
, 0,0,0);
368 /* Stop at the first failover nid */
374 CERROR("No valid MGS nids found.\n");
375 GOTO(out_free
, rc
= -EINVAL
);
377 lsi
->lsi_lmd
->lmd_mgs_failnodes
= 1;
379 /* Random uuid for MGC allows easier reconnects */
381 ll_generate_random_uuid(uuidc
);
382 class_uuid_unparse(uuidc
, uuid
);
385 rc
= lustre_start_simple(mgcname
, LUSTRE_MGC_NAME
,
386 (char *)uuid
->uuid
, LUSTRE_MGS_OBDNAME
,
392 /* Add any failover MGS nids */
394 while (ptr
&& ((*ptr
== ':' ||
395 class_find_param(ptr
, PARAM_MGSNODE
, &ptr
) == 0))) {
396 /* New failover node */
397 sprintf(niduuid
, "%s_%x", mgcname
, i
);
399 while (class_parse_nid_quiet(ptr
, &nid
, &ptr
) == 0) {
401 rc
= do_lcfg(mgcname
, nid
,
402 LCFG_ADD_UUID
, niduuid
, 0,0,0);
407 rc
= do_lcfg(mgcname
, 0, LCFG_ADD_CONN
,
415 lsi
->lsi_lmd
->lmd_mgs_failnodes
= i
;
417 obd
= class_name2obd(mgcname
);
419 CERROR("Can't find mgcobd %s\n", mgcname
);
420 GOTO(out_free
, rc
= -ENOTCONN
);
423 rc
= obd_set_info_async(NULL
, obd
->obd_self_export
,
424 strlen(KEY_MGSSEC
), KEY_MGSSEC
,
425 strlen(mgssec
), mgssec
, NULL
);
429 /* Keep a refcount of servers/clients who started with "mount",
430 so we know when we can get rid of the mgc. */
431 atomic_set(&obd
->u
.cli
.cl_mgc_refcount
, 1);
433 /* Try all connections, but only once. */
435 rc
= obd_set_info_async(NULL
, obd
->obd_self_export
,
436 sizeof(KEY_INIT_RECOV_BACKUP
),
437 KEY_INIT_RECOV_BACKUP
,
438 sizeof(recov_bk
), &recov_bk
, NULL
);
441 CWARN("can't set %s %d\n", KEY_INIT_RECOV_BACKUP
, rc
);
443 /* We connect to the MGS at setup, and don't disconnect until cleanup */
444 data
->ocd_connect_flags
= OBD_CONNECT_VERSION
| OBD_CONNECT_AT
|
445 OBD_CONNECT_FULL20
| OBD_CONNECT_IMP_RECOV
|
446 OBD_CONNECT_LVB_TYPE
;
448 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
449 data
->ocd_connect_flags
|= OBD_CONNECT_MNE_SWAB
;
451 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
454 if (lmd_is_client(lsi
->lsi_lmd
) &&
455 lsi
->lsi_lmd
->lmd_flags
& LMD_FLG_NOIR
)
456 data
->ocd_connect_flags
&= ~OBD_CONNECT_IMP_RECOV
;
457 data
->ocd_version
= LUSTRE_VERSION_CODE
;
458 rc
= obd_connect(NULL
, &exp
, obd
, &(obd
->obd_uuid
), data
, NULL
);
460 CERROR("connect failed %d\n", rc
);
464 obd
->u
.cli
.cl_mgc_mgsexp
= exp
;
467 /* Keep the mgc info in the sb. Note that many lsi's can point
471 mutex_unlock(&mgc_start_lock
);
476 OBD_FREE(mgcname
, len
);
478 OBD_FREE(niduuid
, len
+ 2);
482 static int lustre_stop_mgc(struct super_block
*sb
)
484 struct lustre_sb_info
*lsi
= s2lsi(sb
);
485 struct obd_device
*obd
;
486 char *niduuid
= 0, *ptr
= 0;
487 int i
, rc
= 0, len
= 0;
497 mutex_lock(&mgc_start_lock
);
498 LASSERT(atomic_read(&obd
->u
.cli
.cl_mgc_refcount
) > 0);
499 if (!atomic_dec_and_test(&obd
->u
.cli
.cl_mgc_refcount
)) {
500 /* This is not fatal, every client that stops
501 will call in here. */
502 CDEBUG(D_MOUNT
, "mgc still has %d references.\n",
503 atomic_read(&obd
->u
.cli
.cl_mgc_refcount
));
504 GOTO(out
, rc
= -EBUSY
);
507 /* The MGC has no recoverable data in any case.
508 * force shotdown set in umount_begin */
509 obd
->obd_no_recov
= 1;
511 if (obd
->u
.cli
.cl_mgc_mgsexp
) {
512 /* An error is not fatal, if we are unable to send the
513 disconnect mgs ping evictor cleans up the export */
514 rc
= obd_disconnect(obd
->u
.cli
.cl_mgc_mgsexp
);
516 CDEBUG(D_MOUNT
, "disconnect failed %d\n", rc
);
519 /* Save the obdname for cleaning the nid uuids, which are
521 len
= strlen(obd
->obd_name
) + 6;
522 OBD_ALLOC(niduuid
, len
);
524 strcpy(niduuid
, obd
->obd_name
);
525 ptr
= niduuid
+ strlen(niduuid
);
528 rc
= class_manual_cleanup(obd
);
532 /* Clean the nid uuids */
534 GOTO(out
, rc
= -ENOMEM
);
536 for (i
= 0; i
< lsi
->lsi_lmd
->lmd_mgs_failnodes
; i
++) {
537 sprintf(ptr
, "_%x", i
);
538 rc
= do_lcfg(LUSTRE_MGC_OBDNAME
, 0, LCFG_DEL_UUID
,
541 CERROR("del MDC UUID %s failed: rc = %d\n",
546 OBD_FREE(niduuid
, len
);
548 /* class_import_put will get rid of the additional connections */
549 mutex_unlock(&mgc_start_lock
);
553 /***************** lustre superblock **************/
555 struct lustre_sb_info
*lustre_init_lsi(struct super_block
*sb
)
557 struct lustre_sb_info
*lsi
;
563 OBD_ALLOC_PTR(lsi
->lsi_lmd
);
569 lsi
->lsi_lmd
->lmd_exclude_count
= 0;
570 lsi
->lsi_lmd
->lmd_recovery_time_soft
= 0;
571 lsi
->lsi_lmd
->lmd_recovery_time_hard
= 0;
572 s2lsi_nocast(sb
) = lsi
;
573 /* we take 1 extra ref for our setup */
574 atomic_set(&lsi
->lsi_mounts
, 1);
576 /* Default umount style */
577 lsi
->lsi_flags
= LSI_UMOUNT_FAILOVER
;
582 static int lustre_free_lsi(struct super_block
*sb
)
584 struct lustre_sb_info
*lsi
= s2lsi(sb
);
587 LASSERT(lsi
!= NULL
);
588 CDEBUG(D_MOUNT
, "Freeing lsi %p\n", lsi
);
590 /* someone didn't call server_put_mount. */
591 LASSERT(atomic_read(&lsi
->lsi_mounts
) == 0);
593 if (lsi
->lsi_lmd
!= NULL
) {
594 if (lsi
->lsi_lmd
->lmd_dev
!= NULL
)
595 OBD_FREE(lsi
->lsi_lmd
->lmd_dev
,
596 strlen(lsi
->lsi_lmd
->lmd_dev
) + 1);
597 if (lsi
->lsi_lmd
->lmd_profile
!= NULL
)
598 OBD_FREE(lsi
->lsi_lmd
->lmd_profile
,
599 strlen(lsi
->lsi_lmd
->lmd_profile
) + 1);
600 if (lsi
->lsi_lmd
->lmd_mgssec
!= NULL
)
601 OBD_FREE(lsi
->lsi_lmd
->lmd_mgssec
,
602 strlen(lsi
->lsi_lmd
->lmd_mgssec
) + 1);
603 if (lsi
->lsi_lmd
->lmd_opts
!= NULL
)
604 OBD_FREE(lsi
->lsi_lmd
->lmd_opts
,
605 strlen(lsi
->lsi_lmd
->lmd_opts
) + 1);
606 if (lsi
->lsi_lmd
->lmd_exclude_count
)
607 OBD_FREE(lsi
->lsi_lmd
->lmd_exclude
,
608 sizeof(lsi
->lsi_lmd
->lmd_exclude
[0]) *
609 lsi
->lsi_lmd
->lmd_exclude_count
);
610 if (lsi
->lsi_lmd
->lmd_mgs
!= NULL
)
611 OBD_FREE(lsi
->lsi_lmd
->lmd_mgs
,
612 strlen(lsi
->lsi_lmd
->lmd_mgs
) + 1);
613 if (lsi
->lsi_lmd
->lmd_osd_type
!= NULL
)
614 OBD_FREE(lsi
->lsi_lmd
->lmd_osd_type
,
615 strlen(lsi
->lsi_lmd
->lmd_osd_type
) + 1);
616 if (lsi
->lsi_lmd
->lmd_params
!= NULL
)
617 OBD_FREE(lsi
->lsi_lmd
->lmd_params
, 4096);
619 OBD_FREE(lsi
->lsi_lmd
, sizeof(*lsi
->lsi_lmd
));
622 LASSERT(lsi
->lsi_llsbi
== NULL
);
623 OBD_FREE(lsi
, sizeof(*lsi
));
624 s2lsi_nocast(sb
) = NULL
;
629 /* The lsi has one reference for every server that is using the disk -
630 e.g. MDT, MGS, and potentially MGC */
631 int lustre_put_lsi(struct super_block
*sb
)
633 struct lustre_sb_info
*lsi
= s2lsi(sb
);
636 LASSERT(lsi
!= NULL
);
638 CDEBUG(D_MOUNT
, "put %p %d\n", sb
, atomic_read(&lsi
->lsi_mounts
));
639 if (atomic_dec_and_test(&lsi
->lsi_mounts
)) {
640 if (IS_SERVER(lsi
) && lsi
->lsi_osd_exp
) {
641 obd_disconnect(lsi
->lsi_osd_exp
);
642 /* wait till OSD is gone */
643 obd_zombie_barrier();
652 * <FSNAME><SEPERATOR><TYPE><INDEX>
653 * FSNAME is between 1 and 8 characters (inclusive).
654 * Excluded characters are '/' and ':'
655 * SEPERATOR is either ':' or '-'
656 * TYPE: "OST", "MDT", etc.
657 * INDEX: Hex representation of the index
660 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
661 * @param [in] svname server name including type and index
662 * @param [out] fsname Buffer to copy filesystem name prefix into.
663 * Must have at least 'strlen(fsname) + 1' chars.
664 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
667 int server_name2fsname(const char *svname
, char *fsname
, const char **endptr
)
671 dash
= svname
+ strnlen(svname
, 8); /* max fsname length is 8 */
672 for (; dash
> svname
&& *dash
!= '-' && *dash
!= ':'; dash
--)
677 if (fsname
!= NULL
) {
678 strncpy(fsname
, svname
, dash
- svname
);
679 fsname
[dash
- svname
] = '\0';
687 EXPORT_SYMBOL(server_name2fsname
);
690 * Get service name (svname) from string
692 * if endptr isn't NULL it is set to end of fsname *
694 int server_name2svname(const char *label
, char *svname
, const char **endptr
,
700 /* We use server_name2fsname() just for parsing */
701 rc
= server_name2fsname(label
, NULL
, &dash
);
708 if (strlcpy(svname
, dash
+ 1, svsize
) >= svsize
)
713 EXPORT_SYMBOL(server_name2svname
);
716 /* Get the index from the obd name.
719 if endptr isn't NULL it is set to end of name */
720 int server_name2index(const char *svname
, __u32
*idx
, const char **endptr
)
726 /* We use server_name2fsname() just for parsing */
727 rc
= server_name2fsname(svname
, NULL
, &dash
);
733 if (strncmp(dash
, "MDT", 3) == 0)
734 rc
= LDD_F_SV_TYPE_MDT
;
735 else if (strncmp(dash
, "OST", 3) == 0)
736 rc
= LDD_F_SV_TYPE_OST
;
742 if (strncmp(dash
, "all", 3) == 0) {
745 return rc
| LDD_F_SV_ALL
;
748 index
= simple_strtoul(dash
, (char **)endptr
, 16);
752 /* Account for -mdc after index that is possible when specifying mdt */
753 if (endptr
!= NULL
&& strncmp(LUSTRE_MDC_NAME
, *endptr
+ 1,
754 sizeof(LUSTRE_MDC_NAME
)-1) == 0)
755 *endptr
+= sizeof(LUSTRE_MDC_NAME
);
759 EXPORT_SYMBOL(server_name2index
);
761 /*************** mount common betweeen server and client ***************/
764 int lustre_common_put_super(struct super_block
*sb
)
769 CDEBUG(D_MOUNT
, "dropping sb %p\n", sb
);
771 /* Drop a ref to the MGC */
772 rc
= lustre_stop_mgc(sb
);
773 if (rc
&& (rc
!= -ENOENT
)) {
775 CERROR("Can't stop MGC: %d\n", rc
);
778 /* BUSY just means that there's some other obd that
779 needs the mgc. Let him clean it up. */
780 CDEBUG(D_MOUNT
, "MGC still in use\n");
782 /* Drop a ref to the mounted disk */
787 EXPORT_SYMBOL(lustre_common_put_super
);
789 static void lmd_print(struct lustre_mount_data
*lmd
)
793 PRINT_CMD(D_MOUNT
, " mount data:\n");
794 if (lmd_is_client(lmd
))
795 PRINT_CMD(D_MOUNT
, "profile: %s\n", lmd
->lmd_profile
);
796 PRINT_CMD(D_MOUNT
, "device: %s\n", lmd
->lmd_dev
);
797 PRINT_CMD(D_MOUNT
, "flags: %x\n", lmd
->lmd_flags
);
800 PRINT_CMD(D_MOUNT
, "options: %s\n", lmd
->lmd_opts
);
802 if (lmd
->lmd_recovery_time_soft
)
803 PRINT_CMD(D_MOUNT
, "recovery time soft: %d\n",
804 lmd
->lmd_recovery_time_soft
);
806 if (lmd
->lmd_recovery_time_hard
)
807 PRINT_CMD(D_MOUNT
, "recovery time hard: %d\n",
808 lmd
->lmd_recovery_time_hard
);
810 for (i
= 0; i
< lmd
->lmd_exclude_count
; i
++) {
811 PRINT_CMD(D_MOUNT
, "exclude %d: OST%04x\n", i
,
812 lmd
->lmd_exclude
[i
]);
816 /* Is this server on the exclusion list */
817 int lustre_check_exclusion(struct super_block
*sb
, char *svname
)
819 struct lustre_sb_info
*lsi
= s2lsi(sb
);
820 struct lustre_mount_data
*lmd
= lsi
->lsi_lmd
;
825 rc
= server_name2index(svname
, &index
, NULL
);
826 if (rc
!= LDD_F_SV_TYPE_OST
)
827 /* Only exclude OSTs */
830 CDEBUG(D_MOUNT
, "Check exclusion %s (%d) in %d of %s\n", svname
,
831 index
, lmd
->lmd_exclude_count
, lmd
->lmd_dev
);
833 for(i
= 0; i
< lmd
->lmd_exclude_count
; i
++) {
834 if (index
== lmd
->lmd_exclude
[i
]) {
835 CWARN("Excluding %s (on exclusion list)\n", svname
);
842 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
843 static int lmd_make_exclusion(struct lustre_mount_data
*lmd
, const char *ptr
)
845 const char *s1
= ptr
, *s2
;
846 __u32 index
, *exclude_list
;
850 /* The shortest an ost name can be is 8 chars: -OST0000.
851 We don't actually know the fsname at this time, so in fact
852 a user could specify any fsname. */
853 devmax
= strlen(ptr
) / 8 + 1;
855 /* temp storage until we figure out how many we have */
856 OBD_ALLOC(exclude_list
, sizeof(index
) * devmax
);
860 /* we enter this fn pointing at the '=' */
861 while (*s1
&& *s1
!= ' ' && *s1
!= ',') {
863 rc
= server_name2index(s1
, &index
, &s2
);
865 CERROR("Can't parse server name '%s': rc = %d\n",
869 if (rc
== LDD_F_SV_TYPE_OST
)
870 exclude_list
[lmd
->lmd_exclude_count
++] = index
;
872 CDEBUG(D_MOUNT
, "ignoring exclude %.*s: type = %#x\n",
873 (uint
)(s2
-s1
), s1
, rc
);
875 /* now we are pointing at ':' (next exclude)
876 or ',' (end of excludes) */
877 if (lmd
->lmd_exclude_count
>= devmax
)
880 if (rc
>= 0) /* non-err */
883 if (lmd
->lmd_exclude_count
) {
884 /* permanent, freed in lustre_free_lsi */
885 OBD_ALLOC(lmd
->lmd_exclude
, sizeof(index
) *
886 lmd
->lmd_exclude_count
);
887 if (lmd
->lmd_exclude
) {
888 memcpy(lmd
->lmd_exclude
, exclude_list
,
889 sizeof(index
) * lmd
->lmd_exclude_count
);
892 lmd
->lmd_exclude_count
= 0;
895 OBD_FREE(exclude_list
, sizeof(index
) * devmax
);
899 static int lmd_parse_mgssec(struct lustre_mount_data
*lmd
, char *ptr
)
904 if (lmd
->lmd_mgssec
!= NULL
) {
905 OBD_FREE(lmd
->lmd_mgssec
, strlen(lmd
->lmd_mgssec
) + 1);
906 lmd
->lmd_mgssec
= NULL
;
909 tail
= strchr(ptr
, ',');
911 length
= strlen(ptr
);
915 OBD_ALLOC(lmd
->lmd_mgssec
, length
+ 1);
916 if (lmd
->lmd_mgssec
== NULL
)
919 memcpy(lmd
->lmd_mgssec
, ptr
, length
);
920 lmd
->lmd_mgssec
[length
] = '\0';
924 static int lmd_parse_string(char **handle
, char *ptr
)
929 if ((handle
== NULL
) || (ptr
== NULL
))
932 if (*handle
!= NULL
) {
933 OBD_FREE(*handle
, strlen(*handle
) + 1);
937 tail
= strchr(ptr
, ',');
939 length
= strlen(ptr
);
943 OBD_ALLOC(*handle
, length
+ 1);
947 memcpy(*handle
, ptr
, length
);
948 (*handle
)[length
] = '\0';
953 /* Collect multiple values for mgsnid specifiers */
954 static int lmd_parse_mgs(struct lustre_mount_data
*lmd
, char **ptr
)
962 /* Find end of nidlist */
963 while (class_parse_nid_quiet(tail
, &nid
, &tail
) == 0) {}
964 length
= tail
- *ptr
;
966 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr
);
970 if (lmd
->lmd_mgs
!= NULL
)
971 oldlen
= strlen(lmd
->lmd_mgs
) + 1;
973 OBD_ALLOC(mgsnid
, oldlen
+ length
+ 1);
977 if (lmd
->lmd_mgs
!= NULL
) {
978 /* Multiple mgsnid= are taken to mean failover locations */
979 memcpy(mgsnid
, lmd
->lmd_mgs
, oldlen
);
980 mgsnid
[oldlen
- 1] = ':';
981 OBD_FREE(lmd
->lmd_mgs
, oldlen
);
983 memcpy(mgsnid
+ oldlen
, *ptr
, length
);
984 mgsnid
[oldlen
+ length
] = '\0';
985 lmd
->lmd_mgs
= mgsnid
;
991 /** Parse mount line options
992 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
993 * dev is passed as device=uml1:/lustre by mount.lustre
995 static int lmd_parse(char *options
, struct lustre_mount_data
*lmd
)
997 char *s1
, *s2
, *devname
= NULL
;
998 struct lustre_mount_data
*raw
= (struct lustre_mount_data
*)options
;
1004 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that "
1005 "/sbin/mount.lustre is installed.\n");
1009 /* Options should be a string - try to detect old lmd data */
1010 if ((raw
->lmd_magic
& 0xffffff00) == (LMD_MAGIC
& 0xffffff00)) {
1011 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of "
1012 "/sbin/mount.lustre. Please install "
1013 "version %s\n", LUSTRE_VERSION_STRING
);
1016 lmd
->lmd_magic
= LMD_MAGIC
;
1018 OBD_ALLOC(lmd
->lmd_params
, 4096);
1019 if (lmd
->lmd_params
== NULL
)
1021 lmd
->lmd_params
[0] = '\0';
1023 /* Set default flags here */
1028 int time_min
= OBD_RECOVERY_TIME_MIN
;
1030 /* Skip whitespace and extra commas */
1031 while (*s1
== ' ' || *s1
== ',')
1034 /* Client options are parsed in ll_options: eg. flock,
1037 /* Parse non-ldiskfs options here. Rather than modifying
1038 ldiskfs, we just zero these out here */
1039 if (strncmp(s1
, "abort_recov", 11) == 0) {
1040 lmd
->lmd_flags
|= LMD_FLG_ABORT_RECOV
;
1042 } else if (strncmp(s1
, "recovery_time_soft=", 19) == 0) {
1043 lmd
->lmd_recovery_time_soft
= max_t(int,
1044 simple_strtoul(s1
+ 19, NULL
, 10), time_min
);
1046 } else if (strncmp(s1
, "recovery_time_hard=", 19) == 0) {
1047 lmd
->lmd_recovery_time_hard
= max_t(int,
1048 simple_strtoul(s1
+ 19, NULL
, 10), time_min
);
1050 } else if (strncmp(s1
, "noir", 4) == 0) {
1051 lmd
->lmd_flags
|= LMD_FLG_NOIR
; /* test purpose only. */
1053 } else if (strncmp(s1
, "nosvc", 5) == 0) {
1054 lmd
->lmd_flags
|= LMD_FLG_NOSVC
;
1056 } else if (strncmp(s1
, "nomgs", 5) == 0) {
1057 lmd
->lmd_flags
|= LMD_FLG_NOMGS
;
1059 } else if (strncmp(s1
, "noscrub", 7) == 0) {
1060 lmd
->lmd_flags
|= LMD_FLG_NOSCRUB
;
1062 } else if (strncmp(s1
, PARAM_MGSNODE
,
1063 sizeof(PARAM_MGSNODE
) - 1) == 0) {
1064 s2
= s1
+ sizeof(PARAM_MGSNODE
) - 1;
1065 /* Assume the next mount opt is the first
1066 invalid nid we get to. */
1067 rc
= lmd_parse_mgs(lmd
, &s2
);
1071 } else if (strncmp(s1
, "writeconf", 9) == 0) {
1072 lmd
->lmd_flags
|= LMD_FLG_WRITECONF
;
1074 } else if (strncmp(s1
, "update", 6) == 0) {
1075 lmd
->lmd_flags
|= LMD_FLG_UPDATE
;
1077 } else if (strncmp(s1
, "virgin", 6) == 0) {
1078 lmd
->lmd_flags
|= LMD_FLG_VIRGIN
;
1080 } else if (strncmp(s1
, "noprimnode", 10) == 0) {
1081 lmd
->lmd_flags
|= LMD_FLG_NO_PRIMNODE
;
1083 } else if (strncmp(s1
, "mgssec=", 7) == 0) {
1084 rc
= lmd_parse_mgssec(lmd
, s1
+ 7);
1088 /* ost exclusion list */
1089 } else if (strncmp(s1
, "exclude=", 8) == 0) {
1090 rc
= lmd_make_exclusion(lmd
, s1
+ 7);
1094 } else if (strncmp(s1
, "mgs", 3) == 0) {
1096 lmd
->lmd_flags
|= LMD_FLG_MGS
;
1098 } else if (strncmp(s1
, "svname=", 7) == 0) {
1099 rc
= lmd_parse_string(&lmd
->lmd_profile
, s1
+ 7);
1103 } else if (strncmp(s1
, "param=", 6) == 0) {
1105 char *tail
= strchr(s1
+ 6, ',');
1107 length
= strlen(s1
);
1111 strncat(lmd
->lmd_params
, s1
+ 6, length
);
1112 strcat(lmd
->lmd_params
, " ");
1114 } else if (strncmp(s1
, "osd=", 4) == 0) {
1115 rc
= lmd_parse_string(&lmd
->lmd_osd_type
, s1
+ 4);
1120 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1121 end of the options. */
1122 else if (strncmp(s1
, "device=", 7) == 0) {
1124 /* terminate options right before device. device
1125 must be the last one. */
1131 s2
= strchr(s1
, ',');
1139 memmove(s1
, s2
, strlen(s2
) + 1);
1145 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name "
1146 "(need mount option 'device=...')\n");
1150 s1
= strstr(devname
, ":/");
1153 lmd
->lmd_flags
|= LMD_FLG_CLIENT
;
1154 /* Remove leading /s from fsname */
1155 while (*++s1
== '/') ;
1156 /* Freed in lustre_free_lsi */
1157 OBD_ALLOC(lmd
->lmd_profile
, strlen(s1
) + 8);
1158 if (!lmd
->lmd_profile
)
1160 sprintf(lmd
->lmd_profile
, "%s-client", s1
);
1163 /* Freed in lustre_free_lsi */
1164 OBD_ALLOC(lmd
->lmd_dev
, strlen(devname
) + 1);
1167 strcpy(lmd
->lmd_dev
, devname
);
1169 /* Save mount options */
1170 s1
= options
+ strlen(options
) - 1;
1171 while (s1
>= options
&& (*s1
== ',' || *s1
== ' '))
1173 if (*options
!= 0) {
1174 /* Freed in lustre_free_lsi */
1175 OBD_ALLOC(lmd
->lmd_opts
, strlen(options
) + 1);
1178 strcpy(lmd
->lmd_opts
, options
);
1182 lmd
->lmd_magic
= LMD_MAGIC
;
1187 CERROR("Bad mount options %s\n", options
);
1191 struct lustre_mount_data2
{
1193 struct vfsmount
*lmd2_mnt
;
1196 /** This is the entry point for the mount call into Lustre.
1197 * This is called when a server or client is mounted,
1198 * and this is where we start setting things up.
1199 * @param data Mount options (e.g. -o flock,abort_recov)
1201 int lustre_fill_super(struct super_block
*sb
, void *data
, int silent
)
1203 struct lustre_mount_data
*lmd
;
1204 struct lustre_mount_data2
*lmd2
= data
;
1205 struct lustre_sb_info
*lsi
;
1209 CDEBUG(D_MOUNT
|D_VFSTRACE
, "VFS Op: sb %p\n", sb
);
1211 lsi
= lustre_init_lsi(sb
);
1217 * Disable lockdep during mount, because mount locking patterns are
1223 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1225 obd_zombie_barrier();
1227 /* Figure out the lmd from the mount options */
1228 if (lmd_parse((char *)(lmd2
->lmd2_data
), lmd
)) {
1230 GOTO(out
, rc
= -EINVAL
);
1233 if (lmd_is_client(lmd
)) {
1234 CDEBUG(D_MOUNT
, "Mounting client %s\n", lmd
->lmd_profile
);
1235 if (!client_fill_super
) {
1236 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for "
1237 "client mount! Is the 'lustre' "
1238 "module loaded?\n");
1242 rc
= lustre_start_mgc(sb
);
1247 /* Connect and start */
1248 /* (should always be ll_fill_super) */
1249 rc
= (*client_fill_super
)(sb
, lmd2
->lmd2_mnt
);
1250 /* c_f_s will call lustre_common_put_super on failure */
1253 CERROR("This is client-side-only module, "
1254 "cannot handle server mount.\n");
1258 /* If error happens in fill_super() call, @lsi will be killed there.
1259 * This is why we do not put it here. */
1263 CERROR("Unable to mount %s (%d)\n",
1264 s2lsi(sb
) ? lmd
->lmd_dev
: "", rc
);
1266 CDEBUG(D_SUPER
, "Mount %s complete\n",
1274 /* We can't call ll_fill_super by name because it lives in a module that
1275 must be loaded after this one. */
1276 void lustre_register_client_fill_super(int (*cfs
)(struct super_block
*sb
,
1277 struct vfsmount
*mnt
))
1279 client_fill_super
= cfs
;
1281 EXPORT_SYMBOL(lustre_register_client_fill_super
);
1283 void lustre_register_kill_super_cb(void (*cfs
)(struct super_block
*sb
))
1285 kill_super_cb
= cfs
;
1287 EXPORT_SYMBOL(lustre_register_kill_super_cb
);
1289 /***************** FS registration ******************/
1290 struct dentry
*lustre_mount(struct file_system_type
*fs_type
, int flags
,
1291 const char *devname
, void *data
)
1293 struct lustre_mount_data2 lmd2
= { data
, NULL
};
1295 return mount_nodev(fs_type
, flags
, &lmd2
, lustre_fill_super
);
1298 void lustre_kill_super(struct super_block
*sb
)
1300 struct lustre_sb_info
*lsi
= s2lsi(sb
);
1302 if (kill_super_cb
&& lsi
&& !IS_SERVER(lsi
))
1303 (*kill_super_cb
)(sb
);
1305 kill_anon_super(sb
);
1308 /** Register the "lustre" fs type
1310 struct file_system_type lustre_fs_type
= {
1311 .owner
= THIS_MODULE
,
1313 .mount
= lustre_mount
,
1314 .kill_sb
= lustre_kill_super
,
1315 .fs_flags
= FS_BINARY_MOUNTDATA
| FS_REQUIRES_DEV
|
1316 FS_HAS_FIEMAP
| FS_RENAME_DOES_D_MOVE
,
1319 int lustre_register_fs(void)
1321 return register_filesystem(&lustre_fs_type
);
1324 int lustre_unregister_fs(void)
1326 return unregister_filesystem(&lustre_fs_type
);