├── .gitignore ├── .gitmodules ├── Config.mk ├── LICENSE ├── Makefile ├── Minicache.mk ├── README.md ├── Target.linux.x86_64.mk ├── Target.minios.arm32.mk ├── Target.minios.x86_64.mk ├── Target.osv.x86_64.mk ├── ctltrigger ├── Makefile ├── README.md ├── ctltrigger.c └── ctltrigger.h ├── debug.c ├── debug.h ├── demofs ├── favicon.ico ├── index.html └── logo.png ├── dlist.h ├── docs └── references │ ├── ctldir.md │ └── shell.md ├── doxygen.conf ├── hash.h ├── hexdump.c ├── hexdump.h ├── htable.c ├── htable.h ├── http.c ├── http.h ├── http_data.h ├── http_defs.h ├── http_fio.c ├── http_fio.h ├── http_hdr.h ├── http_link.c ├── http_link.h ├── http_parser.c ├── http_parser.h ├── likely.h ├── link_format.c ├── link_format.h ├── mempool.c ├── mempool.h ├── minicache.c ├── ring.c ├── ring.h ├── scripts ├── LICENSE ├── README.md ├── add-obj.py ├── get-stats.py ├── m3u8-to-mc.sh ├── mkwebfs └── rm-obj.py ├── shell.c ├── shell.h ├── shell_extras.c ├── shell_extras.h ├── shfs-kmod ├── Kbuild ├── Kconfig ├── README.md ├── blkdev.c ├── dir.c ├── htable.c ├── include │ └── target │ │ ├── blkdev.h │ │ ├── linux_shfs.h │ │ ├── stubs.h │ │ └── sys.h ├── inode.c ├── shfs.c ├── shfs_check.c └── super.c ├── shfs-tools ├── LICENSE ├── Makefile ├── README.md ├── hash.h ├── htable.c ├── htable.h ├── http_parser.c ├── http_parser.h ├── likely.h ├── shfs_admin.c ├── shfs_admin.h ├── shfs_alloc.c ├── shfs_alloc.h ├── shfs_btable.h ├── shfs_check.c ├── shfs_check.h ├── shfs_defs.h ├── shfs_mkfs.c ├── shfs_mkfs.h ├── tools_common.c └── tools_common.h ├── shfs.c ├── shfs.h ├── shfs_btable.h ├── shfs_cache.c ├── shfs_cache.h ├── shfs_check.c ├── shfs_check.h ├── shfs_defs.h ├── shfs_fio.c ├── shfs_fio.h ├── shfs_stats.c ├── shfs_stats.h ├── shfs_stats_data.h ├── shfs_tools.c ├── shfs_tools.h ├── target ├── linux │ ├── blkdev │ │ ├── osv-blk-bio.cc │ │ ├── osv-blk.c │ │ └── paio-blk.c │ ├── include │ │ ├── arch │ │ │ ├── cc.h │ │ │ ├── perf.h │ │ │ └── sys_arch.h │ │ ├── blkdev │ │ │ ├── osv-blk.h │ │ │ └── paio-blk.h │ │ ├── lwipopts.h │ │ ├── netif │ │ │ ├── fifo.h │ │ │ ├── netmapif.h │ │ │ ├── osv-net-io.h │ │ │ ├── osv-net.h │ │ │ ├── pcapif.h │ │ │ ├── sio.h │ │ │ └── tapif.h │ │ ├── private_mib.h │ │ └── target │ │ │ ├── blkdev.h │ │ │ ├── netdev.h │ │ │ └── sys.h │ ├── lwip_prvmib.c │ ├── netif │ │ ├── fifo.c │ │ ├── netmapif.c │ │ ├── osv-net-io.cc │ │ ├── osv-net.c │ │ ├── pcapif.c │ │ ├── sio.c │ │ └── tapif.c │ └── sys_arch.c └── minios │ ├── blkdev.c │ ├── ctldir.c │ └── include │ └── target │ ├── blkdev.h │ ├── ctldir.h │ ├── netdev.h │ └── sys.h ├── testsuite.c └── testsuite.h /.gitignore: -------------------------------------------------------------------------------- 1 | shfs-tools/shfs_mkfs 2 | shfs-tools/shfs_admin 3 | ctltrigger/ctltrigger 4 | .config.mk 5 | build/* 6 | *.bak 7 | *.o 8 | *.a 9 | *.d 10 | *.so 11 | *~ 12 | \#*\# 13 | .\#* 14 | *.swp 15 | minicache 16 | Capstanfile 17 | ,* 18 | .* 19 | shfs-kmod/Module.symvers 20 | shfs-kmod/kmod_shfs.ko 21 | shfs-kmod/kmod_shfs.mod.c 22 | shfs-kmod/modules.order 23 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysml/minicache/4e0a52e14367e560b047f17b752d7bf7f0ab90ac/.gitmodules -------------------------------------------------------------------------------- /Config.mk: -------------------------------------------------------------------------------- 1 | ###################################### 2 | ## General 3 | ###################################### 4 | CONFIG_MINICACHE_HIDE_BANNER ?= n 5 | CONFIG_MINICACHE_AUTOMOUNT ?= y 6 | CONFIG_MINICACHE_MINDER_PRINT ?= n 7 | CONFIG_MINICACHE_TRACE_BOOTTIME ?= y 8 | 9 | ###################################### 10 | ## µSh 11 | ###################################### 12 | CONFIG_SHELL ?= y 13 | CONFIG_SHELL_COLORPROMPT ?= y 14 | 15 | ###################################### 16 | ## SHFS 17 | ###################################### 18 | CONFIG_SHFS_OPENBYNAME ?= y 19 | CONFIG_SHFS_CACHEINFO ?= y 20 | 21 | # Enable statistic capabilities of SHFS 22 | # If this option is disabled, STATS_HTTP is disabled as well 23 | CONFIG_SHFS_STATS ?= y 24 | 25 | # Advanced statistics from HTTP 26 | # This enables counting the number of successful downloads 27 | # (including range requests) and download progress 28 | # counters (see: DPCR) 29 | CONFIG_SHFS_STATS_HTTP ?= y 30 | 31 | # Download progress counters resolution (DPCR) 32 | # e.g., DPCR=6 means 6 counter values: 33 | # VAL1: HTTP request counts that downloaded >= 0% of file 34 | # VAL2: HTTP request counts that downloaded >= 20% of file 35 | # VAL3: HTTP request counts that downloaded >= 40% of file 36 | # VAL4: HTTP request counts that downloaded >= 60% of file 37 | # VAL5: HTTP request counts that downloaded >= 80% of file 38 | # VAL6: HTTP request counts that downloaded = 100% of file 39 | # 40 | # Note: DPCR has to be at least 2 for a 0% and 100% counter 41 | # otherwise this feature is disabled 42 | CONFIG_SHFS_STATS_HTTP_DPCR ?= 6 43 | 44 | ###################################### 45 | ## HTTP 46 | ###################################### 47 | # Enable http-info cmd in shell 48 | CONFIG_HTTP_INFO ?= y 49 | # Consider 50 | CONFIG_HTTP_URL_CUTARGS ?= y 51 | # Provide a performance test file on hash digest 0x0 52 | CONFIG_HTTP_TESTFILE ?= n 53 | 54 | ###################################### 55 | ## ctldir (only available on Mini-OS) 56 | ###################################### 57 | CONFIG_CTLDIR ?= y 58 | CONFIG_CTLDIR_NOCHMOD ?= y 59 | 60 | ###################################### 61 | ## Misc 62 | ###################################### 63 | CONFIG_TESTSUITE ?= n 64 | 65 | ###################################### 66 | ## Debugging options 67 | ###################################### 68 | CONFIG_HTABLE_DEBUG ?= n 69 | CONFIG_MEMPOOL_DEBUG ?= n 70 | CONFIG_SHFS_DEBUG ?= n 71 | CONFIG_SHFS_CACHE_DEBUG ?= n 72 | CONFIG_SHFS_CACHE_DISABLE ?= n 73 | CONFIG_SHFS_CACHE_STATS ?= y 74 | CONFIG_HTTP_DEBUG ?= n 75 | CONFIG_HTTP_DEBUG_SESSIONSTATES ?= n 76 | CONFIG_HTTP_DEBUG_PRINTACCESS ?= n 77 | CONFIG_CTLDIR_DEBUG ?= n 78 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, NEC Europe Ltd., NEC Corporation All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 3. Neither the name of the copyright holder nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | default : all 2 | 3 | .PHONY: doc 4 | doc: 5 | doxygen doxygen.conf 6 | 7 | # default build target 8 | GITSHA1 ?= $(shell git rev-parse --short HEAD || echo "?") 9 | ARCH ?= x86_64 10 | TARGET ?= minios 11 | 12 | # user configuration 13 | ifneq ("$(wildcard .config.mk)","") 14 | include .config.mk 15 | endif 16 | # default configuration 17 | include Config.mk 18 | 19 | # build target specific configuration 20 | include Target.$(TARGET).$(ARCH).mk 21 | -------------------------------------------------------------------------------- /Minicache.mk: -------------------------------------------------------------------------------- 1 | ################### 2 | # General 3 | ################### 4 | MCCFLAGS += -I. 5 | MCCFLAGS += -DCONFIG_BANNER_VERSION="\"MiniCache/$(GITSHA1)/$(ARCH)\"" 6 | MCCFLAGS-$(CONFIG_MINICACHE_HIDE_BANNER) += -DCONFIG_HIDE_BANNER 7 | MCCFLAGS-$(CONFIG_MINICACHE_AUTOMOUNT) += -DCONFIG_AUTOMOUNT 8 | MCCFLAGS-$(CONFIG_MINICACHE_MINDER_PRINT) += -DCONFIG_MINDER_PRINT 9 | MCCFLAGS-$(CONFIG_MINICACHE_DEBUG_PRINT) += -DCONFIG_DEBUG_PRINT 10 | MCCFLAGS-$(CONFIG_MINICACHE_TRACE_BOOTTIME) += -DTRACE_BOOTTIME 11 | 12 | MCOBJS = ring.o \ 13 | mempool.o \ 14 | hexdump.o \ 15 | debug.o \ 16 | htable.o \ 17 | shfs.o \ 18 | shfs_check.o \ 19 | shfs_cache.o \ 20 | shfs_fio.o \ 21 | shfs_tools.o \ 22 | http_parser.o \ 23 | http_fio.o \ 24 | http_link.o \ 25 | http.o \ 26 | link_format.o \ 27 | minicache.o 28 | 29 | MCCFLAGS-$(CONFIG_HTABLE_DEBUG) += -DHTABLE_DEBUG 30 | MCCFLAGS-$(CONFIG_MEMPOOL_DEBUG) += -DMEMPOOL_DEBUG 31 | 32 | 33 | ###################################### 34 | ## µSh 35 | ###################################### 36 | ifeq ($(CONFIG_SHELL),y) 37 | MCCFLAGS += -DSHELL_INFO="\"MiniCache/$(GITSHA1)/$(ARCH) (built: $(shell date +%F))\nCopyright(C) 2013-2020 NEC Laboratories Europe GmbH\"" \ 38 | -DSHELL_WELCOME="\"MiniCache $(GITSHA1)\nCopyright(C) 2013-2020 NEC Laboratories Europe GmbH, NEC Corporation.\n\nType 'help' to get an overview of available commands\"" 39 | 40 | ifeq ($(CONFIG_SHELL_COLORPROMPT),y) 41 | MCCFLAGS += -DSHELL_PROMPT="\"\\e[01;31mmc\\e[00m\#\"" 42 | else 43 | MCCFLAGS += -DSHELL_PROMPT="\"mc\#\"" 44 | endif 45 | 46 | MCOBJS += shell.o shell_extras.o 47 | MCCFLAGS += -DHAVE_SHELL 48 | endif 49 | MCCFLAGS-$(CONFIG_SHELL_DEBUG) += -DSHELL_DEBUG 50 | 51 | ###################################### 52 | ## ctldir (only available on Mini-OS) 53 | ###################################### 54 | ifeq ($(TARGET),minios) 55 | MCCFLAGS-$(CONFIG_CTLDIR) += -DHAVE_CTLDIR 56 | MCCFLAGS-$(CONFIG_CTLDIR_NOCHMOD) += -DCTLDIR_NOCHMOD 57 | MCCFLAGS-$(CONFIG_CTLDIR_DEBUG) += -DCTLDIR_DEBUG 58 | MCOBJS-$(CONFIG_CTLDIR) += target/$(TARGET)/ctldir.o 59 | endif 60 | 61 | ###################################### 62 | ## SHFS 63 | ###################################### 64 | MCCFLAGS-$(CONFIG_SHFS_OPENBYNAME) += -DSHFS_OPENBYNAME 65 | MCCFLAGS-$(CONFIG_SHFS_CACHEINFO) += -DSHFS_CACHE_INFO 66 | MCCFLAGS-$(CONFIG_SHFS_DEBUG) += -DSHFS_DEBUG 67 | MCCFLAGS-$(CONFIG_SHFS_CACHE_DEBUG) += -DSHFS_CACHE_DEBUG 68 | MCCFLAGS-$(CONFIG_SHFS_CACHE_DISABLE) += -DSHFS_CACHE_DISABLE 69 | MCCFLAGS-$(CONFIG_SHFS_CACHE_IMMEDIATEDROP) += -DSHFS_CACHE_IMMEDIATEDROP 70 | MCCFLAGS-$(CONFIG_SHFS_CACHE_STATS) += -DSHFS_CACHE_STATS 71 | ifeq ($(CONFIG_SHFS_STATS),y) 72 | MCCFLAGS += -DSHFS_STATS 73 | MCOBJS += shfs_stats.o 74 | ifeq ($(CONFIG_SHFS_STATS_HTTP),y) 75 | MCCFLAGS += -DSHFS_STATS_HTTP 76 | #ifeq ($(shell echo ${CONFIG_SHFS_STATS_HTTP_DPCR}\>=2 | bc),"1") 77 | MCCFLAGS += -DSHFS_STATS_HTTP_DPC \ 78 | -DSHFS_STATS_HTTP_DPCR=$(CONFIG_SHFS_STATS_HTTP_DPCR) 79 | #endif 80 | endif 81 | endif 82 | 83 | ifneq ($(CONFIG_SHFS_CACHE_READAHEAD),) 84 | CONFIG_SHFS_CACHE_READAHEAD ?= 8 85 | MCCFLAGS += -DSHFS_CACHE_READAHEAD=$(CONFIG_SHFS_CACHE_READAHEAD) 86 | endif 87 | CONFIG_SHFS_CACHE_POOL_NB_BUFFERS ?= 64 88 | MCCFLAGS-$(CONFIG_SHFS_CACHE_POOL_MAXALLOC) += -DSHFS_CACHE_POOL_MAXALLOC 89 | ifneq ($(CONFIG_SHFS_CACHE_POOL_MAXALLOC_THRESHOLD),) 90 | MCCFLAGS-$(CONFIG_SHFS_CACHE_POOL_MAXALLOC) += -DSHFS_CACHE_POOL_MAXALLOC_THRESHOLD=$(CONFIG_SHFS_CACHE_POOL_MAXALLOC_THRESHOLD) 91 | endif 92 | MCCFLAGS += -DSHFS_CACHE_POOL_NB_BUFFERS=$(CONFIG_SHFS_CACHE_POOL_NB_BUFFERS) 93 | MCCFLAGS-$(CONFIG_SHFS_CACHE_GROW) += -DSHFS_CACHE_GROW 94 | ifneq ($(CONFIG_SHFS_CACHE_HTABLE_BUCKETORDER),) 95 | MCCFLAGS += -DSHFS_CACHE_HTABLE_BUCKETORDER=$(CONFIG_SHFS_CACHE_HTABLE_BUCKETORDER) 96 | endif 97 | 98 | ###################################### 99 | ## HTTP 100 | ###################################### 101 | MCCFLAGS += -DHTTP_SERVER_AGENT="\"MiniCache/$(GITSHA1)\"" 102 | MCCFLAGS-$(CONFIG_HTTP_TESTFILES) += -DHTTP_TESTFILES 103 | MCCFLAGS-$(CONFIG_HTTP_INFO) += -DHTTP_INFO 104 | MCCFLAGS-$(CONFIG_HTTP_URL_CUTARGS) += -DHTTP_URL_CUTARGS 105 | MCCFLAGS-$(CONFIG_HTTP_LINK_MEMCPY) += -DHTTP_LINK_MEMCPY 106 | 107 | MCCFLAGS-$(CONFIG_HTTP_DEBUG) += -DHTTP_DEBUG 108 | MCCFLAGS-$(CONFIG_HTTP_DEBUG_SESSIONSTATES) += -DHTTP_DEBUG_SESSIONSTATES 109 | MCCFLAGS-$(CONFIG_HTTP_DEBUG_PRINTACCESS) += -DHTTP_DEBUG_PRINTACCESS 110 | 111 | ###################################### 112 | ## Misc 113 | ###################################### 114 | MCCFLAGS-$(CONFIG_TESTSUITE) += -DTESTSUITE 115 | MCOBJS-$(CONFIG_TESTSUITE) += testsuite.o 116 | 117 | ###################################### 118 | MCOBJS += $(MCOBJS-y) 119 | MCCFLAGS += $(MCCFLAGS-y) 120 | -------------------------------------------------------------------------------- /Target.minios.arm32.mk: -------------------------------------------------------------------------------- 1 | XEN_TARGET_ARCH = $(ARCH) 2 | XEN_COMPILE_ARCH = $(ARCH) 3 | XEN_ROOT ?= $(realpath ../xen) 4 | TOOLCHAIN_ROOT ?= $(realpath ../toolchain) 5 | MINIOS_ROOT ?= $(realpath ../mini-os) 6 | NEWLIB_ROOT ?= $(TOOLCHAIN_ROOT)/$(ARCH)-root/arm-none-eabi 7 | LWIP_ROOT ?= $(TOOLCHAIN_ROOT)/$(ARCH)-root/arm-none-eabi 8 | GCC_VERSION ?= 4.7.2 9 | 10 | # arm32 cross compiler 11 | CCTOOL = arm-linux-gnueabihf 12 | CC = $(CCTOOL)-gcc-$(shell echo ${GCC_VERSION} | cut -d. -f1,2) 13 | AR = $(CCTOOL)-ar 14 | AS = $(CCTOOL)-as 15 | LD = $(CCTOOL)-ld 16 | RANLIB = $(CCTOOL)-ranlib 17 | READELF = $(CCTOOL)-readelf 18 | STRIP = $(CCTOOL)-strip 19 | NM = $(CCTOOL)-nm 20 | OBJCOPY = $(CCTOOL)-objcopy 21 | 22 | verbose ?= 23 | 24 | ###################################### 25 | ## General 26 | ###################################### 27 | CONFIG_BLKFRONT_PERSISTENT_GRANTS ?= y 28 | CONFIG_SHUTDOWN = y 29 | CONFIG_CONSFRONT_SYNC = n 30 | CONFIG_SELECT_POLL ?= y 31 | 32 | CFLAGS += -Wunused \ 33 | -Wparentheses \ 34 | -Wsequence-point \ 35 | -Wswitch-default \ 36 | -Wpointer-arith \ 37 | -Wbad-function-cast \ 38 | -Wwrite-strings \ 39 | -Wold-style-definition \ 40 | -Wredundant-decls \ 41 | -Wno-address \ 42 | -Wtype-limits \ 43 | -Itarget/minios/include 44 | 45 | ###################################### 46 | ## Networking 47 | ###################################### 48 | ## vif 49 | CONFIG_NETFRONT = y 50 | CONFIG_NETFRONT_PERSISTENT_GRANTS ?= y 51 | CONFIG_NETFRONT_GSO ?= y 52 | CONFIG_NETFRONT_POLL = n 53 | CONFIG_NETFRONT_POLLTIMEOUT = 1 54 | CONFIG_NETFRONT_WAITFORTX ?= y 55 | CONFIG_NETFRONT_LWIP_ONLY ?= y 56 | 57 | ## lwip 58 | CONFIG_LWIP = y 59 | CONFIG_LWIP_MINIMAL = y 60 | CONFIG_LWIP_NOTHREADS = y 61 | CONFIG_LWIP_HEAP_ONLY ?= n 62 | CONFIG_LWIP_POOLS_ONLY = n 63 | CONFIG_LWIP_GSO ?= n 64 | CONFIG_LWIP_PARTIAL_CHECKSUM ?= $(CONFIG_NETFRONT_GSO) 65 | CONFIG_START_NETWORK = n 66 | 67 | CONFIG_LWIP_BATCHTX ?= n 68 | CONFIG_LWIP_WND_SCALE ?= y 69 | 70 | ifeq ($(CONFIG_LWIP_NUM_TCPCON),) 71 | CONFIG_LWIP_NUM_TCPCON=128 72 | endif 73 | CFLAGS += -DCONFIG_LWIP_NUM_TCPCON=$(CONFIG_LWIP_NUM_TCPCON) 74 | 75 | ###################################### 76 | ## Debugging 77 | ###################################### 78 | debug ?= n 79 | CONFIG_DEBUG_LWIP ?= n 80 | CONFIG_DEBUG_LWIP_MALLOC ?= n 81 | #CFLAGS += -DLWIP_STATS_DISPLAY=1 82 | #CFLAGS += -DLWIP_IF_DEBUG 83 | #CFLAGS += -DLWIP_TCP_DEBUG 84 | 85 | ###################################### 86 | ## Stub Domain 87 | ###################################### 88 | CONFIG_SHFS_CACHE_READAHEAD ?= 4 89 | CONFIG_SHFS_CACHE_POOL_NB_BUFFERS ?= 64 90 | CONFIG_SHFS_CACHE_GROW ?= y 91 | 92 | include Minicache.mk 93 | 94 | stubdom = y 95 | STUBDOM_NAME = minicache 96 | STUBDOM_ROOT = $(realpath .) 97 | 98 | STUB_APP_OBJS0 = $(MCOBJS) target/$(TARGET)/blkdev.o 99 | STUB_APP_OBJS = $(addprefix $(STUB_APP_OBJ_DIR)/,$(STUB_APP_OBJS0)) 100 | STUB_BUILD_DIRS += $(STUB_APP_OBJ_DIR)/target/$(TARGET) 101 | CFLAGS += $(MCCFLAGS) 102 | 103 | include $(MINIOS_ROOT)/stub.mk 104 | -------------------------------------------------------------------------------- /Target.minios.x86_64.mk: -------------------------------------------------------------------------------- 1 | XEN_TARGET_ARCH ?= $(ARCH) 2 | XEN_COMPILE_ARCH ?= $(ARCH) 3 | XEN_ROOT ?= $(realpath ../xen) 4 | TOOLCHAIN_ROOT ?= $(realpath ../toolchain) 5 | MINIOS_ROOT ?= $(realpath ../mini-os) 6 | NEWLIB_ROOT ?= $(TOOLCHAIN_ROOT)/$(ARCH)-root/x86_64-xen-elf 7 | LWIP_ROOT ?= $(TOOLCHAIN_ROOT)/$(ARCH)-root/x86_64-xen-elf 8 | GCC_VERSION ?= 4.8 9 | verbose ?= 10 | 11 | ###################################### 12 | ## General 13 | ###################################### 14 | CONFIG_BLKFRONT_PERSISTENT_GRANTS ?= y 15 | CONFIG_SHUTDOWN = y 16 | CONFIG_CONSFRONT_SYNC ?= y 17 | CONFIG_SELECT_POLL ?= y 18 | 19 | CFLAGS += -Wunused \ 20 | -Wparentheses \ 21 | -Wsequence-point \ 22 | -Wswitch-default \ 23 | -Wpointer-arith \ 24 | -Wbad-function-cast \ 25 | -Wwrite-strings \ 26 | -Wold-style-definition \ 27 | -Wredundant-decls \ 28 | -Wno-address \ 29 | -Wtype-limits \ 30 | -Itarget/minios/include 31 | 32 | ###################################### 33 | ## Networking 34 | ###################################### 35 | ## vif 36 | CONFIG_NETFRONT = y 37 | CONFIG_NETFRONT_PERSISTENT_GRANTS ?= y 38 | CONFIG_NETFRONT_GSO ?= y 39 | CONFIG_NETFRONT_POLL = n 40 | CONFIG_NETFRONT_POLLTIMEOUT = 1 41 | CONFIG_NETFRONT_WAITFORTX ?= y 42 | CONFIG_NETFRONT_LWIP_ONLY ?= y 43 | 44 | ## lwip 45 | CONFIG_LWIP = y 46 | CONFIG_LWIP_MINIMAL = y 47 | CONFIG_LWIP_NOTHREADS = y 48 | CONFIG_LWIP_HEAP_ONLY ?= n 49 | CONFIG_LWIP_POOLS_ONLY = n 50 | CONFIG_LWIP_GSO ?= n 51 | CONFIG_LWIP_PARTIAL_CHECKSUM ?= $(CONFIG_NETFRONT_GSO) 52 | CONFIG_START_NETWORK = n 53 | 54 | CONFIG_LWIP_BATCHTX ?= n 55 | CONFIG_LWIP_WND_SCALE ?= y 56 | 57 | ifeq ($(CONFIG_LWIP_NUM_TCPCON),) 58 | CONFIG_LWIP_NUM_TCPCON=512 59 | endif 60 | CFLAGS += -DCONFIG_LWIP_NUM_TCPCON=$(CONFIG_LWIP_NUM_TCPCON) 61 | 62 | CFLAGS += -DNETMAP_RXBUSYCOUNT=1000 63 | 64 | ###################################### 65 | ## Debugging 66 | ###################################### 67 | debug ?= n 68 | CONFIG_DEBUG_LWIP ?= n 69 | CONFIG_DEBUG_LWIP_MALLOC ?= n 70 | 71 | # Enables LWIP stats in the shell 72 | #CFLAGS += -DLWIP_STATS_DISPLAY=1 73 | # LWIP debug 74 | #CFLAGS += -DLWIP_IF_DEBUG 75 | #CFLAGS += -DLWIP_TCP_DEBUG 76 | 77 | ###################################### 78 | ## Stub Domain 79 | ###################################### 80 | CONFIG_SHFS_CACHE_READAHEAD ?= 4 81 | CONFIG_SHFS_CACHE_POOL_NB_BUFFERS ?= 64 82 | CONFIG_SHFS_CACHE_GROW ?= y 83 | 84 | include Minicache.mk 85 | 86 | stubdom = y 87 | STUBDOM_NAME = minicache 88 | STUBDOM_ROOT = $(realpath .) 89 | 90 | STUB_APP_OBJS0 = $(MCOBJS) target/$(TARGET)/blkdev.o 91 | STUB_APP_OBJS = $(addprefix $(STUB_APP_OBJ_DIR)/,$(STUB_APP_OBJS0)) 92 | STUB_BUILD_DIRS += $(STUB_APP_OBJ_DIR)/target/$(TARGET) 93 | CFLAGS += $(MCCFLAGS) 94 | 95 | include $(MINIOS_ROOT)/stub.mk 96 | -------------------------------------------------------------------------------- /Target.osv.x86_64.mk: -------------------------------------------------------------------------------- 1 | TARGET=linux 2 | CONFIG_OSVAPP=y 3 | CONFIG_SHELL=n 4 | 5 | CONFIG_SHFS_CACHE_READAHEAD ?= 8 6 | CONFIG_SHFS_CACHE_POOL_NB_BUFFERS ?= 512 7 | CONFIG_SHFS_CACHE_GROW ?= n 8 | CONFIG_BUILD_OPTIMISATION ?= -O3 9 | 10 | CFLAGS+=-DCONFIG_LWIP_CHECKSUM_NOCHECK 11 | 12 | include Target.$(TARGET).$(ARCH).mk 13 | -------------------------------------------------------------------------------- /ctltrigger/Makefile: -------------------------------------------------------------------------------- 1 | RM = rm -f 2 | CC = gcc 3 | LD = gcc 4 | CFLAGS += -O3 -g -Wunused -Wtype-limits 5 | LDFLAGS += 6 | LDLIBS += -lxenstore 7 | 8 | default: all 9 | 10 | %.o: %.c 11 | $(CC) $(CFLAGS) -c $< -o $@ 12 | 13 | %: %.o 14 | $(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@ 15 | 16 | ctltrigger: ctltrigger.o 17 | 18 | all: ctltrigger 19 | 20 | clean: 21 | $(RM) *.o core ctltrigger 22 | -------------------------------------------------------------------------------- /ctltrigger/README.md: -------------------------------------------------------------------------------- 1 | XenStore control dir trigger tool 2 | ================================= 3 | 4 | This tool can be used to trigger XenStore 5 | 6 | Requirements 7 | ------------ 8 | 9 | In order to build the XenStore control dir trigger tool tool, you will need to 10 | have the following shared library installed: 11 | * [libxenstore](http://wiki.xen.org/wiki/XenStoreReference) 12 | 13 | Usually it is installed when you have Xen isntalled but you 14 | can install it manually on Debian/Ubuntu via: 15 | 16 | apt-get install libxenstore 17 | 18 | 19 | Build Instructions 20 | ------------------ 21 | 22 | You build the tool with the following make command: 23 | 24 | make 25 | 26 | 27 | Examples: Using ctltrigger with MiniCache 28 | ----------------------------------------- 29 | 30 | ### Unmount filesystem on MiniCache Dom-U 5 31 | 32 | ctltrigger 5 minicache umount 33 | 34 | ### Mount xvda (VBD ID is 51712) on MiniCache Dom-U 16 35 | 36 | ctltrigger 16 minicache mount 51712 37 | -------------------------------------------------------------------------------- /ctltrigger/ctltrigger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Control Trigger Interface client for XenStore 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _CTLTRIGGER_H_ 36 | #define _CTLTRIGGER_H_ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #define STR_VERSION "XenStore Control Action Trigger v0.01" 45 | 46 | struct args { 47 | unsigned int domid; 48 | char *scope; 49 | char *trigger; 50 | char *args; /* malloc'd */ 51 | int nowait; 52 | }; 53 | 54 | /* 55 | * Print helpers 56 | */ 57 | extern unsigned int verbosity; 58 | extern int force; 59 | 60 | #define eprintf(...) fprintf(stderr, __VA_ARGS__) 61 | #define fatal() eprintf("%s\n", strerror(errno)) 62 | #define dief(...) do { eprintf(__VA_ARGS__); exit(EXIT_FAILURE); } while(0) 63 | #define die() do { fatal(); exit(EXIT_FAILURE); } while(0) 64 | #define dprintf(LEVEL, ...) do { if (verbosity >= (LEVEL)) fprintf(stderr, __VA_ARGS__); } while(0) 65 | #define printvar(VAR, FMT) do { if (verbosity >= (D_MAX)) fprintf(stderr, #VAR ": "#FMT"\n", (VAR)); } while(0) 66 | 67 | #define D_L0 1 68 | #define D_L1 2 69 | #define D_MAX D_L1 70 | 71 | /* 72 | * Argument parsing helper 73 | */ 74 | static inline int parse_args_setval_str(char** out, const char* buf) 75 | { 76 | if (*out) 77 | free(*out); 78 | *out = strdup(buf); 79 | if (!*out) { 80 | *out = NULL; 81 | return -ENOMEM; 82 | } 83 | 84 | return 0; 85 | } 86 | 87 | static inline int parse_args_setval_int(int* out, const char* buf) 88 | { 89 | if (sscanf(optarg, "%d", out) != 1) 90 | return -EINVAL; 91 | return 0; 92 | } 93 | 94 | #endif /* _CTLTRIGGER_H_ */ 95 | -------------------------------------------------------------------------------- /debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniCache Debugging 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #include "debug.h" 37 | 38 | struct timeval __debug_tsref; 39 | -------------------------------------------------------------------------------- /debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniCache Debugging 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _DEBUG_H_ 37 | #define _DEBUG_H_ 38 | 39 | #ifndef __KERNEL__ 40 | #include 41 | #include 42 | #include 43 | #endif 44 | 45 | extern struct timeval __debug_tsref; 46 | 47 | #define init_debug() (gettimeofday(&__debug_tsref, NULL)) 48 | 49 | #ifndef STRINGIFY 50 | #define STRINGIFY(s) #s 51 | #endif 52 | #ifndef XSTRINGIFY 53 | #define XSTRINGIFY(s) STRINGIFY(s) 54 | #endif 55 | 56 | #ifdef ENABLE_DEBUG 57 | #ifdef __MINIOS__ 58 | #if (defined __x86_64__ || defined __x86_32__) 59 | #define CONFIG_DEBUG_CALLDEPTH 60 | #endif 61 | #define __debug_printf(fmt, ...) printk((fmt), ##__VA_ARGS__) 62 | #else 63 | #define __debug_printf(fmt, ...) fprintf(stderr, (fmt), ##__VA_ARGS__) 64 | #endif /* __MINIOS__ */ 65 | 66 | #if defined __MINIOS__ && defined __x86_64__ 67 | #define __get_bp() \ 68 | ({ \ 69 | unsigned long bp; \ 70 | asm("movq %%rbp, %0":"=r"(bp)); \ 71 | bp; \ 72 | }) 73 | #elif defined __MINIOS__ && defined __x86_32__ 74 | #define __get_bp() \ 75 | ({ \ 76 | unsigned long bp; \ 77 | asm("movq %%ebp, %0":"=r"(bp)); \ 78 | bp; \ 79 | }) 80 | #endif 81 | 82 | #if defined __MINIOS__ && (defined __x86_64__ || defined __x86_32__) 83 | /** 84 | * get_caller(): returns calling address for the current function 85 | * 86 | * Note: On non-x86 platforms, 0xBADC0DED is returned 87 | */ 88 | #define get_caller() \ 89 | ({ \ 90 | unsigned long *frame = (void *) __get_bp(); \ 91 | frame[1]; \ 92 | }) 93 | 94 | /** 95 | * get_calldepth(): returns the current number of invoked function calls 96 | * 97 | * Note: On non-x86 platforms, 0x0 is returned always 98 | */ 99 | #define get_calldepth() \ 100 | ({ \ 101 | unsigned long depth = 0; \ 102 | unsigned long *frame = (void *) __get_bp(); \ 103 | while (frame[0]) { \ 104 | ++depth; \ 105 | frame = (void *) frame[0]; \ 106 | } \ 107 | depth; \ 108 | }) 109 | #else 110 | #define get_caller() (0xBADC0DED) 111 | #define get_calldepth() (0x0) 112 | #endif 113 | 114 | /** 115 | * printd(): prints a debug message to stdout 116 | */ 117 | #ifdef CONFIG_DEBUG_CALLDEPTH 118 | #define printd(fmt, ...) \ 119 | do { \ 120 | struct timeval now; \ 121 | uint64_t mins, secs, usecs; \ 122 | unsigned long cd = get_calldepth(); \ 123 | \ 124 | gettimeofday(&now, NULL); \ 125 | if (now.tv_usec < __debug_tsref.tv_usec) { \ 126 | now.tv_usec += 1000000l; \ 127 | now.tv_sec--; \ 128 | } \ 129 | usecs = (now.tv_usec - __debug_tsref.tv_usec); \ 130 | \ 131 | secs = (now.tv_sec - __debug_tsref.tv_sec); \ 132 | secs += usecs / 1000000l; \ 133 | usecs %= 1000000l; \ 134 | mins = secs / 60; \ 135 | secs %= 60; \ 136 | \ 137 | __debug_printf("[%"PRIu64"m%02"PRIu64".%06"PRIu64"s] ", \ 138 | mins, secs, usecs); \ 139 | while (cd--) \ 140 | __debug_printf("-"); \ 141 | __debug_printf(" %s():%d: " \ 142 | fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ 143 | } while(0) 144 | #else 145 | #define printd(fmt, ...) \ 146 | do { \ 147 | struct timeval now; \ 148 | uint64_t mins, secs, usecs; \ 149 | \ 150 | gettimeofday(&now, NULL); \ 151 | if (now.tv_usec < __debug_tsref.tv_usec) { \ 152 | now.tv_usec += 1000000l; \ 153 | now.tv_sec--; \ 154 | } \ 155 | usecs = (now.tv_usec - __debug_tsref.tv_usec); \ 156 | \ 157 | secs = (now.tv_sec - __debug_tsref.tv_sec); \ 158 | secs += usecs / 1000000l; \ 159 | usecs %= 1000000l; \ 160 | mins = secs / 60; \ 161 | secs %= 60; \ 162 | \ 163 | __debug_printf("[%"PRIu64"m%02"PRIu64".%06"PRIu64"s] %s:%4d: %s(): " \ 164 | fmt, mins, secs, usecs, \ 165 | __FILE__, __LINE__, __FUNCTION__, \ 166 | ##__VA_ARGS__); \ 167 | } while(0) 168 | #endif 169 | 170 | #else /* ENABLE_DEBUG */ 171 | 172 | #define printd(fmt, ...) do {} while(0) 173 | #define get_caller() (0xDEADC0DE) 174 | #define get_calldepth() (0x0) 175 | 176 | #endif /* ENABLE_DEBUG */ 177 | 178 | #define tprobe_start(x) \ 179 | uint64_t x; \ 180 | x = target_now_ns(); 181 | #define tprobe_end(x) \ 182 | x = target_now_ns() - x; \ 183 | printk(STRINGIFY(x)": %01"PRIu64".%09"PRIu64"s\n", x / 1000000000ull, x % 1000000000ull); 184 | 185 | #endif /* _DEBUG_H_ */ 186 | -------------------------------------------------------------------------------- /demofs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysml/minicache/4e0a52e14367e560b047f17b752d7bf7f0ab90ac/demofs/favicon.ico -------------------------------------------------------------------------------- /demofs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | MiniCache is ready! 4 | 5 | 6 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 77 | 78 |
MiniCache is ready!

