2008-07-31 09:33:47

by Thomas Petazzoni

[permalink] [raw]
Subject: [patch 2/4] Configure out file locking features

This patch adds the CONFIG_FILE_LOCKING option which allows to remove
support for advisory locks. With this patch enabled, the flock()
system call, the F_GETLK, F_SETLK and F_SETLKW operations of fcntl()
and NFS support are disabled. These features are not necessarly needed
on embedded systems. It allows to save ~11 Kb of kernel code and data:

text data bss dec hex filename
1125436 118764 212992 1457192 163c28 vmlinux.old
1114299 118564 212992 1445855 160fdf vmlinux
-11137 -200 0 -11337 -2C49 +/-

This patch has originally been written by Matt Mackall
<[email protected]>, and is part of the Linux Tiny project.

Signed-off-by: Thomas Petazzoni <[email protected]>
Signed-off-by: Matt Mackall <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
fs/Kconfig | 2 +-
fs/Makefile | 3 ++-
fs/proc/proc_misc.c | 4 ++++
include/linux/fs.h | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
init/Kconfig | 8 ++++++++
kernel/sys_ni.c | 1 +
kernel/sysctl.c | 6 +++++-
7 files changed, 66 insertions(+), 10 deletions(-)

Index: linuxdev/fs/Kconfig
===================================================================
--- linuxdev.orig/fs/Kconfig
+++ linuxdev/fs/Kconfig
@@ -1559,7 +1559,7 @@

config NFS_FS
tristate "NFS client support"
- depends on INET
+ depends on INET && FILE_LOCKING
select LOCKD
select SUNRPC
select NFS_ACL_SUPPORT if NFS_V3_ACL
Index: linuxdev/fs/Makefile
===================================================================
--- linuxdev.orig/fs/Makefile
+++ linuxdev/fs/Makefile
@@ -7,7 +7,7 @@

obj-y := open.o read_write.o file_table.o super.o \
char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
- ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
+ ioctl.o readdir.o select.o fifo.o dcache.o inode.o \
attr.o bad_inode.o file.o filesystems.o namespace.o \
seq_file.o xattr.o libfs.o fs-writeback.o \
pnode.o drop_caches.o splice.o sync.o utimes.o \
@@ -28,6 +28,7 @@
obj-$(CONFIG_TIMERFD) += timerfd.o
obj-$(CONFIG_EVENTFD) += eventfd.o
obj-$(CONFIG_AIO) += aio.o
+obj-$(CONFIG_FILE_LOCKING) += locks.o
obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o

nfsd-$(CONFIG_NFSD) := nfsctl.o
Index: linuxdev/fs/proc/proc_misc.c
===================================================================
--- linuxdev.orig/fs/proc/proc_misc.c
+++ linuxdev/fs/proc/proc_misc.c
@@ -677,6 +677,7 @@
return proc_calc_metrics(page, start, off, count, eof, len);
}

+#ifdef CONFIG_FILE_LOCKING
static int locks_open(struct inode *inode, struct file *filp)
{
return seq_open(filp, &locks_seq_operations);
@@ -688,6 +689,7 @@
.llseek = seq_lseek,
.release = seq_release,
};
+#endif /* CONFIG_FILE_LOCKING */

static int execdomains_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data)
@@ -881,7 +883,9 @@
#ifdef CONFIG_PRINTK
proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
#endif
+#ifdef CONFIG_FILE_LOCKING
proc_create("locks", 0, NULL, &proc_locks_operations);
+#endif
proc_create("devices", 0, NULL, &proc_devinfo_operations);
proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
#ifdef CONFIG_BLOCK
Index: linuxdev/include/linux/fs.h
===================================================================
--- linuxdev.orig/include/linux/fs.h
+++ linuxdev/include/linux/fs.h
@@ -983,6 +983,13 @@

#include <linux/fcntl.h>

+extern void send_sigio(struct fown_struct *fown, int fd, int band);
+
+/* fs/sync.c */
+extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
+ loff_t endbyte, unsigned int flags);
+
+#ifdef CONFIG_FILE_LOCKING
extern int fcntl_getlk(struct file *, struct flock __user *);
extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
struct flock __user *);
@@ -993,14 +1000,9 @@
struct flock64 __user *);
#endif

-extern void send_sigio(struct fown_struct *fown, int fd, int band);
extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
extern int fcntl_getlease(struct file *filp);

-/* fs/sync.c */
-extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
- loff_t endbyte, unsigned int flags);
-
/* fs/locks.c */
extern void locks_init_lock(struct file_lock *);
extern void locks_copy_lock(struct file_lock *, struct file_lock *);
@@ -1023,6 +1025,33 @@
extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
extern struct seq_operations locks_seq_operations;
+#else /* !CONFIG_FILE_LOCKING */
+#define fcntl_getlk(a, b) (-EINVAL)
+#define fcntl_setlk(a, b, c, d) (-EACCES)
+#if BITS_PER_LONG == 32
+#define fcntl_getlk64(a, b) (-EINVAL)
+#define fcntl_setlk64(a, b, c, d) (-EACCES)
+#endif
+#define fcntl_setlease(a, b, c) (0)
+#define fcntl_getlease(a) (0)
+#define locks_init_lock(a)
+#define locks_copy_lock(a, b)
+#define locks_remove_posix(a, b)
+#define locks_remove_flock(a)
+#define posix_test_lock(a, b) (0)
+#define posix_lock_file(a, b) (-ENOLCK)
+#define posix_lock_file_wait(a, b) (-ENOLCK)
+#define posix_unblock_lock(a, b) (-ENOENT)
+#define vfs_test_lock(a, b) (0)
+#define vfs_lock_file(a, b, c, d) (-ENOLCK)
+#define vfs_cancel_lock(a, b) (0)
+#define flock_lock_file_wait(a, b) (-ENOLCK)
+#define __break_lease(a, b) (0)
+#define lease_get_mtime(a, b)
+#define lock_may_read(a, b, c) (1)
+#define lock_may_write(a, b, c) (1)
+#endif /* !CONFIG_FILE_LOCKING */
+

struct fasync_struct {
int magic;
@@ -1554,9 +1583,12 @@
/* /sys/fs */
extern struct kobject *fs_kobj;

+extern int rw_verify_area(int, struct file *, loff_t *, size_t);
+
#define FLOCK_VERIFY_READ 1
#define FLOCK_VERIFY_WRITE 2

+#ifdef CONFIG_FILE_LOCKING
extern int locks_mandatory_locked(struct inode *);
extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);

@@ -1587,8 +1619,6 @@
return 0;
}

-extern int rw_verify_area(int, struct file *, loff_t *, size_t);
-
static inline int locks_verify_truncate(struct inode *inode,
struct file *filp,
loff_t size)
@@ -1609,6 +1639,14 @@
return __break_lease(inode, mode);
return 0;
}
+#else /* !CONFIG_FILE_LOCKING */
+#define locks_mandatory_locked(a) (0)
+#define locks_mandatory_area(a, b, c, d, e) (0)
+#define mandatory_lock(a) (0)
+#define locks_verify_locked(a) (0)
+#define locks_verify_truncate(a, b, c) (0)
+#define break_lease(a, b) (0)
+#endif /* CONFIG_FILE_LOCKING */

/* fs/open.c */

Index: linuxdev/init/Kconfig
===================================================================
--- linuxdev.orig/init/Kconfig
+++ linuxdev/init/Kconfig
@@ -732,6 +732,14 @@
by some high performance threaded applications. Disabling
this option saves about 7k.

+config FILE_LOCKING
+ bool "Enable POSIX file locking API" if EMBEDDED
+ default y
+ help
+ This option enables standard file locking support, required
+ for filesystems like NFS and for the flock() system
+ call. Disabling this option saves about 11k.
+
config VM_EVENT_COUNTERS
default y
bool "Enable VM event counters for /proc/vmstat" if EMBEDDED
Index: linuxdev/kernel/sys_ni.c
===================================================================
--- linuxdev.orig/kernel/sys_ni.c
+++ linuxdev/kernel/sys_ni.c
@@ -130,6 +130,7 @@
cond_syscall(sys_io_submit);
cond_syscall(sys_io_cancel);
cond_syscall(sys_io_getevents);
+cond_syscall(sys_flock);

/* arch-specific weak syscall entries */
cond_syscall(sys_pciconfig_read);
Index: linuxdev/kernel/sysctl.c
===================================================================
--- linuxdev.orig/kernel/sysctl.c
+++ linuxdev/kernel/sysctl.c
@@ -97,7 +97,7 @@
static int neg_one = -1;
#endif

-#ifdef CONFIG_MMU
+#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
static int two = 2;
#endif

