2 * 2008+ 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 #ifndef __DNET_INTERFACE_H
17 #define __DNET_INTERFACE_H
19 #include <elliptics/core.h>
25 #include <netinet/in.h>
26 #include <sys/socket.h>
27 #include <arpa/inet.h>
29 #include <eblob/blob.h>
30 #include <elliptics/packet.h>
31 #include <elliptics/srw.h>
38 #define O_CLOEXEC 02000000
45 struct dnet_net_state
;
49 int dnet_need_exit(struct dnet_node
*n
);
50 void dnet_set_need_exit(struct dnet_node
*n
);
53 * Callback data structures.
58 * [dnet_cmd] header when present shows number of attached bytes.
59 * It should be equal to the al_attr structure at least in the
60 * correct message, otherwise it should be discarded.
61 * One can also check cmd->flags if it has DNET_FLAGS_MORE or
62 * DNET_FLAGS_DESTROY bit set. The former means that callback
63 * will be invoked again in the future and transaction is not
64 * yet completed. The latter means that transaction is about
71 * dnet_node is a node pointer returned by calling dnet_node_create()
72 * dnet_io_attr contains IO details (size, offset and the checksum)
73 * completion callback (if present) will be invoked when IO transaction is finished
74 * private data will be stored in the appropriate transaction and can be obtained
75 * when transaction completion callback is invoked. It will be automatically
76 * freed when transaction is completed.
79 struct dnet_io_control
{
80 /* Used as cmd->id/group_id - 'address' of the remote node */
84 * IO control structure - it is copied into resulted transaction as is.
85 * During write origin will be replaced with data transformation, and
86 * id will be replaced with the object name transformation.
88 struct dnet_io_attr io
;
91 * If present, will be invoked when transaction is completed.
92 * Can be invoked multiple times, the last one will be when
93 * cmd->flags does not have DNET_FLAGS_MORE flag.
95 * All parameters are releated to the received transaction reply.
97 int (* complete
)(struct dnet_net_state
*st
,
102 * Transaction completion private data. Will be accessible in the
103 * above completion callback.
113 * File descriptor to read data from (for the write transaction).
118 * This offset represent local data shift, when local and remote offsets differ.
119 * For example when we want to put local object into transaction but place it
120 * after some bytes in the remote object.
122 uint64_t local_offset
;
130 * Command flags (DNET_FLAGS_*)
134 /* Data transaction timestamp */
139 * Reads an object identified by the provided ID from the appropriate node.
140 * In case of error completion callback may be invoked with all parameters
141 * set to null, private pointer will be setto what was provided by the user
144 * Returns negative error value in case of error.
146 int dnet_read_object(struct dnet_session
*s
, struct dnet_io_control
*ctl
);
149 * Read @io->size bytes (0 means everything) from @io->offset bytes
150 * of data associated with key @ID. Use @io->flags and @cflags for control
151 * Returns NULL and set @errp when error happens
153 void *dnet_read_data_wait(struct dnet_session
*s
, struct dnet_id
*id
,
154 struct dnet_io_attr
*io
, uint64_t cflags
, int *errp
);
156 /* Read latest data according to stored metadata */
157 int dnet_read_latest(struct dnet_session
*s
, struct dnet_id
*id
,
158 struct dnet_io_attr
*io
, uint64_t cflags
, void **datap
);
160 struct dnet_read_latest_prepare
{
161 struct dnet_session
*s
;
170 int dnet_read_latest_prepare(struct dnet_read_latest_prepare
*pr
);
174 * Read data from range of keys [io->id, io->parent)
175 * Other parameters are treated the same as in dnet_read_data_wait()
176 * On success @errp will point to number of dnet_range_data structures.
178 struct dnet_range_data
{
183 struct dnet_io_attr
*dnet_remove_range(struct dnet_session
*s
, struct dnet_io_attr
*io
,
184 int group_id
, uint64_t cflags
, int *rep_num
, int *errp
);
186 struct dnet_range_data
*dnet_read_range(struct dnet_session
*s
, struct dnet_io_attr
*io
,
187 int group_id
, uint64_t cflags
, int *errp
);
189 int __attribute__((weak
)) dnet_send_read_data(void *state
, struct dnet_cmd
*cmd
, struct dnet_io_attr
*io
,
190 void *data
, int fd
, uint64_t offset
, int close_on_exit
);
193 * Reads given file from the storage. If there are multiple transformation functions,
194 * they will be tried one after another.
196 * If @id is set, it is used as a main object ID, otherwise @file transformation
197 * is used as object ID.
199 * @type is column type, only meaningful with eblob backend, otherwise it is unused
201 * Returns negative error value in case of error.
203 * dnet_read_file_direct() works the same way except it sets DNET_FLAGS_DIRECT flag,
204 * which means it will ask node for given object, which is the closest in routing
205 * table and will not allow to forward this request to other nodes.
207 int dnet_read_file_id(struct dnet_session
*s
, const char *file
, struct dnet_id
*id
,
208 uint64_t offset
, uint64_t size
);
209 int dnet_read_file(struct dnet_session
*s
, const char *file
, const void *remote
, int remote_size
,
210 uint64_t offset
, uint64_t size
, int type
);
213 * dnet_write_object() returns number of transactions sent. If it is equal to 0,
214 * then no transactions were sent which indicates an error.
216 * ->complete() can be called multiple times, depending on how server sends data
218 int dnet_write_object(struct dnet_session
*s
, struct dnet_io_control
*ctl
);
220 /* Returns size of the reply or negative error value */
221 int __attribute__((weak
)) dnet_write_data_wait(struct dnet_session
*s
, struct dnet_io_control
*ctl
, void **result
);
224 * Sends given file to the remote nodes and waits until all of them ack the write.
226 * Returns negative error value in case of error.
228 int dnet_write_file_id(struct dnet_session
*s
, const char *file
, struct dnet_id
*id
, uint64_t local_offset
,
229 uint64_t remote_offset
, uint64_t size
, uint64_t cflags
, unsigned int ioflags
);
231 int dnet_write_file(struct dnet_session
*s
, const char *file
, const void *remote
, int remote_len
,
232 uint64_t local_offset
, uint64_t remote_offset
, uint64_t size
,
233 uint64_t cflags
, unsigned int ioflags
, int type
);
235 enum dnet_log_level
{
243 #define DNET_MAX_ADDRLEN 256
244 #define DNET_MAX_PORTLEN 8
247 #define DNET_CFG_JOIN_NETWORK (1<<0) /* given node joins network and becomes part of the storage */
248 #define DNET_CFG_NO_ROUTE_LIST (1<<1) /* do not request route table from remote nodes */
249 #define DNET_CFG_MIX_STATES (1<<2) /* mix states according to their weights before reading data */
250 #define DNET_CFG_NO_CSUM (1<<3) /* globally disable checksum verification and update */
251 #define DNET_CFG_NO_META (1<<4) /* do not write metadata */
252 #define DNET_CFG_RANDOMIZE_STATES (1<<5) /* randomize states for read requests */
256 * Logging parameters.
257 * Mask specifies set of the events we are interested in to log.
258 * Private data is used in the log function to get access to whatever
263 void (* log
)(void *priv
, int level
, const char *msg
);
266 struct dnet_iterate_ctl
{
267 void *iterate_private
;
273 struct eblob_iterate_callbacks iterate_cb
;
274 void *callback_private
;
277 struct dnet_backend_callbacks
{
278 /* command handler processes DNET_CMD_* commands */
279 int (* command_handler
)(void *state
, void *priv
, struct dnet_cmd
*cmd
, void *data
);
281 /* this must be provided as @priv argument to all above and below callbacks*/
282 void *command_private
;
284 /* sends object with given ID to specified @state */
285 int (* send
)(void *state
, void *priv
, struct dnet_id
*id
);
287 /* fills storage statistics */
288 int (* storage_stat
)(void *priv
, struct dnet_stat
*st
);
290 /* cleanups backend at exit */
291 void (* backend_cleanup
)(void *command_private
);
294 * calculates checksum and writes (no more than *@csize bytes) it
296 * @csize must be set to actual @csum size
298 int (* checksum
)(struct dnet_node
*n
, void *priv
, struct dnet_id
*id
, void *csum
, int *csize
);
301 /* metadata read/write/remove commands */
302 ssize_t (* meta_read
)(void *priv
, struct dnet_raw_id
*id
, void **datap
);
303 int (* meta_write
)(void *priv
, struct dnet_raw_id
*id
, void *data
, size_t size
);
304 int (* meta_remove
)(void *priv
, struct dnet_raw_id
*id
, int real_remove
);
307 * parallel metadata iterator
308 * given callback will be executed for every not deleted record found,
309 * if it returns negative error value, iteration stops
310 * @callback_private will be accessible in @callback as argument @p
312 int (* meta_iterate
)(struct dnet_iterate_ctl
*ctl
);
314 /* returns number of metadata elements */
315 long long (* meta_total_elements
)(void *priv
);
319 * Node configuration interface.
324 * Socket type (SOCK_STREAM, SOCK_DGRAM and so on),
325 * a protocol (IPPROTO_TCP for example) and
326 * a family (AF_INET, AF_INET6 and so on)
327 * of the appropriate socket. These parameters are
328 * sent in the lookup replies so that remote nodes
329 * could know how to connect to this one.
331 int sock_type
, proto
, family
;
334 * Socket address/port suitable for the getaddrinfo().
336 char addr
[DNET_MAX_ADDRLEN
];
337 char port
[DNET_MAX_PORTLEN
];
340 * Wait timeout in seconds used for example to wait
341 * for remote content sync.
343 unsigned int wait_timeout
;
346 * Specifies wether given node will join the network,
347 * or it is a client node and its ID should not be checked
348 * against collision with others.
350 * Also has a bit to forbid route list download.
355 * If node joins network this will be used to find a group to join.
360 struct dnet_log
*log
;
363 * Network command handler.
364 * Returns negative error value or zero in case of success.
366 * Private data is accessible from the handler as parameter.
368 struct dnet_backend_callbacks
*cb
;
371 * Free and total space on given storage.
373 unsigned long long storage_free
;
374 unsigned long long storage_size
;
376 /* Notify hash table size */
377 unsigned int hash_size
;
380 * Wait until transaction acknowledge is received.
385 * Destroy state if stall_count transactions stalled.
390 * Number of IO threads in processing pool
395 * Number of IO threads in processing pool dedicated to non-blocking operations
396 * Those operations are started from recursive commands like from DNET_CMD_EXEC handler
398 int nonblocking_io_thread_num
;
401 * Number of threads in network processing pool
405 /* Temporary metadata for CHECK process directory path */
406 char temp_meta_env
[1024];
410 * - 'ids' file automatically generated for ID ranges
411 * - python.init script used to initialize external python workers
412 * - all scripts are hosted here and are chrooted here
414 char history_env
[1024];
420 /* IO nice parameters for background operations */
425 char cookie
[DNET_AUTH_COOKIE_SIZE
];
427 /* man 7 socket for IP_PRIORITY - priorities are set for joined (server) and others (client) connections */
431 /* table of operation locks */
434 struct srw_init_ctl srw
;
438 /* so that we do not change major version frequently */
439 int reserved_for_future_use
[12];
442 struct dnet_node
*dnet_get_node_from_state(void *state
);
444 int __attribute__((weak
)) dnet_session_set_groups(struct dnet_session
*s
, int *groups
, int group_num
);
451 * Initialize private logging system.
453 int dnet_log_init(struct dnet_node
*s
, struct dnet_log
*l
);
454 void __attribute__((weak
)) dnet_log_raw(struct dnet_node
*n
, int level
, const char *format
, ...) DNET_LOG_CHECK
;
467 (addr).s6_addr[10], \
468 (addr).s6_addr[11], \
469 (addr).s6_addr[12], \
470 (addr).s6_addr[13], \
471 (addr).s6_addr[14], \
473 #define NIP6_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"
476 * Logging helpers used for the fine-printed address representation.
478 static inline char *dnet_server_convert_addr_raw(struct sockaddr
*sa
, unsigned int len
, char *inet_addr
, int inet_size
)
480 memset(inet_addr
, 0, inet_size
);
481 if (len
== sizeof(struct sockaddr_in
)) {
482 struct sockaddr_in
*in
= (struct sockaddr_in
*)sa
;
483 snprintf(inet_addr
, inet_size
, "%s", inet_ntoa(in
->sin_addr
));
484 } else if (len
== sizeof(struct sockaddr_in6
)) {
485 struct sockaddr_in6
*in
= (struct sockaddr_in6
*)sa
;
486 snprintf(inet_addr
, inet_size
, NIP6_FMT
, NIP6(in
->sin6_addr
));
491 static inline char *dnet_server_convert_addr(struct sockaddr
*sa
, unsigned int len
)
493 static char __inet_addr
[128];
494 return dnet_server_convert_addr_raw(sa
, len
, __inet_addr
, sizeof(__inet_addr
));
497 static inline int dnet_server_convert_port(struct sockaddr
*sa
, unsigned int len
)
499 if (len
== sizeof(struct sockaddr_in
)) {
500 struct sockaddr_in
*in
= (struct sockaddr_in
*)sa
;
501 return ntohs(in
->sin_port
);
502 } else if (len
== sizeof(struct sockaddr_in6
)) {
503 struct sockaddr_in6
*in
= (struct sockaddr_in6
*)sa
;
504 return ntohs(in
->sin6_port
);
509 static inline char *dnet_server_convert_dnet_addr_raw(struct dnet_addr
*sa
, char *inet_addr
, int inet_size
)
511 memset(inet_addr
, 0, inet_size
);
512 if (sa
->addr_len
== sizeof(struct sockaddr_in
)) {
513 struct sockaddr_in
*in
= (struct sockaddr_in
*)sa
->addr
;
514 snprintf(inet_addr
, inet_size
, "%s:%d", inet_ntoa(in
->sin_addr
),
515 ntohs(in
->sin_port
));
516 } else if (sa
->addr_len
== sizeof(struct sockaddr_in6
)) {
517 struct sockaddr_in6
*in
= (struct sockaddr_in6
*)sa
->addr
;
518 snprintf(inet_addr
, inet_size
, NIP6_FMT
":%d", NIP6(in
->sin6_addr
),
519 ntohs(in
->sin6_port
));
524 static inline char *dnet_server_convert_dnet_addr(struct dnet_addr
*sa
)
526 static char ___inet_addr
[128];
527 return dnet_server_convert_dnet_addr_raw(sa
, ___inet_addr
, sizeof(___inet_addr
));
530 struct dnet_addr
*dnet_state_addr(struct dnet_net_state
*st
);
531 static inline char *dnet_state_dump_addr(struct dnet_net_state
*st
)
533 return dnet_server_convert_dnet_addr(dnet_state_addr(st
));
536 static inline char *dnet_state_dump_addr_only(struct dnet_addr
*a
)
538 return dnet_server_convert_addr((struct sockaddr
*)a
->addr
, a
->addr_len
);
542 * Node creation/destruction callbacks. Node is a building block of the storage
543 * and it is needed for every operation one may want to do with the network.
545 struct dnet_node
*dnet_node_create(struct dnet_config
*);
546 void dnet_node_destroy(struct dnet_node
*n
);
549 * Create a session from node.
550 * Session is not thread safe!
552 struct dnet_session
*dnet_session_create(struct dnet_node
*n
);
553 void dnet_session_destroy(struct dnet_session
*s
);
555 /* Server node creation/destruction.
557 struct dnet_node
*dnet_server_node_create(struct dnet_config
*);
558 void dnet_server_node_destroy(struct dnet_node
*s
);
561 * dnet_add_state() is used to add a node into the route list, the more
562 * routes are added the less network lookups will be performed to send/receive
565 int dnet_add_state(struct dnet_node
*n
, struct dnet_config
*cfg
);
568 * Returns number of states we are connected to.
569 * It does not check whether they are alive though.
572 int dnet_state_num(struct dnet_session
*s
);
574 #define DNET_DUMP_NUM 6
576 * Logging helper used to print ID (DNET_ID_SIZE bytes) as a hex string.
578 static inline char *dnet_dump_id_len_raw(const unsigned char *id
, unsigned int len
, char *dst
)
582 if (len
> DNET_ID_SIZE
)
585 for (i
=0; i
<len
; ++i
)
586 sprintf(&dst
[2*i
], "%02x", id
[i
]);
590 static inline char *dnet_dump_id_len(const struct dnet_id
*id
, unsigned int len
)
592 static char __dnet_dump_str
[2 * DNET_ID_SIZE
+ 16 + 3];
593 char tmp
[2*DNET_ID_SIZE
+ 1];
595 snprintf(__dnet_dump_str
, sizeof(__dnet_dump_str
), "%d:%s", id
->group_id
,
596 dnet_dump_id_len_raw(id
->id
, len
, tmp
));
597 return __dnet_dump_str
;
600 static inline char *dnet_dump_id(const struct dnet_id
*id
)
602 return dnet_dump_id_len(id
, DNET_DUMP_NUM
);
605 static inline char *dnet_dump_id_str(const unsigned char *id
)
607 static char __dnet_dump_id_str
[2 * DNET_ID_SIZE
+ 1];
608 return dnet_dump_id_len_raw(id
, DNET_DUMP_NUM
, __dnet_dump_id_str
);
612 * Lookup a node which hosts given ID.
614 * dnet_lookup_object() will invoke given callback when lookup reply is received.
615 * dnet_lookup() will add received address into local route table.
616 * dnet_lookup_complete() is a completion function which adds received address
617 * into local route table.
619 * Effectively dnet_lookup() is a dnet_lookup_object() with dnet_lookup_complete()
620 * completion function.
622 int dnet_lookup_object(struct dnet_session
*s
, struct dnet_id
*id
, uint64_t cflags
,
623 int (* complete
)(struct dnet_net_state
*, struct dnet_cmd
*, void *),
625 int dnet_lookup(struct dnet_session
*s
, const char *file
);
626 int dnet_lookup_complete(struct dnet_net_state
*st
, struct dnet_cmd
*cmd
, void *priv
);
627 int dnet_stat_local(struct dnet_net_state
*st
, struct dnet_id
*id
);
631 * Returns 1 when id1 > id2
635 static inline int dnet_id_cmp_str(const unsigned char *id1
, const unsigned char *id2
)
639 for (i
*=sizeof(unsigned long); i
<DNET_ID_SIZE
; ++i
) {
648 static inline int dnet_id_cmp(const struct dnet_id
*id1
, const struct dnet_id
*id2
)
650 if (id1
->group_id
< id2
->group_id
)
652 if (id1
->group_id
> id2
->group_id
)
655 return dnet_id_cmp_str(id1
->id
, id2
->id
);
659 * Send given number of bytes as reply command.
660 * It will fill transaction, command and ID from the original command and copy given data.
661 * It will set DNET_FLAGS_MORE if original command requested acknowledge or @more is set.
663 * If cmd->cmd is DNET_CMD_SYNC then plain data will be sent back, otherwise transaction
664 * reply will be generated. So effectively difference is in DNET_TRANS_REPLY bit presence.
666 int __attribute__((weak
)) dnet_send_reply(void *state
, struct dnet_cmd
*cmd
, void *odata
, unsigned int size
, int more
);
669 * Request statistics from the node corresponding to given ID.
670 * If @id is NULL statistics will be requested from all connected nodes.
671 * @cmd specified stat command to use (DNET_CMD_STAT or DNET_CMD_STAT_COUNT).
673 * Function will sleep and print into DNET_LOG_INFO log level short
674 * statistics if no @complete function is provided, otherwise it returns
675 * after queueing all transactions and appropriate callback will be
676 * invoked asynchronously.
678 * Function returns number of nodes statistics request was sent to
679 * or negative error code. In case of error callback completion can
682 int dnet_request_stat(struct dnet_session
*s
, struct dnet_id
*id
,
683 unsigned int cmd
, uint64_t cflags
,
684 int (* complete
)(struct dnet_net_state
*state
,
685 struct dnet_cmd
*cmd
,
690 * Request notifications when given ID is modified.
691 * Notifications are sent after update was stored in the IO backend.
692 * @id and @complete are not allowed to be NULL.
694 * @complete will be invoked each time object with given @id is modified.
696 int dnet_request_notification(struct dnet_session
*s
, struct dnet_id
*id
,
697 int (* complete
)(struct dnet_net_state
*state
,
698 struct dnet_cmd
*cmd
,
703 * Drop notifications for given ID.
705 int dnet_drop_notification(struct dnet_session
*s
, struct dnet_id
*id
);
708 * Low-level transaction allocation and sending function.
710 struct dnet_trans_control
720 int (* complete
)(struct dnet_net_state
*state
, struct dnet_cmd
*cmd
, void *priv
);
725 * Allocate and send transaction according to above control structure.
727 int dnet_trans_alloc_send(struct dnet_session
*s
, struct dnet_trans_control
*ctl
);
728 int dnet_trans_create_send_all(struct dnet_session
*s
, struct dnet_io_control
*ctl
);
730 int dnet_request_cmd(struct dnet_session
*s
, struct dnet_trans_control
*ctl
);
732 int dnet_fill_addr(struct dnet_addr
*addr
, const char *saddr
, const char *port
, const int family
,
733 const int sock_type
, const int proto
);
735 /* Change node status on given address or ID */
736 int dnet_update_status(struct dnet_session
*s
, struct dnet_addr
*addr
, struct dnet_id
*id
, struct dnet_node_status
*status
);
739 * Remove object by @id
740 * If callback is provided, it will be invoked on completion, otherwise
741 * function will block until server returns an acknowledge.
743 int dnet_remove_object(struct dnet_session
*s
, struct dnet_id
*id
,
744 int (* complete
)(struct dnet_net_state
*state
,
745 struct dnet_cmd
*cmd
,
748 uint64_t cflags
, uint64_t ioflags
);
750 /* Remove object with @id from the storage immediately */
751 int dnet_remove_object_now(struct dnet_session
*s
, struct dnet_id
*id
, uint64_t cflags
, uint64_t ioflags
);
754 * Remove given file (identified by name or ID) from the storage.
756 int dnet_remove_file(struct dnet_session
*s
, char *remote
, int remote_len
, struct dnet_id
*id
, uint64_t cflags
, uint64_t ioflags
);
759 * Transformation helper, which uses *ppos as an index for transformation function.
760 * @src and @size correspond to to be transformed source data.
761 * @dst and @dsize specify destination buffer.
763 int __attribute__((weak
)) dnet_transform(struct dnet_node
*n
, const void *src
, uint64_t size
, struct dnet_id
*id
);
765 int dnet_request_ids(struct dnet_session
*s
, struct dnet_id
*id
, uint64_t cflags
,
766 int (* complete
)(struct dnet_net_state
*state
,
767 struct dnet_cmd
*cmd
,
771 struct dnet_meta_container
{
775 } __attribute__ ((packed
));
777 static inline void dnet_convert_meta_container(struct dnet_meta_container
*m
)
779 m
->size
= dnet_bswap32(m
->size
);
782 struct dnet_metadata_control
{
790 uint64_t update_flags
;
797 * Reads meta of given file from the storage. If there are multiple transformation functions,
798 * they will be tried one after another.
800 * If @id is set, it is used as a main object ID, otherwise @remote transformation
801 * is used as object ID.
803 * Returns negative error value in case of error.
805 int dnet_read_meta(struct dnet_session
*s
, struct dnet_meta_container
*mc
,
806 const void *remote
, unsigned int remote_len
, struct dnet_id
*id
);
809 * Modify or search metadata in meta object. Data must be realloc()able.
811 struct dnet_meta
*dnet_meta_search(struct dnet_node
*n
, struct dnet_meta_container
*mc
, uint32_t type
);
813 void dnet_create_meta_update(struct dnet_meta
*m
, struct timespec
*ts
, uint64_t flags_set
, uint64_t flags_clear
);
814 int dnet_write_metadata(struct dnet_session
*s
, struct dnet_meta_container
*mc
, int convert
, uint64_t cflags
);
815 int dnet_create_write_metadata(struct dnet_session
*s
, struct dnet_metadata_control
*ctl
);
816 int dnet_create_write_metadata_strings(struct dnet_session
*s
, const void *remote
, unsigned int remote_len
,
817 struct dnet_id
*id
, struct timespec
*ts
, uint64_t cflags
);
818 int dnet_create_metadata(struct dnet_session
*s
, struct dnet_metadata_control
*ctl
, struct dnet_meta_container
*mc
);
819 void dnet_meta_print(struct dnet_session
*s
, struct dnet_meta_container
*mc
);
821 int dnet_read_file_info(struct dnet_node
*n
, struct dnet_id
*id
, struct dnet_file_info
*info
);
822 int dnet_meta_update_check_status_raw(struct dnet_node
*n
, struct dnet_meta_container
*mc
);
823 int dnet_meta_update_check_status(struct dnet_node
*n
, struct dnet_meta_container
*mc
);
825 int dnet_lookup_addr(struct dnet_session
*s
, const void *remote
, int len
, struct dnet_id
*id
, int group_id
, char *dst
, int dlen
);
826 void dnet_fill_addr_attr(struct dnet_node
*n
, struct dnet_addr_attr
*attr
);
828 struct dnet_id_param
{
829 unsigned int group_id
;
831 uint64_t param_reserved
;
832 } __attribute__ ((packed
));
835 DNET_ID_PARAM_LA
= 1,
836 DNET_ID_PARAM_FREE_SPACE
,
839 //TODO int dnet_generate_ids_by_param(struct dnet_session *s, struct dnet_id *id, enum id_params param, struct dnet_id_param **dst);
840 //TODO int64_t dnet_get_param(struct dnet_session *s, struct dnet_id *id, enum id_params param);
842 struct dnet_check_reply
{
849 static inline void dnet_convert_check_reply(struct dnet_check_reply
*r
)
851 r
->total
= dnet_bswap32(r
->total
);
852 r
->completed
= dnet_bswap32(r
->completed
);
853 r
->errors
= dnet_bswap32(r
->errors
);
856 /* Set by dnet_check when we only want to merge transaction
857 * and do not check copies in other groups
859 #define DNET_CHECK_MERGE (1<<0)
860 /* Check not only history presence but also try to read part of the data object */
861 #define DNET_CHECK_FULL (1<<1)
862 /* Do not actually perform any action, just update counters */
863 #define DNET_CHECK_DRY_RUN (1<<2)
864 /* Physically delete files marked as REMOVED in history */
865 #define DNET_CHECK_DELETE (1<<3)
867 struct dnet_check_request
{
871 uint64_t updatestamp_start
;
872 uint64_t updatestamp_stop
;
878 } __attribute__ ((packed
));
880 static inline void dnet_convert_check_request(struct dnet_check_request
*r
)
882 r
->flags
= dnet_bswap32(r
->flags
);
883 r
->thread_num
= dnet_bswap32(r
->thread_num
);
884 r
->timestamp
= dnet_bswap64(r
->timestamp
);
885 r
->updatestamp_start
= dnet_bswap64(r
->updatestamp_start
);
886 r
->updatestamp_stop
= dnet_bswap64(r
->updatestamp_stop
);
887 r
->obj_num
= dnet_bswap32(r
->obj_num
);
888 r
->group_num
= dnet_bswap32(r
->group_num
);
889 r
->blob_start
= dnet_bswap32(r
->blob_start
);
890 r
->blob_num
= dnet_bswap32(r
->blob_num
);
893 int dnet_request_check(struct dnet_session
*s
, struct dnet_check_request
*r
);
895 void *dnet_node_get_ns(struct dnet_node
*n
, int *nsize
);
896 void dnet_node_set_ns(struct dnet_node
*n
, void *ns
, int nsize
);
898 long __attribute__((weak
)) dnet_get_id(void);
900 static inline int is_trans_destroyed(struct dnet_net_state
*st
, struct dnet_cmd
*cmd
)
904 if (!st
|| !cmd
|| (cmd
->flags
& DNET_FLAGS_DESTROY
)) {
906 if (cmd
&& cmd
->status
)
913 int dnet_mix_states(struct dnet_session
*s
, struct dnet_id
*id
, int **groupsp
);
915 char * __attribute__((weak
)) dnet_cmd_string(int cmd
);
916 char *dnet_counter_string(int cntr
, int cmd_num
);
918 int dnet_checksum_file(struct dnet_node
*n
, void *csum
, int *csize
, const char *file
, uint64_t offset
, uint64_t size
);
919 int dnet_checksum_fd(struct dnet_node
*n
, void *csum
, int *csize
, int fd
, uint64_t offset
, uint64_t size
);
922 ssize_t
dnet_db_read_raw(struct eblob_backend
*b
, struct dnet_raw_id
*id
, void **datap
);
923 int dnet_db_write_raw(struct eblob_backend
*b
, struct dnet_raw_id
*id
, void *data
, unsigned int size
);
924 int dnet_db_remove_raw(struct eblob_backend
*b
, struct dnet_raw_id
*id
, int real_del
);
925 int dnet_db_iterate(struct eblob_backend
*b
, struct dnet_iterate_ctl
*ctl
);
927 int dnet_send_file_info(void *state
, struct dnet_cmd
*cmd
, int fd
, uint64_t offset
, int64_t size
);
929 int dnet_get_routes(struct dnet_session
*s
, struct dnet_id
**ids
, struct dnet_addr
**addrs
);
931 * Send a shell/python command to the remote node for execution.
933 int dnet_send_cmd(struct dnet_session
*s
, struct dnet_id
*id
, struct sph
*h
, void **ret
);
934 int dnet_send_cmd_nolock(struct dnet_session
*s
, struct dnet_id
*id
, struct sph
*e
, void **ret
);
936 struct dnet_range_data
*dnet_bulk_read(struct dnet_session
*s
, struct dnet_io_attr
*ios
, uint32_t io_num
, int group_id
, uint64_t cflags
, int *errp
);
937 struct dnet_range_data
dnet_bulk_write(struct dnet_session
*s
, struct dnet_io_control
*ctl
, int ctl_num
, int *errp
);
939 int dnet_flags(struct dnet_node
*n
);
940 void dnet_set_timeouts(struct dnet_node
*n
, int wait_timeout
, int check_timeout
);
942 #define DNET_CONF_ADDR_DELIM ':'
943 int dnet_parse_addr(char *addr
, struct dnet_config
*cfg
);
945 int dnet_start_defrag(struct dnet_session
*s
, uint64_t cflags
);
947 int dnet_discovery_add(struct dnet_node
*n
, struct dnet_config
*cfg
);
953 #endif /* __DNET_INTERFACE_H */