Skip to content

Commit

Permalink
Merge 5f11900 into fc83af3
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Oct 16, 2018
2 parents fc83af3 + 5f11900 commit 4548c7f
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 43 deletions.
27 changes: 19 additions & 8 deletions src/lib/y2storage/autoinst_profile/drive_section.rb
Expand Up @@ -244,16 +244,12 @@ def init_from_disk(disk)
@partitions = partitions_from_disk(disk)
return false if @partitions.empty?

@enable_snapshots = enabled_snapshots?(disk.partitions.map(&:filesystem))
filesystems = disk.filesystem ? [disk.filesystem] : disk.partitions.map(&:filesystem)
@enable_snapshots = enabled_snapshots?(filesystems)
@partitions.each { |i| i.create = false } if reuse_partitions?(disk)

# Same logic followed by the old exporter
@use =
if disk.partitions.any? { |i| windows?(i) }
@partitions.map(&:partition_nr)
else
"all"
end
@use = use_value_from_storage(disk, @partitions)

true
end
Expand Down Expand Up @@ -427,7 +423,7 @@ def enabled_snapshots?(filesystems)
# @param disk [Array<Y2Storage::Disk,Y2Storage::Dasd>] Disk to check whether it is used
# @return [Boolean] true if the disk is being used
def used?(disk)
!(disk.partitions.empty? && disk.component_of.empty?)
!(disk.filesystem.nil? && disk.partitions.empty? && disk.component_of.empty?)
end

# Return the disklabel value for the given disk
Expand All @@ -439,6 +435,21 @@ def used?(disk)
def disklabel_from_disk(disk)
disk.partition_table ? disk.partition_table.type.to_s : NO_PARTITION_TABLE
end

# Determines the value of the 'use' element for a disk/dasd device
#
# @note This logic is inherited from the pre-storage-ng times.
#
# @param disk [Y2Storage::Disk, Y2Storage::Dasd] Disk
# @param partitions [Y2Storage::AutoinstProposal::PartitionSection] Set of partition sections
# @return [String] Value of the 'use' element for a disk.
def use_value_from_storage(disk, partitions)
if disk.partitions.any? { |i| windows?(i) }
partitions.map(&:partition_nr)
else
"all"
end
end
end
end
end
15 changes: 13 additions & 2 deletions src/lib/y2storage/autoinst_profile/partition_section.rb
Expand Up @@ -252,7 +252,7 @@ def init_from_device(device)
# unit (that equals to 8225280 bytes in my experiments).
# According to the comments there, that was done due to bnc#415005 and
# bnc#262535.
@size = device.size.to_i.to_s if create && !device.is?(:disk_device)
@size = device.size.to_i.to_s if create && !fixed_size?(device)
end

def to_hashes
Expand Down Expand Up @@ -287,7 +287,7 @@ def partition_id_from(partition)
def init_fields_by_type(device)
if device.is?(:lvm_lv)
init_lv_fields(device)
elsif device.is?(:disk_device)
elsif device.is?(:disk_device, :software_raid)
init_disk_device_fields(device)
else
init_partition_fields(device)
Expand Down Expand Up @@ -420,6 +420,17 @@ def lvm_group_name(device)
return nil if device.lvm_pv.nil? || device.lvm_pv.lvm_vg.nil?
device.lvm_pv.lvm_vg.basename
end

# Determines whether the device has a fixed size (disk, RAID, etc.)
#
# It is used to find out whether the size specification should be included
# in the profile.
#
# @param device [Y2Storage::Device] Device
# @return [Boolean]
def fixed_size?(device)
device.is?(:disk_device, :software_raid)
end
end
end
end
156 changes: 156 additions & 0 deletions test/data/devicegraphs/btrfs_md_raid.xml
@@ -0,0 +1,156 @@
<?xml version="1.0"?>
<Devicegraph>
<Devices>
<Disk>
<sid>42</sid>
<name>/dev/sda</name>
<region>
<length>104857600</length>
<block-size>512</block-size>
</region>
<topology/>
<range>256</range>
</Disk>
<Gpt>
<sid>43</sid>
</Gpt>
<Partition>
<sid>44</sid>
<name>/dev/sda1</name>
<region>
<start>2048</start>
<length>20971520</length>
<block-size>512</block-size>
</region>
<type>primary</type>
<id>253</id>
</Partition>
<Partition>
<sid>45</sid>
<name>/dev/sda2</name>
<region>
<start>20973568</start>
<length>20971520</length>
<block-size>512</block-size>
</region>
<type>primary</type>
<id>253</id>
</Partition>
<Md>
<sid>46</sid>
<name>/dev/md/md0</name>
<sysfs-name>md0</sysfs-name>
<sysfs-path>/devices/virtual/block/md0</sysfs-path>
<region>
<length>41418624</length>
<block-size>512</block-size>
</region>
<topology>
<optimal-io-size>65536</optimal-io-size>
</topology>
<range>256</range>
<md-level>RAID0</md-level>
<chunk-size>32768</chunk-size>
</Md>
<Btrfs>
<sid>47</sid>
</Btrfs>
<BtrfsSubvolume>
<sid>52</sid>
<id>5</id>
<path></path>
</BtrfsSubvolume>
<BtrfsSubvolume>
<sid>53</sid>
<id>256</id>
<path>@</path>
</BtrfsSubvolume>
<BtrfsSubvolume>
<sid>54</sid>
<id>257</id>
<path>@/.snapshots</path>
</BtrfsSubvolume>
<BtrfsSubvolume>
<sid>55</sid>
<id>257</id>
<path>@/.snapshots/1/snapshot</path>
<default-btrfs-subvolume>true</default-btrfs-subvolume>
</BtrfsSubvolume>
<Partition>
<sid>48</sid>
<name>/dev/sda3</name>
<region>
<start>41945088</start>
<length>62912479</length>
<block-size>512</block-size>
</region>
<type>primary</type>
<id>131</id>
</Partition>
<Ext4>
<sid>50</sid>
</Ext4>
<MountPoint>
<sid>51</sid>
<path>/</path>
<mount-by>device</mount-by>
<in-etc-fstab>true</in-etc-fstab>
<freq>0</freq>
<passno>0</passno>
</MountPoint>
</Devices>
<Holders>
<User>
<source-sid>42</source-sid>
<target-sid>43</target-sid>
</User>
<Subdevice>
<source-sid>43</source-sid>
<target-sid>44</target-sid>
</Subdevice>
<Subdevice>
<source-sid>43</source-sid>
<target-sid>45</target-sid>
</Subdevice>
<MdUser>
<source-sid>44</source-sid>
<target-sid>46</target-sid>
</MdUser>
<MdUser>
<source-sid>45</source-sid>
<target-sid>46</target-sid>
</MdUser>
<FilesystemUser>
<source-sid>46</source-sid>
<target-sid>47</target-sid>
</FilesystemUser>
<Subdevice>
<source-sid>43</source-sid>
<target-sid>48</target-sid>
</Subdevice>
<FilesystemUser>
<source-sid>48</source-sid>
<target-sid>50</target-sid>
</FilesystemUser>
<User>
<source-sid>50</source-sid>
<target-sid>51</target-sid>
</User>
<Subdevice>
<source-sid>47</source-sid>
<target-sid>52</target-sid>
</Subdevice>
<Subdevice>
<source-sid>52</source-sid>
<target-sid>53</target-sid>
</Subdevice>
<Subdevice>
<source-sid>52</source-sid>
<target-sid>54</target-sid>
</Subdevice>
<Subdevice>
<source-sid>54</source-sid>
<target-sid>55</target-sid>
</Subdevice>
</Holders>
</Devicegraph>
42 changes: 39 additions & 3 deletions test/data/devicegraphs/partitioned_md_raid.xml
@@ -1,5 +1,4 @@
<?xml version="1.0"?>
<!-- generated by libstorage-ng version 3.3.50, linux-74ac.(none), 2017-10-31 15:30:41 GMT -->
<Devicegraph>
<Devices>
<Disk>
Expand Down Expand Up @@ -53,9 +52,30 @@
<md-level>RAID0</md-level>
<chunk-size>32768</chunk-size>
</Md>
<Xfs>
<Btrfs>
<sid>47</sid>
</Xfs>
</Btrfs>
<BtrfsSubvolume>
<sid>54</sid>
<id>5</id>
<path></path>
</BtrfsSubvolume>
<BtrfsSubvolume>
<sid>55</sid>
<id>256</id>
<path>@</path>
</BtrfsSubvolume>
<BtrfsSubvolume>
<sid>56</sid>
<id>257</id>
<path>@/.snapshots</path>
</BtrfsSubvolume>
<BtrfsSubvolume>
<sid>57</sid>
<id>257</id>
<path>@/.snapshots/1/snapshot</path>
<default-btrfs-subvolume>true</default-btrfs-subvolume>
</BtrfsSubvolume>
<Partition>
<sid>48</sid>
<name>/dev/sda3</name>
Expand Down Expand Up @@ -130,6 +150,22 @@
<source-sid>43</source-sid>
<target-sid>48</target-sid>
</Subdevice>
<Subdevice>
<source-sid>47</source-sid>
<target-sid>54</target-sid>
</Subdevice>
<Subdevice>
<source-sid>54</source-sid>
<target-sid>55</target-sid>
</Subdevice>
<Subdevice>
<source-sid>54</source-sid>
<target-sid>56</target-sid>
</Subdevice>
<Subdevice>
<source-sid>56</source-sid>
<target-sid>57</target-sid>
</Subdevice>
<FilesystemUser>
<source-sid>48</source-sid>
<target-sid>50</target-sid>
Expand Down
47 changes: 47 additions & 0 deletions test/data/devicegraphs/unpartitioned-disk.yml
@@ -0,0 +1,47 @@
---
- disk:
name: /dev/sda
size: 500 GiB
file_system: btrfs
mount_point: "/"
btrfs:
default_subvolume: "@"
subvolumes:
- subvolume:
path: "@/home"
nocow: false
- subvolume:
path: "@/srv"
nocow: false
- subvolume:
path: "@/tmp"
nocow: false
- subvolume:
path: "@/usr/local"
nocow: false
- subvolume:
path: "@/var/cache"
nocow: false
- subvolume:
path: "@/var/crash"
nocow: false
- subvolume:
path: "@/log"
nocow: false
- subvolume:
path: "@/opt"
nocow: false
- subvolume:
path: "@/var/lib/mariadb"
nocow: true
- subvolume:
path: "@/var/lib/mysql"
nocow: true
- subvolume:
path: "@/var/lib/pgsql"
nocow: true
- subvolume:
path: "@/.snapshots"
- subvolume:
path: "@/.snapshots/1/snapshot"

0 comments on commit 4548c7f

Please sign in to comment.