node_device_conf.h 8.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * node_device_conf.h: config handling for node devices
 *
 * Copyright (C) 2008 Virtual Iron Software, Inc.
 * Copyright (C) 2008 David F. Lively
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 * Author: David F. Lively <dlively@virtualiron.com>
 */

#ifndef __VIR_NODE_DEVICE_CONF_H__
#define __VIR_NODE_DEVICE_CONF_H__

#include "internal.h"
#include "util.h"
29
#include "threads.h"
30

31 32
#include <libxml/tree.h>

33 34 35
#define CREATE_DEVICE 1
#define EXISTING_DEVICE 0

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
enum virNodeDevCapType {
    /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */
    VIR_NODE_DEV_CAP_SYSTEM,		/* System capability */
    VIR_NODE_DEV_CAP_PCI_DEV,		/* PCI device */
    VIR_NODE_DEV_CAP_USB_DEV,		/* USB device */
    VIR_NODE_DEV_CAP_USB_INTERFACE,	/* USB interface */
    VIR_NODE_DEV_CAP_NET,		/* Network device */
    VIR_NODE_DEV_CAP_SCSI_HOST,		/* SCSI Host Bus Adapter */
    VIR_NODE_DEV_CAP_SCSI,		/* SCSI device */
    VIR_NODE_DEV_CAP_STORAGE,		/* Storage device */
    VIR_NODE_DEV_CAP_LAST
};

enum virNodeDevNetCapType {
    /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */
    VIR_NODE_DEV_CAP_NET_80203,		/* 802.03 network device */
    VIR_NODE_DEV_CAP_NET_80211,		/* 802.11 network device */
    VIR_NODE_DEV_CAP_NET_LAST
};

56 57 58 59 60 61 62
enum virNodeDevHBACapType {
    /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */
    VIR_NODE_DEV_CAP_HBA_FC_HOST,	/* fibre channel HBA */
    VIR_NODE_DEV_CAP_HBA_VPORT_OPS,	/* capable of vport operations */
    VIR_NODE_DEV_CAP_HBA_LAST
};

63 64
VIR_ENUM_DECL(virNodeDevCap)
VIR_ENUM_DECL(virNodeDevNetCap)
65
VIR_ENUM_DECL(virNodeDevHBACap)
66 67 68 69 70 71 72

enum virNodeDevStorageCapFlags {
    VIR_NODE_DEV_CAP_STORAGE_REMOVABLE			= (1 << 0),
    VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE	= (1 << 1),
    VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE		= (1 << 2),
};

73 74 75 76 77
enum virNodeDevScsiHostCapFlags {
    VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST			= (1 << 0),
    VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS			= (1 << 1),
};

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
typedef struct _virNodeDevCapsDef virNodeDevCapsDef;
typedef virNodeDevCapsDef *virNodeDevCapsDefPtr;
struct _virNodeDevCapsDef {
    enum virNodeDevCapType type;
    union _virNodeDevCapData {
        struct {
            char *product_name;
            struct {
                char *vendor_name;
                char *version;
                char *serial;
                unsigned char uuid[VIR_UUID_BUFLEN];
            } hardware;
            struct {
                char *vendor_name;
                char *version;
                char *release_date;
            } firmware;
        } system;
        struct {
            unsigned domain;
            unsigned bus;
            unsigned slot;
            unsigned function;
            unsigned product;
            unsigned vendor;
            char *product_name;
            char *vendor_name;
        } pci_dev;
        struct {
            unsigned bus;
            unsigned device;
            unsigned product;
            unsigned vendor;
            char *product_name;
            char *vendor_name;
        } usb_dev;
        struct {
            unsigned number;
            unsigned _class;		/* "class" is reserved in C */
            unsigned subclass;
            unsigned protocol;
            char *description;
        } usb_if;
        struct {
            char *address;
124
            char *ifname;
125 126 127 128
            enum virNodeDevNetCapType subtype;  /* LAST -> no subtype */
        } net;
        struct {
            unsigned host;
129 130 131
            char *wwnn;
            char *wwpn;
            unsigned flags;
132 133 134 135 136 137 138 139 140 141 142
        } scsi_host;
        struct {
            unsigned host;
            unsigned bus;
            unsigned target;
            unsigned lun;
            char *type;
        } scsi;
        struct {
            unsigned long long size;
            unsigned long long removable_media_size;
143
            char *block;
144 145 146 147
            char *bus;
            char *drive_type;
            char *model;
            char *vendor;
148
            char *serial;
149 150 151 152 153 154 155 156 157 158 159 160
            unsigned flags;	/* virNodeDevStorageCapFlags bits */
        } storage;
    } data;
    virNodeDevCapsDefPtr next;          /* next capability */
};


