node_device_conf.h 12.5 KB
Newer Older
1 2 3
/*
 * node_device_conf.h: config handling for node devices
 *
4
 * Copyright (C) 2009-2015 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
#pragma once
24

25 26 27 28 29 30 31 32 33
#include "internal.h"
#include "virbitmap.h"
#include "virutil.h"
#include "virscsihost.h"
#include "virpci.h"
#include "virvhba.h"
#include "device_conf.h"
#include "storage_adapter_conf.h"
#include "virenum.h"
34

35
#include <libxml/tree.h>
36

37 38
#define CREATE_DEVICE 1
#define EXISTING_DEVICE 0
39

40 41 42 43 44 45 46 47
typedef enum {
    /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */
    VIR_NODE_DEV_DEVNODE_DEV,
    VIR_NODE_DEV_DEVNODE_LINK,

    VIR_NODE_DEV_DEVNODE_LAST
} virNodeDevDevnodeType;

48
VIR_ENUM_DECL(virNodeDevDevnode);
49

50
typedef enum {
51
    /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */
52 53 54 55 56 57 58 59 60 61 62
    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_TARGET,       /* SCSI Target */
    VIR_NODE_DEV_CAP_SCSI,              /* SCSI device */
    VIR_NODE_DEV_CAP_STORAGE,           /* Storage device */
    VIR_NODE_DEV_CAP_FC_HOST,           /* FC Host Bus Adapter */
    VIR_NODE_DEV_CAP_VPORTS,            /* HBA which is capable of vports */
63
    VIR_NODE_DEV_CAP_SCSI_GENERIC,      /* SCSI generic device */
M
Marc-André Lureau 已提交
64
    VIR_NODE_DEV_CAP_DRM,               /* DRM device */
65 66
    VIR_NODE_DEV_CAP_MDEV_TYPES,        /* Device capable of mediated devices */
    VIR_NODE_DEV_CAP_MDEV,              /* Mediated device */
B
Bjoern Walk 已提交
67
    VIR_NODE_DEV_CAP_CCW_DEV,           /* s390 CCW device */
68

69
    VIR_NODE_DEV_CAP_LAST
70
} virNodeDevCapType;
71

72
typedef enum {
73
    /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */
74 75
    VIR_NODE_DEV_CAP_NET_80203,         /* 802.03 network device */
    VIR_NODE_DEV_CAP_NET_80211,         /* 802.11 network device */
76
    VIR_NODE_DEV_CAP_NET_LAST
77
} virNodeDevNetCapType;
78

79 80
VIR_ENUM_DECL(virNodeDevCap);
VIR_ENUM_DECL(virNodeDevNetCap);
81

82
typedef enum {
83 84 85
    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),
86
} virNodeDevStorageCapFlags;
87

88
typedef enum {
89 90
    VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST                   = (1 << 0),
    VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS                 = (1 << 1),
91
} virNodeDevSCSIHostCapFlags;
92

93
typedef enum {
94
    VIR_NODE_DEV_CAP_FLAG_FC_RPORT                      = (1 << 0),
95 96
} virNodeDevSCSITargetCapsFlags;

97
typedef enum {
98 99 100
    VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION     = (1 << 0),
    VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION      = (1 << 1),
    VIR_NODE_DEV_CAP_FLAG_PCIE                      = (1 << 2),
101
    VIR_NODE_DEV_CAP_FLAG_PCI_MDEV                  = (1 << 3),
102
} virNodeDevPCICapFlags;
103

M
Marc-André Lureau 已提交
104 105 106 107 108 109 110 111 112
typedef enum {
    /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */
    VIR_NODE_DEV_DRM_PRIMARY,
    VIR_NODE_DEV_DRM_CONTROL,
    VIR_NODE_DEV_DRM_RENDER,

    VIR_NODE_DEV_DRM_LAST
} virNodeDevDRMType;

113
VIR_ENUM_DECL(virNodeDevDRM);
M
Marc-André Lureau 已提交
114

115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
typedef struct _virNodeDevCapSystemHardware virNodeDevCapSystemHardware;
typedef virNodeDevCapSystemHardware *virNodeDevCapSystemHardwarePtr;
struct _virNodeDevCapSystemHardware {
    char *vendor_name;
    char *version;
    char *serial;
    unsigned char uuid[VIR_UUID_BUFLEN];
};

typedef struct _virNodeDevCapSystemFirmware virNodeDevCapSystemFirmware;
typedef virNodeDevCapSystemFirmware *virNodeDevCapSystemFirmwarePtr;
struct _virNodeDevCapSystemFirmware {
    char *vendor_name;
    char *version;
    char *release_date;
};

