};
static FLIST_HEAD(client_list);
-static unsigned int nr_clients;
static struct fio_client *find_client_by_fd(int fd)
{
return NULL;
}
+#if 0
static struct fio_client *find_client_by_name(const char *name)
{
struct fio_client *client;
return NULL;
}
+#endif
static void remove_client(struct fio_client *client)
{
free(client);
}
-int fio_client_connect(const char *host)
+void fio_client_add(const char *hostname)
{
struct fio_client *client;
- int fd;
client = malloc(sizeof(*client));
+ memset(client, 0, sizeof(*client));
+ client->hostname = strdup(hostname);
+ client->fd = -1;
+ flist_add(&client->list, &client_list);
+ nr_clients++;
+}
+
+static int fio_client_connect(struct fio_client *client)
+{
+ int fd;
memset(&client->addr, 0, sizeof(client->addr));
client->addr.sin_family = AF_INET;
client->addr.sin_port = htons(fio_net_port);
- if (inet_aton(host, &client->addr.sin_addr) != 1) {
+ if (inet_aton(client->hostname, &client->addr.sin_addr) != 1) {
struct hostent *hent;
- hent = gethostbyname(host);
+ hent = gethostbyname(client->hostname);
if (!hent) {
log_err("fio: gethostbyname: %s\n", strerror(errno));
return 1;
return 1;
}
- client->hostname = strdup(host);
- flist_add(&client->list, &client_list);
- nr_clients++;
client->fd = fd;
return 0;
}
+int fio_clients_connect(void)
+{
+ struct fio_client *client;
+ struct flist_head *entry, *tmp;
+ int ret;
+
+ flist_for_each_safe(entry, tmp, &client_list) {
+ client = flist_entry(entry, struct fio_client, list);
+
+ ret = fio_client_connect(client);
+ if (ret)
+ remove_client(client);
+ }
+
+ return !nr_clients;
+}
+
static int send_file_buf(struct fio_client *client, char *buf, off_t size)
{
return fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, size);
* Send file contents to server backend. We could use sendfile(), but to remain
* more portable lets just read/write the darn thing.
*/
-int fio_client_send_ini(const char *hostname, const char *filename)
+static int fio_client_send_ini(struct fio_client *client, const char *filename)
{
- struct fio_client *client;
struct stat sb;
char *p, *buf;
off_t len;
int fd, ret;
- client = find_client_by_name(hostname);
- if (!client) {
- log_err("fio: can't find client for host %s\n", hostname);
- return 1;
- }
-
fd = open(filename, O_RDONLY);
if (fd < 0) {
log_err("fio: job file open: %s\n", strerror(errno));
return ret;
}
+int fio_clients_send_ini(const char *filename)
+{
+ struct fio_client *client;
+ struct flist_head *entry, *tmp;
+
+ flist_for_each_safe(entry, tmp, &client_list) {
+ client = flist_entry(entry, struct fio_client, list);
+
+ if (fio_client_send_ini(client, filename))
+ remove_client(client);
+ }
+
+ return !nr_clients;
+}
+
static int handle_client(struct fio_client *client)
{
struct fio_net_cmd *cmd;
int warnings_fatal = 0;
int terse_version = 2;
int is_backend = 0;
-int is_client = 0;
-char *client;
+int nr_clients = 0;
int write_bw_log = 0;
int read_only = 0;
}
break;
case 'S':
- if (is_client) {
+ if (nr_clients) {
log_err("fio: can't be both client and server\n");
do_exit++;
exit_val = 1;
exit_val = 1;
break;
}
- is_client = 1;
- client = strdup(optarg);
+ fio_client_add(optarg);
break;
default:
do_exit++;
if (do_exit)
exit(exit_val);
- if (is_client && fio_client_connect(client)) {
+ if (nr_clients && fio_clients_connect()) {
do_exit++;
exit_val = 1;
return 1;
for (i = 0; i < job_files; i++) {
if (fill_def_thread())
return 1;
- if (is_client) {
- if (fio_client_send_ini(client, ini_file[i]))
+ if (nr_clients) {
+ if (fio_clients_send_ini(ini_file[i]))
return 1;
} else {
if (parse_jobs_ini(ini_file[i], 0, i))
return 0;
if (exec_profile)
return 0;
- if (is_backend || is_client)
+ if (is_backend || nr_clients)
return 0;
log_err("No jobs(s) defined\n\n");
extern int fio_server_log(const char *format, ...);
extern int fio_net_send_cmd(int, uint16_t, const char *, off_t);
-extern int fio_client_connect(const char *);
-extern int fio_client_send_ini(const char *, const char *);
+extern int fio_clients_connect(void);
+extern int fio_clients_send_ini(const char *);
extern int fio_handle_clients(void);
+extern void fio_client_add(const char *);
extern int fio_recv_data(int sk, void *p, unsigned int len);
extern int fio_send_data(int sk, const void *p, unsigned int len);