@@ -1260,6 +1260,7 @@
.extra1 = &minolduid,
.extra2 = &maxolduid,
},
+#ifdef CONFIG_FILE_LOCKING
{
.ctl_name = FS_LEASES,
.procname = "leases-enable",
@@ -1268,6 +1269,7 @@
.mode = 0644,
.proc_handler = &proc_dointvec,
},
+#endif
#ifdef CONFIG_DNOTIFY
{
.ctl_name = FS_DIR_NOTIFY,
@@ -1279,6 +1281,7 @@
},
#endif
#ifdef CONFIG_MMU
+#ifdef CONFIG_FILE_LOCKING
{
.ctl_name = FS_LEASE_TIME,
.procname = "lease-break-time",
@@ -1290,6 +1293,7 @@
.extra1 = &zero,
.extra2 = &two,
},
+#endif /* CONFIG_FILE_LOCKING */
#ifdef CONFIG_AIO
{
.procname = "aio-nr",

--
Thomas Petazzoni, Free Electrons
Kernel, drivers and embedded Linux development,
consulting, training and support.
http://free-electrons.com


2008-07-31 13:54:28

by Adrian Bunk

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Thu, Jul 31, 2008 at 11:27:05AM +0200, Thomas Petazzoni wrote:
> This patch adds the CONFIG_FILE_LOCKING option which allows to remove
> support for advisory locks. With this patch enabled, the flock()
> system call, the F_GETLK, F_SETLK and F_SETLKW operations of fcntl()
> and NFS support are disabled. These features are not necessarly needed
> on embedded systems. It allows to save ~11 Kb of kernel code and data:
>
> text data bss dec hex filename
> 1125436 118764 212992 1457192 163c28 vmlinux.old
> 1114299 118564 212992 1445855 160fdf vmlinux
> -11137 -200 0 -11337 -2C49 +/-
>
> This patch has originally been written by Matt Mackall
> <[email protected]>, and is part of the Linux Tiny project.
>...

As I've already said in the past I'm personally not a huge fan of these
patches, but if it brings advantages in real-life situations it's hard
to argue against it.

In which use cases can users safely disable this option, and on what
devices have you verified that CONFIG_FILE_LOCKING=n kernels actually
work in practice?

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2008-07-31 14:20:31

by Thomas Petazzoni

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

Le Thu, 31 Jul 2008 16:53:19 +0300,
Adrian Bunk <[email protected]> a écrit :

> As I've already said in the past I'm personally not a huge fan of
> these patches, but if it brings advantages in real-life situations
> it's hard to argue against it.

Yes, I've seen your points about that kind of patches on
linux-embedded, and I understand them. I agree that adding dozens and
dozens of configuration items for small features doesn't look like
something sustainable on the long run. However, the kernel keeps
growing and this isn't sustainable either on the long run for *some*
embedded users. So, what should we do ? (That's a real question)

Some numbers about a bootable x86 allnoconfig kernel with ELF, ext2 and
IDE support :

text data bss dec hex filename
1110389 119468 217088 1446945 161421 vmlinux.2.6.26
1134606 118840 212992 1466438 166046 vmlinux.2.6.27-rc1
24217 -628 -4096 19493 4C25 +/-

(The only configuration change between the two kernels is
CONFIG_FW_LOADER n->y, which pulls drivers/base/firmware_class.o, 3k).

> In which use cases can users safely disable this option, and on what
> devices have you verified that CONFIG_FILE_LOCKING=n kernels actually
> work in practice?

As long as they don't use NFS (realistic in many production
environments) and that the applications do not rely on advisory locking
(flock() and fnctl() F_GETLK and F_SETLK), file locking can be
disabled. In practice, I only tested a CONFIG_FILE_LOCKING=n kernel
with a basic Busybox under Qemu.

Sincerly,

Thomas
--
Thomas Petazzoni, Free Electrons
Kernel, drivers and embedded Linux development,
consulting, training and support.
http://free-electrons.com

2008-07-31 15:39:13

by Adrian Bunk

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Thu, Jul 31, 2008 at 04:20:07PM +0200, Thomas Petazzoni wrote:
> Le Thu, 31 Jul 2008 16:53:19 +0300,
> Adrian Bunk <[email protected]> a écrit :
>
> > As I've already said in the past I'm personally not a huge fan of
> > these patches, but if it brings advantages in real-life situations
> > it's hard to argue against it.
>
> Yes, I've seen your points about that kind of patches on
> linux-embedded, and I understand them. I agree that adding dozens and
> dozens of configuration items for small features doesn't look like
> something sustainable on the long run. However, the kernel keeps
> growing and this isn't sustainable either on the long run for *some*
> embedded users. So, what should we do ? (That's a real question)

I'm not against making the kernel smaller.

I'm just not a fan of adding config options for each few kB of code -
we have to maintain them and the more complex the configuration becomes
the more often it breaks.

> Some numbers about a bootable x86 allnoconfig kernel with ELF, ext2 and
> IDE support :
>
> text data bss dec hex filename
> 1110389 119468 217088 1446945 161421 vmlinux.2.6.26
> 1134606 118840 212992 1466438 166046 vmlinux.2.6.27-rc1
> 24217 -628 -4096 19493 4C25 +/-

What became bigger was most likely not related to the patches you sent.

Where and why did the kernel become bigger?

> (The only configuration change between the two kernels is
> CONFIG_FW_LOADER n->y, which pulls drivers/base/firmware_class.o, 3k).

Why did CONFIG_FW_LOADER get enabled?
Due to alnoconfig disabling CONFIG_EMBEDDED?

> > In which use cases can users safely disable this option, and on what
> > devices have you verified that CONFIG_FILE_LOCKING=n kernels actually
> > work in practice?
>
> As long as they don't use NFS (realistic in many production
> environments) and that the applications do not rely on advisory locking
> (flock() and fnctl() F_GETLK and F_SETLK), file locking can be
> disabled.

But what does that mean in practice?

A user will ask:
I'm using $applications with $libraries, can I safely disable this option?

And e.g. according to a quick grep through the sources uClibc's
updwtmp() seems to cease working without flock().

It costs us maintainance of the option and the #ifdef's and gives users
one way more to shoot themselves into the foot in nontrivial to detect
ways.

> In practice, I only tested a CONFIG_FILE_LOCKING=n kernel
> with a basic Busybox under Qemu.
>
> Sincerly,
>
> Thomas

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2008-07-31 16:26:36

by Thomas Petazzoni

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

Le Thu, 31 Jul 2008 18:37:57 +0300,
Adrian Bunk <[email protected]> a écrit :

> I'm just not a fan of adding config options for each few kB of code -
> we have to maintain them and the more complex the configuration
> becomes the more often it breaks.

I'm not a fan of these too, but are there other solutions ?

> What became bigger was most likely not related to the patches you
> sent.

No, it is not.

> Where and why did the kernel become bigger?

It's not up-to-date with 2.6.26 and 2.6.27-rc1, but Bloatwatch
<http://www.selenic.com/bloatwatch/>, by Matt Mackall, is here to
answer these questions. I haven't made the analysis for
2.6.26->2.6.27-rc1.

> Why did CONFIG_FW_LOADER get enabled?
> Due to alnoconfig disabling CONFIG_EMBEDDED?

I don't know. Haven't made the analysis for now.

> A user will ask:
> I'm using $applications with $libraries, can I safely disable this
> option?

Hard to tell in the general case.

> And e.g. according to a quick grep through the sources uClibc's
> updwtmp() seems to cease working without flock().

Correct. But on many embedded systems, we don't care about logging past
user logins. We might even not care about logins at all.

> It costs us maintainance of the option and the #ifdef's and gives
> users one way more to shoot themselves into the foot in nontrivial to
> detect ways.

That's correct, and as I said previously, I fully understand the
maintainance problem of all these new configuration options. I must
admit that I do not really have more objective technical arguments that
would help us deciding whether the code size reduction vs. code
maintainance choice should be made in one direction or the other.

Sincerly,

Thomas
--
Thomas Petazzoni, Free Electrons
Kernel, drivers and embedded Linux development,
consulting, training and support.
http://free-electrons.com

2008-07-31 16:50:31

by Adrian Bunk

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Thu, Jul 31, 2008 at 06:26:16PM +0200, Thomas Petazzoni wrote:
> Le Thu, 31 Jul 2008 18:37:57 +0300,
> Adrian Bunk <[email protected]> a écrit :
>
> > I'm just not a fan of adding config options for each few kB of code -
> > we have to maintain them and the more complex the configuration
> > becomes the more often it breaks.
>
> I'm not a fan of these too, but are there other solutions ?

There are many things that can be done to reduce the kernel size or try
to minimize the growth of the kernel.

E.g. working on --combine -fwhole-program (where David once had
preliminary patches for the per-module approach) might be better.

> > What became bigger was most likely not related to the patches you
> > sent.
>
> No, it is not.
>
> > Where and why did the kernel become bigger?
>
> It's not up-to-date with 2.6.26 and 2.6.27-rc1, but Bloatwatch
> <http://www.selenic.com/bloatwatch/>, by Matt Mackall, is here to
> answer these questions. I haven't made the analysis for
> 2.6.26->2.6.27-rc1.

It can only give some hints where to start searching.

But it tracks a defconfig, and e.g. the nearly doubled size between
2.6.18 and 2.6.19 is both expected and not a problem for embedded
systems.

The real work is to figure out in which areas that are relevant for
embedded systems the kernel became bigger.

> > Why did CONFIG_FW_LOADER get enabled?
> > Due to alnoconfig disabling CONFIG_EMBEDDED?
>
> I don't know. Haven't made the analysis for now.
>
> > A user will ask:
> > I'm using $applications with $libraries, can I safely disable this
> > option?
>
> Hard to tell in the general case.
>
> > And e.g. according to a quick grep through the sources uClibc's
> > updwtmp() seems to cease working without flock().
>
> Correct. But on many embedded systems, we don't care about logging past
> user logins. We might even not care about logins at all.

And for embedded systems with which applications is it 100% safe to
disable this option?

And don't answer "doesn't use flock()", I want a real-life example of a
device where you could guarantee a developer that disabling this option
in his product would be safe.

> > It costs us maintainance of the option and the #ifdef's and gives
> > users one way more to shoot themselves into the foot in nontrivial to
> > detect ways.
>
> That's correct, and as I said previously, I fully understand the
> maintainance problem of all these new configuration options. I must
> admit that I do not really have more objective technical arguments that
> would help us deciding whether the code size reduction vs. code
> maintainance choice should be made in one direction or the other.

My personal criteron for this patch is still how many real-life systems
can safely disable it.

> Sincerly,
>
> Thomas

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2008-07-31 16:58:26

by David Woodhouse

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Thu, 2008-07-31 at 19:49 +0300, Adrian Bunk wrote:
> On Thu, Jul 31, 2008 at 06:26:16PM +0200, Thomas Petazzoni wrote:
> > Le Thu, 31 Jul 2008 18:37:57 +0300,
> > Adrian Bunk <[email protected]> a écrit :
> >
> > > I'm just not a fan of adding config options for each few kB of code -
> > > we have to maintain them and the more complex the configuration
> > > becomes the more often it breaks.
> >
> > I'm not a fan of these too, but are there other solutions ?
>
> There are many things that can be done to reduce the kernel size or try
> to minimize the growth of the kernel.
>
> E.g. working on --combine -fwhole-program (where David once had
> preliminary patches for the per-module approach) might be better.

Yeah, I'm planning to dig that out again and play with it some time
soon. The Kbuild issues were too scary at the time, but I'm less
frightened of it these days...

Segher has also been looking at it, and reported quite a useful win when
he used it to combine arch/$ARCH/mm and mm/, and arch/$ARCH/kernel and
kernel/.

--
David Woodhouse Open Source Technology Centre
[email protected] Intel Corporation


2008-07-31 17:29:55

by Tim Bird

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

Adrian Bunk wrote:
> And for embedded systems with which applications is it 100% safe to
> disable this option?

Sony's digital cameras.

This option *is* disabled in the kernel for (most) Sony digital cameras.
Those digital cameras have the kernel, busybox, a custom C library,
and one proprietary application. The application does not use
flock() (or AIO, or ethtool or multi-cast)

These cameras were heavily tested, and are shipping now. I can't
make any guarantees for other developers, but those of us who
are careful about our application development would like the option
to eliminate completely unused features from the kernel. (And
the C library, but that's a different issue.)

> And don't answer "doesn't use flock()", I want a real-life example of a
> device where you could guarantee a developer that disabling this option
> in his product would be safe.

I'm not sure why a guarantee is required that other developers
use this option safely. Maybe this is a point of disconnect between
embedded folks and non-embedded folks. We're accustomed to making
tradeoff decisions that only affect our product, and which
we take full responsibility for testing.

If warnings or support avoidance for the general population using
such config options is the issue, I think that David Woodhouse's
suggestion that such things could taint the kernel is an interesting
idea. Maybe have we could have an "unsafe-config" taint flag?

I should add that I am sympathetic with the larger issue you raise
about nibbling at the bottom with patches that only address a
few KB of the problem, while the size continues to build (to an
even greater degree) with each release. My response is that I agree
with you on the nibbling bit, but probably just at a different
level of KB savings.

That is, I presume you'd be OK with something that saved 100K or
even 20K, but balk at bit at these patches, which save 10k or less.
My threshold is lower (probably down to about 5K, so these are
pretty close to the bubble), but even I wouldn't recommend
applying anything much below that. We've already started
considering to drop some linux-tiny patches that just don't save
enough to warrant continued maintenance.
-- Tim


=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================

2008-07-31 18:12:53

by Robert Schwebel

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Thu, Jul 31, 2008 at 10:32:20AM -0700, Tim Bird wrote:
> > And for embedded systems with which applications is it 100% safe to
> > disable this option?
>
> Sony's digital cameras.

We have also several very small automation & measurement devices in the
field which run a very dedicated more or less single application which
can be carefully audited.

In the OSADL safety working group, people are discussing about Linux for
safety critical applications. If we want to achieve such scenarios,
stripped-down systems are an absolute must.

Although increasing processor power even in embedded applications lead
to more and more standard-line kernels plus normal userspace components
(i.e. glibc instead of uclibc), there are still applications where the
final product consists only of the kernel plus the app, whereas during
development time, the system has a full-blown configuration.

rsc
--
Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
Pengutronix - Linux Solutions for Science and Industry
Handelsregister: Amtsgericht Hildesheim, HRA 2686
Hannoversche Str. 2, 31134 Hildesheim, Germany
Phone: +49-5121-206917-0 | Fax: +49-5121-206917-9

2008-07-31 19:17:59

by Adrian Bunk

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Thu, Jul 31, 2008 at 10:32:20AM -0700, Tim Bird wrote:
> Adrian Bunk wrote:
> > And for embedded systems with which applications is it 100% safe to
> > disable this option?
>
> Sony's digital cameras.
>
> This option *is* disabled in the kernel for (most) Sony digital cameras.
> Those digital cameras have the kernel, busybox, a custom C library,
> and one proprietary application. The application does not use
> flock() (or AIO, or ethtool or multi-cast)
>
> These cameras were heavily tested, and are shipping now. I can't
> make any guarantees for other developers, but those of us who
> are careful about our application development would like the option
> to eliminate completely unused features from the kernel. (And
> the C library, but that's a different issue.)
>
> > And don't answer "doesn't use flock()", I want a real-life example of a
> > device where you could guarantee a developer that disabling this option
> > in his product would be safe.
>
> I'm not sure why a guarantee is required that other developers
> use this option safely. Maybe this is a point of disconnect between
> embedded folks and non-embedded folks. We're accustomed to making
> tradeoff decisions that only affect our product, and which
> we take full responsibility for testing.

Thanks. That's quite different from Thomas' "In practice, I only tested
a CONFIG_FILE_LOCKING=n kernel with a basic Busybox under Qemu." and
addresses my concerns.

In case I didn't express myself clearly:
I was not interested in guarantees for random developers but in seeing
some reasonable use case for a real device.

> If warnings or support avoidance for the general population using
> such config options is the issue, I think that David Woodhouse's
> suggestion that such things could taint the kernel is an interesting
> idea. Maybe have we could have an "unsafe-config" taint flag?

A CONFIG_EMBEDDED=y flag?

> I should add that I am sympathetic with the larger issue you raise
> about nibbling at the bottom with patches that only address a
> few KB of the problem, while the size continues to build (to an
> even greater degree) with each release. My response is that I agree
> with you on the nibbling bit, but probably just at a different
> level of KB savings.
>
> That is, I presume you'd be OK with something that saved 100K or
> even 20K, but balk at bit at these patches, which save 10k or less.
> My threshold is lower (probably down to about 5K, so these are
> pretty close to the bubble), but even I wouldn't recommend
> applying anything much below that. We've already started
> considering to drop some linux-tiny patches that just don't save
> enough to warrant continued maintenance.

It's not only about limits, I also have a general dislike for the
"add more config options" approach.

I get your point why it brings advantages in some cases, but if you are
looking for a cheerleader it won't be me. ;-)

> -- Tim

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2008-07-31 19:32:55

by Adrian Bunk

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Thu, Jul 31, 2008 at 08:12:14PM +0200, Robert Schwebel wrote:
> On Thu, Jul 31, 2008 at 10:32:20AM -0700, Tim Bird wrote:
> > > And for embedded systems with which applications is it 100% safe to
> > > disable this option?
> >
> > Sony's digital cameras.
>
> We have also several very small automation & measurement devices in the
> field which run a very dedicated more or less single application which
> can be carefully audited.
>
> In the OSADL safety working group, people are discussing about Linux for
> safety critical applications. If we want to achieve such scenarios,
> stripped-down systems are an absolute must.
>...

My first reaction is that as soon as you enable CONFIG_EMBEDDED you can
easily enter codepaths noone else has used for a while and that got
unnoticed broken.

> rsc

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2008-07-31 20:35:24

by Tim Bird

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

Adrian Bunk wrote:
> On Thu, Jul 31, 2008 at 10:32:20AM -0700, Tim Bird wrote:
>> If warnings or support avoidance for the general population using
>> such config options is the issue, I think that David Woodhouse's
>> suggestion that such things could taint the kernel is an interesting
>> idea. Maybe have we could have an "unsafe-config" taint flag?
>
> A CONFIG_EMBEDDED=y flag?

If this is sufficient, it works for me!

> It's not only about limits, I also have a general dislike for the
> "add more config options" approach.
>
> I get your point why it brings advantages in some cases, but if you are
> looking for a cheerleader it won't be me. ;-)

Understood. I promise not to send you any pom-poms. ;-)
-- Tim


=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================

2008-08-01 07:28:40

by Robert Schwebel

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Thu, Jul 31, 2008 at 10:31:26PM +0300, Adrian Bunk wrote:
> > In the OSADL safety working group, people are discussing about Linux
> > for safety critical applications. If we want to achieve such
> > scenarios, stripped-down systems are an absolute must.
> >...
>
> My first reaction is that as soon as you enable CONFIG_EMBEDDED you
> can easily enter codepaths noone else has used for a while and that
> got unnoticed broken.

That may be no problem; if we ever come to a safety kernel, it will have
to be audited and carefully tested anyway.

rsc
--
Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
Pengutronix - Linux Solutions for Science and Industry
Handelsregister: Amtsgericht Hildesheim, HRA 2686
Hannoversche Str. 2, 31134 Hildesheim, Germany
Phone: +49-5121-206917-0 | Fax: +49-5121-206917-9

2008-08-02 16:39:15

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Thu, Jul 31, 2008 at 11:27:05AM +0200, Thomas Petazzoni wrote:
> This patch adds the CONFIG_FILE_LOCKING option which allows to remove
> support for advisory locks. With this patch enabled, the flock()
> system call, the F_GETLK, F_SETLK and F_SETLKW operations of fcntl()
> and NFS support are disabled. These features are not necessarly needed
> on embedded systems. It allows to save ~11 Kb of kernel code and data:

Out of curiosity, why does the nfs client need disabling, but not nfsd,
gfs2, fuse, etc.?

--b.

>
> text data bss dec hex filename
> 1125436 118764 212992 1457192 163c28 vmlinux.old
> 1114299 118564 212992 1445855 160fdf vmlinux
> -11137 -200 0 -11337 -2C49 +/-
>
> This patch has originally been written by Matt Mackall
> <[email protected]>, and is part of the Linux Tiny project.
>
> Signed-off-by: Thomas Petazzoni <[email protected]>
> Signed-off-by: Matt Mackall <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
>
> ---
> fs/Kconfig | 2 +-
> fs/Makefile | 3 ++-
> fs/proc/proc_misc.c | 4 ++++
> include/linux/fs.h | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
> init/Kconfig | 8 ++++++++
> kernel/sys_ni.c | 1 +
> kernel/sysctl.c | 6 +++++-
> 7 files changed, 66 insertions(+), 10 deletions(-)
>
> Index: linuxdev/fs/Kconfig
> ===================================================================
> --- linuxdev.orig/fs/Kconfig
> +++ linuxdev/fs/Kconfig
> @@ -1559,7 +1559,7 @@
>
> config NFS_FS
> tristate "NFS client support"
> - depends on INET
> + depends on INET && FILE_LOCKING
> select LOCKD
> select SUNRPC
> select NFS_ACL_SUPPORT if NFS_V3_ACL
> Index: linuxdev/fs/Makefile
> ===================================================================
> --- linuxdev.orig/fs/Makefile
> +++ linuxdev/fs/Makefile
> @@ -7,7 +7,7 @@
>
> obj-y := open.o read_write.o file_table.o super.o \
> char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
> - ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
> + ioctl.o readdir.o select.o fifo.o dcache.o inode.o \
> attr.o bad_inode.o file.o filesystems.o namespace.o \
> seq_file.o xattr.o libfs.o fs-writeback.o \
> pnode.o drop_caches.o splice.o sync.o utimes.o \
> @@ -28,6 +28,7 @@
> obj-$(CONFIG_TIMERFD) += timerfd.o
> obj-$(CONFIG_EVENTFD) += eventfd.o
> obj-$(CONFIG_AIO) += aio.o
> +obj-$(CONFIG_FILE_LOCKING) += locks.o
> obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o
>
> nfsd-$(CONFIG_NFSD) := nfsctl.o
> Index: linuxdev/fs/proc/proc_misc.c
> ===================================================================
> --- linuxdev.orig/fs/proc/proc_misc.c
> +++ linuxdev/fs/proc/proc_misc.c
> @@ -677,6 +677,7 @@
> return proc_calc_metrics(page, start, off, count, eof, len);
> }
>
> +#ifdef CONFIG_FILE_LOCKING
> static int locks_open(struct inode *inode, struct file *filp)
> {
> return seq_open(filp, &locks_seq_operations);
> @@ -688,6 +689,7 @@
> .llseek = seq_lseek,
> .release = seq_release,
> };
> +#endif /* CONFIG_FILE_LOCKING */
>
> static int execdomains_read_proc(char *page, char **start, off_t off,
> int count, int *eof, void *data)
> @@ -881,7 +883,9 @@
> #ifdef CONFIG_PRINTK
> proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
> #endif
> +#ifdef CONFIG_FILE_LOCKING
> proc_create("locks", 0, NULL, &proc_locks_operations);
> +#endif
> proc_create("devices", 0, NULL, &proc_devinfo_operations);
> proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
> #ifdef CONFIG_BLOCK
> Index: linuxdev/include/linux/fs.h
> ===================================================================
> --- linuxdev.orig/include/linux/fs.h
> +++ linuxdev/include/linux/fs.h
> @@ -983,6 +983,13 @@
>
> #include <linux/fcntl.h>
>
> +extern void send_sigio(struct fown_struct *fown, int fd, int band);
> +
> +/* fs/sync.c */
> +extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
> + loff_t endbyte, unsigned int flags);
> +
> +#ifdef CONFIG_FILE_LOCKING
> extern int fcntl_getlk(struct file *, struct flock __user *);
> extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
> struct flock __user *);
> @@ -993,14 +1000,9 @@
> struct flock64 __user *);
> #endif
>
> -extern void send_sigio(struct fown_struct *fown, int fd, int band);
> extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
> extern int fcntl_getlease(struct file *filp);
>
> -/* fs/sync.c */
> -extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
> - loff_t endbyte, unsigned int flags);
> -
> /* fs/locks.c */
> extern void locks_init_lock(struct file_lock *);
> extern void locks_copy_lock(struct file_lock *, struct file_lock *);
> @@ -1023,6 +1025,33 @@
> extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
> extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
> extern struct seq_operations locks_seq_operations;
> +#else /* !CONFIG_FILE_LOCKING */
> +#define fcntl_getlk(a, b) (-EINVAL)
> +#define fcntl_setlk(a, b, c, d) (-EACCES)
> +#if BITS_PER_LONG == 32
> +#define fcntl_getlk64(a, b) (-EINVAL)
> +#define fcntl_setlk64(a, b, c, d) (-EACCES)
> +#endif
> +#define fcntl_setlease(a, b, c) (0)
> +#define fcntl_getlease(a) (0)
> +#define locks_init_lock(a)
> +#define locks_copy_lock(a, b)
> +#define locks_remove_posix(a, b)
> +#define locks_remove_flock(a)
> +#define posix_test_lock(a, b) (0)
> +#define posix_lock_file(a, b) (-ENOLCK)
> +#define posix_lock_file_wait(a, b) (-ENOLCK)
> +#define posix_unblock_lock(a, b) (-ENOENT)
> +#define vfs_test_lock(a, b) (0)
> +#define vfs_lock_file(a, b, c, d) (-ENOLCK)
> +#define vfs_cancel_lock(a, b) (0)
> +#define flock_lock_file_wait(a, b) (-ENOLCK)
> +#define __break_lease(a, b) (0)
> +#define lease_get_mtime(a, b)
> +#define lock_may_read(a, b, c) (1)
> +#define lock_may_write(a, b, c) (1)
> +#endif /* !CONFIG_FILE_LOCKING */
> +
>
> struct fasync_struct {
> int magic;
> @@ -1554,9 +1583,12 @@
> /* /sys/fs */
> extern struct kobject *fs_kobj;
>
> +extern int rw_verify_area(int, struct file *, loff_t *, size_t);
> +
> #define FLOCK_VERIFY_READ 1
> #define FLOCK_VERIFY_WRITE 2
>
> +#ifdef CONFIG_FILE_LOCKING
> extern int locks_mandatory_locked(struct inode *);
> extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
>
> @@ -1587,8 +1619,6 @@
> return 0;
> }
>
> -extern int rw_verify_area(int, struct file *, loff_t *, size_t);
> -
> static inline int locks_verify_truncate(struct inode *inode,
> struct file *filp,
> loff_t size)
> @@ -1609,6 +1639,14 @@
> return __break_lease(inode, mode);
> return 0;
> }
> +#else /* !CONFIG_FILE_LOCKING */
> +#define locks_mandatory_locked(a) (0)
> +#define locks_mandatory_area(a, b, c, d, e) (0)
> +#define mandatory_lock(a) (0)
> +#define locks_verify_locked(a) (0)
> +#define locks_verify_truncate(a, b, c) (0)
> +#define break_lease(a, b) (0)
> +#endif /* CONFIG_FILE_LOCKING */
>
> /* fs/open.c */
>
> Index: linuxdev/init/Kconfig
> ===================================================================
> --- linuxdev.orig/init/Kconfig
> +++ linuxdev/init/Kconfig
> @@ -732,6 +732,14 @@
> by some high performance threaded applications. Disabling
> this option saves about 7k.
>
> +config FILE_LOCKING
> + bool "Enable POSIX file locking API" if EMBEDDED
> + default y
> + help
> + This option enables standard file locking support, required
> + for filesystems like NFS and for the flock() system
> + call. Disabling this option saves about 11k.
> +
> config VM_EVENT_COUNTERS
> default y
> bool "Enable VM event counters for /proc/vmstat" if EMBEDDED
> Index: linuxdev/kernel/sys_ni.c
> ===================================================================
> --- linuxdev.orig/kernel/sys_ni.c
> +++ linuxdev/kernel/sys_ni.c
> @@ -130,6 +130,7 @@
> cond_syscall(sys_io_submit);
> cond_syscall(sys_io_cancel);
> cond_syscall(sys_io_getevents);
> +cond_syscall(sys_flock);
>
> /* arch-specific weak syscall entries */
> cond_syscall(sys_pciconfig_read);
> Index: linuxdev/kernel/sysctl.c
> ===================================================================
> --- linuxdev.orig/kernel/sysctl.c
> +++ linuxdev/kernel/sysctl.c
> @@ -97,7 +97,7 @@
> static int neg_one = -1;
> #endif
>
> -#ifdef CONFIG_MMU
> +#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
> static int two = 2;
> #endif
>
> @@ -1260,6 +1260,7 @@
> .extra1 = &minolduid,
> .extra2 = &maxolduid,
> },
> +#ifdef CONFIG_FILE_LOCKING
> {
> .ctl_name = FS_LEASES,
> .procname = "leases-enable",
> @@ -1268,6 +1269,7 @@
> .mode = 0644,
> .proc_handler = &proc_dointvec,
> },
> +#endif
> #ifdef CONFIG_DNOTIFY
> {
> .ctl_name = FS_DIR_NOTIFY,
> @@ -1279,6 +1281,7 @@
> },
> #endif
> #ifdef CONFIG_MMU
> +#ifdef CONFIG_FILE_LOCKING
> {
> .ctl_name = FS_LEASE_TIME,
> .procname = "lease-break-time",
> @@ -1290,6 +1293,7 @@
> .extra1 = &zero,
> .extra2 = &two,
> },
> +#endif /* CONFIG_FILE_LOCKING */
> #ifdef CONFIG_AIO
> {
> .procname = "aio-nr",
>
> --
> Thomas Petazzoni, Free Electrons
> Kernel, drivers and embedded Linux development,
> consulting, training and support.
> http://free-electrons.com
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2008-08-04 13:52:57

by Thomas Petazzoni

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

Le Sat, 2 Aug 2008 12:38:48 -0400,
"J. Bruce Fields" <[email protected]> a écrit :

> Out of curiosity, why does the nfs client need disabling, but not
> nfsd, gfs2, fuse, etc.?

Then also need disabling. Updated patch below.

Thanks!

Thomas

---

Configure out file locking features

This patch adds the CONFIG_FILE_LOCKING option which allows to remove
support for advisory locks. With this patch enabled, the flock()
system call, the F_GETLK, F_SETLK and F_SETLKW operations of fcntl()
and NFS support are disabled. These features are not necessarly needed
on embedded systems. It allows to save ~11 Kb of kernel code and data:

text data bss dec hex filename
1125436 118764 212992 1457192 163c28 vmlinux.old
1114299 118564 212992 1445855 160fdf vmlinux
-11137 -200 0 -11337 -2C49 +/-

This patch has originally been written by Matt Mackall
<[email protected]>, and is part of the Linux Tiny project.

Signed-off-by: Thomas Petazzoni <[email protected]>
Signed-off-by: Matt Mackall <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
fs/Kconfig | 15 ++++++++++++++-
fs/Makefile | 3 ++-
fs/dlm/Kconfig | 1 +
fs/gfs2/Kconfig | 1 +
fs/proc/proc_misc.c | 4 ++++
include/linux/fs.h | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
kernel/sys_ni.c | 1 +
kernel/sysctl.c | 6 +++++-
8 files changed, 73 insertions(+), 10 deletions(-)

Index: linuxdev/fs/Kconfig
===================================================================
--- linuxdev.orig/fs/Kconfig
+++ linuxdev/fs/Kconfig
@@ -427,12 +427,21 @@
bool
default n

+config FILE_LOCKING
+ bool "Enable POSIX file locking API" if EMBEDDED
+ default y
+ help
+ This option enables standard file locking support, required
+ for filesystems like NFS and for the flock() system
+ call. Disabling this option saves about 11k.
+
source "fs/xfs/Kconfig"
source "fs/gfs2/Kconfig"

config OCFS2_FS
tristate "OCFS2 file system support"
depends on NET && SYSFS
+ depends on FILE_LOCKING
select CONFIGFS_FS
select JBD
select CRC32
@@ -642,6 +651,7 @@

config FUSE_FS
tristate "Filesystem in Userspace support"
+ depends on FILE_LOCKING
help
With FUSE it is possible to implement a fully functional filesystem
in a userspace program.
@@ -1567,7 +1577,7 @@

config NFS_FS
tristate "NFS client support"
- depends on INET
+ depends on INET && FILE_LOCKING
select LOCKD
select SUNRPC
select NFS_ACL_SUPPORT if NFS_V3_ACL
@@ -1735,6 +1745,7 @@

config LOCKD
tristate
+ depends on FILE_LOCKING

config LOCKD_V4
bool
@@ -1870,6 +1881,7 @@
config CIFS
tristate "CIFS support (advanced network filesystem, SMBFS successor)"
depends on INET
+ depends on FILE_LOCKING
select NLS
help
This is the client VFS module for the Common Internet File System
@@ -2059,6 +2071,7 @@
config AFS_FS
tristate "Andrew File System support (AFS) (EXPERIMENTAL)"
depends on INET && EXPERIMENTAL
+ depends on FILE_LOCKING
select AF_RXRPC
help
If you say Y here, you will get an experimental Andrew File System
Index: linuxdev/fs/Makefile
===================================================================
--- linuxdev.orig/fs/Makefile
+++ linuxdev/fs/Makefile
@@ -7,7 +7,7 @@

obj-y := open.o read_write.o file_table.o super.o \
char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
- ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
+ ioctl.o readdir.o select.o fifo.o dcache.o inode.o \
attr.o bad_inode.o file.o filesystems.o namespace.o \
seq_file.o xattr.o libfs.o fs-writeback.o \
pnode.o drop_caches.o splice.o sync.o utimes.o \
@@ -28,6 +28,7 @@
obj-$(CONFIG_TIMERFD) += timerfd.o
obj-$(CONFIG_EVENTFD) += eventfd.o
obj-$(CONFIG_AIO) += aio.o
+obj-$(CONFIG_FILE_LOCKING) += locks.o
obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o

nfsd-$(CONFIG_NFSD) := nfsctl.o
Index: linuxdev/fs/dlm/Kconfig
===================================================================
--- linuxdev.orig/fs/dlm/Kconfig
+++ linuxdev/fs/dlm/Kconfig
@@ -2,6 +2,7 @@
tristate "Distributed Lock Manager (DLM)"
depends on EXPERIMENTAL && INET
depends on SYSFS && (IPV6 || IPV6=n)
+ depends on FILE_LOCKING
select CONFIGFS_FS
select IP_SCTP
help
Index: linuxdev/fs/gfs2/Kconfig
===================================================================
--- linuxdev.orig/fs/gfs2/Kconfig
+++ linuxdev/fs/gfs2/Kconfig
@@ -1,6 +1,7 @@
config GFS2_FS
tristate "GFS2 file system support"
depends on EXPERIMENTAL && (64BIT || (LSF && LBD))
+ depends on FILE_LOCKING
select FS_POSIX_ACL
select CRC32
help
Index: linuxdev/fs/proc/proc_misc.c
===================================================================
--- linuxdev.orig/fs/proc/proc_misc.c
+++ linuxdev/fs/proc/proc_misc.c
@@ -677,6 +677,7 @@
return proc_calc_metrics(page, start, off, count, eof, len);
}

