Skip to contentSkip to conversation

linuxabi

PATCH In review [email protected] 14 participants 15 messages Oct 1, 2003 – Oct 4, 2003 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linuxabi

Hi Linus,

Something we have talked about for a long time is separating out from the kernel headers the parts fit for inclusion in user space.

This is a very large project, and it will take a long time, especially if we want the user space headers to be a pleasure to look at, instead of just a cut-n-paste copy of whatever we find in the current headers.

Some start is required, and the very first step is making sure that you agree with the project. Immediately following is the choice of directory names.

Below
(i) a small textfile "linuxabi" describing the naming
(subdirectories linuxabi and linuxabi-alpha etc of include),
(ii) the file linuxabi/mountflags.h with definitions for
MS_RDONLY and family,
(iii) the file linux/mountflags.h that includes
linuxabi/mountflags.h and moreover defines things like MS_RMT_MASK and IS_NOATIME(inode), and
(iv) the patch on fs.h that removes these defines and
adds an include line.

Andries

Documentation/linuxabi +18 -0
diff -u --recursive --new-file -X /linux/dontdiff a/Documentation/linuxabi b/Documentation/linuxabi
@@ -0,0 +1,18 @@
+The subdirectories  linuxabi  and  linuxabi-$ARCH 
+(linuxabi-alpha, linuxabi-arm, ...) of linux/include
+are meant for headers that are to be used both by the kernel
+and in user space. The symbolic link  linuxabi-arch
+points at  linuxabi-$ARCH  for the current architecture.
+
+Be careful not to pollute namespace.
+
+Typical material for such headers are manifest constants
+and structures used by the kernel-userspace interface.
+
+Make sure no symbolic types like dev_t, pid_t, ino_t and
+the like are used, but only explicit types like char and
+int, or even more explicit types like uint8_t and int64_t.
+
+These headers are "append-only", in the sense that Linux
+tries to keep supporting old interfaces.
+
include/linux/fs.h +5 -64

91 lines not on this page · raw message

include/linux/mountflags.h +40 -0
diff -u --recursive --new-file -X /linux/dontdiff a/include/linux/mountflags.h b/include/linux/mountflags.h
@@ -0,0 +1,40 @@
+#ifndef _LINUX_MOUNTFLAGS_H
+#define _LINUX_MOUNTFLAGS_H
+
+#include <linuxabi/mountflags.h>
+
+/*
+ * Superblock flags that can be altered by MS_REMOUNT
+ */
+#define MS_RMT_MASK	(MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|\
+			 MS_NODIRATIME)
+
+/*
+ * Note that nosuid etc flags are inode-specific: setting some file-system
+ * flags just means all the inodes inherit those flags by default. It might be
+ * possible to override it selectively if you really wanted to with some
+ * ioctl() that is not currently implemented.
+ *
+ * Exception: MS_RDONLY is always applied to the entire file system.
+ *
+ * Unfortunately, it is possible to change a filesystems flags with it mounted
+ * with files in use.  This means that all of the inodes will not have their
+ * i_flags updated.  Hence, i_flags no longer inherit the superblock mount
+ * flags, so these have to be checked separately. -- [email protected]
+ */
+#define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
+
+#define IS_RDONLY(inode)        __IS_FLG(inode, MS_RDONLY)
+#define IS_MANDLOCK(inode)	__IS_FLG(inode, MS_MANDLOCK)
+#define IS_NODIRATIME(inode)	__IS_FLG(inode, MS_NODIRATIME)
+#define IS_POSIXACL(inode)	__IS_FLG(inode, MS_POSIXACL)
+#define IS_ONE_SECOND(inode)	__IS_FLG(inode, MS_ONE_SECOND)
+
+#define IS_SYNC(inode)	       (__IS_FLG(inode, MS_SYNCHRONOUS) || \
+				       ((inode)->i_flags & S_SYNC))
+#define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
+				       ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
+#define IS_NOATIME(inode)      (__IS_FLG(inode, MS_NOATIME) || \
+				       ((inode)->i_flags & S_NOATIME))
+
+#endif /* _LINUX_MOUNTFLAGS_H */
include/linuxabi/mountflags.h +32 -0
diff -u --recursive --new-file -X /linux/dontdiff a/include/linuxabi/mountflags.h b/include/linuxabi/mountflags.h
@@ -0,0 +1,32 @@
+#ifndef _LINUXABI_MOUNTFLAGS_H
+#define _LINUXABI_MOUNTFLAGS_H
+
+/*
+ * These are the fs-independent mount-flags: up to 32 flags are supported
+ */
+#define MS_RDONLY	 1	/* Mount read-only */
+#define MS_NOSUID	 2	/* Ignore suid and sgid bits */
+#define MS_NODEV	 4	/* Disallow access to device special files */
+#define MS_NOEXEC	 8	/* Disallow program execution */
+#define MS_SYNCHRONOUS	16	/* Writes are synced at once */
+#define MS_REMOUNT	32	/* Alter flags of a mounted FS */
+#define MS_MANDLOCK	64	/* Allow mandatory locks on an FS */
+#define MS_DIRSYNC	128	/* Directory modifications are synchronous */
+#define MS_NOATIME	1024	/* Do not update access times. */
+#define MS_NODIRATIME	2048	/* Do not update directory access times */
+#define MS_BIND		4096
+#define MS_MOVE		8192
+#define MS_REC		16384
+#define MS_VERBOSE	32768
+#define MS_POSIXACL	(1<<16)	/* VFS does not apply the umask */
+#define MS_ONE_SECOND	(1<<17)	/* fs has 1 sec a/m/ctime resolution */
+#define MS_ACTIVE	(1<<30)
+#define MS_NOUSER	(1<<31)
+
+/*
+ * Old magic mount flag and mask
+ */
+#define MS_MGC_VAL 0xC0ED0000
+#define MS_MGC_MSK 0xffff0000
+
+#endif /* _LINUXABI_MOUNTFLAGS_H */
#1 lore raw

