From 124fb0c752530322e6311dde668422afef6b2afe Mon Sep 17 00:00:00 2001 From: "Anand V. Avati" Date: Fri, 3 Apr 2009 15:17:04 +0530 Subject: IOBUF support (to be used by transports and fuse) Signed-off-by: Anand V. Avati --- libglusterfs/src/iobuf.h | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 libglusterfs/src/iobuf.h (limited to 'libglusterfs/src/iobuf.h') diff --git a/libglusterfs/src/iobuf.h b/libglusterfs/src/iobuf.h new file mode 100644 index 000000000..8a854db8f --- /dev/null +++ b/libglusterfs/src/iobuf.h @@ -0,0 +1,97 @@ +/* + Copyright (c) 2009 Z RESEARCH, Inc. + This file is part of GlusterFS. + + GlusterFS 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 3 of the License, + or (at your option) any later version. + + GlusterFS 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, see + . +*/ + +#ifndef _IOBUF_H_ +#define _IOBUF_H_ + +#include "list.h" +#include "common-utils.h" +#include +#include + +/* one allocatable unit for the consumers of the IOBUF API */ +/* each unit hosts @page_size bytes of memory */ +struct iobuf; + +/* one region of memory MMAPed from the operating system */ +/* each region MMAPs @arena_size bytes of memory */ +/* each arena hosts @arena_size / @page_size IOBUFs */ +struct iobuf_arena; + +/* expandable and contractable pool of memory, internally broken into arenas */ +struct iobuf_pool; + + +struct iobuf { + union { + struct list_head list; + struct { + struct iobuf *next; + struct iobuf *prev; + }; + }; + struct iobuf_arena *iobuf_arena; + + gf_lock_t lock; /* for ->ptr and ->ref */ + int ref; /* 0 == passive, >0 == active */ + + void *ptr; /* usable memory region by the consumer */ +}; + + +struct iobuf_arena { + union { + struct list_head list; + struct { + struct iobuf_arena *next; + struct iobuf_arena *prev; + }; + }; + struct iobuf_pool *iobuf_pool; + + void *mem_base; + struct iobuf *iobufs; /* allocated iobufs list */ + + int active_cnt; + struct iobuf active; /* head node iobuf + (unused by itself) */ + int passive_cnt; + struct iobuf passive; /* head node iobuf + (unused by itself) */ +}; + + +struct iobuf_pool { + pthread_mutex_t mutex; + size_t page_size; /* size of all iobufs in this pool */ + size_t arena_size; /* size of memory region in arena */ + + int arena_cnt; + struct iobuf_arena arenas; /* head node arena + (unused by itself) */ +}; + + + + +struct iobuf_pool *iobuf_pool_new (size_t arena_size, size_t page_size); +struct iobuf *iobuf_get (struct iobuf_pool *iobuf_pool); +void iobuf_unref (struct iobuf *iobuf); + +#endif /* !_IOBUF_H_ */ -- cgit