- /* The MGC has no recoverable data in any case.
- * force shotdown set in umount_begin */
- obd->obd_no_recov = 1;
-
- if (obd->u.cli.cl_mgc_mgsexp) {
- /* An error is not fatal, if we are unable to send the
- disconnect mgs ping evictor cleans up the export */
- rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
- if (rc)
- CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
- }
-
- /* Save the obdname for cleaning the nid uuids, which are
- obdname_XX */
- len = strlen(obd->obd_name) + 6;
- OBD_ALLOC(niduuid, len);
- if (niduuid) {
- strcpy(niduuid, obd->obd_name);
- ptr = niduuid + strlen(niduuid);
- }
-
- rc = class_manual_cleanup(obd);
- if (rc)
- GOTO(out, rc);
-
- /* Clean the nid uuids */
- if (!niduuid)
- GOTO(out, rc = -ENOMEM);
-
- for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
- sprintf(ptr, "_%x", i);
- rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
- niduuid, 0, 0, 0);
- if (rc)
- CERROR("del MDC UUID %s failed: rc = %d\n",
- niduuid, rc);
- }
-out:
- if (niduuid)
- OBD_FREE(niduuid, len);
-
- /* class_import_put will get rid of the additional connections */
- cfs_mutex_unlock(&mgc_start_lock);
- RETURN(rc);
-}
-
-/* Since there's only one mgc per node, we have to change it's fs to get
- access to the right disk. */
-static int server_mgc_set_fs(struct obd_device *mgc, struct super_block *sb)
-{
- struct lustre_sb_info *lsi = s2lsi(sb);
- int rc;
- ENTRY;
-
- CDEBUG(D_MOUNT, "Set mgc disk for %s\n", lsi->lsi_lmd->lmd_dev);
-
- /* cl_mgc_sem in mgc insures we sleep if the mgc_fs is busy */
- rc = obd_set_info_async(NULL, mgc->obd_self_export,
- sizeof(KEY_SET_FS), KEY_SET_FS,
- sizeof(*sb), sb, NULL);
- if (rc) {
- CERROR("can't set_fs %d\n", rc);
- }
-
- RETURN(rc);
-}
-
-static int server_mgc_clear_fs(struct obd_device *mgc)
-{
- int rc;
- ENTRY;
-
- CDEBUG(D_MOUNT, "Unassign mgc disk\n");
-
- rc = obd_set_info_async(NULL, mgc->obd_self_export,
- sizeof(KEY_CLEAR_FS), KEY_CLEAR_FS,
- 0, NULL, NULL);
- RETURN(rc);
-}
-
-CFS_DEFINE_MUTEX(server_start_lock);
-
-/* Stop MDS/OSS if nobody is using them */
-static int server_stop_servers(int lsiflags)
-{
- struct obd_device *obd = NULL;
- struct obd_type *type = NULL;
- int rc = 0;
- ENTRY;
-
- cfs_mutex_lock(&server_start_lock);
-
- /* Either an MDT or an OST or neither */
- /* if this was an MDT, and there are no more MDT's, clean up the MDS */
- if ((lsiflags & LDD_F_SV_TYPE_MDT) &&
- (obd = class_name2obd(LUSTRE_MDS_OBDNAME))) {
- /*FIXME pre-rename, should eventually be LUSTRE_MDT_NAME*/
- type = class_search_type(LUSTRE_MDS_NAME);
- }
- /* if this was an OST, and there are no more OST's, clean up the OSS */
- if ((lsiflags & LDD_F_SV_TYPE_OST) &&
- (obd = class_name2obd(LUSTRE_OSS_OBDNAME))) {
- type = class_search_type(LUSTRE_OST_NAME);
- }
-
- if (obd && (!type || !type->typ_refcnt)) {
- int err;
- obd->obd_force = 1;
- /* obd_fail doesn't mean much on a server obd */
- err = class_manual_cleanup(obd);
- if (!rc)
- rc = err;
- }
-
- cfs_mutex_unlock(&server_start_lock);
-
- RETURN(rc);
-}
-
-int server_mti_print(char *title, struct mgs_target_info *mti)
-{
- PRINT_CMD(PRINT_MASK, "mti %s\n", title);
- PRINT_CMD(PRINT_MASK, "server: %s\n", mti->mti_svname);
- PRINT_CMD(PRINT_MASK, "fs: %s\n", mti->mti_fsname);
- PRINT_CMD(PRINT_MASK, "uuid: %s\n", mti->mti_uuid);
- PRINT_CMD(PRINT_MASK, "ver: %d flags: %#x\n",
- mti->mti_config_ver, mti->mti_flags);
- return(0);
-}
-
-/** Get the fsname ("lustre") from the server name ("lustre-OST003F").
- * @param [in] svname server name including type and index
- * @param [out] fsname Buffer to copy filesystem name prefix into.
- * Must have at least 'strlen(fsname) + 1' chars.
- * @param [out] endptr if endptr isn't NULL it is set to end of fsname
- * rc < 0 on error
- */
-static int server_name2fsname(char *svname, char *fsname, char **endptr)
-{
- char *p;
-
- p = strstr(svname, "-OST");
- if (p == NULL)
- p = strstr(svname, "-MDT");
- if (p == NULL)
- return -1;
-
- if (fsname) {
- strncpy(fsname, svname, p - svname);
- fsname[p - svname] = '\0';
- }
-
- if (endptr != NULL)
- *endptr = p;
-
- return 0;
-}
-
-/**
- * Get service name (svname) from string
- * rc < 0 on error
- * if endptr isn't NULL it is set to end of fsname *
- */
-int server_name2svname(char *label, char *svname, char **endptr)
-{
- int rc;
- char *dash;
-
- /* We use server_name2fsname() just for parsing */
- rc = server_name2fsname(label, NULL, &dash);
- if (rc != 0)
- return rc;
-
- if (*dash != '-')
- return -1;
-
- strncpy(svname, dash + 1, MTI_NAME_MAXLEN);
-
- return 0;
-}
-EXPORT_SYMBOL(server_name2svname);
-
-
-/* Get the index from the obd name.
- rc = server type, or
- rc < 0 on error
- if endptr isn't NULL it is set to end of name */
-int server_name2index(char *svname, __u32 *idx, char **endptr)
-{
- unsigned long index;
- int rc;
- char *dash;
-
- /* We use server_name2fsname() just for parsing */
- rc = server_name2fsname(svname, NULL, &dash);
- if (rc != 0)
- return rc;
-
- if (*dash != '-')
- return -EINVAL;
-
- dash++;
-
- if (strncmp(dash, "MDT", 3) == 0)
- rc = LDD_F_SV_TYPE_MDT;
- else if (strncmp(dash, "OST", 3) == 0)
- rc = LDD_F_SV_TYPE_OST;
- else
- return -EINVAL;
-
- dash += 3;
-
- if (strcmp(dash, "all") == 0)
- return rc | LDD_F_SV_ALL;
-
- index = simple_strtoul(dash, endptr, 16);
- *idx = index;
-
- return rc;
-}
-EXPORT_SYMBOL(server_name2index);
-
-/* Generate data for registration */
-static int server_lsi2mti(struct lustre_sb_info *lsi,
- struct mgs_target_info *mti)
-{
- lnet_process_id_t id;
- int rc, i = 0;
- ENTRY;
-
- if (!IS_SERVER(lsi))
- RETURN(-EINVAL);
-
- strncpy(mti->mti_svname, lsi->lsi_svname, sizeof(mti->mti_svname));
-
- mti->mti_nid_count = 0;
- while (LNetGetId(i++, &id) != -ENOENT) {
- if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
- continue;
-
- /* server use --servicenode param, only allow specified
- * nids be registered */
- if ((lsi->lsi_lmd->lmd_flags & LMD_FLG_NO_PRIMNODE) != 0 &&
- class_match_nid(lsi->lsi_lmd->lmd_params,
- PARAM_FAILNODE, id.nid) < 1)
- continue;
-
- /* match specified network */
- if (!class_match_net(lsi->lsi_lmd->lmd_params,
- PARAM_NETWORK, LNET_NIDNET(id.nid)))
- continue;
-
- mti->mti_nids[mti->mti_nid_count] = id.nid;
- mti->mti_nid_count++;
- if (mti->mti_nid_count >= MTI_NIDS_MAX) {
- CWARN("Only using first %d nids for %s\n",
- mti->mti_nid_count, mti->mti_svname);
- break;
- }
- }
-
- mti->mti_lustre_ver = LUSTRE_VERSION_CODE;
- mti->mti_config_ver = 0;
-
- rc = server_name2fsname(lsi->lsi_svname, mti->mti_fsname, NULL);
- if (rc != 0)
- return rc;
-
- rc = server_name2index(lsi->lsi_svname, &mti->mti_stripe_index, NULL);
- if (rc < 0)
- return rc;
- /* Orion requires index to be set */
- LASSERT(!(rc & LDD_F_NEED_INDEX));
- /* keep only LDD flags */
- mti->mti_flags = lsi->lsi_flags & LDD_F_MASK;
- mti->mti_flags |= LDD_F_UPDATE;
- strncpy(mti->mti_params, lsi->lsi_lmd->lmd_params,
- sizeof(mti->mti_params));
- return 0;
-}
-
-/* Register an old or new target with the MGS. If needed MGS will construct
- startup logs and assign index */
-static int server_register_target(struct lustre_sb_info *lsi)
-{
- struct obd_device *mgc = lsi->lsi_mgc;
- struct mgs_target_info *mti = NULL;
- bool writeconf;
- int rc;
- ENTRY;
-
- LASSERT(mgc);
-
- if (!IS_SERVER(lsi))
- RETURN(-EINVAL);
-
- OBD_ALLOC_PTR(mti);
- if (!mti)
- RETURN(-ENOMEM);
-
- rc = server_lsi2mti(lsi, mti);
- if (rc)
- GOTO(out, rc);
-
- CDEBUG(D_MOUNT, "Registration %s, fs=%s, %s, index=%04x, flags=%#x\n",
- mti->mti_svname, mti->mti_fsname,
- libcfs_nid2str(mti->mti_nids[0]), mti->mti_stripe_index,
- mti->mti_flags);
-
- /* if write_conf is true, the registration must succeed */
- writeconf = !!(lsi->lsi_flags & (LDD_F_NEED_INDEX | LDD_F_UPDATE));
- mti->mti_flags |= LDD_F_OPC_REG;
-
- /* Register the target */
- /* FIXME use mgc_process_config instead */
- rc = obd_set_info_async(NULL, mgc->u.cli.cl_mgc_mgsexp,
- sizeof(KEY_REGISTER_TARGET), KEY_REGISTER_TARGET,
- sizeof(*mti), mti, NULL);
- if (rc) {
- if (mti->mti_flags & LDD_F_ERROR) {
- LCONSOLE_ERROR_MSG(0x160,
- "The MGS is refusing to allow this "
- "server (%s) to start. Please see messages"
- " on the MGS node.\n", lsi->lsi_svname);
- } else if (writeconf) {
- LCONSOLE_ERROR_MSG(0x15f,
- "Communication to the MGS return error %d. "
- "Is the MGS running?\n", rc);
- } else {
- CERROR("Cannot talk to the MGS: %d, not fatal\n", rc);
- /* reset the error code for non-fatal error. */
- rc = 0;
- }
- GOTO(out, rc);
- }
-
-out:
- if (mti)
- OBD_FREE_PTR(mti);
- RETURN(rc);
-}
-
-/**
- * Notify the MGS that this target is ready.
- * Used by IR - if the MGS receives this message, it will notify clients.
- */
-static int server_notify_target(struct super_block *sb, struct obd_device *obd)
-{
- struct lustre_sb_info *lsi = s2lsi(sb);
- struct obd_device *mgc = lsi->lsi_mgc;
- struct mgs_target_info *mti = NULL;
- int rc;
- ENTRY;
-
- LASSERT(mgc);
-
- if (!(IS_SERVER(lsi)))
- RETURN(-EINVAL);
-
- OBD_ALLOC_PTR(mti);
- if (!mti)
- RETURN(-ENOMEM);
- rc = server_lsi2mti(lsi, mti);
- if (rc)
- GOTO(out, rc);
-
- mti->mti_instance = obd->u.obt.obt_instance;
- mti->mti_flags |= LDD_F_OPC_READY;
-
- /* FIXME use mgc_process_config instead */
- rc = obd_set_info_async(NULL, mgc->u.cli.cl_mgc_mgsexp,
- sizeof(KEY_REGISTER_TARGET),
- KEY_REGISTER_TARGET,
- sizeof(*mti), mti, NULL);
-
- /* Imperative recovery: if the mgs informs us to use IR? */
- if (!rc && !(mti->mti_flags & LDD_F_ERROR) &&
- (mti->mti_flags & LDD_F_IR_CAPABLE))
- lsi->lsi_flags |= LDD_F_IR_CAPABLE;
-
-out:
- if (mti)
- OBD_FREE_PTR(mti);
- RETURN(rc);
-
-}
-
-/** Start server targets: MDTs and OSTs
- */
-static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
-{
- struct obd_device *obd;
- struct lustre_sb_info *lsi = s2lsi(sb);
- struct config_llog_instance cfg;
- struct lu_env env;
- struct lu_device *dev;
- int rc;
- ENTRY;
-
- CDEBUG(D_MOUNT, "starting target %s\n", lsi->lsi_svname);
-
-#if 0
- /* If we're an MDT, make sure the global MDS is running */
- if (lsi->lsi_ldd->ldd_flags & LDD_F_SV_TYPE_MDT) {
- /* make sure the MDS is started */
- cfs_mutex_lock(&server_start_lock);
- obd = class_name2obd(LUSTRE_MDS_OBDNAME);
- if (!obd) {
- rc = lustre_start_simple(LUSTRE_MDS_OBDNAME,
- /* FIXME pre-rename, should eventually be LUSTRE_MDS_NAME */
- LUSTRE_MDT_NAME,
- LUSTRE_MDS_OBDNAME"_uuid",
- 0, 0);
- if (rc) {
- cfs_mutex_unlock(&server_start_lock);
- CERROR("failed to start MDS: %d\n", rc);
- RETURN(rc);
- }
- }
- cfs_mutex_unlock(&server_start_lock);
- }
-#endif
-
- /* If we're an OST, make sure the global OSS is running */
- if (IS_OST(lsi)) {
- /* make sure OSS is started */
- cfs_mutex_lock(&server_start_lock);
- obd = class_name2obd(LUSTRE_OSS_OBDNAME);
- if (!obd) {
- rc = lustre_start_simple(LUSTRE_OSS_OBDNAME,
- LUSTRE_OSS_NAME,
- LUSTRE_OSS_OBDNAME"_uuid",
- 0, 0, 0, 0);
- if (rc) {
- cfs_mutex_unlock(&server_start_lock);
- CERROR("failed to start OSS: %d\n", rc);
- RETURN(rc);
- }
- }
- cfs_mutex_unlock(&server_start_lock);
- }
-
- /* Set the mgc fs to our server disk. This allows the MGC to
- * read and write configs locally, in case it can't talk to the MGS. */
- if (lsi->lsi_srv_mnt) {
- rc = server_mgc_set_fs(lsi->lsi_mgc, sb);
- if (rc)
- RETURN(rc);
- }
-
- /* Register with MGS */
- rc = server_register_target(lsi);
- if (rc)
- GOTO(out_mgc, rc);
-
- /* Let the target look up the mount using the target's name
- (we can't pass the sb or mnt through class_process_config.) */
- rc = server_register_mount(lsi->lsi_svname, sb, mnt);
- if (rc)
- GOTO(out_mgc, rc);
-
- /* Start targets using the llog named for the target */
- memset(&cfg, 0, sizeof(cfg));
- rc = lustre_process_log(sb, lsi->lsi_svname, &cfg);
- if (rc) {
- CERROR("failed to start server %s: %d\n",
- lsi->lsi_svname, rc);
- /* Do NOT call server_deregister_mount() here. This makes it
- * impossible to find mount later in cleanup time and leaves
- * @lsi and othder stuff leaked. -umka */
- GOTO(out_mgc, rc);
- }