mars/kernel/sy_old/sy_net.c

152 lines
3.7 KiB
C
Raw Normal View History

2014-11-21 10:51:34 +00:00
/*
* MARS Long Distance Replication Software
*
* This file is part of MARS project: http://schoebel.github.io/mars/
*
* 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
2011-07-22 10:43:40 +00:00
//#define BRICK_DEBUGGING
//#define MARS_DEBUGGING
//#define IO_DEBUGGING
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include "strategy.h"
#include "../mars_net.h"
static
char *_mars_translate_hostname(const char *name)
{
2013-04-10 07:54:04 +00:00
char *res = brick_strdup(name);
2011-07-22 10:43:40 +00:00
char *tmp;
char *trans;
2013-04-10 07:54:04 +00:00
for (tmp = res; *tmp; tmp++) {
if (*tmp == ':') {
*tmp = '\0';
break;
}
}
tmp = path_make("/mars/ips/ip-%s", res);
2011-07-22 10:43:40 +00:00
if (unlikely(!tmp)) {
goto done;
}
trans = ordered_readlink(tmp, NULL);
if (trans && trans[0]) {
MARS_DBG("'%s' => '%s'\n", tmp, trans);
2013-04-10 07:54:04 +00:00
brick_string_free(res);
res = trans;
2013-04-10 07:54:04 +00:00
} else {
MARS_DBG("no translation for '%s'\n", tmp);
2017-09-05 09:23:44 +00:00
brick_string_free(trans);
2011-07-22 10:43:40 +00:00
}
2011-08-12 11:09:48 +00:00
brick_string_free(tmp);
2011-07-22 10:43:40 +00:00
done:
2013-04-10 07:54:04 +00:00
return res;
2011-07-22 10:43:40 +00:00
}
int mars_send_dent_list(struct mars_global *global, struct mars_socket *sock)
2011-07-22 10:43:40 +00:00
{
struct list_head *anchor;
2011-07-22 10:43:40 +00:00
struct list_head *tmp;
struct mars_dent *dent;
int status = 0;
2020-07-08 20:14:03 +00:00
down_read(&global->dent_mutex);
anchor = &global->dent_anchor;
2011-07-22 10:43:40 +00:00
for (tmp = anchor->next; tmp != anchor; tmp = tmp->next) {
dent = container_of(tmp, struct mars_dent, dent_link);
2020-07-08 20:14:03 +00:00
dent->d_proto = MARS_PROTO_LEVEL;
2017-04-12 07:50:19 +00:00
status = mars_send_struct(sock, dent, mars_dent_meta, true);
2011-07-22 10:43:40 +00:00
if (status < 0)
break;
}
2011-08-31 11:42:04 +00:00
if (status >= 0) { // send EOR
2017-04-12 07:50:19 +00:00
status = mars_send_struct(sock, NULL, mars_dent_meta, false);
2011-07-22 10:43:40 +00:00
}
up_read(&global->dent_mutex);
2011-07-22 10:43:40 +00:00
return status;
}
EXPORT_SYMBOL_GPL(mars_send_dent_list);
int mars_recv_dent_list(struct mars_global *global, struct mars_socket *sock)
2011-07-22 10:43:40 +00:00
{
struct list_head *anchor;
2011-07-22 10:43:40 +00:00
int status;
down_write(&global->dent_mutex);
anchor = &global->dent_anchor;
2011-07-22 10:43:40 +00:00
for (;;) {
2011-08-12 11:09:48 +00:00
struct mars_dent *dent = brick_zmem_alloc(sizeof(struct mars_dent));
2020-09-17 16:06:09 +00:00
struct list_head *hash_anchor;
unsigned int hash;
2011-07-22 10:43:40 +00:00
if (!dent)
return -ENOMEM;
//MARS_IO("\n");
2014-04-07 12:56:03 +00:00
INIT_LIST_HEAD(&dent->dent_link);
INIT_LIST_HEAD(&dent->dent_hash_link);
2014-04-07 12:56:03 +00:00
INIT_LIST_HEAD(&dent->brick_list);
2011-07-22 10:43:40 +00:00
status = mars_recv_struct(sock, dent, mars_dent_meta);
if (status <= 0) {
2019-03-12 13:36:25 +00:00
mars_free_dent(NULL, dent);
2011-07-22 10:43:40 +00:00
goto done;
}
2020-07-08 20:14:03 +00:00
if (dent->d_proto >= 2) {
sock->s_remote_proto_level = dent->d_proto;
sock->s_common_proto_level = min(dent->d_proto, MARS_PROTO_LEVEL);
}
2011-07-22 10:43:40 +00:00
list_add_tail(&dent->dent_link, anchor);
2020-09-17 16:06:09 +00:00
if (!dent->d_path || dent->d_unordered)
continue;
hash = dent_hash(dent->d_path, strlen(dent->d_path));
dent->d_hash = hash;
hash_anchor = DENT_HASH_ANCHOR(global, hash);
list_add_tail(&dent->dent_hash_link, hash_anchor);
2011-07-22 10:43:40 +00:00
}
done:
up_write(&global->dent_mutex);
2011-07-22 10:43:40 +00:00
return status;
}
EXPORT_SYMBOL_GPL(mars_recv_dent_list);
////////////////// module init stuff /////////////////////////
2011-08-25 10:16:32 +00:00
int __init init_sy_net(void)
2011-07-22 10:43:40 +00:00
{
MARS_INF("init_sy_net()\n");
mars_translate_hostname = _mars_translate_hostname;
return 0;
}
2014-04-23 11:16:26 +00:00
void exit_sy_net(void)
2011-07-22 10:43:40 +00:00
{
MARS_INF("exit_sy_net()\n");
}