summaryrefslogtreecommitdiffstats
path: root/src/statfile.h
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-12 16:39:52 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-12 16:39:52 +0300
commit2003dce62438e513e614056540c22f4f755ec88b (patch)
treed32496a72ec5c7cbe8679516817e3675de4e7333 /src/statfile.h
parent512154c538336e68b59ef0ed2c87ef9ba1e94151 (diff)
downloadrspamd-2003dce62438e513e614056540c22f4f755ec88b.tar.gz
rspamd-2003dce62438e513e614056540c22f4f755ec88b.zip
* Add sections support to rspamd statfiles API
* Change logic of statfile pool: - statfiles hash is no longer shared hash as we have per-process uniq things like current section or offset in statfile - introduce shared hash of statfiles mmapped areas to avoid multiply mmaps of the same file
Diffstat (limited to 'src/statfile.h')
-rw-r--r--src/statfile.h44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/statfile.h b/src/statfile.h
index 88779ca16..38ec9d13f 100644
--- a/src/statfile.h
+++ b/src/statfile.h
@@ -12,6 +12,9 @@
#define CHAIN_LENGTH 128
+/* Section types */
+#define STATFILE_SECTION_COMMON 1
+
/**
* Common statfile header
*/
@@ -23,6 +26,14 @@ struct stat_file_header {
} __attribute__((__packed__));
/**
+ * Section header
+ */
+struct stat_file_section {
+ uint32_t code; /**< section's code */
+ uint64_t length; /**< section's length in blocks */
+};
+
+/**
* Block of data in statfile
*/
struct stat_file_block {
@@ -37,6 +48,7 @@ struct stat_file_block {
*/
struct stat_file {
struct stat_file_header header; /**< header */
+ struct stat_file_section section; /**< first section */
struct stat_file_block blocks[1]; /**< first block of data */
};
@@ -47,10 +59,11 @@ typedef struct stat_file_s {
char *filename; /**< name of file */
int fd; /**< descriptor */
void *map; /**< mmaped area */
+ off_t seek_pos; /**< current seek position */
+ struct stat_file_section cur_section; /**< current section */
time_t open_time; /**< time when file was opened */
time_t access_time; /**< last access time */
size_t len; /**< length of file(in bytes) */
- size_t blocks; /**< length of file in blocks */
gint *lock; /**< mutex */
} stat_file_t;
@@ -59,6 +72,7 @@ typedef struct stat_file_s {
*/
typedef struct statfile_pool_s {
rspamd_hash_t *files; /**< hash table of opened files indexed by name */
+ rspamd_hash_t *maps; /**< shared hash table of mmaped areas indexed by name */
int opened; /**< number of opened files */
size_t max; /**< maximum size */
size_t occupied; /**< current size */
@@ -148,4 +162,32 @@ void statfile_pool_set_block (statfile_pool_t *pool, char *filename, uint32_t h1
*/
gboolean statfile_pool_is_open (statfile_pool_t *pool, char *filename);
+/**
+ * Returns current statfile section
+ * @param pool statfile pool object
+ * @param filename name of statfile
+ * @return code of section or 0 if file is not opened
+ */
+uint32_t statfile_pool_get_section (statfile_pool_t *pool, char *filename);
+
+/**
+ * Go to other section of statfile
+ * @param pool statfile pool object
+ * @param filename name of statfile
+ * @param code code of section to seek to
+ * @param from_begin search for section from begin of file if true
+ * @return TRUE if section was set and FALSE otherwise
+ */
+gboolean statfile_pool_set_section (statfile_pool_t *pool, char *filename, uint32_t code, gboolean from_begin);
+
+/**
+ * Add new section to statfile
+ * @param pool statfile pool object
+ * @param filename name of statfile
+ * @param code code of section to seek to
+ * @param length length in blocks of new section
+ * @return TRUE if section was successfully added and FALSE in case of error
+ */
+gboolean statfile_pool_add_section (statfile_pool_t *pool, char *filename, uint32_t code, uint64_t length);
+
#endif