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, Whamcloud, Inc.
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/server 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
47 #define PRINT_MASK D_SUPER|D_CONFIG
51 #include <lustre_fsfilt.h>
52 #include <obd_class.h>
53 #include <lustre/lustre_user.h>
54 #include <linux/version.h>
55 #include <lustre_log.h>
56 #include <lustre_disk.h>
57 #include <lustre_param.h>
58 #ifdef HAVE_KERNEL_LOCKED
59 #include <linux/smp_lock.h>
62 static int (*client_fill_super)(struct super_block *sb,
63 struct vfsmount *mnt) = NULL;
64 static void (*kill_super_cb)(struct super_block *sb) = NULL;
66 /*********** mount lookup *********/
68 DEFINE_MUTEX(lustre_mount_info_lock);
69 static CFS_LIST_HEAD(server_mount_info_list);
71 static struct lustre_mount_info *server_find_mount(const char *name)
74 struct lustre_mount_info *lmi;
77 cfs_list_for_each(tmp, &server_mount_info_list) {
78 lmi = cfs_list_entry(tmp, struct lustre_mount_info,
80 if (strcmp(name, lmi->lmi_name) == 0)
86 /* we must register an obd for a mount before we call the setup routine.
87 *_setup will call lustre_get_mount to get the mnt struct
88 by obd_name, since we can't pass the pointer to setup. */
89 static int server_register_mount(const char *name, struct super_block *sb,
92 struct lustre_mount_info *lmi;
98 OBD_ALLOC(lmi, sizeof(*lmi));
101 OBD_ALLOC(name_cp, strlen(name) + 1);
103 OBD_FREE(lmi, sizeof(*lmi));
106 strcpy(name_cp, name);
108 mutex_lock(&lustre_mount_info_lock);
110 if (server_find_mount(name)) {
111 mutex_unlock(&lustre_mount_info_lock);
112 OBD_FREE(lmi, sizeof(*lmi));
113 OBD_FREE(name_cp, strlen(name) + 1);
114 CERROR("Already registered %s\n", name);
117 lmi->lmi_name = name_cp;
120 cfs_list_add(&lmi->lmi_list_chain, &server_mount_info_list);
122 mutex_unlock(&lustre_mount_info_lock);
124 CDEBUG(D_MOUNT, "reg_mnt %p from %s\n", lmi->lmi_mnt, name);
129 /* when an obd no longer needs a mount */
130 static int server_deregister_mount(const char *name)
132 struct lustre_mount_info *lmi;
135 mutex_lock(&lustre_mount_info_lock);
136 lmi = server_find_mount(name);
138 mutex_unlock(&lustre_mount_info_lock);
139 CERROR("%s not registered\n", name);
143 CDEBUG(D_MOUNT, "dereg_mnt %p from %s\n", lmi->lmi_mnt, name);
145 OBD_FREE(lmi->lmi_name, strlen(lmi->lmi_name) + 1);
146 cfs_list_del(&lmi->lmi_list_chain);
147 OBD_FREE(lmi, sizeof(*lmi));
148 mutex_unlock(&lustre_mount_info_lock);
153 /* obd's look up a registered mount using their obdname. This is just
154 for initial obd setup to find the mount struct. It should not be
155 called every time you want to mntget. */
156 struct lustre_mount_info *server_get_mount(const char *name)
158 struct lustre_mount_info *lmi;
159 struct lustre_sb_info *lsi;
162 mutex_lock(&lustre_mount_info_lock);
163 lmi = server_find_mount(name);
164 mutex_unlock(&lustre_mount_info_lock);
166 CERROR("Can't find mount for %s\n", name);
169 lsi = s2lsi(lmi->lmi_sb);
171 cfs_atomic_inc(&lsi->lsi_mounts);
173 CDEBUG(D_MOUNT, "get_mnt %p from %s, refs=%d\n", lmi->lmi_mnt,
174 name, cfs_atomic_read(&lsi->lsi_mounts));
178 EXPORT_SYMBOL(server_get_mount);
181 * Used by mdt to get mount_info from obdname.
182 * There are no blocking when using the mount_info.
183 * Do not use server_get_mount for this purpose.
185 struct lustre_mount_info *server_get_mount_2(const char *name)
187 struct lustre_mount_info *lmi;
190 mutex_lock(&lustre_mount_info_lock);
191 lmi = server_find_mount(name);
192 mutex_unlock(&lustre_mount_info_lock);
194 CERROR("Can't find mount for %s\n", name);
198 EXPORT_SYMBOL(server_get_mount_2);
200 static int lustre_put_lsi(struct super_block *sb);
202 /* to be called from obd_cleanup methods */
203 int server_put_mount(const char *name, struct vfsmount *mnt)
205 struct lustre_mount_info *lmi;
206 struct lustre_sb_info *lsi;
209 mutex_lock(&lustre_mount_info_lock);
210 lmi = server_find_mount(name);
211 mutex_unlock(&lustre_mount_info_lock);
213 CERROR("Can't find mount for %s\n", name);
216 lsi = s2lsi(lmi->lmi_sb);
218 CDEBUG(D_MOUNT, "put_mnt %p from %s, refs=%d\n",
219 lmi->lmi_mnt, name, cfs_atomic_read(&lsi->lsi_mounts));
221 if (lustre_put_lsi(lmi->lmi_sb))
222 CDEBUG(D_MOUNT, "Last put of mnt %p from %s\n",
225 /* this obd should never need the mount again */
226 server_deregister_mount(name);
230 EXPORT_SYMBOL(server_put_mount);
232 /* Corresponding to server_get_mount_2 */
233 int server_put_mount_2(const char *name, struct vfsmount *mnt)
238 EXPORT_SYMBOL(server_put_mount_2);
240 /**************** config llog ********************/
242 /** Get a config log from the MGS and process it.
243 * This func is called for both clients and servers.
244 * Continue to process new statements appended to the logs
245 * (whenever the config lock is revoked) until lustre_end_log
247 * @param sb The superblock is used by the MGC to write to the local copy of
249 * @param logname The name of the llog to replicate from the MGS
250 * @param cfg Since the same mgc may be used to follow multiple config logs
251 * (e.g. ost1, ost2, client), the config_llog_instance keeps the state for
252 * this log, and is added to the mgc's list of logs to follow.
254 int lustre_process_log(struct super_block *sb, char *logname,
255 struct config_llog_instance *cfg)
257 struct lustre_cfg *lcfg;
258 struct lustre_cfg_bufs *bufs;
259 struct lustre_sb_info *lsi = s2lsi(sb);
260 struct obd_device *mgc = lsi->lsi_mgc;
271 /* mgc_process_config */
272 lustre_cfg_bufs_reset(bufs, mgc->obd_name);
273 lustre_cfg_bufs_set_string(bufs, 1, logname);
274 lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
275 lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
276 lcfg = lustre_cfg_new(LCFG_LOG_START, bufs);
277 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
278 lustre_cfg_free(lcfg);
283 LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s'"
284 "failed from the MGS (%d). Make sure this "
285 "client and the MGS are running compatible "
286 "versions of Lustre.\n",
287 mgc->obd_name, logname, rc);
290 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' "
291 "failed (%d). This may be the result of "
292 "communication errors between this node and "
293 "the MGS, a bad configuration, or other "
294 "errors. See the syslog for more "
295 "information.\n", mgc->obd_name, logname,
298 /* class_obd_list(); */
301 EXPORT_SYMBOL(lustre_process_log);
303 /* Stop watching this config log for updates */
304 int lustre_end_log(struct super_block *sb, char *logname,
305 struct config_llog_instance *cfg)
307 struct lustre_cfg *lcfg;
308 struct lustre_cfg_bufs bufs;
309 struct lustre_sb_info *lsi = s2lsi(sb);
310 struct obd_device *mgc = lsi->lsi_mgc;
317 /* mgc_process_config */
318 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
319 lustre_cfg_bufs_set_string(&bufs, 1, logname);
321 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
322 lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
323 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
324 lustre_cfg_free(lcfg);
327 EXPORT_SYMBOL(lustre_end_log);
329 /**************** obd start *******************/
331 /** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
332 * lctl (and do for echo cli/srv.
334 int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
335 char *s1, char *s2, char *s3, char *s4)
337 struct lustre_cfg_bufs bufs;
338 struct lustre_cfg * lcfg = NULL;
341 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
342 cmd, s1, s2, s3, s4);
344 lustre_cfg_bufs_reset(&bufs, cfgname);
346 lustre_cfg_bufs_set_string(&bufs, 1, s1);
348 lustre_cfg_bufs_set_string(&bufs, 2, s2);
350 lustre_cfg_bufs_set_string(&bufs, 3, s3);
352 lustre_cfg_bufs_set_string(&bufs, 4, s4);
354 lcfg = lustre_cfg_new(cmd, &bufs);
355 lcfg->lcfg_nid = nid;
356 rc = class_process_config(lcfg);
357 lustre_cfg_free(lcfg);
360 EXPORT_SYMBOL(do_lcfg);
362 /** Call class_attach and class_setup. These methods in turn call
363 * obd type-specific methods.
365 static int lustre_start_simple(char *obdname, char *type, char *uuid,
366 char *s1, char *s2, char *s3, char *s4)
369 CDEBUG(D_MOUNT, "Starting obd %s (typ=%s)\n", obdname, type);
371 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, 0, 0);
373 CERROR("%s attach error %d\n", obdname, rc);
376 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
378 CERROR("%s setup error %d\n", obdname, rc);
379 do_lcfg(obdname, 0, LCFG_DETACH, 0, 0, 0, 0);
384 /* Set up a MGS to serve startup logs */
385 static int server_start_mgs(struct super_block *sb)
387 struct lustre_sb_info *lsi = s2lsi(sb);
388 struct vfsmount *mnt = lsi->lsi_srv_mnt;
389 struct lustre_mount_info *lmi;
393 /* It is impossible to have more than 1 MGS per node, since
394 MGC wouldn't know which to connect to */
395 lmi = server_find_mount(LUSTRE_MGS_OBDNAME);
397 lsi = s2lsi(lmi->lmi_sb);
398 LCONSOLE_ERROR_MSG(0x15d, "The MGS service was already started"
403 CDEBUG(D_CONFIG, "Start MGS service %s\n", LUSTRE_MGS_OBDNAME);
405 rc = server_register_mount(LUSTRE_MGS_OBDNAME, sb, mnt);
408 rc = lustre_start_simple(LUSTRE_MGS_OBDNAME, LUSTRE_MGS_NAME,
409 LUSTRE_MGS_OBDNAME, 0, 0,
410 lsi->lsi_osd_obdname, 0);
411 /* Do NOT call server_deregister_mount() here. This leads to
412 * inability cleanup cleanly and free lsi and other stuff when
413 * mgs calls server_put_mount() in error handling case. -umka */
417 LCONSOLE_ERROR_MSG(0x15e, "Failed to start MGS '%s' (%d). "
418 "Is the 'mgs' module loaded?\n",
419 LUSTRE_MGS_OBDNAME, rc);
423 static int server_stop_mgs(struct super_block *sb)
425 struct obd_device *obd;
429 CDEBUG(D_MOUNT, "Stop MGS service %s\n", LUSTRE_MGS_OBDNAME);
431 /* There better be only one MGS */
432 obd = class_name2obd(LUSTRE_MGS_OBDNAME);
434 CDEBUG(D_CONFIG, "mgs %s not running\n", LUSTRE_MGS_OBDNAME);
438 /* The MGS should always stop when we say so */
440 rc = class_manual_cleanup(obd);
444 DEFINE_MUTEX(mgc_start_lock);
446 /** Set up a mgc obd to process startup logs
448 * \param sb [in] super block of the mgc obd
450 * \retval 0 success, otherwise error code
452 static int lustre_start_mgc(struct super_block *sb)
454 struct obd_connect_data *data = NULL;
455 struct lustre_sb_info *lsi = s2lsi(sb);
456 struct obd_device *obd;
457 struct obd_export *exp;
458 struct obd_uuid *uuid;
461 char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
464 int rc = 0, i = 0, j, len;
467 LASSERT(lsi->lsi_lmd);
469 /* Find the first non-lo MGS nid for our MGC name */
470 if (IS_SERVER(lsi)) {
471 /* mount -o mgsnode=nid */
472 ptr = lsi->lsi_lmd->lmd_mgs;
473 if (lsi->lsi_lmd->lmd_mgs &&
474 (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) {
476 } else if (IS_MGS(lsi)) {
477 lnet_process_id_t id;
478 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
479 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
486 } else { /* client */
487 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
488 ptr = lsi->lsi_lmd->lmd_dev;
489 if (class_parse_nid(ptr, &nid, &ptr) == 0)
493 CERROR("No valid MGS nids found.\n");
497 mutex_lock(&mgc_start_lock);
499 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
500 OBD_ALLOC(mgcname, len);
501 OBD_ALLOC(niduuid, len + 2);
502 if (!mgcname || !niduuid)
503 GOTO(out_free, rc = -ENOMEM);
504 sprintf(mgcname, "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
506 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
510 GOTO(out_free, rc = -ENOMEM);
512 obd = class_name2obd(mgcname);
513 if (obd && !obd->obd_stopping) {
514 rc = obd_set_info_async(NULL, obd->obd_self_export,
515 strlen(KEY_MGSSEC), KEY_MGSSEC,
516 strlen(mgssec), mgssec, NULL);
520 /* Re-using an existing MGC */
521 cfs_atomic_inc(&obd->u.cli.cl_mgc_refcount);
523 /* IR compatibility check, only for clients */
524 if (lmd_is_client(lsi->lsi_lmd)) {
526 int vallen = sizeof(*data);
527 __u32 *flags = &lsi->lsi_lmd->lmd_flags;
529 rc = obd_get_info(NULL, obd->obd_self_export,
530 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
531 &vallen, data, NULL);
533 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
534 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
535 /* LMD_FLG_NOIR is for test purpose only */
537 "Trying to mount a client with IR setting "
538 "not compatible with current mgc. "
539 "Force to use current mgc setting that is "
541 has_ir ? "enabled" : "disabled");
543 *flags &= ~LMD_FLG_NOIR;
545 *flags |= LMD_FLG_NOIR;
550 /* If we are restarting the MGS, don't try to keep the MGC's
551 old connection, or registration will fail. */
553 CDEBUG(D_MOUNT, "New MGS with live MGC\n");
557 /* Try all connections, but only once (again).
558 We don't want to block another target from starting
559 (using its local copy of the log), but we do want to connect
560 if at all possible. */
562 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,recov_bk);
563 rc = obd_set_info_async(NULL, obd->obd_self_export,
564 sizeof(KEY_INIT_RECOV_BACKUP),
565 KEY_INIT_RECOV_BACKUP,
566 sizeof(recov_bk), &recov_bk, NULL);
570 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
572 /* Add the primary nids for the MGS */
574 sprintf(niduuid, "%s_%x", mgcname, i);
575 if (IS_SERVER(lsi)) {
576 ptr = lsi->lsi_lmd->lmd_mgs;
578 /* Use local nids (including LO) */
579 lnet_process_id_t id;
580 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
581 rc = do_lcfg(mgcname, id.nid,
582 LCFG_ADD_UUID, niduuid, 0,0,0);
585 /* Use mgsnode= nids */
586 /* mount -o mgsnode=nid */
587 if (lsi->lsi_lmd->lmd_mgs) {
588 ptr = lsi->lsi_lmd->lmd_mgs;
589 } else if (class_find_param(ptr, PARAM_MGSNODE,
591 CERROR("No MGS nids given.\n");
592 GOTO(out_free, rc = -EINVAL);
594 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
595 rc = do_lcfg(mgcname, nid,
596 LCFG_ADD_UUID, niduuid, 0,0,0);
600 } else { /* client */
601 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
602 ptr = lsi->lsi_lmd->lmd_dev;
603 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
604 rc = do_lcfg(mgcname, nid,
605 LCFG_ADD_UUID, niduuid, 0,0,0);
607 /* Stop at the first failover nid */
613 CERROR("No valid MGS nids found.\n");
614 GOTO(out_free, rc = -EINVAL);
616 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
618 /* Random uuid for MGC allows easier reconnects */
620 ll_generate_random_uuid(uuidc);
621 class_uuid_unparse(uuidc, uuid);
624 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
625 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
631 /* Add any failover MGS nids */
633 while (ptr && ((*ptr == ':' ||
634 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
635 /* New failover node */
636 sprintf(niduuid, "%s_%x", mgcname, i);
638 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
640 rc = do_lcfg(mgcname, nid,
641 LCFG_ADD_UUID, niduuid, 0,0,0);
646 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
654 lsi->lsi_lmd->lmd_mgs_failnodes = i;
656 obd = class_name2obd(mgcname);
658 CERROR("Can't find mgcobd %s\n", mgcname);
659 GOTO(out_free, rc = -ENOTCONN);
662 rc = obd_set_info_async(NULL, obd->obd_self_export,
663 strlen(KEY_MGSSEC), KEY_MGSSEC,
664 strlen(mgssec), mgssec, NULL);
668 /* Keep a refcount of servers/clients who started with "mount",
669 so we know when we can get rid of the mgc. */
670 cfs_atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
672 /* Try all connections, but only once. */
674 rc = obd_set_info_async(NULL, obd->obd_self_export,
675 sizeof(KEY_INIT_RECOV_BACKUP),
676 KEY_INIT_RECOV_BACKUP,
677 sizeof(recov_bk), &recov_bk, NULL);
680 CWARN("can't set %s %d\n", KEY_INIT_RECOV_BACKUP, rc);
682 /* We connect to the MGS at setup, and don't disconnect until cleanup */
683 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
684 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
685 OBD_CONNECT_LVB_TYPE;
687 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
688 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
690 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
693 if (lmd_is_client(lsi->lsi_lmd) &&
694 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
695 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
696 data->ocd_version = LUSTRE_VERSION_CODE;
697 rc = obd_connect(NULL, &exp, obd, &(obd->obd_uuid), data, NULL);
699 CERROR("connect failed %d\n", rc);
703 obd->u.cli.cl_mgc_mgsexp = exp;
706 /* Keep the mgc info in the sb. Note that many lsi's can point
710 mutex_unlock(&mgc_start_lock);
715 OBD_FREE(mgcname, len);
717 OBD_FREE(niduuid, len + 2);
721 static int lustre_stop_mgc(struct super_block *sb)
723 struct lustre_sb_info *lsi = s2lsi(sb);
724 struct obd_device *obd;
725 char *niduuid = 0, *ptr = 0;
726 int i, rc = 0, len = 0;
736 mutex_lock(&mgc_start_lock);
737 LASSERT(cfs_atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
738 if (!cfs_atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
739 /* This is not fatal, every client that stops
740 will call in here. */
741 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
742 cfs_atomic_read(&obd->u.cli.cl_mgc_refcount));
743 GOTO(out, rc = -EBUSY);
746 /* The MGC has no recoverable data in any case.
747 * force shotdown set in umount_begin */
748 obd->obd_no_recov = 1;
750 if (obd->u.cli.cl_mgc_mgsexp) {
751 /* An error is not fatal, if we are unable to send the
752 disconnect mgs ping evictor cleans up the export */
753 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
755 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
758 /* Save the obdname for cleaning the nid uuids, which are
760 len = strlen(obd->obd_name) + 6;
761 OBD_ALLOC(niduuid, len);
763 strcpy(niduuid, obd->obd_name);
764 ptr = niduuid + strlen(niduuid);
767 rc = class_manual_cleanup(obd);
771 /* Clean the nid uuids */
773 GOTO(out, rc = -ENOMEM);
775 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
776 sprintf(ptr, "_%x", i);
777 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
780 CERROR("del MDC UUID %s failed: rc = %d\n",
785 OBD_FREE(niduuid, len);
787 /* class_import_put will get rid of the additional connections */
788 mutex_unlock(&mgc_start_lock);
792 /* Since there's only one mgc per node, we have to change it's fs to get
793 access to the right disk. */
794 static int server_mgc_set_fs(struct obd_device *mgc, struct super_block *sb)
796 struct lustre_sb_info *lsi = s2lsi(sb);
800 CDEBUG(D_MOUNT, "Set mgc disk for %s\n", lsi->lsi_lmd->lmd_dev);
802 /* cl_mgc_sem in mgc insures we sleep if the mgc_fs is busy */
803 rc = obd_set_info_async(NULL, mgc->obd_self_export,
804 sizeof(KEY_SET_FS), KEY_SET_FS,
805 sizeof(*sb), sb, NULL);
807 CERROR("can't set_fs %d\n", rc);
813 static int server_mgc_clear_fs(struct obd_device *mgc)
818 CDEBUG(D_MOUNT, "Unassign mgc disk\n");
820 rc = obd_set_info_async(NULL, mgc->obd_self_export,
821 sizeof(KEY_CLEAR_FS), KEY_CLEAR_FS,
826 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
827 * @param [in] svname server name including type and index
828 * @param [out] fsname Buffer to copy filesystem name prefix into.
829 * Must have at least 'strlen(fsname) + 1' chars.
830 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
833 int server_name2fsname(char *svname, char *fsname, char **endptr)
835 char *dash = strrchr(svname, '-');
837 dash = strrchr(svname, ':');
842 /* interpret <fsname>-MDTXXXXX-mdc as mdt, the better way is to pass
843 * in the fsname, then determine the server index */
844 if (!strcmp(LUSTRE_MDC_NAME, dash + 1)) {
846 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
852 if (fsname != NULL) {
853 strncpy(fsname, svname, dash - svname);
854 fsname[dash - svname] = '\0';
862 EXPORT_SYMBOL(server_name2fsname);
864 static int is_mdc_device(char *devname)
867 ptr = strrchr(devname, '-');
868 if (ptr != NULL && strcmp(ptr, "-mdc") == 0)
873 static int inline tgt_is_mdt0(char *tgtname)
878 type = server_name2index(tgtname, &idx, NULL);
879 if (type != LDD_F_SV_TYPE_MDT)
882 return (idx == 0) ? 1 :0;
885 static int inline is_mdc_for_mdt0(char *devname)
889 if (!is_mdc_device(devname))
892 ptr = strrchr(devname, '-');
897 if (tgt_is_mdt0(devname)) {
906 * Convert OST/MDT name(fsname-OSTxxxx) to an osp name
907 * (fsname-MDT0000-osp-OSTxxxx), which will be used to
908 * communicate with MDT0 for this target.
910 int tgt_name2ospname(char *svname, char *ospname)
917 OBD_ALLOC(fsname, MTI_NAME_MAXLEN);
921 rc = server_name2fsname(svname, fsname, &tgt);
923 CERROR("%s change fsname error: rc %d\n", svname, rc);
927 if (*tgt != '-' && *tgt != ':') {
928 CERROR("%s wrong svname name!\n", svname);
929 GOTO(cleanup, rc = -EINVAL);
933 if (strncmp(tgt, "OST", 3) != 0 && strncmp(tgt, "MDT", 3) != 0) {
934 CERROR("%s is not an OST or MDT target!\n", svname);
935 GOTO(cleanup, rc = -EINVAL);
937 sprintf(ospname, "%s-MDT0000-%s-%s", fsname, LUSTRE_OSP_NAME, tgt);
940 OBD_FREE(fsname, MTI_NAME_MAXLEN);
943 EXPORT_SYMBOL(tgt_name2ospname);
945 static CFS_LIST_HEAD(osp_register_list);
946 DEFINE_MUTEX(osp_register_list_lock);
948 int lustre_register_osp_item(char *ospname, struct obd_export **exp,
949 register_osp_cb cb_func, void *cb_data)
951 struct obd_device *osp;
952 struct osp_register_item *ori;
955 LASSERTF(strlen(ospname) < MTI_NAME_MAXLEN, "ospname is too long %s\n",
957 LASSERT(exp != NULL && *exp == NULL);
963 mutex_lock(&osp_register_list_lock);
965 osp = class_name2obd(ospname);
966 if (osp != NULL && osp->obd_set_up == 1) {
967 struct obd_uuid *uuid;
971 mutex_unlock(&osp_register_list_lock);
974 memcpy(uuid->uuid, ospname, strlen(ospname));
975 *exp = cfs_hash_lookup(osp->obd_uuid_hash, uuid);
979 memcpy(ori->ori_name, ospname, strlen(ospname));
981 ori->ori_cb_func = cb_func;
982 ori->ori_cb_data = cb_data;
983 CFS_INIT_LIST_HEAD(&ori->ori_list);
984 cfs_list_add(&ori->ori_list, &osp_register_list);
986 if (*exp != NULL && cb_func != NULL)
989 mutex_unlock(&osp_register_list_lock);
992 EXPORT_SYMBOL(lustre_register_osp_item);
994 void lustre_deregister_osp_item(struct obd_export **exp)
996 struct osp_register_item *ori, *tmp;
998 mutex_lock(&osp_register_list_lock);
999 cfs_list_for_each_entry_safe(ori, tmp, &osp_register_list, ori_list) {
1000 if (exp == ori->ori_exp) {
1002 class_export_put(*exp);
1003 cfs_list_del(&ori->ori_list);
1008 mutex_unlock(&osp_register_list_lock);
1010 EXPORT_SYMBOL(lustre_deregister_osp_item);
1012 static void lustre_notify_osp_list(struct obd_export *exp)
1014 struct osp_register_item *ori, *tmp;
1015 LASSERT(exp != NULL);
1017 mutex_lock(&osp_register_list_lock);
1018 cfs_list_for_each_entry_safe(ori, tmp, &osp_register_list, ori_list) {
1019 if (strcmp(exp->exp_obd->obd_name, ori->ori_name))
1021 if (*ori->ori_exp != NULL)
1023 *ori->ori_exp = class_export_get(exp);
1024 if (ori->ori_cb_func != NULL)
1025 ori->ori_cb_func(ori->ori_cb_data);
1027 mutex_unlock(&osp_register_list_lock);
1030 static int lustre_osp_connect(struct obd_device *osp)
1033 struct lu_context session_ctx;
1034 struct obd_export *exp;
1035 struct obd_uuid *uuid = NULL;
1036 struct obd_connect_data *data = NULL;
1040 /* log has been fully processed, let clients connect */
1041 rc = lu_env_init(&env, osp->obd_lu_dev->ld_type->ldt_ctx_tags);
1045 lu_context_init(&session_ctx, LCT_SESSION);
1046 session_ctx.lc_thread = NULL;
1047 lu_context_enter(&session_ctx);
1048 env.le_ses = &session_ctx;
1050 OBD_ALLOC_PTR(data);
1052 GOTO(out, rc = -ENOMEM);
1054 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_INDEX;
1055 data->ocd_version = LUSTRE_VERSION_CODE;
1056 data->ocd_ibits_known = MDS_INODELOCK_UPDATE;
1057 data->ocd_connect_flags |= OBD_CONNECT_ACL | OBD_CONNECT_IBITS |
1058 OBD_CONNECT_MDS_MDS | OBD_CONNECT_FID |
1059 OBD_CONNECT_AT | OBD_CONNECT_FULL20 |
1060 OBD_CONNECT_LVB_TYPE |
1061 OBD_CONNECT_LIGHTWEIGHT;
1062 OBD_ALLOC_PTR(uuid);
1064 GOTO(out, rc = -ENOMEM);
1066 if (strlen(osp->obd_name) > sizeof(uuid->uuid)) {
1067 CERROR("%s: Too long osp name %s, max_size is %d\n",
1068 osp->obd_name, osp->obd_name, (int)sizeof(uuid->uuid));
1069 GOTO(out, rc = -EINVAL);
1071 /* Use osp name as the uuid, so we find the export by
1073 memcpy(uuid->uuid, osp->obd_name, strlen(osp->obd_name));
1074 rc = obd_connect(&env, &exp, osp, uuid, data, NULL);
1076 CERROR("%s: connect failed: rc = %d\n", osp->obd_name, rc);
1078 lustre_notify_osp_list(exp);
1087 lu_context_exit(&session_ctx);
1088 lu_context_fini(&session_ctx);
1094 * osp-on-ost is used by slaves (Non-MDT0 targets) to manage the connection
1097 * The OSTs will communicate with MDT0 by the connection established by the
1098 * osp-on-ost to get quota and fid sequence.
1101 static int lustre_osp_setup(struct lustre_cfg *lcfg, struct lustre_sb_info *lsi)
1103 struct obd_connect_data *data = NULL;
1104 struct obd_device *obd;
1105 char *ospname = NULL;
1106 char *ospuuid = NULL;
1110 rc = class_add_uuid(lustre_cfg_string(lcfg, 1),
1113 CERROR("%s: Can't add uuid: rc =%d\n", lsi->lsi_svname, rc);
1117 OBD_ALLOC(ospname, MTI_NAME_MAXLEN);
1118 if (ospname == NULL)
1119 GOTO(out, rc = -ENOMEM);
1121 rc = tgt_name2ospname(lsi->lsi_svname, ospname);
1123 CERROR("%s change ospname error: rc %d\n",
1124 lsi->lsi_svname, rc);
1128 OBD_ALLOC(ospuuid, MTI_NAME_MAXLEN);
1129 if (ospuuid == NULL)
1130 GOTO(out, rc = -ENOMEM);
1132 sprintf(ospuuid, "%s_UUID", ospname);
1133 rc = lustre_start_simple(ospname, LUSTRE_OSP_NAME,
1134 ospuuid, lustre_cfg_string(lcfg, 1),
1137 CERROR("%s: setup up failed: rc %d\n", ospname, rc);
1141 obd = class_name2obd(ospname);
1142 LASSERT(obd != NULL);
1144 rc = lustre_osp_connect(obd);
1146 CERROR("%s: connect failed: rc = %d\n", ospname, rc);
1150 if (ospname != NULL)
1151 OBD_FREE(ospname, MTI_NAME_MAXLEN);
1152 if (ospuuid != NULL)
1153 OBD_FREE(ospuuid, MTI_NAME_MAXLEN);
1158 static int lustre_osp_add_conn(struct lustre_cfg *cfg,
1159 struct lustre_sb_info *lsi)
1161 struct lustre_cfg_bufs *bufs = NULL;
1162 struct lustre_cfg *lcfg = NULL;
1163 char *ospname = NULL;
1164 struct obd_device *osp;
1168 OBD_ALLOC(ospname, MTI_NAME_MAXLEN);
1169 if (ospname == NULL)
1170 GOTO(out, rc = -ENOMEM);
1172 rc = tgt_name2ospname(lsi->lsi_svname, ospname);
1174 CERROR("%s change ospname error: rc %d\n",
1175 lsi->lsi_svname, rc);
1179 OBD_ALLOC_PTR(bufs);
1183 lustre_cfg_bufs_reset(bufs, ospname);
1184 lustre_cfg_bufs_set_string(bufs, 1,
1185 lustre_cfg_string(cfg, 1));
1187 lcfg = lustre_cfg_new(LCFG_ADD_CONN, bufs);
1189 osp = class_name2obd(ospname);
1191 CERROR("Can not find %s\n", ospname);
1192 GOTO(out, rc = -EINVAL);
1195 rc = class_add_conn(osp, lcfg);
1197 CERROR("%s: can't add conn: rc = %d\n", ospname, rc);
1203 lustre_cfg_free(lcfg);
1204 if (ospname != NULL)
1205 OBD_FREE(ospname, MTI_NAME_MAXLEN);
1211 * Retrieve MDT nids from the client log, then start the osp-on-ost device.
1212 * there are only two scenarios which would include mdt nid.
1214 * marker 5 (flags=0x01, v2.1.54.0) lustre-MDT0000 'add mdc' xxx-
1215 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:192.168.122.162@tcp
1216 * attach 0:lustre-MDT0000-mdc 1:mdc 2:lustre-clilmv_UUID
1217 * setup 0:lustre-MDT0000-mdc 1:lustre-MDT0000_UUID 2:192.168.122.162@tcp
1218 * add_uuid nid=192.168.172.1@tcp(0x20000c0a8ac01) 0: 1:192.168.172.1@tcp
1219 * add_conn 0:lustre-MDT0000-mdc 1:192.168.172.1@tcp
1220 * modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID xxxx
1221 * marker 5 (flags=0x02, v2.1.54.0) lustre-MDT0000 'add mdc' xxxx-
1223 * marker 7 (flags=0x01, v2.1.54.0) lustre-MDT0000 'add failnid' xxxx-
1224 * add_uuid nid=192.168.122.2@tcp(0x20000c0a87a02) 0: 1:192.168.122.2@tcp
1225 * add_conn 0:lustre-MDT0000-mdc 1:192.168.122.2@tcp
1226 * marker 7 (flags=0x02, v2.1.54.0) lustre-MDT0000 'add failnid' xxxx-
1228 static int client_osp_config_process(const struct lu_env *env,
1229 struct llog_handle *handle,
1230 struct llog_rec_hdr *rec, void *data)
1232 struct config_llog_instance *clli = data;
1233 int cfg_len = rec->lrh_len;
1234 char *cfg_buf = (char *) (rec + 1);
1235 struct lustre_cfg *lcfg = NULL;
1236 struct lustre_sb_info *lsi;
1237 int rc = 0, swab = 0;
1240 if (rec->lrh_type != OBD_CFG_REC) {
1241 CERROR("Unknown llog record type %#x encountered\n",
1246 LASSERT(clli->cfg_sb != NULL);
1247 lsi = s2lsi(clli->cfg_sb);
1249 lcfg = (struct lustre_cfg *)cfg_buf;
1250 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1251 lustre_swab_lustre_cfg(lcfg);
1255 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1259 switch (lcfg->lcfg_command) {
1261 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1263 lustre_swab_cfg_marker(marker, swab,
1264 LUSTRE_CFG_BUFLEN(lcfg, 1));
1265 if (marker->cm_flags & CM_SKIP ||
1266 marker->cm_flags & CM_EXCLUDE)
1269 if (!tgt_is_mdt0(marker->cm_tgtname))
1272 if(!strncmp(marker->cm_comment, "add mdc", 7) ||
1273 !strncmp(marker->cm_comment, "add failnid", 11)) {
1274 if (marker->cm_flags & CM_START) {
1275 clli->cfg_flags = CFG_F_MARKER;
1276 /* This hack is to differentiate the
1277 * ADD_UUID is come from "add mdc" record
1278 * or from "add failnid" record. */
1279 if (!strncmp(marker->cm_comment,
1281 clli->cfg_flags |= CFG_F_SKIP;
1282 } else if (marker->cm_flags & CM_END) {
1283 clli->cfg_flags = 0;
1288 case LCFG_ADD_UUID: {
1289 if (clli->cfg_flags == CFG_F_MARKER) {
1290 rc = lustre_osp_setup(lcfg, lsi);
1291 /* XXX: process only the first nid as
1292 * we don't need another instance of osp */
1293 clli->cfg_flags |= CFG_F_SKIP;
1294 } else if (clli->cfg_flags == (CFG_F_MARKER | CFG_F_SKIP)) {
1295 rc = class_add_uuid(lustre_cfg_string(lcfg, 1),
1298 CERROR("%s: Fail to add uuid, rc:%d\n",
1299 lsi->lsi_svname, rc);
1303 case LCFG_ADD_CONN: {
1304 if (is_mdc_for_mdt0(lustre_cfg_string(lcfg, 0)))
1305 rc = lustre_osp_add_conn(lcfg, lsi);
1315 static int lustre_disconnect_osp(struct super_block *sb)
1317 struct lustre_sb_info *lsi = s2lsi(sb);
1318 struct obd_device *osp;
1319 char *ospname = NULL;
1320 char *logname = NULL;
1321 struct lustre_cfg *lcfg = NULL;
1322 struct lustre_cfg_bufs *bufs = NULL;
1323 struct config_llog_instance *cfg = NULL;
1327 LASSERT(IS_OST(lsi) || IS_MDT(lsi));
1328 OBD_ALLOC(logname, MTI_NAME_MAXLEN);
1329 if (logname == NULL)
1332 OBD_ALLOC(ospname, MTI_NAME_MAXLEN);
1333 if (ospname == NULL)
1334 GOTO(out, rc = -ENOMEM);
1336 rc = server_name2fsname(lsi->lsi_svname, ospname, NULL);
1338 CERROR("%s: get fsname error: %d\n",
1339 lsi->lsi_svname, rc);
1342 sprintf(logname, "%s-client", ospname);
1346 GOTO(out, rc = -ENOMEM);
1349 cfg->cfg_instance = sb;
1350 rc = lustre_end_log(sb, logname, cfg);
1352 CERROR("Can't end config log %s\n", ospname);
1356 rc = tgt_name2ospname(lsi->lsi_svname, ospname);
1358 CERROR("%s: get osp name error: %d\n",
1359 lsi->lsi_svname, rc);
1363 osp = class_name2obd(ospname);
1365 CERROR("Can't find osp-on-ost %s\n", ospname);
1366 GOTO(out, rc = -ENOENT);
1369 OBD_ALLOC_PTR(bufs);
1371 GOTO(out, rc = -ENOMEM);
1373 lustre_cfg_bufs_reset(bufs, osp->obd_name);
1374 lustre_cfg_bufs_set_string(bufs, 1, NULL);
1375 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
1377 GOTO(out, rc = -ENOMEM);
1379 /* Disconnect import first. NULL is passed for the '@env', since
1380 * it will not be used for the 'osp-on-ost'. (see osp_shutdown()) */
1381 rc = osp->obd_lu_dev->ld_ops->ldo_process_config(NULL, osp->obd_lu_dev,
1385 lustre_cfg_free(lcfg);
1391 OBD_FREE(ospname, MTI_NAME_MAXLEN);
1393 OBD_FREE(logname, MTI_NAME_MAXLEN);
1398 * Stop the osp(fsname-MDT0000-osp-OSTxxxx) for an OST target.
1400 static int lustre_stop_osp(struct super_block *sb)
1402 struct lustre_sb_info *lsi = s2lsi(sb);
1403 struct obd_device *osp = NULL;
1404 char *ospname = NULL;
1408 LASSERT(IS_OST(lsi) || IS_MDT(lsi));
1409 OBD_ALLOC(ospname, MTI_NAME_MAXLEN);
1411 rc = tgt_name2ospname(lsi->lsi_svname, ospname);
1413 CERROR("%s get fsname error: rc %d\n",
1414 lsi->lsi_svname, rc);
1418 osp = class_name2obd(ospname);
1420 CERROR("Can not find osp-on-ost %s\n", ospname);
1421 GOTO(cleanup, rc = -ENOENT);
1425 rc = class_manual_cleanup(osp);
1428 if (ospname != NULL)
1429 OBD_FREE(ospname, MTI_NAME_MAXLEN);
1433 DEFINE_MUTEX(server_start_lock);
1435 /* Stop MDS/OSS if nobody is using them */
1436 static int server_stop_servers(int lsiflags)
1438 struct obd_device *obd = NULL;
1439 struct obd_type *type = NULL;
1443 mutex_lock(&server_start_lock);
1445 /* Either an MDT or an OST or neither */
1446 /* if this was an MDT, and there are no more MDT's, clean up the MDS */
1447 if ((lsiflags & LDD_F_SV_TYPE_MDT) &&
1448 (obd = class_name2obd(LUSTRE_MDS_OBDNAME))) {
1449 type = class_search_type(LUSTRE_MDT_NAME);
1451 /* if this was an OST, and there are no more OST's, clean up the OSS */
1452 if ((lsiflags & LDD_F_SV_TYPE_OST) &&
1453 (obd = class_name2obd(LUSTRE_OSS_OBDNAME))) {
1454 type = class_search_type(LUSTRE_OST_NAME);
1457 if (obd && (!type || !type->typ_refcnt)) {
1460 /* obd_fail doesn't mean much on a server obd */
1461 err = class_manual_cleanup(obd);
1466 mutex_unlock(&server_start_lock);
1471 int server_mti_print(char *title, struct mgs_target_info *mti)
1473 PRINT_CMD(PRINT_MASK, "mti %s\n", title);
1474 PRINT_CMD(PRINT_MASK, "server: %s\n", mti->mti_svname);
1475 PRINT_CMD(PRINT_MASK, "fs: %s\n", mti->mti_fsname);
1476 PRINT_CMD(PRINT_MASK, "uuid: %s\n", mti->mti_uuid);
1477 PRINT_CMD(PRINT_MASK, "ver: %d flags: %#x\n",
1478 mti->mti_config_ver, mti->mti_flags);
1483 * Get service name (svname) from string
1485 * if endptr isn't NULL it is set to end of fsname *
1487 int server_name2svname(char *label, char *svname, char **endptr)
1492 /* We use server_name2fsname() just for parsing */
1493 rc = server_name2fsname(label, NULL, &dash);
1500 strncpy(svname, dash + 1, MTI_NAME_MAXLEN);
1504 EXPORT_SYMBOL(server_name2svname);
1507 /* Get the index from the obd name.
1508 rc = server type, or
1510 if endptr isn't NULL it is set to end of name */
1511 int server_name2index(char *svname, __u32 *idx, char **endptr)
1513 unsigned long index;
1517 /* We use server_name2fsname() just for parsing */
1518 rc = server_name2fsname(svname, NULL, &dash);
1527 if (strncmp(dash, "MDT", 3) == 0)
1528 rc = LDD_F_SV_TYPE_MDT;
1529 else if (strncmp(dash, "OST", 3) == 0)
1530 rc = LDD_F_SV_TYPE_OST;
1536 if (strcmp(dash, "all") == 0)
1537 return rc | LDD_F_SV_ALL;
1539 index = simple_strtoul(dash, endptr, 16);
1544 EXPORT_SYMBOL(server_name2index);
1546 /* Generate data for registration */
1547 static int server_lsi2mti(struct lustre_sb_info *lsi,
1548 struct mgs_target_info *mti)
1550 lnet_process_id_t id;
1554 if (!IS_SERVER(lsi))
1557 strncpy(mti->mti_svname, lsi->lsi_svname, sizeof(mti->mti_svname));
1559 mti->mti_nid_count = 0;
1560 while (LNetGetId(i++, &id) != -ENOENT) {
1561 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
1564 /* server use --servicenode param, only allow specified
1565 * nids be registered */
1566 if ((lsi->lsi_lmd->lmd_flags & LMD_FLG_NO_PRIMNODE) != 0 &&
1567 class_match_nid(lsi->lsi_lmd->lmd_params,
1568 PARAM_FAILNODE, id.nid) < 1)
1571 /* match specified network */
1572 if (!class_match_net(lsi->lsi_lmd->lmd_params,
1573 PARAM_NETWORK, LNET_NIDNET(id.nid)))
1576 mti->mti_nids[mti->mti_nid_count] = id.nid;
1577 mti->mti_nid_count++;
1578 if (mti->mti_nid_count >= MTI_NIDS_MAX) {
1579 CWARN("Only using first %d nids for %s\n",
1580 mti->mti_nid_count, mti->mti_svname);
1585 mti->mti_lustre_ver = LUSTRE_VERSION_CODE;
1586 mti->mti_config_ver = 0;
1588 rc = server_name2fsname(lsi->lsi_svname, mti->mti_fsname, NULL);
1592 rc = server_name2index(lsi->lsi_svname, &mti->mti_stripe_index, NULL);
1595 /* Orion requires index to be set */
1596 LASSERT(!(rc & LDD_F_NEED_INDEX));
1597 /* keep only LDD flags */
1598 mti->mti_flags = lsi->lsi_flags & LDD_F_MASK;
1599 if (mti->mti_flags & (LDD_F_WRITECONF | LDD_F_VIRGIN))
1600 mti->mti_flags |= LDD_F_UPDATE;
1601 strncpy(mti->mti_params, lsi->lsi_lmd->lmd_params,
1602 sizeof(mti->mti_params));
1606 /* Register an old or new target with the MGS. If needed MGS will construct
1607 startup logs and assign index */
1608 static int server_register_target(struct lustre_sb_info *lsi)
1610 struct obd_device *mgc = lsi->lsi_mgc;
1611 struct mgs_target_info *mti = NULL;
1618 if (!IS_SERVER(lsi))
1625 rc = server_lsi2mti(lsi, mti);
1629 CDEBUG(D_MOUNT, "Registration %s, fs=%s, %s, index=%04x, flags=%#x\n",
1630 mti->mti_svname, mti->mti_fsname,
1631 libcfs_nid2str(mti->mti_nids[0]), mti->mti_stripe_index,
1634 /* if write_conf is true, the registration must succeed */
1635 writeconf = !!(lsi->lsi_flags & (LDD_F_NEED_INDEX | LDD_F_UPDATE));
1636 mti->mti_flags |= LDD_F_OPC_REG;
1638 /* Register the target */
1639 /* FIXME use mgc_process_config instead */
1640 rc = obd_set_info_async(NULL, mgc->u.cli.cl_mgc_mgsexp,
1641 sizeof(KEY_REGISTER_TARGET), KEY_REGISTER_TARGET,
1642 sizeof(*mti), mti, NULL);
1644 if (mti->mti_flags & LDD_F_ERROR) {
1645 LCONSOLE_ERROR_MSG(0x160,
1646 "The MGS is refusing to allow this "
1647 "server (%s) to start. Please see messages"
1648 " on the MGS node.\n", lsi->lsi_svname);
1649 } else if (writeconf) {
1650 LCONSOLE_ERROR_MSG(0x15f,
1651 "Communication to the MGS return error %d. "
1652 "Is the MGS running?\n", rc);
1654 CERROR("Cannot talk to the MGS: %d, not fatal\n", rc);
1655 /* reset the error code for non-fatal error. */
1668 * Notify the MGS that this target is ready.
1669 * Used by IR - if the MGS receives this message, it will notify clients.
1671 static int server_notify_target(struct super_block *sb, struct obd_device *obd)
1673 struct lustre_sb_info *lsi = s2lsi(sb);
1674 struct obd_device *mgc = lsi->lsi_mgc;
1675 struct mgs_target_info *mti = NULL;
1681 if (!(IS_SERVER(lsi)))
1687 rc = server_lsi2mti(lsi, mti);
1691 mti->mti_instance = obd->u.obt.obt_instance;
1692 mti->mti_flags |= LDD_F_OPC_READY;
1694 /* FIXME use mgc_process_config instead */
1695 rc = obd_set_info_async(NULL, mgc->u.cli.cl_mgc_mgsexp,
1696 sizeof(KEY_REGISTER_TARGET),
1697 KEY_REGISTER_TARGET,
1698 sizeof(*mti), mti, NULL);
1700 /* Imperative recovery: if the mgs informs us to use IR? */
1701 if (!rc && !(mti->mti_flags & LDD_F_ERROR) &&
1702 (mti->mti_flags & LDD_F_IR_CAPABLE))
1703 lsi->lsi_flags |= LDD_F_IR_CAPABLE;
1713 * Start the osp(fsname-MDT0000-osp-OSTxxxx) for an OST target,
1714 * which would be used to communicate with MDT0 for quota and FID.
1716 static int lustre_start_osp(struct super_block *sb)
1718 struct lustre_sb_info *lsi = s2lsi(sb);
1719 struct config_llog_instance *cfg = NULL;
1720 struct obd_device *osp;
1721 char *ospname = NULL;
1722 char *logname = NULL;
1727 LASSERT(IS_OST(lsi) || IS_MDT(lsi));
1728 OBD_ALLOC(ospname, MTI_NAME_MAXLEN);
1729 OBD_ALLOC(logname, MTI_NAME_MAXLEN);
1730 if (ospname == NULL || logname == NULL)
1731 GOTO(cleanup, rc = -ENOMEM);
1733 rc = server_name2fsname(lsi->lsi_svname, ospname, &tgt);
1735 CERROR("%s change fsname error: rc %d\n",
1736 lsi->lsi_svname, rc);
1739 sprintf(logname, "%s-client", ospname);
1741 rc = tgt_name2ospname(lsi->lsi_svname, ospname);
1743 CERROR("%s change ospname error: rc %d\n",
1744 lsi->lsi_svname, rc);
1748 osp = class_name2obd(ospname);
1750 GOTO(cleanup, rc = 0);
1754 GOTO(cleanup, rc = -ENOMEM);
1756 cfg->cfg_callback = client_osp_config_process;
1757 cfg->cfg_instance = sb;
1759 rc = lustre_process_log(sb, logname, cfg);
1762 if (ospname != NULL)
1763 OBD_FREE(ospname, MTI_NAME_MAXLEN);
1764 if (logname != NULL)
1765 OBD_FREE(logname, MTI_NAME_MAXLEN);
1772 /** Start server targets: MDTs and OSTs
1774 static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
1776 struct obd_device *obd;
1777 struct lustre_sb_info *lsi = s2lsi(sb);
1778 struct config_llog_instance cfg;
1780 struct lu_device *dev;
1784 CDEBUG(D_MOUNT, "starting target %s\n", lsi->lsi_svname);
1787 /* make sure the MDS is started */
1788 mutex_lock(&server_start_lock);
1789 obd = class_name2obd(LUSTRE_MDS_OBDNAME);
1791 rc = lustre_start_simple(LUSTRE_MDS_OBDNAME,
1793 LUSTRE_MDS_OBDNAME"_uuid",
1796 mutex_unlock(&server_start_lock);
1797 CERROR("failed to start MDS: %d\n", rc);
1801 mutex_unlock(&server_start_lock);
1804 /* If we're an OST, make sure the global OSS is running */
1806 /* make sure OSS is started */
1807 mutex_lock(&server_start_lock);
1808 obd = class_name2obd(LUSTRE_OSS_OBDNAME);
1810 rc = lustre_start_simple(LUSTRE_OSS_OBDNAME,
1812 LUSTRE_OSS_OBDNAME"_uuid",
1815 mutex_unlock(&server_start_lock);
1816 CERROR("failed to start OSS: %d\n", rc);
1820 mutex_unlock(&server_start_lock);
1823 /* Set the mgc fs to our server disk. This allows the MGC to
1824 * read and write configs locally, in case it can't talk to the MGS. */
1825 if (lsi->lsi_srv_mnt) {
1826 rc = server_mgc_set_fs(lsi->lsi_mgc, sb);
1828 GOTO(out_stop_service, rc);
1831 /* Register with MGS */
1832 rc = server_register_target(lsi);
1836 /* Let the target look up the mount using the target's name
1837 (we can't pass the sb or mnt through class_process_config.) */
1838 rc = server_register_mount(lsi->lsi_svname, sb, mnt);
1842 /* Start targets using the llog named for the target */
1843 memset(&cfg, 0, sizeof(cfg));
1844 cfg.cfg_callback = class_config_llog_handler;
1845 rc = lustre_process_log(sb, lsi->lsi_svname, &cfg);
1847 CERROR("failed to start server %s: %d\n",
1848 lsi->lsi_svname, rc);
1849 /* Do NOT call server_deregister_mount() here. This makes it
1850 * impossible to find mount later in cleanup time and leaves
1851 * @lsi and othder stuff leaked. -umka */
1855 obd = class_name2obd(lsi->lsi_svname);
1857 CERROR("no server named %s was started\n", lsi->lsi_svname);
1858 GOTO(out_mgc, rc = -ENXIO);
1861 if (IS_OST(lsi) || IS_MDT(lsi)) {
1862 rc = lustre_start_osp(sb);
1864 CERROR("%s: failed to start OSP: %d\n",
1865 lsi->lsi_svname, rc);
1870 server_notify_target(sb, obd);
1872 /* calculate recovery timeout, do it after lustre_process_log */
1873 server_calc_timeout(lsi, obd);
1875 /* log has been fully processed */
1876 obd_notify(obd, NULL, OBD_NOTIFY_CONFIG, (void *)CONFIG_LOG);
1878 /* log has been fully processed, let clients connect */
1879 dev = obd->obd_lu_dev;
1880 if (dev && dev->ld_ops->ldo_prepare) {
1881 rc = lu_env_init(&env, dev->ld_type->ldt_ctx_tags);
1883 struct lu_context session_ctx;
1885 lu_context_init(&session_ctx, LCT_SESSION);
1886 session_ctx.lc_thread = NULL;
1887 lu_context_enter(&session_ctx);
1888 env.le_ses = &session_ctx;
1890 dev->ld_ops->ldo_prepare(&env, NULL, dev);
1893 lu_context_exit(&session_ctx);
1894 lu_context_fini(&session_ctx);
1898 /* abort recovery only on the complete stack:
1899 * many devices can be involved */
1900 if ((lsi->lsi_lmd->lmd_flags & LMD_FLG_ABORT_RECOV) &&
1901 (OBP(obd, iocontrol))) {
1902 obd_iocontrol(OBD_IOC_ABORT_RECOVERY, obd->obd_self_export, 0,
1907 /* Release the mgc fs for others to use */
1908 if (lsi->lsi_srv_mnt)
1909 server_mgc_clear_fs(lsi->lsi_mgc);
1913 server_stop_servers(lsi->lsi_flags);
1918 /***************** lustre superblock **************/
1920 struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
1922 struct lustre_sb_info *lsi;
1928 OBD_ALLOC_PTR(lsi->lsi_lmd);
1929 if (!lsi->lsi_lmd) {
1934 lsi->lsi_lmd->lmd_exclude_count = 0;
1935 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
1936 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
1937 s2lsi_nocast(sb) = lsi;
1938 /* we take 1 extra ref for our setup */
1939 cfs_atomic_set(&lsi->lsi_mounts, 1);
1941 /* Default umount style */
1942 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
1947 static int lustre_free_lsi(struct super_block *sb)
1949 struct lustre_sb_info *lsi = s2lsi(sb);
1952 LASSERT(lsi != NULL);
1953 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
1955 /* someone didn't call server_put_mount. */
1956 LASSERT(cfs_atomic_read(&lsi->lsi_mounts) == 0);
1958 if (lsi->lsi_lmd != NULL) {
1959 if (lsi->lsi_lmd->lmd_dev != NULL)
1960 OBD_FREE(lsi->lsi_lmd->lmd_dev,
1961 strlen(lsi->lsi_lmd->lmd_dev) + 1);
1962 if (lsi->lsi_lmd->lmd_profile != NULL)
1963 OBD_FREE(lsi->lsi_lmd->lmd_profile,
1964 strlen(lsi->lsi_lmd->lmd_profile) + 1);
1965 if (lsi->lsi_lmd->lmd_mgssec != NULL)
1966 OBD_FREE(lsi->lsi_lmd->lmd_mgssec,
1967 strlen(lsi->lsi_lmd->lmd_mgssec) + 1);
1968 if (lsi->lsi_lmd->lmd_opts != NULL)
1969 OBD_FREE(lsi->lsi_lmd->lmd_opts,
1970 strlen(lsi->lsi_lmd->lmd_opts) + 1);
1971 if (lsi->lsi_lmd->lmd_exclude_count)
1972 OBD_FREE(lsi->lsi_lmd->lmd_exclude,
1973 sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
1974 lsi->lsi_lmd->lmd_exclude_count);
1975 if (lsi->lsi_lmd->lmd_mgs != NULL)
1976 OBD_FREE(lsi->lsi_lmd->lmd_mgs,
1977 strlen(lsi->lsi_lmd->lmd_mgs) + 1);
1978 if (lsi->lsi_lmd->lmd_osd_type != NULL)
1979 OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
1980 strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
1981 if (lsi->lsi_lmd->lmd_params != NULL)
1982 OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
1984 OBD_FREE(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
1987 LASSERT(lsi->lsi_llsbi == NULL);
1988 OBD_FREE(lsi, sizeof(*lsi));
1989 s2lsi_nocast(sb) = NULL;
1994 /* The lsi has one reference for every server that is using the disk -
1995 e.g. MDT, MGS, and potentially MGC */
1996 static int lustre_put_lsi(struct super_block *sb)
1998 struct lustre_sb_info *lsi = s2lsi(sb);
2001 LASSERT(lsi != NULL);
2003 CDEBUG(D_MOUNT, "put %p %d\n", sb, cfs_atomic_read(&lsi->lsi_mounts));
2004 if (cfs_atomic_dec_and_test(&lsi->lsi_mounts)) {
2005 if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
2006 obd_disconnect(lsi->lsi_osd_exp);
2007 /* wait till OSD is gone */
2008 obd_zombie_barrier();
2010 lustre_free_lsi(sb);
2016 static int lsi_prepare(struct lustre_sb_info *lsi)
2023 LASSERT(lsi->lsi_lmd);
2025 /* The server name is given as a mount line option */
2026 if (lsi->lsi_lmd->lmd_profile == NULL) {
2027 LCONSOLE_ERROR("Can't determine server name\n");
2031 if (strlen(lsi->lsi_lmd->lmd_profile) >= sizeof(lsi->lsi_svname))
2032 RETURN(-ENAMETOOLONG);
2034 strcpy(lsi->lsi_svname, lsi->lsi_lmd->lmd_profile);
2036 /* Determine osd type */
2037 if (lsi->lsi_lmd->lmd_osd_type != NULL) {
2038 if (strlen(lsi->lsi_lmd->lmd_osd_type) >=
2039 sizeof(lsi->lsi_osd_type))
2040 RETURN(-ENAMETOOLONG);
2042 strcpy(lsi->lsi_osd_type, lsi->lsi_lmd->lmd_osd_type);
2044 strcpy(lsi->lsi_osd_type, LUSTRE_OSD_LDISKFS_NAME);
2047 /* XXX: a temp. solution for components using fsfilt
2048 * to be removed in one of the subsequent patches */
2049 if (!strcmp(lsi->lsi_lmd->lmd_osd_type, "osd-ldiskfs")) {
2050 strcpy(lsi->lsi_fstype, "ldiskfs");
2052 strcpy(lsi->lsi_fstype, lsi->lsi_lmd->lmd_osd_type);
2055 /* Determine server type */
2056 rc = server_name2index(lsi->lsi_svname, &index, NULL);
2058 if (lsi->lsi_lmd->lmd_flags & LMD_FLG_MGS) {
2059 /* Assume we're a bare MGS */
2061 lsi->lsi_lmd->lmd_flags |= LMD_FLG_NOSVC;
2063 LCONSOLE_ERROR("Can't determine server type of '%s'\n",
2068 lsi->lsi_flags |= rc;
2070 /* Add mount line flags that used to be in ldd:
2071 * writeconf, mgs, anything else?
2073 lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_WRITECONF) ?
2074 LDD_F_WRITECONF : 0;
2075 lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_VIRGIN) ?
2077 lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_MGS) ?
2078 LDD_F_SV_TYPE_MGS : 0;
2079 lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_NO_PRIMNODE) ?
2080 LDD_F_NO_PRIMNODE : 0;
2085 /*************** server mount ******************/
2087 /** Start the shutdown of servers at umount.
2089 static void server_put_super(struct super_block *sb)
2091 struct lustre_sb_info *lsi = s2lsi(sb);
2092 struct obd_device *obd;
2093 char *tmpname, *extraname = NULL;
2095 int lsiflags = lsi->lsi_flags;
2098 LASSERT(IS_SERVER(lsi));
2100 tmpname_sz = strlen(lsi->lsi_svname) + 1;
2101 OBD_ALLOC(tmpname, tmpname_sz);
2102 memcpy(tmpname, lsi->lsi_svname, tmpname_sz);
2103 CDEBUG(D_MOUNT, "server put_super %s\n", tmpname);
2104 if (IS_MDT(lsi) && (lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC))
2105 snprintf(tmpname, tmpname_sz, "MGS");
2107 /* disconnect the osp-on-ost first to drain off the inflight request */
2108 if (IS_OST(lsi) || IS_MDT(lsi)) {
2111 rc = lustre_disconnect_osp(sb);
2112 if (rc && rc != ETIMEDOUT)
2113 CERROR("%s: failed to disconnect osp-on-ost (rc=%d)!\n",
2117 /* Stop the target */
2118 if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC) &&
2119 (IS_MDT(lsi) || IS_OST(lsi))) {
2120 struct lustre_profile *lprof = NULL;
2122 /* tell the mgc to drop the config log */
2123 lustre_end_log(sb, lsi->lsi_svname, NULL);
2125 /* COMPAT_146 - profile may get deleted in mgc_cleanup.
2126 If there are any setup/cleanup errors, save the lov
2127 name for safety cleanup later. */
2128 lprof = class_get_profile(lsi->lsi_svname);
2129 if (lprof && lprof->lp_dt) {
2130 OBD_ALLOC(extraname, strlen(lprof->lp_dt) + 1);
2131 strcpy(extraname, lprof->lp_dt);
2134 obd = class_name2obd(lsi->lsi_svname);
2136 CDEBUG(D_MOUNT, "stopping %s\n", obd->obd_name);
2137 if (lsiflags & LSI_UMOUNT_FAILOVER)
2139 /* We can't seem to give an error return code
2140 * to .put_super, so we better make sure we clean up! */
2142 class_manual_cleanup(obd);
2144 CERROR("no obd %s\n", lsi->lsi_svname);
2145 server_deregister_mount(lsi->lsi_svname);
2149 /* If they wanted the mgs to stop separately from the mdt, they
2150 should have put it on a different device. */
2152 /* if MDS start with --nomgs, don't stop MGS then */
2153 if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOMGS))
2154 server_stop_mgs(sb);
2157 if (IS_OST(lsi) || IS_MDT(lsi)) {
2158 if (lustre_stop_osp(sb) < 0)
2159 CERROR("%s: Fail to stop osp-on-ost!\n", tmpname);
2162 /* Clean the mgc and sb */
2163 lustre_common_put_super(sb);
2165 /* wait till all in-progress cleanups are done
2166 * specifically we're interested in ofd cleanup
2168 obd_zombie_barrier();
2170 /* Stop the servers (MDS, OSS) if no longer needed. We must wait
2171 until the target is really gone so that our type refcount check
2173 server_stop_servers(lsiflags);
2175 /* In case of startup or cleanup err, stop related obds */
2177 obd = class_name2obd(extraname);
2179 CWARN("Cleaning orphaned obd %s\n", extraname);
2181 class_manual_cleanup(obd);
2183 OBD_FREE(extraname, strlen(extraname) + 1);
2186 LCONSOLE_WARN("server umount %s complete\n", tmpname);
2187 OBD_FREE(tmpname, tmpname_sz);
2191 /** Called only for 'umount -f'
2193 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
2194 static void server_umount_begin(struct vfsmount *vfsmnt, int flags)
2196 struct super_block *sb = vfsmnt->mnt_sb;
2198 static void server_umount_begin(struct super_block *sb)
2201 struct lustre_sb_info *lsi = s2lsi(sb);
2204 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
2205 if (!(flags & MNT_FORCE)) {
2211 CDEBUG(D_MOUNT, "umount -f\n");
2212 /* umount = failover
2214 no third way to do non-force, non-failover */
2215 lsi->lsi_flags &= ~LSI_UMOUNT_FAILOVER;
2219 static int server_statfs (struct dentry *dentry, cfs_kstatfs_t *buf)
2221 struct super_block *sb = dentry->d_sb;
2222 struct lustre_sb_info *lsi = s2lsi(sb);
2223 struct obd_statfs statfs;
2227 if (lsi->lsi_dt_dev) {
2228 rc = dt_statfs(NULL, lsi->lsi_dt_dev, &statfs);
2230 statfs_unpack(buf, &statfs);
2231 buf->f_type = sb->s_magic;
2237 buf->f_type = sb->s_magic;
2238 buf->f_bsize = sb->s_blocksize;
2244 buf->f_namelen = NAME_MAX;
2248 /** The operations we support directly on the superblock:
2249 * mount, umount, and df.
2251 static struct super_operations server_ops =
2253 .put_super = server_put_super,
2254 .umount_begin = server_umount_begin, /* umount -f */
2255 .statfs = server_statfs,
2258 #define log2(n) ffz(~(n))
2259 #define LUSTRE_SUPER_MAGIC 0x0BD00BD1
2261 static int server_fill_super_common(struct super_block *sb)
2263 struct inode *root = 0;
2266 CDEBUG(D_MOUNT, "Server sb, dev=%d\n", (int)sb->s_dev);
2268 sb->s_blocksize = 4096;
2269 sb->s_blocksize_bits = log2(sb->s_blocksize);
2270 sb->s_magic = LUSTRE_SUPER_MAGIC;
2271 sb->s_maxbytes = 0; /* we don't allow file IO on server mountpoints */
2272 sb->s_flags |= MS_RDONLY;
2273 sb->s_op = &server_ops;
2275 root = new_inode(sb);
2277 CERROR("Can't make root inode\n");
2281 /* returns -EIO for every operation */
2282 /* make_bad_inode(root); -- badness - can't umount */
2283 /* apparently we need to be a directory for the mount to finish */
2284 root->i_mode = S_IFDIR;
2286 sb->s_root = d_make_root(root);
2288 CERROR("%s: can't make root dentry\n", sb->s_id);
2295 static int osd_start(struct lustre_sb_info *lsi, unsigned long mflags)
2297 struct lustre_mount_data *lmd = lsi->lsi_lmd;
2298 struct obd_device *obd;
2299 struct dt_device_param p;
2305 "Attempting to start %s, type=%s, lsifl=%x, mountfl=%lx\n",
2306 lsi->lsi_svname, lsi->lsi_osd_type, lsi->lsi_flags, mflags);
2308 sprintf(lsi->lsi_osd_obdname, "%s-osd", lsi->lsi_svname);
2309 strcpy(lsi->lsi_osd_uuid, lsi->lsi_osd_obdname);
2310 strcat(lsi->lsi_osd_uuid, "_UUID");
2311 sprintf(flagstr, "%lu:%lu", mflags, (unsigned long) lmd->lmd_flags);
2313 obd = class_name2obd(lsi->lsi_osd_obdname);
2315 rc = lustre_start_simple(lsi->lsi_osd_obdname,
2317 lsi->lsi_osd_uuid, lmd->lmd_dev,
2318 flagstr, lsi->lsi_lmd->lmd_opts,
2322 obd = class_name2obd(lsi->lsi_osd_obdname);
2326 rc = obd_connect(NULL, &lsi->lsi_osd_exp, obd, &obd->obd_uuid, NULL, NULL);
2329 class_manual_cleanup(obd);
2330 lsi->lsi_dt_dev = NULL;
2333 /* XXX: to keep support old components relying on lsi_srv_mnt
2334 * we get this info from OSD just started */
2335 LASSERT(obd->obd_lu_dev);
2336 lsi->lsi_dt_dev = lu2dt_dev(obd->obd_lu_dev);
2337 LASSERT(lsi->lsi_dt_dev);
2339 dt_conf_get(NULL, lsi->lsi_dt_dev, &p);
2341 lsi->lsi_srv_mnt = p.ddp_mnt;
2347 /** Fill in the superblock info for a Lustre server.
2348 * Mount the device with the correct options.
2349 * Read the on-disk config file.
2350 * Start the services.
2352 static int server_fill_super(struct super_block *sb)
2354 struct lustre_sb_info *lsi = s2lsi(sb);
2358 rc = lsi_prepare(lsi);
2362 /* Start low level OSD */
2363 rc = osd_start(lsi, sb->s_flags);
2365 CERROR("Unable to start osd on %s: %d\n",
2366 lsi->lsi_lmd->lmd_dev, rc);
2371 CDEBUG(D_MOUNT, "Found service %s on device %s\n",
2372 lsi->lsi_svname, lsi->lsi_lmd->lmd_dev);
2374 if (class_name2obd(lsi->lsi_svname)) {
2375 LCONSOLE_ERROR_MSG(0x161, "The target named %s is already "
2376 "running. Double-mount may have compromised"
2377 " the disk journal.\n",
2383 /* Start MGS before MGC */
2384 if (IS_MGS(lsi) && !(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOMGS)){
2385 rc = server_start_mgs(sb);
2390 /* Start MGC before servers */
2391 rc = lustre_start_mgc(sb);
2395 /* Set up all obd devices for service */
2396 if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC) &&
2397 (IS_OST(lsi) || IS_MDT(lsi))) {
2398 rc = server_start_targets(sb, lsi->lsi_srv_mnt);
2400 CERROR("Unable to start targets: %d\n", rc);
2403 /* FIXME overmount client here,
2404 or can we just start a client log and client_fill_super on this sb?
2405 We need to make sure server_put_super gets called too - ll_put_super
2406 calls lustre_common_put_super; check there for LSI_SERVER flag,
2408 Probably should start client from new thread so we can return.
2409 Client will not finish until all servers are connected.
2410 Note - MGS-only server does NOT get a client, since there is no
2411 lustre fs associated - the MGS is for all lustre fs's */
2414 rc = server_fill_super_common(sb);
2420 /* We jump here in case of failure while starting targets or MGS.
2421 * In this case we can't just put @mnt and have to do real cleanup
2422 * with stoping targets, etc. */
2423 server_put_super(sb);
2428 * Calculate timeout value for a target.
2430 void server_calc_timeout(struct lustre_sb_info *lsi, struct obd_device *obd)
2432 struct lustre_mount_data *lmd;
2436 bool has_ir = !!(lsi->lsi_flags & LDD_F_IR_CAPABLE);
2437 int min = OBD_RECOVERY_TIME_MIN;
2439 LASSERT(IS_SERVER(lsi));
2443 soft = lmd->lmd_recovery_time_soft;
2444 hard = lmd->lmd_recovery_time_hard;
2445 has_ir = has_ir && !(lmd->lmd_flags & LMD_FLG_NOIR);
2446 obd->obd_no_ir = !has_ir;
2450 soft = OBD_RECOVERY_TIME_SOFT;
2452 hard = OBD_RECOVERY_TIME_HARD;
2454 /* target may have ir_factor configured. */
2455 factor = OBD_IR_FACTOR_DEFAULT;
2456 if (obd->obd_recovery_ir_factor)
2457 factor = obd->obd_recovery_ir_factor;
2460 int new_soft = soft;
2461 int new_hard = hard;
2463 /* adjust timeout value by imperative recovery */
2465 new_soft = (soft * factor) / OBD_IR_FACTOR_MAX;
2466 new_hard = (hard * factor) / OBD_IR_FACTOR_MAX;
2468 /* make sure the timeout is not too short */
2469 new_soft = max(min, new_soft);
2470 new_hard = max(new_soft, new_hard);
2472 LCONSOLE_INFO("%s: Imperative Recovery enabled, recovery "
2473 "window shrunk from %d-%d down to %d-%d\n",
2474 obd->obd_name, soft, hard, new_soft, new_hard);
2481 obd->obd_recovery_timeout = max(obd->obd_recovery_timeout, soft);
2482 obd->obd_recovery_time_hard = hard;
2483 obd->obd_recovery_ir_factor = factor;
2485 EXPORT_SYMBOL(server_calc_timeout);
2487 /*************** mount common betweeen server and client ***************/
2490 int lustre_common_put_super(struct super_block *sb)
2495 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
2497 /* Drop a ref to the MGC */
2498 rc = lustre_stop_mgc(sb);
2499 if (rc && (rc != -ENOENT)) {
2501 CERROR("Can't stop MGC: %d\n", rc);
2504 /* BUSY just means that there's some other obd that
2505 needs the mgc. Let him clean it up. */
2506 CDEBUG(D_MOUNT, "MGC still in use\n");
2508 /* Drop a ref to the mounted disk */
2513 EXPORT_SYMBOL(lustre_common_put_super);
2515 static void lmd_print(struct lustre_mount_data *lmd)
2519 PRINT_CMD(PRINT_MASK, " mount data:\n");
2520 if (lmd_is_client(lmd))
2521 PRINT_CMD(PRINT_MASK, "profile: %s\n", lmd->lmd_profile);
2522 PRINT_CMD(PRINT_MASK, "device: %s\n", lmd->lmd_dev);
2523 PRINT_CMD(PRINT_MASK, "flags: %x\n", lmd->lmd_flags);
2526 PRINT_CMD(PRINT_MASK, "options: %s\n", lmd->lmd_opts);
2528 if (lmd->lmd_recovery_time_soft)
2529 PRINT_CMD(PRINT_MASK, "recovery time soft: %d\n",
2530 lmd->lmd_recovery_time_soft);
2532 if (lmd->lmd_recovery_time_hard)
2533 PRINT_CMD(PRINT_MASK, "recovery time hard: %d\n",
2534 lmd->lmd_recovery_time_hard);
2536 for (i = 0; i < lmd->lmd_exclude_count; i++) {
2537 PRINT_CMD(PRINT_MASK, "exclude %d: OST%04x\n", i,
2538 lmd->lmd_exclude[i]);
2542 /* Is this server on the exclusion list */
2543 int lustre_check_exclusion(struct super_block *sb, char *svname)
2545 struct lustre_sb_info *lsi = s2lsi(sb);
2546 struct lustre_mount_data *lmd = lsi->lsi_lmd;
2551 rc = server_name2index(svname, &index, NULL);
2552 if (rc != LDD_F_SV_TYPE_OST)
2553 /* Only exclude OSTs */
2556 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
2557 index, lmd->lmd_exclude_count, lmd->lmd_dev);
2559 for(i = 0; i < lmd->lmd_exclude_count; i++) {
2560 if (index == lmd->lmd_exclude[i]) {
2561 CWARN("Excluding %s (on exclusion list)\n", svname);
2568 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
2569 static int lmd_make_exclusion(struct lustre_mount_data *lmd, char *ptr)
2571 char *s1 = ptr, *s2;
2572 __u32 index, *exclude_list;
2576 /* The shortest an ost name can be is 8 chars: -OST0000.
2577 We don't actually know the fsname at this time, so in fact
2578 a user could specify any fsname. */
2579 devmax = strlen(ptr) / 8 + 1;
2581 /* temp storage until we figure out how many we have */
2582 OBD_ALLOC(exclude_list, sizeof(index) * devmax);
2586 /* we enter this fn pointing at the '=' */
2587 while (*s1 && *s1 != ' ' && *s1 != ',') {
2589 rc = server_name2index(s1, &index, &s2);
2591 CERROR("Can't parse server name '%s'\n", s1);
2594 if (rc == LDD_F_SV_TYPE_OST)
2595 exclude_list[lmd->lmd_exclude_count++] = index;
2597 CDEBUG(D_MOUNT, "ignoring exclude %.7s\n", s1);
2599 /* now we are pointing at ':' (next exclude)
2600 or ',' (end of excludes) */
2601 if (lmd->lmd_exclude_count >= devmax)
2604 if (rc >= 0) /* non-err */
2607 if (lmd->lmd_exclude_count) {
2608 /* permanent, freed in lustre_free_lsi */
2609 OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
2610 lmd->lmd_exclude_count);
2611 if (lmd->lmd_exclude) {
2612 memcpy(lmd->lmd_exclude, exclude_list,
2613 sizeof(index) * lmd->lmd_exclude_count);
2616 lmd->lmd_exclude_count = 0;
2619 OBD_FREE(exclude_list, sizeof(index) * devmax);
2623 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
2628 if (lmd->lmd_mgssec != NULL) {
2629 OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
2630 lmd->lmd_mgssec = NULL;
2633 tail = strchr(ptr, ',');
2635 length = strlen(ptr);
2637 length = tail - ptr;
2639 OBD_ALLOC(lmd->lmd_mgssec, length + 1);
2640 if (lmd->lmd_mgssec == NULL)
2643 memcpy(lmd->lmd_mgssec, ptr, length);
2644 lmd->lmd_mgssec[length] = '\0';
2648 static int lmd_parse_string(char **handle, char *ptr)
2653 if ((handle == NULL) || (ptr == NULL))
2656 if (*handle != NULL) {
2657 OBD_FREE(*handle, strlen(*handle) + 1);
2661 tail = strchr(ptr, ',');
2663 length = strlen(ptr);
2665 length = tail - ptr;
2667 OBD_ALLOC(*handle, length + 1);
2668 if (*handle == NULL)
2671 memcpy(*handle, ptr, length);
2672 (*handle)[length] = '\0';
2677 /* Collect multiple values for mgsnid specifiers */
2678 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
2686 /* Find end of nidlist */
2687 while (class_parse_nid_quiet(tail, &nid, &tail) == 0) {}
2688 length = tail - *ptr;
2690 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
2694 if (lmd->lmd_mgs != NULL)
2695 oldlen = strlen(lmd->lmd_mgs) + 1;
2697 OBD_ALLOC(mgsnid, oldlen + length + 1);
2701 if (lmd->lmd_mgs != NULL) {
2702 /* Multiple mgsnid= are taken to mean failover locations */
2703 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
2704 mgsnid[oldlen - 1] = ':';
2705 OBD_FREE(lmd->lmd_mgs, oldlen);
2707 memcpy(mgsnid + oldlen, *ptr, length);
2708 mgsnid[oldlen + length] = '\0';
2709 lmd->lmd_mgs = mgsnid;
2715 /** Parse mount line options
2716 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
2717 * dev is passed as device=uml1:/lustre by mount.lustre
2719 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
2721 char *s1, *s2, *devname = NULL;
2722 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
2728 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that "
2729 "/sbin/mount.lustre is installed.\n");
2733 /* Options should be a string - try to detect old lmd data */
2734 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
2735 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of "
2736 "/sbin/mount.lustre. Please install "
2737 "version %s\n", LUSTRE_VERSION_STRING);
2740 lmd->lmd_magic = LMD_MAGIC;
2742 OBD_ALLOC(lmd->lmd_params, 4096);
2743 if (lmd->lmd_params == NULL)
2745 lmd->lmd_params[0] = '\0';
2747 /* Set default flags here */
2752 int time_min = OBD_RECOVERY_TIME_MIN;
2754 /* Skip whitespace and extra commas */
2755 while (*s1 == ' ' || *s1 == ',')
2758 /* Client options are parsed in ll_options: eg. flock,
2761 /* Parse non-ldiskfs options here. Rather than modifying
2762 ldiskfs, we just zero these out here */
2763 if (strncmp(s1, "abort_recov", 11) == 0) {
2764 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
2766 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
2767 lmd->lmd_recovery_time_soft = max_t(int,
2768 simple_strtoul(s1 + 19, NULL, 10), time_min);
2770 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
2771 lmd->lmd_recovery_time_hard = max_t(int,
2772 simple_strtoul(s1 + 19, NULL, 10), time_min);
2774 } else if (strncmp(s1, "noir", 4) == 0) {
2775 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
2777 } else if (strncmp(s1, "nosvc", 5) == 0) {
2778 lmd->lmd_flags |= LMD_FLG_NOSVC;
2780 } else if (strncmp(s1, "nomgs", 5) == 0) {
2781 lmd->lmd_flags |= LMD_FLG_NOMGS;
2783 } else if (strncmp(s1, "noscrub", 7) == 0) {
2784 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
2786 } else if (strncmp(s1, PARAM_MGSNODE,
2787 sizeof(PARAM_MGSNODE) - 1) == 0) {
2788 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
2789 /* Assume the next mount opt is the first
2790 invalid nid we get to. */
2791 rc = lmd_parse_mgs(lmd, &s2);
2795 } else if (strncmp(s1, "writeconf", 9) == 0) {
2796 lmd->lmd_flags |= LMD_FLG_WRITECONF;
2798 } else if (strncmp(s1, "virgin", 6) == 0) {
2799 lmd->lmd_flags |= LMD_FLG_VIRGIN;
2801 } else if (strncmp(s1, "noprimnode", 10) == 0) {
2802 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
2804 } else if (strncmp(s1, "mgssec=", 7) == 0) {
2805 rc = lmd_parse_mgssec(lmd, s1 + 7);
2809 /* ost exclusion list */
2810 } else if (strncmp(s1, "exclude=", 8) == 0) {
2811 rc = lmd_make_exclusion(lmd, s1 + 7);
2815 } else if (strncmp(s1, "mgs", 3) == 0) {
2817 lmd->lmd_flags |= LMD_FLG_MGS;
2819 } else if (strncmp(s1, "svname=", 7) == 0) {
2820 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
2824 } else if (strncmp(s1, "param=", 6) == 0) {
2826 char *tail = strchr(s1 + 6, ',');
2828 length = strlen(s1);
2832 strncat(lmd->lmd_params, s1 + 6, length);
2833 strcat(lmd->lmd_params, " ");
2835 } else if (strncmp(s1, "osd=", 4) == 0) {
2836 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
2841 /* Linux 2.4 doesn't pass the device, so we stuck it at the
2842 end of the options. */
2843 else if (strncmp(s1, "device=", 7) == 0) {
2845 /* terminate options right before device. device
2846 must be the last one. */
2852 s2 = strchr(s1, ',');
2860 memmove(s1, s2, strlen(s2) + 1);
2866 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name "
2867 "(need mount option 'device=...')\n");
2871 s1 = strstr(devname, ":/");
2874 lmd->lmd_flags |= LMD_FLG_CLIENT;
2875 /* Remove leading /s from fsname */
2876 while (*++s1 == '/') ;
2877 /* Freed in lustre_free_lsi */
2878 OBD_ALLOC(lmd->lmd_profile, strlen(s1) + 8);
2879 if (!lmd->lmd_profile)
2881 sprintf(lmd->lmd_profile, "%s-client", s1);
2884 /* Freed in lustre_free_lsi */
2885 OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
2888 strcpy(lmd->lmd_dev, devname);
2890 /* Save mount options */
2891 s1 = options + strlen(options) - 1;
2892 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
2894 if (*options != 0) {
2895 /* Freed in lustre_free_lsi */
2896 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
2899 strcpy(lmd->lmd_opts, options);
2903 lmd->lmd_magic = LMD_MAGIC;
2908 CERROR("Bad mount options %s\n", options);
2912 struct lustre_mount_data2 {
2914 struct vfsmount *lmd2_mnt;
2917 /** This is the entry point for the mount call into Lustre.
2918 * This is called when a server or client is mounted,
2919 * and this is where we start setting things up.
2920 * @param data Mount options (e.g. -o flock,abort_recov)
2922 int lustre_fill_super(struct super_block *sb, void *data, int silent)
2924 struct lustre_mount_data *lmd;
2925 struct lustre_mount_data2 *lmd2 = data;
2926 struct lustre_sb_info *lsi;
2930 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
2932 lsi = lustre_init_lsi(sb);
2938 * Disable lockdep during mount, because mount locking patterns are
2944 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
2946 obd_zombie_barrier();
2948 /* Figure out the lmd from the mount options */
2949 if (lmd_parse((char *)(lmd2->lmd2_data), lmd)) {
2951 GOTO(out, rc = -EINVAL);
2954 if (lmd_is_client(lmd)) {
2955 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
2956 if (!client_fill_super) {
2957 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for "
2958 "client mount! Is the 'lustre' "
2959 "module loaded?\n");
2963 rc = lustre_start_mgc(sb);
2968 /* Connect and start */
2969 /* (should always be ll_fill_super) */
2970 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
2971 /* c_f_s will call lustre_common_put_super on failure */
2974 CDEBUG(D_MOUNT, "Mounting server from %s\n", lmd->lmd_dev);
2975 rc = server_fill_super(sb);
2976 /* s_f_s calls lustre_start_mgc after the mount because we need
2977 the MGS nids which are stored on disk. Plus, we may
2978 need to start the MGS first. */
2979 /* s_f_s will call server_put_super on failure */
2982 /* If error happens in fill_super() call, @lsi will be killed there.
2983 * This is why we do not put it here. */
2987 CERROR("Unable to mount %s (%d)\n",
2988 s2lsi(sb) ? lmd->lmd_dev : "", rc);
2990 CDEBUG(D_SUPER, "Mount %s complete\n",
2998 /* We can't call ll_fill_super by name because it lives in a module that
2999 must be loaded after this one. */
3000 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
3001 struct vfsmount *mnt))
3003 client_fill_super = cfs;
3005 EXPORT_SYMBOL(lustre_register_client_fill_super);
3007 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
3009 kill_super_cb = cfs;
3011 EXPORT_SYMBOL(lustre_register_kill_super_cb);
3013 /***************** FS registration ******************/
3014 #ifdef HAVE_FSTYPE_MOUNT
3015 struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
3016 const char *devname, void *data)
3018 struct lustre_mount_data2 lmd2 = { data, NULL };
3020 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
3023 int lustre_get_sb(struct file_system_type *fs_type, int flags,
3024 const char *devname, void * data, struct vfsmount *mnt)
3026 struct lustre_mount_data2 lmd2 = { data, mnt };
3028 return get_sb_nodev(fs_type, flags, &lmd2, lustre_fill_super, mnt);
3032 void lustre_kill_super(struct super_block *sb)
3034 struct lustre_sb_info *lsi = s2lsi(sb);
3036 if (kill_super_cb && lsi && !IS_SERVER(lsi))
3037 (*kill_super_cb)(sb);
3039 kill_anon_super(sb);
3042 /** Register the "lustre" fs type
3044 struct file_system_type lustre_fs_type = {
3045 .owner = THIS_MODULE,
3047 #ifdef HAVE_FSTYPE_MOUNT
3048 .mount = lustre_mount,
3050 .get_sb = lustre_get_sb,
3052 .kill_sb = lustre_kill_super,
3053 .fs_flags = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV |
3054 FS_HAS_FIEMAP | FS_RENAME_DOES_D_MOVE,
3057 int lustre_register_fs(void)
3059 return register_filesystem(&lustre_fs_type);
3062 int lustre_unregister_fs(void)
3064 return unregister_filesystem(&lustre_fs_type);
3067 EXPORT_SYMBOL(server_mti_print);