Whamcloud - gitweb
- unland b_fid to HEAD
[fs/lustre-release.git] / lustre / cobd / cache_obd.c
index fdebff1..f4072eb 100644 (file)
@@ -58,7 +58,7 @@ static int connect_to_obd(char *name, struct lustre_handle *conn)
                        obd->obd_name, name);
                 RETURN(-EINVAL);
         }
-        rc = obd_connect(conn, obd, &obd_uuid);
+        rc = obd_connect(conn, obd, &obd_uuid, 0);
         RETURN(rc);
 }
 
@@ -66,7 +66,8 @@ static int cobd_setup(struct obd_device *obd, obd_count len, void *buf)
 {
         struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
         struct cache_obd  *cobd = &obd->u.cobd;
-        struct lustre_handle real_conn = {0,}, cache_conn = {0,};
+//        struct lustre_handle real_conn = {0,}, cache_conn = {0,};
+        struct lustre_handle  cache_conn = {0,};
         struct obd_device *real;
         struct obd_device *cache;
         int rc;
@@ -109,13 +110,14 @@ static int cobd_setup(struct obd_device *obd, obd_count len, void *buf)
         memcpy(cobd->cobd_cache_name, lcfg->lcfg_inlbuf2, 
                strlen(lcfg->lcfg_inlbuf2));
 
+#if 0        
         /* don't bother checking attached/setup;
          * obd_connect() should, and it can change underneath us */
         rc = connect_to_obd(cobd->cobd_real_name, &real_conn);
         if (rc != 0)
                 GOTO(exit, rc);
         cobd->cobd_real_exp = class_conn2export(&real_conn);
-        
+#endif        
         rc = connect_to_obd(cobd->cobd_cache_name, &cache_conn);
         if (rc != 0) {
                 obd_disconnect(cobd->cobd_cache_exp, 0);
@@ -123,6 +125,7 @@ static int cobd_setup(struct obd_device *obd, obd_count len, void *buf)
         }
         cobd->cobd_cache_exp = class_conn2export(&cache_conn);
         
+        cobd->cache_on = 1;
         if (!strcmp(real->obd_type->typ_name, LUSTRE_MDC_NAME)) {
                 /* set mds_num for lustre */
                 int mds_num;
@@ -143,7 +146,6 @@ exit:
                         OBD_FREE(cobd->cobd_real_name, 
                                  strlen(cobd->cobd_real_name) + 1);
         }
-        cobd->cache_on = 1;
         RETURN(rc);
 }
 
@@ -155,9 +157,12 @@ static int cobd_cleanup(struct obd_device *obd, int flags)
         if (!list_empty(&obd->obd_exports))
                 return (-EBUSY);
         
