aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_mount.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_mount.c')
-rw-r--r--fs/xfs/xfs_mount.c188
1 files changed, 59 insertions, 129 deletions
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index da3988453b71..a4503f5e9497 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -47,12 +47,10 @@
47 47
48STATIC int xfs_mount_log_sb(xfs_mount_t *, __int64_t); 48STATIC int xfs_mount_log_sb(xfs_mount_t *, __int64_t);
49STATIC int xfs_uuid_mount(xfs_mount_t *); 49STATIC int xfs_uuid_mount(xfs_mount_t *);
50STATIC void xfs_uuid_unmount(xfs_mount_t *mp);
51STATIC void xfs_unmountfs_wait(xfs_mount_t *); 50STATIC void xfs_unmountfs_wait(xfs_mount_t *);
52 51
53 52
54#ifdef HAVE_PERCPU_SB 53#ifdef HAVE_PERCPU_SB
55STATIC void xfs_icsb_destroy_counters(xfs_mount_t *);
56STATIC void xfs_icsb_balance_counter(xfs_mount_t *, xfs_sb_field_t, 54STATIC void xfs_icsb_balance_counter(xfs_mount_t *, xfs_sb_field_t,
57 int); 55 int);
58STATIC void xfs_icsb_balance_counter_locked(xfs_mount_t *, xfs_sb_field_t, 56STATIC void xfs_icsb_balance_counter_locked(xfs_mount_t *, xfs_sb_field_t,
@@ -63,7 +61,6 @@ STATIC void xfs_icsb_disable_counter(xfs_mount_t *, xfs_sb_field_t);
63 61
64#else 62#else
65 63
66#define xfs_icsb_destroy_counters(mp) do { } while (0)
67#define xfs_icsb_balance_counter(mp, a, b) do { } while (0) 64#define xfs_icsb_balance_counter(mp, a, b) do { } while (0)
68#define xfs_icsb_balance_counter_locked(mp, a, b) do { } while (0) 65#define xfs_icsb_balance_counter_locked(mp, a, b) do { } while (0)
69#define xfs_icsb_modify_counters(mp, a, b, c) do { } while (0) 66#define xfs_icsb_modify_counters(mp, a, b, c) do { } while (0)
@@ -126,34 +123,12 @@ static const struct {
126}; 123};
127 124
128/* 125/*
129 * Return a pointer to an initialized xfs_mount structure.
130 */
131xfs_mount_t *
132xfs_mount_init(void)
133{
134 xfs_mount_t *mp;
135
136 mp = kmem_zalloc(sizeof(xfs_mount_t), KM_SLEEP);
137
138 if (xfs_icsb_init_counters(mp)) {
139 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
140 }
141
142 spin_lock_init(&mp->m_sb_lock);
143 mutex_init(&mp->m_ilock);
144 mutex_init(&mp->m_growlock);
145 atomic_set(&mp->m_active_trans, 0);
146
147 return mp;
148}
149
150/*
151 * Free up the resources associated with a mount structure. Assume that 126 * Free up the resources associated with a mount structure. Assume that
152 * the structure was initially zeroed, so we can tell which fields got 127 * the structure was initially zeroed, so we can tell which fields got
153 * initialized. 128 * initialized.
154 */ 129 */
155void 130STATIC void
156xfs_mount_free( 131xfs_free_perag(
157 xfs_mount_t *mp) 132 xfs_mount_t *mp)
158{ 133{
159 if (mp->m_perag) { 134 if (mp->m_perag) {
@@ -161,28 +136,9 @@ xfs_mount_free(
161 136
162 for (agno = 0; agno < mp->m_maxagi; agno++) 137 for (agno = 0; agno < mp->m_maxagi; agno++)
163 if (mp->m_perag[agno].pagb_list) 138 if (mp->m_perag[agno].pagb_list)
164 kmem_free(mp->m_perag[agno].pagb_list, 139 kmem_free(mp->m_perag[agno].pagb_list);
165 sizeof(xfs_perag_busy_t) * 140 kmem_free(mp->m_perag);
166 XFS_PAGB_NUM_SLOTS);
167 kmem_free(mp->m_perag,
168 sizeof(xfs_perag_t) * mp->m_sb.sb_agcount);
169 } 141 }
170
171 spinlock_destroy(&mp->m_ail_lock);
172 spinlock_destroy(&mp->m_sb_lock);
173 mutex_destroy(&mp->m_ilock);
174 mutex_destroy(&mp->m_growlock);
175 if (mp->m_quotainfo)
176 XFS_QM_DONE(mp);
177
178 if (mp->m_fsname != NULL)
179 kmem_free(mp->m_fsname, mp->m_fsname_len);
180 if (mp->m_rtname != NULL)
181 kmem_free(mp->m_rtname, strlen(mp->m_rtname) + 1);
182 if (mp->m_logname != NULL)
183 kmem_free(mp->m_logname, strlen(mp->m_logname) + 1);
184
185 xfs_icsb_destroy_counters(mp);
186} 142}
187 143
188/* 144/*
@@ -288,6 +244,19 @@ xfs_mount_validate_sb(
288 return XFS_ERROR(EFSCORRUPTED); 244 return XFS_ERROR(EFSCORRUPTED);
289 } 245 }
290 246
247 /*
248 * Until this is fixed only page-sized or smaller data blocks work.
249 */
250 if (unlikely(sbp->sb_blocksize > PAGE_SIZE)) {
251 xfs_fs_mount_cmn_err(flags,
252 "file system with blocksize %d bytes",
253 sbp->sb_blocksize);
254 xfs_fs_mount_cmn_err(flags,
255 "only pagesize (%ld) or less will currently work.",
256 PAGE_SIZE);
257 return XFS_ERROR(ENOSYS);
258 }
259
291 if (xfs_sb_validate_fsb_count(sbp, sbp->sb_dblocks) || 260 if (xfs_sb_validate_fsb_count(sbp, sbp->sb_dblocks) ||
292 xfs_sb_validate_fsb_count(sbp, sbp->sb_rblocks)) { 261 xfs_sb_validate_fsb_count(sbp, sbp->sb_rblocks)) {
293 xfs_fs_mount_cmn_err(flags, 262 xfs_fs_mount_cmn_err(flags,
@@ -309,19 +278,6 @@ xfs_mount_validate_sb(
309 return XFS_ERROR(ENOSYS); 278 return XFS_ERROR(ENOSYS);
310 } 279 }
311 280
312 /*
313 * Until this is fixed only page-sized or smaller data blocks work.
314 */
315 if (unlikely(sbp->sb_blocksize > PAGE_SIZE)) {
316 xfs_fs_mount_cmn_err(flags,
317 "file system with blocksize %d bytes",
318 sbp->sb_blocksize);
319 xfs_fs_mount_cmn_err(flags,
320 "only pagesize (%ld) or less will currently work.",
321 PAGE_SIZE);
322 return XFS_ERROR(ENOSYS);
323 }
324
325 return 0; 281 return 0;
326} 282}
327 283
@@ -734,11 +690,11 @@ xfs_initialize_perag_data(xfs_mount_t *mp, xfs_agnumber_t agcount)
734 * Update alignment values based on mount options and sb values 690 * Update alignment values based on mount options and sb values
735 */ 691 */
736STATIC int 692STATIC int
737xfs_update_alignment(xfs_mount_t *mp, int mfsi_flags, __uint64_t *update_flags) 693xfs_update_alignment(xfs_mount_t *mp, __uint64_t *update_flags)
738{ 694{
739 xfs_sb_t *sbp = &(mp->m_sb); 695 xfs_sb_t *sbp = &(mp->m_sb);
740 696
741 if (mp->m_dalign && !(mfsi_flags & XFS_MFSI_SECOND)) { 697 if (mp->m_dalign) {
742 /* 698 /*
743 * If stripe unit and stripe width are not multiples 699 * If stripe unit and stripe width are not multiples
744 * of the fs blocksize turn off alignment. 700 * of the fs blocksize turn off alignment.
@@ -894,7 +850,7 @@ xfs_set_inoalignment(xfs_mount_t *mp)
894 * Check that the data (and log if separate) are an ok size. 850 * Check that the data (and log if separate) are an ok size.
895 */ 851 */
896STATIC int 852STATIC int
897xfs_check_sizes(xfs_mount_t *mp, int mfsi_flags) 853xfs_check_sizes(xfs_mount_t *mp)
898{ 854{
899 xfs_buf_t *bp; 855 xfs_buf_t *bp;
900 xfs_daddr_t d; 856 xfs_daddr_t d;
@@ -917,8 +873,7 @@ xfs_check_sizes(xfs_mount_t *mp, int mfsi_flags)
917 return error; 873 return error;
918 } 874 }
919 875
920 if (((mfsi_flags & XFS_MFSI_CLIENT) == 0) && 876 if (mp->m_logdev_targp != mp->m_ddev_targp) {
921 mp->m_logdev_targp != mp->m_ddev_targp) {
922 d = (xfs_daddr_t)XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks); 877 d = (xfs_daddr_t)XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks);
923 if (XFS_BB_TO_FSB(mp, d) != mp->m_sb.sb_logblocks) { 878 if (XFS_BB_TO_FSB(mp, d) != mp->m_sb.sb_logblocks) {
924 cmn_err(CE_WARN, "XFS: size check 3 failed"); 879 cmn_err(CE_WARN, "XFS: size check 3 failed");
@@ -953,15 +908,13 @@ xfs_check_sizes(xfs_mount_t *mp, int mfsi_flags)
953 */ 908 */
954int 909int
955xfs_mountfs( 910xfs_mountfs(
956 xfs_mount_t *mp, 911 xfs_mount_t *mp)
957 int mfsi_flags)
958{ 912{
959 xfs_sb_t *sbp = &(mp->m_sb); 913 xfs_sb_t *sbp = &(mp->m_sb);
960 xfs_inode_t *rip; 914 xfs_inode_t *rip;
961 __uint64_t resblks; 915 __uint64_t resblks;
962 __int64_t update_flags = 0LL; 916 __int64_t update_flags = 0LL;
963 uint quotamount, quotaflags; 917 uint quotamount, quotaflags;
964 int agno;
965 int uuid_mounted = 0; 918 int uuid_mounted = 0;
966 int error = 0; 919 int error = 0;
967 920
@@ -994,9 +947,19 @@ xfs_mountfs(
994 * Re-check for ATTR2 in case it was found in bad_features2 947 * Re-check for ATTR2 in case it was found in bad_features2
995 * slot. 948 * slot.
996 */ 949 */
997 if (xfs_sb_version_hasattr2(&mp->m_sb)) 950 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
951 !(mp->m_flags & XFS_MOUNT_NOATTR2))
998 mp->m_flags |= XFS_MOUNT_ATTR2; 952 mp->m_flags |= XFS_MOUNT_ATTR2;
953 }
954
955 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
956 (mp->m_flags & XFS_MOUNT_NOATTR2)) {
957 xfs_sb_version_removeattr2(&mp->m_sb);
958 update_flags |= XFS_SB_FEATURES2;
999 959
960 /* update sb_versionnum for the clearing of the morebits */
961 if (!sbp->sb_features2)
962 update_flags |= XFS_SB_VERSIONNUM;
1000 } 963 }
1001 964
1002 /* 965 /*
@@ -1005,7 +968,7 @@ xfs_mountfs(
1005 * allocator alignment is within an ag, therefore ag has 968 * allocator alignment is within an ag, therefore ag has
1006 * to be aligned at stripe boundary. 969 * to be aligned at stripe boundary.
1007 */ 970 */
1008 error = xfs_update_alignment(mp, mfsi_flags, &update_flags); 971 error = xfs_update_alignment(mp, &update_flags);
1009 if (error) 972 if (error)
1010 goto error1; 973 goto error1;
1011 974
@@ -1024,8 +987,7 @@ xfs_mountfs(
1024 * since a single partition filesystem is identical to a single 987 * since a single partition filesystem is identical to a single
1025 * partition volume/filesystem. 988 * partition volume/filesystem.
1026 */ 989 */
1027 if ((mfsi_flags & XFS_MFSI_SECOND) == 0 && 990 if ((mp->m_flags & XFS_MOUNT_NOUUID) == 0) {
1028 (mp->m_flags & XFS_MOUNT_NOUUID) == 0) {
1029 if (xfs_uuid_mount(mp)) { 991 if (xfs_uuid_mount(mp)) {
1030 error = XFS_ERROR(EINVAL); 992 error = XFS_ERROR(EINVAL);
1031 goto error1; 993 goto error1;
@@ -1053,7 +1015,7 @@ xfs_mountfs(
1053 /* 1015 /*
1054 * Check that the data (and log if separate) are an ok size. 1016 * Check that the data (and log if separate) are an ok size.
1055 */ 1017 */
1056 error = xfs_check_sizes(mp, mfsi_flags); 1018 error = xfs_check_sizes(mp);
1057 if (error) 1019 if (error)
1058 goto error1; 1020 goto error1;
1059 1021
@@ -1067,13 +1029,6 @@ xfs_mountfs(
1067 } 1029 }
1068 1030
1069 /* 1031 /*
1070 * For client case we are done now
1071 */
1072 if (mfsi_flags & XFS_MFSI_CLIENT) {
1073 return 0;
1074 }
1075
1076 /*
1077 * Copies the low order bits of the timestamp and the randomly 1032 * Copies the low order bits of the timestamp and the randomly
1078 * set "sequence" number out of a UUID. 1033 * set "sequence" number out of a UUID.
1079 */ 1034 */
@@ -1097,8 +1052,10 @@ xfs_mountfs(
1097 * Allocate and initialize the per-ag data. 1052 * Allocate and initialize the per-ag data.
1098 */ 1053 */
1099 init_rwsem(&mp->m_peraglock); 1054 init_rwsem(&mp->m_peraglock);
1100 mp->m_perag = 1055 mp->m_perag = kmem_zalloc(sbp->sb_agcount * sizeof(xfs_perag_t),
1101 kmem_zalloc(sbp->sb_agcount * sizeof(xfs_perag_t), KM_SLEEP); 1056 KM_MAYFAIL);
1057 if (!mp->m_perag)
1058 goto error1;
1102 1059
1103 mp->m_maxagi = xfs_initialize_perag(mp, sbp->sb_agcount); 1060 mp->m_maxagi = xfs_initialize_perag(mp, sbp->sb_agcount);
1104 1061
@@ -1210,7 +1167,7 @@ xfs_mountfs(
1210 * delayed until after the root and real-time bitmap inodes 1167 * delayed until after the root and real-time bitmap inodes
1211 * were consistently read in. 1168 * were consistently read in.
1212 */ 1169 */
1213 error = xfs_log_mount_finish(mp, mfsi_flags); 1170 error = xfs_log_mount_finish(mp);
1214 if (error) { 1171 if (error) {
1215 cmn_err(CE_WARN, "XFS: log mount finish failed"); 1172 cmn_err(CE_WARN, "XFS: log mount finish failed");
1216 goto error4; 1173 goto error4;
@@ -1219,7 +1176,7 @@ xfs_mountfs(
1219 /* 1176 /*
1220 * Complete the quota initialisation, post-log-replay component. 1177 * Complete the quota initialisation, post-log-replay component.
1221 */ 1178 */
1222 error = XFS_QM_MOUNT(mp, quotamount, quotaflags, mfsi_flags); 1179 error = XFS_QM_MOUNT(mp, quotamount, quotaflags);
1223 if (error) 1180 if (error)
1224 goto error4; 1181 goto error4;
1225 1182
@@ -1253,31 +1210,25 @@ xfs_mountfs(
1253 error3: 1210 error3:
1254 xfs_log_unmount_dealloc(mp); 1211 xfs_log_unmount_dealloc(mp);
1255 error2: 1212 error2:
1256 for (agno = 0; agno < sbp->sb_agcount; agno++) 1213 xfs_free_perag(mp);
1257 if (mp->m_perag[agno].pagb_list)
1258 kmem_free(mp->m_perag[agno].pagb_list,
1259 sizeof(xfs_perag_busy_t) * XFS_PAGB_NUM_SLOTS);
1260 kmem_free(mp->m_perag, sbp->sb_agcount * sizeof(xfs_perag_t));
1261 mp->m_perag = NULL;
1262 /* FALLTHROUGH */
1263 error1: 1214 error1:
1264 if (uuid_mounted) 1215 if (uuid_mounted)
1265 xfs_uuid_unmount(mp); 1216 uuid_table_remove(&mp->m_sb.sb_uuid);
1266 xfs_freesb(mp);
1267 return error; 1217 return error;
1268} 1218}
1269 1219
1270/* 1220/*
1271 * xfs_unmountfs
1272 *
1273 * This flushes out the inodes,dquots and the superblock, unmounts the 1221 * This flushes out the inodes,dquots and the superblock, unmounts the
1274 * log and makes sure that incore structures are freed. 1222 * log and makes sure that incore structures are freed.
1275 */ 1223 */
1276int 1224void
1277xfs_unmountfs(xfs_mount_t *mp, struct cred *cr) 1225xfs_unmountfs(
1226 struct xfs_mount *mp)
1278{ 1227{
1279 __uint64_t resblks; 1228 __uint64_t resblks;
1280 int error = 0; 1229 int error;
1230
1231 IRELE(mp->m_rootip);
1281 1232
1282 /* 1233 /*
1283 * We can potentially deadlock here if we have an inode cluster 1234 * We can potentially deadlock here if we have an inode cluster
@@ -1334,32 +1285,20 @@ xfs_unmountfs(xfs_mount_t *mp, struct cred *cr)
1334 xfs_unmountfs_wait(mp); /* wait for async bufs */ 1285 xfs_unmountfs_wait(mp); /* wait for async bufs */
1335 xfs_log_unmount(mp); /* Done! No more fs ops. */ 1286 xfs_log_unmount(mp); /* Done! No more fs ops. */
1336 1287
1337 xfs_freesb(mp);
1338
1339 /* 1288 /*
1340 * All inodes from this mount point should be freed. 1289 * All inodes from this mount point should be freed.
1341 */ 1290 */
1342 ASSERT(mp->m_inodes == NULL); 1291 ASSERT(mp->m_inodes == NULL);
1343 1292
1344 xfs_unmountfs_close(mp, cr);
1345 if ((mp->m_flags & XFS_MOUNT_NOUUID) == 0) 1293 if ((mp->m_flags & XFS_MOUNT_NOUUID) == 0)
1346 xfs_uuid_unmount(mp); 1294 uuid_table_remove(&mp->m_sb.sb_uuid);
1347 1295
1348#if defined(DEBUG) || defined(INDUCE_IO_ERROR) 1296#if defined(DEBUG)
1349 xfs_errortag_clearall(mp, 0); 1297 xfs_errortag_clearall(mp, 0);
1350#endif 1298#endif
1351 xfs_mount_free(mp); 1299 xfs_free_perag(mp);
1352 return 0; 1300 if (mp->m_quotainfo)
1353} 1301 XFS_QM_DONE(mp);
1354
1355void
1356xfs_unmountfs_close(xfs_mount_t *mp, struct cred *cr)
1357{
1358 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp)
1359 xfs_free_buftarg(mp->m_logdev_targp, 1);
1360 if (mp->m_rtdev_targp)
1361 xfs_free_buftarg(mp->m_rtdev_targp, 1);
1362 xfs_free_buftarg(mp->m_ddev_targp, 0);
1363} 1302}
1364 1303
1365STATIC void 1304STATIC void
@@ -1905,16 +1844,6 @@ xfs_uuid_mount(
1905} 1844}
1906 1845
1907/* 1846/*
1908 * Remove filesystem from the UUID table.
1909 */
1910STATIC void
1911xfs_uuid_unmount(
1912 xfs_mount_t *mp)
1913{
1914 uuid_table_remove(&mp->m_sb.sb_uuid);
1915}
1916
1917/*
1918 * Used to log changes to the superblock unit and width fields which could 1847 * Used to log changes to the superblock unit and width fields which could
1919 * be altered by the mount options, as well as any potential sb_features2 1848 * be altered by the mount options, as well as any potential sb_features2
1920 * fixup. Only the first superblock is updated. 1849 * fixup. Only the first superblock is updated.
@@ -1928,7 +1857,8 @@ xfs_mount_log_sb(
1928 int error; 1857 int error;
1929 1858
1930 ASSERT(fields & (XFS_SB_UNIT | XFS_SB_WIDTH | XFS_SB_UUID | 1859 ASSERT(fields & (XFS_SB_UNIT | XFS_SB_WIDTH | XFS_SB_UUID |
1931 XFS_SB_FEATURES2 | XFS_SB_BAD_FEATURES2)); 1860 XFS_SB_FEATURES2 | XFS_SB_BAD_FEATURES2 |
1861 XFS_SB_VERSIONNUM));
1932 1862
1933 tp = xfs_trans_alloc(mp, XFS_TRANS_SB_UNIT); 1863 tp = xfs_trans_alloc(mp, XFS_TRANS_SB_UNIT);
1934 error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0, 1864 error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0,
@@ -2109,7 +2039,7 @@ xfs_icsb_reinit_counters(
2109 xfs_icsb_unlock(mp); 2039 xfs_icsb_unlock(mp);
2110} 2040}
2111 2041
2112STATIC void 2042void
2113xfs_icsb_destroy_counters( 2043xfs_icsb_destroy_counters(
2114 xfs_mount_t *mp) 2044 xfs_mount_t *mp)
2115{ 2045{