/* TODO: better use MAC addresses (or motherboard IDs where available). * Or, at least, some checks for MAC addresses should be recorded / added. * When the nodename is misconfigured, data might be scrambled. * MAC addresses should be more secure. * In ideal case, further checks should be added to prohibit accidental * name clashes. */ char *my_id(void) { struct new_utsname *u; if (!id) { //down_read(&uts_sem); // FIXME: this is currenty not EXPORTed from the kernel! u = utsname(); if (u) { id = brick_strdup(u->nodename); } //up_read(&uts_sem); } return id; }
static char *_mars_translate_hostname(const char *name) { struct mars_global *global = mars_global; char *res = brick_strdup(name); struct mars_dent *test; char *tmp; if (unlikely(!global)) { goto done; } for (tmp = res; *tmp; tmp++) { if (*tmp == ':') { *tmp = '\0'; break; } } tmp = path_make("/mars/ips/ip-%s", res); if (unlikely(!tmp)) { goto done; } test = mars_find_dent(global, tmp); if (test && test->new_link) { MARS_DBG("'%s' => '%s'\n", tmp, test->new_link); brick_string_free(res); res = brick_strdup(test->new_link); } else { MARS_DBG("no translation for '%s'\n", tmp); } brick_string_free(tmp); done: return res; }
static int _connect(struct client_output *output, const char *str) { struct sockaddr_storage sockaddr = {}; int status; if (unlikely(!output->path)) { output->path = brick_strdup(str); status = -ENOMEM; if (!output->path) { MARS_DBG("no mem\n"); goto done; } status = -EINVAL; output->host = strchr(output->path, '@'); if (!output->host) { brick_string_free(output->path); output->path = NULL; MARS_ERR("parameter string '%s' contains no remote specifier with '@'-syntax\n", str); goto done; } *output->host++ = '\0'; } if (unlikely(output->receiver.thread)) { MARS_WRN("receiver thread unexpectedly not dead\n"); _kill_thread(&output->receiver, "receiver"); } status = mars_create_sockaddr(&sockaddr, output->host); if (unlikely(status < 0)) { MARS_DBG("no sockaddr, status = %d\n", status); goto done; } status = mars_create_socket(&output->socket, &sockaddr, false); if (unlikely(status < 0)) { MARS_DBG("no socket, status = %d\n", status); goto really_done; } output->socket.s_shutdown_on_err = true; output->receiver.thread = brick_thread_create(receiver_thread, output, "mars_receiver%d", thread_count++); if (unlikely(!output->receiver.thread)) { MARS_ERR("cannot start receiver thread, status = %d\n", status); status = -ENOENT; goto done; } { struct mars_cmd cmd = { .cmd_code = CMD_CONNECT, .cmd_str1 = output->path, }; status = mars_send_struct(&output->socket, &cmd, mars_cmd_meta); if (unlikely(status < 0)) { MARS_DBG("send of connect failed, status = %d\n", status); goto done; } } if (status >= 0) { status = _request_info(output); } done: if (status < 0) { MARS_INF("cannot connect to remote host '%s' (status = %d) -- retrying\n", output->host ? output->host : "NULL", status); _kill_socket(output); } really_done: return status; } ////////////////// own brick / input / output operations ////////////////// static int client_get_info(struct client_output *output, struct mars_info *info) { int status; output->got_info = false; output->get_info = true; wake_up_interruptible(&output->event); wait_event_interruptible_timeout(output->info_event, output->got_info, 60 * HZ); status = -EIO; if (output->got_info && info) { memcpy(info, &output->info, sizeof(*info)); status = 0; } //done: return status; }