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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull gfs2 updates from Andreas Gruenbacher:

- Partially revert "gfs2: do_xmote fixes" to ignore dlm_lock() errors
during withdraw; passing on those errors doesn't help

- Change the LM_FLAG_TRY and LM_FLAG_TRY_1CB logic in add_to_queue() to
check if the holder would actually block

- Move some more dlm specific code from glock.c to lock_dlm.c

- Remove the unused dlm alternate locking mode code

- Add proper locking to make sure that dlm lockspaces are never used
after being released

- Various other cleanups

* tag 'gfs2-for-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2:
gfs2: Fix unlikely race in gdlm_put_lock
gfs2: Add proper lockspace locking
gfs2: Minor run_queue fixes
gfs2: run_queue cleanup
gfs2: Simplify do_promote
gfs2: Get rid of GLF_INVALIDATE_IN_PROGRESS
gfs2: Fix GLF_INVALIDATE_IN_PROGRESS flag clearing in do_xmote
gfs2: Remove duplicate check in do_xmote
gfs2: Fix LM_FLAG_TRY* logic in add_to_queue
gfs2: Remove DLM_LKF_ALTCW / DLM_LKF_ALTPR code
gfs2: Further sanitize lock_dlm.c
gfs2: Do not use atomic operations unnecessarily
gfs2: Sanitize gfs2_meta_check, gfs2_metatype_check, gfs2_io_error
gfs2: Turn gfs2_withdraw into a void function
gfs2: Partially revert "gfs2: do_xmote fixes"
gfs2: Simplify refcounting in do_xmote
gfs2: do_xmote cleanup
gfs2: Remove space before newline
gfs2: Remove unused sd_withdraw_wait field
gfs2: Remove unused GIF_FREE_VFS_INODE flag

