NetBSD Problem Report #52814

From taca@a.back-street.net  Wed Dec 13 07:04:58 2017
Return-Path: <taca@a.back-street.net>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 17E2F7A1CC
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 13 Dec 2017 07:04:58 +0000 (UTC)
Message-Id: <20171213070439.4072510573F@currnet.a.back-street.net>
Date: Wed, 13 Dec 2017 16:04:39 +0900 (JST)
From: taca@back-street.net
Reply-To: taca@back-street.net
To: gnats-bugs@NetBSD.org
Subject: WD_SOFTBADSECT option cause build error
X-Send-Pr-Version: 3.95

>Number:         52814
>Category:       kern
>Synopsis:       WD_SOFTBADSECT kernel option cause build error
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pgoyette
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 13 07:05:00 +0000 2017
>Closed-Date:    Wed Dec 13 10:26:37 +0000 2017
>Last-Modified:  Wed Dec 13 21:25:00 +0000 2017
>Originator:     Takahiro Kambe
>Release:        NetBSD 8.99.5
>Organization:

>Environment:


System: NetBSD currnet.a.back-street.net 8.99.5 NetBSD 8.99.5 (GENERIC) #10: Thu Oct 26 18:29:39 JST 2017 taca@currnet.a.back-street.net:/data/amd64/obj/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
	WD_SOFTBADSECT kernel option cause build error
>How-To-Repeat:
	Set WD_SOFTBADSECT in your kernel configuration file.

Don't forget to run "make depend"
depending the kern library objects
depending the compat library objects
making sure the compat library is up to date...
    compile  HPMICRO/wd.o
