-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestrados.c
77 lines (59 loc) · 1.78 KB
/
testrados.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <[email protected]>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include "osdc/librados.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, const char **argv)
{
if (rados_initialize(argc, argv) < 0) {
printf("error initializing\n");
exit(1);
}
time_t tm;
char buf[128], buf2[128];
time(&tm);
snprintf(buf, 128, "%s", ctime(&tm));
const char *oid = "foo";
rados_pool_t pool;
int r = rados_open_pool("data", &pool);
printf("open pool result = %d, pool = %p\n", r, pool);
rados_write(pool, oid, 0, buf, strlen(buf) + 1);
rados_exec(pool, oid, "crypto", "md5", buf, strlen(buf) + 1, buf, 128);
printf("exec result=%s\n", buf);
int size = rados_read(pool, oid, 0, buf2, 128);
printf("read result=%s\n", buf2);
printf("size=%d\n", size);
// test aio
rados_completion_t a, b;
rados_aio_write(pool, "a", 0, buf, 100, &a);
rados_aio_write(pool, "../b/bb_bb_bb\\foo\\bar", 0, buf, 100, &b);
rados_aio_wait_for_safe(a);
printf("a safe\n");
rados_aio_wait_for_safe(b);
printf("b safe\n");
rados_aio_release(a);
rados_aio_release(b);
rados_read(pool, "../b/bb_bb_bb\\foo\\bar", 0, buf2, 128);
const char *entry;
rados_list_ctx_t ctx;
rados_pool_init_ctx(&ctx);
while (rados_pool_list_next(pool, &entry, &ctx) >= 0) {
printf("list entry: %s\n", entry);
}
rados_pool_close_ctx(&ctx);
rados_close_pool(pool);
rados_deinitialize();
return 0;
}