You need to sign in or sign up before continuing.
storage_conf.h 15.2 KB
Newer Older
1 2 3
/*
 * storage_conf.h: config handling for storage driver
 *
E
Eric Blake 已提交
4
 * Copyright (C) 2006-2008, 2010-2012 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * 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
 * 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: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef __VIR_STORAGE_CONF_H__
25
# define __VIR_STORAGE_CONF_H__
26

27 28 29 30
# include "internal.h"
# include "util.h"
# include "storage_encryption_conf.h"
# include "threads.h"
31

32
# include <libxml/tree.h>
33

34 35 36 37 38 39 40
/* Shared structs */



typedef struct _virStoragePerms virStoragePerms;
typedef virStoragePerms *virStoragePermsPtr;
struct _virStoragePerms {
41 42 43
    mode_t mode;
    uid_t uid;
    gid_t gid;
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    char *label;
};

/* Storage volumes */


/*
 * 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;
};


/*
 * How the volume appears on the host
 */
typedef struct _virStorageVolTarget virStorageVolTarget;
typedef virStorageVolTarget *virStorageVolTargetPtr;
struct _virStorageVolTarget {
    char *path;
    int format;
    virStoragePerms perms;
80
    int type; /* only used by disk backend for partition type */
81 82
    /* Currently used only in virStorageVolDef.target, not in .backingstore. */
    virStorageEncryptionPtr encryption;
83 84 85 86 87 88 89 90
};


typedef struct _virStorageVolDef virStorageVolDef;
typedef virStorageVolDef *virStorageVolDefPtr;
struct _virStorageVolDef {
    char *name;
    char *key;
91
    int type; /* virStorageVolType enum */
92

93 94
    unsigned int building;

E
Eric Blake 已提交
95 96
    unsigned long long allocation; /* bytes */
    unsigned long long capacity; /* bytes */
97 98 99

    virStorageVolSource source;
    virStorageVolTarget target;
100
    virStorageVolTarget backingStore;
101 102
};

103 104 105 106 107 108
typedef struct _virStorageVolDefList virStorageVolDefList;
typedef virStorageVolDefList *virStorageVolDefListPtr;
struct _virStorageVolDefList {
    unsigned int count;
    virStorageVolDefPtr *objs;
};
109 110 111 112 113 114



/* Storage pools */

enum virStoragePoolType {
115
    VIR_STORAGE_POOL_DIR,      /* Local directory */
116 117 118 119 120 121
    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 已提交
122
    VIR_STORAGE_POOL_MPATH,    /* Multipath devices */
123
    VIR_STORAGE_POOL_RBD,      /* RADOS Block Device */
124 125

    VIR_STORAGE_POOL_LAST,
126 127
};

128
VIR_ENUM_DECL(virStoragePool)
129

130 131 132 133 134 135 136
enum virStoragePoolDeviceType {
    VIR_STORAGE_DEVICE_TYPE_DISK = 0x00,
    VIR_STORAGE_DEVICE_TYPE_ROM = 0x05,

    VIR_STORAGE_DEVICE_TYPE_LAST,
};

137 138 139 140

enum virStoragePoolAuthType {
    VIR_STORAGE_POOL_AUTH_NONE,
    VIR_STORAGE_POOL_AUTH_CHAP,
141
    VIR_STORAGE_POOL_AUTH_CEPHX,
142 143 144 145 146 147 148 149 150
};

typedef struct _virStoragePoolAuthChap virStoragePoolAuthChap;
typedef virStoragePoolAuthChap *virStoragePoolAuthChapPtr;
struct _virStoragePoolAuthChap {
    char *login;
    char *passwd;
};

151 152 153 154 155 156 157 158 159
typedef struct _virStoragePoolAuthCephx virStoragePoolAuthCephx;
typedef virStoragePoolAuthCephx *virStoragePoolAuthCephxPtr;
struct _virStoragePoolAuthCephx {
    char *username;
    struct {
            unsigned char uuid[VIR_UUID_BUFLEN];
            char *usage;
    } secret;
};
160 161 162 163 164 165 166 167 168 169 170 171

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


172 173 174 175 176 177 178 179 180 181 182 183
/*
 * For MSDOS partitions, the free area
 * is important when creating
 * logical partitions
 */
enum virStorageFreeType {
    VIR_STORAGE_FREE_NONE = 0,
    VIR_STORAGE_FREE_NORMAL,
    VIR_STORAGE_FREE_LOGICAL,
    VIR_STORAGE_FREE_LAST
};

184 185 186 187 188 189 190 191
/*
 * Available extents on the underlying storage
 */
typedef struct _virStoragePoolSourceDeviceExtent virStoragePoolSourceDeviceExtent;
typedef virStoragePoolSourceDeviceExtent *virStoragePoolSourceDeviceExtentPtr;
struct _virStoragePoolSourceDeviceExtent {
    unsigned long long start;
    unsigned long long end;
192
    int type;  /* free space type */
193 194
};

