[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 1 of 7 v2] blktap3/tapback: Introduce core defines and structure definitions
diff -r fbf47a5d98ff -r 0777319f0a6e tools/blktap3/tapback/tapback.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/blktap3/tapback/tapback.h Fri Jan 04 11:54:51 2013 +0000 @@ -0,0 +1,253 @@ +/* + * 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 __TAPBACK_H__ +#define __TAPBACK_H__ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include <xen/xen.h> +#include <xenstore.h> +#include <xen/io/xenbus.h> +#include <xen/event_channel.h> +#include <xen/grant_table.h> + +#include "tap-ctl.h" + +void tapback_log(int prio, const char *fmt, ...); +void (*tapback_vlog) (int prio, const char *fmt, va_list ap); + +#define DBG(_fmt, _args...) tapback_log(LOG_DEBUG, "%s:%d "_fmt, __FILE__, \ + __LINE__, ##_args) +#define INFO(_fmt, _args...) tapback_log(LOG_INFO, _fmt, ##_args) +#define WARN(_fmt, _args...) tapback_log(LOG_WARNING, "%s:%d "_fmt, __FILE__, \ + __LINE__, ##_args) + +#define WARN_ON(_cond, fmt, ...) \ + if (unlikely(_cond)) { \ + printf(fmt, ##__VA_ARGS__); \ + } + +#define BUG_ON(_cond) \ + if (unlikely(_cond)) { \ + assert(0); \ + } + +/* + * XenStore path components. + * + * To avoid confusion with blktap2, we'll use a new kind of device for libxl + * defining it in tools/libxl/libxl_types_internal.idl. This will be done by + * the patch that adds libxl support for blktap3. TODO When that patch is sent, + * use the definition from there instead of hard-coding it here. + */ +#define XENSTORE_BACKEND "backend" +#define BLKTAP3_BACKEND_NAME "xenio" +#define BLKTAP3_BACKEND_PATH XENSTORE_BACKEND"/"BLKTAP3_BACKEND_NAME +#define BLKTAP3_BACKEND_TOKEN XENSTORE_BACKEND"-"BLKTAP3_BACKEND_NAME +#define BLKTAP3_FRONTEND_TOKEN "otherend-state" +#define BLKTAP3_SERIAL BLKTAP3_BACKEND_NAME"-serial" + +/* + * TODO Put the rest of the front-end nodes defined in blkif.h here and group + * them. e.g. FRONTEND_NODE_xxx. + */ +#define RING_REF "ring-ref" +#define FEAT_PERSIST "feature-persistent" + +/** + * A Virtual Block Device (VBD), represents a block device in a guest VM. + * Contains all relevant information. + */ +typedef struct vbd { + + /** + * Device name, as retrieved from XenStore at probe-time. + */ + char *name; + + /** + * The device ID. Same as vbd.name, we keep it around because the tapdisk + * control libreary wants it as an int and not as a string. + */ + int devid; + + /** + * For linked lists. + */ + TAILQ_ENTRY(vbd) backend_entry; + + /** + * TODO Supposed to solve some kind of race condition with libxl? + */ + long long serial; + + /** + * The domain ID this VBD belongs to. + */ + domid_t domid; + + /** + * The root directory in XenStore for this VBD. This is where all + * directories and key/value pairs related to this VBD are stored. + */ + char *frontend_path; + + /** + * XenStore path to the VBD's state. This is just + * vbd.frontend_path + "/state", we keep it around so we don't have to + * allocate/free memory all the time. + */ + char *frontend_state_path; + + /** + * FIXME This is used but isn't initialised anywhere! This reflects + * tap_list.minor. + */ + dev_t dev; + + /** + * Indicates whether the tapdisk is connected to the shared ring. + */ + bool connected; + + /** + * Descriptor of the tapdisk process serving this virtual block device. We + * need this until the end of the VBD's lifetime in order to disconnect + * the tapdisk from the shared ring. + */ + tap_list_t tap; + + /* + * XXX We keep sector_size, sectors, and info because we need to + * communicate them to the front-end not only when the front-end goes to + * XenbusStateInitialised, but to XenbusStateConnected as well. + */ + + /** + * Sector size, supplied by the tapdisk, communicated to blkfront. + */ + unsigned int sector_size; + + /** + * Number of sectors, supplied by the tapdisk, communicated to blkfront. + */ + unsigned long long sectors; + + /** + * VDISK_???, defined in include/xen/interface/io/blkif.h. + */ + unsigned int info; + +} vbd_t; + +TAILQ_HEAD(tqh_vbd, vbd); + +/** + * The collection of all necessary handles and descriptors. + */ +struct _blktap3_daemon { + + /** + * A handle to XenStore. + */ + struct xs_handle *xs; + + /** + * For executing transacted operations on XenStore. + */ + xs_transaction_t xst; + + /** + * The list of virtual block devices. + * + * TODO We sometimes have to scan the whole list to find the device/domain + * we're interested in, should we optimize this? E.g. use a hash table + * for O(1) access? + */ + struct tqh_vbd devices; + + /** + * For allocating serials. + */ + long long serial; + + /** + * TODO From xen/include/public/io/blkif.h: "The maximum supported size of + * the request ring buffer" + */ + int max_ring_page_order; +}; + +extern struct _blktap3_daemon blktap3_daemon; + +#define tapback_backend_for_each_device(_device, _next) \ + TAILQ_FOREACH_SAFE(_device, &blktap3_daemon.devices, backend_entry, _next) + +/** + * Iterates over all devices and returns the one for which the condition is + * true. + */ +#define tapback_backend_find_device(_device, _cond) \ +do { \ + vbd_t *__next; \ + int found = 0; \ + tapback_backend_for_each_device(_device, __next) { \ + if (_cond) { \ + found = 1; \ + break; \ + } \ + } \ + if (!found) \ + _device = NULL; \ +} while (0) + +/** + * Act in response to a change in the front-end XenStore path. + * + * @param path the front-end's XenStore path that changed + * @returns 0 on success, an error code otherwise + * + * XXX Only called by tapback_read_watch + */ +int +tapback_backend_handle_otherend_watch(const char * const path); + +/** + * Act in response to a change in the back-end directory in XenStore. + * + * If the path is "/backend" or "/backend/<backend name>", all devices are + * probed. Otherwise, the path should be + * "backend/<backend name>/<domid>/<device name>" + * (i.e. backend/<backend name>/1/51712), and in this case this specific device + * is probed. + * + * @param path the back-end's XenStore path that changed @returns 0 on success, + * an error code otherwise + * + * XXX Only called by tapback_read_watch. + */ +int +tapback_backend_handle_backend_watch(char * const path); + +#endif /* __TAPBACK_H__ */ _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |