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

Test inotify watch after drop caches #246

Closed

Conversation

amir73il
Copy link
Contributor

A test for a problem reported by Niklas Cassel for a setup of inotify watch on overlayfs:
https://marc.info/?l=linux-unionfs&m=151581833424827&w=2

Starts with a face lift to existing inotify tests

@metan-ucw
Copy link
Member

The first two patches looks good to me.

I do have some questions for the new testcase though.

Is there a kernel commit that fixes the bug? We usually add the commit hash to the top level comment of the test so that everyone can check if the tested kernel should contain the fix or not.

Also is there a pointer to original reproducer? We tend to include link to it as well.

tst_brk(TBROK, "Failed to open drop_caches");
}
}

Copy link
Member

Choose a reason for hiding this comment

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

We do have SAFE_FILE_PRINTF() exactly for this purpose, the whole function can be replaced with:
SAFE_FILE_PRINTF("proc/sys/vm/drop_caches", "2");

{
struct stat buf;

fd_notify = tst_syscall(__NR_inotify_init1, O_NONBLOCK);
Copy link
Member

Choose a reason for hiding this comment

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

This calls for addition of myinotify_init1() to the inotify.h.

@amir73il
Copy link
Contributor Author

@metan-ucw the fix commit is not yet in upstream. it is on Miklos's overlayfs-next branch,
which is queued for the upcoming v4.16 merge window
31747eda41ef - ovl: hash directory inodes for fsnotify
I will add this commit to the test description once fix commit is merged upstream.

I did not get a reproducer. The reproducer was described in the post from Niklas that I referred to in the RP.

@metan-ucw
Copy link
Member

Then something is not right, the test is passing for me on vanilla 4.14.11. Do I get it right that we should stop getting updates after we drop the dentry cache?

@amir73il
Copy link
Contributor Author

amir73il commented Jan 25, 2018

That's because the bug is an overlay bug, not an inotify bug.
I ran the test with TMPDIR=<path/to/overlay/mount>.
Sorry for failing to mention that.
Example for setting up overlay mount:
mkdir upper work lower ovl
mount -t overlay overlay ovl -oupperdir=upper,lowerdir=lower,workdir=work

@metan-ucw
Copy link
Member

Then the test has to mount the overlay in the test setup().

@amir73il
Copy link
Contributor Author

OK. will do that.

@amir73il
Copy link
Contributor Author

Please note that the commit in the test description is in linux-next tree, but not yet upstream

@amir73il amir73il force-pushed the inotify-drop-caches branch 3 times, most recently from 3b4f443 to a3183bb Compare January 28, 2018 14:01
@amir73il
Copy link
Contributor Author

Rebased to master.
Added directory copy-up before drop caches to cover more cases.
Exit with TCONF status if overlayfs is not available in kernel.
Not sure what these CI build failures are about?

@amir73il amir73il force-pushed the inotify-drop-caches branch 2 times, most recently from cb34158 to d2445a2 Compare February 4, 2018 14:30
@amir73il
Copy link
Contributor Author

amir73il commented Feb 4, 2018

Added another test for another issue I found.
I will update the fix commit once it gets merged upstream.

@amir73il
Copy link
Contributor Author

@metan-ucw commit 31747eda41ef that fixes test case inotify07 in now merged to kernel v4.16-rc1.
The test case inotify08 is still failing in upstream kernel.
Would you like me to split test inotify08 to a new pull request? or just modify test description to not mention a fix commit?

@metan-ucw
Copy link
Member

If there is a real bug we can always push the test even if there is no upstream commit, we just have to add that information to the test top level comment and then replace it with kernel commit id once the fix is released.

@amir73il
Copy link
Contributor Author

@metan-ucw I updated fix commit of inotify08. It's not upstream yet, but on overlayfs-next branch, so will get upstream soon.

@metan-ucw
Copy link
Member

I've pushed the first two patches along with seven more fixes for the original inotify tests on the top of that. Some of the problems I've fixed are in the new test you wrote as well. Can you please rebase the pull request and also update the two new test cases?

@amir73il
Copy link
Contributor Author

FYI, commit 764baba80168 from inotify08 was merged to v4.16-rc5

@amir73il
Copy link
Contributor Author

@metan-ucw ping

@amir73il amir73il force-pushed the inotify-drop-caches branch 2 times, most recently from 2171cff to 1b26582 Compare April 5, 2018 10:24
@amir73il
Copy link
Contributor Author

amir73il commented Apr 5, 2018

@metan-ucw rebased and fixed problem with inotify07 -i 2

* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
Copy link
Member

Choose a reason for hiding this comment

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

LTP default license is GPLv2+ (the any later one) but that is very minor.

tst_brk(TBROK | TERRNO,
"read(%d, buf, %zu) failed",
fd_notify, EVENT_BUF_LEN);

Copy link
Member

Choose a reason for hiding this comment

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

The only nit for this version is that when executed on broken kernel the failure message produced is:

BROK: read(3, buf, 32768) failed: EAGAIN/EWOULDBLOCK

Which looks much more like a broken test rather than anything else. Can we please check for the EAGAIN errno here and print a bit more user friendly TFAIL message in this case?

The same applies to the next test and apart from that the code looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. there are already meaningful TFAIL messages further down, so I only skipped TBROK for EAGAIN case

SAFE_STAT(FILE_PATH, &buf);
tst_res(TINFO, FILE_PATH " ino=%lu, dev=%u:%u", buf.st_ino,
major(buf.st_dev), minor(buf.st_dev));

Copy link
Member

Choose a reason for hiding this comment

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

I've also got a header deprecation warnings on newer systems for the minor() and major():

inotify08.c:211:13: warning: In the GNU C Library, "minor" is defined
 by <sys/sysmacros.h>. For historical compatibility, it is
 currently defined by <sys/types.h> as well, but we plan to
 remove this soon. To use "minor", include <sys/sysmacros.h>
 directly. If you did not intend to use a system-defined macro
 "minor", you should undefine it after including <sys/types.h>.

So we should add #include <sys/sysmacros.h> to the includes here.

Add watch on an overlayfs lower directory, then copy up the directory
and drop dentry and inode caches.

An inotify watch pins the directory inode in cache, but not the dentry.
Execute operations on directory and child and expect events to be
reported on directory watch. This will fail if file system does
not obtain the pinned inode to the new allocated dentry after copy up
and drop caches.

This is a regression test for commit 31747eda41ef ("ovl: hash directory
inodes for fsnotify").

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
@amir73il amir73il force-pushed the inotify-drop-caches branch 2 times, most recently from 291c24d to c6b6a5b Compare April 12, 2018 14:51
Add watch on an overlayfs lower file, then copy up the file
and drop dentry and inode caches.

An inotify watch pins the file inode in cache, but not the dentry.
Execute operations on file and expect events to be reported on file
watch. This will fail if file system does not obtain the pinned inode
to the new allocated dentry after copy up and drop caches.

This is a regression test for commit 764baba80168 ("ovl: hash non-dir by
lower inode for fsnotify").

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
@metan-ucw
Copy link
Member

Applied, thanks!

@metan-ucw metan-ucw closed this Apr 19, 2018
@amir73il amir73il deleted the inotify-drop-caches branch November 7, 2020 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants