On Tue, 7 Jun 2011 18:59:12 +0530 Amit Shah <amit.s...@redhat.com> wrote:
> On (Mon) 06 Jun 2011 [11:38:03], Luiz Capitulino wrote: > > On Mon, 6 Jun 2011 17:10:32 +0530 > > Amit Shah <amit.s...@redhat.com> wrote: > > > > > On (Fri) 03 Jun 2011 [16:03:57], Luiz Capitulino wrote: > > > > > > > +static int tray_open(const char *device, int remove, int force) > > > > +{ > > > > + BlockDriverState *bs; > > > > + > > > > + bs = bdrv_removable_find(device); > > > > + if (!bs) { > > > > + return -1; > > > > + } > > > > + > > > > + if (bdrv_eject(bs, 1, force) < 0) { > > > > + /* FIXME: will report undefined error in QMP */ > > > > + return -1; > > > > + } > > > > + > > > > + if (remove) { > > > > + bdrv_close(bs); > > > > + } > > > > + > > > > + return 0; > > > > +} > > > > > > What's the reason to tie the 'remove' with tray open? > > > > In my first try I had a command called 'blockdev-media-remove', but then > > I had the impression that I was going too far as the only reason a client > > would ever want to open the tray is to remove the media. > > Not necessary -- CD/DVD writers eject and reload trays after erasing > media -- at least they used to. But that's not done by the VM's user/client. I think I'll add it anyway, as it's what people seem to expect from an API like this. > > > Won't it be > > > simpler to have it separated out, perhaps a 'change' event instead of > > > 'insert' that can accept NULL which means just remove medium? > > > > You meant 'command' instead of 'event', right? > > > > I don't think a change command makes sense, because it's just a shortcut > > to open/remove/insert/close. > > Yes, command, sorry. > > And by 'change' I don't mean the current monitor change command -- > that's a badly-named one. > > By change I mean just that -- replace the media. And that should > succeed only if tray is open. And tray remains open after the change. The same thing can be done with blockdev-media-remove and blockdev-media-insert, so I don't think this adds value.