commit 343d53a31a9e438dae3ba53c8778fa50d0660286
Merge: 6af5421 5e68cc5
Author: Klaus Aehlig <[email protected]>
Date: Wed Apr 8 16:26:01 2015 +0200
Merge branch 'stable-2.12' into stable-2.13
* stable-2.12
Fix typos
* stable-2.11
(no changes)
* stable-2.10
fix typos in design-file-based-storage.rst doc
Switch to our osminor
Provide an alternative for os.minor working around its bug
Fix typo
CanTieredAlloc test: make instances big enough
After master-failover verify reachability of master IP
Report failure to deactivate old master IP in exit code
Expose warnings during master-failover
Fix manpage for gnt-cluster copyfile
Conflicts:
lib/storage/bdev.py: trivial
lib/utils/storage.py: take stable-2.13
Signed-off-by: Klaus Aehlig <[email protected]>
diff --cc lib/utils/storage.py
index c8aa2b9,e742d5e..0b7e388
--- a/lib/utils/storage.py
+++ b/lib/utils/storage.py
@@@ -220,73 -217,11 +220,83 @@@ def GetDiskLabels(prefix, num_disks, st
yield prefix + _GetDiskSuffix(i)
+def CreateBdevPartitionMapping(image_path):
+ """Create dm device for each partition of disk image.
+
+ This operation will allocate a loopback and a device-mapper device to map
+ partitions.
+ You must call L{ReleaseBdevPartitionMapping} to clean up resources allocated
+ by this function call.
+
+ @type image_path: string
+ @param image_path: path of multi-partition disk image
+ @rtype: tuple(string, list(string)) or NoneType
+ @return: returns the tuple(loopback_device, list(device_mapper_files)) if
+ image_path is a multi-partition disk image. otherwise, returns None.
+
+ """
+ # Unfortunately, there are two different losetup commands in this world.
+ # One has the '-s' switch and the other has the '--show' switch to provide
the
+ # same functionality.
+ result = utils_process.RunCmd(["losetup", "-f", "-s", image_path])
+ if result.failed and "invalid option -- 's'" in result.stderr:
+ result = utils_process.RunCmd(["losetup", "-f", "--show", image_path])
+ if result.failed:
+ raise errors.CommandError("Failed to setup loop device for %s: %s" %
+ (image_path, result.output))
+ loop_dev_path = result.stdout.strip()
+ logging.debug("Loop dev %s allocated for %s", loop_dev_path, image_path)
+
+ result = utils_process.RunCmd(["kpartx", "-a", "-v", loop_dev_path])
+ if result.failed:
+ # Just try to cleanup allocated loop device
+ utils_process.RunCmd(["losetup", "-d", loop_dev_path])
+ raise errors.CommandError("Failed to add partition mapping for %s: %s" %
+ (image_path, result.output))
+ dm_devs = [x.split(" ") for x in result.stdout.split("\n") if x]
+ if dm_devs:
+ dm_dev_paths = [utils_io.PathJoin("/dev/mapper", x[2]) for x in dm_devs]
+ return (loop_dev_path, dm_dev_paths)
+ else:
+ # image_path is not a multi partition disk image, no need to use
+ # device-mapper.
+ logging.debug("Release loop dev %s allocated for %s",
+ loop_dev_path, image_path)
+ ReleaseBdevPartitionMapping(loop_dev_path)
+ return None
+
+
+def ReleaseBdevPartitionMapping(loop_dev_path):
+ """Release allocated dm devices and loopback devices.
+
+ @type loop_dev_path: string
+ @param loop_dev_path: path of loopback device returned by
+ L{CreateBdevPartitionMapping}
+
+ """
+ result = utils_process.RunCmd(["kpartx", "-d", loop_dev_path])
+ if result.failed:
+ raise errors.CommandError("Failed to release partition mapping of %s: %s"
%
+ (loop_dev_path, result.output))
+
+ # The invocation of udevadm settle was added here because users had issues
+ # with the loopback device still being busy after kpartx / earlier commands
+ # did their work.
+ result = utils_process.RunCmd(["udevadm", "settle"])
+ if result.failed:
+ raise errors.CommandError("Waiting on udev failed: %s" % result.output)
+
+ result = utils_process.RunCmd(["losetup", "-d", loop_dev_path])
+ if result.failed:
+ raise errors.CommandError("Failed to detach %s: %s" %
+ (loop_dev_path, result.output))
++
++
+ def osminor(dev):
+ """Return the device minor number from a raw device number.
+
+ This is a replacement for os.minor working around the issue that
+ Python's os.minor still has the old definition. See Ganeti issue
+ 1058 for more details.
+ """
+ return (dev & 0xff) | ((dev >> 12) & ~0xff)
--
Klaus Aehlig
Google Germany GmbH, Dienerstr. 12, 80331 Muenchen
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschaeftsfuehrer: Graham Law, Christine Elizabeth Flores