From d2ab808876d0f34eb729a07c2953326907de7c30 Mon Sep 17 00:00:00 2001
From: shadow <shadow>
Date: Mon, 25 Aug 2008 05:56:15 +0000
Subject: [PATCH] Force OBD_NOTIFY_ACTIVE and OBD_NOTIFY_SYNC events to send
 index of lov target as data parameter.

Branch b1_6
b=16826
i=adilger
i=green
---
 lustre/include/obd.h |  1 -
 lustre/lov/lov_obd.c | 29 +++++++++++++++--------------
 lustre/mds/mds_lov.c | 29 +++++++----------------------
 3 files changed, 22 insertions(+), 37 deletions(-)

diff --git a/lustre/include/obd.h b/lustre/include/obd.h
index 1a231e9c41..7233d5853e 100644
--- a/lustre/include/obd.h
+++ b/lustre/include/obd.h
@@ -925,7 +925,6 @@ enum obd_cleanup_stage {
 #define KEY_LOVDESC             "lovdesc"
 #define KEY_INIT_RECOV          "initial_recov"
 #define KEY_INIT_RECOV_BACKUP   "init_recov_bk"
-#define KEY_LOV_IDX             "lov_idx"
 #define KEY_LAST_ID             "last_id"
 #define KEY_LOCK_TO_STRIPE      "lock_to_stripe"
 #define KEY_CHECKSUM            "checksum"
diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c
index 75673d4f90..3525a18dc8 100644
--- a/lustre/lov/lov_obd.c
+++ b/lustre/lov/lov_obd.c
@@ -205,7 +205,7 @@ static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                 struct obd_uuid *uuid;
 
                 LASSERT(watched);
-                
+
                 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
                         CERROR("unexpected notification of %s %s!\n",
                                watched->obd_type->typ_name,
@@ -218,12 +218,14 @@ static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                  * observer can use the OSC normally.
                  */
                 rc = lov_set_osc_active(obd, uuid, ev == OBD_NOTIFY_ACTIVE);
-                if (rc) {
+                if (rc < 0) {
                         CERROR("%sactivation of %s failed: %d\n",
                                (ev == OBD_NOTIFY_ACTIVE) ? "" : "de",
                                obd_uuid2str(uuid), rc);
                         RETURN(rc);
                 }
+                /* active event should be pass lov target index as data */
+                data = &rc;
         }
 
         /* Pass the notification up the chain. */
@@ -231,6 +233,7 @@ static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                 rc = obd_notify_observer(obd, watched, ev, data);
         } else {
                 /* NULL watched means all osc's in the lov (only for syncs) */
+                /* sync event should be send lov idx as data */
                 struct lov_obd *lov = &obd->u.lov;
                 struct obd_device *tgt_obd;
                 int i;
@@ -239,6 +242,11 @@ static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                         if (!lov->lov_tgts[i])
                                 continue;
                         tgt_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
+
+                        if ((ev == OBD_NOTIFY_SYNC) ||
+                            (ev == OBD_NOTIFY_SYNC_NONBLOCK))
+                                data = &i;
+
                         rc = obd_notify_observer(obd, tgt_obd, ev, data);
                         if (rc) {
                                 CERROR("%s: notify %s of %s failed %d\n",
@@ -555,13 +563,14 @@ out:
  *  -EINVAL  : UUID can't be found in the LOV's target list
  *  -ENOTCONN: The UUID is found, but the target connection is bad (!)
  *  -EBADF   : The UUID is found, but the OBD is the wrong type (!)
+ *  - any above 0 is lov index
  */
 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
                               int activate)
 {
         struct lov_obd *lov = &obd->u.lov;
         struct lov_tgt_desc *tgt;
-        int i, rc = 0;
+        int i = 0;
         ENTRY;
 
         CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
@@ -581,12 +590,12 @@ static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
         }
 
         if (i == lov->desc.ld_tgt_count)
-                GOTO(out, rc = -EINVAL);
+                GOTO(out, i = -EINVAL);
 
         if (lov->lov_tgts[i]->ltd_active == activate) {
                 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
                        activate ? "" : "in");
-                GOTO(out, rc);
+                GOTO(out, i);
         }
 
         CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
@@ -606,7 +615,7 @@ static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
 
  out:
         lov_putref(obd);
-        RETURN(rc);
+        RETURN(i);
 }
 
 
@@ -2874,14 +2883,6 @@ static int lov_get_info(struct obd_export *exp, __u32 keylen,
                 *desc_ret = lov->desc;
 
                 GOTO(out, rc = 0);
-        } else if (KEY_IS(KEY_LOV_IDX)) {
-                struct lov_tgt_desc *tgt;
-
-                for(i = 0; i < lov->desc.ld_tgt_count; i++) {
-                        tgt = lov->lov_tgts[i];
-                        if (tgt && obd_uuid_equals(val, &tgt->ltd_uuid))
-                                GOTO(out, rc = i);
-                }
         } else if (KEY_IS(KEY_FIEMAP)) {
                 rc = lov_fiemap(lov, keylen, key, vallen, val, lsm);
                 GOTO(out, rc);
diff --git a/lustre/mds/mds_lov.c b/lustre/mds/mds_lov.c
index 8acd5a333f..5a75a3a874 100644
--- a/lustre/mds/mds_lov.c
+++ b/lustre/mds/mds_lov.c
@@ -466,19 +466,6 @@ static int mds_lov_set_one_nextid(struct obd_device * obd, __u32 idx, obd_id *id
         RETURN(rc);
 }
 
-static __u32 mds_lov_get_idx(struct obd_export *lov,
-                             struct obd_uuid *ost_uuid)
-{
-        int rc;
-        int valsize = sizeof(ost_uuid);
-
-        rc = obd_get_info(lov, sizeof(KEY_LOV_IDX), KEY_LOV_IDX,
-                          &valsize, ost_uuid, NULL);
-        LASSERT(rc >= 0);
-
-        RETURN(rc);
-}
-
 /* Update the lov desc for a new size lov. */
 static int mds_lov_update_desc(struct obd_device *obd, struct obd_export *lov,
                                 __u32 index)
@@ -997,7 +984,6 @@ int mds_lov_start_synchronize(struct obd_device *obd,
                               void *data, int nonblock)
 {
         struct mds_lov_sync_info *mlsi;
-        struct mds_obd *mds = &obd->u.mds;
         int rc;
         struct obd_uuid *uuid;
         ENTRY;
@@ -1009,12 +995,10 @@ int mds_lov_start_synchronize(struct obd_device *obd,
         if (mlsi == NULL)
                 RETURN(-ENOMEM);
 
+        LASSERT(data);
         mlsi->mlsi_obd = obd;
         mlsi->mlsi_watched = watched;
-        if (data)
-                mlsi->mlsi_index = *(__u32 *)data;
-        else
-                mlsi->mlsi_index = mds_lov_get_idx(mds->mds_osc_exp, uuid);
+        mlsi->mlsi_index = *(__u32 *)data;
 
         /* Although class_export_get(obd->obd_self_export) would lock
            the MDS in place, since it's only a self-export
@@ -1060,8 +1044,10 @@ int mds_notify(struct obd_device *obd, struct obd_device *watched,
         case OBD_NOTIFY_ACTIVE:
                 /* lov want one or more _active_ targets for work */
                 mds_allow_cli(obd, CONFIG_TARGET);
+                /* activate event should be pass lov idx as argument */
         case OBD_NOTIFY_SYNC:
         case OBD_NOTIFY_SYNC_NONBLOCK:
+                /* sync event should be pass lov idx as argument */
                 break;
         case OBD_NOTIFY_CONFIG:
                 mds_allow_cli(obd, (unsigned long)data);
@@ -1076,16 +1062,15 @@ int mds_notify(struct obd_device *obd, struct obd_device *watched,
         }
 
         if (obd->obd_recovering) {
-                __u32 idx;
                 CWARN("MDS %s: in recovery, not resetting orphans on %s\n",
                       obd->obd_name,
                       obd_uuid2str(&watched->u.cli.cl_target_uuid));
                 /* We still have to fix the lov descriptor for ost's added
                    after the mdt in the config log.  They didn't make it into
                    mds_lov_connect. */
-                idx = mds_lov_get_idx(obd->u.mds.mds_osc_exp,
-                                      &watched->u.cli.cl_target_uuid);
-                rc = mds_lov_update_desc(obd, obd->u.mds.mds_osc_exp, idx);
+                LASSERT(data);
+                rc = mds_lov_update_desc(obd, obd->u.mds.mds_osc_exp,
+                                        *(__u32 *)data);
                 mds_allow_cli(obd, CONFIG_SYNC);
                 RETURN(rc);
         }
-- 
GitLab