diff options
Diffstat (limited to 'fs/nilfs2/super.c')
-rw-r--r-- | fs/nilfs2/super.c | 214 |
1 files changed, 91 insertions, 123 deletions
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c index 1673b3d99842..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 | ||
@@ -706,7 +702,7 @@ skip_mount_setup: | |||
706 | /* synchronize sbp[1] with sbp[0] */ | 702 | /* synchronize sbp[1] with sbp[0] */ |
707 | if (sbp[1]) | 703 | if (sbp[1]) |
708 | memcpy(sbp[1], sbp[0], nilfs->ns_sbsize); | 704 | memcpy(sbp[1], sbp[0], nilfs->ns_sbsize); |
709 | return nilfs_commit_super(sbi, NILFS_SB_COMMIT_ALL); | 705 | return nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL); |
710 | } | 706 | } |
711 | 707 | ||
712 | 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, |
@@ -727,7 +723,7 @@ int nilfs_store_magic_and_option(struct super_block *sb, | |||
727 | struct nilfs_super_block *sbp, | 723 | struct nilfs_super_block *sbp, |
728 | char *data) | 724 | char *data) |
729 | { | 725 | { |
730 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 726 | struct the_nilfs *nilfs = sb->s_fs_info; |
731 | 727 | ||
732 | sb->s_magic = le16_to_cpu(sbp->s_magic); | 728 | sb->s_magic = le16_to_cpu(sbp->s_magic); |
733 | 729 | ||
@@ -736,12 +732,12 @@ int nilfs_store_magic_and_option(struct super_block *sb, | |||
736 | sb->s_flags |= MS_NOATIME; | 732 | sb->s_flags |= MS_NOATIME; |
737 | #endif | 733 | #endif |
738 | 734 | ||
739 | nilfs_set_default_options(sbi, sbp); | 735 | nilfs_set_default_options(sb, sbp); |
740 | 736 | ||
741 | sbi->s_resuid = le16_to_cpu(sbp->s_def_resuid); | 737 | nilfs->ns_resuid = le16_to_cpu(sbp->s_def_resuid); |
742 | sbi->s_resgid = le16_to_cpu(sbp->s_def_resgid); | 738 | nilfs->ns_resgid = le16_to_cpu(sbp->s_def_resgid); |
743 | sbi->s_interval = le32_to_cpu(sbp->s_c_interval); | 739 | nilfs->ns_interval = le32_to_cpu(sbp->s_c_interval); |
744 | sbi->s_watermark = le32_to_cpu(sbp->s_c_block_max); | 740 | nilfs->ns_watermark = le32_to_cpu(sbp->s_c_block_max); |
745 | 741 | ||
746 | return !parse_options(data, sb, 0) ? -EINVAL : 0 ; | 742 | return !parse_options(data, sb, 0) ? -EINVAL : 0 ; |
747 | } | 743 | } |
@@ -822,7 +818,7 @@ static int nilfs_get_root_dentry(struct super_block *sb, | |||
822 | static int nilfs_attach_snapshot(struct super_block *s, __u64 cno, | 818 | static int nilfs_attach_snapshot(struct super_block *s, __u64 cno, |
823 | struct dentry **root_dentry) | 819 | struct dentry **root_dentry) |
824 | { | 820 | { |
825 | struct the_nilfs *nilfs = NILFS_SB(s)->s_nilfs; | 821 | struct the_nilfs *nilfs = s->s_fs_info; |
826 | struct nilfs_root *root; | 822 | struct nilfs_root *root; |
827 | int ret; | 823 | int ret; |
828 | 824 | ||
@@ -840,7 +836,7 @@ static int nilfs_attach_snapshot(struct super_block *s, __u64 cno, | |||
840 | goto out; | 836 | goto out; |
841 | } | 837 | } |
842 | 838 | ||
843 | ret = nilfs_attach_checkpoint(NILFS_SB(s), cno, false, &root); | 839 | ret = nilfs_attach_checkpoint(s, cno, false, &root); |
844 | if (ret) { | 840 | if (ret) { |
845 | printk(KERN_ERR "NILFS: error loading snapshot " | 841 | printk(KERN_ERR "NILFS: error loading snapshot " |
846 | "(checkpoint number=%llu).\n", | 842 | "(checkpoint number=%llu).\n", |
@@ -874,7 +870,7 @@ static int nilfs_try_to_shrink_tree(struct dentry *root_dentry) | |||
874 | 870 | ||
875 | int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno) | 871 | int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno) |
876 | { | 872 | { |
877 | struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs; | 873 | struct the_nilfs *nilfs = sb->s_fs_info; |
878 | struct nilfs_root *root; | 874 | struct nilfs_root *root; |
879 | struct inode *inode; | 875 | struct inode *inode; |
880 | struct dentry *dentry; | 876 | struct dentry *dentry; |
@@ -887,7 +883,7 @@ int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno) | |||
887 | return true; /* protect recent checkpoints */ | 883 | return true; /* protect recent checkpoints */ |
888 | 884 | ||
889 | ret = false; | 885 | ret = false; |
890 | root = nilfs_lookup_root(NILFS_SB(sb)->s_nilfs, cno); | 886 | root = nilfs_lookup_root(nilfs, cno); |
891 | if (root) { | 887 | if (root) { |
892 | inode = nilfs_ilookup(sb, root, NILFS_ROOT_INO); | 888 | inode = nilfs_ilookup(sb, root, NILFS_ROOT_INO); |
893 | if (inode) { | 889 | if (inode) { |
@@ -917,43 +913,21 @@ static int | |||
917 | nilfs_fill_super(struct super_block *sb, void *data, int silent) | 913 | nilfs_fill_super(struct super_block *sb, void *data, int silent) |
918 | { | 914 | { |
919 | struct the_nilfs *nilfs; | 915 | struct the_nilfs *nilfs; |
920 | struct nilfs_sb_info *sbi; | ||
921 | struct nilfs_root *fsroot; | 916 | struct nilfs_root *fsroot; |
922 | struct backing_dev_info *bdi; | 917 | struct backing_dev_info *bdi; |
923 | __u64 cno; | 918 | __u64 cno; |
924 | int err; | 919 | int err; |
925 | 920 | ||
926 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); | 921 | nilfs = alloc_nilfs(sb->s_bdev); |
927 | if (!sbi) | 922 | if (!nilfs) |
928 | return -ENOMEM; | 923 | return -ENOMEM; |
929 | 924 | ||
930 | sb->s_fs_info = sbi; | 925 | sb->s_fs_info = nilfs; |
931 | sbi->s_super = sb; | ||
932 | |||
933 | nilfs = alloc_nilfs(sb->s_bdev); | ||
934 | if (!nilfs) { | ||
935 | err = -ENOMEM; | ||
936 | goto failed_sbi; | ||
937 | } | ||
938 | sbi->s_nilfs = nilfs; | ||
939 | 926 | ||
940 | err = init_nilfs(nilfs, sbi, (char *)data); | 927 | err = init_nilfs(nilfs, sb, (char *)data); |
941 | if (err) | 928 | if (err) |
942 | goto failed_nilfs; | 929 | goto failed_nilfs; |
943 | 930 | ||
944 | spin_lock_init(&sbi->s_inode_lock); | ||
945 | INIT_LIST_HEAD(&sbi->s_dirty_files); | ||
946 | |||
947 | /* | ||
948 | * Following initialization is overlapped because | ||
949 | * nilfs_sb_info structure has been cleared at the beginning. | ||
950 | * But we reserve them to keep our interest and make ready | ||
951 | * for the future change. | ||
952 | */ | ||
953 | get_random_bytes(&sbi->s_next_generation, | ||
954 | sizeof(sbi->s_next_generation)); | ||
955 | spin_lock_init(&sbi->s_next_gen_lock); | ||
956 | |||
957 | sb->s_op = &nilfs_sops; | 931 | sb->s_op = &nilfs_sops; |
958 | sb->s_export_op = &nilfs_export_ops; | 932 | sb->s_export_op = &nilfs_export_ops; |
959 | sb->s_root = NULL; | 933 | sb->s_root = NULL; |
@@ -962,12 +936,12 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent) | |||
962 | bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info; | 936 | bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info; |
963 | sb->s_bdi = bdi ? : &default_backing_dev_info; | 937 | sb->s_bdi = bdi ? : &default_backing_dev_info; |
964 | 938 | ||
965 | err = load_nilfs(nilfs, sbi); | 939 | err = load_nilfs(nilfs, sb); |
966 | if (err) | 940 | if (err) |
967 | goto failed_nilfs; | 941 | goto failed_nilfs; |
968 | 942 | ||
969 | cno = nilfs_last_cno(nilfs); | 943 | cno = nilfs_last_cno(nilfs); |
970 | err = nilfs_attach_checkpoint(sbi, cno, true, &fsroot); | 944 | err = nilfs_attach_checkpoint(sb, cno, true, &fsroot); |
971 | if (err) { | 945 | if (err) { |
972 | printk(KERN_ERR "NILFS: error loading last checkpoint " | 946 | printk(KERN_ERR "NILFS: error loading last checkpoint " |
973 | "(checkpoint number=%llu).\n", (unsigned long long)cno); | 947 | "(checkpoint number=%llu).\n", (unsigned long long)cno); |
@@ -975,7 +949,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent) | |||
975 | } | 949 | } |
976 | 950 | ||
977 | if (!(sb->s_flags & MS_RDONLY)) { | 951 | if (!(sb->s_flags & MS_RDONLY)) { |
978 | err = nilfs_attach_segment_constructor(sbi, fsroot); | 952 | err = nilfs_attach_log_writer(sb, fsroot); |
979 | if (err) | 953 | if (err) |
980 | goto failed_checkpoint; | 954 | goto failed_checkpoint; |
981 | } | 955 | } |
@@ -988,14 +962,14 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent) | |||
988 | 962 | ||
989 | if (!(sb->s_flags & MS_RDONLY)) { | 963 | if (!(sb->s_flags & MS_RDONLY)) { |
990 | down_write(&nilfs->ns_sem); | 964 | down_write(&nilfs->ns_sem); |
991 | nilfs_setup_super(sbi, true); | 965 | nilfs_setup_super(sb, true); |
992 | up_write(&nilfs->ns_sem); | 966 | up_write(&nilfs->ns_sem); |
993 | } | 967 | } |
994 | 968 | ||
995 | return 0; | 969 | return 0; |
996 | 970 | ||
997 | failed_segctor: | 971 | failed_segctor: |
998 | nilfs_detach_segment_constructor(sbi); | 972 | nilfs_detach_log_writer(sb); |
999 | 973 | ||
1000 | failed_checkpoint: | 974 | failed_checkpoint: |
1001 | nilfs_put_root(fsroot); | 975 | nilfs_put_root(fsroot); |
@@ -1007,23 +981,18 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent) | |||
1007 | 981 | ||
1008 | failed_nilfs: | 982 | failed_nilfs: |
1009 | destroy_nilfs(nilfs); | 983 | destroy_nilfs(nilfs); |
1010 | |||
1011 | failed_sbi: | ||
1012 | sb->s_fs_info = NULL; | ||
1013 | kfree(sbi); | ||
1014 | return err; | 984 | return err; |
1015 | } | 985 | } |
1016 | 986 | ||
1017 | 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) |
1018 | { | 988 | { |
1019 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 989 | struct the_nilfs *nilfs = sb->s_fs_info; |
1020 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
1021 | unsigned long old_sb_flags; | 990 | unsigned long old_sb_flags; |
1022 | unsigned long old_mount_opt; | 991 | unsigned long old_mount_opt; |
1023 | int err; | 992 | int err; |
1024 | 993 | ||
1025 | old_sb_flags = sb->s_flags; | 994 | old_sb_flags = sb->s_flags; |
1026 | old_mount_opt = sbi->s_mount_opt; | 995 | old_mount_opt = nilfs->ns_mount_opt; |
1027 | 996 | ||
1028 | if (!parse_options(data, sb, 1)) { | 997 | if (!parse_options(data, sb, 1)) { |
1029 | err = -EINVAL; | 998 | err = -EINVAL; |
@@ -1043,8 +1012,8 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data) | |||
1043 | if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) | 1012 | if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) |
1044 | goto out; | 1013 | goto out; |
1045 | if (*flags & MS_RDONLY) { | 1014 | if (*flags & MS_RDONLY) { |
1046 | /* Shutting down the segment constructor */ | 1015 | /* Shutting down log writer */ |
1047 | nilfs_detach_segment_constructor(sbi); | 1016 | nilfs_detach_log_writer(sb); |
1048 | sb->s_flags |= MS_RDONLY; | 1017 | sb->s_flags |= MS_RDONLY; |
1049 | 1018 | ||
1050 | /* | 1019 | /* |
@@ -1052,7 +1021,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data) | |||
1052 | * the RDONLY flag and then mark the partition as valid again. | 1021 | * the RDONLY flag and then mark the partition as valid again. |
1053 | */ | 1022 | */ |
1054 | down_write(&nilfs->ns_sem); | 1023 | down_write(&nilfs->ns_sem); |
1055 | nilfs_cleanup_super(sbi); | 1024 | nilfs_cleanup_super(sb); |
1056 | up_write(&nilfs->ns_sem); | 1025 | up_write(&nilfs->ns_sem); |
1057 | } else { | 1026 | } else { |
1058 | __u64 features; | 1027 | __u64 features; |
@@ -1079,12 +1048,12 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data) | |||
1079 | sb->s_flags &= ~MS_RDONLY; | 1048 | sb->s_flags &= ~MS_RDONLY; |
1080 | 1049 | ||
1081 | root = NILFS_I(sb->s_root->d_inode)->i_root; | 1050 | root = NILFS_I(sb->s_root->d_inode)->i_root; |
1082 | err = nilfs_attach_segment_constructor(sbi, root); | 1051 | err = nilfs_attach_log_writer(sb, root); |
1083 | if (err) | 1052 | if (err) |
1084 | goto restore_opts; | 1053 | goto restore_opts; |
1085 | 1054 | ||
1086 | down_write(&nilfs->ns_sem); | 1055 | down_write(&nilfs->ns_sem); |
1087 | nilfs_setup_super(sbi, true); | 1056 | nilfs_setup_super(sb, true); |
1088 | up_write(&nilfs->ns_sem); | 1057 | up_write(&nilfs->ns_sem); |
1089 | } | 1058 | } |
1090 | out: | 1059 | out: |
@@ -1092,13 +1061,12 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data) | |||
1092 | 1061 | ||
1093 | restore_opts: | 1062 | restore_opts: |
1094 | sb->s_flags = old_sb_flags; | 1063 | sb->s_flags = old_sb_flags; |
1095 | sbi->s_mount_opt = old_mount_opt; | 1064 | nilfs->ns_mount_opt = old_mount_opt; |
1096 | return err; | 1065 | return err; |
1097 | } | 1066 | } |
1098 | 1067 | ||
1099 | struct nilfs_super_data { | 1068 | struct nilfs_super_data { |
1100 | struct block_device *bdev; | 1069 | struct block_device *bdev; |
1101 | struct nilfs_sb_info *sbi; | ||
1102 | __u64 cno; | 1070 | __u64 cno; |
1103 | int flags; | 1071 | int flags; |
1104 | }; | 1072 | }; |