2020-09-17 23:02:40 +03:00
|
|
|
// Copyright (c) Vitaliy Filippov, 2019+
|
2021-02-06 01:26:07 +03:00
|
|
|
// License: VNPL-1.1 (see README.md for details)
|
2020-09-17 23:02:40 +03:00
|
|
|
|
2019-12-28 01:25:55 +03:00
|
|
|
#include "osd.h"
|
|
|
|
|
|
|
|
#include "json11/json11.hpp"
|
|
|
|
|
2020-02-24 01:01:34 +03:00
|
|
|
void osd_t::secondary_op_callback(osd_op_t *op)
|
2019-12-28 01:25:55 +03:00
|
|
|
{
|
2020-08-31 23:57:50 +03:00
|
|
|
if (op->req.hdr.opcode == OSD_OP_SEC_READ ||
|
2020-09-01 00:02:39 +03:00
|
|
|
op->req.hdr.opcode == OSD_OP_SEC_WRITE ||
|
|
|
|
op->req.hdr.opcode == OSD_OP_SEC_WRITE_STABLE)
|
2019-12-28 01:25:55 +03:00
|
|
|
{
|
2020-03-24 00:18:35 +03:00
|
|
|
op->reply.sec_rw.version = op->bs_op->version;
|
|
|
|
}
|
2020-08-31 23:57:50 +03:00
|
|
|
else if (op->req.hdr.opcode == OSD_OP_SEC_DELETE)
|
2020-03-24 00:18:35 +03:00
|
|
|
{
|
|
|
|
op->reply.sec_del.version = op->bs_op->version;
|
2019-12-28 01:25:55 +03:00
|
|
|
}
|
2021-01-11 02:01:42 +03:00
|
|
|
if (op->req.hdr.opcode == OSD_OP_SEC_READ)
|
2019-12-28 01:25:55 +03:00
|
|
|
{
|
2021-02-01 01:37:54 +03:00
|
|
|
if (op->bs_op->retval >= 0)
|
2021-02-07 16:26:08 +03:00
|
|
|
op->reply.sec_rw.attr_len = clean_entry_bitmap_size;
|
2021-02-01 01:37:54 +03:00
|
|
|
else
|
|
|
|
op->reply.sec_rw.attr_len = 0;
|
2021-01-11 02:01:42 +03:00
|
|
|
if (op->bs_op->retval > 0)
|
|
|
|
op->iov.push_back(op->buf, op->bs_op->retval);
|
2020-03-24 00:18:35 +03:00
|
|
|
}
|
2020-08-31 23:57:50 +03:00
|
|
|
else if (op->req.hdr.opcode == OSD_OP_SEC_LIST)
|
2020-03-24 00:18:35 +03:00
|
|
|
{
|
|
|
|
// allocated by blockstore
|
|
|
|
op->buf = op->bs_op->buf;
|
|
|
|
if (op->bs_op->retval > 0)
|
|
|
|
{
|
2020-06-18 02:07:20 +03:00
|
|
|
op->iov.push_back(op->buf, op->bs_op->retval * sizeof(obj_ver_id));
|
2020-03-24 00:18:35 +03:00
|
|
|
}
|
|
|
|
op->reply.sec_list.stable_count = op->bs_op->version;
|
2019-12-28 01:25:55 +03:00
|
|
|
}
|
2020-05-25 15:09:55 +03:00
|
|
|
int retval = op->bs_op->retval;
|
|
|
|
delete op->bs_op;
|
|
|
|
op->bs_op = NULL;
|
|
|
|
finish_op(op, retval);
|
2019-12-28 01:25:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void osd_t::exec_secondary(osd_op_t *cur_op)
|
|
|
|
{
|
2021-02-13 23:38:51 +03:00
|
|
|
if (cur_op->req.hdr.opcode == OSD_OP_SEC_READ_BMP)
|
|
|
|
{
|
|
|
|
int n = cur_op->req.sec_read_bmp.len / sizeof(obj_ver_id);
|
|
|
|
if (n > 0)
|
|
|
|
{
|
|
|
|
obj_ver_id *ov = (obj_ver_id*)cur_op->buf;
|
|
|
|
void *reply_buf = malloc_or_die(n * (8 + clean_entry_bitmap_size));
|
|
|
|
void *cur_buf = reply_buf;
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
{
|
2022-01-15 23:55:10 +03:00
|
|
|
bs->read_bitmap(ov[i].oid, ov[i].version, (uint8_t*)cur_buf + sizeof(uint64_t), (uint64_t*)cur_buf);
|
|
|
|
cur_buf = (uint8_t*)cur_buf + (8 + clean_entry_bitmap_size);
|
2021-02-13 23:38:51 +03:00
|
|
|
}
|
|
|
|
free(cur_op->buf);
|
|
|
|
cur_op->buf = reply_buf;
|
|
|
|
}
|
|
|
|
finish_op(cur_op, n * (8 + clean_entry_bitmap_size));
|
|
|
|
return;
|
|
|
|
}
|
2020-02-23 23:19:11 +03:00
|
|
|
cur_op->bs_op = new blockstore_op_t();
|
|
|
|
cur_op->bs_op->callback = [this, cur_op](blockstore_op_t* bs_op) { secondary_op_callback(cur_op); };
|
2020-08-31 23:57:50 +03:00
|
|
|
cur_op->bs_op->opcode = (cur_op->req.hdr.opcode == OSD_OP_SEC_READ ? BS_OP_READ
|
|
|
|
: (cur_op->req.hdr.opcode == OSD_OP_SEC_WRITE ? BS_OP_WRITE
|
2020-09-01 00:02:39 +03:00
|
|
|
: (cur_op->req.hdr.opcode == OSD_OP_SEC_WRITE_STABLE ? BS_OP_WRITE_STABLE
|
2020-08-31 23:57:50 +03:00
|
|
|
: (cur_op->req.hdr.opcode == OSD_OP_SEC_SYNC ? BS_OP_SYNC
|
|
|
|
: (cur_op->req.hdr.opcode == OSD_OP_SEC_STABILIZE ? BS_OP_STABLE
|
|
|
|
: (cur_op->req.hdr.opcode == OSD_OP_SEC_ROLLBACK ? BS_OP_ROLLBACK
|
|
|
|
: (cur_op->req.hdr.opcode == OSD_OP_SEC_DELETE ? BS_OP_DELETE
|
|
|
|
: (cur_op->req.hdr.opcode == OSD_OP_SEC_LIST ? BS_OP_LIST
|
2020-09-01 00:02:39 +03:00
|
|
|
: -1))))))));
|
2020-08-31 23:57:50 +03:00
|
|
|
if (cur_op->req.hdr.opcode == OSD_OP_SEC_READ ||
|
2020-09-01 00:02:39 +03:00
|
|
|
cur_op->req.hdr.opcode == OSD_OP_SEC_WRITE ||
|
|
|
|
cur_op->req.hdr.opcode == OSD_OP_SEC_WRITE_STABLE)
|
2019-12-28 01:25:55 +03:00
|
|
|
{
|
2021-01-11 02:01:42 +03:00
|
|
|
if (cur_op->req.hdr.opcode == OSD_OP_SEC_READ)
|
|
|
|
{
|
|
|
|
// Allocate memory for the read operation
|
2021-02-07 16:26:08 +03:00
|
|
|
if (clean_entry_bitmap_size > sizeof(unsigned))
|
|
|
|
cur_op->bitmap = cur_op->rmw_buf = malloc_or_die(clean_entry_bitmap_size);
|
2021-01-12 01:02:56 +03:00
|
|
|
else
|
|
|
|
cur_op->bitmap = &cur_op->bmp_data;
|
2021-01-11 02:01:42 +03:00
|
|
|
if (cur_op->req.sec_rw.len > 0)
|
|
|
|
cur_op->buf = memalign_or_die(MEM_ALIGNMENT, cur_op->req.sec_rw.len);
|
|
|
|
}
|
2020-02-23 23:19:11 +03:00
|
|
|
cur_op->bs_op->oid = cur_op->req.sec_rw.oid;
|
|
|
|
cur_op->bs_op->version = cur_op->req.sec_rw.version;
|
|
|
|
cur_op->bs_op->offset = cur_op->req.sec_rw.offset;
|
|
|
|
cur_op->bs_op->len = cur_op->req.sec_rw.len;
|
|
|
|
cur_op->bs_op->buf = cur_op->buf;
|
2021-01-11 02:01:42 +03:00
|
|
|
cur_op->bs_op->bitmap = cur_op->bitmap;
|
2020-02-28 01:46:39 +03:00
|
|
|
#ifdef OSD_STUB
|
|
|
|
cur_op->bs_op->retval = cur_op->bs_op->len;
|
|
|
|
#endif
|
2019-12-28 01:25:55 +03:00
|
|
|
}
|
2020-08-31 23:57:50 +03:00
|
|
|
else if (cur_op->req.hdr.opcode == OSD_OP_SEC_DELETE)
|
2019-12-28 01:25:55 +03:00
|
|
|
{
|
2020-02-23 23:19:11 +03:00
|
|
|
cur_op->bs_op->oid = cur_op->req.sec_del.oid;
|
|
|
|
cur_op->bs_op->version = cur_op->req.sec_del.version;
|
2020-02-28 01:46:39 +03:00
|
|
|
#ifdef OSD_STUB
|
|
|
|
cur_op->bs_op->retval = 0;
|
|
|
|
#endif
|
2019-12-28 01:25:55 +03:00
|
|
|
}
|
2020-08-31 23:57:50 +03:00
|
|
|
else if (cur_op->req.hdr.opcode == OSD_OP_SEC_STABILIZE ||
|
|
|
|
cur_op->req.hdr.opcode == OSD_OP_SEC_ROLLBACK)
|
2019-12-28 01:25:55 +03:00
|
|
|
{
|
2020-02-23 23:19:11 +03:00
|
|
|
cur_op->bs_op->len = cur_op->req.sec_stab.len/sizeof(obj_ver_id);
|
|
|
|
cur_op->bs_op->buf = cur_op->buf;
|
2020-02-28 01:46:39 +03:00
|
|
|
#ifdef OSD_STUB
|
|
|
|
cur_op->bs_op->retval = 0;
|
|
|
|
#endif
|
2019-12-28 01:25:55 +03:00
|
|
|
}
|
2020-08-31 23:57:50 +03:00
|
|
|
else if (cur_op->req.hdr.opcode == OSD_OP_SEC_LIST)
|
2019-12-28 01:25:55 +03:00
|
|
|
{
|
2020-02-23 19:03:06 +03:00
|
|
|
if (cur_op->req.sec_list.pg_count < cur_op->req.sec_list.list_pg)
|
2020-01-30 22:06:46 +03:00
|
|
|
{
|
|
|
|
// requested pg number is greater than total pg count
|
2020-09-05 17:24:27 +03:00
|
|
|
printf("Invalid LIST request: pg count %u < pg number %u\n", cur_op->req.sec_list.pg_count, cur_op->req.sec_list.list_pg);
|
2020-02-23 23:19:11 +03:00
|
|
|
cur_op->bs_op->retval = -EINVAL;
|
2020-01-30 22:06:46 +03:00
|
|
|
secondary_op_callback(cur_op);
|
|
|
|
return;
|
|
|
|
}
|
2023-02-15 00:55:40 +03:00
|
|
|
cur_op->bs_op->pg_alignment = cur_op->req.sec_list.pg_stripe_size;
|
|
|
|
cur_op->bs_op->pg_count = cur_op->req.sec_list.pg_count;
|
|
|
|
cur_op->bs_op->pg_number = cur_op->req.sec_list.list_pg - 1;
|
|
|
|
cur_op->bs_op->min_oid.inode = cur_op->req.sec_list.min_inode;
|
|
|
|
cur_op->bs_op->min_oid.stripe = cur_op->req.sec_list.min_stripe;
|
|
|
|
cur_op->bs_op->max_oid.inode = cur_op->req.sec_list.max_inode;
|
|
|
|
if (cur_op->req.sec_list.max_inode && cur_op->req.sec_list.max_stripe != UINT64_MAX)
|
|
|
|
{
|
|
|
|
cur_op->bs_op->max_oid.stripe = cur_op->req.sec_list.max_stripe
|
|
|
|
? cur_op->req.sec_list.max_stripe : UINT64_MAX;
|
|
|
|
}
|
|
|
|
cur_op->bs_op->list_stable_limit = cur_op->req.sec_list.stable_limit;
|
2020-02-28 01:46:39 +03:00
|
|
|
#ifdef OSD_STUB
|
|
|
|
cur_op->bs_op->retval = 0;
|
|
|
|
cur_op->bs_op->buf = NULL;
|
|
|
|
#endif
|
2019-12-28 01:25:55 +03:00
|
|
|
}
|
2020-01-08 12:05:59 +03:00
|
|
|
#ifdef OSD_STUB
|
|
|
|
secondary_op_callback(cur_op);
|
|
|
|
#else
|
2020-02-23 23:19:11 +03:00
|
|
|
bs->enqueue_op(cur_op->bs_op);
|
2020-01-08 12:05:59 +03:00
|
|
|
#endif
|
2019-12-28 01:25:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void osd_t::exec_show_config(osd_op_t *cur_op)
|
|
|
|
{
|
2021-04-16 00:18:15 +03:00
|
|
|
std::string json_err;
|
|
|
|
json11::Json req_json = cur_op->req.show_conf.json_len > 0
|
|
|
|
? json11::Json::parse(std::string((char *)cur_op->buf), json_err)
|
|
|
|
: json11::Json();
|
2021-04-17 23:10:50 +03:00
|
|
|
// Expose sensitive configuration values so peers can check them
|
|
|
|
json11::Json::object wire_config = json11::Json::object {
|
|
|
|
{ "osd_num", osd_num },
|
|
|
|
{ "protocol_version", OSD_PROTOCOL_VERSION },
|
|
|
|
{ "block_size", (uint64_t)bs_block_size },
|
|
|
|
{ "bitmap_granularity", (uint64_t)bs_bitmap_granularity },
|
|
|
|
{ "primary_enabled", run_primary },
|
|
|
|
{ "blockstore_enabled", bs ? true : false },
|
|
|
|
{ "readonly", readonly },
|
|
|
|
{ "immediate_commit", (immediate_commit == IMMEDIATE_ALL ? "all" :
|
|
|
|
(immediate_commit == IMMEDIATE_SMALL ? "small" : "none")) },
|
2022-01-23 00:00:00 +03:00
|
|
|
{ "lease_timeout", etcd_report_interval+(st_cli.max_etcd_attempts*(2*st_cli.etcd_quick_timeout)+999)/1000 },
|
2021-04-17 23:10:50 +03:00
|
|
|
};
|
2021-04-16 00:18:15 +03:00
|
|
|
#ifdef WITH_RDMA
|
|
|
|
if (msgr.is_rdma_enabled())
|
|
|
|
{
|
|
|
|
// Indicate that RDMA is enabled
|
|
|
|
wire_config["rdma_enabled"] = true;
|
|
|
|
if (req_json["connect_rdma"].is_string())
|
|
|
|
{
|
|
|
|
// Peer is trying to connect using RDMA, try to satisfy him
|
2021-04-29 01:39:32 +03:00
|
|
|
bool ok = msgr.connect_rdma(cur_op->peer_fd, req_json["connect_rdma"].string_value(), req_json["rdma_max_msg"].uint64_value());
|
2021-04-16 00:18:15 +03:00
|
|
|
if (ok)
|
|
|
|
{
|
2021-04-29 01:39:32 +03:00
|
|
|
auto rc = msgr.clients.at(cur_op->peer_fd)->rdma_conn;
|
|
|
|
wire_config["rdma_address"] = rc->addr.to_string();
|
|
|
|
wire_config["rdma_max_msg"] = rc->max_msg;
|
2021-04-16 00:18:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (cur_op->buf)
|
|
|
|
free(cur_op->buf);
|
2021-04-17 23:10:50 +03:00
|
|
|
std::string cfg_str = json11::Json(wire_config).dump();
|
2020-09-05 01:09:10 +03:00
|
|
|
cur_op->buf = malloc_or_die(cfg_str.size()+1);
|
2020-02-24 01:01:34 +03:00
|
|
|
memcpy(cur_op->buf, cfg_str.c_str(), cfg_str.size()+1);
|
2020-06-18 02:07:20 +03:00
|
|
|
cur_op->iov.push_back(cur_op->buf, cfg_str.size()+1);
|
2020-03-24 00:18:35 +03:00
|
|
|
finish_op(cur_op, cfg_str.size()+1);
|
2019-12-28 01:25:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void osd_t::exec_sync_stab_all(osd_op_t *cur_op)
|
|
|
|
{
|
|
|
|
// Sync and stabilize all objects
|
|
|
|
// This command is only valid for tests
|
2020-02-23 23:19:11 +03:00
|
|
|
cur_op->bs_op = new blockstore_op_t();
|
2019-12-28 01:25:55 +03:00
|
|
|
if (!allow_test_ops)
|
|
|
|
{
|
2020-02-23 23:19:11 +03:00
|
|
|
cur_op->bs_op->retval = -EINVAL;
|
2019-12-28 01:25:55 +03:00
|
|
|
secondary_op_callback(cur_op);
|
|
|
|
return;
|
|
|
|
}
|
2020-02-23 23:19:11 +03:00
|
|
|
cur_op->bs_op->opcode = BS_OP_SYNC_STAB_ALL;
|
|
|
|
cur_op->bs_op->callback = [this, cur_op](blockstore_op_t *bs_op)
|
2019-12-28 01:25:55 +03:00
|
|
|
{
|
2020-02-23 20:34:37 +03:00
|
|
|
secondary_op_callback(cur_op);
|
2019-12-28 01:25:55 +03:00
|
|
|
};
|
2020-01-08 12:05:59 +03:00
|
|
|
#ifdef OSD_STUB
|
2020-02-23 23:19:11 +03:00
|
|
|
cur_op->bs_op->retval = 0;
|
2020-01-08 12:05:59 +03:00
|
|
|
secondary_op_callback(cur_op);
|
|
|
|
#else
|
2020-02-23 23:19:11 +03:00
|
|
|
bs->enqueue_op(cur_op->bs_op);
|
2020-01-08 12:05:59 +03:00
|
|
|
#endif
|
2019-12-28 01:25:55 +03:00
|
|
|
}
|