NetBSD Problem Report #55601

From abs@absd.org  Sun Aug 23 23:04:27 2020
Return-Path: <abs@absd.org>
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 9FA9D1A923A
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 23 Aug 2020 23:04:27 +0000 (UTC)
Message-Id: <20200823220409.1DD4F435F8@iris.absd.org>
Date: Sun, 23 Aug 2020 23:04:09 +0100 (BST)
From: abs@absd.org
Reply-To: abs@absd.org
To: gnats-bugs@NetBSD.org
Subject: Unable to destroy gpt on disk with invalid GPT
X-Send-Pr-Version: 3.95

>Number:         55601
>Category:       bin
>Synopsis:       Unable to destroy gpt on disk with invalid GPT
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 23 23:05:00 +0000 2020
>Last-Modified:  Mon Aug 24 07:00:01 +0000 2020
>Originator:     David Brownlee
>Release:        NetBSD 9.0_STABLE
>Organization:

>Environment:


System: NetBSD iris.absd.org 9.0_STABLE NetBSD 9.0_STABLE (GENERIC) #0: Thu Aug 20 16:16:33 UTC 2020 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
        I have a disk component on an mfii controller which is half of a
        previous raid0 instance. As such it has an invalig GPT which
        represents a disk twice its size
	Unfortunately I cannot destroy the gpt:

        # gpt -v destroy sd3
        /dev/rsd3: mediasize=8000987201536; sectorsize=512; blocks=15626928128
        gpt: /dev/rsd3: map entry doesn't fit media: new start + new size < start + size
        (22 + 3a36fffde < 800 + 746dff000)

        Resize disk suffers similarly
>How-To-Repeat:
        Boot with an invalid GPT which describes a larger disk and then
        try to destroy it to create a valid GPT
>Fix:


>Audit-Trail:
From: Robert Elz <kre@munnari.OZ.AU>
To: abs@absd.org
Cc: gnats-bugs@netbsd.org
Subject: Re: bin/55601: Unable to destroy gpt on disk with invalid GPT
Date: Mon, 24 Aug 2020 13:58:16 +0700

 Can you try the following patch?

 (For a bunch of reasons I'm not in a position to actually test this
 right now, but I think it should work).

 It applies (to HEAD) in src/sbin/gpt

 kre

 ps: the spaces in the #define of GPT_OPTDEV in gpt.h should be changed to
 a tab, but that has nothing to do with this issue.

 Index: destroy.c
 ===================================================================
 RCS file: /cvsroot/src/sbin/gpt/destroy.c,v
 retrieving revision 1.13
 diff -u -r1.13 destroy.c
 --- destroy.c	16 Oct 2019 19:03:53 -0000	1.13
 +++ destroy.c	24 Aug 2020 06:53:52 -0000
 @@ -59,7 +59,7 @@
  	"destroy",
  	cmd_destroy,
  	destroyhelp, __arraycount(destroyhelp),
 -	GPT_SYNC,
 +	GPT_IGNORE | GPT_SYNC,
  };

  #define usage() gpt_usage(NULL, &c_destroy)
 Index: gpt.c
 ===================================================================
 RCS file: /cvsroot/src/sbin/gpt/gpt.c,v
 retrieving revision 1.82
 diff -u -r1.82 gpt.c
 --- gpt.c	24 May 2020 18:42:20 -0000	1.82
 +++ gpt.c	24 Aug 2020 06:53:53 -0000
 @@ -569,6 +569,9 @@
  	if (map_init(gpt, devsz) == -1)
  		goto close;

 +	if (flags & GPT_IGNORE)
 +		return gpt;
 +
  	index = 1;
  	if (gpt_mbr(gpt, 0LL, &index, 0U) == -1)
  		goto close;
 Index: gpt.h
 ===================================================================
 RCS file: /cvsroot/src/sbin/gpt/gpt.h,v
 retrieving revision 1.42
 diff -u -r1.42 gpt.h
 --- gpt.h	24 May 2020 18:42:20 -0000	1.42
 +++ gpt.h	24 Aug 2020 06:53:53 -0000
 @@ -85,6 +85,7 @@
  #define GPT_TIMESTAMP	0x20
  #define GPT_SYNC	0x40
  #define GPT_HYBRID	0x80
 +#define GPT_IGNORE	0x4000
  #define GPT_OPTDEV      0x8000

  void*	gpt_read(gpt_t, off_t, size_t);


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.