Commit bfcd17a6c5529bc37234cfa720a047cf9397bcfc
Committed by
J. Bruce Fields
1 parent
04716e6621
Exists in
master
and in
20 other branches
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 <mpm@selenic.com>, and is part of the Linux Tiny project. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Signed-off-by: Matt Mackall <mpm@selenic.com> Cc: matthew@wil.cx Cc: linux-fsdevel@vger.kernel.org Cc: mpm@selenic.com Cc: akpm@linux-foundation.org Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Showing 6 changed files with 70 additions and 9 deletions Side-by-side Diff
fs/Kconfig
... | ... | @@ -419,6 +419,14 @@ |
419 | 419 | bool |
420 | 420 | default n |
421 | 421 | |
422 | +config FILE_LOCKING | |
423 | + bool "Enable POSIX file locking API" if EMBEDDED | |
424 | + default y | |
425 | + help | |
426 | + This option enables standard file locking support, required | |
427 | + for filesystems like NFS and for the flock() system | |
428 | + call. Disabling this option saves about 11k. | |
429 | + | |
422 | 430 | source "fs/xfs/Kconfig" |
423 | 431 | source "fs/gfs2/Kconfig" |
424 | 432 |
fs/Makefile
... | ... | @@ -7,7 +7,7 @@ |
7 | 7 | |
8 | 8 | obj-y := open.o read_write.o file_table.o super.o \ |
9 | 9 | char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \ |
10 | - ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \ | |
10 | + ioctl.o readdir.o select.o fifo.o dcache.o inode.o \ | |
11 | 11 | attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \ |
12 | 12 | seq_file.o xattr.o libfs.o fs-writeback.o \ |
13 | 13 | pnode.o drop_caches.o splice.o sync.o utimes.o \ |
... | ... | @@ -27,6 +27,7 @@ |
27 | 27 | obj-$(CONFIG_SIGNALFD) += signalfd.o |
28 | 28 | obj-$(CONFIG_TIMERFD) += timerfd.o |
29 | 29 | obj-$(CONFIG_EVENTFD) += eventfd.o |
30 | +obj-$(CONFIG_FILE_LOCKING) += locks.o | |
30 | 31 | obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o |
31 | 32 | |
32 | 33 | nfsd-$(CONFIG_NFSD) := nfsctl.o |
fs/proc/proc_misc.c
... | ... | @@ -684,6 +684,7 @@ |
684 | 684 | return proc_calc_metrics(page, start, off, count, eof, len); |
685 | 685 | } |
686 | 686 | |
687 | +#ifdef CONFIG_FILE_LOCKING | |
687 | 688 | static int locks_open(struct inode *inode, struct file *filp) |
688 | 689 | { |
689 | 690 | return seq_open(filp, &locks_seq_operations); |
... | ... | @@ -695,6 +696,7 @@ |
695 | 696 | .llseek = seq_lseek, |
696 | 697 | .release = seq_release, |
697 | 698 | }; |
699 | +#endif /* CONFIG_FILE_LOCKING */ | |
698 | 700 | |
699 | 701 | static int execdomains_read_proc(char *page, char **start, off_t off, |
700 | 702 | int count, int *eof, void *data) |
701 | 703 | |
... | ... | @@ -888,7 +890,9 @@ |
888 | 890 | #ifdef CONFIG_PRINTK |
889 | 891 | proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations); |
890 | 892 | #endif |
893 | +#ifdef CONFIG_FILE_LOCKING | |
891 | 894 | proc_create("locks", 0, NULL, &proc_locks_operations); |
895 | +#endif | |
892 | 896 | proc_create("devices", 0, NULL, &proc_devinfo_operations); |
893 | 897 | proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations); |
894 | 898 | #ifdef CONFIG_BLOCK |
include/linux/fs.h
... | ... | @@ -983,6 +983,13 @@ |
983 | 983 | |
984 | 984 | #include <linux/fcntl.h> |
985 | 985 | |
986 | +extern void send_sigio(struct fown_struct *fown, int fd, int band); | |
987 | + | |
988 | +/* fs/sync.c */ | |
989 | +extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset, | |
990 | + loff_t endbyte, unsigned int flags); | |
991 | + | |
992 | +#ifdef CONFIG_FILE_LOCKING | |
986 | 993 | extern int fcntl_getlk(struct file *, struct flock __user *); |
987 | 994 | extern int fcntl_setlk(unsigned int, struct file *, unsigned int, |
988 | 995 | struct flock __user *); |
989 | 996 | |
... | ... | @@ -993,14 +1000,9 @@ |
993 | 1000 | struct flock64 __user *); |
994 | 1001 | #endif |
995 | 1002 | |
996 | -extern void send_sigio(struct fown_struct *fown, int fd, int band); | |
997 | 1003 | extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); |
998 | 1004 | extern int fcntl_getlease(struct file *filp); |
999 | 1005 | |
1000 | -/* fs/sync.c */ | |
1001 | -extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset, | |
1002 | - loff_t endbyte, unsigned int flags); | |
1003 | - | |
1004 | 1006 | /* fs/locks.c */ |
1005 | 1007 | extern void locks_init_lock(struct file_lock *); |
1006 | 1008 | extern void locks_copy_lock(struct file_lock *, struct file_lock *); |
1007 | 1009 | |
... | ... | @@ -1023,7 +1025,38 @@ |
1023 | 1025 | extern int lock_may_read(struct inode *, loff_t start, unsigned long count); |
1024 | 1026 | extern int lock_may_write(struct inode *, loff_t start, unsigned long count); |
1025 | 1027 | extern struct seq_operations locks_seq_operations; |
1028 | +#else /* !CONFIG_FILE_LOCKING */ | |
1029 | +#define fcntl_getlk(a, b) ({ -EINVAL; }) | |
1030 | +#define fcntl_setlk(a, b, c, d) ({ -EACCES; }) | |
1031 | +#if BITS_PER_LONG == 32 | |
1032 | +#define fcntl_getlk64(a, b) ({ -EINVAL; }) | |
1033 | +#define fcntl_setlk64(a, b, c, d) ({ -EACCES; }) | |
1034 | +#endif | |
1035 | +#define fcntl_setlease(a, b, c) ({ 0; }) | |
1036 | +#define fcntl_getlease(a) ({ 0; }) | |
1037 | +#define locks_init_lock(a) ({ }) | |
1038 | +#define __locks_copy_lock(a, b) ({ }) | |
1039 | +#define locks_copy_lock(a, b) ({ }) | |
1040 | +#define locks_remove_posix(a, b) ({ }) | |
1041 | +#define locks_remove_flock(a) ({ }) | |
1042 | +#define posix_test_lock(a, b) ({ 0; }) | |
1043 | +#define posix_lock_file(a, b, c) ({ -ENOLCK; }) | |
1044 | +#define posix_lock_file_wait(a, b) ({ -ENOLCK; }) | |
1045 | +#define posix_unblock_lock(a, b) (-ENOENT) | |
1046 | +#define vfs_test_lock(a, b) ({ 0; }) | |
1047 | +#define vfs_lock_file(a, b, c, d) (-ENOLCK) | |
1048 | +#define vfs_cancel_lock(a, b) ({ 0; }) | |
1049 | +#define flock_lock_file_wait(a, b) ({ -ENOLCK; }) | |
1050 | +#define __break_lease(a, b) ({ 0; }) | |
1051 | +#define lease_get_mtime(a, b) ({ }) | |
1052 | +#define generic_setlease(a, b, c) ({ -EINVAL; }) | |
1053 | +#define vfs_setlease(a, b, c) ({ -EINVAL; }) | |
1054 | +#define lease_modify(a, b) ({ -EINVAL; }) | |
1055 | +#define lock_may_read(a, b, c) ({ 1; }) | |
1056 | +#define lock_may_write(a, b, c) ({ 1; }) | |
1057 | +#endif /* !CONFIG_FILE_LOCKING */ | |
1026 | 1058 | |
1059 | + | |
1027 | 1060 | struct fasync_struct { |
1028 | 1061 | int magic; |
1029 | 1062 | int fa_fd; |
1030 | 1063 | |
... | ... | @@ -1554,9 +1587,12 @@ |
1554 | 1587 | /* /sys/fs */ |
1555 | 1588 | extern struct kobject *fs_kobj; |
1556 | 1589 | |
1590 | +extern int rw_verify_area(int, struct file *, loff_t *, size_t); | |
1591 | + | |
1557 | 1592 | #define FLOCK_VERIFY_READ 1 |
1558 | 1593 | #define FLOCK_VERIFY_WRITE 2 |
1559 | 1594 | |
1595 | +#ifdef CONFIG_FILE_LOCKING | |
1560 | 1596 | extern int locks_mandatory_locked(struct inode *); |
1561 | 1597 | extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); |
1562 | 1598 | |
... | ... | @@ -1587,8 +1623,6 @@ |
1587 | 1623 | return 0; |
1588 | 1624 | } |
1589 | 1625 | |
1590 | -extern int rw_verify_area(int, struct file *, loff_t *, size_t); | |
1591 | - | |
1592 | 1626 | static inline int locks_verify_truncate(struct inode *inode, |
1593 | 1627 | struct file *filp, |
1594 | 1628 | loff_t size) |
... | ... | @@ -1609,6 +1643,15 @@ |
1609 | 1643 | return __break_lease(inode, mode); |
1610 | 1644 | return 0; |
1611 | 1645 | } |
1646 | +#else /* !CONFIG_FILE_LOCKING */ | |
1647 | +#define locks_mandatory_locked(a) ({ 0; }) | |
1648 | +#define locks_mandatory_area(a, b, c, d, e) ({ 0; }) | |
1649 | +#define __mandatory_lock(a) ({ 0; }) | |
1650 | +#define mandatory_lock(a) ({ 0; }) | |
1651 | +#define locks_verify_locked(a) ({ 0; }) | |
1652 | +#define locks_verify_truncate(a, b, c) ({ 0; }) | |
1653 | +#define break_lease(a, b) ({ 0; }) | |
1654 | +#endif /* CONFIG_FILE_LOCKING */ | |
1612 | 1655 | |
1613 | 1656 | /* fs/open.c */ |
1614 | 1657 |
kernel/sys_ni.c
kernel/sysctl.c
... | ... | @@ -97,7 +97,7 @@ |
97 | 97 | static int neg_one = -1; |
98 | 98 | #endif |
99 | 99 | |
100 | -#ifdef CONFIG_MMU | |
100 | +#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING) | |
101 | 101 | static int two = 2; |
102 | 102 | #endif |
103 | 103 | |
... | ... | @@ -1261,6 +1261,7 @@ |
1261 | 1261 | .extra1 = &minolduid, |
1262 | 1262 | .extra2 = &maxolduid, |
1263 | 1263 | }, |
1264 | +#ifdef CONFIG_FILE_LOCKING | |
1264 | 1265 | { |
1265 | 1266 | .ctl_name = FS_LEASES, |
1266 | 1267 | .procname = "leases-enable", |
... | ... | @@ -1269,6 +1270,7 @@ |
1269 | 1270 | .mode = 0644, |
1270 | 1271 | .proc_handler = &proc_dointvec, |
1271 | 1272 | }, |
1273 | +#endif | |
1272 | 1274 | #ifdef CONFIG_DNOTIFY |
1273 | 1275 | { |
1274 | 1276 | .ctl_name = FS_DIR_NOTIFY, |
... | ... | @@ -1280,6 +1282,7 @@ |
1280 | 1282 | }, |
1281 | 1283 | #endif |
1282 | 1284 | #ifdef CONFIG_MMU |
1285 | +#ifdef CONFIG_FILE_LOCKING | |
1283 | 1286 | { |
1284 | 1287 | .ctl_name = FS_LEASE_TIME, |
1285 | 1288 | .procname = "lease-break-time", |
... | ... | @@ -1291,6 +1294,7 @@ |
1291 | 1294 | .extra1 = &zero, |
1292 | 1295 | .extra2 = &two, |
1293 | 1296 | }, |
1297 | +#endif | |
1294 | 1298 | { |
1295 | 1299 | .procname = "aio-nr", |
1296 | 1300 | .data = &aio_nr, |