`libcompat.a' is up to date.
    compile  HPMICRO/wsdisplay_compat_usl.o
In file included from /usr/src/sys/sys/timevar.h:64:0,
                 from /usr/src/sys/sys/time.h:307,
                 from /usr/src/sys/sys/param.h:145,
                 from /usr/src/sys/dev/ata/wd.c:62:
/usr/src/sys/dev/ata/wd.c: In function 'wddetach':
/usr/src/sys/dev/ata/wd.c:538:23: error: 'sc' undeclared (first use in this function)
  while (!SLIST_EMPTY(&sc->sc_bslist)) {
                       ^
/usr/src/sys/sys/queue.h:124:29: note: in definition of macro 'SLIST_EMPTY'
 #define SLIST_EMPTY(head) ((head)->slh_first == NULL)
                             ^
/usr/src/sys/dev/ata/wd.c:538:23: note: each undeclared identifier is reported only once for each function it appears in
  while (!SLIST_EMPTY(&sc->sc_bslist)) {
                       ^
/usr/src/sys/sys/queue.h:124:29: note: in definition of macro 'SLIST_EMPTY'
 #define SLIST_EMPTY(head) ((head)->slh_first == NULL)
                             ^
/usr/src/sys/dev/ata/wd.c: In function 'wdstrategy':
/usr/src/sys/dev/ata/wd.c:589:20: error: 'blkno' undeclared (first use in this function)
   daddr_t maxblk = blkno + (bp->b_bcount / wd->sc_blksize) - 1;
                    ^
--- wd.o ---
*** [wd.o] Error code 1

nbmake: stopped in /data/amd64/obj/sys/arch/amd64/compile/HPMICRO
1 error

nbmake: stopped in /data/amd64/obj/sys/arch/amd64/compile/HPMICRO

ERROR: Failed to make all in "/data/amd64/obj/sys/arch/amd64/compile/HPMICRO"
*** BUILD ABORTED ***

>Fix:


>Release-Note:

>Audit-Trail:
From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: kern/52814: WD_SOFTBADSECT option cause build error
Date: Wed, 13 Dec 2017 15:26:08 +0800 (+08)

 Looks like (based on WD_SOFTBADSECT code elsewhere), the sc in this 
 block should really be the wdsc.

 Perhaps try the following?

 Index: wd.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/ata/wd.c,v
 retrieving revision 1.436
 diff -u -p -r1.436 wd.c
 --- wd.c        7 Nov 2017 04:09:08 -0000       1.436
 +++ wd.c        13 Dec 2017 07:24:42 -0000
 @@ -535,9 +535,9 @@ wddetach(device_t self, int flags)

   #ifdef WD_SOFTBADSECT
   	/* Clean out the bad sector list */
 -	while (!SLIST_EMPTY(&sc->sc_bslist)) {
 -		void *head = SLIST_FIRST(&sc->sc_bslist);
 -		SLIST_REMOVE_HEAD(&sc->sc_bslist, dbs_next);
 +	while (!SLIST_EMPTY(&wd->sc_bslist)) {
 +		void *head = SLIST_FIRST(&wd->sc_bslist);
 +		SLIST_REMOVE_HEAD(&wd->sc_bslist, dbs_next);
   		free(head, M_TEMP);
   	}
          sc->sc_bscount = 0;




 +------------------+--------------------------+----------------------------+
 | Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:          |
 | (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee dot com   |
 | Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd dot org |
 +------------------+--------------------------+----------------------------+

From: Takahiro Kambe <taca@back-street.net>
To: gnats-bugs@NetBSD.org, paul@whooppee.com
Cc: 
Subject: Re: kern/52814: WD_SOFTBADSECT option cause build error
Date: Wed, 13 Dec 2017 16:51:49 +0900 (JST)

 In message <20171213073001.5E64D7A1FF@mollari.NetBSD.org>
 	on Wed, 13 Dec 2017 07:30:01 +0000 (UTC),
 	Paul Goyette <paul@whooppee.com> wrote:
 >  Looks like (based on WD_SOFTBADSECT code elsewhere), the sc in this 
 >  block should really be the wdsc.
 >  
 >  Perhaps try the following?
 It is not enough to fix below error.

 >> /usr/src/sys/dev/ata/wd.c: In function 'wdstrategy':
 >> /usr/src/sys/dev/ata/wd.c:589:20: error: 'blkno' undeclared (first use in this function)
 >>    daddr_t maxblk = blkno + (bp->b_bcount / wd->sc_blksize) - 1;

 -- 
 Takahiro Kambe <taca@back-street.net>

From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: kern/52814: WD_SOFTBADSECT option cause build error
Date: Wed, 13 Dec 2017 18:11:21 +0800 (+08)

 On Wed, 13 Dec 2017, Paul Goyette wrote:

 > Looks like (based on WD_SOFTBADSECT code elsewhere), the sc in this block 
 > should really be the wdsc.
 >
 > Perhaps try the following?

 Here is a more complete patch which should help:

 Index: wd.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/ata/wd.c,v
 retrieving revision 1.436
 diff -u -p -r1.436 wd.c
 --- wd.c	7 Nov 2017 04:09:08 -0000	1.436
 +++ wd.c	13 Dec 2017 10:10:21 -0000
 @@ -535,9 +535,9 @@ wddetach(device_t self, int flags)

   #ifdef WD_SOFTBADSECT
   	/* Clean out the bad sector list */
 -	while (!SLIST_EMPTY(&sc->sc_bslist)) {
 -		void *head = SLIST_FIRST(&sc->sc_bslist);
 -		SLIST_REMOVE_HEAD(&sc->sc_bslist, dbs_next);
 +	while (!SLIST_EMPTY(&wd->sc_bslist)) {
 +		void *head = SLIST_FIRST(&wd->sc_bslist);
 +		SLIST_REMOVE_HEAD(&wd->sc_bslist, dbs_next);
   		free(head, M_TEMP);
   	}
   	sc->sc_bscount = 0;
 @@ -586,11 +586,13 @@ wdstrategy(struct buf *bp)
   	 */
   	if (__predict_false(!SLIST_EMPTY(&wd->sc_bslist))) {
   		struct disk_badsectors *dbs;
 -		daddr_t maxblk = blkno + (bp->b_bcount / wd->sc_blksize) - 1;
 +		daddr_t maxblk = bp->b_rawblkno +
 +		    (bp->b_bcount / wd->sc_blksize) - 1;

   		mutex_enter(&wd->sc_lock);
   		SLIST_FOREACH(dbs, &wd->sc_bslist, dbs_next)
 -			if ((dbs->dbs_min <= blkno && blkno <= dbs->dbs_max) ||
 +			if ((dbs->dbs_min <= bp->b_rawblkno &&
 +			     bp->b_rawblkno <= dbs->dbs_max) ||
   			    (dbs->dbs_min <= maxblk && maxblk <= dbs->dbs_max)){
   				mutex_exit(&wd->sc_lock);
   				goto err;





 +------------------+--------------------------+----------------------------+
 | Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:          |
 | (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee dot com   |
 | Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd dot org |
 +------------------+--------------------------+----------------------------+

From: "Paul Goyette" <pgoyette@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52814 CVS commit: src/sys/dev/ata
Date: Wed, 13 Dec 2017 10:24:31 +0000

 Module Name:	src
 Committed By:	pgoyette
 Date:		Wed Dec 13 10:24:31 UTC 2017

 Modified Files:
 	src/sys/dev/ata: wd.c

 Log Message:
 Fix build for WD_SOFTBADSECT option.  PR kern/52814

 XXX No clue if this option actually works.  This fix just makes it
 XXX compile without error.


 To generate a diff of this commit:
 cvs rdiff -u -r1.436 -r1.437 src/sys/dev/ata/wd.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

Responsible-Changed-From-To: kern-bug-people->pgoyette
Responsible-Changed-By: pgoyette@NetBSD.org
Responsible-Changed-When: Wed, 13 Dec 2017 10:26:37 +0000
Responsible-Changed-Why:
I handled it


State-Changed-From-To: open->closed
State-Changed-By: pgoyette@NetBSD.org
State-Changed-When: Wed, 13 Dec 2017 10:26:37 +0000
State-Changed-Why:
Fix committed - once again this code will build (at least on amd64).  I
have no clue if it actually works or not.


From: mlelstv@serpens.de (Michael van Elst)
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/52814: WD_SOFTBADSECT option cause build error
Date: Wed, 13 Dec 2017 17:23:28 -0000 (UTC)

 taca@back-street.net writes:

 >/usr/src/sys/dev/ata/wd.c: In function 'wdstrategy':
 >/usr/src/sys/dev/ata/wd.c:589:20: error: 'blkno' undeclared (first use in this function)
 >   daddr_t maxblk = blkno + (bp->b_bcount / wd->sc_blksize) - 1;

 Maybe this:

 Index: sys/dev/ata/wd.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/ata/wd.c,v
 retrieving revision 1.436
 diff -p -u -r1.436 wd.c
 --- sys/dev/ata/wd.c	7 Nov 2017 04:09:08 -0000	1.436
 +++ sys/dev/ata/wd.c	13 Dec 2017 17:22:47 -0000
 @@ -535,12 +535,12 @@ wddetach(device_t self, int flags)

  #ifdef WD_SOFTBADSECT
  	/* Clean out the bad sector list */
 -	while (!SLIST_EMPTY(&sc->sc_bslist)) {
 -		void *head = SLIST_FIRST(&sc->sc_bslist);
 -		SLIST_REMOVE_HEAD(&sc->sc_bslist, dbs_next);
 +	while (!SLIST_EMPTY(&wd->sc_bslist)) {
 +		void *head = SLIST_FIRST(&wd->sc_bslist);
 +		SLIST_REMOVE_HEAD(&wd->sc_bslist, dbs_next);
  		free(head, M_TEMP);
  	}
 -	sc->sc_bscount = 0;
 +	wd->sc_bscount = 0;
  #endif

  	pmf_device_deregister(self);
 @@ -585,8 +585,18 @@ wdstrategy(struct buf *bp)
  	 * up failing again.
  	 */
  	if (__predict_false(!SLIST_EMPTY(&wd->sc_bslist))) {
 +		struct disklabel *lp = dksc->sc_dkdev.dk_label;
  		struct disk_badsectors *dbs;
 -		daddr_t maxblk = blkno + (bp->b_bcount / wd->sc_blksize) - 1;
 +		daddr_t blkno, maxblk;
 +
 +		/* convert the block number to absolute */
 +		if (lp->d_secsize >= DEV_BSIZE)
 +			blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
 +		else
 +			blkno = bp->b_blkno * (DEV_BSIZE / lp->d_secsize);
 +		if (WDPART(bp->b_dev) != RAW_PART)
 +			blkno += lp->d_partitions[WDPART(bp->b_dev)].p_offset;
 +		maxblk = blkno + (bp->b_bcount / wd->sc_blksize) - 1;

  		mutex_enter(&wd->sc_lock);
  		SLIST_FOREACH(dbs, &wd->sc_bslist, dbs_next)
 -- 
 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

From: mlelstv@serpens.de (Michael van Elst)
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/52814: WD_SOFTBADSECT option cause build error
Date: Wed, 13 Dec 2017 21:19:31 -0000 (UTC)

 paul@whooppee.com (Paul Goyette) writes:

 > Here is a more complete patch which should help:
 > 
 > -		daddr_t maxblk = blkno + (bp->b_bcount / wd->sc_blksize) - 1;
 > +		daddr_t maxblk = bp->b_rawblkno +
 > +		    (bp->b_bcount / wd->sc_blksize) - 1;

 Unfortunately the computation of b_rawblkno has been factored into
 dk_strategy which is called only afterwards. See my patch...


 -- 
 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.