node_device_conf.h 10.3 KB
Newer Older
1 2 3
/*
 * node_device_conf.h: config handling for node devices
 *
4
 * Copyright (C) 2009-2013 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * 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
19
 * License along with this library.  If not, see
O
Osier Yang 已提交
20
 * <http://www.gnu.org/licenses/>.
21 22 23 24 25
 *
 * Author: David F. Lively <dlively@virtualiron.com>
 */

#ifndef __VIR_NODE_DEVICE_CONF_H__
26
# define __VIR_NODE_DEVICE_CONF_H__
27

28
# include "internal.h"
29
# include "virutil.h"
30
# include "virthread.h"
31
# include "virpci.h"
32

33
# include <libxml/tree.h>
34

35 36
# define CREATE_DEVICE 1
# define EXISTING_DEVICE 0
37

38
typedef enum {
39 40 41 42 43 44 45
    /* 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 */
D
David Allan 已提交
46
    VIR_NODE_DEV_CAP_SCSI_TARGET,	/* SCSI Target */
47 48
    VIR_NODE_DEV_CAP_SCSI,		/* SCSI device */
    VIR_NODE_DEV_CAP_STORAGE,		/* Storage device */
49 50
    VIR_NODE_DEV_CAP_FC_HOST,		/* FC Host Bus Adapter */
    VIR_NODE_DEV_CAP_VPORTS,		/* HBA which is capable of vports */
51 52
    VIR_NODE_DEV_CAP_SCSI_GENERIC,      /* SCSI generic device */

53
    VIR_NODE_DEV_CAP_LAST
54
} virNodeDevCapType;
55

56
typedef enum {
57 58 59 60
    /* 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
61
} virNodeDevNetCapType;
62

63 64
VIR_ENUM_DECL(virNodeDevCap)
VIR_ENUM_DECL(virNodeDevNetCap)
65

66
typedef enum {
67 68 69
    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),
70
} virNodeDevStorageCapFlags;
71

72
typedef enum {
73 74
    VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST			= (1 << 0),
    VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS			= (1 << 1),
75
} virNodeDevSCSIHostCapFlags;
76

77
typedef enum {
78 79
    VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION		= (1 << 0),
    VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION		= (1 << 1),
80
} virNodeDevPCICapFlags;
81

82 83 84
typedef struct _virNodeDevCapsDef virNodeDevCapsDef;
typedef virNodeDevCapsDef *virNodeDevCapsDefPtr;
struct _virNodeDevCapsDef {
85
    virNodeDevCapType type;
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    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 {
E
Eric Blake 已提交
102 103 104 105 106 107 108
            unsigned int domain;
            unsigned int bus;
            unsigned int slot;
            unsigned int function;
            unsigned int product;
            unsigned int vendor;
            unsigned int class;
109 110
            char *product_name;
            char *vendor_name;
111 112
            virPCIDeviceAddressPtr physical_function;
            virPCIDeviceAddressPtr *virtual_functions;
113
            size_t num_virtual_functions;
E
Eric Blake 已提交
114
            unsigned int flags;
115 116 117
            virPCIDeviceAddressPtr *iommuGroupDevices;
            size_t nIommuGroupDevices;
            unsigned int iommuGroupNumber;
118
            int numa_node;
119 120
        } pci_dev;
        struct {
E
Eric Blake 已提交
121 122 123 124
            unsigned int bus;
            unsigned int device;
            unsigned int product;
            unsigned int vendor;
125 126 127 128
            char *product_name;
            char *vendor_name;
        } usb_dev;
        struct {
E
Eric Blake 已提交
129 130 131 132
            unsigned int number;
            unsigned int _class;		/* "class" is reserved in C */
            unsigned int subclass;
            unsigned int protocol;
133 134 135 136
            char *description;
        } usb_if;
        struct {
            char *address;
E
Eric Blake 已提交
137
            unsigned int address_len;
138
            char *ifname;
139
            virNodeDevNetCapType subtype;  /* LAST -> no subtype */
140 141
        } net;
        struct {
E
Eric Blake 已提交
142
            unsigned int host;
143 144
            char *wwnn;
            char *wwpn;
O
Osier Yang 已提交
145
            char *fabric_wwn;
E
Eric Blake 已提交
146
            unsigned int flags;
147 148
            int max_vports;
            int vports;
149
        } scsi_host;
D
David Allan 已提交
150 151 152
        struct {
            char *name;
        } scsi_target;
153
        struct {
E
Eric Blake 已提交
154 155 156 157
            unsigned int host;
            unsigned int bus;
            unsigned int target;
            unsigned int lun;
158 159 160 161
            char *type;
        } scsi;
        struct {
            unsigned long long size;
162 163
            unsigned long long num_blocks;
            unsigned long long logical_block_size;
164
            unsigned long long removable_media_size;
165
            char *block;
166 167 168 169
            char *bus;
            char *drive_type;
            char *model;
            char *vendor;
170
            char *serial;
171
            char *media_label;
E
Eric Blake 已提交
172
            unsigned int flags;	/* virNodeDevStorageCapFlags bits */
173
        } storage;
174 175 176
        struct {
            char *path;
        } sg; /* SCSI generic device */
177 178 179 180 181 182 183 184 185
    } data;
    virNodeDevCapsDefPtr next;          /* next capability */
};


typedef struct _virNodeDeviceDef virNodeDeviceDef;
typedef virNodeDeviceDef *virNodeDeviceDefPtr;
struct _virNodeDeviceDef {
    char *name;                         /* device name (unique on node) */
186
    char *sysfs_path;                   /* udev name/sysfs path */
187
    char *parent;			/* optional parent device name */
188
    char *parent_sysfs_path;            /* udev parent name/sysfs path */
189
    char *driver;                       /* optional driver name */
190 191 192 193 194 195 196
    virNodeDevCapsDefPtr caps;		/* optional device capabilities */
};


typedef struct _virNodeDeviceObj virNodeDeviceObj;
typedef virNodeDeviceObj *virNodeDeviceObjPtr;
struct _virNodeDeviceObj {
197
    virMutex lock;
198

199 200 201 202 203 204 205 206 207
    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 {
208
    size_t count;
209 210 211
    virNodeDeviceObjPtr *objs;
};

212 213 214
typedef struct _virNodeDeviceDriverState virNodeDeviceDriverState;
typedef virNodeDeviceDriverState *virNodeDeviceDriverStatePtr;
struct _virNodeDeviceDriverState {
215
    virMutex lock;
216

217 218 219 220 221
    virNodeDeviceObjList devs;		/* currently-known devices */
    void *privateData;			/* driver-specific private data */
};


E
Eric Blake 已提交
222
int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap);
223

E
Eric Blake 已提交
224
virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs,
225
                                            const char *name);
226
virNodeDeviceObjPtr
E
Eric Blake 已提交
227
virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs,
228 229
                             const char *sysfs_path)
    ATTRIBUTE_NONNULL(2);
230

231
virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs,
E
Eric Blake 已提交
232
                                           virNodeDeviceDefPtr def);
233 234

void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs,
E
Eric Blake 已提交
235
                            virNodeDeviceObjPtr dev);
236

E
Eric Blake 已提交
237
char *virNodeDeviceDefFormat(const virNodeDeviceDef *def);
238

239
virNodeDeviceDefPtr virNodeDeviceDefParseString(const char *str,
240 241
                                                int create,
                                                const char *virt_type);
242
virNodeDeviceDefPtr virNodeDeviceDefParseFile(const char *filename,
243 244
                                              int create,
                                              const char *virt_type);
245
virNodeDeviceDefPtr virNodeDeviceDefParseNode(xmlDocPtr xml,
246
                                              xmlNodePtr root,
247 248
                                              int create,
                                              const char *virt_type);
249

250
int virNodeDeviceGetWWNs(virNodeDeviceDefPtr def,
251 252 253
                         char **wwnn,
                         char **wwpn);

E
Eric Blake 已提交
254
int virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs,
255 256 257 258
                               const char *dev_name,
                               const char *parent_name,
                               int *parent_host);

259 260 261 262 263 264 265 266
void virNodeDeviceDefFree(virNodeDeviceDefPtr def);

void virNodeDeviceObjFree(virNodeDeviceObjPtr dev);

void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs);

void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps);

D
Daniel P. Berrange 已提交
267 268 269
void virNodeDeviceObjLock(virNodeDeviceObjPtr obj);
void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj);

270 271 272 273 274 275 276 277 278
# define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP \
                (VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM        | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV       | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV       | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET           | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST     | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET   | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI          | \
279 280
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE       | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST       | \
281 282
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS        | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC)
283

284 285 286 287 288 289 290 291
typedef bool (*virNodeDeviceObjListFilter)(virConnectPtr conn,
                                           virNodeDeviceDefPtr def);

int virNodeDeviceObjListExport(virConnectPtr conn,
                               virNodeDeviceObjList devobjs,
                               virNodeDevicePtr **devices,
                               virNodeDeviceObjListFilter filter,
                               unsigned int flags);
292

293
#endif /* __VIR_NODE_DEVICE_CONF_H__ */