From: Mateusz Guzik <mguzik@redhat.com>
To: Rajat Jain <rajatxjain@gmail.com>
Cc: linux-fsdevel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
Davide Libenzi <davidel@xmailserver.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: Anonymous inode cleanup?
Date: Fri, 13 Nov 2015 06:52:34 +0100 [thread overview]
Message-ID: <20151113055233.GA6674@mguzik> (raw)
In-Reply-To: <CAA93t1pFoXnpcCry5VV6_ZceBg9JYSr+kWfc7ztK0iAjp+_rBA@mail.gmail.com>
On Thu, Nov 12, 2015 at 09:43:00PM -0800, Rajat Jain wrote:
> Hello,
>
> I'm writing a module that wants to get anonymous fd [using
> anon_inode_getfd()] and my code looks like this:
>
> fd = anon_inode_getfd(...)
> if (fd < 0)
> return -EINVAL;
>
> if (foobar_fail()) {
> /* undo everything */
> return -EINVAL;
> }
>
> My question is that in case of a failure after the anon_inode_getfd(),
> I want to cleanup and undo whatever needs to be done w.r.t. anodnymous
> fd I just allocated. (May be put a reference, or return the fd to the
> free pool or whatever). Can some one please let me know what cleanup
> needs to be done?
>
> However neither I see a cleanup function, nor I see any of the drivers
> attempting
> to free the fd in case of failure.
>
It is impossible to properly clean up in this case without serious
tinkering. In fact this code cannot realiably work without weird
locking. By the time anon_inode_getfd returns, the file could have been
closed by a different thread.
What you want instead is anon_inode_getfile. See perf_event_open for an
example how to use it.
--
Mateusz Guzik
next prev parent reply other threads:[~2015-11-13 5:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-13 5:43 Anonymous inode cleanup? Rajat Jain
2015-11-13 5:52 ` Mateusz Guzik [this message]
2015-11-13 6:31 ` Al Viro
2015-11-18 20:28 ` Rajat Jain
2015-11-18 21:06 ` Al Viro
2015-11-18 21:10 ` Rajat Jain
2015-11-18 21:24 ` Al Viro
2015-11-18 21:25 ` Rajat Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151113055233.GA6674@mguzik \
--to=mguzik@redhat.com \
--cc=davidel@xmailserver.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rajatxjain@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.