Bladeren bron

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>
Marcin Jurkowski 12 jaren geleden
bovenliggende
commit
9bf1fa6622
3 gewijzigde bestanden met toevoegingen van 169 en 1 verwijderingen
  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 Bestand weergeven

@@ -37,12 +37,24 @@ define Package/nbd/description
37 37
   This package contains the network block device client.
38 38
 endef
39 39
 
40
+define Package/nbd-server
41
+  SECTION:=net
42
+  CATEGORY:=Network
43
+  TITLE:=Network Block Device Server
44
+  URL:=http://nbd.sourceforge.net
45
+  DEPENDS:=+glib2
46
+endef
47
+
48
+define Package/nbd-server/description
49
+  This package contains the network block device server.
50
+endef
51
+
40 52
 CONFIGURE_ARGS+= \
41 53
 	--disable-glibtest
42 54
 
43 55
 define Build/Compile
44 56
 	$(MAKE) -C $(PKG_BUILD_DIR) \
45
-		nbd-client
57
+		nbd-client nbd-server
46 58
 endef
47 59
 
48 60
 define Package/nbd/install
@@ -51,3 +63,20 @@ define Package/nbd/install
51 63
 endef
52 64
 
53 65
 $(eval $(call BuildPackage,nbd))
66
+
67
+define Package/nbd-server/install
68
+	$(INSTALL_DIR) $(1)/usr/bin
69
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nbd-server $(1)/usr/bin/
70
+	$(INSTALL_DIR) $(1)/etc/config
71
+	$(INSTALL_CONF) ./files/nbd-server.conf $(1)/etc/config/nbd-server
72
+	$(INSTALL_DIR) $(1)/etc/init.d
73
+	$(INSTALL_BIN) ./files/nbd-server.init $(1)/etc/init.d/nbd-server
74
+endef
75
+
76
+define Package/nbd-server/conffiles
77
+/etc/config/nbd-server
78
+/etc/nbd-server/conf.d
79
+/etc/nbd-server/allow
80
+endef
81
+
82
+$(eval $(call BuildPackage,nbd-server))

+ 31
- 0
net/nbd/files/nbd-server.conf Bestand weergeven

@@ -0,0 +1,31 @@
1
+config nbd-server
2
+	option enabled 0
3
+#	option port 10809
4
+#	option user root
5
+#	option group root
6
+#	option allowlist 0
7
+#	option includedir '/etc/nbd-server/conf.d'
8
+#	option listenaddr '0.0.0.0'
9
+#	option oldstyle 0
10
+
11
+config share usb_sda1
12
+	option filename '/dev/sda1'
13
+#	option authfile '/etc/nbd-server/allow'
14
+#	option timeout 0
15
+#	option flush 0
16
+#	option fua 0
17
+#	option rotational 0
18
+#	option sync 0
19
+#	option discard 0
20
+#	option maxconnections 10
21
+#	option filesize 1000000
22
+#	option multifile 0
23
+#	option copyonwrite 0
24
+#	option sparse_cow 1
25
+#	option readonly 0
26
+#	option prerun '/bin/true'
27
+#	option postrun '/bin/true'
28
+#	option virtstyle 'ipliteral'
29
+#	option oldstyle_port 12345
30
+#	option oldstyle_listenaddr '0.0.0.0'
31
+

+ 108
- 0
net/nbd/files/nbd-server.init Bestand weergeven

@@ -0,0 +1,108 @@
1
+#!/bin/sh /etc/rc.common
2
+# Copyright (C) 2012 OpenWrt.org
3
+
4
+START=60
5
+SERVICE_USE_PID=1
6
+
7
+CONFIGFILE="/var/etc/nbd-server.conf"
8
+
9
+
10
+append_plain() {
11
+	echo "$1" >> $CONFIGFILE
12
+}
13
+
14
+append_val_str() {
15
+	local resultname="$1"
16
+	local cfg="$2"
17
+	local uciname="${3:-$1}"
18
+	local value=
19
+
20
+	config_get value "$cfg" "$uciname"
21
+
22
+	if [ -z "$value" ]; then
23
+		return
24
+	fi
25
+	append_plain "$resultname = $value"
26
+}
27
+
28
+append_val_bool() {
29
+	local resultname="$1"
30
+	local cfg="$2"
31
+	local uciname="${3:-$1}"
32
+	local value=
33
+
34
+	config_get_bool value "$cfg" "$uciname"
35
+	if [ -z "$value" ]; then
36
+		return
37
+	fi
38
+
39
+	[ $value == 1 ] && value="true" || value="false"
40
+	append_plain "$resultname = $value"
41
+}
42
+
43
+config_handle_generic() {
44
+	local cfg="$1"
45
+
46
+	append_plain "[generic]"
47
+	append_val_str user "$cfg"
48
+	append_val_str group "$cfg"
49
+	append_val_str port "$cfg"
50
+	append_val_str listenaddr "$cfg"
51
+	append_val_bool allowlist "$cfg"
52
+	append_val_str includedir "$cfg"
53
+	append_val_bool oldstyle "$cfg"
54
+
55
+	config_get_bool SERVICE_ENABLED "$cfg" enabled 0
56
+}
57
+
58
+config_handle_share() {
59
+	local cfg="$1"
60
+
61
+	append_plain
62
+	append_plain "[$cfg]"
63
+	append_val_str exportname "$cfg" filename
64
+	append_val_str timeout "$cfg"
65
+	append_val_str maxconnections "$cfg"
66
+	append_val_str authfile "$cfg"
67
+	append_val_str filesize "$cfg"
68
+	append_val_str readonly "$cfg"
69
+	append_val_str multifile "$cfg"
70
+	append_val_str copyonwrite "$cfg"
71
+	append_val_bool sparse_cow "$cfg"
72
+	append_val_bool flush "$cfg"
73
+	append_val_bool fua "$cfg"
74
+	append_val_bool rotational "$cfg"
75
+	append_val_bool sync "$cfg"
76
+	append_val_bool discard "$cfg"
77
+	append_val_str prerun "$cfg"
78
+	append_val_str postrun "$cfg"
79
+	append_val_str virtstyle "$cfg"
80
+	append_val_str port "$cfg" oldstyle_port
81
+	append_val_str listenaddr "$cfg" oldstyle_listenaddr
82
+}
83
+
84
+config_read() {
85
+
86
+	mkdir -p $(dirname $CONFIGFILE)
87
+	echo -n > $CONFIGFILE
88
+
89
+	config_load nbd-server
90
+	config_foreach config_handle_generic nbd-server
91
+	config_foreach config_handle_share share
92
+}
93
+
94
+start() {
95
+	config_read
96
+
97
+	if [ "$SERVICE_ENABLED" = "1" ]; then
98
+		service_start /usr/bin/nbd-server \
99
+			--pid-file /var/run/nbd-server.pid \
100
+			--config-file=$CONFIGFILE
101
+	fi
102
+}
103
+
104
+stop() {
105
+	service_stop /usr/bin/nbd-server
106
+}
107
+
108
+