diff --git a/scst/src/scst_dlm.c b/scst/src/scst_dlm.c index 046800345..109dc83a0 100644 --- a/scst/src/scst_dlm.c +++ b/scst/src/scst_dlm.c @@ -1510,4 +1510,6 @@ const struct scst_cl_ops scst_dlm_cl_ops = { .reserve = scst_dlm_reserve, }; +char *scst_dlm_cluster_name; + #endif diff --git a/scst/src/scst_priv.h b/scst/src/scst_priv.h index ce5b5eb55..c2e2cf727 100644 --- a/scst/src/scst_priv.h +++ b/scst/src/scst_priv.h @@ -176,6 +176,7 @@ extern wait_queue_head_t scst_dev_cmd_waitQ; extern const struct scst_cl_ops scst_no_dlm_cl_ops; extern const struct scst_cl_ops scst_dlm_cl_ops; +extern char *scst_dlm_cluster_name; extern unsigned int scst_setup_id; @@ -417,8 +418,8 @@ static inline int scst_dlm_new_lockspace(const char *name, int namelen, uint32_t flags, int lvblen) { - return dlm_new_lockspace(name, NULL, flags, lvblen, NULL, NULL, NULL, - lockspace); + return dlm_new_lockspace(name, scst_dlm_cluster_name, flags, lvblen, + NULL, NULL, NULL, lockspace); } int scst_alloc_space(struct scst_cmd *cmd); diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 8fed1731a..a4d5c3098 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -7593,6 +7593,80 @@ static struct kobj_attribute scst_last_sysfs_mgmt_res_attr = __ATTR(last_sysfs_mgmt_res, S_IRUGO, scst_last_sysfs_mgmt_res_show, NULL); +static ssize_t scst_cluster_name_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + int res; + + TRACE_ENTRY(); + + if (scst_dlm_cluster_name != NULL) + res = sprintf(buf, "%s\n%s", scst_dlm_cluster_name, + SCST_SYSFS_KEY_MARK "\n"); + else + res = 0; + + TRACE_EXIT_RES(res); + return res; +} + +static ssize_t scst_cluster_name_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int res; + char *p; + int len; + + TRACE_ENTRY(); + + if ((buf == NULL) || (count == 0)) { + res = 0; + goto out; + } + + len = strnlen(buf, count); + if (buf[count-1] == '\n') + len--; + + if (len == 0) { + kfree(scst_dlm_cluster_name); + scst_dlm_cluster_name = NULL; + goto out_done; + } + + if (len >= DLM_LOCKSPACE_LEN) { + PRINT_ERROR("cluster_name string too long (len %d)", len); + res = -EINVAL; + goto out; + } + + p = kmalloc(len+1, GFP_KERNEL); + if (p == NULL) { + PRINT_ERROR("Unable to alloc cluster_name string (len %d)", + len+1); + res = -ENOMEM; + goto out; + } + + memcpy(p, buf, len); + p[len] = '\0'; + + kfree(scst_dlm_cluster_name); + + scst_dlm_cluster_name = p; + +out_done: + res = count; + +out: + TRACE_EXIT_RES(res); + return res; +} + +static struct kobj_attribute scst_cluster_name_attr = + __ATTR(cluster_name, S_IRUGO | S_IWUSR, scst_cluster_name_show, + scst_cluster_name_store); + static struct attribute *scst_sysfs_root_def_attrs[] = { &scst_measure_latency_attr.attr, &scst_threads_attr.attr, @@ -7608,6 +7682,7 @@ static struct attribute *scst_sysfs_root_def_attrs[] = { &scst_trace_mcmds_attr.attr, &scst_version_attr.attr, &scst_last_sysfs_mgmt_res_attr.attr, + &scst_cluster_name_attr.attr, NULL, }; #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0) @@ -7931,6 +8006,7 @@ void scst_sysfs_cleanup(void) TRACE_ENTRY(); PRINT_INFO("%s", "Exiting SCST sysfs hierarchy..."); + kfree(scst_dlm_cluster_name); scst_del_put_sgv_kobj();