+#ifdef CONFIG_FILE_LOCKING
static int locks_open(struct inode *inode, struct file *filp)
{
return seq_open(filp, &locks_seq_operations);
@@ -688,6 +689,7 @@
.llseek = seq_lseek,
.release = seq_release,
};
+#endif /* CONFIG_FILE_LOCKING */

static int execdomains_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data)
@@ -881,7 +883,9 @@
#ifdef CONFIG_PRINTK
proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
#endif
+#ifdef CONFIG_FILE_LOCKING
proc_create("locks", 0, NULL, &proc_locks_operations);
+#endif
proc_create("devices", 0, NULL, &proc_devinfo_operations);
proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
#ifdef CONFIG_BLOCK
Index: linuxdev/include/linux/fs.h
===================================================================
--- linuxdev.orig/include/linux/fs.h
+++ linuxdev/include/linux/fs.h
@@ -983,6 +983,13 @@

#include <linux/fcntl.h>

+extern void send_sigio(struct fown_struct *fown, int fd, int band);
+
+/* fs/sync.c */
+extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
+ loff_t endbyte, unsigned int flags);
+
+#ifdef CONFIG_FILE_LOCKING
extern int fcntl_getlk(struct file *, struct flock __user *);
extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
struct flock __user *);
@@ -993,14 +1000,9 @@
struct flock64 __user *);
#endif

