diff options
| author | Eric W. Biederman <ebiederm@xmission.com> | 2012-01-06 07:07:15 -0500 |
|---|---|---|
| committer | Eric W. Biederman <ebiederm@xmission.com> | 2012-01-24 19:37:54 -0500 |
| commit | 1f87f0b52b1d6581168cb80f86746bc4df918d01 (patch) | |
| tree | 73576c0872c61c526ade225d6441a6610beb666b /kernel | |
| parent | de4e83bd6b5e16d491ec068cd22801d5d063b07a (diff) | |
sysctl: Move the implementation into fs/proc/proc_sysctl.c
Move the core sysctl code from kernel/sysctl.c and kernel/sysctl_check.c
into fs/proc/proc_sysctl.c.
Currently sysctl maintenance is hampered by the sysctl implementation
being split across 3 files with artificial layering between them.
Consolidate the entire sysctl implementation into 1 file so that
it is easier to see what is going on and hopefully allowing for
simpler maintenance.
For functions that are now only used in fs/proc/proc_sysctl.c remove
their declarations from sysctl.h and make them static in fs/proc/proc_sysctl.c
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/Makefile | 1 | ||||
| -rw-r--r-- | kernel/sysctl.c | 464 | ||||
| -rw-r--r-- | kernel/sysctl_check.c | 160 |
3 files changed, 0 insertions, 625 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 2d9de86b7e76..cb41b9547c9f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
| @@ -27,7 +27,6 @@ obj-y += power/ | |||
| 27 | 27 | ||
| 28 | obj-$(CONFIG_FREEZER) += freezer.o | 28 | obj-$(CONFIG_FREEZER) += freezer.o |
| 29 | obj-$(CONFIG_PROFILING) += profile.o | 29 | obj-$(CONFIG_PROFILING) += profile.o |
| 30 | obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o | ||
| 31 | obj-$(CONFIG_STACKTRACE) += stacktrace.o | 30 | obj-$(CONFIG_STACKTRACE) += stacktrace.o |
| 32 | obj-y += time/ | 31 | obj-y += time/ |
| 33 | obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o | 32 | obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index ad460248acc7..b774909ed46c 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
| @@ -192,20 +192,6 @@ static int sysrq_sysctl_handler(ctl_table *table, int write, | |||
| 192 | 192 | ||
| 193 | #endif | 193 | #endif |
| 194 | 194 | ||
| 195 | static struct ctl_table root_table[1]; | ||
| 196 | static struct ctl_table_root sysctl_table_root; | ||
| 197 | static struct ctl_table_header root_table_header = { | ||
| 198 | {{.count = 1, | ||
| 199 | .ctl_table = root_table, | ||
| 200 | .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}}, | ||
| 201 | .root = &sysctl_table_root, | ||
| 202 | .set = &sysctl_table_root.default_set, | ||
| 203 | }; | ||
| 204 | static struct ctl_table_root sysctl_table_root = { | ||
| 205 | .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), | ||
| 206 | .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry), | ||
| 207 | }; | ||
| 208 | |||
| 209 | static struct ctl_table kern_table[]; | 195 | static struct ctl_table kern_table[]; |
| 210 | static struct ctl_table vm_table[]; | 196 | static struct ctl_table vm_table[]; |
| 211 | static struct ctl_table fs_table[]; | 197 | static struct ctl_table fs_table[]; |
| @@ -1559,459 +1545,12 @@ static struct ctl_table dev_table[] = { | |||
| 1559 | { } | 1545 | { } |
| 1560 | }; | 1546 | }; |
| 1561 | 1547 | ||
| 1562 | static DEFINE_SPINLOCK(sysctl_lock); | ||
| 1563 | |||
| 1564 | /* called under sysctl_lock */ | ||
| 1565 | static int use_table(struct ctl_table_header *p) | ||
| 1566 | { | ||
| 1567 | if (unlikely(p->unregistering)) | ||
| 1568 | return 0; | ||
| 1569 | p->used++; | ||
| 1570 | return 1; | ||
| 1571 | } | ||
| 1572 | |||
| 1573 | /* called under sysctl_lock */ | ||
| 1574 | static void unuse_table(struct ctl_table_header *p) | ||
| 1575 | { | ||
| 1576 | if (!--p->used) | ||
| 1577 | if (unlikely(p->unregistering)) | ||
| 1578 | complete(p->unregistering); | ||
| 1579 | } | ||
| 1580 | |||
| 1581 | /* called under sysctl_lock, will reacquire if has to wait */ | ||
| 1582 | static void start_unregistering(struct ctl_table_header *p) | ||
| 1583 | { | ||
| 1584 | /* | ||
| 1585 | * if p->used is 0, nobody will ever touch that entry again; | ||
| 1586 | * we'll eliminate all paths to it before dropping sysctl_lock | ||
| 1587 | */ | ||
| 1588 | if (unlikely(p->used)) { | ||
| 1589 | struct completion wait; | ||
| 1590 | init_completion(&wait); | ||
| 1591 | p->unregistering = &wait; | ||
| 1592 | spin_unlock(&sysctl_lock); | ||
| 1593 | wait_for_completion(&wait); | ||
| 1594 | spin_lock(&sysctl_lock); | ||
| 1595 | } else { | ||
| 1596 | /* anything non-NULL; we'll never dereference it */ | ||
| 1597 | p->unregistering = ERR_PTR(-EINVAL); | ||
| 1598 | } | ||
| 1599 | /* | ||
| 1600 | * do not remove from the list until nobody holds it; walking the | ||
| 1601 | * list in do_sysctl() relies on that. | ||
| 1602 | */ | ||
| 1603 | list_del_init(&p->ctl_entry); | ||
| 1604 | } | ||
| 1605 | |||
| 1606 | void sysctl_head_get(struct ctl_table_header *head) | ||
| 1607 | { | ||
| 1608 | spin_lock(&sysctl_lock); | ||
| 1609 | head->count++; | ||
| 1610 | spin_unlock(&sysctl_lock); | ||
| 1611 | } | ||
| 1612 | |||
| 1613 | void sysctl_head_put(struct ctl_table_header *head) | ||
| 1614 | { | ||
| 1615 | spin_lock(&sysctl_lock); | ||
| 1616 | if (!--head->count) | ||
| 1617 | kfree_rcu(head, rcu); | ||
| 1618 | spin_unlock(&sysctl_lock); | ||
| 1619 | } | ||
| 1620 | |||
| 1621 | struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head) | ||
| 1622 | { | ||
| 1623 | if (!head) | ||
| 1624 | BUG(); | ||
| 1625 | spin_lock(&sysctl_lock); | ||
| 1626 | if (!use_table(head)) | ||
| 1627 | head = ERR_PTR(-ENOENT); | ||
| 1628 | spin_unlock(&sysctl_lock); | ||
| 1629 | return head; | ||
| 1630 | } | ||
| 1631 | |||
| 1632 | void sysctl_head_finish(struct ctl_table_header *head) | ||
| 1633 | { | ||
| 1634 | if (!head) | ||
| 1635 | return; | ||
| 1636 | spin_lock(&sysctl_lock); | ||
| 1637 | unuse_table(head); | ||
| 1638 | spin_unlock(&sysctl_lock); | ||
| 1639 | } | ||
| 1640 | |||
| 1641 | static struct ctl_table_set * | ||
| 1642 | lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces) | ||
| 1643 | { | ||
| 1644 | struct ctl_table_set *set = &root->default_set; | ||
| 1645 | if (root->lookup) | ||
| 1646 | set = root->lookup(root, namespaces); | ||
| 1647 | return set; | ||
| 1648 | } | ||
| 1649 | |||
| 1650 | static struct list_head * | ||
| 1651 | lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) | ||
| 1652 | { | ||
| 1653 | struct ctl_table_set *set = lookup_header_set(root, namespaces); | ||
| 1654 | return &set->list; | ||
| 1655 | } | ||
| 1656 | |||
| 1657 | struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, | ||
| 1658 | struct ctl_table_header *prev) | ||
| 1659 | { | ||
| 1660 | struct ctl_table_root *root; | ||
| 1661 | struct list_head *header_list; | ||
| 1662 | struct ctl_table_header *head; | ||
| 1663 | struct list_head *tmp; | ||
| 1664 | |||
| 1665 | spin_lock(&sysctl_lock); | ||
| 1666 | if (prev) { | ||
| 1667 | head = prev; | ||
| 1668 | tmp = &prev->ctl_entry; | ||
| 1669 | unuse_table(prev); | ||
| 1670 | goto next; | ||
| 1671 | } | ||
| 1672 | tmp = &root_table_header.ctl_entry; | ||
| 1673 | for (;;) { | ||
| 1674 | head = list_entry(tmp, struct ctl_table_header, ctl_entry); | ||
| 1675 | |||
| 1676 | if (!use_table(head)) | ||
| 1677 | goto next; | ||
| 1678 | spin_unlock(&sysctl_lock); | ||
| 1679 | return head; | ||
| 1680 | next: | ||
| 1681 | root = head->root; | ||
| 1682 | tmp = tmp->next; | ||
| 1683 | header_list = lookup_header_list(root, namespaces); | ||
| 1684 | if (tmp != header_list) | ||
| 1685 | continue; | ||
| 1686 | |||
| 1687 | do { | ||
| 1688 | root = list_entry(root->root_list.next, | ||
| 1689 | struct ctl_table_root, root_list); | ||
| 1690 | if (root == &sysctl_table_root) | ||
| 1691 | goto out; | ||
| 1692 | header_list = lookup_header_list(root, namespaces); | ||
| 1693 | } while (list_empty(header_list)); | ||
| 1694 | tmp = header_list->next; | ||
| 1695 | } | ||
| 1696 | out: | ||
| 1697 | spin_unlock(&sysctl_lock); | ||
| 1698 | return NULL; | ||
| 1699 | } | ||
| 1700 | |||
| 1701 | struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) | ||
| 1702 | { | ||
| 1703 | return __sysctl_head_next(current->nsproxy, prev); | ||
| 1704 | } | ||
| 1705 | |||
| 1706 | void register_sysctl_root(struct ctl_table_root *root) | ||
| 1707 | { | ||
| 1708 | spin_lock(&sysctl_lock); | ||
| 1709 | list_add_tail(&root->root_list, &sysctl_table_root.root_list); | ||
| 1710 | spin_unlock(&sysctl_lock); | ||
| 1711 | } | ||
| 1712 | |||
| 1713 | /* | ||
| 1714 | * sysctl_perm does NOT grant the superuser all rights automatically, because | ||
| 1715 | * some sysctl variables are readonly even to root. | ||
| 1716 | */ | ||
| 1717 | |||
| 1718 | static int test_perm(int mode, int op) | ||
| 1719 | { | ||
| 1720 | if (!current_euid()) | ||
