Introduce FilesystemEntry class
Needs RevisionPublic

Authored by hallas on Feb 4 2020, 5:55 AM.

Details

Reviewers
bruns
meven
Group Reviewers
Frameworks
Summary

Introdue a dedicated type for representing a FilesystemEntry. A
FilesystemEntry is either mounted by the system or can be mounted by the
system. It is created from the information found in filesystem table
files, this can be fstab, mtab or any other mtab type file.

This commit is a small part of a larger fstab refactor patch which can
bee seen here D26600

Test Plan

Unit tests
Tested manually with Plasma Vaults

Diff Detail

Repository
R245 Solid
Branch
introduce_filesystem_entry
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 23284
Build 23302: arc lint + arc unit
hallas requested review of this revision.Feb 4 2020, 5:55 AM
hallas created this revision.
meven accepted this revision.Feb 4 2020, 9:17 AM

Nice one. Good step splitting out this.

src/solid/devices/backends/fstab/filesystem_entry.cpp
48

It would be great to expose an enum (KIO's KFileSystemType does this a little).
But given the number of filesystems this days, it may be overcomplicated.

src/solid/devices/backends/fstab/filesystem_entry.h
89

Is it necessary to keep if it is commented out ?

95

Same

This revision is now accepted and ready to land.Feb 4 2020, 9:17 AM
hallas added inline comments.Feb 4 2020, 4:48 PM
src/solid/devices/backends/fstab/filesystem_entry.cpp
48

Yeah I agree ;) But I would really like for this class to be used more generically so having a list of filesystems here would probably make it hard for that. We could also have two methods, one similar to this one given the "raw" filesystem type, and one that would give an enum entry from a so called "known" list, but would return "unknown" for a filesystem type not in the list, then you would have access to both? What do you think?

src/solid/devices/backends/fstab/filesystem_entry.h
89

No, I only put them here for completeness sake. Basically I sat down with the fstab man page and the header file documenting the mntent structure and based this class around that, but if this code should be exported an made generally available then we should probably add these, what do you think? Should I remove them now, and then we can always add them if needed?

bruns requested changes to this revision.Feb 4 2020, 9:04 PM
This revision now requires changes to proceed.Feb 4 2020, 9:04 PM
bruns added inline comments.Feb 4 2020, 9:48 PM
src/solid/devices/backends/fstab/CMakeLists.txt
3

remove

src/solid/devices/backends/fstab/filesystem_entry.cpp
60

store this in the entry, otherwise you pay the cost on every access

src/solid/devices/backends/fstab/filesystem_entry.h
35

wrap long lines, also below.

49

Whats wrong with mountPoint? Its used everywhere else here, and is a well known term.

src/solid/devices/backends/fstab/fstabhandling.cpp
166–167

should be const now

208

add temporary for fstype

259

detaches m_fstabCache, also below.

277–278

missing _k_updateMtabMountPointsCache();

293–294

dito

meven added inline comments.Feb 5 2020, 7:51 AM
src/solid/devices/backends/fstab/filesystem_entry.cpp
48

This sound sane to me.
Ideally we would store only the string in case of an unknown fs or the enum but not both for a same entry, the choice could be done in ctor.

src/solid/devices/backends/fstab/filesystem_entry.h
89

Just leave a leave a comment as to why we want to keep those.

src/solid/devices/backends/fstab/fstabhandling.cpp
405

Detaches m_mtabCache, just qAsConst or temporary const variable

hallas updated this revision to Diff 75961.Feb 19 2020, 6:18 AM
hallas marked 17 inline comments as done.

Updated patch with review comments

hallas added inline comments.Feb 20 2020, 6:12 AM
src/solid/devices/backends/fstab/filesystem_entry.cpp
48

I have added a new enum class type FilesystemType to represent the known filesystem types. Currently I have just added a single known filesystem type, but this should be extended over time. I have also added the necessary from/to string conversion functions.

src/solid/devices/backends/fstab/filesystem_entry.h
35

I have wrapped all lines to fit 80 characters in width

49

Good point :)
Actually, I don't know why I called the function mountPath instead of mountPoint - but I have reamed it, along with the member etc.

src/solid/devices/backends/fstab/fstabhandling.cpp
259

The code didn't need the for loop anyway, so I have rewritten it

405

The code didn't need the for loop anyway, so I have rewritten it

meven accepted this revision.Feb 20 2020, 8:16 AM
hallas added a comment.Mar 3 2020, 5:04 AM

Hi @bruns - I have updated this patch with the changes you requested and would really like your feedback :)

bruns requested changes to this revision.Mar 3 2020, 12:45 PM
bruns added inline comments.
src/solid/devices/backends/fstab/filesystem_entry.cpp
78

Why don't you just keep the string?

src/solid/devices/backends/fstab/fstabdevice.cpp
41

Ircs, raw pointers ... you newer know who owns them ... It is a pointer to an entry in a QHash, it may be deleted/moved when you don't expect it.

Unfortunately, std::optional is C++17 only.

Return it by value, return a default constructed instance if no found, and compare fsEntry.device() != m_device

src/solid/devices/backends/fstab/fstabhandling.cpp
264

this looks wrong ...

315

this is bad, bad, bad, ...

This revision now requires changes to proceed.Mar 3 2020, 12:45 PM
hallas updated this revision to Diff 76898.Mar 4 2020, 6:09 AM
hallas marked 9 inline comments as done.

Addressed review comments

hallas added a comment.Mar 4 2020, 6:09 AM

@bruns - thanks a lot for the feedback, I have updated the patch with your suggestions.

src/solid/devices/backends/fstab/filesystem_entry.cpp
78

It was merely meant as an optimization, I don't know if it makes sense - I'll remove it.

src/solid/devices/backends/fstab/fstabdevice.cpp
41

