From owner-freebsd-geom@FreeBSD.ORG Sun Aug 22 09:19:36 2010 Return-Path: Delivered-To: freebsd-geom@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4CB5C1065694; Sun, 22 Aug 2010 09:19:36 +0000 (UTC) (envelope-from bu7cher@yandex.ru) Received: from forward10.mail.yandex.net (forward10.mail.yandex.net [77.88.61.49]) by mx1.freebsd.org (Postfix) with ESMTP id D03AE8FC1B; Sun, 22 Aug 2010 09:19:35 +0000 (UTC) Received: from smtp6.mail.yandex.net (smtp6.mail.yandex.net [77.88.61.56]) by forward10.mail.yandex.net (Yandex) with ESMTP id 079F11F503A7; Sun, 22 Aug 2010 13:19:34 +0400 (MSD) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1282468774; bh=TXi7Bp5AUDLEP1niYGGaTcVU6M7fEDYA4Qtscu4UcDg=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:Content-Type; b=HVdYz7KB8AyqpLU3xUf+fpFEOdybn4mxgvDcLm9acdknB4zmS4kLtikkuxal/QxPJ 5Jy7FuIOF/P7EWaHIsTJCzAvKAiHChRwQsZR2pOX1XRNzyMFEyoE0cyjOD+bAuG/j4 pJOdNq72/vFzZH1A65LXdwpYT515en1K/GOAAhks= Received: from [10.43.163.197] (bu7cher.heavennet.ru [92.39.76.197]) by smtp6.mail.yandex.net (Yandex) with ESMTPSA id 9AA3932809C; Sun, 22 Aug 2010 13:19:33 +0400 (MSD) Message-ID: <4C70EB80.5050901@yandex.ru> Date: Sun, 22 Aug 2010 13:18:56 +0400 From: "Andrey V. Elsukov" User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.8) Gecko/20100806 Thunderbird/3.1.2 MIME-Version: 1.0 To: freebsd-geom@freebsd.org X-Enigmail-Version: 1.1.2 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigE94F7561C954C44902BF8BBC" X-Yandex-TimeMark: 1282468773 X-Yandex-Spam: 1 X-Yandex-Front: smtp6.mail.yandex.net Cc: Alexander Motin , Marcel Moolenaar , Konstantin Belousov Subject: RFC: destroying non empty partition tables with gpart(8) X-BeenThere: freebsd-geom@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: GEOM-specific discussions and implementations List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Aug 2010 09:19:36 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigE94F7561C954C44902BF8BBC Content-Type: multipart/mixed; boundary="------------070603030901060605090502" This is a multi-part message in MIME format. --------------070603030901060605090502 Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: quoted-printable Hi All. I think gpart(8) is default way to create partition tables and manage partitions in head/ and stable/8. Now when you want to destroy partition table you should delete all partitions from it. This is not so bad, but i made a patch that add ability destroy table with auto deleting all partitions. For example: # gpart destroy -r ada1 I did it in user space, it just delete all partition entries before destroying table. At this time if deleting of some partition failed you can do `gpart undo ada1` and all already deleted by last command partition will be restored. It seems usable for me. Any comments? --=20 WBR, Andrey V. Elsukov --------------070603030901060605090502 Content-Type: text/plain; name="gpart_recursive_destroy.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="gpart_recursive_destroy.diff" Index: head/sbin/geom/class/part/geom_part.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- head/sbin/geom/class/part/geom_part.c (revision 211453) +++ head/sbin/geom/class/part/geom_part.c (working copy) @@ -68,6 +68,7 @@ static char ssize[32]; static const char const bootcode_param[] =3D "bootcode"; static const char const index_param[] =3D "index"; static const char const partcode_param[] =3D "partcode"; +static const char const recursive_param[] =3D "recursive"; =20 static struct gclass *find_class(struct gmesh *, const char *); static struct ggeom * find_geom(struct gclass *, const char *); @@ -85,6 +86,8 @@ static void gpart_show_geom(struct ggeom *, const static int gpart_show_hasopt(struct gctl_req *, const char *, const char= *); static void gpart_write_partcode(struct ggeom *, int, void *, ssize_t); static void gpart_write_partcode_vtoc8(struct ggeom *, int, void *); +static void gpart_destroy(struct gctl_req *, unsigned int); +static void gpart_print_error(const char *); =20 struct g_command PUBSYM(class_commands)[] =3D { { "add", 0, gpart_issue, { @@ -119,7 +122,8 @@ struct g_command PUBSYM(class_commands)[] =3D { G_OPT_SENTINEL }, "geom", NULL }, - { "destroy", 0, gpart_issue, { + { "destroy", 0, gpart_destroy, { + { 'r', recursive_param, NULL, G_TYPE_BOOL }, { 'f', "flags", flags, G_TYPE_STRING }, G_OPT_SENTINEL }, "geom", NULL }, @@ -852,10 +856,87 @@ gpart_bootcode(struct gctl_req *req, unsigned int } =20 static void +gpart_destroy(struct gctl_req *req, unsigned int fl) +{ + struct gmesh mesh; + struct gclass *classp; + struct gctl_req *req2; + struct ggeom *gp; + struct gprovider *pp; + const char *s; + int error, val; + + if (gctl_has_param(req, recursive_param)) { + val =3D gctl_get_int(req, recursive_param); + error =3D gctl_delete_param(req, recursive_param); + if (error) + errc(EXIT_FAILURE, error, "internal error"); + if (val =3D=3D 0) + goto done; + s =3D gctl_get_ascii(req, "class"); + if (s =3D=3D NULL) + abort(); + error =3D geom_gettree(&mesh); + if (error !=3D 0) + errc(EXIT_FAILURE, error, "Cannot get GEOM tree"); + classp =3D find_class(&mesh, s); + if (classp =3D=3D NULL) { + geom_deletetree(&mesh); + errx(EXIT_FAILURE, "Class %s not found.", s); + } + s =3D gctl_get_ascii(req, "geom"); + if (s =3D=3D NULL) + abort(); + gp =3D find_geom(classp, s); + if (gp =3D=3D NULL) + errx(EXIT_FAILURE, "No such geom: %s.", s); + LIST_FOREACH(pp, &gp->lg_provider, lg_provider){ + s =3D find_provcfg(pp, "index"); + if (s =3D=3D NULL) + errx(EXIT_FAILURE, "Index not found for %s.", + pp->lg_name); + req2 =3D gctl_get_handle(); + gctl_ro_param(req2, "verb", -1, "delete"); + gctl_ro_param(req2, "class", -1, classp->lg_name); + gctl_ro_param(req2, "geom", -1, gp->lg_name); + gctl_ro_param(req2, "index", -1, s); + gctl_ro_param(req2, "flags", -1, "XXX"); + s =3D gctl_issue(req2); + if (s !=3D NULL && s[0] !=3D '\0') { + gpart_print_error(s); + exit(EXIT_FAILURE); + } + gctl_free(req2); + } + geom_deletetree(&mesh); + } +done: + gpart_issue(req, fl); +} + + +static void +gpart_print_error(const char *errstr) +{ + char *errmsg; + int error; + + error =3D strtol(errstr, &errmsg, 0); + if (errmsg !=3D errstr) { + while (errmsg[0] =3D=3D ' ') + errmsg++; + if (errmsg[0] !=3D '\0') + warnc(error, "%s", errmsg); + else + warnc(error, NULL); + } else + warnx("%s", errmsg); +} + +static void gpart_issue(struct gctl_req *req, unsigned int fl __unused) { char buf[4096]; - char *errmsg; const char *errstr; int error, status; =20 @@ -876,20 +957,8 @@ gpart_issue(struct gctl_req *req, unsigned int fl status =3D EXIT_SUCCESS; goto done; } - - error =3D strtol(errstr, &errmsg, 0); - if (errmsg !=3D errstr) { - while (errmsg[0] =3D=3D ' ') - errmsg++; - if (errmsg[0] !=3D '\0') - warnc(error, "%s", errmsg); - else - warnc(error, NULL); - } else - warnx("%s", errmsg); - + gpart_print_error(errstr); status =3D EXIT_FAILURE; - done: gctl_free(req); exit(status); --------------070603030901060605090502-- --------------enigE94F7561C954C44902BF8BBC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (FreeBSD) iQEcBAEBAgAGBQJMcOuGAAoJEAHF6gQQyKF6BU8H/2cTI93h5b0qs881FBfoc5S6 gW+OAZ5rOx7LQZiqAYtTHmy4RkjEnnjpWVBbHsz0uzJb2+D5oqtaxUFWM2uA3z94 0uOzQpCwgQ5drkdnG/ok81WenNeZlH7TP71pl3P8GhAxkjnY5/Hdy54KXHqlEkl4 406RkkuBnLFxaIGe65IXNk8jN6DPY+JXp6XKuAWb7iW5Igjztbc9/jjP+Mgn7K1y cSd3QtziOVbWmZqtZ4Hzxr0trIHiAELQDkZLAaCbh11cdmcuQ1uFfwoRicUSVmY1 GnfcDShAwjTv05ldEwF93P8kAaG4zuiJsQKMtoBWuHaVgdOqfXKN3q+Y7pQKwuo= =/unY -----END PGP SIGNATURE----- --------------enigE94F7561C954C44902BF8BBC--