[stgt] [PATCH v2 3/3] bs_sheepdog.c: test connection when new logical unit is created
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Wed Oct 16 10:42:08 CEST 2013
This patch adds creation of a test connection in the process of making
logical unit. This is required for validating --backing-store option
and avoid forever trying of reconnection.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
usr/bs_sheepdog.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/usr/bs_sheepdog.c b/usr/bs_sheepdog.c
index de66d59..a0dc896 100644
--- a/usr/bs_sheepdog.c
+++ b/usr/bs_sheepdog.c
@@ -909,7 +909,7 @@ out:
static int sd_open(struct sheepdog_access_info *ai, char *filename, int flags)
{
- int ret = 0, i, len;
+ int ret = 0, i, len, fd;
uint32_t vid = 0;
char *orig_filename;
@@ -973,6 +973,15 @@ static int sd_open(struct sheepdog_access_info *ai, char *filename, int flags)
parse_state = EXPECT_PORT;
break;
case EXPECT_PORT:
+ len = strlen(result);
+ for (i = 0; i < len; i++) {
+ if (!isdigit(result[i])) {
+ eprintf("invalid tcp port number:"\
+ " %s\n", result);
+ return -1;
+ }
+ }
+
ai->port = atoi(result);
parse_state = EXPECT_VDI;
break;
@@ -1020,6 +1029,25 @@ trans_to_expect_nothing:
else
dprintf("hostname: %s, port: %d\n", ai->hostname, ai->port);
+ /*
+ * test connection for validating command line option
+ *
+ * if this step is skipped, the main thread of tgtd will try to
+ * reconnect to sheep process forever
+ */
+ fd = ai->is_unix ?
+ connect_to_sdog_unix(ai->uds_path) :
+ connect_to_sdog_tcp(ai->hostname, ai->port);
+
+ if (fd < 0) {
+ eprintf("connecting to sheep process failed, "\
+ "please verify the --backing-store option: %s",
+ orig_filename);
+ return -1;
+ }
+
+ close(fd); /* we don't need this connection */
+
if (snapid == -1)
dprintf("tag: %s\n", tag);
else
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list