Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fvNbU-0005EW-9p for mharc-grub-devel@gnu.org; Thu, 30 Aug 2018 10:07:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fvNbP-000535-Bd for grub-devel@gnu.org; Thu, 30 Aug 2018 10:07:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fvNbI-0007Un-1h for grub-devel@gnu.org; Thu, 30 Aug 2018 10:07:15 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:50632) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fvNbH-0007Rl-Jc for grub-devel@gnu.org; Thu, 30 Aug 2018 10:07:07 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w7UE4UnE139394; Thu, 30 Aug 2018 14:07:04 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-2018-07-02; bh=e3eUfkbSxQuGLuoCNjfC7jXBbzh3ni09tetnk7XqUhk=; b=rLnS9eDA969ZOxYU+1iN7IIIrEurnyuE/SL5/OJkwF6jA8J1hM3Tbe5la6AAixST3VNB wM5o7hM7c5o2+EemweMVLDa24q1v7LwXDZVXfQ5zfSyj+dg12IFZ9FIYuPDw5bahCBoI bdyvzSHPltenMcXIbzdYAXj6LVViMUX+r0lOts/Y64DLS2PUunHiND8cKkZQcS8Lm/Xa OL9lm0cUTfr6Nt35/Y2P11wNTyzPMxnArc7FDAD7NiVZ5qMUsJD10VnkdgUa/BEn378d HA7ULMzRsAq1PpREvpM3FA15c2gyVZoGlWFNO2EroEbJNDqL3GhtgAhtMwwooUIoz1AD iQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2m2yrqjkdm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Aug 2018 14:07:04 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w7UE6wwI004848 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Aug 2018 14:06:58 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UE6vwg009303; Thu, 30 Aug 2018 14:06:58 GMT Received: from olila.i.net-space.pl (/10.175.183.119) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 07:06:57 -0700 Date: Thu, 30 Aug 2018 16:06:53 +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: <20180830140653.GE4616@olila.i.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> <20180621165822.GA20016@olila.local.net-space.pl> <20180716135117.GF26572@olila.local.net-space.pl> <0F674D8E-77C2-4208-8C50-1B5D0A0C4866@oracle.com> <20180717133857.GI26572@olila.local.net-space.pl> <465A56C4-8481-4DEC-9367-A64CB7A82B31@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <465A56C4-8481-4DEC-9367-A64CB7A82B31@oracle.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9000 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-1807170000 definitions=main-1808300147 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by userp2120.oracle.com id w7UE4UnE139394 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 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, 30 Aug 2018 14:07:18 -0000 On Tue, Jul 17, 2018 at 09:59:33AM -0600, Eric Snowberg wrote: > > On Jul 17, 2018, at 7:38 AM, Daniel Kiper w= rote: > > On Mon, Jul 16, 2018 at 09:33:17AM -0600, Eric Snowberg wrote: > >>> On Jul 16, 2018, at 7:51 AM, Daniel Kiper = wrote: > >>> > >>> Sorry for late reply but I was busy with other stuff. > >>> > >>> On Thu, Jun 21, 2018 at 01:46:46PM -0600, Eric Snowberg wrote: > >>>>> On Jun 21, 2018, at 10:58 AM, Daniel Kiper wrote: > >>>>> On Fri, Jun 15, 2018 at 09:58:56AM -0600, Eric Snowberg wrote: > >>>>>>> On Jun 15, 2018, at 6:02 AM, Daniel Kiper wrote: > >>>>>>> On Wed, May 30, 2018 at 04:55:22PM -0700, Eric Snowberg wrote: > >>> > >>> [...] > >>> > >>>>>>>> +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 ",=E2=80= =9D, > >>>> > >>>> AFAIK all layers above expect it: > >>>> https://www.gnu.org/software/grub/manual/grub/grub.html#Device-syn= tax > >>>> > >>>> Everything above this driver expects it to be escaped. Obviously = when > >>> > >>> Do you mean from the command line? > >> > >> This goes much further than the command line. For example, it is > >> built right into the disk driver. Look at grub-core/kern/disk.c: 54= 4 > > > > This is the last line of the file. So, I am not sure what exactly you= mean. > > > >> /* Return the location of the first ',', if any, which is not > >> escaped by a '\'. */ > >> static const char * > >> find_part_sep (const char *name) > >> { > >> const char *p =3D name; > >> char c; > >> > >> while ((c =3D *p++) !=3D '\0') > >> { > >> if (c =3D=3D '\\' && *p =3D=3D ',') > >> p++; > >> else if (c =3D=3D ',') > >> return p - 1; > >> } > >> return NULL; > >> } > > > > OK, this one. > > > >> When the obdisk driver discovers a disk, it must put the disk name i= n > >> the proper format. Otherwise when grub_disk_open takes place later > >> on, the wrong disk name will eventually get sent back to the obdisk > >> driver. > > > > Then we need proper escaping. And AIUI your driver does that. > > > >>> If yes could you give an example with > >>> proper escaping? > >>> > >>>> the driver talks to the actual hardware these devices can not have= the > >>>> escaped names. > >>> > >>> OK but this is not clear. So, please add a comment explaining it in > >>> the code somewhere. > >> > >> Ok > >> > >>> > >>>>> how often this conversions must be done, why you have chosen that > >>>>> solution, etc. Then I will try to optimize solution a bit. > >>>> > >>>> Under normal circumstances it only takes place once per disk as th= ey > >>>> are enumerated. All disks are cached within this driver so it sh= ould > >>>> not happen often. That is why I store both versions so I don=E2=80= =99t have > >>>> to go back and forth. Look at the current driver ofdisk. It has = a > >>>> function called compute_dev_path which does this conversion on eve= ry > >>>> single open (grub_ofdisk_open). That does not happen with this ne= w > >>>> driver. IMHO this is a much more optimized solution than the curr= ent > >>>> driver. > >>> > >>> Then OK. However, this have to be explained somewhere in the code. > >>> Additionally, I think that proper variable naming would help too, > >>> e.g. name and name_esc. And I would do this: > >>> - s/decode_grub_devname/unescape_grub_devnam/, > >>> - s/encode_grub_devname/escape_grub_devname/, > >> > >>> - extract unscaping code to the unescape_commas() function; > >>> even if it is called once; just for the completeness. > >> > >> Ok > >> > >>> > >>> What is replace_escaped_commas()? Why do we need that function? > >> > >> It is a convenience function for the end-user, so they can access a > >> disk without having to understand all this escaping when they want t= o > >> use one thru the shell. > > > > I think that this will introduce more confusion. I would like that > > escaping of drive paths should be properly explained in GRUB docs. > > Including why it is needed. And replace_escaped_commas() should be > > dropped. > > The confusion seems to be around what needs to be escaped and what > doesn=E2=80=99t, as can be seen from the discussion within this email. = This > change makes it convenient for the end-user, since they will not need > to understand any of this. > > When function grub_obdisk_iterate (defined as .iterate within > grub_disk_dev) gets called, it returns the disks the driver controls. > As explained within the description of this patch, a single IEEE1275 > disk can have over 6 names. When the .iterate function is called, > only a single drive can be returned. If the disk that is to be > returned contains \\, within the name, they are replaced with __. > Then for example, the end-user will see something like this following > a ls: > > grub> ls > (ieee1275//pci@308/pci@1/usb@0/hub@1/storage@3/disk@0__0) (ieee1275//pc= i@308/pc > i@1/usb@0/hub@1/storage@3/disk@0__0,gpt1) (ieee1275//pci@306/pci@1/LSI_= _mrsas@0 > /disk@0__0) (ieee1275//pci@306/pci@1/LSI__mrsas@0/disk@0__0,gpt3) (ieee= 1275//pc > i@306/pci@1/LSI__mrsas@0/disk@0__0,gpt2) (ieee1275//pci@306/pci@1/LSI__= mrsas@0/ > disk@0__0,gpt1) > > The end-user can now type the disk name exactly as it is returned on > the screen. Or they can escape any of the real disk names properly > and the driver will understand it is the same disk. Do you really > want this removed? After some thinking it seems to me that we should remove this "__" feature. It introduces another specific escaping form. And IMO this will make more confusion then it is worth. And what if disk path contains "__"? Yeah, I know probably it is not the case right now but we should be prepared... Though I am not against displaying properly escaped disks and partitions paths, e.g.: (ieee1275//pci@308/pci@1/usb@0/hub@1/storage@3/disk@0\\,0) or (ieee1275//pci@308/pci@1/usb@0/hub@1/storage@3/disk@0\\,0,gpt1) etc. Additionally, I think that you should update GRUB2 docs in relevant place= s and add an info saying that disk paths containing "," should be properly escaped. Daniel