From owner-svn-src-all@freebsd.org Wed Jul 29 05:53:50 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 434CD9AE54D; Wed, 29 Jul 2015 05:53:50 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-oi0-x22f.google.com (mail-oi0-x22f.google.com [IPv6:2607:f8b0:4003:c06::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0D94092A; Wed, 29 Jul 2015 05:53:50 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by oibn4 with SMTP id n4so81237101oib.3; Tue, 28 Jul 2015 22:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=HPS9sfsKR31D4pH1LShgmwr3LvgYOoFPbYvSfSdI5yQ=; b=I9PMlyY44NKtUJuf7p+0Q9mPgZcrD0MbAZ+P1dxx7/OiwlwzpJHydwGSIOnZq2bO5l 27hmOJMcCrhPr7Nu72vCCJ3VqZV2Ra0PoPKsNuNYQ8m509cr1zxQCkcbJwGwkSGAKmyC IiKUFf3rkaxXYkxCHnxaZjDlnwqRJx8UFgQHKxJ3NVd+h9X4bKAh1dZdf75TAg7yQn7K 7xP4f6oQQLmPjEpl8GleFK02smm+IJlFNEA8xciPcy5TTwjFCEk6hCTRGNfHVPzlHeeT soAQfEu+MSTfz10IuBrPipiT/9TQ+TJ7LTRDBOe9pMqDZwBLkzOWxgsYycJQlVomfF6D aa9Q== MIME-Version: 1.0 X-Received: by 10.202.73.83 with SMTP id w80mr5223075oia.102.1438149229401; Tue, 28 Jul 2015 22:53:49 -0700 (PDT) Received: by 10.76.58.17 with HTTP; Tue, 28 Jul 2015 22:53:49 -0700 (PDT) In-Reply-To: <201507290226.t6T2Qwp7072379@repo.freebsd.org> References: <201507290226.t6T2Qwp7072379@repo.freebsd.org> Date: Tue, 28 Jul 2015 22:53:49 -0700 Message-ID: Subject: Re: svn commit: r285993 - in head/sys: kern sys ufs/ffs vm From: Conrad Meyer To: Jeff Roberson Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jul 2015 05:53:50 -0000 On Tue, Jul 28, 2015 at 7:26 PM, Jeff Roberson wrote: > Author: jeff > Date: Wed Jul 29 02:26:57 2015 > New Revision: 285993 > URL: https://svnweb.freebsd.org/changeset/base/285993 > > Log: > - Make 'struct buf *buf' private to vfs_bio.c. Having a global variable > 'buf' is inconvenient and has lead me to some irritating to discover > bugs over the years. It also makes it more challenging to refactor > the buf allocation system. > - Move swbuf and declare it as an extern in vfs_bio.c. This is still > not perfect but better than it was before. > - Eliminate the unused ffs function that relied on knowledge of the buf > array. > - Move the shutdown code that iterates over the buf array into vfs_bio.c. > > Reviewed by: kib > Sponsored by: EMC / Isilon Storage Division > > Modified: > head/sys/kern/kern_shutdown.c > head/sys/kern/subr_param.c > head/sys/kern/vfs_bio.c > head/sys/sys/buf.h > head/sys/ufs/ffs/ffs_subr.c > head/sys/vm/vm_pager.c > > ... > > Modified: head/sys/kern/vfs_bio.c > ============================================================================== > --- head/sys/kern/vfs_bio.c Wed Jul 29 02:21:35 2015 (r285992) > +++ head/sys/kern/vfs_bio.c Wed Jul 29 02:26:57 2015 (r285993) > ... This section is #ifdef INVARIANTS, breaking build on non-INVARIANTS kernels (missing bufshutdown): > @@ -958,6 +958,134 @@ vfs_buf_check_mapped(struct buf *bp) > KASSERT(bp->b_data < unmapped_buf || bp->b_data > unmapped_buf + > MAXPHYS, ("b_data + b_offset unmapped %p", bp)); > } > +static int > +isbufbusy(struct buf *bp) > +{ > + if (((bp->b_flags & (B_INVAL | B_PERSISTENT)) == 0 && > + BUF_ISLOCKED(bp)) || > + ((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI)) > + return (1); > + return (0); > +} > + > +/* > + * Shutdown the system cleanly to prepare for reboot, halt, or power off. > + */ > +void > +bufshutdown(int show_busybufs) > +{ > + static int first_buf_printf = 1; > + struct buf *bp; > + int iter, nbusy, pbusy; > +#ifndef PREEMPTION > + int subiter; > +#endif > + > + /* > + * Sync filesystems for shutdown > + */ > + wdog_kern_pat(WD_LASTVAL); > + sys_sync(curthread, NULL); > + > + /* > + * With soft updates, some buffers that are > + * written will be remarked as dirty until other > + * buffers are written. > + */ > + for (iter = pbusy = 0; iter < 20; iter++) { > + nbusy = 0; > + for (bp = &buf[nbuf]; --bp >= buf; ) > + if (isbufbusy(bp)) > + nbusy++; > + if (nbusy == 0) { > + if (first_buf_printf) > + printf("All buffers synced."); > + break; > + } > + if (first_buf_printf) { > + printf("Syncing disks, buffers remaining... "); > + first_buf_printf = 0; > + } > + printf("%d ", nbusy); > + if (nbusy < pbusy) > + iter = 0; > + pbusy = nbusy; > + > + wdog_kern_pat(WD_LASTVAL); > + sys_sync(curthread, NULL); > + > +#ifdef PREEMPTION > + /* > + * Drop Giant and spin for a while to allow > + * interrupt threads to run. > + */ > + DROP_GIANT(); > + DELAY(50000 * iter); > + PICKUP_GIANT(); > +#else > + /* > + * Drop Giant and context switch several times to > + * allow interrupt threads to run. > + */ > + DROP_GIANT(); > + for (subiter = 0; subiter < 50 * iter; subiter++) { > + thread_lock(curthread); > + mi_switch(SW_VOL, NULL); > + thread_unlock(curthread); > + DELAY(1000); > + } > + PICKUP_GIANT(); > +#endif > + } > + printf("\n"); > + /* > + * Count only busy local buffers to prevent forcing > + * a fsck if we're just a client of a wedged NFS server > + */ > + nbusy = 0; > + for (bp = &buf[nbuf]; --bp >= buf; ) { > + if (isbufbusy(bp)) { > +#if 0 > +/* XXX: This is bogus. We should probably have a BO_REMOTE flag instead */ > + if (bp->b_dev == NULL) { > + TAILQ_REMOVE(&mountlist, > + bp->b_vp->v_mount, mnt_list); > + continue; > + } > +#endif > + nbusy++; > + if (show_busybufs > 0) { > + printf( > + "%d: buf:%p, vnode:%p, flags:%0x, blkno:%jd, lblkno:%jd, buflock:", > + nbusy, bp, bp->b_vp, bp->b_flags, > + (intmax_t)bp->b_blkno, > + (intmax_t)bp->b_lblkno); > + BUF_LOCKPRINTINFO(bp); > + if (show_busybufs > 1) > + vn_printf(bp->b_vp, > + "vnode content: "); > + } > + } > + } > + if (nbusy) { > + /* > + * Failed to sync all blocks. Indicate this and don't > + * unmount filesystems (thus forcing an fsck on reboot). > + */ > + printf("Giving up on %d buffers\n", nbusy); > + DELAY(5000000); /* 5 seconds */ > + } else { > + if (!first_buf_printf) > + printf("Final sync complete\n"); > + /* > + * Unmount filesystems > + */ > + if (panicstr == 0) > + vfs_unmountall(); > + } > + swapoff_all(); > + DELAY(100000); /* wait for console output to finish */ > +} Thanks, Conrad