storage_conf.h 17.0 KB
Newer Older
1 2 3
/*
 * storage_conf.h: config handling for storage driver
 *
4
 * Copyright (C) 2006-2008, 2010-2014 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17
 * Copyright (C) 2006-2008 Daniel P. Berrange
 *
 * 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
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
20 21 22 23 24
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef __VIR_STORAGE_CONF_H__
25
# define __VIR_STORAGE_CONF_H__
26

27
# include "internal.h"
28
# include "virstorageencryption.h"
E
Eric Blake 已提交
29
# include "virstoragefile.h"
30
# include "virbitmap.h"
31
# include "virthread.h"
32
# include "device_conf.h"
33
# include "node_device_conf.h"
34

35
# include <libxml/tree.h>
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/*
 * How the volume's data is stored on underlying
 * physical devices - can potentially span many
 * devices in LVM case.
 */
typedef struct _virStorageVolSourceExtent virStorageVolSourceExtent;
typedef virStorageVolSourceExtent *virStorageVolSourceExtentPtr;
struct _virStorageVolSourceExtent {
    char *path;
    unsigned long long start;
    unsigned long long end;
};

typedef struct _virStorageVolSource virStorageVolSource;
typedef virStorageVolSource *virStorageVolSourcePtr;
struct _virStorageVolSource {
    int nextent;
    virStorageVolSourceExtentPtr extents;
55

56
    int partType; /* virStorageVolTypeDisk, only used by disk
57
                   * backend for partition type creation */
58 59 60 61 62 63 64 65
};


typedef struct _virStorageVolDef virStorageVolDef;
typedef virStorageVolDef *virStorageVolDefPtr;
struct _virStorageVolDef {
    char *name;
    char *key;
66
    int type; /* virStorageVolType */
67

68
    bool building;
69
    unsigned int in_use;
70

71
    virStorageVolSource source;
72
    virStorageSource target;
73 74
};

75 76 77
typedef struct _virStorageVolDefList virStorageVolDefList;
typedef virStorageVolDefList *virStorageVolDefListPtr;
struct _virStorageVolDefList {
78
    size_t count;
79 80
    virStorageVolDefPtr *objs;
};
81

82
VIR_ENUM_DECL(virStorageVol)
83

84
typedef enum {
85
    VIR_STORAGE_POOL_DIR,      /* Local directory */
86 87 88 89 90 91
    VIR_STORAGE_POOL_FS,       /* Local filesystem */
    VIR_STORAGE_POOL_NETFS,    /* Networked filesystem - eg NFS, GFS, etc */
    VIR_STORAGE_POOL_LOGICAL,  /* Logical volume groups / volumes */
    VIR_STORAGE_POOL_DISK,     /* Disk partitions */
    VIR_STORAGE_POOL_ISCSI,    /* iSCSI targets */
    VIR_STORAGE_POOL_SCSI,     /* SCSI HBA */
D
Dave Allan 已提交
92
    VIR_STORAGE_POOL_MPATH,    /* Multipath devices */
93
    VIR_STORAGE_POOL_RBD,      /* RADOS Block Device */
94
    VIR_STORAGE_POOL_SHEEPDOG, /* Sheepdog device */
95
    VIR_STORAGE_POOL_GLUSTER,  /* Gluster device */
R
Roman Bogorodskiy 已提交
96
    VIR_STORAGE_POOL_ZFS,      /* ZFS */
97 98

    VIR_STORAGE_POOL_LAST,
99
} virStoragePoolType;
100

101
VIR_ENUM_DECL(virStoragePool)
102

103
typedef enum {
104 105 106 107
    VIR_STORAGE_DEVICE_TYPE_DISK = 0x00,
    VIR_STORAGE_DEVICE_TYPE_ROM = 0x05,

    VIR_STORAGE_DEVICE_TYPE_LAST,
108
} virStoragePoolDeviceType;
109

110 111 112 113 114 115 116 117 118 119 120 121

/*
 * For remote pools, info on how to reach the host
 */
typedef struct _virStoragePoolSourceHost virStoragePoolSourceHost;
typedef virStoragePoolSourceHost *virStoragePoolSourceHostPtr;
struct _virStoragePoolSourceHost {
    char *name;
    int port;
};


122
/*
123 124
 * For MSDOS partitions, the free area is important when
 * creating logical partitions
125
 */
126
typedef enum {
127 128 129 130
    VIR_STORAGE_FREE_NONE = 0,
    VIR_STORAGE_FREE_NORMAL,
    VIR_STORAGE_FREE_LOGICAL,
    VIR_STORAGE_FREE_LAST
131
} virStorageFreeType;
132

133 134 135 136 137 138 139 140
/*
 * Available extents on the underlying storage
 */
typedef struct _virStoragePoolSourceDeviceExtent virStoragePoolSourceDeviceExtent;
typedef virStoragePoolSourceDeviceExtent *virStoragePoolSourceDeviceExtentPtr;
struct _virStoragePoolSourceDeviceExtent {
    unsigned long long start;
    unsigned long long end;
141
    int type; /* virStorageFreeType */
142 143
};

D
David Allan 已提交
144 145
typedef struct _virStoragePoolSourceInitiatorAttr virStoragePoolSourceInitiatorAttr;
struct _virStoragePoolSourceInitiatorAttr {
146
    char *iqn; /* Initiator IQN */
D
David Allan 已提交
147 148
};

149 150 151 152 153 154 155 156 157 158
/*
 * Pools can be backed by one or more devices, and some
 * allow us to track free space on underlying devices.
 */
typedef struct _virStoragePoolSourceDevice virStoragePoolSourceDevice;
typedef virStoragePoolSourceDevice *virStoragePoolSourceDevicePtr;
struct _virStoragePoolSourceDevice {
    int nfreeExtent;
    virStoragePoolSourceDeviceExtentPtr freeExtents;
    char *path;
159 160
    int format; /* Pool specific source format */

161
    /* When the source device is a physical disk,
162 163
     * the geometry data is needed
     */
164
    struct _geometry {
P
Peter Krempa 已提交
165
        int cylinders;
166 167 168
        int heads;
        int sectors;
    } geometry;
169 170
};

171
typedef enum {
172 173 174
    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_DEFAULT = 0,
    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST,
    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST,
175

176
    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_LAST,
177
} virStoragePoolSourceAdapterType;
178
VIR_ENUM_DECL(virStoragePoolSourceAdapter)
179 180

typedef struct _virStoragePoolSourceAdapter virStoragePoolSourceAdapter;
181
typedef virStoragePoolSourceAdapter *virStoragePoolSourceAdapterPtr;
182
struct _virStoragePoolSourceAdapter {
183
    int type; /* virStoragePoolSourceAdapterType */
184 185

    union {
186 187
        struct {
            char *name;
188 189 190
            virDevicePCIAddress parentaddr; /* host address */
            int unique_id;
            bool has_parent;
191
        } scsi_host;
192 193 194 195
        struct {
            char *parent;
            char *wwnn;
            char *wwpn;
196
            int managed;        /* enum virTristateSwitch */
197 198 199
        } fchost;
    } data;
};
200 201 202 203

typedef struct _virStoragePoolSource virStoragePoolSource;
typedef virStoragePoolSource *virStoragePoolSourcePtr;
struct _virStoragePoolSource {
204 205 206
    /* An optional (maybe multiple) host(s) */
    size_t nhost;
    virStoragePoolSourceHostPtr hosts;
207 208

    /* And either one or more devices ... */
209
    size_t ndevice;
210 211 212 213 214 215
    virStoragePoolSourceDevicePtr devices;

    /* Or a directory */
    char *dir;

    /* Or an adapter */
216
    virStoragePoolSourceAdapter adapter;
217

218 219 220
    /* Or a name */
    char *name;

D
David Allan 已提交
221 222 223
    /* Initiator IQN */
    virStoragePoolSourceInitiatorAttr initiator;

224 225
    /* Authentication information */
    virStorageAuthDefPtr auth;
226

227 228 229 230 231 232
    /* Vendor of the source */
    char *vendor;

    /* Product name of the source*/
    char *product;

233 234 235 236
    /* Pool type specific format such as filesystem type,
     * or lvm version, etc.
     */
    int format;
237 238 239 240 241
};

typedef struct _virStoragePoolTarget virStoragePoolTarget;
typedef virStoragePoolTarget *virStoragePoolTargetPtr;
struct _virStoragePoolTarget {
242 243
    char *path; /* Optional local filesystem mapping */
    virStoragePerms perms; /* Default permissions for volumes */
244 245 246 247 248 249 250
};

typedef struct _virStoragePoolDef virStoragePoolDef;
typedef virStoragePoolDef *virStoragePoolDefPtr;
struct _virStoragePoolDef {
    char *name;
    unsigned char uuid[VIR_UUID_BUFLEN];
251
    int type; /* virStoragePoolType */
252

E
Eric Blake 已提交
253 254 255
    unsigned long long allocation; /* bytes */
    unsigned long long capacity; /* bytes */
    unsigned long long available; /* bytes */
256 257 258 259 260 261 262 263 264

    virStoragePoolSource source;
    virStoragePoolTarget target;
};

typedef struct _virStoragePoolObj virStoragePoolObj;
typedef virStoragePoolObj *virStoragePoolObjPtr;

struct _virStoragePoolObj {
265
    virMutex lock;
266

267 268 269 270
    char *configFile;
    char *autostartLink;
    int active;
    int autostart;
271
    unsigned int asyncjobs;
272 273 274 275

    virStoragePoolDefPtr def;
    virStoragePoolDefPtr newDef;

276 277
    virStorageVolDefList volumes;
};
278

279 280 281
typedef struct _virStoragePoolObjList virStoragePoolObjList;
typedef virStoragePoolObjList *virStoragePoolObjListPtr;
struct _virStoragePoolObjList {
282
    size_t count;
283
    virStoragePoolObjPtr *objs;
284 285 286 287 288 289
};

typedef struct _virStorageDriverState virStorageDriverState;
typedef virStorageDriverState *virStorageDriverStatePtr;

struct _virStorageDriverState {
290
    virMutex lock;
291

292 293
    virStoragePoolObjList pools;

294 295
    char *configDir;
    char *autostartDir;
296
    bool privileged;
297 298
};

299 300 301
typedef struct _virStoragePoolSourceList virStoragePoolSourceList;
typedef virStoragePoolSourceList *virStoragePoolSourceListPtr;
struct _virStoragePoolSourceList {
302
    int type;
303 304 305
    unsigned int nsources;
    virStoragePoolSourcePtr sources;
};
306

307 308
typedef bool (*virStoragePoolObjListFilter)(virConnectPtr conn,
                                            virStoragePoolDefPtr def);
309

310 311 312
static inline int
virStoragePoolObjIsActive(virStoragePoolObjPtr pool)
{
313 314 315
    return pool->active;
}

316
int virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools,
317 318
                                 const char *configDir,
                                 const char *autostartDir);
319

320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
virStoragePoolObjPtr
virStoragePoolObjFindByUUID(virStoragePoolObjListPtr pools,
                            const unsigned char *uuid);
virStoragePoolObjPtr
virStoragePoolObjFindByName(virStoragePoolObjListPtr pools,
                            const char *name);
virStoragePoolObjPtr
virStoragePoolSourceFindDuplicateDevices(virStoragePoolObjPtr pool,
                                         virStoragePoolDefPtr def);

virStorageVolDefPtr
virStorageVolDefFindByKey(virStoragePoolObjPtr pool,
                          const char *key);
virStorageVolDefPtr
virStorageVolDefFindByPath(virStoragePoolObjPtr pool,
                           const char *path);
virStorageVolDefPtr
virStorageVolDefFindByName(virStoragePoolObjPtr pool,
                           const char *name);
339 340 341

void virStoragePoolObjClearVols(virStoragePoolObjPtr pool);

342 343 344
virStoragePoolDefPtr virStoragePoolDefParseString(const char *xml);
virStoragePoolDefPtr virStoragePoolDefParseFile(const char *filename);
virStoragePoolDefPtr virStoragePoolDefParseNode(xmlDocPtr xml,
345
                                                xmlNodePtr root);
346
char *virStoragePoolDefFormat(virStoragePoolDefPtr def);
347

348 349 350 351 352 353 354 355 356 357
virStorageVolDefPtr
virStorageVolDefParseString(virStoragePoolDefPtr pool,
                            const char *xml);
virStorageVolDefPtr
virStorageVolDefParseFile(virStoragePoolDefPtr pool,
                          const char *filename);
virStorageVolDefPtr
virStorageVolDefParseNode(virStoragePoolDefPtr pool,
                          xmlDocPtr xml,
                          xmlNodePtr root);
