Commit 742bf0d3 authored by Hilko Bengen's avatar Hilko Bengen

New upstream version 0.1.6

parent 4d25f18d
......@@ -44,6 +44,7 @@ Makefile.in
/examples/threaded-reads-and-writes
/examples/simple-fetch-first-sector
/examples/simple-reads-and-writes
/examples/strict-structured-reads
/generator/generator-cache.v1
/generator/stamp-generator
/html/*.?.html
......
......@@ -22,7 +22,8 @@ ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = \
.dir-locals.el \
.gitignore \
html/pod.css
html/pod.css \
$(NULL)
SUBDIRS = \
generator \
......@@ -36,7 +37,8 @@ SUBDIRS = \
sh \
ocaml \
ocaml/examples \
interop
interop \
$(NULL)
noinst_SCRIPTS = run
......
This diff is collapsed.
This diff is collapsed.
......@@ -18,6 +18,9 @@
# common-rules.mk is included in every Makefile.am.
# subdir-rules.mk is included only in subdirectories.
# Convenient list terminator
NULL =
CLEANFILES = *~
$(generator_built): $(top_builddir)/generator/stamp-generator
......
#! /bin/sh
# Wrapper for compilers which do not understand '-c -o'.
scriptversion=2018-03-07.03; # UTC
# Copyright (C) 1999-2018 Free Software Foundation, Inc.
# Written by Tom Tromey <tromey@cygnus.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
nl='
'
# We need space, tab and new line, in precisely that order. Quoting is
# there to prevent tools from complaining about whitespace usage.
IFS=" "" $nl"
file_conv=
# func_file_conv build_file lazy
# Convert a $build file to $host form and store it in $file
# Currently only supports Windows hosts. If the determined conversion
# type is listed in (the comma separated) LAZY, no conversion will
# take place.
func_file_conv ()
{
file=$1
case $file in
/ | /[!/]*) # absolute file, and not a UNC file
if test -z "$file_conv"; then
# lazily determine how to convert abs files
case `uname -s` in
MINGW*)
file_conv=mingw
;;
CYGWIN*)
file_conv=cygwin
;;
*)
file_conv=wine
;;
esac
fi
case $file_conv/,$2, in
*,$file_conv,*)
;;
mingw/*)
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
;;
cygwin/*)
file=`cygpath -m "$file" || echo "$file"`
;;
wine/*)
file=`winepath -w "$file" || echo "$file"`
;;
esac
;;
esac
}
# func_cl_dashL linkdir
# Make cl look for libraries in LINKDIR
func_cl_dashL ()
{
func_file_conv "$1"
if test -z "$lib_path"; then
lib_path=$file
else
lib_path="$lib_path;$file"
fi
linker_opts="$linker_opts -LIBPATH:$file"
}
# func_cl_dashl library
# Do a library search-path lookup for cl
func_cl_dashl ()
{
lib=$1
found=no
save_IFS=$IFS
IFS=';'
for dir in $lib_path $LIB
do
IFS=$save_IFS
if $shared && test -f "$dir/$lib.dll.lib"; then
found=yes
lib=$dir/$lib.dll.lib
break
fi
if test -f "$dir/$lib.lib"; then
found=yes
lib=$dir/$lib.lib
break
fi
if test -f "$dir/lib$lib.a"; then
found=yes
lib=$dir/lib$lib.a
break
fi
done
IFS=$save_IFS
if test "$found" != yes; then
lib=$lib.lib
fi
}
# func_cl_wrapper cl arg...
# Adjust compile command to suit cl
func_cl_wrapper ()
{
# Assume a capable shell
lib_path=
shared=:
linker_opts=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
eat=1
case $2 in
*.o | *.[oO][bB][jJ])
func_file_conv "$2"
set x "$@" -Fo"$file"
shift
;;
*)
func_file_conv "$2"
set x "$@" -Fe"$file"
shift
;;
esac
;;
-I)
eat=1
func_file_conv "$2" mingw
set x "$@" -I"$file"
shift
;;
-I*)
func_file_conv "${1#-I}" mingw
set x "$@" -I"$file"
shift
;;
-l)
eat=1
func_cl_dashl "$2"
set x "$@" "$lib"
shift
;;
-l*)
func_cl_dashl "${1#-l}"
set x "$@" "$lib"
shift
;;
-L)
eat=1
func_cl_dashL "$2"
;;
-L*)
func_cl_dashL "${1#-L}"
;;
-static)
shared=false
;;
-Wl,*)
arg=${1#-Wl,}
save_ifs="$IFS"; IFS=','
for flag in $arg; do
IFS="$save_ifs"
linker_opts="$linker_opts $flag"
done
IFS="$save_ifs"
;;
-Xlinker)
eat=1
linker_opts="$linker_opts $2"
;;
-*)
set x "$@" "$1"
shift
;;
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
func_file_conv "$1"
set x "$@" -Tp"$file"
shift
;;
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
func_file_conv "$1" mingw
set x "$@" "$file"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -n "$linker_opts"; then
linker_opts="-link$linker_opts"
fi
exec "$@" $linker_opts
exit 1
}
eat=
case $1 in
'')
echo "$0: No command. Try '$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: compile [--help] [--version] PROGRAM [ARGS]
Wrapper for compilers which do not understand '-c -o'.
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
arguments, and rename the output as expected.
If you are trying to build a whole package this is not the
right script to run: please start by reading the file 'INSTALL'.
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "compile $scriptversion"
exit $?
;;
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
func_cl_wrapper "$@" # Doesn't return...
;;
esac
ofile=
cfile=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
# So we strip '-o arg' only if arg is an object.
eat=1
case $2 in
*.o | *.obj)
ofile=$2
;;
*)
set x "$@" -o "$2"
shift
;;
esac
;;
*.c)
cfile=$1
set x "$@" "$1"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -z "$ofile" || test -z "$cfile"; then
# If no '-o' option was seen then we might have been invoked from a
# pattern rule where we don't need one. That is ok -- this is a
# normal compilation that the losing compiler can handle. If no
# '.c' file was seen then we are probably linking. That is also
# ok.
exec "$@"
fi
# Name of file we expect compiler to create.
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
# Create the lock directory.
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
# that we are using for the .o file. Also, base the name on the expected
# object file name, since that is what matters with a parallel build.
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
while true; do
if mkdir "$lockdir" >/dev/null 2>&1; then
break
fi
sleep 1
done
# FIXME: race condition here if user kills between mkdir and trap.
trap "rmdir '$lockdir'; exit 1" 1 2 15
# Run the compile.
"$@"
ret=$?
if test -f "$cofile"; then
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
elif test -f "${cofile}bj"; then
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
fi
rmdir "$lockdir"
exit $ret
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'before-save-hook 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC0"
# time-stamp-end: "; # UTC"
# End:
This diff is collapsed.
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* gnutls found at compile time. */
#undef HAVE_GNUTLS
/* Define to 1 if you have the `gnutls_session_set_verify_cert' function. */
#undef HAVE_GNUTLS_SESSION_SET_VERIFY_CERT
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* libxml2 found at compile time. */
#undef HAVE_LIBXML2
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define if you have POSIX threads libraries and header files. */
#undef HAVE_PTHREAD
/* Have PTHREAD_PRIO_INHERIT. */
#undef HAVE_PTHREAD_PRIO_INHERIT
/* Python library found at compile time */
#undef HAVE_PYTHON
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#undef LT_OBJDIR
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if the C compiler supports function prototypes. */
#undef PROTOTYPES
/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
#undef PTHREAD_CREATE_JOINABLE
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Default TLS session priority string */
#undef TLS_PRIORITY
/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif
/* Enable extensions on HP NonStop. */
#ifndef _TANDEM_SOURCE
# undef _TANDEM_SOURCE
#endif
/* Enable general extensions on Solaris. */
#ifndef __EXTENSIONS__
# undef __EXTENSIONS__
#endif
/* Version number of package */
#undef VERSION
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS
/* Define for large files, on AIX-style hosts. */
#undef _LARGE_FILES
/* Define to 1 if on MINIX. */
#undef _MINIX
/* Define to 2 if the system does not provide POSIX.1 features except with
this defined. */
#undef _POSIX_1_SOURCE
/* Define to 1 if you need to in order for `stat' and other things to work. */
#undef _POSIX_SOURCE
/* Define like PROTOTYPES; this can be used by system headers. */
#undef __PROTOTYPES
This diff is collapsed.
This diff is collapsed.
......@@ -15,7 +15,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
AC_INIT([libnbd],[0.1.5])
AC_INIT([libnbd],[0.1.6])
AC_CONFIG_MACRO_DIR([m4])
m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],[],
......
This diff is collapsed.
......@@ -18,17 +18,20 @@
include $(top_srcdir)/subdir-rules.mk
generator_built = \
libnbd-api.pod
libnbd-api.pod \
$(NULL)
EXTRA_DIST = \
$(generator_built) \
libnbd.pod
libnbd.pod \
$(NULL)
if HAVE_POD
man_MANS = \
libnbd.3 \
libnbd-api.3
libnbd-api.3 \
$(NULL)
CLEANFILES += $(man_MANS)
libnbd.3: libnbd.pod
......
This diff is collapsed.
This diff is collapsed.
......@@ -169,7 +169,27 @@ has completed:
}
For almost all high level synchronous calls (eg. C<nbd_pread>) there
is a low level asynchronous equivalent (eg. C<nbd_aio_pread>).
are two low level asynchronous equivalents (eg. C<nbd_aio_pread> for
starting a command, and C<nbd_aio_pread_notify> for also registering
a callback to be invoked right before the command is complete).
=head1 CALLBACKS
Some of the high-level commands (C<nbd_pread_structured>,
C<nbd_block_status>) involve the use of a callback function invoked by
the state machine at appropriate points in the server's reply before
the overall command is complete. Also, all of the low-level commands
have a notify variant that registers a callback function used right
before the command is marked complete. These callback functions
include a parameter C<error> containing the value of any error
detected so far; if the callback function fails, it should assign back
into C<error> and return C<-1> to change the resulting error of the
overall command.
The callbacks are invoked at a point where the libnbd lock is held; as
such, it is unsafe for the callback to call any C<nbd_*> APIs on the
same nbd object, as it would cause deadlock. Functions that take two
callback pointers share the same opaque data for both calls.
=head1 ERROR HANDLING
......
......@@ -23,42 +23,73 @@ noinst_PROGRAMS = \
batched-read-write \
simple-fetch-first-sector \
simple-reads-and-writes \
threaded-reads-and-writes
threaded-reads-and-writes \
strict-structured-reads \
$(NULL)
simple_fetch_first_sector_SOURCES = \
simple-fetch-first-sector.c
simple-fetch-first-sector.c \
$(NULL)
simple_fetch_first_sector_CPPFLAGS = \
-I$(top_srcdir)/include
-I$(top_srcdir)/include \
$(NULL)
simple_fetch_first_sector_CFLAGS = \
$(WARNINGS_CFLAGS)
$(WARNINGS_CFLAGS) \
$(NULL)
simple_fetch_first_sector_LDADD = \
$(top_builddir)/lib/libnbd.la
$(top_builddir)/lib/libnbd.la \
$(NULL)
simple_reads_and_writes_SOURCES = \
simple-reads-and-writes.c
simple-reads-and-writes.c \
$(NULL)
simple_reads_and_writes_CPPFLAGS = \
-I$(top_srcdir)/include
-I$(top_srcdir)/include \
$(NULL)
simple_reads_and_writes_CFLAGS = \
$(WARNINGS_CFLAGS)
$(WARNINGS_CFLAGS) \
$(NULL)
simple_reads_and_writes_LDADD = \
$(top_builddir)/lib/libnbd.la
$(top_builddir)/lib/libnbd.la \
$(NULL)
strict_structured_reads_SOURCES = \
strict-structured-reads.c \
$(NULL)
strict_structured_reads_CPPFLAGS = \
-I$(top_srcdir)/include \
$(NULL)
strict_structured_reads_CFLAGS = \
$(WARNINGS_CFLAGS) \
$(NULL)
strict_structured_reads_LDADD = \
$(top_builddir)/lib/libnbd.la \
$(NULL)
threaded_reads_and_writes_SOURCES = \
threaded-reads-and-writes.c
threaded-reads-and-writes.c \
$(NULL)
threaded_reads_and_writes_CPPFLAGS = \
-I$(top_srcdir)/include
-I$(top_srcdir)/include \
$(NULL)
threaded_reads_and_writes_CFLAGS = \
$(WARNINGS_CFLAGS) \
$(PTHREAD_CFLAGS)
$(PTHREAD_CFLAGS) \
$(NULL)
threaded_reads_and_writes_LDADD = \
$(top_builddir)/lib/libnbd.la \
$(PTHREAD_LIBS)
$(PTHREAD_LIBS) \
$(NULL)
batched_read_write_SOURCES = \
batched-read-write.c
batched-read-write.c \
$(NULL)
batched_read_write_CPPFLAGS = \
-I$(top_srcdir)/include
-I$(top_srcdir)/include \
$(NULL)
batched_read_write_CFLAGS = \
$(WARNINGS_CFLAGS)
$(WARNINGS_CFLAGS) \
$(NULL)
batched_read_write_LDADD = \
$(top_builddir)/lib/libnbd.la
$(top_builddir)/lib/libnbd.la \
$(NULL)
This diff is collapsed.
......@@ -48,26 +48,22 @@ try_deadlock (void *arg)
struct pollfd fds[1];
size_t i;
int64_t handles[2], done;
size_t in_flight; /* counts number of requests in flight */
int dir, r;
/* Issue commands. */
in_flight = 0;
handles[0] = nbd_aio_pread (nbd, in, packetsize, 0, 0);
if (handles[0] == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
goto error;
}
in_flight++;
handles[1] = nbd_aio_pwrite (nbd, out, packetsize, packetsize, 0);
if (handles[1] == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
goto error;
}
in_flight++;
/* Now wait for commands to retire, or for deadlock to occur */
while (in_flight > 0) {
while (nbd_aio_in_flight (nbd) > 0) {
if (nbd_aio_is_dead (nbd) || nbd_aio_is_closed (nbd)) {
fprintf (stderr, "connection is dead or closed\n");
goto error;
......@@ -96,23 +92,20 @@ try_deadlock (void *arg)
/* If a command is ready to retire, retire it. */
while ((done = nbd_aio_peek_command_completed (nbd)) > 0) {
for (i = 0; i < in_flight; ++i) {
for (i = 0; i < sizeof handles / sizeof handles[0]; ++i) {
if (handles[i] == done) {
r = nbd_aio_command_completed (nbd, handles[i]);
if (r == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
goto error;
}
assert (r);
memmove (&handles[i], &handles[i+1],
sizeof (handles[0]) * (in_flight - i - 1));
break;
assert (r == 1);
handles[i] = 0;
}
}
assert (i < in_flight);
in_flight--;
}