Good point :) I have changed this as you suggested, but I have added a method to FilesystemEntry called isValid to check if it is valid

src/solid/devices/backends/fstab/fstabhandling.cpp
264

Yes definitely :) I have removed the line

315

Fixed

bruns requested changes to this revision.Mar 4 2020, 4:57 PM
bruns added inline comments.
autotests/filesystem_entry_test.h
7

For tests LGPL is preferred as well. Also see D27742.

src/solid/devices/backends/fstab/filesystem_entry.cpp
32

This is a behavioral change:

  • overlayfs is no longer handled
  • fuse.cryfs is no longer handled
  • encfs gets an extra '@', and the prefix is changed from <fstype> to <device>

The identifier is API, don't change it. E.g. dolphin may reference it.

src/solid/devices/backends/fstab/filesystem_entry.h
6

This has to be LGPL.

Regarding wording, please have a look at D27742 for how it should look like.

Applies to other files as well.

This revision now requires changes to proceed.Mar 4 2020, 4:57 PM
hallas updated this revision to Diff 76990.Mar 5 2020, 6:26 AM
hallas marked 7 inline comments as done.

Review comments

hallas added inline comments.Mar 5 2020, 6:26 AM
src/solid/devices/backends/fstab/filesystem_entry.cpp
32

I have added handling of overlayfs and CryFs and removed the '@' separator. Actually I don't know why I added the '@', I was sure that I had seen it somewhere in the code, but I guess that is not the case ;)

I tried to do a solid-hardware5 list details and compare the before and after output, and it should be the same now. I tested with both encfs and cryfs filesystems.

bruns requested changes to this revision.Mar 7 2020, 3:27 PM
bruns added inline comments.
src/solid/devices/backends/fstab/fstabhandling.cpp
374

Why is the id() a property of the entry now?

  • it does not correspond to anything from the fstab/mtab
  • it is only used here to generate the key for the cache

Please move the id generation back here, eventually changing it from _k_deviceNameForMountpoint(const QString &source, const QString &fstype,const QString &mountpoint) to _k_deviceIdForFsentry(const FilesystemEntry&)

This revision now requires changes to proceed.Mar 7 2020, 3:27 PM
hallas added inline comments.Mar 9 2020, 6:02 AM
src/solid/devices/backends/fstab/fstabhandling.cpp
374

I guess the main reason is that the id is a function of a FilesystemEntry, meaning that the id is computed from the contents of it. You are absolutely right that it is not picked up directly from the fstab/mtab file, but it is computed from the contents. I think it should either be a member function of the FilesystemEntry class or a static member function of some other class (taking the FilesystemEntry as an input paramter) - it at least has to be in a place where it is possible to write a unit test for it's functionality. especially since the id() is used as part of the public API. Therefore I don't think we should make this an internal function in fstabhandling. Another reason is that, we might need the id in other places then the fstabhandling, at least we need it for the rest of the fstab handling refactor I posted in the other review.

So long story short :)
I think we should either keep it here or make it a public (static) method somewhere else - @bruns what do you think?

bruns added inline comments.Mar 9 2020, 10:29 AM
src/solid/devices/backends/fstab/fstabhandling.cpp
374

For now just keep it here, I can see now benefit of making it public (even unexported).

And thanks for baring with my nitpicking ;-), this now is pretty much what I hoped for.

hallas marked 4 inline comments as done.Mar 10 2020, 5:58 AM
hallas added inline comments.
src/solid/devices/backends/fstab/fstabhandling.cpp
374

No problem, I really appreciate the thorough review feedback you provide. I definitely prefer to take more time and get things right, then to rush things and potentially get them wrong.

So, have you had a chance to test out the patch? Do you think it is ready to land?

I will also start to prepare the next patch as part of splitting up the mega-refactor patch from D26600

meven added inline comments.Mar 10 2020, 3:06 PM
src/solid/devices/backends/fstab/fstabhandling.cpp
208

The temporary for fstype is gone it seems.

hallas marked an inline comment as done.Apr 12 2020, 5:49 AM

Hi @bruns - did you have a chance to go through this patch again? Am I missing anything to move on with this?

bruns added inline comments.Apr 12 2020, 9:55 AM
src/solid/devices/backends/fstab/fstabhandling.cpp
374

The id() method and members are still part of the FstabEntry, where they do not belong.

The UDIs go through some further mangling in FstabHandling::deviceList(), which should be covered by the unit-tests as well.

Conceptually, the _k_deviceNameForMountpoint/_k_deviceNameForFilesystemEntry should be part of the m_mtabCache/m_fstabCache class (which currently is just a QMultiHash<>). This class can then be unit tested easily.

For now, keep the _k_deviceNameForMountpoint inside fstabhandling.cpp

hallas marked an inline comment as done.Apr 22 2020, 5:40 PM
hallas added inline comments.
src/solid/devices/backends/fstab/fstabhandling.cpp
374

@bruns - I am little confused now. You wrote previously that you could see the point in the id() function, but now you want it moved?
What kind of unit test are you missing? I can't quite follow the added mangling in FstabHandling::deviceList()? I don't think we have (or ever have) had any unit test of FstabHandling, but that was one of the things I am trying to achieve was this patch series that breaks up and decouples the code pieces into smaller bits.

Could I ask you to take a look at it again? Sorry for nagging, I just really want to close this up soon and move on with the next patches ;D

bruns added inline comments.Apr 22 2020, 5:50 PM
src/solid/devices/backends/fstab/fstabhandling.cpp
374

I never said anything like that. "here" == fstabhandling.cpp

The name is exported by deviceList(), after mangling it. Thats the reason any further processing should go there, not into fstentry, but that is matter for another patch.

The code should be be split up, but the splitting should be done at the right places.