]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - fs/hugetlbfs/inode.c
Merge omap tree
[mv-sheeva.git] / fs / hugetlbfs / inode.c
index b351952899453be64165ba7315e5f59bd0c851ac..6449cb697967d28818016b9ee4fbbc7519202203 100644 (file)
@@ -34,8 +34,8 @@
 #define HUGETLBFS_MAGIC        0x958458f6
 
 static struct super_operations hugetlbfs_ops;
-static struct address_space_operations hugetlbfs_aops;
-struct file_operations hugetlbfs_file_operations;
+static const struct address_space_operations hugetlbfs_aops;
+const struct file_operations hugetlbfs_file_operations;
 static struct inode_operations hugetlbfs_dir_inode_operations;
 static struct inode_operations hugetlbfs_inode_operations;
 
@@ -56,48 +56,9 @@ static void huge_pagevec_release(struct pagevec *pvec)
        pagevec_reinit(pvec);
 }
 
-/*
- * huge_pages_needed tries to determine the number of new huge pages that
- * will be required to fully populate this VMA.  This will be equal to
- * the size of the VMA in huge pages minus the number of huge pages
- * (covered by this VMA) that are found in the page cache.
- *
- * Result is in bytes to be compatible with is_hugepage_mem_enough()
- */
-static unsigned long
-huge_pages_needed(struct address_space *mapping, struct vm_area_struct *vma)
-{
-       int i;
-       struct pagevec pvec;
-       unsigned long start = vma->vm_start;
-       unsigned long end = vma->vm_end;
-       unsigned long hugepages = (end - start) >> HPAGE_SHIFT;
-       pgoff_t next = vma->vm_pgoff >> (HPAGE_SHIFT - PAGE_SHIFT);
-       pgoff_t endpg = next + hugepages;
-
-       pagevec_init(&pvec, 0);
-       while (next < endpg) {
-               if (!pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE))
-                       break;
-               for (i = 0; i < pagevec_count(&pvec); i++) {
-                       struct page *page = pvec.pages[i];
-                       if (page->index > next)
-                               next = page->index;
-                       if (page->index >= endpg)
-                               break;
-                       next++;
-                       hugepages--;
-               }
-               huge_pagevec_release(&pvec);
-       }
-       return hugepages << HPAGE_SHIFT;
-}
-
 static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
 {
        struct inode *inode = file->f_dentry->d_inode;
-       struct address_space *mapping = inode->i_mapping;
-       unsigned long bytes;
        loff_t len, vma_len;
        int ret;
 
@@ -113,10 +74,6 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
        if (vma->vm_end - vma->vm_start < HPAGE_SIZE)
                return -EINVAL;
 
-       bytes = huge_pages_needed(mapping, vma);
-       if (!is_hugepage_mem_enough(bytes))
-               return -ENOMEM;
-
        vma_len = (loff_t)(vma->vm_end - vma->vm_start);
 
        mutex_lock(&inode->i_mutex);
@@ -129,6 +86,11 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
        if (!(vma->vm_flags & VM_WRITE) && len > inode->i_size)
                goto out;
 
+       if (vma->vm_flags & VM_MAYSHARE &&
+           hugetlb_reserve_pages(inode, vma->vm_pgoff >> (HPAGE_SHIFT-PAGE_SHIFT),
+                                 len >> HPAGE_SHIFT))
+               goto out;
+
        ret = 0;
        hugetlb_prefault_arch_hook(vma->vm_mm);
        if (inode->i_size < len)
@@ -227,12 +189,13 @@ static void truncate_huge_page(struct page *page)
        put_page(page);
 }
 
-static void truncate_hugepages(struct address_space *mapping, loff_t lstart)
+static void truncate_hugepages(struct inode *inode, loff_t lstart)
 {
+       struct address_space *mapping = &inode->i_data;
        const pgoff_t start = lstart >> HPAGE_SHIFT;
        struct pagevec pvec;
        pgoff_t next;
-       int i;
+       int i, freed = 0;
 
        pagevec_init(&pvec, 0);
        next = start;
@@ -254,16 +217,17 @@ static void truncate_hugepages(struct address_space *mapping, loff_t lstart)
                        truncate_huge_page(page);
                        unlock_page(page);
                        hugetlb_put_quota(mapping);
+                       freed++;
                }
                huge_pagevec_release(&pvec);
        }
        BUG_ON(!lstart && mapping->nrpages);
+       hugetlb_unreserve_pages(inode, start, freed);
 }
 
 static void hugetlbfs_delete_inode(struct inode *inode)
 {
-       if (inode->i_data.nrpages)
-               truncate_hugepages(&inode->i_data, 0);
+       truncate_hugepages(inode, 0);
        clear_inode(inode);
 }
 
@@ -296,8 +260,7 @@ static void hugetlbfs_forget_inode(struct inode *inode)
        inode->i_state |= I_FREEING;
        inodes_stat.nr_inodes--;
        spin_unlock(&inode_lock);
-       if (inode->i_data.nrpages)
-               truncate_hugepages(&inode->i_data, 0);
+       truncate_hugepages(inode, 0);
        clear_inode(inode);
        destroy_inode(inode);
 }
@@ -356,7 +319,7 @@ static int hugetlb_vmtruncate(struct inode *inode, loff_t offset)
        if (!prio_tree_empty(&mapping->i_mmap))
                hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff);
        spin_unlock(&mapping->i_mmap_lock);
-       truncate_hugepages(mapping, offset);
+       truncate_hugepages(inode, offset);
        return 0;
 }
 
@@ -401,6 +364,7 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb, uid_t uid,
                inode->i_mapping->a_ops = &hugetlbfs_aops;
                inode->i_mapping->backing_dev_info =&hugetlbfs_backing_dev_info;
                inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+               INIT_LIST_HEAD(&inode->i_mapping->private_list);
                info = HUGETLBFS_I(inode);
                mpol_shared_policy_init(&info->policy, MPOL_DEFAULT, NULL);
                switch (mode & S_IFMT) {
@@ -502,9 +466,9 @@ static int hugetlbfs_set_page_dirty(struct page *page)
        return 0;
 }
 
-static int hugetlbfs_statfs(struct super_block *sb, struct kstatfs *buf)
+static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
-       struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(sb);
+       struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(dentry->d_sb);
 
        buf->f_type = HUGETLBFS_MAGIC;
        buf->f_bsize = HPAGE_SIZE;
@@ -583,7 +547,7 @@ static void hugetlbfs_destroy_inode(struct inode *inode)
        kmem_cache_free(hugetlbfs_inode_cachep, HUGETLBFS_I(inode));
 }
 
-static struct address_space_operations hugetlbfs_aops = {
+static const struct address_space_operations hugetlbfs_aops = {
        .readpage       = hugetlbfs_readpage,
        .prepare_write  = hugetlbfs_prepare_write,
        .commit_write   = hugetlbfs_commit_write,
@@ -600,7 +564,7 @@ static void init_once(void *foo, kmem_cache_t *cachep, unsigned long flags)
                inode_init_once(&ei->vfs_inode);
 }
 
-struct file_operations hugetlbfs_file_operations = {
+const struct file_operations hugetlbfs_file_operations = {
        .mmap                   = hugetlbfs_file_mmap,
        .fsync                  = simple_sync_file,
        .get_unmapped_area      = hugetlb_get_unmapped_area,
@@ -757,10 +721,10 @@ void hugetlb_put_quota(struct address_space *mapping)
        }
 }
 
-static struct super_block *hugetlbfs_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *data)
+static int hugetlbfs_get_sb(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *data, struct vfsmount *mnt)
 {
-       return get_sb_nodev(fs_type, flags, data, hugetlbfs_fill_super);
+       return get_sb_nodev(fs_type, flags, data, hugetlbfs_fill_super, mnt);
 }
 
 static struct file_system_type hugetlbfs_fs_type = {
@@ -771,21 +735,6 @@ static struct file_system_type hugetlbfs_fs_type = {
 
 static struct vfsmount *hugetlbfs_vfsmount;
 
-/*
- * Return the next identifier for a shm file
- */
-static unsigned long hugetlbfs_counter(void)
-{
-       static DEFINE_SPINLOCK(lock);
-       static unsigned long counter;
-       unsigned long ret;
-
-       spin_lock(&lock);
-       ret = ++counter;
-       spin_unlock(&lock);
-       return ret;
-}
-
 static int can_do_hugetlb_shm(void)
 {
        return likely(capable(CAP_IPC_LOCK) ||
@@ -801,18 +750,16 @@ struct file *hugetlb_zero_setup(size_t size)
        struct dentry *dentry, *root;
        struct qstr quick_string;
        char buf[16];
+       static atomic_t counter;
 
        if (!can_do_hugetlb_shm())
                return ERR_PTR(-EPERM);
 
-       if (!is_hugepage_mem_enough(size))
-               return ERR_PTR(-ENOMEM);
-
        if (!user_shm_lock(size, current->user))
                return ERR_PTR(-ENOMEM);
 
        root = hugetlbfs_vfsmount->mnt_root;
-       snprintf(buf, 16, "%lu", hugetlbfs_counter());
+       snprintf(buf, 16, "%u", atomic_inc_return(&counter));
        quick_string.name = buf;
        quick_string.len = strlen(quick_string.name);
        quick_string.hash = 0;
@@ -831,6 +778,10 @@ struct file *hugetlb_zero_setup(size_t size)
        if (!inode)
                goto out_file;
 
+       error = -ENOMEM;
+       if (hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT))
+               goto out_inode;
+
        d_instantiate(dentry, inode);
        inode->i_size = size;
        inode->i_nlink = 0;
@@ -841,6 +792,8 @@ struct file *hugetlb_zero_setup(size_t size)
        file->f_mode = FMODE_WRITE | FMODE_READ;
        return file;
 
+out_inode:
+       iput(inode);
 out_file:
        put_filp(file);
 out_dentry: