Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fW2ur-0004GB-4x for mharc-grub-devel@gnu.org; Thu, 21 Jun 2018 12:58:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47115) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fW2uo-0004EB-OG for grub-devel@gnu.org; Thu, 21 Jun 2018 12:58:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fW2ul-0000T8-Kh for grub-devel@gnu.org; Thu, 21 Jun 2018 12:58:34 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:41156) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fW2ul-0000SV-Co for grub-devel@gnu.org; Thu, 21 Jun 2018 12:58:31 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5LGnjqq043095; Thu, 21 Jun 2018 16:58:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : content-transfer-encoding : in-reply-to; s=corp-2017-10-26; bh=lrKA10zJz0ch+z+JQjYcxnHroKsFGVoA92dNr2ntcGc=; b=W7eHUB7FFJvc+MDQr1HS1a7zjeAPe06AcPBR/e12YUHN/OsiSBMqwAs8wuwV4NR+FzC1 kyZallyDpKGQx+KnVEfdInh7Pm871FH3VuWbUGQUGGSgx+TrpdLMNFBpJqZEoGZ1P7K0 JMhqMFte3lDy0oA93W4dEjkPCi+bQyiuNca58tDdIEzlboBL3CLZliKJlGJucb79tXGi 78h3wH4HA6IRJJZrHVjhqUPtw8xSxTpAA+aoUcf7Mo8anRs41TuwpJKGAVrhDfoDEPbL M5O8kFHvH/XHKMF4M6QhRL/xDfUdaWCTQOJruSNo6Z3gR1MUwfAdProat0WEA04xRQmx gQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2jmtgx1m34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Jun 2018 16:58:28 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w5LGwRrS029925 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Jun 2018 16:58:27 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w5LGwQon032030; Thu, 21 Jun 2018 16:58:26 GMT Received: from olila.local.net-space.pl (/10.175.200.249) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 21 Jun 2018 09:58:25 -0700 Date: Thu, 21 Jun 2018 18:58:22 +0200 From: Daniel Kiper To: Eric Snowberg Cc: The development of GNU GRUB , John Paul Adrian Glaubitz Subject: Re: [PATCH v2] ieee1275: obdisk driver Message-ID: <20180621165822.GA20016@olila.local.net-space.pl> References: <1527724522-32305-1-git-send-email-eric.snowberg@oracle.com> <20180615120218.GO20016@olila.local.net-space.pl> <3C2AB209-D05C-4C0C-B2D9-FF3C0AD7B2E7@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <3C2AB209-D05C-4C0C-B2D9-FF3C0AD7B2E7@oracle.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8931 signatures=668703 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806210183 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by aserp2120.oracle.com id w5LGnjqq043095 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jun 2018 16:58:36 -0000 On Fri, Jun 15, 2018 at 09:58:56AM -0600, Eric Snowberg wrote: > > On Jun 15, 2018, at 6:02 AM, Daniel Kiper w= rote: > > On Wed, May 30, 2018 at 04:55:22PM -0700, Eric Snowberg wrote: [...] > >> +static struct grub_scsi_test_unit_ready tur =3D > >> +{ > >> + .opcode =3D grub_scsi_cmd_test_unit_ready, > >> + .lun =3D 0, > >> + .reserved1 =3D 0, > >> + .reserved2 =3D 0, > >> + .reserved3 =3D 0, > >> + .control =3D 0, > >> +}; > >> + > >> +static int disks_enumerated =3D 0; > >> +static struct disk_dev *disk_devs =3D NULL; > >> +static struct parent_dev *parent_devs =3D NULL; > > > > I would drop all these 0/NULL initializations. > > Compiler will do work for you. I asked about > > that in earlier comments. > > I thought I changed everything I could without getting the warning > Adrian found. I=E2=80=99ll try to drop these. Thanks. [...] > >> +static char * > >> +replace_escaped_commas (char *src) > >> +{ > >> + char *iptr; > >> + > >> + if (src =3D=3D NULL) > >> + return NULL; > >> + for (iptr =3D src; *iptr; ) > >> + { > >> + if ((*iptr =3D=3D '\\') && (*(iptr + 1) =3D=3D ',')) > >> + { > >> + *iptr++ =3D '_'; > >> + *iptr++ =3D '_'; > >> + } > >> + iptr++; > >> + } > >> + > >> + return src; > >> +} > >> + > >> +static int > >> +count_commas (const char *src) > >> +{ > >> + int count =3D 0; > >> + > >> + for ( ; *src; src++) > >> + if (*src =3D=3D ',') > >> + count++; > >> + > >> + return count; > >> +} > >> + > >> +static void > >> +escape_commas (const char *src, char *dest) > > > > I am confused by this play with commas. Could explain somewhere > > where this commas are needed unescaped, escaped, replaced, etc. > > Could not we simplify this somehow? > > I=E2=80=99m open for recommendations. Great! However, I need more info which layer need what WRT ",", how often this conversions must be done, why you have chosen that solution, etc. Then I will try to optimize solution a bit. [...] > >> +static grub_err_t > >> +add_disk (const char *path) > >> +{ > >> + grub_err_t ret =3D GRUB_ERR_NONE; > >> + struct disk_dev *dev; > >> + char *canon; > >> + > >> + canon =3D canonicalise_disk (path); > >> + dev =3D grub_named_list_find (GRUB_AS_NAMED_LIST (disk_devs), can= on); > >> + > >> + if ((canon !=3D NULL) && (dev =3D=3D NULL)) > >> + { > >> + struct disk_dev *ob_device; > >> + > >> + ob_device =3D add_canon_disk (canon); > >> + > >> + if (ob_device =3D=3D NULL) > >> + ret =3D grub_error (GRUB_ERR_OUT_OF_MEMORY, "failure to add= disk"); > >> + } > >> + else if (dev) > >> + dev->valid =3D 1; > > > > What will happen if canon =3D=3D NULL? > > dev will always be equal to NULL in that case so nothing would happen > other than the error being printed. But I supposed it would be better > to have a final =E2=80=9Celse" after the "else if" and set ret =3D grub= _error > with GRUB_ERR_BAD_DEVICE. Please do if you can. [...] > >> + grub_free (canon); > >> + return (ret); > >> +} > >> + > >> +static grub_err_t > >> +grub_obdisk_read (grub_disk_t disk, grub_disk_addr_t sector, > >> + grub_size_t size, char *dest) > >> +{ > >> + grub_err_t ret =3D GRUB_ERR_NONE; > >> + struct disk_dev *dev; > >> + unsigned long long pos; > >> + grub_ssize_t result =3D 0; > >> + > >> + if (disk->data =3D=3D NULL) > >> + return grub_error (GRUB_ERR_BAD_DEVICE, "invalid disk data"); > >> + > >> + dev =3D (struct disk_dev *)disk->data; > >> + pos =3D sector << disk->log_sector_size; > >> + grub_ieee1275_seek (dev->ihandle, pos, &result); > >> + > >> + if (result < 0) > >> + { > >> + dev->opened =3D 0; > >> + return grub_error (GRUB_ERR_READ_ERROR, "seek error, can't se= ek block %llu", > >> + (long long) sector); > >> + } > >> + > >> + grub_ieee1275_read (dev->ihandle, dest, size << disk->log_sector_= size, > >> + &result); > >> + > >> + if (result !=3D (grub_ssize_t) (size << disk->log_sector_size)) > >> + { > >> + dev->opened =3D 0; > >> + return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading s= ector 0x%llx " > >> + "from `%s'"), > >> + (unsigned long long) sector, > >> + disk->name); > >> + } > >> + return ret; > >> +} > >> + > >> +static void > >> +grub_obdisk_close (grub_disk_t disk) > > > > s/grub_obdisk_close/grub_obdisk_clear/? > > It really is a close as far as the grub driver is concerned > (grub_disk_dev). If you insist I=E2=80=99ll change it, but naming it cl= ear > doesn't make sense to me. If similar functions in other drivers do just memset() or so and they are named *close* then I am not going to insist. If it is not true then I will ask you to do that change. [...] > >> +static void > >> +iterate_devtree (const struct grub_ieee1275_devalias *alias) > >> +{ > >> + struct grub_ieee1275_devalias child; > >> + > >> + if ((grub_strcmp (alias->type, "scsi-2") =3D=3D 0) || > >> + (grub_strcmp (alias->type, "scsi-sas") =3D=3D 0)) > >> + return scan_sparc_sas_disk (alias->path); > >> + > >> + else if (grub_strcmp (alias->type, "nvme") =3D=3D 0) > >> + return scan_nvme_disk (alias->path); > >> + > >> + else if (grub_strcmp (alias->type, "scsi-usb") =3D=3D 0) > >> + return scan_usb_disk (alias->path); > >> + > >> + else if (grub_strcmp (alias->type, "block") =3D=3D 0) > >> + { > >> + const char **bl =3D block_blacklist; > >> + > >> + while (*bl !=3D NULL) > >> + { > >> + if (grub_strstr (alias->path, *bl)) > >> + return; > >> + bl++; > >> + } > >> + > >> + add_disk (alias->path); > >> + return; > >> + } > >> + > >> + FOR_IEEE1275_DEVCHILDREN (alias->path, child) > >> + iterate_devtree (&child); > >> +} > >> + > >> +static void > >> +unescape_devices (void) > > > > Why? > > Many SPARC disks contain a comma within the name. Code from various > layers above this driver handle the comma differently. At times they > will strip everything to the right of the comma. The solution I came > up with here is self contained and will not impact generic grub2 code. > So far it seems to work from all reports I've seen. Great! Though I have feeling that there is still room for some optimizations. At least we should try to do it... Daniel