Project

General

Profile

Bug #36345 » test_ceph.c

Anonymous, 10/08/2018 02:56 PM

 

#include <stdio.h>
#include <stdlib.h>
#include <rados/librados.h>

rados_t CephCluster;
rados_ioctx_t io;
rados_completion_t comp;

int main(int ac, char **av) {

int err, res;
const char id[4] = "xyz\0";

if ( ( err = rados_create2(&CephCluster, "ceph", "client.tnr", 0) ) < 0 ) {
printf("[DEBUG] couldn't create the ceph cluster handle: %s\n", strerror(-err));
exit(1);
}
if ( ( err = rados_conf_read_file(CephCluster, "/home/tnr/etc/ceph.conf") ) < 0 ) {
printf("[DEBUG] cannot read ceph config file: %s\n", strerror(-err));
exit(1);
}

if ( ( err = rados_connect(CephCluster) ) < 0 ) {
printf("[DEBUG] cannot connect to cluster: %s\n", strerror(-err));
exit(1);
}

if ( (err = rados_ioctx_create(CephCluster, "diablo", &io)) < 0 ) {
printf("[DEBUG] error while talking to the cluster: %s\n", strerror(-err));
exit(1);
}

uint64_t mtime, psize;
err = rados_aio_create_completion(NULL, NULL, NULL, &comp);
if (err < 0) {
printf("[DEBUG] could not create aio completion: %s\n", strerror(-err));
exit(1);
}
err = rados_aio_stat( io, id, comp, &psize, &mtime );

if (err < 0) {
printf("[DEBUG] could not stat: %s\n", strerror(-err));
exit(1);
}
rados_aio_wait_for_complete(comp);
res = rados_aio_get_return_value( comp );

rados_aio_release( comp );
if ( res < 0 ) {
printf("[DEBUG] could not stat: %s\n", strerror(-err));
exit(1);
}
sleep(1);
printf("[DEBUG] mtime: %d, psize: %d\n", mtime, psize);
sleep(1);

err = rados_aio_create_completion(NULL, NULL, NULL, &comp);
if (err < 0) {
printf("[DEBUG] could not create aio completion: %s\n", strerror(-err));
exit(1);
}

char *buf = malloc( psize );

err = rados_aio_read( io, id, comp, buf, psize, 0 );

if (err < 0) {
printf("[DEBUG] could not read: %s ", strerror(-err));
exit(1);
}

rados_aio_wait_for_complete(comp);

res = rados_aio_get_return_value( comp );
rados_aio_release( comp );

if ( res < 0 ) {
printf("[DEBUG] could not read: %s\n", strerror(-err));
exit(1);
}
sleep(1);
printf("[DEBUG] bytes read: %d, psize: %d\n", res, psize);
printf("[DEBUG] --\n%.*s\n[DEBUG] --\n", 60, buf+0);
sleep(1);
free(buf);
buf = malloc( psize );
res = rados_read( io, id, buf, psize, 0 );
if (err < 0) {
printf("[DEBUG] could not read: %s ", strerror(-err));
exit(1);
}
sleep(1);
printf("[DEBUG] bytes read: %d, psize: %d\n", res, psize);
printf("[DEBUG] --\n%.*s\n[DEBUG] --\n", 60, buf+0);
sleep(1);
free(buf);
rados_ioctx_destroy(io);
rados_shutdown(CephCluster);

}
(1-1/2)