From 20c8de5cb1ef461974e301451dd63a60dabca473 Mon Sep 17 00:00:00 2001 From: vlnb Date: Wed, 24 Jun 2009 12:40:28 +0000 Subject: [PATCH] Cleanup of use of READ ONLY flag git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@918 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst.h | 5 +- scst/src/dev_handlers/scst_user.c | 4 +- scst/src/dev_handlers/scst_vdisk.c | 138 +++++++++++++---------------- scst/src/scst_lib.c | 2 +- scst/src/scst_proc.c | 4 +- scst/src/scst_targ.c | 6 +- 6 files changed, 75 insertions(+), 84 deletions(-) diff --git a/scst/include/scst.h b/scst/include/scst.h index 3837134..3b11b26 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -1455,6 +1455,9 @@ struct scst_device { /* Set if double reset UA is possible */ unsigned short dev_double_ua_possible:1; + /* If set, dev is read only */ + unsigned int rd_only:1; + /**************************************************************/ /************************************************************* @@ -1644,7 +1647,7 @@ struct scst_tgt_dev { struct scst_acg_dev { struct scst_device *dev; /* corresponding device */ uint64_t lun; /* device's LUN in this acg */ - unsigned int rd_only_flag:1; /* if != 0, then read only */ + unsigned int rd_only:1; /* if != 0, then read only */ struct scst_acg *acg; /* parent acg */ /* list entry in dev->dev_acg_dev_list */ diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index 064f62f..4432f63 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -2462,7 +2462,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_flag; + ucmd->user_cmd.sess.rd_only = tgt_dev->acg_dev->rd_only; strncpy(ucmd->user_cmd.sess.initiator_name, tgt_dev->sess->initiator_name, sizeof(ucmd->user_cmd.sess.initiator_name)-1); @@ -2477,7 +2477,7 @@ static int dev_user_attach_tgt(struct scst_tgt_dev *tgt_dev) } TRACE_MGMT_DBG("Preparing ATTACH_SESS %p (h %d, sess_h %llx, LUN %llx, " - "threads_num %d, rd_only_flag %d, initiator %s, target %s)", + "threads_num %d, rd_only %d, initiator %s, target %s)", ucmd, ucmd->h, ucmd->user_cmd.sess.sess_h, ucmd->user_cmd.sess.lun, ucmd->user_cmd.sess.threads_num, ucmd->user_cmd.sess.rd_only, ucmd->user_cmd.sess.initiator_name, diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 0edd896..52e1811 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -193,7 +193,7 @@ struct scst_vdisk_dev { * Below flags are protected by flags_lock or suspended activity * with scst_vdisk_mutex. */ - unsigned int rd_only_flag:1; + unsigned int rd_only:1; unsigned int wt_flag:1; unsigned int nv_cache:1; unsigned int o_direct_flag:1; @@ -395,7 +395,7 @@ static struct file *vdisk_open(const struct scst_vdisk_dev *virt_dev) TRACE_ENTRY(); - if (virt_dev->rd_only_flag) + if (virt_dev->dev->rd_only) open_flags |= O_RDONLY; else open_flags |= O_RDWR; @@ -530,8 +530,9 @@ static int vdisk_attach(struct scst_device *dev) virt_dev->dev = dev; + dev->rd_only = virt_dev->rd_only; if (dev->type == TYPE_ROM) - virt_dev->rd_only_flag = 1; + dev->rd_only = 1; if (!virt_dev->cdrom_empty) { if (virt_dev->nullio) @@ -892,80 +893,61 @@ static int vdisk_do_job(struct scst_cmd *cmd) case WRITE_10: case WRITE_12: case WRITE_16: - if (likely(!virt_dev->rd_only_flag)) { - int do_fsync = vdisk_sync_queue_type(cmd->queue_type); - struct scst_vdisk_tgt_dev *ftgt_dev = - (struct scst_vdisk_tgt_dev *) - tgt_dev->dh_priv; - enum scst_cmd_queue_type last_queue_type = - ftgt_dev->last_write_cmd_queue_type; - ftgt_dev->last_write_cmd_queue_type = cmd->queue_type; - if (vdisk_need_pre_sync(cmd->queue_type, - last_queue_type)) { - TRACE(TRACE_ORDER, "ORDERED " - "WRITE(%d): loff=%lld, data_len=%lld", - cmd->queue_type, - (long long unsigned int)loff, - (long long unsigned int)data_len); - do_fsync = 1; - if (vdisk_fsync(thr, 0, 0, cmd) != 0) - goto out_compl; - } - if (virt_dev->blockio) { - blockio_exec_rw(cmd, thr, lba_start, 1); - goto out_thr; - } else - vdisk_exec_write(cmd, thr, loff); - /* O_SYNC flag is used for WT devices */ - if (do_fsync || fua) - vdisk_fsync(thr, loff, data_len, cmd); - } else { - PRINT_WARNING("Attempt of write access to read-only " - "device %s: initiator %s, op %x", - virt_dev->name, cmd->sess->initiator_name, - cmd->cdb[0]); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_data_protect)); + { + int do_fsync = vdisk_sync_queue_type(cmd->queue_type); + struct scst_vdisk_tgt_dev *ftgt_dev = + (struct scst_vdisk_tgt_dev *)tgt_dev->dh_priv; + enum scst_cmd_queue_type last_queue_type = + ftgt_dev->last_write_cmd_queue_type; + ftgt_dev->last_write_cmd_queue_type = cmd->queue_type; + if (vdisk_need_pre_sync(cmd->queue_type, last_queue_type)) { + TRACE(TRACE_ORDER, "ORDERED WRITE(%d): loff=%lld, " + "data_len=%lld", cmd->queue_type, + (long long unsigned int)loff, + (long long unsigned int)data_len); + do_fsync = 1; + if (vdisk_fsync(thr, 0, 0, cmd) != 0) + goto out_compl; } + if (virt_dev->blockio) { + blockio_exec_rw(cmd, thr, lba_start, 1); + goto out_thr; + } else + vdisk_exec_write(cmd, thr, loff); + /* O_SYNC flag is used for WT devices */ + if (do_fsync || fua) + vdisk_fsync(thr, loff, data_len, cmd); break; + } case WRITE_VERIFY: case WRITE_VERIFY_12: case WRITE_VERIFY_16: - if (likely(!virt_dev->rd_only_flag)) { - int do_fsync = vdisk_sync_queue_type(cmd->queue_type); - struct scst_vdisk_tgt_dev *ftgt_dev = - (struct scst_vdisk_tgt_dev *) - tgt_dev->dh_priv; - enum scst_cmd_queue_type last_queue_type = - ftgt_dev->last_write_cmd_queue_type; - ftgt_dev->last_write_cmd_queue_type = cmd->queue_type; - if (vdisk_need_pre_sync(cmd->queue_type, - last_queue_type)) { - TRACE(TRACE_ORDER, "ORDERED " - "WRITE_VERIFY(%d): loff=%lld," - " data_len=%lld", cmd->queue_type, - (long long unsigned int)loff, - (long long unsigned int)data_len); - do_fsync = 1; - if (vdisk_fsync(thr, 0, 0, cmd) != 0) - goto out_compl; - } - /* ToDo: BLOCKIO VERIFY */ - vdisk_exec_write(cmd, thr, loff); - /* O_SYNC flag is used for WT devices */ - if (scsi_status_is_good(cmd->status)) - vdisk_exec_verify(cmd, thr, loff); - else if (do_fsync) - vdisk_fsync(thr, loff, data_len, cmd); - } else { - PRINT_WARNING("Attempt of write access to read-only " - "device %s: initiator %s, op %x", - virt_dev->name, cmd->sess->initiator_name, - cmd->cdb[0]); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_data_protect)); + { + int do_fsync = vdisk_sync_queue_type(cmd->queue_type); + struct scst_vdisk_tgt_dev *ftgt_dev = + (struct scst_vdisk_tgt_dev *) tgt_dev->dh_priv; + enum scst_cmd_queue_type last_queue_type = + ftgt_dev->last_write_cmd_queue_type; + ftgt_dev->last_write_cmd_queue_type = cmd->queue_type; + if (vdisk_need_pre_sync(cmd->queue_type, last_queue_type)) { + TRACE(TRACE_ORDER, "ORDERED " + "WRITE_VERIFY(%d): loff=%lld," + " data_len=%lld", cmd->queue_type, + (long long unsigned int)loff, + (long long unsigned int)data_len); + do_fsync = 1; + if (vdisk_fsync(thr, 0, 0, cmd) != 0) + goto out_compl; } + /* ToDo: BLOCKIO VERIFY */ + vdisk_exec_write(cmd, thr, loff); + /* O_SYNC flag is used for WT devices */ + if (scsi_status_is_good(cmd->status)) + vdisk_exec_verify(cmd, thr, loff); + else if (do_fsync) + vdisk_fsync(thr, loff, data_len, cmd); break; + } case SYNCHRONIZE_CACHE: { int immed = cdb[1] & 0x2; @@ -1554,7 +1536,7 @@ static void vdisk_exec_mode_sense(struct scst_cmd *cmd) pcode = cmd->cdb[2] & 0x3f; subpcode = cmd->cdb[3]; msense_6 = (MODE_SENSE == cmd->cdb[0]); - dev_spec = (virt_dev->rd_only_flag ? WP : 0) | DPOFUA; + dev_spec = (virt_dev->dev->rd_only ? WP : 0) | DPOFUA; length = scst_get_buf_first(cmd, &address); if (unlikely(length <= 0)) { @@ -2084,8 +2066,7 @@ static int vdisk_fsync(struct scst_vdisk_thr *thr, /* Hopefully, the compiler will generate the single comparison */ if (virt_dev->nv_cache || virt_dev->blockio || virt_dev->wt_flag || - virt_dev->rd_only_flag || virt_dev->o_direct_flag || - virt_dev->nullio) + virt_dev->o_direct_flag || virt_dev->nullio) goto out; inode = file->f_dentry->d_inode; @@ -2764,7 +2745,12 @@ static int vdisk_read_proc(struct seq_file *seq, struct scst_dev_type *dev_type) seq_printf(seq, "NV "); c += 3; } - if (virt_dev->rd_only_flag) { + if (virt_dev->dev != NULL) { + if (virt_dev->dev->rd_only) { + seq_printf(seq, "RO "); + c += 3; + } + } else if (virt_dev->rd_only) { seq_printf(seq, "RO "); c += 3; } @@ -2813,7 +2799,7 @@ static void vdisk_report_registering(const char *type, i += snprintf(&buf[i], sizeof(buf) - i, "%sNV_CACHE", (j == i) ? "(" : ", "); - if (virt_dev->rd_only_flag) + if (virt_dev->rd_only) i += snprintf(&buf[i], sizeof(buf) - i, "%sREAD_ONLY", (j == i) ? "(" : ", "); @@ -3013,7 +2999,7 @@ static int vdisk_write_proc(char *buffer, char **start, off_t offset, TRACE_DBG("%s", "NON-VOLATILE CACHE"); } else if (!strncmp("READ_ONLY", p, 9)) { p += 9; - virt_dev->rd_only_flag = 1; + virt_dev->rd_only = 1; TRACE_DBG("%s", "READ_ONLY"); } else if (!strncmp("O_DIRECT", p, 8)) { p += 8; diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 08461f8..1a3424c 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -1367,7 +1367,7 @@ int scst_acg_add_dev(struct scst_acg *acg, struct scst_device *dev, res = -ENOMEM; goto out; } - acg_dev->rd_only_flag = read_only; + acg_dev->rd_only = read_only; TRACE_DBG("Adding acg_dev %p to acg_dev_list and dev_acg_dev_list", acg_dev); diff --git a/scst/src/scst_proc.c b/scst/src/scst_proc.c index ae5ff91..181811b 100644 --- a/scst/src/scst_proc.c +++ b/scst/src/scst_proc.c @@ -1987,12 +1987,12 @@ static int scst_groups_devices_show(struct seq_file *seq, void *v) acg_dev->dev->scsi_dev->lun, acg_dev->lun); seq_printf(seq, "%s\n", - acg_dev->rd_only_flag ? "RO" : ""); + acg_dev->rd_only ? "RO" : ""); } else { seq_printf(seq, "%-60s%-13lld%s\n", acg_dev->dev->virt_name, (long long unsigned int)acg_dev->lun, - acg_dev->rd_only_flag ? "RO" : ""); + acg_dev->rd_only ? "RO" : ""); } } mutex_unlock(&scst_mutex); diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index e6ccc27..ef6539b 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -2145,7 +2145,8 @@ 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_flag) || cmd->dev->swp)) { + (tgt_dev->acg_dev->rd_only || cmd->dev->swp || + cmd->dev->rd_only)) { 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]); @@ -2556,7 +2557,8 @@ 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_flag && + (cmd->tgt_dev->acg_dev->rd_only || cmd->dev->swp || + cmd->dev->rd_only) && (type == TYPE_DISK || type == TYPE_WORM || type == TYPE_MOD || -- 2.17.1