diff options
Diffstat (limited to 'mm/swapfile.c')
-rw-r--r-- | mm/swapfile.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c index 5238d8d15d78..6d1c3c67ae65 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c | |||
@@ -1844,33 +1844,15 @@ static int __init max_swapfiles_check(void) | |||
1844 | late_initcall(max_swapfiles_check); | 1844 | late_initcall(max_swapfiles_check); |
1845 | #endif | 1845 | #endif |
1846 | 1846 | ||
1847 | SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) | 1847 | static struct swap_info_struct *alloc_swap_info(void) |
1848 | { | 1848 | { |
1849 | struct swap_info_struct *p; | 1849 | struct swap_info_struct *p; |
1850 | char *name = NULL; | ||
1851 | struct block_device *bdev = NULL; | ||
1852 | struct file *swap_file = NULL; | ||
1853 | struct address_space *mapping; | ||
1854 | unsigned int type; | 1850 | unsigned int type; |
1855 | int i, prev; | ||
1856 | int error; | 1851 | int error; |
1857 | union swap_header *swap_header; | ||
1858 | unsigned int nr_good_pages; | ||
1859 | int nr_extents = 0; | ||
1860 | sector_t span; | ||
1861 | unsigned long maxpages; | ||
1862 | unsigned long swapfilepages; | ||
1863 | unsigned char *swap_map = NULL; | ||
1864 | struct page *page = NULL; | ||
1865 | struct inode *inode = NULL; | ||
1866 | int did_down = 0; | ||
1867 | |||
1868 | if (!capable(CAP_SYS_ADMIN)) | ||
1869 | return -EPERM; | ||
1870 | 1852 | ||
1871 | p = kzalloc(sizeof(*p), GFP_KERNEL); | 1853 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
1872 | if (!p) | 1854 | if (!p) |
1873 | return -ENOMEM; | 1855 | return ERR_PTR(-ENOMEM); |
1874 | 1856 | ||
1875 | spin_lock(&swap_lock); | 1857 | spin_lock(&swap_lock); |
1876 | for (type = 0; type < nr_swapfiles; type++) { | 1858 | for (type = 0; type < nr_swapfiles; type++) { |
@@ -1906,6 +1888,41 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) | |||
1906 | p->next = -1; | 1888 | p->next = -1; |
1907 | spin_unlock(&swap_lock); | 1889 | spin_unlock(&swap_lock); |
1908 | 1890 | ||
1891 | return p; | ||
1892 | |||
1893 | out: | ||
1894 | return ERR_PTR(error); | ||
1895 | } | ||
1896 | |||
1897 | SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) | ||
1898 | { | ||
1899 | struct swap_info_struct *p; | ||
1900 | char *name = NULL; | ||
1901 | struct block_device *bdev = NULL; | ||
1902 | struct file *swap_file = NULL; | ||
1903 | struct address_space *mapping; | ||
1904 | int i, prev; | ||
1905 | int error; | ||
1906 | union swap_header *swap_header; | ||
1907 | unsigned int nr_good_pages; | ||
1908 | int nr_extents = 0; | ||
1909 | sector_t span; | ||
1910 | unsigned long maxpages; | ||
1911 | unsigned long swapfilepages; | ||
1912 | unsigned char *swap_map = NULL; | ||
1913 | struct page *page = NULL; | ||
1914 | struct inode *inode = NULL; | ||
1915 | int did_down = 0; | ||
1916 | |||
1917 | if (!capable(CAP_SYS_ADMIN)) | ||
1918 | return -EPERM; | ||
1919 | |||
1920 | p = alloc_swap_info(); | ||
1921 | if (IS_ERR(p)) { | ||
1922 | error = PTR_ERR(p); | ||
1923 | goto out; | ||
1924 | } | ||
1925 | |||
1909 | name = getname(specialfile); | 1926 | name = getname(specialfile); |
1910 | error = PTR_ERR(name); | 1927 | error = PTR_ERR(name); |
1911 | if (IS_ERR(name)) { | 1928 | if (IS_ERR(name)) { |