All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 06/11] fdc: do not call revalidate on eject
Date: Fri, 18 Dec 2015 17:11:29 +0100	[thread overview]
Message-ID: <87y4cr3ff2.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <1450304177-3935-7-git-send-email-jsnow@redhat.com> (John Snow's message of "Wed, 16 Dec 2015 17:16:12 -0500")

John Snow <jsnow@redhat.com> writes:

> Currently, fd_revalidate is called in two different places, with two
> different expectations of behavior:
>
> (1) On initialization, as a routine to help pick the drive type and
>     initial geometries as a side-effect of the pick_geometry routine
>
> (2) On insert/eject, which either sets the geometries to a default value
>     or chooses new geometries based on the inserted diskette.
>
> Break this nonsense apart by creating a new function dedicated towards
> picking the drive type on initialization.
>
> This has a few results:
>
> (1) fd_revalidate does not get called on boot anymore for drives with no
>     diskette.
>
> (2) pick_geometry will actually get called twice if we have a diskette
>     inserted, but this is harmless. (Once for the drive type, and once
>     as part of the media callback.)
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  hw/block/fdc.c | 36 +++++++++++++++++++++++++++++-------
>  1 file changed, 29 insertions(+), 7 deletions(-)
>
> diff --git a/hw/block/fdc.c b/hw/block/fdc.c
> index b587de8..e752758 100644
> --- a/hw/block/fdc.c
> +++ b/hw/block/fdc.c
> @@ -167,6 +167,7 @@ static void fd_init(FDrive *drv)
>      drv->disk = FLOPPY_DRIVE_TYPE_NONE;
>      drv->last_sect = 0;
>      drv->max_track = 0;
> +    drv->ro = true;
>  }
>  
>  #define NUM_SIDES(drv) ((drv)->flags & FDISK_DBL_SIDES ? 2 : 1)
> @@ -249,13 +250,21 @@ static void fd_recalibrate(FDrive *drv)
>      fd_seek(drv, 0, 0, 1, 1);
>  }
>  
> -static void pick_geometry(FDrive *drv)
> +/**
> + * Determine geometry based on inserted diskette.
> + */
> +static bool pick_geometry(FDrive *drv)

Meaning of return value?

>  {
>      BlockBackend *blk = drv->blk;
>      const FDFormat *parse;
>      uint64_t nb_sectors, size;
>      int i, first_match, match;
>  
> +    /* We can only pick a geometry if we have a diskette. */
> +    if (!drv->media_inserted) {
> +        return false;
> +    }
> +
>      blk_get_geometry(blk, &nb_sectors);
>      match = -1;
>      first_match = -1;
> @@ -293,8 +302,7 @@ static void pick_geometry(FDrive *drv)
>      }
>      drv->max_track = parse->max_track;
>      drv->last_sect = parse->last_sect;
> -    drv->drive = parse->drive;
> -    drv->disk = drv->media_inserted ? parse->drive : FLOPPY_DRIVE_TYPE_NONE;
> +    drv->disk = parse->drive;
>      drv->media_rate = parse->rate;
>  
>      if (drv->media_inserted) {
> @@ -303,6 +311,14 @@ static void pick_geometry(FDrive *drv)
>                         drv->max_track, drv->last_sect,
>                         drv->ro ? "ro" : "rw");
>      }
> +    return true;
> +}
> +
> +static void pick_drive_type(FDrive *drv)
> +{
> +    if (pick_geometry(drv)) {
> +        drv->drive = drv->disk;
> +    }
>  }
>  
>  /* Revalidate a disk drive after a disk change */
> @@ -311,15 +327,18 @@ static void fd_revalidate(FDrive *drv)
>      FLOPPY_DPRINTF("revalidate\n");
>      if (drv->blk != NULL) {
>          drv->ro = blk_is_read_only(drv->blk);
> -        pick_geometry(drv);
>          if (!drv->media_inserted) {
>              FLOPPY_DPRINTF("No disk in drive\n");
> +            drv->disk = FLOPPY_DRIVE_TYPE_NONE;

The left hand side is the "current disk type" (@disk's comment says so).

The right hand side is "no drive connected" drive type (the enum's
comment says so).

Thus, we set the current disk type to the "no drive connected" drive
type.  Sounds nuts, doesn't it?  :)

Perhaps drv->disk isn't a disk type, but really into what an auto drive
type should be morphed.  Correct?

> +        } else {
> +            pick_geometry(drv);
>          }
>      } else {
>          FLOPPY_DPRINTF("No drive connected\n");
>          drv->last_sect = 0;
>          drv->max_track = 0;
>          drv->flags &= ~FDISK_DBL_SIDES;
> +        drv->disk = FLOPPY_DRIVE_TYPE_NONE;
>      }
>  }
>  
> @@ -2196,9 +2215,11 @@ static void fdctrl_change_cb(void *opaque, bool load)
>      FDrive *drive = opaque;
>  
>      drive->media_inserted = load && drive->blk && blk_is_inserted(drive->blk);
> -
>      drive->media_changed = 1;
> -    fd_revalidate(drive);
> +
> +    if (load) {
> +        fd_revalidate(drive);
> +    }

