Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754807AbcL3XAB (ORCPT ); Fri, 30 Dec 2016 18:00:01 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.220]:25204 "EHLO mo4-p00-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754665AbcL3W62 (ORCPT ); Fri, 30 Dec 2016 17:58:28 -0500 X-RZG-AUTH: :OH8QVVOrc/CP6za/qRmbF3BWedPGA1vjs2ejZCzW8NRdwTYefHi0L5RzHLEjAZn5asq7vKs= X-RZG-CLASS-ID: mo00 From: Thomas Schoebel-Theuer To: linux-kernel@vger.kernel.org, tst@schoebel-theuer.de Subject: [RFC 26/32] mars: add new module net Date: Fri, 30 Dec 2016 23:57:52 +0100 Message-Id: <18b28830812ca68d3cc33ac6613de64b1a792c1a.1483138400.git.tst@schoebel-theuer.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3040 Lines: 123 Signed-off-by: Thomas Schoebel-Theuer --- drivers/staging/mars/mars/net.c | 109 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 drivers/staging/mars/mars/net.c diff --git a/drivers/staging/mars/mars/net.c b/drivers/staging/mars/mars/net.c new file mode 100644 index 000000000000..d1b9715c0a93 --- /dev/null +++ b/drivers/staging/mars/mars/net.c @@ -0,0 +1,109 @@ +/* + * MARS Long Distance Replication Software + * + * Copyright (C) 2010-2014 Thomas Schoebel-Theuer + * Copyright (C) 2011-2014 1&1 Internet AG + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +#include "strategy.h" +#include + +static +char *_xio_translate_hostname(const char *name) +{ + char *res = brick_strdup(name); + char *test; + char *tmp; + + 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_readlink(tmp); + if (test && test[0]) { + XIO_DBG("'%s' => '%s'\n", tmp, test); + brick_string_free(res); + res = test; + } else { + brick_string_free(test); + XIO_WRN("no hostname translation for '%s'\n", tmp); + } + brick_string_free(tmp); + +done: + return res; +} + +int xio_send_dent_list(struct xio_socket *sock, struct list_head *anchor) +{ + struct list_head *tmp; + struct mars_dent *dent; + int status = 0; + + for (tmp = anchor->next; tmp != anchor; tmp = tmp->next) { + dent = container_of(tmp, struct mars_dent, dent_link); + status = xio_send_struct(sock, dent, mars_dent_meta); + if (status < 0) + break; + } + if (status >= 0) { /* send EOR */ + status = xio_send_struct(sock, NULL, mars_dent_meta); + } + return status; +} + +int xio_recv_dent_list(struct xio_socket *sock, struct list_head *anchor) +{ + int status; + + for (;;) { + struct mars_dent *dent = brick_zmem_alloc(sizeof(struct mars_dent)); + + INIT_LIST_HEAD(&dent->dent_link); + INIT_LIST_HEAD(&dent->brick_list); + + status = xio_recv_struct(sock, dent, mars_dent_meta); + if (status <= 0) { + xio_free_dent(dent); + goto done; + } + list_add_tail(&dent->dent_link, anchor); + } +done: + return status; +} + +/***************** module init stuff ************************/ + +int __init init_sy_net(void) +{ + XIO_INF("init_sy_net()\n"); + xio_translate_hostname = _xio_translate_hostname; + return 0; +} + +void exit_sy_net(void) +{ + XIO_INF("exit_sy_net()\n"); +} -- 2.11.0