From owner-svn-src-head@freebsd.org Thu Aug 6 15:43:16 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1BC843A579D; Thu, 6 Aug 2020 15:43:16 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BMt7773ybz4GWv; Thu, 6 Aug 2020 15:43:15 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D69059686; Thu, 6 Aug 2020 15:43:15 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 076FhFNN028486; Thu, 6 Aug 2020 15:43:15 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 076FhFbG028485; Thu, 6 Aug 2020 15:43:15 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202008061543.076FhFbG028485@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 6 Aug 2020 15:43:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363960 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 363960 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Aug 2020 15:43:16 -0000 Author: markj Date: Thu Aug 6 15:43:15 2020 New Revision: 363960 URL: https://svnweb.freebsd.org/changeset/base/363960 Log: Clean up reassignbuf() and buf_vlist_remove() a bit. - Convert panic() calls to INVARIANTS-only assertions. The PCTRIE code provides some of the same protection since it will panic upon an attempt to remove a non-resident buffer. - Update the comment above reassignbuf() to reflect reality. Reviewed by: cem, kib, mjg MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25965 Modified: head/sys/kern/vfs_subr.c Modified: head/sys/kern/vfs_subr.c ============================================================================== --- head/sys/kern/vfs_subr.c Thu Aug 6 15:42:59 2020 (r363959) +++ head/sys/kern/vfs_subr.c Thu Aug 6 15:43:15 2020 (r363960) @@ -2256,13 +2256,17 @@ static void buf_vlist_remove(struct buf *bp) { struct bufv *bv; + b_xflags_t flags; + flags = bp->b_xflags; + KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp)); ASSERT_BO_WLOCKED(bp->b_bufobj); - KASSERT((bp->b_xflags & (BX_VNDIRTY|BX_VNCLEAN)) != - (BX_VNDIRTY|BX_VNCLEAN), - ("buf_vlist_remove: Buf %p is on two lists", bp)); - if (bp->b_xflags & BX_VNDIRTY) + KASSERT((flags & (BX_VNDIRTY | BX_VNCLEAN)) != 0 && + (flags & (BX_VNDIRTY | BX_VNCLEAN)) != (BX_VNDIRTY | BX_VNCLEAN), + ("%s: buffer %p has invalid queue state", __func__, bp)); + + if ((flags & BX_VNDIRTY) != 0) bv = &bp->b_bufobj->bo_dirty; else bv = &bp->b_bufobj->bo_clean; @@ -2391,10 +2395,7 @@ brelvp(struct buf *bp) vp = bp->b_vp; /* XXX */ bo = bp->b_bufobj; BO_LOCK(bo); - if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN)) - buf_vlist_remove(bp); - else - panic("brelvp: Buffer %p not on queue.", bp); + buf_vlist_remove(bp); if ((bo->bo_flag & BO_ONWORKLST) && bo->bo_dirty.bv_cnt == 0) { bo->bo_flag &= ~BO_ONWORKLST; mtx_lock(&sync_mtx); @@ -2707,9 +2708,7 @@ syncer_resume(void) } /* - * Reassign a buffer from one vnode to another. - * Used to assign file specific control information - * (indirect blocks) to the vnode to which they belong. + * Move the buffer between the clean and dirty lists of its vnode. */ void reassignbuf(struct buf *bp) @@ -2724,23 +2723,15 @@ reassignbuf(struct buf *bp) vp = bp->b_vp; bo = bp->b_bufobj; + KASSERT((bp->b_flags & B_PAGING) == 0, + ("%s: cannot reassign paging buffer %p", __func__, bp)); + CTR3(KTR_BUF, "reassignbuf(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); - /* - * B_PAGING flagged buffers cannot be reassigned because their vp - * is not fully linked in. - */ - if (bp->b_flags & B_PAGING) - panic("cannot reassign paging buffer"); - /* - * Delete from old vnode list, if on one. - */ BO_LOCK(bo); - if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN)) - buf_vlist_remove(bp); - else - panic("reassignbuf: Buffer %p not on queue.", bp); + buf_vlist_remove(bp); + /* * If dirty, put on list of dirty buffers; otherwise insert onto list * of clean buffers.