mars/kernel/lib_log.h

208 lines
5.3 KiB
C
Raw Permalink Normal View History

2014-11-21 10:51:34 +00:00
/*
* MARS Long Distance Replication Software
*
* This file is part of MARS project: http://schoebel.github.io/mars/
*
* Copyright (C) 2010-2014 Thomas Schoebel-Theuer
* Copyright (C) 2011-2014 1&1 Internet AG
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
2011-02-23 20:48:06 +00:00
/* Definitions for logfile format.
*
* This is meant for sharing between different transaction logger variants,
* and/or for sharing with userspace tools (e.g. logfile analyzers).
2011-04-18 09:23:04 +00:00
* TODO: factor out some remaining kernelspace issues.
2011-02-23 20:48:06 +00:00
*/
2011-04-18 09:23:04 +00:00
#ifndef LIB_LOG_H
#define LIB_LOG_H
2010-12-15 11:58:22 +00:00
2022-06-10 15:57:39 +00:00
#include "mars_errno.h"
#ifdef __KERNEL__
2010-12-15 11:58:22 +00:00
#include "mars.h"
2019-07-25 08:27:43 +00:00
extern __u32 enabled_log_compressions;
extern __u32 used_log_compression;
extern atomic_t global_mref_flying;
#endif
2010-12-15 11:58:22 +00:00
/* The following structure is memory-only.
* Transfers to disk are indirectly via the
* format conversion functions below.
* The advantage is that even newer disk formats can be parsed
* by old code (of course, not all information / features will be
* available then).
*/
2011-03-10 11:40:06 +00:00
#define log_header log_header_v1
struct log_header_v1 {
2019-02-19 09:18:29 +00:00
struct lamport_time l_stamp;
2010-12-15 11:58:22 +00:00
loff_t l_pos;
short l_len;
2019-07-25 08:27:43 +00:00
short l_decompress_len;
2011-03-27 15:18:38 +00:00
short l_code;
unsigned int l_seq_nr;
2019-08-07 06:40:43 +00:00
__u32 l_crc_old;
2019-03-26 09:57:33 +00:00
__u16 l_crc_flags;
2010-12-15 11:58:22 +00:00
};
#define FORMAT_VERSION 1 // version of disk format, currently there is no other one
#define CODE_UNKNOWN 0
#define CODE_WRITE_NEW 1
#define CODE_WRITE_OLD 2
#define START_MAGIC 0xa8f7e908d9177957ll
#define END_MAGIC 0x74941fb74ab5726dll
2011-03-27 15:18:38 +00:00
#define START_OVERHEAD \
2010-12-15 11:58:22 +00:00
( \
sizeof(START_MAGIC) + \
2011-03-27 15:18:38 +00:00
sizeof(char) + \
sizeof(char) + \
2010-12-15 11:58:22 +00:00
sizeof(short) + \
2019-02-19 09:18:29 +00:00
sizeof(struct lamport_time) + \
2011-03-27 15:18:38 +00:00
sizeof(loff_t) + \
sizeof(int) + \
2010-12-15 11:58:22 +00:00
sizeof(int) + \
sizeof(short) + \
2011-03-27 15:18:38 +00:00
sizeof(short) + \
0 \
)
2019-08-07 12:10:45 +00:00
#define LOG_CHKSUM_SIZE (sizeof(__u64) * 2)
2011-03-27 15:18:38 +00:00
#define END_OVERHEAD \
( \
sizeof(END_MAGIC) + \
2010-12-15 11:58:22 +00:00
sizeof(int) + \
2011-03-27 15:18:38 +00:00
sizeof(char) + \
3 + 4 /*spare*/ + \
2019-08-07 12:10:45 +00:00
LOG_CHKSUM_SIZE + \
2010-12-15 11:58:22 +00:00
0 \
)
2011-03-27 15:18:38 +00:00
#define OVERHEAD (START_OVERHEAD + END_OVERHEAD)
2020-04-28 07:58:06 +00:00
/* alignment of log positions to 64bit */
#define _LOG_PAD_BITS 3
#define _LOG_PAD (1 << _LOG_PAD_BITS)
2010-12-15 11:58:22 +00:00
// TODO: make this bytesex-aware.
#define DATA_PUT(data,offset,val) \
do { \
2011-03-27 15:18:38 +00:00
*((typeof(val)*)((data)+offset)) = val; \
2010-12-15 11:58:22 +00:00
offset += sizeof(val); \
} while (0)
#define DATA_GET(data,offset,val) \
do { \
2011-03-27 15:18:38 +00:00
val = *((typeof(val)*)((data)+offset)); \
2010-12-15 11:58:22 +00:00
offset += sizeof(val); \
} while (0)
#define SCAN_TXT "at file_pos = %lld file_offset = %d scan_offset = %d (%lld) test_offset = %d (%lld) restlen = %d: "
#define SCAN_PAR file_pos, file_offset, offset, file_pos + file_offset + offset, i, file_pos + file_offset + i, restlen
2019-07-25 09:14:24 +00:00
extern int log_scan(void *buf,
int len,
loff_t file_pos,
int file_offset,
bool sloppy,
struct log_header *lh,
void **payload, int *payload_len,
void **dealloc,
2022-06-10 15:57:39 +00:00
unsigned int *seq_nr,
int *mars_error_code,
int *byte_code);
2011-03-10 11:40:06 +00:00
////////////////////////////////////////////////////////////////////////////
#ifdef __KERNEL__
/* Bookkeeping status between calls
*/
struct log_status {
2012-12-11 15:33:26 +00:00
// interfacing
wait_queue_head_t *signal_event;
2020-01-29 08:42:43 +00:00
int *signal_flag;
2011-03-11 13:57:54 +00:00
// tunables
loff_t start_pos;
loff_t end_pos;
2011-03-11 13:57:54 +00:00
int align_size; // alignment between requests
int chunk_size; // must be at least 8K (better 64k)
int max_size; // max payload length
2011-03-29 14:40:40 +00:00
int io_prio;
2019-07-25 08:27:43 +00:00
bool do_compress;
2011-03-18 13:15:40 +00:00
// informational
atomic_t mref_flying;
2011-05-13 11:19:28 +00:00
int count;
2011-03-18 13:15:40 +00:00
loff_t log_pos;
2019-02-19 09:18:29 +00:00
struct lamport_time log_pos_stamp;
2011-03-11 13:57:54 +00:00
// internal
2019-02-19 09:18:29 +00:00
struct lamport_time tmp_pos_stamp;
2011-03-10 11:40:06 +00:00
struct mars_input *input;
struct mars_brick *brick;
2011-03-10 11:40:06 +00:00
struct mars_info info;
2011-03-11 13:57:54 +00:00
int offset;
2011-03-10 11:40:06 +00:00
int validflag_offset;
2019-07-25 08:27:43 +00:00
int totallen_offset;
2011-03-10 11:40:06 +00:00
int reallen_offset;
2019-07-25 08:27:43 +00:00
int decompresslen_offset;
2011-03-10 11:40:06 +00:00
int payload_offset;
int payload_len;
unsigned int seq_nr;
2011-03-10 11:40:06 +00:00
struct mref_object *log_mref;
2011-03-22 14:36:26 +00:00
struct mref_object *read_mref;
wait_queue_head_t event;
2022-06-10 15:57:39 +00:00
int posix_error_code;
int mars_error_code;
int byte_code;
2011-03-22 14:36:26 +00:00
bool got;
2011-04-08 09:52:46 +00:00
bool do_free;
2011-03-11 13:57:54 +00:00
void *private;
2011-03-10 11:40:06 +00:00
};
2010-12-15 11:58:22 +00:00
void init_logst(struct log_status *logst, struct mars_input *input, loff_t start_pos, loff_t end_pos);
void exit_logst(struct log_status *logst);
2010-12-15 11:58:22 +00:00
2011-03-22 14:36:26 +00:00
void log_flush(struct log_status *logst);
2011-03-10 11:40:06 +00:00
void *log_reserve(struct log_status *logst, struct log_header *lh);
2013-01-03 09:12:20 +00:00
bool log_finalize(struct log_status *logst, int len, void (*endio)(void *private, int error), void *private);
2011-03-10 11:40:06 +00:00
int log_read(struct log_status *logst,
bool sloppy,
struct log_header *lh,
void **payload, int *payload_len,
void **dealloc);
2011-03-18 13:15:40 +00:00
2011-08-25 10:16:32 +00:00
/////////////////////////////////////////////////////////////////////////
// init
extern int init_log_format(void);
extern void exit_log_format(void);
2011-03-10 11:40:06 +00:00
#endif
2010-12-15 11:58:22 +00:00
#endif