2012-06-22 09:33:37

by Ozan Çağlayan

[permalink] [raw]
Subject: get_unused_fd and get_unused_fd_flags

Hi,

With,

commit 1027abe8827b47f7e9c4ed6514fde3d44f79963c
Author: Al Viro <[email protected]>
Date: Wed Jul 30 04:13:04 2008 -0400

[PATCH] merge locate_fd() and get_unused_fd()

New primitive: alloc_fd(start, flags). get_unused_fd() and
get_unused_fd_flags() become wrappers on top of it.

Signed-off-by: Al Viro <[email protected]>

Two wrappers get_unused_fd() and get_unused_fd_flags() are introduced.
get_unused_fd() is an exported one-liner:

int get_unused_fd(void)
{
return alloc_fd(0, 0);
}
EXPORT_SYMBOL(get_unused_fd);

But get_unused_fd_flags() is implemented through a macro:

#define get_unused_fd_flags(flags) alloc_fd(0, (flags))

Both are wrappers around alloc_fd(). I'm quite new to this stuff but
why there's an asymmetry in here? One is exposed, the other is not.

(BTW: I'm doing compat-drm stuff for GSoC and I have to call
get_unused_fd_flags() but since alloc_fd() is not exported, this
doesn't work.)

Thanks :)

--
Ozan Çağlayan


2012-06-22 09:47:07

by Al Viro

[permalink] [raw]
Subject: Re: get_unused_fd and get_unused_fd_flags

On Fri, Jun 22, 2012 at 12:33:35PM +0300, Ozan ??a??layan wrote:
> But get_unused_fd_flags() is implemented through a macro:
>
> #define get_unused_fd_flags(flags) alloc_fd(0, (flags))
>
> Both are wrappers around alloc_fd(). I'm quite new to this stuff but
> why there's an asymmetry in here? One is exposed, the other is not.

Because get_unused_fd_flags() never had been exported. And
default policy for exports is "Don't, unless somebody can
demonstrate a clear need that can't be handled in other
ways".

> (BTW: I'm doing compat-drm stuff for GSoC and I have to call
> get_unused_fd_flags() but since alloc_fd() is not exported, this
> doesn't work.)

Details of that "have to", please. Note that existing modular uses of
get_unused_fd() tend to be rather fishy; if anything, I'd expect
get_unused_fd() eventually becoming internal-only, if we manage to
pull that off.

2012-06-22 09:59:32

by Ozan Çağlayan

[permalink] [raw]
Subject: Re: get_unused_fd and get_unused_fd_flags

> Details of that "have to", please.  Note that existing modular uses of
> get_unused_fd() tend to be rather fishy; if anything, I'd expect
> get_unused_fd() eventually becoming internal-only, if we manage to
> pull that off.

I've got it. I'm backporting the dma-buf (drivers/base/dma-buf.c)
feature to kernels < 3.3. It is actually pretty straightforward except
a single call to get_unused_fd_flags() from dma_buf_fd(). Then
get_unused_fd_flags() macro resolves to alloc_fd() which is not
exported.

Maybe I should backport alloc_fd and rename it to sth like
compat_alloc_fd and use that instead of alloc_fd in compat. What I was
trying to understand was the reason behind exporting/not-exporting
those similar wrappers. I don't try to justify that it should be
exported for me :)

Thanks!



--
Ozan Çağlayan

2012-06-22 10:35:02

by Ozan Çağlayan

[permalink] [raw]
Subject: Re: get_unused_fd and get_unused_fd_flags

> Maybe I should backport alloc_fd and rename it to sth like
> compat_alloc_fd and use that instead of alloc_fd in compat. What I was
> trying to understand was the reason behind exporting/not-exporting
> those similar wrappers. I don't try to justify that it should be
> exported for me :)

Well this already seems unbackportable as alloc_fd() pulls in
expand_files() which pulls in expand_fdtable() which pulls in
alloc_fdtable(), etc. etc.


--
Ozan Çağlayan