-extern void send_sigio(struct fown_struct *fown, int fd, int band);
extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
extern int fcntl_getlease(struct file *filp);

-/* fs/sync.c */
-extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
- loff_t endbyte, unsigned int flags);
-
/* fs/locks.c */
extern void locks_init_lock(struct file_lock *);
extern void locks_copy_lock(struct file_lock *, struct file_lock *);
@@ -1023,6 +1025,33 @@
extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
extern struct seq_operations locks_seq_operations;
+#else /* !CONFIG_FILE_LOCKING */
+#define fcntl_getlk(a, b) (-EINVAL)
+#define fcntl_setlk(a, b, c, d) (-EACCES)
+#if BITS_PER_LONG == 32
+#define fcntl_getlk64(a, b) (-EINVAL)
+#define fcntl_setlk64(a, b, c, d) (-EACCES)
+#endif
+#define fcntl_setlease(a, b, c) (0)
+#define fcntl_getlease(a) (0)
+#define locks_init_lock(a)
+#define locks_copy_lock(a, b)
+#define locks_remove_posix(a, b)
+#define locks_remove_flock(a)
+#define posix_test_lock(a, b) (0)
+#define posix_lock_file(a, b) (-ENOLCK)
+#define posix_lock_file_wait(a, b) (-ENOLCK)
+#define posix_unblock_lock(a, b) (-ENOENT)
+#define vfs_test_lock(a, b) (0)
+#define vfs_lock_file(a, b, c, d) (-ENOLCK)
+#define vfs_cancel_lock(a, b) (0)
+#define flock_lock_file_wait(a, b) (-ENOLCK)
+#define __break_lease(a, b) (0)
+#define lease_get_mtime(a, b)
+#define lock_may_read(a, b, c) (1)
+#define lock_may_write(a, b, c) (1)
+#endif /* !CONFIG_FILE_LOCKING */
+

struct fasync_struct {
int magic;
@@ -1554,9 +1583,12 @@
/* /sys/fs */
extern struct kobject *fs_kobj;

+extern int rw_verify_area(int, struct file *, loff_t *, size_t);
+
#define FLOCK_VERIFY_READ 1
#define FLOCK_VERIFY_WRITE 2

+#ifdef CONFIG_FILE_LOCKING
extern int locks_mandatory_locked(struct inode *);
extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);

@@ -1587,8 +1619,6 @@
return 0;
}

