Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mount-options: Add Mount Options Support #90

Closed
wants to merge 1 commit into from

Conversation

hswong3i
Copy link
Contributor

When using zram for file system, we need to enable discard mount option for issue discard/TRIM commands to the underlying zram block device when blocks are freed. Else deleted files are not zero-ed, so zram does not remove the compressed pages.

Fixes #89

src/config.rs Outdated
@@ -38,6 +39,7 @@ impl Device {
disksize: 0,
swap_priority: 100,
mount_point: None,
mount_options: Some("".to_string()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes no sense. Either make this just String, or actually only write it if it's set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nabijaczleweli sorry that I have zero experience on rust, and what I could handle is modify from similar logic, e.g. fs-type and mount-point.

What am I looking for from here is: if mount-options is empty string or None, just print an empty string to the generated file with Options="".

May you provide some code snippet as reference, so I could modify it correctly?

@hswong3i hswong3i force-pushed the main-mount_options branch 4 times, most recently from 66ded65 to 9e44984 Compare July 26, 2021 14:24
@hswong3i
Copy link
Contributor Author

@nabijaczleweli test case added and passing as expected; BTW, after reboot the device is now format and override as swap by systemd, so the mount failed (because discard is not support):

# cat /etc/systemd/zram-generator.conf 
[zram0]
max-zram-size = 8192
zram-fraction = 1.0
[zram1]
max-zram-size = 8192
zram-fraction = 1.0
mount-point = /var/lib/libvirt/images
fs-type = ext4
mount-options = discard
# systemctl status systemd-zram-setup@zram1.service 
● systemd-zram-setup@zram1.service - Create swap on /dev/zram1
     Loaded: loaded (/lib/systemd/system/systemd-zram-setup@.service; static)
    Drop-In: /run/systemd/generator/systemd-zram-setup@zram1.service.d
             └─bindsto-mount.conf
     Active: inactive (dead) since Mon 2021-07-26 22:25:53 CST; 45s ago
       Docs: man:zram-generator(8)
             man:zram-generator.conf(5)
    Process: 9827 ExecStart=/lib/systemd/system-generators/zram-generator --setup-device zram1 (code=exited, status=0/SUCCESS)
    Process: 9832 ExecStop=/lib/systemd/system-generators/zram-generator --reset-device zram1 (code=exited, status=0/SUCCESS)
   Main PID: 9827 (code=exited, status=0/SUCCESS)

Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: Superblock backups stored on blocks:
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]:         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: [49B blob data]
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: [46B blob data]
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: Creating journal (16384 blocks): done
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: [83B blob data]
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: Finished Create swap on /dev/zram1.
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: Stopping Create swap on /dev/zram1...
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: systemd-zram-setup@zram1.service: Succeeded.
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: Stopped Create swap on /dev/zram1.
# journalctl -xef | egrep -e '^\w.*(systemd|zram)'
Jul 26 22:25:52 hswong3i-XPS-13-9300 kernel: zram1: detected capacity change from 0 to 16777216
Jul 26 22:25:52 hswong3i-XPS-13-9300 zram-generator[9830]: mke2fs 1.45.7 (28-Jan-2021)
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: [120B blob data]
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: Creating filesystem with 2097152 4k blocks and 524288 inodes
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: Filesystem UUID: c8cf6c3f-6dd1-48e6-86a2-9f46ae887980
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: Superblock backups stored on blocks:
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]:         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: [49B blob data]
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: [46B blob data]
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: update-notifier-download.service: Succeeded.
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: Finished Download data for packages that failed at package install time.
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: Creating journal (16384 blocks): done
Jul 26 22:25:53 hswong3i-XPS-13-9300 zram-generator[9830]: [83B blob data]
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: Finished Create swap on /dev/zram1.
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: var-lib-libvirt-images.mount: Directory /var/lib/libvirt/images to mount over is not empty, mounting anyway.
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: Mounting Compressed Storage on /dev/zram1...
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: var-lib-libvirt-images.mount: Mount process exited, code=exited, status=1/FAILURE
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: var-lib-libvirt-images.mount: Failed with result 'exit-code'.
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: Failed to mount Compressed Storage on /dev/zram1.
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: Stopping Create swap on /dev/zram1...
Jul 26 22:25:53 hswong3i-XPS-13-9300 kernel: zram1: detected capacity change from 16777216 to 0
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: systemd-zram-setup@zram1.service: Succeeded.
Jul 26 22:25:53 hswong3i-XPS-13-9300 systemd[1]: Stopped Create swap on /dev/zram1.

Any idea why incorrectly detect fs-type as swap?

src/generator.rs Outdated Show resolved Hide resolved
@hswong3i
Copy link
Contributor Author

@nabijaczleweli any more hits could be provided for #90 (comment)?

@hswong3i hswong3i force-pushed the main-mount_options branch 2 times, most recently from 83abe00 to 7f0eb95 Compare July 28, 2021 07:59
@keszybz
Copy link
Member

keszybz commented Jul 28, 2021

Please drop the first commit from this pull request.

@hswong3i
Copy link
Contributor Author

Please drop the first commit from this pull request.

Then the CI will fail due to missing kernel module, are you sure?

@hswong3i hswong3i force-pushed the main-mount_options branch 3 times, most recently from 455e4be to 5150a6b Compare July 31, 2021 06:15
@keszybz
Copy link
Member

keszybz commented Aug 8, 2021

Please drop the first commit from this pull request.

Then the CI will fail due to missing kernel module, are you sure?

You are pulling in unrelated changes into the pull request. If the requirement for a new module is added in this pull request, then the commit to install the module should also be in this pull request. If not, then not. And the other changes to Makefiles make this pull request unmergeable. Please clean it up to keep only the relevant parts.

