Whamcloud - gitweb
LU-5099 api: transfer object type via dt_insert API
[fs/lustre-release.git] / lustre / target / tgt_handler.c
index 5a837a6..af9cb58 100644 (file)
@@ -38,6 +38,7 @@
 #include <obd_class.h>
 #include <obd_cksum.h>
 #include <md_object.h>
+#include <lustre_lfsck.h>
 
 #include "tgt_internal.h"
 
@@ -75,29 +76,29 @@ static int tgt_mdt_body_unpack(struct tgt_session_info *tsi, __u32 flags)
 
        tsi->tsi_mdt_body = body;
 
-       if (!(body->valid & OBD_MD_FLID))
+       if (!(body->mbo_valid & OBD_MD_FLID))
                RETURN(0);
 
        /* mdc_pack_body() doesn't check if fid is zero and set OBD_ML_FID
         * in any case in pre-2.5 clients. Fix that here if needed */
-       if (unlikely(fid_is_zero(&body->fid1)))
+       if (unlikely(fid_is_zero(&body->mbo_fid1)))
                RETURN(0);
 
-       if (!fid_is_sane(&body->fid1)) {
+       if (!fid_is_sane(&body->mbo_fid1)) {
                CERROR("%s: invalid FID: "DFID"\n", tgt_name(tsi->tsi_tgt),
-                      PFID(&body->fid1));
+                      PFID(&body->mbo_fid1));
                RETURN(-EINVAL);
        }
 
        obj = lu_object_find(tsi->tsi_env,
                             &tsi->tsi_tgt->lut_bottom->dd_lu_dev,
-                            &body->fid1, NULL);
+                            &body->mbo_fid1, NULL);
        if (!IS_ERR(obj)) {
                if ((flags & HABEO_CORPUS) && !lu_object_exists(obj)) {
                        lu_object_put(tsi->tsi_env, obj);
                        /* for capability renew ENOENT will be handled in
                         * mdt_renew_capa */
-                       if (body->valid & OBD_MD_FLOSSCAPA)
+                       if (body->mbo_valid & OBD_MD_FLOSSCAPA)
                                rc = 0;
                        else
                                rc = -ENOENT;
@@ -109,7 +110,7 @@ static int tgt_mdt_body_unpack(struct tgt_session_info *tsi, __u32 flags)
                rc = PTR_ERR(obj);
        }
 
-       tsi->tsi_fid = body->fid1;
+       tsi->tsi_fid = body->mbo_fid1;
 
        RETURN(rc);
 }
@@ -148,7 +149,7 @@ int tgt_validate_obdo(struct tgt_session_info *tsi, struct obdo *oa)
                oi->oi_fid.f_oid = id ?: 1;
                oi->oi_fid.f_ver = 0;
        } else {
-               struct lu_fid *fid = &tsi->tsi_fid2;
+               struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env);
 
                if (unlikely((oa->o_valid & OBD_MD_FLID) && id == 0))
                        GOTO(out, rc = -EPROTO);
@@ -165,11 +166,12 @@ int tgt_validate_obdo(struct tgt_session_info *tsi, struct obdo *oa)
                               fid_seq_is_norm(seq) || fid_seq_is_echo(seq))))
                        GOTO(out, rc = -EPROTO);
 
-               rc = ostid_to_fid(fid, oi, tsi->tsi_tgt->lut_lsd.lsd_osd_index);
+               rc = ostid_to_fid(&tti->tti_fid1, oi,
+                                 tsi->tsi_tgt->lut_lsd.lsd_osd_index);
                if (unlikely(rc != 0))
                        GOTO(out, rc);
 
-               oi->oi_fid = *fid;
+               oi->oi_fid = tti->tti_fid1;
        }
 
        RETURN(0);