-extern int rw_verify_area(int, struct file *, loff_t *, size_t);
-
static inline int locks_verify_truncate(struct inode *inode,
struct file *filp,
loff_t size)
@@ -1609,6 +1639,14 @@
return __break_lease(inode, mode);
return 0;
}
+#else /* !CONFIG_FILE_LOCKING */
+#define locks_mandatory_locked(a) (0)
+#define locks_mandatory_area(a, b, c, d, e) (0)
+#define mandatory_lock(a) (0)
+#define locks_verify_locked(a) (0)
+#define locks_verify_truncate(a, b, c) (0)
+#define break_lease(a, b) (0)
+#endif /* CONFIG_FILE_LOCKING */

/* fs/open.c */

Index: linuxdev/kernel/sys_ni.c
===================================================================
--- linuxdev.orig/kernel/sys_ni.c
+++ linuxdev/kernel/sys_ni.c
@@ -130,6 +130,7 @@
cond_syscall(sys_io_submit);
cond_syscall(sys_io_cancel);
cond_syscall(sys_io_getevents);
+cond_syscall(sys_flock);

/* arch-specific weak syscall entries */
cond_syscall(sys_pciconfig_read);
Index: linuxdev/kernel/sysctl.c
===================================================================
--- linuxdev.orig/kernel/sysctl.c
+++ linuxdev/kernel/sysctl.c
@@ -97,7 +97,7 @@
static int neg_one = -1;
#endif

-#ifdef CONFIG_MMU
+#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
static int two = 2;
#endif

