From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from helmsgmaster01.f-secure.com ([193.110.108.20]:57272 "EHLO helmsgmaster01.f-secure.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751386AbdAYLsU (ORCPT ); Wed, 25 Jan 2017 06:48:20 -0500 From: Marko Rauhamaa To: Subject: Reproducible, long-standing fanotify+autofs problem CC: , Amir Goldstein Date: Wed, 25 Jan 2017 13:48:16 +0200 Message-ID: <878tpztl6n.fsf@drapion.f-secure.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-fsdevel-owner@vger.kernel.org List-ID: We have run into an easily reproducible fanotify hang that affects several distros as well as the latest development kernel. (It isn't fixed by Amir Goldstein's recent fanotify patch, BTW.) Here is a simple reproduction: 1. Compile and build the tiny test program below, which has been adapted from the example in "man fanotify": cc -o fantest3 fantest.c 2. Install autofs. 3. Run these commands as root: mkdir -p foo/home/test foo/user/test echo /sshome /etc/auto.sshome >/etc/auto.master echo "test / :/root/foo/home/test /user :/root/foo/user/test" \ >/etc/auto.sshome systemctl start autofs ls -l /sshome/test ./fantest3 / /sshome/test /sshome/test/user/ # NB! The final slash in the fantest3 command can be significant! 4. Observe the last command hang. While it is hung, other file system operations from other processes are blocked. 5. Press Ctrl-C to force fantest3 to exit. The file system becomes alive. Rerunning the fantest3 command no longer hangs. 6. To get back into the problem state, execute (as root): systemctl restart autofs ls -l /sshome/test ./fantest3 / /sshome/test /sshome/test/user/ ===Begin fantest.c====================================================== #include #include #include #include int main(int argc, char *argv[]) { int fd, i; if (argc < 2) { fprintf(stderr, "Usage: %s MOUNT ...\n", argv[0]); exit(EXIT_FAILURE); } fd = fanotify_init(FAN_CLOEXEC | FAN_CLASS_CONTENT | FAN_NONBLOCK, O_RDONLY); if (fd == -1) { perror("fanotify_init"); exit(EXIT_FAILURE); } for (i = 1; i < argc; i++) if (fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT, FAN_OPEN_PERM | FAN_CLOSE_WRITE, AT_FDCWD, argv[i]) == -1) { perror("fanotify_mark"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } ===End fantest.c======================================================== Marko