-        OBD_FREE(cobd->cobd_cache_name, strlen(cobd->cobd_cache_name) + 1);
-        OBD_FREE(cobd->cobd_real_name, strlen(cobd->cobd_real_name) + 1);
-        
+        if (cobd->cobd_cache_name)
+                OBD_FREE(cobd->cobd_cache_name, 
+                         strlen(cobd->cobd_cache_name) + 1);
+        if (cobd->cobd_real_name)
+                OBD_FREE(cobd->cobd_real_name, 
+                         strlen(cobd->cobd_real_name) + 1);
         if (cobd->cache_on) { 
                 rc = obd_disconnect(cobd->cobd_cache_exp, flags);
                 if (rc != 0)
@@ -182,7 +187,7 @@ struct obd_export *cobd_get_exp(struct obd_device *obd)
 
 static int
 cobd_connect(struct lustre_handle *conn, struct obd_device *obd,
-             struct obd_uuid *cluuid)
+             struct obd_uuid *cluuid, unsigned long connect_flags)
 {
         int rc;
         rc = class_connect(conn, obd, cluuid);
@@ -680,8 +685,7 @@ static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 {
         struct obd_device *obd = class_exp2obd(exp);
         struct cache_obd  *cobd = &obd->u.cobd;
-        struct obd_device *real_dev = class_exp2obd(cobd->cobd_real_exp);
-        struct obd_device *cache_dev = class_exp2obd(cobd->cobd_cache_exp); 
+        struct obd_device *real_dev = NULL;
         struct obd_export *cobd_exp;
         int rc = 0;
  
@@ -690,29 +694,40 @@ static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 if (!cobd->cache_on) {
                         struct lustre_handle cache_conn = {0,};
                         
+                        rc = obd_disconnect(cobd->cobd_real_exp, 0);
+                        if (rc != 0)
+                                CERROR("error %d disconnecting real\n", rc);
                         rc = connect_to_obd(cobd->cobd_cache_name, &cache_conn);
                         if (rc != 0)
                                 RETURN(rc); 
                         cobd->cobd_cache_exp = class_conn2export(&cache_conn);
+                        
                         cobd->cache_on = 1;
                 }
                 break;
         case OBD_IOC_COBD_COFF: 
                 if (cobd->cache_on) {
-                        /*Here disconnect for cancel unused ldlm resources,
-                         *then do flush, otherwise, there will be some problems
-                         *in flush cache
-                         *is is right? FIXME later*/
+                        struct lustre_handle real_conn = {0,};
+                        struct obd_device *cache_dev = NULL;
+                        int m_easize, m_cooksize;
+
+                        cache_dev = class_exp2obd(cobd->cobd_cache_exp); 
+                        m_easize = cache_dev->u.cli.cl_max_mds_easize; 
+                        m_cooksize = cache_dev->u.cli.cl_max_mds_cookiesize; 
                         rc = obd_disconnect(cobd->cobd_cache_exp, 0);
                         if (rc != 0)
                                 CERROR("error %d disconnecting real\n", rc);
 
-                        cobd->cache_on = 0;
                         /*FIXME, should read from real_dev*/
-                       real_dev->u.cli.cl_max_mds_easize =
-                                              cache_dev->u.cli.cl_max_mds_easize;
-                       real_dev->u.cli.cl_max_mds_cookiesize =
-                                              cache_dev->u.cli.cl_max_mds_cookiesize;
+                        
+                        rc = connect_to_obd(cobd->cobd_real_name, &real_conn);
+                        if (rc != 0)
+                                RETURN(rc); 
+                        cobd->cobd_real_exp = class_conn2export(&real_conn);
+                        real_dev = class_exp2obd(cobd->cobd_real_exp);
+                        real_dev->u.cli.cl_max_mds_easize = m_easize;
+                        real_dev->u.cli.cl_max_mds_cookiesize = m_cooksize;
+                        cobd->cache_on = 0;
                 }
                 break;
         case OBD_IOC_COBD_CFLUSH:
@@ -755,15 +770,14 @@ static int cobd_llog_finish(struct obd_device *obd, struct obd_llogs *llogs,
         return obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
 }
 
-static int cobd_notify(struct obd_device *obd,
-                       struct obd_device *watched,
-                       int active)
+static int cobd_notify(struct obd_device *obd, struct obd_device *watched,
+                       int active, void *data)
 {
         struct obd_export *cobd_exp;
 
         cobd_exp = cobd_get_exp(obd);
 
-        return obd_notify(class_exp2obd(cobd_exp), watched, active);
+        return obd_notify(class_exp2obd(cobd_exp), watched, active, data);
 }
 
 static int cobd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
@@ -1127,7 +1141,7 @@ static int cobd_md_enqueue(struct obd_export *exp, int lock_type,
                           cb_data);
 }
 
-static int cobd_md_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
+static int cobd_md_intent_lock(struct obd_export *exp,
                                struct ll_fid *pfid, const char *name, int len,
                                void *lmm, int lmmsize,
                                struct ll_fid *cfid, struct lookup_intent *it,
@@ -1143,7 +1157,7 @@ static int cobd_md_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
                 return -EINVAL;
         }
         cobd_exp = cobd_get_exp(obd);
-        return md_intent_lock(cobd_exp, uctxt, pfid, name, len, lmm, lmmsize,
+        return md_intent_lock(cobd_exp, pfid, name, len, lmm, lmmsize,
                               cfid, it, lookup_flags, reqp, cb_blocking);
 }