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

Add option --remount for remount support #6488

Open
Weathercold opened this issue Oct 12, 2022 · 5 comments
Open

Add option --remount for remount support #6488

Weathercold opened this issue Oct 12, 2022 · 5 comments

Comments

@Weathercold
Copy link

What is your current rclone version (output from rclone version)?

$ rclone --version
rclone 1.59.2
- os/version: nixos 22.11 (Raccoon) (64 bit)
- os/kernel: 5.19.12-zen1 (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.18.6
- go/linking: dynamic
- go/tags: cmount

What problem are you are trying to solve?

I'm using rclone as a mount helper. Whenever I try sudo systemctl reload <rclone-mount>.mount, it fails because rclone doesn't recognize the flag --remount. Normally this can be circumvented by unmounting then remounting, but I also use NixOS and the aforementioned command is automatically invoked whenever I switch system generation.

How do you think rclone should be changed to solve that?

Add the --remount flag to remount a file system.

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.
@ncw
Copy link
Member

ncw commented Oct 12, 2022

Add the --remount flag to remount a file system.

What do you think rclone should when it receives this flag

Here is what I found in the mount man page

remount

Attempt to remount an already-mounted filesystem. This is commonly
used to change the mount flags for a filesystem, especially to make
a readonly filesystem writable. It does not change device or mount
point.

The remount operation together with the bind flag has special
semantics. See above, the subsection Bind mounts.

The remount functionality follows the standard way the mount
command works with options from fstab. This means that mount does
not read fstab (or mtab) only when both device and dir are
specified.

mount -o remount,rw /dev/foo /dir

After this call all old mount options are replaced and arbitrary
stuff from fstab (or mtab) is ignored, except the loop= option
which is internally generated and maintained by the mount command.

mount -o remount,rw /dir

After this call, mount reads fstab and merges these options with
the options from the command line (-o). If no mountpoint is found
in fstab, then a remount with unspecified source is allowed.

mount allows the use of --all to remount all already mounted
filesystems which match a specified filter (-O and -t). For
example:

mount --all -o remount,ro -t vfat

remounts all already mounted vfat filesystems in read-only mode.
Each of the filesystems is remounted by mount -o remount,ro /dir
semantic. This means the mount command reads fstab or mtab and
merges these options with the options from the command line.

It sounds very hard to diff the config for the mount before and after and work out what to do.

Rclone could

  1. ignore the flag
  2. attempt to unmount an rclone fs at /mountpoint then carry on as before

?

@Weathercold
Copy link
Author

I did a few tests using echo as a mount helper:

  • --all, loop, and bind mounts are handled by mount itself (not sure if rclone supports loop devices), so no need to support them
  • with option remount, mount handles merge of options
  • with option remount, mount does not unmount the mount point automatically, so this is handled by the mount helper
  • when attempting to "remount" a device onto a mount point with a different one, it is a no-op and silently returns success

TL;DR rclone only has to verify that the new remote is the same as the old one, then unmount the mount point and carry on as before. If the verification fails then return success (there really should be a warning).

@ncw
Copy link
Member

ncw commented Oct 13, 2022

Do you want to have a go at implementing this?

If so then the first step would be to add a Remount bool here

type Options struct {

Then add a flag --remount pointing at it here

func AddFlags(flagSet *pflag.FlagSet) {

The -o remount should get translated into a --remount flag.

Then somewhere just before here

// Start background task if --daemon is specified

You check m.MountOpt.Remount and if it was set you'd unmount the mountpoint first. I'm not sure exactly of the best way you'd do this... You could call fusermount -zu /mountpoint which would work fine on linux. Perhaps we should only support this flag under linux as it is too dificult otherwise.

@Weathercold
Copy link
Author

Sadly I can't code in Go, and I don't have time to learn it 😅

@KDreynolds
Copy link
Contributor

Ill take a crack at this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants