Elliptics version update: 2.19.2.7
[elliptics.git] / example / backends.h
blob675e478109c899e30fedfa237ca254485e1ac4e2
1 /*
2 * 2008+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
3 * All rights reserved.
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_BACKENDS_H
17 #define __DNET_BACKENDS_H
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
23 #include <strings.h>
25 #include "elliptics/core.h"
26 #include "elliptics/packet.h"
28 static inline int64_t dnet_backend_check_get_size(struct dnet_io_attr *io, uint64_t record_size)
30 uint64_t size = io->size;
32 if (record_size <= io->offset)
33 return 0;
35 if (!record_size && size)
36 return -E2BIG;
38 if (!size || size + io->offset >= record_size) {
39 if (!size)
40 size = record_size;
42 if (size + io->offset >= record_size) {
43 if (io->offset >= record_size)
44 size = 0;
45 else
46 size = record_size - io->offset;
50 return size;
53 int backend_stat(void *state, char *path, struct dnet_cmd *cmd);
55 int backend_stat_low_level(const char *path, struct dnet_stat *st);
57 static inline char *file_backend_get_dir(const unsigned char *id, uint64_t bit_num, char *dst)
59 char *res = dnet_dump_id_len_raw(id, ALIGN(bit_num, 8) / 8, dst);
61 if (res)
62 res[bit_num / 4] = '\0';
63 return res;
66 struct dnet_config_backend;
67 struct dnet_config_entry {
68 char key[64];
69 int (*callback)(struct dnet_config_backend *b, char *key, char *value);
72 struct dnet_config_backend {
73 char name[64];
74 struct dnet_config_entry *ent;
75 int num;
76 int size;
77 void *data;
79 unsigned long long storage_size;
80 unsigned long long storage_free;
82 struct dnet_log *log;
84 int (* init)(struct dnet_config_backend *b, struct dnet_config *cfg);
85 void (* cleanup)(struct dnet_config_backend *b);
87 struct dnet_backend_callbacks cb;
90 int dnet_backend_register(struct dnet_config_backend *b);
92 int dnet_file_backend_init(void);
93 void dnet_file_backend_exit(void);
95 int dnet_eblob_backend_init(void);
96 void dnet_eblob_backend_exit(void);
98 int backend_storage_size(struct dnet_config_backend *b, const char *root);
100 int dnet_backend_check_log_level(int level);
101 void dnet_backend_log_raw(int level, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
102 #define dnet_backend_log(level, format, a...) \
103 do { \
104 if (dnet_backend_check_log_level(level)) \
105 dnet_backend_log_raw(level, format, ##a); \
106 } while (0)
108 #ifdef __cplusplus
110 #endif
112 #endif /* __DNET_BACKENDS_H */