Skip to content

Commit

Permalink
Fix wlog header init issues
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacKhor committed May 22, 2024
1 parent 3022693 commit 3a90482
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 175 deletions.
4 changes: 2 additions & 2 deletions src/image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ lsvd_image::lsvd_image(std::string name, rados_ioctx_t io, lsvd_config cfg)
map_lock, bufmap, bufmap_lock, last_data_seq, clones,
obj_info, checkpoints);

wlog = open_wlog(cfg.wlog_path(name), cfg.wlog_size / 4096, *xlate, cfg);
wlog = open_wlog(cfg.wlog_path(name), *xlate, cfg);
THROW_MSG_ON(!wlog, "Failed to open write log");
// recover_from_wlog();

Expand Down Expand Up @@ -468,7 +468,7 @@ class lsvd_image::write_request : public lsvd_image::aio_request
{
assert(parent == nullptr);

img->wlog->get_room(req_bytes / 512);
img->wlog->reserve_room(req_bytes / 512);
img->xlate->backend_backpressure();

sector_t size_sectors = req_bytes / 512;
Expand Down
80 changes: 1 addition & 79 deletions src/imgtool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@
#include "translate.h"
#include "utils.h"

enum tool_operation {
OP_CREATE = 1,
OP_DELETE = 2,
OP_INFO = 3,
OP_MKCACHE = 4,
OP_CLONE = 5
};
enum tool_operation { OP_CREATE = 1, OP_DELETE = 2, OP_INFO = 3, OP_CLONE = 5 };

const char *backend = "rados";
const char *image_name;
const char *cache_dir;
const char *cache_dev;
cfg_cache_type cache_type = LSVD_CFG_READ;
enum tool_operation op;
const char *pool_name = "lsvd";
Expand All @@ -46,11 +38,7 @@ static long parseint(const char *_s)
}

static struct argp_option options[] = {
{"cache-dir", 'd', "DIR", 0, "cache directory", 0},
{"create", 'C', 0, 0, "create image", 0},
{"mkcache", 'k', "DEV", 0, "use DEV as cache", 0},
{"cache-type", 't', "R/W", 0,
"R for read cache, W for write cache (default: R)", 0},
{"size", 'z', "SIZE", 0, "size in bytes (M/G=2^20,2^30)", 0},
{"delete", 'D', 0, 0, "delete image", 0},
{"info", 'I', 0, 0, "show image information", 0},
Expand All @@ -61,18 +49,12 @@ static struct argp_option options[] = {

static char args_doc[] = "IMAGE";

extern int init_wcache(int fd, uuid_t &uuid, int n_pages);
int (*make_cache)(int fd, uuid_t &uuid, int n_pages) = init_wcache;

static error_t parse_opt(int key, char *arg, struct argp_state *state)
{
switch (key) {
case ARGP_KEY_ARG:
image_name = arg;
break;
case 'd':
cache_dir = arg;
break;
case 'C':
op = OP_CREATE;
break;
Expand All @@ -85,21 +67,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 'I':
op = OP_INFO;
break;
case 't':
if (arg[0] == 'R') {
cache_type = LSVD_CFG_READ;
log_error("read cache no longer supported");
exit(1);
} else if (arg[0] == 'W') {
cache_type = LSVD_CFG_WRITE;
make_cache = init_wcache;
} else
argp_usage(state);
break;
case 'k':
op = OP_MKCACHE;
cache_dev = arg;
break;
case 'c':
op = OP_CLONE;
break;
Expand Down Expand Up @@ -171,41 +138,6 @@ void info(rados_ioctx_t io, const char *image_name)
}
}

void mk_cache(rados_ioctx_t io, const char *image_name, const char *dev_name,
cfg_cache_type type)
{
int rv, fd = open(dev_name, O_RDWR);
if (fd < 0) {
perror("device file open");
exit(1);
}
auto sz = getsize64(fd);

lsvd_config cfg;
if ((rv = cfg.read()) < 0) {
printf("error reading config: %d\n", rv);
exit(1);
}
auto objstore = make_rados_backend(io);
uuid_t uu;
if ((rv = translate_get_uuid(objstore, image_name, uu)) < 0) {
printf("error reading superblock: %d\n", rv);
exit(1);
}
auto cache_file = cfg.cache_filename(uu, image_name, type);

auto n_pages = sz / 4096;
if (make_cache(fd, uu, n_pages) < 0) {
printf("make_cache failed\n");
exit(1);
}
if ((rv = symlink(dev_name, cache_file.c_str())) < 0) {
perror("symbolic link");
exit(1);
}
close(fd);
}

int main(int argc, char **argv)
{
std::set_terminate([]() {
Expand All @@ -218,14 +150,6 @@ int main(int argc, char **argv)

argp_parse(&argp, argc, argv, 0, 0, 0);

setenv("LSVD_BACKEND", backend, 1);
if (cache_dir != NULL) {
if (cache_type == LSVD_CFG_READ)
setenv("LSVD_RCACHE_DIR", cache_dir, 1);
else
setenv("LSVD_WCACHE_DIR", cache_dir, 1);
}

rados_t cluster;
int err = rados_create2(&cluster, "ceph", "client.admin", 0);
check_ret_neg(err, "Failed to create cluster handle");
Expand All @@ -246,8 +170,6 @@ int main(int argc, char **argv)
rbd_remove(io_ctx, image_name);
else if (op == OP_INFO)
info(io_ctx, image_name);
else if (op == OP_MKCACHE)
mk_cache(io_ctx, image_name, cache_dev, cache_type);
else if (op == OP_CLONE) {
auto src_img = image_name;
auto dst_img = argv[argc - 1];
Expand Down
Loading

0 comments on commit 3a90482

Please sign in to comment.