From: "Satoshi Uchida" Subject: [PATCH][1/4][IOMGR] I/O request Manager body Date: Mon, 30 Jul 2007 17:50:51 +0900 Message-ID: <038601c7d286$bb8ba410$4c87380a@ad.spf.cl.nec.co.jp> Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This patch provides a I/O request management framework. This framework can control virtual block device threads at 7 places : * deciding that virtual block devices(threads) is ether going or = waiting, * before allocating pending_request variables, * after allocated pending_request variables, * after allocated no pending_request variables (Namely, out of = request), * after freed pending_request variables and * starting/stopping virtual block devices(threads). And, iomgr provides the total number of pending requests in blkback and = blktap. -------------------------------------------------- Satoshi UCHIDA=20 NEC Corporation, Japan # HG changeset patch # User s-uchida@ap.jp.nec.com # Date 1184302359 -32400 # Node ID aee77a9230c1b19873e60761d080af517bbfb189 # Parent e64625df946b81ac1a5f8be7c5d0ae2aad618d7c [IOMGR] Add I/O request management framework. This is body for I/O request management. Signed-by-off Satoshi UCHIDA diff -r e64625df946b -r aee77a9230c1 drivers/xen/Kconfig --- a/drivers/xen/Kconfig Fri Jun 15 13:33:47 2007 -0600 +++ b/drivers/xen/Kconfig Fri Jul 13 13:45:30 2007 +0900 @@ -65,6 +65,15 @@ config XEN_BLKDEV_TAP high-performance block backends, where disk images may be = implemented as files, in memory, or on other hosts across the network. = This=20 driver can safely coexist with the existing blockback driver. + +config XEN_IOMGR + tristate "Backend I/O request manager framework" + depends on XEN_BACKEND || XEN_BLKDEV_TAP + default y + help + The Backend I/O request manager framework provides interface + which makes backend driver to control I/O requests by I/O=20 + control modules =20 config XEN_NETDEV_BACKEND tristate "Network-device backend driver" diff -r e64625df946b -r aee77a9230c1 drivers/xen/Makefile --- a/drivers/xen/Makefile Fri Jun 15 13:33:47 2007 -0600 +++ b/drivers/xen/Makefile Fri Jul 13 13:45:30 2007 +0900 @@ -10,6 +10,7 @@ obj-y +=3D util.o obj-y +=3D util.o obj-$(CONFIG_XEN_BLKDEV_BACKEND) +=3D blkback/ obj-$(CONFIG_XEN_BLKDEV_TAP) +=3D blktap/ +obj-$(CONFIG_XEN_IOMGR) +=3D iomgr/ obj-$(CONFIG_XEN_NETDEV_BACKEND) +=3D netback/ obj-$(CONFIG_XEN_TPMDEV_BACKEND) +=3D tpmback/ obj-$(CONFIG_XEN_BLKDEV_FRONTEND) +=3D blkfront/ diff -r e64625df946b -r aee77a9230c1 drivers/xen/iomgr/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/drivers/xen/iomgr/Makefile Fri Jul 13 13:52:39 2007 +0900 @@ -0,0 +1,4 @@ +obj-$(CONFIG_XEN_IOMGR) :=3D xeniomgr.o + +xeniomgr-y :=3D iomgr.o + diff -r e64625df946b -r aee77a9230c1 drivers/xen/iomgr/iomgr.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/drivers/xen/iomgr/iomgr.c Fri Jul 13 13:52:39 2007 +0900 @@ -0,0 +1,188 @@ +/***********************************************************************= ****** + * iomgr.c + * + * Management interface for I/O request. + * + * Copyright(c) 2007, Satoshi UCHIDA, NEC Corporation + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version = 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: + *=20 + * Permission is hereby granted, free of charge, to any person = obtaining a copy + * of this source file (the "Software"), to deal in the Software = without + * restriction, including without limitation the rights to use, copy, = modify, + * merge, publish, distribute, sublicense, and/or sell copies of the = Software, + * and to permit persons to whom the Software is furnished to do so, = subject to + * the following conditions: + *=20 + * The above copyright notice and this permission notice shall be = included in + * all copies or substantial portions of the Software. + *=20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, = EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF = MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT = SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR = OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, = ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER = DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include +#include +#include + +/* Current manager. */ +struct iomgr *mgr; + +/* + * Default Manager. + * Non Management for I/O request. + */ +static struct iomgr nomgr =3D { + .ops =3D { + .iomgr_waiting_request_fn =3D NULL, + .iomgr_allow_request_fn =3D NULL, + .iomgr_alloc_request_fn =3D NULL, + .iomgr_oo_abort_request_fn =3D NULL, + .iomgr_free_request_fn =3D NULL, + .iomgr_dev_start_fn =3D NULL, + .iomgr_dev_stop_fn =3D NULL, + }, + .iomgr_name =3D "none", +}; + +/* + * Counter for pending request. + */ +atomic_t pending_req =3D ATOMIC_INIT(0); + + +/* + * Functions which apply iomgr operations + */ + +/* + * Management for original waiting condition within VBD/TAP thread. + */ +int do_iomgr_waiting_request(struct xenbus_device *dev) +{ + if (mgr->ops.iomgr_waiting_request_fn !=3D NULL) + return mgr->ops.iomgr_waiting_request_fn(dev); + else + return 0; +} + +/* + * Management when new request for VBD/TAP thread is securing. + */ +int do_iomgr_allow_request(struct xenbus_device *dev) +{ + if (mgr->ops.iomgr_allow_request_fn !=3D NULL) + return mgr->ops.iomgr_allow_request_fn(dev); + else + return 0; +} + +/* Management of allocating new request for VBD/TAP thread. */ +int do_iomgr_alloc_request(struct xenbus_device *dev) +{ + atomic_inc(&pending_req); + if (mgr->ops.iomgr_alloc_request_fn !=3D NULL) + return mgr->ops.iomgr_alloc_request_fn(dev); + else + return 0; +} + +/* + * Management when it is failure to allocating new request + * for VBD/TAP thread. + */ +int do_iomgr_oo_abort_request(struct xenbus_device *dev) +{ + if (mgr->ops.iomgr_oo_abort_request_fn !=3D NULL) + return mgr->ops.iomgr_oo_abort_request_fn(dev); + else + return 0; +} + +/* + * Management when request for VBD/TAP thread finishes. + */ +void do_iomgr_free_request(struct xenbus_device *dev) +{ + atomic_dec(&pending_req); + if (mgr->ops.iomgr_free_request_fn !=3D NULL) + mgr->ops.iomgr_free_request_fn(dev); +} + +/* + * Management when new VBD/TAP thread start. + */ +int do_iomgr_dev_start(struct xenbus_device *dev) +{ + if (mgr->ops.iomgr_dev_start_fn !=3D NULL) + return mgr->ops.iomgr_dev_start_fn(dev); + return 0; +} + +/* + * Management when VBD/TAP thread stops. + */ +void do_iomgr_dev_stop(struct xenbus_device *dev) +{ + if (mgr->ops.iomgr_dev_stop_fn !=3D NULL) + mgr->ops.iomgr_dev_stop_fn(dev); +} + + +/* Access to counter for pending requests. */ +atomic_t *num_pending_req(void) +{ + return &pending_req; +} +EXPORT_SYMBOL(num_pending_req); + + +/* + * Registration function for I/O manager. + */ + +/* Registration of I/O Manager.*/ +int xen_iomgr_register(struct iomgr *newmgr) +{ + mgr =3D newmgr; + + return 0; +} +EXPORT_SYMBOL_GPL(xen_iomgr_register); + +/* + * Unregistration of I/O Manager. + * Change to No operation manager. + */ +void xen_iomgr_unregister(struct iomgr *removemgr) +{ + if (mgr =3D=3D removemgr) + mgr =3D &nomgr; +} +EXPORT_SYMBOL_GPL(xen_iomgr_unregister); + + +/* Initializing function */ +static int iomgr_init(void) +{ + mgr =3D &nomgr; + + return 0; +} + + +module_init(iomgr_init); + +MODULE_AUTHOR("Satoshi UCHIDA"); +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_DESCRIPTION("Xen IO Manager"); diff -r e64625df946b -r aee77a9230c1 include/xen/iomgr.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/xen/iomgr.h Fri Jul 13 13:52:39 2007 +0900 @@ -0,0 +1,100 @@ +/***********************************************************************= ****** + * iomgr.h + * + * Management interface for I/O request. + * + * Copyright(c) 2007, Satoshi UCHIDA, NEC Corporation + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version = 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: + *=20 + * Permission is hereby granted, free of charge, to any person = obtaining a copy + * of this source file (the "Software"), to deal in the Software = without + * restriction, including without limitation the rights to use, copy, = modify, + * merge, publish, distribute, sublicense, and/or sell copies of the = Software, + * and to permit persons to whom the Software is furnished to do so, = subject to + * the following conditions: + *=20 + * The above copyright notice and this permission notice shall be = included in + * all copies or substantial portions of the Software. + *=20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, = EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF = MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT = SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR = OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, = ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER = DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef _XEN_IOMER_H +#define _XEN_IOMER_H + +#include + +#define IOMGR_ALLOW_NG 1 + +struct xenbus_device; + +/* + * Definition of iomgr function. + */ +typedef int (iomgr_waiting_request_fn) (struct xenbus_device *); +typedef int (iomgr_allow_request_fn) (struct xenbus_device *); +typedef int (iomgr_alloc_request_fn) (struct xenbus_device *); +typedef int (iomgr_oo_abort_request_fn) (struct xenbus_device *); +typedef void (iomgr_free_request_fn) (struct xenbus_device *); +typedef int (iomgr_dev_start_fn) (struct xenbus_device *); +typedef void (iomgr_dev_stop_fn) (struct xenbus_device *); + + +/* iomgr operations */ +struct iomgr_ops +{ + iomgr_waiting_request_fn *iomgr_waiting_request_fn; + iomgr_allow_request_fn *iomgr_allow_request_fn; + iomgr_alloc_request_fn *iomgr_alloc_request_fn; + iomgr_oo_abort_request_fn *iomgr_oo_abort_request_fn; + iomgr_free_request_fn *iomgr_free_request_fn; + iomgr_dev_start_fn *iomgr_dev_start_fn; + iomgr_dev_stop_fn *iomgr_dev_stop_fn; +}; + +#define IOMGR_NAME_MAX (16) + + +/* iomgr scheduler structure */ +struct iomgr +{ + struct iomgr_ops ops; + char iomgr_name[IOMGR_NAME_MAX]; +}; + + +/* + * functions which apply iomgr operations + */ +int do_iomgr_waiting_request(struct xenbus_device *dev); +int do_iomgr_allow_request(struct xenbus_device *dev); +int do_iomgr_alloc_request(struct xenbus_device *dev); +int do_iomgr_oo_abort_request(struct xenbus_device *dev); +void do_iomgr_free_request(struct xenbus_device *dev); +int do_iomgr_dev_start(struct xenbus_device *dev); +void do_iomgr_dev_stop(struct xenbus_device *dev); + +/* + * pending rezuest counter + */=20 +atomic_t *num_pending_req(void); + + +/* + * Xen I/O scheduler registration + */ +extern int xen_iomgr_register(struct iomgr *); +extern void xen_iomgr_unregister(struct iomgr *); +=09 +#endif