check_layer: Add tests for constant st_dev
PATCH 1/1 check_layer: Add tests for constant st_dev
With constant st_dev implemented, overlayfs never returns the real dev corresponding to lowerdir filesystems. Also, for the samefs case, overlayfs always returns the pseudo st_dev corresponding to the union layer.
--- context.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
context.py +4 -6
@@ -532,17 +532,15 @@ class test_context: if self.skip_layer_test(): pass elif dev == self.lower_fs(): - if dentry.is_dir(): - raise TestError(name + ": Directory unexpectedly on lower filesystem") + # Overlayfs never returns st_dev corresponding to any of + # the lower layers + raise TestError(name + ": File unexpectedly has lowerfs dev id") elif dentry.is_dir(): if dev != self.upper_dir_fs(): raise TestError(name + ": Directory not on union layer") elif dev == self.upper_fs() and not dentry.on_upper(): raise TestError(name + ": File unexpectedly on upper layer") - elif dev != self.upper_fs() and dev != self.upper_dir_fs() and self.config().is_samefs(): - # For samefs, file is on overlay dev - # TODO: for non-samefs, check file dev matches pseudo dev - # and that pseduo dev != real dev + elif dev != self.upper_dir_fs() and self.config().is_samefs(): raise TestError(name + ": File on unexpected layer") if dentry.is_sym() and dentry not in symlinks:
Signature · 1 line
2.9.4
Quoted 6 lines · Chandan Rajendra
With constant
st_devimplemented, overlayfs never returns the real dev corresponding to lowerdir filesystems. Also, for the samefs case, overlayfs always returns the pseudost_devcorresponding to the union layer.Signed-off-by Chandan Rajendra <[email protected]>
Chandan,
Tests look correct, however, the tests are correct for a future version of overlayfs
(overlayfs-devel branch) and we don't want to break unionmounts for current stable kernel and not even for older kernels, so we have to maintain backward compat somehow...
I suggest that you use the config flag self.config().is_verify(), which I already
introduced in order to support old kernels w.r.t constant ino check, as an indication for which st_dev can be expected in layer check.
I think the rules should be:
1. ./run --verify --samefs # should enforce all dentries on overlay st_dev
2. ./run --verify # should enforce the rules that you wrote
3. ./run [--samefs] # should allow for either old kernel rules or new rules
Your challenge is to manage to describe all those rules in a clean and short way,
just like you did with this patch.
Good luck!
Amir.
(see two more comments below)
Quoted 12 lines
--- context.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)context.py +0
-0@@ -532,17 +532,15 @@ class test_context: if self.skip_layer_test(): pass elif dev == self.lower_fs():
context.py class test_context: · line 542
Quoted 10 lines
context.py +3
-2- if dentry.is_dir(): - raise TestError(name + ": Directory unexpectedly on lower filesystem") + # Overlayfs never returns st_dev corresponding to any of + # the lower layers + raise TestError(name + ": File unexpectedly has lowerfs dev id") elif dentry.is_dir(): if dev != self.upper_dir_fs(): raise TestError(name + ": Directory not on union layer") elif dev == self.upper_fs() and not dentry.on_upper(): raise TestError(name + ": File unexpectedly on upper layer")
You can and should also add the opposite check to enforce that:
if dentry.on_upper() and not self.config().is_samefs() and dev != self.upper_fs():
"File unexpectedly not on upper layer"
context.py class test_context: · line 544
Quoted 6 lines
context.py +1
-4- elif dev != self.upper_fs() and dev != self.upper_dir_fs() and self.config().is_samefs(): - # For samefs, file is on overlay dev - # TODO: for non-samefs, check file dev matches pseudo dev - # and that pseduo dev != real dev + elif dev != self.upper_dir_fs() and self.config().is_samefs(): raise TestError(name + ": File on unexpected layer")
Here, the error could be more descriptive "File not on union layer"
Quoted 54 lines · IST Amir Goldstein
Quoted 6 lines · Chandan Rajendra
With constant
st_devimplemented, overlayfs never returns the real dev corresponding to lowerdir filesystems. Also, for the samefs case, overlayfs always returns the pseudost_devcorresponding to the union layer.Signed-off-by Chandan Rajendra <[email protected]>Chandan,
Tests look correct, however, the tests are correct for a future version of overlayfs
(overlayfs-devel branch) and we don't want to break unionmounts for current stable kernel and not even for older kernels, so we have to maintain backward compat somehow...
I suggest that you use the config flag self.config().is_verify(), which I already
introduced in order to support old kernels w.r.t constant ino check, as an indication for whichst_devcan be expected in layer check.I think the rules should be:
1. ./run --verify --samefs # should enforce all dentries on overlayst_dev
2. ./run --verify # should enforce the rules that you wrote
3. ./run [--samefs] # should allow for either old kernel rules or new rulesYour challenge is to manage to describe all those rules in a clean and short way,
just like you did with this patch.Good luck!
Amir.(see two more comments below)
Quoted 19 lines
--- context.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)context.py +3
-2@@ -532,17 +532,15 @@ class test_context: if self.skip_layer_test(): pass elif dev == self.lower_fs(): - if dentry.is_dir(): - raise TestError(name + ": Directory unexpectedly on lower filesystem") + # Overlayfs never returns st_dev corresponding to any of + # the lower layers + raise TestError(name + ": File unexpectedly has lowerfs dev id") elif dentry.is_dir(): if dev != self.upper_dir_fs():
Quoted 8 lines
context.py class test_context: · line 542
Quoted 3 lines
context.py +0
-0raise TestError(name + ": Directory not on union layer") elif dev == self.upper_fs() and not dentry.on_upper(): raise TestError(name + ": File unexpectedly on upper layer")You can and should also add the opposite check to enforce that:
ifdentry.on_upper()and not self.config().is_samefs() and dev !=self.upper_fs():
"File unexpectedly not on upper layer"
Hi Amir,
The above check will fail on the newer kernels which might have non-dirs (on non-samefs overlay instances) which have been copied-up from a file originally present on lowerdir. For such files, on_upper will be set but st_dev would correspond to the pseudo device that ovl_getattr() returns.
I have tried to groups together the tests within "is_samefs()" and "is_verify()" groups as shown below,
context.py +17 -11
@@ -530,20 +530,26 @@ class test_context: #self.output("- check_layer ", dentry.filename(), " -", dentry.layer(), " # ", dev, "\n") if self.skip_layer_test(): - pass - elif dev == self.lower_fs(): - if dentry.is_dir(): - raise TestError(name + ": Directory unexpectedly on lower filesystem") - elif dentry.is_dir(): + return + + if self.config().is_samefs(): if dev != self.upper_dir_fs(): + raise TestError(name + ": File not on union layer") + + if self.config().is_verify(): + if dev == self.lower_fs(): + # Overlayfs never returns st_dev corresponding to any of + # the lower layers + raise TestError(name + ": File unexpectedly on lower layer") + if dentry.is_dir() and dev != self.upper_dir_fs(): raise TestError(name + ": Directory not on union layer") - elif dev == self.upper_fs() and not dentry.on_upper(): + + if dev == self.upper_fs() and not dentry.on_upper(): raise TestError(name + ": File unexpectedly on upper layer") - elif dev != self.upper_fs() and dev != self.upper_dir_fs() and self.config().is_samefs(): - # For samefs, file is on overlay dev - # TODO: for non-samefs, check file dev matches pseudo dev - # and that pseduo dev != real dev - raise TestError(name + ": File on unexpected layer") + + if not self.config().is_samefs() and not self.config().is_verify() \ + and dentry.on_upper() and dev != self.upper_fs(): + raise TestError(name + ": File unexpectedly not on upper layer") if dentry.is_sym() and dentry not in symlinks: symlinks.add(dentry)
However, as described above, the last added test fails on newer kernels. I am still trying to figure out an ideal place in check_layer() to add this test.
Signature · 1 line
chandan
Quoted 118 lines · Chandan Rajendra
Quoted 54 lines · IST Amir Goldstein
Quoted 6 lines · Chandan Rajendra
With constant
st_devimplemented, overlayfs never returns the real dev corresponding to lowerdir filesystems. Also, for the samefs case, overlayfs always returns the pseudost_devcorresponding to the union layer.Signed-off-by Chandan Rajendra <[email protected]>Chandan,
Tests look correct, however, the tests are correct for a future version of overlayfs
(overlayfs-devel branch) and we don't want to break unionmounts for current stable kernel and not even for older kernels, so we have to maintain backward compat somehow...
I suggest that you use the config flag self.config().is_verify(), which I already
introduced in order to support old kernels w.r.t constant ino check, as an indication for whichst_devcan be expected in layer check.I think the rules should be:
1. ./run --verify --samefs # should enforce all dentries on overlayst_dev
2. ./run --verify # should enforce the rules that you wrote
3. ./run [--samefs] # should allow for either old kernel rules or new rulesYour challenge is to manage to describe all those rules in a clean and short way,
just like you did with this patch.Good luck!
Amir.(see two more comments below)
Quoted 19 lines
--- context.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)context.py +3
-2@@ -532,17 +532,15 @@ class test_context: if self.skip_layer_test(): pass elif dev == self.lower_fs(): - if dentry.is_dir(): - raise TestError(name + ": Directory unexpectedly on lower filesystem") + # Overlayfs never returns st_dev corresponding to any of + # the lower layers + raise TestError(name + ": File unexpectedly has lowerfs dev id") elif dentry.is_dir(): if dev != self.upper_dir_fs():Quoted 8 lines
context.py class test_context: · line 548
Quoted 3 lines
context.py +0
-0raise TestError(name + ": Directory not on union layer") elif dev == self.upper_fs() and not dentry.on_upper(): raise TestError(name + ": File unexpectedly on upper layer")You can and should also add the opposite check to enforce that:
ifdentry.on_upper()and not self.config().is_samefs() and dev !=self.upper_fs():
"File unexpectedly not on upper layer"Hi Amir,
The above check will fail on the newer kernels which might have non-dirs (on non-samefs overlay instances) which have been copied-up from a file originally present on lowerdir. For such files,
on_upperwill be set butst_devwould correspond to the pseudo device thatovl_getattr()returns.I have tried to groups together the tests within "
is_samefs()" and "is_verify()" groups as shown below,context.py +17
-11@@ -530,20 +530,26 @@ class test_context: #self.output("- check_layer ", dentry.filename(), " -", dentry.layer(), " # ", dev, "\n") if self.skip_layer_test(): - pass - elif dev == self.lower_fs(): - if dentry.is_dir(): - raise TestError(name + ": Directory unexpectedly on lower filesystem") - elif dentry.is_dir(): + return + + if self.config().is_samefs(): if dev != self.upper_dir_fs(): + raise TestError(name + ": File not on union layer") + + if self.config().is_verify(): + if dev == self.lower_fs(): + # Overlayfs never returns st_dev corresponding to any of + # the lower layers + raise TestError(name + ": File unexpectedly on lower layer") + if dentry.is_dir() and dev != self.upper_dir_fs(): raise TestError(name + ": Directory not on union layer") - elif dev == self.upper_fs() and not dentry.on_upper(): + + if dev == self.upper_fs() and not dentry.on_upper(): raise TestError(name + ": File unexpectedly on upper layer") - elif dev != self.upper_fs() and dev != self.upper_dir_fs() and self.config().is_samefs(): - # For samefs, file is on overlay dev - # TODO: for non-samefs, check file dev matches pseudo dev - # and that pseduo dev != real dev - raise TestError(name + ": File on unexpected layer") + + if not self.config().is_samefs() and not self.config().is_verify() \ + and dentry.on_upper() and dev != self.upper_fs(): + raise TestError(name + ": File unexpectedly not on upper layer") if dentry.is_sym() and dentry not in symlinks: symlinks.add(dentry)
Quoted 5 lines
However, as described above, the last added test fails on newer kernels. I am still trying to figure out an ideal place in
check_layer()to add this test.
Chandan,
I think your tests will fail on upstream kernel and older kernels.
The test matrix to verify is at least:
run --ov[=1] [--samefs] with kernel [v4.11|v4.12|overlayfs-next] run --ov[=1] --samefs --verify with kernel [4.12|overlayfs-next] run --ov[=1] --verify with kernel overlayfs-devel (with your patch)
* all overlayfs Kconfig options set to y
Maybe something like this.
It is not tested at all, so may be bogus. Please reply on specific lines if you don't
follow the reasoning:
if self.skip_layer_test():
pass
elif dentry.is_dir():
# Directory inodes are always on overlay st_dev if dev != self.upper_dir_fs():
raise TestError(name + ": Directory not on union layer")
pass
elif self.config().is_samefs():
# With samefs setup, files are on overlay st_dev if st_ino
is constant
# on copy up and on real st_dev if st_ino is not constant.
# --verify verifies constant st_ino, so it implies overlay
st_dev check.
# Without --verify, we allow for both options.
if dev == self.upper_dir_fs():
pass
if self.config().is_verify():
raise TestError(name + ": File not on union layer")
if dev != self.upper_fs():
raise TestError(name + ": File unexpectedly not on
lower/upper layer")
pass
else
# With non samefs setup, files are on pseudo or upper
st_dev if st_ino
# is constant on copy up and on lower or upper st_dev if
st_ino is not constant.
# --verify verifies constant st_ino, so it implies pseudo
st_dev check.
# Without --verify we allow for both options.
# Lower file can be on upper fs when rotating upper layers (--ov=N).
# TODO: stricter lower/upper checks for --ov=0.
if dev == self.upper_dir_fs():
raise TestError(name + ": File unexpectedly on union layer")
if dev == self.upper_fs():
if not dentry.on_upper():
raise TestError(name + ": File unexpectedly on upper layer")
pass
if self.config().is_verify()
if dev == self.lower_fs():
# Overlayfs returns pseudo st_dev or upper st_dev,
but never the lower layer
raise TestError(name + ": File unexpectedly on lower layer")
pass
if dev != self.upper_fs() and dev != self.lower_fs():
raise TestError(name + ": File unexpectedly not on
lower/upper layer")
pass if dentry.is_sym() and dentry not in symlinks:
symlinks.add(dentry)
Quoted 10 lines · Amir Goldstein
Chandan,
I think your tests will fail on upstream kernel and older kernels.
The test matrix to verify is at least:
run --ov[=1] [--samefs] with kernel [v4.11|v4.12|overlayfs-next] run --ov[=1] --samefs --verify with kernel [4.12|overlayfs-next] run --ov[=1] --verify with kernel overlayfs-devel (with your patch)
* all overlayfsKconfigoptions set to y
Quoted 5 lines
Maybe something like this.
It is not tested at all, so may be bogus. Please reply on specific lines if you don't
follow the reasoning:
Sorry for all the messed up spaced and line wrapping...
Quoted 31 lines
if
self.skip_layer_test():
pass
elifdentry.is_dir():
# Directory inodes are always on overlayst_devif dev !=self.upper_dir_fs():
raiseTestError(name + ": Directory not on union layer")
pass
elif self.config().is_samefs():
# With samefs setup, files are on overlayst_devifst_ino
is constant# on copy up and on real st_dev if st_ino is not constant. # --verify verifies constant st_ino, so it implies overlay st_dev check. # Without --verify, we allow for both options. if dev == self.upper_dir_fs(): pass if self.config().is_verify(): raise TestError(name + ": File not on union layer") if dev != self.upper_fs(): raise TestError(name + ": File unexpectedly not on lower/upper layer") pass else # With non samefs setup, files are on pseudo or upper st_dev if st_ino # is constant on copy up and on lower or upper st_dev if st_ino is not constant. # --verify verifies constant st_ino, so it implies pseudo st_dev check. # Without --verify we allow for both options.
Quoted 2 lines
# Lower file can be on upper fs when rotating upper layers (--ov=N). # TODO: stricter lower/upper checks for --ov=0.
Don't think this comment about Lower file is relevant to these test cases. I think in this context, not dentry.on_upper() means on lowermost layer, which is either self.lower_fs() or pseudo dev.
Quoted 7 lines
if dev ==
self.upper_dir_fs():
raiseTestError(name + ": File unexpectedly on union layer")
if dev ==self.upper_fs():
if notdentry.on_upper():
raiseTestError(name + ": File unexpectedly on upper layer")
pass
if self.config().is_verify()
Quoted 8 lines
if dev ==
self.lower_fs():
# Overlayfs returns pseudost_devor upperst_dev,
but never the lower layer
raiseTestError(name + ": File unexpectedly on lower layer")
pass
if dev !=self.upper_fs()and dev !=self.lower_fs():
raise TestError(name + ": File unexpectedly not on
lower/upper layer")
Yeah, this last test is wrong because without --verify, pseudo st_dev is still allowed.
Instead could check:
if dev == self.lower_fs() and dentry.on_upper():
raise TestError(name + ": File unexpectedly on lower layer")
Quoted 4 lines
pass
if
dentry.is_sym()and dentry not in symlinks:
symlinks.add(dentry)
Quoted 74 lines · Amir Goldstein
Quoted 10 lines · Amir Goldstein
Chandan,
I think your tests will fail on upstream kernel and older kernels.
The test matrix to verify is at least:
run --ov[=1] [--samefs] with kernel [v4.11|v4.12|overlayfs-next] run --ov[=1] --samefs --verify with kernel [4.12|overlayfs-next] run --ov[=1] --verify with kernel overlayfs-devel (with your patch)
* all overlayfsKconfigoptions set to yQuoted 5 lines
Maybe something like this.
It is not tested at all, so may be bogus. Please reply on specific lines if you don't
follow the reasoning:Sorry for all the messed up spaced and line wrapping...
Quoted 31 lines
if
self.skip_layer_test():
pass
elifdentry.is_dir():
# Directory inodes are always on overlayst_devif dev !=self.upper_dir_fs():
raiseTestError(name + ": Directory not on union layer")
pass
elif self.config().is_samefs():
# With samefs setup, files are on overlayst_devifst_ino
is constant# on copy up and on real st_dev if st_ino is not constant. # --verify verifies constant st_ino, so it implies overlay st_dev check. # Without --verify, we allow for both options. if dev == self.upper_dir_fs(): pass if self.config().is_verify(): raise TestError(name + ": File not on union layer") if dev != self.upper_fs(): raise TestError(name + ": File unexpectedly not on lower/upper layer") pass else # With non samefs setup, files are on pseudo or upper st_dev if st_ino # is constant on copy up and on lower or upper st_dev if st_ino is not constant. # --verify verifies constant st_ino, so it implies pseudo st_dev check. # Without --verify we allow for both options.Quoted 2 lines
# Lower file can be on upper fs when rotating upper layers (--ov=N). # TODO: stricter lower/upper checks for --ov=0.
Don't think this comment about Lower file is relevant to these test cases. I think in this context, not
dentry.on_upper()means on lowermost layer, which is eitherself.lower_fs()or pseudo dev.Quoted 7 lines
if dev ==
self.upper_dir_fs():
raiseTestError(name + ": File unexpectedly on union layer")
if dev ==self.upper_fs():
if notdentry.on_upper():
raiseTestError(name + ": File unexpectedly on upper layer")
pass
if self.config().is_verify()Quoted 8 lines
if dev ==
self.lower_fs():
# Overlayfs returns pseudost_devor upperst_dev,
but never the lower layer
raiseTestError(name + ": File unexpectedly on lower layer")
pass
if dev !=self.upper_fs()and dev !=self.lower_fs():
raise TestError(name + ": File unexpectedly not on
lower/upper layer")
Quoted 11 lines
Yeah, this last test is wrong because without --verify, pseudo
st_devis still allowed.
Instead could check:
if dev ==self.lower_fs()anddentry.on_upper():
raiseTestError(name + ": File unexpectedly on lower layer")Quoted 4 lines
pass
if
dentry.is_sym()and dentry not in symlinks:
symlinks.add(dentry)
OK, my pseudo patch was mostly correct, but full of brainoes, push a tested patch to
https://github.com/amir73il/unionmount-testsuite/commits/overlayfs-devel
Please review and verify.
Thanks,
Amir.
Quoted 6 lines · IST Amir Goldstein
OK, my pseudo patch was mostly correct, but full of brainoes, push a tested patch to
https://github.com/amir73il/unionmount-testsuite/commits/overlayfs-develPlease review and verify.
Hi Amir,
'./run --ov' on 'next' kernel (i.e. the one containing code which returns pseudo st_devs for files on lowerdir) fails as shown below,
$ ./run --ov *** *** ./run --ov --ts=0 open-plain *** TEST open-plain.py:10: Open O_RDONLY /mnt/a/foo100: File not on lower/upper layer
The corresponding code from check_layer() is,
elif dev != self.upper_fs() and dev != self.lower_fs():
raise TestError(name + ": File not on lower/upper layer")
This happens due to open-plain.py's subtest_1() opening a file on lowerdir in read-only mode (i.e. copy-up does not occur). Later, stat(2) invocation from check_layer() would end up returning the pseudo st_dev corresponding to lowerdir.
'./run --ov --samefs --verify' on 4.12 kernel fails as shown below,
$ ./run --ov --samefs --verify *** *** ./run --ov --ts=0 hard-link *** TEST hard-link.py:10: Hard link file ./run --link /mnt/a/foo100 /mnt/a/no_foo100 /mnt/a/no_foo100: inode number wrong (got 39001, want 37581)
The failure happens because the dentry representing the new hard link wouldn't have __OVL_PATH_ORIGIN set.
Signature · 1 line
chandan
Quoted 5 lines · Chandan Rajendra
Quoted 4 lines · IST Amir Goldstein
OK, my pseudo patch was mostly correct, but full of brainoes, push a tested patch to
https://github.com/amir73il/unionmount-testsuite/commits/overlayfs-devel
Quoted 8 lines
Quoted 2 lines
Please review and verify.
Hi Amir,
'./run --ov' on 'next' kernel (i.e. the one containing code which returns pseudo
st_devsfor files on lowerdir) fails as shown below,
Are you sure?
I'm pretty sure that I tested this.
What is the HEAD commit of the branch you are testing with?
Quoted 30 lines
$ ./run --ov *** *** ./run --ov --ts=0 open-plain *** TEST open-plain.py:10: Open O_RDONLY /mnt/a/foo100: File not on lower/upper layerThe corresponding code from
check_layer()is,elif dev !=
self.upper_fs()and dev !=self.lower_fs():
raiseTestError(name + ": File not on lower/upper layer")This happens due to open-plain.py's
subtest_1()opening a file on lowerdir in read-only mode (i.e. copy-up does not occur). Later, stat(2) invocation fromcheck_layer()would end up returning the pseudost_devcorresponding to lowerdir.'./run --ov --samefs --verify' on 4.12 kernel fails as shown below,
$ ./run --ov --samefs --verify *** *** ./run --ov --ts=0 hard-link *** TEST hard-link.py:10: Hard link file ./run --link /mnt/a/foo100 /mnt/a/no_foo100 /mnt/a/no_foo100: inode number wrong (got 39001, want 37581)
Quoted 3 lines
The failure happens because the dentry representing the new hard link wouldn't have
__OVL_PATH_ORIGINset.
Right.
That is because of fbaf94ee3cd5 ("ovl: don't set origin on broken lower hardlink")
that Miklos added just before final v4.12.
It will be fixed on kernel v4.13-rc1 with CONFIG_OVERLAYFS_INDEX=y
Thanks!
Quoted 11 lines · Amir Goldstein
Quoted 9 lines · Chandan Rajendra
Quoted 6 lines · IST Amir Goldstein
OK, my pseudo patch was mostly correct, but full of brainoes, push a tested patch to
https://github.com/amir73il/unionmount-testsuite/commits/overlayfs-develPlease review and verify.
Quoted 9 lines
Quoted 4 lines
Hi Amir,
'./run --ov' on 'next' kernel (i.e. the one containing code which returns pseudo
st_devsfor files on lowerdir) fails as shown below,Are you sure?
I'm pretty sure that I tested this.
What is the HEAD commit of the branch you are testing with?
Yes, you are right. I must've missed this basic test. Will push a fix.
Thanks for testing this!