summaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorJohann Latocha2012-01-30 12:28:38 +0100
committerJohann Latocha2012-01-30 12:28:38 +0100
commit23c91a086d70898303ca3f8a0fb70a161b79bb37 (patch)
tree35b25a6578dd2c41357723109883aa04f0ab1c59 /src/client
parent[SERVER] Reload configuration at runtime (diff)
downloaddnbd3-23c91a086d70898303ca3f8a0fb70a161b79bb37.tar.gz
dnbd3-23c91a086d70898303ca3f8a0fb70a161b79bb37.tar.xz
dnbd3-23c91a086d70898303ca3f8a0fb70a161b79bb37.zip
[KERNEL] Change server at runtime
[SERVER] Build error/warning on x64 fixed
Diffstat (limited to 'src/client')
-rw-r--r--src/client/client.c57
1 files changed, 40 insertions, 17 deletions
diff --git a/src/client/client.c b/src/client/client.c
index d60614b..54535a3 100644
--- a/src/client/client.c
+++ b/src/client/client.c
@@ -31,12 +31,13 @@
void print_help(char* argv_0)
{
- printf("Usage: %s -H <host> -p <port> -i <image-id> -d <device>\n", argv_0);
+ printf("Usage: %s -H <host> -p <port> -i <image-id> -d <device> || -c <host> -d <device>\n", argv_0);
printf("Start the DNBD3 client.\n");
printf("-H or --host \t\t Host running dnbd3-server.\n");
printf("-p or --port \t\t Port used by server.\n");
printf("-i or --image \t\t Exported image ID.\n");
printf("-d or --device \t\t DNBD3 device name.\n");
+ printf("-c or --changehost \t Change dnbd3-server on device (DEBUG).\n");
printf("-h or --help \t\t Show this help text and quit.\n");
printf("-v or --version \t Show version and quit.\n");
exit(EXIT_SUCCESS);
@@ -50,20 +51,23 @@ void print_version()
int main(int argc, char *argv[])
{
+ int fd;
char *host = NULL;
char *port = NULL;
char *image_id = NULL;
char *dev = NULL;
+ int change_host = 0;
int opt = 0;
int longIndex = 0;
- static const char *optString = "H:p:i:d:hv?";
+ static const char *optString = "H:p:i:d:D:c:hv?";
static const struct option longOpts[] =
{
{ "host", required_argument, NULL, 'H' },
{ "port", required_argument, NULL, 'p' },
{ "image", required_argument, NULL, 'i' },
{ "device", required_argument, NULL, 'd' },
+ { "changehost", required_argument, NULL, 'c' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'v' }, };
@@ -85,6 +89,10 @@ int main(int argc, char *argv[])
case 'd':
dev = optarg;
break;
+ case 'c':
+ host = optarg;
+ change_host = 1;
+ break;
case 'h':
print_help(argv[0]);
break;
@@ -97,28 +105,43 @@ int main(int argc, char *argv[])
opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
}
- if (!host || !port || !dev || !image_id)
+ if (change_host && host && dev && !port && !image_id)
{
- printf("FATAL: Not enough information specified\n");
- exit(EXIT_FAILURE);
+ fd = open(dev, O_RDONLY);
+
+ if (ioctl(fd, IOCTL_DISCONNECT) < 0)
+ printf("ERROR: ioctl not successful\n");
+
+ if (ioctl(fd, IOCTL_SET_HOST, host) < 0)
+ printf("ERROR: ioctl not successful\n");
+
+ if (ioctl(fd, IOCTL_CONNECT) < 0)
+ printf("ERROR: ioctl not successful\n");
+
+ close(fd);
+ exit(EXIT_SUCCESS);
}
- int fd;
- fd = open(dev, O_RDONLY);
+ if (host && port && dev && image_id)
+ {
+ fd = open(dev, O_RDONLY);
- if (ioctl(fd, IOCTL_SET_HOST, host) < 0)
- printf("ERROR: ioctl not successful\n");
+ if (ioctl(fd, IOCTL_SET_HOST, host) < 0)
+ printf("ERROR: ioctl not successful\n");
- if (ioctl(fd, IOCTL_SET_PORT, port) < 0)
- printf("ERROR: ioctl not successful\n");
+ if (ioctl(fd, IOCTL_SET_PORT, port) < 0)
+ printf("ERROR: ioctl not successful\n");
- if (ioctl(fd, IOCTL_SET_IMAGE, image_id) < 0)
- printf("ERROR: ioctl not successful\n");
+ if (ioctl(fd, IOCTL_SET_IMAGE, image_id) < 0)
+ printf("ERROR: ioctl not successful\n");
- if (ioctl(fd, IOCTL_CONNECT) < 0)
- printf("ERROR: ioctl not successful\n");
+ if (ioctl(fd, IOCTL_CONNECT) < 0)
+ printf("ERROR: ioctl not successful\n");
- close(fd);
+ close(fd);
+ exit(EXIT_SUCCESS);
+ }
- exit(EXIT_SUCCESS);
+ print_help(argv[0]);
+ exit(EXIT_FAILURE);
}