Documentation/linuxabi line 17

Quoted 2 lines · In article <[email protected]> you wrote:
Documentation/linuxabi +2 -0
+These headers are "append-only", in the sense that Linux
+tries to keep supporting old interfaces.

I dont think this is true. Neighter was is true in the past nor is it desireable in all cases. We may define a range of releases, where the ABI will be stable, but I am not sure we find a text everybody agrees on.

I do think it is not a bead idea to keep deprecated values at least commented out, to avoid reuse, whenever possible.

Otherwise I love the idea. Have you checked back with the Glibc folks?

include/linuxabi/mountflags.h line 21

Quoted 3 lines
include/linuxabi/mountflags.h +3 -0
+#define MS_NODIRATIME  2048    /* Do not update directory access times */
+#define MS_BIND                4096
+#define MS_POSIXACL    (1<<16) /* VFS does not apply the umask */

can we clean that up? with shifting, without shifting, with comments and without comments? I suggest to use the linuxdoc comments mandatory for the abi files.

Quoted 1 line

+ * Old magic mount flag and mask

i also suggest to think twice about using the word old somewhere. valid-since, deprecated-after may be used in conjunction with version identifiers. And not including deprecated symbols is also a good start.

Greetings
Bernd

Signature · 2 lines
eckes privat - http://www.eckes.org/
Project Freefire - http://www.freefire.org/
#2 lore raw
Quoted 5 lines · Bernd Eckenfels

include/linuxabi/mountflags.h line 21

Quoted 3 lines
include/linuxabi/mountflags.h +3 -0
+#define MS_NODIRATIME  2048    /* Do not update directory access times */
+#define MS_BIND                4096
+#define MS_POSIXACL    (1<<16) /* VFS does not apply the umask */

can we clean that up? with shifting, without shifting, with comments and without comments? I suggest to use the linuxdoc comments mandatory for the abi files.

... and make it enum, while we are at it. It's cleaner, it survives cpp and it can be handled by gdb et.al. in sane way.

Unless we really want to support pre-v7 compilers, there is no benefit in using #define for such constants.

