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) 2013, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/obdclass/obd_mount_server.c
33 * Server mount routines
35 * Author: Nathan Rutman <nathan@clusterfs.com>
37 #define DEBUG_SUBSYSTEM S_CLASS
38 #define D_MOUNT (D_SUPER | D_CONFIG /* | D_WARNING */)
40 #include <linux/types.h>
41 #include <linux/generic-radix-tree.h>
42 #ifdef HAVE_LINUX_SELINUX_IS_ENABLED
43 #include <linux/selinux.h>
45 #include <linux/statfs.h>
46 #include <linux/version.h>
47 #include <linux/delay.h>
48 #include <linux/file.h>
50 #include <linux/fsmap.h>
53 #include <llog_swab.h>
54 #include <lustre_disk.h>
55 #include <uapi/linux/lustre/lustre_ioctl.h>
56 #include <lustre_log.h>
57 #include <uapi/linux/lustre/lustre_param.h>
59 #include <obd_class.h>
61 #include "tgt_internal.h"
63 /*********** mount lookup *********/
65 static DEFINE_MUTEX(lustre_mount_info_lock);
66 static LIST_HEAD(server_mount_info_list);
68 static struct lustre_mount_info *server_find_mount(const char *name)
70 struct list_head *tmp;
71 struct lustre_mount_info *lmi;
74 list_for_each(tmp, &server_mount_info_list) {
75 lmi = list_entry(tmp, struct lustre_mount_info,
77 if (strcmp(name, lmi->lmi_name) == 0)
83 /* we must register an obd for a mount before we call the setup routine.
84 *_setup will call lustre_get_mount to get the mnt struct
85 * by obd_name, since we can't pass the pointer to setup.
87 static int server_register_mount(const char *name, struct super_block *sb)
89 struct lustre_mount_info *lmi;
95 OBD_ALLOC(lmi, sizeof(*lmi));
98 OBD_ALLOC(name_cp, strlen(name) + 1);
100 OBD_FREE(lmi, sizeof(*lmi));
103 strcpy(name_cp, name);
105 mutex_lock(&lustre_mount_info_lock);
107 if (server_find_mount(name)) {
108 mutex_unlock(&lustre_mount_info_lock);
109 OBD_FREE(lmi, sizeof(*lmi));
110 OBD_FREE(name_cp, strlen(name) + 1);
111 CERROR("Already registered %s\n", name);
114 lmi->lmi_name = name_cp;
116 list_add(&lmi->lmi_list_chain, &server_mount_info_list);
118 mutex_unlock(&lustre_mount_info_lock);
120 CDEBUG(D_MOUNT, "register mount %p from %s\n", sb, name);
125 /* when an obd no longer needs a mount */
126 static int server_deregister_mount(const char *name)
128 struct lustre_mount_info *lmi;
131 mutex_lock(&lustre_mount_info_lock);
132 lmi = server_find_mount(name);
134 mutex_unlock(&lustre_mount_info_lock);
135 CERROR("%s not registered\n", name);
139 CDEBUG(D_MOUNT, "deregister mount %p from %s\n", lmi->lmi_sb, name);
141 OBD_FREE(lmi->lmi_name, strlen(lmi->lmi_name) + 1);
142 list_del(&lmi->lmi_list_chain);
143 OBD_FREE(lmi, sizeof(*lmi));
144 mutex_unlock(&lustre_mount_info_lock);
146 CFS_RACE(OBD_FAIL_MDS_LLOG_UMOUNT_RACE);
150 /* obd's look up a registered mount using their obdname. This is just
151 * for initial obd setup to find the mount struct. It should not be
152 * called every time you want to mntget.
154 struct lustre_mount_info *server_get_mount(const char *name)
156 struct lustre_mount_info *lmi;
157 struct lustre_sb_info *lsi;
160 mutex_lock(&lustre_mount_info_lock);
161 lmi = server_find_mount(name);
162 mutex_unlock(&lustre_mount_info_lock);
164 CERROR("Can't find mount for %s\n", name);
167 lsi = s2lsi(lmi->lmi_sb);
169 kref_get(&lsi->lsi_mounts);
171 CDEBUG(D_MOUNT, "get mount %p from %s, refs=%d\n", lmi->lmi_sb,
172 name, kref_read(&lsi->lsi_mounts));
176 EXPORT_SYMBOL(server_get_mount);
179 * server_put_mount: to be called from obd_cleanup methods
181 * @dereg_mnt: 0 or 1 depending on whether the mount is to be deregistered or
184 * The caller decides whether server_deregister_mount() needs to be called or
185 * not. Calling of server_deregister_mount() does not depend on refcounting on
186 * lsi because we could have say the mgs and mds on the same node and we
187 * unmount the mds, then the ref on the lsi would still be non-zero but we
188 * would still want to deregister the mds mount.
190 int server_put_mount(const char *name, bool dereg_mnt)
192 struct lustre_mount_info *lmi;
193 struct lustre_sb_info *lsi;
196 mutex_lock(&lustre_mount_info_lock);
197 lmi = server_find_mount(name);
198 mutex_unlock(&lustre_mount_info_lock);
200 CERROR("Can't find mount for %s\n", name);
203 lsi = s2lsi(lmi->lmi_sb);
205 CDEBUG(D_MOUNT, "put mount %p from %s, refs=%d\n",
206 lmi->lmi_sb, name, kref_read(&lsi->lsi_mounts));
208 if (lustre_put_lsi(lmi->lmi_sb))
209 CDEBUG(D_MOUNT, "Last put of mount %p from %s\n",
213 /* this obd should never need the mount again */
214 server_deregister_mount(name);
218 EXPORT_SYMBOL(server_put_mount);
220 /* Set up a MGS to serve startup logs */
221 static int server_start_mgs(struct super_block *sb)
223 struct lustre_sb_info *lsi = s2lsi(sb);
224 struct lustre_mount_info *lmi;
228 /* It is impossible to have more than 1 MGS per node, since
229 * MGC wouldn't know which to connect to
231 lmi = server_find_mount(LUSTRE_MGS_OBDNAME);
233 lsi = s2lsi(lmi->lmi_sb);
234 LCONSOLE_ERROR("The MGS service was already started from server\n");
238 CDEBUG(D_CONFIG, "Start MGS service %s\n", LUSTRE_MGS_OBDNAME);
240 rc = server_register_mount(LUSTRE_MGS_OBDNAME, sb);
242 GOTO(report_err, rc);
244 rc = lustre_start_simple(LUSTRE_MGS_OBDNAME, LUSTRE_MGS_NAME,
245 LUSTRE_MGS_OBDNAME, NULL, NULL,
246 lsi->lsi_osd_obdname, NULL);
247 /* server_deregister_mount() is not called previously, for lsi
248 * and other stuff can't be freed cleanly when mgs calls
249 * server_put_mount() in error handling case (see b=17758),
250 * this problem is caused by a bug in mgs_init0, which forgot
251 * calling server_put_mount in error case.
254 server_deregister_mount(LUSTRE_MGS_OBDNAME);
256 LCONSOLE_ERROR("Failed to start MGS '%s' (%d). Is the 'mgs' module loaded?\n",
257 LUSTRE_MGS_OBDNAME, rc);
262 static int server_stop_mgs(struct super_block *sb)
264 struct obd_device *obd;
266 struct lustre_mount_info *lmi;
269 /* Do not stop MGS if this device is not the running MGT */
270 lmi = server_find_mount(LUSTRE_MGS_OBDNAME);
271 if (lmi && lmi->lmi_sb != sb)
274 CDEBUG(D_MOUNT, "Stop MGS service %s\n", LUSTRE_MGS_OBDNAME);
276 /* There better be only one MGS */
277 obd = class_name2obd(LUSTRE_MGS_OBDNAME);
279 CDEBUG(D_CONFIG, "mgs %s not running\n", LUSTRE_MGS_OBDNAME);
283 /* The MGS should always stop when we say so */
285 rc = class_manual_cleanup(obd);
289 /* Since there's only one mgc per node, we have to change it's fs to get
290 * access to the right disk.
292 static int server_mgc_set_fs(const struct lu_env *env,
293 struct obd_device *mgc, struct super_block *sb)
295 struct lustre_sb_info *lsi = s2lsi(sb);
299 CDEBUG(D_MOUNT, "Set mgc disk for %s\n", lsi->lsi_lmd->lmd_dev);
301 /* cl_mgc_sem in mgc insures we sleep if the mgc_fs is busy */
302 rc = obd_set_info_async(env, mgc->obd_self_export,
303 sizeof(KEY_SET_FS), KEY_SET_FS,
304 sizeof(*sb), sb, NULL);
306 CERROR("can't set_fs %d\n", rc);
311 static int server_mgc_clear_fs(const struct lu_env *env,
312 struct obd_device *mgc)
317 CDEBUG(D_MOUNT, "Unassign mgc disk\n");
318 rc = obd_set_info_async(env, mgc->obd_self_export,
319 sizeof(KEY_CLEAR_FS), KEY_CLEAR_FS,
324 static inline bool is_mdc_device(const char *devname)
328 ptr = strrchr(devname, '-');
329 return ptr && strcmp(ptr, "-mdc") == 0;
332 static inline bool tgt_is_mdt(const char *tgtname, u32 *idx)
336 type = server_name2index(tgtname, idx, NULL);
338 return type == LDD_F_SV_TYPE_MDT;
342 * Convert OST/MDT name(fsname-{MDT,OST}xxxx) to a lwp name with the @idx:yyyy
343 * (fsname-MDTyyyy-lwp-{MDT,OST}xxxx)
345 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, u32 idx)
352 OBD_ALLOC(fsname, MTI_NAME_MAXLEN);
356 rc = server_name2fsname(tgt_name, fsname, &tgt);
358 CERROR("%s: failed to get fsname from tgt_name: rc = %d\n",
363 if (*tgt != '-' && *tgt != ':') {
364 CERROR("%s: invalid tgt_name name!\n", tgt_name);
365 GOTO(cleanup, rc = -EINVAL);
369 if (strncmp(tgt, "OST", 3) != 0 && strncmp(tgt, "MDT", 3) != 0) {
370 CERROR("%s is not an OST or MDT target!\n", tgt_name);
371 GOTO(cleanup, rc = -EINVAL);
373 snprintf(lwp_name, len, "%s-MDT%04x-%s-%s",
374 fsname, idx, LUSTRE_LWP_NAME, tgt);
376 GOTO(cleanup, rc = 0);
380 OBD_FREE(fsname, MTI_NAME_MAXLEN);
384 EXPORT_SYMBOL(tgt_name2lwp_name);
386 static LIST_HEAD(lwp_register_list);
387 static DEFINE_SPINLOCK(lwp_register_list_lock);
389 static void lustre_put_lwp_item(struct lwp_register_item *lri)
391 if (atomic_dec_and_test(&lri->lri_ref)) {
392 LASSERT(list_empty(&lri->lri_list));
395 class_export_put(*lri->lri_exp);
400 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
401 register_lwp_cb cb_func, void *cb_data)
403 struct obd_device *lwp;
404 struct lwp_register_item *lri;
408 LASSERTF(strlen(lwpname) < MTI_NAME_MAXLEN, "lwpname is too long %s\n",
410 LASSERT(exp && !*exp);
416 lwp = class_name2obd(lwpname);
417 if (lwp && lwp->obd_set_up == 1) {
418 struct obd_uuid *uuid;
425 memcpy(uuid->uuid, lwpname, strlen(lwpname));
426 *exp = obd_uuid_lookup(lwp, uuid);
430 memcpy(lri->lri_name, lwpname, strlen(lwpname));
432 lri->lri_cb_func = cb_func;
433 lri->lri_cb_data = cb_data;
434 INIT_LIST_HEAD(&lri->lri_list);
436 * Initialize the lri_ref at 2, one will be released before
437 * current function returned via lustre_put_lwp_item(), the
438 * other will be released in lustre_deregister_lwp_item().
440 atomic_set(&lri->lri_ref, 2);
442 spin_lock(&lwp_register_list_lock);
443 list_add(&lri->lri_list, &lwp_register_list);
446 spin_unlock(&lwp_register_list_lock);
450 lustre_put_lwp_item(lri);
454 EXPORT_SYMBOL(lustre_register_lwp_item);
456 void lustre_deregister_lwp_item(struct obd_export **exp)
458 struct lwp_register_item *lri;
459 bool removed = false;
462 spin_lock(&lwp_register_list_lock);
463 list_for_each_entry(lri, &lwp_register_list, lri_list) {
464 if (exp == lri->lri_exp) {
465 list_del_init(&lri->lri_list);
470 spin_unlock(&lwp_register_list_lock);
475 /* See lustre_notify_lwp_list(), in some extreme race conditions,
476 * the notify callback could be still on the fly, we need to wait
477 * for the callback done before moving on to free the data used
480 while (atomic_read(&lri->lri_ref) > 1) {
481 CDEBUG(D_MOUNT, "lri reference count %u, repeat: %d\n",
482 atomic_read(&lri->lri_ref), repeat);
484 schedule_timeout_interruptible(cfs_time_seconds(1));
486 lustre_put_lwp_item(lri);
488 EXPORT_SYMBOL(lustre_deregister_lwp_item);
490 struct obd_export *lustre_find_lwp_by_index(const char *dev, u32 idx)
492 struct lustre_mount_info *lmi;
493 struct lustre_sb_info *lsi;
494 struct obd_device *lwp;
495 struct obd_export *exp = NULL;
500 lmi = server_get_mount(dev);
504 lsi = s2lsi(lmi->lmi_sb);
505 rc = server_name2fsname(lsi->lsi_svname, fsname, NULL);
507 CERROR("%s: failed to get fsname: rc = %d\n",
508 lsi->lsi_svname, rc);
512 snprintf(lwp_name, sizeof(lwp_name), "%s-MDT%04x", fsname, idx);
513 mutex_lock(&lsi->lsi_lwp_mutex);
514 list_for_each_entry(lwp, &lsi->lsi_lwp_list, obd_lwp_list) {
515 char *ptr = strstr(lwp->obd_name, lwp_name);
517 if (ptr && lwp->obd_lwp_export) {
518 exp = class_export_get(lwp->obd_lwp_export);
522 mutex_unlock(&lsi->lsi_lwp_mutex);
525 server_put_mount(dev, false);
529 EXPORT_SYMBOL(lustre_find_lwp_by_index);
531 void lustre_notify_lwp_list(struct obd_export *exp)
533 struct lwp_register_item *lri;
537 spin_lock(&lwp_register_list_lock);
538 list_for_each_entry(lri, &lwp_register_list, lri_list) {
539 if (strcmp(exp->exp_obd->obd_name, lri->lri_name))
543 *lri->lri_exp = class_export_get(exp);
544 if (!lri->lri_cb_func)
546 atomic_inc(&lri->lri_ref);
547 spin_unlock(&lwp_register_list_lock);
549 lri->lri_cb_func(lri->lri_cb_data);
550 lustre_put_lwp_item(lri);
552 /* Others may have changed the list after we unlock, we have
553 * to rescan the list from the beginning. Usually, the list
554 * 'lwp_register_list' is very short, and there is 'guard'
555 * lri::lri_exp that will prevent the callback to be done
556 * repeatedly. So rescanning the list has no problem.
560 spin_unlock(&lwp_register_list_lock);
562 EXPORT_SYMBOL(lustre_notify_lwp_list);
564 static int lustre_lwp_connect(struct obd_device *lwp, bool is_mdt)
567 struct lu_context session_ctx;
568 struct obd_export *exp;
569 struct obd_uuid *uuid = NULL;
570 struct obd_connect_data *data = NULL;
574 /* log has been fully processed, let clients connect */
575 rc = lu_env_init(&env, lwp->obd_lu_dev->ld_type->ldt_ctx_tags);
579 lu_context_init(&session_ctx, LCT_SERVER_SESSION);
580 session_ctx.lc_thread = NULL;
581 lu_context_enter(&session_ctx);
582 env.le_ses = &session_ctx;
586 GOTO(out, rc = -ENOMEM);
588 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_INDEX;
589 data->ocd_version = LUSTRE_VERSION_CODE;
590 data->ocd_connect_flags |= OBD_CONNECT_FID | OBD_CONNECT_AT |
591 OBD_CONNECT_LRU_RESIZE | OBD_CONNECT_FULL20 |
592 OBD_CONNECT_LVB_TYPE | OBD_CONNECT_LIGHTWEIGHT |
593 OBD_CONNECT_LFSCK | OBD_CONNECT_BULK_MBITS;
596 data->ocd_connect_flags |= OBD_CONNECT_MDS_MDS;
600 GOTO(out, rc = -ENOMEM);
602 if (strlen(lwp->obd_name) > sizeof(uuid->uuid)) {
603 CERROR("%s: Too long lwp name %s, max_size is %d\n",
604 lwp->obd_name, lwp->obd_name, (int)sizeof(uuid->uuid));
605 GOTO(out, rc = -EINVAL);
608 /* Use lwp name as the uuid, so we find the export by lwp name later */
609 memcpy(uuid->uuid, lwp->obd_name, strlen(lwp->obd_name));
610 rc = obd_connect(&env, &exp, lwp, uuid, data, NULL);
612 CERROR("%s: connect failed: rc = %d\n", lwp->obd_name, rc);
614 if (unlikely(lwp->obd_lwp_export))
615 class_export_put(lwp->obd_lwp_export);
616 lwp->obd_lwp_export = class_export_get(exp);
628 lu_context_exit(&session_ctx);
629 lu_context_fini(&session_ctx);
635 * lwp is used by slaves (Non-MDT0 targets) to manage the connection to MDT0,
636 * or from the OSTx to MDTy.
638 static int lustre_lwp_setup(struct lustre_cfg *lcfg, struct lustre_sb_info *lsi,
641 struct obd_device *obd;
642 char *lwpname = NULL;
643 char *lwpuuid = NULL;
649 lnet_nid4_to_nid(lcfg->lcfg_nid, &nid);
651 rc = libcfs_strnid(&nid, lustre_cfg_string(lcfg, 2));
655 rc = class_add_uuid(lustre_cfg_string(lcfg, 1), &nid);
657 CERROR("%s: Can't add uuid: rc =%d\n", lsi->lsi_svname, rc);
661 OBD_ALLOC(lwpname, MTI_NAME_MAXLEN);
663 GOTO(out, rc = -ENOMEM);
665 rc = tgt_name2lwp_name(lsi->lsi_svname, lwpname, MTI_NAME_MAXLEN, idx);
667 CERROR("%s: failed to generate lwp name: rc = %d\n",
668 lsi->lsi_svname, rc);
672 OBD_ALLOC(lwpuuid, MTI_NAME_MAXLEN);
674 GOTO(out, rc = -ENOMEM);
676 sprintf(lwpuuid, "%s_UUID", lwpname);
677 rc = lustre_start_simple(lwpname, LUSTRE_LWP_NAME,
678 lwpuuid, lustre_cfg_string(lcfg, 1),
681 CERROR("%s: setup up failed: rc %d\n", lwpname, rc);
685 obd = class_name2obd(lwpname);
688 rc = lustre_lwp_connect(obd, strstr(lsi->lsi_svname, "-MDT") != NULL);
690 CERROR("%s: connect failed: rc = %d\n", lwpname, rc);
694 obd->u.cli.cl_max_mds_easize = MAX_MD_SIZE;
695 mutex_lock(&lsi->lsi_lwp_mutex);
696 list_add_tail(&obd->obd_lwp_list, &lsi->lsi_lwp_list);
697 mutex_unlock(&lsi->lsi_lwp_mutex);
700 OBD_FREE(lwpname, MTI_NAME_MAXLEN);
702 OBD_FREE(lwpuuid, MTI_NAME_MAXLEN);
707 /* the caller is responsible for memory free */
708 static struct obd_device *lustre_find_lwp(struct lustre_sb_info *lsi,
709 char **lwpname, u32 idx)
711 struct obd_device *lwp;
716 LASSERT(IS_OST(lsi) || IS_MDT(lsi));
718 OBD_ALLOC(*lwpname, MTI_NAME_MAXLEN);
719 if (*lwpname == NULL)
720 RETURN(ERR_PTR(-ENOMEM));
722 rc = tgt_name2lwp_name(lsi->lsi_svname, *lwpname, MTI_NAME_MAXLEN, idx);
724 CERROR("%s: failed to generate lwp name: rc = %d\n",
725 lsi->lsi_svname, rc);
726 GOTO(out, rc = -EINVAL);
729 lwp = class_name2obd(*lwpname);
733 if (*lwpname != NULL) {
734 OBD_FREE(*lwpname, MTI_NAME_MAXLEN);
740 RETURN(lwp ? lwp : ERR_PTR(-ENOENT));
743 static int lustre_lwp_add_conn(struct lustre_cfg *cfg,
744 struct lustre_sb_info *lsi, u32 idx)
746 struct lustre_cfg_bufs *bufs = NULL;
747 struct lustre_cfg *lcfg = NULL;
748 char *lwpname = NULL;
749 struct obd_device *lwp;
753 lwp = lustre_find_lwp(lsi, &lwpname, idx);
755 CERROR("%s: can't find lwp device.\n", lsi->lsi_svname);
756 GOTO(out, rc = PTR_ERR(lwp));
762 GOTO(out, rc = -ENOMEM);
764 lustre_cfg_bufs_reset(bufs, lwpname);
765 lustre_cfg_bufs_set_string(bufs, 1,
766 lustre_cfg_string(cfg, 1));
768 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
770 GOTO(out_cfg, rc = -ENOMEM);
771 lustre_cfg_init(lcfg, LCFG_ADD_CONN, bufs);
773 rc = class_add_conn(lwp, lcfg);
775 CERROR("%s: can't add conn: rc = %d\n", lwpname, rc);
778 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
779 lcfg->lcfg_buflens));
785 OBD_FREE(lwpname, MTI_NAME_MAXLEN);
790 * Retrieve MDT nids from the client log, then start the lwp device.
791 * there are only two scenarios which would include mdt nid.
793 * marker 5 (flags=0x01, v2.1.54.0) lustre-MDTyyyy 'add mdc' xxx-
794 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:192.168.122.162@tcp
795 * attach 0:lustre-MDTyyyy-mdc 1:mdc 2:lustre-clilmv_UUID
796 * setup 0:lustre-MDTyyyy-mdc 1:lustre-MDTyyyy_UUID 2:192.168.122.162@tcp
797 * add_uuid nid=192.168.172.1@tcp(0x20000c0a8ac01) 0: 1:192.168.172.1@tcp
798 * add_conn 0:lustre-MDTyyyy-mdc 1:192.168.172.1@tcp
799 * modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDTyyyy_UUID xxxx
800 * marker 5 (flags=0x02, v2.1.54.0) lustre-MDTyyyy 'add mdc' xxxx-
802 * marker 7 (flags=0x01, v2.1.54.0) lustre-MDTyyyy 'add failnid' xxxx-
803 * add_uuid nid=192.168.122.2@tcp(0x20000c0a87a02) 0: 1:192.168.122.2@tcp
804 * add_conn 0:lustre-MDTyyyy-mdc 1:192.168.122.2@tcp
805 * marker 7 (flags=0x02, v2.1.54.0) lustre-MDTyyyy 'add failnid' xxxx-
807 static int client_lwp_config_process(const struct lu_env *env,
808 struct llog_handle *handle,
809 struct llog_rec_hdr *rec, void *data)
811 struct config_llog_instance *cfg = data;
812 int cfg_len = rec->lrh_len;
813 char *cfg_buf = (char *) (rec + 1);
814 struct lustre_cfg *lcfg = NULL;
815 struct lustre_sb_info *lsi;
816 int rc = 0, swab = 0;
819 if (rec->lrh_type != OBD_CFG_REC) {
820 CERROR("Unknown llog record type %#x encountered\n",
826 GOTO(out, rc = -EINVAL);
827 lsi = s2lsi(cfg->cfg_sb);
829 lcfg = (struct lustre_cfg *)cfg_buf;
830 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
831 lustre_swab_lustre_cfg(lcfg);
835 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
839 switch (lcfg->lcfg_command) {
841 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
843 lustre_swab_cfg_marker(marker, swab,
844 LUSTRE_CFG_BUFLEN(lcfg, 1));
845 if (marker->cm_flags & CM_SKIP ||
846 marker->cm_flags & CM_EXCLUDE)
849 if (!tgt_is_mdt(marker->cm_tgtname, &cfg->cfg_lwp_idx))
852 if (IS_MDT(lsi) && cfg->cfg_lwp_idx != 0)
855 if (!strncmp(marker->cm_comment, "add mdc", 7) ||
856 !strncmp(marker->cm_comment, "add failnid", 11)) {
857 if (marker->cm_flags & CM_START) {
858 cfg->cfg_flags = CFG_F_MARKER;
859 /* This hack is to differentiate the
860 * ADD_UUID is come from "add mdc" record
861 * or from "add failnid" record.
863 if (!strncmp(marker->cm_comment,
865 cfg->cfg_flags |= CFG_F_SKIP;
866 } else if (marker->cm_flags & CM_END) {
872 case LCFG_ADD_UUID: {
873 if (cfg->cfg_flags == CFG_F_MARKER) {
874 rc = lustre_lwp_setup(lcfg, lsi, cfg->cfg_lwp_idx);
875 /* XXX: process only the first nid as
876 * we don't need another instance of lwp
878 cfg->cfg_flags |= CFG_F_SKIP;
879 } else if (cfg->cfg_flags == (CFG_F_MARKER | CFG_F_SKIP)) {
884 lnet_nid4_to_nid(lcfg->lcfg_nid, &nid);
886 rc = libcfs_strnid(&nid,
887 lustre_cfg_string(lcfg, 2));
889 rc = class_add_uuid(lustre_cfg_string(lcfg, 1),
892 CERROR("%s: Fail to add uuid, rc:%d\n",
893 lsi->lsi_svname, rc);
897 case LCFG_ADD_CONN: {
898 char *devname = lustre_cfg_string(lcfg, 0);
902 if (!is_mdc_device(devname))
905 if (!(cfg->cfg_flags & CFG_F_MARKER)) {
906 CDEBUG(D_CONFIG, "Skipping add_conn for %s, rec %d\n",
907 devname, rec->lrh_index);
911 /* add_conn should follow by add_uuid. This
912 * guarantee lwp device was created
914 if (!(cfg->cfg_flags & CFG_F_SKIP)) {
915 CWARN("Error at config for %s rec %d, add_conn should follow by add_uuid\n",
916 devname, rec->lrh_index);
919 ptr = strrchr(devname, '-');
924 if (!tgt_is_mdt(devname, &idx)) {
930 if (IS_MDT(lsi) && idx != 0)
933 rc = lustre_lwp_add_conn(lcfg, lsi, idx);
943 static int lustre_disconnect_lwp(struct super_block *sb)
945 struct lustre_sb_info *lsi = s2lsi(sb);
946 struct obd_device *lwp;
947 char *logname = NULL;
948 struct lustre_cfg_bufs *bufs = NULL;
949 struct config_llog_instance *cfg = NULL;
954 if (likely(lsi->lsi_lwp_started)) {
955 OBD_ALLOC(logname, MTI_NAME_MAXLEN);
959 rc = server_name2fsname(lsi->lsi_svname, logname, NULL);
961 CERROR("%s: failed to get fsname from svname: rc = %d\n",
962 lsi->lsi_svname, rc);
963 GOTO(out, rc = -EINVAL);
966 strcat(logname, "-client");
969 GOTO(out, rc = -ENOMEM);
972 cfg->cfg_instance = ll_get_cfg_instance(sb);
973 rc = lustre_end_log(sb, logname, cfg);
974 if (rc != 0 && rc != -ENOENT)
977 lsi->lsi_lwp_started = 0;
982 GOTO(out, rc = -ENOMEM);
984 mutex_lock(&lsi->lsi_lwp_mutex);
985 list_for_each_entry(lwp, &lsi->lsi_lwp_list, obd_lwp_list) {
986 struct lustre_cfg *lcfg;
988 if (likely(lwp->obd_lwp_export)) {
989 class_export_put(lwp->obd_lwp_export);
990 lwp->obd_lwp_export = NULL;
993 lustre_cfg_bufs_reset(bufs, lwp->obd_name);
994 lustre_cfg_bufs_set_string(bufs, 1, NULL);
995 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount,
1001 lustre_cfg_init(lcfg, LCFG_CLEANUP, bufs);
1003 /* Disconnect import first. NULL is passed for the '@env',
1004 * since it will not be used.
1006 rc = lwp->obd_lu_dev->ld_ops->ldo_process_config(NULL,
1007 lwp->obd_lu_dev, lcfg);
1008 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
1009 lcfg->lcfg_buflens));
1010 if (rc != 0 && rc != -ETIMEDOUT && rc != -ENODEV &&
1011 rc != -ENOTCONN && rc != -ESHUTDOWN) {
1012 CERROR("%s: fail to disconnect LWP: rc = %d\n",
1017 mutex_unlock(&lsi->lsi_lwp_mutex);
1027 OBD_FREE(logname, MTI_NAME_MAXLEN);
1029 return rc1 != 0 ? rc1 : rc;
1033 * Stop the lwp for an OST/MDT target.
1035 static int lustre_stop_lwp(struct super_block *sb)
1037 struct lustre_sb_info *lsi = s2lsi(sb);
1038 struct obd_device *lwp;
1043 mutex_lock(&lsi->lsi_lwp_mutex);
1044 while (!list_empty(&lsi->lsi_lwp_list)) {
1045 lwp = list_first_entry(&lsi->lsi_lwp_list, struct obd_device,
1047 list_del_init(&lwp->obd_lwp_list);
1049 mutex_unlock(&lsi->lsi_lwp_mutex);
1051 rc = class_manual_cleanup(lwp);
1053 CERROR("%s: fail to stop LWP: rc = %d\n",
1057 mutex_lock(&lsi->lsi_lwp_mutex);
1059 mutex_unlock(&lsi->lsi_lwp_mutex);
1061 RETURN(rc1 != 0 ? rc1 : rc);
1065 * Start the lwp(fsname-MDTyyyy-lwp-{MDT,OST}xxxx) for a MDT/OST or MDT target.
1067 static int lustre_start_lwp(struct super_block *sb)
1069 struct lustre_sb_info *lsi = s2lsi(sb);
1070 struct config_llog_instance *cfg = NULL;
1075 if (unlikely(lsi->lsi_lwp_started))
1078 OBD_ALLOC(logname, MTI_NAME_MAXLEN);
1079 if (logname == NULL)
1082 rc = server_name2fsname(lsi->lsi_svname, logname, NULL);
1084 CERROR("%s: failed to get fsname from svname: rc = %d\n",
1085 lsi->lsi_svname, rc);
1086 GOTO(out, rc = -EINVAL);
1089 strcat(logname, "-client");
1092 GOTO(out, rc = -ENOMEM);
1094 cfg->cfg_callback = client_lwp_config_process;
1095 cfg->cfg_instance = ll_get_cfg_instance(sb);
1096 rc = lustre_process_log(sb, logname, cfg);
1097 /* need to remove config llog from mgc */
1098 lsi->lsi_lwp_started = 1;
1103 OBD_FREE(logname, MTI_NAME_MAXLEN);
1110 static DEFINE_MUTEX(server_start_lock);
1112 /* Stop MDS/OSS if nobody is using them */
1113 static int server_stop_servers(int lsiflags)
1115 struct obd_device *obd = NULL;
1116 struct obd_type *type = NULL;
1121 mutex_lock(&server_start_lock);
1123 /* Either an MDT or an OST or neither */
1124 /* if this was an MDT, and there are no more MDT's, clean up the MDS */
1125 if (lsiflags & LDD_F_SV_TYPE_MDT) {
1126 obd = class_name2obd(LUSTRE_MDS_OBDNAME);
1127 type = class_search_type(LUSTRE_MDT_NAME);
1128 } else if (lsiflags & LDD_F_SV_TYPE_OST) {
1129 /* if this was an OST, and there are no more OST's, clean up the OSS */
1130 obd = class_name2obd(LUSTRE_OSS_OBDNAME);
1131 type = class_search_type(LUSTRE_OST_NAME);
1134 /* server_stop_servers is a pair of server_start_targets
1135 * Here we put type which was taken at server_start_targets.
1136 * If type is NULL then there is a wrong logic around type or
1139 LASSERTF(type, "Server flags %d, obd %s\n", lsiflags,
1140 obd ? obd->obd_name : "NULL");
1142 type_last = (atomic_read(&type->typ_refcnt) == 1);
1144 class_put_type(type);
1145 if (obd && type_last) {
1147 /* obd_fail doesn't mean much on a server obd */
1148 rc = class_manual_cleanup(obd);
1151 /* put reference taken by class_search_type */
1152 kobject_put(&type->typ_kobj);
1154 mutex_unlock(&server_start_lock);
1159 int server_mti_print(const char *title, struct mgs_target_info *mti)
1161 CDEBUG(D_MOUNT, "mti - %s\n", title);
1162 CDEBUG(D_MOUNT, "server: %s\n", mti->mti_svname);
1163 CDEBUG(D_MOUNT, "fs: %s\n", mti->mti_fsname);
1164 CDEBUG(D_MOUNT, "uuid: %s\n", mti->mti_uuid);
1165 CDEBUG(D_MOUNT, "ver: %d\n", mti->mti_config_ver);
1166 CDEBUG(D_MOUNT, "flags:\n");
1167 if (mti->mti_flags & LDD_F_SV_TYPE_MDT)
1168 CDEBUG(D_MOUNT, " LDD_F_SV_TYPE_MDT\n");
1169 if (mti->mti_flags & LDD_F_SV_TYPE_OST)
1170 CDEBUG(D_MOUNT, " LDD_F_SV_TYPE_OST\n");
1171 if (mti->mti_flags & LDD_F_SV_TYPE_MGS)
1172 CDEBUG(D_MOUNT, " LDD_F_SV_TYPE_MGS\n");
1173 if (mti->mti_flags & LDD_F_SV_ALL)
1174 CDEBUG(D_MOUNT, " LDD_F_SV_ALL\n");
1175 if (mti->mti_flags & LDD_F_NEED_INDEX)
1176 CDEBUG(D_MOUNT, " LDD_F_NEED_INDEX\n");
1177 if (mti->mti_flags & LDD_F_VIRGIN)
1178 CDEBUG(D_MOUNT, " LDD_F_VIRIGIN\n");
1179 if (mti->mti_flags & LDD_F_UPDATE)
1180 CDEBUG(D_MOUNT, " LDD_F_UPDATE\n");
1181 if (mti->mti_flags & LDD_F_REWRITE_LDD)
1182 CDEBUG(D_MOUNT, " LDD_F_REWRITE_LDD\n");
1183 if (mti->mti_flags & LDD_F_WRITECONF)
1184 CDEBUG(D_MOUNT, " LDD_F_WRITECONF\n");
1185 if (mti->mti_flags & LDD_F_PARAM)
1186 CDEBUG(D_MOUNT, " LDD_F_PARAM\n");
1187 if (mti->mti_flags & LDD_F_NO_PRIMNODE)
1188 CDEBUG(D_MOUNT, " LDD_F_NO_PRIMNODE\n");
1189 if (mti->mti_flags & LDD_F_IR_CAPABLE)
1190 CDEBUG(D_MOUNT, " LDD_F_IR_CAPABLE\n");
1191 if (mti->mti_flags & LDD_F_ERROR)
1192 CDEBUG(D_MOUNT, " LDD_F_ERROR\n");
1193 if (mti->mti_flags & LDD_F_PARAM2)
1194 CDEBUG(D_MOUNT, " LDD_F_PARAM2\n");
1195 if (mti->mti_flags & LDD_F_NO_LOCAL_LOGS)
1196 CDEBUG(D_MOUNT, " LDD_F_NO_LOCAL_LOGS\n");
1198 /* Upper 16 bits for target registering */
1199 if (target_supports_large_nid(mti))
1200 CDEBUG(D_MOUNT, " LDD_F_LARGE_NID\n");
1201 if (mti->mti_flags & LDD_F_OPC_REG)
1202 CDEBUG(D_MOUNT, " LDD_F_OPC_REG\n");
1203 if (mti->mti_flags & LDD_F_OPC_UNREG)
1204 CDEBUG(D_MOUNT, " LDD_F_OPC_UNREG\n");
1205 if (mti->mti_flags & LDD_F_OPC_READY)
1206 CDEBUG(D_MOUNT, " LDD_F_OPC_READY\n");
1210 EXPORT_SYMBOL(server_mti_print);
1212 /* Generate data for registration */
1213 static struct mgs_target_info *server_lsi2mti(struct lustre_sb_info *lsi)
1215 size_t len = offsetof(struct mgs_target_info, mti_nidlist);
1216 GENRADIX(struct lnet_processid) plist;
1217 struct lnet_processid id, *tmp;
1218 struct mgs_target_info *mti;
1219 bool large_nid = false;
1225 if (!IS_SERVER(lsi))
1226 RETURN(ERR_PTR(-EINVAL));
1228 if (exp_connect_flags2(lsi->lsi_mgc->u.cli.cl_mgc_mgsexp) &
1229 OBD_CONNECT2_LARGE_NID)
1232 genradix_init(&plist);
1234 while (LNetGetId(i++, &id, large_nid) != -ENOENT) {
1235 if (nid_is_lo0(&id.nid))
1238 /* server use --servicenode param, only allow specified
1239 * nids be registered
1241 if (test_bit(LMD_FLG_NO_PRIMNODE, lsi->lsi_lmd->lmd_flags) &&
1242 class_match_nid(lsi->lsi_lmd->lmd_params,
1243 PARAM_FAILNODE, &id.nid) < 1)
1246 if (!class_find_param(lsi->lsi_lmd->lmd_params,
1247 PARAM_NETWORK, NULL)) {
1248 if (LNetGetPeerDiscoveryStatus()) {
1249 CERROR("LNet Dynamic Peer Discovery is enabled"
1250 " on this node. 'network' option used in"
1251 " mkfs.lustre cannot be taken into"
1253 GOTO(free_list, mti = ERR_PTR(-EINVAL));
1257 /* match specified network */
1258 if (!class_match_net(lsi->lsi_lmd->lmd_params,
1259 PARAM_NETWORK, LNET_NID_NET(&id.nid)))
1262 tmp = genradix_ptr_alloc(&plist, nid_count++, GFP_KERNEL);
1264 GOTO(free_list, mti = ERR_PTR(-ENOMEM));
1267 len += LNET_NIDSTR_SIZE;
1271 if (nid_count == 0) {
1272 CERROR("Failed to get NID for server %s, please check whether the target is specifed with improper --servicenode or --network options.\n",
1274 GOTO(free_list, mti = ERR_PTR(-EINVAL));
1277 OBD_ALLOC(mti, len);
1279 GOTO(free_list, mti = ERR_PTR(-ENOMEM));
1281 rc = strscpy(mti->mti_svname, lsi->lsi_svname, sizeof(mti->mti_svname));
1285 mti->mti_nid_count = nid_count;
1286 for (i = 0; i < mti->mti_nid_count; i++) {
1287 tmp = genradix_ptr(&plist, i);
1290 libcfs_nidstr_r(&tmp->nid, mti->mti_nidlist[i],
1291 sizeof(mti->mti_nidlist[i]));
1293 mti->mti_nids[i] = lnet_nid_to_nid4(&tmp->nid);
1295 mti->mti_lustre_ver = LUSTRE_VERSION_CODE;
1296 mti->mti_config_ver = 0;
1298 rc = server_name2fsname(lsi->lsi_svname, mti->mti_fsname, NULL);
1302 rc = server_name2index(lsi->lsi_svname, &mti->mti_stripe_index, NULL);
1306 /* Orion requires index to be set */
1307 LASSERT(!(rc & LDD_F_NEED_INDEX));
1308 /* keep only LDD flags */
1309 mti->mti_flags = lsi->lsi_flags & LDD_F_MASK;
1310 if (mti->mti_flags & (LDD_F_WRITECONF | LDD_F_VIRGIN))
1311 mti->mti_flags |= LDD_F_UPDATE;
1312 /* use NID strings instead */
1314 mti->mti_flags |= LDD_F_LARGE_NID;
1315 cplen = strscpy(mti->mti_params, lsi->lsi_lmd->lmd_params,
1316 sizeof(mti->mti_params));
1317 if (cplen >= sizeof(mti->mti_params))
1325 genradix_free(&plist);
1330 /* Register an old or new target with the MGS. If needed MGS will construct
1331 * startup logs and assign index
1333 static int server_register_target(struct lustre_sb_info *lsi)
1335 struct obd_device *mgc = lsi->lsi_mgc;
1336 struct mgs_target_info *mti = NULL;
1337 size_t mti_len = sizeof(*mti);
1344 mti = server_lsi2mti(lsi);
1346 GOTO(out, rc = PTR_ERR(mti));
1348 CDEBUG(D_MOUNT, "Registration %s, fs=%s, %s, index=%04x, flags=%#x\n",
1349 mti->mti_svname, mti->mti_fsname, mti->mti_nidlist[0],
1350 mti->mti_stripe_index, mti->mti_flags);
1352 /* we cannot ignore registration failure if MGS logs must be updated. */
1353 must_succeed = !!(lsi->lsi_flags &
1354 (LDD_F_NEED_INDEX | LDD_F_UPDATE | LDD_F_WRITECONF |
1356 mti->mti_flags |= LDD_F_OPC_REG;
1357 if (target_supports_large_nid(mti))
1358 mti_len += mti->mti_nid_count * LNET_NIDSTR_SIZE;
1359 server_mti_print("server_register_target", mti);
1361 /* Register the target */
1362 /* FIXME use mgc_process_config instead */
1363 rc = obd_set_info_async(NULL, mgc->u.cli.cl_mgc_mgsexp,
1364 sizeof(KEY_REGISTER_TARGET),
1365 KEY_REGISTER_TARGET,
1366 mti_len, mti, NULL);
1368 if (mti->mti_flags & LDD_F_ERROR) {
1369 LCONSOLE_ERROR("%s: the MGS refuses to allow this server to start: rc = %d. Please see messages on the MGS.\n",
1370 lsi->lsi_svname, rc);
1371 } else if (must_succeed) {
1372 if ((rc == -ESHUTDOWN || rc == -EIO) && ++tried < 5) {
1373 /* The connection with MGS is not established.
1374 * Try again after 2 seconds. Interruptable.
1376 schedule_timeout_interruptible(cfs_time_seconds(2));
1377 if (!signal_pending(current))
1381 LCONSOLE_ERROR("%s: cannot register this server with the MGS: rc = %d. Is the MGS running?\n",
1382 lsi->lsi_svname, rc);
1385 "%s: error registering with the MGS: rc = %d (not fatal)\n",
1386 lsi->lsi_svname, rc);
1387 /* reset the error code for non-fatal error. */
1392 OBD_FREE(mti, mti_len);
1398 * Notify the MGS that this target is ready.
1399 * Used by IR - if the MGS receives this message, it will notify clients.
1401 static int server_notify_target(struct super_block *sb, struct obd_device *obd)
1403 struct lustre_sb_info *lsi = s2lsi(sb);
1404 struct obd_device *mgc = lsi->lsi_mgc;
1405 struct mgs_target_info *mti = NULL;
1406 size_t mti_len = sizeof(*mti);
1411 mti = server_lsi2mti(lsi);
1413 GOTO(out, rc = PTR_ERR(mti));
1415 mti->mti_instance = obd2obt(obd)->obt_instance;
1416 mti->mti_flags |= LDD_F_OPC_READY;
1417 if (target_supports_large_nid(mti))
1418 mti_len += mti->mti_nid_count * LNET_NIDSTR_SIZE;
1419 server_mti_print("server_notify_target", mti);
1421 /* FIXME use mgc_process_config instead */
1422 rc = obd_set_info_async(NULL, mgc->u.cli.cl_mgc_mgsexp,
1423 sizeof(KEY_REGISTER_TARGET),
1424 KEY_REGISTER_TARGET,
1425 mti_len, mti, NULL);
1427 /* Imperative recovery: if the mgs informs us to use IR? */
1428 if (!rc && !(mti->mti_flags & LDD_F_ERROR) &&
1429 (mti->mti_flags & LDD_F_IR_CAPABLE))
1430 lsi->lsi_flags |= LDD_F_IR_CAPABLE;
1432 OBD_FREE(mti, mti_len);
1437 /* Start server targets: MDTs and OSTs */
1438 static int server_start_targets(struct super_block *sb)
1440 struct obd_device *obd;
1441 struct lustre_sb_info *lsi = s2lsi(sb);
1442 struct config_llog_instance cfg;
1443 struct lu_env mgc_env;
1444 struct lu_device *dev;
1445 char *name_service, *obd_name_service = NULL;
1446 struct obd_type *type = NULL;
1450 CDEBUG(D_MOUNT, "starting target %s\n", lsi->lsi_svname);
1452 LASSERTF(IS_MDT(lsi) || IS_OST(lsi), "designed for MDT or OST only\n");
1455 obd_name_service = LUSTRE_MDS_OBDNAME;
1456 name_service = LUSTRE_MDS_NAME;
1458 obd_name_service = LUSTRE_OSS_OBDNAME;
1459 name_service = LUSTRE_OSS_NAME;
1462 /* make sure MDS/OSS is started */
1463 mutex_lock(&server_start_lock);
1464 obd = class_name2obd(obd_name_service);
1466 rc = lustre_start_simple(obd_name_service, name_service,
1468 LUSTRE_MDS_OBDNAME"_uuid" :
1469 LUSTRE_OSS_OBDNAME"_uuid"),
1470 NULL, NULL, NULL, NULL);
1472 mutex_unlock(&server_start_lock);
1473 CERROR("failed to start %s: %d\n",
1474 obd_name_service, rc);
1478 /* hold a type reference and put it at server_stop_servers */
1479 type = class_get_type(IS_MDT(lsi) ?
1480 LUSTRE_MDT_NAME : LUSTRE_OST_NAME);
1482 mutex_unlock(&server_start_lock);
1483 GOTO(out_stop_service, rc = -ENODEV);
1485 lsi->lsi_server_started = 1;
1486 mutex_unlock(&server_start_lock);
1487 if (CFS_FAIL_PRECHECK(OBD_FAIL_OBD_STOP_MDS_RACE) &&
1489 CFS_RACE(OBD_FAIL_OBD_STOP_MDS_RACE);
1490 msleep(2 * MSEC_PER_SEC);
1493 rc = lu_env_init(&mgc_env, LCT_MG_THREAD);
1495 GOTO(out_stop_service, rc);
1497 /* Set the mgc fs to our server disk. This allows the MGC to
1498 * read and write configs locally, in case it can't talk to the MGS.
1500 rc = server_mgc_set_fs(&mgc_env, lsi->lsi_mgc, sb);
1504 /* Register with MGS */
1505 rc = server_register_target(lsi);
1509 /* Let the target look up the mount using the target's name
1510 * (we can't pass the sb or mnt through class_process_config.)
1512 rc = server_register_mount(lsi->lsi_svname, sb);
1516 /* Start targets using the llog named for the target */
1517 memset(&cfg, 0, sizeof(cfg));
1518 cfg.cfg_callback = class_config_llog_handler;
1519 cfg.cfg_sub_clds = CONFIG_SUB_SERVER;
1520 rc = lustre_process_log(sb, lsi->lsi_svname, &cfg);
1522 CERROR("failed to start server %s: %d\n",
1523 lsi->lsi_svname, rc);
1524 /* Do NOT call server_deregister_mount() here. This makes it
1525 * impossible to find mount later in cleanup time and leaves
1526 * @lsi and othder stuff leaked. -umka
1531 obd = class_name2obd(lsi->lsi_svname);
1533 CERROR("no server named %s was started\n", lsi->lsi_svname);
1534 GOTO(out_mgc, rc = -ENXIO);
1537 if (IS_OST(lsi) || IS_MDT(lsi)) {
1538 rc = lustre_start_lwp(sb);
1540 CERROR("%s: failed to start LWP: %d\n",
1541 lsi->lsi_svname, rc);
1546 server_notify_target(sb, obd);
1548 /* calculate recovery timeout, do it after lustre_process_log */
1549 server_calc_timeout(lsi, obd);
1551 /* log has been fully processed, let clients connect */
1552 dev = obd->obd_lu_dev;
1553 if (dev && dev->ld_ops->ldo_prepare) {
1556 rc = lu_env_init(&env, dev->ld_type->ldt_ctx_tags);
1558 struct lu_context session_ctx;
1560 lu_context_init(&session_ctx, LCT_SERVER_SESSION);
1561 session_ctx.lc_thread = NULL;
1562 lu_context_enter(&session_ctx);
1563 env.le_ses = &session_ctx;
1565 rc = dev->ld_ops->ldo_prepare(&env, NULL, dev);
1568 lu_context_exit(&session_ctx);
1569 lu_context_fini(&session_ctx);
1573 /* abort recovery only on the complete stack:
1574 * many devices can be involved
1576 if ((test_bit(LMD_FLG_ABORT_RECOV, lsi->lsi_lmd->lmd_flags) ||
1577 (test_bit(LMD_FLG_ABORT_RECOV_MDT, lsi->lsi_lmd->lmd_flags))) &&
1578 (obd->obd_type->typ_dt_ops->o_iocontrol)) {
1579 struct obd_ioctl_data karg;
1581 if (test_bit(LMD_FLG_ABORT_RECOV, lsi->lsi_lmd->lmd_flags))
1582 karg.ioc_type = OBD_FLG_ABORT_RECOV_OST;
1584 karg.ioc_type = OBD_FLG_ABORT_RECOV_MDT;
1586 obd_iocontrol(OBD_IOC_ABORT_RECOVERY, obd->obd_self_export, 0,
1591 /* Release the mgc fs for others to use */
1592 server_mgc_clear_fs(&mgc_env, lsi->lsi_mgc);
1594 lu_env_fini(&mgc_env);
1596 /* in case of error upper function call
1597 * server_put_super->server_stop_servers()
1603 static int lsi_prepare(struct lustre_sb_info *lsi)
1605 const char *osd_type;
1612 LASSERT(lsi->lsi_lmd);
1614 /* The server name is given as a mount line option */
1615 if (!lsi->lsi_lmd->lmd_profile) {
1616 LCONSOLE_ERROR("Can't determine server name\n");
1620 /* Determine osd type */
1621 if (!lsi->lsi_lmd->lmd_osd_type) {
1622 osd_type = LUSTRE_OSD_LDISKFS_NAME;
1625 osd_type = lsi->lsi_lmd->lmd_osd_type;
1626 fstype = lsi->lsi_lmd->lmd_osd_type;
1629 if (strlen(lsi->lsi_lmd->lmd_profile) >= sizeof(lsi->lsi_svname) ||
1630 strlen(osd_type) >= sizeof(lsi->lsi_osd_type) ||
1631 strlen(fstype) >= sizeof(lsi->lsi_fstype))
1632 RETURN(-ENAMETOOLONG);
1634 strscpy(lsi->lsi_svname, lsi->lsi_lmd->lmd_profile,
1635 sizeof(lsi->lsi_svname));
1636 strscpy(lsi->lsi_osd_type, osd_type, sizeof(lsi->lsi_osd_type));
1637 /* XXX: a temp. solution for components using ldiskfs
1638 * to be removed in one of the subsequent patches
1640 strscpy(lsi->lsi_fstype, fstype, sizeof(lsi->lsi_fstype));
1642 /* Determine server type */
1643 rc = server_name2index(lsi->lsi_svname, &index, NULL);
1645 if (test_bit(LMD_FLG_MGS, lsi->lsi_lmd->lmd_flags)) {
1646 /* Assume we're a bare MGS */
1648 set_bit(LMD_FLG_NOSVC, lsi->lsi_lmd->lmd_flags);
1650 LCONSOLE_ERROR("Can't determine server type of '%s'\n",
1655 lsi->lsi_flags |= rc;
1657 /* Add mount line flags that used to be in ldd:
1658 * writeconf, mgs, anything else?
1660 lsi->lsi_flags |= test_bit(LMD_FLG_WRITECONF, lsi->lsi_lmd->lmd_flags) ?
1661 LDD_F_WRITECONF : 0;
1662 lsi->lsi_flags |= test_bit(LMD_FLG_NO_LOCAL_LOGS, lsi->lsi_lmd->lmd_flags) ?
1663 LDD_F_NO_LOCAL_LOGS : 0;
1664 lsi->lsi_flags |= test_bit(LMD_FLG_VIRGIN, lsi->lsi_lmd->lmd_flags) ?
1666 lsi->lsi_flags |= test_bit(LMD_FLG_UPDATE, lsi->lsi_lmd->lmd_flags) ?
1668 lsi->lsi_flags |= test_bit(LMD_FLG_MGS, lsi->lsi_lmd->lmd_flags) ?
1669 LDD_F_SV_TYPE_MGS : 0;
1670 lsi->lsi_flags |= test_bit(LMD_FLG_NO_PRIMNODE, lsi->lsi_lmd->lmd_flags) ?
1671 LDD_F_NO_PRIMNODE : 0;
1676 /*************** server mount ******************/
1678 /** Start the shutdown of servers at umount.
1680 static void server_put_super(struct super_block *sb)
1682 struct lustre_sb_info *lsi = s2lsi(sb);
1683 struct obd_device *obd;
1684 char *tmpname, *extraname = NULL;
1686 int lsiflags = lsi->lsi_flags;
1687 bool stop_servers = lsi->lsi_server_started;
1690 LASSERT(IS_SERVER(lsi));
1692 tmpname_sz = strlen(lsi->lsi_svname) + 1;
1693 OBD_ALLOC(tmpname, tmpname_sz);
1694 memcpy(tmpname, lsi->lsi_svname, tmpname_sz);
1695 CDEBUG(D_MOUNT, "server put_super %s\n", tmpname);
1696 if (IS_MDT(lsi) && test_bit(LMD_FLG_NOSVC, lsi->lsi_lmd->lmd_flags))
1697 snprintf(tmpname, tmpname_sz, "MGS");
1699 /* disconnect the lwp first to drain off the inflight request */
1700 if (IS_OST(lsi) || IS_MDT(lsi)) {
1703 rc = lustre_disconnect_lwp(sb);
1704 if (rc != 0 && rc != -ETIMEDOUT && rc != -ENODEV &&
1705 rc != -ENOTCONN && rc != -ESHUTDOWN)
1706 CWARN("%s: failed to disconnect lwp: rc= %d\n",
1710 /* Stop the target */
1711 if (!test_bit(LMD_FLG_NOSVC, lsi->lsi_lmd->lmd_flags) &&
1712 (IS_MDT(lsi) || IS_OST(lsi))) {
1713 struct lustre_profile *lprof = NULL;
1715 /* tell the mgc to drop the config log */
1716 lustre_end_log(sb, lsi->lsi_svname, NULL);
1718 /* COMPAT_146 - profile may get deleted in mgc_cleanup.
1719 * If there are any setup/cleanup errors, save the lov
1720 * name for safety cleanup later.
1722 lprof = class_get_profile(lsi->lsi_svname);
1725 OBD_ALLOC(extraname, strlen(lprof->lp_dt) + 1);
1726 strncpy(extraname, lprof->lp_dt,
1727 strlen(lprof->lp_dt) + 1);
1729 class_put_profile(lprof);
1732 obd = class_name2obd(lsi->lsi_svname);
1734 CDEBUG(D_MOUNT, "stopping %s\n", obd->obd_name);
1735 if (lsiflags & LSI_UMOUNT_FAILOVER)
1737 /* We can't seem to give an error return code
1738 * to .put_super, so we better make sure we clean up!
1741 class_manual_cleanup(obd);
1742 if (CFS_FAIL_PRECHECK(OBD_FAIL_OBD_STOP_MDS_RACE)) {
1745 server_name2index(lsi->lsi_svname, &idx, NULL);
1746 /* sleeping for MDT0001 */
1748 CFS_RACE(OBD_FAIL_OBD_STOP_MDS_RACE);
1751 CERROR("no obd %s\n", lsi->lsi_svname);
1752 server_deregister_mount(lsi->lsi_svname);
1756 /* If they wanted the mgs to stop separately from the mdt, they
1757 * should have put it on a different device.
1759 lustre_stop_mgc(sb);
1761 /* if MDS start with --nomgs, don't stop MGS then */
1762 if (!test_bit(LMD_FLG_NOMGS, lsi->lsi_lmd->lmd_flags))
1763 server_stop_mgs(sb);
1766 if (IS_OST(lsi) || IS_MDT(lsi)) {
1767 if (lustre_stop_lwp(sb) < 0)
1768 CERROR("%s: failed to stop lwp!\n", tmpname);
1771 /* Drop a ref to the mounted disk */
1774 /* wait till all in-progress cleanups are done
1775 * specifically we're interested in ofd cleanup
1778 obd_zombie_barrier();
1780 /* Stop the servers (MDS, OSS) if no longer needed. We must wait
1781 * until the target is really gone so that our type refcount check
1785 server_stop_servers(lsiflags);
1787 /* In case of startup or cleanup err, stop related obds */
1789 obd = class_name2obd(extraname);
1791 CWARN("Cleaning orphaned obd %s\n", extraname);
1793 class_manual_cleanup(obd);
1795 OBD_FREE(extraname, strlen(extraname) + 1);
1798 LCONSOLE(D_WARNING, "server umount %s complete\n", tmpname);
1799 OBD_FREE(tmpname, tmpname_sz);
1803 /* Called only for 'umount -f' */
1804 static void server_umount_begin(struct super_block *sb)
1806 struct lustre_sb_info *lsi = s2lsi(sb);
1809 CDEBUG(D_MOUNT, "umount -f\n");
1810 /* umount = failover
1812 * no third way to do non-force, non-failover
1814 lsi->lsi_flags &= ~LSI_UMOUNT_FAILOVER;
1818 static int server_statfs(struct dentry *dentry, struct kstatfs *buf)
1820 struct super_block *sb = dentry->d_sb;
1821 struct lustre_sb_info *lsi = s2lsi(sb);
1822 struct obd_statfs statfs;
1826 if (lsi->lsi_dt_dev) {
1827 rc = dt_statfs(NULL, lsi->lsi_dt_dev, &statfs);
1829 statfs_unpack(buf, &statfs);
1830 buf->f_type = sb->s_magic;
1836 buf->f_type = sb->s_magic;
1837 buf->f_bsize = sb->s_blocksize;
1843 buf->f_namelen = NAME_MAX;
1847 static int server_show_options(struct seq_file *seq, struct dentry *dentry)
1849 struct lustre_sb_info *lsi;
1850 struct lustre_mount_data *lmd;
1851 struct obd_statfs osfs;
1852 struct super_block *sb;
1855 LASSERT(seq && dentry);
1856 lsi = s2lsi(dentry->d_sb);
1860 if (lsi->lsi_dt_dev) {
1861 rc = dt_statfs(NULL, lsi->lsi_dt_dev, &osfs);
1863 /* Check FS State for OS_STATFS_READONLY
1864 * (Read only) flag. If it is not set then
1865 * toggle back the s_flag's SB_RDONLY bit.
1866 * The SB_RDONLY bit is always set for OST/MDT
1867 * during server prep (server_fill_super_common())
1870 * Also, if server is mounted with "rdonly_dev"
1871 * (LMD_FLG_DEV_RDONLY) then force flag to be 'ro'
1873 if (!test_bit(LMD_FLG_DEV_RDONLY, lmd->lmd_flags) &&
1874 !(osfs.os_state & OS_STATFS_READONLY))
1875 sb->s_flags &= ~SB_RDONLY;
1879 seq_printf(seq, ",svname=%s", lmd->lmd_profile);
1881 if (test_bit(LMD_FLG_ABORT_RECOV, lmd->lmd_flags))
1882 seq_puts(seq, ",abort_recov");
1884 if (test_bit(LMD_FLG_NOIR, lmd->lmd_flags))
1885 seq_puts(seq, ",noir");
1887 if (test_bit(LMD_FLG_NOSVC, lmd->lmd_flags))
1888 seq_puts(seq, ",nosvc");
1890 if (test_bit(LMD_FLG_NOMGS, lmd->lmd_flags))
1891 seq_puts(seq, ",nomgs");
1893 if (test_bit(LMD_FLG_NOSCRUB, lmd->lmd_flags))
1894 seq_puts(seq, ",noscrub");
1896 if (test_bit(LMD_FLG_SKIP_LFSCK, lmd->lmd_flags))
1897 seq_puts(seq, ",skip_lfsck");
1899 if (test_bit(LMD_FLG_DEV_RDONLY, lmd->lmd_flags))
1900 seq_puts(seq, ",rdonly_dev");
1902 if (test_bit(LMD_FLG_MGS, lmd->lmd_flags))
1903 seq_puts(seq, ",mgs");
1906 seq_printf(seq, ",mgsnode=%s", lmd->lmd_mgs);
1908 if (lmd->lmd_osd_type)
1909 seq_printf(seq, ",osd=%s", lmd->lmd_osd_type);
1911 if (lmd->lmd_opts) {
1913 seq_puts(seq, lmd->lmd_opts);
1919 /** The operations we support directly on the superblock:
1920 * mount, umount, and df.
1922 static const struct super_operations server_ops = {
1923 .put_super = server_put_super,
1924 .umount_begin = server_umount_begin, /* umount -f */
1925 .statfs = server_statfs,
1926 .show_options = server_show_options,
1929 #if defined(HAVE_USER_NAMESPACE_ARG)
1930 # define IDMAP_ARG idmap,
1933 # ifdef HAVE_INODEOPS_ENHANCED_GETATTR
1934 # define server_getattr(ns, path, st, rq, fl) server_getattr(path, st, rq, fl)
1939 * inode operations for Lustre server mountpoints
1941 #if defined(HAVE_USER_NAMESPACE_ARG) || defined(HAVE_INODEOPS_ENHANCED_GETATTR)
1942 static int server_getattr(struct mnt_idmap *idmap,
1943 const struct path *path, struct kstat *stat,
1944 u32 request_mask, unsigned int flags)
1946 struct inode *inode = d_inode(path->dentry);
1948 static int server_getattr(struct vfsmount *mnt, struct dentry *de,
1951 struct inode *inode = de->d_inode;
1953 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
1954 struct vfsmount *root_mnt;
1955 struct inode *root_inode;
1957 root_mnt = dt_mnt_get(lsi->lsi_dt_dev);
1958 if (IS_ERR(root_mnt))
1959 root_inode = igrab(inode);
1961 root_inode = igrab(root_mnt->mnt_sb->s_root->d_inode);
1965 CDEBUG(D_SUPER, "%s: root_inode from %s ino=%lu, dev=%x\n",
1966 lsi->lsi_svname, root_inode == inode ? "lsi" : "vfsmnt",
1967 root_inode->i_ino, root_inode->i_rdev);
1968 generic_fillattr(IDMAP_ARG RQMASK_ARG root_inode, stat);
1974 #ifdef HAVE_IOP_XATTR
1975 static ssize_t server_getxattr(struct dentry *dentry, const char *name,
1976 void *buffer, size_t size)
1978 if (!selinux_is_enabled())
1983 static int server_setxattr(struct dentry *dentry, const char *name,
1984 const void *value, size_t size, int flags)
1990 static ssize_t server_listxattr(struct dentry *d_entry, char *name,
1996 static bool is_cmd_supported(unsigned int cmd)
1998 CDEBUG(D_SUPER, "ioctl cmd=%x\n", cmd);
2003 case LL_IOC_RESIZE_FS:
2006 case FS_IOC_GETFSMAP:
2016 static long server_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2018 struct lustre_sb_info *lsi = s2lsi(file_inode(filp)->i_sb);
2019 struct vfsmount *root_mnt;
2020 struct file *root_filp;
2021 struct inode *root_inode;
2024 if (!is_cmd_supported(cmd))
2027 root_mnt = dt_mnt_get(lsi->lsi_dt_dev);
2028 if (IS_ERR(root_mnt))
2031 root_inode = igrab(root_mnt->mnt_root->d_inode);
2035 root_filp = alloc_file_pseudo(root_inode, root_mnt, "/",
2036 O_RDWR | O_NOATIME, root_inode->i_fop);
2037 if (root_inode->i_fop && root_inode->i_fop->unlocked_ioctl)
2038 err = root_inode->i_fop->unlocked_ioctl(root_filp, cmd, arg);
2044 static const struct inode_operations server_inode_operations = {
2045 .getattr = server_getattr,
2046 #ifdef HAVE_IOP_XATTR
2047 .setxattr = server_setxattr,
2048 .getxattr = server_getxattr,
2050 .listxattr = server_listxattr,
2053 static const struct file_operations server_file_operations = {
2054 .unlocked_ioctl = server_ioctl,
2057 #define log2(n) ffz(~(n))
2058 #define LUSTRE_SUPER_MAGIC 0x0BD00BD1
2060 static int server_fill_super_common(struct super_block *sb)
2062 struct inode *root = NULL;
2065 CDEBUG(D_MOUNT, "Server sb, dev=%d\n", (int)sb->s_dev);
2067 sb->s_blocksize = 4096;
2068 sb->s_blocksize_bits = log2(sb->s_blocksize);
2069 sb->s_magic = LUSTRE_SUPER_MAGIC;
2070 sb->s_maxbytes = 0; /* we don't allow file IO on server mountpoints */
2071 sb->s_flags |= SB_RDONLY;
2072 sb->s_op = &server_ops;
2074 root = new_inode(sb);
2076 CERROR("Can't make root inode\n");
2080 /* returns -EIO for every operation */
2081 /* make_bad_inode(root); -- badness - can't umount */
2082 /* apparently we need to be a directory for the mount to finish */
2083 root->i_mode = S_IFDIR;
2084 root->i_op = &server_inode_operations;
2085 root->i_fop = &server_file_operations;
2086 sb->s_root = d_make_root(root);
2088 CERROR("%s: can't make root dentry\n", sb->s_id);
2095 static int osd_start(struct lustre_sb_info *lsi, unsigned long mflags)
2097 struct lustre_mount_data *lmd = lsi->lsi_lmd;
2098 struct obd_device *obd;
2099 struct dt_device_param p;
2100 char flagstr[20 + 1 + 10 + 1];
2106 "Attempting to start %s, type=%s, lsifl=%x, mountfl=%lx\n",
2107 lsi->lsi_svname, lsi->lsi_osd_type, lsi->lsi_flags, mflags);
2109 sprintf(lsi->lsi_osd_obdname, "%s-osd", lsi->lsi_svname);
2110 strcpy(lsi->lsi_osd_uuid, lsi->lsi_osd_obdname);
2111 strcat(lsi->lsi_osd_uuid, "_UUID");
2112 bitmap_to_arr32(&lmd_flags, lmd->lmd_flags, LMD_FLG_NUM_FLAGS);
2113 snprintf(flagstr, sizeof(flagstr), "%lu:%u", mflags, lmd_flags);
2115 obd = class_name2obd(lsi->lsi_osd_obdname);
2117 rc = lustre_start_simple(lsi->lsi_osd_obdname,
2119 lsi->lsi_osd_uuid, lmd->lmd_dev,
2120 flagstr, lsi->lsi_lmd->lmd_opts,
2124 obd = class_name2obd(lsi->lsi_osd_obdname);
2127 CDEBUG(D_MOUNT, "%s already started\n", lsi->lsi_osd_obdname);
2128 /* but continue setup to allow special case of MDT and internal
2129 * MGT being started separately.
2131 if (!((IS_MGS(lsi) &&
2132 test_bit(LMD_FLG_NOMGS, lsi->lsi_lmd->lmd_flags)) ||
2134 test_bit(LMD_FLG_NOSVC, lsi->lsi_lmd->lmd_flags))))
2138 rc = obd_connect(NULL, &lsi->lsi_osd_exp,
2139 obd, &obd->obd_uuid, NULL, NULL);
2143 class_manual_cleanup(obd);
2144 lsi->lsi_dt_dev = NULL;
2148 LASSERT(obd->obd_lu_dev);
2149 lu_device_get(obd->obd_lu_dev);
2150 lsi->lsi_dt_dev = lu2dt_dev(obd->obd_lu_dev);
2151 LASSERT(lsi->lsi_dt_dev);
2153 /* set disk context for llog usage */
2154 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
2155 obd->obd_lvfs_ctxt.dt = lsi->lsi_dt_dev;
2157 dt_conf_get(NULL, lsi->lsi_dt_dev, &p);
2162 /** Fill in the superblock info for a Lustre server.
2163 * Mount the device with the correct options.
2164 * Read the on-disk config file.
2165 * Start the services.
2167 int server_fill_super(struct super_block *sb)
2169 struct lustre_sb_info *lsi = s2lsi(sb);
2173 /* to simulate target mount race */
2174 CFS_RACE(OBD_FAIL_TGT_MOUNT_RACE);
2176 rc = lsi_prepare(lsi);
2182 /* Start low level OSD */
2183 rc = osd_start(lsi, sb->s_flags);
2185 CERROR("Unable to start osd on %s: %d\n",
2186 lsi->lsi_lmd->lmd_dev, rc);
2191 CDEBUG(D_MOUNT, "Found service %s on device %s\n",
2192 lsi->lsi_svname, lsi->lsi_lmd->lmd_dev);
2194 if (class_name2obd(lsi->lsi_svname)) {
2195 LCONSOLE_ERROR("The target named %s is already running. Double-mount may have compromised the disk journal.\n",
2201 /* Start MGS before MGC */
2202 if (IS_MGS(lsi) && !test_bit(LMD_FLG_NOMGS, lsi->lsi_lmd->lmd_flags)) {
2203 rc = server_start_mgs(sb);
2208 /* Start MGC before servers */
2209 rc = lustre_start_mgc(sb);
2213 /* Set up all obd devices for service */
2214 if (!test_bit(LMD_FLG_NOSVC, lsi->lsi_lmd->lmd_flags) &&
2215 (IS_OST(lsi) || IS_MDT(lsi))) {
2216 rc = server_start_targets(sb);
2218 CERROR("Unable to start targets: %d\n", rc);
2221 /* FIXME overmount client here, or can we just start a
2222 * client log and client_fill_super on this sb? We
2223 * need to make sure server_put_super gets called too
2224 * - ll_put_super calls lustre_common_put_super; check
2225 * there for LSI_SERVER flag, call s_p_s if so.
2227 * Probably should start client from new thread so we
2228 * can return. Client will not finish until all
2229 * servers are connected. Note - MGS-only server does
2230 * NOT get a client, since there is no lustre fs
2231 * associated - the MGS is for all lustre fs's
2235 rc = server_fill_super_common(sb);
2241 /* We jump here in case of failure while starting targets or MGS.
2242 * In this case we can't just put @mnt and have to do real cleanup
2243 * with stoping targets, etc.
2245 server_put_super(sb);
2248 EXPORT_SYMBOL(server_fill_super);
2251 * Calculate timeout value for a target.
2253 void server_calc_timeout(struct lustre_sb_info *lsi, struct obd_device *obd)
2255 struct lustre_mount_data *lmd;
2259 bool has_ir = !!(lsi->lsi_flags & LDD_F_IR_CAPABLE);
2260 int min = OBD_RECOVERY_TIME_MIN;
2262 LASSERT(IS_SERVER(lsi));
2266 soft = lmd->lmd_recovery_time_soft;
2267 hard = lmd->lmd_recovery_time_hard;
2268 has_ir = has_ir && !test_bit(LMD_FLG_NOIR, lmd->lmd_flags);
2269 obd->obd_no_ir = !has_ir;
2273 soft = OBD_RECOVERY_TIME_SOFT;
2275 hard = OBD_RECOVERY_TIME_HARD;
2277 /* target may have ir_factor configured. */
2278 factor = OBD_IR_FACTOR_DEFAULT;
2279 if (obd->obd_recovery_ir_factor)
2280 factor = obd->obd_recovery_ir_factor;
2283 int new_soft = soft;
2285 /* adjust timeout value by imperative recovery */
2286 new_soft = (soft * factor) / OBD_IR_FACTOR_MAX;
2287 /* make sure the timeout is not too short */
2288 new_soft = max(min, new_soft);
2290 LCONSOLE_INFO("%s: Imperative Recovery enabled, recovery window shrunk from %d-%d down to %d-%d\n",
2291 obd->obd_name, soft, hard, new_soft, hard);
2295 LCONSOLE_INFO("%s: Imperative Recovery not enabled, recovery window %d-%d\n",
2296 obd->obd_name, soft, hard);
2300 obd->obd_recovery_timeout = max_t(time64_t, obd->obd_recovery_timeout,
2302 obd->obd_recovery_time_hard = hard;
2303 obd->obd_recovery_ir_factor = factor;
2307 * This is the entry point for the mount call into Lustre.
2308 * This is called when a server target is mounted,
2309 * and this is where we start setting things up.
2310 * @param data Mount options (e.g. -o flock,abort_recov)
2312 static int lustre_tgt_fill_super(struct super_block *sb, void *lmd2_data,
2315 struct lustre_mount_data *lmd;
2316 struct lustre_sb_info *lsi;
2320 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
2322 lsi = lustre_init_lsi(sb);
2328 * Disable lockdep during mount, because mount locking patterns are
2334 * LU-639: the OBD cleanup of last mount may not finish yet, wait here.
2336 obd_zombie_barrier();
2338 /* Figure out the lmd from the mount options */
2339 if (lmd_parse(lmd2_data, lmd)) {
2341 GOTO(out, rc = -EINVAL);
2344 if (lmd_is_client(lmd)) {
2346 CERROR("%s: attempting to mount a client with -t lustre_tgt' which is only for server-side mounts: rc = %d\n",
2352 CDEBUG(D_MOUNT, "Mounting server from %s\n", lmd->lmd_dev);
2353 rc = server_fill_super(sb);
2355 * server_fill_super calls lustre_start_mgc after the mount
2356 * because we need the MGS NIDs which are stored on disk.
2357 * Plus, we may need to start the MGS first.
2359 * server_fill_super will call server_put_super on failure
2361 * If error happens in fill_super() call, @lsi will be killed there.
2362 * This is why we do not put it here.
2366 CERROR("Unable to mount %s (%d)\n",
2367 s2lsi(sb) ? lmd->lmd_dev : "", rc);
2369 CDEBUG(D_SUPER, "Mount %s complete\n",
2376 /***************** FS registration ******************/
2377 static struct dentry *lustre_tgt_mount(struct file_system_type *fs_type,
2378 int flags, const char *devname,
2381 return mount_nodev(fs_type, flags, data, lustre_tgt_fill_super);
2384 /* Register the "lustre_tgt" fs type.
2386 * Right now this isn't any different than the normal "lustre" filesystem
2387 * type, but it is added so that there is some compatibility to allow
2388 * changing documentation and scripts to start using the "lustre_tgt" type
2389 * at mount time. That will simplify test interop, and in case of upgrades
2390 * that change to the new type and then need to roll back for some reason.
2392 * The long-term goal is to disentangle the client and server mount code.
2394 static struct file_system_type lustre_tgt_fstype = {
2395 .owner = THIS_MODULE,
2396 .name = "lustre_tgt",
2397 .mount = lustre_tgt_mount,
2398 .kill_sb = kill_anon_super,
2399 .fs_flags = FS_REQUIRES_DEV | FS_RENAME_DOES_D_MOVE,
2401 MODULE_ALIAS_FS("lustre_tgt");
2403 int lustre_tgt_register_fs(void)
2405 return register_filesystem(&lustre_tgt_fstype);
2408 void lustre_tgt_unregister_fs(void)
2410 unregister_filesystem(&lustre_tgt_fstype);