summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2001-12-23 07:34:55 +0000
committerRoland McGrath <roland@gnu.org>2001-12-23 07:34:55 +0000
commit18790079c352179672807040da38ab5ff31d6dc4 (patch)
treed56661d3cfb1bbd33044ea88d548bb1911716a37
parent6369617c93f57ee8707d0294aeb2c980ee816416 (diff)
2001-10-14 Roland McGrath <roland@frob.com>
* nbd.c (nbd_validate_name): Accept an optional "nbd://" prefix. (nbdopen): Likewise.
-rw-r--r--libstore/nbd.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/libstore/nbd.c b/libstore/nbd.c
index 6fe910c1..c802724e 100644
--- a/libstore/nbd.c
+++ b/libstore/nbd.c
@@ -191,13 +191,20 @@ nbd_open (const char *name, int flags,
return store_nbd_open (name, flags, store);
}
-/* Valid name syntax is HOSTNAME:PORT[/BLOCKSIZE].
+static const char url_prefix[] = "nbd://";
+
+/* Valid name syntax is [nbd://]HOSTNAME:PORT[/BLOCKSIZE].
If "/BLOCKSIZE" is omitted, the block size is 1. */
static error_t
nbd_validate_name (const char *name,
const struct store_class *const *classes)
{
- char *p = strchr (name, ':'), *endp;
+ char *p, *endp;
+
+ if (!strncmp (name, url_prefix, sizeof url_prefix - 1))
+ name += sizeof url_prefix - 1;
+
+ p = strchr (name, ':');
if (p == 0)
return EINVAL;
endp = 0;
@@ -231,13 +238,17 @@ nbdopen (const char *name, int *mod_flags,
char **ap;
struct nbd_startup ns;
ssize_t cc;
+ unsigned long int port;
+ char *hostname, *p, *endp;
+
+ if (!strncmp (name, url_prefix, sizeof url_prefix - 1))
+ name += sizeof url_prefix - 1;
/* First we have to parse the store name to get the host name and TCP
port number to connect to and the block size to use. */
- unsigned long int port;
- char *hostname = strdupa (name);
- char *p = strchr (hostname, ':'), *endp;
+ hostname = strdupa (name);
+ p = strchr (hostname, ':');
if (p == 0)
return EINVAL;
@@ -357,8 +368,7 @@ nbd_clear_flags (struct store *store, int flags)
return err;
}
-const struct store_class
-store_nbd_class =
+const struct store_class store_nbd_class =
{
STORAGE_NETWORK, "nbd",
open: nbd_open,