#3 lore raw
Followup to:  <[email protected]>
By author:    [email protected]
In newsgroup: linux.dev.kernel
Quoted 10 lines · Bernd Eckenfels
Quoted 6 lines

include/linuxabi/mountflags.h line 21

Quoted 4 lines
include/linuxabi/mountflags.h +3 -0
+#define MS_NODIRATIME  2048    /* Do not update directory access times */
+#define MS_BIND                4096
+#define MS_POSIXACL    (1<<16) /* VFS does not apply the umask */

can we clean that up? with shifting, without shifting, with comments and without comments? I suggest to use the linuxdoc comments mandatory for the abi files.

Quoted 5 lines

... and make it enum, while we are at it. It's cleaner, it survives cpp and it can be handled by gdb et.al. in sane way.

Unless we really want to support pre-v7 compilers, there is no benefit in using #define for such constants.

... except you can use #ifdef to test for obsolete headers.

-hpa

Signature · 4 lines
<[email protected]> at work, <[email protected]> in private!
If you send me mail in HTML format I will assume it's spam.
"Unix gives you enough rope to shoot yourself in the foot."
Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64
#4 lore raw
Quoted 13 lines · H. Peter Anvin
Followup to:  <[email protected]>
By author:    [email protected]
In newsgroup: linux.dev.kernel
Quoted 10 lines · Bernd Eckenfels
Quoted 6 lines

include/linuxabi/mountflags.h line 21

Quoted 4 lines
include/linuxabi/mountflags.h +3 -0
+#define MS_NODIRATIME  2048    /* Do not update directory access times */
+#define MS_BIND                4096
+#define MS_POSIXACL    (1<<16) /* VFS does not apply the umask */

can we clean that up? with shifting, without shifting, with comments and without comments? I suggest to use the linuxdoc comments mandatory for the abi files.

Quoted 7 lines
Quoted 5 lines

... and make it enum, while we are at it. It's cleaner, it survives cpp and it can be handled by gdb et.al. in sane way.

Unless we really want to support pre-v7 compilers, there is no benefit in using #define for such constants.

... except you can use #ifdef to test for obsolete headers.

A common uber-ugly trick (seen in Solaris headers) to solve this problem is:

  enum {
  #define FOO FOO
    FOO,
  #define BAR BAR
    BAR
  } 

Phil.

#5 lore raw
Quoted 6 lines · Philippe Troin

