Network Block Device  @PACKAGE_VERSION@
nbd-client.c
Go to the documentation of this file.
1 /*
2  * Open connection for network block device
3  *
4  * Copyright 1997,1998 Pavel Machek, distribute under GPL
5  * <pavel@atrey.karlin.mff.cuni.cz>
6  * Copyright (c) 2002 - 2011 Wouter Verhelst <w@uter.be>
7  *
8  * Version 1.0 - 64bit issues should be fixed, now
9  * Version 1.1 - added bs (blocksize) option (Alexey Guzeev, aga@permonline.ru)
10  * Version 1.2 - I added new option '-d' to send the disconnect request
11  * Version 2.0 - Version synchronised with server
12  * Version 2.1 - Check for disconnection before INIT_PASSWD is received
13  * to make errormsg a bit more helpful in case the server can't
14  * open the exported file.
15  * 16/03/2010 - Add IPv6 support.
16  * Kitt Tientanopajai <kitt@kitty.in.th>
17  * Neutron Soutmun <neo.neutron@gmail.com>
18  * Suriya Soutmun <darksolar@gmail.com>
19  */
20 
21 #include "config.h"
22 #include "lfs.h"
23 
24 #include <sys/ioctl.h>
25 #include <sys/socket.h>
26 #include <sys/types.h>
27 #include <unistd.h>
28 #include <netinet/tcp.h>
29 #include <netinet/in.h>
30 #include <netdb.h>
31 #include "netdb-compat.h"
32 #include <stdio.h>
33 #include <fcntl.h>
34 #include <syslog.h>
35 #include <stdlib.h>
36 #include <sys/mount.h>
37 #include <sys/mman.h>
38 #include <signal.h>
39 #include <errno.h>
40 #include <getopt.h>
41 #include <stdarg.h>
42 
43 #include <linux/ioctl.h>
44 #define MY_NAME "nbd_client"
45 #include "cliserv.h"
46 
47 #ifdef WITH_SDP
48 #include <sdp_inet.h>
49 #endif
50 
51 #define NBDC_DO_LIST 1
52 
53 int check_conn(char* devname, int do_print) {
54  char buf[256];
55  char* p;
56  int fd;
57  int len;
58 
59  if( (p=strrchr(devname, '/')) ) {
60  devname=p+1;
61  }
62  if((p=strchr(devname, 'p'))) {
63  /* We can't do checks on partitions. */
64  *p='\0';
65  }
66  snprintf(buf, 256, "/sys/block/%s/pid", devname);
67  if((fd=open(buf, O_RDONLY))<0) {
68  if(errno==ENOENT) {
69  return 1;
70  } else {
71  return 2;
72  }
73  }
74  len=read(fd, buf, 256);
75  buf[len-1]='\0';
76  if(do_print) printf("%s\n", buf);
77  close(fd);
78  return 0;
79 }
80 
81 int opennet(char *name, char* portstr, int sdp) {
82  int sock;
83  struct addrinfo hints;
84  struct addrinfo *ai = NULL;
85  struct addrinfo *rp = NULL;
86  int e;
87 
88  memset(&hints,'\0',sizeof(hints));
89  hints.ai_family = AF_UNSPEC;
90  hints.ai_socktype = SOCK_STREAM;
91  hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV;
92  hints.ai_protocol = IPPROTO_TCP;
93 
94  e = getaddrinfo(name, portstr, &hints, &ai);
95 
96  if(e != 0) {
97  fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(e));
98  freeaddrinfo(ai);
99  return -1;
100  }
101 
102  if(sdp) {
103 #ifdef WITH_SDP
104  if (ai->ai_family == AF_INET)
105  ai->ai_family = AF_INET_SDP;
106  else (ai->ai_family == AF_INET6)
107  ai->ai_family = AF_INET6_SDP;
108 #else
109  err("Can't do SDP: I was not compiled with SDP support!");
110 #endif
111  }
112 
113  for(rp = ai; rp != NULL; rp = rp->ai_next) {
114  sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
115 
116  if(sock == -1)
117  continue; /* error */
118 
119  if(connect(sock, rp->ai_addr, rp->ai_addrlen) != -1)
120  break; /* success */
121  }
122 
123  if (rp == NULL) {
124  err_nonfatal("Socket failed: %m");
125  return -1;
126  }
127 
128  setmysockopt(sock);
129 
130  freeaddrinfo(ai);
131  return sock;
132 }
133 
134 void ask_list(int sock) {
135  uint32_t opt;
136  uint32_t opt_server;
137  uint32_t len;
138  uint32_t reptype;
139  uint64_t magic;
140  char buf[1024];
141 
142  magic = ntohll(opts_magic);
143  if (write(sock, &magic, sizeof(magic)) < 0)
144  err("Failed/2.2: %m");
145 
146  /* Ask for the list */
147  opt = htonl(NBD_OPT_LIST);
148  if(write(sock, &opt, sizeof(opt)) < 0) {
149  err("writing list option failed: %m");
150  }
151  /* Send the length (zero) */
152  len = htonl(0);
153  if(write(sock, &len, sizeof(len)) < 0) {
154  err("writing length failed: %m");
155  }
156  /* newline, move away from the "Negotiation:" line */
157  printf("\n");
158  do {
159  memset(buf, 0, 1024);
160  if(read(sock, &magic, sizeof(magic)) < 0) {
161  err("Reading magic from server: %m");
162  }
163  if(read(sock, &opt_server, sizeof(opt_server)) < 0) {
164  err("Reading option: %m");
165  }
166  if(read(sock, &reptype, sizeof(reptype)) <0) {
167  err("Reading reply from server: %m");
168  }
169  if(read(sock, &len, sizeof(len)) < 0) {
170  err("Reading length from server: %m");
171  }
172  magic=ntohll(magic);
173  len=ntohl(len);
174  reptype=ntohl(reptype);
175  if(magic != rep_magic) {
176  err("Not enough magic from server");
177  }
178  if(reptype & NBD_REP_FLAG_ERROR) {
179  switch(reptype) {
180  case NBD_REP_ERR_POLICY:
181  fprintf(stderr, "\nE: listing not allowed by server.\n");
182  break;
183  default:
184  fprintf(stderr, "\nE: unexpected error from server.\n");
185  break;
186  }
187  if(len) {
188  if(read(sock, buf, len) < 0) {
189  fprintf(stderr, "\nE: could not read error message from server\n");
190  }
191  fprintf(stderr, "Server said: %s\n", buf);
192  }
193  exit(EXIT_FAILURE);
194  } else {
195  if(len) {
196  if(reptype != NBD_REP_SERVER) {
197  err("Server sent us a reply we don't understand!");
198  }
199  if(read(sock, &len, sizeof(len)) < 0) {
200  fprintf(stderr, "\nE: could not read export name length from server\n");
201  exit(EXIT_FAILURE);
202  }
203  len=ntohl(len);
204  if(read(sock, buf, len) < 0) {
205  fprintf(stderr, "\nE: could not read export name from server\n");
206  exit(EXIT_FAILURE);
207  }
208  printf("%s\n", buf);
209  }
210  }
211  } while(reptype != NBD_REP_ACK);
212  opt=htonl(NBD_OPT_ABORT);
213  len=htonl(0);
214  magic=htonll(opts_magic);
215  if (write(sock, &magic, sizeof(magic)) < 0)
216  err("Failed/2.2: %m");
217  if (write(sock, &opt, sizeof(opt)) < 0)
218  err("Failed writing abort");
219  if (write(sock, &len, sizeof(len)) < 0)
220  err("Failed writing length");
221 }
222 
223 void negotiate(int sock, u64 *rsize64, u32 *flags, char* name, uint32_t needed_flags, uint32_t client_flags, uint32_t do_opts) {
224  u64 magic, size64;
225  uint16_t tmp;
226  char buf[256] = "\0\0\0\0\0\0\0\0\0";
227 
228  printf("Negotiation: ");
229  if (read(sock, buf, 8) < 0)
230  err("Failed/1: %m");
231  if (strlen(buf)==0)
232  err("Server closed connection");
233  if (strcmp(buf, INIT_PASSWD))
234  err("INIT_PASSWD bad");
235  printf(".");
236  if (read(sock, &magic, sizeof(magic)) < 0)
237  err("Failed/2: %m");
238  magic = ntohll(magic);
239  if(name) {
240  uint32_t opt;
241  uint32_t namesize;
242 
243  if (magic != opts_magic) {
244  if(magic == cliserv_magic) {
245  err("It looks like you're trying to connect to an oldstyle server with a named export. This won't work.");
246  }
247  }
248  printf(".");
249  if(read(sock, &tmp, sizeof(uint16_t)) < 0) {
250  err("Failed reading flags: %m");
251  }
252  *flags = ((u32)ntohs(tmp));
253  if((needed_flags & *flags) != needed_flags) {
254  /* There's currently really only one reason why this
255  * check could possibly fail, but we may need to change
256  * this error message in the future... */
257  fprintf(stderr, "\nE: Server does not support listing exports\n");
258  exit(EXIT_FAILURE);
259  }
260 
261  client_flags = htonl(client_flags);
262  if (write(sock, &client_flags, sizeof(client_flags)) < 0)
263  err("Failed/2.1: %m");
264 
265  if(do_opts & NBDC_DO_LIST) {
266  ask_list(sock);
267  exit(EXIT_SUCCESS);
268  }
269 
270  /* Write the export name that we're after */
271  magic = htonll(opts_magic);
272  if (write(sock, &magic, sizeof(magic)) < 0)
273  err("Failed/2.2: %m");
274 
275  opt = ntohl(NBD_OPT_EXPORT_NAME);
276  if (write(sock, &opt, sizeof(opt)) < 0)
277  err("Failed/2.3: %m");
278  namesize = (u32)strlen(name);
279  namesize = ntohl(namesize);
280  if (write(sock, &namesize, sizeof(namesize)) < 0)
281  err("Failed/2.4: %m");
282  if (write(sock, name, strlen(name)) < 0)
283  err("Failed/2.4: %m");
284  } else {
285  if (magic != cliserv_magic) {
286  if(magic != opts_magic)
287  err("Not enough cliserv_magic");
288  else
289  err("It looks like you're trying to connect to a newstyle server with the oldstyle protocol. Try the -N option.");
290  }
291  printf(".");
292  }
293 
294  if (read(sock, &size64, sizeof(size64)) <= 0) {
295  if (!errno)
296  err("Server closed connection");
297  err("Failed/3: %m\n");
298  }
299  size64 = ntohll(size64);
300 
301  if ((size64>>12) > (uint64_t)~0UL) {
302  printf("size = %luMB", (unsigned long)(size64>>20));
303  err("Exported device is too big for me. Get 64-bit machine :-(\n");
304  } else
305  printf("size = %luMB", (unsigned long)(size64>>20));
306 
307  if(!name) {
308  if (read(sock, flags, sizeof(*flags)) < 0)
309  err("Failed/4: %m\n");
310  *flags = ntohl(*flags);
311  } else {
312  if(read(sock, &tmp, sizeof(tmp)) < 0)
313  err("Failed/4: %m\n");
314  *flags |= (uint32_t)ntohs(tmp);
315  }
316 
317  if (read(sock, &buf, 124) < 0)
318  err("Failed/5: %m\n");
319  printf("\n");
320 
321  *rsize64 = size64;
322 }
323 
324 void setsizes(int nbd, u64 size64, int blocksize, u32 flags) {
325  unsigned long size;
326  int read_only = (flags & NBD_FLAG_READ_ONLY) ? 1 : 0;
327 
328  if (size64>>12 > (uint64_t)~0UL)
329  err("Device too large.\n");
330  else {
331  if (ioctl(nbd, NBD_SET_BLKSIZE, 4096UL) < 0)
332  err("Ioctl/1.1a failed: %m\n");
333  size = (unsigned long)(size64>>12);
334  if (ioctl(nbd, NBD_SET_SIZE_BLOCKS, size) < 0)
335  err("Ioctl/1.1b failed: %m\n");
336  if (ioctl(nbd, NBD_SET_BLKSIZE, (unsigned long)blocksize) < 0)
337  err("Ioctl/1.1c failed: %m\n");
338  fprintf(stderr, "bs=%d, sz=%llu bytes\n", blocksize, 4096ULL*size);
339  }
340 
341  ioctl(nbd, NBD_CLEAR_SOCK);
342 
343  /* ignore error as kernel may not support */
344  ioctl(nbd, NBD_SET_FLAGS, (unsigned long) flags);
345 
346  if (ioctl(nbd, BLKROSET, (unsigned long) &read_only) < 0)
347  err("Unable to set read-only attribute for device");
348 }
349 
350 void set_timeout(int nbd, int timeout) {
351  if (timeout) {
352  if (ioctl(nbd, NBD_SET_TIMEOUT, (unsigned long)timeout) < 0)
353  err("Ioctl NBD_SET_TIMEOUT failed: %m\n");
354  fprintf(stderr, "timeout=%d\n", timeout);
355  }
356 }
357 
358 void finish_sock(int sock, int nbd, int swap) {
359  if (ioctl(nbd, NBD_SET_SOCK, sock) < 0)
360  err("Ioctl NBD_SET_SOCK failed: %m\n");
361 
362  if (swap)
363  mlockall(MCL_CURRENT | MCL_FUTURE);
364 }
365 
366 static int
367 oom_adjust(const char *file, const char *value)
368 {
369  int fd, rc;
370  size_t len;
371 
372  fd = open(file, O_WRONLY);
373  if (fd < 0)
374  return -1;
375  len = strlen(value);
376  rc = write(fd, value, len) != (ssize_t) len;
377  close(fd);
378  return rc ? -1 : 0;
379 }
380 
381 void usage(char* errmsg, ...) {
382  if(errmsg) {
383  char tmp[256];
384  va_list ap;
385  va_start(ap, errmsg);
386  snprintf(tmp, 256, "ERROR: %s\n\n", errmsg);
387  vfprintf(stderr, tmp, ap);
388  va_end(ap);
389  } else {
390  fprintf(stderr, "nbd-client version %s\n", PACKAGE_VERSION);
391  }
392  fprintf(stderr, "Usage: nbd-client host port nbd_device [-block-size|-b block size] [-timeout|-t timeout] [-swap|-s] [-sdp|-S] [-persist|-p] [-nofork|-n]\n");
393  fprintf(stderr, "Or : nbd-client -name|-N name host [port] nbd_device [-block-size|-b block size] [-timeout|-t timeout] [-swap|-s] [-sdp|-S] [-persist|-p] [-nofork|-n]\n");
394  fprintf(stderr, "Or : nbd-client -d nbd_device\n");
395  fprintf(stderr, "Or : nbd-client -c nbd_device\n");
396  fprintf(stderr, "Or : nbd-client -h|--help\n");
397  fprintf(stderr, "Or : nbd-client -l|--list host\n");
398  fprintf(stderr, "Default value for blocksize is 1024 (recommended for ethernet)\n");
399  fprintf(stderr, "Allowed values for blocksize are 512,1024,2048,4096\n"); /* will be checked in kernel :) */
400  fprintf(stderr, "Note, that kernel 2.4.2 and older ones do not work correctly with\n");
401  fprintf(stderr, "blocksizes other than 1024 without patches\n");
402  fprintf(stderr, "Default value for port with -N is 10809. Note that port must always be numeric\n");
403 }
404 
405 void disconnect(char* device) {
406  int nbd = open(device, O_RDWR);
407 
408  if (nbd < 0)
409  err("Cannot open NBD: %m\nPlease ensure the 'nbd' module is loaded.");
410  printf("Disconnecting: que, ");
411  if (ioctl(nbd, NBD_CLEAR_QUE)< 0)
412  err("Ioctl failed: %m\n");
413  printf("disconnect, ");
414  if (ioctl(nbd, NBD_DISCONNECT)<0)
415  err("Ioctl failed: %m\n");
416  printf("sock, ");
417  if (ioctl(nbd, NBD_CLEAR_SOCK)<0)
418  err("Ioctl failed: %m\n");
419  printf("done\n");
420 }
421 
422 int main(int argc, char *argv[]) {
423  char* port=NULL;
424  int sock, nbd;
425  int blocksize=1024;
426  char *hostname=NULL;
427  char *nbddev=NULL;
428  int swap=0;
429  int cont=0;
430  int timeout=0;
431  int sdp=0;
432  int G_GNUC_UNUSED nofork=0; // if -dNOFORK
433  u64 size64;
434  u32 flags;
435  int c;
436  int nonspecial=0;
437  char* name=NULL;
438  uint32_t needed_flags=0;
439  uint32_t cflags=0;
440  uint32_t opts=0;
441  sigset_t block, old;
442  struct option long_options[] = {
443  { "block-size", required_argument, NULL, 'b' },
444  { "check", required_argument, NULL, 'c' },
445  { "disconnect", required_argument, NULL, 'd' },
446  { "help", no_argument, NULL, 'h' },
447  { "list", no_argument, NULL, 'l' },
448  { "name", required_argument, NULL, 'N' },
449  { "nofork", no_argument, NULL, 'n' },
450  { "persist", no_argument, NULL, 'p' },
451  { "sdp", no_argument, NULL, 'S' },
452  { "swap", no_argument, NULL, 's' },
453  { "timeout", required_argument, NULL, 't' },
454  { 0, 0, 0, 0 },
455  };
456 
457  logging();
458 
459  while((c=getopt_long_only(argc, argv, "-b:c:d:hlnN:pSst:", long_options, NULL))>=0) {
460  switch(c) {
461  case 1:
462  // non-option argument
463  if(strchr(optarg, '=')) {
464  // old-style 'bs=' or 'timeout='
465  // argument
466  fprintf(stderr, "WARNING: old-style command-line argument encountered. This is deprecated.\n");
467  if(!strncmp(optarg, "bs=", 3)) {
468  optarg+=3;
469  goto blocksize;
470  }
471  if(!strncmp(optarg, "timeout=", 8)) {
472  optarg+=8;
473  goto timeout;
474  }
475  usage("unknown option %s encountered", optarg);
476  exit(EXIT_FAILURE);
477  }
478  switch(nonspecial++) {
479  case 0:
480  // host
481  hostname=optarg;
482  break;
483  case 1:
484  // port
485  if(!strtol(optarg, NULL, 0)) {
486  // not parseable as a number, assume it's the device and we have a name
487  nbddev = optarg;
488  nonspecial++;
489  } else {
490  port = optarg;
491  }
492  break;
493  case 2:
494  // device
495  nbddev = optarg;
496  break;
497  default:
498  usage("too many non-option arguments specified");
499  exit(EXIT_FAILURE);
500  }
501  break;
502  case 'b':
503  blocksize:
504  blocksize=(int)strtol(optarg, NULL, 0);
505  break;
506  case 'c':
507  return check_conn(optarg, 1);
508  case 'd':
509  disconnect(optarg);
510  exit(EXIT_SUCCESS);
511  case 'h':
512  usage(NULL);
513  exit(EXIT_SUCCESS);
514  case 'l':
515  needed_flags |= NBD_FLAG_FIXED_NEWSTYLE;
516  cflags |= NBD_FLAG_C_FIXED_NEWSTYLE;
517  opts |= NBDC_DO_LIST;
518  name="";
519  nbddev="";
520  port = NBD_DEFAULT_PORT;
521  break;
522  case 'n':
523  nofork=1;
524  break;
525  case 'N':
526  name=optarg;
527  if(!port) {
528  port = NBD_DEFAULT_PORT;
529  }
530  break;
531  case 'p':
532  cont=1;
533  break;
534  case 's':
535  swap=1;
536  break;
537  case 'S':
538  sdp=1;
539  break;
540  case 't':
541  timeout:
542  timeout=strtol(optarg, NULL, 0);
543  break;
544  default:
545  fprintf(stderr, "E: option eaten by 42 mice\n");
546  exit(EXIT_FAILURE);
547  }
548  }
549 
550  if((!port && !name) || !hostname || !nbddev) {
551  usage("not enough information specified");
552  exit(EXIT_FAILURE);
553  }
554 
555  sock = opennet(hostname, port, sdp);
556  if (sock < 0)
557  exit(EXIT_FAILURE);
558 
559  negotiate(sock, &size64, &flags, name, needed_flags, cflags, opts);
560 
561  nbd = open(nbddev, O_RDWR);
562  if (nbd < 0)
563  err("Cannot open NBD: %m\nPlease ensure the 'nbd' module is loaded.");
564 
565  setsizes(nbd, size64, blocksize, flags);
566  set_timeout(nbd, timeout);
567  finish_sock(sock, nbd, swap);
568  if (swap) {
569  /* try linux >= 2.6.36 interface first */
570  if (oom_adjust("/proc/self/oom_score_adj", "-1000")) {
571  /* fall back to linux <= 2.6.35 interface */
572  oom_adjust("/proc/self/oom_adj", "-17");
573  }
574  }
575 
576  /* Go daemon */
577 
578 #ifndef NOFORK
579  if(!nofork) {
580  if (daemon(0,0) < 0)
581  err("Cannot detach from terminal");
582  }
583 #endif
584  do {
585 #ifndef NOFORK
586 
587  sigfillset(&block);
588  sigdelset(&block, SIGKILL);
589  sigdelset(&block, SIGTERM);
590  sigdelset(&block, SIGPIPE);
591  sigprocmask(SIG_SETMASK, &block, &old);
592 
593  if (!fork()) {
594  /* Due to a race, the kernel NBD driver cannot
595  * call for a reread of the partition table
596  * in the handling of the NBD_DO_IT ioctl().
597  * Therefore, this is done in the first open()
598  * of the device. We therefore make sure that
599  * the device is opened at least once after the
600  * connection was made. This has to be done in a
601  * separate process, since the NBD_DO_IT ioctl()
602  * does not return until the NBD device has
603  * disconnected.
604  */
605  while(check_conn(nbddev, 0)) {
606  sleep(1);
607  }
608  open(nbddev, O_RDONLY);
609  exit(0);
610  }
611 #endif
612 
613  if (ioctl(nbd, NBD_DO_IT) < 0) {
614  int error = errno;
615  fprintf(stderr, "nbd,%d: Kernel call returned: %d", getpid(), error);
616  if(error==EBADR) {
617  /* The user probably did 'nbd-client -d' on us.
618  * quit */
619  cont=0;
620  } else {
621  if(cont) {
622  u64 new_size;
623  u32 new_flags;
624 
625  close(sock); close(nbd);
626  for (;;) {
627  fprintf(stderr, " Reconnecting\n");
628  sock = opennet(hostname, port, sdp);
629  if (sock >= 0)
630  break;
631  sleep (1);
632  }
633  nbd = open(nbddev, O_RDWR);
634  if (nbd < 0)
635  err("Cannot open NBD: %m");
636  negotiate(sock, &new_size, &new_flags, name, needed_flags, cflags, opts);
637  if (size64 != new_size) {
638  err("Size of the device changed. Bye");
639  }
640  setsizes(nbd, size64, blocksize,
641  new_flags);
642 
643  set_timeout(nbd, timeout);
644  finish_sock(sock,nbd,swap);
645  }
646  }
647  } else {
648  /* We're on 2.4. It's not clearly defined what exactly
649  * happened at this point. Probably best to quit, now
650  */
651  fprintf(stderr, "Kernel call returned.");
652  cont=0;
653  }
654  } while(cont);
655  printf("Closing: que, ");
656  ioctl(nbd, NBD_CLEAR_QUE);
657  printf("sock, ");
658  ioctl(nbd, NBD_CLEAR_SOCK);
659  printf("done\n");
660  return 0;
661 }
void setsizes(int nbd, u64 size64, int blocksize, u32 flags)
Definition: nbd-client.c:324
void disconnect(char *device)
Definition: nbd-client.c:405
#define NBD_REP_FLAG_ERROR
Definition: cliserv.h:159
#define NBD_OPT_LIST
Definition: cliserv.h:154
#define NBD_CLEAR_SOCK
Definition: nbd.h:24
#define NBD_SET_SOCK
Definition: nbd.h:20
u64 ntohll(u64 a)
Definition: cliserv.h:138
void finish_sock(int sock, int nbd, int swap)
Definition: nbd-client.c:358
void setmysockopt(int sock)
Definition: cliserv.h:64
#define NBD_REP_ERR_POLICY
Definition: cliserv.h:161
u64 rep_magic
Definition: cliserv.h:59
#define NBD_SET_SIZE_BLOCKS
Definition: nbd.h:27
void err_nonfatal(const char *s)
Definition: cliserv.h:92
void usage(char *errmsg,...)
Definition: nbd-client.c:381
#define NBD_OPT_EXPORT_NAME
Definition: cliserv.h:152
#define NBD_REP_ACK
Definition: cliserv.h:157
#define NBD_OPT_ABORT
Definition: cliserv.h:153
u64 cliserv_magic
Definition: cliserv.h:57
#define NBDC_DO_LIST
Definition: nbd-client.c:51
#define AI_NUMERICSERV
Definition: netdb-compat.h:21
#define NBD_DISCONNECT
Definition: nbd.h:28
#define NBD_SET_TIMEOUT
Definition: nbd.h:29
int check_conn(char *devname, int do_print)
Definition: nbd-client.c:53
#define NBD_FLAG_C_FIXED_NEWSTYLE
Definition: cliserv.h:168
static uint64_t size
void err(const char *s) G_GNUC_NORETURN
Definition: cliserv.h:120
void ask_list(int sock)
Definition: nbd-client.c:134
#define NBD_FLAG_READ_ONLY
Definition: nbd.h:45
#define G_GNUC_UNUSED
Definition: cliserv.h:88
#define NBD_SET_FLAGS
Definition: nbd.h:30
void set_timeout(int nbd, int timeout)
Definition: nbd-client.c:350
#define NBD_SET_BLKSIZE
Definition: nbd.h:21
int main(int argc, char **argv)
#define htonll
Definition: cliserv.h:146
static int oom_adjust(const char *file, const char *value)
Definition: nbd-client.c:367
#define NBD_REP_SERVER
Definition: cliserv.h:158
#define NBD_DEFAULT_PORT
Definition: cliserv.h:148
#define PACKAGE_VERSION
Definition: config.h:150
int opennet(char *name, char *portstr, int sdp)
Definition: nbd-client.c:81
u64 opts_magic
Definition: cliserv.h:58
#define NBD_FLAG_FIXED_NEWSTYLE
Definition: cliserv.h:166
#define INIT_PASSWD
Definition: cliserv.h:60
__be32 magic
Definition: nbd.h:37
#define NBD_DO_IT
Definition: nbd.h:23
#define NBD_CLEAR_QUE
Definition: nbd.h:25
void negotiate(int sock, u64 *rsize64, u32 *flags, char *name, uint32_t needed_flags, uint32_t client_flags, uint32_t do_opts)
Definition: nbd-client.c:223
void logging(void)
Definition: cliserv.h:125
__be32 len
Definition: nbd.h:41