1 /* 2 * storage_backend.h: internal storage driver backend contract 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library. If not, see 16 * <http://www.gnu.org/licenses/>. 17 */ 18 19 #pragma once 20 21 #include <sys/stat.h> 22 23 #include "internal.h" 24 #include "virstorageobj.h" 25 #include "storage_driver.h" 26 27 typedef char * (*virStorageBackendFindPoolSources)(const char *srcSpec, 28 unsigned int flags); 29 typedef int (*virStorageBackendCheckPool)(virStoragePoolObj *pool, 30 bool *active); 31 typedef int (*virStorageBackendStartPool)(virStoragePoolObj *pool); 32 typedef int (*virStorageBackendBuildPool)(virStoragePoolObj *pool, 33 unsigned int flags); 34 typedef int (*virStorageBackendRefreshPool)(virStoragePoolObj *pool); 35 typedef int (*virStorageBackendStopPool)(virStoragePoolObj *pool); 36 typedef int (*virStorageBackendDeletePool)(virStoragePoolObj *pool, 37 unsigned int flags); 38 39 /* A 'buildVol' backend must remove any volume created on error since 40 * the storage driver does not distinguish whether the failure is due 41 * to failure to create the volume, to reserve any space necessary for 42 * the volume, to get data about the volume, to change it's accessibility, 43 * etc. This avoids issues arising from a creation failure due to some 44 * external action which created a volume of the same name that libvirt 45 * was not aware of between checking the pool and the create attempt. It 46 * also avoids extra round trips to just delete a file. 47 */ 48 typedef int (*virStorageBackendBuildVol)(virStoragePoolObj *pool, 49 virStorageVolDef *vol, 50 unsigned int flags); 51 typedef int (*virStorageBackendCreateVol)(virStoragePoolObj *pool, 52 virStorageVolDef *vol); 53 typedef int (*virStorageBackendRefreshVol)(virStoragePoolObj *pool, 54 virStorageVolDef *vol); 55 typedef int (*virStorageBackendDeleteVol)(virStoragePoolObj *pool, 56 virStorageVolDef *vol, 57 unsigned int flags); 58 typedef int (*virStorageBackendBuildVolFrom)(virStoragePoolObj *pool, 59 virStorageVolDef *origvol, 60 virStorageVolDef *newvol, 61 unsigned int flags); 62 typedef int (*virStorageBackendVolumeResize)(virStoragePoolObj *pool, 63 virStorageVolDef *vol, 64 unsigned long long capacity, 65 unsigned int flags); 66 67 /* Upon entering this callback passed @obj is unlocked. However, 68 * the pool's asyncjobs counter has been incremented and volume's 69 * in_use has been adjusted to ensure singular usage. */ 70 typedef int (*virStorageBackendVolumeDownload)(virStoragePoolObj *obj, 71 virStorageVolDef *vol, 72 virStreamPtr stream, 73 unsigned long long offset, 74 unsigned long long length, 75 unsigned int flags); 76 77 /* Upon entering this callback passed @obj is unlocked. However, 78 * the pool's asyncjobs counter has been incremented and volume's 79 * in_use has been adjusted to ensure singular usage. */ 80 typedef int (*virStorageBackendVolumeUpload)(virStoragePoolObj *obj, 81 virStorageVolDef *vol, 82 virStreamPtr stream, 83 unsigned long long offset, 84 unsigned long long len, 85 unsigned int flags); 86 87 /* Upon entering this callback passed @obj is unlocked. However, 88 * the pool's asyncjobs counter has been incremented and volume's 89 * in_use has been adjusted to ensure singular usage. */ 90 typedef int (*virStorageBackendVolumeWipe)(virStoragePoolObj *pool, 91 virStorageVolDef *vol, 92 unsigned int algorithm, 93 unsigned int flags); 94 95 typedef struct _virStorageBackend virStorageBackend; 96 97 /* Callbacks are optional unless documented otherwise; but adding more 98 * callbacks provides better pool support. */ 99 struct _virStorageBackend { 100 int type; 101 102 virStorageBackendFindPoolSources findPoolSources; 103 virStorageBackendCheckPool checkPool; 104 virStorageBackendStartPool startPool; 105 virStorageBackendBuildPool buildPool; 106 virStorageBackendRefreshPool refreshPool; /* Must be non-NULL */ 107 virStorageBackendStopPool stopPool; 108 virStorageBackendDeletePool deletePool; 109 110 virStorageBackendBuildVol buildVol; 111 virStorageBackendBuildVolFrom buildVolFrom; 112 virStorageBackendCreateVol createVol; 113 virStorageBackendRefreshVol refreshVol; 114 virStorageBackendDeleteVol deleteVol; 115 virStorageBackendVolumeResize resizeVol; 116 virStorageBackendVolumeUpload uploadVol; 117 virStorageBackendVolumeDownload downloadVol; 118 virStorageBackendVolumeWipe wipeVol; 119 }; 120 121 virStorageBackend *virStorageBackendForType(int type); 122 123 int virStorageBackendDriversRegister(bool allmodules); 124 125 int virStorageBackendRegister(virStorageBackend *backend); 126 127 virCaps * 128 virStorageBackendGetCapabilities(void); 129