D
David Allan 已提交
195 196 197 198 199 200
typedef struct _virStoragePoolSourceInitiatorAttr virStoragePoolSourceInitiatorAttr;
struct _virStoragePoolSourceInitiatorAttr {
    /* Initiator IQN */
    char *iqn;
};

201 202 203 204 205 206 207 208 209 210 211
/*
 * 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;
    int format;     /* Pool specific source format */
212 213 214 215 216 217 218
    /* When the source device is a physical disk,
       the geometry data is needed */
    struct _geometry {
        int cyliders;
        int heads;
        int sectors;
    } geometry;
219 220 221 222 223 224 225
};



typedef struct _virStoragePoolSource virStoragePoolSource;
typedef virStoragePoolSource *virStoragePoolSourcePtr;
struct _virStoragePoolSource {
226 227 228
    /* An optional (maybe multiple) host(s) */
    size_t nhost;
    virStoragePoolSourceHostPtr hosts;
229 230 231 232 233 234 235 236 237 238 239

    /* And either one or more devices ... */
    int ndevice;
    virStoragePoolSourceDevicePtr devices;

    /* Or a directory */
    char *dir;

    /* Or an adapter */
    char *adapter;

240 241 242
    /* Or a name */
    char *name;

D
David Allan 已提交
243 244 245
    /* Initiator IQN */
    virStoragePoolSourceInitiatorAttr initiator;

246 247 248
    int authType;       /* virStoragePoolAuthType */
    union {
        virStoragePoolAuthChap chap;
249
        virStoragePoolAuthCephx cephx;
250 251
    } auth;

252 253 254 255 256 257
    /* Vendor of the source */
    char *vendor;

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

258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
    int format; /* Pool type specific format such as filesystem type, or lvm version, etc */
};


typedef struct _virStoragePoolTarget virStoragePoolTarget;
typedef virStoragePoolTarget *virStoragePoolTargetPtr;
struct _virStoragePoolTarget {
    char *path;                /* Optional local filesystem mapping */
    virStoragePerms perms;     /* Default permissions for volumes */
};


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

E
Eric Blake 已提交
278 279 280
    unsigned long long allocation; /* bytes */
    unsigned long long capacity; /* bytes */
    unsigned long long available; /* bytes */
281 282 283 284 285 286 287 288 289

    virStoragePoolSource source;
    virStoragePoolTarget target;
};

typedef struct _virStoragePoolObj virStoragePoolObj;
typedef virStoragePoolObj *virStoragePoolObjPtr;

struct _virStoragePoolObj {
290
    virMutex lock;
291

292 293 294 295
    char *configFile;
    char *autostartLink;
    int active;
    int autostart;
296
    unsigned int asyncjobs;
297 298 299 300

    virStoragePoolDefPtr def;
    virStoragePoolDefPtr newDef;

301 302
    virStorageVolDefList volumes;
};
303

304 305 306 307 308
typedef struct _virStoragePoolObjList virStoragePoolObjList;
typedef virStoragePoolObjList *virStoragePoolObjListPtr;
struct _virStoragePoolObjList {
    unsigned int count;
    virStoragePoolObjPtr *objs;
309 310 311 312 313 314 315 316 317
};




typedef struct _virStorageDriverState virStorageDriverState;
typedef virStorageDriverState *virStorageDriverStatePtr;

struct _virStorageDriverState {
318
    virMutex lock;
319

320 321
    virStoragePoolObjList pools;

322 323 324 325
    char *configDir;
    char *autostartDir;
};

326 327 328
typedef struct _virStoragePoolSourceList virStoragePoolSourceList;
typedef virStoragePoolSourceList *virStoragePoolSourceListPtr;
struct _virStoragePoolSourceList {
329
    int type;
330 331 332
    unsigned int nsources;
    virStoragePoolSourcePtr sources;
};
333

334

335 336 337 338
static inline int virStoragePoolObjIsActive(virStoragePoolObjPtr pool) {
    return pool->active;
}

339
# define virStorageReportError(code, ...)                                \
340
    virReportErrorHelper(VIR_FROM_STORAGE, code, __FILE__,               \
341
                         __FUNCTION__, __LINE__, __VA_ARGS__)
342

343
int virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools,
344 345
                                 const char *configDir,
                                 const char *autostartDir);
346

347
virStoragePoolObjPtr virStoragePoolObjFindByUUID(virStoragePoolObjListPtr pools,
348
                                                 const unsigned char *uuid);
349
virStoragePoolObjPtr virStoragePoolObjFindByName(virStoragePoolObjListPtr pools,
350
                                                 const char *name);
351 352
virStoragePoolObjPtr virStoragePoolSourceFindDuplicateDevices(virStoragePoolObjPtr pool,
                                                              virStoragePoolDefPtr def);
