Project

General

Profile

radostimeout.c

Wido den Hollander, 02/03/2014 02:41 AM

Download (1.31 KB)

 
1
#include <stdio.h>
2
#include <string.h>
3
#include <rados/librados.h>
4

    
5
int set_rados_option(rados_t cluster, const char *option, const char *value) {
6
    printf("Set the %s option to: %s\n", option, value);
7
    return rados_conf_set(cluster, option, value);
8
}
9

    
10
int main(int argc, char *argv[]) {
11
    rados_t cluster;
12
    rados_ioctx_t io;
13

    
14
    int r;
15

    
16
    const char *id             = "admin";
17
    const char *key            = "AQB7Sg1R2DlXIxAAkbOnif9m3v/HD4QW19kNHA==";
18
    const char *mon            = "localhost";
19
    const char *pool_name      = "data";
20
    const char *client_timeout = "5";
21

    
22
    rados_create(&cluster, id);
23
    printf("%s\n", "Created the RADOS cluster");
24

    
25
    set_rados_option(cluster, "key", key);
26
    set_rados_option(cluster, "mon_host", mon);
27
    set_rados_option(cluster, "client_mount_timeout", client_timeout);  
28

    
29
    r = rados_connect(cluster);
30
    if (r < 0) {
31
        printf("%s: %d\n", "Failed to connect to the Ceph cluster", r);
32
    } else {
33
        printf("%s\n", "Connected to the RADOS cluster");
34
    }
35

    
36
    r = rados_ioctx_create(cluster, pool_name, io);
37
    if (r < 0) {
38
        printf("%s: %d\n", "Failed to connect to the Ceph cluster", r);
39
    } else {
40
        printf("%s\n", "Connected to the RADOS cluster");
41
    }
42

    
43
    rados_shutdown(cluster);
44
    printf("%s\n", "Shut down the RADOS cluster");
45
}