Whamcloud - gitweb
LU-1866 misc: fix some issues found during LFSCK
[fs/lustre-release.git] / lustre / ptlrpc / pack_generic.c
index d59fa98..6de2ad3 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -261,20 +261,20 @@ EXPORT_SYMBOL(lustre_pack_request);
 
 #if RS_DEBUG
 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
-cfs_spinlock_t ptlrpc_rs_debug_lock;
+spinlock_t ptlrpc_rs_debug_lock;
 
-#define PTLRPC_RS_DEBUG_LRU_ADD(rs)                                     \
-do {                                                                    \
-        cfs_spin_lock(&ptlrpc_rs_debug_lock);                           \
-        cfs_list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru);  \
-        cfs_spin_unlock(&ptlrpc_rs_debug_lock);                         \
+#define PTLRPC_RS_DEBUG_LRU_ADD(rs)                                    \
+do {                                                                   \
+       spin_lock(&ptlrpc_rs_debug_lock);                               \
+       cfs_list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru);  \
+       spin_unlock(&ptlrpc_rs_debug_lock);                             \
 } while (0)
 
-#define PTLRPC_RS_DEBUG_LRU_DEL(rs)             \
-do {                                            \
-        cfs_spin_lock(&ptlrpc_rs_debug_lock);   \
-        cfs_list_del(&(rs)->rs_debug_list);     \
-        cfs_spin_unlock(&ptlrpc_rs_debug_lock); \
+#define PTLRPC_RS_DEBUG_LRU_DEL(rs)                                    \
+do {                                                                   \
+       spin_lock(&ptlrpc_rs_debug_lock);                               \
+       cfs_list_del(&(rs)->rs_debug_list);                             \
+       spin_unlock(&ptlrpc_rs_debug_lock);                             \
 } while (0)
 #else
 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
@@ -286,14 +286,14 @@ lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt)
 {
        struct ptlrpc_reply_state *rs = NULL;
 
-       cfs_spin_lock(&svcpt->scp_rep_lock);
+       spin_lock(&svcpt->scp_rep_lock);
 
        /* See if we have anything in a pool, and wait if nothing */
        while (cfs_list_empty(&svcpt->scp_rep_idle)) {
                struct l_wait_info      lwi;
                int                     rc;
 
-               cfs_spin_unlock(&svcpt->scp_rep_lock);
+               spin_unlock(&svcpt->scp_rep_lock);
                /* If we cannot get anything for some long time, we better
                 * bail out instead of waiting infinitely */
                lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
@@ -301,16 +301,15 @@ lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt)
                                  !cfs_list_empty(&svcpt->scp_rep_idle), &lwi);
                if (rc != 0)
                        goto out;
-               cfs_spin_lock(&svcpt->scp_rep_lock);
+               spin_lock(&svcpt->scp_rep_lock);
        }
 
        rs = cfs_list_entry(svcpt->scp_rep_idle.next,
                            struct ptlrpc_reply_state, rs_list);
        cfs_list_del(&rs->rs_list);
 
-       cfs_spin_unlock(&svcpt->scp_rep_lock);
+       spin_unlock(&svcpt->scp_rep_lock);
 
-       LASSERT(rs != NULL);
        memset(rs, 0, svcpt->scp_service->srv_max_reply_size);
        rs->rs_svcpt = svcpt;
        rs->rs_prealloc = 1;
@@ -322,9 +321,9 @@ void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
 {
        struct ptlrpc_service_part *svcpt = rs->rs_svcpt;
 
-       cfs_spin_lock(&svcpt->scp_rep_lock);
+       spin_lock(&svcpt->scp_rep_lock);
        cfs_list_add(&rs->rs_list, &svcpt->scp_rep_idle);
-       cfs_spin_unlock(&svcpt->scp_rep_lock);
+       spin_unlock(&svcpt->scp_rep_lock);
        cfs_waitq_signal(&svcpt->scp_rep_waitq);
 }
 
@@ -338,9 +337,9 @@ int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
         LASSERT(req->rq_reply_state == NULL);
 
         if ((flags & LPRFL_EARLY_REPLY) == 0) {
-                cfs_spin_lock(&req->rq_lock);
-                req->rq_packed_final = 1;
-                cfs_spin_unlock(&req->rq_lock);
+               spin_lock(&req->rq_lock);
+               req->rq_packed_final = 1;
+               spin_unlock(&req->rq_lock);
         }
 
         msg_len = lustre_msg_size_v2(count, lens);
