Whamcloud - gitweb
- generate capability in open resend case
[fs/lustre-release.git] / lustre / cobd / cache_obd.c
index dca4582..a2b1d17 100644 (file)
@@ -147,7 +147,7 @@ static int cobd_setup(struct obd_device *obd, obd_count len, void *buf)
         }
         cobd->cache_exp = class_conn2export(&conn);
         
-        /* default set cache on, but nothins is realy connected yet, will be
+        /* default set cache on, but nothing is realy connected yet, will be
          * done in cobd_connect() time. */
         cobd->cache_on = 1;
 
@@ -305,8 +305,8 @@ cobd_disconnect_client(struct obd_device *obd,
 }
 
 #define COBD_CONNECT (1 << 0)
-#define COBD_DISCON (1 << 1)
-#define COBD_BOTH (1 << 2)
+#define COBD_DISCON  (1 << 1)
+#define COBD_SWITCH  (1 << 2)
 
 /* magic function for switching cobd between two exports cache and master in
  * strong correspondence with passed @cache_on. It also may perform partial
@@ -314,8 +314,9 @@ cobd_disconnect_client(struct obd_device *obd,
  *
  * bias == COBD_CONNECT only connect new export (used in cobd_connect())
  * bias == COBD_DISCON only disconnect old export (used in cobd_disconnect())
- * bias == COBD_BOTH do both (disconnect old and connect new) (used in
- * cobd_iocontrol())
+ *
+ * bias == COBD_SWITCH do both (disconnect old and connect new). This will also
+ * set ->cache_on  to passed @cache_on value.
  */
 static int cobd_switch(struct obd_device *obd,
                        int cache_on, int bias)
@@ -337,7 +338,7 @@ static int cobd_switch(struct obd_device *obd,
         }
 
         /* disconnect old export */
