Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add imgtool fix for new backend #27

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:

cd build-dbg
sudo meson test
sudo ./imgtool --create --size 1g --pool pone test-img

- name: Logs
if: always()
Expand Down
39 changes: 28 additions & 11 deletions src/imgtool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ enum tool_operation {
OP_CLONE = 5
};

const char *backend = "file";
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";
size_t size = 0;

static long parseint(const char *_s)
Expand All @@ -46,7 +47,6 @@ static long parseint(const char *_s)

static struct argp_option options[] = {
{"cache-dir", 'd', "DIR", 0, "cache directory", 0},
{"rados", 'O', 0, 0, "use RADOS", 0},
{"create", 'C', 0, 0, "create image", 0},
{"mkcache", 'k', "DEV", 0, "use DEV as cache", 0},
{"cache-type", 't', "R/W", 0,
Expand All @@ -55,6 +55,7 @@ static struct argp_option options[] = {
{"delete", 'D', 0, 0, "delete image", 0},
{"info", 'I', 0, 0, "show image information", 0},
{"clone", 'c', "IMAGE", 0, "clone image", 0},
{"pool", 'p', "POOL", 0, "pool name", 0},
{0, 0, 0, 0, 0, 0},
};

Expand All @@ -72,9 +73,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 'd':
cache_dir = arg;
break;
case 'O':
backend = "rados";
break;
case 'C':
op = OP_CREATE;
break;
Expand Down Expand Up @@ -105,6 +103,8 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 'c':
op = OP_CLONE;
break;
case 'p':
pool_name = arg;
case ARGP_KEY_END:
if (op == 0 || (op == OP_CREATE && size == 0))
argp_usage(state);
Expand Down Expand Up @@ -217,19 +217,36 @@ int main(int argc, char **argv)
else
setenv("LSVD_WCACHE_DIR", cache_dir, 1);
}
rados_ioctx_t io = 0;

rados_t cluster;
int err = rados_create2(&cluster, "ceph", "client.admin", 0);
check_ret_neg(err, "Failed to create cluster handle");

err = rados_conf_read_file(cluster, "/etc/ceph/ceph.conf");
check_ret_neg(err, "Failed to read config file");

err = rados_connect(cluster);
check_ret_neg(err, "Failed to connect to cluster");

rados_ioctx_t io_ctx;
err = rados_ioctx_create(cluster, pool_name, &io_ctx);
check_ret_neg(err, "Failed to connect to pool {}", pool_name);

if (op == OP_CREATE && size > 0)
rbd_create(io, image_name, size, NULL);
rbd_create(io_ctx, image_name, size, NULL);
else if (op == OP_DELETE)
rbd_remove(io, image_name);
rbd_remove(io_ctx, image_name);
else if (op == OP_INFO)
info(io, image_name);
info(io_ctx, image_name);
else if (op == OP_MKCACHE)
mk_cache(io, image_name, cache_dev, cache_type);
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];
fmt::print("cloning from {} to {}\n", src_img, dst_img);
rbd_clone(io, src_img, dst_img);
rbd_clone(io_ctx, src_img, dst_img);
}

rados_ioctx_destroy(io_ctx);
rados_shutdown(cluster);
}
Loading