Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scst_sysfs: Add support for cluster_name #129

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scst/src/scst_dlm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,4 +1510,6 @@ const struct scst_cl_ops scst_dlm_cl_ops = {
.reserve = scst_dlm_reserve,
};

char *scst_dlm_cluster_name;

#endif
5 changes: 3 additions & 2 deletions scst/src/scst_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
66 changes: 66 additions & 0 deletions scst/src/scst_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7594,6 +7594,70 @@ 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 = 0;

TRACE_ENTRY();

if (scst_dlm_cluster_name != NULL)
res = sprintf(buf, "%s\n%s", scst_dlm_cluster_name,
SCST_SYSFS_KEY_MARK "\n");

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 = 0;
int len;

TRACE_ENTRY();

if ((buf == NULL) || (count == 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;
}

kfree(scst_dlm_cluster_name);
scst_dlm_cluster_name = kstrndup(buf, len, GFP_KERNEL);
if (!scst_dlm_cluster_name) {
PRINT_ERROR("Unable to alloc cluster_name string (len %d)",
len+1);
res = -ENOMEM;
goto out;
}

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,
Expand All @@ -7609,6 +7673,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)
Expand Down Expand Up @@ -7932,6 +7997,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();

Expand Down