EXPORT_SYMBOL(scsi_cmd_allowed);
 
 static int scsi_fill_sghdr_rq(struct scsi_device *sdev, struct request *rq,
-               struct sg_io_hdr *hdr, fmode_t mode)
+               struct sg_io_hdr *hdr, bool open_for_write)
 {
        struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
 
                return -EMSGSIZE;
        if (copy_from_user(scmd->cmnd, hdr->cmdp, hdr->cmd_len))
                return -EFAULT;
-       if (!scsi_cmd_allowed(scmd->cmnd, mode & FMODE_WRITE))
+       if (!scsi_cmd_allowed(scmd->cmnd, open_for_write))
                return -EPERM;
        scmd->cmd_len = hdr->cmd_len;
 
        return ret;
 }
 
-static int sg_io(struct scsi_device *sdev, struct sg_io_hdr *hdr, fmode_t mode)
+static int sg_io(struct scsi_device *sdev, struct sg_io_hdr *hdr,
+               bool open_for_write)
 {
        unsigned long start_time;
        ssize_t ret = 0;
                goto out_put_request;
        }
 
-       ret = scsi_fill_sghdr_rq(sdev, rq, hdr, mode);
+       ret = scsi_fill_sghdr_rq(sdev, rq, hdr, open_for_write);
        if (ret < 0)
                goto out_put_request;
 
 /**
  * sg_scsi_ioctl  --  handle deprecated SCSI_IOCTL_SEND_COMMAND ioctl
  * @q:         request queue to send scsi commands down
- * @mode:      mode used to open the file through which the ioctl has been
- *             submitted
+ * @open_for_write: is the file / block device opened for writing?
  * @sic:       userspace structure describing the command to perform
  *
  * Send down the scsi command described by @sic to the device below
  *      Positive numbers returned are the compacted SCSI error codes (4
  *      bytes in one int) where the lowest byte is the SCSI status.
  */
-static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode,
+static int sg_scsi_ioctl(struct request_queue *q, bool open_for_write,
                struct scsi_ioctl_command __user *sic)
 {
        struct request *rq;
                goto error;
 
        err = -EPERM;
-       if (!scsi_cmd_allowed(scmd->cmnd, mode & FMODE_WRITE))
+       if (!scsi_cmd_allowed(scmd->cmnd, open_for_write))
                goto error;
 
        /* default.  possible overridden later */
        return 0;
 }
 
-static int scsi_cdrom_send_packet(struct scsi_device *sdev, fmode_t mode,
+static int scsi_cdrom_send_packet(struct scsi_device *sdev, bool open_for_write,
                void __user *arg)
 {
        struct cdrom_generic_command cgc;
        hdr.cmdp = ((struct cdrom_generic_command __user *) arg)->cmd;
        hdr.cmd_len = sizeof(cgc.cmd);
 
-       err = sg_io(sdev, &hdr, mode);
+       err = sg_io(sdev, &hdr, open_for_write);
        if (err == -EFAULT)
                return -EFAULT;
 
        return err;
 }
 
-static int scsi_ioctl_sg_io(struct scsi_device *sdev, fmode_t mode,
+static int scsi_ioctl_sg_io(struct scsi_device *sdev, bool open_for_write,
                void __user *argp)
 {
        struct sg_io_hdr hdr;
        error = get_sg_io_hdr(&hdr, argp);
        if (error)
                return error;
-       error = sg_io(sdev, &hdr, mode);
+       error = sg_io(sdev, &hdr, open_for_write);
        if (error == -EFAULT)
                return error;
        if (put_sg_io_hdr(&hdr, argp))
 /**
  * scsi_ioctl - Dispatch ioctl to scsi device
  * @sdev: scsi device receiving ioctl
- * @mode: mode the block/char device is opened with
+ * @open_for_write: is the file / block device opened for writing?
  * @cmd: which ioctl is it
  * @arg: data associated with ioctl
  *
  * does not take a major/minor number as the dev field.  Rather, it takes
  * a pointer to a &struct scsi_device.
  */
-int scsi_ioctl(struct scsi_device *sdev, fmode_t mode, int cmd,
+int scsi_ioctl(struct scsi_device *sdev, bool open_for_write, int cmd,
                void __user *arg)
 {
        struct request_queue *q = sdev->request_queue;
        case SG_EMULATED_HOST:
                return sg_emulated_host(q, arg);
        case SG_IO:
-               return scsi_ioctl_sg_io(sdev, mode, arg);
+               return scsi_ioctl_sg_io(sdev, open_for_write, arg);
        case SCSI_IOCTL_SEND_COMMAND:
-               return sg_scsi_ioctl(q, mode, arg);
+               return sg_scsi_ioctl(q, open_for_write, arg);
        case CDROM_SEND_PACKET:
-               return scsi_cdrom_send_packet(sdev, mode, arg);
+               return scsi_cdrom_send_packet(sdev, open_for_write, arg);
        case CDROMCLOSETRAY:
                return scsi_send_start_stop(sdev, 3);
        case CDROMEJECT: