Whamcloud - gitweb
Branch: HEAD
[fs/lustre-release.git] / lustre / mds / mds_lov.c
index 13d262e..6d78907 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/obd_lov.h>
 #include <linux/lustre_lib.h>
 #include <linux/lustre_fsfilt.h>
+#include <linux/lustre_sec.h>
 
 #include "mds_internal.h"
 
@@ -55,6 +56,19 @@ void cpu_to_le_lov_desc (struct lov_desc *ld)
         ld->ld_pattern = cpu_to_le32 (ld->ld_pattern);
 }
 
+void mds_dt_save_objids(struct obd_device *obd, obd_id *ids)
+{
+        struct mds_obd *mds = &obd->u.mds;
+        int i;
+        ENTRY;
+
+        spin_lock(&mds->mds_dt_lock);
+        for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
+                ids[i] = mds->mds_dt_objids[i];
+        spin_unlock(&mds->mds_dt_lock);
+        EXIT;
+}
+
 void mds_dt_update_objids(struct obd_device *obd, obd_id *ids)
 {
         struct mds_obd *mds = &obd->u.mds;
@@ -63,8 +77,8 @@ void mds_dt_update_objids(struct obd_device *obd, obd_id *ids)
 
         spin_lock(&mds->mds_dt_lock);
         for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
-                if (ids[i] > (mds->mds_dt_objids)[i])
-                        (mds->mds_dt_objids)[i] = ids[i];
+                if (ids[i] > mds->mds_dt_objids[i])
+                        mds->mds_dt_objids[i] = ids[i];
         spin_unlock(&mds->mds_dt_lock);
         EXIT;
 }
@@ -72,14 +86,15 @@ void mds_dt_update_objids(struct obd_device *obd, obd_id *ids)
 static int mds_dt_read_objids(struct obd_device *obd)
 {
         struct mds_obd *mds = &obd->u.mds;
-        obd_id *ids;
+        int i, rc, size;
         loff_t off = 0;
-        int i, rc, size = mds->mds_dt_desc.ld_tgt_count * sizeof(*ids);
+        obd_id *ids;
         ENTRY;
 
         if (mds->mds_dt_objids != NULL)
                 RETURN(0);
 
+        size = mds->mds_dt_desc.ld_tgt_count * sizeof(*ids);
         OBD_ALLOC(ids, size);
         if (ids == NULL)
                 RETURN(-ENOMEM);
@@ -87,17 +102,19 @@ static int mds_dt_read_objids(struct obd_device *obd)
 
         if (mds->mds_dt_objid_filp->f_dentry->d_inode->i_size == 0)
                 RETURN(0);
+        
         rc = fsfilt_read_record(obd, mds->mds_dt_objid_filp, ids, size, &off);
         if (rc < 0) {
-                CERROR("Error reading objids %d\n", rc);
+                CERROR("error reading objids %d\n", rc);
         } else {
                 mds->mds_dt_objids_valid = 1;
                 rc = 0;
         }
 
-        for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
-                CDEBUG(D_INFO, "read last object "LPU64" for idx %d\n",
-                       mds->mds_dt_objids[i], i);
+        for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++) {
+                CDEBUG(D_INFO, "read last object "LPU64
+                       " for idx %d\n", mds->mds_dt_objids[i], i);
+        }
 
         RETURN(rc);
 }
@@ -105,25 +122,26 @@ static int mds_dt_read_objids(struct obd_device *obd)
 int mds_dt_write_objids(struct obd_device *obd)
 {
         struct mds_obd *mds = &obd->u.mds;
+        int i, rc, size;
         loff_t off = 0;
-        int i, rc, size = mds->mds_dt_desc.ld_tgt_count * sizeof(obd_id);
         ENTRY;
 
         for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
                 CDEBUG(D_INFO, "writing last object "LPU64" for idx %d\n",
                        mds->mds_dt_objids[i], i);
 
+        size = mds->mds_dt_desc.ld_tgt_count * sizeof(obd_id);
         rc = fsfilt_write_record(obd, mds->mds_dt_objid_filp,
                                  mds->mds_dt_objids, size, &off, 0);
         RETURN(rc);
 }
 
-int mds_dt_clearorphans(struct mds_obd *mds, struct obd_uuid *ost_uuid)
+int mds_dt_clear_orphans(struct mds_obd *mds, struct obd_uuid *ost_uuid)
 {
-        int rc;
+        struct lov_stripe_md *empty_ea = NULL;
+        struct obd_trans_info oti = { 0 };
         struct obdo *oa = NULL;
-        struct obd_trans_info oti = {0};
-        struct lov_stripe_md  *empty_ea = NULL;
+        int rc;
         ENTRY;
 
         LASSERT(mds->mds_dt_objids != NULL);
@@ -138,32 +156,27 @@ int mds_dt_clearorphans(struct mds_obd *mds, struct obd_uuid *ost_uuid)
                 RETURN(-ENOMEM);
         
         memset(oa, 0, sizeof(*oa));
+
         oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
         oa->o_valid = OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
         oa->o_flags = OBD_FL_DELORPHAN;
         
         if (ost_uuid != NULL) {
-                memcpy(&oa->o_inline, ost_uuid, sizeof(*ost_uuid));
+                memcpy(&oa->o_inline, ost_uuid,
+                       sizeof(*ost_uuid));
                 oa->o_valid |= OBD_MD_FLINLINE;
         }
-        rc = obd_create(mds->mds_dt_exp, oa, &empty_ea, &oti);
-        obdo_free(oa);
-        RETURN(rc);
-}
-
-/* update the LOV-OSC knowledge of the last used object id's */
-int mds_dt_set_nextid(struct obd_device *obd)
-{
-        struct mds_obd *mds = &obd->u.mds;
-        int rc;
-        ENTRY;
-
-        LASSERT(!obd->obd_recovering);
-
-        LASSERT(mds->mds_dt_objids != NULL);
 
-        rc = obd_set_info(mds->mds_dt_exp, strlen("next_id"), "next_id",
-                          mds->mds_dt_desc.ld_tgt_count, mds->mds_dt_objids);
+        /* 
+         * passing current objids for letting data layer know last objids MDS
+         * knows about and do appropriate. --umka
+         */
+        oti.oti_objid = mds->mds_dt_objids;
+        
+        rc = obd_create(mds->mds_dt_exp, oa,
+                        NULL, 0, &empty_ea, &oti);
+        
+        obdo_free(oa);
         RETURN(rc);
 }
 
@@ -182,12 +195,14 @@ int mds_dt_set_growth(struct mds_obd *mds, int count)
 static int mds_dt_update_desc(struct obd_device *obd, struct obd_export *lov)
 {
         struct mds_obd *mds = &obd->u.mds;
-        int valsize = sizeof(mds->mds_dt_desc), rc, i;
-        int old_count = mds->mds_dt_desc.ld_tgt_count;
+        __u32 valsize = sizeof(mds->mds_dt_desc);
+        int old_count, rc = 0, i;
         ENTRY;
 
-        rc = obd_get_info(lov, strlen("lovdesc") + 1, "lovdesc", &valsize,
-                          &mds->mds_dt_desc);
+        old_count = mds->mds_dt_desc.ld_tgt_count;
+        
+        rc = obd_get_info(lov, strlen("lovdesc") + 1, "lovdesc",
+                          &valsize, &mds->mds_dt_desc);
         if (rc)
                 RETURN(rc);
 
@@ -221,11 +236,12 @@ static int mds_dt_update_desc(struct obd_device *obd, struct obd_export *lov)
         RETURN(0);
 }
 
-int mds_dt_connect(struct obd_device *obd, char * lov_name)
+int mds_dt_connect(struct obd_device *obd, char *lov_name)
 {
         struct mds_obd *mds = &obd->u.mds;
-        struct lustre_handle conn = {0,};
-        int rc, i;
+        struct lustre_handle conn = { 0 };
+        unsigned long sec_flags = PTLRPC_SEC_FL_MDS;
+        int i, rc = 0;
         ENTRY;
 
         if (IS_ERR(mds->mds_dt_obd))
@@ -252,10 +268,18 @@ int mds_dt_connect(struct obd_device *obd, char * lov_name)
                 }
         }
 
+        rc = obd_set_info(mds->mds_dt_obd->obd_self_export,
+                          strlen("sec_flags"), "sec_flags",
+                          sizeof(sec_flags), &sec_flags);
+        if (rc) {
+                mds->mds_dt_obd = ERR_PTR(rc);
+                RETURN(rc);
+        }
+
         CDEBUG(D_HA, "obd: %s osc: %s lov_name: %s\n",
                obd->obd_name, mds->mds_dt_obd->obd_name, lov_name);
 
-        rc = obd_connect(&conn, mds->mds_dt_obd, &obd->obd_uuid,
+        rc = obd_connect(&conn, mds->mds_dt_obd, &obd->obd_uuid, NULL,
                          mds->mds_num + FILTER_GROUP_FIRST_MDS);
         if (rc) {
                 CERROR("MDS cannot connect to LOV %s (%d)\n", lov_name, rc);
@@ -288,10 +312,13 @@ int mds_dt_connect(struct obd_device *obd, char * lov_name)
                 GOTO(err_reg, rc);
         }
 
-        /* If we're mounting this code for the first time on an existing FS,
-         * we need to populate the objids array from the real OST values */
+        /*
+         * If we're mounting this code for the first time on an existing FS, we
+         * need to populate the objids array from the real OST values.
+         */
         if (!mds->mds_dt_objids_valid) {
-                int size = sizeof(obd_id) * mds->mds_dt_desc.ld_tgt_count;
+                __u32 size = sizeof(obd_id) * mds->mds_dt_desc.ld_tgt_count;
+                
                 rc = obd_get_info(mds->mds_dt_exp, strlen("last_id"),
                                   "last_id", &size, mds->mds_dt_objids);
                 if (!rc) {
@@ -306,21 +333,37 @@ int mds_dt_connect(struct obd_device *obd, char * lov_name)
                 }
         }
 
-        /* I want to see a callback happen when the OBD moves to a
-         * "For General Use" state, and that's when we'll call
-         * set_nextid().  The class driver can help us here, because
-         * it can use the obd_recovering flag to determine when the
-         * the OBD is full available. */
-        if (!obd->obd_recovering)
-                rc = mds_postrecov(obd);
+        /*
+         * I want to see a callback happen when the OBD moves to a "For General
+         * Use" state, and that's when we'll call set_nextid(). The class driver
+         * can help us here, because it can use the obd_recovering flag to
+         * determine when the the OBD is full available.
+         */
+        if (!obd->obd_recovering) {
+                CDEBUG(D_OTHER, "call mds_postrecov_common()\n");
+                rc = mds_postrecov_common(obd);
+                if (rc < 0)
+                        GOTO(err_reg, rc);
+                rc = 0;
+        }
+
+        for (i = 0; i < 2; i++) {
+                if (!mds->mds_capa_keys[i].k_key)
+                        break;
+                rc = obd_set_info(mds->mds_dt_exp, strlen("capa_key"),
+                                  "capa_key", sizeof(struct lustre_capa_key),
+                                  mds->mds_capa_keys[i].k_key);
+                if (rc)
+                        GOTO(err_reg, rc);
+        }
         RETURN(rc);
 
 err_reg:
         obd_register_observer(mds->mds_dt_obd, NULL);
 err_discon:
         obd_disconnect(mds->mds_dt_exp, 0);
-        mds->mds_dt_exp = NULL;
         mds->mds_dt_obd = ERR_PTR(rc);
+        mds->mds_dt_exp = NULL;
         return rc;
 }
 
@@ -487,7 +530,7 @@ int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 LASSERT(handle);
                 rc = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 1);
 
-                dev_set_rdonly(ll_sbdev(obd->u.mds.mds_sb), 2);
+                ll_set_rdonly(ll_sbdev(obd->u.mds.mds_sb));
                 RETURN(0);
         }
 
@@ -583,11 +626,8 @@ int mds_dt_synchronize(void *data)
         struct obd_uuid *uuid;
         obd_id vals[2];
         unsigned long flags;
-        __u32  vallen;
-        __u32  group;
-        int old_count;
-        int count;
-        int index;
+        __u32  vallen, group;
+        int old_count, count, index, i;
         int rc;
         char name[32] = "CATLIST";
 
@@ -615,6 +655,8 @@ int mds_dt_synchronize(void *data)
         down(&mds->mds_orphan_recovery_sem);
 
         uuid = &watched->u.cli.cl_import->imp_target_uuid;
+        CWARN("MDS %s: %s now active, repairing the connection\n",
+              obd->obd_name, uuid->uuid);
 
         group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
         rc = obd_set_info(watched->obd_self_export, strlen("mds_conn"),
@@ -637,11 +679,25 @@ int mds_dt_synchronize(void *data)
         if (rc)
                 GOTO(cleanup, rc);
 
+        for (i = 0; i < 2; i++) {
+                if (!mds->mds_capa_keys[i].k_key)
+                        break;
+                rc = obd_set_info(mds->mds_dt_exp, strlen("capa_key"),
+                                  "capa_key", sizeof(struct lustre_capa_key),
+                                  mds->mds_capa_keys[i].k_key);
+                if (rc)
+                        GOTO(cleanup, rc);
+        }
+
+        /* we don't set next id manually, instead OSCs will set them
+         * during own recovery from DELORPHAN reply -bzzz */
+#if 0
         vals[0] = index;
         rc = mds_dt_set_info(obd->obd_self_export, strlen("next_id"),
                              "next_id", 2, vals);
         if (rc)
                 GOTO(cleanup, rc);
+#endif
 
         obd_llog_finish(obd, &obd->obd_llogs, old_count);
         obd_llog_cat_initialize(obd, &obd->obd_llogs, count, name);
@@ -659,9 +715,9 @@ int mds_dt_synchronize(void *data)
         CWARN("MDS %s: %s now active, resetting orphans\n",
               obd->obd_name, uuid->uuid);
 
-        rc = mds_dt_clearorphans(&obd->u.mds, uuid);
+        rc = mds_dt_clear_orphans(&obd->u.mds, uuid);
         if (rc != 0) {
-                CERROR("%s: failed at mds_dt_clearorphans(): %d\n", 
+                CERROR("%s: failed at mds_dt_clear_orphans(): %d\n", 
                        obd->obd_name, rc);
                 GOTO(cleanup, rc);
         }
@@ -712,10 +768,10 @@ int mds_notify(struct obd_device *obd, struct obd_device *watched,
         if (!active)
                 RETURN(0);
 
-        if (!strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME))
+        if (!strcmp(watched->obd_type->typ_name, OBD_MDC_DEVICENAME))
                 RETURN(0);
 
-        if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
+        if (strcmp(watched->obd_type->typ_name, OBD_OSC_DEVICENAME)) {
                 CERROR("unexpected notification of %s %s!\n",
                        watched->obd_type->typ_name, watched->obd_name);
                 RETURN(-EINVAL);
@@ -771,15 +827,15 @@ int mds_dt_update_config(struct obd_device *obd, int clean)
 {
         struct mds_obd *mds = &obd->u.mds;
         struct lvfs_run_ctxt saved;
-        struct config_llog_instance cfg;
         struct llog_ctxt *ctxt;
+        struct config_llog_instance cfg;
         char *profile = mds->mds_profile, *name;
-        int rc, version, namelen;
+         int rc, version, namelen, value;
+        __u32 valsize;
         ENTRY;
 
         if (profile == NULL)
                 RETURN(0);
-
         cfg.cfg_instance = NULL;
         cfg.cfg_uuid = mds->mds_dt_uuid;
 
@@ -787,7 +843,6 @@ int mds_dt_update_config(struct obd_device *obd, int clean)
         OBD_ALLOC(name, namelen);
         if (name == NULL)
                 RETURN(-ENOMEM);
-
         if (clean) {
                 version = mds->mds_config_version - 1;
                 sprintf(name, "%s-clean-%d", profile, version);
@@ -795,17 +850,28 @@ int mds_dt_update_config(struct obd_device *obd, int clean)
                 version = mds->mds_config_version + 1;
                 sprintf(name, "%s-%d", profile, version);
         }
-
         CWARN("Applying configuration log %s\n", name);
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
         ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
         rc = class_config_process_llog(ctxt, name, &cfg);
         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        if (rc == 0)
-                mds->mds_config_version = version;
         CWARN("Finished applying configuration log %s: %d\n", name, rc);
+        if (rc != 0) { 
+                GOTO(exit, rc);
+        }
+        /* retrieve size of EA */
+        rc = obd_get_info(mds->mds_md_exp, strlen("mdsize"),
+                          "mdsize", &valsize, &value);
+        
+        if (value > mds->mds_max_mdsize)
+                mds->mds_max_mdsize = value;
 
+        CDEBUG(D_INFO, "mds max md size %d \n", mds->mds_max_mdsize);
+        
+        if (rc == 0)
+                mds->mds_config_version = version;
+exit:
         OBD_FREE(name, namelen);
         RETURN(rc);
 }