typedef struct _virNodeDevCapSystem virNodeDevCapSystem;
typedef virNodeDevCapSystem *virNodeDevCapSystemPtr;
struct _virNodeDevCapSystem {
    char *product_name;
    virNodeDevCapSystemHardware hardware;
    virNodeDevCapSystemFirmware firmware;
};

140 141 142 143 144 145 146
typedef struct _virNodeDevCapMdev virNodeDevCapMdev;
typedef virNodeDevCapMdev *virNodeDevCapMdevPtr;
struct _virNodeDevCapMdev {
    char *type;
    unsigned int iommuGroupNumber;
};

147 148 149 150 151 152 153 154 155
typedef struct _virNodeDevCapPCIDev virNodeDevCapPCIDev;
typedef virNodeDevCapPCIDev *virNodeDevCapPCIDevPtr;
struct _virNodeDevCapPCIDev {
    unsigned int domain;
    unsigned int bus;
    unsigned int slot;
    unsigned int function;
    unsigned int product;
    unsigned int vendor;
156
    int klass;
157 158 159 160 161 162 163 164 165 166 167 168 169
    char *product_name;
    char *vendor_name;
    virPCIDeviceAddressPtr physical_function;
    virPCIDeviceAddressPtr *virtual_functions;
    size_t num_virtual_functions;
    unsigned int max_virtual_functions;
    unsigned int flags;
    virPCIDeviceAddressPtr *iommuGroupDevices;
    size_t nIommuGroupDevices;
    unsigned int iommuGroupNumber;
    int numa_node;
    virPCIEDeviceInfoPtr pci_express;
    int hdrType; /* enum virPCIHeaderType or -1 */
170
    virMediatedDeviceTypePtr *mdev_types;
171
    size_t nmdev_types;
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
};

typedef struct _virNodeDevCapUSBDev virNodeDevCapUSBDev;
typedef virNodeDevCapUSBDev *virNodeDevCapUSBDevPtr;
struct _virNodeDevCapUSBDev {
   unsigned int bus;
   unsigned int device;
   unsigned int product;
   unsigned int vendor;
   char *product_name;
   char *vendor_name;
};

typedef struct _virNodeDevCapUSBIf virNodeDevCapUSBIf;
typedef virNodeDevCapUSBIf *virNodeDevCapUSBIfPtr;
struct _virNodeDevCapUSBIf {
    unsigned int number;
189
    unsigned int klass;
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
    unsigned int subclass;
    unsigned int protocol;
    char *description;
};

typedef struct _virNodeDevCapNet virNodeDevCapNet;
typedef virNodeDevCapNet *virNodeDevCapNetPtr;
struct _virNodeDevCapNet {
    char *address;
    unsigned int address_len;
    char *ifname;
    virNetDevIfLink lnk;
    virNodeDevNetCapType subtype;  /* LAST -> no subtype */
    virBitmapPtr features; /* enum virNetDevFeature */
};

typedef struct _virNodeDevCapSCSIHost virNodeDevCapSCSIHost;
typedef virNodeDevCapSCSIHost *virNodeDevCapSCSIHostPtr;
struct _virNodeDevCapSCSIHost {
    unsigned int host;
    int unique_id;
    char *wwnn;
    char *wwpn;
    char *fabric_wwn;
    unsigned int flags;
    int max_vports;
    int vports;
};

typedef struct _virNodeDevCapSCSITarget virNodeDevCapSCSITarget;
typedef virNodeDevCapSCSITarget *virNodeDevCapSCSITargetPtr;
struct _virNodeDevCapSCSITarget {
    char *name;
223 224 225
    unsigned int flags; /* enum virNodeDevSCSITargetCapsFlags */
    char *rport;
    char *wwpn;
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
};

typedef struct _virNodeDevCapSCSI virNodeDevCapSCSI;
typedef virNodeDevCapSCSI *virNodeDevCapSCSIPtr;
struct _virNodeDevCapSCSI {
    unsigned int host;
    unsigned int bus;
    unsigned int target;
    unsigned int lun;
    char *type;
};

typedef struct _virNodeDevCapStorage virNodeDevCapStorage;
typedef virNodeDevCapStorage *virNodeDevCapStoragePtr;
struct _virNodeDevCapStorage {
    unsigned long long size;
    unsigned long long num_blocks;
    unsigned long long logical_block_size;
    unsigned long long removable_media_size;
    char *block;
    char *bus;
    char *drive_type;
    char *model;
    char *vendor;
    char *serial;
    char *media_label;
252
    unsigned int flags; /* virNodeDevStorageCapFlags bits */
253 254 255 256 257 258 259 260 261 262 263 264 265 266
};

