librbd 簡單學習例子

2021-10-25 04:11:16 字數 1841 閱讀 8951

去年寫了個librbd的讀寫demo,今天找了好久才找到,寫到部落格裡記錄下

熟悉librbd的介面,從乙個demo 開始是個不錯的選擇

/* 注釋就不詳細寫了,**比較簡單 */

#include #include #include #include rados_t init_rados() else

return rados;

}rados_ioctx_t init_ioctx(rados_t rados)

// 3. connect to ceph cluster

ret = rados_connect(rados);

if (ret < 0) else

// 4. init io context for rbd pool

const char *pool_name = "rbd";

ret = rados_ioctx_create(rados, pool_name, &io_ctx);

if (ret < 0) else

return io_ctx;

}rbd_image_t init_image(rados_ioctx_t io_ctx) else

return image;

}int get_rbd_size(rbd_image_t image) else

return size;

}void rbd_finish_aiocb(rbd_completion_t c, void *arg)

int aio_write(rbd_image_t image, const char *buff)

int len = strlen(buff);

ret = rbd_aio_write(image, off, len, buff, c);

if (ret < 0)

printf("write %s to image end\n", buff);

return ret;

}int aio_read(rbd_image_t image, char *buff)

memset(buff, 0, 128);

ret = rbd_aio_read(image, off, len, buff, c);

if (ret < 0)

printf("read from image end\n");

return ret;

}int main() ;

int len;

rados_t rados = init_rados();

if (!rados)

rados_ioctx_t io_ctx = init_ioctx(rados);

if (!io_ctx)

rbd_image_t image = init_image(io_ctx);

if (!image)

int size = get_rbd_size(image);

printf("image size: %d\n", size);

sprintf(buff, "%s", "abcd123efg");

aio_write(image, buff);

aio_read(image, buff);

// 7. close image, io context and rados object

ret = rbd_close(image);

if (ret < 0) else

rados_ioctx_destroy(io_ctx);

rados_shutdown(rados);

return 0;

}

cxf 簡單例子學習

最少需要的jar cxf 2.3.3.jar geronimo annotation 1.0 spec 1.1.1.jar geronimo jaxws 2.2 spec 1.0.jar geronimo stax api 1.0 spec 1.0.1.jar geronimo ws metadat...

簡單委託例子

例子1 using system using system.collections.generic using system.text 例子2 using system using system.collections.generic using system.text namespace 介面 c...

Pro C 簡單例子

include exec sql begin declare section char userid 11 hr oracle char std name 10 int std number int dept number exec sql end declare section char temp...