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, 2017, 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>
40 #define DEBUG_SUBSYSTEM S_CLASS
41 #define D_MOUNT (D_SUPER|D_CONFIG/*|D_WARNING */)
42 #define PRINT_CMD CDEBUG
45 #include <obd_class.h>
46 #include <linux/random.h>
47 #include <libcfs/linux/linux-uuid.h>
48 #include <linux/version.h>
49 #include <lustre_log.h>
50 #include <lustre_disk.h>
51 #include <uapi/linux/lustre/lustre_param.h>
53 static int (*client_fill_super)(struct super_block *sb,
54 struct vfsmount *mnt);
56 static void (*kill_super_cb)(struct super_block *sb);
58 /**************** config llog ********************/
61 * Get a config log from the MGS and process it.
62 * This func is called for both clients and servers.
63 * Continue to process new statements appended to the logs
64 * (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;
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 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
99 GOTO(out, rc = -ENOMEM);
100 lustre_cfg_init(lcfg, LCFG_LOG_START, bufs);
102 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
103 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
108 LCONSOLE_ERROR_MSG(0x15b,
109 "%s: Configuration from log %s failed from MGS %d. Check client and MGS are on compatible version.\n",
110 mgc->obd_name, logname, rc);
112 LCONSOLE_ERROR_MSG(0x15c,
113 "%s: Confguration from log %s failed from MGS %d. Communication error between node & MGS, a bad configuration, or other errors. See syslog for more info\n",
114 mgc->obd_name, logname, rc);
116 /* class_obd_list(); */
119 EXPORT_SYMBOL(lustre_process_log);
121 /* Stop watching this config log for updates */
122 int lustre_end_log(struct super_block *sb, char *logname,
123 struct config_llog_instance *cfg)
125 struct lustre_cfg *lcfg;
126 struct lustre_cfg_bufs bufs;
127 struct lustre_sb_info *lsi = s2lsi(sb);
128 struct obd_device *mgc = lsi->lsi_mgc;
136 /* mgc_process_config */
137 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
138 lustre_cfg_bufs_set_string(&bufs, 1, logname);
140 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
141 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
144 lustre_cfg_init(lcfg, LCFG_LOG_END, &bufs);
145 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
146 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
149 EXPORT_SYMBOL(lustre_end_log);
151 /**************** OBD start *******************/
154 * lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
155 * lctl (and do for echo cli/srv.
157 static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
158 char *s1, char *s2, char *s3, char *s4)
160 struct lustre_cfg_bufs bufs;
161 struct lustre_cfg *lcfg = NULL;
164 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
165 cmd, s1, s2, s3, s4);
167 lustre_cfg_bufs_reset(&bufs, cfgname);
169 lustre_cfg_bufs_set_string(&bufs, 1, s1);
171 lustre_cfg_bufs_set_string(&bufs, 2, s2);
173 lustre_cfg_bufs_set_string(&bufs, 3, s3);
175 lustre_cfg_bufs_set_string(&bufs, 4, s4);
177 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
180 lustre_cfg_init(lcfg, cmd, &bufs);
181 lcfg->lcfg_nid = nid;
182 rc = class_process_config(lcfg);
183 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
188 * Call class_attach and class_setup. These methods in turn call
189 * OBD type-specific methods.
191 int lustre_start_simple(char *obdname, char *type, char *uuid,
192 char *s1, char *s2, char *s3, char *s4)
196 CDEBUG(D_MOUNT, "Starting OBD %s (typ=%s)\n", obdname, type);
198 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
200 CERROR("%s attach error %d\n", obdname, rc);
203 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
205 CERROR("%s setup error %d\n", obdname, rc);
206 do_lcfg(obdname, 0, LCFG_DETACH, NULL, NULL, NULL, NULL);
211 static DEFINE_MUTEX(mgc_start_lock);
214 * Set up a MGC OBD to process startup logs
216 * \param sb [in] super block of the MGC OBD
218 * \retval 0 success, otherwise error code
220 int lustre_start_mgc(struct super_block *sb)
222 struct obd_connect_data *data = NULL;
223 struct lustre_sb_info *lsi = s2lsi(sb);
224 struct obd_device *obd;
225 struct obd_export *exp;
226 struct obd_uuid *uuid = NULL;
229 char nidstr[LNET_NIDSTR_SIZE];
230 char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
232 int rc = 0, i = 0, j;
237 LASSERT(lsi->lsi_lmd);
239 /* Find the first non-lo MGS NID for our MGC name */
240 if (IS_SERVER(lsi)) {
241 /* mount -o mgsnode=nid */
242 ptr = lsi->lsi_lmd->lmd_mgs;
243 if (lsi->lsi_lmd->lmd_mgs &&
244 (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) {
246 } else if (IS_MGS(lsi)) {
247 struct lnet_process_id id;
249 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
250 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
257 } else { /* client */
258 /* Use NIDs from mount line: uml1,1@elan:uml2,2@elan:/lustre */
259 ptr = lsi->lsi_lmd->lmd_dev;
260 if (class_parse_nid(ptr, &nid, &ptr) == 0)
264 CERROR("No valid MGS NIDs found.\n");
268 mutex_lock(&mgc_start_lock);
270 libcfs_nid2str_r(nid, nidstr, sizeof(nidstr));
271 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(nidstr) + 1;
272 OBD_ALLOC(mgcname, len);
273 OBD_ALLOC(niduuid, len + 2);
274 if (mgcname == NULL || niduuid == NULL)
275 GOTO(out_free, rc = -ENOMEM);
276 snprintf(mgcname, len, "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
278 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
282 GOTO(out_free, rc = -ENOMEM);
284 obd = class_name2obd(mgcname);
285 if (obd && !obd->obd_stopping) {
288 rc = obd_set_info_async(NULL, obd->obd_self_export,
289 strlen(KEY_MGSSEC), KEY_MGSSEC,
290 strlen(mgssec), mgssec, NULL);
294 /* Re-using an existing MGC */
295 atomic_inc(&obd->u.cli.cl_mgc_refcount);
297 /* IR compatibility check, only for clients */
298 if (lmd_is_client(lsi->lsi_lmd)) {
300 int vallen = sizeof(*data);
301 __u32 *flags = &lsi->lsi_lmd->lmd_flags;
303 rc = obd_get_info(NULL, obd->obd_self_export,
304 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
307 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
308 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
309 /* LMD_FLG_NOIR is for test purpose only */
311 "Mounting client with IR setting not compatible with current MGC. Using MGC setting that is IR %s",
312 has_ir ? "enabled" : "disabled");
314 *flags &= ~LMD_FLG_NOIR;
316 *flags |= LMD_FLG_NOIR;
322 * If we are restarting the MGS, don't try to keep the MGC's
323 * old connection, or registration will fail.
326 CDEBUG(D_MOUNT, "New MGS with live MGC\n");
331 * Try all connections, but only once (again).
332 * We don't want to block another target from starting
333 * (using its local copy of the log), but we do want to connect
334 * if at all possible.
337 CDEBUG(D_MOUNT, "%s:Set MGC reconnect %d\n", mgcname, recov_bk);
338 rc = obd_set_info_async(NULL, obd->obd_self_export,
339 sizeof(KEY_INIT_RECOV_BACKUP),
340 KEY_INIT_RECOV_BACKUP,
341 sizeof(recov_bk), &recov_bk, NULL);
345 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
347 /* Add the primary NIDs for the MGS */
349 snprintf(niduuid, len + 2, "%s_%x", mgcname, i);
350 if (IS_SERVER(lsi)) {
351 ptr = lsi->lsi_lmd->lmd_mgs;
352 CDEBUG(D_MOUNT, "mgs NIDs %s.\n", ptr);
354 /* Use local NIDs (including LO) */
355 struct lnet_process_id id;
357 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
358 rc = do_lcfg(mgcname, id.nid, LCFG_ADD_UUID,
359 niduuid, NULL, NULL, NULL);
362 /* Use mgsnode= nids */
363 /* mount -o mgsnode=nid */
364 if (lsi->lsi_lmd->lmd_mgs) {
365 ptr = lsi->lsi_lmd->lmd_mgs;
366 } else if (class_find_param(ptr, PARAM_MGSNODE,
368 CERROR("No MGS NIDs given.\n");
369 GOTO(out_free, rc = -EINVAL);
372 * Add primary MGS NID(s).
373 * Multiple NIDs on one MGS node are separated
376 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
377 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
378 niduuid, NULL, NULL, NULL);
381 /* Stop at the first failover NID */
386 } else { /* client */
387 /* Use NIDs from mount line: uml1,1@elan:uml2,2@elan:/lustre */
388 ptr = lsi->lsi_lmd->lmd_dev;
389 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
390 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
391 niduuid, NULL, NULL, NULL);
394 /* Stop at the first failover NID */
400 CERROR("No valid MGS NIDs found.\n");
401 GOTO(out_free, rc = -EINVAL);
403 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
405 /* Random uuid for MGC allows easier reconnects */
408 GOTO(out_free, rc = -ENOMEM);
410 generate_random_uuid(uuidc.b);
411 snprintf(uuid->uuid, UUID_SIZE, "%pU", uuidc.b);
414 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
415 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
416 niduuid, NULL, NULL);
420 /* Add any failover MGS NIDs */
422 while (ptr && ((*ptr == ':' ||
423 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
424 /* New failover node */
425 sprintf(niduuid, "%s_%x", mgcname, i);
427 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
428 rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID,
429 niduuid, NULL, NULL, NULL);
436 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
437 niduuid, NULL, NULL, NULL);
445 lsi->lsi_lmd->lmd_mgs_failnodes = i;
447 obd = class_name2obd(mgcname);
449 CERROR("Can't find mgcobd %s\n", mgcname);
450 GOTO(out_free, rc = -ENOTCONN);
453 rc = obd_set_info_async(NULL, obd->obd_self_export,
454 strlen(KEY_MGSSEC), KEY_MGSSEC,
455 strlen(mgssec), mgssec, NULL);
460 * Keep a refcount of servers/clients who started with "mount",
461 * so we know when we can get rid of the mgc.
463 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
465 /* We connect to the MGS at setup, and don't disconnect until cleanup */
466 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
467 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
468 OBD_CONNECT_LVB_TYPE |
469 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_BARRIER;
471 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
472 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
475 if (lmd_is_client(lsi->lsi_lmd) &&
476 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
477 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
478 data->ocd_version = LUSTRE_VERSION_CODE;
479 rc = obd_connect(NULL, &exp, obd, uuid, data, NULL);
481 CERROR("connect failed %d\n", rc);
485 obd->u.cli.cl_mgc_mgsexp = exp;
489 * Keep the MGC info in the sb. Note that many lsi's can point
494 mutex_unlock(&mgc_start_lock);
501 OBD_FREE(mgcname, len);
503 OBD_FREE(niduuid, len + 2);
507 static int lustre_stop_mgc(struct super_block *sb)
509 struct lustre_sb_info *lsi = s2lsi(sb);
510 struct obd_device *obd;
511 char *niduuid = NULL, *ptr = NULL;
512 int i, rc = 0, len = 0;
523 mutex_lock(&mgc_start_lock);
524 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
525 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
527 * This is not fatal, every client that stops
530 CDEBUG(D_MOUNT, "MGC still has %d references.\n",
531 atomic_read(&obd->u.cli.cl_mgc_refcount));
532 GOTO(out, rc = -EBUSY);
536 * The MGC has no recoverable data in any case.
537 * force shotdown set in umount_begin
539 obd->obd_no_recov = 1;
541 if (obd->u.cli.cl_mgc_mgsexp) {
543 * An error is not fatal, if we are unable to send the
544 * disconnect mgs ping evictor cleans up the export
546 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
548 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
552 * Save the obdname for cleaning the nid uuids, which are
555 len = strlen(obd->obd_name) + 6;
556 OBD_ALLOC(niduuid, len);
558 strcpy(niduuid, obd->obd_name);
559 ptr = niduuid + strlen(niduuid);
562 rc = class_manual_cleanup(obd);
566 /* Clean the nid uuids */
568 GOTO(out, rc = -ENOMEM);
570 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
571 sprintf(ptr, "_%x", i);
572 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
573 niduuid, NULL, NULL, NULL);
575 CERROR("del MDC UUID %s failed: rc = %d\n",
580 OBD_FREE(niduuid, len);
582 /* class_import_put will get rid of the additional connections */
583 mutex_unlock(&mgc_start_lock);
587 /***************** lustre superblock **************/
589 static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
591 struct lustre_sb_info *lsi;
598 OBD_ALLOC_PTR(lsi->lsi_lmd);
604 lsi->lsi_lmd->lmd_exclude_count = 0;
605 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
606 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
607 s2lsi_nocast(sb) = lsi;
608 /* we take 1 extra ref for our setup */
609 atomic_set(&lsi->lsi_mounts, 1);
611 /* Default umount style */
612 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
613 INIT_LIST_HEAD(&lsi->lsi_lwp_list);
614 mutex_init(&lsi->lsi_lwp_mutex);
619 static int lustre_free_lsi(struct super_block *sb)
621 struct lustre_sb_info *lsi = s2lsi(sb);
625 LASSERT(lsi != NULL);
626 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
628 /* someone didn't call server_put_mount. */
629 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
631 if (lsi->lsi_lmd != NULL) {
632 if (lsi->lsi_lmd->lmd_dev != NULL)
633 OBD_FREE(lsi->lsi_lmd->lmd_dev,
634 strlen(lsi->lsi_lmd->lmd_dev) + 1);
635 if (lsi->lsi_lmd->lmd_profile != NULL)
636 OBD_FREE(lsi->lsi_lmd->lmd_profile,
637 strlen(lsi->lsi_lmd->lmd_profile) + 1);
638 if (lsi->lsi_lmd->lmd_fileset != NULL)
639 OBD_FREE(lsi->lsi_lmd->lmd_fileset,
640 strlen(lsi->lsi_lmd->lmd_fileset) + 1);
641 if (lsi->lsi_lmd->lmd_mgssec != NULL)
642 OBD_FREE(lsi->lsi_lmd->lmd_mgssec,
643 strlen(lsi->lsi_lmd->lmd_mgssec) + 1);
644 if (lsi->lsi_lmd->lmd_opts != NULL)
645 OBD_FREE(lsi->lsi_lmd->lmd_opts,
646 strlen(lsi->lsi_lmd->lmd_opts) + 1);
647 if (lsi->lsi_lmd->lmd_exclude_count)
648 OBD_FREE(lsi->lsi_lmd->lmd_exclude,
649 sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
650 lsi->lsi_lmd->lmd_exclude_count);
651 if (lsi->lsi_lmd->lmd_mgs != NULL)
652 OBD_FREE(lsi->lsi_lmd->lmd_mgs,
653 strlen(lsi->lsi_lmd->lmd_mgs) + 1);
654 if (lsi->lsi_lmd->lmd_osd_type != NULL)
655 OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
656 strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
657 if (lsi->lsi_lmd->lmd_params != NULL)
658 OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
659 if (lsi->lsi_lmd->lmd_nidnet != NULL)
660 OBD_FREE(lsi->lsi_lmd->lmd_nidnet,
661 strlen(lsi->lsi_lmd->lmd_nidnet) + 1);
663 OBD_FREE_PTR(lsi->lsi_lmd);
666 LASSERT(lsi->lsi_llsbi == NULL);
668 s2lsi_nocast(sb) = NULL;
674 * The lsi has one reference for every server that is using the disk -
675 * e.g. MDT, MGS, and potentially MGC
677 int lustre_put_lsi(struct super_block *sb)
679 struct lustre_sb_info *lsi = s2lsi(sb);
683 LASSERT(lsi != NULL);
685 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
686 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
687 if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
688 lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
689 lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
690 lsi->lsi_dt_dev = NULL;
691 obd_disconnect(lsi->lsi_osd_exp);
692 /* wait till OSD is gone */
693 obd_zombie_barrier();
702 * The goal of this function is to extract the file system name
703 * from the OBD name. This can come in two flavors. One is
704 * fsname-MDTXXXX or fsname-XXXXXXX were X is a hexadecimal
705 * number. In both cases we should return fsname. If it is
706 * not a valid OBD name it is assumed to be the file system
709 void obdname2fsname(const char *tgt, char *fsname, size_t buflen)
716 * First we have to see if the @tgt has '-' at all. It is
717 * valid for the user to request something like
718 * lctl set_param -P llite.lustre*.xattr_cache=0
720 ptr = strrchr(tgt, '-');
722 /* No '-' means it could end in '*' */
723 ptr = strchr(tgt, '*');
725 /* No '*' either. Assume tgt = fsname */
733 /* tgt format fsname-MDT0000-* */
734 if ((!strncmp(ptr, "-MDT", 4) ||
735 !strncmp(ptr, "-OST", 4)) &&
736 (isxdigit(ptr[4]) && isxdigit(ptr[5]) &&
737 isxdigit(ptr[6]) && isxdigit(ptr[7]))) {
743 * tgt_format fsname-cli'dev'-'uuid' except for the llite case
744 * which are named fsname-'uuid'. Examples:
746 * lustre-clilov-ffff88104db5b800
747 * lustre-ffff88104db5b800 (for llite device)
749 * The length of the OBD uuid can vary on different platforms.
750 * This test if any invalid characters are in string. Allow
751 * wildcards with '*' character.
754 if (!strspn(ptr, "0123456789abcdefABCDEF*")) {
760 * Now that we validated the device name lets extract the
761 * file system name. Most of the names in this class will
762 * have '-cli' in its name which needs to be dropped. If
763 * it doesn't have '-cli' then its a llite device which
764 * ptr already points to the start of the uuid string.
766 tmp = strstr(tgt, "-cli");
773 len = min_t(size_t, len, LUSTRE_MAXFSNAME);
774 snprintf(fsname, buflen, "%.*s", (int)len, tgt);
778 EXPORT_SYMBOL(obdname2fsname);
782 * <FSNAME><SEPARATOR><TYPE><INDEX>
783 * FSNAME is between 1 and 8 characters (inclusive).
784 * Excluded characters are '/' and ':'
785 * SEPARATOR is either ':' or '-'
786 * TYPE: "OST", "MDT", etc.
787 * INDEX: Hex representation of the index
791 * Get the fsname ("lustre") from the server name ("lustre-OST003F").
792 * @param [in] svname server name including type and index
793 * @param [out] fsname Buffer to copy filesystem name prefix into.
794 * Must have at least 'strlen(fsname) + 1' chars.
795 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
798 int server_name2fsname(const char *svname, char *fsname, const char **endptr)
802 dash = svname + strnlen(svname, LUSTRE_MAXFSNAME);
803 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
808 if (fsname != NULL) {
809 strncpy(fsname, svname, dash - svname);
810 fsname[dash - svname] = '\0';
818 EXPORT_SYMBOL(server_name2fsname);
821 * Get service name (svname) from string
823 * if endptr isn't NULL it is set to end of fsname *
825 int server_name2svname(const char *label, char *svname, const char **endptr,
831 /* We use server_name2fsname() just for parsing */
832 rc = server_name2fsname(label, NULL, &dash);
839 if (strlcpy(svname, dash + 1, svsize) >= svsize)
844 EXPORT_SYMBOL(server_name2svname);
847 * check server name is OST.
849 int server_name_is_ost(const char *svname)
854 /* We use server_name2fsname() just for parsing */
855 rc = server_name2fsname(svname, NULL, &dash);
861 if (strncmp(dash, "OST", 3) == 0)
865 EXPORT_SYMBOL(server_name_is_ost);
868 * Get the index from the target name MDTXXXX/OSTXXXX
869 * rc = server type, or rc < 0 on error
871 int target_name2index(const char *tgtname, __u32 *idx, const char **endptr)
873 const char *dash = tgtname;
877 if (strncmp(dash, "MDT", 3) == 0)
878 rc = LDD_F_SV_TYPE_MDT;
879 else if (strncmp(dash, "OST", 3) == 0)
880 rc = LDD_F_SV_TYPE_OST;
886 if (strncmp(dash, "all", 3) == 0) {
889 return rc | LDD_F_SV_ALL;
892 index = simple_strtoul(dash, (char **)endptr, 16);
901 EXPORT_SYMBOL(target_name2index);
904 * Get the index from the OBD name.
905 * rc = server type, or
907 * if endptr isn't NULL it is set to end of name
909 int server_name2index(const char *svname, __u32 *idx, const char **endptr)
914 /* We use server_name2fsname() just for parsing */
915 rc = server_name2fsname(svname, NULL, &dash);
920 rc = target_name2index(dash, idx, endptr);
924 /* Account for -mdc after index that is possible when specifying mdt */
925 if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
926 sizeof(LUSTRE_MDC_NAME)-1) == 0)
927 *endptr += sizeof(LUSTRE_MDC_NAME);
931 EXPORT_SYMBOL(server_name2index);
933 /*************** mount common betweeen server and client ***************/
936 int lustre_common_put_super(struct super_block *sb)
942 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
944 /* Drop a ref to the MGC */
945 rc = lustre_stop_mgc(sb);
946 if (rc && (rc != -ENOENT)) {
948 CERROR("Can't stop MGC: %d\n", rc);
952 * BUSY just means that there's some other OBD that
953 * needs the mgc. Let him clean it up.
955 CDEBUG(D_MOUNT, "MGC still in use\n");
957 /* Drop a ref to the mounted disk */
962 EXPORT_SYMBOL(lustre_common_put_super);
964 static void lmd_print(struct lustre_mount_data *lmd)
968 PRINT_CMD(D_MOUNT, " mount data:\n");
969 if (lmd_is_client(lmd))
970 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
971 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
972 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
975 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
977 if (lmd->lmd_recovery_time_soft)
978 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
979 lmd->lmd_recovery_time_soft);
981 if (lmd->lmd_recovery_time_hard)
982 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
983 lmd->lmd_recovery_time_hard);
985 for (i = 0; i < lmd->lmd_exclude_count; i++) {
986 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
987 lmd->lmd_exclude[i]);
991 /* Is this server on the exclusion list */
992 int lustre_check_exclusion(struct super_block *sb, char *svname)
994 struct lustre_sb_info *lsi = s2lsi(sb);
995 struct lustre_mount_data *lmd = lsi->lsi_lmd;
1001 rc = server_name2index(svname, &index, NULL);
1002 if (rc != LDD_F_SV_TYPE_OST)
1003 /* Only exclude OSTs */
1006 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
1007 index, lmd->lmd_exclude_count, lmd->lmd_dev);
1009 for (i = 0; i < lmd->lmd_exclude_count; i++) {
1010 if (index == lmd->lmd_exclude[i]) {
1011 CWARN("Excluding %s (on exclusion list)\n", svname);
1018 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
1019 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
1021 const char *s1 = ptr, *s2;
1022 __u32 *exclude_list;
1029 * The shortest an ost name can be is 8 chars: -OST0000.
1030 * We don't actually know the fsname at this time, so in fact
1031 * a user could specify any fsname.
1033 devmax = strlen(ptr) / 8 + 1;
1035 /* temp storage until we figure out how many we have */
1036 OBD_ALLOC(exclude_list, sizeof(index) * devmax);
1040 /* we enter this fn pointing at the '=' */
1041 while (*s1 && *s1 != ' ' && *s1 != ',') {
1043 rc = server_name2index(s1, &index, &s2);
1045 CERROR("Can't parse server name '%s': rc = %d\n",
1049 if (rc == LDD_F_SV_TYPE_OST)
1050 exclude_list[lmd->lmd_exclude_count++] = index;
1052 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
1053 (uint)(s2-s1), s1, rc);
1056 * now we are pointing at ':' (next exclude)
1057 * or ',' (end of excludes)
1059 if (lmd->lmd_exclude_count >= devmax)
1062 if (rc >= 0) /* non-err */
1065 if (lmd->lmd_exclude_count) {
1066 /* permanent, freed in lustre_free_lsi */
1067 OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
1068 lmd->lmd_exclude_count);
1069 if (lmd->lmd_exclude) {
1070 memcpy(lmd->lmd_exclude, exclude_list,
1071 sizeof(index) * lmd->lmd_exclude_count);
1074 lmd->lmd_exclude_count = 0;
1077 OBD_FREE(exclude_list, sizeof(index) * devmax);
1081 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
1086 if (lmd->lmd_mgssec != NULL) {
1087 OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
1088 lmd->lmd_mgssec = NULL;
1091 tail = strchr(ptr, ',');
1093 length = strlen(ptr);
1095 length = tail - ptr;
1097 OBD_ALLOC(lmd->lmd_mgssec, length + 1);
1098 if (lmd->lmd_mgssec == NULL)
1101 memcpy(lmd->lmd_mgssec, ptr, length);
1102 lmd->lmd_mgssec[length] = '\0';
1106 static int lmd_parse_network(struct lustre_mount_data *lmd, char *ptr)
1111 if (lmd->lmd_nidnet != NULL) {
1112 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
1113 lmd->lmd_nidnet = NULL;
1116 tail = strchr(ptr, ',');
1118 length = strlen(ptr);
1120 length = tail - ptr;
1122 OBD_ALLOC(lmd->lmd_nidnet, length + 1);
1123 if (lmd->lmd_nidnet == NULL)
1126 memcpy(lmd->lmd_nidnet, ptr, length);
1127 lmd->lmd_nidnet[length] = '\0';
1131 static int lmd_parse_string(char **handle, char *ptr)
1136 if ((handle == NULL) || (ptr == NULL))
1139 if (*handle != NULL) {
1140 OBD_FREE(*handle, strlen(*handle) + 1);
1144 tail = strchr(ptr, ',');
1146 length = strlen(ptr);
1148 length = tail - ptr;
1150 OBD_ALLOC(*handle, length + 1);
1151 if (*handle == NULL)
1154 memcpy(*handle, ptr, length);
1155 (*handle)[length] = '\0';
1160 /* Collect multiple values for mgsnid specifiers */
1161 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
1169 /* Find end of NID-list */
1170 while (class_parse_nid_quiet(tail, &nid, &tail) == 0)
1173 length = tail - *ptr;
1175 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
1179 if (lmd->lmd_mgs != NULL)
1180 oldlen = strlen(lmd->lmd_mgs) + 1;
1182 OBD_ALLOC(mgsnid, oldlen + length + 1);
1186 if (lmd->lmd_mgs != NULL) {
1187 /* Multiple mgsnid= are taken to mean failover locations */
1188 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
1189 mgsnid[oldlen - 1] = ':';
1190 OBD_FREE(lmd->lmd_mgs, oldlen);
1192 memcpy(mgsnid + oldlen, *ptr, length);
1193 mgsnid[oldlen + length] = '\0';
1194 lmd->lmd_mgs = mgsnid;
1201 * Find the first delimiter (comma or colon) from the specified \a buf and
1202 * make \a *endh point to the string starting with the delimiter. The commas
1203 * in expression list [...] will be skipped.
1205 * @buf a delimiter-separated string
1206 * @endh a pointer to a pointer that will point to the string
1207 * starting with the delimiter
1209 * RETURNS true if delimiter is found, false if delimiter is not found
1211 static bool lmd_find_delimiter(char *buf, char **endh)
1220 if (*c == ',' || *c == ':')
1223 pos = strcspn(c, "[:,]");
1227 /* Not a valid mount string */
1229 CWARN("invalid mount string format\n");
1237 /* invalid mount string */
1239 CWARN("invalid mount string format\n");
1254 * Find the first valid string delimited by comma or colon from the specified
1255 * \a buf and parse it to see whether it's a valid NID list. If yes, \a *endh
1256 * will point to the next string starting with the delimiter.
1258 * \param[in] buf a delimiter-separated string
1259 * \param[in] endh a pointer to a pointer that will point to the string
1260 * starting with the delimiter
1262 * \retval 0 if the string is a valid NID list
1263 * \retval 1 if the string is not a valid NID list
1265 static int lmd_parse_nidlist(char *buf, char **endh)
1267 struct list_head nidlist;
1274 while (*buf == ',' || *buf == ':')
1276 if (*buf == ' ' || *buf == '/' || *buf == '\0')
1279 if (!lmd_find_delimiter(buf, &endp))
1280 endp = buf + strlen(buf);
1285 INIT_LIST_HEAD(&nidlist);
1286 if (cfs_parse_nidlist(buf, strlen(buf), &nidlist) <= 0)
1288 cfs_free_nidlist(&nidlist);
1299 * Parse mount line options
1300 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
1301 * dev is passed as device=uml1:/lustre by mount.lustre_tgt
1303 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
1305 char *s1, *s2, *devname = NULL;
1306 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
1313 LCONSOLE_ERROR_MSG(0x162,
1314 "Missing mount data: check /sbin/mount.lustre_tgt is installed.\n");
1318 /* Options should be a string - try to detect old lmd data */
1319 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1320 LCONSOLE_ERROR_MSG(0x163,
1321 "Using an old version of /sbin/mount.lustre. Please install version %s\n",
1322 LUSTRE_VERSION_STRING);
1325 lmd->lmd_magic = LMD_MAGIC;
1327 OBD_ALLOC(lmd->lmd_params, LMD_PARAMS_MAXLEN);
1328 if (lmd->lmd_params == NULL)
1330 lmd->lmd_params[0] = '\0';
1332 /* Set default flags here */
1337 int time_min = OBD_RECOVERY_TIME_MIN;
1340 /* Skip whitespace and extra commas */
1341 while (*s1 == ' ' || *s1 == ',')
1346 * Client options are parsed in ll_options: eg. flock,
1351 * Parse non-ldiskfs options here. Rather than modifying
1352 * ldiskfs, we just zero these out here
1354 if (strncmp(s1, "abort_recov", 11) == 0) {
1355 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
1357 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
1358 lmd->lmd_recovery_time_soft =
1359 max_t(int, simple_strtoul(s1 + 19, NULL, 10),
1362 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
1363 lmd->lmd_recovery_time_hard =
1364 max_t(int, simple_strtoul(s1 + 19, NULL, 10),
1367 } else if (strncmp(s1, "noir", 4) == 0) {
1368 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
1370 } else if (strncmp(s1, "nosvc", 5) == 0) {
1371 lmd->lmd_flags |= LMD_FLG_NOSVC;
1373 } else if (strncmp(s1, "nomgs", 5) == 0) {
1374 lmd->lmd_flags |= LMD_FLG_NOMGS;
1376 } else if (strncmp(s1, "noscrub", 7) == 0) {
1377 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
1379 } else if (strncmp(s1, "skip_lfsck", 10) == 0) {
1380 lmd->lmd_flags |= LMD_FLG_SKIP_LFSCK;
1382 } else if (strncmp(s1, "rdonly_dev", 10) == 0) {
1383 lmd->lmd_flags |= LMD_FLG_DEV_RDONLY;
1385 } else if (strncmp(s1, PARAM_MGSNODE,
1386 sizeof(PARAM_MGSNODE) - 1) == 0) {
1387 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
1389 * Assume the next mount opt is the first
1390 * invalid NID we get to.
1392 rc = lmd_parse_mgs(lmd, &s2);
1397 } else if (strncmp(s1, "writeconf", 9) == 0) {
1398 lmd->lmd_flags |= LMD_FLG_WRITECONF;
1400 } else if (strncmp(s1, "update", 6) == 0) {
1401 lmd->lmd_flags |= LMD_FLG_UPDATE;
1403 } else if (strncmp(s1, "virgin", 6) == 0) {
1404 lmd->lmd_flags |= LMD_FLG_VIRGIN;
1406 } else if (strncmp(s1, "noprimnode", 10) == 0) {
1407 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
1409 } else if (strncmp(s1, "mgssec=", 7) == 0) {
1410 rc = lmd_parse_mgssec(lmd, s1 + 7);
1414 /* ost exclusion list */
1415 } else if (strncmp(s1, "exclude=", 8) == 0) {
1416 rc = lmd_make_exclusion(lmd, s1 + 7);
1420 } else if (strncmp(s1, "mgs", 3) == 0) {
1422 lmd->lmd_flags |= LMD_FLG_MGS;
1424 } else if (strncmp(s1, "svname=", 7) == 0) {
1425 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
1429 } else if (strncmp(s1, "param=", 6) == 0) {
1430 size_t length, params_length;
1433 if (lmd_find_delimiter(s1 + 6, &tail)) {
1434 char *param_str = tail + 1;
1435 int supplementary = 1;
1437 while (lmd_parse_nidlist(param_str,
1441 length = param_str - s1 - supplementary;
1443 length = strlen(s1);
1446 params_length = strlen(lmd->lmd_params);
1447 if (params_length + length + 1 >= LMD_PARAMS_MAXLEN)
1449 strncat(lmd->lmd_params, s1 + 6, length);
1450 lmd->lmd_params[params_length + length] = '\0';
1451 strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
1452 s3 = s1 + 6 + length;
1454 } else if (strncmp(s1, "osd=", 4) == 0) {
1455 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1461 * Linux 2.4 doesn't pass the device, so we stuck it at
1462 * the end of the options.
1464 else if (strncmp(s1, "device=", 7) == 0) {
1467 * terminate options right before device. device
1468 * must be the last one.
1472 } else if (strncmp(s1, "network=", 8) == 0) {
1473 rc = lmd_parse_network(lmd, s1 + 8);
1477 /* check if LNet dynamic peer discovery is activated */
1478 if (LNetGetPeerDiscoveryStatus()) {
1479 CERROR("LNet Dynamic Peer Discovery is enabled "
1480 "on this node. 'network' mount option "
1481 "cannot be taken into account.\n");
1489 s2 = strchr(s3, ',');
1497 memmove(s1, s2, strlen(s2) + 1);
1503 LCONSOLE_ERROR_MSG(0x164,
1504 "Can't find device name (need mount option 'device=...')\n");
1508 s1 = strstr(devname, ":/");
1511 lmd->lmd_flags |= LMD_FLG_CLIENT;
1512 /* Remove leading /s from fsname */
1513 while (*++s1 == '/')
1516 while (*s2 != '/' && *s2 != '\0')
1518 /* Freed in lustre_free_lsi */
1519 OBD_ALLOC(lmd->lmd_profile, s2 - s1 + 8);
1520 if (!lmd->lmd_profile)
1523 strncat(lmd->lmd_profile, s1, s2 - s1);
1524 strncat(lmd->lmd_profile, "-client", 7);
1527 s2 = s1 + strlen(s1) - 1;
1528 /* Remove padding /s from fileset */
1532 OBD_ALLOC(lmd->lmd_fileset, s2 - s1 + 2);
1533 if (lmd->lmd_fileset == NULL) {
1534 OBD_FREE(lmd->lmd_profile,
1535 strlen(lmd->lmd_profile) + 1);
1538 strncat(lmd->lmd_fileset, s1, s2 - s1 + 1);
1542 if (lmd->lmd_nidnet != NULL) {
1543 /* 'network=' mount option forbidden for server */
1544 OBD_FREE(lmd->lmd_nidnet, strlen(lmd->lmd_nidnet) + 1);
1545 lmd->lmd_nidnet = NULL;
1548 "%s: option 'network=' not allowed for Lustre servers: rc = %d\n",
1554 /* Freed in lustre_free_lsi */
1555 OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
1558 strncpy(lmd->lmd_dev, devname, strlen(devname)+1);
1560 /* Save mount options */
1561 s1 = options + strlen(options) - 1;
1562 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1564 while (*options && (*options == ',' || *options == ' '))
1566 if (*options != 0) {
1567 /* Freed in lustre_free_lsi */
1568 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
1571 strncpy(lmd->lmd_opts, options, strlen(options)+1);
1575 lmd->lmd_magic = LMD_MAGIC;
1580 CERROR("Bad mount options %s\n", options);
1584 struct lustre_mount_data2 {
1586 struct vfsmount *lmd2_mnt;
1590 * This is the entry point for the mount call into Lustre.
1591 * This is called when a server or client is mounted,
1592 * and this is where we start setting things up.
1593 * @param data Mount options (e.g. -o flock,abort_recov)
1595 static int lustre_fill_super(struct super_block *sb, void *data, int silent)
1597 struct lustre_mount_data *lmd;
1598 struct lustre_mount_data2 *lmd2 = data;
1599 struct lustre_sb_info *lsi;
1604 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
1606 lsi = lustre_init_lsi(sb);
1612 * Disable lockdep during mount, because mount locking patterns are
1618 * LU-639: the OBD cleanup of last mount may not finish yet, wait here.
1620 obd_zombie_barrier();
1622 /* Figure out the lmd from the mount options */
1623 if (lmd_parse((char *)(lmd2->lmd2_data), lmd)) {
1625 GOTO(out, rc = -EINVAL);
1628 if (lmd_is_client(lmd)) {
1629 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1630 if (client_fill_super == NULL)
1631 request_module("lustre");
1632 if (client_fill_super == NULL) {
1633 LCONSOLE_ERROR_MSG(0x165,
1634 "Nothing registered for client mount! Is the 'lustre' module loaded?\n");
1638 rc = lustre_start_mgc(sb);
1640 lustre_common_put_super(sb);
1643 /* Connect and start */
1644 /* (should always be ll_fill_super) */
1645 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1646 /* c_f_s will call lustre_common_put_super on failure */
1649 #ifdef HAVE_SERVER_SUPPORT
1650 CDEBUG(D_MOUNT, "Mounting server from %s\n", lmd->lmd_dev);
1651 rc = server_fill_super(sb);
1653 * s_f_s calls lustre_start_mgc after the mount because we need
1654 * the MGS NIDs which are stored on disk. Plus, we may
1655 * need to start the MGS first.
1657 /* s_f_s will call server_put_super on failure */
1659 CERROR("client-side-only module, cannot handle server mount\n");
1665 * If error happens in fill_super() call, @lsi will be killed there.
1666 * This is why we do not put it here.
1671 CERROR("Unable to mount %s (%d)\n",
1672 s2lsi(sb) ? lmd->lmd_dev : "", rc);
1674 CDEBUG(D_SUPER, "Mount %s complete\n",
1683 * We can't call ll_fill_super by name because it lives in a module that
1684 * must be loaded after this one.
1686 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1687 struct vfsmount *mnt))
1689 client_fill_super = cfs;
1691 EXPORT_SYMBOL(lustre_register_client_fill_super);
1693 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1695 kill_super_cb = cfs;
1697 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1699 /***************** FS registration ******************/
1700 #ifdef HAVE_FSTYPE_MOUNT
1701 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1702 const char *devname, void *data)
1704 struct lustre_mount_data2 lmd2 = {
1708 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1711 static int lustre_get_sb(struct file_system_type *fs_type, int flags,
1712 const char *devname, void *data, struct vfsmount *mnt)
1714 struct lustre_mount_data2 lmd2 = {
1719 return get_sb_nodev(fs_type, flags, &lmd2, lustre_fill_super, mnt);
1723 static void lustre_kill_super(struct super_block *sb)
1725 struct lustre_sb_info *lsi = s2lsi(sb);
1727 if (kill_super_cb && lsi && !IS_SERVER(lsi))
1728 (*kill_super_cb)(sb);
1730 kill_anon_super(sb);
1733 #ifdef HAVE_SERVER_SUPPORT
1734 /* Register the "lustre_tgt" fs type.
1736 * Right now this isn't any different than the normal "lustre" filesystem
1737 * type, but it is added so that there is some compatibility to allow
1738 * changing documentation and scripts to start using the "lustre_tgt" type
1739 * at mount time. That will simplify test interop, and in case of upgrades
1740 * that change to the new type and then need to roll back for some reason.
1742 * The long-term goal is to disentangle the client and server mount code.
1744 static struct file_system_type lustre_fs_type_tgt = {
1745 .owner = THIS_MODULE,
1746 .name = "lustre_tgt",
1747 #ifdef HAVE_FSTYPE_MOUNT
1748 .mount = lustre_mount,
1750 .get_sb = lustre_get_sb,
1752 .kill_sb = lustre_kill_super,
1753 .fs_flags = FS_REQUIRES_DEV | FS_RENAME_DOES_D_MOVE,
1755 MODULE_ALIAS_FS("lustre_tgt");
1757 #define register_filesystem_tgt(fstype) \
1761 _rc = register_filesystem(fstype); \
1762 if (_rc && _rc != -EBUSY) { \
1763 /* Don't fail if server code also registers "lustre_tgt" */ \
1764 CERROR("obdclass: register fstype '%s' failed: rc = %d\n", \
1765 (fstype)->name, _rc); \
1769 #define unregister_filesystem_tgt(fstype) unregister_filesystem(fstype)
1771 #define register_filesystem_tgt(fstype) do {} while (0)
1772 #define unregister_filesystem_tgt(fstype) do {} while (0)
1775 /* Register the "lustre" fs type */
1776 static struct file_system_type lustre_fs_type = {
1777 .owner = THIS_MODULE,
1779 #ifdef HAVE_FSTYPE_MOUNT
1780 .mount = lustre_mount,
1782 .get_sb = lustre_get_sb,
1784 .kill_sb = lustre_kill_super,
1785 .fs_flags = FS_RENAME_DOES_D_MOVE,
1787 MODULE_ALIAS_FS("lustre");
1789 int lustre_register_fs(void)
1791 register_filesystem_tgt(&lustre_fs_type_tgt);
1793 return register_filesystem(&lustre_fs_type);
1796 int lustre_unregister_fs(void)
1798 unregister_filesystem_tgt(&lustre_fs_type_tgt);
1800 return unregister_filesystem(&lustre_fs_type);