import subprocess
import random
import string
-import logging
import time
import fcntl
import struct
device = losetupOutput.split()[0]
- logging.debug("Losetup add %s mapping to %s" % (device, self.lofile))
+ msger.debug("Losetup add %s mapping to %s" % (device, self.lofile))
rc = subprocess.call([self.losetupcmd, device, self.lofile])
if rc != 0:
raise MountError("Failed to allocate loop device for '%s'" %
def cleanup(self):
if self.device is None:
return
- logging.debug("Losetup remove %s" % self.device)
+ msger.debug("Losetup remove %s" % self.device)
rc = subprocess.call([self.losetupcmd, "-d", self.device])
self.device = None
if size is None:
size = self.size
- logging.debug("Extending sparse file %s to %d" % (self.lofile, size))
+ msger.debug("Extending sparse file %s to %d" % (self.lofile, size))
if create:
fd = os.open(self.lofile, flags, 0644)
else:
if size is None:
size = self.size
- logging.debug("Truncating sparse file %s to %d" % (self.lofile, size))
+ msger.debug("Truncating sparse file %s to %d" % (self.lofile, size))
fd = os.open(self.lofile, os.O_WRONLY)
os.ftruncate(fd, size)
os.close(fd)
def unmount(self):
if self.mounted:
- logging.debug("Unmounting directory %s" % self.mountdir)
+ msger.debug("Unmounting directory %s" % self.mountdir)
synccmd = find_binary_path("sync")
subprocess.call([synccmd]) # sync the data on this mount point
rc = subprocess.call([self.umountcmd, "-l", self.mountdir])
return
if not os.path.isdir(self.mountdir):
- logging.debug("Creating mount point %s" % self.mountdir)
+ msger.debug("Creating mount point %s" % self.mountdir)
os.makedirs(self.mountdir)
self.rmdir = self.rmmountdir
self.__create()
- logging.debug("Mounting %s at %s" % (self.disk.device, self.mountdir))
+ msger.debug("Mounting %s at %s" % (self.disk.device, self.mountdir))
if options:
args = [ self.mountcmd, "-o", options, self.disk.device, self.mountdir ]
else:
def __format_filesystem(self):
if self.skipformat:
- logging.debug("Skip filesystem format.")
+ msger.debug("Skip filesystem format.")
return
- logging.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
+ msger.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
rc = subprocess.call([self.mkfscmd,
"-F", "-L", self.fslabel,
"-m", "1", "-b", str(self.blocksize),
os.close(dev_null)
self.uuid = self.__parse_field(out, "Filesystem UUID")
- logging.debug("Tuning filesystem on %s" % self.disk.device)
+ msger.debug("Tuning filesystem on %s" % self.disk.device)
subprocess.call([self.tune2fs, "-c0", "-i0", "-Odir_index",
"-ouser_xattr,acl", self.disk.device],
stdout=sys.stdout, stderr=sys.stderr)
DiskMount.mount(self, options)
def __fsck(self):
- logging.debug("Checking filesystem %s" % self.disk.lofile)
+ msger.debug("Checking filesystem %s" % self.disk.lofile)
subprocess.call(["/sbin/e2fsck", "-f", "-y", self.disk.lofile], stdout=sys.stdout, stderr=sys.stderr)
def __get_size_from_filesystem(self):
def __format_filesystem(self):
if self.skipformat:
- logging.debug("Skip filesystem format.")
+ msger.debug("Skip filesystem format.")
return
- logging.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
+ msger.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
blah = [self.mkfscmd, "-n", self.fslabel, "-i", self.uuid, self.disk.device]
rc = subprocess.call(blah)
if rc != 0:
raise MountError("Error creating %s filesystem on disk %s" % (self.fstype,self.disk.device))
- logging.debug("Tuning filesystem on %s" % self.disk.device)
+ msger.debug("Tuning filesystem on %s" % self.disk.device)
def __resize_filesystem(self, size = None):
current_size = os.stat(self.disk.lofile)[stat.ST_SIZE]
DiskMount.mount(self, options)
def __fsck(self):
- logging.debug("Checking filesystem %s" % self.disk.lofile)
+ msger.debug("Checking filesystem %s" % self.disk.lofile)
subprocess.call([self.fsckcmd, "-y", self.disk.lofile])
def __get_size_from_filesystem(self):
def __format_filesystem(self):
if self.skipformat:
- logging.debug("Skip filesystem format.")
+ msger.debug("Skip filesystem format.")
return
- logging.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
+ msger.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
rc = subprocess.call([self.mkfscmd, "-L", self.fslabel, self.disk.device])
if rc != 0:
raise MountError("Error creating %s filesystem on disk %s" % (self.fstype,self.disk.device))
DiskMount.mount(self, options)
def __fsck(self):
- logging.debug("Checking filesystem %s" % self.disk.lofile)
+ msger.debug("Checking filesystem %s" % self.disk.lofile)
subprocess.call([self.btrfsckcmd, self.disk.lofile])
def __get_size_from_filesystem(self):
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os
-import os.path
import glob
import shutil
import subprocess
-import logging
import time
from mic.utils.errors import *
from mic.utils.fs_related import *
+from mic import msger
class PartitionedMount(Mount):
def __init__(self, disks, mountdir, skipformat = False):
def __create_part_to_image(self,device, parttype, fstype, start, size):
# Start is included to the size so we need to substract one from the end.
end = start+size-1
- logging.debug("Added '%s' part at %d of size %d" % (parttype,start,end))
+ msger.debug("Added '%s' part at %d of size %d" % (parttype,start,end))
part_cmd = [self.parted, "-s", device, "unit", "s", "mkpart", parttype]
if fstype:
part_cmd.extend([fstype])
part_cmd.extend(["%d" % start, "%d" % end])
- logging.debug(part_cmd)
+ msger.debug(part_cmd)
p1 = subprocess.Popen(part_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(out,err) = p1.communicate()
- logging.debug(out)
+ msger.debug(out)
return p1
def __format_disks(self):
- logging.debug("Assigning partitions to disks")
+ msger.debug("Assigning partitions to disks")
mbr_sector_skipped = False
p['start'] = d['offset']
d['offset'] += p['size']
d['partitions'].append(n)
- logging.debug("Assigned %s to %s%d at %d at size %d" % (p['mountpoint'], p['disk'], p['num'], p['start'], p['size']))
+ msger.debug("Assigned %s to %s%d at %d at size %d" % (p['mountpoint'], p['disk'], p['num'], p['start'], p['size']))
if self.skipformat:
- logging.debug("Skipping disk format, because skipformat flag is set.")
+ msger.debug("Skipping disk format, because skipformat flag is set.")
return
for dev in self.disks.keys():
d = self.disks[dev]
- logging.debug("Initializing partition table for %s" % (d['disk'].device))
+ msger.debug("Initializing partition table for %s" % (d['disk'].device))
p1 = subprocess.Popen([self.parted, "-s", d['disk'].device, "mklabel", "msdos"],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(out,err) = p1.communicate()
- logging.debug(out)
+ msger.debug(out)
if p1.returncode != 0:
# NOTE: We don't throw exception when return code is not 0, because
# parted always fails to reload part table with loop devices.
# This prevents us from distinguishing real errors based on return code.
- logging.debug("WARNING: parted returned '%s' instead of 0 when creating partition-table for disk '%s'." % (p1.returncode,d['disk'].device))
+ msger.debug("WARNING: parted returned '%s' instead of 0 when creating partition-table for disk '%s'." % (p1.returncode,d['disk'].device))
- logging.debug("Creating partitions")
+ msger.debug("Creating partitions")
for p in self.partitions:
d = self.disks[p['disk']]
# Boot ROM of OMAP boards require vfat boot partition to have an
# even number of sectors.
if p['mountpoint'] == "/boot" and p['fstype'] in ["vfat","msdos"] and p['size'] % 2:
- logging.debug("Substracting one sector from '%s' partition to get even number of sectors for the partition." % (p['mountpoint']))
+ msger.debug("Substracting one sector from '%s' partition to get even number of sectors for the partition." % (p['mountpoint']))
p['size'] -= 1
p1 = self.__create_part_to_image(d['disk'].device,p['type'],
# NOTE: We don't throw exception when return code is not 0, because
# parted always fails to reload part table with loop devices.
# This prevents us from distinguishing real errors based on return code.
- logging.debug("WARNING: parted returned '%s' instead of 0 when creating partition '%s' for disk '%s'." % (p1.returncode,p['mountpoint'],d['disk'].device))
+ msger.debug("WARNING: parted returned '%s' instead of 0 when creating partition '%s' for disk '%s'." % (p1.returncode,p['mountpoint'],d['disk'].device))
if p['boot']:
- logging.debug("Setting boot flag for partition '%s' on disk '%s'." % (p['num'],d['disk'].device))
+ msger.debug("Setting boot flag for partition '%s' on disk '%s'." % (p['num'],d['disk'].device))
boot_cmd = [self.parted, "-s", d['disk'].device, "set", "%d" % p['num'], "boot", "on"]
- logging.debug(boot_cmd)
+ msger.debug(boot_cmd)
p1 = subprocess.Popen(boot_cmd,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(out,err) = p1.communicate()
- logging.debug(out)
+ msger.debug(out)
if p1.returncode != 0:
# NOTE: We don't throw exception when return code is not 0, because
# parted always fails to reload part table with loop devices.
# This prevents us from distinguishing real errors based on return code.
- logging.debug("WARNING: parted returned '%s' instead of 0 when adding boot flag for partition '%s' disk '%s'." % (p1.returncode,p['num'],d['disk'].device))
+ msger.debug("WARNING: parted returned '%s' instead of 0 when adding boot flag for partition '%s' disk '%s'." % (p1.returncode,p['num'],d['disk'].device))
def __map_partitions(self):
"""Load it if dm_snapshot isn't loaded"""
if d['mapped']:
continue
- logging.debug("Running kpartx on %s" % d['disk'].device )
+ msger.debug("Running kpartx on %s" % d['disk'].device )
kpartx = subprocess.Popen([self.kpartx, "-l", "-v", d['disk'].device],
stdout=subprocess.PIPE, stderr=dev_null)
mapperdev = "/dev/mapper/" + newdev
loopdev = d['disk'].device + newdev[-1]
- logging.debug("Dev %s: %s -> %s" % (newdev, loopdev, mapperdev))
+ msger.debug("Dev %s: %s -> %s" % (newdev, loopdev, mapperdev))
pnum = d['partitions'][i]
self.partitions[pnum]['device'] = loopdev
os.unlink(loopdev)
os.symlink(mapperdev, loopdev)
- logging.debug("Adding partx mapping for %s" % d['disk'].device)
+ msger.debug("Adding partx mapping for %s" % d['disk'].device)
p1 = subprocess.Popen([self.kpartx, "-v", "-a", d['disk'].device],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(out,err) = p1.communicate()
- logging.debug(out)
+ msger.debug(out)
if p1.returncode != 0:
# Make sure that the device maps are also removed on error case.
if not d['mapped']:
continue
- logging.debug("Removing compat symlinks")
+ msger.debug("Removing compat symlinks")
for pnum in d['partitions']:
if self.partitions[pnum]['device'] != None:
os.unlink(self.partitions[pnum]['device'])
self.partitions[pnum]['device'] = None
- logging.debug("Unmapping %s" % d['disk'].device)
+ msger.debug("Unmapping %s" % d['disk'].device)
rc = subprocess.call([self.kpartx, "-d", d['disk'].device],
stdout=dev_null, stderr=dev_null)
if rc != 0:
def __calculate_mountorder(self):
- logging.debug("Calculating mount order")
+ msger.debug("Calculating mount order")
for p in self.partitions:
self.mountOrder.append(p['mountpoint'])
self.unmountOrder.append(p['mountpoint'])
argv = [ self.btrfscmd, "subvolume", "list", rootpath ]
p1 = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(out,err) = p1.communicate()
- logging.debug(out)
+ msger.debug(out)
if p1.returncode != 0:
raise MountError("Failed to get subvolume id from %s', return code: %d." % (rootpath, p1.returncode))
subvolid = -1
argv = [ self.btrfscmd, "subvolume", "list", pdisk.mountdir ]
p1 = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(out,err) = p1.communicate()
- logging.debug(out)
+ msger.debug(out)
if p1.returncode != 0:
raise MountError("Failed to get subvolume id from %s', return code: %d." % (pdisk.mountdir, p1.returncode))
subvolid_items = out.split("\n")
argv = [ self.btrfscmd, "subvolume", "create", pdisk.mountdir + "/" + subvol["subvol"]]
p1 = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(out,err) = p1.communicate()
- logging.debug(out)
+ msger.debug(out)
if p1.returncode != 0:
raise MountError("Failed to create subvolume '%s', return code: %d." % (subvol["subvol"], p1.returncode))
argv = [ self.btrfscmd, "subvolume", "set-default", "%d" % subvolid, pdisk.mountdir]
p1 = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(out,err) = p1.communicate()
- logging.debug(out)
+ msger.debug(out)
if p1.returncode != 0:
raise MountError("Failed to set default subvolume id: %d', return code: %d." % (subvolid, p1.returncode))
continue
subvolid = self. __get_subvolume_id(pdisk.mountdir, subvol["subvol"])
if subvolid == -1:
- logging.debug("WARNING: invalid subvolume %s" % subvol["subvol"])
+ msger.debug("WARNING: invalid subvolume %s" % subvol["subvol"])
continue
""" Replace subvolume name with subvolume ID """
opts = subvol["fsopts"].split(",")
argv = [ self.btrfscmd, "subvolume", "snapshot", subvolpath, snapshotpath ]
p1 = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(out,err) = p1.communicate()
- logging.debug(out)
+ msger.debug(out)
if p1.returncode != 0:
raise MountError("Failed to create subvolume snapshot '%s' for '%s', return code: %d." % (snapshotpath, subvolpath, p1.returncode))
self.snapshot_created = True