Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'gfs2-for-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2

Pull gfs2 updates from Andreas Gruenbacher:

- Use asynchronous glocks and timeouts to recover from deadlocks during
rename and exchange: the lock ordering constraints the vfs uses are
not sufficient to prevent deadlocks across multiple nodes.

- Add support for IOMAP_ZERO and use iomap_zero_range to replace gfs2
specific code.

- Various other minor fixes and cleanups.

* tag 'gfs2-for-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2:
gfs2: clear buf_in_tr when ending a transaction in sweep_bh_for_rgrps
gfs2: Improve mmap write vs. truncate consistency
gfs2: Use async glocks for rename
gfs2: create function gfs2_glock_update_hold_time
gfs2: separate holder for rgrps in gfs2_rename
gfs2: Delete an unnecessary check before brelse()
gfs2: Minor PAGE_SIZE arithmetic cleanups
gfs2: Fix recovery slot bumping
gfs2: Fix possible fs name overflows
gfs2: untangle the logic in gfs2_drevalidate
gfs2: Always mark inode dirty in fallocate
gfs2: Minor gfs2_alloc_inode cleanup
gfs2: implement gfs2_block_zero_range using iomap_zero_range
gfs2: Add support for IOMAP_ZERO
gfs2: gfs2_iomap_begin cleanup

