Browse Source

nbd: new package nbd-server

Network block device server allows to export a block device from router
to remote host. This is particularly useful if no network filesystem
server is feasible or direct access to a block device is needed.

It's been tested for nearly a month on ar71xx (TL-WR842ND) and proved to
be very stable and efficient solution.
The package comes with init.d script and conf.d file allowing to
configure most nbd-server options using standard uci interface.

Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
lilik-openwrt-22.03
Marcin Jurkowski 12 years ago
parent
commit
9bf1fa6622
3 changed files with 169 additions and 1 deletions
  1. +30
    -1
      net/nbd/Makefile
  2. +31
    -0
      net/nbd/files/nbd-server.conf
  3. +108
    -0
      net/nbd/files/nbd-server.init

+ 30
- 1
net/nbd/Makefile View File

@ -37,12 +37,24 @@ define Package/nbd/description
This package contains the network block device client.
endef
define Package/nbd-server
SECTION:=net
CATEGORY:=Network
TITLE:=Network Block Device Server
URL:=http://nbd.sourceforge.net
DEPENDS:=+glib2
endef
define Package/nbd-server/description
This package contains the network block device server.
endef
CONFIGURE_ARGS+= \
--disable-glibtest
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
nbd-client
nbd-client nbd-server
endef
define Package/nbd/install
@ -51,3 +63,20 @@ define Package/nbd/install
endef
$(eval $(call BuildPackage,nbd))
define Package/nbd-server/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nbd-server $(1)/usr/bin/
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/nbd-server.conf $(1)/etc/config/nbd-server
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/nbd-server.init $(1)/etc/init.d/nbd-server
endef
define Package/nbd-server/conffiles
/etc/config/nbd-server
/etc/nbd-server/conf.d
/etc/nbd-server/allow
endef
$(eval $(call BuildPackage,nbd-server))

+ 31
- 0
net/nbd/files/nbd-server.conf View File

@ -0,0 +1,31 @@
config nbd-server
option enabled 0
# option port 10809
# option user root
# option group root
# option allowlist 0
# option includedir '/etc/nbd-server/conf.d'
# option listenaddr '0.0.0.0'
# option oldstyle 0
config share usb_sda1
option filename '/dev/sda1'
# option authfile '/etc/nbd-server/allow'
# option timeout 0
# option flush 0
# option fua 0
# option rotational 0
# option sync 0
# option discard 0
# option maxconnections 10
# option filesize 1000000
# option multifile 0
# option copyonwrite 0
# option sparse_cow 1
# option readonly 0
# option prerun '/bin/true'
# option postrun '/bin/true'
# option virtstyle 'ipliteral'
# option oldstyle_port 12345
# option oldstyle_listenaddr '0.0.0.0'

+ 108
- 0
net/nbd/files/nbd-server.init View File

@ -0,0 +1,108 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2012 OpenWrt.org
START=60
SERVICE_USE_PID=1
CONFIGFILE="/var/etc/nbd-server.conf"
append_plain() {
echo "$1" >> $CONFIGFILE
}
append_val_str() {
local resultname="$1"
local cfg="$2"
local uciname="${3:-$1}"
local value=
config_get value "$cfg" "$uciname"
if [ -z "$value" ]; then
return
fi
append_plain "$resultname = $value"
}
append_val_bool() {
local resultname="$1"
local cfg="$2"
local uciname="${3:-$1}"
local value=
config_get_bool value "$cfg" "$uciname"
if [ -z "$value" ]; then
return
fi
[ $value == 1 ] && value="true" || value="false"
append_plain "$resultname = $value"
}
config_handle_generic() {
local cfg="$1"
append_plain "[generic]"
append_val_str user "$cfg"
append_val_str group "$cfg"
append_val_str port "$cfg"
append_val_str listenaddr "$cfg"
append_val_bool allowlist "$cfg"
append_val_str includedir "$cfg"
append_val_bool oldstyle "$cfg"
config_get_bool SERVICE_ENABLED "$cfg" enabled 0
}
config_handle_share() {
local cfg="$1"
append_plain
append_plain "[$cfg]"
append_val_str exportname "$cfg" filename
append_val_str timeout "$cfg"
append_val_str maxconnections "$cfg"
append_val_str authfile "$cfg"
append_val_str filesize "$cfg"
append_val_str readonly "$cfg"
append_val_str multifile "$cfg"
append_val_str copyonwrite "$cfg"
append_val_bool sparse_cow "$cfg"
append_val_bool flush "$cfg"
append_val_bool fua "$cfg"
append_val_bool rotational "$cfg"
append_val_bool sync "$cfg"
append_val_bool discard "$cfg"
append_val_str prerun "$cfg"
append_val_str postrun "$cfg"
append_val_str virtstyle "$cfg"
append_val_str port "$cfg" oldstyle_port
append_val_str listenaddr "$cfg" oldstyle_listenaddr
}
config_read() {
mkdir -p $(dirname $CONFIGFILE)
echo -n > $CONFIGFILE
config_load nbd-server
config_foreach config_handle_generic nbd-server
config_foreach config_handle_share share
}
start() {
config_read
if [ "$SERVICE_ENABLED" = "1" ]; then
service_start /usr/bin/nbd-server \
--pid-file /var/run/nbd-server.pid \
--config-file=$CONFIGFILE
fi
}
stop() {
service_stop /usr/bin/nbd-server
}

Loading…
Cancel
Save