write-actions.h 2.98 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 * (C) 2017 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */
#ifndef __MOBJECT_WRITE_OPCODES_H
#define __MOBJECT_WRITE_OPCODES_H

#include "mobject-store-config.h"
10
#include "buffer-union.h"
11 12 13 14 15 16 17 18 19 20 21 22

typedef enum {
	WRITE_OPCODE_BASE = 0,
	WRITE_OPCODE_CREATE,
	WRITE_OPCODE_WRITE,
	WRITE_OPCODE_WRITE_FULL,
	WRITE_OPCODE_WRITE_SAME,
	WRITE_OPCODE_APPEND,
	WRITE_OPCODE_REMOVE,
	WRITE_OPCODE_TRUNCATE,
	WRITE_OPCODE_ZERO,
	WRITE_OPCODE_OMAP_SET,
23 24
	WRITE_OPCODE_OMAP_RM_KEYS,
	_WRITE_OPCODE_END_ENUM_
25 26 27 28 29 30 31 32 33 34 35 36 37
} write_op_code_t;

#define WRITE_ACTION_DOWNCAST(child_obj, base_obj, child_category) \
	if(WRITE_OPCODE_ ## child_category != base_obj->type) {\
		MOBJECT_LOG("Downcast error: " #base_obj " is not of type WRITE_ACTION_" #child_category);\
	}\
	struct wr_action_ ## child_category * child_obj = (struct wr_action_ ## child_category *) base_obj;

#define WRITE_ACTION_UPCAST(base_obj, child_obj) \
	struct wr_action_BASE* base_obj = (struct wr_action_BASE*) child_obj;

typedef struct wr_action_BASE {
	write_op_code_t        type;
38 39
	struct wr_action_BASE* prev;
	struct wr_action_BASE* next;
40 41 42 43 44 45 46 47 48
}* wr_action_base_t;

typedef struct wr_action_CREATE {
	struct wr_action_BASE base;
	int                   exclusive;
}* wr_action_create_t;

typedef struct wr_action_WRITE {
	struct wr_action_BASE base;
49
	buffer_u              buffer;
50 51 52 53 54 55
	size_t                len;
	uint64_t              offset;
}* wr_action_write_t;

typedef struct wr_action_WRITE_FULL {
	struct wr_action_BASE base;
56
	buffer_u              buffer;
57 58 59 60 61
	size_t                len;
}* wr_action_write_full_t;

typedef struct wr_action_WRITE_SAME {
	struct wr_action_BASE base;
62
	buffer_u              buffer;
63 64 65 66 67 68 69
	size_t                data_len;
	size_t                write_len;
	uint64_t              offset;
}* wr_action_write_same_t;

typedef struct wr_action_APPEND {
	struct wr_action_BASE base;
70
	buffer_u              buffer;
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
	size_t                len;
}* wr_action_append_t;

typedef struct wr_action_REMOVE {
	struct wr_action_BASE base;
}* wr_action_remove_t;

typedef struct wr_action_TRUNCATE {
	struct wr_action_BASE base;
	uint64_t              offset;
}* wr_action_truncate_t;

typedef struct wr_action_ZERO {
	struct wr_action_BASE base;
	uint64_t              offset;
	uint64_t              len;
}* wr_action_zero_t;

typedef struct wr_action_OMAP_SET {
	struct wr_action_BASE base;
	size_t                num;
92
	size_t                data_size;
93
	char                  data[1];
94
}* wr_action_omap_set_t;
95 96 97 98 99
// data above is meant to hold keys, lengths, and values,
// all put together in the same contiguous buffer.
// The buffer holds a series of [key,len,value] segments
// where key is a null-terminated string, len is a size_t,
// and value is a len-sized segment.
100 101 102

typedef struct wr_action_RM_KEYS {
	struct wr_action_BASE base;
103 104 105
	size_t                num_keys;
	size_t                data_size;
	char                  data[1];
106
}* wr_action_omap_rm_keys_t;
107 108
// keys above is meant to hold keys in a contiguous buffer.
// The keys are null-terminated strings.
109 110 111

#endif