Ceph block snapshot

Good morning,

I'm VERY new to Rust, coming from Python, so I apologize in advance for some naive question or very obvious issue.

As my first real-world Rust application, I want to create a very simple script that lists all the images in a Ceph block pool and takes a snapshot of each one.

Basically just the equivalent of some "rbd ls", "rbd snap create" command.

I know that I could do everything by just wrapping the Ceph cli commands with std::process::Command but I'd rather use a more specific interface.

I'm trying to use librados-sys (librados_sys - Rust) and librbd-sys (librbd_sys - Rust) but I couldn't find any real documentation with examples on how to use them.

I'm completely stuck. So far, I haven't even been able to figure out how to create a connection to the Ceph cluster by passing the /etc/ceph/ceph.conf file to rados_connect() (I'm not even sure this is what I'm supposed to do, tbh).

Is there some better library that I could use? Or some example on how to use these?

Thanks a lot.

-sys crates are direct transcriptions of the C APIs of the libraries that they wrap. You should be able to look at the documentation of those (e.g. Introduction to librados — Ceph Documentation) and adapt that from C to Rust.

Usually, you'd want to instead work with a higher level library that uses the -sys crate to adapt the C API into a safe, more ergonomic Rust API. Unfortunately, it looks like that might not exist for librados, librbd, etc currently.

Hey Steven, thank you for the explanation! Now I have a clearer picture.

I found the ceph crate (ceph - Rust) which seems to wrap the librados-sys as you said. I've been able to do some basic operation like listing the pools, but the libraries look quite limited. Maybe I'm missing something but it looks like it can only create pool-wide snapshots, not single volumes. The documentation only provides a few usage examples and none about rbd images management.

Also, although I can authenticate and list the pools, when I try to create a snapshot, the only error I get is "Err(ApiError(EINVAL))" which is not particularly helpful. Activating RUST_BACKTRACE doesn't do any better.

fn main() {
    println!("RBD snapshot manager");

    let pool_name = "ceph-blockpool";
    
    println!("Connecting to ceph");
    let cluster = ceph_helpers::connect_to_ceph("admin", "/etc/ceph/ceph.conf").unwrap();

    println!("Listing pools");
    let pools_list = cluster.rados_pools().unwrap();

    for pool in pools_list {
        println!("pool: {}", pool);
    }

    println!("Creating a pool-wide snapshot for pool {}", pool_name);

    let ioctx = cluster.get_rados_ioctx(pool_name).unwrap();
    let snapshot = ioctx.rados_snap_create("foo");

    println!("Snapshot: {:?}", snapshot);
}

It returns:

bash-5.1$ rook-ceph-backup
RBD snapshot manager
Connecting to ceph
Listing pools
pool: .mgr
pool: ceph-blockpool
pool: ceph-objectstore.rgw.control
pool: ceph-filesystem-metadata
pool: ceph-objectstore.rgw.meta
pool: ceph-filesystem-data0
pool: ceph-objectstore.rgw.log
pool: ceph-objectstore.rgw.buckets.index
pool: ceph-objectstore.rgw.buckets.non-ec
pool: ceph-objectstore.rgw.otp
pool: .rgw.root
pool: ceph-objectstore.rgw.buckets.data
Creating a pool-wide snapshot for pool ceph-blockpool
Snapshot: Err(ApiError(EINVAL))

Is there a way to have a more detailed description of the issue?

Thanks