75 | Congratulations, it works!
Your cache node is ready. 76 |
79 | 80 | 81 | -------------------------------------------------------------------------------- /demofs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysml/minicache/4e0a52e14367e560b047f17b752d7bf7f0ab90ac/demofs/logo.png -------------------------------------------------------------------------------- /dlist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Double linked list implementation 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _DLIST_H_ 37 | #define _DLIST_H_ 38 | 39 | #include 40 | #include 41 | #include "likely.h" 42 | 43 | struct dlist_el { 44 | void *next; 45 | void *prev; 46 | }; 47 | #define dlist_el(dlname) \ 48 | struct dlist_el (dlname) 49 | 50 | struct dlist_head { 51 | void *first; 52 | void *last; 53 | }; 54 | #define dlist_head(dlname) \ 55 | struct dlist_head (dlname) 56 | 57 | #define dlist_init_head(head)\ 58 | do { \ 59 | (head).first = NULL; \ 60 | (head).last = NULL; \ 61 | } while (0) 62 | #define dlist_init_el(el, dlname) /* optional as long as */ \ 63 | /* dlist_is_linked() is not used */ \ 64 | do { \ 65 | (el)->dlname.next = NULL; \ 66 | (el)->dlname.prev = NULL; \ 67 | } while (0) 68 | 69 | #define dlist_is_empty(head) \ 70 | ((head).first == NULL) 71 | 72 | #define dlist_next_el(el, dlname) \ 73 | ((typeof((el))) (el)->dlname.next) 74 | #define dlist_prev_el(el, dlname) \ 75 | ((typeof((el))) (el)->dlname.prev) 76 | #define dlist_first_el(head, eltype) \ 77 | ((eltype *) ((head).first)) 78 | #define dlist_last_el(head, eltype) \ 79 | ((eltype *) ((head).last)) 80 | 81 | /* Note: This function only supports checking if an element is linked into 82 | * a specific list. It will fail as soon as the element is linked to a 83 | * different list (with same dlname) than checked against */ 84 | #define dlist_is_linked(el, head, dlname) /* requires dlist_init_el() */ \ 85 | (((el)->dlname.prev != NULL || (el)->dlname.next != NULL) || \ 86 | ((head).first == (el) || (head).last == (el))) 87 | 88 | #define dlist_unlink(el, head, dlname) \ 89 | do { \ 90 | /* element part of this list? (brief check, 91 | * works only if element is at the beginning 92 | * or at the end of the list) */ \ 93 | BUG_ON(!(el)->dlname.prev && (head).first != (el)); \ 94 | BUG_ON(!(el)->dlname.next && (head).last != (el)); \ 95 | \ 96 | if ((el)->dlname.prev) { \ 97 | ((typeof((el))) (el)->dlname.prev)->dlname.next = (el)->dlname.next; \ 98 | } else { \ 99 | (head).first = (el)->dlname.next; \ 100 | } \ 101 | if ((el)->dlname.next) { \ 102 | ((typeof((el))) (el)->dlname.next)->dlname.prev = (el)->dlname.prev; \ 103 | } else { \ 104 | (head).last = (el)->dlname.prev; \ 105 | } \ 106 | dlist_init_el((el), dlname); \ 107 | } while(0) 108 | 109 | #define dlist_foreach(el, head, dlname) \ 110 | for((el) = ((typeof((el))) (head).first); \ 111 | (el) != NULL; \ 112 | (el) = dlist_next_el((el), dlname)) 113 | 114 | #define dlist_foreach_reverse(el, head, dlname) \ 115 | for((el) = ((typeof((el))) (head).last); \ 116 | (el) != NULL; \ 117 | (el) = dlist_prev_el((el), dlname)) 118 | 119 | #define dlist_append(el, head, dlname) \ 120 | do { \ 121 | if (dlist_is_empty((head))) { \ 122 | (head).first = (el); \ 123 | (el)->dlname.prev = NULL; \ 124 | } else { \ 125 | ((typeof((el))) (head).last)->dlname.next = (el); \ 126 | (el)->dlname.prev = (head).last; \ 127 | } \ 128 | (el)->dlname.next = NULL; \ 129 | (head).last = (el); \ 130 | } while(0) 131 | #define dlist_relink_tail(el, head, dlname) \ 132 | do { \ 133 | dlist_unlink((el), (head), dlname); \ 134 | dlist_append((el), (head), dlname); \ 135 | } while(0) 136 | 137 | #define dlist_prepend(el, head, dlname) \ 138 | do { \ 139 | if (dlist_is_empty((head))) { \ 140 | (head).last = (el); \ 141 | (el)->dlname.next = NULL; \ 142 | } else { \ 143 | ((typeof((el))) (head).first)->dlname.prev = (el); \ 144 | (el)->dlname.next = (head).first; \ 145 | } \ 146 | (el)->dlname.prev = NULL; \ 147 | (head).first = (el); \ 148 | } while(0) 149 | #define dlist_relink_head(el, head, dlname) \ 150 | do { \ 151 | dlist_unlink((el), (head), dlname); \ 152 | dlist_prepend((el), (head), dlname); \ 153 | } while(0) 154 | 155 | #endif /* _DLIST_H_ */ 156 | -------------------------------------------------------------------------------- /docs/references/ctldir.md: -------------------------------------------------------------------------------- 1 | MiniCache: XenStore control dir trigger reference 2 | ================================================= 3 | 4 | XenStore control triggers are XenStore interfaces to specific commands. 5 | Their execution can be triggered by using the `ctltrigger` command. 6 | Please refer its help to get an overview of its usage. 7 | 8 | ``` 9 | export-stats 10 | ``` 11 | Exports collected access statistics to the configured stats device. 12 | 13 | ``` 14 | mount [VBD ID]... 15 | ``` 16 | Mounts an SHFS volume. Multiple devices can be passed to the command. 17 | In this case, mount will search for SHFS volumes an all devices 18 | and will mount the first valid one. This is also required when multi-member 19 | volumes shall be mounted. 20 | 21 | ``` 22 | prefetch [FILE] 23 | ``` 24 | Prefetches FILE into the disk block cache. 25 | 26 | ``` 27 | remount 28 | ``` 29 | Re-mounts the currently mounted SHFS volume. 30 | 31 | ``` 32 | umount 33 | ``` 34 | Un-mounts the currently mounted SHFS volume. 35 | 36 | ``` 37 | flush 38 | ``` 39 | Flushes the disk block cache. 40 | -------------------------------------------------------------------------------- /docs/references/shell.md: -------------------------------------------------------------------------------- 1 | MiniCache: µShell command reference 2 | =================================== 3 | 4 | µShell is a telnet server built-into MiniCache. 5 | By using `telnet [IP/DNS of CACHE]`, a shell session is established. 6 | 7 | ``` 8 | cat [FILE]... 9 | ``` 10 | Displays FILE contents. 11 | 12 | ``` 13 | clear 14 | ``` 15 | Clears screen. 16 | 17 | ``` 18 | date 19 | ``` 20 | Displays current system time and date (Note: Times are displayed in UTC/GMT). 21 | 22 | ``` 23 | df [FILE] 24 | ``` 25 | Displays hexdump of FILE contents. 26 | 27 | ``` 28 | echo [[STRING]]... 29 | ``` 30 | Prints arguments. 31 | 32 | ``` 33 | exit 34 | ``` 35 | Closes session. 36 | 37 | ``` 38 | export-stats 39 | ``` 40 | Exports collected access statistics to the configured stats device. 41 | 42 | ``` 43 | file [FILE]... 44 | ``` 45 | Displays MIME-type and size of FILE. 46 | 47 | ``` 48 | flush 49 | ``` 50 | Flushes the disk block cache. 51 | 52 | ``` 53 | free [[-k|-m|-g|-p|-u]] 54 | ``` 55 | Displays current memory usage. 56 | 57 | ``` 58 | halt 59 | ``` 60 | Shutdowns system. 61 | 62 | ``` 63 | help 64 | ``` 65 | Displays command overview. 66 | 67 | ``` 68 | ifconfig 69 | ``` 70 | Lists configured network interfaces and their IP settings. 71 | An asterisk (*) marks the default interface. 72 | 73 | ``` 74 | info 75 | ``` 76 | Displays version. 77 | 78 | ``` 79 | ls 80 | ``` 81 | Lists available files of mounted SHFS volume. 82 | 83 | ``` 84 | lsof 85 | ``` 86 | Lists currently opened files and their reference counters. 87 | 88 | ``` 89 | lsvbd 90 | ``` 91 | Lists available virtual block devices. 92 | 93 | ``` 94 | mallinfo 95 | ``` 96 | Displays heap memory allocation information. 97 | 98 | ``` 99 | mount [VBD ID]... 100 | ``` 101 | Mounts an SHFS volume. Multiple devices can be passed to the command. 102 | In this case, mount will search for SHFS volumes an all devices 103 | and will mount the first valid one. This is also required when multi-member 104 | volumes shall be mounted. 105 | 106 | ``` 107 | prefetch [FILE] 108 | ``` 109 | Prefetches FILE into the disk block cache. 110 | 111 | ``` 112 | reboot 113 | ``` 114 | Reboots system. 115 | 116 | ``` 117 | remount 118 | ``` 119 | Re-mounts the currently mounted SHFS volume. 120 | 121 | ``` 122 | repeat [TIMES] [DELAY] [CLEAR] [COMMAND] [[ARGS]]... 123 | ``` 124 | Executes COMMAND TIMES-times. DELAY specifies a delay in ms between the 125 | executions. If a single COMMAND execution interation returns something less 126 | than 0, repeat exists immediately by returning this error code. 127 | CLEAR specifies after how many command execution the screen shall be cleared. 128 | A CLEAR value of 0 let never clear the screen. 129 | 130 | ``` 131 | shfs-info 132 | ``` 133 | Displays information about currently mounted SHFS volume. 134 | 135 | ``` 136 | stats 137 | ``` 138 | Lists collected access statistics of files. 139 | 140 | ``` 141 | suspend 142 | ``` 143 | Suspends system. 144 | 145 | ``` 146 | time [COMMAND] [[ARGS]]... 147 | ``` 148 | Executes COMMAND while measuring its execution time. 149 | 150 | ``` 151 | umount 152 | ``` 153 | Un-mounts the currently mounted SHFS volume. 154 | 155 | ``` 156 | uptime 157 | ``` 158 | Displays system uptime. 159 | 160 | ``` 161 | who 162 | ``` 163 | Lists active shell sessions. 164 | 165 | ``` 166 | xargs [COMMAND] [[ARGS]]... 167 | ``` 168 | Executes COMMAND for each ARG. 169 | -------------------------------------------------------------------------------- /doxygen.conf: -------------------------------------------------------------------------------- 1 | # This first one is optional 2 | PROJECT_NAME = "MiniCache" 3 | OPTIMIZE_OUTPUT_FOR_C = YES 4 | EXTRACT_ALL = YES 5 | EXTRACT_STATIC = YES 6 | 7 | # Set only the dirs you want 8 | INPUT = ./ 9 | RECURSIVE = YES 10 | SOURCE_BROWSER = YES 11 | HAVE_DOT = YES 12 | 13 | # Set according to your system 14 | DOT_NUM_THREADS = 3 15 | CALL_GRAPH = YES 16 | CALLER_GRAPH = YES 17 | -------------------------------------------------------------------------------- /hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash number data type and handler functions 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _HASH_H_ 36 | #define _HASH_H_ 37 | 38 | #ifndef __KERNEL__ 39 | #include 40 | #endif 41 | 42 | typedef uint8_t hash512_t[64] __attribute__((aligned(8))); 43 | 44 | 45 | static inline void hash_copy(hash512_t dst, const hash512_t src, uint8_t hlen) 46 | { 47 | #ifdef __x86_64 48 | register uint8_t nbleft = hlen & 0x07; /* = mod by 8 */ 49 | register uint64_t mask64; 50 | register uint64_t *p64_dst; 51 | register uint64_t *p64_src; 52 | register uint8_t i; 53 | 54 | hlen -= nbleft; 55 | i = 0; 56 | for (; i < hlen; i += 8) { 57 | p64_dst = (uint64_t *) &dst[i]; 58 | p64_src = (uint64_t *) &src[i]; 59 | *p64_dst = *p64_src; 60 | } 61 | if (nbleft) { 62 | mask64 = ((uint64_t) 1 << (nbleft << 3)) - 1; 63 | p64_dst = (uint64_t *) &dst[i]; 64 | p64_src = (uint64_t *) &src[i]; 65 | *p64_dst = *p64_src & mask64; 66 | } 67 | #else 68 | memcpy(dst, src, hlen); 69 | #endif 70 | } 71 | 72 | static inline int hash_compare(const hash512_t h0, const hash512_t h1, uint8_t hlen) 73 | { 74 | #ifdef __x86_64 75 | register uint8_t nbleft = hlen & 0x07; /* = mod by 8 */ 76 | register uint64_t mask64; 77 | register uint64_t *p64_0; 78 | register uint64_t *p64_1; 79 | register uint8_t i; 80 | 81 | hlen -= nbleft; 82 | i = 0; 83 | for (; i < hlen; i += 8) { 84 | p64_0 = (uint64_t *) &h0[i]; 85 | p64_1 = (uint64_t *) &h1[i]; 86 | if (*p64_0 != *p64_1) 87 | return 1; 88 | } 89 | if (nbleft) { 90 | mask64 = ((uint64_t) 1 << (nbleft << 3)) - 1; 91 | p64_0 = (uint64_t *) &h0[i]; 92 | p64_1 = (uint64_t *) &h1[i]; 93 | if ((*p64_0 & mask64) != (*p64_1 & mask64)) 94 | return 1; 95 | } 96 | 97 | return 0; 98 | #else 99 | return (memcmp(h0, h1, hlen) != 0); 100 | #endif 101 | } 102 | 103 | static inline int hash_is_zero(const hash512_t h, uint8_t hlen) 104 | { 105 | #ifdef __x86_64 106 | register uint8_t nbleft = hlen & 0x07; /* = mod by 8 */ 107 | register uint64_t mask64; 108 | register uint64_t *p64; 109 | register uint8_t i; 110 | 111 | hlen -= nbleft; 112 | i = 0; 113 | for (; i < hlen; i += 8) { 114 | p64 = (uint64_t *) &h[i]; 115 | if (*p64 != 0) 116 | return 0; 117 | } 118 | if (nbleft) { 119 | mask64 = ((uint64_t) 1 << (nbleft << 3)) - 1; 120 | p64 = (uint64_t *) &h[i]; 121 | if ((*p64 & mask64) != 0) 122 | return 0; 123 | } 124 | 125 | return 1; 126 | #else 127 | uint8_t i; 128 | 129 | for (i = 0; i < hlen; ++i) 130 | if (h[i] != 0) 131 | return 0; 132 | return 1; 133 | #endif 134 | } 135 | 136 | static inline int hash_is_max(const hash512_t h, uint8_t hlen) 137 | { 138 | #ifdef __x86_64 139 | register uint8_t nbleft = hlen & 0x07; /* = mod by 8 */ 140 | register uint64_t mask64; 141 | register uint64_t *p64; 142 | register uint8_t i; 143 | 144 | hlen -= nbleft; 145 | i = 0; 146 | for (; i < hlen; i += 8) { 147 | p64 = (uint64_t *) &h[i]; 148 | if (*p64 != UINT64_MAX) 149 | return 0; 150 | } 151 | if (nbleft) { 152 | mask64 = ((uint64_t) 1 << (nbleft << 3)) - 1; 153 | p64 = (uint64_t *) &h[i]; 154 | if ((*p64 & mask64) != mask64) 155 | return 0; 156 | } 157 | 158 | return 1; 159 | #else 160 | uint8_t i; 161 | 162 | for (i = 0; i < hlen; ++i) 163 | if (h[i] != 0xFF) 164 | return 0; 165 | return 1; 166 | #endif 167 | } 168 | 169 | static inline void hash_clear(hash512_t h, uint8_t hlen) 170 | { 171 | #ifdef __x86_64 172 | register uint64_t *p64; 173 | register uint8_t i; 174 | 175 | for (i = 0; i < hlen; i += 8) { 176 | p64 = (uint64_t *) &h[i]; 177 | *p64 = 0; 178 | } 179 | #else 180 | memset(h, 0x00, hlen); 181 | #endif 182 | } 183 | 184 | static inline int hash_parse(const char *in, hash512_t h, uint8_t hlen) 185 | { 186 | uint8_t strlen = hlen * 2; 187 | uint8_t i, nu, nl; 188 | 189 | for (i = 0; i < strlen; ++i) { 190 | /* get upper nibble (4 bits) */ 191 | switch (in[i]) { 192 | case '0' ... '9': 193 | nu = in[i] - '0'; 194 | break; 195 | case 'a' ... 'f': 196 | nu = in[i] - 'a' + 10; 197 | break; 198 | #ifndef SHFS_HASH_PARSE_CASE_SENSITIVE 199 | case 'A' ... 'F': 200 | nu = in[i] - 'A' + 10; 201 | break; 202 | #endif 203 | case '\0': 204 | default: 205 | return -1; /* unknown character or string ended unexpectedly */ 206 | } 207 | 208 | /* get lower nibble (4 bits) */ 209 | ++i; 210 | switch (in[i]) { 211 | case '0' ... '9': 212 | nl = in[i] - '0'; 213 | break; 214 | case 'a' ... 'f': 215 | nl = in[i] - 'a' + 10; 216 | break; 217 | #ifndef SHFS_HASH_PARSE_CASE_SENSITIVE 218 | case 'A' ... 'F': 219 | nl = in[i] - 'A' + 10; 220 | break; 221 | case '\0': 222 | #endif 223 | default: 224 | return -1; 225 | } 226 | 227 | h[i >> 1] = (nu << 4) | nl; 228 | } 229 | 230 | if (in[i] != '\0') 231 | return -1; 232 | 233 | return 0; 234 | } 235 | 236 | #endif /* _HASH_H_ */ 237 | -------------------------------------------------------------------------------- /hexdump.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hexdump-like routines 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _HEXDUMP_H_ 37 | #define _HEXDUMP_H_ 38 | 39 | enum hd_addr_type { 40 | HDAT_NONE = 0, 41 | HDAT_RELATIVE, 42 | HDAT_ABSOLUTE 43 | }; 44 | 45 | /** 46 | * hexdump - print a text hexdump for a binary blob of data 47 | * @buf: data blob to dump 48 | * @len: number of bytes in the @buf 49 | * @prefix_str: null-terminated string that is prefixed to each line 50 | * @addr_type: controls whether the offset address, full address, or none 51 | * is printed in front of each line (%HDAT_RELATIVE, %HDAT_ABSOLUTE, 52 | * %HDAT_NONE) 53 | * @addr_offset: An offset that is added to each printed address if %addr_tpe is 54 | * set to %HDAT_RELATIVE 55 | * @rowlen: number of buffer bytes to print per line 56 | * @groupsize: number of bytes to print as group together 57 | * @show_ascii_comlumn: include ASCII after the hex output 58 | * 59 | * Example output using %HDAT_RELATIVE and 4-byte mode: 60 | * 0009ab42: 40 41 42 43 44 45 46 47 @ABCD EFGH 61 | * Example output using %HDAT_ABSOLUTE and 2-byte mode: 62 | * ffffffff88089af0: 73 72 71 70 77 76 75 74 pq rs tu vw 63 | */ 64 | void hexdump(FILE *cout, const void *buf, size_t len, 65 | const char *prefix_str, enum hd_addr_type addr_type, 66 | off_t addr_offset ,size_t rowsize, size_t groupsize, 67 | int show_ascii_column); 68 | 69 | /** 70 | * printh - shorthand form of print_hex_dump() with default params 71 | * @buf: data blob to dump 72 | * @len: number of bytes in the @buf 73 | * 74 | * Calls hexdump(), with rowsize of 16, groupsize of 4, 75 | * and enabled ASCII column output. 76 | */ 77 | #define printh(buf, len) \ 78 | hexdump((stdout), (buf), (len), "", HDAT_RELATIVE, 0, 16, 4, 1) 79 | 80 | #endif /* _HEXDUMP_H_ */ 81 | -------------------------------------------------------------------------------- /htable.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash table implementation 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * This software is available to you under a choice of one of two 10 | * licenses. You may choose to be licensed under the terms of the GNU 11 | * General Public License (GPL) Version 2, or the BSD license below: 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 3. Neither the name of the copyright holder nor the names of its 23 | * contributors may be used to endorse or promote products derived from 24 | * this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | */ 39 | #if defined(__MINIOS__) 40 | #include 41 | #include 42 | #include 43 | #include 44 | #elif defined(__KERNEL__) 45 | #include 46 | #include 47 | #include 48 | #include 49 | #else 50 | #include 51 | #include 52 | 53 | #define target_free(p) free(p) 54 | #define target_malloc(a, l) malloc(l) 55 | #endif 56 | 57 | #ifndef MIN_ALIGN 58 | #define MIN_ALIGN ((size_t) 8) 59 | #endif 60 | 61 | #include "htable.h" 62 | 63 | #ifndef max 64 | #define max(a, b) \ 65 | ({ __typeof__ (a) __a = (a); \ 66 | __typeof__ (b) __b = (b); \ 67 | __a > __b ? __a : __b; }) 68 | #endif 69 | 70 | static inline size_t align_up(size_t size, size_t align) 71 | { 72 | return (size + align - 1) & ~(align - 1); 73 | } 74 | 75 | struct htable *alloc_htable(uint32_t nb_bkts, uint32_t el_per_bkt, uint8_t hlen, size_t el_private_len, size_t align) 76 | { 77 | size_t ht_size; 78 | size_t bkt_hdr_size; 79 | size_t bkt_size; 80 | size_t el_hdr_size; 81 | size_t el_size; 82 | struct htable *ht; 83 | struct htable_bkt *bkt; 84 | struct htable_el *el; 85 | uint32_t i, j; 86 | 87 | align = max(MIN_ALIGN, align); 88 | 89 | el_hdr_size = align_up(sizeof(struct htable_el), align); 90 | el_size = el_hdr_size + align_up(el_private_len, align); 91 | bkt_hdr_size = align_up(sizeof(struct htable_bkt) 92 | + (sizeof(hash512_t) * el_per_bkt), align); /* hash list */ 93 | bkt_size = bkt_hdr_size 94 | + (el_size * el_per_bkt) /* element list */; 95 | ht_size = sizeof(struct htable) 96 | + sizeof(struct htable_bkt *) * nb_bkts; 97 | 98 | #ifdef HTABLE_DEBUG 99 | printf("el_size = %lu B\n", el_size); 100 | printf("bkt_size = %lu B\n", bkt_size); 101 | printf("ht_size = %lu B\n", ht_size); 102 | #endif 103 | /* allocate main htable struct */ 104 | ht = target_malloc(align, ht_size); 105 | if (!ht) { 106 | errno = ENOMEM; 107 | goto err_out; 108 | } 109 | memset(ht, 0, ht_size); 110 | 111 | #ifdef HTABLE_DEBUG 112 | printf("htable (%lu B) @ %p\n", ht_size); 113 | #endif 114 | ht->nb_bkts = nb_bkts; 115 | ht->el_per_bkt = el_per_bkt; 116 | ht->hlen = hlen; 117 | ht->head = NULL; 118 | ht->tail = NULL; 119 | 120 | /* allocate buckets */ 121 | for (i = 0; i < nb_bkts; ++i) { 122 | bkt = target_malloc(align, bkt_size); 123 | if (!bkt) { 124 | errno = ENOMEM; 125 | goto err_free_bkts; 126 | } 127 | memset(bkt, 0, bkt_size); 128 | 129 | #ifdef HTABLE_DEBUG 130 | printf(" bucket %lu (%lu B) @ %p\n", i, bkt_size, bkt); 131 | #endif 132 | ht->b[i] = bkt; 133 | bkt->el = (void *) (((uint8_t *) ht->b[i]) + bkt_hdr_size); 134 | bkt->el_size = el_size; 135 | bkt->el_private_len = el_private_len; 136 | 137 | for (j = 0; j < el_per_bkt; ++j) { 138 | el = _htable_bkt_el(bkt, j); 139 | el->h = &bkt->h[j]; 140 | el->private = (void *) (((uint8_t *) el) + el_hdr_size); 141 | 142 | #ifdef HTABLE_DEBUG 143 | //printf(" entry %3lu:%02lu (%p): h = @%p; private = @%p\n", 144 | // i, j, el, el->h, el->private); 145 | #endif 146 | } 147 | } 148 | 149 | return ht; 150 | 151 | err_free_bkts: 152 | for (i = 0; i < nb_bkts; ++i) { 153 | if (ht->b[i]) { 154 | target_free(ht->b[i]); 155 | } 156 | } 157 | target_free(ht); 158 | err_out: 159 | return NULL; 160 | } 161 | 162 | void free_htable(struct htable *ht) 163 | { 164 | uint32_t i; 165 | 166 | for (i = 0; i < ht->nb_bkts; ++i) { 167 | if (ht->b[i]) { 168 | target_free(ht->b[i]); 169 | } 170 | } 171 | target_free(ht); 172 | } 173 | -------------------------------------------------------------------------------- /http.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fast HTTP Server Implementation for SHFS volumes 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _HTTP_H_ 37 | #define _HTTP_H_ 38 | 39 | #include 40 | #include 41 | 42 | int init_http(uint16_t nb_sess, uint32_t nb_reqs); 43 | void exit_http(void); 44 | 45 | void http_poll_ioretry(void); 46 | 47 | #ifdef HTTP_INFO 48 | int shcmd_http_info(FILE *cio, int argc, char *argv[]); 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /http_fio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Fast HTTP Server Implementation for SHFS volumes 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #include "http_fio.h" 37 | 38 | void httpreq_fio_aiocb(SHFS_AIO_TOKEN *t, void *cookie, void *argp) 39 | { 40 | struct http_req *hreq = (struct http_req *) cookie; 41 | 42 | printd("Chunk %"PRIchk" loaded (cce: %p, t: %p/%p)\n", hreq->f.cce[hreq->f.cce_idx]->addr, hreq->f.cce[hreq->f.cce_idx], hreq->f.cce_t, t); 43 | 44 | BUG_ON(t != hreq->f.cce_t); 45 | BUG_ON(hreq->state != HRS_RESPONDING_MSG); 46 | 47 | shfs_aio_finalize(t); 48 | hreq->f.cce_t = NULL; 49 | 50 | /* continue sending */ 51 | printd("** [cce] request done, calling httpsess_respond()\n"); 52 | httpsess_respond(hreq->hsess); 53 | } 54 | -------------------------------------------------------------------------------- /likely.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Branching hints 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _LIKELY_H_ 36 | #define _LIKELY_H_ 37 | 38 | #ifndef likely 39 | #define likely(_x) (__builtin_expect((!!(_x)), 1)) 40 | #endif 41 | 42 | #ifndef unlikely 43 | #define unlikely(_x) (__builtin_expect((!!(_x)), 0)) 44 | #endif 45 | 46 | #endif /* _LIKELY_H_ */ 47 | -------------------------------------------------------------------------------- /link_format.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Media stream parser 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #include "link_format.h" 37 | #include "string.h" 38 | 39 | enum lftype mime_to_lftype(const char *mime) { 40 | enum lftype ret; 41 | 42 | /* TODO: returned type is fixed type for now (independent of mime) */ 43 | ret = LFT_RAW512; 44 | 45 | if (strcasecmp("audio/mpeg", mime) == 0 || 46 | strcasecmp("audio/mpeg3", mime) == 0 || 47 | strcasecmp("audio/x-mpeg-3", mime) == 0) { 48 | ret = LFT_MP3; 49 | } 50 | 51 | return ret; 52 | } 53 | 54 | int init_lformat(struct lfstate *lfs, enum lftype type, size_t offset) 55 | { 56 | /* TODO: supported type is fixed for now */ 57 | if (type == LFT_UNKNOWN) 58 | return -EINVAL; 59 | 60 | lfs->type = type; 61 | lfs->pos = offset; 62 | lfs->joins.num = 0; 63 | lfs->joins.head = 0; 64 | return 0; 65 | } 66 | 67 | #define _lformat_add_join(lfs, off) \ 68 | do { \ 69 | if ((lfs)->joins.num) \ 70 | (lfs)->joins.head = ((lfs)->joins.head + 1) % (LF_MAXNB_JOINS); \ 71 | else \ 72 | (lfs)->joins.head = 0; \ 73 | if ((lfs)->joins.num < (LF_MAXNB_JOINS)) \ 74 | ++(lfs)->joins.num; \ 75 | (lfs)->joins.offset[(lfs)->joins.head] = (off); \ 76 | } while(0) 77 | 78 | int lformat_parse(struct lfstate *lfs, const char *b, size_t len) 79 | { 80 | size_t next; 81 | 82 | lfs->pos += len; 83 | 84 | switch(lfs->type) { 85 | case LFT_RAW512: 86 | next = lformat_getrjoin(lfs) + 512; 87 | while (next < lfs->pos) { 88 | _lformat_add_join(lfs, next); 89 | next += 512; 90 | } 91 | break; 92 | 93 | case LFT_MP3: 94 | next = lformat_getrjoin(lfs) + 81920; 95 | while (next < lfs->pos) { 96 | _lformat_add_join(lfs, next); 97 | next += 81920; 98 | } 99 | break; 100 | 101 | default: /* unsupported type */ 102 | break; 103 | } 104 | 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /link_format.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Media stream parser 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _LINK_FORMAT_H_ 37 | #define _LINK_FORMAT_H_ 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #define LF_MAXNB_JOINS 2 /* keep two recent join offsets */ 44 | 45 | enum lftype { 46 | LFT_UNKNOWN = 0, 47 | LFT_RAW512, /* 512B */ 48 | LFT_MP3, /* 80KB */ 49 | }; 50 | 51 | struct lfstate { 52 | enum lftype type; 53 | 54 | /* state of parser */ 55 | size_t offset; 56 | size_t pos; 57 | 58 | /* list of n recent join points */ 59 | struct { 60 | size_t offset[LF_MAXNB_JOINS]; 61 | unsigned int head; 62 | unsigned int num; 63 | } joins; 64 | }; 65 | 66 | enum lftype mime_to_lftype(const char *mime); 67 | int init_lformat(struct lfstate *lfs, enum lftype type, size_t offset); 68 | int lformat_parse(struct lfstate *lfs, const char *b, size_t len); 69 | 70 | static inline size_t lformat_getjoin(struct lfstate *lfs, unsigned idx) 71 | { 72 | unsigned int p; 73 | 74 | /* index is outside of parser window? 75 | * -> return initial offset */ 76 | if (idx > lfs->joins.num) 77 | return lfs->offset; 78 | 79 | p = (idx > lfs->joins.head) ? 80 | (LF_MAXNB_JOINS - (idx - lfs->joins.head)) : 81 | lfs->joins.head - idx; 82 | return lfs->joins.offset[p]; 83 | } 84 | /* most recent join */ 85 | #define lformat_getrjoin(lfs) \ 86 | lformat_getjoin((lfs), 0) 87 | /* oldest join in parser window */ 88 | #define lformat_getojoin(lfs) \ 89 | lformat_getjoin((lfs), ((lfs)->num ? ((lfs)->num - 1) : 0)) 90 | 91 | #endif /* _LINK_FORMAT_H_ */ 92 | -------------------------------------------------------------------------------- /ring.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple ring implementation to handle object references. 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | /* 36 | * Parts of this code is derived/copied from FreeBSD's buf_ring.h: 37 | * 38 | * Copyright (c) 2007,2008 Kip Macy kmacy@freebsd.org 39 | * All rights reserved. 40 | * 41 | * Redistribution and use in source and binary forms, with or without 42 | * modification, are permitted provided that the following conditions are met: 43 | * 44 | * 1. Redistributions of source code must retain the above copyright notice, 45 | * this list of conditions and the following disclaimer. 46 | * 47 | * 2. The name of Kip Macy nor the names of other 48 | * contributors may be used to endorse or promote products derived from 49 | * this software without specific prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 52 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 55 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 56 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 57 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 58 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 59 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 60 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 61 | * POSSIBILITY OF SUCH DAMAGE. 62 | * 63 | */ 64 | /* Note: This implementation is thread-safe but not SMP-safe. */ 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | #define MIN_ALIGN 8 71 | #define CACHELINE_SIZE 64 72 | 73 | #ifndef POWER_OF_2 74 | #define POWER_OF_2(x) (((x)) && (!((x) & ((x) - 1)))) 75 | #endif 76 | 77 | #ifndef ALIGN_UP 78 | #define ALIGN_UP(x, a) (((x) + (a) - 1) & ~((a) - 1)) 79 | #endif 80 | 81 | struct ring *alloc_ring(uint32_t size) 82 | { 83 | struct ring *r; 84 | size_t h_size = ALIGN_UP(sizeof(struct ring), MIN_ALIGN); 85 | 86 | ASSERT(size > 0 && POWER_OF_2(size)); 87 | 88 | r = target_malloc(CACHELINE_SIZE, h_size + (sizeof(void *) * size)); 89 | if (!r) { 90 | errno = ENOMEM; 91 | return NULL; 92 | } 93 | r->size = size; 94 | r->mask = size - 1; 95 | r->enq_idx = 0; 96 | r->deq_idx = 0; 97 | r->ring = (void **) ((uintptr_t) r + h_size); 98 | return r; 99 | } 100 | 101 | void free_ring(struct ring *r) 102 | { 103 | target_free(r); 104 | } 105 | -------------------------------------------------------------------------------- /scripts/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, NEC Europe Ltd., NEC Corporation All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 3. Neither the name of the copyright holder nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | MiniCache Scripts 2 | ================= 3 | This directory contains a collection of various scripts 4 | to be used with MiniCache. 5 | 6 | Requirements 7 | ------------ 8 | Please ensure that you compiled MiniCache and 9 | the following tools: 10 | * shfs-tools 11 | * ctltrigger 12 | 13 | Scripts 14 | ------- 15 | ### Online SHFS modification 16 | Enables you to change the content of an mounted SHFS 17 | object store (by MiniCache on Xen). The scripts modify 18 | the volume with ```shfs_admin``` and use ```ctltrigger``` 19 | to issue a remount. 20 | * ```add-obj.py``` 21 | * ```rm-obj.py``` 22 | 23 | ### Cache node statistic retrievel 24 | Issues a command to MiniCache on Xen by using ```ctltrigger``` 25 | to write the current statistics to a defined block device. 26 | The script reads the contents from the device and prints it 27 | to stdout. 28 | * ```get-stats.py``` 29 | 30 | ### SHFS filesystem creation 31 | Automatically creates an SHFS filesystem image for a a given 32 | directory. All files, including from subdirectories, are 33 | included to the image. 34 | * ```mkwebfs``` 35 | -------------------------------------------------------------------------------- /scripts/get-stats.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # 4 | # MiniCache Tools 5 | # 6 | # Authors: Simon Kuenzer 7 | # 8 | # 9 | # Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 10 | # 11 | # Redistribution and use in source and binary forms, with or without 12 | # modification, are permitted provided that the following conditions 13 | # are met: 14 | # 15 | # 1. Redistributions of source code must retain the above copyright 16 | # notice, this list of conditions and the following disclaimer. 17 | # 2. Redistributions in binary form must reproduce the above copyright 18 | # notice, this list of conditions and the following disclaimer in the 19 | # documentation and/or other materials provided with the distribution. 20 | # 3. Neither the name of the copyright holder nor the names of its 21 | # contributors may be used to endorse or promote products derived from 22 | # this software without specific prior written permission. 23 | # 24 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 28 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | # POSSIBILITY OF SUCH DAMAGE. 35 | # 36 | # 37 | 38 | import os 39 | import sys 40 | import stat 41 | import fcntl 42 | import subprocess 43 | 44 | CMDA_CTLTRIGGER="ctltrigger" # expected to be in $PATH 45 | CMDB_CTLTRIGGER="../ctltrigger/ctltrigger" # alternatively 46 | BLKFLSBUF = 0x00001261 # from 47 | BYTESPERREAD = 512 48 | 49 | def ctltrigger(domid, action, args=[], scope="minicache"): 50 | pargs = [CMDA_CTLTRIGGER, domid, scope, action] 51 | pargs.extend(args) 52 | try: 53 | p = subprocess.Popen(pargs, stdin=subprocess.PIPE, stdout=subprocess.PIPE) 54 | except OSError as e: 55 | if e.errno == os.errno.ENOENT: 56 | try: 57 | # try again with CMDB 58 | pargs = [CMDB_CTLTRIGGER, domid, scope, "--", action] 59 | pargs.extend(args) 60 | p = subprocess.Popen(pargs, stdin=subprocess.PIPE, stdout=subprocess.PIPE) 61 | except OSError as e: 62 | sys.stderr.write("Could not execute '%s': %s\n" % (CMDB_CTLTRIGGER, e.strerror)) 63 | exit(1) 64 | else: 65 | sys.stderr.write("Could not execute '%s': %s\n" % (CMDA_CTLTRIGGER, e.strerror)) 66 | exit(1) 67 | (pout, perr) = p.communicate("") 68 | prc = p.returncode 69 | if prc != 0: 70 | return(1) 71 | return(int(pout)) 72 | 73 | def usage(): 74 | sys.stderr.write("Usage: %s [DOMID] [STATSDEV]\n" % sys.argv[0]) 75 | exit(1) 76 | 77 | ##--------------------------------------------------------------- 78 | ## MAIN 79 | ##--------------------------------------------------------------- 80 | 81 | # check arguments 82 | if len(sys.argv) < 3: 83 | usage() 84 | 85 | # try to open device 86 | try: 87 | sdev = os.open(sys.argv[2], os.O_RDONLY) 88 | except (OSError, IOError) as e: 89 | sys.stderr.write("Could not open '%s': %s\n" % (sys.argv[2], e.strerror)) 90 | usage() 91 | 92 | # ensure that sdev is a file or block device 93 | sdev_info = os.fstat(sdev) 94 | sdev_isblk = stat.S_ISBLK(sdev_info.st_mode) 95 | if not sdev_isblk and not stat.S_ISREG(sdev_info.st_mode): 96 | sys.stderr.write("Could not open '%s': %s\n" % (sys.argv[2], "Is not a regular file or block device")) 97 | usage() 98 | 99 | # trigger stats export 100 | rc = ctltrigger(domid=sys.argv[1], action="export-stats") 101 | if rc != 0: 102 | sys.stderr.write("Could not trigger action 'export-stats' on Domain %s\n" % sys.argv[1]) 103 | exit(1) 104 | 105 | # discard OS's buffer caches for block devices 106 | if sdev_isblk: 107 | try: 108 | #fcntl.ioctl(sdev, BLKFLSBUF, 0) 109 | open('/proc/sys/vm/drop_caches','w').write("1\n") 110 | except (OSError, IOError) as e: 111 | sys.stderr.write("Could not reset cache for '%s': %s\n" % (sys.argv[2], e.strerror)) 112 | exit(1) 113 | 114 | # read sdev content and print it to stdout 115 | # (read until '\0') 116 | try: 117 | while True: 118 | blen = BYTESPERREAD 119 | buf = os.read(sdev, BYTESPERREAD) 120 | blen = len(buf) 121 | for i, c in enumerate(buf): 122 | if c[0] == '\0': 123 | blen = i 124 | break 125 | sys.stdout.write(buf[:blen]) 126 | if blen < BYTESPERREAD: 127 | break 128 | except (OSError, IOError) as e: 129 | sys.stderr.write("Read error on '%s': %s\n" % (sys.argv[2], e.strerror)) 130 | sys.stderr.write("Statistics are most likely incomplete\n") 131 | 132 | # exit 133 | os.close(sdev) 134 | exit(0) 135 | -------------------------------------------------------------------------------- /scripts/m3u8-to-mc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # MiniCache Tools 5 | # 6 | # Authors: Simon Kuenzer 7 | # 8 | # 9 | # Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 10 | # 11 | # Redistribution and use in source and binary forms, with or without 12 | # modification, are permitted provided that the following conditions 13 | # are met: 14 | # 15 | # 1. Redistributions of source code must retain the above copyright 16 | # notice, this list of conditions and the following disclaimer. 17 | # 2. Redistributions in binary form must reproduce the above copyright 18 | # notice, this list of conditions and the following disclaimer in the 19 | # documentation and/or other materials provided with the distribution. 20 | # 3. Neither the name of the copyright holder nor the names of its 21 | # contributors may be used to endorse or promote products derived from 22 | # this software without specific prior written permission. 23 | # 24 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 28 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | # POSSIBILITY OF SUCH DAMAGE. 35 | # 36 | # 37 | 38 | NL=$'\n' 39 | IFS_ORIG=$IFS 40 | HASH_INDICATOR_PREFIX='?' 41 | 42 | function err() 43 | { 44 | echo "$@" 1>&2 45 | } 46 | 47 | function gethash_file() 48 | { 49 | local H 50 | H=$( "$HASH" "$1" ) 51 | if [ $? -ne 0 ]; then 52 | err "Could not calculate hash dighest for '$1'" 53 | fi 54 | 55 | printf "%s" "$H" | cut -d' ' -f1 56 | } 57 | 58 | function gethash_text() 59 | { 60 | printf "%s" "$1" | "$HASH" - | cut -d' ' -f1 61 | } 62 | 63 | IN="$1" 64 | INDIR=$( dirname "$IN" ) 65 | if [ ! -f "$IN" ]; then 66 | err "Usage: $0 [M3U8] [[HASH]]" 67 | exit 1 68 | fi 69 | HASH="$2" 70 | if [ -z "$HASH" ]; then 71 | HASH="sha256sum" 72 | fi 73 | 74 | PL=$( cat "$IN" ) 75 | IFS=$NL 76 | for L in $PL 77 | do 78 | IFS=$IFS_ORIG 79 | 80 | printf "%s" "$L" | grep -qe '^#.*' 81 | if [ $? -eq 0 ]; then 82 | # CONTROL LINE 83 | # copy 84 | printf "%s%s" "$L" "$NL" 85 | else 86 | # FILE 87 | if [ ! -f "${INDIR}/${L}" ]; then 88 | err "Could not find '${INDIR}/${L}'" 89 | exit 1 90 | fi 91 | H=$( gethash_file "${INDIR}/${L}" ) 92 | 93 | # replace entry with hash digest 94 | printf "%s%s%s" "$HASH_INDICATOR_PREFIX" "$H" "$NL" 95 | fi 96 | 97 | IFS=$NL 98 | done 99 | IFS=$IFS_ORIG 100 | exit 0 101 | -------------------------------------------------------------------------------- /scripts/rm-obj.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # 4 | # MiniCache Tools 5 | # 6 | # Authors: Simon Kuenzer 7 | # 8 | # 9 | # Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 10 | # 11 | # Redistribution and use in source and binary forms, with or without 12 | # modification, are permitted provided that the following conditions 13 | # are met: 14 | # 15 | # 1. Redistributions of source code must retain the above copyright 16 | # notice, this list of conditions and the following disclaimer. 17 | # 2. Redistributions in binary form must reproduce the above copyright 18 | # notice, this list of conditions and the following disclaimer in the 19 | # documentation and/or other materials provided with the distribution. 20 | # 3. Neither the name of the copyright holder nor the names of its 21 | # contributors may be used to endorse or promote products derived from 22 | # this software without specific prior written permission. 23 | # 24 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 28 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | # POSSIBILITY OF SUCH DAMAGE. 35 | # 36 | # 37 | 38 | import os 39 | import sys 40 | import getopt 41 | import subprocess 42 | 43 | CMDA_SHFSADMIN="shfs_admin" # expected to be in $PATH 44 | CMDB_SHFSADMIN="../shfs-tools/shfs_admin" # alternatively 45 | CMDA_CTLTRIGGER="ctltrigger" # expected to be in $PATH 46 | CMDB_CTLTRIGGER="../ctltrigger/ctltrigger" # alternatively 47 | 48 | def shfsadmin(args=[]): 49 | pargs = [CMDA_SHFSADMIN, '-v', '-f'] 50 | pargs.extend(args) 51 | try: 52 | p = subprocess.Popen(pargs, stdin=subprocess.PIPE) 53 | except OSError as e: 54 | if e.errno == os.errno.ENOENT: 55 | try: 56 | # try again with CMDB 57 | pargs = [CMDB_SHFSADMIN, '-v', '-f'] 58 | pargs.extend(args) 59 | p = subprocess.Popen(pargs, stdin=subprocess.PIPE) 60 | except OSError as e: 61 | sys.stderr.write("Could not execute '%s': %s\n" % (CMDB_SHFSADMIN, e.strerror)) 62 | exit(1) 63 | else: 64 | sys.stderr.write("Could not execute '%s': %s\n" % (CMDA_SHFSADMIN, e.strerror)) 65 | exit(1) 66 | perr = p.communicate("") 67 | prc = p.returncode 68 | return(prc) 69 | 70 | def ctltrigger(domid, action, args=[], scope="minicache"): 71 | pargs = [CMDA_CTLTRIGGER, domid, scope, action] 72 | pargs.extend(args) 73 | try: 74 | p = subprocess.Popen(pargs, stdin=subprocess.PIPE, stdout=subprocess.PIPE) 75 | except OSError as e: 76 | if e.errno == os.errno.ENOENT: 77 | try: 78 | # try again with CMDB 79 | pargs = [CMDB_CTLTRIGGER, domid, scope, "--", action] 80 | pargs.extend(args) 81 | p = subprocess.Popen(pargs, stdin=subprocess.PIPE, stdout=subprocess.PIPE) 82 | except OSError as e: 83 | sys.stderr.write("Could not execute '%s': %s\n" % (CMDB_CTLTRIGGER, e.strerror)) 84 | exit(1) 85 | else: 86 | sys.stderr.write("Could not execute '%s': %s\n" % (CMDA_CTLTRIGGER, e.strerror)) 87 | exit(1) 88 | (pout, perr) = p.communicate("") 89 | prc = p.returncode 90 | if prc != 0: 91 | return(1) 92 | return(int(pout)) 93 | 94 | def usage(): 95 | sys.stderr.write("Usage: %s [OPTION]... [DEVICE]...\n" % sys.argv[0]) 96 | sys.stderr.write(" -d, --dom [DOMID] triggers remount on Domain DOMID after completion\n"); 97 | sys.stderr.write(" -r, --rm-obj [HASH] removes an object from the volume\n"); 98 | exit(1) 99 | 100 | ##--------------------------------------------------------------- 101 | ## MAIN 102 | ##--------------------------------------------------------------- 103 | 104 | # check arguments 105 | try: 106 | opts, rem_args = getopt.getopt(sys.argv[1:], "d:r:h", ["dom=", "rm-obj=", "help"]) 107 | except getopt.GetoptError as err: 108 | sys.stderr.write(str(err)) 109 | usage() 110 | 111 | dom = [] 112 | rm = [] 113 | for o, a in opts: 114 | if o in ("-d", "--dom"): 115 | try: 116 | if int(a) <= 0: 117 | sys.stderr.write("'%s' is an invalid domain ID\n" % a) 118 | exit(1) 119 | dom.append(str(int(a))) 120 | except ValueError as e: 121 | sys.stderr.write("'%s' is an invalid domain ID\n" % a) 122 | exit(1) 123 | elif o in ("-r", "--rm-obj"): 124 | rm.append(a) 125 | elif o in ("-h", "--help"): 126 | usage() 127 | exit(0) 128 | else: 129 | sys.stderr.write("Unrecognized option: %s\n", o) 130 | usage() 131 | exit(1) 132 | 133 | if len(sys.argv) < 3: 134 | usage() 135 | 136 | # run shfs_admin 137 | args = [] 138 | for r in rm: 139 | args.extend(['-r', r]) 140 | args.extend(rem_args) 141 | shfsadmin(args=args) 142 | 143 | # trigger remount 144 | # TODO: parallelize triggering remount/update 145 | for d in dom: 146 | sys.stdout.write("Trigger action 'remount' on Domain %s\n" % d) 147 | rc = ctltrigger(domid=d, action="remount") 148 | if rc != 0: 149 | sys.stderr.write("Could not trigger action 'remount' on Domain %s\n" % d) 150 | 151 | # exit 152 | exit(0) 153 | -------------------------------------------------------------------------------- /shell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MicroShell (µSh) 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _SHELL_H_ 37 | #define _SHELL_H_ 38 | 39 | #include 40 | #include 41 | 42 | typedef int (*shfunc_ptr_t)(FILE *cio, int argc, char *argv[]); 43 | 44 | #define SH_CLOSE INT_MAX 45 | 46 | int init_shell(unsigned int en_lsess, unsigned int nb_rsess); 47 | void exit_shell(void); 48 | 49 | int shell_register_cmd(const char *cmd, shfunc_ptr_t func); 50 | void shell_unregister_cmd(const char *cmd); 51 | 52 | #endif /* _SHELL_H_ */ 53 | -------------------------------------------------------------------------------- /shell_extras.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MicroShell (µSh) 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _SHELL_EXTRAS_H_ 37 | #define _SHELL_EXTRAS_H_ 38 | 39 | #ifdef HAVE_CTLDIR 40 | #include 41 | #endif 42 | 43 | /** 44 | * Registers shfs tools to micro shell + ctldir (if *cd is not NULL) 45 | */ 46 | #ifdef HAVE_CTLDIR 47 | int register_shell_extras(struct ctldir *cd); 48 | #else 49 | int register_shell_extras(void); 50 | #endif 51 | 52 | #endif /* _SHELL_EXTRAS_H_ */ 53 | -------------------------------------------------------------------------------- /shfs-kmod/Kbuild: -------------------------------------------------------------------------------- 1 | ccflags-y := -I$(src)/include 2 | ccflags-y += -I$(realpath $(src)/../) 3 | ccflags-y += -DSHFS_HASH_PARSE_CASE_SENSITIVE 4 | 5 | obj-m := kmod_shfs.o 6 | kmod_shfs-y := super.o dir.o blkdev.o inode.o shfs.o shfs_check.o htable.o 7 | -------------------------------------------------------------------------------- /shfs-kmod/Kconfig: -------------------------------------------------------------------------------- 1 | config SHFS_FS 2 | bool "Simon's HashFS" 3 | help 4 | If unsure, say N. 5 | -------------------------------------------------------------------------------- /shfs-kmod/README.md: -------------------------------------------------------------------------------- 1 | # SHFS linux port 2 | 3 | This is a port of the "Simple Hash File System" to linux kernel 3.16. 4 | 5 | SHFS is experimental, so it is highly recommended to run it inside an 6 | isolated sandbox environment such as a virtual machine or dedicated 7 | test computer. 8 | For now, only a single volume can be mounted. 9 | 10 | To build the module run: 11 | ``` 12 | # cd shfs-kmod 13 | # make -C M=$PWD 14 | ``` 15 | 16 | When mounted, filesystem shows two folders under the root directory: 17 | "hashes" and "names". The latter one contains the symbolic links to 18 | the files inside the first one: 19 | ``` 20 | # ls /mnt/names -la 21 | total 0 22 | drwxrwxrwx 1 root root 1 Jan 1 1970 . 23 | drwxrwxrwx 1 root root 1 Jan 1 1970 .. 24 | lr--r--r-- 1 root root 1 Jan 1 1970 bigrnd -> ../hashes/a478133e09e414c3a7e680fe574338864db548adc371c55616c4c79edf016c52 25 | ``` 26 | -------------------------------------------------------------------------------- /shfs-kmod/blkdev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Block device abstraction level for SHFS 3 | * 4 | * Authors: Yuri Volchkov 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * This software is available to you under a choice of one of two 10 | * licenses. You may choose to be licensed under the terms of the GNU 11 | * General Public License (GPL) Version 2, or the BSD license below: 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 3. Neither the name of the copyright holder nor the names of its 23 | * contributors may be used to endorse or promote products derived from 24 | * this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | */ 39 | 40 | #include "shfs.h" 41 | #include 42 | 43 | static inline int read_one_page(struct shfs_sb_info *sbi, sector_t start, char *buffer) 44 | { 45 | struct address_space *mapping = sbi->sb->s_bdev->bd_inode->i_mapping; 46 | struct page *page; 47 | int ret = 0; 48 | 49 | page = read_mapping_page(mapping, start, NULL); 50 | 51 | if (IS_ERR(page)) 52 | return -1; 53 | if (PageError(page)) { 54 | ret = -1; 55 | goto out; 56 | } 57 | memcpy(buffer, page_address(page), PAGE_CACHE_SIZE); 58 | 59 | out: 60 | page_cache_release(page); 61 | 62 | return ret; 63 | } 64 | 65 | int blkdev_sync_read(struct shfs_sb_info *sbi, sector_t start, size_t len, char *buffer) 66 | { 67 | int i; 68 | int ret; 69 | 70 | for (i = 0; i < len; i++) { 71 | ret = read_one_page(sbi, start + i, 72 | buffer + ((sector_t) i << PAGE_CACHE_SHIFT)); 73 | if (ret) 74 | return ret; 75 | } 76 | 77 | return 0; 78 | } 79 | 80 | int blkdev_async_io(struct blkdev *bd, sector_t start, sector_t len, 81 | int write, void *buffer, blkdev_aiocb_t *cb, void *cb_argp) 82 | { 83 | SHFS_AIO_TOKEN *t = cb_argp; 84 | BUG_ON(write); 85 | 86 | if (t->cb) { 87 | t->infly = 0; 88 | t->cb(t, t->cb_cookie, t->cb_argp); 89 | } 90 | return blkdev_sync_read(bd, start, len, buffer); 91 | } 92 | -------------------------------------------------------------------------------- /shfs-kmod/htable.c: -------------------------------------------------------------------------------- 1 | ../htable.c -------------------------------------------------------------------------------- /shfs-kmod/include/target/linux_shfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SHFS linux definitions 3 | * 4 | * Authors: Yuri Volchkov 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved 8 | * 9 | * This software is available to you under a choice of one of two 10 | * licenses. You may choose to be licensed under the terms of the GNU 11 | * General Public License (GPL) Version 2, or the BSD license below: 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 3. Neither the name of the copyright holder nor the names of its 23 | * contributors may be used to endorse or promote products derived from 24 | * this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | */ 39 | 40 | #ifndef _LINUX_SHFS_H 41 | #define _LINUX_SHFS_H 42 | #include 43 | 44 | struct shfs_sb_info { 45 | struct super_block *sb; 46 | size_t size; 47 | int chunk_size_shift; 48 | }; 49 | 50 | struct inode *shfs_get_root_inode(struct shfs_sb_info *sbi); 51 | 52 | extern const struct file_operations shfs_dir_operations; 53 | extern const struct inode_operations shfs_dir_inode_operations; 54 | extern const struct address_space_operations shfs_aops; 55 | 56 | 57 | #define SHFS_SIMLINK_INODE_N(file_inode_n) (file_inode_n + \ 58 | shfs_vol.htable_nb_entries + \ 59 | LINUX_FIRST_INO_N) 60 | 61 | struct shfs_inode_info { 62 | struct inode vfs_inode; 63 | struct shfs_bentry *bentry; 64 | sector_t start_block; 65 | }; 66 | 67 | static inline struct shfs_inode_info *SHFS_I(struct inode *inode) 68 | { 69 | return container_of(inode, struct shfs_inode_info, vfs_inode); 70 | } 71 | 72 | static inline struct shfs_sb_info *SHFS_SB(struct super_block *sb) 73 | { 74 | return sb->s_fs_info; 75 | } 76 | 77 | #define CHUNK_SIZE_MASK(sbi) ((1 << sbi->chunk_size_shift) - 1) 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /shfs-kmod/include/target/stubs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SHFS stubs disabling unneeded minicache functionality 3 | * 4 | * Authors: Yuri Volchkov 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved 8 | * 9 | * This software is available to you under a choice of one of two 10 | * licenses. You may choose to be licensed under the terms of the GNU 11 | * General Public License (GPL) Version 2, or the BSD license below: 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 3. Neither the name of the copyright holder nor the names of its 23 | * contributors may be used to endorse or promote products derived from 24 | * this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | */ 39 | 40 | #ifndef SHFS_STUBS_H 41 | #define SHFS_STUBS_H 42 | 43 | #include 44 | 45 | typedef int sem_t; 46 | 47 | 48 | struct mempool { 49 | int a; 50 | }; 51 | static inline struct mempool_obj *mempool_pick(struct mempool *p) 52 | { BUG(); } 53 | 54 | struct mempool_obj { 55 | int *data; 56 | }; 57 | static inline void mempool_put(struct mempool_obj *obj) 58 | { BUG(); } 59 | 60 | extern int shfs_errno; 61 | #define errno shfs_errno 62 | 63 | #define ENOTSUP ENOTSUPP 64 | 65 | #define init_SEMAPHORE(s, v) 66 | static inline int sem_stub(uint64_t s) { return 1; } 67 | #define up(s) sem_stub((uint64_t) s) 68 | #define down(s) sem_stub((uint64_t) s) 69 | #define trydown(s) sem_stub((uint64_t) s) 70 | 71 | #define alloc_mempool(a, b, c, d, e, f, g, h) ((void *) 0xdeadbeaf) 72 | #define shfs_alloc_cache() 1 73 | #define shfs_free_cache() 74 | #define free_mempool(a) 75 | #define shfs_flush_cache() 76 | 77 | static inline int mempool_free_count(struct mempool *a) 78 | { 79 | BUG(); 80 | return 0; 81 | } 82 | 83 | static inline int shfs_cache_ref_count(void) 84 | { 85 | BUG(); 86 | return 0; 87 | } 88 | 89 | /* temporary stubs */ 90 | 91 | #define UINT64_MAX ((uint64_t) (-1)) 92 | 93 | #define __BYTE_ORDER __LITTLE_ENDIAN 94 | #ifndef __BIG_ENDIAN 95 | #define __BIG_ENDIAN 0 96 | #endif 97 | 98 | /* static inline */ 99 | /* struct blkdev *shfs_checkopen_blkdev(blkdev_id_t bd_id, */ 100 | /* void *chk0, int mode) */ 101 | /* { */ 102 | /* BUG(); */ 103 | /* } */ 104 | #endif 105 | -------------------------------------------------------------------------------- /shfs-kmod/include/target/sys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Minicache system definitions required to shfs 3 | * 4 | * Authors: Yuri Volchkov 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved 8 | * 9 | * This software is available to you under a choice of one of two 10 | * licenses. You may choose to be licensed under the terms of the GNU 11 | * General Public License (GPL) Version 2, or the BSD license below: 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 3. Neither the name of the copyright holder nor the names of its 23 | * contributors may be used to endorse or promote products derived from 24 | * this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | */ 39 | 40 | #ifndef _SYS_H_ 41 | #define _SYS_H_ 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | 48 | #define target_malloc(align, size) \ 49 | kmalloc(size, GFP_KERNEL) 50 | #define target_free(ptr) \ 51 | kfree(ptr) 52 | 53 | #define ASSERT(x) BUG_ON(!(x)) 54 | 55 | /* shutdown */ 56 | #define TARGET_SHTDN_POWEROFF 0 57 | #define TARGET_SHTDN_REBOOT 1 58 | #define TARGET_SHTDN_SUSPEND 2 59 | 60 | #define target_suspend() \ 61 | do { \ 62 | printk("WARNING: 'suspend' is not supported by platform; ignore\n"); \ 63 | } while(0) 64 | 65 | #define target_halt() \ 66 | exit(0) 67 | 68 | #define target_reboot() \ 69 | do { \ 70 | printk("WARNING: 'reboot' is not supported by platform; use 'halt'\n"); \ 71 | target_halt(); \ 72 | } while(0) 73 | 74 | #define target_crash() \ 75 | exit(1) 76 | 77 | void app_shutdown(unsigned reason); 78 | 79 | /* scheduling */ 80 | #define msleep(ms) usleep((((ms)) * 1000l)) 81 | 82 | #ifdef CONFIG_PTH_THREADS 83 | #include 84 | 85 | #define thread pth 86 | #define schedule() \ 87 | pth_yield(NULL) 88 | #define create_thread(name, func, argp) \ 89 | pth_spawn(PTH_ATTR_DEFAULT, (void * (*)(void *)) (func), (argp)) 90 | #define exit_thread() \ 91 | pth_exit(NULL) 92 | #else 93 | #define thread (void *) 94 | #define schedule() \ 95 | do {} while (0) 96 | #define create_thread(name, func, argp) \ 97 | do {} while (0) 98 | #define exit_thread() \ 99 | do {} while (0) 100 | #endif 101 | 102 | /* semaphore */ 103 | 104 | /* #define init_SEMAPHORE(s, v) sem_init((s), 0, (v)) /\* negative semaphores? *\/ */ 105 | /* #define up(s) (sem_post((s)) ? 0 : 1) */ 106 | /* #define down(s) (sem_wait((s)) ? 0 : 1) */ 107 | /* #define trydown(s) (sem_trywait((s)) ? 0 : 1) */ 108 | 109 | 110 | 111 | 112 | #define target_now_ns() ({ \ 113 | uint64_t r; \ 114 | struct timeval now; \ 115 | gettimeofday(&now, NULL); \ 116 | r = now.tv_usec * 1000 + now.tv_sec * 1000000000l; \ 117 | r; }) 118 | 119 | #define NSEC_TO_MSEC(ns) ((ns) / 1000000l) 120 | 121 | /* env init/exit */ 122 | #ifdef CONFIG_PTH_THREADS 123 | #define target_init() \ 124 | pth_init() 125 | #define target_exit() \ 126 | pth_exit(NULL) 127 | #else 128 | #define target_init() \ 129 | do {} while (0) 130 | #define target_exit() \ 131 | do {} while (0) 132 | #endif 133 | 134 | 135 | #endif /* _SYS_H_ */ 136 | -------------------------------------------------------------------------------- /shfs-kmod/inode.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SHFS inodes handling functions 3 | * 4 | * Authors: Yuri Volchkov 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved 8 | * 9 | * This software is available to you under a choice of one of two 10 | * licenses. You may choose to be licensed under the terms of the GNU 11 | * General Public License (GPL) Version 2, or the BSD license below: 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 3. Neither the name of the copyright holder nor the names of its 23 | * contributors may be used to endorse or promote products derived from 24 | * this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include "shfs.h" 45 | #include "htable.h" 46 | #include "shfs_btable.h" 47 | #include "shfs_fio.h" 48 | 49 | int shfs_get_block(struct inode *inode, 50 | sector_t iblock, 51 | struct buffer_head *bh_result, 52 | int create) 53 | { 54 | /* struct hentry *hentry = SHFS_I(inode)->bentry->hentry; */ 55 | /* struct shfs_sb_info *sbi = SHFS_SB(inode->i_sb); */ 56 | 57 | sector_t block = iblock + SHFS_I(inode)->start_block; 58 | map_bh(bh_result, inode->i_sb, block); 59 | bh_result->b_size = 4096; 60 | return 0; 61 | } 62 | 63 | static int shfs_readpage(struct file *file, struct page *page) 64 | { 65 | return mpage_readpage(page, shfs_get_block); 66 | } 67 | 68 | static int 69 | shfs_readpages(struct file *file, struct address_space *mapping, 70 | struct list_head *pages, unsigned nr_pages) 71 | { 72 | return mpage_readpages(mapping, pages, nr_pages, shfs_get_block); 73 | } 74 | 75 | static sector_t shfs_bmap(struct address_space *mapping, sector_t block) 76 | { 77 | return generic_block_bmap(mapping, block, shfs_get_block); 78 | } 79 | 80 | const struct address_space_operations shfs_aops = { 81 | .readpage = shfs_readpage, 82 | .readpages = shfs_readpages, 83 | .bmap = shfs_bmap, 84 | /* .direct_IO = shfs_direct_IO, */ 85 | }; 86 | -------------------------------------------------------------------------------- /shfs-kmod/shfs.c: -------------------------------------------------------------------------------- 1 | ../shfs.c -------------------------------------------------------------------------------- /shfs-kmod/shfs_check.c: -------------------------------------------------------------------------------- 1 | ../shfs_check.c -------------------------------------------------------------------------------- /shfs-tools/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, NEC Europe Ltd., NEC Corporation All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 3. Neither the name of the copyright holder nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /shfs-tools/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Simple hash filesystem (SHFS) tools 3 | # 4 | # Authors: Simon Kuenzer 5 | # 6 | # 7 | # Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions 11 | # are met: 12 | # 13 | # 1. Redistributions of source code must retain the above copyright 14 | # notice, this list of conditions and the following disclaimer. 15 | # 2. Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | # 3. Neither the name of the copyright holder nor the names of its 19 | # contributors may be used to endorse or promote products derived from 20 | # this software without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | # POSSIBILITY OF SUCH DAMAGE. 33 | # 34 | # 35 | 36 | RM = rm -f 37 | CC = gcc 38 | LD = gcc 39 | CFLAGS += -O3 -g -Wunused -Wtype-limits -D__SHFS_TOOLS__ 40 | LDFLAGS += 41 | LDLIBS += -luuid -lmhash 42 | 43 | default: all 44 | 45 | %.o: %.c 46 | $(CC) $(CFLAGS) -c $< -o $@ 47 | 48 | %: %.o 49 | $(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@ 50 | 51 | shfs_mkfs: shfs_mkfs.o tools_common.o 52 | 53 | shfs_admin: shfs_admin.o htable.o tools_common.o shfs_alloc.o shfs_check.o http_parser.o 54 | 55 | all: shfs_mkfs shfs_admin 56 | 57 | clean: 58 | $(RM) *.o core shfs_mkfs shfs_admin 59 | -------------------------------------------------------------------------------- /shfs-tools/README.md: -------------------------------------------------------------------------------- 1 | SHFS Tools 2 | ========== 3 | 4 | The SHFS tools can be used to create and manage SHFS object stores. 5 | 6 | 7 | Requirements 8 | ------------ 9 | 10 | In order to build the SHFS tools, you will need to have the following 11 | shared libraries installed: 12 | * [libuuid](http://e2fsprogs.sourceforge.net) 13 | * [libmhash](http://mhash.sourceforge.net) 14 | 15 | On Debian/Ubuntu you install them via: 16 | 17 | apt-get install libmhash2 libmhash-dev libuuid1 uuid-dev 18 | 19 | 20 | Build Instructions 21 | ------------------ 22 | 23 | You build the SHFS tools with the following make command: 24 | 25 | make 26 | 27 | Alternatively, you can also build a single tool by passing its executable 28 | name (e.g., shfs_mkfs) to make: 29 | 30 | make shfs_mkfs 31 | 32 | 33 | Examples: Using SHFS Tools 34 | -------------------------- 35 | 36 | ### Format a Physical Block Device with SHFS 37 | 38 | shfs_mkfs -n "NewVol#00" /dev/sdb2 39 | 40 | ### Create an 2GB SHFS Image File 41 | 42 | dd if=/dev/zero of=shfs-demo.img count=0 bs=1 seek=2G 43 | shfs_mkfs -n "SHFS-Demo" shfs-demo.img 44 | 45 | ### Adding Files to an SHFS Volume 46 | 47 | shfs_admin --add-obj /path/to/my_music.mp3 -m audio/mpeg3 shfs-demo.img 48 | 49 | ### Note 50 | 51 | Please remember that you have to run remount on a MiniCache Domain after you 52 | did changes to the object store while it is mounted. 53 | -------------------------------------------------------------------------------- /shfs-tools/hash.h: -------------------------------------------------------------------------------- 1 | ../hash.h -------------------------------------------------------------------------------- /shfs-tools/htable.c: -------------------------------------------------------------------------------- 1 | ../htable.c -------------------------------------------------------------------------------- /shfs-tools/htable.h: -------------------------------------------------------------------------------- 1 | ../htable.h -------------------------------------------------------------------------------- /shfs-tools/http_parser.c: -------------------------------------------------------------------------------- 1 | ../http_parser.c -------------------------------------------------------------------------------- /shfs-tools/http_parser.h: -------------------------------------------------------------------------------- 1 | ../http_parser.h -------------------------------------------------------------------------------- /shfs-tools/likely.h: -------------------------------------------------------------------------------- 1 | ../likely.h -------------------------------------------------------------------------------- /shfs-tools/shfs_admin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash filesystem (SHFS) tools 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _SHFS_ADMIN_ 36 | #define _SHFS_ADMIN_ 37 | 38 | #include "tools_common.h" 39 | #include "shfs_defs.h" 40 | 41 | #define STR_VERSION "Simple Hash FS (SHFS) Tools: Admin" 42 | 43 | #define MAX_NB_TRY_BLKDEVS SHFS_MAX_NB_MEMBERS 44 | 45 | enum action { 46 | NONE = 0, 47 | ADDOBJ, 48 | ADDLNK, 49 | RMOBJ, 50 | CATOBJ, 51 | SETDEFOBJ, 52 | CLEARDEFOBJ, 53 | LSOBJS, 54 | SHOWINFO 55 | }; 56 | 57 | enum ltype { 58 | LREDIRECT = 0, 59 | LRAW, 60 | LAUTO 61 | }; 62 | 63 | struct token { 64 | struct token *next; 65 | 66 | enum action action; 67 | char *path; 68 | char *optstr0; 69 | char *optstr1; 70 | char *optstr2; 71 | enum ltype optltype; 72 | }; 73 | 74 | struct args { 75 | char **devpath; 76 | unsigned int nb_devs; 77 | 78 | struct token *tokens; /* list of tokens */ 79 | }; 80 | 81 | struct vol_info { 82 | uuid_t uuid; 83 | char volname[17]; 84 | uint32_t chunksize; 85 | chk_t volsize; 86 | 87 | struct storage s; 88 | 89 | /* hash table */ 90 | struct htable *bt; 91 | void **htable_chunk_cache; 92 | int *htable_chunk_cache_state; 93 | chk_t htable_ref; 94 | chk_t htable_bak_ref; 95 | chk_t htable_len; 96 | uint32_t htable_nb_buckets; 97 | uint32_t htable_nb_entries; 98 | uint32_t htable_nb_entries_per_bucket; 99 | uint32_t htable_nb_entries_per_chunk; 100 | uint8_t hfunc; 101 | uint8_t hlen; 102 | 103 | struct shfs_bentry *def_bentry; 104 | 105 | /* allocator */ 106 | uint8_t allocator; 107 | struct shfs_alist *al; 108 | }; 109 | 110 | /* chunk_cache_states */ 111 | #define CCS_MODIFIED 0x02 112 | 113 | #endif /* _SHFS_ADMIN_ */ 114 | -------------------------------------------------------------------------------- /shfs-tools/shfs_alloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash filesystem (SHFS) tools 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #include 36 | #include 37 | 38 | #include "shfs_alloc.h" 39 | 40 | struct shfs_alist *shfs_alloc_alist(chk_t area_size, uint8_t allocator) 41 | { 42 | struct shfs_alist *alist; 43 | 44 | if (allocator != SALLOC_FIRSTFIT && 45 | allocator != SALLOC_BESTFIT) { 46 | errno = ENOTSUP; 47 | return NULL; 48 | } 49 | 50 | alist = malloc(sizeof(*alist)); 51 | if (!alist) 52 | return NULL; 53 | 54 | alist->head = NULL; 55 | alist->tail = NULL; 56 | alist->count = 0; 57 | alist->end = area_size; 58 | alist->allocator = allocator; 59 | return alist; 60 | } 61 | 62 | void shfs_free_alist(struct shfs_alist *al) 63 | { 64 | struct shfs_aentry *cur; 65 | struct shfs_aentry *next; 66 | 67 | if (al) { 68 | cur = al->head; 69 | while (cur) { 70 | next = cur->next; 71 | free(cur); 72 | cur = next; 73 | } 74 | 75 | free(al); 76 | } 77 | } 78 | 79 | int shfs_alist_register(struct shfs_alist *al, chk_t start, chk_t len) 80 | { 81 | struct shfs_aentry *e; 82 | struct shfs_aentry *prev; 83 | struct shfs_aentry *next; 84 | struct shfs_aentry *new; 85 | 86 | new = malloc(sizeof(*new)); 87 | if (!new) 88 | return -ENOMEM; 89 | new->start = start; 90 | new->end = (start + len); 91 | 92 | if (!al->head) { 93 | /* list is empty */ 94 | al->head = new; 95 | al->tail = new; 96 | new->prev = NULL; 97 | new->next = NULL; 98 | } else { 99 | /* search for predecessor which has start <= new->start */ 100 | prev = NULL; 101 | next = NULL; 102 | for (e = al->head; e != NULL; e = e->next) { 103 | if (e->start <= start) { 104 | prev = e; 105 | continue; 106 | } else { 107 | next = e; 108 | break; 109 | } 110 | } 111 | 112 | new->prev = prev; 113 | new->next = next; 114 | if (prev) 115 | prev->next = new; 116 | else 117 | al->head = new; 118 | if (next) 119 | next->prev = new; 120 | else 121 | al->tail = new; 122 | } 123 | 124 | al->count++; 125 | return 0; 126 | } 127 | 128 | int shfs_alist_unregister(struct shfs_alist *al, chk_t start, chk_t len) 129 | { 130 | struct shfs_aentry *e; 131 | chk_t end = (start + len); 132 | 133 | /* search for element in the list and remove it if found */ 134 | for (e = al->head; e != NULL; e = e->next) { 135 | if (e->start == start && 136 | e->end == end) { 137 | if (e->prev) 138 | e->prev->next = e->next; 139 | else 140 | al->head = e->next; 141 | if (e->next) 142 | e->next->prev = e->prev; 143 | else 144 | al->tail = e->prev; 145 | free(e); 146 | al->count--; 147 | return 0; 148 | } 149 | } 150 | 151 | return -ENOENT; 152 | } 153 | 154 | static chk_t _shfs_alist_find_ff(struct shfs_alist *al, chk_t len) 155 | { 156 | struct shfs_aentry *e; 157 | chk_t free_start, free_end; 158 | 159 | /* list all segments */ 160 | for (e = al->head; e != NULL; e = e->next) { 161 | /* find actual start and end of a free space segment */ 162 | free_start = e->end; 163 | while (e->next && 164 | e->next->start <= e->end) { 165 | if (e->next->end > free_start) 166 | free_start = e->next->end; 167 | e = e->next; 168 | } 169 | 170 | if (e->next) 171 | free_end = e->next->start; 172 | else { 173 | free_end = al->end; 174 | if (free_end == free_start) 175 | break; /* nothing else found -> cancel */ 176 | } 177 | 178 | /* free_start and free_end points now to a free space segment */ 179 | if (free_end - free_start >= len) 180 | return free_start; 181 | } 182 | 183 | return 0; 184 | } 185 | 186 | static chk_t _shfs_alist_find_bf(struct shfs_alist *al, chk_t len) 187 | { 188 | struct shfs_aentry *e; 189 | chk_t free_start, free_end; 190 | 191 | /* list all segments */ 192 | for (e = al->head; e != NULL; e = e->next) { 193 | /* find actual start and end of a free space segment */ 194 | free_start = e->end; 195 | while (e->next && 196 | e->next->start <= e->end) { 197 | if (e->next->end > free_start) 198 | free_start = e->next->end; 199 | e = e->next; 200 | } 201 | 202 | if (e->next) 203 | free_end = e->next->start; 204 | else { 205 | free_end = al->end; 206 | if (free_end == free_start) 207 | break; /* nothing else found -> cancel */ 208 | } 209 | 210 | /* free_start and free_end points now to a free space segment */ 211 | printf("[FREE] %15"PRIchk" - %15"PRIchk"\n", free_start, free_end); 212 | } 213 | 214 | return 0; 215 | } 216 | 217 | chk_t shfs_alist_find_free(struct shfs_alist *al, chk_t len) 218 | { 219 | switch (al->allocator) { 220 | case SALLOC_FIRSTFIT: 221 | return _shfs_alist_find_ff(al, len); 222 | case SALLOC_BESTFIT: 223 | return _shfs_alist_find_bf(al, len); 224 | default: 225 | break; 226 | } 227 | return 0; 228 | } 229 | -------------------------------------------------------------------------------- /shfs-tools/shfs_alloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash filesystem (SHFS) tools 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _SHFS_ALLOC_ 36 | #define _SHFS_ALLOC_ 37 | 38 | #include "shfs_defs.h" 39 | 40 | struct shfs_aentry { 41 | chk_t start; 42 | chk_t end; 43 | 44 | struct shfs_aentry *next; 45 | struct shfs_aentry *prev; 46 | }; 47 | 48 | struct shfs_alist { 49 | chk_t end; 50 | unsigned int count; 51 | uint8_t allocator; 52 | 53 | struct shfs_aentry *head; 54 | struct shfs_aentry *tail; 55 | }; 56 | 57 | struct shfs_alist *shfs_alloc_alist(chk_t area_size, uint8_t allocator); 58 | void shfs_free_alist(struct shfs_alist *al); 59 | 60 | int shfs_alist_register(struct shfs_alist *al, chk_t start, chk_t len); 61 | int shfs_alist_unregister(struct shfs_alist *al, chk_t start, chk_t len); 62 | chk_t shfs_alist_find_free(struct shfs_alist *al, chk_t len); 63 | 64 | 65 | /******* DEBUG ********/ 66 | #include 67 | 68 | static inline void print_alist(struct shfs_alist *al) 69 | { 70 | struct shfs_aentry *e; 71 | unsigned int i = 0; 72 | 73 | for (e = al->head; e != NULL; e = e->next) 74 | printf("[entry%5u] %15"PRIchk" - %15"PRIchk" (len: %15"PRIchk")\n", i++, e->start, e->end, e->end - e->start); 75 | } 76 | 77 | #endif /* _SHFS_ALLOC_ */ 78 | -------------------------------------------------------------------------------- /shfs-tools/shfs_btable.h: -------------------------------------------------------------------------------- 1 | ../shfs_btable.h -------------------------------------------------------------------------------- /shfs-tools/shfs_check.c: -------------------------------------------------------------------------------- 1 | ../shfs_check.c -------------------------------------------------------------------------------- /shfs-tools/shfs_check.h: -------------------------------------------------------------------------------- 1 | ../shfs_check.h -------------------------------------------------------------------------------- /shfs-tools/shfs_defs.h: -------------------------------------------------------------------------------- 1 | ../shfs_defs.h -------------------------------------------------------------------------------- /shfs-tools/shfs_mkfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash filesystem (SHFS) tools 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _SHFS_MKFS_ 36 | #define _SHFS_MKFS_ 37 | 38 | #include "tools_common.h" 39 | 40 | #define STR_VERSION "Simple Hash FS (SHFS) Tools: MakeFS" 41 | 42 | struct args { 43 | char **devpath; 44 | uint8_t nb_devs; 45 | 46 | uint8_t encoding; 47 | char volname[17]; /* null-terminated */ 48 | uint32_t stripesize; 49 | 50 | int fullerase; 51 | int combined_striping; 52 | 53 | uint8_t allocator; 54 | uint8_t hashfunc; 55 | uint8_t hashlen; 56 | uint32_t bucket_count; 57 | uint32_t entries_per_bucket; 58 | }; 59 | 60 | #endif /* _SHFS_MKFS_ */ 61 | -------------------------------------------------------------------------------- /shfs-tools/tools_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash filesystem (SHFS) tools 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _TOOLS_COMMON_ 36 | #define _TOOLS_COMMON_ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include "shfs_defs.h" 46 | 47 | /* 48 | * Print helpers 49 | */ 50 | extern unsigned int verbosity; 51 | extern int force; 52 | 53 | #define eprintf(...) fprintf(stderr, __VA_ARGS__) 54 | #define fatal() eprintf("%s\n", strerror(errno)) 55 | #define dief(...) do { eprintf(__VA_ARGS__); exit(EXIT_FAILURE); } while(0) 56 | #define die() do { fatal(); exit(EXIT_FAILURE); } while(0) 57 | #define dprintf(LEVEL, ...) do { if (verbosity >= (LEVEL)) fprintf(stderr, __VA_ARGS__); } while(0) 58 | #define printvar(VAR, FMT) do { if (verbosity >= (D_MAX)) fprintf(stderr, #VAR ": "FMT"\n", (VAR)); } while(0) 59 | 60 | #define D_L0 1 61 | #define D_L1 2 62 | #define D_MAX D_L1 63 | 64 | 65 | /* 66 | * Argument parsing helper 67 | */ 68 | static inline int parse_args_setval_str(char** out, const char* buf) 69 | { 70 | if (*out) 71 | free(*out); 72 | *out = strdup(buf); 73 | if (!*out) { 74 | *out = NULL; 75 | return -ENOMEM; 76 | } 77 | 78 | return 0; 79 | } 80 | 81 | static inline int parse_args_setval_int(int* out, const char* buf) 82 | { 83 | if (sscanf(optarg, "%d", out) != 1) 84 | return -EINVAL; 85 | return 0; 86 | } 87 | 88 | /* 89 | * Disk I/O 90 | */ 91 | struct disk { 92 | int fd; 93 | char *path; 94 | uint64_t size; 95 | uint32_t blksize; 96 | int discard; 97 | }; 98 | 99 | struct disk *open_disk(const char *path, int mode); 100 | void close_disk(struct disk *d); 101 | 102 | struct vol_member { 103 | struct disk *d; 104 | uuid_t uuid; 105 | }; 106 | 107 | struct storage { 108 | struct vol_member member[SHFS_MAX_NB_MEMBERS]; 109 | uint8_t nb_members; 110 | uint32_t stripesize; 111 | uint8_t stripemode; 112 | }; 113 | 114 | int sync_io_chunk(struct storage *s, chk_t start, chk_t len, int owrite, void *buffer); 115 | #define sync_read_chunk(s, start, len, buffer) \ 116 | sync_io_chunk((s), (start), (len), 0, (buffer)) 117 | #define sync_write_chunk(s, start, len, buffer) \ 118 | sync_io_chunk((s), (start), (len), 1, (buffer)) 119 | int sync_erase_chunk(struct storage *s, chk_t start, chk_t len); 120 | 121 | 122 | /* 123 | * Misc 124 | */ 125 | void print_shfs_hdr_summary(struct shfs_hdr_common *hdr_common, 126 | struct shfs_hdr_config *hdr_config); 127 | chk_t metadata_size(struct shfs_hdr_common *hdr_common, 128 | struct shfs_hdr_config *hdr_config); 129 | chk_t avail_space(struct shfs_hdr_common *hdr_common, 130 | struct shfs_hdr_config *hdr_config); 131 | static inline void hash_unparse(hash512_t h, uint8_t hlen, char *out) 132 | { 133 | uint8_t i; 134 | 135 | for (i = 0; i < hlen; i++) 136 | snprintf(out + (2*i), 3, "%02x", h[i]); 137 | } 138 | 139 | static inline size_t strftimestamp_s(char *s, size_t slen, const char *fmt, uint64_t ts_sec) 140 | { 141 | struct tm *tm; 142 | time_t *tsec = (time_t *) &ts_sec; 143 | tm = localtime(tsec); 144 | return strftime(s, slen, fmt, tm); 145 | } 146 | 147 | size_t strshfshost(char *s, size_t slen, struct shfs_host *h); 148 | 149 | #endif /* _TOOLS_COMMON_ */ 150 | -------------------------------------------------------------------------------- /shfs_check.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash filesystem (SHFS) 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * This software is available to you under a choice of one of two 10 | * licenses. You may choose to be licensed under the terms of the GNU 11 | * General Public License (GPL) Version 2, or the BSD license below: 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 3. Neither the name of the copyright holder nor the names of its 23 | * contributors may be used to endorse or promote products derived from 24 | * this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | */ 39 | #ifdef __KERNEL__ 40 | #include 41 | #include 42 | #endif 43 | 44 | #include "shfs_check.h" 45 | #include "shfs_defs.h" 46 | 47 | int shfs_detect_hdr0(void *chk0) { 48 | struct shfs_hdr_common *hdr_common; 49 | 50 | hdr_common = (void *)((uint8_t *) chk0 + BOOT_AREA_LENGTH); 51 | 52 | /* Check for SHFS magic */ 53 | if (hdr_common->magic[0] != SHFS_MAGIC0) 54 | return -1; 55 | if (hdr_common->magic[1] != SHFS_MAGIC1) 56 | return -1; 57 | if (hdr_common->magic[2] != SHFS_MAGIC2) 58 | return -1; 59 | if (hdr_common->magic[3] != SHFS_MAGIC3) 60 | return -1; 61 | 62 | /* Check for compatible version */ 63 | if (hdr_common->version[0] != SHFS_MAJOR) 64 | return -2; 65 | if (hdr_common->version[1] != SHFS_MINOR) 66 | return -2; 67 | 68 | /* Check Endianess */ 69 | #if __BYTE_ORDER == __LITTLE_ENDIAN 70 | if (hdr_common->vol_byteorder != SBO_LITTLEENDIAN) 71 | #elif __BYTE_ORDER == __BIG_ENDIAN 72 | if (hdr_common->vol_byteorder != SBO_BIGENDIAN) 73 | #else 74 | #warning "Could not detect byte-order" 75 | #endif 76 | return -3; 77 | 78 | /* Briefly check member count */ 79 | if (hdr_common->member_count == 0 || hdr_common->member_count > SHFS_MAX_NB_MEMBERS) 80 | return -4; 81 | 82 | return 1; /* SHFSv1 detected */ 83 | } 84 | -------------------------------------------------------------------------------- /shfs_check.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash filesystem (SHFS) 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _SHFS_CHECK_H_ 36 | #define _SHFS_CHECK_H_ 37 | 38 | /** 39 | * Can be used to detect an compatible SHFS filesystem 40 | * header. It returns a value >= 0 if SHFS was detected. 41 | * Note: chk0 buffer has to be at least 4096 bytes long 42 | */ 43 | int shfs_detect_hdr0(void *chk0); 44 | 45 | #endif /* _SHFS_CHECK_H_ */ 46 | -------------------------------------------------------------------------------- /shfs_fio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash filesystem (SHFS) 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _SHFS_FIO_ 36 | #define _SHFS_FIO_ 37 | 38 | #include "shfs_defs.h" 39 | #include "shfs.h" 40 | #include "shfs_btable.h" 41 | 42 | #ifndef __KERNEL__ 43 | #include "shfs_cache.h" 44 | #include "likely.h" 45 | 46 | #define SHFS_HASH_INDICATOR_PREFIX '?' /* has to be the same as HTTPURL_ARGS_INDICATOR_PREFIX in http.c */ 47 | 48 | typedef struct shfs_bentry *SHFS_FD; 49 | 50 | /** 51 | * Opens a file/object via hash string or name depending on 52 | * the first character of path: 53 | * 54 | * Hash: "?024a5bec" 55 | * Name: "index.html" 56 | */ 57 | SHFS_FD shfs_fio_open(const char *path); 58 | /** 59 | * Opens a file/object via a hash digest 60 | */ 61 | SHFS_FD shfs_fio_openh(hash512_t h); 62 | /** 63 | * Creates a file descriptor clone 64 | */ 65 | SHFS_FD shfs_fio_openf(SHFS_FD f); 66 | /** 67 | * Closes a file descriptor 68 | */ 69 | void shfs_fio_close(SHFS_FD f); 70 | 71 | void shfs_fio_name(SHFS_FD f, char *out, size_t outlen); /* null-termination is ensured */ 72 | void shfs_fio_hash(SHFS_FD f, hash512_t out); 73 | #define shfs_fio_islink(f) \ 74 | (SHFS_HENTRY_ISLINK((f)->hentry)) 75 | void shfs_fio_size(SHFS_FD f, uint64_t *out); /* returns 0 on links */ 76 | 77 | /** 78 | * Link object attributes 79 | * The following interfaces can only be used on link objects 80 | */ 81 | #define shfs_fio_link_type(f) \ 82 | (SHFS_HENTRY_LINK_TYPE((f)->hentry)) 83 | #define shfs_fio_link_rport(f) \ 84 | (SHFS_HENTRY_LINKATTR((f)->hentry).rport) 85 | #define shfs_fio_link_rhost(f) \ 86 | (&(SHFS_HENTRY_LINKATTR((f)->hentry).rhost)) 87 | void shfs_fio_link_rpath(SHFS_FD f, char *out, size_t outlen); /* null-termination is ensured */ 88 | 89 | /** 90 | * File object attributes 91 | * The following interfaces can only be used to non-link objects 92 | */ 93 | void shfs_fio_mime(SHFS_FD f, char *out, size_t outlen); /* null-termination is ensured */ 94 | 95 | /* file container size in chunks */ 96 | #define shfs_fio_size_chks(f) \ 97 | (DIV_ROUND_UP(((f)->hentry->f_attr.offset + (f)->hentry->f_attr.len), shfs_vol.chunksize)) 98 | 99 | /* volume chunk address of file chunk address */ 100 | #define shfs_volchk_fchk(f, fchk) \ 101 | ((f)->hentry->f_attr.chunk + (fchk)) 102 | 103 | /* volume chunk address of file byte offset */ 104 | #define shfs_volchk_foff(f, foff) \ 105 | (((f)->hentry->f_attr.offset + (foff)) / shfs_vol.chunksize + (f)->hentry->f_attr.chunk) 106 | /* byte offset in volume chunk of file byte offset */ 107 | #define shfs_volchkoff_foff(f, foff) \ 108 | (((f)->hentry->f_attr.offset + (foff)) % shfs_vol.chunksize) 109 | 110 | /* Check macros to test if a address is within file bounds */ 111 | #define shfs_is_fchk_in_bound(f, fchk) \ 112 | (shfs_fio_size_chks((f)) > (fchk)) 113 | #define shfs_is_foff_in_bound(f, foff) \ 114 | ((f)->hentry->f_attr.len > (foff)) 115 | 116 | /** 117 | * File cookies 118 | */ 119 | #define shfs_fio_get_cookie(f) \ 120 | ((f)->cookie) 121 | static inline int shfs_fio_set_cookie(SHFS_FD f, void *cookie) { 122 | if (f->cookie) 123 | return -EBUSY; 124 | f->cookie = cookie; 125 | return 0; 126 | } 127 | #define shfs_fio_clear_cookie(f) \ 128 | do { (f)->cookie = NULL; } while (0) 129 | 130 | /* 131 | * Simple but synchronous file read 132 | * Note: Busy-waiting is used 133 | */ 134 | /* direct read */ 135 | int shfs_fio_read(SHFS_FD f, uint64_t offset, void *buf, uint64_t len); 136 | int shfs_fio_read_nosched(SHFS_FD f, uint64_t offset, void *buf, uint64_t len); 137 | /* read is using cache */ 138 | int shfs_fio_cache_read(SHFS_FD f, uint64_t offset, void *buf, uint64_t len); 139 | int shfs_fio_cache_read_nosched(SHFS_FD f, uint64_t offset, void *buf, uint64_t len); 140 | 141 | /* 142 | * Async file read 143 | */ 144 | static inline int shfs_fio_cache_aread(SHFS_FD f, chk_t offset, shfs_aiocb_t *cb, void *cb_cookie, void *cb_argp, struct shfs_cache_entry **cce_out, SHFS_AIO_TOKEN **t_out) 145 | { 146 | register chk_t addr; 147 | 148 | if (unlikely(!(shfs_is_fchk_in_bound(f, offset)))) 149 | return -EINVAL; 150 | addr = shfs_volchk_fchk(f, offset); 151 | return shfs_cache_aread(addr, cb, cb_cookie, cb_argp, cce_out, t_out); 152 | } 153 | #endif /* __KERNEL__ */ 154 | 155 | 156 | 157 | #endif /* _SHFS_FIO_ */ 158 | -------------------------------------------------------------------------------- /shfs_stats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash filesystem (SHFS) 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _SHFS_STATS_H_ 36 | #define _SHFS_STATS_H_ 37 | 38 | #include "shfs_stats_data.h" 39 | #include "shfs_btable.h" 40 | #include "shfs_fio.h" 41 | #include "shfs.h" 42 | #include "likely.h" 43 | #ifdef HAVE_CTLDIR 44 | #include 45 | #endif 46 | 47 | /* 48 | * Retrieve stats structure from SHFS btable entry 49 | */ 50 | #define shfs_stats_from_bentry(bentry) \ 51 | (&((bentry)->hstats)) 52 | 53 | /* 54 | * Retrieves stats structure from an SHFS_FD 55 | * NOTE: No NULL check is made since it is assumed that 56 | * f is provided by the currently mounted shfs hash table 57 | * -> bentry does exist 58 | */ 59 | static inline struct shfs_el_stats *shfs_stats_from_fd(SHFS_FD f) { 60 | struct shfs_bentry *bentry = (struct shfs_bentry *) f; 61 | 62 | return shfs_stats_from_bentry(bentry); 63 | } 64 | 65 | /* 66 | * Retrieves stats element from miss stats table 67 | * NOTE: A new entry is created automatically, if it does not 68 | * exist yet 69 | */ 70 | static inline struct shfs_el_stats *shfs_stats_from_mstats(hash512_t h) { 71 | int is_new; 72 | struct htable_el *el; 73 | struct shfs_el_stats *el_stats; 74 | 75 | el = htable_lookup_add(shfs_vol.mstats.el_ht, h, &is_new); 76 | if (unlikely(!el)) 77 | return NULL; 78 | 79 | el_stats = (struct shfs_el_stats *) el->private; 80 | if (is_new) 81 | memset(el_stats, 0, sizeof(*el_stats)); 82 | return el_stats; 83 | } 84 | 85 | /* 86 | * Deletes an entry from mstat table 87 | */ 88 | static inline void shfs_stats_mstats_drop(hash512_t h) { 89 | struct htable_el *el; 90 | 91 | el = htable_lookup(shfs_vol.mstats.el_ht, h); 92 | if (!el) 93 | return; 94 | htable_rm(shfs_vol.mstats.el_ht, el); 95 | } 96 | 97 | /* 98 | * Resetting statistics 99 | */ 100 | static inline void shfs_reset_mstats(void) { 101 | htable_clear(shfs_vol.mstats.el_ht); 102 | shfs_vol.mstats.i = 0; 103 | shfs_vol.mstats.e = 0; 104 | } 105 | 106 | static inline void shfs_reset_hstats(void) { 107 | struct htable_el *el; 108 | struct shfs_el_stats *el_stats; 109 | 110 | foreach_htable_el(shfs_vol.bt, el) { 111 | el_stats = shfs_stats_from_bentry((struct shfs_bentry *) el->private); 112 | memset(el_stats, 0, sizeof(*el_stats)); 113 | } 114 | } 115 | 116 | #define shfs_reset_stats() \ 117 | do { \ 118 | shfs_reset_hstats(); \ 119 | shfs_reset_mstats(); \ 120 | } while (0) 121 | 122 | /* 123 | * Dumps statistics of element entries 124 | */ 125 | typedef int (*shfs_dump_el_stats_t)(void *argp, hash512_t h, int loaded, struct shfs_el_stats *stats); 126 | 127 | int shfs_dump_mstats(shfs_dump_el_stats_t dump_el, void *dump_el_argp); 128 | int shfs_dump_hstats(shfs_dump_el_stats_t dump_el, void *dump_el_argp); 129 | 130 | static inline int shfs_dump_stats(shfs_dump_el_stats_t dump_el, void *dump_el_argp) 131 | { 132 | int ret; 133 | ret = shfs_dump_hstats(dump_el, dump_el_argp); 134 | if (unlikely(ret < 0)) 135 | return ret; 136 | ret = shfs_dump_mstats(dump_el, dump_el_argp); 137 | if (unlikely(ret < 0)) 138 | return ret; 139 | return 0; 140 | } 141 | 142 | /* 143 | * Tools to display/export stats via uSh/ctldir 144 | */ 145 | int init_shfs_stats_export(blkdev_id_t bd_id); 146 | #ifdef HAVE_CTLDIR 147 | int register_shfs_stats_tools(struct ctldir *cd); 148 | #else 149 | int register_shfs_stats_tools(void); 150 | #endif 151 | void exit_shfs_stats_export(void); 152 | 153 | #endif /* _SHFS_STATS_H_ */ 154 | -------------------------------------------------------------------------------- /shfs_stats_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple hash filesystem (SHFS) 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _SHFS_STATS_DATA_H_ 36 | #define _SHFS_STATS_DATA_H_ 37 | 38 | #include "htable.h" 39 | 40 | #ifdef SHFS_STATS_HTTP 41 | #ifdef SHFS_STATS_HTTP_DPC 42 | #ifndef SHFS_STATS_HTTP_DPCR 43 | #define SHFS_STATS_HTTP_DPCR 3 /* enabler download progress counters 44 | per default with 0%, 50%, 100% */ 45 | #else 46 | #if SHFS_STATS_HTTP_DPCR < 2 47 | #warning "DPCR value has to be >= 2, disabling download progress counters" 48 | #undef SHFS_STATS_HTTP_DPC /* disable download progress counters */ 49 | #endif 50 | #endif 51 | #endif 52 | 53 | #ifdef SHFS_STATS_HTTP_DPC 54 | /* threshold calculation */ 55 | #define SHFS_STATS_HTTP_DPC_THRESHOLD(r, x) \ 56 | (((x) * (r)) / ((SHFS_STATS_HTTP_DPCR) - 1)) 57 | #define SHFS_STATS_HTTP_DPC_THRESHOLD_PERCENTAGE(x) \ 58 | SHFS_STATS_HTTP_DPC_THRESHOLD(100, (x)) 59 | #endif 60 | #endif 61 | 62 | struct shfs_mstats { 63 | uint32_t i; /* invalid requests */ 64 | uint32_t e; /* errors */ 65 | struct htable *el_ht; /* hash table of elements that are not in cache */ 66 | }; 67 | 68 | struct shfs_el_stats { 69 | uint32_t laccess; /* last access timestamp */ 70 | uint32_t h; /* element hit */ 71 | uint32_t m; /* element miss */ 72 | #ifdef SHFS_STATS_HTTP 73 | uint32_t c; /* successfully completed file transfers (even partial) */ 74 | 75 | /* download progress counters */ 76 | #ifdef SHFS_STATS_HTTP_DPC 77 | uint32_t p[SHFS_STATS_HTTP_DPCR]; 78 | #endif 79 | #endif 80 | }; 81 | 82 | int shfs_init_mstats(uint32_t nb_bkts, uint32_t ent_per_bkt, uint8_t hlen); 83 | void shfs_free_mstats(void); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /shfs_tools.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MicroShell Tools for Simple hash filesystem (SHFS) 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _SHFS_TOOLS_H_ 36 | #define _SHFS_TOOLS_H_ 37 | 38 | #include "shfs_defs.h" 39 | #ifdef HAVE_CTLDIR 40 | #include 41 | #endif 42 | 43 | /** 44 | * Registers shfs tools to micro shell + ctldir (if *cd is not NULL) 45 | */ 46 | #ifdef HAVE_CTLDIR 47 | int register_shfs_tools(struct ctldir *cd); 48 | #else 49 | int register_shfs_tools(void); 50 | #endif 51 | 52 | /** 53 | * Prints an uuid/hash number to a buffer 54 | * Note: The target buffer for the UUID has to be at least 37 bytes long 55 | * Note: The target buffer for the hash has to be at least ((2 * hlen) + 1) bytes long 56 | */ 57 | #ifdef __MINIOS__ 58 | void uuid_unparse(const uuid_t uu, char *out); 59 | int shfs_prefetch_bgnd(unsigned int delay_ms); 60 | #endif 61 | void hash_unparse(const hash512_t h, uint8_t hlen, char *out); 62 | 63 | size_t strftimestamp_s(char *s, size_t slen, const char *fmt, uint64_t ts_sec); 64 | 65 | size_t strshfshost(char *s, size_t slen, struct shfs_host *h); 66 | 67 | #ifdef HAVE_LWIP 68 | #include 69 | #include 70 | #include 71 | 72 | #if LWIP_DNS 73 | static inline int shfshost2ipaddr(const struct shfs_host *h, ip_addr_t *out, dns_found_callback dns_cb, void *dns_cb_argp) 74 | #else 75 | static inline int shfshost2ipaddr(const struct shfs_host *h, ip_addr_t *out) 76 | #endif 77 | { 78 | err_t err; 79 | char hname[sizeof(h->name) + 1]; 80 | 81 | switch(h->type) { 82 | #if !(defined LWIP_IPV4) || LWIP_IPV4 83 | case SHFS_HOST_TYPE_IPV4: 84 | IP4_ADDR(out, h->addr[0], h->addr[1], h->addr[2], h->addr[3]); 85 | return 0; 86 | #endif 87 | #if LWIP_IPV6 88 | case SHFS_HOST_TYPE_IPV6: 89 | IP6_ADDR(out, h->addr[0], h->addr[1], h->addr[2], h->addr[3], 90 | h->addr[4], h->addr[5], h->addr[6], h->addr[7]); 91 | return 0; 92 | #endif 93 | #if LWIP_DNS 94 | case SHFS_HOST_TYPE_NAME: 95 | /* FIXME: remove this workaround for null-terminating hostname in SHFS field */ 96 | strncpy(hname, h->name, sizeof(h->name)); 97 | hname[sizeof(hname) - 1] = '\0'; 98 | err = dns_gethostbyname(h->name, out, dns_cb, dns_cb_argp); 99 | if (err == ERR_OK) 100 | return 0; /* hostname found in local table */ 101 | if (err == ERR_INPROGRESS) 102 | return 1; /* query sent, callback will be called on answer */ 103 | return -EINVAL; /* general error */ 104 | #endif 105 | default: 106 | return -ENOTSUP; 107 | } 108 | } 109 | #endif /* HAVE_LWIP */ 110 | 111 | #endif /* _SHFS_TOOLS_H_ */ 112 | -------------------------------------------------------------------------------- /target/linux/blkdev/osv-blk-bio.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * OSv block I/O glue 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * 35 | */ 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | extern "C" { 50 | int bio_isdone(struct bio *bio); 51 | } 52 | 53 | int 54 | bio_isdone(struct bio *bio) 55 | { 56 | int ret; 57 | 58 | WITH_LOCK(bio->bio_mutex) { 59 | //SCOPE_LOCK(bio->bio_mutex); 60 | ret = bio->bio_flags & BIO_DONE ? 1 : 0; 61 | } 62 | return ret; 63 | } 64 | -------------------------------------------------------------------------------- /target/linux/include/arch/cc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2003 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef LWIP_ARCH_CC_H 33 | #define LWIP_ARCH_CC_H 34 | 35 | /* Include some files for defining library routines */ 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #define LWIP_TIMEVAL_PRIVATE 0 42 | 43 | /* Define platform endianness */ 44 | #ifndef BYTE_ORDER 45 | #define BYTE_ORDER LITTLE_ENDIAN 46 | #endif /* BYTE_ORDER */ 47 | 48 | /* Define generic types used in lwIP */ 49 | typedef unsigned char u8_t; 50 | typedef signed char s8_t; 51 | typedef unsigned short u16_t; 52 | typedef signed short s16_t; 53 | typedef unsigned int u32_t; 54 | typedef signed int s32_t; 55 | 56 | typedef unsigned long mem_ptr_t; 57 | 58 | /* Define (sn)printf formatters for these lwIP types */ 59 | #define X8_F "02x" 60 | #define U16_F "hu" 61 | #define S16_F "hd" 62 | #define X16_F "hx" 63 | #define U32_F "u" 64 | #define S32_F "d" 65 | #define X32_F "x" 66 | 67 | /* If only we could use C99 and get %zu */ 68 | #if defined(__x86_64__) 69 | #define SZT_F "lu" 70 | #else 71 | #define SZT_F "u" 72 | #endif 73 | 74 | /* Compiler hints for packing structures */ 75 | #define PACK_STRUCT_FIELD(_x) _x 76 | #define PACK_STRUCT_STRUCT __attribute__((packed)) 77 | #define PACK_STRUCT_BEGIN 78 | #define PACK_STRUCT_END 79 | 80 | /* prototypes for printf() and abort() */ 81 | #include 82 | #include 83 | /* Plaform specific diagnostic output */ 84 | #define LWIP_PLATFORM_DIAG(_x) do {printf _x;} while(0) 85 | 86 | #ifdef LWIP_UNIX_EMPTY_ASSERT 87 | #define LWIP_PLATFORM_ASSERT(_x) 88 | #else 89 | #define LWIP_PLATFORM_ASSERT(_x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \ 90 | _x, __LINE__, __FILE__); fflush(NULL); abort();} while(0) 91 | #endif 92 | 93 | #define LWIP_RAND() ((u32_t)rand()) 94 | 95 | #endif /* LWIP_ARCH_CC_H */ 96 | -------------------------------------------------------------------------------- /target/linux/include/arch/perf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2003 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef LWIP_ARCH_PERF_H 33 | #define LWIP_ARCH_PERF_H 34 | 35 | #include 36 | 37 | #ifdef PERF 38 | #define PERF_START { \ 39 | unsigned long __c1l, __c1h, __c2l, __c2h; \ 40 | __asm__(".byte 0x0f, 0x31" : "=a" (__c1l), "=d" (__c1h)) 41 | #define PERF_STOP(x) __asm__(".byte 0x0f, 0x31" : "=a" (__c2l), "=d" (__c2h)); \ 42 | perf_print(__c1l, __c1h, __c2l, __c2h, x);} 43 | 44 | /*#define PERF_START do { \ 45 | struct tms __perf_start, __perf_end; \ 46 | times(&__perf_start) 47 | #define PERF_STOP(x) times(&__perf_end); \ 48 | perf_print_times(&__perf_start, &__perf_end, x);\ 49 | } while(0)*/ 50 | #else /* PERF */ 51 | #define PERF_START /* null definition */ 52 | #define PERF_STOP(x) /* null definition */ 53 | #endif /* PERF */ 54 | 55 | void perf_print(unsigned long c1l, unsigned long c1h, 56 | unsigned long c2l, unsigned long c2h, 57 | char *key); 58 | 59 | void perf_print_times(struct tms *start, struct tms *end, char *key); 60 | 61 | void perf_init(char *fname); 62 | 63 | #endif /* LWIP_ARCH_PERF_H */ 64 | -------------------------------------------------------------------------------- /target/linux/include/arch/sys_arch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2003 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef LWIP_ARCH_SYS_ARCH_H 33 | #define LWIP_ARCH_SYS_ARCH_H 34 | 35 | #include 36 | 37 | #define SYS_MBOX_NULL NULL 38 | #define SYS_SEM_NULL NULL 39 | 40 | typedef u32_t sys_prot_t; 41 | 42 | struct sys_sem; 43 | typedef struct sys_sem * sys_sem_t; 44 | #define sys_sem_valid(sem) (((sem) != NULL) && (*(sem) != NULL)) 45 | #define sys_sem_set_invalid(sem) do { if((sem) != NULL) { *(sem) = NULL; }}while(0) 46 | 47 | /* let sys.h use binary semaphores for mutexes */ 48 | #define LWIP_COMPAT_MUTEX 1 49 | 50 | struct sys_mbox; 51 | typedef struct sys_mbox *sys_mbox_t; 52 | #define sys_mbox_valid(mbox) (((mbox) != NULL) && (*(mbox) != NULL)) 53 | #define sys_mbox_set_invalid(mbox) do { if((mbox) != NULL) { *(mbox) = NULL; }}while(0) 54 | 55 | struct sys_thread; 56 | typedef struct sys_thread * sys_thread_t; 57 | 58 | /* include SIO driver before anything else, this way we never 59 | * load lwip/sio.h before netif/sio.h in order to prevent prototypes 60 | * redefinition. 61 | */ 62 | #include "netif/sio.h" 63 | 64 | #endif /* LWIP_ARCH_SYS_ARCH_H */ 65 | 66 | -------------------------------------------------------------------------------- /target/linux/include/netif/fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef FIFO_H 2 | #define FIFO_H 3 | 4 | #include "lwip/sys.h" 5 | 6 | /** How many bytes in fifo */ 7 | #define FIFOSIZE 2048 8 | 9 | /** fifo data structure, this one is passed to all fifo functions */ 10 | typedef struct fifo_t { 11 | u8_t data[FIFOSIZE+10]; /* data segment, +10 is a hack probably not needed.. FIXME! */ 12 | int dataslot; /* index to next char to be read */ 13 | int emptyslot; /* index to next empty slot */ 14 | int len; /* len probably not needed, may be calculated from dataslot and emptyslot in conjunction with FIFOSIZE */ 15 | 16 | sys_sem_t sem; /* semaphore protecting simultaneous data manipulation */ 17 | sys_sem_t getSem; /* sepaphore used to signal new data if getWaiting is set */ 18 | u8_t getWaiting; /* flag used to indicate that fifoget is waiting for data. fifoput is suposed to clear */ 19 | /* this flag prior to signaling the getSem semaphore */ 20 | } fifo_t; 21 | 22 | 23 | /** 24 | * Get a character from fifo 25 | * Blocking call. 26 | * @param pointer to fifo data structure 27 | * @return character read from fifo 28 | */ 29 | u8_t fifoGet(fifo_t * fifo); 30 | 31 | /** 32 | * Get a character from fifo 33 | * Non blocking call. 34 | * @param pointer to fifo data structure 35 | * @return character read from fifo, or < zero if non was available 36 | */ 37 | s16_t fifoGetNonBlock(fifo_t * fifo); 38 | 39 | /** 40 | * fifoput is called by the signalhandler when new data has arrived (or some other event is indicated) 41 | * fifoput reads directly from the serialport and is thus highly dependent on unix arch at this moment 42 | * @param fifo pointer to fifo data structure 43 | * @param fd unix file descriptor 44 | */ 45 | void fifoPut(fifo_t * fifo, int fd); 46 | 47 | /** 48 | * fifoinit initiate fifo 49 | * @param fifo pointer to fifo data structure, allocated by the user 50 | */ 51 | void fifoInit(fifo_t * fifo); 52 | 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /target/linux/include/netif/netmapif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Netmap networking glue for lwIP 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * 35 | */ 36 | #ifndef __NETMAPIF_H__ 37 | #define __NETMAPIF_H__ 38 | 39 | #include 40 | #include "lwip/opt.h" 41 | #include "netif/etharp.h" 42 | #include "netif/ppp/pppoe.h" 43 | 44 | #define NETMAP_WITH_LIBS 45 | #if NETIF_DEBUG 46 | #define DEBUG_NETMAP_USER 47 | #endif 48 | 49 | #include 50 | #include 51 | #include 52 | 53 | /** 54 | * Helper struct to hold private data used to operate the ethernet interface. 55 | * The user can pre-initialize some values (e.g., providing a mac address, 56 | * passing a opened nm_desc struct) and lwIP will use those passed data 57 | * instead. For values that are not set (e.g., dev is NULL, hwaddress is 58 | * zero), lwIP will retrieve them from the interface. 59 | * 60 | * If no netmapif struct is passed (via netif->state), lwIP is opening and 61 | * managing one by itself. lwIP will only close self-opened devices on 62 | * netif_exit(). 63 | */ 64 | struct netmapif { 65 | char ifname[IFNAMSIZ]; 66 | struct nm_desc *dev; 67 | struct eth_addr hwaddr; 68 | 69 | /* the following fields are used internally */ 70 | struct netmap_if *_nifp; 71 | struct netmap_ring *_txring; 72 | int _fd; 73 | #ifndef CONFIG_LWIP_NOTHREADS 74 | volatile int _thread_exit; 75 | char _thread_name[6]; 76 | #endif 77 | int _state_is_private; 78 | int _dev_is_private; 79 | int _hwaddr_is_private; 80 | }; 81 | 82 | #ifdef CONFIG_LWIP_NOTHREADS 83 | /* NIC I/O handling: has to be called periodically 84 | * to get received by the lwIP stack. 85 | * 86 | * Note: On threaded configuration, this call 87 | * is executed by a thread created for the device. 88 | * In this case, it has just to be ensured that this 89 | * thread get scheduled frequently. 90 | */ 91 | void netmapif_poll(struct netif *netif); 92 | #endif 93 | 94 | err_t netmapif_init(struct netif *netif); 95 | 96 | #endif /* __NETMAPIF_H__ */ 97 | -------------------------------------------------------------------------------- /target/linux/include/netif/osv-net-io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * OSv networking glue for lwIP 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * 35 | */ 36 | #ifndef __OSV_NET_IO__ 37 | #define __OSV_NET_IO__ 38 | #ifdef __cplusplus 39 | #include 40 | 41 | extern "C" 42 | { 43 | #endif 44 | 45 | struct pbuf; /* defined in lwIP */ 46 | 47 | typedef struct _onio onio; 48 | 49 | /* if name==NULL, first available device is opened */ 50 | onio *open_onio(const char *ifname, 51 | struct pbuf *(*mk_pbuf)(const unsigned char *, int), 52 | void (*rxcb)(struct pbuf *, void *), void *rxcb_argp); 53 | void close_onio(onio *dev); 54 | 55 | int onio_transmit(onio *dev, void *buf, size_t len); 56 | void onio_poll(onio *dev); 57 | 58 | size_t onio_get_hwaddr(onio *dev, void *addr_out, size_t maxlen); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #endif /* __OSV_NET_IO__ */ 64 | -------------------------------------------------------------------------------- /target/linux/include/netif/osv-net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * OSv networking glue for lwIP 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * 35 | */ 36 | #ifndef __OSV_NET_H__ 37 | #define __OSV_NET_H__ 38 | 39 | #include 40 | #include "lwip/opt.h" 41 | #include "netif/etharp.h" 42 | #include "netif/ppp/pppoe.h" 43 | 44 | #include 45 | 46 | /** 47 | * Helper struct to hold private data used to operate the ethernet interface. 48 | * The user can pre-initialize some values (e.g., providing a mac address, 49 | * passing a opened netfront_dev struct) and lwIP will use those passed data 50 | * instead. For values that are not set (e.g., dev is NULL, hwaddress is 51 | * zero), lwIP will retrieve them from the interface. 52 | * 53 | * If no netfrontif struct is passed (via netif->state), lwIP is opening and 54 | * managing one by itself. lwIP will only close self-opened devices on 55 | * netif_exit(). 56 | */ 57 | struct osvnetif { 58 | uint8_t vif_id; 59 | onio *dev; 60 | struct eth_addr hwaddr; 61 | 62 | /* the following fields are used internally */ 63 | #ifndef CONFIG_LWIP_NOTHREADS 64 | volatile int _thread_exit; 65 | char _thread_name[6]; 66 | #endif 67 | int _state_is_private; 68 | int _dev_is_private; 69 | int _hwaddr_is_private; 70 | }; 71 | 72 | #ifdef CONFIG_LWIP_NOTHREADS 73 | /* NIC I/O handling: has to be called periodically 74 | * to get received by the lwIP stack. 75 | * 76 | * Note: On threaded configuration, this call 77 | * is executed by a thread created for the device. 78 | * In this case, it has just to be ensured that this 79 | * thread get scheduled frequently. 80 | */ 81 | #define osvnetif_poll(netif) \ 82 | onio_poll(((struct osvnetif *) ((netif)->state))->dev) 83 | #endif 84 | 85 | err_t osvnetif_init(struct netif *netif); 86 | 87 | #endif /* __OSV_NET_H__ */ 88 | -------------------------------------------------------------------------------- /target/linux/include/netif/pcapif.h: -------------------------------------------------------------------------------- 1 | #ifndef LWIP_PCAPIF_H 2 | #define LWIP_PCAPIF_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "lwip/err.h" 9 | 10 | #define LWIP_MAC_ADDR_BASE {0x00,0x01,0x02,0x03,0x04,0x05} 11 | 12 | /** Set to 1 to let rx use an own thread (only for NO_SYS==0). 13 | * If set to 0, ethernetif_poll is used to poll for packets. 14 | */ 15 | #ifndef PCAPIF_RX_USE_THREAD 16 | #define PCAPIF_RX_USE_THREAD !NO_SYS 17 | #endif 18 | #if PCAPIF_RX_USE_THREAD && NO_SYS 19 | #error "Can't create a dedicated RX thread with NO_SYS==1" 20 | #endif 21 | 22 | struct netif; 23 | 24 | err_t pcapif_init (struct netif *netif); 25 | void pcapif_shutdown(struct netif *netif); 26 | #if !PCAPIF_RX_USE_THREAD 27 | void pcapif_poll (struct netif *netif); 28 | #endif /* !PCAPIF_RX_USE_THREAD */ 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* LWIP_PCAPIF_H */ 35 | -------------------------------------------------------------------------------- /target/linux/include/netif/sio.h: -------------------------------------------------------------------------------- 1 | #ifndef SIO_UNIX_H 2 | #define SIO_UNIX_H 3 | 4 | #include "lwip/sys.h" 5 | #include "lwip/netif.h" 6 | #include "netif/fifo.h" 7 | /*#include "netif/pppif.h"*/ 8 | /* BAUDRATE is defined in sio.c as it is implementation specific */ 9 | 10 | typedef struct sio_status_t { 11 | int fd; 12 | fifo_t myfifo; 13 | } sio_status_t; 14 | #define sio_fd_t sio_status_t* 15 | #define __sio_fd_t_defined 16 | 17 | /** Baudrates */ 18 | typedef enum sioBaudrates { 19 | SIO_BAUD_9600, 20 | SIO_BAUD_19200, 21 | SIO_BAUD_38400, 22 | SIO_BAUD_57600, 23 | SIO_BAUD_115200 24 | } sioBaudrates; 25 | 26 | /** 27 | * Read a char from incoming data stream, this call blocks until data has arrived 28 | * @param siostat siostatus struct, contains sio instance data, given by sio_open 29 | * @return char read from input stream 30 | */ 31 | u8_t sio_unix_recv( sio_status_t * siostat ); 32 | #define sio_recv sio_unix_recv 33 | 34 | /** 35 | * Poll for a new character from incoming data stream 36 | * @param siostat siostatus struct, contains sio instance data, given by sio_open 37 | * @return char read from input stream, or < 0 if no char was available 38 | */ 39 | s16_t sio_unix_poll(sio_status_t * siostat); 40 | 41 | /** 42 | * Parse incoming characters until a string str is recieved, blocking call 43 | * @param str zero terminated string to expect 44 | * @param siostat siostatus struct, contains sio instance data, given by sio_open 45 | */ 46 | void sio_unix_expect_string(u8_t *str, sio_status_t * siostat); 47 | 48 | /** 49 | * Write a char to output data stream 50 | * @param c char to write to output stream 51 | * @param siostat siostatus struct, contains sio instance data, given by sio_open 52 | */ 53 | void sio_unix_send( u8_t c, sio_status_t * siostat ); 54 | 55 | /** 56 | * Write a char to output data stream 57 | * @param str pointer to a zero terminated string 58 | * @param siostat siostatus struct, contains sio instance data, given by sio_open 59 | */ 60 | void sio_unix_send_string(u8_t *str, sio_status_t * siostat); 61 | 62 | /** 63 | * Flush outbuffer (send everything in buffer now), useful if some layer below is 64 | * holding on to data, waitng to fill a buffer 65 | * @param siostat siostatus struct, contains sio instance data, given by sio_open 66 | */ 67 | void sio_unix_flush( sio_status_t * siostat ); 68 | 69 | /** 70 | * Open serial port entry point from serial protocol (slipif, pppif) 71 | * @param devnum the device number to use, i.e. ttySx, comx:, etc. there x = devnum 72 | * @return siostatus struct, contains sio instance data, use when calling sio functions 73 | */ 74 | sio_status_t * sio_unix_open( int devnum ); 75 | #define sio_open sio_unix_open 76 | 77 | /** 78 | * Change baudrate of port, may close and reopen port 79 | * @param baud new baudrate 80 | * @param siostat siostatus struct, contains sio instance data, given by sio_open 81 | */ 82 | void sio_unix_change_baud( sioBaudrates baud, sio_status_t * siostat ); 83 | 84 | #if PPP_SUPPORT 85 | /** 86 | * Write buffer to serial port 87 | * @param siostat siostatus struct, contains sio instance data, given by sio_open 88 | * @param buf output buffer 89 | * @param size output buffer size 90 | */ 91 | u32_t sio_unix_write(sio_status_t * siostat, u8_t *buf, u32_t size); 92 | #define sio_write sio_unix_write 93 | 94 | /** 95 | * Read buffer from serial port 96 | * @param siostat siostatus struct, contains sio instance data, given by sio_open 97 | * @param buf input buffer 98 | * @param size input buffer size 99 | */ 100 | u32_t sio_unix_read(sio_status_t * siostat, u8_t *buf, u32_t size); 101 | #define sio_read sio_unix_read 102 | 103 | /** 104 | * Flush serial port input buffer 105 | * @param siostat siostatus struct, contains sio instance data, given by sio_open 106 | */ 107 | void sio_unix_read_abort(sio_status_t * siostat); 108 | #define sio_read_abort sio_unix_read_abort 109 | #endif /* PPP_SUPPORT */ 110 | 111 | #endif 112 | 113 | -------------------------------------------------------------------------------- /target/linux/include/netif/tapif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2003 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef LWIP_TAPIF_H 33 | #define LWIP_TAPIF_H 34 | 35 | #include "lwip/netif.h" 36 | 37 | err_t tapif_init(struct netif *netif); 38 | 39 | #ifdef CONFIG_LWIP_NOTHREADS 40 | /* NIC I/O handling: has to be called periodically 41 | * to get received by the lwIP stack. 42 | * 43 | * Note: On threaded configuration, this call 44 | * is executed by a thread created for the device. 45 | * In this case, it has just to be ensured that this 46 | * thread get scheduled frequently. 47 | */ 48 | void tapif_poll(struct netif *netif); 49 | #endif 50 | 51 | #endif /* LWIP_TAPIF_H */ 52 | -------------------------------------------------------------------------------- /target/linux/include/private_mib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Exports Private lwIP MIB 4 | */ 5 | 6 | #ifndef LWIP_HDR_PRIVATE_MIB_H 7 | #define LWIP_HDR_PRIVATE_MIB_H 8 | 9 | #include "arch/cc.h" 10 | #include "lwip/opt.h" 11 | 12 | #if LWIP_SNMP 13 | #include "lwip/snmp_structs.h" 14 | extern const struct mib_array_node mib_private; 15 | 16 | /** @todo remove this?? */ 17 | struct private_msg 18 | { 19 | u8_t dummy; 20 | }; 21 | 22 | void lwip_privmib_init(void); 23 | 24 | #define SNMP_PRIVATE_MIB_INIT() lwip_privmib_init() 25 | 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /target/linux/include/target/blkdev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Block I/O wrapper for MiniCache on OSv/Linux 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * 35 | */ 36 | #ifndef _BLKDEV_H_ 37 | #define _BLKDEV_H_ 38 | 39 | #if defined CONFIG_OSVBLK 40 | #include 41 | #else 42 | #include 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /target/linux/include/target/netdev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Networking wrapper for MiniCache on OSv/Linux 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * 35 | */ 36 | #ifndef _NETDEV_H_ 37 | #define _NETDEV_H_ 38 | 39 | #if defined CONFIG_OSVNET 40 | #include 41 | #define target_netif_init \ 42 | osvnetif_init 43 | #define target_netif_poll \ 44 | osvnetif_poll 45 | #define CONFIG_LWIP_IPDEV 46 | 47 | #elif defined CONFIG_PCAPIF 48 | #include 49 | #define target_netif_init \ 50 | pcapif_init 51 | 52 | #elif defined CONFIG_NETMAP 53 | #include 54 | #define target_netif_init \ 55 | netmapif_init 56 | #define target_netif_poll \ 57 | netmapif_poll 58 | 59 | #else 60 | #include 61 | #define target_netif_init \ 62 | tapif_init 63 | #define target_netif_poll \ 64 | tapif_poll 65 | 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /target/linux/include/target/sys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Platform wrapper for OSv/Linux 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _SYS_H_ 36 | #define _SYS_H_ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #ifndef PAGE_SHIFT 47 | #define PAGE_SHIFT 12 48 | #endif 49 | #ifndef PAGE_SIZE 50 | #define PAGE_SIZE (1<<(PAGE_SHIFT)) 51 | #endif 52 | 53 | #define target_malloc(align, size) \ 54 | malloc(size) 55 | #define target_free(ptr) \ 56 | free(ptr) 57 | 58 | #define local_irq_save(flags) \ 59 | (flags = 0) 60 | #define local_irq_restore(flags) \ 61 | (flags = 1) 62 | 63 | #define ASSERT(x) assert((x)) 64 | #define BUG_ON(x) assert(!((x))) 65 | #define printk(...) printf(__VA_ARGS__) 66 | 67 | /* shutdown */ 68 | #define TARGET_SHTDN_POWEROFF 0 69 | #define TARGET_SHTDN_REBOOT 1 70 | #define TARGET_SHTDN_SUSPEND 2 71 | 72 | #define target_suspend() \ 73 | do { \ 74 | printk("WARNING: 'suspend' is not supported by platform; ignore\n"); \ 75 | } while(0) 76 | 77 | #define target_halt() \ 78 | exit(0) 79 | 80 | #define target_reboot() \ 81 | do { \ 82 | printk("WARNING: 'reboot' is not supported by platform; use 'halt'\n"); \ 83 | target_halt(); \ 84 | } while(0) 85 | 86 | #define target_crash() \ 87 | exit(1) 88 | 89 | void app_shutdown(unsigned reason); 90 | 91 | /* scheduling */ 92 | #define msleep(ms) usleep((((ms)) * 1000l)) 93 | 94 | #ifdef CONFIG_PTH_THREADS 95 | #include 96 | 97 | #define thread pth 98 | #define schedule() \ 99 | pth_yield(NULL) 100 | #define create_thread(name, func, argp) \ 101 | pth_spawn(PTH_ATTR_DEFAULT, (void * (*)(void *)) (func), (argp)) 102 | #define exit_thread() \ 103 | pth_exit(NULL) 104 | #else 105 | #define thread (void *) 106 | #define schedule() \ 107 | do {} while (0) 108 | #define create_thread(name, func, argp) \ 109 | do {} while (0) 110 | #define exit_thread() \ 111 | do {} while (0) 112 | #endif 113 | 114 | /* semaphore */ 115 | #define init_SEMAPHORE(s, v) sem_init((s), 0, (v)) /* negative semaphores? */ 116 | #define up(s) (sem_post((s)) ? 0 : 1) 117 | #define down(s) (sem_wait((s)) ? 0 : 1) 118 | #define trydown(s) (sem_trywait((s)) ? 0 : 1) 119 | 120 | #define target_now_ns() ({ \ 121 | uint64_t r; \ 122 | struct timeval now; \ 123 | gettimeofday(&now, NULL); \ 124 | r = now.tv_usec * 1000 + now.tv_sec * 1000000000l; \ 125 | r; }) 126 | 127 | #define NSEC_TO_MSEC(ns) ((ns) / 1000000l) 128 | 129 | /* env init/exit */ 130 | #ifdef CONFIG_PTH_THREADS 131 | #define target_init() \ 132 | pth_init() 133 | #define target_exit() \ 134 | pth_exit(NULL) 135 | #else 136 | #define target_init() \ 137 | do {} while (0) 138 | #define target_exit() \ 139 | do {} while (0) 140 | #endif 141 | 142 | #endif /* _SYS_H_ */ 143 | -------------------------------------------------------------------------------- /target/linux/netif/fifo.c: -------------------------------------------------------------------------------- 1 | /* Author: Magnus Ivarsson */ 2 | 3 | /* ---------------------------------------------- */ 4 | /* --- fifo 4 unix ------------------------------ */ 5 | /* ---------------------------------------------- */ 6 | #include "netif/fifo.h" 7 | #include "lwip/debug.h" 8 | #include "lwip/def.h" 9 | #include "lwip/sys.h" 10 | #include "lwip/arch.h" 11 | #include 12 | 13 | #ifndef TRUE 14 | #define TRUE 1 15 | #endif 16 | #ifndef FALSE 17 | #define FALSE 0 18 | #endif 19 | 20 | 21 | u8_t fifoGet(fifo_t * fifo) 22 | { 23 | u8_t c; 24 | 25 | sys_sem_wait(&fifo->sem); /* enter critical section */ 26 | 27 | if (fifo->dataslot == fifo->emptyslot) 28 | { 29 | fifo->getWaiting = TRUE; /* tell putFifo to signal us when data is available */ 30 | sys_sem_signal(&fifo->sem); /* leave critical section (allow input from serial port..) */ 31 | sys_sem_wait(&fifo->getSem); /* wait 4 data */ 32 | sys_sem_wait(&fifo->sem); /* reenter critical section */ 33 | } 34 | 35 | c = fifo->data[fifo->dataslot++]; 36 | fifo->len--; 37 | 38 | if (fifo->dataslot == FIFOSIZE) 39 | { 40 | fifo->dataslot = 0; 41 | } 42 | sys_sem_signal(&fifo->sem); /* leave critical section */ 43 | return c; 44 | } 45 | 46 | 47 | s16_t fifoGetNonBlock(fifo_t * fifo) 48 | { 49 | u16_t c; 50 | 51 | sys_sem_wait(&fifo->sem); /* enter critical section */ 52 | 53 | if (fifo->dataslot == fifo->emptyslot) 54 | { 55 | /* empty fifo */ 56 | c = -1; 57 | } 58 | else 59 | { 60 | c = fifo->data[fifo->dataslot++]; 61 | fifo->len--; 62 | 63 | if (fifo->dataslot == FIFOSIZE) 64 | { 65 | fifo->dataslot = 0; 66 | } 67 | } 68 | sys_sem_signal(&fifo->sem); /* leave critical section */ 69 | return c; 70 | } 71 | 72 | 73 | void fifoPut(fifo_t * fifo, int fd) 74 | { 75 | /* FIXME: mutex around struct data.. */ 76 | int cnt=0; 77 | 78 | sys_sem_wait(&fifo->sem ); /* enter critical */ 79 | 80 | LWIP_DEBUGF( SIO_FIFO_DEBUG,("fifoput: len%d dat%d empt%d --> ", fifo->len, fifo->dataslot, fifo->emptyslot ) ); 81 | 82 | if ( fifo->emptyslot < fifo->dataslot ) 83 | { 84 | cnt = read( fd, &fifo->data[fifo->emptyslot], fifo->dataslot - fifo->emptyslot ); 85 | } 86 | else 87 | { 88 | cnt = read( fd, &fifo->data[fifo->emptyslot], FIFOSIZE-fifo->emptyslot ); 89 | } 90 | fifo->emptyslot += cnt; 91 | fifo->len += cnt; 92 | 93 | LWIP_DEBUGF( SIO_FIFO_DEBUG,("len%d dat%d empt%d\n", fifo->len, fifo->dataslot, fifo->emptyslot ) ); 94 | 95 | if ( fifo->len > FIFOSIZE ) 96 | { 97 | printf( "ERROR: fifo overrun detected len=%d, flushing\n", fifo->len ); 98 | fifo->dataslot = 0; 99 | fifo->emptyslot = 0; 100 | fifo->len = 0; 101 | } 102 | 103 | if ( fifo->emptyslot == FIFOSIZE ) 104 | { 105 | fifo->emptyslot = 0; 106 | LWIP_DEBUGF( SIO_FIFO_DEBUG, ("(WRAP) ") ); 107 | 108 | sys_sem_signal(&fifo->sem ); /* leave critical */ 109 | fifoPut( fifo, fd ); 110 | return; 111 | } 112 | if ( fifo->getWaiting ) 113 | { 114 | fifo->getWaiting = FALSE; 115 | sys_sem_signal(&fifo->getSem ); 116 | } 117 | 118 | sys_sem_signal(&fifo->sem ); /* leave critical */ 119 | return; 120 | } 121 | 122 | 123 | void fifoInit(fifo_t * fifo) 124 | { 125 | fifo->dataslot = 0; 126 | fifo->emptyslot = 0; 127 | fifo->len = 0; 128 | if(sys_sem_new(&fifo->sem, 1) != ERR_OK) { /* critical section 1=free to enter */ 129 | LWIP_ASSERT("Failed to create semaphore", 0); 130 | } 131 | if(sys_sem_new(&fifo->getSem, 0) != ERR_OK) { /* 0 = no one waiting */ 132 | LWIP_ASSERT("Failed to create semaphore", 0); 133 | } 134 | fifo->getWaiting = FALSE; 135 | } 136 | -------------------------------------------------------------------------------- /target/linux/netif/sio.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysml/minicache/4e0a52e14367e560b047f17b752d7bf7f0ab90ac/target/linux/netif/sio.c -------------------------------------------------------------------------------- /target/minios/include/target/ctldir.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Control Trigger Interface module for XenStore 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _CTLDIR_H_ 36 | #define _CTLDIR_H_ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include "shell.h" 44 | 45 | #define CTLDIR_MAX_TRIGGERS 16 46 | #define CTLDIR_MAX_NAMELEN 32 47 | 48 | //typedef int (*shfunc_ptr_t)(FILE *cio, int argc, char *argv[]); 49 | 50 | typedef char *(*ctldfunc_ptr_t)(void *cookie, char *arg); 51 | 52 | struct ctldir { 53 | char basename[CTLDIR_MAX_NAMELEN]; 54 | char threadname[CTLDIR_MAX_NAMELEN + 9]; 55 | struct thread *watcher; 56 | xenbus_event_queue xseq; 57 | 58 | const char *lock_name; 59 | 60 | uint32_t nb_trigger; 61 | char *trigger_name[CTLDIR_MAX_TRIGGERS]; 62 | char *trigger_ipath[CTLDIR_MAX_TRIGGERS]; 63 | char *trigger_opath[CTLDIR_MAX_TRIGGERS]; 64 | ctldfunc_ptr_t trigger_func[CTLDIR_MAX_TRIGGERS]; 65 | void *trigger_cookie[CTLDIR_MAX_TRIGGERS]; 66 | unsigned int trigger_ignore[CTLDIR_MAX_TRIGGERS]; 67 | }; 68 | 69 | struct ctldir *create_ctldir(const char *name); 70 | 71 | int ctldir_register_trigger(struct ctldir *ctld, const char *name, ctldfunc_ptr_t func, void *cookie); 72 | int ctldir_register_shcmd(struct ctldir *ctld, const char *name, shfunc_ptr_t func); 73 | 74 | int ctldir_start_watcher(struct ctldir *ctld); 75 | 76 | #endif /* _CTLDIR_H_ */ 77 | -------------------------------------------------------------------------------- /target/minios/include/target/netdev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Network device wrapper for MiniOS 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _NETDEV_H_ 36 | #define _NETDEV_H_ 37 | 38 | #include 39 | 40 | #ifdef CONFIG_NETMAPFRONT 41 | #include 42 | 43 | #define target_netif_init \ 44 | netmapfrontif_init 45 | #define target_netif_poll \ 46 | netmapfrontif_poll 47 | 48 | #ifdef CONFIG_SELECT_POLL 49 | #define CAN_POLL_NETDEV 50 | #define target_netif_fd \ 51 | netmapfrontif_fd 52 | #endif /* CONFIG_SELECT_POLL */ 53 | 54 | #else 55 | 56 | #define target_netif_init \ 57 | netfrontif_init 58 | #define target_netif_poll \ 59 | netfrontif_poll 60 | 61 | #ifdef CONFIG_SELECT_POLL 62 | #define CAN_POLL_NETDEV 63 | #define target_netif_fd \ 64 | netfrontif_fd 65 | #endif /* CONFIG_SELECT_POLL */ 66 | 67 | #endif /* CONFIG_NETMAPFRONT */ 68 | #endif /* _NETDEV_H_ */ 69 | -------------------------------------------------------------------------------- /target/minios/include/target/sys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Platform wrapper for MiniOS 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef _SYS_H_ 36 | #define _SYS_H_ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #define target_malloc(align, size) \ 45 | ((void *) _xmalloc((size), (align))) 46 | #define target_free(ptr) \ 47 | xfree(ptr) 48 | 49 | /* semaphores */ 50 | #include 51 | typedef struct semaphore sem_t; 52 | 53 | /* shutdown */ 54 | #include 55 | 56 | #define TARGET_SHTDN_POWEROFF \ 57 | SHUTDOWN_poweroff 58 | #define TARGET_SHTDN_REBOOT \ 59 | SHUTDOWN_reboot 60 | #define TARGET_SHTDN_SUSPEND \ 61 | SHUTDOWN_suspend 62 | 63 | #define target_suspend() \ 64 | kernel_suspend() 65 | 66 | #define target_halt() \ 67 | kernel_shutdown(SHUTDOWN_poweroff) 68 | 69 | #define target_reboot() \ 70 | kernel_shutdown(SHUTDOWN_reboot) 71 | 72 | #define target_crash() \ 73 | kernel_shutdown(SHUTDOWN_crash) 74 | 75 | #define target_init() \ 76 | do {} while(0) 77 | #define target_exit() \ 78 | do {} while(0) 79 | 80 | /* 81 | #ifdef CONFIG_ARM 82 | #define target_now_ns() ({ \ 83 | uint64_t r; \ 84 | struct timeval now; \ 85 | gettimeofday(&now, NULL); \ 86 | r = now.tv_usec * 1000 + now.tv_sec * 1000000000l; \ 87 | r; }) 88 | #else 89 | */ 90 | #define target_now_ns() (NOW()) 91 | /* 92 | #endif 93 | */ 94 | 95 | #endif /* _SYS_H_ */ 96 | -------------------------------------------------------------------------------- /testsuite.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniCache Test Suite for MicroShell 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _TESTSUITE_H_ 37 | #define _TESTSUITE_H_ 38 | 39 | #include "shfs_defs.h" 40 | #ifdef HAVE_CTLDIR 41 | #include 42 | #endif 43 | 44 | /** 45 | * Registers testsuite to micro shell + ctldir (if *cd is not NULL) 46 | */ 47 | #ifdef HAVE_CTLDIR 48 | int register_testsuite(struct ctldir *cd); 49 | #else 50 | int register_testsuite(void); 51 | #endif 52 | 53 | #endif /* _TESTSUITE_H_ */ 54 | --------------------------------------------------------------------------------