openscopeproject / ZipROFS

FUSE file system with transparent access to zip files as if they were folders.
MIT License
11 stars 5 forks source link

Add some way to clear cache without remounting #6

Open JuniorJPDJ opened 3 years ago

JuniorJPDJ commented 3 years ago

First thing that came up to my mind was to open some invisible virtual file in main directory. eg. echo "" > ./.clean_ziprofs_cache Of course .clean_cache wouldn't be listed in readdir() call

At the moment when I remount underlying filesystem (which was pretty often bcs of bugs in it) I need to remount also ZipROFS and restart all software which was using it. Some workaroundish way to clean cache and reopen existing handles would be helpful.

qu1ck commented 3 years ago

Probably handling SIGHUP to dump cache is as close to a convention as we can get. At least it's better then creating some special meaning files.

By the way you will probably still have to restart software using ziprofs because it likely doesn't handle file handles becoming invalid well. Software that can handle that also survives ziprofs restart as I can attest from my everyday usage.

JuniorJPDJ commented 3 years ago

We could close any cached files and refresh handles inside ZipROFS to make this seamless

JuniorJPDJ commented 3 years ago

The solution I've in my mind is clearing cache and freezing ZipROFS process until underlying FS remounts

qu1ck commented 3 years ago

I don't think there is a way for ziprofs to distinguish between empty root and not mounted root. So freeze/unfreeze triggers have to be external, you could use SIGUSR1/2 for that.

JuniorJPDJ commented 3 years ago

I meant just freezing whole process with SIGSTOP :D

qu1ck commented 3 years ago

That works too but then you can't clear cache while the process is frozen.

JuniorJPDJ commented 3 years ago

I would guess it would process SIGUSR before anything other after unfreezing. We could also provide SIGTSTP as it is being handled by process - which would first clear cache, then freeze process.

qu1ck commented 3 years ago

I would guess it would process SIGUSR before anything other after unfreezing.

Unless this is documented behavior I wouldn't count on it.

We could also provide SIGTSTP as it is being handled by process - which would first clear cache, then freeze process.

I would rather go for more generic solution. Sometimes dumping cache is useful without freezing process, these operations shouldn't be tied together.

JuniorJPDJ commented 3 years ago

Yes, but it could be function called twice, for SIGUSR and SIGTSTP.

qu1ck commented 3 years ago

So this sounds like a plan:

  1. Handle SIGHUP to drop cache
  2. Handle SIGTSTP to freeze and drop cache
  3. Handle SIGCONT to unfreeze and attempt to refresh file handles

For refreshing file handles I think we will have to try to refresh non-zip handles as well. For that we will need a mapping of ziprofs handles to system handles instead of current odd-even scheme.

But I probably won't have time to implement this stuff in a while.

JuniorJPDJ commented 3 years ago

We could just drop and zipfiles instead of holding next handles. Those are just open ZipFiles which we can close and reopen using cached implementation if needed.