@hswong3i
Copy link
Contributor Author

hswong3i commented Aug 8, 2021

You are pulling in unrelated changes into the pull request. If the requirement for a new module is added in this pull request, then the commit to install the module should also be in this pull request. If not, then not. And the other changes to Makefiles make this pull request unmergeable. Please clean it up to keep only the relevant parts.

Could we make #92 and #93 get merged? I will follow up this PR afterward.

@keszybz
Copy link
Member

keszybz commented Aug 8, 2021

Could we make #92 and #93 get merged? I will follow up this PR afterward.

Done.

@hswong3i hswong3i force-pushed the main-mount_options branch 2 times, most recently from 35bb962 to e678eb5 Compare August 9, 2021 05:40
@hswong3i
Copy link
Contributor Author

hswong3i commented Aug 9, 2021

Could we make #92 and #93 get merged? I will follow up this PR afterward.

Done.

Done

Copy link
Member

@keszybz keszybz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks reasonable, but:

  1. please rebase on top of current main
  2. please explain in the commit message what the change is. (Right now there's a discussion of why the change is useful, which is good, but cannot be the only content of the commit message.)
  3. the new option needs to be described in the docs (at least in man/zram-generator.conf.md).
  4. why are the test cases renamed? Either drop that change, or if there's some good reason for it, make it a separate commit and justify.

src/generator.rs Outdated Show resolved Hide resolved
src/generator.rs Outdated Show resolved Hide resolved
@hswong3i hswong3i force-pushed the main-mount_options branch 4 times, most recently from 1eab6ef to d074e71 Compare August 9, 2021 09:41
@hswong3i
Copy link
Contributor Author

hswong3i commented Aug 9, 2021

This mostly looks reasonable, but:

1. please rebase on top of current `main`

Done

2. please explain in the commit message what the change is. (Right now there's a discussion of why the change is useful, which is good, but cannot be the only content of the commit message.)

Doesn't the commit title mount-options: Add Mount Options Support already enough?

3. the new option needs to be described in the docs (at least in `man/zram-generator.conf.md`).

Done

4. why are the test cases renamed? Either drop that change, or if there's some good reason for it, make it a separate commit and justify.

After reorder, the options provided is now increased from 1 -> 2 -> 3, which simpler for tracing:

$ cat tests/07-plain-device/etc/systemd/zram-generator.conf 
[zram11]
fs-type = ext4

$ cat tests/08-mount-point/etc/systemd/zram-generator.conf 
[zram11]
mount-point = /var/compressed
fs-type = ext4

$ cat tests/09-mount-options/etc/systemd/zram-generator.conf 
[zram11]
mount-point = /var/compressed
fs-type = ext4
mount-options = discard

@keszybz
Copy link
Member

keszybz commented Aug 10, 2021

  1. why are the test cases renamed? Either drop that change, or if there's some good reason for it, make it a separate commit and justify.

OK. But it needs to be a separate commit.

Doesn't the commit title mount-options: Add Mount Options Support already enough?

The title doesn't explain what the option name is, and what it does. A person looking at the commit list should be able to figure out what a commit does from the description. A much better title would be "Add Options= setting to set mount options" and then have some more details in the commit body, for example a very simple example of the option and the effect on the generated unit.

keszybz added a commit to keszybz/systemd that referenced this pull request Aug 10, 2021
All units in units/ follow this pattern, as do all other generators that we
provide. The question of the order was raised in
systemd/zram-generator#90 (comment),
and I think it's nice to make it consistent everywhere
(What= before Where= matches mount(8) and fstab(5)).
@keszybz
Copy link
Member

keszybz commented Aug 10, 2021

Please undo all the unrelated changes from commit, like the file system type and default options. Let's try to do one thing first correctly.

@hswong3i
Copy link
Contributor Author

Please undo all the unrelated changes from commit, like the file system type and default options. Let's try to do one thing first correctly.

Done, also split PR to #95 and #96

poettering pushed a commit to systemd/systemd that referenced this pull request Aug 10, 2021
All units in units/ follow this pattern, as do all other generators that we
provide. The question of the order was raised in
systemd/zram-generator#90 (comment),
and I think it's nice to make it consistent everywhere
(What= before Where= matches mount(8) and fstab(5)).
man/zram-generator.conf.md Outdated Show resolved Hide resolved
@hswong3i
Copy link
Contributor Author

  1. why are the test cases renamed? Either drop that change, or if there's some good reason for it, make it a separate commit and justify.

OK. But it needs to be a separate commit.

See #96

Doesn't the commit title mount-options: Add Mount Options Support already enough?

The title doesn't explain what the option name is, and what it does. A person looking at the commit list should be able to figure out what a commit does from the description. A much better title would be "Add Options= setting to set mount options" and then have some more details in the commit body, for example a very simple example of the option and the effect on the generated unit.

Done

When using zram for file system, we need to enable `discard` mount
option for issue discard/TRIM commands to the underlying zram block
device when blocks are freed. Else deleted files are not zero-ed, so
zram does not remove the compressed pages.

For example, setting `/etc/systemd/zram-generator.conf` as below could
format the file system as ext4 with TRIM enabled:

    $ cat /etc/systemd/zram-generator.conf
    [zram11]
    mount-point = /var/compressed
    fs-type = ext4
    mount-options = discard

Fixes systemd#89

Signed-off-by: Wong Hoi Sing Edison <hswong3i@pantarei-design.com>
@keszybz
Copy link
Member

keszybz commented Oct 13, 2021

Replaced by #103.

@keszybz keszybz closed this Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

mount-options: Add Mount Options Support?
3 participants