358
char *virStorageVolDefFormat(virStoragePoolDefPtr pool,
359 360
                             virStorageVolDefPtr def);

361 362 363
virStoragePoolObjPtr
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
                           virStoragePoolDefPtr def);
364

365 366
int virStoragePoolSaveConfig(const char *configDir,
                             virStoragePoolDefPtr def);
367
int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
368 369
                             virStoragePoolObjPtr pool,
                             virStoragePoolDefPtr def);
370
int virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool);
371 372

void virStorageVolDefFree(virStorageVolDefPtr def);
373
void virStoragePoolSourceClear(virStoragePoolSourcePtr source);
374
void virStoragePoolSourceDeviceClear(virStoragePoolSourceDevicePtr dev);
375
void virStoragePoolSourceFree(virStoragePoolSourcePtr source);
376 377
void virStoragePoolDefFree(virStoragePoolDefPtr def);
void virStoragePoolObjFree(virStoragePoolObjPtr pool);
378 379
void virStoragePoolObjListFree(virStoragePoolObjListPtr pools);
void virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
380 381
                             virStoragePoolObjPtr pool);

382
virStoragePoolSourcePtr
383
virStoragePoolDefParseSourceString(const char *srcSpec,
384 385
                                   int pool_type);
virStoragePoolSourcePtr
386 387
virStoragePoolSourceListNewSource(virStoragePoolSourceListPtr list);
char *virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def);
388

389 390 391 392
int virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
                                 virStoragePoolDefPtr def,
                                 unsigned int check_active);

393 394 395 396
char *virStoragePoolGetVhbaSCSIHostParent(virConnectPtr conn,
                                          const char *name)
    ATTRIBUTE_NONNULL(1);

397 398
int virStoragePoolSourceFindDuplicate(virConnectPtr conn,
                                      virStoragePoolObjListPtr pools,
399 400
                                      virStoragePoolDefPtr def);

D
Daniel P. Berrange 已提交
401 402 403
void virStoragePoolObjLock(virStoragePoolObjPtr obj);
void virStoragePoolObjUnlock(virStoragePoolObjPtr obj);

404

405
typedef enum {
406 407 408 409 410 411 412 413 414 415 416 417
    VIR_STORAGE_POOL_FS_AUTO = 0,
    VIR_STORAGE_POOL_FS_EXT2,
    VIR_STORAGE_POOL_FS_EXT3,
    VIR_STORAGE_POOL_FS_EXT4,
    VIR_STORAGE_POOL_FS_UFS,
    VIR_STORAGE_POOL_FS_ISO,
    VIR_STORAGE_POOL_FS_UDF,
    VIR_STORAGE_POOL_FS_GFS,
    VIR_STORAGE_POOL_FS_GFS2,
    VIR_STORAGE_POOL_FS_VFAT,
    VIR_STORAGE_POOL_FS_HFSPLUS,
    VIR_STORAGE_POOL_FS_XFS,
J
Jim Fehlig 已提交
418
    VIR_STORAGE_POOL_FS_OCFS2,
419
    VIR_STORAGE_POOL_FS_LAST,
420
} virStoragePoolFormatFileSystem;
421
VIR_ENUM_DECL(virStoragePoolFormatFileSystem)
422

423
typedef enum {
424 425
    VIR_STORAGE_POOL_NETFS_AUTO = 0,
    VIR_STORAGE_POOL_NETFS_NFS,
426
    VIR_STORAGE_POOL_NETFS_GLUSTERFS,
427
    VIR_STORAGE_POOL_NETFS_CIFS,
428
    VIR_STORAGE_POOL_NETFS_LAST,
429
} virStoragePoolFormatFileSystemNet;
430
VIR_ENUM_DECL(virStoragePoolFormatFileSystemNet)
431

432
typedef enum {
433 434 435 436 437 438 439 440 441 442
    VIR_STORAGE_POOL_DISK_UNKNOWN = 0,
    VIR_STORAGE_POOL_DISK_DOS = 1,
    VIR_STORAGE_POOL_DISK_DVH,
    VIR_STORAGE_POOL_DISK_GPT,
    VIR_STORAGE_POOL_DISK_MAC,
    VIR_STORAGE_POOL_DISK_BSD,
    VIR_STORAGE_POOL_DISK_PC98,
    VIR_STORAGE_POOL_DISK_SUN,
    VIR_STORAGE_POOL_DISK_LVM2,
    VIR_STORAGE_POOL_DISK_LAST,
443
} virStoragePoolFormatDisk;
444
VIR_ENUM_DECL(virStoragePoolFormatDisk)
445

