- int i, rc = 0, len = 0;
- ENTRY;
-
- if (!lsi)
- RETURN(-ENOENT);
- obd = lsi->lsi_mgc;
- if (!obd)
- RETURN(-ENOENT);
- lsi->lsi_mgc = NULL;
-
- cfs_mutex_lock(&mgc_start_lock);
- LASSERT(cfs_atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
- if (!cfs_atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
- /* This is not fatal, every client that stops
- will call in here. */
- CDEBUG(D_MOUNT, "mgc still has %d references.\n",
- cfs_atomic_read(&obd->u.cli.cl_mgc_refcount));
- GOTO(out, rc = -EBUSY);
- }
-
- /* 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 lddflags, 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 ((lddflags & 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 ((lddflags & 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);
-}
-
-static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti)
-{
- struct lustre_sb_info *lsi = s2lsi(sb);
- struct lustre_disk_data *ldd = lsi->lsi_ldd;
- lnet_process_id_t id;
- int i = 0;
- ENTRY;
-
- if (!(lsi->lsi_flags & LSI_SERVER))
- RETURN(-EINVAL);
-
- strncpy(mti->mti_fsname, ldd->ldd_fsname,
- sizeof(mti->mti_fsname));
- strncpy(mti->mti_svname, ldd->ldd_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 ((ldd->ldd_flags & LDD_F_NO_PRIMNODE) != 0 &&
- class_match_nid(ldd->ldd_params,
- PARAM_FAILNODE, id.nid) < 1)
- continue;
-
- /* match specified network */
- if (!class_match_net(ldd->ldd_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;
- if (lsi->lsi_lmd->lmd_flags & LMD_FLG_WRITECONF)
- ldd->ldd_flags |= LDD_F_WRITECONF;
- mti->mti_flags = ldd->ldd_flags;
- mti->mti_stripe_index = ldd->ldd_svindex;
- memcpy(mti->mti_uuid, ldd->ldd_uuid, sizeof(mti->mti_uuid));
- if (strlen(ldd->ldd_params) > sizeof(mti->mti_params)) {
- CERROR("params too big for mti\n");
- RETURN(-ENOMEM);
- }
- memcpy(mti->mti_params, ldd->ldd_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 */
-int server_register_target(struct super_block *sb)
-{
- struct lustre_sb_info *lsi = s2lsi(sb);
- struct obd_device *mgc = lsi->lsi_mgc;
- struct lustre_disk_data *ldd = lsi->lsi_ldd;
- struct mgs_target_info *mti = NULL;
- bool writeconf;
- int rc;
- ENTRY;
-
- LASSERT(mgc);
-
- if (!(lsi->lsi_flags & LSI_SERVER))
- RETURN(-EINVAL);
-
- OBD_ALLOC_PTR(mti);
- if (!mti)
- RETURN(-ENOMEM);
- rc = server_sb2mti(sb, 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 = !!(ldd->ldd_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", ldd->ldd_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);
- }
-
- /* Always update our flags */
- ldd->ldd_flags = mti->mti_flags & LDD_F_ONDISK_MASK;
-
- /* If this flag is set, it means the MGS wants us to change our
- on-disk data. (So far this means just the index.) */
- if (mti->mti_flags & LDD_F_REWRITE_LDD) {
- char *label;
- int err;
- CDEBUG(D_MOUNT, "Changing on-disk index from %#x to %#x "
- "for %s\n", ldd->ldd_svindex, mti->mti_stripe_index,
- mti->mti_svname);
- ldd->ldd_svindex = mti->mti_stripe_index;
- strncpy(ldd->ldd_svname, mti->mti_svname,
- sizeof(ldd->ldd_svname));
- /* or ldd_make_sv_name(ldd); */
- ldd_write(&mgc->obd_lvfs_ctxt, ldd);
- err = fsfilt_set_label(mgc, lsi->lsi_srv_mnt->mnt_sb,
- mti->mti_svname);
- if (err)
- CERROR("Label set error %d\n", err);
- label = fsfilt_get_label(mgc, lsi->lsi_srv_mnt->mnt_sb);
- if (label)
- CDEBUG(D_MOUNT, "Disk label changed to %s\n", label);
-
- /* Flush the new ldd to disk */
- fsfilt_sync(mgc, lsi->lsi_srv_mnt->mnt_sb);
- }
-
-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 (!(lsi->lsi_flags & LSI_SERVER))
- RETURN(-EINVAL);
-
- OBD_ALLOC_PTR(mti);
- if (!mti)
- RETURN(-ENOMEM);
- rc = server_sb2mti(sb, 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 |= LSI_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;
- int rc;