Generate libvirt constants from libvirt sources.
- Add a yacc-based parser and a hand-written lexer to read the remote_protocol.x file from libvirt's sources. - Use the new parser to generate the constants used to communicate with libvirt.
This commit is contained in:
		
							
								
								
									
										474
									
								
								internal/constants/constants.gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										474
									
								
								internal/constants/constants.gen.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,474 @@ | |||||||
|  | /* | ||||||
|  |  * This file generated by internal/lvgen/generate.go. DO NOT EDIT BY HAND! | ||||||
|  |  * | ||||||
|  |  * To regenerate, run 'go generate' in internal/lvgen. | ||||||
|  |  */ | ||||||
|  | package constants | ||||||
|  |  | ||||||
|  | // libvirt procedure identifiers and other enums | ||||||
|  | // | ||||||
|  | // These are libvirt procedure numbers which correspond to each respective | ||||||
|  | // API call between remote_internal driver and libvirtd. Each procedure is | ||||||
|  | // identified by a unique number which *may change in any future libvirt | ||||||
|  | // update*. | ||||||
|  | // | ||||||
|  | // Examples: | ||||||
|  | //	REMOTE_PROC_CONNECT_OPEN = 1 | ||||||
|  | //	REMOTE_PROC_DOMAIN_DEFINE_XML = 11 | ||||||
|  | //	REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207, | ||||||
|  | const ( | ||||||
|  | 	// From enums: | ||||||
|  | 	AuthNone = 0 | ||||||
|  | 	AuthSasl = 1 | ||||||
|  | 	AuthPolkit = 2 | ||||||
|  | 	ProcConnectOpen = 1 | ||||||
|  | 	ProcConnectClose = 2 | ||||||
|  | 	ProcConnectGetType = 3 | ||||||
|  | 	ProcConnectGetVersion = 4 | ||||||
|  | 	ProcConnectGetMaxVcpus = 5 | ||||||
|  | 	ProcNodeGetInfo = 6 | ||||||
|  | 	ProcConnectGetCapabilities = 7 | ||||||
|  | 	ProcDomainAttachDevice = 8 | ||||||
|  | 	ProcDomainCreate = 9 | ||||||
|  | 	ProcDomainCreateXML = 10 | ||||||
|  | 	ProcDomainDefineXML = 11 | ||||||
|  | 	ProcDomainDestroy = 12 | ||||||
|  | 	ProcDomainDetachDevice = 13 | ||||||
|  | 	ProcDomainGetXMLDesc = 14 | ||||||
|  | 	ProcDomainGetAutostart = 15 | ||||||
|  | 	ProcDomainGetInfo = 16 | ||||||
|  | 	ProcDomainGetMaxMemory = 17 | ||||||
|  | 	ProcDomainGetMaxVcpus = 18 | ||||||
|  | 	ProcDomainGetOsType = 19 | ||||||
|  | 	ProcDomainGetVcpus = 20 | ||||||
|  | 	ProcConnectListDefinedDomains = 21 | ||||||
|  | 	ProcDomainLookupByID = 22 | ||||||
|  | 	ProcDomainLookupByName = 23 | ||||||
|  | 	ProcDomainLookupByUUID = 24 | ||||||
|  | 	ProcConnectNumOfDefinedDomains = 25 | ||||||
|  | 	ProcDomainPinVcpu = 26 | ||||||
|  | 	ProcDomainReboot = 27 | ||||||
|  | 	ProcDomainResume = 28 | ||||||
|  | 	ProcDomainSetAutostart = 29 | ||||||
|  | 	ProcDomainSetMaxMemory = 30 | ||||||
|  | 	ProcDomainSetMemory = 31 | ||||||
|  | 	ProcDomainSetVcpus = 32 | ||||||
|  | 	ProcDomainShutdown = 33 | ||||||
|  | 	ProcDomainSuspend = 34 | ||||||
|  | 	ProcDomainUndefine = 35 | ||||||
|  | 	ProcConnectListDefinedNetworks = 36 | ||||||
|  | 	ProcConnectListDomains = 37 | ||||||
|  | 	ProcConnectListNetworks = 38 | ||||||
|  | 	ProcNetworkCreate = 39 | ||||||
|  | 	ProcNetworkCreateXML = 40 | ||||||
|  | 	ProcNetworkDefineXML = 41 | ||||||
|  | 	ProcNetworkDestroy = 42 | ||||||
|  | 	ProcNetworkGetXMLDesc = 43 | ||||||
|  | 	ProcNetworkGetAutostart = 44 | ||||||
|  | 	ProcNetworkGetBridgeName = 45 | ||||||
|  | 	ProcNetworkLookupByName = 46 | ||||||
|  | 	ProcNetworkLookupByUUID = 47 | ||||||
|  | 	ProcNetworkSetAutostart = 48 | ||||||
|  | 	ProcNetworkUndefine = 49 | ||||||
|  | 	ProcConnectNumOfDefinedNetworks = 50 | ||||||
|  | 	ProcConnectNumOfDomains = 51 | ||||||
|  | 	ProcConnectNumOfNetworks = 52 | ||||||
|  | 	ProcDomainCoreDump = 53 | ||||||
|  | 	ProcDomainRestore = 54 | ||||||
|  | 	ProcDomainSave = 55 | ||||||
|  | 	ProcDomainGetSchedulerType = 56 | ||||||
|  | 	ProcDomainGetSchedulerParameters = 57 | ||||||
|  | 	ProcDomainSetSchedulerParameters = 58 | ||||||
|  | 	ProcConnectGetHostname = 59 | ||||||
|  | 	ProcConnectSupportsFeature = 60 | ||||||
|  | 	ProcDomainMigratePrepare = 61 | ||||||
|  | 	ProcDomainMigratePerform = 62 | ||||||
|  | 	ProcDomainMigrateFinish = 63 | ||||||
|  | 	ProcDomainBlockStats = 64 | ||||||
|  | 	ProcDomainInterfaceStats = 65 | ||||||
|  | 	ProcAuthList = 66 | ||||||
|  | 	ProcAuthSaslInit = 67 | ||||||
|  | 	ProcAuthSaslStart = 68 | ||||||
|  | 	ProcAuthSaslStep = 69 | ||||||
|  | 	ProcAuthPolkit = 70 | ||||||
|  | 	ProcConnectNumOfStoragePools = 71 | ||||||
|  | 	ProcConnectListStoragePools = 72 | ||||||
|  | 	ProcConnectNumOfDefinedStoragePools = 73 | ||||||
|  | 	ProcConnectListDefinedStoragePools = 74 | ||||||
|  | 	ProcConnectFindStoragePoolSources = 75 | ||||||
|  | 	ProcStoragePoolCreateXML = 76 | ||||||
|  | 	ProcStoragePoolDefineXML = 77 | ||||||
|  | 	ProcStoragePoolCreate = 78 | ||||||
|  | 	ProcStoragePoolBuild = 79 | ||||||
|  | 	ProcStoragePoolDestroy = 80 | ||||||
|  | 	ProcStoragePoolDelete = 81 | ||||||
|  | 	ProcStoragePoolUndefine = 82 | ||||||
|  | 	ProcStoragePoolRefresh = 83 | ||||||
|  | 	ProcStoragePoolLookupByName = 84 | ||||||
|  | 	ProcStoragePoolLookupByUUID = 85 | ||||||
|  | 	ProcStoragePoolLookupByVolume = 86 | ||||||
|  | 	ProcStoragePoolGetInfo = 87 | ||||||
|  | 	ProcStoragePoolGetXMLDesc = 88 | ||||||
|  | 	ProcStoragePoolGetAutostart = 89 | ||||||
|  | 	ProcStoragePoolSetAutostart = 90 | ||||||
|  | 	ProcStoragePoolNumOfVolumes = 91 | ||||||
|  | 	ProcStoragePoolListVolumes = 92 | ||||||
|  | 	ProcStorageVolCreateXML = 93 | ||||||
|  | 	ProcStorageVolDelete = 94 | ||||||
|  | 	ProcStorageVolLookupByName = 95 | ||||||
|  | 	ProcStorageVolLookupByKey = 96 | ||||||
|  | 	ProcStorageVolLookupByPath = 97 | ||||||
|  | 	ProcStorageVolGetInfo = 98 | ||||||
|  | 	ProcStorageVolGetXMLDesc = 99 | ||||||
|  | 	ProcStorageVolGetPath = 100 | ||||||
|  | 	ProcNodeGetCellsFreeMemory = 101 | ||||||
|  | 	ProcNodeGetFreeMemory = 102 | ||||||
|  | 	ProcDomainBlockPeek = 103 | ||||||
|  | 	ProcDomainMemoryPeek = 104 | ||||||
|  | 	ProcConnectDomainEventRegister = 105 | ||||||
|  | 	ProcConnectDomainEventDeregister = 106 | ||||||
|  | 	ProcDomainEventLifecycle = 107 | ||||||
|  | 	ProcDomainMigratePrepare2 = 108 | ||||||
|  | 	ProcDomainMigrateFinish2 = 109 | ||||||
|  | 	ProcConnectGetUri = 110 | ||||||
|  | 	ProcNodeNumOfDevices = 111 | ||||||
|  | 	ProcNodeListDevices = 112 | ||||||
|  | 	ProcNodeDeviceLookupByName = 113 | ||||||
|  | 	ProcNodeDeviceGetXMLDesc = 114 | ||||||
|  | 	ProcNodeDeviceGetParent = 115 | ||||||
|  | 	ProcNodeDeviceNumOfCaps = 116 | ||||||
|  | 	ProcNodeDeviceListCaps = 117 | ||||||
|  | 	ProcNodeDeviceDettach = 118 | ||||||
|  | 	ProcNodeDeviceReAttach = 119 | ||||||
|  | 	ProcNodeDeviceReset = 120 | ||||||
|  | 	ProcDomainGetSecurityLabel = 121 | ||||||
|  | 	ProcNodeGetSecurityModel = 122 | ||||||
|  | 	ProcNodeDeviceCreateXML = 123 | ||||||
|  | 	ProcNodeDeviceDestroy = 124 | ||||||
|  | 	ProcStorageVolCreateXMLFrom = 125 | ||||||
|  | 	ProcConnectNumOfInterfaces = 126 | ||||||
|  | 	ProcConnectListInterfaces = 127 | ||||||
|  | 	ProcInterfaceLookupByName = 128 | ||||||
|  | 	ProcInterfaceLookupByMacString = 129 | ||||||
|  | 	ProcInterfaceGetXMLDesc = 130 | ||||||
|  | 	ProcInterfaceDefineXML = 131 | ||||||
|  | 	ProcInterfaceUndefine = 132 | ||||||
|  | 	ProcInterfaceCreate = 133 | ||||||
|  | 	ProcInterfaceDestroy = 134 | ||||||
|  | 	ProcConnectDomainXMLFromNative = 135 | ||||||
|  | 	ProcConnectDomainXMLToNative = 136 | ||||||
|  | 	ProcConnectNumOfDefinedInterfaces = 137 | ||||||
|  | 	ProcConnectListDefinedInterfaces = 138 | ||||||
|  | 	ProcConnectNumOfSecrets = 139 | ||||||
|  | 	ProcConnectListSecrets = 140 | ||||||
|  | 	ProcSecretLookupByUUID = 141 | ||||||
|  | 	ProcSecretDefineXML = 142 | ||||||
|  | 	ProcSecretGetXMLDesc = 143 | ||||||
|  | 	ProcSecretSetValue = 144 | ||||||
|  | 	ProcSecretGetValue = 145 | ||||||
|  | 	ProcSecretUndefine = 146 | ||||||
|  | 	ProcSecretLookupByUsage = 147 | ||||||
|  | 	ProcDomainMigratePrepareTunnel = 148 | ||||||
|  | 	ProcConnectIsSecure = 149 | ||||||
|  | 	ProcDomainIsActive = 150 | ||||||
|  | 	ProcDomainIsPersistent = 151 | ||||||
|  | 	ProcNetworkIsActive = 152 | ||||||
|  | 	ProcNetworkIsPersistent = 153 | ||||||
|  | 	ProcStoragePoolIsActive = 154 | ||||||
|  | 	ProcStoragePoolIsPersistent = 155 | ||||||
|  | 	ProcInterfaceIsActive = 156 | ||||||
|  | 	ProcConnectGetLibVersion = 157 | ||||||
|  | 	ProcConnectCompareCPU = 158 | ||||||
|  | 	ProcDomainMemoryStats = 159 | ||||||
|  | 	ProcDomainAttachDeviceFlags = 160 | ||||||
|  | 	ProcDomainDetachDeviceFlags = 161 | ||||||
|  | 	ProcConnectBaselineCPU = 162 | ||||||
|  | 	ProcDomainGetJobInfo = 163 | ||||||
|  | 	ProcDomainAbortJob = 164 | ||||||
|  | 	ProcStorageVolWipe = 165 | ||||||
|  | 	ProcDomainMigrateSetMaxDowntime = 166 | ||||||
|  | 	ProcConnectDomainEventRegisterAny = 167 | ||||||
|  | 	ProcConnectDomainEventDeregisterAny = 168 | ||||||
|  | 	ProcDomainEventReboot = 169 | ||||||
|  | 	ProcDomainEventRtcChange = 170 | ||||||
|  | 	ProcDomainEventWatchdog = 171 | ||||||
|  | 	ProcDomainEventIOError = 172 | ||||||
|  | 	ProcDomainEventGraphics = 173 | ||||||
|  | 	ProcDomainUpdateDeviceFlags = 174 | ||||||
|  | 	ProcNwfilterLookupByName = 175 | ||||||
|  | 	ProcNwfilterLookupByUUID = 176 | ||||||
|  | 	ProcNwfilterGetXMLDesc = 177 | ||||||
|  | 	ProcConnectNumOfNwfilters = 178 | ||||||
|  | 	ProcConnectListNwfilters = 179 | ||||||
|  | 	ProcNwfilterDefineXML = 180 | ||||||
|  | 	ProcNwfilterUndefine = 181 | ||||||
|  | 	ProcDomainManagedSave = 182 | ||||||
|  | 	ProcDomainHasManagedSaveImage = 183 | ||||||
|  | 	ProcDomainManagedSaveRemove = 184 | ||||||
|  | 	ProcDomainSnapshotCreateXML = 185 | ||||||
|  | 	ProcDomainSnapshotGetXMLDesc = 186 | ||||||
|  | 	ProcDomainSnapshotNum = 187 | ||||||
|  | 	ProcDomainSnapshotListNames = 188 | ||||||
|  | 	ProcDomainSnapshotLookupByName = 189 | ||||||
|  | 	ProcDomainHasCurrentSnapshot = 190 | ||||||
|  | 	ProcDomainSnapshotCurrent = 191 | ||||||
|  | 	ProcDomainRevertToSnapshot = 192 | ||||||
|  | 	ProcDomainSnapshotDelete = 193 | ||||||
|  | 	ProcDomainGetBlockInfo = 194 | ||||||
|  | 	ProcDomainEventIOErrorReason = 195 | ||||||
|  | 	ProcDomainCreateWithFlags = 196 | ||||||
|  | 	ProcDomainSetMemoryParameters = 197 | ||||||
|  | 	ProcDomainGetMemoryParameters = 198 | ||||||
|  | 	ProcDomainSetVcpusFlags = 199 | ||||||
|  | 	ProcDomainGetVcpusFlags = 200 | ||||||
|  | 	ProcDomainOpenConsole = 201 | ||||||
|  | 	ProcDomainIsUpdated = 202 | ||||||
|  | 	ProcConnectGetSysinfo = 203 | ||||||
|  | 	ProcDomainSetMemoryFlags = 204 | ||||||
|  | 	ProcDomainSetBlkioParameters = 205 | ||||||
|  | 	ProcDomainGetBlkioParameters = 206 | ||||||
|  | 	ProcDomainMigrateSetMaxSpeed = 207 | ||||||
|  | 	ProcStorageVolUpload = 208 | ||||||
|  | 	ProcStorageVolDownload = 209 | ||||||
|  | 	ProcDomainInjectNmi = 210 | ||||||
|  | 	ProcDomainScreenshot = 211 | ||||||
|  | 	ProcDomainGetState = 212 | ||||||
|  | 	ProcDomainMigrateBegin3 = 213 | ||||||
|  | 	ProcDomainMigratePrepare3 = 214 | ||||||
|  | 	ProcDomainMigratePrepareTunnel3 = 215 | ||||||
|  | 	ProcDomainMigratePerform3 = 216 | ||||||
|  | 	ProcDomainMigrateFinish3 = 217 | ||||||
|  | 	ProcDomainMigrateConfirm3 = 218 | ||||||
|  | 	ProcDomainSetSchedulerParametersFlags = 219 | ||||||
|  | 	ProcInterfaceChangeBegin = 220 | ||||||
|  | 	ProcInterfaceChangeCommit = 221 | ||||||
|  | 	ProcInterfaceChangeRollback = 222 | ||||||
|  | 	ProcDomainGetSchedulerParametersFlags = 223 | ||||||
|  | 	ProcDomainEventControlError = 224 | ||||||
|  | 	ProcDomainPinVcpuFlags = 225 | ||||||
|  | 	ProcDomainSendKey = 226 | ||||||
|  | 	ProcNodeGetCPUStats = 227 | ||||||
|  | 	ProcNodeGetMemoryStats = 228 | ||||||
|  | 	ProcDomainGetControlInfo = 229 | ||||||
|  | 	ProcDomainGetVcpuPinInfo = 230 | ||||||
|  | 	ProcDomainUndefineFlags = 231 | ||||||
|  | 	ProcDomainSaveFlags = 232 | ||||||
|  | 	ProcDomainRestoreFlags = 233 | ||||||
|  | 	ProcDomainDestroyFlags = 234 | ||||||
|  | 	ProcDomainSaveImageGetXMLDesc = 235 | ||||||
|  | 	ProcDomainSaveImageDefineXML = 236 | ||||||
|  | 	ProcDomainBlockJobAbort = 237 | ||||||
|  | 	ProcDomainGetBlockJobInfo = 238 | ||||||
|  | 	ProcDomainBlockJobSetSpeed = 239 | ||||||
|  | 	ProcDomainBlockPull = 240 | ||||||
|  | 	ProcDomainEventBlockJob = 241 | ||||||
|  | 	ProcDomainMigrateGetMaxSpeed = 242 | ||||||
|  | 	ProcDomainBlockStatsFlags = 243 | ||||||
|  | 	ProcDomainSnapshotGetParent = 244 | ||||||
|  | 	ProcDomainReset = 245 | ||||||
|  | 	ProcDomainSnapshotNumChildren = 246 | ||||||
|  | 	ProcDomainSnapshotListChildrenNames = 247 | ||||||
|  | 	ProcDomainEventDiskChange = 248 | ||||||
|  | 	ProcDomainOpenGraphics = 249 | ||||||
|  | 	ProcNodeSuspendForDuration = 250 | ||||||
|  | 	ProcDomainBlockResize = 251 | ||||||
|  | 	ProcDomainSetBlockIOTune = 252 | ||||||
|  | 	ProcDomainGetBlockIOTune = 253 | ||||||
|  | 	ProcDomainSetNumaParameters = 254 | ||||||
|  | 	ProcDomainGetNumaParameters = 255 | ||||||
|  | 	ProcDomainSetInterfaceParameters = 256 | ||||||
|  | 	ProcDomainGetInterfaceParameters = 257 | ||||||
|  | 	ProcDomainShutdownFlags = 258 | ||||||
|  | 	ProcStorageVolWipePattern = 259 | ||||||
|  | 	ProcStorageVolResize = 260 | ||||||
|  | 	ProcDomainPmSuspendForDuration = 261 | ||||||
|  | 	ProcDomainGetCPUStats = 262 | ||||||
|  | 	ProcDomainGetDiskErrors = 263 | ||||||
|  | 	ProcDomainSetMetadata = 264 | ||||||
|  | 	ProcDomainGetMetadata = 265 | ||||||
|  | 	ProcDomainBlockRebase = 266 | ||||||
|  | 	ProcDomainPmWakeup = 267 | ||||||
|  | 	ProcDomainEventTrayChange = 268 | ||||||
|  | 	ProcDomainEventPmwakeup = 269 | ||||||
|  | 	ProcDomainEventPmsuspend = 270 | ||||||
|  | 	ProcDomainSnapshotIsCurrent = 271 | ||||||
|  | 	ProcDomainSnapshotHasMetadata = 272 | ||||||
|  | 	ProcConnectListAllDomains = 273 | ||||||
|  | 	ProcDomainListAllSnapshots = 274 | ||||||
|  | 	ProcDomainSnapshotListAllChildren = 275 | ||||||
|  | 	ProcDomainEventBalloonChange = 276 | ||||||
|  | 	ProcDomainGetHostname = 277 | ||||||
|  | 	ProcDomainGetSecurityLabelList = 278 | ||||||
|  | 	ProcDomainPinEmulator = 279 | ||||||
|  | 	ProcDomainGetEmulatorPinInfo = 280 | ||||||
|  | 	ProcConnectListAllStoragePools = 281 | ||||||
|  | 	ProcStoragePoolListAllVolumes = 282 | ||||||
|  | 	ProcConnectListAllNetworks = 283 | ||||||
|  | 	ProcConnectListAllInterfaces = 284 | ||||||
|  | 	ProcConnectListAllNodeDevices = 285 | ||||||
|  | 	ProcConnectListAllNwfilters = 286 | ||||||
|  | 	ProcConnectListAllSecrets = 287 | ||||||
|  | 	ProcNodeSetMemoryParameters = 288 | ||||||
|  | 	ProcNodeGetMemoryParameters = 289 | ||||||
|  | 	ProcDomainBlockCommit = 290 | ||||||
|  | 	ProcNetworkUpdate = 291 | ||||||
|  | 	ProcDomainEventPmsuspendDisk = 292 | ||||||
|  | 	ProcNodeGetCPUMap = 293 | ||||||
|  | 	ProcDomainFstrim = 294 | ||||||
|  | 	ProcDomainSendProcessSignal = 295 | ||||||
|  | 	ProcDomainOpenChannel = 296 | ||||||
|  | 	ProcNodeDeviceLookupScsiHostByWwn = 297 | ||||||
|  | 	ProcDomainGetJobStats = 298 | ||||||
|  | 	ProcDomainMigrateGetCompressionCache = 299 | ||||||
|  | 	ProcDomainMigrateSetCompressionCache = 300 | ||||||
|  | 	ProcNodeDeviceDetachFlags = 301 | ||||||
|  | 	ProcDomainMigrateBegin3Params = 302 | ||||||
|  | 	ProcDomainMigratePrepare3Params = 303 | ||||||
|  | 	ProcDomainMigratePrepareTunnel3Params = 304 | ||||||
|  | 	ProcDomainMigratePerform3Params = 305 | ||||||
|  | 	ProcDomainMigrateFinish3Params = 306 | ||||||
|  | 	ProcDomainMigrateConfirm3Params = 307 | ||||||
|  | 	ProcDomainSetMemoryStatsPeriod = 308 | ||||||
|  | 	ProcDomainCreateXMLWithFiles = 309 | ||||||
|  | 	ProcDomainCreateWithFiles = 310 | ||||||
|  | 	ProcDomainEventDeviceRemoved = 311 | ||||||
|  | 	ProcConnectGetCPUModelNames = 312 | ||||||
|  | 	ProcConnectNetworkEventRegisterAny = 313 | ||||||
|  | 	ProcConnectNetworkEventDeregisterAny = 314 | ||||||
|  | 	ProcNetworkEventLifecycle = 315 | ||||||
|  | 	ProcConnectDomainEventCallbackRegisterAny = 316 | ||||||
|  | 	ProcConnectDomainEventCallbackDeregisterAny = 317 | ||||||
|  | 	ProcDomainEventCallbackLifecycle = 318 | ||||||
|  | 	ProcDomainEventCallbackReboot = 319 | ||||||
|  | 	ProcDomainEventCallbackRtcChange = 320 | ||||||
|  | 	ProcDomainEventCallbackWatchdog = 321 | ||||||
|  | 	ProcDomainEventCallbackIOError = 322 | ||||||
|  | 	ProcDomainEventCallbackGraphics = 323 | ||||||
|  | 	ProcDomainEventCallbackIOErrorReason = 324 | ||||||
|  | 	ProcDomainEventCallbackControlError = 325 | ||||||
|  | 	ProcDomainEventCallbackBlockJob = 326 | ||||||
|  | 	ProcDomainEventCallbackDiskChange = 327 | ||||||
|  | 	ProcDomainEventCallbackTrayChange = 328 | ||||||
|  | 	ProcDomainEventCallbackPmwakeup = 329 | ||||||
|  | 	ProcDomainEventCallbackPmsuspend = 330 | ||||||
|  | 	ProcDomainEventCallbackBalloonChange = 331 | ||||||
|  | 	ProcDomainEventCallbackPmsuspendDisk = 332 | ||||||
|  | 	ProcDomainEventCallbackDeviceRemoved = 333 | ||||||
|  | 	ProcDomainCoreDumpWithFormat = 334 | ||||||
|  | 	ProcDomainFsfreeze = 335 | ||||||
|  | 	ProcDomainFsthaw = 336 | ||||||
|  | 	ProcDomainGetTime = 337 | ||||||
|  | 	ProcDomainSetTime = 338 | ||||||
|  | 	ProcDomainEventBlockJob2 = 339 | ||||||
|  | 	ProcNodeGetFreePages = 340 | ||||||
|  | 	ProcNetworkGetDhcpLeases = 341 | ||||||
|  | 	ProcConnectGetDomainCapabilities = 342 | ||||||
|  | 	ProcDomainOpenGraphicsFd = 343 | ||||||
|  | 	ProcConnectGetAllDomainStats = 344 | ||||||
|  | 	ProcDomainBlockCopy = 345 | ||||||
|  | 	ProcDomainEventCallbackTunable = 346 | ||||||
|  | 	ProcNodeAllocPages = 347 | ||||||
|  | 	ProcDomainEventCallbackAgentLifecycle = 348 | ||||||
|  | 	ProcDomainGetFsinfo = 349 | ||||||
|  | 	ProcDomainDefineXMLFlags = 350 | ||||||
|  | 	ProcDomainGetIothreadInfo = 351 | ||||||
|  | 	ProcDomainPinIothread = 352 | ||||||
|  | 	ProcDomainInterfaceAddresses = 353 | ||||||
|  | 	ProcDomainEventCallbackDeviceAdded = 354 | ||||||
|  | 	ProcDomainAddIothread = 355 | ||||||
|  | 	ProcDomainDelIothread = 356 | ||||||
|  | 	ProcDomainSetUserPassword = 357 | ||||||
|  | 	ProcDomainRename = 358 | ||||||
|  | 	ProcDomainEventCallbackMigrationIteration = 359 | ||||||
|  | 	ProcConnectRegisterCloseCallback = 360 | ||||||
|  | 	ProcConnectUnregisterCloseCallback = 361 | ||||||
|  | 	ProcConnectEventConnectionClosed = 362 | ||||||
|  | 	ProcDomainEventCallbackJobCompleted = 363 | ||||||
|  | 	ProcDomainMigrateStartPostCopy = 364 | ||||||
|  | 	ProcDomainGetPerfEvents = 365 | ||||||
|  | 	ProcDomainSetPerfEvents = 366 | ||||||
|  | 	ProcDomainEventCallbackDeviceRemovalFailed = 367 | ||||||
|  | 	ProcConnectStoragePoolEventRegisterAny = 368 | ||||||
|  | 	ProcConnectStoragePoolEventDeregisterAny = 369 | ||||||
|  | 	ProcStoragePoolEventLifecycle = 370 | ||||||
|  | 	ProcDomainGetGuestVcpus = 371 | ||||||
|  | 	ProcDomainSetGuestVcpus = 372 | ||||||
|  | 	ProcStoragePoolEventRefresh = 373 | ||||||
|  | 	ProcConnectNodeDeviceEventRegisterAny = 374 | ||||||
|  | 	ProcConnectNodeDeviceEventDeregisterAny = 375 | ||||||
|  | 	ProcNodeDeviceEventLifecycle = 376 | ||||||
|  | 	ProcNodeDeviceEventUpdate = 377 | ||||||
|  | 	ProcStorageVolGetInfoFlags = 378 | ||||||
|  | 	ProcDomainEventCallbackMetadataChange = 379 | ||||||
|  | 	ProcConnectSecretEventRegisterAny = 380 | ||||||
|  | 	ProcConnectSecretEventDeregisterAny = 381 | ||||||
|  | 	ProcSecretEventLifecycle = 382 | ||||||
|  | 	ProcSecretEventValueChanged = 383 | ||||||
|  | 	ProcDomainSetVcpu = 384 | ||||||
|  | 	ProcDomainEventBlockThreshold = 385 | ||||||
|  | 	ProcDomainSetBlockThreshold = 386 | ||||||
|  | 	ProcDomainMigrateGetMaxDowntime = 387 | ||||||
|  | 	ProcDomainManagedSaveGetXMLDesc = 388 | ||||||
|  | 	ProcDomainManagedSaveDefineXML = 389 | ||||||
|  | 	ProcDomainSetLifecycleAction = 390 | ||||||
|  | 	 | ||||||
|  |  | ||||||
|  | 	// From consts: | ||||||
|  | 	StringMax = 4194304 | ||||||
|  | 	DomainListMax = 16384 | ||||||
|  | 	CpumapMax = 2048 | ||||||
|  | 	VcpuinfoMax = 16384 | ||||||
|  | 	CpumapsMax = 8388608 | ||||||
|  | 	IothreadInfoMax = 16384 | ||||||
|  | 	MigrateCookieMax = 4194304 | ||||||
|  | 	NetworkListMax = 16384 | ||||||
|  | 	InterfaceListMax = 16384 | ||||||
|  | 	StoragePoolListMax = 16384 | ||||||
|  | 	StorageVolListMax = 16384 | ||||||
|  | 	NodeDeviceListMax = 65536 | ||||||
|  | 	NodeDeviceCapsListMax = 65536 | ||||||
|  | 	NwfilterListMax = 16384 | ||||||
|  | 	DomainSchedulerParametersMax = 16 | ||||||
|  | 	DomainBlkioParametersMax = 16 | ||||||
|  | 	DomainMemoryParametersMax = 16 | ||||||
|  | 	DomainBlockIOTuneParametersMax = 32 | ||||||
|  | 	DomainNumaParametersMax = 16 | ||||||
|  | 	DomainPerfEventsMax = 64 | ||||||
|  | 	DomainBlockCopyParametersMax = 16 | ||||||
|  | 	NodeCPUStatsMax = 16 | ||||||
|  | 	NodeMemoryStatsMax = 16 | ||||||
|  | 	DomainBlockStatsParametersMax = 16 | ||||||
|  | 	NodeMaxCells = 1024 | ||||||
|  | 	AuthSaslDataMax = 65536 | ||||||
|  | 	AuthTypeListMax = 20 | ||||||
|  | 	DomainMemoryStatsMax = 1024 | ||||||
|  | 	DomainSnapshotListMax = 16384 | ||||||
|  | 	DomainBlockPeekBufferMax = 4194304 | ||||||
|  | 	DomainMemoryPeekBufferMax = 4194304 | ||||||
|  | 	SecurityLabelListMax = 64 | ||||||
|  | 	SecretValueMax = 65536 | ||||||
|  | 	SecretListMax = 16384 | ||||||
|  | 	CPUBaselineMax = 256 | ||||||
|  | 	DomainSendKeyMax = 16 | ||||||
|  | 	DomainInterfaceParametersMax = 16 | ||||||
|  | 	DomainGetCPUStatsNcpusMax = 128 | ||||||
|  | 	DomainGetCPUStatsMax = 2048 | ||||||
|  | 	DomainDiskErrorsMax = 256 | ||||||
|  | 	NodeMemoryParametersMax = 64 | ||||||
|  | 	DomainMigrateParamListMax = 64 | ||||||
|  | 	DomainJobStatsMax = 64 | ||||||
|  | 	ConnectCPUModelsMax = 8192 | ||||||
|  | 	DomainFsfreezeMountpointsMax = 256 | ||||||
|  | 	NetworkDhcpLeasesMax = 65536 | ||||||
|  | 	ConnectGetAllDomainStatsMax = 262144 | ||||||
|  | 	DomainEventTunableMax = 2048 | ||||||
|  | 	DomainFsinfoMax = 256 | ||||||
|  | 	DomainFsinfoDisksMax = 256 | ||||||
|  | 	DomainInterfaceMax = 2048 | ||||||
|  | 	DomainIPAddrMax = 2048 | ||||||
|  | 	DomainGuestVcpuParamsMax = 64 | ||||||
|  | 	DomainEventGraphicsIdentityMax = 20 | ||||||
|  | 	Program = 0x20008086 | ||||||
|  | 	ProtocolVersion = 1 | ||||||
|  | 	 | ||||||
|  | ) | ||||||
| @@ -15,54 +15,11 @@ | |||||||
| // Package constants provides shared data for the libvirt package. | // Package constants provides shared data for the libvirt package. | ||||||
| package constants | package constants | ||||||
|  |  | ||||||
| // protocol procedure numbers |  | ||||||
| const ( | const ( | ||||||
| 	ProgramVersion   = 1 |  | ||||||
| 	ProgramRemote    = 0x20008086 |  | ||||||
| 	ProgramQEMU      = 0x20008087 | 	ProgramQEMU      = 0x20008087 | ||||||
| 	ProgramKeepAlive = 0x6b656570 | 	ProgramKeepAlive = 0x6b656570 | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // libvirt procedure identifiers |  | ||||||
| // These are libvirt procedure numbers which correspond to each respective |  | ||||||
| // API call between remote_internal driver and libvirtd. Although stable. |  | ||||||
| // Each call is identified by a unique number which *may change at any time*. |  | ||||||
| // |  | ||||||
| // Examples: |  | ||||||
| //	REMOTE_PROC_CONNECT_OPEN = 1 |  | ||||||
| //	REMOTE_PROC_DOMAIN_DEFINE_XML = 11 |  | ||||||
| //	REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207, |  | ||||||
| // |  | ||||||
| // See: |  | ||||||
| // https://libvirt.org/git/?p=libvirt.git;a=blob_plain;f=src/remote/remote_protocol.x;hb=HEAD |  | ||||||
| const ( |  | ||||||
| 	ProcConnectOpen                = 1 |  | ||||||
| 	ProcConnectClose               = 2 |  | ||||||
| 	ProcConnectGetCapabilties      = 7 |  | ||||||
| 	ProcDomainGetXMLDesc           = 14 |  | ||||||
| 	ProcDomainLookupByName         = 23 |  | ||||||
| 	ProcDomainReboot               = 27 |  | ||||||
| 	ProcAuthList                   = 66 |  | ||||||
| 	ProcStoragePoolRefresh         = 83 |  | ||||||
| 	ProcStoragePoolLookupByName    = 84 |  | ||||||
| 	ProcConnectGetLibVersion       = 157 |  | ||||||
| 	ProcDomainMemoryStats          = 159 |  | ||||||
| 	ProcDomainCreateWithFlags      = 196 |  | ||||||
| 	ProcDomainMigrateSetMaxSpeed   = 207 |  | ||||||
| 	ProcDomainGetState             = 212 |  | ||||||
| 	ProcDomainUndefineFlags        = 231 |  | ||||||
| 	ProcDomainDestroyFlags         = 234 |  | ||||||
| 	ProcDomainReset                = 245 |  | ||||||
| 	ProcDomainSetBlockIOTune       = 252 |  | ||||||
| 	ProcDomainGetBlockIOTune       = 253 |  | ||||||
| 	ProcDomainShutdownFlags        = 258 |  | ||||||
| 	ProcConnectListAllDomains      = 273 |  | ||||||
| 	ProcConnectListAllStoragePools = 281 |  | ||||||
| 	ProcConnectListAllSecrets      = 287 |  | ||||||
| 	ProcMigratePerformParams       = 305 |  | ||||||
| 	ProcDomainDefineXMLFlags       = 350 |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| // qemu procedure identifiers | // qemu procedure identifiers | ||||||
| const ( | const ( | ||||||
| 	QEMUDomainMonitor                       = 1 | 	QEMUDomainMonitor                       = 1 | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								internal/lvgen/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								internal/lvgen/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | # Ignore the yacc intermediate files. | ||||||
|  | y.go | ||||||
|  | y.output | ||||||
|  |  | ||||||
							
								
								
									
										43
									
								
								internal/lvgen/gen/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								internal/lvgen/gen/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | |||||||
|  | // Copyright 2017 The go-libvirt Authors. | ||||||
|  | // | ||||||
|  | // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  | // you may not use this file except in compliance with the License. | ||||||
|  | // You may obtain a copy of the License at | ||||||
|  | // | ||||||
|  | //   http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|  | // | ||||||
|  | // Unless required by applicable law or agreed to in writing, software | ||||||
|  | // distributed under the License is distributed on an "AS IS" BASIS, | ||||||
|  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
|  | // See the License for the specific language governing permissions and | ||||||
|  | // limitations under the License. | ||||||
|  |  | ||||||
|  | package main | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"os" | ||||||
|  | 	"path" | ||||||
|  |  | ||||||
|  | 	"github.com/digitalocean/go-libvirt/internal/lvgen" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | // TODO: make these an argument | ||||||
|  | const lvPath = "../../../libvirt" | ||||||
|  | const protoPath = "src/remote/remote_protocol.x" | ||||||
|  |  | ||||||
|  | func main() { | ||||||
|  | 	fmt.Println("Generating golang bindings for libvirt") | ||||||
|  | 	lvFile := path.Join(lvPath, protoPath) | ||||||
|  | 	rdr, err := os.Open(lvFile) | ||||||
|  | 	if err != nil { | ||||||
|  | 		fmt.Printf("failed to open protocol file at %v: %v\n", lvFile, err) | ||||||
|  | 		os.Exit(1) | ||||||
|  | 	} | ||||||
|  | 	defer rdr.Close() | ||||||
|  |  | ||||||
|  | 	if err = lvgen.Generate(rdr); err != nil { | ||||||
|  | 		fmt.Println("go-libvirt code generator failed:", err) | ||||||
|  | 		os.Exit(1) | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										564
									
								
								internal/lvgen/generate.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										564
									
								
								internal/lvgen/generate.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,564 @@ | |||||||
|  | // Copyright 2017 The go-libvirt Authors. | ||||||
|  | // | ||||||
|  | // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  | // you may not use this file except in compliance with the License. | ||||||
|  | // You may obtain a copy of the License at | ||||||
|  | // | ||||||
|  | //   http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|  | // | ||||||
|  | // Unless required by applicable law or agreed to in writing, software | ||||||
|  | // distributed under the License is distributed on an "AS IS" BASIS, | ||||||
|  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
|  | // See the License for the specific language governing permissions and | ||||||
|  | // limitations under the License. | ||||||
|  |  | ||||||
|  | package lvgen | ||||||
|  |  | ||||||
|  | // The libvirt API is divided into several categories. (Gallia est omnis divisa | ||||||
|  | // in partes tres.) The generator will output code for each category in a | ||||||
|  | // package underneath the go-libvirt directory. | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"io" | ||||||
|  | 	"io/ioutil" | ||||||
|  | 	"os" | ||||||
|  | 	"strconv" | ||||||
|  | 	"strings" | ||||||
|  | 	"text/template" | ||||||
|  | 	"unicode" | ||||||
|  | 	"unicode/utf8" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | var keywords = map[string]int{ | ||||||
|  | 	"hyper":    HYPER, | ||||||
|  | 	"int":      INT, | ||||||
|  | 	"short":    SHORT, | ||||||
|  | 	"char":     CHAR, | ||||||
|  | 	"bool":     BOOL, | ||||||
|  | 	"case":     CASE, | ||||||
|  | 	"const":    CONST, | ||||||
|  | 	"default":  DEFAULT, | ||||||
|  | 	"double":   DOUBLE, | ||||||
|  | 	"enum":     ENUM, | ||||||
|  | 	"float":    FLOAT, | ||||||
|  | 	"opaque":   OPAQUE, | ||||||
|  | 	"string":   STRING, | ||||||
|  | 	"struct":   STRUCT, | ||||||
|  | 	"switch":   SWITCH, | ||||||
|  | 	"typedef":  TYPEDEF, | ||||||
|  | 	"union":    UNION, | ||||||
|  | 	"unsigned": UNSIGNED, | ||||||
|  | 	"void":     VOID, | ||||||
|  | 	"program":  PROGRAM, | ||||||
|  | 	"version":  VERSION, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // ConstItem stores an const's symbol and value from the parser. This struct is | ||||||
|  | // also used for enums. | ||||||
|  | type ConstItem struct { | ||||||
|  | 	Name string | ||||||
|  | 	Val  string | ||||||
|  | } | ||||||
|  |  | ||||||
|  | type Generator struct { | ||||||
|  | 	// Enums holds the list of enums found by the parser. | ||||||
|  | 	Enums []ConstItem | ||||||
|  | 	// Consts holds all the const items found by the parser. | ||||||
|  | 	Consts []ConstItem | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Gen accumulates items as the parser runs, and is then used to produce the | ||||||
|  | // output. | ||||||
|  | var Gen Generator | ||||||
|  |  | ||||||
|  | // CurrentEnumVal is the auto-incrementing value assigned to enums that aren't | ||||||
|  | // explicitly given a value. | ||||||
|  | var CurrentEnumVal int64 | ||||||
|  |  | ||||||
|  | // oneRuneTokens lists the runes the lexer will consider to be tokens when it | ||||||
|  | // finds them. These are returned to the parser using the integer value of their | ||||||
|  | // runes. | ||||||
|  | var oneRuneTokens = `{}[]<>(),=;:*` | ||||||
|  |  | ||||||
|  | // Generate will output go bindings for libvirt. The lvPath parameter should be | ||||||
|  | // the path to the root of the libvirt source directory to use for the | ||||||
|  | // generation. | ||||||
|  | func Generate(proto io.Reader) error { | ||||||
|  | 	lexer, err := NewLexer(proto) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	go lexer.Run() | ||||||
|  | 	parser := yyNewParser() | ||||||
|  | 	yyErrorVerbose = true | ||||||
|  | 	// Turn this on if you're debugging. | ||||||
|  | 	// yyDebug = 3 | ||||||
|  | 	rv := parser.Parse(lexer) | ||||||
|  | 	if rv != 0 { | ||||||
|  | 		return fmt.Errorf("failed to parse libvirt protocol: %v", rv) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Generate and write the output. | ||||||
|  | 	wr, err := os.Create("../constants/constants.gen.go") | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	defer wr.Close() | ||||||
|  |  | ||||||
|  | 	err = genGo(wr) | ||||||
|  |  | ||||||
|  | 	return err | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func genGo(wr io.Writer) error { | ||||||
|  | 	// TODO: Move this someplace nice. | ||||||
|  | 	const consttempl = `/* | ||||||
|  |  * This file generated by internal/lvgen/generate.go. DO NOT EDIT BY HAND! | ||||||
|  |  * | ||||||
|  |  * To regenerate, run 'go generate' in internal/lvgen. | ||||||
|  |  */ | ||||||
|  | package constants | ||||||
|  |  | ||||||
|  | // libvirt procedure identifiers and other enums | ||||||
|  | // | ||||||
|  | // These are libvirt procedure numbers which correspond to each respective | ||||||
|  | // API call between remote_internal driver and libvirtd. Each procedure is | ||||||
|  | // identified by a unique number which *may change in any future libvirt | ||||||
|  | // update*. | ||||||
|  | // | ||||||
|  | // Examples: | ||||||
|  | //	REMOTE_PROC_CONNECT_OPEN = 1 | ||||||
|  | //	REMOTE_PROC_DOMAIN_DEFINE_XML = 11 | ||||||
|  | //	REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207, | ||||||
|  | const ( | ||||||
|  | 	// From enums: | ||||||
|  | 	{{range .Enums}}{{.Name}} = {{.Val}} | ||||||
|  | 	{{end}} | ||||||
|  |  | ||||||
|  | 	// From consts: | ||||||
|  | 	{{range .Consts}}{{.Name}} = {{.Val}} | ||||||
|  | 	{{end}} | ||||||
|  | ) | ||||||
|  | ` | ||||||
|  | 	// Enums and consts from the protocol definition both become go consts in | ||||||
|  | 	// the generated code. We'll remove "REMOTE_" and then camel-case the | ||||||
|  | 	// name before making each one a go constant. | ||||||
|  | 	for ix, en := range Gen.Enums { | ||||||
|  | 		Gen.Enums[ix].Name = constNameTransform(en.Name) | ||||||
|  | 	} | ||||||
|  | 	for ix, en := range Gen.Consts { | ||||||
|  | 		Gen.Consts[ix].Name = constNameTransform(en.Name) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	t := template.Must(template.New("consts").Parse(consttempl)) | ||||||
|  | 	if err := t.Execute(wr, Gen); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // constNameTransform changes an upcased, snake-style name like | ||||||
|  | // REMOTE_PROTOCOL_VERSION to a comfortable Go name like ProtocolVersion. It | ||||||
|  | // also tries to upcase abbreviations so a name like DOMAIN_GET_XML becomes | ||||||
|  | // DomainGetXML, not DomainGetXml. | ||||||
|  | func constNameTransform(name string) string { | ||||||
|  | 	nn := fromSnakeToCamel(strings.TrimPrefix(name, "REMOTE_")) | ||||||
|  | 	nn = fixAbbrevs(nn) | ||||||
|  | 	return nn | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // fromSnakeToCamel transmutes a snake-cased string to a camel-cased one. All | ||||||
|  | // runes that follow an underscore are up-cased, and the underscores themselves | ||||||
|  | // are omitted. | ||||||
|  | // | ||||||
|  | // ex: "PROC_DOMAIN_GET_METADATA" -> "ProcDomainGetMetadata" | ||||||
|  | func fromSnakeToCamel(s string) string { | ||||||
|  | 	buf := make([]rune, 0, len(s)) | ||||||
|  | 	// Start with an upper-cased rune | ||||||
|  | 	hump := true | ||||||
|  |  | ||||||
|  | 	for _, r := range s { | ||||||
|  | 		if r == '_' { | ||||||
|  | 			hump = true | ||||||
|  | 		} else { | ||||||
|  | 			var transform func(rune) rune | ||||||
|  | 			if hump == true { | ||||||
|  | 				transform = unicode.ToUpper | ||||||
|  | 			} else { | ||||||
|  | 				transform = unicode.ToLower | ||||||
|  | 			} | ||||||
|  | 			buf = append(buf, transform(r)) | ||||||
|  | 			hump = false | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return string(buf) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // abbrevs is a list of abbreviations which should be all upper-case in a name. | ||||||
|  | // (This is really just to keep the go linters happy and to produce names that | ||||||
|  | // are intuitive to a go developer.) | ||||||
|  | var abbrevs = []string{"Xml", "Io", "Uuid", "Cpu", "Id", "Ip"} | ||||||
|  |  | ||||||
|  | // fixAbbrevs up-cases all instances of anything in the 'abbrevs' array. This | ||||||
|  | // would be a simple matter, but we don't want to upcase an abbreviation if it's | ||||||
|  | // actually part of a larger word, so it's not so simple. | ||||||
|  | func fixAbbrevs(s string) string { | ||||||
|  | 	for _, a := range abbrevs { | ||||||
|  | 		for loc := 0; ; { | ||||||
|  | 			loc = strings.Index(s[loc:], a) | ||||||
|  | 			if loc == -1 { | ||||||
|  | 				break | ||||||
|  | 			} | ||||||
|  | 			r := 'A' | ||||||
|  | 			if len(a) < len(s[loc:]) { | ||||||
|  | 				r, _ = utf8.DecodeRune([]byte(s[loc+len(a):])) | ||||||
|  | 			} | ||||||
|  | 			if unicode.IsLower(r) == false { | ||||||
|  | 				s = s[:loc] + strings.Replace(s[loc:], a, strings.ToUpper(a), 1) | ||||||
|  | 			} | ||||||
|  | 			loc++ | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return s | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // TODO: Move this lexer to its own file? | ||||||
|  |  | ||||||
|  | // eof is returned by the lexer when there's no more input. | ||||||
|  | const eof = -1 | ||||||
|  |  | ||||||
|  | type item struct { | ||||||
|  | 	typ          int | ||||||
|  | 	val          string | ||||||
|  | 	line, column int | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // String will display lexer items for humans to debug. There are some | ||||||
|  | // calculations here due to the way goyacc arranges token values; see the | ||||||
|  | // generated file y.go for an idea what's going on here, but the basic idea is | ||||||
|  | // that the lower token type values are reserved for single-rune tokens, which | ||||||
|  | // the lexer reports using the value of the rune itself. Everything else is | ||||||
|  | // allocated a range of type value up above all the possible single-rune values. | ||||||
|  | func (i item) String() string { | ||||||
|  | 	tokType := i.typ | ||||||
|  | 	if tokType >= yyPrivate { | ||||||
|  | 		if tokType < yyPrivate+len(yyTok2) { | ||||||
|  | 			tokType = yyTok2[tokType-yyPrivate] | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	rv := fmt.Sprintf("%s %q %d:%d", yyTokname(tokType), i.val, i.line, i.column) | ||||||
|  | 	return rv | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Lexer stores the state of this lexer. | ||||||
|  | type Lexer struct { | ||||||
|  | 	input    string    // the string we're scanning. | ||||||
|  | 	start    int       // start position of the item. | ||||||
|  | 	pos      int       // current position in the input. | ||||||
|  | 	line     int       // the current line (for error reporting). | ||||||
|  | 	column   int       // current position within the current line. | ||||||
|  | 	width    int       // width of the last rune scanned. | ||||||
|  | 	items    chan item // channel of scanned lexer items (lexemes). | ||||||
|  | 	lastItem item      // The last item the lexer handed the parser | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // NewLexer will return a new lexer for the passed-in reader. | ||||||
|  | func NewLexer(rdr io.Reader) (*Lexer, error) { | ||||||
|  | 	l := &Lexer{} | ||||||
|  |  | ||||||
|  | 	b, err := ioutil.ReadAll(rdr) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  | 	l.input = string(b) | ||||||
|  | 	l.items = make(chan item) | ||||||
|  |  | ||||||
|  | 	return l, nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Run starts the lexer, and should be called in a goroutine. | ||||||
|  | func (l *Lexer) Run() { | ||||||
|  | 	for state := lexText; state != nil; { | ||||||
|  | 		state = state(l) | ||||||
|  | 	} | ||||||
|  | 	close(l.items) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // emit returns a token to the parser. | ||||||
|  | func (l *Lexer) emit(t int) { | ||||||
|  | 	l.items <- item{t, l.input[l.start:l.pos], l.line, l.column} | ||||||
|  | 	l.start = l.pos | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Lex gets the next token. | ||||||
|  | func (l *Lexer) Lex(st *yySymType) int { | ||||||
|  | 	s := <-l.items | ||||||
|  | 	l.lastItem = s | ||||||
|  | 	st.val = s.val | ||||||
|  | 	// fmt.Println("Lex returning", s) | ||||||
|  | 	return int(s.typ) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Error is called by the parser when it finds a problem. | ||||||
|  | func (l *Lexer) Error(s string) { | ||||||
|  | 	fmt.Printf("parse error at %d:%d: %v\n", l.lastItem.line+1, l.lastItem.column+1, s) | ||||||
|  | 	fmt.Printf("error at %q\n", l.lastItem.val) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // errorf is used by the lexer to report errors. It inserts an ERROR token into | ||||||
|  | // the items channel, and sets the state to nil, which stops the lexer's state | ||||||
|  | // machine. | ||||||
|  | func (l *Lexer) errorf(format string, args ...interface{}) stateFn { | ||||||
|  | 	l.items <- item{ERROR, fmt.Sprintf(format, args), l.line, l.column} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // next returns the rune at the current location, and advances to the next rune | ||||||
|  | // in the input. | ||||||
|  | func (l *Lexer) next() (r rune) { | ||||||
|  | 	if l.pos >= len(l.input) { | ||||||
|  | 		l.width = 0 | ||||||
|  | 		return eof | ||||||
|  | 	} | ||||||
|  | 	r, l.width = utf8.DecodeRuneInString(l.input[l.pos:]) | ||||||
|  | 	l.pos += l.width | ||||||
|  | 	l.column++ | ||||||
|  | 	if r == '\n' { | ||||||
|  | 		l.line++ | ||||||
|  | 		l.column = 0 | ||||||
|  | 	} | ||||||
|  | 	return r | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // ignore discards the current text from start to pos. | ||||||
|  | func (l *Lexer) ignore() { | ||||||
|  | 	l.start = l.pos | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // backup moves back one character, but can only be called once per next() call. | ||||||
|  | func (l *Lexer) backup() { | ||||||
|  | 	l.pos -= l.width | ||||||
|  | 	if l.column > 0 { | ||||||
|  | 		l.column-- | ||||||
|  | 	} else { | ||||||
|  | 		l.line-- | ||||||
|  | 	} | ||||||
|  | 	l.width = 0 | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // peek looks ahead at the next rune in the stream without consuming it. | ||||||
|  | func (l *Lexer) peek() rune { | ||||||
|  | 	r := l.next() | ||||||
|  | 	l.backup() | ||||||
|  | 	return r | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // accept will advance to the next rune if it's contained in the string of valid | ||||||
|  | // runes passed in by the caller. | ||||||
|  | func (l *Lexer) accept(valid string) bool { | ||||||
|  | 	if strings.IndexRune(valid, l.next()) >= 0 { | ||||||
|  | 		return true | ||||||
|  | 	} | ||||||
|  | 	l.backup() | ||||||
|  | 	return false | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // acceptRun advances over a number of valid runes, stopping as soon as it hits | ||||||
|  | // one not on the list. | ||||||
|  | func (l *Lexer) acceptRun(valid string) { | ||||||
|  | 	for strings.IndexRune(valid, l.next()) >= 0 { | ||||||
|  | 	} | ||||||
|  | 	l.backup() | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // keyword checks whether the current lexeme is a keyword or not. If so it | ||||||
|  | // returns the keyword's token id, otherwise it returns IDENTIFIER. | ||||||
|  | func (l *Lexer) keyword() int { | ||||||
|  | 	ident := l.input[l.start:l.pos] | ||||||
|  | 	tok, ok := keywords[ident] | ||||||
|  | 	if ok == true { | ||||||
|  | 		return int(tok) | ||||||
|  | 	} | ||||||
|  | 	return IDENTIFIER | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // oneRuneToken determines whether a rune is a token. If so it returns the token | ||||||
|  | // id and true, otherwise it returns false. | ||||||
|  | func (l *Lexer) oneRuneToken(r rune) (int, bool) { | ||||||
|  | 	if strings.IndexRune(oneRuneTokens, r) >= 0 { | ||||||
|  | 		return int(r), true | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return 0, false | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // State functions | ||||||
|  | type stateFn func(*Lexer) stateFn | ||||||
|  |  | ||||||
|  | // lexText is the master lex routine. The lexer is started in this state. | ||||||
|  | func lexText(l *Lexer) stateFn { | ||||||
|  | 	for { | ||||||
|  | 		if strings.HasPrefix(l.input[l.pos:], "/*") { | ||||||
|  | 			return lexBlockComment | ||||||
|  | 		} | ||||||
|  | 		r := l.next() | ||||||
|  | 		if r == eof { | ||||||
|  | 			break | ||||||
|  | 		} | ||||||
|  | 		if unicode.IsSpace(r) { | ||||||
|  | 			l.ignore() | ||||||
|  | 			return lexText | ||||||
|  | 		} | ||||||
|  | 		if l.column == 1 && r == '%' { | ||||||
|  | 			l.backup() | ||||||
|  | 			return lexDirective | ||||||
|  | 		} | ||||||
|  | 		if unicode.IsLetter(r) { | ||||||
|  | 			l.backup() | ||||||
|  | 			return lexIdent | ||||||
|  | 		} | ||||||
|  | 		if unicode.IsNumber(r) || r == '-' { | ||||||
|  | 			l.backup() | ||||||
|  | 			return lexNumber | ||||||
|  | 		} | ||||||
|  | 		if t, isToken := l.oneRuneToken(r); isToken == true { | ||||||
|  | 			l.emit(t) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // lexBlockComment is used when we find a comment marker '/*' in the input. | ||||||
|  | func lexBlockComment(l *Lexer) stateFn { | ||||||
|  | 	for { | ||||||
|  | 		if strings.HasPrefix(l.input[l.pos:], "*/") { | ||||||
|  | 			// Found the end. Advance past the '*/' and discard the comment body. | ||||||
|  | 			l.next() | ||||||
|  | 			l.next() | ||||||
|  | 			l.ignore() | ||||||
|  | 			return lexText | ||||||
|  | 		} | ||||||
|  | 		if l.next() == eof { | ||||||
|  | 			return l.errorf("unterminated block comment") | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // lexIdent handles identifiers. | ||||||
|  | func lexIdent(l *Lexer) stateFn { | ||||||
|  | 	for { | ||||||
|  | 		r := l.next() | ||||||
|  | 		if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' { | ||||||
|  | 			continue | ||||||
|  | 		} | ||||||
|  | 		l.backup() | ||||||
|  | 		break | ||||||
|  | 	} | ||||||
|  | 	// We may have a keyword, so check for that before emitting. | ||||||
|  | 	l.emit(l.keyword()) | ||||||
|  |  | ||||||
|  | 	return lexText | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // lexNumber handles decimal and hexadecimal numbers. Decimal numbers may begin | ||||||
|  | // with a '-'; hex numbers begin with '0x' and do not accept leading '-'. | ||||||
|  | func lexNumber(l *Lexer) stateFn { | ||||||
|  | 	// Leading '-' is ok | ||||||
|  | 	digits := "0123456789" | ||||||
|  | 	neg := l.accept("-") | ||||||
|  | 	if !neg { | ||||||
|  | 		// allow '0x' for hex numbers, as long as there's not a leading '-'. | ||||||
|  | 		r := l.peek() | ||||||
|  | 		if r == '0' { | ||||||
|  | 			l.next() | ||||||
|  | 			if l.accept("x") { | ||||||
|  | 				digits = "0123456789ABCDEFabcdef" | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	// followed by any number of digits | ||||||
|  | 	l.acceptRun(digits) | ||||||
|  | 	r := l.peek() | ||||||
|  | 	if unicode.IsLetter(r) { | ||||||
|  | 		l.next() | ||||||
|  | 		return l.errorf("invalid number: %q", l.input[l.start:l.pos]) | ||||||
|  | 	} | ||||||
|  | 	l.emit(CONSTANT) | ||||||
|  | 	return lexText | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // lexDirective handles lines beginning with '%'. These are used to emit C code | ||||||
|  | // directly to the output file. For now we're ignoring them, but some of the | ||||||
|  | // constants in the protocol file do depend on values from #included header | ||||||
|  | // files, so that may need to change. | ||||||
|  | func lexDirective(l *Lexer) stateFn { | ||||||
|  | 	for { | ||||||
|  | 		r := l.next() | ||||||
|  | 		if r == '\n' { | ||||||
|  | 			l.ignore() | ||||||
|  | 			return lexText | ||||||
|  | 		} | ||||||
|  | 		if r == eof { | ||||||
|  | 			return l.errorf("unterminated directive") | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //--------------------------------------------------------------------------- | ||||||
|  | // Routines called by the parser's actions. | ||||||
|  | //--------------------------------------------------------------------------- | ||||||
|  |  | ||||||
|  | // StartEnum is called when the parser has found a valid enum. | ||||||
|  | func StartEnum() { | ||||||
|  | 	// Set the automatic value var to -1; it will be incremented before being | ||||||
|  | 	// assigned to an enum value. | ||||||
|  | 	CurrentEnumVal = -1 | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // AddEnum will add a new enum value to the list. | ||||||
|  | func AddEnum(name, val string) error { | ||||||
|  | 	ev, err := parseNumber(val) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return fmt.Errorf("invalid enum value %v = %v", name, val) | ||||||
|  | 	} | ||||||
|  | 	return addEnum(name, ev) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // AddEnumAutoVal adds an enum to the list, using the automatically-incremented | ||||||
|  | // value. This is called when the parser finds an enum definition without an | ||||||
|  | // explicit value. | ||||||
|  | func AddEnumAutoVal(name string) error { | ||||||
|  | 	CurrentEnumVal++ | ||||||
|  | 	return addEnum(name, CurrentEnumVal) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func addEnum(name string, val int64) error { | ||||||
|  | 	Gen.Enums = append(Gen.Enums, ConstItem{name, fmt.Sprintf("%d", val)}) | ||||||
|  | 	CurrentEnumVal = val | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // AddConst adds a new constant to the parser's list. | ||||||
|  | func AddConst(name, val string) error { | ||||||
|  | 	_, err := parseNumber(val) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return fmt.Errorf("invalid const value %v = %v", name, val) | ||||||
|  | 	} | ||||||
|  | 	Gen.Consts = append(Gen.Consts, ConstItem{name, val}) | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // parseNumber makes sure that a parsed numerical value can be parsed to a 64- | ||||||
|  | // bit integer. | ||||||
|  | func parseNumber(val string) (int64, error) { | ||||||
|  | 	base := 10 | ||||||
|  | 	if strings.HasPrefix(val, "0x") { | ||||||
|  | 		base = 16 | ||||||
|  | 		val = val[2:] | ||||||
|  | 	} | ||||||
|  | 	n, err := strconv.ParseInt(val, base, 64) | ||||||
|  | 	return n, err | ||||||
|  | } | ||||||
							
								
								
									
										4
									
								
								internal/lvgen/lv-gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								internal/lvgen/lv-gen.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | package lvgen | ||||||
|  |  | ||||||
|  | //go:generate goyacc sunrpc.y | ||||||
|  | //go:generate go run gen/main.go | ||||||
							
								
								
									
										218
									
								
								internal/lvgen/sunrpc.y
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										218
									
								
								internal/lvgen/sunrpc.y
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,218 @@ | |||||||
|  | %{ | ||||||
|  |  | ||||||
|  | package lvgen | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  |     //"fmt" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | %} | ||||||
|  |  | ||||||
|  | // SymType | ||||||
|  | %union{ | ||||||
|  |     val string | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // XDR tokens: | ||||||
|  | %token BOOL CASE CONST DEFAULT DOUBLE ENUM FLOAT OPAQUE STRING STRUCT | ||||||
|  | %token SWITCH TYPEDEF UNION UNSIGNED VOID HYPER INT SHORT CHAR | ||||||
|  | %token IDENTIFIER CONSTANT ERROR | ||||||
|  | // RPCL additional tokens: | ||||||
|  | %token PROGRAM VERSION | ||||||
|  |  | ||||||
|  | %% | ||||||
|  |  | ||||||
|  | specification | ||||||
|  |     : definition_list | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | value | ||||||
|  |     : IDENTIFIER | ||||||
|  |     | CONSTANT | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | definition_list | ||||||
|  |     : definition ';' | ||||||
|  |     | definition ';' definition_list | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | definition | ||||||
|  |     : enum_definition | ||||||
|  |     | const_definition | ||||||
|  |     | typedef_definition | ||||||
|  |     | struct_definition | ||||||
|  |     | union_definition | ||||||
|  |     | program_definition | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | enum_definition | ||||||
|  |     : ENUM enum_ident '{' enum_value_list '}' { StartEnum() } | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | enum_value_list | ||||||
|  |     : enum_value | ||||||
|  |     | enum_value ',' enum_value_list | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | enum_value | ||||||
|  |     : enum_value_ident { | ||||||
|  |         err := AddEnumAutoVal($1.val) | ||||||
|  |         if err != nil { | ||||||
|  |             yylex.Error(err.Error()) | ||||||
|  |             return 1 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     | enum_value_ident '=' value { | ||||||
|  |         err := AddEnum($1.val, $3.val) | ||||||
|  |         if err != nil { | ||||||
|  |             yylex.Error(err.Error()) | ||||||
|  |             return 1 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | enum_ident | ||||||
|  |     : IDENTIFIER | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | enum_value_ident | ||||||
|  |     : IDENTIFIER | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | // Ignore consts that are set to IDENTIFIERs - this isn't allowed by the spec, | ||||||
|  | // but occurs in the file because libvirt runs the pre-processor on the protocol | ||||||
|  | // file, and it handles replacing the identifier with it's #defined value. | ||||||
|  | const_definition | ||||||
|  |     : CONST const_ident '=' IDENTIFIER | ||||||
|  |     | CONST const_ident '=' CONSTANT { | ||||||
|  |         err := AddConst($2.val, $4.val) | ||||||
|  |         if err != nil { | ||||||
|  |             yylex.Error(err.Error()) | ||||||
|  |             return 1 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | const_ident | ||||||
|  |     : IDENTIFIER | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | typedef_definition | ||||||
|  |     : TYPEDEF declaration | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | declaration | ||||||
|  |     : simple_declaration | ||||||
|  |     | fixed_array_declaration | ||||||
|  |     | variable_array_declaration | ||||||
|  |     | pointer_declaration | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | simple_declaration | ||||||
|  |     : type_specifier variable_ident | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | type_specifier | ||||||
|  |     : int_spec | ||||||
|  |     | UNSIGNED int_spec | ||||||
|  |     | FLOAT | ||||||
|  |     | DOUBLE | ||||||
|  |     | BOOL | ||||||
|  |     | STRING | ||||||
|  |     | OPAQUE | ||||||
|  |     | enum_definition | ||||||
|  |     | struct_definition | ||||||
|  |     | union_definition | ||||||
|  |     | IDENTIFIER | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | int_spec | ||||||
|  |     : HYPER | ||||||
|  |     | INT | ||||||
|  |     | SHORT | ||||||
|  |     | CHAR | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | variable_ident | ||||||
|  |     : IDENTIFIER | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | fixed_array_declaration | ||||||
|  |     : type_specifier variable_ident '[' value ']' | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | variable_array_declaration | ||||||
|  |     : type_specifier variable_ident '<' value '>' | ||||||
|  |     | type_specifier variable_ident '<' '>' | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | pointer_declaration | ||||||
|  |     : type_specifier '*' variable_ident | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | struct_definition | ||||||
|  |     : STRUCT struct_ident '{' declaration_list '}' | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | struct_ident | ||||||
|  |     : IDENTIFIER | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | declaration_list | ||||||
|  |     : declaration ';' | ||||||
|  |     | declaration ';' declaration_list | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | union_definition | ||||||
|  |     : UNION union_ident SWITCH '(' simple_declaration ')' '{' case_list '}' | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | union_ident | ||||||
|  |     : IDENTIFIER | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | case_list | ||||||
|  |     : case ';' | ||||||
|  |     | case ';' case_list | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | case | ||||||
|  |     : CASE value ':' declaration | ||||||
|  |     | DEFAULT ':' declaration | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | program_definition | ||||||
|  |     : PROGRAM program_ident '{' version_list '}' '=' value | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | program_ident | ||||||
|  |     : IDENTIFIER | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | version_list | ||||||
|  |     : version ';' | ||||||
|  |     | version ';' version_list | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | version | ||||||
|  |     : VERSION version_ident '{' procedure_list '}' '=' value ';' | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | version_ident | ||||||
|  |     : IDENTIFIER | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | procedure_list | ||||||
|  |     : procedure ';' | ||||||
|  |     | procedure ';' procedure_list | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | procedure | ||||||
|  |     : type_specifier procedure_ident '(' type_specifier ')' '=' value ';' | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | procedure_ident | ||||||
|  |     : IDENTIFIER | ||||||
|  |     ; | ||||||
|  |  | ||||||
|  | %% | ||||||
							
								
								
									
										45
									
								
								libvirt.go
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								libvirt.go
									
									
									
									
									
								
							| @@ -514,7 +514,7 @@ type DomainMemoryStat struct { | |||||||
|  |  | ||||||
| // Capabilities returns an XML document describing the host's capabilties. | // Capabilities returns an XML document describing the host's capabilties. | ||||||
| func (l *Libvirt) Capabilities() ([]byte, error) { | func (l *Libvirt) Capabilities() ([]byte, error) { | ||||||
| 	resp, err := l.request(constants.ProcConnectGetCapabilties, constants.ProgramRemote, nil) | 	resp, err := l.request(constants.ProcConnectGetCapabilities, constants.Program, nil) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @@ -571,7 +571,7 @@ func (l *Libvirt) Domains() ([]Domain, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcConnectListAllDomains, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcConnectListAllDomains, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @@ -613,7 +613,7 @@ func (l *Libvirt) DomainCreateWithFlags(dom string, flags DomainCreateFlags) err | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	resp, err := l.request(constants.ProcDomainCreateWithFlags, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainCreateWithFlags, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -647,7 +647,7 @@ func (l *Libvirt) DomainMemoryStats(dom string) ([]DomainMemoryStat, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainMemoryStats, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainMemoryStats, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @@ -687,7 +687,7 @@ func (l *Libvirt) DomainState(dom string) (DomainState, error) { | |||||||
| 		return DomainStateNoState, err | 		return DomainStateNoState, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainGetState, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainGetState, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return DomainStateNoState, err | 		return DomainStateNoState, err | ||||||
| 	} | 	} | ||||||
| @@ -814,7 +814,8 @@ func (l *Libvirt) Migrate(dom string, dest string, flags MigrateFlags) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcMigratePerformParams, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainMigratePerform3Params, | ||||||
|  | 		constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -852,7 +853,7 @@ func (l *Libvirt) MigrateSetMaxSpeed(dom string, speed int64) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainMigrateSetMaxSpeed, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainMigrateSetMaxSpeed, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -932,7 +933,7 @@ func (l *Libvirt) Secrets() ([]Secret, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcConnectListAllSecrets, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcConnectListAllSecrets, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @@ -970,7 +971,7 @@ func (l *Libvirt) StoragePool(name string) (*StoragePool, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcStoragePoolLookupByName, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcStoragePoolLookupByName, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @@ -1013,7 +1014,7 @@ func (l *Libvirt) StoragePoolRefresh(name string) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcStoragePoolRefresh, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcStoragePoolRefresh, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -1042,7 +1043,7 @@ func (l *Libvirt) StoragePools(flags StoragePoolsFlags) ([]StoragePool, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcConnectListAllStoragePools, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcConnectListAllStoragePools, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @@ -1089,7 +1090,7 @@ func (l *Libvirt) Undefine(dom string, flags UndefineFlags) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainUndefineFlags, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainUndefineFlags, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -1125,7 +1126,7 @@ func (l *Libvirt) Destroy(dom string, flags DestroyFlags) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainDestroyFlags, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainDestroyFlags, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -1159,7 +1160,7 @@ func (l *Libvirt) XML(dom string, flags DomainXMLFlags) ([]byte, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainGetXMLDesc, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainGetXMLDesc, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @@ -1194,7 +1195,7 @@ func (l *Libvirt) DefineXML(x []byte, flags DomainDefineXMLFlags) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainDefineXMLFlags, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainDefineXMLFlags, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -1209,7 +1210,7 @@ func (l *Libvirt) DefineXML(x []byte, flags DomainDefineXMLFlags) error { | |||||||
|  |  | ||||||
| // Version returns the version of the libvirt daemon. | // Version returns the version of the libvirt daemon. | ||||||
| func (l *Libvirt) Version() (string, error) { | func (l *Libvirt) Version() (string, error) { | ||||||
| 	resp, err := l.request(constants.ProcConnectGetLibVersion, constants.ProgramRemote, nil) | 	resp, err := l.request(constants.ProcConnectGetLibVersion, constants.Program, nil) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return "", err | 		return "", err | ||||||
| 	} | 	} | ||||||
| @@ -1263,7 +1264,7 @@ func (l *Libvirt) Shutdown(dom string, flags ShutdownFlags) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainShutdownFlags, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainShutdownFlags, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -1297,7 +1298,7 @@ func (l *Libvirt) Reboot(dom string, flags RebootFlags) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainReboot, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainReboot, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -1330,7 +1331,7 @@ func (l *Libvirt) Reset(dom string) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainReset, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainReset, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -1418,7 +1419,7 @@ func (l *Libvirt) SetBlockIOTune(dom string, disk string, limits ...BlockLimit) | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	resp, err := l.request(constants.ProcDomainSetBlockIOTune, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainSetBlockIOTune, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -1456,7 +1457,7 @@ func (l *Libvirt) GetBlockIOTune(dom string, disk string) ([]BlockLimit, error) | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainGetBlockIOTune, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainGetBlockIOTune, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @@ -1525,7 +1526,7 @@ func (l *Libvirt) lookup(name string) (*Domain, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err := l.request(constants.ProcDomainLookupByName, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcDomainLookupByName, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -563,7 +563,7 @@ func (m *MockLibvirt) handle(conn net.Conn) { | |||||||
| 		proc := binary.BigEndian.Uint32(buf[12:16]) | 		proc := binary.BigEndian.Uint32(buf[12:16]) | ||||||
|  |  | ||||||
| 		switch prog { | 		switch prog { | ||||||
| 		case constants.ProgramRemote: | 		case constants.Program: | ||||||
| 			m.handleRemote(proc, conn) | 			m.handleRemote(proc, conn) | ||||||
| 		case constants.ProgramQEMU: | 		case constants.ProgramQEMU: | ||||||
| 			m.handleQEMU(proc, conn) | 			m.handleQEMU(proc, conn) | ||||||
| @@ -599,7 +599,7 @@ func (m *MockLibvirt) handleRemote(procedure uint32, conn net.Conn) { | |||||||
| 		conn.Write(m.reply(testDomainMemoryStatsReply)) | 		conn.Write(m.reply(testDomainMemoryStatsReply)) | ||||||
| 	case constants.ProcDomainMigrateSetMaxSpeed: | 	case constants.ProcDomainMigrateSetMaxSpeed: | ||||||
| 		conn.Write(m.reply(testSetSpeedReply)) | 		conn.Write(m.reply(testSetSpeedReply)) | ||||||
| 	case constants.ProcMigratePerformParams: | 	case constants.ProcDomainMigratePerform3Params: | ||||||
| 		conn.Write(m.reply(testMigrateReply)) | 		conn.Write(m.reply(testMigrateReply)) | ||||||
| 	case constants.ProcDomainUndefineFlags: | 	case constants.ProcDomainUndefineFlags: | ||||||
| 		conn.Write(m.reply(testUndefineReply)) | 		conn.Write(m.reply(testUndefineReply)) | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								rpc.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								rpc.go
									
									
									
									
									
								
							| @@ -131,7 +131,7 @@ func (l *Libvirt) connect() error { | |||||||
|  |  | ||||||
| 	// libvirt requires that we call auth-list prior to connecting, | 	// libvirt requires that we call auth-list prior to connecting, | ||||||
| 	// event when no authentication is used. | 	// event when no authentication is used. | ||||||
| 	resp, err := l.request(constants.ProcAuthList, constants.ProgramRemote, &buf) | 	resp, err := l.request(constants.ProcAuthList, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -141,7 +141,7 @@ func (l *Libvirt) connect() error { | |||||||
| 		return decodeError(r.Payload) | 		return decodeError(r.Payload) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	resp, err = l.request(constants.ProcConnectOpen, constants.ProgramRemote, &buf) | 	resp, err = l.request(constants.ProcConnectOpen, constants.Program, &buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -155,7 +155,7 @@ func (l *Libvirt) connect() error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func (l *Libvirt) disconnect() error { | func (l *Libvirt) disconnect() error { | ||||||
| 	resp, err := l.request(constants.ProcConnectClose, constants.ProgramRemote, nil) | 	resp, err := l.request(constants.ProcConnectClose, constants.Program, nil) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -329,7 +329,7 @@ func (l *Libvirt) request(proc uint32, program uint32, payload *bytes.Buffer) (< | |||||||
| 		Len: uint32(size), | 		Len: uint32(size), | ||||||
| 		Header: header{ | 		Header: header{ | ||||||
| 			Program:   program, | 			Program:   program, | ||||||
| 			Version:   constants.ProgramVersion, | 			Version:   constants.ProtocolVersion, | ||||||
| 			Procedure: proc, | 			Procedure: proc, | ||||||
| 			Type:      Call, | 			Type:      Call, | ||||||
| 			Serial:    serial, | 			Serial:    serial, | ||||||
|   | |||||||
| @@ -120,12 +120,12 @@ func TestExtractHeader(t *testing.T) { | |||||||
| 		t.Error(err) | 		t.Error(err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if h.Program != constants.ProgramRemote { | 	if h.Program != constants.Program { | ||||||
| 		t.Errorf("expected Program %q, got %q", constants.ProgramRemote, h.Program) | 		t.Errorf("expected Program %q, got %q", constants.Program, h.Program) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if h.Version != constants.ProgramVersion { | 	if h.Version != constants.ProtocolVersion { | ||||||
| 		t.Errorf("expected version %q, got %q", constants.ProgramVersion, h.Version) | 		t.Errorf("expected version %q, got %q", constants.ProtocolVersion, h.Version) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if h.Procedure != constants.ProcConnectOpen { | 	if h.Procedure != constants.ProcConnectOpen { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user