447
447
self.mounted = True
449
class F2fsDiskMount(DiskMount):
450
"""A DiskMount object that is able to format/resize f2fs filesystems."""
451
def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None, fsuuid=None):
453
DiskMount.__init__(self, disk, mountdir, fstype, rmmountdir)
454
self.blocksize = blocksize
455
self.fslabel = fslabel.replace("/", "")
456
self.uuid = fsuuid or None
457
self.skipformat = skipformat
459
self.__f2fsopts = None
460
self.blkidcmd = find_binary_path("blkid")
461
self.dumpe2fs = find_binary_path("dump." + self.fstype)
462
self.fsckcmd = find_binary_path("fsck." + self.fstype)
463
self.resizecmd = find_binary_path("resize." + self.fstype)
465
def __get_f2fsopts(self):
466
return self.__f2f2opts
468
def __set_f2fsopts(self, val):
470
self.__f2fsopts = None
472
self.__f2fsopts = val
473
f2fsopts = property(__get_f2fsopts, __set_f2fsopts)
475
def __check_f2fs(self):
477
""" Need to load f2fs module to mount it """
479
for line in open("/proc/filesystems"):
480
if line.find("f2fs") > -1:
484
raise MountError("Your system can't mount f2fs filesystem, please make sure your kernel has f2fs support and the module f2fs.ko has been loaded.")
486
def __parse_field(self, output, field):
487
for line in output.split(" "):
488
if line.startswith(field + "="):
489
return line[len(field) + 1:].strip().replace("\"", "")
491
raise KeyError("Failed to find field '%s' in output" % field)
493
def __format_filesystem(self):
495
msger.debug("Skip filesystem format.")
498
msger.verbose("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
500
cmdlist = [self.mkfscmd, "-l", self.fslabel]
502
cmdlist.extend(self._f2fsopts.split())
503
cmdlist.extend([self.disk.device])
505
rc, errout = runner.runtool(cmdlist, catch=2)
507
raise MountError("Error creating %s filesystem on disk %s:\n%s" %
508
(self.fstype, self.disk.device, errout))
510
self.uuid = self.__parse_field(runner.outs([self.blkidcmd, self.disk.device]), "UUID")
512
def __resize_filesystem(self, size = None):
513
msger.info("Resizing filesystem ...")
514
current_size = os.stat(self.disk.lofile)[stat.ST_SIZE]
517
size = self.disk.size
519
if size == current_size:
522
if size > current_size:
523
self.disk.expand(size=size)
531
if not self.disk.fixed() and self.disk.exists():
537
self.__resize_filesystem()
539
self.__format_filesystem()
541
def mount(self, options = None, init_expand = False):
544
expand_size = int(self.disk.size * 1.5)
545
msger.info("Initial partition size expanded : %ld -> %ld" % (self.disk.size, expand_size))
546
self.__resize_filesystem(expand_size)
547
self.disk.reread_size()
548
DiskMount.mount(self, options)
551
msger.info("Checking filesystem %s" % self.disk.lofile)
552
runner.quiet([self.fsckcmd, self.disk.lofile])
554
def __get_size_from_filesystem(self):
555
return self.disk.size
557
def __resize_to_minimal(self):
558
msger.info("Resizing filesystem to minimal ...")
561
return self.__get_size_from_filesystem()
563
def resparse(self, size = None):
568
minsize = self.__resize_to_minimal()
569
self.disk.truncate(minsize)
570
self.__resize_filesystem(size)
449
573
class ExtDiskMount(DiskMount):
450
574
"""A DiskMount object that is able to format/resize ext[23] filesystems."""
451
575
def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None, fsuuid=None):