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_BACKENDS_H
17 #define __DNET_BACKENDS_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
)
35 if (!record_size
&& size
)
38 if (!size
|| size
+ io
->offset
>= record_size
) {
42 if (size
+ io
->offset
>= record_size
) {
43 if (io
->offset
>= record_size
)
46 size
= record_size
- io
->offset
;
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
);
62 res
[bit_num
/ 4] = '\0';
66 struct dnet_config_backend
;
67 struct dnet_config_entry
{
69 int (*callback
)(struct dnet_config_backend
*b
, char *key
, char *value
);
72 struct dnet_config_backend
{
74 struct dnet_config_entry
*ent
;
79 unsigned long long storage_size
;
80 unsigned long long storage_free
;
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_mask(uint32_t mask
);
101 void dnet_backend_log_raw(uint32_t mask
, const char *fmt
, ...) __attribute__ ((format(printf
, 2, 3)));
102 #define dnet_backend_log(mask, format, a...) \
104 if (dnet_backend_check_log_mask(mask)) \
105 dnet_backend_log_raw(mask, format, ##a); \
112 #endif /* __DNET_BACKENDS_H */