2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
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 version 2.
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>
16 #include <linux/pagemap.h>
17 #include <linux/gfs2_ondisk.h>
18 #include <linux/lm_interface.h>
31 static struct page
*gfs2_private_nopage(struct vm_area_struct
*area
,
32 unsigned long address
, int *type
)
34 struct gfs2_inode
*ip
= GFS2_I(area
->vm_file
->f_mapping
->host
);
36 set_bit(GIF_PAGED
, &ip
->i_flags
);
37 return filemap_nopage(area
, address
, type
);
40 static int alloc_page_backing(struct gfs2_inode
*ip
, struct page
*page
)
42 struct gfs2_sbd
*sdp
= GFS2_SB(&ip
->i_inode
);
43 unsigned long index
= page
->index
;
44 u64 lblock
= index
<< (PAGE_CACHE_SHIFT
-
45 sdp
->sd_sb
.sb_bsize_shift
);
46 unsigned int blocks
= PAGE_CACHE_SIZE
>> sdp
->sd_sb
.sb_bsize_shift
;
47 struct gfs2_alloc
*al
;
48 unsigned int data_blocks
, ind_blocks
;
52 al
= gfs2_alloc_get(ip
);
54 error
= gfs2_quota_lock(ip
, NO_QUOTA_CHANGE
, NO_QUOTA_CHANGE
);
58 error
= gfs2_quota_check(ip
, ip
->i_inode
.i_uid
, ip
->i_inode
.i_gid
);
62 gfs2_write_calc_reserv(ip
, PAGE_CACHE_SIZE
, &data_blocks
, &ind_blocks
);
64 al
->al_requested
= data_blocks
+ ind_blocks
;
66 error
= gfs2_inplace_reserve(ip
);
70 error
= gfs2_trans_begin(sdp
, al
->al_rgd
->rd_ri
.ri_length
+
71 ind_blocks
+ RES_DINODE
+
72 RES_STATFS
+ RES_QUOTA
, 0);
76 if (gfs2_is_stuffed(ip
)) {
77 error
= gfs2_unstuff_dinode(ip
, NULL
);
82 for (x
= 0; x
< blocks
; ) {
87 error
= gfs2_extent_map(&ip
->i_inode
, lblock
, &new, &dblock
, &extlen
);
95 gfs2_assert_warn(sdp
, al
->al_alloced
);
100 gfs2_inplace_release(ip
);
102 gfs2_quota_unlock(ip
);
108 static struct page
*gfs2_sharewrite_nopage(struct vm_area_struct
*area
,
109 unsigned long address
, int *type
)
111 struct file
*file
= area
->vm_file
;
112 struct gfs2_file
*gf
= file
->private_data
;
113 struct gfs2_inode
*ip
= GFS2_I(file
->f_mapping
->host
);
114 struct gfs2_holder i_gh
;
115 struct page
*result
= NULL
;
116 unsigned long index
= ((address
- area
->vm_start
) >> PAGE_CACHE_SHIFT
) +
121 error
= gfs2_glock_nq_init(ip
->i_gl
, LM_ST_EXCLUSIVE
, 0, &i_gh
);
125 set_bit(GIF_PAGED
, &ip
->i_flags
);
126 set_bit(GIF_SW_PAGED
, &ip
->i_flags
);
128 error
= gfs2_write_alloc_required(ip
, (u64
)index
<< PAGE_CACHE_SHIFT
,
129 PAGE_CACHE_SIZE
, &alloc_required
);
133 set_bit(GFF_EXLOCK
, &gf
->f_flags
);
134 result
= filemap_nopage(area
, address
, type
);
135 clear_bit(GFF_EXLOCK
, &gf
->f_flags
);
136 if (!result
|| result
== NOPAGE_OOM
)
139 if (alloc_required
) {
140 error
= alloc_page_backing(ip
, result
);
142 page_cache_release(result
);
146 set_page_dirty(result
);
150 gfs2_glock_dq_uninit(&i_gh
);
155 struct vm_operations_struct gfs2_vm_ops_private
= {
156 .nopage
= gfs2_private_nopage
,
159 struct vm_operations_struct gfs2_vm_ops_sharewrite
= {
160 .nopage
= gfs2_sharewrite_nopage
,