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,75 @@
1
+ require 'disk/MiqDisk'
2
+
3
+ #
4
+ # One object of this class for each logical volume.
5
+ #
6
+ class LogicalVolume
7
+ attr_accessor :lvId, :lvName, :segmentCount, :segments, :status, :vgObj, :lvPath, :driveHint
8
+
9
+ def initialize(lvId = nil, lvName = nil, segmentCount = 0)
10
+ @lvId = lvId # the UUID of this logical volume
11
+ @lvName = lvName # the logical volume's name
12
+ @lvPath = nil # native use only
13
+ @segmentCount = segmentCount.to_i # the number of segments in this LV
14
+
15
+ @driveHint = nil # Drive hint, for windows
16
+ @segments = [] # array of this LV's LvSegment objects
17
+ @status = []
18
+ @vgObj = nil # a reference to this LV's volume group
19
+
20
+ @superblock = nil # thin metadata superblock (if this is a thin metadata volume)
21
+ end
22
+
23
+ # will raise exception if LogicalVolume is not thin metadata volume
24
+ def superblock
25
+ @superblock ||= Lvm2Thin::SuperBlock.get self
26
+ end
27
+
28
+ # MiqDisk object for volume
29
+ def disk
30
+ @disk ||= begin
31
+ dInfo = OpenStruct.new
32
+ dInfo.lvObj = self
33
+ dInfo.hardwareId = ""
34
+ MiqDisk.new(Lvm2DiskIO, dInfo, 0)
35
+ end
36
+ end
37
+
38
+ def thin_segments
39
+ @thin_segments ||= segments.select { |segment| segment.thin? }
40
+ end
41
+
42
+ def thin_segment
43
+ thin_segments.first
44
+ end
45
+
46
+ def thin?
47
+ !thin_segments.empty?
48
+ end
49
+
50
+ def thin_pool_volume
51
+ return nil unless thin?
52
+ return thin_segment.thin_pool_volume
53
+ end
54
+
55
+ def thin_pool_segments
56
+ @thin_pool_segments ||= segments.select { |segment| segment.thin_pool? }
57
+ end
58
+
59
+ def thin_pool_segment
60
+ thin_pool_segments.first
61
+ end
62
+
63
+ def thin_pool?
64
+ !thin_pool_segments.empty?
65
+ end
66
+
67
+ def metadata_volume
68
+ thin_pool_segment.metadata_volume
69
+ end
70
+
71
+ def data_volume
72
+ thin_pool_segment.data_volume
73
+ end
74
+ end # class LogicalVolume
75
+
@@ -0,0 +1,43 @@
1
+ #
2
+ # One object of this class for each segment in a logical volume.
3
+ #
4
+ class LvSegment
5
+ attr_accessor :startExtent, :extentCount, :type, :stripeCount, :stripes
6
+
7
+ attr_accessor :thin_pool, :device_id # set for thin segments
8
+
9
+ attr_accessor :metadata, :pool # set for thin pool segments
10
+
11
+ attr_accessor :thin_pool_volume, :metadata_volume, :data_volume
12
+
13
+ def initialize(startExtent = 0, extentCount = 0, type = nil, stripeCount = 0, deviceId=nil)
14
+ @startExtent = startExtent.to_i # the first logical extent of this segment
15
+ @extentCount = extentCount.to_i # the number of logical extents in this segment
16
+ @type = type # the type of segment
17
+ @stripeCount = stripeCount.to_i # the number of stripes in this segment(1 = linear)
18
+
19
+ @stripes = [] # <pvName, startPhysicalExtent> pairs for each stripe.
20
+ @device_id = deviceId
21
+ end
22
+
23
+ def thin?
24
+ type == 'thin'
25
+ end
26
+
27
+ def thin_pool?
28
+ type == 'thin-pool'
29
+ end
30
+
31
+ def set_metadata_volume(lvs)
32
+ @metadata_volume = lvs.find { |lv| lv.lvName == metadata }
33
+ end
34
+
35
+ def set_data_volume(lvs)
36
+ @data_volume = lvs.find { |lv| lv.lvName == pool }
37
+ end
38
+
39
+ def set_thin_pool_volume(lvs)
40
+ @thin_pool_volume = lvs.find { |lv| lv.lvName == thin_pool }
41
+ end
42
+ end # class LvSegment
43
+
@@ -0,0 +1,158 @@
1
+ #
2
+ # MiqDisk support module for LVM2 logical volumes.
3
+ #
4
+ module Lvm2DiskIO
5
+ def d_init
6
+ @lvObj = dInfo.lvObj
7
+ raise "Logical volume object not present in disk info." unless @lvObj
8
+ @vgObj = @lvObj.vgObj
9
+ self.diskType = "#{@vgObj.lvmType} Logical Volume"
10
+ self.blockSize = 512
11
+
12
+ @extentSize = @vgObj.extentSize * blockSize # extent size in bytes
13
+
14
+ @lvSize = 0
15
+ @segments = []
16
+ @lvObj.segments.each do |lvSeg|
17
+ seg = Segment.new(lvSeg.startExtent * @extentSize, ((lvSeg.startExtent + lvSeg.extentCount) * @extentSize) - 1, lvSeg.type)
18
+ seg.lvSeg = lvSeg
19
+ @lvSize += (seg.segSize / blockSize)
20
+
21
+ #
22
+ # Each slice is defined by a physical volume name and the extent
23
+ # number of where the stripe starts on that physical volume.
24
+ #
25
+ lvSeg.stripes.each_slice(2) do |pvn, ext|
26
+ pvObj = @vgObj.physicalVolumes[pvn]
27
+ raise "Physical volume object (name=<#{pvn}>) not found in volume group (id=<#{@vgObj.vgId}> name=<#{@vgObj.vgName}>) of logical volume (id=<#{@lvObj.lvId}> name=<#{@lvObj.lvName}>)" if pvObj.nil?
28
+ #
29
+ # Compute the byte address of the start of the stripe on the physical volume.
30
+ #
31
+ ba = (pvObj.peStart * blockSize) + (ext * @extentSize)
32
+ seg.stripes << Stripe.new(pvObj.diskObj, ba)
33
+ end
34
+ @segments << seg
35
+ end
36
+ end # def d_init
37
+
38
+ def d_read(pos, len)
39
+ retStr = ''
40
+ return retStr if len == 0
41
+
42
+ if logicalVolume.thin?
43
+ device_id = logicalVolume.thin_segment.device_id
44
+ thin_pool = logicalVolume.thin_pool_volume
45
+ data_blks = thin_pool.metadata_volume.superblock.device_to_data(device_id, pos, len)
46
+ data_blks.each do |offset, len|
47
+ thin_pool.data_volume.disk.seek offset
48
+ retStr << thin_pool.data_volume.disk.read(len)
49
+ end
50
+
51
+ return retStr
52
+ end
53
+
54
+ endPos = pos + len - 1
55
+ startSeg, endSeg = getSegs(pos, endPos)
56
+
57
+ (startSeg..endSeg).each do |si|
58
+ seg = @segments[si]
59
+ srs = seg.startByteAddr # segment read start
60
+ srl = seg.segSize # segment read length
61
+
62
+ if si == startSeg
63
+ srs = pos
64
+ srl = seg.segSize - (pos - seg.startByteAddr)
65
+ end
66
+
67
+ if si == endSeg
68
+ srl = endPos - srs + 1
69
+ end
70
+
71
+ retStr << readSeg(seg, srs, srl)
72
+ end
73
+
74
+ retStr
75
+ end # def d_read
76
+
77
+ def d_write(_pos, _buf, _len)
78
+ raise "Write operation not yet supported for logical volumes"
79
+ end # def d_write
80
+
81
+ def d_close
82
+ end # def d_close
83
+
84
+ def d_size
85
+ @lvSize
86
+ end # def d_size
87
+
88
+ def logicalVolume
89
+ @lvObj
90
+ end
91
+
92
+ def volumeGroup
93
+ @vgObj
94
+ end
95
+
96
+ private
97
+
98
+ def getSegs(startPos, endPos, segments=@segments)
99
+ startSeg = nil
100
+ endSeg = nil
101
+
102
+ segments.each_with_index do |seg, i|
103
+ startSeg = i if seg.byteRange === startPos
104
+ if seg.byteRange === endPos
105
+ raise "Segment sequence error" unless startSeg
106
+ endSeg = i
107
+ break
108
+ end
109
+ end
110
+ raise "Segment range error: LV = #{@lvObj.lvName}, startPos = #{startPos}, endPos = #{endPos}" if !startSeg || !endSeg
111
+
112
+ return startSeg, endSeg
113
+ end
114
+
115
+ def readSeg(seg, sba, len)
116
+ #
117
+ # For now, we only support linear segments (stripeCount = 1)
118
+ # TODO: support other segment types.
119
+ #
120
+ stripe = seg.stripes[0]
121
+ pvReadPos = stripe.pvStartByteAddr + (sba - seg.startByteAddr) # byte address on the physical volume
122
+
123
+ stripe.pvDiskObj.seek(pvReadPos, IO::SEEK_SET)
124
+ stripe.pvDiskObj.read(len)
125
+ end
126
+
127
+ #
128
+ # Like LvSegment but optimized for logical volume IO
129
+ #
130
+ class Segment
131
+ attr_accessor :type, :stripes, :segSize, :byteRange
132
+ attr_accessor :lvSeg
133
+
134
+ def initialize(startByte, endByte, type = nil)
135
+ @byteRange = Range.new(startByte, endByte, false)
136
+ @type = type
137
+ @segSize = endByte - startByte + 1
138
+ @stripes = []
139
+ end
140
+
141
+ def startByteAddr
142
+ @byteRange.begin
143
+ end
144
+
145
+ def endByteAddr
146
+ @byteRange.end
147
+ end
148
+ end
149
+
150
+ class Stripe
151
+ attr_accessor :pvDiskObj, :pvStartByteAddr
152
+
153
+ def initialize(pvDisk, pvStart)
154
+ @pvDiskObj = pvDisk
155
+ @pvStartByteAddr = pvStart
156
+ end
157
+ end
158
+ end # module Lvm2DiskIO
@@ -0,0 +1,138 @@
1
+ require 'active_support/core_ext/object/try'
2
+
3
+ class Lvm2MdParser
4
+ HASH_START = '{'
5
+ HASH_END = '}'
6
+ ARRAY_START = '['
7
+ ARRAY_END = ']'
8
+ STRING_START = '"'
9
+ STRING_END = '"'
10
+
11
+ attr_reader :vgName
12
+
13
+ def initialize(mdStr, pvHdrs)
14
+ @pvHdrs = pvHdrs # PV headers hashed by UUID
15
+ @mda = mdStr.gsub(/#.*$/, "").gsub("[", "[ ").gsub("]", " ]").gsub('"', ' " ').delete("=,").gsub(/\s+/, " ").split(' ')
16
+ @vgName = @mda.shift
17
+ end # def initialize
18
+
19
+ def parse
20
+ vgHash = {}
21
+ parseObj(vgHash, @vgName)
22
+ vg = vgHash[@vgName]
23
+
24
+ getVgObj(@vgName, vg)
25
+ end # def parse
26
+
27
+ def self.dumpMetadata(md)
28
+ level = 0
29
+ md.lines do |line|
30
+ line.strip!
31
+ level -= 1 if line[0, 1] == HASH_END || line[0, 1] == ARRAY_END
32
+ $log.debug((level > 0 ? " " * level : "") + line)
33
+ level += 1 if line[-1, 1] == HASH_START || line[-1, 1] == ARRAY_START
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def getVgObj(_vgName, vg)
40
+ vgObj = VolumeGroup.new(vg['id'], @vgName, vg['extent_size'], vg['seqno'])
41
+ vgObj.lvmType = "LVM2"
42
+ vg["status"].each { |s| vgObj.status << s }
43
+
44
+ vg["physical_volumes"].each { |pvName, pv| vgObj.physicalVolumes[pvName] = getPvObj(vgObj, pvName, pv) } unless vg["physical_volumes"].nil?
45
+ vg["logical_volumes"].each { |lvName, lv| vgObj.logicalVolumes[lvName] = getLvObj(vgObj, lvName, lv) } unless vg["logical_volumes"].nil?
46
+
47
+ vgObj
48
+ end # def getVgObj
49
+
50
+ def getPvObj(vgObj, pvName, pv)
51
+ pvObj = PhysicalVolume.new(pv['id'].delete('-'), pvName, pv['device'], pv['dev_size'], pv['pe_start'], pv['pe_count'])
52
+ # Add reference to volume group object to each physical volume object.
53
+ pvObj.vgObj = vgObj
54
+
55
+ dobj = @pvHdrs[pvObj.pvId].try(:diskObj)
56
+ if dobj
57
+ pvObj.diskObj = dobj
58
+ dobj.pvObj = pvObj
59
+ end
60
+
61
+ pv["status"].each { |s| pvObj.status << s }
62
+
63
+ pvObj
64
+ end # def getPvObj
65
+
66
+ def getLvObj(vgObj, lvName, lv)
67
+ lvObj = LogicalVolume.new(lv['id'], lvName, lv['segment_count'])
68
+ lvObj.vgObj = vgObj
69
+ lv["status"].each { |s| lvObj.status << s }
70
+
71
+ (1..lvObj.segmentCount).each { |seg| lvObj.segments << getSegObj(lv["segment#{seg}"]) }
72
+
73
+ lvObj
74
+ end # def getLvObj
75
+
76
+ def getSegObj(seg)
77
+ device_id = seg['device_id'].try(:to_i)
78
+ segObj = LvSegment.new(seg['start_extent'], seg['extent_count'], seg['type'], seg['stripe_count'], device_id)
79
+ segObj.thin_pool = seg['thin_pool'] if seg.key?('thin_pool')
80
+ segObj.metadata = seg['metadata'] if seg.key?('metadata')
81
+ segObj.pool = seg['pool'] if seg.key?('pool')
82
+ seg['stripes'].each_slice(2) do |pv, o|
83
+ segObj.stripes << pv
84
+ segObj.stripes << o.to_i
85
+ end unless seg['stripes'].nil?
86
+
87
+ segObj
88
+ end # def getSegObj
89
+
90
+ def parseObj(parent, name)
91
+ val = @mda.shift
92
+
93
+ parent[name] =
94
+ case val
95
+ when HASH_START then parseHash
96
+ when ARRAY_START then parseArray
97
+ else parseVal(val)
98
+ end
99
+ end
100
+
101
+ def parseVal(val)
102
+ if val == STRING_START
103
+ return parseString
104
+ else
105
+ return val
106
+ end
107
+ end
108
+
109
+ def parseHash
110
+ h = {}
111
+ name = @mda.shift
112
+ while name && name != HASH_END
113
+ parseObj(h, name)
114
+ name = @mda.shift
115
+ end
116
+ h
117
+ end
118
+
119
+ def parseArray
120
+ a = []
121
+ val = @mda.shift
122
+ while val && val != ARRAY_END
123
+ a << parseVal(val)
124
+ val = @mda.shift
125
+ end
126
+ a
127
+ end
128
+
129
+ def parseString
130
+ s = ''
131
+ word = @mda.shift
132
+ while word && word != STRING_END
133
+ s << word + " "
134
+ word = @mda.shift
135
+ end
136
+ s.chomp(" ")
137
+ end
138
+ end # class Lvm2MdParser
@@ -0,0 +1,19 @@
1
+ #
2
+ # One object of this class for each physical volume in a volume group.
3
+ #
4
+ class PhysicalVolume
5
+ attr_accessor :pvId, :pvName, :device, :deviceSize, :peStart, :peCount, :status, :vgObj, :diskObj
6
+
7
+ def initialize(pvId = nil, pvName = nil, device = nil, deviceSize = nil, peStart = nil, peCount = nil)
8
+ @pvId = pvId # the UUID of this physical volume
9
+ @pvName = pvName # the name of this physical volume
10
+ @device = device # the physical volume's device node under /dev.
11
+ @deviceSize = deviceSize # the size if this physical volume (in )
12
+ @peStart = peStart.to_i # the sector number of the first physical extent on this PV
13
+ @peCount = peCount.to_i # the number of physical extents on this PV
14
+
15
+ @status = []
16
+ @vgObj = nil # a reference to this PV's volume group
17
+ @diskObj = nil # a reference to the MiqDisk object for this PV
18
+ end
19
+ end # class PhysicalVolume
@@ -0,0 +1,156 @@
1
+ module Lvm2Scanner
2
+ LVM_PARTITION_TYPE = 142
3
+ SECTOR_SIZE = 512
4
+ LABEL_SCAN_SECTORS = 4
5
+
6
+ LVM_ID_LEN = 8
7
+ LVM_TYPE_LEN = 8
8
+ LVM_ID = "LABELONE"
9
+
10
+ PV_ID_LEN = 32
11
+ MDA_MAGIC_LEN = 16
12
+ FMTT_MAGIC = "\040\114\126\115\062\040\170\133\065\101\045\162\060\116\052\076"
13
+
14
+ #
15
+ # On disk label header.
16
+ #
17
+ LABEL_HEADER = BinaryStruct.new([
18
+ "A#{LVM_ID_LEN}", 'lvm_id',
19
+ 'Q', 'sector_xl',
20
+ 'L', 'crc_xl',
21
+ 'L', 'offset_xl',
22
+ "A#{LVM_TYPE_LEN}", 'lvm_type'
23
+ ])
24
+
25
+ #
26
+ # On disk physical volume header.
27
+ #
28
+ PV_HEADER = BinaryStruct.new([
29
+ "A#{PV_ID_LEN}", 'pv_uuid',
30
+ "Q", 'device_size_xl'
31
+ ])
32
+
33
+ #
34
+ # On disk disk location structure.
35
+ #
36
+ DISK_LOCN = BinaryStruct.new([
37
+ "Q", 'offset',
38
+ "Q", 'size'
39
+ ])
40
+
41
+ #
42
+ # On disk metadata area header.
43
+ #
44
+ MDA_HEADER = BinaryStruct.new([
45
+ "L", 'checksum_xl',
46
+ "A#{MDA_MAGIC_LEN}", 'magic',
47
+ "L", 'version',
48
+ "Q", 'start',
49
+ "Q", 'size'
50
+ ])
51
+
52
+ #
53
+ # On disk raw location header, points to metadata.
54
+ #
55
+ RAW_LOCN = BinaryStruct.new([
56
+ "Q", 'offset',
57
+ "Q", 'size',
58
+ "L", 'checksum',
59
+ "L", 'filler'
60
+ ])
61
+
62
+ #
63
+ # Scan the physical volume for LVM headers.
64
+ # Return nil if no label is found.
65
+ # Otherwise, return a physical volume header containing a list of metadata areas.
66
+ #
67
+ def self.labelScan(d)
68
+ lh = nil
69
+ (0...LABEL_SCAN_SECTORS).each do |s|
70
+ lh = readLabel(d, s)
71
+ break if lh
72
+ end
73
+ return nil unless lh
74
+
75
+ pvh = readPvHeader(d, lh)
76
+
77
+ mdList = []
78
+ pvh.metadataDiskLocations.each do |dlh|
79
+ mdah = readMdah(d, dlh)
80
+ mdah.rawLocations.each do |rl|
81
+ mdList << readRaw(d, rl)
82
+ end
83
+ end
84
+ pvh.mdList = mdList
85
+ pvh.lvm_type = lh.lvm_type.split(" ").first
86
+ pvh
87
+ end # def self.labelScan
88
+
89
+ private
90
+
91
+ def self.readLabel(d, s)
92
+ d.seek(s * SECTOR_SIZE, IO::SEEK_SET)
93
+ lh = readStruct(d, LABEL_HEADER)
94
+ return lh if lh.lvm_id == LVM_ID
95
+ nil
96
+ end # def self.readLabel
97
+
98
+ def self.readPvHeader(d, lh)
99
+ pvho = (lh.sector_xl * SECTOR_SIZE) + lh.offset_xl
100
+ d.seek(pvho)
101
+ pvh = readStruct(d, PV_HEADER)
102
+
103
+ #
104
+ # Read and save disk location structures for data areas.
105
+ #
106
+ pvh.dataDiskLocations = []
107
+ loop do
108
+ dlh = readStruct(d, DISK_LOCN)
109
+ break if dlh.offset == 0
110
+ pvh.dataDiskLocations << dlh
111
+ end
112
+
113
+ #
114
+ # Read and save disk location structures for metadata headers.
115
+ #
116
+ pvh.metadataDiskLocations = []
117
+ loop do
118
+ dlh = readStruct(d, DISK_LOCN)
119
+ break if dlh.offset == 0
120
+ pvh.metadataDiskLocations << dlh
121
+ end
122
+
123
+ pvh
124
+ end # def self.readPvHeader
125
+
126
+ def self.readMdah(d, dlh)
127
+ d.seek(dlh.offset, IO::SEEK_SET)
128
+ mdah = readStruct(d, MDA_HEADER)
129
+ raise "** readMdah: unknown magic number" if mdah.magic != FMTT_MAGIC
130
+
131
+ #
132
+ # Read and save raw loaction headers for metadata.
133
+ #
134
+ mdah.rawLocations = []
135
+ loop do
136
+ rlh = readStruct(d, RAW_LOCN)
137
+ break if rlh.offset == 0
138
+ rlh.base = mdah.start
139
+ mdah.rawLocations << rlh
140
+ end
141
+
142
+ mdah
143
+ end # def self.readMdah
144
+
145
+ def self.readRaw(d, rlh)
146
+ osp = d.seekPos
147
+ d.seek(rlh.base + rlh.offset, IO::SEEK_SET)
148
+ da = d.read(rlh.size)
149
+ d.seek(osp, IO::SEEK_SET)
150
+ da
151
+ end # def self.readRaw
152
+
153
+ def self.readStruct(d, struct)
154
+ OpenStruct.new(struct.decode(d.read(struct.size)))
155
+ end # def self.readStruct
156
+ end # module Lvm2Scanner
@@ -0,0 +1,83 @@
1
+ module Lvm2Thin
2
+ class BTree
3
+ FLAGS = { :internal => 1, :leaf => 2}
4
+
5
+ attr_accessor :root_address
6
+
7
+ def initialize(superblock, root_address, value_type)
8
+ @superblock = superblock
9
+ @root_address = root_address
10
+ @value_type = value_type
11
+ end
12
+
13
+ def root
14
+ @root ||= begin
15
+ @superblock.seek root_address
16
+ @superblock.read_struct DISK_NODE
17
+ end
18
+ end
19
+
20
+ def internal?
21
+ (root['flags'] & FLAGS[:internal]) != 0
22
+ end
23
+
24
+ def leaf?
25
+ (root['flags'] & FLAGS[:leaf]) != 0
26
+ end
27
+
28
+ def num_entries
29
+ @num_entries ||= root['nr_entries']
30
+ end
31
+
32
+ def max_entries
33
+ @max_entries ||= root['max_entries']
34
+ end
35
+
36
+ def key_base
37
+ root_address + DISK_NODE.size
38
+ end
39
+
40
+ def key_address(i)
41
+ key_base + i * 8
42
+ end
43
+
44
+ def value_base
45
+ key_address(max_entries)
46
+ end
47
+
48
+ def value_address(i)
49
+ value_base + @value_type.size * i
50
+ end
51
+
52
+ def keys
53
+ @keys ||= begin
54
+ @superblock.seek key_base
55
+ @superblock.read(num_entries * 8).unpack("Q#{num_entries}")
56
+ end
57
+ end
58
+
59
+ def entries
60
+ @entries ||= begin
61
+ @superblock.seek value_base
62
+ @superblock.read_structs @value_type, num_entries
63
+ end
64
+ end
65
+
66
+ def entry_for(key)
67
+ entries[keys.index(key)]
68
+ end
69
+
70
+ def to_h
71
+ @h ||=
72
+ Hash[0.upto(num_entries-1).collect do |i|
73
+ k = keys[i]
74
+ e = entries[i].kind_of?(BTree) ? entries[i].to_h : entries[i]
75
+ [k, e]
76
+ end]
77
+ end
78
+
79
+ def [](key)
80
+ return to_h[key]
81
+ end
82
+ end
83
+ end # module Lvm2Thin