-
Notifications
You must be signed in to change notification settings - Fork 1
/
cache_file.h
66 lines (47 loc) · 1.84 KB
/
cache_file.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* vim: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
#ifndef __CACHE_FILE_H_
#define __CACHE_FILE_H_
#include "ht.h"
#include "constants.h"
struct table_t *file_table;
struct cache_file_t {
// open fd of the file, -1 if fd not available
int fd;
// should be mmap in case fd is set, otherwise normal buf
// if mmap then munmap for cleanup, free in case of normal buf
// note that buf.len >= size due to alignment
mk_pointer buf;
off_t size;
// hashed based on uri's, assuming mostly unique uri per file
// NOTE: previously it was based on inodes, but that made it
// hard to add custom buffer files in that scheme
char uri[MAX_URI_LEN];
// list of pipe_buf_t
struct mk_list cache;
// cached headers, along with some duplicate file content from cache
// header len is the length of the headers in the pipe
struct pipe_buf_t *cache_headers;
// tells weather file can be evicted from cache in case of no usage,
// not the case when its a custom buffer through the api
int evictable;
// the last time file was requested by a user
struct timeval last_accessed;
// length of the headers, rest is file contents
long header_len;
// file is zombie when it is removed from files table, but some pending
// requests still need it, when they go to zero, it is freed and went to
// heaven
int zombie;
int pending_reqs;
};
void cache_file_process_init();
void cache_file_thread_init();
void cache_file_exit();
void cache_file_free(struct cache_file_t *);
struct cache_file_t *cache_file_get(const char *);
void cache_file_reset(const char *);
struct cache_file_t *cache_file_tmp(const char *, mk_pointer *);
struct cache_file_t *cache_file_new(const char *, const char *);
// called after every interval, evicts old caches
void cache_file_tick();
#endif