@@ -396,7 +398,7 @@ static int tgt_handle_request0(struct tgt_session_info *tsi,
                                          RCL_SERVER))
                        req_capsule_set_size(tsi->tsi_pill, &RMF_MDT_MD,
                                             RCL_SERVER,
-                                            tsi->tsi_mdt_body->eadatasize);
+                                            tsi->tsi_mdt_body->mbo_eadatasize);
                if (req_capsule_has_field(tsi->tsi_pill, &RMF_LOGCOOKIES,
                                          RCL_SERVER))
                        req_capsule_set_size(tsi->tsi_pill, &RMF_LOGCOOKIES,
@@ -459,7 +461,7 @@ static int tgt_filter_recovery_request(struct ptlrpc_request *req,
        case MDS_SYNC: /* used in unmounting */
        case OBD_PING:
        case MDS_REINT:
-       case UPDATE_OBJ:
+       case OUT_UPDATE:
        case SEQ_QUERY:
        case FLD_QUERY:
        case LDLM_ENQUEUE:
@@ -795,7 +797,7 @@ static int tgt_init_sec_level(struct ptlrpc_request *req)
                        RETURN(-EACCES);
                }
        } else {
-               if (req->rq_auth_uid == INVALID_UID) {
+               if (!uid_valid(make_kuid(&init_user_ns, req->rq_auth_uid))) {
                        CDEBUG(D_SEC, "client %s -> target %s: user is not "
                               "authenticated!\n", client, tgt_name(tgt));
                        RETURN(-EACCES);
@@ -1124,7 +1126,7 @@ TGT_OBD_HDL    (0,        OBD_IDX_READ,           tgt_obd_idx_read)
 EXPORT_SYMBOL(tgt_obd_handlers);
 
 int tgt_sync(const struct lu_env *env, struct lu_target *tgt,
-            struct dt_object *obj)
+            struct dt_object *obj, __u64 start, __u64 end)
 {
        int rc = 0;
 
@@ -1135,7 +1137,7 @@ int tgt_sync(const struct lu_env *env, struct lu_target *tgt,
                rc = dt_sync(env, tgt->lut_bottom);
        } else if (dt_version_get(env, obj) >
                   tgt->lut_obd->obd_last_committed) {
-               rc = dt_object_sync(env, obj);
+               rc = dt_object_sync(env, obj, start, end);
        }
 
        RETURN(rc);
@@ -1165,6 +1167,9 @@ int tgt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
            (tgt->lut_sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
             (tgt->lut_sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
              lock->l_flags & LDLM_FL_CBPENDING))) {
+               __u64 start = 0;
+               __u64 end = OBD_OBJECT_EOF;
+
                rc = lu_env_init(&env, LCT_DT_THREAD);
                if (unlikely(rc != 0))
                        RETURN(rc);
@@ -1178,7 +1183,12 @@ int tgt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
                if (!dt_object_exists(obj))
                        GOTO(err_put, rc = -ENOENT);
 
-               rc = tgt_sync(&env, tgt, obj);
+               if (lock->l_resource->lr_type == LDLM_EXTENT) {
+                       start = lock->l_policy_data.l_extent.start;
+                       end = lock->l_policy_data.l_extent.end;
+               }
+
+               rc = tgt_sync(&env, tgt, obj, start, end);
                if (rc < 0) {
                        CERROR("%s: syncing "DFID" ("LPU64"-"LPU64") on lock "
                               "cancel: rc = %d\n",
@@ -1361,6 +1371,77 @@ TGT_SEC_HDL_VAR(0,       SEC_CTX_FINI,           tgt_sec_ctx_handle),
 };
 EXPORT_SYMBOL(tgt_sec_ctx_handlers);
 
+int (*tgt_lfsck_in_notify)(const struct lu_env *env,
+                          struct dt_device *key,
+                          struct lfsck_request *lr) = NULL;
+
+void tgt_register_lfsck_in_notify(int (*notify)(const struct lu_env *,
+                                               struct dt_device *,
+                                               struct lfsck_request *))
+{
+       tgt_lfsck_in_notify = notify;
+}
+EXPORT_SYMBOL(tgt_register_lfsck_in_notify);
+
+static int (*tgt_lfsck_query)(const struct lu_env *env,
+                             struct dt_device *key,
+                             struct lfsck_request *lr) = NULL;
+
+void tgt_register_lfsck_query(int (*query)(const struct lu_env *,
+                                          struct dt_device *,
+                                          struct lfsck_request *))
+{
+       tgt_lfsck_query = query;
+}
+EXPORT_SYMBOL(tgt_register_lfsck_query);
+
+/* LFSCK request handlers */
+static int tgt_handle_lfsck_notify(struct tgt_session_info *tsi)
+{
+       const struct lu_env     *env = tsi->tsi_env;
+       struct dt_device        *key = tsi->tsi_tgt->lut_bottom;
+       struct lfsck_request    *lr;
+       int                      rc;
+       ENTRY;
+
+       lr = req_capsule_client_get(tsi->tsi_pill, &RMF_LFSCK_REQUEST);
+       if (lr == NULL)
+               RETURN(-EPROTO);
+
+       rc = tgt_lfsck_in_notify(env, key, lr);
+
+       RETURN(rc);
+}
+
+static int tgt_handle_lfsck_query(struct tgt_session_info *tsi)
+{
+       struct lfsck_request    *request;
+       struct lfsck_reply      *reply;
+       int                      rc      = 0;
+       ENTRY;
+
+       request = req_capsule_client_get(tsi->tsi_pill, &RMF_LFSCK_REQUEST);
+       if (request == NULL)
+               RETURN(-EPROTO);
+
+       reply = req_capsule_server_get(tsi->tsi_pill, &RMF_LFSCK_REPLY);
+       if (reply == NULL)
+               RETURN(-ENOMEM);
+
+       reply->lr_status = tgt_lfsck_query(tsi->tsi_env,
+                                          tsi->tsi_tgt->lut_bottom, request);
+       if (reply->lr_status < 0)
+               rc = reply->lr_status;
+
+       RETURN(rc);
+}
+
+struct tgt_handler tgt_lfsck_handlers[] = {
+TGT_LFSCK_HDL(HABEO_REFERO,    LFSCK_NOTIFY,   tgt_handle_lfsck_notify),
+TGT_LFSCK_HDL(HABEO_REFERO,    LFSCK_QUERY,    tgt_handle_lfsck_query),
+};
+EXPORT_SYMBOL(tgt_lfsck_handlers);
+
 /*
  * initialize per-thread page pool (bug 5137).
  */
@@ -1555,10 +1636,8 @@ static __u32 tgt_checksum_bulk(struct lu_target *tgt,
                }
        }
 
-       bufsize = 4;
+       bufsize = sizeof(cksum);
        err = cfs_crypto_hash_final(hdesc, (unsigned char *)&cksum, &bufsize);
-       if (err)
-               cfs_crypto_hash_final(hdesc, NULL, NULL);
 
        return cksum;
 }