Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fw9Zx-0001G4-VS for mharc-grub-devel@gnu.org; Sat, 01 Sep 2018 13:20:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fw9Zt-0001Ej-Os for grub-devel@gnu.org; Sat, 01 Sep 2018 13:20:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fw9QK-0004JK-9F for grub-devel@gnu.org; Sat, 01 Sep 2018 13:11:04 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:54126) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fw9QJ-0004GI-Ph for grub-devel@gnu.org; Sat, 01 Sep 2018 13:11:00 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w81H9kwT033837; Sat, 1 Sep 2018 17:10:52 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=c0zrA2JSJlSyhICVv2kvL5ooYN3x10sKDWsBEBdbeaM=; b=FU9QnWKC5XFKjUXmXwAaLImUYuXvgJXfehNrNQHmgweIUFUuVibh1aZvKPsCTYRE2/AN lOVR7zXUjs/klGx8vHlVFSntxk0KQP8GDG6QhEjZ50vpW530PvE2pPVXxHsybC0jTn4o /kNIHxlvDIF5sK3m9F3WDGHw9MgNoVwN9OdcTvgT8YKLZdKIsaNlLyws0FOlY7+0v1jl 6CzuvINPrscZiahAx6EvI0NbRK8h5dAqtX4gAOovP+QjEvfcx99sLPyzMvZALrBLhuwz JY8l6FOdBVrkBZPEnz76rf/yeHLk/vbTj2JALqwegpApBR+bfQQPCzmdtQu8WEUghVHp ng== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2m7j6t20qp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 01 Sep 2018 17:10:51 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w81HAprb012337 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 1 Sep 2018 17:10:51 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w81HAoDL022719; Sat, 1 Sep 2018 17:10:51 GMT Received: from olila.i.net-space.pl (/10.175.218.143) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 01 Sep 2018 10:10:49 -0700 Date: Sat, 1 Sep 2018 19:10:46 +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: <20180901171046.GE4462@olila.i.net-space.pl> References: <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> <20180830140653.GE4616@olila.i.net-space.pl> <3CA5742D-C75B-43DF-8C2D-C40D0DEFF311@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <3CA5742D-C75B-43DF-8C2D-C40D0DEFF311@oracle.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9003 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-1809010191 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by userp2130.oracle.com id w81H9kwT033837 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 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: Sat, 01 Sep 2018 17:20:57 -0000 On Thu, Aug 30, 2018 at 09:28:52AM -0600, Eric Snowberg wrote: > > On Aug 30, 2018, at 8:06 AM, Daniel Kiper w= rote: > > On Tue, Jul 17, 2018 at 09:59:33AM -0600, Eric Snowberg wrote: > >>> On Jul 17, 2018, at 7:38 AM, Daniel Kiper = wrote: > >>> 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 somewhe= re > >>>>>>>>> where this commas are needed unescaped, escaped, replaced, et= c. > >>>>>>>>> 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-s= yntax > >>>>>> > >>>>>> Everything above this driver expects it to be escaped. Obviousl= y 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: = 544 > >>> > >>> This is the last line of the file. So, I am not sure what exactly y= ou 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= in > >>>> the proper format. Otherwise when grub_disk_open takes place late= r > >>>> on, the wrong disk name will eventually get sent back to the obdis= k > >>>> 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 ha= ve 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 th= at > >>>>>>> solution, etc. Then I will try to optimize solution a bit. > >>>>>> > >>>>>> Under normal circumstances it only takes place once per disk as = they > >>>>>> are enumerated. All disks are cached within this driver so it = should > >>>>>> 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 ha= s a > >>>>>> function called compute_dev_path which does this conversion on e= very > >>>>>> single open (grub_ofdisk_open). That does not happen with this = new > >>>>>> driver. IMHO this is a much more optimized solution than the cu= rrent > >>>>>> 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= to > >>>> 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 emai= l. This > >> change makes it convenient for the end-user, since they will not nee= d > >> 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 followin= g > >> a ls: > >> > >> grub> ls > >> (ieee1275//pci@308/pci@1/usb@0/hub@1/storage@3/disk@0__0) (ieee1275/= /pci@308/pc > >> i@1/usb@0/hub@1/storage@3/disk@0__0,gpt1) (ieee1275//pci@306/pci@1/L= SI__mrsas@0 > >> /disk@0__0) (ieee1275//pci@306/pci@1/LSI__mrsas@0/disk@0__0,gpt3) (i= eee1275//pc > >> i@306/pci@1/LSI__mrsas@0/disk@0__0,gpt2) (ieee1275//pci@306/pci@1/LS= I__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 w= ill > > make more confusion then it is worth. And what if disk path contains > > "__=E2=80=9D? Yeah, I know probably it is not the case right now but = we should > > be prepared=E2=80=A6 > > 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. > > I don=E2=80=99t believe you have escaped the name properly above. Unle= ss you > are suggesting substituting =E2=80=98\\=E2=80=99 with =E2=80=9C\\=E2=80= =9D before the item is I think that it is correct. If you use one '\' then after shell processing you will get (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) And I suppose that this is not what you want. So, you need two '\'. This way the layer below will get after shell processing (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) Then new driver should get 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 if you really need escaped ',' in the path. However, I do not think so. It seems to me that OF expects ',' as ','. Hence, I have a feeling that we can reduce number of escaping/unescaping in the driver. Am I right? > displayed. If that is acceptable, would you accept this change > instead? > > +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 '\'; Plus *iptr++ =3D ','; > + } > + iptr++; > + } > + > + return src; > +} > > > > > > Additionally, I think that you should update GRUB2 docs in relevant p= laces > > and add an info saying that disk paths containing "," should be prope= rly > > escaped. > > > > It is already documented here: > https://www.gnu.org/software/grub/manual/grub/grub.html#Device-syntax OK but this does not discuss shell processing of '\' which is important here. So, I think that doc should be updated. Daniel