[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 05 of 15 v4] 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. 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,82 @@ +/* + * 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" +#include "tap-ctl-xen.h" + +int +tap_ctl_connect_xenblkif(const pid_t pid, const int minor, + 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; + + memset(&message, 0, sizeof(message)); + message.type = TAPDISK_MESSAGE_XENBLKIF_CONNECT; + message.cookie = minor; + + 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 int minor, + 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.cookie = minor; + 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; +} diff --git a/tools/blktap3/control/tap-ctl-xen.h b/tools/blktap3/control/tap-ctl-xen.h new file mode 100644 --- /dev/null +++ b/tools/blktap3/control/tap-ctl-xen.h @@ -0,0 +1,64 @@ +/* + * 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. + */ + +#ifndef __TAP_CTL_XEN_H__ +#define __TAP_CTL_XEN_H__ + +#include <xen/xen.h> +#include <xen/grant_table.h> +#include <xen/event_channel.h> + +/** + * Instructs a tapdisk to connect to the shared ring. + * + * @param pid the process ID of the tapdisk that should connect to the shared + * ring + * @param minor the minor number of the virtual block device + * @param domid the domain ID of the guest VM + * @param devid the device ID + * @param grefs the grant references + * @param order number of grant references, expressed as a 2's order + * @param port event channel port + * @param proto the protocol: native (XENIO_BLKIF_PROTO_NATIVE), + * x86 (XENIO_BLKIF_PROTO_X86_32), or x64 (XENIO_BLKIF_PROTO_X86_64) + * @param pool a string used as an identifier to group two or more VBDs + * beloning to the same tapdisk process. For VBDs with the same pool name, a + * single event channel is used. + * @returns 0 on success, an error code otherwise + */ +int +tap_ctl_connect_xenblkif(const pid_t pid, const int minor, + 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); + +/** + * Instructs a tapdisk to disconnect from the shared ring. + * + * @param pid the process ID of the tapdisk that should disconnect + * @param minor the minor number of the virtual block device + * @param domid the ID of the guest VM + * @param devid the device ID of the virtual block device + * @param timeout timeout to wait, if NULL the function will wait indefinitely + */ +int +tap_ctl_disconnect_xenblkif(const pid_t pid, const int minor, + const domid_t domid, const int devid, struct timeval *timeout); + +#endif /* __TAP_CTL_XEN_H__ */ _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |