Author: fehr
Date: Tue May 17 13:39:44 2011
New Revision: 64012
URL: http://svn.opensuse.org/viewcvs/yast?rev=64012&view=rev
Log:
- huge backport from svn and git head for lots of features
in SLES11 SP2 (e.g. fate#307741, fate#311015, fate#310223,
fate#303810, fate#306587l, fate#306960)
- version 2.17.101
Added:
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/SaveGraph.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/ShowBytes.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ArchInfo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ArchInfo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Blkid.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Blkid.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/BtrfsCo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/BtrfsCo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasdview.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasdview.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Device.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Device.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Enum.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Enum.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcMdadm.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcMdadm.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FreeInfo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FreeInfo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Geometry.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Geometry.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Graph.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Graph.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/HumanString.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/HumanString.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lsscsi.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lsscsi.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Parted.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Parted.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ProcMdstat.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ProcMdstat.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ProcParts.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ProcParts.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Region.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/SystemInfo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/SystemInfo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Tmpfs.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Tmpfs.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/TmpfsCo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/TmpfsCo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/XmlFile.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/XmlFile.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/backupstate1.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/common.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/contvolinfo1.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/empty/
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/empty/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/empty/disk_sda.info
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/scandium/
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/scandium/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/scandium/arch.info
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/scandium/disk_sda.info
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/thalassa/
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/thalassa/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/thalassa/disk_sda.info
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/thalassa/disk_sdb.info
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/thalassa/disk_sdc.info
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/thalassa/free.info
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/thalassa/lvmvg_system.info
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/disklabel1.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/freeinfo1.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/fstab2.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/fstab3.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/fstab4.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/lvm_create2.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/partitionname.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/partitionprefix.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/recursive1.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/recursive2.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/renumber1.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/renumber2.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/renumber3.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/backupstate1.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/backupstate1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/contvolinfo1.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/contvolinfo1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/disklabel1.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/disklabel1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/freeinfo1.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/freeinfo1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/fstab2.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/fstab2.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/fstab3.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/fstab3.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/fstab4.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/fstab4.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/lvm_create2.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/lvm_create2.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/partitionname.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/partitionname.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/partitionprefix.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/partitionprefix.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/recursive1.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/recursive1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/recursive2.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/recursive2.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/renumber1.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/renumber1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/renumber2.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/renumber2.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/renumber3.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/renumber3.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/udevdecode.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/udevdecode.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/udevencode.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/udevencode.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/usedby1.err
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/usedby1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/udevdecode.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/udevencode.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/usedby1.cc
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-btrfs-dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-btrfs-lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-btrfs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-graph.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-import.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-summary.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-tmpfs-dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-tmpfs-lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-tmpfs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/inst_resize_dialog.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/StorageIcons.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/StorageProposal.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/StorageUpdate.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/README
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/empty/
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/empty-efi/
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/empty-efi/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/empty-efi/arch.info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/empty-efi/disk_sda.info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/empty/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/empty/disk_sda.info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/half-empty/
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/half-empty/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/half-empty/disk_sda.info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/reuse-home/
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/reuse-home/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/reuse-home/disk_sda.info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/reuse-home/free.info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/windows/
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/windows-only/
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/windows-only/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/windows-only/disk_sda.info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/windows-only/free.info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/windows/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/windows/disk_sda.info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/windows/free.info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/lib/test.exp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/lib/test_init.exp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty-efi1.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty-efi1.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty-efi1.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty-efi2.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty-efi2.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty-efi2.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty1.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty1.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty1.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty2.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty2.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty2.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty3.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty3.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty3.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty4.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty4.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty4.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty5.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty5.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty5.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty6.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty6.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/empty6.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/half-empty1.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/half-empty1.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/half-empty1.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/helper1a.yh
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/helper1b.yh
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/reuse-home1.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/reuse-home1.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/reuse-home1.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/setup-system.yh
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/windows-only1.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/windows-only1.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/windows-only1.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/windows1.err
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/windows1.out
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/windows1.ycp
Removed:
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ProcPart.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ProcPart.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/disk_hda
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/disk_hdb
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/disk_sda
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/disk_sdb
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/volume_info
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/inst_do_resize.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/auto_part_functions.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/size_calculations.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/tests/test_inst_target_part.ycp
Modified:
branches/SuSE-Code-11-SP2-Branch/storage/ (props changed)
branches/SuSE-Code-11-SP2-Branch/storage/VERSION
branches/SuSE-Code-11-SP2-Branch/storage/disk/src/disk_worker.ycp
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/python/LibStorage.i
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/python/Makefile
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/ycp/LibStorage.i
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/ (props changed)
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLock.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLoop.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLvm.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestMd.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestProbing.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestStorage.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ (props changed)
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AppUtil.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AppUtil.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AsciiFile.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AsciiFile.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Container.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Container.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasd.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasd.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DerefIterator.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Disk.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Disk.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dm.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dm.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmCo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmCo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPart.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPart.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPartCo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPartCo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmmultipath.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmmultipath.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmmultipathCo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmmultipathCo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmraid.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmraid.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmraidCo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmraidCo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcFstab.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcFstab.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FilterIterator.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/IterPair.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ListListIterator.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lock.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lock.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Loop.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Loop.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LoopCo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LoopCo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmLv.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmLv.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmVg.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmVg.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Md.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Md.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/MdCo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/MdCo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/MdPart.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/MdPart.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/MdPartCo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/MdPartCo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Nfs.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Nfs.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/NfsCo.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/NfsCo.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/OutputProcessor.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/OutputProcessor.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Partition.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Partition.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/PeContainer.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/PeContainer.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ProcMounts.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ProcMounts.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Regex.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Regex.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Region.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Storage.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Storage.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageCallbacks.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageCallbacks.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageDefines.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageInterface.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageTmpl.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageTypes.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageTypes.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/SystemCmd.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/SystemCmd.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/common.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/data/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/format1.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/fstab1.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/humanstring1.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/humanstring2.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/lvm_create.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/lvm_extend.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/md_create.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/partition1.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/format1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/humanstring1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/humanstring2.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/lvm_create.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/lvm_extend.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/md_create.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/partition1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/single.out/uuid1.out
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/testsuite/uuid1.cc
branches/SuSE-Code-11-SP2-Branch/storage/package/yast2-storage.changes
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/auto_part_create.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/auto_part_functions.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/auto_part_prepare.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/auto_part_ui.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/custom_part_check_generated.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/custom_part_dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/custom_part_helptexts.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/custom_part_lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-all.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-dm-dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-dm-lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-dm.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-hd-dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-hd-lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-hd.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-log.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-loop-dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-loop-lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-loop.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-lvm-dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-lvm-lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-lvm.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-main.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-nfs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-raid-dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-raid-lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-raid.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-settings.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/ep-unused.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/lvm_lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/lvm_lv_lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/lvm_pv_lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/lvm_ui_dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/partition_defines.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/include/raid_lib.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/inst_custom_part.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/inst_disk_proposal.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/inst_prepdisk.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/inst_resize_ui.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/inst_target_part.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/inst_target_selection.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/FileSystems.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/Makefile.am
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/MiniWorkflow.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/Partitions.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/Storage.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/StorageClients.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/StorageControllers.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/StorageDevices.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/StorageFields.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/StorageSettings.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/TabPanel.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/modules/TreePanel.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/proposal/partitions_proposal.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/storage_finish.ycp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/ (props changed)
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/config/unix.exp
branches/SuSE-Code-11-SP2-Branch/storage/storage/src/testsuite/data/ (props changed)
branches/SuSE-Code-11-SP2-Branch/storage/yast2-storage.spec.in
Modified: branches/SuSE-Code-11-SP2-Branch/storage/VERSION
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/VERSION?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/VERSION (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/VERSION Tue May 17 13:39:44 2011
@@ -1 +1 @@
-2.17.100
+2.17.101
Modified: branches/SuSE-Code-11-SP2-Branch/storage/disk/src/disk_worker.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/disk/src/disk_worker.ycp?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/disk/src/disk_worker.ycp (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/disk/src/disk_worker.ycp Tue May 17 13:39:44 2011
@@ -33,6 +33,8 @@
Storage::SwitchUiAutomounter(true);
Storage::SaveUsedFs();
+ Storage::FinishLibstorage();
+
return ret;
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/python/LibStorage.i
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/python/LibStorage.i?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/python/LibStorage.i (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/python/LibStorage.i Tue May 17 13:39:44 2011
@@ -6,23 +6,29 @@
%{
#include "../../src/StorageInterface.h"
+#include "../../src/HumanString.h"
+#include "../../src/Graph.h"
%}
using namespace std;
%include "std_string.i"
%include "std_deque.i"
+%include "std_list.i"
%typemap(out) std::string* {
- $result = PyString_FromString ($1->c_str ());
+ $result = PyString_FromString($1->c_str());
}
%include "../../src/StorageInterface.h"
+%include "../../src/HumanString.h"
+%include "../../src/Graph.h"
using namespace storage;
%template(dequestring) deque<string>;
%template(dequecontainerinfo) deque<ContainerInfo>;
%template(dequepartitioninfo) deque<PartitionInfo>;
+%template(dequemdinfo) deque<MdInfo>;
%template(dequelvmlvinfo) deque<LvmLvInfo>;
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/python/Makefile
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/python/Makefile?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/python/Makefile (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/python/Makefile Tue May 17 13:39:44 2011
@@ -9,8 +9,8 @@
LibStorage.pyo: LibStorage_wrap.cxx
python -O -c "import LibStorage"
-LibStorage_wrap.cxx: LibStorage.i ../../src/StorageInterface.h
+LibStorage_wrap.cxx: LibStorage.i ../../src/StorageInterface.h
swig -Wall -c++ -python LibStorage.i
- g++ -c -I/usr/include/python -O2 -fPIC -pipe LibStorage_wrap.cxx
- g++ -shared LibStorage_wrap.o -o _LibStorage.so -ly2storage
+ g++ -c -I/usr/include/python -I../../src -O2 -fPIC -pipe LibStorage_wrap.cxx
+ g++ -shared LibStorage_wrap.o -o _LibStorage.so -L../../src/.libs -ly2storage
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/ycp/LibStorage.i
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/ycp/LibStorage.i?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/ycp/LibStorage.i (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/bindings/ycp/LibStorage.i Tue May 17 13:39:44 2011
@@ -7,7 +7,12 @@
%include "LiMaL.i"
%{
+// workaround for bnc #593954
+#undef seed
+
#include "../../src/StorageInterface.h"
+#include "../../src/HumanString.h"
+#include "../../src/Graph.h"
%}
using namespace std;
@@ -37,8 +42,16 @@
specialize_sequence(storage::DmPartInfo, TO_PACK, FROM_PACK, CHECK)
specialize_sequence(storage::DmraidInfo, TO_PACK, FROM_PACK, CHECK)
specialize_sequence(storage::DmmultipathInfo, TO_PACK, FROM_PACK, CHECK)
+specialize_sequence(storage::BtrfsInfo, TO_PACK, FROM_PACK, CHECK)
+specialize_sequence(storage::TmpfsInfo, TO_PACK, FROM_PACK, CHECK)
specialize_sequence(storage::PartitionSlotInfo, TO_PACK, FROM_PACK, CHECK)
specialize_sequence(storage::CommitInfo, TO_PACK, FROM_PACK, CHECK)
+specialize_sequence(storage::ResizeInfo, TO_PACK, FROM_PACK, CHECK)
+specialize_sequence(storage::ContentInfo, TO_PACK, FROM_PACK, CHECK)
+
+specialize_sequence(storage::Environment, TO_PACK, FROM_PACK, CHECK)
%include "../../src/StorageInterface.h"
+%include "../../src/HumanString.h"
+%include "../../src/Graph.h"
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/Makefile.am?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/Makefile.am (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/Makefile.am Tue May 17 13:39:44 2011
@@ -9,7 +9,7 @@
AM_CXXFLAGS =
-noinst_PROGRAMS = TestDisk TestDiskLog TestStorage TestProbing TestLvm TestMd TestLoop TestLock
+noinst_PROGRAMS = TestDisk TestDiskLog TestStorage TestProbing TestLvm TestMd TestLoop TestLock SaveGraph ShowBytes
TestDisk_SOURCES = TestDisk.cc
@@ -27,9 +27,13 @@
TestLock_SOURCES = TestLock.cc
+SaveGraph_SOURCES = SaveGraph.cc
+
+ShowBytes_SOURCES = ShowBytes.cc
+
exampledir = $(docdir)/examples/libstorage
-example_DATA = TestDisk.cc TestDiskLog.cc TestProbing.cc TestLvm.cc TestMd.cc TestLoop.cc
+example_DATA = TestDisk.cc TestDiskLog.cc TestProbing.cc TestLvm.cc TestMd.cc TestLoop.cc SaveGraph.cc ShowBytes.cc
EXTRA_DIST = $(example_DATA) Makefile.example
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/SaveGraph.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/SaveGraph.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/SaveGraph.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/SaveGraph.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,27 @@
+
+#include
+#include <iostream>
+
+#include
+#include
+
+using namespace storage;
+using namespace std;
+
+int
+main (int argc, char** argv)
+{
+ initDefaultLogger();
+
+ StorageInterface* s = createStorageInterface(Environment(true));
+
+ saveDeviceGraph(s, "device.gv");
+ saveMountGraph(s, "mount.gv");
+
+ destroyStorageInterface(s);
+
+ cout << "run \"dot -T png -o device.png device.gv\" and "
+ "\"dot -T png -o mount.png mount.gv\" to generate pngs" << endl;
+
+ exit(EXIT_SUCCESS);
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/ShowBytes.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/ShowBytes.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/ShowBytes.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/ShowBytes.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,32 @@
+
+#include <iostream>
+
+#include
+
+using namespace storage;
+using namespace std;
+
+int
+main(int argc, char** argv)
+{
+ if (argc != 2)
+ {
+ cerr << "no value provided" << endl;
+ return 1;
+ }
+
+ locale::global(locale(""));
+
+ unsigned long long bytes = 0;
+ if (!humanStringToByte(argv[1], false, bytes))
+ {
+ cerr << "parsing value failed" << endl;
+ return 1;
+ }
+
+ cout << bytes << " " << getSuffix(0, false) << endl;
+
+ cout << byteToHumanString(bytes, false, 2, true) << endl;
+
+ return 0;
+}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLock.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLock.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLock.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLock.cc Tue May 17 13:39:44 2011
@@ -95,7 +95,7 @@
usage();
}
- Storage::initDefaultLogger();
+ initDefaultLogger();
cout << "pid is " << getpid() << endl;
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLoop.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLoop.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLoop.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLoop.cc Tue May 17 13:39:44 2011
@@ -1,17 +1,13 @@
#include <iostream>
-#include
-#include
-
#include
using namespace storage;
using namespace std;
-using namespace blocxx;
-void scrollbarCb( const string& id, unsigned cur, unsigned max )
+void progressbarCb( const string& id, unsigned cur, unsigned max )
{
- cout << "SCROLLBAR id:" << id << " cur:" << cur << " max:" << max << endl;
+ cout << "PROGRESSBAR id:" << id << " cur:" << cur << " max:" << max << endl;
}
void installInfoCb( const string& info )
@@ -20,12 +16,13 @@
}
void
-printCommitActions( StorageInterface* s )
- {
- deque<string> l = s->getCommitActions( false );
- for( deque<string>::iterator i=l.begin(); i!=l.end(); ++i )
- cout << *i << endl;
- }
+printCommitActions(StorageInterface* s)
+{
+ list<CommitInfo> l;
+ s->getCommitInfos(l);
+ for (list<CommitInfo>::iterator i=l.begin(); i!=l.end(); ++i)
+ cout << i->text << endl;
+}
int doCommit( StorageInterface* s )
{
@@ -50,7 +47,7 @@
int ret = 0;
initDefaultLogger();
StorageInterface* s = createStorageInterface(Environment(false));
- s->setCallbackProgressBar( scrollbarCb );
+ s->setCallbackProgressBar( progressbarCb );
s->setCallbackShowInstallInfo( installInfoCb );
string disk = "/dev/hdb";
string device;
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLvm.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLvm.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLvm.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestLvm.cc Tue May 17 13:39:44 2011
@@ -7,11 +7,10 @@
using namespace storage;
using namespace std;
-using namespace blocxx;
-void scrollbarCb( const string& id, unsigned cur, unsigned max )
+void progressbarCb( const string& id, unsigned cur, unsigned max )
{
- cout << "SCROLLBAR id:" << id << " cur:" << cur << " max:" << max << endl;
+ cout << "PROGRESSBAR id:" << id << " cur:" << cur << " max:" << max << endl;
}
void installInfoCb( const string& info )
@@ -20,12 +19,13 @@
}
void
-printCommitActions( StorageInterface* s )
- {
- deque<string> l = s->getCommitActions( false );
- for( deque<string>::iterator i=l.begin(); i!=l.end(); ++i )
- cout << *i << endl;
- }
+printCommitActions(StorageInterface* s)
+{
+ list<CommitInfo> l;
+ s->getCommitInfos(l);
+ for (list<CommitInfo>::iterator i=l.begin(); i!=l.end(); ++i)
+ cout << i->text << endl;
+}
int doCommit( StorageInterface* s )
{
@@ -48,7 +48,7 @@
int ret = 0;
initDefaultLogger();
StorageInterface* s = createStorageInterface(Environment(false));
- s->setCallbackProgressBar( scrollbarCb );
+ s->setCallbackProgressBar( progressbarCb );
s->setCallbackShowInstallInfo( installInfoCb );
string disk = "/dev/hdb";
string device;
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestMd.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestMd.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestMd.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestMd.cc Tue May 17 13:39:44 2011
@@ -7,11 +7,10 @@
using namespace storage;
using namespace std;
-using namespace blocxx;
-void scrollbarCb( const string& id, unsigned cur, unsigned max )
+void progressbarCb( const string& id, unsigned cur, unsigned max )
{
- cout << "SCROLLBAR id:" << id << " cur:" << cur << " max:" << max << endl;
+ cout << "PROGRESSBAR id:" << id << " cur:" << cur << " max:" << max << endl;
}
void installInfoCb( const string& info )
@@ -20,12 +19,13 @@
}
void
-printCommitActions( StorageInterface* s )
- {
- deque<string> l = s->getCommitActions( false );
- for( deque<string>::iterator i=l.begin(); i!=l.end(); ++i )
- cout << *i << endl;
- }
+printCommitActions(StorageInterface* s)
+{
+ list<CommitInfo> l;
+ s->getCommitInfos(l);
+ for (list<CommitInfo>::iterator i=l.begin(); i!=l.end(); ++i)
+ cout << i->text << endl;
+}
int doCommit( StorageInterface* s )
{
@@ -50,7 +50,7 @@
int ret = 0;
initDefaultLogger();
StorageInterface* s = createStorageInterface(Environment(false));
- s->setCallbackProgressBar( scrollbarCb );
+ s->setCallbackProgressBar( progressbarCb );
s->setCallbackShowInstallInfo( installInfoCb );
string disk = "/dev/hdb";
string device;
@@ -80,49 +80,49 @@
}
if( ret==0 )
{
- deque<string> ds;
+ list<string> ds;
ds.push_back( "/dev/hdb5" );
ds.push_back( "/dev/hdb6" );
ds.push_back( "/dev/hdb7" );
- ret = s->createMd( "md0", RAID0, ds );
+ ret = s->createMd("md0", RAID0, ds, list<string>());
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
- deque<string> ds;
+ list<string> ds;
ds.push_back( "/dev/hdb8" );
ds.push_back( "/dev/hdb9" );
- ret = s->createMdAny( RAID1, ds, device );
+ ret = s->createMdAny(RAID1, ds, list<string>(), device);
cout << "device:" << device << endl;
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
- deque<string> ds;
+ list<string> ds;
ds.push_back( "/dev/hdb10" );
ds.push_back( "/dev/hdb11" );
ds.push_back( "/dev/hdb12" );
- ret = s->createMd( "/dev/md2", RAID5, ds );
+ ret = s->createMd("/dev/md2", RAID5, ds, list<string>());
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
- deque<string> ds;
+ list<string> ds;
ds.push_back( "/dev/hdb13" );
ds.push_back( "/dev/hdb14" );
ds.push_back( "/dev/hdb15" );
ds.push_back( "/dev/hdb16" );
- ret = s->createMd( "/dev/md3", RAID6, ds );
+ ret = s->createMd("/dev/md3", RAID6, ds, list<string>());
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
- deque<string> ds;
+ list<string> ds;
ds.push_back( "/dev/hdb17" );
ds.push_back( "/dev/hdb18" );
ds.push_back( "/dev/hdb19" );
ds.push_back( "/dev/hdb1" );
- ret = s->createMd( "/dev/md4", RAID10, ds );
+ ret = s->createMd("/dev/md4", RAID10, ds, list<string>());
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestProbing.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestProbing.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestProbing.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestProbing.cc Tue May 17 13:39:44 2011
@@ -19,13 +19,14 @@
main (int argc, char** argv)
{
initDefaultLogger();
- StorageInterface* s = createStorageInterface(Environment(false));
+
+ StorageInterface* s = createStorageInterface(Environment(true));
deque<ContainerInfo> containers;
s->getContainers (containers);
- for (deque<ContainerInfo>::iterator i1 = containers.begin ();
- i1 != containers.end(); i1++)
+ for (deque<ContainerInfo>::const_iterator i1 = containers.begin();
+ i1 != containers.end(); ++i1)
{
switch (i1->type)
{
@@ -40,8 +41,8 @@
exit (EXIT_FAILURE);
}
- for (deque<PartitionInfo>::iterator i2 = partitions.begin ();
- i2 != partitions.end(); i2++)
+ for (deque<PartitionInfo>::const_iterator i2 = partitions.begin();
+ i2 != partitions.end(); ++i2)
{
cout << " " << i2->v.name << ' ';
switch (i2->partitionType)
@@ -57,6 +58,8 @@
case REISERFS: cout << "REISERFS"; break;
case EXT2: cout << "EXT2"; break;
case EXT3: cout << "EXT3"; break;
+ case EXT4: cout << "EXT4"; break;
+ case BTRFS: cout << "BTRFS"; break;
case VFAT: cout << "VFAT"; break;
case XFS: cout << "XFS"; break;
case JFS: cout << "JFS"; break;
@@ -65,6 +68,8 @@
case NTFS: cout << "NTFS"; break;
case SWAP: cout << "SWAP"; break;
case NFS: cout << "NFS"; break;
+ case NFS4: cout << "NFS4"; break;
+ case TMPFS: cout << "TMPFS"; break;
case FSNONE: cout << "NONE"; break;
}
cout << '\n';
@@ -72,6 +77,26 @@
} break;
+ case MD:
+ {
+ cout << "found special container (md) " << i1->name << '\n';
+
+ deque<MdInfo> mds;
+ if (s->getMdInfo(mds) != 0)
+ {
+ cerr << "getMdInfo failed\n";
+ exit (EXIT_FAILURE);
+ }
+
+ for (deque<MdInfo>::const_iterator i2 = mds.begin();
+ i2 != mds.end(); ++i2)
+ {
+ cout << " " << i2->v.name;
+ cout << '\n';
+ }
+
+ } break;
+
case LVM: {
cout << "found container (lvm) " << i1->name << '\n';
@@ -83,8 +108,8 @@
exit (EXIT_FAILURE);
}
- for (deque<LvmLvInfo>::iterator i2 = lvmlvs.begin ();
- i2 != lvmlvs.end(); i2++)
+ for (deque<LvmLvInfo>::const_iterator i2 = lvmlvs.begin();
+ i2 != lvmlvs.end(); ++i2)
{
cout << " " << i2->v.name;
cout << '\n';
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestStorage.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestStorage.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestStorage.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/examples/TestStorage.cc Tue May 17 13:39:44 2011
@@ -10,13 +10,14 @@
using namespace std;
using namespace storage;
-struct test_hdb { bool operator()(const Container&d) const {return( d.name().find( "hdb" )!=string::npos);}};
+struct test_sdb { bool operator()(const Container&d) const {return( d.name().find( "sdb" )!=string::npos);}};
+struct NotDeleted { bool operator()(const Container& d) const { return !d.deleted(); } };
struct Smaller5 { bool operator()(const Volume&d) const {return(d.nr()<5);}};
-struct Smaller150 { bool operator()(const Disk&d) const {return(d.cylinders()<150);}};
-struct Larger150 { bool operator()(const Disk&d) const {return(d.cylinders()>150);}};
+struct Smaller20000 { bool operator()(const Disk&d) const {return(d.cylinders()<20000);}};
+struct Larger20000 { bool operator()(const Disk&d) const {return(d.cylinders()>20000);}};
struct Equal150 { bool operator()(const Disk&d) const {return(d.cylinders()==150);}};
struct Larger10 { bool operator()(const Partition&d) const {return(d.cylSize()>10);}};
-struct DiskStart { bool operator()(const Partition&d) const {return(d.cylStart()==1);}};
+struct DiskStart { bool operator()(const Partition&d) const {return(d.cylStart()==0);}};
template <class C> struct First
{ bool operator()(const C&d) const {return(d.nr()==0);}};
@@ -54,29 +55,29 @@
int
main( int argc_iv, char** argv_ppcv )
{
- Storage::initDefaultLogger();
+ initDefaultLogger();
Storage Sto(Environment(true));
+ Sto.assertInit();
for( Storage::ConstContIterator i=Sto.contBegin(); i!=Sto.contEnd(); ++i )
{
cout << *i << endl;
}
{
- struct test_hdb t;
- Storage::ContCondIPair::type p=Sto.contCondPair(t);
- cout << "test_hdb pair empty:" << p.empty() << " length:" << p.length() << endl;
- for( Storage::ConstContainerI::type i=p.begin(); i!=p.end(); ++i )
+ struct test_sdb t;
+ Storage::ContCondIPair::type p=Sto.contCondPair(t);
+ cout << "test_sdb pair empty:" << p.empty() << " length:" << p.length() << endl;
+ for( Storage::ConstContainerI::type i=p.begin(); i!=p.end(); ++i )
{
cout << *i << endl;
}
}
{
- Storage::ContCondIPairStorage::SkipDeleted::type p =
- Sto.contCondPairStorage::SkipDeleted( Storage::SkipDel );
- cout << "SkipDeleted pair empty:" << p.empty() << " length:" << p.length() << endl;
- for( Storage::ConstContainerIStorage::SkipDeleted::type i=p.begin();
- i!=p.end(); ++i )
+ NotDeleted NotDel;
+ Storage::ContCondIPair<NotDeleted>::type p = Sto.contCondPair<NotDeleted>(NotDel);
+ cout << "NotDeleted pair empty:" << p.empty() << " length:" << p.length() << endl;
+ for (Storage::ConstContainerI<NotDeleted>::type i = p.begin(); i != p.end(); ++i)
{
- cout << *i << endl;
+ cout << *i << endl;
}
}
struct tmp {
@@ -115,7 +116,7 @@
{
cout << *i << endl;
}
- p = Sto.contPair( Storage::notDeleted );
+ p = Sto.contPair( Container::notDeleted );
cout << "not deleted empty:" << p.empty() << " length:" << p.length() << endl;
for( Storage::ConstContIterator i=p.begin(); i!=p.end(); ++i )
{
@@ -161,7 +162,9 @@
Storage::ConstVolIterator j = i;
//cout << endl << "type(j)=" << typeid(j).name() << endl;
//cout << "type(--j)=" << typeid(--j).name() << endl;
- cout << " P Name:" << (*--j).device() << endl;
+ if( j!=p.begin() )
+ cout << " P Name:" << (*--j).device();
+ cout << endl;
}
cout << "Inverted order" << endl;
for( Storage::ConstVolIterator i=p.end(); i!=p.begin(); )
@@ -169,11 +172,11 @@
--i;
cout << *i << endl;
}
- p = Sto.volPair( Storage::notDeleted );
+ p = Sto.volPair( Container::notDeleted );
PrintPairStorage::ConstVolPair( cout, p, "All Volumes on undel disks\n" );
p = Sto.volPair( tmp::TestIsEven );
PrintPairStorage::ConstVolPair( cout, p, "All Volumes with even numbers\n" );
- p = Sto.volPair( tmp::TestIsEven, Storage::notDeleted );
+ p = Sto.volPair( tmp::TestIsEven, Container::notDeleted );
PrintPairStorage::ConstVolPair( cout, p, "All Volumes with even numbers on undel disks\n" );
cout << "Inverted order" << endl;
for( Storage::ConstVolIterator i=p.end(); i!=p.begin(); )
@@ -191,27 +194,27 @@
Storage::ConstDiskPair p = Sto.diskPair();
PrintPairStorage::ConstDiskPair( cout, p, "Disks " );
struct tmp {
- static bool TestLarger150( const Disk& d )
- { return( d.cylinders()>150 ); };
- static bool TestSmaller150( const Disk& d )
- { return( d.cylinders()<150 ); };
+ static bool TestLarger20000( const Disk& d )
+ { return( d.cylinders()>20000 ); };
+ static bool TestSmaller20000( const Disk& d )
+ { return( d.cylinders()<20000 ); };
static bool TestEqual150( const Disk& d )
{ return( d.cylinders()==150 ); };
};
- p = Sto.diskPair(tmp::TestLarger150);
- PrintPairStorage::ConstDiskPair( cout, p, "Disks >150 " );
- p = Sto.diskPair(tmp::TestSmaller150);
- PrintPairStorage::ConstDiskPair( cout, p, "Disks <150 " );
+ p = Sto.diskPair(tmp::TestLarger20000);
+ PrintPairStorage::ConstDiskPair( cout, p, "Disks >20000 " );
+ p = Sto.diskPair(tmp::TestSmaller20000);
+ PrintPairStorage::ConstDiskPair( cout, p, "Disks <20000 " );
p = Sto.diskPair(tmp::TestEqual150);
PrintPairStorage::ConstDiskPair( cout, p, "Disks ==150 " );
}
{
- Storage::DiskCondIPair<Larger150>::type p = Sto.diskCondPair<Larger150>( Larger150() );
- PrintPair( cout, p, "Disks >150 " );
+ Storage::DiskCondIPair<Larger20000>::type p = Sto.diskCondPair<Larger20000>( Larger20000() );
+ PrintPair( cout, p, "Disks >20000 " );
}
{
- Storage::DiskCondIPair<Smaller150>::type p = Sto.diskCondPair<Smaller150>( Smaller150() );
- PrintPair( cout, p, "Disks <150 " );
+ Storage::DiskCondIPair<Smaller20000>::type p = Sto.diskCondPair<Smaller20000>( Smaller20000() );
+ PrintPair( cout, p, "Disks <20000 " );
}
{
Storage::DiskCondIPair<Equal150>::type p = Sto.diskCondPair<Equal150>( Equal150() );
@@ -222,7 +225,7 @@
PrintPairStorage::ConstPartPair( cout, p, "Part " );
struct tmp {
static bool TestStart( const Partition& d )
- { return( d.cylStart()==1 ); };
+ { return( d.cylStart()==0 ); };
static bool TestLarger10( const Partition& d )
{ return( d.cylSize()>10 ); };
};
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AppUtil.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AppUtil.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AppUtil.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AppUtil.cc Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -19,19 +19,18 @@
* find current contact information at www.novell.com.
*/
-// Maintainer: fehr@suse.de
-/*
- Textdomain "storage"
-*/
-
+#include
+#include
#include
-#include <string>
+#include
+#include
#include
+#include
#include
+#include
#include
-
-#include <locale>
+#include <string>
#include
#include
@@ -39,89 +38,31 @@
#include
#include
-#include "y2storage/AsciiFile.h"
-#include "y2storage/StorageTmpl.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/SystemCmd.h"
+#include "storage/AsciiFile.h"
+#include "storage/StorageTmpl.h"
+#include "storage/AppUtil.h"
+#include "storage/StorageTypes.h"
-using namespace std;
namespace storage
{
-
-string dupDash(const string& s)
- {
- string ret(s);
- string::size_type pos = ret.find("-");
- while(pos!=string::npos)
- {
- ret.insert(pos,1,'-');
- pos = ret.find("-",pos+2);
- }
- return(ret);
- }
-
-bool
-searchFile(AsciiFile& File_Cr, string Pat_Cv, string& Line_Cr)
-{
- int LineNr_ii = 0;
- return searchFile(File_Cr, Pat_Cv, Line_Cr, LineNr_ii);
-}
-
-bool
-searchFile(AsciiFile& File_Cr, string Pat_Cv, string& Line_Cr, int& LineNr_ir)
-{
- int End_ii;
- bool Found_bi = false;
- bool BeginOfLine_bi;
- string Tmp_Ci;
- int LineNr_ii;
- string Search_Ci(Pat_Cv);
-
- BeginOfLine_bi = Search_Ci.length() > 0 && Search_Ci[0] == '^';
- if (BeginOfLine_bi)
- Search_Ci.erase(0, 1);
- End_ii = File_Cr.numLines();
- LineNr_ii = LineNr_ir;
- while (!Found_bi && LineNr_ii < End_ii)
- {
- string::size_type Idx_ii;
-
- Tmp_Ci = File_Cr[LineNr_ii++];
- Idx_ii = Tmp_Ci.find(Search_Ci);
- if (Idx_ii != string::npos)
- {
- if (BeginOfLine_bi)
- Found_bi = Idx_ii == 0;
- else
- Found_bi = true;
- }
- }
- if (Found_bi)
- {
- Line_Cr = Tmp_Ci;
- LineNr_ir = LineNr_ii - 1;
- }
- return Found_bi;
-}
+ using namespace std;
-void createPath(string Path_Cv)
+void createPath(const string& Path_Cv)
{
- string Path_Ci = Path_Cv;
- string Tmp_Ci;
-
string::size_type Pos_ii = 0;
- while ((Pos_ii = Path_Ci.find('/', Pos_ii + 1)) != string::npos)
+ while ((Pos_ii = Path_Cv.find('/', Pos_ii + 1)) != string::npos)
{
- Tmp_Ci = Path_Ci.substr(0, Pos_ii);
+ string Tmp_Ci = Path_Cv.substr(0, Pos_ii);
mkdir(Tmp_Ci.c_str(), 0777);
}
- mkdir(Path_Ci.c_str(), 0777);
+ mkdir(Path_Cv.c_str(), 0777);
}
+
bool
-checkDir(string Path_Cv)
+checkDir(const string& Path_Cv)
{
struct stat Stat_ri;
@@ -129,26 +70,33 @@
S_ISDIR(Stat_ri.st_mode));
}
+
bool
-checkSymlink(string Path_Cv)
+getStatMode(const string& Path_Cv, mode_t& val )
{
struct stat Stat_ri;
+ int ret_ii = stat(Path_Cv.c_str(), &Stat_ri);
+
+ if( ret_ii==0 )
+ val = Stat_ri.st_mode;
+ else
+ y2mil( "stat " << Path_Cv << " ret:" << ret_ii );
- return (lstat(Path_Cv.c_str(), &Stat_ri) >= 0 &&
- S_ISLNK(Stat_ri.st_mode));
+ return (ret_ii==0);
}
bool
-checkBlockDevice(string Path_Cv)
+setStatMode(const string& Path_Cv, mode_t val )
{
- struct stat Stat_ri;
-
- return (stat(Path_Cv.c_str(), &Stat_ri) >= 0 &&
- S_ISBLK(Stat_ri.st_mode));
+ int ret_ii = chmod( Path_Cv.c_str(), val );
+ if( ret_ii!=0 )
+ y2mil( "chmod " << Path_Cv << " ret:" << ret_ii );
+ return( ret_ii==0 );
}
+
bool
-checkNormalFile(string Path_Cv)
+checkNormalFile(const string& Path_Cv)
{
struct stat Stat_ri;
@@ -156,6 +104,71 @@
S_ISREG(Stat_ri.st_mode));
}
+
+ list<string>
+ glob(const string& path, int flags)
+ {
+ list<string> ret;
+
+ glob_t globbuf;
+ if (glob(path.c_str(), flags, 0, &globbuf) == 0)
+ {
+ for (char** p = globbuf.gl_pathv; *p != 0; p++)
+ ret.push_back(*p);
+ }
+ globfree (&globbuf);
+
+ return ret;
+ }
+
+
+ bool
+ getStatVfs(const string& path, StatVfs& buf)
+ {
+ struct statvfs64 fsbuf;
+ if (statvfs64(path.c_str(), &fsbuf) != 0)
+ {
+ buf.sizeK = buf.freeK = 0;
+
+ y2err("errno:" << errno << " " << strerror(errno));
+ return false;
+ }
+
+ buf.sizeK = fsbuf.f_blocks;
+ buf.sizeK *= fsbuf.f_bsize;
+ buf.sizeK /= 1024;
+
+ buf.freeK = fsbuf.f_bfree;
+ buf.freeK *= fsbuf.f_bsize;
+ buf.freeK /= 1024;
+
+ y2mil("blocks:" << fsbuf.f_blocks << " bfree:" << fsbuf.f_bfree <<
+ " bsize:" << fsbuf.f_bsize << " sizeK:" << buf.sizeK <<
+ " freeK:" << buf.freeK);
+ return true;
+ }
+
+
+ bool
+ getMajorMinor(const string& device, unsigned long& major, unsigned long& minor)
+ {
+ bool ret = false;
+ string dev = normalizeDevice(device);
+ struct stat sbuf;
+ if (stat(device.c_str(), &sbuf) == 0)
+ {
+ major = gnu_dev_major(sbuf.st_rdev);
+ minor = gnu_dev_minor(sbuf.st_rdev);
+ ret = true;
+ }
+ else
+ {
+ y2err("stat for " << device << " failed errno:" << errno << " (" << strerror(errno) << ")");
+ }
+ return ret;
+ }
+
+
string extractNthWord(int Num_iv, const string& Line_Cv, bool GetRest_bi)
{
string::size_type pos;
@@ -249,13 +262,6 @@
}
-string
-mergeString(const list<string>& l, const string& del)
-{
- return boost::join(l, del);
-}
-
-
map
makeMap( const list<string>& l, const string& delim, const string& removeSur )
{
@@ -289,44 +295,42 @@
}
-string normalizeDevice( const string& dev )
+ string normalizeDevice(const string& dev)
{
- string ret( dev );
- normalizeDevice( ret );
- return( ret );
+ if (!boost::starts_with(dev, "/dev/") && !isNfsDev(dev))
+ return "/dev/" + dev;
+ return dev;
}
-bool isNfsDev( const string& dev )
- {
- return( !dev.empty() && dev[0]!='/' &&
- dev.find( ':' )!=string::npos );
- }
-void normalizeDevice( string& dev )
+ list<string> normalizeDevices(const list<string>& devs)
{
- if( dev.find( "/dev/" )!=0 && !isNfsDev(dev) )
- dev = "/dev/" + dev;
+ list<string> ret;
+ for (list<string>::const_iterator it = devs.begin(); it != devs.end(); ++it)
+ ret.push_back(normalizeDevice(*it));
+ return ret;
}
-string undevDevice( const string& dev )
+
+bool isNfsDev( const string& dev )
{
- string ret( dev );
- undevDevice( ret );
- return( ret );
+ return( !dev.empty() && dev[0]!='/' &&
+ dev.find( ':' )!=string::npos );
}
-void undevDevice( string& dev )
+
+ string undevDevice(const string& dev)
{
- if( dev.find( "/dev/" )==0 )
- dev.erase( 0, 5 );
+ if (boost::starts_with(dev, "/dev/"))
+ return string(dev, 5);
+ return dev;
}
static const blocxx::String component = "libstorage";
-void createLogger(const string& lcomponent, const string& name,
- const string& logpath, const string& logfile)
+void createLogger(const string& name, const string& logpath, const string& logfile)
{
using namespace blocxx;
@@ -398,16 +402,26 @@
void
-prepareLogStream(std::ostringstream& s)
+prepareLogStream(ostringstream& stream)
{
- s.imbue(std::locale::classic());
- s.setf(std::ios::showbase);
+ stream.imbue(std::locale::classic());
+ stream.setf(std::ios::boolalpha);
+ stream.setf(std::ios::showbase);
+}
+
+
+ostringstream*
+logStreamOpen()
+{
+ std::ostringstream* stream = new ostringstream;
+ prepareLogStream(*stream);
+ return stream;
}
void
-logMsg(LogLevel level, const char* file, unsigned line, const char* func,
- const string& str)
+logStreamClose(LogLevel level, const char* file, unsigned line, const char* func,
+ ostringstream* stream)
{
using namespace blocxx;
@@ -440,32 +454,99 @@
if (!category.empty())
{
- LogAppender::getCurrentLogAppender()->logMessage(LogMessage(component, category,
- String(str), file,
- line, func));
+ string tmp = stream->str();
+
+ string::size_type pos1 = 0;
+
+ while (true)
+ {
+ string::size_type pos2 = tmp.find('\n', pos1);
+
+ if (pos2 != string::npos || pos1 != tmp.length())
+ LogAppender::getCurrentLogAppender()->logMessage(LogMessage(component, category,
+ String(tmp.substr(pos1, pos2 - pos1)),
+ file, line, func));
+
+ if (pos2 == string::npos)
+ break;
+
+ pos1 = pos2 + 1;
+ }
}
+
+ delete stream;
}
-void
-logMsgVaArgs(LogLevel level, const char* file, unsigned line, const char* func,
- const char* format, ...)
-{
- if (testLogLevel(level))
+ string
+ udevAppendPart(const string& s, unsigned num)
{
- char* str;
- va_list ap;
+ return s + "-part" + decString(num);
+ }
- va_start(ap, format);
- if (vasprintf(&str, format, ap) == -1)
- return;
- va_end(ap);
- logMsg(level, file, line, func, str);
+ string
+ udevEncode(const string& s)
+ {
+ string r = s;
- free(str);
+ string::size_type pos = 0;
+
+ while (true)
+ {
+ pos = r.find_first_of(" '\\/", pos);
+ if (pos == string::npos)
+ break;
+
+ char tmp[16];
+ sprintf(tmp, "\\x%02x", r[pos]);
+ r.replace(pos, 1, tmp);
+
+ pos += 4;
+ }
+
+ return r;
+ }
+
+
+ string
+ udevDecode(const string& s)
+ {
+ string r = s;
+
+ string::size_type pos = 0;
+
+ while (true)
+ {
+ pos = r.find("\\x", pos);
+ if (pos == string::npos || pos > r.size() - 4)
+ break;
+
+ unsigned int tmp;
+ if (sscanf(r.substr(pos + 2, 2).c_str(), "%x", &tmp) == 1)
+ r.replace(pos, 4, 1, (char) tmp);
+
+ pos += 1;
+ }
+
+ return r;
+ }
+
+
+ bool
+ mkdtemp(string& path)
+ {
+ char* tmp = strdup(path.c_str());
+ if (!::mkdtemp(tmp))
+ {
+ free(tmp);
+ return false;
+ }
+
+ path = tmp;
+ free(tmp);
+ return true;
}
-}
bool
@@ -479,232 +560,191 @@
}
- string
- udevAppendPart(const string& s, unsigned num)
+ bool
+ readlinkat(int fd, const string& path, string& buf)
{
- return s + "-part" + decString(num);
+ char tmp[1024];
+ int count = ::readlinkat(fd, path.c_str(), tmp, sizeof(tmp));
+ if (count >= 0)
+ buf = string(tmp, count);
+ return count != -1;
}
-map
-getUdevLinks(const char* path)
-{
- map links;
-
- DIR* dir;
- if ((dir = opendir(path)) != NULL)
+ map
+ getUdevLinks(const char* path)
{
- struct dirent* entry;
- while ((entry = readdir(dir)) != NULL)
- {
- if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
- continue;
+ map links;
- string full = string(path) + "/" + entry->d_name;
+ int fd = open(path, O_RDONLY);
+ if (fd >= 0)
+ {
+ DIR* dir;
+ if ((dir = fdopendir(fd)) != NULL)
+ {
+ struct dirent* entry;
+ while ((entry = readdir(dir)) != NULL)
+ {
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
+ continue;
- string tmp;
- if (readlink(full, tmp))
+ string tmp;
+ if (!readlinkat(fd, entry->d_name, tmp))
+ continue;
+
+ string::size_type pos = tmp.find_first_not_of("./");
+ if (pos != string::npos)
+ links[udevDecode(entry->d_name)] = tmp.substr(pos);
+ }
+ closedir(dir);
+ }
+ else
{
- string::size_type pos = tmp.find_first_not_of("./");
- if (pos != string::npos)
- links[entry->d_name] = tmp.substr(pos);
+ close(fd);
}
}
- closedir(dir);
- }
- return links;
-}
+ return links;
+ }
-void
-getUdevMap(const char* path, map& m)
-{
- y2mil( "path: " << path );
+ UdevMap::UdevMap(const string& path)
+ {
+ y2mil("path: " << path);
- map links = getUdevLinks(path);
+ const map links = getUdevLinks(path.c_str());
- m.clear();
- for (map::const_iterator it = links.begin(); it != links.end(); it++)
- m[it->second].push_back(it->first);
+ for (map::const_iterator it = links.begin(); it != links.end(); ++it)
+ data[it->second].push_back(it->first);
- y2mil("map: " << m);
-}
+ for (const_iterator it = begin(); it != end(); ++it)
+ y2mil("data[" << it->first << "] -> " << boost::join(it->second, " "));
+ }
-void
-getRevUdevMap(const char* path, map& m)
+unsigned
+getMajorDevices(const char* driver)
{
- y2mil("path: " << path);
+ unsigned ret = 0;
+
+ AsciiFile file("/proc/devices");
+ const vector<string>& lines = file.lines();
+
+ Regex rx("^" + Regex::ws + "([0-9]+)" + Regex::ws + string(driver) + "$");
- m = getUdevLinks(path);
+ if (find_if(lines, regex_matches(rx)) != lines.end())
+ rx.cap(1) >> ret;
+ else
+ y2err("did not find " << driver << " in /proc/devices");
- y2mil("map: " << m);
+ y2mil("driver:" << driver << " ret:" << ret);
+ return ret;
}
-unsigned getMajorDevices( const string& driver )
+ void
+ Text::clear()
{
- unsigned ret=0;
- string cmd = "grep \" " + driver + "$\" /proc/devices";
- SystemCmd c( cmd );
- if( c.numLines()>0 )
- {
- extractNthWord( 0, *c.getLine(0)) >> ret;
- }
- y2mil( "driver:" << driver << " ret:" << ret );
- return( ret );
+ native.clear();
+ text.clear();
}
-string sformat(const char* format, ...)
-{
- char* result;
- va_list ap;
+ const Text&
+ Text::operator+=(const Text& a)
+ {
+ native += a.native;
+ text += a.text;
+ return *this;
+ }
- va_start(ap, format);
- if (vasprintf(&result, format, ap) == -1)
- return string();
- va_end(ap);
- string str(result);
- free(result);
- return str;
-}
+ string
+ sformat(const string& format, va_list ap)
+ {
+ char* result;
+ if (vasprintf(&result, format.c_str(), ap) == -1)
+ return string();
-int
-numSuffixes()
-{
- return 6;
-}
+ string str(result);
+ free(result);
+ return str;
+ }
-string
-getSuffix(int i, bool classic, bool sloppy = false)
-{
- switch (i)
+ Text
+ sformat(const Text& format, ...)
{
- case 0:
- if (sloppy)
- return "";
- else
- /* Byte abbreviated */
- return classic ? "B" : _("B");
-
- case 1:
- if (sloppy)
- /* Kilo abbreviated */
- return classic ? "k" : _("k");
- else
- /* KiloByte abbreviated */
- return classic ? "kB" : _("kB");
-
- case 2:
- if (sloppy)
- /* Mega abbreviated */
- return classic ? "M" : _("M");
- else
- /* MegaByte abbreviated */
- return classic ? "MB" : _("MB");
+ Text text;
+ va_list ap;
- case 3:
- if (sloppy)
- /* Giga abbreviated */
- return classic ? "G" : _("G");
- else
- /* GigaByte abbreviated */
- return classic ? "GB" : _("GB");
+ va_start(ap, format);
+ text.native = sformat(format.native, ap);
+ va_end(ap);
- case 4:
- if (sloppy)
- /* Tera abbreviated */
- return classic ? "T" : _("T");
- else
- /* TeraByte abbreviated */
- return classic ? "TB" : _("TB");
+ va_start(ap, format);
+ text.text = sformat(format.text, ap);
+ va_end(ap);
- case 5:
- if (sloppy)
- /* Peta abbreviated */
- return classic ? "P" : _("P");
- else
- /* PetaByte abbreviated */
- return classic ? "PB" : _("PB");
+ return text;
}
- return string("error");
-}
-
-
-string
-byteToHumanString(unsigned long long size, bool classic, int precision, bool omit_zeroes)
-{
- const locale loc = classic ? locale::classic() : locale();
-
- double f = size;
- int i = 0;
- while (f >= 1024.0 && i + 1 < numSuffixes())
+ Text _(const char* msgid)
{
- f /= 1024.0;
- i++;
+ return Text(msgid, dgettext("libstorage", msgid));
}
- if (omit_zeroes && (f == (unsigned long long)(f)))
+ Text _(const char* msgid, const char* msgid_plural, unsigned long int n)
{
- precision = 0;
+ return Text(n == 1 ? msgid : msgid_plural, dngettext("libstorage", msgid, msgid_plural, n));
}
- ostringstream s;
- s.imbue(loc);
- s.setf(ios::fixed);
- s.precision(precision);
-
- s << f << ' ' << getSuffix(i, classic);
-
- return s.str();
-}
+ string
+ hostname()
+ {
+ struct utsname buf;
+ if (uname(&buf) != 0)
+ return string("unknown");
+ string hostname(buf.nodename);
+ if (strlen(buf.domainname) > 0)
+ hostname += "." + string(buf.domainname);
+ return hostname;
+ }
-bool
-humanStringToByte(const string& str, bool classic, unsigned long long& size)
-{
- const locale loc = classic ? locale::classic() : locale();
- const string str_trimmed = boost::trim_copy(str, loc);
+ string
+ datetime()
+ {
+ time_t t1 = time(NULL);
+ struct tm t2;
+ gmtime_r(&t1, &t2);
+ char buf[64 + 1];
+ if (strftime(buf, sizeof(buf), "%F %T %Z", &t2) == 0)
+ return string("unknown");
+ return string(buf);
+ }
- double f = 1.0;
- for (int i = 0; i < numSuffixes(); i++)
+ StopWatch::StopWatch()
{
- for (int j = 0; j < (classic ? 1 : 2); j++)
- {
- string suffix = getSuffix(i, classic, j != 0);
- if (boost::iends_with(str_trimmed, suffix, loc))
- {
- string number = str_trimmed.substr(0, str_trimmed.size() - suffix.size());
+ gettimeofday(&start_tv, NULL);
+ }
- istringstream s(boost::trim_copy(number, loc));
- s.imbue(loc);
- double g;
- s >> g;
+ std::ostream& operator<<(std::ostream& s, const StopWatch& sw)
+ {
+ struct timeval stop_tv;
+ gettimeofday(&stop_tv, NULL);
- if (!s.fail() && s.eof() && g >= 0.0)
- {
- size = g * f;
- return true;
- }
- }
- }
+ struct timeval tv;
+ timersub(&stop_tv, &sw.start_tv, &tv);
- f *= 1024.0;
+ return s << fixed << double(tv.tv_sec) + (double)(tv.tv_usec) / 1000000.0 << "s";
}
- return false;
-}
-
const string app_ws = " \t\n";
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AppUtil.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AppUtil.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AppUtil.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AppUtil.h Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -23,55 +23,87 @@
#ifndef APP_UTIL_H
#define APP_UTIL_H
-#include
#include
-#include
-#include <cstdarg>
-#include <cstdio>
-#include <fstream>
+#include
+#include
#include <sstream>
#include <locale>
#include <string>
#include <list>
#include <map>
-using std::string;
namespace storage
{
+ using std::string;
+ using std::list;
+ using std::map;
-class AsciiFile;
-bool searchFile(AsciiFile& File_Cr, string Pat_Cv, string& Line_Cr);
-bool searchFile(AsciiFile& File_Cr, string Pat_Cv, string& Line_Cr,
- int& StartLine_ir);
-void createPath(string Path_Cv);
-bool checkNormalFile(string Path_Cv);
-bool checkDir(string Path_Cv);
+void createPath(const string& Path_Cv);
+bool checkNormalFile(const string& Path_Cv);
+bool checkDir(const string& Path_Cv);
+bool getStatMode(const string& Path_Cv, mode_t& val );
+bool setStatMode(const string& Path_Cv, mode_t val );
+
+ list<string> glob(const string& path, int flags);
+
+ struct StatVfs
+ {
+ unsigned long long sizeK;
+ unsigned long long freeK;
+ };
+
+ bool getStatVfs(const string& path, StatVfs&);
+
+ bool getMajorMinor(const string& device, unsigned long& major, unsigned long& minor);
+
-string dupDash(const string& s);
string extractNthWord(int Num_iv, const string& Line_Cv, bool GetRest_bi = false);
std::list<string> splitString( const string& s, const string& delChars=" \t\n",
bool multipleDelim=true, bool skipEmpty=true,
const string& quotes="" );
-string mergeString( const std::list<string>& l, const string& del=" " );
-std::map makeMap( const std::list<string>& l,
+std::map makeMap( const std::list<string>& l,
const string& delim = "=",
const string& removeSur = " \t\n" );
+ string udevAppendPart(const string&, unsigned num);
+
+ string udevEncode(const string&);
+ string udevDecode(const string&);
+
+ bool mkdtemp(string& path);
+
bool readlink(const string& path, string& buf);
- string udevAppendPart(const string&, unsigned num);
-void getUdevMap(const char* path, std::map& m);
-void getRevUdevMap(const char* path, std::map& m);
+ class UdevMap
+ {
+ public:
+
+ UdevMap(const string& path);
+
+ typedef map::const_iterator const_iterator;
+
+ const_iterator begin() const { return data.begin(); }
+ const_iterator end() const { return data.end(); }
+
+ const_iterator find(const string& nm) const { return data.find(nm); }
+
+ private:
+
+ map data;
+
+ };
+
+
+ string normalizeDevice(const string& dev);
+ list<string> normalizeDevices(const list<string>& devs);
+ string undevDevice(const string& dev);
-string normalizeDevice( const string& dev );
-void normalizeDevice( string& dev );
-string undevDevice( const string& dev );
-void undevDevice( string& dev );
bool isNfsDev( const string& dev );
-unsigned getMajorDevices( const string& driver );
+
+unsigned getMajorDevices(const char* driver);
template<class StreamType>
@@ -83,64 +115,71 @@
enum LogLevel { DEBUG, MILESTONE, WARNING, ERROR };
-void createLogger(const string& component, const string& name,
- const string& logpath, const string& logfile);
+void createLogger(const string& name, const string& logpath, const string& logfile);
bool testLogLevel(LogLevel level);
-void logMsg(LogLevel level, const char* file, unsigned line,
- const char* func, const string& str);
+void prepareLogStream(std::ostringstream& stream);
+
+std::ostringstream* logStreamOpen();
-void logMsgVaArgs(LogLevel level, const char* file, unsigned line,
- const char* func, const char* format, ...)
- __attribute__ ((format(printf, 5, 6)));
-
-void prepareLogStream(std::ostringstream& s);
-
-#define y2debug(format, ...) \
- logMsgVaArgs(storage::DEBUG, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
-#define y2milestone(format, ...) \
- logMsgVaArgs(storage::MILESTONE, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
-#define y2warning(format, ...) \
- logMsgVaArgs(storage::WARNING, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
-#define y2error(format, ...) \
- logMsgVaArgs(storage::ERROR, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
+void logStreamClose(LogLevel level, const char* file, unsigned line,
+ const char* func, std::ostringstream*);
#define y2deb(op) y2log_op(storage::DEBUG, __FILE__, __LINE__, __FUNCTION__, op)
#define y2mil(op) y2log_op(storage::MILESTONE, __FILE__, __LINE__, __FUNCTION__, op)
#define y2war(op) y2log_op(storage::WARNING, __FILE__, __LINE__, __FUNCTION__, op)
#define y2err(op) y2log_op(storage::ERROR, __FILE__, __LINE__, __FUNCTION__, op)
-#define y2log_op(level, file, line, function, op) \
+#define y2log_op(level, file, line, func, op) \
do { \
if (storage::testLogLevel(level)) \
{ \
- std::ostringstream __buf; \
- storage::prepareLogStream(__buf); \
- __buf << op; \
- storage::logMsg(level, file, line, function, __buf.str()); \
+ std::ostringstream* __buf = storage::logStreamOpen(); \
+ *__buf << op; \
+ storage::logStreamClose(level, file, line, func, __buf); \
} \
} while (0)
-string sformat(const char* format, ...);
+ string hostname();
+ string datetime();
-string byteToHumanString(unsigned long long size, bool classic, int precision,
- bool omit_zeroes);
+ class StopWatch
+ {
+ public:
-bool humanStringToByte(const string& str, bool classic, unsigned long long& size);
+ StopWatch();
+ friend std::ostream& operator<<(std::ostream& s, const StopWatch& sw);
-inline const char* _(const char* msgid)
-{
- return dgettext("storage", msgid);
-}
+ protected:
-inline const char* _(const char* msgid, const char* msgid_plural, unsigned long int n)
-{
- return dngettext("storage", msgid, msgid_plural, n);
-}
+ struct timeval start_tv;
+
+ };
+
+
+ struct Text
+ {
+ Text() : native(), text() {}
+ Text(const string& native, const string& text) : native(native), text(text) {}
+
+ void clear();
+
+ const Text& operator+=(const Text& a);
+
+ string native;
+ string text;
+ };
+
+
+ Text sformat(const Text& format, ...);
+
+
+ Text _(const char* msgid);
+ Text _(const char* msgid, const char* msgid_plural, unsigned long int n);
extern const string app_ws;
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ArchInfo.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ArchInfo.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ArchInfo.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ArchInfo.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include
+#include
+
+#include "storage/ArchInfo.h"
+#include "storage/AsciiFile.h"
+#include "storage/StorageTypes.h"
+
+
+namespace storage
+{
+
+ ArchInfo::ArchInfo()
+ : arch("i386"), is_ppc_mac(false), is_ppc_pegasos(false), is_efiboot(false)
+ {
+ }
+
+
+ void
+ ArchInfo::readData(const xmlNode* node)
+ {
+ getChildValue(node, "arch", arch);
+
+ if (!getChildValue(node, "efiboot", is_efiboot))
+ is_efiboot = false;
+ }
+
+
+ void
+ ArchInfo::saveData(xmlNode* node) const
+ {
+ setChildValue(node, "arch", arch);
+
+ if (is_efiboot)
+ setChildValue(node, "efiboot", is_efiboot);
+ }
+
+
+ void
+ ArchInfo::detect(bool instsys)
+ {
+ arch = "i386";
+ struct utsname buf;
+ if (uname(&buf) == 0)
+ {
+ if (strncmp(buf.machine, "ppc", 3) == 0)
+ {
+ arch = "ppc";
+ }
+ else if (strncmp(buf.machine, "x86_64", 5) == 0)
+ {
+ arch = "x86_64";
+ }
+ else if (strncmp(buf.machine, "ia64", 4) == 0)
+ {
+ arch = "ia64";
+ }
+ else if (strncmp(buf.machine, "s390", 4) == 0)
+ {
+ arch = "s390";
+ }
+ else if (strncmp(buf.machine, "sparc", 5) == 0)
+ {
+ arch = "sparc";
+ }
+ }
+
+ if (arch == "ppc")
+ {
+ AsciiFile cpuinfo("/proc/cpuinfo");
+ vector<string>::const_iterator it = find_if(cpuinfo.lines(), string_starts_with("machine\t"));
+ if (it != cpuinfo.lines().end())
+ {
+ y2mil("line:" << *it);
+
+ string tmp1 = extractNthWord(2, *it);
+ y2mil("tmp1:" << tmp1);
+ is_ppc_mac = boost::starts_with(tmp1, "PowerMac") || boost::starts_with(tmp1, "PowerBook");
+ is_ppc_pegasos = boost::starts_with(tmp1, "EFIKA5K2");
+
+ if (!is_ppc_mac && !is_ppc_pegasos)
+ {
+ string tmp2 = extractNthWord(3, *it);
+ y2mil("tmp2:" << tmp2);
+ is_ppc_pegasos = boost::starts_with(tmp2, "Pegasos");
+ }
+ }
+ }
+
+ if (arch == "ia64")
+ {
+ is_efiboot = true;
+ }
+ else
+ {
+ string val;
+ if (instsys)
+ {
+ InstallInfFile ii("/etc/install.inf");
+ if (ii.getValue("EFI", val))
+ is_efiboot = val == "1";
+ }
+ else
+ {
+ SysconfigFile sc("/etc/sysconfig/bootloader");
+ if (sc.getValue("LOADER_TYPE", val))
+ is_efiboot = val == "elilo";
+ }
+ }
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const ArchInfo& archinfo)
+ {
+ return s << "arch:" << archinfo.arch << " is_ppc_mac:" << archinfo.is_ppc_mac
+ << " is_ppc_pegasos:" << archinfo.is_ppc_pegasos << " is_efiboot:"
+ << archinfo.is_efiboot;
+ }
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ArchInfo.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ArchInfo.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ArchInfo.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ArchInfo.h Tue May 17 13:39:44 2011
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef ARCH_INFO_H
+#define ARCH_INFO_H
+
+
+#include "storage/XmlFile.h"
+
+
+namespace storage
+{
+
+ class ArchInfo
+ {
+ public:
+
+ ArchInfo();
+
+ void readData(const xmlNode* node);
+ void saveData(xmlNode* node) const;
+
+ void detect(bool instsys);
+
+ string arch;
+ bool is_ppc_mac;
+ bool is_ppc_pegasos;
+ bool is_efiboot;
+
+ };
+
+
+ std::ostream& operator<<(std::ostream& s, const ArchInfo& archinfo);
+
+}
+
+
+#endif
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AsciiFile.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AsciiFile.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AsciiFile.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AsciiFile.cc Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -19,80 +19,50 @@
* find current contact information at www.novell.com.
*/
-// Maintainer: fehr@suse.de
-/*
- Textdomain "storage"
-*/
#include
-#include
#include
#include <fstream>
-#include "y2storage/AppUtil.h"
-#include "y2storage/Regex.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/AsciiFile.h"
-
-using namespace std;
-using namespace storage;
+#include "storage/AppUtil.h"
+#include "storage/AsciiFile.h"
+#include "storage/StorageTypes.h"
-AsciiFile::AsciiFile( bool CreateBackup_bv, const char* BackupExt_Cv ) :
- BackupCreated_b(!CreateBackup_bv),
- BackupExtension_C( BackupExt_Cv )
+namespace storage
{
-}
+ using namespace std;
-AsciiFile::AsciiFile( const char* Name_Cv, bool CreateBackup_bv,
- const char* BackupExt_Cv ) :
- BackupCreated_b(!CreateBackup_bv),
- BackupExtension_C( BackupExt_Cv )
- {
- loadFile( Name_Cv );
- }
-AsciiFile::AsciiFile( const string& Name_Cv, bool CreateBackup_bv,
- const char* BackupExt_Cv ) :
- BackupCreated_b(!CreateBackup_bv),
- BackupExtension_C( BackupExt_Cv )
- {
- loadFile( Name_Cv.c_str() );
- }
-
-AsciiFile::~AsciiFile()
- {
- }
+AsciiFile::AsciiFile(const char* Name_Cv, bool remove_empty)
+ : Name_C(Name_Cv),
+ remove_empty(remove_empty)
+{
+ reload();
+}
-bool AsciiFile::loadFile( const string& Name_Cv )
- {
- bool Ret_bi;
- y2mil("Loading File:\"" << Name_Cv << "\"");
- Lines_C.clear();
- Ret_bi = appendFile( Name_Cv, Lines_C );
- Name_C = Name_Cv;
- return Ret_bi;
- }
+AsciiFile::AsciiFile(const string& Name_Cv, bool remove_empty)
+ : Name_C(Name_Cv),
+ remove_empty(remove_empty)
+{
+ reload();
+}
-const string& AsciiFile::fileName() const
- {
- return Name_C;
- }
-bool AsciiFile::appendFile( const string& Name_Cv )
+bool
+AsciiFile::reload()
+{
+ if (Name_C.empty())
{
- return appendFile( Name_Cv, Lines_C );
+ y2err("trying to load nameless AsciiFile");
+ return false;
}
-bool AsciiFile::appendFile( AsciiFile& File_Cv )
-{
- return appendFile( File_Cv, Lines_C );
-}
+ y2mil("loading file " << Name_C);
+ clear();
-bool AsciiFile::appendFile( const string& Name_Cv, vector<string>& Lines_Cr )
-{
- ifstream File_Ci( Name_Cv.c_str() );
+ ifstream File_Ci(Name_C.c_str());
classic(File_Ci);
string Line_Ci;
@@ -100,140 +70,55 @@
File_Ci.unsetf(ifstream::skipws);
getline( File_Ci, Line_Ci );
while( File_Ci.good() )
- {
- Lines_Cr.push_back( Line_Ci );
+ {
+ Lines_C.push_back( Line_Ci );
getline( File_Ci, Line_Ci );
- }
+ }
return Ret_bi;
}
-bool AsciiFile::appendFile( AsciiFile& File_Cv, vector<string>& Lines_Cr )
-{
- unsigned Idx_ii = 0;
-
- while( Idx_ii 0 && Text_Cr[Text_Cr.length() - 1] == Char_cv)
+ Text_Cr.erase(Text_Cr.length() - 1);
+}
+
+
+ bool
+ SysconfigFile::getValue(const string& key, string& value) const
{
- string::size_type Pos_ii;
- unsigned int Idx_ii = Start_iv;
- int Ret_ii = -1;
- string Pat_Ci = Pat_Cv;
- bool BeginOfLine_bi = Pat_Ci.length()>0 && Pat_Ci[0]=='^';
+ Regex rx('^' + Regex::ws + key + '=' + "(['\"]?)([^'\"]*)\\1" + Regex::ws + '$');
- if( BeginOfLine_bi )
- {
- Pat_Ci.erase( 0, 1 );
- }
- while( Ret_ii<0 && Idx_iiCnt_ii || File_Cv.numLines()>Cnt_ii )
- {
- Ret_ii = Cnt_ii;
- }
- return Ret_ii;
- }
+ if (find_if(lines(), regex_matches(rx)) == lines().end())
+ return false;
+ value = rx.cap(1);
+ y2mil("key:" << key << " value:" << value);
+ return true;
+ }
-void AsciiFile::removeLastIf (string& Text_Cr, char Char_cv) const
-{
- if (Text_Cr.length() > 0 && Text_Cr[Text_Cr.length() - 1] == Char_cv)
- Text_Cr.erase(Text_Cr.length() - 1);
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AsciiFile.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AsciiFile.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AsciiFile.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/AsciiFile.h Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -23,63 +23,93 @@
#ifndef ASCII_FILE_H
#define ASCII_FILE_H
+
+#include <string>
#include <vector>
-#include <list>
+#include <algorithm>
-using std::string;
namespace storage
{
-
-class Regex;
+ using std::string;
+ using std::vector;
-class AsciiFile
+ class AsciiFile
{
public:
- AsciiFile( bool CreateBackup_bv=false,
- const char* BackupExt_Cv=".orig" );
- AsciiFile( const string& Name_Cv, bool CreateBackup_bv=false,
- const char* BackupExt_Cv=".orig" );
- AsciiFile( const char* Name_Cv, bool CreateBackup_bv=false,
- const char* BackupExt_Cv=".orig" );
- ~AsciiFile();
- bool insertFile( AsciiFile& File_Cv, unsigned int BeforeLine_iv=0 );
- bool appendFile( AsciiFile& File_Cv );
- bool insertFile( const string& Name_Cv, unsigned int BeforeLine_iv=0 );
- bool appendFile( const string& Name_Cv );
- bool loadFile( const string& Name_Cv );
- bool updateFile();
- bool saveToFile( const string& Name_Cv );
+
+ explicit AsciiFile(const char* name, bool remove_empty = false);
+ explicit AsciiFile(const string& name, bool remove_empty = false);
+
+ string name() const { return Name_C; }
+
+ bool reload();
+ bool save();
+
+ void logContent() const;
+
void append( const string& Line_Cv );
- void append( const std::list<string>& Lines_Cv );
+ void append( const vector<string>& Lines_Cv );
void insert( unsigned int Before_iv, const string& Line_Cv );
+ void clear();
void remove( unsigned int Start_iv, unsigned int Cnt_iv );
void replace( unsigned int Start_iv, unsigned int Cnt_iv,
const string& Line_Cv );
void replace( unsigned int Start_iv, unsigned int Cnt_iv,
- const std::list<string>& Line_Cv );
+ const vector<string>& Line_Cv );
+
const string& operator []( unsigned int Index_iv ) const;
string& operator []( unsigned int Index_iv );
- int find( unsigned int Start_iv, const string& Pat_Cv ) const;
- int find( unsigned int Start_iv, Regex& Pat_Cv ) const;
- unsigned numLines() const;
- std::vector<string>& lines() { return Lines_C; }
- const string& fileName() const;
- unsigned differentLine( const AsciiFile& File_Cv ) const;
- bool removeIfEmpty();
+
+ template <class Pred>
+ int find_if_idx(Pred pred) const
+ {
+ vector<string>::const_iterator it = std::find_if(Lines_C.begin(), Lines_C.end(), pred);
+ if (it == Lines_C.end())
+ return -1;
+ return std::distance(Lines_C.begin(), it);
+ }
+
+ unsigned numLines() const { return Lines_C.size(); }
+
+ vector<string>& lines() { return Lines_C; }
+ const vector<string>& lines() const { return Lines_C; }
protected:
- bool appendFile( const string& Name_Cv, std::vector<string>& Lines_Cr );
- bool appendFile( AsciiFile& File_Cv, std::vector<string>& Lines_Cr );
+
void removeLastIf(string& Text_Cr, char Char_cv) const;
- bool BackupCreated_b;
- string BackupExtension_C;
- std::vector<string> Lines_C;
- string Name_C;
+ const string Name_C;
+ const bool remove_empty;
+
+ vector<string> Lines_C;
+
+ };
+
+
+ class SysconfigFile : protected AsciiFile
+ {
+ public:
+
+ SysconfigFile(const char* name) : AsciiFile(name) {}
+
+ bool getValue(const string& key, string& value) const;
+
+ };
+
+
+ class InstallInfFile : protected AsciiFile
+ {
+ public:
+
+ InstallInfFile(const char* name) : AsciiFile(name) {}
+
+ bool getValue(const string& key, string& value) const;
+
};
}
+
#endif
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Blkid.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Blkid.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Blkid.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Blkid.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) [2004-2009] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include "storage/AppUtil.h"
+#include "storage/SystemCmd.h"
+#include "storage/StorageDefines.h"
+#include "storage/Blkid.h"
+#include "storage/Volume.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ Blkid::Blkid()
+ {
+ SystemCmd cmd("BLKID_SKIP_CHECK_MDRAID=1 " BLKIDBIN " -c /dev/null");
+ if (cmd.retcode() == 0)
+ parse(cmd.stdout());
+ }
+
+
+ Blkid::Blkid(const string& device)
+ {
+ SystemCmd cmd("BLKID_SKIP_CHECK_MDRAID=1 " BLKIDBIN " -c /dev/null " + quote(device));
+ if (cmd.retcode() == 0)
+ parse(cmd.stdout());
+ }
+
+
+ void
+ Blkid::parse(const vector<string>& lines)
+ {
+ data.clear();
+
+ for (vector<string>::const_iterator it = lines.begin(); it != lines.end(); ++it)
+ {
+ string::size_type pos = it->find(":");
+ if (pos == string::npos)
+ continue;
+
+ string device = string(*it, 0, pos);
+ list<string> l = splitString(string(*it, pos + 1), " \t\n", true, true, "\"");
+
+ Entry entry;
+
+ const map m = makeMap(l, "=", "\"");
+
+ map::const_iterator i = m.find("TYPE");
+ if (i != m.end())
+ {
+ if (i->second == "reiserfs")
+ {
+ entry.is_fs = true;
+ entry.fs_type = REISERFS;
+ }
+ else if (i->second == "swap")
+ {
+ entry.is_fs = true;
+ entry.fs_type = SWAP;
+ }
+ else if (i->second == "ext2")
+ {
+ entry.is_fs = true;
+ entry.fs_type = EXT2;
+ }
+ else if (i->second == "ext3")
+ {
+ entry.is_fs = true;
+ entry.fs_type = EXT3;
+ }
+ else if (i->second == "ext4")
+ {
+ entry.is_fs = true;
+ entry.fs_type = EXT4;
+ }
+ else if (i->second == "btrfs")
+ {
+ entry.is_fs = true;
+ entry.fs_type = BTRFS;
+ }
+ else if (i->second == "vfat")
+ {
+ entry.is_fs = true;
+ entry.fs_type = VFAT;
+ }
+ else if (i->second == "ntfs" || i->second == "ntfs-3g")
+ {
+ entry.is_fs = true;
+ entry.fs_type = NTFS;
+ }
+ else if (i->second == "jfs")
+ {
+ entry.is_fs = true;
+ entry.fs_type = JFS;
+ }
+ else if (i->second == "hfs")
+ {
+ entry.is_fs = true;
+ entry.fs_type = HFS;
+ }
+ else if (i->second == "hfsplus")
+ {
+ entry.is_fs = true;
+ entry.fs_type = HFSPLUS;
+ }
+ else if (i->second == "xfs")
+ {
+ entry.is_fs = true;
+ entry.fs_type = XFS;
+ }
+ else if (i->second == "LVM2_member")
+ {
+ entry.is_lvm = true;
+ }
+ else if (i->second == "crypto_LUKS")
+ {
+ entry.is_luks = true;
+ }
+ }
+
+ if (entry.is_fs)
+ {
+ i = m.find("UUID");
+ if (i != m.end())
+ entry.fs_uuid = i->second;
+
+ i = m.find("LABEL");
+ if (i != m.end())
+ entry.fs_label = i->second;
+ }
+
+ if (entry.is_luks)
+ {
+ i = m.find("UUID");
+ if (i != m.end())
+ entry.luks_uuid = i->second;
+ }
+
+ if (entry.is_fs || entry.is_lvm || entry.is_luks)
+ data[device] = entry;
+ }
+
+ for (const_iterator it = data.begin(); it != data.end(); ++it)
+ y2mil("data[" << it->first << "] -> " << it->second);
+ }
+
+
+ bool
+ Blkid::getEntry(const string& device, Entry& entry) const
+ {
+ const_iterator i = data.find(device);
+ if (i == data.end())
+ return false;
+
+ entry = i->second;
+ return true;
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const Blkid::Entry& entry)
+ {
+ if (entry.is_fs)
+ {
+ s << "is_fs:" << entry.is_fs;
+ s << " fs_type:" << toString(entry.fs_type);
+ if (!entry.fs_uuid.empty())
+ s << " fs_uuid:" << entry.fs_uuid;
+ if (!entry.fs_label.empty())
+ s << " fs_label:" << entry.fs_label;
+ }
+
+ if (entry.is_lvm)
+ {
+ s << "is_lvm:" << entry.is_lvm;
+ }
+
+ if (entry.is_luks)
+ {
+ s << "is_luks:" << entry.is_luks;
+ if (!entry.luks_uuid.empty())
+ s << " luks_uuid:" << entry.luks_uuid;
+ }
+
+ return s;
+ }
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Blkid.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Blkid.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Blkid.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Blkid.h Tue May 17 13:39:44 2011
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) [2004-2009] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef BLKID_H
+#define BLKID_H
+
+#include <string>
+#include <map>
+#include <vector>
+
+#include "storage/StorageInterface.h"
+
+
+namespace storage
+{
+ using std::map;
+ using std::vector;
+
+
+ class Blkid
+ {
+ public:
+
+ Blkid();
+ Blkid(const string& device);
+
+ struct Entry
+ {
+ Entry() : is_fs(false), fs_type(FSUNKNOWN), fs_uuid(), fs_label(),
+ is_lvm(false), is_luks(false), luks_uuid() {}
+
+ bool is_fs;
+ FsType fs_type;
+ string fs_uuid;
+ string fs_label;
+
+ bool is_lvm;
+
+ bool is_luks;
+ string luks_uuid;
+ };
+
+ friend std::ostream& operator<<(std::ostream& s, const Entry& entry);
+
+ bool getEntry(const string& device, Entry& entry) const;
+
+ protected:
+
+ void parse(const vector<string>& lines);
+
+ typedef map::const_iterator const_iterator;
+
+ map data;
+
+ };
+
+}
+
+
+#endif
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,765 @@
+/*
+ * Copyright (c) [2004-2011] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include
+#include <sstream>
+
+#include "storage/Btrfs.h"
+#include "storage/StorageTypes.h"
+#include "storage/Container.h"
+#include "storage/AppUtil.h"
+#include "storage/SystemInfo.h"
+#include "storage/Storage.h"
+#include "storage/SystemCmd.h"
+#include "storage/StorageDefines.h"
+
+
+namespace storage
+{
+using namespace std;
+
+Btrfs::Btrfs(const BtrfsCo& d, const Volume& v, unsigned long long sz,
+ const list<string>& devs ) : Volume(d, v), devices(devs)
+ {
+ y2mil("constructed btrfs vol size:" << sz << " devs:" << devs );
+ y2mil("constructed btrfs vol from:" << v );
+ changeMountBy(MOUNTBY_UUID);
+ setSize( sz );
+ }
+
+Btrfs::Btrfs(const BtrfsCo& d, const Volume& v ) : Volume(d, v)
+ {
+ y2mil("constructed btrfs vol from:" << v );
+ y2mil( "fs:" << fs << " det:" << detected_fs );
+ changeMountBy(MOUNTBY_UUID);
+ devices.push_back(v.device());
+ }
+
+Btrfs::Btrfs(const BtrfsCo& d, const xmlNode* node ) : Volume(d, node)
+ {
+ list l = getChildNodes(node, "devices");
+ for( list::const_iterator it=l.begin(); it!=l.end(); ++it )
+ {
+ string s;
+ getChildValue(*it, "devices", s);
+ devices.push_back(s);
+ }
+ l = getChildNodes(node, "dev_add");
+ for( list::const_iterator it=l.begin(); it!=l.end(); ++it )
+ {
+ string s;
+ getChildValue(*it, "devices", s);
+ dev_add.push_back(s);
+ }
+ l = getChildNodes(node, "dev_rem");
+ for( list::const_iterator it=l.begin(); it!=l.end(); ++it )
+ {
+ string s;
+ getChildValue(*it, "devices", s);
+ dev_rem.push_back(s);
+ }
+ l = getChildNodes(node, "subvolumes");
+ for (list::const_iterator it=l.begin(); it!=l.end(); ++it )
+ {
+ subvol.push_back(Subvolume(*it));
+ }
+ }
+
+
+Btrfs::Btrfs(const BtrfsCo& c, const Btrfs& v) : Volume(c, v),
+ devices(v.devices), subvol(v.subvol)
+ {
+ y2deb("copy-constructed Btrfs from " << v.dev);
+ }
+
+
+Btrfs::~Btrfs()
+ {
+ y2deb("destructed Btrfs " << dev);
+ }
+
+void Btrfs::addSubvol( const string& path )
+ {
+ y2mil( "path:\"" << path << "\"" );
+ Subvolume v( path );
+ if( !contains( subvol, v ))
+ subvol.push_back( v );
+ else
+ y2war( "subvolume " << v << " already exists!" );
+ }
+
+int
+Btrfs::createSubvolume( const string& name )
+ {
+ int ret=0;
+ y2mil( "name:" << name );
+ list<Subvolume>::iterator i=subvol.begin();
+ while( i!=subvol.end() && !i->deleted() && i->path()!=name )
+ ++i;
+ if( i==subvol.end() )
+ {
+ Subvolume v( name );
+ v.setCreated();
+ subvol.push_back( v );
+ }
+ else
+ ret = BTRFS_SUBVOL_EXISTS;
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+int
+Btrfs::deleteSubvolume( const string& name )
+ {
+ int ret=0;
+ y2mil( "name:" << name );
+ list<Subvolume>::iterator i=subvol.begin();
+ while( i!=subvol.end() && i->path()!=name )
+ ++i;
+ if( i!=subvol.end() )
+ {
+ if( i->created() )
+ subvol.erase(i);
+ else
+ i->setDeleted();
+ }
+ else
+ ret = BTRFS_SUBVOL_NON_EXISTS;
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+int Btrfs::extendVolume( const string& dev )
+ {
+ list<string> d;
+ d.push_back(dev);
+ return( extendVolume(d));
+ }
+
+int Btrfs::extendVolume( const list<string>& devs )
+ {
+ int ret = 0;
+ y2mil( "name:" << name() << " devices:" << devs );
+ y2mil( "this:" << *this );
+
+ list<string>::const_iterator i=devs.begin();
+ list<string>::iterator p;
+ while( ret==0 && i!=devs.end() )
+ {
+ string d = normalizeDevice( *i );
+ if( (p=find( devices.begin(), devices.end(), d ))!=devices.end() ||
+ (p=find( dev_add.begin(), dev_add.end(), d ))!=dev_add.end())
+ ret = BTRFS_DEV_ALREADY_CONTAINED;
+ else if( (p=find( dev_rem.begin(), dev_rem.end(), d )) != dev_rem.end() &&
+ !getStorage()->deletedDevice( d ) )
+ {
+ }
+ else if( !getStorage()->knownDevice( d, true ) )
+ {
+ ret = BTRFS_DEVICE_UNKNOWN;
+ }
+ else if( !getStorage()->canUseDevice( d, true ) )
+ {
+ ret = BTRFS_DEVICE_USED;
+ }
+ ++i;
+ }
+ i=devs.begin();
+ while( ret==0 && i!=devs.end() )
+ {
+ string d = normalizeDevice( *i );
+ if( (p=find( dev_rem.begin(), dev_rem.end(), d )) != dev_rem.end() &&
+ !getStorage()->deletedDevice( d ) )
+ {
+ devices.push_back( *p );
+ dev_rem.erase( p );
+ }
+ else
+ {
+ dev_add.push_back( d );
+ if( !getStorage()->isDisk(d))
+ getStorage()->changeFormatVolume( d, false, FSNONE );
+ }
+ getStorage()->setUsedBy(d, UB_BTRFS, device());
+ setSize( size_k+getStorage()->deviceSize( d ) );
+ ++i;
+ }
+ if( ret==0 && dev_add.size()+devices.size()-dev_rem.size()<=0 )
+ ret = BTRFS_HAS_NONE_DEV;
+ y2mil( "this:" << *this );
+ y2mil("ret:" << ret);
+ return( ret );
+ }
+
+int Btrfs::shrinkVolume( const string& dev )
+ {
+ list<string> d;
+ d.push_back(dev);
+ return( shrinkVolume(d));
+ }
+
+int Btrfs::shrinkVolume( const list<string>& devs )
+ {
+ int ret = 0;
+ y2mil("name:" << name() << " devices:" << devs);
+ y2mil("this:" << *this);
+
+ list<string>::const_iterator i = devs.begin();
+ list<string>::iterator p;
+ while( ret==0 && i!=devs.end() )
+ {
+ string d = normalizeDevice( *i );
+ if( (p=find( devices.begin(), devices.end(), d ))==devices.end() &&
+ (p=find( dev_add.begin(), dev_add.end(), d ))==dev_add.end())
+ ret = BTRFS_DEV_NOT_FOUND;
+ ++i;
+ }
+ unsigned long long s = size_k;
+ i = devs.begin();
+ while( ret==0 && i!=devs.end() )
+ {
+ string d = normalizeDevice( *i );
+ if( (p=find( dev_add.begin(), dev_add.end(), d ))!=dev_add.end())
+ dev_add.erase(p);
+ else
+ dev_rem.push_back(d);
+ getStorage()->clearUsedBy(d);
+ s -= min(getStorage()->deviceSize( d ),s);
+ setSize( size_k-getStorage()->deviceSize( d ) );
+ ++i;
+ }
+ if( ret==0 && dev_add.size()+devices.size()-devs.size()<=0 )
+ ret = BTRFS_HAS_NONE_DEV;
+ if( ret == 0 )
+ {
+ setSize( s );
+ }
+ y2mil("this:" << *this);
+ y2mil("ret:" << ret);
+ return ret;
+ }
+
+int Btrfs::doExtend()
+ {
+ y2mil( "this:" << *this );
+ int ret = 0;
+ bool needUmount = false;
+ Storage* st = NULL;
+ string m = getMount();
+ if( !isMounted() )
+ {
+ st = getContainer()->getStorage();
+ if( st->mountTmp( this, m ) )
+ needUmount = true;
+ else
+ ret = BTRFS_CANNOT_TMP_MOUNT;
+ }
+ list<string> devs = dev_add;
+ list<string>::const_iterator d = devs.begin();
+ SystemCmd c;
+ while( ret==0 && d!=devs.end() )
+ {
+ if( !silent )
+ getStorage()->showInfoCb(extendText(true, *d));
+ string cmd = BTRFSBIN " device add " + quote(*d) + " " + m;
+ c.execute( cmd );
+ if( c.retcode()==0 )
+ {
+ devices.push_back(*d);
+ dev_add.remove_if( bind2nd(equal_to<string>(),*d));
+ }
+ else
+ ret = BTRFS_EXTEND_FAIL;
+ ++d;
+ }
+ if( needUmount )
+ {
+ if( !st->umountDev( device() ) && ret==0 )
+ {
+ ret = BTRFS_CANNOT_TMP_UMOUNT;
+ }
+ }
+ y2mil( "this:" << *this );
+ y2mil("ret:" << ret);
+ return( ret );
+ }
+
+int Btrfs::doReduce()
+ {
+ y2mil( "this:" << *this );
+ int ret = 0;
+ bool needUmount = false;
+ Storage* st = NULL;
+ string m = getMount();
+ if( !isMounted() )
+ {
+ st = getContainer()->getStorage();
+ if( st->mountTmp( this, m ) )
+ needUmount = true;
+ else
+ ret = BTRFS_CANNOT_TMP_MOUNT;
+ }
+ list<string> devs = dev_rem;
+ list<string>::const_iterator d = devs.begin();
+ SystemCmd c;
+ while( ret==0 && d!=devs.end() )
+ {
+ if( !silent )
+ getStorage()->showInfoCb(reduceText(true, *d));
+ string cmd = BTRFSBIN " device delete " + quote(*d) + " " + m;
+ c.execute( cmd );
+ if( c.retcode()==0 )
+ {
+ devices.remove_if( bind2nd(equal_to<string>(),*d));
+ dev_rem.remove_if( bind2nd(equal_to<string>(),*d));
+ }
+ else
+ ret = BTRFS_REDUCE_FAIL;
+ ++d;
+ }
+ if( needUmount )
+ {
+ if( !st->umountDev( device() ) && ret==0 )
+ {
+ ret = BTRFS_CANNOT_TMP_UMOUNT;
+ }
+ }
+ y2mil( "this:" << *this );
+ y2mil("ret:" << ret);
+ return( ret );
+ }
+
+int Btrfs::doDeleteSubvol()
+ {
+ int ret = 0;
+ bool needUmount = false;
+ Storage* st = NULL;
+ string m = getMount();
+ if( !isMounted() )
+ {
+ st = getContainer()->getStorage();
+ if( st->mountTmp( this, m ) )
+ needUmount = true;
+ else
+ ret = BTRFS_CANNOT_TMP_MOUNT;
+ }
+ if( ret==0 )
+ {
+ SystemCmd c;
+ string cmd = BTRFSBIN " subvolume delete " + m + '/';
+ for( list<Subvolume>::iterator i=subvol.begin(); i!=subvol.end(); ++i )
+ {
+ if( i->deleted() )
+ {
+ if( !silent )
+ getStorage()->showInfoCb( deleteSubvolText(true,i->path()));
+ c.execute( cmd + i->path() );
+ if( c.retcode()==0 )
+ i->setDeleted(false);
+ else
+ ret = BTRFS_DELETE_SUBVOL_FAIL;
+ }
+ }
+ }
+ if( needUmount )
+ {
+ if( !st->umountDev( device() ) && ret==0 )
+ {
+ ret = BTRFS_CANNOT_TMP_UMOUNT;
+ }
+ }
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+int Btrfs::doCreateSubvol()
+ {
+ int ret = 0;
+ bool needUmount = false;
+ Storage* st = NULL;
+ string m = getMount();
+ if( !isMounted() )
+ {
+ st = getContainer()->getStorage();
+ if( st->mountTmp( this, m ) )
+ needUmount = true;
+ else
+ ret = BTRFS_CANNOT_TMP_MOUNT;
+ }
+ if( ret==0 )
+ {
+ SystemCmd c;
+ string cmd = BTRFSBIN " subvolume create " + m + '/';
+ for( list<Subvolume>::iterator i=subvol.begin(); i!=subvol.end(); ++i )
+ {
+ if( i->created() )
+ {
+ if( !silent )
+ getStorage()->showInfoCb( createSubvolText(true,i->path()));
+ c.execute( cmd + i->path() );
+ if( c.retcode()==0 )
+ i->setCreated(false);
+ else
+ ret = BTRFS_CREATE_SUBVOL_FAIL;
+ }
+ }
+ }
+ if( needUmount )
+ {
+ if( !st->umountDev( device() ) && ret==0 )
+ {
+ ret = BTRFS_CANNOT_TMP_UMOUNT;
+ }
+ }
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+list<string> Btrfs::getSubvolAddDel( bool add ) const
+ {
+ list<string> ret;
+ list<Subvolume>::const_iterator i;
+ for( i=subvol.begin(); i!=subvol.end(); ++i )
+ {
+ if( !add && i->deleted() )
+ ret.push_back(i->path());
+ if( add && i->created() )
+ ret.push_back(i->path());
+ }
+ if( !ret.empty() )
+ y2mil( "add:" << add << " ret:" << ret );
+ return( ret );
+ }
+
+void
+Btrfs::countSubvolAddDel( unsigned& add, unsigned& del ) const
+ {
+ add = del = 0;
+ for( list<Subvolume>::const_iterator i=subvol.begin();
+ i!=subvol.end(); ++i )
+ {
+ if( i->deleted() )
+ del++;
+ if( i->created() )
+ add++;
+ }
+ if( add>0 || del>0 )
+ y2mil( "add:" << add << " del:" << del );
+ }
+
+string
+Btrfs::subvolNames( bool added ) const
+ {
+ string ret;
+ for( list<Subvolume>::const_iterator i=subvol.begin();
+ i!=subvol.end(); ++i )
+ {
+ if( (added && i->created()) ||
+ (!added && i->deleted()))
+ {
+ if( !ret.empty() )
+ ret += ' ';
+ ret += i->path();
+ }
+ }
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+void Btrfs::unuseDev() const
+ {
+ for( list<string>::const_iterator s=devices.begin(); s!=devices.end(); ++s )
+ getContainer()->getStorage()->clearUsedBy(*s);
+ for( list<string>::const_iterator s=dev_add.begin(); s!=dev_add.end(); ++s )
+ getContainer()->getStorage()->clearUsedBy(*s);
+ }
+
+int Btrfs::clearSignature()
+ {
+ int ret = 0;
+ // no need to actually remove signature from single volume btrfs filesystems
+ if( devices.size()>1 )
+ {
+ for( list<string>::const_iterator s=devices.begin(); s!=devices.end(); ++s )
+ getContainer()->getStorage()->zeroDevice(*s,0);
+ }
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+Text Btrfs::removeText(bool doing) const
+ {
+ Text txt;
+ string d = boost::join( devices, " " );
+ if( doing )
+ {
+ // displayed text during action, %1$s is replaced by device names e.g /dev/sda1 /dev/sda2
+ txt = sformat( _("Deleting Btrfs volume on devices %1$s"), d.c_str() );
+ }
+ else
+ {
+ // displayed text before action, %1$s is replaced by device names e.g /dev/sda1 /dev/sda2
+ // %2$s is replaced by size (e.g. 623.5 MB)
+ txt = sformat( _("Delete Btrfs volume on devices %1$s (%2$s)"),
+ d.c_str(), sizeString().c_str() );
+ }
+ return( txt );
+ }
+
+void
+Btrfs::getCommitActions(list<commitAction>& l) const
+ {
+ Volume::getCommitActions( l );
+ unsigned rem, add;
+ list<string>::const_iterator i;
+ if( !dev_add.empty() )
+ for( i=dev_add.begin(); i!=dev_add.end(); ++i )
+ l.push_back(commitAction(INCREASE, cont->type(),
+ extendText(false, *i), this, true));
+ if( !dev_rem.empty() )
+ for( i=dev_rem.begin(); i!=dev_rem.end(); ++i )
+ l.push_back(commitAction(DECREASE, cont->type(),
+ reduceText(false, *i), this, false));
+ countSubvolAddDel( add, rem );
+ if( rem>0 )
+ {
+ list<string> sl = getSubvolAddDel( false );
+ for( list<string>::const_iterator i=sl.begin(); i!=sl.end(); ++i )
+ l.push_back(commitAction(SUBVOL, cont->type(),
+ deleteSubvolText(false,*i), this, true));
+ }
+ if( add>0 )
+ {
+ list<string> sl = getSubvolAddDel( true );
+ for( list<string>::const_iterator i=sl.begin(); i!=sl.end(); ++i )
+ l.push_back(commitAction(SUBVOL, cont->type(),
+ createSubvolText(false,*i), this, true));
+ }
+ }
+
+Text
+Btrfs::extendText(bool doing, const string& dev) const
+ {
+ Text txt;
+ if( doing )
+ {
+ // displayed text during action,
+ // %1$s and %2$s are replaced by a device names (e.g. /dev/hda1)
+ txt = sformat( _("Extending BTRFS volume %1$s by %2$s"), name().c_str(),
+ dev.c_str() );
+ }
+ else
+ {
+ // displayed text before action,
+ // %1$s and %2$s are replaced by a device names (e.g. /dev/hda1)
+ txt = sformat( _("Extend BTRFS volume %1$s by %2$s"), name().c_str(),
+ dev.c_str() );
+ }
+ return( txt );
+ }
+
+Text
+Btrfs::reduceText(bool doing, const string& dev) const
+ {
+ Text txt;
+ if( doing )
+ {
+ // displayed text during action,
+ // %1$s and %2$s are replaced by a device names (e.g. /dev/hda1)
+ txt = sformat( _("Reducing BTRFS volume %1$s by %2$s"), name().c_str(),
+ dev.c_str() );
+ }
+ else
+ {
+ // displayed text before action,
+ // %1$s and %2$s are replaced by a device names (e.g. /dev/hda1)
+ txt = sformat( _("Reduce BTRFS volume %1$s by %2$s"), name().c_str(),
+ dev.c_str() );
+ }
+ return( txt );
+ }
+
+Text Btrfs::createSubvolText(bool doing, const string& name) const
+ {
+ Text txt;
+ if( doing )
+ {
+ // displayed text during action, %1$s is replaced by subvolume name e.g. tmp
+ // %2$s is replaced by device name e.g. /dev/hda1
+ txt = sformat( _("Creating subvolume %1$s on device %2$s"),
+ name.c_str(), dev.c_str() );
+ }
+ else
+ {
+ // displayed text before action, %1$s is replaced by subvolume name e.g. tmp
+ // %2$s is replaced by device name e.g. /dev/hda1
+ txt = sformat( _("Create subvolume %1$s on device %2$s"),
+ name.c_str(), dev.c_str() );
+ }
+ return( txt );
+ }
+
+Text Btrfs::deleteSubvolText(bool doing, const string& name) const
+ {
+ Text txt;
+ if( doing )
+ {
+ // displayed text during action, %1$s is replaced by subvolume name e.g. tmp
+ // %2$s is replaced by device name e.g. /dev/hda1
+ txt = sformat( _("Removing subvolume %1$s on device %2$s"),
+ name.c_str(), dev.c_str() );
+ }
+ else
+ {
+ // displayed text before action, %1$s is replaced by subvolume name e.g. tmp
+ // %2$s is replaced by device name e.g. /dev/hda1
+ txt = sformat( _("Remove subvolume %1$s on device %2$s"),
+ name.c_str(), dev.c_str() );
+ }
+ return( txt );
+ }
+
+void Btrfs::getInfo( BtrfsInfo& tinfo ) const
+ {
+ Volume::getInfo(info.v);
+ info.devices = boost::join( devices, "\n" );
+ info.devices_add = boost::join( dev_add, "\n" );
+ info.devices_rem = boost::join( dev_rem, "\n" );
+ info.subvol.erase();
+
+ for( list<Subvolume>::const_iterator i=subvol.begin();
+ i!=subvol.end(); ++i )
+ {
+ if( !info.subvol.empty() )
+ info.subvol += '\n';
+ if( !i->deleted() )
+ info.subvol += i->path();
+ }
+ tinfo = info;
+ }
+
+std::ostream& operator<< (std::ostream& s, const Btrfs& v )
+ {
+ s << "Btrfs " << dynamic_cast(v);
+ s << " devices:" << v.devices;
+ if( !v.dev_add.empty() )
+ s << " dev_add:" << v.dev_add;
+ if( !v.dev_rem.empty() )
+ s << " dev_rem:" << v.dev_rem;
+ if( !v.subvol.empty() )
+ s << " subvol:" << v.subvol;
+ return( s );
+ }
+
+
+bool Btrfs::equalContent( const Btrfs& rhs ) const
+ {
+ return( Volume::equalContent(rhs) && devices==rhs.devices &&
+ dev_add==rhs.dev_add && dev_rem==rhs.dev_rem &&
+ subvol==rhs.subvol );
+ }
+
+
+void Btrfs::logDifference(std::ostream& log, const Btrfs& rhs) const
+ {
+ Volume::logDifference(log, rhs);
+ list<string>::const_iterator i;
+ string tmp;
+ for( i = devices.begin(); i != devices.end(); ++i)
+ if (!contains(rhs.devices, *i))
+ tmp += *i + "-->";
+ for( i = rhs.devices.begin(); i != rhs.devices.end(); ++i)
+ if (!contains(devices, *i))
+ tmp += "<--" + *i;
+ if (!tmp.empty())
+ log << " Devices:" << tmp;
+
+ tmp.erase();
+ for( i = dev_add.begin(); i != dev_add.end(); ++i)
+ if (!contains(rhs.dev_add, *i))
+ tmp += *i + "-->";
+ for( i = rhs.dev_add.begin(); i != rhs.dev_add.end(); ++i)
+ if (!contains(dev_add, *i))
+ tmp += "<--" + *i;
+ if (!tmp.empty())
+ log << " DevAdd:" << tmp;
+
+ tmp.erase();
+ for( i = dev_rem.begin(); i != dev_rem.end(); ++i)
+ if (!contains(rhs.dev_rem, *i))
+ tmp += *i + "-->";
+ for( i = rhs.dev_rem.begin(); i != rhs.dev_rem.end(); ++i)
+ if (!contains(dev_rem, *i))
+ tmp += "<--" + *i;
+ if (!tmp.empty())
+ log << " DevRem:" << tmp;
+
+ tmp.erase();
+ list<Subvolume>::const_iterator s;
+ for( s=subvol.begin(); s!=subvol.end(); ++s )
+ {
+ if( s->deleted() )
+ tmp += "<--" + s->path();
+ else if( s->created() )
+ tmp += s->path() + "-->";
+ }
+ if (!tmp.empty())
+ log << " SubVol:" << tmp;
+ }
+
+void Btrfs::saveData(xmlNode* node) const
+ {
+ Volume::saveData(node);
+ setChildValue(node, "devices", devices);
+ if( !dev_add.empty() )
+ setChildValue(node, "dev_add", dev_add);
+ if( !dev_rem.empty() )
+ setChildValue(node, "dev_rem", dev_rem);
+ if (!subvol.empty())
+ setChildValue(node, "subvolume", subvol);
+ }
+
+bool Btrfs::needCreateSubvol( const Btrfs& v )
+ {
+ unsigned dummy, cnt;
+ v.countSubvolAddDel( cnt, dummy );
+ return( cnt>0 );
+ }
+
+bool Btrfs::needDeleteSubvol( const Btrfs& v )
+ {
+ unsigned dummy, cnt;
+ v.countSubvolAddDel( dummy, cnt );
+ return( cnt>0 );
+ }
+
+bool Btrfs::needReduce( const Btrfs& v )
+ {
+ return( !v.dev_rem.empty() );
+ }
+
+bool Btrfs::needExtend( const Btrfs& v )
+ {
+ return( !v.dev_add.empty() );
+ }
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.h Tue May 17 13:39:44 2011
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) [2004-2011] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef BTRFS_H
+#define BTRFS_H
+
+#include "storage/Volume.h"
+
+namespace storage
+{
+class BtrfsCo;
+class SystemInfo;
+
+
+class Btrfs : public Volume
+ {
+ public:
+
+ Btrfs( const BtrfsCo& d, const Volume& v, unsigned long long sz,
+ const list<string>& devices );
+ Btrfs( const BtrfsCo& d, const Volume& v );
+ Btrfs( const BtrfsCo& d, const xmlNode* node );
+ Btrfs( const BtrfsCo& c, const Btrfs& v);
+ virtual ~Btrfs();
+
+ void clearSubvol() { subvol.clear(); }
+ void addSubvol( const string& path );
+ const list<string>& getDevices() const { return devices; }
+ void getDevices( list<string>& devs ) const { devs=devices; }
+ void getSubvolumes( list<Subvolume>& sv ) const { sv = subvol; }
+
+ int createSubvolume( const string& name );
+ int deleteSubvolume( const string& name );
+ int extendVolume( const string& dev );
+ int extendVolume( const list<string>& devs );
+ int shrinkVolume( const string& dev );
+ int shrinkVolume( const list<string>& devs );
+
+ void getCommitActions(list<commitAction>& l) const;
+ int doDeleteSubvol();
+ int doCreateSubvol();
+ int doReduce();
+ int doExtend();
+ Text createSubvolText(bool doing, const string& name) const;
+ Text deleteSubvolText(bool doing, const string& name) const;
+ Text extendText(bool doing, const string& device) const;
+ Text reduceText(bool doing, const string& device) const;
+ Text removeText( bool doing ) const;
+
+ void countSubvolAddDel( unsigned& add, unsigned& rem ) const;
+ list<string> getSubvolAddDel( bool ) const;
+
+ void saveData(xmlNode* node) const;
+ friend std::ostream& operator<< (std::ostream& s, const Btrfs& l );
+ virtual void print( std::ostream& s ) const { s << *this; }
+ void getInfo( storage::BtrfsInfo& info ) const;
+ bool equalContent( const Btrfs& rhs ) const;
+ void logDifference(std::ostream& log, const Btrfs& rhs) const;
+ void unuseDev() const;
+ int clearSignature();
+
+
+ static bool notDeleted( const Btrfs& l ) { return( !l.deleted() ); }
+ static bool needCreateSubvol( const Btrfs& v );
+ static bool needDeleteSubvol( const Btrfs& v );
+ static bool needReduce( const Btrfs& v );
+ static bool needExtend( const Btrfs& v );
+
+ protected:
+ string subvolNames( bool added ) const;
+ list<string> devices;
+ list<string> dev_add;
+ list<string> dev_rem;
+ list<Subvolume> subvol;
+
+ mutable storage::BtrfsInfo info; // workaround for broken ycp bindings
+
+ private:
+
+ Btrfs& operator=(const Btrfs& v); // disallow
+ Btrfs(const Btrfs&); // disallow
+
+ };
+
+}
+
+#endif
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/BtrfsCo.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/BtrfsCo.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/BtrfsCo.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/BtrfsCo.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,487 @@
+/*
+ * Copyright (c) [2004-2011] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include <ostream>
+#include <sstream>
+
+#include "storage/BtrfsCo.h"
+#include "storage/Btrfs.h"
+#include "storage/SystemCmd.h"
+#include "storage/Dm.h"
+#include "storage/SystemInfo.h"
+#include "storage/ProcMounts.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
+#include "storage/EtcFstab.h"
+#include "storage/StorageDefines.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ BtrfsCo::BtrfsCo(Storage* s)
+ : Container(s, "btrfs", "/dev/btrfs", staticType())
+ {
+ y2deb("constructing BtrfsCo");
+ }
+
+
+ BtrfsCo::BtrfsCo(Storage* s, SystemInfo& systeminfo)
+ : Container(s, "btrfs", "/dev/btrfs", staticType(), systeminfo)
+ {
+ y2deb("constructing BtrfsCo");
+ getBtrfsData(systeminfo);
+ }
+
+
+ BtrfsCo::BtrfsCo(const BtrfsCo& c)
+ : Container(c)
+ {
+ y2deb("copy-constructed BtrfsCo from " << c.dev);
+
+ ConstBtrfsPair p = c.btrfsPair();
+ for (ConstBtrfsIter i = p.begin(); i != p.end(); ++i)
+ {
+ Btrfs* p = new Btrfs(*this, *i);
+ vols.push_back(p);
+ }
+ }
+
+
+ BtrfsCo::~BtrfsCo()
+ {
+ y2deb("destructed BtrfsCo " << dev);
+ }
+
+
+void BtrfsCo::getBtrfsData(SystemInfo& systeminfo)
+ {
+ y2mil("begin");
+ list<string> uuids = systeminfo.getCmdBtrfsShow().getUuids();
+ CmdBtrfsShow::Entry e;
+ for( list<string>::const_iterator i=uuids.begin(); i!=uuids.end(); ++i )
+ {
+ if( systeminfo.getCmdBtrfsShow().getEntry( *i, e ))
+ {
+ Volume const* cv = NULL;
+ unsigned long long sum_size = 0;
+ list<string> an;
+ for( list<string>::const_iterator d=e.devices.begin(); d!=e.devices.end(); ++d )
+ {
+ Volume const* v;
+ if( getStorage()->findVolume( *d, v ))
+ {
+ if( cv==NULL ||
+ (cv->getMount().empty() && !v->getMount().empty()) ||
+ (!cv->getFormat() && v->getFormat() ))
+ cv = v;
+ sum_size += v->sizeK();
+ list<string> li = v->altNames();
+ an.splice( an.end(), li );
+ }
+ else
+ y2war( "device " << *d << " not found" );
+ }
+ list<string> devs;
+ for( list<string>::const_iterator i=e.devices.begin(); i!=e.devices.end(); ++i )
+ {
+ const Device* v;
+ if( getStorage()->findDevice( *i, v ) )
+ devs.push_back( v->device() );
+ else
+ devs.push_back( *i );
+ }
+ Btrfs* b = new Btrfs( *this, *cv, sum_size, devs );
+ y2mil( "alt_names:" << an );
+ b->setAltNames( an );
+ vols.push_back(b);
+ }
+ else
+ y2war( "uuid " << *i << " not found" );
+ }
+ BtrfsPair p( btrfsPair() );
+ for( BtrfsIter i=p.begin(); i!=p.end(); ++i )
+ {
+ y2mil( "dev:" << i->device() );
+ bool mounted = false;
+ string mp = i->getMount();
+ if( !i->isMounted() && getStorage()->mountTmpRo( &(*i), mp ) )
+ mounted = true;
+ if( !mp.empty() )
+ {
+ i->clearSubvol();
+ SystemCmd cmd( "btrfs subvolume list " + mp );
+ for( vector<string>::const_iterator s=cmd.stdout().begin();
+ s!=cmd.stdout().end(); ++s )
+ {
+ string subvol;
+ string::size_type pos = s->find( " path " );
+ if( pos!=string::npos )
+ pos = s->find_first_not_of( app_ws, pos+5 );
+ if( pos!=string::npos )
+ subvol = s->substr( pos, s->find_last_not_of( app_ws ) );
+ if( !subvol.empty() )
+ i->addSubvol( subvol );
+ }
+ }
+ if( mounted )
+ {
+ getStorage()->umountDev( i->device() );
+ rmdir( mp.c_str() );
+ }
+ }
+ y2mil("end");
+ }
+
+void
+BtrfsCo::addFromVolume( const Volume& v )
+ {
+ Btrfs* b = new Btrfs( *this, v );
+ vols.push_back(b);
+ }
+
+int BtrfsCo::createSubvolume( const string& device, const string& name )
+ {
+ int ret = 0;
+ y2mil( "device:" << device << " name:" << name );
+ BtrfsIter i;
+ if( readonly() )
+ ret = BTRFS_CHANGE_READONLY;
+ else if( findBtrfs( device, i ))
+ ret = i->createSubvolume( name );
+ else
+ ret = BTRFS_VOLUME_NOT_FOUND;
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+int BtrfsCo::removeSubvolume( const string& device, const string& name )
+ {
+ int ret = 0;
+ y2mil( "device:" << device << " name:" << name );
+ BtrfsIter i;
+ if( readonly() )
+ ret = BTRFS_CHANGE_READONLY;
+ else if( findBtrfs( device, i ))
+ ret = i->deleteSubvolume( name );
+ else
+ ret = BTRFS_VOLUME_NOT_FOUND;
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+int BtrfsCo::extendVolume( const string& device, const string& dev )
+ {
+ list<string> d;
+ d.push_back(dev);
+ return( extendVolume(device,d));
+ }
+
+int BtrfsCo::extendVolume( const string& device, const list<string>& devs )
+ {
+ int ret = 0;
+ y2mil( "device:" << device << " devices:" << devs );
+ BtrfsIter i;
+ if( readonly() )
+ ret = BTRFS_CHANGE_READONLY;
+ else if( findBtrfs( device, i ))
+ ret = i->extendVolume( devs );
+ else
+ ret = BTRFS_VOLUME_NOT_FOUND;
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+int BtrfsCo::shrinkVolume( const string& device, const string& dev )
+ {
+ list<string> d;
+ d.push_back(dev);
+ return( shrinkVolume(device,d));
+ }
+
+int BtrfsCo::shrinkVolume( const string& device, const list<string>& devs )
+ {
+ int ret = 0;
+ y2mil( "device:" << device << " devs:" << devs );
+ BtrfsIter i;
+ if( readonly() )
+ ret = BTRFS_CHANGE_READONLY;
+ else if( findBtrfs( device, i ))
+ ret = i->shrinkVolume( devs );
+ else
+ ret = BTRFS_VOLUME_NOT_FOUND;
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+void
+BtrfsCo::eraseVolume( Volume* v )
+ {
+ BtrfsPair p=btrfsPair(Btrfs::notDeleted);
+ BtrfsIter i = p.begin();
+ while( i!=p.end() && i->device()!=v->device() )
+ ++i;
+ if( i!=p.end() )
+ removeFromList( v );
+ }
+
+bool
+BtrfsCo::findBtrfs( const string& id, BtrfsIter& i )
+ {
+ BtrfsPair p=btrfsPair(Btrfs::notDeleted);
+ string uuid( id );
+ if( boost::starts_with( uuid, "UUID=" ))
+ uuid = uuid.substr( 5 );
+ i=p.begin();
+ while( i!=p.end() && i->getUuid()!=uuid )
+ ++i;
+ if( i==p.end() && !p.empty() )
+ {
+ i=p.begin();
+ bool found = false;
+ while( i!=p.end() && !found )
+ {
+ found = i->device()==id;
+ if( !found )
+ {
+ const list<string>& al( i->altNames() );
+ found = find( al.begin(), al.end(), id )!=al.end();
+ }
+ if( !found )
+ ++i;
+ }
+ }
+ y2mil( "id:" << id << " ret:" << (i!=p.end()) );
+ return( i!=p.end() );
+ }
+
+bool BtrfsCo::deviceToUuid( const string& device, string& uuid )
+ {
+ bool ret = false;
+ y2mil( "device:" << device );
+ const Volume* v = getStorage()->getVolume( device );
+ list<UsedBy>::const_iterator ul = v->getUsedBy().begin();
+ uuid.clear();
+ while( v && ul != v->getUsedBy().end() )
+ {
+ if( ul->type()==UB_BTRFS )
+ {
+ uuid = v->getUsedBy().front().device();
+ ret = true;
+ }
+ ++ul;
+ }
+ y2mil( "ret:" << ret << " uuid:" << (ret?uuid:"") );
+ return( ret );
+ }
+
+int BtrfsCo::commitChanges( CommitStage stage, Volume* vol )
+ {
+ y2mil("name:" << name() << " stage:" << stage);
+ int ret = Container::commitChanges( stage, vol );
+ if( ret==0 && stage==DECREASE )
+ {
+ Btrfs * b = dynamic_cast(vol);
+ if( b!=NULL )
+ ret = b->doReduce();
+ else
+ ret = BTRFS_COMMIT_INVALID_VOLUME;
+ }
+ else if( ret==0 && stage==INCREASE )
+ {
+ Btrfs * b = dynamic_cast(vol);
+ if( b!=NULL )
+ ret = b->doExtend();
+ else
+ ret = BTRFS_COMMIT_INVALID_VOLUME;
+ }
+ else if( ret==0 && stage==SUBVOL )
+ {
+ Btrfs * b = dynamic_cast(vol);
+ if( b!=NULL )
+ {
+ if( Btrfs::needDeleteSubvol( *b ) )
+ ret = b->doDeleteSubvol();
+ else if( Btrfs::needCreateSubvol( *b ) )
+ ret = b->doCreateSubvol();
+ }
+ else
+ ret = BTRFS_COMMIT_INVALID_VOLUME;
+ }
+ y2mil("ret:" << ret);
+ return( ret );
+ }
+
+void BtrfsCo::getToCommit( storage::CommitStage stage, list& col,
+ list& vol ) const
+ {
+ unsigned long oco = col.size();
+ unsigned long ovo = vol.size();
+ Container::getToCommit( stage, col, vol );
+ if( stage==DECREASE )
+ {
+ ConstBtrfsPair p = btrfsPair( Btrfs::needReduce );
+ for( ConstBtrfsIter i=p.begin(); i!=p.end(); ++i )
+ if( find( vol.begin(), vol.end(), &(*i) )==vol.end() )
+ vol.push_back( &(*i) );
+ }
+ else if( stage==INCREASE )
+ {
+ ConstBtrfsPair p = btrfsPair( Btrfs::needExtend );
+ for( ConstBtrfsIter i=p.begin(); i!=p.end(); ++i )
+ if( find( vol.begin(), vol.end(), &(*i) )==vol.end() )
+ vol.push_back( &(*i) );
+ }
+ else if( stage==SUBVOL )
+ {
+ ConstBtrfsPair p = btrfsPair( Btrfs::needDeleteSubvol );
+ for( ConstBtrfsIter i=p.begin(); i!=p.end(); ++i )
+ if( find( vol.begin(), vol.end(), &(*i) )==vol.end() )
+ vol.push_back( &(*i) );
+ p = btrfsPair( Btrfs::needCreateSubvol );
+ for( ConstBtrfsIter i=p.begin(); i!=p.end(); ++i )
+ if( find( vol.begin(), vol.end(), &(*i) )==vol.end() )
+ vol.push_back( &(*i) );
+ }
+ if( col.size()!=oco || vol.size()!=ovo )
+ y2mil("stage:" << stage << " col:" << col.size() << " vol:" << vol.size());
+ }
+
+
+int BtrfsCo::removeUuid( const string& uuid )
+ {
+ int ret = 0;
+ y2mil( "uuid:" << uuid );
+ BtrfsIter b;
+ if( findBtrfs( uuid, b ) )
+ ret = removeVolume( &(*b), true );
+ else
+ ret = BTRFS_REMOVE_NOT_FOUND;
+ y2mil( "ret:" << ret );
+ return( ret );
+ }
+
+int BtrfsCo::removeVolume( Volume* v, bool quiet )
+ {
+ int ret = 0;
+ y2mil("qiet:" << quiet);
+ y2mil("vol:" << *v);
+ v->setDeleted();
+ if( quiet )
+ v->setSilent();
+ Btrfs * b = dynamic_cast(v);
+ if( b )
+ b->unuseDev();
+ else
+ y2err( "no btrfs volume:" << *v );
+ y2mil("ret:" << ret);
+ return( ret );
+ }
+
+int BtrfsCo::removeVolume( Volume* v )
+ {
+ return( removeVolume( v, false ));
+ }
+
+int
+BtrfsCo::doRemove( Volume* v )
+ {
+ int ret = 0;
+ Btrfs *b = dynamic_cast(v);
+ if( b != NULL )
+ {
+ if( !silent )
+ {
+ getStorage()->showInfoCb( b->removeText(true) );
+ }
+ ret = b->clearSignature();
+ if( ret==0 && !removeFromList(v) )
+ ret = BTRFS_REMOVE_NO_BTRFS;
+ }
+ else
+ ret = BTRFS_REMOVE_INVALID_VOLUME;
+ y2mil("ret:" << ret);
+ return( ret );
+ }
+
+void
+BtrfsCo::logData(const string& Dir) const
+ {
+ string fname(Dir + "/btrfs.info.tmp");
+
+ XmlFile xml;
+ xmlNode* node = xmlNewNode("btrfs");
+ xml.setRootElement(node);
+ saveData(node);
+ xml.save(fname);
+
+ getStorage()->handleLogFile( fname );
+ }
+
+void
+BtrfsCo::saveData(xmlNode* node) const
+ {
+ Container::saveData(node);
+ ConstBtrfsPair vp = btrfsPair();
+ for (ConstBtrfsIter v = vp.begin(); v != vp.end(); ++v)
+ v->saveData(xmlNewChild(node, "btrfs"));
+ }
+
+
+std::ostream& operator<<(std::ostream& s, const BtrfsCo& d)
+ {
+ s << dynamic_cast(d);
+ return( s );
+ }
+
+
+void BtrfsCo::logDifferenceWithVolumes(std::ostream& log, const Container& rhs_c) const
+ {
+ const BtrfsCo& rhs = dynamic_cast(rhs_c);
+
+ logDifference(log, rhs);
+ log << endl;
+
+ ConstBtrfsPair pp = btrfsPair();
+ ConstBtrfsPair pc = rhs.btrfsPair();
+ logVolumesDifference(log, pp.begin(), pp.end(), pc.begin(), pc.end());
+ }
+
+
+bool BtrfsCo::equalContent( const Container& rhs ) const
+ {
+ const BtrfsCo * p = NULL;
+ bool ret = Container::equalContent(rhs);
+ if( ret )
+ p = dynamic_cast(&rhs);
+ if( ret && p )
+ {
+ ConstBtrfsPair pp = btrfsPair();
+ ConstBtrfsPair pc = p->btrfsPair();
+ ret = ret && storage::equalContent(pp.begin(), pp.end(), pc.begin(), pc.end());
+ }
+ return( ret );
+ }
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/BtrfsCo.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/BtrfsCo.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/BtrfsCo.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/BtrfsCo.h Tue May 17 13:39:44 2011
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) [2004-2011] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef BTRFS_CO_H
+#define BTRFS_CO_H
+
+#include "storage/Container.h"
+#include "storage/Btrfs.h"
+
+
+namespace storage
+{
+ class SystemInfo;
+
+
+class BtrfsCo : public Container
+ {
+ friend class Storage;
+
+ public:
+
+ BtrfsCo(Storage * const s);
+ BtrfsCo(Storage * const s, SystemInfo& systeminfo);
+ BtrfsCo(const BtrfsCo& c);
+ virtual ~BtrfsCo();
+
+ void addFromVolume( const Volume& v );
+ void eraseVolume( Volume* v );
+
+ int createSubvolume( const string& device, const string& name );
+ int removeSubvolume( const string& device, const string& name );
+ int extendVolume( const string& device, const string& dev );
+ int extendVolume( const string& device, const list<string>& devs );
+ int shrinkVolume( const string& device, const string& dev );
+ int shrinkVolume( const string& device, const list<string>& devs );
+ bool deviceToUuid( const string& device, string& uuid );
+
+ int doRemove( Volume* v );
+
+ static storage::CType staticType() { return storage::BTRFSC; }
+ friend std::ostream& operator<< (std::ostream&, const BtrfsCo& );
+
+ int commitChanges( CommitStage stage, Volume* vol );
+ void getToCommit( storage::CommitStage stage, list& col,
+ list& vo ) const;
+
+ int removeVolume( Volume* v );
+ int removeVolume( Volume* v, bool quiet );
+ int removeUuid( const string& uuid );
+ bool equalContent( const Container& rhs ) const;
+ void saveData(xmlNode* node) const;
+
+ virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
+ virtual void logData(const string& Dir) const;
+
+
+ protected:
+ // iterators over BTRFS volumes
+ // protected typedefs for iterators over BTRFS volumes
+ typedef CastIterator BtrfsInter;
+ typedef CastIterator BtrfsCInter;
+ template< class Pred >
+ struct BtrfsPI { typedef ContainerIter type; };
+ template< class Pred >
+ struct BtrfsCPI { typedef ContainerIter type; };
+ typedef CheckFnc<const Btrfs> CheckFncBtrfs;
+ typedef CheckerIterator< CheckFncBtrfs, BtrfsPI<CheckFncBtrfs>::type,
+ BtrfsInter, Btrfs > BtrfsPIterator;
+ typedef CheckerIterator< CheckFncBtrfs, BtrfsCPI<CheckFncBtrfs>::type,
+ BtrfsCInter, const Btrfs > BtrfsCPIterator;
+ typedef DerefIterator BtrfsIter;
+ typedef DerefIterator ConstBtrfsIter;
+ typedef IterPair<BtrfsIter> BtrfsPair;
+ typedef IterPair<ConstBtrfsIter> ConstBtrfsPair;
+
+ BtrfsPair btrfsPair( bool (* Check)( const Btrfs& )=NULL)
+ {
+ return( BtrfsPair( btrfsBegin( Check ), btrfsEnd( Check ) ));
+ }
+ BtrfsIter btrfsBegin( bool (* Check)( const Btrfs& )=NULL)
+ {
+ IterPair<BtrfsInter> p( (BtrfsInter(begin())), (BtrfsInter(end())) );
+ return( BtrfsIter( BtrfsPIterator( p, Check )) );
+ }
+ BtrfsIter btrfsEnd( bool (* Check)( const Btrfs& )=NULL)
+ {
+ IterPair<BtrfsInter> p( (BtrfsInter(begin())), (BtrfsInter(end())) );
+ return( BtrfsIter( BtrfsPIterator( p, Check, true )) );
+ }
+
+ ConstBtrfsPair btrfsPair( bool (* Check)( const Btrfs& )=NULL) const
+ {
+ return( ConstBtrfsPair( btrfsBegin( Check ), btrfsEnd( Check ) ));
+ }
+ ConstBtrfsIter btrfsBegin( bool (* Check)( const Btrfs& )=NULL) const
+ {
+ IterPair<BtrfsCInter> p( (BtrfsCInter(begin())), (BtrfsCInter(end())) );
+ return( ConstBtrfsIter( BtrfsCPIterator( p, Check )) );
+ }
+ ConstBtrfsIter btrfsEnd( bool (* Check)( const Btrfs& )=NULL) const
+ {
+ IterPair<BtrfsCInter> p( (BtrfsCInter(begin())), (BtrfsCInter(end())) );
+ return( ConstBtrfsIter( BtrfsCPIterator( p, Check, true )) );
+ }
+
+ void getBtrfsData(SystemInfo& systeminfo);
+ bool findBtrfs( const string& uuid, BtrfsIter& i );
+ void addBtrfs( Btrfs* m );
+
+ virtual void print( std::ostream& s ) const { s << *this; }
+ virtual Container* getCopy() const { return( new BtrfsCo( *this ) ); }
+
+ private:
+
+ BtrfsCo& operator=(const BtrfsCo&); // disallow
+
+ };
+
+}
+
+#endif
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Container.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Container.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Container.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Container.cc Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -19,64 +19,105 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
-#include <iostream>
+#include <ostream>
#include <algorithm>
#include <list>
-#include "y2storage/Container.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/Storage.h"
-#include "y2storage/AppUtil.h"
+#include "storage/Container.h"
+#include "storage/SystemCmd.h"
+#include "storage/Storage.h"
+#include "storage/AppUtil.h"
+#include "storage/Device.h"
+
+
+namespace storage
+{
+ using namespace std;
-using namespace std;
-using namespace storage;
-Container::Container( Storage * const s, const string& Name, CType t ) :
- sto(s), nm(Name)
+ /* This is our constructor for Container used for containers created via
+ the storage interface. This is recognisable by the fact that it does
+ not have a parameter of type SystemInfo or xmlNode. */
+ Container::Container(Storage* s, const string& name, const string& device, CType t)
+ : Device(name, device), sto(s), typ(t), ronly(false)
{
- del = silent = ronly = create = false;
- dev = "/dev/" + nm;
- size_k = mnr = mjr = 0;
- typ = t;
- y2deb("constructed cont " << nm);
+ y2deb("constructed Container " << dev);
+
+ assert(!nm.empty() && !dev.empty());
}
-Container::~Container()
+
+ /* This is our constructor for Container used during detection. This is
+ recognisable by the fact that it has an parameter of type
+ SystemInfo. */
+ Container::Container(Storage* s, const string& name, const string& device, CType t,
+ SystemInfo& systeminfo)
+ : Device(name, device, systeminfo), sto(s), typ(t), ronly(false)
{
- for( PlainIterator i=begin(); i!=end(); i++ )
- {
- delete( *i );
- }
- y2deb("destructed cont " << dev);
+ y2deb("constructed Container " << dev);
+
+ assert(!nm.empty() && !dev.empty());
+ assert(!s->testmode());
}
-static bool notDeleted( const Volume& v )
- { return( !v.deleted()); }
-unsigned Container::numVolumes() const
+ /* This is our constructor for Container used during fake detection in
+ testmode. This is recognisable by the fact that it has an parameter of
+ type xmlNode. */
+ Container::Container(Storage* s, CType t, const xmlNode* node)
+ : Device(node), sto(s), typ(t), ronly(false)
{
- ConstVolPair p = volPair( notDeleted );
- return( p.length() );
+ getChildValue(node, "readonly", ronly);
+
+ y2deb("constructed Container " << dev);
+
+ assert(s->testmode());
}
-bool Container::isEmpty() const
+
+ /* This is our copy-constructor for Container. Every class derived from
+ Container needs an equivalent one. */
+ Container::Container(const Container& c)
+ : Device(c), sto(c.sto), typ(c.typ), ronly(c.ronly)
+ {
+ y2deb("copy-constructed Container " << dev);
+ }
+
+
+ Container::~Container()
{
- ConstVolPair p = volPair( notDeleted );
- return( p.empty() );
+ clearPointerList(vols);
+ y2deb("destructed Container " << dev);
}
-bool Container::sameDevice( const string& device ) const
+
+ void
+ Container::saveData(xmlNode* node) const
+ {
+ Device::saveData(node);
+
+ if (ronly)
+ setChildValue(node, "readonly", ronly);
+ }
+
+
+ bool
+ Container::isEmpty() const
{
- string d = normalizeDevice(device);
- return( d==dev ||
- find( alt_names.begin(), alt_names.end(), d )!=alt_names.end() );
+ ConstVolPair p = volPair(Volume::notDeleted);
+ return p.empty();
}
+bool Container::isPartitionable() const
+ {
+ return( typ==DISK || typ==DMRAID || typ==DMMULTIPATH || typ==MDPART );
+ }
+bool Container::isDeviceUsable() const
+ {
+ return( typ==DISK || typ==DMRAID || typ==DMMULTIPATH || typ==MDPART );
+ }
bool Container::stageDecrease(const Volume& v)
{
@@ -98,18 +139,18 @@
return v.needRemount() || v.needFstabUpdate();
}
-int Container::getToCommit( CommitStage stage, list& col,
- list& vol )
+
+void
+Container::getToCommit(CommitStage stage, list& col, list& vol) const
{
- int ret = 0;
unsigned long oco = col.size();
unsigned long ovo = vol.size();
switch( stage )
{
case DECREASE:
{
- VolPair p = volPair( stageDecrease );
- for( VolIterator i=p.begin(); i!=p.end(); ++i )
+ ConstVolPair p = volPair( stageDecrease );
+ for( ConstVolIterator i=p.begin(); i!=p.end(); ++i )
vol.push_back( &(*i) );
if( deleted() )
col.push_back( this );
@@ -117,8 +158,8 @@
break;
case INCREASE:
{
- VolPair p = volPair(stageIncrease);
- for( VolIterator i=p.begin(); i!=p.end(); ++i )
+ ConstVolPair p = volPair(stageIncrease);
+ for( ConstVolIterator i=p.begin(); i!=p.end(); ++i )
vol.push_back( &(*i) );
if( created() )
col.push_back( this );
@@ -126,26 +167,25 @@
break;
case FORMAT:
{
- VolPair p = volPair( stageFormat );
- for( VolIterator i=p.begin(); i!=p.end(); ++i )
+ ConstVolPair p = volPair( stageFormat );
+ for( ConstVolIterator i=p.begin(); i!=p.end(); ++i )
vol.push_back( &(*i) );
}
break;
case MOUNT:
{
- VolPair p = volPair( stageMount );
- for( VolIterator i=p.begin(); i!=p.end(); ++i )
+ ConstVolPair p = volPair( stageMount );
+ for( ConstVolIterator i=p.begin(); i!=p.end(); ++i )
vol.push_back( &(*i) );
}
break;
- default:
+ case SUBVOL:
break;
}
if( col.size()!=oco || vol.size()!=ovo )
- y2mil("ret:" << ret << " stage:" << stage << " col:" << col.size() << " vol:" <<
- vol.size());
- return( ret );
- }
+ y2mil("stage:" << stage << " col:" << col.size() << " vol:" << vol.size());
+}
+
int Container::commitChanges( CommitStage stage, Volume* vol )
{
@@ -197,6 +237,8 @@
vol->fstabUpdateDone();
}
break;
+ case SUBVOL:
+ break;
default:
ret = VOLUME_COMMIT_UNKNOWN_STAGE;
@@ -213,17 +255,20 @@
return( ret );
}
-void Container::getCommitActions( list& l ) const
+
+void
+Container::getCommitActions(list<commitAction>& l) const
{
ConstVolPair p = volPair();
for( ConstVolIterator i=p.begin(); i!=p.end(); ++i )
- if( !i->silent() )
+ if( !i->isSilent() )
i->getCommitActions( l );
}
-string Container::createText( bool doing ) const
+
+Text Container::createText( bool doing ) const
{
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by device name e.g. /dev/hda1
@@ -237,9 +282,9 @@
return( txt );
}
-string Container::removeText( bool doing ) const
+Text Container::removeText( bool doing ) const
{
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by device name e.g. /dev/hda1
@@ -255,25 +300,25 @@
int Container::doCreate( Volume * v )
{
- y2war("invalid container:" << type_names[typ] << " name:" << name());
+ y2war("invalid container:" << toString(typ) << " name:" << name());
return( CONTAINER_INVALID_VIRTUAL_CALL );
}
int Container::doRemove( Volume * v )
{
- y2war("invalid container:" << type_names[typ] << " name:" << name());
+ y2war("invalid container:" << toString(typ) << " name:" << name());
return( CONTAINER_INVALID_VIRTUAL_CALL );
}
int Container::doResize( Volume * v )
{
- y2war("invalid container:" << type_names[typ] << " name:" << name());
+ y2war("invalid container:" << toString(typ) << " name:" << name());
return( CONTAINER_INVALID_VIRTUAL_CALL );
}
int Container::removeVolume( Volume * v )
{
- y2war("invalid container:" << type_names[typ] << " name:" << name());
+ y2war("invalid container:" << toString(typ) << " name:" << name());
return( CONTAINER_INVALID_VIRTUAL_CALL );
}
@@ -282,6 +327,14 @@
return( VOLUME_RESIZE_UNSUPPORTED_BY_CONTAINER );
}
+
+ void
+ Container::addToList(Volume* e)
+ {
+ pointerIntoSortedList<Volume>(vols, e);
+ }
+
+
bool Container::removeFromList( Volume* e )
{
bool ret=false;
@@ -290,11 +343,11 @@
++i;
if( i!=vols.end() )
{
- delete( *i );
+ delete *i;
vols.erase( i );
ret = true;
}
- y2milestone( "P:%p ret:%d", e, ret );
+ y2mil("P:" << e << " ret:" << ret);
return( ret );
}
@@ -306,14 +359,11 @@
void Container::setExtError( const SystemCmd& cmd, bool serr ) const
{
- const string& s = serr ? cmd.stderr() : cmd.stdout();
- if( s.size()>0 )
- {
+ string s = boost::join(serr ? cmd.stderr() : cmd.stdout(), "\n");
+ if (!s.empty())
sto->setExtError( cmd.cmd() + ":\n" + s );
- }
else
- y2warning( "called with empty %s cmd:%s",
- (serr?"stderr":"stdout"), cmd.cmd().c_str());
+ y2war("called with empty " << (serr?"stderr":"stdout") << " cmd:" << cmd.cmd());
}
bool Container::findVolume( const string& device, Volume*& vol )
@@ -335,96 +385,59 @@
void Container::getInfo(storage::ContainerInfo& tinfo) const
{
- Container::ConstVolPair vp = volPair( Volume::notDeleted );
info.type = type();
info.name = name();
info.device = device();
- info.volcnt = vp.length();
- info.usedByType = uby.type();
- info.usedByName = uby.name();
- info.usedByDevice = uby.device();
+
+ info.udevPath = udevPath();
+ info.udevId = boost::join(udevId(), " ");
+
+ info.usedBy = list<UsedByInfo>(uby.begin(), uby.end());
+
+ if (uby.empty())
+ {
+ info.usedByType = UB_NONE;
+ info.usedByDevice = "";
+ }
+ else
+ {
+ info.usedByType = uby.front().type();
+ info.usedByDevice = uby.front().device();
+ }
+
info.readonly = readonly();
tinfo = info;
}
-namespace storage
-{
-
std::ostream& operator<< ( std::ostream& s, const Container &c )
{
- s << "Type:" << Container::type_names[c.typ]
- << " Name:" << c.nm
- << " Device:" << c.dev
- << " Vcnt:" << c.vols.size();
- if( c.del )
- s << " deleted";
- if( c.create )
- s << " created";
+ s << "CType:" << toString(c.typ)
+ << " " << dynamic_cast(c);
if( c.ronly )
s << " readonly";
- if( c.silent )
- s << " silent";
- s << c.uby;
- return( s );
+ if (!c.uby.empty())
+ s << " usedby:" << c.uby;
+ if (!c.alt_names.empty())
+ s << " alt_names:" << c.alt_names;
+ return s;
}
-}
-void
-Container::logDifference( const Container& c ) const
-{
- y2mil(getDiffString(c));
-}
-
-string
-Container::getDiffString( const Container& c ) const
- {
- string ret = "Name:" + nm;
- if( nm!=c.nm )
- ret += "-->"+c.nm;
- if( typ!=c.typ )
- ret += " Type:" + Container::type_names[typ] + "-->" +
- Container::type_names[c.typ];
- if( dev!=c.dev )
- ret += " Device:" + dev + "-->" + c.dev;
- if( del!=c.del )
- {
- if( c.del )
- ret += " -->deleted";
- else
- ret += " deleted-->";
- }
- if( create!=c.create )
- {
- if( c.create )
- ret += " -->created";
- else
- ret += " created-->";
- }
- if( ronly!=c.ronly )
- {
- if( c.ronly )
- ret += " -->readonly";
- else
- ret += " readonly-->";
- }
- if( silent!=c.silent )
- {
- if( c.silent )
- ret += " -->silent";
- else
- ret += " silent-->";
- }
- if( uby!=c.uby )
- {
- std::ostringstream b;
- classic(b);
- b << uby << "-->" << string(c.uby);
- ret += b.str();
- }
- return( ret );
+
+ void
+ Container::logDifference(std::ostream& log, const Container& rhs) const
+ {
+ Device::logDifference(log, rhs);
+
+ logDiffEnum(log, "type", typ, rhs.typ);
+
+ logDiff(log, "readonly", ronly, rhs.ronly);
+ logDiff(log, "silent", silent, rhs.silent);
+
+ logDiff(log, "usedby", uby, rhs.uby);
}
+
bool Container::equalContent( const Container& rhs ) const
{
return( typ==rhs.typ && nm==rhs.nm && dev==rhs.dev && del==rhs.del &&
@@ -432,49 +445,34 @@
uby==rhs.uby );
}
-bool Container::compareContainer( const Container* c, bool verbose ) const
+
+ bool
+ Container::compareContainer(const Container& rhs, bool verbose) const
{
- bool ret = typ == c->typ;
- if( !ret )
+ assert(typ != CUNKNOWN);
+ if (typ == CUNKNOWN)
{
- if( verbose )
- y2mil(getDiffString( *c ));
+ y2err("unknown container type lhs:" << *this);
+ return false;
}
- else
+
+ assert(typ == rhs.typ);
+ if (typ != rhs.typ)
{
- ret = equalContent( *c );
- if( !ret && verbose )
- logDifference( *c );
- if( typ==COTYPE_LAST_ENTRY || typ==CUNKNOWN )
- y2err( "Unknown Container:" << *c );
+ y2err("comparing different container types lhs:" << *this << " rhs:" << rhs);
+ return false;
}
- return( ret );
- }
+ bool ret = equalContent(rhs);
+ if (!ret && verbose)
+ {
+ std::ostringstream log;
+ prepareLogStream(log);
+ logDifferenceWithVolumes(log, rhs);
+ y2mil(log.str());
+ }
-Container& Container::operator= ( const Container& rhs )
- {
- y2deb("operator= from " << rhs.nm);
- typ = rhs.typ;
- nm = rhs.nm;
- dev = rhs.dev;
- del = rhs.del;
- mjr = rhs.mjr;
- mnr = rhs.mnr;
- size_k = rhs.size_k;
- create = rhs.create;
- ronly = rhs.ronly;
- silent = rhs.silent;
- uby = rhs.uby;
- return( *this );
- }
-
-Container::Container( const Container& rhs ) : sto(rhs.sto)
- {
- y2deb("constructed cont by copy constructor from " << rhs.nm);
- *this = rhs;
+ return ret;
}
-const string Container::type_names[] = { "UNKNOWN", "DISK", "MD", "LOOP", "LVM",
- "DM", "DMRAID", "NFS", "DMMULTIPATH", "MDPART" };
-
+}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Container.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Container.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Container.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Container.h Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -25,14 +25,17 @@
#include <list>
-#include "y2storage/Volume.h"
-#include "y2storage/StorageTypes.h"
-#include "y2storage/StorageTmpl.h"
+#include "storage/Volume.h"
+#include "storage/StorageTypes.h"
+#include "storage/StorageTmpl.h"
+
namespace storage
{
+ using std::list;
+
-class Container
+ class Container : public Device
{
friend class Storage;
protected:
@@ -65,26 +68,24 @@
{ return( !(*this ( const Container& rhs ) const
{ return( !(*this<=rhs) ); }
- bool sameDevice( const string& device ) const;
virtual bool equalContent( const Container& rhs ) const;
- virtual string getDiffString( const Container& c ) const;
- virtual void logDifference( const Container& c ) const;
- const std::list<string>& altNames() const { return( alt_names ); }
+ void logDifference(std::ostream& log, const Container& rhs) const;
+ virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const = 0;
- virtual void getCommitActions( std::liststorage::commitAction*& l ) const;
- virtual int getToCommit( storage::CommitStage stage,
- std::list& col,
- std::list& vol );
+ virtual void getCommitActions(list<commitAction>& l) const;
+ virtual void getToCommit(storage::CommitStage stage, list& col,
+ list& vol) const;
virtual int commitChanges( storage::CommitStage stage );
virtual int commitChanges( storage::CommitStage stage, Volume* vol );
virtual void changeDeviceName( const string& old, const string& nw ) {}
- unsigned numVolumes() const;
bool isEmpty() const;
void getInfo( storage::ContainerInfo& info ) const;
bool findVolume( const string& device, Volume*& vol );
+ static bool notDeleted(const Container& c) { return !c.deleted(); }
+
// iterators over volumes of a container
protected:
// protected typedefs for iterators over volumes
@@ -154,36 +155,38 @@
}
public:
- Container( Storage * const, const string& Name, storage::CType typ );
- Container( const Container& );
- Storage * getStorage() const { return sto; }
+
+ Container(Storage* s, const string& name, const string& device, CType typ);
+ Container(Storage* s, const string& name, const string& device, CType typ,
+ SystemInfo& systemInfo);
+ Container(Storage* s, CType typ, const xmlNode* node);
+ Container(const Container& c);
virtual ~Container();
- const string& name() const { return nm; }
- const string& device() const { return dev; }
- storage::CType type() const { return typ; }
- bool deleted() const { return del; }
- bool created() const { return create; }
- void setDeleted( bool val=true ) { del=val; }
- void setCreated( bool val=true ) { create=val; }
- void setSilent( bool val=true ) { silent=val; }
-
- void clearUsedBy() { uby.clear(); }
- void setUsedBy(storage::UsedByType ub_type, const string& ub_name) { uby.set(ub_type, ub_name); }
- const storage::usedBy& getUsedBy() const { return uby; }
- storage::UsedByType getUsedByType() const { return uby.type(); }
+
+ void saveData(xmlNode* node) const;
+
+ Storage* getStorage() const { return sto; }
+ const Storage* getStorageConst() const { return sto; }
+ CType type() const { return typ; }
+ bool isPartitionable() const;
+ static bool Partitionable( const Container&d )
+ { return( d.isPartitionable() ); }
+ bool isDeviceUsable() const;
+ static bool DeviceUsable( const Container&d )
+ { return( d.isDeviceUsable() ); }
bool readonly() const { return ronly; }
- unsigned long minorNr() const { return mnr; }
- unsigned long majorNr() const { return mjr; }
- unsigned long long sizeK() const { return size_k; }
- virtual string removeText(bool doing=true) const;
- virtual string createText(bool doing=true) const;
+
+ virtual Text removeText(bool doing) const;
+ virtual Text createText(bool doing) const;
virtual int resizeVolume( Volume* v, unsigned long long newSize );
virtual int removeVolume( Volume* v );
static storage::CType staticType() { return storage::CUNKNOWN; }
friend std::ostream& operator<< (std::ostream& s, const Container &c );
- virtual Container* getCopy() const { return( new Container( *this ) ); }
- bool compareContainer( const Container* c, bool verbose ) const;
+
+ virtual Container* getCopy() const = 0; // Container is always derived
+
+ bool compareContainer(const Container& rhs, bool verbose) const;
void setExtError( const string& txt ) const;
void setExtError( const SystemCmd& cmd, bool serr=true ) const;
@@ -197,37 +200,31 @@
PlainIterator end() { return vols.end(); }
virtual void print( std::ostream& s ) const { s << *this; }
- void addToList( Volume* e )
- { pointerIntoSortedList<Volume>( vols, e ); }
+ void addToList(Volume* e);
bool removeFromList( Volume* e );
virtual int doCreate( Volume * v );
virtual int doRemove( Volume * v );
virtual int doResize( Volume * v );
- virtual void logData( const string& Dir ) {}
- Container& operator=( const Container& );
+
+ virtual void logData(const string& Dir) const {}
static bool stageDecrease(const Volume& v);
static bool stageIncrease(const Volume& v);
static bool stageFormat(const Volume& v);
static bool stageMount(const Volume& v);
- static const string type_names[COTYPE_LAST_ENTRY];
-
- Storage * const sto;
- storage::CType typ;
- string nm;
- string dev;
- bool del;
- bool create;
- bool silent;
+ Storage* const sto;
+ const CType typ;
bool ronly;
- storage::usedBy uby;
- std::list<string> alt_names;
- unsigned long long size_k;
- unsigned long mnr;
- unsigned long mjr;
+
VCont vols;
- mutable storage::ContainerInfo info;
+
+ mutable storage::ContainerInfo info; // workaround for broken ycp bindings
+
+ private:
+
+ Container& operator=(const Container&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasd.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasd.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasd.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasd.cc Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -19,105 +19,92 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
-#include <iostream>
#include
-
#include <string>
-#include <sstream>
+#include <ostream>
+#include <fstream>
#include <iomanip>
#include
-#include "y2storage/SystemCmd.h"
-#include "y2storage/ProcPart.h"
-#include "y2storage/Storage.h"
-#include "y2storage/OutputProcessor.h"
-#include "y2storage/Dasd.h"
-#include "y2storage/StorageDefines.h"
+#include "storage/SystemCmd.h"
+#include "storage/ProcParts.h"
+#include "storage/Storage.h"
+#include "storage/OutputProcessor.h"
+#include "storage/Dasd.h"
+#include "storage/StorageDefines.h"
+#include "storage/SystemInfo.h"
+#include "storage/Dasdview.h"
+
+
+namespace storage
+{
+ using namespace std;
-using namespace std;
-using namespace storage;
-Dasd::Dasd( Storage * const s, const string& Name,
- unsigned long long SizeK ) :
- Disk(s,Name,SizeK)
+ Dasd::Dasd(Storage* s, const string& name, const string& device, unsigned long long SizeK,
+ SystemInfo& systeminfo)
+ : Disk(s, name, device, SizeK, systeminfo), fmt(DASDF_NONE)
{
- fmt = DASDF_NONE;
- y2deb("constructed dasd " << dev);
+ y2deb("constructed Dasd " << dev);
}
-Dasd::~Dasd()
+
+ Dasd::Dasd(const Dasd& c)
+ : Disk(c), fmt(c.fmt)
{
- y2deb("destructed dasd " << dev);
+ y2deb("copy-constructed Dasd from " << c.dev);
}
-bool Dasd::detectPartitionsFdasd( ProcPart& ppart )
+
+ Dasd::~Dasd()
+ {
+ y2deb("destructed Dasd " << dev);
+ }
+
+
+ bool
+ Dasd::detectPartitionsFdasd(SystemInfo& systeminfo)
{
bool ret = true;
- string cmd_line = FDASDBIN " -p " + quote(device());
- system_stderr.erase();
- y2milestone( "executing cmd:%s", cmd_line.c_str() );
- SystemCmd Cmd( cmd_line );
- y2milestone( "retcode:%d", Cmd.retcode() );
- if( Cmd.retcode() == 0 )
- checkFdasdOutput( Cmd, ppart );
- y2milestone( "ret:%d partitons:%zd", ret, vols.size() );
+ checkFdasdOutput(systeminfo);
+ y2mil("ret:" << ret << " partitions:" << vols.size());
return( ret );
}
-bool Dasd::detectPartitions( ProcPart& ppart )
+
+ bool
+ Dasd::detectPartitions(SystemInfo& systeminfo)
{
bool ret = true;
- string cmd_line = DASDVIEWBIN " -x " + quote(device());
- system_stderr.erase();
+
detected_label = "dasd";
setLabelData( "dasd" );
- y2milestone( "executing cmd:%s", cmd_line.c_str() );
- SystemCmd Cmd( cmd_line );
- y2milestone( "retcode:%d", Cmd.retcode() );
- if( Cmd.retcode() == 0 )
- {
- if( Cmd.select( "^format" )>0 )
- {
- string tmp = *Cmd.getLine(0, true);
- y2milestone( "Format line:%s", tmp.c_str() );
- tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
- tmp = boost::to_lower_copy(extractNthWord(4, tmp), locale::classic());
- if( tmp == "cdl" )
- fmt = DASDF_CDL;
- else if( tmp == "ldl" )
- fmt = DASDF_LDL;
- }
- getGeometry( Cmd, cyl, head, sector );
- new_cyl = cyl;
- new_head = head;
- new_sector = sector;
- y2milestone( "After dasdview Head:%u Sector:%u Cylinder:%lu SizeK:%llu",
- head, sector, cyl, size_k );
- byte_cyl = head * sector * 512;
- y2milestone( "byte_cyl:%lu", byte_cyl );
+
+ Dasdview dasdview(device());
+ new_geometry = geometry = dasdview.getGeometry();
+ fmt = dasdview.getDasdFormat();
+ ronly = fmt != DASDF_CDL;
+
if( size_k==0 )
{
- size_k = (head*sector*cyl)/2;
- y2milestone( "New SizeK:%llu", size_k );
+ size_k = geometry.sizeK();
+ y2mil("New SizeK:" << size_k);
}
- y2mil( "fmt:" << fmt );
+
switch( fmt )
{
case DASDF_CDL:
- ret = Dasd::detectPartitionsFdasd(ppart);
+ ret = Dasd::detectPartitionsFdasd(systeminfo);
break;
case DASDF_LDL:
{
max_primary = 1;
- unsigned long long s = cylinderToKb(cyl);
- Partition *p = new Partition( *this, 1, s, 0, cyl,
- PRIMARY, Partition::ID_LINUX,
- false );
- if( ppart.getSize( p->device(), s ))
+ unsigned long long s = cylinderToKb(cylinders());
+ Partition *p = new Partition(*this, getPartName(1), getPartDevice(1), 1,
+ systeminfo, s, Region(0, cylinders()), PRIMARY);
+ const ProcParts& parts = systeminfo.getProcParts();
+ if (parts.getSize(p->device(), s))
{
p->setSize( s );
}
@@ -128,105 +115,84 @@
default:
break;
}
+
+ y2mil("ret:" << ret << " partitions:" << vols.size() << " detected label:" << label);
+ y2mil("geometry:" << geometry << " fmt:" << toString(fmt) << " readonly:" << ronly);
+ return ret;
+ }
+
+
+ bool
+ Dasd::checkPartitionsValid(SystemInfo& systeminfo, const list& pl) const
+ {
+ const ProcParts& parts = systeminfo.getProcParts();
+ const Fdasd& fdasd = systeminfo.getFdasd(dev);
+
+ list<string> ps = partitionsKernelKnowns(parts);
+ if (pl.size() != ps.size())
+ {
+ y2err("number of partitions fdasd and kernel see differs");
+ return false;
}
- else
+
+ for (list::const_iterator i = pl.begin(); i != pl.end(); ++i)
{
- new_sector = sector = 96;
- y2milestone( "new sector:%u", sector );
+ const Partition& p = **i;
+
+ Fdasd::Entry entry;
+ if (fdasd.getEntry(p.nr(), entry))
+ {
+ // maybe too strict but should be ok
+
+ Region head_fdasd = entry.headRegion;
+ Region head_kernel = p.detectSysfsBlkRegion() / (geometry.headSize() / 512);
+
+ if (head_fdasd != head_kernel)
+ {
+ y2err("region mismatch dev:" << dev << " nr:" << p.nr() << " head_fdasd:" <<
+ head_fdasd << " head_kernel:" << head_kernel);
+ return false;
+ }
+ }
}
- byte_cyl = head * sector * 512;
- y2milestone( "byte_cyl:%lu", byte_cyl );
- y2milestone( "ret:%d partitons:%zd detected label:%s", ret, vols.size(),
- label.c_str() );
- ronly = fmt!=DASDF_CDL;
- y2milestone( "fmt:%d readonly:%d", fmt, ronly );
- return( ret );
+
+ return true;
}
+
bool
-Dasd::scanFdasdLine( const string& Line, unsigned& nr, unsigned long& start,
- unsigned long& csize )
+ Dasd::checkFdasdOutput(SystemInfo& systeminfo)
{
- unsigned long StartM, EndM;
- string PartitionType, TInfo;
+ const ProcParts& parts = systeminfo.getProcParts();
+ const Fdasd& fdasd = systeminfo.getFdasd(dev);
- y2deb("Line:" << Line);
- std::istringstream Data( Line );
- classic(Data);
-
- nr=0;
- StartM = EndM = 0;
- string devname;
- Data >> devname >> StartM >> EndM;
- devname.erase(0,device().size());
- devname >> nr;
- y2milestone( "Fields Num:%d Start:%lu End:%lu", nr, StartM, EndM );
- if( nr>0 )
- {
- start = StartM/head;
- csize = EndM/head-start+1;
- if( start+csize > cylinders() )
- {
- csize = cylinders()-start;
- y2milestone( "new csize:%lu", csize );
- }
- y2milestone( "Fields Num:%d Start:%ld Size:%ld", nr, start, csize );
- }
- return( nr>0 );
- }
+ assert(geometry == fdasd.getGeometry());
-bool
-Dasd::checkFdasdOutput( SystemCmd& cmd, ProcPart& ppart )
- {
- int cnt;
- string line;
- string tmp;
list pl;
- Regex part( "^"+device()+"[0123456789]+$" );
- cmd.select( device() );
- cnt = cmd.numLines();
- for( int i=0; inum < range )
{
- unsigned long long s = cylinderToKb(c_size);
- Partition *p = new Partition( *this, pnr, s,
- c_start, c_size, PRIMARY,
- Partition::ID_LINUX, false );
- if( ppart.getSize( p->device(), s ))
+ unsigned long long s = cylinderToKb(it->cylRegion.len());
+ Partition *p = new Partition(*this, getPartName(it->num), getPartDevice(it->num),
+ it->num, systeminfo, s, it->cylRegion, PRIMARY);
+ if (parts.getSize(p->device(), s))
{
p->setSize( s );
}
pl.push_back( p );
}
else
- y2warning( "partition nr %d outside range %lu", pnr, range );
- }
- }
+ y2war("partition nr " << it->num << " outside range " << range);
}
- y2mil( "nm:" << nm );
- string reg = nm;
- if( !reg.empty() && reg.find( '/' )!=string::npos &&
- isdigit(reg[reg.length()-1]) )
- reg += "p";
- reg += "[0-9]+";
- list<string> ps = ppart.getMatchingEntries( reg );
- y2mil( "regex " << reg << " ps " << ps );
+
+ y2mil("nm:" << nm);
unsigned long dummy = 0;
- if( !checkPartedValid( ppart, nm, pl, dummy ) )
+ if (!checkPartedValid(systeminfo, pl, dummy))
{
- string txt = sformat(
+ Text txt = sformat(
// popup text %1$s is replaced by disk name e.g. /dev/hda
_("The partitioning on disk %1$s is not readable by\n"
"the partitioning tool fdasd, which is used to change the\n"
@@ -247,58 +213,6 @@
return( true );
}
-void Dasd::getGeometry( SystemCmd& cmd, unsigned long& c,
- unsigned& h, unsigned& s )
- {
- string tmp;
- unsigned long val;
- if( cmd.select( "cylinders" )>0 )
- {
- val = 0;
- tmp = *cmd.getLine(0, true);
- y2milestone( "Cylinder line:%s", tmp.c_str() );
- tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
- tmp = extractNthWord( 3, tmp );
- tmp >> val;
- y2mil( "val:" << val );
- c=val;
- }
- if( cmd.select( "tracks per" )>0 )
- {
- val = 0;
- tmp = *cmd.getLine(0, true);
- y2milestone( "Tracks line:%s", tmp.c_str() );
- tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
- tmp = extractNthWord( 3, tmp );
- tmp >> val;
- y2mil( "val:" << val );
- h=val;
- }
- if( cmd.select( "blocks per" )>0 )
- {
- val = 0;
- tmp = *cmd.getLine(0, true);
- y2milestone( "Blocks line:%s", tmp.c_str() );
- tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
- tmp = extractNthWord( 3, tmp );
- tmp >> val;
- y2mil( "val:" << val );
- s=val;
- }
- if( cmd.select( "blocksize" )>0 )
- {
- val = 0;
- tmp = *cmd.getLine(0, true);
- y2milestone( "Bytes line:%s", tmp.c_str() );
- tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
- tmp = extractNthWord( 3, tmp );
- tmp >> val;
- y2mil( "val:" << val );
- s*=val/512;
- }
- y2milestone( "c:%lu h:%u s:%u", c, h, s );
- }
-
int Dasd::doResize( Volume* v )
{
@@ -312,11 +226,11 @@
int Dasd::removePartition( unsigned nr )
{
- y2milestone( "begin nr %u", nr );
+ y2mil("begin nr:" << nr);
int ret = Disk::removePartition( nr );
if( ret==0 )
{
- PartPair p = partPair( notDeleted );
+ PartPair p = partPair(Partition::notDeleted);
changeNumbers( p.begin(), p.end(), nr, -1 );
}
y2mil("ret:" << ret);
@@ -327,9 +241,9 @@
unsigned long len, string& device,
bool checkRelaxed )
{
- y2milestone( "begin type %d at %ld len %ld relaxed:%d", type, start, len,
- checkRelaxed );
- int ret = createChecks( type, start, len, checkRelaxed );
+ y2mil("begin type:" << toString(type) << " start:" << start << " len:" << len << " relaxed:"
+ << checkRelaxed);
+ int ret = createChecks(type, Region(start, len), checkRelaxed);
int number = 0;
if( ret==0 )
{
@@ -340,7 +254,7 @@
}
else
{
- PartPair p = partPair( notDeleted );
+ PartPair p = partPair(Partition::notDeleted);
number = 1;
PartIter i = p.begin();
while( i!=p.end() && i->cylStart()setCreated();
device = p->device();
addToList( p );
@@ -364,11 +278,11 @@
return( ret );
}
-string Dasd::fdasdText() const
+Text Dasd::fdasdText() const
{
- string txt;
+ Text txt;
// displayed text during action, %1$s is replaced by disk name (e.g. /dev/dasda),
- txt = sformat( _("Executing fdasd for disk %1$s..."), dev.c_str() );
+ txt = sformat( _("Executing fdasd for disk %1$s"), dev.c_str() );
return( txt );
}
@@ -382,12 +296,12 @@
string inpname = getStorage()->tmpDir()+"/fdasd_inp";
ofstream inpfile( inpname.c_str() );
classic(inpfile);
- PartPair p = partPair( notDeleted );
+ PartPair p = partPair(Partition::notDeleted);
PartIter i = p.begin();
while( i!=p.end() )
{
- string start = decString(i->cylStart()*new_head);
- string end = decString((i->cylEnd()+1)*new_head-1);
+ string start = decString(i->cylStart() * new_geometry.heads);
+ string end = decString((i->cylEnd() + 1) * new_geometry.heads - 1);
if( i->cylStart()==0 )
start = "first";
if( i->cylEnd()>=cylinders()-1 )
@@ -404,7 +318,7 @@
}
if( ret==0 )
{
- ProcPart ppart;
+ ProcParts parts;
p = partPair();
i = p.begin();
list rem_list;
@@ -418,13 +332,13 @@
if( i->created() )
{
unsigned long long s;
- getStorage()->waitForDevice( i->device() );
+ Storage::waitForDevice(i->device());
i->setCreated( false );
- if( ppart.getSize( i->device(), s ))
+ if (parts.getSize(i->device(), s))
{
i->setSize( s );
}
- ret = i->zeroIfNeeded();
+ ret = i->zeroIfNeeded();
}
++i;
}
@@ -441,68 +355,59 @@
return( ret );
}
-void Dasd::getCommitActions( list& l ) const
+
+void
+Dasd::getCommitActions(list<commitAction>& l) const
{
- y2mil( "begin:" << name() << " init_disk:" << init_disk );
+ y2mil("begin:" << name() << " init_disk:" << init_disk);
Disk::getCommitActions( l );
if( init_disk )
{
- list::iterator i = l.begin();
- while( i!=l.end() )
- {
- if( (*i)->stage==DECREASE )
- {
- delete( *i );
- i=l.erase( i );
- }
- else
- ++i;
- }
- l.push_front( new commitAction( DECREASE, staticType(),
- dasdfmtText(false), this, true ));
+ l.remove_if(stage_is(DECREASE));
+ l.push_front(commitAction(DECREASE, staticType(), dasdfmtText(false), this, true));
}
}
-string Dasd::dasdfmtTexts( bool single, const string& devs )
+
+ Text
+ Dasd::dasdfmtTexts(bool doing, const list<string>& devs)
{
- string txt;
- if( single )
+ Text txt;
+ if (doing)
{
- // displayed text during action, %1$s is replaced by disk name (e.g. dasda),
- txt = sformat( _("Executing dasdfmt for disk %1$s..."), devs.c_str() );
+ // displayed text during action, %1$s is replaced by disk name (e.g. dasda)
+ txt = sformat(_("Executing dasdfmt for disk %1$s",
+ "Executing dasdfmt for disks %1$s", devs.size()),
+ boost::join(devs, " ").c_str());
}
- else
+ else
{
- // displayed text during action, %1$s is replaced by list of disk names (e.g. dasda dasdb dasdc),
- txt = sformat( _("Executing dasdfmt for disks: %1$s..."), devs.c_str() );
+ // displayed text during action, %1$s is replaced by disk name (e.g. dasda)
+ txt = sformat(_("Execute dasdfmt on disk %1$s",
+ "Execute dasdfmt on disks %1$s", devs.size()),
+ boost::join(devs, " ").c_str());
}
- return( txt );
+ return txt;
}
-string Dasd::dasdfmtText( bool doing ) const
+
+ Text
+ Dasd::dasdfmtText(bool doing) const
{
- string txt;
- if( doing )
- {
- txt = dasdfmtTexts( true, dev );
- }
- else
- {
- // displayed text before action, %1$s is replaced by disk name (e.g. /dev/dasda),
- txt = sformat( _("Execute dasdfmt on disk %1$s"), dev.c_str() );
- }
- return( txt );
+ list<string> tmp;
+ tmp.push_back(dev);
+ return dasdfmtTexts(doing, tmp);
}
-int Dasd::getToCommit( CommitStage stage, list& col,
- list& vol )
- {
- int ret = 0;
+
+void
+Dasd::getToCommit(CommitStage stage, list& col, list& vol) const
+{
unsigned long oco = col.size();
unsigned long ovo = vol.size();
if( stage==DECREASE )
{
- VolPair p = volPair( stageDecrease );
+ ConstVolPair p = volPair( stageDecrease );
if( !p.empty() )
vol.push_back( &(*(p.begin())) );
if( deleted() || init_disk )
@@ -510,20 +415,20 @@
}
else if( stage==INCREASE )
{
- VolPair p = volPair(stageIncrease);
+ ConstVolPair p = volPair(stageIncrease);
if( !p.empty() )
vol.push_back( &(*(p.begin())) );
}
else
- ret = Disk::getToCommit( stage, col, vol );
+ Disk::getToCommit( stage, col, vol );
if( col.size()!=oco || vol.size()!=ovo )
- y2milestone( "ret:%d col:%zd vol:%zd", ret, col.size(), vol.size());
- return( ret );
- }
+ y2mil("stage:" << stage << " col:" << col.size() << " vol:" << vol.size());
+}
+
int Dasd::commitChanges( CommitStage stage )
{
- y2milestone( "name %s stage %d", name().c_str(), stage );
+ y2mil("name:" << name() << " stage:" << stage);
int ret = 0;
if( stage==DECREASE && init_disk )
{
@@ -546,7 +451,7 @@
int Dasd::doDasdfmt()
{
int ret = 0;
- y2milestone( "dasd:%s", device().c_str() );
+ y2mil("dasd:" << device());
list dl;
list<string> devs;
getStorage()->getDiskList( needDasdfmt, dl );
@@ -556,58 +461,56 @@
{
devs.push_back( undevDevice((*i)->device()) );
}
- y2mil( "devs:" << devs );
+ y2mil("devs:" << devs);
if( !silent )
{
- string txt = dasdfmtTexts( dl.size()==1, mergeString(devs) );
+ Text txt = dasdfmtTexts(true, devs);
getStorage()->showInfoCb( txt );
}
for( list<string>::iterator i = devs.begin(); i!=devs.end(); ++i )
{
- normalizeDevice(*i);
- *i = "-f " + quote(*i);
+ *i = "-f " + quote(normalizeDevice(*i));
}
- string cmd_line = DASDFMTBIN " -Y -P 4 -b 4096 -y -m 1 -d cdl " + mergeString(devs);
- y2milestone( "cmdline:%s", cmd_line.c_str() );
+ string cmd_line = DASDFMTBIN " -Y -P 4 -b 4096 -y -m 1 -d cdl " + boost::join(devs, " ");
+ y2mil("cmdline:" << cmd_line);
CallbackProgressBar cb = getStorage()->getCallbackProgressBarTheOne();
- ScrollBarHandler* sb = new DasdfmtScrollbar( cb );
+ ProgressBar* progressbar = new DasdfmtProgressBar( cb );
SystemCmd cmd;
- cmd.setOutputProcessor( sb );
+ cmd.setOutputProcessor(progressbar);
if( execCheckFailed( cmd, cmd_line ) )
{
ret = DASD_DASDFMT_FAILED;
}
if( ret==0 )
{
- ProcPart ppart;
+ SystemInfo systeminfo;
for( list::iterator i = dl.begin(); i!=dl.end(); ++i )
{
Dasd * ds = static_cast(*i);
- ds->detectPartitions( ppart );
+ ds->detectPartitions(systeminfo);
ds->resetInitDisk();
ds->removeFromMemory();
}
}
+ delete progressbar;
}
return( ret );
}
int Dasd::initializeDisk( bool value )
{
- y2milestone( "value:%d old:%d", value, init_disk );
+ y2mil("value:" << value << " old:" << init_disk);
int ret = 0;
if( init_disk != value )
{
init_disk = value;
if( init_disk )
{
- new_sector = sector = 96;
- new_head = head = 15;
- y2milestone( "new sector:%u head:%u", sector, head );
- size_k = (head*sector*cyl)/2;
- y2milestone( "new SizeK:%llu", size_k );
- byte_cyl = head * sector * 512;
- y2milestone( "new byte_cyl:%lu", byte_cyl );
+ new_geometry.heads = geometry.heads = 15;
+ new_geometry.sectors = geometry.sectors = 12;
+ y2mil("new geometry:" << geometry);
+ size_k = geometry.sizeK();
+ y2mil("new SizeK:" << size_k);
ret = destroyPartitionTable( "dasd" );
}
else
@@ -639,26 +542,21 @@
return( ret );
}
-Dasd& Dasd::operator= ( const Dasd& rhs )
- {
- y2deb("operator= from " << rhs.nm);
- *((Disk*)this) = rhs;
- fmt = rhs.fmt;
- return( *this );
- }
-
-Dasd::Dasd( const Dasd& rhs ) : Disk(rhs)
- {
- fmt = DASDF_NONE;
- y2deb("constructed dasd by copy constructor from " << rhs.nm);
- }
-namespace storage
-{
std::ostream& operator<< (std::ostream& s, const Dasd& d )
{
- s << *((Disk*)&d);
- s << " fmt:" << d.fmt;
- return( s );
+ s << dynamic_cast(d);
+ s << " fmt:" << toString(d.fmt);
+ return s;
}
+
+
+ static const string dasd_format_names[] = {
+ "NONE", "LDL", "CDL"
+ };
+
+ const vector<string> EnumInfoDasd::DasdFormat::names(dasd_format_names, dasd_format_names +
+ lengthof(dasd_format_names));
+
+
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasd.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasd.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasd.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasd.h Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -23,21 +23,30 @@
#ifndef DASD_H
#define DASD_H
-#include "y2storage/Disk.h"
+#include "storage/Disk.h"
+
namespace storage
{
+ using std::list;
+
+
+ class ProcParts;
-class SystemCmd;
-class ProcPart;
class Dasd : public Disk
{
friend class Storage;
+
public:
- Dasd( Storage * const s, const string& Name, unsigned long long Size );
- Dasd( const Dasd& rhs );
+
+ enum DasdFormat { DASDF_NONE, DASDF_LDL, DASDF_CDL };
+
+ Dasd(Storage* s, const string& name, const string& device, unsigned long long Size,
+ SystemInfo& systeminfo);
+ Dasd(const Dasd& c);
virtual ~Dasd();
+
int createPartition( storage::PartitionType type, long unsigned start,
long unsigned len, string& device,
bool checkRelaxed=false );
@@ -45,26 +54,22 @@
int changePartitionId( unsigned nr, unsigned id ) { return 0; }
int resizePartition( Partition* p, unsigned long newCyl );
int initializeDisk( bool value );
- string fdasdText() const;
- string dasdfmtText( bool doing ) const;
- static string dasdfmtTexts( bool single, const string& devs );
- void getCommitActions( std::liststorage::commitAction*& l ) const;
- int getToCommit( storage::CommitStage stage, std::list& col,
- std::list& vol );
+ Text fdasdText() const;
+ Text dasdfmtText( bool doing ) const;
+ static Text dasdfmtTexts(bool doing, const list<string>& devs);
+ void getCommitActions(list<commitAction>& l) const;
+ void getToCommit(storage::CommitStage stage, list& col,
+ list& vol) const;
int commitChanges( storage::CommitStage stage );
protected:
- enum DasdFormat { DASDF_NONE, DASDF_LDL, DASDF_CDL };
virtual void print( std::ostream& s ) const { s << *this; }
virtual Container* getCopy() const { return( new Dasd( *this ) ); }
- bool detectPartitionsFdasd(ProcPart& ppart);
- bool detectPartitions( ProcPart& ppart );
- bool checkFdasdOutput( SystemCmd& Cmd, ProcPart& ppart );
- bool scanFdasdLine( const string& Line, unsigned& nr,
- unsigned long& start, unsigned long& csize );
- void getGeometry( SystemCmd& cmd, unsigned long& c,
- unsigned& h, unsigned& s );
+ bool detectPartitionsFdasd(SystemInfo& systeminfo);
+ bool detectPartitions(SystemInfo& systeminfo);
+ virtual bool checkPartitionsValid(SystemInfo& systeminfo, const list& pl) const;
+ bool checkFdasdOutput(SystemInfo& systeminfo);
void redetectGeometry() {};
int doCreate( Volume* v ) { return(doFdasd()); }
int doRemove( Volume* v ) { return(init_disk?0:doFdasd()); }
@@ -73,13 +78,20 @@
int doSetType( Volume* v ) { return 0; }
int doCreateLabel() { return 0; }
int doDasdfmt();
+
DasdFormat fmt;
- Dasd& operator= ( const Dasd& rhs );
friend std::ostream& operator<< (std::ostream&, const Dasd& );
+ private:
+
+ Dasd& operator=(const Dasd&); // disallow
+
};
+
+ template <> struct EnumInfoDasd::DasdFormat { static const vector<string> names; };
+
}
#endif
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasdview.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasdview.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasdview.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasdview.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include "storage/Dasdview.h"
+#include "storage/StorageDefines.h"
+#include "storage/SystemCmd.h"
+
+
+namespace storage
+{
+
+ Dasdview::Dasdview(const string& device)
+ : dasd_format(Dasd::DASDF_NONE)
+ {
+ SystemCmd cmd(DASDVIEWBIN " --extended " + quote(device));
+
+ if (cmd.retcode() == 0)
+ {
+ if (cmd.select("^format") > 0)
+ {
+ string tmp = cmd.getLine(0, true);
+ y2mil("Format line:" << tmp);
+ tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
+ tmp = boost::to_lower_copy(extractNthWord(4, tmp), locale::classic());
+ if( tmp == "cdl" )
+ dasd_format = Dasd::DASDF_CDL;
+ else if( tmp == "ldl" )
+ dasd_format = Dasd::DASDF_LDL;
+ }
+
+ scanGeometry(cmd);
+ }
+ else
+ {
+ y2err("dasdview failed");
+
+ geometry.heads = 15;
+ geometry.sectors = 12;
+ geometry.sector_size = 4096;
+ }
+
+ y2mil("device: " << device << " geometry:" << geometry << " dasd_format:" <<
+ toString(dasd_format));
+ }
+
+
+ void
+ Dasdview::scanGeometry(SystemCmd& cmd)
+ {
+ if (cmd.select("number of cylinders") > 0)
+ {
+ string tmp = cmd.getLine(0, true);
+ y2mil("Cylinder line:" << tmp);
+ tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
+ tmp = extractNthWord( 3, tmp );
+ tmp >> geometry.cylinders;
+ }
+
+ if (cmd.select("tracks per cylinder") > 0)
+ {
+ string tmp = cmd.getLine(0, true);
+ y2mil("Tracks line:" << tmp);
+ tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
+ tmp = extractNthWord( 3, tmp );
+ tmp >> geometry.heads;
+ }
+
+ if (cmd.select("blocks per track") > 0)
+ {
+ string tmp = cmd.getLine(0, true);
+ y2mil("Blocks line:" << tmp);
+ tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
+ tmp = extractNthWord( 3, tmp );
+ tmp >> geometry.sectors;
+ }
+
+ if (cmd.select("blocksize") > 0)
+ {
+ string tmp = cmd.getLine(0, true);
+ y2mil("Bytes line:" << tmp);
+ tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
+ tmp = extractNthWord( 3, tmp );
+ tmp >> geometry.sector_size;
+ }
+ }
+
+
+ Fdasd::Fdasd(const string& device)
+ {
+ SystemCmd cmd(FDASDBIN " --table " + quote(device));
+
+ if (cmd.retcode() == 0)
+ {
+ scanGeometry(cmd);
+
+ Regex part("^" + device + "[0123456789]+$");
+ cmd.select( device );
+ int cnt = cmd.numLines();
+ for (int i = 0; i < cnt; ++i)
+ {
+ string line = cmd.getLine(i);
+ string tmp = extractNthWord( 0, line );
+ if( part.match(tmp) )
+ {
+ scanEntryLine(line);
+ }
+ }
+ }
+ else
+ {
+ y2err("fdasd failed");
+ }
+
+ y2mil("device:" << device << " geometry:" << geometry);
+
+ for (const_iterator it = entries.begin(); it != entries.end(); ++it)
+ y2mil(*it);
+ }
+
+
+ bool
+ Fdasd::getEntry(unsigned num, Entry& entry) const
+ {
+ for (const_iterator it = entries.begin(); it != entries.end(); ++it)
+ {
+ if (it->num == num)
+ {
+ entry = *it;
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const Fdasd::Entry& e)
+ {
+ return s << "num:" << e.num << " cylRegion:" << e.cylRegion << " headRegion:"
+ << e.headRegion;
+ }
+
+
+ void
+ Fdasd::scanGeometry(SystemCmd& cmd)
+ {
+ if (cmd.select("cylinders") > 0)
+ {
+ string tmp = cmd.getLine(0, true);
+ y2mil("Cylinder line:" << tmp);
+ tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
+ tmp >> geometry.cylinders;
+ }
+
+ if (cmd.select("tracks per cylinder") > 0)
+ {
+ string tmp = cmd.getLine(0, true);
+ y2mil("Tracks line:" << tmp);
+ tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
+ tmp >> geometry.heads;
+ }
+
+ if (cmd.select("blocks per track") > 0)
+ {
+ string tmp = cmd.getLine(0, true);
+ y2mil("Blocks line:" << tmp);
+ tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
+ tmp >> geometry.sectors;
+ }
+
+ if (cmd.select("bytes per block") > 0)
+ {
+ string tmp = cmd.getLine(0, true);
+ y2mil("Bytes line:" << tmp);
+ tmp = tmp.erase( 0, tmp.find( ':' ) + 1 );
+ tmp >> geometry.sector_size;
+ }
+ }
+
+
+ void
+ Fdasd::scanEntryLine(const string& line)
+ {
+ std::istringstream Data(line);
+ classic(Data);
+
+ Entry entry;
+
+ unsigned long StartM = 0;
+ unsigned long EndM = 0;
+ unsigned long SizeM = 0;
+
+ string devname;
+ Data >> devname >> StartM >> EndM >> SizeM;
+
+ string::size_type pos = devname.find_last_not_of("0123456789");
+ string(devname, pos + 1) >> entry.num;
+
+ y2mil("Fields Num:" << entry.num << " Start:" << StartM << " End:" << EndM <<
+ " Size:" << SizeM);
+
+ assert(!Data.fail());
+ assert(entry.num != 0);
+
+ if (Data.fail() || entry.num == 0)
+ {
+ y2err("invalid line:" << line);
+ return;
+ }
+
+ unsigned long start = StartM / geometry.heads;
+ unsigned long csize = EndM / geometry.heads - start + 1;
+ if( start+csize > geometry.cylinders )
+ {
+ csize = geometry.cylinders - start;
+ y2mil("new csize:" << csize);
+ }
+ entry.cylRegion = Region(start, csize);
+
+ entry.headRegion = Region(StartM, SizeM);
+
+ y2mil("Fields num:" << entry.num << " cylRegion:" << entry.cylRegion << " headRegion:" <<
+ entry.headRegion);
+
+ entries.push_back(entry);
+ }
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasdview.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasdview.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasdview.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dasdview.h Tue May 17 13:39:44 2011
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef DASDVIEW_H
+#define DASDVIEW_H
+
+#include "storage/StorageInterface.h"
+#include "storage/Geometry.h"
+#include "storage/Dasd.h"
+
+
+namespace storage
+{
+ class SystemCmd;
+
+
+ class Dasdview
+ {
+
+ public:
+
+ Dasdview(const string& device);
+
+ const Geometry& getGeometry() const { return geometry; }
+ Dasd::DasdFormat getDasdFormat() const { return dasd_format; }
+
+ private:
+
+ Geometry geometry;
+ Dasd::DasdFormat dasd_format;
+
+ void scanGeometry(SystemCmd& cmd);
+
+ };
+
+
+ class Fdasd
+ {
+
+ public:
+
+ Fdasd(const string& device);
+
+ struct Entry
+ {
+ Entry() : num(0) {}
+
+ unsigned num;
+ Region cylRegion;
+ Region headRegion;
+
+ friend std::ostream& operator<<(std::ostream& s, const Entry& e);
+ };
+
+ const Geometry& getGeometry() const { return geometry; }
+
+ typedef vector<Entry>::const_iterator const_iterator;
+
+ const vector<Entry>& getEntries() const { return entries; }
+
+ bool getEntry(unsigned num, Entry& entry) const;
+
+ private:
+
+ typedef vector<Entry>::iterator iterator;
+
+ Geometry geometry;
+ vector<Entry> entries;
+
+ void scanGeometry(SystemCmd& cmd);
+ void scanEntryLine(const string& line);
+
+ };
+
+}
+
+#endif
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DerefIterator.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DerefIterator.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DerefIterator.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DerefIterator.h Tue May 17 13:39:44 2011
@@ -23,7 +23,7 @@
#ifndef DEREF_ITERATOR_H
#define DEREF_ITERATOR_H
-#include "y2storage/AppUtil.h"
+#include "storage/AppUtil.h"
namespace storage
{
@@ -40,7 +40,8 @@
DerefIterator() {}
- DerefIterator( const Iter& i ) : Iter(i) {}
+ template< class It >
+ DerefIterator( const It& i ) : Iter(i) {}
DerefIterator& operator++() { Iter::operator++(); return(*this); }
DerefIterator operator++(int)
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Device.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Device.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Device.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Device.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include "storage/Device.h"
+#include "storage/AppUtil.h"
+#include "storage/StorageTmpl.h"
+#include "storage/HumanString.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ Device::Device(const string& nm, const string& dev)
+ : nm(nm), dev(dev), create(false), del(false), silent(false), size_k(0), mjr(0), mnr(0)
+ {
+ y2deb("constructed Device " << dev);
+ }
+
+
+ Device::Device(const string& nm, const string& dev, SystemInfo& systeminfo)
+ : nm(nm), dev(dev), create(false), del(false), silent(false), size_k(0), mjr(0), mnr(0)
+ {
+ y2deb("constructed Device " << dev);
+
+ assert(!nm.empty() && !dev.empty());
+ }
+
+
+ Device::Device(const xmlNode* node)
+ : nm(), dev(), create(false), del(false), silent(false), size_k(0), mjr(0), mnr(0)
+ {
+ getChildValue(node, "name", nm);
+ getChildValue(node, "device", dev);
+
+ getChildValue(node, "size_k", size_k);
+
+ getChildValue(node, "major", mjr);
+ getChildValue(node, "minor", mnr);
+
+ y2deb("constructed Device " << dev);
+
+ assert(!nm.empty() && !dev.empty());
+ }
+
+
+ Device::Device(const Device& d)
+ : nm(d.nm), dev(d.dev), create(d.create), del(d.del), silent(d.silent), size_k(d.size_k),
+ mjr(d.mjr), mnr(d.mnr), uby(d.uby), alt_names(d.alt_names)
+ {
+ y2deb("copy-constructed Device " << dev);
+ }
+
+
+ Device::~Device()
+ {
+ y2deb("destructed Device " << dev);
+ }
+
+
+ void
+ Device::saveData(xmlNode* node) const
+ {
+ setChildValue(node, "name", nm);
+ setChildValue(node, "device", dev);
+ setChildValue(node, "size_k", size_k);
+ setChildValue(node, "major", mjr);
+ setChildValue(node, "minor", mnr);
+
+ if (!uby.empty())
+ setChildValue(node, "used_by", uby);
+ }
+
+
+ void
+ Device::setNameDevice(const string& name, const string& device)
+ {
+ nm = name;
+ dev = device;
+ }
+
+
+ string
+ Device::sizeString() const
+ {
+ return byteToHumanString(1024 * sizeK(), false, 2, false);
+ }
+
+
+ bool
+ Device::getMajorMinor()
+ {
+ return storage::getMajorMinor(dev, mjr, mnr);
+ }
+
+
+ string
+ Device::udevPath() const
+ {
+ return string();
+ }
+
+ list<string>
+ Device::udevId() const
+ {
+ return list<string>();
+ }
+
+
+ void
+ Device::setUsedBy(UsedByType type, const string& device)
+ {
+ uby.clear();
+ uby.push_back(UsedBy(type, device));
+ }
+
+ void
+ Device::addUsedBy(UsedByType type, const string& device)
+ {
+ uby.push_back(UsedBy(type, device));
+ }
+
+ void
+ Device::removeUsedBy(UsedByType type, const string& device)
+ {
+ uby.remove(UsedBy(type, device));
+ }
+
+ bool
+ Device::isUsedBy(UsedByType type) const
+ {
+ for (list<UsedBy>::const_iterator it = uby.begin(); it != uby.end(); ++it)
+ if (it->type() == type)
+ return true;
+
+ return false;
+ }
+
+
+bool Device::sameDevice( const string& device ) const
+ {
+ string d = normalizeDevice(device);
+ return( d==dev ||
+ find( alt_names.begin(), alt_names.end(), d )!=alt_names.end() );
+ }
+
+
+ void
+ Device::logDifference(std::ostream& log, const Device& rhs) const
+ {
+ log << "nm:" + nm;
+ if (nm != rhs.nm)
+ log << "-->" << rhs.nm;
+ logDiff(log, "dev", dev, rhs.dev);
+
+ logDiff(log, "deleted", del, rhs.del);
+ logDiff(log, "created", create, rhs.create);
+
+ logDiff(log, "mjr", mjr, rhs.mjr);
+ logDiff(log, "mnr", mnr, rhs.mnr);
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const Device& d)
+ {
+ s << "Name:" << d.nm << " Device:" << d.dev;
+ s << " SizeK:" << d.size_k;
+ if (d.mjr != 0 || d.mnr != 0)
+ s << " Node:<" << d.mjr << ":" << d.mnr << ">";
+ if (d.create)
+ s << " created";
+ if (d.del)
+ s << " deleted";
+ if (d.silent)
+ s << " silent";
+ return s;
+ }
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Device.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Device.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Device.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Device.h Tue May 17 13:39:44 2011
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef DEVICE_H
+#define DEVICE_H
+
+
+#include <string>
+#include <list>
+
+#include "storage/StorageTypes.h"
+#include "storage/XmlFile.h"
+
+
+namespace storage
+{
+ using std::string;
+ using std::list;
+
+
+ class SystemInfo;
+
+
+ class Device
+ {
+ public:
+
+ Device(const string& nm, const string& dev);
+ Device(const string& nm, const string& dev, SystemInfo& systeminfo);
+ Device(const xmlNode* node);
+ Device(const Device&);
+ virtual ~Device();
+
+ void saveData(xmlNode* node) const;
+
+ const string& name() const { return nm; }
+ const string& device() const { return dev; }
+ void setNameDevice(const string& nm, const string& dev);
+
+ bool created() const { return create; }
+ bool deleted() const { return del; }
+ void setCreated(bool val = true) { create = val; }
+ void setDeleted(bool val = true) { del = val; }
+
+ bool isSilent() const { return silent; }
+ void setSilent(bool val = true) { silent = val; }
+
+ unsigned long long sizeK() const { return size_k; }
+ string sizeString() const;
+
+ bool getMajorMinor();
+ unsigned long majorNr() const { return mjr; }
+ unsigned long minorNr() const { return mnr; }
+
+ const std::list<string>& altNames() const { return( alt_names ); }
+ void setAltNames( std::list<string>& li ) { alt_names=li; }
+ bool sameDevice( const string& device ) const;
+
+ // udev path and ids (without leading "/dev/disk/by-*/")
+ virtual string udevPath() const;
+ virtual list<string> udevId() const;
+
+ // name for device in /proc/partitions
+ virtual string procName() const { return ""; }
+
+ // full path for device in /sys/block
+ virtual string sysfsPath() const { return ""; }
+
+ void clearUsedBy() { uby.clear(); }
+ void setUsedBy(UsedByType type, const string& device);
+ void addUsedBy(UsedByType type, const string& device);
+ void removeUsedBy(UsedByType type, const string& device);
+ bool isUsedBy() const { return !uby.empty(); }
+ bool isUsedBy(UsedByType type) const;
+ const list<UsedBy>& getUsedBy() const { return uby; }
+
+ void logDifference(std::ostream& log, const Device& rhs) const;
+
+ friend std::ostream& operator<<(std::ostream& s, const Device& d);
+
+ protected:
+
+ string nm;
+ string dev;
+
+ bool create;
+ bool del;
+
+ bool silent;
+
+ unsigned long long size_k;
+
+ unsigned long mjr;
+ unsigned long mnr;
+
+ list<UsedBy> uby;
+ list<string> alt_names;
+
+ private:
+
+ Device& operator=(const Device&); // disallow
+
+ };
+
+}
+
+
+#endif
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Disk.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Disk.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Disk.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Disk.cc Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -19,180 +19,155 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
-
-#include
-#include /* for BLKGETSIZE */
-#include /* for HDIO_GETGEO */
-#include <iostream>
#include <string>
+#include <ostream>
+#include <fstream>
#include <sstream>
#include <iomanip>
#include
-#include "y2storage/Region.h"
-#include "y2storage/Partition.h"
-#include "y2storage/ProcPart.h"
-#include "y2storage/Disk.h"
-#include "y2storage/Storage.h"
-#include "y2storage/AsciiFile.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/StorageDefines.h"
-
-using namespace std;
-using namespace storage;
-
-Disk::Disk( Storage * const s, const string& Name,
- unsigned long long SizeK ) :
- Container(s,"",staticType())
- {
- init_disk = dmp_slave = iscsi = gpt_enlarge = no_addpart = false;
- logical_sector_size = 512;
- nm = Name;
- undevDevice(nm);
- logfile_name = nm;
- string::size_type pos = 0;
- while( (pos=logfile_name.find( '/', pos )) != string::npos )
- logfile_name[pos] = '_';
- if( Name.find( "/dev/" )==0 )
- dev = Name;
- else
- dev = "/dev/" + Name;
+#include "storage/Region.h"
+#include "storage/Partition.h"
+#include "storage/SystemInfo.h"
+#include "storage/ProcParts.h"
+#include "storage/Disk.h"
+#include "storage/Storage.h"
+#include "storage/AppUtil.h"
+#include "storage/SystemCmd.h"
+#include "storage/StorageDefines.h"
+#include "storage/Parted.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+ const unsigned int fuzz_cyl = 2;
+
+
+ Disk::Disk(Storage* s, const string& name, const string& device,
+ unsigned long long SizeK, SystemInfo& systeminfo)
+ : Container(s, name, device, staticType(), systeminfo),
+ init_disk(false), transport(TUNKNOWN), dmp_slave(false), no_addpart(false),
+ gpt_enlarge(false), del_ptable(false)
+ {
+ logfile_name = boost::replace_all_copy(nm, "/", "_");
+ getMajorMinor();
+
+ Lsscsi::Entry entry;
+ if (systeminfo.getLsscsi().getEntry(device, entry))
+ transport = entry.transport;
+
size_k = SizeK;
- y2deb("constructed disk " << dev);
+ y2deb("constructed Disk name:" << name);
}
-Disk::Disk( Storage * const s, const string& Name,
- unsigned num, unsigned long long SizeK, ProcPart& ppart ) :
- Container(s,Name,staticType())
- {
- y2milestone( "constructed disk %s nr %u sizeK:%llu", Name.c_str(), num,
- SizeK );
- logfile_name = Name + decString(num);
- init_disk = dmp_slave = iscsi = gpt_enlarge = no_addpart = false;
- logical_sector_size = 512;
+
+ Disk::Disk(Storage* s, const string& name, const string& device, unsigned num,
+ unsigned long long SizeK, SystemInfo& systeminfo)
+ : Container(s, name, device, staticType(), systeminfo),
+ init_disk(false), transport(TUNKNOWN), dmp_slave(false), no_addpart(false),
+ gpt_enlarge(false), del_ptable(false)
+ {
+ y2mil("constructed Disk name:" << name << " nr " << num << " sizeK:" << SizeK);
+ logfile_name = name + decString(num);
ronly = true;
size_k = SizeK;
- head = new_head = 16;
- sector = new_sector = 32;
- byte_cyl = head * sector * logical_sector_size;
- cyl = new_cyl = 0;
- addPartition( num, size_k, ppart );
+ addPartition( num, size_k, systeminfo );
}
-Disk::Disk( Storage * const s, const string& fname ) :
- Container(s,"",staticType())
+
+ Disk::Disk(Storage* s, const xmlNode* node)
+ : Container(s, staticType(), node), label(), udev_path(),
+ udev_id(), max_primary(0), ext_possible(false), max_logical(0),
+ init_disk(false), transport(TUNKNOWN), dmp_slave(false), no_addpart(false),
+ gpt_enlarge(false), range(4), del_ptable(false)
{
- init_disk = dmp_slave = iscsi = gpt_enlarge = no_addpart = false;
- logical_sector_size = 512;
- nm = fname.substr( fname.find_last_of( '/' )+1);
- if( nm.find("disk_")==0 )
- nm.erase( 0, 5 );
- AsciiFile file( fname );
- string line;
- if( searchFile( file, "^Device:", line ) )
- {
- dev = extractNthWord( 1, line );
- }
- mnr = mjr = 0;
- if( searchFile( file, "^Major:", line ) )
- {
- extractNthWord( 1, line ) >> mjr;
- }
- if( searchFile( file, "^Minor:", line ) )
- {
- extractNthWord( 1, line ) >> mnr;
- }
- range = 4;
- if( searchFile( file, "^Range:", line ) )
- {
- extractNthWord( 1, line ) >> range;
- }
- cyl = 1024;
- if( searchFile( file, "^Cylinder:", line ) )
- {
- extractNthWord( 1, line ) >> cyl;
- }
- head = 1024;
- if( searchFile( file, "^Head:", line ) )
- {
- extractNthWord( 1, line ) >> head;
- }
- sector = 32;
- if( searchFile( file, "^Sector:", line ) )
- {
- extractNthWord( 1, line ) >> sector;
- }
- byte_cyl = head * sector * logical_sector_size;
- if( searchFile( file, "^Label:", line ) )
- {
- label = extractNthWord( 1, line );
- }
- max_primary = 0;
- if( searchFile( file, "^MaxPrimary:", line ) )
- {
- extractNthWord( 1, line ) >> max_primary;
- }
- ext_possible = false;
- if( searchFile( file, "^ExtPossible:", line ) )
- {
- extractNthWord( 1, line ) >> ext_possible;
- }
- max_logical = 0;
- if( searchFile( file, "^MaxLogical:", line ) )
- {
- extractNthWord( 1, line ) >> max_logical;
- }
- ronly = false;
- if( searchFile( file, "^Readonly:", line ) )
- {
- extractNthWord( 1, line ) >> ronly;
- }
- if( FakeDisk() && isdigit( nm[nm.size()-1] ))
- {
- string::size_type p = nm.find_last_not_of( "0123456789" );
- nm.erase( p+1 );
- }
- size_k = 0;
- if( searchFile( file, "^SizeK:", line ) )
- {
- extractNthWord( 1, line ) >> size_k;
- }
- logical_sector_size = 512;
- if( searchFile( file, "^LogicalSectorSize:", line ) )
- {
- extractNthWord( 1, line ) >> logical_sector_size;
- }
- udev_path.clear();
- if( searchFile( file, "^UdevPath:", line ) )
- {
- udev_path = extractNthWord( 1, line );
- }
- udev_id.clear();
- if( searchFile( file, "^UdevId:", line ) )
+ logfile_name = nm;
+
+ getChildValue(node, "range", range);
+
+ getChildValue(node, "geometry", geometry);
+
+ getChildValue(node, "label", label);
+ getChildValue(node, "max_primary", max_primary);
+ getChildValue(node, "ext_possible", ext_possible);
+ getChildValue(node, "max_logical", max_logical);
+
+ const list l = getChildNodes(node, "partition");
+ for (list::const_iterator it = l.begin(); it != l.end(); ++it)
+ addToList(new Partition(*this, *it));
+
+ y2deb("constructed Disk " << dev);
+ }
+
+
+ Disk::Disk(const Disk& c)
+ : Container(c), geometry(c.geometry), new_geometry(c.new_geometry),
+ label(c.label), udev_path(c.udev_path), udev_id(c.udev_id),
+ detected_label(c.detected_label), logfile_name(c.logfile_name),
+ max_primary(c.max_primary),
+ ext_possible(c.ext_possible), max_logical(c.max_logical),
+ init_disk(c.init_disk), transport(c.transport),
+ dmp_slave(c.dmp_slave), no_addpart(c.no_addpart),
+ gpt_enlarge(c.gpt_enlarge), range(c.range),
+ del_ptable(c.del_ptable)
+ {
+ y2deb("copy-constructed Disk " << dev);
+
+ ConstPartPair p = c.partPair();
+ for (ConstPartIter i = p.begin(); i != p.end(); ++i)
{
- udev_id.push_back( extractNthWord( 1, line ));
+ Partition* p = new Partition(*this, *i);
+ vols.push_back(p);
}
- int lnr = 0;
- while( searchFile( file, "^Partition:", line, lnr ))
+ }
+
+
+ Disk::~Disk()
+ {
+ y2deb("destructed Disk " << dev);
+ }
+
+
+ void
+ Disk::saveData(xmlNode* node) const
+ {
+ Container::saveData(node);
+
+ setChildValue(node, "range", range);
+
+ setChildValue(node, "geometry", geometry);
+
+ setChildValue(node, "label", label);
+ setChildValue(node, "max_primary", max_primary);
+ if (ext_possible)
{
- lnr++;
- Partition *p = new Partition( *this, extractNthWord( 1, line, true ));
- addToList( p );
+ setChildValue(node, "ext_possible", ext_possible);
+ setChildValue(node, "max_logical", max_logical);
}
- y2deb("constructed disk " << dev << " from file " << fname);
+
+ if (!udev_path.empty())
+ setChildValue(node, "udev_path", udev_path);
+ if (!udev_id.empty())
+ setChildValue(node, "udev_id", udev_id);
+
+ if (transport != TUNKNOWN)
+ setChildValue(node, "transport", toString(transport));
+
+ ConstPartPair vp = partPair();
+ for (ConstPartIter v = vp.begin(); v != vp.end(); ++v)
+ v->saveData(xmlNewChild(node, "partition"));
}
-Disk::~Disk()
+
+ string
+ Disk::sysfsPath() const
{
- y2deb("destructed disk " << dev);
+ return SYSFSDIR "/" + boost::replace_all_copy(procName(), "/", "!");
}
- const unsigned int fuzz_cyl = 2;
void
Disk::triggerUdevUpdate() const
@@ -212,19 +187,8 @@
y2mil("disk:" << nm << " path:" << path << "id:" << id);
udev_path = path;
udev_id = id;
-
- udev_id.erase(remove_if(udev_id.begin(), udev_id.end(), find_begin("edd-")), udev_id.end());
-
- if( udev_id.size()>1 )
- {
- list<string>::iterator i = find_if( udev_id.begin(), udev_id.end(), find_begin( "ata-" ) );
- if( i!=udev_id.end() && i!=udev_id.begin() )
- {
- string tmp = *i;
- udev_id.erase( i );
- udev_id.push_front(tmp);
- }
- }
+ udev_id.remove_if(string_starts_with("edd-"));
+ partition(udev_id.begin(), udev_id.end(), string_starts_with("ata-"));
y2mil("id:" << udev_id);
alt_names.remove_if(string_contains("/by-path/"));
@@ -243,161 +207,58 @@
}
-unsigned long long
-Disk::cylinderToKb( unsigned long cylinder ) const
- {
- return (unsigned long long)byte_cyl * cylinder / 1024;
- }
-
-unsigned long
-Disk::kbToCylinder( unsigned long long kb ) const
+ bool
+ Disk::detect(SystemInfo& systeminfo)
{
- unsigned long long bytes = kb * 1024;
- bytes += byte_cyl - 1;
- unsigned long ret = bytes/byte_cyl;
- y2milestone( "KB:%lld ret:%ld byte_cyl:%ld", kb, ret, byte_cyl );
- return (ret);
+ return detectGeometry() && detectPartitions(systeminfo);
}
-bool Disk::detect( ProcPart& ppart )
- {
- return( detectGeometry() && detectPartitions(ppart) );
- }
bool Disk::detectGeometry()
{
- y2milestone( "disk:%s", device().c_str() );
- bool ret = false;
- int fd = open( device().c_str(), O_RDONLY );
- if( fd >= 0 )
- {
- int rcode = ioctl(fd, BLKSSZGET, &logical_sector_size);
- y2mil("BLKSSZGET ret:" << rcode << " sector_size:" << logical_sector_size);
-
- head = 255;
- sector = 63;
- cyl = 16;
- struct hd_geometry geometry;
- rcode = ioctl( fd, HDIO_GETGEO, &geometry );
- if( rcode==0 )
- {
- head = geometry.heads>0?geometry.heads:head;
- sector = geometry.sectors>0?geometry.sectors:sector;
- cyl = geometry.cylinders>0?geometry.cylinders:cyl;
- }
- y2milestone( "After HDIO_GETGEO ret %d Head:%u Sector:%u Cylinder:%lu",
- rcode, head, sector, cyl );
- __uint64_t sect = 0;
- rcode = ioctl( fd, BLKGETSIZE64, §);
- y2milestone( "BLKGETSIZE64 Ret:%d Bytes:%llu", rcode,
- (unsigned long long int) sect );
- if( rcode==0 && sect!=0 )
- {
- sect /= logical_sector_size;
- cyl = (unsigned)(sect / (__uint64_t)(head*sector));
- ret = true;
- }
- else
- {
- unsigned long lsect;
- rcode = ioctl( fd, BLKGETSIZE, &lsect );
- y2milestone( "BLKGETSIZE Ret:%d Sect:%lu", rcode, lsect );
- if( rcode==0 && lsect!=0 )
- {
- cyl = lsect / (unsigned long)(head*sector);
- ret = true;
- }
- }
- y2milestone( "After getsize Cylinder:%lu", cyl );
- close( fd );
- }
- byte_cyl = head * sector * logical_sector_size;
- y2milestone( "ret:%d byte_cyl:%lu", ret, byte_cyl );
- return( ret );
- }
-
-
- unsigned long long
- Disk::sectorToKb(unsigned long long sector) const
- {
- // TODO use 128 arithmetic
- return sector * logical_sector_size / 1024;
- }
-
-
- unsigned long long
- Disk::kbToSector(unsigned long long kb) const
- {
- // TODO use 128 arithmetic
- return kb * 1024 / logical_sector_size;
+ return storage::detectGeometry(dev, geometry);
}
bool
Disk::getSysfsInfo(const string& sysfsdir, SysfsInfo& sysfsinfo)
{
- string sysfsfile = sysfsdir + "/dev";
- if (access(sysfsfile.c_str(), R_OK) == 0)
+ string devtype;
+ if (read_sysfs_property(sysfsdir + "/device/devtype", devtype, false))
{
- ifstream file(sysfsfile.c_str());
- classic(file);
- char c;
- file >> sysfsinfo.mjr >> c >> sysfsinfo.mnr;
+ sysfsinfo.vbd = devtype == "vbd";
}
else
{
- y2war("reading " << sysfsfile << " failed");
- return false;
- }
-
- sysfsfile = sysfsdir + "/device";
- if (!readlink(sysfsfile, sysfsinfo.device))
- {
// not always available so no error
- sysfsinfo.device.clear();
+ sysfsinfo.vbd = false;
}
- if (!read_sysfs_property(sysfsdir + "/range", sysfsinfo.range))
- return false;
-
- unsigned long ext_range;
- if (read_sysfs_property(sysfsdir + "/ext_range", ext_range, false))
- sysfsinfo.range = ext_range;
+ if (!read_sysfs_property(sysfsdir + "/ext_range", sysfsinfo.range, false))
+ if (!read_sysfs_property(sysfsdir + "/range", sysfsinfo.range))
+ return false;
if (!read_sysfs_property(sysfsdir + "/size", sysfsinfo.size))
return false;
- y2mil("sysfsdir:" << sysfsdir << " mjr:" << sysfsinfo.mjr << " mnr:" << sysfsinfo.mnr <<
- " device:" << sysfsinfo.device << " range:" << sysfsinfo.range << " size:" <<
- sysfsinfo.size);
+ y2mil("sysfsdir:" << sysfsdir << " devtype:" << devtype << " range:" << sysfsinfo.range <<
+ " size:" << sysfsinfo.size);
return true;
}
bool
- Disk::getSysfsInfo(const string& SysfsDir)
+ Disk::getSysfsInfo()
{
bool ret = true;
- sysfs_dir = SysfsDir;
- y2mil("sysfs_dir:" << sysfs_dir);
SysfsInfo sysfsinfo;
- if (getSysfsInfo(sysfs_dir, sysfsinfo))
+ if (getSysfsInfo(sysfsPath(), sysfsinfo))
{
range = sysfsinfo.range;
if (range <= 1)
ret = false;
-
- mjr = sysfsinfo.mjr;
- mnr = sysfsinfo.mnr;
-
- string link;
- if (readlink(sysfs_dir, link))
- {
- y2mil("link:" << link);
- iscsi = boost::contains(link, "/session");
- }
}
else
{
@@ -405,119 +266,43 @@
}
y2mil("dev:" << dev << " ret:" << ret << " range:" << range << " major:" << mjr <<
- " minor:" << mnr << " iscsi:" << iscsi);
+ " minor:" << mnr);
return ret;
}
-void Disk::getGeometry( const string& line, unsigned long& c, unsigned& h,
- unsigned& s )
+ bool
+ Disk::detectPartitions(SystemInfo& systeminfo)
{
- string tmp( line );
- tmp.erase( 0, tmp.find(':')+1 );
- tmp = extractNthWord( 0, tmp );
- list<string> geo = splitString( extractNthWord( 0, tmp ), "," );
- list<string>::const_iterator i = geo.begin();
- unsigned long val = 0;
- bool sect_head_changed = false;
- bool cyl_changed = false;
- if( i!=geo.end() )
- {
- *i >> val;
- if( val>0 )
- {
- c = val;
- cyl_changed = true;
- }
- }
- ++i;
- val = 0;
- if( i!=geo.end() )
- {
- *i >> val;
- if( val>0 )
- {
- h = (unsigned)val;
- sect_head_changed = true;
- }
- }
- ++i;
- val = 0;
- if( i!=geo.end() )
- {
- *i >> val;
- if( val>0 )
- {
- s = (unsigned)val;
- sect_head_changed = true;
- }
- }
- if( !cyl_changed && sect_head_changed )
- {
- c = sizeK()*2/(s*h);
- if( c<=0 )
- c=1;
- y2mil( "new c:" << c );
- }
- y2milestone( "line:%s", line.c_str() );
- y2milestone( "c:%lu h:%u s:%u", c, h, s );
- }
+ bool ret = true;
+
+ const Parted& parted = systeminfo.getParted(dev);
+
+ string dlabel = parted.getLabel();
+
+ new_geometry = geometry = parted.getGeometry();
+
+ gpt_enlarge = parted.getGptEnlarge();
+
+ y2mil("dlabel:" << dlabel << " geometry:" << geometry << " gpt_enlarge:" << gpt_enlarge);
-bool Disk::detectPartitions( ProcPart& ppart )
- {
- bool ret = true;
- string cmd_line = PARTEDCMD + quote(device()) + " unit cyl print | sort -n";
- string dlabel;
- system_stderr.erase();
- y2milestone( "executing cmd:%s", cmd_line.c_str() );
- SystemCmd Cmd( cmd_line );
- checkSystemError( cmd_line, Cmd );
- if( Cmd.select( "Partition Table:" )>0 )
- {
- string tmp = *Cmd.getLine(0, true);
- y2milestone( "Label line:%s", tmp.c_str() );
- dlabel = extractNthWord( 2, tmp );
- }
- if( Cmd.select( "BIOS cylinder" )>0 )
- {
- string tmp = *Cmd.getLine(0, true);
- getGeometry( tmp, cyl, head, sector );
- new_cyl = cyl;
- new_head = head;
- new_sector = sector;
- y2milestone( "After parted Head:%u Sector:%u Cylinder:%lu",
- head, sector, cyl );
- byte_cyl = head * sector * logical_sector_size;
- y2milestone( "byte_cyl:%lu", byte_cyl );
- }
- gpt_enlarge = Cmd.select( "fix the GPT to use all" )>0;
- y2milestone( "Label:%s gpt_enlarge:%d", dlabel.c_str(), gpt_enlarge );
if( dlabel!="loop" )
{
setLabelData( dlabel );
- checkPartedOutput( Cmd, ppart );
- if( dlabel.empty() )
- {
- Cmd.setCombine();
- Cmd.execute(FDISKBIN " -l " + quote(device()));
- if( Cmd.select( "AIX label" )>0 )
- {
- detected_label = "aix";
- }
- }
+ checkPartedOutput(systeminfo);
}
else
dlabel.erase();
if( detected_label.empty() )
detected_label = dlabel;
if( dlabel.empty() )
- dlabel = defaultLabel(getStorage()->efiBoot(), kbToSector(size_k));
+ dlabel = defaultLabel();
setLabelData( dlabel );
if (label == "unsupported")
{
- string txt = sformat(
+ Text txt = sformat(
// popup text %1$s is replaced by disk name e.g. /dev/hda
_("The partition table type on disk %1$s cannot be handled by\n"
"this tool.\n"
@@ -526,90 +311,57 @@
"You can format them and assign mount points to them, but you\n"
"cannot add, edit, resize, or remove partitions from that\n"
"disk with this tool."), dev.c_str() );
- y2war( "unsupported disk label on " << dev << " txt:" << txt );
+ y2war( "unsupported disk label on " << dev << " txt:" << txt.native );
detected_label = label;
ronly = true;
}
- y2milestone( "ret:%d partitons:%zd detected label:%s label:%s", ret,
- vols.size(), detected_label.c_str(), label.c_str() );
+ y2mil("ret:" << ret << " partitions:" << vols.size() << " detected label:" << detected_label <<
+ " label:" << label);
return( ret );
}
+
void
-Disk::logData( const string& Dir )
+Disk::logData(const string& Dir) const
{
- string fname( Dir + "/disk_" + logfile_name + ".tmp" );
- ofstream file( fname.c_str() );
- classic(file);
- file << "Device: " << dev << endl;
- if( !udev_path.empty() )
- file << "UdevPath: " << udev_path << endl;
- if( !udev_id.empty() )
- file << "UdevId: " << udev_id << endl;
- file << "Major: " << mjr << endl;
- file << "Minor: " << mnr << endl;
- file << "Range: " << range << endl;
-
- file << "Cylinder: " << cyl << endl;
- file << "Head: " << head << endl;
- file << "Sector: " << sector << endl;
- if( logical_sector_size!=512 )
- file << "LogicalSectorSize: " << logical_sector_size << endl;
-
- file << "Label: " << label << endl;
- file << "MaxPrimary: " << max_primary << endl;
- if( ext_possible )
- {
- file << "ExtPossible: " << ext_possible << endl;
- file << "MaxLogical: " << max_logical << endl;
- }
- if( ronly )
- {
- file << "Readonly: " << ronly << endl;
- }
- file << "SizeK: " << size_k << endl;
+ string fname(Dir + "/disk_" + logfile_name + ".info.tmp");
+
+ XmlFile xml;
+ xmlNode* node = xmlNewNode("disk");
+ xml.setRootElement(node);
+ saveData(node);
+ xml.save(fname);
- PartPair pp = partPair();
- for( PartIter p=pp.begin(); p!=pp.end(); ++p )
- {
- file << "Partition: ";
- p->logData(file);
- file << endl;
- }
- file.close();
getStorage()->handleLogFile( fname );
}
-void
-Disk::setLabelData( const string& disklabel )
+
+ void
+ Disk::setLabelData(const string& disklabel)
{
- y2milestone( "disklabel:%s", disklabel.c_str() );
- int i=0;
- while( !labels[i].name.empty() && labels[i].name!=disklabel )
- {
- i++;
+ y2mil("disklabel:" << disklabel);
+ DlabelCapabilities caps;
+ if (getDlabelCapabilities(disklabel, caps))
+ {
+ max_primary = min(caps.maxPrimary, (unsigned)(range - 1));
+ ext_possible = caps.extendedPossible;
+ max_logical = min(caps.maxLogical, (unsigned)(range - 1));
+ label = disklabel;
}
- if( labels[i].name.empty() )
+ else
{
- y2error ("unknown disklabel %s", disklabel.c_str());
- ext_possible = false;
- max_primary = 0;
- max_logical = 0;
- label = "unsupported";
- }
- else
- {
- ext_possible = labels[i].extended;
- max_primary = min(labels[i].primary,unsigned(range-1));
- max_logical = min(labels[i].logical,unsigned(range-1));
- label = labels[i].name;
+ max_primary = 0;
+ ext_possible = false;
+ max_logical = 0;
+ label = "unsupported";
}
- y2milestone( "name:%s ext:%d primary:%d logical:%d", label.c_str(),
- ext_possible, max_primary, max_logical );
+ y2mil("label:" << label << " max_primary:" << max_logical << " ext_possible:" <<
+ ext_possible << " max_logical:" << max_logical);
}
+
bool
Disk::getDlabelCapabilities(const string& dlabel, DlabelCapabilities& dlabelcapabilities)
{
@@ -632,31 +384,20 @@
}
-
int
-Disk::checkSystemError( const string& cmd_line, const SystemCmd& cmd )
+Disk::checkSystemError( const string& cmd_line, const SystemCmd& cmd ) const
{
- string tmp = *cmd.getString(SystemCmd::IDX_STDERR);
- if( tmp.length()>0 )
+ string tmp = boost::join(cmd.stderr(), "\n");
+ if (!tmp.empty())
{
- y2error( "cmd:%s", cmd_line.c_str() );
- y2error( "err:%s", tmp.c_str() );
- if( !system_stderr.empty() )
- {
- system_stderr += "\n";
- }
- system_stderr += tmp;
+ y2err("cmd:" << cmd_line);
+ y2err("err:" << tmp);
}
- tmp = *cmd.getString(SystemCmd::IDX_STDOUT);
- if( tmp.length()>0 )
+ tmp = boost::join(cmd.stdout(), "\n");
+ if (!tmp.empty())
{
- y2milestone( "cmd:%s", cmd_line.c_str() );
- y2milestone( "out:%s", tmp.c_str() );
- if( !system_stderr.empty() )
- {
- system_stderr += "\n";
- }
- system_stderr += tmp;
+ y2mil("cmd:" << cmd_line);
+ y2mil("out:" << tmp);
}
int ret = cmd.retcode();
if( ret!=0 && tmp.find( "kernel failed to re-read" )!=string::npos )
@@ -672,7 +413,7 @@
ret = 0;
}
else
- y2error( "retcode:%d", cmd.retcode() );
+ y2err("retcode:" << cmd.retcode());
}
return( ret );
}
@@ -699,246 +440,39 @@
}
-
bool
-Disk::scanPartedSectors( const string& Line, unsigned& nr,
- unsigned long long& start,
- unsigned long long& ssize ) const
- {
- std::istringstream Data( Line );
- classic(Data);
-
- nr=0;
- string skip;
- char c;
- Data >> nr >> start >> c >> skip >> ssize;
- y2mil( "nr:" << nr << " st:" << start << " sz:" << ssize << " c:" << c );
- return( nr>0 );
- }
-
-bool
-Disk::scanPartedLine( const string& Line, unsigned& nr, unsigned long& start,
- unsigned long& csize, PartitionType& type, unsigned& id,
- bool& boot )
+ Disk::checkPartedOutput(SystemInfo& systeminfo)
{
- unsigned long StartM, EndM;
- string PartitionType, TInfo;
+ const ProcParts& parts = systeminfo.getProcParts();
+ const Parted& parted = systeminfo.getParted(dev);
- y2deb("Line:" << Line);
- std::istringstream Data( Line );
- classic(Data);
+ unsigned long range_exceed = 0;
+ list pl;
- nr=0;
- StartM = EndM = 0;
- type = PRIMARY;
- string skip;
- if( label == "msdos" )
- {
- Data >> nr >> StartM >> skip >> EndM >> skip >> skip >> PartitionType;
- }
- else
- {
- Data >> nr >> StartM >> skip >> EndM >> skip >> skip;
- }
- if (Data.fail())
+ for (Parted::const_iterator it = parted.getEntries().begin();
+ it != parted.getEntries().end(); ++it)
{
- y2mil( "invalid line:" << Line );
- nr = 0;
- }
- char c;
- TInfo = ",";
- Data.unsetf(ifstream::skipws);
- Data >> c;
- char last_char = ',';
- while( Data.good() && !Data.eof() )
- {
- if( !isspace(c) )
+ if (it->num < range)
{
- TInfo += c;
- last_char = c;
- }
- else
- {
- if( last_char != ',' )
+ unsigned long long s = cylinderToKb(it->cylRegion.len());
+ Partition* p = new Partition(*this, getPartName(it->num), getPartDevice(it->num),
+ it->num, systeminfo, s, it->cylRegion, it->type,
+ it->id, it->boot);
+ if (parts.getSize(p->procName(), s))
{
- TInfo += ",";
- last_char = ',';
+ if( s>0 && p->type() != EXTENDED )
+ p->setSize( s );
}
+ pl.push_back( p );
}
- Data >> c;
- }
- TInfo += ",";
- if( nr>0 )
- {
- y2milestone( "Fields Num:%d Start:%lu End:%lu Type:%d",
- nr, StartM, EndM, type );
- y2milestone( "TInfo:%s", TInfo.c_str() );
- start = StartM;
- csize = EndM-StartM+1;
- if( start+csize > cylinders() )
- {
- csize = cylinders()-start;
- y2milestone( "new csize:%lu", csize );
- }
- id = Partition::ID_LINUX;
- boot = TInfo.find( ",boot," ) != string::npos;
- string OrigTInfo = TInfo;
- boost::to_lower(TInfo, locale::classic());
- if( ext_possible )
- {
- if( PartitionType == "extended" )
- {
- type = EXTENDED;
- id = Partition::ID_EXTENDED;
- }
- else if( nr>=5 )
- {
- type = LOGICAL;
- }
- }
- else if( TInfo.find( ",fat" )!=string::npos )
- {
- id = Partition::ID_DOS;
- }
- else if( TInfo.find( ",ntfs," )!=string::npos )
- {
- id = Partition::ID_NTFS;
- }
- else if( TInfo.find( "swap," )!=string::npos )
- {
- id = Partition::ID_SWAP;
- }
- else if( TInfo.find( ",raid," )!=string::npos )
- {
- id = Partition::ID_RAID;
- }
- else if( TInfo.find( ",lvm," )!=string::npos )
- {
- id = Partition::ID_LVM;
- }
- string::size_type pos = TInfo.find( ",type=" );
- if( pos != string::npos )
- {
- string val;
- int tmp_id = 0;
- if( label != "mac" )
- {
- val = TInfo.substr( pos+6, 2 );
- Data.clear();
- Data.str( val );
- Data >> std::hex >> tmp_id;
- y2debug( "val=%s id=%d", val.c_str(), tmp_id );
- if( tmp_id>0 )
- {
- id = tmp_id;
- }
- }
else
- {
- pos = OrigTInfo.find("type=");
- val = OrigTInfo.substr( pos+5 );
- if( (pos=val.find_first_of( ", \t\n" )) != string::npos )
- {
- val = val.substr( 0, pos );
- }
- if( id == Partition::ID_LINUX )
- {
- if( val.find( "Apple_HFS" ) != string::npos ||
- val.find( "Apple_Bootstrap" ) != string::npos )
- {
- id = Partition::ID_APPLE_HFS;
- }
- else if( val.find( "Apple_partition" ) != string::npos ||
- val.find( "Apple_Driver" ) != string::npos ||
- val.find( "Apple_Loader" ) != string::npos ||
- val.find( "Apple_Boot" ) != string::npos ||
- val.find( "Apple_ProDOS" ) != string::npos ||
- val.find( "Apple_FWDriver" ) != string::npos ||
- val.find( "Apple_Patches" ) != string::npos )
- {
- id = Partition::ID_APPLE_OTHER;
- }
- else if( val.find( "Apple_UFS" ) != string::npos )
- {
- id = Partition::ID_APPLE_UFS;
- }
- }
- }
- }
- if( label == "gpt" )
- {
- if( TInfo.find( ",boot," ) != string::npos &&
- TInfo.find( ",fat" ) != string::npos )
- {
- id = Partition::ID_GPT_BOOT;
- }
- if( TInfo.find( ",hp-service," ) != string::npos )
- {
- id = Partition::ID_GPT_SERVICE;
- }
- if( TInfo.find( ",msftres," ) != string::npos )
- {
- id = Partition::ID_GPT_MSFTRES;
- }
- if( TInfo.find( ",hfs+," ) != string::npos ||
- TInfo.find( ",hfs," ) != string::npos )
- {
- id = Partition::ID_APPLE_HFS;
- }
- }
- y2milestone( "Fields Num:%d Id:%x Ptype:%d Start:%ld Size:%ld",
- nr, id, type, start, csize );
+ range_exceed = max(range_exceed, (unsigned long) it->num);
}
- return( nr>0 );
- }
-bool
-Disk::checkPartedOutput( const SystemCmd& Cmd, ProcPart& ppart )
- {
- int cnt;
- string line;
- string tmp;
- unsigned long range_exceed = 0;
- list pl;
-
- cnt = Cmd.numLines();
- for( int i=0; i0 && isdigit(tmp[0]) )
- {
- if( scanPartedLine( line, pnr, c_start, c_size, type, id, boot ))
- {
- if( pnrdevice(), s ))
- {
- if( s>0 && p->type() != EXTENDED )
- p->setSize( s );
- }
- pl.push_back( p );
- }
- else
- range_exceed = max( range_exceed, (unsigned long)pnr );
- }
- }
- }
- y2mil( "nm:" << nm );
- if( !dmp_slave && !checkPartedValid( ppart, nm, pl, range_exceed ) )
+ y2mil("nm:" << nm);
+ if (!dmp_slave && !checkPartedValid(systeminfo, pl, range_exceed))
{
- string txt = sformat(
+ Text txt = sformat(
// popup text %1$s is replaced by disk name e.g. /dev/hda
_("The partitioning on disk %1$s is not readable by\n"
"the partitioning tool parted, which is used to change the\n"
@@ -954,14 +488,14 @@
}
if( range_exceed>0 )
{
- string txt = sformat(
+ Text txt = sformat(
// popup text %1$s is replaced by disk name e.g. /dev/hda
// %2$lu and %3$lu are replaced by numbers.
_("Your disk %1$s contains %2$lu partitions. The maximum number\n"
"of partitions that the kernel driver of the disk can handle is %3$lu.\n"
"Partitions numbered above %3$lu cannot be accessed."),
- (char*)dev.c_str(), range_exceed, range-1 );
- txt += "\n";
+ dev.c_str(), range_exceed, range-1 );
+ txt += Text("\n", "\n");
txt +=
// popup text
_("You have the following options:\n"
@@ -981,70 +515,72 @@
}
+ list<string>
+ Disk::partitionsKernelKnowns(const ProcParts& parts) const
+ {
+ // does not work for device-mapper based disks
+
+ string reg = "^" + dev + partNaming(dev) + "[0-9]+" "$";
+ list<string> ps = parts.getMatchingEntries(regex_matches(reg));
+ y2mil("dev:" << dev << " reg:\"" << reg << "\" ps:" << ps);
+ return ps;
+ }
+
+
bool
-Disk::checkPartedValid(const ProcPart& pp, const string& diskname,
- list& pl, unsigned long& range_exceed)
+Disk::checkPartitionsValid(SystemInfo& systeminfo, const list& pl) const
{
- unsigned ext_nr = 0;
- bool ret=true;
- unsigned long Dummy;
- unsigned long long SizeK;
- map proc_l;
- map parted_l;
- for( list::const_iterator i=pl.begin(); i!=pl.end(); i++ )
- {
- if( (*i)->type()==EXTENDED )
- ext_nr = (*i)->nr();
- else
- {
- parted_l[(*i)->nr()] = (*i)->cylSize();
- }
- }
- string reg = diskname;
- if( !reg.empty() && isdigit(reg[reg.length()-1]) )
- reg += "p";
- reg += "[0-9]+";
- list<string> ps = pp.getMatchingEntries( reg );
- y2mil( "regex " << reg << " ps " << ps );
- for( list<string>::const_iterator i=ps.begin(); i!=ps.end(); i++ )
- {
- pair p = getDiskPartition( *i );
- if( p.second>0 && p.second!=ext_nr &&
- pp.getInfo( *i, SizeK, Dummy, Dummy ))
- {
- proc_l[p.second] = kbToCylinder( SizeK );
- }
- }
- y2mil( "proc :" << proc_l );
- y2mil( "parted:" << parted_l );
- if( proc_l.size()>=parted_l.size() && !parted_l.empty() )
+ const Parted& parted = systeminfo.getParted(dev);
+
+ // It's allowed that the kernel sees more partitions than parted. This is
+ // the case with BSD slices.
+
+ for (list::const_iterator i = pl.begin(); i != pl.end(); ++i)
+ {
+ const Partition& p = **i;
+
+ if (p.type() != EXTENDED)
{
- map::const_iterator i, j;
- for( i=proc_l.begin(); i!=proc_l.end(); i++ )
+ Parted::Entry entry;
+ if (parted.getEntry(p.nr(), entry))
{
- j=parted_l.find(i->first);
- if( j!=parted_l.end() )
- {
- ret = ret && (abs((long)i->second-(long)j->second)<=2 ||
- abs((long)i->second-(long)j->second)<(long)j->second/100);
- }
- }
- for( i=parted_l.begin(); i!=parted_l.end(); i++ )
- {
- j=proc_l.find(i->first);
- if( j==proc_l.end() )
- ret = false;
- else
+ Region sec_parted = entry.secRegion;
+ Region sec_kernel = p.detectSysfsBlkRegion() / (sectorSize() / 512);
+
+ if (sec_parted != sec_kernel)
{
- ret = ret && (abs((long)i->second-(long)j->second)<=2 ||
- abs((long)i->second-(long)j->second)<(long)j->second/100);
+ y2err("region mismatch dev:" << dev << " nr:" << p.nr() << " sec_parted:" <<
+ sec_parted << " sec_kernel:" << sec_kernel);
+ return false;
}
}
}
- else
+ }
+
+ // But if parted sees no disk the kernel must also see no disks.
+
+ if (pl.empty())
+ {
+ const ProcParts& parts = systeminfo.getProcParts();
+ list<string> ps = partitionsKernelKnowns(parts);
+
+ if (!ps.empty())
{
- ret = parted_l.empty() && proc_l.empty();
+ y2err("parted sees no partitions but kernel does");
+ return false;
}
+ }
+
+ return true;
+}
+
+
+bool
+Disk::checkPartedValid(SystemInfo& systeminfo, list& pl,
+ unsigned long& range_exceed) const
+{
+ bool ret = checkPartitionsValid(systeminfo, pl);
+
if( !ret || label=="unsupported" )
{
range_exceed = 0;
@@ -1053,13 +589,15 @@
delete *i;
}
pl.clear();
- unsigned cyl_start = 1;
+ unsigned long cyl_start = 1;
+ const ProcParts& parts = systeminfo.getProcParts();
+ list<string> ps = partitionsKernelKnowns(parts);
for( list<string>::const_iterator i=ps.begin(); i!=ps.end(); i++ )
{
unsigned long cyl;
unsigned long long s;
pair pr = getDiskPartition( *i );
- if( pp.getSize( *i, s ))
+ if (parts.getSize(*i, s))
{
cyl = kbToCylinder(s);
if( pr.second!=0 && pr.second < range )
@@ -1068,7 +606,7 @@
PartitionType type = PRIMARY;
if( ext_possible )
{
- if( s==1 )
+ if (2 * s == procExtendedBlks())
{
type = EXTENDED;
id = Partition::ID_EXTENDED;
@@ -1078,9 +616,9 @@
type = LOGICAL;
}
}
- Partition *p =
- new Partition( *this, pr.second, s, cyl_start, cyl,
- type, id, false );
+ Partition *p = new Partition(*this, getPartName(pr.second), getPartDevice(pr.second),
+ pr.second, systeminfo, s, Region(cyl_start, cyl), type,
+ id);
pl.push_back( p );
}
else if( pr.second>0 )
@@ -1089,44 +627,59 @@
}
}
}
- y2mil("pr.size:" << proc_l.size() << " pa.size:" << parted_l.size());
+
y2mil("ret:" << ret);
return ret;
}
string
-Disk::defaultLabel(bool efiboot, unsigned long long num_sectors)
+Disk::defaultLabel() const
{
string ret = "msdos";
- if (efiboot)
- ret = "gpt";
- else if (num_sectors > (1ULL << 32) - 1)
- ret = "gpt";
- else if( Storage::arch()=="ia64" )
- ret = "gpt";
- else if( Storage::arch()=="sparc" )
- ret = "sun";
- else if( Storage::arch()=="ppc" && Storage::isPPCMac() )
- ret = "mac";
- else if( Storage::arch()=="ppc" && Storage::isPPCPegasos() )
- ret = "amiga";
- y2mil("efiboot:" << efiboot << " num_sectors:" << num_sectors << " ret:" << ret);
+
+ if (isDasd())
+ {
+ ret = "dasd";
+ }
+ else
+ {
+ const ArchInfo& archinfo = getStorage()->getArchInfo();
+ unsigned long long num_sectors = kbToSector(size_k);
+ y2mil("num_sectors:" << num_sectors);
+
+ ret = "msdos";
+ if (archinfo.is_efiboot)
+ ret = "gpt";
+ else if (num_sectors > (1ULL << 32) - 1)
+ ret = "gpt";
+ else if (archinfo.arch == "ia64")
+ ret = "gpt";
+ else if (archinfo.arch == "sparc")
+ ret = "sun";
+ else if (archinfo.arch == "ppc" && archinfo.is_ppc_mac)
+ ret = "mac";
+ else if (archinfo.arch == "ppc" && archinfo.is_ppc_pegasos)
+ ret = "amiga";
+ }
+
+ y2mil("ret:" << ret);
return ret;
}
-const Disk::label_info Disk::labels[] = {
- { "msdos", true, 4, 256, (1ULL << 32) - 1 }, // actually unlimited number of logical partitions
- { "gpt", false, 128, 0, (1ULL << 48) - 1 }, // actually 64 bit but we cannot calculate with that,
- // 48 bit looks nice since it matches LBA48
- { "bsd", false, 8, 0, (1ULL << 32) - 1 },
- { "sun", false, 8, 0, (1ULL << 32) - 1 },
- { "mac", false, 64, 0, (1ULL << 32) - 1 },
- { "dasd", false, 3, 0, (1ULL << 32) - 1 },
- { "aix", false, 0, 0, (1ULL << 32) - 1 },
- { "amiga", false, 63, 0, (1ULL << 32) - 1 },
- { "", false, 0, 0, 0 }
-};
+
+ const Disk::label_info Disk::labels[] = {
+ { "msdos", true, 4, 256, (1ULL << 32) - 1 }, // actually unlimited number of logical partitions
+ { "gpt", false, 128, 0, (1ULL << 48) - 1 }, // actually 64 bit but we cannot calculate with that,
+ // 48 bit looks nice since it matches LBA48
+ { "bsd", false, 8, 0, (1ULL << 32) - 1 },
+ { "sun", false, 8, 0, (1ULL << 32) - 1 },
+ { "mac", false, 64, 0, (1ULL << 32) - 1 },
+ { "dasd", false, 3, 0, (1ULL << 32) - 1 },
+ { "aix", false, 0, 0, (1ULL << 32) - 1 },
+ { "amiga", false, 63, 0, (1ULL << 32) - 1 },
+ { "", false, 0, 0, 0 }
+ };
Region Disk::usableCylRegion() const
@@ -1139,32 +692,20 @@
}
-const string Disk::p_disks [] = { "cciss/", "ida/", "ataraid/", "etherd/", "rd/" };
+ const string Disk::p_disks[] = { "cciss/", "ida/", "ataraid/", "etherd/", "rd/", "mmcblk[0-9]+",
+ "md[0-9]+" };
+
-bool Disk::needP( const string& disk )
+ bool
+ Disk::needP(const string& disk)
{
- bool need_p = false;
- unsigned i=0;
- static Regex mdpart( "md[0123456789]+$" );
- if ( mdpart.match( disk ) == true )
- {
- return true;
- }
- static Regex mmcblkpart( "mmcblk[0123456789]+$" );
- if ( mmcblkpart.match( disk ) == true )
- {
- return true;
- }
- while( !need_p && i Disk::getDiskPartition( const string& dev )
{
static Regex prx( "[0123456789]p[0123456789]+$" );
@@ -1217,7 +757,7 @@
disk = dev.substr( 0, pos );
}
y2mil( "dev:" << dev << " disk:" << disk << " nr:" << nr );
- return( make_pair(disk,nr) );
+ return make_pair(disk, nr);
}
@@ -1256,9 +796,9 @@
unsigned
Disk::availablePartNumber(PartitionType type) const
{
- y2mil("begin name:" << name() << " type:" << type);
+ y2mil("begin name:" << name() << " type:" << toString(type));
unsigned ret = 0;
- ConstPartPair p = partPair( notDeleted );
+ ConstPartPair p = partPair(Partition::notDeleted);
if( !ext_possible && type==LOGICAL )
{
ret = 0;
@@ -1348,7 +888,7 @@
list<Region> tmp;
for (ConstPartIter i = p.begin(); i != p.end(); ++i)
- tmp.push_back(Region(i->cylStart(), i->cylEnd() - i->cylStart() + 1));
+ tmp.push_back(i->cylRegion());
tmp.sort();
for (list<Region>::const_iterator i = tmp.begin(); i != tmp.end(); ++i)
@@ -1373,7 +913,7 @@
list<Region> tmp;
for (ConstPartIter i = p.begin(); i != p.end(); ++i)
- tmp.push_back(Region(i->cylStart(), i->cylEnd() - i->cylStart() + 1));
+ tmp.push_back(i->cylRegion());
tmp.sort();
for (list<Region>::const_iterator i = tmp.begin(); i != tmp.end(); ++i)
@@ -1417,22 +957,22 @@
int Disk::createPartition( unsigned long cylLen, string& device,
bool checkRelaxed )
{
- y2milestone( "len %ld relaxed:%d", cylLen, checkRelaxed );
+ y2mil("len:" << cylLen << " relaxed:" << checkRelaxed);
getStorage()->logCo( this );
int ret = 0;
list<Region> free;
getUnusedSpace( free );
- y2milestone( "free:" );
+ y2mil("free:");
if( !free.empty() )
{
free.sort( regions_sort_size );
- list<Region>::iterator i = free.begin();
+ list<Region>::const_iterator i = free.begin();
while( i!=free.end() && i->len()>=cylLen )
++i;
--i;
if( i->len()>=cylLen )
{
- PartPair ext = partPair(notDeletedExt);
+ ConstPartPair ext = partPair(notDeletedExt);
PartitionType t = PRIMARY;
bool usable = false;
do
@@ -1464,15 +1004,15 @@
int Disk::createPartition( PartitionType type, string& device )
{
- y2milestone( "type %u", type );
+ y2mil("type " << toString(type));
int ret = 0;
list<Region> free;
getUnusedSpace( free, type==PTYPE_ANY, type==LOGICAL );
if( !free.empty() )
{
free.sort( regions_sort_size );
- list<Region>::iterator i = free.begin();
- PartPair ext = partPair(notDeletedExt);
+ list<Region>::const_iterator i = free.begin();
+ ConstPartPair ext = partPair(notDeletedExt);
PartitionType t = type;
bool usable = false;
do
@@ -1505,18 +1045,14 @@
{
int ret = 0;
device = "";
- nr = 0;
- unsigned number = availablePartNumber( type );
- if( number==0 )
+ nr = availablePartNumber( type );
+ if (nr == 0)
{
ret = DISK_PARTITION_NO_FREE_NUMBER;
}
else
{
- Partition * p = new Partition( *this, number, 0, 0, 1, type );
- device = p->device();
- nr = p->nr();
- delete( p );
+ device = getPartDevice(nr);
}
y2mil("ret:" << ret << " nr:" << nr << " device:" << device);
return ret;
@@ -1527,10 +1063,10 @@
unsigned long len, string& device,
bool checkRelaxed )
{
- y2milestone( "begin type %d at %ld len %ld relaxed:%d", type, start, len,
- checkRelaxed );
+ y2mil("begin type " << toString(type) << " at " << start << " len " << len << " relaxed:" <<
+ checkRelaxed);
getStorage()->logCo( this );
- int ret = createChecks( type, start, len, checkRelaxed );
+ int ret = createChecks(type, Region(start, len), checkRelaxed);
unsigned number = 0;
if( ret==0 )
{
@@ -1544,10 +1080,10 @@
{
if( label=="sun" && start==0 )
start=1;
- Partition * p = new Partition( *this, number, cylinderToKb(len), start,
- len, type );
- PartPair pp = partPair();
- PartIter i=pp.begin();
+ Partition * p = new Partition(*this, getPartName(number), getPartDevice(number), number,
+ cylinderToKb(len), Region(start, len), type);
+ ConstPartPair pp = partPair();
+ ConstPartIter i = pp.begin();
while( i!=pp.end() && !(i->deleted() && i->cylStart()==start) )
++i;
if( i!=pp.end() )
@@ -1574,22 +1110,22 @@
addToList( p );
}
getStorage()->logCo( this );
- y2milestone( "ret:%d device:%s", ret, ret==0?device.c_str():"" );
+ y2mil("ret:" << ret << " device:" << (ret==0?device:""));
return( ret );
}
-int Disk::createChecks( PartitionType& type, unsigned long start,
- unsigned long len, bool checkRelaxed )
+
+ int
+ Disk::createChecks(PartitionType& type, const Region& cylRegion, bool checkRelaxed) const
{
- y2milestone( "begin type %d at %ld len %ld relaxed:%d", type, start, len,
- checkRelaxed );
+ y2mil("type:" << toString(type) << " cylRegion:" << cylRegion << " relaxed:" <<
+ checkRelaxed);
unsigned fuzz = checkRelaxed ? fuzz_cyl : 0;
int ret = 0;
- Region r( start, len );
- PartPair ext = partPair(notDeletedExt);
+ ConstPartPair ext = partPair(notDeletedExt);
if( type==PTYPE_ANY )
{
- if( ext.empty() || !ext.begin()->contains( Region(start,1) ))
+ if( ext.empty() || !ext.begin()->contains( Region(cylRegion.start(), 1) ))
type = PRIMARY;
else
type = LOGICAL;
@@ -1599,12 +1135,12 @@
{
ret = DISK_CHANGE_READONLY;
}
- if( ret==0 && (r.end() > cylinders()+fuzz) )
+ if( ret==0 && (cylRegion.end() > cylinders()+fuzz) )
{
- y2milestone( "too large for disk cylinders %lu", cylinders() );
+ y2mil("too large for disk cylinders " << cylinders());
ret = DISK_PARTITION_EXCEEDS_DISK;
}
- if( ret==0 && len==0 )
+ if( ret==0 && cylRegion.empty() )
{
ret = DISK_PARTITION_ZERO_SIZE;
}
@@ -1614,24 +1150,23 @@
}
if( ret==0 )
{
- PartPair p = (type!=LOGICAL) ? partPair( notDeleted )
- : partPair( notDeletedLog );
- PartIter i = p.begin();
- while( i!=p.end() && !i->intersectArea( r, fuzz ))
+ ConstPartPair p = (type != LOGICAL) ? partPair(Partition::notDeleted) : partPair(notDeletedLog);
+ ConstPartIter i = p.begin();
+ while( i!=p.end() && !i->intersectArea( cylRegion, fuzz ))
{
++i;
}
if( i!=p.end() )
{
- y2war( "overlaps r:" << r << " p:" << i->region() <<
- " inter:" << i->region().intersect(r) );
+ y2war("overlaps r:" << cylRegion << " p:" << i->cylRegion() <<
+ " inter:" << i->cylRegion().intersect(cylRegion) );
ret = DISK_PARTITION_OVERLAPS_EXISTING;
}
}
- if( ret==0 && type==LOGICAL && !ext.begin()->contains( r, fuzz ))
+ if( ret==0 && type==LOGICAL && !ext.begin()->contains( cylRegion, fuzz ))
{
- y2war( "outside ext r:" << r << " ext:" << ext.begin()->region() <<
- "inter:" << ext.begin()->region().intersect(r) );
+ y2war("outside ext r:" << cylRegion << " ext:" << ext.begin()->cylRegion() <<
+ "inter:" << ext.begin()->cylRegion().intersect(cylRegion) );
ret = DISK_PARTITION_LOGICAL_OUTSIDE_EXT;
}
if( ret==0 && type==EXTENDED )
@@ -1643,22 +1178,21 @@
}
}
y2mil("ret:" << ret);
- return( ret );
+ return ret;
}
-int Disk::changePartitionArea( unsigned nr, unsigned long start,
- unsigned long len, bool checkRelaxed )
+
+ int
+ Disk::changePartitionArea(unsigned nr, const Region& cylRegion, bool checkRelaxed)
{
- y2milestone( "begin nr %u at %ld len %ld relaxed:%d", nr, start, len,
- checkRelaxed );
+ y2mil("begin nr:" << nr << " cylRegion:" << cylRegion << " relaxed:" << checkRelaxed);
int ret = 0;
- Region r( start, len );
unsigned fuzz = checkRelaxed ? fuzz_cyl : 0;
if( readonly() )
{
ret = DISK_CHANGE_READONLY;
}
- PartPair p = partPair( notDeleted );
+ PartPair p = partPair(Partition::notDeleted);
PartIter part = p.begin();
while( ret==0 && part!=p.end() && part->nr()!=nr)
{
@@ -1668,55 +1202,55 @@
{
ret = DISK_PARTITION_NOT_FOUND;
}
- if( ret==0 && r.end() > cylinders()+fuzz )
+ if( ret==0 && cylRegion.end() > cylinders()+fuzz )
{
- y2milestone( "too large for disk cylinders %lu", cylinders() );
+ y2mil("too large for disk cylinders " << cylinders());
ret = DISK_PARTITION_EXCEEDS_DISK;
}
- if( ret==0 && len==0 )
+ if( ret==0 && cylRegion.empty() )
{
ret = DISK_PARTITION_ZERO_SIZE;
}
if( ret==0 && part->type()==LOGICAL )
{
- PartPair ext = partPair(notDeletedExt);
+ ConstPartPair ext = partPair(notDeletedExt);
p = partPair( notDeletedLog );
- PartIter i = p.begin();
- while( i!=p.end() && (i==part||!i->intersectArea( r, fuzz )) )
+ ConstPartIter i = p.begin();
+ while( i!=p.end() && (i==part||!i->intersectArea( cylRegion, fuzz )) )
{
++i;
}
if( i!=p.end() )
{
- y2war( "overlaps r:" << r << " p:" << i->region() <<
- " inter:" << i->region().intersect(r) );
+ y2war("overlaps r:" << cylRegion << " p:" << i->cylRegion() <<
+ " inter:" << i->cylRegion().intersect(cylRegion) );
ret = DISK_PARTITION_OVERLAPS_EXISTING;
}
- if( ret==0 && !ext.begin()->contains( r, fuzz ))
+ if( ret==0 && !ext.begin()->contains( cylRegion, fuzz ))
{
- y2war( "outside ext r:" << r << " ext:" << ext.begin()->region() <<
- "inter:" << ext.begin()->region().intersect(r) );
+ y2war("outside ext r:" << cylRegion << " ext:" << ext.begin()->cylRegion() <<
+ "inter:" << ext.begin()->cylRegion().intersect(cylRegion) );
ret = DISK_PARTITION_LOGICAL_OUTSIDE_EXT;
}
}
if( ret==0 && part->type()!=LOGICAL )
{
- PartIter i = p.begin();
+ ConstPartIter i = p.begin();
while( i!=p.end() &&
- (i==part || i->nr()>max_primary || !i->intersectArea( r, fuzz )))
+ (i==part || i->nr()>max_primary || !i->intersectArea( cylRegion, fuzz )))
{
++i;
}
if( i!=p.end() )
{
- y2war( "overlaps r:" << r << " p:" << i->region() <<
- " inter:" << i->region().intersect(r) );
+ y2war("overlaps r:" << cylRegion << " p:" << i->cylRegion() <<
+ " inter:" << i->cylRegion().intersect(cylRegion) );
ret = DISK_PARTITION_OVERLAPS_EXISTING;
}
}
if( ret==0 )
{
- part->changeRegion( start, len, cylinderToKb(len) );
+ part->changeRegion(cylRegion, cylinderToKb(cylRegion.len()));
}
y2mil("ret:" << ret);
return( ret );
@@ -1729,10 +1263,10 @@
int Disk::removePartition( unsigned nr )
{
- y2milestone( "begin nr %u", nr );
+ y2mil("begin nr " << nr);
getStorage()->logCo( this );
int ret = 0;
- PartPair p = partPair( notDeleted );
+ PartPair p = partPair(Partition::notDeleted);
PartIter i = p.begin();
while( i!=p.end() && i->nr()!=nr)
{
@@ -1746,7 +1280,7 @@
{
ret = DISK_CHANGE_READONLY;
}
- else if( i->getUsedByType() != UB_NONE )
+ else if (i->isUsedBy())
{
ret = DISK_REMOVE_USED_BY;
}
@@ -1757,7 +1291,7 @@
{
if( !removeFromList( &(*i) ))
ret = DISK_REMOVE_PARTITION_CREATE_NOT_FOUND;
- p = partPair( notDeleted );
+ p = partPair(Partition::notDeleted);
}
else
i->setDeleted();
@@ -1823,7 +1357,7 @@
void Disk::changeNumbers( const PartIter& b, const PartIter& e,
unsigned start, int incr )
{
- y2milestone( "start:%u incr:%d", start, incr );
+ y2mil("start:" << start << " incr:" << incr);
PartIter i(b);
while( i!=e )
{
@@ -1837,7 +1371,7 @@
int Disk::destroyPartitionTable( const string& new_label )
{
- y2milestone( "begin" );
+ y2mil("begin");
int ret = 0;
setLabelData( new_label );
if( max_primary==0 )
@@ -1861,7 +1395,7 @@
}
bool save = getStorage()->getRecursiveRemoval();
getStorage()->setRecursiveRemoval(true);
- if( getUsedByType() != UB_NONE )
+ if (isUsedBy())
{
getStorage()->removeUsing( device(), getUsedBy() );
}
@@ -1874,7 +1408,7 @@
++i;
}
getStorage()->setRecursiveRemoval(save);
- setDeleted( true );
+ del_ptable = true;
}
y2mil("ret:" << ret);
return( ret );
@@ -1886,7 +1420,7 @@
{
y2mil("begin nr:" << nr << " id:" << hex << id);
int ret = 0;
- PartPair p = partPair( notDeleted );
+ PartPair p = partPair(Partition::notDeleted);
PartIter i = p.begin();
while( i!=p.end() && i->nr()!=nr)
{
@@ -1913,9 +1447,9 @@
int Disk::forgetChangePartitionId( unsigned nr )
{
- y2milestone( "begin nr:%u", nr );
+ y2mil("begin nr:" << nr);
int ret = 0;
- PartPair p = partPair( notDeleted );
+ PartPair p = partPair(Partition::notDeleted);
PartIter i = p.begin();
while( i!=p.end() && i->nr()!=nr)
{
@@ -1937,28 +1471,29 @@
return( ret );
}
-int Disk::getToCommit( CommitStage stage, list& col,
- list& vol )
+
+void
+Disk::getToCommit(CommitStage stage, list& col, list& vol) const
{
- int ret = 0;
unsigned long oco = col.size();
unsigned long ovo = vol.size();
Container::getToCommit( stage, col, vol );
if( stage==INCREASE )
{
- PartPair p = partPair( Partition::toChangeId );
- for( PartIter i=p.begin(); i!=p.end(); ++i )
+ ConstPartPair p = partPair( Partition::toChangeId );
+ for( ConstPartIter i=p.begin(); i!=p.end(); ++i )
if( find( vol.begin(), vol.end(), &(*i) )==vol.end() )
vol.push_back( &(*i) );
}
+ if( del_ptable && find( col.begin(), col.end(), this )==col.end() )
+ col.push_back( this );
if( col.size()!=oco || vol.size()!=ovo )
- y2milestone( "ret:%d col:%zd vol:%zd", ret, col.size(), vol.size());
- return( ret );
+ y2mil("stage:" << stage << " col:" << col.size() << " vol:" << vol.size());
}
int Disk::commitChanges( CommitStage stage, Volume* vol )
{
- y2milestone( "name %s stage %d", name().c_str(), stage );
+ y2mil("name:" << name() << " stage:" << stage);
int ret = Container::commitChanges( stage, vol );
if( ret==0 && stage==INCREASE )
{
@@ -1977,9 +1512,9 @@
int Disk::commitChanges( CommitStage stage )
{
- y2milestone( "name %s stage %d", name().c_str(), stage );
+ y2mil("name:" << name() << " stage:" << stage);
int ret = 0;
- if( stage==DECREASE && deleted() )
+ if( stage==DECREASE && del_ptable )
{
ret = doCreateLabel();
}
@@ -1989,51 +1524,44 @@
return( ret );
}
-void Disk::getCommitActions( list& l ) const
+
+void
+Disk::getCommitActions(list<commitAction>& l) const
{
Container::getCommitActions( l );
- if( deleted() )
+ if( del_ptable )
{
- list::iterator i = l.begin();
- while( i!=l.end() )
- {
- if( (*i)->stage==DECREASE )
- {
- delete( *i );
- i=l.erase( i );
- }
- else
- ++i;
- }
- l.push_front( new commitAction( DECREASE, staticType(),
- setDiskLabelText(false), this, true ));
+ l.remove_if(stage_is(DECREASE));
+ l.push_front(commitAction(DECREASE, staticType(), setDiskLabelText(false), this, true));
}
}
-string Disk::setDiskLabelText( bool doing ) const
+
+ Text
+ Disk::setDiskLabelText(bool doing) const
{
- string txt;
- string d = dev;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by disk name (e.g. /dev/hda),
// %2$s is replaced by label name (e.g. msdos)
- txt = sformat( _("Setting disk label of disk %1$s to %2$s"),
- d.c_str(), label.c_str() );
+ txt = sformat(_("Setting disk label of %1$s to %2$s"), dev.c_str(),
+ boost::to_upper_copy(label).c_str());
}
else
{
// displayed text before action, %1$s is replaced by disk name (e.g. /dev/hda),
// %2$s is replaced by label name (e.g. msdos)
- txt = sformat( _("Set disk label of disk %1$s to %2$s"),
- d.c_str(), label.c_str() );
+ txt = sformat(_("Set disk label of %1$s to %2$s"), dev.c_str(),
+ boost::to_upper_copy(label).c_str());
}
- return( txt );
+ return txt;
}
+
int Disk::doCreateLabel()
{
- y2milestone( "label:%s", label.c_str() );
+ y2mil("label:" << label);
int ret = 0;
if( !silent )
{
@@ -2042,9 +1570,11 @@
if( !dmp_slave )
getStorage()->removeDmMapsTo( device() );
removePresentPartitions();
- system_stderr.erase();
std::ostringstream cmd_line;
classic(cmd_line);
+ cmd_line << MDADMBIN " --zero-superblock --force " << quote(device());
+ execCheckFailed( cmd_line.str() );
+ cmd_line.str("");
cmd_line << PARTEDCMD << quote(device()) << " mklabel " << label;
if( execCheckFailed( cmd_line.str() ) )
{
@@ -2052,13 +1582,13 @@
}
else
{
- setDeleted(false);
+ del_ptable = false;
removeFromMemory();
}
if( ret==0 )
{
if( !dmp_slave )
- getStorage()->waitForDevice();
+ Storage::waitForDevice();
redetectGeometry();
}
gpt_enlarge = false;
@@ -2096,6 +1626,7 @@
y2mil( "rem:" << *i );
if( !(*i)->created() )
{
+ delete *i;
i = vols.erase( i );
}
else
@@ -2103,33 +1634,23 @@
}
}
-void Disk::redetectGeometry()
+
+ void
+ Disk::redetectGeometry()
{
- string cmd_line = PARTEDCMD + quote(device()) + " unit cyl print";
- y2milestone( "executing cmd:%s", cmd_line.c_str() );
- SystemCmd Cmd( cmd_line );
- if( Cmd.select( "BIOS cylinder" )>0 )
- {
- unsigned long c;
- unsigned h;
- unsigned s;
- string tmp = *Cmd.getLine(0, true);
- getGeometry( tmp, c, h, s );
- if( c!=0 && c!=cyl )
- {
- new_cyl = c;
- new_head = h;
- new_sector = s;
- y2milestone( "new parted geometry Head:%u Sector:%u Cylinder:%lu",
- new_head, new_sector, new_cyl );
- }
+ Parted parted(device());
+ Geometry tmp_geometry = parted.getGeometry();
+ if (tmp_geometry != geometry)
+ {
+ new_geometry = tmp_geometry;
+ y2mil("new parted geometry " << new_geometry);
}
}
+
int Disk::doSetType( Volume* v )
{
- y2milestone( "doSetType container %s name %s", name().c_str(),
- v->name().c_str() );
+ y2mil("doSetType container " << name() << " name " << v->name());
Partition * p = dynamic_cast(v);
int ret = 0;
if( p != NULL )
@@ -2140,66 +1661,39 @@
}
if( p->id()!=Partition::ID_LINUX && p->id()!=Partition::ID_SWAP )
p->eraseLabel();
- system_stderr.erase();
- std::ostringstream cmd_line;
- classic(cmd_line);
- cmd_line << PARTEDCMD << quote(device()) << " set " << p->nr() << " ";
- string start_cmd = cmd_line.str();
- if( ret==0 )
- {
- cmd_line.str( start_cmd );
- cmd_line.seekp(0, ios_base::end );
- cmd_line << "lvm " << (p->id()==Partition::ID_LVM ? "on" : "off");
- if( execCheckFailed( cmd_line.str() ) && !dmp_slave )
- {
- ret = DISK_SET_TYPE_PARTED_FAILED;
- }
- }
- if( ret==0 && (label!="sun"))
- {
- cmd_line.str( start_cmd );
- cmd_line.seekp(0, ios_base::end );
- cmd_line << "raid " << (p->id()==Partition::ID_RAID?"on":"off");
- if( execCheckFailed( cmd_line.str() ) && !dmp_slave )
- {
- ret = DISK_SET_TYPE_PARTED_FAILED;
- }
- }
- if( ret==0 && (label=="dvh"||label=="mac"))
- {
- cmd_line.str( start_cmd );
- cmd_line.seekp(0, ios_base::end );
- cmd_line << "swap " << (p->id()==Partition::ID_SWAP?"on":"off");
- if( execCheckFailed( cmd_line.str() ) && !dmp_slave )
- {
- ret = DISK_SET_TYPE_PARTED_FAILED;
- }
- }
+
+ std::ostringstream options;
+ classic(options);
+
if( ret==0 )
+ {
+ options << " set " << p->nr() << " lvm " << (p->id()==Partition::ID_LVM ? "on" : "off");
+
+ if (label != "sun")
+ options << " set " << p->nr() << " raid " << (p->id()==Partition::ID_RAID?"on":"off");
+
+ if (label == "dvh" || label == "mac")
+ options << " set " << p->nr() << " swap " << (p->id()==Partition::ID_SWAP?"on":"off");
+
+ options << " set " << p->nr() << " boot " << ((p->boot()||p->id()==Partition::ID_GPT_BOOT)?"on":"off");
+
+ if (p->id() <= 255 && label == "msdos")
+ options << " set " << p->nr() << " type " << p->id();
+ }
+
+ if (!options.str().empty())
+ {
+ string cmd_line = PARTEDCMD + quote(device()) + options.str();
+ if( execCheckFailed( cmd_line ) && !dmp_slave )
{
- cmd_line.str( start_cmd );
- cmd_line.seekp(0, ios_base::end );
- cmd_line << "boot " <<
- ((p->boot()||p->id()==Partition::ID_GPT_BOOT)?"on":"off");
- if( execCheckFailed( cmd_line.str() ) && !dmp_slave )
- {
- ret = DISK_SET_TYPE_PARTED_FAILED;
- }
- }
- if( ret==0 && p->id()<=255 && label=="msdos" )
- {
- cmd_line.str( start_cmd );
- cmd_line.seekp(0, ios_base::end );
- cmd_line << "type " << p->id();
- if( execCheckFailed( cmd_line.str() ) && !dmp_slave )
- {
ret = DISK_SET_TYPE_PARTED_FAILED;
- }
}
+ }
+
if( ret==0 )
{
if( !dmp_slave )
- getStorage()->waitForDevice( p->device() );
+ Storage::waitForDevice(p->device());
p->changeIdDone();
}
}
@@ -2211,135 +1705,116 @@
return( ret );
}
-int
-Disk::callDelpart( unsigned nr ) const
+
+ bool
+ Disk::callDelpart(unsigned nr) const
{
- SystemCmd c( DELPARTBIN " " + quote(device()) + ' ' + decString(nr) );
- return( c.retcode() );
+ SystemCmd c(DELPARTBIN " " + quote(device()) + ' ' + decString(nr));
+ return c.retcode() == 0;
}
-int
-Disk::callAddpart( unsigned nr, unsigned long long sstart,
- unsigned long long ssize ) const
+
+ bool
+ Disk::callAddpart(unsigned nr, const Region& blkRegion) const
{
- SystemCmd c( ADDPARTBIN " " + quote(device()) + ' ' + decString(nr) + ' ' +
- decString(sstart) + ' ' + decString(ssize) );
- return( c.retcode() );
+ SystemCmd c(ADDPARTBIN " " + quote(device()) + ' ' + decString(nr) + ' ' +
+ decString(blkRegion.start()) + ' ' + decString(blkRegion.len()));
+ return c.retcode() == 0;
}
+
+unsigned long long
+Disk::procExtendedBlks() const
+{
+ return std::max(2U, sectorSize() / 512);
+}
+
+
bool
-Disk::getPartedValues( Partition *p )
+Disk::getPartedValues( Partition *p ) const
{
y2mil( "nr:" << p->nr() );
bool ret = false;
- if( getStorage()->testmode() )
+ if (getStorage()->testmode())
{
ret = true;
p->setSize( p->sizeK() );
}
else
{
- std::ostringstream cmd_line;
- classic(cmd_line);
- cmd_line << PARTEDCMD << quote(device()) << " unit cyl print unit s print";
- std::string cmd_str = cmd_line.str();
- cmd_line << " | grep -w \"^[ \t]*\"" << p->nr();
- SystemCmd cmd( cmd_line.str() );
- unsigned nr, id;
- unsigned long start, csize;
- unsigned long long sstart, ssize;
- PartitionType type;
- bool boot;
- if( cmd.numLines()>1 &&
- scanPartedSectors( *cmd.getLine(1), nr, sstart, ssize ))
- {
- string start_p = p->sysfsPath() + "/start";
- string size_p = p->sysfsPath() + "/size";
- y2mil("start_p:" << start_p << " size_p:" << size_p);
- unsigned long long sysfs_start = 0;
- unsigned long long sysfs_size = 0;
- read_sysfs_property(start_p, sysfs_start, false);
- read_sysfs_property(size_p, sysfs_size, false);
- if( p->type()==EXTENDED )
- ssize=2;
- y2mil( "sectors nr:" << nr << " sysfs start:" << sysfs_start <<
- " size:" << sysfs_size );
- y2mil( "sectors nr:" << nr << " parted start:" << sstart <<
- " size:" << ssize );
- if( nr == p->nr() && !no_addpart &&
- (sysfs_start!=sstart || sysfs_size!=ssize) )
- {
- callDelpart( nr );
- callAddpart( nr, sstart, ssize );
- read_sysfs_property(start_p, sysfs_start);
- read_sysfs_property(size_p, sysfs_size);
- if( sysfs_start!=sstart || sysfs_size!=ssize )
- y2err( "addpart failed sectors parted:" << sstart << ' ' <<
- ssize << " sysfs:" << sysfs_start << ' ' <<
- sysfs_size );
- }
- }
- if( cmd.numLines()>0 &&
- scanPartedLine( *cmd.getLine(0), nr, start, csize, type,
- id, boot ))
- {
- ProcPart ppart;
- y2milestone( "really created at cyl:%ld csize:%ld", start, csize );
- p->changeRegion( start, csize, cylinderToKb(csize) );
- unsigned long long s=0;
+ Parted parted(device());
+ Parted::Entry entry;
+ if (parted.getEntry(p->nr(), entry))
+ {
+ Region partedBlkRegion = sectorSize() / 512 * entry.secRegion;
+ y2mil("partedBlkRegion:" << partedBlkRegion);
+
+ if (p->type() == EXTENDED)
+ partedBlkRegion.setLen(procExtendedBlks());
+
+ Region sysfsBlkRegion = p->detectSysfsBlkRegion(false);
+ y2mil("sysfsBlkRegion:" << sysfsBlkRegion);
+
+ if (!no_addpart && partedBlkRegion != sysfsBlkRegion)
+ {
+ callDelpart(p->nr());
+ callAddpart(p->nr(), partedBlkRegion);
+
+ sysfsBlkRegion = p->detectSysfsBlkRegion();
+
+ if (partedBlkRegion != sysfsBlkRegion)
+ y2err("addpart failed sysfsBlkRegion:" << sysfsBlkRegion);
+ }
+
+ const Region& partedCylRegion = entry.cylRegion;
+ y2mil("partedCylRegion:" << partedCylRegion);
+ p->changeRegion(partedCylRegion, cylinderToKb(partedCylRegion.len()));
+
ret = true;
+
if( !dmp_slave && p->type() != EXTENDED )
{
- if( !ppart.getSize( p->device(), s ) || s==0 )
+ ProcParts parts;
+ unsigned long long s = 0;
+ if (!parts.getSize(p->procName(), s) || s == 0)
{
- y2error( "device %s not found in /proc/partitions",
- p->device().c_str() );
+ y2err("device " << p->device() << " not found in /proc/partitions");
ret = false;
}
else
p->setSize( s );
}
}
- cmd.execute( cmd_str );
}
return( ret );
}
bool
Disk::getPartedSectors( const Partition *p, unsigned long long& start,
- unsigned long long& end )
+ unsigned long long& end ) const
{
bool ret = false;
- if( getStorage()->testmode() )
+ if (getStorage()->testmode())
{
ret = true;
- start = p->cylStart()*new_head*new_sector;
- end = (p->cylEnd()+1)*new_head*new_sector-1;
+ start = p->cylStart() * new_geometry.heads * new_geometry.sectors;
+ end = (p->cylEnd() + 1) * new_geometry.heads * new_geometry.sectors - 1;
}
else
{
- std::ostringstream cmd_line;
- classic(cmd_line);
- cmd_line << PARTEDCMD << quote(device()) << " unit s print | grep -w \"^[ \t]*\"" << p->nr();
- SystemCmd cmd( cmd_line.str() );
- if( cmd.numLines()>0 )
- {
- string dummy, s1, s2;
- std::istringstream data( *cmd.getLine(0) );
- classic(data);
- data >> dummy >> s1 >> s2;
- y2milestone( "dummy:\"%s\" s1:\"%s\" s2:\"%s\"", dummy.c_str(),
- s1.c_str(), s2.c_str() );
- start = end = 0;
- s1 >> start;
- s2 >> end;
- y2milestone( "start:%llu end:%llu", start, end );
- ret = end>0;
- }
+ Parted parted(device());
+ Parted::Entry entry;
+ if (parted.getEntry(p->nr(), entry))
+ {
+ start = entry.secRegion.start();
+ end = entry.secRegion.end();
+ ret = true;
+ }
}
return( ret );
}
+
void Disk::enlargeGpt()
{
y2mil( "gpt_enlarge:" << gpt_enlarge );
@@ -2369,13 +1844,9 @@
{
getStorage()->showInfoCb( p->createText(true) );
}
- system_stderr.erase();
- y2milestone( "doCreate container %s name %s", name().c_str(),
- p->name().c_str() );
- y2milestone( "doCreate nr:%d start %ld len %ld", p->nr(),
- p->cylStart(), p->cylSize() );
- y2milestone( "doCreate detected_label:%s label:%s",
- detected_label.c_str(), label.c_str() );
+ y2mil("doCreate container " << name() << " name " << p->name());
+ y2mil("doCreate nr:" << p->nr() << " start " << p->cylStart() << " len " << p->cylSize());
+ y2mil("doCreate detected_label:" << detected_label << " label:" << label);
if( detected_label != label )
{
ret = doCreateLabel();
@@ -2391,10 +1862,7 @@
if( ret==0 )
{
cmd_line << PARTEDCMD;
- if( getStorage()->getPartitionAlignment()==ALIGN_CYLINDER )
- cmd_line << "--align=cylinder ";
- else
- cmd_line << "--align=optimal ";
+ cmd_line << "--align=" << toString(getStorage()->getPartitionAlignment()) << " ";
cmd_line << quote(device()) << " unit cyl mkpart ";
if( label != "sun" )
{
@@ -2423,7 +1891,7 @@
}
else if( p->id()==Partition::ID_GPT_BOOT ||
p->id()==Partition::ID_DOS16 ||
- p->id()==Partition::ID_DOS )
+ p->id()==Partition::ID_DOS32 )
{
cmd_line << "fat32 ";
}
@@ -2441,18 +1909,18 @@
{
unsigned long start = p->cylStart();
unsigned long end = p->cylStart()+p->cylSize();
- PartPair pp = (p->type()!=LOGICAL) ? partPair( existingNotLog )
- : partPair( existingLog );
+ ConstPartPair pp = (p->type()!=LOGICAL) ? partPair( existingNotLog )
+ : partPair( existingLog );
unsigned long maxc = cylinders();
if( p->type()==LOGICAL )
{
- PartPair ext = partPair(notDeletedExt);
+ ConstPartPair ext = partPair(notDeletedExt);
if( !ext.empty() )
maxc = ext.begin()->cylEnd();
}
- y2milestone( "max %lu end:%lu", maxc, end );
- y2mil( "pp " << *p );
- for( PartIter i=pp.begin(); i!=pp.end(); ++i )
+ y2mil("max " << maxc << " end:" << end);
+ y2mil("pp " << *p);
+ for (ConstPartIter i = pp.begin(); i != pp.end(); ++i)
{
y2mil( "i " << *i );
if( i->cylStart()cylStart()maxc && maxc<=cylinders() )
{
- y2milestone( "corrected end from %lu to max %lu", end, maxc );
+ y2mil("corrected end from " << end << " to max " << maxc);
end = maxc;
}
if( start==0 && (label == "mac" || label == "amiga") )
@@ -2515,7 +1981,7 @@
// kludge to make the extended partition visible in
// /proc/partitions otherwise grub refuses to install if root
// filesystem is a logical partition
- PartPair lc = partPair(logicalCreated);
+ ConstPartPair lc = partPair(logicalCreated);
call_blockdev = lc.length()<=1;
y2mil("logicalCreated:" << lc.length() << " call_blockdev:" << call_blockdev);
}
@@ -2543,9 +2009,9 @@
}
if( !dmp_slave && call_blockdev )
{
- SystemCmd c("/sbin/blockdev --rereadpt " + quote(device()));
+ SystemCmd c(BLOCKDEVBIN " --rereadpt " + quote(device()));
if( p->type()!=EXTENDED )
- getStorage()->waitForDevice( p->device() );
+ Storage::waitForDevice(p->device());
}
}
else
@@ -2566,12 +2032,10 @@
{
getStorage()->showInfoCb( p->removeText(true) );
}
- system_stderr.erase();
- y2milestone( "doRemove container %s name %s", name().c_str(),
- p->name().c_str() );
+ y2mil("doRemove container " << name() << " name " << p->name());
if( !dmp_slave )
{
- getStorage()->removeDmMapsTo( getPartName(p->OrigNr()) );
+ getStorage()->removeDmMapsTo( getPartDevice(p->OrigNr()) );
ret = v->prepareRemove();
}
if( ret==0 && !p->created() )
@@ -2584,8 +2048,8 @@
{
ret = DISK_REMOVE_PARTITION_PARTED_FAILED;
}
- ProcPart parts;
- if( parts.findDevice(getPartName(device(), p->OrigNr())) )
+ ProcParts parts;
+ if( parts.findDevice(getPartName(p->OrigNr())) )
callDelpart( p->OrigNr() );
getStorage()->handleHald(false);
}
@@ -2596,12 +2060,12 @@
}
if( ret==0 )
{
- PartPair p = partPair( notCreatedPrimary );
+ ConstPartPair p = partPair( notCreatedPrimary );
if( p.empty() )
redetectGeometry();
}
if( ret==0 && !dmp_slave )
- getStorage()->waitForDevice();
+ Storage::waitForDevice();
}
else
{
@@ -2622,11 +2086,13 @@
const unsigned long endBefore = p->cylStart() - 1;
const unsigned long startAfter = p->cylEnd() + 1;
unsigned long endAfter = cylinders();
+ Region usable_region = usableCylRegion();
if (p->type() == LOGICAL && hasExtended())
{
ConstPartPair pp = partPair(notDeletedExt);
startBefore = pp.begin()->cylStart() - 1;
endAfter = pp.begin()->cylEnd() + 1;
+ usable_region = pp.begin()->cylRegion();
}
y2mil("startBefore:" << startBefore << " endBefore:" << endBefore);
@@ -2687,12 +2153,12 @@
if (endAfter > startAfter)
freeCylsAfter = endAfter - startAfter;
- Region around(p->cylStart() - freeCylsBefore, p->cylEnd() + freeCylsAfter - 1);
- Region usable_region = usableCylRegion();
-
+ y2mil( "bef:" << freeCylsBefore << " aft:" << freeCylsAfter );
+ Region around(p->cylStart() - freeCylsBefore, p->cylSize() + freeCylsAfter + freeCylsBefore );
+ y2mil( "around:" << around );
if (usable_region.doIntersect(around))
{
- around = around.intersect(usableCylRegion());
+ around = around.intersect(usable_region);
freeCylsBefore = freeCylsAfter = 0;
if (around.start() < p->cylStart())
@@ -2709,6 +2175,7 @@
return ret;
}
+
int
Disk::resizePartition(Partition* p, unsigned long newCyl)
{
@@ -2726,7 +2193,7 @@
if( ret==0 && newCyl<p->cylSize() )
{
if( p->created() )
- p->changeRegion( p->cylStart(), newCyl, newSize );
+ p->changeRegion(Region(p->cylStart(), newCyl), newSize);
else
p->setResizedSize( newSize );
}
@@ -2746,7 +2213,7 @@
else
{
if( p->created() )
- p->changeRegion( p->cylStart(), newCyl, newSize );
+ p->changeRegion(Region(p->cylStart(), newCyl), newSize);
else
p->setResizedSize( newSize );
}
@@ -2791,7 +2258,7 @@
bool Disk::isLogical( unsigned nr ) const
{
bool ret = ext_possible && nr>max_primary;
- y2milestone( "nr:%u ret:%d", nr, ret );
+ y2mil("nr:" << nr << " ret:" << ret);
return( ret );
}
@@ -2819,17 +2286,15 @@
ret = p->resizeFs();
if( ret==0 )
{
- system_stderr.erase();
- y2milestone( "doResize container %s name %s", name().c_str(),
- p->name().c_str() );
+ y2mil("doResize container " << name() << " name " << p->name());
std::ostringstream cmd_line;
classic(cmd_line);
unsigned long long start_sect, end_sect;
getPartedSectors( p, start_sect, end_sect );
- end_sect = start_sect + p->sizeK()*2 - 1;
- y2milestone( "end_sect %llu", end_sect );
+ end_sect = start_sect + kbToSector(p->sizeK()) - 1;
+ y2mil("end_sect " << end_sect);
const Partition * after = getPartitionAfter( p );
- unsigned long max_end = sizeK()*2-1;
+ unsigned long max_end = kbToSector(sizeK()) - 1;
if( after!=NULL )
{
unsigned long long start_after, end_after;
@@ -2840,7 +2305,7 @@
}
else if( p->type()==LOGICAL )
{
- PartPair ext = partPair(notDeletedExt);
+ ConstPartPair ext = partPair(notDeletedExt);
if( !ext.empty() )
{
unsigned long long start_ext, end_ext;
@@ -2850,7 +2315,7 @@
}
y2mil( "max_end:" << max_end << " end_sect:" << end_sect );
if( max_endhandleHald(false);
if( ret==0 && !dmp_slave )
- getStorage()->waitForDevice( p->device() );
- y2milestone( "after resize size:%llu resize:%d", p->sizeK(),
- p->needShrink()||p->needExtend() );
+ Storage::waitForDevice(p->device());
+ y2mil("after resize size:" << p->sizeK() << " resize:" << (p->needShrink()||p->needExtend()));
}
if( needExtend && !dmp_slave &&
p->getFs()!=HFS && p->getFs()!=HFSPLUS && p->getFs()!=VFAT &&
@@ -2889,12 +2353,12 @@
return( ret );
}
-const Partition * Disk::getPartitionAfter( const Partition * p )
+const Partition* Disk::getPartitionAfter(const Partition* p) const
{
- const Partition * ret = NULL;
+ const Partition* ret = NULL;
y2mil( "p:" << *p );
- PartPair pp = partPair( (p->type()==LOGICAL)?notDeleted:notDeletedLog );
- for( PartIter pi=pp.begin(); pi!=pp.end(); ++pi )
+ ConstPartPair pp = partPair((p->type() == LOGICAL) ? Partition::notDeleted : notDeletedLog);
+ for (ConstPartIter pi = pp.begin(); pi != pp.end(); ++pi)
{
if( !pi->created() &&
pi->cylStart()>p->cylStart() &&
@@ -2902,21 +2366,21 @@
ret = &(*pi);
}
if( ret==NULL )
- y2milestone( "ret:NULL" );
+ y2mil( "ret:NULL" );
else
y2mil( "ret:" << *ret );
- return( ret );
+ return ret;
}
void Disk::addPartition( unsigned num, unsigned long long sz,
- ProcPart& ppart )
+ SystemInfo& systeminfo )
{
- y2mil( "dev:" << device() << " num:" << num << " sizek" << sz );
- unsigned long cyl_inc = std::max( sz*2 / head / sector, 1ULL );
- Partition *p = new Partition( *this, num, sz, cyl, cyl_inc, PRIMARY );
- cyl += cyl_inc;
- new_cyl = cyl;
- if( ppart.getSize( p->device(), sz ) && sz>0 )
+ unsigned long cyl_inc = std::max(kbToSector(size_k) / geometry.heads / geometry.sectors, 1ULL);
+ Partition *p = new Partition(*this, getPartName(num), getPartDevice(num), num, systeminfo, sz,
+ Region(geometry.cylinders, cyl_inc), PRIMARY);
+ geometry.cylinders += cyl_inc;
+ new_geometry.cylinders = geometry.cylinders;
+ if( systeminfo.getProcParts().getSize(p->procName(), sz) && sz>0 )
{
p->setSize( sz );
}
@@ -2925,7 +2389,7 @@
unsigned Disk::numPartitions() const
{
- return(partPair( notDeleted ).length());
+ return partPair(Partition::notDeleted).length();
}
void Disk::getInfo( DiskInfo& tinfo ) const
@@ -2934,34 +2398,28 @@
info.cyl = cylinders();
info.heads = heads();
info.sectors = sectors();
- info.sectorSize = logical_sector_size;
- info.cylSizeB = cylSizeB();
+ info.sectorSize = sectorSize();
+ info.cylSize = geometry.cylinderSize();
info.disklabel = labelName();
- info.maxLogical = maxLogical();
info.maxPrimary = maxPrimary();
+ info.extendedPossible = extendedPossible();
+ info.maxLogical = maxLogical();
info.initDisk = init_disk;
- info.iscsi = iscsi;
- info.udevPath = udev_path;
- info.udevId = mergeString( udev_id );
+ info.iscsi = transport == ISCSI;
+ info.transport = transport;
tinfo = info;
}
-namespace storage
-{
std::ostream& operator<< (std::ostream& s, const Disk& d )
{
- s << *((Container*)&d);
- s << " Cyl:" << d.cyl
- << " Head:" << d.head
- << " Sect:" << d.sector
- << " Node <" << d.mjr << ":" << d.mnr << ">"
+ s << dynamic_cast(d);
+ s << " geometry:" << d.geometry
<< " Range:" << d.range
- << " SizeM:" << d.size_k/1024
+ << " SizeK:" << d.size_k
<< " Label:" << d.label;
if( d.detected_label!=d.label )
s << " DetectedLabel:" << d.detected_label;
- s << " SysfsDir:" << d.sysfs_dir;
if( !d.udev_path.empty() )
s << " UdevPath:" << d.udev_path;
if( !d.udev_id.empty() )
@@ -2971,105 +2429,55 @@
s << " ExtPossible MaxLogical:" << d.max_logical;
if( d.init_disk )
s << " InitDisk";
- if( d.iscsi )
- s << " iSCSI";
+ s << " transport:" << toString(d.transport);
if( d.dmp_slave )
s << " DmpSlave";
if( d.no_addpart )
s << " NoAddpart";
if( d.gpt_enlarge )
s << " GptEnlarge";
+ if (d.del_ptable)
+ s << " delPT";
return( s );
}
-}
-void Disk::logDifference( const Container& d ) const
+ void
+ Disk::logDifference(std::ostream& log, const Disk& rhs) const
{
- string log = getDiffString( d );
- const Disk * p = dynamic_cast(&d);
- if( p != NULL )
- {
- if( cyl!=p->cyl )
- log += " Cyl:" + decString(cyl) + "-->" + decString(p->cyl);
- if( head!=p->head )
- log += " Head:" + decString(head) + "-->" + decString(p->head);
- if( sector!=p->sector )
- log += " Sect:" + decString(sector) + "-->" + decString(p->sector);
- if( mjr!=p->mjr )
- log += " Mjr:" + decString(mjr) + "-->" + decString(p->mjr);
- if( mnr!=p->mnr )
- log += " Mnr:" + decString(mnr) + "-->" + decString(p->mnr);
- if( range!=p->range )
- log += " Range:" + decString(range) + "-->" + decString(p->range);
- if( size_k!=p->size_k )
- log += " SizeK:" + decString(size_k) + "-->" + decString(p->size_k);
- if( label!=p->label )
- log += " Label:" + label + "-->" + p->label;
- if( sysfs_dir!=p->sysfs_dir )
- log += " SysfsDir:" + sysfs_dir + "-->" + p->sysfs_dir;
- if( max_primary!=p->max_primary )
- log += " MaxPrimary:" + decString(max_primary) + "-->" + decString(p->max_primary);
- if( ext_possible!=p->ext_possible )
- {
- if( p->ext_possible )
- log += " -->ExtPossible";
- else
- log += " ExtPossible-->";
- }
- if( max_logical!=p->max_logical )
- log += " MaxLogical:" + decString(max_logical) + "-->" + decString(p->max_logical);
- if( init_disk!=p->init_disk )
- {
- if( p->init_disk )
- log += " -->InitDisk";
- else
- log += " InitDisk-->";
- }
- if( iscsi!=p->iscsi )
- {
- if( p->iscsi )
- log += " -->iSCSI";
- else
- log += " iSCSI-->";
- }
- y2mil(log);
- ConstPartPair pp=partPair();
- ConstPartIter i=pp.begin();
- while( i!=pp.end() )
- {
- ConstPartPair pc=p->partPair();
- ConstPartIter j = pc.begin();
- while( j!=pc.end() &&
- (i->device()!=j->device() || i->created()!=j->created()) )
- ++j;
- if( j!=pc.end() )
- {
- if( !i->equalContent( *j ) )
- i->logDifference( *j );
- }
- else
- y2mil( " -->" << *i );
- ++i;
- }
- pp=p->partPair();
- i=pp.begin();
- while( i!=pp.end() )
- {
- ConstPartPair pc=partPair();
- ConstPartIter j = pc.begin();
- while( j!=pc.end() &&
- (i->device()!=j->device() || i->created()!=j->created()) )
- ++j;
- if( j==pc.end() )
- y2mil( " <--" << *i );
- ++i;
- }
- }
- else
- y2mil(log);
+ Container::logDifference(log, rhs);
+
+ logDiff(log, "geometry", geometry, rhs.geometry);
+ logDiff(log, "size_k", size_k, rhs.size_k);
+
+ logDiff(log, "label", label, rhs.label);
+ logDiff(log, "range", range, rhs.range);
+ logDiff(log, "max_primary", max_primary, rhs.max_primary);
+ logDiff(log, "ext_possible", ext_possible, rhs.ext_possible);
+ logDiff(log, "max_logical", max_logical, rhs.max_logical);
+
+ logDiff(log, "init_disk", init_disk, rhs.init_disk);
+
+ logDiffEnum(log, "transport", transport, rhs.transport);
+
+ logDiff(log, "del_ptable", del_ptable, rhs.del_ptable);
}
+
+ void
+ Disk::logDifferenceWithVolumes(std::ostream& log, const Container& rhs_c) const
+ {
+ const Disk& rhs = dynamic_cast(rhs_c);
+
+ logDifference(log, rhs);
+ log << endl;
+
+ ConstPartPair pp = partPair();
+ ConstPartPair pc = rhs.partPair();
+ logVolumesDifference(log, pp.begin(), pp.end(), pc.begin(), pc.end());
+ }
+
+
bool Disk::equalContent( const Container& rhs ) const
{
const Disk * p = NULL;
@@ -3077,68 +2485,21 @@
if( ret )
p = dynamic_cast(&rhs);
if( ret && p )
- ret = cyl==p->cyl && head==p->head && sector==p->sector &&
+ ret = geometry == p->geometry &&
mjr==p->mjr && mnr==p->mnr && range==p->range &&
size_k==p->size_k && max_primary==p->max_primary &&
ext_possible==p->ext_possible && max_logical==p->max_logical &&
init_disk==p->init_disk && label==p->label &&
- iscsi==p->iscsi && sysfs_dir==p->sysfs_dir &&
- no_addpart==p->no_addpart &&
- dmp_slave==p->dmp_slave && gpt_enlarge==p->gpt_enlarge;
+ transport == p->transport &&
+ dmp_slave==p->dmp_slave && no_addpart==p->no_addpart &&
+ gpt_enlarge==p->gpt_enlarge && del_ptable == p->del_ptable;
if( ret && p )
{
ConstPartPair pp = partPair();
ConstPartPair pc = p->partPair();
- ConstPartIter i = pp.begin();
- ConstPartIter j = pc.begin();
- while( ret && i!=pp.end() && j!=pc.end() )
- {
- ret = ret && i->equalContent( *j );
- ++i;
- ++j;
- }
- ret = ret && i==pp.end() && j==pc.end();
+ ret = ret && storage::equalContent(pp.begin(), pp.end(), pc.begin(), pc.end());
}
return( ret );
}
-Disk& Disk::operator= ( const Disk& rhs )
- {
- y2deb("operator= from " << rhs.nm);
- cyl = rhs.cyl;
- head = rhs.head;
- sector = rhs.sector;
- new_cyl = rhs.new_cyl;
- new_head = rhs.new_head;
- new_sector = rhs.new_sector;
- label = rhs.label;
- detected_label = rhs.detected_label;
- range = rhs.range;
- byte_cyl = rhs.byte_cyl;
- max_primary = rhs.max_primary;
- ext_possible = rhs.ext_possible;
- max_logical = rhs.max_logical;
- init_disk = rhs.init_disk;
- iscsi = rhs.iscsi;
- udev_path = rhs.udev_path;
- udev_id = rhs.udev_id;
- logfile_name = rhs.logfile_name;
- sysfs_dir = rhs.sysfs_dir;
- dmp_slave = rhs.dmp_slave;
- no_addpart = rhs.no_addpart;
- gpt_enlarge = rhs.gpt_enlarge;
- return( *this );
- }
-
-Disk::Disk( const Disk& rhs ) : Container(rhs)
- {
- y2deb("constructed disk by copy constructor from " << rhs.nm);
- *this = rhs;
- ConstPartPair p = rhs.partPair();
- for( ConstPartIter i = p.begin(); i!=p.end(); ++i )
- {
- Partition * p = new Partition( *this, *i );
- vols.push_back( p );
- }
- }
-
+}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Disk.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Disk.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Disk.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Disk.h Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -25,17 +25,24 @@
#include <list>
-#include "y2storage/Container.h"
-#include "y2storage/Partition.h"
+#include "storage/Container.h"
+#include "storage/Partition.h"
+#include "storage/Geometry.h"
+
namespace storage
{
+ using std::list;
+
class Storage;
class SystemCmd;
-class ProcPart;
+ class SystemInfo;
+ class ArchInfo;
+class ProcParts;
class Region;
+
class Disk : public Container
{
friend class Storage;
@@ -52,35 +59,45 @@
};
public:
- Disk( Storage * const s, const string& Name, unsigned long long Size );
- Disk( Storage * const s, const string& Name, unsigned num,
- unsigned long long Size, ProcPart& ppart );
- Disk( const Disk& rhs );
+
+ Disk(Storage* s, const string& name, const string& device, unsigned long long Size,
+ SystemInfo& systeminfo);
+ Disk(Storage* s, const string& name, const string& device, unsigned num,
+ unsigned long long Size, SystemInfo& systeminfo);
+ Disk(Storage* s, const xmlNode* node);
+ Disk(const Disk& c);
virtual ~Disk();
- unsigned long cylinders() const { return cyl; }
- unsigned heads() const { return head; }
- unsigned sectors() const { return sector; }
+ void saveData(xmlNode* node) const;
+
+ unsigned long cylinders() const { return geometry.cylinders; }
+ unsigned heads() const { return geometry.heads; }
+ unsigned sectors() const { return geometry.sectors; }
+ unsigned sectorSize() const { return geometry.sector_size; }
+ const Geometry& getGeometry() const { return geometry; }
Region usableCylRegion() const;
unsigned long numMinor() const { return range; }
- unsigned long cylSizeB() const { return byte_cyl; }
unsigned maxPrimary() const { return max_primary; }
bool extendedPossible() const { return ext_possible; }
unsigned maxLogical() const { return max_logical; }
const string& labelName() const { return label; }
- const string& udevPath() const { return udev_path; }
- const std::list<string>& udevId() const { return udev_id; }
+ virtual string udevPath() const { return udev_path; }
+ virtual list<string> udevId() const { return udev_id; }
void setSlave( bool val=true ) { dmp_slave=val; }
void setAddpart( bool val=true ) { no_addpart=!val; }
void setNumMinor( unsigned long val ) { range=val; }
- const string& sysfsDir() const { return sysfs_dir; }
+
+ virtual string procName() const { return nm; }
+ virtual string sysfsPath() const;
+
unsigned numPartitions() const;
bool isDasd() const { return( nm.find("dasd")==0 ); }
- bool isIScsi() const { return iscsi; }
+ bool isIScsi() const { return transport == ISCSI; }
+ static bool isIScsi(const Disk& d) { return d.isIScsi(); }
bool isLogical( unsigned nr ) const;
- bool detect( ProcPart& ppart );
+ bool detect(SystemInfo& systeminfo);
static storage::CType staticType() { return storage::DISK; }
friend std::ostream& operator<< (std::ostream&, const Disk& );
void triggerUdevUpdate() const;
@@ -100,16 +117,14 @@
bool initializeDisk() const { return init_disk; }
void resetInitDisk() { init_disk=false; }
int forgetChangePartitionId( unsigned nr );
- int changePartitionArea( unsigned nr, unsigned long start,
- unsigned long size, bool checkRelaxed=false );
+ int changePartitionArea(unsigned nr, const Region& cylRegion, bool checkRelaxed = false);
int nextFreePartition(storage::PartitionType type, unsigned& nr,
string& device) const;
int destroyPartitionTable( const string& new_label );
unsigned availablePartNumber(storage::PartitionType type = storage::PRIMARY) const;
- virtual void getCommitActions( std::liststorage::commitAction*& l ) const;
- virtual int getToCommit( storage::CommitStage stage,
- std::list& col,
- std::list& vol );
+ virtual void getCommitActions(list<commitAction>& l) const;
+ virtual void getToCommit(storage::CommitStage stage, list& col,
+ list& vol) const;
virtual int commitChanges( storage::CommitStage stage );
int commitChanges( storage::CommitStage stage, Volume* vol );
int freeCylindersAroundPartition(const Partition* p, unsigned long& freeCylsBefore,
@@ -122,34 +137,39 @@
unsigned int numPrimary() const;
bool hasExtended() const;
unsigned int numLogical() const;
- string setDiskLabelText( bool doing=true ) const;
+ Text setDiskLabelText(bool doing) const;
- unsigned long long cylinderToKb( unsigned long ) const;
- unsigned long kbToCylinder( unsigned long long ) const;
+ unsigned long long cylinderToKb(unsigned long cylinder) const
+ { return geometry.cylinderToKb(cylinder); }
+ unsigned long kbToCylinder(unsigned long long kb) const
+ { return geometry.kbToCylinder(kb); }
+
+ unsigned long long sectorToKb(unsigned long long sector) const
+ { return geometry.sectorToKb(sector); }
+ unsigned long long kbToSector(unsigned long long kb) const
+ { return geometry.kbToSector(kb); }
- unsigned long long sectorToKb(unsigned long long sector) const;
- unsigned long long kbToSector(unsigned long long kb) const;
+ string getPartName(unsigned nr) const;
+ string getPartDevice(unsigned nr) const;
- string getPartName( unsigned nr ) const;
void getInfo( storage::DiskInfo& info ) const;
bool equalContent( const Container& rhs ) const;
- void logDifference( const Container& d ) const;
- Disk& operator= ( const Disk& rhs );
+
+ void logDifference(std::ostream& log, const Disk& rhs) const;
+ virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
+
bool FakeDisk() const { return(range==1); }
- static string getPartName( const string& disk, unsigned nr );
- static string getPartName( const string& disk, const string& nr );
static std::pair getDiskPartition( const string& dev );
+
static bool getDlabelCapabilities(const string& dlabel,
storage::DlabelCapabilities& dlabelcapabilities);
struct SysfsInfo
{
- unsigned long mjr;
- unsigned long mnr;
- string device;
unsigned long range;
unsigned long long size;
+ bool vbd;
};
static bool getSysfsInfo(const string& sysfsdir, SysfsInfo& sysfsinfo);
@@ -206,47 +226,41 @@
}
protected:
- Disk( Storage * const s, const string& File );
+
virtual bool detectGeometry();
- virtual bool detectPartitions( ProcPart& ppart );
- bool getSysfsInfo( const string& SysFsDir );
- int checkSystemError( const string& cmd_line, const SystemCmd& cmd );
+ virtual bool detectPartitions(SystemInfo& systeminfo);
+ bool getSysfsInfo();
+ int checkSystemError( const string& cmd_line, const SystemCmd& cmd ) const;
int execCheckFailed( const string& cmd_line, bool stop_hald=true );
int execCheckFailed( SystemCmd& cmd, const string& cmd_line,
- bool stop_hald=true );
- bool checkPartedOutput( const SystemCmd& cmd, ProcPart& ppart );
- bool scanPartedLine( const string& Line, unsigned& nr,
- unsigned long& start, unsigned long& csize,
- storage::PartitionType& type,
- unsigned& id, bool& boot );
- bool scanPartedSectors( const string& Line, unsigned& nr,
- unsigned long long& start,
- unsigned long long& ssize ) const;
- bool checkPartedValid( const ProcPart& pp, const string& diskname,
- std::list& pl, unsigned long& rng );
- int callDelpart( unsigned nr ) const;
- int callAddpart( unsigned nr, unsigned long long sstart,
- unsigned long long ssize ) const;
- bool getPartedValues( Partition *p );
+ bool stop_hald=true );
+ bool checkPartedOutput(SystemInfo& systeminfo);
+ list<string> partitionsKernelKnowns(const ProcParts& parts) const;
+ bool checkPartedValid(SystemInfo& systeminfo, list& pl,
+ unsigned long& rng) const;
+ virtual bool checkPartitionsValid(SystemInfo& systeminfo, const list& pl) const;
+
+ bool callDelpart(unsigned nr) const;
+ bool callAddpart(unsigned nr, const Region& blkRegion) const;
+
+ bool getPartedValues( Partition *p ) const;
bool getPartedSectors( const Partition *p, unsigned long long& start,
- unsigned long long& end );
- const Partition * getPartitionAfter( const Partition * p );
+ unsigned long long& end ) const;
+ const Partition * getPartitionAfter( const Partition * p ) const;
void addPartition( unsigned num, unsigned long long sz,
- ProcPart& ppart );
+ SystemInfo& ppart );
virtual void print( std::ostream& s ) const { s << *this; }
virtual Container* getCopy() const { return( new Disk( *this ) ); }
- void getGeometry( const string& line, unsigned long& c,
- unsigned& h, unsigned& s );
virtual void redetectGeometry();
void changeNumbers( const PartIter& b, const PartIter& e,
unsigned start, int incr );
- int createChecks( storage::PartitionType& type, unsigned long start,
- unsigned long len, bool checkRelaxed );
+ int createChecks(PartitionType& type, const Region& cylRegion, bool checkRelaxed) const;
void removePresentPartitions();
void removeFromMemory();
void enlargeGpt();
- static bool notDeleted( const Partition&d ) { return( !d.deleted() ); }
+ /* size of extended partition in proc and sysfs in 512 byte blocks */
+ unsigned long long procExtendedBlks() const;
virtual int doCreate( Volume* v );
virtual int doRemove( Volume* v );
@@ -254,40 +268,40 @@
virtual int doSetType( Volume* v );
virtual int doCreateLabel();
- void logData( const string& Dir );
+ virtual void logData(const string& Dir) const;
+
void setLabelData( const string& );
- static string defaultLabel(bool efiboot, unsigned long long num_sectors);
+ string defaultLabel() const;
static const label_info labels[];
static const string p_disks[];
- unsigned int logical_sector_size;
+ Geometry geometry;
+ Geometry new_geometry;
- unsigned long cyl;
- unsigned head;
- unsigned sector;
- unsigned long new_cyl;
- unsigned new_head;
- unsigned new_sector;
string label;
string udev_path;
- std::list<string> udev_id;
+ list<string> udev_id;
string detected_label;
- string system_stderr;
string logfile_name;
- string sysfs_dir;
unsigned max_primary;
bool ext_possible;
unsigned max_logical;
bool init_disk;
- bool iscsi;
+ Transport transport;
bool dmp_slave;
bool no_addpart;
bool gpt_enlarge;
- unsigned long byte_cyl;
unsigned long range;
- mutable storage::DiskInfo info;
+ bool del_ptable;
+
+ mutable storage::DiskInfo info; // workaround for broken ycp bindings
+
+ private:
+
+ Disk& operator=(const Disk&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dm.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dm.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dm.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dm.cc Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -19,72 +19,117 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
#include <sstream>
-#include "y2storage/Dm.h"
-#include "y2storage/PeContainer.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Regex.h"
-#include "y2storage/Storage.h"
-#include "y2storage/StorageDefines.h"
-
-using namespace storage;
-using namespace std;
-
-Dm::Dm( const PeContainer& d, const string& tn ) :
- Volume( d ), tname(tn)
- {
- num_le = 0;
- stripe = 1;
- stripe_size = 0;
- inactiv = true;
- y2deb("constructed dm dev");
- }
-
-Dm::Dm( const PeContainer& d, const string& tn, unsigned mnum ) :
- Volume( d ), tname(tn)
- {
- y2milestone( "constructed dm dev table \"%s\" %u", tn.c_str(), mnum );
- num_le = 0;
- stripe = 1;
- stripe_size = 0;
- inactiv = true;
- nm = tn;
- init();
+#include "storage/Dm.h"
+#include "storage/PeContainer.h"
+#include "storage/SystemCmd.h"
+#include "storage/AppUtil.h"
+#include "storage/Regex.h"
+#include "storage/Storage.h"
+#include "storage/StorageDefines.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ // this ctr is used for volumes of LvmVg and DmPart
+ Dm::Dm(const PeContainer& c, const string& name, const string& device, const string& tname)
+ : Volume(c, name, device), tname(tname), num_le(0), stripe(1), stripe_size(0),
+ inactiv(true)
+ {
+ y2mil("constructed Dm tname:" << tname);
+ }
+
+
+ // this ctr is used for volumes of DmCo
+ Dm::Dm(const PeContainer& c, const string& name, const string& device, const string& tname,
+ SystemInfo& systeminfo)
+ : Volume(c, name, device, systeminfo), tname(tname), num_le(0), stripe(1), stripe_size(0),
+ inactiv(true)
+ {
+ y2mil("constructed Dm dev:" << dev << " tname:" << tname);
+
+ string dmn = "/dev/mapper/" + tname;
+ if (dmn != dev)
+ alt_names.push_back(dmn);
+
+ updateMajorMinor();
+
getTableInfo();
+
+ getStorage()->fetchDanglingUsedBy(dev, uby);
+ for (list<string>::const_iterator it = alt_names.begin(); it != alt_names.end(); ++it)
+ getStorage()->fetchDanglingUsedBy(*it, uby);
}
-Dm::~Dm()
-{
- y2deb("destructed dm dev " << dev);
-}
+ Dm::Dm(const PeContainer& c, const xmlNode* node)
+ : Volume(c, node), tname(), num_le(0), stripe(1), stripe_size(0), inactiv(true)
+ {
+ getChildValue(node, "table_name", tname);
+
+ getChildValue(node, "stripes", stripe);
+ getChildValue(node, "stripe_size_k", stripe_size);
+
+ y2deb("constructed Dm " << dev);
+
+ assert(!tname.empty());
+ assert(stripe == 1 || stripe_size > 0);
+ }
+
+
+ Dm::Dm(const PeContainer& c, const Dm& v)
+ : Volume(c, v), tname(v.tname), num_le(v.num_le), stripe(v.stripe),
+ stripe_size(v.stripe_size), inactiv(v.inactiv), pe_map(v.pe_map)
+ {
+ y2deb("copy-constructed Dm " << dev);
+ }
+
+
+ Dm::~Dm()
+ {
+ y2deb("destructed Dm dev " << dev);
+ }
+
+
+ void
+ Dm::saveData(xmlNode* node) const
+ {
+ Volume::saveData(node);
+
+ setChildValue(node, "table_name", tname);
+
+ setChildValue(node, "stripes", stripe);
+ if (stripe > 1)
+ setChildValue(node, "stripe_size_k", stripe_size);
+ }
unsigned Dm::dmMajor()
{
if( dm_major==0 )
- getDmMajor();
+ {
+ dm_major = getMajorDevices("device-mapper");
+ y2mil("dm_major:" << dm_major);
+ }
return( dm_major );
}
+
void
Dm::getTableInfo()
{
- if( dm_major==0 )
- getDmMajor();
SystemCmd c(DMSETUPBIN " table " + quote(tname));
inactiv = c.retcode()!=0;
- y2milestone( "table %s retcode:%d numLines:%u inactive:%d",
- tname.c_str(), c.retcode(), c.numLines(), inactiv );
+ y2mil("table:" << tname << " retcode:" << c.retcode() << " numLines:" << c.numLines() <<
+ " inactive:" << inactiv);
if( c.numLines()>0 )
{
- string line = *c.getLine(0);
+ string line = c.getLine(0);
target = extractNthWord( 2, line );
if( target=="striped" )
extractNthWord( 3, line ) >> stripe;
@@ -98,7 +143,7 @@
unsigned long le;
string dev;
string majmin;
- string line = *c.getLine(i);
+ string line = c.getLine(i);
if( target=="linear" )
{
extractNthWord( 1, line ) >> le;
@@ -106,7 +151,7 @@
le += pesize-1;
le /= pesize;
majmin = extractNthWord( 3, line );
- dev = getDevice( majmin );
+ dev = pec()->getDeviceByNumber( majmin );
if( !dev.empty() )
{
if( (mit=pe_map.find( dev ))==pe_map.end() )
@@ -115,8 +160,7 @@
mit->second += le;
}
else
- y2warning( "could not find major/minor pair %s",
- majmin.c_str());
+ y2war("could not find major/minor pair " << majmin);
}
else if (target == "snapshot-origin")
{
@@ -137,14 +181,14 @@
stripe_size /= 2;
extractNthWord( 3, line ) >> str;
if( str<2 )
- y2warning( "invalid stripe count %u", str );
+ y2war("invalid stripe count " << str);
else
{
le = (le+str-1)/str;
for( unsigned j=0; jgetDeviceByNumber( majmin );
if( !dev.empty() )
{
if( (mit=pe_map.find( dev ))==pe_map.end() )
@@ -153,8 +197,7 @@
mit->second += le;
}
else
- y2warning( "could not find major/minor pair %s",
- majmin.c_str());
+ y2war("could not find major/minor pair " << majmin);
}
}
}
@@ -162,7 +205,7 @@
{
if( find( known_types.begin(), known_types.end(), target ) ==
known_types.end() )
- y2warning( "unknown target type \"%s\"", target.c_str() );
+ y2war("unknown target type \"" << target << "\"");
extractNthWord( 1, line ) >> le;
y2mil( "le:" << le );
le /= 2;
@@ -182,7 +225,7 @@
if( devspec.match( *i ))
{
y2mil( "match \"" << *i << "\"" );
- dev = getDevice( *i );
+ dev = pec()->getDeviceByNumber( *i );
if( !dev.empty() )
{
if( (mit=pe_map.find( dev ))==pe_map.end() )
@@ -191,8 +234,7 @@
mit->second += le;
}
else
- y2warning( "could not find major/minor pair %s",
- majmin.c_str());
+ y2war("could not find major/minor pair " << majmin);
}
}
}
@@ -201,58 +243,7 @@
bool Dm::removeTable()
{
- return( getContainer()->getStorage()->removeDmTable( tname ));
- }
-
-string Dm::getDevice( const string& majmin )
- {
- string ret = cont->getStorage()->deviceByNumber( majmin );
- if( ret.empty() )
- {
- unsigned mj = 0;
- unsigned mi = 0;
- string pair( majmin );
- SystemCmd c;
- do
- {
- mj = mi = 0;
- string::size_type pos = pair.find( ':' );
- if( pos != string::npos )
- pair[pos] = ' ';
- istringstream i( pair );
- classic(i);
- i >> mj >> mi;
- list<string> ls = splitString(pair);
- if( cont->majorNr()>0 && mj==cont->majorNr() && mi==cont->minorNr())
- ret = cont->device();
- if( mj==Loop::major() )
- ret = Loop::loopDeviceName(mi);
- if( ret.empty() && mj==dmMajor() && ls.size()>=2 )
- {
- c.execute(DMSETUPBIN " info -c --noheadings -j " + *ls.begin() +
- " -m " + *(++ls.begin()) + " | sed -e \"s/:.*//\"" );
- if( c.retcode()==0 && c.numLines()>0 )
- {
- string tmp = "/dev/"+*c.getLine(0);
- if( cont->getStorage()->knownDevice( tmp, true ) )
- {
- ret = tmp;
- }
- else
- {
- c.execute(DMSETUPBIN " table " + quote(*c.getLine(0)));
- if( c.retcode()==0 && c.numLines()>0 )
- {
- pair = extractNthWord( 3, *c.getLine(0) );
- ret = cont->getStorage()->deviceByNumber( pair );
- }
- }
- }
- }
- }
- while( ret.empty() && mj==dm_major && c.retcode()==0 );
- }
- return( ret );
+ return getStorage()->removeDmTable(tname);
}
unsigned long long
@@ -287,8 +278,8 @@
ret = mit != pe_map.end();
if( ret )
{
- y2mil( "map:" << pe_map );
- y2milestone( "table:%s dev:%s ret:%d", tname.c_str(), dev.c_str(), ret );
+ y2mil("map:" << pe_map);
+ y2mil("table:" << tname << " dev:" << dev << " ret:" << ret);
}
return( ret );
}
@@ -302,7 +293,7 @@
mit!=pe_map.end(); ++mit )
sum += mit->second;
if( sum != num_le )
- y2warning( "lv:%s sum:%lu num:%llu", dev.c_str(), sum, num_le );
+ y2war("lv:" << dev << " sum:" << sum << " num:" << num_le);
else
ret = true;
return( ret );
@@ -317,20 +308,16 @@
void Dm::init()
{
string dmn = "/dev/mapper/" + tname;
- if( dev.empty() )
- {
- dev = dmn;
- nm = tname;
- }
- else if( dmn != dev )
+ if( dmn != dev )
alt_names.push_back( dmn );
//alt_names.push_back( "/dev/"+tname );
- updateMajorMinor();
+ if (!getStorage()->testmode())
+ updateMajorMinor();
}
void Dm::updateMajorMinor()
{
- getMajorMinor( dev, mjr, mnr );
+ getMajorMinor();
if( majorNr()==Dm::dmMajor() )
{
string d = "/dev/dm-" + decString(minorNr());
@@ -387,9 +374,9 @@
}
}
-string Dm::removeText( bool doing ) const
+Text Dm::removeText( bool doing ) const
{
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by device name e.g. /dev/mapper/system
@@ -405,9 +392,9 @@
return( txt );
}
-string Dm::formatText( bool doing ) const
+Text Dm::formatText( bool doing ) const
{
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by device name e.g. /dev/mapper/system
@@ -456,7 +443,10 @@
void Dm::activate( bool val )
{
- y2milestone( "old active:%d val:%d", active, val );
+ if (getenv("LIBSTORAGE_NO_DM") != NULL)
+ return;
+
+ y2mil("old active:" << active << " val:" << val);
if( active!=val )
{
SystemCmd c;
@@ -465,18 +455,24 @@
c.execute(DMSETUPBIN " version");
if( c.retcode()!=0 )
{
- c.execute("grep \"^dm[-_]mod[ \t]\" /proc/modules");
- if( c.numLines()<=0 )
c.execute(MODPROBEBIN " dm-mod");
- c.execute("grep \"^dm[-_]snapshot[ \t]\" /proc/modules");
- if( c.numLines()<=0 )
c.execute(MODPROBEBIN " dm-snapshot");
- c.execute("/sbin/devmap_mknod.sh");
+ c.execute(DMSETUPBIN " version");
}
}
else
{
- c.execute(DMSETUPBIN " remove_all");
+ c.execute(DMSETUPBIN " info -c -o name,subsystem");
+ SystemCmd rm;
+ for( unsigned i=0; i %s", dev.c_str(), ret.c_str() );
+ y2mil("dev:" << dev << " ret:" << ret);
return( ret );
}
-string Dm::dmName( const string& table )
- {
- string ret = "";
- int num = Dm::dmNumber( table );
- if( num>=0 )
- ret = "dm-" + decString(num);
- y2mil( "table:" << table << " ret:" << ret );
- return( ret );
- }
string Dm::dmDeviceName( unsigned long num )
{
return( "/dev/dm-" + decString(num));
}
-int Dm::dmNumber( const string& table )
- {
- int ret = -1;
- SystemCmd c(DMSETUPBIN " -c --noheadings info " + quote(table));
- if( c.retcode()==0 && c.numLines()>0 )
- {
- list<string> sl = splitString( *c.getLine(0), ":" );
- if( sl.size()>=3 )
- {
- list<string>::const_iterator ci = sl.begin();
- ++ci;
- ++ci;
- *ci >> ret;
- }
- }
- y2mil( "table:" << table << " ret:" << ret );
- return( ret );
- }
-string Dm::sysfsPath() const
+ string
+ Dm::sysfsPath() const
{
- string ret = SYSFSDIR "/";
- list<string>::const_iterator i =
- find_if( alt_names.begin(), alt_names.end(), find_begin( "/dev/dm-" ) );
- if( i != alt_names.end() )
- {
- string::size_type pos = i->rfind( '/' ) + 1;
- ret += i->substr( pos );
- }
- else
- {
- y2mil( "no dm device found " << *this );
- }
- y2mil( "ret:" << ret );
- return( ret );
+ return SYSFSDIR "/" + procName();
}
-void Dm::getDmMajor()
- {
- dm_major = getMajorDevices( "device-mapper" );
- y2milestone( "dm_major:%u", dm_major );
- }
void Dm::getInfo( DmInfo& tinfo ) const
{
- ((Volume*)this)->getInfo( info.v );
+ Volume::getInfo(info.v);
info.nr = num;
info.table = tname;
info.target = target;
tinfo = info;
}
-namespace storage
-{
std::ostream& operator<< (std::ostream& s, const Dm &p )
{
s << p.shortPrintedName() << " ";
- s << *(Volume*)&p;
+ s << dynamic_cast(p);
if( p.num_le>0 )
s << " LE:" << p.num_le;
s << " Table:" << p.tname;
@@ -591,7 +534,6 @@
return( s );
}
-}
bool Dm::equalContent( const Dm& rhs ) const
{
@@ -600,53 +542,24 @@
stripe_size==rhs.stripe_size && pe_map==rhs.pe_map );
}
-void Dm::logDifference( const Dm& rhs ) const
-{
- string log = stringDifference(rhs);
- y2mil(log);
-}
-string Dm::stringDifference( const Dm& rhs ) const
+ void
+ Dm::logDifference(std::ostream& log, const Dm& rhs) const
{
- string ret = Volume::logDifference( rhs );
- if( num_le!=rhs.num_le )
- ret += " LE:" + decString(num_le) + "-->" + decString(rhs.num_le);
- if( stripe!=rhs.stripe )
- ret += " Stripes:" + decString(stripe) + "-->" + decString(rhs.stripe);
- if( stripe_size!=rhs.stripe_size )
- ret += " StripeSize:" + decString(stripe_size) + "-->" +
- decString(rhs.stripe_size);
- if( pe_map!=rhs.pe_map )
- {
- std::ostringstream b;
- classic(b);
- b << " pe_map:" << pe_map << "-->" << rhs.pe_map;
- ret += b.str();
- }
- return( ret );
- }
+ Volume::logDifference(log, rhs);
-Dm& Dm::operator= ( const Dm& rhs )
- {
- y2deb("operator= from " << rhs.nm);
- *((Volume*)this) = rhs;
- num_le = rhs.num_le;
- stripe = rhs.stripe;
- stripe_size = rhs.stripe_size;
- inactiv = rhs.inactiv;
- tname = rhs.tname;
- pe_map = rhs.pe_map;
- return( *this );
- }
+ logDiff(log, "num_le", num_le, rhs.num_le);
+ logDiff(log, "stripes", stripe, rhs.stripe);
+ logDiff(log, "stripe_size", stripe_size, rhs.stripe_size);
-Dm::Dm( const PeContainer& d, const Dm& rhs ) : Volume(d)
- {
- y2deb("constructed dm by copy constructor from " << rhs.dev);
- *this = rhs;
+ logDiff(log, "pe_map", pe_map, rhs.pe_map);
}
+
bool Dm::active = false;
unsigned Dm::dm_major = 0;
-static const char* elem[] = { "crypt" };
-list<string> Dm::known_types( elem, elem+lengthof(elem) );
+ static const char* elem[] = { "crypt" };
+ const list<string> Dm::known_types(elem, elem + lengthof(elem));
+
+}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dm.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dm.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dm.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dm.h Tue May 17 13:39:44 2011
@@ -25,7 +25,7 @@
#include <map>
-#include "y2storage/Volume.h"
+#include "storage/Volume.h"
namespace storage
{
@@ -35,12 +35,16 @@
class Dm : public Volume
{
public:
- Dm( const PeContainer& d, const string& tn );
- Dm( const PeContainer& d, const string& tn, unsigned mnum );
- Dm( const PeContainer& d, const Dm& rhs );
- Dm& operator=( const Dm& );
+ Dm(const PeContainer& c, const string& name, const string& device, const string& tname);
+ Dm(const PeContainer& c, const string& name, const string& device, const string& tname,
+ SystemInfo& systeminfo);
+ Dm(const PeContainer& c, const xmlNode* node);
+ Dm(const PeContainer& c, const Dm& v);
virtual ~Dm();
+
+ void saveData(xmlNode* node) const;
+
const string& getTableName() const { return( tname ); }
const string& getTargetName() const { return( target ); }
void setTableName( const string& name ) { tname=name; }
@@ -60,28 +64,31 @@
unsigned setStripes( unsigned long val ) { return stripe=val; }
unsigned long long stripeSize() const { return stripe_size; }
void setStripeSize( unsigned long long val ) { stripe_size=val; }
- string sysfsPath() const;
+
+ virtual string procName() const { return "dm-" + decString(mnr); }
+ virtual string sysfsPath() const;
+
void updateMajorMinor();
- virtual const std::list<string> udevId() const { return Volume::udevId(); }
friend std::ostream& operator<< (std::ostream& s, const Dm &p );
virtual void print( std::ostream& s ) const { s << *this; }
- virtual string removeText( bool doing ) const;
- virtual string formatText( bool doing ) const;
+ virtual Text removeText( bool doing ) const;
+ virtual Text formatText( bool doing ) const;
void getInfo( storage::DmInfo& info ) const;
void changeDeviceName( const string& old, const string& nw );
static bool notDeleted( const Dm& l ) { return( !l.deleted() ); }
+ static bool isDeleted(const Dm& l) { return l.deleted(); }
- static void activate( bool val=true );
+ static void activate(bool val);
static bool isActive() { return active; }
static string devToTable( const string& dev );
- static string dmName( const string& table );
- static int dmNumber( const string& table );
- bool equalContent( const Dm& rhs ) const;
- void logDifference( const Dm& d ) const;
- string stringDifference( const Dm& d ) const;
+
+ bool equalContent(const Dm& rhs) const;
+
+ void logDifference(std::ostream& log, const Dm& rhs) const;
+
static unsigned dmMajor();
static string dmDeviceName( unsigned long num );
@@ -89,8 +96,6 @@
void init();
const PeContainer* pec() const;
virtual const string shortPrintedName() const { return( "Dm" ); }
- string getDevice( const string& majmin );
- static void getDmMajor();
string tname;
string target;
@@ -101,8 +106,16 @@
std::map pe_map;
static bool active;
static unsigned dm_major;
- static std::list<string> known_types;
- mutable storage::DmInfo info;
+
+ static const list<string> known_types;
+
+ mutable storage::DmInfo info; // workaround for broken ycp bindings
+
+ private:
+
+ Dm(const Dm&); // disallow
+ Dm& operator=(const Dm&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmCo.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmCo.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmCo.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmCo.cc Tue May 17 13:39:44 2011
@@ -19,55 +19,107 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
-#include <iostream>
+#include <ostream>
#include <sstream>
-#include "y2storage/DmCo.h"
-#include "y2storage/Dm.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/ProcPart.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Storage.h"
-#include "y2storage/StorageDefines.h"
-
-using namespace std;
-using namespace storage;
-
- DmCo::DmCo(Storage * const s, bool detect, ProcPart& ppart, bool only_crypt)
- : PeContainer(s, staticType())
- {
- y2deb("constructing DmCo detect:" << detect);
- init();
- if (detect)
- getDmData(ppart, only_crypt);
+#include "storage/DmCo.h"
+#include "storage/Dm.h"
+#include "storage/SystemCmd.h"
+#include "storage/SystemInfo.h"
+#include "storage/ProcParts.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
+#include "storage/StorageDefines.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ CmdDmsetup::CmdDmsetup()
+ {
+ SystemCmd c(DMSETUPBIN " --columns --noheadings -o name,major,minor,segments,uuid info");
+ if (c.retcode() != 0 || c.numLines() == 0)
+ return;
+
+ for (vector<string>::const_iterator it = c.stdout().begin(); it != c.stdout().end(); ++it)
+ {
+ list<string> sl = splitString(*it, ":");
+ if (sl.size() >= 4)
+ {
+ Entry entry;
+
+ list<string>::const_iterator ci = sl.begin();
+ string name = *ci++;
+ *ci++ >> entry.mjr;
+ *ci++ >> entry.mnr;
+ *ci++ >> entry.segments;
+ entry.uuid = *ci++;
+
+ data[name] = entry;
+ }
+ }
+
+ for (const_iterator it = data.begin(); it != data.end(); ++it)
+ y2mil("data[" << it->first << "] -> mjr:" << it->second.mjr << " mnr:" <<
+ it->second.mnr << " segments:" << it->second.segments << " uuid:" <<
+ it->second.uuid);
}
- void
- DmCo::second(bool detect, ProcPart& ppart, bool only_crypt)
+ bool
+ CmdDmsetup::getEntry(const string& name, Entry& entry) const
{
- y2deb("second DmCo detect:" << detect);
- if (detect)
- getDmData(ppart, only_crypt);
+ const_iterator it = data.find(name);
+ if (it == data.end())
+ return false;
+
+ entry = it->second;
+ return true;
+ }
+
+
+ list<string>
+ CmdDmsetup::getEntries() const
+ {
+ list<string> ret;
+ for (const_iterator i = data.begin(); i != data.end(); ++i)
+ ret.push_back(i->first);
+ return ret;
}
-DmCo::DmCo( Storage * const s, const string& file ) :
- PeContainer(s,staticType())
+ DmCo::DmCo(Storage* s)
+ : PeContainer(s, "mapper", "/dev/mapper", staticType())
{
- y2deb("constructing DmCo file:" << file);
- init();
+ y2deb("constructing DmCo");
}
-DmCo::~DmCo()
+
+ DmCo::DmCo(Storage* s, SystemInfo& systeminfo, bool only_crypt)
+ : PeContainer(s, "mapper", "/dev/mapper", staticType(), systeminfo)
+ {
+ y2deb("constructing DmCo");
+ getDmData(systeminfo, only_crypt);
+ }
+
+
+ void
+ DmCo::second(SystemInfo& systeminfo, bool only_crypt)
+ {
+ y2deb("second DmCo");
+ getDmData(systeminfo, only_crypt);
+ }
+
+
+ DmCo::~DmCo()
{
y2deb("destructed DmCo");
}
+
void DmCo::updateDmMaps()
{
DmPair dp = dmPair();
@@ -92,13 +144,6 @@
while( success );
}
-void
-DmCo::init()
- {
- nm = "dm";
- dev = "/dev/mapper";
- }
-
// dev should be something like /dev/mapper/cr_test
storage::EncryptType
@@ -114,7 +159,7 @@
string cipher, keysize;
for( unsigned int i = 0; i < c.numLines(); i++)
{
- string line = *c.getLine(i);
+ string line = c.getLine(i);
string key = extractNthWord( 0, line );
if( key == "cipher:" )
cipher = extractNthWord( 1, line );
@@ -132,32 +177,34 @@
ret = ENC_TWOFISH256_OLD;
}
- y2mil("ret:" << ret);
+ y2mil("ret:" << toString(ret));
return ret;
}
void
-DmCo::getDmData(ProcPart& ppart, bool only_crypt)
+ DmCo::getDmData(SystemInfo& systeminfo, bool only_crypt)
{
Storage::ConstLvmLvPair lv = getStorage()->lvmLvPair();
Storage::ConstDmraidCoPair dmrco = getStorage()->dmraidCoPair();
Storage::ConstDmraidPair dmr = getStorage()->dmrPair();
Storage::ConstDmmultipathCoPair dmmco = getStorage()->dmmultipathCoPair();
Storage::ConstDmmultipathPair dmm = getStorage()->dmmPair();
- y2mil("begin");
- SystemCmd c(DMSETUPBIN " ls | grep \"(.*)\"" );
- for( unsigned i=0; ifirst;
bool found=false;
- Storage::ConstLvmLvIterator i=lv.begin();
- while( !found && i!=lv.end() )
+ if (!found)
+ {
+ Storage::ConstLvmLvIterator i=lv.begin();
+ while( !found && i!=lv.end() )
{
- found = i->getTableName()==table;
- ++i;
+ found = i->getTableName()==table;
+ ++i;
}
+ }
if( !found )
{
Storage::ConstDmraidCoIterator i=dmrco.begin();
@@ -196,18 +243,13 @@
}
if( !found )
{
- string minor = extractNthWord( 2, line );
- unsigned min_num;
- string::size_type pos;
- if( (pos=minor.find( ")" ))!=string::npos )
- minor.erase( pos );
- minor >> min_num;
- y2mil( "minor:\"" << minor << "\" minor:" << min_num );
- Dm * m = new Dm( *this, table, min_num );
- y2mil( "new Dm:" << *m );
+ const CmdDmsetup::Entry& entry = it1->second;
+
+ Dm* m = new Dm(*this, table, "/dev/mapper/" + table, table, systeminfo);
+ y2mil("new Dm:" << *m);
unsigned long long s = 0;
- string dev = "/dev/dm-" + decString(min_num);
- if( ppart.getSize( dev, s ))
+ string dev = "/dev/dm-" + decString(entry.mnr);
+ if (systeminfo.getProcParts().getSize(dev, s))
{
y2mil( "new dm size:" << s );
m->setSize( s );
@@ -222,7 +264,7 @@
if( !getStorage()->canUseDevice( it->first, true ))
in_use = true;
if( !in_use || multipath )
- getStorage()->setUsedBy( it->first, UB_DM, table );
+ getStorage()->setUsedBy(it->first, UB_DM, "/dev/mapper/" + table);
}
string tmp = m->device();
tmp.erase( 5, 7 );
@@ -234,13 +276,12 @@
getStorage()->knownDevice( it->first ))
{
skip = true;
- getStorage()->setDmcryptData( it->first, m->device(), min_num,
+ getStorage()->setDmcryptData( it->first, m->device(), entry.mnr,
m->sizeK(), detectEncryption (m->device()) );
- if (getStorage()->usedBy(it->first) == UB_DM)
+ if (getStorage()->isUsedBy(it->first, UB_DM))
getStorage()->clearUsedBy(it->first);
}
- if (!skip && m->sizeK() > 0 && ((only_crypt && m->getTargetName() == "crypt") ||
- (!only_crypt && m->getTargetName() != "crypt")))
+ if (!skip && m->sizeK()>0 && !only_crypt )
addDm( m );
else
delete( m );
@@ -309,7 +350,7 @@
if( !findDm( tname, i ))
ret = DM_UNKNOWN_TABLE;
}
- if( ret==0 && i->getUsedByType() != UB_NONE )
+ if (ret == 0 && i->isUsedBy())
{
ret = DM_REMOVE_USED_BY;
}
@@ -328,7 +369,7 @@
{
getStorage()->clearUsedBy(it->first);
}
- i->setDeleted( true );
+ i->setDeleted();
}
}
y2mil("ret:" << ret);
@@ -367,7 +408,7 @@
if( c.retcode()!=0 )
ret = DM_REMOVE_FAILED;
else
- getStorage()->waitForDevice();
+ Storage::waitForDevice();
y2mil( "this:" << *this );
getStorage()->logProcData( cmd );
}
@@ -383,57 +424,28 @@
return( ret );
}
-namespace storage
-{
-inline std::ostream& operator<< (std::ostream& s, const DmCo& d )
+ std::ostream& operator<<(std::ostream& s, const DmCo& d)
{
- s << *((Container*)&d);
+ s << dynamic_cast(d);
return( s );
}
-}
-void DmCo::logDifference( const Container& d ) const
+ void
+ DmCo::logDifferenceWithVolumes(std::ostream& log, const Container& rhs_c) const
{
- y2mil(getDiffString(d));
- const DmCo * p = dynamic_cast(&d);
- if( p != NULL )
- {
- ConstDmPair pp=dmPair();
- ConstDmIter i=pp.begin();
- while( i!=pp.end() )
- {
- ConstDmPair pc=p->dmPair();
- ConstDmIter j = pc.begin();
- while( j!=pc.end() &&
- (i->device()!=j->device() || i->created()!=j->created()) )
- ++j;
- if( j!=pc.end() )
- {
- if( !i->equalContent( *j ) )
- i->logDifference( *j );
- }
- else
- y2mil( " -->" << *i );
- ++i;
- }
- pp=p->dmPair();
- i=pp.begin();
- while( i!=pp.end() )
- {
- ConstDmPair pc=dmPair();
- ConstDmIter j = pc.begin();
- while( j!=pc.end() &&
- (i->device()!=j->device() || i->created()!=j->created()) )
- ++j;
- if( j==pc.end() )
- y2mil( " <--" << *i );
- ++i;
- }
- }
+ const DmCo& rhs = dynamic_cast(rhs_c);
+
+ logDifference(log, rhs);
+ log << endl;
+
+ ConstDmPair pp = dmPair();
+ ConstDmPair pc = rhs.dmPair();
+ logVolumesDifference(log, pp.begin(), pp.end(), pc.begin(), pc.end());
}
+
bool DmCo::equalContent( const Container& rhs ) const
{
const DmCo * p = NULL;
@@ -444,15 +456,7 @@
{
ConstDmPair pp = dmPair();
ConstDmPair pc = p->dmPair();
- ConstDmIter i = pp.begin();
- ConstDmIter j = pc.begin();
- while( ret && i!=pp.end() && j!=pc.end() )
- {
- ret = ret && i->equalContent( *j );
- ++i;
- ++j;
- }
- ret = ret && i==pp.end() && j==pc.end();
+ ret = ret && storage::equalContent(pp.begin(), pp.end(), pc.begin(), pc.end());
}
return( ret );
}
@@ -468,5 +472,4 @@
}
}
-
-void DmCo::logData( const string& Dir ) {;}
+}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmCo.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmCo.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmCo.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmCo.h Tue May 17 13:39:44 2011
@@ -23,48 +23,93 @@
#ifndef DM_CO_H
#define DM_CO_H
-#include "y2storage/PeContainer.h"
-#include "y2storage/Dm.h"
+#include "storage/PeContainer.h"
+#include "storage/Dm.h"
namespace storage
{
-class ProcPart;
+ class SystemInfo;
+
+
+ class CmdDmsetup
+ {
+
+ public:
+
+ CmdDmsetup();
+
+ struct Entry
+ {
+ Entry() : name(), mjr(0), mnr(0), segments(0), uuid() {}
+
+ string name;
+ unsigned long mjr;
+ unsigned long mnr;
+ unsigned segments;
+ string uuid;
+ };
+
+ bool getEntry(const string& name, Entry& entry) const;
+
+ list<string> getEntries() const;
+
+ template<class Pred>
+ list<string> getMatchingEntries(Pred pred) const
+ {
+ list<string> ret;
+ for (const_iterator i = data.begin(); i != data.end(); ++i)
+ if (pred(i->first))
+ ret.push_back(i->first);
+ return ret;
+ }
+
+ typedef map::const_iterator const_iterator;
+
+ const_iterator begin() const { return data.begin(); }
+ const_iterator end() const { return data.end(); }
+
+ private:
+
+ map data;
+
+ };
+
class DmCo : public PeContainer
{
friend class Storage;
public:
- DmCo(Storage * const s, bool detect, ProcPart& ppart, bool only_crypt);
- DmCo( const DmCo& rhs );
-
- void second(bool detect, ProcPart& ppart, bool only_crypt);
+ DmCo(Storage * const s);
+ DmCo(Storage * const s, SystemInfo& systeminfo, bool only_crypt);
+ DmCo(const DmCo& c);
virtual ~DmCo();
+ void second(SystemInfo& systeminfo, bool only_crypt);
+
static storage::CType staticType() { return storage::DM; }
friend std::ostream& operator<< (std::ostream&, const DmCo& );
bool equalContent( const Container& rhs ) const;
- void logDifference( const Container& d ) const;
+
+ virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
+
void updateDmMaps();
int removeDm( const string& table );
int removeVolume( Volume* v );
protected:
- DmCo( Storage * const s, const string& File );
- void getDmData(ProcPart& ppart, bool only_crypt);
+ void getDmData(SystemInfo& systeminfo, bool only_crypt);
bool findDm( unsigned num, DmIter& i );
bool findDm( unsigned num );
bool findDm( const string& dev, DmIter& i );
bool findDm( const string& dev );
void addDm( Dm* m );
void checkDm( Dm* m );
- void updateEntry( const Dm* m );
- virtual Container* getCopy() const { return( new DmCo( *this ) ); }
- void init();
+ virtual Container* getCopy() const { return( new DmCo( *this ) ); }
storage::EncryptType detectEncryption( const string& device ) const;
@@ -72,7 +117,10 @@
int doRemove( Volume* v );
- void logData( const string& Dir );
+ private:
+
+ DmCo& operator=(const DmCo&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPart.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPart.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPart.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPart.cc Tue May 17 13:39:44 2011
@@ -19,57 +19,50 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
#include <sstream>
-#include "y2storage/DmPart.h"
-#include "y2storage/DmPartCo.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/ProcPart.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Storage.h"
+#include "storage/DmPart.h"
+#include "storage/DmPartCo.h"
+#include "storage/SystemCmd.h"
+#include "storage/ProcParts.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
-using namespace storage;
-using namespace std;
-
-DmPart::DmPart(const DmPartCo& d, unsigned nr, Partition* pa)
- : Dm(d, "")
+namespace storage
{
- init( d.numToName(nr) );
+ using namespace std;
+
+
+ DmPart::DmPart(const DmPartCo& c, const string& name, const string& device, unsigned nr,
+ Partition* pa)
+ : Dm(c, name, device, name), p(pa)
+ {
+ Dm::init();
+
numeric = true;
num = nr;
getTableInfo();
- p = pa;
if( pa )
setSize( pa->sizeK() );
- y2mil("constructed DmPart " << dev << " on co " << cont->name());
+ y2mil("constructed DmPart " << dev << " on " << cont->device());
}
-DmPart::~DmPart()
-{
- y2deb("destructed DmPart " << dev);
-}
+ DmPart::DmPart(const DmPartCo& c, const DmPart& v)
+ : Dm(c, v)
+ {
+ y2deb("copy-constructed DmPart from " << v.dev);
+ }
-void DmPart::init( const string& name )
+ DmPart::~DmPart()
{
- p = NULL;
- nm = name;
- dev = "/dev/mapper/" + name;
- string::size_type pos = name.find_last_of( "/" );
- if( pos!=string::npos )
- nm = name.substr( pos+1 );
- else
- nm = name;
- tname = nm;
- Dm::init();
+ y2deb("destructed DmPart " << dev);
}
+
const DmPartCo* DmPart::co() const
{
return(dynamic_cast(cont));
@@ -80,21 +73,18 @@
if( p && p->nr() != num )
{
num = p->nr();
- nm = co()->numToName(num);
- dev = "/dev/mapper/" + nm;
+ setNameDevice(co()->getPartName(num), co()->getPartDevice(num));
}
}
void DmPart::updateMinor()
{
- unsigned long mj=mjr;
- unsigned long mi=mnr;
- getMajorMinor( dev, mj, mi );
- if( mi!=mnr || mj!=mjr )
+ unsigned long old_mjr = mjr;
+ unsigned long old_mnr = mnr;
+ getMajorMinor();
+ if (mjr != old_mjr || mnr != old_mnr)
{
- mnr = mi;
- mjr = mj;
- replaceAltName( "/dev/dm-", "/dev/dm-"+decString(mnr) );
+ replaceAltName("/dev/dm-", "/dev/dm-" + decString(mnr));
getTableInfo();
}
}
@@ -108,75 +98,64 @@
}
}
-void DmPart::updateSize( ProcPart& pp )
+
+ void
+ DmPart::updateSize(const ProcParts& parts)
{
unsigned long long si = 0;
updateSize();
- if( mjr>0 && pp.getSize( "dm-"+decString(mnr), si ))
+ if (mjr > 0 && parts.getSize("/dev/dm-" + decString(mnr), si))
setSize( si );
}
+
void DmPart::addUdevData()
{
addAltUdevId( num );
}
-static string udevCompleteIdPath( const string& s, unsigned nr )
+
+ void
+ DmPart::addAltUdevId(unsigned num)
{
- return( "/dev/disk/by-id/" + s + "-part" + decString(nr) );
- }
+ alt_names.remove_if(string_contains("/by-id/"));
+ const list<string> tmp = co()->udevId();
+ for (list<string>::const_iterator i = tmp.begin(); i != tmp.end(); ++i)
+ alt_names.push_back("/dev/disk/by-id/" + udevAppendPart(*i, num));
-void
-DmPart::addAltUdevId( unsigned num )
-{
- list<string>::iterator i = alt_names.begin();
- while( i!=alt_names.end() )
- {
- if( i->find( "/by-id/" ) != string::npos )
- i = alt_names.erase( i );
- else
- ++i;
- }
- list<string>::const_iterator j = co()->udevId().begin();
- while( j!=co()->udevId().end() )
- {
- alt_names.push_back( udevCompleteIdPath( *j, num ));
- ++j;
- }
- mount_by = orig_mount_by = defaultMountBy();
-}
+ mount_by = orig_mount_by = defaultMountBy();
+ }
-const std::list<string>
-DmPart::udevId() const
-{
- list<string> ret;
- for (list<string>::const_iterator i = alt_names.begin();
- i != alt_names.end(); i++)
+ list<string>
+ DmPart::udevId() const
{
- if (i->find("/by-id/") != string::npos)
- ret.push_back(*i);
+ list<string> ret;
+ const list<string> tmp = co()->udevId();
+ for (list<string>::const_iterator i = tmp.begin(); i != tmp.end(); ++i)
+ ret.push_back(udevAppendPart(*i, num));
+ return ret;
}
- return ret;
-}
-void DmPart::getCommitActions( std::liststorage::commitAction*& l ) const
+void
+DmPart::getCommitActions(list<commitAction>& l) const
{
unsigned s = l.size();
Dm::getCommitActions(l);
if( p )
{
if( s==l.size() && Partition::toChangeId( *p ) )
- l.push_back( new commitAction( INCREASE, cont->staticType(),
- setTypeText(false), this, false ));
+ l.push_back(commitAction(INCREASE, cont->type(),
+ setTypeText(false), this, false));
}
}
-string DmPart::setTypeText( bool doing ) const
+
+Text DmPart::setTypeText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev;
if( doing )
{
@@ -197,7 +176,7 @@
void DmPart::getInfo( DmPartInfo& tinfo ) const
{
- ((Volume*)this)->getInfo( info.v );
+ Volume::getInfo(info.v);
if( p )
p->getInfo( info.p );
info.part = p!=NULL;
@@ -206,40 +185,24 @@
tinfo = info;
}
-namespace storage
-{
std::ostream& operator<< (std::ostream& s, const DmPart &p )
{
- s << *(Dm*)&p;
+ s << dynamic_cast(p);
return( s );
}
-}
bool DmPart::equalContent( const DmPart& rhs ) const
{
return( Dm::equalContent(rhs) );
}
-void DmPart::logDifference( const DmPart& rhs ) const
-{
- string log = stringDifference(rhs);
- y2mil(log);
-}
-
-
-DmPart& DmPart::operator=(const DmPart& rhs)
-{
- y2deb("operator= from " << rhs.nm);
- *((Dm*)this) = rhs;
- return *this;
-}
+ void
+ DmPart::logDifference(std::ostream& log, const DmPart& rhs) const
+ {
+ Dm::logDifference(log, rhs);
+ }
-DmPart::DmPart(const DmPartCo& d, const DmPart& rhs)
- : Dm(d, rhs)
-{
- y2deb("constructed dmraid by copy constructor from " << rhs.dev);
- *this = rhs;
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPart.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPart.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPart.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPart.h Tue May 17 13:39:44 2011
@@ -23,50 +23,59 @@
#ifndef DM_PART_H
#define DM_PART_H
-#include "y2storage/Dm.h"
-#include "y2storage/Partition.h"
+#include "storage/Dm.h"
+#include "storage/Partition.h"
namespace storage
{
class DmPartCo;
-class ProcPart;
+ class ProcParts;
+
class DmPart : public Dm
{
public:
- DmPart( const DmPartCo& d, unsigned nr, Partition* p=NULL );
- DmPart( const DmPartCo& d, const DmPart& rd );
- DmPart& operator=( const DmPart& );
+ DmPart(const DmPartCo& c, const string& name, const string& device, unsigned nr,
+ Partition* p);
+ DmPart(const DmPartCo& c, const DmPart& v);
virtual ~DmPart();
+
friend std::ostream& operator<< (std::ostream& s, const DmPart &p );
virtual void print( std::ostream& s ) const { s << *this; }
void getInfo( storage::DmPartInfo& info ) const;
bool equalContent( const DmPart& rhs ) const;
- void logDifference( const DmPart& d ) const;
+
+ void logDifference(std::ostream& log, const DmPart& rhs) const;
+
void setPtr( Partition* pa ) { p=pa; };
Partition* getPtr() const { return p; };
unsigned id() const { return p?p->id():0; }
void updateName();
void updateMinor();
- void updateSize( ProcPart& pp );
+ void updateSize(const ProcParts& parts);
void updateSize();
- void getCommitActions( std::liststorage::commitAction*& l ) const;
+ void getCommitActions(list<commitAction>& l) const;
void addUdevData();
- virtual const std::list<string> udevId() const;
- virtual string setTypeText( bool doing=true ) const;
+ virtual list<string> udevId() const;
+ virtual Text setTypeText(bool doing) const;
static bool notDeleted( const DmPart& l ) { return( !l.deleted() ); }
protected:
- void init( const string& name );
- void dataFromPart( const Partition* p );
+
virtual const string shortPrintedName() const { return( "DmPart" ); }
const DmPartCo* co() const;
void addAltUdevId( unsigned num );
Partition* p;
- mutable storage::DmPartInfo info;
+ mutable storage::DmPartInfo info; // workaround for broken ycp bindings
+
+ private:
+
+ DmPart(const DmPart&); // disallow
+ DmPart& operator=(const DmPart&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPartCo.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPartCo.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPartCo.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPartCo.cc Tue May 17 13:39:44 2011
@@ -19,38 +19,36 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
-#include <iostream>
+#include <ostream>
#include <sstream>
-#include "y2storage/DmPartCo.h"
-#include "y2storage/DmPart.h"
-#include "y2storage/ProcPart.h"
-#include "y2storage/Partition.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Storage.h"
-#include "y2storage/StorageDefines.h"
-
-using namespace std;
-using namespace storage;
-
-DmPartCo::DmPartCo( Storage * const s, const string& name, storage::CType t,
- ProcPart& ppart ) :
- PeContainer(s,t)
- {
- y2deb("constructing DmPart co " << name);
- dev = name;
- nm = undevName(name);
- num_part = num_pe = free_pe = 0;
- active = del_ptable = false;
- disk = NULL;
- init( ppart );
+#include "storage/DmPartCo.h"
+#include "storage/DmPart.h"
+#include "storage/ProcParts.h"
+#include "storage/Partition.h"
+#include "storage/SystemCmd.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
+#include "storage/StorageDefines.h"
+#include "storage/SystemInfo.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ DmPartCo::DmPartCo(Storage* s, const string& name, const string& device, CType t,
+ SystemInfo& systeminfo)
+ : PeContainer(s, name, device, t, systeminfo), disk(NULL), active(false)
+ {
+ y2deb("constructing DmPartCo name:" << name);
+ getMajorMinor();
+ init(systeminfo);
}
+
DmPartCo::~DmPartCo()
{
if( disk )
@@ -58,7 +56,14 @@
delete disk;
disk = NULL;
}
- y2deb("destructed DmPart co " << dev);
+ y2deb("destructed DmPartCo " << dev);
+ }
+
+
+ string
+ DmPartCo::sysfsPath() const
+ {
+ return SYSFSDIR "/" + procName();
}
@@ -75,7 +80,7 @@
unsigned number;
device.substr(pos + 5) >> number;
y2mil("num:" << number);
- device = "/dev/mapper/" + numToName(number);
+ device = getPartDevice(number);
Partition *p = getPartition( number, false );
if( p==NULL )
ret = DMPART_PARTITION_NOT_FOUND;
@@ -86,6 +91,7 @@
newP( dm, p->nr(), p );
dm->getFsInfo( p );
dm->setCreated();
+ dm->addUdevData();
addToList( dm );
}
handleWholeDevice();
@@ -99,8 +105,8 @@
DmPartCo::createPartition( storage::PartitionType type, long unsigned start,
long unsigned len, string& device, bool checkRelaxed )
{
- y2milestone( "begin type %d at %ld len %ld relaxed:%d", type, start, len,
- checkRelaxed );
+ y2mil("begin type:" << toString(type) << " start:" << start << " len:" << len <<
+ " relaxed:" << checkRelaxed);
int ret = disk ? 0 : DMPART_INTERNAL_ERR;
if( ret==0 && readonly() )
ret = DMPART_CHANGE_READONLY;
@@ -115,7 +121,7 @@
int
DmPartCo::createPartition( long unsigned len, string& device, bool checkRelaxed )
{
- y2milestone( "len %ld relaxed:%d", len, checkRelaxed );
+ y2mil("len:" << len << " relaxed:" << checkRelaxed);
int ret = disk ? 0 : DMPART_INTERNAL_ERR;
if( ret==0 && readonly() )
ret = DMPART_CHANGE_READONLY;
@@ -130,7 +136,7 @@
int
DmPartCo::createPartition( storage::PartitionType type, string& device )
{
- y2milestone( "type %u", type );
+ y2mil("type:" << toString(type));
int ret = disk ? 0 : DMPART_INTERNAL_ERR;
if( ret==0 && readonly() )
ret = DMPART_CHANGE_READONLY;
@@ -277,73 +283,70 @@
return( ret );
}
+
void
-DmPartCo::init( ProcPart& ppart )
+ DmPartCo::init(SystemInfo& systeminfo)
{
- SystemCmd c(DMSETUPBIN " table " + quote(nm));
- if( c.retcode()==0 && c.numLines()>=1 && isdigit( c.stdout()[0] ))
+ CmdDmsetup::Entry entry;
+ if (systeminfo.getCmdDmsetup().getEntry(nm, entry) && entry.segments > 0)
{
- mnr = Dm::dmNumber( nm );
- ppart.getSize( "dm-"+decString(mnr), size_k );
- y2mil( "mnr:" << mnr << " nm:" << nm );
+ systeminfo.getProcParts().getSize("/dev/dm-" + decString(entry.mnr), size_k);
+ y2mil("minor:" << entry.mnr << " nm:" << nm);
y2mil( "pe_size:" << pe_size << " size_k:" << size_k );
if( size_k>0 )
pe_size = size_k;
else
- y2war( "size_k zero for dm minor " << mnr );
+ y2war("size_k zero for dm minor " << entry.mnr);
num_pe = 1;
- createDisk( ppart );
+ createDisk(systeminfo);
if( disk->numPartitions()>0 )
{
- string pat = numToName(1);
+ string pat = getPartName(1);
pat.erase( pat.length()-1, 1 );
- c.execute(DMSETUPBIN " ls | grep -w ^" + pat + "[0-9]\\\\+" );
- if( c.numLines()==0 )
+ string reg = "^" + pat + "[0-9]+" "$";
+ list<string> tmp = systeminfo.getCmdDmsetup().getMatchingEntries(regex_matches(reg));
+ if (tmp.empty())
activate_part(true);
}
- getVolumes( ppart );
+ getVolumes(systeminfo.getProcParts());
active = true;
}
- else
- {
- y2err("error dm " << nm << " table not found");
- }
}
+
void
-DmPartCo::createDisk( ProcPart& ppart )
+ DmPartCo::createDisk(SystemInfo& systeminfo)
{
if( disk )
delete disk;
- disk = new Disk( getStorage(), dev, size_k );
+ disk = new Disk(getStorage(), nm, dev, size_k, systeminfo);
disk->setNumMinor( 64 );
disk->setSilent();
disk->setSlave();
disk->setAddpart(false);
- disk->detect(ppart);
+ disk->detect(systeminfo);
}
+
void
DmPartCo::newP( DmPart*& dm, unsigned num, Partition* p )
{
y2mil( "num:" << num );
- dm = new DmPart( *this, num, p );
+ dm = new DmPart( *this, getPartName(num), getPartDevice(num), num, p );
}
+
void
-DmPartCo::getVolumes( ProcPart& ppart )
+ DmPartCo::getVolumes(const ProcParts& parts)
{
- vols.clear();
- num_part = 0;
+ clearPointerList(vols);
Disk::PartPair pp = disk->partPair();
Disk::PartIter i = pp.begin();
DmPart * p = NULL;
while( i!=pp.end() )
{
newP( p, i->nr(), &(*i) );
- p->updateSize( ppart );
- i->setSize(p->sizeK());
- num_part++;
+ p->updateSize(parts);
addToList( p );
++i;
}
@@ -353,7 +356,7 @@
void DmPartCo::handleWholeDevice()
{
Disk::PartPair pp = disk->partPair( Partition::notDeleted );
- y2milestone( "empty:%d", pp.empty() );
+ y2mil("empty:" << pp.empty());
if( pp.empty() )
{
DmPart * p = NULL;
@@ -419,15 +422,13 @@
void DmPartCo::updateMinor()
{
DmPartPair p=dmpartPair();
- DmPartIter i=p.begin();
- while( i!=p.end() )
- {
+ for (DmPartIter i = p.begin(); i != p.end(); ++i)
i->updateMinor();
- ++i;
- }
}
-string DmPartCo::numToName( unsigned num ) const
+
+ string
+ DmPartCo::getPartName(unsigned num) const
{
string ret = nm;
if( num>0 )
@@ -439,6 +440,21 @@
return( ret );
}
+
+ string
+ DmPartCo::getPartDevice(unsigned num) const
+ {
+ string ret = dev;
+ if( num>0 )
+ {
+ ret += "_part";
+ ret += decString(num);
+ }
+ y2mil( "num:" << num << " ret:" << ret );
+ return( ret );
+ }
+
+
string DmPartCo::undevName( const string& name )
{
string ret = name;
@@ -451,7 +467,7 @@
int DmPartCo::destroyPartitionTable( const string& new_label )
{
- y2milestone( "begin" );
+ y2mil("begin");
int ret = disk->destroyPartitionTable( new_label );
if( ret==0 )
{
@@ -468,7 +484,7 @@
}
bool save = getStorage()->getRecursiveRemoval();
getStorage()->setRecursiveRemoval(true);
- if( getUsedByType() != UB_NONE )
+ if (isUsedBy())
{
getStorage()->removeUsing( device(), getUsedBy() );
}
@@ -481,7 +497,6 @@
++i;
}
getStorage()->setRecursiveRemoval(save);
- del_ptable = true;
}
y2mil("ret:" << ret);
return( ret );
@@ -513,23 +528,29 @@
int
DmPartCo::nextFreePartition(PartitionType type, unsigned& nr, string& device) const
{
- int ret = disk->nextFreePartition( type, nr, device );
- if( ret==0 )
+ int ret = 0;
+ device = "";
+ nr = disk->availablePartNumber( type );
+ if (nr == 0)
{
- device = "/dev/mapper/" + numToName(nr);
+ ret = DISK_PARTITION_NO_FREE_NUMBER;
+ }
+ else
+ {
+ device = getPartDevice(nr);
}
y2mil("ret:" << ret << " nr:" << nr << " device:" << device);
return ret;
}
-int DmPartCo::changePartitionArea( unsigned nr, unsigned long start,
- unsigned long len, bool checkRelaxed )
+ int
+ DmPartCo::changePartitionArea(unsigned nr, const Region& cylRegion, bool checkRelaxed)
{
int ret = nr>0?0:DMPART_PARTITION_NOT_FOUND;
if( ret==0 )
{
- ret = disk->changePartitionArea( nr, start, len, checkRelaxed );
+ ret = disk->changePartitionArea(nr, cylRegion, checkRelaxed);
DmPartIter i;
if( findDm( nr, i ))
i->updateSize();
@@ -549,27 +570,12 @@
void DmPartCo::activate_part( bool val )
{
- y2milestone( "old active:%d val:%d", active, val );
- if( active != val )
- {
- SystemCmd c;
- if( val )
- {
- Dm::activate(true);
- c.execute(KPARTXBIN " -a -p _part " + quote(dev));
- }
- else
- {
- c.execute(KPARTXBIN " -d -p _part " + quote(dev));
- }
active = val;
- }
}
int DmPartCo::doSetType( DmPart* dm )
{
- y2milestone( "doSetType container %s name %s", name().c_str(),
- dm->name().c_str() );
+ y2mil("doSetType container " << name() << " name " << dm->name());
Partition * p = dm->getPtr();
int ret = p?0:DMPART_PARTITION_NOT_FOUND;
if( ret==0 )
@@ -586,7 +592,7 @@
int DmPartCo::doCreateLabel()
{
- y2milestone( "label:%s", labelName().c_str() );
+ y2mil("label:" << labelName());
int ret = 0;
if( !silent )
{
@@ -597,10 +603,9 @@
ret = disk->doCreateLabel();
if( ret==0 )
{
- del_ptable = false;
removeFromMemory();
handleWholeDevice();
- getStorage()->waitForDevice();
+ Storage::waitForDevice();
}
y2mil("ret:" << ret);
return( ret );
@@ -610,7 +615,7 @@
DmPartCo::removeDmPart()
{
int ret = 0;
- y2milestone( "begin" );
+ y2mil("begin");
if( readonly() )
{
ret = DMPART_CHANGE_READONLY;
@@ -629,7 +634,7 @@
if( !removeFromList( &(*p.begin()) ))
y2err( "not found:" << *p.begin() );
}
- setDeleted( true );
+ setDeleted();
}
if( ret==0 )
{
@@ -669,6 +674,7 @@
y2mil( "rem:" << *i );
if( !(*i)->created() )
{
+ delete *i;
i = vols.erase( i );
}
else
@@ -682,33 +688,32 @@
return( p!=NULL && !d.deleted() && Partition::toChangeId(*p) );
}
-int DmPartCo::getToCommit( CommitStage stage, list& col,
- list& vol )
- {
- int ret = 0;
- y2milestone( "ret:%d col:%zd vol:%zd", ret, col.size(), vol.size());
+
+void
+DmPartCo::getToCommit(CommitStage stage, list& col, list& vol) const
+{
+ y2mil("col:" << col.size() << " vol:" << vol.size());
getStorage()->logCo( this );
unsigned long oco = col.size();
unsigned long ovo = vol.size();
Container::getToCommit( stage, col, vol );
if( stage==INCREASE )
{
- DmPartPair p = dmpartPair( toChangeId );
- for( DmPartIter i=p.begin(); i!=p.end(); ++i )
+ ConstDmPartPair p = dmpartPair( toChangeId );
+ for( ConstDmPartIter i=p.begin(); i!=p.end(); ++i )
if( find( vol.begin(), vol.end(), &(*i) )==vol.end() )
vol.push_back( &(*i) );
}
- if( del_ptable && find( col.begin(), col.end(), this )==col.end() )
+ if( disk->del_ptable && find( col.begin(), col.end(), this )==col.end() )
col.push_back( this );
if( col.size()!=oco || vol.size()!=ovo )
- y2milestone( "ret:%d col:%zd vol:%zd", ret, col.size(), vol.size());
- return( ret );
- }
+ y2mil("stage:" << stage << " col:" << col.size() << " vol:" << vol.size());
+}
int DmPartCo::commitChanges( CommitStage stage, Volume* vol )
{
- y2milestone( "name %s stage %d", name().c_str(), stage );
+ y2mil("name:" << name() << " stage:" << stage);
int ret = Container::commitChanges( stage, vol );
if( ret==0 && stage==INCREASE )
{
@@ -728,13 +733,13 @@
int DmPartCo::commitChanges( CommitStage stage )
{
- y2milestone( "name %s stage %d", name().c_str(), stage );
+ y2mil("name:" << name() << " stage:" << stage);
int ret = 0;
if( stage==DECREASE && deleted() )
{
ret = doRemove();
}
- else if( stage==DECREASE && del_ptable )
+ else if( stage==DECREASE && disk->del_ptable )
{
ret = doCreateLabel();
}
@@ -744,36 +749,27 @@
return( ret );
}
-void DmPartCo::getCommitActions( list& l ) const
+
+void
+DmPartCo::getCommitActions(list<commitAction>& l) const
{
y2mil( "l:" << l );
Container::getCommitActions( l );
y2mil( "l:" << l );
- if( deleted() || del_ptable )
+ if( deleted() || disk->del_ptable )
{
- list::iterator i = l.begin();
- while( i!=l.end() )
- {
- if( (*i)->stage==DECREASE )
- {
- delete( *i );
- i=l.erase( i );
- }
- else
- ++i;
- }
- string txt = deleted() ? removeText(false) :
- setDiskLabelText(false);
- l.push_front( new commitAction( DECREASE, staticType(),
- txt, this, true ));
+ l.remove_if(stage_is(DECREASE));
+ Text txt = deleted() ? removeText(false) : setDiskLabelText(false);
+ l.push_front(commitAction(DECREASE, staticType(), txt, this, true));
}
y2mil( "l:" << l );
}
+
int
DmPartCo::doCreate( Volume* v )
{
- y2milestone( "Raid:%s part:%s", name().c_str(), v->name().c_str() );
+ y2mil("DmPart:" << name() << " name:" << v->name());
DmPart * l = dynamic_cast(v);
int ret = disk ? 0 : DMPART_INTERNAL_ERR;
if( ret==0 && l == NULL )
@@ -800,12 +796,12 @@
{
activate_part(false);
activate_part(true);
- ProcPart pp;
+ ProcParts parts;
updateMinor();
- l->updateSize( pp );
+ l->updateSize(parts);
}
if( p->type()!=EXTENDED )
- getStorage()->waitForDevice( l->device() );
+ Storage::waitForDevice(l->device());
}
y2mil("ret:" << ret);
return( ret );
@@ -818,7 +814,7 @@
int DmPartCo::doRemove( Volume* v )
{
- y2milestone( "Raid:%s name:%s", name().c_str(), v->name().c_str() );
+ y2mil("DmPart:" << name() << " name:" << v->name());
DmPart * l = dynamic_cast(v);
bool save_act = false;
int ret = disk ? 0 : DMPART_INTERNAL_ERR;
@@ -854,14 +850,14 @@
updateMinor();
}
if( ret==0 )
- getStorage()->waitForDevice();
+ Storage::waitForDevice();
y2mil("ret:" << ret);
return( ret );
}
int DmPartCo::doResize( Volume* v )
{
- y2milestone( "DmPart:%s name:%s", name().c_str(), v->name().c_str() );
+ y2mil("DmPart:" << name() << " name:" << v->name());
DmPart * l = dynamic_cast(v);
int ret = disk ? 0 : DMPART_INTERNAL_ERR;
if( ret==0 && l == NULL )
@@ -901,10 +897,10 @@
ret = l->resizeFs();
if( ret==0 )
{
- ProcPart pp;
+ ProcParts parts;
updateMinor();
- l->updateSize( pp );
- getStorage()->waitForDevice( l->device() );
+ l->updateSize(parts);
+ Storage::waitForDevice(l->device());
}
if( ret==0 && remount )
ret = l->mount();
@@ -912,30 +908,14 @@
return( ret );
}
-string DmPartCo::setDiskLabelText( bool doing ) const
+Text DmPartCo::setDiskLabelText( bool doing ) const
{
- string txt;
- string d = dev;
- if( doing )
- {
- // displayed text during action, %1$s is replaced by name (e.g. pdc_igeeeadj),
- // %2$s is replaced by label name (e.g. msdos)
- txt = sformat( _("Setting disk label of %1$s to %2$s"),
- d.c_str(), labelName().c_str() );
- }
- else
- {
- // displayed text before action, %1$s is replaced by name (e.g. pdc_igeeeadj),
- // %2$s is replaced by label name (e.g. msdos)
- txt = sformat( _("Set disk label of %1$s to %2$s"),
- d.c_str(), labelName().c_str() );
- }
- return( txt );
+ return disk->setDiskLabelText(doing);
}
-string DmPartCo::removeText( bool doing ) const
+Text DmPartCo::removeText( bool doing ) const
{
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by a name (e.g. pdc_igeeeadj),
@@ -980,125 +960,60 @@
tinfo = info;
}
-namespace storage
-{
std::ostream& operator<< (std::ostream& s, const DmPartCo& d )
{
- s << *((PeContainer*)&d);
- s << " DmNr:" << d.mnr
- << " PNum:" << d.num_part;
+ s << dynamic_cast(d);
if( !d.udev_id.empty() )
s << " UdevId:" << d.udev_id;
- if( d.del_ptable )
- s << " delPT";
if( !d.active )
s << " inactive";
+ s << " geometry:" << d.disk->getGeometry();
return( s );
}
-}
-string DmPartCo::getDiffString( const Container& d ) const
+ void
+ DmPartCo::logDifference(std::ostream& log, const DmPartCo& rhs) const
{
- string log = Container::getDiffString( d );
- const DmPartCo* p = dynamic_cast(&d);
- if( p )
- {
- if( del_ptable!=p->del_ptable )
- {
- if( p->del_ptable )
- log += " -->delPT";
- else
- log += " delPT-->";
- }
- if( active!=p->active )
- {
- if( p->active )
- log += " -->active";
- else
- log += " active-->";
- }
- }
- return( log );
- }
+ PeContainer::logDifference(log, rhs);
-void DmPartCo::logDifference( const DmPartCo& d ) const
- {
- string log = getDiffString( d );
- y2mil(log);
- ConstDmPartPair pp=dmpartPair();
- ConstDmPartIter i=pp.begin();
- while( i!=pp.end() )
- {
- ConstDmPartPair pc=d.dmpartPair();
- ConstDmPartIter j = pc.begin();
- while( j!=pc.end() &&
- (i->device()!=j->device() || i->created()!=j->created()) )
- ++j;
- if( j!=pc.end() )
- {
- if( !i->equalContent( *j ) )
- i->logDifference( *j );
- }
- else
- y2mil( " -->" << *i );
- ++i;
- }
- pp=d.dmpartPair();
- i=pp.begin();
- while( i!=pp.end() )
- {
- ConstDmPartPair pc=dmpartPair();
- ConstDmPartIter j = pc.begin();
- while( j!=pc.end() &&
- (i->device()!=j->device() || i->created()!=j->created()) )
- ++j;
- if( j==pc.end() )
- y2mil( " <--" << *i );
- ++i;
- }
+ logDiff(log, "active", active, rhs.active);
}
+
bool DmPartCo::equalContent( const DmPartCo& rhs ) const
{
bool ret = PeContainer::equalContent(rhs,false) &&
- active==rhs.active &&
- del_ptable==rhs.del_ptable;
+ active==rhs.active;
if( ret )
{
ConstDmPartPair pp = dmpartPair();
ConstDmPartPair pc = rhs.dmpartPair();
- ConstDmPartIter i = pp.begin();
- ConstDmPartIter j = pc.begin();
- while( ret && i!=pp.end() && j!=pc.end() )
- {
- ret = ret && i->equalContent( *j );
- ++i;
- ++j;
- }
- ret = ret && i==pp.end() && j==pc.end();
+ ret = ret && storage::equalContent(pp.begin(), pp.end(), pc.begin(), pc.end());
}
return( ret );
}
-DmPartCo::DmPartCo( const DmPartCo& rhs ) : PeContainer(rhs)
+
+ DmPartCo::DmPartCo(const DmPartCo& c)
+ : PeContainer(c), udev_id(c.udev_id), active(c.active)
{
- y2deb("constructed DmPartCo by copy constructor from " << rhs.nm);
- active = rhs.active;
- del_ptable = rhs.del_ptable;
- disk = NULL;
- if( rhs.disk )
- disk = new Disk( *rhs.disk );
- getStorage()->waitForDevice();
- ConstDmPartPair p = rhs.dmpartPair();
- for( ConstDmPartIter i = p.begin(); i!=p.end(); ++i )
+ y2deb("copy-constructed DmPartCo from " << c.dev);
+
+ disk = NULL;
+ if (c.disk)
+ disk = new Disk(*c.disk);
+
+ Storage::waitForDevice();
+ ConstDmPartPair p = c.dmpartPair();
+ for (ConstDmPartIter i = p.begin(); i != p.end(); ++i)
{
- DmPart * p = new DmPart( *this, *i );
- vols.push_back( p );
+ DmPart* p = new DmPart(*this, *i);
+ vols.push_back(p);
}
- updatePointers(true);
- }
-void DmPartCo::logData( const string& Dir ) {;}
+ updatePointers(true);
+ }
+}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPartCo.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPartCo.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPartCo.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmPartCo.h Tue May 17 13:39:44 2011
@@ -25,37 +25,43 @@
#include <list>
-#include "y2storage/PeContainer.h"
-#include "y2storage/Disk.h"
-#include "y2storage/DmPart.h"
+#include "storage/PeContainer.h"
+#include "storage/Disk.h"
+#include "storage/DmPart.h"
+
namespace storage
{
+ using std::list;
+
class Storage;
-class SystemCmd;
-class ProcPart;
+ class SystemInfo;
class Region;
+
class DmPartCo : public PeContainer
{
friend class Storage;
public:
- DmPartCo( Storage * const s, const string& Name, storage::CType t,
- ProcPart& ppart );
- DmPartCo( const DmPartCo& rhs );
+
+ DmPartCo(Storage* s, const string& name, const string& device, CType t,
+ SystemInfo& systeminfo);
+ DmPartCo(const DmPartCo& c);
virtual ~DmPartCo();
unsigned long long sizeK() const { return size_k; }
const string& labelName() const { return disk->labelName(); }
- const string& udevPath() const { return udev_path; }
- const std::list<string>& udevId() const { return udev_id; }
+ virtual list<string> udevId() const { return udev_id; }
unsigned numPartitions() const { return disk->numPartitions(); }
static storage::CType staticType() { return storage::DMRAID; }
friend std::ostream& operator<< (std::ostream&, const DmPartCo& );
void setUdevData(const list<string>& id);
+ virtual string procName() const { return "dm-" + decString(mnr); }
+ virtual string sysfsPath() const;
+
int createPartition( storage::PartitionType type, long unsigned start,
long unsigned len, string& device,
bool checkRelaxed=false );
@@ -65,8 +71,7 @@
int removePartition( unsigned nr );
int changePartitionId( unsigned nr, unsigned id );
int forgetChangePartitionId( unsigned nr );
- int changePartitionArea( unsigned nr, unsigned long start,
- unsigned long size, bool checkRelaxed=false );
+ int changePartitionArea(unsigned nr, const Region& cylRegion, bool checkRelaxed = false);
int nextFreePartition(storage::PartitionType type, unsigned& nr,
string& device) const;
int destroyPartitionTable( const string& new_label );
@@ -92,23 +97,23 @@
{ return disk->cylinderToKb( val ); }
unsigned long kbToCylinder( unsigned long long val ) const
{ return disk->kbToCylinder( val ); }
- string getPartName( unsigned nr ) const;
- virtual void getCommitActions( std::liststorage::commitAction*& l ) const;
- virtual int getToCommit( storage::CommitStage stage,
- std::list& col,
- std::list& vol );
+ string getPartName(unsigned nr) const;
+ string getPartDevice(unsigned nr) const;
+
+ virtual void getCommitActions(list<commitAction>& l) const;
+ virtual void getToCommit(storage::CommitStage stage, list& col,
+ list& vol) const;
virtual int commitChanges( storage::CommitStage stage );
int commitChanges( storage::CommitStage stage, Volume* vol );
Partition* getPartition( unsigned nr, bool del );
void getInfo( storage::DmPartCoInfo& info ) const;
bool equalContent( const DmPartCo& rhs ) const;
- virtual string getDiffString( const Container& d ) const;
- void logDifference( const DmPartCo& d ) const;
- DmPartCo& operator= ( const DmPartCo& rhs );
+
+ void logDifference(std::ostream& log, const DmPartCo& rhs) const;
+
static string undevName( const string& name );
- string numToName( unsigned num ) const;
protected:
// iterators over partitions
@@ -159,13 +164,12 @@
return( ConstDmPartIter( DmPartCPIterator( p, CheckDmPart, true )) );
}
- DmPartCo( Storage * const s, const string& File );
virtual void print( std::ostream& s ) const { s << *this; }
- virtual Container* getCopy() const { return( new DmPartCo( *this ) ); }
+ virtual Container* getCopy() const = 0; // { return( new DmPartCo( *this ) ); }
void activate_part( bool val );
- void init( ProcPart& ppart );
- void createDisk( ProcPart& ppart );
- void getVolumes( ProcPart& ppart );
+ void init(SystemInfo& systeminfo);
+ void createDisk(SystemInfo& systeminfo);
+ void getVolumes(const ProcParts& parts);
void updatePointers( bool invalid=false );
void updateMinor();
virtual void newP( DmPart*& dm, unsigned num, Partition* p );
@@ -177,28 +181,25 @@
bool validPartition( const Partition* p );
bool findDm( unsigned nr, DmPartIter& i );
- static bool partNotDeleted( const DmPart&d ) { return( !d.deleted() ); }
-
int doCreate( Volume* v );
int doRemove( Volume* v );
int doResize( Volume* v );
int doSetType( DmPart* v );
int doCreateLabel();
virtual int doRemove();
- virtual string removeText( bool doing ) const;
- virtual string setDiskLabelText( bool doing ) const;
-
- void logData( const string& Dir );
- string udev_path;
- std::list<string> udev_id;
- string logfile_name;
+ virtual Text removeText( bool doing ) const;
+ virtual Text setDiskLabelText( bool doing ) const;
+ list<string> udev_id;
Disk* disk;
bool active;
- bool del_ptable;
- unsigned num_part;
- mutable storage::DmPartCoInfo info;
+ mutable storage::DmPartCoInfo info; // workaround for broken ycp bindings
+
+ private:
+
+ DmPartCo& operator=(const DmPartCo&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmmultipath.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmmultipath.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmmultipath.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmmultipath.cc Tue May 17 13:39:44 2011
@@ -19,41 +19,48 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
#include <sstream>
-#include "y2storage/Dmmultipath.h"
-#include "y2storage/DmmultipathCo.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Storage.h"
+#include "storage/Dmmultipath.h"
+#include "storage/DmmultipathCo.h"
+#include "storage/SystemCmd.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
-using namespace storage;
-using namespace std;
-
-Dmmultipath::Dmmultipath(const DmmultipathCo& d, unsigned nr, Partition* p)
- : DmPart(d, nr, p)
+namespace storage
{
- y2mil("constructed dmmultipath " << dev << " on co " << cont->name());
-}
+ using namespace std;
-Dmmultipath::~Dmmultipath()
-{
- y2deb("destructed dmmultipath " << dev);
-}
+ Dmmultipath::Dmmultipath(const DmmultipathCo& c, const string& name, const string& device,
+ unsigned nr, Partition* p)
+ : DmPart(c, name, device, nr, p)
+ {
+ y2mil("constructed Dmmultipath " << dev << " on " << cont->device());
+ }
+
+
+ Dmmultipath::Dmmultipath(const DmmultipathCo& c, const Dmmultipath& v)
+ : DmPart(c, v)
+ {
+ y2deb("copy-constructed Dmmultipath from " << v.dev);
+ }
-string Dmmultipath::removeText( bool doing ) const
+ Dmmultipath::~Dmmultipath()
{
- string txt;
+ y2deb("destructed Dmmultipath " << dev);
+ }
+
+
+Text Dmmultipath::removeText( bool doing ) const
+ {
+ Text txt;
string d = dev.substr(12);
if( p && p->OrigNr()!=p->nr() )
- d = co()->numToName(p->OrigNr());
+ d = co()->getPartName(p->OrigNr());
if( doing )
{
// displayed text during action, %1$s is replaced by multipath partition name e.g. 3600508b400105f590000900000300000_part1
@@ -69,9 +76,9 @@
return( txt );
}
-string Dmmultipath::createText( bool doing ) const
+Text Dmmultipath::createText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev.substr(12);
if( doing )
{
@@ -128,9 +135,9 @@
return( txt );
}
-string Dmmultipath::formatText( bool doing ) const
+Text Dmmultipath::formatText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev.substr(12);
if( doing )
{
@@ -185,9 +192,9 @@
return( txt );
}
-string Dmmultipath::resizeText( bool doing ) const
+Text Dmmultipath::resizeText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev.substr(12);
if( doing )
{
@@ -199,8 +206,9 @@
// displayed text during action, %1$s is replaced by multipath partition e.g. 3600508b400105f590000900000300000_part1
// %2$s is replaced by size (e.g. 623.5 MB)
txt = sformat( _("Extending multipath partition %1$s to %2$s"), d.c_str(), sizeString().c_str() );
+ txt += Text(" ", " ");
// text displayed during action
- txt += string(" ") + _("(progress bar might not move)");
+ txt += _("(progress bar might not move)");
}
else
{
@@ -217,9 +225,9 @@
return( txt );
}
-string Dmmultipath::setTypeText( bool doing ) const
+Text Dmmultipath::setTypeText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev.substr(12);
if( doing )
{
@@ -244,31 +252,24 @@
tinfo.p = info;
}
-namespace storage
-{
std::ostream& operator<< (std::ostream& s, const Dmmultipath &p )
{
- s << *(DmPart*)&p;
+ s << dynamic_cast(p);
return( s );
}
-}
bool Dmmultipath::equalContent( const Dmmultipath& rhs ) const
{
return( DmPart::equalContent(rhs) );
}
-void Dmmultipath::logDifference( const Dmmultipath& rhs ) const
+
+ void
+ Dmmultipath::logDifference(std::ostream& log, const Dmmultipath& rhs) const
{
- DmPart::logDifference(rhs);
+ DmPart::logDifference(log, rhs);
}
-
-Dmmultipath& Dmmultipath::operator=(const Dmmultipath& rhs)
-{
- y2deb("operator= from " << rhs.nm);
- *((DmPart*)this) = rhs;
- return *this;
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmmultipath.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmmultipath.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmmultipath.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmmultipath.h Tue May 17 13:39:44 2011
@@ -23,7 +23,7 @@
#ifndef DMMULTIPATH_H
#define DMMULTIPATH_H
-#include "y2storage/DmPart.h"
+#include "storage/DmPart.h"
namespace storage
{
@@ -34,25 +34,34 @@
class Dmmultipath : public DmPart
{
public:
- Dmmultipath( const DmmultipathCo& d, unsigned nr, Partition* p=NULL );
- Dmmultipath( const DmmultipathCo& d, const Dmmultipath& rd );
+ Dmmultipath(const DmmultipathCo& c, const string& name, const string& device, unsigned nr,
+ Partition* p);
+ Dmmultipath(const DmmultipathCo& c, const Dmmultipath& v);
virtual ~Dmmultipath();
+
void getInfo( storage::DmmultipathInfo& info ) const;
friend std::ostream& operator<< (std::ostream& s, const Dmmultipath &p );
virtual void print( std::ostream& s ) const { s << *this; }
- string removeText( bool doing ) const;
- string createText( bool doing ) const;
- string formatText( bool doing ) const;
- string resizeText( bool doing ) const;
- string setTypeText( bool doing=true ) const;
+ Text removeText( bool doing ) const;
+ Text createText( bool doing ) const;
+ Text formatText( bool doing ) const;
+ Text resizeText( bool doing ) const;
+ Text setTypeText(bool doing) const;
bool equalContent( const Dmmultipath& rhs ) const;
- void logDifference( const Dmmultipath& d ) const;
+
+ void logDifference(std::ostream& log, const Dmmultipath& rhs) const;
+
static bool notDeleted( const Dmmultipath& l ) { return( !l.deleted() ); }
protected:
virtual const string shortPrintedName() const { return( "Dmmultipath" ); }
- Dmmultipath& operator=( const Dmmultipath& );
+
+ private:
+
+ Dmmultipath(const Dmmultipath&); // disallow
+ Dmmultipath& operator=(const Dmmultipath&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmmultipathCo.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmmultipathCo.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmmultipathCo.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmmultipathCo.cc Tue May 17 13:39:44 2011
@@ -19,24 +19,24 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
-#include <iostream>
+#include <ostream>
#include <sstream>
#include <locale>
#include
-#include "y2storage/DmmultipathCo.h"
-#include "y2storage/Dmmultipath.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Storage.h"
-#include "y2storage/StorageDefines.h"
+#include "storage/DmmultipathCo.h"
+#include "storage/Dmmultipath.h"
+#include "storage/SystemCmd.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
+#include "storage/StorageDefines.h"
+#include "storage/SystemInfo.h"
-using namespace std;
-using namespace storage;
+
+namespace storage
+{
+ using namespace std;
CmdMultipath::CmdMultipath()
@@ -45,8 +45,7 @@
if (c.retcode() != 0 || c.numLines() == 0)
return;
- vector<string> lines;
- c.getStdout(lines);
+ const vector<string>& lines = c.stdout();
vector<string>::const_iterator it1 = lines.begin();
while (it1 != lines.end())
@@ -58,7 +57,9 @@
string name = extractNthWord(0, *it1);
y2mil("mp name:" << name);
- list<string> tmp = splitString(extractNthWord(2, *it1, true), ",");
+ bool has_alias = boost::starts_with(extractNthWord(1, *it1), "(");
+
+ list<string> tmp = splitString(extractNthWord(has_alias ? 3 : 2, *it1, true), ",");
if (tmp.size() >= 2)
{
list<string>::const_iterator it2 = tmp.begin();
@@ -120,41 +121,51 @@
}
-DmmultipathCo::DmmultipathCo( Storage * const s, const string& Name, ProcPart& ppart ) :
- DmPartCo(s, "/dev/mapper/"+Name, staticType(), ppart )
-{
- DmPartCo::init( ppart );
- getMultipathData( Name );
- y2deb("constructing dmmultipath co " << Name);
-}
+ DmmultipathCo::DmmultipathCo(Storage* s, const string& name, const string& device,
+ SystemInfo& systeminfo)
+ : DmPartCo(s, name, device, staticType(), systeminfo)
+ {
+ getMultipathData(name, systeminfo);
+ const UdevMap& by_id = systeminfo.getUdevMap("/dev/disk/by-id");
+ UdevMap::const_iterator it = by_id.find("dm-" + decString(minorNr()));
+ if (it != by_id.end())
+ setUdevData(it->second);
-DmmultipathCo::~DmmultipathCo()
-{
- y2deb("destructed multipath co " << dev);
-}
+ y2deb("constructing DmmultipathCo " << name);
+ }
-void
-DmmultipathCo::getMultipathData(const string& name)
-{
- y2mil("name:" << name);
+ DmmultipathCo::DmmultipathCo(const DmmultipathCo& c)
+ : DmPartCo(c), vendor(c.vendor), model(c.model)
+ {
+ y2deb("copy-constructed DmmultipathCo from " << c.dev);
+ }
+
- CmdMultipath::Entry entry;
- if (CmdMultipath().getEntry(name, entry))
+ DmmultipathCo::~DmmultipathCo()
{
- vendor = entry.vendor;
- model = entry.model;
+ y2deb("destructed DmMultipathCo " << dev);
+ }
+
- Pv *pv = new Pv;
- for (list<string>::const_iterator it = entry.devices.begin(); it != entry.devices.end(); ++it)
+ void
+ DmmultipathCo::getMultipathData(const string& name, SystemInfo& systeminfo)
+ {
+ CmdMultipath::Entry entry;
+ if (systeminfo.getCmdMultipath().getEntry(name, entry))
{
- pv->device = *it;
- addPv(pv);
+ vendor = entry.vendor;
+ model = entry.model;
+
+ for (list<string>::const_iterator it = entry.devices.begin(); it != entry.devices.end(); ++it)
+ {
+ Pv pv;
+ pv.device = *it;
+ addPv(pv);
+ }
}
- delete pv;
}
-}
void
@@ -162,8 +173,7 @@
{
y2mil("disk:" << nm << " id:" << id);
udev_id = id;
- udev_id.erase(remove_if(udev_id.begin(), udev_id.end(), find_begin("dm-")), udev_id.end());
- udev_id.sort();
+ udev_id.remove_if(string_starts_with("dm-"));
y2mil("id:" << udev_id);
DmPartCo::setUdevData(udev_id);
@@ -180,23 +190,25 @@
DmmultipathCo::newP( DmPart*& dm, unsigned num, Partition* p )
{
y2mil( "num:" << num );
- dm = new Dmmultipath( *this, num, p );
+ dm = new Dmmultipath( *this, getPartName(num), getPartDevice(num), num, p );
}
void
-DmmultipathCo::addPv(Pv*& p)
+ DmmultipathCo::addPv(const Pv& p)
{
- PeContainer::addPv(p);
+ PeContainer::addPv(p);
if (!deleted())
- getStorage()->setUsedBy(p->device, UB_DMMULTIPATH, name());
- p = new Pv;
+ getStorage()->setUsedBy(p.device, UB_DMMULTIPATH, device());
}
void
DmmultipathCo::activate(bool val)
{
+ if (getenv("LIBSTORAGE_NO_DMMULTIPATH") != NULL)
+ return;
+
y2mil("old active:" << active << " val:" << val);
if (active != val)
@@ -228,27 +240,20 @@
}
- bool
- DmmultipathCo::isActivated(const string& name)
- {
- SystemCmd c(DMSETUPBIN " table " + quote(name));
- return c.retcode() == 0 && c.numLines() >= 1 && isdigit(c.stdout()[0]);
- }
-
-
list<string>
- DmmultipathCo::getMultipaths()
+ DmmultipathCo::getMultipaths(SystemInfo& systeminfo)
{
list<string> l;
- list<string> entries = CmdMultipath().getEntries();
+ list<string> entries = systeminfo.getCmdMultipath().getEntries();
for (list<string>::const_iterator it = entries.begin(); it != entries.end(); ++it)
- {
- if (isActivated(*it))
+ {
+ CmdDmsetup::Entry entry;
+ if (systeminfo.getCmdDmsetup().getEntry(*it, entry) && entry.segments > 0)
l.push_back(*it);
else
y2mil("ignoring inactive dmmultipath " << *it);
- }
+ }
if (!l.empty())
active = true;
@@ -258,28 +263,6 @@
}
-string DmmultipathCo::setDiskLabelText( bool doing ) const
- {
- string txt;
- string d = nm;
- if( doing )
- {
- // displayed text during action, %1$s is replaced by multipath name (e.g. 3600508b400105f590000900000300000),
- // %2$s is replaced by label name (e.g. msdos)
- txt = sformat( _("Setting disk label of multipath disk %1$s to %2$s"),
- d.c_str(), labelName().c_str() );
- }
- else
- {
- // displayed text before action, %1$s is replaced by multipath name (e.g. 3600508b400105f590000900000300000),
- // %2$s is replaced by label name (e.g. msdos)
- txt = sformat( _("Set disk label of multipath disk %1$s to %2$s"),
- d.c_str(), labelName().c_str() );
- }
- return( txt );
- }
-
-
void DmmultipathCo::getInfo( DmmultipathCoInfo& tinfo ) const
{
DmPartCo::getInfo( info );
@@ -288,32 +271,39 @@
tinfo.model = model;
}
-namespace storage
-{
std::ostream& operator<<(std::ostream& s, const DmmultipathCo& d)
{
- s << *((DmPartCo*)&d);
+ s << dynamic_cast(d);
s << " Vendor:" << d.vendor
<< " Model:" << d.model;
return s;
}
-}
-string DmmultipathCo::getDiffString( const Container& d ) const
-{
- string log = DmPartCo::getDiffString(d);
- const DmmultipathCo * p = dynamic_cast(&d);
- if (p)
- {
- if (vendor != p->vendor)
- log += " vendor:" + vendor + "-->" + p->vendor;
- if (model != p->model)
- log += " model:" + model + "-->" + p->model;
+ void
+ DmmultipathCo::logDifference(std::ostream& log, const DmmultipathCo& rhs) const
+ {
+ DmPartCo::logDifference(log, rhs);
+
+ logDiff(log, "vendor", vendor, rhs.vendor);
+ logDiff(log, "model", model, rhs.model);
}
- return log;
-}
+
+
+ void
+ DmmultipathCo::logDifferenceWithVolumes(std::ostream& log, const Container& rhs_c) const
+ {
+ const DmmultipathCo& rhs = dynamic_cast(rhs_c);
+
+ logDifference(log, rhs);
+ log << endl;
+
+ ConstDmPartPair pp = dmpartPair();
+ ConstDmPartPair pc = rhs.dmpartPair();
+ logVolumesDifference(log, pp.begin(), pp.end(), pc.begin(), pc.end());
+ }
+
bool DmmultipathCo::equalContent( const Container& rhs ) const
{
@@ -327,12 +317,7 @@
return ret;
}
-DmmultipathCo::DmmultipathCo( const DmmultipathCo& rhs ) : DmPartCo(rhs)
-{
- vendor = rhs.vendor;
- model = rhs.model;
-}
-
-void DmmultipathCo::logData( const string& Dir ) {}
bool DmmultipathCo::active = false;
+
+}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmmultipathCo.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmmultipathCo.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmmultipathCo.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmmultipathCo.h Tue May 17 13:39:44 2011
@@ -25,18 +25,14 @@
#include <list>
-#include "y2storage/DmPartCo.h"
-#include "y2storage/Dmmultipath.h"
+#include "storage/DmPartCo.h"
+#include "storage/Dmmultipath.h"
namespace storage
{
- using std::map;
-
class Storage;
-class SystemCmd;
-class ProcPart;
-class Region;
+ class SystemInfo;
class CmdMultipath
@@ -71,10 +67,9 @@
friend class Storage;
public:
- DmmultipathCo( Storage * const s, const string& Name, ProcPart& ppart );
- DmmultipathCo( Storage * const s, const string& Name, unsigned num,
- unsigned long long Size, ProcPart& ppart );
- DmmultipathCo( const DmmultipathCo& rhs );
+
+ DmmultipathCo(Storage* s, const string& name, const string& device, SystemInfo& systeminfo);
+ DmmultipathCo(const DmmultipathCo& c);
virtual ~DmmultipathCo();
static storage::CType staticType() { return storage::DMMULTIPATH; }
@@ -83,8 +78,9 @@
void setUdevData(const list<string>& id);
bool equalContent( const Container& rhs ) const;
- string getDiffString( const Container& d ) const;
- DmmultipathCo& operator= ( const DmmultipathCo& rhs );
+
+ void logDifference(std::ostream& log, const DmmultipathCo& rhs) const;
+ virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
protected:
@@ -136,31 +132,26 @@
return( ConstDmmultipathIter( DmmultipathCPIterator( p, CheckDmmultipath, true )) );
}
- DmmultipathCo( Storage * const s, const string& File );
virtual void print( std::ostream& s ) const { s << *this; }
virtual Container* getCopy() const { return( new DmmultipathCo( *this ) ); }
- void getMultipathData( const string& name );
- void addMultipath( const string& name );
- void addPv( Pv*& p );
+ void getMultipathData(const string& name, SystemInfo& systeminfo);
+ void addPv(const Pv& pv);
void newP( DmPart*& dm, unsigned num, Partition* p );
- string setDiskLabelText( bool doing ) const;
- static string undevName( const string& name );
-
- static void activate( bool val=true );
+ static void activate(bool val);
static bool isActive() { return active; }
- static bool isActivated(const string& name);
- static list<string> getMultipaths();
-
- static bool multipathNotDeleted( const Dmmultipath&d ) { return( !d.deleted() ); }
-
- void logData( const string& Dir );
+ static list<string> getMultipaths(SystemInfo& systeminfo);
string vendor;
string model;
static bool active;
+
+ private:
+
+ DmmultipathCo& operator=(const DmmultipathCo&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmraid.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmraid.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmraid.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmraid.cc Tue May 17 13:39:44 2011
@@ -19,41 +19,48 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
#include <sstream>
-#include "y2storage/Dmraid.h"
-#include "y2storage/DmraidCo.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Storage.h"
+#include "storage/Dmraid.h"
+#include "storage/DmraidCo.h"
+#include "storage/SystemCmd.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
-using namespace storage;
-using namespace std;
-
-Dmraid::Dmraid(const DmraidCo& d, unsigned nr, Partition* p)
- : DmPart(d, nr, p)
+namespace storage
{
- y2mil("constructed dmraid " << dev << " on co " << cont->name());
-}
+ using namespace std;
-Dmraid::~Dmraid()
-{
- y2deb("destructed dmraid " << dev);
-}
+ Dmraid::Dmraid(const DmraidCo& c, const string& name, const string& device, unsigned nr,
+ Partition* p)
+ : DmPart(c, name, device, nr, p)
+ {
+ y2mil("constructed Dmraid " << dev << " on " << cont->device());
+ }
+
+
+ Dmraid::Dmraid(const DmraidCo& c, const Dmraid& v)
+ : DmPart(c, v)
+ {
+ y2deb("copy-constructed Dmraid from " << v.dev);
+ }
-string Dmraid::removeText( bool doing ) const
+ Dmraid::~Dmraid()
{
- string txt;
+ y2deb("destructed Dmraid " << dev);
+ }
+
+
+Text Dmraid::removeText( bool doing ) const
+ {
+ Text txt;
string d = dev.substr(12);
if( p && p->OrigNr()!=p->nr() )
- d = co()->numToName(p->OrigNr());
+ d = co()->getPartName(p->OrigNr());
if( doing )
{
// displayed text during action, %1$s is replaced by raid partition name e.g. pdc_dabaheedj_part1
@@ -69,9 +76,9 @@
return( txt );
}
-string Dmraid::createText( bool doing ) const
+Text Dmraid::createText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev.substr(12);
if( doing )
{
@@ -128,9 +135,9 @@
return( txt );
}
-string Dmraid::formatText( bool doing ) const
+Text Dmraid::formatText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev.substr(12);
if( doing )
{
@@ -185,9 +192,9 @@
return( txt );
}
-string Dmraid::resizeText( bool doing ) const
+Text Dmraid::resizeText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev.substr(12);
if( doing )
{
@@ -199,8 +206,9 @@
// displayed text during action, %1$s is replaced by raid partition e.g. pdc_dabaheedj_part1
// %2$s is replaced by size (e.g. 623.5 MB)
txt = sformat( _("Extending raid partition %1$s to %2$s"), d.c_str(), sizeString().c_str() );
+ txt += Text(" ", " ");
// text displayed during action
- txt += string(" ") + _("(progress bar might not move)");
+ txt += _("(progress bar might not move)");
}
else
{
@@ -217,9 +225,9 @@
return( txt );
}
-string Dmraid::setTypeText( bool doing ) const
+Text Dmraid::setTypeText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev.substr(12);
if( doing )
{
@@ -244,31 +252,24 @@
tinfo.p = info;
}
-namespace storage
-{
std::ostream& operator<< (std::ostream& s, const Dmraid &p )
{
- s << *(DmPart*)&p;
+ s << dynamic_cast(p);
return( s );
}
-}
bool Dmraid::equalContent( const Dmraid& rhs ) const
{
return( DmPart::equalContent(rhs) );
}
-void Dmraid::logDifference( const Dmraid& rhs ) const
+
+ void
+ Dmraid::logDifference(std::ostream& log, const Dmraid& rhs) const
{
- DmPart::logDifference(rhs);
+ DmPart::logDifference(log, rhs);
}
-
-Dmraid& Dmraid::operator=(const Dmraid& rhs)
-{
- y2deb("operator= from " << rhs.nm);
- *((DmPart*)this) = rhs;
- return *this;
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmraid.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmraid.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmraid.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Dmraid.h Tue May 17 13:39:44 2011
@@ -23,7 +23,7 @@
#ifndef DMRAID_H
#define DMRAID_H
-#include "y2storage/DmPart.h"
+#include "storage/DmPart.h"
namespace storage
{
@@ -34,25 +34,34 @@
class Dmraid : public DmPart
{
public:
- Dmraid( const DmraidCo& d, unsigned nr, Partition* p=NULL );
- Dmraid( const DmraidCo& d, const Dmraid& rd );
+ Dmraid(const DmraidCo& c, const string& name, const string& device, unsigned nr,
+ Partition* p);
+ Dmraid(const DmraidCo& c, const Dmraid& v);
virtual ~Dmraid();
+
void getInfo( storage::DmraidInfo& info ) const;
friend std::ostream& operator<< (std::ostream& s, const Dmraid &p );
virtual void print( std::ostream& s ) const { s << *this; }
- string removeText( bool doing ) const;
- string createText( bool doing ) const;
- string formatText( bool doing ) const;
- string resizeText( bool doing ) const;
- string setTypeText( bool doing=true ) const;
+ Text removeText( bool doing ) const;
+ Text createText( bool doing ) const;
+ Text formatText( bool doing ) const;
+ Text resizeText( bool doing ) const;
+ Text setTypeText(bool doing) const;
bool equalContent( const Dmraid& rhs ) const;
- void logDifference( const Dmraid& d ) const;
+
+ void logDifference(std::ostream& log, const Dmraid& rhs) const;
+
static bool notDeleted( const Dmraid& l ) { return( !l.deleted() ); }
protected:
virtual const string shortPrintedName() const { return( "Dmraid" ); }
- Dmraid& operator=( const Dmraid& );
+
+ private:
+
+ Dmraid(const Dmraid&); // disallow
+ Dmraid& operator=(const Dmraid&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmraidCo.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmraidCo.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmraidCo.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmraidCo.cc Tue May 17 13:39:44 2011
@@ -19,80 +19,135 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
-#include <iostream>
+#include <ostream>
#include <sstream>
-#include "y2storage/DmraidCo.h"
-#include "y2storage/Dmraid.h"
-#include "y2storage/MdPartCo.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Storage.h"
-#include "y2storage/StorageDefines.h"
+#include "storage/DmraidCo.h"
+#include "storage/Dmraid.h"
+#include "storage/SystemCmd.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
+#include "storage/StorageDefines.h"
+#include "storage/SystemInfo.h"
-using namespace std;
-using namespace storage;
-
-DmraidCo::DmraidCo(Storage * const s, const string& Name, ProcPart& ppart)
- : DmPartCo(s, "/dev/mapper/"+Name, staticType(), ppart)
-{
- DmPartCo::init(ppart);
- getRaidData(Name);
- y2deb("constructing dmraid co " << Name);
-}
-
-
-DmraidCo::~DmraidCo()
+namespace storage
{
- y2deb("destructed raid co " << dev);
-}
+ using namespace std;
-void DmraidCo::getRaidData( const string& name )
+ CmdDmraid::CmdDmraid()
{
- y2milestone( "name:%s", name.c_str() );
- SystemCmd c(DMRAIDBIN " -s -c -c -c " + quote(name));
- list<string>::const_iterator ci;
- list<string> sl;
- if( c.numLines()>0 )
- sl = splitString( *c.getLine(0), ":" );
- Pv *pve = new Pv;
- if( sl.size()>=4 )
- {
- ci = sl.begin();
- ++ci; ++ci; ++ci;
- raidtype = *ci;
- }
- unsigned num = 1;
- while( num=3 )
+ const list<string> sl = splitString(*it++, ":");
+ if (sl.size() >= 4)
{
- ci = sl.begin();
- ++ci; ++ci;
- if( *ci == name )
+ Entry entry;
+
+ list<string>::const_iterator ci = sl.begin();
+ string name = *ci;
+ advance(ci, 3);
+ entry.raidtype = *ci;
+
+ while (it != lines.end() && boost::starts_with(*it, "/dev/"))
{
- --ci;
- if( controller.empty() && !ci->empty() )
- controller = *ci;
- --ci;
- if( ci->find( "/dev/" )==0 )
+ const list<string> sl = splitString(*it, ":");
+ if (sl.size() >= 4)
{
- pve->device = *ci;
- addPv( pve );
+ list<string>::const_iterator ci = sl.begin();
+ entry.devices.push_back(*ci);
+ advance(ci, 1);
+ entry.controller = *ci;
}
+
+ ++it;
}
+
+ data[name] = entry;
+ }
+ }
+
+ for (const_iterator it = data.begin(); it != data.end(); ++it)
+ y2mil("data[" << it->first << "] -> controller:" << it->second.controller <<
+ " raidtype:" << it->second.raidtype << " devices:" << it->second.devices);
+ }
+
+
+ list<string>
+ CmdDmraid::getEntries() const
+ {
+ list<string> ret;
+ for (const_iterator it = data.begin(); it != data.end(); ++it)
+ ret.push_back(it->first);
+ return ret;
+ }
+
+
+ bool
+ CmdDmraid::getEntry(const string& name, Entry& entry) const
+ {
+ const_iterator it = data.find(name);
+ if (it == data.end())
+ return false;
+
+ entry = it->second;
+ return true;
+ }
+
+
+ DmraidCo::DmraidCo(Storage* s, const string& name, const string& device, SystemInfo& systeminfo)
+ : DmPartCo(s, name, device, staticType(), systeminfo)
+ {
+ getRaidData(name, systeminfo);
+
+ const UdevMap& by_id = systeminfo.getUdevMap("/dev/disk/by-id");
+ UdevMap::const_iterator it = by_id.find("dm-" + decString(minorNr()));
+ if (it != by_id.end())
+ setUdevData(it->second);
+
+ y2deb("constructing DmraidCo " << name);
+ }
+
+
+ DmraidCo::DmraidCo(const DmraidCo& c)
+ : DmPartCo(c), raidtype(c.raidtype), controller(c.controller)
+ {
+ y2deb("copy-constructed DmraidCo from " << c.dev);
+ }
+
+
+ DmraidCo::~DmraidCo()
+ {
+ y2deb("destructed DmraidCo " << dev);
+ }
+
+
+ void
+ DmraidCo::getRaidData(const string& name, SystemInfo& systeminfo)
+ {
+ y2mil("name:" << name);
+
+ CmdDmraid::Entry entry;
+ if (systeminfo.getCmdDmraid().getEntry(name, entry))
+ {
+ controller = entry.controller;
+ raidtype = entry.raidtype;
+
+ for (list<string>::const_iterator it = entry.devices.begin(); it != entry.devices.end(); ++it)
+ {
+ Pv pv;
+ pv.device = *it;
+ addPv(pv);
}
- ++num;
}
- delete( pve );
}
@@ -101,8 +156,7 @@
{
y2mil("disk:" << nm << " id:" << id);
udev_id = id;
- udev_id.erase(remove_if(udev_id.begin(), udev_id.end(), find_begin("dm-")), udev_id.end());
- udev_id.sort();
+ udev_id.remove_if(string_starts_with("dm-"));
y2mil("id:" << udev_id);
DmPartCo::setUdevData(udev_id);
@@ -119,26 +173,32 @@
DmraidCo::newP( DmPart*& dm, unsigned num, Partition* p )
{
y2mil( "num:" << num );
- dm = new Dmraid( *this, num, p );
+ dm = new Dmraid( *this, getPartName(num), getPartDevice(num), num, p );
}
-void DmraidCo::addPv( Pv*& p )
+
+ void
+ DmraidCo::addPv(const Pv& pv)
{
- PeContainer::addPv( p );
- if( !deleted() )
- getStorage()->setUsedBy( p->device, UB_DMRAID, name() );
- p = new Pv;
+ PeContainer::addPv(pv);
+ if (!deleted())
+ getStorage()->addUsedBy(pv.device, UB_DMRAID, device());
}
+
void DmraidCo::activate( bool val )
{
- y2milestone( "old active:%d val:%d", active, val );
+ if (getenv("LIBSTORAGE_NO_DMRAID") != NULL)
+ return;
+
+ y2mil("old active:" << active << " val:" << val);
if( active != val )
{
SystemCmd c;
if( val )
{
Dm::activate(true);
+ // option '-p' since udev creates the partition nodes
c.execute(DMRAIDBIN " -ay -p");
}
else
@@ -147,53 +207,33 @@
}
active = val;
}
- }
-
-
- bool
- DmraidCo::isActivated(const string& name)
- {
- SystemCmd c(DMSETUPBIN " table " + quote(name));
- return c.retcode() == 0 && c.numLines() >= 1 && isdigit(c.stdout()[0]);
+ Storage::waitForDevice();
}
list<string>
- DmraidCo::getRaids()
+ DmraidCo::getRaids(SystemInfo& systeminfo)
{
- list<string> l;
+ list<string> l;
- SystemCmd c(DMRAIDBIN " -s -c -c -c");
- for( unsigned i=0; i=3 )
- {
- list<string>::const_iterator ci = sl.begin();
- if( !ci->empty()
- && ci->find( "/dev/" )==string::npos
- && find( l.begin(), l.end(), *ci )==l.end())
- {
- if (isActivated(*ci))
- {
- l.push_back( *ci );
- }
- else
- {
- y2mil("ignoring inactive dmraid " << *ci);
- }
- }
- }
- }
+ list<string> entries = systeminfo.getCmdDmraid().getEntries();
+ for (list<string>::const_iterator it = entries.begin(); it != entries.end(); ++it)
+ {
+ CmdDmsetup::Entry entry;
+ if (systeminfo.getCmdDmsetup().getEntry(*it, entry) && entry.segments > 0)
+ l.push_back(*it);
+ else
+ y2mil("ignoring inactive dmraid " << *it);
+ }
- y2mil("detected dmraids " << l);
- return l;
+ y2mil("detected dmraids " << l);
+ return l;
}
-string DmraidCo::removeText( bool doing ) const
+Text DmraidCo::removeText( bool doing ) const
{
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by a name (e.g. pdc_igeeeadj),
@@ -208,31 +248,10 @@
}
-string DmraidCo::setDiskLabelText( bool doing ) const
- {
- string txt;
- string d = nm;
- if( doing )
- {
- // displayed text during action, %1$s is replaced by raid name (e.g. pdc_igeeeadj),
- // %2$s is replaced by label name (e.g. msdos)
- txt = sformat( _("Setting disk label of raid %1$s to %2$s"),
- d.c_str(), labelName().c_str() );
- }
- else
- {
- // displayed text before action, %1$s is replaced by raid name (e.g. pdc_igeeeadj),
- // %2$s is replaced by label name (e.g. msdos)
- txt = sformat( _("Set disk label of raid %1$s to %2$s"),
- d.c_str(), labelName().c_str() );
- }
- return( txt );
- }
-
int
DmraidCo::doRemove()
{
- y2milestone( "Raid:%s", name().c_str() );
+ y2mil("Raid:" << name());
int ret = 0;
if( deleted() )
{
@@ -271,33 +290,40 @@
tinfo.p = info;
}
-namespace storage
-{
std::ostream& operator<< (std::ostream& s, const DmraidCo& d )
{
- s << *((DmPartCo*)&d);
+ s << dynamic_cast(d);
s << " Cont:" << d.controller
<< " RType:" << d.raidtype;
return( s );
}
-}
-string DmraidCo::getDiffString( const Container& d ) const
+ void
+ DmraidCo::logDifference(std::ostream& log, const DmraidCo& rhs) const
{
- string log = DmPartCo::getDiffString( d );
- const DmraidCo * p = dynamic_cast(&d);
- if( p )
- {
- if( controller!=p->controller )
- log += " controller:" + controller + "-->" + p->controller;
- if( raidtype!=p->raidtype )
- log += " raidtype:" + raidtype + "-->" + p->raidtype;
- }
- return( log );
+ DmPartCo::logDifference(log, rhs);
+
+ logDiff(log, "controller", controller, rhs.controller);
+ logDiff(log, "raidtype", raidtype, rhs.raidtype);
}
+
+ void
+ DmraidCo::logDifferenceWithVolumes(std::ostream& log, const Container& rhs_c) const
+ {
+ const DmraidCo& rhs = dynamic_cast(rhs_c);
+
+ logDifference(log, rhs);
+ log << endl;
+
+ ConstDmPartPair pp = dmpartPair();
+ ConstDmPartPair pc = rhs.dmpartPair();
+ logVolumesDifference(log, pp.begin(), pp.end(), pc.begin(), pc.end());
+ }
+
+
bool DmraidCo::equalContent( const Container& rhs ) const
{
bool ret = Container::equalContent(rhs);
@@ -310,12 +336,7 @@
return( ret );
}
-DmraidCo::DmraidCo( const DmraidCo& rhs ) : DmPartCo(rhs)
- {
- raidtype = rhs.raidtype;
- controller = rhs.controller;
- }
-
-void DmraidCo::logData( const string& Dir ) {;}
bool DmraidCo::active = false;
+
+}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmraidCo.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmraidCo.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmraidCo.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/DmraidCo.h Tue May 17 13:39:44 2011
@@ -25,26 +25,50 @@
#include <list>
-#include "y2storage/DmPartCo.h"
-#include "y2storage/Dmraid.h"
+#include "storage/DmPartCo.h"
+#include "storage/Dmraid.h"
namespace storage
{
-
class Storage;
-class SystemCmd;
-class ProcPart;
-class Region;
+ class SystemInfo;
+
+
+ class CmdDmraid
+ {
+
+ public:
+
+ CmdDmraid();
+
+ struct Entry
+ {
+ string raidtype;
+ string controller;
+ list<string> devices;
+ };
+
+ list<string> getEntries() const;
+
+ bool getEntry(const string& name, Entry& entry) const;
+
+ private:
+
+ typedef map::const_iterator const_iterator;
+
+ map data;
+
+ };
+
class DmraidCo : public DmPartCo
{
friend class Storage;
public:
- DmraidCo( Storage * const s, const string& Name, ProcPart& ppart );
- DmraidCo( Storage * const s, const string& Name, unsigned num,
- unsigned long long Size, ProcPart& ppart );
- DmraidCo( const DmraidCo& rhs );
+
+ DmraidCo(Storage* s, const string& name, const string& device, SystemInfo& systeminfo);
+ DmraidCo(const DmraidCo& c);
virtual ~DmraidCo();
static storage::CType staticType() { return storage::DMRAID; }
@@ -53,8 +77,9 @@
void setUdevData(const list<string>& id);
bool equalContent( const Container& rhs ) const;
- string getDiffString( const Container& d ) const;
- DmraidCo& operator= ( const DmraidCo& rhs );
+
+ void logDifference(std::ostream& log, const DmraidCo& rhs) const;
+ virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
protected:
@@ -106,32 +131,28 @@
return( ConstDmraidIter( DmraidCPIterator( p, CheckDmraid, true )) );
}
- DmraidCo( Storage * const s, const string& File );
virtual void print( std::ostream& s ) const { s << *this; }
virtual Container* getCopy() const { return( new DmraidCo( *this ) ); }
- static void activate( bool val );
- void getRaidData( const string& name );
- void addRaid( const string& name );
- void addPv( Pv*& p );
+ static void activate(bool val);
+ void getRaidData(const string& name, SystemInfo& systeminfo);
+ void addPv(const Pv& pv);
void newP( DmPart*& dm, unsigned num, Partition* p );
- string removeText( bool doing ) const;
- string setDiskLabelText( bool doing ) const;
- static string undevName( const string& name );
+ Text removeText( bool doing ) const;
- static bool isActivated(const string& name);
- static list<string> getRaids();
-
- static bool raidNotDeleted( const Dmraid&d ) { return( !d.deleted() ); }
+ static list<string> getRaids(SystemInfo& systeminfo);
int doRemove();
- void logData( const string& Dir );
-
string raidtype;
string controller;
- static bool active;
+ static bool active;
+
+ private:
+
+ DmraidCo& operator=(const DmraidCo&); // disallow
+
};
}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Enum.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Enum.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Enum.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Enum.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include "storage/Enum.h"
+#include "storage/StorageTmpl.h"
+
+
+namespace storage
+{
+
+ // strings must match /etc/fstab
+ static const string fs_type_names[] = {
+ "unknown", "reiserfs", "ext2", "ext3", "ext4", "btrfs", "vfat", "xfs", "jfs", "hfs",
+ "ntfs-3g", "swap", "hfsplus", "nfs", "nfs4", "tmpfs", "none"
+ };
+
+ const vector<string> EnumInfo<FsType>::names(fs_type_names, fs_type_names +
+ lengthof(fs_type_names));
+
+
+ static const string partition_type_names[] = {
+ "primary", "extended", "logical", "any"
+ };
+
+ const vector<string> EnumInfo<PartitionType>::names(partition_type_names, partition_type_names +
+ lengthof(partition_type_names));
+
+
+ static const string mount_by_names[] = {
+ "device", "uuid", "label", "id", "path"
+ };
+
+ const vector<string> EnumInfo<MountByType>::names(mount_by_names, mount_by_names +
+ lengthof(mount_by_names));
+
+
+ static const string encrypt_names[] = {
+ "none", "twofish256", "twofish", "twofishSL92", "luks", "unknown"
+ };
+
+ const vector<string> EnumInfo<EncryptType>::names(encrypt_names, encrypt_names +
+ lengthof(encrypt_names));
+
+
+ // strings must match /proc/mdstat
+ static const string md_type_names[] = {
+ "unknown", "raid0", "raid1", "raid5", "raid6", "raid10", "multipath"
+ };
+
+ const vector<string> EnumInfo<MdType>::names(md_type_names, md_type_names +
+ lengthof(md_type_names));
+
+
+ // strings must match "mdadm --parity" option
+ static const string md_parity_names[] = {
+ "default", "left-asymmetric", "left-symmetric", "right-asymmetric", "right-symmetric",
+ "parity-first", "parity-last",
+ "left-asymmetric-6", "left-symmetric-6", "right-asymmetric-6", "right-symmetric-6",
+ "parity-first-6",
+ "n2", "o2", "f2", "n3", "o3", "f3"
+ };
+
+ const vector<string> EnumInfo<MdParity>::names(md_parity_names, md_parity_names +
+ lengthof(md_parity_names));
+
+
+ // strings must match /sys/block/md*/md/array_state
+ static const string md_array_state_names[] = {
+ "unknown", "clear", "inactive", "suspended", "readonly", "read-auto", "clean", "active",
+ "write-pending", "active-idle"
+ };
+
+ const vector<string> EnumInfo<MdArrayState>::names(md_array_state_names, md_array_state_names +
+ lengthof(md_array_state_names));
+
+
+ static const string used_by_type_names[] = {
+ "NONE", "LVM", "MD", "MDPART", "DM", "DMRAID", "DMMULTIPATH", "BTRFS"
+ };
+
+ const vector<string> EnumInfo<UsedByType>::names(used_by_type_names, used_by_type_names +
+ lengthof(used_by_type_names));
+
+
+ static const string c_type_names[] = {
+ "UNKNOWN", "DISK", "MD", "LOOP", "LVM", "DM", "DMRAID", "NFS", "DMMULTIPATH", "MDPART", "BTRFS", "TMPFS"
+ };
+
+ const vector<string> EnumInfo<CType>::names(c_type_names, c_type_names +
+ lengthof(c_type_names));
+
+
+ static const string transport_names[] = {
+ "UNKNOWN", "SBP", "ATA", "FC", "iSCSI", "SAS", "SATA", "SPI", "USB"
+ };
+
+ const vector<string> EnumInfo<Transport>::names(transport_names, transport_names +
+ lengthof(transport_names));
+
+
+ static const string imsm_driver_names[] = {
+ "UNDECIDED", "DMRAID", "MDADM"
+ };
+
+ const vector<string> EnumInfo<ImsmDriver>::names(imsm_driver_names, imsm_driver_names +
+ lengthof(imsm_driver_names));
+
+
+ // strings must match "parted --align" option
+ static const string part_align_names[] = {
+ "optimal", "cylinder"
+ };
+
+ const vector<string> EnumInfo<PartAlign>::names(part_align_names, part_align_names +
+ lengthof(part_align_names));
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Enum.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Enum.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Enum.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Enum.h Tue May 17 13:39:44 2011
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2010 Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef ENUM_H
+#define ENUM_H
+
+
+#include
+#include <string>
+#include <vector>
+#include <algorithm>
+
+#include "storage/StorageInterface.h"
+#include "storage/AppUtil.h"
+
+
+namespace storage
+{
+ using std::string;
+ using std::vector;
+
+
+ template <typename EnumType> struct EnumInfo {};
+
+ template <> struct EnumInfo<FsType> { static const vector<string> names; };
+ template <> struct EnumInfo<PartitionType> { static const vector<string> names; };
+ template <> struct EnumInfo<MountByType> { static const vector<string> names; };
+ template <> struct EnumInfo<EncryptType> { static const vector<string> names; };
+ template <> struct EnumInfo<MdType> { static const vector<string> names; };
+ template <> struct EnumInfo<MdParity> { static const vector<string> names; };
+ template <> struct EnumInfo<MdArrayState> { static const vector<string> names; };
+ template <> struct EnumInfo<UsedByType> { static const vector<string> names; };
+ template <> struct EnumInfo<CType> { static const vector<string> names; };
+ template <> struct EnumInfo<Transport> { static const vector<string> names; };
+ template <> struct EnumInfo<ImsmDriver> { static const vector<string> names; };
+ template <> struct EnumInfo<PartAlign> { static const vector<string> names; };
+
+
+ template <typename EnumType>
+ const string& toString(EnumType value)
+ {
+ static_assert(std::is_enum<EnumType>::value, "not enum");
+
+ const vector<string>& names = EnumInfo<EnumType>::names;
+
+ // Comparisons must not be done with type of enum since the enum may
+ // define comparison operators.
+ assert((size_t)(value) < names.size());
+
+ return names[value];
+ }
+
+
+ template <typename EnumType>
+ bool toValue(const string& str, EnumType& value, bool log_error = true)
+ {
+ static_assert(std::is_enum<EnumType>::value, "not enum");
+
+ const vector<string>& names = EnumInfo<EnumType>::names;
+
+ vector<string>::const_iterator it = find(names.begin(), names.end(), str);
+
+ if (it == names.end())
+ {
+ if (log_error)
+ y2err("converting '" << str << "' to enum failed");
+ return false;
+ }
+
+ value = EnumType(it - names.begin());
+ return true;
+ }
+
+
+ template <typename EnumType>
+ EnumType toValueWithFallback(const string& str, EnumType fallback, bool log_error = true)
+ {
+ EnumType value;
+
+ if (toValue(str, value, log_error))
+ return value;
+
+ return fallback;
+ }
+
+}
+
+
+#endif
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcFstab.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcFstab.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcFstab.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcFstab.cc Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -19,31 +19,31 @@
* find current contact information at www.novell.com.
*/
-// Maintainer: fehr@suse.de
-/*
- Textdomain "storage"
-*/
#include <fstream>
#include <algorithm>
-#include "y2storage/AppUtil.h"
-#include "y2storage/StorageTypes.h"
-#include "y2storage/AsciiFile.h"
-#include "y2storage/Regex.h"
-#include "y2storage/StorageTmpl.h"
-#include "y2storage/Volume.h"
-#include "y2storage/EtcFstab.h"
-
-using namespace storage;
-using namespace std;
-
-EtcFstab::EtcFstab( const string& pfx, bool rootMounted ) : prefix(pfx)
- {
- y2milestone( "prefix:%s rootMounted:%d", pfx.c_str(), rootMounted );
- if( rootMounted )
+#include "storage/AppUtil.h"
+#include "storage/StorageTypes.h"
+#include "storage/AsciiFile.h"
+#include "storage/Regex.h"
+#include "storage/StorageTmpl.h"
+#include "storage/Volume.h"
+#include "storage/EtcFstab.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+EtcFstab::EtcFstab(const string& pfx, bool rootMounted)
+ : prefix(pfx)
+{
+ y2mil("prefix:" << pfx << " rootMounted:" << rootMounted);
+ if (rootMounted)
readFiles();
- }
+}
void
EtcFstab::readFiles()
@@ -72,9 +72,9 @@
{
Entry *p = new Entry;
if( i!=l.end() )
- p->old.device = p->old.dentry = *i++;
+ p->old.device = p->old.dentry = fstabDecode(*i++);
if( i!=l.end() )
- p->old.mount = *i++;
+ p->old.mount = fstabDecode(*i++);
if( i!=l.end() )
{
p->old.fs = *i++;
@@ -83,8 +83,6 @@
p->old.dmcrypt = true;
p->old.encr = ENC_LUKS;
}
- else if( p->old.fs=="ntfs-3g" )
- p->old.fs=="ntfs";
}
if( i!=l.end() )
p->old.opts = splitString( *i++, "," );
@@ -124,11 +122,9 @@
if( i!=l.end() )
{
p->old.fs = *i++;
- if( p->old.fs=="ntfs-3g" )
- p->old.fs=="ntfs";
}
if( i!=l.end() )
- p->old.encr = Volume::toEncType( *i++ );
+ p->old.encr = toValueWithFallback(*i++, ENC_UNKNOWN);
if( i!=l.end() )
p->old.opts = splitString( *i++, "," );
p->nnew = p->old;
@@ -169,22 +165,21 @@
p->old.noauto = false;
p->old.encr = ENC_LUKS;
p->old.device = *i;
- list<string>::iterator li = p->old.opts.begin();
- while( li != p->old.opts.end() )
- {
- if( *li == "noauto" || *li == "nofail" )
- li = p->old.opts.erase(li);
- else
- ++li;
- }
+ p->old.opts.remove("nofail");
++i;
if( *i != "none" )
p->old.cr_key = *i;
+ p->old.tmpcrypt = p->old.cr_key == "/dev/urandom";
++i;
if( i!=l.end() )
{
if( *i != "none" )
p->old.cr_opts = *i;
+ list<string> tls = splitString( *i, "," );
+ p->old.noauto =
+ find( tls.begin(), tls.end(), "noauto" ) != tls.end();
+ if( p->old.noauto )
+ p->old.opts.push_back("noauto");
++i;
}
p->nnew = p->old;
@@ -194,9 +189,10 @@
}
mounts.close();
- y2milestone( "entries:%zd", co.size() );
+ y2mil("entries:" << co.size());
}
+
void
FstabEntry::calcDependent()
{
@@ -205,7 +201,7 @@
noauto = find( beg, end, "noauto" ) != end;
- list<string>::const_iterator i = find_if( beg, end, find_begin("loop") );
+ list<string>::const_iterator i = find_if( beg, end, string_starts_with("loop") );
if( i!=end )
{
loop = true;
@@ -215,36 +211,52 @@
loop_dev = i->substr( pos+1 );
}
}
- i = find_if( beg, end, find_begin("encryption=") );
+ i = find_if( beg, end, string_starts_with("encryption=") );
if( i!=end )
{
string::size_type pos = i->find("=");
if( pos!=string::npos )
{
- encr = Volume::toEncType( i->substr( pos+1 ) );
+ encr = toValueWithFallback(i->substr(pos + 1), ENC_UNKNOWN);
}
}
- if( device.find( "LABEL=" )==0 )
+
+ if (boost::starts_with(device, "LABEL="))
{
- mount_by = MOUNTBY_LABEL;
- device.erase();
+ mount_by = MOUNTBY_LABEL;
+ device.erase();
}
- else if( device.find( "UUID=" )==0 )
+ else if (boost::starts_with(device, "UUID="))
{
- mount_by = MOUNTBY_UUID;
- device.erase();
+ mount_by = MOUNTBY_UUID;
+ device.erase();
}
- else if( device.substr(0, 16) == "/dev/disk/by-id/" )
+ else if (boost::starts_with(device, "/dev/disk/by-id/"))
{
- mount_by = MOUNTBY_ID;
+ mount_by = MOUNTBY_ID;
}
- else if( device.substr(0, 18) == "/dev/disk/by-path/" )
+ else if (boost::starts_with(device, "/dev/disk/by-path/"))
{
- mount_by = MOUNTBY_PATH;
+ mount_by = MOUNTBY_PATH;
+ }
+ else if (boost::starts_with(device, "/dev/disk/by-label/"))
+ {
+ mount_by = MOUNTBY_LABEL;
+ }
+ else if (boost::starts_with(device, "/dev/disk/by-uuid/"))
+ {
+ mount_by = MOUNTBY_UUID;
}
+
dmcrypt = encr==ENC_LUKS;
- cryptotab = !noauto && encr!=ENC_NONE && !dmcrypt;
- crypttab = !noauto && dmcrypt;
+ cryptotab = encr!=ENC_NONE && !dmcrypt;
+ crypttab = dmcrypt;
+ }
+
+bool
+FstabEntry::optUser() const
+ {
+ return find( opts.begin(), opts.end(), "user" ) != opts.end();
}
bool
@@ -283,7 +295,7 @@
int EtcFstab::changeRootPrefix( const string& prfix )
{
- y2milestone( "new prefix:%s", prfix.c_str() );
+ y2mil("new prefix:" << prfix);
int ret = 0;
if( prfix != prefix )
{
@@ -311,58 +323,86 @@
i->nnew.device = i->old.device = device;
}
-bool
-EtcFstab::findUuidLabel( const string& uuid, const string& label,
- FstabEntry& entry ) const
- {
- y2milestone( "uuid:%s label:%s", uuid.c_str(), label.c_str() );
- list<Entry>::const_iterator i = co.end();
- if( !uuid.empty() )
- {
- string dev = "UUID=" + uuid;
- i = co.begin();
- while( i!=co.end() && i->nnew.dentry != dev )
- ++i;
+
+ bool
+ EtcFstab::findUuidLabel(const string& uuid, const string& label,
+ FstabEntry& entry) const
+ {
+ y2mil("uuid:" << uuid << " label:" << label);
+ list<Entry>::const_iterator i = co.end();
+ if (!uuid.empty())
+ {
+ string dentry = "UUID=" + uuid;
+ i = co.begin();
+ while (i != co.end() && i->nnew.dentry != dentry)
+ ++i;
}
- if( i==co.end() && !label.empty() )
+ if (i == co.end() && !uuid.empty())
{
- string dev = "LABEL=" + label;
- i = co.begin();
- while( i!=co.end() && i->nnew.dentry != dev )
- ++i;
+ string dentry = "/dev/disk/by-uuid/" + uuid;
+ i = co.begin();
+ while (i != co.end() && i->nnew.dentry != dentry)
+ ++i;
}
- if( i!=co.end())
- entry = i->nnew;
- y2mil("ret:" << (i != co.end()));
- return i != co.end();
+ if (i == co.end() && !label.empty())
+ {
+ string dentry = "LABEL=" + label;
+ i = co.begin();
+ while (i != co.end() && i->nnew.dentry != dentry)
+ ++i;
+ }
+ if (i == co.end() && !label.empty())
+ {
+ string dentry = "/dev/disk/by-label/" + udevEncode(label);
+ i = co.begin();
+ while (i != co.end() && i->nnew.dentry != dentry)
+ ++i;
+ }
+ if (i != co.end())
+ entry = i->nnew;
+ y2mil("ret:" << (i != co.end()));
+ return i != co.end();
}
-bool
-EtcFstab::findIdPath( const std::list<string>& id, const string& path,
- FstabEntry& entry ) const
+
+ bool
+ EtcFstab::findIdPath(const list<string>& id, const string& path, FstabEntry& entry ) const
{
- y2mil( "id:" << id << " path:" << path );
- list<Entry>::const_iterator i = co.begin();
- if( !id.empty() )
+ y2mil("id:" << id << " path:" << path);
+ list<Entry>::const_iterator i = co.end();
+
+ if (!id.empty())
{
- while( i!=co.end() &&
- find( id.begin(), id.end(), i->nnew.dentry )==id.end() )
- ++i;
+ for (list<string>::const_iterator j = id.begin(); j != id.end(); ++j)
+ {
+ const string full = "/dev/disk/by-id/" + *j;
+
+ i = co.begin();
+ while(i != co.end() && i->nnew.dentry != full)
+ ++i;
+
+ if (i != co.end())
+ break;
+ }
}
- else
- i = co.end();
- if( i==co.end() && !path.empty() )
+
+ if (i == co.end() && !path.empty())
{
- i = co.begin();
- while( i!=co.end() && i->nnew.dentry != path )
- ++i;
+ const string full = "/dev/disk/by-path/" + path;
+
+ i = co.begin();
+ while(i != co.end() && i->nnew.dentry != full)
+ ++i;
}
- if( i!=co.end())
- entry = i->nnew;
- y2mil("ret:" << (i != co.end()));
- return( i!=co.end() );
+
+ bool ret = i != co.end();
+ if (ret)
+ entry = i->nnew;
+ y2mil("ret:" << ret);
+ return ret;
}
+
int EtcFstab::removeEntry( const FstabEntry& entry )
{
y2mil("dentry:" << entry.dentry << " mount:" << entry.mount);
@@ -407,7 +447,7 @@
int EtcFstab::addEntry( const FstabChange& entry )
{
- y2mil("dentry:" << entry.dentry << " mount:" << entry.mount);
+ y2mil("dentry:" << entry.dentry << " mount:" << entry.mount);
Entry e;
e.op = Entry::ADD;
e.nnew = entry;
@@ -419,78 +459,78 @@
AsciiFile* EtcFstab::findFile( const FstabEntry& e, AsciiFile*& fstab,
AsciiFile*& cryptotab, int& lineno ) const
{
- y2mil("dentry:" << e.dentry << " mount:" << e.mount << " fstab:" << fstab <<
- " cryptotab:" << cryptotab);
+ y2mil("dentry:" << e.dentry << " mount:" << e.mount << " fstab:" << fstab <<
+ " cryptotab:" << cryptotab);
AsciiFile* ret=NULL;
- Regex *fi = NULL;
+ string reg;
if( e.cryptotab )
{
if( cryptotab==NULL )
- cryptotab = new AsciiFile( prefix + "/cryptotab" );
+ cryptotab = new AsciiFile( prefix + "/cryptotab", true );
ret = cryptotab;
- fi = new Regex( "[ \t]" + e.dentry + "[ \t]" );
+ reg = "[ \t]" + boost::replace_all_copy(fstabEncode(e.dentry), "\\", "\\\\") + "[ \t]";
}
else
{
if( fstab==NULL )
fstab = new AsciiFile( prefix + "/fstab" );
ret = fstab;
- fi = new Regex( "^[ \t]*" + e.dentry + "[ \t]" );
+ reg = "^[ \t]*" + boost::replace_all_copy(fstabEncode(e.dentry), "\\", "\\\\") + "[ \t]";
}
- lineno = ret->find( 0, *fi );
- delete fi;
- y2milestone( "fstab:%p cryptotab:%p lineno:%d", fstab, cryptotab, lineno );
+ if( e.dentry != "tmpfs" )
+ lineno = ret->find_if_idx(regex_matches(reg));
+ else
+ {
+ reg = "[ \t]+" + boost::replace_all_copy(fstabEncode(e.mount), "\\", "\\\\") + "[ \t]";
+ lineno = ret->find_if_idx(regex_matches(reg));
+ }
+ y2mil("fstab:" << fstab << " cryptotab:" << cryptotab << " lineno:" << lineno);
return( ret );
}
int EtcFstab::findPrefix( const AsciiFile& tab, const string& mount ) const
{
- bool crypto = tab.fileName().find( "/cryptotab" )!=string::npos;
- y2mil("file:" << tab.fileName() << " mount:" << mount << " crypto:" << crypto);
+ bool crypto = tab.name().find( "/cryptotab" )!=string::npos;
+ y2mil("file:" << tab.name() << " mount:" << mount << " crypto:" << crypto);
string reg = "^[ \t]*[^ \t]+";
if( crypto )
reg += "[ \t]+[^ \t]+";
reg += "[ \t]+" + mount;
if( mount.length()>0 && mount[mount.length()-1] != '/' )
reg += "/";
- Regex *fi = new Regex( reg );
- int lineno = tab.find( 0, *fi );
- delete fi;
- y2milestone( "reg:%s lineno:%d", reg.c_str(), lineno );
+ int lineno = tab.find_if_idx(regex_matches(reg));
+ y2mil("reg:" << reg << " lineno:" << lineno);
return( lineno );
}
bool EtcFstab::findCrtab( const FstabEntry& e, const AsciiFile& tab,
int& lineno ) const
{
- y2milestone( "dev:%s", e.device.c_str() );
+ y2mil("dev:" << e.device);
string reg = "^[ \t]*[^ \t]+[ \t]+" + e.device + "[ \t]";
- Regex fi( reg );
- lineno = tab.find( 0, fi );
+ lineno = tab.find_if_idx(regex_matches(reg));
if( lineno<0 )
{
reg = "^[ \t]*" + e.dentry + "[ \t]";
- Regex fil( reg );
- lineno = tab.find( 0, fil );
+ lineno = tab.find_if_idx(regex_matches(reg));
}
- y2milestone( "reg:%s lineno:%d", reg.c_str(), lineno );
+ y2mil("reg:" << reg << " lineno:" << lineno);
return( lineno>=0 );
}
bool EtcFstab::findCrtab( const string& dev, const AsciiFile& tab,
int& lineno ) const
{
- y2milestone( "dev:%s", dev.c_str() );
+ y2mil("dev:" << dev.c_str());
string reg = "^[ \t]*[^ \t]+[ \t]+" + dev + "[ \t]";
- Regex fi( reg );
- lineno = tab.find( 0, fi );
- y2milestone( "reg:%s lineno:%d", reg.c_str(), lineno );
+ lineno = tab.find_if_idx(regex_matches(reg));
+ y2mil("reg:" << reg << " lineno:" << lineno);
return( lineno>=0 );
}
-list<string> EtcFstab::makeStringList(const FstabEntry& e) const
+static list<string> makeStringList(const FstabEntry& e)
{
- list<string> ls;
+ list<string> ls;
if( e.cryptotab )
{
ls.push_back( e.loop_dev );
@@ -506,10 +546,10 @@
ls.push_back( (e.fs!="ntfs")?e.fs:"ntfs-3g" );
if( e.cryptotab )
{
- ls.push_back( Volume::encTypeString(e.encr) );
+ ls.push_back(toString(e.encr));
}
- ls.push_back( mergeString( e.opts, "," ) );
- if( e.dmcrypt && e.mount!="swap" )
+ ls.push_back( boost::join( e.opts, "," ) );
+ if( e.dmcrypt && e.mount!="swap" )
{
if( find( e.opts.begin(), e.opts.end(), "nofail" )==e.opts.end() )
{
@@ -524,11 +564,11 @@
ls.push_back( decString(e.freq) );
ls.push_back( decString(e.passno) );
}
- return ls;
+ return ls;
}
string EtcFstab::createLine( const list<string>& ls, unsigned fields,
- unsigned* flen ) const
+ const unsigned* flen ) const
{
string ret;
unsigned count=0;
@@ -536,7 +576,7 @@
{
if( i != ls.begin() )
ret += " ";
- ret += *i;
+ ret += fstabEncode(*i);
if( countsize()size(), ' ' );
@@ -551,30 +591,31 @@
{
y2mil("dentry:" << e.dentry << " mount:" << e.mount << " device:" << e.device);
const list<string> ls = makeStringList(e);
- y2mil( "list:" << ls );
unsigned max_fields = e.cryptotab ? lengthof(cryptotabFields)
: lengthof(fstabFields);
- unsigned* fields = e.cryptotab ? cryptotabFields : fstabFields;
+ const unsigned* fields = e.cryptotab ? cryptotabFields : fstabFields;
return createLine(ls, max_fields, fields);
}
-list<string> EtcFstab::makeCrStringList(const FstabEntry& e) const
+static list<string> makeCrStringList(const FstabEntry& e)
{
- list<string> ls;
+ list<string> ls;
ls.push_back( e.dentry.substr(e.dentry.rfind( '/' )+1) );
string tmp = e.device;
ls.push_back( tmp );
tmp = e.cr_key;
if( e.tmpcrypt )
tmp = "/dev/urandom";
+ if( !e.tmpcrypt && tmp=="/dev/urandom" )
+ tmp.clear();
ls.push_back( tmp.empty()?"none":tmp );
tmp = e.cr_opts;
list<string>::iterator i;
list<string> tls = splitString( tmp );
- if( e.mount=="swap" &&
+ if( e.mount=="swap" && e.tmpcrypt &&
find( tls.begin(), tls.end(), "swap" )==tls.end() )
tls.push_back("swap");
- else if( e.mount!="swap" &&
+ else if( (e.mount!="swap"||!e.tmpcrypt) &&
(i=find( tls.begin(), tls.end(), "swap" ))!=tls.end() )
tls.erase(i);
bool need_tmp = e.tmpcrypt && e.mount!="swap";
@@ -582,48 +623,52 @@
tls.push_back("tmp");
else if( !need_tmp && (i=find( tls.begin(), tls.end(), "tmp" ))!=tls.end() )
tls.erase(i);
- tmp = mergeString( tls, "," );
+ if( !e.noauto && (i=find( tls.begin(), tls.end(), "noauto" ))!=tls.end() )
+ tls.erase(i);
+ else if( e.noauto && (i=find( tls.begin(), tls.end(), "noauto" ))==tls.end() )
+ tls.push_back("noauto");
+ tmp = boost::join( tls, "," );
ls.push_back( tmp.empty()?"none":tmp );
return ls;
}
string EtcFstab::createCrtabLine( const FstabEntry& e ) const
{
- y2mil("dentry:" << e.dentry << " mount:" << e.mount << " device:" << e.device);
- const list<string> ls = makeCrStringList(e);
- return createLine(ls, lengthof(crypttabFields), crypttabFields);
+ y2mil("dentry:" << e.dentry << " mount:" << e.mount << " device:" << e.device);
+ const list<string> ls = makeCrStringList(e);
+ return createLine(ls, lengthof(crypttabFields), crypttabFields);
}
-void EtcFstab::getFileBasedLoops( const string& prefix, list<FstabEntry>& l ) const
+
+void
+EtcFstab::getFileBasedLoops(const string& prefix, list<FstabEntry>& l) const
{
l.clear();
- list<Entry>::const_iterator i = co.begin();
- while( i!=co.end() )
+ for (list<Entry>::const_iterator i = co.begin(); i != co.end(); ++i)
{
- if( i->op==Entry::NONE )
+ if (i->op == Entry::NONE)
{
string lfile = prefix + i->old.device;
- if( checkNormalFile( lfile ))
- l.push_back( i->old );
+ if (checkNormalFile(lfile))
+ l.push_back(i->old);
}
- ++i;
}
}
-void EtcFstab::getEntries( list<FstabEntry>& l ) const
+
+list<FstabEntry>
+EtcFstab::getEntries() const
{
- l.clear();
- list<Entry>::const_iterator i = co.begin();
- while( i!=co.end() )
+ list<FstabEntry> ret;
+ for (list<Entry>::const_iterator i = co.begin(); i != co.end(); ++i)
{
- if( i->op==Entry::NONE )
- {
- l.push_back( i->old );
- }
- ++i;
+ if (i->op == Entry::NONE)
+ ret.push_back(i->old);
}
+ return ret;
}
+
string EtcFstab::updateLine( const list<string>& ol,
const list<string>& nl, const string& oldline ) const
{
@@ -669,38 +714,36 @@
return( line );
}
-static void printFile( const string& fname )
- {
- y2mil( "name:" << fname );
- ifstream file( fname.c_str() );
- classic(file);
- string line;
- int count = 1;
- getline( file, line );
- while( file.good() )
- {
- y2mil( "line:" << count++ << " \"" << line << "\"" );
- getline( file, line );
- }
- file.close();
+void EtcFstab::updateTabLine( list<string>(*fnc)(const FstabEntry&),
+ const FstabEntry& old, const FstabEntry& nnew,
+ string& line ) const
+ {
+ const list<string> nl = (*fnc)(nnew);
+ const list<string> ol = (*fnc)(old);
+ y2mil( "old line:" << line );
+ line = updateLine( ol, nl, line );
+ y2mil( "new line:" << line );
}
int EtcFstab::flush()
{
int ret = 0;
- list<Entry>::iterator i = co.begin();
AsciiFile *fstab = NULL;
AsciiFile *cryptotab = NULL;
AsciiFile *cur = NULL;
- AsciiFile crypttab( prefix + "/crypttab" );
- int lineno;
- if( i!=co.end() && !checkDir( prefix ) )
+ AsciiFile crypttab( prefix + "/crypttab", true );
+ if (!co.empty() && !checkDir(prefix))
createPath( prefix );
+
+ list<Entry>::iterator i = co.begin();
while( i!=co.end() && ret==0 )
{
switch( i->op )
{
case Entry::REMOVE:
+ {
+ y2mil( "REMOVE:" << i->old.device );
+ int lineno;
cur = findFile( i->old, fstab, cryptotab, lineno );
if( lineno>=0 )
{
@@ -718,8 +761,12 @@
ret = FSTAB_REMOVE_ENTRY_NOT_FOUND;
}
i = co.erase( i );
- break;
+ } break;
+
case Entry::UPDATE:
+ {
+ y2mil( "UPDATE:" << i->nnew.device );
+ int lineno;
cur = findFile( i->old, fstab, cryptotab, lineno );
if( lineno<0 )
cur = findFile( i->nnew, fstab, cryptotab, lineno );
@@ -735,11 +782,9 @@
}
else if( !i->nnew.mount.empty() )
{
- line = (*cur)[lineno];
- const list<string> nl = makeStringList(i->nnew);
- const list<string> ol = makeStringList(i->old);
- line = updateLine( ol, nl, line );
- (*cur)[lineno] = line;
+ y2mil( "lineno:" << lineno );
+ updateTabLine( makeStringList,
+ i->old, i->nnew, (*cur)[lineno] );
}
else
{
@@ -754,11 +799,9 @@
if( findCrtab( i->old, crypttab, lineno ) ||
findCrtab( i->nnew, crypttab, lineno ))
{
- line = crypttab[lineno];
- const list<string> nl = makeCrStringList(i->nnew);
- const list<string> ol = makeCrStringList(i->old);
- line = updateLine( ol, nl, line );
- crypttab[lineno] = line;
+ y2mil( "lineno:" << lineno );
+ updateTabLine( makeCrStringList,
+ i->old, i->nnew, crypttab[lineno] );
}
else
crypttab.append( line );
@@ -768,18 +811,27 @@
}
else if( findCrtab( i->nnew, crypttab, lineno ))
{
+ int oldln;
string line = createTabLine( i->nnew );
if (!i->nnew.mount.empty())
fstab->append( line );
if( i->old.crypttab > i->nnew.crypttab &&
- findCrtab( i->old, crypttab, lineno ))
- crypttab.remove( lineno, 1 );
+ findCrtab( i->old, crypttab, oldln ))
+ crypttab.remove( oldln, 1 );
+ else if( i->nnew.crypttab )
+ {
+ updateTabLine( makeCrStringList,
+ i->old, i->nnew, crypttab[oldln] );
+ }
}
else
ret = FSTAB_UPDATE_ENTRY_NOT_FOUND;
- break;
+ } break;
+
case Entry::ADD:
{
+ int lineno;
+ y2mil( "ADD:" << i->nnew.device );
cur = findFile( i->nnew, fstab, cryptotab, lineno );
string line = createTabLine( i->nnew );
string before_dev;
@@ -793,10 +845,10 @@
cur->insert( lineno, line );
}
else
- {
+ {
if (!i->nnew.mount.empty())
cur->append( line );
- }
+ }
}
else
{
@@ -822,8 +874,8 @@
}
i->old = i->nnew;
i->op = Entry::NONE;
- }
- break;
+ } break;
+
default:
break;
}
@@ -831,28 +883,29 @@
}
if( fstab != NULL )
{
- fstab->updateFile();
+ fstab->save();
delete( fstab );
}
if( cryptotab != NULL )
{
- if( !cryptotab->removeIfEmpty() )
- cryptotab->updateFile();
+ cryptotab->save();
delete( cryptotab );
}
- if( !crypttab.removeIfEmpty() )
- crypttab.updateFile();
- printFile( prefix + "/fstab" );
- printFile( prefix + "/cryptotab" );
- printFile( prefix + "/crypttab" );
+ if( true )
+ {
+ crypttab.save();
+ }
+ AsciiFile(prefix + "/fstab").logContent();
+ AsciiFile(prefix + "/cryptotab").logContent();
+ AsciiFile(prefix + "/crypttab").logContent();
y2mil("ret:" << ret);
return( ret );
}
-string EtcFstab::addText( bool doing, bool crypto, const string& mp ) const
+Text EtcFstab::addText( bool doing, bool crypto, const string& mp ) const
{
const char* file = crypto?"/etc/cryptotab":"/etc/fstab";
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by mount point e.g. /home
@@ -870,10 +923,10 @@
return( txt );
}
-string EtcFstab::updateText( bool doing, bool crypto, const string& mp ) const
+Text EtcFstab::updateText( bool doing, bool crypto, const string& mp ) const
{
const char* file = crypto?"/etc/cryptotab":"/etc/fstab";
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by mount point e.g. /home
@@ -891,10 +944,10 @@
return( txt );
}
-string EtcFstab::removeText( bool doing, bool crypto, const string& mp ) const
+Text EtcFstab::removeText( bool doing, bool crypto, const string& mp ) const
{
const char* file = crypto?"/etc/cryptotab":"/etc/fstab";
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by mount point e.g. /home
@@ -912,13 +965,88 @@
return( txt );
}
-bool
-FstabEntry::optUser() const
+
+ FstabEntry& FstabEntry::operator=(const FstabChange& rhs)
{
- return find( opts.begin(), opts.end(), "user" ) != opts.end();
+ device = rhs.device; dentry = rhs.dentry; mount = rhs.mount;
+ fs = rhs.fs; opts = rhs.opts; freq = rhs.freq; passno = rhs.passno;
+ loop_dev = rhs.loop_dev; encr = rhs.encr; tmpcrypt = rhs.tmpcrypt;
+ calcDependent();
+ return *this;
+ }
+
+
+ FstabChange& FstabChange::operator=(const FstabEntry& rhs)
+ {
+ device = rhs.device; dentry = rhs.dentry; mount = rhs.mount;
+ fs = rhs.fs; opts = rhs.opts; freq = rhs.freq; passno = rhs.passno;
+ loop_dev = rhs.loop_dev; encr = rhs.encr; tmpcrypt = rhs.tmpcrypt;
+ return *this;
}
-unsigned EtcFstab::fstabFields[] = { 20, 20, 10, 21, 1, 1 };
-unsigned EtcFstab::cryptotabFields[] = { 11, 15, 20, 10, 10, 1 };
-unsigned EtcFstab::crypttabFields[] = { 15, 20, 10, 1 };
+ std::ostream& operator<<(std::ostream& s, const FstabEntry& v)
+ {
+ s << "device:" << v.device
+ << " dentry:" << v.dentry << " mount:" << v.mount
+ << " fs:" << v.fs << " opts:" << boost::join(v.opts, ",")
+ << " freq:" << v.freq << " passno:" << v.passno;
+ if( v.noauto )
+ s << " noauto";
+ if( v.cryptotab )
+ s << " cryptotab";
+ if( v.crypttab )
+ s << " crypttab";
+ if( v.tmpcrypt )
+ s << " tmpcrypt";
+ if( v.loop )
+ s << " loop";
+ if( v.dmcrypt )
+ s << " dmcrypt";
+ if( !v.loop_dev.empty() )
+ s << " loop_dev:" << v.loop_dev;
+ if( !v.cr_key.empty() )
+ s << " cr_key:" << v.cr_key;
+ if( !v.cr_opts.empty() )
+ s << " cr_opts:" << v.cr_opts;
+ if( v.encr != storage::ENC_NONE )
+ s << " encr:" << toString(v.encr);
+ return s;
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const FstabChange& v)
+ {
+ s << "device:" << v.device
+ << " dentry:" << v.dentry << " mount:" << v.mount
+ << " fs:" << v.fs << " opts:" << boost::join(v.opts, ",")
+ << " freq:" << v.freq << " passno:" << v.passno;
+ if( !v.loop_dev.empty() )
+ s << " loop_dev:" << v.loop_dev;
+ if( v.encr != storage::ENC_NONE )
+ s << " encr:" << toString(v.encr);
+ if( v.tmpcrypt )
+ s << " tmpcrypt";
+ return s;
+ }
+
+
+ string
+ EtcFstab::fstabEncode(const string& s)
+ {
+ return boost::replace_all_copy(s, " ", "\\040");
+ }
+
+
+ string
+ EtcFstab::fstabDecode(const string& s)
+ {
+ return boost::replace_all_copy(s, "\\040", " ");
+ }
+
+
+ const unsigned EtcFstab::fstabFields[] = { 20, 20, 10, 21, 1, 1 };
+ const unsigned EtcFstab::cryptotabFields[] = { 11, 15, 20, 10, 10, 1 };
+ const unsigned EtcFstab::crypttabFields[] = { 15, 20, 10, 1 };
+
+}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcFstab.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcFstab.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcFstab.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcFstab.h Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -25,12 +25,17 @@
#include <string>
#include <list>
-#include <map>
+#include
+
+#include "storage/StorageInterface.h"
+#include "storage/AppUtil.h"
-#include "y2storage/StorageInterface.h"
namespace storage
{
+ using std::string;
+ using std::list;
+
class AsciiFile;
struct FstabChange;
@@ -41,7 +46,9 @@
cryptotab(false), crypttab(false), tmpcrypt(false), encr(ENC_NONE),
mount_by(MOUNTBY_DEVICE) {}
- FstabEntry& operator=( const FstabChange& rhs );
+ explicit FstabEntry(const FstabChange& change) { *this = change; }
+
+ FstabEntry& operator=(const FstabChange& rhs);
friend std::ostream& operator<< (std::ostream& s, const FstabEntry &v );
@@ -68,50 +75,14 @@
bool optUser() const;
};
-inline std::ostream& operator<< (std::ostream& s, const FstabEntry &v )
- {
- s << "device:" << v.device
- << " dentry:" << v.dentry << " mount:" << v.mount
- << " fs:" << v.fs << " opts:" << mergeString( v.opts, "," )
- << " freq:" << v.freq << " passno:" << v.passno;
- if( v.noauto )
- s << " noauto";
- if( v.cryptotab )
- s << " cryptotab";
- if( v.crypttab )
- s << " crypttab";
- if( v.tmpcrypt )
- s << " tmpcrypt";
- if( v.loop )
- s << " loop";
- if( v.dmcrypt )
- s << " dmcrypt";
- if( !v.loop_dev.empty() )
- s << " loop_dev:" << v.loop_dev;
- if( !v.cr_key.empty() )
- s << " cr_key:" << v.cr_key;
- if( !v.cr_opts.empty() )
- s << " cr_opts:" << v.cr_opts;
- if( v.encr != storage::ENC_NONE )
- s << " encr:" << v.encr;
- return( s );
- }
struct FstabChange
{
FstabChange() : freq(0), passno(0), encr(ENC_NONE), tmpcrypt(false) {}
- FstabChange( const FstabEntry& e ) { *this = e; }
+ explicit FstabChange(const FstabEntry& entry) { *this = entry; }
- FstabChange& operator=( const FstabEntry& rhs )
- {
- device = rhs.device;
- dentry = rhs.dentry; mount = rhs.mount; fs = rhs.fs;
- opts = rhs.opts; freq = rhs.freq; passno = rhs.passno;
- loop_dev = rhs.loop_dev; encr = rhs.encr;
- tmpcrypt = rhs.tmpcrypt;
- return( *this );
- }
+ FstabChange& operator=(const FstabEntry& rhs);
friend std::ostream& operator<< (std::ostream& s, const FstabChange &v );
@@ -127,31 +98,6 @@
bool tmpcrypt;
};
-inline FstabEntry& FstabEntry::operator=( const FstabChange& rhs )
- {
- device = rhs.device;
- dentry = rhs.dentry; mount = rhs.mount; fs = rhs.fs;
- opts = rhs.opts; freq = rhs.freq; passno = rhs.passno;
- loop_dev = rhs.loop_dev; encr = rhs.encr;
- tmpcrypt = rhs.tmpcrypt;
- calcDependent();
- return( *this );
- }
-
-inline std::ostream& operator<< (std::ostream& s, const FstabChange &v )
- {
- s << "device:" << v.device
- << " dentry:" << v.dentry << " mount:" << v.mount
- << " fs:" << v.fs << " opts:" << mergeString( v.opts, "," )
- << " freq:" << v.freq << " passno:" << v.passno;
- if( !v.loop_dev.empty() )
- s << " loop_dev:" << v.loop_dev;
- if( v.encr != storage::ENC_NONE )
- s << " encr:" << v.encr;
- if( v.tmpcrypt )
- s << " tmpcrypt";
- return( s );
- }
class EtcFstab
{
@@ -160,24 +106,22 @@
bool findDevice( const string& dev, FstabEntry& entry ) const;
bool findDevice( const std::list<string>& dl, FstabEntry& entry ) const;
bool findMount( const string& mount, FstabEntry& entry ) const;
+ bool findMount( const string& mount ) const
+ { FstabEntry e; return( findMount( mount,e )); }
bool findUuidLabel( const string& uuid, const string& label,
FstabEntry& entry ) const;
- bool findIdPath( const std::list<string>& id, const string& path,
- FstabEntry& entry ) const;
+ bool findIdPath(const list<string>& id, const string& path, FstabEntry& entry) const;
void setDevice( const FstabEntry& entry, const string& device );
- int updateEntry( const string& dev, const string& mount,
- const string& fs, const string& opts="defaults" );
int updateEntry( const FstabChange& entry );
int addEntry( const FstabChange& entry );
int removeEntry( const FstabEntry& entry );
int changeRootPrefix( const string& prfix );
void getFileBasedLoops( const string& prefix, std::list<FstabEntry>& l ) const;
- void getEntries( std::list<FstabEntry>& l ) const;
- string addText( bool doing, bool crypto, const string& mp ) const;
- string updateText( bool doing, bool crypto, const string& mp ) const;
- string removeText( bool doing, bool crypto, const string& mp ) const;
+ list<FstabEntry> getEntries() const;
+ Text addText( bool doing, bool crypto, const string& mp ) const;
+ Text updateText( bool doing, bool crypto, const string& mp ) const;
+ Text removeText( bool doing, bool crypto, const string& mp ) const;
int flush();
- int findPrefix( const AsciiFile& tab, const string& mount ) const;
protected:
struct Entry
@@ -191,27 +135,33 @@
void readFiles();
+ int findPrefix( const AsciiFile& tab, const string& mount ) const;
+
AsciiFile* findFile( const FstabEntry& e, AsciiFile*& fstab,
AsciiFile*& cryptotab, int& lineno ) const;
+
bool findCrtab( const FstabEntry& e, const AsciiFile& crtab,
int& lineno ) const;
bool findCrtab( const string& device, const AsciiFile& crtab,
int& lineno ) const;
- list<string> makeStringList(const FstabEntry& e) const;
- list<string> makeCrStringList(const FstabEntry& e) const;
-
string updateLine( const std::list<string>& ol,
const std::list<string>& nl, const string& line ) const;
string createLine( const std::list<string>& ls, unsigned fields,
- unsigned* flen ) const;
+ const unsigned* flen ) const;
string createTabLine( const FstabEntry& e ) const;
string createCrtabLine( const FstabEntry& e ) const;
-
- static unsigned fstabFields[6];
- static unsigned cryptotabFields[6];
- static unsigned crypttabFields[6];
+ void updateTabLine( list<string>(*fnc)(const FstabEntry& e),
+ const FstabEntry& old, const FstabEntry& nnew,
+ string& line ) const;
+
+ static string fstabEncode(const string&);
+ static string fstabDecode(const string&);
+
+ static const unsigned fstabFields[6];
+ static const unsigned cryptotabFields[6];
+ static const unsigned crypttabFields[6];
string prefix;
std::list<Entry> co;
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcMdadm.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcMdadm.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcMdadm.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcMdadm.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include "storage/AppUtil.h"
+#include "storage/EtcMdadm.h"
+#include "storage/AsciiFile.h"
+#include "storage/StorageTypes.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ EtcMdadm::EtcMdadm(const Storage* sto, const string& prefix)
+ : sto(sto), mdadm(prefix + "/etc/mdadm.conf")
+ {
+ }
+
+
+ bool
+ EtcMdadm::updateEntry(const mdconf_info& info)
+ {
+ y2mil("uuid:" << info.uuid << " device:" << info.device);
+
+ if (info.uuid.empty())
+ {
+ y2err("empty UUID " << info);
+ return false;
+ }
+
+ if (info.container_present && info.container_uuid.empty())
+ {
+ y2err("empty UUID for container " << info);
+ return false;
+ }
+
+ if (info.container_present)
+ setArrayLine(ContLine(info), info.container_uuid);
+
+ setArrayLine(ArrayLine(info), info.uuid);
+
+ setDeviceLine("DEVICE containers partitions");
+
+ if (sto->hasIScsiDisks())
+ setAutoLine("AUTO -all");
+
+ mdadm.save();
+
+ return true;
+ }
+
+
+ bool
+ EtcMdadm::removeEntry(const string& uuid)
+ {
+ y2mil("uuid:" << uuid);
+
+ if (uuid.empty())
+ {
+ y2err("empty UUID");
+ return false;
+ }
+
+ vector<string>& lines = mdadm.lines();
+ vector<string>::iterator it = findArray(uuid);
+ if (it == lines.end())
+ {
+ y2war("line not found");
+ return false;
+ }
+
+ lines.erase(it);
+
+ mdadm.save();
+
+ return true;
+ }
+
+
+ void
+ EtcMdadm::setDeviceLine(const string& line)
+ {
+ vector<string>& lines = mdadm.lines();
+ vector<string>::iterator it = find_if(lines, string_starts_with("DEVICE"));
+ if (it == lines.end())
+ lines.insert(lines.begin(), line);
+ else
+ *it = line;
+ }
+
+
+ void
+ EtcMdadm::setAutoLine(const string& line)
+ {
+ vector<string>& lines = mdadm.lines();
+ vector<string>::iterator it = find_if(lines, string_starts_with("AUTO"));
+ if (it == lines.end())
+ lines.insert(lines.begin(), line);
+ else
+ *it = line;
+ }
+
+
+ void
+ EtcMdadm::setArrayLine(const string& line, const string& uuid)
+ {
+ vector<string>& lines = mdadm.lines();
+ vector<string>::iterator it = findArray(uuid);
+ if (it == lines.end())
+ lines.push_back(line);
+ else
+ *it = line;
+ }
+
+
+ string
+ EtcMdadm::ContLine(const mdconf_info& info) const
+ {
+ string line = "ARRAY";
+ line += " metadata=" + info.container_metadata;
+ line += " UUID=" + info.container_uuid;
+ return line;
+ }
+
+
+ string
+ EtcMdadm::ArrayLine(const mdconf_info& info) const
+ {
+ string line = "ARRAY " + info.device;
+ if (info.container_present)
+ {
+ line += " container=" + info.container_uuid;
+ line += " member=" + info.container_member;
+ }
+ line += " UUID=" + info.uuid;
+ return line;
+ }
+
+
+ vector<string>::iterator
+ EtcMdadm::findArray(const string& uuid)
+ {
+ vector<string>& lines = mdadm.lines();
+ for (vector<string>::iterator it = lines.begin(); it != lines.end(); ++it)
+ {
+ if (boost::starts_with(*it, "ARRAY"))
+ {
+ string tmp = getUuid(*it);
+ if (!tmp.empty() && tmp == uuid)
+ return it;
+ }
+ }
+
+ return lines.end();
+ }
+
+
+ string
+ EtcMdadm::getUuid(const string& line) const
+ {
+ string::size_type pos1 = line.find("UUID=");
+ if (pos1 == string::npos)
+ return "";
+
+ pos1 += 5;
+ string::size_type pos2 = line.find_first_not_of("0123456789abcdefABCDEF:", pos1);
+ return line.substr(pos1, pos2 - pos1);
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const EtcMdadm::mdconf_info& info)
+ {
+ s << "device:" << info.device << " uuid:" << info.uuid;
+
+ if (info.container_present)
+ {
+ s << " container_present container_uuid:" << info.container_uuid << " container_member:"
+ << info.container_member << " container_metadata:" << info.container_metadata;
+ }
+
+ return s;
+ }
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcMdadm.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcMdadm.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcMdadm.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/EtcMdadm.h Tue May 17 13:39:44 2011
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef ETC_MDADM_H
+#define ETC_MDADM_H
+
+#include <string>
+#include <map>
+
+#include "storage/AsciiFile.h"
+#include "storage/Storage.h"
+
+
+namespace storage
+{
+
+ class EtcMdadm
+ {
+
+ public:
+
+ EtcMdadm(const Storage* sto, const string& prefix = "");
+
+ // From this structure line 'ARRAY' will be build in config file.
+ // Not all fields are mandatory
+ // If container is present then container line will be build
+ // before volume line.
+ struct mdconf_info
+ {
+ mdconf_info() : container_present(false) {}
+
+ string device;
+ string uuid;
+
+ bool container_present;
+
+ /* following members only valid if container_present is true */
+ string container_member;
+ string container_metadata;
+ string container_uuid;
+
+ friend std::ostream& operator<<(std::ostream& s, const mdconf_info& info);
+ };
+
+ bool updateEntry(const mdconf_info& info);
+
+ bool removeEntry(const string& uuid);
+
+ protected:
+
+ void setDeviceLine(const string& line);
+ void setAutoLine(const string& line);
+ void setArrayLine(const string& line, const string& uuid);
+
+ string ContLine(const mdconf_info& info) const;
+ string ArrayLine(const mdconf_info& info) const;
+
+ vector<string>::iterator findArray(const string& uuid);
+
+ string getUuid(const string& line) const;
+
+ const Storage* sto;
+
+ AsciiFile mdadm;
+
+ };
+
+}
+
+
+#endif
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FilterIterator.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FilterIterator.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FilterIterator.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FilterIterator.h Tue May 17 13:39:44 2011
@@ -23,8 +23,8 @@
#ifndef FILTER_ITERATOR_H
#define FILTER_ITERATOR_H
-#include "y2storage/AppUtil.h"
-#include "y2storage/IterPair.h"
+#include "storage/AppUtil.h"
+#include "storage/IterPair.h"
namespace storage
{
@@ -42,7 +42,8 @@
FilterIterator() { }
- FilterIterator( const Iter& begin, const Iter& end, Pred f, bool setend=false ) :
+ template<class It>
+ FilterIterator( const It& begin, const It& end, Pred f, bool setend=false ) :
m_begin(begin), m_end(end), m_cur(begin), m_f(f)
{
initialize( setend );
@@ -103,11 +104,13 @@
{
return( &(*m_cur) );
}
- bool operator==(const FilterIterator& x) const
+ template <class Other>
+ bool operator==(const Other& x) const
{
return( m_cur == x.cur() );
}
- bool operator!=(const FilterIterator& x) const
+ template <class Other>
+ bool operator!=(const Other& x) const
{
return( m_cur != x.cur() );
}
@@ -117,7 +120,7 @@
Iter cur() const {return m_cur;}
Iter begin() const {return m_begin;}
- private:
+ protected:
Iter m_begin;
Iter m_end;
Iter m_cur;
@@ -139,7 +142,6 @@
m_f = x.pred();
}
-
void assertPred( bool forward=true )
{
if( forward )
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FreeInfo.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FreeInfo.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FreeInfo.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FreeInfo.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,237 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include
+
+#include "storage/FreeInfo.h"
+#include "storage/Volume.h"
+#include "storage/SystemCmd.h"
+
+
+namespace storage
+{
+
+ FreeInfo::FreeInfo(const xmlNode* node)
+ : resize_cached(false), content_cached(false)
+ {
+ if (getChildValue(node, "resize_cached", resize_cached) && resize_cached)
+ {
+ getChildValue(node, "df_free_k", resize_info.df_freeK);
+ getChildValue(node, "resize_free_k", resize_info.resize_freeK);
+ getChildValue(node, "used_k", resize_info.usedK);
+ getChildValue(node, "resize_ok", resize_info.resize_ok);
+ }
+
+ if (getChildValue(node, "content_cached", content_cached) && content_cached)
+ {
+ getChildValue(node, "windows", content_info.windows);
+ getChildValue(node, "efi", content_info.efi);
+ getChildValue(node, "homes", content_info.homes);
+ }
+ }
+
+
+ void
+ FreeInfo::saveData(xmlNode* node) const
+ {
+ if (resize_cached)
+ {
+ setChildValue(node, "resize_cached", resize_cached);
+
+ setChildValue(node, "df_free_k", resize_info.df_freeK);
+ setChildValue(node, "resize_free_k", resize_info.resize_freeK);
+ setChildValue(node, "used_k", resize_info.usedK);
+ setChildValue(node, "resize_ok", resize_info.resize_ok);
+ }
+
+ if (content_cached)
+ {
+ setChildValue(node, "content_cached", content_cached);
+
+ setChildValue(node, "windows", content_info.windows);
+ setChildValue(node, "efi", content_info.efi);
+ setChildValue(node, "homes", content_info.homes);
+ }
+ }
+
+
+ void
+ FreeInfo::update(bool new_resize_cached, const ResizeInfo& new_resize_info,
+ bool new_content_cached, const ContentInfo& new_content_info)
+ {
+ if (new_resize_cached)
+ {
+ resize_cached = true;
+ resize_info = new_resize_info;
+ }
+
+ if (new_content_cached)
+ {
+ content_cached = true;
+ content_info = new_content_info;
+ }
+ }
+
+
+ bool
+ FreeInfo::isWindows(const string& mp)
+ {
+ const char* files[] = { "boot.ini", "msdos.sys", "io.sys", "config.sys", "MSDOS.SYS",
+ "IO.SYS", "bootmgr", "$Boot" };
+
+ for (unsigned int i = 0; i < lengthof(files); ++i)
+ {
+ string file = mp + "/" + files[i];
+ if (access(file.c_str(), R_OK) == 0)
+ {
+ y2mil("found windows file " << quote(file));
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+ unsigned
+ FreeInfo::numHomes(const string& mp)
+ {
+ const char* files[] = { ".profile", ".bashrc", ".ssh", ".kde", ".kde4", ".gnome",
+ ".gnome2" };
+
+ unsigned num = 0;
+
+ const list<string> dirs = glob(mp + "/*", GLOB_NOSORT | GLOB_ONLYDIR);
+ for (list<string>::const_iterator dir = dirs.begin(); dir != dirs.end(); ++dir)
+ {
+ if (*dir != "root" && checkDir(*dir))
+ {
+ for (unsigned int i = 0; i < lengthof(files); ++i)
+ {
+ string file = *dir + "/" + files[i];
+ if (access(file.c_str(), R_OK) == 0)
+ {
+ y2mil("found home file " << quote(file));
+ ++num;
+ break;
+ }
+ }
+ }
+
+ if (num >= 2)
+ return num;
+ }
+
+ return num;
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const ResizeInfo& resize_info)
+ {
+ return s << "df_freeK:" << resize_info.df_freeK << " resize_freeK:" << resize_info.resize_freeK
+ << " usedK:" << resize_info.usedK << " resize_ok:" << resize_info.resize_ok;
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const ContentInfo& content_info)
+ {
+ return s << "windows:" << content_info.windows << " efi:" << content_info.efi
+ << " homes:" << content_info.homes;
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const FreeInfo& free_info)
+ {
+ s << "resize_cached:" << free_info.resize_cached;
+ if (free_info.resize_cached)
+ s << " resize_info " << free_info.resize_info;
+
+ s << "content_cached:" << free_info.content_cached;
+ if (free_info.content_cached)
+ s << " content_info " << free_info.content_info;
+
+ return s;
+ }
+
+
+ ResizeInfo
+ FreeInfo::detectResizeInfo(const string& mp, const Volume& vol)
+ {
+ ResizeInfo resize_info;
+
+ StatVfs vfsbuf;
+ bool ret = getStatVfs(mp, vfsbuf);
+ if (ret)
+ {
+ resize_info.df_freeK = vfsbuf.freeK;
+ resize_info.usedK = vfsbuf.sizeK - vfsbuf.freeK;
+ resize_info.resize_freeK = resize_info.df_freeK;
+ resize_info.resize_ok = true;
+ }
+
+ if (ret && vol.getFs() == NTFS)
+ {
+ SystemCmd c("/usr/sbin/ntfsresize -f -i " + quote(vol.device()));
+ string fstr = " might resize at ";
+ string::size_type pos;
+ string stdout = boost::join(c.stdout(), "\n");
+ if (c.retcode()==0 && (pos=stdout.find(fstr))!=string::npos)
+ {
+ y2mil("pos:" << pos);
+ pos = stdout.find_first_not_of(" \t\n", pos + fstr.size());
+ y2mil("pos:" << pos);
+ string number = stdout.substr(pos, stdout.find_first_not_of("0123456789", pos));
+ y2mil("number:\"" << number << "\"");
+ unsigned long long t;
+ number >> t;
+ y2mil("number:" << t);
+ if (t - vol.sizeK() < resize_info.resize_freeK)
+ resize_info.resize_freeK = t - vol.sizeK();
+ }
+ else
+ {
+ resize_info.resize_ok = false;
+ }
+ }
+
+ y2mil("device:" << vol.device() << " " << resize_info);
+ return resize_info;
+ }
+
+
+ ContentInfo
+ FreeInfo::detectContentInfo(const string& mp, const Volume& vol)
+ {
+ ContentInfo content_info;
+
+ content_info.efi = vol.getFs() == VFAT && checkDir(mp + "/efi");
+
+ if (!content_info.efi && (vol.getFs() == VFAT || vol.getFs() == NTFS))
+ content_info.windows = isWindows(mp);
+
+ content_info.homes = numHomes(mp);
+
+ y2mil("device:" << vol.device() << " " << content_info);
+ return content_info;
+ }
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FreeInfo.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FreeInfo.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FreeInfo.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/FreeInfo.h Tue May 17 13:39:44 2011
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef FREE_INFO_H
+#define FREE_INFO_H
+
+#include <ostream>
+
+#include "storage/StorageInterface.h"
+#include "storage/XmlFile.h"
+
+
+namespace storage
+{
+ class Volume;
+
+
+ class FreeInfo
+ {
+
+ public:
+
+ FreeInfo(bool resize_cached, const ResizeInfo& resize_info,
+ bool content_cached, const ContentInfo& content_info)
+ : resize_cached(resize_cached), resize_info(resize_info),
+ content_cached(content_cached), content_info(content_info) {}
+
+ FreeInfo(const xmlNode* node);
+
+ void saveData(xmlNode* node) const;
+
+ bool resize_cached;
+ ResizeInfo resize_info;
+
+ bool content_cached;
+ ContentInfo content_info;
+
+ void update(bool resize_cached, const ResizeInfo& resize_info,
+ bool content_cached, const ContentInfo& content_info);
+
+ static ResizeInfo detectResizeInfo(const string& mp, const Volume& vol);
+ static ContentInfo detectContentInfo(const string& mp, const Volume& vol);
+
+ protected:
+
+ static bool isWindows(const string& mp);
+ static unsigned numHomes(const string& mp);
+
+ };
+
+ std::ostream& operator<<(std::ostream& s, const ResizeInfo& resize_info);
+ std::ostream& operator<<(std::ostream& s, const ContentInfo& content_info);
+ std::ostream& operator<<(std::ostream& s, const FreeInfo& free_info);
+
+}
+
+
+#endif
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Geometry.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Geometry.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Geometry.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Geometry.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include
+#include
+#include
+#include
+#include
+
+#include "storage/AppUtil.h"
+#include "storage/SystemCmd.h"
+#include "storage/StorageDefines.h"
+#include "storage/Parted.h"
+#include "storage/Enum.h"
+#include "storage/Partition.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ Geometry::Geometry()
+ : cylinders(0), heads(32), sectors(16), sector_size(512)
+ {
+ }
+
+
+ unsigned long long
+ Geometry::sizeK() const
+ {
+ return (unsigned long long)(cylinders) * cylinderSize() / 1024;
+ }
+
+
+ unsigned long
+ Geometry::cylinderSize() const
+ {
+ return heads * sectors * sector_size;
+ }
+
+ unsigned long
+ Geometry::headSize() const
+ {
+ return sectors * sector_size;
+ }
+
+
+ unsigned long long
+ Geometry::cylinderToKb(unsigned long cylinder) const
+ {
+ const unsigned long long cyl_size = cylinderSize();
+
+ return cyl_size * cylinder / 1024;
+ }
+
+
+ unsigned long
+ Geometry::kbToCylinder(unsigned long long kb) const
+ {
+ const unsigned long long cyl_size = cylinderSize();
+
+ unsigned long long bytes = kb * 1024;
+ bytes += cyl_size - 1;
+ return bytes / cyl_size;
+ }
+
+
+ unsigned long long
+ Geometry::sectorToKb(unsigned long long sector) const
+ {
+ // TODO use 128 arithmetic
+ return sector * sector_size / 1024;
+ }
+
+
+ unsigned long long
+ Geometry::kbToSector(unsigned long long kb) const
+ {
+ // TODO use 128 arithmetic
+ return kb * 1024 / sector_size;
+ }
+
+
+ bool
+ Geometry::operator==(const Geometry& rhs) const
+ {
+ return cylinders == rhs.cylinders && heads == rhs.heads && sectors == rhs.sectors &&
+ sector_size == rhs.sector_size;
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const Geometry& geo)
+ {
+ return s << "[" << geo.cylinders << "," << geo.heads << "," << geo.sectors << ","
+ << geo.sector_size << "]";
+ }
+
+
+ bool
+ getChildValue(const xmlNode* node, const char* name, Geometry& value)
+ {
+ const xmlNode* tmp = getChildNode(node, name);
+ if (!tmp)
+ return false;
+
+ getChildValue(tmp, "cylinders", value.cylinders);
+ getChildValue(tmp, "heads", value.heads);
+ getChildValue(tmp, "sectors", value.sectors);
+
+ if (!getChildValue(tmp, "sector_size", value.sector_size))
+ value.sector_size = 512;
+
+ return true;
+ }
+
+
+ void
+ setChildValue(xmlNode* node, const char* name, const Geometry& value)
+ {
+ xmlNode* tmp = xmlNewChild(node, name);
+
+ setChildValue(tmp, "cylinders", value.cylinders);
+ setChildValue(tmp, "heads", value.heads);
+ setChildValue(tmp, "sectors", value.sectors);
+
+ if (value.sector_size != 512)
+ setChildValue(tmp, "sector_size", value.sector_size);
+ }
+
+
+ bool
+ detectGeometry(const string& device, Geometry& geo)
+ {
+ y2mil("device:" << device);
+
+ bool ret = false;
+
+ int fd = open(device.c_str(), O_RDONLY);
+ if (fd >= 0)
+ {
+ int rcode = ioctl(fd, BLKSSZGET, &geo.sector_size);
+ y2mil("BLKSSZGET rcode:" << rcode << " sector_size:" << geo.sector_size);
+
+ geo.cylinders = 16;
+ geo.heads = 255;
+ geo.sectors = 63;
+
+ struct hd_geometry hd_geo;
+ rcode = ioctl(fd, HDIO_GETGEO, &hd_geo);
+ y2mil("HDIO_GETGEO rcode:" << rcode << " cylinders:" << (unsigned) hd_geo.cylinders <<
+ " heads:" << (unsigned) hd_geo.heads << " sectors:" << (unsigned) hd_geo.sectors);
+ if (rcode == 0)
+ {
+ geo.cylinders = hd_geo.cylinders > 0 ? hd_geo.cylinders : geo.cylinders;
+ geo.heads = hd_geo.heads > 0 ? hd_geo.heads : geo.heads;
+ geo.sectors = hd_geo.sectors > 0 ? hd_geo.sectors : geo.sectors;
+ }
+
+ uint64_t bytes = 0;
+ rcode = ioctl(fd, BLKGETSIZE64, &bytes);
+ y2mil("BLKGETSIZE64 rcode:" << rcode << " bytes:" << bytes);
+ if (rcode == 0 && bytes != 0)
+ {
+ geo.cylinders = bytes / (uint64_t)(geo.cylinderSize());
+ y2mil("calc cylinders:" << geo.cylinders);
+ ret = true;
+ }
+ else
+ {
+ unsigned long blocks;
+ rcode = ioctl(fd, BLKGETSIZE, &blocks);
+ y2mil("BLKGETSIZE rcode:" << rcode << " blocks:" << blocks);
+ if (rcode == 0 && blocks != 0)
+ {
+ geo.cylinders = (uint64_t)(blocks) * 512 / (uint64_t)(geo.cylinderSize());
+ y2mil("calc cylinders:" << geo.cylinders);
+ ret = true;
+ }
+ }
+
+ close(fd);
+ }
+
+ y2mil("device:" << device << " ret:" << ret << " geo:" << geo);
+ return ret;
+ }
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Geometry.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Geometry.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Geometry.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Geometry.h Tue May 17 13:39:44 2011
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef GEOMETRY_H
+#define GEOMETRY_H
+
+#include "storage/XmlFile.h"
+
+
+namespace storage
+{
+
+ struct Geometry
+ {
+ Geometry();
+
+ unsigned long cylinders;
+ unsigned int heads;
+ unsigned int sectors;
+ unsigned int sector_size;
+
+ unsigned long long sizeK() const;
+
+ unsigned long cylinderSize() const;
+ unsigned long headSize() const;
+
+ unsigned long long cylinderToKb(unsigned long cylinder) const;
+ unsigned long kbToCylinder(unsigned long long kb) const;
+
+ unsigned long long sectorToKb(unsigned long long sector) const;
+ unsigned long long kbToSector(unsigned long long kb) const;
+
+ bool operator==(const Geometry& rhs) const;
+ bool operator!=(const Geometry& rhs) const { return !(*this == rhs); }
+
+ friend std::ostream& operator<<(std::ostream& s, const Geometry& geo);
+
+ friend bool getChildValue(const xmlNode* node, const char* name, Geometry& value);
+ friend void setChildValue(xmlNode* node, const char* name, const Geometry& value);
+ };
+
+
+ bool detectGeometry(const string& device, Geometry& geometry);
+
+}
+
+
+#endif
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Graph.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Graph.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Graph.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Graph.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,609 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include <string>
+#include <fstream>
+#include
+
+#include "config.h"
+#include "storage/Graph.h"
+#include "storage/AppUtil.h"
+#include "storage/HumanString.h"
+#include "storage/StorageInterface.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ class Graph
+ {
+
+ public:
+
+ bool save(const string& filename) const;
+
+ protected:
+
+ enum NodeType { NODE_DISK, NODE_DMMULTIPATH, NODE_DMRAID, NODE_PARTITION, NODE_MD, NODE_MDPART,
+ NODE_LVMVG, NODE_LVMLV, NODE_DM, NODE_BTRFS, NODE_MOUNTPOINT };
+
+ struct Node
+ {
+ Node(NodeType type, const string& device, const string& label, unsigned long long sizeK)
+ : type(type), device(device), label(label), sizeK(sizeK) {}
+
+ string id() const { return (type == NODE_MOUNTPOINT ? "mountpoint:" : "device:") + device; }
+
+ NodeType type;
+ string device;
+ string label;
+ unsigned long long sizeK;
+ };
+
+ enum EdgeType { EDGE_SUBDEVICE, EDGE_MOUNT, EDGE_USED };
+
+ struct Edge
+ {
+ Edge(EdgeType type, const string& id1, const string& id2)
+ : type(type), id1(id1), id2(id2) {}
+
+ EdgeType type;
+ string id1;
+ string id2;
+ };
+
+ enum RankType { RANK_SOURCE, RANK_SAME, RANK_SINK };
+
+ struct Rank
+ {
+ Rank(RankType type = RANK_SAME)
+ : type(type) {}
+
+ RankType type;
+ list<string> ids;
+ };
+
+ friend ostream& operator<<(ostream& s, const Node& node);
+ friend ostream& operator<<(ostream& s, const Edge& edge);
+ friend ostream& operator<<(ostream& s, const Rank& rank);
+
+ list<Node> nodes;
+ list<Edge> edges;
+ list<Rank> ranks;
+
+ private:
+
+ static string quote(const string& str);
+ static string makeTooltip(const Text& text, const string& label, unsigned long long sizeK);
+
+ };
+
+
+ class DeviceGraph : public Graph
+ {
+
+ public:
+
+ DeviceGraph(StorageInterface* s);
+
+ private:
+
+ Rank disks_rank;
+ Rank partitions_rank;
+ Rank mounts_rank;
+
+ void processUsedby(const Node& node, const list<UsedByInfo>& usedBy);
+ void processMount(const Node& node, const VolumeInfo& volume);
+
+ };
+
+
+ class MountGraph : public Graph
+ {
+
+ public:
+
+ MountGraph(StorageInterface* s);
+
+ private:
+
+ map mount_ranks;
+
+ typedef map Entries;
+
+ Entries entries;
+
+ Entries::const_iterator findParent(const Entries::const_iterator& child) const;
+
+ };
+
+
+ DeviceGraph::DeviceGraph(StorageInterface* s)
+ : disks_rank(RANK_SOURCE), partitions_rank(), mounts_rank(RANK_SINK)
+ {
+ deque<ContainerInfo> containers;
+ s->getContainers(containers);
+ for (deque<ContainerInfo>::const_iterator i1 = containers.begin(); i1 != containers.end(); ++i1)
+ {
+ switch (i1->type)
+ {
+ case DISK: {
+
+ DiskInfo diskinfo;
+ s->getDiskInfo(i1->device, diskinfo);
+
+ Node disk_node(NODE_DISK, i1->device, i1->name, diskinfo.sizeK);
+ nodes.push_back(disk_node);
+ disks_rank.ids.push_back(disk_node.id());
+
+ processUsedby(disk_node, i1->usedBy);
+
+ deque<PartitionInfo> partitions;
+ s->getPartitionInfo(i1->name, partitions);
+ for (deque<PartitionInfo>::const_iterator i2 = partitions.begin(); i2 != partitions.end(); ++i2)
+ {
+ if (i2->partitionType == EXTENDED)
+ continue;
+
+ Node partition_node(NODE_PARTITION, i2->v.device, i2->v.name, i2->v.sizeK);
+ nodes.push_back(partition_node);
+ partitions_rank.ids.push_back(partition_node.id());
+
+ edges.push_back(Edge(EDGE_SUBDEVICE, disk_node.id(), partition_node.id()));
+
+ processUsedby(partition_node, i2->v.usedBy);
+ processMount(partition_node, i2->v);
+ }
+
+ } break;
+
+ case LVM: {
+
+ LvmVgInfo lvmvginfo;
+ s->getLvmVgInfo(i1->name, lvmvginfo);
+
+ Node vg_node(NODE_LVMVG, i1->device, i1->name, lvmvginfo.sizeK);
+ nodes.push_back(vg_node);
+
+ processUsedby(vg_node, i1->usedBy);
+
+ Rank rank;
+
+ deque<LvmLvInfo> lvs;
+ s->getLvmLvInfo(i1->name, lvs);
+ for (deque<LvmLvInfo>::const_iterator i2 = lvs.begin(); i2 != lvs.end(); ++i2)
+ {
+ Node lv_node(NODE_LVMLV, i2->v.device, i2->v.name, i2->v.sizeK);
+ nodes.push_back(lv_node);
+ rank.ids.push_back(lv_node.id());
+
+ edges.push_back(Edge(EDGE_SUBDEVICE, vg_node.id(), lv_node.id()));
+
+ processUsedby(lv_node, i2->v.usedBy);
+ processMount(lv_node, i2->v);
+ }
+
+ if (!rank.ids.empty())
+ ranks.push_back(rank);
+
+ } break;
+
+ case MD: {
+
+ deque<MdInfo> mds;
+ s->getMdInfo(mds);
+
+ for (deque<MdInfo>::const_iterator i2 = mds.begin(); i2 != mds.end(); ++i2)
+ {
+ Node md_node(NODE_MD, i2->v.device, i2->v.name, i2->v.sizeK);
+ nodes.push_back(md_node);
+
+ processUsedby(md_node, i2->v.usedBy);
+ processMount(md_node, i2->v);
+ }
+
+ } break;
+
+ case MDPART: {
+
+ MdPartCoInfo mdpartcoinfo;
+ s->getMdPartCoInfo(i1->device, mdpartcoinfo);
+
+ Node mdpart_node(NODE_MDPART, i1->device, i1->name, mdpartcoinfo.d.sizeK);
+ nodes.push_back(mdpart_node);
+
+ processUsedby(mdpart_node, i1->usedBy);
+
+ Rank rank;
+
+ deque<MdPartInfo> partitions;
+ s->getMdPartInfo(i1->name, partitions);
+ for (deque<MdPartInfo>::const_iterator i2 = partitions.begin(); i2 != partitions.end(); ++i2)
+ {
+ if (i2->p.partitionType == EXTENDED)
+ continue;
+
+ Node partition_node(NODE_PARTITION, i2->v.device, i2->v.name, i2->v.sizeK);
+ nodes.push_back(partition_node);
+ rank.ids.push_back(partition_node.id());
+
+ edges.push_back(Edge(EDGE_SUBDEVICE, mdpart_node.id(), partition_node.id()));
+
+ processUsedby(partition_node, i2->v.usedBy);
+ processMount(partition_node, i2->v);
+ }
+
+ if (!rank.ids.empty())
+ ranks.push_back(rank);
+
+ } break;
+
+ case DM: {
+
+ deque<DmInfo> dms;
+ s->getDmInfo(dms);
+
+ for (deque<DmInfo>::const_iterator i2 = dms.begin(); i2 != dms.end(); ++i2)
+ {
+ Node dm_node(NODE_DM, i2->v.device, i2->v.name, i2->v.sizeK);
+ nodes.push_back(dm_node);
+
+ processUsedby(dm_node, i2->v.usedBy);
+ processMount(dm_node, i2->v);
+ }
+
+ } break;
+
+ case DMRAID: {
+
+ DmraidCoInfo dmraidcoinfo;
+ s->getDmraidCoInfo(i1->device, dmraidcoinfo);
+
+ Node dmraid_node(NODE_DMRAID, i1->device, i1->name, dmraidcoinfo.p.d.sizeK);
+ nodes.push_back(dmraid_node);
+
+ processUsedby(dmraid_node, i1->usedBy);
+
+ Rank rank;
+
+ deque<DmraidInfo> partitions;
+ s->getDmraidInfo(i1->name, partitions);
+ for (deque<DmraidInfo>::const_iterator i2 = partitions.begin(); i2 != partitions.end(); ++i2)
+ {
+ if (i2->p.p.partitionType == EXTENDED)
+ continue;
+
+ Node partition_node(NODE_PARTITION, i2->p.v.device, i2->p.v.name, i2->p.v.sizeK);
+ nodes.push_back(partition_node);
+ rank.ids.push_back(partition_node.id());
+
+ edges.push_back(Edge(EDGE_SUBDEVICE, dmraid_node.id(), partition_node.id()));
+
+ processUsedby(partition_node, i2->p.v.usedBy);
+ processMount(partition_node, i2->p.v);
+ }
+
+ if (!rank.ids.empty())
+ ranks.push_back(rank);
+
+ } break;
+
+ case DMMULTIPATH: {
+
+ DmmultipathCoInfo dmmultipathcoinfo;
+ s->getDmmultipathCoInfo(i1->device, dmmultipathcoinfo);
+
+ Node dmmultipath_node(NODE_DMMULTIPATH, i1->device, i1->name, dmmultipathcoinfo.p.d.sizeK);
+ nodes.push_back(dmmultipath_node);
+
+ processUsedby(dmmultipath_node, i1->usedBy);
+
+ Rank rank;
+
+ deque<DmmultipathInfo> partitions;
+ s->getDmmultipathInfo(i1->name, partitions);
+ for (deque<DmmultipathInfo>::const_iterator i2 = partitions.begin(); i2 != partitions.end(); ++i2)
+ {
+ if (i2->p.p.partitionType == EXTENDED)
+ continue;
+
+ Node partition_node(NODE_PARTITION, i2->p.v.device, i2->p.v.name, i2->p.v.sizeK);
+ nodes.push_back(partition_node);
+ rank.ids.push_back(partition_node.id());
+
+ edges.push_back(Edge(EDGE_SUBDEVICE, dmmultipath_node.id(), partition_node.id()));
+
+ processUsedby(partition_node, i2->p.v.usedBy);
+ processMount(partition_node, i2->p.v);
+ }
+
+ if (!rank.ids.empty())
+ ranks.push_back(rank);
+
+ } break;
+
+ case BTRFSC: {
+
+ deque<BtrfsInfo> btrfss;
+ s->getBtrfsInfo(btrfss);
+
+ for (deque<BtrfsInfo>::const_iterator i2 = btrfss.begin(); i2 != btrfss.end(); ++i2)
+ {
+ Node btrfs_node(NODE_BTRFS, i2->v.uuid, i2->v.name, i2->v.sizeK);
+ nodes.push_back(btrfs_node);
+
+ processUsedby(btrfs_node, i2->v.usedBy);
+ processMount(btrfs_node, i2->v);
+ }
+
+ } break;
+
+ case LOOP:
+ case NFSC:
+ case TMPFSC:
+ case CUNKNOWN:
+ break;
+ }
+ }
+
+ if (!disks_rank.ids.empty())
+ ranks.push_back(disks_rank);
+
+ if (!partitions_rank.ids.empty())
+ ranks.push_back(partitions_rank);
+
+ if (!mounts_rank.ids.empty())
+ ranks.push_back(mounts_rank);
+ }
+
+
+ void
+ DeviceGraph::processUsedby(const Node& node, const list<UsedByInfo>& usedBy)
+ {
+ for (list<UsedByInfo>::const_iterator i = usedBy.begin(); i != usedBy.end(); ++i)
+ {
+ edges.push_back(Edge(EDGE_USED, node.id(), "device:" + i->device));
+ }
+ }
+
+
+ void
+ DeviceGraph::processMount(const Node& node, const VolumeInfo& volume)
+ {
+ if (!volume.mount.empty())
+ {
+ Node mountpoint_node(NODE_MOUNTPOINT, volume.device, volume.mount, volume.sizeK);
+ nodes.push_back(mountpoint_node);
+ mounts_rank.ids.push_back(mountpoint_node.id());
+
+ edges.push_back(Edge(EDGE_MOUNT, node.id(), mountpoint_node.id()));
+ }
+ }
+
+
+ MountGraph::MountGraph(StorageInterface* s)
+ {
+ mount_ranks[0].type = RANK_SOURCE;
+
+ deque<VolumeInfo> volumes;
+ s->getVolumes(volumes);
+ for (deque<VolumeInfo>::const_iterator i1 = volumes.begin(); i1 != volumes.end(); ++i1)
+ {
+ if (!i1->mount.empty() && i1->mount != "swap")
+ {
+ Node mountpoint_node(NODE_MOUNTPOINT, i1->device, i1->mount, i1->sizeK);
+ nodes.push_back(mountpoint_node);
+
+ int r = i1->mount == "/" ? 0 : count(i1->mount.begin(), i1->mount.end(), '/');
+ mount_ranks[r].ids.push_back(mountpoint_node.id());
+
+ entries[i1->mount] = i1->device;
+ }
+ }
+
+ for (map::const_iterator i1 = mount_ranks.begin(); i1 != mount_ranks.end(); ++i1)
+ if (!i1->second.ids.empty())
+ ranks.push_back(i1->second);
+
+ for (Entries::const_iterator i1 = entries.begin(); i1 != entries.end(); ++i1)
+ {
+ Entries::const_iterator i2 = findParent(i1);
+ if (i2 != entries.end())
+ edges.push_back(Edge(EDGE_MOUNT, "mountpoint:" + i2->second, "mountpoint:" + i1->second));
+ }
+ }
+
+
+ MountGraph::Entries::const_iterator
+ MountGraph::findParent(const Entries::const_iterator& child) const
+ {
+ string mount = child->first;
+
+ while (mount != "/")
+ {
+ string::size_type pos = mount.rfind("/");
+ if (pos == string::npos)
+ return entries.end();
+
+ mount.erase(pos);
+ if (mount.empty())
+ mount = "/";
+
+ Entries::const_iterator i1 = entries.find(mount);
+ if (i1 != entries.end())
+ return i1;
+ }
+
+ return entries.end();
+ }
+
+
+ string
+ Graph::quote(const string& str)
+ {
+ return '"' + boost::replace_all_copy(str, "\"", "\\\"") + '"';
+ }
+
+
+ string
+ Graph::makeTooltip(const Text& text, const string& label, unsigned long long sizeK)
+ {
+ return quote(text.text + "\\n" + label + "\\n" + byteToHumanString(1024 * sizeK, false, 2, false));
+ }
+
+
+ ostream& operator<<(ostream& s, const Graph::Node& node)
+ {
+ s << Graph::quote(node.id()) << " [label=" << Graph::quote(node.label);
+ switch (node.type)
+ {
+ case Graph::NODE_DISK:
+ s << ", color=\"#ff0000\", fillcolor=\"#ffaaaa\"" << ", tooltip="
+ << Graph::makeTooltip(_("Hard Disk"), node.device, node.sizeK);
+ break;
+ case Graph::NODE_DMRAID:
+ s << ", color=\"#ff0000\", fillcolor=\"#ffaaaa\"" << ", tooltip="
+ << Graph::makeTooltip(_("DM RAID"), node.device, node.sizeK);
+ break;
+ case Graph::NODE_DMMULTIPATH:
+ s << ", color=\"#ff0000\", fillcolor=\"#ffaaaa\"" << ", tooltip="
+ << Graph::makeTooltip(_("DM Multipath"), node.device, node.sizeK);
+ break;
+ case Graph::NODE_PARTITION:
+ s << ", color=\"#cc33cc\", fillcolor=\"#eeaaee\"" << ", tooltip="
+ << Graph::makeTooltip(_("Partition"), node.device, node.sizeK);
+ break;
+ case Graph::NODE_MD:
+ s << ", color=\"#aaaa00\", fillcolor=\"#ffffaa\"" << ", tooltip="
+ << Graph::makeTooltip(_("MD RAID"), node.device, node.sizeK);
+ break;
+ case Graph::NODE_MDPART:
+ s << ", color=\"#aaaa00\", fillcolor=\"#ffffaa\"" << ", tooltip="
+ << Graph::makeTooltip(_("MD RAID"), node.device, node.sizeK);
+ break;
+ case Graph::NODE_LVMVG:
+ s << ", color=\"#0000ff\", fillcolor=\"#aaaaff\"" << ", tooltip="
+ << Graph::makeTooltip(_("Volume Group"), node.device, node.sizeK);
+ break;
+ case Graph::NODE_LVMLV:
+ s << ", color=\"#6622dd\", fillcolor=\"#bb99ff\"" << ", tooltip="
+ << Graph::makeTooltip(_("Logical Volume"), node.device, node.sizeK);
+ break;
+ case Graph::NODE_BTRFS:
+ s << ", color=\"#17534f\", fillcolor=\"#28e3d8\"" << ", tooltip="
+ << Graph::makeTooltip(_("Btrfs Volume"), node.device, node.sizeK);
+ break;
+ case Graph::NODE_DM:
+ s << ", color=\"#885511\", fillcolor=\"#ddbb99\"" << ", tooltip="
+ << Graph::makeTooltip(_("DM Device"), node.device, node.sizeK);
+ break;
+ case Graph::NODE_MOUNTPOINT:
+ s << ", color=\"#008800\", fillcolor=\"#99ee99\"" << ", tooltip="
+ << Graph::makeTooltip(_("Mount Point"), node.device, node.sizeK);
+ break;
+ }
+ return s << "];";
+ }
+
+
+ ostream& operator<<(ostream& s, const Graph::Edge& edge)
+ {
+ s << Graph::quote(edge.id1) << " -> " << Graph::quote(edge.id2);
+ switch (edge.type)
+ {
+ case Graph::EDGE_SUBDEVICE:
+ s << " [style=solid]";
+ break;
+ case Graph::EDGE_MOUNT:
+ s << " [style=dashed]";
+ break;
+ case Graph::EDGE_USED:
+ s << " [style=dotted]";
+ break;
+ }
+ return s << ";";
+ }
+
+
+ ostream& operator<<(ostream& s, const Graph::Rank& rank)
+ {
+ static const char* names[] = { "source", "same", "sink" };
+
+ s << "{ rank=" << names[rank.type] << "; ";
+ for (list<string>::const_iterator id = rank.ids.begin(); id != rank.ids.end(); ++id)
+ s << Graph::quote(*id) << " ";
+ return s << "};";
+ }
+
+
+ bool
+ Graph::save(const string& filename) const
+ {
+ ofstream out(filename.c_str());
+ classic(out);
+
+ out << "// generated by libstorage version " VERSION << endl;
+ out << "// " << hostname() << ", " << datetime() << endl;
+ out << endl;
+
+ out << "digraph storage" << endl;
+ out << "{" << endl;
+ out << " node [shape=rectangle, style=filled, fontname=\"Arial\"];" << endl;
+ out << " edge [color=\"#444444\"];" << endl;
+ out << endl;
+
+ for (list<Node>::const_iterator node = nodes.begin(); node != nodes.end(); ++node)
+ out << " " << (*node) << endl;
+
+ out << endl;
+
+ for (list<Rank>::const_iterator rank = ranks.begin(); rank != ranks.end(); ++rank)
+ out << " " << (*rank) << endl;
+
+ out << endl;
+
+ for (list<Edge>::const_iterator edge = edges.begin(); edge != edges.end(); ++edge)
+ out << " " << (*edge) << endl;
+
+ out << "}" << endl;
+
+ out.close();
+
+ return !out.bad();
+ }
+
+
+ bool
+ saveDeviceGraph(StorageInterface* s, const string& filename)
+ {
+ return DeviceGraph(s).save(filename);
+ }
+
+
+ bool
+ saveMountGraph(StorageInterface* s, const string& filename)
+ {
+ return MountGraph(s).save(filename);
+ }
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Graph.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Graph.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Graph.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Graph.h Tue May 17 13:39:44 2011
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) [2004-2009] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef GRAPH_H
+#define GRAPH_H
+
+
+#include <string>
+
+using std::string;
+
+
+namespace storage
+{
+ class StorageInterface;
+
+
+ /**
+ * Saves a graph of the storage devices as a DOT file for graphviz.
+ *
+ * @param s StorageInterface
+ * @param filename filename of graph
+ * @return true on successful writing of graph
+ */
+ bool saveDeviceGraph(StorageInterface* s, const string& filename);
+
+
+ /**
+ * Saves a graph of the mount points as a DOT file for graphviz.
+ *
+ * @param s StorageInterface
+ * @param filename filename of graph
+ * @return true on successful writing of graph
+ */
+ bool saveMountGraph(StorageInterface* s, const string& filename);
+
+}
+
+
+#endif
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/HumanString.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/HumanString.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/HumanString.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/HumanString.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include <locale>
+#include
+
+#include "storage/AppUtil.h"
+#include "storage/HumanString.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ int
+ numSuffixes()
+ {
+ return 7;
+ }
+
+
+ list<Text>
+ getAllSuffixes(int i, bool all = false, bool sloppy = false)
+ {
+ list<Text> ret;
+
+ switch (i)
+ {
+ case 0:
+ /* symbol for "bytes" (best keep untranslated) */
+ ret.push_back(_("B"));
+ if (sloppy)
+ ret.push_back(Text("", ""));
+ break;
+
+ case 1:
+ /* symbol for "kilo bytes" (best keep untranslated) */
+ ret.push_back(_("kB"));
+ if (all)
+ /* symbol for "kibi bytes" (best keep untranslated) */
+ ret.push_back(_("KiB"));
+ if (sloppy)
+ /* symbol for "kilo" (best keep untranslated) */
+ ret.push_back(_("k"));
+ break;
+
+ case 2:
+ /* symbol for "mega bytes" (best keep untranslated) */
+ ret.push_back(_("MB"));
+ if (all)
+ /* symbol for "mebi bytes" (best keep untranslated) */
+ ret.push_back(_("MiB"));
+ if (sloppy)
+ /* symbol for "mega" (best keep untranslated) */
+ ret.push_back(_("M"));
+ break;
+
+ case 3:
+ /* symbol for "giga bytes" (best keep untranslated) */
+ ret.push_back(_("GB"));
+ if (all)
+ /* symbol for "gibi bytes" (best keep untranslated) */
+ ret.push_back(_("GiB"));
+ if (sloppy)
+ /* symbol for "giga" (best keep untranslated) */
+ ret.push_back(_("G"));
+ break;
+
+ case 4:
+ /* symbol for "tera bytes" (best keep untranslated) */
+ ret.push_back(_("TB"));
+ if (all)
+ /* symbol for "tebi bytes" (best keep untranslated) */
+ ret.push_back(_("TiB"));
+ if (sloppy)
+ /* symbol for "tera" (best keep untranslated) */
+ ret.push_back(_("T"));
+ break;
+
+ case 5:
+ /* symbol for "peta bytes" (best keep untranslated) */
+ ret.push_back(_("PB"));
+ if (all)
+ /* symbol for "pebi bytes" (best keep untranslated) */
+ ret.push_back(_("PiB"));
+ if (sloppy)
+ /* symbol for "peta" (best keep untranslated) */
+ ret.push_back(_("P"));
+ break;
+
+ case 6:
+ /* symbol for "exa bytes" (best keep untranslated) */
+ ret.push_back(_("EB"));
+ if (all)
+ /* symbol for "exbi bytes" (best keep untranslated) */
+ ret.push_back(_("EiB"));
+ if (sloppy)
+ /* symbol for "exa" (best keep untranslated) */
+ ret.push_back(_("E"));
+ break;
+ }
+
+ return ret;
+ }
+
+
+ string
+ getSuffix(int i, bool classic)
+ {
+ return classic ? getAllSuffixes(i).front().native : getAllSuffixes(i).front().text;
+ }
+
+
+ string
+ byteToHumanString(unsigned long long size, bool classic, int precision, bool omit_zeroes)
+ {
+ const locale loc = classic ? locale::classic() : locale();
+
+ double f = size;
+ int i = 0;
+
+ while (f >= 1024.0 && i + 1 < numSuffixes())
+ {
+ f /= 1024.0;
+ i++;
+ }
+
+ if ((i == 0) || (omit_zeroes && (f == (unsigned long long)(f))))
+ {
+ precision = 0;
+ }
+
+ ostringstream s;
+ s.imbue(loc);
+ s.setf(ios::fixed);
+ s.precision(precision);
+
+ s << f << ' ' << getSuffix(i, classic);
+
+ return s.str();
+ }
+
+
+ bool
+ humanStringToByte(const string& str, bool classic, unsigned long long& size)
+ {
+ const locale loc = classic ? locale::classic() : locale();
+
+ const string str_trimmed = boost::trim_copy(str, loc);
+
+ double f = 1.0;
+
+ for (int i = 0; i < numSuffixes(); ++i)
+ {
+ list<Text> suffix = getAllSuffixes(i, true, !classic);
+
+ for (list<Text>::const_iterator j = suffix.begin(); j != suffix.end(); ++j)
+ {
+ const string& tmp = classic ? j->native : j->text;
+
+ if (boost::iends_with(str_trimmed, tmp, loc))
+ {
+ string number = str_trimmed.substr(0, str_trimmed.size() - tmp.size());
+
+ istringstream s(boost::trim_copy(number, loc));
+ s.imbue(loc);
+
+ double g;
+ s >> g;
+
+ if (!s.fail() && s.eof() && g >= 0.0)
+ {
+ size = g * f;
+ return true;
+ }
+ }
+ }
+
+ f *= 1024.0;
+ }
+
+ return false;
+ }
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/HumanString.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/HumanString.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/HumanString.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/HumanString.h Tue May 17 13:39:44 2011
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) [2004-2010] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef HUMAN_STRING_H
+#define HUMAN_STRING_H
+
+
+#include <string>
+
+using std::string;
+
+
+namespace storage
+{
+
+ /**
+ * Return number of suffixes.
+ *
+ * @return number of suffixes
+ */
+ int numSuffixes();
+
+ /**
+ * Return a suffix.
+ *
+ * @param i index of suffix
+ * @param classic use classic locale instead of global C++ locale
+ * @return suffix
+ */
+ string getSuffix(int i, bool classic);
+
+
+ /**
+ * Return a pretty description of a size with required precision
+ * and using B, kB, MB, GB, TB or PB as unit as appropriate.
+ *
+ * @param size size in bytes
+ * @param classic use classic locale instead of global C++ locale
+ * @param precision number of fraction digits in output
+ * @param omit_zeroes if true omit trailing zeroes for exact values
+ * @return formatted string
+ */
+ string byteToHumanString(unsigned long long size, bool classic, int precision,
+ bool omit_zeroes);
+
+ /**
+ * Converts a size description using B, kB, MB, GB, TB or PB into an integer.
+ *
+ * @param str size string
+ * @param classic use classic locale instead of global C++ locale
+ * @param size size in bytes
+ * @return true on successful conversion
+ *
+ * The conversion is always case-insensitive. With classic set to
+ * false the conversion is also sloppy concerning omission of 'B'.
+ */
+ bool humanStringToByte(const string& str, bool classic, unsigned long long& size);
+
+}
+
+
+#endif
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/IterPair.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/IterPair.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/IterPair.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/IterPair.h Tue May 17 13:39:44 2011
@@ -33,20 +33,26 @@
{
public:
typedef Iter itype;
- IterPair( const Iter b, const Iter e ) : m_begin(b), m_end(e) {}
+ IterPair(const Iter& b, const Iter& e) : m_begin(b), m_end(e) {}
IterPair( const IterPair& x )
{
*this = x;
}
- IterPair& operator=(const IterPair& x)
+
+ template <class Ip>
+ IterPair(const Ip& x) : m_begin(x.begin()), m_end(x.end()) {}
+
+ template< class Ip >
+ IterPair& operator=(const Ip& x)
{
- m_begin=x.m_begin;
- m_end=x.m_end;
+ m_begin=x.begin();
+ m_end=x.end();
return( *this );
}
- bool operator==(const IterPair& x) const
+ template< class Ip >
+ bool operator==(const Ip& x) const
{
- return( m_begin==x.m_begin && m_end==x.m_end );
+ return( m_begin==x.begin() && m_end==x.end() );
}
bool empty() const { return( m_begin==m_end ); }
unsigned length() const { return( std::distance( m_begin, m_end )); }
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ListListIterator.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ListListIterator.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ListListIterator.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/ListListIterator.h Tue May 17 13:39:44 2011
@@ -23,8 +23,8 @@
#ifndef LIST_LIST_ITERATOR_H
#define LIST_LIST_ITERATOR_H
-#include "y2storage/AppUtil.h"
-#include "y2storage/IterPair.h"
+#include "storage/AppUtil.h"
+#include "storage/IterPair.h"
namespace storage
{
@@ -53,9 +53,13 @@
initialize( p.begin(), p.end(), setend );
}
- ListListIterator( const ListListIterator& x )
+ template< class It >
+ ListListIterator( const It& x )
{
- copyMembers( x );
+ m_begin = x.begin();
+ m_end = x.end();
+ m_lcur = x.cur();
+ m_pcur = x.pcur();
}
ListListIterator& operator=(const ListListIterator& x)
@@ -99,11 +103,13 @@
{
return( &(*m_pcur) );
}
- bool operator==(const ListListIterator& x) const
+ template< class It >
+ bool operator==(const It& x) const
{
return( m_pcur == x.pcur() );
}
- bool operator!=(const ListListIterator& x) const
+ template< class It >
+ bool operator!=(const It& x) const
{
return( m_pcur != x.pcur() );
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lock.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lock.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lock.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lock.cc Tue May 17 13:39:44 2011
@@ -19,10 +19,6 @@
* find current contact information at www.novell.com.
*/
-/*
- * Author: Arvin Schnell
- */
-
#include
#include
@@ -32,8 +28,8 @@
#include
#include
-#include "y2storage/AppUtil.h"
-#include "y2storage/Lock.h"
+#include "storage/AppUtil.h"
+#include "storage/Lock.h"
namespace storage
@@ -51,7 +47,7 @@
Lock::Lock(bool readonly, bool disable)
- : disabled(disable || getenv("YAST2_STORAGE_NO_LOCKING") != NULL),
+ : disabled(disable || getenv("LIBSTORAGE_NO_LOCKING") != NULL),
fd(-1)
{
if (disabled)
@@ -71,7 +67,7 @@
{
// Opening lock-file failed.
y2err("opening lock-file failed: " << strerror(errno));
- throw(LockException(0));
+ throw LockException(0);
}
struct flock lock;
@@ -89,13 +85,15 @@
// release. In that case we don't get the pid (and it is
// still 0).
fcntl(fd, F_GETLK, &lock);
+ close(fd);
y2err("locked by process " << lock.l_pid);
- throw(LockException(lock.l_pid));
+ throw LockException(lock.l_pid);
default:
// Some other error.
+ close(fd);
y2err("getting lock failed: " << strerror(errno));
- throw(LockException(0));
+ throw LockException(0);
}
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lock.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lock.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lock.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lock.h Tue May 17 13:39:44 2011
@@ -24,11 +24,6 @@
#define LOCK_H
-/*
- * Author: Arvin Schnell
- */
-
-
#include <stdexcept>
#include
@@ -66,7 +61,7 @@
private:
- bool disabled;
+ const bool disabled;
int fd;
};
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Loop.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Loop.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Loop.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Loop.cc Tue May 17 13:39:44 2011
@@ -19,47 +19,39 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
+#include
#include <sstream>
-#include
+#include "storage/Loop.h"
+#include "storage/StorageTypes.h"
+#include "storage/Container.h"
+#include "storage/AppUtil.h"
+#include "storage/SystemInfo.h"
+#include "storage/Storage.h"
+#include "storage/SystemCmd.h"
+#include "storage/StorageDefines.h"
-#include "y2storage/Loop.h"
-#include "y2storage/StorageTypes.h"
-#include "y2storage/Container.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/ProcPart.h"
-#include "y2storage/Storage.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/StorageDefines.h"
-using namespace storage;
-using namespace std;
+namespace storage
+{
+ using namespace std;
Loop::Loop(const LoopCo& d, const string& LoopDev, const string& LoopFile,
- bool dmcrypt, const string& dm_dev, ProcPart& ppart,
+ bool dmcrypt, const string& dm_dev, SystemInfo& systeminfo,
SystemCmd& losetup)
- : Volume(d, 0, 0)
+ : Volume(d, 0, 0), lfile(LoopFile), reuseFile(true), delFile(false)
{
y2mil("constructed loop dev:" << LoopDev << " file:" << LoopFile <<
" dmcrypt:" << dmcrypt << " dmdev:" << dm_dev);
if( d.type() != LOOP )
y2err("constructed loop with wrong container");
- init();
- lfile = LoopFile;
loop_dev = fstab_loop_dev = LoopDev;
if( loop_dev.empty() )
getLoopData( losetup );
if( loop_dev.empty() )
- {
- list<unsigned> l;
- d.loopIds( l );
- getFreeLoop( losetup, l );
- }
+ getFreeLoop(losetup, d.usedNumbers());
string proc_dev;
if( !dmcrypt )
{
@@ -67,7 +59,7 @@
if( loopStringNum( loop_dev, num ))
{
setNameDev();
- getMajorMinor( dev, mjr, mnr );
+ getMajorMinor();
}
proc_dev = loop_dev;
}
@@ -84,7 +76,7 @@
is_loop = true;
unsigned long long s = 0;
if( !proc_dev.empty() )
- ppart.getSize( proc_dev, s );
+ systeminfo.getProcParts().getSize(proc_dev, s);
if( s>0 )
{
setSize( s );
@@ -100,15 +92,12 @@
Loop::Loop(const LoopCo& d, const string& file, bool reuseExisting,
unsigned long long sizeK, bool dmcr)
- : Volume(d, 0, 0)
+ : Volume(d, 0, 0), lfile(file), reuseFile(reuseExisting), delFile(false)
{
y2mil("constructed loop file:" << file << " reuseExisting:" << reuseExisting <<
" sizek:" << sizeK << " dmcrypt:" << dmcr);
if( d.type() != LOOP )
y2err("constructed loop with wrong container");
- init();
- reuseFile = reuseExisting;
- lfile = file;
getFreeLoop();
is_loop = true;
if( !dmcr )
@@ -117,7 +106,7 @@
if( loopStringNum( dev, num ))
{
setNameDev();
- getMajorMinor( dev, mjr, mnr );
+ getMajorMinor();
}
}
else
@@ -134,19 +123,20 @@
}
-Loop::~Loop()
-{
- y2deb("destructed loop " << dev);
-}
+ Loop::Loop(const LoopCo& c, const Loop& v)
+ : Volume(c, v), lfile(v.lfile), reuseFile(v.reuseFile),
+ delFile(v.delFile)
+ {
+ y2deb("copy-constructed Loop from " << v.dev);
+ }
-void
-Loop::init()
+ Loop::~Loop()
{
- delFile = false;
- reuseFile = true;
+ y2deb("destructed Loop " << dev);
}
+
void
Loop::setDmcryptDev( const string& dm_dev, bool active )
{
@@ -155,7 +145,7 @@
nm = dm_dev.substr( dm_dev.find_last_of( '/' )+1);
if( active )
{
- getMajorMinor( dev, mjr, mnr );
+ getMajorMinor();
replaceAltName( "/dev/dm-", "/dev/dm-"+decString(mnr) );
}
Volume::setDmcryptDev( dm_dev, active );
@@ -222,21 +212,20 @@
string
Loop::lfileRealPath() const
{
- return( cont->getStorage()->root() + lfile );
+ return getStorage()->root() + lfile;
}
-unsigned Loop::major()
+
+unsigned Loop::loopMajor()
{
if( loop_major==0 )
- getLoopMajor();
+ {
+ loop_major = getMajorDevices("loop");
+ y2mil("loop_major:" << loop_major);
+ }
return( loop_major );
}
-void Loop::getLoopMajor()
- {
- loop_major = getMajorDevices( "loop" );
- y2mil("loop_major:" << loop_major);
- }
string Loop::loopDeviceName( unsigned num )
{
@@ -245,7 +234,7 @@
int Loop::setEncryption( bool val, storage::EncryptType typ )
{
- y2mil( "val:" << val << " type:" << typ );
+ y2mil("val:" << val << " enc_type:" << toString(typ));
int ret = Volume::setEncryption( val, typ );
if( ret==0 && encryption!=orig_encryption )
{
@@ -265,9 +254,9 @@
return(ret);
}
-string Loop::removeText( bool doing ) const
+Text Loop::removeText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev;
if( doing )
{
@@ -284,9 +273,9 @@
return( txt );
}
-string Loop::createText( bool doing ) const
+Text Loop::createText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev;
if( doing )
{
@@ -337,9 +326,9 @@
}
-string Loop::formatText( bool doing ) const
+Text Loop::formatText( bool doing ) const
{
- string txt;
+ Text txt;
string d = dev;
if( doing )
{
@@ -397,19 +386,17 @@
void Loop::getInfo( LoopInfo& tinfo ) const
{
- ((Volume*)this)->getInfo( info.v );
+ Volume::getInfo(info.v);
info.nr = num;
info.file = lfile;
info.reuseFile = reuseFile;
tinfo = info;
}
-namespace storage
-{
std::ostream& operator<< (std::ostream& s, const Loop& l )
{
- s << "Loop " << *(Volume*)&l
+ s << "Loop " << dynamic_cast(l)
<< " LoopFile:" << l.lfile;
if( l.reuseFile )
s << " reuse";
@@ -418,7 +405,6 @@
return( s );
}
-}
bool Loop::equalContent( const Loop& rhs ) const
{
@@ -427,46 +413,18 @@
delFile==rhs.delFile );
}
-void Loop::logDifference( const Loop& rhs ) const
+
+ void
+ Loop::logDifference(std::ostream& log, const Loop& rhs) const
{
- string log = Volume::logDifference( rhs );
- if( lfile!=rhs.lfile )
- log += " LoopFile:" + lfile + "-->" + rhs.lfile;
- if( reuseFile!=rhs.reuseFile )
- {
- if( rhs.reuseFile )
- log += " -->reuse";
- else
- log += " reuse-->";
- }
- if( delFile!=rhs.delFile )
- {
- if( rhs.delFile )
- log += " -->delFile";
- else
- log += " delFile-->";
- }
- y2mil(log);
+ Volume::logDifference(log, rhs);
+
+ logDiff(log, "loopfile", lfile, rhs.lfile);
+ logDiff(log, "reusefile", reuseFile, rhs.reuseFile);
+ logDiff(log, "delfile", delFile, rhs.delFile);
}
-Loop& Loop::operator=(const Loop& rhs)
-{
- y2deb("operator= from " << rhs.nm);
- *((Volume*)this) = rhs;
- lfile = rhs.lfile;
- reuseFile = rhs.reuseFile;
- delFile = rhs.delFile;
- return *this;
-}
-
+unsigned Loop::loop_major = 0;
-Loop::Loop(const LoopCo& d, const Loop& rhs)
- : Volume(d)
-{
- y2deb("constructed loop by copy constructor from " << rhs.nm);
- *this = rhs;
}
-
-
-unsigned Loop::loop_major = 0;
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Loop.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Loop.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Loop.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Loop.h Tue May 17 13:39:44 2011
@@ -23,26 +23,29 @@
#ifndef LOOP_H
#define LOOP_H
-#include "y2storage/Volume.h"
+#include "storage/Volume.h"
namespace storage
{
class LoopCo;
-class ProcPart;
+ class SystemInfo;
+
class Loop : public Volume
{
public:
+
Loop( const LoopCo& d, const string& LoopDev, const string& LoopFile,
bool dmcrypt, const string& dm_dev,
- ProcPart& ppart, SystemCmd& losetup );
+ SystemInfo& systeminfo, SystemCmd& losetup);
Loop( const LoopCo& d, const string& file, bool reuseExisting,
unsigned long long sizeK, bool dmcr );
- Loop( const LoopCo& d, const Loop& rhs );
+ Loop(const LoopCo& c, const Loop& v);
virtual ~Loop();
+
const string& loopFile() const { return lfile; }
void setLoopFile( const string& file );
- bool getReuse() { return( reuseFile ); }
+ bool getReuse() const { return reuseFile; }
void setReuse( bool reuseExisting );
void setDelFile( bool val=true ) { delFile=val; }
bool removeFile();
@@ -54,30 +57,37 @@
virtual void print( std::ostream& s ) const { s << *this; }
virtual int setEncryption( bool val, storage::EncryptType typ=storage::ENC_LUKS );
- string removeText( bool doing ) const;
- string createText( bool doing ) const;
- string formatText( bool doing ) const;
+ Text removeText( bool doing ) const;
+ Text createText( bool doing ) const;
+ Text formatText( bool doing ) const;
void getInfo( storage::LoopInfo& info ) const;
bool equalContent( const Loop& rhs ) const;
- void logDifference( const Loop& d ) const;
- static unsigned major();
+
+ void logDifference(std::ostream& log, const Loop& rhs) const;
+
+ static unsigned loopMajor();
static string loopDeviceName( unsigned num );
static bool notDeleted( const Loop& l ) { return( !l.deleted() ); }
protected:
- void init();
+
void checkReuse();
- static void getLoopMajor();
- Loop& operator=( const Loop& );
string lfile;
bool reuseFile;
bool delFile;
static unsigned loop_major;
- mutable storage::LoopInfo info;
+
+ mutable storage::LoopInfo info; // workaround for broken ycp bindings
+
+ private:
+
+ Loop(const Loop&); // disallow
+ Loop& operator=(const Loop&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LoopCo.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LoopCo.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LoopCo.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LoopCo.cc Tue May 17 13:39:44 2011
@@ -19,63 +19,68 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
-#include <iostream>
+#include <ostream>
#include <sstream>
-#include "y2storage/LoopCo.h"
-#include "y2storage/Loop.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/Dm.h"
-#include "y2storage/ProcMounts.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Storage.h"
-#include "y2storage/EtcFstab.h"
-#include "y2storage/StorageDefines.h"
+#include "storage/LoopCo.h"
+#include "storage/Loop.h"
+#include "storage/SystemCmd.h"
+#include "storage/Dm.h"
+#include "storage/SystemInfo.h"
+#include "storage/ProcMounts.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
+#include "storage/EtcFstab.h"
+#include "storage/StorageDefines.h"
-using namespace storage;
-using namespace std;
-
-LoopCo::LoopCo(Storage * const s, bool detect, ProcPart& ppart)
- : Container(s, "loop", staticType())
+namespace storage
{
- y2deb("constructing LoopCo detect:" << detect);
- init();
- if( detect )
- getLoopData( ppart );
-}
+ using namespace std;
-LoopCo::LoopCo(Storage * const s, const string& file)
- : Container(s, "loop", staticType())
-{
- y2deb("constructing LoopCo file:" << file);
- init();
-}
+ LoopCo::LoopCo(Storage* s)
+ : Container(s, "loop", "/dev/loop", staticType())
+ {
+ y2deb("constructing LoopCo");
+ }
-LoopCo::~LoopCo()
-{
- y2deb("destructed LoopCo");
-}
+ LoopCo::LoopCo(Storage* s, SystemInfo& systeminfo)
+ : Container(s, "loop", "/dev/loop", staticType(), systeminfo)
+ {
+ y2deb("constructing LoopCo");
+ getLoopData(systeminfo);
+ }
-void
-LoopCo::init()
+ LoopCo::LoopCo(const LoopCo& c)
+ : Container(c)
+ {
+ y2deb("copy-constructed LoopCo from " << c.dev);
+
+ ConstLoopPair p = c.loopPair();
+ for (ConstLoopIter i = p.begin(); i != p.end(); ++i)
+ {
+ Loop* p = new Loop(*this, *i);
+ vols.push_back(p);
+ }
+ }
+
+
+ LoopCo::~LoopCo()
{
- mjr = Loop::major();
+ y2deb("destructed LoopCo " << dev);
}
+
void
-LoopCo::getLoopData( ProcPart& ppart )
+ LoopCo::getLoopData(SystemInfo& systeminfo)
{
y2mil("begin");
list<FstabEntry> l;
- EtcFstab* fstab = getStorage()->getFstab();
+ const EtcFstab* fstab = getStorage()->getFstab();
fstab->getFileBasedLoops( getStorage()->root(), l );
if( !l.empty() )
{
@@ -95,16 +100,16 @@
{
Loop *l = new Loop( *this, i->loop_dev, lfile,
i->dmcrypt, !i->noauto?i->dentry:"",
- ppart, c );
+ systeminfo, c);
l->setEncryption( i->encr );
- l->setFs( Volume::toFsType(i->fs) );
+ l->setFs(toValueWithFallback(i->fs, FSUNKNOWN));
y2mil( "l:" << *l );
addToList( l );
}
}
LoopPair p=loopPair(Loop::notDeleted);
LoopIter i=p.begin();
- std::map mp = ProcMounts(getStorage()).allMounts();
+ map mp = systeminfo.getProcMounts().allMounts();
while( i!=p.end() )
{
if( i->dmcrypt() )
@@ -138,18 +143,20 @@
}
}
-void LoopCo::loopIds( std::list<unsigned>& l ) const
+
+ list<unsigned>
+ LoopCo::usedNumbers() const
{
- l.clear();
- ConstLoopPair p=loopPair(Loop::notDeleted);
- ConstLoopIter i=p.begin();
- while( i!=p.end() )
- {
- l.push_back( i->nr() );
- ++i;
- }
+ list<unsigned> nums;
+
+ ConstLoopPair p = loopPair(Loop::notDeleted);
+ for (ConstLoopIter i = p.begin(); i != p.end(); ++i)
+ nums.push_back(i->nr());
+
+ return nums;
}
+
bool
LoopCo::findLoop( unsigned num, LoopIter& i )
{
@@ -268,7 +275,7 @@
if( !findLoop( file, i ) && !findLoopDev( file, i ) )
ret = LOOP_UNKNOWN_FILE;
}
- if( ret==0 && i->getUsedByType() != UB_NONE )
+ if (ret == 0 && i->isUsedBy())
{
ret = LOOP_REMOVE_USED_BY;
}
@@ -281,7 +288,7 @@
}
else
{
- i->setDeleted( true );
+ i->setDeleted();
i->setDelFile( removeFile );
}
}
@@ -358,59 +365,28 @@
return( ret );
}
-void LoopCo::logData( const string& Dir ) {;}
-
-namespace storage
-{
-inline std::ostream& operator<< (std::ostream& s, const LoopCo& d )
+ std::ostream& operator<<(std::ostream& s, const LoopCo& d)
{
- s << *((Container*)&d);
+ s << dynamic_cast(d);
return( s );
}
-}
-void LoopCo::logDifference( const Container& d ) const
+ void
+ LoopCo::logDifferenceWithVolumes(std::ostream& log, const Container& rhs_c) const
{
- y2mil(getDiffString(d));
- const LoopCo * p = dynamic_cast(&d);
- if( p != NULL )
- {
- ConstLoopPair pp=loopPair();
- ConstLoopIter i=pp.begin();
- while( i!=pp.end() )
- {
- ConstLoopPair pc=p->loopPair();
- ConstLoopIter j = pc.begin();
- while( j!=pc.end() &&
- (i->device()!=j->device() || i->created()!=j->created()) )
- ++j;
- if( j!=pc.end() )
- {
- if( !i->equalContent( *j ) )
- i->logDifference( *j );
- }
- else
- y2mil( " -->" << *i );
- ++i;
- }
- pp=p->loopPair();
- i=pp.begin();
- while( i!=pp.end() )
- {
- ConstLoopPair pc=loopPair();
- ConstLoopIter j = pc.begin();
- while( j!=pc.end() &&
- (i->device()!=j->device() || i->created()!=j->created()) )
- ++j;
- if( j==pc.end() )
- y2mil( " <--" << *i );
- ++i;
- }
- }
+ const LoopCo& rhs = dynamic_cast(rhs_c);
+
+ logDifference(log, rhs);
+ log << endl;
+
+ ConstLoopPair pp = loopPair();
+ ConstLoopPair pc = rhs.loopPair();
+ logVolumesDifference(log, pp.begin(), pp.end(), pc.begin(), pc.end());
}
+
bool LoopCo::equalContent( const Container& rhs ) const
{
const LoopCo * p = NULL;
@@ -421,29 +397,10 @@
{
ConstLoopPair pp = loopPair();
ConstLoopPair pc = p->loopPair();
- ConstLoopIter i = pp.begin();
- ConstLoopIter j = pc.begin();
- while( ret && i!=pp.end() && j!=pc.end() )
- {
- ret = ret && i->equalContent( *j );
- ++i;
- ++j;
- }
- ret = ret && i==pp.end() && j==pc.end();
+ ret = ret && storage::equalContent(pp.begin(), pp.end(), pc.begin(), pc.end());
}
return( ret );
}
-LoopCo::LoopCo(const LoopCo& rhs)
- : Container(rhs)
-{
- y2deb("constructed LoopCo by copy constructor from " << rhs.nm);
- *this = rhs;
- ConstLoopPair p = rhs.loopPair();
- for( ConstLoopIter i=p.begin(); i!=p.end(); ++i )
- {
- Loop * p = new Loop( *this, *i );
- vols.push_back( p );
- }
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LoopCo.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LoopCo.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LoopCo.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LoopCo.h Tue May 17 13:39:44 2011
@@ -23,22 +23,26 @@
#ifndef LOOP_CO_H
#define LOOP_CO_H
-#include "y2storage/Container.h"
-#include "y2storage/Loop.h"
+#include "storage/Container.h"
+#include "storage/Loop.h"
+
namespace storage
{
-class ProcPart;
+ class SystemInfo;
+
class LoopCo : public Container
{
friend class Storage;
public:
- LoopCo( Storage * const s, bool detect, ProcPart& ppart );
- LoopCo( const LoopCo& rhs );
+ LoopCo(Storage * const s);
+ LoopCo(Storage * const s, SystemInfo& systeminfo);
+ LoopCo(const LoopCo& c);
virtual ~LoopCo();
+
static storage::CType staticType() { return storage::LOOP; }
friend std::ostream& operator<< (std::ostream&, const LoopCo& );
@@ -47,11 +51,13 @@
int updateLoop( const string& device, const string& file,
bool reuseExisting, unsigned long long sizeK );
int removeLoop( const string& file, bool removeFile = false );
- void loopIds( std::list<unsigned>& l ) const;
+
+ list<unsigned> usedNumbers() const;
int removeVolume( Volume* v );
bool equalContent( const Container& rhs ) const;
- void logDifference( const Container& d ) const;
+
+ virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
protected:
// iterators over LOOP volumes
@@ -102,18 +108,13 @@
return( ConstLoopIter( LoopCPIterator( p, Check, true )) );
}
- LoopCo( Storage * const s, const string& File );
-
- void getLoopData( ProcPart& ppart );
+ void getLoopData(SystemInfo& systeminfo);
bool findLoop( unsigned num, LoopIter& i );
bool findLoop( unsigned num );
bool findLoop( const string& file, LoopIter& i );
bool findLoop( const string& file );
bool findLoopDev( const string& dev, LoopIter& i );
void addLoop( Loop* m );
- void updateEntry( const Loop* m );
-
- void init();
virtual void print( std::ostream& s ) const { s << *this; }
virtual Container* getCopy() const { return( new LoopCo( *this ) ); }
@@ -121,7 +122,10 @@
int doCreate( Volume* v );
int doRemove( Volume* v );
- void logData( const string& Dir );
+ private:
+
+ LoopCo& operator=(const LoopCo&); // disallow
+
};
}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lsscsi.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lsscsi.cc?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lsscsi.cc (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lsscsi.cc Tue May 17 13:39:44 2011
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2010 Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include
+
+#include "storage/AppUtil.h"
+#include "storage/SystemCmd.h"
+#include "storage/StorageDefines.h"
+#include "storage/Lsscsi.h"
+#include "storage/Enum.h"
+
+
+namespace storage
+{
+ using namespace std;
+
+
+ Lsscsi::Lsscsi()
+ {
+ SystemCmd cmd(LSSCSIBIN " --transport");
+ if (cmd.retcode() == 0)
+ parse(cmd.stdout());
+ }
+
+
+ void
+ Lsscsi::parse(const vector<string>& lines)
+ {
+ data.clear();
+
+ for (vector<string>::const_iterator it = lines.begin(); it != lines.end(); ++it)
+ {
+ string line = boost::replace_all_copy(*it, " usb: ", " usb:");
+
+ string transport = extractNthWord(2, line);
+ string device = extractNthWord(3, line);
+
+ if (!boost::starts_with(device, "/dev/"))
+ continue;
+
+ Entry entry;
+
+ if (boost::starts_with(transport, "sbp:"))
+ entry.transport = SBP;
+ else if (boost::starts_with(transport, "ata:"))
+ entry.transport = ATA;
+ else if (boost::starts_with(transport, "fc:"))
+ entry.transport = FC;
+ else if (boost::starts_with(transport, "iqn"))
+ entry.transport = ISCSI;
+ else if (boost::starts_with(transport, "sas:"))
+ entry.transport = SAS;
+ else if (boost::starts_with(transport, "sata:"))
+ entry.transport = SATA;
+ else if (boost::starts_with(transport, "spi:"))
+ entry.transport = SPI;
+ else if (boost::starts_with(transport, "usb:"))
+ entry.transport = USB;
+
+ data[device] = entry;
+ }
+
+ for (const_iterator it = data.begin(); it != data.end(); ++it)
+ y2mil("data[" << it->first << "] -> " << it->second);
+ }
+
+
+ bool
+ Lsscsi::getEntry(const string& device, Entry& entry) const
+ {
+ const_iterator i = data.find(device);
+ if (i == data.end())
+ return false;
+
+ entry = i->second;
+ return true;
+ }
+
+
+ std::ostream& operator<<(std::ostream& s, const Lsscsi::Entry& entry)
+ {
+ return s << "transport:" << toString(entry.transport);
+ }
+
+}
Added: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lsscsi.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lsscsi.h?rev=64012&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lsscsi.h (added)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Lsscsi.h Tue May 17 13:39:44 2011
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2010 Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef LSSCSI_H
+#define LSSCSI_H
+
+#include <string>
+#include <map>
+#include <vector>
+
+#include "storage/StorageInterface.h"
+
+
+namespace storage
+{
+ using std::map;
+ using std::vector;
+
+
+ class Lsscsi
+ {
+ public:
+
+ Lsscsi();
+
+ struct Entry
+ {
+ Entry() : transport(TUNKNOWN) {}
+
+ Transport transport;
+ };
+
+ friend std::ostream& operator<<(std::ostream& s, const Entry& entry);
+
+ bool getEntry(const string& device, Entry& entry) const;
+
+ protected:
+
+ void parse(const vector<string>& lines);
+
+ typedef map::const_iterator const_iterator;
+
+ map data;
+
+ };
+
+}
+
+
+#endif
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmLv.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmLv.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmLv.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmLv.cc Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -19,30 +19,28 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
#include <sstream>
+#include
+
+#include "storage/LvmLv.h"
+#include "storage/LvmVg.h"
+#include "storage/SystemCmd.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
+#include "storage/StorageDefines.h"
+
+
+namespace storage
+{
+ using namespace std;
-#include "y2storage/LvmLv.h"
-#include "y2storage/LvmVg.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Storage.h"
-#include "y2storage/StorageDefines.h"
-
-using namespace storage;
-using namespace std;
-
-
-LvmLv::LvmLv(const LvmVg& d, const string& name, const string& origi,
- unsigned long le, const string& uuid, const string& stat,
- const string& alloc)
- : Dm( d, dupDash(d.name())+"-"+dupDash(name) ),
- origin(origi)
+
+ LvmLv::LvmLv(const LvmVg& c, const string& name, const string& device, const string& origi,
+ unsigned long le, const string& uuid, const string& stat, const string& alloc)
+ : Dm(c, name, device, makeDmTableName(c.name(), name)), origin(origi)
{
- init( name );
+ Dm::init();
setUuid( uuid );
setStatus( stat );
setAlloc( alloc );
@@ -54,26 +52,50 @@
}
-LvmLv::LvmLv(const LvmVg& d, const string& name, const string& origi,
- unsigned long le, unsigned str)
- : Dm( d, dupDash(d.name())+"-"+dupDash(name) ),
- origin(origi)
+ LvmLv::LvmLv(const LvmVg& c, const string& name, const string& device, const string& origi,
+ unsigned long le, unsigned str)
+ : Dm(c, name, device, makeDmTableName(c.name(), name)), origin(origi)
{
- init( name );
+ Dm::init();
setLe( le );
calcSize();
stripe = str;
fs = detected_fs = FSNONE;
- alt_names.push_back( "/dev/mapper/" + dupDash(cont->name()) + "-" + dupDash(name) );
+ alt_names.push_back("/dev/mapper/" + getTableName());
y2deb("constructed lvm lv dev:" << dev << " vg:" << cont->name() << " origin:" << origin);
}
-LvmLv::~LvmLv()
-{
- y2deb("destructed lvm lv dev:" << dev);
-}
+ LvmLv::LvmLv(const LvmVg& c, const xmlNode* node)
+ : Dm(c, node)
+ {
+ assert(!numeric);
+ assert(num == 0);
+
+ y2deb("constructed LvmLv " << dev);
+ }
+
+
+ LvmLv::LvmLv(const LvmVg& c, const LvmLv& v)
+ : Dm(c, v), origin(v.origin), vol_uuid(v.vol_uuid), status(v.status),
+ allocation(v.allocation)
+ {
+ y2deb("copy-constructed LvmLv " << dev);
+ }
+
+
+ LvmLv::~LvmLv()
+ {
+ y2deb("destructed LvmLv " << dev);
+ }
+
+
+ void
+ LvmLv::saveData(xmlNode* node) const
+ {
+ Dm::saveData(node);
+ }
const LvmVg* LvmLv::vg() const
@@ -82,11 +104,11 @@
}
-void LvmLv::init( const string& name )
+ string
+ LvmLv::makeDmTableName(const string& vg_name, const string& lv_name)
{
- nm = name;
- dev = normalizeDevice( cont->name() + "/" + name );
- Dm::init();
+ return boost::replace_all_copy(vg_name, "-", "--") + "-" +
+ boost::replace_all_copy(lv_name, "-", "--");
}
@@ -98,7 +120,7 @@
}
else
{
- LvmVg::ConstLvmLvPair p = vg()->LvmVg::lvmLvPair(LvmVg::lvNotDeleted);
+ LvmVg::ConstLvmLvPair p = vg()->LvmVg::lvmLvPair(LvmLv::notDeleted);
LvmVg::ConstLvmLvIter i = p.begin();
while( i!=p.end() && i->name()!=origin )
++i;
@@ -118,7 +140,7 @@
bool
LvmLv::hasSnapshots() const
{
- LvmVg::ConstLvmLvPair p = vg()->LvmVg::lvmLvPair(LvmVg::lvNotDeleted);
+ LvmVg::ConstLvmLvPair p = vg()->LvmVg::lvmLvPair(LvmLv::notDeleted);
LvmVg::ConstLvmLvIter i = p.begin();
while( i!=p.end() && i->getOrigin()!=name() )
++i;
@@ -135,7 +157,7 @@
{
for (unsigned int l = 1; l < cmd.numLines(); l++)
{
- string line = *cmd.getLine(l);
+ string line = cmd.getLine(l);
if (extractNthWord(0, line) == name())
{
@@ -150,9 +172,9 @@
}
-string LvmLv::removeText( bool doing ) const
+Text LvmLv::removeText( bool doing ) const
{
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by device name e.g. /dev/system/var
@@ -168,9 +190,9 @@
return( txt );
}
-string LvmLv::createText( bool doing ) const
+Text LvmLv::createText( bool doing ) const
{
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by device name e.g. /dev/system/var
@@ -219,9 +241,9 @@
return( txt );
}
-string LvmLv::formatText( bool doing ) const
+Text LvmLv::formatText( bool doing ) const
{
- string txt;
+ Text txt;
if( doing )
{
// displayed text during action, %1$s is replaced by device name e.g. /dev/system/var
@@ -275,9 +297,9 @@
return( txt );
}
-string LvmLv::resizeText( bool doing ) const
+Text LvmLv::resizeText( bool doing ) const
{
- string txt;
+ Text txt;
if( doing )
{
if( needShrink() )
@@ -288,8 +310,9 @@
// displayed text during action, %1$s is replaced by device name e.g. /dev/system/var
// %2$s is replaced by size (e.g. 623.5 MB)
txt = sformat( _("Extending logical volume %1$s to %2$s"), dev.c_str(), sizeString().c_str() );
+ txt += Text(" ", " ");
// text displayed during action
- txt += string(" ") + _("(progress bar might not move)");
+ txt += _("(progress bar might not move)");
}
else
{
@@ -308,9 +331,9 @@
void LvmLv::getInfo( LvmLvInfo& tinfo ) const
{
- ((Volume*)this)->getInfo( info.v );
- info.stripe = stripe;
- info.stripe_size = stripe_size;
+ Volume::getInfo(info.v);
+ info.stripes = stripe;
+ info.stripeSizeK = stripe_size;
info.uuid = vol_uuid;
info.status = status;
info.allocation = allocation;
@@ -323,12 +346,10 @@
tinfo = info;
}
-namespace storage
-{
std::ostream& operator<< (std::ostream& s, const LvmLv &p )
{
- s << *(Dm*)&p;
+ s << dynamic_cast(p);
if( !p.vol_uuid.empty() )
s << " UUID:" << p.vol_uuid;
if( !p.status.empty() )
@@ -338,7 +359,6 @@
return( s );
}
-}
bool LvmLv::equalContent( const LvmLv& rhs ) const
{
@@ -347,31 +367,15 @@
allocation==rhs.allocation );
}
-void LvmLv::logDifference( const LvmLv& rhs ) const
- {
- string log = stringDifference( rhs );
- if( vol_uuid!=rhs.vol_uuid )
- log += " UUID:" + vol_uuid + "-->" + rhs.vol_uuid;
- if( status!=rhs.status )
- log += " Status:" + status + "-->" + rhs.status;
- if( allocation!=rhs.allocation )
- log += " Alloc:" + allocation + "-->" + rhs.allocation;
- y2mil(log);
- }
-LvmLv& LvmLv::operator= ( const LvmLv& rhs )
+ void
+ LvmLv::logDifference(std::ostream& log, const LvmLv& rhs) const
{
- y2deb("operator= from " << rhs.nm);
- *((Dm*)this) = rhs;
- vol_uuid = rhs.vol_uuid;
- status = rhs.status;
- allocation = rhs.allocation;
- return( *this );
- }
+ Dm::logDifference(log, rhs);
-LvmLv::LvmLv( const LvmVg& d, const LvmLv& rhs ) : Dm(d,rhs)
- {
- y2deb("constructed lvm lv by copy constructor from " << rhs.dev);
- *this = rhs;
+ logDiff(log, "vol_uuid", vol_uuid, rhs.vol_uuid);
+ logDiff(log, "status", status, rhs.status);
+ logDiff(log, "alloc", allocation, rhs.allocation);
}
+}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmLv.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmLv.h?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmLv.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmLv.h Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -23,9 +23,8 @@
#ifndef LVM_LV_H
#define LVM_LV_H
-#include <map>
+#include "storage/Dm.h"
-#include "y2storage/Dm.h"
namespace storage
{
@@ -35,14 +34,17 @@
class LvmLv : public Dm
{
public:
- LvmLv(const LvmVg& d, const string& name, const string& origin, unsigned long le,
- const string& uuid, const string& status, const string& alloc);
- LvmLv(const LvmVg& d, const string& name, const string& origin, unsigned long le,
- unsigned stripe);
- LvmLv(const LvmVg& d, const LvmLv& l);
+ LvmLv(const LvmVg& c, const string& name, const string& device, const string& origin,
+ unsigned long le, const string& uuid, const string& status, const string& alloc);
+ LvmLv(const LvmVg& c, const string& name, const string& device, const string& origin,
+ unsigned long le, unsigned stripe);
+ LvmLv(const LvmVg& c, const xmlNode* node);
+ LvmLv(const LvmVg& c, const LvmLv& v);
virtual ~LvmLv();
+ void saveData(xmlNode* node) const;
+
const LvmVg* vg() const;
void calcSize();
@@ -60,25 +62,35 @@
void setAlloc( const string& a ) { allocation=a; }
friend std::ostream& operator<< (std::ostream& s, const LvmLv &p );
virtual void print( std::ostream& s ) const { s << *this; }
- string removeText( bool doing ) const;
- string createText( bool doing ) const;
- string formatText( bool doing ) const;
- string resizeText( bool doing ) const;
+ Text removeText( bool doing ) const;
+ Text createText( bool doing ) const;
+ Text formatText( bool doing ) const;
+ Text resizeText( bool doing ) const;
void getInfo( storage::LvmLvInfo& info ) const;
bool equalContent( const LvmLv& rhs ) const;
- void logDifference( const LvmLv& d ) const;
+
+ void logDifference(std::ostream& log, const LvmLv& rhs) const;
+
+ static bool notDeleted(const LvmLv& l) { return !l.deleted(); }
protected:
- void init( const string& name );
- virtual const string shortPrintedName() const { return( "Lv" ); }
- LvmLv& operator=( const LvmLv& );
+ static string makeDmTableName(const string& vg_name, const string& lv_name);
+
+ virtual const string shortPrintedName() const { return "Lv"; }
string origin; // only for snapshots, empty otherwise
string vol_uuid;
string status;
string allocation;
- mutable storage::LvmLvInfo info;
+
+ mutable storage::LvmLvInfo info; // workaround for broken ycp bindings
+
+ private:
+
+ LvmLv(const LvmLv&); // disallow
+ LvmLv& operator=(const LvmLv&); // disallow
+
};
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmVg.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmVg.cc?rev=64012&r1=64011&r2=64012&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmVg.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/LvmVg.cc Tue May 17 13:39:44 2011
@@ -1,5 +1,5 @@
/*
- * Copyright (c) [2004-2009] Novell, Inc.
+ * Copyright (c) [2004-2010] Novell, Inc.
*
* All Rights Reserved.
*
@@ -19,88 +19,112 @@
* find current contact information at www.novell.com.
*/
-/*
- Textdomain "storage"
-*/
-#include <iostream>
+#include <ostream>
#include <sstream>
-#include "y2storage/LvmVg.h"
-#include "y2storage/LvmLv.h"
-#include "y2storage/SystemCmd.h"
-#include "y2storage/AppUtil.h"
-#include "y2storage/Storage.h"
-#include "y2storage/StorageDefines.h"
+#include "storage/LvmVg.h"
+#include "storage/LvmLv.h"
+#include "storage/SystemCmd.h"
+#include "storage/AppUtil.h"
+#include "storage/Storage.h"
+#include "storage/StorageDefines.h"
+
+
+namespace storage
+{
+ using namespace std;
-using namespace std;
-using namespace storage;
static bool lvNotCreated( const LvmLv& l ) { return( !l.created() ); }
static bool lvNotDeletedCreated( const LvmLv& l ) { return( !l.created()&&!l.deleted() ); }
-LvmVg::LvmVg( Storage * const s, const string& Name ) :
- PeContainer(s,staticType())
+
+ LvmVg::LvmVg(Storage* s, const string& name, const string& device, bool lvm1)
+ : PeContainer(s, name, device, staticType()), lvm1(lvm1)
{
- nm = Name;
- y2deb("constructing lvm vg " << Name);
- init();
- if( !Name.empty() )
- {
- getVgData( Name, false );
- LvmLvPair p=lvmLvPair(lvNotCreated);
- if( !p.empty() )
- getStorage()->waitForDevice( p.begin()->device() );
- }
- else
- {
- y2err("empty name in constructor");
- }
+ y2deb("constructing LvmVg name:" << name << " lvm1:" << lvm1);
+ setCreated(true);
+ }
+
+
+ LvmVg::LvmVg(Storage* s, const string& name, const string& device, SystemInfo& systeminfo)
+ : PeContainer(s, name, device, staticType(), systeminfo), lvm1(false)
+ {
+ y2deb("constructing LvmVg name:" << name);
+ getVgData(name, false);
}
-LvmVg::LvmVg( Storage * const s, const string& Name, bool lv1 ) :
- PeContainer(s,staticType())
+
+ LvmVg::LvmVg(Storage* s, const xmlNode* node)
+ : PeContainer(s, staticType(), node), lvm1(false)
+ {
+ const list l = getChildNodes(node, "logical_volume");
+ for (list::const_iterator it = l.begin(); it != l.end(); ++it)
+ addToList(new LvmLv(*this, *it));
+
+ y2deb("constructed LvmVg " << dev);
+ }
+
+
+ LvmVg::LvmVg(const LvmVg& c)
+ : PeContainer(c), status(c.status), uuid(c.uuid), lvm1(c.lvm1)
{
- nm = Name;
- y2debug( "constructing lvm vg %s lvm1:%d", Name.c_str(), lv1 );
- init();
- lvm1 = lv1;
- if( Name.empty() )
+ y2deb("copy-constructed LvmVg " << dev);
+
+ ConstLvmLvPair p = c.lvmLvPair();
+ for (ConstLvmLvIter i = p.begin(); i != p.end(); ++i)
{
- y2error("empty name in constructor");
+ LvmLv* p = new LvmLv(*this, *i);
+ vols.push_back(p);
}
}
-LvmVg::LvmVg( Storage * const s, const string& file, int ) :
- PeContainer(s,staticType())
+
+ LvmVg::~LvmVg()
{
- y2debug( "constructing lvm vg %s from file %s", dev.c_str(), file.c_str() );
+ y2deb("destructed LvmVg " << dev);
}
-LvmVg::~LvmVg()
+
+ void
+ LvmVg::saveData(xmlNode* node) const
{
- y2deb("destructed lvm vg " << dev);
+ PeContainer::saveData(node);
+
+ ConstLvmLvPair vp = lvmLvPair();
+ for (ConstLvmLvIter v = vp.begin(); v != vp.end(); ++v)
+ v->saveData(xmlNewChild(node, "logical_volume"));
}
+
static bool lvDeleted( const LvmLv& l ) { return( l.deleted() ); }
static bool lvCreated( const LvmLv& l ) { return( l.created() ); }
static bool lvResized( const LvmLv& l ) { return( l.extendSize()!=0 ); }
+
+unsigned
+LvmVg::numLv() const
+{
+ return lvmLvPair(LvmLv::notDeleted).length();
+}
+
+
int
LvmVg::removeVg()
{
int ret = 0;
- y2milestone( "begin" );
+ y2mil("begin");
if( readonly() )
{
ret = LVM_CHANGE_READONLY;
}
if( ret==0 && !created() )
{
- LvmLvPair p=lvmLvPair(lvNotDeleted);
+ LvmLvPair p = lvmLvPair(LvmLv::notDeleted);
for( LvmLvIter i=p.begin(); i!=p.end(); ++i )
ret = removeLv( i->name() );
- setDeleted( true );
+ setDeleted();
}
if( ret==0 )
{
@@ -132,6 +156,10 @@
{
ret = LVM_CHANGE_READONLY;
}
+ else if( devs.empty() )
+ {
+ ret = LVM_LIST_EMPTY;
+ }
while( ret==0 && i!=devs.end() )
{
string d = normalizeDevice( *i );
@@ -180,9 +208,10 @@
if( !getStorage()->isDisk(d))
getStorage()->changeFormatVolume( d, false, FSNONE );
}
- getStorage()->setUsedBy( d, UB_LVM, name() );
+ getStorage()->setUsedBy(d, UB_LVM, device());
free_pe += pe;
num_pe += pe;
+ calcSize();
++i;
}
if( ret==0 && pv_add.size()+pv.size()-pv_remove.size()<=0 )
@@ -221,6 +250,10 @@
{
ret = LVM_CHANGE_READONLY;
}
+ else if( devs.empty() )
+ {
+ ret = LVM_LIST_EMPTY;
+ }
list<string>::const_iterator i = devs.begin();
while( ret==0 && i!=devs.end() )
@@ -239,6 +272,7 @@
pv_remove = plrem;
free_pe -= rem_pe;
num_pe -= rem_pe;
+ calcSize();
}
if( ret==0 )
checkConsistency();
@@ -254,7 +288,7 @@
LvmVg::setPeSize( long long unsigned peSizeK )
{
int ret = 0;
- y2milestone( "old:%llu new:%llu", pe_size, peSizeK );
+ y2mil("old:" << pe_size << " new:" << peSizeK);
if( peSizeK != pe_size )
{
unsigned long long old_pe = pe_size;
@@ -279,7 +313,7 @@
string& device )
{
int ret = 0;
- y2milestone( "name:%s sizeK:%llu stripe:%u", name.c_str(), sizeK, stripe );
+ y2mil("name:" << name << " sizeK:" << sizeK << " stripe:" << stripe);
checkConsistency();
if( readonly() )
{
@@ -291,8 +325,8 @@
}
if( ret==0 )
{
- LvmLvPair p=lvmLvPair(lvNotDeleted);
- LvmLvIter i=p.begin();
+ ConstLvmLvPair p = lvmLvPair(LvmLv::notDeleted);
+ ConstLvmLvIter i = p.begin();
while( i!=p.end() && i->name()!=name )
++i;
if( i!=p.end() )
@@ -310,7 +344,7 @@
ret = addLvPeDistribution( num_le, stripe, pv, pv_add, pe_map );
if( ret==0 )
{
- LvmLv* l = new LvmLv( *this, name, "", num_le, stripe );
+ LvmLv* l = new LvmLv( *this, name, dev + "/" + name, "", num_le, stripe );
l->setCreated( true );
l->setPeMap( pe_map );
device = l->device();
@@ -319,14 +353,14 @@
}
if( ret==0 )
checkConsistency();
- y2milestone( "ret:%d device:%s", ret, ret?"":device.c_str() );
+ y2mil("ret:" << ret << " device:" << (ret?"":device));
return( ret );
}
int LvmVg::resizeVolume( Volume* v, unsigned long long newSize )
{
int ret = 0;
- y2milestone( "newSizeK:%llu vol:%s", newSize, v->name().c_str() );
+ y2mil("newSizeK:" << newSize << " vol:" << v->name());
checkConsistency();
LvmLv * l = dynamic_cast(v);
@@ -405,7 +439,7 @@
LvmVg::removeLv( const string& name )
{
int ret = 0;
- y2milestone( "name:%s", name.c_str() );
+ y2mil("name:" << name);
LvmLvIter i;
checkConsistency();
if( readonly() )
@@ -414,7 +448,7 @@
}
if( ret==0 )
{
- LvmLvPair p=lvmLvPair(lvNotDeleted);
+ LvmLvPair p = lvmLvPair(LvmLv::notDeleted);
i=p.begin();
while( i!=p.end() && i->name()!=name )
++i;
@@ -423,9 +457,10 @@
else if (i->hasSnapshots())
ret = LVM_LV_HAS_SNAPSHOTS;
}
- if( ret==0 && i->getUsedByType() != UB_NONE )
+ if (ret == 0 && i->isUsedBy())
{
- if( getStorage()->getRecursiveRemoval() )
+ if( getStorage()->getRecursiveRemoval() ||
+ getStorage()->isUsedBySingleBtrfs(*i) )
ret = getStorage()->removeUsing( i->device(), i->getUsedBy() );
else
ret = LVM_LV_REMOVE_USED_BY;
@@ -444,7 +479,7 @@
ret = LVM_LV_NOT_IN_LIST;
}
else
- i->setDeleted( true );
+ i->setDeleted();
}
y2mil("ret:" << ret);
return( ret );
@@ -454,7 +489,7 @@
LvmVg::changeStripe( const string& name, unsigned long stripe )
{
int ret = 0;
- y2milestone( "name:%s stripe:%lu", name.c_str(), stripe );
+ y2mil("name:" << name << " stripe:" << stripe);
LvmLvIter i;
checkConsistency();
if( readonly() )
@@ -463,7 +498,7 @@
}
if( ret==0 )
{
- LvmLvPair p=lvmLvPair(lvNotDeleted);
+ LvmLvPair p = lvmLvPair(LvmLv::notDeleted);
i=p.begin();
while( i!=p.end() && i->name()!=name )
++i;
@@ -506,7 +541,7 @@
LvmVg::changeStripeSize( const string& name, unsigned long long stripeSize )
{
int ret = 0;
- y2milestone( "name:%s stripeSize:%llu", name.c_str(), stripeSize );
+ y2mil("name:" << name << " stripeSize:" << stripeSize);
LvmLvIter i;
checkConsistency();
if( readonly() )
@@ -515,7 +550,7 @@
}
if( ret==0 )
{
- LvmLvPair p=lvmLvPair(lvNotDeleted);
+ LvmLvPair p = lvmLvPair(LvmLv::notDeleted);
i=p.begin();
while( i!=p.end() && i->name()!=name )
++i;
@@ -558,7 +593,7 @@
int stripe = 1;
if (ret == 0)
{
- LvmLvPair p = lvmLvPair(lvNotDeleted);
+ LvmLvPair p = lvmLvPair(LvmLv::notDeleted);
LvmLvIter i = p.begin();
while (i != p.end() && i->name() != origin)
++i;
@@ -569,7 +604,7 @@
}
if (ret == 0)
{
- LvmLvPair p = lvmLvPair(lvNotDeleted);
+ LvmLvPair p = lvmLvPair(LvmLv::notDeleted);
LvmLvIter i = p.begin();
while (i != p.end() && i->name() != name)
++i;
@@ -588,7 +623,7 @@
ret = addLvPeDistribution(num_le, stripe, pv, pv_add, pe_map);
if (ret == 0)
{
- LvmLv* l = new LvmLv(*this, name, origin, num_le, stripe);
+ LvmLv* l = new LvmLv(*this, name, dev + "/" + name, origin, num_le, stripe);
l->setCreated(true);
l->setPeMap(pe_map);
device = l->device();
@@ -609,7 +644,7 @@
y2mil("name:" << name);
if( ret==0 )
{
- LvmLvPair p=lvmLvPair(lvNotDeleted);
+ LvmLvPair p = lvmLvPair(LvmLv::notDeleted);
LvmLvIter i=p.begin();
while( i!=p.end() && i->name()!=name )
++i;
@@ -636,7 +671,7 @@
checkConsistency();
if (ret == 0)
{
- LvmLvPair p=lvmLvPair(lvNotDeleted);
+ LvmLvPair p = lvmLvPair(LvmLv::notDeleted);
i=p.begin();
while( i!=p.end() && i->name()!=name )
++i;
@@ -660,20 +695,19 @@
void LvmVg::getVgData( const string& name, bool exists )
{
- y2milestone( "name:%s", name.c_str() );
+ y2mil("name:" << name);
SystemCmd c(VGDISPLAYBIN " --units k -v " + quote(name));
unsigned cnt = c.numLines();
unsigned i = 0;
- num_lv = 0;
string line;
string tmp;
string::size_type pos;
while( i> pes;
if( exists && pes != pe_size )
- y2warning( "inconsistent pe_size my:%llu lvm:%llu",
- pe_size, pes );
+ y2war("inconsistent pe_size my:" << pe_size << " lvm:" << pes);
pe_size = pes;
+ calcSize();
}
else if( line.find( "Total PE" ) == 0 )
{
extractNthWord( 2, line ) >> num_pe;
+ calcSize();
}
else if( line.find( "Free PE" ) == 0 )
{
@@ -720,7 +754,7 @@
{
uuid = extractNthWord( 2, line );
}
- line = *c.getLine( i++ );
+ line = c.getLine( i++ );
}
string vname;
string origin;
@@ -778,7 +812,7 @@
{
uuid = extractNthWord( 2, line );
}
- line = *c.getLine( i++ );
+ line = c.getLine( i++ );
}
if( !vname.empty() )
{
@@ -816,8 +850,9 @@
{
extractNthWord( 5, line ) >> p->num_pe;
extractNthWord( 7, line ) >> p->free_pe;
+ calcSize();
}
- line = *c.getLine( i++ );
+ line = c.getLine( i++ );
}
if( !p->device.empty() )
{
@@ -837,7 +872,6 @@
p=lvmLvPair(lvCreated);
for( LvmLvIter i=p.begin(); i!=p.end(); ++i )
{
- num_lv++;
//cout << "Created:" << *i << endl;
map pe_map;
if( addLvPeDistribution( i->getLe(), i->stripes(), pv, pv_add,
@@ -864,24 +898,19 @@
}
free_pe -= size_diff;
}
- if( num_lv>0 && lvmLvPair().empty() )
- {
- y2milestone( "inactive VG %s num_lv:%u", nm.c_str(), num_lv );
- inactiv = true;
- }
}
void LvmVg::addLv(unsigned long& le, string& name, string& origin, string& uuid,
string& status, string& alloc, bool& ro)
{
- y2milestone( "addLv:%s", name.c_str() );
+ y2mil("addLv:" << name);
LvmLvPair p=lvmLvPair(lvNotDeletedCreated);
LvmLvIter i=p.begin();
while( i!=p.end() && i->name()!=name )
{
++i;
}
- y2milestone( "addLv exists %d", i!=p.end() );
+ y2mil("addLv exists " << (i!=p.end()));
if( i!=p.end() )
{
if( !lvResized( *i ))
@@ -907,18 +936,17 @@
{
++i;
}
- y2milestone( "addLv exists deleted %d", i!=p.end() );
+ y2mil("addLv exists deleted " << (i!=p.end()));
if( i==p.end() )
{
- num_lv++;
- LvmLv *n = new LvmLv( *this, name, origin, le, uuid, status, alloc );
+ LvmLv *n = new LvmLv( *this, name, dev + "/" + name, origin, le, uuid, status, alloc );
if( ro )
n->setReadonly();
if( !n->inactive() )
addToList( n );
else
{
- y2milestone( "inactive Lv %s", name.c_str() );
+ y2mil("inactive Lv " << name);
delete n;
}
}
@@ -931,17 +959,18 @@
void LvmVg::addPv( Pv*& p )
{
- PeContainer::addPv( p );
+ PeContainer::addPv( *p );
if( !deleted() &&
find( pv_remove.begin(), pv_remove.end(), *p )==pv_remove.end() )
- getStorage()->setUsedBy( p->device, UB_LVM, name() );
+ getStorage()->setUsedBy(p->device, UB_LVM, device());
+ delete p;
p = new Pv;
}
-int LvmVg::getToCommit( CommitStage stage, list