manageiq-smartstate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (305) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +4 -0
  4. data/.rspec_ci +4 -0
  5. data/.travis.yml +15 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE.txt +202 -0
  8. data/README.md +45 -0
  9. data/Rakefile +23 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/MiqContainerGroup/MiqContainerGroup.rb +31 -0
  13. data/lib/MiqVm/MiqLocalVm.rb +50 -0
  14. data/lib/MiqVm/MiqRhevmVm.rb +179 -0
  15. data/lib/MiqVm/MiqVm.rb +355 -0
  16. data/lib/MiqVm/miq_azure_vm.rb +96 -0
  17. data/lib/MiqVm/miq_scvmm_vm.rb +38 -0
  18. data/lib/MiqVm/test/camcorder_fleece_test.rb +60 -0
  19. data/lib/MiqVm/test/localVm.rb +45 -0
  20. data/lib/MiqVm/test/partitionAlignmentCheck.rb +76 -0
  21. data/lib/MiqVm/test/remoteVm.rb +65 -0
  22. data/lib/MiqVm/test/rhevmNfsTest.rb +62 -0
  23. data/lib/MiqVm/test/rhevmNfsTest2.rb +66 -0
  24. data/lib/MiqVm/test/rhevmTest.rb +70 -0
  25. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackCommon.rb +107 -0
  26. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackImage.rb +67 -0
  27. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackInstance.rb +182 -0
  28. data/lib/Scvmm/miq_hyperv_disk.rb +273 -0
  29. data/lib/Scvmm/miq_scvmm_parse_powershell.rb +75 -0
  30. data/lib/Scvmm/miq_scvmm_vm_ssa_info.rb +135 -0
  31. data/lib/Scvmm/test/miq_hyperv_disk_test.rb +33 -0
  32. data/lib/Scvmm/test/miq_scvmm_vm_ssa_info_test.rb +41 -0
  33. data/lib/VmLocalDiskAccess/test/localCfg.rb +97 -0
  34. data/lib/VolumeManager/LVM/logical_volume.rb +75 -0
  35. data/lib/VolumeManager/LVM/lv_segment.rb +43 -0
  36. data/lib/VolumeManager/LVM/lvm2disk.rb +158 -0
  37. data/lib/VolumeManager/LVM/parser.rb +138 -0
  38. data/lib/VolumeManager/LVM/physical_volume.rb +19 -0
  39. data/lib/VolumeManager/LVM/scanner.rb +156 -0
  40. data/lib/VolumeManager/LVM/thin/btree.rb +83 -0
  41. data/lib/VolumeManager/LVM/thin/constants.rb +86 -0
  42. data/lib/VolumeManager/LVM/thin/data_map.rb +44 -0
  43. data/lib/VolumeManager/LVM/thin/mapping_tree.rb +19 -0
  44. data/lib/VolumeManager/LVM/thin/space_maps.rb +58 -0
  45. data/lib/VolumeManager/LVM/thin/superblock.rb +136 -0
  46. data/lib/VolumeManager/LVM/thin.rb +6 -0
  47. data/lib/VolumeManager/LVM/volume_group.rb +97 -0
  48. data/lib/VolumeManager/LVM.rb +8 -0
  49. data/lib/VolumeManager/MiqLdm.rb +546 -0
  50. data/lib/VolumeManager/MiqLvm.rb +17 -0
  51. data/lib/VolumeManager/MiqNativeVolumeManager.rb +150 -0
  52. data/lib/VolumeManager/MiqVolumeManager.rb +277 -0
  53. data/lib/VolumeManager/VolMgrPlatformSupport.rb +18 -0
  54. data/lib/VolumeManager/VolMgrPlatformSupportLinux.rb +77 -0
  55. data/lib/VolumeManager/VolMgrPlatformSupportWin.rb +17 -0
  56. data/lib/VolumeManager/test/blockDevTest.rb +40 -0
  57. data/lib/VolumeManager/test/ldm.rb +97 -0
  58. data/lib/blackbox/VmBlackBox.rb +103 -0
  59. data/lib/blackbox/xmlStorage.rb +180 -0
  60. data/lib/db/MiqBdb/MiqBdb.rb +309 -0
  61. data/lib/db/MiqBdb/MiqBdbBtree.rb +219 -0
  62. data/lib/db/MiqBdb/MiqBdbHash.rb +199 -0
  63. data/lib/db/MiqBdb/MiqBdbPage.rb +159 -0
  64. data/lib/db/MiqBdb/MiqBdbUtil.rb +18 -0
  65. data/lib/db/MiqSqlite/MiqSqlite3.rb +330 -0
  66. data/lib/db/MiqSqlite/MiqSqlite3Cell.rb +167 -0
  67. data/lib/db/MiqSqlite/MiqSqlite3Page.rb +151 -0
  68. data/lib/db/MiqSqlite/MiqSqlite3Table.rb +124 -0
  69. data/lib/db/MiqSqlite/MiqSqlite3Util.rb +32 -0
  70. data/lib/disk/DiskProbe.rb +68 -0
  71. data/lib/disk/MiqDisk.rb +317 -0
  72. data/lib/disk/camcorder_test.rb +90 -0
  73. data/lib/disk/dos_mbr.img +0 -0
  74. data/lib/disk/modules/AzureBlobDisk.rb +101 -0
  75. data/lib/disk/modules/LocalDevMod.rb +47 -0
  76. data/lib/disk/modules/LocalDevProbe.rb +6 -0
  77. data/lib/disk/modules/MSCommon.rb +352 -0
  78. data/lib/disk/modules/MSVSDiffDisk.rb +91 -0
  79. data/lib/disk/modules/MSVSDiskProbe.rb +61 -0
  80. data/lib/disk/modules/MSVSDynamicDisk.rb +42 -0
  81. data/lib/disk/modules/MSVSFixedDisk.rb +45 -0
  82. data/lib/disk/modules/MiqLargeFile.rb +63 -0
  83. data/lib/disk/modules/MiqLargeFileWin32.rb +107 -0
  84. data/lib/disk/modules/QcowDisk.rb +692 -0
  85. data/lib/disk/modules/QcowDiskProbe.rb +34 -0
  86. data/lib/disk/modules/RawBlockIO.rb +116 -0
  87. data/lib/disk/modules/RawDisk.rb +45 -0
  88. data/lib/disk/modules/RawDiskProbe.rb +7 -0
  89. data/lib/disk/modules/RhevmDescriptor.rb +167 -0
  90. data/lib/disk/modules/RhevmDiskProbe.rb +52 -0
  91. data/lib/disk/modules/VMWareCowdDisk.rb +207 -0
  92. data/lib/disk/modules/VMWareDescriptor.rb +214 -0
  93. data/lib/disk/modules/VMWareDiskProbe.rb +74 -0
  94. data/lib/disk/modules/VMWareSparseDisk.rb +189 -0
  95. data/lib/disk/modules/VhdxDisk.rb +625 -0
  96. data/lib/disk/modules/VhdxDiskProbe.rb +46 -0
  97. data/lib/disk/modules/VixDiskMod.rb +54 -0
  98. data/lib/disk/modules/VixDiskProbe.rb +6 -0
  99. data/lib/disk/modules/miq_disk_cache.rb +135 -0
  100. data/lib/disk/modules/miq_dummy_disk.rb +41 -0
  101. data/lib/disk/modules/vhdx_bat_entry.rb +10 -0
  102. data/lib/disk/test.rb +66 -0
  103. data/lib/fs/MetakitFS/MetakitFS.rb +530 -0
  104. data/lib/fs/MetakitFS/test/Makefile +14 -0
  105. data/lib/fs/MetakitFS/test/MkCollectFiles.rb +165 -0
  106. data/lib/fs/MetakitFS/test/MkSelectFiles.rb +30 -0
  107. data/lib/fs/MetakitFS/test/collect_files.yaml +70 -0
  108. data/lib/fs/MetakitFS/test/init.rb +3 -0
  109. data/lib/fs/MetakitFS/test/mk2vmdk.rb +64 -0
  110. data/lib/fs/MetakitFS/test/mk4test.c +92 -0
  111. data/lib/fs/MetakitFS/test/mkFsTest.rb +113 -0
  112. data/lib/fs/MetakitFS/test/proto.rb +97 -0
  113. data/lib/fs/MiqFS/FsProbe.rb +39 -0
  114. data/lib/fs/MiqFS/MiqFS.rb +515 -0
  115. data/lib/fs/MiqFS/modules/AUFSProbe.rb +26 -0
  116. data/lib/fs/MiqFS/modules/Ext3.rb +305 -0
  117. data/lib/fs/MiqFS/modules/Ext3Probe.rb +25 -0
  118. data/lib/fs/MiqFS/modules/Ext4.rb +304 -0
  119. data/lib/fs/MiqFS/modules/Ext4Probe.rb +25 -0
  120. data/lib/fs/MiqFS/modules/Fat32.rb +318 -0
  121. data/lib/fs/MiqFS/modules/Fat32Probe.rb +30 -0
  122. data/lib/fs/MiqFS/modules/HFSProbe.rb +18 -0
  123. data/lib/fs/MiqFS/modules/Iso9660.rb +293 -0
  124. data/lib/fs/MiqFS/modules/Iso9660Probe.rb +18 -0
  125. data/lib/fs/MiqFS/modules/LocalFS.rb +105 -0
  126. data/lib/fs/MiqFS/modules/NTFS.rb +287 -0
  127. data/lib/fs/MiqFS/modules/NTFSProbe.rb +21 -0
  128. data/lib/fs/MiqFS/modules/NativeFS.rb +155 -0
  129. data/lib/fs/MiqFS/modules/ReFSProbe.rb +17 -0
  130. data/lib/fs/MiqFS/modules/RealFS.rb +79 -0
  131. data/lib/fs/MiqFS/modules/RealFSProbe.rb +6 -0
  132. data/lib/fs/MiqFS/modules/Reiser4Probe.rb +18 -0
  133. data/lib/fs/MiqFS/modules/ReiserFS.rb +315 -0
  134. data/lib/fs/MiqFS/modules/ReiserFSProbe.rb +42 -0
  135. data/lib/fs/MiqFS/modules/UnionFSProbe.rb +18 -0
  136. data/lib/fs/MiqFS/modules/WebDAV.rb +127 -0
  137. data/lib/fs/MiqFS/modules/WebDAVFile.rb +68 -0
  138. data/lib/fs/MiqFS/modules/XFS.rb +300 -0
  139. data/lib/fs/MiqFS/modules/XFSProbe.rb +26 -0
  140. data/lib/fs/MiqFS/modules/ZFSProbe.rb +18 -0
  141. data/lib/fs/MiqFS/test.rb +59 -0
  142. data/lib/fs/MiqFsUtil.rb +383 -0
  143. data/lib/fs/MiqMountManager.rb +209 -0
  144. data/lib/fs/MiqNativeMountManager.rb +101 -0
  145. data/lib/fs/MountManagerProbe.rb +29 -0
  146. data/lib/fs/ReiserFS/block.rb +209 -0
  147. data/lib/fs/ReiserFS/directory.rb +136 -0
  148. data/lib/fs/ReiserFS/directory_entry.rb +140 -0
  149. data/lib/fs/ReiserFS/file_data.rb +111 -0
  150. data/lib/fs/ReiserFS/superblock.rb +140 -0
  151. data/lib/fs/ReiserFS/utils.rb +95 -0
  152. data/lib/fs/VimDatastoreFS/VimDatastoreFS.rb +192 -0
  153. data/lib/fs/ext3/alloc_bitmap.rb +38 -0
  154. data/lib/fs/ext3/block_pointers_path.rb +130 -0
  155. data/lib/fs/ext3/directory.rb +51 -0
  156. data/lib/fs/ext3/directory_entry.rb +67 -0
  157. data/lib/fs/ext3/ex_attrib_header.rb +14 -0
  158. data/lib/fs/ext3/ex_attrib_name.rb +23 -0
  159. data/lib/fs/ext3/file_data.rb +130 -0
  160. data/lib/fs/ext3/group_descriptor_entry.rb +65 -0
  161. data/lib/fs/ext3/group_descriptor_table.rb +54 -0
  162. data/lib/fs/ext3/hash_tree_entry.rb +18 -0
  163. data/lib/fs/ext3/hash_tree_header.rb +15 -0
  164. data/lib/fs/ext3/inode.rb +228 -0
  165. data/lib/fs/ext3/posix_acl_entry.rb +29 -0
  166. data/lib/fs/ext3/posix_acl_header.rb +11 -0
  167. data/lib/fs/ext3/superblock.rb +406 -0
  168. data/lib/fs/ext3/test/tc_Ext3BlockPointersPath.rb +74 -0
  169. data/lib/fs/ext4/alloc_bitmap.rb +38 -0
  170. data/lib/fs/ext4/directory.rb +87 -0
  171. data/lib/fs/ext4/directory_entry.rb +77 -0
  172. data/lib/fs/ext4/ex_attrib_header.rb +14 -0
  173. data/lib/fs/ext4/ex_attrib_name.rb +23 -0
  174. data/lib/fs/ext4/extent.rb +35 -0
  175. data/lib/fs/ext4/extent_header.rb +40 -0
  176. data/lib/fs/ext4/extent_index.rb +33 -0
  177. data/lib/fs/ext4/group_descriptor_entry.rb +69 -0
  178. data/lib/fs/ext4/group_descriptor_table.rb +54 -0
  179. data/lib/fs/ext4/hash_tree_entry.rb +58 -0
  180. data/lib/fs/ext4/hash_tree_header.rb +35 -0
  181. data/lib/fs/ext4/inode.rb +465 -0
  182. data/lib/fs/ext4/posix_acl_entry.rb +29 -0
  183. data/lib/fs/ext4/posix_acl_header.rb +11 -0
  184. data/lib/fs/ext4/superblock.rb +412 -0
  185. data/lib/fs/fat32/boot_sect.rb +379 -0
  186. data/lib/fs/fat32/directory.rb +222 -0
  187. data/lib/fs/fat32/directory_entry.rb +540 -0
  188. data/lib/fs/fat32/file_data.rb +128 -0
  189. data/lib/fs/iso9660/boot_sector.rb +170 -0
  190. data/lib/fs/iso9660/directory.rb +90 -0
  191. data/lib/fs/iso9660/directory_entry.rb +147 -0
  192. data/lib/fs/iso9660/file_data.rb +78 -0
  193. data/lib/fs/iso9660/rock_ridge.rb +329 -0
  194. data/lib/fs/iso9660/util.rb +57 -0
  195. data/lib/fs/modules/LinuxMount.rb +300 -0
  196. data/lib/fs/modules/LinuxMountProbe.rb +29 -0
  197. data/lib/fs/modules/WinMount.rb +97 -0
  198. data/lib/fs/modules/WinMountProbe.rb +24 -0
  199. data/lib/fs/ntfs/attrib_attribute_list.rb +131 -0
  200. data/lib/fs/ntfs/attrib_bitmap.rb +26 -0
  201. data/lib/fs/ntfs/attrib_data.rb +74 -0
  202. data/lib/fs/ntfs/attrib_file_name.rb +110 -0
  203. data/lib/fs/ntfs/attrib_header.rb +194 -0
  204. data/lib/fs/ntfs/attrib_index_allocation.rb +19 -0
  205. data/lib/fs/ntfs/attrib_index_root.rb +247 -0
  206. data/lib/fs/ntfs/attrib_object_id.rb +40 -0
  207. data/lib/fs/ntfs/attrib_standard_information.rb +107 -0
  208. data/lib/fs/ntfs/attrib_type.rb +49 -0
  209. data/lib/fs/ntfs/attrib_volume_information.rb +53 -0
  210. data/lib/fs/ntfs/attrib_volume_name.rb +31 -0
  211. data/lib/fs/ntfs/boot_sect.rb +253 -0
  212. data/lib/fs/ntfs/data_run.rb +358 -0
  213. data/lib/fs/ntfs/directory_index_node.rb +114 -0
  214. data/lib/fs/ntfs/index_node_header.rb +69 -0
  215. data/lib/fs/ntfs/index_record_header.rb +85 -0
  216. data/lib/fs/ntfs/mft_entry.rb +288 -0
  217. data/lib/fs/ntfs/utils.rb +43 -0
  218. data/lib/fs/test/camcorder_fs_test.rb +108 -0
  219. data/lib/fs/test/collect_files_direct.yaml +22 -0
  220. data/lib/fs/test/collect_files_in.yaml +24 -0
  221. data/lib/fs/test/collect_files_in_nc.yaml +22 -0
  222. data/lib/fs/test/collect_files_out.yaml +6 -0
  223. data/lib/fs/test/collect_files_rm.yaml +6 -0
  224. data/lib/fs/test/copyTest.rb +126 -0
  225. data/lib/fs/test/fsTest.rb +87 -0
  226. data/lib/fs/test/updateTest.rb +184 -0
  227. data/lib/fs/xfs/allocation_group.rb +160 -0
  228. data/lib/fs/xfs/bmap_btree_block.rb +125 -0
  229. data/lib/fs/xfs/bmap_btree_record.rb +80 -0
  230. data/lib/fs/xfs/bmap_btree_root_node.rb +72 -0
  231. data/lib/fs/xfs/directory.rb +133 -0
  232. data/lib/fs/xfs/directory2_data_header.rb +27 -0
  233. data/lib/fs/xfs/directory3_data_header.rb +34 -0
  234. data/lib/fs/xfs/directory_block_tail.rb +22 -0
  235. data/lib/fs/xfs/directory_data_header.rb +46 -0
  236. data/lib/fs/xfs/directory_entry.rb +106 -0
  237. data/lib/fs/xfs/inode.rb +532 -0
  238. data/lib/fs/xfs/inode_map.rb +100 -0
  239. data/lib/fs/xfs/short_form_directory_entry.rb +91 -0
  240. data/lib/fs/xfs/short_form_header.rb +44 -0
  241. data/lib/fs/xfs/superblock.rb +556 -0
  242. data/lib/lib/tasks/azure.rake +52 -0
  243. data/lib/manageiq/smartstate/version.rb +5 -0
  244. data/lib/manageiq/smartstate.rb +7 -0
  245. data/lib/manageiq-smartstate.rb +1 -0
  246. data/lib/metadata/MIQExtract/MIQExtract.rb +297 -0
  247. data/lib/metadata/MIQExtract/test/extractTest.rb +41 -0
  248. data/lib/metadata/MIQExtract/test/full_extract_test.rb +68 -0
  249. data/lib/metadata/ScanProfile/HostScanItem.rb +4 -0
  250. data/lib/metadata/ScanProfile/HostScanProfile.rb +4 -0
  251. data/lib/metadata/ScanProfile/HostScanProfiles.rb +41 -0
  252. data/lib/metadata/ScanProfile/ScanItemBase.rb +63 -0
  253. data/lib/metadata/ScanProfile/ScanProfileBase.rb +51 -0
  254. data/lib/metadata/ScanProfile/ScanProfilesBase.rb +60 -0
  255. data/lib/metadata/ScanProfile/VmScanItem.rb +4 -0
  256. data/lib/metadata/ScanProfile/VmScanProfile.rb +4 -0
  257. data/lib/metadata/ScanProfile/VmScanProfiles.rb +38 -0
  258. data/lib/metadata/ScanProfile/modules/HostScanItemFile.rb +51 -0
  259. data/lib/metadata/ScanProfile/modules/HostScanItemNteventlog.rb +84 -0
  260. data/lib/metadata/ScanProfile/modules/VmScanItemFile.rb +39 -0
  261. data/lib/metadata/ScanProfile/modules/VmScanItemNteventlog.rb +34 -0
  262. data/lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb +64 -0
  263. data/lib/metadata/VMMount/VMMount.rb +81 -0
  264. data/lib/metadata/VMMount/VMPlatformMount.rb +18 -0
  265. data/lib/metadata/VMMount/VMPlatformMountLinux.rb +75 -0
  266. data/lib/metadata/VMMount/VMPlatformMountWin.rb +13 -0
  267. data/lib/metadata/VmConfig/GetNativeCfg.rb +45 -0
  268. data/lib/metadata/VmConfig/VmConfig.rb +947 -0
  269. data/lib/metadata/VmConfig/cfgConfig.rb +45 -0
  270. data/lib/metadata/VmConfig/ovfConfig.rb +99 -0
  271. data/lib/metadata/VmConfig/test/GetVMwareCfgTest.rb +40 -0
  272. data/lib/metadata/VmConfig/vmcConfig.rb +116 -0
  273. data/lib/metadata/VmConfig/vmtxConfig.rb +4 -0
  274. data/lib/metadata/VmConfig/vmxConfig.rb +162 -0
  275. data/lib/metadata/VmConfig/xmlConfig.rb +79 -0
  276. data/lib/metadata/VmConfig/xmlMsHyperVConfig.rb +41 -0
  277. data/lib/metadata/linux/InitProcHash.rb +632 -0
  278. data/lib/metadata/linux/LinuxInitProcs.rb +142 -0
  279. data/lib/metadata/linux/LinuxOSInfo.rb +237 -0
  280. data/lib/metadata/linux/LinuxPackages.rb +209 -0
  281. data/lib/metadata/linux/LinuxSystemd.rb +130 -0
  282. data/lib/metadata/linux/LinuxUsers.rb +289 -0
  283. data/lib/metadata/linux/LinuxUtils.rb +197 -0
  284. data/lib/metadata/linux/MiqConaryPackages.rb +41 -0
  285. data/lib/metadata/linux/MiqRpmPackages.rb +160 -0
  286. data/lib/metadata/linux/test/Name +0 -0
  287. data/lib/metadata/linux/test/Packages +0 -0
  288. data/lib/metadata/linux/test/rpoTest.rb +5 -0
  289. data/lib/metadata/linux/test/tc_LinuxUtils.rb +4157 -0
  290. data/lib/metadata/util/event_log_filter.rb +61 -0
  291. data/lib/metadata/util/md5deep.rb +280 -0
  292. data/lib/metadata/util/win32/Win32Accounts.rb +764 -0
  293. data/lib/metadata/util/win32/Win32EventLog.rb +743 -0
  294. data/lib/metadata/util/win32/Win32Services.rb +86 -0
  295. data/lib/metadata/util/win32/Win32Software.rb +326 -0
  296. data/lib/metadata/util/win32/Win32System.rb +333 -0
  297. data/lib/metadata/util/win32/boot_info_win.rb +59 -0
  298. data/lib/metadata/util/win32/fleece_hives.rb +220 -0
  299. data/lib/metadata/util/win32/ms-registry.rb +650 -0
  300. data/lib/metadata/util/win32/peheader.rb +868 -0
  301. data/lib/metadata/util/win32/remote-registry.rb +142 -0
  302. data/lib/metadata/util/win32/system_path_win.rb +103 -0
  303. data/lib/metadata/util/win32/versioninfo.rb +17 -0
  304. data/manageiq-smartstate.gemspec +35 -0
  305. metadata +486 -0
