<command>&dhpackage;</command>
<arg choice=plain><option>-d <replaceable>nbd-device</replaceable></option></arg>
</cmdsynopsis>
+ <cmdsynopsis>
+ <command>&dhpackage;</command>
+ <arg choice="plain"><option>-c <replaceable>nbd-device</replaceable></option></arg>
+ </cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
</listitem>
</varlistentry>
<varlistentry>
+ <term>-c</term>
+ <listitem>
+ <para>Check whether the specified nbd device is
+ connected.</para>
+ <para>If the device is connected, &dhpackage; will exit
+ with an exit state of 0 and print the PID of the &dhpackage;
+ instance that connected it to stdout.
+ <para>If the device is not
+ connected or does not exist (for example because the nbd
+ module was not loaded), &dhpackage; will exit with an exit
+ state of 1 and not print anything on stdout.</para>
+ <para>If an error occurred, &dhpackage; will exit with an exit
+ state of 2, and not print anything on stdout either.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term>-d</term>
<listitem>
<para>Disconnect the specified nbd device from the
#include <syslog.h>
#include <stdlib.h>
#include <sys/mount.h>
+#include <errno.h>
#ifndef __GNUC__
#error I need GCC to work
#define MY_NAME "nbd_client"
#include "cliserv.h"
+int check_conn(char* devname) {
+ char buf[256];
+ int fd;
+ int len;
+ if(!strncmp(devname, "/dev/", 5)) {
+ devname+=5;
+ }
+ snprintf(buf, 256, "/sys/block/%s/pid", devname);
+ if((fd=open(buf, O_RDONLY))<0) {
+ if(errno==ENOENT) {
+ return 1;
+ } else {
+ return 2;
+ }
+ }
+ len=read(fd, buf, 256);
+ buf[len-1]='\0';
+ printf("%s\n", buf);
+ return 0;
+}
+
int opennet(char *name, int port, int sdp) {
int sock;
struct sockaddr_in xaddrin;
fprintf(stderr, "nbd-client version %s\n", PACKAGE_VERSION);
fprintf(stderr, "Usage: nbd-client [bs=blocksize] [timeout=sec] host port nbd_device [-swap] [-persist]\n");
fprintf(stderr, "Or : nbd-client -d nbd_device\n");
+ fprintf(stderr, "Or : nbd-client -c nbd_device\n");
fprintf(stderr, "Default value for blocksize is 1024 (recommended for ethernet)\n");
fprintf(stderr, "Allowed values for blocksize are 512,1024,2048,4096\n"); /* will be checked in kernel :) */
fprintf(stderr, "Note, that kernel 2.4.2 and older ones do not work correctly with\n");
printf("done\n");
return 0;
}
+ if(strcmp(argv[0], "-c")==0) {
+ return check_conn(argv[1]);
+ }
if (strncmp(argv[0], "bs=", 3)==0) {
blocksize=atoi(argv[0]+3);