#include #include #include #include #include int main(int argc, char** argv) { rados_t cluster; char cluster_name[] = "ceph"; char user_name[] = "client.admin"; uint64_t flags = 0; int i=0; rados_ioctx_t io; char *poolname = "rbd"; int rt_num; rt_num = rados_create2(&cluster, cluster_name, user_name, flags); if(rt_num < 0){ return -1; }else{ printf("\nCreated a cluster handle success. \n"); } rt_num = rados_conf_read_file(cluster, "/etc/ceph/ceph.conf"); if(rt_num < 0){ return -1; }else{ printf("\nRead the config file. \n"); } //Connect to the cluster rt_num = rados_connect(cluster); if(rt_num < 0){ return -1; }else{ printf("\nConnected to the cluster.\n"); } //create io handle rt_num = rados_ioctx_create(cluster, poolname, &io); if(rt_num<0){ rados_shutdown(cluster); return -1; }else{ printf("\nCreated I/O context. \n"); } const char* id = "638de1bd4de892"; rbd_image_t image; rt_num = rbd_open_by_id( io, id, &image, NULL); if( rt_num ==0 ){ printf("\nrbd_open success !!\n"); }else{ printf("\nrbd_open failed !!%s\n", strerror(-rt_num)); rados_ioctx_destroy(io); rados_shutdown(cluster); return -1; } rt_num = rbd_close(image); if(rt_num == 0){ printf("\nrbd_close success !!\n"); }else{ printf("\nrbd_close failed !!%s\n", strerror(-rt_num)); } printf("\nClosing the connection\n"); rados_ioctx_destroy(io); printf("\nShut down the handle\n"); rados_shutdown(cluster); return 0; }