@@ -0,0 +1,86 @@
1
+ module Lvm2Thin
2
+ SECTOR_SIZE = 512
3
+
4
+ THIN_MAGIC = 27022010
5
+
6
+ SPACE_MAP_ROOT_SIZE = 128
7
+
8
+ MAX_METADATA_BITMAPS = 255
9
+
10
+ SUPERBLOCK = BinaryStruct.new([
11
+ 'L', 'csum',
12
+ 'L', 'flags_',
13
+ 'Q', 'block',
14
+ 'A16', 'uuid',
15
+ 'Q', 'magic',
16
+ 'L', 'version',
17
+ 'L', 'time',
18
+
19
+ 'Q', 'trans_id',
20
+ 'Q', 'metadata_snap',
21
+
22
+ "A#{SPACE_MAP_ROOT_SIZE}", 'data_space_map_root',
23
+ "A#{SPACE_MAP_ROOT_SIZE}", 'metadata_space_map_root',
24
+
25
+ 'Q', 'data_mapping_root',
26
+
27
+ 'Q', 'device_details_root',
28
+
29
+ 'L', 'data_block_size', # in 512-byte sectors
30
+
31
+ 'L', 'metadata_block_size', # in 512-byte sectors
32
+ 'Q', 'metadata_nr_blocks',
33
+
34
+ 'L', 'compat_flags',
35
+ 'L', 'compat_ro_flags',
36
+ 'L', 'incompat_flags'
37
+ ])
38
+
39
+ SPACE_MAP = BinaryStruct.new([
40
+ 'Q', 'nr_blocks',
41
+ 'Q', 'nr_allocated',
42
+ 'Q', 'bitmap_root',
43
+ 'Q', 'ref_count_root'
44
+ ])
45
+
46
+ DISK_NODE = BinaryStruct.new([
47
+ 'L', 'csum',
48
+ 'L', 'flags',
49
+ 'Q', 'blocknr',
50
+
51
+ 'L', 'nr_entries',
52
+ 'L', 'max_entries',
53
+ 'L', 'value_size',
54
+ 'L', 'padding'
55
+ #'Q', 'keys'
56
+ ])
57
+
58
+ INDEX_ENTRY = BinaryStruct.new([
59
+ 'Q', 'blocknr',
60
+ 'L', 'nr_free',
61
+ 'L', 'none_free_before'
62
+ ])
63
+
64
+ METADATA_INDEX = BinaryStruct.new([
65
+ 'L', 'csum',
66
+ 'L', 'padding',
67
+ 'Q', 'blocknr'
68
+ ])
69
+
70
+ BITMAP_HEADER = BinaryStruct.new([
71
+ 'L', 'csum',
72
+ 'L', 'notused',
73
+ 'Q', 'blocknr'
74
+ ])
75
+
76
+ DEVICE_DETAILS = BinaryStruct.new([
77
+ 'Q', 'mapped_blocks',
78
+ 'Q', 'transaction_id',
79
+ 'L', 'creation_time',
80
+ 'L', 'snapshotted_time'
81
+ ])
82
+
83
+ MAPPING_DETAILS = BinaryStruct.new([
84
+ 'Q', 'value'
85
+ ])
86
+ end # module Lvm2Thin
@@ -0,0 +1,44 @@
1
+ module Lvm2Thin
2
+ class DataMap < BTree
3
+ TIME_MASK = (1 << 24) - 1
4
+
5
+ def initialize(superblock, root_address)
6
+ super superblock, root_address, MAPPING_DETAILS
7
+ end
8
+
9
+ alias :device_blocks :keys
10
+
11
+ def entries
12
+ @dmentries ||= begin
13
+ super.collect do |entry|
14
+ value = entry['value']
15
+ internal? ? DataMap.new(@superblock, @superblock.md_block_address(value)) :
16
+ [extract_data_block(value), extract_time(value)]
17
+ end
18
+ end
19
+ end
20
+
21
+ def data_block(device_block)
22
+ device_blocks.reverse.each do |map_device_block|
23
+ if map_device_block <= device_block
24
+ entry = entry_for(map_device_block)
25
+ return entry.data_block(device_block) if entry.is_a?(DataMap)
26
+ raise RuntimeError, "LVM2Thin cannot find device block: #{device_block} (closest: #{map_device_block})" unless map_device_block == device_block
27
+ return entry.first
28
+ end
29
+ end
30
+
31
+ raise RuntimeError, "LVM2Thin could not find data block for #{device_block}"
32
+ end
33
+
34
+ private
35
+
36
+ def extract_data_block(value)
37
+ value >> 24
38
+ end
39
+
40
+ def extract_time(value)
41
+ value & TIME_MASK
42
+ end
43
+ end
44
+ end # module Lvm2Thin
@@ -0,0 +1,19 @@
1
+ module Lvm2Thin
2
+ class MappingTree < BTree
3
+ def initialize(superblock, root_address)
4
+ super superblock, root_address, MAPPING_DETAILS
5
+ end
6
+
7
+ def entries
8
+ @mtentries ||= begin
9
+ super.collect do |entry|
10
+ DataMap.new @superblock, @superblock.md_block_address(entry['value'])
11
+ end
12
+ end
13
+ end
14
+
15
+ def map_for(device_id)
16
+ entry_for(device_id)
17
+ end
18
+ end
19
+ end # module Lvm2Thin
@@ -0,0 +1,58 @@
1
+ module Lvm2Thin
2
+ class DataSpaceMap
3
+ attr_accessor :struct
4
+
5
+ def initialize(superblock, struct)
6
+ @superblock = superblock
7
+ @struct = struct
8
+ end
9
+
10
+ def btree_root_address
11
+ @btree_root_address ||= @superblock.md_block_address(struct['bitmap_root'])
12
+ end
13
+
14
+ def btree
15
+ @btree ||= BTree.new @superblock, btree_root_address, INDEX_ENTRY
16
+ end
17
+ end
18
+
19
+ class MetadataSpaceMap
20
+ def metadata_root_address
21
+ @metadata_root_address ||= @superblock.md_block_address(struct['bitmap_root'])
22
+ end
23
+
24
+ def root
25
+ @metadata_root ||= begin
26
+ @superblock.seek metadata_root_address
27
+ @superblock.read_struct METADATA_INDEX
28
+ end
29
+ end
30
+
31
+ def indices
32
+ @metadata_indices ||= (struct['nr_blocks'].to_f / @superblock.entries_per_block).ceil
33
+ end
34
+
35
+ def index_entries
36
+ @index_entries ||=
37
+ 0.upto(indices-1).collect do |i|
38
+ address = metadata_root_address + METADATA_INDEX.size + i * INDEX_ENTRY.size
39
+ @superblock.seek address
40
+ @superblock.read_struct INDEX_ENTRY
41
+ end
42
+ end
43
+
44
+ def bitmaps
45
+ @bitmaps ||= index_entries.collect do |index_entry|
46
+ @superblock.seek @superblock.md_block_address(index_entry['blocknr'])
47
+ @superblock.read_struct BITMAP_HEADER
48
+ end
49
+ end
50
+
51
+ attr_accessor :struct
52
+
53
+ def initialize(superblock, struct)
54
+ @superblock = superblock
55
+ @struct = struct
56
+ end
57
+ end
58
+ end # module Lvm2Thin
@@ -0,0 +1,136 @@
1
+ module Lvm2Thin
2
+ class SuperBlock
3
+ attr_accessor :metadata_volume
4
+
5
+ attr_accessor :struct
6
+
7
+ def self.get(metadata_volume)
8
+ @superblock ||= begin
9
+ superblock = SuperBlock.new
10
+ superblock.metadata_volume = metadata_volume
11
+ superblock.seek 0
12
+ superblock.struct = superblock.read_struct SUPERBLOCK
13
+ raise "unknown lvm2 thin metadata magic number" if superblock.struct.magic != THIN_MAGIC
14
+ superblock
15
+ end
16
+ end
17
+
18
+ ### superblock properties:
19
+
20
+ def md_block_size
21
+ @md_block_size ||= struct['metadata_block_size'] * 512 # = 4096
22
+ end
23
+
24
+ def md_block_address(blk_addr)
25
+ blk_addr * md_block_size
26
+ end
27
+
28
+ def entries_per_block
29
+ @entries_per_block ||= (md_block_size - BITMAP_HEADER.size) * 4
30
+ end
31
+
32
+ def data_block_size
33
+ @data_block_size ||= struct['data_block_size'] * 512
34
+ end
35
+
36
+ def data_block_address(blk_addr)
37
+ blk_addr * data_block_size
38
+ end
39
+
40
+ ### lvm thin structures:
41
+
42
+ def data_space_map
43
+ @data_space_map ||= begin
44
+ seek SUPERBLOCK.offset('data_space_map_root')
45
+ DataSpaceMap.new self, read_struct(SPACE_MAP)
46
+ end
47
+ end
48
+
49
+ def metadata_space_map
50
+ @metadata_space_map ||= begin
51
+ seek SUPERBLOCK.offset('metadata_space_map_root')
52
+ MetadataSpaceMap.new self, read_struct(SPACE_MAP)
53
+ end
54
+ end
55
+
56
+ def data_mapping_address
57
+ @data_mapping_address ||= md_block_address(struct['data_mapping_root'])
58
+ end
59
+
60
+ def data_mapping
61
+ @data_mapping ||= MappingTree.new self, data_mapping_address
62
+ end
63
+
64
+ def device_details_address
65
+ @device_details_address ||= md_block_address(struct['device_details_root'])
66
+ end
67
+
68
+ def device_details
69
+ @device_details ||= BTree.new self, device_details_address, DEVICE_DETAILS
70
+ end
71
+
72
+ ### address resolution / mapping:
73
+
74
+ def device_block(device_address)
75
+ (device_address / data_block_size).to_i
76
+ end
77
+
78
+ def device_block_offset(device_address)
79
+ device_address % data_block_size
80
+ end
81
+
82
+ # return array of tuples containing data volume addresses and lengths to
83
+ # read from them to read the specified device offset & length
84
+ def device_to_data(device_id, pos, len)
85
+ dev_blk = device_block(pos)
86
+ dev_off = device_block_offset(pos)
87
+
88
+ total_len = 0
89
+ data_blks = []
90
+
91
+ num_data_blks = (len / data_block_size).to_i + 1
92
+ 0.upto(num_data_blks - 1) do |i|
93
+ data_blk = data_mapping.map_for(device_id).data_block(dev_blk + i)
94
+
95
+ blk_start = data_blk * data_block_size
96
+ blk_len = 0
97
+
98
+ if i == 0
99
+ blk_start += dev_off
100
+ blk_len = data_block_size - dev_off - 1
101
+
102
+ elsif i == num_data_blks - 1
103
+ blk_len = len - total_len
104
+
105
+ else
106
+ blk_len = data_block_size
107
+ end
108
+
109
+ total_len += blk_len
110
+ data_blks << [blk_start, blk_len]
111
+ end
112
+
113
+ data_blks
114
+ end
115
+
116
+ ### metadata volume disk helpers:
117
+
118
+ def seek(pos)
119
+ @metadata_volume.disk.seek pos
120
+ end
121
+
122
+ def read(n)
123
+ @metadata_volume.disk.read n
124
+ end
125
+
126
+ def read_struct(struct)
127
+ OpenStruct.new(struct.decode(@metadata_volume.disk.read(struct.size)))
128
+ end
129
+
130
+ def read_structs(struct, num)
131
+ Array.new(num) do
132
+ read_struct struct
133
+ end
134
+ end
135
+ end # class SuperBlock
136
+ end # module Lvm2Thin
@@ -0,0 +1,6 @@
1
+ require 'VolumeManager/LVM/thin/constants'
2
+ require 'VolumeManager/LVM/thin/btree'
3
+ require 'VolumeManager/LVM/thin/data_map'
4
+ require 'VolumeManager/LVM/thin/mapping_tree'
5
+ require 'VolumeManager/LVM/thin/space_maps'
6
+ require 'VolumeManager/LVM/thin/superblock'
@@ -0,0 +1,97 @@
1
+ #
2
+ # One object of this class for each volume group.
3
+ #
4
+ class VolumeGroup
5
+ attr_accessor :vgId, :vgName, :extentSize, :seqNo, :status, :physicalVolumes, :logicalVolumes, :lvmType
6
+
7
+ def initialize(vgId = nil, vgName = nil, extentSize = nil, seqNo = nil)
8
+ @vgId = vgId # the UUID of this volme group
9
+ @vgName = vgName # the name of this volume group
10
+ @extentSize = extentSize.to_i # the size of all physical and logical extents (in sectors)
11
+ @seqNo = seqNo
12
+
13
+ @lvmType = nil
14
+ @status = []
15
+ @physicalVolumes = {} # PhysicalVolume objects, hashed by name
16
+ @logicalVolumes = {} # LogicalVolume objects, hashed by name
17
+ end
18
+
19
+ def thin_pool_volumes
20
+ @thin_pool_volumes ||= logicalVolumes.values.select { |lv| lv.thin_pool? }
21
+ end
22
+
23
+ def thin_volumes
24
+ @thin_volumes ||= logicalVolumes.values.select { |lv| lv.thin? }
25
+ end
26
+
27
+ def getLvs
28
+ lvList = []
29
+ skipLvs = []
30
+ @logicalVolumes.each_value do |lvObj|
31
+ # remove logical volumes w/ 'thin-pool' segments as they are handled internally
32
+ if lvObj.thin_pool?
33
+ skipLvs << lvObj.lvName unless skipLvs.include?(lvObj.lvName)
34
+ metadata_volume_names = lvObj.thin_pool_segments.collect { |tps| tps.metadata }
35
+ data_volume_names = lvObj.thin_pool_segments.collect { |tps| tps.pool }
36
+ (metadata_volume_names + data_volume_names).each do |vol|
37
+ skipLvs << vol unless skipLvs.include?(vol)
38
+ end
39
+ end
40
+ end
41
+
42
+ @logicalVolumes.each_value do |lvObj|
43
+ if skipLvs.include?(lvObj.lvName)
44
+ $log.debug "Ignoring thin volume: #{lvObj.lvName}"
45
+ next
46
+ end
47
+
48
+ begin
49
+ lvList << lvObj.disk
50
+ rescue => err
51
+ $log.warn "Failed to load MiqDisk for <#{lvObj.disk.dInfo.fileName}>. Message:<#{err}> #{err.backtrace}"
52
+ end
53
+ end
54
+ lvList
55
+ end # def getLvs
56
+
57
+ def dump
58
+ $log.info "#{@vgName}:"
59
+ $log.info "\tID: #{@vgId}"
60
+ $log.info "\tseqno: #{@seqNo}"
61
+ $log.info "\textent_size: #{@extentSize}"
62
+ $log.info "\tstatus:"
63
+ vg.status.each { |s| $log.info "\t\t#{s}" }
64
+
65
+ $log.info "\n\tPhysical Volumes:"
66
+ vg.physicalVolumes.each do |pvName, pv|
67
+ $log.info "\t\t#{pvName}:"
68
+ $log.info "\t\t\tID: #{pv.pvId}"
69
+ $log.info "\t\t\tdevice: #{pv.device}"
70
+ $log.info "\t\t\tdev_size: #{pv.deviceSize}"
71
+ $log.info "\t\t\tpe_start: #{pv.peStart}"
72
+ $log.info "\t\t\tpe_count: #{pv.peCount}"
73
+ $log.info "\t\t\tstatus:"
74
+ pv.status.each { |s| $log.info "\t\t\t\t#{s}" }
75
+ end
76
+
77
+ $log.info "\n\tLogical Volumes:"
78
+ @logicalVolumes.each do |lvName, lv|
79
+ $log.info "\t\t#{lvName}:"
80
+ $log.info "\t\t\tID: #{lv.lvId}"
81
+ $log.info "\t\t\tstatus:"
82
+ lv.status.each { |s| $log.info "\t\t\t\t#{s}" }
83
+ $log.info "\n\t\t\tSegments, count = #{lv.segmentCount}:"
84
+ i = 0
85
+ lv.segments.each do |s|
86
+ $log.info "\t\t\t\tsegment - #{i}:"
87
+ $log.info "\t\t\t\t\tstart_extent: #{s.startExtent}"
88
+ $log.info "\t\t\t\t\textent_count: #{s.extentCount}"
89
+ $log.info "\t\t\t\t\ttype: #{s.type}"
90
+ $log.info "\t\t\t\t\tstripe_count: #{s.stripeCount}"
91
+ $log.info "\n\t\t\t\t\tstripes:"
92
+ s.stripes.each { |si| $log.info "\t\t\t\t\t\t#{si}" }
93
+ i += 1
94
+ end
95
+ end
96
+ end # def dump
97
+ end # class VolumeGroup
@@ -0,0 +1,8 @@
1
+ require 'VolumeManager/LVM/scanner'
2
+ require 'VolumeManager/LVM/parser'
3
+ require 'VolumeManager/LVM/thin'
4
+ require 'VolumeManager/LVM/volume_group'
5
+ require 'VolumeManager/LVM/physical_volume'
6
+ require 'VolumeManager/LVM/logical_volume'
7
+ require 'VolumeManager/LVM/lv_segment'
8
+ require 'VolumeManager/LVM/lvm2disk'