[libvirt] [PATCH v4 2/2] storage: Improve error handling on cdrom backend
John Ferlan
jferlan at redhat.com
Tue Nov 6 17:20:51 UTC 2018
On 10/25/18 11:39 PM, Han Han wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1596096
>
> Implement virFileCheckCDROM in virStorageBackendVolOpen to check if
> cdrom backend is ok. Report more detailed error if not ok.
>
> Signed-off-by: Han Han <hhan at redhat.com>
> ---
> src/storage/storage_util.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
> index 318a556656..c9f89b817a 100644
> --- a/src/storage/storage_util.c
> +++ b/src/storage/storage_util.c
> @@ -1601,6 +1601,38 @@ virStorageBackendVolOpen(const char *path, struct stat *sb,
> return -1;
> }
>
> +#if defined(__linux__)
This not what I was expecting... Let's not have conditionals in this
module and go with my suggestion from patch1 of changing the non linux
version of virFileCheckCDROM to return VIR_FILE_CDROM_DISC_OK when we
return 1 and to return/handle VIR_FILE_CDROM_NO_DEVICE here when 0 is
returned (even though this code doesn't handle that "yet").
> + virFileCDRomStatus cd_status = VIR_FILE_CDROM_UNKNOWN;
Definition belongs at the top-level...
> +
> + if (virFileCheckCDROM(path, &cd_status) > 0) {
> + switch (cd_status) {
> + case VIR_FILE_CDROM_UNKNOWN:
> + virReportError(VIR_ERR_NO_STORAGE_VOL,
> + _("unknown status for CDROM storage vol '%s'"),
> + path);
> + return -1;
> + case VIR_FILE_CDROM_NO_DISC:
> + virReportError(VIR_ERR_NO_STORAGE_VOL,
> + _("no disc in CDROM storage vol '%s'"),
> + path);
> + return -1;
> + case VIR_FILE_CDROM_TRAY_OPEN:
> + virReportError(VIR_ERR_NO_STORAGE_VOL,
> + _("the tray of CDROM storage vol '%s' is open"),
> + path);
> + return -1;
> + case VIR_FILE_CDROM_DRIVE_NOT_READY:
> + virReportError(VIR_ERR_NO_STORAGE_VOL,
> + _("CDROM storage vol '%s' is not ready"),
> + path);
> + return -1;
> + case VIR_FILE_CDROM_DISC_OK:
> + VIR_INFO("CDROM storage vol %s is OK", path);
Depending on the level of debugging enabled and the times we go through
here, this could be chatty...
Also, kind of strange to be making a check for a specific issue from the
bz description in a generic place. Check all the callers of
virStorageBackendVolOpen... I think you may need to move this switch.
For callers that may be correctly supplying a CDROM @path we could
return a failure now.
The switch may be nice as a common/shared method too so that no one is
tempted to cut-n-paste whenever the values are needed.
John
> + break;
> + }
> + }
> +#endif /* defined(__linux__) */
> +
> /* O_NONBLOCK should only matter during open() for fifos and
> * sockets, which we already filtered; but using it prevents a
> * TOCTTOU race. However, later on we will want to read() the
>
More information about the libvir-list
mailing list