X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=server.c;h=eccd9d37e80f9b48026c9d5435111c84c55e15ca;hp=f53e2c8d161c251469432a71e586b46b83e67416;hb=8dc1a870973e;hpb=dfc8e76c8d438da9861acfcdc96c46afe4339148 diff --git a/server.c b/server.c index f53e2c8d..eccd9d37 100644 --- a/server.c +++ b/server.c @@ -46,7 +46,7 @@ struct sk_entry { int opcode; /* Actual command fields */ void *buf; off_t size; - uint64_t *tagptr; + uint64_t tag; struct flist_head next; /* Other sk_entry's, if linked command */ }; @@ -151,11 +151,13 @@ static int __sk_out_drop(struct sk_out *sk_out) 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; } } @@ -168,8 +170,7 @@ void sk_out_drop(void) 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, @@ -536,7 +537,10 @@ static struct sk_entry *fio_net_prep_cmd(uint16_t opcode, void *buf, entry->buf = buf; entry->size = size; - entry->tagptr = tagptr; + if (tagptr) + entry->tag = *tagptr; + else + entry->tag = 0; entry->flags = flags; return entry; } @@ -754,6 +758,8 @@ static int handle_run_cmd(struct sk_out *sk_out, struct flist_head *job_list, pid_t pid; int ret; + sk_out_assign(sk_out); + fio_time_init(); set_genesis_time(); @@ -765,6 +771,7 @@ static int handle_run_cmd(struct sk_out *sk_out, struct flist_head *job_list, ret = fio_backend(sk_out); free_threads_shm(); + sk_out_drop(); _exit(ret); } @@ -1069,29 +1076,24 @@ static void finish_entry(struct sk_entry *entry) 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; - - if (entry->tagptr) - *tag = *entry->tagptr; - else - *tag = 0; } 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; @@ -1099,9 +1101,10 @@ static int send_vec_entry(struct sk_out *sk_out, struct sk_entry *first) 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); } @@ -1117,16 +1120,11 @@ static int handle_sk_entry(struct sk_out *sk_out, struct sk_entry *entry) if (entry->flags & SK_F_VEC) ret = send_vec_entry(sk_out, entry); else if (entry->flags & SK_F_SIMPLE) { - uint64_t tag = 0; - - if (entry->tagptr) - tag = *entry->tagptr; - - 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->tagptr, NULL); + entry->size, &entry->tag, NULL); } fio_mutex_up(&sk_out->xmit); @@ -1801,13 +1799,14 @@ int fio_server_get_verify_state(const char *name, int threadnumber, 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); @@ -1825,17 +1824,19 @@ int fio_server_get_verify_state(const char *name, int threadnumber, */ 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; } /* @@ -1843,12 +1844,15 @@ fail: * 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); @@ -1857,7 +1861,7 @@ fail: sfree(rep->data); __fio_mutex_remove(&rep->lock); sfree(rep); - return 0; + return ret; } static int fio_init_server_ip(void)