summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2011-10-03 14:45:27 +0200
committerJens Axboe <axboe@kernel.dk>2011-10-03 14:45:27 +0200
commitddcc0b69aa4ed04c8681f447a1a6274bb8837a14 (patch)
treea1b30e7b4bce73becd9f5d332b5977515a87c571
parenta450e4924ad4ae4a05015e55cb54c78fb0c5015f (diff)
downloadfio-ddcc0b69aa4ed04c8681f447a1a6274bb8837a14.tar.gz
Add type checking to 16/32/64 endianness converters
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--client.c8
-rw-r--r--server.c20
-rw-r--r--server.h51
-rw-r--r--stat.h6
4 files changed, 55 insertions, 30 deletions
diff --git a/client.c b/client.c
index 459c300b..c6588664 100644
--- a/client.c
+++ b/client.c
@@ -208,8 +208,8 @@ static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
dst->min_val = le64_to_cpu(src->min_val);
dst->samples = le64_to_cpu(src->samples);
/* FIXME */
- dst->mean = le64_to_cpu(src->mean);
- dst->S = le64_to_cpu(src->S);
+ dst->mean = __le64_to_cpu(src->mean);
+ dst->S = __le64_to_cpu(src->S);
}
static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
@@ -267,8 +267,8 @@ static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
dst->total_run_time = le64_to_cpu(src->total_run_time);
dst->continue_on_error = le16_to_cpu(src->continue_on_error);
dst->total_err_count = le64_to_cpu(src->total_err_count);
- dst->first_error = le64_to_cpu(src->first_error);
- dst->kb_base = le64_to_cpu(src->kb_base);
+ dst->first_error = le32_to_cpu(src->first_error);
+ dst->kb_base = le32_to_cpu(src->kb_base);
}
static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
diff --git a/server.c b/server.c
index 72761c56..92d37bd9 100644
--- a/server.c
+++ b/server.c
@@ -180,11 +180,11 @@ void fio_net_cmd_crc(struct fio_net_cmd *cmd)
{
uint32_t pdu_len;
- cmd->cmd_crc16 = cpu_to_le16(crc16(cmd, FIO_NET_CMD_CRC_SZ));
+ cmd->cmd_crc16 = __cpu_to_le16(crc16(cmd, FIO_NET_CMD_CRC_SZ));
pdu_len = le32_to_cpu(cmd->pdu_len);
if (pdu_len)
- cmd->pdu_crc16 = cpu_to_le16(crc16(cmd->payload, pdu_len));
+ cmd->pdu_crc16 = __cpu_to_le16(crc16(cmd->payload, pdu_len));
}
int fio_net_send_cmd(int fd, uint16_t opcode, const void *buf, off_t size)
@@ -203,7 +203,7 @@ int fio_net_send_cmd(int fd, uint16_t opcode, const void *buf, off_t size)
fio_init_net_cmd(cmd, opcode, buf, this_len);
if (this_len < size)
- cmd->flags = cpu_to_le32(FIO_NET_CMD_F_MORE);
+ cmd->flags = __cpu_to_le32(FIO_NET_CMD_F_MORE);
fio_net_cmd_crc(cmd);
@@ -219,7 +219,7 @@ int fio_net_send_cmd(int fd, uint16_t opcode, const void *buf, off_t size)
static int send_simple_command(int sk, uint16_t opcode, uint64_t serial)
{
struct fio_net_cmd cmd = {
- .version = cpu_to_le16(FIO_SERVER_VER1),
+ .version = __cpu_to_le16(FIO_SERVER_VER1),
.opcode = cpu_to_le16(opcode),
.serial = cpu_to_le64(serial),
};
@@ -442,8 +442,8 @@ static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
dst->min_val = cpu_to_le64(src->min_val);
dst->samples = cpu_to_le64(src->samples);
/* FIXME */
- dst->mean = cpu_to_le64(src->mean);
- dst->S = cpu_to_le64(src->S);
+ dst->mean = __cpu_to_le64(src->mean);
+ dst->S = __cpu_to_le64(src->S);
}
static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
@@ -476,9 +476,9 @@ void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs)
strcpy(p.ts.verror, ts->verror);
strcpy(p.ts.description, ts->description);
- p.ts.error = cpu_to_le32(ts->error);
+ p.ts.error = cpu_to_le32(ts->error);
p.ts.groupid = cpu_to_le32(ts->groupid);
- p.ts.pid = cpu_to_le32(ts->pid);
+ p.ts.pid = cpu_to_le32(ts->pid);
p.ts.members = cpu_to_le32(ts->members);
for (i = 0; i < 2; i++) {
@@ -527,8 +527,8 @@ void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs)
p.ts.total_run_time = cpu_to_le64(ts->total_run_time);
p.ts.continue_on_error = cpu_to_le16(ts->continue_on_error);
p.ts.total_err_count = cpu_to_le64(ts->total_err_count);
- p.ts.first_error = cpu_to_le64(ts->first_error);
- p.ts.kb_base = cpu_to_le64(ts->kb_base);
+ p.ts.first_error = cpu_to_le32(ts->first_error);
+ p.ts.kb_base = cpu_to_le32(ts->kb_base);
convert_gs(&p.rs, rs);
diff --git a/server.h b/server.h
index 10c9006e..9aa91de1 100644
--- a/server.h
+++ b/server.h
@@ -76,29 +76,54 @@ extern int exit_backend;
extern int fio_net_port;
#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define le16_to_cpu(x) (x)
-#define le32_to_cpu(x) (x)
-#define le64_to_cpu(x) (x)
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#define cpu_to_le64(x) (x)
+#define __le16_to_cpu(x) (x)
+#define __le32_to_cpu(x) (x)
+#define __le64_to_cpu(x) (x)
+#define __cpu_to_le16(x) (x)
+#define __cpu_to_le32(x) (x)
+#define __cpu_to_le64(x) (x)
#elif __BYTE_ORDER == __BIG_ENDIAN
-#define le16_to_cpu(x) __bswap_16(x)
-#define le32_to_cpu(x) __bswap_32(x)
-#define le64_to_cpu(x) __bswap_64(x)
-#define cpu_to_le16(x) __bswap_16(x)
-#define cpu_to_le32(x) __bswap_32(x)
-#define cpu_to_le64(x) __bswap_64(x)
+#define __le16_to_cpu(x) __bswap_16(x)
+#define __le32_to_cpu(x) __bswap_32(x)
+#define __le64_to_cpu(x) __bswap_64(x)
+#define __cpu_to_le16(x) __bswap_16(x)
+#define __cpu_to_le32(x) __bswap_32(x)
+#define __cpu_to_le64(x) __bswap_64(x)
#else
#error "Endianness not detected"
#endif
+#define le16_to_cpu(val) ({ \
+ uint16_t *__val = &(val); \
+ __le16_to_cpu(*__val); \
+})
+#define le32_to_cpu(val) ({ \
+ uint32_t *__val = &(val); \
+ __le32_to_cpu(*__val); \
+})
+#define le64_to_cpu(val) ({ \
+ uint64_t *__val = &(val); \
+ __le64_to_cpu(*__val); \
+})
+#define cpu_to_le16(val) ({ \
+ uint16_t *__val = &(val); \
+ __cpu_to_le16(*__val); \
+})
+#define cpu_to_le32(val) ({ \
+ uint32_t *__val = &(val); \
+ __cpu_to_le32(*__val); \
+})
+#define cpu_to_le64(val) ({ \
+ uint64_t *__val = &(val); \
+ __cpu_to_le64(*__val); \
+})
+
static inline void fio_init_net_cmd(struct fio_net_cmd *cmd, uint16_t opcode,
const void *pdu, uint32_t pdu_len)
{
memset(cmd, 0, sizeof(*cmd));
- cmd->version = cpu_to_le16(FIO_SERVER_VER1);
+ cmd->version = __cpu_to_le16(FIO_SERVER_VER1);
cmd->opcode = cpu_to_le16(opcode);
if (pdu) {
diff --git a/stat.h b/stat.h
index 507a76a9..cba87145 100644
--- a/stat.h
+++ b/stat.h
@@ -115,8 +115,8 @@ struct group_run_stats {
struct thread_stat {
char name[FIO_JOBNAME_SIZE];
char verror[FIO_VERROR_SIZE];
- int32_t error;
- int32_t groupid;
+ uint32_t error;
+ uint32_t groupid;
uint32_t pid;
char description[FIO_JOBNAME_SIZE];
uint32_t members;
@@ -163,7 +163,7 @@ struct thread_stat {
*/
uint16_t continue_on_error;
uint64_t total_err_count;
- int32_t first_error;
+ uint32_t first_error;
uint32_t kb_base;
};