@@ -1260,6 +1260,7 @@
.extra1 = &minolduid,
.extra2 = &maxolduid,
},
+#ifdef CONFIG_FILE_LOCKING
{
.ctl_name = FS_LEASES,
.procname = "leases-enable",
@@ -1268,6 +1269,7 @@
.mode = 0644,
.proc_handler = &proc_dointvec,
},
+#endif
#ifdef CONFIG_DNOTIFY
{
.ctl_name = FS_DIR_NOTIFY,
@@ -1279,6 +1281,7 @@
},
#endif
#ifdef CONFIG_MMU
+#ifdef CONFIG_FILE_LOCKING
{
.ctl_name = FS_LEASE_TIME,
.procname = "lease-break-time",
@@ -1290,6 +1293,7 @@
.extra1 = &zero,
.extra2 = &two,
},
+#endif /* CONFIG_FILE_LOCKING */
#ifdef CONFIG_AIO
{
.procname = "aio-nr",


--
Thomas Petazzoni, Free Electrons
Kernel, drivers and embedded Linux development,
consulting, training and support.
http://free-electrons.com

2008-08-04 18:20:52

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Mon, Aug 04, 2008 at 03:52:37PM +0200, Thomas Petazzoni wrote:
> Le Sat, 2 Aug 2008 12:38:48 -0400,
> "J. Bruce Fields" <[email protected]> a écrit :
>
> > Out of curiosity, why does the nfs client need disabling, but not
> > nfsd, gfs2, fuse, etc.?
>
> Then also need disabling.

OK by me, but again, why exactly? Since you're replacing the locking
calls they used by stubs that just return errors, in theory nfs, nfsd,
gfs2, and the rest should still compile and run, just without locking
support, right?

I don't have a strong opinion either way, just curious.

--b.

> Updated patch below.
>
> Thanks!
>
> Thomas
>
> ---
>
> Configure out file locking features
>
> This patch adds the CONFIG_FILE_LOCKING option which allows to remove
> support for advisory locks. With this patch enabled, the flock()
> system call, the F_GETLK, F_SETLK and F_SETLKW operations of fcntl()
> and NFS support are disabled. These features are not necessarly needed
> on embedded systems. It allows to save ~11 Kb of kernel code and data:
>
> text data bss dec hex filename
> 1125436 118764 212992 1457192 163c28 vmlinux.old
> 1114299 118564 212992 1445855 160fdf vmlinux
> -11137 -200 0 -11337 -2C49 +/-
>
> This patch has originally been written by Matt Mackall
> <[email protected]>, and is part of the Linux Tiny project.
>
> Signed-off-by: Thomas Petazzoni <[email protected]>
> Signed-off-by: Matt Mackall <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
>
> ---
> fs/Kconfig | 15 ++++++++++++++-
> fs/Makefile | 3 ++-
> fs/dlm/Kconfig | 1 +
> fs/gfs2/Kconfig | 1 +
> fs/proc/proc_misc.c | 4 ++++
> include/linux/fs.h | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
> kernel/sys_ni.c | 1 +
> kernel/sysctl.c | 6 +++++-
> 8 files changed, 73 insertions(+), 10 deletions(-)
>
> Index: linuxdev/fs/Kconfig
> ===================================================================
> --- linuxdev.orig/fs/Kconfig
> +++ linuxdev/fs/Kconfig
> @@ -427,12 +427,21 @@
> bool
> default n
>
> +config FILE_LOCKING
> + bool "Enable POSIX file locking API" if EMBEDDED
> + default y
> + help
> + This option enables standard file locking support, required
> + for filesystems like NFS and for the flock() system
> + call. Disabling this option saves about 11k.
> +
> source "fs/xfs/Kconfig"
> source "fs/gfs2/Kconfig"
>
> config OCFS2_FS
> tristate "OCFS2 file system support"
> depends on NET && SYSFS
> + depends on FILE_LOCKING
> select CONFIGFS_FS
> select JBD
> select CRC32
> @@ -642,6 +651,7 @@
>
> config FUSE_FS
> tristate "Filesystem in Userspace support"
> + depends on FILE_LOCKING
> help
> With FUSE it is possible to implement a fully functional filesystem
> in a userspace program.
> @@ -1567,7 +1577,7 @@
>
> config NFS_FS
> tristate "NFS client support"
> - depends on INET
> + depends on INET && FILE_LOCKING
> select LOCKD
> select SUNRPC
> select NFS_ACL_SUPPORT if NFS_V3_ACL
> @@ -1735,6 +1745,7 @@
>
> config LOCKD
> tristate
> + depends on FILE_LOCKING
>
> config LOCKD_V4
> bool
> @@ -1870,6 +1881,7 @@
> config CIFS
> tristate "CIFS support (advanced network filesystem, SMBFS successor)"
> depends on INET
> + depends on FILE_LOCKING
> select NLS
> help
> This is the client VFS module for the Common Internet File System
> @@ -2059,6 +2071,7 @@
> config AFS_FS
> tristate "Andrew File System support (AFS) (EXPERIMENTAL)"
> depends on INET && EXPERIMENTAL
> + depends on FILE_LOCKING
> select AF_RXRPC
> help
> If you say Y here, you will get an experimental Andrew File System
> Index: linuxdev/fs/Makefile
> ===================================================================
> --- linuxdev.orig/fs/Makefile
> +++ linuxdev/fs/Makefile
> @@ -7,7 +7,7 @@
>
> obj-y := open.o read_write.o file_table.o super.o \
> char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
> - ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
> + ioctl.o readdir.o select.o fifo.o dcache.o inode.o \
> attr.o bad_inode.o file.o filesystems.o namespace.o \
> seq_file.o xattr.o libfs.o fs-writeback.o \
> pnode.o drop_caches.o splice.o sync.o utimes.o \
> @@ -28,6 +28,7 @@
> obj-$(CONFIG_TIMERFD) += timerfd.o
> obj-$(CONFIG_EVENTFD) += eventfd.o
> obj-$(CONFIG_AIO) += aio.o
> +obj-$(CONFIG_FILE_LOCKING) += locks.o
> obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o
>
> nfsd-$(CONFIG_NFSD) := nfsctl.o
> Index: linuxdev/fs/dlm/Kconfig
> ===================================================================
> --- linuxdev.orig/fs/dlm/Kconfig
> +++ linuxdev/fs/dlm/Kconfig
> @@ -2,6 +2,7 @@
> tristate "Distributed Lock Manager (DLM)"
> depends on EXPERIMENTAL && INET
> depends on SYSFS && (IPV6 || IPV6=n)
> + depends on FILE_LOCKING
> select CONFIGFS_FS
> select IP_SCTP
> help
> Index: linuxdev/fs/gfs2/Kconfig
> ===================================================================
> --- linuxdev.orig/fs/gfs2/Kconfig
> +++ linuxdev/fs/gfs2/Kconfig
> @@ -1,6 +1,7 @@
> config GFS2_FS
> tristate "GFS2 file system support"
> depends on EXPERIMENTAL && (64BIT || (LSF && LBD))
> + depends on FILE_LOCKING
> select FS_POSIX_ACL
> select CRC32
> help
> Index: linuxdev/fs/proc/proc_misc.c
> ===================================================================
> --- linuxdev.orig/fs/proc/proc_misc.c
> +++ linuxdev/fs/proc/proc_misc.c
> @@ -677,6 +677,7 @@
> return proc_calc_metrics(page, start, off, count, eof, len);
> }
>
> +#ifdef CONFIG_FILE_LOCKING
> static int locks_open(struct inode *inode, struct file *filp)
> {
> return seq_open(filp, &locks_seq_operations);
> @@ -688,6 +689,7 @@
> .llseek = seq_lseek,
> .release = seq_release,
> };
> +#endif /* CONFIG_FILE_LOCKING */
>
> static int execdomains_read_proc(char *page, char **start, off_t off,
> int count, int *eof, void *data)
> @@ -881,7 +883,9 @@
> #ifdef CONFIG_PRINTK
> proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
> #endif
> +#ifdef CONFIG_FILE_LOCKING
> proc_create("locks", 0, NULL, &proc_locks_operations);
> +#endif
> proc_create("devices", 0, NULL, &proc_devinfo_operations);
> proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
> #ifdef CONFIG_BLOCK
> Index: linuxdev/include/linux/fs.h
> ===================================================================
> --- linuxdev.orig/include/linux/fs.h
> +++ linuxdev/include/linux/fs.h
> @@ -983,6 +983,13 @@
>
> #include <linux/fcntl.h>
>
> +extern void send_sigio(struct fown_struct *fown, int fd, int band);
> +
> +/* fs/sync.c */
> +extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
> + loff_t endbyte, unsigned int flags);
> +
> +#ifdef CONFIG_FILE_LOCKING
> extern int fcntl_getlk(struct file *, struct flock __user *);
> extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
> struct flock __user *);
> @@ -993,14 +1000,9 @@
> struct flock64 __user *);
> #endif
>
> -extern void send_sigio(struct fown_struct *fown, int fd, int band);
> extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
> extern int fcntl_getlease(struct file *filp);
>
> -/* fs/sync.c */
> -extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
> - loff_t endbyte, unsigned int flags);
> -
> /* fs/locks.c */
> extern void locks_init_lock(struct file_lock *);
> extern void locks_copy_lock(struct file_lock *, struct file_lock *);
> @@ -1023,6 +1025,33 @@
> extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
> extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
> extern struct seq_operations locks_seq_operations;
> +#else /* !CONFIG_FILE_LOCKING */
> +#define fcntl_getlk(a, b) (-EINVAL)
> +#define fcntl_setlk(a, b, c, d) (-EACCES)
> +#if BITS_PER_LONG == 32
> +#define fcntl_getlk64(a, b) (-EINVAL)
> +#define fcntl_setlk64(a, b, c, d) (-EACCES)
> +#endif
> +#define fcntl_setlease(a, b, c) (0)
> +#define fcntl_getlease(a) (0)
> +#define locks_init_lock(a)
> +#define locks_copy_lock(a, b)
> +#define locks_remove_posix(a, b)
> +#define locks_remove_flock(a)
> +#define posix_test_lock(a, b) (0)
> +#define posix_lock_file(a, b) (-ENOLCK)
> +#define posix_lock_file_wait(a, b) (-ENOLCK)
> +#define posix_unblock_lock(a, b) (-ENOENT)
> +#define vfs_test_lock(a, b) (0)
> +#define vfs_lock_file(a, b, c, d) (-ENOLCK)
> +#define vfs_cancel_lock(a, b) (0)
> +#define flock_lock_file_wait(a, b) (-ENOLCK)
> +#define __break_lease(a, b) (0)
> +#define lease_get_mtime(a, b)
> +#define lock_may_read(a, b, c) (1)
> +#define lock_may_write(a, b, c) (1)
> +#endif /* !CONFIG_FILE_LOCKING */
> +
>
> struct fasync_struct {
> int magic;
> @@ -1554,9 +1583,12 @@
> /* /sys/fs */
> extern struct kobject *fs_kobj;
>
> +extern int rw_verify_area(int, struct file *, loff_t *, size_t);
> +
> #define FLOCK_VERIFY_READ 1
> #define FLOCK_VERIFY_WRITE 2
>
> +#ifdef CONFIG_FILE_LOCKING
> extern int locks_mandatory_locked(struct inode *);
> extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
>
> @@ -1587,8 +1619,6 @@
> return 0;
> }
>
> -extern int rw_verify_area(int, struct file *, loff_t *, size_t);
> -
> static inline int locks_verify_truncate(struct inode *inode,
> struct file *filp,
> loff_t size)
> @@ -1609,6 +1639,14 @@
> return __break_lease(inode, mode);
> return 0;
> }
> +#else /* !CONFIG_FILE_LOCKING */
> +#define locks_mandatory_locked(a) (0)
> +#define locks_mandatory_area(a, b, c, d, e) (0)
> +#define mandatory_lock(a) (0)
> +#define locks_verify_locked(a) (0)
> +#define locks_verify_truncate(a, b, c) (0)
> +#define break_lease(a, b) (0)
> +#endif /* CONFIG_FILE_LOCKING */
>
> /* fs/open.c */
>
> Index: linuxdev/kernel/sys_ni.c
> ===================================================================
> --- linuxdev.orig/kernel/sys_ni.c
> +++ linuxdev/kernel/sys_ni.c
> @@ -130,6 +130,7 @@
> cond_syscall(sys_io_submit);
> cond_syscall(sys_io_cancel);
> cond_syscall(sys_io_getevents);
> +cond_syscall(sys_flock);
>
> /* arch-specific weak syscall entries */
> cond_syscall(sys_pciconfig_read);
> Index: linuxdev/kernel/sysctl.c
> ===================================================================
> --- linuxdev.orig/kernel/sysctl.c
> +++ linuxdev/kernel/sysctl.c
> @@ -97,7 +97,7 @@
> static int neg_one = -1;
> #endif
>
> -#ifdef CONFIG_MMU
> +#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
> static int two = 2;
> #endif
>
> @@ -1260,6 +1260,7 @@
> .extra1 = &minolduid,
> .extra2 = &maxolduid,
> },
> +#ifdef CONFIG_FILE_LOCKING
> {
> .ctl_name = FS_LEASES,
> .procname = "leases-enable",
> @@ -1268,6 +1269,7 @@
> .mode = 0644,
> .proc_handler = &proc_dointvec,
> },
> +#endif
> #ifdef CONFIG_DNOTIFY
> {
> .ctl_name = FS_DIR_NOTIFY,
> @@ -1279,6 +1281,7 @@
> },
> #endif
> #ifdef CONFIG_MMU
> +#ifdef CONFIG_FILE_LOCKING
> {
> .ctl_name = FS_LEASE_TIME,
> .procname = "lease-break-time",
> @@ -1290,6 +1293,7 @@
> .extra1 = &zero,
> .extra2 = &two,
> },
> +#endif /* CONFIG_FILE_LOCKING */
> #ifdef CONFIG_AIO
> {
> .procname = "aio-nr",
>
>
> --
> Thomas Petazzoni, Free Electrons
> Kernel, drivers and embedded Linux development,
> consulting, training and support.
> http://free-electrons.com

2008-08-04 18:22:34

by Tim Bird

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

J. Bruce Fields wrote:
> On Mon, Aug 04, 2008 at 03:52:37PM +0200, Thomas Petazzoni wrote:
>> Le Sat, 2 Aug 2008 12:38:48 -0400,
>> "J. Bruce Fields" <[email protected]> a écrit :
>>
>>> Out of curiosity, why does the nfs client need disabling, but not
>>> nfsd, gfs2, fuse, etc.?
>> Then also need disabling.
>
> OK by me, but again, why exactly? Since you're replacing the locking
> calls they used by stubs that just return errors, in theory nfs, nfsd,
> gfs2, and the rest should still compile and run, just without locking
> support, right?

I think so, but haven't tested this myself.

However, I would still be inclined to NOT add the extra config
dependencies. Just my 2 cents.
-- Tim

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================

2008-08-04 18:26:05

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Mon, Aug 04, 2008 at 11:24:51AM -0700, Tim Bird wrote:
> J. Bruce Fields wrote:
> > On Mon, Aug 04, 2008 at 03:52:37PM +0200, Thomas Petazzoni wrote:
> >> Le Sat, 2 Aug 2008 12:38:48 -0400,
> >> "J. Bruce Fields" <[email protected]> a écrit :
> >>
> >>> Out of curiosity, why does the nfs client need disabling, but not
> >>> nfsd, gfs2, fuse, etc.?
> >> Then also need disabling.
> >
> > OK by me, but again, why exactly? Since you're replacing the locking
> > calls they used by stubs that just return errors, in theory nfs, nfsd,
> > gfs2, and the rest should still compile and run, just without locking
> > support, right?
>
> I think so, but haven't tested this myself.
>
> However, I would still be inclined to NOT add the extra config
> dependencies. Just my 2 cents.

OK. My fear was that there was some good reason that the nfs dependency
was added in the first place, and that it's since been lost....

--b.

2008-08-04 18:56:25

by Matt Mackall

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features


On Mon, 2008-08-04 at 14:25 -0400, J. Bruce Fields wrote:
> On Mon, Aug 04, 2008 at 11:24:51AM -0700, Tim Bird wrote:
> > J. Bruce Fields wrote:
> > > On Mon, Aug 04, 2008 at 03:52:37PM +0200, Thomas Petazzoni wrote:
> > >> Le Sat, 2 Aug 2008 12:38:48 -0400,
> > >> "J. Bruce Fields" <[email protected]> a écrit :
> > >>
> > >>> Out of curiosity, why does the nfs client need disabling, but not
> > >>> nfsd, gfs2, fuse, etc.?
> > >> Then also need disabling.
> > >
> > > OK by me, but again, why exactly? Since you're replacing the locking
> > > calls they used by stubs that just return errors, in theory nfs, nfsd,
> > > gfs2, and the rest should still compile and run, just without locking
> > > support, right?
> >
> > I think so, but haven't tested this myself.
> >
> > However, I would still be inclined to NOT add the extra config
> > dependencies. Just my 2 cents.
>
> OK. My fear was that there was some good reason that the nfs dependency
> was added in the first place, and that it's since been lost....

I vaguely remember there was some compile issue here, but that would
have been back in the 2.6.10 era.

--
Mathematics is the supreme nostalgia of our time.

2008-08-04 19:43:16

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Mon, Aug 04, 2008 at 01:54:01PM -0500, Matt Mackall wrote:
>
> On Mon, 2008-08-04 at 14:25 -0400, J. Bruce Fields wrote:
> > On Mon, Aug 04, 2008 at 11:24:51AM -0700, Tim Bird wrote:
> > > J. Bruce Fields wrote:
> > > > On Mon, Aug 04, 2008 at 03:52:37PM +0200, Thomas Petazzoni wrote:
> > > >> Le Sat, 2 Aug 2008 12:38:48 -0400,
> > > >> "J. Bruce Fields" <[email protected]> a écrit :
> > > >>
> > > >>> Out of curiosity, why does the nfs client need disabling, but not
> > > >>> nfsd, gfs2, fuse, etc.?
> > > >> Then also need disabling.
> > > >
> > > > OK by me, but again, why exactly? Since you're replacing the locking
> > > > calls they used by stubs that just return errors, in theory nfs, nfsd,
> > > > gfs2, and the rest should still compile and run, just without locking
> > > > support, right?
> > >
> > > I think so, but haven't tested this myself.
> > >
> > > However, I would still be inclined to NOT add the extra config
> > > dependencies. Just my 2 cents.
> >
> > OK. My fear was that there was some good reason that the nfs dependency
> > was added in the first place, and that it's since been lost....
>
> I vaguely remember there was some compile issue here, but that would
> have been back in the 2.6.10 era.

Sounds plausible. I've got no objection to the patch either way, but if
we could at least just add a comment documenting the issue (if it
exists), that might be helpful.

--b.

2008-08-04 22:30:01

by Tim Bird

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

J. Bruce Fields wrote:
> On Mon, Aug 04, 2008 at 11:24:51AM -0700, Tim Bird wrote:
>> J. Bruce Fields wrote:
>>> On Mon, Aug 04, 2008 at 03:52:37PM +0200, Thomas Petazzoni wrote:
>>>> Le Sat, 2 Aug 2008 12:38:48 -0400,
>>>> "J. Bruce Fields" <[email protected]> a écrit :
>>>>
>>>>> Out of curiosity, why does the nfs client need disabling, but not
>>>>> nfsd, gfs2, fuse, etc.?
>>>> Then also need disabling.
>>> OK by me, but again, why exactly? Since you're replacing the locking
>>> calls they used by stubs that just return errors, in theory nfs, nfsd,
>>> gfs2, and the rest should still compile and run, just without locking
>>> support, right?
>> I think so, but haven't tested this myself.
>>
>> However, I would still be inclined to NOT add the extra config
>> dependencies. Just my 2 cents.
>
> OK. My fear was that there was some good reason that the nfs dependency
> was added in the first place, and that it's since been lost....

For general information, I just ran a test with the NFS dependency
on file locking turned off, and with the NFS auto-enable of
CONFIG_LOCKD removed.

It got me about a 16K savings, and I was able to successfully boot
a target with an NFS-mounted root file system. I haven't run extensive
tests, so I don't know what apps might break in this configuration,
but at least in this test, it ran well enough to boot the machine.

Below is the patch I used, which is only provided for information.
This should NOT be applied - it consists of quick hacks to test this
configuration only (that is, to test NFS with CONFIG_FILE_LOCKING=n).

BTW - this is on a 2.6.23 kernel, so even the regular FILE_LOCKING
bits may be different from the current no-file-locking patch.

---
fs/Kconfig | 3 +--
fs/nfs/client.c | 6 ++++++
fs/nfs/nfs3proc.c | 4 ++++
fs/nfs/proc.c | 4 ++++
fs/read_write.c | 2 ++
include/linux/fs.h | 13 +++++++------
6 files changed, 24 insertions(+), 8 deletions(-)

--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -1701,8 +1701,7 @@ menu "Network File Systems"

config NFS_FS
tristate "NFS file system support"
- depends on INET && FILE_LOCKING
- select LOCKD
+ depends on INET
select SUNRPC
select NFS_ACL_SUPPORT if NFS_V3_ACL
help
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -414,6 +414,7 @@ static void nfs_destroy_server(struct nf
lockd_down(); /* release rpc.lockd */
}

+#ifdef LOCKD
/*
* Version 2 or 3 lockd setup
*/
@@ -434,6 +435,7 @@ static int nfs_start_lockd(struct nfs_se
out:
return error;
}
+#endif

/*
* Initialise an NFSv3 ACL client connection
@@ -577,9 +579,11 @@ static int nfs_init_server(struct nfs_se
server->acdirmax = data->acdirmax * HZ;

/* Start lockd here, before we might error out */
+#ifdef LOCKD
error = nfs_start_lockd(server);
if (error < 0)
goto error;
+#endif

error = nfs_init_server_rpcclient(server, data->pseudoflavor);
if (error < 0)
@@ -1128,9 +1132,11 @@ struct nfs_server *nfs_clone_server(stru
(unsigned long long) server->fsid.major,
(unsigned long long) server->fsid.minor);

+#ifdef LOCKD
error = nfs_start_lockd(server);
if (error < 0)
goto out_free_server;
+#endif

spin_lock(&nfs_client_lock);
list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -795,7 +795,11 @@ static void nfs3_proc_commit_setup(struc
static int
nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
{
+#ifdef LOCKD
return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
+#else
+ return -ENOLCK;
+#endif
}

const struct nfs_rpc_ops nfs_v3_clientops = {
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -605,7 +605,11 @@ nfs_proc_commit_setup(struct nfs_write_d
static int
nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
{
+#ifdef LOCKD
return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
+#else
+ return -ENOLCK;
+#endif
}


--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -211,6 +211,7 @@ int rw_verify_area(int read_write, struc
if (unlikely((pos < 0) || (loff_t) (pos + count) < 0))
goto Einval;

+#ifdef FILE_LOCKING
if (unlikely(inode->i_flock && MANDATORY_LOCK(inode))) {
int retval = locks_mandatory_area(
read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE,
@@ -218,6 +219,7 @@ int rw_verify_area(int read_write, struc
if (retval < 0)
return retval;
}
+#endif
return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;

Einval:
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -863,10 +863,6 @@ extern int fcntl_setlk64(unsigned int, s
extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
extern int fcntl_getlease(struct file *filp);

-/* fs/sync.c */
-extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
- loff_t endbyte, unsigned int flags);
-
/* fs/locks.c */
extern void locks_init_lock(struct file_lock *);
extern void locks_copy_lock(struct file_lock *, struct file_lock *);
@@ -918,6 +914,10 @@ extern int lock_may_write(struct inode *
#define steal_locks(a)
#endif /* !CONFIG_FILE_LOCKING */

+/* fs/sync.c */
+extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
+ loff_t endbyte, unsigned int flags);
+
struct fasync_struct {
int magic;
int fa_fd;
@@ -1424,8 +1424,6 @@ static inline int locks_verify_locked(st
return 0;
}

-extern int rw_verify_area(int, struct file *, loff_t *, size_t);
-
static inline int locks_verify_truncate(struct inode *inode,
struct file *filp,
loff_t size)
@@ -1459,6 +1457,9 @@ static inline int break_lease(struct ino

#endif /* !CONFIG_FILE_LOCKING */

+extern int rw_verify_area(int, struct file *, loff_t *, size_t);
+
+
/* fs/open.c */

extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,



=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================

2008-08-06 13:13:26

by Thomas Petazzoni

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

Le Mon, 4 Aug 2008 14:16:41 -0400,
"J. Bruce Fields" <[email protected]> a écrit :

> OK by me, but again, why exactly? Since you're replacing the locking
> calls they used by stubs that just return errors, in theory nfs, nfsd,
> gfs2, and the rest should still compile and run, just without locking
> support, right?

You're right, that was stupid. Either should I add the Kconfig
dependencies *OR* add the function stubs, not both. The following patch
implements the second solution. I've checked that NFS, CIFS, GFS2,
OCFS2, AFS and FUSE compile correctly. I've tested NFS only, though.

Here is the new patch. Comments and suggestions welcome.

Sincerly,

Thomas

---

Configure out file locking features

This patch adds the CONFIG_FILE_LOCKING option which allows to remove
support for advisory locks. With this patch enabled, the flock()
system call, the F_GETLK, F_SETLK and F_SETLKW operations of fcntl()
and NFS support are disabled. These features are not necessarly needed
on embedded systems. It allows to save ~11 Kb of kernel code and data:

text data bss dec hex filename
1125436 118764 212992 1457192 163c28 vmlinux.old
1114299 118564 212992 1445855 160fdf vmlinux
-11137 -200 0 -11337 -2C49 +/-

This patch has originally been written by Matt Mackall
<[email protected]>, and is part of the Linux Tiny project.

Signed-off-by: Thomas Petazzoni <[email protected]>
Signed-off-by: Matt Mackall <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
fs/Kconfig | 8 +++++++
fs/Makefile | 3 +-
fs/proc/proc_misc.c | 4 +++
include/linux/fs.h | 55 +++++++++++++++++++++++++++++++++++++++++++++-------
kernel/sys_ni.c | 1
kernel/sysctl.c | 6 ++++-
6 files changed, 68 insertions(+), 9 deletions(-)

Index: linuxdev/fs/Kconfig
===================================================================
--- linuxdev.orig/fs/Kconfig
+++ linuxdev/fs/Kconfig
@@ -419,6 +419,14 @@
bool
default n

+config FILE_LOCKING
+ bool "Enable POSIX file locking API" if EMBEDDED
+ default y
+ help
+ This option enables standard file locking support, required
+ for filesystems like NFS and for the flock() system
+ call. Disabling this option saves about 11k.
+
source "fs/xfs/Kconfig"
source "fs/gfs2/Kconfig"

Index: linuxdev/fs/Makefile
===================================================================
--- linuxdev.orig/fs/Makefile
+++ linuxdev/fs/Makefile
@@ -7,7 +7,7 @@

obj-y := open.o read_write.o file_table.o super.o \
char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
- ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
+ ioctl.o readdir.o select.o fifo.o dcache.o inode.o \
attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
seq_file.o xattr.o libfs.o fs-writeback.o \
pnode.o drop_caches.o splice.o sync.o utimes.o \
@@ -27,6 +27,7 @@
obj-$(CONFIG_SIGNALFD) += signalfd.o
obj-$(CONFIG_TIMERFD) += timerfd.o
obj-$(CONFIG_EVENTFD) += eventfd.o
+obj-$(CONFIG_FILE_LOCKING) += locks.o
obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o

nfsd-$(CONFIG_NFSD) := nfsctl.o
Index: linuxdev/fs/proc/proc_misc.c
===================================================================
--- linuxdev.orig/fs/proc/proc_misc.c
+++ linuxdev/fs/proc/proc_misc.c
@@ -677,6 +677,7 @@
return proc_calc_metrics(page, start, off, count, eof, len);
}

+#ifdef CONFIG_FILE_LOCKING
static int locks_open(struct inode *inode, struct file *filp)
{
return seq_open(filp, &locks_seq_operations);
@@ -688,6 +689,7 @@
.llseek = seq_lseek,
.release = seq_release,
};
+#endif /* CONFIG_FILE_LOCKING */

static int execdomains_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data)
@@ -881,7 +883,9 @@
#ifdef CONFIG_PRINTK
proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
#endif
+#ifdef CONFIG_FILE_LOCKING
proc_create("locks", 0, NULL, &proc_locks_operations);
+#endif
proc_create("devices", 0, NULL, &proc_devinfo_operations);
proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
#ifdef CONFIG_BLOCK
Index: linuxdev/include/linux/fs.h
===================================================================
--- linuxdev.orig/include/linux/fs.h
+++ linuxdev/include/linux/fs.h
@@ -983,6 +983,13 @@

#include <linux/fcntl.h>

+extern void send_sigio(struct fown_struct *fown, int fd, int band);
+
+/* fs/sync.c */
+extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
+ loff_t endbyte, unsigned int flags);
+
+#ifdef CONFIG_FILE_LOCKING
extern int fcntl_getlk(struct file *, struct flock __user *);
extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
struct flock __user *);
@@ -993,14 +1000,9 @@
struct flock64 __user *);
#endif

-extern void send_sigio(struct fown_struct *fown, int fd, int band);
extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
extern int fcntl_getlease(struct file *filp);

-/* fs/sync.c */
-extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
- loff_t endbyte, unsigned int flags);
-
/* fs/locks.c */
extern void locks_init_lock(struct file_lock *);
extern void locks_copy_lock(struct file_lock *, struct file_lock *);
@@ -1023,6 +1025,35 @@
extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
extern struct seq_operations locks_seq_operations;
+#else /* !CONFIG_FILE_LOCKING */
+#define fcntl_getlk(a, b) ({ -EINVAL; })
+#define fcntl_setlk(a, b, c, d) ({ -EACCES; })
+#if BITS_PER_LONG == 32
+#define fcntl_getlk64(a, b) ({ -EINVAL; })
+#define fcntl_setlk64(a, b, c, d) ({ -EACCES; })
+#endif
+#define fcntl_setlease(a, b, c) ({ 0; })
+#define fcntl_getlease(a) ({ 0; })
+#define locks_init_lock(a) ({ })
+#define __locks_copy_lock(a, b) ({ })
+#define locks_copy_lock(a, b) ({ })
+#define locks_remove_posix(a, b) ({ })
+#define locks_remove_flock(a) ({ })
+#define posix_test_lock(a, b) ({ 0; })
+#define posix_lock_file(a, b, c) ({ -ENOLCK; })
+#define posix_lock_file_wait(a, b) ({ -ENOLCK; })
+#define posix_unblock_lock(a, b) (-ENOENT)
+#define vfs_test_lock(a, b) ({ 0; })
+#define vfs_lock_file(a, b, c, d) (-ENOLCK)
+#define vfs_cancel_lock(a, b) ({ 0; })
+#define flock_lock_file_wait(a, b) ({ -ENOLCK; })
+#define __break_lease(a, b) ({ 0; })
+#define lease_get_mtime(a, b) ({ })
+#define generic_setlease(a, b, c) ({ -EINVAL; })
+#define lock_may_read(a, b, c) ({ 1; })
+#define lock_may_write(a, b, c) ({ 1; })
+#endif /* !CONFIG_FILE_LOCKING */
+

struct fasync_struct {
int magic;
@@ -1554,9 +1585,12 @@
/* /sys/fs */
extern struct kobject *fs_kobj;

+extern int rw_verify_area(int, struct file *, loff_t *, size_t);
+
#define FLOCK_VERIFY_READ 1
#define FLOCK_VERIFY_WRITE 2

+#ifdef CONFIG_FILE_LOCKING
extern int locks_mandatory_locked(struct inode *);
extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);

@@ -1587,8 +1621,6 @@
return 0;
}

-extern int rw_verify_area(int, struct file *, loff_t *, size_t);
-
static inline int locks_verify_truncate(struct inode *inode,
struct file *filp,
loff_t size)
@@ -1609,6 +1641,15 @@
return __break_lease(inode, mode);
return 0;
}
+#else /* !CONFIG_FILE_LOCKING */
+#define locks_mandatory_locked(a) ({ 0; })
+#define locks_mandatory_area(a, b, c, d, e) ({ 0; })
+#define __mandatory_lock(a) ({ 0; })
+#define mandatory_lock(a) ({ 0; })
+#define locks_verify_locked(a) ({ 0; })
+#define locks_verify_truncate(a, b, c) ({ 0; })
+#define break_lease(a, b) ({ 0; })
+#endif /* CONFIG_FILE_LOCKING */

/* fs/open.c */

Index: linuxdev/kernel/sys_ni.c
===================================================================
--- linuxdev.orig/kernel/sys_ni.c
+++ linuxdev/kernel/sys_ni.c
@@ -125,6 +125,7 @@
cond_syscall(sys_vm86);
cond_syscall(compat_sys_ipc);
cond_syscall(compat_sys_sysctl);
+cond_syscall(sys_flock);

/* arch-specific weak syscall entries */
cond_syscall(sys_pciconfig_read);
Index: linuxdev/kernel/sysctl.c
===================================================================
--- linuxdev.orig/kernel/sysctl.c
+++ linuxdev/kernel/sysctl.c
@@ -97,7 +97,7 @@
static int neg_one = -1;
#endif

-#ifdef CONFIG_MMU
+#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
static int two = 2;
#endif

@@ -1260,6 +1260,7 @@
.extra1 = &minolduid,
.extra2 = &maxolduid,
},
+#ifdef CONFIG_FILE_LOCKING
{
.ctl_name = FS_LEASES,
.procname = "leases-enable",
@@ -1268,6 +1269,7 @@
.mode = 0644,
.proc_handler = &proc_dointvec,
},
+#endif
#ifdef CONFIG_DNOTIFY
{
.ctl_name = FS_DIR_NOTIFY,
@@ -1279,6 +1281,7 @@
},
#endif
#ifdef CONFIG_MMU
+#ifdef CONFIG_FILE_LOCKING
{
.ctl_name = FS_LEASE_TIME,
.procname = "lease-break-time",
@@ -1290,6 +1293,7 @@
.extra1 = &zero,
.extra2 = &two,
},
+#endif
{
.procname = "aio-nr",
.data = &aio_nr,


--
Thomas Petazzoni, Free Electrons
Kernel, drivers and embedded Linux development,
consulting, training and support.
http://free-electrons.com

2008-08-07 22:56:32

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [patch 2/4] Configure out file locking features

On Wed, Aug 06, 2008 at 03:12:22PM +0200, Thomas Petazzoni wrote:
> Le Mon, 4 Aug 2008 14:16:41 -0400,
> "J. Bruce Fields" <[email protected]> a écrit :
>
> > OK by me, but again, why exactly? Since you're replacing the locking
> > calls they used by stubs that just return errors, in theory nfs, nfsd,
> > gfs2, and the rest should still compile and run, just without locking
> > support, right?
>
> You're right, that was stupid. Either should I add the Kconfig
> dependencies *OR* add the function stubs, not both. The following patch
> implements the second solution. I've checked that NFS, CIFS, GFS2,
> OCFS2, AFS and FUSE compile correctly. I've tested NFS only, though.
>
> Here is the new patch. Comments and suggestions welcome.

Seems fine to me, thanks! I can queue it up in my tree for 2.6.28 if
there's no objections.

(But, basic mail question: so I give this message to git-am and it
complains because of all this =3D=20 stuff, which google tells me is
quoted-printable encoding. Fine, I fixed it up by hand, but a) there
must be some less boring way to deal with it, and b) there must have
been some easy way to avoid it in the first place, either on my side or
yours? Enlightenment welcome.)

