All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: peter.maydell@linaro.org, bin.meng@windriver.com,
	mark.cave-ayland@ilande.co.uk, qemu-devel@nongnu.org,
	sundeep.lkml@gmail.com, qemu-block@nongnu.org,
	andrew.smirnov@gmail.com, hskinnemoen@google.com, joel@jms.id.au,
	atar4qemu@gmail.com, alistair@alistair23.me, b.galvani@gmail.com,
	nieklinnenbank@gmail.com, qemu-arm@nongnu.org, clg@kaod.org,
	kwolf@redhat.com, qemu-riscv@nongnu.org, andrew@aj.id.au,
	Andrew.Baumann@microsoft.com, jcd@tribudubois.net,
	kfting@nuvoton.com, hreitz@redhat.com, palmer@dabbelt.com
Subject: Re: [PATCH RFC 2/2] hw: Replace drive_get_next() by drive_get()
Date: Tue, 16 Nov 2021 08:47:22 +0100	[thread overview]
Message-ID: <878rxoczjp.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <b18519f7-7198-0965-a528-2d1a45c7c93c@amsat.org> ("Philippe =?utf-8?Q?Mathieu-Daud=C3=A9=22's?= message of "Mon, 15 Nov 2021 22:15:12 +0100")

Philippe Mathieu-Daudé <f4bug@amsat.org> writes:

> On 11/15/21 16:57, Markus Armbruster wrote:
>> Philippe Mathieu-Daudé <f4bug@amsat.org> writes:
>>> On 11/15/21 13:55, Markus Armbruster wrote:
>>>> drive_get_next() is basically a bad idea.  It returns the "next" block
>>>> backend of a certain interface type.  "Next" means bus=0,unit=N, where
>>>> subsequent calls count N up from zero, per interface type.
>>>>
>>>> This lets you define unit numbers implicitly by execution order.  If the
>>>> order changes, or new calls appear "in the middle", unit numbers change.
>>>> ABI break.  Hard to spot in review.
>>>>
>>>> Explicit is better than implicit: use drive_get() directly.
>>>>
>>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>>> ---
>
>>>> @@ -435,11 +438,13 @@ static void aspeed_machine_init(MachineState *machine)
>>>>      }
>>>>  
>>>>      for (i = 0; i < bmc->soc.sdhci.num_slots; i++) {
>>>> -        sdhci_attach_drive(&bmc->soc.sdhci.slots[i], drive_get_next(IF_SD));
>>>> +        sdhci_attach_drive(&bmc->soc.sdhci.slots[i],
>>>> +                           drive_get(IF_SD, 0, i));
>>>
>>> If we put SD on bus #0, ...
>>>
>>>>      }
>>>>  
>>>>      if (bmc->soc.emmc.num_slots) {
>>>> -        sdhci_attach_drive(&bmc->soc.emmc.slots[0], drive_get_next(IF_SD));
>>>> +        sdhci_attach_drive(&bmc->soc.emmc.slots[0],
>>>> +                           drive_get(IF_SD, 0, bmc->soc.sdhci.num_slots));
>>>
>>> ... we'd want to put eMMC on bus #1
>> 
>> Using separate buses for different kinds of devices would be neater, but
>> it also would be an incompatible change.  This patch keeps existing
>> bus/unit numbers working.  drive_get_next() can only use bus 0.
>> 
>>>                                      but I see having eMMC cards on a
>>> IF_SD bus as a bug, since these cards are soldered on the board.
>> 
>> IF_SD is not a bus, it's an "block interface type", which is really just
>> a user interface thing.
>
> Why are we discriminating by "block interface type" then?
>
> What is the difference between "block interfaces"? I see a block drive
> as a generic unit, usable on multiple hardware devices.
>
> I never really understood how this "block interface type" helps
> developers and users. I thought BlockInterfaceType and DriveInfo
> were legacy / deprecated APIs we want to get rid of; and we would
> come up with a replacement API using BlockDeviceInfo or providing
> a BlockFrontend state of the art object.
> Anyway, I suppose the explanation is buried in the git history
> before the last 8 years. I need to keep reading.

In the beginning (v0.4.2), there was -hda and -hdb, and life was simple.

Then there was -hdc, -hdd, -cdrom (v0.5.1), -fda, -fdb (v0.6.0),
-mtdblock, -sd, -pflash (v0.9.1).

All these options do two things: they create a block backend, and they
request the board to create a certain block frontend for it, similar to
other options of this vintage, like -serial, -parallel, and -net.
Boards generally ignore requests they don't understand, but that's just
sloppiness.

For each set of related options, there was a global variable holding the
requests: bs_table[] for -hda, -hdb, -hdc, -hdd, -cdrom; fd_table[]
-fda, -fdb; mtd_bdrv for -mtd; sd_drv for -ds; pflash_table[] for
-pflash.

The options replaced prior ones, except for -pflash, which appended to
its table.

bs_table[]'s index had a peculiar meaning: it's bus * MAX_IDE_DEVS +
unit.  This ensures that -hda (index 0) goes on IDE bus 0 as unit 0;
-hdb on bus 0, unit 1; -hdc on 1, 0; -hdc on 1, 1.

Life was now complicated enough for a generalization (v0.9.1), so there
was -drive (v0.9.1).  All the variables holding requests were fused into
drives_table[].  Table elements are identified by (type, bus, unit),
where type is an enum whose members correspond to the old global
variables: IF_IDE for bs_table[], IF_FLOPPY for fd_table[], and so
forth.  So:

    -hda becomes type = IF_IDE, bus = 0, unit = 0
    -hdb becomes type = IF_IDE, bus = 0, unit = 1
    ...
    -sd becomes type = IF_SD, bus = 0, unit = 0
    1st -pflash becomes type = IF_PFLASH, bus = 0, unit = 0
    2nd -pflash becomes type = IF_PFLASH, bus = 0, unit = 1
    ...

Other mappings from old to new global variables would have been
possible.  I figure this one was chosen because it comes with a
reasonable user interface.  Identifying block devices by (interface
type, bus, unit) is certainly nicer than by index in bs_table[].  Since
bus and/or unit make sense only with some interface types, they are
optional.

Things calmed down for a couple of years, until -device appeared
(v0.12).  Now we needed a way to define just a backend, without
requesting a frontend from the board.  Instead of inventing a new
option, this became IF_NONE, with meaningless bus and unit.

Over the next years, the block layer outgrew -drive's limited
capabilities to define frontends.  -blockdev appeard (v1.7.0) and
matured over several releases.  I don't remember exactly when it became
stable, relegating -drive if=none to legacy status.

What's *not* legacy is -drive with other interface types, simply because
there is no replacement.  Yet.  We clearly want one.

Questions?



WARNING: multiple messages have this Message-ID (diff)
From: Markus Armbruster <armbru@redhat.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: peter.maydell@linaro.org,  bin.meng@windriver.com,
	mark.cave-ayland@ilande.co.uk,  qemu-devel@nongnu.org,
	jcd@tribudubois.net,  qemu-block@nongnu.org,
	 andrew.smirnov@gmail.com, hskinnemoen@google.com,
	 joel@jms.id.au,  atar4qemu@gmail.com, alistair@alistair23.me,
	 b.galvani@gmail.com,  nieklinnenbank@gmail.com,
	qemu-arm@nongnu.org,  clg@kaod.org,  kwolf@redhat.com,
	qemu-riscv@nongnu.org,  andrew@aj.id.au,
	 Andrew.Baumann@microsoft.com, sundeep.lkml@gmail.com,
	 kfting@nuvoton.com,  hreitz@redhat.com, palmer@dabbelt.com
Subject: Re: [PATCH RFC 2/2] hw: Replace drive_get_next() by drive_get()
Date: Tue, 16 Nov 2021 08:47:22 +0100	[thread overview]
Message-ID: <878rxoczjp.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <b18519f7-7198-0965-a528-2d1a45c7c93c@amsat.org> ("Philippe =?utf-8?Q?Mathieu-Daud=C3=A9=22's?= message of "Mon, 15 Nov 2021 22:15:12 +0100")

Philippe Mathieu-Daudé <f4bug@amsat.org> writes:

> On 11/15/21 16:57, Markus Armbruster wrote:
>> Philippe Mathieu-Daudé <f4bug@amsat.org> writes:
>>> On 11/15/21 13:55, Markus Armbruster wrote:
>>>> drive_get_next() is basically a bad idea.  It returns the "next" block
>>>> backend of a certain interface type.  "Next" means bus=0,unit=N, where
>>>> subsequent calls count N up from zero, per interface type.
>>>>
>>>> This lets you define unit numbers implicitly by execution order.  If the
>>>> order changes, or new calls appear "in the middle", unit numbers change.
>>>> ABI break.  Hard to spot in review.
>>>>
>>>> Explicit is better than implicit: use drive_get() directly.
>>>>
>>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>>> ---
>
>>>> @@ -435,11 +438,13 @@ static void aspeed_machine_init(MachineState *machine)
>>>>      }
>>>>  
>>>>      for (i = 0; i < bmc->soc.sdhci.num_slots; i++) {
>>>> -        sdhci_attach_drive(&bmc->soc.sdhci.slots[i], drive_get_next(IF_SD));
>>>> +        sdhci_attach_drive(&bmc->soc.sdhci.slots[i],
>>>> +                           drive_get(IF_SD, 0, i));
>>>
>>> If we put SD on bus #0, ...
>>>
>>>>      }
>>>>  
>>>>      if (bmc->soc.emmc.num_slots) {
>>>> -        sdhci_attach_drive(&bmc->soc.emmc.slots[0], drive_get_next(IF_SD));
>>>> +        sdhci_attach_drive(&bmc->soc.emmc.slots[0],
>>>> +                           drive_get(IF_SD, 0, bmc->soc.sdhci.num_slots));
>>>
>>> ... we'd want to put eMMC on bus #1
>> 
>> Using separate buses for different kinds of devices would be neater, but
>> it also would be an incompatible change.  This patch keeps existing
>> bus/unit numbers working.  drive_get_next() can only use bus 0.
>> 
>>>                                      but I see having eMMC cards on a
>>> IF_SD bus as a bug, since these cards are soldered on the board.
>> 
>> IF_SD is not a bus, it's an "block interface type", which is really just
>> a user interface thing.
>
> Why are we discriminating by "block interface type" then?
>
> What is the difference between "block interfaces"? I see a block drive
> as a generic unit, usable on multiple hardware devices.
>
> I never really understood how this "block interface type" helps
> developers and users. I thought BlockInterfaceType and DriveInfo
> were legacy / deprecated APIs we want to get rid of; and we would
> come up with a replacement API using BlockDeviceInfo or providing
> a BlockFrontend state of the art object.
> Anyway, I suppose the explanation is buried in the git history
> before the last 8 years. I need to keep reading.

In the beginning (v0.4.2), there was -hda and -hdb, and life was simple.

Then there was -hdc, -hdd, -cdrom (v0.5.1), -fda, -fdb (v0.6.0),
-mtdblock, -sd, -pflash (v0.9.1).

All these options do two things: they create a block backend, and they
request the board to create a certain block frontend for it, similar to
other options of this vintage, like -serial, -parallel, and -net.
Boards generally ignore requests they don't understand, but that's just
sloppiness.

For each set of related options, there was a global variable holding the
requests: bs_table[] for -hda, -hdb, -hdc, -hdd, -cdrom; fd_table[]
-fda, -fdb; mtd_bdrv for -mtd; sd_drv for -ds; pflash_table[] for
-pflash.

The options replaced prior ones, except for -pflash, which appended to
its table.

bs_table[]'s index had a peculiar meaning: it's bus * MAX_IDE_DEVS +
unit.  This ensures that -hda (index 0) goes on IDE bus 0 as unit 0;
-hdb on bus 0, unit 1; -hdc on 1, 0; -hdc on 1, 1.

Life was now complicated enough for a generalization (v0.9.1), so there
was -drive (v0.9.1).  All the variables holding requests were fused into
drives_table[].  Table elements are identified by (type, bus, unit),
where type is an enum whose members correspond to the old global
variables: IF_IDE for bs_table[], IF_FLOPPY for fd_table[], and so
forth.  So:

    -hda becomes type = IF_IDE, bus = 0, unit = 0
    -hdb becomes type = IF_IDE, bus = 0, unit = 1
    ...
    -sd becomes type = IF_SD, bus = 0, unit = 0
    1st -pflash becomes type = IF_PFLASH, bus = 0, unit = 0
    2nd -pflash becomes type = IF_PFLASH, bus = 0, unit = 1
    ...

Other mappings from old to new global variables would have been
possible.  I figure this one was chosen because it comes with a
reasonable user interface.  Identifying block devices by (interface
type, bus, unit) is certainly nicer than by index in bs_table[].  Since
bus and/or unit make sense only with some interface types, they are
optional.

Things calmed down for a couple of years, until -device appeared
(v0.12).  Now we needed a way to define just a backend, without
requesting a frontend from the board.  Instead of inventing a new
option, this became IF_NONE, with meaningless bus and unit.

Over the next years, the block layer outgrew -drive's limited
capabilities to define frontends.  -blockdev appeard (v1.7.0) and
matured over several releases.  I don't remember exactly when it became
stable, relegating -drive if=none to legacy status.

What's *not* legacy is -drive with other interface types, simply because
there is no replacement.  Yet.  We clearly want one.

Questions?



  reply	other threads:[~2021-11-16  7:51 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15 12:55 [PATCH RFC 0/2] Eliminate drive_get_next() Markus Armbruster
2021-11-15 12:55 ` Markus Armbruster
2021-11-15 12:55 ` [PATCH RFC 1/2] hw/sd/ssi-sd: Do not create SD card within controller's realize Markus Armbruster
2021-11-15 12:55   ` Markus Armbruster
2021-11-15 13:40   ` Peter Maydell
2021-11-15 13:40     ` Peter Maydell
2021-11-15 13:48     ` Markus Armbruster
2021-11-15 13:48       ` Markus Armbruster
2021-11-15 12:55 ` [PATCH RFC 2/2] hw: Replace drive_get_next() by drive_get() Markus Armbruster
2021-11-15 12:55   ` Markus Armbruster
2021-11-15 13:38   ` Peter Maydell
2021-11-15 13:38     ` Peter Maydell
2021-11-15 13:48     ` Markus Armbruster
2021-11-15 13:48       ` Markus Armbruster
2021-11-15 13:59   ` Philippe Mathieu-Daudé
2021-11-15 13:59     ` Philippe Mathieu-Daudé
2021-11-15 15:57     ` Markus Armbruster
2021-11-15 15:57       ` Markus Armbruster
2021-11-15 21:15       ` Philippe Mathieu-Daudé
2021-11-15 21:15         ` Philippe Mathieu-Daudé
2021-11-16  7:47         ` Markus Armbruster [this message]
2021-11-16  7:47           ` Markus Armbruster
2021-11-16  8:52       ` Cédric Le Goater
2021-11-16  8:52         ` Cédric Le Goater
2021-11-16  9:29         ` Markus Armbruster
2021-11-16  9:29           ` Markus Armbruster
2021-11-16 12:14           ` Cédric Le Goater
2021-11-16 12:14             ` Cédric Le Goater
2021-11-15 14:05 ` [PATCH RFC 0/2] Eliminate drive_get_next() Peter Maydell
2021-11-15 14:05   ` Peter Maydell
2021-11-15 16:01   ` Markus Armbruster
2021-11-15 16:01     ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878rxoczjp.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=Andrew.Baumann@microsoft.com \
    --cc=alistair@alistair23.me \
    --cc=andrew.smirnov@gmail.com \
    --cc=andrew@aj.id.au \
    --cc=atar4qemu@gmail.com \
    --cc=b.galvani@gmail.com \
    --cc=bin.meng@windriver.com \
    --cc=clg@kaod.org \
    --cc=f4bug@amsat.org \
    --cc=hreitz@redhat.com \
    --cc=hskinnemoen@google.com \
    --cc=jcd@tribudubois.net \
    --cc=joel@jms.id.au \
    --cc=kfting@nuvoton.com \
    --cc=kwolf@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=nieklinnenbank@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=sundeep.lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.