cache/engines/fs.c
author Tero Marttila <terom@fixme.fi>
Sat, 30 Aug 2008 19:13:15 +0300
changeset 49 10c7dce1a043
parent 37 f0188b445c84
permissions -rw-r--r--
autogenerate the memcache_test help output, and pipeline memcache requests
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     1
#define _GNU_SOURCE
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     2
#include <sys/types.h>
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     3
#include <unistd.h>
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     4
#include <sys/mman.h>
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     5
#include <sys/stat.h>
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     6
#include <stdlib.h>
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     7
#include <sys/param.h>
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     8
#include <stdio.h>
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     9
#include <fcntl.h>
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    10
#include <errno.h>
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    11
#include <assert.h>
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    12
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    13
#include "../../cache.h"
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    14
#include "../cache.h"
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    15
#include "../engine.h"
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    16
#include "../op.h"
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    17
#include "../../common.h"
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    18
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    19
#define FS_PAGE_SIZE (4096)
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    20
#define FS_INITIAL_SIZE (1 * FS_PAGE_SIZE)
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    21
#define FS_PAGE_GROW_FACTOR (2)
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    22
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    23
struct cache_engine_fs {
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    24
    struct cache_engine base;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    25
    
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    26
    // custom stuff
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    27
    const char *cache_dir;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    28
};
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    29
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    30
struct cache_fs {
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    31
    struct cache base;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    32
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    33
    // custom stuff?
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    34
};
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    35
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    36
struct cache_op_fs {
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    37
    struct cache_op base;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    38
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    39
    // custom
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    40
    int fd;
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    41
    
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    42
    // what kind of access... PROT_READ | PROT_WRITE or PROT_READ
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    43
    int mmap_prot;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    44
    
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    45
    /*
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    46
     * Either contains the final size of the cache entry, or zero.
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    47
     */
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    48
    off_t size;
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    49
    
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    50
    /*
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    51
     * Contains the size of the underlying file. Usually this is the same as mmap_size.
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    52
     */
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    53
    off_t file_size;
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    54
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    55
    /*
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    56
     * Contains the size of the currently mmap'd region
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    57
     */
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    58
    off_t mmap_size;
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    59
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    60
    void *mmap;
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    61
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    62
    off_t write_offset;
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    63
};
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    64
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    65
#define FS_OP_DATA_SIZE(op) (op->size ? op->size : op->write_offset)
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    66
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    67
/*
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    68
 * if new_size is equal to op->mmap_size, nothing will be changed
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    69
 */
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    70
static int _fs_mmap (struct cache_op_fs *op, size_t new_size) {
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    71
    assert(new_size > 0);
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    72
    
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    73
    // resize file?
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    74
    if (new_size != op->file_size) {
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    75
        // new size
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    76
        op->file_size = new_size;
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    77
        
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    78
        // and ftruncate
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    79
        if (ftruncate(op->fd, op->file_size))
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    80
            PERROR("ftruncate");
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    81
    }
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    82
    
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    83
    // create mmap, or resize?
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    84
    if (op->mmap) {
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    85
        assert(op->mmap_size > 0);
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    86
        
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    87
        // resize mmap?
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    88
        if (op->mmap_size != new_size) {
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    89
            if ((op->mmap = mremap(op->mmap, new_size, op->mmap_size, MREMAP_MAYMOVE)) == MAP_FAILED)
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    90
                PERROR("mremap");
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    91
            
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    92
            op->mmap_size = new_size;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    93
        }
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    94
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    95
    } else {
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    96
        // do new mmap
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    97
        op->mmap_size = new_size;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    98
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    99
        if ((op->mmap = mmap(NULL, op->mmap_size, op->mmap_prot, MAP_SHARED | MAP_POPULATE, op->fd, 0)) == MAP_FAILED)
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   100
            PERROR("mmap");
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   101
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   102
    }
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   103
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   104
    return 0;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   105
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   106
error:
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   107
    return -1;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   108
}
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   109
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   110
/*
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   111
 * reuturn a pointer to a static buf containing the path to the key in the given op
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   112
 */
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   113
static const char *_fs_path (struct cache_engine_fs *engine, struct cache_op_fs *op) {
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   114
    static char path[PATH_MAX];
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   115
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   116
    struct cache_key *key = op->base.key;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   117
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   118
    // construct the path to the appropriate file
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   119
    if (snprintf(path, PATH_MAX, "%s/%*s", engine->cache_dir, (int) key->length - 1, key->buf) >= PATH_MAX)
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   120
        ERROR("path too long: %s/%*s", engine->cache_dir, (int) key->length - 1, key->buf);
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   121
    
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   122
    return path;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   123
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   124
error:
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   125
    return NULL;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   126
}
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   127
 
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   128
/*
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   129
 * Grow the file if needed so that it fits the given amount of bytes
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   130
 */
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   131
static int _fs_grow (struct cache_op_fs *op, size_t new_size_hint) {
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   132
    if (op->mmap_size >= new_size_hint)
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   133
        return 0;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   134
    
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   135
    // XXX: need some math.ceil
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   136
    size_t new_size = ((op->mmap_size / FS_PAGE_SIZE) + 1) * FS_PAGE_SIZE;
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   137
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   138
    while (new_size < new_size_hint) {
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   139
        new_size *= FS_PAGE_GROW_FACTOR;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   140
    }
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   141
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   142
    return _fs_mmap(op, new_size);
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   143
}
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   144
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   145
static int _fs_do_init (struct cache_engine *engine, struct cache **cache_ptr) {
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   146
    struct cache_engine_fs *ctx = (struct cache_engine_fs *) engine;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   147
    struct cache_fs *cache = NULL;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   148
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   149
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   150
    if ((cache = calloc(1, sizeof(*cache))) == NULL)
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   151
        ERROR("calloc");
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   152
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   153
    if (cache_init(&cache->base, &ctx->base))
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   154
        goto error;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   155
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   156
    *cache_ptr = &cache->base;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   157
    
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   158
    return 0;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   159
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   160
error:
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   161
    free(cache);
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   162
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   163
    return -1;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   164
}
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   165
    
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   166
static int _fs_do_op_start (struct cache *cache, struct cache_op **op_ptr, struct cache_key *key) {
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   167
    struct cache_engine_fs *engine = (struct cache_engine_fs *) cache->engine;
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   168
    struct cache_op_fs *op = NULL;
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   169
    struct stat stat_info;
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   170
    int found = 0;
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   171
    const char *path;
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   172
    
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   173
    // allocate it
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   174
    if ((op = calloc(1, sizeof(*op))) == NULL)
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   175
        ERROR("calloc");
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   176
    
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   177
    // init it
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
   178
    if (_cache_op_init(&op->base, cache, key))
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   179
        goto error;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   180
    
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   181
    // mark it as being in the lookup state...
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   182
    op->base.state = OP_STATE_LOOKUP;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   183
    
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   184
    // fetch the path
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   185
    if ((path = _fs_path(engine, op)) == NULL)
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   186
        goto error;
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   187
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   188
    // stat
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   189
    if (stat(path, &stat_info)) {
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   190
        if (errno == ENOENT) {
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   191
            found = 0;
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   192
            // op->size remains 0
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   193
        } else
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   194
            PERROR("stat: %s", path);
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   195
    } else {
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   196
        found = 1;
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   197
        op->file_size = stat_info.st_size;
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   198
    }
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   199
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   200
    // indicate that the key was found/not found
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
   201
    if (_cache_op_lookup_done(&op->base, found))
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   202
        goto error;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   203
    
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   204
    *op_ptr = &op->base;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   205
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   206
    // done!
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   207
    return 0;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   208
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   209
error:
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   210
    free(op);
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   211
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   212
    return -1;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   213
   
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   214
}
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   215
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   216
int _fs_do_op_available (struct cache_op *op_base, size_t *size, size_t *offset) {
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   217
    struct cache_op_fs *op = (struct cache_op_fs *) op_base;
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   218
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   219
    // this is easy, it's only known if a HIT, or after op_done, so it's the same as...
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   220
    *size = op->size;
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   221
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   222
    // op->size if nonzero, write_offset otherwise
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   223
    *offset = op->size ? op->size : op->write_offset;
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   224
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   225
    return 0;
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   226
}
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   227
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   228
int _fs_do_op_begin_read (struct cache_op *op_base) {
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   229
    struct cache_op_fs *op = (struct cache_op_fs *) op_base;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   230
    struct cache_engine_fs *engine = (struct cache_engine_fs *) op->base.cache->engine;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   231
    
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   232
    const char *path;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   233
    
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   234
    // should be known (nonzero) for HITs that we read from
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   235
    assert(op->file_size > 0);
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   236
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   237
    // fetch the path
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   238
    if ((path = _fs_path(engine, op)) == NULL)
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   239
        goto error;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   240
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   241
    // create the appropriate file for read-write, exclusively
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   242
    if ((op->fd = open(path, O_RDONLY)) == -1)
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   243
        PERROR("open: %s", path);
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   244
    
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   245
    {
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   246
        struct stat stat_info;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   247
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   248
        // assert size hasn't changed
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   249
        if (fstat(op->fd, &stat_info))
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   250
            PERROR("fstat");
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   251
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   252
        assert(stat_info.st_size == op->file_size);
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   253
    }
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   254
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   255
    // assign exact size
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   256
    op->size = op->file_size;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   257
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   258
    // read-only access
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   259
    op->mmap_prot = PROT_READ;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   260
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   261
    // doesn't ftruncate, just mmap's
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   262
    if (_fs_mmap(op, op->size))
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   263
        goto error;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   264
    
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   265
    // great
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   266
    if (_cache_op_read_ready(&op->base))
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   267
        goto error;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   268
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   269
    // done
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   270
    return 0;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   271
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   272
error:
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   273
    return -1;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   274
}
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   275
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   276
int _fs_do_op_begin_write (struct cache_op *op_base, size_t size_hint) {
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   277
    struct cache_op_fs *op = (struct cache_op_fs *) op_base;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   278
    struct cache_engine_fs *engine = (struct cache_engine_fs *) op->base.cache->engine;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   279
    
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   280
    const char *path;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   281
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   282
    assert(size_hint >= 0);
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   283
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   284
    // should be unknown (0) for MISS's that we then write to
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   285
    assert(op->size == 0);
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   286
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   287
    // fetch the path
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   288
    if ((path = _fs_path(engine, op)) == NULL)
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   289
        goto error;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   290
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   291
    // create the appropriate file for read-write, exclusively
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   292
    if ((op->fd = open(path, O_CREAT | O_RDWR | O_EXCL, 0644)) == -1)
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   293
        PERROR("open: %s", path);
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   294
    
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   295
    // read/write access
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   296
    op->mmap_prot = PROT_READ | PROT_WRITE;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   297
    
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   298
    // ftruncate, and then mmap
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   299
    if (_fs_mmap(op, size_hint ? size_hint : FS_INITIAL_SIZE))
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   300
        goto error;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   301
    
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   302
    // great
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
   303
    if (_cache_op_write_ready(&op->base))
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   304
        goto error;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   305
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   306
    // done
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   307
    return 0;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   308
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   309
error:
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   310
    return -1;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   311
}
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   312
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   313
int _fs_do_op_push (struct cache_op *op_base, int fd, size_t *size_ptr) {
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   314
    struct cache_op_fs *op = (struct cache_op_fs *) op_base;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   315
    struct cache_engine_fs *engine = (struct cache_engine_fs *) op->base.cache->engine;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   316
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   317
    size_t ret, size;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   318
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   319
    assert(op->fd > 0);
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   320
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   321
    // must have called begin_write first...
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   322
    assert(op->mmap_size > 0);
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   323
    assert(op->mmap != NULL);
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   324
    assert(op->write_offset <= op->mmap_size);
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   325
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   326
    // default size if none specified
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   327
    if (*size_ptr == 0)
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   328
        size = FS_INITIAL_SIZE;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   329
    else
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   330
        size = *size_ptr;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   331
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   332
    // grow the file if needed
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   333
    if (_fs_grow(op, op->write_offset + size))
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   334
        goto error;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   335
    
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   336
    // read the data into the mmap'd region
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   337
    if ((ret = read(fd, op->mmap + op->write_offset, size)) == -1)
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   338
        // XXX: EAGAIN
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   339
        PERROR("read");
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   340
    
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   341
    // move the write offset along
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   342
    op->write_offset += ret;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   343
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   344
    // return something
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   345
    *size_ptr = ret;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   346
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   347
    // notify newly available data
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
   348
    if (_cache_op_data_available(&op->base))
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   349
        goto error;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   350
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   351
    // great
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   352
    return 0;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   353
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   354
error:
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   355
    return -1;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   356
}
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   357
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   358
int _fs_do_op_pull (struct cache_op *op_base, int fd, size_t *offset, size_t *size) {
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   359
    struct cache_op_fs *op = (struct cache_op_fs *) op_base;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   360
    struct cache_engine_fs *engine = (struct cache_engine_fs *) op->base.cache->engine;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   361
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   362
    size_t ret;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   363
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   364
    // must have called begin_read first...
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   365
    assert(op->fd > 0);
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   366
    assert(op->mmap_size > 0);
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   367
    assert(op->mmap != NULL);
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   368
    // op->size may be zero
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   369
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   370
    // default size if none specified
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   371
    if (*size == 0) {
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   372
        *size = FS_OP_DATA_SIZE(op) - *offset;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   373
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   374
        if (*size == 0) {
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   375
            ERROR("no more data available");
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   376
        }
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   377
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   378
    } else if (*size + *offset > FS_OP_DATA_SIZE(op)) {
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   379
        ERROR("more data requested is available");
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   380
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   381
    } else if (*size == 0) {
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   382
        ERROR("size may not be zero");
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   383
    }
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   384
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   385
    // write the data from the mmap'd region
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   386
    if ((ret = write(fd, op->mmap + *offset, *size)) == -1)
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   387
        // XXX: EAGAIN?
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   388
        PERROR("write");
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   389
    
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   390
    // move the offset along
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   391
    *offset += ret;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   392
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   393
    // great
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   394
    return 0;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   395
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   396
error:
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   397
    return -1;
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   398
}
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   399
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   400
int _fs_do_op_done (struct cache_op *op_base) {
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   401
    struct cache_op_fs *op = (struct cache_op_fs *) op_base;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   402
    struct cache_engine_fs *engine = (struct cache_engine_fs *) op->base.cache->engine;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   403
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   404
    assert(op->fd > 0);
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   405
    assert(op->mmap != NULL);
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   406
    assert(op->write_offset <= op->mmap_size);
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   407
    
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   408
    // empty cache entries are illegal
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   409
    assert(op->write_offset > 0);
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   410
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   411
    // final size is now known
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   412
    op->size = op->write_offset;
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   413
    
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   414
    // truncate to match data length
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   415
    if (_fs_mmap(op, op->size))
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   416
        goto error;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   417
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   418
    // notify that data is complete
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
   419
    if (_cache_op_write_done(&op->base))
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   420
        goto error;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   421
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   422
    // great
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   423
    return 0;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   424
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   425
error:
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   426
    return -1;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   427
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   428
}
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   429
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   430
int _fs_do_op_close (struct cache_op *op_base) {
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   431
    struct cache_op_fs *op = (struct cache_op_fs *) op_base;
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   432
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   433
    // unmap
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   434
    if (op->mmap)
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   435
        if (munmap(op->mmap, op->mmap_size))
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   436
            PWARNING("munmap");
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   437
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   438
    // close
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   439
    if (op->fd > 0)
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   440
        if (close(op->fd))
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   441
            PWARNING("close");
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   442
    
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   443
    // XXX: delete if op->write_offset == 0?
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   444
    
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   445
    // free
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   446
    free(op);
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   447
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   448
    return 0;
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   449
}
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   450
struct cache_engine *cache_engine_fs (const char *cache_dir) {
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   451
    struct cache_engine_fs *ctx = NULL;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   452
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   453
    if ((ctx = calloc(1, sizeof(*ctx))) == NULL)
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   454
        ERROR("calloc");
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   455
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   456
    ctx->cache_dir = cache_dir;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   457
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   458
    // set up the fn table
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   459
    ctx->base.fn_init = &_fs_do_init;
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   460
    ctx->base.fn_op_start = &_fs_do_op_start;
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   461
    ctx->base.fn_op_available = &_fs_do_op_available;
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   462
    ctx->base.fn_op_begin_read = &_fs_do_op_begin_read;
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   463
    ctx->base.fn_op_begin_write = &_fs_do_op_begin_write;
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   464
    ctx->base.fn_op_push = &_fs_do_op_push;
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   465
    ctx->base.fn_op_pull = &_fs_do_op_pull;
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   466
    ctx->base.fn_op_done = &_fs_do_op_done;
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   467
    ctx->base.fn_op_close = &_fs_do_op_close;
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   468
    
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   469
    return &ctx->base;
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   470
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   471
error:
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   472
    free(ctx);
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   473
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   474
    return NULL;
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   475
}
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
   476