d::cerr << "couldn't create rbd image! err " << ret << std::endl; ret = EXIT_FAILURE; io_ctx.close(); //关闭I/O上下文 rados.shutdown(); //断开集群连接 return EXIT_FAILURE; } else { std::cout << "We just created an rbd image" << std::endl; }
打开rbd映像
librbd::RBD rbd; const char *image_name = "rumboo"; librbd::Image image; ret = rbd.open(io_ctx, image, image_name); if (ret < 0) { std::cerr << "couldn't open rbd image! err " << ret << std::endl; ret = EXIT_FAILURE; io_ctx.close(); //关闭I/O上下文 rados.shutdown(); //断开集群连接 return EXIT_FAILURE; } else { std::cout << "We just opened an rbd image" << std::endl; }
查看映像大小
uint64_t size = 0; ret = image.size(&size); if (ret < 0) { std::cerr << "couldn't get image size! err " << ret << std::endl; ret = EXIT_FAILURE; return EXIT_FAILURE; } else { std::cout << "The size of the image is " << size << std::endl; }
调整映像大小
size = (uint64_t) 500 * 1024 * 1024; //调整映像大小500MB ret = image.resize(size); if (ret < 0) { std::cerr << "couldn't change the size of the image! err " << ret << std::endl; ret = EXIT_FAILURE; return EXIT_FAILURE; } else { std::cout << "We just change the size of the image" << std::endl; }
查看映像ID
std::string id; ret = image.get_id(&id); if (ret < 0) { std::cerr << "couldn't get image ID! err " << ret << std::endl; ret = EXIT_FAILURE; return EXIT_FAILURE; } else { std::cout << "The ID of the image is " << id << std::endl; }
查看映像features
features = 0; ret = image.features(&features); if (ret < 0) { std::cerr << "couldn't get image features! err " << ret << std::endl; ret = EXIT_FAILURE; return EXIT_FAILURE; } else { std::cout << "The features of the image are " << features << std::endl; }
查看映像状态信息
librbd::image_info_t info; ret = image.stat(info, sizeof(info)); if (ret < 0) { std::cerr << "couldn't get image stat_info! err " << ret << std::endl; ret = EXIT_FAILURE; return EXIT_FAILURE; } else { std::cout << "info.size is " << info.size << std::endl; std::cout << "info.obj_size is " << info.obj_size << std::endl; std::cout << "info.num_objs is " << info.num_objs << std::endl; std::cout << "info.order is " << info.order << std::endl; std::cout << "info.block_name_prefix is " << info.block_name_prefix << std::endl; }
查看存储池ID
std::cout << "data pool id is " << image.get_data_pool_id() << std::endl;
1
查看block_name_prefix
std::cout << "block name prefix is " << image.get_block_name_prefix() << std::endl;
查看flags
uint64_t flags = 0; ret = image.get_flags(&flags); if (ret < 0) { std::cerr << "couldn't get image flags! err " << ret << std::endl; ret = EXIT_FAILURE; return EXIT_FAILURE; } else { std::cout << "image flags is " << flags << std::endl; }
查看条带化参数
std::cout << "image stripe unit is " << image.get_stripe_unit() << std::endl; std::cout << &q