Hmm.  Looks like drv->last_sect, ->max_track and ->flags now remain
after an eject.  If yes, why is that a good idea?

>  }
>  
>  static bool fdctrl_is_tray_open(void *opaque)
> @@ -2234,13 +2255,14 @@ static void fdctrl_connect_drives(FDCtrl *fdctrl, Error **errp)
>          }
>  
>          fd_init(drive);
> -        fdctrl_change_cb(drive, 0);
>          if (drive->blk) {
>              blk_set_dev_ops(drive->blk, &fdctrl_block_ops, drive);
>              drive->media_inserted = blk_is_inserted(drive->blk);
> +            pick_drive_type(drive);
>          } else {
>              drive->drive = FLOPPY_DRIVE_TYPE_NONE;
>          }
> +        fdctrl_change_cb(drive, drive->media_inserted);
>      }
>  }

  reply	other threads:[~2015-12-18 16:11 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-16 22:16 [Qemu-devel] [PATCH v3 00/11] fdc: fix 2.88mb floppy diskette support John Snow
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 01/11] fdc: move pick_geometry John Snow
2015-12-18 16:15   ` Eric Blake
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 02/11] fdc: refactor pick_geometry John Snow
2015-12-17  7:53   ` Markus Armbruster
2015-12-17 17:50     ` John Snow
2015-12-17 19:09       ` Markus Armbruster
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 03/11] fdc: add disk field John Snow
2015-12-17  8:30   ` Markus Armbruster
2015-12-17 16:59     ` John Snow
2015-12-17 18:15       ` Markus Armbruster
2015-12-17 18:55         ` John Snow
2015-12-17 19:04           ` Markus Armbruster
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 04/11] fdc: add default drive type option John Snow
2015-12-16 23:03   ` Eric Blake
2015-12-18 15:54   ` Markus Armbruster
2015-12-18 17:20     ` John Snow
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 05/11] fdc: Add fallback option John Snow
2015-12-18 15:57   ` Markus Armbruster
2015-12-18 17:22     ` John Snow
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 06/11] fdc: do not call revalidate on eject John Snow
2015-12-18 16:11   ` Markus Armbruster [this message]
2015-12-18 20:13     ` John Snow
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 07/11] fdc: implement new drive type property John Snow
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 08/11] fdc: add physical disk sizes John Snow
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 09/11] fdc: rework pick_geometry John Snow
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 10/11] qtest/fdc: Support for 2.88MB drives John Snow
2015-12-16 22:16 ` [Qemu-devel] [PATCH v3 11/11] fdc: change auto fallback drive for ISA FDC to 288 John Snow
2015-12-16 22:30   ` John Snow

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=87y4cr3ff2.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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.