Don't require CONFIG_CRYPTO_CRC32 to build if not configured,
as it may not be available for all kernels and is easily fixed.
Consolidate the early reply code in sec_plain.c to also call
lustre_msg_calc_cksum() to reduce code duplication.
Fixes:
e1a0f602a608 ("LU-13127 libcfs: make noise to console if CRC32 is missing")
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I00511df418ddfbd8522936cf2bc0f3193d2540e5
Reviewed-on: https://review.whamcloud.com/39201
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alexey Lyashkov <alexey.lyashkov@hpe.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
EXTRA_KCFLAGS="$tmp_flags"
]) # LIBCFS_CACHE_DETAIL_WRITERS
-#
-# LIBCFS_CONFIG_CRYPTO_CRC32
-#
-# The kernel must support CONFIG_CRYPTO_CRC32 to RPC checksumming
-#
-AC_DEFUN([LIBCFS_CONFIG_CRYPTO_CRC32], [
-LB_CHECK_CONFIG_IM([CRYPTO_CRC32], [],
- [AC_MSG_ERROR([
-
-Lustre requires that CONFIG_CRYPTO_CRC32 is enabled in your kernel.
-])])
-]) # LIBCFS_CONFIG_CRYPTO_CRC32
-
AC_DEFUN([LIBCFS_PROG_LINUX_SRC], [] )
AC_DEFUN([LIBCFS_PROG_LINUX_RESULTS], [])
AC_MSG_NOTICE([LibCFS kernel checks
==============================================================================])
LIBCFS_CONFIG_PANIC_DUMPLOG
-LIBCFS_CONFIG_CRYPTO_CRC32
# 3.11
LIBCFS_KTIME_GET_TS64
char *lustre_msg_get_jobid(struct lustre_msg *msg);
__u32 lustre_msg_get_cksum(struct lustre_msg *msg);
__u64 lustre_msg_get_mbits(struct lustre_msg *msg);
-__u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
+__u32 lustre_msg_calc_cksum(struct lustre_msg *msg, __u32 buf);
void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
#define DEBUG_SUBSYSTEM S_RPC
+#ifndef CONFIG_CRYPTO_CRC32
+#include <linux/crc32.h>
+#endif
+
#include <libcfs/libcfs.h>
#include <llog_swab.h>
}
}
-__u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
+__u32 lustre_msg_calc_cksum(struct lustre_msg *msg, __u32 buf)
{
switch (msg->lm_magic) {
case LUSTRE_MSG_MAGIC_V2: {
- struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
- __u32 len = lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF);
-
- unsigned int hsize = 4;
+ struct ptlrpc_body *pb = lustre_msg_buf_v2(msg, buf, 0);
+ __u32 len = lustre_msg_buflen(msg, buf);
__u32 crc;
LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
+#ifdef CONFIG_CRYPTO_CRC32
+ unsigned int hsize = 4;
cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb,
len, NULL, 0, (unsigned char *)&crc,
&hsize);
+#else
+ crc = crc32_le(~(__u32)0, (unsigned char *)pb, len);
+#endif
return crc;
}
default:
if (req->rq_early) {
cksums = lustre_msg_get_cksum(req->rq_repdata);
- cksumc = lustre_msg_calc_cksum(req->rq_repmsg);
+ cksumc = lustre_msg_calc_cksum(req->rq_repmsg,
+ MSG_PTLRPC_BODY_OFF);
if (cksumc != cksums) {
CDEBUG(D_SEC,
rs->rs_repbuf->lm_secflvr = SPTLRPC_FLVR_NULL;
rs->rs_repdata_len = req->rq_replen;
+ req->rq_reply_off = 0;
if (likely(req->rq_packed_final)) {
if (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)
req->rq_reply_off = lustre_msg_early_size();
- else
- req->rq_reply_off = 0;
} else {
__u32 cksum;
- cksum = lustre_msg_calc_cksum(rs->rs_repbuf);
+ cksum = lustre_msg_calc_cksum(rs->rs_repbuf,
+ MSG_PTLRPC_BODY_OFF);
lustre_msg_set_cksum(rs->rs_repbuf, cksum);
- req->rq_reply_off = 0;
}
return 0;
{
struct lustre_msg *msg = req->rq_repdata;
struct plain_header *phdr;
- __u32 cksum;
bool swabbed;
ENTRY;
}
if (unlikely(req->rq_early)) {
- unsigned int hsize = 4;
+ __u32 cksum = lustre_msg_calc_cksum(msg, PLAIN_PACK_MSG_OFF);
- cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32,
- lustre_msg_buf(msg, PLAIN_PACK_MSG_OFF, 0),
- lustre_msg_buflen(msg, PLAIN_PACK_MSG_OFF),
- NULL, 0, (unsigned char *)&cksum, &hsize);
if (cksum != msg->lm_cksum) {
CDEBUG(D_SEC,
"early reply checksum mismatch: %08x != %08x\n",
phdr->ph_flags |= PLAIN_FL_BULK;
rs->rs_repdata_len = len;
+ req->rq_reply_off = 0;
if (likely(req->rq_packed_final)) {
if (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)
req->rq_reply_off = plain_at_offset;
- else
- req->rq_reply_off = 0;
} else {
- unsigned int hsize = 4;
-
- cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32,
- lustre_msg_buf(msg, PLAIN_PACK_MSG_OFF, 0),
- lustre_msg_buflen(msg, PLAIN_PACK_MSG_OFF),
- NULL, 0, (unsigned char *)&msg->lm_cksum, &hsize);
- req->rq_reply_off = 0;
+ msg->lm_cksum = lustre_msg_calc_cksum(msg, PLAIN_PACK_MSG_OFF);
}
RETURN(0);