diff options
Diffstat (limited to 'fs/nilfs2/super.c')
-rw-r--r-- | fs/nilfs2/super.c | 219 |
1 files changed, 94 insertions, 125 deletions
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c index 0994f6a76c07..062cca065195 100644 --- a/fs/nilfs2/super.c +++ b/fs/nilfs2/super.c | |||
@@ -43,7 +43,6 @@ | |||
43 | #include <linux/init.h> | 43 | #include <linux/init.h> |
44 | #include <linux/blkdev.h> | 44 | #include <linux/blkdev.h> |
45 | #include <linux/parser.h> | 45 | #include <linux/parser.h> |
46 | #include <linux/random.h> | ||
47 | #include <linux/crc32.h> | 46 | #include <linux/crc32.h> |
48 | #include <linux/vfs.h> | 47 | #include <linux/vfs.h> |
49 | #include <linux/writeback.h> | 48 | #include <linux/writeback.h> |
@@ -72,23 +71,23 @@ struct kmem_cache *nilfs_transaction_cachep; | |||
72 | struct kmem_cache *nilfs_segbuf_cachep; | 71 | struct kmem_cache *nilfs_segbuf_cachep; |
73 | struct kmem_cache *nilfs_btree_path_cache; | 72 | struct kmem_cache *nilfs_btree_path_cache; |
74 | 73 | ||
75 | static int nilfs_setup_super(struct nilfs_sb_info *sbi, int is_mount); | 74 | static int nilfs_setup_super(struct super_block *sb, int is_mount); |
76 | static int nilfs_remount(struct super_block *sb, int *flags, char *data); | 75 | static int nilfs_remount(struct super_block *sb, int *flags, char *data); |
77 | 76 | ||
78 | static void nilfs_set_error(struct nilfs_sb_info *sbi) | 77 | static void nilfs_set_error(struct super_block *sb) |
79 | { | 78 | { |
80 | struct the_nilfs *nilfs = sbi->s_nilfs; | 79 | struct the_nilfs *nilfs = sb->s_fs_info; |
81 | struct nilfs_super_block **sbp; | 80 | struct nilfs_super_block **sbp; |
82 | 81 | ||
83 | down_write(&nilfs->ns_sem); | 82 | down_write(&nilfs->ns_sem); |
84 | if (!(nilfs->ns_mount_state & NILFS_ERROR_FS)) { | 83 | if (!(nilfs->ns_mount_state & NILFS_ERROR_FS)) { |
85 | nilfs->ns_mount_state |= NILFS_ERROR_FS; | 84 | nilfs->ns_mount_state |= NILFS_ERROR_FS; |
86 | sbp = nilfs_prepare_super(sbi, 0); | 85 | sbp = nilfs_prepare_super(sb, 0); |
87 | if (likely(sbp)) { | 86 | if (likely(sbp)) { |
88 | sbp[0]->s_state |= cpu_to_le16(NILFS_ERROR_FS); | 87 | sbp[0]->s_state |= cpu_to_le16(NILFS_ERROR_FS); |
89 | if (sbp[1]) | 88 | if (sbp[1]) |
90 | sbp[1]->s_state |= cpu_to_le16(NILFS_ERROR_FS); | 89 | sbp[1]->s_state |= cpu_to_le16(NILFS_ERROR_FS); |
91 | nilfs_commit_super(sbi, NILFS_SB_COMMIT_ALL); | 90 | nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL); |
92 | } | 91 | } |
93 | } | 92 | } |
94 | up_write(&nilfs->ns_sem); | 93 | up_write(&nilfs->ns_sem); |
@@ -109,7 +108,7 @@ static void nilfs_set_error(struct nilfs_sb_info *sbi) | |||
109 | void nilfs_error(struct super_block *sb, const char *function, | 108 | void nilfs_error(struct super_block *sb, const char *function, |
110 | const char *fmt, ...) | 109 | const char *fmt, ...) |
111 | { | 110 | { |
112 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 111 | struct the_nilfs *nilfs = sb->s_fs_info; |
113 | struct va_format vaf; | 112 | struct va_format vaf; |
114 | va_list args; | 113 | va_list args; |
115 | 114 | ||
@@ -124,15 +123,15 @@ void nilfs_error(struct super_block *sb, const char *function, | |||
124 | va_end(args); | 123 | va_end(args); |
125 | 124 | ||
126 | if (!(sb->s_flags & MS_RDONLY)) { | 125 | if (!(sb->s_flags & MS_RDONLY)) { |
127 | nilfs_set_error(sbi); | 126 | nilfs_set_error(sb); |
128 | 127 | ||
129 | if (nilfs_test_opt(sbi, ERRORS_RO)) { | 128 | if (nilfs_test_opt(nilfs, ERRORS_RO)) { |
130 | printk(KERN_CRIT "Remounting filesystem read-only\n"); | 129 | printk(KERN_CRIT "Remounting filesystem read-only\n"); |
131 | sb->s_flags |= MS_RDONLY; | 130 | sb->s_flags |= MS_RDONLY; |
132 | } | 131 | } |
133 | } | 132 | } |
134 | 133 | ||
135 | if (nilfs_test_opt(sbi, ERRORS_PANIC)) | 134 | if (nilfs_test_opt(nilfs, ERRORS_PANIC)) |
136 | panic("NILFS (device %s): panic forced after error\n", | 135 | panic("NILFS (device %s): panic forced after error\n", |
137 | sb->s_id); | 136 | sb->s_id); |
138 | } | 137 | } |
@@ -189,14 +188,14 @@ void nilfs_destroy_inode(struct inode *inode) | |||
189 | call_rcu(&inode->i_rcu, nilfs_i_callback); | 188 | call_rcu(&inode->i_rcu, nilfs_i_callback); |
190 | } | 189 | } |
191 | 190 | ||
192 | static int nilfs_sync_super(struct nilfs_sb_info *sbi, int flag) | 191 | static int nilfs_sync_super(struct super_block *sb, int flag) |
193 | { | 192 | { |
194 | struct the_nilfs *nilfs = sbi->s_nilfs; | 193 | struct the_nilfs *nilfs = sb->s_fs_info; |
195 | int err; | 194 | int err; |
196 | 195 | ||
197 | retry: | 196 | retry: |
198 | set_buffer_dirty(nilfs->ns_sbh[0]); | 197 | set_buffer_dirty(nilfs->ns_sbh[0]); |
199 | if (nilfs_test_opt(sbi, BARRIER)) { | 198 | if (nilfs_test_opt(nilfs, BARRIER)) { |
200 | err = __sync_dirty_buffer(nilfs->ns_sbh[0], | 199 | err = __sync_dirty_buffer(nilfs->ns_sbh[0], |
201 | WRITE_SYNC | WRITE_FLUSH_FUA); | 200 | WRITE_SYNC | WRITE_FLUSH_FUA); |
202 | } else { | 201 | } else { |
@@ -263,10 +262,10 @@ void nilfs_set_log_cursor(struct nilfs_super_block *sbp, | |||
263 | spin_unlock(&nilfs->ns_last_segment_lock); | 262 | spin_unlock(&nilfs->ns_last_segment_lock); |
264 | } | 263 | } |
265 | 264 | ||
266 | struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *sbi, | 265 | struct nilfs_super_block **nilfs_prepare_super(struct super_block *sb, |
267 | int flip) | 266 | int flip) |
268 | { | 267 | { |
269 | struct the_nilfs *nilfs = sbi->s_nilfs; | 268 | struct the_nilfs *nilfs = sb->s_fs_info; |
270 | struct nilfs_super_block **sbp = nilfs->ns_sbp; | 269 | struct nilfs_super_block **sbp = nilfs->ns_sbp; |
271 | 270 | ||
272 | /* nilfs->ns_sem must be locked by the caller. */ | 271 | /* nilfs->ns_sem must be locked by the caller. */ |
@@ -276,7 +275,7 @@ struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *sbi, | |||
276 | memcpy(sbp[0], sbp[1], nilfs->ns_sbsize); | 275 | memcpy(sbp[0], sbp[1], nilfs->ns_sbsize); |
277 | } else { | 276 | } else { |
278 | printk(KERN_CRIT "NILFS: superblock broke on dev %s\n", | 277 | printk(KERN_CRIT "NILFS: superblock broke on dev %s\n", |
279 | sbi->s_super->s_id); | 278 | sb->s_id); |
280 | return NULL; | 279 | return NULL; |
281 | } | 280 | } |
282 | } else if (sbp[1] && | 281 | } else if (sbp[1] && |
@@ -290,9 +289,9 @@ struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *sbi, | |||
290 | return sbp; | 289 | return sbp; |
291 | } | 290 | } |
292 | 291 | ||
293 | int nilfs_commit_super(struct nilfs_sb_info *sbi, int flag) | 292 | int nilfs_commit_super(struct super_block *sb, int flag) |
294 | { | 293 | { |
295 | struct the_nilfs *nilfs = sbi->s_nilfs; | 294 | struct the_nilfs *nilfs = sb->s_fs_info; |
296 | struct nilfs_super_block **sbp = nilfs->ns_sbp; | 295 | struct nilfs_super_block **sbp = nilfs->ns_sbp; |
297 | time_t t; | 296 | time_t t; |
298 | 297 | ||
@@ -312,27 +311,28 @@ int nilfs_commit_super(struct nilfs_sb_info *sbi, int flag) | |||
312 | nilfs->ns_sbsize)); | 311 | nilfs->ns_sbsize)); |
313 | } | 312 | } |
314 | clear_nilfs_sb_dirty(nilfs); | 313 | clear_nilfs_sb_dirty(nilfs); |
315 | return nilfs_sync_super(sbi, flag); | 314 | return nilfs_sync_super(sb, flag); |
316 | } | 315 | } |
317 | 316 | ||
318 | /** | 317 | /** |
319 | * nilfs_cleanup_super() - write filesystem state for cleanup | 318 | * nilfs_cleanup_super() - write filesystem state for cleanup |
320 | * @sbi: nilfs_sb_info to be unmounted or degraded to read-only | 319 | * @sb: super block instance to be unmounted or degraded to read-only |
321 | * | 320 | * |
322 | * This function restores state flags in the on-disk super block. | 321 | * This function restores state flags in the on-disk super block. |
323 | * This will set "clean" flag (i.e. NILFS_VALID_FS) unless the | 322 | * This will set "clean" flag (i.e. NILFS_VALID_FS) unless the |
324 | * filesystem was not clean previously. | 323 | * filesystem was not clean previously. |
325 | */ | 324 | */ |
326 | int nilfs_cleanup_super(struct nilfs_sb_info *sbi) | 325 | int nilfs_cleanup_super(struct super_block *sb) |
327 | { | 326 | { |
327 | struct the_nilfs *nilfs = sb->s_fs_info; | ||
328 | struct nilfs_super_block **sbp; | 328 | struct nilfs_super_block **sbp; |
329 | int flag = NILFS_SB_COMMIT; | 329 | int flag = NILFS_SB_COMMIT; |
330 | int ret = -EIO; | 330 | int ret = -EIO; |
331 | 331 | ||
332 | sbp = nilfs_prepare_super(sbi, 0); | 332 | sbp = nilfs_prepare_super(sb, 0); |
333 | if (sbp) { | 333 | if (sbp) { |
334 | sbp[0]->s_state = cpu_to_le16(sbi->s_nilfs->ns_mount_state); | 334 | sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state); |
335 | nilfs_set_log_cursor(sbp[0], sbi->s_nilfs); | 335 | nilfs_set_log_cursor(sbp[0], nilfs); |
336 | if (sbp[1] && sbp[0]->s_last_cno == sbp[1]->s_last_cno) { | 336 | if (sbp[1] && sbp[0]->s_last_cno == sbp[1]->s_last_cno) { |
337 | /* | 337 | /* |
338 | * make the "clean" flag also to the opposite | 338 | * make the "clean" flag also to the opposite |
@@ -342,21 +342,20 @@ int nilfs_cleanup_super(struct nilfs_sb_info *sbi) | |||
342 | sbp[1]->s_state = sbp[0]->s_state; | 342 | sbp[1]->s_state = sbp[0]->s_state; |
343 | flag = NILFS_SB_COMMIT_ALL; | 343 | flag = NILFS_SB_COMMIT_ALL; |
344 | } | 344 | } |
345 | ret = nilfs_commit_super(sbi, flag); | 345 | ret = nilfs_commit_super(sb, flag); |
346 | } | 346 | } |
347 | return ret; | 347 | return ret; |
348 | } | 348 | } |
349 | 349 | ||
350 | static void nilfs_put_super(struct super_block *sb) | 350 | static void nilfs_put_super(struct super_block *sb) |
351 | { | 351 | { |
352 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 352 | struct the_nilfs *nilfs = sb->s_fs_info; |
353 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
354 | 353 | ||
355 | nilfs_detach_segment_constructor(sbi); | 354 | nilfs_detach_log_writer(sb); |
356 | 355 | ||
357 | if (!(sb->s_flags & MS_RDONLY)) { | 356 | if (!(sb->s_flags & MS_RDONLY)) { |
358 | down_write(&nilfs->ns_sem); | 357 | down_write(&nilfs->ns_sem); |
359 | nilfs_cleanup_super(sbi); | 358 | nilfs_cleanup_super(sb); |
360 | up_write(&nilfs->ns_sem); | 359 | up_write(&nilfs->ns_sem); |
361 | } | 360 | } |
362 | 361 | ||
@@ -365,15 +364,12 @@ static void nilfs_put_super(struct super_block *sb) | |||
365 | iput(nilfs->ns_dat); | 364 | iput(nilfs->ns_dat); |
366 | 365 | ||
367 | destroy_nilfs(nilfs); | 366 | destroy_nilfs(nilfs); |
368 | sbi->s_super = NULL; | ||
369 | sb->s_fs_info = NULL; | 367 | sb->s_fs_info = NULL; |
370 | kfree(sbi); | ||
371 | } | 368 | } |
372 | 369 | ||
373 | static int nilfs_sync_fs(struct super_block *sb, int wait) | 370 | static int nilfs_sync_fs(struct super_block *sb, int wait) |
374 | { | 371 | { |
375 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 372 | struct the_nilfs *nilfs = sb->s_fs_info; |
376 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
377 | struct nilfs_super_block **sbp; | 373 | struct nilfs_super_block **sbp; |
378 | int err = 0; | 374 | int err = 0; |
379 | 375 | ||
@@ -383,10 +379,10 @@ static int nilfs_sync_fs(struct super_block *sb, int wait) | |||
383 | 379 | ||
384 | down_write(&nilfs->ns_sem); | 380 | down_write(&nilfs->ns_sem); |
385 | if (nilfs_sb_dirty(nilfs)) { | 381 | if (nilfs_sb_dirty(nilfs)) { |
386 | sbp = nilfs_prepare_super(sbi, nilfs_sb_will_flip(nilfs)); | 382 | sbp = nilfs_prepare_super(sb, nilfs_sb_will_flip(nilfs)); |
387 | if (likely(sbp)) { | 383 | if (likely(sbp)) { |
388 | nilfs_set_log_cursor(sbp[0], nilfs); | 384 | nilfs_set_log_cursor(sbp[0], nilfs); |
389 | nilfs_commit_super(sbi, NILFS_SB_COMMIT); | 385 | nilfs_commit_super(sb, NILFS_SB_COMMIT); |
390 | } | 386 | } |
391 | } | 387 | } |
392 | up_write(&nilfs->ns_sem); | 388 | up_write(&nilfs->ns_sem); |
@@ -394,10 +390,10 @@ static int nilfs_sync_fs(struct super_block *sb, int wait) | |||
394 | return err; | 390 | return err; |
395 | } | 391 | } |
396 | 392 | ||
397 | int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt, | 393 | int nilfs_attach_checkpoint(struct super_block *sb, __u64 cno, int curr_mnt, |
398 | struct nilfs_root **rootp) | 394 | struct nilfs_root **rootp) |
399 | { | 395 | { |
400 | struct the_nilfs *nilfs = sbi->s_nilfs; | 396 | struct the_nilfs *nilfs = sb->s_fs_info; |
401 | struct nilfs_root *root; | 397 | struct nilfs_root *root; |
402 | struct nilfs_checkpoint *raw_cp; | 398 | struct nilfs_checkpoint *raw_cp; |
403 | struct buffer_head *bh_cp; | 399 | struct buffer_head *bh_cp; |
@@ -426,7 +422,7 @@ int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt, | |||
426 | goto failed; | 422 | goto failed; |
427 | } | 423 | } |
428 | 424 | ||
429 | err = nilfs_ifile_read(sbi->s_super, root, nilfs->ns_inode_size, | 425 | err = nilfs_ifile_read(sb, root, nilfs->ns_inode_size, |
430 | &raw_cp->cp_ifile_inode, &root->ifile); | 426 | &raw_cp->cp_ifile_inode, &root->ifile); |
431 | if (err) | 427 | if (err) |
432 | goto failed_bh; | 428 | goto failed_bh; |
@@ -450,8 +446,7 @@ int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt, | |||
450 | 446 | ||
451 | static int nilfs_freeze(struct super_block *sb) | 447 | static int nilfs_freeze(struct super_block *sb) |
452 | { | 448 | { |
453 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 449 | struct the_nilfs *nilfs = sb->s_fs_info; |
454 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
455 | int err; | 450 | int err; |
456 | 451 | ||
457 | if (sb->s_flags & MS_RDONLY) | 452 | if (sb->s_flags & MS_RDONLY) |
@@ -459,21 +454,20 @@ static int nilfs_freeze(struct super_block *sb) | |||
459 | 454 | ||
460 | /* Mark super block clean */ | 455 | /* Mark super block clean */ |
461 | down_write(&nilfs->ns_sem); | 456 | down_write(&nilfs->ns_sem); |
462 | err = nilfs_cleanup_super(sbi); | 457 | err = nilfs_cleanup_super(sb); |
463 | up_write(&nilfs->ns_sem); | 458 | up_write(&nilfs->ns_sem); |
464 | return err; | 459 | return err; |
465 | } | 460 | } |
466 | 461 | ||
467 | static int nilfs_unfreeze(struct super_block *sb) | 462 | static int nilfs_unfreeze(struct super_block *sb) |
468 | { | 463 | { |
469 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 464 | struct the_nilfs *nilfs = sb->s_fs_info; |
470 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
471 | 465 | ||
472 | if (sb->s_flags & MS_RDONLY) | 466 | if (sb->s_flags & MS_RDONLY) |
473 | return 0; | 467 | return 0; |
474 | 468 | ||
475 | down_write(&nilfs->ns_sem); | 469 | down_write(&nilfs->ns_sem); |
476 | nilfs_setup_super(sbi, false); | 470 | nilfs_setup_super(sb, false); |
477 | up_write(&nilfs->ns_sem); | 471 | up_write(&nilfs->ns_sem); |
478 | return 0; | 472 | return 0; |
479 | } | 473 | } |
@@ -530,22 +524,22 @@ static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
530 | static int nilfs_show_options(struct seq_file *seq, struct vfsmount *vfs) | 524 | static int nilfs_show_options(struct seq_file *seq, struct vfsmount *vfs) |
531 | { | 525 | { |
532 | struct super_block *sb = vfs->mnt_sb; | 526 | struct super_block *sb = vfs->mnt_sb; |
533 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 527 | struct the_nilfs *nilfs = sb->s_fs_info; |
534 | struct nilfs_root *root = NILFS_I(vfs->mnt_root->d_inode)->i_root; | 528 | struct nilfs_root *root = NILFS_I(vfs->mnt_root->d_inode)->i_root; |
535 | 529 | ||
536 | if (!nilfs_test_opt(sbi, BARRIER)) | 530 | if (!nilfs_test_opt(nilfs, BARRIER)) |
537 | seq_puts(seq, ",nobarrier"); | 531 | seq_puts(seq, ",nobarrier"); |
538 | if (root->cno != NILFS_CPTREE_CURRENT_CNO) | 532 | if (root->cno != NILFS_CPTREE_CURRENT_CNO) |
539 | seq_printf(seq, ",cp=%llu", (unsigned long long)root->cno); | 533 | seq_printf(seq, ",cp=%llu", (unsigned long long)root->cno); |
540 | if (nilfs_test_opt(sbi, ERRORS_PANIC)) | 534 | if (nilfs_test_opt(nilfs, ERRORS_PANIC)) |
541 | seq_puts(seq, ",errors=panic"); | 535 | seq_puts(seq, ",errors=panic"); |
542 | if (nilfs_test_opt(sbi, ERRORS_CONT)) | 536 | if (nilfs_test_opt(nilfs, ERRORS_CONT)) |
543 | seq_puts(seq, ",errors=continue"); | 537 | seq_puts(seq, ",errors=continue"); |
544 | if (nilfs_test_opt(sbi, STRICT_ORDER)) | 538 | if (nilfs_test_opt(nilfs, STRICT_ORDER)) |
545 | seq_puts(seq, ",order=strict"); | 539 | seq_puts(seq, ",order=strict"); |
546 | if (nilfs_test_opt(sbi, NORECOVERY)) | 540 | if (nilfs_test_opt(nilfs, NORECOVERY)) |
547 | seq_puts(seq, ",norecovery"); | 541 | seq_puts(seq, ",norecovery"); |
548 | if (nilfs_test_opt(sbi, DISCARD)) | 542 | if (nilfs_test_opt(nilfs, DISCARD)) |
549 | seq_puts(seq, ",discard"); | 543 | seq_puts(seq, ",discard"); |
550 | 544 | ||
551 | return 0; | 545 | return 0; |
@@ -594,7 +588,7 @@ static match_table_t tokens = { | |||
594 | 588 | ||
595 | static int parse_options(char *options, struct super_block *sb, int is_remount) | 589 | static int parse_options(char *options, struct super_block *sb, int is_remount) |
596 | { | 590 | { |
597 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 591 | struct the_nilfs *nilfs = sb->s_fs_info; |
598 | char *p; | 592 | char *p; |
599 | substring_t args[MAX_OPT_ARGS]; | 593 | substring_t args[MAX_OPT_ARGS]; |
600 | 594 | ||
@@ -609,29 +603,29 @@ static int parse_options(char *options, struct super_block *sb, int is_remount) | |||
609 | token = match_token(p, tokens, args); | 603 | token = match_token(p, tokens, args); |
610 | switch (token) { | 604 | switch (token) { |
611 | case Opt_barrier: | 605 | case Opt_barrier: |
612 | nilfs_set_opt(sbi, BARRIER); | 606 | nilfs_set_opt(nilfs, BARRIER); |
613 | break; | 607 | break; |
614 | case Opt_nobarrier: | 608 | case Opt_nobarrier: |
615 | nilfs_clear_opt(sbi, BARRIER); | 609 | nilfs_clear_opt(nilfs, BARRIER); |
616 | break; | 610 | break; |
617 | case Opt_order: | 611 | case Opt_order: |
618 | if (strcmp(args[0].from, "relaxed") == 0) | 612 | if (strcmp(args[0].from, "relaxed") == 0) |
619 | /* Ordered data semantics */ | 613 | /* Ordered data semantics */ |
620 | nilfs_clear_opt(sbi, STRICT_ORDER); | 614 | nilfs_clear_opt(nilfs, STRICT_ORDER); |
621 | else if (strcmp(args[0].from, "strict") == 0) | 615 | else if (strcmp(args[0].from, "strict") == 0) |
622 | /* Strict in-order semantics */ | 616 | /* Strict in-order semantics */ |
623 | nilfs_set_opt(sbi, STRICT_ORDER); | 617 | nilfs_set_opt(nilfs, STRICT_ORDER); |
624 | else | 618 | else |
625 | return 0; | 619 | return 0; |
626 | break; | 620 | break; |
627 | case Opt_err_panic: | 621 | case Opt_err_panic: |
628 | nilfs_write_opt(sbi, ERROR_MODE, ERRORS_PANIC); | 622 | nilfs_write_opt(nilfs, ERROR_MODE, ERRORS_PANIC); |
629 | break; | 623 | break; |
630 | case Opt_err_ro: | 624 | case Opt_err_ro: |
631 | nilfs_write_opt(sbi, ERROR_MODE, ERRORS_RO); | 625 | nilfs_write_opt(nilfs, ERROR_MODE, ERRORS_RO); |
632 | break; | 626 | break; |
633 | case Opt_err_cont: | 627 | case Opt_err_cont: |
634 | nilfs_write_opt(sbi, ERROR_MODE, ERRORS_CONT); | 628 | nilfs_write_opt(nilfs, ERROR_MODE, ERRORS_CONT); |
635 | break; | 629 | break; |
636 | case Opt_snapshot: | 630 | case Opt_snapshot: |
637 | if (is_remount) { | 631 | if (is_remount) { |
@@ -642,13 +636,13 @@ static int parse_options(char *options, struct super_block *sb, int is_remount) | |||
642 | } | 636 | } |
643 | break; | 637 | break; |
644 | case Opt_norecovery: | 638 | case Opt_norecovery: |
645 | nilfs_set_opt(sbi, NORECOVERY); | 639 | nilfs_set_opt(nilfs, NORECOVERY); |
646 | break; | 640 | break; |
647 | case Opt_discard: | 641 | case Opt_discard: |
648 | nilfs_set_opt(sbi, DISCARD); | 642 | nilfs_set_opt(nilfs, DISCARD); |
649 | break; | 643 | break; |
650 | case Opt_nodiscard: | 644 | case Opt_nodiscard: |
651 | nilfs_clear_opt(sbi, DISCARD); | 645 | nilfs_clear_opt(nilfs, DISCARD); |
652 | break; | 646 | break; |
653 | default: | 647 | default: |
654 | printk(KERN_ERR | 648 | printk(KERN_ERR |
@@ -660,22 +654,24 @@ static int parse_options(char *options, struct super_block *sb, int is_remount) | |||
660 | } | 654 | } |
661 | 655 | ||
662 | static inline void | 656 | static inline void |
663 | nilfs_set_default_options(struct nilfs_sb_info *sbi, | 657 | nilfs_set_default_options(struct super_block *sb, |
664 | struct nilfs_super_block *sbp) | 658 | struct nilfs_super_block *sbp) |
665 | { | 659 | { |
666 | sbi->s_mount_opt = | 660 | struct the_nilfs *nilfs = sb->s_fs_info; |
661 | |||
662 | nilfs->ns_mount_opt = | ||
667 | NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER; | 663 | NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER; |
668 | } | 664 | } |
669 | 665 | ||
670 | static int nilfs_setup_super(struct nilfs_sb_info *sbi, int is_mount) | 666 | static int nilfs_setup_super(struct super_block *sb, int is_mount) |
671 | { | 667 | { |
672 | struct the_nilfs *nilfs = sbi->s_nilfs; | 668 | struct the_nilfs *nilfs = sb->s_fs_info; |
673 | struct nilfs_super_block **sbp; | 669 | struct nilfs_super_block **sbp; |
674 | int max_mnt_count; | 670 | int max_mnt_count; |
675 | int mnt_count; | 671 | int mnt_count; |
676 | 672 | ||
677 | /* nilfs->ns_sem must be locked by the caller. */ | 673 | /* nilfs->ns_sem must be locked by the caller. */ |
678 | sbp = nilfs_prepare_super(sbi, 0); | 674 | sbp = nilfs_prepare_super(sb, 0); |
679 | if (!sbp) | 675 | if (!sbp) |
680 | return -EIO; | 676 | return -EIO; |
681 | 677 | ||
@@ -704,8 +700,9 @@ skip_mount_setup: | |||
704 | sbp[0]->s_state = | 700 | sbp[0]->s_state = |
705 | cpu_to_le16(le16_to_cpu(sbp[0]->s_state) & ~NILFS_VALID_FS); | 701 | cpu_to_le16(le16_to_cpu(sbp[0]->s_state) & ~NILFS_VALID_FS); |
706 | /* synchronize sbp[1] with sbp[0] */ | 702 | /* synchronize sbp[1] with sbp[0] */ |
707 | memcpy(sbp[1], sbp[0], nilfs->ns_sbsize); | 703 | if (sbp[1]) |
708 | return nilfs_commit_super(sbi, NILFS_SB_COMMIT_ALL); | 704 | memcpy(sbp[1], sbp[0], nilfs->ns_sbsize); |
705 | return nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL); | ||
709 | } | 706 | } |
710 | 707 | ||
711 | struct nilfs_super_block *nilfs_read_super_block(struct super_block *sb, | 708 | struct nilfs_super_block *nilfs_read_super_block(struct super_block *sb, |
@@ -726,7 +723,7 @@ int nilfs_store_magic_and_option(struct super_block *sb, | |||
726 | struct nilfs_super_block *sbp, | 723 | struct nilfs_super_block *sbp, |
727 | char *data) | 724 | char *data) |
728 | { | 725 | { |
729 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 726 | struct the_nilfs *nilfs = sb->s_fs_info; |
730 | 727 | ||
731 | sb->s_magic = le16_to_cpu(sbp->s_magic); | 728 | sb->s_magic = le16_to_cpu(sbp->s_magic); |
732 | 729 | ||
@@ -735,12 +732,12 @@ int nilfs_store_magic_and_option(struct super_block *sb, | |||
735 | sb->s_flags |= MS_NOATIME; | 732 | sb->s_flags |= MS_NOATIME; |
736 | #endif | 733 | #endif |
737 | 734 | ||
738 | nilfs_set_default_options(sbi, sbp); | 735 | nilfs_set_default_options(sb, sbp); |
739 | 736 | ||
740 | sbi->s_resuid = le16_to_cpu(sbp->s_def_resuid); | 737 | nilfs->ns_resuid = le16_to_cpu(sbp->s_def_resuid); |
741 | sbi->s_resgid = le16_to_cpu(sbp->s_def_resgid); | 738 | nilfs->ns_resgid = le16_to_cpu(sbp->s_def_resgid); |
742 | sbi->s_interval = le32_to_cpu(sbp->s_c_interval); | 739 | nilfs->ns_interval = le32_to_cpu(sbp->s_c_interval); |
743 | sbi->s_watermark = le32_to_cpu(sbp->s_c_block_max); | 740 | nilfs->ns_watermark = le32_to_cpu(sbp->s_c_block_max); |
744 | 741 | ||
745 | return !parse_options(data, sb, 0) ? -EINVAL : 0 ; | 742 | return !parse_options(data, sb, 0) ? -EINVAL : 0 ; |
746 | } | 743 | } |
@@ -821,7 +818,7 @@ static int nilfs_get_root_dentry(struct super_block *sb, | |||
821 | static int nilfs_attach_snapshot(struct super_block *s, __u64 cno, | 818 | static int nilfs_attach_snapshot(struct super_block *s, __u64 cno, |
822 | struct dentry **root_dentry) | 819 | struct dentry **root_dentry) |
823 | { | 820 | { |
824 | struct the_nilfs *nilfs = NILFS_SB(s)->s_nilfs; | 821 | struct the_nilfs *nilfs = s->s_fs_info; |
825 | struct nilfs_root *root; | 822 | struct nilfs_root *root; |
826 | int ret; | 823 | int ret; |
827 | 824 | ||
@@ -839,7 +836,7 @@ static int nilfs_attach_snapshot(struct super_block *s, __u64 cno, | |||
839 | goto out; | 836 | goto out; |
840 | } | 837 | } |
841 | 838 | ||
842 | ret = nilfs_attach_checkpoint(NILFS_SB(s), cno, false, &root); | 839 | ret = nilfs_attach_checkpoint(s, cno, false, &root); |
843 | if (ret) { | 840 | if (ret) { |
844 | printk(KERN_ERR "NILFS: error loading snapshot " | 841 | printk(KERN_ERR "NILFS: error loading snapshot " |
845 | "(checkpoint number=%llu).\n", | 842 | "(checkpoint number=%llu).\n", |
@@ -873,7 +870,7 @@ static int nilfs_try_to_shrink_tree(struct dentry *root_dentry) | |||
873 | 870 | ||
874 | int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno) | 871 | int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno) |
875 | { | 872 | { |
876 | struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs; | 873 | struct the_nilfs *nilfs = sb->s_fs_info; |
877 | struct nilfs_root *root; | 874 | struct nilfs_root *root; |
878 | struct inode *inode; | 875 | struct inode *inode; |
879 | struct dentry *dentry; | 876 | struct dentry *dentry; |
@@ -886,7 +883,7 @@ int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno) | |||
886 | return true; /* protect recent checkpoints */ | 883 | return true; /* protect recent checkpoints */ |
887 | 884 | ||
888 | ret = false; | 885 | ret = false; |
889 | root = nilfs_lookup_root(NILFS_SB(sb)->s_nilfs, cno); | 886 | root = nilfs_lookup_root(nilfs, cno); |
890 | if (root) { | 887 | if (root) { |
891 | inode = nilfs_ilookup(sb, root, NILFS_ROOT_INO); | 888 | inode = nilfs_ilookup(sb, root, NILFS_ROOT_INO); |
892 | if (inode) { | 889 | if (inode) { |
@@ -916,43 +913,21 @@ static int | |||
916 | nilfs_fill_super(struct super_block *sb, void *data, int silent) | 913 | nilfs_fill_super(struct super_block *sb, void *data, int silent) |
917 | { | 914 | { |
918 | struct the_nilfs *nilfs; | 915 | struct the_nilfs *nilfs; |
919 | struct nilfs_sb_info *sbi; | ||
920 | struct nilfs_root *fsroot; | 916 | struct nilfs_root *fsroot; |
921 | struct backing_dev_info *bdi; | 917 | struct backing_dev_info *bdi; |
922 | __u64 cno; | 918 | __u64 cno; |
923 | int err; | 919 | int err; |
924 | 920 | ||
925 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); | 921 | nilfs = alloc_nilfs(sb->s_bdev); |
926 | if (!sbi) | 922 | if (!nilfs) |
927 | return -ENOMEM; | 923 | return -ENOMEM; |
928 | 924 | ||
929 | sb->s_fs_info = sbi; | 925 | sb->s_fs_info = nilfs; |
930 | sbi->s_super = sb; | ||
931 | |||
932 | nilfs = alloc_nilfs(sb->s_bdev); | ||
933 | if (!nilfs) { | ||
934 | err = -ENOMEM; | ||
935 | goto failed_sbi; | ||
936 | } | ||
937 | sbi->s_nilfs = nilfs; | ||
938 | 926 | ||
939 | err = init_nilfs(nilfs, sbi, (char *)data); | 927 | err = init_nilfs(nilfs, sb, (char *)data); |
940 | if (err) | 928 | if (err) |
941 | goto failed_nilfs; | 929 | goto failed_nilfs; |
942 | 930 | ||
943 | spin_lock_init(&sbi->s_inode_lock); | ||
944 | INIT_LIST_HEAD(&sbi->s_dirty_files); | ||
945 | |||
946 | /* | ||
947 | * Following initialization is overlapped because | ||
948 | * nilfs_sb_info structure has been cleared at the beginning. | ||
949 | * But we reserve them to keep our interest and make ready | ||
950 | * for the future change. | ||
951 | */ | ||
952 | get_random_bytes(&sbi->s_next_generation, | ||
953 | sizeof(sbi->s_next_generation)); | ||
954 | spin_lock_init(&sbi->s_next_gen_lock); | ||
955 | |||
956 | sb->s_op = &nilfs_sops; | 931 | sb->s_op = &nilfs_sops; |
957 | sb->s_export_op = &nilfs_export_ops; | 932 | sb->s_export_op = &nilfs_export_ops; |
958 | sb->s_root = NULL; | 933 | sb->s_root = NULL; |
@@ -961,12 +936,12 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent) | |||
961 | bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info; | 936 | bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info; |
962 | sb->s_bdi = bdi ? : &default_backing_dev_info; | 937 | sb->s_bdi = bdi ? : &default_backing_dev_info; |
963 | 938 | ||
964 | err = load_nilfs(nilfs, sbi); | 939 | err = load_nilfs(nilfs, sb); |
965 | if (err) | 940 | if (err) |
966 | goto failed_nilfs; | 941 | goto failed_nilfs; |
967 | 942 | ||
968 | cno = nilfs_last_cno(nilfs); | 943 | cno = nilfs_last_cno(nilfs); |
969 | err = nilfs_attach_checkpoint(sbi, cno, true, &fsroot); | 944 | err = nilfs_attach_checkpoint(sb, cno, true, &fsroot); |
970 | if (err) { | 945 | if (err) { |
971 | printk(KERN_ERR "NILFS: error loading last checkpoint " | 946 | printk(KERN_ERR "NILFS: error loading last checkpoint " |
972 | "(checkpoint number=%llu).\n", (unsigned long long)cno); | 947 | "(checkpoint number=%llu).\n", (unsigned long long)cno); |
@@ -974,7 +949,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent) | |||
974 | } | 949 | } |
975 | 950 | ||
976 | if (!(sb->s_flags & MS_RDONLY)) { | 951 | if (!(sb->s_flags & MS_RDONLY)) { |
977 | err = nilfs_attach_segment_constructor(sbi, fsroot); | 952 | err = nilfs_attach_log_writer(sb, fsroot); |
978 | if (err) | 953 | if (err) |
979 | goto failed_checkpoint; | 954 | goto failed_checkpoint; |
980 | } | 955 | } |
@@ -987,14 +962,14 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent) | |||
987 | 962 | ||
988 | if (!(sb->s_flags & MS_RDONLY)) { | 963 | if (!(sb->s_flags & MS_RDONLY)) { |
989 | down_write(&nilfs->ns_sem); | 964 | down_write(&nilfs->ns_sem); |
990 | nilfs_setup_super(sbi, true); | 965 | nilfs_setup_super(sb, true); |
991 | up_write(&nilfs->ns_sem); | 966 | up_write(&nilfs->ns_sem); |
992 | } | 967 | } |
993 | 968 | ||
994 | return 0; | 969 | return 0; |
995 | 970 | ||
996 | failed_segctor: | 971 | failed_segctor: |
997 | nilfs_detach_segment_constructor(sbi); | 972 | nilfs_detach_log_writer(sb); |
998 | 973 | ||
999 | failed_checkpoint: | 974 | failed_checkpoint: |
1000 | nilfs_put_root(fsroot); | 975 | nilfs_put_root(fsroot); |
@@ -1006,23 +981,18 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent) | |||
1006 | 981 | ||
1007 | failed_nilfs: | 982 | failed_nilfs: |
1008 | destroy_nilfs(nilfs); | 983 | destroy_nilfs(nilfs); |
1009 | |||
1010 | failed_sbi: | ||
1011 | sb->s_fs_info = NULL; | ||
1012 | kfree(sbi); | ||
1013 | return err; | 984 | return err; |
1014 | } | 985 | } |
1015 | 986 | ||
1016 | static int nilfs_remount(struct super_block *sb, int *flags, char *data) | 987 | static int nilfs_remount(struct super_block *sb, int *flags, char *data) |
1017 | { | 988 | { |
1018 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 989 | struct the_nilfs *nilfs = sb->s_fs_info; |
1019 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
1020 | unsigned long old_sb_flags; | 990 | unsigned long old_sb_flags; |
1021 | unsigned long old_mount_opt; | 991 | unsigned long old_mount_opt; |
1022 | int err; | 992 | int err; |
1023 | 993 | ||
1024 | old_sb_flags = sb->s_flags; | 994 | old_sb_flags = sb->s_flags; |
1025 | old_mount_opt = sbi->s_mount_opt; | 995 | old_mount_opt = nilfs->ns_mount_opt; |
1026 | 996 | ||
1027 | if (!parse_options(data, sb, 1)) { | 997 | if (!parse_options(data, sb, 1)) { |
1028 | err = -EINVAL; | 998 | err = -EINVAL; |
@@ -1042,8 +1012,8 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data) | |||
1042 | if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) | 1012 | if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) |
1043 | goto out; | 1013 | goto out; |
1044 | if (*flags & MS_RDONLY) { | 1014 | if (*flags & MS_RDONLY) { |
1045 | /* Shutting down the segment constructor */ | 1015 | /* Shutting down log writer */ |
1046 | nilfs_detach_segment_constructor(sbi); | 1016 | nilfs_detach_log_writer(sb); |
1047 | sb->s_flags |= MS_RDONLY; | 1017 | sb->s_flags |= MS_RDONLY; |
1048 | 1018 | ||
1049 | /* | 1019 | /* |
@@ -1051,7 +1021,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data) | |||
1051 | * the RDONLY flag and then mark the partition as valid again. | 1021 | * the RDONLY flag and then mark the partition as valid again. |
1052 | */ | 1022 | */ |
1053 | down_write(&nilfs->ns_sem); | 1023 | down_write(&nilfs->ns_sem); |
1054 | nilfs_cleanup_super(sbi); | 1024 | nilfs_cleanup_super(sb); |
1055 | up_write(&nilfs->ns_sem); | 1025 | up_write(&nilfs->ns_sem); |
1056 | } else { | 1026 | } else { |
1057 | __u64 features; | 1027 | __u64 features; |
@@ -1078,12 +1048,12 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data) | |||
1078 | sb->s_flags &= ~MS_RDONLY; | 1048 | sb->s_flags &= ~MS_RDONLY; |
1079 | 1049 | ||
1080 | root = NILFS_I(sb->s_root->d_inode)->i_root; | 1050 | root = NILFS_I(sb->s_root->d_inode)->i_root; |
1081 | err = nilfs_attach_segment_constructor(sbi, root); | 1051 | err = nilfs_attach_log_writer(sb, root); |
1082 | if (err) | 1052 | if (err) |
1083 | goto restore_opts; | 1053 | goto restore_opts; |
1084 | 1054 | ||
1085 | down_write(&nilfs->ns_sem); | 1055 | down_write(&nilfs->ns_sem); |
1086 | nilfs_setup_super(sbi, true); | 1056 | nilfs_setup_super(sb, true); |
1087 | up_write(&nilfs->ns_sem); | 1057 | up_write(&nilfs->ns_sem); |
1088 | } | 1058 | } |
1089 | out: | 1059 | out: |
@@ -1091,13 +1061,12 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data) | |||
1091 | 1061 | ||
1092 | restore_opts: | 1062 | restore_opts: |
1093 | sb->s_flags = old_sb_flags; | 1063 | sb->s_flags = old_sb_flags; |
1094 | sbi->s_mount_opt = old_mount_opt; | 1064 | nilfs->ns_mount_opt = old_mount_opt; |
1095 | return err; | 1065 | return err; |
1096 | } | 1066 | } |
1097 | 1067 | ||
1098 | struct nilfs_super_data { | 1068 | struct nilfs_super_data { |
1099 | struct block_device *bdev; | 1069 | struct block_device *bdev; |
1100 | struct nilfs_sb_info *sbi; | ||
1101 | __u64 cno; | 1070 | __u64 cno; |
1102 | int flags; | 1071 | int flags; |
1103 | }; | 1072 | }; |
@@ -1278,7 +1247,7 @@ static void nilfs_inode_init_once(void *obj) | |||
1278 | #ifdef CONFIG_NILFS_XATTR | 1247 | #ifdef CONFIG_NILFS_XATTR |
1279 | init_rwsem(&ii->xattr_sem); | 1248 | init_rwsem(&ii->xattr_sem); |
1280 | #endif | 1249 | #endif |
1281 | nilfs_btnode_cache_init_once(&ii->i_btnode_cache); | 1250 | address_space_init_once(&ii->i_btnode_cache); |
1282 | ii->i_bmap = &ii->i_bmap_data; | 1251 | ii->i_bmap = &ii->i_bmap_data; |
1283 | inode_init_once(&ii->vfs_inode); | 1252 | inode_init_once(&ii->vfs_inode); |
1284 | } | 1253 | } |