diff --git a/scst/include/scst.h b/scst/include/scst.h index 9af3ce9a3..76bd650ad 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -543,12 +543,6 @@ enum scst_exec_context { /* Set if tgt_dev is RESERVED by another session */ #define SCST_TGT_DEV_RESERVED 1 -/* Set if the corresponding context should be atomic */ -#define SCST_TGT_DEV_AFTER_INIT_WR_ATOMIC 5 -#define SCST_TGT_DEV_AFTER_EXEC_ATOMIC 6 - -#define SCST_TGT_DEV_CLUST_POOL 11 - /************************************************************* ** I/O grouping types. Changing them don't forget to change ** the corresponding *_STR values in scst_const.h! @@ -2333,7 +2327,7 @@ struct scst_device { unsigned short dev_double_ua_possible:1; /* If set, dev is read only */ - unsigned short rd_only:1; + unsigned short dev_rd_only:1; /* Set, if a strictly serialized cmd is waiting blocked */ unsigned short strictly_serialized_cmd_waiting:1; @@ -2542,6 +2536,22 @@ struct scst_tgt_dev { struct sgv_pool *pool; int max_sg_cnt; + /************************************************************* + ** Tgt_dev's flags + *************************************************************/ + + /* Set if tgt_dev is read only (to save extra dereferences) */ + unsigned int tgt_dev_rd_only:1; + + /* Set if the corresponding context should be atomic */ + unsigned int tgt_dev_after_init_wr_atomic:1; + unsigned int tgt_dev_after_exec_atimic:1; + + /* Set if tgt_dev uses clustered SGV pool */ + unsigned int tgt_dev_clust_pool:1; + + /**************************************************************/ + /* * Tgt_dev's async flags. Modified independently to the neighbour * fields. @@ -2629,7 +2639,7 @@ struct scst_acg_dev { uint64_t lun; /* device's LUN in this acg */ /* If set, the corresponding LU is read only */ - unsigned int rd_only:1; + unsigned int acg_dev_rd_only:1; struct scst_acg *acg; /* parent acg */ diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index b8b330954..e3477ec98 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -2676,7 +2676,7 @@ static int dev_user_attach_tgt(struct scst_tgt_dev *tgt_dev) * memory for SCST local commands, like REPORT LUNS, where there is no * corresponding ucmd. Otherwise we will crash in dev_user_alloc_sg(). */ - if (test_bit(SCST_TGT_DEV_CLUST_POOL, &tgt_dev->tgt_dev_flags)) + if (tgt_dev->tgt_dev_clust_pool) tgt_dev->dh_priv = dev->pool_clust; else tgt_dev->dh_priv = dev->pool; @@ -2694,7 +2694,7 @@ static int dev_user_attach_tgt(struct scst_tgt_dev *tgt_dev) ucmd->user_cmd.sess.sess_h = (unsigned long)tgt_dev; ucmd->user_cmd.sess.lun = (uint64_t)tgt_dev->lun; ucmd->user_cmd.sess.threads_num = tgt_dev->sess->tgt->tgtt->threads_num; - ucmd->user_cmd.sess.rd_only = tgt_dev->acg_dev->rd_only; + ucmd->user_cmd.sess.rd_only = tgt_dev->tgt_dev_rd_only; if (tgtt->get_phys_transport_version != NULL) ucmd->user_cmd.sess.phys_transport_version = tgtt->get_phys_transport_version(tgt); diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 03ee51fa9..88e105b5b 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -606,7 +606,8 @@ static const char *vdev_get_filename(const struct scst_vdisk_dev *virt_dev) } /* Returns fd, use IS_ERR(fd) to get error status */ -static struct file *vdev_open_fd(const struct scst_vdisk_dev *virt_dev) +static struct file *vdev_open_fd(const struct scst_vdisk_dev *virt_dev, + bool read_only) { int open_flags = 0; struct file *fd; @@ -615,7 +616,7 @@ static struct file *vdev_open_fd(const struct scst_vdisk_dev *virt_dev) sBUG_ON(!virt_dev->filename); - if (virt_dev->dev->rd_only) + if (read_only) open_flags |= O_RDONLY; else open_flags |= O_RDWR; @@ -836,7 +837,7 @@ static int vdisk_attach(struct scst_device *dev) virt_dev->dev = dev; - dev->rd_only = virt_dev->rd_only; + dev->dev_rd_only = virt_dev->rd_only; if (!virt_dev->cdrom_empty) { if (virt_dev->nullio) @@ -913,7 +914,7 @@ static void vdisk_detach(struct scst_device *dev) return; } -static int vdisk_open_fd(struct scst_vdisk_dev *virt_dev) +static int vdisk_open_fd(struct scst_vdisk_dev *virt_dev, bool read_only) { int res; @@ -922,7 +923,7 @@ static int vdisk_open_fd(struct scst_vdisk_dev *virt_dev) #endif sBUG_ON(!virt_dev->filename); - virt_dev->fd = vdev_open_fd(virt_dev); + virt_dev->fd = vdev_open_fd(virt_dev, read_only); if (IS_ERR(virt_dev->fd)) { res = PTR_ERR(virt_dev->fd); virt_dev->fd = NULL; @@ -954,7 +955,7 @@ static int vdisk_attach_tgt(struct scst_tgt_dev *tgt_dev) goto out; if (!virt_dev->nullio && !virt_dev->cdrom_empty) { - res = vdisk_open_fd(virt_dev); + res = vdisk_open_fd(virt_dev, tgt_dev->tgt_dev_rd_only); if (res != 0) { virt_dev->tgt_dev_cnt--; goto out; @@ -2685,8 +2686,7 @@ static enum compl_status_e vdisk_exec_mode_sense(struct vdisk_cmd_params *p) pcode = cmd->cdb[2] & 0x3f; subpcode = cmd->cdb[3]; msense_6 = (MODE_SENSE == cmd->cdb[0]); - dev_spec = (virt_dev->dev->rd_only || - cmd->tgt_dev->acg_dev->rd_only) ? WP : 0; + dev_spec = cmd->tgt_dev->tgt_dev_rd_only ? WP : 0; if (type != TYPE_ROM) dev_spec |= DPOFUA; @@ -2810,7 +2810,7 @@ out_not_sup: goto out_put; } -static int vdisk_set_wt(struct scst_vdisk_dev *virt_dev, int wt) +static int vdisk_set_wt(struct scst_vdisk_dev *virt_dev, int wt, bool read_only) { int res = 0; struct file *fd; @@ -2830,7 +2830,7 @@ static int vdisk_set_wt(struct scst_vdisk_dev *virt_dev, int wt) * to reopen fd. */ - fd = vdev_open_fd(virt_dev); + fd = vdev_open_fd(virt_dev, read_only); if (IS_ERR(fd)) { PRINT_ERROR("filp_open(%s) returned an error %ld", virt_dev->filename, PTR_ERR(fd)); @@ -2934,8 +2934,8 @@ static enum compl_status_e vdisk_exec_mode_select(struct vdisk_cmd_params *p) scst_set_invalid_field_in_parm_list(cmd, offset+1, 0); goto out_put; } - if (vdisk_set_wt(virt_dev, - (address[offset + 2] & WCE) ? 0 : 1) != 0) { + if (vdisk_set_wt(virt_dev, (address[offset + 2] & WCE) ? 0 : 1, + cmd->tgt_dev->tgt_dev_rd_only) != 0) { scst_set_busy(cmd); goto out_put; } @@ -4176,7 +4176,8 @@ static void vdisk_task_mgmt_fn_done(struct scst_mgmt_cmd *mcmd, else dev->queue_alg = DEF_QUEUE_ALG; - rc = vdisk_set_wt(virt_dev, DEF_WRITE_THROUGH); + rc = vdisk_set_wt(virt_dev, DEF_WRITE_THROUGH, + tgt_dev->tgt_dev_rd_only); if (rc != 0) { PRINT_CRIT_ERROR("Unable to reset caching mode to %d", DEF_WRITE_THROUGH); @@ -4952,7 +4953,7 @@ static int vcdrom_change(struct scst_vdisk_dev *virt_dev, if (res != 0) goto out_free_fn; if (virt_dev->tgt_dev_cnt > 0) { - res = vdisk_open_fd(virt_dev); + res = vdisk_open_fd(virt_dev, true); if (res != 0) goto out_free_fn; sBUG_ON(!virt_dev->fd); @@ -5609,7 +5610,7 @@ static int vdisk_read_proc(struct seq_file *seq, struct scst_dev_type *dev_type) c += 3; } if (virt_dev->dev != NULL) { - if (virt_dev->dev->rd_only) { + if (virt_dev->dev->dev_rd_only) { seq_printf(seq, "RO "); c += 3; } diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 4efbf751d..4c192677e 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -2495,7 +2495,7 @@ retry_add: sess_tgt_dev_list_entry) { if ((tgt_dev->dev == acg_dev->dev) && (tgt_dev->lun == acg_dev->lun) && - (tgt_dev->acg_dev->rd_only == acg_dev->rd_only)) { + (tgt_dev->acg_dev->acg_dev_rd_only == acg_dev->acg_dev_rd_only)) { TRACE_MGMT_DBG("sess %p: tgt_dev %p for " "LUN %lld stays the same", sess, tgt_dev, @@ -3512,7 +3512,7 @@ int scst_acg_add_lun(struct scst_acg *acg, struct kobject *parent, res = -ENOMEM; goto out; } - acg_dev->rd_only = read_only; + acg_dev->acg_dev_rd_only = read_only; TRACE_DBG("Adding acg_dev %p to acg_dev_list and dev_acg_dev_list", acg_dev); @@ -4099,6 +4099,7 @@ static int scst_alloc_add_tgt_dev(struct scst_session *sess, tgt_dev->dev = dev; tgt_dev->lun = acg_dev->lun; tgt_dev->acg_dev = acg_dev; + tgt_dev->tgt_dev_rd_only = acg_dev->acg_dev_rd_only || dev->dev_rd_only; tgt_dev->sess = sess; atomic_set(&tgt_dev->tgt_dev_cmd_count, 0); @@ -4139,14 +4140,11 @@ static int scst_alloc_add_tgt_dev(struct scst_session *sess, dev->handler->dev_alloc_data_buf_atomic && (sess->tgt->tgtt->preprocessing_done == NULL)) { if (sess->tgt->tgtt->rdy_to_xfer_atomic) - __set_bit(SCST_TGT_DEV_AFTER_INIT_WR_ATOMIC, - &tgt_dev->tgt_dev_flags); + tgt_dev->tgt_dev_after_init_wr_atomic = 1; } if (dev->handler->dev_done_atomic && - sess->tgt->tgtt->xmit_response_atomic) { - __set_bit(SCST_TGT_DEV_AFTER_EXEC_ATOMIC, - &tgt_dev->tgt_dev_flags); - } + sess->tgt->tgtt->xmit_response_atomic) + tgt_dev->tgt_dev_after_exec_atimic = 1; sl = scst_set_sense(sense_buffer, sizeof(sense_buffer), dev->d_sense, SCST_LOAD_SENSE(scst_sense_reset_UA)); diff --git a/scst/src/scst_mem.c b/scst/src/scst_mem.c index a2841553d..ca36975ea 100644 --- a/scst/src/scst_mem.c +++ b/scst/src/scst_mem.c @@ -90,7 +90,7 @@ void scst_sgv_pool_use_norm(struct scst_tgt_dev *tgt_dev) { tgt_dev->gfp_mask = __GFP_NOWARN; tgt_dev->pool = sgv_norm_pool; - clear_bit(SCST_TGT_DEV_CLUST_POOL, &tgt_dev->tgt_dev_flags); + tgt_dev->tgt_dev_clust_pool = 0; } void scst_sgv_pool_use_norm_clust(struct scst_tgt_dev *tgt_dev) @@ -98,7 +98,7 @@ void scst_sgv_pool_use_norm_clust(struct scst_tgt_dev *tgt_dev) TRACE_MEM("%s", "Use clustering"); tgt_dev->gfp_mask = __GFP_NOWARN; tgt_dev->pool = sgv_norm_clust_pool; - set_bit(SCST_TGT_DEV_CLUST_POOL, &tgt_dev->tgt_dev_flags); + tgt_dev->tgt_dev_clust_pool = 1; } void scst_sgv_pool_use_dma(struct scst_tgt_dev *tgt_dev) @@ -106,7 +106,7 @@ void scst_sgv_pool_use_dma(struct scst_tgt_dev *tgt_dev) TRACE_MEM("%s", "Use ISA DMA memory"); tgt_dev->gfp_mask = __GFP_NOWARN | GFP_DMA; tgt_dev->pool = sgv_dma_pool; - clear_bit(SCST_TGT_DEV_CLUST_POOL, &tgt_dev->tgt_dev_flags); + tgt_dev->tgt_dev_clust_pool = 0; } /* Must be no locks */ diff --git a/scst/src/scst_proc.c b/scst/src/scst_proc.c index 5013499c6..a451f516f 100644 --- a/scst/src/scst_proc.c +++ b/scst/src/scst_proc.c @@ -2532,7 +2532,7 @@ static int scst_groups_devices_show(struct seq_file *seq, void *v) seq_printf(seq, "%-60s%-13lld%s\n", acg_dev->dev->virt_name, (long long unsigned int)acg_dev->lun, - acg_dev->rd_only ? "RO" : ""); + acg_dev->acg_dev_rd_only ? "RO" : ""); } mutex_unlock(&scst_mutex); diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 802cb03d3..30ad1b569 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -3730,7 +3730,7 @@ static ssize_t scst_lun_rd_only_show(struct kobject *kobj, acg_dev = container_of(kobj, struct scst_acg_dev, acg_dev_kobj); - if (acg_dev->rd_only || acg_dev->dev->rd_only) + if (acg_dev->acg_dev_rd_only || acg_dev->dev->dev_rd_only) return sprintf(buf, "%d\n%s\n", 1, SCST_SYSFS_KEY_MARK); else return sprintf(buf, "%d\n", 0); diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index c2a3da00c..90c56ec82 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -345,8 +345,7 @@ static int scst_init_cmd(struct scst_cmd *cmd, enum scst_exec_context *context) */ BUILD_BUG_ON(SCST_DATA_UNKNOWN != 0); if ((cmd->data_direction | cmd->expected_data_direction) & SCST_DATA_WRITE) { - if (!test_bit(SCST_TGT_DEV_AFTER_INIT_WR_ATOMIC, - &cmd->tgt_dev->tgt_dev_flags)) + if (!cmd->tgt_dev->tgt_dev_after_init_wr_atomic) *context = SCST_CONTEXT_THREAD; } else *context = SCST_CONTEXT_THREAD; @@ -1712,8 +1711,7 @@ static inline enum scst_exec_context scst_optimize_post_exec_context( if (((context == SCST_CONTEXT_SAME) && scst_cmd_atomic(cmd)) || (context == SCST_CONTEXT_TASKLET) || (context == SCST_CONTEXT_DIRECT_ATOMIC)) { - if (!test_bit(SCST_TGT_DEV_AFTER_EXEC_ATOMIC, - &cmd->tgt_dev->tgt_dev_flags)) + if (!cmd->tgt_dev->tgt_dev_after_exec_atimic) context = SCST_CONTEXT_THREAD; } return context; @@ -2765,8 +2763,7 @@ static int scst_do_local_exec(struct scst_cmd *cmd) /* Check READ_ONLY device status */ if ((cmd->op_flags & SCST_WRITE_MEDIUM) && - (tgt_dev->acg_dev->rd_only || cmd->dev->swp || - cmd->dev->rd_only)) { + (tgt_dev->tgt_dev_rd_only || cmd->dev->swp)) { PRINT_WARNING("Attempt of write access to read-only device: " "initiator %s, LUN %lld, op %x", cmd->sess->initiator_name, cmd->lun, cmd->cdb[0]); @@ -3174,8 +3171,7 @@ static int scst_pre_dev_done(struct scst_cmd *cmd) unsigned char type = cmd->dev->type; if (unlikely((cmd->cdb[0] == MODE_SENSE || cmd->cdb[0] == MODE_SENSE_10)) && - (cmd->tgt_dev->acg_dev->rd_only || cmd->dev->swp || - cmd->dev->rd_only) && + (cmd->tgt_dev->tgt_dev_rd_only || cmd->dev->swp) && (type == TYPE_DISK || type == TYPE_WORM || type == TYPE_MOD ||