Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (C) International Business Machines Corp., 2000-2004 | |
3 | * Portions Copyright (C) Christoph Hellwig, 2001-2002 | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
63f83c9f | 7 | * the Free Software Foundation; either version 2 of the License, or |
1da177e4 | 8 | * (at your option) any later version. |
63f83c9f | 9 | * |
1da177e4 LT |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | |
13 | * the GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
63f83c9f | 16 | * along with this program; if not, write to the Free Software |
1da177e4 LT |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ | |
19 | ||
20 | #include <linux/fs.h> | |
1da177e4 LT |
21 | #include <linux/module.h> |
22 | #include <linux/parser.h> | |
23 | #include <linux/completion.h> | |
24 | #include <linux/vfs.h> | |
74abb989 | 25 | #include <linux/quotaops.h> |
8fc2751b | 26 | #include <linux/mount.h> |
1da177e4 | 27 | #include <linux/moduleparam.h> |
91dbb4de | 28 | #include <linux/kthread.h> |
9a59f452 | 29 | #include <linux/posix_acl.h> |
115ff50b | 30 | #include <linux/buffer_head.h> |
a5694255 | 31 | #include <linux/exportfs.h> |
b5c816a4 | 32 | #include <linux/crc32.h> |
5a0e3ad6 | 33 | #include <linux/slab.h> |
1da177e4 | 34 | #include <asm/uaccess.h> |
8fc2751b | 35 | #include <linux/seq_file.h> |
b40c2e66 | 36 | #include <linux/blkdev.h> |
1da177e4 LT |
37 | |
38 | #include "jfs_incore.h" | |
39 | #include "jfs_filsys.h" | |
1868f4aa | 40 | #include "jfs_inode.h" |
1da177e4 LT |
41 | #include "jfs_metapage.h" |
42 | #include "jfs_superblock.h" | |
43 | #include "jfs_dmap.h" | |
44 | #include "jfs_imap.h" | |
45 | #include "jfs_acl.h" | |
46 | #include "jfs_debug.h" | |
47 | ||
48 | MODULE_DESCRIPTION("The Journaled Filesystem (JFS)"); | |
49 | MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM"); | |
50 | MODULE_LICENSE("GPL"); | |
51 | ||
e18b890b | 52 | static struct kmem_cache * jfs_inode_cachep; |
1da177e4 | 53 | |
ee9b6d61 | 54 | static const struct super_operations jfs_super_operations; |
39655164 | 55 | static const struct export_operations jfs_export_operations; |
1da177e4 LT |
56 | static struct file_system_type jfs_fs_type; |
57 | ||
58 | #define MAX_COMMIT_THREADS 64 | |
59 | static int commit_threads = 0; | |
60 | module_param(commit_threads, int, 0); | |
61 | MODULE_PARM_DESC(commit_threads, "Number of commit threads"); | |
62 | ||
91dbb4de CH |
63 | static struct task_struct *jfsCommitThread[MAX_COMMIT_THREADS]; |
64 | struct task_struct *jfsIOthread; | |
65 | struct task_struct *jfsSyncThread; | |
1da177e4 LT |
66 | |
67 | #ifdef CONFIG_JFS_DEBUG | |
68 | int jfsloglevel = JFS_LOGLEVEL_WARN; | |
69 | module_param(jfsloglevel, int, 0644); | |
70 | MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)"); | |
71 | #endif | |
72 | ||
1da177e4 LT |
73 | static void jfs_handle_error(struct super_block *sb) |
74 | { | |
75 | struct jfs_sb_info *sbi = JFS_SBI(sb); | |
76 | ||
77 | if (sb->s_flags & MS_RDONLY) | |
78 | return; | |
79 | ||
80 | updateSuper(sb, FM_DIRTY); | |
81 | ||
82 | if (sbi->flag & JFS_ERR_PANIC) | |
83 | panic("JFS (device %s): panic forced after error\n", | |
84 | sb->s_id); | |
85 | else if (sbi->flag & JFS_ERR_REMOUNT_RO) { | |
86 | jfs_err("ERROR: (device %s): remounting filesystem " | |
87 | "as read-only\n", | |
88 | sb->s_id); | |
89 | sb->s_flags |= MS_RDONLY; | |
63f83c9f | 90 | } |
1da177e4 LT |
91 | |
92 | /* nothing is done for continue beyond marking the superblock dirty */ | |
93 | } | |
94 | ||
95 | void jfs_error(struct super_block *sb, const char * function, ...) | |
96 | { | |
97 | static char error_buf[256]; | |
98 | va_list args; | |
99 | ||
100 | va_start(args, function); | |
4a6e617a | 101 | vsnprintf(error_buf, sizeof(error_buf), function, args); |
1da177e4 LT |
102 | va_end(args); |
103 | ||
b40c2e66 | 104 | pr_err("ERROR: (device %s): %s\n", sb->s_id, error_buf); |
1da177e4 LT |
105 | |
106 | jfs_handle_error(sb); | |
107 | } | |
108 | ||
109 | static struct inode *jfs_alloc_inode(struct super_block *sb) | |
110 | { | |
111 | struct jfs_inode_info *jfs_inode; | |
112 | ||
113 | jfs_inode = kmem_cache_alloc(jfs_inode_cachep, GFP_NOFS); | |
114 | if (!jfs_inode) | |
115 | return NULL; | |
116 | return &jfs_inode->vfs_inode; | |
117 | } | |
118 | ||
fa0d7e3d NP |
119 | static void jfs_i_callback(struct rcu_head *head) |
120 | { | |
121 | struct inode *inode = container_of(head, struct inode, i_rcu); | |
122 | struct jfs_inode_info *ji = JFS_IP(inode); | |
fa0d7e3d NP |
123 | kmem_cache_free(jfs_inode_cachep, ji); |
124 | } | |
125 | ||
1da177e4 LT |
126 | static void jfs_destroy_inode(struct inode *inode) |
127 | { | |
128 | struct jfs_inode_info *ji = JFS_IP(inode); | |
129 | ||
8a9cd6d6 DK |
130 | BUG_ON(!list_empty(&ji->anon_inode_list)); |
131 | ||
1da177e4 LT |
132 | spin_lock_irq(&ji->ag_lock); |
133 | if (ji->active_ag != -1) { | |
134 | struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap; | |
135 | atomic_dec(&bmap->db_active[ji->active_ag]); | |
136 | ji->active_ag = -1; | |
137 | } | |
138 | spin_unlock_irq(&ji->ag_lock); | |
fa0d7e3d | 139 | call_rcu(&inode->i_rcu, jfs_i_callback); |
1da177e4 LT |
140 | } |
141 | ||
726c3342 | 142 | static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
1da177e4 | 143 | { |
726c3342 | 144 | struct jfs_sb_info *sbi = JFS_SBI(dentry->d_sb); |
1da177e4 LT |
145 | s64 maxinodes; |
146 | struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap; | |
147 | ||
148 | jfs_info("In jfs_statfs"); | |
149 | buf->f_type = JFS_SUPER_MAGIC; | |
150 | buf->f_bsize = sbi->bsize; | |
151 | buf->f_blocks = sbi->bmap->db_mapsize; | |
152 | buf->f_bfree = sbi->bmap->db_nfree; | |
153 | buf->f_bavail = sbi->bmap->db_nfree; | |
154 | /* | |
155 | * If we really return the number of allocated & free inodes, some | |
156 | * applications will fail because they won't see enough free inodes. | |
157 | * We'll try to calculate some guess as to how may inodes we can | |
158 | * really allocate | |
159 | * | |
160 | * buf->f_files = atomic_read(&imap->im_numinos); | |
161 | * buf->f_ffree = atomic_read(&imap->im_numfree); | |
162 | */ | |
163 | maxinodes = min((s64) atomic_read(&imap->im_numinos) + | |
164 | ((sbi->bmap->db_nfree >> imap->im_l2nbperiext) | |
165 | << L2INOSPEREXT), (s64) 0xffffffffLL); | |
166 | buf->f_files = maxinodes; | |
167 | buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) - | |
168 | atomic_read(&imap->im_numfree)); | |
b5c816a4 CL |
169 | buf->f_fsid.val[0] = (u32)crc32_le(0, sbi->uuid, sizeof(sbi->uuid)/2); |
170 | buf->f_fsid.val[1] = (u32)crc32_le(0, sbi->uuid + sizeof(sbi->uuid)/2, | |
171 | sizeof(sbi->uuid)/2); | |
1da177e4 LT |
172 | |
173 | buf->f_namelen = JFS_NAME_MAX; | |
174 | return 0; | |
175 | } | |
176 | ||
177 | static void jfs_put_super(struct super_block *sb) | |
178 | { | |
179 | struct jfs_sb_info *sbi = JFS_SBI(sb); | |
180 | int rc; | |
181 | ||
182 | jfs_info("In jfs_put_super"); | |
6cfd0148 | 183 | |
e0ccfd95 CH |
184 | dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); |
185 | ||
1da177e4 LT |
186 | rc = jfs_umount(sb); |
187 | if (rc) | |
188 | jfs_err("jfs_umount failed with return code %d", rc); | |
6d729e44 TG |
189 | |
190 | unload_nls(sbi->nls_tab); | |
1da177e4 | 191 | |
7fab479b DK |
192 | truncate_inode_pages(sbi->direct_inode->i_mapping, 0); |
193 | iput(sbi->direct_inode); | |
7fab479b | 194 | |
1da177e4 LT |
195 | kfree(sbi); |
196 | } | |
197 | ||
198 | enum { | |
199 | Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize, | |
8fc2751b | 200 | Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota, |
b40c2e66 TR |
201 | Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask, |
202 | Opt_discard, Opt_nodiscard, Opt_discard_minblk | |
1da177e4 LT |
203 | }; |
204 | ||
a447c093 | 205 | static const match_table_t tokens = { |
1da177e4 LT |
206 | {Opt_integrity, "integrity"}, |
207 | {Opt_nointegrity, "nointegrity"}, | |
208 | {Opt_iocharset, "iocharset=%s"}, | |
209 | {Opt_resize, "resize=%u"}, | |
210 | {Opt_resize_nosize, "resize"}, | |
211 | {Opt_errors, "errors=%s"}, | |
212 | {Opt_ignore, "noquota"}, | |
213 | {Opt_ignore, "quota"}, | |
8fc2751b MB |
214 | {Opt_usrquota, "usrquota"}, |
215 | {Opt_grpquota, "grpquota"}, | |
69eb66d7 DK |
216 | {Opt_uid, "uid=%u"}, |
217 | {Opt_gid, "gid=%u"}, | |
218 | {Opt_umask, "umask=%u"}, | |
b40c2e66 TR |
219 | {Opt_discard, "discard"}, |
220 | {Opt_nodiscard, "nodiscard"}, | |
221 | {Opt_discard_minblk, "discard=%u"}, | |
1da177e4 LT |
222 | {Opt_err, NULL} |
223 | }; | |
224 | ||
225 | static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, | |
226 | int *flag) | |
227 | { | |
228 | void *nls_map = (void *)-1; /* -1: no change; NULL: none */ | |
229 | char *p; | |
230 | struct jfs_sb_info *sbi = JFS_SBI(sb); | |
231 | ||
232 | *newLVSize = 0; | |
233 | ||
234 | if (!options) | |
235 | return 1; | |
236 | ||
237 | while ((p = strsep(&options, ",")) != NULL) { | |
238 | substring_t args[MAX_OPT_ARGS]; | |
239 | int token; | |
240 | if (!*p) | |
241 | continue; | |
242 | ||
243 | token = match_token(p, tokens, args); | |
244 | switch (token) { | |
245 | case Opt_integrity: | |
246 | *flag &= ~JFS_NOINTEGRITY; | |
247 | break; | |
248 | case Opt_nointegrity: | |
249 | *flag |= JFS_NOINTEGRITY; | |
250 | break; | |
251 | case Opt_ignore: | |
252 | /* Silently ignore the quota options */ | |
253 | /* Don't do anything ;-) */ | |
254 | break; | |
255 | case Opt_iocharset: | |
256 | if (nls_map && nls_map != (void *) -1) | |
257 | unload_nls(nls_map); | |
258 | if (!strcmp(args[0].from, "none")) | |
259 | nls_map = NULL; | |
260 | else { | |
261 | nls_map = load_nls(args[0].from); | |
262 | if (!nls_map) { | |
b40c2e66 | 263 | pr_err("JFS: charset not found\n"); |
1da177e4 LT |
264 | goto cleanup; |
265 | } | |
266 | } | |
267 | break; | |
268 | case Opt_resize: | |
269 | { | |
270 | char *resize = args[0].from; | |
271 | *newLVSize = simple_strtoull(resize, &resize, 0); | |
272 | break; | |
273 | } | |
274 | case Opt_resize_nosize: | |
275 | { | |
276 | *newLVSize = sb->s_bdev->bd_inode->i_size >> | |
277 | sb->s_blocksize_bits; | |
278 | if (*newLVSize == 0) | |
b40c2e66 | 279 | pr_err("JFS: Cannot determine volume size\n"); |
1da177e4 LT |
280 | break; |
281 | } | |
282 | case Opt_errors: | |
283 | { | |
284 | char *errors = args[0].from; | |
285 | if (!errors || !*errors) | |
286 | goto cleanup; | |
287 | if (!strcmp(errors, "continue")) { | |
288 | *flag &= ~JFS_ERR_REMOUNT_RO; | |
289 | *flag &= ~JFS_ERR_PANIC; | |
290 | *flag |= JFS_ERR_CONTINUE; | |
291 | } else if (!strcmp(errors, "remount-ro")) { | |
292 | *flag &= ~JFS_ERR_CONTINUE; | |
293 | *flag &= ~JFS_ERR_PANIC; | |
294 | *flag |= JFS_ERR_REMOUNT_RO; | |
295 | } else if (!strcmp(errors, "panic")) { | |
296 | *flag &= ~JFS_ERR_CONTINUE; | |
297 | *flag &= ~JFS_ERR_REMOUNT_RO; | |
298 | *flag |= JFS_ERR_PANIC; | |
299 | } else { | |
b40c2e66 | 300 | pr_err("JFS: %s is an invalid error handler\n", |
1da177e4 LT |
301 | errors); |
302 | goto cleanup; | |
303 | } | |
304 | break; | |
305 | } | |
8fc2751b | 306 | |
115ff50b | 307 | #ifdef CONFIG_QUOTA |
8fc2751b MB |
308 | case Opt_quota: |
309 | case Opt_usrquota: | |
310 | *flag |= JFS_USRQUOTA; | |
311 | break; | |
312 | case Opt_grpquota: | |
313 | *flag |= JFS_GRPQUOTA; | |
314 | break; | |
315 | #else | |
316 | case Opt_usrquota: | |
317 | case Opt_grpquota: | |
318 | case Opt_quota: | |
b40c2e66 | 319 | pr_err("JFS: quota operations not supported\n"); |
8fc2751b MB |
320 | break; |
321 | #endif | |
69eb66d7 DK |
322 | case Opt_uid: |
323 | { | |
324 | char *uid = args[0].from; | |
c18cdc1a EB |
325 | uid_t val = simple_strtoul(uid, &uid, 0); |
326 | sbi->uid = make_kuid(current_user_ns(), val); | |
327 | if (!uid_valid(sbi->uid)) | |
328 | goto cleanup; | |
69eb66d7 DK |
329 | break; |
330 | } | |
b40c2e66 | 331 | |
69eb66d7 DK |
332 | case Opt_gid: |
333 | { | |
334 | char *gid = args[0].from; | |
c18cdc1a EB |
335 | gid_t val = simple_strtoul(gid, &gid, 0); |
336 | sbi->gid = make_kgid(current_user_ns(), val); | |
337 | if (!gid_valid(sbi->gid)) | |
338 | goto cleanup; | |
69eb66d7 DK |
339 | break; |
340 | } | |
b40c2e66 | 341 | |
69eb66d7 DK |
342 | case Opt_umask: |
343 | { | |
344 | char *umask = args[0].from; | |
345 | sbi->umask = simple_strtoul(umask, &umask, 8); | |
346 | if (sbi->umask & ~0777) { | |
b40c2e66 | 347 | pr_err("JFS: Invalid value of umask\n"); |
69eb66d7 DK |
348 | goto cleanup; |
349 | } | |
350 | break; | |
351 | } | |
b40c2e66 TR |
352 | |
353 | case Opt_discard: | |
354 | { | |
355 | struct request_queue *q = bdev_get_queue(sb->s_bdev); | |
356 | /* if set to 1, even copying files will cause | |
357 | * trimming :O | |
358 | * -> user has more control over the online trimming | |
359 | */ | |
360 | sbi->minblks_trim = 64; | |
361 | if (blk_queue_discard(q)) { | |
362 | *flag |= JFS_DISCARD; | |
363 | } else { | |
364 | pr_err("JFS: discard option " \ | |
365 | "not supported on device\n"); | |
366 | } | |
367 | break; | |
368 | } | |
369 | ||
370 | case Opt_nodiscard: | |
371 | *flag &= ~JFS_DISCARD; | |
372 | break; | |
373 | ||
374 | case Opt_discard_minblk: | |
375 | { | |
376 | struct request_queue *q = bdev_get_queue(sb->s_bdev); | |
377 | char *minblks_trim = args[0].from; | |
378 | if (blk_queue_discard(q)) { | |
379 | *flag |= JFS_DISCARD; | |
380 | sbi->minblks_trim = simple_strtoull( | |
381 | minblks_trim, &minblks_trim, 0); | |
382 | } else { | |
383 | pr_err("JFS: discard option " \ | |
384 | "not supported on device\n"); | |
385 | } | |
386 | break; | |
387 | } | |
388 | ||
1da177e4 LT |
389 | default: |
390 | printk("jfs: Unrecognized mount option \"%s\" " | |
391 | " or missing value\n", p); | |
392 | goto cleanup; | |
393 | } | |
394 | } | |
395 | ||
396 | if (nls_map != (void *) -1) { | |
397 | /* Discard old (if remount) */ | |
6d729e44 | 398 | unload_nls(sbi->nls_tab); |
1da177e4 LT |
399 | sbi->nls_tab = nls_map; |
400 | } | |
401 | return 1; | |
402 | ||
403 | cleanup: | |
404 | if (nls_map && nls_map != (void *) -1) | |
405 | unload_nls(nls_map); | |
406 | return 0; | |
407 | } | |
408 | ||
409 | static int jfs_remount(struct super_block *sb, int *flags, char *data) | |
410 | { | |
411 | s64 newLVSize = 0; | |
412 | int rc = 0; | |
413 | int flag = JFS_SBI(sb)->flag; | |
337eb00a | 414 | int ret; |
1da177e4 LT |
415 | |
416 | if (!parse_options(data, sb, &newLVSize, &flag)) { | |
417 | return -EINVAL; | |
418 | } | |
22b26db6 | 419 | |
1da177e4 LT |
420 | if (newLVSize) { |
421 | if (sb->s_flags & MS_RDONLY) { | |
b40c2e66 TR |
422 | pr_err("JFS: resize requires volume" \ |
423 | " to be mounted read-write\n"); | |
1da177e4 LT |
424 | return -EROFS; |
425 | } | |
426 | rc = jfs_extendfs(sb, newLVSize, 0); | |
22b26db6 | 427 | if (rc) |
1da177e4 LT |
428 | return rc; |
429 | } | |
430 | ||
431 | if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { | |
7fab479b DK |
432 | /* |
433 | * Invalidate any previously read metadata. fsck may have | |
434 | * changed the on-disk data since we mounted r/o | |
435 | */ | |
436 | truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0); | |
437 | ||
1da177e4 | 438 | JFS_SBI(sb)->flag = flag; |
337eb00a | 439 | ret = jfs_mount_rw(sb, 1); |
c79d967d CH |
440 | |
441 | /* mark the fs r/w for quota activity */ | |
442 | sb->s_flags &= ~MS_RDONLY; | |
443 | ||
0f0dd62f | 444 | dquot_resume(sb, -1); |
337eb00a | 445 | return ret; |
1da177e4 LT |
446 | } |
447 | if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) { | |
0f0dd62f CH |
448 | rc = dquot_suspend(sb, -1); |
449 | if (rc < 0) { | |
0f0dd62f | 450 | return rc; |
c79d967d | 451 | } |
1da177e4 LT |
452 | rc = jfs_umount_rw(sb); |
453 | JFS_SBI(sb)->flag = flag; | |
454 | return rc; | |
455 | } | |
456 | if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY)) | |
457 | if (!(sb->s_flags & MS_RDONLY)) { | |
458 | rc = jfs_umount_rw(sb); | |
22b26db6 | 459 | if (rc) |
1da177e4 | 460 | return rc; |
22b26db6 | 461 | |
1da177e4 | 462 | JFS_SBI(sb)->flag = flag; |
337eb00a | 463 | ret = jfs_mount_rw(sb, 1); |
337eb00a | 464 | return ret; |
1da177e4 LT |
465 | } |
466 | JFS_SBI(sb)->flag = flag; | |
467 | ||
468 | return 0; | |
469 | } | |
470 | ||
471 | static int jfs_fill_super(struct super_block *sb, void *data, int silent) | |
472 | { | |
473 | struct jfs_sb_info *sbi; | |
474 | struct inode *inode; | |
475 | int rc; | |
476 | s64 newLVSize = 0; | |
eab1df71 | 477 | int flag, ret = -EINVAL; |
1da177e4 LT |
478 | |
479 | jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags); | |
480 | ||
22b26db6 | 481 | if (!new_valid_dev(sb->s_bdev->bd_dev)) |
1da177e4 LT |
482 | return -EOVERFLOW; |
483 | ||
5b3030e3 | 484 | sbi = kzalloc(sizeof (struct jfs_sb_info), GFP_KERNEL); |
22b26db6 | 485 | if (!sbi) |
087387f9 | 486 | return -ENOMEM; |
22b26db6 | 487 | |
1da177e4 | 488 | sb->s_fs_info = sbi; |
8de52778 | 489 | sb->s_max_links = JFS_LINK_MAX; |
1da177e4 | 490 | sbi->sb = sb; |
c18cdc1a EB |
491 | sbi->uid = INVALID_UID; |
492 | sbi->gid = INVALID_GID; | |
493 | sbi->umask = -1; | |
1da177e4 LT |
494 | |
495 | /* initialize the mount flag and determine the default error handler */ | |
496 | flag = JFS_ERR_REMOUNT_RO; | |
497 | ||
684bdc7f JB |
498 | if (!parse_options((char *) data, sb, &newLVSize, &flag)) |
499 | goto out_kfree; | |
1da177e4 LT |
500 | sbi->flag = flag; |
501 | ||
502 | #ifdef CONFIG_JFS_POSIX_ACL | |
503 | sb->s_flags |= MS_POSIXACL; | |
504 | #endif | |
505 | ||
506 | if (newLVSize) { | |
b40c2e66 | 507 | pr_err("resize option for remount only\n"); |
684bdc7f | 508 | goto out_kfree; |
1da177e4 LT |
509 | } |
510 | ||
511 | /* | |
512 | * Initialize blocksize to 4K. | |
513 | */ | |
514 | sb_set_blocksize(sb, PSIZE); | |
515 | ||
516 | /* | |
517 | * Set method vectors. | |
518 | */ | |
519 | sb->s_op = &jfs_super_operations; | |
520 | sb->s_export_op = &jfs_export_operations; | |
123e9caf CH |
521 | #ifdef CONFIG_QUOTA |
522 | sb->dq_op = &dquot_operations; | |
287a8095 | 523 | sb->s_qcop = &dquot_quotactl_ops; |
123e9caf | 524 | #endif |
1da177e4 | 525 | |
7fab479b DK |
526 | /* |
527 | * Initialize direct-mapping inode/address-space | |
528 | */ | |
529 | inode = new_inode(sb); | |
eab1df71 DH |
530 | if (inode == NULL) { |
531 | ret = -ENOMEM; | |
684bdc7f | 532 | goto out_unload; |
eab1df71 | 533 | } |
7fab479b | 534 | inode->i_ino = 0; |
7fab479b DK |
535 | inode->i_size = sb->s_bdev->bd_inode->i_size; |
536 | inode->i_mapping->a_ops = &jfs_metapage_aops; | |
ac17b8b5 | 537 | insert_inode_hash(inode); |
7fab479b DK |
538 | mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); |
539 | ||
540 | sbi->direct_inode = inode; | |
541 | ||
1da177e4 LT |
542 | rc = jfs_mount(sb); |
543 | if (rc) { | |
544 | if (!silent) { | |
545 | jfs_err("jfs_mount failed w/return code = %d", rc); | |
546 | } | |
7fab479b | 547 | goto out_mount_failed; |
1da177e4 LT |
548 | } |
549 | if (sb->s_flags & MS_RDONLY) | |
550 | sbi->log = NULL; | |
551 | else { | |
552 | rc = jfs_mount_rw(sb, 0); | |
553 | if (rc) { | |
554 | if (!silent) { | |
555 | jfs_err("jfs_mount_rw failed, return code = %d", | |
556 | rc); | |
557 | } | |
558 | goto out_no_rw; | |
559 | } | |
560 | } | |
561 | ||
562 | sb->s_magic = JFS_SUPER_MAGIC; | |
563 | ||
94b77bd8 AV |
564 | if (sbi->mntflag & JFS_OS2) |
565 | sb->s_d_op = &jfs_ci_dentry_operations; | |
566 | ||
eab1df71 DH |
567 | inode = jfs_iget(sb, ROOT_I); |
568 | if (IS_ERR(inode)) { | |
569 | ret = PTR_ERR(inode); | |
6536d289 | 570 | goto out_no_rw; |
eab1df71 | 571 | } |
48fde701 | 572 | sb->s_root = d_make_root(inode); |
1da177e4 LT |
573 | if (!sb->s_root) |
574 | goto out_no_root; | |
575 | ||
1da177e4 LT |
576 | /* logical blocks are represented by 40 bits in pxd_t, etc. */ |
577 | sb->s_maxbytes = ((u64) sb->s_blocksize) << 40; | |
578 | #if BITS_PER_LONG == 32 | |
579 | /* | |
580 | * Page cache is indexed by long. | |
581 | * I would use MAX_LFS_FILESIZE, but it's only half as big | |
582 | */ | |
28ba0ec6 | 583 | sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, (u64)sb->s_maxbytes); |
1da177e4 LT |
584 | #endif |
585 | sb->s_time_gran = 1; | |
586 | return 0; | |
587 | ||
588 | out_no_root: | |
6536d289 | 589 | jfs_err("jfs_read_super: get root dentry failed"); |
1da177e4 LT |
590 | |
591 | out_no_rw: | |
592 | rc = jfs_umount(sb); | |
593 | if (rc) { | |
594 | jfs_err("jfs_umount failed with return code %d", rc); | |
595 | } | |
7fab479b | 596 | out_mount_failed: |
28fd1298 | 597 | filemap_write_and_wait(sbi->direct_inode->i_mapping); |
7fab479b DK |
598 | truncate_inode_pages(sbi->direct_inode->i_mapping, 0); |
599 | make_bad_inode(sbi->direct_inode); | |
600 | iput(sbi->direct_inode); | |
601 | sbi->direct_inode = NULL; | |
684bdc7f | 602 | out_unload: |
1da177e4 LT |
603 | if (sbi->nls_tab) |
604 | unload_nls(sbi->nls_tab); | |
684bdc7f | 605 | out_kfree: |
1da177e4 | 606 | kfree(sbi); |
eab1df71 | 607 | return ret; |
1da177e4 LT |
608 | } |
609 | ||
c4be0c1d | 610 | static int jfs_freeze(struct super_block *sb) |
1da177e4 LT |
611 | { |
612 | struct jfs_sb_info *sbi = JFS_SBI(sb); | |
613 | struct jfs_log *log = sbi->log; | |
614 | ||
615 | if (!(sb->s_flags & MS_RDONLY)) { | |
616 | txQuiesce(sb); | |
617 | lmLogShutdown(log); | |
618 | updateSuper(sb, FM_CLEAN); | |
619 | } | |
c4be0c1d | 620 | return 0; |
1da177e4 LT |
621 | } |
622 | ||
c4be0c1d | 623 | static int jfs_unfreeze(struct super_block *sb) |
1da177e4 LT |
624 | { |
625 | struct jfs_sb_info *sbi = JFS_SBI(sb); | |
626 | struct jfs_log *log = sbi->log; | |
627 | int rc = 0; | |
628 | ||
629 | if (!(sb->s_flags & MS_RDONLY)) { | |
630 | updateSuper(sb, FM_MOUNT); | |
631 | if ((rc = lmLogInit(log))) | |
632 | jfs_err("jfs_unlock failed with return code %d", rc); | |
633 | else | |
634 | txResume(sb); | |
635 | } | |
c4be0c1d | 636 | return 0; |
1da177e4 LT |
637 | } |
638 | ||
152a0836 AV |
639 | static struct dentry *jfs_do_mount(struct file_system_type *fs_type, |
640 | int flags, const char *dev_name, void *data) | |
1da177e4 | 641 | { |
152a0836 | 642 | return mount_bdev(fs_type, flags, dev_name, data, jfs_fill_super); |
1da177e4 LT |
643 | } |
644 | ||
645 | static int jfs_sync_fs(struct super_block *sb, int wait) | |
646 | { | |
647 | struct jfs_log *log = JFS_SBI(sb)->log; | |
648 | ||
649 | /* log == NULL indicates read-only mount */ | |
1c627829 | 650 | if (log) { |
a1177825 JK |
651 | /* |
652 | * Write quota structures to quota file, sync_blockdev() will | |
653 | * write them to disk later | |
654 | */ | |
655 | dquot_writeback_dquots(sb, -1); | |
1da177e4 | 656 | jfs_flush_journal(log, wait); |
cbc3d65e | 657 | jfs_syncpt(log, 0); |
1c627829 | 658 | } |
1da177e4 LT |
659 | |
660 | return 0; | |
661 | } | |
662 | ||
34c80b1d | 663 | static int jfs_show_options(struct seq_file *seq, struct dentry *root) |
8fc2751b | 664 | { |
34c80b1d | 665 | struct jfs_sb_info *sbi = JFS_SBI(root->d_sb); |
8fc2751b | 666 | |
c18cdc1a EB |
667 | if (uid_valid(sbi->uid)) |
668 | seq_printf(seq, ",uid=%d", from_kuid(&init_user_ns, sbi->uid)); | |
669 | if (gid_valid(sbi->gid)) | |
670 | seq_printf(seq, ",gid=%d", from_kgid(&init_user_ns, sbi->gid)); | |
69eb66d7 DK |
671 | if (sbi->umask != -1) |
672 | seq_printf(seq, ",umask=%03o", sbi->umask); | |
8fc2751b MB |
673 | if (sbi->flag & JFS_NOINTEGRITY) |
674 | seq_puts(seq, ",nointegrity"); | |
b40c2e66 TR |
675 | if (sbi->flag & JFS_DISCARD) |
676 | seq_printf(seq, ",discard=%u", sbi->minblks_trim); | |
5c5e32ce MS |
677 | if (sbi->nls_tab) |
678 | seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset); | |
679 | if (sbi->flag & JFS_ERR_CONTINUE) | |
680 | seq_printf(seq, ",errors=continue"); | |
681 | if (sbi->flag & JFS_ERR_PANIC) | |
682 | seq_printf(seq, ",errors=panic"); | |
8fc2751b | 683 | |
115ff50b | 684 | #ifdef CONFIG_QUOTA |
8fc2751b MB |
685 | if (sbi->flag & JFS_USRQUOTA) |
686 | seq_puts(seq, ",usrquota"); | |
687 | ||
688 | if (sbi->flag & JFS_GRPQUOTA) | |
689 | seq_puts(seq, ",grpquota"); | |
690 | #endif | |
691 | ||
692 | return 0; | |
693 | } | |
694 | ||
115ff50b DK |
695 | #ifdef CONFIG_QUOTA |
696 | ||
697 | /* Read data from quotafile - avoid pagecache and such because we cannot afford | |
698 | * acquiring the locks... As quota files are never truncated and quota code | |
25985edc | 699 | * itself serializes the operations (and no one else should touch the files) |
115ff50b DK |
700 | * we don't have to be afraid of races */ |
701 | static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data, | |
702 | size_t len, loff_t off) | |
703 | { | |
704 | struct inode *inode = sb_dqopt(sb)->files[type]; | |
705 | sector_t blk = off >> sb->s_blocksize_bits; | |
706 | int err = 0; | |
707 | int offset = off & (sb->s_blocksize - 1); | |
708 | int tocopy; | |
709 | size_t toread; | |
710 | struct buffer_head tmp_bh; | |
711 | struct buffer_head *bh; | |
712 | loff_t i_size = i_size_read(inode); | |
713 | ||
714 | if (off > i_size) | |
715 | return 0; | |
716 | if (off+len > i_size) | |
717 | len = i_size-off; | |
718 | toread = len; | |
719 | while (toread > 0) { | |
720 | tocopy = sb->s_blocksize - offset < toread ? | |
721 | sb->s_blocksize - offset : toread; | |
722 | ||
723 | tmp_bh.b_state = 0; | |
724 | tmp_bh.b_size = 1 << inode->i_blkbits; | |
725 | err = jfs_get_block(inode, blk, &tmp_bh, 0); | |
726 | if (err) | |
727 | return err; | |
728 | if (!buffer_mapped(&tmp_bh)) /* A hole? */ | |
729 | memset(data, 0, tocopy); | |
730 | else { | |
731 | bh = sb_bread(sb, tmp_bh.b_blocknr); | |
732 | if (!bh) | |
733 | return -EIO; | |
734 | memcpy(data, bh->b_data+offset, tocopy); | |
735 | brelse(bh); | |
736 | } | |
737 | offset = 0; | |
738 | toread -= tocopy; | |
739 | data += tocopy; | |
740 | blk++; | |
741 | } | |
742 | return len; | |
743 | } | |
744 | ||
745 | /* Write to quotafile */ | |
746 | static ssize_t jfs_quota_write(struct super_block *sb, int type, | |
747 | const char *data, size_t len, loff_t off) | |
748 | { | |
749 | struct inode *inode = sb_dqopt(sb)->files[type]; | |
750 | sector_t blk = off >> sb->s_blocksize_bits; | |
751 | int err = 0; | |
752 | int offset = off & (sb->s_blocksize - 1); | |
753 | int tocopy; | |
754 | size_t towrite = len; | |
755 | struct buffer_head tmp_bh; | |
756 | struct buffer_head *bh; | |
757 | ||
758 | mutex_lock(&inode->i_mutex); | |
759 | while (towrite > 0) { | |
760 | tocopy = sb->s_blocksize - offset < towrite ? | |
761 | sb->s_blocksize - offset : towrite; | |
762 | ||
763 | tmp_bh.b_state = 0; | |
8bcb2839 | 764 | tmp_bh.b_size = 1 << inode->i_blkbits; |
115ff50b DK |
765 | err = jfs_get_block(inode, blk, &tmp_bh, 1); |
766 | if (err) | |
767 | goto out; | |
768 | if (offset || tocopy != sb->s_blocksize) | |
769 | bh = sb_bread(sb, tmp_bh.b_blocknr); | |
770 | else | |
771 | bh = sb_getblk(sb, tmp_bh.b_blocknr); | |
772 | if (!bh) { | |
773 | err = -EIO; | |
774 | goto out; | |
775 | } | |
776 | lock_buffer(bh); | |
777 | memcpy(bh->b_data+offset, data, tocopy); | |
778 | flush_dcache_page(bh->b_page); | |
779 | set_buffer_uptodate(bh); | |
780 | mark_buffer_dirty(bh); | |
781 | unlock_buffer(bh); | |
782 | brelse(bh); | |
783 | offset = 0; | |
784 | towrite -= tocopy; | |
785 | data += tocopy; | |
786 | blk++; | |
787 | } | |
788 | out: | |
9c83633a DC |
789 | if (len == towrite) { |
790 | mutex_unlock(&inode->i_mutex); | |
115ff50b | 791 | return err; |
9c83633a | 792 | } |
115ff50b DK |
793 | if (inode->i_size < off+len-towrite) |
794 | i_size_write(inode, off+len-towrite); | |
795 | inode->i_version++; | |
796 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; | |
797 | mark_inode_dirty(inode); | |
798 | mutex_unlock(&inode->i_mutex); | |
799 | return len - towrite; | |
800 | } | |
801 | ||
802 | #endif | |
803 | ||
ee9b6d61 | 804 | static const struct super_operations jfs_super_operations = { |
1da177e4 LT |
805 | .alloc_inode = jfs_alloc_inode, |
806 | .destroy_inode = jfs_destroy_inode, | |
1da177e4 LT |
807 | .dirty_inode = jfs_dirty_inode, |
808 | .write_inode = jfs_write_inode, | |
62aff86f | 809 | .evict_inode = jfs_evict_inode, |
1da177e4 LT |
810 | .put_super = jfs_put_super, |
811 | .sync_fs = jfs_sync_fs, | |
c4be0c1d TS |
812 | .freeze_fs = jfs_freeze, |
813 | .unfreeze_fs = jfs_unfreeze, | |
1da177e4 LT |
814 | .statfs = jfs_statfs, |
815 | .remount_fs = jfs_remount, | |
115ff50b DK |
816 | .show_options = jfs_show_options, |
817 | #ifdef CONFIG_QUOTA | |
818 | .quota_read = jfs_quota_read, | |
819 | .quota_write = jfs_quota_write, | |
820 | #endif | |
1da177e4 LT |
821 | }; |
822 | ||
39655164 | 823 | static const struct export_operations jfs_export_operations = { |
d425de70 CH |
824 | .fh_to_dentry = jfs_fh_to_dentry, |
825 | .fh_to_parent = jfs_fh_to_parent, | |
1da177e4 LT |
826 | .get_parent = jfs_get_parent, |
827 | }; | |
828 | ||
829 | static struct file_system_type jfs_fs_type = { | |
830 | .owner = THIS_MODULE, | |
831 | .name = "jfs", | |
152a0836 | 832 | .mount = jfs_do_mount, |
1da177e4 LT |
833 | .kill_sb = kill_block_super, |
834 | .fs_flags = FS_REQUIRES_DEV, | |
835 | }; | |
836 | ||
51cc5068 | 837 | static void init_once(void *foo) |
1da177e4 LT |
838 | { |
839 | struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo; | |
840 | ||
a35afb83 CL |
841 | memset(jfs_ip, 0, sizeof(struct jfs_inode_info)); |
842 | INIT_LIST_HEAD(&jfs_ip->anon_inode_list); | |
843 | init_rwsem(&jfs_ip->rdwrlock); | |
844 | mutex_init(&jfs_ip->commit_mutex); | |
845 | init_rwsem(&jfs_ip->xattr_sem); | |
846 | spin_lock_init(&jfs_ip->ag_lock); | |
847 | jfs_ip->active_ag = -1; | |
a35afb83 | 848 | inode_init_once(&jfs_ip->vfs_inode); |
1da177e4 LT |
849 | } |
850 | ||
851 | static int __init init_jfs_fs(void) | |
852 | { | |
853 | int i; | |
854 | int rc; | |
855 | ||
856 | jfs_inode_cachep = | |
63f83c9f | 857 | kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0, |
fffb60f9 | 858 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, |
20c2df83 | 859 | init_once); |
1da177e4 LT |
860 | if (jfs_inode_cachep == NULL) |
861 | return -ENOMEM; | |
862 | ||
863 | /* | |
864 | * Metapage initialization | |
865 | */ | |
866 | rc = metapage_init(); | |
867 | if (rc) { | |
868 | jfs_err("metapage_init failed w/rc = %d", rc); | |
869 | goto free_slab; | |
870 | } | |
871 | ||
872 | /* | |
873 | * Transaction Manager initialization | |
874 | */ | |
875 | rc = txInit(); | |
876 | if (rc) { | |
877 | jfs_err("txInit failed w/rc = %d", rc); | |
878 | goto free_metapage; | |
879 | } | |
880 | ||
881 | /* | |
882 | * I/O completion thread (endio) | |
883 | */ | |
91dbb4de CH |
884 | jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO"); |
885 | if (IS_ERR(jfsIOthread)) { | |
886 | rc = PTR_ERR(jfsIOthread); | |
887 | jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); | |
1da177e4 LT |
888 | goto end_txmngr; |
889 | } | |
1da177e4 LT |
890 | |
891 | if (commit_threads < 1) | |
892 | commit_threads = num_online_cpus(); | |
893 | if (commit_threads > MAX_COMMIT_THREADS) | |
894 | commit_threads = MAX_COMMIT_THREADS; | |
895 | ||
896 | for (i = 0; i < commit_threads; i++) { | |
91dbb4de CH |
897 | jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL, "jfsCommit"); |
898 | if (IS_ERR(jfsCommitThread[i])) { | |
899 | rc = PTR_ERR(jfsCommitThread[i]); | |
900 | jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); | |
1da177e4 LT |
901 | commit_threads = i; |
902 | goto kill_committask; | |
903 | } | |
1da177e4 LT |
904 | } |
905 | ||
91dbb4de CH |
906 | jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync"); |
907 | if (IS_ERR(jfsSyncThread)) { | |
908 | rc = PTR_ERR(jfsSyncThread); | |
909 | jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); | |
1da177e4 LT |
910 | goto kill_committask; |
911 | } | |
1da177e4 LT |
912 | |
913 | #ifdef PROC_FS_JFS | |
914 | jfs_proc_init(); | |
915 | #endif | |
916 | ||
76bf09fc AV |
917 | rc = register_filesystem(&jfs_fs_type); |
918 | if (!rc) | |
919 | return 0; | |
1da177e4 | 920 | |
76bf09fc AV |
921 | #ifdef PROC_FS_JFS |
922 | jfs_proc_clean(); | |
923 | #endif | |
924 | kthread_stop(jfsSyncThread); | |
1da177e4 | 925 | kill_committask: |
1da177e4 | 926 | for (i = 0; i < commit_threads; i++) |
91dbb4de CH |
927 | kthread_stop(jfsCommitThread[i]); |
928 | kthread_stop(jfsIOthread); | |
1da177e4 LT |
929 | end_txmngr: |
930 | txExit(); | |
931 | free_metapage: | |
932 | metapage_exit(); | |
933 | free_slab: | |
934 | kmem_cache_destroy(jfs_inode_cachep); | |
935 | return rc; | |
936 | } | |
937 | ||
938 | static void __exit exit_jfs_fs(void) | |
939 | { | |
940 | int i; | |
941 | ||
942 | jfs_info("exit_jfs_fs called"); | |
943 | ||
1da177e4 LT |
944 | txExit(); |
945 | metapage_exit(); | |
91dbb4de CH |
946 | |
947 | kthread_stop(jfsIOthread); | |
1da177e4 | 948 | for (i = 0; i < commit_threads; i++) |
91dbb4de CH |
949 | kthread_stop(jfsCommitThread[i]); |
950 | kthread_stop(jfsSyncThread); | |
1da177e4 LT |
951 | #ifdef PROC_FS_JFS |
952 | jfs_proc_clean(); | |
953 | #endif | |
954 | unregister_filesystem(&jfs_fs_type); | |
8c0a8537 KS |
955 | |
956 | /* | |
957 | * Make sure all delayed rcu free inodes are flushed before we | |
958 | * destroy cache. | |
959 | */ | |
960 | rcu_barrier(); | |
1da177e4 LT |
961 | kmem_cache_destroy(jfs_inode_cachep); |
962 | } | |
963 | ||
964 | module_init(init_jfs_fs) | |
965 | module_exit(exit_jfs_fs) |