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

No support inotify_add_watch() in docker overlayfs storage backend #11705

Closed
brain-zhang opened this issue Mar 24, 2015 · 8 comments
Closed

No support inotify_add_watch() in docker overlayfs storage backend #11705

brain-zhang opened this issue Mar 24, 2015 · 8 comments
Labels
area/kernel area/storage/overlay kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed.

Comments

@brain-zhang
Copy link

Hi, I try to start a container which use overlayfs.

when i exec:

tail -f xx.log

it'll block after show serveral headlines.

i exec:

strace tail -n1 -f xx.log

it shows:

...
inotify_init()                          = 4
inotify_add_watch(4, "test.txt", IN_MODIFY|IN_ATTRIB|IN_DELETE_SELF|IN_MOVE_SELF) = 1
fstat(3, {st_mode=S_IFREG|0644, st_size=5470, ...}) = 0
read(4,

then block

i exec:

inotifywatch -v -e access -e modify -t 5 -r xx.log

show:

No events occurred.

but i has sustained flushing text to xx.log

so why doesn't overlayfs support inotify_add_watch()?

sysinfo:

uanme -a

Linux 3b6656e0c11c 3.19.0-9-generic #9-Ubuntu SMP Wed Mar 11 17:50:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

docker -v

Docker version 1.5.0-dev, build a78ce5c

@dqminh
Copy link
Contributor

dqminh commented Mar 24, 2015

IIRC, overlayfs does not fully support inotify ( so tail / inotifywatch may not work )

@brain-zhang
Copy link
Author

Hi,I found history discussion here:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/882147

It seems that --disable-inotify is a good solution and merits being made into a feature.

So i exec:

tail -f ---disable-inotify xx.log

it works.

@GordonTheTurtle GordonTheTurtle added the kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. label Mar 25, 2015
@bobrik
Copy link
Contributor

bobrik commented May 7, 2015

http://whichstoragedrivershouldiuse.github.io/

Easy, the one without inotify support :(

@wuxxin
Copy link

wuxxin commented May 8, 2015

for testing, you could try: https://launchpadlibrarian.net/149319334/overlayfs_inotify.patch

@purew
Copy link

purew commented Oct 1, 2015

Ran into this problem today with docker 1.8.2 using overlay-fs. Testcase:

docker run -it ubuntu
apt-get update && apt-get install -y inotify-tools
touch /tmp/test && inotifywait -e delete_self /tmp/test & sleep 1 && rm /tmp/test

Correct output should be:

Setting up watches.
Watches established.
/tmp/test DELETE_SELF

For some reason, IN_ATTRIB is still raised so my temporary workaround is to react to that signal instead for now.

@philips
Copy link
Contributor

philips commented Jun 8, 2016

@wuxxin Is anyone pushing this patch upstream?

cc @mjg59

@nehaljwani
Copy link

nehaljwani commented Sep 13, 2016

Another example where it works when the storage driver is devicemapper, but doesn't work as expected when the storage driver is overlayfs:

#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <assert.h>
#include <sys/inotify.h>
#include <sys/syscall.h>

struct InotifyEvent {
  int      wd;
  uint32_t mask;
  uint32_t cookie;
  uint32_t len;
  char     name __flexarr;
};

int main() {
    int fd;
    int inotifyFd;
    int watchDescriptor;
    char file[] = "/tmp/inotify_test.XXXXXX";
    struct InotifyEvent* event;

    printf("Inotify on a File.\n");

    // Create a file
    fd = mkstemp(file);
    assert(fd > -1);

    inotifyFd = inotify_init();
    assert(inotifyFd > -1);

    // add watch on the file for modify and delete
    watchDescriptor = inotify_add_watch(inotifyFd,
                       file,
                       IN_MODIFY |
                                       IN_DELETE_SELF);
    assert(watchDescriptor > -1);

    // modify file;
    write(fd, "test", sizeof("test"));
    fflush(NULL);

    // check modify
    event = reinterpret_cast<InotifyEvent*>(malloc(sizeof(*event)));

    assert(read(inotifyFd, event, sizeof(InotifyEvent)) > 0);

    assert(watchDescriptor == event->wd);
    assert(IN_MODIFY == event->mask);

    // check delete
    assert(0 == remove(file));
    assert(0 == close(fd));

    assert(read(inotifyFd, event, sizeof(InotifyEvent)) > 0);

    assert(watchDescriptor == event->wd);
    assert(IN_DELETE_SELF == event->mask);
    free(event);
}

In overlayfs, the first read() gets stuck. Another discussion which didn't have any follow up: http://lkml.iu.edu/hypermail/linux/kernel/1202.3/01782.html

yiannist added a commit to yiannist/ganeti that referenced this issue Nov 8, 2017
This test uses inotify which doesn't work well with docker overlayfs.
More information about this can be found in:
moby/moby#11705

Testcase:

> # Example: loops monitoring events forever.
> import pyinotify
>
> # Instanciate a new WatchManager (will be used to store watches).
> wm = pyinotify.WatchManager()
> # Associate this WatchManager with a Notifier (will be used to report
> # and process events).
> notifier = pyinotify.Notifier(wm)
> # Add a new watch on /tmp/foo for ganeti's MODIFY and IGNORED events.
> wm.add_watch('/tmp/foo', pyinotify.IN_MODIFY | pyinotify.IN_IGNORED)
> # Loop forever and handle events.
> notifier.loop()
yiannist added a commit to yiannist/ganeti that referenced this issue Nov 8, 2017
This test uses inotify which doesn't work well with docker overlayfs.
More information about this can be found in:
moby/moby#11705

Testcase:

> # Example: loops monitoring events forever.
> import pyinotify
>
> # Instanciate a new WatchManager (will be used to store watches).
> wm = pyinotify.WatchManager()
> # Associate this WatchManager with a Notifier (will be used to report
> # and process events).
> notifier = pyinotify.Notifier(wm)
> # Add a new watch on /tmp/foo for ganeti's MODIFY and IGNORED events.
> wm.add_watch('/tmp/foo', pyinotify.IN_MODIFY | pyinotify.IN_IGNORED)
> # Loop forever and handle events.
> notifier.loop()
yiannist added a commit to yiannist/ganeti that referenced this issue Nov 16, 2017
This test uses inotify which doesn't work well with docker overlayfs.
More information about this can be found in:
moby/moby#11705

Testcase:

> # Example: loops monitoring events forever.
> import pyinotify
>
> # Instanciate a new WatchManager (will be used to store watches).
> wm = pyinotify.WatchManager()
> # Associate this WatchManager with a Notifier (will be used to report
> # and process events).
> notifier = pyinotify.Notifier(wm)
> # Add a new watch on /tmp/foo for ganeti's MODIFY and IGNORED events.
> wm.add_watch('/tmp/foo', pyinotify.IN_MODIFY | pyinotify.IN_IGNORED)
> # Loop forever and handle events.
> notifier.loop()
yiannist added a commit to yiannist/ganeti that referenced this issue Nov 16, 2017
This test uses inotify which doesn't work well with docker overlayfs.
More information about this can be found in:
moby/moby#11705

Testcase:

> # Example: loops monitoring events forever.
> import pyinotify
>
> # Instanciate a new WatchManager (will be used to store watches).
> wm = pyinotify.WatchManager()
> # Associate this WatchManager with a Notifier (will be used to report
> # and process events).
> notifier = pyinotify.Notifier(wm)
> # Add a new watch on /tmp/foo for ganeti's MODIFY and IGNORED events.
> wm.add_watch('/tmp/foo', pyinotify.IN_MODIFY | pyinotify.IN_IGNORED)
> # Loop forever and handle events.
> notifier.loop()
@sam-thibault
Copy link
Contributor

This is an old issue. I will close it as stale.

@sam-thibault sam-thibault closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kernel area/storage/overlay kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed.
Projects
None yet
Development

No branches or pull requests