Skip to content

Commit

Permalink
scst_sysfs: Add support for cluster_name
Browse files Browse the repository at this point in the history
When dlm_new_lockspace is called with a NULL cluster_name the
kernel will emit an error message "dlm cluster name '%s' is being
used without an application provided cluster name".

Therefore, provide a mechanism to set a cluster_name and use it
when calling dlm_new_lockspace.
  • Loading branch information
bmeagherix committed Feb 8, 2023
1 parent e76e326 commit ba3540d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
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
76 changes: 76 additions & 0 deletions scst/src/scst_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit ba3540d

Please sign in to comment.