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) 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/obd_mount_server.c
38 * 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)
49 #include <linux/statfs.h>
51 #include <obd_class.h>
52 #include <lustre/lustre_user.h>
53 #include <linux/version.h>
54 #include <lustre_ioctl.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>
61 #ifdef HAVE_SELINUX_IS_ENABLED
62 #include <linux/selinux.h>
65 /*********** mount lookup *********/
67 DEFINE_MUTEX(lustre_mount_info_lock);
68 static struct list_head server_mount_info_list =
69 LIST_HEAD_INIT(server_mount_info_list);
71 static struct lustre_mount_info *server_find_mount(const char *name)
73 struct list_head *tmp;
74 struct lustre_mount_info *lmi;
77 list_for_each(tmp, &server_mount_info_list) {
78 lmi = 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)
91 struct lustre_mount_info *lmi;
97 OBD_ALLOC(lmi, sizeof(*lmi));
100 OBD_ALLOC(name_cp, strlen(name) + 1);
102 OBD_FREE(lmi, sizeof(*lmi));
105 strcpy(name_cp, name);
107 mutex_lock(&lustre_mount_info_lock);
109 if (server_find_mount(name)) {
110 mutex_unlock(&lustre_mount_info_lock);
111 OBD_FREE(lmi, sizeof(*lmi));
112 OBD_FREE(name_cp, strlen(name) + 1);
113 CERROR("Already registered %s\n", name);
116 lmi->lmi_name = name_cp;
118 list_add(&lmi->lmi_list_chain, &server_mount_info_list);
120 mutex_unlock(&lustre_mount_info_lock);
122 CDEBUG(D_MOUNT, "register mount %p from %s\n", sb, name);
127 /* when an obd no longer needs a mount */
128 static int server_deregister_mount(const char *name)
130 struct lustre_mount_info *lmi;
133 mutex_lock(&lustre_mount_info_lock);
134 lmi = server_find_mount(name);
136 mutex_unlock(&lustre_mount_info_lock);
137 CERROR("%s not registered\n", name);
141 CDEBUG(D_MOUNT, "deregister mount %p from %s\n", lmi->lmi_sb, name);
143 OBD_FREE(lmi->lmi_name, strlen(lmi->lmi_name) + 1);
144 list_del(&lmi->lmi_list_chain);
145 OBD_FREE(lmi, sizeof(*lmi));
146 mutex_unlock(&lustre_mount_info_lock);
151 /* obd's look up a registered mount using their obdname. This is just
152 for initial obd setup to find the mount struct. It should not be
153 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 atomic_inc(&lsi->lsi_mounts);
171 CDEBUG(D_MOUNT, "get mount %p from %s, refs=%d\n", lmi->lmi_sb,
172 name, atomic_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, atomic_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 */
230 lmi = server_find_mount(LUSTRE_MGS_OBDNAME);
232 lsi = s2lsi(lmi->lmi_sb);
233 LCONSOLE_ERROR_MSG(0x15d, "The MGS service was already started"
238 CDEBUG(D_CONFIG, "Start MGS service %s\n", LUSTRE_MGS_OBDNAME);
240 rc = server_register_mount(LUSTRE_MGS_OBDNAME, sb);
243 rc = lustre_start_simple(LUSTRE_MGS_OBDNAME, LUSTRE_MGS_NAME,
244 LUSTRE_MGS_OBDNAME, 0, 0,
245 lsi->lsi_osd_obdname, 0);
246 /* server_deregister_mount() is not called previously, for lsi
247 * and other stuff can't be freed cleanly when mgs calls
248 * server_put_mount() in error handling case (see b=17758),
249 * this problem is caused by a bug in mgs_init0, which forgot
250 * calling server_put_mount in error case. */
253 server_deregister_mount(LUSTRE_MGS_OBDNAME);
257 LCONSOLE_ERROR_MSG(0x15e, "Failed to start MGS '%s' (%d). "
258 "Is the 'mgs' module loaded?\n",
259 LUSTRE_MGS_OBDNAME, rc);
263 static int server_stop_mgs(struct super_block *sb)
265 struct obd_device *obd;
269 CDEBUG(D_MOUNT, "Stop MGS service %s\n", LUSTRE_MGS_OBDNAME);
271 /* There better be only one MGS */
272 obd = class_name2obd(LUSTRE_MGS_OBDNAME);
274 CDEBUG(D_CONFIG, "mgs %s not running\n", LUSTRE_MGS_OBDNAME);
278 /* The MGS should always stop when we say so */
280 rc = class_manual_cleanup(obd);
284 /* Since there's only one mgc per node, we have to change it's fs to get
285 access to the right disk. */
286 static int server_mgc_set_fs(struct obd_device *mgc, struct super_block *sb)
288 struct lustre_sb_info *lsi = s2lsi(sb);
292 CDEBUG(D_MOUNT, "Set mgc disk for %s\n", lsi->lsi_lmd->lmd_dev);
294 /* cl_mgc_sem in mgc insures we sleep if the mgc_fs is busy */
295 rc = obd_set_info_async(NULL, mgc->obd_self_export,
296 sizeof(KEY_SET_FS), KEY_SET_FS,
297 sizeof(*sb), sb, NULL);
299 CERROR("can't set_fs %d\n", rc);
304 static int server_mgc_clear_fs(struct obd_device *mgc)
309 CDEBUG(D_MOUNT, "Unassign mgc disk\n");
311 rc = obd_set_info_async(NULL, mgc->obd_self_export,
312 sizeof(KEY_CLEAR_FS), KEY_CLEAR_FS,
317 static inline bool is_mdc_device(const char *devname)
321 ptr = strrchr(devname, '-');
322 return ptr != NULL && strcmp(ptr, "-mdc") == 0;
325 static inline bool tgt_is_mdt(const char *tgtname, __u32 *idx)
329 type = server_name2index(tgtname, idx, NULL);
331 return type == LDD_F_SV_TYPE_MDT;
335 * Convert OST/MDT name(fsname-{MDT,OST}xxxx) to a lwp name with the @idx:yyyy
336 * (fsname-MDTyyyy-lwp-{MDT,OST}xxxx)
338 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx)
345 OBD_ALLOC(fsname, MTI_NAME_MAXLEN);
349 rc = server_name2fsname(tgt_name, fsname, &tgt);
351 CERROR("%s: failed to get fsname from tgt_name: rc = %d\n",
356 if (*tgt != '-' && *tgt != ':') {
357 CERROR("%s: invalid tgt_name name!\n", tgt_name);
358 GOTO(cleanup, rc = -EINVAL);
362 if (strncmp(tgt, "OST", 3) != 0 && strncmp(tgt, "MDT", 3) != 0) {
363 CERROR("%s is not an OST or MDT target!\n", tgt_name);
364 GOTO(cleanup, rc = -EINVAL);
366 snprintf(lwp_name, len, "%s-MDT%04x-%s-%s",
367 fsname, idx, LUSTRE_LWP_NAME, tgt);
369 GOTO(cleanup, rc = 0);
373 OBD_FREE(fsname, MTI_NAME_MAXLEN);
377 EXPORT_SYMBOL(tgt_name2lwp_name);
379 static struct list_head lwp_register_list =
380 LIST_HEAD_INIT(lwp_register_list);
381 DEFINE_MUTEX(lwp_register_list_lock);
383 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
384 register_lwp_cb cb_func, void *cb_data)
386 struct obd_device *lwp;
387 struct lwp_register_item *lri;
390 LASSERTF(strlen(lwpname) < MTI_NAME_MAXLEN, "lwpname is too long %s\n",
392 LASSERT(exp != NULL && *exp == NULL);
398 mutex_lock(&lwp_register_list_lock);
400 lwp = class_name2obd(lwpname);
401 if (lwp != NULL && lwp->obd_set_up == 1) {
402 struct obd_uuid *uuid;
406 mutex_unlock(&lwp_register_list_lock);
410 memcpy(uuid->uuid, lwpname, strlen(lwpname));
411 *exp = cfs_hash_lookup(lwp->obd_uuid_hash, uuid);
415 memcpy(lri->lri_name, lwpname, strlen(lwpname));
417 lri->lri_cb_func = cb_func;
418 lri->lri_cb_data = cb_data;
419 INIT_LIST_HEAD(&lri->lri_list);
420 list_add(&lri->lri_list, &lwp_register_list);
422 if (*exp != NULL && cb_func != NULL)
425 mutex_unlock(&lwp_register_list_lock);
428 EXPORT_SYMBOL(lustre_register_lwp_item);
430 void lustre_deregister_lwp_item(struct obd_export **exp)
432 struct lwp_register_item *lri, *tmp;
434 mutex_lock(&lwp_register_list_lock);
435 list_for_each_entry_safe(lri, tmp, &lwp_register_list, lri_list) {
436 if (exp == lri->lri_exp) {
438 class_export_put(*exp);
439 list_del(&lri->lri_list);
444 mutex_unlock(&lwp_register_list_lock);
446 EXPORT_SYMBOL(lustre_deregister_lwp_item);
448 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx)
450 struct lustre_mount_info *lmi;
451 struct lustre_sb_info *lsi;
452 struct obd_device *lwp;
453 struct obd_export *exp = NULL;
458 lmi = server_get_mount(dev);
462 lsi = s2lsi(lmi->lmi_sb);
463 rc = server_name2fsname(lsi->lsi_svname, fsname, NULL);
465 CERROR("%s: failed to get fsname: rc = %d\n",
466 lsi->lsi_svname, rc);
470 snprintf(lwp_name, sizeof(lwp_name), "%s-MDT%04x", fsname, idx);
471 spin_lock(&lsi->lsi_lwp_lock);
472 list_for_each_entry(lwp, &lsi->lsi_lwp_list, obd_lwp_list) {
473 char *ptr = strstr(lwp->obd_name, lwp_name);
476 exp = class_export_get(lwp->obd_lwp_export);
480 spin_unlock(&lsi->lsi_lwp_lock);
483 server_put_mount(dev, false);
487 EXPORT_SYMBOL(lustre_find_lwp_by_index);
489 static void lustre_notify_lwp_list(struct obd_export *exp)
491 struct lwp_register_item *lri, *tmp;
492 LASSERT(exp != NULL);
494 mutex_lock(&lwp_register_list_lock);
495 list_for_each_entry_safe(lri, tmp, &lwp_register_list, lri_list) {
496 if (strcmp(exp->exp_obd->obd_name, lri->lri_name))
498 if (*lri->lri_exp != NULL)
500 *lri->lri_exp = class_export_get(exp);
501 if (lri->lri_cb_func != NULL)
502 lri->lri_cb_func(lri->lri_cb_data);
504 mutex_unlock(&lwp_register_list_lock);
507 static int lustre_lwp_connect(struct obd_device *lwp)
510 struct lu_context session_ctx;
511 struct obd_export *exp;
512 struct obd_uuid *uuid = NULL;
513 struct obd_connect_data *data = NULL;
517 /* log has been fully processed, let clients connect */
518 rc = lu_env_init(&env, lwp->obd_lu_dev->ld_type->ldt_ctx_tags);
522 lu_context_init(&session_ctx, LCT_SERVER_SESSION);
523 session_ctx.lc_thread = NULL;
524 lu_context_enter(&session_ctx);
525 env.le_ses = &session_ctx;
529 GOTO(out, rc = -ENOMEM);
531 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_INDEX;
532 data->ocd_version = LUSTRE_VERSION_CODE;
533 data->ocd_connect_flags |= OBD_CONNECT_MDS_MDS | OBD_CONNECT_FID |
534 OBD_CONNECT_AT | OBD_CONNECT_LRU_RESIZE |
535 OBD_CONNECT_FULL20 | OBD_CONNECT_LVB_TYPE |
536 OBD_CONNECT_LIGHTWEIGHT | OBD_CONNECT_LFSCK;
539 GOTO(out, rc = -ENOMEM);
541 if (strlen(lwp->obd_name) > sizeof(uuid->uuid)) {
542 CERROR("%s: Too long lwp name %s, max_size is %d\n",
543 lwp->obd_name, lwp->obd_name, (int)sizeof(uuid->uuid));
544 GOTO(out, rc = -EINVAL);
547 /* Use lwp name as the uuid, so we find the export by lwp name later */
548 memcpy(uuid->uuid, lwp->obd_name, strlen(lwp->obd_name));
549 rc = obd_connect(&env, &exp, lwp, uuid, data, NULL);
551 CERROR("%s: connect failed: rc = %d\n", lwp->obd_name, rc);
553 if (unlikely(lwp->obd_lwp_export != NULL))
554 class_export_put(lwp->obd_lwp_export);
555 lwp->obd_lwp_export = class_export_get(exp);
556 lustre_notify_lwp_list(exp);
568 lu_context_exit(&session_ctx);
569 lu_context_fini(&session_ctx);
575 * lwp is used by slaves (Non-MDT0 targets) to manage the connection to MDT0,
576 * or from the OSTx to MDTy.
578 static int lustre_lwp_setup(struct lustre_cfg *lcfg, struct lustre_sb_info *lsi,
581 struct obd_device *obd;
582 char *lwpname = NULL;
583 char *lwpuuid = NULL;
587 rc = class_add_uuid(lustre_cfg_string(lcfg, 1),
590 CERROR("%s: Can't add uuid: rc =%d\n", lsi->lsi_svname, rc);
594 OBD_ALLOC(lwpname, MTI_NAME_MAXLEN);
596 GOTO(out, rc = -ENOMEM);
598 rc = tgt_name2lwp_name(lsi->lsi_svname, lwpname, MTI_NAME_MAXLEN, idx);
600 CERROR("%s: failed to generate lwp name: rc = %d\n",
601 lsi->lsi_svname, rc);
605 OBD_ALLOC(lwpuuid, MTI_NAME_MAXLEN);
607 GOTO(out, rc = -ENOMEM);
609 sprintf(lwpuuid, "%s_UUID", lwpname);
610 rc = lustre_start_simple(lwpname, LUSTRE_LWP_NAME,
611 lwpuuid, lustre_cfg_string(lcfg, 1),
614 CERROR("%s: setup up failed: rc %d\n", lwpname, rc);
618 obd = class_name2obd(lwpname);
619 LASSERT(obd != NULL);
621 rc = lustre_lwp_connect(obd);
623 obd->u.cli.cl_max_mds_easize = MAX_MD_SIZE;
624 spin_lock(&lsi->lsi_lwp_lock);
625 list_add_tail(&obd->obd_lwp_list, &lsi->lsi_lwp_list);
626 spin_unlock(&lsi->lsi_lwp_lock);
628 CERROR("%s: connect failed: rc = %d\n", lwpname, rc);
635 OBD_FREE(lwpname, MTI_NAME_MAXLEN);
637 OBD_FREE(lwpuuid, MTI_NAME_MAXLEN);
642 /* the caller is responsible for memory free */
643 static struct obd_device *lustre_find_lwp(struct lustre_sb_info *lsi,
644 char **lwpname, __u32 idx)
646 struct obd_device *lwp;
650 LASSERT(lwpname != NULL);
651 LASSERT(IS_OST(lsi) || IS_MDT(lsi));
653 OBD_ALLOC(*lwpname, MTI_NAME_MAXLEN);
654 if (*lwpname == NULL)
655 RETURN(ERR_PTR(-ENOMEM));
657 rc = tgt_name2lwp_name(lsi->lsi_svname, *lwpname, MTI_NAME_MAXLEN, idx);
659 CERROR("%s: failed to generate lwp name: rc = %d\n",
660 lsi->lsi_svname, rc);
661 GOTO(out, rc = -EINVAL);
664 lwp = class_name2obd(*lwpname);
668 if (*lwpname != NULL) {
669 OBD_FREE(*lwpname, MTI_NAME_MAXLEN);
675 RETURN(lwp != NULL ? lwp : ERR_PTR(-ENOENT));
678 static int lustre_lwp_add_conn(struct lustre_cfg *cfg,
679 struct lustre_sb_info *lsi, __u32 idx)
681 struct lustre_cfg_bufs *bufs = NULL;
682 struct lustre_cfg *lcfg = NULL;
683 char *lwpname = NULL;
684 struct obd_device *lwp;
688 lwp = lustre_find_lwp(lsi, &lwpname, idx);
690 CERROR("%s: can't find lwp device.\n", lsi->lsi_svname);
691 GOTO(out, rc = PTR_ERR(lwp));
693 LASSERT(lwpname != NULL);
697 GOTO(out, rc = -ENOMEM);
699 lustre_cfg_bufs_reset(bufs, lwpname);
700 lustre_cfg_bufs_set_string(bufs, 1,
701 lustre_cfg_string(cfg, 1));
703 lcfg = lustre_cfg_new(LCFG_ADD_CONN, bufs);
705 GOTO(out_cfg, rc = -ENOMEM);
706 rc = class_add_conn(lwp, lcfg);
708 CERROR("%s: can't add conn: rc = %d\n", lwpname, rc);
711 lustre_cfg_free(lcfg);
717 OBD_FREE(lwpname, MTI_NAME_MAXLEN);
722 * Retrieve MDT nids from the client log, then start the lwp device.
723 * there are only two scenarios which would include mdt nid.
725 * marker 5 (flags=0x01, v2.1.54.0) lustre-MDTyyyy 'add mdc' xxx-
726 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:192.168.122.162@tcp
727 * attach 0:lustre-MDTyyyy-mdc 1:mdc 2:lustre-clilmv_UUID
728 * setup 0:lustre-MDTyyyy-mdc 1:lustre-MDTyyyy_UUID 2:192.168.122.162@tcp
729 * add_uuid nid=192.168.172.1@tcp(0x20000c0a8ac01) 0: 1:192.168.172.1@tcp
730 * add_conn 0:lustre-MDTyyyy-mdc 1:192.168.172.1@tcp
731 * modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDTyyyy_UUID xxxx
732 * marker 5 (flags=0x02, v2.1.54.0) lustre-MDTyyyy 'add mdc' xxxx-
734 * marker 7 (flags=0x01, v2.1.54.0) lustre-MDTyyyy 'add failnid' xxxx-
735 * add_uuid nid=192.168.122.2@tcp(0x20000c0a87a02) 0: 1:192.168.122.2@tcp
736 * add_conn 0:lustre-MDTyyyy-mdc 1:192.168.122.2@tcp
737 * marker 7 (flags=0x02, v2.1.54.0) lustre-MDTyyyy 'add failnid' xxxx-
739 static int client_lwp_config_process(const struct lu_env *env,
740 struct llog_handle *handle,
741 struct llog_rec_hdr *rec, void *data)
743 struct config_llog_instance *clli = data;
744 int cfg_len = rec->lrh_len;
745 char *cfg_buf = (char *) (rec + 1);
746 struct lustre_cfg *lcfg = NULL;
747 struct lustre_sb_info *lsi;
748 int rc = 0, swab = 0;
751 if (rec->lrh_type != OBD_CFG_REC) {
752 CERROR("Unknown llog record type %#x encountered\n",
757 LASSERT(clli->cfg_sb != NULL);
758 lsi = s2lsi(clli->cfg_sb);
760 lcfg = (struct lustre_cfg *)cfg_buf;
761 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
762 lustre_swab_lustre_cfg(lcfg);
766 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
770 switch (lcfg->lcfg_command) {
772 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
774 lustre_swab_cfg_marker(marker, swab,
775 LUSTRE_CFG_BUFLEN(lcfg, 1));
776 if (marker->cm_flags & CM_SKIP ||
777 marker->cm_flags & CM_EXCLUDE)
780 if (!tgt_is_mdt(marker->cm_tgtname, &clli->cfg_lwp_idx))
783 if (IS_MDT(lsi) && clli->cfg_lwp_idx != 0)
786 if (!strncmp(marker->cm_comment, "add mdc", 7) ||
787 !strncmp(marker->cm_comment, "add failnid", 11)) {
788 if (marker->cm_flags & CM_START) {
789 clli->cfg_flags = CFG_F_MARKER;
790 /* This hack is to differentiate the
791 * ADD_UUID is come from "add mdc" record
792 * or from "add failnid" record. */
793 if (!strncmp(marker->cm_comment,
795 clli->cfg_flags |= CFG_F_SKIP;
796 } else if (marker->cm_flags & CM_END) {
802 case LCFG_ADD_UUID: {
803 if (clli->cfg_flags == CFG_F_MARKER) {
804 rc = lustre_lwp_setup(lcfg, lsi, clli->cfg_lwp_idx);
805 /* XXX: process only the first nid as
806 * we don't need another instance of lwp */
807 clli->cfg_flags |= CFG_F_SKIP;
808 } else if (clli->cfg_flags == (CFG_F_MARKER | CFG_F_SKIP)) {
809 rc = class_add_uuid(lustre_cfg_string(lcfg, 1),
812 CERROR("%s: Fail to add uuid, rc:%d\n",
813 lsi->lsi_svname, rc);
817 case LCFG_ADD_CONN: {
818 char *devname = lustre_cfg_string(lcfg, 0);
822 if (!is_mdc_device(devname))
825 ptr = strrchr(devname, '-');
830 if (!tgt_is_mdt(devname, &idx)) {
836 if (IS_MDT(lsi) && idx != 0)
839 rc = lustre_lwp_add_conn(lcfg, lsi, idx);
849 static int lustre_disconnect_lwp(struct super_block *sb)
851 struct lustre_sb_info *lsi = s2lsi(sb);
852 struct obd_device *lwp;
853 char *logname = NULL;
854 struct lustre_cfg_bufs *bufs = NULL;
855 struct config_llog_instance *cfg = NULL;
860 if (likely(lsi->lsi_lwp_started)) {
861 OBD_ALLOC(logname, MTI_NAME_MAXLEN);
865 rc = server_name2fsname(lsi->lsi_svname, logname, NULL);
867 CERROR("%s: failed to get fsname from svname: "
868 "rc = %d\n", lsi->lsi_svname, rc);
869 GOTO(out, rc = -EINVAL);
872 strcat(logname, "-client");
875 GOTO(out, rc = -ENOMEM);
878 cfg->cfg_instance = sb;
879 rc = lustre_end_log(sb, logname, cfg);
883 lsi->lsi_lwp_started = 0;
888 GOTO(out, rc = -ENOMEM);
890 list_for_each_entry(lwp, &lsi->lsi_lwp_list, obd_lwp_list) {
891 struct lustre_cfg *lcfg;
893 if (likely(lwp->obd_lwp_export != NULL)) {
894 class_export_put(lwp->obd_lwp_export);
895 lwp->obd_lwp_export = NULL;
898 lustre_cfg_bufs_reset(bufs, lwp->obd_name);
899 lustre_cfg_bufs_set_string(bufs, 1, NULL);
900 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
902 GOTO(out, rc = -ENOMEM);
904 /* Disconnect import first. NULL is passed for the '@env',
905 * since it will not be used. */
906 rc = lwp->obd_lu_dev->ld_ops->ldo_process_config(NULL,
907 lwp->obd_lu_dev, lcfg);
908 lustre_cfg_free(lcfg);
909 if (rc != 0 && rc != -ETIMEDOUT) {
910 CERROR("%s: fail to disconnect LWP: rc = %d\n",
924 OBD_FREE(logname, MTI_NAME_MAXLEN);
926 return rc1 != 0 ? rc1 : rc;
930 * Stop the lwp for an OST/MDT target.
932 static int lustre_stop_lwp(struct super_block *sb)
934 struct lustre_sb_info *lsi = s2lsi(sb);
935 struct obd_device *lwp;
940 while (!list_empty(&lsi->lsi_lwp_list)) {
941 lwp = list_entry(lsi->lsi_lwp_list.next, struct obd_device,
943 list_del_init(&lwp->obd_lwp_list);
945 rc = class_manual_cleanup(lwp);
947 CERROR("%s: fail to stop LWP: rc = %d\n",
953 RETURN(rc1 != 0 ? rc1 : rc);
957 * Start the lwp(fsname-MDTyyyy-lwp-{MDT,OST}xxxx) for a MDT/OST or MDT target.
959 static int lustre_start_lwp(struct super_block *sb)
961 struct lustre_sb_info *lsi = s2lsi(sb);
962 struct config_llog_instance *cfg = NULL;
967 if (unlikely(lsi->lsi_lwp_started))
970 OBD_ALLOC(logname, MTI_NAME_MAXLEN);
974 rc = server_name2fsname(lsi->lsi_svname, logname, NULL);
976 CERROR("%s: failed to get fsname from svname: rc = %d\n",
977 lsi->lsi_svname, rc);
978 GOTO(out, rc = -EINVAL);
981 strcat(logname, "-client");
984 GOTO(out, rc = -ENOMEM);
986 cfg->cfg_callback = client_lwp_config_process;
987 cfg->cfg_instance = sb;
988 rc = lustre_process_log(sb, logname, cfg);
990 lsi->lsi_lwp_started = 1;
995 OBD_FREE(logname, MTI_NAME_MAXLEN);
1002 DEFINE_MUTEX(server_start_lock);
1004 /* Stop MDS/OSS if nobody is using them */
1005 static int server_stop_servers(int lsiflags)
1007 struct obd_device *obd = NULL;
1008 struct obd_type *type = NULL;
1012 mutex_lock(&server_start_lock);
1014 /* Either an MDT or an OST or neither */
1015 /* if this was an MDT, and there are no more MDT's, clean up the MDS */
1016 if (lsiflags & LDD_F_SV_TYPE_MDT) {
1017 obd = class_name2obd(LUSTRE_MDS_OBDNAME);
1019 type = class_search_type(LUSTRE_MDT_NAME);
1022 /* if this was an OST, and there are no more OST's, clean up the OSS */
1023 if (lsiflags & LDD_F_SV_TYPE_OST) {
1024 obd = class_name2obd(LUSTRE_OSS_OBDNAME);
1026 type = class_search_type(LUSTRE_OST_NAME);
1029 if (obd != NULL && (type == NULL || type->typ_refcnt == 0)) {
1031 /* obd_fail doesn't mean much on a server obd */
1032 rc = class_manual_cleanup(obd);
1035 mutex_unlock(&server_start_lock);
1040 int server_mti_print(const char *title, struct mgs_target_info *mti)
1042 PRINT_CMD(PRINT_MASK, "mti %s\n", title);
1043 PRINT_CMD(PRINT_MASK, "server: %s\n", mti->mti_svname);
1044 PRINT_CMD(PRINT_MASK, "fs: %s\n", mti->mti_fsname);
1045 PRINT_CMD(PRINT_MASK, "uuid: %s\n", mti->mti_uuid);
1046 PRINT_CMD(PRINT_MASK, "ver: %d flags: %#x\n",
1047 mti->mti_config_ver, mti->mti_flags);
1050 EXPORT_SYMBOL(server_mti_print);
1052 /* Generate data for registration */
1053 static int server_lsi2mti(struct lustre_sb_info *lsi,
1054 struct mgs_target_info *mti)
1056 lnet_process_id_t id;
1061 if (!IS_SERVER(lsi))
1064 if (strlcpy(mti->mti_svname, lsi->lsi_svname, sizeof(mti->mti_svname))
1065 >= sizeof(mti->mti_svname))
1068 mti->mti_nid_count = 0;
1069 while (LNetGetId(i++, &id) != -ENOENT) {
1070 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
1073 /* server use --servicenode param, only allow specified
1074 * nids be registered */
1075 if ((lsi->lsi_lmd->lmd_flags & LMD_FLG_NO_PRIMNODE) != 0 &&
1076 class_match_nid(lsi->lsi_lmd->lmd_params,
1077 PARAM_FAILNODE, id.nid) < 1)
1080 /* match specified network */
1081 if (!class_match_net(lsi->lsi_lmd->lmd_params,
1082 PARAM_NETWORK, LNET_NIDNET(id.nid)))
1085 mti->mti_nids[mti->mti_nid_count] = id.nid;
1086 mti->mti_nid_count++;
1087 if (mti->mti_nid_count >= MTI_NIDS_MAX) {
1088 CWARN("Only using first %d nids for %s\n",
1089 mti->mti_nid_count, mti->mti_svname);
1094 mti->mti_lustre_ver = LUSTRE_VERSION_CODE;
1095 mti->mti_config_ver = 0;
1097 rc = server_name2fsname(lsi->lsi_svname, mti->mti_fsname, NULL);
1101 rc = server_name2index(lsi->lsi_svname, &mti->mti_stripe_index, NULL);
1104 /* Orion requires index to be set */
1105 LASSERT(!(rc & LDD_F_NEED_INDEX));
1106 /* keep only LDD flags */
1107 mti->mti_flags = lsi->lsi_flags & LDD_F_MASK;
1108 if (mti->mti_flags & (LDD_F_WRITECONF | LDD_F_VIRGIN))
1109 mti->mti_flags |= LDD_F_UPDATE;
1110 cplen = strlcpy(mti->mti_params, lsi->lsi_lmd->lmd_params,
1111 sizeof(mti->mti_params));
1112 if (cplen >= sizeof(mti->mti_params))
1117 /* Register an old or new target with the MGS. If needed MGS will construct
1118 startup logs and assign index */
1119 static int server_register_target(struct lustre_sb_info *lsi)
1121 struct obd_device *mgc = lsi->lsi_mgc;
1122 struct mgs_target_info *mti = NULL;
1129 if (!IS_SERVER(lsi))
1136 rc = server_lsi2mti(lsi, mti);
1140 CDEBUG(D_MOUNT, "Registration %s, fs=%s, %s, index=%04x, flags=%#x\n",
1141 mti->mti_svname, mti->mti_fsname,
1142 libcfs_nid2str(mti->mti_nids[0]), mti->mti_stripe_index,
1145 /* if write_conf is true, the registration must succeed */
1146 writeconf = !!(lsi->lsi_flags & (LDD_F_NEED_INDEX | LDD_F_UPDATE));
1147 mti->mti_flags |= LDD_F_OPC_REG;
1149 /* Register the target */
1150 /* FIXME use mgc_process_config instead */
1151 rc = obd_set_info_async(NULL, mgc->u.cli.cl_mgc_mgsexp,
1152 sizeof(KEY_REGISTER_TARGET),
1153 KEY_REGISTER_TARGET,
1154 sizeof(*mti), mti, NULL);
1156 if (mti->mti_flags & LDD_F_ERROR) {
1157 LCONSOLE_ERROR_MSG(0x160,
1158 "%s: the MGS refuses to allow this server "
1159 "to start: rc = %d. Please see messages on "
1160 "the MGS.\n", lsi->lsi_svname, rc);
1161 } else if (writeconf) {
1162 LCONSOLE_ERROR_MSG(0x15f,
1163 "%s: cannot register this server with the MGS: "
1164 "rc = %d. Is the MGS running?\n",
1165 lsi->lsi_svname, rc);
1167 CERROR("%s: error registering with the MGS: rc = %d "
1168 "(not fatal)\n", lsi->lsi_svname, rc);
1169 /* reset the error code for non-fatal error. */
1182 * Notify the MGS that this target is ready.
1183 * Used by IR - if the MGS receives this message, it will notify clients.
1185 static int server_notify_target(struct super_block *sb, struct obd_device *obd)
1187 struct lustre_sb_info *lsi = s2lsi(sb);
1188 struct obd_device *mgc = lsi->lsi_mgc;
1189 struct mgs_target_info *mti = NULL;
1195 if (!(IS_SERVER(lsi)))
1201 rc = server_lsi2mti(lsi, mti);
1205 mti->mti_instance = obd->u.obt.obt_instance;
1206 mti->mti_flags |= LDD_F_OPC_READY;
1208 /* FIXME use mgc_process_config instead */
1209 rc = obd_set_info_async(NULL, mgc->u.cli.cl_mgc_mgsexp,
1210 sizeof(KEY_REGISTER_TARGET),
1211 KEY_REGISTER_TARGET,
1212 sizeof(*mti), mti, NULL);
1214 /* Imperative recovery: if the mgs informs us to use IR? */
1215 if (!rc && !(mti->mti_flags & LDD_F_ERROR) &&
1216 (mti->mti_flags & LDD_F_IR_CAPABLE))
1217 lsi->lsi_flags |= LDD_F_IR_CAPABLE;
1226 /** Start server targets: MDTs and OSTs
1228 static int server_start_targets(struct super_block *sb)
1230 struct obd_device *obd;
1231 struct lustre_sb_info *lsi = s2lsi(sb);
1232 struct config_llog_instance cfg;
1234 struct lu_device *dev;
1238 CDEBUG(D_MOUNT, "starting target %s\n", lsi->lsi_svname);
1241 /* make sure the MDS is started */
1242 mutex_lock(&server_start_lock);
1243 obd = class_name2obd(LUSTRE_MDS_OBDNAME);
1245 rc = lustre_start_simple(LUSTRE_MDS_OBDNAME,
1247 LUSTRE_MDS_OBDNAME"_uuid",
1250 mutex_unlock(&server_start_lock);
1251 CERROR("failed to start MDS: %d\n", rc);
1255 mutex_unlock(&server_start_lock);
1258 /* If we're an OST, make sure the global OSS is running */
1260 /* make sure OSS is started */
1261 mutex_lock(&server_start_lock);
1262 obd = class_name2obd(LUSTRE_OSS_OBDNAME);
1264 rc = lustre_start_simple(LUSTRE_OSS_OBDNAME,
1266 LUSTRE_OSS_OBDNAME"_uuid",
1269 mutex_unlock(&server_start_lock);
1270 CERROR("failed to start OSS: %d\n", rc);
1274 mutex_unlock(&server_start_lock);
1277 /* Set the mgc fs to our server disk. This allows the MGC to
1278 * read and write configs locally, in case it can't talk to the MGS. */
1279 rc = server_mgc_set_fs(lsi->lsi_mgc, sb);
1281 GOTO(out_stop_service, rc);
1283 /* Register with MGS */
1284 rc = server_register_target(lsi);
1288 /* Let the target look up the mount using the target's name
1289 (we can't pass the sb or mnt through class_process_config.) */
1290 rc = server_register_mount(lsi->lsi_svname, sb);
1294 /* Start targets using the llog named for the target */
1295 memset(&cfg, 0, sizeof(cfg));
1296 cfg.cfg_callback = class_config_llog_handler;
1297 rc = lustre_process_log(sb, lsi->lsi_svname, &cfg);
1299 CERROR("failed to start server %s: %d\n",
1300 lsi->lsi_svname, rc);
1301 /* Do NOT call server_deregister_mount() here. This makes it
1302 * impossible to find mount later in cleanup time and leaves
1303 * @lsi and othder stuff leaked. -umka */
1307 obd = class_name2obd(lsi->lsi_svname);
1309 CERROR("no server named %s was started\n", lsi->lsi_svname);
1310 GOTO(out_mgc, rc = -ENXIO);
1313 if (IS_OST(lsi) || IS_MDT(lsi)) {
1314 rc = lustre_start_lwp(sb);
1316 CERROR("%s: failed to start LWP: %d\n",
1317 lsi->lsi_svname, rc);
1322 server_notify_target(sb, obd);
1324 /* calculate recovery timeout, do it after lustre_process_log */
1325 server_calc_timeout(lsi, obd);
1327 /* log has been fully processed */
1328 obd_notify(obd, NULL, OBD_NOTIFY_CONFIG, (void *)CONFIG_LOG);
1330 /* log has been fully processed, let clients connect */
1331 dev = obd->obd_lu_dev;
1332 if (dev && dev->ld_ops->ldo_prepare) {
1333 rc = lu_env_init(&env, dev->ld_type->ldt_ctx_tags);
1335 struct lu_context session_ctx;
1337 lu_context_init(&session_ctx, LCT_SERVER_SESSION);
1338 session_ctx.lc_thread = NULL;
1339 lu_context_enter(&session_ctx);
1340 env.le_ses = &session_ctx;
1342 rc = dev->ld_ops->ldo_prepare(&env, NULL, dev);
1345 lu_context_exit(&session_ctx);
1346 lu_context_fini(&session_ctx);
1350 /* abort recovery only on the complete stack:
1351 * many devices can be involved */
1352 if ((lsi->lsi_lmd->lmd_flags & LMD_FLG_ABORT_RECOV) &&
1353 (OBP(obd, iocontrol))) {
1354 obd_iocontrol(OBD_IOC_ABORT_RECOVERY, obd->obd_self_export, 0,
1359 /* Release the mgc fs for others to use */
1360 server_mgc_clear_fs(lsi->lsi_mgc);
1364 server_stop_servers(lsi->lsi_flags);
1369 static int lsi_prepare(struct lustre_sb_info *lsi)
1376 LASSERT(lsi->lsi_lmd);
1378 /* The server name is given as a mount line option */
1379 if (lsi->lsi_lmd->lmd_profile == NULL) {
1380 LCONSOLE_ERROR("Can't determine server name\n");
1384 if (strlen(lsi->lsi_lmd->lmd_profile) >= sizeof(lsi->lsi_svname))
1385 RETURN(-ENAMETOOLONG);
1387 strcpy(lsi->lsi_svname, lsi->lsi_lmd->lmd_profile);
1389 /* Determine osd type */
1390 if (lsi->lsi_lmd->lmd_osd_type != NULL) {
1391 if (strlen(lsi->lsi_lmd->lmd_osd_type) >=
1392 sizeof(lsi->lsi_osd_type))
1393 RETURN(-ENAMETOOLONG);
1395 strcpy(lsi->lsi_osd_type, lsi->lsi_lmd->lmd_osd_type);
1397 strcpy(lsi->lsi_osd_type, LUSTRE_OSD_LDISKFS_NAME);
1400 /* XXX: a temp. solution for components using ldiskfs
1401 * to be removed in one of the subsequent patches */
1402 if (!strcmp(lsi->lsi_lmd->lmd_osd_type, "osd-ldiskfs"))
1403 strcpy(lsi->lsi_fstype, "ldiskfs");
1405 strcpy(lsi->lsi_fstype, lsi->lsi_lmd->lmd_osd_type);
1407 /* Determine server type */
1408 rc = server_name2index(lsi->lsi_svname, &index, NULL);
1410 if (lsi->lsi_lmd->lmd_flags & LMD_FLG_MGS) {
1411 /* Assume we're a bare MGS */
1413 lsi->lsi_lmd->lmd_flags |= LMD_FLG_NOSVC;
1415 LCONSOLE_ERROR("Can't determine server type of '%s'\n",
1420 lsi->lsi_flags |= rc;
1422 /* Add mount line flags that used to be in ldd:
1423 * writeconf, mgs, anything else?
1425 lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_WRITECONF) ?
1426 LDD_F_WRITECONF : 0;
1427 lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_VIRGIN) ?
1429 lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_UPDATE) ?
1431 lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_MGS) ?
1432 LDD_F_SV_TYPE_MGS : 0;
1433 lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_NO_PRIMNODE) ?
1434 LDD_F_NO_PRIMNODE : 0;
1439 /*************** server mount ******************/
1441 /** Start the shutdown of servers at umount.
1443 static void server_put_super(struct super_block *sb)
1445 struct lustre_sb_info *lsi = s2lsi(sb);
1446 struct obd_device *obd;
1447 char *tmpname, *extraname = NULL;
1449 int lsiflags = lsi->lsi_flags;
1452 LASSERT(IS_SERVER(lsi));
1454 tmpname_sz = strlen(lsi->lsi_svname) + 1;
1455 OBD_ALLOC(tmpname, tmpname_sz);
1456 memcpy(tmpname, lsi->lsi_svname, tmpname_sz);
1457 CDEBUG(D_MOUNT, "server put_super %s\n", tmpname);
1458 if (IS_MDT(lsi) && (lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC))
1459 snprintf(tmpname, tmpname_sz, "MGS");
1461 /* disconnect the lwp first to drain off the inflight request */
1462 if (IS_OST(lsi) || IS_MDT(lsi)) {
1465 rc = lustre_disconnect_lwp(sb);
1466 if (rc != 0 && rc != -ETIMEDOUT &&
1467 rc != -ENOTCONN && rc != -ESHUTDOWN)
1468 CWARN("%s: failed to disconnect lwp: rc= %d\n",
1472 /* Stop the target */
1473 if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC) &&
1474 (IS_MDT(lsi) || IS_OST(lsi))) {
1475 struct lustre_profile *lprof = NULL;
1477 /* tell the mgc to drop the config log */
1478 lustre_end_log(sb, lsi->lsi_svname, NULL);
1480 /* COMPAT_146 - profile may get deleted in mgc_cleanup.
1481 If there are any setup/cleanup errors, save the lov
1482 name for safety cleanup later. */
1483 lprof = class_get_profile(lsi->lsi_svname);
1484 if (lprof && lprof->lp_dt) {
1485 OBD_ALLOC(extraname, strlen(lprof->lp_dt) + 1);
1486 strcpy(extraname, lprof->lp_dt);
1489 obd = class_name2obd(lsi->lsi_svname);
1491 CDEBUG(D_MOUNT, "stopping %s\n", obd->obd_name);
1492 if (lsiflags & LSI_UMOUNT_FAILOVER)
1494 /* We can't seem to give an error return code
1495 * to .put_super, so we better make sure we clean up! */
1497 class_manual_cleanup(obd);
1499 CERROR("no obd %s\n", lsi->lsi_svname);
1500 server_deregister_mount(lsi->lsi_svname);
1504 /* If they wanted the mgs to stop separately from the mdt, they
1505 should have put it on a different device. */
1507 /* if MDS start with --nomgs, don't stop MGS then */
1508 if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOMGS))
1509 server_stop_mgs(sb);
1512 if (IS_OST(lsi) || IS_MDT(lsi)) {
1513 if (lustre_stop_lwp(sb) < 0)
1514 CERROR("%s: failed to stop lwp!\n", tmpname);
1517 /* Clean the mgc and sb */
1518 lustre_common_put_super(sb);
1520 /* wait till all in-progress cleanups are done
1521 * specifically we're interested in ofd cleanup
1523 obd_zombie_barrier();
1525 /* Stop the servers (MDS, OSS) if no longer needed. We must wait
1526 until the target is really gone so that our type refcount check
1528 server_stop_servers(lsiflags);
1530 /* In case of startup or cleanup err, stop related obds */
1532 obd = class_name2obd(extraname);
1534 CWARN("Cleaning orphaned obd %s\n", extraname);
1536 class_manual_cleanup(obd);
1538 OBD_FREE(extraname, strlen(extraname) + 1);
1541 LCONSOLE_WARN("server umount %s complete\n", tmpname);
1542 OBD_FREE(tmpname, tmpname_sz);
1546 /** Called only for 'umount -f'
1548 static void server_umount_begin(struct super_block *sb)
1550 struct lustre_sb_info *lsi = s2lsi(sb);
1553 CDEBUG(D_MOUNT, "umount -f\n");
1554 /* umount = failover
1556 no third way to do non-force, non-failover */
1557 lsi->lsi_flags &= ~LSI_UMOUNT_FAILOVER;
1561 static int server_statfs(struct dentry *dentry, struct kstatfs *buf)
1563 struct super_block *sb = dentry->d_sb;
1564 struct lustre_sb_info *lsi = s2lsi(sb);
1565 struct obd_statfs statfs;
1569 if (lsi->lsi_dt_dev) {
1570 rc = dt_statfs(NULL, lsi->lsi_dt_dev, &statfs);
1572 statfs_unpack(buf, &statfs);
1573 buf->f_type = sb->s_magic;
1579 buf->f_type = sb->s_magic;
1580 buf->f_bsize = sb->s_blocksize;
1586 buf->f_namelen = NAME_MAX;
1590 /** The operations we support directly on the superblock:
1591 * mount, umount, and df.
1593 static struct super_operations server_ops = {
1594 .put_super = server_put_super,
1595 .umount_begin = server_umount_begin, /* umount -f */
1596 .statfs = server_statfs,
1600 * Xattr support for Lustre servers
1602 static ssize_t lustre_getxattr(struct dentry *dentry, const char *name,
1603 void *buffer, size_t size)
1605 if (!selinux_is_enabled())
1610 static int lustre_setxattr(struct dentry *dentry, const char *name,
1611 const void *value, size_t size, int flags)
1616 static ssize_t lustre_listxattr(struct dentry *d_entry, char *name,
1622 const struct inode_operations server_inode_operations = {
1623 .setxattr = lustre_setxattr,
1624 .getxattr = lustre_getxattr,
1625 .listxattr = lustre_listxattr,
1628 #define log2(n) ffz(~(n))
1629 #define LUSTRE_SUPER_MAGIC 0x0BD00BD1
1631 static int server_fill_super_common(struct super_block *sb)
1633 struct inode *root = 0;
1636 CDEBUG(D_MOUNT, "Server sb, dev=%d\n", (int)sb->s_dev);
1638 sb->s_blocksize = 4096;
1639 sb->s_blocksize_bits = log2(sb->s_blocksize);
1640 sb->s_magic = LUSTRE_SUPER_MAGIC;
1641 sb->s_maxbytes = 0; /* we don't allow file IO on server mountpoints */
1642 sb->s_flags |= MS_RDONLY;
1643 sb->s_op = &server_ops;
1645 root = new_inode(sb);
1647 CERROR("Can't make root inode\n");
1651 /* returns -EIO for every operation */
1652 /* make_bad_inode(root); -- badness - can't umount */
1653 /* apparently we need to be a directory for the mount to finish */
1654 root->i_mode = S_IFDIR;
1655 root->i_op = &server_inode_operations;
1656 sb->s_root = d_make_root(root);
1658 CERROR("%s: can't make root dentry\n", sb->s_id);
1665 static int osd_start(struct lustre_sb_info *lsi, unsigned long mflags)
1667 struct lustre_mount_data *lmd = lsi->lsi_lmd;
1668 struct obd_device *obd;
1669 struct dt_device_param p;
1675 "Attempting to start %s, type=%s, lsifl=%x, mountfl=%lx\n",
1676 lsi->lsi_svname, lsi->lsi_osd_type, lsi->lsi_flags, mflags);
1678 sprintf(lsi->lsi_osd_obdname, "%s-osd", lsi->lsi_svname);
1679 strcpy(lsi->lsi_osd_uuid, lsi->lsi_osd_obdname);
1680 strcat(lsi->lsi_osd_uuid, "_UUID");
1681 sprintf(flagstr, "%lu:%lu", mflags, (unsigned long) lmd->lmd_flags);
1683 obd = class_name2obd(lsi->lsi_osd_obdname);
1685 rc = lustre_start_simple(lsi->lsi_osd_obdname,
1687 lsi->lsi_osd_uuid, lmd->lmd_dev,
1688 flagstr, lsi->lsi_lmd->lmd_opts,
1692 obd = class_name2obd(lsi->lsi_osd_obdname);
1695 CDEBUG(D_MOUNT, "%s already started\n", lsi->lsi_osd_obdname);
1696 /* but continue setup to allow special case of MDT and internal
1697 * MGT being started separately. */
1698 if (!((IS_MGS(lsi) && (lsi->lsi_lmd->lmd_flags &
1700 (IS_MDT(lsi) && (lsi->lsi_lmd->lmd_flags &
1705 rc = obd_connect(NULL, &lsi->lsi_osd_exp,
1706 obd, &obd->obd_uuid, NULL, NULL);
1708 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 10);
1712 class_manual_cleanup(obd);
1713 lsi->lsi_dt_dev = NULL;
1717 LASSERT(obd->obd_lu_dev);
1718 lu_device_get(obd->obd_lu_dev);
1719 lsi->lsi_dt_dev = lu2dt_dev(obd->obd_lu_dev);
1720 LASSERT(lsi->lsi_dt_dev);
1722 /* set disk context for llog usage */
1723 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
1724 obd->obd_lvfs_ctxt.dt = lsi->lsi_dt_dev;
1726 dt_conf_get(NULL, lsi->lsi_dt_dev, &p);
1731 /** Fill in the superblock info for a Lustre server.
1732 * Mount the device with the correct options.
1733 * Read the on-disk config file.
1734 * Start the services.
1736 int server_fill_super(struct super_block *sb)
1738 struct lustre_sb_info *lsi = s2lsi(sb);
1742 rc = lsi_prepare(lsi);
1746 /* Start low level OSD */
1747 rc = osd_start(lsi, sb->s_flags);
1749 CERROR("Unable to start osd on %s: %d\n",
1750 lsi->lsi_lmd->lmd_dev, rc);
1755 CDEBUG(D_MOUNT, "Found service %s on device %s\n",
1756 lsi->lsi_svname, lsi->lsi_lmd->lmd_dev);
1758 if (class_name2obd(lsi->lsi_svname)) {
1759 LCONSOLE_ERROR_MSG(0x161, "The target named %s is already "
1760 "running. Double-mount may have compromised"
1761 " the disk journal.\n",
1767 /* Start MGS before MGC */
1768 if (IS_MGS(lsi) && !(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOMGS)) {
1769 rc = server_start_mgs(sb);
1774 /* Start MGC before servers */
1775 rc = lustre_start_mgc(sb);
1779 /* Set up all obd devices for service */
1780 if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC) &&
1781 (IS_OST(lsi) || IS_MDT(lsi))) {
1782 rc = server_start_targets(sb);
1784 CERROR("Unable to start targets: %d\n", rc);
1787 /* FIXME overmount client here, or can we just start a
1788 * client log and client_fill_super on this sb? We
1789 * need to make sure server_put_super gets called too
1790 * - ll_put_super calls lustre_common_put_super; check
1791 * there for LSI_SERVER flag, call s_p_s if so.
1793 * Probably should start client from new thread so we
1794 * can return. Client will not finish until all
1795 * servers are connected. Note - MGS-only server does
1796 * NOT get a client, since there is no lustre fs
1797 * associated - the MGS is for all lustre fs's */
1800 rc = server_fill_super_common(sb);
1806 /* We jump here in case of failure while starting targets or MGS.
1807 * In this case we can't just put @mnt and have to do real cleanup
1808 * with stoping targets, etc. */
1809 server_put_super(sb);
1814 * Calculate timeout value for a target.
1816 void server_calc_timeout(struct lustre_sb_info *lsi, struct obd_device *obd)
1818 struct lustre_mount_data *lmd;
1822 bool has_ir = !!(lsi->lsi_flags & LDD_F_IR_CAPABLE);
1823 int min = OBD_RECOVERY_TIME_MIN;
1825 LASSERT(IS_SERVER(lsi));
1829 soft = lmd->lmd_recovery_time_soft;
1830 hard = lmd->lmd_recovery_time_hard;
1831 has_ir = has_ir && !(lmd->lmd_flags & LMD_FLG_NOIR);
1832 obd->obd_no_ir = !has_ir;
1836 soft = OBD_RECOVERY_TIME_SOFT;
1838 hard = OBD_RECOVERY_TIME_HARD;
1840 /* target may have ir_factor configured. */
1841 factor = OBD_IR_FACTOR_DEFAULT;
1842 if (obd->obd_recovery_ir_factor)
1843 factor = obd->obd_recovery_ir_factor;
1846 int new_soft = soft;
1847 int new_hard = hard;
1849 /* adjust timeout value by imperative recovery */
1851 new_soft = (soft * factor) / OBD_IR_FACTOR_MAX;
1852 new_hard = (hard * factor) / OBD_IR_FACTOR_MAX;
1854 /* make sure the timeout is not too short */
1855 new_soft = max(min, new_soft);
1856 new_hard = max(new_soft, new_hard);
1858 LCONSOLE_INFO("%s: Imperative Recovery enabled, recovery "
1859 "window shrunk from %d-%d down to %d-%d\n",
1860 obd->obd_name, soft, hard, new_soft, new_hard);
1867 obd->obd_recovery_timeout = max(obd->obd_recovery_timeout, soft);
1868 obd->obd_recovery_time_hard = hard;
1869 obd->obd_recovery_ir_factor = factor;
1871 EXPORT_SYMBOL(server_calc_timeout);