2016-08-13 17:11:11 -07:00
|
|
|
#ifndef PLASMA_H
|
|
|
|
#define PLASMA_H
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2016-09-10 16:39:24 -07:00
|
|
|
#include <stddef.h>
|
2016-08-13 17:11:11 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-09-15 15:39:33 -07:00
|
|
|
#include "uthash.h"
|
|
|
|
|
2016-08-17 12:54:34 -07:00
|
|
|
#ifdef NDEBUG
|
2016-09-08 15:28:27 -07:00
|
|
|
#define LOG_DEBUG(M, ...)
|
2016-08-17 12:54:34 -07:00
|
|
|
#else
|
2016-09-08 15:28:27 -07:00
|
|
|
#define LOG_DEBUG(M, ...) \
|
|
|
|
fprintf(stderr, "[DEBUG] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
2016-08-17 12:54:34 -07:00
|
|
|
#endif
|
|
|
|
|
2016-09-10 16:39:24 -07:00
|
|
|
#ifdef PLASMA_LOGGIN_ON
|
|
|
|
#define LOG_INFO(M, ...) \
|
|
|
|
fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define LOG_INFO(M, ...)
|
|
|
|
#endif
|
|
|
|
|
2016-09-08 15:28:27 -07:00
|
|
|
#define LOG_ERR(M, ...) \
|
|
|
|
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, \
|
|
|
|
errno == 0 ? "None" : strerror(errno), ##__VA_ARGS__)
|
2016-08-13 17:11:11 -07:00
|
|
|
|
2016-09-13 16:45:44 -07:00
|
|
|
#define PLASMA_CHECK(CONDITION, M, ...) \
|
|
|
|
do { \
|
|
|
|
if (!(CONDITION)) { \
|
|
|
|
fprintf(stderr, "[FATAL] (%s:%d " #CONDITION ") \n" M, __FILE__, \
|
|
|
|
__LINE__); \
|
|
|
|
exit(-1); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2016-08-13 17:11:11 -07:00
|
|
|
typedef struct {
|
2016-09-14 14:20:34 -07:00
|
|
|
int64_t data_size;
|
|
|
|
int64_t metadata_size;
|
2016-08-13 17:11:11 -07:00
|
|
|
int64_t create_time;
|
|
|
|
int64_t construct_duration;
|
|
|
|
} plasma_object_info;
|
|
|
|
|
2016-09-07 20:19:37 -07:00
|
|
|
/* Represents an object id hash, can hold a full SHA1 hash */
|
2016-09-08 15:28:27 -07:00
|
|
|
typedef struct { unsigned char id[20]; } plasma_id;
|
2016-08-13 17:11:11 -07:00
|
|
|
|
|
|
|
enum plasma_request_type {
|
2016-09-07 20:19:37 -07:00
|
|
|
/* Create a new object. */
|
|
|
|
PLASMA_CREATE,
|
|
|
|
/* Get an object. */
|
|
|
|
PLASMA_GET,
|
|
|
|
/* seal an object */
|
|
|
|
PLASMA_SEAL,
|
|
|
|
/* request transfer to another store */
|
|
|
|
PLASMA_TRANSFER,
|
|
|
|
/* Header for sending data */
|
|
|
|
PLASMA_DATA,
|
2016-08-13 17:11:11 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int type;
|
|
|
|
plasma_id object_id;
|
2016-09-14 14:20:34 -07:00
|
|
|
/* The size of the data. */
|
|
|
|
int64_t data_size;
|
|
|
|
/* The size of the metadata. */
|
|
|
|
int64_t metadata_size;
|
2016-08-15 16:41:22 -07:00
|
|
|
uint8_t addr[4];
|
|
|
|
int port;
|
2016-08-13 17:11:11 -07:00
|
|
|
} plasma_request;
|
|
|
|
|
|
|
|
typedef struct {
|
2016-09-14 14:20:34 -07:00
|
|
|
/* The offset in the memory mapped file of the data. */
|
|
|
|
ptrdiff_t data_offset;
|
|
|
|
/* The offset in the memory mapped file of the metadata. */
|
|
|
|
ptrdiff_t metadata_offset;
|
|
|
|
/* The size of the memory mapped file. */
|
2016-09-10 16:39:24 -07:00
|
|
|
int64_t map_size;
|
2016-09-14 14:20:34 -07:00
|
|
|
/* The size of the data. */
|
|
|
|
int64_t data_size;
|
|
|
|
/* The size of the metadata. */
|
|
|
|
int64_t metadata_size;
|
2016-09-15 15:39:33 -07:00
|
|
|
/* Numerical value of the fd of the memory mapped file in the store. */
|
|
|
|
int store_fd_val;
|
2016-08-13 17:11:11 -07:00
|
|
|
} plasma_reply;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
plasma_id object_id;
|
2016-09-14 14:20:34 -07:00
|
|
|
uint8_t *data;
|
|
|
|
int64_t data_size;
|
|
|
|
uint8_t *metadata;
|
|
|
|
int64_t metadata_size;
|
2016-08-13 17:11:11 -07:00
|
|
|
int writable;
|
|
|
|
} plasma_buffer;
|
|
|
|
|
2016-09-15 15:39:33 -07:00
|
|
|
typedef struct {
|
|
|
|
/* Key that uniquely identifies the memory mapped file. In practice, we
|
|
|
|
* take the numerical value of the file descriptor in the object store. */
|
|
|
|
int key;
|
|
|
|
/* The result of mmap for this file descriptor. */
|
|
|
|
uint8_t *pointer;
|
|
|
|
/* Handle for the uthash table. */
|
|
|
|
UT_hash_handle hh;
|
|
|
|
} client_mmap_table_entry;
|
|
|
|
|
|
|
|
/* A client connection with a plasma store */
|
|
|
|
typedef struct {
|
|
|
|
/* File descriptor of the Unix domain socket that connects to the store. */
|
|
|
|
int conn;
|
|
|
|
/* Table of dlmalloc buffer files that have been memory mapped so far. */
|
|
|
|
client_mmap_table_entry *mmap_table;
|
|
|
|
} plasma_store_conn;
|
2016-09-05 15:34:11 -07:00
|
|
|
|
|
|
|
void plasma_send(int conn, plasma_request *req);
|
2016-08-17 12:54:34 -07:00
|
|
|
|
2016-08-13 17:11:11 -07:00
|
|
|
#endif
|