1 /* NBD client library in userspace
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 /* Test interop with nbdkit or qemu-nbd, and systemd socket activation. */
34 main (int argc
, char *argv
[])
36 struct nbd_handle
*nbd
;
37 char tmpfile
[] = "/tmp/nbdXXXXXX";
43 /* Create a large sparse temporary file. */
44 fd
= mkstemp (tmpfile
);
46 ftruncate (fd
, SIZE
) == -1 ||
54 fprintf (stderr
, "%s\n", nbd_get_error ());
58 char *args
[] = { SERVER
, SERVER_PARAMS
, NULL
};
59 if (nbd_connect_systemd_socket_activation (nbd
, args
) == -1) {
60 fprintf (stderr
, "%s\n", nbd_get_error ());
64 actual_size
= nbd_get_size (nbd
);
65 if (actual_size
== -1) {
66 fprintf (stderr
, "%s\n", nbd_get_error ());
69 if (actual_size
!= SIZE
) {
70 fprintf (stderr
, "%s: actual size %" PRIi64
" <> expected size %d",
71 argv
[0], actual_size
, SIZE
);
75 if (nbd_pread (nbd
, buf
, sizeof buf
, 0, 0) == -1) {
76 fprintf (stderr
, "%s\n", nbd_get_error ());
80 if (nbd_shutdown (nbd
, 0) == -1) {
81 fprintf (stderr
, "%s\n", nbd_get_error ());
91 exit (r
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
);