[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 05 of 13 v6] blktap3/libblktapctl: Introduce functionality used by tapback to instruct tapdisk to connect to the sring



This patch introduces functions tap_ctl_connect_xenblkif and
tap_ctl_disconnect_xenblkif, that are used by the tapback daemon to instruct a
running tapdisk process to connect to/disconnect from the shared ring.

Signed-off-by: Thanos Makatos <thanos.makatos@xxxxxxxxxx>

---
Changed since v2:
  * Simplified error-checking after calling tap_ctl_connect_send_and_receive.

Changed since v3:
  * Removed trailing whitespace in license.
  * Updated documentation regarding the pool parameter in
    tap_ctl_connect_xenblkif.
  * Use more const in the arguments of tap_ctl_connect_xenblkif and of
    tap_ctl_disconnect_xenblkif.

Changed since v4:
  * Move definitions of functions tap_ctl_connect_xenblkif and
    tap_ctl_disconnect_xenblkif to tap-ctl.h.
  * Remove the minor number from tap_ctl_connect_xenblkif and
    tap_ctl_disconnect_xenblkif.

diff --git a/tools/blktap3/control/tap-ctl-xen.c 
b/tools/blktap3/control/tap-ctl-xen.c
new file mode 100644
--- /dev/null
+++ b/tools/blktap3/control/tap-ctl-xen.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2012      Citrix Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "tap-ctl.h"
+
+int
+tap_ctl_connect_xenblkif(const pid_t pid, const char *params,
+        const domid_t domid, const int devid, const grant_ref_t * grefs,
+        const int order, const evtchn_port_t port, int proto, const char *pool)
+{
+    tapdisk_message_t message;
+    int i, err;
+
+    if (!params)
+        return -EINVAL;
+    if (strnlen(params, TAPDISK_MESSAGE_STRING_LENGTH)
+            >= TAPDISK_MESSAGE_STRING_LENGTH)
+        return -ENAMETOOLONG;
+
+    memset(&message, 0, sizeof(message));
+    message.type = TAPDISK_MESSAGE_XENBLKIF_CONNECT;
+    strcpy(message.u.blkif.params, params);
+
+    message.u.blkif.domid = domid;
+    message.u.blkif.devid = devid;
+    for (i = 0; i < 1 << order; i++)
+        message.u.blkif.gref[i] = grefs[i];
+    message.u.blkif.order = order;
+    message.u.blkif.port = port;
+    message.u.blkif.proto = proto;
+    if (pool)
+        strncpy(message.u.blkif.pool, pool, sizeof(message.u.blkif.pool));
+    else
+        message.u.blkif.pool[0] = 0;
+
+    err = tap_ctl_connect_send_and_receive(pid, &message, NULL);
+    if (err)
+        /*
+         * TODO include more info
+         */
+        EPRINTF("failed to connect tapdisk %d to the ring: %s\n", pid,
+                strerror(-err));
+    return err;
+}
+
+int
+tap_ctl_disconnect_xenblkif(const pid_t pid, const domid_t domid,
+        const int devid, struct timeval *timeout)
+{
+    tapdisk_message_t message;
+    int err;
+
+    memset(&message, 0, sizeof(message));
+    message.type = TAPDISK_MESSAGE_XENBLKIF_DISCONNECT;
+    message.u.blkif.domid = domid;
+    message.u.blkif.devid = devid;
+
+    err = tap_ctl_connect_send_and_receive(pid, &message, timeout);
+    if (err)
+        /*
+         * TODO include more info
+         */
+        EPRINTF("failed to disconnect tapdisk %d from the ring: %s\n", pid,
+                strerror(-err));
+
+    return err;
+}

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.