+199 -193
+15 -8
fs/gfs2/file.c
··· 1442 1442 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); 1443 1443 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); 1444 1444 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 1445 + int ret; 1445 1446 1446 1447 if (!(fl->c.flc_flags & FL_POSIX)) 1447 1448 return -ENOLCK; ··· 1451 1450 locks_lock_file_wait(file, fl); 1452 1451 return -EIO; 1453 1452 } 1454 - if (cmd == F_CANCELLK) 1455 - return dlm_posix_cancel(ls->ls_dlm, ip->i_no_addr, file, fl); 1456 - else if (IS_GETLK(cmd)) 1457 - return dlm_posix_get(ls->ls_dlm, ip->i_no_addr, file, fl); 1458 - else if (lock_is_unlock(fl)) 1459 - return dlm_posix_unlock(ls->ls_dlm, ip->i_no_addr, file, fl); 1460 - else 1461 - return dlm_posix_lock(ls->ls_dlm, ip->i_no_addr, file, cmd, fl); 1453 + down_read(&ls->ls_sem); 1454 + ret = -ENODEV; 1455 + if (likely(ls->ls_dlm != NULL)) { 1456 + if (cmd == F_CANCELLK) 1457 + ret = dlm_posix_cancel(ls->ls_dlm, ip->i_no_addr, file, fl); 1458 + else if (IS_GETLK(cmd)) 1459 + ret = dlm_posix_get(ls->ls_dlm, ip->i_no_addr, file, fl); 1460 + else if (lock_is_unlock(fl)) 1461 + ret = dlm_posix_unlock(ls->ls_dlm, ip->i_no_addr, file, fl); 1462 + else 1463 + ret = dlm_posix_lock(ls->ls_dlm, ip->i_no_addr, file, cmd, fl); 1464 + } 1465 + up_read(&ls->ls_sem); 1466 + return ret; 1462 1467 } 1463 1468 1464 1469 static void __flock_holder_uninit(struct file *file, struct gfs2_holder *fl_gh)
+85 -100
fs/gfs2/glock.c
··· 481 481 /** 482 482 * do_promote - promote as many requests as possible on the current queue 483 483 * @gl: The glock 484 - * 485 - * Returns true on success (i.e., progress was made or there are no waiters). 486 484 */ 487 485 488 - static bool do_promote(struct gfs2_glock *gl) 486 + static void do_promote(struct gfs2_glock *gl) 489 487 { 490 488 struct gfs2_holder *gh, *current_gh; 491 489 ··· 494 496 if (!may_grant(gl, current_gh, gh)) { 495 497 /* 496 498 * If we get here, it means we may not grant this 497 - * holder for some reason. If this holder is at the 498 - * head of the list, it means we have a blocked holder 499 - * at the head, so return false. 499 + * holder for some reason. 500 500 */ 501 - if (list_is_first(&gh->gh_list, &gl->gl_holders)) 502 - return false; 503 - do_error(gl, 0); 501 + if (current_gh) 502 + do_error(gl, 0); /* Fail queued try locks */ 504 503 break; 505 504 } 506 505 set_bit(HIF_HOLDER, &gh->gh_iflags); ··· 506 511 if (!current_gh) 507 512 current_gh = gh; 508 513 } 509 - return true; 510 514 } 511 515 512 516 /** ··· 640 646 } 641 647 642 648 /* Fast path - we got what we asked for */ 643 - if (test_and_clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)) 649 + if (test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)) { 650 + clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags); 644 651 gfs2_demote_wake(gl); 652 + } 645 653 if (gl->gl_state != LM_ST_UNLOCKED) { 646 654 if (glops->go_xmote_bh) { 647 655 int rv; ··· 689 693 const struct gfs2_glock_operations *glops = gl->gl_ops; 690 694 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 691 695 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 692 - unsigned int lck_flags = (unsigned int)(gh ? gh->gh_flags : 0); 693 696 int ret; 694 697 695 698 if (target != LM_ST_UNLOCKED && glock_blocked_by_withdraw(gl) && 696 699 gh && !(gh->gh_flags & LM_FLAG_NOEXP)) 697 700 goto skip_inval; 698 701 699 - lck_flags &= (LM_FLAG_TRY | LM_FLAG_TRY_1CB | LM_FLAG_NOEXP); 700 702 GLOCK_BUG_ON(gl, gl->gl_state == target); 701 703 GLOCK_BUG_ON(gl, gl->gl_state == gl->gl_target); 702 - if ((target == LM_ST_UNLOCKED || target == LM_ST_DEFERRED) && 703 - glops->go_inval) { 704 - /* 705 - * If another process is already doing the invalidate, let that 706 - * finish first. The glock state machine will get back to this 707 - * holder again later. 708 - */ 709 - if (test_and_set_bit(GLF_INVALIDATE_IN_PROGRESS, 710 - &gl->gl_flags)) 711 - return; 712 - do_error(gl, 0); /* Fail queued try locks */ 713 - } 714 - gl->gl_req = target; 715 - set_bit(GLF_BLOCKING, &gl->gl_flags); 716 - if ((gl->gl_req == LM_ST_UNLOCKED) || 717 - (gl->gl_state == LM_ST_EXCLUSIVE) || 718 - (lck_flags & (LM_FLAG_TRY|LM_FLAG_TRY_1CB))) 719 - clear_bit(GLF_BLOCKING, &gl->gl_flags); 720 - if (!glops->go_inval && !glops->go_sync) 704 + if (!glops->go_inval || !glops->go_sync) 721 705 goto skip_inval; 722 706 723 707 spin_unlock(&gl->gl_lockref.lock); 724 - if (glops->go_sync) { 725 - ret = glops->go_sync(gl); 726 - /* If we had a problem syncing (due to io errors or whatever, 727 - * we should not invalidate the metadata or tell dlm to 728 - * release the glock to other nodes. 729 - */ 730 - if (ret) { 731 - if (cmpxchg(&sdp->sd_log_error, 0, ret)) { 732 - fs_err(sdp, "Error %d syncing glock \n", ret); 733 - gfs2_dump_glock(NULL, gl, true); 734 - } 735 - spin_lock(&gl->gl_lockref.lock); 736 - goto skip_inval; 708 + ret = glops->go_sync(gl); 709 + /* If we had a problem syncing (due to io errors or whatever, 710 + * we should not invalidate the metadata or tell dlm to 711 + * release the glock to other nodes. 712 + */ 713 + if (ret) { 714 + if (cmpxchg(&sdp->sd_log_error, 0, ret)) { 715 + fs_err(sdp, "Error %d syncing glock\n", ret); 716 + gfs2_dump_glock(NULL, gl, true); 737 717 } 718 + spin_lock(&gl->gl_lockref.lock); 719 + goto skip_inval; 738 720 } 739 - if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) { 721 + 722 + if (target == LM_ST_UNLOCKED || target == LM_ST_DEFERRED) { 740 723 /* 741 724 * The call to go_sync should have cleared out the ail list. 742 725 * If there are still items, we have a problem. We ought to ··· 730 755 gfs2_dump_glock(NULL, gl, true); 731 756 } 732 757 glops->go_inval(gl, target == LM_ST_DEFERRED ? 0 : DIO_METADATA); 733 - clear_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags); 734 758 } 735 759 spin_lock(&gl->gl_lockref.lock); 736 760 737 761 skip_inval: 738 - gl->gl_lockref.count++; 739 762 /* 740 763 * Check for an error encountered since we called go_sync and go_inval. 741 764 * If so, we can't withdraw from the glock code because the withdraw ··· 776 803 if (!test_bit(GLF_CANCELING, &gl->gl_flags)) 777 804 clear_bit(GLF_LOCK, &gl->gl_flags); 778 805 clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags); 806 + gl->gl_lockref.count++; 779 807 gfs2_glock_queue_work(gl, GL_GLOCK_DFT_HOLD); 780 808 return; 781 - } else { 782 - clear_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags); 783 809 } 784 810 } 785 811 786 812 if (ls->ls_ops->lm_lock) { 787 813 set_bit(GLF_PENDING_REPLY, &gl->gl_flags); 788 814 spin_unlock(&gl->gl_lockref.lock); 789 - ret = ls->ls_ops->lm_lock(gl, target, lck_flags); 815 + ret = ls->ls_ops->lm_lock(gl, target, gh ? gh->gh_flags : 0); 790 816 spin_lock(&gl->gl_lockref.lock); 791 817 792 - if (ret == -EINVAL && gl->gl_target == LM_ST_UNLOCKED && 793 - target == LM_ST_UNLOCKED && 794 - test_bit(DFL_UNMOUNT, &ls->ls_recover_flags)) { 818 + if (!ret) { 819 + /* The operation will be completed asynchronously. */ 820 + gl->gl_lockref.count++; 821 + return; 822 + } 823 + clear_bit(GLF_PENDING_REPLY, &gl->gl_flags); 824 + 825 + if (ret == -ENODEV && gl->gl_target == LM_ST_UNLOCKED && 826 + target == LM_ST_UNLOCKED) { 795 827 /* 796 828 * The lockspace has been released and the lock has 797 829 * been unlocked implicitly. 798 830 */ 799 - } else if (ret) { 800 - fs_err(sdp, "lm_lock ret %d\n", ret); 801 - target = gl->gl_state | LM_OUT_ERROR; 802 831 } else { 803 - /* The operation will be completed asynchronously. */ 832 + fs_err(sdp, "lm_lock ret %d\n", ret); 833 + GLOCK_BUG_ON(gl, !gfs2_withdrawing_or_withdrawn(sdp)); 804 834 return; 805 835 } 806 - clear_bit(GLF_PENDING_REPLY, &gl->gl_flags); 807 836 } 808 837 809 838 /* Complete the operation now. */ 810 839 finish_xmote(gl, target); 840 + gl->gl_lockref.count++; 811 841 gfs2_glock_queue_work(gl, 0); 812 842 } 813 843 ··· 831 855 return; 832 856 set_bit(GLF_LOCK, &gl->gl_flags); 833 857 834 - /* While a demote is in progress, the GLF_LOCK flag must be set. */ 858 + /* 859 + * The GLF_DEMOTE_IN_PROGRESS flag is only set intermittently during 860 + * locking operations. We have just started a locking operation by 861 + * setting the GLF_LOCK flag, so the GLF_DEMOTE_IN_PROGRESS flag must 862 + * be cleared. 863 + */ 835 864 GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)); 836 865 837 - if (test_bit(GLF_DEMOTE, &gl->gl_flags) && 838 - gl->gl_demote_state != gl->gl_state) { 866 + if (test_bit(GLF_DEMOTE, &gl->gl_flags)) { 867 + if (gl->gl_demote_state == gl->gl_state) { 868 + gfs2_demote_wake(gl); 869 + goto promote; 870 + } 871 + 839 872 if (find_first_holder(gl)) 840 873 goto out_unlock; 841 874 if (nonblock) ··· 854 869 gl->gl_target = gl->gl_demote_state; 855 870 do_xmote(gl, NULL, gl->gl_target); 856 871 return; 857 - } else { 858 - if (test_bit(GLF_DEMOTE, &gl->gl_flags)) 859 - gfs2_demote_wake(gl); 860 - if (do_promote(gl)) 861 - goto out_unlock; 862 - gh = find_first_waiter(gl); 863 - if (!gh) 864 - goto out_unlock; 865 - gl->gl_target = gh->gh_state; 866 - if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) 867 - do_error(gl, 0); /* Fail queued try locks */ 868 - do_xmote(gl, gh, gl->gl_target); 869 - return; 870 872 } 873 + 874 + promote: 875 + do_promote(gl); 876 + if (find_first_holder(gl)) 877 + goto out_unlock; 878 + gh = find_first_waiter(gl); 879 + if (!gh) 880 + goto out_unlock; 881 + if (nonblock) 882 + goto out_sched; 883 + gl->gl_target = gh->gh_state; 884 + if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) 885 + do_error(gl, 0); /* Fail queued try locks */ 886 + do_xmote(gl, gh, gl->gl_target); 887 + return; 871 888 872 889 out_sched: 873 890 clear_bit(GLF_LOCK, &gl->gl_flags); 874 - smp_mb__after_atomic(); 875 891 gl->gl_lockref.count++; 876 892 gfs2_glock_queue_work(gl, 0); 877 893 return; 878 894 879 895 out_unlock: 880 896 clear_bit(GLF_LOCK, &gl->gl_flags); 881 - smp_mb__after_atomic(); 882 897 } 883 898 884 899 /** ··· 1447 1462 va_end(args); 1448 1463 } 1449 1464 1465 + static bool gfs2_should_queue_trylock(struct gfs2_glock *gl, 1466 + struct gfs2_holder *gh) 1467 + { 1468 + struct gfs2_holder *current_gh, *gh2; 1469 + 1470 + current_gh = find_first_holder(gl); 1471 + if (current_gh && !may_grant(gl, current_gh, gh)) 1472 + return false; 1473 + 1474 + list_for_each_entry(gh2, &gl->gl_holders, gh_list) { 1475 + if (test_bit(HIF_HOLDER, &gh2->gh_iflags)) 1476 + continue; 1477 + if (!(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) 1478 + return false; 1479 + } 1480 + return true; 1481 + } 1482 + 1450 1483 static inline bool pid_is_meaningful(const struct gfs2_holder *gh) 1451 1484 { 1452 1485 if (!(gh->gh_flags & GL_NOPID)) ··· 1483 1480 */ 1484 1481 1485 1482 static inline void add_to_queue(struct gfs2_holder *gh) 1486 - __releases(&gl->gl_lockref.lock) 1487 - __acquires(&gl->gl_lockref.lock) 1488 1483 { 1489 1484 struct gfs2_glock *gl = gh->gh_gl; 1490 1485 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 1491 1486 struct gfs2_holder *gh2; 1492 - int try_futile = 0; 1493 1487 1494 1488 GLOCK_BUG_ON(gl, gh->gh_owner_pid == NULL); 1495 1489 if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags)) 1496 1490 GLOCK_BUG_ON(gl, true); 1497 1491 1498 - if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) { 1499 - if (test_bit(GLF_LOCK, &gl->gl_flags)) { 1500 - struct gfs2_holder *current_gh; 1501 - 1502 - current_gh = find_first_holder(gl); 1503 - try_futile = !may_grant(gl, current_gh, gh); 1504 - } 1505 - if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) 1506 - goto fail; 1492 + if ((gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) && 1493 + !gfs2_should_queue_trylock(gl, gh)) { 1494 + gh->gh_error = GLR_TRYFAILED; 1495 + gfs2_holder_wake(gh); 1496 + return; 1507 1497 } 1508 1498 1509 1499 list_for_each_entry(gh2, &gl->gl_holders, gh_list) { ··· 1507 1511 if (!pid_is_meaningful(gh2)) 1508 1512 continue; 1509 1513 goto trap_recursive; 1510 - } 1511 - list_for_each_entry(gh2, &gl->gl_holders, gh_list) { 1512 - if (try_futile && 1513 - !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) { 1514 - fail: 1515 - gh->gh_error = GLR_TRYFAILED; 1516 - gfs2_holder_wake(gh); 1517 - return; 1518 - } 1519 1514 } 1520 1515 trace_gfs2_glock_queue(gh, 1); 1521 1516 gfs2_glstats_inc(gl, GFS2_LKS_QCOUNT); ··· 2308 2321 *p++ = 'y'; 2309 2322 if (test_bit(GLF_LFLUSH, gflags)) 2310 2323 *p++ = 'f'; 2311 - if (test_bit(GLF_INVALIDATE_IN_PROGRESS, gflags)) 2312 - *p++ = 'i'; 2313 2324 if (test_bit(GLF_PENDING_REPLY, gflags)) 2314 2325 *p++ = 'R'; 2315 2326 if (test_bit(GLF_HAVE_REPLY, gflags))
+4
fs/gfs2/glock.h
··· 68 68 * also be granted in SHARED. The preferred state is whichever is compatible 69 69 * with other granted locks, or the specified state if no other locks exist. 70 70 * 71 + * In addition, when a lock is already held in EX mode locally, a SHARED or 72 + * DEFERRED mode request with the LM_FLAG_ANY flag set will be granted. 73 + * (The LM_FLAG_ANY flag is only use for SHARED mode requests currently.) 74 + * 71 75 * LM_FLAG_NODE_SCOPE 72 76 * This holder agrees to share the lock within this node. In other words, 73 77 * the glock is held in EX mode according to DLM, but local holders on the
+2 -3
fs/gfs2/incore.h
··· 319 319 GLF_DEMOTE_IN_PROGRESS = 5, 320 320 GLF_DIRTY = 6, 321 321 GLF_LFLUSH = 7, 322 - GLF_INVALIDATE_IN_PROGRESS = 8, 323 322 GLF_HAVE_REPLY = 9, 324 323 GLF_INITIAL = 10, 325 324 GLF_HAVE_FROZEN_REPLY = 11, ··· 375 376 enum { 376 377 GIF_QD_LOCKED = 1, 377 378 GIF_SW_PAGED = 3, 378 - GIF_FREE_VFS_INODE = 5, 379 379 GIF_GLOP_PENDING = 6, 380 380 }; 381 381 ··· 656 658 struct completion ls_sync_wait; /* {control,mounted}_{lock,unlock} */ 657 659 char *ls_lvb_bits; 658 660 661 + struct rw_semaphore ls_sem; 662 + 659 663 spinlock_t ls_recover_spin; /* protects following fields */ 660 664 unsigned long ls_recover_flags; /* DFL_ */ 661 665 uint32_t ls_recover_mount; /* gen in first recover_done cb */ ··· 823 823 atomic_t sd_log_in_flight; 824 824 wait_queue_head_t sd_log_flush_wait; 825 825 int sd_log_error; /* First log error */ 826 - wait_queue_head_t sd_withdraw_wait; 827 826 828 827 unsigned int sd_log_tail; 829 828 unsigned int sd_log_flush_tail;
+60 -40
fs/gfs2/lock_dlm.c
··· 58 58 /** 59 59 * gfs2_update_reply_times - Update locking statistics 60 60 * @gl: The glock to update 61 + * @blocking: The operation may have been blocking 61 62 * 62 63 * This assumes that gl->gl_dstamp has been set earlier. 63 64 * ··· 73 72 * TRY_1CB flags are set are classified as non-blocking. All 74 73 * other DLM requests are counted as (potentially) blocking. 75 74 */ 76 - static inline void gfs2_update_reply_times(struct gfs2_glock *gl) 75 + static inline void gfs2_update_reply_times(struct gfs2_glock *gl, 76 + bool blocking) 77 77 { 78 78 struct gfs2_pcpu_lkstats *lks; 79 79 const unsigned gltype = gl->gl_name.ln_type; 80 - unsigned index = test_bit(GLF_BLOCKING, &gl->gl_flags) ? 81 - GFS2_LKS_SRTTB : GFS2_LKS_SRTT; 80 + unsigned index = blocking ? GFS2_LKS_SRTTB : GFS2_LKS_SRTT; 82 81 s64 rtt; 83 82 84 83 preempt_disable(); ··· 120 119 static void gdlm_ast(void *arg) 121 120 { 122 121 struct gfs2_glock *gl = arg; 122 + bool blocking; 123 123 unsigned ret; 124 + 125 + blocking = test_bit(GLF_BLOCKING, &gl->gl_flags); 126 + gfs2_update_reply_times(gl, blocking); 127 + clear_bit(GLF_BLOCKING, &gl->gl_flags); 124 128 125 129 /* If the glock is dead, we only react to a dlm_unlock() reply. */ 126 130 if (__lockref_is_dead(&gl->gl_lockref) && 127 131 gl->gl_lksb.sb_status != -DLM_EUNLOCK) 128 132 return; 129 133 130 - gfs2_update_reply_times(gl); 131 134 BUG_ON(gl->gl_lksb.sb_flags & DLM_SBF_DEMOTED); 132 135 133 136 if ((gl->gl_lksb.sb_flags & DLM_SBF_VALNOTVALID) && gl->gl_lksb.sb_lvbptr) ··· 162 157 } 163 158 164 159 ret = gl->gl_req; 165 - if (gl->gl_lksb.sb_flags & DLM_SBF_ALTMODE) { 166 - if (gl->gl_req == LM_ST_SHARED) 167 - ret = LM_ST_DEFERRED; 168 - else if (gl->gl_req == LM_ST_DEFERRED) 169 - ret = LM_ST_SHARED; 170 - else 171 - BUG(); 172 - } 173 160 174 161 /* 175 162 * The GLF_INITIAL flag is initially set for new glocks. Upon the ··· 238 241 } 239 242 240 243 static u32 make_flags(struct gfs2_glock *gl, const unsigned int gfs_flags, 241 - const int cur, const int req) 244 + const int req, bool blocking) 242 245 { 243 246 u32 lkf = 0; 244 247 ··· 253 256 lkf |= DLM_LKF_NOQUEUEBAST; 254 257 } 255 258 256 - if (gfs_flags & LM_FLAG_ANY) { 257 - if (req == DLM_LOCK_PR) 258 - lkf |= DLM_LKF_ALTCW; 259 - else if (req == DLM_LOCK_CW) 260 - lkf |= DLM_LKF_ALTPR; 261 - else 262 - BUG(); 263 - } 264 - 265 259 if (!test_bit(GLF_INITIAL, &gl->gl_flags)) { 266 260 lkf |= DLM_LKF_CONVERT; 267 261 ··· 262 274 * "upward" lock conversions or else DLM will reject the 263 275 * request as invalid. 264 276 */ 265 - if (!down_conversion(cur, req)) 277 + if (blocking) 266 278 lkf |= DLM_LKF_QUECVT; 267 279 } 268 280 ··· 282 294 unsigned int flags) 283 295 { 284 296 struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct; 297 + bool blocking; 285 298 int cur, req; 286 299 u32 lkf; 287 300 char strname[GDLM_STRNAME_BYTES] = ""; 288 301 int error; 289 302 303 + gl->gl_req = req_state; 290 304 cur = make_mode(gl->gl_name.ln_sbd, gl->gl_state); 291 305 req = make_mode(gl->gl_name.ln_sbd, req_state); 292 - lkf = make_flags(gl, flags, cur, req); 306 + blocking = !down_conversion(cur, req) && 307 + !(flags & (LM_FLAG_TRY|LM_FLAG_TRY_1CB)); 308 + lkf = make_flags(gl, flags, req, blocking); 309 + if (blocking) 310 + set_bit(GLF_BLOCKING, &gl->gl_flags); 293 311 gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT); 294 312 gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT); 295 313 if (test_bit(GLF_INITIAL, &gl->gl_flags)) { ··· 312 318 */ 313 319 314 320 again: 315 - error = dlm_lock(ls->ls_dlm, req, &gl->gl_lksb, lkf, strname, 316 - GDLM_STRNAME_BYTES - 1, 0, gdlm_ast, gl, gdlm_bast); 321 + down_read(&ls->ls_sem); 322 + error = -ENODEV; 323 + if (likely(ls->ls_dlm != NULL)) { 324 + error = dlm_lock(ls->ls_dlm, req, &gl->gl_lksb, lkf, strname, 325 + GDLM_STRNAME_BYTES - 1, 0, gdlm_ast, gl, gdlm_bast); 326 + } 327 + up_read(&ls->ls_sem); 317 328 if (error == -EBUSY) { 318 329 msleep(20); 319 330 goto again; ··· 340 341 return; 341 342 } 342 343 343 - clear_bit(GLF_BLOCKING, &gl->gl_flags); 344 344 gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT); 345 345 gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT); 346 346 gfs2_update_request_times(gl); 347 - 348 - /* don't want to call dlm if we've unmounted the lock protocol */ 349 - if (test_bit(DFL_UNMOUNT, &ls->ls_recover_flags)) { 350 - gfs2_glock_free(gl); 351 - return; 352 - } 353 347 354 348 /* 355 349 * When the lockspace is released, all remaining glocks will be ··· 361 369 flags |= DLM_LKF_VALBLK; 362 370 363 371 again: 364 - error = dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, flags, 365 - NULL, gl); 372 + down_read(&ls->ls_sem); 373 + error = -ENODEV; 374 + if (likely(ls->ls_dlm != NULL)) { 375 + error = dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, flags, 376 + NULL, gl); 377 + } 378 + up_read(&ls->ls_sem); 366 379 if (error == -EBUSY) { 367 380 msleep(20); 368 381 goto again; 382 + } 383 + 384 + if (error == -ENODEV) { 385 + gfs2_glock_free(gl); 386 + return; 369 387 } 370 388 371 389 if (error) { ··· 388 386 static void gdlm_cancel(struct gfs2_glock *gl) 389 387 { 390 388 struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct; 391 - dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_CANCEL, NULL, gl); 389 + 390 + down_read(&ls->ls_sem); 391 + if (likely(ls->ls_dlm != NULL)) { 392 + dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_CANCEL, NULL, gl); 393 + } 394 + up_read(&ls->ls_sem); 392 395 } 393 396 394 397 /* ··· 574 567 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 575 568 int error; 576 569 577 - error = dlm_unlock(ls->ls_dlm, lksb->sb_lkid, 0, lksb, ls); 570 + down_read(&ls->ls_sem); 571 + error = -ENODEV; 572 + if (likely(ls->ls_dlm != NULL)) 573 + error = dlm_unlock(ls->ls_dlm, lksb->sb_lkid, 0, lksb, ls); 574 + up_read(&ls->ls_sem); 578 575 if (error) { 579 576 fs_err(sdp, "%s lkid %x error %d\n", 580 577 name, lksb->sb_lkid, error); ··· 605 594 memset(strname, 0, GDLM_STRNAME_BYTES); 606 595 snprintf(strname, GDLM_STRNAME_BYTES, "%8x%16x", LM_TYPE_NONDISK, num); 607 596 608 - error = dlm_lock(ls->ls_dlm, mode, lksb, flags, 609 - strname, GDLM_STRNAME_BYTES - 1, 610 - 0, sync_wait_cb, ls, NULL); 597 + down_read(&ls->ls_sem); 598 + error = -ENODEV; 599 + if (likely(ls->ls_dlm != NULL)) { 600 + error = dlm_lock(ls->ls_dlm, mode, lksb, flags, 601 + strname, GDLM_STRNAME_BYTES - 1, 602 + 0, sync_wait_cb, ls, NULL); 603 + } 604 + up_read(&ls->ls_sem); 611 605 if (error) { 612 606 fs_err(sdp, "%s lkid %x flags %x mode %d error %d\n", 613 607 name, lksb->sb_lkid, flags, mode, error); ··· 1339 1323 */ 1340 1324 1341 1325 INIT_DELAYED_WORK(&sdp->sd_control_work, gfs2_control_func); 1326 + ls->ls_dlm = NULL; 1342 1327 spin_lock_init(&ls->ls_recover_spin); 1343 1328 ls->ls_recover_flags = 0; 1344 1329 ls->ls_recover_mount = 0; ··· 1374 1357 * create/join lockspace 1375 1358 */ 1376 1359 1360 + init_rwsem(&ls->ls_sem); 1377 1361 error = dlm_new_lockspace(fsname, cluster, flags, GDLM_LVB_SIZE, 1378 1362 &gdlm_lockspace_ops, sdp, &ops_result, 1379 1363 &ls->ls_dlm); ··· 1454 1436 1455 1437 /* mounted_lock and control_lock will be purged in dlm recovery */ 1456 1438 release: 1439 + down_write(&ls->ls_sem); 1457 1440 if (ls->ls_dlm) { 1458 1441 dlm_release_lockspace(ls->ls_dlm, 2); 1459 1442 ls->ls_dlm = NULL; 1460 1443 } 1444 + up_write(&ls->ls_sem); 1461 1445 1462 1446 free_recover_size(ls); 1463 1447 }
-1
fs/gfs2/trace_gfs2.h
··· 52 52 {(1UL << GLF_DEMOTE_IN_PROGRESS), "p" }, \ 53 53 {(1UL << GLF_DIRTY), "y" }, \ 54 54 {(1UL << GLF_LFLUSH), "f" }, \ 55 - {(1UL << GLF_INVALIDATE_IN_PROGRESS), "i" }, \ 56 55 {(1UL << GLF_PENDING_REPLY), "R" }, \ 57 56 {(1UL << GLF_HAVE_REPLY), "r" }, \ 58 57 {(1UL << GLF_INITIAL), "a" }, \
+13 -25
fs/gfs2/util.c
··· 309 309 va_end(args); 310 310 } 311 311 312 - int gfs2_withdraw(struct gfs2_sbd *sdp) 312 + void gfs2_withdraw(struct gfs2_sbd *sdp) 313 313 { 314 314 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 315 315 const struct lm_lockops *lm = ls->ls_ops; ··· 322 322 wait_on_bit(&sdp->sd_flags, 323 323 SDF_WITHDRAW_IN_PROG, 324 324 TASK_UNINTERRUPTIBLE); 325 - return -1; 325 + return; 326 326 } 327 327 new = old | BIT(SDF_WITHDRAWN) | BIT(SDF_WITHDRAW_IN_PROG); 328 328 } while (unlikely(!try_cmpxchg(&sdp->sd_flags, &old, new))); ··· 350 350 351 351 if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC) 352 352 panic("GFS2: fsid=%s: panic requested\n", sdp->sd_fsname); 353 - 354 - return -1; 355 353 } 356 354 357 355 /* ··· 471 473 472 474 /* 473 475 * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw 474 - * Returns: -1 if this call withdrew the machine, 475 - * -2 if it was already withdrawn 476 476 */ 477 477 478 - int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, 479 - const char *function, char *file, 480 - unsigned int line) 478 + void gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, 479 + const char *function, char *file, 480 + unsigned int line) 481 481 { 482 - int me; 483 - 484 482 gfs2_lm(sdp, 485 483 "fatal: invalid metadata block - " 486 484 "bh = %llu (bad magic number), " 487 485 "function = %s, file = %s, line = %u\n", 488 486 (unsigned long long)bh->b_blocknr, 489 487 function, file, line); 490 - me = gfs2_withdraw(sdp); 491 - return (me) ? -1 : -2; 488 + gfs2_withdraw(sdp); 492 489 } 493 490 494 491 /* 495 492 * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw 496 - * Returns: -1 if this call withdrew the machine, 497 - * -2 if it was already withdrawn 498 493 */ 499 494 500 - int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, 501 - u16 type, u16 t, const char *function, 502 - char *file, unsigned int line) 495 + void gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, 496 + u16 type, u16 t, const char *function, 497 + char *file, unsigned int line) 503 498 { 504 - int me; 505 - 506 499 gfs2_lm(sdp, 507 500 "fatal: invalid metadata block - " 508 501 "bh = %llu (type: exp=%u, found=%u), " 509 502 "function = %s, file = %s, line = %u\n", 510 503 (unsigned long long)bh->b_blocknr, type, t, 511 504 function, file, line); 512 - me = gfs2_withdraw(sdp); 513 - return (me) ? -1 : -2; 505 + gfs2_withdraw(sdp); 514 506 } 515 507 516 508 /* ··· 509 521 * 0 if it was already withdrawn 510 522 */ 511 523 512 - int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file, 513 - unsigned int line) 524 + void gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file, 525 + unsigned int line) 514 526 { 515 527 gfs2_lm(sdp, 516 528 "fatal: I/O error - " 517 529 "function = %s, file = %s, line = %u\n", 518 530 function, file, line); 519 - return gfs2_withdraw(sdp); 531 + gfs2_withdraw(sdp); 520 532 } 521 533 522 534 /*
+20 -16
fs/gfs2/util.h
··· 91 91 gfs2_consist_rgrpd_i((rgd), __func__, __FILE__, __LINE__) 92 92 93 93 94 - int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, 95 - const char *function, 96 - char *file, unsigned int line); 94 + void gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, 95 + const char *function, 96 + char *file, unsigned int line); 97 97 98 98 static inline int gfs2_meta_check(struct gfs2_sbd *sdp, 99 99 struct buffer_head *bh) ··· 108 108 return 0; 109 109 } 110 110 111 - int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, 112 - u16 type, u16 t, 113 - const char *function, 114 - char *file, unsigned int line); 111 + void gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, 112 + u16 type, u16 t, 113 + const char *function, 114 + char *file, unsigned int line); 115 115 116 116 static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp, 117 117 struct buffer_head *bh, ··· 122 122 struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; 123 123 u32 magic = be32_to_cpu(mh->mh_magic); 124 124 u16 t = be32_to_cpu(mh->mh_type); 125 - if (unlikely(magic != GFS2_MAGIC)) 126 - return gfs2_meta_check_ii(sdp, bh, function, 127 - file, line); 128 - if (unlikely(t != type)) 129 - return gfs2_metatype_check_ii(sdp, bh, type, t, function, 130 - file, line); 125 + if (unlikely(magic != GFS2_MAGIC)) { 126 + gfs2_meta_check_ii(sdp, bh, function, 127 + file, line); 128 + return -EIO; 129 + } 130 + if (unlikely(t != type)) { 131 + gfs2_metatype_check_ii(sdp, bh, type, t, function, 132 + file, line); 133 + return -EIO; 134 + } 131 135 return 0; 132 136 } 133 137 ··· 148 144 } 149 145 150 146 151 - int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, 152 - char *file, unsigned int line); 147 + void gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, 148 + char *file, unsigned int line); 153 149 154 150 int check_journal_clean(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, 155 151 bool verbose); ··· 232 228 233 229 __printf(2, 3) 234 230 void gfs2_lm(struct gfs2_sbd *sdp, const char *fmt, ...); 235 - int gfs2_withdraw(struct gfs2_sbd *sdp); 231 + void gfs2_withdraw(struct gfs2_sbd *sdp); 236 232 237 233 #endif /* __UTIL_DOT_H__ */