ENFILE, File table overflow, when using kernel ite

2019-07-26 17:03发布

I recently started with system programming and was wondering how iterate_dir works.

I have written something and I can't figure out why I get errors. My code starts to fail at about 190k-210k iterations.

struct dir_context context2 = { actor2, 0 };

for (i = 0; i < 1000000; i++)
{
    file = filp_open("/", O_RDONLY, 0);
    if (IS_ERR(file))
    {
        printk(KERN_ALERT "ERR: %d", file);
        break;
    }
    if (iterate_dir(file, &context2))
    {
        printk(KERN_ALERT "iterate_dir failed");
        break;
    }
    filp_close(file, 0);
}

The error is always the same 23 (ENFILE, File table overflow), but I opened and closed the file and actor2 is doing nothing. Sometimes vfs file-max limit xxx reached is printed.

static int actor2(struct dir_context *ctx, const char *name, int namlen, loff_t offset, u64 ino, unsigned int d_type)
{
    return 0;
}

Or maybe I have to close the files inside of actor2 (but there is no filep?!).

0条回答
登录 后发表回答