fio & pgbench
This commit is contained in:
@@ -16,12 +16,15 @@
|
||||
|
||||
struct ipc_client_ctx {
|
||||
int fd;
|
||||
uint8_t rx_buf[ZVFS_IPC_BUF_SIZE];
|
||||
uint8_t *rx_buf;
|
||||
uint8_t *tx_buf;
|
||||
size_t rx_len;
|
||||
};
|
||||
|
||||
static __thread struct ipc_client_ctx g_ipc_tls = {
|
||||
.fd = -1,
|
||||
.rx_buf = NULL,
|
||||
.tx_buf = NULL,
|
||||
.rx_len = 0,
|
||||
};
|
||||
|
||||
@@ -47,6 +50,24 @@ static void ipc_close_conn(struct ipc_client_ctx *ctx) {
|
||||
ctx->rx_len = 0;
|
||||
}
|
||||
|
||||
static int ipc_ensure_buffers(struct ipc_client_ctx *ctx) {
|
||||
if (!ctx->rx_buf) {
|
||||
ctx->rx_buf = (uint8_t *)malloc(ZVFS_IPC_BUF_SIZE);
|
||||
if (!ctx->rx_buf) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (!ctx->tx_buf) {
|
||||
ctx->tx_buf = (uint8_t *)malloc(ZVFS_IPC_BUF_SIZE);
|
||||
if (!ctx->tx_buf) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ipc_connect(struct ipc_client_ctx *ctx) {
|
||||
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
@@ -113,12 +134,12 @@ static int try_pop_resp(struct ipc_client_ctx *ctx, struct zvfs_resp *resp) {
|
||||
|
||||
static int read_into_rx(struct ipc_client_ctx *ctx) {
|
||||
while (1) {
|
||||
if (ctx->rx_len >= sizeof(ctx->rx_buf)) {
|
||||
if (ctx->rx_len >= ZVFS_IPC_BUF_SIZE) {
|
||||
errno = EOVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t n = read(ctx->fd, ctx->rx_buf + ctx->rx_len, sizeof(ctx->rx_buf) - ctx->rx_len);
|
||||
ssize_t n = read(ctx->fd, ctx->rx_buf + ctx->rx_len, ZVFS_IPC_BUF_SIZE - ctx->rx_len);
|
||||
if (n > 0) {
|
||||
ctx->rx_len += (size_t)n;
|
||||
return 0;
|
||||
@@ -152,7 +173,7 @@ static int recv_one_resp(struct ipc_client_ctx *ctx, struct zvfs_resp *resp_out)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ctx->rx_len == sizeof(ctx->rx_buf)) {
|
||||
if (ctx->rx_len == ZVFS_IPC_BUF_SIZE) {
|
||||
struct zvfs_resp probe;
|
||||
memset(&probe, 0, sizeof(probe));
|
||||
if (zvfs_deserialize_resp(ctx->rx_buf, ctx->rx_len, &probe) == 0) {
|
||||
@@ -183,22 +204,24 @@ static int set_errno_by_status(int status) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t tx[ZVFS_IPC_BUF_SIZE];
|
||||
|
||||
static int ipc_do_req(struct zvfs_req *req, struct zvfs_resp *resp_out) {
|
||||
struct ipc_client_ctx *ctx = &g_ipc_tls;
|
||||
|
||||
if (ipc_ensure_buffers(ctx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ipc_ensure_connected(ctx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t tx_len = zvfs_serialize_req(req, tx, sizeof(tx));
|
||||
size_t tx_len = zvfs_serialize_req(req, ctx->tx_buf, ZVFS_IPC_BUF_SIZE);
|
||||
if (tx_len == 0) {
|
||||
errno = EMSGSIZE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (write_all(ctx->fd, tx, tx_len) != 0) {
|
||||
if (write_all(ctx->fd, ctx->tx_buf, tx_len) != 0) {
|
||||
ipc_close_conn(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user