typedef struct _virNodeDeviceDef virNodeDeviceDef;
typedef virNodeDeviceDef *virNodeDeviceDefPtr;
struct _virNodeDeviceDef {
    char *name;                         /* device name (unique on node) */
    char *parent;			/* optional parent device name */
161
    char *driver;                       /* optional driver name */
162 163 164 165 166 167 168
    virNodeDevCapsDefPtr caps;		/* optional device capabilities */
};


typedef struct _virNodeDeviceObj virNodeDeviceObj;
typedef virNodeDeviceObj *virNodeDeviceObjPtr;
struct _virNodeDeviceObj {
169
    virMutex lock;
170

171
    char *devicePath;                   /* OS specific path to device metadat, eg sysfs */
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
    virNodeDeviceDefPtr def;		/* device definition */
    void *privateData;			/* driver-specific private data */
    void (*privateFree)(void *data);	/* destructor for private data */

};

typedef struct _virNodeDeviceObjList virNodeDeviceObjList;
typedef virNodeDeviceObjList *virNodeDeviceObjListPtr;
struct _virNodeDeviceObjList {
    unsigned int count;
    virNodeDeviceObjPtr *objs;
};

typedef struct _virDeviceMonitorState virDeviceMonitorState;
typedef virDeviceMonitorState *virDeviceMonitorStatePtr;
struct _virDeviceMonitorState {
188
    virMutex lock;
189

190 191 192 193 194 195 196 197
    virNodeDeviceObjList devs;		/* currently-known devices */
    void *privateData;			/* driver-specific private data */
};

#define virNodeDeviceReportError(conn, code, fmt...)			\
        virReportErrorHelper(conn, VIR_FROM_NODEDEV, code, __FILE__,	\
                               __FUNCTION__, __LINE__, fmt)

198 199
int virNodeDeviceHasCap(const virNodeDeviceObjPtr dev, const char *cap);

200 201 202 203 204 205 206 207 208 209 210 211 212
virNodeDeviceObjPtr virNodeDeviceFindByName(const virNodeDeviceObjListPtr devs,
                                            const char *name);

virNodeDeviceObjPtr virNodeDeviceAssignDef(virConnectPtr conn,
                                           virNodeDeviceObjListPtr devs,
                                           const virNodeDeviceDefPtr def);

void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs,
                            const virNodeDeviceObjPtr dev);

char *virNodeDeviceDefFormat(virConnectPtr conn,
                             const virNodeDeviceDefPtr def);

213
virNodeDeviceDefPtr virNodeDeviceDefParseString(virConnectPtr conn,
214 215
                                                const char *str,
                                                int create);
216 217 218 219 220 221 222
virNodeDeviceDefPtr virNodeDeviceDefParseFile(virConnectPtr conn,
                                              const char *filename,
                                              int create);
virNodeDeviceDefPtr virNodeDeviceDefParseNode(virConnectPtr conn,
                                              xmlDocPtr xml,
                                              xmlNodePtr root,
                                              int create);
223

224 225 226 227 228 229 230 231 232 233 234
int virNodeDeviceGetWWNs(virConnectPtr conn,
                         virNodeDeviceDefPtr def,
                         char **wwnn,
                         char **wwpn);

int virNodeDeviceGetParentHost(virConnectPtr conn,
                               const virNodeDeviceObjListPtr devs,
                               const char *dev_name,
                               const char *parent_name,
                               int *parent_host);

235 236 237 238 239 240 241 242
void virNodeDeviceDefFree(virNodeDeviceDefPtr def);

void virNodeDeviceObjFree(virNodeDeviceObjPtr dev);

void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs);

void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps);

D
Daniel P. Berrange 已提交
243 244 245
void virNodeDeviceObjLock(virNodeDeviceObjPtr obj);
void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj);

246
#endif /* __VIR_NODE_DEVICE_CONF_H__ */