typedef struct _virNodeDevCapSCSIGeneric virNodeDevCapSCSIGeneric;
typedef virNodeDevCapSCSIGeneric *virNodeDevCapSCSIGenericPtr;
struct _virNodeDevCapSCSIGeneric {
    char *path;
};

typedef struct _virNodeDevCapDRM virNodeDevCapDRM;
typedef virNodeDevCapDRM *virNodeDevCapDRMPtr;
struct _virNodeDevCapDRM {
    virNodeDevDRMType type;
};

B
Bjoern Walk 已提交
267 268 269 270 271 272 273 274
typedef struct _virNodeDevCapCCW virNodeDevCapCCW;
typedef virNodeDevCapCCW *virNodeDevCapCCWPtr;
struct _virNodeDevCapCCW {
    unsigned int cssid;
    unsigned int ssid;
    unsigned int devno;
};

275 276 277
typedef struct _virNodeDevCapData virNodeDevCapData;
typedef virNodeDevCapData *virNodeDevCapDataPtr;
struct _virNodeDevCapData {
278
    virNodeDevCapType type;
279
    union {
280 281 282 283 284 285 286 287 288 289 290
        virNodeDevCapSystem system;
        virNodeDevCapPCIDev pci_dev;
        virNodeDevCapUSBDev usb_dev;
        virNodeDevCapUSBIf usb_if;
        virNodeDevCapNet net;
        virNodeDevCapSCSIHost scsi_host;
        virNodeDevCapSCSITarget scsi_target;
        virNodeDevCapSCSI scsi;
        virNodeDevCapStorage storage;
        virNodeDevCapSCSIGeneric sg;
        virNodeDevCapDRM drm;
291
        virNodeDevCapMdev mdev;
B
Bjoern Walk 已提交
292
        virNodeDevCapCCW ccw_dev;
293
    };
294
};
295 296 297 298 299

typedef struct _virNodeDevCapsDef virNodeDevCapsDef;
typedef virNodeDevCapsDef *virNodeDevCapsDefPtr;
struct _virNodeDevCapsDef {
    virNodeDevCapData data;
300 301 302 303 304 305 306 307
    virNodeDevCapsDefPtr next;          /* next capability */
};


typedef struct _virNodeDeviceDef virNodeDeviceDef;
typedef virNodeDeviceDef *virNodeDeviceDefPtr;
struct _virNodeDeviceDef {
    char *name;                         /* device name (unique on node) */
308
    char *sysfs_path;                   /* udev name/sysfs path */
309
    char *parent;                       /* optional parent device name */
310
    char *parent_sysfs_path;            /* udev parent name/sysfs path */
311 312 313
    char *parent_wwnn;                  /* optional parent wwnn */
    char *parent_wwpn;                  /* optional parent wwpn */
    char *parent_fabric_wwn;            /* optional parent fabric_wwn */
314
    char *driver;                       /* optional driver name */
315 316
    char *devnode;                      /* /dev path */
    char **devlinks;                    /* /dev links */
317
    virNodeDevCapsDefPtr caps;          /* optional device capabilities */
318 319
};

320 321
char *
virNodeDeviceDefFormat(const virNodeDeviceDef *def);
322

323 324 325 326
virNodeDeviceDefPtr
virNodeDeviceDefParseString(const char *str,
                            int create,
                            const char *virt_type);
327

328 329 330 331
virNodeDeviceDefPtr
virNodeDeviceDefParseFile(const char *filename,
                          int create,
                          const char *virt_type);
332

333 334 335 336 337
virNodeDeviceDefPtr
virNodeDeviceDefParseNode(xmlDocPtr xml,
                          xmlNodePtr root,
                          int create,
                          const char *virt_type);
338

339 340 341 342 343 344 345 346
int
virNodeDeviceGetWWNs(virNodeDeviceDefPtr def,
                     char **wwnn,
                     char **wwpn);

void
virNodeDeviceDefFree(virNodeDeviceDefPtr def);

347 348
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNodeDeviceDef, virNodeDeviceDefFree);

349 350
void
virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps);
351

352
#define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP \
353 354 355 356 357 358 359 360
                (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          | \
361 362
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE       | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST       | \
363
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS        | \
364
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC  | \
365 366
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM           | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES    | \
367 368
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV          | \
                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV)
369

370 371 372
int
virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host);

373 374 375 376 377 378 379
int
virNodeDeviceGetSCSITargetCaps(const char *sysfsPath,
                               virNodeDevCapSCSITargetPtr scsi_target);

int
virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath,
                               virNodeDevCapPCIDevPtr pci_dev);
380 381 382

int
virNodeDeviceUpdateCaps(virNodeDeviceDefPtr def);
383 384 385 386

int
virNodeDeviceCapsListExport(virNodeDeviceDefPtr def,
                            virNodeDevCapType **list);