hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/ocfs2/super.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* -*- mode: c; c-basic-offset: 8; -*-
23 * vim: noexpandtab sw=8 ts=8 sts=0:
34 *
....@@ -6,21 +7,6 @@
67 * load/unload driver, mount/dismount volumes
78 *
89 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
9
- *
10
- * This program is free software; you can redistribute it and/or
11
- * modify it under the terms of the GNU General Public
12
- * License as published by the Free Software Foundation; either
13
- * version 2 of the License, or (at your option) any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
- * General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public
21
- * License along with this program; if not, write to the
22
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23
- * Boston, MA 021110-1307, USA.
2410 */
2511
2612 #include <linux/module.h>
....@@ -85,6 +71,7 @@
8571
8672 MODULE_AUTHOR("Oracle");
8773 MODULE_LICENSE("GPL");
74
+MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
8875 MODULE_DESCRIPTION("OCFS2 cluster file system");
8976
9077 struct mount_options
....@@ -134,7 +121,7 @@
134121 int block,
135122 int sect_size);
136123 static struct inode *ocfs2_alloc_inode(struct super_block *sb);
137
-static void ocfs2_destroy_inode(struct inode *inode);
124
+static void ocfs2_free_inode(struct inode *inode);
138125 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
139126 static int ocfs2_enable_quotas(struct ocfs2_super *osb);
140127 static void ocfs2_disable_quotas(struct ocfs2_super *osb);
....@@ -147,7 +134,7 @@
147134 static const struct super_operations ocfs2_sops = {
148135 .statfs = ocfs2_statfs,
149136 .alloc_inode = ocfs2_alloc_inode,
150
- .destroy_inode = ocfs2_destroy_inode,
137
+ .free_inode = ocfs2_free_inode,
151138 .drop_inode = ocfs2_drop_inode,
152139 .evict_inode = ocfs2_evict_inode,
153140 .sync_fs = ocfs2_sync_fs,
....@@ -234,31 +221,31 @@
234221 int i, out = 0;
235222 unsigned long flags;
236223
237
- out += snprintf(buf + out, len - out,
224
+ out += scnprintf(buf + out, len - out,
238225 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
239226 "Device", osb->dev_str, osb->uuid_str,
240227 osb->fs_generation, osb->vol_label);
241228
242
- out += snprintf(buf + out, len - out,
229
+ out += scnprintf(buf + out, len - out,
243230 "%10s => State: %d Flags: 0x%lX\n", "Volume",
244231 atomic_read(&osb->vol_state), osb->osb_flags);
245232
246
- out += snprintf(buf + out, len - out,
233
+ out += scnprintf(buf + out, len - out,
247234 "%10s => Block: %lu Cluster: %d\n", "Sizes",
248235 osb->sb->s_blocksize, osb->s_clustersize);
249236
250
- out += snprintf(buf + out, len - out,
237
+ out += scnprintf(buf + out, len - out,
251238 "%10s => Compat: 0x%X Incompat: 0x%X "
252239 "ROcompat: 0x%X\n",
253240 "Features", osb->s_feature_compat,
254241 osb->s_feature_incompat, osb->s_feature_ro_compat);
255242
256
- out += snprintf(buf + out, len - out,
243
+ out += scnprintf(buf + out, len - out,
257244 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
258245 osb->s_mount_opt, osb->s_atime_quantum);
259246
260247 if (cconn) {
261
- out += snprintf(buf + out, len - out,
248
+ out += scnprintf(buf + out, len - out,
262249 "%10s => Stack: %s Name: %*s "
263250 "Version: %d.%d\n", "Cluster",
264251 (*osb->osb_cluster_stack == '\0' ?
....@@ -269,7 +256,7 @@
269256 }
270257
271258 spin_lock_irqsave(&osb->dc_task_lock, flags);
272
- out += snprintf(buf + out, len - out,
259
+ out += scnprintf(buf + out, len - out,
273260 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
274261 "WorkSeq: %lu\n", "DownCnvt",
275262 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
....@@ -278,32 +265,32 @@
278265 spin_unlock_irqrestore(&osb->dc_task_lock, flags);
279266
280267 spin_lock(&osb->osb_lock);
281
- out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
268
+ out += scnprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
282269 "Recovery",
283270 (osb->recovery_thread_task ?
284271 task_pid_nr(osb->recovery_thread_task) : -1));
285272 if (rm->rm_used == 0)
286
- out += snprintf(buf + out, len - out, " None\n");
273
+ out += scnprintf(buf + out, len - out, " None\n");
287274 else {
288275 for (i = 0; i < rm->rm_used; i++)
289
- out += snprintf(buf + out, len - out, " %d",
276
+ out += scnprintf(buf + out, len - out, " %d",
290277 rm->rm_entries[i]);
291
- out += snprintf(buf + out, len - out, "\n");
278
+ out += scnprintf(buf + out, len - out, "\n");
292279 }
293280 spin_unlock(&osb->osb_lock);
294281
295
- out += snprintf(buf + out, len - out,
282
+ out += scnprintf(buf + out, len - out,
296283 "%10s => Pid: %d Interval: %lu\n", "Commit",
297284 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
298285 osb->osb_commit_interval);
299286
300
- out += snprintf(buf + out, len - out,
287
+ out += scnprintf(buf + out, len - out,
301288 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
302289 "Journal", osb->journal->j_state,
303290 osb->journal->j_trans_id,
304291 atomic_read(&osb->journal->j_num_trans));
305292
306
- out += snprintf(buf + out, len - out,
293
+ out += scnprintf(buf + out, len - out,
307294 "%10s => GlobalAllocs: %d LocalAllocs: %d "
308295 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
309296 "Stats",
....@@ -313,7 +300,7 @@
313300 atomic_read(&osb->alloc_stats.moves),
314301 atomic_read(&osb->alloc_stats.bg_extends));
315302
316
- out += snprintf(buf + out, len - out,
303
+ out += scnprintf(buf + out, len - out,
317304 "%10s => State: %u Descriptor: %llu Size: %u bits "
318305 "Default: %u bits\n",
319306 "LocalAlloc", osb->local_alloc_state,
....@@ -321,7 +308,7 @@
321308 osb->local_alloc_bits, osb->local_alloc_default_bits);
322309
323310 spin_lock(&osb->osb_lock);
324
- out += snprintf(buf + out, len - out,
311
+ out += scnprintf(buf + out, len - out,
325312 "%10s => InodeSlot: %d StolenInodes: %d, "
326313 "MetaSlot: %d StolenMeta: %d\n", "Steal",
327314 osb->s_inode_steal_slot,
....@@ -330,20 +317,20 @@
330317 atomic_read(&osb->s_num_meta_stolen));
331318 spin_unlock(&osb->osb_lock);
332319
333
- out += snprintf(buf + out, len - out, "OrphanScan => ");
334
- out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
320
+ out += scnprintf(buf + out, len - out, "OrphanScan => ");
321
+ out += scnprintf(buf + out, len - out, "Local: %u Global: %u ",
335322 os->os_count, os->os_seqno);
336
- out += snprintf(buf + out, len - out, " Last Scan: ");
323
+ out += scnprintf(buf + out, len - out, " Last Scan: ");
337324 if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
338
- out += snprintf(buf + out, len - out, "Disabled\n");
325
+ out += scnprintf(buf + out, len - out, "Disabled\n");
339326 else
340
- out += snprintf(buf + out, len - out, "%lu seconds ago\n",
327
+ out += scnprintf(buf + out, len - out, "%lu seconds ago\n",
341328 (unsigned long)(ktime_get_seconds() - os->os_scantime));
342329
343
- out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
330
+ out += scnprintf(buf + out, len - out, "%10s => %3s %10s\n",
344331 "Slots", "Num", "RecoGen");
345332 for (i = 0; i < osb->max_slots; ++i) {
346
- out += snprintf(buf + out, len - out,
333
+ out += scnprintf(buf + out, len - out,
347334 "%10s %c %3d %10d\n",
348335 " ",
349336 (i == osb->slot_num ? '*' : ' '),
....@@ -575,15 +562,9 @@
575562 return &oi->vfs_inode;
576563 }
577564
578
-static void ocfs2_i_callback(struct rcu_head *head)
565
+static void ocfs2_free_inode(struct inode *inode)
579566 {
580
- struct inode *inode = container_of(head, struct inode, i_rcu);
581567 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
582
-}
583
-
584
-static void ocfs2_destroy_inode(struct inode *inode)
585
-{
586
- call_rcu(&inode->i_rcu, ocfs2_i_callback);
587568 }
588569
589570 static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
....@@ -600,7 +581,6 @@
600581 */
601582
602583 #if BITS_PER_LONG == 32
603
-# if defined(CONFIG_LBDAF)
604584 BUILD_BUG_ON(sizeof(sector_t) != 8);
605585 /*
606586 * We might be limited by page cache size.
....@@ -614,15 +594,6 @@
614594 */
615595 bitshift = 31;
616596 }
617
-# else
618
- /*
619
- * We are limited by the size of sector_t. Use block size, as
620
- * that's what we expose to the VFS.
621
- */
622
- bytes = 1 << bbits;
623
- trim = 1;
624
- bitshift = 31;
625
-# endif
626597 #endif
627598
628599 /*
....@@ -956,8 +927,8 @@
956927 status = -ENOENT;
957928 goto out_quota_off;
958929 }
959
- status = dquot_enable(inode[type], type, QFMT_OCFS2,
960
- DQUOT_USAGE_ENABLED);
930
+ status = dquot_load_quota_inode(inode[type], type, QFMT_OCFS2,
931
+ DQUOT_USAGE_ENABLED);
961932 if (status < 0)
962933 goto out_quota_off;
963934 }
....@@ -985,8 +956,10 @@
985956 for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
986957 if (!sb_has_quota_loaded(sb, type))
987958 continue;
988
- oinfo = sb_dqinfo(sb, type)->dqi_priv;
989
- cancel_delayed_work_sync(&oinfo->dqi_sync_work);
959
+ if (!sb_has_quota_suspended(sb, type)) {
960
+ oinfo = sb_dqinfo(sb, type)->dqi_priv;
961
+ cancel_delayed_work_sync(&oinfo->dqi_sync_work);
962
+ }
990963 inode = igrab(sb->s_dquot.files[type]);
991964 /* Turn off quotas. This will remove all dquot structures from
992965 * memory and so they will be automatically synced to global
....@@ -1014,28 +987,27 @@
1014987
1015988 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
1016989 status = -EINVAL;
1017
- goto read_super_error;
990
+ goto out;
1018991 }
1019992
1020993 /* probe for superblock */
1021994 status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
1022995 if (status < 0) {
1023996 mlog(ML_ERROR, "superblock probe failed!\n");
1024
- goto read_super_error;
997
+ goto out;
1025998 }
1026999
10271000 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
1028
- osb = OCFS2_SB(sb);
1029
- if (status < 0) {
1030
- mlog_errno(status);
1031
- goto read_super_error;
1032
- }
10331001 brelse(bh);
10341002 bh = NULL;
1003
+ if (status < 0)
1004
+ goto out;
1005
+
1006
+ osb = OCFS2_SB(sb);
10351007
10361008 if (!ocfs2_check_set_options(sb, &parsed_options)) {
10371009 status = -EINVAL;
1038
- goto read_super_error;
1010
+ goto out_super;
10391011 }
10401012 osb->s_mount_opt = parsed_options.mount_opt;
10411013 osb->s_atime_quantum = parsed_options.atime_quantum;
....@@ -1052,7 +1024,7 @@
10521024
10531025 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
10541026 if (status)
1055
- goto read_super_error;
1027
+ goto out_super;
10561028
10571029 sb->s_magic = OCFS2_SUPER_MAGIC;
10581030
....@@ -1066,7 +1038,7 @@
10661038 status = -EACCES;
10671039 mlog(ML_ERROR, "Readonly device detected but readonly "
10681040 "mount was not specified.\n");
1069
- goto read_super_error;
1041
+ goto out_super;
10701042 }
10711043
10721044 /* You should not be able to start a local heartbeat
....@@ -1075,7 +1047,7 @@
10751047 status = -EROFS;
10761048 mlog(ML_ERROR, "Local heartbeat specified on readonly "
10771049 "device.\n");
1078
- goto read_super_error;
1050
+ goto out_super;
10791051 }
10801052
10811053 status = ocfs2_check_journals_nolocks(osb);
....@@ -1084,9 +1056,7 @@
10841056 mlog(ML_ERROR, "Recovery required on readonly "
10851057 "file system, but write access is "
10861058 "unavailable.\n");
1087
- else
1088
- mlog_errno(status);
1089
- goto read_super_error;
1059
+ goto out_super;
10901060 }
10911061
10921062 ocfs2_set_ro_flag(osb, 1);
....@@ -1102,71 +1072,37 @@
11021072 }
11031073
11041074 status = ocfs2_verify_heartbeat(osb);
1105
- if (status < 0) {
1106
- mlog_errno(status);
1107
- goto read_super_error;
1108
- }
1075
+ if (status < 0)
1076
+ goto out_super;
11091077
11101078 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
11111079 ocfs2_debugfs_root);
1112
- if (!osb->osb_debug_root) {
1113
- status = -EINVAL;
1114
- mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1115
- goto read_super_error;
1116
- }
11171080
1118
- osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1119
- osb->osb_debug_root,
1120
- osb,
1121
- &ocfs2_osb_debug_fops);
1122
- if (!osb->osb_ctxt) {
1123
- status = -EINVAL;
1124
- mlog_errno(status);
1125
- goto read_super_error;
1126
- }
1081
+ debugfs_create_file("fs_state", S_IFREG|S_IRUSR, osb->osb_debug_root,
1082
+ osb, &ocfs2_osb_debug_fops);
11271083
1128
- if (ocfs2_meta_ecc(osb)) {
1129
- status = ocfs2_blockcheck_stats_debugfs_install(
1130
- &osb->osb_ecc_stats,
1131
- osb->osb_debug_root);
1132
- if (status) {
1133
- mlog(ML_ERROR,
1134
- "Unable to create blockcheck statistics "
1135
- "files\n");
1136
- goto read_super_error;
1137
- }
1138
- }
1084
+ if (ocfs2_meta_ecc(osb))
1085
+ ocfs2_blockcheck_stats_debugfs_install( &osb->osb_ecc_stats,
1086
+ osb->osb_debug_root);
11391087
11401088 status = ocfs2_mount_volume(sb);
11411089 if (status < 0)
1142
- goto read_super_error;
1090
+ goto out_debugfs;
11431091
11441092 if (osb->root_inode)
11451093 inode = igrab(osb->root_inode);
11461094
11471095 if (!inode) {
11481096 status = -EIO;
1149
- mlog_errno(status);
1150
- goto read_super_error;
1097
+ goto out_dismount;
11511098 }
1152
-
1153
- root = d_make_root(inode);
1154
- if (!root) {
1155
- status = -ENOMEM;
1156
- mlog_errno(status);
1157
- goto read_super_error;
1158
- }
1159
-
1160
- sb->s_root = root;
1161
-
1162
- ocfs2_complete_mount_recovery(osb);
11631099
11641100 osb->osb_dev_kset = kset_create_and_add(sb->s_id, NULL,
11651101 &ocfs2_kset->kobj);
11661102 if (!osb->osb_dev_kset) {
11671103 status = -ENOMEM;
11681104 mlog(ML_ERROR, "Unable to create device kset %s.\n", sb->s_id);
1169
- goto read_super_error;
1105
+ goto out_dismount;
11701106 }
11711107
11721108 /* Create filecheck sysfs related directories/files at
....@@ -1175,8 +1111,18 @@
11751111 status = -ENOMEM;
11761112 mlog(ML_ERROR, "Unable to create filecheck sysfs directory at "
11771113 "/sys/fs/ocfs2/%s/filecheck.\n", sb->s_id);
1178
- goto read_super_error;
1114
+ goto out_dismount;
11791115 }
1116
+
1117
+ root = d_make_root(inode);
1118
+ if (!root) {
1119
+ status = -ENOMEM;
1120
+ goto out_dismount;
1121
+ }
1122
+
1123
+ sb->s_root = root;
1124
+
1125
+ ocfs2_complete_mount_recovery(osb);
11801126
11811127 if (ocfs2_mount_local(osb))
11821128 snprintf(nodestr, sizeof(nodestr), "local");
....@@ -1218,17 +1164,22 @@
12181164
12191165 return status;
12201166
1221
-read_super_error:
1222
- brelse(bh);
1167
+out_dismount:
1168
+ atomic_set(&osb->vol_state, VOLUME_DISABLED);
1169
+ wake_up(&osb->osb_mount_event);
1170
+ ocfs2_free_replay_slots(osb);
1171
+ ocfs2_dismount_volume(sb, 1);
1172
+ goto out;
12231173
1224
- if (status)
1225
- mlog_errno(status);
1226
-
1227
- if (osb) {
1228
- atomic_set(&osb->vol_state, VOLUME_DISABLED);
1229
- wake_up(&osb->osb_mount_event);
1230
- ocfs2_dismount_volume(sb, 1);
1231
- }
1174
+out_debugfs:
1175
+ debugfs_remove_recursive(osb->osb_debug_root);
1176
+out_super:
1177
+ ocfs2_release_system_inodes(osb);
1178
+ kfree(osb->recovery_map);
1179
+ ocfs2_delete_osb(osb);
1180
+ kfree(osb);
1181
+out:
1182
+ mlog_errno(status);
12321183
12331184 return status;
12341185 }
....@@ -1622,11 +1573,6 @@
16221573 goto out2;
16231574
16241575 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1625
- if (!ocfs2_debugfs_root) {
1626
- status = -ENOMEM;
1627
- mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1628
- goto out3;
1629
- }
16301576
16311577 ocfs2_set_locking_protocol();
16321578
....@@ -1842,11 +1788,12 @@
18421788 static int ocfs2_mount_volume(struct super_block *sb)
18431789 {
18441790 int status = 0;
1845
- int unlock_super = 0;
18461791 struct ocfs2_super *osb = OCFS2_SB(sb);
18471792
18481793 if (ocfs2_is_hard_readonly(osb))
1849
- goto leave;
1794
+ goto out;
1795
+
1796
+ mutex_init(&osb->obs_trim_fs_mutex);
18501797
18511798 status = ocfs2_dlm_init(osb);
18521799 if (status < 0) {
....@@ -1854,44 +1801,58 @@
18541801 if (status == -EBADR && ocfs2_userspace_stack(osb))
18551802 mlog(ML_ERROR, "couldn't mount because cluster name on"
18561803 " disk does not match the running cluster name.\n");
1857
- goto leave;
1804
+ goto out;
18581805 }
18591806
18601807 status = ocfs2_super_lock(osb, 1);
18611808 if (status < 0) {
18621809 mlog_errno(status);
1863
- goto leave;
1810
+ goto out_dlm;
18641811 }
1865
- unlock_super = 1;
18661812
18671813 /* This will load up the node map and add ourselves to it. */
18681814 status = ocfs2_find_slot(osb);
18691815 if (status < 0) {
18701816 mlog_errno(status);
1871
- goto leave;
1817
+ goto out_super_lock;
18721818 }
18731819
18741820 /* load all node-local system inodes */
18751821 status = ocfs2_init_local_system_inodes(osb);
18761822 if (status < 0) {
18771823 mlog_errno(status);
1878
- goto leave;
1824
+ goto out_super_lock;
18791825 }
18801826
18811827 status = ocfs2_check_volume(osb);
18821828 if (status < 0) {
18831829 mlog_errno(status);
1884
- goto leave;
1830
+ goto out_system_inodes;
18851831 }
18861832
18871833 status = ocfs2_truncate_log_init(osb);
1888
- if (status < 0)
1834
+ if (status < 0) {
18891835 mlog_errno(status);
1836
+ goto out_check_volume;
1837
+ }
18901838
1891
-leave:
1892
- if (unlock_super)
1893
- ocfs2_super_unlock(osb, 1);
1839
+ ocfs2_super_unlock(osb, 1);
1840
+ return 0;
18941841
1842
+out_check_volume:
1843
+ ocfs2_free_replay_slots(osb);
1844
+out_system_inodes:
1845
+ if (osb->local_alloc_state == OCFS2_LA_ENABLED)
1846
+ ocfs2_shutdown_local_alloc(osb);
1847
+ ocfs2_release_system_inodes(osb);
1848
+ /* before journal shutdown, we should release slot_info */
1849
+ ocfs2_free_slot_info(osb);
1850
+ ocfs2_journal_shutdown(osb);
1851
+out_super_lock:
1852
+ ocfs2_super_unlock(osb, 1);
1853
+out_dlm:
1854
+ ocfs2_dlm_shutdown(osb, 0);
1855
+out:
18951856 return status;
18961857 }
18971858
....@@ -1912,8 +1873,6 @@
19121873 ocfs2_filecheck_remove_sysfs(osb);
19131874
19141875 kset_unregister(osb->osb_dev_kset);
1915
-
1916
- debugfs_remove(osb->osb_ctxt);
19171876
19181877 /* Orphan scan should be stopped as early as possible */
19191878 ocfs2_orphan_scan_stop(osb);
....@@ -1966,11 +1925,10 @@
19661925 !ocfs2_is_hard_readonly(osb))
19671926 hangup_needed = 1;
19681927
1969
- if (osb->cconn)
1970
- ocfs2_dlm_shutdown(osb, hangup_needed);
1928
+ ocfs2_dlm_shutdown(osb, hangup_needed);
19711929
19721930 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
1973
- debugfs_remove(osb->osb_debug_root);
1931
+ debugfs_remove_recursive(osb->osb_debug_root);
19741932
19751933 if (hangup_needed)
19761934 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));