mirror of
https://github.com/schoebel/mars
synced 2025-02-17 20:47:16 +00:00
infra: introduce separate resource_name
do no longer misuse brick_name
This commit is contained in:
parent
32d605b986
commit
564f03e455
@ -287,6 +287,7 @@ struct mars_info {
|
||||
struct generic_object_layout mref_object_layout; \
|
||||
struct list_head global_brick_link; \
|
||||
struct list_head dent_brick_link; \
|
||||
const char *resource_name; \
|
||||
const char *brick_path; \
|
||||
struct mars_global *global; \
|
||||
struct lamport_time create_stamp; \
|
||||
|
@ -1091,7 +1091,7 @@ static int client_switch(struct client_brick *brick)
|
||||
goto done;
|
||||
mars_power_led_off((void*)brick, false);
|
||||
if (!output->bundle.sender.thread) {
|
||||
status = _setup_bundle(&output->bundle, brick->brick_name);
|
||||
status = _setup_bundle(&output->bundle, brick->resource_name);
|
||||
if (likely(status >= 0)) {
|
||||
brick->connection_state = 1;
|
||||
}
|
||||
|
@ -1075,7 +1075,9 @@ static int if_switch(struct if_brick *brick)
|
||||
disk->major = MARS_MAJOR; //TODO: make this dynamic for >256 devices
|
||||
disk->first_minor = minor;
|
||||
disk->fops = &if_blkdev_ops;
|
||||
snprintf(disk->disk_name, sizeof(disk->disk_name), "mars/%s", brick->brick_name);
|
||||
snprintf(disk->disk_name, sizeof(disk->disk_name),
|
||||
"mars/%s",
|
||||
brick->resource_name);
|
||||
disk->private_data = input;
|
||||
input->disk = disk;
|
||||
MARS_DBG("created device name %s, capacity=%lld\n",
|
||||
|
@ -38,6 +38,9 @@
|
||||
#include "mars_aio.h"
|
||||
#include "mars_sio.h"
|
||||
|
||||
#define RESOURCE_PREFIX "/mars/resource-"
|
||||
#define RESOURCE_PREFIX_LEN (sizeof(RESOURCE_PREFIX - 1))
|
||||
|
||||
///////////////////////// own type definitions ////////////////////////
|
||||
|
||||
#include "mars_server.h"
|
||||
@ -542,14 +545,30 @@ int handler_thread(void *data)
|
||||
{
|
||||
struct mars_brick *prev;
|
||||
const char *path = cmd.cmd_str1;
|
||||
char *resource_name = "(none)";
|
||||
char *to_free = NULL;
|
||||
|
||||
status = -EINVAL;
|
||||
CHECK_PTR(path, err);
|
||||
CHECK_PTR_NULL(_bio_brick_type, err);
|
||||
|
||||
/* extract the resource name */
|
||||
if (!strncmp(path, RESOURCE_PREFIX, RESOURCE_PREFIX_LEN)) {
|
||||
char *tmp;
|
||||
|
||||
resource_name =
|
||||
brick_strdup(path + RESOURCE_PREFIX_LEN);
|
||||
to_free = resource_name;
|
||||
tmp = resource_name;
|
||||
while (*tmp && *tmp != '/')
|
||||
tmp++;
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
prev = make_brick_all(
|
||||
handler_global,
|
||||
NULL,
|
||||
resource_name,
|
||||
_set_server_bio_params,
|
||||
NULL,
|
||||
path,
|
||||
@ -576,6 +595,7 @@ int handler_thread(void *data)
|
||||
status = mars_send_cmd(sock, &cmd, false);
|
||||
old_proto_level = sock->s_common_proto_level;
|
||||
up(&brick->socket_sem);
|
||||
brick_string_free(to_free);
|
||||
break;
|
||||
}
|
||||
case CMD_MREF:
|
||||
@ -950,6 +970,7 @@ static int port_thread(void *data)
|
||||
++cookie->thread_nr);
|
||||
brick = (void*)mars_make_brick(server_global, NULL,
|
||||
&server_brick_type,
|
||||
"none",
|
||||
ini_path,
|
||||
ini_path);
|
||||
brick_string_free(ini_path);
|
||||
|
@ -1876,6 +1876,7 @@ typedef int (*copy_update_fn)(struct mars_brick *copy, bool switch_on, void *pri
|
||||
|
||||
static
|
||||
int __make_copy(struct mars_dent *belongs,
|
||||
const char *resource_name,
|
||||
const char *switch_path,
|
||||
const char *copy_path,
|
||||
const char *parent,
|
||||
@ -1943,6 +1944,7 @@ int __make_copy(struct mars_dent *belongs,
|
||||
aio =
|
||||
make_brick_all(mars_global,
|
||||
NULL,
|
||||
cc.fullpath[i],
|
||||
_set_bio_params,
|
||||
&clc[i],
|
||||
NULL,
|
||||
@ -1996,6 +1998,7 @@ int __make_copy(struct mars_dent *belongs,
|
||||
copy =
|
||||
make_brick_all(mars_global,
|
||||
belongs,
|
||||
resource_name,
|
||||
_set_copy_params,
|
||||
&cc,
|
||||
cc.fullpath[1],
|
||||
@ -2443,6 +2446,7 @@ int _update_file(struct mars_dent *parent, const char *switch_path, const char *
|
||||
tmp, file, start_pos, do_start);
|
||||
|
||||
status = __make_copy(NULL,
|
||||
parent->d_rest,
|
||||
do_start ? switch_path : "",
|
||||
copy_path,
|
||||
NULL,
|
||||
@ -4371,6 +4375,7 @@ int make_log_init(struct mars_dent *dent)
|
||||
aio_brick =
|
||||
make_brick_all(mars_global,
|
||||
aio_dent,
|
||||
parent->d_rest,
|
||||
_set_aio_params,
|
||||
NULL,
|
||||
aio_path,
|
||||
@ -4429,6 +4434,7 @@ int make_log_init(struct mars_dent *dent)
|
||||
trans_brick =
|
||||
make_brick_all(mars_global,
|
||||
replay_link,
|
||||
parent->d_rest,
|
||||
_set_trans_params,
|
||||
NULL,
|
||||
aio_path,
|
||||
@ -5039,6 +5045,7 @@ void _rotate_trans(struct mars_rotate *rot)
|
||||
trans_brick->cease_logging) &&
|
||||
(next_nr = _get_free_input(trans_brick)) >= 0) {
|
||||
struct trans_logger_input *trans_input;
|
||||
struct mars_dent *parent = rot->next_relevant_log->d_parent;
|
||||
int status;
|
||||
|
||||
MARS_DBG("start switchover %d -> %d\n", old_nr, next_nr);
|
||||
@ -5046,6 +5053,7 @@ void _rotate_trans(struct mars_rotate *rot)
|
||||
rot->next_relevant_brick =
|
||||
make_brick_all(mars_global,
|
||||
rot->next_relevant_log,
|
||||
parent->d_rest,
|
||||
_set_aio_params,
|
||||
NULL,
|
||||
rot->next_relevant_log->d_path,
|
||||
@ -5187,6 +5195,7 @@ int _start_trans(struct mars_rotate *rot)
|
||||
rot->relevant_brick =
|
||||
make_brick_all(mars_global,
|
||||
rot->relevant_log,
|
||||
rot->relevant_log->d_parent->d_rest,
|
||||
_set_aio_params,
|
||||
NULL,
|
||||
rot->relevant_log->d_path,
|
||||
@ -5736,6 +5745,7 @@ int make_bio(struct mars_dent *dent)
|
||||
brick =
|
||||
make_brick_all(mars_global,
|
||||
dent,
|
||||
dent->d_parent->d_rest,
|
||||
_set_bio_params,
|
||||
NULL,
|
||||
dent->d_path,
|
||||
@ -5913,6 +5923,7 @@ int make_dev(struct mars_dent *dent)
|
||||
dev_brick =
|
||||
make_brick_all(mars_global,
|
||||
dent,
|
||||
dent->d_parent->d_rest,
|
||||
_set_if_params,
|
||||
rot,
|
||||
dent->d_argv[0],
|
||||
@ -5993,6 +6004,7 @@ static int _make_direct(struct mars_dent *dent)
|
||||
brick =
|
||||
make_brick_all(mars_global,
|
||||
dent,
|
||||
dent->d_parent->d_rest,
|
||||
_set_bio_params,
|
||||
NULL,
|
||||
src_path,
|
||||
@ -6012,6 +6024,7 @@ static int _make_direct(struct mars_dent *dent)
|
||||
brick =
|
||||
make_brick_all(mars_global,
|
||||
dent,
|
||||
dent->d_parent->d_rest,
|
||||
_set_if_params,
|
||||
NULL,
|
||||
dent->d_argv[1],
|
||||
@ -6060,6 +6073,7 @@ static int _make_copy(struct mars_dent *dent)
|
||||
switch_path = path_make("%s/todo-%s/connect", dent->d_parent->d_path, my_id());
|
||||
|
||||
status = __make_copy(dent,
|
||||
dent->d_parent->d_rest,
|
||||
switch_path,
|
||||
copy_path,
|
||||
dent->d_parent->d_path,
|
||||
@ -6429,6 +6443,7 @@ static int make_sync(struct mars_dent *dent)
|
||||
};
|
||||
|
||||
status = __make_copy(dent,
|
||||
dent->d_parent->d_rest,
|
||||
do_start ? switch_path : "",
|
||||
copy_path, dent->d_parent->d_path, argv, find_key(rot->msgs, "inf-sync"),
|
||||
start_pos, end_pos,
|
||||
|
@ -242,7 +242,11 @@ int mars_connect(struct mars_input *a, struct mars_output *b);
|
||||
int mars_disconnect(struct mars_input *a);
|
||||
|
||||
extern struct mars_brick *mars_find_brick(struct mars_global *global, const void *brick_type, const char *path);
|
||||
extern struct mars_brick *mars_make_brick(struct mars_global *global, struct mars_dent *belongs, const void *_brick_type, const char *path, const char *name);
|
||||
extern struct mars_brick *mars_make_brick(struct mars_global *global,
|
||||
struct mars_dent *belongs,
|
||||
const void *_brick_type,
|
||||
const char *resource_name,
|
||||
const char *path, const char *name);
|
||||
extern int mars_free_brick(struct mars_brick *brick);
|
||||
extern int mars_kill_brick(struct mars_brick *brick);
|
||||
extern int mars_kill_brick_all(struct mars_global *global, struct list_head *anchor, bool use_dent_link);
|
||||
@ -271,6 +275,7 @@ extern struct mars_brick *path_find_brick(struct mars_global *global, const void
|
||||
extern struct mars_brick *make_brick_all(
|
||||
struct mars_global *global,
|
||||
struct mars_dent *belongs,
|
||||
const char *resource_name,
|
||||
int (*setup_fn)(struct mars_brick *brick, void *private),
|
||||
void *private,
|
||||
const char *new_name,
|
||||
|
@ -2703,6 +2703,7 @@ int mars_free_brick(struct mars_brick *brick)
|
||||
MARS_DBG("deallocate name = '%s' path = '%s'\n", SAFE_STR(brick->brick_name), SAFE_STR(brick->brick_path));
|
||||
brick_string_free(brick->brick_name);
|
||||
brick_string_free(brick->brick_path);
|
||||
brick_string_free(brick->resource_name);
|
||||
|
||||
status = generic_brick_exit_full((void*)brick);
|
||||
|
||||
@ -2718,7 +2719,11 @@ done:
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mars_free_brick);
|
||||
|
||||
struct mars_brick *mars_make_brick(struct mars_global *global, struct mars_dent *belongs, const void *_brick_type, const char *path, const char *_name)
|
||||
struct mars_brick *mars_make_brick(struct mars_global *global,
|
||||
struct mars_dent *belongs,
|
||||
const void *_brick_type,
|
||||
const char *resource_name,
|
||||
const char *path, const char *_name)
|
||||
{
|
||||
const char *name = brick_strdup(_name);
|
||||
const char *names[] = { name, NULL };
|
||||
@ -2772,11 +2777,8 @@ struct mars_brick *mars_make_brick(struct mars_global *global, struct mars_dent
|
||||
get_lamport(NULL, &res->create_stamp);
|
||||
res->global = global;
|
||||
INIT_LIST_HEAD(&res->dent_brick_link);
|
||||
res->resource_name = brick_strdup(resource_name);
|
||||
res->brick_path = brick_strdup(path);
|
||||
if (!res->brick_path) {
|
||||
MARS_ERR("cannot grab memory for path '%s'\n", path);
|
||||
goto err_res;
|
||||
}
|
||||
|
||||
status = generic_brick_init_full(res, size, brick_type, NULL, NULL, names);
|
||||
MARS_DBG("brick '%s' init '%s' '%s' (status=%d)\n", brick_type->type_name, path, name, status);
|
||||
@ -2799,8 +2801,8 @@ struct mars_brick *mars_make_brick(struct mars_global *global, struct mars_dent
|
||||
return res;
|
||||
|
||||
err_path:
|
||||
brick_string_free(res->resource_name);
|
||||
brick_string_free(res->brick_path);
|
||||
err_res:
|
||||
brick_mem_free(res);
|
||||
err_name:
|
||||
brick_string_free(name);
|
||||
@ -3148,6 +3150,7 @@ EXPORT_SYMBOL_GPL(_sio_brick_type);
|
||||
struct mars_brick *make_brick_all(
|
||||
struct mars_global *global,
|
||||
struct mars_dent *belongs,
|
||||
const char *resource_name,
|
||||
int (*setup_fn)(struct mars_brick *brick, void *private),
|
||||
void *private,
|
||||
const char *new_name,
|
||||
@ -3263,7 +3266,11 @@ struct mars_brick *make_brick_all(
|
||||
remote++;
|
||||
MARS_DBG("substitute by remote brick '%s' on peer '%s'\n", new_name, remote);
|
||||
|
||||
brick = mars_make_brick(global, belongs, _client_brick_type, new_path, new_name);
|
||||
brick = mars_make_brick(global,
|
||||
belongs,
|
||||
_client_brick_type,
|
||||
resource_name,
|
||||
new_path, new_name);
|
||||
if (brick) {
|
||||
struct client_brick *_brick = (void*)brick;
|
||||
_brick->max_flying = 10000;
|
||||
@ -3287,7 +3294,11 @@ struct mars_brick *make_brick_all(
|
||||
|
||||
// create it...
|
||||
if (!brick)
|
||||
brick = mars_make_brick(global, belongs, new_brick_type, new_path, new_name);
|
||||
brick = mars_make_brick(global,
|
||||
belongs,
|
||||
new_brick_type,
|
||||
resource_name,
|
||||
new_path, new_name);
|
||||
if (unlikely(!brick)) {
|
||||
MARS_ERR("creation failed '%s' '%s'\n", new_path, new_name);
|
||||
goto err;
|
||||
|
Loading…
Reference in New Issue
Block a user