1/* 2 * Copyright (c) 2014, University of Washington. 3 * All rights reserved. 4 * 5 * This file is distributed under the terms in the attached LICENSE file. 6 * If you do not find this file, copies can be found by writing to: 7 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group. 8 */ 9 10#ifndef TENACIOUSD_LOG_H 11#define TENACIOUSD_LOG_H 12 13struct storage_vsa; 14struct storage_vsic; 15 16#define TENACIOUSD_LOG_MIN_ENTRY_SIZE(log) \ 17 (STORAGE_VSIC_ROUND(log->vsic, sizeof(struct tenaciousd_log_entry)) - sizeof(struct tenaciousd_log_entry)) 18 19// sizeof(struct tenaciousd_log_entry) = on-disk size of header + footer 20struct tenaciousd_log_entry { 21 uint64_t size; 22 uint64_t next; // Only valid on disk 23 uint8_t data[0]; 24 uint8_t marker; // Never valid 25} __attribute__ ((packed)); 26 27struct tenaciousd_log_iter { 28 struct tenaciousd_log_entry *entry; 29 struct tenaciousd_log_iter *next; 30 uint64_t offset; 31}; 32 33struct tenaciousd_log { 34 struct storage_vsa *vsa; 35 struct storage_vsic *vsic; 36 uint64_t entries; 37 uint64_t end; 38}; 39 40struct tenaciousd_log *tenaciousd_log_new(struct storage_vsa *vsa, 41 struct storage_vsic *vsic); 42 43errval_t tenaciousd_log_delete(struct tenaciousd_log *log); 44 45errval_t tenaciousd_log_append(struct tenaciousd_log *log, 46 struct tenaciousd_log_entry *entry); 47 48errval_t tenaciousd_log_trim(struct tenaciousd_log *log, int nentries); 49 50struct tenaciousd_log_iter tenaciousd_log_begin(struct tenaciousd_log *log); 51 52struct tenaciousd_log_iter tenaciousd_log_next(struct tenaciousd_log *log, 53 struct tenaciousd_log_iter iter); 54 55struct tenaciousd_log_entry * 56tenaciousd_log_entry_new(struct tenaciousd_log *log, 57 size_t *size); 58 59struct tenaciousd_log_entry * 60tenaciousd_log_entry_resize(struct tenaciousd_log *log, 61 struct tenaciousd_log_entry *entry, 62 size_t *newsize); 63 64void tenaciousd_log_entry_delete(struct tenaciousd_log *log, 65 struct tenaciousd_log_entry *entry); 66 67static inline bool tenaciousd_log_end(struct tenaciousd_log_iter iter) 68{ 69 return iter.entry == NULL ? true : false; 70} 71 72static inline void *tenaciousd_log_iter_data(struct tenaciousd_log_iter iter) 73{ 74 return (void *)iter.entry->data; 75} 76 77#endif 78