target: Set peripheral device type consistently in INQUIRY response
authorRoland Dreier <roland@purestorage.com>
Tue, 14 Feb 2012 00:18:15 +0000 (16:18 -0800)
committerNicholas Bellinger <nab@linux-iscsi.org>
Sat, 25 Feb 2012 22:37:49 +0000 (14:37 -0800)
Current code sets the peripheral device type to 0x3f == "not present
unknown" for virtual LUN 0 for standard INQUIRY commands, but leaves it
as 0 == "connected direct access block" for VPD INQUIRY commands.  This
is just because the check for LUN 0 only happens in some code paths.

Make our peripheral device type consistent by moving the LUN 0 check
into the common emulate_inquiry() code.

Signed-off-by: Roland Dreier <roland@purestorage.com>
Cc: stable@vger.kernel.org
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_cdb.c

index ef8034b60d8d7a6ee9a02c2f6e34be87a6039d37..af8ebbde45ead1732b922b08cdea258e5716b74e 100644 (file)
@@ -70,15 +70,11 @@ target_emulate_inquiry_std(struct se_cmd *cmd, char *buf)
 {
        struct se_lun *lun = cmd->se_lun;
        struct se_device *dev = cmd->se_dev;
-       struct se_portal_group *tpg = lun->lun_sep->sep_tpg;
 
-       if (dev == tpg->tpg_virt_lun0.lun_se_dev) {
-               buf[0] = 0x3f; /* Not connected */
-       } else {
-               buf[0] = dev->transport->get_device_type(dev);
-               if (buf[0] == TYPE_TAPE)
-                       buf[1] = 0x80;
-       }
+       /* Set RMB (removable media) for tape devices */
+       if (dev->transport->get_device_type(dev) == TYPE_TAPE)
+               buf[1] = 0x80;
+
        buf[2] = dev->transport->get_device_rev(dev);
 
        /*
@@ -606,6 +602,7 @@ int target_emulate_inquiry(struct se_task *task)
 {
        struct se_cmd *cmd = task->task_se_cmd;
        struct se_device *dev = cmd->se_dev;
+       struct se_portal_group *tpg = cmd->se_lun->lun_sep->sep_tpg;
        unsigned char *buf, *map_buf;
        unsigned char *cdb = cmd->t_task_cdb;
        int p, ret;
@@ -630,6 +627,11 @@ int target_emulate_inquiry(struct se_task *task)
                buf = map_buf;
        }
 
+       if (dev == tpg->tpg_virt_lun0.lun_se_dev)
+               buf[0] = 0x3f; /* Not connected */
+       else
+               buf[0] = dev->transport->get_device_type(dev);
+
        if (!(cdb[1] & 0x1)) {
                if (cdb[2]) {
                        pr_err("INQUIRY with EVPD==0 but PAGE CODE=%02x\n",
@@ -643,8 +645,6 @@ int target_emulate_inquiry(struct se_task *task)
                goto out;
        }
 
-       buf[0] = dev->transport->get_device_type(dev);
-
        for (p = 0; p < ARRAY_SIZE(evpd_handlers); ++p) {
                if (cdb[2] == evpd_handlers[p].page) {
                        buf[1] = cdb[2];