- /* It's good; let handle2md succeed and add to active mds */
- lnet_res_lh_initialize(&the_lnet.ln_md_container, &lmd->md_lh);
- LASSERT(cfs_list_empty(&lmd->md_list));
- cfs_list_add(&lmd->md_list, &the_lnet.ln_md_container.rec_active);
+/* must be called with resource lock held */
+static int
+lnet_md_link(lnet_libmd_t *md, lnet_handle_eq_t eq_handle)
+{
+ struct lnet_res_container *container = &the_lnet.ln_md_container;
+
+ /* NB we are passed an allocated, but inactive md.
+ * if we return success, caller may lnet_md_unlink() it.
+ * otherwise caller may only lnet_md_free() it.
+ */
+ /* This implementation doesn't know how to create START events or
+ * disable END events. Best to LASSERT our caller is compliant so
+ * we find out quickly... */
+ /* TODO - reevaluate what should be here in light of
+ * the removal of the start and end events
+ * maybe there we shouldn't even allow LNET_EQ_NONE!)
+ * LASSERT (eq == NULL);
+ */
+ if (!LNetHandleIsInvalid(eq_handle)) {
+ md->md_eq = lnet_handle2eq(&eq_handle);
+
+ if (md->md_eq == NULL)
+ return -ENOENT;
+
+ md->md_eq->eq_refcount++;
+ }
+
+ lnet_res_lh_initialize(container, &md->md_lh);
+
+ LASSERT(cfs_list_empty(&md->md_list));
+ cfs_list_add(&md->md_list, &container->rec_active);