353 354 355 356 357 358 359 360 361 362

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

void virStoragePoolObjClearVols(virStoragePoolObjPtr pool);

363 364 365
virStoragePoolDefPtr virStoragePoolDefParseString(const char *xml);
virStoragePoolDefPtr virStoragePoolDefParseFile(const char *filename);
virStoragePoolDefPtr virStoragePoolDefParseNode(xmlDocPtr xml,
366
                                                xmlNodePtr root);
367
char *virStoragePoolDefFormat(virStoragePoolDefPtr def);
368

369
virStorageVolDefPtr virStorageVolDefParseString(virStoragePoolDefPtr pool,
370
                                                const char *xml);
371
virStorageVolDefPtr virStorageVolDefParseFile(virStoragePoolDefPtr pool,
372
                                              const char *filename);
373
virStorageVolDefPtr virStorageVolDefParseNode(virStoragePoolDefPtr pool,
374 375
                                              xmlDocPtr xml,
                                              xmlNodePtr root);
376
char *virStorageVolDefFormat(virStoragePoolDefPtr pool,
377 378
                             virStorageVolDefPtr def);

379
virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
380 381
                                                virStoragePoolDefPtr def);

382
int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
383 384
                             virStoragePoolObjPtr pool,
                             virStoragePoolDefPtr def);
385
int virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool);
386 387

void virStorageVolDefFree(virStorageVolDefPtr def);
388
void virStoragePoolSourceClear(virStoragePoolSourcePtr source);
389
void virStoragePoolSourceFree(virStoragePoolSourcePtr source);
390 391
void virStoragePoolDefFree(virStoragePoolDefPtr def);
void virStoragePoolObjFree(virStoragePoolObjPtr pool);
392 393
void virStoragePoolObjListFree(virStoragePoolObjListPtr pools);
void virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
394 395
                             virStoragePoolObjPtr pool);

396
virStoragePoolSourcePtr
397
virStoragePoolDefParseSourceString(const char *srcSpec,
398 399
                                   int pool_type);
virStoragePoolSourcePtr
400 401
virStoragePoolSourceListNewSource(virStoragePoolSourceListPtr list);
char *virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def);
402

403 404 405 406
int virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
                                 virStoragePoolDefPtr def,
                                 unsigned int check_active);

407 408 409
int virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools,
                                      virStoragePoolDefPtr def);

D
Daniel P. Berrange 已提交
410 411 412
void virStoragePoolObjLock(virStoragePoolObjPtr obj);
void virStoragePoolObjUnlock(virStoragePoolObjPtr obj);

413 414 415 416 417 418 419 420 421 422 423 424 425 426

enum virStoragePoolFormatFileSystem {
    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 已提交
427
    VIR_STORAGE_POOL_FS_OCFS2,
428 429
    VIR_STORAGE_POOL_FS_LAST,
};
430
VIR_ENUM_DECL(virStoragePoolFormatFileSystem)
431 432 433 434

enum virStoragePoolFormatFileSystemNet {
    VIR_STORAGE_POOL_NETFS_AUTO = 0,
    VIR_STORAGE_POOL_NETFS_NFS,
435
    VIR_STORAGE_POOL_NETFS_GLUSTERFS,
436
    VIR_STORAGE_POOL_NETFS_CIFS,
437 438
    VIR_STORAGE_POOL_NETFS_LAST,
};
439
VIR_ENUM_DECL(virStoragePoolFormatFileSystemNet)
440 441 442 443 444 445 446 447 448 449 450 451 452 453

enum virStoragePoolFormatDisk {
    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,
};

454
VIR_ENUM_DECL(virStoragePoolFormatDisk)
455 456 457 458 459 460

enum virStoragePoolFormatLogical {
    VIR_STORAGE_POOL_LOGICAL_UNKNOWN = 0,
    VIR_STORAGE_POOL_LOGICAL_LVM2 = 1,
    VIR_STORAGE_POOL_LOGICAL_LAST,
};
461
VIR_ENUM_DECL(virStoragePoolFormatLogical)
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482

/*
 * XXX these are basically partition types.
 *
 * fdisk has a bazillion partition ID types
 * parted has practically none, and splits the
 * info across 3 different attributes.
 *
 * So this is a semi-generic set
 */
enum virStorageVolFormatDisk {
    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,
};
483
VIR_ENUM_DECL(virStorageVolFormatDisk)
484

485 486 487 488 489 490 491
enum virStorageVolTypeDisk {
    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,
};
492

493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
/*
 * Mapping of Parted fs-types
 * MUST be kept in the same order
 * as virStorageVolFormatDisk
 */
enum virStoragePartedFsType {
    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,
};
VIR_ENUM_DECL(virStoragePartedFsType)
510

511
#endif /* __VIR_STORAGE_CONF_H__ */