Whamcloud - gitweb
LU-5061 obd: add lnb_ prefix to members of struct niobuf_local
[fs/lustre-release.git] / lustre / target / tgt_handler.c
index 6f65b62..de964ff 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);
 }
@@ -397,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,
@@ -460,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:
@@ -796,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);
@@ -1125,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;
 
@@ -1136,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);
@@ -1166,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);
@@ -1179,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",
@@ -1362,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).
  */
@@ -1556,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;
 }
@@ -1661,7 +1739,7 @@ int tgt_brw_read(struct tgt_session_info *tsi)
 
        nob = 0;
        for (i = 0; i < npages; i++) {
-               int page_rc = local_nb[i].rc;
+               int page_rc = local_nb[i].lnb_rc;
 
                if (page_rc < 0) {
                        rc = page_rc;
@@ -1670,16 +1748,16 @@ int tgt_brw_read(struct tgt_session_info *tsi)
 
                nob += page_rc;
                if (page_rc != 0) { /* some data! */
-                       LASSERT(local_nb[i].page != NULL);
-                       ptlrpc_prep_bulk_page_nopin(desc, local_nb[i].page,
+                       LASSERT(local_nb[i].lnb_page != NULL);
+                       ptlrpc_prep_bulk_page_nopin(desc, local_nb[i].lnb_page,
                                                    local_nb[i].lnb_page_offset,
                                                    page_rc);
                }
 
-               if (page_rc != local_nb[i].len) { /* short read */
+               if (page_rc != local_nb[i].lnb_len) { /* short read */
                        /* All subsequent pages should be 0 */
                        while (++i < npages)
-                               LASSERT(local_nb[i].rc == 0);
+                               LASSERT(local_nb[i].lnb_rc == 0);
                        break;
                }
        }
@@ -1794,7 +1872,7 @@ static void tgt_warn_on_cksum(struct ptlrpc_request *req,
                           POSTID(&body->oa.o_oi),
                           local_nb[0].lnb_file_offset,
                           local_nb[npages-1].lnb_file_offset +
-                          local_nb[npages-1].len - 1,
+                          local_nb[npages - 1].lnb_len - 1,
                           client_cksum, server_cksum);
 }
 
@@ -1930,9 +2008,9 @@ int tgt_brw_write(struct tgt_session_info *tsi)
 
        /* NB Having prepped, we must commit... */
        for (i = 0; i < npages; i++)
-               ptlrpc_prep_bulk_page_nopin(desc, local_nb[i].page,
+               ptlrpc_prep_bulk_page_nopin(desc, local_nb[i].lnb_page,
                                            local_nb[i].lnb_page_offset,
-                                           local_nb[i].len);
+                                           local_nb[i].lnb_len);
 
        rc = sptlrpc_svc_prep_bulk(req, desc);
        if (rc != 0)
@@ -1999,9 +2077,9 @@ skip_transfer:
                        rcs[i] = 0;
                        do {
                                LASSERT(j < npages);
-                               if (local_nb[j].rc < 0)
-                                       rcs[i] = local_nb[j].rc;
-                               len -= local_nb[j].len;
+                               if (local_nb[j].lnb_rc < 0)
+                                       rcs[i] = local_nb[j].lnb_rc;
+                               len -= local_nb[j].lnb_len;
                                j++;
                        } while (len > 0);
                        LASSERT(len == 0);