node_device_conf.h 9.7 KB
Newer Older
1 2 3
/*
 * node_device_conf.h: config handling for node devices
 *
4
 * Copyright (C) 2010-2011 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

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
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 */
D
David Allan 已提交
45
    VIR_NODE_DEV_CAP_SCSI_TARGET,	/* SCSI Target */
46 47 48 49 50 51 52 53 54 55 56 57
    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
};

58 59 60 61 62 63 64
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
};

65 66
VIR_ENUM_DECL(virNodeDevCap)
VIR_ENUM_DECL(virNodeDevNetCap)
67
VIR_ENUM_DECL(virNodeDevHBACap)
68 69 70 71 72 73 74

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),
};

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

80 81 82 83 84
enum virNodeDevPCICapFlags {
    VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION		= (1 << 0),
    VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION		= (1 << 1),
};

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


typedef struct _virNodeDeviceDef virNodeDeviceDef;
typedef virNodeDeviceDef *virNodeDeviceDefPtr;
struct _virNodeDeviceDef {
    char *name;                         /* device name (unique on node) */
180
    char *sysfs_path;                   /* udev name/sysfs path */
181
    char *parent;			/* optional parent device name */
182
    char *parent_sysfs_path;            /* udev parent name/sysfs path */
183
    char *driver;                       /* optional driver name */
184 185 186 187 188 189 190
    virNodeDevCapsDefPtr caps;		/* optional device capabilities */
};


typedef struct _virNodeDeviceObj virNodeDeviceObj;
typedef virNodeDeviceObj *virNodeDeviceObjPtr;
struct _virNodeDeviceObj {
191
    virMutex lock;
192

193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    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 {
209
    virMutex lock;
210

211 212 213 214 215
    virNodeDeviceObjList devs;		/* currently-known devices */
    void *privateData;			/* driver-specific private data */
};


216 217
int virNodeDeviceHasCap(const virNodeDeviceObjPtr dev, const char *cap);

218 219
virNodeDeviceObjPtr virNodeDeviceFindByName(const virNodeDeviceObjListPtr devs,
                                            const char *name);
220 221
virNodeDeviceObjPtr
virNodeDeviceFindBySysfsPath(const virNodeDeviceObjListPtr devs,
222 223
                             const char *sysfs_path)
    ATTRIBUTE_NONNULL(2);
224

225
virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs,
226 227 228 229 230
                                           const virNodeDeviceDefPtr def);

void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs,
                            const virNodeDeviceObjPtr dev);

231
char *virNodeDeviceDefFormat(const virNodeDeviceDefPtr def);
232

233
virNodeDeviceDefPtr virNodeDeviceDefParseString(const char *str,
234 235
                                                int create,
                                                const char *virt_type);
236
virNodeDeviceDefPtr virNodeDeviceDefParseFile(const char *filename,
237 238
                                              int create,
                                              const char *virt_type);
239
virNodeDeviceDefPtr virNodeDeviceDefParseNode(xmlDocPtr xml,
240
                                              xmlNodePtr root,
241 242
                                              int create,
                                              const char *virt_type);
243

244
int virNodeDeviceGetWWNs(virNodeDeviceDefPtr def,
245 246 247
                         char **wwnn,
                         char **wwpn);

248
int virNodeDeviceGetParentHost(const virNodeDeviceObjListPtr devs,
249 250 251 252
                               const char *dev_name,
                               const char *parent_name,
                               int *parent_host);

253 254 255 256 257 258 259 260
void virNodeDeviceDefFree(virNodeDeviceDefPtr def);

void virNodeDeviceObjFree(virNodeDeviceObjPtr dev);

void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs);

void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps);

D
Daniel P. Berrange 已提交
261 262 263
void virNodeDeviceObjLock(virNodeDeviceObjPtr obj);
void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj);

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
# 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          | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE)

int virNodeDeviceList(virConnectPtr conn,
                      virNodeDeviceObjList devobjs,
                      virNodeDevicePtr **devices,
                      unsigned int flags);

280
#endif /* __VIR_NODE_DEVICE_CONF_H__ */