+266 -209
+2 -2
fs/gfs2/aops.c
··· 243 243 { 244 244 struct inode *inode = mapping->host; 245 245 struct gfs2_sbd *sdp = GFS2_SB(inode); 246 - unsigned nrblocks = nr_pages * (PAGE_SIZE/inode->i_sb->s_blocksize); 246 + unsigned nrblocks = nr_pages * (PAGE_SIZE >> inode->i_blkbits); 247 247 int i; 248 248 int ret; 249 249 ··· 552 552 unsigned size) 553 553 { 554 554 struct address_space *mapping = ip->i_inode.i_mapping; 555 - unsigned long index = *pos / PAGE_SIZE; 555 + unsigned long index = *pos >> PAGE_SHIFT; 556 556 unsigned offset = *pos & (PAGE_SIZE - 1); 557 557 unsigned copied = 0; 558 558 unsigned amt;
+74 -121
fs/gfs2/bmap.c
··· 1065 1065 { 1066 1066 struct gfs2_inode *ip = GFS2_I(inode); 1067 1067 struct gfs2_sbd *sdp = GFS2_SB(inode); 1068 - unsigned int data_blocks = 0, ind_blocks = 0, rblocks; 1069 - bool unstuff, alloc_required; 1068 + bool unstuff; 1070 1069 int ret; 1071 - 1072 - ret = gfs2_write_lock(inode); 1073 - if (ret) 1074 - return ret; 1075 1070 1076 1071 unstuff = gfs2_is_stuffed(ip) && 1077 1072 pos + length > gfs2_max_stuffed_size(ip); 1078 1073 1079 - ret = gfs2_iomap_get(inode, pos, length, flags, iomap, mp); 1080 - if (ret) 1081 - goto out_unlock; 1074 + if (unstuff || iomap->type == IOMAP_HOLE) { 1075 + unsigned int data_blocks, ind_blocks; 1076 + struct gfs2_alloc_parms ap = {}; 1077 + unsigned int rblocks; 1078 + struct gfs2_trans *tr; 1082 1079 1083 - alloc_required = unstuff || iomap->type == IOMAP_HOLE; 1084 - 1085 - if (alloc_required || gfs2_is_jdata(ip)) 1086 1080 gfs2_write_calc_reserv(ip, iomap->length, &data_blocks, 1087 1081 &ind_blocks); 1088 - 1089 - if (alloc_required) { 1090 - struct gfs2_alloc_parms ap = { 1091 - .target = data_blocks + ind_blocks 1092 - }; 1093 - 1082 + ap.target = data_blocks + ind_blocks; 1094 1083 ret = gfs2_quota_lock_check(ip, &ap); 1095 1084 if (ret) 1096 - goto out_unlock; 1085 + return ret; 1097 1086 1098 1087 ret = gfs2_inplace_reserve(ip, &ap); 1099 1088 if (ret) 1100 1089 goto out_qunlock; 1101 - } 1102 1090 1103 - rblocks = RES_DINODE + ind_blocks; 1104 - if (gfs2_is_jdata(ip)) 1105 - rblocks += data_blocks; 1106 - if (ind_blocks || data_blocks) 1107 - rblocks += RES_STATFS + RES_QUOTA; 1108 - if (inode == sdp->sd_rindex) 1109 - rblocks += 2 * RES_STATFS; 1110 - if (alloc_required) 1091 + rblocks = RES_DINODE + ind_blocks; 1092 + if (gfs2_is_jdata(ip)) 1093 + rblocks += data_blocks; 1094 + if (ind_blocks || data_blocks) 1095 + rblocks += RES_STATFS + RES_QUOTA; 1096 + if (inode == sdp->sd_rindex) 1097 + rblocks += 2 * RES_STATFS; 1111 1098 rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks); 1112 - 1113 - if (unstuff || iomap->type == IOMAP_HOLE) { 1114 - struct gfs2_trans *tr; 1115 1099 1116 1100 ret = gfs2_trans_begin(sdp, rblocks, 1117 1101 iomap->length >> inode->i_blkbits); ··· 1137 1153 out_trans_end: 1138 1154 gfs2_trans_end(sdp); 1139 1155 out_trans_fail: 1140 - if (alloc_required) 1141 - gfs2_inplace_release(ip); 1156 + gfs2_inplace_release(ip); 1142 1157 out_qunlock: 1143 - if (alloc_required) 1144 - gfs2_quota_unlock(ip); 1145 - out_unlock: 1146 - gfs2_write_unlock(inode); 1158 + gfs2_quota_unlock(ip); 1147 1159 return ret; 1160 + } 1161 + 1162 + static inline bool gfs2_iomap_need_write_lock(unsigned flags) 1163 + { 1164 + return (flags & IOMAP_WRITE) && !(flags & IOMAP_DIRECT); 1148 1165 } 1149 1166 1150 1167 static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, ··· 1158 1173 iomap->flags |= IOMAP_F_BUFFER_HEAD; 1159 1174 1160 1175 trace_gfs2_iomap_start(ip, pos, length, flags); 1161 - if ((flags & IOMAP_WRITE) && !(flags & IOMAP_DIRECT)) { 1162 - ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap, &mp); 1163 - } else { 1164 - ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp); 1165 - 1166 - /* 1167 - * Silently fall back to buffered I/O for stuffed files or if 1168 - * we've hot a hole (see gfs2_file_direct_write). 1169 - */ 1170 - if ((flags & IOMAP_WRITE) && (flags & IOMAP_DIRECT) && 1171 - iomap->type != IOMAP_MAPPED) 1172 - ret = -ENOTBLK; 1176 + if (gfs2_iomap_need_write_lock(flags)) { 1177 + ret = gfs2_write_lock(inode); 1178 + if (ret) 1179 + goto out; 1173 1180 } 1181 + 1182 + ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp); 1183 + if (ret) 1184 + goto out_unlock; 1185 + 1186 + switch(flags & (IOMAP_WRITE | IOMAP_ZERO)) { 1187 + case IOMAP_WRITE: 1188 + if (flags & IOMAP_DIRECT) { 1189 + /* 1190 + * Silently fall back to buffered I/O for stuffed files 1191 + * or if we've got a hole (see gfs2_file_direct_write). 1192 + */ 1193 + if (iomap->type != IOMAP_MAPPED) 1194 + ret = -ENOTBLK; 1195 + goto out_unlock; 1196 + } 1197 + break; 1198 + case IOMAP_ZERO: 1199 + if (iomap->type == IOMAP_HOLE) 1200 + goto out_unlock; 1201 + break; 1202 + default: 1203 + goto out_unlock; 1204 + } 1205 + 1206 + ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap, &mp); 1207 + 1208 + out_unlock: 1209 + if (ret && gfs2_iomap_need_write_lock(flags)) 1210 + gfs2_write_unlock(inode); 1174 1211 release_metapath(&mp); 1212 + out: 1175 1213 trace_gfs2_iomap_end(ip, iomap, ret); 1176 1214 return ret; 1177 1215 } ··· 1205 1197 struct gfs2_inode *ip = GFS2_I(inode); 1206 1198 struct gfs2_sbd *sdp = GFS2_SB(inode); 1207 1199 1208 - if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) != IOMAP_WRITE) 1209 - goto out; 1200 + switch (flags & (IOMAP_WRITE | IOMAP_ZERO)) { 1201 + case IOMAP_WRITE: 1202 + if (flags & IOMAP_DIRECT) 1203 + return 0; 1204 + break; 1205 + case IOMAP_ZERO: 1206 + if (iomap->type == IOMAP_HOLE) 1207 + return 0; 1208 + break; 1209 + default: 1210 + return 0; 1211 + } 1210 1212 1211 1213 if (!gfs2_is_stuffed(ip)) 1212 1214 gfs2_ordered_add_inode(ip); ··· 1249 1231 set_bit(GLF_DIRTY, &ip->i_gl->gl_flags); 1250 1232 1251 1233 out_unlock: 1252 - gfs2_write_unlock(inode); 1253 - out: 1234 + if (gfs2_iomap_need_write_lock(flags)) 1235 + gfs2_write_unlock(inode); 1254 1236 return 0; 1255 1237 } 1256 1238 ··· 1348 1330 return ret; 1349 1331 } 1350 1332 1351 - /** 1352 - * gfs2_block_zero_range - Deal with zeroing out data 1353 - * 1354 - * This is partly borrowed from ext3. 1355 - */ 1356 1333 static int gfs2_block_zero_range(struct inode *inode, loff_t from, 1357 1334 unsigned int length) 1358 1335 { 1359 - struct address_space *mapping = inode->i_mapping; 1360 - struct gfs2_inode *ip = GFS2_I(inode); 1361 - unsigned long index = from >> PAGE_SHIFT; 1362 - unsigned offset = from & (PAGE_SIZE-1); 1363 - unsigned blocksize, iblock, pos; 1364 - struct buffer_head *bh; 1365 - struct page *page; 1366 - int err; 1367 - 1368 - page = find_or_create_page(mapping, index, GFP_NOFS); 1369 - if (!page) 1370 - return 0; 1371 - 1372 - blocksize = inode->i_sb->s_blocksize; 1373 - iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits); 1374 - 1375 - if (!page_has_buffers(page)) 1376 - create_empty_buffers(page, blocksize, 0); 1377 - 1378 - /* Find the buffer that contains "offset" */ 1379 - bh = page_buffers(page); 1380 - pos = blocksize; 1381 - while (offset >= pos) { 1382 - bh = bh->b_this_page; 1383 - iblock++; 1384 - pos += blocksize; 1385 - } 1386 - 1387 - err = 0; 1388 - 1389 - if (!buffer_mapped(bh)) { 1390 - gfs2_block_map(inode, iblock, bh, 0); 1391 - /* unmapped? It's a hole - nothing to do */ 1392 - if (!buffer_mapped(bh)) 1393 - goto unlock; 1394 - } 1395 - 1396 - /* Ok, it's mapped. Make sure it's up-to-date */ 1397 - if (PageUptodate(page)) 1398 - set_buffer_uptodate(bh); 1399 - 1400 - if (!buffer_uptodate(bh)) { 1401 - err = -EIO; 1402 - ll_rw_block(REQ_OP_READ, 0, 1, &bh); 1403 - wait_on_buffer(bh); 1404 - /* Uhhuh. Read error. Complain and punt. */ 1405 - if (!buffer_uptodate(bh)) 1406 - goto unlock; 1407 - err = 0; 1408 - } 1409 - 1410 - if (gfs2_is_jdata(ip)) 1411 - gfs2_trans_add_data(ip->i_gl, bh); 1412 - else 1413 - gfs2_ordered_add_inode(ip); 1414 - 1415 - zero_user(page, offset, length); 1416 - mark_buffer_dirty(bh); 1417 - unlock: 1418 - unlock_page(page); 1419 - put_page(page); 1420 - return err; 1336 + return iomap_zero_range(inode, from, length, NULL, &gfs2_iomap_ops); 1421 1337 } 1422 1338 1423 1339 #define GFS2_JTRUNC_REVOKES 8192 ··· 1632 1680 brelse(dibh); 1633 1681 up_write(&ip->i_rw_mutex); 1634 1682 gfs2_trans_end(sdp); 1683 + buf_in_tr = false; 1635 1684 } 1636 1685 gfs2_glock_dq_uninit(rd_gh); 1637 1686 cond_resched(); ··· 2140 2187 if (error) 2141 2188 goto do_end_trans; 2142 2189 2143 - i_size_write(inode, size); 2190 + truncate_setsize(inode, size); 2144 2191 ip->i_inode.i_mtime = ip->i_inode.i_ctime = current_time(&ip->i_inode); 2145 2192 gfs2_trans_add_meta(ip->i_gl, dibh); 2146 2193 gfs2_dinode_out(ip, dibh->b_data);
+12 -35
fs/gfs2/dentry.c
··· 38 38 struct inode *inode; 39 39 struct gfs2_holder d_gh; 40 40 struct gfs2_inode *ip = NULL; 41 - int error; 41 + int error, valid = 0; 42 42 int had_lock = 0; 43 43 44 44 if (flags & LOOKUP_RCU) ··· 51 51 52 52 if (inode) { 53 53 if (is_bad_inode(inode)) 54 - goto invalid; 54 + goto out; 55 55 ip = GFS2_I(inode); 56 56 } 57 57 58 - if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) 59 - goto valid; 58 + if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) { 59 + valid = 1; 60 + goto out; 61 + } 60 62 61 63 had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL); 62 64 if (!had_lock) { 63 65 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); 64 66 if (error) 65 - goto fail; 66 - } 67 - 68 - error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip); 69 - switch (error) { 70 - case 0: 71 - if (!inode) 72 - goto invalid_gunlock; 73 - break; 74 - case -ENOENT: 75 - if (!inode) 76 - goto valid_gunlock; 77 - goto invalid_gunlock; 78 - default: 79 - goto fail_gunlock; 67 + goto out; 80 68 } 81 69 82 - valid_gunlock: 70 + error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip); 71 + valid = inode ? !error : (error == -ENOENT); 72 + 83 73 if (!had_lock) 84 74 gfs2_glock_dq_uninit(&d_gh); 85 - valid: 75 + out: 86 76 dput(parent); 87 - return 1; 88 - 89 - invalid_gunlock: 90 - if (!had_lock) 91 - gfs2_glock_dq_uninit(&d_gh); 92 - invalid: 93 - dput(parent); 94 - return 0; 95 - 96 - fail_gunlock: 97 - gfs2_glock_dq_uninit(&d_gh); 98 - fail: 99 - dput(parent); 100 - return 0; 77 + return valid; 101 78 } 102 79 103 80 static int gfs2_dhash(const struct dentry *dentry, struct qstr *str)
+1 -2
fs/gfs2/dir.c
··· 1463 1463 sort_offset : entries, copied); 1464 1464 out_free: 1465 1465 for(i = 0; i < leaf; i++) 1466 - if (larr[i]) 1467 - brelse(larr[i]); 1466 + brelse(larr[i]); 1468 1467 kvfree(larr); 1469 1468 out: 1470 1469 return error;
+1 -2
fs/gfs2/dir.h
··· 32 32 const struct gfs2_inode *ip, struct gfs2_diradd *da); 33 33 static inline void gfs2_dir_no_add(struct gfs2_diradd *da) 34 34 { 35 - if (da->bh) 36 - brelse(da->bh); 35 + brelse(da->bh); 37 36 da->bh = NULL; 38 37 } 39 38 extern int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry);
+4 -5
fs/gfs2/file.c
··· 1049 1049 rblocks += data_blocks ? data_blocks : 1; 1050 1050 1051 1051 error = gfs2_trans_begin(sdp, rblocks, 1052 - PAGE_SIZE/sdp->sd_sb.sb_bsize); 1052 + PAGE_SIZE >> inode->i_blkbits); 1053 1053 if (error) 1054 1054 goto out_trans_fail; 1055 1055 ··· 1065 1065 gfs2_quota_unlock(ip); 1066 1066 } 1067 1067 1068 - if (!(mode & FALLOC_FL_KEEP_SIZE) && (pos + count) > inode->i_size) { 1068 + if (!(mode & FALLOC_FL_KEEP_SIZE) && (pos + count) > inode->i_size) 1069 1069 i_size_write(inode, pos + count); 1070 - file_update_time(file); 1071 - mark_inode_dirty(inode); 1072 - } 1070 + file_update_time(file); 1071 + mark_inode_dirty(inode); 1073 1072 1074 1073 if ((file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host)) 1075 1074 return vfs_fsync_range(file, pos, pos + count - 1,
+106 -9
fs/gfs2/glock.c
··· 305 305 clear_bit(HIF_WAIT, &gh->gh_iflags); 306 306 smp_mb__after_atomic(); 307 307 wake_up_bit(&gh->gh_iflags, HIF_WAIT); 308 + if (gh->gh_flags & GL_ASYNC) { 309 + struct gfs2_sbd *sdp = gh->gh_gl->gl_name.ln_sbd; 310 + 311 + wake_up(&sdp->sd_async_glock_wait); 312 + } 308 313 } 309 314 310 315 /** ··· 936 931 gh->gh_ip = 0; 937 932 } 938 933 934 + static void gfs2_glock_update_hold_time(struct gfs2_glock *gl, 935 + unsigned long start_time) 936 + { 937 + /* Have we waited longer that a second? */ 938 + if (time_after(jiffies, start_time + HZ)) { 939 + /* Lengthen the minimum hold time. */ 940 + gl->gl_hold_time = min(gl->gl_hold_time + GL_GLOCK_HOLD_INCR, 941 + GL_GLOCK_MAX_HOLD); 942 + } 943 + } 944 + 939 945 /** 940 946 * gfs2_glock_wait - wait on a glock acquisition 941 947 * @gh: the glock holder ··· 956 940 957 941 int gfs2_glock_wait(struct gfs2_holder *gh) 958 942 { 959 - unsigned long time1 = jiffies; 943 + unsigned long start_time = jiffies; 960 944 961 945 might_sleep(); 962 946 wait_on_bit(&gh->gh_iflags, HIF_WAIT, TASK_UNINTERRUPTIBLE); 963 - if (time_after(jiffies, time1 + HZ)) /* have we waited > a second? */ 964 - /* Lengthen the minimum hold time. */ 965 - gh->gh_gl->gl_hold_time = min(gh->gh_gl->gl_hold_time + 966 - GL_GLOCK_HOLD_INCR, 967 - GL_GLOCK_MAX_HOLD); 947 + gfs2_glock_update_hold_time(gh->gh_gl, start_time); 968 948 return gh->gh_error; 949 + } 950 + 951 + static int glocks_pending(unsigned int num_gh, struct gfs2_holder *ghs) 952 + { 953 + int i; 954 + 955 + for (i = 0; i < num_gh; i++) 956 + if (test_bit(HIF_WAIT, &ghs[i].gh_iflags)) 957 + return 1; 958 + return 0; 959 + } 960 + 961 + /** 962 + * gfs2_glock_async_wait - wait on multiple asynchronous glock acquisitions 963 + * @num_gh: the number of holders in the array 964 + * @ghs: the glock holder array 965 + * 966 + * Returns: 0 on success, meaning all glocks have been granted and are held. 967 + * -ESTALE if the request timed out, meaning all glocks were released, 968 + * and the caller should retry the operation. 969 + */ 970 + 971 + int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs) 972 + { 973 + struct gfs2_sbd *sdp = ghs[0].gh_gl->gl_name.ln_sbd; 974 + int i, ret = 0, timeout = 0; 975 + unsigned long start_time = jiffies; 976 + bool keep_waiting; 977 + 978 + might_sleep(); 979 + /* 980 + * Total up the (minimum hold time * 2) of all glocks and use that to 981 + * determine the max amount of time we should wait. 982 + */ 983 + for (i = 0; i < num_gh; i++) 984 + timeout += ghs[i].gh_gl->gl_hold_time << 1; 985 + 986 + wait_for_dlm: 987 + if (!wait_event_timeout(sdp->sd_async_glock_wait, 988 + !glocks_pending(num_gh, ghs), timeout)) 989 + ret = -ESTALE; /* request timed out. */ 990 + 991 + /* 992 + * If dlm granted all our requests, we need to adjust the glock 993 + * minimum hold time values according to how long we waited. 994 + * 995 + * If our request timed out, we need to repeatedly release any held 996 + * glocks we acquired thus far to allow dlm to acquire the remaining 997 + * glocks without deadlocking. We cannot currently cancel outstanding 998 + * glock acquisitions. 999 + * 1000 + * The HIF_WAIT bit tells us which requests still need a response from 1001 + * dlm. 1002 + * 1003 + * If dlm sent us any errors, we return the first error we find. 1004 + */ 1005 + keep_waiting = false; 1006 + for (i = 0; i < num_gh; i++) { 1007 + /* Skip holders we have already dequeued below. */ 1008 + if (!gfs2_holder_queued(&ghs[i])) 1009 + continue; 1010 + /* Skip holders with a pending DLM response. */ 1011 + if (test_bit(HIF_WAIT, &ghs[i].gh_iflags)) { 1012 + keep_waiting = true; 1013 + continue; 1014 + } 1015 + 1016 + if (test_bit(HIF_HOLDER, &ghs[i].gh_iflags)) { 1017 + if (ret == -ESTALE) 1018 + gfs2_glock_dq(&ghs[i]); 1019 + else 1020 + gfs2_glock_update_hold_time(ghs[i].gh_gl, 1021 + start_time); 1022 + } 1023 + if (!ret) 1024 + ret = ghs[i].gh_error; 1025 + } 1026 + 1027 + if (keep_waiting) 1028 + goto wait_for_dlm; 1029 + 1030 + /* 1031 + * At this point, we've either acquired all locks or released them all. 1032 + */ 1033 + return ret; 969 1034 } 970 1035 971 1036 /** ··· 1115 1018 struct gfs2_holder *gh2; 1116 1019 int try_futile = 0; 1117 1020 1118 - BUG_ON(gh->gh_owner_pid == NULL); 1021 + GLOCK_BUG_ON(gl, gh->gh_owner_pid == NULL); 1119 1022 if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags)) 1120 - BUG(); 1023 + GLOCK_BUG_ON(gl, true); 1121 1024 1122 1025 if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) { 1123 1026 if (test_bit(GLF_LOCK, &gl->gl_flags)) ··· 1885 1788 unsigned long long dtime; 1886 1789 const struct gfs2_holder *gh; 1887 1790 char gflags_buf[32]; 1888 - char fs_id_buf[GFS2_FSNAME_LEN + 3 * sizeof(int) + 2]; 1889 1791 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 1792 + char fs_id_buf[sizeof(sdp->sd_fsname) + 7]; 1890 1793 1891 1794 memset(fs_id_buf, 0, sizeof(fs_id_buf)); 1892 1795 if (fsid && sdp) /* safety precaution */
+6
fs/gfs2/glock.h
··· 190 190 extern int gfs2_glock_nq(struct gfs2_holder *gh); 191 191 extern int gfs2_glock_poll(struct gfs2_holder *gh); 192 192 extern int gfs2_glock_wait(struct gfs2_holder *gh); 193 + extern int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs); 193 194 extern void gfs2_glock_dq(struct gfs2_holder *gh); 194 195 extern void gfs2_glock_dq_wait(struct gfs2_holder *gh); 195 196 extern void gfs2_glock_dq_uninit(struct gfs2_holder *gh); ··· 259 258 static inline bool gfs2_holder_initialized(struct gfs2_holder *gh) 260 259 { 261 260 return gh->gh_gl; 261 + } 262 + 263 + static inline bool gfs2_holder_queued(struct gfs2_holder *gh) 264 + { 265 + return !list_empty(&gh->gh_list); 262 266 } 263 267 264 268 /**
+1
fs/gfs2/incore.h
··· 725 725 struct gfs2_glock *sd_freeze_gl; 726 726 struct work_struct sd_freeze_work; 727 727 wait_queue_head_t sd_glock_wait; 728 + wait_queue_head_t sd_async_glock_wait; 728 729 atomic_t sd_glock_disposal; 729 730 struct completion sd_locking_init; 730 731 struct completion sd_wdack;
+44 -19
fs/gfs2/inode.c
··· 1348 1348 struct gfs2_inode *ip = GFS2_I(d_inode(odentry)); 1349 1349 struct gfs2_inode *nip = NULL; 1350 1350 struct gfs2_sbd *sdp = GFS2_SB(odir); 1351 - struct gfs2_holder ghs[5], r_gh; 1351 + struct gfs2_holder ghs[4], r_gh, rd_gh; 1352 1352 struct gfs2_rgrpd *nrgd; 1353 1353 unsigned int num_gh; 1354 1354 int dir_rename = 0; ··· 1357 1357 int error; 1358 1358 1359 1359 gfs2_holder_mark_uninitialized(&r_gh); 1360 + gfs2_holder_mark_uninitialized(&rd_gh); 1360 1361 if (d_really_is_positive(ndentry)) { 1361 1362 nip = GFS2_I(d_inode(ndentry)); 1362 1363 if (ip == nip) ··· 1388 1387 } 1389 1388 1390 1389 num_gh = 1; 1391 - gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 1390 + gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, ghs); 1392 1391 if (odip != ndip) { 1393 - gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); 1392 + gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE,GL_ASYNC, 1393 + ghs + num_gh); 1394 1394 num_gh++; 1395 1395 } 1396 - gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); 1396 + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, ghs + num_gh); 1397 1397 num_gh++; 1398 1398 1399 1399 if (nip) { 1400 - gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); 1400 + gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, 1401 + ghs + num_gh); 1401 1402 num_gh++; 1402 - /* grab the resource lock for unlink flag twiddling 1403 - * this is the case of the target file already existing 1404 - * so we unlink before doing the rename 1405 - */ 1406 - nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr, 1); 1407 - if (nrgd) 1408 - gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++); 1409 1403 } 1410 1404 1411 1405 for (x = 0; x < num_gh; x++) { 1412 1406 error = gfs2_glock_nq(ghs + x); 1407 + if (error) 1408 + goto out_gunlock; 1409 + } 1410 + error = gfs2_glock_async_wait(num_gh, ghs); 1411 + if (error) 1412 + goto out_gunlock; 1413 + 1414 + if (nip) { 1415 + /* Grab the resource group glock for unlink flag twiddling. 1416 + * This is the case where the target dinode already exists 1417 + * so we unlink before doing the rename. 1418 + */ 1419 + nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr, 1); 1420 + if (!nrgd) { 1421 + error = -ENOENT; 1422 + goto out_gunlock; 1423 + } 1424 + error = gfs2_glock_nq_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, 1425 + &rd_gh); 1413 1426 if (error) 1414 1427 goto out_gunlock; 1415 1428 } ··· 1556 1541 gfs2_quota_unlock(ndip); 1557 1542 out_gunlock: 1558 1543 gfs2_dir_no_add(&da); 1544 + if (gfs2_holder_initialized(&rd_gh)) 1545 + gfs2_glock_dq_uninit(&rd_gh); 1546 + 1559 1547 while (x--) { 1560 - gfs2_glock_dq(ghs + x); 1548 + if (gfs2_holder_queued(ghs + x)) 1549 + gfs2_glock_dq(ghs + x); 1561 1550 gfs2_holder_uninit(ghs + x); 1562 1551 } 1563 1552 out_gunlock_r: ··· 1591 1572 struct gfs2_inode *oip = GFS2_I(odentry->d_inode); 1592 1573 struct gfs2_inode *nip = GFS2_I(ndentry->d_inode); 1593 1574 struct gfs2_sbd *sdp = GFS2_SB(odir); 1594 - struct gfs2_holder ghs[5], r_gh; 1575 + struct gfs2_holder ghs[4], r_gh; 1595 1576 unsigned int num_gh; 1596 1577 unsigned int x; 1597 1578 umode_t old_mode = oip->i_inode.i_mode; ··· 1625 1606 } 1626 1607 1627 1608 num_gh = 1; 1628 - gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 1609 + gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, ghs); 1629 1610 if (odip != ndip) { 1630 - gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); 1611 + gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, 1612 + ghs + num_gh); 1631 1613 num_gh++; 1632 1614 } 1633 - gfs2_holder_init(oip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); 1615 + gfs2_holder_init(oip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, ghs + num_gh); 1634 1616 num_gh++; 1635 1617 1636 - gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); 1618 + gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, ghs + num_gh); 1637 1619 num_gh++; 1638 1620 1639 1621 for (x = 0; x < num_gh; x++) { ··· 1642 1622 if (error) 1643 1623 goto out_gunlock; 1644 1624 } 1625 + 1626 + error = gfs2_glock_async_wait(num_gh, ghs); 1627 + if (error) 1628 + goto out_gunlock; 1645 1629 1646 1630 error = -ENOENT; 1647 1631 if (oip->i_inode.i_nlink == 0 || nip->i_inode.i_nlink == 0) ··· 1707 1683 gfs2_trans_end(sdp); 1708 1684 out_gunlock: 1709 1685 while (x--) { 1710 - gfs2_glock_dq(ghs + x); 1686 + if (gfs2_holder_queued(ghs + x)) 1687 + gfs2_glock_dq(ghs + x); 1711 1688 gfs2_holder_uninit(ghs + x); 1712 1689 } 1713 1690 out_gunlock_r:
+4 -4
fs/gfs2/lock_dlm.c
··· 1035 1035 } 1036 1036 1037 1037 old_size = ls->ls_recover_size; 1038 - 1039 - if (old_size >= max_jid + 1) 1038 + new_size = old_size; 1039 + while (new_size < max_jid + 1) 1040 + new_size += RECOVER_SIZE_INC; 1041 + if (new_size == old_size) 1040 1042 return 0; 1041 - 1042 - new_size = old_size + RECOVER_SIZE_INC; 1043 1043 1044 1044 submit = kcalloc(new_size, sizeof(uint32_t), GFP_NOFS); 1045 1045 result = kcalloc(new_size, sizeof(uint32_t), GFP_NOFS);
+1
fs/gfs2/ops_fstype.c
··· 87 87 gfs2_tune_init(&sdp->sd_tune); 88 88 89 89 init_waitqueue_head(&sdp->sd_glock_wait); 90 + init_waitqueue_head(&sdp->sd_async_glock_wait); 90 91 atomic_set(&sdp->sd_glock_disposal, 0); 91 92 init_completion(&sdp->sd_locking_init); 92 93 init_completion(&sdp->sd_wdack);
+1 -1
fs/gfs2/quota.c
··· 774 774 nbytes = sizeof(struct gfs2_quota); 775 775 776 776 pg_beg = loc >> PAGE_SHIFT; 777 - pg_off = loc % PAGE_SIZE; 777 + pg_off = offset_in_page(loc); 778 778 779 779 /* If the quota straddles a page boundary, split the write in two */ 780 780 if ((pg_off + nbytes) > PAGE_SIZE) {
+1 -1
fs/gfs2/rgrp.c
··· 2285 2285 static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd) 2286 2286 { 2287 2287 struct gfs2_sbd *sdp = rgd->rd_sbd; 2288 - char fs_id_buf[GFS2_FSNAME_LEN + 3 * sizeof(int) + 2]; 2288 + char fs_id_buf[sizeof(sdp->sd_fsname) + 7]; 2289 2289 2290 2290 fs_warn(sdp, "rgrp %llu has an error, marking it readonly until umount\n", 2291 2291 (unsigned long long)rgd->rd_addr);
+7 -7
fs/gfs2/super.c
··· 1722 1722 struct gfs2_inode *ip; 1723 1723 1724 1724 ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL); 1725 - if (ip) { 1726 - ip->i_flags = 0; 1727 - ip->i_gl = NULL; 1728 - memset(&ip->i_res, 0, sizeof(ip->i_res)); 1729 - RB_CLEAR_NODE(&ip->i_res.rs_node); 1730 - ip->i_rahead = 0; 1731 - } 1725 + if (!ip) 1726 + return NULL; 1727 + ip->i_flags = 0; 1728 + ip->i_gl = NULL; 1729 + memset(&ip->i_res, 0, sizeof(ip->i_res)); 1730 + RB_CLEAR_NODE(&ip->i_res.rs_node); 1731 + ip->i_rahead = 0; 1732 1732 return &ip->i_inode; 1733 1733 } 1734 1734
+1 -1
fs/gfs2/util.c
··· 178 178 const char *function, char *file, unsigned int line) 179 179 { 180 180 struct gfs2_sbd *sdp = rgd->rd_sbd; 181 - char fs_id_buf[GFS2_FSNAME_LEN + 3 * sizeof(int) + 2]; 181 + char fs_id_buf[sizeof(sdp->sd_fsname) + 7]; 182 182 int rv; 183 183 184 184 sprintf(fs_id_buf, "fsid=%s: ", sdp->sd_fsname);