.. | .. |
---|
53 | 53 | MODULE_DESCRIPTION("A New Implementation of the Log-structured Filesystem " |
---|
54 | 54 | "(NILFS)"); |
---|
55 | 55 | MODULE_LICENSE("GPL"); |
---|
| 56 | +MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY); |
---|
56 | 57 | |
---|
57 | 58 | static struct kmem_cache *nilfs_inode_cachep; |
---|
58 | 59 | struct kmem_cache *nilfs_transaction_cachep; |
---|
.. | .. |
---|
62 | 63 | static int nilfs_setup_super(struct super_block *sb, int is_mount); |
---|
63 | 64 | static int nilfs_remount(struct super_block *sb, int *flags, char *data); |
---|
64 | 65 | |
---|
65 | | -void __nilfs_msg(struct super_block *sb, const char *level, const char *fmt, |
---|
66 | | - ...) |
---|
| 66 | +void __nilfs_msg(struct super_block *sb, const char *fmt, ...) |
---|
67 | 67 | { |
---|
68 | 68 | struct va_format vaf; |
---|
69 | 69 | va_list args; |
---|
| 70 | + int level; |
---|
70 | 71 | |
---|
71 | 72 | va_start(args, fmt); |
---|
72 | | - vaf.fmt = fmt; |
---|
| 73 | + |
---|
| 74 | + level = printk_get_level(fmt); |
---|
| 75 | + vaf.fmt = printk_skip_level(fmt); |
---|
73 | 76 | vaf.va = &args; |
---|
| 77 | + |
---|
74 | 78 | if (sb) |
---|
75 | | - printk("%sNILFS (%s): %pV\n", level, sb->s_id, &vaf); |
---|
| 79 | + printk("%c%cNILFS (%s): %pV\n", |
---|
| 80 | + KERN_SOH_ASCII, level, sb->s_id, &vaf); |
---|
76 | 81 | else |
---|
77 | | - printk("%sNILFS: %pV\n", level, &vaf); |
---|
| 82 | + printk("%c%cNILFS: %pV\n", |
---|
| 83 | + KERN_SOH_ASCII, level, &vaf); |
---|
| 84 | + |
---|
78 | 85 | va_end(args); |
---|
79 | 86 | } |
---|
80 | 87 | |
---|
.. | .. |
---|
106 | 113 | * |
---|
107 | 114 | * This implements the body of nilfs_error() macro. Normally, |
---|
108 | 115 | * nilfs_error() should be used. As for sustainable errors such as a |
---|
109 | | - * single-shot I/O error, nilfs_msg() should be used instead. |
---|
| 116 | + * single-shot I/O error, nilfs_err() should be used instead. |
---|
110 | 117 | * |
---|
111 | 118 | * Callers should not add a trailing newline since this will do it. |
---|
112 | 119 | */ |
---|
.. | .. |
---|
151 | 158 | ii->i_bh = NULL; |
---|
152 | 159 | ii->i_state = 0; |
---|
153 | 160 | ii->i_cno = 0; |
---|
154 | | - nilfs_mapping_init(&ii->i_btnode_cache, &ii->vfs_inode); |
---|
| 161 | + ii->i_assoc_inode = NULL; |
---|
| 162 | + ii->i_bmap = &ii->i_bmap_data; |
---|
155 | 163 | return &ii->vfs_inode; |
---|
156 | 164 | } |
---|
157 | 165 | |
---|
158 | | -static void nilfs_i_callback(struct rcu_head *head) |
---|
| 166 | +static void nilfs_free_inode(struct inode *inode) |
---|
159 | 167 | { |
---|
160 | | - struct inode *inode = container_of(head, struct inode, i_rcu); |
---|
161 | | - |
---|
162 | 168 | if (nilfs_is_metadata_file_inode(inode)) |
---|
163 | 169 | nilfs_mdt_destroy(inode); |
---|
164 | 170 | |
---|
165 | 171 | kmem_cache_free(nilfs_inode_cachep, NILFS_I(inode)); |
---|
166 | | -} |
---|
167 | | - |
---|
168 | | -void nilfs_destroy_inode(struct inode *inode) |
---|
169 | | -{ |
---|
170 | | - call_rcu(&inode->i_rcu, nilfs_i_callback); |
---|
171 | 172 | } |
---|
172 | 173 | |
---|
173 | 174 | static int nilfs_sync_super(struct super_block *sb, int flag) |
---|
.. | .. |
---|
185 | 186 | } |
---|
186 | 187 | |
---|
187 | 188 | if (unlikely(err)) { |
---|
188 | | - nilfs_msg(sb, KERN_ERR, "unable to write superblock: err=%d", |
---|
189 | | - err); |
---|
| 189 | + nilfs_err(sb, "unable to write superblock: err=%d", err); |
---|
190 | 190 | if (err == -EIO && nilfs->ns_sbh[1]) { |
---|
191 | 191 | /* |
---|
192 | 192 | * sbp[0] points to newer log than sbp[1], |
---|
.. | .. |
---|
256 | 256 | sbp[1]->s_magic == cpu_to_le16(NILFS_SUPER_MAGIC)) { |
---|
257 | 257 | memcpy(sbp[0], sbp[1], nilfs->ns_sbsize); |
---|
258 | 258 | } else { |
---|
259 | | - nilfs_msg(sb, KERN_CRIT, "superblock broke"); |
---|
| 259 | + nilfs_crit(sb, "superblock broke"); |
---|
260 | 260 | return NULL; |
---|
261 | 261 | } |
---|
262 | 262 | } else if (sbp[1] && |
---|
.. | .. |
---|
366 | 366 | offset = sb2off & (nilfs->ns_blocksize - 1); |
---|
367 | 367 | nsbh = sb_getblk(sb, newblocknr); |
---|
368 | 368 | if (!nsbh) { |
---|
369 | | - nilfs_msg(sb, KERN_WARNING, |
---|
370 | | - "unable to move secondary superblock to block %llu", |
---|
371 | | - (unsigned long long)newblocknr); |
---|
| 369 | + nilfs_warn(sb, |
---|
| 370 | + "unable to move secondary superblock to block %llu", |
---|
| 371 | + (unsigned long long)newblocknr); |
---|
372 | 372 | ret = -EIO; |
---|
373 | 373 | goto out; |
---|
374 | 374 | } |
---|
375 | 375 | nsbp = (void *)nsbh->b_data + offset; |
---|
376 | | - memset(nsbp, 0, nilfs->ns_blocksize); |
---|
| 376 | + |
---|
| 377 | + lock_buffer(nsbh); |
---|
| 378 | + if (sb2i >= 0) { |
---|
| 379 | + /* |
---|
| 380 | + * The position of the second superblock only changes by 4KiB, |
---|
| 381 | + * which is larger than the maximum superblock data size |
---|
| 382 | + * (= 1KiB), so there is no need to use memmove() to allow |
---|
| 383 | + * overlap between source and destination. |
---|
| 384 | + */ |
---|
| 385 | + memcpy(nsbp, nilfs->ns_sbp[sb2i], nilfs->ns_sbsize); |
---|
| 386 | + |
---|
| 387 | + /* |
---|
| 388 | + * Zero fill after copy to avoid overwriting in case of move |
---|
| 389 | + * within the same block. |
---|
| 390 | + */ |
---|
| 391 | + memset(nsbh->b_data, 0, offset); |
---|
| 392 | + memset((void *)nsbp + nilfs->ns_sbsize, 0, |
---|
| 393 | + nsbh->b_size - offset - nilfs->ns_sbsize); |
---|
| 394 | + } else { |
---|
| 395 | + memset(nsbh->b_data, 0, nsbh->b_size); |
---|
| 396 | + } |
---|
| 397 | + set_buffer_uptodate(nsbh); |
---|
| 398 | + unlock_buffer(nsbh); |
---|
377 | 399 | |
---|
378 | 400 | if (sb2i >= 0) { |
---|
379 | | - memcpy(nsbp, nilfs->ns_sbp[sb2i], nilfs->ns_sbsize); |
---|
380 | 401 | brelse(nilfs->ns_sbh[sb2i]); |
---|
381 | 402 | nilfs->ns_sbh[sb2i] = nsbh; |
---|
382 | 403 | nilfs->ns_sbp[sb2i] = nsbp; |
---|
.. | .. |
---|
408 | 429 | devsize = i_size_read(sb->s_bdev->bd_inode); |
---|
409 | 430 | if (newsize > devsize) |
---|
410 | 431 | goto out; |
---|
| 432 | + |
---|
| 433 | + /* |
---|
| 434 | + * Prevent underflow in second superblock position calculation. |
---|
| 435 | + * The exact minimum size check is done in nilfs_sufile_resize(). |
---|
| 436 | + */ |
---|
| 437 | + if (newsize < 4096) { |
---|
| 438 | + ret = -ENOSPC; |
---|
| 439 | + goto out; |
---|
| 440 | + } |
---|
411 | 441 | |
---|
412 | 442 | /* |
---|
413 | 443 | * Write lock is required to protect some functions depending |
---|
.. | .. |
---|
474 | 504 | up_write(&nilfs->ns_sem); |
---|
475 | 505 | } |
---|
476 | 506 | |
---|
| 507 | + nilfs_sysfs_delete_device_group(nilfs); |
---|
477 | 508 | iput(nilfs->ns_sufile); |
---|
478 | 509 | iput(nilfs->ns_cpfile); |
---|
479 | 510 | iput(nilfs->ns_dat); |
---|
.. | .. |
---|
531 | 562 | up_read(&nilfs->ns_segctor_sem); |
---|
532 | 563 | if (unlikely(err)) { |
---|
533 | 564 | if (err == -ENOENT || err == -EINVAL) { |
---|
534 | | - nilfs_msg(sb, KERN_ERR, |
---|
| 565 | + nilfs_err(sb, |
---|
535 | 566 | "Invalid checkpoint (checkpoint number=%llu)", |
---|
536 | 567 | (unsigned long long)cno); |
---|
537 | 568 | err = -EINVAL; |
---|
.. | .. |
---|
629 | 660 | err = nilfs_ifile_count_free_inodes(root->ifile, |
---|
630 | 661 | &nmaxinodes, &nfreeinodes); |
---|
631 | 662 | if (unlikely(err)) { |
---|
632 | | - nilfs_msg(sb, KERN_WARNING, |
---|
633 | | - "failed to count free inodes: err=%d", err); |
---|
| 663 | + nilfs_warn(sb, "failed to count free inodes: err=%d", err); |
---|
634 | 664 | if (err == -ERANGE) { |
---|
635 | 665 | /* |
---|
636 | 666 | * If nilfs_palloc_count_max_entries() returns |
---|
.. | .. |
---|
654 | 684 | buf->f_files = nmaxinodes; |
---|
655 | 685 | buf->f_ffree = nfreeinodes; |
---|
656 | 686 | buf->f_namelen = NILFS_NAME_LEN; |
---|
657 | | - buf->f_fsid.val[0] = (u32)id; |
---|
658 | | - buf->f_fsid.val[1] = (u32)(id >> 32); |
---|
| 687 | + buf->f_fsid = u64_to_fsid(id); |
---|
659 | 688 | |
---|
660 | 689 | return 0; |
---|
661 | 690 | } |
---|
.. | .. |
---|
686 | 715 | |
---|
687 | 716 | static const struct super_operations nilfs_sops = { |
---|
688 | 717 | .alloc_inode = nilfs_alloc_inode, |
---|
689 | | - .destroy_inode = nilfs_destroy_inode, |
---|
| 718 | + .free_inode = nilfs_free_inode, |
---|
690 | 719 | .dirty_inode = nilfs_dirty_inode, |
---|
691 | 720 | .evict_inode = nilfs_evict_inode, |
---|
692 | 721 | .put_super = nilfs_put_super, |
---|
.. | .. |
---|
762 | 791 | break; |
---|
763 | 792 | case Opt_snapshot: |
---|
764 | 793 | if (is_remount) { |
---|
765 | | - nilfs_msg(sb, KERN_ERR, |
---|
| 794 | + nilfs_err(sb, |
---|
766 | 795 | "\"%s\" option is invalid for remount", |
---|
767 | 796 | p); |
---|
768 | 797 | return 0; |
---|
.. | .. |
---|
778 | 807 | nilfs_clear_opt(nilfs, DISCARD); |
---|
779 | 808 | break; |
---|
780 | 809 | default: |
---|
781 | | - nilfs_msg(sb, KERN_ERR, |
---|
782 | | - "unrecognized mount option \"%s\"", p); |
---|
| 810 | + nilfs_err(sb, "unrecognized mount option \"%s\"", p); |
---|
783 | 811 | return 0; |
---|
784 | 812 | } |
---|
785 | 813 | } |
---|
.. | .. |
---|
815 | 843 | mnt_count = le16_to_cpu(sbp[0]->s_mnt_count); |
---|
816 | 844 | |
---|
817 | 845 | if (nilfs->ns_mount_state & NILFS_ERROR_FS) { |
---|
818 | | - nilfs_msg(sb, KERN_WARNING, "mounting fs with errors"); |
---|
| 846 | + nilfs_warn(sb, "mounting fs with errors"); |
---|
819 | 847 | #if 0 |
---|
820 | 848 | } else if (max_mnt_count >= 0 && mnt_count >= max_mnt_count) { |
---|
821 | | - nilfs_msg(sb, KERN_WARNING, "maximal mount count reached"); |
---|
| 849 | + nilfs_warn(sb, "maximal mount count reached"); |
---|
822 | 850 | #endif |
---|
823 | 851 | } |
---|
824 | 852 | if (!max_mnt_count) |
---|
.. | .. |
---|
881 | 909 | features = le64_to_cpu(sbp->s_feature_incompat) & |
---|
882 | 910 | ~NILFS_FEATURE_INCOMPAT_SUPP; |
---|
883 | 911 | if (features) { |
---|
884 | | - nilfs_msg(sb, KERN_ERR, |
---|
| 912 | + nilfs_err(sb, |
---|
885 | 913 | "couldn't mount because of unsupported optional features (%llx)", |
---|
886 | 914 | (unsigned long long)features); |
---|
887 | 915 | return -EINVAL; |
---|
.. | .. |
---|
889 | 917 | features = le64_to_cpu(sbp->s_feature_compat_ro) & |
---|
890 | 918 | ~NILFS_FEATURE_COMPAT_RO_SUPP; |
---|
891 | 919 | if (!sb_rdonly(sb) && features) { |
---|
892 | | - nilfs_msg(sb, KERN_ERR, |
---|
| 920 | + nilfs_err(sb, |
---|
893 | 921 | "couldn't mount RDWR because of unsupported optional features (%llx)", |
---|
894 | 922 | (unsigned long long)features); |
---|
895 | 923 | return -EINVAL; |
---|
.. | .. |
---|
908 | 936 | inode = nilfs_iget(sb, root, NILFS_ROOT_INO); |
---|
909 | 937 | if (IS_ERR(inode)) { |
---|
910 | 938 | ret = PTR_ERR(inode); |
---|
911 | | - nilfs_msg(sb, KERN_ERR, "error %d getting root inode", ret); |
---|
| 939 | + nilfs_err(sb, "error %d getting root inode", ret); |
---|
912 | 940 | goto out; |
---|
913 | 941 | } |
---|
914 | 942 | if (!S_ISDIR(inode->i_mode) || !inode->i_blocks || !inode->i_size) { |
---|
915 | 943 | iput(inode); |
---|
916 | | - nilfs_msg(sb, KERN_ERR, "corrupt root inode"); |
---|
| 944 | + nilfs_err(sb, "corrupt root inode"); |
---|
917 | 945 | ret = -EINVAL; |
---|
918 | 946 | goto out; |
---|
919 | 947 | } |
---|
.. | .. |
---|
941 | 969 | return ret; |
---|
942 | 970 | |
---|
943 | 971 | failed_dentry: |
---|
944 | | - nilfs_msg(sb, KERN_ERR, "error %d getting root dentry", ret); |
---|
| 972 | + nilfs_err(sb, "error %d getting root dentry", ret); |
---|
945 | 973 | goto out; |
---|
946 | 974 | } |
---|
947 | 975 | |
---|
.. | .. |
---|
961 | 989 | ret = (ret == -ENOENT) ? -EINVAL : ret; |
---|
962 | 990 | goto out; |
---|
963 | 991 | } else if (!ret) { |
---|
964 | | - nilfs_msg(s, KERN_ERR, |
---|
| 992 | + nilfs_err(s, |
---|
965 | 993 | "The specified checkpoint is not a snapshot (checkpoint number=%llu)", |
---|
966 | 994 | (unsigned long long)cno); |
---|
967 | 995 | ret = -EINVAL; |
---|
.. | .. |
---|
970 | 998 | |
---|
971 | 999 | ret = nilfs_attach_checkpoint(s, cno, false, &root); |
---|
972 | 1000 | if (ret) { |
---|
973 | | - nilfs_msg(s, KERN_ERR, |
---|
| 1001 | + nilfs_err(s, |
---|
974 | 1002 | "error %d while loading snapshot (checkpoint number=%llu)", |
---|
975 | 1003 | ret, (unsigned long long)cno); |
---|
976 | 1004 | goto out; |
---|
.. | .. |
---|
1067 | 1095 | cno = nilfs_last_cno(nilfs); |
---|
1068 | 1096 | err = nilfs_attach_checkpoint(sb, cno, true, &fsroot); |
---|
1069 | 1097 | if (err) { |
---|
1070 | | - nilfs_msg(sb, KERN_ERR, |
---|
| 1098 | + nilfs_err(sb, |
---|
1071 | 1099 | "error %d while loading last checkpoint (checkpoint number=%llu)", |
---|
1072 | 1100 | err, (unsigned long long)cno); |
---|
1073 | 1101 | goto failed_unload; |
---|
.. | .. |
---|
1100 | 1128 | nilfs_put_root(fsroot); |
---|
1101 | 1129 | |
---|
1102 | 1130 | failed_unload: |
---|
| 1131 | + nilfs_sysfs_delete_device_group(nilfs); |
---|
1103 | 1132 | iput(nilfs->ns_sufile); |
---|
1104 | 1133 | iput(nilfs->ns_cpfile); |
---|
1105 | 1134 | iput(nilfs->ns_dat); |
---|
.. | .. |
---|
1129 | 1158 | err = -EINVAL; |
---|
1130 | 1159 | |
---|
1131 | 1160 | if (!nilfs_valid_fs(nilfs)) { |
---|
1132 | | - nilfs_msg(sb, KERN_WARNING, |
---|
1133 | | - "couldn't remount because the filesystem is in an incomplete recovery state"); |
---|
| 1161 | + nilfs_warn(sb, |
---|
| 1162 | + "couldn't remount because the filesystem is in an incomplete recovery state"); |
---|
1134 | 1163 | goto restore_opts; |
---|
1135 | 1164 | } |
---|
1136 | 1165 | |
---|
1137 | 1166 | if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb)) |
---|
1138 | 1167 | goto out; |
---|
1139 | 1168 | if (*flags & SB_RDONLY) { |
---|
1140 | | - /* Shutting down log writer */ |
---|
1141 | | - nilfs_detach_log_writer(sb); |
---|
1142 | 1169 | sb->s_flags |= SB_RDONLY; |
---|
1143 | 1170 | |
---|
1144 | 1171 | /* |
---|
.. | .. |
---|
1162 | 1189 | ~NILFS_FEATURE_COMPAT_RO_SUPP; |
---|
1163 | 1190 | up_read(&nilfs->ns_sem); |
---|
1164 | 1191 | if (features) { |
---|
1165 | | - nilfs_msg(sb, KERN_WARNING, |
---|
1166 | | - "couldn't remount RDWR because of unsupported optional features (%llx)", |
---|
1167 | | - (unsigned long long)features); |
---|
| 1192 | + nilfs_warn(sb, |
---|
| 1193 | + "couldn't remount RDWR because of unsupported optional features (%llx)", |
---|
| 1194 | + (unsigned long long)features); |
---|
1168 | 1195 | err = -EROFS; |
---|
1169 | 1196 | goto restore_opts; |
---|
1170 | 1197 | } |
---|
.. | .. |
---|
1223 | 1250 | return 0; |
---|
1224 | 1251 | |
---|
1225 | 1252 | parse_error: |
---|
1226 | | - nilfs_msg(NULL, KERN_ERR, "invalid option \"%s\": %s", option, msg); |
---|
| 1253 | + nilfs_err(NULL, "invalid option \"%s\": %s", option, msg); |
---|
1227 | 1254 | return 1; |
---|
1228 | 1255 | } |
---|
1229 | 1256 | |
---|
.. | .. |
---|
1326 | 1353 | } else if (!sd.cno) { |
---|
1327 | 1354 | if (nilfs_tree_is_busy(s->s_root)) { |
---|
1328 | 1355 | if ((flags ^ s->s_flags) & SB_RDONLY) { |
---|
1329 | | - nilfs_msg(s, KERN_ERR, |
---|
| 1356 | + nilfs_err(s, |
---|
1330 | 1357 | "the device already has a %s mount.", |
---|
1331 | 1358 | sb_rdonly(s) ? "read-only" : "read/write"); |
---|
1332 | 1359 | err = -EBUSY; |
---|
.. | .. |
---|
1382 | 1409 | #ifdef CONFIG_NILFS_XATTR |
---|
1383 | 1410 | init_rwsem(&ii->xattr_sem); |
---|
1384 | 1411 | #endif |
---|
1385 | | - address_space_init_once(&ii->i_btnode_cache); |
---|
1386 | | - ii->i_bmap = &ii->i_bmap_data; |
---|
1387 | 1412 | inode_init_once(&ii->vfs_inode); |
---|
1388 | 1413 | } |
---|
1389 | 1414 | |
---|