@@ -356,7 +355,7 @@ int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
         CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
         CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
         CFS_INIT_LIST_HEAD(&rs->rs_list);
-        cfs_spin_lock_init(&rs->rs_lock);
+       spin_lock_init(&rs->rs_lock);
 
         req->rq_replen = msg_len;
         req->rq_reply_state = rs;
@@ -1323,7 +1322,7 @@ __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
         }
 }
 
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 0, 0)
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
 /*
  * In 1.6 and 1.8 the checksum was computed only on struct ptlrpc_body as
  * it was in 1.6 (88 bytes, smaller than the full size in 1.8).  It makes
@@ -1341,7 +1340,7 @@ __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 0, 0)
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
                __u32 crc;
                unsigned int hsize = 4;
                __u32 len = compat18 ? ptlrpc_body_cksum_size_compat18 :
@@ -1557,7 +1556,11 @@ void lustre_msg_set_jobid(struct lustre_msg *msg, char *jobid)
                pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
                                       sizeof(struct ptlrpc_body));
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
-               memcpy(pb->pb_jobid, jobid, JOBSTATS_JOBID_SIZE);
+
+               if (jobid != NULL)
+                       memcpy(pb->pb_jobid, jobid, JOBSTATS_JOBID_SIZE);
+               else if (pb->pb_jobid[0] == '\0')
+                       lustre_get_jobid(pb->pb_jobid);
                return;
        }
        default:
@@ -1771,7 +1774,7 @@ void lustre_swab_obd_statfs (struct obd_statfs *os)
         __swab32s (&os->os_namelen);
         __swab64s (&os->os_maxbytes);
         __swab32s (&os->os_state);
-        CLASSERT(offsetof(typeof(*os), os_spare1) != 0);
+       CLASSERT(offsetof(typeof(*os), os_fprecreated) != 0);
         CLASSERT(offsetof(typeof(*os), os_spare2) != 0);
         CLASSERT(offsetof(typeof(*os), os_spare3) != 0);
         CLASSERT(offsetof(typeof(*os), os_spare4) != 0);
@@ -1818,20 +1821,50 @@ void lustre_swab_generic_32s(__u32 *val)
 }
 EXPORT_SYMBOL(lustre_swab_generic_32s);
 
-void lustre_swab_lvb(union ldlm_wire_lvb *lvb)
+void lustre_swab_gl_desc(union ldlm_gl_desc *desc)
 {
-        /* The ldlm_wire_lvb union represents all the possible LVB types.
-         * Unfortunately, there is no way to know what member of the union we
-         * are dealing with at this point. Therefore, all LVB structures must
-         * have fields of the same types, although used for different purposes
-         */
-        __swab64s(&lvb->l_ost.lvb_size);
-        __swab64s(&lvb->l_ost.lvb_mtime);
-        __swab64s(&lvb->l_ost.lvb_atime);
-        __swab64s(&lvb->l_ost.lvb_ctime);
-        __swab64s(&lvb->l_ost.lvb_blocks);
+       lustre_swab_lu_fid(&desc->lquota_desc.gl_id.qid_fid);
+       __swab64s(&desc->lquota_desc.gl_flags);
+       __swab64s(&desc->lquota_desc.gl_ver);
+       __swab64s(&desc->lquota_desc.gl_hardlimit);
+       __swab64s(&desc->lquota_desc.gl_softlimit);
+       __swab64s(&desc->lquota_desc.gl_time);
+       CLASSERT(offsetof(typeof(desc->lquota_desc), gl_pad2) != 0);
+}
+
+void lustre_swab_ost_lvb_v1(struct ost_lvb_v1 *lvb)
+{
+       __swab64s(&lvb->lvb_size);
+       __swab64s(&lvb->lvb_mtime);
+       __swab64s(&lvb->lvb_atime);
+       __swab64s(&lvb->lvb_ctime);
+       __swab64s(&lvb->lvb_blocks);
+}
+EXPORT_SYMBOL(lustre_swab_ost_lvb_v1);
+
+void lustre_swab_ost_lvb(struct ost_lvb *lvb)
+{
+       __swab64s(&lvb->lvb_size);
+       __swab64s(&lvb->lvb_mtime);
+       __swab64s(&lvb->lvb_atime);
+       __swab64s(&lvb->lvb_ctime);
+       __swab64s(&lvb->lvb_blocks);
+       __swab32s(&lvb->lvb_mtime_ns);
+       __swab32s(&lvb->lvb_atime_ns);
+       __swab32s(&lvb->lvb_ctime_ns);
+       __swab32s(&lvb->lvb_padding);
 }
-EXPORT_SYMBOL(lustre_swab_lvb);
+EXPORT_SYMBOL(lustre_swab_ost_lvb);
+
+void lustre_swab_lquota_lvb(struct lquota_lvb *lvb)
+{
+       __swab64s(&lvb->lvb_flags);
+       __swab64s(&lvb->lvb_id_may_rel);
+       __swab64s(&lvb->lvb_id_rel);
+       __swab64s(&lvb->lvb_id_qunit);
+       __swab64s(&lvb->lvb_pad1);
+}
+EXPORT_SYMBOL(lustre_swab_lquota_lvb);
 
 void lustre_swab_mdt_body (struct mdt_body *b)
 {
@@ -1845,7 +1878,7 @@ void lustre_swab_mdt_body (struct mdt_body *b)
         __swab64s (&b->ctime);
         __swab64s (&b->blocks);
         __swab64s (&b->ioepoch);
-        __swab64s (&b->ino);
+       CLASSERT(offsetof(typeof(*b), unused1) != 0);
         __swab32s (&b->fsuid);
         __swab32s (&b->fsgid);
         __swab32s (&b->capability);
@@ -1855,7 +1888,7 @@ void lustre_swab_mdt_body (struct mdt_body *b)
         __swab32s (&b->flags);
         __swab32s (&b->rdev);
         __swab32s (&b->nlink);
-        __swab32s (&b->generation);
+       CLASSERT(offsetof(typeof(*b), unused2) != 0);
         __swab32s (&b->suppgid);
         __swab32s (&b->eadatasize);
         __swab32s (&b->aclsize);
@@ -1962,16 +1995,6 @@ void lustre_swab_obd_quotactl (struct obd_quotactl *q)
 }
 EXPORT_SYMBOL(lustre_swab_obd_quotactl);
 
-void lustre_swab_quota_adjust_qunit (struct quota_adjust_qunit *q)
-{
-        __swab32s (&q->qaq_flags);
-        __swab32s (&q->qaq_id);
-        __swab64s (&q->qaq_bunit_sz);
-        __swab64s (&q->qaq_iunit_sz);
-        __swab64s (&q->padding1);
-}
-EXPORT_SYMBOL(lustre_swab_quota_adjust_qunit);
-
 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
 {
         __swab32s (&p->rp_uid);
@@ -2019,6 +2042,29 @@ void lustre_swab_fiemap(struct ll_user_fiemap *fiemap)
 }
 EXPORT_SYMBOL(lustre_swab_fiemap);
 
+void lustre_swab_idx_info(struct idx_info *ii)
+{
+       __swab32s(&ii->ii_magic);
+       __swab32s(&ii->ii_flags);
+       __swab16s(&ii->ii_count);
+       __swab32s(&ii->ii_attrs);
+       lustre_swab_lu_fid(&ii->ii_fid);
+       __swab64s(&ii->ii_version);
+       __swab64s(&ii->ii_hash_start);
+       __swab64s(&ii->ii_hash_end);
+       __swab16s(&ii->ii_keysize);
+       __swab16s(&ii->ii_recsize);
+}
+
+void lustre_swab_lip_header(struct lu_idxpage *lip)
+{
+       /* swab header */
+       __swab32s(&lip->lip_magic);
+       __swab16s(&lip->lip_flags);
+       __swab16s(&lip->lip_nr);
+}
+EXPORT_SYMBOL(lustre_swab_lip_header);
+
 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
 {
         __swab32s (&rr->rr_opcode);
@@ -2232,15 +2278,15 @@ int llog_log_swabbed(struct llog_log_hdr *hdr)
         return -1;
 }
 
-void lustre_swab_qdata(struct qunit_data *d)
+void lustre_swab_quota_body(struct quota_body *b)
 {
-        __swab32s (&d->qd_id);
-        __swab32s (&d->qd_flags);
-        __swab64s (&d->qd_count);
-        __swab64s (&d->qd_qunit);
-        CLASSERT(offsetof(typeof(*d), padding) != 0);
+       lustre_swab_lu_fid(&b->qb_fid);
+       lustre_swab_lu_fid((struct lu_fid *)&b->qb_id);
+       __swab32s(&b->qb_flags);
+       __swab64s(&b->qb_count);
+       __swab64s(&b->qb_usage);
+       __swab64s(&b->qb_slv_ver);
 }
-EXPORT_SYMBOL(lustre_swab_qdata);
 
 /* Dump functions */
 void dump_ioo(struct obd_ioobj *ioo)
@@ -2337,68 +2383,6 @@ void dump_rcs(__u32 *rc)
 }
 EXPORT_SYMBOL(dump_rcs);
 
-#ifdef __KERNEL__
-
-/**
- * got qdata from request(req/rep)
- */
-struct qunit_data *quota_get_qdata(void *r, int is_req, int is_exp)
-{
-        struct ptlrpc_request *req = (struct ptlrpc_request *)r;
-        struct qunit_data *qdata;
-        __u64  flags = is_exp ? req->rq_export->exp_connect_flags :
-                       req->rq_import->imp_connect_data.ocd_connect_flags;
-
-        LASSERT(req);
-        /* support for quota64 */
-        LASSERT(flags & OBD_CONNECT_QUOTA64);
-        /* support for change_qs */
-        LASSERT(flags & OBD_CONNECT_CHANGE_QS);
-
-        if (is_req == QUOTA_REQUEST)
-                qdata = req_capsule_client_get(&req->rq_pill, &RMF_QUNIT_DATA);
-        else
-                qdata = req_capsule_server_get(&req->rq_pill, &RMF_QUNIT_DATA);
-        if (qdata == NULL)
-                return ERR_PTR(-EPROTO);
-
-        QDATA_SET_CHANGE_QS(qdata);
-        return qdata;
-}
-EXPORT_SYMBOL(quota_get_qdata);
-
-/**
- * copy qdata to request(req/rep)
- */
-int quota_copy_qdata(void *r, struct qunit_data *qdata, int is_req,
-                     int is_exp)
-{
-        struct ptlrpc_request *req = (struct ptlrpc_request *)r;
-        void *target;
-        __u64  flags = is_exp ? req->rq_export->exp_connect_flags :
-                req->rq_import->imp_connect_data.ocd_connect_flags;
-
-        LASSERT(req);
-        LASSERT(qdata);
-        /* support for quota64 */
-        LASSERT(flags & OBD_CONNECT_QUOTA64);
-        /* support for change_qs */
-        LASSERT(flags & OBD_CONNECT_CHANGE_QS);
-
-        if (is_req == QUOTA_REQUEST)
-                target = req_capsule_client_get(&req->rq_pill, &RMF_QUNIT_DATA);
-        else
-                target = req_capsule_server_get(&req->rq_pill, &RMF_QUNIT_DATA);
-        if (target == NULL)
-                return -EPROTO;
-
-        LASSERT(target != qdata);
-        memcpy(target, qdata, sizeof(*qdata));
-        return 0;
-}
-EXPORT_SYMBOL(quota_copy_qdata);
-#endif /* __KERNEL__ */
-
 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
 {
         LASSERT(req->rq_reqmsg);
@@ -2493,40 +2477,88 @@ void lustre_swab_lustre_capa_key(struct lustre_capa_key *k)
 }
 EXPORT_SYMBOL(lustre_swab_lustre_capa_key);
 
-void lustre_swab_hsm_state(struct hsm_state_set_ioc *hssi)
+void lustre_swab_hsm_user_state(struct hsm_user_state *state)
 {
-        lustre_swab_lu_fid(&hssi->hssi_fid);
-        __swab64s(&hssi->hssi_setmask);
-        __swab64s(&hssi->hssi_clearmask);
+       __swab32s(&state->hus_states);
+       __swab32s(&state->hus_archive_id);
 }
-EXPORT_SYMBOL(lustre_swab_hsm_state);
+EXPORT_SYMBOL(lustre_swab_hsm_user_state);
 
-void lustre_swab_hsm_user_request(struct hsm_user_request *hur)
+void lustre_swab_hsm_state_set(struct hsm_state_set *hss)
 {
-        int i;
+       __swab32s(&hss->hss_valid);
+       __swab64s(&hss->hss_setmask);
+       __swab64s(&hss->hss_clearmask);
+       __swab32s(&hss->hss_archive_id);
+}
+EXPORT_SYMBOL(lustre_swab_hsm_state_set);
 
-        __swab32s(&hur->hur_action);
-        __swab32s(&hur->hur_itemcount);
-        __swab32s(&hur->hur_data_len);
-        for (i = 0; i < hur->hur_itemcount; i++) {
-                struct hsm_user_item *hui = &hur->hur_user_item[i];
-                lustre_swab_lu_fid(&hui->hui_fid);
-                __swab64s(&hui->hui_extent.offset);
-                __swab64s(&hui->hui_extent.length);
-        }
-        /* Note: data blob is not swabbed here */
+void lustre_swab_hsm_extent(struct hsm_extent *extent)
+{
+       __swab64s(&extent->offset);
+       __swab64s(&extent->length);
 }
-EXPORT_SYMBOL(lustre_swab_hsm_user_request);
 
-void lustre_swab_hsm_progress(struct hsm_progress *hp)
+void lustre_swab_hsm_current_action(struct hsm_current_action *action)
 {
-        lustre_swab_lu_fid(&hp->hp_fid);
-        __swab64s(&hp->hp_cookie);
-        __swab64s(&hp->hp_extent.offset);
-        __swab64s(&hp->hp_extent.length);
-        __swab16s(&hp->hp_flags);
-        __swab16s(&hp->hp_errval);
+       __swab32s(&action->hca_state);
+       __swab32s(&action->hca_action);
+       lustre_swab_hsm_extent(&action->hca_location);
 }
-EXPORT_SYMBOL(lustre_swab_hsm_progress);
+EXPORT_SYMBOL(lustre_swab_hsm_current_action);
 
+void lustre_swab_hsm_user_item(struct hsm_user_item *hui)
+{
+       lustre_swab_lu_fid(&hui->hui_fid);
+       lustre_swab_hsm_extent(&hui->hui_extent);
+}
+EXPORT_SYMBOL(lustre_swab_hsm_user_item);
+
+void lustre_swab_layout_intent(struct layout_intent *li)
+{
+       __swab32s(&li->li_opc);
+       __swab32s(&li->li_flags);
+       __swab64s(&li->li_start);
+       __swab64s(&li->li_end);
+}
+EXPORT_SYMBOL(lustre_swab_layout_intent);
+
+void lustre_swab_hsm_progress_kernel(struct hsm_progress_kernel *hpk)
+{
+       lustre_swab_lu_fid(&hpk->hpk_fid);
+       __swab64s(&hpk->hpk_cookie);
+       __swab64s(&hpk->hpk_extent.offset);
+       __swab64s(&hpk->hpk_extent.length);
+       __swab16s(&hpk->hpk_flags);
+       __swab16s(&hpk->hpk_errval);
+}
+EXPORT_SYMBOL(lustre_swab_hsm_progress_kernel);
+
+void lustre_swab_hsm_request(struct hsm_request *hr)
+{
+       __swab32s(&hr->hr_action);
+       __swab32s(&hr->hr_archive_id);
+       __swab64s(&hr->hr_flags);
+       __swab32s(&hr->hr_itemcount);
+       __swab32s(&hr->hr_data_len);
+}
+EXPORT_SYMBOL(lustre_swab_hsm_request);
+
+void lustre_swab_update_buf(struct update_buf *ub)
+{
+       __swab32s(&ub->ub_magic);
+       __swab32s(&ub->ub_count);
+}
+EXPORT_SYMBOL(lustre_swab_update_buf);
+
+void lustre_swab_update_reply_buf(struct update_reply *ur)
+{
+       int i;
+
+       __swab32s(&ur->ur_version);
+       __swab32s(&ur->ur_count);
+       for (i = 0; i < ur->ur_count; i++)
+               __swab32s(&ur->ur_lens[i]);
+}
+EXPORT_SYMBOL(lustre_swab_update_reply_buf);