From 3979325ed9ca5fffe75c14b6348ae351a531c2dc Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Mon, 30 Apr 2012 19:28:21 +0000 Subject: [PATCH] vcdrom: Process CDROMs without medium correctly Signed-off-by: Bart Van Assche with small improvements git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4250 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 889d5eed6..474ae038d 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -926,7 +926,7 @@ static int vdisk_attach_tgt(struct scst_tgt_dev *tgt_dev) if (virt_dev->tgt_dev_cnt++ > 0) goto out; - if (!virt_dev->nullio && !virt_dev->cdrom_empty && virt_dev->filename) { + if (!virt_dev->nullio && !virt_dev->cdrom_empty) { virt_dev->fd = vdev_open_fd(virt_dev); if (IS_ERR(virt_dev->fd)) { PRINT_ERROR("filp_open(%s) returned an error %ld", @@ -4684,6 +4684,7 @@ static int vcdrom_change(struct scst_vdisk_dev *virt_dev, { loff_t err; char *old_fn, *p, *pp; + bool old_empty; const char *filename = NULL; int length = strlen(buffer); int res = 0; @@ -4710,13 +4711,15 @@ static int vcdrom_change(struct scst_vdisk_dev *virt_dev, /* To sync with detach*() functions */ mutex_lock(&scst_mutex); + old_empty = virt_dev->cdrom_empty; + if (*filename == '\0') { virt_dev->cdrom_empty = 1; TRACE_DBG("%s", "No media"); } else if (*filename != '/') { PRINT_ERROR("File path \"%s\" is not absolute", filename); res = -EINVAL; - goto out_unlock; + goto out_e_unlock; } else virt_dev->cdrom_empty = 0; @@ -4727,7 +4730,7 @@ static int vcdrom_change(struct scst_vdisk_dev *virt_dev, if (fn == NULL) { PRINT_ERROR("%s", "Allocation of filename failed"); res = -ENOMEM; - goto out_unlock; + goto out_e_unlock; } virt_dev->filename = fn; @@ -4783,7 +4786,9 @@ out_free_fn: kfree(virt_dev->filename); virt_dev->filename = old_fn; -out_unlock: +out_e_unlock: + virt_dev->cdrom_empty = old_empty; + mutex_unlock(&scst_mutex); goto out_resume; }