- rc = lov_expand_targets(env, ld);
- if (rc == 0 && ld->ld_flags & LOV_DEV_INITIALIZED) {
- LASSERT(dev->ld_site != NULL);
-
- cl = cl_type_setup(env, dev->ld_site, &lovsub_device_type,
- tgt->ltd_obd->obd_lu_dev);
- if (!IS_ERR(cl)) {
- lsd = cl2lovsub_dev(cl);
- lsd->acid_idx = index;
- lsd->acid_super = ld;
- ld->ld_target[index] = lsd;
- } else {
- CERROR("add failed (%d), deleting %s\n", rc,
- obd_uuid2str(&tgt->ltd_uuid));
- lov_cl_del_target(env, dev, index);
- rc = PTR_ERR(cl);
- }
- }
- obd_putref(obd);
- RETURN(rc);
+ lov_tgts_putref(obd);
+
+ RETURN(rc);
+}
+
+/**
+ * Add new MDC target device in LOV.
+ *
+ * This function is part of the configuration log processing. It adds new MDC
+ * device to the MDC device array indexed by their indexes.
+ *
+ * \param[in] env execution environment
+ * \param[in] d LU device of LOV device
+ * \param[in] mdc MDC device to add
+ * \param[in] idx MDC device index
+ *
+ * \retval 0 if successful
+ * \retval negative value on error
+ */
+static int lov_add_mdc_target(const struct lu_env *env, struct lu_device *d,
+ struct obd_device *mdc, __u32 idx)
+{
+ struct lov_device *ld = lu2lov_dev(d);
+ struct obd_device *lov_obd = d->ld_obd;
+ struct obd_device *lmv_obd;
+ int next;
+ int rc = 0;
+
+ ENTRY;
+
+ LASSERT(mdc != NULL);
+ if (ld->ld_md_tgts_nr == LOV_MDC_TGT_MAX) {
+ /*
+ * If the maximum value of LOV_MDC_TGT_MAX will become too
+ * small then all MD target handling must be rewritten in LOD
+ * manner, check lod_add_device() and related functionality.
+ */
+ CERROR("%s: cannot serve more than %d MDC devices\n",
+ lov_obd->obd_name, LOV_MDC_TGT_MAX);
+ RETURN(-ERANGE);
+ }
+
+ /*
+ * grab FLD from lmv, do that here, when first MDC is added
+ * to be sure LMV is set up and can be found
+ */
+ if (!ld->ld_lmv) {
+ next = 0;
+ while ((lmv_obd = class_devices_in_group(&lov_obd->obd_uuid,
+ &next)) != NULL) {
+ if ((strncmp(lmv_obd->obd_type->typ_name,
+ LUSTRE_LMV_NAME,
+ strlen(LUSTRE_LMV_NAME)) == 0))
+ break;
+ }
+ if (!lmv_obd) {
+ CERROR("%s: cannot find LMV OBD by UUID (%s)\n",
+ lov_obd->obd_name,
+ obd_uuid2str(&lmv_obd->obd_uuid));
+ RETURN(-ENODEV);
+ }
+ spin_lock(&lmv_obd->obd_dev_lock);
+ class_incref(lmv_obd, "lov", ld);
+ spin_unlock(&lmv_obd->obd_dev_lock);
+ ld->ld_lmv = lmv_obd;
+ }
+
+ LASSERT(lov_obd->u.lov.lov_mdc_tgts[ld->ld_md_tgts_nr].lmtd_mdc ==
+ NULL);
+
+ if (ld->ld_flags & LOV_DEV_INITIALIZED) {
+ rc = lov_mdc_dev_init(env, ld, mdc->obd_lu_dev, idx,
+ ld->ld_md_tgts_nr);
+ if (rc) {
+ CERROR("%s: failed to add MDC %s as target: rc = %d\n",
+ lov_obd->obd_name, obd_uuid2str(&mdc->obd_uuid),
+ rc);
+ RETURN(rc);
+ }
+ }
+
+ lov_obd->u.lov.lov_mdc_tgts[ld->ld_md_tgts_nr].lmtd_mdc = mdc;
+ lov_obd->u.lov.lov_mdc_tgts[ld->ld_md_tgts_nr].lmtd_index = idx;
+ ld->ld_md_tgts_nr++;
+
+ RETURN(rc);