[GFS2] Patch to remove stats gathering from GFS2
[linux-2.6.git] / fs / gfs2 / ops_vm.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
4  *
5  * This copyrighted material is made available to anyone wishing to use,
6  * modify, copy, or redistribute it subject to the terms and conditions
7  * of the GNU General Public License v.2.
8  */
9
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/mm.h>
16 #include <linux/pagemap.h>
17 #include <asm/semaphore.h>
18
19 #include "gfs2.h"
20 #include "bmap.h"
21 #include "glock.h"
22 #include "inode.h"
23 #include "ops_vm.h"
24 #include "page.h"
25 #include "quota.h"
26 #include "rgrp.h"
27 #include "trans.h"
28
29 static void pfault_be_greedy(struct gfs2_inode *ip)
30 {
31         unsigned int time;
32
33         spin_lock(&ip->i_spin);
34         time = ip->i_greedy;
35         ip->i_last_pfault = jiffies;
36         spin_unlock(&ip->i_spin);
37
38         gfs2_inode_hold(ip);
39         if (gfs2_glock_be_greedy(ip->i_gl, time))
40                 gfs2_inode_put(ip);
41 }
42
43 static struct page *gfs2_private_nopage(struct vm_area_struct *area,
44                                         unsigned long address, int *type)
45 {
46         struct gfs2_inode *ip = get_v2ip(area->vm_file->f_mapping->host);
47         struct gfs2_holder i_gh;
48         struct page *result;
49         int error;
50
51         error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
52         if (error)
53                 return NULL;
54
55         set_bit(GIF_PAGED, &ip->i_flags);
56
57         result = filemap_nopage(area, address, type);
58
59         if (result && result != NOPAGE_OOM)
60                 pfault_be_greedy(ip);
61
62         gfs2_glock_dq_uninit(&i_gh);
63
64         return result;
65 }
66
67 static int alloc_page_backing(struct gfs2_inode *ip, struct page *page)
68 {
69         struct gfs2_sbd *sdp = ip->i_sbd;
70         unsigned long index = page->index;
71         uint64_t lblock = index << (PAGE_CACHE_SHIFT - sdp->sd_sb.sb_bsize_shift);
72         unsigned int blocks = PAGE_CACHE_SIZE >> sdp->sd_sb.sb_bsize_shift;
73         struct gfs2_alloc *al;
74         unsigned int data_blocks, ind_blocks;
75         unsigned int x;
76         int error;
77
78         al = gfs2_alloc_get(ip);
79
80         error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
81         if (error)
82                 goto out;
83
84         error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid);
85         if (error)
86                 goto out_gunlock_q;
87
88         gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE,
89                               &data_blocks, &ind_blocks);
90
91         al->al_requested = data_blocks + ind_blocks;
92
93         error = gfs2_inplace_reserve(ip);
94         if (error)
95                 goto out_gunlock_q;
96
97         error = gfs2_trans_begin(sdp,
98                                  al->al_rgd->rd_ri.ri_length +
99                                  ind_blocks + RES_DINODE +
100                                  RES_STATFS + RES_QUOTA, 0);
101         if (error)
102                 goto out_ipres;
103
104         if (gfs2_is_stuffed(ip)) {
105                 error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, NULL);
106                 if (error)
107                         goto out_trans;
108         }
109
110         for (x = 0; x < blocks; ) {
111                 uint64_t dblock;
112                 unsigned int extlen;
113                 int new = 1;
114
115                 error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen);
116                 if (error)
117                         goto out_trans;
118
119                 lblock += extlen;
120                 x += extlen;
121         }
122
123         gfs2_assert_warn(sdp, al->al_alloced);
124
125  out_trans:
126         gfs2_trans_end(sdp);
127
128  out_ipres:
129         gfs2_inplace_release(ip);
130
131  out_gunlock_q:
132         gfs2_quota_unlock(ip);
133
134  out:
135         gfs2_alloc_put(ip);
136
137         return error;
138 }
139
140 static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area,
141                                            unsigned long address, int *type)
142 {
143         struct gfs2_inode *ip = get_v2ip(area->vm_file->f_mapping->host);
144         struct gfs2_holder i_gh;
145         struct page *result = NULL;
146         unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) + area->vm_pgoff;
147         int alloc_required;
148         int error;
149
150         error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
151         if (error)
152                 return NULL;
153
154         set_bit(GIF_PAGED, &ip->i_flags);
155         set_bit(GIF_SW_PAGED, &ip->i_flags);
156
157         error = gfs2_write_alloc_required(ip,
158                                           (uint64_t)index << PAGE_CACHE_SHIFT,
159                                           PAGE_CACHE_SIZE, &alloc_required);
160         if (error)
161                 goto out;
162
163         result = filemap_nopage(area, address, type);
164         if (!result || result == NOPAGE_OOM)
165                 goto out;
166
167         if (alloc_required) {
168                 error = alloc_page_backing(ip, result);
169                 if (error) {
170                         page_cache_release(result);
171                         result = NULL;
172                         goto out;
173                 }
174                 set_page_dirty(result);
175         }
176
177         pfault_be_greedy(ip);
178
179  out:
180         gfs2_glock_dq_uninit(&i_gh);
181
182         return result;
183 }
184
185 struct vm_operations_struct gfs2_vm_ops_private = {
186         .nopage = gfs2_private_nopage,
187 };
188
189 struct vm_operations_struct gfs2_vm_ops_sharewrite = {
190         .nopage = gfs2_sharewrite_nopage,
191 };
192