History

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.

Thomas Petazzoni committed 18 years ago

Commit bfcd17a1 parent 04716e66 files · +70 −9Browse files

Unified · Split

6 files
  1. fs/Kconfig +8 −0
  2. fs/Makefile +2 −1
  3. fs/proc/proc_misc.c +4 −0
  4. include/linux/fs.h +50 −7
  5. kernel/sys_ni.c +1 −0
  6. kernel/sysctl.c +5 −1
fs/Kconfig+8−0
@@ -419,6 +419,14 @@ config FS_POSIX_ACL · 418 unmodified lines
419419 bool
420420 default n
421421
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+
422430 source "fs/xfs/Kconfig"
423431 source "fs/gfs2/Kconfig"
424432
fs/Makefile+2−1
@@ -7,7 +7,7 @@ · 6 unmodified lines
77
88 obj-y := open.o read_write.o file_table.o super.o \
99 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 \
1111 attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
1212 seq_file.o xattr.o libfs.o fs-writeback.o \
1313 pnode.o drop_caches.o splice.o sync.o utimes.o \
@@ -27,6 +27,7 @@ obj-$(CONFIG_ANON_INODES) += anon_inodes.o · 13 unmodified lines
2727 obj-$(CONFIG_SIGNALFD) += signalfd.o
2828 obj-$(CONFIG_TIMERFD) += timerfd.o
2929 obj-$(CONFIG_EVENTFD) += eventfd.o
30+obj-$(CONFIG_FILE_LOCKING) += locks.o
3031 obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o
3132
3233 nfsd-$(CONFIG_NFSD) := nfsctl.o
fs/proc/proc_misc.c+4−0
@@ -684,6 +684,7 @@ static int cmdline_read_proc(char *page, char **start, off_t off, · 683 unmodified lines
684684 return proc_calc_metrics(page, start, off, count, eof, len);
685685 }
686686
687+#ifdef CONFIG_FILE_LOCKING
687688 static int locks_open(struct inode *inode, struct file *filp)
688689 {
689690 return seq_open(filp, &locks_seq_operations);
@@ -695,6 +696,7 @@ static const struct file_operations proc_locks_operations = { · 5 unmodified lines
695696 .llseek = seq_lseek,
696697 .release = seq_release,
697698 };
699+#endif /* CONFIG_FILE_LOCKING */
698700
699701 static int execdomains_read_proc(char *page, char **start, off_t off,
700702 int count, int *eof, void *data)
@@ -888,7 +890,9 @@ void __init proc_misc_init(void) · 187 unmodified lines
888890 #ifdef CONFIG_PRINTK
889891 proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
890892 #endif
893+#ifdef CONFIG_FILE_LOCKING
891894 proc_create("locks", 0, NULL, &proc_locks_operations);
895+#endif
892896 proc_create("devices", 0, NULL, &proc_devinfo_operations);
893897 proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
894898 #ifdef CONFIG_BLOCK
include/linux/fs.h+50−7
@@ -983,6 +983,13 @@ struct file_lock { · 982 unmodified lines
983983
984984 #include <linux/fcntl.h>
985985
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
986993 extern int fcntl_getlk(struct file *, struct flock __user *);
987994 extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
988995 struct flock __user *);
@@ -993,14 +1000,9 @@ extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, · 4 unmodified lines
9931000 struct flock64 __user *);
9941001 #endif
9951002
996−extern void send_sigio(struct fown_struct *fown, int fd, int band);
9971003 extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
9981004 extern int fcntl_getlease(struct file *filp);
9991005
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−
10041006 /* fs/locks.c */
10051007 extern void locks_init_lock(struct file_lock *);
10061008 extern void locks_copy_lock(struct file_lock *, struct file_lock *);
@@ -1023,6 +1025,37 @@ extern int lease_modify(struct file_lock **, int); · 16 unmodified lines
10231025 extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
10241026 extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
10251027 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 */
1058+
10261059
10271060 struct fasync_struct {
10281061 int magic;
@@ -1554,9 +1587,12 @@ extern int vfs_statfs(struct dentry *, struct kstatfs *); · 525 unmodified lines
15541587 /* /sys/fs */
15551588 extern struct kobject *fs_kobj;
15561589
1590+extern int rw_verify_area(int, struct file *, loff_t *, size_t);
1591+
15571592 #define FLOCK_VERIFY_READ 1
15581593 #define FLOCK_VERIFY_WRITE 2
15591594
1595+#ifdef CONFIG_FILE_LOCKING
15601596 extern int locks_mandatory_locked(struct inode *);
15611597 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
15621598
@@ -1587,8 +1623,6 @@ static inline int locks_verify_locked(struct inode *inode) · 24 unmodified lines
15871623 return 0;
15881624 }
15891625
1590−extern int rw_verify_area(int, struct file *, loff_t *, size_t);
1591−
15921626 static inline int locks_verify_truncate(struct inode *inode,
15931627 struct file *filp,
15941628 loff_t size)
@@ -1609,6 +1643,15 @@ static inline int break_lease(struct inode *inode, unsigned int mode) · 14 unmodified lines
16091643 return __break_lease(inode, mode);
16101644 return 0;
16111645 }
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 */
16121655
16131656 /* fs/open.c */
16141657
kernel/sys_ni.c+1−0
@@ -125,6 +125,7 @@ cond_syscall(sys_vm86old); · 124 unmodified lines
125125 cond_syscall(sys_vm86);
126126 cond_syscall(compat_sys_ipc);
127127 cond_syscall(compat_sys_sysctl);
128+cond_syscall(sys_flock);
128129
129130 /* arch-specific weak syscall entries */
130131 cond_syscall(sys_pciconfig_read);
kernel/sysctl.c+5−1
@@ -97,7 +97,7 @@ static int sixty = 60; · 96 unmodified lines
9797 static int neg_one = -1;
9898 #endif
9999
100−#ifdef CONFIG_MMU
100+#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
101101 static int two = 2;
102102 #endif
103103
@@ -1261,6 +1261,7 @@ static struct ctl_table fs_table[] = { · 1157 unmodified lines
12611261 .extra1 = &minolduid,
12621262 .extra2 = &maxolduid,
12631263 },
1264+#ifdef CONFIG_FILE_LOCKING
12641265 {
12651266 .ctl_name = FS_LEASES,
12661267 .procname = "leases-enable",
@@ -1269,6 +1270,7 @@ static struct ctl_table fs_table[] = { · 2 unmodified lines
12691270 .mode = 0644,
12701271 .proc_handler = &proc_dointvec,
12711272 },
1273+#endif
12721274 #ifdef CONFIG_DNOTIFY
12731275 {
12741276 .ctl_name = FS_DIR_NOTIFY,
@@ -1280,6 +1282,7 @@ static struct ctl_table fs_table[] = { · 5 unmodified lines
12801282 },
12811283 #endif
12821284 #ifdef CONFIG_MMU
1285+#ifdef CONFIG_FILE_LOCKING
12831286 {
12841287 .ctl_name = FS_LEASE_TIME,
12851288 .procname = "lease-break-time",
@@ -1291,6 +1294,7 @@ static struct ctl_table fs_table[] = { · 5 unmodified lines
12911294 .extra1 = &zero,
12921295 .extra2 = &two,
12931296 },
1297+#endif
12941298 {
12951299 .procname = "aio-nr",
12961300 .data = &aio_nr,