2019-11-03 01:34:29 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-11-12 13:52:27 +03:00
|
|
|
#ifndef _LARGEFILE64_SOURCE
|
2019-11-03 01:34:29 +03:00
|
|
|
#define _LARGEFILE64_SOURCE
|
2019-11-12 13:52:27 +03:00
|
|
|
#endif
|
2019-12-15 14:49:10 +03:00
|
|
|
|
2019-11-03 01:34:29 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <map>
|
2019-12-15 14:49:10 +03:00
|
|
|
#include <unordered_map>
|
2019-11-03 01:34:29 +03:00
|
|
|
#include <functional>
|
|
|
|
|
2019-12-16 12:39:15 +03:00
|
|
|
#include "object_id.h"
|
2019-11-05 02:43:21 +03:00
|
|
|
#include "ringloop.h"
|
|
|
|
|
2019-12-02 02:44:56 +03:00
|
|
|
// Default block size is 128 KB, current allowed range is 4K - 128M
|
2019-11-03 01:34:29 +03:00
|
|
|
#define DEFAULT_ORDER 17
|
2019-12-02 02:44:56 +03:00
|
|
|
#define MIN_BLOCK_SIZE 4*1024
|
2019-11-03 01:34:29 +03:00
|
|
|
#define MAX_BLOCK_SIZE 128*1024*1024
|
|
|
|
|
2019-12-19 20:50:20 +03:00
|
|
|
#define BS_OP_MIN 1
|
2019-12-19 13:56:26 +03:00
|
|
|
#define BS_OP_READ 1
|
|
|
|
#define BS_OP_WRITE 2
|
|
|
|
#define BS_OP_SYNC 3
|
|
|
|
#define BS_OP_STABLE 4
|
|
|
|
#define BS_OP_DELETE 5
|
2019-12-19 20:50:20 +03:00
|
|
|
#define BS_OP_LIST 6
|
2020-01-24 20:10:18 +03:00
|
|
|
#define BS_OP_ROLLBACK 7
|
|
|
|
#define BS_OP_MAX 7
|
2019-11-03 01:34:29 +03:00
|
|
|
|
2019-12-15 14:49:10 +03:00
|
|
|
#define BS_OP_PRIVATE_DATA_SIZE 256
|
2019-12-03 12:09:30 +03:00
|
|
|
|
2019-12-19 20:50:20 +03:00
|
|
|
/* BS_OP_LIST:
|
|
|
|
|
|
|
|
Input:
|
|
|
|
- len = divisor
|
|
|
|
- offset = modulo. object is listed if (object_id % len) == offset.
|
|
|
|
|
|
|
|
Output:
|
|
|
|
- retval = total obj_ver_id count
|
|
|
|
- version = stable obj_ver_id count
|
|
|
|
- buf = obj_ver_id array allocated by the blockstore. stable versions come first
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2019-12-15 14:11:03 +03:00
|
|
|
struct blockstore_op_t
|
2019-11-03 01:34:29 +03:00
|
|
|
{
|
2019-12-19 13:56:26 +03:00
|
|
|
// operation
|
|
|
|
uint64_t opcode;
|
2019-11-12 18:16:03 +03:00
|
|
|
// finish callback
|
2019-12-15 14:11:03 +03:00
|
|
|
std::function<void (blockstore_op_t*)> callback;
|
2019-11-11 14:10:23 +03:00
|
|
|
// For reads, writes & deletes: oid is the requested object
|
2019-11-03 01:34:29 +03:00
|
|
|
object_id oid;
|
2019-11-10 13:26:56 +03:00
|
|
|
// For reads: version=0 -> last stable, version=UINT64_MAX -> last unstable, version=X -> specific version
|
2019-11-11 14:10:23 +03:00
|
|
|
// For writes & deletes: a new version is assigned automatically
|
2019-11-03 01:34:29 +03:00
|
|
|
uint64_t version;
|
2019-11-11 14:10:23 +03:00
|
|
|
// For reads & writes: offset & len are the requested part of the object, buf is the buffer
|
2019-11-03 01:34:29 +03:00
|
|
|
uint32_t offset;
|
2019-11-11 14:10:23 +03:00
|
|
|
// For stabilize requests: buf contains <len> obj_ver_id's to stabilize
|
2019-11-03 01:34:29 +03:00
|
|
|
uint32_t len;
|
2019-11-26 00:02:54 +03:00
|
|
|
void *buf;
|
2019-11-05 14:10:23 +03:00
|
|
|
int retval;
|
2019-11-03 01:34:29 +03:00
|
|
|
|
2019-12-15 14:49:10 +03:00
|
|
|
uint8_t private_data[BS_OP_PRIVATE_DATA_SIZE];
|
2019-11-03 01:34:29 +03:00
|
|
|
};
|
|
|
|
|
2019-12-15 14:49:10 +03:00
|
|
|
typedef std::unordered_map<std::string, std::string> blockstore_config_t;
|
2019-11-13 17:45:37 +03:00
|
|
|
|
2019-12-15 14:49:10 +03:00
|
|
|
class blockstore_impl_t;
|
2019-11-28 00:50:52 +03:00
|
|
|
|
2019-12-15 14:49:10 +03:00
|
|
|
class blockstore_t
|
2019-11-03 01:34:29 +03:00
|
|
|
{
|
2019-12-15 14:49:10 +03:00
|
|
|
blockstore_impl_t *impl;
|
2019-11-10 01:40:48 +03:00
|
|
|
public:
|
2019-12-15 14:49:10 +03:00
|
|
|
blockstore_t(blockstore_config_t & config, ring_loop_t *ringloop);
|
|
|
|
~blockstore_t();
|
2019-11-10 01:40:48 +03:00
|
|
|
|
|
|
|
// Event loop
|
|
|
|
void loop();
|
|
|
|
|
2019-11-25 01:29:07 +03:00
|
|
|
// Returns true when blockstore is ready to process operations
|
|
|
|
// (Although you're free to enqueue them before that)
|
2019-11-18 02:36:53 +03:00
|
|
|
bool is_started();
|
|
|
|
|
2020-01-10 01:23:46 +03:00
|
|
|
// Returns true when blockstore is stalled
|
|
|
|
bool is_stalled();
|
|
|
|
|
2019-11-11 21:22:28 +03:00
|
|
|
// Returns true when it's safe to destroy the instance. If destroying the instance
|
|
|
|
// requires to purge some queues, starts that process. Should be called in the event
|
|
|
|
// loop until it returns true.
|
2019-11-25 01:29:07 +03:00
|
|
|
bool is_safe_to_stop();
|
2019-11-11 21:22:28 +03:00
|
|
|
|
2019-11-10 01:40:48 +03:00
|
|
|
// Submission
|
2019-12-15 14:11:03 +03:00
|
|
|
void enqueue_op(blockstore_op_t *op);
|
2019-11-26 00:02:54 +03:00
|
|
|
|
2020-01-10 20:05:17 +03:00
|
|
|
// Insert operation into the beginning of the queue
|
|
|
|
// Intended for the OSD syncer "thread" to be able to stabilize something when the journal is full
|
|
|
|
void enqueue_op_first(blockstore_op_t *op);
|
|
|
|
|
2019-12-10 00:13:57 +03:00
|
|
|
// Unstable writes are added here (map of object_id -> version)
|
2019-12-15 14:49:10 +03:00
|
|
|
std::map<object_id, uint64_t> & get_unstable_writes();
|
2019-12-10 00:13:57 +03:00
|
|
|
|
2019-12-15 14:49:10 +03:00
|
|
|
uint32_t get_block_size();
|
|
|
|
uint64_t get_block_count();
|
2019-11-03 01:34:29 +03:00
|
|
|
};
|