-        if (bias == COBD_BOTH || bias == COBD_DISCON) {
+        if (bias == COBD_SWITCH || bias == COBD_DISCON) {
                 if (discon_exp) {
                         rc = cobd_disconnect_client(obd, discon_exp, 0);
                         if (rc) {
@@ -353,43 +354,54 @@ static int cobd_switch(struct obd_device *obd,
         }
 
         /* connect new export */
-        if (bias == COBD_BOTH || bias == COBD_CONNECT) {
-                rc = cobd_connect_client(obd, conn_exp, &conn,
-                                         NULL, OBD_OPT_REAL_CLIENT);
-                if (rc) {
-                        CERROR("can't connect export %p, err %d\n",
-                               conn_exp, rc);
-                        RETURN(rc);
-                }
+        if (bias == COBD_SWITCH || bias == COBD_CONNECT) {
+                int connected;
 
-                if (cache_on) {
-                        cobd->cache_real_exp = class_conn2export(&conn);
-                        cli_obd = class_exp2obd(cobd->cache_exp);
-                } else {
-                        cobd->master_real_exp = class_conn2export(&conn);
-                        cli_obd = class_exp2obd(cobd->master_exp);
-                }
-        }
+                connected = cache_on ? (cobd->cache_real_exp != NULL) :
+                        (cobd->master_real_exp != NULL);
 
-        cobd->cache_on = cache_on;
-        
-        if (bias == COBD_BOTH || bias == COBD_CONNECT) {
-                /* re-init EA size for new selected export. This should be done after
-                 * assigining new state to @cobd->cache_on to not call not connened
-                 * already old export. */
-                if (obd_md_type(cli_obd)) {
-                        rc = cobd_init_dt_desc(obd);
-                        if (rc == 0) {
-                                rc = cobd_init_ea_size(obd);
-                                if (rc) {
-                                        CERROR("can't initialize EA size, "
+                /* correct export already may be connected */
+                if (!connected) {
+                        rc = cobd_connect_client(obd, conn_exp, &conn,
+                                                 NULL, OBD_OPT_REAL_CLIENT);
+                        if (rc) {
+                                CERROR("can't connect export %p, err %d\n",
+                                       conn_exp, rc);
+                                RETURN(rc);
+                        }
+
+                        if (cache_on) {
+                                cobd->cache_real_exp = class_conn2export(&conn);
+                                cli_obd = class_exp2obd(cobd->cache_exp);
+                        } else {
+                                cobd->master_real_exp = class_conn2export(&conn);
+                                cli_obd = class_exp2obd(cobd->master_exp);
+                        }
+
+                        /* change flag only if connect is allowed to keep
+                         * ->cache_on coherent with real export connected. */
+                        cobd->cache_on = cache_on;
+                
+                        /* re-init EA size for new selected export. This should
+                         * be done after assigining new state to @cobd->cache_on
+                         * to not call disconnected old export. */
+                        if (obd_md_type(cli_obd)) {
+                                rc = cobd_init_dt_desc(obd);
+                                if (rc == 0) {
+                                        rc = cobd_init_ea_size(obd);
+                                        if (rc) {
+                                                CERROR("can't initialize EA size, "
+                                                       "err %d\n", rc);
+                                        }
+                                } else {
+                                        CERROR("can't initialize data lovdesc, "
                                                "err %d\n", rc);
+                                        /* ignore cases when we did not manage
+                                         * to init lovdesc. This is because some
+                                         * devices may not know "lovdesc" info
+                                         * command. */
+                                        rc = 0;
                                 }
-                        } else {
-                                /* ignore cases when we di dnot manage to init
-                                 * lovdesc. This is because some devices may not know
-                                 * "lovdesc" info command. */
-                                rc = 0;
                         }
                 }
         }
@@ -442,7 +454,7 @@ cobd_disconnect(struct obd_export *exp, unsigned long flags)
          * cache should be switched after client umount this is not needed.
          * --umka. */
         cobd = &obd->u.cobd;
-        rc = cobd_switch(obd, cobd->cache_on, COBD_DISCON);
+        rc = cobd_switch(obd, !cobd->cache_on, COBD_DISCON);
         class_disconnect(exp, flags);
 
         RETURN(rc);
@@ -520,11 +532,11 @@ static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp,
         switch (cmd) {
         case OBD_IOC_COBD_CON:
                 if (!cobd->cache_on)
-                        rc = cobd_switch(obd, 1, COBD_BOTH);
+                        rc = cobd_switch(obd, 1, COBD_SWITCH);
                 break;
         case OBD_IOC_COBD_COFF: 
                 if (cobd->cache_on)
-                        rc = cobd_switch(obd, 0, COBD_BOTH);
+                        rc = cobd_switch(obd, 0, COBD_SWITCH);
                 break;
         default:
                 cobd_exp = cobd_get_exp(obd);
@@ -535,6 +547,57 @@ static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp,
         RETURN(rc);
 }
 
+static int cobd_notify(struct obd_device *obd, struct obd_device *watched,
+                       int active, void *data)
+{
+        struct obd_export *cobd_exp;
+        int rc = 0;
+        ENTRY;
+
+        cobd_exp = cobd_get_exp(obd);
+        rc = obd_notify(class_exp2obd(cobd_exp), watched, active, data);
+        RETURN(rc);
+}
+
+static int cobd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
+                    int type, struct obd_client_handle *handle,
+                    int flag)
+{
+        struct obd_device *obd = class_exp2obd(exp);
+        struct obd_export *cobd_exp;
+        int rc = 0;
+        ENTRY;
+
+        if (obd == NULL) {
+                CERROR("invalid client cookie "LPX64"\n", 
+                       exp->exp_handle.h_cookie);
+                RETURN(-EINVAL);
+        }
+        cobd_exp = cobd_get_exp(obd);
+        rc = obd_pin(cobd_exp, ino, gen, type, handle, flag);
+        RETURN(rc);
+}
+
+static int cobd_unpin(struct obd_export *exp,
+                      struct obd_client_handle *handle,
+                      int flag)
+{
+        struct obd_device *obd = class_exp2obd(exp);
+        struct obd_export *cobd_exp;
+        int rc = 0;
+        ENTRY;
+
+        if (obd == NULL) {
+                CERROR("invalid client cookie "LPX64"\n", 
+                       exp->exp_handle.h_cookie);
+                RETURN(-EINVAL);
+        }
+        cobd_exp = cobd_get_exp(obd);
+        rc = obd_unpin(cobd_exp, handle, flag);
+        RETURN(rc);
+}
+
+/* data related stuff */
 static int cobd_dt_packmd(struct obd_export *exp,
                           struct lov_mds_md **disk_tgt,
                           struct lov_stripe_md *mem_src)
@@ -661,7 +724,8 @@ static int cobd_dt_getattr_async(struct obd_export *exp,
 
 static int cobd_dt_setattr(struct obd_export *exp, struct obdo *obdo,
                            struct lov_stripe_md *ea,
-                           struct obd_trans_info *oti)
+                           struct obd_trans_info *oti,
+                           struct lustre_capa *capa)
 {
         struct obd_device *obd = class_exp2obd(exp);
         struct obd_export *cobd_exp;
@@ -674,7 +738,7 @@ static int cobd_dt_setattr(struct obd_export *exp, struct obdo *obdo,
                 RETURN(-EINVAL);
         }
         cobd_exp = cobd_get_exp(obd);
-        rc = obd_setattr(cobd_exp, obdo, ea, oti);
+        rc = obd_setattr(cobd_exp, obdo, ea, oti, capa);
         RETURN(rc);
 }
 
@@ -852,7 +916,8 @@ static int cobd_dt_teardown_async_page(struct obd_export *exp,
 
 static int cobd_dt_punch(struct obd_export *exp, struct obdo *oa,
                          struct lov_stripe_md *ea, obd_size start,
-                         obd_size end, struct obd_trans_info *oti)
+                         obd_size end, struct obd_trans_info *oti,
+                         struct lustre_capa *capa)
 {
         struct obd_device *obd = class_exp2obd(exp);
         struct obd_export *cobd_exp;
@@ -865,7 +930,7 @@ static int cobd_dt_punch(struct obd_export *exp, struct obdo *oa,
                 RETURN(-EINVAL);
         }
         cobd_exp = cobd_get_exp(obd);
-        rc = obd_punch(cobd_exp, oa, ea, start, end, oti);
+        rc = obd_punch(cobd_exp, oa, ea, start, end, oti, capa);
         RETURN(rc);
 }
 
@@ -992,7 +1057,8 @@ static int cobd_dt_preprw(int cmd, struct obd_export *exp,
                           struct obd_ioobj *obj, int niocount,
                           struct niobuf_remote *nb,
                           struct niobuf_local *res,
-                          struct obd_trans_info *oti)
+                          struct obd_trans_info *oti,
+                          struct lustre_capa *capa)
 {
         struct obd_device *obd = class_exp2obd(exp);
         struct obd_export *cobd_exp;
@@ -1006,7 +1072,7 @@ static int cobd_dt_preprw(int cmd, struct obd_export *exp,
         }
         cobd_exp = cobd_get_exp(obd);
         rc = obd_preprw(cmd, cobd_exp, oa, objcount, obj,
-                        niocount, nb, res, oti);
+                          niocount, nb, res, oti, capa);
         RETURN(rc);
 }
 
@@ -1085,56 +1151,6 @@ static int cobd_dt_llog_finish(struct obd_device *obd,
         RETURN(rc);
 }
 
-static int cobd_dt_notify(struct obd_device *obd, struct obd_device *watched,
-                          int active, void *data)
-{
-        struct obd_export *cobd_exp;
-        int rc = 0;
-        ENTRY;
-
-        cobd_exp = cobd_get_exp(obd);
-        rc = obd_notify(class_exp2obd(cobd_exp), watched, active, data);
-        RETURN(rc);
-}
-
-static int cobd_dt_pin(struct obd_export *exp, obd_id ino, __u32 gen,
-                       int type, struct obd_client_handle *handle,
-                       int flag)
-{
-        struct obd_device *obd = class_exp2obd(exp);
-        struct obd_export *cobd_exp;
-        int rc = 0;
-        ENTRY;
-
-        if (obd == NULL) {
-                CERROR("invalid client cookie "LPX64"\n", 
-                       exp->exp_handle.h_cookie);
-                RETURN(-EINVAL);
-        }
-        cobd_exp = cobd_get_exp(obd);
-        rc = obd_pin(cobd_exp, ino, gen, type, handle, flag);
-        RETURN(rc);
-}
-
-static int cobd_dt_unpin(struct obd_export *exp,
-                         struct obd_client_handle *handle,
-                         int flag)
-{
-        struct obd_device *obd = class_exp2obd(exp);
-        struct obd_export *cobd_exp;
-        int rc = 0;
-        ENTRY;
-
-        if (obd == NULL) {
-                CERROR("invalid client cookie "LPX64"\n", 
-                       exp->exp_handle.h_cookie);
-                RETURN(-EINVAL);
-        }
-        cobd_exp = cobd_get_exp(obd);
-        rc = obd_unpin(cobd_exp, handle, flag);
-        RETURN(rc);
-}
-
 static int cobd_dt_init_ea_size(struct obd_export *exp, int easize,
                                 int cookiesize)
 {
@@ -1159,6 +1175,7 @@ static int cobd_dt_import_event(struct obd_device *obd,
         RETURN(0); 
 }
 
+/* metadata related stuff */
 static int cobd_md_getstatus(struct obd_export *exp,
                              struct lustre_id *rootid)
 {
@@ -1180,7 +1197,7 @@ static int cobd_md_getstatus(struct obd_export *exp,
 static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
                            __u64 valid, const char *xattr_name,
                            const void *xattr_data, unsigned int xattr_datalen,
-                           unsigned int ea_size,
+                           unsigned int ea_size, struct obd_capa *ocapa,
                            struct ptlrpc_request **request)
 {
         struct obd_device *obd = class_exp2obd(exp);
@@ -1194,8 +1211,8 @@ static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
                 RETURN(-EINVAL);
         }
         cobd_exp = cobd_get_exp(obd);
-        rc = md_getattr(cobd_exp, id, valid, xattr_name,
-                        xattr_data, xattr_datalen, ea_size, request);
+        rc = md_getattr(cobd_exp, id, valid, xattr_name, xattr_data,
+                          xattr_datalen, ea_size, ocapa, request);
         RETURN(rc);
 }
 
@@ -1394,7 +1411,7 @@ static int cobd_md_readpage(struct obd_export *exp,
         RETURN(rc);
 }
 
-static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
+static int cobd_md_close(struct obd_export *exp, struct mdc_op_data *op_data,
                          struct obd_client_handle *och, 
                          struct ptlrpc_request **request)
 {
@@ -1409,7 +1426,7 @@ static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
                 RETURN(-EINVAL);
         }
         cobd_exp = cobd_get_exp(obd);
-        rc = md_close(cobd_exp, obdo, och, request);
+        rc = md_close(cobd_exp, op_data, och, request);
         RETURN(rc);
 }
 
@@ -1619,6 +1636,9 @@ static struct obd_ops cobd_obd_ops = {
         .o_get_info               = cobd_get_info,
         .o_statfs                 = cobd_statfs,
         .o_iocontrol              = cobd_iocontrol,
+        .o_notify                 = cobd_notify,
+        .o_pin                    = cobd_pin,
+        .o_unpin                  = cobd_unpin,
 
         .o_packmd                 = cobd_dt_packmd,
         .o_unpackmd               = cobd_dt_unpackmd,
@@ -1647,9 +1667,6 @@ static struct obd_ops cobd_obd_ops = {
         .o_commitrw               = cobd_dt_commitrw,
         .o_llog_init              = cobd_dt_llog_init,
         .o_llog_finish            = cobd_dt_llog_finish,
-        .o_notify                 = cobd_dt_notify,
-        .o_pin                    = cobd_dt_pin,
-        .o_unpin                  = cobd_dt_unpin,
         .o_import_event           = cobd_dt_import_event,
         .o_init_ea_size           = cobd_dt_init_ea_size,
         .o_adjust_kms             = cobd_dt_adjust_kms,