446
typedef enum {
447 448 449
    VIR_STORAGE_POOL_LOGICAL_UNKNOWN = 0,
    VIR_STORAGE_POOL_LOGICAL_LVM2 = 1,
    VIR_STORAGE_POOL_LOGICAL_LAST,
450
} virStoragePoolFormatLogical;
451
VIR_ENUM_DECL(virStoragePoolFormatLogical)
452 453

/*
454
 * XXX: these are basically partition types.
455
 *
456 457 458
 * fdisk has a bazillion partition ID types parted has
 * practically none, and splits the * info across 3
 * different attributes.
459 460 461
 *
 * So this is a semi-generic set
 */
462
typedef enum {
463 464 465 466 467 468 469 470 471
    VIR_STORAGE_VOL_DISK_NONE = 0,
    VIR_STORAGE_VOL_DISK_LINUX,
    VIR_STORAGE_VOL_DISK_FAT16,
    VIR_STORAGE_VOL_DISK_FAT32,
    VIR_STORAGE_VOL_DISK_LINUX_SWAP,
    VIR_STORAGE_VOL_DISK_LINUX_LVM,
    VIR_STORAGE_VOL_DISK_LINUX_RAID,
    VIR_STORAGE_VOL_DISK_EXTENDED,
    VIR_STORAGE_VOL_DISK_LAST,
472
} virStorageVolFormatDisk;
473
VIR_ENUM_DECL(virStorageVolFormatDisk)
474

475
typedef enum {
476 477 478 479 480
    VIR_STORAGE_VOL_DISK_TYPE_NONE = 0,
    VIR_STORAGE_VOL_DISK_TYPE_PRIMARY,
    VIR_STORAGE_VOL_DISK_TYPE_LOGICAL,
    VIR_STORAGE_VOL_DISK_TYPE_EXTENDED,
    VIR_STORAGE_VOL_DISK_TYPE_LAST,
481
} virStorageVolTypeDisk;
482

483
/*
484 485
 * Mapping of Parted fs-types MUST be kept in the
 * same order as virStorageVolFormatDisk
486
 */
487
typedef enum {
488 489 490 491 492 493 494 495 496
    VIR_STORAGE_PARTED_FS_TYPE_NONE = 0,
    VIR_STORAGE_PARTED_FS_TYPE_LINUX,
    VIR_STORAGE_PARTED_FS_TYPE_FAT16,
    VIR_STORAGE_PARTED_FS_TYPE_FAT32,
    VIR_STORAGE_PARTED_FS_TYPE_LINUX_SWAP,
    VIR_STORAGE_PARTED_FS_TYPE_LINUX_LVM,
    VIR_STORAGE_PARTED_FS_TYPE_LINUX_RAID,
    VIR_STORAGE_PARTED_FS_TYPE_EXTENDED,
    VIR_STORAGE_PARTED_FS_TYPE_LAST,
497
} virStoragePartedFsType;
498
VIR_ENUM_DECL(virStoragePartedFs)
499

500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
# define VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE   \
                (VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE)

# define VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_PERSISTENT   \
                (VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT)

# define VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART    \
                (VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART |  \
                 VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART)

# define VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE  \
                (VIR_CONNECT_LIST_STORAGE_POOLS_DIR      | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_FS       | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_NETFS    | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL  | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_DISK     | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI    | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_SCSI     | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_MPATH    | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_RBD      | \
522
                 VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG | \
R
Roman Bogorodskiy 已提交
523 524
                 VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER  | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_ZFS)
525 526 527 528 529 530 531

# define VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ALL                  \
                (VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE     | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_PERSISTENT | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART  | \
                 VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)

532 533 534 535 536
int virStoragePoolObjListExport(virConnectPtr conn,
                                virStoragePoolObjList poolobjs,
                                virStoragePoolPtr **pools,
                                virStoragePoolObjListFilter filter,
                                unsigned int flags);
537

538
#endif /* __VIR_STORAGE_CONF_H__ */