int refs;
sk_lock(sk_out);
+ assert(sk_out->refs != 0);
refs = --sk_out->refs;
sk_unlock(sk_out);
if (!refs) {
sk_out_free(sk_out);
+ pthread_setspecific(sk_out_key, NULL);
return 0;
}
}
struct sk_out *sk_out;
sk_out = pthread_getspecific(sk_out_key);
- if (!__sk_out_drop(sk_out))
- pthread_setspecific(sk_out_key, NULL);
+ __sk_out_drop(sk_out);
}
static void __fio_init_net_cmd(struct fio_net_cmd *cmd, uint16_t opcode,
return fio_sendv_data(sk, &iov, 1);
}
-static int fio_recv_data(int sk, void *p, unsigned int len)
+static int fio_recv_data(int sk, void *p, unsigned int len, bool wait)
{
+ int flags;
+
+ if (wait)
+ flags = MSG_WAITALL;
+ else
+ flags = MSG_DONTWAIT;
+
do {
- int ret = recv(sk, p, len, MSG_WAITALL);
+ int ret = recv(sk, p, len, flags);
if (ret > 0) {
len -= ret;
continue;
} else if (!ret)
break;
- else if (errno == EAGAIN || errno == EINTR)
- continue;
- else
+ else if (errno == EAGAIN || errno == EINTR) {
+ if (wait)
+ continue;
+ break;
+ } else
break;
} while (!exit_backend);
/*
* Read (and defragment, if necessary) incoming commands
*/
-struct fio_net_cmd *fio_net_recv_cmd(int sk)
+struct fio_net_cmd *fio_net_recv_cmd(int sk, bool wait)
{
struct fio_net_cmd cmd, *tmp, *cmdret = NULL;
size_t cmd_size = 0, pdu_offset = 0;
void *pdu = NULL;
do {
- ret = fio_recv_data(sk, &cmd, sizeof(cmd));
+ ret = fio_recv_data(sk, &cmd, sizeof(cmd), wait);
if (ret)
break;
/* There's payload, get it */
pdu = (void *) cmdret->payload + pdu_offset;
- ret = fio_recv_data(sk, pdu, cmd.pdu_len);
+ ret = fio_recv_data(sk, pdu, cmd.pdu_len, wait);
if (ret)
break;
pid_t pid;
int ret;
+ sk_out_assign(sk_out);
+
fio_time_init();
set_genesis_time();
ret = fio_backend(sk_out);
free_threads_shm();
+ sk_out_drop();
_exit(ret);
}
sfree(entry);
}
-static void entry_set_flags_tag(struct sk_entry *entry, struct flist_head *list,
- unsigned int *flags, uint64_t *tag)
+static void entry_set_flags(struct sk_entry *entry, struct flist_head *list,
+ unsigned int *flags)
{
if (!flist_empty(list))
*flags = FIO_NET_CMD_F_MORE;
else
*flags = 0;
-
- *tag = entry->tag;
}
static int send_vec_entry(struct sk_out *sk_out, struct sk_entry *first)
{
unsigned int flags;
- uint64_t tag;
int ret;
- entry_set_flags_tag(first, &first->next, &flags, &tag);
+ entry_set_flags(first, &first->next, &flags);
- ret = fio_send_cmd_ext_pdu(sk_out->sk, first->opcode, first->buf, first->size, tag, flags);
+ ret = fio_send_cmd_ext_pdu(sk_out->sk, first->opcode, first->buf,
+ first->size, first->tag, flags);
while (!flist_empty(&first->next)) {
struct sk_entry *next;
next = flist_first_entry(&first->next, struct sk_entry, list);
flist_del_init(&next->list);
- entry_set_flags_tag(next, &first->next, &flags, &tag);
+ entry_set_flags(next, &first->next, &flags);
- ret += fio_send_cmd_ext_pdu(sk_out->sk, next->opcode, next->buf, next->size, tag, flags);
+ ret += fio_send_cmd_ext_pdu(sk_out->sk, next->opcode, next->buf,
+ next->size, next->tag, flags);
finish_entry(next);
}
if (entry->flags & SK_F_VEC)
ret = send_vec_entry(sk_out, entry);
else if (entry->flags & SK_F_SIMPLE) {
- uint64_t tag = entry->tag;
-
- ret = fio_net_send_simple_cmd(sk_out->sk, entry->opcode, tag,
- NULL);
+ ret = fio_net_send_simple_cmd(sk_out->sk, entry->opcode,
+ entry->tag, NULL);
} else {
ret = fio_net_send_cmd(sk_out->sk, entry->opcode, entry->buf,
entry->size, &entry->tag, NULL);
if (ret < 0)
break;
- cmd = fio_net_recv_cmd(sk_out->sk);
+ cmd = fio_net_recv_cmd(sk_out->sk, true);
if (!cmd) {
ret = -1;
break;
struct cmd_reply *rep;
uint64_t tag;
void *data;
+ int ret;
dprint(FD_NET, "server: request verify state\n");
rep = smalloc(sizeof(*rep));
if (!rep) {
log_err("fio: smalloc pool too small\n");
- return 1;
+ return ENOMEM;
}
__fio_mutex_init(&rep->lock, FIO_MUTEX_LOCKED);
*/
if (fio_mutex_down_timeout(&rep->lock, 10000)) {
log_err("fio: timed out waiting for reply\n");
+ ret = ETIMEDOUT;
goto fail;
}
if (rep->error) {
- log_err("fio: failure on receiving state file: %s\n",
- strerror(rep->error));
+ log_err("fio: failure on receiving state file %s: %s\n",
+ out.path, strerror(rep->error));
+ ret = rep->error;
fail:
*datap = NULL;
sfree(rep);
fio_net_queue_quit();
- return 1;
+ return ret;
}
/*
* the header, and the thread_io_list checksum
*/
s = rep->data + sizeof(struct verify_state_hdr);
- if (verify_state_hdr(rep->data, s, version))
+ if (verify_state_hdr(rep->data, s, version)) {
+ ret = EILSEQ;
goto fail;
+ }
/*
* Don't need the header from now, copy just the thread_io_list
*/
+ ret = 0;
rep->size -= sizeof(struct verify_state_hdr);
data = malloc(rep->size);
memcpy(data, s, rep->size);
sfree(rep->data);
__fio_mutex_remove(&rep->lock);
sfree(rep);
- return 0;
+ return ret;
}
static int fio_init_server_ip(void)
sigaction(SIGINT, &act, NULL);
}
-static int fio_server(void)
+void fio_server_destroy_sk_key(void)
{
- int sk, ret;
+ pthread_key_delete(sk_out_key);
+}
+int fio_server_create_sk_key(void)
+{
if (pthread_key_create(&sk_out_key, NULL)) {
log_err("fio: can't create sk_out backend key\n");
- return -1;
+ return 1;
}
pthread_setspecific(sk_out_key, NULL);
+ return 0;
+}
+
+static int fio_server(void)
+{
+ int sk, ret;
dprint(FD_NET, "starting server\n");