diff --git a/scst/src/scst_copy_mgr.c b/scst/src/scst_copy_mgr.c index c59233ba8..049ac0529 100644 --- a/scst/src/scst_copy_mgr.c +++ b/scst/src/scst_copy_mgr.c @@ -2550,7 +2550,7 @@ static int scst_cm_dev_register(struct scst_device *dev) }; res = scst_acg_add_lun(scst_cm_tgt->default_acg, - scst_cm_tgt->tgt_luns_kobj, dev, lun, false, false, &acg_dev); + scst_cm_tgt->tgt_luns_kobj, dev, lun, 0, &acg_dev); if (res != 0) goto out_err; diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 9d15d4c8e..c73c54ba8 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -4407,8 +4407,8 @@ out: /* The activity supposed to be suspended and scst_mutex held */ int scst_acg_add_lun(struct scst_acg *acg, struct kobject *parent, - struct scst_device *dev, uint64_t lun, int read_only, - bool gen_scst_report_luns_changed, struct scst_acg_dev **out_acg_dev) + struct scst_device *dev, uint64_t lun, unsigned int flags, + struct scst_acg_dev **out_acg_dev) { int res; struct scst_acg_dev *acg_dev; @@ -4429,7 +4429,7 @@ int scst_acg_add_lun(struct scst_acg *acg, struct kobject *parent, res = -ENOMEM; goto out; } - acg_dev->acg_dev_rd_only = read_only; + acg_dev->acg_dev_rd_only = ((flags & SCST_ADD_LUN_READ_ONLY) != 0); if (dev->dev_dif_mode & SCST_DIF_MODE_DEV_STORE) { /* Devices are allowed to store only CRCs */ acg_dev->acg_dev_dif_guard_format = SCST_DIF_GUARD_FORMAT_CRC; @@ -4459,12 +4459,12 @@ int scst_acg_add_lun(struct scst_acg *acg, struct kobject *parent, if (res != 0) goto out_free; - if (gen_scst_report_luns_changed) + if (flags & SCST_ADD_LUN_GEN_UA) scst_report_luns_changed(acg); PRINT_INFO("Added device %s to group %s (LUN %lld, " - "rd_only %d) to target %s", dev->virt_name, acg->acg_name, - lun, read_only, acg->tgt ? acg->tgt->tgt_name : "?"); + "flags 0x%x) to target %s", dev->virt_name, acg->acg_name, + lun, flags, acg->tgt ? acg->tgt->tgt_name : "?"); if (out_acg_dev != NULL) *out_acg_dev = acg_dev; @@ -4585,7 +4585,7 @@ out: int scst_acg_repl_lun(struct scst_acg *acg, struct kobject *parent, struct scst_device *dev, uint64_t lun, - bool read_only, bool gen_ua) + unsigned int flags) { struct scst_acg_dev *acg_dev; struct scst_tgt_dev *tgt_dev, *tt; @@ -4598,12 +4598,11 @@ int scst_acg_repl_lun(struct scst_acg *acg, struct kobject *parent, acg_dev = __scst_acg_del_lun(acg, lun, &tgt_dev_list); - res = scst_acg_add_lun(acg, parent, dev, lun, read_only, !acg_dev, - NULL); + res = scst_acg_add_lun(acg, parent, dev, lun, flags, NULL); if (res != 0) goto out; - if (acg_dev && gen_ua) { + if (acg_dev && (flags & SCST_REPL_LUN_GEN_UA)) { list_for_each_entry(tgt_dev, &dev->dev_tgt_dev_list, dev_tgt_dev_list_entry) { if (tgt_dev->acg_dev->acg == acg && diff --git a/scst/src/scst_priv.h b/scst/src/scst_priv.h index 010914212..0181356fc 100644 --- a/scst/src/scst_priv.h +++ b/scst/src/scst_priv.h @@ -364,14 +364,19 @@ void scst_sess_free_tgt_devs(struct scst_session *sess); struct scst_tgt_dev *scst_lookup_tgt_dev(struct scst_session *sess, u64 lun); void scst_nexus_loss(struct scst_tgt_dev *tgt_dev, bool queue_UA); +#define SCST_ADD_LUN_READ_ONLY 1 +#define SCST_ADD_LUN_GEN_UA 2 +#define SCST_ADD_LUN_CM 4 +#define SCST_REPL_LUN_GEN_UA 8 + int scst_acg_add_lun(struct scst_acg *acg, struct kobject *parent, - struct scst_device *dev, uint64_t lun, int read_only, - bool gen_scst_report_luns_changed, struct scst_acg_dev **out_acg_dev); + struct scst_device *dev, uint64_t lun, unsigned int flags, + struct scst_acg_dev **out_acg_dev); int scst_acg_del_lun(struct scst_acg *acg, uint64_t lun, - bool gen_scst_report_luns_changed); + bool gen_report_luns_changed); int scst_acg_repl_lun(struct scst_acg *acg, struct kobject *parent, - struct scst_device *dev, uint64_t lun, bool read_only, - bool gen_ua); + struct scst_device *dev, uint64_t lun, + unsigned int flags); int scst_acg_add_acn(struct scst_acg *acg, const char *name); #ifdef CONFIG_SCST_PROC diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index d6ffb482d..eb1ab9274 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -1405,10 +1405,14 @@ static int __scst_process_luns_mgmt_store(char *buffer, switch (action) { case SCST_LUN_ACTION_ADD: + { + unsigned int flags = SCST_ADD_LUN_GEN_UA; + res = scst_parse_add_repl_param(acg, dev, pp, &virt_lun, &read_only); if (res != 0) goto out_unlock; + acg_dev = NULL; list_for_each_entry(acg_dev_tmp, &acg->acg_dev_list, acg_dev_list_entry) { @@ -1417,31 +1421,40 @@ static int __scst_process_luns_mgmt_store(char *buffer, break; } } - if (acg_dev) { - PRINT_ERROR("virt lun %ld already exists in " - "group %s", virt_lun, acg->acg_name); + + if (acg_dev != NULL) { + PRINT_ERROR("virt lun %ld already exists in group %s", + virt_lun, acg->acg_name); res = -EEXIST; goto out_unlock; } + if (read_only) + flags |= SCST_ADD_LUN_READ_ONLY; res = scst_acg_add_lun(acg, tgt_kobj ? tgt->tgt_luns_kobj : acg->luns_kobj, - dev, virt_lun, read_only, true, NULL); + dev, virt_lun, flags, NULL); if (res != 0) goto out_unlock; - break; + } case SCST_LUN_ACTION_REPLACE: + { + unsigned int flags = (read_only ? SCST_ADD_LUN_READ_ONLY : 0) | + (replace_gen_ua ? SCST_REPL_LUN_GEN_UA : 0); + res = scst_parse_add_repl_param(acg, dev, pp, &virt_lun, &read_only); if (res != 0) goto out_unlock; - res = scst_acg_repl_lun(acg, - tgt_kobj ? tgt->tgt_luns_kobj : acg->luns_kobj, - dev, virt_lun, read_only, replace_gen_ua); + + res = scst_acg_repl_lun(acg, tgt_kobj ? tgt->tgt_luns_kobj : + acg->luns_kobj, dev, virt_lun, + flags); if (res != 0) goto out_unlock; break; + } case SCST_LUN_ACTION_DEL: p = scst_get_next_lexem(&pp); res = kstrtoul(p, 0, &virt_lun);