mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* KernFS: Missing IN_DELETE_SELF or IN_IGNORED inotify events
@ 2023-05-24 19:53 Josef Schönberger
  2023-05-24 22:10 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Josef Schönberger @ 2023-05-24 19:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Tejun Heo; +Cc: linux-kernel

Hi everybody,

I'm currently working on event listeners for cgroups for a long running
daemon. I found that the removal of cgroups that I'm currently listening
for produces neither an IN_DELETE_SELF nor an IN_IGNORED event; which is
unfortunate, since I need to maintain a map from watch descriptors to
paths, from which I would like to remove all obsolete entries.

Since this is not the documented behaviour and since I could not find
any material that would specify an intention behind this, I'm assuming
that this is a bug?

I've found that the same applies to the sysfs. Taking a look at the
kernel code, I'd guess that the issue might be in KernFS.

I've appended a minimal reproducible example.

Thanks
Josef



#include <stdlib.h>
#include <err.h>
#include <sys/inotify.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <signal.h>

void cleanup(int signo) {
    (void) signo;
    printf("Removing /sys/fs/cgroup/demo again...\n");
    if (rmdir("/sys/fs/cgroup/demo"))
        err(EXIT_FAILURE, "Could not remove /sys/fs/cgroup/demo");
    exit(0);
}

int main(void) {
    if (geteuid() != 0)
        fprintf(stderr, "Need root privileges.\n"
                "Will probably not be able to cgroup without.\n"
                "Giving it a shot regardless...\n");

    int fd = inotify_init();
    if (fd < 0)
        err(EXIT_FAILURE, "Could not create inotify fd");

    if (mkdir("/sys/fs/cgroup/demo", 755))
        err(EXIT_FAILURE, "Could not create cgroup @ /sys/fs/cgroup/demo");

    signal(SIGINT, cleanup);

    int wd = inotify_add_watch(fd, "/sys/fs/cgroup/demo", IN_DELETE_SELF);
    if (wd < 0)
        err(EXIT_FAILURE, "Could not add /sys/fs/cgroup/demo to inotify
fd");

    printf("Expecting to read an IN_DELETE_SELF or IN_IGNORED event...\n");
    char buf[512];
    ssize_t nbytes = read(fd, buf, sizeof(buf));
    if (nbytes < 0)
        err(EXIT_FAILURE, "Could not read from inotify fd");

    printf("Read %zd bytes\n", nbytes);
    cleanup(0);
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: KernFS: Missing IN_DELETE_SELF or IN_IGNORED inotify events
  2023-05-24 19:53 KernFS: Missing IN_DELETE_SELF or IN_IGNORED inotify events Josef Schönberger
@ 2023-05-24 22:10 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2023-05-24 22:10 UTC (permalink / raw)
  To: Josef Schönberger; +Cc: Greg Kroah-Hartman, linux-kernel

On Wed, May 24, 2023 at 09:53:01PM +0200, Josef Schönberger wrote:
> Hi everybody,
> 
> I'm currently working on event listeners for cgroups for a long running
> daemon. I found that the removal of cgroups that I'm currently listening
> for produces neither an IN_DELETE_SELF nor an IN_IGNORED event; which is
> unfortunate, since I need to maintain a map from watch descriptors to
> paths, from which I would like to remove all obsolete entries.
> 
> Since this is not the documented behaviour and since I could not find
> any material that would specify an intention behind this, I'm assuming
> that this is a bug?
> 
> I've found that the same applies to the sysfs. Taking a look at the
> kernel code, I'd guess that the issue might be in KernFS.

Yeah, that'd be all kernfs. kernfs does have some explicit fsnotify hookups
so that kernfs users can generate custom modified events (e.g. for
cgroup.events file) but doesn't do anything else. If the generic layer
generates events, they'd go out. If not, they won't. I can't think of a
reason why hooking up the missing events would be difficult tho. I'm pretty
bandwidth constrained these days and don't know when I'll be able to get to
it but if you wanna take a stab at it, I'd be happy to review.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-24 22:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-24 19:53 KernFS: Missing IN_DELETE_SELF or IN_IGNORED inotify events Josef Schönberger
2023-05-24 22:10 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®