Preserve XFS quota options in temporary mounts #1132
Conversation
libmount logs only when debug is enabled so we get no logs for mount and unmount calls. We are now using FS plugin in blivet and having the mounting logged is useful for debugging.
Summary of ChangesHello @vojtechtrefny, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where XFS quota settings were not maintained during temporary filesystem mounts, which could lead to unexpected behavior, especially during operations like resizing. It implements a mechanism to dynamically read existing XFS quota configurations and apply them to temporary mounts, ensuring consistent filesystem behavior. The changes also include improved logging for mount operations and updated tests to validate the new functionality. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds functionality to preserve XFS quota options during temporary mounts, which is a valuable improvement. The implementation is mostly solid, and the accompanying tests cover the new functionality well. I've identified a few areas for improvement regarding code style, test correctness, and security best practices in the test suite. My comments are detailed below.
| self.assertEqual(fi.block_size * fi.block_count, 450 * 1024**2) | ||
|
|
||
| # quota options should be preserved during temp mount | ||
| self.assertIn("with options: uquota,gquota,pquota", self.log) |
There was a problem hiding this comment.
This assertion is likely to fail. The log message will include other mount options like nosuid and nodev appended to the quota options, so the full string will be something like ... with options: uquota,gquota,pquota,nosuid,nodev. The substring you're checking for won't be found.
To make the test more robust and accurate, you should check for the presence of each quota option individually.
| self.assertIn("with options: uquota,gquota,pquota", self.log) | |
| self.assertIn("with options:", self.log) | |
| self.assertIn("uquota", self.log) | |
| self.assertIn("gquota", self.log) | |
| self.assertIn("pquota", self.log) |
| def mount(device, where, ro=False, options=None): | ||
| if not os.path.isdir(where): | ||
| os.makedirs(where) | ||
|
|
||
| if ro: | ||
| os.system("mount -oro %s %s" % (device, where)) | ||
| if options: | ||
| options += ",ro" | ||
| else: | ||
| options = "ro" | ||
|
|
||
| if options: | ||
| os.system("mount -o %s %s %s" % (options, device, where)) | ||
| else: | ||
| os.system("mount %s %s" % (device, where)) |
There was a problem hiding this comment.
Using os.system with string formatting is vulnerable to shell injection. While this is test code, it's a good practice to use safer alternatives. I recommend refactoring this function to use subprocess.run with a list of arguments, which avoids the shell and is more secure.
def mount(device, where, ro=False, options=None):
if not os.path.isdir(where):
os.makedirs(where)
mount_cmd = ["mount"]
if ro:
if options:
options += ",ro"
else:
options = "ro"
if options:
mount_cmd.extend(["-o", options])
mount_cmd.extend([device, where])
# Using subprocess.run is safer than os.system with string formatting.
# The original implementation ignored the return code, so we do the same.
subprocess.run(mount_cmd)If XFS was previously mounted with the quota options and then we are mounting it for resize, the quota mount options need to be preserved or XFS would need to recheck the quotas during the next mount which may take a long time, depending on filesystem size.
9c530e1 to
10b3cdf
Compare
Sounds like a really bad design in XFS, but we can't do anything about that... |
Originally reported against LVM and their fsresize helper script: lvmteam/lvm2#182