--b.

>
> Sincerly,
>
> Thomas
>
> ---
>
> Configure out file locking features
>
> This patch adds the CONFIG_FILE_LOCKING option which allows to remove
> support for advisory locks. With this patch enabled, the flock()
> system call, the F_GETLK, F_SETLK and F_SETLKW operations of fcntl()
> and NFS support are disabled. These features are not necessarly needed
> on embedded systems. It allows to save ~11 Kb of kernel code and data:
>
> text data bss dec hex filename
> 1125436 118764 212992 1457192 163c28 vmlinux.old
> 1114299 118564 212992 1445855 160fdf vmlinux
> -11137 -200 0 -11337 -2C49 +/-
>
> This patch has originally been written by Matt Mackall
> <[email protected]>, and is part of the Linux Tiny project.
>
> Signed-off-by: Thomas Petazzoni <[email protected]>
> Signed-off-by: Matt Mackall <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
>
> ---
> fs/Kconfig | 8 +++++++
> fs/Makefile | 3 +-
> fs/proc/proc_misc.c | 4 +++
> include/linux/fs.h | 55 +++++++++++++++++++++++++++++++++++++++++++++-------
> kernel/sys_ni.c | 1
> kernel/sysctl.c | 6 ++++-
> 6 files changed, 68 insertions(+), 9 deletions(-)
>
> Index: linuxdev/fs/Kconfig
> ===================================================================
> --- linuxdev.orig/fs/Kconfig
> +++ linuxdev/fs/Kconfig
> @@ -419,6 +419,14 @@
> bool
> default n
>
> +config FILE_LOCKING
> + bool "Enable POSIX file locking API" if EMBEDDED
> + default y
> + help
> + This option enables standard file locking support, required
> + for filesystems like NFS and for the flock() system
> + call. Disabling this option saves about 11k.
> +
> source "fs/xfs/Kconfig"
> source "fs/gfs2/Kconfig"
>
> Index: linuxdev/fs/Makefile
> ===================================================================
> --- linuxdev.orig/fs/Makefile
> +++ linuxdev/fs/Makefile
> @@ -7,7 +7,7 @@
>
> obj-y := open.o read_write.o file_table.o super.o \
> char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
> - ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
> + ioctl.o readdir.o select.o fifo.o dcache.o inode.o \
> attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
> seq_file.o xattr.o libfs.o fs-writeback.o \
> pnode.o drop_caches.o splice.o sync.o utimes.o \
> @@ -27,6 +27,7 @@
> obj-$(CONFIG_SIGNALFD) += signalfd.o
> obj-$(CONFIG_TIMERFD) += timerfd.o
> obj-$(CONFIG_EVENTFD) += eventfd.o
> +obj-$(CONFIG_FILE_LOCKING) += locks.o
> obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o
>
> nfsd-$(CONFIG_NFSD) := nfsctl.o
> Index: linuxdev/fs/proc/proc_misc.c
> ===================================================================
> --- linuxdev.orig/fs/proc/proc_misc.c
> +++ linuxdev/fs/proc/proc_misc.c
> @@ -677,6 +677,7 @@
> return proc_calc_metrics(page, start, off, count, eof, len);
> }
>
> +#ifdef CONFIG_FILE_LOCKING
> static int locks_open(struct inode *inode, struct file *filp)
> {
> return seq_open(filp, &locks_seq_operations);
> @@ -688,6 +689,7 @@
> .llseek = seq_lseek,
> .release = seq_release,
> };
> +#endif /* CONFIG_FILE_LOCKING */
>
> static int execdomains_read_proc(char *page, char **start, off_t off,
> int count, int *eof, void *data)
> @@ -881,7 +883,9 @@
> #ifdef CONFIG_PRINTK
> proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
> #endif
> +#ifdef CONFIG_FILE_LOCKING
> proc_create("locks", 0, NULL, &proc_locks_operations);
> +#endif
> proc_create("devices", 0, NULL, &proc_devinfo_operations);
> proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
> #ifdef CONFIG_BLOCK
> Index: linuxdev/include/linux/fs.h
> ===================================================================
> --- linuxdev.orig/include/linux/fs.h
> +++ linuxdev/include/linux/fs.h
> @@ -983,6 +983,13 @@
>
> #include <linux/fcntl.h>
>
> +extern void send_sigio(struct fown_struct *fown, int fd, int band);
> +
> +/* fs/sync.c */
> +extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
> + loff_t endbyte, unsigned int flags);
> +
> +#ifdef CONFIG_FILE_LOCKING
> extern int fcntl_getlk(struct file *, struct flock __user *);
> extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
> struct flock __user *);
> @@ -993,14 +1000,9 @@
> struct flock64 __user *);
> #endif
>
> -extern void send_sigio(struct fown_struct *fown, int fd, int band);
> extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
> extern int fcntl_getlease(struct file *filp);
>
> -/* fs/sync.c */
> -extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
> - loff_t endbyte, unsigned int flags);
> -
> /* fs/locks.c */
> extern void locks_init_lock(struct file_lock *);
> extern void locks_copy_lock(struct file_lock *, struct file_lock *);
> @@ -1023,6 +1025,35 @@
> extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
> extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
> extern struct seq_operations locks_seq_operations;
> +#else /* !CONFIG_FILE_LOCKING */
> +#define fcntl_getlk(a, b) ({ -EINVAL; })
> +#define fcntl_setlk(a, b, c, d) ({ -EACCES; })
> +#if BITS_PER_LONG == 32
> +#define fcntl_getlk64(a, b) ({ -EINVAL; })
> +#define fcntl_setlk64(a, b, c, d) ({ -EACCES; })
> +#endif
> +#define fcntl_setlease(a, b, c) ({ 0; })
> +#define fcntl_getlease(a) ({ 0; })
> +#define locks_init_lock(a) ({ })
> +#define __locks_copy_lock(a, b) ({ })
> +#define locks_copy_lock(a, b) ({ })
> +#define locks_remove_posix(a, b) ({ })
> +#define locks_remove_flock(a) ({ })
> +#define posix_test_lock(a, b) ({ 0; })
> +#define posix_lock_file(a, b, c) ({ -ENOLCK; })
> +#define posix_lock_file_wait(a, b) ({ -ENOLCK; })
> +#define posix_unblock_lock(a, b) (-ENOENT)
> +#define vfs_test_lock(a, b) ({ 0; })
> +#define vfs_lock_file(a, b, c, d) (-ENOLCK)
> +#define vfs_cancel_lock(a, b) ({ 0; })
> +#define flock_lock_file_wait(a, b) ({ -ENOLCK; })
> +#define __break_lease(a, b) ({ 0; })
> +#define lease_get_mtime(a, b) ({ })
> +#define generic_setlease(a, b, c) ({ -EINVAL; })
> +#define lock_may_read(a, b, c) ({ 1; })
> +#define lock_may_write(a, b, c) ({ 1; })
> +#endif /* !CONFIG_FILE_LOCKING */
> +
>
> struct fasync_struct {
> int magic;
> @@ -1554,9 +1585,12 @@
> /* /sys/fs */
> extern struct kobject *fs_kobj;
>
> +extern int rw_verify_area(int, struct file *, loff_t *, size_t);
> +
> #define FLOCK_VERIFY_READ 1
> #define FLOCK_VERIFY_WRITE 2
>
> +#ifdef CONFIG_FILE_LOCKING
> extern int locks_mandatory_locked(struct inode *);
> extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
>
> @@ -1587,8 +1621,6 @@
> return 0;
> }
>
> -extern int rw_verify_area(int, struct file *, loff_t *, size_t);
> -
> static inline int locks_verify_truncate(struct inode *inode,
> struct file *filp,
> loff_t size)
> @@ -1609,6 +1641,15 @@
> return __break_lease(inode, mode);
> return 0;
> }
> +#else /* !CONFIG_FILE_LOCKING */
> +#define locks_mandatory_locked(a) ({ 0; })
> +#define locks_mandatory_area(a, b, c, d, e) ({ 0; })
> +#define __mandatory_lock(a) ({ 0; })
> +#define mandatory_lock(a) ({ 0; })
> +#define locks_verify_locked(a) ({ 0; })
> +#define locks_verify_truncate(a, b, c) ({ 0; })
> +#define break_lease(a, b) ({ 0; })
> +#endif /* CONFIG_FILE_LOCKING */
>
> /* fs/open.c */
>
> Index: linuxdev/kernel/sys_ni.c
> ===================================================================
> --- linuxdev.orig/kernel/sys_ni.c
> +++ linuxdev/kernel/sys_ni.c
> @@ -125,6 +125,7 @@
> cond_syscall(sys_vm86);
> cond_syscall(compat_sys_ipc);
> cond_syscall(compat_sys_sysctl);
> +cond_syscall(sys_flock);
>
> /* arch-specific weak syscall entries */
> cond_syscall(sys_pciconfig_read);
> Index: linuxdev/kernel/sysctl.c
> ===================================================================
> --- linuxdev.orig/kernel/sysctl.c
> +++ linuxdev/kernel/sysctl.c
> @@ -97,7 +97,7 @@
> static int neg_one = -1;
> #endif
>
> -#ifdef CONFIG_MMU
> +#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
> static int two = 2;
> #endif
>
> @@ -1260,6 +1260,7 @@
> .extra1 = &minolduid,
> .extra2 = &maxolduid,
> },
> +#ifdef CONFIG_FILE_LOCKING
> {
> .ctl_name = FS_LEASES,
> .procname = "leases-enable",
> @@ -1268,6 +1269,7 @@
> .mode = 0644,
> .proc_handler = &proc_dointvec,
> },
> +#endif
> #ifdef CONFIG_DNOTIFY
> {
> .ctl_name = FS_DIR_NOTIFY,
> @@ -1279,6 +1281,7 @@
> },
> #endif
> #ifdef CONFIG_MMU
> +#ifdef CONFIG_FILE_LOCKING
> {
> .ctl_name = FS_LEASE_TIME,
> .procname = "lease-break-time",
> @@ -1290,6 +1293,7 @@
> .extra1 = &zero,
> .extra2 = &two,
> },
> +#endif
> {
> .procname = "aio-nr",
> .data = &aio_nr,
>
>
> --
> Thomas Petazzoni, Free Electrons
> Kernel, drivers and embedded Linux development,
> consulting, training and support.
> http://free-electrons.com