diff --git a/config.example b/config.example new file mode 100644 index 0000000..186f476 --- /dev/null +++ b/config.example @@ -0,0 +1,33 @@ +[generic] + # The [generic] section is required, even if nothing is specified + # there. + # When either of these options are specified, nbd-server drops + # privileges to the given user and group after opening ports, but + # _before_ opening files. + user = nbd + group = nbd + # Since version 2.9.17, nbd-server will do exports on a name + # basis (the used name is the name of the section in which the + # export is specified). This however required an incompatible + # protocol change. To enable backwards-compatible port-based + # exports, uncomment the following line: + # oldstyle = true +[export1] + exportname = /export/nbd/export1-file + # The following line will be ignored unless the + # "oldstyle = true" line in the generic section above is + # enabled. + port = 12345 + authfile = /export/nbd/export1-authfile + timeout = 30 + filesize = 10000000 + readonly = false + multifile = false + copyonwrite = false + prerun = dd if=/dev/zero of=%s bs=1k count=500 + postrun = rm -f %s +[otherexport] + exportname = /export/nbd/experiment + # The other options are all optional, except this one in case + # the oldstyle option is used in [generic]: + # port = 12346 diff --git a/nbd-2.9.25-close.diff b/nbd-2.9.25-close.diff index 3f123f5..d37d7dd 100644 --- a/nbd-2.9.25-close.diff +++ b/nbd-2.9.25-close.diff @@ -1,8 +1,10 @@ ---- nbd-2.9.25/nbd-client.c.orig 2012-01-05 15:40:31.962826124 -0500 -+++ nbd-2.9.25/nbd-client.c 2012-01-05 15:40:53.627555277 -0500 -@@ -70,6 +70,7 @@ - len=read(fd, buf, 256); - buf[len-1]='\0'; +Index: nbd-3.9/nbd-client.c +=================================================================== +--- nbd-3.9.orig/nbd-client.c ++++ nbd-3.9/nbd-client.c +@@ -79,6 +79,7 @@ int check_conn(char* devname, int do_pri + } + buf[(len < 256) ? len : 255]='\0'; if(do_print) printf("%s\n", buf); + close(fd); return 0; diff --git a/nbd-3.3.tar.bz2 b/nbd-3.3.tar.bz2 deleted file mode 100644 index 7002360..0000000 --- a/nbd-3.3.tar.bz2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:83105718dcab9eee7ea152d6e5f4928095f0d3e21dcf92e43eef183e29a80c19 -size 515909 diff --git a/nbd-3.9.tar.xz b/nbd-3.9.tar.xz new file mode 100644 index 0000000..fe1c41f --- /dev/null +++ b/nbd-3.9.tar.xz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af8ba47cf041c61dd2ae5f064fd856bed8affbee426f3d6441beb5764ffc71c3 +size 459260 diff --git a/nbd-server.service b/nbd-server.service new file mode 100644 index 0000000..17abc67 --- /dev/null +++ b/nbd-server.service @@ -0,0 +1,13 @@ +[Unit] +Description=Network Block Device server +Documentation=man:nbd-server(1) man:nbd-server(5) +After=syslog.target network.target + +[Service] +Type=forking +EnvironmentFile=/etc/sysconfig/nbd-server +ExecStart=/usr/bin/nbd-server $OPTIONS +PIDFile=/run/nbd-server.pid + +[Install] +WantedBy=multi-user.target diff --git a/nbd-server.sysconfig b/nbd-server.sysconfig new file mode 100644 index 0000000..e8f582d --- /dev/null +++ b/nbd-server.sysconfig @@ -0,0 +1,2 @@ +# Command line options for nbd-server +OPTIONS="" diff --git a/nbd.changes b/nbd.changes index 7efe5e0..e649823 100644 --- a/nbd.changes +++ b/nbd.changes @@ -1,3 +1,38 @@ +------------------------------------------------------------------- +Thu Mar 5 12:28:06 UTC 2015 - mpluskal@suse.com + +- Cleanup spec-file with spec-cleaner +- Do not generate config.example from README + * add config.example as source +- Add unit file (nbd-server.service) +- Add sysconfig template (nbd-server.sysconfig) +- Add no-return-nonvoid.patch +- Update requirements +- Update to 3.9 + * AF_UNIX support + * Fixed test suite on non-GNU getopt() implementations + * New "treefiles" mode, which exports a gazillion of page-sized + files; useful for exporting things which are stored on an + SSHFS or amazon AWS (trough FUSE) or similar, where every + write causes an upload to the backend storage + * New "cowdir" option, allowing to specify where copy-on-write + files are written. + * Minor changes so that nbd-client can now also be compiled for + the Android platform. This required removal of the -swap + command line option, which requires the mlockall() system + call, unavailable on Android. + * Protocol update: a reserved bit is used to avoid sending + the 124 bytes of useless data at the beginning of the + negotiation. The change is implemented so that things will + still work with clients not supporting this option, however. + * gznbd is now built by the same build system, rather than + a separate one. Note however that gznbd is still + unmaintained; it should be considered a "contrib" feature. + * "nbd-server -V" will now output the nbd-server version number. + * Various fixes found through Coverity and the clang static + analyzer, and lots of other minor things too small to + mention here. + ------------------------------------------------------------------- Sun Nov 09 19:27:00 UTC 2014 - Led diff --git a/nbd.spec b/nbd.spec index fc1d639..7461b88 100644 --- a/nbd.spec +++ b/nbd.spec @@ -1,7 +1,7 @@ # # spec file for package nbd # -# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,22 +17,34 @@ Name: nbd -BuildRequires: doxygen -BuildRequires: glib2-devel >= 2.26.0 -PreReq: %insserv_prereq coreutils -Version: 3.3 +Version: 3.9 Release: 0 -Source: http://downloads.sourceforge.net/project/%{name}/%{name}/%{version}/%{name}-%{version}.tar.bz2 -Source2: init.nbd-server -Patch2: nbd-2.9.25-close.diff -Patch3: nbd-2.9.25-doxyfile.diff Summary: Network Block Device Server and Client Utilities License: GPL-2.0+ Group: Productivity/Networking/Other Url: http://nbd.sourceforge.net/ -Prefix: /usr -BuildRoot: %{_tmppath}/%{name}-%{version}-build +Source0: http://downloads.sourceforge.net/project/%{name}/%{name}/%{version}/%{name}-%{version}.tar.xz +Source1: %{name}-server.service +Source2: init.nbd-server +Source3: config.example +Source4: nbd-server.sysconfig +Patch2: nbd-2.9.25-close.diff +Patch3: nbd-2.9.25-doxyfile.diff +# fix return value +Patch4: no-return-nonvoid.patch +BuildRequires: doxygen +BuildRequires: glib2-devel >= 2.26.0 +BuildRequires: xz +Requires(pre): %fillup_prereq +Requires(pre): coreutils Suggests: nbd-doc +BuildRoot: %{_tmppath}/%{name}-%{version}-build +%if 0%{?suse_version} >= 1210 +BuildRequires: systemd-rpm-macros +%systemd_requires +%else +Requires(pre): %insserv_prereq +%endif %description This package contains nbd-server. It is the server backend for the nbd @@ -41,7 +53,7 @@ network block device driver that's in the Linux kernel. nbd can be used to have a filesystem stored on another machine. It does provide a block device, not a file system; so unless you put a clustering filesystem on top of it, you can't access it simultaneously -from more than one client. Use NFS or a real cluster FS (such as +from more than one client. Use NFS or a real cluster FS (such as ocfs2) if you want to do this. nbd-server can export a file (which may contain a filesystem image) or a partition. Swapping over nbd is possible as well, though it's said not to be safe against OOM and @@ -52,15 +64,6 @@ the connection closes. The package also contains the nbd-client tools, which you need to configure the nbd devices on the client side. - - -Authors: --------- - Wouter Verhelst - Anton Altaparmakov - Pavel Machek - Paul Clements - %package doc Summary: Network Block Device Server and Client Utilities Group: Productivity/Networking/Other @@ -73,7 +76,7 @@ device (nbd) utilities. nbd can be used to have a filesystem stored on another machine. It does provide a block device, not a file system; so unless you put a clustering filesystem on top of it, you can't access it simultaneously -from more than one client. Use NFS or a real cluster FS (such as +from more than one client. Use NFS or a real cluster FS (such as ocfs2) if you want to do this. nbd-server can export a file (which may contain a filesystem image) or a partition. Swapping over nbd is possible as well, though it's said not to be safe against OOM and @@ -81,90 +84,111 @@ should not be used for that case. nbd-server also has a copy-on-write mode where changes are saved to a separate file and thrown away when the connection closes. - - -Authors: --------- - Wouter Verhelst - Anton Altaparmakov - Pavel Machek - Paul Clements - %prep -%setup +%setup -q %patch2 -p1 %patch3 -p1 +%patch4 -p1 %build -export CFLAGS="$RPM_OPT_FLAGS -fstack-protector -fno-strict-aliasing" -./configure --with-gnu-ld --prefix=/usr --mandir=%{_mandir} \ - --infodir=%{_infodir} --libdir=%{_libdir} --libexecdir=%{_libdir} \ - --program-prefix="" --sysconfdir=/etc --build=%{_target_cpu}-suse-linux -make +export CFLAGS="%{optflags} -fstack-protector -fno-strict-aliasing" +%configure + +make %{?_smp_mflags} doxygen doc/Doxyfile.in %install -make install DESTDIR=$RPM_BUILD_ROOT man_MANS='nbd-client.8 nbd-server.1 nbd-server.5 nbd-trdump.1' -mkdir -p $RPM_BUILD_ROOT/etc/init.d -install %SOURCE2 $RPM_BUILD_ROOT/etc/init.d/nbd-server -mkdir -p $RPM_BUILD_ROOT/usr/bin -ln -s ../../etc/init.d/nbd-server $RPM_BUILD_ROOT/usr/bin/rcnbd-server +make install DESTDIR=%{buildroot} man_MANS='nbd-client.8 nbd-server.1 nbd-server.5 nbd-trdump.1' +mkdir -p %{buildroot}%{_sysconfdir}/init.d +mkdir -p %{buildroot}%{_prefix}/bin + +%if 0%{?suse_version} >= 1210 +install -D -m 0644 %{SOURCE1} %{buildroot}/%{_unitdir}/%{name}-server.service +ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}-server +%else +install %{SOURCE2} %{buildroot}%{_initddir}/nbd-server +ln -s ../..%{_initddir}/nbd-server %{buildroot}%{_sbindir}/rc%{name}-server +%endif + #echo "#Port file options" > $RPM_BUILD_ROOT/etc/nbd-server.conf -mkdir -p $RPM_BUILD_ROOT/etc/nbd-server -touch $RPM_BUILD_ROOT/etc/nbd-server/config -touch $RPM_BUILD_ROOT/etc/nbd-server/allow -grep -A16 -B1 '^\[generic\]' README > $RPM_BUILD_ROOT/etc/nbd-server/config.example +mkdir -p %{buildroot}%{_sysconfdir}/nbd-server +touch %{buildroot}%{_sysconfdir}/nbd-server/config +touch %{buildroot}%{_sysconfdir}/nbd-server/allow +install -D -m 0644 %{SOURCE3} %{buildroot}%{_sysconfdir}/nbd-server/config.example +install -D -m 0644 %{SOURCE4} %{buildroot}%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}-server %files %defattr(-,root,root) -%attr(0755,root,root) /usr/sbin/nbd-client -%attr(0755,root,root) /usr/bin/nbd-server -%attr(0755,root,root) /usr/bin/nbd-trdump -%attr(0755,root,root) /etc/init.d/nbd-server -%attr(0755,root,root) /usr/bin/rcnbd-server +%attr(0755,root,root) %{_sbindir}/nbd-client +%attr(0755,root,root) %{_bindir}/nbd-server +%attr(0755,root,root) %{_bindir}/nbd-trdump +%{_sbindir}/rcnbd-server +%if 0%{?suse_version} >= 1210 +%{_unitdir}/%{name}-server.service +%else +%{_initddir}/%{name}-server +%endif %{_mandir}/man1/nbd-server.1.gz %{_mandir}/man1/nbd-trdump.1.gz %{_mandir}/man5/nbd-server.5.gz %{_mandir}/man8/nbd-client.8.gz -%doc README -#%%config(noreplace) /etc/nbd-server.conf -%dir /etc/nbd-server -%ghost %config(noreplace) /etc/nbd-server/config -%ghost %config(noreplace) /etc/nbd-server/allow -%config /etc/nbd-server/config.example +%doc README.md +%dir %{_sysconfdir}/nbd-server +%ghost %config(noreplace) %{_sysconfdir}/nbd-server/config +%ghost %config(noreplace) %{_sysconfdir}/nbd-server/allow +%config %{_sysconfdir}/nbd-server/config.example +%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}-server %files doc %defattr(-,root,root) %doc doc/html %post +%if 0%{?suse_version} >= 1210 +%service_add_post %{name}-server.service +%fillup_only -n nbd-server +%else %{fillup_and_insserv -f nbd-server} -if test -e /etc/nbd-server.conf; then +%endif +if test -e %{_sysconfdir}/nbd-server.conf; then # Do we have to create a generic section? unset generic - if test -e /etc/nbd-server/config; then generic=1; fi - grep -vE '^(#|[[:blank:]]*$)' /etc/nbd-server.conf | + if test -e %{_sysconfdir}/nbd-server/config; then generic=1; fi + grep -vE '^(#|[[:blank:]]*$)' %{_sysconfdir}/nbd-server.conf | while read port file opts; do if test -z "$generic"; then - echo > /etc/nbd-server/config - echo "[generic]" >> /etc/nbd-server/config - echo " # No generic options yet" >> /etc/nbd-server/config - echo >> /etc/nbd-server/config + echo > %{_sysconfdir}/nbd-server/config + echo "[generic]" >> %{_sysconfdir}/nbd-server/config + echo " # No generic options yet" >> %{_sysconfdir}/nbd-server/config + echo >> %{_sysconfdir}/nbd-server/config generic=1 fi FN=${file%/*} nm="cvt.$port.${FN##*/}.${file##*/}" echo " ... convert $port $file $opts -> $nm" - /usr/bin/nbd-server $port $file $opts -o "$nm" >> /etc/nbd-server/config + %{_bindir}/nbd-server $port $file $opts -o "$nm" >> %{_sysconfdir}/nbd-server/config done - mv /etc/nbd-server.conf /etc/nbd-server.conf.converted + mv %{_sysconfdir}/nbd-server.conf %{_sysconfdir}/nbd-server.conf.converted fi %postun -%{insserv_cleanup} +%if 0%{?suse_version} >= 1210 +%service_del_postun %{name}-server.service +%else +%insserv_cleanup %restart_on_update nbd-server +%endif + +%pre +%if 0%{?suse_version} >= 1210 +%service_add_pre %{name}-server.service +%endif %preun +%if 0%{?suse_version} >= 1210 +%service_del_preun %{name}-server.service +%else %{stop_on_removal nbd-server} +%endif %changelog diff --git a/no-return-nonvoid.patch b/no-return-nonvoid.patch new file mode 100644 index 0000000..b8a6d35 --- /dev/null +++ b/no-return-nonvoid.patch @@ -0,0 +1,12 @@ +Index: nbd-3.9/nbd-server.c +=================================================================== +--- nbd-3.9.orig/nbd-server.c ++++ nbd-3.9/nbd-server.c +@@ -1595,6 +1595,7 @@ CLIENT* negotiate(int net, CLIENT *clien + err("Negotiation failed/12: %m"); + return NULL; + } ++ return NULL; + } + + /** sending macro. */