A common uber-ugly trick (seen in Solaris headers) to solve this problem is:

  enum {
  #define FOO FOO
    FOO,

I always thought this trick was kind of cool, despite the slight increase in ugliness for the enum definition.

-Miles

Signature · 2 lines
"Though they may have different meanings, the cries of 'Yeeeee-haw!' and
 'Allahu akbar!' are, in spirit, not actually all that different."
#6 lore raw
In reply to [email protected]
Quoted 9 lines · On Wed, Oct 01, 2003 at 04:34:37AM +0100…
Quoted 5 lines · Bernd Eckenfels

include/linuxabi/mountflags.h line 21

Quoted 3 lines
include/linuxabi/mountflags.h +3 -0
+#define MS_NODIRATIME  2048    /* Do not update directory access times */
+#define MS_BIND                4096
+#define MS_POSIXACL    (1<<16) /* VFS does not apply the umask */

can we clean that up? with shifting, without shifting, with comments and without comments? I suggest to use the linuxdoc comments mandatory for the abi files.

Quoted 5 lines

... and make it enum, while we are at it. It's cleaner, it survives cpp and it can be handled by gdb et.al. in sane way.

Unless we really want to support pre-v7 compilers, there is no benefit in using #define for such constants.

... although with -g3 the GDB argument goes away; but I'm not arguing about the surviving-cpp part.

Signature · 2 lines
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer
#7 lore raw
In reply to [email protected]
Quoted 11 lines · On 10.01, [email protected] wrote:

Hi Linus,

Something we have talked about for a long time is separating out from the kernel headers the parts fit for inclusion in user space.

This is a very large project, and it will take a long time, especially if we want the user space headers to be a pleasure to look at, instead of just a cut-n-paste copy of whatever we find in the current headers.

Quoted 7 lines

Some start is required, and the very first step is making sure that you agree with the project. Immediately following is the choice of directory names.

Below
(i) a small textfile "linuxabi" describing the naming
(subdirectories linuxabi and linuxabi-alpha etc of include),

Why not just 'abi' ? Simpler, and allows glibc to include
just 'abi/xxxx' in other systems if they follow the same convention (BSD?) ?

Where would this live in userspace, /usr/include/abi or /usr/include/linux/abi ? How would this relate to current /usr/include/linux
(symlink /usr/include/linux to /usr/include/abi) ?

Just curious.

Signature · 4 lines
J.A. Magallon <jamagallon()able!es>     \                 Software is like sex:
werewolf!able!es                         \           It's better when it's free
Mandrake Linux release 9.2 (Cooker) for i586
Linux 2.4.23-pre5-jam1 (gcc 3.3.1 (Mandrake Linux 9.2 3.3.1-2mdk))
#8 lore raw
In reply to [email protected]
Quoted 6 lines · [email protected] writes:

Hi Linus,

Something we have talked about for a long time is separating out from the kernel headers the parts fit for inclusion in user space.

Quoted 8 lines

This is a very large project, and it will take a long time, especially if we want the user space headers to be a pleasure to look at, instead of just a cut-n-paste copy of whatever we find in the current headers.

Some start is required, and the very first step is making sure that you agree with the project. Immediately following is the choice of directory names.

This is a 2.7 project. Doing this right requires a lot more than what you are doing here.

One example is that we need to be very careful with is that the glibc abi is not the same as the linux kernel abi. Even though most of the functions are pass through some are not. And which are which is a fairly arbitrary decision. So all of the definitions exported through linuxabi need to be in a linux centric namespace. This is especially true because otherwise I could not include linuxabi/mountflags.h and sys/mount.h and not get compilation conflicts.

I believe linuxabi/mountflags.h should look more like:

include/linuxabi/mountflags.h +32 -0
@@ -0,0 +1,32 @@
+#ifndef _LINUXABI_MOUNTFLAGS_H
+#define _LINUXABI_MOUNTFLAGS_H
+
+/*
+ * These are the fs-independent mount-flags: up to 32 flags are supported
+ */
+#define LINUX_MS_RDONLY	 1	/* Mount read-only */
+#define LINUX_MS_NOSUID	 2	/* Ignore suid and sgid bits */
+#define LINUX_MS_NODEV	 4	/* Disallow access to device special files */
+#define LINUX_MS_NOEXEC	 8	/* Disallow program execution */
+#define LINUX_MS_SYNCHRONOUS	16	/* Writes are synced at once */
+#define LINUX_MS_REMOUNT	32	/* Alter flags of a mounted FS */
+#define LINUX_MS_MANDLOCK	64	/* Allow mandatory locks on an FS */
+#define LINUX_MS_DIRSYNC	128	/* Directory modifications are synchronous */
+#define LINUX_MS_NOATIME	1024	/* Do not update access times. */
+#define LINUX_MS_NODIRATIME	2048	/* Do not update directory access times */
+#define LINUX_MS_BIND		4096
+#define LINUX_MS_MOVE		8192
+#define LINUX_MS_REC		16384
+#define LINUX_MS_VERBOSE	32768
+#define LINUX_MS_POSIXACL	(1<<16)	/* VFS does not apply the umask */
+#define LINUX_MS_ONE_SECOND	(1<<17)	/* fs has 1 sec a/m/ctime resolution */
+#define LINUX_MS_ACTIVE	(1<<30)
+#define LINUX_MS_NOUSER	(1<<31)
+
+/*
+ * Old magic mount flag and mask
+ */
+#define LINUX_MS_MGC_VAL 0xC0ED0000
+#define LINUX_MS_MGC_MSK 0xffff0000
+
+#endif /* _LINUXABI_MOUNTFLAGS_H */

Eric

#9 lore raw
Quoted 1 line · Eric W. Biederman

This is a 2.7 project.

I disagree. This is unrelated to kernel development, just like working on sparse is unrelated to kernel development.

Quoted 2 lines

Doing this right requires a lot more
than what you are doing here.

Possibly. So we need discussion.

I have registered comment #1: Al prefers the enum style. A possibility.

Now you come with comment #2: write LINUX_MS_RDONLY instead of MS_RDONLY. You have not convinced me.

Quoted 8 lines

One example is that we need to be very careful with is that the glibc abi is not the same as the linux kernel abi. Even though most of the functions are pass through some are not. And which are which is a fairly arbitrary decision. So all of the definitions exported through linuxabi need to be in a linux centric namespace. This is especially true because otherwise I could not include linuxabi/mountflags.h and sys/mount.h and not get compilation conflicts.

Today glibc tells me in sys/mount.h
#define MS_RMT_MASK (MS_RDONLY | MS_MANDLOCK)
and in linux/fs.h
#define MS_RMT_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|MS_NODIRATIME)

It seems glibc is not even self-consistent.
Consider linuxabi/mountflags.h as part of the replacement for linux/fs.h.

Andries

#10 lore raw
Quoted 6 lines · Andries Brouwer
Quoted 1 line · Eric W. Biederman

This is a 2.7 project.

I disagree. This is unrelated to kernel development, just like working on sparse is unrelated to kernel development.

Granted. The major point is that it requires a development cycle before it is ready. Only if this is to be maintained as part of the kernel is it needed to be 2.7 work.

Quoted 10 lines
Quoted 2 lines

Doing this right requires a lot more
than what you are doing here.

Possibly. So we need discussion.

I have registered comment #1: Al prefers the enum style. A possibility.

Now you come with comment #2: write LINUX_MS_RDONLY instead of MS_RDONLY. You have not convinced me.

My point is that we need to cleanly handle the fact that glibc defines it's own abi that is not equivalent to the kernel abi. A linux specific namespace does that. After libc is done with the definitions users will still use MS_RDONLY.

Using defines unconditionally in a private namespace is cumbersome. A better way to go is probably:

linuxabi/features.h
....
#ifdef __USE_LINUX_NS

# define LINUX_NS(X) LINUX_##
#else
# define LINUX_NS(X) X
#endif

.....
linuxabi/mountflags.h
#include <linuxabi/features.h>

enum {
        LINUX_NS(MS_RDONLY) = 1,
	LINUX_NS(MS_NOSUID) = 2,
};

The result being that defines are placed in their own namespace if necessary to avoid libc/kernel abi differences.

Eric

#11 lore raw
Quoted 10 lines · Eric W. Biederman
Quoted 5 lines · Andries Brouwer
Quoted 1 line · Eric W. Biederman

This is a 2.7 project.

I disagree. This is unrelated to kernel development, just like working on sparse is unrelated to kernel development.

Granted. The major point is that it requires a development cycle before it is ready. Only if this is to be maintained as part of the kernel is it needed to be 2.7 work.

Um, what's the point of having linux abi exort header files that are NOT part of the kernel?

The theory here is that _some_ of the definitions in the kernel headers define interfaces with userspace. Structures passed to fcntl or ioctl, constants, etc. The kernel has to have copies of these definitions for its own use, just as much as userspace does. (It has to get the data from and put the data into these structures, doesn't it? How can it do this without a defiition of these structures? An interface has two sides, and the kernel side of that interface needs the abi definitions to provide the abi.)

The other 99% of the kernel headers should NOT get included in userspace programs. This is the reason that, way back, #ifdef KERNEL was put in there in the first place, with the ABI stuff being anything that was outside the #ifdef. This solution sucked eggs for fairly obvious reasons, but rather than separate out the ABI definitions into their own header files shared by kernel and user space, the advice from on high became "just cut and paste out the bits you need". This solution sucked different eggs. Any library that talks directly to the linux kernel needs to have access the kernel ABI, and manually extracting it from the kernel header files is a maintenance nightmare. Even if you abstract this away into a library, the LIBRARY still needs to do it. You've just moved the problem.

Some people here have argued variants of "tracking what the linux kernel exports to userspace is somebody else's problem". I.E. the linux kernel can't be bothered to keep track of what it exports to userspace. That just gives me a warm fuzzy feeling all over, that does...

Quoted 4 lines

My point is that we need to cleanly handle the fact that glibc defines it's own abi that is not equivalent to the kernel abi. A linux specific namespace does that. After libc is done with the definitions users will still use MS_RDONLY.

Does anything other than glibc have this problem? (Does uclibc have this problem? cdrecord?)

Rob

#12 lore raw
Quoted 7 lines · Rob Landley
Quoted 4 lines

My point is that we need to cleanly handle the fact that glibc defines it's own abi that is not equivalent to the kernel abi. A linux specific namespace does that. After libc is done with the definitions users will still use MS_RDONLY.

Does anything other than glibc have this problem? (Does uclibc have this problem? cdrecord?)

glibc presents the glibc ABI to its client applications, and uclibc presents the uclibc ABI to its clients. If they choose to process things a bit before communicating with their clients that is their business. But that is certainly not a problem for the kernel developer's to worry about.

The means by which the various C libs present their own ABI to their clients is also their private business. If the kernel developers can provide a clean ABI to user space that is not mingled with kernel internals, you can be sure the various C lib developers will be overjoyed to use that for kernel communication and will gladly address any needed ABI translation.

-Erik

--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw

[email protected] (Andries Brouwer) wrote on 02.10.03 in <[email protected]>:

Quoted 2 lines

Now you come with comment #2: write LINUX_MS_RDONLY instead of MS_RDONLY. You have not convinced me.

The argument is fairly simple.

The main idea is that we expect glibc to use these includes to talk to the kernel, and that we expect glibc to at least in part do that by including these files from the glibc includes.

So this means userspace is bound to see these declarations.

So this means namespace cleanliness issues come up.

Also, we know that glibc likes to have an ABI that's different from the kernel ABI.

So we can't use the POSIX names for these things, or we'd create serious problems for glibc actually using this stuff.

Now, what namespace to use?

I think the rules here are clear: it MUST be part of the namespace reserved for language implementation, which is /^_[_A-Z][a-zA-Z_0-9]*$/. Also, it SHOULD be something we're fairly certain nobody else will be using.

There's one more thing here. Sometimes things change. We should consider having some sort of standard way of indicating a version in the name, AND WE SHOULD USE IT FROM THE FIRST VERSION ON, so that there's never a need to change the definition of a symbol, and there's never a need to invent a name like new_new_new_foo.

Let me repeat and slightly rephrase that point:

Symbols in the ABI includes should *NEVER* change their definition. Use new symbols for new definitions. Glibc should be able to rely on knowing that, say, _Linux_20_stat_t will always describe the stat_t to use on Linux 2.0 and compatible kernels.

Remember, these things describe an ABI. To be useful, there has to be a 1:1 correspondence between names and ABI. It's glibc above and kernel below who actually do compatibility conversions, it's not the job of the ABI descriptions. (Except in the form of comments.)

MfG Kai

#15 lore raw
In reply to Eric W. Biederman
Quoted 2 lines · Eric W. Biederman

So all of the definitions exported
through linuxabi need to be in a linux centric namespace.

What we try to achieve is to use the same headerfiles for user, and kernel. Previously this has been done by including selected files direct from include/linux/*.
A few cases that I recall is DVB, scsi, and ipv6.
For all of these there were no need to create a specific linux namespace. If there is parts of the kernel that _really_ require a separate linux namespace then we need to find a solution for that part. But we should not try to uglify the interface becasue a limited part of the kernel interface have specific needs.

And since dvb, scsi and ipv6 could accept current namespace before, they should also be able to accept it today - no?

The concept introduced by inventing abi/ is to make it visible what part of the kernel interface is actually visible from user level. And also a good way for us to make sure no kernel specific types sneaks in.

Sam