1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#ifndef __OBD_CKSUM
36#define __OBD_CKSUM
37#include "../../include/linux/libcfs/libcfs.h"
38#include "lustre/lustre_idl.h"
39
40static inline unsigned char cksum_obd2cfs(enum cksum_type cksum_type)
41{
42 switch (cksum_type) {
43 case OBD_CKSUM_CRC32:
44 return CFS_HASH_ALG_CRC32;
45 case OBD_CKSUM_ADLER:
46 return CFS_HASH_ALG_ADLER32;
47 case OBD_CKSUM_CRC32C:
48 return CFS_HASH_ALG_CRC32C;
49 default:
50 CERROR("Unknown checksum type (%x)!!!\n", cksum_type);
51 LBUG();
52 }
53 return 0;
54}
55
56
57
58
59
60
61
62
63
64
65
66
67
68static inline u32 cksum_type_pack(enum cksum_type cksum_type)
69{
70 unsigned int performance = 0, tmp;
71 u32 flag = OBD_FL_CKSUM_ADLER;
72
73 if (cksum_type & OBD_CKSUM_CRC32) {
74 tmp = cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32));
75 if (tmp > performance) {
76 performance = tmp;
77 flag = OBD_FL_CKSUM_CRC32;
78 }
79 }
80 if (cksum_type & OBD_CKSUM_CRC32C) {
81 tmp = cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32C));
82 if (tmp > performance) {
83 performance = tmp;
84 flag = OBD_FL_CKSUM_CRC32C;
85 }
86 }
87 if (cksum_type & OBD_CKSUM_ADLER) {
88 tmp = cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_ADLER));
89 if (tmp > performance) {
90 performance = tmp;
91 flag = OBD_FL_CKSUM_ADLER;
92 }
93 }
94 if (unlikely(cksum_type && !(cksum_type & (OBD_CKSUM_CRC32C |
95 OBD_CKSUM_CRC32 |
96 OBD_CKSUM_ADLER))))
97 CWARN("unknown cksum type %x\n", cksum_type);
98
99 return flag;
100}
101
102static inline enum cksum_type cksum_type_unpack(u32 o_flags)
103{
104 switch (o_flags & OBD_FL_CKSUM_ALL) {
105 case OBD_FL_CKSUM_CRC32C:
106 return OBD_CKSUM_CRC32C;
107 case OBD_FL_CKSUM_CRC32:
108 return OBD_CKSUM_CRC32;
109 default:
110 break;
111 }
112
113 return OBD_CKSUM_ADLER;
114}
115
116
117
118
119
120static inline enum cksum_type cksum_types_supported_client(void)
121{
122 enum cksum_type ret = OBD_CKSUM_ADLER;
123
124 CDEBUG(D_INFO, "Crypto hash speed: crc %d, crc32c %d, adler %d\n",
125 cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32)),
126 cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32C)),
127 cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_ADLER)));
128
129 if (cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32C)) > 0)
130 ret |= OBD_CKSUM_CRC32C;
131 if (cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32)) > 0)
132 ret |= OBD_CKSUM_CRC32;
133
134 return ret;
135}
136
137
138
139
140
141
142
143
144
145static inline enum cksum_type cksum_type_select(enum cksum_type cksum_types)
146{
147 return cksum_type_unpack(cksum_type_pack(cksum_types));
148}
149
150
151
152
153#define DECLARE_CKSUM_NAME char *cksum_name[] = {"crc32", "adler", "crc32c"}
154
155#endif
156