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
;
48 int dnet_need_exit(struct dnet_node
*n
);
49 void dnet_set_need_exit(struct dnet_node
*n
);
52 * Callback data structures.
57 * [dnet_cmd] header when present shows number of attached bytes.
58 * It should be equal to the al_attr structure at least in the
59 * correct message, otherwise it should be discarded.
60 * One can also check cmd->flags if it has DNET_FLAGS_MORE or
61 * DNET_FLAGS_DESTROY bit set. The former means that callback
62 * will be invoked again in the future and transaction is not
63 * yet completed. The latter means that transaction is about
70 * dnet_node is a node pointer returned by calling dnet_node_create()
71 * dnet_io_attr contains IO details (size, offset and the checksum)
72 * completion callback (if present) will be invoked when IO transaction is finished
73 * private data will be stored in the appropriate transaction and can be obtained
74 * when transaction completion callback is invoked. It will be automatically
75 * freed when transaction is completed.
78 struct dnet_io_control
{
79 /* Used as cmd->id/group_id - 'address' of the remote node */
83 * IO control structure - it is copied into resulted transaction as is.
84 * During write origin will be replaced with data transformation, and
85 * id will be replaced with the object name transformation.
87 struct dnet_io_attr io
;
90 * If present, will be invoked when transaction is completed.
91 * Can be invoked multiple times, the last one will be when
92 * cmd->flags does not have DNET_FLAGS_MORE flag.
94 * All parameters are releated to the received transaction reply.
96 int (* complete
)(struct dnet_net_state
*st
,
101 * Transaction completion private data. Will be accessible in the
102 * above completion callback.
112 * File descriptor to read data from (for the write transaction).
117 * This offset represent local data shift, when local and remote offsets differ.
118 * For example when we want to put local object into transaction but place it
119 * after some bytes in the remote object.
121 uint64_t local_offset
;
129 * Command flags (DNET_FLAGS_*)
133 /* Data transaction timestamp */
138 * Reads an object identified by the provided ID from the appropriate node.
139 * In case of error completion callback may be invoked with all parameters
140 * set to null, private pointer will be setto what was provided by the user
143 * Returns negative error value in case of error.
145 int dnet_read_object(struct dnet_node
*n
, struct dnet_io_control
*ctl
);
148 * Read @io->size bytes (0 means everything) from @io->offset bytes
149 * of data associated with key @ID. Use @io->flags and @cflags for control
150 * Returns NULL and set @errp when error happens
152 void *dnet_read_data_wait(struct dnet_node
*n
, struct dnet_id
*id
,
153 struct dnet_io_attr
*io
, uint64_t cflags
, int *errp
);
155 /* Read latest data according to stored metadata */
156 int dnet_read_latest(struct dnet_node
*n
, struct dnet_id
*id
,
157 struct dnet_io_attr
*io
, uint64_t cflags
, void **datap
);
159 struct dnet_read_latest_prepare
{
169 int dnet_read_latest_prepare(struct dnet_read_latest_prepare
*pr
);
173 * Read data from range of keys [io->id, io->parent)
174 * Other parameters are treated the same as in dnet_read_data_wait()
175 * On success @errp will point to number of dnet_range_data structures.
177 struct dnet_range_data
{
182 struct dnet_io_attr
*dnet_remove_range(struct dnet_node
*n
, struct dnet_io_attr
*io
,
183 int group_id
, uint64_t cflags
, int *rep_num
, int *errp
);
185 struct dnet_range_data
*dnet_read_range(struct dnet_node
*n
, struct dnet_io_attr
*io
,
186 int group_id
, uint64_t cflags
, int *errp
);
188 int __attribute__((weak
)) dnet_send_read_data(void *state
, struct dnet_cmd
*cmd
, struct dnet_io_attr
*io
,
189 void *data
, int fd
, uint64_t offset
, int close_on_exit
);
192 * Reads given file from the storage. If there are multiple transformation functions,
193 * they will be tried one after another.
195 * If @id is set, it is used as a main object ID, otherwise @file transformation
196 * is used as object ID.
198 * @type is column type, only meaningful with eblob backend, otherwise it is unused
200 * Returns negative error value in case of error.
202 * dnet_read_file_direct() works the same way except it sets DNET_FLAGS_DIRECT flag,
203 * which means it will ask node for given object, which is the closest in routing
204 * table and will not allow to forward this request to other nodes.
206 int dnet_read_file_id(struct dnet_node
*n
, const char *file
, struct dnet_id
*id
,
207 uint64_t offset
, uint64_t size
);
208 int dnet_read_file(struct dnet_node
*n
, const char *file
, const void *remote
, int remote_size
,
209 uint64_t offset
, uint64_t size
, int type
);
212 * dnet_write_object() returns number of transactions sent. If it is equal to 0,
213 * then no transactions were sent which indicates an error.
215 * ->complete() can be called multiple times, depending on how server sends data
217 int dnet_write_object(struct dnet_node
*n
, struct dnet_io_control
*ctl
);
219 /* Returns size of the reply or negative error value */
220 int __attribute__((weak
)) dnet_write_data_wait(struct dnet_node
*n
, struct dnet_io_control
*ctl
, void **result
);
223 * Sends given file to the remote nodes and waits until all of them ack the write.
225 * Returns negative error value in case of error.
227 int dnet_write_file_id(struct dnet_node
*n
, const char *file
, struct dnet_id
*id
, uint64_t local_offset
,
228 uint64_t remote_offset
, uint64_t size
, uint64_t cflags
, unsigned int ioflags
);
230 int dnet_write_file(struct dnet_node
*n
, const char *file
, const void *remote
, int remote_len
,
231 uint64_t local_offset
, uint64_t remote_offset
, uint64_t size
,
232 uint64_t cflags
, unsigned int ioflags
, int type
);
234 enum dnet_log_level
{
242 #define DNET_MAX_ADDRLEN 256
243 #define DNET_MAX_PORTLEN 8
246 #define DNET_CFG_JOIN_NETWORK (1<<0) /* given node joins network and becomes part of the storage */
247 #define DNET_CFG_NO_ROUTE_LIST (1<<1) /* do not request route table from remote nodes */
248 #define DNET_CFG_MIX_STATES (1<<2) /* mix states according to their weights before reading data */
249 #define DNET_CFG_NO_CSUM (1<<3) /* globally disable checksum verification and update */
250 #define DNET_CFG_NO_META (1<<4) /* do not write metadata */
251 #define DNET_CFG_RANDOMIZE_STATES (1<<5) /* randomize states for read requests */
255 * Logging parameters.
256 * Mask specifies set of the events we are interested in to log.
257 * Private data is used in the log function to get access to whatever
262 void (* log
)(void *priv
, int level
, const char *msg
);
265 struct dnet_iterate_ctl
{
266 void *iterate_private
;
272 struct eblob_iterate_callbacks iterate_cb
;
273 void *callback_private
;
276 struct dnet_backend_callbacks
{
277 /* command handler processes DNET_CMD_* commands */
278 int (* command_handler
)(void *state
, void *priv
, struct dnet_cmd
*cmd
, void *data
);
280 /* this must be provided as @priv argument to all above and below callbacks*/
281 void *command_private
;
283 /* sends object with given ID to specified @state */
284 int (* send
)(void *state
, void *priv
, struct dnet_id
*id
);
286 /* fills storage statistics */
287 int (* storage_stat
)(void *priv
, struct dnet_stat
*st
);
289 /* cleanups backend at exit */
290 void (* backend_cleanup
)(void *command_private
);
292 /* metadata read/write/remove commands */
293 ssize_t (* meta_read
)(void *priv
, struct dnet_raw_id
*id
, void **datap
);
294 int (* meta_write
)(void *priv
, struct dnet_raw_id
*id
, void *data
, size_t size
);
295 int (* meta_remove
)(void *priv
, struct dnet_raw_id
*id
, int real_remove
);
298 * parallel metadata iterator
299 * given callback will be executed for every not deleted record found,
300 * if it returns negative error value, iteration stops
301 * @callback_private will be accessible in @callback as argument @p
303 int (* meta_iterate
)(struct dnet_iterate_ctl
*ctl
);
305 /* returns number of metadata elements */
306 long long (* meta_total_elements
)(void *priv
);
310 * Node configuration interface.
315 * Socket type (SOCK_STREAM, SOCK_DGRAM and so on),
316 * a protocol (IPPROTO_TCP for example) and
317 * a family (AF_INET, AF_INET6 and so on)
318 * of the appropriate socket. These parameters are
319 * sent in the lookup replies so that remote nodes
320 * could know how to connect to this one.
322 int sock_type
, proto
, family
;
325 * Socket address/port suitable for the getaddrinfo().
327 char addr
[DNET_MAX_ADDRLEN
];
328 char port
[DNET_MAX_PORTLEN
];
331 * Wait timeout in seconds used for example to wait
332 * for remote content sync.
334 unsigned int wait_timeout
;
337 * Specifies wether given node will join the network,
338 * or it is a client node and its ID should not be checked
339 * against collision with others.
341 * Also has a bit to forbid route list download.
346 * If node joins network this will be used to find a group to join.
351 struct dnet_log
*log
;
354 * Network command handler.
355 * Returns negative error value or zero in case of success.
357 * Private data is accessible from the handler as parameter.
359 struct dnet_backend_callbacks
*cb
;
362 * Free and total space on given storage.
364 unsigned long long storage_free
;
365 unsigned long long storage_size
;
367 /* Notify hash table size */
368 unsigned int hash_size
;
371 * Wait until transaction acknowledge is received.
376 * Destroy state if stall_count transactions stalled.
381 * Number of IO threads in processing pool
386 * Number of IO threads in processing pool dedicated to non-blocking operations
387 * Those operations are started from recursive commands like from DNET_CMD_EXEC handler
389 int nonblocking_io_thread_num
;
392 * Number of threads in network processing pool
396 /* Temporary metadata for CHECK process directory path */
397 char temp_meta_env
[1024];
401 * - 'ids' file automatically generated for ID ranges
402 * - python.init script used to initialize external python workers
403 * - all scripts are hosted here and are chrooted here
405 char history_env
[1024];
411 /* IO nice parameters for background operations */
416 char cookie
[DNET_AUTH_COOKIE_SIZE
];
418 /* man 7 socket for IP_PRIORITY - priorities are set for joined (server) and others (client) connections */
422 /* table of operation locks */
425 struct srw_init_ctl srw
;
429 /* so that we do not change major version frequently */
430 int reserved_for_future_use
[12];
433 struct dnet_node
*dnet_get_node_from_state(void *state
);
435 int __attribute__((weak
)) dnet_node_set_groups(struct dnet_node
*n
, int *groups
, int group_num
);
442 * Initialize private logging system.
444 int dnet_log_init(struct dnet_node
*n
, struct dnet_log
*l
);
445 void __attribute__((weak
)) dnet_log_raw(struct dnet_node
*n
, int level
, const char *format
, ...) DNET_LOG_CHECK
;
458 (addr).s6_addr[10], \
459 (addr).s6_addr[11], \
460 (addr).s6_addr[12], \
461 (addr).s6_addr[13], \
462 (addr).s6_addr[14], \
464 #define NIP6_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"
467 * Logging helpers used for the fine-printed address representation.
469 static inline char *dnet_server_convert_addr_raw(struct sockaddr
*sa
, unsigned int len
, char *inet_addr
, int inet_size
)
471 memset(inet_addr
, 0, inet_size
);
472 if (len
== sizeof(struct sockaddr_in
)) {
473 struct sockaddr_in
*in
= (struct sockaddr_in
*)sa
;
474 snprintf(inet_addr
, inet_size
, "%s", inet_ntoa(in
->sin_addr
));
475 } else if (len
== sizeof(struct sockaddr_in6
)) {
476 struct sockaddr_in6
*in
= (struct sockaddr_in6
*)sa
;
477 snprintf(inet_addr
, inet_size
, NIP6_FMT
, NIP6(in
->sin6_addr
));
482 static inline char *dnet_server_convert_addr(struct sockaddr
*sa
, unsigned int len
)
484 static char __inet_addr
[128];
485 return dnet_server_convert_addr_raw(sa
, len
, __inet_addr
, sizeof(__inet_addr
));
488 static inline int dnet_server_convert_port(struct sockaddr
*sa
, unsigned int len
)
490 if (len
== sizeof(struct sockaddr_in
)) {
491 struct sockaddr_in
*in
= (struct sockaddr_in
*)sa
;
492 return ntohs(in
->sin_port
);
493 } else if (len
== sizeof(struct sockaddr_in6
)) {
494 struct sockaddr_in6
*in
= (struct sockaddr_in6
*)sa
;
495 return ntohs(in
->sin6_port
);
500 static inline char *dnet_server_convert_dnet_addr_raw(struct dnet_addr
*sa
, char *inet_addr
, int inet_size
)
502 memset(inet_addr
, 0, inet_size
);
503 if (sa
->addr_len
== sizeof(struct sockaddr_in
)) {
504 struct sockaddr_in
*in
= (struct sockaddr_in
*)sa
->addr
;
505 snprintf(inet_addr
, inet_size
, "%s:%d", inet_ntoa(in
->sin_addr
),
506 ntohs(in
->sin_port
));
507 } else if (sa
->addr_len
== sizeof(struct sockaddr_in6
)) {
508 struct sockaddr_in6
*in
= (struct sockaddr_in6
*)sa
->addr
;
509 snprintf(inet_addr
, inet_size
, NIP6_FMT
":%d", NIP6(in
->sin6_addr
),
510 ntohs(in
->sin6_port
));
515 static inline char *dnet_server_convert_dnet_addr(struct dnet_addr
*sa
)
517 static char ___inet_addr
[128];
518 return dnet_server_convert_dnet_addr_raw(sa
, ___inet_addr
, sizeof(___inet_addr
));
521 struct dnet_addr
*dnet_state_addr(struct dnet_net_state
*st
);
522 static inline char *dnet_state_dump_addr(struct dnet_net_state
*st
)
524 return dnet_server_convert_dnet_addr(dnet_state_addr(st
));
527 static inline char *dnet_state_dump_addr_only(struct dnet_addr
*a
)
529 return dnet_server_convert_addr((struct sockaddr
*)a
->addr
, a
->addr_len
);
533 * Node creation/destruction callbacks. Node is a building block of the storage
534 * and it is needed for every operation one may want to do with the network.
536 struct dnet_node
*dnet_node_create(struct dnet_config
*);
537 void dnet_node_destroy(struct dnet_node
*n
);
539 /* Server node creation/destruction.
541 struct dnet_node
*dnet_server_node_create(struct dnet_config
*);
542 void dnet_server_node_destroy(struct dnet_node
*n
);
545 * dnet_add_state() is used to add a node into the route list, the more
546 * routes are added the less network lookups will be performed to send/receive
549 int dnet_add_state(struct dnet_node
*n
, struct dnet_config
*cfg
);
552 * Returns number of states we are connected to.
553 * It does not check whether they are alive though.
556 int dnet_state_num(struct dnet_node
*n
);
558 #define DNET_DUMP_NUM 6
560 * Logging helper used to print ID (DNET_ID_SIZE bytes) as a hex string.
562 static inline char *dnet_dump_id_len_raw(const unsigned char *id
, unsigned int len
, char *dst
)
566 if (len
> DNET_ID_SIZE
)
569 for (i
=0; i
<len
; ++i
)
570 sprintf(&dst
[2*i
], "%02x", id
[i
]);
574 static inline char *dnet_dump_id_len(const struct dnet_id
*id
, unsigned int len
)
576 static char __dnet_dump_str
[2 * DNET_ID_SIZE
+ 16 + 3];
577 char tmp
[2*DNET_ID_SIZE
+ 1];
579 snprintf(__dnet_dump_str
, sizeof(__dnet_dump_str
), "%d:%s", id
->group_id
,
580 dnet_dump_id_len_raw(id
->id
, len
, tmp
));
581 return __dnet_dump_str
;
584 static inline char *dnet_dump_id(const struct dnet_id
*id
)
586 return dnet_dump_id_len(id
, DNET_DUMP_NUM
);
589 static inline char *dnet_dump_id_str(const unsigned char *id
)
591 static char __dnet_dump_id_str
[2 * DNET_ID_SIZE
+ 1];
592 return dnet_dump_id_len_raw(id
, DNET_DUMP_NUM
, __dnet_dump_id_str
);
596 * Lookup a node which hosts given ID.
598 * dnet_lookup_object() will invoke given callback when lookup reply is received.
599 * dnet_lookup() will add received address into local route table.
600 * dnet_lookup_complete() is a completion function which adds received address
601 * into local route table.
603 * Effectively dnet_lookup() is a dnet_lookup_object() with dnet_lookup_complete()
604 * completion function.
606 int dnet_lookup_object(struct dnet_node
*n
, struct dnet_id
*id
, uint64_t cflags
,
607 int (* complete
)(struct dnet_net_state
*, struct dnet_cmd
*, void *),
609 int dnet_lookup(struct dnet_node
*n
, const char *file
);
610 int dnet_lookup_complete(struct dnet_net_state
*st
, struct dnet_cmd
*cmd
, void *priv
);
611 int dnet_stat_local(struct dnet_net_state
*st
, struct dnet_id
*id
);
615 * Returns 1 when id1 > id2
619 static inline int dnet_id_cmp_str(const unsigned char *id1
, const unsigned char *id2
)
623 for (i
*=sizeof(unsigned long); i
<DNET_ID_SIZE
; ++i
) {
632 static inline int dnet_id_cmp(const struct dnet_id
*id1
, const struct dnet_id
*id2
)
634 if (id1
->group_id
< id2
->group_id
)
636 if (id1
->group_id
> id2
->group_id
)
639 return dnet_id_cmp_str(id1
->id
, id2
->id
);
643 * Send given number of bytes as reply command.
644 * It will fill transaction, command and ID from the original command and copy given data.
645 * It will set DNET_FLAGS_MORE if original command requested acknowledge or @more is set.
647 * If cmd->cmd is DNET_CMD_SYNC then plain data will be sent back, otherwise transaction
648 * reply will be generated. So effectively difference is in DNET_TRANS_REPLY bit presence.
650 int __attribute__((weak
)) dnet_send_reply(void *state
, struct dnet_cmd
*cmd
, void *odata
, unsigned int size
, int more
);
653 * Request statistics from the node corresponding to given ID.
654 * If @id is NULL statistics will be requested from all connected nodes.
655 * @cmd specified stat command to use (DNET_CMD_STAT or DNET_CMD_STAT_COUNT).
657 * Function will sleep and print into DNET_LOG_INFO log level short
658 * statistics if no @complete function is provided, otherwise it returns
659 * after queueing all transactions and appropriate callback will be
660 * invoked asynchronously.
662 * Function returns number of nodes statistics request was sent to
663 * or negative error code. In case of error callback completion can
666 int dnet_request_stat(struct dnet_node
*n
, struct dnet_id
*id
,
667 unsigned int cmd
, uint64_t cflags
,
668 int (* complete
)(struct dnet_net_state
*state
,
669 struct dnet_cmd
*cmd
,
674 * Request notifications when given ID is modified.
675 * Notifications are sent after update was stored in the IO backend.
676 * @id and @complete are not allowed to be NULL.
678 * @complete will be invoked each time object with given @id is modified.
680 int dnet_request_notification(struct dnet_node
*n
, struct dnet_id
*id
,
681 int (* complete
)(struct dnet_net_state
*state
,
682 struct dnet_cmd
*cmd
,
687 * Drop notifications for given ID.
689 int dnet_drop_notification(struct dnet_node
*n
, struct dnet_id
*id
);
692 * Low-level transaction allocation and sending function.
694 struct dnet_trans_control
704 int (* complete
)(struct dnet_net_state
*state
, struct dnet_cmd
*cmd
, void *priv
);
709 * Allocate and send transaction according to above control structure.
711 int dnet_trans_alloc_send(struct dnet_node
*n
, struct dnet_trans_control
*ctl
);
712 int dnet_trans_create_send_all(struct dnet_node
*n
, struct dnet_io_control
*ctl
);
714 int dnet_request_cmd(struct dnet_node
*n
, struct dnet_trans_control
*ctl
);
716 int dnet_fill_addr(struct dnet_addr
*addr
, const char *saddr
, const char *port
, const int family
,
717 const int sock_type
, const int proto
);
719 /* Change node status on given address or ID */
720 int dnet_update_status(struct dnet_node
*n
, struct dnet_addr
*addr
, struct dnet_id
*id
, struct dnet_node_status
*status
);
723 * Remove object by @id
724 * If callback is provided, it will be invoked on completion, otherwise
725 * function will block until server returns an acknowledge.
727 int dnet_remove_object(struct dnet_node
*n
, struct dnet_id
*id
,
728 int (* complete
)(struct dnet_net_state
*state
,
729 struct dnet_cmd
*cmd
,
732 uint64_t cflags
, uint64_t ioflags
);
734 /* Remove object with @id from the storage immediately */
735 int dnet_remove_object_now(struct dnet_node
*n
, struct dnet_id
*id
, uint64_t cflags
, uint64_t ioflags
);
738 * Remove given file (identified by name or ID) from the storage.
740 int dnet_remove_file(struct dnet_node
*n
, char *remote
, int remote_len
, struct dnet_id
*id
, uint64_t cflags
, uint64_t ioflags
);
743 * Transformation helper, which uses *ppos as an index for transformation function.
744 * @src and @size correspond to to be transformed source data.
745 * @dst and @dsize specify destination buffer.
747 int __attribute__((weak
)) dnet_transform(struct dnet_node
*n
, const void *src
, uint64_t size
, struct dnet_id
*id
);
749 int dnet_request_ids(struct dnet_node
*n
, struct dnet_id
*id
, uint64_t cflags
,
750 int (* complete
)(struct dnet_net_state
*state
,
751 struct dnet_cmd
*cmd
,
755 struct dnet_meta_container
{
759 } __attribute__ ((packed
));
761 static inline void dnet_convert_meta_container(struct dnet_meta_container
*m
)
763 m
->size
= dnet_bswap32(m
->size
);
766 struct dnet_metadata_control
{
774 uint64_t update_flags
;
781 * Reads meta of given file from the storage. If there are multiple transformation functions,
782 * they will be tried one after another.
784 * If @id is set, it is used as a main object ID, otherwise @remote transformation
785 * is used as object ID.
787 * Returns negative error value in case of error.
789 int dnet_read_meta(struct dnet_node
*n
, struct dnet_meta_container
*mc
,
790 const void *remote
, unsigned int remote_len
, struct dnet_id
*id
);
793 * Modify or search metadata in meta object. Data must be realloc()able.
795 struct dnet_meta
*dnet_meta_search(struct dnet_node
*n
, struct dnet_meta_container
*mc
, uint32_t type
);
797 void dnet_create_meta_update(struct dnet_meta
*m
, struct timespec
*ts
, uint64_t flags_set
, uint64_t flags_clear
);
798 int dnet_write_metadata(struct dnet_node
*n
, struct dnet_meta_container
*mc
, int convert
, uint64_t cflags
);
799 int dnet_create_write_metadata(struct dnet_node
*n
, struct dnet_metadata_control
*ctl
);
800 int dnet_create_write_metadata_strings(struct dnet_node
*n
, const void *remote
, unsigned int remote_len
,
801 struct dnet_id
*id
, struct timespec
*ts
, uint64_t cflags
);
802 int dnet_create_metadata(struct dnet_node
*n
, struct dnet_metadata_control
*ctl
, struct dnet_meta_container
*mc
);
803 void dnet_meta_print(struct dnet_node
*n
, struct dnet_meta_container
*mc
);
805 int dnet_read_file_info(struct dnet_node
*n
, struct dnet_id
*id
, struct dnet_file_info
*info
);
806 int dnet_meta_update_check_status_raw(struct dnet_node
*n
, struct dnet_meta_container
*mc
);
807 int dnet_meta_update_check_status(struct dnet_node
*n
, struct dnet_meta_container
*mc
);
809 int dnet_lookup_addr(struct dnet_node
*n
, const void *remote
, int len
, struct dnet_id
*id
, int group_id
, char *dst
, int dlen
);
810 void dnet_fill_addr_attr(struct dnet_node
*n
, struct dnet_addr_attr
*attr
);
812 struct dnet_id_param
{
813 unsigned int group_id
;
815 uint64_t param_reserved
;
816 } __attribute__ ((packed
));
819 DNET_ID_PARAM_LA
= 1,
820 DNET_ID_PARAM_FREE_SPACE
,
823 int dnet_generate_ids_by_param(struct dnet_node
*n
, struct dnet_id
*id
, enum id_params param
, struct dnet_id_param
**dst
);
824 int64_t dnet_get_param(struct dnet_node
*n
, struct dnet_id
*id
, enum id_params param
);
826 int dnet_read_multiple(struct dnet_node
*n
, struct dnet_id
*id
, int num
, struct dnet_id_param
**dst
);
828 struct dnet_check_reply
{
835 static inline void dnet_convert_check_reply(struct dnet_check_reply
*r
)
837 r
->total
= dnet_bswap32(r
->total
);
838 r
->completed
= dnet_bswap32(r
->completed
);
839 r
->errors
= dnet_bswap32(r
->errors
);
842 /* Set by dnet_check when we only want to merge transaction
843 * and do not check copies in other groups
845 #define DNET_CHECK_MERGE (1<<0)
846 /* Check not only history presence but also try to read part of the data object */
847 #define DNET_CHECK_FULL (1<<1)
848 /* Do not actually perform any action, just update counters */
849 #define DNET_CHECK_DRY_RUN (1<<2)
850 /* Physically delete files marked as REMOVED in history */
851 #define DNET_CHECK_DELETE (1<<3)
853 struct dnet_check_request
{
857 uint64_t updatestamp_start
;
858 uint64_t updatestamp_stop
;
864 } __attribute__ ((packed
));
866 static inline void dnet_convert_check_request(struct dnet_check_request
*r
)
868 r
->flags
= dnet_bswap32(r
->flags
);
869 r
->thread_num
= dnet_bswap32(r
->thread_num
);
870 r
->timestamp
= dnet_bswap64(r
->timestamp
);
871 r
->updatestamp_start
= dnet_bswap64(r
->updatestamp_start
);
872 r
->updatestamp_stop
= dnet_bswap64(r
->updatestamp_stop
);
873 r
->obj_num
= dnet_bswap32(r
->obj_num
);
874 r
->group_num
= dnet_bswap32(r
->group_num
);
875 r
->blob_start
= dnet_bswap32(r
->blob_start
);
876 r
->blob_num
= dnet_bswap32(r
->blob_num
);
879 int dnet_request_check(struct dnet_node
*n
, struct dnet_check_request
*r
);
881 void *dnet_node_get_ns(struct dnet_node
*n
, int *nsize
);
882 void dnet_node_set_ns(struct dnet_node
*n
, void *ns
, int nsize
);
884 long __attribute__((weak
)) dnet_get_id(void);
886 static inline int is_trans_destroyed(struct dnet_net_state
*st
, struct dnet_cmd
*cmd
)
890 if (!st
|| !cmd
|| (cmd
->flags
& DNET_FLAGS_DESTROY
)) {
892 if (cmd
&& cmd
->status
)
899 int dnet_mix_states(struct dnet_node
*n
, struct dnet_id
*id
, int **groupsp
);
901 char * __attribute__((weak
)) dnet_cmd_string(int cmd
);
902 char *dnet_counter_string(int cntr
, int cmd_num
);
904 ssize_t
dnet_db_read_raw(struct eblob_backend
*b
, struct dnet_raw_id
*id
, void **datap
);
905 int dnet_db_write_raw(struct eblob_backend
*b
, struct dnet_raw_id
*id
, void *data
, unsigned int size
);
906 int dnet_db_remove_raw(struct eblob_backend
*b
, struct dnet_raw_id
*id
, int real_del
);
907 int dnet_db_iterate(struct eblob_backend
*b
, struct dnet_iterate_ctl
*ctl
);
909 int dnet_send_file_info(void *state
, struct dnet_cmd
*cmd
, int fd
, uint64_t offset
, int64_t size
);
911 int dnet_get_routes(struct dnet_node
*n
, struct dnet_id
**ids
, struct dnet_addr
**addrs
);
913 * Send a shell/python command to the remote node for execution.
915 int dnet_send_cmd(struct dnet_node
*n
, struct dnet_id
*id
, struct sph
*h
, void **ret
);
916 int dnet_send_cmd_nolock(struct dnet_node
*n
, struct dnet_id
*id
, struct sph
*e
, void **ret
);
918 struct dnet_range_data
*dnet_bulk_read(struct dnet_node
*n
, struct dnet_io_attr
*ios
, uint32_t io_num
, int group_id
, uint64_t cflags
, int *errp
);
919 struct dnet_range_data
dnet_bulk_write(struct dnet_node
*n
, struct dnet_io_control
*ctl
, int ctl_num
, int *errp
);
921 int dnet_flags(struct dnet_node
*n
);
922 void dnet_set_timeouts(struct dnet_node
*n
, int wait_timeout
, int check_timeout
);
924 #define DNET_CONF_ADDR_DELIM ':'
925 int dnet_parse_addr(char *addr
, struct dnet_config
*cfg
);
927 int dnet_start_defrag(struct dnet_node
*n
, uint64_t cflags
);
929 int dnet_discovery_add(struct dnet_node
*n
, struct dnet_config
*cfg
);
935 #endif /* __DNET_INTERFACE_H */