Commit 429479f031322a0cc5c921ffb2321a51718dc875
Committed by
Al Viro
1 parent
bfe881255c
Exists in
master
and in
7 other branches
vfs: Make __fsync_super() a static function (version 4)
__fsync_super() does the same thing as fsync_super(). So change the only caller to use fsync_super() and make __fsync_super() static. This removes unnecessarily duplicated call to sync_blockdev() and prepares ground for the changes to __fsync_super() in the following patches. Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 3 changed files with 4 additions and 6 deletions Inline Diff
fs/block_dev.c
1 | /* | 1 | /* |
2 | * linux/fs/block_dev.c | 2 | * linux/fs/block_dev.c |
3 | * | 3 | * |
4 | * Copyright (C) 1991, 1992 Linus Torvalds | 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
5 | * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE | 5 | * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/init.h> | 8 | #include <linux/init.h> |
9 | #include <linux/mm.h> | 9 | #include <linux/mm.h> |
10 | #include <linux/fcntl.h> | 10 | #include <linux/fcntl.h> |
11 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
12 | #include <linux/kmod.h> | 12 | #include <linux/kmod.h> |
13 | #include <linux/major.h> | 13 | #include <linux/major.h> |
14 | #include <linux/smp_lock.h> | 14 | #include <linux/smp_lock.h> |
15 | #include <linux/device_cgroup.h> | 15 | #include <linux/device_cgroup.h> |
16 | #include <linux/highmem.h> | 16 | #include <linux/highmem.h> |
17 | #include <linux/blkdev.h> | 17 | #include <linux/blkdev.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/blkpg.h> | 19 | #include <linux/blkpg.h> |
20 | #include <linux/buffer_head.h> | 20 | #include <linux/buffer_head.h> |
21 | #include <linux/pagevec.h> | 21 | #include <linux/pagevec.h> |
22 | #include <linux/writeback.h> | 22 | #include <linux/writeback.h> |
23 | #include <linux/mpage.h> | 23 | #include <linux/mpage.h> |
24 | #include <linux/mount.h> | 24 | #include <linux/mount.h> |
25 | #include <linux/uio.h> | 25 | #include <linux/uio.h> |
26 | #include <linux/namei.h> | 26 | #include <linux/namei.h> |
27 | #include <linux/log2.h> | 27 | #include <linux/log2.h> |
28 | #include <linux/kmemleak.h> | 28 | #include <linux/kmemleak.h> |
29 | #include <asm/uaccess.h> | 29 | #include <asm/uaccess.h> |
30 | #include "internal.h" | 30 | #include "internal.h" |
31 | 31 | ||
32 | struct bdev_inode { | 32 | struct bdev_inode { |
33 | struct block_device bdev; | 33 | struct block_device bdev; |
34 | struct inode vfs_inode; | 34 | struct inode vfs_inode; |
35 | }; | 35 | }; |
36 | 36 | ||
37 | static const struct address_space_operations def_blk_aops; | 37 | static const struct address_space_operations def_blk_aops; |
38 | 38 | ||
39 | static inline struct bdev_inode *BDEV_I(struct inode *inode) | 39 | static inline struct bdev_inode *BDEV_I(struct inode *inode) |
40 | { | 40 | { |
41 | return container_of(inode, struct bdev_inode, vfs_inode); | 41 | return container_of(inode, struct bdev_inode, vfs_inode); |
42 | } | 42 | } |
43 | 43 | ||
44 | inline struct block_device *I_BDEV(struct inode *inode) | 44 | inline struct block_device *I_BDEV(struct inode *inode) |
45 | { | 45 | { |
46 | return &BDEV_I(inode)->bdev; | 46 | return &BDEV_I(inode)->bdev; |
47 | } | 47 | } |
48 | 48 | ||
49 | EXPORT_SYMBOL(I_BDEV); | 49 | EXPORT_SYMBOL(I_BDEV); |
50 | 50 | ||
51 | static sector_t max_block(struct block_device *bdev) | 51 | static sector_t max_block(struct block_device *bdev) |
52 | { | 52 | { |
53 | sector_t retval = ~((sector_t)0); | 53 | sector_t retval = ~((sector_t)0); |
54 | loff_t sz = i_size_read(bdev->bd_inode); | 54 | loff_t sz = i_size_read(bdev->bd_inode); |
55 | 55 | ||
56 | if (sz) { | 56 | if (sz) { |
57 | unsigned int size = block_size(bdev); | 57 | unsigned int size = block_size(bdev); |
58 | unsigned int sizebits = blksize_bits(size); | 58 | unsigned int sizebits = blksize_bits(size); |
59 | retval = (sz >> sizebits); | 59 | retval = (sz >> sizebits); |
60 | } | 60 | } |
61 | return retval; | 61 | return retval; |
62 | } | 62 | } |
63 | 63 | ||
64 | /* Kill _all_ buffers and pagecache , dirty or not.. */ | 64 | /* Kill _all_ buffers and pagecache , dirty or not.. */ |
65 | static void kill_bdev(struct block_device *bdev) | 65 | static void kill_bdev(struct block_device *bdev) |
66 | { | 66 | { |
67 | if (bdev->bd_inode->i_mapping->nrpages == 0) | 67 | if (bdev->bd_inode->i_mapping->nrpages == 0) |
68 | return; | 68 | return; |
69 | invalidate_bh_lrus(); | 69 | invalidate_bh_lrus(); |
70 | truncate_inode_pages(bdev->bd_inode->i_mapping, 0); | 70 | truncate_inode_pages(bdev->bd_inode->i_mapping, 0); |
71 | } | 71 | } |
72 | 72 | ||
73 | int set_blocksize(struct block_device *bdev, int size) | 73 | int set_blocksize(struct block_device *bdev, int size) |
74 | { | 74 | { |
75 | /* Size must be a power of two, and between 512 and PAGE_SIZE */ | 75 | /* Size must be a power of two, and between 512 and PAGE_SIZE */ |
76 | if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size)) | 76 | if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size)) |
77 | return -EINVAL; | 77 | return -EINVAL; |
78 | 78 | ||
79 | /* Size cannot be smaller than the size supported by the device */ | 79 | /* Size cannot be smaller than the size supported by the device */ |
80 | if (size < bdev_logical_block_size(bdev)) | 80 | if (size < bdev_logical_block_size(bdev)) |
81 | return -EINVAL; | 81 | return -EINVAL; |
82 | 82 | ||
83 | /* Don't change the size if it is same as current */ | 83 | /* Don't change the size if it is same as current */ |
84 | if (bdev->bd_block_size != size) { | 84 | if (bdev->bd_block_size != size) { |
85 | sync_blockdev(bdev); | 85 | sync_blockdev(bdev); |
86 | bdev->bd_block_size = size; | 86 | bdev->bd_block_size = size; |
87 | bdev->bd_inode->i_blkbits = blksize_bits(size); | 87 | bdev->bd_inode->i_blkbits = blksize_bits(size); |
88 | kill_bdev(bdev); | 88 | kill_bdev(bdev); |
89 | } | 89 | } |
90 | return 0; | 90 | return 0; |
91 | } | 91 | } |
92 | 92 | ||
93 | EXPORT_SYMBOL(set_blocksize); | 93 | EXPORT_SYMBOL(set_blocksize); |
94 | 94 | ||
95 | int sb_set_blocksize(struct super_block *sb, int size) | 95 | int sb_set_blocksize(struct super_block *sb, int size) |
96 | { | 96 | { |
97 | if (set_blocksize(sb->s_bdev, size)) | 97 | if (set_blocksize(sb->s_bdev, size)) |
98 | return 0; | 98 | return 0; |
99 | /* If we get here, we know size is power of two | 99 | /* If we get here, we know size is power of two |
100 | * and it's value is between 512 and PAGE_SIZE */ | 100 | * and it's value is between 512 and PAGE_SIZE */ |
101 | sb->s_blocksize = size; | 101 | sb->s_blocksize = size; |
102 | sb->s_blocksize_bits = blksize_bits(size); | 102 | sb->s_blocksize_bits = blksize_bits(size); |
103 | return sb->s_blocksize; | 103 | return sb->s_blocksize; |
104 | } | 104 | } |
105 | 105 | ||
106 | EXPORT_SYMBOL(sb_set_blocksize); | 106 | EXPORT_SYMBOL(sb_set_blocksize); |
107 | 107 | ||
108 | int sb_min_blocksize(struct super_block *sb, int size) | 108 | int sb_min_blocksize(struct super_block *sb, int size) |
109 | { | 109 | { |
110 | int minsize = bdev_logical_block_size(sb->s_bdev); | 110 | int minsize = bdev_logical_block_size(sb->s_bdev); |
111 | if (size < minsize) | 111 | if (size < minsize) |
112 | size = minsize; | 112 | size = minsize; |
113 | return sb_set_blocksize(sb, size); | 113 | return sb_set_blocksize(sb, size); |
114 | } | 114 | } |
115 | 115 | ||
116 | EXPORT_SYMBOL(sb_min_blocksize); | 116 | EXPORT_SYMBOL(sb_min_blocksize); |
117 | 117 | ||
118 | static int | 118 | static int |
119 | blkdev_get_block(struct inode *inode, sector_t iblock, | 119 | blkdev_get_block(struct inode *inode, sector_t iblock, |
120 | struct buffer_head *bh, int create) | 120 | struct buffer_head *bh, int create) |
121 | { | 121 | { |
122 | if (iblock >= max_block(I_BDEV(inode))) { | 122 | if (iblock >= max_block(I_BDEV(inode))) { |
123 | if (create) | 123 | if (create) |
124 | return -EIO; | 124 | return -EIO; |
125 | 125 | ||
126 | /* | 126 | /* |
127 | * for reads, we're just trying to fill a partial page. | 127 | * for reads, we're just trying to fill a partial page. |
128 | * return a hole, they will have to call get_block again | 128 | * return a hole, they will have to call get_block again |
129 | * before they can fill it, and they will get -EIO at that | 129 | * before they can fill it, and they will get -EIO at that |
130 | * time | 130 | * time |
131 | */ | 131 | */ |
132 | return 0; | 132 | return 0; |
133 | } | 133 | } |
134 | bh->b_bdev = I_BDEV(inode); | 134 | bh->b_bdev = I_BDEV(inode); |
135 | bh->b_blocknr = iblock; | 135 | bh->b_blocknr = iblock; |
136 | set_buffer_mapped(bh); | 136 | set_buffer_mapped(bh); |
137 | return 0; | 137 | return 0; |
138 | } | 138 | } |
139 | 139 | ||
140 | static int | 140 | static int |
141 | blkdev_get_blocks(struct inode *inode, sector_t iblock, | 141 | blkdev_get_blocks(struct inode *inode, sector_t iblock, |
142 | struct buffer_head *bh, int create) | 142 | struct buffer_head *bh, int create) |
143 | { | 143 | { |
144 | sector_t end_block = max_block(I_BDEV(inode)); | 144 | sector_t end_block = max_block(I_BDEV(inode)); |
145 | unsigned long max_blocks = bh->b_size >> inode->i_blkbits; | 145 | unsigned long max_blocks = bh->b_size >> inode->i_blkbits; |
146 | 146 | ||
147 | if ((iblock + max_blocks) > end_block) { | 147 | if ((iblock + max_blocks) > end_block) { |
148 | max_blocks = end_block - iblock; | 148 | max_blocks = end_block - iblock; |
149 | if ((long)max_blocks <= 0) { | 149 | if ((long)max_blocks <= 0) { |
150 | if (create) | 150 | if (create) |
151 | return -EIO; /* write fully beyond EOF */ | 151 | return -EIO; /* write fully beyond EOF */ |
152 | /* | 152 | /* |
153 | * It is a read which is fully beyond EOF. We return | 153 | * It is a read which is fully beyond EOF. We return |
154 | * a !buffer_mapped buffer | 154 | * a !buffer_mapped buffer |
155 | */ | 155 | */ |
156 | max_blocks = 0; | 156 | max_blocks = 0; |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | bh->b_bdev = I_BDEV(inode); | 160 | bh->b_bdev = I_BDEV(inode); |
161 | bh->b_blocknr = iblock; | 161 | bh->b_blocknr = iblock; |
162 | bh->b_size = max_blocks << inode->i_blkbits; | 162 | bh->b_size = max_blocks << inode->i_blkbits; |
163 | if (max_blocks) | 163 | if (max_blocks) |
164 | set_buffer_mapped(bh); | 164 | set_buffer_mapped(bh); |
165 | return 0; | 165 | return 0; |
166 | } | 166 | } |
167 | 167 | ||
168 | static ssize_t | 168 | static ssize_t |
169 | blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | 169 | blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, |
170 | loff_t offset, unsigned long nr_segs) | 170 | loff_t offset, unsigned long nr_segs) |
171 | { | 171 | { |
172 | struct file *file = iocb->ki_filp; | 172 | struct file *file = iocb->ki_filp; |
173 | struct inode *inode = file->f_mapping->host; | 173 | struct inode *inode = file->f_mapping->host; |
174 | 174 | ||
175 | return blockdev_direct_IO_no_locking(rw, iocb, inode, I_BDEV(inode), | 175 | return blockdev_direct_IO_no_locking(rw, iocb, inode, I_BDEV(inode), |
176 | iov, offset, nr_segs, blkdev_get_blocks, NULL); | 176 | iov, offset, nr_segs, blkdev_get_blocks, NULL); |
177 | } | 177 | } |
178 | 178 | ||
179 | /* | 179 | /* |
180 | * Write out and wait upon all the dirty data associated with a block | 180 | * Write out and wait upon all the dirty data associated with a block |
181 | * device via its mapping. Does not take the superblock lock. | 181 | * device via its mapping. Does not take the superblock lock. |
182 | */ | 182 | */ |
183 | int sync_blockdev(struct block_device *bdev) | 183 | int sync_blockdev(struct block_device *bdev) |
184 | { | 184 | { |
185 | int ret = 0; | 185 | int ret = 0; |
186 | 186 | ||
187 | if (bdev) | 187 | if (bdev) |
188 | ret = filemap_write_and_wait(bdev->bd_inode->i_mapping); | 188 | ret = filemap_write_and_wait(bdev->bd_inode->i_mapping); |
189 | return ret; | 189 | return ret; |
190 | } | 190 | } |
191 | EXPORT_SYMBOL(sync_blockdev); | 191 | EXPORT_SYMBOL(sync_blockdev); |
192 | 192 | ||
193 | /* | 193 | /* |
194 | * Write out and wait upon all dirty data associated with this | 194 | * Write out and wait upon all dirty data associated with this |
195 | * device. Filesystem data as well as the underlying block | 195 | * device. Filesystem data as well as the underlying block |
196 | * device. Takes the superblock lock. | 196 | * device. Takes the superblock lock. |
197 | */ | 197 | */ |
198 | int fsync_bdev(struct block_device *bdev) | 198 | int fsync_bdev(struct block_device *bdev) |
199 | { | 199 | { |
200 | struct super_block *sb = get_super(bdev); | 200 | struct super_block *sb = get_super(bdev); |
201 | if (sb) { | 201 | if (sb) { |
202 | int res = fsync_super(sb); | 202 | int res = fsync_super(sb); |
203 | drop_super(sb); | 203 | drop_super(sb); |
204 | return res; | 204 | return res; |
205 | } | 205 | } |
206 | return sync_blockdev(bdev); | 206 | return sync_blockdev(bdev); |
207 | } | 207 | } |
208 | EXPORT_SYMBOL(fsync_bdev); | 208 | EXPORT_SYMBOL(fsync_bdev); |
209 | 209 | ||
210 | /** | 210 | /** |
211 | * freeze_bdev -- lock a filesystem and force it into a consistent state | 211 | * freeze_bdev -- lock a filesystem and force it into a consistent state |
212 | * @bdev: blockdevice to lock | 212 | * @bdev: blockdevice to lock |
213 | * | 213 | * |
214 | * This takes the block device bd_mount_sem to make sure no new mounts | 214 | * This takes the block device bd_mount_sem to make sure no new mounts |
215 | * happen on bdev until thaw_bdev() is called. | 215 | * happen on bdev until thaw_bdev() is called. |
216 | * If a superblock is found on this device, we take the s_umount semaphore | 216 | * If a superblock is found on this device, we take the s_umount semaphore |
217 | * on it to make sure nobody unmounts until the snapshot creation is done. | 217 | * on it to make sure nobody unmounts until the snapshot creation is done. |
218 | * The reference counter (bd_fsfreeze_count) guarantees that only the last | 218 | * The reference counter (bd_fsfreeze_count) guarantees that only the last |
219 | * unfreeze process can unfreeze the frozen filesystem actually when multiple | 219 | * unfreeze process can unfreeze the frozen filesystem actually when multiple |
220 | * freeze requests arrive simultaneously. It counts up in freeze_bdev() and | 220 | * freeze requests arrive simultaneously. It counts up in freeze_bdev() and |
221 | * count down in thaw_bdev(). When it becomes 0, thaw_bdev() will unfreeze | 221 | * count down in thaw_bdev(). When it becomes 0, thaw_bdev() will unfreeze |
222 | * actually. | 222 | * actually. |
223 | */ | 223 | */ |
224 | struct super_block *freeze_bdev(struct block_device *bdev) | 224 | struct super_block *freeze_bdev(struct block_device *bdev) |
225 | { | 225 | { |
226 | struct super_block *sb; | 226 | struct super_block *sb; |
227 | int error = 0; | 227 | int error = 0; |
228 | 228 | ||
229 | mutex_lock(&bdev->bd_fsfreeze_mutex); | 229 | mutex_lock(&bdev->bd_fsfreeze_mutex); |
230 | if (bdev->bd_fsfreeze_count > 0) { | 230 | if (bdev->bd_fsfreeze_count > 0) { |
231 | bdev->bd_fsfreeze_count++; | 231 | bdev->bd_fsfreeze_count++; |
232 | sb = get_super(bdev); | 232 | sb = get_super(bdev); |
233 | mutex_unlock(&bdev->bd_fsfreeze_mutex); | 233 | mutex_unlock(&bdev->bd_fsfreeze_mutex); |
234 | return sb; | 234 | return sb; |
235 | } | 235 | } |
236 | bdev->bd_fsfreeze_count++; | 236 | bdev->bd_fsfreeze_count++; |
237 | 237 | ||
238 | down(&bdev->bd_mount_sem); | 238 | down(&bdev->bd_mount_sem); |
239 | sb = get_super(bdev); | 239 | sb = get_super(bdev); |
240 | if (sb && !(sb->s_flags & MS_RDONLY)) { | 240 | if (sb && !(sb->s_flags & MS_RDONLY)) { |
241 | sb->s_frozen = SB_FREEZE_WRITE; | 241 | sb->s_frozen = SB_FREEZE_WRITE; |
242 | smp_wmb(); | 242 | smp_wmb(); |
243 | 243 | ||
244 | __fsync_super(sb); | 244 | fsync_super(sb); |
245 | 245 | ||
246 | sb->s_frozen = SB_FREEZE_TRANS; | 246 | sb->s_frozen = SB_FREEZE_TRANS; |
247 | smp_wmb(); | 247 | smp_wmb(); |
248 | 248 | ||
249 | sync_blockdev(sb->s_bdev); | 249 | sync_blockdev(sb->s_bdev); |
250 | 250 | ||
251 | if (sb->s_op->freeze_fs) { | 251 | if (sb->s_op->freeze_fs) { |
252 | error = sb->s_op->freeze_fs(sb); | 252 | error = sb->s_op->freeze_fs(sb); |
253 | if (error) { | 253 | if (error) { |
254 | printk(KERN_ERR | 254 | printk(KERN_ERR |
255 | "VFS:Filesystem freeze failed\n"); | 255 | "VFS:Filesystem freeze failed\n"); |
256 | sb->s_frozen = SB_UNFROZEN; | 256 | sb->s_frozen = SB_UNFROZEN; |
257 | drop_super(sb); | 257 | drop_super(sb); |
258 | up(&bdev->bd_mount_sem); | 258 | up(&bdev->bd_mount_sem); |
259 | bdev->bd_fsfreeze_count--; | 259 | bdev->bd_fsfreeze_count--; |
260 | mutex_unlock(&bdev->bd_fsfreeze_mutex); | 260 | mutex_unlock(&bdev->bd_fsfreeze_mutex); |
261 | return ERR_PTR(error); | 261 | return ERR_PTR(error); |
262 | } | 262 | } |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | sync_blockdev(bdev); | 266 | sync_blockdev(bdev); |
267 | mutex_unlock(&bdev->bd_fsfreeze_mutex); | 267 | mutex_unlock(&bdev->bd_fsfreeze_mutex); |
268 | 268 | ||
269 | return sb; /* thaw_bdev releases s->s_umount and bd_mount_sem */ | 269 | return sb; /* thaw_bdev releases s->s_umount and bd_mount_sem */ |
270 | } | 270 | } |
271 | EXPORT_SYMBOL(freeze_bdev); | 271 | EXPORT_SYMBOL(freeze_bdev); |
272 | 272 | ||
273 | /** | 273 | /** |
274 | * thaw_bdev -- unlock filesystem | 274 | * thaw_bdev -- unlock filesystem |
275 | * @bdev: blockdevice to unlock | 275 | * @bdev: blockdevice to unlock |
276 | * @sb: associated superblock | 276 | * @sb: associated superblock |
277 | * | 277 | * |
278 | * Unlocks the filesystem and marks it writeable again after freeze_bdev(). | 278 | * Unlocks the filesystem and marks it writeable again after freeze_bdev(). |
279 | */ | 279 | */ |
280 | int thaw_bdev(struct block_device *bdev, struct super_block *sb) | 280 | int thaw_bdev(struct block_device *bdev, struct super_block *sb) |
281 | { | 281 | { |
282 | int error = 0; | 282 | int error = 0; |
283 | 283 | ||
284 | mutex_lock(&bdev->bd_fsfreeze_mutex); | 284 | mutex_lock(&bdev->bd_fsfreeze_mutex); |
285 | if (!bdev->bd_fsfreeze_count) { | 285 | if (!bdev->bd_fsfreeze_count) { |
286 | mutex_unlock(&bdev->bd_fsfreeze_mutex); | 286 | mutex_unlock(&bdev->bd_fsfreeze_mutex); |
287 | return -EINVAL; | 287 | return -EINVAL; |
288 | } | 288 | } |
289 | 289 | ||
290 | bdev->bd_fsfreeze_count--; | 290 | bdev->bd_fsfreeze_count--; |
291 | if (bdev->bd_fsfreeze_count > 0) { | 291 | if (bdev->bd_fsfreeze_count > 0) { |
292 | if (sb) | 292 | if (sb) |
293 | drop_super(sb); | 293 | drop_super(sb); |
294 | mutex_unlock(&bdev->bd_fsfreeze_mutex); | 294 | mutex_unlock(&bdev->bd_fsfreeze_mutex); |
295 | return 0; | 295 | return 0; |
296 | } | 296 | } |
297 | 297 | ||
298 | if (sb) { | 298 | if (sb) { |
299 | BUG_ON(sb->s_bdev != bdev); | 299 | BUG_ON(sb->s_bdev != bdev); |
300 | if (!(sb->s_flags & MS_RDONLY)) { | 300 | if (!(sb->s_flags & MS_RDONLY)) { |
301 | if (sb->s_op->unfreeze_fs) { | 301 | if (sb->s_op->unfreeze_fs) { |
302 | error = sb->s_op->unfreeze_fs(sb); | 302 | error = sb->s_op->unfreeze_fs(sb); |
303 | if (error) { | 303 | if (error) { |
304 | printk(KERN_ERR | 304 | printk(KERN_ERR |
305 | "VFS:Filesystem thaw failed\n"); | 305 | "VFS:Filesystem thaw failed\n"); |
306 | sb->s_frozen = SB_FREEZE_TRANS; | 306 | sb->s_frozen = SB_FREEZE_TRANS; |
307 | bdev->bd_fsfreeze_count++; | 307 | bdev->bd_fsfreeze_count++; |
308 | mutex_unlock(&bdev->bd_fsfreeze_mutex); | 308 | mutex_unlock(&bdev->bd_fsfreeze_mutex); |
309 | return error; | 309 | return error; |
310 | } | 310 | } |
311 | } | 311 | } |
312 | sb->s_frozen = SB_UNFROZEN; | 312 | sb->s_frozen = SB_UNFROZEN; |
313 | smp_wmb(); | 313 | smp_wmb(); |
314 | wake_up(&sb->s_wait_unfrozen); | 314 | wake_up(&sb->s_wait_unfrozen); |
315 | } | 315 | } |
316 | drop_super(sb); | 316 | drop_super(sb); |
317 | } | 317 | } |
318 | 318 | ||
319 | up(&bdev->bd_mount_sem); | 319 | up(&bdev->bd_mount_sem); |
320 | mutex_unlock(&bdev->bd_fsfreeze_mutex); | 320 | mutex_unlock(&bdev->bd_fsfreeze_mutex); |
321 | return 0; | 321 | return 0; |
322 | } | 322 | } |
323 | EXPORT_SYMBOL(thaw_bdev); | 323 | EXPORT_SYMBOL(thaw_bdev); |
324 | 324 | ||
325 | static int blkdev_writepage(struct page *page, struct writeback_control *wbc) | 325 | static int blkdev_writepage(struct page *page, struct writeback_control *wbc) |
326 | { | 326 | { |
327 | return block_write_full_page(page, blkdev_get_block, wbc); | 327 | return block_write_full_page(page, blkdev_get_block, wbc); |
328 | } | 328 | } |
329 | 329 | ||
330 | static int blkdev_readpage(struct file * file, struct page * page) | 330 | static int blkdev_readpage(struct file * file, struct page * page) |
331 | { | 331 | { |
332 | return block_read_full_page(page, blkdev_get_block); | 332 | return block_read_full_page(page, blkdev_get_block); |
333 | } | 333 | } |
334 | 334 | ||
335 | static int blkdev_write_begin(struct file *file, struct address_space *mapping, | 335 | static int blkdev_write_begin(struct file *file, struct address_space *mapping, |
336 | loff_t pos, unsigned len, unsigned flags, | 336 | loff_t pos, unsigned len, unsigned flags, |
337 | struct page **pagep, void **fsdata) | 337 | struct page **pagep, void **fsdata) |
338 | { | 338 | { |
339 | *pagep = NULL; | 339 | *pagep = NULL; |
340 | return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, | 340 | return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, |
341 | blkdev_get_block); | 341 | blkdev_get_block); |
342 | } | 342 | } |
343 | 343 | ||
344 | static int blkdev_write_end(struct file *file, struct address_space *mapping, | 344 | static int blkdev_write_end(struct file *file, struct address_space *mapping, |
345 | loff_t pos, unsigned len, unsigned copied, | 345 | loff_t pos, unsigned len, unsigned copied, |
346 | struct page *page, void *fsdata) | 346 | struct page *page, void *fsdata) |
347 | { | 347 | { |
348 | int ret; | 348 | int ret; |
349 | ret = block_write_end(file, mapping, pos, len, copied, page, fsdata); | 349 | ret = block_write_end(file, mapping, pos, len, copied, page, fsdata); |
350 | 350 | ||
351 | unlock_page(page); | 351 | unlock_page(page); |
352 | page_cache_release(page); | 352 | page_cache_release(page); |
353 | 353 | ||
354 | return ret; | 354 | return ret; |
355 | } | 355 | } |
356 | 356 | ||
357 | /* | 357 | /* |
358 | * private llseek: | 358 | * private llseek: |
359 | * for a block special file file->f_path.dentry->d_inode->i_size is zero | 359 | * for a block special file file->f_path.dentry->d_inode->i_size is zero |
360 | * so we compute the size by hand (just as in block_read/write above) | 360 | * so we compute the size by hand (just as in block_read/write above) |
361 | */ | 361 | */ |
362 | static loff_t block_llseek(struct file *file, loff_t offset, int origin) | 362 | static loff_t block_llseek(struct file *file, loff_t offset, int origin) |
363 | { | 363 | { |
364 | struct inode *bd_inode = file->f_mapping->host; | 364 | struct inode *bd_inode = file->f_mapping->host; |
365 | loff_t size; | 365 | loff_t size; |
366 | loff_t retval; | 366 | loff_t retval; |
367 | 367 | ||
368 | mutex_lock(&bd_inode->i_mutex); | 368 | mutex_lock(&bd_inode->i_mutex); |
369 | size = i_size_read(bd_inode); | 369 | size = i_size_read(bd_inode); |
370 | 370 | ||
371 | switch (origin) { | 371 | switch (origin) { |
372 | case 2: | 372 | case 2: |
373 | offset += size; | 373 | offset += size; |
374 | break; | 374 | break; |
375 | case 1: | 375 | case 1: |
376 | offset += file->f_pos; | 376 | offset += file->f_pos; |
377 | } | 377 | } |
378 | retval = -EINVAL; | 378 | retval = -EINVAL; |
379 | if (offset >= 0 && offset <= size) { | 379 | if (offset >= 0 && offset <= size) { |
380 | if (offset != file->f_pos) { | 380 | if (offset != file->f_pos) { |
381 | file->f_pos = offset; | 381 | file->f_pos = offset; |
382 | } | 382 | } |
383 | retval = offset; | 383 | retval = offset; |
384 | } | 384 | } |
385 | mutex_unlock(&bd_inode->i_mutex); | 385 | mutex_unlock(&bd_inode->i_mutex); |
386 | return retval; | 386 | return retval; |
387 | } | 387 | } |
388 | 388 | ||
389 | /* | 389 | /* |
390 | * Filp is never NULL; the only case when ->fsync() is called with | 390 | * Filp is never NULL; the only case when ->fsync() is called with |
391 | * NULL first argument is nfsd_sync_dir() and that's not a directory. | 391 | * NULL first argument is nfsd_sync_dir() and that's not a directory. |
392 | */ | 392 | */ |
393 | 393 | ||
394 | static int block_fsync(struct file *filp, struct dentry *dentry, int datasync) | 394 | static int block_fsync(struct file *filp, struct dentry *dentry, int datasync) |
395 | { | 395 | { |
396 | return sync_blockdev(I_BDEV(filp->f_mapping->host)); | 396 | return sync_blockdev(I_BDEV(filp->f_mapping->host)); |
397 | } | 397 | } |
398 | 398 | ||
399 | /* | 399 | /* |
400 | * pseudo-fs | 400 | * pseudo-fs |
401 | */ | 401 | */ |
402 | 402 | ||
403 | static __cacheline_aligned_in_smp DEFINE_SPINLOCK(bdev_lock); | 403 | static __cacheline_aligned_in_smp DEFINE_SPINLOCK(bdev_lock); |
404 | static struct kmem_cache * bdev_cachep __read_mostly; | 404 | static struct kmem_cache * bdev_cachep __read_mostly; |
405 | 405 | ||
406 | static struct inode *bdev_alloc_inode(struct super_block *sb) | 406 | static struct inode *bdev_alloc_inode(struct super_block *sb) |
407 | { | 407 | { |
408 | struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL); | 408 | struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL); |
409 | if (!ei) | 409 | if (!ei) |
410 | return NULL; | 410 | return NULL; |
411 | return &ei->vfs_inode; | 411 | return &ei->vfs_inode; |
412 | } | 412 | } |
413 | 413 | ||
414 | static void bdev_destroy_inode(struct inode *inode) | 414 | static void bdev_destroy_inode(struct inode *inode) |
415 | { | 415 | { |
416 | struct bdev_inode *bdi = BDEV_I(inode); | 416 | struct bdev_inode *bdi = BDEV_I(inode); |
417 | 417 | ||
418 | bdi->bdev.bd_inode_backing_dev_info = NULL; | 418 | bdi->bdev.bd_inode_backing_dev_info = NULL; |
419 | kmem_cache_free(bdev_cachep, bdi); | 419 | kmem_cache_free(bdev_cachep, bdi); |
420 | } | 420 | } |
421 | 421 | ||
422 | static void init_once(void *foo) | 422 | static void init_once(void *foo) |
423 | { | 423 | { |
424 | struct bdev_inode *ei = (struct bdev_inode *) foo; | 424 | struct bdev_inode *ei = (struct bdev_inode *) foo; |
425 | struct block_device *bdev = &ei->bdev; | 425 | struct block_device *bdev = &ei->bdev; |
426 | 426 | ||
427 | memset(bdev, 0, sizeof(*bdev)); | 427 | memset(bdev, 0, sizeof(*bdev)); |
428 | mutex_init(&bdev->bd_mutex); | 428 | mutex_init(&bdev->bd_mutex); |
429 | sema_init(&bdev->bd_mount_sem, 1); | 429 | sema_init(&bdev->bd_mount_sem, 1); |
430 | INIT_LIST_HEAD(&bdev->bd_inodes); | 430 | INIT_LIST_HEAD(&bdev->bd_inodes); |
431 | INIT_LIST_HEAD(&bdev->bd_list); | 431 | INIT_LIST_HEAD(&bdev->bd_list); |
432 | #ifdef CONFIG_SYSFS | 432 | #ifdef CONFIG_SYSFS |
433 | INIT_LIST_HEAD(&bdev->bd_holder_list); | 433 | INIT_LIST_HEAD(&bdev->bd_holder_list); |
434 | #endif | 434 | #endif |
435 | inode_init_once(&ei->vfs_inode); | 435 | inode_init_once(&ei->vfs_inode); |
436 | /* Initialize mutex for freeze. */ | 436 | /* Initialize mutex for freeze. */ |
437 | mutex_init(&bdev->bd_fsfreeze_mutex); | 437 | mutex_init(&bdev->bd_fsfreeze_mutex); |
438 | } | 438 | } |
439 | 439 | ||
440 | static inline void __bd_forget(struct inode *inode) | 440 | static inline void __bd_forget(struct inode *inode) |
441 | { | 441 | { |
442 | list_del_init(&inode->i_devices); | 442 | list_del_init(&inode->i_devices); |
443 | inode->i_bdev = NULL; | 443 | inode->i_bdev = NULL; |
444 | inode->i_mapping = &inode->i_data; | 444 | inode->i_mapping = &inode->i_data; |
445 | } | 445 | } |
446 | 446 | ||
447 | static void bdev_clear_inode(struct inode *inode) | 447 | static void bdev_clear_inode(struct inode *inode) |
448 | { | 448 | { |
449 | struct block_device *bdev = &BDEV_I(inode)->bdev; | 449 | struct block_device *bdev = &BDEV_I(inode)->bdev; |
450 | struct list_head *p; | 450 | struct list_head *p; |
451 | spin_lock(&bdev_lock); | 451 | spin_lock(&bdev_lock); |
452 | while ( (p = bdev->bd_inodes.next) != &bdev->bd_inodes ) { | 452 | while ( (p = bdev->bd_inodes.next) != &bdev->bd_inodes ) { |
453 | __bd_forget(list_entry(p, struct inode, i_devices)); | 453 | __bd_forget(list_entry(p, struct inode, i_devices)); |
454 | } | 454 | } |
455 | list_del_init(&bdev->bd_list); | 455 | list_del_init(&bdev->bd_list); |
456 | spin_unlock(&bdev_lock); | 456 | spin_unlock(&bdev_lock); |
457 | } | 457 | } |
458 | 458 | ||
459 | static const struct super_operations bdev_sops = { | 459 | static const struct super_operations bdev_sops = { |
460 | .statfs = simple_statfs, | 460 | .statfs = simple_statfs, |
461 | .alloc_inode = bdev_alloc_inode, | 461 | .alloc_inode = bdev_alloc_inode, |
462 | .destroy_inode = bdev_destroy_inode, | 462 | .destroy_inode = bdev_destroy_inode, |
463 | .drop_inode = generic_delete_inode, | 463 | .drop_inode = generic_delete_inode, |
464 | .clear_inode = bdev_clear_inode, | 464 | .clear_inode = bdev_clear_inode, |
465 | }; | 465 | }; |
466 | 466 | ||
467 | static int bd_get_sb(struct file_system_type *fs_type, | 467 | static int bd_get_sb(struct file_system_type *fs_type, |
468 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) | 468 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) |
469 | { | 469 | { |
470 | return get_sb_pseudo(fs_type, "bdev:", &bdev_sops, 0x62646576, mnt); | 470 | return get_sb_pseudo(fs_type, "bdev:", &bdev_sops, 0x62646576, mnt); |
471 | } | 471 | } |
472 | 472 | ||
473 | static struct file_system_type bd_type = { | 473 | static struct file_system_type bd_type = { |
474 | .name = "bdev", | 474 | .name = "bdev", |
475 | .get_sb = bd_get_sb, | 475 | .get_sb = bd_get_sb, |
476 | .kill_sb = kill_anon_super, | 476 | .kill_sb = kill_anon_super, |
477 | }; | 477 | }; |
478 | 478 | ||
479 | struct super_block *blockdev_superblock __read_mostly; | 479 | struct super_block *blockdev_superblock __read_mostly; |
480 | 480 | ||
481 | void __init bdev_cache_init(void) | 481 | void __init bdev_cache_init(void) |
482 | { | 482 | { |
483 | int err; | 483 | int err; |
484 | struct vfsmount *bd_mnt; | 484 | struct vfsmount *bd_mnt; |
485 | 485 | ||
486 | bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode), | 486 | bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode), |
487 | 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| | 487 | 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| |
488 | SLAB_MEM_SPREAD|SLAB_PANIC), | 488 | SLAB_MEM_SPREAD|SLAB_PANIC), |
489 | init_once); | 489 | init_once); |
490 | err = register_filesystem(&bd_type); | 490 | err = register_filesystem(&bd_type); |
491 | if (err) | 491 | if (err) |
492 | panic("Cannot register bdev pseudo-fs"); | 492 | panic("Cannot register bdev pseudo-fs"); |
493 | bd_mnt = kern_mount(&bd_type); | 493 | bd_mnt = kern_mount(&bd_type); |
494 | if (IS_ERR(bd_mnt)) | 494 | if (IS_ERR(bd_mnt)) |
495 | panic("Cannot create bdev pseudo-fs"); | 495 | panic("Cannot create bdev pseudo-fs"); |
496 | /* | 496 | /* |
497 | * This vfsmount structure is only used to obtain the | 497 | * This vfsmount structure is only used to obtain the |
498 | * blockdev_superblock, so tell kmemleak not to report it. | 498 | * blockdev_superblock, so tell kmemleak not to report it. |
499 | */ | 499 | */ |
500 | kmemleak_not_leak(bd_mnt); | 500 | kmemleak_not_leak(bd_mnt); |
501 | blockdev_superblock = bd_mnt->mnt_sb; /* For writeback */ | 501 | blockdev_superblock = bd_mnt->mnt_sb; /* For writeback */ |
502 | } | 502 | } |
503 | 503 | ||
504 | /* | 504 | /* |
505 | * Most likely _very_ bad one - but then it's hardly critical for small | 505 | * Most likely _very_ bad one - but then it's hardly critical for small |
506 | * /dev and can be fixed when somebody will need really large one. | 506 | * /dev and can be fixed when somebody will need really large one. |
507 | * Keep in mind that it will be fed through icache hash function too. | 507 | * Keep in mind that it will be fed through icache hash function too. |
508 | */ | 508 | */ |
509 | static inline unsigned long hash(dev_t dev) | 509 | static inline unsigned long hash(dev_t dev) |
510 | { | 510 | { |
511 | return MAJOR(dev)+MINOR(dev); | 511 | return MAJOR(dev)+MINOR(dev); |
512 | } | 512 | } |
513 | 513 | ||
514 | static int bdev_test(struct inode *inode, void *data) | 514 | static int bdev_test(struct inode *inode, void *data) |
515 | { | 515 | { |
516 | return BDEV_I(inode)->bdev.bd_dev == *(dev_t *)data; | 516 | return BDEV_I(inode)->bdev.bd_dev == *(dev_t *)data; |
517 | } | 517 | } |
518 | 518 | ||
519 | static int bdev_set(struct inode *inode, void *data) | 519 | static int bdev_set(struct inode *inode, void *data) |
520 | { | 520 | { |
521 | BDEV_I(inode)->bdev.bd_dev = *(dev_t *)data; | 521 | BDEV_I(inode)->bdev.bd_dev = *(dev_t *)data; |
522 | return 0; | 522 | return 0; |
523 | } | 523 | } |
524 | 524 | ||
525 | static LIST_HEAD(all_bdevs); | 525 | static LIST_HEAD(all_bdevs); |
526 | 526 | ||
527 | struct block_device *bdget(dev_t dev) | 527 | struct block_device *bdget(dev_t dev) |
528 | { | 528 | { |
529 | struct block_device *bdev; | 529 | struct block_device *bdev; |
530 | struct inode *inode; | 530 | struct inode *inode; |
531 | 531 | ||
532 | inode = iget5_locked(blockdev_superblock, hash(dev), | 532 | inode = iget5_locked(blockdev_superblock, hash(dev), |
533 | bdev_test, bdev_set, &dev); | 533 | bdev_test, bdev_set, &dev); |
534 | 534 | ||
535 | if (!inode) | 535 | if (!inode) |
536 | return NULL; | 536 | return NULL; |
537 | 537 | ||
538 | bdev = &BDEV_I(inode)->bdev; | 538 | bdev = &BDEV_I(inode)->bdev; |
539 | 539 | ||
540 | if (inode->i_state & I_NEW) { | 540 | if (inode->i_state & I_NEW) { |
541 | bdev->bd_contains = NULL; | 541 | bdev->bd_contains = NULL; |
542 | bdev->bd_inode = inode; | 542 | bdev->bd_inode = inode; |
543 | bdev->bd_block_size = (1 << inode->i_blkbits); | 543 | bdev->bd_block_size = (1 << inode->i_blkbits); |
544 | bdev->bd_part_count = 0; | 544 | bdev->bd_part_count = 0; |
545 | bdev->bd_invalidated = 0; | 545 | bdev->bd_invalidated = 0; |
546 | inode->i_mode = S_IFBLK; | 546 | inode->i_mode = S_IFBLK; |
547 | inode->i_rdev = dev; | 547 | inode->i_rdev = dev; |
548 | inode->i_bdev = bdev; | 548 | inode->i_bdev = bdev; |
549 | inode->i_data.a_ops = &def_blk_aops; | 549 | inode->i_data.a_ops = &def_blk_aops; |
550 | mapping_set_gfp_mask(&inode->i_data, GFP_USER); | 550 | mapping_set_gfp_mask(&inode->i_data, GFP_USER); |
551 | inode->i_data.backing_dev_info = &default_backing_dev_info; | 551 | inode->i_data.backing_dev_info = &default_backing_dev_info; |
552 | spin_lock(&bdev_lock); | 552 | spin_lock(&bdev_lock); |
553 | list_add(&bdev->bd_list, &all_bdevs); | 553 | list_add(&bdev->bd_list, &all_bdevs); |
554 | spin_unlock(&bdev_lock); | 554 | spin_unlock(&bdev_lock); |
555 | unlock_new_inode(inode); | 555 | unlock_new_inode(inode); |
556 | } | 556 | } |
557 | return bdev; | 557 | return bdev; |
558 | } | 558 | } |
559 | 559 | ||
560 | EXPORT_SYMBOL(bdget); | 560 | EXPORT_SYMBOL(bdget); |
561 | 561 | ||
562 | long nr_blockdev_pages(void) | 562 | long nr_blockdev_pages(void) |
563 | { | 563 | { |
564 | struct block_device *bdev; | 564 | struct block_device *bdev; |
565 | long ret = 0; | 565 | long ret = 0; |
566 | spin_lock(&bdev_lock); | 566 | spin_lock(&bdev_lock); |
567 | list_for_each_entry(bdev, &all_bdevs, bd_list) { | 567 | list_for_each_entry(bdev, &all_bdevs, bd_list) { |
568 | ret += bdev->bd_inode->i_mapping->nrpages; | 568 | ret += bdev->bd_inode->i_mapping->nrpages; |
569 | } | 569 | } |
570 | spin_unlock(&bdev_lock); | 570 | spin_unlock(&bdev_lock); |
571 | return ret; | 571 | return ret; |
572 | } | 572 | } |
573 | 573 | ||
574 | void bdput(struct block_device *bdev) | 574 | void bdput(struct block_device *bdev) |
575 | { | 575 | { |
576 | iput(bdev->bd_inode); | 576 | iput(bdev->bd_inode); |
577 | } | 577 | } |
578 | 578 | ||
579 | EXPORT_SYMBOL(bdput); | 579 | EXPORT_SYMBOL(bdput); |
580 | 580 | ||
581 | static struct block_device *bd_acquire(struct inode *inode) | 581 | static struct block_device *bd_acquire(struct inode *inode) |
582 | { | 582 | { |
583 | struct block_device *bdev; | 583 | struct block_device *bdev; |
584 | 584 | ||
585 | spin_lock(&bdev_lock); | 585 | spin_lock(&bdev_lock); |
586 | bdev = inode->i_bdev; | 586 | bdev = inode->i_bdev; |
587 | if (bdev) { | 587 | if (bdev) { |
588 | atomic_inc(&bdev->bd_inode->i_count); | 588 | atomic_inc(&bdev->bd_inode->i_count); |
589 | spin_unlock(&bdev_lock); | 589 | spin_unlock(&bdev_lock); |
590 | return bdev; | 590 | return bdev; |
591 | } | 591 | } |
592 | spin_unlock(&bdev_lock); | 592 | spin_unlock(&bdev_lock); |
593 | 593 | ||
594 | bdev = bdget(inode->i_rdev); | 594 | bdev = bdget(inode->i_rdev); |
595 | if (bdev) { | 595 | if (bdev) { |
596 | spin_lock(&bdev_lock); | 596 | spin_lock(&bdev_lock); |
597 | if (!inode->i_bdev) { | 597 | if (!inode->i_bdev) { |
598 | /* | 598 | /* |
599 | * We take an additional bd_inode->i_count for inode, | 599 | * We take an additional bd_inode->i_count for inode, |
600 | * and it's released in clear_inode() of inode. | 600 | * and it's released in clear_inode() of inode. |
601 | * So, we can access it via ->i_mapping always | 601 | * So, we can access it via ->i_mapping always |
602 | * without igrab(). | 602 | * without igrab(). |
603 | */ | 603 | */ |
604 | atomic_inc(&bdev->bd_inode->i_count); | 604 | atomic_inc(&bdev->bd_inode->i_count); |
605 | inode->i_bdev = bdev; | 605 | inode->i_bdev = bdev; |
606 | inode->i_mapping = bdev->bd_inode->i_mapping; | 606 | inode->i_mapping = bdev->bd_inode->i_mapping; |
607 | list_add(&inode->i_devices, &bdev->bd_inodes); | 607 | list_add(&inode->i_devices, &bdev->bd_inodes); |
608 | } | 608 | } |
609 | spin_unlock(&bdev_lock); | 609 | spin_unlock(&bdev_lock); |
610 | } | 610 | } |
611 | return bdev; | 611 | return bdev; |
612 | } | 612 | } |
613 | 613 | ||
614 | /* Call when you free inode */ | 614 | /* Call when you free inode */ |
615 | 615 | ||
616 | void bd_forget(struct inode *inode) | 616 | void bd_forget(struct inode *inode) |
617 | { | 617 | { |
618 | struct block_device *bdev = NULL; | 618 | struct block_device *bdev = NULL; |
619 | 619 | ||
620 | spin_lock(&bdev_lock); | 620 | spin_lock(&bdev_lock); |
621 | if (inode->i_bdev) { | 621 | if (inode->i_bdev) { |
622 | if (!sb_is_blkdev_sb(inode->i_sb)) | 622 | if (!sb_is_blkdev_sb(inode->i_sb)) |
623 | bdev = inode->i_bdev; | 623 | bdev = inode->i_bdev; |
624 | __bd_forget(inode); | 624 | __bd_forget(inode); |
625 | } | 625 | } |
626 | spin_unlock(&bdev_lock); | 626 | spin_unlock(&bdev_lock); |
627 | 627 | ||
628 | if (bdev) | 628 | if (bdev) |
629 | iput(bdev->bd_inode); | 629 | iput(bdev->bd_inode); |
630 | } | 630 | } |
631 | 631 | ||
632 | int bd_claim(struct block_device *bdev, void *holder) | 632 | int bd_claim(struct block_device *bdev, void *holder) |
633 | { | 633 | { |
634 | int res; | 634 | int res; |
635 | spin_lock(&bdev_lock); | 635 | spin_lock(&bdev_lock); |
636 | 636 | ||
637 | /* first decide result */ | 637 | /* first decide result */ |
638 | if (bdev->bd_holder == holder) | 638 | if (bdev->bd_holder == holder) |
639 | res = 0; /* already a holder */ | 639 | res = 0; /* already a holder */ |
640 | else if (bdev->bd_holder != NULL) | 640 | else if (bdev->bd_holder != NULL) |
641 | res = -EBUSY; /* held by someone else */ | 641 | res = -EBUSY; /* held by someone else */ |
642 | else if (bdev->bd_contains == bdev) | 642 | else if (bdev->bd_contains == bdev) |
643 | res = 0; /* is a whole device which isn't held */ | 643 | res = 0; /* is a whole device which isn't held */ |
644 | 644 | ||
645 | else if (bdev->bd_contains->bd_holder == bd_claim) | 645 | else if (bdev->bd_contains->bd_holder == bd_claim) |
646 | res = 0; /* is a partition of a device that is being partitioned */ | 646 | res = 0; /* is a partition of a device that is being partitioned */ |
647 | else if (bdev->bd_contains->bd_holder != NULL) | 647 | else if (bdev->bd_contains->bd_holder != NULL) |
648 | res = -EBUSY; /* is a partition of a held device */ | 648 | res = -EBUSY; /* is a partition of a held device */ |
649 | else | 649 | else |
650 | res = 0; /* is a partition of an un-held device */ | 650 | res = 0; /* is a partition of an un-held device */ |
651 | 651 | ||
652 | /* now impose change */ | 652 | /* now impose change */ |
653 | if (res==0) { | 653 | if (res==0) { |
654 | /* note that for a whole device bd_holders | 654 | /* note that for a whole device bd_holders |
655 | * will be incremented twice, and bd_holder will | 655 | * will be incremented twice, and bd_holder will |
656 | * be set to bd_claim before being set to holder | 656 | * be set to bd_claim before being set to holder |
657 | */ | 657 | */ |
658 | bdev->bd_contains->bd_holders ++; | 658 | bdev->bd_contains->bd_holders ++; |
659 | bdev->bd_contains->bd_holder = bd_claim; | 659 | bdev->bd_contains->bd_holder = bd_claim; |
660 | bdev->bd_holders++; | 660 | bdev->bd_holders++; |
661 | bdev->bd_holder = holder; | 661 | bdev->bd_holder = holder; |
662 | } | 662 | } |
663 | spin_unlock(&bdev_lock); | 663 | spin_unlock(&bdev_lock); |
664 | return res; | 664 | return res; |
665 | } | 665 | } |
666 | 666 | ||
667 | EXPORT_SYMBOL(bd_claim); | 667 | EXPORT_SYMBOL(bd_claim); |
668 | 668 | ||
669 | void bd_release(struct block_device *bdev) | 669 | void bd_release(struct block_device *bdev) |
670 | { | 670 | { |
671 | spin_lock(&bdev_lock); | 671 | spin_lock(&bdev_lock); |
672 | if (!--bdev->bd_contains->bd_holders) | 672 | if (!--bdev->bd_contains->bd_holders) |
673 | bdev->bd_contains->bd_holder = NULL; | 673 | bdev->bd_contains->bd_holder = NULL; |
674 | if (!--bdev->bd_holders) | 674 | if (!--bdev->bd_holders) |
675 | bdev->bd_holder = NULL; | 675 | bdev->bd_holder = NULL; |
676 | spin_unlock(&bdev_lock); | 676 | spin_unlock(&bdev_lock); |
677 | } | 677 | } |
678 | 678 | ||
679 | EXPORT_SYMBOL(bd_release); | 679 | EXPORT_SYMBOL(bd_release); |
680 | 680 | ||
681 | #ifdef CONFIG_SYSFS | 681 | #ifdef CONFIG_SYSFS |
682 | /* | 682 | /* |
683 | * Functions for bd_claim_by_kobject / bd_release_from_kobject | 683 | * Functions for bd_claim_by_kobject / bd_release_from_kobject |
684 | * | 684 | * |
685 | * If a kobject is passed to bd_claim_by_kobject() | 685 | * If a kobject is passed to bd_claim_by_kobject() |
686 | * and the kobject has a parent directory, | 686 | * and the kobject has a parent directory, |
687 | * following symlinks are created: | 687 | * following symlinks are created: |
688 | * o from the kobject to the claimed bdev | 688 | * o from the kobject to the claimed bdev |
689 | * o from "holders" directory of the bdev to the parent of the kobject | 689 | * o from "holders" directory of the bdev to the parent of the kobject |
690 | * bd_release_from_kobject() removes these symlinks. | 690 | * bd_release_from_kobject() removes these symlinks. |
691 | * | 691 | * |
692 | * Example: | 692 | * Example: |
693 | * If /dev/dm-0 maps to /dev/sda, kobject corresponding to | 693 | * If /dev/dm-0 maps to /dev/sda, kobject corresponding to |
694 | * /sys/block/dm-0/slaves is passed to bd_claim_by_kobject(), then: | 694 | * /sys/block/dm-0/slaves is passed to bd_claim_by_kobject(), then: |
695 | * /sys/block/dm-0/slaves/sda --> /sys/block/sda | 695 | * /sys/block/dm-0/slaves/sda --> /sys/block/sda |
696 | * /sys/block/sda/holders/dm-0 --> /sys/block/dm-0 | 696 | * /sys/block/sda/holders/dm-0 --> /sys/block/dm-0 |
697 | */ | 697 | */ |
698 | 698 | ||
699 | static int add_symlink(struct kobject *from, struct kobject *to) | 699 | static int add_symlink(struct kobject *from, struct kobject *to) |
700 | { | 700 | { |
701 | if (!from || !to) | 701 | if (!from || !to) |
702 | return 0; | 702 | return 0; |
703 | return sysfs_create_link(from, to, kobject_name(to)); | 703 | return sysfs_create_link(from, to, kobject_name(to)); |
704 | } | 704 | } |
705 | 705 | ||
706 | static void del_symlink(struct kobject *from, struct kobject *to) | 706 | static void del_symlink(struct kobject *from, struct kobject *to) |
707 | { | 707 | { |
708 | if (!from || !to) | 708 | if (!from || !to) |
709 | return; | 709 | return; |
710 | sysfs_remove_link(from, kobject_name(to)); | 710 | sysfs_remove_link(from, kobject_name(to)); |
711 | } | 711 | } |
712 | 712 | ||
713 | /* | 713 | /* |
714 | * 'struct bd_holder' contains pointers to kobjects symlinked by | 714 | * 'struct bd_holder' contains pointers to kobjects symlinked by |
715 | * bd_claim_by_kobject. | 715 | * bd_claim_by_kobject. |
716 | * It's connected to bd_holder_list which is protected by bdev->bd_sem. | 716 | * It's connected to bd_holder_list which is protected by bdev->bd_sem. |
717 | */ | 717 | */ |
718 | struct bd_holder { | 718 | struct bd_holder { |
719 | struct list_head list; /* chain of holders of the bdev */ | 719 | struct list_head list; /* chain of holders of the bdev */ |
720 | int count; /* references from the holder */ | 720 | int count; /* references from the holder */ |
721 | struct kobject *sdir; /* holder object, e.g. "/block/dm-0/slaves" */ | 721 | struct kobject *sdir; /* holder object, e.g. "/block/dm-0/slaves" */ |
722 | struct kobject *hdev; /* e.g. "/block/dm-0" */ | 722 | struct kobject *hdev; /* e.g. "/block/dm-0" */ |
723 | struct kobject *hdir; /* e.g. "/block/sda/holders" */ | 723 | struct kobject *hdir; /* e.g. "/block/sda/holders" */ |
724 | struct kobject *sdev; /* e.g. "/block/sda" */ | 724 | struct kobject *sdev; /* e.g. "/block/sda" */ |
725 | }; | 725 | }; |
726 | 726 | ||
727 | /* | 727 | /* |
728 | * Get references of related kobjects at once. | 728 | * Get references of related kobjects at once. |
729 | * Returns 1 on success. 0 on failure. | 729 | * Returns 1 on success. 0 on failure. |
730 | * | 730 | * |
731 | * Should call bd_holder_release_dirs() after successful use. | 731 | * Should call bd_holder_release_dirs() after successful use. |
732 | */ | 732 | */ |
733 | static int bd_holder_grab_dirs(struct block_device *bdev, | 733 | static int bd_holder_grab_dirs(struct block_device *bdev, |
734 | struct bd_holder *bo) | 734 | struct bd_holder *bo) |
735 | { | 735 | { |
736 | if (!bdev || !bo) | 736 | if (!bdev || !bo) |
737 | return 0; | 737 | return 0; |
738 | 738 | ||
739 | bo->sdir = kobject_get(bo->sdir); | 739 | bo->sdir = kobject_get(bo->sdir); |
740 | if (!bo->sdir) | 740 | if (!bo->sdir) |
741 | return 0; | 741 | return 0; |
742 | 742 | ||
743 | bo->hdev = kobject_get(bo->sdir->parent); | 743 | bo->hdev = kobject_get(bo->sdir->parent); |
744 | if (!bo->hdev) | 744 | if (!bo->hdev) |
745 | goto fail_put_sdir; | 745 | goto fail_put_sdir; |
746 | 746 | ||
747 | bo->sdev = kobject_get(&part_to_dev(bdev->bd_part)->kobj); | 747 | bo->sdev = kobject_get(&part_to_dev(bdev->bd_part)->kobj); |
748 | if (!bo->sdev) | 748 | if (!bo->sdev) |
749 | goto fail_put_hdev; | 749 | goto fail_put_hdev; |
750 | 750 | ||
751 | bo->hdir = kobject_get(bdev->bd_part->holder_dir); | 751 | bo->hdir = kobject_get(bdev->bd_part->holder_dir); |
752 | if (!bo->hdir) | 752 | if (!bo->hdir) |
753 | goto fail_put_sdev; | 753 | goto fail_put_sdev; |
754 | 754 | ||
755 | return 1; | 755 | return 1; |
756 | 756 | ||
757 | fail_put_sdev: | 757 | fail_put_sdev: |
758 | kobject_put(bo->sdev); | 758 | kobject_put(bo->sdev); |
759 | fail_put_hdev: | 759 | fail_put_hdev: |
760 | kobject_put(bo->hdev); | 760 | kobject_put(bo->hdev); |
761 | fail_put_sdir: | 761 | fail_put_sdir: |
762 | kobject_put(bo->sdir); | 762 | kobject_put(bo->sdir); |
763 | 763 | ||
764 | return 0; | 764 | return 0; |
765 | } | 765 | } |
766 | 766 | ||
767 | /* Put references of related kobjects at once. */ | 767 | /* Put references of related kobjects at once. */ |
768 | static void bd_holder_release_dirs(struct bd_holder *bo) | 768 | static void bd_holder_release_dirs(struct bd_holder *bo) |
769 | { | 769 | { |
770 | kobject_put(bo->hdir); | 770 | kobject_put(bo->hdir); |
771 | kobject_put(bo->sdev); | 771 | kobject_put(bo->sdev); |
772 | kobject_put(bo->hdev); | 772 | kobject_put(bo->hdev); |
773 | kobject_put(bo->sdir); | 773 | kobject_put(bo->sdir); |
774 | } | 774 | } |
775 | 775 | ||
776 | static struct bd_holder *alloc_bd_holder(struct kobject *kobj) | 776 | static struct bd_holder *alloc_bd_holder(struct kobject *kobj) |
777 | { | 777 | { |
778 | struct bd_holder *bo; | 778 | struct bd_holder *bo; |
779 | 779 | ||
780 | bo = kzalloc(sizeof(*bo), GFP_KERNEL); | 780 | bo = kzalloc(sizeof(*bo), GFP_KERNEL); |
781 | if (!bo) | 781 | if (!bo) |
782 | return NULL; | 782 | return NULL; |
783 | 783 | ||
784 | bo->count = 1; | 784 | bo->count = 1; |
785 | bo->sdir = kobj; | 785 | bo->sdir = kobj; |
786 | 786 | ||
787 | return bo; | 787 | return bo; |
788 | } | 788 | } |
789 | 789 | ||
790 | static void free_bd_holder(struct bd_holder *bo) | 790 | static void free_bd_holder(struct bd_holder *bo) |
791 | { | 791 | { |
792 | kfree(bo); | 792 | kfree(bo); |
793 | } | 793 | } |
794 | 794 | ||
795 | /** | 795 | /** |
796 | * find_bd_holder - find matching struct bd_holder from the block device | 796 | * find_bd_holder - find matching struct bd_holder from the block device |
797 | * | 797 | * |
798 | * @bdev: struct block device to be searched | 798 | * @bdev: struct block device to be searched |
799 | * @bo: target struct bd_holder | 799 | * @bo: target struct bd_holder |
800 | * | 800 | * |
801 | * Returns matching entry with @bo in @bdev->bd_holder_list. | 801 | * Returns matching entry with @bo in @bdev->bd_holder_list. |
802 | * If found, increment the reference count and return the pointer. | 802 | * If found, increment the reference count and return the pointer. |
803 | * If not found, returns NULL. | 803 | * If not found, returns NULL. |
804 | */ | 804 | */ |
805 | static struct bd_holder *find_bd_holder(struct block_device *bdev, | 805 | static struct bd_holder *find_bd_holder(struct block_device *bdev, |
806 | struct bd_holder *bo) | 806 | struct bd_holder *bo) |
807 | { | 807 | { |
808 | struct bd_holder *tmp; | 808 | struct bd_holder *tmp; |
809 | 809 | ||
810 | list_for_each_entry(tmp, &bdev->bd_holder_list, list) | 810 | list_for_each_entry(tmp, &bdev->bd_holder_list, list) |
811 | if (tmp->sdir == bo->sdir) { | 811 | if (tmp->sdir == bo->sdir) { |
812 | tmp->count++; | 812 | tmp->count++; |
813 | return tmp; | 813 | return tmp; |
814 | } | 814 | } |
815 | 815 | ||
816 | return NULL; | 816 | return NULL; |
817 | } | 817 | } |
818 | 818 | ||
819 | /** | 819 | /** |
820 | * add_bd_holder - create sysfs symlinks for bd_claim() relationship | 820 | * add_bd_holder - create sysfs symlinks for bd_claim() relationship |
821 | * | 821 | * |
822 | * @bdev: block device to be bd_claimed | 822 | * @bdev: block device to be bd_claimed |
823 | * @bo: preallocated and initialized by alloc_bd_holder() | 823 | * @bo: preallocated and initialized by alloc_bd_holder() |
824 | * | 824 | * |
825 | * Add @bo to @bdev->bd_holder_list, create symlinks. | 825 | * Add @bo to @bdev->bd_holder_list, create symlinks. |
826 | * | 826 | * |
827 | * Returns 0 if symlinks are created. | 827 | * Returns 0 if symlinks are created. |
828 | * Returns -ve if something fails. | 828 | * Returns -ve if something fails. |
829 | */ | 829 | */ |
830 | static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo) | 830 | static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo) |
831 | { | 831 | { |
832 | int err; | 832 | int err; |
833 | 833 | ||
834 | if (!bo) | 834 | if (!bo) |
835 | return -EINVAL; | 835 | return -EINVAL; |
836 | 836 | ||
837 | if (!bd_holder_grab_dirs(bdev, bo)) | 837 | if (!bd_holder_grab_dirs(bdev, bo)) |
838 | return -EBUSY; | 838 | return -EBUSY; |
839 | 839 | ||
840 | err = add_symlink(bo->sdir, bo->sdev); | 840 | err = add_symlink(bo->sdir, bo->sdev); |
841 | if (err) | 841 | if (err) |
842 | return err; | 842 | return err; |
843 | 843 | ||
844 | err = add_symlink(bo->hdir, bo->hdev); | 844 | err = add_symlink(bo->hdir, bo->hdev); |
845 | if (err) { | 845 | if (err) { |
846 | del_symlink(bo->sdir, bo->sdev); | 846 | del_symlink(bo->sdir, bo->sdev); |
847 | return err; | 847 | return err; |
848 | } | 848 | } |
849 | 849 | ||
850 | list_add_tail(&bo->list, &bdev->bd_holder_list); | 850 | list_add_tail(&bo->list, &bdev->bd_holder_list); |
851 | return 0; | 851 | return 0; |
852 | } | 852 | } |
853 | 853 | ||
854 | /** | 854 | /** |
855 | * del_bd_holder - delete sysfs symlinks for bd_claim() relationship | 855 | * del_bd_holder - delete sysfs symlinks for bd_claim() relationship |
856 | * | 856 | * |
857 | * @bdev: block device to be bd_claimed | 857 | * @bdev: block device to be bd_claimed |
858 | * @kobj: holder's kobject | 858 | * @kobj: holder's kobject |
859 | * | 859 | * |
860 | * If there is matching entry with @kobj in @bdev->bd_holder_list | 860 | * If there is matching entry with @kobj in @bdev->bd_holder_list |
861 | * and no other bd_claim() from the same kobject, | 861 | * and no other bd_claim() from the same kobject, |
862 | * remove the struct bd_holder from the list, delete symlinks for it. | 862 | * remove the struct bd_holder from the list, delete symlinks for it. |
863 | * | 863 | * |
864 | * Returns a pointer to the struct bd_holder when it's removed from the list | 864 | * Returns a pointer to the struct bd_holder when it's removed from the list |
865 | * and ready to be freed. | 865 | * and ready to be freed. |
866 | * Returns NULL if matching claim isn't found or there is other bd_claim() | 866 | * Returns NULL if matching claim isn't found or there is other bd_claim() |
867 | * by the same kobject. | 867 | * by the same kobject. |
868 | */ | 868 | */ |
869 | static struct bd_holder *del_bd_holder(struct block_device *bdev, | 869 | static struct bd_holder *del_bd_holder(struct block_device *bdev, |
870 | struct kobject *kobj) | 870 | struct kobject *kobj) |
871 | { | 871 | { |
872 | struct bd_holder *bo; | 872 | struct bd_holder *bo; |
873 | 873 | ||
874 | list_for_each_entry(bo, &bdev->bd_holder_list, list) { | 874 | list_for_each_entry(bo, &bdev->bd_holder_list, list) { |
875 | if (bo->sdir == kobj) { | 875 | if (bo->sdir == kobj) { |
876 | bo->count--; | 876 | bo->count--; |
877 | BUG_ON(bo->count < 0); | 877 | BUG_ON(bo->count < 0); |
878 | if (!bo->count) { | 878 | if (!bo->count) { |
879 | list_del(&bo->list); | 879 | list_del(&bo->list); |
880 | del_symlink(bo->sdir, bo->sdev); | 880 | del_symlink(bo->sdir, bo->sdev); |
881 | del_symlink(bo->hdir, bo->hdev); | 881 | del_symlink(bo->hdir, bo->hdev); |
882 | bd_holder_release_dirs(bo); | 882 | bd_holder_release_dirs(bo); |
883 | return bo; | 883 | return bo; |
884 | } | 884 | } |
885 | break; | 885 | break; |
886 | } | 886 | } |
887 | } | 887 | } |
888 | 888 | ||
889 | return NULL; | 889 | return NULL; |
890 | } | 890 | } |
891 | 891 | ||
892 | /** | 892 | /** |
893 | * bd_claim_by_kobject - bd_claim() with additional kobject signature | 893 | * bd_claim_by_kobject - bd_claim() with additional kobject signature |
894 | * | 894 | * |
895 | * @bdev: block device to be claimed | 895 | * @bdev: block device to be claimed |
896 | * @holder: holder's signature | 896 | * @holder: holder's signature |
897 | * @kobj: holder's kobject | 897 | * @kobj: holder's kobject |
898 | * | 898 | * |
899 | * Do bd_claim() and if it succeeds, create sysfs symlinks between | 899 | * Do bd_claim() and if it succeeds, create sysfs symlinks between |
900 | * the bdev and the holder's kobject. | 900 | * the bdev and the holder's kobject. |
901 | * Use bd_release_from_kobject() when relesing the claimed bdev. | 901 | * Use bd_release_from_kobject() when relesing the claimed bdev. |
902 | * | 902 | * |
903 | * Returns 0 on success. (same as bd_claim()) | 903 | * Returns 0 on success. (same as bd_claim()) |
904 | * Returns errno on failure. | 904 | * Returns errno on failure. |
905 | */ | 905 | */ |
906 | static int bd_claim_by_kobject(struct block_device *bdev, void *holder, | 906 | static int bd_claim_by_kobject(struct block_device *bdev, void *holder, |
907 | struct kobject *kobj) | 907 | struct kobject *kobj) |
908 | { | 908 | { |
909 | int err; | 909 | int err; |
910 | struct bd_holder *bo, *found; | 910 | struct bd_holder *bo, *found; |
911 | 911 | ||
912 | if (!kobj) | 912 | if (!kobj) |
913 | return -EINVAL; | 913 | return -EINVAL; |
914 | 914 | ||
915 | bo = alloc_bd_holder(kobj); | 915 | bo = alloc_bd_holder(kobj); |
916 | if (!bo) | 916 | if (!bo) |
917 | return -ENOMEM; | 917 | return -ENOMEM; |
918 | 918 | ||
919 | mutex_lock(&bdev->bd_mutex); | 919 | mutex_lock(&bdev->bd_mutex); |
920 | 920 | ||
921 | err = bd_claim(bdev, holder); | 921 | err = bd_claim(bdev, holder); |
922 | if (err) | 922 | if (err) |
923 | goto fail; | 923 | goto fail; |
924 | 924 | ||
925 | found = find_bd_holder(bdev, bo); | 925 | found = find_bd_holder(bdev, bo); |
926 | if (found) | 926 | if (found) |
927 | goto fail; | 927 | goto fail; |
928 | 928 | ||
929 | err = add_bd_holder(bdev, bo); | 929 | err = add_bd_holder(bdev, bo); |
930 | if (err) | 930 | if (err) |
931 | bd_release(bdev); | 931 | bd_release(bdev); |
932 | else | 932 | else |
933 | bo = NULL; | 933 | bo = NULL; |
934 | fail: | 934 | fail: |
935 | mutex_unlock(&bdev->bd_mutex); | 935 | mutex_unlock(&bdev->bd_mutex); |
936 | free_bd_holder(bo); | 936 | free_bd_holder(bo); |
937 | return err; | 937 | return err; |
938 | } | 938 | } |
939 | 939 | ||
940 | /** | 940 | /** |
941 | * bd_release_from_kobject - bd_release() with additional kobject signature | 941 | * bd_release_from_kobject - bd_release() with additional kobject signature |
942 | * | 942 | * |
943 | * @bdev: block device to be released | 943 | * @bdev: block device to be released |
944 | * @kobj: holder's kobject | 944 | * @kobj: holder's kobject |
945 | * | 945 | * |
946 | * Do bd_release() and remove sysfs symlinks created by bd_claim_by_kobject(). | 946 | * Do bd_release() and remove sysfs symlinks created by bd_claim_by_kobject(). |
947 | */ | 947 | */ |
948 | static void bd_release_from_kobject(struct block_device *bdev, | 948 | static void bd_release_from_kobject(struct block_device *bdev, |
949 | struct kobject *kobj) | 949 | struct kobject *kobj) |
950 | { | 950 | { |
951 | if (!kobj) | 951 | if (!kobj) |
952 | return; | 952 | return; |
953 | 953 | ||
954 | mutex_lock(&bdev->bd_mutex); | 954 | mutex_lock(&bdev->bd_mutex); |
955 | bd_release(bdev); | 955 | bd_release(bdev); |
956 | free_bd_holder(del_bd_holder(bdev, kobj)); | 956 | free_bd_holder(del_bd_holder(bdev, kobj)); |
957 | mutex_unlock(&bdev->bd_mutex); | 957 | mutex_unlock(&bdev->bd_mutex); |
958 | } | 958 | } |
959 | 959 | ||
960 | /** | 960 | /** |
961 | * bd_claim_by_disk - wrapper function for bd_claim_by_kobject() | 961 | * bd_claim_by_disk - wrapper function for bd_claim_by_kobject() |
962 | * | 962 | * |
963 | * @bdev: block device to be claimed | 963 | * @bdev: block device to be claimed |
964 | * @holder: holder's signature | 964 | * @holder: holder's signature |
965 | * @disk: holder's gendisk | 965 | * @disk: holder's gendisk |
966 | * | 966 | * |
967 | * Call bd_claim_by_kobject() with getting @disk->slave_dir. | 967 | * Call bd_claim_by_kobject() with getting @disk->slave_dir. |
968 | */ | 968 | */ |
969 | int bd_claim_by_disk(struct block_device *bdev, void *holder, | 969 | int bd_claim_by_disk(struct block_device *bdev, void *holder, |
970 | struct gendisk *disk) | 970 | struct gendisk *disk) |
971 | { | 971 | { |
972 | return bd_claim_by_kobject(bdev, holder, kobject_get(disk->slave_dir)); | 972 | return bd_claim_by_kobject(bdev, holder, kobject_get(disk->slave_dir)); |
973 | } | 973 | } |
974 | EXPORT_SYMBOL_GPL(bd_claim_by_disk); | 974 | EXPORT_SYMBOL_GPL(bd_claim_by_disk); |
975 | 975 | ||
976 | /** | 976 | /** |
977 | * bd_release_from_disk - wrapper function for bd_release_from_kobject() | 977 | * bd_release_from_disk - wrapper function for bd_release_from_kobject() |
978 | * | 978 | * |
979 | * @bdev: block device to be claimed | 979 | * @bdev: block device to be claimed |
980 | * @disk: holder's gendisk | 980 | * @disk: holder's gendisk |
981 | * | 981 | * |
982 | * Call bd_release_from_kobject() and put @disk->slave_dir. | 982 | * Call bd_release_from_kobject() and put @disk->slave_dir. |
983 | */ | 983 | */ |
984 | void bd_release_from_disk(struct block_device *bdev, struct gendisk *disk) | 984 | void bd_release_from_disk(struct block_device *bdev, struct gendisk *disk) |
985 | { | 985 | { |
986 | bd_release_from_kobject(bdev, disk->slave_dir); | 986 | bd_release_from_kobject(bdev, disk->slave_dir); |
987 | kobject_put(disk->slave_dir); | 987 | kobject_put(disk->slave_dir); |
988 | } | 988 | } |
989 | EXPORT_SYMBOL_GPL(bd_release_from_disk); | 989 | EXPORT_SYMBOL_GPL(bd_release_from_disk); |
990 | #endif | 990 | #endif |
991 | 991 | ||
992 | /* | 992 | /* |
993 | * Tries to open block device by device number. Use it ONLY if you | 993 | * Tries to open block device by device number. Use it ONLY if you |
994 | * really do not have anything better - i.e. when you are behind a | 994 | * really do not have anything better - i.e. when you are behind a |
995 | * truly sucky interface and all you are given is a device number. _Never_ | 995 | * truly sucky interface and all you are given is a device number. _Never_ |
996 | * to be used for internal purposes. If you ever need it - reconsider | 996 | * to be used for internal purposes. If you ever need it - reconsider |
997 | * your API. | 997 | * your API. |
998 | */ | 998 | */ |
999 | struct block_device *open_by_devnum(dev_t dev, fmode_t mode) | 999 | struct block_device *open_by_devnum(dev_t dev, fmode_t mode) |
1000 | { | 1000 | { |
1001 | struct block_device *bdev = bdget(dev); | 1001 | struct block_device *bdev = bdget(dev); |
1002 | int err = -ENOMEM; | 1002 | int err = -ENOMEM; |
1003 | if (bdev) | 1003 | if (bdev) |
1004 | err = blkdev_get(bdev, mode); | 1004 | err = blkdev_get(bdev, mode); |
1005 | return err ? ERR_PTR(err) : bdev; | 1005 | return err ? ERR_PTR(err) : bdev; |
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | EXPORT_SYMBOL(open_by_devnum); | 1008 | EXPORT_SYMBOL(open_by_devnum); |
1009 | 1009 | ||
1010 | /** | 1010 | /** |
1011 | * flush_disk - invalidates all buffer-cache entries on a disk | 1011 | * flush_disk - invalidates all buffer-cache entries on a disk |
1012 | * | 1012 | * |
1013 | * @bdev: struct block device to be flushed | 1013 | * @bdev: struct block device to be flushed |
1014 | * | 1014 | * |
1015 | * Invalidates all buffer-cache entries on a disk. It should be called | 1015 | * Invalidates all buffer-cache entries on a disk. It should be called |
1016 | * when a disk has been changed -- either by a media change or online | 1016 | * when a disk has been changed -- either by a media change or online |
1017 | * resize. | 1017 | * resize. |
1018 | */ | 1018 | */ |
1019 | static void flush_disk(struct block_device *bdev) | 1019 | static void flush_disk(struct block_device *bdev) |
1020 | { | 1020 | { |
1021 | if (__invalidate_device(bdev)) { | 1021 | if (__invalidate_device(bdev)) { |
1022 | char name[BDEVNAME_SIZE] = ""; | 1022 | char name[BDEVNAME_SIZE] = ""; |
1023 | 1023 | ||
1024 | if (bdev->bd_disk) | 1024 | if (bdev->bd_disk) |
1025 | disk_name(bdev->bd_disk, 0, name); | 1025 | disk_name(bdev->bd_disk, 0, name); |
1026 | printk(KERN_WARNING "VFS: busy inodes on changed media or " | 1026 | printk(KERN_WARNING "VFS: busy inodes on changed media or " |
1027 | "resized disk %s\n", name); | 1027 | "resized disk %s\n", name); |
1028 | } | 1028 | } |
1029 | 1029 | ||
1030 | if (!bdev->bd_disk) | 1030 | if (!bdev->bd_disk) |
1031 | return; | 1031 | return; |
1032 | if (disk_partitionable(bdev->bd_disk)) | 1032 | if (disk_partitionable(bdev->bd_disk)) |
1033 | bdev->bd_invalidated = 1; | 1033 | bdev->bd_invalidated = 1; |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | /** | 1036 | /** |
1037 | * check_disk_size_change - checks for disk size change and adjusts bdev size. | 1037 | * check_disk_size_change - checks for disk size change and adjusts bdev size. |
1038 | * @disk: struct gendisk to check | 1038 | * @disk: struct gendisk to check |
1039 | * @bdev: struct bdev to adjust. | 1039 | * @bdev: struct bdev to adjust. |
1040 | * | 1040 | * |
1041 | * This routine checks to see if the bdev size does not match the disk size | 1041 | * This routine checks to see if the bdev size does not match the disk size |
1042 | * and adjusts it if it differs. | 1042 | * and adjusts it if it differs. |
1043 | */ | 1043 | */ |
1044 | void check_disk_size_change(struct gendisk *disk, struct block_device *bdev) | 1044 | void check_disk_size_change(struct gendisk *disk, struct block_device *bdev) |
1045 | { | 1045 | { |
1046 | loff_t disk_size, bdev_size; | 1046 | loff_t disk_size, bdev_size; |
1047 | 1047 | ||
1048 | disk_size = (loff_t)get_capacity(disk) << 9; | 1048 | disk_size = (loff_t)get_capacity(disk) << 9; |
1049 | bdev_size = i_size_read(bdev->bd_inode); | 1049 | bdev_size = i_size_read(bdev->bd_inode); |
1050 | if (disk_size != bdev_size) { | 1050 | if (disk_size != bdev_size) { |
1051 | char name[BDEVNAME_SIZE]; | 1051 | char name[BDEVNAME_SIZE]; |
1052 | 1052 | ||
1053 | disk_name(disk, 0, name); | 1053 | disk_name(disk, 0, name); |
1054 | printk(KERN_INFO | 1054 | printk(KERN_INFO |
1055 | "%s: detected capacity change from %lld to %lld\n", | 1055 | "%s: detected capacity change from %lld to %lld\n", |
1056 | name, bdev_size, disk_size); | 1056 | name, bdev_size, disk_size); |
1057 | i_size_write(bdev->bd_inode, disk_size); | 1057 | i_size_write(bdev->bd_inode, disk_size); |
1058 | flush_disk(bdev); | 1058 | flush_disk(bdev); |
1059 | } | 1059 | } |
1060 | } | 1060 | } |
1061 | EXPORT_SYMBOL(check_disk_size_change); | 1061 | EXPORT_SYMBOL(check_disk_size_change); |
1062 | 1062 | ||
1063 | /** | 1063 | /** |
1064 | * revalidate_disk - wrapper for lower-level driver's revalidate_disk call-back | 1064 | * revalidate_disk - wrapper for lower-level driver's revalidate_disk call-back |
1065 | * @disk: struct gendisk to be revalidated | 1065 | * @disk: struct gendisk to be revalidated |
1066 | * | 1066 | * |
1067 | * This routine is a wrapper for lower-level driver's revalidate_disk | 1067 | * This routine is a wrapper for lower-level driver's revalidate_disk |
1068 | * call-backs. It is used to do common pre and post operations needed | 1068 | * call-backs. It is used to do common pre and post operations needed |
1069 | * for all revalidate_disk operations. | 1069 | * for all revalidate_disk operations. |
1070 | */ | 1070 | */ |
1071 | int revalidate_disk(struct gendisk *disk) | 1071 | int revalidate_disk(struct gendisk *disk) |
1072 | { | 1072 | { |
1073 | struct block_device *bdev; | 1073 | struct block_device *bdev; |
1074 | int ret = 0; | 1074 | int ret = 0; |
1075 | 1075 | ||
1076 | if (disk->fops->revalidate_disk) | 1076 | if (disk->fops->revalidate_disk) |
1077 | ret = disk->fops->revalidate_disk(disk); | 1077 | ret = disk->fops->revalidate_disk(disk); |
1078 | 1078 | ||
1079 | bdev = bdget_disk(disk, 0); | 1079 | bdev = bdget_disk(disk, 0); |
1080 | if (!bdev) | 1080 | if (!bdev) |
1081 | return ret; | 1081 | return ret; |
1082 | 1082 | ||
1083 | mutex_lock(&bdev->bd_mutex); | 1083 | mutex_lock(&bdev->bd_mutex); |
1084 | check_disk_size_change(disk, bdev); | 1084 | check_disk_size_change(disk, bdev); |
1085 | mutex_unlock(&bdev->bd_mutex); | 1085 | mutex_unlock(&bdev->bd_mutex); |
1086 | bdput(bdev); | 1086 | bdput(bdev); |
1087 | return ret; | 1087 | return ret; |
1088 | } | 1088 | } |
1089 | EXPORT_SYMBOL(revalidate_disk); | 1089 | EXPORT_SYMBOL(revalidate_disk); |
1090 | 1090 | ||
1091 | /* | 1091 | /* |
1092 | * This routine checks whether a removable media has been changed, | 1092 | * This routine checks whether a removable media has been changed, |
1093 | * and invalidates all buffer-cache-entries in that case. This | 1093 | * and invalidates all buffer-cache-entries in that case. This |
1094 | * is a relatively slow routine, so we have to try to minimize using | 1094 | * is a relatively slow routine, so we have to try to minimize using |
1095 | * it. Thus it is called only upon a 'mount' or 'open'. This | 1095 | * it. Thus it is called only upon a 'mount' or 'open'. This |
1096 | * is the best way of combining speed and utility, I think. | 1096 | * is the best way of combining speed and utility, I think. |
1097 | * People changing diskettes in the middle of an operation deserve | 1097 | * People changing diskettes in the middle of an operation deserve |
1098 | * to lose :-) | 1098 | * to lose :-) |
1099 | */ | 1099 | */ |
1100 | int check_disk_change(struct block_device *bdev) | 1100 | int check_disk_change(struct block_device *bdev) |
1101 | { | 1101 | { |
1102 | struct gendisk *disk = bdev->bd_disk; | 1102 | struct gendisk *disk = bdev->bd_disk; |
1103 | struct block_device_operations * bdops = disk->fops; | 1103 | struct block_device_operations * bdops = disk->fops; |
1104 | 1104 | ||
1105 | if (!bdops->media_changed) | 1105 | if (!bdops->media_changed) |
1106 | return 0; | 1106 | return 0; |
1107 | if (!bdops->media_changed(bdev->bd_disk)) | 1107 | if (!bdops->media_changed(bdev->bd_disk)) |
1108 | return 0; | 1108 | return 0; |
1109 | 1109 | ||
1110 | flush_disk(bdev); | 1110 | flush_disk(bdev); |
1111 | if (bdops->revalidate_disk) | 1111 | if (bdops->revalidate_disk) |
1112 | bdops->revalidate_disk(bdev->bd_disk); | 1112 | bdops->revalidate_disk(bdev->bd_disk); |
1113 | return 1; | 1113 | return 1; |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | EXPORT_SYMBOL(check_disk_change); | 1116 | EXPORT_SYMBOL(check_disk_change); |
1117 | 1117 | ||
1118 | void bd_set_size(struct block_device *bdev, loff_t size) | 1118 | void bd_set_size(struct block_device *bdev, loff_t size) |
1119 | { | 1119 | { |
1120 | unsigned bsize = bdev_logical_block_size(bdev); | 1120 | unsigned bsize = bdev_logical_block_size(bdev); |
1121 | 1121 | ||
1122 | bdev->bd_inode->i_size = size; | 1122 | bdev->bd_inode->i_size = size; |
1123 | while (bsize < PAGE_CACHE_SIZE) { | 1123 | while (bsize < PAGE_CACHE_SIZE) { |
1124 | if (size & bsize) | 1124 | if (size & bsize) |
1125 | break; | 1125 | break; |
1126 | bsize <<= 1; | 1126 | bsize <<= 1; |
1127 | } | 1127 | } |
1128 | bdev->bd_block_size = bsize; | 1128 | bdev->bd_block_size = bsize; |
1129 | bdev->bd_inode->i_blkbits = blksize_bits(bsize); | 1129 | bdev->bd_inode->i_blkbits = blksize_bits(bsize); |
1130 | } | 1130 | } |
1131 | EXPORT_SYMBOL(bd_set_size); | 1131 | EXPORT_SYMBOL(bd_set_size); |
1132 | 1132 | ||
1133 | static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); | 1133 | static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); |
1134 | 1134 | ||
1135 | /* | 1135 | /* |
1136 | * bd_mutex locking: | 1136 | * bd_mutex locking: |
1137 | * | 1137 | * |
1138 | * mutex_lock(part->bd_mutex) | 1138 | * mutex_lock(part->bd_mutex) |
1139 | * mutex_lock_nested(whole->bd_mutex, 1) | 1139 | * mutex_lock_nested(whole->bd_mutex, 1) |
1140 | */ | 1140 | */ |
1141 | 1141 | ||
1142 | static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) | 1142 | static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) |
1143 | { | 1143 | { |
1144 | struct gendisk *disk; | 1144 | struct gendisk *disk; |
1145 | int ret; | 1145 | int ret; |
1146 | int partno; | 1146 | int partno; |
1147 | int perm = 0; | 1147 | int perm = 0; |
1148 | 1148 | ||
1149 | if (mode & FMODE_READ) | 1149 | if (mode & FMODE_READ) |
1150 | perm |= MAY_READ; | 1150 | perm |= MAY_READ; |
1151 | if (mode & FMODE_WRITE) | 1151 | if (mode & FMODE_WRITE) |
1152 | perm |= MAY_WRITE; | 1152 | perm |= MAY_WRITE; |
1153 | /* | 1153 | /* |
1154 | * hooks: /n/, see "layering violations". | 1154 | * hooks: /n/, see "layering violations". |
1155 | */ | 1155 | */ |
1156 | ret = devcgroup_inode_permission(bdev->bd_inode, perm); | 1156 | ret = devcgroup_inode_permission(bdev->bd_inode, perm); |
1157 | if (ret != 0) { | 1157 | if (ret != 0) { |
1158 | bdput(bdev); | 1158 | bdput(bdev); |
1159 | return ret; | 1159 | return ret; |
1160 | } | 1160 | } |
1161 | 1161 | ||
1162 | lock_kernel(); | 1162 | lock_kernel(); |
1163 | restart: | 1163 | restart: |
1164 | 1164 | ||
1165 | ret = -ENXIO; | 1165 | ret = -ENXIO; |
1166 | disk = get_gendisk(bdev->bd_dev, &partno); | 1166 | disk = get_gendisk(bdev->bd_dev, &partno); |
1167 | if (!disk) | 1167 | if (!disk) |
1168 | goto out_unlock_kernel; | 1168 | goto out_unlock_kernel; |
1169 | 1169 | ||
1170 | mutex_lock_nested(&bdev->bd_mutex, for_part); | 1170 | mutex_lock_nested(&bdev->bd_mutex, for_part); |
1171 | if (!bdev->bd_openers) { | 1171 | if (!bdev->bd_openers) { |
1172 | bdev->bd_disk = disk; | 1172 | bdev->bd_disk = disk; |
1173 | bdev->bd_contains = bdev; | 1173 | bdev->bd_contains = bdev; |
1174 | if (!partno) { | 1174 | if (!partno) { |
1175 | struct backing_dev_info *bdi; | 1175 | struct backing_dev_info *bdi; |
1176 | 1176 | ||
1177 | ret = -ENXIO; | 1177 | ret = -ENXIO; |
1178 | bdev->bd_part = disk_get_part(disk, partno); | 1178 | bdev->bd_part = disk_get_part(disk, partno); |
1179 | if (!bdev->bd_part) | 1179 | if (!bdev->bd_part) |
1180 | goto out_clear; | 1180 | goto out_clear; |
1181 | 1181 | ||
1182 | if (disk->fops->open) { | 1182 | if (disk->fops->open) { |
1183 | ret = disk->fops->open(bdev, mode); | 1183 | ret = disk->fops->open(bdev, mode); |
1184 | if (ret == -ERESTARTSYS) { | 1184 | if (ret == -ERESTARTSYS) { |
1185 | /* Lost a race with 'disk' being | 1185 | /* Lost a race with 'disk' being |
1186 | * deleted, try again. | 1186 | * deleted, try again. |
1187 | * See md.c | 1187 | * See md.c |
1188 | */ | 1188 | */ |
1189 | disk_put_part(bdev->bd_part); | 1189 | disk_put_part(bdev->bd_part); |
1190 | bdev->bd_part = NULL; | 1190 | bdev->bd_part = NULL; |
1191 | module_put(disk->fops->owner); | 1191 | module_put(disk->fops->owner); |
1192 | put_disk(disk); | 1192 | put_disk(disk); |
1193 | bdev->bd_disk = NULL; | 1193 | bdev->bd_disk = NULL; |
1194 | mutex_unlock(&bdev->bd_mutex); | 1194 | mutex_unlock(&bdev->bd_mutex); |
1195 | goto restart; | 1195 | goto restart; |
1196 | } | 1196 | } |
1197 | if (ret) | 1197 | if (ret) |
1198 | goto out_clear; | 1198 | goto out_clear; |
1199 | } | 1199 | } |
1200 | if (!bdev->bd_openers) { | 1200 | if (!bdev->bd_openers) { |
1201 | bd_set_size(bdev,(loff_t)get_capacity(disk)<<9); | 1201 | bd_set_size(bdev,(loff_t)get_capacity(disk)<<9); |
1202 | bdi = blk_get_backing_dev_info(bdev); | 1202 | bdi = blk_get_backing_dev_info(bdev); |
1203 | if (bdi == NULL) | 1203 | if (bdi == NULL) |
1204 | bdi = &default_backing_dev_info; | 1204 | bdi = &default_backing_dev_info; |
1205 | bdev->bd_inode->i_data.backing_dev_info = bdi; | 1205 | bdev->bd_inode->i_data.backing_dev_info = bdi; |
1206 | } | 1206 | } |
1207 | if (bdev->bd_invalidated) | 1207 | if (bdev->bd_invalidated) |
1208 | rescan_partitions(disk, bdev); | 1208 | rescan_partitions(disk, bdev); |
1209 | } else { | 1209 | } else { |
1210 | struct block_device *whole; | 1210 | struct block_device *whole; |
1211 | whole = bdget_disk(disk, 0); | 1211 | whole = bdget_disk(disk, 0); |
1212 | ret = -ENOMEM; | 1212 | ret = -ENOMEM; |
1213 | if (!whole) | 1213 | if (!whole) |
1214 | goto out_clear; | 1214 | goto out_clear; |
1215 | BUG_ON(for_part); | 1215 | BUG_ON(for_part); |
1216 | ret = __blkdev_get(whole, mode, 1); | 1216 | ret = __blkdev_get(whole, mode, 1); |
1217 | if (ret) | 1217 | if (ret) |
1218 | goto out_clear; | 1218 | goto out_clear; |
1219 | bdev->bd_contains = whole; | 1219 | bdev->bd_contains = whole; |
1220 | bdev->bd_inode->i_data.backing_dev_info = | 1220 | bdev->bd_inode->i_data.backing_dev_info = |
1221 | whole->bd_inode->i_data.backing_dev_info; | 1221 | whole->bd_inode->i_data.backing_dev_info; |
1222 | bdev->bd_part = disk_get_part(disk, partno); | 1222 | bdev->bd_part = disk_get_part(disk, partno); |
1223 | if (!(disk->flags & GENHD_FL_UP) || | 1223 | if (!(disk->flags & GENHD_FL_UP) || |
1224 | !bdev->bd_part || !bdev->bd_part->nr_sects) { | 1224 | !bdev->bd_part || !bdev->bd_part->nr_sects) { |
1225 | ret = -ENXIO; | 1225 | ret = -ENXIO; |
1226 | goto out_clear; | 1226 | goto out_clear; |
1227 | } | 1227 | } |
1228 | bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9); | 1228 | bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9); |
1229 | } | 1229 | } |
1230 | } else { | 1230 | } else { |
1231 | put_disk(disk); | 1231 | put_disk(disk); |
1232 | module_put(disk->fops->owner); | 1232 | module_put(disk->fops->owner); |
1233 | disk = NULL; | 1233 | disk = NULL; |
1234 | if (bdev->bd_contains == bdev) { | 1234 | if (bdev->bd_contains == bdev) { |
1235 | if (bdev->bd_disk->fops->open) { | 1235 | if (bdev->bd_disk->fops->open) { |
1236 | ret = bdev->bd_disk->fops->open(bdev, mode); | 1236 | ret = bdev->bd_disk->fops->open(bdev, mode); |
1237 | if (ret) | 1237 | if (ret) |
1238 | goto out_unlock_bdev; | 1238 | goto out_unlock_bdev; |
1239 | } | 1239 | } |
1240 | if (bdev->bd_invalidated) | 1240 | if (bdev->bd_invalidated) |
1241 | rescan_partitions(bdev->bd_disk, bdev); | 1241 | rescan_partitions(bdev->bd_disk, bdev); |
1242 | } | 1242 | } |
1243 | } | 1243 | } |
1244 | bdev->bd_openers++; | 1244 | bdev->bd_openers++; |
1245 | if (for_part) | 1245 | if (for_part) |
1246 | bdev->bd_part_count++; | 1246 | bdev->bd_part_count++; |
1247 | mutex_unlock(&bdev->bd_mutex); | 1247 | mutex_unlock(&bdev->bd_mutex); |
1248 | unlock_kernel(); | 1248 | unlock_kernel(); |
1249 | return 0; | 1249 | return 0; |
1250 | 1250 | ||
1251 | out_clear: | 1251 | out_clear: |
1252 | disk_put_part(bdev->bd_part); | 1252 | disk_put_part(bdev->bd_part); |
1253 | bdev->bd_disk = NULL; | 1253 | bdev->bd_disk = NULL; |
1254 | bdev->bd_part = NULL; | 1254 | bdev->bd_part = NULL; |
1255 | bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; | 1255 | bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; |
1256 | if (bdev != bdev->bd_contains) | 1256 | if (bdev != bdev->bd_contains) |
1257 | __blkdev_put(bdev->bd_contains, mode, 1); | 1257 | __blkdev_put(bdev->bd_contains, mode, 1); |
1258 | bdev->bd_contains = NULL; | 1258 | bdev->bd_contains = NULL; |
1259 | out_unlock_bdev: | 1259 | out_unlock_bdev: |
1260 | mutex_unlock(&bdev->bd_mutex); | 1260 | mutex_unlock(&bdev->bd_mutex); |
1261 | out_unlock_kernel: | 1261 | out_unlock_kernel: |
1262 | unlock_kernel(); | 1262 | unlock_kernel(); |
1263 | 1263 | ||
1264 | if (disk) | 1264 | if (disk) |
1265 | module_put(disk->fops->owner); | 1265 | module_put(disk->fops->owner); |
1266 | put_disk(disk); | 1266 | put_disk(disk); |
1267 | bdput(bdev); | 1267 | bdput(bdev); |
1268 | 1268 | ||
1269 | return ret; | 1269 | return ret; |
1270 | } | 1270 | } |
1271 | 1271 | ||
1272 | int blkdev_get(struct block_device *bdev, fmode_t mode) | 1272 | int blkdev_get(struct block_device *bdev, fmode_t mode) |
1273 | { | 1273 | { |
1274 | return __blkdev_get(bdev, mode, 0); | 1274 | return __blkdev_get(bdev, mode, 0); |
1275 | } | 1275 | } |
1276 | EXPORT_SYMBOL(blkdev_get); | 1276 | EXPORT_SYMBOL(blkdev_get); |
1277 | 1277 | ||
1278 | static int blkdev_open(struct inode * inode, struct file * filp) | 1278 | static int blkdev_open(struct inode * inode, struct file * filp) |
1279 | { | 1279 | { |
1280 | struct block_device *bdev; | 1280 | struct block_device *bdev; |
1281 | int res; | 1281 | int res; |
1282 | 1282 | ||
1283 | /* | 1283 | /* |
1284 | * Preserve backwards compatibility and allow large file access | 1284 | * Preserve backwards compatibility and allow large file access |
1285 | * even if userspace doesn't ask for it explicitly. Some mkfs | 1285 | * even if userspace doesn't ask for it explicitly. Some mkfs |
1286 | * binary needs it. We might want to drop this workaround | 1286 | * binary needs it. We might want to drop this workaround |
1287 | * during an unstable branch. | 1287 | * during an unstable branch. |
1288 | */ | 1288 | */ |
1289 | filp->f_flags |= O_LARGEFILE; | 1289 | filp->f_flags |= O_LARGEFILE; |
1290 | 1290 | ||
1291 | if (filp->f_flags & O_NDELAY) | 1291 | if (filp->f_flags & O_NDELAY) |
1292 | filp->f_mode |= FMODE_NDELAY; | 1292 | filp->f_mode |= FMODE_NDELAY; |
1293 | if (filp->f_flags & O_EXCL) | 1293 | if (filp->f_flags & O_EXCL) |
1294 | filp->f_mode |= FMODE_EXCL; | 1294 | filp->f_mode |= FMODE_EXCL; |
1295 | if ((filp->f_flags & O_ACCMODE) == 3) | 1295 | if ((filp->f_flags & O_ACCMODE) == 3) |
1296 | filp->f_mode |= FMODE_WRITE_IOCTL; | 1296 | filp->f_mode |= FMODE_WRITE_IOCTL; |
1297 | 1297 | ||
1298 | bdev = bd_acquire(inode); | 1298 | bdev = bd_acquire(inode); |
1299 | if (bdev == NULL) | 1299 | if (bdev == NULL) |
1300 | return -ENOMEM; | 1300 | return -ENOMEM; |
1301 | 1301 | ||
1302 | filp->f_mapping = bdev->bd_inode->i_mapping; | 1302 | filp->f_mapping = bdev->bd_inode->i_mapping; |
1303 | 1303 | ||
1304 | res = blkdev_get(bdev, filp->f_mode); | 1304 | res = blkdev_get(bdev, filp->f_mode); |
1305 | if (res) | 1305 | if (res) |
1306 | return res; | 1306 | return res; |
1307 | 1307 | ||
1308 | if (filp->f_mode & FMODE_EXCL) { | 1308 | if (filp->f_mode & FMODE_EXCL) { |
1309 | res = bd_claim(bdev, filp); | 1309 | res = bd_claim(bdev, filp); |
1310 | if (res) | 1310 | if (res) |
1311 | goto out_blkdev_put; | 1311 | goto out_blkdev_put; |
1312 | } | 1312 | } |
1313 | 1313 | ||
1314 | return 0; | 1314 | return 0; |
1315 | 1315 | ||
1316 | out_blkdev_put: | 1316 | out_blkdev_put: |
1317 | blkdev_put(bdev, filp->f_mode); | 1317 | blkdev_put(bdev, filp->f_mode); |
1318 | return res; | 1318 | return res; |
1319 | } | 1319 | } |
1320 | 1320 | ||
1321 | static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) | 1321 | static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) |
1322 | { | 1322 | { |
1323 | int ret = 0; | 1323 | int ret = 0; |
1324 | struct gendisk *disk = bdev->bd_disk; | 1324 | struct gendisk *disk = bdev->bd_disk; |
1325 | struct block_device *victim = NULL; | 1325 | struct block_device *victim = NULL; |
1326 | 1326 | ||
1327 | mutex_lock_nested(&bdev->bd_mutex, for_part); | 1327 | mutex_lock_nested(&bdev->bd_mutex, for_part); |
1328 | lock_kernel(); | 1328 | lock_kernel(); |
1329 | if (for_part) | 1329 | if (for_part) |
1330 | bdev->bd_part_count--; | 1330 | bdev->bd_part_count--; |
1331 | 1331 | ||
1332 | if (!--bdev->bd_openers) { | 1332 | if (!--bdev->bd_openers) { |
1333 | sync_blockdev(bdev); | 1333 | sync_blockdev(bdev); |
1334 | kill_bdev(bdev); | 1334 | kill_bdev(bdev); |
1335 | } | 1335 | } |
1336 | if (bdev->bd_contains == bdev) { | 1336 | if (bdev->bd_contains == bdev) { |
1337 | if (disk->fops->release) | 1337 | if (disk->fops->release) |
1338 | ret = disk->fops->release(disk, mode); | 1338 | ret = disk->fops->release(disk, mode); |
1339 | } | 1339 | } |
1340 | if (!bdev->bd_openers) { | 1340 | if (!bdev->bd_openers) { |
1341 | struct module *owner = disk->fops->owner; | 1341 | struct module *owner = disk->fops->owner; |
1342 | 1342 | ||
1343 | put_disk(disk); | 1343 | put_disk(disk); |
1344 | module_put(owner); | 1344 | module_put(owner); |
1345 | disk_put_part(bdev->bd_part); | 1345 | disk_put_part(bdev->bd_part); |
1346 | bdev->bd_part = NULL; | 1346 | bdev->bd_part = NULL; |
1347 | bdev->bd_disk = NULL; | 1347 | bdev->bd_disk = NULL; |
1348 | bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; | 1348 | bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; |
1349 | if (bdev != bdev->bd_contains) | 1349 | if (bdev != bdev->bd_contains) |
1350 | victim = bdev->bd_contains; | 1350 | victim = bdev->bd_contains; |
1351 | bdev->bd_contains = NULL; | 1351 | bdev->bd_contains = NULL; |
1352 | } | 1352 | } |
1353 | unlock_kernel(); | 1353 | unlock_kernel(); |
1354 | mutex_unlock(&bdev->bd_mutex); | 1354 | mutex_unlock(&bdev->bd_mutex); |
1355 | bdput(bdev); | 1355 | bdput(bdev); |
1356 | if (victim) | 1356 | if (victim) |
1357 | __blkdev_put(victim, mode, 1); | 1357 | __blkdev_put(victim, mode, 1); |
1358 | return ret; | 1358 | return ret; |
1359 | } | 1359 | } |
1360 | 1360 | ||
1361 | int blkdev_put(struct block_device *bdev, fmode_t mode) | 1361 | int blkdev_put(struct block_device *bdev, fmode_t mode) |
1362 | { | 1362 | { |
1363 | return __blkdev_put(bdev, mode, 0); | 1363 | return __blkdev_put(bdev, mode, 0); |
1364 | } | 1364 | } |
1365 | EXPORT_SYMBOL(blkdev_put); | 1365 | EXPORT_SYMBOL(blkdev_put); |
1366 | 1366 | ||
1367 | static int blkdev_close(struct inode * inode, struct file * filp) | 1367 | static int blkdev_close(struct inode * inode, struct file * filp) |
1368 | { | 1368 | { |
1369 | struct block_device *bdev = I_BDEV(filp->f_mapping->host); | 1369 | struct block_device *bdev = I_BDEV(filp->f_mapping->host); |
1370 | if (bdev->bd_holder == filp) | 1370 | if (bdev->bd_holder == filp) |
1371 | bd_release(bdev); | 1371 | bd_release(bdev); |
1372 | return blkdev_put(bdev, filp->f_mode); | 1372 | return blkdev_put(bdev, filp->f_mode); |
1373 | } | 1373 | } |
1374 | 1374 | ||
1375 | static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) | 1375 | static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) |
1376 | { | 1376 | { |
1377 | struct block_device *bdev = I_BDEV(file->f_mapping->host); | 1377 | struct block_device *bdev = I_BDEV(file->f_mapping->host); |
1378 | fmode_t mode = file->f_mode; | 1378 | fmode_t mode = file->f_mode; |
1379 | 1379 | ||
1380 | /* | 1380 | /* |
1381 | * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have | 1381 | * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have |
1382 | * to updated it before every ioctl. | 1382 | * to updated it before every ioctl. |
1383 | */ | 1383 | */ |
1384 | if (file->f_flags & O_NDELAY) | 1384 | if (file->f_flags & O_NDELAY) |
1385 | mode |= FMODE_NDELAY; | 1385 | mode |= FMODE_NDELAY; |
1386 | else | 1386 | else |
1387 | mode &= ~FMODE_NDELAY; | 1387 | mode &= ~FMODE_NDELAY; |
1388 | 1388 | ||
1389 | return blkdev_ioctl(bdev, mode, cmd, arg); | 1389 | return blkdev_ioctl(bdev, mode, cmd, arg); |
1390 | } | 1390 | } |
1391 | 1391 | ||
1392 | /* | 1392 | /* |
1393 | * Try to release a page associated with block device when the system | 1393 | * Try to release a page associated with block device when the system |
1394 | * is under memory pressure. | 1394 | * is under memory pressure. |
1395 | */ | 1395 | */ |
1396 | static int blkdev_releasepage(struct page *page, gfp_t wait) | 1396 | static int blkdev_releasepage(struct page *page, gfp_t wait) |
1397 | { | 1397 | { |
1398 | struct super_block *super = BDEV_I(page->mapping->host)->bdev.bd_super; | 1398 | struct super_block *super = BDEV_I(page->mapping->host)->bdev.bd_super; |
1399 | 1399 | ||
1400 | if (super && super->s_op->bdev_try_to_free_page) | 1400 | if (super && super->s_op->bdev_try_to_free_page) |
1401 | return super->s_op->bdev_try_to_free_page(super, page, wait); | 1401 | return super->s_op->bdev_try_to_free_page(super, page, wait); |
1402 | 1402 | ||
1403 | return try_to_free_buffers(page); | 1403 | return try_to_free_buffers(page); |
1404 | } | 1404 | } |
1405 | 1405 | ||
1406 | static const struct address_space_operations def_blk_aops = { | 1406 | static const struct address_space_operations def_blk_aops = { |
1407 | .readpage = blkdev_readpage, | 1407 | .readpage = blkdev_readpage, |
1408 | .writepage = blkdev_writepage, | 1408 | .writepage = blkdev_writepage, |
1409 | .sync_page = block_sync_page, | 1409 | .sync_page = block_sync_page, |
1410 | .write_begin = blkdev_write_begin, | 1410 | .write_begin = blkdev_write_begin, |
1411 | .write_end = blkdev_write_end, | 1411 | .write_end = blkdev_write_end, |
1412 | .writepages = generic_writepages, | 1412 | .writepages = generic_writepages, |
1413 | .releasepage = blkdev_releasepage, | 1413 | .releasepage = blkdev_releasepage, |
1414 | .direct_IO = blkdev_direct_IO, | 1414 | .direct_IO = blkdev_direct_IO, |
1415 | }; | 1415 | }; |
1416 | 1416 | ||
1417 | const struct file_operations def_blk_fops = { | 1417 | const struct file_operations def_blk_fops = { |
1418 | .open = blkdev_open, | 1418 | .open = blkdev_open, |
1419 | .release = blkdev_close, | 1419 | .release = blkdev_close, |
1420 | .llseek = block_llseek, | 1420 | .llseek = block_llseek, |
1421 | .read = do_sync_read, | 1421 | .read = do_sync_read, |
1422 | .write = do_sync_write, | 1422 | .write = do_sync_write, |
1423 | .aio_read = generic_file_aio_read, | 1423 | .aio_read = generic_file_aio_read, |
1424 | .aio_write = generic_file_aio_write_nolock, | 1424 | .aio_write = generic_file_aio_write_nolock, |
1425 | .mmap = generic_file_mmap, | 1425 | .mmap = generic_file_mmap, |
1426 | .fsync = block_fsync, | 1426 | .fsync = block_fsync, |
1427 | .unlocked_ioctl = block_ioctl, | 1427 | .unlocked_ioctl = block_ioctl, |
1428 | #ifdef CONFIG_COMPAT | 1428 | #ifdef CONFIG_COMPAT |
1429 | .compat_ioctl = compat_blkdev_ioctl, | 1429 | .compat_ioctl = compat_blkdev_ioctl, |
1430 | #endif | 1430 | #endif |
1431 | .splice_read = generic_file_splice_read, | 1431 | .splice_read = generic_file_splice_read, |
1432 | .splice_write = generic_file_splice_write, | 1432 | .splice_write = generic_file_splice_write, |
1433 | }; | 1433 | }; |
1434 | 1434 | ||
1435 | int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg) | 1435 | int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg) |
1436 | { | 1436 | { |
1437 | int res; | 1437 | int res; |
1438 | mm_segment_t old_fs = get_fs(); | 1438 | mm_segment_t old_fs = get_fs(); |
1439 | set_fs(KERNEL_DS); | 1439 | set_fs(KERNEL_DS); |
1440 | res = blkdev_ioctl(bdev, 0, cmd, arg); | 1440 | res = blkdev_ioctl(bdev, 0, cmd, arg); |
1441 | set_fs(old_fs); | 1441 | set_fs(old_fs); |
1442 | return res; | 1442 | return res; |
1443 | } | 1443 | } |
1444 | 1444 | ||
1445 | EXPORT_SYMBOL(ioctl_by_bdev); | 1445 | EXPORT_SYMBOL(ioctl_by_bdev); |
1446 | 1446 | ||
1447 | /** | 1447 | /** |
1448 | * lookup_bdev - lookup a struct block_device by name | 1448 | * lookup_bdev - lookup a struct block_device by name |
1449 | * @pathname: special file representing the block device | 1449 | * @pathname: special file representing the block device |
1450 | * | 1450 | * |
1451 | * Get a reference to the blockdevice at @pathname in the current | 1451 | * Get a reference to the blockdevice at @pathname in the current |
1452 | * namespace if possible and return it. Return ERR_PTR(error) | 1452 | * namespace if possible and return it. Return ERR_PTR(error) |
1453 | * otherwise. | 1453 | * otherwise. |
1454 | */ | 1454 | */ |
1455 | struct block_device *lookup_bdev(const char *pathname) | 1455 | struct block_device *lookup_bdev(const char *pathname) |
1456 | { | 1456 | { |
1457 | struct block_device *bdev; | 1457 | struct block_device *bdev; |
1458 | struct inode *inode; | 1458 | struct inode *inode; |
1459 | struct path path; | 1459 | struct path path; |
1460 | int error; | 1460 | int error; |
1461 | 1461 | ||
1462 | if (!pathname || !*pathname) | 1462 | if (!pathname || !*pathname) |
1463 | return ERR_PTR(-EINVAL); | 1463 | return ERR_PTR(-EINVAL); |
1464 | 1464 | ||
1465 | error = kern_path(pathname, LOOKUP_FOLLOW, &path); | 1465 | error = kern_path(pathname, LOOKUP_FOLLOW, &path); |
1466 | if (error) | 1466 | if (error) |
1467 | return ERR_PTR(error); | 1467 | return ERR_PTR(error); |
1468 | 1468 | ||
1469 | inode = path.dentry->d_inode; | 1469 | inode = path.dentry->d_inode; |
1470 | error = -ENOTBLK; | 1470 | error = -ENOTBLK; |
1471 | if (!S_ISBLK(inode->i_mode)) | 1471 | if (!S_ISBLK(inode->i_mode)) |
1472 | goto fail; | 1472 | goto fail; |
1473 | error = -EACCES; | 1473 | error = -EACCES; |
1474 | if (path.mnt->mnt_flags & MNT_NODEV) | 1474 | if (path.mnt->mnt_flags & MNT_NODEV) |
1475 | goto fail; | 1475 | goto fail; |
1476 | error = -ENOMEM; | 1476 | error = -ENOMEM; |
1477 | bdev = bd_acquire(inode); | 1477 | bdev = bd_acquire(inode); |
1478 | if (!bdev) | 1478 | if (!bdev) |
1479 | goto fail; | 1479 | goto fail; |
1480 | out: | 1480 | out: |
1481 | path_put(&path); | 1481 | path_put(&path); |
1482 | return bdev; | 1482 | return bdev; |
1483 | fail: | 1483 | fail: |
1484 | bdev = ERR_PTR(error); | 1484 | bdev = ERR_PTR(error); |
1485 | goto out; | 1485 | goto out; |
1486 | } | 1486 | } |
1487 | EXPORT_SYMBOL(lookup_bdev); | 1487 | EXPORT_SYMBOL(lookup_bdev); |
1488 | 1488 | ||
1489 | /** | 1489 | /** |
1490 | * open_bdev_exclusive - open a block device by name and set it up for use | 1490 | * open_bdev_exclusive - open a block device by name and set it up for use |
1491 | * | 1491 | * |
1492 | * @path: special file representing the block device | 1492 | * @path: special file representing the block device |
1493 | * @mode: FMODE_... combination to pass be used | 1493 | * @mode: FMODE_... combination to pass be used |
1494 | * @holder: owner for exclusion | 1494 | * @holder: owner for exclusion |
1495 | * | 1495 | * |
1496 | * Open the blockdevice described by the special file at @path, claim it | 1496 | * Open the blockdevice described by the special file at @path, claim it |
1497 | * for the @holder. | 1497 | * for the @holder. |
1498 | */ | 1498 | */ |
1499 | struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *holder) | 1499 | struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *holder) |
1500 | { | 1500 | { |
1501 | struct block_device *bdev; | 1501 | struct block_device *bdev; |
1502 | int error = 0; | 1502 | int error = 0; |
1503 | 1503 | ||
1504 | bdev = lookup_bdev(path); | 1504 | bdev = lookup_bdev(path); |
1505 | if (IS_ERR(bdev)) | 1505 | if (IS_ERR(bdev)) |
1506 | return bdev; | 1506 | return bdev; |
1507 | 1507 | ||
1508 | error = blkdev_get(bdev, mode); | 1508 | error = blkdev_get(bdev, mode); |
1509 | if (error) | 1509 | if (error) |
1510 | return ERR_PTR(error); | 1510 | return ERR_PTR(error); |
1511 | error = -EACCES; | 1511 | error = -EACCES; |
1512 | if ((mode & FMODE_WRITE) && bdev_read_only(bdev)) | 1512 | if ((mode & FMODE_WRITE) && bdev_read_only(bdev)) |
1513 | goto blkdev_put; | 1513 | goto blkdev_put; |
1514 | error = bd_claim(bdev, holder); | 1514 | error = bd_claim(bdev, holder); |
1515 | if (error) | 1515 | if (error) |
1516 | goto blkdev_put; | 1516 | goto blkdev_put; |
1517 | 1517 | ||
1518 | return bdev; | 1518 | return bdev; |
1519 | 1519 | ||
1520 | blkdev_put: | 1520 | blkdev_put: |
1521 | blkdev_put(bdev, mode); | 1521 | blkdev_put(bdev, mode); |
1522 | return ERR_PTR(error); | 1522 | return ERR_PTR(error); |
1523 | } | 1523 | } |
1524 | 1524 | ||
1525 | EXPORT_SYMBOL(open_bdev_exclusive); | 1525 | EXPORT_SYMBOL(open_bdev_exclusive); |
1526 | 1526 | ||
1527 | /** | 1527 | /** |
1528 | * close_bdev_exclusive - close a blockdevice opened by open_bdev_exclusive() | 1528 | * close_bdev_exclusive - close a blockdevice opened by open_bdev_exclusive() |
1529 | * | 1529 | * |
1530 | * @bdev: blockdevice to close | 1530 | * @bdev: blockdevice to close |
1531 | * @mode: mode, must match that used to open. | 1531 | * @mode: mode, must match that used to open. |
1532 | * | 1532 | * |
1533 | * This is the counterpart to open_bdev_exclusive(). | 1533 | * This is the counterpart to open_bdev_exclusive(). |
1534 | */ | 1534 | */ |
1535 | void close_bdev_exclusive(struct block_device *bdev, fmode_t mode) | 1535 | void close_bdev_exclusive(struct block_device *bdev, fmode_t mode) |
1536 | { | 1536 | { |
1537 | bd_release(bdev); | 1537 | bd_release(bdev); |
1538 | blkdev_put(bdev, mode); | 1538 | blkdev_put(bdev, mode); |
1539 | } | 1539 | } |
1540 | 1540 | ||
1541 | EXPORT_SYMBOL(close_bdev_exclusive); | 1541 | EXPORT_SYMBOL(close_bdev_exclusive); |
1542 | 1542 | ||
1543 | int __invalidate_device(struct block_device *bdev) | 1543 | int __invalidate_device(struct block_device *bdev) |
1544 | { | 1544 | { |
1545 | struct super_block *sb = get_super(bdev); | 1545 | struct super_block *sb = get_super(bdev); |
1546 | int res = 0; | 1546 | int res = 0; |
1547 | 1547 | ||
1548 | if (sb) { | 1548 | if (sb) { |
1549 | /* | 1549 | /* |
1550 | * no need to lock the super, get_super holds the | 1550 | * no need to lock the super, get_super holds the |
1551 | * read mutex so the filesystem cannot go away | 1551 | * read mutex so the filesystem cannot go away |
1552 | * under us (->put_super runs with the write lock | 1552 | * under us (->put_super runs with the write lock |
1553 | * hold). | 1553 | * hold). |
1554 | */ | 1554 | */ |
1555 | shrink_dcache_sb(sb); | 1555 | shrink_dcache_sb(sb); |
1556 | res = invalidate_inodes(sb); | 1556 | res = invalidate_inodes(sb); |
1557 | drop_super(sb); | 1557 | drop_super(sb); |
1558 | } | 1558 | } |
1559 | invalidate_bdev(bdev); | 1559 | invalidate_bdev(bdev); |
1560 | return res; | 1560 | return res; |
1561 | } | 1561 | } |
1562 | EXPORT_SYMBOL(__invalidate_device); | 1562 | EXPORT_SYMBOL(__invalidate_device); |
1563 | 1563 |
fs/super.c
1 | /* | 1 | /* |
2 | * linux/fs/super.c | 2 | * linux/fs/super.c |
3 | * | 3 | * |
4 | * Copyright (C) 1991, 1992 Linus Torvalds | 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
5 | * | 5 | * |
6 | * super.c contains code to handle: - mount structures | 6 | * super.c contains code to handle: - mount structures |
7 | * - super-block tables | 7 | * - super-block tables |
8 | * - filesystem drivers list | 8 | * - filesystem drivers list |
9 | * - mount system call | 9 | * - mount system call |
10 | * - umount system call | 10 | * - umount system call |
11 | * - ustat system call | 11 | * - ustat system call |
12 | * | 12 | * |
13 | * GK 2/5/95 - Changed to support mounting the root fs via NFS | 13 | * GK 2/5/95 - Changed to support mounting the root fs via NFS |
14 | * | 14 | * |
15 | * Added kerneld support: Jacques Gelinas and Bjorn Ekwall | 15 | * Added kerneld support: Jacques Gelinas and Bjorn Ekwall |
16 | * Added change_root: Werner Almesberger & Hans Lermen, Feb '96 | 16 | * Added change_root: Werner Almesberger & Hans Lermen, Feb '96 |
17 | * Added options to /proc/mounts: | 17 | * Added options to /proc/mounts: |
18 | * Torbjรถrn Lindh (torbjorn.lindh@gopta.se), April 14, 1996. | 18 | * Torbjรถrn Lindh (torbjorn.lindh@gopta.se), April 14, 1996. |
19 | * Added devfs support: Richard Gooch <rgooch@atnf.csiro.au>, 13-JAN-1998 | 19 | * Added devfs support: Richard Gooch <rgooch@atnf.csiro.au>, 13-JAN-1998 |
20 | * Heavily rewritten for 'one fs - one tree' dcache architecture. AV, Mar 2000 | 20 | * Heavily rewritten for 'one fs - one tree' dcache architecture. AV, Mar 2000 |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/init.h> | 25 | #include <linux/init.h> |
26 | #include <linux/smp_lock.h> | 26 | #include <linux/smp_lock.h> |
27 | #include <linux/acct.h> | 27 | #include <linux/acct.h> |
28 | #include <linux/blkdev.h> | 28 | #include <linux/blkdev.h> |
29 | #include <linux/quotaops.h> | 29 | #include <linux/quotaops.h> |
30 | #include <linux/namei.h> | 30 | #include <linux/namei.h> |
31 | #include <linux/buffer_head.h> /* for fsync_super() */ | 31 | #include <linux/buffer_head.h> /* for fsync_super() */ |
32 | #include <linux/mount.h> | 32 | #include <linux/mount.h> |
33 | #include <linux/security.h> | 33 | #include <linux/security.h> |
34 | #include <linux/syscalls.h> | 34 | #include <linux/syscalls.h> |
35 | #include <linux/vfs.h> | 35 | #include <linux/vfs.h> |
36 | #include <linux/writeback.h> /* for the emergency remount stuff */ | 36 | #include <linux/writeback.h> /* for the emergency remount stuff */ |
37 | #include <linux/idr.h> | 37 | #include <linux/idr.h> |
38 | #include <linux/kobject.h> | 38 | #include <linux/kobject.h> |
39 | #include <linux/mutex.h> | 39 | #include <linux/mutex.h> |
40 | #include <linux/file.h> | 40 | #include <linux/file.h> |
41 | #include <asm/uaccess.h> | 41 | #include <asm/uaccess.h> |
42 | #include "internal.h" | 42 | #include "internal.h" |
43 | 43 | ||
44 | 44 | ||
45 | LIST_HEAD(super_blocks); | 45 | LIST_HEAD(super_blocks); |
46 | DEFINE_SPINLOCK(sb_lock); | 46 | DEFINE_SPINLOCK(sb_lock); |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * alloc_super - create new superblock | 49 | * alloc_super - create new superblock |
50 | * @type: filesystem type superblock should belong to | 50 | * @type: filesystem type superblock should belong to |
51 | * | 51 | * |
52 | * Allocates and initializes a new &struct super_block. alloc_super() | 52 | * Allocates and initializes a new &struct super_block. alloc_super() |
53 | * returns a pointer new superblock or %NULL if allocation had failed. | 53 | * returns a pointer new superblock or %NULL if allocation had failed. |
54 | */ | 54 | */ |
55 | static struct super_block *alloc_super(struct file_system_type *type) | 55 | static struct super_block *alloc_super(struct file_system_type *type) |
56 | { | 56 | { |
57 | struct super_block *s = kzalloc(sizeof(struct super_block), GFP_USER); | 57 | struct super_block *s = kzalloc(sizeof(struct super_block), GFP_USER); |
58 | static struct super_operations default_op; | 58 | static struct super_operations default_op; |
59 | 59 | ||
60 | if (s) { | 60 | if (s) { |
61 | if (security_sb_alloc(s)) { | 61 | if (security_sb_alloc(s)) { |
62 | kfree(s); | 62 | kfree(s); |
63 | s = NULL; | 63 | s = NULL; |
64 | goto out; | 64 | goto out; |
65 | } | 65 | } |
66 | INIT_LIST_HEAD(&s->s_dirty); | 66 | INIT_LIST_HEAD(&s->s_dirty); |
67 | INIT_LIST_HEAD(&s->s_io); | 67 | INIT_LIST_HEAD(&s->s_io); |
68 | INIT_LIST_HEAD(&s->s_more_io); | 68 | INIT_LIST_HEAD(&s->s_more_io); |
69 | INIT_LIST_HEAD(&s->s_files); | 69 | INIT_LIST_HEAD(&s->s_files); |
70 | INIT_LIST_HEAD(&s->s_instances); | 70 | INIT_LIST_HEAD(&s->s_instances); |
71 | INIT_HLIST_HEAD(&s->s_anon); | 71 | INIT_HLIST_HEAD(&s->s_anon); |
72 | INIT_LIST_HEAD(&s->s_inodes); | 72 | INIT_LIST_HEAD(&s->s_inodes); |
73 | INIT_LIST_HEAD(&s->s_dentry_lru); | 73 | INIT_LIST_HEAD(&s->s_dentry_lru); |
74 | init_rwsem(&s->s_umount); | 74 | init_rwsem(&s->s_umount); |
75 | mutex_init(&s->s_lock); | 75 | mutex_init(&s->s_lock); |
76 | lockdep_set_class(&s->s_umount, &type->s_umount_key); | 76 | lockdep_set_class(&s->s_umount, &type->s_umount_key); |
77 | /* | 77 | /* |
78 | * The locking rules for s_lock are up to the | 78 | * The locking rules for s_lock are up to the |
79 | * filesystem. For example ext3fs has different | 79 | * filesystem. For example ext3fs has different |
80 | * lock ordering than usbfs: | 80 | * lock ordering than usbfs: |
81 | */ | 81 | */ |
82 | lockdep_set_class(&s->s_lock, &type->s_lock_key); | 82 | lockdep_set_class(&s->s_lock, &type->s_lock_key); |
83 | /* | 83 | /* |
84 | * sget() can have s_umount recursion. | 84 | * sget() can have s_umount recursion. |
85 | * | 85 | * |
86 | * When it cannot find a suitable sb, it allocates a new | 86 | * When it cannot find a suitable sb, it allocates a new |
87 | * one (this one), and tries again to find a suitable old | 87 | * one (this one), and tries again to find a suitable old |
88 | * one. | 88 | * one. |
89 | * | 89 | * |
90 | * In case that succeeds, it will acquire the s_umount | 90 | * In case that succeeds, it will acquire the s_umount |
91 | * lock of the old one. Since these are clearly distrinct | 91 | * lock of the old one. Since these are clearly distrinct |
92 | * locks, and this object isn't exposed yet, there's no | 92 | * locks, and this object isn't exposed yet, there's no |
93 | * risk of deadlocks. | 93 | * risk of deadlocks. |
94 | * | 94 | * |
95 | * Annotate this by putting this lock in a different | 95 | * Annotate this by putting this lock in a different |
96 | * subclass. | 96 | * subclass. |
97 | */ | 97 | */ |
98 | down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING); | 98 | down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING); |
99 | s->s_count = S_BIAS; | 99 | s->s_count = S_BIAS; |
100 | atomic_set(&s->s_active, 1); | 100 | atomic_set(&s->s_active, 1); |
101 | mutex_init(&s->s_vfs_rename_mutex); | 101 | mutex_init(&s->s_vfs_rename_mutex); |
102 | mutex_init(&s->s_dquot.dqio_mutex); | 102 | mutex_init(&s->s_dquot.dqio_mutex); |
103 | mutex_init(&s->s_dquot.dqonoff_mutex); | 103 | mutex_init(&s->s_dquot.dqonoff_mutex); |
104 | init_rwsem(&s->s_dquot.dqptr_sem); | 104 | init_rwsem(&s->s_dquot.dqptr_sem); |
105 | init_waitqueue_head(&s->s_wait_unfrozen); | 105 | init_waitqueue_head(&s->s_wait_unfrozen); |
106 | s->s_maxbytes = MAX_NON_LFS; | 106 | s->s_maxbytes = MAX_NON_LFS; |
107 | s->dq_op = sb_dquot_ops; | 107 | s->dq_op = sb_dquot_ops; |
108 | s->s_qcop = sb_quotactl_ops; | 108 | s->s_qcop = sb_quotactl_ops; |
109 | s->s_op = &default_op; | 109 | s->s_op = &default_op; |
110 | s->s_time_gran = 1000000000; | 110 | s->s_time_gran = 1000000000; |
111 | } | 111 | } |
112 | out: | 112 | out: |
113 | return s; | 113 | return s; |
114 | } | 114 | } |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * destroy_super - frees a superblock | 117 | * destroy_super - frees a superblock |
118 | * @s: superblock to free | 118 | * @s: superblock to free |
119 | * | 119 | * |
120 | * Frees a superblock. | 120 | * Frees a superblock. |
121 | */ | 121 | */ |
122 | static inline void destroy_super(struct super_block *s) | 122 | static inline void destroy_super(struct super_block *s) |
123 | { | 123 | { |
124 | security_sb_free(s); | 124 | security_sb_free(s); |
125 | kfree(s->s_subtype); | 125 | kfree(s->s_subtype); |
126 | kfree(s->s_options); | 126 | kfree(s->s_options); |
127 | kfree(s); | 127 | kfree(s); |
128 | } | 128 | } |
129 | 129 | ||
130 | /* Superblock refcounting */ | 130 | /* Superblock refcounting */ |
131 | 131 | ||
132 | /* | 132 | /* |
133 | * Drop a superblock's refcount. Returns non-zero if the superblock was | 133 | * Drop a superblock's refcount. Returns non-zero if the superblock was |
134 | * destroyed. The caller must hold sb_lock. | 134 | * destroyed. The caller must hold sb_lock. |
135 | */ | 135 | */ |
136 | static int __put_super(struct super_block *sb) | 136 | static int __put_super(struct super_block *sb) |
137 | { | 137 | { |
138 | int ret = 0; | 138 | int ret = 0; |
139 | 139 | ||
140 | if (!--sb->s_count) { | 140 | if (!--sb->s_count) { |
141 | destroy_super(sb); | 141 | destroy_super(sb); |
142 | ret = 1; | 142 | ret = 1; |
143 | } | 143 | } |
144 | return ret; | 144 | return ret; |
145 | } | 145 | } |
146 | 146 | ||
147 | /* | 147 | /* |
148 | * Drop a superblock's refcount. | 148 | * Drop a superblock's refcount. |
149 | * Returns non-zero if the superblock is about to be destroyed and | 149 | * Returns non-zero if the superblock is about to be destroyed and |
150 | * at least is already removed from super_blocks list, so if we are | 150 | * at least is already removed from super_blocks list, so if we are |
151 | * making a loop through super blocks then we need to restart. | 151 | * making a loop through super blocks then we need to restart. |
152 | * The caller must hold sb_lock. | 152 | * The caller must hold sb_lock. |
153 | */ | 153 | */ |
154 | int __put_super_and_need_restart(struct super_block *sb) | 154 | int __put_super_and_need_restart(struct super_block *sb) |
155 | { | 155 | { |
156 | /* check for race with generic_shutdown_super() */ | 156 | /* check for race with generic_shutdown_super() */ |
157 | if (list_empty(&sb->s_list)) { | 157 | if (list_empty(&sb->s_list)) { |
158 | /* super block is removed, need to restart... */ | 158 | /* super block is removed, need to restart... */ |
159 | __put_super(sb); | 159 | __put_super(sb); |
160 | return 1; | 160 | return 1; |
161 | } | 161 | } |
162 | /* can't be the last, since s_list is still in use */ | 162 | /* can't be the last, since s_list is still in use */ |
163 | sb->s_count--; | 163 | sb->s_count--; |
164 | BUG_ON(sb->s_count == 0); | 164 | BUG_ON(sb->s_count == 0); |
165 | return 0; | 165 | return 0; |
166 | } | 166 | } |
167 | 167 | ||
168 | /** | 168 | /** |
169 | * put_super - drop a temporary reference to superblock | 169 | * put_super - drop a temporary reference to superblock |
170 | * @sb: superblock in question | 170 | * @sb: superblock in question |
171 | * | 171 | * |
172 | * Drops a temporary reference, frees superblock if there's no | 172 | * Drops a temporary reference, frees superblock if there's no |
173 | * references left. | 173 | * references left. |
174 | */ | 174 | */ |
175 | static void put_super(struct super_block *sb) | 175 | static void put_super(struct super_block *sb) |
176 | { | 176 | { |
177 | spin_lock(&sb_lock); | 177 | spin_lock(&sb_lock); |
178 | __put_super(sb); | 178 | __put_super(sb); |
179 | spin_unlock(&sb_lock); | 179 | spin_unlock(&sb_lock); |
180 | } | 180 | } |
181 | 181 | ||
182 | 182 | ||
183 | /** | 183 | /** |
184 | * deactivate_super - drop an active reference to superblock | 184 | * deactivate_super - drop an active reference to superblock |
185 | * @s: superblock to deactivate | 185 | * @s: superblock to deactivate |
186 | * | 186 | * |
187 | * Drops an active reference to superblock, acquiring a temprory one if | 187 | * Drops an active reference to superblock, acquiring a temprory one if |
188 | * there is no active references left. In that case we lock superblock, | 188 | * there is no active references left. In that case we lock superblock, |
189 | * tell fs driver to shut it down and drop the temporary reference we | 189 | * tell fs driver to shut it down and drop the temporary reference we |
190 | * had just acquired. | 190 | * had just acquired. |
191 | */ | 191 | */ |
192 | void deactivate_super(struct super_block *s) | 192 | void deactivate_super(struct super_block *s) |
193 | { | 193 | { |
194 | struct file_system_type *fs = s->s_type; | 194 | struct file_system_type *fs = s->s_type; |
195 | if (atomic_dec_and_lock(&s->s_active, &sb_lock)) { | 195 | if (atomic_dec_and_lock(&s->s_active, &sb_lock)) { |
196 | s->s_count -= S_BIAS-1; | 196 | s->s_count -= S_BIAS-1; |
197 | spin_unlock(&sb_lock); | 197 | spin_unlock(&sb_lock); |
198 | vfs_dq_off(s, 0); | 198 | vfs_dq_off(s, 0); |
199 | down_write(&s->s_umount); | 199 | down_write(&s->s_umount); |
200 | fs->kill_sb(s); | 200 | fs->kill_sb(s); |
201 | put_filesystem(fs); | 201 | put_filesystem(fs); |
202 | put_super(s); | 202 | put_super(s); |
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | EXPORT_SYMBOL(deactivate_super); | 206 | EXPORT_SYMBOL(deactivate_super); |
207 | 207 | ||
208 | /** | 208 | /** |
209 | * deactivate_locked_super - drop an active reference to superblock | 209 | * deactivate_locked_super - drop an active reference to superblock |
210 | * @s: superblock to deactivate | 210 | * @s: superblock to deactivate |
211 | * | 211 | * |
212 | * Equivalent of up_write(&s->s_umount); deactivate_super(s);, except that | 212 | * Equivalent of up_write(&s->s_umount); deactivate_super(s);, except that |
213 | * it does not unlock it until it's all over. As the result, it's safe to | 213 | * it does not unlock it until it's all over. As the result, it's safe to |
214 | * use to dispose of new superblock on ->get_sb() failure exits - nobody | 214 | * use to dispose of new superblock on ->get_sb() failure exits - nobody |
215 | * will see the sucker until it's all over. Equivalent using up_write + | 215 | * will see the sucker until it's all over. Equivalent using up_write + |
216 | * deactivate_super is safe for that purpose only if superblock is either | 216 | * deactivate_super is safe for that purpose only if superblock is either |
217 | * safe to use or has NULL ->s_root when we unlock. | 217 | * safe to use or has NULL ->s_root when we unlock. |
218 | */ | 218 | */ |
219 | void deactivate_locked_super(struct super_block *s) | 219 | void deactivate_locked_super(struct super_block *s) |
220 | { | 220 | { |
221 | struct file_system_type *fs = s->s_type; | 221 | struct file_system_type *fs = s->s_type; |
222 | if (atomic_dec_and_lock(&s->s_active, &sb_lock)) { | 222 | if (atomic_dec_and_lock(&s->s_active, &sb_lock)) { |
223 | s->s_count -= S_BIAS-1; | 223 | s->s_count -= S_BIAS-1; |
224 | spin_unlock(&sb_lock); | 224 | spin_unlock(&sb_lock); |
225 | vfs_dq_off(s, 0); | 225 | vfs_dq_off(s, 0); |
226 | fs->kill_sb(s); | 226 | fs->kill_sb(s); |
227 | put_filesystem(fs); | 227 | put_filesystem(fs); |
228 | put_super(s); | 228 | put_super(s); |
229 | } else { | 229 | } else { |
230 | up_write(&s->s_umount); | 230 | up_write(&s->s_umount); |
231 | } | 231 | } |
232 | } | 232 | } |
233 | 233 | ||
234 | EXPORT_SYMBOL(deactivate_locked_super); | 234 | EXPORT_SYMBOL(deactivate_locked_super); |
235 | 235 | ||
236 | /** | 236 | /** |
237 | * grab_super - acquire an active reference | 237 | * grab_super - acquire an active reference |
238 | * @s: reference we are trying to make active | 238 | * @s: reference we are trying to make active |
239 | * | 239 | * |
240 | * Tries to acquire an active reference. grab_super() is used when we | 240 | * Tries to acquire an active reference. grab_super() is used when we |
241 | * had just found a superblock in super_blocks or fs_type->fs_supers | 241 | * had just found a superblock in super_blocks or fs_type->fs_supers |
242 | * and want to turn it into a full-blown active reference. grab_super() | 242 | * and want to turn it into a full-blown active reference. grab_super() |
243 | * is called with sb_lock held and drops it. Returns 1 in case of | 243 | * is called with sb_lock held and drops it. Returns 1 in case of |
244 | * success, 0 if we had failed (superblock contents was already dead or | 244 | * success, 0 if we had failed (superblock contents was already dead or |
245 | * dying when grab_super() had been called). | 245 | * dying when grab_super() had been called). |
246 | */ | 246 | */ |
247 | static int grab_super(struct super_block *s) __releases(sb_lock) | 247 | static int grab_super(struct super_block *s) __releases(sb_lock) |
248 | { | 248 | { |
249 | s->s_count++; | 249 | s->s_count++; |
250 | spin_unlock(&sb_lock); | 250 | spin_unlock(&sb_lock); |
251 | down_write(&s->s_umount); | 251 | down_write(&s->s_umount); |
252 | if (s->s_root) { | 252 | if (s->s_root) { |
253 | spin_lock(&sb_lock); | 253 | spin_lock(&sb_lock); |
254 | if (s->s_count > S_BIAS) { | 254 | if (s->s_count > S_BIAS) { |
255 | atomic_inc(&s->s_active); | 255 | atomic_inc(&s->s_active); |
256 | s->s_count--; | 256 | s->s_count--; |
257 | spin_unlock(&sb_lock); | 257 | spin_unlock(&sb_lock); |
258 | return 1; | 258 | return 1; |
259 | } | 259 | } |
260 | spin_unlock(&sb_lock); | 260 | spin_unlock(&sb_lock); |
261 | } | 261 | } |
262 | up_write(&s->s_umount); | 262 | up_write(&s->s_umount); |
263 | put_super(s); | 263 | put_super(s); |
264 | yield(); | 264 | yield(); |
265 | return 0; | 265 | return 0; |
266 | } | 266 | } |
267 | 267 | ||
268 | /* | 268 | /* |
269 | * Superblock locking. We really ought to get rid of these two. | 269 | * Superblock locking. We really ought to get rid of these two. |
270 | */ | 270 | */ |
271 | void lock_super(struct super_block * sb) | 271 | void lock_super(struct super_block * sb) |
272 | { | 272 | { |
273 | get_fs_excl(); | 273 | get_fs_excl(); |
274 | mutex_lock(&sb->s_lock); | 274 | mutex_lock(&sb->s_lock); |
275 | } | 275 | } |
276 | 276 | ||
277 | void unlock_super(struct super_block * sb) | 277 | void unlock_super(struct super_block * sb) |
278 | { | 278 | { |
279 | put_fs_excl(); | 279 | put_fs_excl(); |
280 | mutex_unlock(&sb->s_lock); | 280 | mutex_unlock(&sb->s_lock); |
281 | } | 281 | } |
282 | 282 | ||
283 | EXPORT_SYMBOL(lock_super); | 283 | EXPORT_SYMBOL(lock_super); |
284 | EXPORT_SYMBOL(unlock_super); | 284 | EXPORT_SYMBOL(unlock_super); |
285 | 285 | ||
286 | /* | 286 | /* |
287 | * Write out and wait upon all dirty data associated with this | 287 | * Write out and wait upon all dirty data associated with this |
288 | * superblock. Filesystem data as well as the underlying block | 288 | * superblock. Filesystem data as well as the underlying block |
289 | * device. Takes the superblock lock. Requires a second blkdev | 289 | * device. Takes the superblock lock. Requires a second blkdev |
290 | * flush by the caller to complete the operation. | 290 | * flush by the caller to complete the operation. |
291 | */ | 291 | */ |
292 | void __fsync_super(struct super_block *sb) | 292 | static int __fsync_super(struct super_block *sb) |
293 | { | 293 | { |
294 | sync_inodes_sb(sb, 0); | 294 | sync_inodes_sb(sb, 0); |
295 | vfs_dq_sync(sb); | 295 | vfs_dq_sync(sb); |
296 | sync_inodes_sb(sb, 1); | 296 | sync_inodes_sb(sb, 1); |
297 | lock_super(sb); | 297 | lock_super(sb); |
298 | if (sb->s_dirt && sb->s_op->write_super) | 298 | if (sb->s_dirt && sb->s_op->write_super) |
299 | sb->s_op->write_super(sb); | 299 | sb->s_op->write_super(sb); |
300 | unlock_super(sb); | 300 | unlock_super(sb); |
301 | if (sb->s_op->sync_fs) | 301 | if (sb->s_op->sync_fs) |
302 | sb->s_op->sync_fs(sb, 1); | 302 | sb->s_op->sync_fs(sb, 1); |
303 | sync_blockdev(sb->s_bdev); | 303 | return sync_blockdev(sb->s_bdev); |
304 | } | 304 | } |
305 | 305 | ||
306 | /* | 306 | /* |
307 | * Write out and wait upon all dirty data associated with this | 307 | * Write out and wait upon all dirty data associated with this |
308 | * superblock. Filesystem data as well as the underlying block | 308 | * superblock. Filesystem data as well as the underlying block |
309 | * device. Takes the superblock lock. | 309 | * device. Takes the superblock lock. |
310 | */ | 310 | */ |
311 | int fsync_super(struct super_block *sb) | 311 | int fsync_super(struct super_block *sb) |
312 | { | 312 | { |
313 | __fsync_super(sb); | 313 | return __fsync_super(sb); |
314 | return sync_blockdev(sb->s_bdev); | ||
315 | } | 314 | } |
316 | EXPORT_SYMBOL_GPL(fsync_super); | 315 | EXPORT_SYMBOL_GPL(fsync_super); |
317 | 316 | ||
318 | /** | 317 | /** |
319 | * generic_shutdown_super - common helper for ->kill_sb() | 318 | * generic_shutdown_super - common helper for ->kill_sb() |
320 | * @sb: superblock to kill | 319 | * @sb: superblock to kill |
321 | * | 320 | * |
322 | * generic_shutdown_super() does all fs-independent work on superblock | 321 | * generic_shutdown_super() does all fs-independent work on superblock |
323 | * shutdown. Typical ->kill_sb() should pick all fs-specific objects | 322 | * shutdown. Typical ->kill_sb() should pick all fs-specific objects |
324 | * that need destruction out of superblock, call generic_shutdown_super() | 323 | * that need destruction out of superblock, call generic_shutdown_super() |
325 | * and release aforementioned objects. Note: dentries and inodes _are_ | 324 | * and release aforementioned objects. Note: dentries and inodes _are_ |
326 | * taken care of and do not need specific handling. | 325 | * taken care of and do not need specific handling. |
327 | * | 326 | * |
328 | * Upon calling this function, the filesystem may no longer alter or | 327 | * Upon calling this function, the filesystem may no longer alter or |
329 | * rearrange the set of dentries belonging to this super_block, nor may it | 328 | * rearrange the set of dentries belonging to this super_block, nor may it |
330 | * change the attachments of dentries to inodes. | 329 | * change the attachments of dentries to inodes. |
331 | */ | 330 | */ |
332 | void generic_shutdown_super(struct super_block *sb) | 331 | void generic_shutdown_super(struct super_block *sb) |
333 | { | 332 | { |
334 | const struct super_operations *sop = sb->s_op; | 333 | const struct super_operations *sop = sb->s_op; |
335 | 334 | ||
336 | 335 | ||
337 | if (sb->s_root) { | 336 | if (sb->s_root) { |
338 | shrink_dcache_for_umount(sb); | 337 | shrink_dcache_for_umount(sb); |
339 | fsync_super(sb); | 338 | fsync_super(sb); |
340 | lock_super(sb); | 339 | lock_super(sb); |
341 | sb->s_flags &= ~MS_ACTIVE; | 340 | sb->s_flags &= ~MS_ACTIVE; |
342 | 341 | ||
343 | /* bad name - it should be evict_inodes() */ | 342 | /* bad name - it should be evict_inodes() */ |
344 | invalidate_inodes(sb); | 343 | invalidate_inodes(sb); |
345 | lock_kernel(); | 344 | lock_kernel(); |
346 | 345 | ||
347 | if (sop->write_super && sb->s_dirt) | 346 | if (sop->write_super && sb->s_dirt) |
348 | sop->write_super(sb); | 347 | sop->write_super(sb); |
349 | if (sop->put_super) | 348 | if (sop->put_super) |
350 | sop->put_super(sb); | 349 | sop->put_super(sb); |
351 | 350 | ||
352 | /* Forget any remaining inodes */ | 351 | /* Forget any remaining inodes */ |
353 | if (invalidate_inodes(sb)) { | 352 | if (invalidate_inodes(sb)) { |
354 | printk("VFS: Busy inodes after unmount of %s. " | 353 | printk("VFS: Busy inodes after unmount of %s. " |
355 | "Self-destruct in 5 seconds. Have a nice day...\n", | 354 | "Self-destruct in 5 seconds. Have a nice day...\n", |
356 | sb->s_id); | 355 | sb->s_id); |
357 | } | 356 | } |
358 | 357 | ||
359 | unlock_kernel(); | 358 | unlock_kernel(); |
360 | unlock_super(sb); | 359 | unlock_super(sb); |
361 | } | 360 | } |
362 | spin_lock(&sb_lock); | 361 | spin_lock(&sb_lock); |
363 | /* should be initialized for __put_super_and_need_restart() */ | 362 | /* should be initialized for __put_super_and_need_restart() */ |
364 | list_del_init(&sb->s_list); | 363 | list_del_init(&sb->s_list); |
365 | list_del(&sb->s_instances); | 364 | list_del(&sb->s_instances); |
366 | spin_unlock(&sb_lock); | 365 | spin_unlock(&sb_lock); |
367 | up_write(&sb->s_umount); | 366 | up_write(&sb->s_umount); |
368 | } | 367 | } |
369 | 368 | ||
370 | EXPORT_SYMBOL(generic_shutdown_super); | 369 | EXPORT_SYMBOL(generic_shutdown_super); |
371 | 370 | ||
372 | /** | 371 | /** |
373 | * sget - find or create a superblock | 372 | * sget - find or create a superblock |
374 | * @type: filesystem type superblock should belong to | 373 | * @type: filesystem type superblock should belong to |
375 | * @test: comparison callback | 374 | * @test: comparison callback |
376 | * @set: setup callback | 375 | * @set: setup callback |
377 | * @data: argument to each of them | 376 | * @data: argument to each of them |
378 | */ | 377 | */ |
379 | struct super_block *sget(struct file_system_type *type, | 378 | struct super_block *sget(struct file_system_type *type, |
380 | int (*test)(struct super_block *,void *), | 379 | int (*test)(struct super_block *,void *), |
381 | int (*set)(struct super_block *,void *), | 380 | int (*set)(struct super_block *,void *), |
382 | void *data) | 381 | void *data) |
383 | { | 382 | { |
384 | struct super_block *s = NULL; | 383 | struct super_block *s = NULL; |
385 | struct super_block *old; | 384 | struct super_block *old; |
386 | int err; | 385 | int err; |
387 | 386 | ||
388 | retry: | 387 | retry: |
389 | spin_lock(&sb_lock); | 388 | spin_lock(&sb_lock); |
390 | if (test) { | 389 | if (test) { |
391 | list_for_each_entry(old, &type->fs_supers, s_instances) { | 390 | list_for_each_entry(old, &type->fs_supers, s_instances) { |
392 | if (!test(old, data)) | 391 | if (!test(old, data)) |
393 | continue; | 392 | continue; |
394 | if (!grab_super(old)) | 393 | if (!grab_super(old)) |
395 | goto retry; | 394 | goto retry; |
396 | if (s) { | 395 | if (s) { |
397 | up_write(&s->s_umount); | 396 | up_write(&s->s_umount); |
398 | destroy_super(s); | 397 | destroy_super(s); |
399 | } | 398 | } |
400 | return old; | 399 | return old; |
401 | } | 400 | } |
402 | } | 401 | } |
403 | if (!s) { | 402 | if (!s) { |
404 | spin_unlock(&sb_lock); | 403 | spin_unlock(&sb_lock); |
405 | s = alloc_super(type); | 404 | s = alloc_super(type); |
406 | if (!s) | 405 | if (!s) |
407 | return ERR_PTR(-ENOMEM); | 406 | return ERR_PTR(-ENOMEM); |
408 | goto retry; | 407 | goto retry; |
409 | } | 408 | } |
410 | 409 | ||
411 | err = set(s, data); | 410 | err = set(s, data); |
412 | if (err) { | 411 | if (err) { |
413 | spin_unlock(&sb_lock); | 412 | spin_unlock(&sb_lock); |
414 | up_write(&s->s_umount); | 413 | up_write(&s->s_umount); |
415 | destroy_super(s); | 414 | destroy_super(s); |
416 | return ERR_PTR(err); | 415 | return ERR_PTR(err); |
417 | } | 416 | } |
418 | s->s_type = type; | 417 | s->s_type = type; |
419 | strlcpy(s->s_id, type->name, sizeof(s->s_id)); | 418 | strlcpy(s->s_id, type->name, sizeof(s->s_id)); |
420 | list_add_tail(&s->s_list, &super_blocks); | 419 | list_add_tail(&s->s_list, &super_blocks); |
421 | list_add(&s->s_instances, &type->fs_supers); | 420 | list_add(&s->s_instances, &type->fs_supers); |
422 | spin_unlock(&sb_lock); | 421 | spin_unlock(&sb_lock); |
423 | get_filesystem(type); | 422 | get_filesystem(type); |
424 | return s; | 423 | return s; |
425 | } | 424 | } |
426 | 425 | ||
427 | EXPORT_SYMBOL(sget); | 426 | EXPORT_SYMBOL(sget); |
428 | 427 | ||
429 | void drop_super(struct super_block *sb) | 428 | void drop_super(struct super_block *sb) |
430 | { | 429 | { |
431 | up_read(&sb->s_umount); | 430 | up_read(&sb->s_umount); |
432 | put_super(sb); | 431 | put_super(sb); |
433 | } | 432 | } |
434 | 433 | ||
435 | EXPORT_SYMBOL(drop_super); | 434 | EXPORT_SYMBOL(drop_super); |
436 | 435 | ||
437 | static inline void write_super(struct super_block *sb) | 436 | static inline void write_super(struct super_block *sb) |
438 | { | 437 | { |
439 | lock_super(sb); | 438 | lock_super(sb); |
440 | if (sb->s_root && sb->s_dirt) | 439 | if (sb->s_root && sb->s_dirt) |
441 | if (sb->s_op->write_super) | 440 | if (sb->s_op->write_super) |
442 | sb->s_op->write_super(sb); | 441 | sb->s_op->write_super(sb); |
443 | unlock_super(sb); | 442 | unlock_super(sb); |
444 | } | 443 | } |
445 | 444 | ||
446 | /* | 445 | /* |
447 | * Note: check the dirty flag before waiting, so we don't | 446 | * Note: check the dirty flag before waiting, so we don't |
448 | * hold up the sync while mounting a device. (The newly | 447 | * hold up the sync while mounting a device. (The newly |
449 | * mounted device won't need syncing.) | 448 | * mounted device won't need syncing.) |
450 | */ | 449 | */ |
451 | void sync_supers(void) | 450 | void sync_supers(void) |
452 | { | 451 | { |
453 | struct super_block *sb; | 452 | struct super_block *sb; |
454 | 453 | ||
455 | spin_lock(&sb_lock); | 454 | spin_lock(&sb_lock); |
456 | restart: | 455 | restart: |
457 | list_for_each_entry(sb, &super_blocks, s_list) { | 456 | list_for_each_entry(sb, &super_blocks, s_list) { |
458 | if (sb->s_dirt) { | 457 | if (sb->s_dirt) { |
459 | sb->s_count++; | 458 | sb->s_count++; |
460 | spin_unlock(&sb_lock); | 459 | spin_unlock(&sb_lock); |
461 | down_read(&sb->s_umount); | 460 | down_read(&sb->s_umount); |
462 | write_super(sb); | 461 | write_super(sb); |
463 | up_read(&sb->s_umount); | 462 | up_read(&sb->s_umount); |
464 | spin_lock(&sb_lock); | 463 | spin_lock(&sb_lock); |
465 | if (__put_super_and_need_restart(sb)) | 464 | if (__put_super_and_need_restart(sb)) |
466 | goto restart; | 465 | goto restart; |
467 | } | 466 | } |
468 | } | 467 | } |
469 | spin_unlock(&sb_lock); | 468 | spin_unlock(&sb_lock); |
470 | } | 469 | } |
471 | 470 | ||
472 | /* | 471 | /* |
473 | * Call the ->sync_fs super_op against all filesystems which are r/w and | 472 | * Call the ->sync_fs super_op against all filesystems which are r/w and |
474 | * which implement it. | 473 | * which implement it. |
475 | * | 474 | * |
476 | * This operation is careful to avoid the livelock which could easily happen | 475 | * This operation is careful to avoid the livelock which could easily happen |
477 | * if two or more filesystems are being continuously dirtied. s_need_sync_fs | 476 | * if two or more filesystems are being continuously dirtied. s_need_sync_fs |
478 | * is used only here. We set it against all filesystems and then clear it as | 477 | * is used only here. We set it against all filesystems and then clear it as |
479 | * we sync them. So redirtied filesystems are skipped. | 478 | * we sync them. So redirtied filesystems are skipped. |
480 | * | 479 | * |
481 | * But if process A is currently running sync_filesystems and then process B | 480 | * But if process A is currently running sync_filesystems and then process B |
482 | * calls sync_filesystems as well, process B will set all the s_need_sync_fs | 481 | * calls sync_filesystems as well, process B will set all the s_need_sync_fs |
483 | * flags again, which will cause process A to resync everything. Fix that with | 482 | * flags again, which will cause process A to resync everything. Fix that with |
484 | * a local mutex. | 483 | * a local mutex. |
485 | * | 484 | * |
486 | * (Fabian) Avoid sync_fs with clean fs & wait mode 0 | 485 | * (Fabian) Avoid sync_fs with clean fs & wait mode 0 |
487 | */ | 486 | */ |
488 | void sync_filesystems(int wait) | 487 | void sync_filesystems(int wait) |
489 | { | 488 | { |
490 | struct super_block *sb; | 489 | struct super_block *sb; |
491 | static DEFINE_MUTEX(mutex); | 490 | static DEFINE_MUTEX(mutex); |
492 | 491 | ||
493 | mutex_lock(&mutex); /* Could be down_interruptible */ | 492 | mutex_lock(&mutex); /* Could be down_interruptible */ |
494 | spin_lock(&sb_lock); | 493 | spin_lock(&sb_lock); |
495 | list_for_each_entry(sb, &super_blocks, s_list) { | 494 | list_for_each_entry(sb, &super_blocks, s_list) { |
496 | if (!sb->s_op->sync_fs) | 495 | if (!sb->s_op->sync_fs) |
497 | continue; | 496 | continue; |
498 | if (sb->s_flags & MS_RDONLY) | 497 | if (sb->s_flags & MS_RDONLY) |
499 | continue; | 498 | continue; |
500 | sb->s_need_sync_fs = 1; | 499 | sb->s_need_sync_fs = 1; |
501 | } | 500 | } |
502 | 501 | ||
503 | restart: | 502 | restart: |
504 | list_for_each_entry(sb, &super_blocks, s_list) { | 503 | list_for_each_entry(sb, &super_blocks, s_list) { |
505 | if (!sb->s_need_sync_fs) | 504 | if (!sb->s_need_sync_fs) |
506 | continue; | 505 | continue; |
507 | sb->s_need_sync_fs = 0; | 506 | sb->s_need_sync_fs = 0; |
508 | if (sb->s_flags & MS_RDONLY) | 507 | if (sb->s_flags & MS_RDONLY) |
509 | continue; /* hm. Was remounted r/o meanwhile */ | 508 | continue; /* hm. Was remounted r/o meanwhile */ |
510 | sb->s_count++; | 509 | sb->s_count++; |
511 | spin_unlock(&sb_lock); | 510 | spin_unlock(&sb_lock); |
512 | down_read(&sb->s_umount); | 511 | down_read(&sb->s_umount); |
513 | if (sb->s_root) | 512 | if (sb->s_root) |
514 | sb->s_op->sync_fs(sb, wait); | 513 | sb->s_op->sync_fs(sb, wait); |
515 | up_read(&sb->s_umount); | 514 | up_read(&sb->s_umount); |
516 | /* restart only when sb is no longer on the list */ | 515 | /* restart only when sb is no longer on the list */ |
517 | spin_lock(&sb_lock); | 516 | spin_lock(&sb_lock); |
518 | if (__put_super_and_need_restart(sb)) | 517 | if (__put_super_and_need_restart(sb)) |
519 | goto restart; | 518 | goto restart; |
520 | } | 519 | } |
521 | spin_unlock(&sb_lock); | 520 | spin_unlock(&sb_lock); |
522 | mutex_unlock(&mutex); | 521 | mutex_unlock(&mutex); |
523 | } | 522 | } |
524 | 523 | ||
525 | #ifdef CONFIG_BLOCK | 524 | #ifdef CONFIG_BLOCK |
526 | /* | 525 | /* |
527 | * Sync all block devices underlying some superblock | 526 | * Sync all block devices underlying some superblock |
528 | */ | 527 | */ |
529 | void sync_blockdevs(void) | 528 | void sync_blockdevs(void) |
530 | { | 529 | { |
531 | struct super_block *sb; | 530 | struct super_block *sb; |
532 | 531 | ||
533 | spin_lock(&sb_lock); | 532 | spin_lock(&sb_lock); |
534 | restart: | 533 | restart: |
535 | list_for_each_entry(sb, &super_blocks, s_list) { | 534 | list_for_each_entry(sb, &super_blocks, s_list) { |
536 | if (!sb->s_bdev) | 535 | if (!sb->s_bdev) |
537 | continue; | 536 | continue; |
538 | sb->s_count++; | 537 | sb->s_count++; |
539 | spin_unlock(&sb_lock); | 538 | spin_unlock(&sb_lock); |
540 | down_read(&sb->s_umount); | 539 | down_read(&sb->s_umount); |
541 | if (sb->s_root) | 540 | if (sb->s_root) |
542 | sync_blockdev(sb->s_bdev); | 541 | sync_blockdev(sb->s_bdev); |
543 | up_read(&sb->s_umount); | 542 | up_read(&sb->s_umount); |
544 | spin_lock(&sb_lock); | 543 | spin_lock(&sb_lock); |
545 | if (__put_super_and_need_restart(sb)) | 544 | if (__put_super_and_need_restart(sb)) |
546 | goto restart; | 545 | goto restart; |
547 | } | 546 | } |
548 | spin_unlock(&sb_lock); | 547 | spin_unlock(&sb_lock); |
549 | } | 548 | } |
550 | #endif | 549 | #endif |
551 | 550 | ||
552 | /** | 551 | /** |
553 | * get_super - get the superblock of a device | 552 | * get_super - get the superblock of a device |
554 | * @bdev: device to get the superblock for | 553 | * @bdev: device to get the superblock for |
555 | * | 554 | * |
556 | * Scans the superblock list and finds the superblock of the file system | 555 | * Scans the superblock list and finds the superblock of the file system |
557 | * mounted on the device given. %NULL is returned if no match is found. | 556 | * mounted on the device given. %NULL is returned if no match is found. |
558 | */ | 557 | */ |
559 | 558 | ||
560 | struct super_block * get_super(struct block_device *bdev) | 559 | struct super_block * get_super(struct block_device *bdev) |
561 | { | 560 | { |
562 | struct super_block *sb; | 561 | struct super_block *sb; |
563 | 562 | ||
564 | if (!bdev) | 563 | if (!bdev) |
565 | return NULL; | 564 | return NULL; |
566 | 565 | ||
567 | spin_lock(&sb_lock); | 566 | spin_lock(&sb_lock); |
568 | rescan: | 567 | rescan: |
569 | list_for_each_entry(sb, &super_blocks, s_list) { | 568 | list_for_each_entry(sb, &super_blocks, s_list) { |
570 | if (sb->s_bdev == bdev) { | 569 | if (sb->s_bdev == bdev) { |
571 | sb->s_count++; | 570 | sb->s_count++; |
572 | spin_unlock(&sb_lock); | 571 | spin_unlock(&sb_lock); |
573 | down_read(&sb->s_umount); | 572 | down_read(&sb->s_umount); |
574 | if (sb->s_root) | 573 | if (sb->s_root) |
575 | return sb; | 574 | return sb; |
576 | up_read(&sb->s_umount); | 575 | up_read(&sb->s_umount); |
577 | /* restart only when sb is no longer on the list */ | 576 | /* restart only when sb is no longer on the list */ |
578 | spin_lock(&sb_lock); | 577 | spin_lock(&sb_lock); |
579 | if (__put_super_and_need_restart(sb)) | 578 | if (__put_super_and_need_restart(sb)) |
580 | goto rescan; | 579 | goto rescan; |
581 | } | 580 | } |
582 | } | 581 | } |
583 | spin_unlock(&sb_lock); | 582 | spin_unlock(&sb_lock); |
584 | return NULL; | 583 | return NULL; |
585 | } | 584 | } |
586 | 585 | ||
587 | EXPORT_SYMBOL(get_super); | 586 | EXPORT_SYMBOL(get_super); |
588 | 587 | ||
589 | struct super_block * user_get_super(dev_t dev) | 588 | struct super_block * user_get_super(dev_t dev) |
590 | { | 589 | { |
591 | struct super_block *sb; | 590 | struct super_block *sb; |
592 | 591 | ||
593 | spin_lock(&sb_lock); | 592 | spin_lock(&sb_lock); |
594 | rescan: | 593 | rescan: |
595 | list_for_each_entry(sb, &super_blocks, s_list) { | 594 | list_for_each_entry(sb, &super_blocks, s_list) { |
596 | if (sb->s_dev == dev) { | 595 | if (sb->s_dev == dev) { |
597 | sb->s_count++; | 596 | sb->s_count++; |
598 | spin_unlock(&sb_lock); | 597 | spin_unlock(&sb_lock); |
599 | down_read(&sb->s_umount); | 598 | down_read(&sb->s_umount); |
600 | if (sb->s_root) | 599 | if (sb->s_root) |
601 | return sb; | 600 | return sb; |
602 | up_read(&sb->s_umount); | 601 | up_read(&sb->s_umount); |
603 | /* restart only when sb is no longer on the list */ | 602 | /* restart only when sb is no longer on the list */ |
604 | spin_lock(&sb_lock); | 603 | spin_lock(&sb_lock); |
605 | if (__put_super_and_need_restart(sb)) | 604 | if (__put_super_and_need_restart(sb)) |
606 | goto rescan; | 605 | goto rescan; |
607 | } | 606 | } |
608 | } | 607 | } |
609 | spin_unlock(&sb_lock); | 608 | spin_unlock(&sb_lock); |
610 | return NULL; | 609 | return NULL; |
611 | } | 610 | } |
612 | 611 | ||
613 | SYSCALL_DEFINE2(ustat, unsigned, dev, struct ustat __user *, ubuf) | 612 | SYSCALL_DEFINE2(ustat, unsigned, dev, struct ustat __user *, ubuf) |
614 | { | 613 | { |
615 | struct super_block *s; | 614 | struct super_block *s; |
616 | struct ustat tmp; | 615 | struct ustat tmp; |
617 | struct kstatfs sbuf; | 616 | struct kstatfs sbuf; |
618 | int err = -EINVAL; | 617 | int err = -EINVAL; |
619 | 618 | ||
620 | s = user_get_super(new_decode_dev(dev)); | 619 | s = user_get_super(new_decode_dev(dev)); |
621 | if (s == NULL) | 620 | if (s == NULL) |
622 | goto out; | 621 | goto out; |
623 | err = vfs_statfs(s->s_root, &sbuf); | 622 | err = vfs_statfs(s->s_root, &sbuf); |
624 | drop_super(s); | 623 | drop_super(s); |
625 | if (err) | 624 | if (err) |
626 | goto out; | 625 | goto out; |
627 | 626 | ||
628 | memset(&tmp,0,sizeof(struct ustat)); | 627 | memset(&tmp,0,sizeof(struct ustat)); |
629 | tmp.f_tfree = sbuf.f_bfree; | 628 | tmp.f_tfree = sbuf.f_bfree; |
630 | tmp.f_tinode = sbuf.f_ffree; | 629 | tmp.f_tinode = sbuf.f_ffree; |
631 | 630 | ||
632 | err = copy_to_user(ubuf,&tmp,sizeof(struct ustat)) ? -EFAULT : 0; | 631 | err = copy_to_user(ubuf,&tmp,sizeof(struct ustat)) ? -EFAULT : 0; |
633 | out: | 632 | out: |
634 | return err; | 633 | return err; |
635 | } | 634 | } |
636 | 635 | ||
637 | /** | 636 | /** |
638 | * do_remount_sb - asks filesystem to change mount options. | 637 | * do_remount_sb - asks filesystem to change mount options. |
639 | * @sb: superblock in question | 638 | * @sb: superblock in question |
640 | * @flags: numeric part of options | 639 | * @flags: numeric part of options |
641 | * @data: the rest of options | 640 | * @data: the rest of options |
642 | * @force: whether or not to force the change | 641 | * @force: whether or not to force the change |
643 | * | 642 | * |
644 | * Alters the mount options of a mounted file system. | 643 | * Alters the mount options of a mounted file system. |
645 | */ | 644 | */ |
646 | int do_remount_sb(struct super_block *sb, int flags, void *data, int force) | 645 | int do_remount_sb(struct super_block *sb, int flags, void *data, int force) |
647 | { | 646 | { |
648 | int retval; | 647 | int retval; |
649 | int remount_rw; | 648 | int remount_rw; |
650 | 649 | ||
651 | #ifdef CONFIG_BLOCK | 650 | #ifdef CONFIG_BLOCK |
652 | if (!(flags & MS_RDONLY) && bdev_read_only(sb->s_bdev)) | 651 | if (!(flags & MS_RDONLY) && bdev_read_only(sb->s_bdev)) |
653 | return -EACCES; | 652 | return -EACCES; |
654 | #endif | 653 | #endif |
655 | if (flags & MS_RDONLY) | 654 | if (flags & MS_RDONLY) |
656 | acct_auto_close(sb); | 655 | acct_auto_close(sb); |
657 | shrink_dcache_sb(sb); | 656 | shrink_dcache_sb(sb); |
658 | fsync_super(sb); | 657 | fsync_super(sb); |
659 | 658 | ||
660 | /* If we are remounting RDONLY and current sb is read/write, | 659 | /* If we are remounting RDONLY and current sb is read/write, |
661 | make sure there are no rw files opened */ | 660 | make sure there are no rw files opened */ |
662 | if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) { | 661 | if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) { |
663 | if (force) | 662 | if (force) |
664 | mark_files_ro(sb); | 663 | mark_files_ro(sb); |
665 | else if (!fs_may_remount_ro(sb)) | 664 | else if (!fs_may_remount_ro(sb)) |
666 | return -EBUSY; | 665 | return -EBUSY; |
667 | retval = vfs_dq_off(sb, 1); | 666 | retval = vfs_dq_off(sb, 1); |
668 | if (retval < 0 && retval != -ENOSYS) | 667 | if (retval < 0 && retval != -ENOSYS) |
669 | return -EBUSY; | 668 | return -EBUSY; |
670 | } | 669 | } |
671 | remount_rw = !(flags & MS_RDONLY) && (sb->s_flags & MS_RDONLY); | 670 | remount_rw = !(flags & MS_RDONLY) && (sb->s_flags & MS_RDONLY); |
672 | 671 | ||
673 | if (sb->s_op->remount_fs) { | 672 | if (sb->s_op->remount_fs) { |
674 | lock_super(sb); | 673 | lock_super(sb); |
675 | retval = sb->s_op->remount_fs(sb, &flags, data); | 674 | retval = sb->s_op->remount_fs(sb, &flags, data); |
676 | unlock_super(sb); | 675 | unlock_super(sb); |
677 | if (retval) | 676 | if (retval) |
678 | return retval; | 677 | return retval; |
679 | } | 678 | } |
680 | sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK); | 679 | sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK); |
681 | if (remount_rw) | 680 | if (remount_rw) |
682 | vfs_dq_quota_on_remount(sb); | 681 | vfs_dq_quota_on_remount(sb); |
683 | return 0; | 682 | return 0; |
684 | } | 683 | } |
685 | 684 | ||
686 | static void do_emergency_remount(struct work_struct *work) | 685 | static void do_emergency_remount(struct work_struct *work) |
687 | { | 686 | { |
688 | struct super_block *sb; | 687 | struct super_block *sb; |
689 | 688 | ||
690 | spin_lock(&sb_lock); | 689 | spin_lock(&sb_lock); |
691 | list_for_each_entry(sb, &super_blocks, s_list) { | 690 | list_for_each_entry(sb, &super_blocks, s_list) { |
692 | sb->s_count++; | 691 | sb->s_count++; |
693 | spin_unlock(&sb_lock); | 692 | spin_unlock(&sb_lock); |
694 | down_read(&sb->s_umount); | 693 | down_read(&sb->s_umount); |
695 | if (sb->s_root && sb->s_bdev && !(sb->s_flags & MS_RDONLY)) { | 694 | if (sb->s_root && sb->s_bdev && !(sb->s_flags & MS_RDONLY)) { |
696 | /* | 695 | /* |
697 | * ->remount_fs needs lock_kernel(). | 696 | * ->remount_fs needs lock_kernel(). |
698 | * | 697 | * |
699 | * What lock protects sb->s_flags?? | 698 | * What lock protects sb->s_flags?? |
700 | */ | 699 | */ |
701 | lock_kernel(); | 700 | lock_kernel(); |
702 | do_remount_sb(sb, MS_RDONLY, NULL, 1); | 701 | do_remount_sb(sb, MS_RDONLY, NULL, 1); |
703 | unlock_kernel(); | 702 | unlock_kernel(); |
704 | } | 703 | } |
705 | drop_super(sb); | 704 | drop_super(sb); |
706 | spin_lock(&sb_lock); | 705 | spin_lock(&sb_lock); |
707 | } | 706 | } |
708 | spin_unlock(&sb_lock); | 707 | spin_unlock(&sb_lock); |
709 | kfree(work); | 708 | kfree(work); |
710 | printk("Emergency Remount complete\n"); | 709 | printk("Emergency Remount complete\n"); |
711 | } | 710 | } |
712 | 711 | ||
713 | void emergency_remount(void) | 712 | void emergency_remount(void) |
714 | { | 713 | { |
715 | struct work_struct *work; | 714 | struct work_struct *work; |
716 | 715 | ||
717 | work = kmalloc(sizeof(*work), GFP_ATOMIC); | 716 | work = kmalloc(sizeof(*work), GFP_ATOMIC); |
718 | if (work) { | 717 | if (work) { |
719 | INIT_WORK(work, do_emergency_remount); | 718 | INIT_WORK(work, do_emergency_remount); |
720 | schedule_work(work); | 719 | schedule_work(work); |
721 | } | 720 | } |
722 | } | 721 | } |
723 | 722 | ||
724 | /* | 723 | /* |
725 | * Unnamed block devices are dummy devices used by virtual | 724 | * Unnamed block devices are dummy devices used by virtual |
726 | * filesystems which don't use real block-devices. -- jrs | 725 | * filesystems which don't use real block-devices. -- jrs |
727 | */ | 726 | */ |
728 | 727 | ||
729 | static DEFINE_IDA(unnamed_dev_ida); | 728 | static DEFINE_IDA(unnamed_dev_ida); |
730 | static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */ | 729 | static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */ |
731 | 730 | ||
732 | int set_anon_super(struct super_block *s, void *data) | 731 | int set_anon_super(struct super_block *s, void *data) |
733 | { | 732 | { |
734 | int dev; | 733 | int dev; |
735 | int error; | 734 | int error; |
736 | 735 | ||
737 | retry: | 736 | retry: |
738 | if (ida_pre_get(&unnamed_dev_ida, GFP_ATOMIC) == 0) | 737 | if (ida_pre_get(&unnamed_dev_ida, GFP_ATOMIC) == 0) |
739 | return -ENOMEM; | 738 | return -ENOMEM; |
740 | spin_lock(&unnamed_dev_lock); | 739 | spin_lock(&unnamed_dev_lock); |
741 | error = ida_get_new(&unnamed_dev_ida, &dev); | 740 | error = ida_get_new(&unnamed_dev_ida, &dev); |
742 | spin_unlock(&unnamed_dev_lock); | 741 | spin_unlock(&unnamed_dev_lock); |
743 | if (error == -EAGAIN) | 742 | if (error == -EAGAIN) |
744 | /* We raced and lost with another CPU. */ | 743 | /* We raced and lost with another CPU. */ |
745 | goto retry; | 744 | goto retry; |
746 | else if (error) | 745 | else if (error) |
747 | return -EAGAIN; | 746 | return -EAGAIN; |
748 | 747 | ||
749 | if ((dev & MAX_ID_MASK) == (1 << MINORBITS)) { | 748 | if ((dev & MAX_ID_MASK) == (1 << MINORBITS)) { |
750 | spin_lock(&unnamed_dev_lock); | 749 | spin_lock(&unnamed_dev_lock); |
751 | ida_remove(&unnamed_dev_ida, dev); | 750 | ida_remove(&unnamed_dev_ida, dev); |
752 | spin_unlock(&unnamed_dev_lock); | 751 | spin_unlock(&unnamed_dev_lock); |
753 | return -EMFILE; | 752 | return -EMFILE; |
754 | } | 753 | } |
755 | s->s_dev = MKDEV(0, dev & MINORMASK); | 754 | s->s_dev = MKDEV(0, dev & MINORMASK); |
756 | return 0; | 755 | return 0; |
757 | } | 756 | } |
758 | 757 | ||
759 | EXPORT_SYMBOL(set_anon_super); | 758 | EXPORT_SYMBOL(set_anon_super); |
760 | 759 | ||
761 | void kill_anon_super(struct super_block *sb) | 760 | void kill_anon_super(struct super_block *sb) |
762 | { | 761 | { |
763 | int slot = MINOR(sb->s_dev); | 762 | int slot = MINOR(sb->s_dev); |
764 | 763 | ||
765 | generic_shutdown_super(sb); | 764 | generic_shutdown_super(sb); |
766 | spin_lock(&unnamed_dev_lock); | 765 | spin_lock(&unnamed_dev_lock); |
767 | ida_remove(&unnamed_dev_ida, slot); | 766 | ida_remove(&unnamed_dev_ida, slot); |
768 | spin_unlock(&unnamed_dev_lock); | 767 | spin_unlock(&unnamed_dev_lock); |
769 | } | 768 | } |
770 | 769 | ||
771 | EXPORT_SYMBOL(kill_anon_super); | 770 | EXPORT_SYMBOL(kill_anon_super); |
772 | 771 | ||
773 | void kill_litter_super(struct super_block *sb) | 772 | void kill_litter_super(struct super_block *sb) |
774 | { | 773 | { |
775 | if (sb->s_root) | 774 | if (sb->s_root) |
776 | d_genocide(sb->s_root); | 775 | d_genocide(sb->s_root); |
777 | kill_anon_super(sb); | 776 | kill_anon_super(sb); |
778 | } | 777 | } |
779 | 778 | ||
780 | EXPORT_SYMBOL(kill_litter_super); | 779 | EXPORT_SYMBOL(kill_litter_super); |
781 | 780 | ||
782 | static int ns_test_super(struct super_block *sb, void *data) | 781 | static int ns_test_super(struct super_block *sb, void *data) |
783 | { | 782 | { |
784 | return sb->s_fs_info == data; | 783 | return sb->s_fs_info == data; |
785 | } | 784 | } |
786 | 785 | ||
787 | static int ns_set_super(struct super_block *sb, void *data) | 786 | static int ns_set_super(struct super_block *sb, void *data) |
788 | { | 787 | { |
789 | sb->s_fs_info = data; | 788 | sb->s_fs_info = data; |
790 | return set_anon_super(sb, NULL); | 789 | return set_anon_super(sb, NULL); |
791 | } | 790 | } |
792 | 791 | ||
793 | int get_sb_ns(struct file_system_type *fs_type, int flags, void *data, | 792 | int get_sb_ns(struct file_system_type *fs_type, int flags, void *data, |
794 | int (*fill_super)(struct super_block *, void *, int), | 793 | int (*fill_super)(struct super_block *, void *, int), |
795 | struct vfsmount *mnt) | 794 | struct vfsmount *mnt) |
796 | { | 795 | { |
797 | struct super_block *sb; | 796 | struct super_block *sb; |
798 | 797 | ||
799 | sb = sget(fs_type, ns_test_super, ns_set_super, data); | 798 | sb = sget(fs_type, ns_test_super, ns_set_super, data); |
800 | if (IS_ERR(sb)) | 799 | if (IS_ERR(sb)) |
801 | return PTR_ERR(sb); | 800 | return PTR_ERR(sb); |
802 | 801 | ||
803 | if (!sb->s_root) { | 802 | if (!sb->s_root) { |
804 | int err; | 803 | int err; |
805 | sb->s_flags = flags; | 804 | sb->s_flags = flags; |
806 | err = fill_super(sb, data, flags & MS_SILENT ? 1 : 0); | 805 | err = fill_super(sb, data, flags & MS_SILENT ? 1 : 0); |
807 | if (err) { | 806 | if (err) { |
808 | deactivate_locked_super(sb); | 807 | deactivate_locked_super(sb); |
809 | return err; | 808 | return err; |
810 | } | 809 | } |
811 | 810 | ||
812 | sb->s_flags |= MS_ACTIVE; | 811 | sb->s_flags |= MS_ACTIVE; |
813 | } | 812 | } |
814 | 813 | ||
815 | simple_set_mnt(mnt, sb); | 814 | simple_set_mnt(mnt, sb); |
816 | return 0; | 815 | return 0; |
817 | } | 816 | } |
818 | 817 | ||
819 | EXPORT_SYMBOL(get_sb_ns); | 818 | EXPORT_SYMBOL(get_sb_ns); |
820 | 819 | ||
821 | #ifdef CONFIG_BLOCK | 820 | #ifdef CONFIG_BLOCK |
822 | static int set_bdev_super(struct super_block *s, void *data) | 821 | static int set_bdev_super(struct super_block *s, void *data) |
823 | { | 822 | { |
824 | s->s_bdev = data; | 823 | s->s_bdev = data; |
825 | s->s_dev = s->s_bdev->bd_dev; | 824 | s->s_dev = s->s_bdev->bd_dev; |
826 | return 0; | 825 | return 0; |
827 | } | 826 | } |
828 | 827 | ||
829 | static int test_bdev_super(struct super_block *s, void *data) | 828 | static int test_bdev_super(struct super_block *s, void *data) |
830 | { | 829 | { |
831 | return (void *)s->s_bdev == data; | 830 | return (void *)s->s_bdev == data; |
832 | } | 831 | } |
833 | 832 | ||
834 | int get_sb_bdev(struct file_system_type *fs_type, | 833 | int get_sb_bdev(struct file_system_type *fs_type, |
835 | int flags, const char *dev_name, void *data, | 834 | int flags, const char *dev_name, void *data, |
836 | int (*fill_super)(struct super_block *, void *, int), | 835 | int (*fill_super)(struct super_block *, void *, int), |
837 | struct vfsmount *mnt) | 836 | struct vfsmount *mnt) |
838 | { | 837 | { |
839 | struct block_device *bdev; | 838 | struct block_device *bdev; |
840 | struct super_block *s; | 839 | struct super_block *s; |
841 | fmode_t mode = FMODE_READ; | 840 | fmode_t mode = FMODE_READ; |
842 | int error = 0; | 841 | int error = 0; |
843 | 842 | ||
844 | if (!(flags & MS_RDONLY)) | 843 | if (!(flags & MS_RDONLY)) |
845 | mode |= FMODE_WRITE; | 844 | mode |= FMODE_WRITE; |
846 | 845 | ||
847 | bdev = open_bdev_exclusive(dev_name, mode, fs_type); | 846 | bdev = open_bdev_exclusive(dev_name, mode, fs_type); |
848 | if (IS_ERR(bdev)) | 847 | if (IS_ERR(bdev)) |
849 | return PTR_ERR(bdev); | 848 | return PTR_ERR(bdev); |
850 | 849 | ||
851 | /* | 850 | /* |
852 | * once the super is inserted into the list by sget, s_umount | 851 | * once the super is inserted into the list by sget, s_umount |
853 | * will protect the lockfs code from trying to start a snapshot | 852 | * will protect the lockfs code from trying to start a snapshot |
854 | * while we are mounting | 853 | * while we are mounting |
855 | */ | 854 | */ |
856 | down(&bdev->bd_mount_sem); | 855 | down(&bdev->bd_mount_sem); |
857 | s = sget(fs_type, test_bdev_super, set_bdev_super, bdev); | 856 | s = sget(fs_type, test_bdev_super, set_bdev_super, bdev); |
858 | up(&bdev->bd_mount_sem); | 857 | up(&bdev->bd_mount_sem); |
859 | if (IS_ERR(s)) | 858 | if (IS_ERR(s)) |
860 | goto error_s; | 859 | goto error_s; |
861 | 860 | ||
862 | if (s->s_root) { | 861 | if (s->s_root) { |
863 | if ((flags ^ s->s_flags) & MS_RDONLY) { | 862 | if ((flags ^ s->s_flags) & MS_RDONLY) { |
864 | deactivate_locked_super(s); | 863 | deactivate_locked_super(s); |
865 | error = -EBUSY; | 864 | error = -EBUSY; |
866 | goto error_bdev; | 865 | goto error_bdev; |
867 | } | 866 | } |
868 | 867 | ||
869 | close_bdev_exclusive(bdev, mode); | 868 | close_bdev_exclusive(bdev, mode); |
870 | } else { | 869 | } else { |
871 | char b[BDEVNAME_SIZE]; | 870 | char b[BDEVNAME_SIZE]; |
872 | 871 | ||
873 | s->s_flags = flags; | 872 | s->s_flags = flags; |
874 | s->s_mode = mode; | 873 | s->s_mode = mode; |
875 | strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id)); | 874 | strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id)); |
876 | sb_set_blocksize(s, block_size(bdev)); | 875 | sb_set_blocksize(s, block_size(bdev)); |
877 | error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); | 876 | error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); |
878 | if (error) { | 877 | if (error) { |
879 | deactivate_locked_super(s); | 878 | deactivate_locked_super(s); |
880 | goto error; | 879 | goto error; |
881 | } | 880 | } |
882 | 881 | ||
883 | s->s_flags |= MS_ACTIVE; | 882 | s->s_flags |= MS_ACTIVE; |
884 | bdev->bd_super = s; | 883 | bdev->bd_super = s; |
885 | } | 884 | } |
886 | 885 | ||
887 | simple_set_mnt(mnt, s); | 886 | simple_set_mnt(mnt, s); |
888 | return 0; | 887 | return 0; |
889 | 888 | ||
890 | error_s: | 889 | error_s: |
891 | error = PTR_ERR(s); | 890 | error = PTR_ERR(s); |
892 | error_bdev: | 891 | error_bdev: |
893 | close_bdev_exclusive(bdev, mode); | 892 | close_bdev_exclusive(bdev, mode); |
894 | error: | 893 | error: |
895 | return error; | 894 | return error; |
896 | } | 895 | } |
897 | 896 | ||
898 | EXPORT_SYMBOL(get_sb_bdev); | 897 | EXPORT_SYMBOL(get_sb_bdev); |
899 | 898 | ||
900 | void kill_block_super(struct super_block *sb) | 899 | void kill_block_super(struct super_block *sb) |
901 | { | 900 | { |
902 | struct block_device *bdev = sb->s_bdev; | 901 | struct block_device *bdev = sb->s_bdev; |
903 | fmode_t mode = sb->s_mode; | 902 | fmode_t mode = sb->s_mode; |
904 | 903 | ||
905 | bdev->bd_super = NULL; | 904 | bdev->bd_super = NULL; |
906 | generic_shutdown_super(sb); | 905 | generic_shutdown_super(sb); |
907 | sync_blockdev(bdev); | 906 | sync_blockdev(bdev); |
908 | close_bdev_exclusive(bdev, mode); | 907 | close_bdev_exclusive(bdev, mode); |
909 | } | 908 | } |
910 | 909 | ||
911 | EXPORT_SYMBOL(kill_block_super); | 910 | EXPORT_SYMBOL(kill_block_super); |
912 | #endif | 911 | #endif |
913 | 912 | ||
914 | int get_sb_nodev(struct file_system_type *fs_type, | 913 | int get_sb_nodev(struct file_system_type *fs_type, |
915 | int flags, void *data, | 914 | int flags, void *data, |
916 | int (*fill_super)(struct super_block *, void *, int), | 915 | int (*fill_super)(struct super_block *, void *, int), |
917 | struct vfsmount *mnt) | 916 | struct vfsmount *mnt) |
918 | { | 917 | { |
919 | int error; | 918 | int error; |
920 | struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL); | 919 | struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL); |
921 | 920 | ||
922 | if (IS_ERR(s)) | 921 | if (IS_ERR(s)) |
923 | return PTR_ERR(s); | 922 | return PTR_ERR(s); |
924 | 923 | ||
925 | s->s_flags = flags; | 924 | s->s_flags = flags; |
926 | 925 | ||
927 | error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); | 926 | error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); |
928 | if (error) { | 927 | if (error) { |
929 | deactivate_locked_super(s); | 928 | deactivate_locked_super(s); |
930 | return error; | 929 | return error; |
931 | } | 930 | } |
932 | s->s_flags |= MS_ACTIVE; | 931 | s->s_flags |= MS_ACTIVE; |
933 | simple_set_mnt(mnt, s); | 932 | simple_set_mnt(mnt, s); |
934 | return 0; | 933 | return 0; |
935 | } | 934 | } |
936 | 935 | ||
937 | EXPORT_SYMBOL(get_sb_nodev); | 936 | EXPORT_SYMBOL(get_sb_nodev); |
938 | 937 | ||
939 | static int compare_single(struct super_block *s, void *p) | 938 | static int compare_single(struct super_block *s, void *p) |
940 | { | 939 | { |
941 | return 1; | 940 | return 1; |
942 | } | 941 | } |
943 | 942 | ||
944 | int get_sb_single(struct file_system_type *fs_type, | 943 | int get_sb_single(struct file_system_type *fs_type, |
945 | int flags, void *data, | 944 | int flags, void *data, |
946 | int (*fill_super)(struct super_block *, void *, int), | 945 | int (*fill_super)(struct super_block *, void *, int), |
947 | struct vfsmount *mnt) | 946 | struct vfsmount *mnt) |
948 | { | 947 | { |
949 | struct super_block *s; | 948 | struct super_block *s; |
950 | int error; | 949 | int error; |
951 | 950 | ||
952 | s = sget(fs_type, compare_single, set_anon_super, NULL); | 951 | s = sget(fs_type, compare_single, set_anon_super, NULL); |
953 | if (IS_ERR(s)) | 952 | if (IS_ERR(s)) |
954 | return PTR_ERR(s); | 953 | return PTR_ERR(s); |
955 | if (!s->s_root) { | 954 | if (!s->s_root) { |
956 | s->s_flags = flags; | 955 | s->s_flags = flags; |
957 | error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); | 956 | error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); |
958 | if (error) { | 957 | if (error) { |
959 | deactivate_locked_super(s); | 958 | deactivate_locked_super(s); |
960 | return error; | 959 | return error; |
961 | } | 960 | } |
962 | s->s_flags |= MS_ACTIVE; | 961 | s->s_flags |= MS_ACTIVE; |
963 | } | 962 | } |
964 | do_remount_sb(s, flags, data, 0); | 963 | do_remount_sb(s, flags, data, 0); |
965 | simple_set_mnt(mnt, s); | 964 | simple_set_mnt(mnt, s); |
966 | return 0; | 965 | return 0; |
967 | } | 966 | } |
968 | 967 | ||
969 | EXPORT_SYMBOL(get_sb_single); | 968 | EXPORT_SYMBOL(get_sb_single); |
970 | 969 | ||
971 | struct vfsmount * | 970 | struct vfsmount * |
972 | vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data) | 971 | vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data) |
973 | { | 972 | { |
974 | struct vfsmount *mnt; | 973 | struct vfsmount *mnt; |
975 | char *secdata = NULL; | 974 | char *secdata = NULL; |
976 | int error; | 975 | int error; |
977 | 976 | ||
978 | if (!type) | 977 | if (!type) |
979 | return ERR_PTR(-ENODEV); | 978 | return ERR_PTR(-ENODEV); |
980 | 979 | ||
981 | error = -ENOMEM; | 980 | error = -ENOMEM; |
982 | mnt = alloc_vfsmnt(name); | 981 | mnt = alloc_vfsmnt(name); |
983 | if (!mnt) | 982 | if (!mnt) |
984 | goto out; | 983 | goto out; |
985 | 984 | ||
986 | if (data && !(type->fs_flags & FS_BINARY_MOUNTDATA)) { | 985 | if (data && !(type->fs_flags & FS_BINARY_MOUNTDATA)) { |
987 | secdata = alloc_secdata(); | 986 | secdata = alloc_secdata(); |
988 | if (!secdata) | 987 | if (!secdata) |
989 | goto out_mnt; | 988 | goto out_mnt; |
990 | 989 | ||
991 | error = security_sb_copy_data(data, secdata); | 990 | error = security_sb_copy_data(data, secdata); |
992 | if (error) | 991 | if (error) |
993 | goto out_free_secdata; | 992 | goto out_free_secdata; |
994 | } | 993 | } |
995 | 994 | ||
996 | error = type->get_sb(type, flags, name, data, mnt); | 995 | error = type->get_sb(type, flags, name, data, mnt); |
997 | if (error < 0) | 996 | if (error < 0) |
998 | goto out_free_secdata; | 997 | goto out_free_secdata; |
999 | BUG_ON(!mnt->mnt_sb); | 998 | BUG_ON(!mnt->mnt_sb); |
1000 | 999 | ||
1001 | error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata); | 1000 | error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata); |
1002 | if (error) | 1001 | if (error) |
1003 | goto out_sb; | 1002 | goto out_sb; |
1004 | 1003 | ||
1005 | mnt->mnt_mountpoint = mnt->mnt_root; | 1004 | mnt->mnt_mountpoint = mnt->mnt_root; |
1006 | mnt->mnt_parent = mnt; | 1005 | mnt->mnt_parent = mnt; |
1007 | up_write(&mnt->mnt_sb->s_umount); | 1006 | up_write(&mnt->mnt_sb->s_umount); |
1008 | free_secdata(secdata); | 1007 | free_secdata(secdata); |
1009 | return mnt; | 1008 | return mnt; |
1010 | out_sb: | 1009 | out_sb: |
1011 | dput(mnt->mnt_root); | 1010 | dput(mnt->mnt_root); |
1012 | deactivate_locked_super(mnt->mnt_sb); | 1011 | deactivate_locked_super(mnt->mnt_sb); |
1013 | out_free_secdata: | 1012 | out_free_secdata: |
1014 | free_secdata(secdata); | 1013 | free_secdata(secdata); |
1015 | out_mnt: | 1014 | out_mnt: |
1016 | free_vfsmnt(mnt); | 1015 | free_vfsmnt(mnt); |
1017 | out: | 1016 | out: |
1018 | return ERR_PTR(error); | 1017 | return ERR_PTR(error); |
1019 | } | 1018 | } |
1020 | 1019 | ||
1021 | EXPORT_SYMBOL_GPL(vfs_kern_mount); | 1020 | EXPORT_SYMBOL_GPL(vfs_kern_mount); |
1022 | 1021 | ||
1023 | static struct vfsmount *fs_set_subtype(struct vfsmount *mnt, const char *fstype) | 1022 | static struct vfsmount *fs_set_subtype(struct vfsmount *mnt, const char *fstype) |
1024 | { | 1023 | { |
1025 | int err; | 1024 | int err; |
1026 | const char *subtype = strchr(fstype, '.'); | 1025 | const char *subtype = strchr(fstype, '.'); |
1027 | if (subtype) { | 1026 | if (subtype) { |
1028 | subtype++; | 1027 | subtype++; |
1029 | err = -EINVAL; | 1028 | err = -EINVAL; |
1030 | if (!subtype[0]) | 1029 | if (!subtype[0]) |
1031 | goto err; | 1030 | goto err; |
1032 | } else | 1031 | } else |
1033 | subtype = ""; | 1032 | subtype = ""; |
1034 | 1033 | ||
1035 | mnt->mnt_sb->s_subtype = kstrdup(subtype, GFP_KERNEL); | 1034 | mnt->mnt_sb->s_subtype = kstrdup(subtype, GFP_KERNEL); |
1036 | err = -ENOMEM; | 1035 | err = -ENOMEM; |
1037 | if (!mnt->mnt_sb->s_subtype) | 1036 | if (!mnt->mnt_sb->s_subtype) |
1038 | goto err; | 1037 | goto err; |
1039 | return mnt; | 1038 | return mnt; |
1040 | 1039 | ||
1041 | err: | 1040 | err: |
1042 | mntput(mnt); | 1041 | mntput(mnt); |
1043 | return ERR_PTR(err); | 1042 | return ERR_PTR(err); |
1044 | } | 1043 | } |
1045 | 1044 | ||
1046 | struct vfsmount * | 1045 | struct vfsmount * |
1047 | do_kern_mount(const char *fstype, int flags, const char *name, void *data) | 1046 | do_kern_mount(const char *fstype, int flags, const char *name, void *data) |
1048 | { | 1047 | { |
1049 | struct file_system_type *type = get_fs_type(fstype); | 1048 | struct file_system_type *type = get_fs_type(fstype); |
1050 | struct vfsmount *mnt; | 1049 | struct vfsmount *mnt; |
1051 | if (!type) | 1050 | if (!type) |
1052 | return ERR_PTR(-ENODEV); | 1051 | return ERR_PTR(-ENODEV); |
1053 | mnt = vfs_kern_mount(type, flags, name, data); | 1052 | mnt = vfs_kern_mount(type, flags, name, data); |
1054 | if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) && | 1053 | if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) && |
1055 | !mnt->mnt_sb->s_subtype) | 1054 | !mnt->mnt_sb->s_subtype) |
1056 | mnt = fs_set_subtype(mnt, fstype); | 1055 | mnt = fs_set_subtype(mnt, fstype); |
1057 | put_filesystem(type); | 1056 | put_filesystem(type); |
1058 | return mnt; | 1057 | return mnt; |
1059 | } | 1058 | } |
1060 | EXPORT_SYMBOL_GPL(do_kern_mount); | 1059 | EXPORT_SYMBOL_GPL(do_kern_mount); |
1061 | 1060 | ||
1062 | struct vfsmount *kern_mount_data(struct file_system_type *type, void *data) | 1061 | struct vfsmount *kern_mount_data(struct file_system_type *type, void *data) |
1063 | { | 1062 | { |
1064 | return vfs_kern_mount(type, MS_KERNMOUNT, type->name, data); | 1063 | return vfs_kern_mount(type, MS_KERNMOUNT, type->name, data); |
1065 | } | 1064 | } |
1066 | 1065 | ||
1067 | EXPORT_SYMBOL_GPL(kern_mount_data); | 1066 | EXPORT_SYMBOL_GPL(kern_mount_data); |
1068 | 1067 |
include/linux/fs.h
1 | #ifndef _LINUX_FS_H | 1 | #ifndef _LINUX_FS_H |
2 | #define _LINUX_FS_H | 2 | #define _LINUX_FS_H |
3 | 3 | ||
4 | /* | 4 | /* |
5 | * This file has definitions for some important file table | 5 | * This file has definitions for some important file table |
6 | * structures etc. | 6 | * structures etc. |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/limits.h> | 9 | #include <linux/limits.h> |
10 | #include <linux/ioctl.h> | 10 | #include <linux/ioctl.h> |
11 | 11 | ||
12 | /* | 12 | /* |
13 | * It's silly to have NR_OPEN bigger than NR_FILE, but you can change | 13 | * It's silly to have NR_OPEN bigger than NR_FILE, but you can change |
14 | * the file limit at runtime and only root can increase the per-process | 14 | * the file limit at runtime and only root can increase the per-process |
15 | * nr_file rlimit, so it's safe to set up a ridiculously high absolute | 15 | * nr_file rlimit, so it's safe to set up a ridiculously high absolute |
16 | * upper limit on files-per-process. | 16 | * upper limit on files-per-process. |
17 | * | 17 | * |
18 | * Some programs (notably those using select()) may have to be | 18 | * Some programs (notably those using select()) may have to be |
19 | * recompiled to take full advantage of the new limits.. | 19 | * recompiled to take full advantage of the new limits.. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | /* Fixed constants first: */ | 22 | /* Fixed constants first: */ |
23 | #undef NR_OPEN | 23 | #undef NR_OPEN |
24 | #define INR_OPEN 1024 /* Initial setting for nfile rlimits */ | 24 | #define INR_OPEN 1024 /* Initial setting for nfile rlimits */ |
25 | 25 | ||
26 | #define BLOCK_SIZE_BITS 10 | 26 | #define BLOCK_SIZE_BITS 10 |
27 | #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS) | 27 | #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS) |
28 | 28 | ||
29 | #define SEEK_SET 0 /* seek relative to beginning of file */ | 29 | #define SEEK_SET 0 /* seek relative to beginning of file */ |
30 | #define SEEK_CUR 1 /* seek relative to current file position */ | 30 | #define SEEK_CUR 1 /* seek relative to current file position */ |
31 | #define SEEK_END 2 /* seek relative to end of file */ | 31 | #define SEEK_END 2 /* seek relative to end of file */ |
32 | #define SEEK_MAX SEEK_END | 32 | #define SEEK_MAX SEEK_END |
33 | 33 | ||
34 | /* And dynamically-tunable limits and defaults: */ | 34 | /* And dynamically-tunable limits and defaults: */ |
35 | struct files_stat_struct { | 35 | struct files_stat_struct { |
36 | int nr_files; /* read only */ | 36 | int nr_files; /* read only */ |
37 | int nr_free_files; /* read only */ | 37 | int nr_free_files; /* read only */ |
38 | int max_files; /* tunable */ | 38 | int max_files; /* tunable */ |
39 | }; | 39 | }; |
40 | 40 | ||
41 | struct inodes_stat_t { | 41 | struct inodes_stat_t { |
42 | int nr_inodes; | 42 | int nr_inodes; |
43 | int nr_unused; | 43 | int nr_unused; |
44 | int dummy[5]; /* padding for sysctl ABI compatibility */ | 44 | int dummy[5]; /* padding for sysctl ABI compatibility */ |
45 | }; | 45 | }; |
46 | 46 | ||
47 | 47 | ||
48 | #define NR_FILE 8192 /* this can well be larger on a larger system */ | 48 | #define NR_FILE 8192 /* this can well be larger on a larger system */ |
49 | 49 | ||
50 | #define MAY_EXEC 1 | 50 | #define MAY_EXEC 1 |
51 | #define MAY_WRITE 2 | 51 | #define MAY_WRITE 2 |
52 | #define MAY_READ 4 | 52 | #define MAY_READ 4 |
53 | #define MAY_APPEND 8 | 53 | #define MAY_APPEND 8 |
54 | #define MAY_ACCESS 16 | 54 | #define MAY_ACCESS 16 |
55 | #define MAY_OPEN 32 | 55 | #define MAY_OPEN 32 |
56 | 56 | ||
57 | /* | 57 | /* |
58 | * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond | 58 | * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond |
59 | * to O_WRONLY and O_RDWR via the strange trick in __dentry_open() | 59 | * to O_WRONLY and O_RDWR via the strange trick in __dentry_open() |
60 | */ | 60 | */ |
61 | 61 | ||
62 | /* file is open for reading */ | 62 | /* file is open for reading */ |
63 | #define FMODE_READ ((__force fmode_t)1) | 63 | #define FMODE_READ ((__force fmode_t)1) |
64 | /* file is open for writing */ | 64 | /* file is open for writing */ |
65 | #define FMODE_WRITE ((__force fmode_t)2) | 65 | #define FMODE_WRITE ((__force fmode_t)2) |
66 | /* file is seekable */ | 66 | /* file is seekable */ |
67 | #define FMODE_LSEEK ((__force fmode_t)4) | 67 | #define FMODE_LSEEK ((__force fmode_t)4) |
68 | /* file can be accessed using pread */ | 68 | /* file can be accessed using pread */ |
69 | #define FMODE_PREAD ((__force fmode_t)8) | 69 | #define FMODE_PREAD ((__force fmode_t)8) |
70 | /* file can be accessed using pwrite */ | 70 | /* file can be accessed using pwrite */ |
71 | #define FMODE_PWRITE ((__force fmode_t)16) | 71 | #define FMODE_PWRITE ((__force fmode_t)16) |
72 | /* File is opened for execution with sys_execve / sys_uselib */ | 72 | /* File is opened for execution with sys_execve / sys_uselib */ |
73 | #define FMODE_EXEC ((__force fmode_t)32) | 73 | #define FMODE_EXEC ((__force fmode_t)32) |
74 | /* File is opened with O_NDELAY (only set for block devices) */ | 74 | /* File is opened with O_NDELAY (only set for block devices) */ |
75 | #define FMODE_NDELAY ((__force fmode_t)64) | 75 | #define FMODE_NDELAY ((__force fmode_t)64) |
76 | /* File is opened with O_EXCL (only set for block devices) */ | 76 | /* File is opened with O_EXCL (only set for block devices) */ |
77 | #define FMODE_EXCL ((__force fmode_t)128) | 77 | #define FMODE_EXCL ((__force fmode_t)128) |
78 | /* File is opened using open(.., 3, ..) and is writeable only for ioctls | 78 | /* File is opened using open(.., 3, ..) and is writeable only for ioctls |
79 | (specialy hack for floppy.c) */ | 79 | (specialy hack for floppy.c) */ |
80 | #define FMODE_WRITE_IOCTL ((__force fmode_t)256) | 80 | #define FMODE_WRITE_IOCTL ((__force fmode_t)256) |
81 | 81 | ||
82 | /* | 82 | /* |
83 | * Don't update ctime and mtime. | 83 | * Don't update ctime and mtime. |
84 | * | 84 | * |
85 | * Currently a special hack for the XFS open_by_handle ioctl, but we'll | 85 | * Currently a special hack for the XFS open_by_handle ioctl, but we'll |
86 | * hopefully graduate it to a proper O_CMTIME flag supported by open(2) soon. | 86 | * hopefully graduate it to a proper O_CMTIME flag supported by open(2) soon. |
87 | */ | 87 | */ |
88 | #define FMODE_NOCMTIME ((__force fmode_t)2048) | 88 | #define FMODE_NOCMTIME ((__force fmode_t)2048) |
89 | 89 | ||
90 | /* | 90 | /* |
91 | * The below are the various read and write types that we support. Some of | 91 | * The below are the various read and write types that we support. Some of |
92 | * them include behavioral modifiers that send information down to the | 92 | * them include behavioral modifiers that send information down to the |
93 | * block layer and IO scheduler. Terminology: | 93 | * block layer and IO scheduler. Terminology: |
94 | * | 94 | * |
95 | * The block layer uses device plugging to defer IO a little bit, in | 95 | * The block layer uses device plugging to defer IO a little bit, in |
96 | * the hope that we will see more IO very shortly. This increases | 96 | * the hope that we will see more IO very shortly. This increases |
97 | * coalescing of adjacent IO and thus reduces the number of IOs we | 97 | * coalescing of adjacent IO and thus reduces the number of IOs we |
98 | * have to send to the device. It also allows for better queuing, | 98 | * have to send to the device. It also allows for better queuing, |
99 | * if the IO isn't mergeable. If the caller is going to be waiting | 99 | * if the IO isn't mergeable. If the caller is going to be waiting |
100 | * for the IO, then he must ensure that the device is unplugged so | 100 | * for the IO, then he must ensure that the device is unplugged so |
101 | * that the IO is dispatched to the driver. | 101 | * that the IO is dispatched to the driver. |
102 | * | 102 | * |
103 | * All IO is handled async in Linux. This is fine for background | 103 | * All IO is handled async in Linux. This is fine for background |
104 | * writes, but for reads or writes that someone waits for completion | 104 | * writes, but for reads or writes that someone waits for completion |
105 | * on, we want to notify the block layer and IO scheduler so that they | 105 | * on, we want to notify the block layer and IO scheduler so that they |
106 | * know about it. That allows them to make better scheduling | 106 | * know about it. That allows them to make better scheduling |
107 | * decisions. So when the below references 'sync' and 'async', it | 107 | * decisions. So when the below references 'sync' and 'async', it |
108 | * is referencing this priority hint. | 108 | * is referencing this priority hint. |
109 | * | 109 | * |
110 | * With that in mind, the available types are: | 110 | * With that in mind, the available types are: |
111 | * | 111 | * |
112 | * READ A normal read operation. Device will be plugged. | 112 | * READ A normal read operation. Device will be plugged. |
113 | * READ_SYNC A synchronous read. Device is not plugged, caller can | 113 | * READ_SYNC A synchronous read. Device is not plugged, caller can |
114 | * immediately wait on this read without caring about | 114 | * immediately wait on this read without caring about |
115 | * unplugging. | 115 | * unplugging. |
116 | * READA Used for read-ahead operations. Lower priority, and the | 116 | * READA Used for read-ahead operations. Lower priority, and the |
117 | * block layer could (in theory) choose to ignore this | 117 | * block layer could (in theory) choose to ignore this |
118 | * request if it runs into resource problems. | 118 | * request if it runs into resource problems. |
119 | * WRITE A normal async write. Device will be plugged. | 119 | * WRITE A normal async write. Device will be plugged. |
120 | * SWRITE Like WRITE, but a special case for ll_rw_block() that | 120 | * SWRITE Like WRITE, but a special case for ll_rw_block() that |
121 | * tells it to lock the buffer first. Normally a buffer | 121 | * tells it to lock the buffer first. Normally a buffer |
122 | * must be locked before doing IO. | 122 | * must be locked before doing IO. |
123 | * WRITE_SYNC_PLUG Synchronous write. Identical to WRITE, but passes down | 123 | * WRITE_SYNC_PLUG Synchronous write. Identical to WRITE, but passes down |
124 | * the hint that someone will be waiting on this IO | 124 | * the hint that someone will be waiting on this IO |
125 | * shortly. The device must still be unplugged explicitly, | 125 | * shortly. The device must still be unplugged explicitly, |
126 | * WRITE_SYNC_PLUG does not do this as we could be | 126 | * WRITE_SYNC_PLUG does not do this as we could be |
127 | * submitting more writes before we actually wait on any | 127 | * submitting more writes before we actually wait on any |
128 | * of them. | 128 | * of them. |
129 | * WRITE_SYNC Like WRITE_SYNC_PLUG, but also unplugs the device | 129 | * WRITE_SYNC Like WRITE_SYNC_PLUG, but also unplugs the device |
130 | * immediately after submission. The write equivalent | 130 | * immediately after submission. The write equivalent |
131 | * of READ_SYNC. | 131 | * of READ_SYNC. |
132 | * WRITE_ODIRECT Special case write for O_DIRECT only. | 132 | * WRITE_ODIRECT Special case write for O_DIRECT only. |
133 | * SWRITE_SYNC | 133 | * SWRITE_SYNC |
134 | * SWRITE_SYNC_PLUG Like WRITE_SYNC/WRITE_SYNC_PLUG, but locks the buffer. | 134 | * SWRITE_SYNC_PLUG Like WRITE_SYNC/WRITE_SYNC_PLUG, but locks the buffer. |
135 | * See SWRITE. | 135 | * See SWRITE. |
136 | * WRITE_BARRIER Like WRITE, but tells the block layer that all | 136 | * WRITE_BARRIER Like WRITE, but tells the block layer that all |
137 | * previously submitted writes must be safely on storage | 137 | * previously submitted writes must be safely on storage |
138 | * before this one is started. Also guarantees that when | 138 | * before this one is started. Also guarantees that when |
139 | * this write is complete, it itself is also safely on | 139 | * this write is complete, it itself is also safely on |
140 | * storage. Prevents reordering of writes on both sides | 140 | * storage. Prevents reordering of writes on both sides |
141 | * of this IO. | 141 | * of this IO. |
142 | * | 142 | * |
143 | */ | 143 | */ |
144 | #define RW_MASK 1 | 144 | #define RW_MASK 1 |
145 | #define RWA_MASK 2 | 145 | #define RWA_MASK 2 |
146 | #define READ 0 | 146 | #define READ 0 |
147 | #define WRITE 1 | 147 | #define WRITE 1 |
148 | #define READA 2 /* read-ahead - don't block if no resources */ | 148 | #define READA 2 /* read-ahead - don't block if no resources */ |
149 | #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */ | 149 | #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */ |
150 | #define READ_SYNC (READ | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG)) | 150 | #define READ_SYNC (READ | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG)) |
151 | #define READ_META (READ | (1 << BIO_RW_META)) | 151 | #define READ_META (READ | (1 << BIO_RW_META)) |
152 | #define WRITE_SYNC_PLUG (WRITE | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_NOIDLE)) | 152 | #define WRITE_SYNC_PLUG (WRITE | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_NOIDLE)) |
153 | #define WRITE_SYNC (WRITE_SYNC_PLUG | (1 << BIO_RW_UNPLUG)) | 153 | #define WRITE_SYNC (WRITE_SYNC_PLUG | (1 << BIO_RW_UNPLUG)) |
154 | #define WRITE_ODIRECT (WRITE | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG)) | 154 | #define WRITE_ODIRECT (WRITE | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG)) |
155 | #define SWRITE_SYNC_PLUG \ | 155 | #define SWRITE_SYNC_PLUG \ |
156 | (SWRITE | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_NOIDLE)) | 156 | (SWRITE | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_NOIDLE)) |
157 | #define SWRITE_SYNC (SWRITE_SYNC_PLUG | (1 << BIO_RW_UNPLUG)) | 157 | #define SWRITE_SYNC (SWRITE_SYNC_PLUG | (1 << BIO_RW_UNPLUG)) |
158 | #define WRITE_BARRIER (WRITE | (1 << BIO_RW_BARRIER)) | 158 | #define WRITE_BARRIER (WRITE | (1 << BIO_RW_BARRIER)) |
159 | 159 | ||
160 | /* | 160 | /* |
161 | * These aren't really reads or writes, they pass down information about | 161 | * These aren't really reads or writes, they pass down information about |
162 | * parts of device that are now unused by the file system. | 162 | * parts of device that are now unused by the file system. |
163 | */ | 163 | */ |
164 | #define DISCARD_NOBARRIER (1 << BIO_RW_DISCARD) | 164 | #define DISCARD_NOBARRIER (1 << BIO_RW_DISCARD) |
165 | #define DISCARD_BARRIER ((1 << BIO_RW_DISCARD) | (1 << BIO_RW_BARRIER)) | 165 | #define DISCARD_BARRIER ((1 << BIO_RW_DISCARD) | (1 << BIO_RW_BARRIER)) |
166 | 166 | ||
167 | #define SEL_IN 1 | 167 | #define SEL_IN 1 |
168 | #define SEL_OUT 2 | 168 | #define SEL_OUT 2 |
169 | #define SEL_EX 4 | 169 | #define SEL_EX 4 |
170 | 170 | ||
171 | /* public flags for file_system_type */ | 171 | /* public flags for file_system_type */ |
172 | #define FS_REQUIRES_DEV 1 | 172 | #define FS_REQUIRES_DEV 1 |
173 | #define FS_BINARY_MOUNTDATA 2 | 173 | #define FS_BINARY_MOUNTDATA 2 |
174 | #define FS_HAS_SUBTYPE 4 | 174 | #define FS_HAS_SUBTYPE 4 |
175 | #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */ | 175 | #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */ |
176 | #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() | 176 | #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() |
177 | * during rename() internally. | 177 | * during rename() internally. |
178 | */ | 178 | */ |
179 | 179 | ||
180 | /* | 180 | /* |
181 | * These are the fs-independent mount-flags: up to 32 flags are supported | 181 | * These are the fs-independent mount-flags: up to 32 flags are supported |
182 | */ | 182 | */ |
183 | #define MS_RDONLY 1 /* Mount read-only */ | 183 | #define MS_RDONLY 1 /* Mount read-only */ |
184 | #define MS_NOSUID 2 /* Ignore suid and sgid bits */ | 184 | #define MS_NOSUID 2 /* Ignore suid and sgid bits */ |
185 | #define MS_NODEV 4 /* Disallow access to device special files */ | 185 | #define MS_NODEV 4 /* Disallow access to device special files */ |
186 | #define MS_NOEXEC 8 /* Disallow program execution */ | 186 | #define MS_NOEXEC 8 /* Disallow program execution */ |
187 | #define MS_SYNCHRONOUS 16 /* Writes are synced at once */ | 187 | #define MS_SYNCHRONOUS 16 /* Writes are synced at once */ |
188 | #define MS_REMOUNT 32 /* Alter flags of a mounted FS */ | 188 | #define MS_REMOUNT 32 /* Alter flags of a mounted FS */ |
189 | #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */ | 189 | #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */ |
190 | #define MS_DIRSYNC 128 /* Directory modifications are synchronous */ | 190 | #define MS_DIRSYNC 128 /* Directory modifications are synchronous */ |
191 | #define MS_NOATIME 1024 /* Do not update access times. */ | 191 | #define MS_NOATIME 1024 /* Do not update access times. */ |
192 | #define MS_NODIRATIME 2048 /* Do not update directory access times */ | 192 | #define MS_NODIRATIME 2048 /* Do not update directory access times */ |
193 | #define MS_BIND 4096 | 193 | #define MS_BIND 4096 |
194 | #define MS_MOVE 8192 | 194 | #define MS_MOVE 8192 |
195 | #define MS_REC 16384 | 195 | #define MS_REC 16384 |
196 | #define MS_VERBOSE 32768 /* War is peace. Verbosity is silence. | 196 | #define MS_VERBOSE 32768 /* War is peace. Verbosity is silence. |
197 | MS_VERBOSE is deprecated. */ | 197 | MS_VERBOSE is deprecated. */ |
198 | #define MS_SILENT 32768 | 198 | #define MS_SILENT 32768 |
199 | #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */ | 199 | #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */ |
200 | #define MS_UNBINDABLE (1<<17) /* change to unbindable */ | 200 | #define MS_UNBINDABLE (1<<17) /* change to unbindable */ |
201 | #define MS_PRIVATE (1<<18) /* change to private */ | 201 | #define MS_PRIVATE (1<<18) /* change to private */ |
202 | #define MS_SLAVE (1<<19) /* change to slave */ | 202 | #define MS_SLAVE (1<<19) /* change to slave */ |
203 | #define MS_SHARED (1<<20) /* change to shared */ | 203 | #define MS_SHARED (1<<20) /* change to shared */ |
204 | #define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */ | 204 | #define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */ |
205 | #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */ | 205 | #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */ |
206 | #define MS_I_VERSION (1<<23) /* Update inode I_version field */ | 206 | #define MS_I_VERSION (1<<23) /* Update inode I_version field */ |
207 | #define MS_STRICTATIME (1<<24) /* Always perform atime updates */ | 207 | #define MS_STRICTATIME (1<<24) /* Always perform atime updates */ |
208 | #define MS_ACTIVE (1<<30) | 208 | #define MS_ACTIVE (1<<30) |
209 | #define MS_NOUSER (1<<31) | 209 | #define MS_NOUSER (1<<31) |
210 | 210 | ||
211 | /* | 211 | /* |
212 | * Superblock flags that can be altered by MS_REMOUNT | 212 | * Superblock flags that can be altered by MS_REMOUNT |
213 | */ | 213 | */ |
214 | #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION) | 214 | #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION) |
215 | 215 | ||
216 | /* | 216 | /* |
217 | * Old magic mount flag and mask | 217 | * Old magic mount flag and mask |
218 | */ | 218 | */ |
219 | #define MS_MGC_VAL 0xC0ED0000 | 219 | #define MS_MGC_VAL 0xC0ED0000 |
220 | #define MS_MGC_MSK 0xffff0000 | 220 | #define MS_MGC_MSK 0xffff0000 |
221 | 221 | ||
222 | /* Inode flags - they have nothing to superblock flags now */ | 222 | /* Inode flags - they have nothing to superblock flags now */ |
223 | 223 | ||
224 | #define S_SYNC 1 /* Writes are synced at once */ | 224 | #define S_SYNC 1 /* Writes are synced at once */ |
225 | #define S_NOATIME 2 /* Do not update access times */ | 225 | #define S_NOATIME 2 /* Do not update access times */ |
226 | #define S_APPEND 4 /* Append-only file */ | 226 | #define S_APPEND 4 /* Append-only file */ |
227 | #define S_IMMUTABLE 8 /* Immutable file */ | 227 | #define S_IMMUTABLE 8 /* Immutable file */ |
228 | #define S_DEAD 16 /* removed, but still open directory */ | 228 | #define S_DEAD 16 /* removed, but still open directory */ |
229 | #define S_NOQUOTA 32 /* Inode is not counted to quota */ | 229 | #define S_NOQUOTA 32 /* Inode is not counted to quota */ |
230 | #define S_DIRSYNC 64 /* Directory modifications are synchronous */ | 230 | #define S_DIRSYNC 64 /* Directory modifications are synchronous */ |
231 | #define S_NOCMTIME 128 /* Do not update file c/mtime */ | 231 | #define S_NOCMTIME 128 /* Do not update file c/mtime */ |
232 | #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */ | 232 | #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */ |
233 | #define S_PRIVATE 512 /* Inode is fs-internal */ | 233 | #define S_PRIVATE 512 /* Inode is fs-internal */ |
234 | 234 | ||
235 | /* | 235 | /* |
236 | * Note that nosuid etc flags are inode-specific: setting some file-system | 236 | * Note that nosuid etc flags are inode-specific: setting some file-system |
237 | * flags just means all the inodes inherit those flags by default. It might be | 237 | * flags just means all the inodes inherit those flags by default. It might be |
238 | * possible to override it selectively if you really wanted to with some | 238 | * possible to override it selectively if you really wanted to with some |
239 | * ioctl() that is not currently implemented. | 239 | * ioctl() that is not currently implemented. |
240 | * | 240 | * |
241 | * Exception: MS_RDONLY is always applied to the entire file system. | 241 | * Exception: MS_RDONLY is always applied to the entire file system. |
242 | * | 242 | * |
243 | * Unfortunately, it is possible to change a filesystems flags with it mounted | 243 | * Unfortunately, it is possible to change a filesystems flags with it mounted |
244 | * with files in use. This means that all of the inodes will not have their | 244 | * with files in use. This means that all of the inodes will not have their |
245 | * i_flags updated. Hence, i_flags no longer inherit the superblock mount | 245 | * i_flags updated. Hence, i_flags no longer inherit the superblock mount |
246 | * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org | 246 | * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org |
247 | */ | 247 | */ |
248 | #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg)) | 248 | #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg)) |
249 | 249 | ||
250 | #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY) | 250 | #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY) |
251 | #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \ | 251 | #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \ |
252 | ((inode)->i_flags & S_SYNC)) | 252 | ((inode)->i_flags & S_SYNC)) |
253 | #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \ | 253 | #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \ |
254 | ((inode)->i_flags & (S_SYNC|S_DIRSYNC))) | 254 | ((inode)->i_flags & (S_SYNC|S_DIRSYNC))) |
255 | #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK) | 255 | #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK) |
256 | #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME) | 256 | #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME) |
257 | #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION) | 257 | #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION) |
258 | 258 | ||
259 | #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA) | 259 | #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA) |
260 | #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) | 260 | #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) |
261 | #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) | 261 | #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) |
262 | #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL) | 262 | #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL) |
263 | 263 | ||
264 | #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD) | 264 | #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD) |
265 | #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME) | 265 | #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME) |
266 | #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE) | 266 | #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE) |
267 | #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE) | 267 | #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE) |
268 | 268 | ||
269 | /* the read-only stuff doesn't really belong here, but any other place is | 269 | /* the read-only stuff doesn't really belong here, but any other place is |
270 | probably as bad and I don't want to create yet another include file. */ | 270 | probably as bad and I don't want to create yet another include file. */ |
271 | 271 | ||
272 | #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */ | 272 | #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */ |
273 | #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */ | 273 | #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */ |
274 | #define BLKRRPART _IO(0x12,95) /* re-read partition table */ | 274 | #define BLKRRPART _IO(0x12,95) /* re-read partition table */ |
275 | #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */ | 275 | #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */ |
276 | #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ | 276 | #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ |
277 | #define BLKRASET _IO(0x12,98) /* set read ahead for block device */ | 277 | #define BLKRASET _IO(0x12,98) /* set read ahead for block device */ |
278 | #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */ | 278 | #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */ |
279 | #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */ | 279 | #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */ |
280 | #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */ | 280 | #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */ |
281 | #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */ | 281 | #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */ |
282 | #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */ | 282 | #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */ |
283 | #define BLKSSZGET _IO(0x12,104)/* get block device sector size */ | 283 | #define BLKSSZGET _IO(0x12,104)/* get block device sector size */ |
284 | #if 0 | 284 | #if 0 |
285 | #define BLKPG _IO(0x12,105)/* See blkpg.h */ | 285 | #define BLKPG _IO(0x12,105)/* See blkpg.h */ |
286 | 286 | ||
287 | /* Some people are morons. Do not use sizeof! */ | 287 | /* Some people are morons. Do not use sizeof! */ |
288 | 288 | ||
289 | #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */ | 289 | #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */ |
290 | #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */ | 290 | #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */ |
291 | /* This was here just to show that the number is taken - | 291 | /* This was here just to show that the number is taken - |
292 | probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */ | 292 | probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */ |
293 | #endif | 293 | #endif |
294 | /* A jump here: 108-111 have been used for various private purposes. */ | 294 | /* A jump here: 108-111 have been used for various private purposes. */ |
295 | #define BLKBSZGET _IOR(0x12,112,size_t) | 295 | #define BLKBSZGET _IOR(0x12,112,size_t) |
296 | #define BLKBSZSET _IOW(0x12,113,size_t) | 296 | #define BLKBSZSET _IOW(0x12,113,size_t) |
297 | #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ | 297 | #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ |
298 | #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup) | 298 | #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup) |
299 | #define BLKTRACESTART _IO(0x12,116) | 299 | #define BLKTRACESTART _IO(0x12,116) |
300 | #define BLKTRACESTOP _IO(0x12,117) | 300 | #define BLKTRACESTOP _IO(0x12,117) |
301 | #define BLKTRACETEARDOWN _IO(0x12,118) | 301 | #define BLKTRACETEARDOWN _IO(0x12,118) |
302 | #define BLKDISCARD _IO(0x12,119) | 302 | #define BLKDISCARD _IO(0x12,119) |
303 | 303 | ||
304 | #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ | 304 | #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ |
305 | #define FIBMAP _IO(0x00,1) /* bmap access */ | 305 | #define FIBMAP _IO(0x00,1) /* bmap access */ |
306 | #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */ | 306 | #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */ |
307 | #define FIFREEZE _IOWR('X', 119, int) /* Freeze */ | 307 | #define FIFREEZE _IOWR('X', 119, int) /* Freeze */ |
308 | #define FITHAW _IOWR('X', 120, int) /* Thaw */ | 308 | #define FITHAW _IOWR('X', 120, int) /* Thaw */ |
309 | 309 | ||
310 | #define FS_IOC_GETFLAGS _IOR('f', 1, long) | 310 | #define FS_IOC_GETFLAGS _IOR('f', 1, long) |
311 | #define FS_IOC_SETFLAGS _IOW('f', 2, long) | 311 | #define FS_IOC_SETFLAGS _IOW('f', 2, long) |
312 | #define FS_IOC_GETVERSION _IOR('v', 1, long) | 312 | #define FS_IOC_GETVERSION _IOR('v', 1, long) |
313 | #define FS_IOC_SETVERSION _IOW('v', 2, long) | 313 | #define FS_IOC_SETVERSION _IOW('v', 2, long) |
314 | #define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap) | 314 | #define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap) |
315 | #define FS_IOC32_GETFLAGS _IOR('f', 1, int) | 315 | #define FS_IOC32_GETFLAGS _IOR('f', 1, int) |
316 | #define FS_IOC32_SETFLAGS _IOW('f', 2, int) | 316 | #define FS_IOC32_SETFLAGS _IOW('f', 2, int) |
317 | #define FS_IOC32_GETVERSION _IOR('v', 1, int) | 317 | #define FS_IOC32_GETVERSION _IOR('v', 1, int) |
318 | #define FS_IOC32_SETVERSION _IOW('v', 2, int) | 318 | #define FS_IOC32_SETVERSION _IOW('v', 2, int) |
319 | 319 | ||
320 | /* | 320 | /* |
321 | * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) | 321 | * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) |
322 | */ | 322 | */ |
323 | #define FS_SECRM_FL 0x00000001 /* Secure deletion */ | 323 | #define FS_SECRM_FL 0x00000001 /* Secure deletion */ |
324 | #define FS_UNRM_FL 0x00000002 /* Undelete */ | 324 | #define FS_UNRM_FL 0x00000002 /* Undelete */ |
325 | #define FS_COMPR_FL 0x00000004 /* Compress file */ | 325 | #define FS_COMPR_FL 0x00000004 /* Compress file */ |
326 | #define FS_SYNC_FL 0x00000008 /* Synchronous updates */ | 326 | #define FS_SYNC_FL 0x00000008 /* Synchronous updates */ |
327 | #define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ | 327 | #define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ |
328 | #define FS_APPEND_FL 0x00000020 /* writes to file may only append */ | 328 | #define FS_APPEND_FL 0x00000020 /* writes to file may only append */ |
329 | #define FS_NODUMP_FL 0x00000040 /* do not dump file */ | 329 | #define FS_NODUMP_FL 0x00000040 /* do not dump file */ |
330 | #define FS_NOATIME_FL 0x00000080 /* do not update atime */ | 330 | #define FS_NOATIME_FL 0x00000080 /* do not update atime */ |
331 | /* Reserved for compression usage... */ | 331 | /* Reserved for compression usage... */ |
332 | #define FS_DIRTY_FL 0x00000100 | 332 | #define FS_DIRTY_FL 0x00000100 |
333 | #define FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ | 333 | #define FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ |
334 | #define FS_NOCOMP_FL 0x00000400 /* Don't compress */ | 334 | #define FS_NOCOMP_FL 0x00000400 /* Don't compress */ |
335 | #define FS_ECOMPR_FL 0x00000800 /* Compression error */ | 335 | #define FS_ECOMPR_FL 0x00000800 /* Compression error */ |
336 | /* End compression flags --- maybe not all used */ | 336 | /* End compression flags --- maybe not all used */ |
337 | #define FS_BTREE_FL 0x00001000 /* btree format dir */ | 337 | #define FS_BTREE_FL 0x00001000 /* btree format dir */ |
338 | #define FS_INDEX_FL 0x00001000 /* hash-indexed directory */ | 338 | #define FS_INDEX_FL 0x00001000 /* hash-indexed directory */ |
339 | #define FS_IMAGIC_FL 0x00002000 /* AFS directory */ | 339 | #define FS_IMAGIC_FL 0x00002000 /* AFS directory */ |
340 | #define FS_JOURNAL_DATA_FL 0x00004000 /* Reserved for ext3 */ | 340 | #define FS_JOURNAL_DATA_FL 0x00004000 /* Reserved for ext3 */ |
341 | #define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */ | 341 | #define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */ |
342 | #define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ | 342 | #define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ |
343 | #define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ | 343 | #define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ |
344 | #define FS_EXTENT_FL 0x00080000 /* Extents */ | 344 | #define FS_EXTENT_FL 0x00080000 /* Extents */ |
345 | #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */ | 345 | #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */ |
346 | #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ | 346 | #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ |
347 | 347 | ||
348 | #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ | 348 | #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ |
349 | #define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */ | 349 | #define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */ |
350 | 350 | ||
351 | 351 | ||
352 | #define SYNC_FILE_RANGE_WAIT_BEFORE 1 | 352 | #define SYNC_FILE_RANGE_WAIT_BEFORE 1 |
353 | #define SYNC_FILE_RANGE_WRITE 2 | 353 | #define SYNC_FILE_RANGE_WRITE 2 |
354 | #define SYNC_FILE_RANGE_WAIT_AFTER 4 | 354 | #define SYNC_FILE_RANGE_WAIT_AFTER 4 |
355 | 355 | ||
356 | #ifdef __KERNEL__ | 356 | #ifdef __KERNEL__ |
357 | 357 | ||
358 | #include <linux/linkage.h> | 358 | #include <linux/linkage.h> |
359 | #include <linux/wait.h> | 359 | #include <linux/wait.h> |
360 | #include <linux/types.h> | 360 | #include <linux/types.h> |
361 | #include <linux/kdev_t.h> | 361 | #include <linux/kdev_t.h> |
362 | #include <linux/dcache.h> | 362 | #include <linux/dcache.h> |
363 | #include <linux/path.h> | 363 | #include <linux/path.h> |
364 | #include <linux/stat.h> | 364 | #include <linux/stat.h> |
365 | #include <linux/cache.h> | 365 | #include <linux/cache.h> |
366 | #include <linux/kobject.h> | 366 | #include <linux/kobject.h> |
367 | #include <linux/list.h> | 367 | #include <linux/list.h> |
368 | #include <linux/radix-tree.h> | 368 | #include <linux/radix-tree.h> |
369 | #include <linux/prio_tree.h> | 369 | #include <linux/prio_tree.h> |
370 | #include <linux/init.h> | 370 | #include <linux/init.h> |
371 | #include <linux/pid.h> | 371 | #include <linux/pid.h> |
372 | #include <linux/mutex.h> | 372 | #include <linux/mutex.h> |
373 | #include <linux/capability.h> | 373 | #include <linux/capability.h> |
374 | #include <linux/semaphore.h> | 374 | #include <linux/semaphore.h> |
375 | #include <linux/fiemap.h> | 375 | #include <linux/fiemap.h> |
376 | 376 | ||
377 | #include <asm/atomic.h> | 377 | #include <asm/atomic.h> |
378 | #include <asm/byteorder.h> | 378 | #include <asm/byteorder.h> |
379 | 379 | ||
380 | struct export_operations; | 380 | struct export_operations; |
381 | struct hd_geometry; | 381 | struct hd_geometry; |
382 | struct iovec; | 382 | struct iovec; |
383 | struct nameidata; | 383 | struct nameidata; |
384 | struct kiocb; | 384 | struct kiocb; |
385 | struct pipe_inode_info; | 385 | struct pipe_inode_info; |
386 | struct poll_table_struct; | 386 | struct poll_table_struct; |
387 | struct kstatfs; | 387 | struct kstatfs; |
388 | struct vm_area_struct; | 388 | struct vm_area_struct; |
389 | struct vfsmount; | 389 | struct vfsmount; |
390 | struct cred; | 390 | struct cred; |
391 | 391 | ||
392 | extern void __init inode_init(void); | 392 | extern void __init inode_init(void); |
393 | extern void __init inode_init_early(void); | 393 | extern void __init inode_init_early(void); |
394 | extern void __init files_init(unsigned long); | 394 | extern void __init files_init(unsigned long); |
395 | 395 | ||
396 | extern struct files_stat_struct files_stat; | 396 | extern struct files_stat_struct files_stat; |
397 | extern int get_max_files(void); | 397 | extern int get_max_files(void); |
398 | extern int sysctl_nr_open; | 398 | extern int sysctl_nr_open; |
399 | extern struct inodes_stat_t inodes_stat; | 399 | extern struct inodes_stat_t inodes_stat; |
400 | extern int leases_enable, lease_break_time; | 400 | extern int leases_enable, lease_break_time; |
401 | #ifdef CONFIG_DNOTIFY | 401 | #ifdef CONFIG_DNOTIFY |
402 | extern int dir_notify_enable; | 402 | extern int dir_notify_enable; |
403 | #endif | 403 | #endif |
404 | 404 | ||
405 | struct buffer_head; | 405 | struct buffer_head; |
406 | typedef int (get_block_t)(struct inode *inode, sector_t iblock, | 406 | typedef int (get_block_t)(struct inode *inode, sector_t iblock, |
407 | struct buffer_head *bh_result, int create); | 407 | struct buffer_head *bh_result, int create); |
408 | typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset, | 408 | typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset, |
409 | ssize_t bytes, void *private); | 409 | ssize_t bytes, void *private); |
410 | 410 | ||
411 | /* | 411 | /* |
412 | * Attribute flags. These should be or-ed together to figure out what | 412 | * Attribute flags. These should be or-ed together to figure out what |
413 | * has been changed! | 413 | * has been changed! |
414 | */ | 414 | */ |
415 | #define ATTR_MODE (1 << 0) | 415 | #define ATTR_MODE (1 << 0) |
416 | #define ATTR_UID (1 << 1) | 416 | #define ATTR_UID (1 << 1) |
417 | #define ATTR_GID (1 << 2) | 417 | #define ATTR_GID (1 << 2) |
418 | #define ATTR_SIZE (1 << 3) | 418 | #define ATTR_SIZE (1 << 3) |
419 | #define ATTR_ATIME (1 << 4) | 419 | #define ATTR_ATIME (1 << 4) |
420 | #define ATTR_MTIME (1 << 5) | 420 | #define ATTR_MTIME (1 << 5) |
421 | #define ATTR_CTIME (1 << 6) | 421 | #define ATTR_CTIME (1 << 6) |
422 | #define ATTR_ATIME_SET (1 << 7) | 422 | #define ATTR_ATIME_SET (1 << 7) |
423 | #define ATTR_MTIME_SET (1 << 8) | 423 | #define ATTR_MTIME_SET (1 << 8) |
424 | #define ATTR_FORCE (1 << 9) /* Not a change, but a change it */ | 424 | #define ATTR_FORCE (1 << 9) /* Not a change, but a change it */ |
425 | #define ATTR_ATTR_FLAG (1 << 10) | 425 | #define ATTR_ATTR_FLAG (1 << 10) |
426 | #define ATTR_KILL_SUID (1 << 11) | 426 | #define ATTR_KILL_SUID (1 << 11) |
427 | #define ATTR_KILL_SGID (1 << 12) | 427 | #define ATTR_KILL_SGID (1 << 12) |
428 | #define ATTR_FILE (1 << 13) | 428 | #define ATTR_FILE (1 << 13) |
429 | #define ATTR_KILL_PRIV (1 << 14) | 429 | #define ATTR_KILL_PRIV (1 << 14) |
430 | #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */ | 430 | #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */ |
431 | #define ATTR_TIMES_SET (1 << 16) | 431 | #define ATTR_TIMES_SET (1 << 16) |
432 | 432 | ||
433 | /* | 433 | /* |
434 | * This is the Inode Attributes structure, used for notify_change(). It | 434 | * This is the Inode Attributes structure, used for notify_change(). It |
435 | * uses the above definitions as flags, to know which values have changed. | 435 | * uses the above definitions as flags, to know which values have changed. |
436 | * Also, in this manner, a Filesystem can look at only the values it cares | 436 | * Also, in this manner, a Filesystem can look at only the values it cares |
437 | * about. Basically, these are the attributes that the VFS layer can | 437 | * about. Basically, these are the attributes that the VFS layer can |
438 | * request to change from the FS layer. | 438 | * request to change from the FS layer. |
439 | * | 439 | * |
440 | * Derek Atkins <warlord@MIT.EDU> 94-10-20 | 440 | * Derek Atkins <warlord@MIT.EDU> 94-10-20 |
441 | */ | 441 | */ |
442 | struct iattr { | 442 | struct iattr { |
443 | unsigned int ia_valid; | 443 | unsigned int ia_valid; |
444 | umode_t ia_mode; | 444 | umode_t ia_mode; |
445 | uid_t ia_uid; | 445 | uid_t ia_uid; |
446 | gid_t ia_gid; | 446 | gid_t ia_gid; |
447 | loff_t ia_size; | 447 | loff_t ia_size; |
448 | struct timespec ia_atime; | 448 | struct timespec ia_atime; |
449 | struct timespec ia_mtime; | 449 | struct timespec ia_mtime; |
450 | struct timespec ia_ctime; | 450 | struct timespec ia_ctime; |
451 | 451 | ||
452 | /* | 452 | /* |
453 | * Not an attribute, but an auxilary info for filesystems wanting to | 453 | * Not an attribute, but an auxilary info for filesystems wanting to |
454 | * implement an ftruncate() like method. NOTE: filesystem should | 454 | * implement an ftruncate() like method. NOTE: filesystem should |
455 | * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL). | 455 | * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL). |
456 | */ | 456 | */ |
457 | struct file *ia_file; | 457 | struct file *ia_file; |
458 | }; | 458 | }; |
459 | 459 | ||
460 | /* | 460 | /* |
461 | * Includes for diskquotas. | 461 | * Includes for diskquotas. |
462 | */ | 462 | */ |
463 | #include <linux/quota.h> | 463 | #include <linux/quota.h> |
464 | 464 | ||
465 | /** | 465 | /** |
466 | * enum positive_aop_returns - aop return codes with specific semantics | 466 | * enum positive_aop_returns - aop return codes with specific semantics |
467 | * | 467 | * |
468 | * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has | 468 | * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has |
469 | * completed, that the page is still locked, and | 469 | * completed, that the page is still locked, and |
470 | * should be considered active. The VM uses this hint | 470 | * should be considered active. The VM uses this hint |
471 | * to return the page to the active list -- it won't | 471 | * to return the page to the active list -- it won't |
472 | * be a candidate for writeback again in the near | 472 | * be a candidate for writeback again in the near |
473 | * future. Other callers must be careful to unlock | 473 | * future. Other callers must be careful to unlock |
474 | * the page if they get this return. Returned by | 474 | * the page if they get this return. Returned by |
475 | * writepage(); | 475 | * writepage(); |
476 | * | 476 | * |
477 | * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has | 477 | * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has |
478 | * unlocked it and the page might have been truncated. | 478 | * unlocked it and the page might have been truncated. |
479 | * The caller should back up to acquiring a new page and | 479 | * The caller should back up to acquiring a new page and |
480 | * trying again. The aop will be taking reasonable | 480 | * trying again. The aop will be taking reasonable |
481 | * precautions not to livelock. If the caller held a page | 481 | * precautions not to livelock. If the caller held a page |
482 | * reference, it should drop it before retrying. Returned | 482 | * reference, it should drop it before retrying. Returned |
483 | * by readpage(). | 483 | * by readpage(). |
484 | * | 484 | * |
485 | * address_space_operation functions return these large constants to indicate | 485 | * address_space_operation functions return these large constants to indicate |
486 | * special semantics to the caller. These are much larger than the bytes in a | 486 | * special semantics to the caller. These are much larger than the bytes in a |
487 | * page to allow for functions that return the number of bytes operated on in a | 487 | * page to allow for functions that return the number of bytes operated on in a |
488 | * given page. | 488 | * given page. |
489 | */ | 489 | */ |
490 | 490 | ||
491 | enum positive_aop_returns { | 491 | enum positive_aop_returns { |
492 | AOP_WRITEPAGE_ACTIVATE = 0x80000, | 492 | AOP_WRITEPAGE_ACTIVATE = 0x80000, |
493 | AOP_TRUNCATED_PAGE = 0x80001, | 493 | AOP_TRUNCATED_PAGE = 0x80001, |
494 | }; | 494 | }; |
495 | 495 | ||
496 | #define AOP_FLAG_UNINTERRUPTIBLE 0x0001 /* will not do a short write */ | 496 | #define AOP_FLAG_UNINTERRUPTIBLE 0x0001 /* will not do a short write */ |
497 | #define AOP_FLAG_CONT_EXPAND 0x0002 /* called from cont_expand */ | 497 | #define AOP_FLAG_CONT_EXPAND 0x0002 /* called from cont_expand */ |
498 | #define AOP_FLAG_NOFS 0x0004 /* used by filesystem to direct | 498 | #define AOP_FLAG_NOFS 0x0004 /* used by filesystem to direct |
499 | * helper code (eg buffer layer) | 499 | * helper code (eg buffer layer) |
500 | * to clear GFP_FS from alloc */ | 500 | * to clear GFP_FS from alloc */ |
501 | 501 | ||
502 | /* | 502 | /* |
503 | * oh the beauties of C type declarations. | 503 | * oh the beauties of C type declarations. |
504 | */ | 504 | */ |
505 | struct page; | 505 | struct page; |
506 | struct address_space; | 506 | struct address_space; |
507 | struct writeback_control; | 507 | struct writeback_control; |
508 | 508 | ||
509 | struct iov_iter { | 509 | struct iov_iter { |
510 | const struct iovec *iov; | 510 | const struct iovec *iov; |
511 | unsigned long nr_segs; | 511 | unsigned long nr_segs; |
512 | size_t iov_offset; | 512 | size_t iov_offset; |
513 | size_t count; | 513 | size_t count; |
514 | }; | 514 | }; |
515 | 515 | ||
516 | size_t iov_iter_copy_from_user_atomic(struct page *page, | 516 | size_t iov_iter_copy_from_user_atomic(struct page *page, |
517 | struct iov_iter *i, unsigned long offset, size_t bytes); | 517 | struct iov_iter *i, unsigned long offset, size_t bytes); |
518 | size_t iov_iter_copy_from_user(struct page *page, | 518 | size_t iov_iter_copy_from_user(struct page *page, |
519 | struct iov_iter *i, unsigned long offset, size_t bytes); | 519 | struct iov_iter *i, unsigned long offset, size_t bytes); |
520 | void iov_iter_advance(struct iov_iter *i, size_t bytes); | 520 | void iov_iter_advance(struct iov_iter *i, size_t bytes); |
521 | int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes); | 521 | int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes); |
522 | size_t iov_iter_single_seg_count(struct iov_iter *i); | 522 | size_t iov_iter_single_seg_count(struct iov_iter *i); |
523 | 523 | ||
524 | static inline void iov_iter_init(struct iov_iter *i, | 524 | static inline void iov_iter_init(struct iov_iter *i, |
525 | const struct iovec *iov, unsigned long nr_segs, | 525 | const struct iovec *iov, unsigned long nr_segs, |
526 | size_t count, size_t written) | 526 | size_t count, size_t written) |
527 | { | 527 | { |
528 | i->iov = iov; | 528 | i->iov = iov; |
529 | i->nr_segs = nr_segs; | 529 | i->nr_segs = nr_segs; |
530 | i->iov_offset = 0; | 530 | i->iov_offset = 0; |
531 | i->count = count + written; | 531 | i->count = count + written; |
532 | 532 | ||
533 | iov_iter_advance(i, written); | 533 | iov_iter_advance(i, written); |
534 | } | 534 | } |
535 | 535 | ||
536 | static inline size_t iov_iter_count(struct iov_iter *i) | 536 | static inline size_t iov_iter_count(struct iov_iter *i) |
537 | { | 537 | { |
538 | return i->count; | 538 | return i->count; |
539 | } | 539 | } |
540 | 540 | ||
541 | /* | 541 | /* |
542 | * "descriptor" for what we're up to with a read. | 542 | * "descriptor" for what we're up to with a read. |
543 | * This allows us to use the same read code yet | 543 | * This allows us to use the same read code yet |
544 | * have multiple different users of the data that | 544 | * have multiple different users of the data that |
545 | * we read from a file. | 545 | * we read from a file. |
546 | * | 546 | * |
547 | * The simplest case just copies the data to user | 547 | * The simplest case just copies the data to user |
548 | * mode. | 548 | * mode. |
549 | */ | 549 | */ |
550 | typedef struct { | 550 | typedef struct { |
551 | size_t written; | 551 | size_t written; |
552 | size_t count; | 552 | size_t count; |
553 | union { | 553 | union { |
554 | char __user *buf; | 554 | char __user *buf; |
555 | void *data; | 555 | void *data; |
556 | } arg; | 556 | } arg; |
557 | int error; | 557 | int error; |
558 | } read_descriptor_t; | 558 | } read_descriptor_t; |
559 | 559 | ||
560 | typedef int (*read_actor_t)(read_descriptor_t *, struct page *, | 560 | typedef int (*read_actor_t)(read_descriptor_t *, struct page *, |
561 | unsigned long, unsigned long); | 561 | unsigned long, unsigned long); |
562 | 562 | ||
563 | struct address_space_operations { | 563 | struct address_space_operations { |
564 | int (*writepage)(struct page *page, struct writeback_control *wbc); | 564 | int (*writepage)(struct page *page, struct writeback_control *wbc); |
565 | int (*readpage)(struct file *, struct page *); | 565 | int (*readpage)(struct file *, struct page *); |
566 | void (*sync_page)(struct page *); | 566 | void (*sync_page)(struct page *); |
567 | 567 | ||
568 | /* Write back some dirty pages from this mapping. */ | 568 | /* Write back some dirty pages from this mapping. */ |
569 | int (*writepages)(struct address_space *, struct writeback_control *); | 569 | int (*writepages)(struct address_space *, struct writeback_control *); |
570 | 570 | ||
571 | /* Set a page dirty. Return true if this dirtied it */ | 571 | /* Set a page dirty. Return true if this dirtied it */ |
572 | int (*set_page_dirty)(struct page *page); | 572 | int (*set_page_dirty)(struct page *page); |
573 | 573 | ||
574 | int (*readpages)(struct file *filp, struct address_space *mapping, | 574 | int (*readpages)(struct file *filp, struct address_space *mapping, |
575 | struct list_head *pages, unsigned nr_pages); | 575 | struct list_head *pages, unsigned nr_pages); |
576 | 576 | ||
577 | int (*write_begin)(struct file *, struct address_space *mapping, | 577 | int (*write_begin)(struct file *, struct address_space *mapping, |
578 | loff_t pos, unsigned len, unsigned flags, | 578 | loff_t pos, unsigned len, unsigned flags, |
579 | struct page **pagep, void **fsdata); | 579 | struct page **pagep, void **fsdata); |
580 | int (*write_end)(struct file *, struct address_space *mapping, | 580 | int (*write_end)(struct file *, struct address_space *mapping, |
581 | loff_t pos, unsigned len, unsigned copied, | 581 | loff_t pos, unsigned len, unsigned copied, |
582 | struct page *page, void *fsdata); | 582 | struct page *page, void *fsdata); |
583 | 583 | ||
584 | /* Unfortunately this kludge is needed for FIBMAP. Don't use it */ | 584 | /* Unfortunately this kludge is needed for FIBMAP. Don't use it */ |
585 | sector_t (*bmap)(struct address_space *, sector_t); | 585 | sector_t (*bmap)(struct address_space *, sector_t); |
586 | void (*invalidatepage) (struct page *, unsigned long); | 586 | void (*invalidatepage) (struct page *, unsigned long); |
587 | int (*releasepage) (struct page *, gfp_t); | 587 | int (*releasepage) (struct page *, gfp_t); |
588 | ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, | 588 | ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, |
589 | loff_t offset, unsigned long nr_segs); | 589 | loff_t offset, unsigned long nr_segs); |
590 | int (*get_xip_mem)(struct address_space *, pgoff_t, int, | 590 | int (*get_xip_mem)(struct address_space *, pgoff_t, int, |
591 | void **, unsigned long *); | 591 | void **, unsigned long *); |
592 | /* migrate the contents of a page to the specified target */ | 592 | /* migrate the contents of a page to the specified target */ |
593 | int (*migratepage) (struct address_space *, | 593 | int (*migratepage) (struct address_space *, |
594 | struct page *, struct page *); | 594 | struct page *, struct page *); |
595 | int (*launder_page) (struct page *); | 595 | int (*launder_page) (struct page *); |
596 | int (*is_partially_uptodate) (struct page *, read_descriptor_t *, | 596 | int (*is_partially_uptodate) (struct page *, read_descriptor_t *, |
597 | unsigned long); | 597 | unsigned long); |
598 | }; | 598 | }; |
599 | 599 | ||
600 | /* | 600 | /* |
601 | * pagecache_write_begin/pagecache_write_end must be used by general code | 601 | * pagecache_write_begin/pagecache_write_end must be used by general code |
602 | * to write into the pagecache. | 602 | * to write into the pagecache. |
603 | */ | 603 | */ |
604 | int pagecache_write_begin(struct file *, struct address_space *mapping, | 604 | int pagecache_write_begin(struct file *, struct address_space *mapping, |
605 | loff_t pos, unsigned len, unsigned flags, | 605 | loff_t pos, unsigned len, unsigned flags, |
606 | struct page **pagep, void **fsdata); | 606 | struct page **pagep, void **fsdata); |
607 | 607 | ||
608 | int pagecache_write_end(struct file *, struct address_space *mapping, | 608 | int pagecache_write_end(struct file *, struct address_space *mapping, |
609 | loff_t pos, unsigned len, unsigned copied, | 609 | loff_t pos, unsigned len, unsigned copied, |
610 | struct page *page, void *fsdata); | 610 | struct page *page, void *fsdata); |
611 | 611 | ||
612 | struct backing_dev_info; | 612 | struct backing_dev_info; |
613 | struct address_space { | 613 | struct address_space { |
614 | struct inode *host; /* owner: inode, block_device */ | 614 | struct inode *host; /* owner: inode, block_device */ |
615 | struct radix_tree_root page_tree; /* radix tree of all pages */ | 615 | struct radix_tree_root page_tree; /* radix tree of all pages */ |
616 | spinlock_t tree_lock; /* and lock protecting it */ | 616 | spinlock_t tree_lock; /* and lock protecting it */ |
617 | unsigned int i_mmap_writable;/* count VM_SHARED mappings */ | 617 | unsigned int i_mmap_writable;/* count VM_SHARED mappings */ |
618 | struct prio_tree_root i_mmap; /* tree of private and shared mappings */ | 618 | struct prio_tree_root i_mmap; /* tree of private and shared mappings */ |
619 | struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */ | 619 | struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */ |
620 | spinlock_t i_mmap_lock; /* protect tree, count, list */ | 620 | spinlock_t i_mmap_lock; /* protect tree, count, list */ |
621 | unsigned int truncate_count; /* Cover race condition with truncate */ | 621 | unsigned int truncate_count; /* Cover race condition with truncate */ |
622 | unsigned long nrpages; /* number of total pages */ | 622 | unsigned long nrpages; /* number of total pages */ |
623 | pgoff_t writeback_index;/* writeback starts here */ | 623 | pgoff_t writeback_index;/* writeback starts here */ |
624 | const struct address_space_operations *a_ops; /* methods */ | 624 | const struct address_space_operations *a_ops; /* methods */ |
625 | unsigned long flags; /* error bits/gfp mask */ | 625 | unsigned long flags; /* error bits/gfp mask */ |
626 | struct backing_dev_info *backing_dev_info; /* device readahead, etc */ | 626 | struct backing_dev_info *backing_dev_info; /* device readahead, etc */ |
627 | spinlock_t private_lock; /* for use by the address_space */ | 627 | spinlock_t private_lock; /* for use by the address_space */ |
628 | struct list_head private_list; /* ditto */ | 628 | struct list_head private_list; /* ditto */ |
629 | struct address_space *assoc_mapping; /* ditto */ | 629 | struct address_space *assoc_mapping; /* ditto */ |
630 | } __attribute__((aligned(sizeof(long)))); | 630 | } __attribute__((aligned(sizeof(long)))); |
631 | /* | 631 | /* |
632 | * On most architectures that alignment is already the case; but | 632 | * On most architectures that alignment is already the case; but |
633 | * must be enforced here for CRIS, to let the least signficant bit | 633 | * must be enforced here for CRIS, to let the least signficant bit |
634 | * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON. | 634 | * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON. |
635 | */ | 635 | */ |
636 | 636 | ||
637 | struct block_device { | 637 | struct block_device { |
638 | dev_t bd_dev; /* not a kdev_t - it's a search key */ | 638 | dev_t bd_dev; /* not a kdev_t - it's a search key */ |
639 | struct inode * bd_inode; /* will die */ | 639 | struct inode * bd_inode; /* will die */ |
640 | struct super_block * bd_super; | 640 | struct super_block * bd_super; |
641 | int bd_openers; | 641 | int bd_openers; |
642 | struct mutex bd_mutex; /* open/close mutex */ | 642 | struct mutex bd_mutex; /* open/close mutex */ |
643 | struct semaphore bd_mount_sem; | 643 | struct semaphore bd_mount_sem; |
644 | struct list_head bd_inodes; | 644 | struct list_head bd_inodes; |
645 | void * bd_holder; | 645 | void * bd_holder; |
646 | int bd_holders; | 646 | int bd_holders; |
647 | #ifdef CONFIG_SYSFS | 647 | #ifdef CONFIG_SYSFS |
648 | struct list_head bd_holder_list; | 648 | struct list_head bd_holder_list; |
649 | #endif | 649 | #endif |
650 | struct block_device * bd_contains; | 650 | struct block_device * bd_contains; |
651 | unsigned bd_block_size; | 651 | unsigned bd_block_size; |
652 | struct hd_struct * bd_part; | 652 | struct hd_struct * bd_part; |
653 | /* number of times partitions within this device have been opened. */ | 653 | /* number of times partitions within this device have been opened. */ |
654 | unsigned bd_part_count; | 654 | unsigned bd_part_count; |
655 | int bd_invalidated; | 655 | int bd_invalidated; |
656 | struct gendisk * bd_disk; | 656 | struct gendisk * bd_disk; |
657 | struct list_head bd_list; | 657 | struct list_head bd_list; |
658 | struct backing_dev_info *bd_inode_backing_dev_info; | 658 | struct backing_dev_info *bd_inode_backing_dev_info; |
659 | /* | 659 | /* |
660 | * Private data. You must have bd_claim'ed the block_device | 660 | * Private data. You must have bd_claim'ed the block_device |
661 | * to use this. NOTE: bd_claim allows an owner to claim | 661 | * to use this. NOTE: bd_claim allows an owner to claim |
662 | * the same device multiple times, the owner must take special | 662 | * the same device multiple times, the owner must take special |
663 | * care to not mess up bd_private for that case. | 663 | * care to not mess up bd_private for that case. |
664 | */ | 664 | */ |
665 | unsigned long bd_private; | 665 | unsigned long bd_private; |
666 | 666 | ||
667 | /* The counter of freeze processes */ | 667 | /* The counter of freeze processes */ |
668 | int bd_fsfreeze_count; | 668 | int bd_fsfreeze_count; |
669 | /* Mutex for freeze */ | 669 | /* Mutex for freeze */ |
670 | struct mutex bd_fsfreeze_mutex; | 670 | struct mutex bd_fsfreeze_mutex; |
671 | }; | 671 | }; |
672 | 672 | ||
673 | /* | 673 | /* |
674 | * Radix-tree tags, for tagging dirty and writeback pages within the pagecache | 674 | * Radix-tree tags, for tagging dirty and writeback pages within the pagecache |
675 | * radix trees | 675 | * radix trees |
676 | */ | 676 | */ |
677 | #define PAGECACHE_TAG_DIRTY 0 | 677 | #define PAGECACHE_TAG_DIRTY 0 |
678 | #define PAGECACHE_TAG_WRITEBACK 1 | 678 | #define PAGECACHE_TAG_WRITEBACK 1 |
679 | 679 | ||
680 | int mapping_tagged(struct address_space *mapping, int tag); | 680 | int mapping_tagged(struct address_space *mapping, int tag); |
681 | 681 | ||
682 | /* | 682 | /* |
683 | * Might pages of this file be mapped into userspace? | 683 | * Might pages of this file be mapped into userspace? |
684 | */ | 684 | */ |
685 | static inline int mapping_mapped(struct address_space *mapping) | 685 | static inline int mapping_mapped(struct address_space *mapping) |
686 | { | 686 | { |
687 | return !prio_tree_empty(&mapping->i_mmap) || | 687 | return !prio_tree_empty(&mapping->i_mmap) || |
688 | !list_empty(&mapping->i_mmap_nonlinear); | 688 | !list_empty(&mapping->i_mmap_nonlinear); |
689 | } | 689 | } |
690 | 690 | ||
691 | /* | 691 | /* |
692 | * Might pages of this file have been modified in userspace? | 692 | * Might pages of this file have been modified in userspace? |
693 | * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff | 693 | * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff |
694 | * marks vma as VM_SHARED if it is shared, and the file was opened for | 694 | * marks vma as VM_SHARED if it is shared, and the file was opened for |
695 | * writing i.e. vma may be mprotected writable even if now readonly. | 695 | * writing i.e. vma may be mprotected writable even if now readonly. |
696 | */ | 696 | */ |
697 | static inline int mapping_writably_mapped(struct address_space *mapping) | 697 | static inline int mapping_writably_mapped(struct address_space *mapping) |
698 | { | 698 | { |
699 | return mapping->i_mmap_writable != 0; | 699 | return mapping->i_mmap_writable != 0; |
700 | } | 700 | } |
701 | 701 | ||
702 | /* | 702 | /* |
703 | * Use sequence counter to get consistent i_size on 32-bit processors. | 703 | * Use sequence counter to get consistent i_size on 32-bit processors. |
704 | */ | 704 | */ |
705 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) | 705 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) |
706 | #include <linux/seqlock.h> | 706 | #include <linux/seqlock.h> |
707 | #define __NEED_I_SIZE_ORDERED | 707 | #define __NEED_I_SIZE_ORDERED |
708 | #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount) | 708 | #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount) |
709 | #else | 709 | #else |
710 | #define i_size_ordered_init(inode) do { } while (0) | 710 | #define i_size_ordered_init(inode) do { } while (0) |
711 | #endif | 711 | #endif |
712 | 712 | ||
713 | struct inode { | 713 | struct inode { |
714 | struct hlist_node i_hash; | 714 | struct hlist_node i_hash; |
715 | struct list_head i_list; | 715 | struct list_head i_list; |
716 | struct list_head i_sb_list; | 716 | struct list_head i_sb_list; |
717 | struct list_head i_dentry; | 717 | struct list_head i_dentry; |
718 | unsigned long i_ino; | 718 | unsigned long i_ino; |
719 | atomic_t i_count; | 719 | atomic_t i_count; |
720 | unsigned int i_nlink; | 720 | unsigned int i_nlink; |
721 | uid_t i_uid; | 721 | uid_t i_uid; |
722 | gid_t i_gid; | 722 | gid_t i_gid; |
723 | dev_t i_rdev; | 723 | dev_t i_rdev; |
724 | u64 i_version; | 724 | u64 i_version; |
725 | loff_t i_size; | 725 | loff_t i_size; |
726 | #ifdef __NEED_I_SIZE_ORDERED | 726 | #ifdef __NEED_I_SIZE_ORDERED |
727 | seqcount_t i_size_seqcount; | 727 | seqcount_t i_size_seqcount; |
728 | #endif | 728 | #endif |
729 | struct timespec i_atime; | 729 | struct timespec i_atime; |
730 | struct timespec i_mtime; | 730 | struct timespec i_mtime; |
731 | struct timespec i_ctime; | 731 | struct timespec i_ctime; |
732 | unsigned int i_blkbits; | 732 | unsigned int i_blkbits; |
733 | blkcnt_t i_blocks; | 733 | blkcnt_t i_blocks; |
734 | unsigned short i_bytes; | 734 | unsigned short i_bytes; |
735 | umode_t i_mode; | 735 | umode_t i_mode; |
736 | spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ | 736 | spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ |
737 | struct mutex i_mutex; | 737 | struct mutex i_mutex; |
738 | struct rw_semaphore i_alloc_sem; | 738 | struct rw_semaphore i_alloc_sem; |
739 | const struct inode_operations *i_op; | 739 | const struct inode_operations *i_op; |
740 | const struct file_operations *i_fop; /* former ->i_op->default_file_ops */ | 740 | const struct file_operations *i_fop; /* former ->i_op->default_file_ops */ |
741 | struct super_block *i_sb; | 741 | struct super_block *i_sb; |
742 | struct file_lock *i_flock; | 742 | struct file_lock *i_flock; |
743 | struct address_space *i_mapping; | 743 | struct address_space *i_mapping; |
744 | struct address_space i_data; | 744 | struct address_space i_data; |
745 | #ifdef CONFIG_QUOTA | 745 | #ifdef CONFIG_QUOTA |
746 | struct dquot *i_dquot[MAXQUOTAS]; | 746 | struct dquot *i_dquot[MAXQUOTAS]; |
747 | #endif | 747 | #endif |
748 | struct list_head i_devices; | 748 | struct list_head i_devices; |
749 | union { | 749 | union { |
750 | struct pipe_inode_info *i_pipe; | 750 | struct pipe_inode_info *i_pipe; |
751 | struct block_device *i_bdev; | 751 | struct block_device *i_bdev; |
752 | struct cdev *i_cdev; | 752 | struct cdev *i_cdev; |
753 | }; | 753 | }; |
754 | int i_cindex; | 754 | int i_cindex; |
755 | 755 | ||
756 | __u32 i_generation; | 756 | __u32 i_generation; |
757 | 757 | ||
758 | #ifdef CONFIG_FSNOTIFY | 758 | #ifdef CONFIG_FSNOTIFY |
759 | __u32 i_fsnotify_mask; /* all events this inode cares about */ | 759 | __u32 i_fsnotify_mask; /* all events this inode cares about */ |
760 | struct hlist_head i_fsnotify_mark_entries; /* fsnotify mark entries */ | 760 | struct hlist_head i_fsnotify_mark_entries; /* fsnotify mark entries */ |
761 | #endif | 761 | #endif |
762 | 762 | ||
763 | #ifdef CONFIG_INOTIFY | 763 | #ifdef CONFIG_INOTIFY |
764 | struct list_head inotify_watches; /* watches on this inode */ | 764 | struct list_head inotify_watches; /* watches on this inode */ |
765 | struct mutex inotify_mutex; /* protects the watches list */ | 765 | struct mutex inotify_mutex; /* protects the watches list */ |
766 | #endif | 766 | #endif |
767 | 767 | ||
768 | unsigned long i_state; | 768 | unsigned long i_state; |
769 | unsigned long dirtied_when; /* jiffies of first dirtying */ | 769 | unsigned long dirtied_when; /* jiffies of first dirtying */ |
770 | 770 | ||
771 | unsigned int i_flags; | 771 | unsigned int i_flags; |
772 | 772 | ||
773 | atomic_t i_writecount; | 773 | atomic_t i_writecount; |
774 | #ifdef CONFIG_SECURITY | 774 | #ifdef CONFIG_SECURITY |
775 | void *i_security; | 775 | void *i_security; |
776 | #endif | 776 | #endif |
777 | void *i_private; /* fs or device private pointer */ | 777 | void *i_private; /* fs or device private pointer */ |
778 | }; | 778 | }; |
779 | 779 | ||
780 | /* | 780 | /* |
781 | * inode->i_mutex nesting subclasses for the lock validator: | 781 | * inode->i_mutex nesting subclasses for the lock validator: |
782 | * | 782 | * |
783 | * 0: the object of the current VFS operation | 783 | * 0: the object of the current VFS operation |
784 | * 1: parent | 784 | * 1: parent |
785 | * 2: child/target | 785 | * 2: child/target |
786 | * 3: quota file | 786 | * 3: quota file |
787 | * | 787 | * |
788 | * The locking order between these classes is | 788 | * The locking order between these classes is |
789 | * parent -> child -> normal -> xattr -> quota | 789 | * parent -> child -> normal -> xattr -> quota |
790 | */ | 790 | */ |
791 | enum inode_i_mutex_lock_class | 791 | enum inode_i_mutex_lock_class |
792 | { | 792 | { |
793 | I_MUTEX_NORMAL, | 793 | I_MUTEX_NORMAL, |
794 | I_MUTEX_PARENT, | 794 | I_MUTEX_PARENT, |
795 | I_MUTEX_CHILD, | 795 | I_MUTEX_CHILD, |
796 | I_MUTEX_XATTR, | 796 | I_MUTEX_XATTR, |
797 | I_MUTEX_QUOTA | 797 | I_MUTEX_QUOTA |
798 | }; | 798 | }; |
799 | 799 | ||
800 | /* | 800 | /* |
801 | * NOTE: in a 32bit arch with a preemptable kernel and | 801 | * NOTE: in a 32bit arch with a preemptable kernel and |
802 | * an UP compile the i_size_read/write must be atomic | 802 | * an UP compile the i_size_read/write must be atomic |
803 | * with respect to the local cpu (unlike with preempt disabled), | 803 | * with respect to the local cpu (unlike with preempt disabled), |
804 | * but they don't need to be atomic with respect to other cpus like in | 804 | * but they don't need to be atomic with respect to other cpus like in |
805 | * true SMP (so they need either to either locally disable irq around | 805 | * true SMP (so they need either to either locally disable irq around |
806 | * the read or for example on x86 they can be still implemented as a | 806 | * the read or for example on x86 they can be still implemented as a |
807 | * cmpxchg8b without the need of the lock prefix). For SMP compiles | 807 | * cmpxchg8b without the need of the lock prefix). For SMP compiles |
808 | * and 64bit archs it makes no difference if preempt is enabled or not. | 808 | * and 64bit archs it makes no difference if preempt is enabled or not. |
809 | */ | 809 | */ |
810 | static inline loff_t i_size_read(const struct inode *inode) | 810 | static inline loff_t i_size_read(const struct inode *inode) |
811 | { | 811 | { |
812 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) | 812 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) |
813 | loff_t i_size; | 813 | loff_t i_size; |
814 | unsigned int seq; | 814 | unsigned int seq; |
815 | 815 | ||
816 | do { | 816 | do { |
817 | seq = read_seqcount_begin(&inode->i_size_seqcount); | 817 | seq = read_seqcount_begin(&inode->i_size_seqcount); |
818 | i_size = inode->i_size; | 818 | i_size = inode->i_size; |
819 | } while (read_seqcount_retry(&inode->i_size_seqcount, seq)); | 819 | } while (read_seqcount_retry(&inode->i_size_seqcount, seq)); |
820 | return i_size; | 820 | return i_size; |
821 | #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) | 821 | #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) |
822 | loff_t i_size; | 822 | loff_t i_size; |
823 | 823 | ||
824 | preempt_disable(); | 824 | preempt_disable(); |
825 | i_size = inode->i_size; | 825 | i_size = inode->i_size; |
826 | preempt_enable(); | 826 | preempt_enable(); |
827 | return i_size; | 827 | return i_size; |
828 | #else | 828 | #else |
829 | return inode->i_size; | 829 | return inode->i_size; |
830 | #endif | 830 | #endif |
831 | } | 831 | } |
832 | 832 | ||
833 | /* | 833 | /* |
834 | * NOTE: unlike i_size_read(), i_size_write() does need locking around it | 834 | * NOTE: unlike i_size_read(), i_size_write() does need locking around it |
835 | * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount | 835 | * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount |
836 | * can be lost, resulting in subsequent i_size_read() calls spinning forever. | 836 | * can be lost, resulting in subsequent i_size_read() calls spinning forever. |
837 | */ | 837 | */ |
838 | static inline void i_size_write(struct inode *inode, loff_t i_size) | 838 | static inline void i_size_write(struct inode *inode, loff_t i_size) |
839 | { | 839 | { |
840 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) | 840 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) |
841 | write_seqcount_begin(&inode->i_size_seqcount); | 841 | write_seqcount_begin(&inode->i_size_seqcount); |
842 | inode->i_size = i_size; | 842 | inode->i_size = i_size; |
843 | write_seqcount_end(&inode->i_size_seqcount); | 843 | write_seqcount_end(&inode->i_size_seqcount); |
844 | #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) | 844 | #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) |
845 | preempt_disable(); | 845 | preempt_disable(); |
846 | inode->i_size = i_size; | 846 | inode->i_size = i_size; |
847 | preempt_enable(); | 847 | preempt_enable(); |
848 | #else | 848 | #else |
849 | inode->i_size = i_size; | 849 | inode->i_size = i_size; |
850 | #endif | 850 | #endif |
851 | } | 851 | } |
852 | 852 | ||
853 | static inline unsigned iminor(const struct inode *inode) | 853 | static inline unsigned iminor(const struct inode *inode) |
854 | { | 854 | { |
855 | return MINOR(inode->i_rdev); | 855 | return MINOR(inode->i_rdev); |
856 | } | 856 | } |
857 | 857 | ||
858 | static inline unsigned imajor(const struct inode *inode) | 858 | static inline unsigned imajor(const struct inode *inode) |
859 | { | 859 | { |
860 | return MAJOR(inode->i_rdev); | 860 | return MAJOR(inode->i_rdev); |
861 | } | 861 | } |
862 | 862 | ||
863 | extern struct block_device *I_BDEV(struct inode *inode); | 863 | extern struct block_device *I_BDEV(struct inode *inode); |
864 | 864 | ||
865 | struct fown_struct { | 865 | struct fown_struct { |
866 | rwlock_t lock; /* protects pid, uid, euid fields */ | 866 | rwlock_t lock; /* protects pid, uid, euid fields */ |
867 | struct pid *pid; /* pid or -pgrp where SIGIO should be sent */ | 867 | struct pid *pid; /* pid or -pgrp where SIGIO should be sent */ |
868 | enum pid_type pid_type; /* Kind of process group SIGIO should be sent to */ | 868 | enum pid_type pid_type; /* Kind of process group SIGIO should be sent to */ |
869 | uid_t uid, euid; /* uid/euid of process setting the owner */ | 869 | uid_t uid, euid; /* uid/euid of process setting the owner */ |
870 | int signum; /* posix.1b rt signal to be delivered on IO */ | 870 | int signum; /* posix.1b rt signal to be delivered on IO */ |
871 | }; | 871 | }; |
872 | 872 | ||
873 | /* | 873 | /* |
874 | * Track a single file's readahead state | 874 | * Track a single file's readahead state |
875 | */ | 875 | */ |
876 | struct file_ra_state { | 876 | struct file_ra_state { |
877 | pgoff_t start; /* where readahead started */ | 877 | pgoff_t start; /* where readahead started */ |
878 | unsigned int size; /* # of readahead pages */ | 878 | unsigned int size; /* # of readahead pages */ |
879 | unsigned int async_size; /* do asynchronous readahead when | 879 | unsigned int async_size; /* do asynchronous readahead when |
880 | there are only # of pages ahead */ | 880 | there are only # of pages ahead */ |
881 | 881 | ||
882 | unsigned int ra_pages; /* Maximum readahead window */ | 882 | unsigned int ra_pages; /* Maximum readahead window */ |
883 | int mmap_miss; /* Cache miss stat for mmap accesses */ | 883 | int mmap_miss; /* Cache miss stat for mmap accesses */ |
884 | loff_t prev_pos; /* Cache last read() position */ | 884 | loff_t prev_pos; /* Cache last read() position */ |
885 | }; | 885 | }; |
886 | 886 | ||
887 | /* | 887 | /* |
888 | * Check if @index falls in the readahead windows. | 888 | * Check if @index falls in the readahead windows. |
889 | */ | 889 | */ |
890 | static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index) | 890 | static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index) |
891 | { | 891 | { |
892 | return (index >= ra->start && | 892 | return (index >= ra->start && |
893 | index < ra->start + ra->size); | 893 | index < ra->start + ra->size); |
894 | } | 894 | } |
895 | 895 | ||
896 | #define FILE_MNT_WRITE_TAKEN 1 | 896 | #define FILE_MNT_WRITE_TAKEN 1 |
897 | #define FILE_MNT_WRITE_RELEASED 2 | 897 | #define FILE_MNT_WRITE_RELEASED 2 |
898 | 898 | ||
899 | struct file { | 899 | struct file { |
900 | /* | 900 | /* |
901 | * fu_list becomes invalid after file_free is called and queued via | 901 | * fu_list becomes invalid after file_free is called and queued via |
902 | * fu_rcuhead for RCU freeing | 902 | * fu_rcuhead for RCU freeing |
903 | */ | 903 | */ |
904 | union { | 904 | union { |
905 | struct list_head fu_list; | 905 | struct list_head fu_list; |
906 | struct rcu_head fu_rcuhead; | 906 | struct rcu_head fu_rcuhead; |
907 | } f_u; | 907 | } f_u; |
908 | struct path f_path; | 908 | struct path f_path; |
909 | #define f_dentry f_path.dentry | 909 | #define f_dentry f_path.dentry |
910 | #define f_vfsmnt f_path.mnt | 910 | #define f_vfsmnt f_path.mnt |
911 | const struct file_operations *f_op; | 911 | const struct file_operations *f_op; |
912 | spinlock_t f_lock; /* f_ep_links, f_flags, no IRQ */ | 912 | spinlock_t f_lock; /* f_ep_links, f_flags, no IRQ */ |
913 | atomic_long_t f_count; | 913 | atomic_long_t f_count; |
914 | unsigned int f_flags; | 914 | unsigned int f_flags; |
915 | fmode_t f_mode; | 915 | fmode_t f_mode; |
916 | loff_t f_pos; | 916 | loff_t f_pos; |
917 | struct fown_struct f_owner; | 917 | struct fown_struct f_owner; |
918 | const struct cred *f_cred; | 918 | const struct cred *f_cred; |
919 | struct file_ra_state f_ra; | 919 | struct file_ra_state f_ra; |
920 | 920 | ||
921 | u64 f_version; | 921 | u64 f_version; |
922 | #ifdef CONFIG_SECURITY | 922 | #ifdef CONFIG_SECURITY |
923 | void *f_security; | 923 | void *f_security; |
924 | #endif | 924 | #endif |
925 | /* needed for tty driver, and maybe others */ | 925 | /* needed for tty driver, and maybe others */ |
926 | void *private_data; | 926 | void *private_data; |
927 | 927 | ||
928 | #ifdef CONFIG_EPOLL | 928 | #ifdef CONFIG_EPOLL |
929 | /* Used by fs/eventpoll.c to link all the hooks to this file */ | 929 | /* Used by fs/eventpoll.c to link all the hooks to this file */ |
930 | struct list_head f_ep_links; | 930 | struct list_head f_ep_links; |
931 | #endif /* #ifdef CONFIG_EPOLL */ | 931 | #endif /* #ifdef CONFIG_EPOLL */ |
932 | struct address_space *f_mapping; | 932 | struct address_space *f_mapping; |
933 | #ifdef CONFIG_DEBUG_WRITECOUNT | 933 | #ifdef CONFIG_DEBUG_WRITECOUNT |
934 | unsigned long f_mnt_write_state; | 934 | unsigned long f_mnt_write_state; |
935 | #endif | 935 | #endif |
936 | }; | 936 | }; |
937 | extern spinlock_t files_lock; | 937 | extern spinlock_t files_lock; |
938 | #define file_list_lock() spin_lock(&files_lock); | 938 | #define file_list_lock() spin_lock(&files_lock); |
939 | #define file_list_unlock() spin_unlock(&files_lock); | 939 | #define file_list_unlock() spin_unlock(&files_lock); |
940 | 940 | ||
941 | #define get_file(x) atomic_long_inc(&(x)->f_count) | 941 | #define get_file(x) atomic_long_inc(&(x)->f_count) |
942 | #define file_count(x) atomic_long_read(&(x)->f_count) | 942 | #define file_count(x) atomic_long_read(&(x)->f_count) |
943 | 943 | ||
944 | #ifdef CONFIG_DEBUG_WRITECOUNT | 944 | #ifdef CONFIG_DEBUG_WRITECOUNT |
945 | static inline void file_take_write(struct file *f) | 945 | static inline void file_take_write(struct file *f) |
946 | { | 946 | { |
947 | WARN_ON(f->f_mnt_write_state != 0); | 947 | WARN_ON(f->f_mnt_write_state != 0); |
948 | f->f_mnt_write_state = FILE_MNT_WRITE_TAKEN; | 948 | f->f_mnt_write_state = FILE_MNT_WRITE_TAKEN; |
949 | } | 949 | } |
950 | static inline void file_release_write(struct file *f) | 950 | static inline void file_release_write(struct file *f) |
951 | { | 951 | { |
952 | f->f_mnt_write_state |= FILE_MNT_WRITE_RELEASED; | 952 | f->f_mnt_write_state |= FILE_MNT_WRITE_RELEASED; |
953 | } | 953 | } |
954 | static inline void file_reset_write(struct file *f) | 954 | static inline void file_reset_write(struct file *f) |
955 | { | 955 | { |
956 | f->f_mnt_write_state = 0; | 956 | f->f_mnt_write_state = 0; |
957 | } | 957 | } |
958 | static inline void file_check_state(struct file *f) | 958 | static inline void file_check_state(struct file *f) |
959 | { | 959 | { |
960 | /* | 960 | /* |
961 | * At this point, either both or neither of these bits | 961 | * At this point, either both or neither of these bits |
962 | * should be set. | 962 | * should be set. |
963 | */ | 963 | */ |
964 | WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN); | 964 | WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN); |
965 | WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_RELEASED); | 965 | WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_RELEASED); |
966 | } | 966 | } |
967 | static inline int file_check_writeable(struct file *f) | 967 | static inline int file_check_writeable(struct file *f) |
968 | { | 968 | { |
969 | if (f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN) | 969 | if (f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN) |
970 | return 0; | 970 | return 0; |
971 | printk(KERN_WARNING "writeable file with no " | 971 | printk(KERN_WARNING "writeable file with no " |
972 | "mnt_want_write()\n"); | 972 | "mnt_want_write()\n"); |
973 | WARN_ON(1); | 973 | WARN_ON(1); |
974 | return -EINVAL; | 974 | return -EINVAL; |
975 | } | 975 | } |
976 | #else /* !CONFIG_DEBUG_WRITECOUNT */ | 976 | #else /* !CONFIG_DEBUG_WRITECOUNT */ |
977 | static inline void file_take_write(struct file *filp) {} | 977 | static inline void file_take_write(struct file *filp) {} |
978 | static inline void file_release_write(struct file *filp) {} | 978 | static inline void file_release_write(struct file *filp) {} |
979 | static inline void file_reset_write(struct file *filp) {} | 979 | static inline void file_reset_write(struct file *filp) {} |
980 | static inline void file_check_state(struct file *filp) {} | 980 | static inline void file_check_state(struct file *filp) {} |
981 | static inline int file_check_writeable(struct file *filp) | 981 | static inline int file_check_writeable(struct file *filp) |
982 | { | 982 | { |
983 | return 0; | 983 | return 0; |
984 | } | 984 | } |
985 | #endif /* CONFIG_DEBUG_WRITECOUNT */ | 985 | #endif /* CONFIG_DEBUG_WRITECOUNT */ |
986 | 986 | ||
987 | #define MAX_NON_LFS ((1UL<<31) - 1) | 987 | #define MAX_NON_LFS ((1UL<<31) - 1) |
988 | 988 | ||
989 | /* Page cache limit. The filesystems should put that into their s_maxbytes | 989 | /* Page cache limit. The filesystems should put that into their s_maxbytes |
990 | limits, otherwise bad things can happen in VM. */ | 990 | limits, otherwise bad things can happen in VM. */ |
991 | #if BITS_PER_LONG==32 | 991 | #if BITS_PER_LONG==32 |
992 | #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) | 992 | #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) |
993 | #elif BITS_PER_LONG==64 | 993 | #elif BITS_PER_LONG==64 |
994 | #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL | 994 | #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL |
995 | #endif | 995 | #endif |
996 | 996 | ||
997 | #define FL_POSIX 1 | 997 | #define FL_POSIX 1 |
998 | #define FL_FLOCK 2 | 998 | #define FL_FLOCK 2 |
999 | #define FL_ACCESS 8 /* not trying to lock, just looking */ | 999 | #define FL_ACCESS 8 /* not trying to lock, just looking */ |
1000 | #define FL_EXISTS 16 /* when unlocking, test for existence */ | 1000 | #define FL_EXISTS 16 /* when unlocking, test for existence */ |
1001 | #define FL_LEASE 32 /* lease held on this file */ | 1001 | #define FL_LEASE 32 /* lease held on this file */ |
1002 | #define FL_CLOSE 64 /* unlock on close */ | 1002 | #define FL_CLOSE 64 /* unlock on close */ |
1003 | #define FL_SLEEP 128 /* A blocking lock */ | 1003 | #define FL_SLEEP 128 /* A blocking lock */ |
1004 | 1004 | ||
1005 | /* | 1005 | /* |
1006 | * Special return value from posix_lock_file() and vfs_lock_file() for | 1006 | * Special return value from posix_lock_file() and vfs_lock_file() for |
1007 | * asynchronous locking. | 1007 | * asynchronous locking. |
1008 | */ | 1008 | */ |
1009 | #define FILE_LOCK_DEFERRED 1 | 1009 | #define FILE_LOCK_DEFERRED 1 |
1010 | 1010 | ||
1011 | /* | 1011 | /* |
1012 | * The POSIX file lock owner is determined by | 1012 | * The POSIX file lock owner is determined by |
1013 | * the "struct files_struct" in the thread group | 1013 | * the "struct files_struct" in the thread group |
1014 | * (or NULL for no owner - BSD locks). | 1014 | * (or NULL for no owner - BSD locks). |
1015 | * | 1015 | * |
1016 | * Lockd stuffs a "host" pointer into this. | 1016 | * Lockd stuffs a "host" pointer into this. |
1017 | */ | 1017 | */ |
1018 | typedef struct files_struct *fl_owner_t; | 1018 | typedef struct files_struct *fl_owner_t; |
1019 | 1019 | ||
1020 | struct file_lock_operations { | 1020 | struct file_lock_operations { |
1021 | void (*fl_copy_lock)(struct file_lock *, struct file_lock *); | 1021 | void (*fl_copy_lock)(struct file_lock *, struct file_lock *); |
1022 | void (*fl_release_private)(struct file_lock *); | 1022 | void (*fl_release_private)(struct file_lock *); |
1023 | }; | 1023 | }; |
1024 | 1024 | ||
1025 | struct lock_manager_operations { | 1025 | struct lock_manager_operations { |
1026 | int (*fl_compare_owner)(struct file_lock *, struct file_lock *); | 1026 | int (*fl_compare_owner)(struct file_lock *, struct file_lock *); |
1027 | void (*fl_notify)(struct file_lock *); /* unblock callback */ | 1027 | void (*fl_notify)(struct file_lock *); /* unblock callback */ |
1028 | int (*fl_grant)(struct file_lock *, struct file_lock *, int); | 1028 | int (*fl_grant)(struct file_lock *, struct file_lock *, int); |
1029 | void (*fl_copy_lock)(struct file_lock *, struct file_lock *); | 1029 | void (*fl_copy_lock)(struct file_lock *, struct file_lock *); |
1030 | void (*fl_release_private)(struct file_lock *); | 1030 | void (*fl_release_private)(struct file_lock *); |
1031 | void (*fl_break)(struct file_lock *); | 1031 | void (*fl_break)(struct file_lock *); |
1032 | int (*fl_mylease)(struct file_lock *, struct file_lock *); | 1032 | int (*fl_mylease)(struct file_lock *, struct file_lock *); |
1033 | int (*fl_change)(struct file_lock **, int); | 1033 | int (*fl_change)(struct file_lock **, int); |
1034 | }; | 1034 | }; |
1035 | 1035 | ||
1036 | struct lock_manager { | 1036 | struct lock_manager { |
1037 | struct list_head list; | 1037 | struct list_head list; |
1038 | }; | 1038 | }; |
1039 | 1039 | ||
1040 | void locks_start_grace(struct lock_manager *); | 1040 | void locks_start_grace(struct lock_manager *); |
1041 | void locks_end_grace(struct lock_manager *); | 1041 | void locks_end_grace(struct lock_manager *); |
1042 | int locks_in_grace(void); | 1042 | int locks_in_grace(void); |
1043 | 1043 | ||
1044 | /* that will die - we need it for nfs_lock_info */ | 1044 | /* that will die - we need it for nfs_lock_info */ |
1045 | #include <linux/nfs_fs_i.h> | 1045 | #include <linux/nfs_fs_i.h> |
1046 | 1046 | ||
1047 | struct file_lock { | 1047 | struct file_lock { |
1048 | struct file_lock *fl_next; /* singly linked list for this inode */ | 1048 | struct file_lock *fl_next; /* singly linked list for this inode */ |
1049 | struct list_head fl_link; /* doubly linked list of all locks */ | 1049 | struct list_head fl_link; /* doubly linked list of all locks */ |
1050 | struct list_head fl_block; /* circular list of blocked processes */ | 1050 | struct list_head fl_block; /* circular list of blocked processes */ |
1051 | fl_owner_t fl_owner; | 1051 | fl_owner_t fl_owner; |
1052 | unsigned char fl_flags; | 1052 | unsigned char fl_flags; |
1053 | unsigned char fl_type; | 1053 | unsigned char fl_type; |
1054 | unsigned int fl_pid; | 1054 | unsigned int fl_pid; |
1055 | struct pid *fl_nspid; | 1055 | struct pid *fl_nspid; |
1056 | wait_queue_head_t fl_wait; | 1056 | wait_queue_head_t fl_wait; |
1057 | struct file *fl_file; | 1057 | struct file *fl_file; |
1058 | loff_t fl_start; | 1058 | loff_t fl_start; |
1059 | loff_t fl_end; | 1059 | loff_t fl_end; |
1060 | 1060 | ||
1061 | struct fasync_struct * fl_fasync; /* for lease break notifications */ | 1061 | struct fasync_struct * fl_fasync; /* for lease break notifications */ |
1062 | unsigned long fl_break_time; /* for nonblocking lease breaks */ | 1062 | unsigned long fl_break_time; /* for nonblocking lease breaks */ |
1063 | 1063 | ||
1064 | struct file_lock_operations *fl_ops; /* Callbacks for filesystems */ | 1064 | struct file_lock_operations *fl_ops; /* Callbacks for filesystems */ |
1065 | struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */ | 1065 | struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */ |
1066 | union { | 1066 | union { |
1067 | struct nfs_lock_info nfs_fl; | 1067 | struct nfs_lock_info nfs_fl; |
1068 | struct nfs4_lock_info nfs4_fl; | 1068 | struct nfs4_lock_info nfs4_fl; |
1069 | struct { | 1069 | struct { |
1070 | struct list_head link; /* link in AFS vnode's pending_locks list */ | 1070 | struct list_head link; /* link in AFS vnode's pending_locks list */ |
1071 | int state; /* state of grant or error if -ve */ | 1071 | int state; /* state of grant or error if -ve */ |
1072 | } afs; | 1072 | } afs; |
1073 | } fl_u; | 1073 | } fl_u; |
1074 | }; | 1074 | }; |
1075 | 1075 | ||
1076 | /* The following constant reflects the upper bound of the file/locking space */ | 1076 | /* The following constant reflects the upper bound of the file/locking space */ |
1077 | #ifndef OFFSET_MAX | 1077 | #ifndef OFFSET_MAX |
1078 | #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1))) | 1078 | #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1))) |
1079 | #define OFFSET_MAX INT_LIMIT(loff_t) | 1079 | #define OFFSET_MAX INT_LIMIT(loff_t) |
1080 | #define OFFT_OFFSET_MAX INT_LIMIT(off_t) | 1080 | #define OFFT_OFFSET_MAX INT_LIMIT(off_t) |
1081 | #endif | 1081 | #endif |
1082 | 1082 | ||
1083 | #include <linux/fcntl.h> | 1083 | #include <linux/fcntl.h> |
1084 | 1084 | ||
1085 | extern void send_sigio(struct fown_struct *fown, int fd, int band); | 1085 | extern void send_sigio(struct fown_struct *fown, int fd, int band); |
1086 | 1086 | ||
1087 | /* fs/sync.c */ | 1087 | /* fs/sync.c */ |
1088 | extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset, | 1088 | extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset, |
1089 | loff_t endbyte, unsigned int flags); | 1089 | loff_t endbyte, unsigned int flags); |
1090 | 1090 | ||
1091 | #ifdef CONFIG_FILE_LOCKING | 1091 | #ifdef CONFIG_FILE_LOCKING |
1092 | extern int fcntl_getlk(struct file *, struct flock __user *); | 1092 | extern int fcntl_getlk(struct file *, struct flock __user *); |
1093 | extern int fcntl_setlk(unsigned int, struct file *, unsigned int, | 1093 | extern int fcntl_setlk(unsigned int, struct file *, unsigned int, |
1094 | struct flock __user *); | 1094 | struct flock __user *); |
1095 | 1095 | ||
1096 | #if BITS_PER_LONG == 32 | 1096 | #if BITS_PER_LONG == 32 |
1097 | extern int fcntl_getlk64(struct file *, struct flock64 __user *); | 1097 | extern int fcntl_getlk64(struct file *, struct flock64 __user *); |
1098 | extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, | 1098 | extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, |
1099 | struct flock64 __user *); | 1099 | struct flock64 __user *); |
1100 | #endif | 1100 | #endif |
1101 | 1101 | ||
1102 | extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); | 1102 | extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); |
1103 | extern int fcntl_getlease(struct file *filp); | 1103 | extern int fcntl_getlease(struct file *filp); |
1104 | 1104 | ||
1105 | /* fs/locks.c */ | 1105 | /* fs/locks.c */ |
1106 | extern void locks_init_lock(struct file_lock *); | 1106 | extern void locks_init_lock(struct file_lock *); |
1107 | extern void locks_copy_lock(struct file_lock *, struct file_lock *); | 1107 | extern void locks_copy_lock(struct file_lock *, struct file_lock *); |
1108 | extern void __locks_copy_lock(struct file_lock *, const struct file_lock *); | 1108 | extern void __locks_copy_lock(struct file_lock *, const struct file_lock *); |
1109 | extern void locks_remove_posix(struct file *, fl_owner_t); | 1109 | extern void locks_remove_posix(struct file *, fl_owner_t); |
1110 | extern void locks_remove_flock(struct file *); | 1110 | extern void locks_remove_flock(struct file *); |
1111 | extern void posix_test_lock(struct file *, struct file_lock *); | 1111 | extern void posix_test_lock(struct file *, struct file_lock *); |
1112 | extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *); | 1112 | extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *); |
1113 | extern int posix_lock_file_wait(struct file *, struct file_lock *); | 1113 | extern int posix_lock_file_wait(struct file *, struct file_lock *); |
1114 | extern int posix_unblock_lock(struct file *, struct file_lock *); | 1114 | extern int posix_unblock_lock(struct file *, struct file_lock *); |
1115 | extern int vfs_test_lock(struct file *, struct file_lock *); | 1115 | extern int vfs_test_lock(struct file *, struct file_lock *); |
1116 | extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *); | 1116 | extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *); |
1117 | extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl); | 1117 | extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl); |
1118 | extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl); | 1118 | extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl); |
1119 | extern int __break_lease(struct inode *inode, unsigned int flags); | 1119 | extern int __break_lease(struct inode *inode, unsigned int flags); |
1120 | extern void lease_get_mtime(struct inode *, struct timespec *time); | 1120 | extern void lease_get_mtime(struct inode *, struct timespec *time); |
1121 | extern int generic_setlease(struct file *, long, struct file_lock **); | 1121 | extern int generic_setlease(struct file *, long, struct file_lock **); |
1122 | extern int vfs_setlease(struct file *, long, struct file_lock **); | 1122 | extern int vfs_setlease(struct file *, long, struct file_lock **); |
1123 | extern int lease_modify(struct file_lock **, int); | 1123 | extern int lease_modify(struct file_lock **, int); |
1124 | extern int lock_may_read(struct inode *, loff_t start, unsigned long count); | 1124 | extern int lock_may_read(struct inode *, loff_t start, unsigned long count); |
1125 | extern int lock_may_write(struct inode *, loff_t start, unsigned long count); | 1125 | extern int lock_may_write(struct inode *, loff_t start, unsigned long count); |
1126 | #else /* !CONFIG_FILE_LOCKING */ | 1126 | #else /* !CONFIG_FILE_LOCKING */ |
1127 | static inline int fcntl_getlk(struct file *file, struct flock __user *user) | 1127 | static inline int fcntl_getlk(struct file *file, struct flock __user *user) |
1128 | { | 1128 | { |
1129 | return -EINVAL; | 1129 | return -EINVAL; |
1130 | } | 1130 | } |
1131 | 1131 | ||
1132 | static inline int fcntl_setlk(unsigned int fd, struct file *file, | 1132 | static inline int fcntl_setlk(unsigned int fd, struct file *file, |
1133 | unsigned int cmd, struct flock __user *user) | 1133 | unsigned int cmd, struct flock __user *user) |
1134 | { | 1134 | { |
1135 | return -EACCES; | 1135 | return -EACCES; |
1136 | } | 1136 | } |
1137 | 1137 | ||
1138 | #if BITS_PER_LONG == 32 | 1138 | #if BITS_PER_LONG == 32 |
1139 | static inline int fcntl_getlk64(struct file *file, struct flock64 __user *user) | 1139 | static inline int fcntl_getlk64(struct file *file, struct flock64 __user *user) |
1140 | { | 1140 | { |
1141 | return -EINVAL; | 1141 | return -EINVAL; |
1142 | } | 1142 | } |
1143 | 1143 | ||
1144 | static inline int fcntl_setlk64(unsigned int fd, struct file *file, | 1144 | static inline int fcntl_setlk64(unsigned int fd, struct file *file, |
1145 | unsigned int cmd, struct flock64 __user *user) | 1145 | unsigned int cmd, struct flock64 __user *user) |
1146 | { | 1146 | { |
1147 | return -EACCES; | 1147 | return -EACCES; |
1148 | } | 1148 | } |
1149 | #endif | 1149 | #endif |
1150 | static inline int fcntl_setlease(unsigned int fd, struct file *filp, long arg) | 1150 | static inline int fcntl_setlease(unsigned int fd, struct file *filp, long arg) |
1151 | { | 1151 | { |
1152 | return 0; | 1152 | return 0; |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | static inline int fcntl_getlease(struct file *filp) | 1155 | static inline int fcntl_getlease(struct file *filp) |
1156 | { | 1156 | { |
1157 | return 0; | 1157 | return 0; |
1158 | } | 1158 | } |
1159 | 1159 | ||
1160 | static inline void locks_init_lock(struct file_lock *fl) | 1160 | static inline void locks_init_lock(struct file_lock *fl) |
1161 | { | 1161 | { |
1162 | return; | 1162 | return; |
1163 | } | 1163 | } |
1164 | 1164 | ||
1165 | static inline void __locks_copy_lock(struct file_lock *new, struct file_lock *fl) | 1165 | static inline void __locks_copy_lock(struct file_lock *new, struct file_lock *fl) |
1166 | { | 1166 | { |
1167 | return; | 1167 | return; |
1168 | } | 1168 | } |
1169 | 1169 | ||
1170 | static inline void locks_copy_lock(struct file_lock *new, struct file_lock *fl) | 1170 | static inline void locks_copy_lock(struct file_lock *new, struct file_lock *fl) |
1171 | { | 1171 | { |
1172 | return; | 1172 | return; |
1173 | } | 1173 | } |
1174 | 1174 | ||
1175 | static inline void locks_remove_posix(struct file *filp, fl_owner_t owner) | 1175 | static inline void locks_remove_posix(struct file *filp, fl_owner_t owner) |
1176 | { | 1176 | { |
1177 | return; | 1177 | return; |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | static inline void locks_remove_flock(struct file *filp) | 1180 | static inline void locks_remove_flock(struct file *filp) |
1181 | { | 1181 | { |
1182 | return; | 1182 | return; |
1183 | } | 1183 | } |
1184 | 1184 | ||
1185 | static inline void posix_test_lock(struct file *filp, struct file_lock *fl) | 1185 | static inline void posix_test_lock(struct file *filp, struct file_lock *fl) |
1186 | { | 1186 | { |
1187 | return; | 1187 | return; |
1188 | } | 1188 | } |
1189 | 1189 | ||
1190 | static inline int posix_lock_file(struct file *filp, struct file_lock *fl, | 1190 | static inline int posix_lock_file(struct file *filp, struct file_lock *fl, |
1191 | struct file_lock *conflock) | 1191 | struct file_lock *conflock) |
1192 | { | 1192 | { |
1193 | return -ENOLCK; | 1193 | return -ENOLCK; |
1194 | } | 1194 | } |
1195 | 1195 | ||
1196 | static inline int posix_lock_file_wait(struct file *filp, struct file_lock *fl) | 1196 | static inline int posix_lock_file_wait(struct file *filp, struct file_lock *fl) |
1197 | { | 1197 | { |
1198 | return -ENOLCK; | 1198 | return -ENOLCK; |
1199 | } | 1199 | } |
1200 | 1200 | ||
1201 | static inline int posix_unblock_lock(struct file *filp, | 1201 | static inline int posix_unblock_lock(struct file *filp, |
1202 | struct file_lock *waiter) | 1202 | struct file_lock *waiter) |
1203 | { | 1203 | { |
1204 | return -ENOENT; | 1204 | return -ENOENT; |
1205 | } | 1205 | } |
1206 | 1206 | ||
1207 | static inline int vfs_test_lock(struct file *filp, struct file_lock *fl) | 1207 | static inline int vfs_test_lock(struct file *filp, struct file_lock *fl) |
1208 | { | 1208 | { |
1209 | return 0; | 1209 | return 0; |
1210 | } | 1210 | } |
1211 | 1211 | ||
1212 | static inline int vfs_lock_file(struct file *filp, unsigned int cmd, | 1212 | static inline int vfs_lock_file(struct file *filp, unsigned int cmd, |
1213 | struct file_lock *fl, struct file_lock *conf) | 1213 | struct file_lock *fl, struct file_lock *conf) |
1214 | { | 1214 | { |
1215 | return -ENOLCK; | 1215 | return -ENOLCK; |
1216 | } | 1216 | } |
1217 | 1217 | ||
1218 | static inline int vfs_cancel_lock(struct file *filp, struct file_lock *fl) | 1218 | static inline int vfs_cancel_lock(struct file *filp, struct file_lock *fl) |
1219 | { | 1219 | { |
1220 | return 0; | 1220 | return 0; |
1221 | } | 1221 | } |
1222 | 1222 | ||
1223 | static inline int flock_lock_file_wait(struct file *filp, | 1223 | static inline int flock_lock_file_wait(struct file *filp, |
1224 | struct file_lock *request) | 1224 | struct file_lock *request) |
1225 | { | 1225 | { |
1226 | return -ENOLCK; | 1226 | return -ENOLCK; |
1227 | } | 1227 | } |
1228 | 1228 | ||
1229 | static inline int __break_lease(struct inode *inode, unsigned int mode) | 1229 | static inline int __break_lease(struct inode *inode, unsigned int mode) |
1230 | { | 1230 | { |
1231 | return 0; | 1231 | return 0; |
1232 | } | 1232 | } |
1233 | 1233 | ||
1234 | static inline void lease_get_mtime(struct inode *inode, struct timespec *time) | 1234 | static inline void lease_get_mtime(struct inode *inode, struct timespec *time) |
1235 | { | 1235 | { |
1236 | return; | 1236 | return; |
1237 | } | 1237 | } |
1238 | 1238 | ||
1239 | static inline int generic_setlease(struct file *filp, long arg, | 1239 | static inline int generic_setlease(struct file *filp, long arg, |
1240 | struct file_lock **flp) | 1240 | struct file_lock **flp) |
1241 | { | 1241 | { |
1242 | return -EINVAL; | 1242 | return -EINVAL; |
1243 | } | 1243 | } |
1244 | 1244 | ||
1245 | static inline int vfs_setlease(struct file *filp, long arg, | 1245 | static inline int vfs_setlease(struct file *filp, long arg, |
1246 | struct file_lock **lease) | 1246 | struct file_lock **lease) |
1247 | { | 1247 | { |
1248 | return -EINVAL; | 1248 | return -EINVAL; |
1249 | } | 1249 | } |
1250 | 1250 | ||
1251 | static inline int lease_modify(struct file_lock **before, int arg) | 1251 | static inline int lease_modify(struct file_lock **before, int arg) |
1252 | { | 1252 | { |
1253 | return -EINVAL; | 1253 | return -EINVAL; |
1254 | } | 1254 | } |
1255 | 1255 | ||
1256 | static inline int lock_may_read(struct inode *inode, loff_t start, | 1256 | static inline int lock_may_read(struct inode *inode, loff_t start, |
1257 | unsigned long len) | 1257 | unsigned long len) |
1258 | { | 1258 | { |
1259 | return 1; | 1259 | return 1; |
1260 | } | 1260 | } |
1261 | 1261 | ||
1262 | static inline int lock_may_write(struct inode *inode, loff_t start, | 1262 | static inline int lock_may_write(struct inode *inode, loff_t start, |
1263 | unsigned long len) | 1263 | unsigned long len) |
1264 | { | 1264 | { |
1265 | return 1; | 1265 | return 1; |
1266 | } | 1266 | } |
1267 | 1267 | ||
1268 | #endif /* !CONFIG_FILE_LOCKING */ | 1268 | #endif /* !CONFIG_FILE_LOCKING */ |
1269 | 1269 | ||
1270 | 1270 | ||
1271 | struct fasync_struct { | 1271 | struct fasync_struct { |
1272 | int magic; | 1272 | int magic; |
1273 | int fa_fd; | 1273 | int fa_fd; |
1274 | struct fasync_struct *fa_next; /* singly linked list */ | 1274 | struct fasync_struct *fa_next; /* singly linked list */ |
1275 | struct file *fa_file; | 1275 | struct file *fa_file; |
1276 | }; | 1276 | }; |
1277 | 1277 | ||
1278 | #define FASYNC_MAGIC 0x4601 | 1278 | #define FASYNC_MAGIC 0x4601 |
1279 | 1279 | ||
1280 | /* SMP safe fasync helpers: */ | 1280 | /* SMP safe fasync helpers: */ |
1281 | extern int fasync_helper(int, struct file *, int, struct fasync_struct **); | 1281 | extern int fasync_helper(int, struct file *, int, struct fasync_struct **); |
1282 | /* can be called from interrupts */ | 1282 | /* can be called from interrupts */ |
1283 | extern void kill_fasync(struct fasync_struct **, int, int); | 1283 | extern void kill_fasync(struct fasync_struct **, int, int); |
1284 | /* only for net: no internal synchronization */ | 1284 | /* only for net: no internal synchronization */ |
1285 | extern void __kill_fasync(struct fasync_struct *, int, int); | 1285 | extern void __kill_fasync(struct fasync_struct *, int, int); |
1286 | 1286 | ||
1287 | extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force); | 1287 | extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force); |
1288 | extern int f_setown(struct file *filp, unsigned long arg, int force); | 1288 | extern int f_setown(struct file *filp, unsigned long arg, int force); |
1289 | extern void f_delown(struct file *filp); | 1289 | extern void f_delown(struct file *filp); |
1290 | extern pid_t f_getown(struct file *filp); | 1290 | extern pid_t f_getown(struct file *filp); |
1291 | extern int send_sigurg(struct fown_struct *fown); | 1291 | extern int send_sigurg(struct fown_struct *fown); |
1292 | 1292 | ||
1293 | /* | 1293 | /* |
1294 | * Umount options | 1294 | * Umount options |
1295 | */ | 1295 | */ |
1296 | 1296 | ||
1297 | #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */ | 1297 | #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */ |
1298 | #define MNT_DETACH 0x00000002 /* Just detach from the tree */ | 1298 | #define MNT_DETACH 0x00000002 /* Just detach from the tree */ |
1299 | #define MNT_EXPIRE 0x00000004 /* Mark for expiry */ | 1299 | #define MNT_EXPIRE 0x00000004 /* Mark for expiry */ |
1300 | 1300 | ||
1301 | extern struct list_head super_blocks; | 1301 | extern struct list_head super_blocks; |
1302 | extern spinlock_t sb_lock; | 1302 | extern spinlock_t sb_lock; |
1303 | 1303 | ||
1304 | #define sb_entry(list) list_entry((list), struct super_block, s_list) | 1304 | #define sb_entry(list) list_entry((list), struct super_block, s_list) |
1305 | #define S_BIAS (1<<30) | 1305 | #define S_BIAS (1<<30) |
1306 | struct super_block { | 1306 | struct super_block { |
1307 | struct list_head s_list; /* Keep this first */ | 1307 | struct list_head s_list; /* Keep this first */ |
1308 | dev_t s_dev; /* search index; _not_ kdev_t */ | 1308 | dev_t s_dev; /* search index; _not_ kdev_t */ |
1309 | unsigned long s_blocksize; | 1309 | unsigned long s_blocksize; |
1310 | unsigned char s_blocksize_bits; | 1310 | unsigned char s_blocksize_bits; |
1311 | unsigned char s_dirt; | 1311 | unsigned char s_dirt; |
1312 | unsigned long long s_maxbytes; /* Max file size */ | 1312 | unsigned long long s_maxbytes; /* Max file size */ |
1313 | struct file_system_type *s_type; | 1313 | struct file_system_type *s_type; |
1314 | const struct super_operations *s_op; | 1314 | const struct super_operations *s_op; |
1315 | struct dquot_operations *dq_op; | 1315 | struct dquot_operations *dq_op; |
1316 | struct quotactl_ops *s_qcop; | 1316 | struct quotactl_ops *s_qcop; |
1317 | const struct export_operations *s_export_op; | 1317 | const struct export_operations *s_export_op; |
1318 | unsigned long s_flags; | 1318 | unsigned long s_flags; |
1319 | unsigned long s_magic; | 1319 | unsigned long s_magic; |
1320 | struct dentry *s_root; | 1320 | struct dentry *s_root; |
1321 | struct rw_semaphore s_umount; | 1321 | struct rw_semaphore s_umount; |
1322 | struct mutex s_lock; | 1322 | struct mutex s_lock; |
1323 | int s_count; | 1323 | int s_count; |
1324 | int s_need_sync_fs; | 1324 | int s_need_sync_fs; |
1325 | atomic_t s_active; | 1325 | atomic_t s_active; |
1326 | #ifdef CONFIG_SECURITY | 1326 | #ifdef CONFIG_SECURITY |
1327 | void *s_security; | 1327 | void *s_security; |
1328 | #endif | 1328 | #endif |
1329 | struct xattr_handler **s_xattr; | 1329 | struct xattr_handler **s_xattr; |
1330 | 1330 | ||
1331 | struct list_head s_inodes; /* all inodes */ | 1331 | struct list_head s_inodes; /* all inodes */ |
1332 | struct list_head s_dirty; /* dirty inodes */ | 1332 | struct list_head s_dirty; /* dirty inodes */ |
1333 | struct list_head s_io; /* parked for writeback */ | 1333 | struct list_head s_io; /* parked for writeback */ |
1334 | struct list_head s_more_io; /* parked for more writeback */ | 1334 | struct list_head s_more_io; /* parked for more writeback */ |
1335 | struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */ | 1335 | struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */ |
1336 | struct list_head s_files; | 1336 | struct list_head s_files; |
1337 | /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */ | 1337 | /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */ |
1338 | struct list_head s_dentry_lru; /* unused dentry lru */ | 1338 | struct list_head s_dentry_lru; /* unused dentry lru */ |
1339 | int s_nr_dentry_unused; /* # of dentry on lru */ | 1339 | int s_nr_dentry_unused; /* # of dentry on lru */ |
1340 | 1340 | ||
1341 | struct block_device *s_bdev; | 1341 | struct block_device *s_bdev; |
1342 | struct mtd_info *s_mtd; | 1342 | struct mtd_info *s_mtd; |
1343 | struct list_head s_instances; | 1343 | struct list_head s_instances; |
1344 | struct quota_info s_dquot; /* Diskquota specific options */ | 1344 | struct quota_info s_dquot; /* Diskquota specific options */ |
1345 | 1345 | ||
1346 | int s_frozen; | 1346 | int s_frozen; |
1347 | wait_queue_head_t s_wait_unfrozen; | 1347 | wait_queue_head_t s_wait_unfrozen; |
1348 | 1348 | ||
1349 | char s_id[32]; /* Informational name */ | 1349 | char s_id[32]; /* Informational name */ |
1350 | 1350 | ||
1351 | void *s_fs_info; /* Filesystem private info */ | 1351 | void *s_fs_info; /* Filesystem private info */ |
1352 | fmode_t s_mode; | 1352 | fmode_t s_mode; |
1353 | 1353 | ||
1354 | /* | 1354 | /* |
1355 | * The next field is for VFS *only*. No filesystems have any business | 1355 | * The next field is for VFS *only*. No filesystems have any business |
1356 | * even looking at it. You had been warned. | 1356 | * even looking at it. You had been warned. |
1357 | */ | 1357 | */ |
1358 | struct mutex s_vfs_rename_mutex; /* Kludge */ | 1358 | struct mutex s_vfs_rename_mutex; /* Kludge */ |
1359 | 1359 | ||
1360 | /* Granularity of c/m/atime in ns. | 1360 | /* Granularity of c/m/atime in ns. |
1361 | Cannot be worse than a second */ | 1361 | Cannot be worse than a second */ |
1362 | u32 s_time_gran; | 1362 | u32 s_time_gran; |
1363 | 1363 | ||
1364 | /* | 1364 | /* |
1365 | * Filesystem subtype. If non-empty the filesystem type field | 1365 | * Filesystem subtype. If non-empty the filesystem type field |
1366 | * in /proc/mounts will be "type.subtype" | 1366 | * in /proc/mounts will be "type.subtype" |
1367 | */ | 1367 | */ |
1368 | char *s_subtype; | 1368 | char *s_subtype; |
1369 | 1369 | ||
1370 | /* | 1370 | /* |
1371 | * Saved mount options for lazy filesystems using | 1371 | * Saved mount options for lazy filesystems using |
1372 | * generic_show_options() | 1372 | * generic_show_options() |
1373 | */ | 1373 | */ |
1374 | char *s_options; | 1374 | char *s_options; |
1375 | }; | 1375 | }; |
1376 | 1376 | ||
1377 | extern struct timespec current_fs_time(struct super_block *sb); | 1377 | extern struct timespec current_fs_time(struct super_block *sb); |
1378 | 1378 | ||
1379 | /* | 1379 | /* |
1380 | * Snapshotting support. | 1380 | * Snapshotting support. |
1381 | */ | 1381 | */ |
1382 | enum { | 1382 | enum { |
1383 | SB_UNFROZEN = 0, | 1383 | SB_UNFROZEN = 0, |
1384 | SB_FREEZE_WRITE = 1, | 1384 | SB_FREEZE_WRITE = 1, |
1385 | SB_FREEZE_TRANS = 2, | 1385 | SB_FREEZE_TRANS = 2, |
1386 | }; | 1386 | }; |
1387 | 1387 | ||
1388 | #define vfs_check_frozen(sb, level) \ | 1388 | #define vfs_check_frozen(sb, level) \ |
1389 | wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level))) | 1389 | wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level))) |
1390 | 1390 | ||
1391 | #define get_fs_excl() atomic_inc(¤t->fs_excl) | 1391 | #define get_fs_excl() atomic_inc(¤t->fs_excl) |
1392 | #define put_fs_excl() atomic_dec(¤t->fs_excl) | 1392 | #define put_fs_excl() atomic_dec(¤t->fs_excl) |
1393 | #define has_fs_excl() atomic_read(¤t->fs_excl) | 1393 | #define has_fs_excl() atomic_read(¤t->fs_excl) |
1394 | 1394 | ||
1395 | #define is_owner_or_cap(inode) \ | 1395 | #define is_owner_or_cap(inode) \ |
1396 | ((current_fsuid() == (inode)->i_uid) || capable(CAP_FOWNER)) | 1396 | ((current_fsuid() == (inode)->i_uid) || capable(CAP_FOWNER)) |
1397 | 1397 | ||
1398 | /* not quite ready to be deprecated, but... */ | 1398 | /* not quite ready to be deprecated, but... */ |
1399 | extern void lock_super(struct super_block *); | 1399 | extern void lock_super(struct super_block *); |
1400 | extern void unlock_super(struct super_block *); | 1400 | extern void unlock_super(struct super_block *); |
1401 | 1401 | ||
1402 | /* | 1402 | /* |
1403 | * VFS helper functions.. | 1403 | * VFS helper functions.. |
1404 | */ | 1404 | */ |
1405 | extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *); | 1405 | extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *); |
1406 | extern int vfs_mkdir(struct inode *, struct dentry *, int); | 1406 | extern int vfs_mkdir(struct inode *, struct dentry *, int); |
1407 | extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t); | 1407 | extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t); |
1408 | extern int vfs_symlink(struct inode *, struct dentry *, const char *); | 1408 | extern int vfs_symlink(struct inode *, struct dentry *, const char *); |
1409 | extern int vfs_link(struct dentry *, struct inode *, struct dentry *); | 1409 | extern int vfs_link(struct dentry *, struct inode *, struct dentry *); |
1410 | extern int vfs_rmdir(struct inode *, struct dentry *); | 1410 | extern int vfs_rmdir(struct inode *, struct dentry *); |
1411 | extern int vfs_unlink(struct inode *, struct dentry *); | 1411 | extern int vfs_unlink(struct inode *, struct dentry *); |
1412 | extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); | 1412 | extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); |
1413 | 1413 | ||
1414 | /* | 1414 | /* |
1415 | * VFS dentry helper functions. | 1415 | * VFS dentry helper functions. |
1416 | */ | 1416 | */ |
1417 | extern void dentry_unhash(struct dentry *dentry); | 1417 | extern void dentry_unhash(struct dentry *dentry); |
1418 | 1418 | ||
1419 | /* | 1419 | /* |
1420 | * VFS file helper functions. | 1420 | * VFS file helper functions. |
1421 | */ | 1421 | */ |
1422 | extern int file_permission(struct file *, int); | 1422 | extern int file_permission(struct file *, int); |
1423 | 1423 | ||
1424 | /* | 1424 | /* |
1425 | * VFS FS_IOC_FIEMAP helper definitions. | 1425 | * VFS FS_IOC_FIEMAP helper definitions. |
1426 | */ | 1426 | */ |
1427 | struct fiemap_extent_info { | 1427 | struct fiemap_extent_info { |
1428 | unsigned int fi_flags; /* Flags as passed from user */ | 1428 | unsigned int fi_flags; /* Flags as passed from user */ |
1429 | unsigned int fi_extents_mapped; /* Number of mapped extents */ | 1429 | unsigned int fi_extents_mapped; /* Number of mapped extents */ |
1430 | unsigned int fi_extents_max; /* Size of fiemap_extent array */ | 1430 | unsigned int fi_extents_max; /* Size of fiemap_extent array */ |
1431 | struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent | 1431 | struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent |
1432 | * array */ | 1432 | * array */ |
1433 | }; | 1433 | }; |
1434 | int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical, | 1434 | int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical, |
1435 | u64 phys, u64 len, u32 flags); | 1435 | u64 phys, u64 len, u32 flags); |
1436 | int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags); | 1436 | int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags); |
1437 | 1437 | ||
1438 | /* | 1438 | /* |
1439 | * File types | 1439 | * File types |
1440 | * | 1440 | * |
1441 | * NOTE! These match bits 12..15 of stat.st_mode | 1441 | * NOTE! These match bits 12..15 of stat.st_mode |
1442 | * (ie "(i_mode >> 12) & 15"). | 1442 | * (ie "(i_mode >> 12) & 15"). |
1443 | */ | 1443 | */ |
1444 | #define DT_UNKNOWN 0 | 1444 | #define DT_UNKNOWN 0 |
1445 | #define DT_FIFO 1 | 1445 | #define DT_FIFO 1 |
1446 | #define DT_CHR 2 | 1446 | #define DT_CHR 2 |
1447 | #define DT_DIR 4 | 1447 | #define DT_DIR 4 |
1448 | #define DT_BLK 6 | 1448 | #define DT_BLK 6 |
1449 | #define DT_REG 8 | 1449 | #define DT_REG 8 |
1450 | #define DT_LNK 10 | 1450 | #define DT_LNK 10 |
1451 | #define DT_SOCK 12 | 1451 | #define DT_SOCK 12 |
1452 | #define DT_WHT 14 | 1452 | #define DT_WHT 14 |
1453 | 1453 | ||
1454 | #define OSYNC_METADATA (1<<0) | 1454 | #define OSYNC_METADATA (1<<0) |
1455 | #define OSYNC_DATA (1<<1) | 1455 | #define OSYNC_DATA (1<<1) |
1456 | #define OSYNC_INODE (1<<2) | 1456 | #define OSYNC_INODE (1<<2) |
1457 | int generic_osync_inode(struct inode *, struct address_space *, int); | 1457 | int generic_osync_inode(struct inode *, struct address_space *, int); |
1458 | 1458 | ||
1459 | /* | 1459 | /* |
1460 | * This is the "filldir" function type, used by readdir() to let | 1460 | * This is the "filldir" function type, used by readdir() to let |
1461 | * the kernel specify what kind of dirent layout it wants to have. | 1461 | * the kernel specify what kind of dirent layout it wants to have. |
1462 | * This allows the kernel to read directories into kernel space or | 1462 | * This allows the kernel to read directories into kernel space or |
1463 | * to have different dirent layouts depending on the binary type. | 1463 | * to have different dirent layouts depending on the binary type. |
1464 | */ | 1464 | */ |
1465 | typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); | 1465 | typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); |
1466 | struct block_device_operations; | 1466 | struct block_device_operations; |
1467 | 1467 | ||
1468 | /* These macros are for out of kernel modules to test that | 1468 | /* These macros are for out of kernel modules to test that |
1469 | * the kernel supports the unlocked_ioctl and compat_ioctl | 1469 | * the kernel supports the unlocked_ioctl and compat_ioctl |
1470 | * fields in struct file_operations. */ | 1470 | * fields in struct file_operations. */ |
1471 | #define HAVE_COMPAT_IOCTL 1 | 1471 | #define HAVE_COMPAT_IOCTL 1 |
1472 | #define HAVE_UNLOCKED_IOCTL 1 | 1472 | #define HAVE_UNLOCKED_IOCTL 1 |
1473 | 1473 | ||
1474 | /* | 1474 | /* |
1475 | * NOTE: | 1475 | * NOTE: |
1476 | * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl | 1476 | * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl |
1477 | * can be called without the big kernel lock held in all filesystems. | 1477 | * can be called without the big kernel lock held in all filesystems. |
1478 | */ | 1478 | */ |
1479 | struct file_operations { | 1479 | struct file_operations { |
1480 | struct module *owner; | 1480 | struct module *owner; |
1481 | loff_t (*llseek) (struct file *, loff_t, int); | 1481 | loff_t (*llseek) (struct file *, loff_t, int); |
1482 | ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); | 1482 | ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); |
1483 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); | 1483 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); |
1484 | ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | 1484 | ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); |
1485 | ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | 1485 | ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); |
1486 | int (*readdir) (struct file *, void *, filldir_t); | 1486 | int (*readdir) (struct file *, void *, filldir_t); |
1487 | unsigned int (*poll) (struct file *, struct poll_table_struct *); | 1487 | unsigned int (*poll) (struct file *, struct poll_table_struct *); |
1488 | int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); | 1488 | int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); |
1489 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); | 1489 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); |
1490 | long (*compat_ioctl) (struct file *, unsigned int, unsigned long); | 1490 | long (*compat_ioctl) (struct file *, unsigned int, unsigned long); |
1491 | int (*mmap) (struct file *, struct vm_area_struct *); | 1491 | int (*mmap) (struct file *, struct vm_area_struct *); |
1492 | int (*open) (struct inode *, struct file *); | 1492 | int (*open) (struct inode *, struct file *); |
1493 | int (*flush) (struct file *, fl_owner_t id); | 1493 | int (*flush) (struct file *, fl_owner_t id); |
1494 | int (*release) (struct inode *, struct file *); | 1494 | int (*release) (struct inode *, struct file *); |
1495 | int (*fsync) (struct file *, struct dentry *, int datasync); | 1495 | int (*fsync) (struct file *, struct dentry *, int datasync); |
1496 | int (*aio_fsync) (struct kiocb *, int datasync); | 1496 | int (*aio_fsync) (struct kiocb *, int datasync); |
1497 | int (*fasync) (int, struct file *, int); | 1497 | int (*fasync) (int, struct file *, int); |
1498 | int (*lock) (struct file *, int, struct file_lock *); | 1498 | int (*lock) (struct file *, int, struct file_lock *); |
1499 | ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); | 1499 | ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); |
1500 | unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); | 1500 | unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); |
1501 | int (*check_flags)(int); | 1501 | int (*check_flags)(int); |
1502 | int (*flock) (struct file *, int, struct file_lock *); | 1502 | int (*flock) (struct file *, int, struct file_lock *); |
1503 | ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); | 1503 | ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); |
1504 | ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); | 1504 | ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); |
1505 | int (*setlease)(struct file *, long, struct file_lock **); | 1505 | int (*setlease)(struct file *, long, struct file_lock **); |
1506 | }; | 1506 | }; |
1507 | 1507 | ||
1508 | struct inode_operations { | 1508 | struct inode_operations { |
1509 | int (*create) (struct inode *,struct dentry *,int, struct nameidata *); | 1509 | int (*create) (struct inode *,struct dentry *,int, struct nameidata *); |
1510 | struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *); | 1510 | struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *); |
1511 | int (*link) (struct dentry *,struct inode *,struct dentry *); | 1511 | int (*link) (struct dentry *,struct inode *,struct dentry *); |
1512 | int (*unlink) (struct inode *,struct dentry *); | 1512 | int (*unlink) (struct inode *,struct dentry *); |
1513 | int (*symlink) (struct inode *,struct dentry *,const char *); | 1513 | int (*symlink) (struct inode *,struct dentry *,const char *); |
1514 | int (*mkdir) (struct inode *,struct dentry *,int); | 1514 | int (*mkdir) (struct inode *,struct dentry *,int); |
1515 | int (*rmdir) (struct inode *,struct dentry *); | 1515 | int (*rmdir) (struct inode *,struct dentry *); |
1516 | int (*mknod) (struct inode *,struct dentry *,int,dev_t); | 1516 | int (*mknod) (struct inode *,struct dentry *,int,dev_t); |
1517 | int (*rename) (struct inode *, struct dentry *, | 1517 | int (*rename) (struct inode *, struct dentry *, |
1518 | struct inode *, struct dentry *); | 1518 | struct inode *, struct dentry *); |
1519 | int (*readlink) (struct dentry *, char __user *,int); | 1519 | int (*readlink) (struct dentry *, char __user *,int); |
1520 | void * (*follow_link) (struct dentry *, struct nameidata *); | 1520 | void * (*follow_link) (struct dentry *, struct nameidata *); |
1521 | void (*put_link) (struct dentry *, struct nameidata *, void *); | 1521 | void (*put_link) (struct dentry *, struct nameidata *, void *); |
1522 | void (*truncate) (struct inode *); | 1522 | void (*truncate) (struct inode *); |
1523 | int (*permission) (struct inode *, int); | 1523 | int (*permission) (struct inode *, int); |
1524 | int (*setattr) (struct dentry *, struct iattr *); | 1524 | int (*setattr) (struct dentry *, struct iattr *); |
1525 | int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *); | 1525 | int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *); |
1526 | int (*setxattr) (struct dentry *, const char *,const void *,size_t,int); | 1526 | int (*setxattr) (struct dentry *, const char *,const void *,size_t,int); |
1527 | ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t); | 1527 | ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t); |
1528 | ssize_t (*listxattr) (struct dentry *, char *, size_t); | 1528 | ssize_t (*listxattr) (struct dentry *, char *, size_t); |
1529 | int (*removexattr) (struct dentry *, const char *); | 1529 | int (*removexattr) (struct dentry *, const char *); |
1530 | void (*truncate_range)(struct inode *, loff_t, loff_t); | 1530 | void (*truncate_range)(struct inode *, loff_t, loff_t); |
1531 | long (*fallocate)(struct inode *inode, int mode, loff_t offset, | 1531 | long (*fallocate)(struct inode *inode, int mode, loff_t offset, |
1532 | loff_t len); | 1532 | loff_t len); |
1533 | int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, | 1533 | int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, |
1534 | u64 len); | 1534 | u64 len); |
1535 | }; | 1535 | }; |
1536 | 1536 | ||
1537 | struct seq_file; | 1537 | struct seq_file; |
1538 | 1538 | ||
1539 | ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, | 1539 | ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, |
1540 | unsigned long nr_segs, unsigned long fast_segs, | 1540 | unsigned long nr_segs, unsigned long fast_segs, |
1541 | struct iovec *fast_pointer, | 1541 | struct iovec *fast_pointer, |
1542 | struct iovec **ret_pointer); | 1542 | struct iovec **ret_pointer); |
1543 | 1543 | ||
1544 | extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); | 1544 | extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); |
1545 | extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); | 1545 | extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); |
1546 | extern ssize_t vfs_readv(struct file *, const struct iovec __user *, | 1546 | extern ssize_t vfs_readv(struct file *, const struct iovec __user *, |
1547 | unsigned long, loff_t *); | 1547 | unsigned long, loff_t *); |
1548 | extern ssize_t vfs_writev(struct file *, const struct iovec __user *, | 1548 | extern ssize_t vfs_writev(struct file *, const struct iovec __user *, |
1549 | unsigned long, loff_t *); | 1549 | unsigned long, loff_t *); |
1550 | 1550 | ||
1551 | struct super_operations { | 1551 | struct super_operations { |
1552 | struct inode *(*alloc_inode)(struct super_block *sb); | 1552 | struct inode *(*alloc_inode)(struct super_block *sb); |
1553 | void (*destroy_inode)(struct inode *); | 1553 | void (*destroy_inode)(struct inode *); |
1554 | 1554 | ||
1555 | void (*dirty_inode) (struct inode *); | 1555 | void (*dirty_inode) (struct inode *); |
1556 | int (*write_inode) (struct inode *, int); | 1556 | int (*write_inode) (struct inode *, int); |
1557 | void (*drop_inode) (struct inode *); | 1557 | void (*drop_inode) (struct inode *); |
1558 | void (*delete_inode) (struct inode *); | 1558 | void (*delete_inode) (struct inode *); |
1559 | void (*put_super) (struct super_block *); | 1559 | void (*put_super) (struct super_block *); |
1560 | void (*write_super) (struct super_block *); | 1560 | void (*write_super) (struct super_block *); |
1561 | int (*sync_fs)(struct super_block *sb, int wait); | 1561 | int (*sync_fs)(struct super_block *sb, int wait); |
1562 | int (*freeze_fs) (struct super_block *); | 1562 | int (*freeze_fs) (struct super_block *); |
1563 | int (*unfreeze_fs) (struct super_block *); | 1563 | int (*unfreeze_fs) (struct super_block *); |
1564 | int (*statfs) (struct dentry *, struct kstatfs *); | 1564 | int (*statfs) (struct dentry *, struct kstatfs *); |
1565 | int (*remount_fs) (struct super_block *, int *, char *); | 1565 | int (*remount_fs) (struct super_block *, int *, char *); |
1566 | void (*clear_inode) (struct inode *); | 1566 | void (*clear_inode) (struct inode *); |
1567 | void (*umount_begin) (struct super_block *); | 1567 | void (*umount_begin) (struct super_block *); |
1568 | 1568 | ||
1569 | int (*show_options)(struct seq_file *, struct vfsmount *); | 1569 | int (*show_options)(struct seq_file *, struct vfsmount *); |
1570 | int (*show_stats)(struct seq_file *, struct vfsmount *); | 1570 | int (*show_stats)(struct seq_file *, struct vfsmount *); |
1571 | #ifdef CONFIG_QUOTA | 1571 | #ifdef CONFIG_QUOTA |
1572 | ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); | 1572 | ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); |
1573 | ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); | 1573 | ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); |
1574 | #endif | 1574 | #endif |
1575 | int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t); | 1575 | int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t); |
1576 | }; | 1576 | }; |
1577 | 1577 | ||
1578 | /* | 1578 | /* |
1579 | * Inode state bits. Protected by inode_lock. | 1579 | * Inode state bits. Protected by inode_lock. |
1580 | * | 1580 | * |
1581 | * Three bits determine the dirty state of the inode, I_DIRTY_SYNC, | 1581 | * Three bits determine the dirty state of the inode, I_DIRTY_SYNC, |
1582 | * I_DIRTY_DATASYNC and I_DIRTY_PAGES. | 1582 | * I_DIRTY_DATASYNC and I_DIRTY_PAGES. |
1583 | * | 1583 | * |
1584 | * Four bits define the lifetime of an inode. Initially, inodes are I_NEW, | 1584 | * Four bits define the lifetime of an inode. Initially, inodes are I_NEW, |
1585 | * until that flag is cleared. I_WILL_FREE, I_FREEING and I_CLEAR are set at | 1585 | * until that flag is cleared. I_WILL_FREE, I_FREEING and I_CLEAR are set at |
1586 | * various stages of removing an inode. | 1586 | * various stages of removing an inode. |
1587 | * | 1587 | * |
1588 | * Two bits are used for locking and completion notification, I_LOCK and I_SYNC. | 1588 | * Two bits are used for locking and completion notification, I_LOCK and I_SYNC. |
1589 | * | 1589 | * |
1590 | * I_DIRTY_SYNC Inode is dirty, but doesn't have to be written on | 1590 | * I_DIRTY_SYNC Inode is dirty, but doesn't have to be written on |
1591 | * fdatasync(). i_atime is the usual cause. | 1591 | * fdatasync(). i_atime is the usual cause. |
1592 | * I_DIRTY_DATASYNC Data-related inode changes pending. We keep track of | 1592 | * I_DIRTY_DATASYNC Data-related inode changes pending. We keep track of |
1593 | * these changes separately from I_DIRTY_SYNC so that we | 1593 | * these changes separately from I_DIRTY_SYNC so that we |
1594 | * don't have to write inode on fdatasync() when only | 1594 | * don't have to write inode on fdatasync() when only |
1595 | * mtime has changed in it. | 1595 | * mtime has changed in it. |
1596 | * I_DIRTY_PAGES Inode has dirty pages. Inode itself may be clean. | 1596 | * I_DIRTY_PAGES Inode has dirty pages. Inode itself may be clean. |
1597 | * I_NEW get_new_inode() sets i_state to I_LOCK|I_NEW. Both | 1597 | * I_NEW get_new_inode() sets i_state to I_LOCK|I_NEW. Both |
1598 | * are cleared by unlock_new_inode(), called from iget(). | 1598 | * are cleared by unlock_new_inode(), called from iget(). |
1599 | * I_WILL_FREE Must be set when calling write_inode_now() if i_count | 1599 | * I_WILL_FREE Must be set when calling write_inode_now() if i_count |
1600 | * is zero. I_FREEING must be set when I_WILL_FREE is | 1600 | * is zero. I_FREEING must be set when I_WILL_FREE is |
1601 | * cleared. | 1601 | * cleared. |
1602 | * I_FREEING Set when inode is about to be freed but still has dirty | 1602 | * I_FREEING Set when inode is about to be freed but still has dirty |
1603 | * pages or buffers attached or the inode itself is still | 1603 | * pages or buffers attached or the inode itself is still |
1604 | * dirty. | 1604 | * dirty. |
1605 | * I_CLEAR Set by clear_inode(). In this state the inode is clean | 1605 | * I_CLEAR Set by clear_inode(). In this state the inode is clean |
1606 | * and can be destroyed. | 1606 | * and can be destroyed. |
1607 | * | 1607 | * |
1608 | * Inodes that are I_WILL_FREE, I_FREEING or I_CLEAR are | 1608 | * Inodes that are I_WILL_FREE, I_FREEING or I_CLEAR are |
1609 | * prohibited for many purposes. iget() must wait for | 1609 | * prohibited for many purposes. iget() must wait for |
1610 | * the inode to be completely released, then create it | 1610 | * the inode to be completely released, then create it |
1611 | * anew. Other functions will just ignore such inodes, | 1611 | * anew. Other functions will just ignore such inodes, |
1612 | * if appropriate. I_LOCK is used for waiting. | 1612 | * if appropriate. I_LOCK is used for waiting. |
1613 | * | 1613 | * |
1614 | * I_LOCK Serves as both a mutex and completion notification. | 1614 | * I_LOCK Serves as both a mutex and completion notification. |
1615 | * New inodes set I_LOCK. If two processes both create | 1615 | * New inodes set I_LOCK. If two processes both create |
1616 | * the same inode, one of them will release its inode and | 1616 | * the same inode, one of them will release its inode and |
1617 | * wait for I_LOCK to be released before returning. | 1617 | * wait for I_LOCK to be released before returning. |
1618 | * Inodes in I_WILL_FREE, I_FREEING or I_CLEAR state can | 1618 | * Inodes in I_WILL_FREE, I_FREEING or I_CLEAR state can |
1619 | * also cause waiting on I_LOCK, without I_LOCK actually | 1619 | * also cause waiting on I_LOCK, without I_LOCK actually |
1620 | * being set. find_inode() uses this to prevent returning | 1620 | * being set. find_inode() uses this to prevent returning |
1621 | * nearly-dead inodes. | 1621 | * nearly-dead inodes. |
1622 | * I_SYNC Similar to I_LOCK, but limited in scope to writeback | 1622 | * I_SYNC Similar to I_LOCK, but limited in scope to writeback |
1623 | * of inode dirty data. Having a separate lock for this | 1623 | * of inode dirty data. Having a separate lock for this |
1624 | * purpose reduces latency and prevents some filesystem- | 1624 | * purpose reduces latency and prevents some filesystem- |
1625 | * specific deadlocks. | 1625 | * specific deadlocks. |
1626 | * | 1626 | * |
1627 | * Q: What is the difference between I_WILL_FREE and I_FREEING? | 1627 | * Q: What is the difference between I_WILL_FREE and I_FREEING? |
1628 | * Q: igrab() only checks on (I_FREEING|I_WILL_FREE). Should it also check on | 1628 | * Q: igrab() only checks on (I_FREEING|I_WILL_FREE). Should it also check on |
1629 | * I_CLEAR? If not, why? | 1629 | * I_CLEAR? If not, why? |
1630 | */ | 1630 | */ |
1631 | #define I_DIRTY_SYNC 1 | 1631 | #define I_DIRTY_SYNC 1 |
1632 | #define I_DIRTY_DATASYNC 2 | 1632 | #define I_DIRTY_DATASYNC 2 |
1633 | #define I_DIRTY_PAGES 4 | 1633 | #define I_DIRTY_PAGES 4 |
1634 | #define I_NEW 8 | 1634 | #define I_NEW 8 |
1635 | #define I_WILL_FREE 16 | 1635 | #define I_WILL_FREE 16 |
1636 | #define I_FREEING 32 | 1636 | #define I_FREEING 32 |
1637 | #define I_CLEAR 64 | 1637 | #define I_CLEAR 64 |
1638 | #define __I_LOCK 7 | 1638 | #define __I_LOCK 7 |
1639 | #define I_LOCK (1 << __I_LOCK) | 1639 | #define I_LOCK (1 << __I_LOCK) |
1640 | #define __I_SYNC 8 | 1640 | #define __I_SYNC 8 |
1641 | #define I_SYNC (1 << __I_SYNC) | 1641 | #define I_SYNC (1 << __I_SYNC) |
1642 | 1642 | ||
1643 | #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES) | 1643 | #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES) |
1644 | 1644 | ||
1645 | extern void __mark_inode_dirty(struct inode *, int); | 1645 | extern void __mark_inode_dirty(struct inode *, int); |
1646 | static inline void mark_inode_dirty(struct inode *inode) | 1646 | static inline void mark_inode_dirty(struct inode *inode) |
1647 | { | 1647 | { |
1648 | __mark_inode_dirty(inode, I_DIRTY); | 1648 | __mark_inode_dirty(inode, I_DIRTY); |
1649 | } | 1649 | } |
1650 | 1650 | ||
1651 | static inline void mark_inode_dirty_sync(struct inode *inode) | 1651 | static inline void mark_inode_dirty_sync(struct inode *inode) |
1652 | { | 1652 | { |
1653 | __mark_inode_dirty(inode, I_DIRTY_SYNC); | 1653 | __mark_inode_dirty(inode, I_DIRTY_SYNC); |
1654 | } | 1654 | } |
1655 | 1655 | ||
1656 | /** | 1656 | /** |
1657 | * inc_nlink - directly increment an inode's link count | 1657 | * inc_nlink - directly increment an inode's link count |
1658 | * @inode: inode | 1658 | * @inode: inode |
1659 | * | 1659 | * |
1660 | * This is a low-level filesystem helper to replace any | 1660 | * This is a low-level filesystem helper to replace any |
1661 | * direct filesystem manipulation of i_nlink. Currently, | 1661 | * direct filesystem manipulation of i_nlink. Currently, |
1662 | * it is only here for parity with dec_nlink(). | 1662 | * it is only here for parity with dec_nlink(). |
1663 | */ | 1663 | */ |
1664 | static inline void inc_nlink(struct inode *inode) | 1664 | static inline void inc_nlink(struct inode *inode) |
1665 | { | 1665 | { |
1666 | inode->i_nlink++; | 1666 | inode->i_nlink++; |
1667 | } | 1667 | } |
1668 | 1668 | ||
1669 | static inline void inode_inc_link_count(struct inode *inode) | 1669 | static inline void inode_inc_link_count(struct inode *inode) |
1670 | { | 1670 | { |
1671 | inc_nlink(inode); | 1671 | inc_nlink(inode); |
1672 | mark_inode_dirty(inode); | 1672 | mark_inode_dirty(inode); |
1673 | } | 1673 | } |
1674 | 1674 | ||
1675 | /** | 1675 | /** |
1676 | * drop_nlink - directly drop an inode's link count | 1676 | * drop_nlink - directly drop an inode's link count |
1677 | * @inode: inode | 1677 | * @inode: inode |
1678 | * | 1678 | * |
1679 | * This is a low-level filesystem helper to replace any | 1679 | * This is a low-level filesystem helper to replace any |
1680 | * direct filesystem manipulation of i_nlink. In cases | 1680 | * direct filesystem manipulation of i_nlink. In cases |
1681 | * where we are attempting to track writes to the | 1681 | * where we are attempting to track writes to the |
1682 | * filesystem, a decrement to zero means an imminent | 1682 | * filesystem, a decrement to zero means an imminent |
1683 | * write when the file is truncated and actually unlinked | 1683 | * write when the file is truncated and actually unlinked |
1684 | * on the filesystem. | 1684 | * on the filesystem. |
1685 | */ | 1685 | */ |
1686 | static inline void drop_nlink(struct inode *inode) | 1686 | static inline void drop_nlink(struct inode *inode) |
1687 | { | 1687 | { |
1688 | inode->i_nlink--; | 1688 | inode->i_nlink--; |
1689 | } | 1689 | } |
1690 | 1690 | ||
1691 | /** | 1691 | /** |
1692 | * clear_nlink - directly zero an inode's link count | 1692 | * clear_nlink - directly zero an inode's link count |
1693 | * @inode: inode | 1693 | * @inode: inode |
1694 | * | 1694 | * |
1695 | * This is a low-level filesystem helper to replace any | 1695 | * This is a low-level filesystem helper to replace any |
1696 | * direct filesystem manipulation of i_nlink. See | 1696 | * direct filesystem manipulation of i_nlink. See |
1697 | * drop_nlink() for why we care about i_nlink hitting zero. | 1697 | * drop_nlink() for why we care about i_nlink hitting zero. |
1698 | */ | 1698 | */ |
1699 | static inline void clear_nlink(struct inode *inode) | 1699 | static inline void clear_nlink(struct inode *inode) |
1700 | { | 1700 | { |
1701 | inode->i_nlink = 0; | 1701 | inode->i_nlink = 0; |
1702 | } | 1702 | } |
1703 | 1703 | ||
1704 | static inline void inode_dec_link_count(struct inode *inode) | 1704 | static inline void inode_dec_link_count(struct inode *inode) |
1705 | { | 1705 | { |
1706 | drop_nlink(inode); | 1706 | drop_nlink(inode); |
1707 | mark_inode_dirty(inode); | 1707 | mark_inode_dirty(inode); |
1708 | } | 1708 | } |
1709 | 1709 | ||
1710 | /** | 1710 | /** |
1711 | * inode_inc_iversion - increments i_version | 1711 | * inode_inc_iversion - increments i_version |
1712 | * @inode: inode that need to be updated | 1712 | * @inode: inode that need to be updated |
1713 | * | 1713 | * |
1714 | * Every time the inode is modified, the i_version field will be incremented. | 1714 | * Every time the inode is modified, the i_version field will be incremented. |
1715 | * The filesystem has to be mounted with i_version flag | 1715 | * The filesystem has to be mounted with i_version flag |
1716 | */ | 1716 | */ |
1717 | 1717 | ||
1718 | static inline void inode_inc_iversion(struct inode *inode) | 1718 | static inline void inode_inc_iversion(struct inode *inode) |
1719 | { | 1719 | { |
1720 | spin_lock(&inode->i_lock); | 1720 | spin_lock(&inode->i_lock); |
1721 | inode->i_version++; | 1721 | inode->i_version++; |
1722 | spin_unlock(&inode->i_lock); | 1722 | spin_unlock(&inode->i_lock); |
1723 | } | 1723 | } |
1724 | 1724 | ||
1725 | extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry); | 1725 | extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry); |
1726 | static inline void file_accessed(struct file *file) | 1726 | static inline void file_accessed(struct file *file) |
1727 | { | 1727 | { |
1728 | if (!(file->f_flags & O_NOATIME)) | 1728 | if (!(file->f_flags & O_NOATIME)) |
1729 | touch_atime(file->f_path.mnt, file->f_path.dentry); | 1729 | touch_atime(file->f_path.mnt, file->f_path.dentry); |
1730 | } | 1730 | } |
1731 | 1731 | ||
1732 | int sync_inode(struct inode *inode, struct writeback_control *wbc); | 1732 | int sync_inode(struct inode *inode, struct writeback_control *wbc); |
1733 | 1733 | ||
1734 | struct file_system_type { | 1734 | struct file_system_type { |
1735 | const char *name; | 1735 | const char *name; |
1736 | int fs_flags; | 1736 | int fs_flags; |
1737 | int (*get_sb) (struct file_system_type *, int, | 1737 | int (*get_sb) (struct file_system_type *, int, |
1738 | const char *, void *, struct vfsmount *); | 1738 | const char *, void *, struct vfsmount *); |
1739 | void (*kill_sb) (struct super_block *); | 1739 | void (*kill_sb) (struct super_block *); |
1740 | struct module *owner; | 1740 | struct module *owner; |
1741 | struct file_system_type * next; | 1741 | struct file_system_type * next; |
1742 | struct list_head fs_supers; | 1742 | struct list_head fs_supers; |
1743 | 1743 | ||
1744 | struct lock_class_key s_lock_key; | 1744 | struct lock_class_key s_lock_key; |
1745 | struct lock_class_key s_umount_key; | 1745 | struct lock_class_key s_umount_key; |
1746 | 1746 | ||
1747 | struct lock_class_key i_lock_key; | 1747 | struct lock_class_key i_lock_key; |
1748 | struct lock_class_key i_mutex_key; | 1748 | struct lock_class_key i_mutex_key; |
1749 | struct lock_class_key i_mutex_dir_key; | 1749 | struct lock_class_key i_mutex_dir_key; |
1750 | struct lock_class_key i_alloc_sem_key; | 1750 | struct lock_class_key i_alloc_sem_key; |
1751 | }; | 1751 | }; |
1752 | 1752 | ||
1753 | extern int get_sb_ns(struct file_system_type *fs_type, int flags, void *data, | 1753 | extern int get_sb_ns(struct file_system_type *fs_type, int flags, void *data, |
1754 | int (*fill_super)(struct super_block *, void *, int), | 1754 | int (*fill_super)(struct super_block *, void *, int), |
1755 | struct vfsmount *mnt); | 1755 | struct vfsmount *mnt); |
1756 | extern int get_sb_bdev(struct file_system_type *fs_type, | 1756 | extern int get_sb_bdev(struct file_system_type *fs_type, |
1757 | int flags, const char *dev_name, void *data, | 1757 | int flags, const char *dev_name, void *data, |
1758 | int (*fill_super)(struct super_block *, void *, int), | 1758 | int (*fill_super)(struct super_block *, void *, int), |
1759 | struct vfsmount *mnt); | 1759 | struct vfsmount *mnt); |
1760 | extern int get_sb_single(struct file_system_type *fs_type, | 1760 | extern int get_sb_single(struct file_system_type *fs_type, |
1761 | int flags, void *data, | 1761 | int flags, void *data, |
1762 | int (*fill_super)(struct super_block *, void *, int), | 1762 | int (*fill_super)(struct super_block *, void *, int), |
1763 | struct vfsmount *mnt); | 1763 | struct vfsmount *mnt); |
1764 | extern int get_sb_nodev(struct file_system_type *fs_type, | 1764 | extern int get_sb_nodev(struct file_system_type *fs_type, |
1765 | int flags, void *data, | 1765 | int flags, void *data, |
1766 | int (*fill_super)(struct super_block *, void *, int), | 1766 | int (*fill_super)(struct super_block *, void *, int), |
1767 | struct vfsmount *mnt); | 1767 | struct vfsmount *mnt); |
1768 | void generic_shutdown_super(struct super_block *sb); | 1768 | void generic_shutdown_super(struct super_block *sb); |
1769 | void kill_block_super(struct super_block *sb); | 1769 | void kill_block_super(struct super_block *sb); |
1770 | void kill_anon_super(struct super_block *sb); | 1770 | void kill_anon_super(struct super_block *sb); |
1771 | void kill_litter_super(struct super_block *sb); | 1771 | void kill_litter_super(struct super_block *sb); |
1772 | void deactivate_super(struct super_block *sb); | 1772 | void deactivate_super(struct super_block *sb); |
1773 | void deactivate_locked_super(struct super_block *sb); | 1773 | void deactivate_locked_super(struct super_block *sb); |
1774 | int set_anon_super(struct super_block *s, void *data); | 1774 | int set_anon_super(struct super_block *s, void *data); |
1775 | struct super_block *sget(struct file_system_type *type, | 1775 | struct super_block *sget(struct file_system_type *type, |
1776 | int (*test)(struct super_block *,void *), | 1776 | int (*test)(struct super_block *,void *), |
1777 | int (*set)(struct super_block *,void *), | 1777 | int (*set)(struct super_block *,void *), |
1778 | void *data); | 1778 | void *data); |
1779 | extern int get_sb_pseudo(struct file_system_type *, char *, | 1779 | extern int get_sb_pseudo(struct file_system_type *, char *, |
1780 | const struct super_operations *ops, unsigned long, | 1780 | const struct super_operations *ops, unsigned long, |
1781 | struct vfsmount *mnt); | 1781 | struct vfsmount *mnt); |
1782 | extern void simple_set_mnt(struct vfsmount *mnt, struct super_block *sb); | 1782 | extern void simple_set_mnt(struct vfsmount *mnt, struct super_block *sb); |
1783 | int __put_super_and_need_restart(struct super_block *sb); | 1783 | int __put_super_and_need_restart(struct super_block *sb); |
1784 | 1784 | ||
1785 | /* Alas, no aliases. Too much hassle with bringing module.h everywhere */ | 1785 | /* Alas, no aliases. Too much hassle with bringing module.h everywhere */ |
1786 | #define fops_get(fops) \ | 1786 | #define fops_get(fops) \ |
1787 | (((fops) && try_module_get((fops)->owner) ? (fops) : NULL)) | 1787 | (((fops) && try_module_get((fops)->owner) ? (fops) : NULL)) |
1788 | #define fops_put(fops) \ | 1788 | #define fops_put(fops) \ |
1789 | do { if (fops) module_put((fops)->owner); } while(0) | 1789 | do { if (fops) module_put((fops)->owner); } while(0) |
1790 | 1790 | ||
1791 | extern int register_filesystem(struct file_system_type *); | 1791 | extern int register_filesystem(struct file_system_type *); |
1792 | extern int unregister_filesystem(struct file_system_type *); | 1792 | extern int unregister_filesystem(struct file_system_type *); |
1793 | extern struct vfsmount *kern_mount_data(struct file_system_type *, void *data); | 1793 | extern struct vfsmount *kern_mount_data(struct file_system_type *, void *data); |
1794 | #define kern_mount(type) kern_mount_data(type, NULL) | 1794 | #define kern_mount(type) kern_mount_data(type, NULL) |
1795 | extern int may_umount_tree(struct vfsmount *); | 1795 | extern int may_umount_tree(struct vfsmount *); |
1796 | extern int may_umount(struct vfsmount *); | 1796 | extern int may_umount(struct vfsmount *); |
1797 | extern long do_mount(char *, char *, char *, unsigned long, void *); | 1797 | extern long do_mount(char *, char *, char *, unsigned long, void *); |
1798 | extern struct vfsmount *collect_mounts(struct path *); | 1798 | extern struct vfsmount *collect_mounts(struct path *); |
1799 | extern void drop_collected_mounts(struct vfsmount *); | 1799 | extern void drop_collected_mounts(struct vfsmount *); |
1800 | 1800 | ||
1801 | extern int vfs_statfs(struct dentry *, struct kstatfs *); | 1801 | extern int vfs_statfs(struct dentry *, struct kstatfs *); |
1802 | 1802 | ||
1803 | extern int current_umask(void); | 1803 | extern int current_umask(void); |
1804 | 1804 | ||
1805 | /* /sys/fs */ | 1805 | /* /sys/fs */ |
1806 | extern struct kobject *fs_kobj; | 1806 | extern struct kobject *fs_kobj; |
1807 | 1807 | ||
1808 | extern int rw_verify_area(int, struct file *, loff_t *, size_t); | 1808 | extern int rw_verify_area(int, struct file *, loff_t *, size_t); |
1809 | 1809 | ||
1810 | #define FLOCK_VERIFY_READ 1 | 1810 | #define FLOCK_VERIFY_READ 1 |
1811 | #define FLOCK_VERIFY_WRITE 2 | 1811 | #define FLOCK_VERIFY_WRITE 2 |
1812 | 1812 | ||
1813 | #ifdef CONFIG_FILE_LOCKING | 1813 | #ifdef CONFIG_FILE_LOCKING |
1814 | extern int locks_mandatory_locked(struct inode *); | 1814 | extern int locks_mandatory_locked(struct inode *); |
1815 | extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); | 1815 | extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); |
1816 | 1816 | ||
1817 | /* | 1817 | /* |
1818 | * Candidates for mandatory locking have the setgid bit set | 1818 | * Candidates for mandatory locking have the setgid bit set |
1819 | * but no group execute bit - an otherwise meaningless combination. | 1819 | * but no group execute bit - an otherwise meaningless combination. |
1820 | */ | 1820 | */ |
1821 | 1821 | ||
1822 | static inline int __mandatory_lock(struct inode *ino) | 1822 | static inline int __mandatory_lock(struct inode *ino) |
1823 | { | 1823 | { |
1824 | return (ino->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID; | 1824 | return (ino->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID; |
1825 | } | 1825 | } |
1826 | 1826 | ||
1827 | /* | 1827 | /* |
1828 | * ... and these candidates should be on MS_MANDLOCK mounted fs, | 1828 | * ... and these candidates should be on MS_MANDLOCK mounted fs, |
1829 | * otherwise these will be advisory locks | 1829 | * otherwise these will be advisory locks |
1830 | */ | 1830 | */ |
1831 | 1831 | ||
1832 | static inline int mandatory_lock(struct inode *ino) | 1832 | static inline int mandatory_lock(struct inode *ino) |
1833 | { | 1833 | { |
1834 | return IS_MANDLOCK(ino) && __mandatory_lock(ino); | 1834 | return IS_MANDLOCK(ino) && __mandatory_lock(ino); |
1835 | } | 1835 | } |
1836 | 1836 | ||
1837 | static inline int locks_verify_locked(struct inode *inode) | 1837 | static inline int locks_verify_locked(struct inode *inode) |
1838 | { | 1838 | { |
1839 | if (mandatory_lock(inode)) | 1839 | if (mandatory_lock(inode)) |
1840 | return locks_mandatory_locked(inode); | 1840 | return locks_mandatory_locked(inode); |
1841 | return 0; | 1841 | return 0; |
1842 | } | 1842 | } |
1843 | 1843 | ||
1844 | static inline int locks_verify_truncate(struct inode *inode, | 1844 | static inline int locks_verify_truncate(struct inode *inode, |
1845 | struct file *filp, | 1845 | struct file *filp, |
1846 | loff_t size) | 1846 | loff_t size) |
1847 | { | 1847 | { |
1848 | if (inode->i_flock && mandatory_lock(inode)) | 1848 | if (inode->i_flock && mandatory_lock(inode)) |
1849 | return locks_mandatory_area( | 1849 | return locks_mandatory_area( |
1850 | FLOCK_VERIFY_WRITE, inode, filp, | 1850 | FLOCK_VERIFY_WRITE, inode, filp, |
1851 | size < inode->i_size ? size : inode->i_size, | 1851 | size < inode->i_size ? size : inode->i_size, |
1852 | (size < inode->i_size ? inode->i_size - size | 1852 | (size < inode->i_size ? inode->i_size - size |
1853 | : size - inode->i_size) | 1853 | : size - inode->i_size) |
1854 | ); | 1854 | ); |
1855 | return 0; | 1855 | return 0; |
1856 | } | 1856 | } |
1857 | 1857 | ||
1858 | static inline int break_lease(struct inode *inode, unsigned int mode) | 1858 | static inline int break_lease(struct inode *inode, unsigned int mode) |
1859 | { | 1859 | { |
1860 | if (inode->i_flock) | 1860 | if (inode->i_flock) |
1861 | return __break_lease(inode, mode); | 1861 | return __break_lease(inode, mode); |
1862 | return 0; | 1862 | return 0; |
1863 | } | 1863 | } |
1864 | #else /* !CONFIG_FILE_LOCKING */ | 1864 | #else /* !CONFIG_FILE_LOCKING */ |
1865 | static inline int locks_mandatory_locked(struct inode *inode) | 1865 | static inline int locks_mandatory_locked(struct inode *inode) |
1866 | { | 1866 | { |
1867 | return 0; | 1867 | return 0; |
1868 | } | 1868 | } |
1869 | 1869 | ||
1870 | static inline int locks_mandatory_area(int rw, struct inode *inode, | 1870 | static inline int locks_mandatory_area(int rw, struct inode *inode, |
1871 | struct file *filp, loff_t offset, | 1871 | struct file *filp, loff_t offset, |
1872 | size_t count) | 1872 | size_t count) |
1873 | { | 1873 | { |
1874 | return 0; | 1874 | return 0; |
1875 | } | 1875 | } |
1876 | 1876 | ||
1877 | static inline int __mandatory_lock(struct inode *inode) | 1877 | static inline int __mandatory_lock(struct inode *inode) |
1878 | { | 1878 | { |
1879 | return 0; | 1879 | return 0; |
1880 | } | 1880 | } |
1881 | 1881 | ||
1882 | static inline int mandatory_lock(struct inode *inode) | 1882 | static inline int mandatory_lock(struct inode *inode) |
1883 | { | 1883 | { |
1884 | return 0; | 1884 | return 0; |
1885 | } | 1885 | } |
1886 | 1886 | ||
1887 | static inline int locks_verify_locked(struct inode *inode) | 1887 | static inline int locks_verify_locked(struct inode *inode) |
1888 | { | 1888 | { |
1889 | return 0; | 1889 | return 0; |
1890 | } | 1890 | } |
1891 | 1891 | ||
1892 | static inline int locks_verify_truncate(struct inode *inode, struct file *filp, | 1892 | static inline int locks_verify_truncate(struct inode *inode, struct file *filp, |
1893 | size_t size) | 1893 | size_t size) |
1894 | { | 1894 | { |
1895 | return 0; | 1895 | return 0; |
1896 | } | 1896 | } |
1897 | 1897 | ||
1898 | static inline int break_lease(struct inode *inode, unsigned int mode) | 1898 | static inline int break_lease(struct inode *inode, unsigned int mode) |
1899 | { | 1899 | { |
1900 | return 0; | 1900 | return 0; |
1901 | } | 1901 | } |
1902 | 1902 | ||
1903 | #endif /* CONFIG_FILE_LOCKING */ | 1903 | #endif /* CONFIG_FILE_LOCKING */ |
1904 | 1904 | ||
1905 | /* fs/open.c */ | 1905 | /* fs/open.c */ |
1906 | 1906 | ||
1907 | extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs, | 1907 | extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs, |
1908 | struct file *filp); | 1908 | struct file *filp); |
1909 | extern long do_sys_open(int dfd, const char __user *filename, int flags, | 1909 | extern long do_sys_open(int dfd, const char __user *filename, int flags, |
1910 | int mode); | 1910 | int mode); |
1911 | extern struct file *filp_open(const char *, int, int); | 1911 | extern struct file *filp_open(const char *, int, int); |
1912 | extern struct file * dentry_open(struct dentry *, struct vfsmount *, int, | 1912 | extern struct file * dentry_open(struct dentry *, struct vfsmount *, int, |
1913 | const struct cred *); | 1913 | const struct cred *); |
1914 | extern int filp_close(struct file *, fl_owner_t id); | 1914 | extern int filp_close(struct file *, fl_owner_t id); |
1915 | extern char * getname(const char __user *); | 1915 | extern char * getname(const char __user *); |
1916 | 1916 | ||
1917 | /* fs/dcache.c */ | 1917 | /* fs/dcache.c */ |
1918 | extern void __init vfs_caches_init_early(void); | 1918 | extern void __init vfs_caches_init_early(void); |
1919 | extern void __init vfs_caches_init(unsigned long); | 1919 | extern void __init vfs_caches_init(unsigned long); |
1920 | 1920 | ||
1921 | extern struct kmem_cache *names_cachep; | 1921 | extern struct kmem_cache *names_cachep; |
1922 | 1922 | ||
1923 | #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL) | 1923 | #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL) |
1924 | #define __putname(name) kmem_cache_free(names_cachep, (void *)(name)) | 1924 | #define __putname(name) kmem_cache_free(names_cachep, (void *)(name)) |
1925 | #ifndef CONFIG_AUDITSYSCALL | 1925 | #ifndef CONFIG_AUDITSYSCALL |
1926 | #define putname(name) __putname(name) | 1926 | #define putname(name) __putname(name) |
1927 | #else | 1927 | #else |
1928 | extern void putname(const char *name); | 1928 | extern void putname(const char *name); |
1929 | #endif | 1929 | #endif |
1930 | 1930 | ||
1931 | #ifdef CONFIG_BLOCK | 1931 | #ifdef CONFIG_BLOCK |
1932 | extern int register_blkdev(unsigned int, const char *); | 1932 | extern int register_blkdev(unsigned int, const char *); |
1933 | extern void unregister_blkdev(unsigned int, const char *); | 1933 | extern void unregister_blkdev(unsigned int, const char *); |
1934 | extern struct block_device *bdget(dev_t); | 1934 | extern struct block_device *bdget(dev_t); |
1935 | extern void bd_set_size(struct block_device *, loff_t size); | 1935 | extern void bd_set_size(struct block_device *, loff_t size); |
1936 | extern void bd_forget(struct inode *inode); | 1936 | extern void bd_forget(struct inode *inode); |
1937 | extern void bdput(struct block_device *); | 1937 | extern void bdput(struct block_device *); |
1938 | extern struct block_device *open_by_devnum(dev_t, fmode_t); | 1938 | extern struct block_device *open_by_devnum(dev_t, fmode_t); |
1939 | extern void invalidate_bdev(struct block_device *); | 1939 | extern void invalidate_bdev(struct block_device *); |
1940 | extern int sync_blockdev(struct block_device *bdev); | 1940 | extern int sync_blockdev(struct block_device *bdev); |
1941 | extern struct super_block *freeze_bdev(struct block_device *); | 1941 | extern struct super_block *freeze_bdev(struct block_device *); |
1942 | extern void emergency_thaw_all(void); | 1942 | extern void emergency_thaw_all(void); |
1943 | extern int thaw_bdev(struct block_device *bdev, struct super_block *sb); | 1943 | extern int thaw_bdev(struct block_device *bdev, struct super_block *sb); |
1944 | extern int fsync_bdev(struct block_device *); | 1944 | extern int fsync_bdev(struct block_device *); |
1945 | extern int fsync_super(struct super_block *); | 1945 | extern int fsync_super(struct super_block *); |
1946 | extern int fsync_no_super(struct block_device *); | 1946 | extern int fsync_no_super(struct block_device *); |
1947 | #else | 1947 | #else |
1948 | static inline void bd_forget(struct inode *inode) {} | 1948 | static inline void bd_forget(struct inode *inode) {} |
1949 | static inline int sync_blockdev(struct block_device *bdev) { return 0; } | 1949 | static inline int sync_blockdev(struct block_device *bdev) { return 0; } |
1950 | static inline void invalidate_bdev(struct block_device *bdev) {} | 1950 | static inline void invalidate_bdev(struct block_device *bdev) {} |
1951 | 1951 | ||
1952 | static inline struct super_block *freeze_bdev(struct block_device *sb) | 1952 | static inline struct super_block *freeze_bdev(struct block_device *sb) |
1953 | { | 1953 | { |
1954 | return NULL; | 1954 | return NULL; |
1955 | } | 1955 | } |
1956 | 1956 | ||
1957 | static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb) | 1957 | static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb) |
1958 | { | 1958 | { |
1959 | return 0; | 1959 | return 0; |
1960 | } | 1960 | } |
1961 | #endif | 1961 | #endif |
1962 | extern const struct file_operations def_blk_fops; | 1962 | extern const struct file_operations def_blk_fops; |
1963 | extern const struct file_operations def_chr_fops; | 1963 | extern const struct file_operations def_chr_fops; |
1964 | extern const struct file_operations bad_sock_fops; | 1964 | extern const struct file_operations bad_sock_fops; |
1965 | extern const struct file_operations def_fifo_fops; | 1965 | extern const struct file_operations def_fifo_fops; |
1966 | #ifdef CONFIG_BLOCK | 1966 | #ifdef CONFIG_BLOCK |
1967 | extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); | 1967 | extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); |
1968 | extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long); | 1968 | extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long); |
1969 | extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); | 1969 | extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); |
1970 | extern int blkdev_get(struct block_device *, fmode_t); | 1970 | extern int blkdev_get(struct block_device *, fmode_t); |
1971 | extern int blkdev_put(struct block_device *, fmode_t); | 1971 | extern int blkdev_put(struct block_device *, fmode_t); |
1972 | extern int bd_claim(struct block_device *, void *); | 1972 | extern int bd_claim(struct block_device *, void *); |
1973 | extern void bd_release(struct block_device *); | 1973 | extern void bd_release(struct block_device *); |
1974 | #ifdef CONFIG_SYSFS | 1974 | #ifdef CONFIG_SYSFS |
1975 | extern int bd_claim_by_disk(struct block_device *, void *, struct gendisk *); | 1975 | extern int bd_claim_by_disk(struct block_device *, void *, struct gendisk *); |
1976 | extern void bd_release_from_disk(struct block_device *, struct gendisk *); | 1976 | extern void bd_release_from_disk(struct block_device *, struct gendisk *); |
1977 | #else | 1977 | #else |
1978 | #define bd_claim_by_disk(bdev, holder, disk) bd_claim(bdev, holder) | 1978 | #define bd_claim_by_disk(bdev, holder, disk) bd_claim(bdev, holder) |
1979 | #define bd_release_from_disk(bdev, disk) bd_release(bdev) | 1979 | #define bd_release_from_disk(bdev, disk) bd_release(bdev) |
1980 | #endif | 1980 | #endif |
1981 | #endif | 1981 | #endif |
1982 | 1982 | ||
1983 | /* fs/char_dev.c */ | 1983 | /* fs/char_dev.c */ |
1984 | #define CHRDEV_MAJOR_HASH_SIZE 255 | 1984 | #define CHRDEV_MAJOR_HASH_SIZE 255 |
1985 | extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *); | 1985 | extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *); |
1986 | extern int register_chrdev_region(dev_t, unsigned, const char *); | 1986 | extern int register_chrdev_region(dev_t, unsigned, const char *); |
1987 | extern int register_chrdev(unsigned int, const char *, | 1987 | extern int register_chrdev(unsigned int, const char *, |
1988 | const struct file_operations *); | 1988 | const struct file_operations *); |
1989 | extern void unregister_chrdev(unsigned int, const char *); | 1989 | extern void unregister_chrdev(unsigned int, const char *); |
1990 | extern void unregister_chrdev_region(dev_t, unsigned); | 1990 | extern void unregister_chrdev_region(dev_t, unsigned); |
1991 | extern void chrdev_show(struct seq_file *,off_t); | 1991 | extern void chrdev_show(struct seq_file *,off_t); |
1992 | 1992 | ||
1993 | /* fs/block_dev.c */ | 1993 | /* fs/block_dev.c */ |
1994 | #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ | 1994 | #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ |
1995 | #define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */ | 1995 | #define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */ |
1996 | 1996 | ||
1997 | #ifdef CONFIG_BLOCK | 1997 | #ifdef CONFIG_BLOCK |
1998 | #define BLKDEV_MAJOR_HASH_SIZE 255 | 1998 | #define BLKDEV_MAJOR_HASH_SIZE 255 |
1999 | extern const char *__bdevname(dev_t, char *buffer); | 1999 | extern const char *__bdevname(dev_t, char *buffer); |
2000 | extern const char *bdevname(struct block_device *bdev, char *buffer); | 2000 | extern const char *bdevname(struct block_device *bdev, char *buffer); |
2001 | extern struct block_device *lookup_bdev(const char *); | 2001 | extern struct block_device *lookup_bdev(const char *); |
2002 | extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *); | 2002 | extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *); |
2003 | extern void close_bdev_exclusive(struct block_device *, fmode_t); | 2003 | extern void close_bdev_exclusive(struct block_device *, fmode_t); |
2004 | extern void blkdev_show(struct seq_file *,off_t); | 2004 | extern void blkdev_show(struct seq_file *,off_t); |
2005 | 2005 | ||
2006 | #else | 2006 | #else |
2007 | #define BLKDEV_MAJOR_HASH_SIZE 0 | 2007 | #define BLKDEV_MAJOR_HASH_SIZE 0 |
2008 | #endif | 2008 | #endif |
2009 | 2009 | ||
2010 | extern void init_special_inode(struct inode *, umode_t, dev_t); | 2010 | extern void init_special_inode(struct inode *, umode_t, dev_t); |
2011 | 2011 | ||
2012 | /* Invalid inode operations -- fs/bad_inode.c */ | 2012 | /* Invalid inode operations -- fs/bad_inode.c */ |
2013 | extern void make_bad_inode(struct inode *); | 2013 | extern void make_bad_inode(struct inode *); |
2014 | extern int is_bad_inode(struct inode *); | 2014 | extern int is_bad_inode(struct inode *); |
2015 | 2015 | ||
2016 | extern const struct file_operations read_pipefifo_fops; | 2016 | extern const struct file_operations read_pipefifo_fops; |
2017 | extern const struct file_operations write_pipefifo_fops; | 2017 | extern const struct file_operations write_pipefifo_fops; |
2018 | extern const struct file_operations rdwr_pipefifo_fops; | 2018 | extern const struct file_operations rdwr_pipefifo_fops; |
2019 | 2019 | ||
2020 | extern int fs_may_remount_ro(struct super_block *); | 2020 | extern int fs_may_remount_ro(struct super_block *); |
2021 | 2021 | ||
2022 | #ifdef CONFIG_BLOCK | 2022 | #ifdef CONFIG_BLOCK |
2023 | /* | 2023 | /* |
2024 | * return READ, READA, or WRITE | 2024 | * return READ, READA, or WRITE |
2025 | */ | 2025 | */ |
2026 | #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK)) | 2026 | #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK)) |
2027 | 2027 | ||
2028 | /* | 2028 | /* |
2029 | * return data direction, READ or WRITE | 2029 | * return data direction, READ or WRITE |
2030 | */ | 2030 | */ |
2031 | #define bio_data_dir(bio) ((bio)->bi_rw & 1) | 2031 | #define bio_data_dir(bio) ((bio)->bi_rw & 1) |
2032 | 2032 | ||
2033 | extern void check_disk_size_change(struct gendisk *disk, | 2033 | extern void check_disk_size_change(struct gendisk *disk, |
2034 | struct block_device *bdev); | 2034 | struct block_device *bdev); |
2035 | extern int revalidate_disk(struct gendisk *); | 2035 | extern int revalidate_disk(struct gendisk *); |
2036 | extern int check_disk_change(struct block_device *); | 2036 | extern int check_disk_change(struct block_device *); |
2037 | extern int __invalidate_device(struct block_device *); | 2037 | extern int __invalidate_device(struct block_device *); |
2038 | extern int invalidate_partition(struct gendisk *, int); | 2038 | extern int invalidate_partition(struct gendisk *, int); |
2039 | #endif | 2039 | #endif |
2040 | extern int invalidate_inodes(struct super_block *); | 2040 | extern int invalidate_inodes(struct super_block *); |
2041 | unsigned long __invalidate_mapping_pages(struct address_space *mapping, | 2041 | unsigned long __invalidate_mapping_pages(struct address_space *mapping, |
2042 | pgoff_t start, pgoff_t end, | 2042 | pgoff_t start, pgoff_t end, |
2043 | bool be_atomic); | 2043 | bool be_atomic); |
2044 | unsigned long invalidate_mapping_pages(struct address_space *mapping, | 2044 | unsigned long invalidate_mapping_pages(struct address_space *mapping, |
2045 | pgoff_t start, pgoff_t end); | 2045 | pgoff_t start, pgoff_t end); |
2046 | 2046 | ||
2047 | static inline unsigned long __deprecated | 2047 | static inline unsigned long __deprecated |
2048 | invalidate_inode_pages(struct address_space *mapping) | 2048 | invalidate_inode_pages(struct address_space *mapping) |
2049 | { | 2049 | { |
2050 | return invalidate_mapping_pages(mapping, 0, ~0UL); | 2050 | return invalidate_mapping_pages(mapping, 0, ~0UL); |
2051 | } | 2051 | } |
2052 | 2052 | ||
2053 | static inline void invalidate_remote_inode(struct inode *inode) | 2053 | static inline void invalidate_remote_inode(struct inode *inode) |
2054 | { | 2054 | { |
2055 | if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || | 2055 | if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || |
2056 | S_ISLNK(inode->i_mode)) | 2056 | S_ISLNK(inode->i_mode)) |
2057 | invalidate_mapping_pages(inode->i_mapping, 0, -1); | 2057 | invalidate_mapping_pages(inode->i_mapping, 0, -1); |
2058 | } | 2058 | } |
2059 | extern int invalidate_inode_pages2(struct address_space *mapping); | 2059 | extern int invalidate_inode_pages2(struct address_space *mapping); |
2060 | extern int invalidate_inode_pages2_range(struct address_space *mapping, | 2060 | extern int invalidate_inode_pages2_range(struct address_space *mapping, |
2061 | pgoff_t start, pgoff_t end); | 2061 | pgoff_t start, pgoff_t end); |
2062 | extern void generic_sync_sb_inodes(struct super_block *sb, | 2062 | extern void generic_sync_sb_inodes(struct super_block *sb, |
2063 | struct writeback_control *wbc); | 2063 | struct writeback_control *wbc); |
2064 | extern int write_inode_now(struct inode *, int); | 2064 | extern int write_inode_now(struct inode *, int); |
2065 | extern int filemap_fdatawrite(struct address_space *); | 2065 | extern int filemap_fdatawrite(struct address_space *); |
2066 | extern int filemap_flush(struct address_space *); | 2066 | extern int filemap_flush(struct address_space *); |
2067 | extern int filemap_fdatawait(struct address_space *); | 2067 | extern int filemap_fdatawait(struct address_space *); |
2068 | extern int filemap_write_and_wait(struct address_space *mapping); | 2068 | extern int filemap_write_and_wait(struct address_space *mapping); |
2069 | extern int filemap_write_and_wait_range(struct address_space *mapping, | 2069 | extern int filemap_write_and_wait_range(struct address_space *mapping, |
2070 | loff_t lstart, loff_t lend); | 2070 | loff_t lstart, loff_t lend); |
2071 | extern int wait_on_page_writeback_range(struct address_space *mapping, | 2071 | extern int wait_on_page_writeback_range(struct address_space *mapping, |
2072 | pgoff_t start, pgoff_t end); | 2072 | pgoff_t start, pgoff_t end); |
2073 | extern int __filemap_fdatawrite_range(struct address_space *mapping, | 2073 | extern int __filemap_fdatawrite_range(struct address_space *mapping, |
2074 | loff_t start, loff_t end, int sync_mode); | 2074 | loff_t start, loff_t end, int sync_mode); |
2075 | extern int filemap_fdatawrite_range(struct address_space *mapping, | 2075 | extern int filemap_fdatawrite_range(struct address_space *mapping, |
2076 | loff_t start, loff_t end); | 2076 | loff_t start, loff_t end); |
2077 | 2077 | ||
2078 | extern int vfs_fsync(struct file *file, struct dentry *dentry, int datasync); | 2078 | extern int vfs_fsync(struct file *file, struct dentry *dentry, int datasync); |
2079 | extern void sync_supers(void); | 2079 | extern void sync_supers(void); |
2080 | extern void sync_filesystems(int wait); | 2080 | extern void sync_filesystems(int wait); |
2081 | extern void __fsync_super(struct super_block *sb); | ||
2082 | extern void emergency_sync(void); | 2081 | extern void emergency_sync(void); |
2083 | extern void emergency_remount(void); | 2082 | extern void emergency_remount(void); |
2084 | extern int do_remount_sb(struct super_block *sb, int flags, | 2083 | extern int do_remount_sb(struct super_block *sb, int flags, |
2085 | void *data, int force); | 2084 | void *data, int force); |
2086 | #ifdef CONFIG_BLOCK | 2085 | #ifdef CONFIG_BLOCK |
2087 | extern sector_t bmap(struct inode *, sector_t); | 2086 | extern sector_t bmap(struct inode *, sector_t); |
2088 | #endif | 2087 | #endif |
2089 | extern int notify_change(struct dentry *, struct iattr *); | 2088 | extern int notify_change(struct dentry *, struct iattr *); |
2090 | extern int inode_permission(struct inode *, int); | 2089 | extern int inode_permission(struct inode *, int); |
2091 | extern int generic_permission(struct inode *, int, | 2090 | extern int generic_permission(struct inode *, int, |
2092 | int (*check_acl)(struct inode *, int)); | 2091 | int (*check_acl)(struct inode *, int)); |
2093 | 2092 | ||
2094 | static inline bool execute_ok(struct inode *inode) | 2093 | static inline bool execute_ok(struct inode *inode) |
2095 | { | 2094 | { |
2096 | return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode); | 2095 | return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode); |
2097 | } | 2096 | } |
2098 | 2097 | ||
2099 | extern int get_write_access(struct inode *); | 2098 | extern int get_write_access(struct inode *); |
2100 | extern int deny_write_access(struct file *); | 2099 | extern int deny_write_access(struct file *); |
2101 | static inline void put_write_access(struct inode * inode) | 2100 | static inline void put_write_access(struct inode * inode) |
2102 | { | 2101 | { |
2103 | atomic_dec(&inode->i_writecount); | 2102 | atomic_dec(&inode->i_writecount); |
2104 | } | 2103 | } |
2105 | static inline void allow_write_access(struct file *file) | 2104 | static inline void allow_write_access(struct file *file) |
2106 | { | 2105 | { |
2107 | if (file) | 2106 | if (file) |
2108 | atomic_inc(&file->f_path.dentry->d_inode->i_writecount); | 2107 | atomic_inc(&file->f_path.dentry->d_inode->i_writecount); |
2109 | } | 2108 | } |
2110 | extern int do_pipe_flags(int *, int); | 2109 | extern int do_pipe_flags(int *, int); |
2111 | extern struct file *create_read_pipe(struct file *f, int flags); | 2110 | extern struct file *create_read_pipe(struct file *f, int flags); |
2112 | extern struct file *create_write_pipe(int flags); | 2111 | extern struct file *create_write_pipe(int flags); |
2113 | extern void free_write_pipe(struct file *); | 2112 | extern void free_write_pipe(struct file *); |
2114 | 2113 | ||
2115 | extern struct file *do_filp_open(int dfd, const char *pathname, | 2114 | extern struct file *do_filp_open(int dfd, const char *pathname, |
2116 | int open_flag, int mode, int acc_mode); | 2115 | int open_flag, int mode, int acc_mode); |
2117 | extern int may_open(struct path *, int, int); | 2116 | extern int may_open(struct path *, int, int); |
2118 | 2117 | ||
2119 | extern int kernel_read(struct file *, unsigned long, char *, unsigned long); | 2118 | extern int kernel_read(struct file *, unsigned long, char *, unsigned long); |
2120 | extern struct file * open_exec(const char *); | 2119 | extern struct file * open_exec(const char *); |
2121 | 2120 | ||
2122 | /* fs/dcache.c -- generic fs support functions */ | 2121 | /* fs/dcache.c -- generic fs support functions */ |
2123 | extern int is_subdir(struct dentry *, struct dentry *); | 2122 | extern int is_subdir(struct dentry *, struct dentry *); |
2124 | extern ino_t find_inode_number(struct dentry *, struct qstr *); | 2123 | extern ino_t find_inode_number(struct dentry *, struct qstr *); |
2125 | 2124 | ||
2126 | #include <linux/err.h> | 2125 | #include <linux/err.h> |
2127 | 2126 | ||
2128 | /* needed for stackable file system support */ | 2127 | /* needed for stackable file system support */ |
2129 | extern loff_t default_llseek(struct file *file, loff_t offset, int origin); | 2128 | extern loff_t default_llseek(struct file *file, loff_t offset, int origin); |
2130 | 2129 | ||
2131 | extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin); | 2130 | extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin); |
2132 | 2131 | ||
2133 | extern struct inode * inode_init_always(struct super_block *, struct inode *); | 2132 | extern struct inode * inode_init_always(struct super_block *, struct inode *); |
2134 | extern void inode_init_once(struct inode *); | 2133 | extern void inode_init_once(struct inode *); |
2135 | extern void inode_add_to_lists(struct super_block *, struct inode *); | 2134 | extern void inode_add_to_lists(struct super_block *, struct inode *); |
2136 | extern void iput(struct inode *); | 2135 | extern void iput(struct inode *); |
2137 | extern struct inode * igrab(struct inode *); | 2136 | extern struct inode * igrab(struct inode *); |
2138 | extern ino_t iunique(struct super_block *, ino_t); | 2137 | extern ino_t iunique(struct super_block *, ino_t); |
2139 | extern int inode_needs_sync(struct inode *inode); | 2138 | extern int inode_needs_sync(struct inode *inode); |
2140 | extern void generic_delete_inode(struct inode *inode); | 2139 | extern void generic_delete_inode(struct inode *inode); |
2141 | extern void generic_drop_inode(struct inode *inode); | 2140 | extern void generic_drop_inode(struct inode *inode); |
2142 | 2141 | ||
2143 | extern struct inode *ilookup5_nowait(struct super_block *sb, | 2142 | extern struct inode *ilookup5_nowait(struct super_block *sb, |
2144 | unsigned long hashval, int (*test)(struct inode *, void *), | 2143 | unsigned long hashval, int (*test)(struct inode *, void *), |
2145 | void *data); | 2144 | void *data); |
2146 | extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval, | 2145 | extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval, |
2147 | int (*test)(struct inode *, void *), void *data); | 2146 | int (*test)(struct inode *, void *), void *data); |
2148 | extern struct inode *ilookup(struct super_block *sb, unsigned long ino); | 2147 | extern struct inode *ilookup(struct super_block *sb, unsigned long ino); |
2149 | 2148 | ||
2150 | extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *); | 2149 | extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *); |
2151 | extern struct inode * iget_locked(struct super_block *, unsigned long); | 2150 | extern struct inode * iget_locked(struct super_block *, unsigned long); |
2152 | extern int insert_inode_locked4(struct inode *, unsigned long, int (*test)(struct inode *, void *), void *); | 2151 | extern int insert_inode_locked4(struct inode *, unsigned long, int (*test)(struct inode *, void *), void *); |
2153 | extern int insert_inode_locked(struct inode *); | 2152 | extern int insert_inode_locked(struct inode *); |
2154 | extern void unlock_new_inode(struct inode *); | 2153 | extern void unlock_new_inode(struct inode *); |
2155 | 2154 | ||
2156 | extern void __iget(struct inode * inode); | 2155 | extern void __iget(struct inode * inode); |
2157 | extern void iget_failed(struct inode *); | 2156 | extern void iget_failed(struct inode *); |
2158 | extern void clear_inode(struct inode *); | 2157 | extern void clear_inode(struct inode *); |
2159 | extern void destroy_inode(struct inode *); | 2158 | extern void destroy_inode(struct inode *); |
2160 | extern struct inode *new_inode(struct super_block *); | 2159 | extern struct inode *new_inode(struct super_block *); |
2161 | extern int should_remove_suid(struct dentry *); | 2160 | extern int should_remove_suid(struct dentry *); |
2162 | extern int file_remove_suid(struct file *); | 2161 | extern int file_remove_suid(struct file *); |
2163 | 2162 | ||
2164 | extern void __insert_inode_hash(struct inode *, unsigned long hashval); | 2163 | extern void __insert_inode_hash(struct inode *, unsigned long hashval); |
2165 | extern void remove_inode_hash(struct inode *); | 2164 | extern void remove_inode_hash(struct inode *); |
2166 | static inline void insert_inode_hash(struct inode *inode) { | 2165 | static inline void insert_inode_hash(struct inode *inode) { |
2167 | __insert_inode_hash(inode, inode->i_ino); | 2166 | __insert_inode_hash(inode, inode->i_ino); |
2168 | } | 2167 | } |
2169 | 2168 | ||
2170 | extern struct file * get_empty_filp(void); | 2169 | extern struct file * get_empty_filp(void); |
2171 | extern void file_move(struct file *f, struct list_head *list); | 2170 | extern void file_move(struct file *f, struct list_head *list); |
2172 | extern void file_kill(struct file *f); | 2171 | extern void file_kill(struct file *f); |
2173 | #ifdef CONFIG_BLOCK | 2172 | #ifdef CONFIG_BLOCK |
2174 | struct bio; | 2173 | struct bio; |
2175 | extern void submit_bio(int, struct bio *); | 2174 | extern void submit_bio(int, struct bio *); |
2176 | extern int bdev_read_only(struct block_device *); | 2175 | extern int bdev_read_only(struct block_device *); |
2177 | #endif | 2176 | #endif |
2178 | extern int set_blocksize(struct block_device *, int); | 2177 | extern int set_blocksize(struct block_device *, int); |
2179 | extern int sb_set_blocksize(struct super_block *, int); | 2178 | extern int sb_set_blocksize(struct super_block *, int); |
2180 | extern int sb_min_blocksize(struct super_block *, int); | 2179 | extern int sb_min_blocksize(struct super_block *, int); |
2181 | extern int sb_has_dirty_inodes(struct super_block *); | 2180 | extern int sb_has_dirty_inodes(struct super_block *); |
2182 | 2181 | ||
2183 | extern int generic_file_mmap(struct file *, struct vm_area_struct *); | 2182 | extern int generic_file_mmap(struct file *, struct vm_area_struct *); |
2184 | extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); | 2183 | extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); |
2185 | extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size); | 2184 | extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size); |
2186 | int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk); | 2185 | int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk); |
2187 | extern ssize_t generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t); | 2186 | extern ssize_t generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t); |
2188 | extern ssize_t generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long, loff_t); | 2187 | extern ssize_t generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long, loff_t); |
2189 | extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *, | 2188 | extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *, |
2190 | unsigned long, loff_t); | 2189 | unsigned long, loff_t); |
2191 | extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, | 2190 | extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, |
2192 | unsigned long *, loff_t, loff_t *, size_t, size_t); | 2191 | unsigned long *, loff_t, loff_t *, size_t, size_t); |
2193 | extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *, | 2192 | extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *, |
2194 | unsigned long, loff_t, loff_t *, size_t, ssize_t); | 2193 | unsigned long, loff_t, loff_t *, size_t, ssize_t); |
2195 | extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); | 2194 | extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); |
2196 | extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); | 2195 | extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); |
2197 | extern int generic_segment_checks(const struct iovec *iov, | 2196 | extern int generic_segment_checks(const struct iovec *iov, |
2198 | unsigned long *nr_segs, size_t *count, int access_flags); | 2197 | unsigned long *nr_segs, size_t *count, int access_flags); |
2199 | 2198 | ||
2200 | /* fs/splice.c */ | 2199 | /* fs/splice.c */ |
2201 | extern ssize_t generic_file_splice_read(struct file *, loff_t *, | 2200 | extern ssize_t generic_file_splice_read(struct file *, loff_t *, |
2202 | struct pipe_inode_info *, size_t, unsigned int); | 2201 | struct pipe_inode_info *, size_t, unsigned int); |
2203 | extern ssize_t default_file_splice_read(struct file *, loff_t *, | 2202 | extern ssize_t default_file_splice_read(struct file *, loff_t *, |
2204 | struct pipe_inode_info *, size_t, unsigned int); | 2203 | struct pipe_inode_info *, size_t, unsigned int); |
2205 | extern ssize_t generic_file_splice_write(struct pipe_inode_info *, | 2204 | extern ssize_t generic_file_splice_write(struct pipe_inode_info *, |
2206 | struct file *, loff_t *, size_t, unsigned int); | 2205 | struct file *, loff_t *, size_t, unsigned int); |
2207 | extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, | 2206 | extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, |
2208 | struct file *out, loff_t *, size_t len, unsigned int flags); | 2207 | struct file *out, loff_t *, size_t len, unsigned int flags); |
2209 | extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out, | 2208 | extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out, |
2210 | size_t len, unsigned int flags); | 2209 | size_t len, unsigned int flags); |
2211 | 2210 | ||
2212 | extern void | 2211 | extern void |
2213 | file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping); | 2212 | file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping); |
2214 | extern loff_t no_llseek(struct file *file, loff_t offset, int origin); | 2213 | extern loff_t no_llseek(struct file *file, loff_t offset, int origin); |
2215 | extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin); | 2214 | extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin); |
2216 | extern loff_t generic_file_llseek_unlocked(struct file *file, loff_t offset, | 2215 | extern loff_t generic_file_llseek_unlocked(struct file *file, loff_t offset, |
2217 | int origin); | 2216 | int origin); |
2218 | extern int generic_file_open(struct inode * inode, struct file * filp); | 2217 | extern int generic_file_open(struct inode * inode, struct file * filp); |
2219 | extern int nonseekable_open(struct inode * inode, struct file * filp); | 2218 | extern int nonseekable_open(struct inode * inode, struct file * filp); |
2220 | 2219 | ||
2221 | #ifdef CONFIG_FS_XIP | 2220 | #ifdef CONFIG_FS_XIP |
2222 | extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len, | 2221 | extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len, |
2223 | loff_t *ppos); | 2222 | loff_t *ppos); |
2224 | extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma); | 2223 | extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma); |
2225 | extern ssize_t xip_file_write(struct file *filp, const char __user *buf, | 2224 | extern ssize_t xip_file_write(struct file *filp, const char __user *buf, |
2226 | size_t len, loff_t *ppos); | 2225 | size_t len, loff_t *ppos); |
2227 | extern int xip_truncate_page(struct address_space *mapping, loff_t from); | 2226 | extern int xip_truncate_page(struct address_space *mapping, loff_t from); |
2228 | #else | 2227 | #else |
2229 | static inline int xip_truncate_page(struct address_space *mapping, loff_t from) | 2228 | static inline int xip_truncate_page(struct address_space *mapping, loff_t from) |
2230 | { | 2229 | { |
2231 | return 0; | 2230 | return 0; |
2232 | } | 2231 | } |
2233 | #endif | 2232 | #endif |
2234 | 2233 | ||
2235 | #ifdef CONFIG_BLOCK | 2234 | #ifdef CONFIG_BLOCK |
2236 | ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | 2235 | ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, |
2237 | struct block_device *bdev, const struct iovec *iov, loff_t offset, | 2236 | struct block_device *bdev, const struct iovec *iov, loff_t offset, |
2238 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, | 2237 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, |
2239 | int lock_type); | 2238 | int lock_type); |
2240 | 2239 | ||
2241 | enum { | 2240 | enum { |
2242 | DIO_LOCKING = 1, /* need locking between buffered and direct access */ | 2241 | DIO_LOCKING = 1, /* need locking between buffered and direct access */ |
2243 | DIO_NO_LOCKING, /* bdev; no locking at all between buffered/direct */ | 2242 | DIO_NO_LOCKING, /* bdev; no locking at all between buffered/direct */ |
2244 | DIO_OWN_LOCKING, /* filesystem locks buffered and direct internally */ | 2243 | DIO_OWN_LOCKING, /* filesystem locks buffered and direct internally */ |
2245 | }; | 2244 | }; |
2246 | 2245 | ||
2247 | static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb, | 2246 | static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb, |
2248 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, | 2247 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, |
2249 | loff_t offset, unsigned long nr_segs, get_block_t get_block, | 2248 | loff_t offset, unsigned long nr_segs, get_block_t get_block, |
2250 | dio_iodone_t end_io) | 2249 | dio_iodone_t end_io) |
2251 | { | 2250 | { |
2252 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, | 2251 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, |
2253 | nr_segs, get_block, end_io, DIO_LOCKING); | 2252 | nr_segs, get_block, end_io, DIO_LOCKING); |
2254 | } | 2253 | } |
2255 | 2254 | ||
2256 | static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb, | 2255 | static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb, |
2257 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, | 2256 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, |
2258 | loff_t offset, unsigned long nr_segs, get_block_t get_block, | 2257 | loff_t offset, unsigned long nr_segs, get_block_t get_block, |
2259 | dio_iodone_t end_io) | 2258 | dio_iodone_t end_io) |
2260 | { | 2259 | { |
2261 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, | 2260 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, |
2262 | nr_segs, get_block, end_io, DIO_NO_LOCKING); | 2261 | nr_segs, get_block, end_io, DIO_NO_LOCKING); |
2263 | } | 2262 | } |
2264 | 2263 | ||
2265 | static inline ssize_t blockdev_direct_IO_own_locking(int rw, struct kiocb *iocb, | 2264 | static inline ssize_t blockdev_direct_IO_own_locking(int rw, struct kiocb *iocb, |
2266 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, | 2265 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, |
2267 | loff_t offset, unsigned long nr_segs, get_block_t get_block, | 2266 | loff_t offset, unsigned long nr_segs, get_block_t get_block, |
2268 | dio_iodone_t end_io) | 2267 | dio_iodone_t end_io) |
2269 | { | 2268 | { |
2270 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, | 2269 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, |
2271 | nr_segs, get_block, end_io, DIO_OWN_LOCKING); | 2270 | nr_segs, get_block, end_io, DIO_OWN_LOCKING); |
2272 | } | 2271 | } |
2273 | #endif | 2272 | #endif |
2274 | 2273 | ||
2275 | extern const struct file_operations generic_ro_fops; | 2274 | extern const struct file_operations generic_ro_fops; |
2276 | 2275 | ||
2277 | #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m)) | 2276 | #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m)) |
2278 | 2277 | ||
2279 | extern int vfs_readlink(struct dentry *, char __user *, int, const char *); | 2278 | extern int vfs_readlink(struct dentry *, char __user *, int, const char *); |
2280 | extern int vfs_follow_link(struct nameidata *, const char *); | 2279 | extern int vfs_follow_link(struct nameidata *, const char *); |
2281 | extern int page_readlink(struct dentry *, char __user *, int); | 2280 | extern int page_readlink(struct dentry *, char __user *, int); |
2282 | extern void *page_follow_link_light(struct dentry *, struct nameidata *); | 2281 | extern void *page_follow_link_light(struct dentry *, struct nameidata *); |
2283 | extern void page_put_link(struct dentry *, struct nameidata *, void *); | 2282 | extern void page_put_link(struct dentry *, struct nameidata *, void *); |
2284 | extern int __page_symlink(struct inode *inode, const char *symname, int len, | 2283 | extern int __page_symlink(struct inode *inode, const char *symname, int len, |
2285 | int nofs); | 2284 | int nofs); |
2286 | extern int page_symlink(struct inode *inode, const char *symname, int len); | 2285 | extern int page_symlink(struct inode *inode, const char *symname, int len); |
2287 | extern const struct inode_operations page_symlink_inode_operations; | 2286 | extern const struct inode_operations page_symlink_inode_operations; |
2288 | extern int generic_readlink(struct dentry *, char __user *, int); | 2287 | extern int generic_readlink(struct dentry *, char __user *, int); |
2289 | extern void generic_fillattr(struct inode *, struct kstat *); | 2288 | extern void generic_fillattr(struct inode *, struct kstat *); |
2290 | extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *); | 2289 | extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *); |
2291 | void inode_add_bytes(struct inode *inode, loff_t bytes); | 2290 | void inode_add_bytes(struct inode *inode, loff_t bytes); |
2292 | void inode_sub_bytes(struct inode *inode, loff_t bytes); | 2291 | void inode_sub_bytes(struct inode *inode, loff_t bytes); |
2293 | loff_t inode_get_bytes(struct inode *inode); | 2292 | loff_t inode_get_bytes(struct inode *inode); |
2294 | void inode_set_bytes(struct inode *inode, loff_t bytes); | 2293 | void inode_set_bytes(struct inode *inode, loff_t bytes); |
2295 | 2294 | ||
2296 | extern int vfs_readdir(struct file *, filldir_t, void *); | 2295 | extern int vfs_readdir(struct file *, filldir_t, void *); |
2297 | 2296 | ||
2298 | extern int vfs_stat(char __user *, struct kstat *); | 2297 | extern int vfs_stat(char __user *, struct kstat *); |
2299 | extern int vfs_lstat(char __user *, struct kstat *); | 2298 | extern int vfs_lstat(char __user *, struct kstat *); |
2300 | extern int vfs_fstat(unsigned int, struct kstat *); | 2299 | extern int vfs_fstat(unsigned int, struct kstat *); |
2301 | extern int vfs_fstatat(int , char __user *, struct kstat *, int); | 2300 | extern int vfs_fstatat(int , char __user *, struct kstat *, int); |
2302 | 2301 | ||
2303 | extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, | 2302 | extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, |
2304 | unsigned long arg); | 2303 | unsigned long arg); |
2305 | extern int __generic_block_fiemap(struct inode *inode, | 2304 | extern int __generic_block_fiemap(struct inode *inode, |
2306 | struct fiemap_extent_info *fieinfo, u64 start, | 2305 | struct fiemap_extent_info *fieinfo, u64 start, |
2307 | u64 len, get_block_t *get_block); | 2306 | u64 len, get_block_t *get_block); |
2308 | extern int generic_block_fiemap(struct inode *inode, | 2307 | extern int generic_block_fiemap(struct inode *inode, |
2309 | struct fiemap_extent_info *fieinfo, u64 start, | 2308 | struct fiemap_extent_info *fieinfo, u64 start, |
2310 | u64 len, get_block_t *get_block); | 2309 | u64 len, get_block_t *get_block); |
2311 | 2310 | ||
2312 | extern void get_filesystem(struct file_system_type *fs); | 2311 | extern void get_filesystem(struct file_system_type *fs); |
2313 | extern void put_filesystem(struct file_system_type *fs); | 2312 | extern void put_filesystem(struct file_system_type *fs); |
2314 | extern struct file_system_type *get_fs_type(const char *name); | 2313 | extern struct file_system_type *get_fs_type(const char *name); |
2315 | extern struct super_block *get_super(struct block_device *); | 2314 | extern struct super_block *get_super(struct block_device *); |
2316 | extern struct super_block *user_get_super(dev_t); | 2315 | extern struct super_block *user_get_super(dev_t); |
2317 | extern void drop_super(struct super_block *sb); | 2316 | extern void drop_super(struct super_block *sb); |
2318 | 2317 | ||
2319 | extern int dcache_dir_open(struct inode *, struct file *); | 2318 | extern int dcache_dir_open(struct inode *, struct file *); |
2320 | extern int dcache_dir_close(struct inode *, struct file *); | 2319 | extern int dcache_dir_close(struct inode *, struct file *); |
2321 | extern loff_t dcache_dir_lseek(struct file *, loff_t, int); | 2320 | extern loff_t dcache_dir_lseek(struct file *, loff_t, int); |
2322 | extern int dcache_readdir(struct file *, void *, filldir_t); | 2321 | extern int dcache_readdir(struct file *, void *, filldir_t); |
2323 | extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *); | 2322 | extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *); |
2324 | extern int simple_statfs(struct dentry *, struct kstatfs *); | 2323 | extern int simple_statfs(struct dentry *, struct kstatfs *); |
2325 | extern int simple_link(struct dentry *, struct inode *, struct dentry *); | 2324 | extern int simple_link(struct dentry *, struct inode *, struct dentry *); |
2326 | extern int simple_unlink(struct inode *, struct dentry *); | 2325 | extern int simple_unlink(struct inode *, struct dentry *); |
2327 | extern int simple_rmdir(struct inode *, struct dentry *); | 2326 | extern int simple_rmdir(struct inode *, struct dentry *); |
2328 | extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); | 2327 | extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); |
2329 | extern int simple_sync_file(struct file *, struct dentry *, int); | 2328 | extern int simple_sync_file(struct file *, struct dentry *, int); |
2330 | extern int simple_empty(struct dentry *); | 2329 | extern int simple_empty(struct dentry *); |
2331 | extern int simple_readpage(struct file *file, struct page *page); | 2330 | extern int simple_readpage(struct file *file, struct page *page); |
2332 | extern int simple_prepare_write(struct file *file, struct page *page, | 2331 | extern int simple_prepare_write(struct file *file, struct page *page, |
2333 | unsigned offset, unsigned to); | 2332 | unsigned offset, unsigned to); |
2334 | extern int simple_write_begin(struct file *file, struct address_space *mapping, | 2333 | extern int simple_write_begin(struct file *file, struct address_space *mapping, |
2335 | loff_t pos, unsigned len, unsigned flags, | 2334 | loff_t pos, unsigned len, unsigned flags, |
2336 | struct page **pagep, void **fsdata); | 2335 | struct page **pagep, void **fsdata); |
2337 | extern int simple_write_end(struct file *file, struct address_space *mapping, | 2336 | extern int simple_write_end(struct file *file, struct address_space *mapping, |
2338 | loff_t pos, unsigned len, unsigned copied, | 2337 | loff_t pos, unsigned len, unsigned copied, |
2339 | struct page *page, void *fsdata); | 2338 | struct page *page, void *fsdata); |
2340 | 2339 | ||
2341 | extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *); | 2340 | extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *); |
2342 | extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *); | 2341 | extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *); |
2343 | extern const struct file_operations simple_dir_operations; | 2342 | extern const struct file_operations simple_dir_operations; |
2344 | extern const struct inode_operations simple_dir_inode_operations; | 2343 | extern const struct inode_operations simple_dir_inode_operations; |
2345 | struct tree_descr { char *name; const struct file_operations *ops; int mode; }; | 2344 | struct tree_descr { char *name; const struct file_operations *ops; int mode; }; |
2346 | struct dentry *d_alloc_name(struct dentry *, const char *); | 2345 | struct dentry *d_alloc_name(struct dentry *, const char *); |
2347 | extern int simple_fill_super(struct super_block *, int, struct tree_descr *); | 2346 | extern int simple_fill_super(struct super_block *, int, struct tree_descr *); |
2348 | extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count); | 2347 | extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count); |
2349 | extern void simple_release_fs(struct vfsmount **mount, int *count); | 2348 | extern void simple_release_fs(struct vfsmount **mount, int *count); |
2350 | 2349 | ||
2351 | extern ssize_t simple_read_from_buffer(void __user *to, size_t count, | 2350 | extern ssize_t simple_read_from_buffer(void __user *to, size_t count, |
2352 | loff_t *ppos, const void *from, size_t available); | 2351 | loff_t *ppos, const void *from, size_t available); |
2353 | 2352 | ||
2354 | #ifdef CONFIG_MIGRATION | 2353 | #ifdef CONFIG_MIGRATION |
2355 | extern int buffer_migrate_page(struct address_space *, | 2354 | extern int buffer_migrate_page(struct address_space *, |
2356 | struct page *, struct page *); | 2355 | struct page *, struct page *); |
2357 | #else | 2356 | #else |
2358 | #define buffer_migrate_page NULL | 2357 | #define buffer_migrate_page NULL |
2359 | #endif | 2358 | #endif |
2360 | 2359 | ||
2361 | extern int inode_change_ok(struct inode *, struct iattr *); | 2360 | extern int inode_change_ok(struct inode *, struct iattr *); |
2362 | extern int __must_check inode_setattr(struct inode *, struct iattr *); | 2361 | extern int __must_check inode_setattr(struct inode *, struct iattr *); |
2363 | 2362 | ||
2364 | extern void file_update_time(struct file *file); | 2363 | extern void file_update_time(struct file *file); |
2365 | 2364 | ||
2366 | extern int generic_show_options(struct seq_file *m, struct vfsmount *mnt); | 2365 | extern int generic_show_options(struct seq_file *m, struct vfsmount *mnt); |
2367 | extern void save_mount_options(struct super_block *sb, char *options); | 2366 | extern void save_mount_options(struct super_block *sb, char *options); |
2368 | extern void replace_mount_options(struct super_block *sb, char *options); | 2367 | extern void replace_mount_options(struct super_block *sb, char *options); |
2369 | 2368 | ||
2370 | static inline ino_t parent_ino(struct dentry *dentry) | 2369 | static inline ino_t parent_ino(struct dentry *dentry) |
2371 | { | 2370 | { |
2372 | ino_t res; | 2371 | ino_t res; |
2373 | 2372 | ||
2374 | spin_lock(&dentry->d_lock); | 2373 | spin_lock(&dentry->d_lock); |
2375 | res = dentry->d_parent->d_inode->i_ino; | 2374 | res = dentry->d_parent->d_inode->i_ino; |
2376 | spin_unlock(&dentry->d_lock); | 2375 | spin_unlock(&dentry->d_lock); |
2377 | return res; | 2376 | return res; |
2378 | } | 2377 | } |
2379 | 2378 | ||
2380 | /* Transaction based IO helpers */ | 2379 | /* Transaction based IO helpers */ |
2381 | 2380 | ||
2382 | /* | 2381 | /* |
2383 | * An argresp is stored in an allocated page and holds the | 2382 | * An argresp is stored in an allocated page and holds the |
2384 | * size of the argument or response, along with its content | 2383 | * size of the argument or response, along with its content |
2385 | */ | 2384 | */ |
2386 | struct simple_transaction_argresp { | 2385 | struct simple_transaction_argresp { |
2387 | ssize_t size; | 2386 | ssize_t size; |
2388 | char data[0]; | 2387 | char data[0]; |
2389 | }; | 2388 | }; |
2390 | 2389 | ||
2391 | #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp)) | 2390 | #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp)) |
2392 | 2391 | ||
2393 | char *simple_transaction_get(struct file *file, const char __user *buf, | 2392 | char *simple_transaction_get(struct file *file, const char __user *buf, |
2394 | size_t size); | 2393 | size_t size); |
2395 | ssize_t simple_transaction_read(struct file *file, char __user *buf, | 2394 | ssize_t simple_transaction_read(struct file *file, char __user *buf, |
2396 | size_t size, loff_t *pos); | 2395 | size_t size, loff_t *pos); |
2397 | int simple_transaction_release(struct inode *inode, struct file *file); | 2396 | int simple_transaction_release(struct inode *inode, struct file *file); |
2398 | 2397 | ||
2399 | void simple_transaction_set(struct file *file, size_t n); | 2398 | void simple_transaction_set(struct file *file, size_t n); |
2400 | 2399 | ||
2401 | /* | 2400 | /* |
2402 | * simple attribute files | 2401 | * simple attribute files |
2403 | * | 2402 | * |
2404 | * These attributes behave similar to those in sysfs: | 2403 | * These attributes behave similar to those in sysfs: |
2405 | * | 2404 | * |
2406 | * Writing to an attribute immediately sets a value, an open file can be | 2405 | * Writing to an attribute immediately sets a value, an open file can be |
2407 | * written to multiple times. | 2406 | * written to multiple times. |
2408 | * | 2407 | * |
2409 | * Reading from an attribute creates a buffer from the value that might get | 2408 | * Reading from an attribute creates a buffer from the value that might get |
2410 | * read with multiple read calls. When the attribute has been read | 2409 | * read with multiple read calls. When the attribute has been read |
2411 | * completely, no further read calls are possible until the file is opened | 2410 | * completely, no further read calls are possible until the file is opened |
2412 | * again. | 2411 | * again. |
2413 | * | 2412 | * |
2414 | * All attributes contain a text representation of a numeric value | 2413 | * All attributes contain a text representation of a numeric value |
2415 | * that are accessed with the get() and set() functions. | 2414 | * that are accessed with the get() and set() functions. |
2416 | */ | 2415 | */ |
2417 | #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ | 2416 | #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ |
2418 | static int __fops ## _open(struct inode *inode, struct file *file) \ | 2417 | static int __fops ## _open(struct inode *inode, struct file *file) \ |
2419 | { \ | 2418 | { \ |
2420 | __simple_attr_check_format(__fmt, 0ull); \ | 2419 | __simple_attr_check_format(__fmt, 0ull); \ |
2421 | return simple_attr_open(inode, file, __get, __set, __fmt); \ | 2420 | return simple_attr_open(inode, file, __get, __set, __fmt); \ |
2422 | } \ | 2421 | } \ |
2423 | static struct file_operations __fops = { \ | 2422 | static struct file_operations __fops = { \ |
2424 | .owner = THIS_MODULE, \ | 2423 | .owner = THIS_MODULE, \ |
2425 | .open = __fops ## _open, \ | 2424 | .open = __fops ## _open, \ |
2426 | .release = simple_attr_release, \ | 2425 | .release = simple_attr_release, \ |
2427 | .read = simple_attr_read, \ | 2426 | .read = simple_attr_read, \ |
2428 | .write = simple_attr_write, \ | 2427 | .write = simple_attr_write, \ |
2429 | }; | 2428 | }; |
2430 | 2429 | ||
2431 | static inline void __attribute__((format(printf, 1, 2))) | 2430 | static inline void __attribute__((format(printf, 1, 2))) |
2432 | __simple_attr_check_format(const char *fmt, ...) | 2431 | __simple_attr_check_format(const char *fmt, ...) |
2433 | { | 2432 | { |
2434 | /* don't do anything, just let the compiler check the arguments; */ | 2433 | /* don't do anything, just let the compiler check the arguments; */ |
2435 | } | 2434 | } |
2436 | 2435 | ||
2437 | int simple_attr_open(struct inode *inode, struct file *file, | 2436 | int simple_attr_open(struct inode *inode, struct file *file, |
2438 | int (*get)(void *, u64 *), int (*set)(void *, u64), | 2437 | int (*get)(void *, u64 *), int (*set)(void *, u64), |
2439 | const char *fmt); | 2438 | const char *fmt); |
2440 | int simple_attr_release(struct inode *inode, struct file *file); | 2439 | int simple_attr_release(struct inode *inode, struct file *file); |
2441 | ssize_t simple_attr_read(struct file *file, char __user *buf, | 2440 | ssize_t simple_attr_read(struct file *file, char __user *buf, |
2442 | size_t len, loff_t *ppos); | 2441 | size_t len, loff_t *ppos); |
2443 | ssize_t simple_attr_write(struct file *file, const char __user *buf, | 2442 | ssize_t simple_attr_write(struct file *file, const char __user *buf, |
2444 | size_t len, loff_t *ppos); | 2443 | size_t len, loff_t *ppos); |
2445 | 2444 | ||
2446 | struct ctl_table; | 2445 | struct ctl_table; |
2447 | int proc_nr_files(struct ctl_table *table, int write, struct file *filp, | 2446 | int proc_nr_files(struct ctl_table *table, int write, struct file *filp, |
2448 | void __user *buffer, size_t *lenp, loff_t *ppos); | 2447 | void __user *buffer, size_t *lenp, loff_t *ppos); |
2449 | 2448 | ||
2450 | int __init get_filesystem_list(char *buf); | 2449 | int __init get_filesystem_list(char *buf); |
2451 | 2450 | ||
2452 | #endif /* __KERNEL__ */ | 2451 | #endif /* __KERNEL__ */ |
2453 | #endif /* _LINUX_FS_H */ | 2452 | #endif /* _LINUX_FS_H */ |
2454 | 2453 |