2 * 2011+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <sys/types.h>
18 #include <sys/socket.h>
20 #include <sys/syscall.h>
32 #include <netinet/in.h>
34 #include "elliptics/packet.h"
35 #include "elliptics/interface.h"
39 * THIS IS REALLY BAD IDEA !!11
43 #include "../library/elliptics.h"
50 #define __unused __attribute__ ((unused))
53 static struct dnet_log meta_logger
;
55 static void meta_usage(char *p
)
57 fprintf(stderr
, "Usage: %s <options>\n"
58 " -I id - use this ID to get metadata\n"
59 " -n name - use this name to get metadata\n"
60 " -g group:group... - groups to get matadata from\n"
61 " -w timeout - wait timeout in seconds\n"
62 " -r addr:port:family - connect to this remote node\n"
63 " -m level - log level\n"
64 " -l log - log file\n"
65 " -f file - read metadata from file\n"
70 int main(int argc
, char *argv
[])
73 char *logfile
= "/dev/stderr";
76 int *groups
, group_num
= 0;
77 unsigned char trans_id
[DNET_ID_SIZE
], *id
= NULL
;
78 struct dnet_config cfg
, rem
;
81 struct dnet_meta_container mc
;
83 memset(&mc
, 0, sizeof(mc
));
84 memset(&cfg
, 0, sizeof(cfg
));
86 cfg
.sock_type
= SOCK_STREAM
;
87 cfg
.proto
= IPPROTO_TCP
;
88 cfg
.wait_timeout
= 10;
89 meta_logger
.log_level
= DNET_LOG_ERROR
;
91 memcpy(&rem
, &cfg
, sizeof(struct dnet_config
));
93 while ((ch
= getopt(argc
, argv
, "f:N:g:w:I:n:r:m:l:h")) != -1) {
96 fd
= open(optarg
, O_RDONLY
| O_CLOEXEC
);
98 fprintf(stderr
, "Could not open file '%s': %s\n", optarg
, strerror(errno
));
103 cfg
.nsize
= strlen(optarg
);
106 err
= dnet_parse_addr(optarg
, &rem
);
111 cfg
.wait_timeout
= atoi(optarg
);
117 meta_logger
.log_level
= strtoul(optarg
, NULL
, 0);
120 err
= dnet_parse_numeric_id(optarg
, trans_id
);
126 group_num
= dnet_parse_groups(optarg
, &groups
);
141 fprintf(stderr
, "You must specify name or id\n");
145 if (id
&& group_num
<= 0) {
146 fprintf(stderr
, "You must specify groups\n");
150 log
= fopen(logfile
, "a");
153 fprintf(stderr
, "Failed to open log file %s: %s.\n", logfile
, strerror(-err
));
157 meta_logger
.log_private
= log
;
158 meta_logger
.log
= dnet_common_log
;
159 cfg
.log
= &meta_logger
;
161 n
= dnet_node_create(&cfg
);
168 err
= dnet_add_state(n
, &rem
);
170 goto err_out_destroy
;
172 dnet_node_set_groups(n
, groups
, group_num
);
177 for (i
=0; i
<group_num
; ++i
) {
178 dnet_setup_id(&raw
, groups
[i
], id
);
179 err
= dnet_read_meta(n
, &mc
, NULL
, 0, &raw
);
181 dnet_meta_print(n
, &mc
);
183 dnet_log_raw(n
, DNET_LOG_ERROR
, "%s: could not read metadata\n", dnet_dump_id(&raw
));
186 err
= dnet_read_meta(n
, &mc
, name
, strlen(name
), NULL
);
188 dnet_meta_print(n
, &mc
);
192 struct dnet_map_fd m
;
196 memset(&m
, 0, sizeof(m
));
197 m
.size
= st
.st_size
- 96;
201 err
= dnet_data_map(&m
);
203 dnet_log_raw(n
, DNET_LOG_ERROR
, "Could not map metadata: %s\n", strerror(-err
));
204 goto err_out_destroy
;
210 dnet_meta_print(n
, &mc
);
216 dnet_node_destroy(n
);