1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

filesystem.py: fix xfs growfs (#137)

* filesystem.py: fix xfs growfs

xfs needs to be mounted to be expanted.

Add function to get mountpoint of filesystem.

* Fail if xfs filesystem is not mounted

xfs growfs needs to be executed on a mountpoint. That will be enforced
now by xfsprogs-4.12.
https://bugzilla.redhat.com/show_bug.cgi?id=1477192

* Update changelogs/fragments/33979-xfs_growfs.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alex 2020-06-23 15:04:55 +02:00 committed by GitHub
parent 7e17b55884
commit ae3fde2647
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "filesystem - resizefs of xfs filesystems is fixed. Filesystem needs to be mounted."

View file

@ -96,6 +96,20 @@ class Device(object):
else:
self.module.fail_json(changed=False, msg="Target device not supported: %s" % self)
def get_mountpoint(self):
"""Return (first) mountpoint of device. Returns None when not mounted."""
cmd_findmnt = self.module.get_bin_path("findmnt", required=True)
# find mountpoint
rc, mountpoint, _ = self.module.run_command([cmd_findmnt, "--mtab", "--noheadings", "--output",
"TARGET", "--source", self.path], check_rc=False)
if rc != 0:
mountpoint = None
else:
mountpoint = mountpoint.split('\n')[0]
return mountpoint
def __str__(self):
return self.path
@ -187,7 +201,13 @@ class XFS(Filesystem):
def get_fs_size(self, dev):
cmd = self.module.get_bin_path('xfs_growfs', required=True)
_, size, _ = self.module.run_command([cmd, '-n', str(dev)], check_rc=True, environ_update=self.LANG_ENV)
mountpoint = dev.get_mountpoint()
if not mountpoint:
# xfs filesystem needs to be mounted
self.module.fail_json(msg="%s needs to be mounted for xfs operations" % dev)
_, size, _ = self.module.run_command([cmd, '-n', str(mountpoint)], check_rc=True, environ_update=self.LANG_ENV)
for line in size.splitlines():
col = line.split('=')
if col[0].strip() == 'data':
@ -199,6 +219,16 @@ class XFS(Filesystem):
block_count = int(col[3].split(',')[0])
return block_size * block_count
def grow_cmd(self, dev):
mountpoint = dev.get_mountpoint()
if not mountpoint:
# xfs filesystem needs to be mounted
self.module.fail_json(msg="%s needs to be mounted for xfs operations" % dev)
cmd = self.module.get_bin_path(self.GROW, required=True)
return [cmd, str(mountpoint)]
class Reiserfs(Filesystem):
MKFS = 'mkfs.reiserfs'