From f5709940008265e8de999af82af543aac5d317b7 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 22:27:04 +0000 Subject: [PATCH] scst: Change add_device_parameters from a string into an array This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7964 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst.h | 7 +- scst/src/dev_handlers/scst_vdisk.c | 121 ++++++++++++++++------------- scst/src/scst_sysfs.c | 37 +++++++-- 3 files changed, 104 insertions(+), 61 deletions(-) diff --git a/scst/include/scst.h b/scst/include/scst.h index ecaf73e14..19281a170 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -1734,8 +1734,11 @@ struct scst_dev_type { /* Optional help string for mgmt_cmd commands */ const char *mgmt_cmd_help; - /* List of parameters for add_device command, if any */ - const char *add_device_parameters; + /* + * Array with parameters for add_device command, if any. NULL + * terminated. + */ + const char *const *add_device_parameters; /* * List of optional, i.e. which could be added by add_attribute command diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index c392b7489..04ca40ea9 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -754,6 +754,28 @@ static vdisk_op_fn fileio_ops[256]; static vdisk_op_fn blockio_ops[256]; static vdisk_op_fn nullio_ops[256]; +static const char *fileio_add_dev_params[] = { + "async", + "blocksize", + "cluster_mode", + "dif_filename", + "dif_mode", + "dif_static_app_tag", + "dif_type", + "filename", + "numa_node_id", + "nv_cache", + "o_direct", + "read_only", + "removable", + "rotational", + "thin_provisioned", + "tst", + "write_through", + "zero_copy", + NULL +}; + /* * Be careful changing "name" field, since it is the name of the corresponding * /sys/kernel/scst_tgt entry, hence a part of user space ABI. @@ -786,25 +808,7 @@ static struct scst_dev_type vdisk_file_devtype = { .add_device = vdisk_add_fileio_device, .del_device = vdisk_del_device, .dev_attrs = vdisk_fileio_attrs, - .add_device_parameters = - "async, " - "blocksize, " - "cluster_mode, " - "filename, " - "numa_node_id, " - "nv_cache, " - "o_direct, " - "read_only, " - "removable, " - "rotational, " - "thin_provisioned, " - "tst, " - "write_through, " - "zero_copy, " - "dif_mode, " - "dif_type, " - "dif_static_app_tag, " - "dif_filename", + .add_device_parameters = fileio_add_dev_params, #endif #if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, @@ -818,6 +822,27 @@ static struct scst_dev_type vdisk_file_devtype = { static struct kmem_cache *blockio_work_cachep; +static const char *blockio_add_dev_params[] = { + "active", + "bind_alua_state", + "blocksize", + "cluster_mode", + "dif_filename", + "dif_mode", + "dif_static_app_tag", + "dif_type", + "filename", + "numa_node_id", + "nv_cache", + "read_only", + "removable", + "rotational", + "thin_provisioned", + "tst", + "write_through", + NULL +}; + static struct scst_dev_type vdisk_blk_devtype = { .name = "vdisk_blockio", .type = TYPE_DISK, @@ -843,24 +868,7 @@ static struct scst_dev_type vdisk_blk_devtype = { .add_device = vdisk_add_blockio_device, .del_device = vdisk_del_device, .dev_attrs = vdisk_blockio_attrs, - .add_device_parameters = - "active, " - "bind_alua_state, " - "blocksize, " - "dif_mode, " - "dif_type, " - "dif_static_app_tag, " - "dif_filename, " - "filename, " - "numa_node_id, " - "nv_cache, " - "cluster_mode, " - "read_only, " - "removable, " - "rotational, " - "thin_provisioned, " - "tst, " - "write_through", + .add_device_parameters = blockio_add_dev_params, #endif #if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, @@ -872,6 +880,23 @@ static struct scst_dev_type vdisk_blk_devtype = { #endif }; +static const char *nullio_add_dev_params[] = { + "blocksize", + "cluster_mode", + "dif_mode", + "dif_static_app_tag", + "dif_type", + "dummy", + "numa_node_id", + "read_only", + "removable", + "rotational", + "size", + "size_mb", + "tst", + NULL +}; + static struct scst_dev_type vdisk_null_devtype = { .name = "vdisk_nullio", .type = TYPE_DISK, @@ -895,20 +920,7 @@ static struct scst_dev_type vdisk_null_devtype = { .add_device = vdisk_add_nullio_device, .del_device = vdisk_del_device, .dev_attrs = vdisk_nullio_attrs, - .add_device_parameters = - "blocksize, " - "dif_mode, " - "dif_type, " - "dif_static_app_tag, " - "dummy, " - "numa_node_id, " - "cluster_mode, " - "read_only, " - "removable, " - "rotational, " - "size, " - "size_mb, " - "tst", + .add_device_parameters = nullio_add_dev_params, #endif #if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, @@ -920,6 +932,11 @@ static struct scst_dev_type vdisk_null_devtype = { #endif }; +static const char *cdrom_add_dev_params[] = { + "tst", + NULL, +}; + static struct scst_dev_type vcdrom_devtype = { .name = "vcdrom", .type = TYPE_ROM, @@ -943,7 +960,7 @@ static struct scst_dev_type vcdrom_devtype = { .add_device = vcdrom_add_device, .del_device = vcdrom_del_device, .dev_attrs = vcdrom_attrs, - .add_device_parameters = "tst", + .add_device_parameters = cdrom_add_dev_params, #endif #if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index b41296141..dc26bc668 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -5771,6 +5771,28 @@ static struct kobj_type scst_devt_ktype = { .default_attrs = scst_devt_default_attrs, }; +static char *scst_dev_params(struct scst_dev_type *devt) +{ + char *p, *r; + const char *const *q; + bool comma = false; + + if (!devt->add_device_parameters) + return NULL; + p = kstrdup("The following parameters available: ", GFP_KERNEL); + if (!p) + return NULL; + for (q = devt->add_device_parameters; *q; q++) { + r = kasprintf(GFP_KERNEL, "%s%s%s", p, comma ? ", " : "", *q); + kfree(p); + if (!r) + return NULL; + p = r; + comma = true; + } + return p; +} + static ssize_t scst_devt_mgmt_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -5782,12 +5804,14 @@ static ssize_t scst_devt_mgmt_show(struct kobject *kobj, "\n" "where parameters are one or more " "param_name=value pairs separated by ';'\n\n" - "%s%s%s%s%s%s%s%s%s%s\n"; + "%s%s%s%s%s%s%s%s%s\n"; struct scst_dev_type *devt; + char *p; + int res; devt = container_of(kobj, struct scst_dev_type, devt_kobj); - - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, help, + p = scst_dev_params(devt); + res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, help, (devt->devt_optional_attributes != NULL) ? " echo \"add_attribute \" >mgmt\n" " echo \"del_attribute \" >mgmt\n" : "", @@ -5796,10 +5820,7 @@ static ssize_t scst_devt_mgmt_show(struct kobject *kobj, " echo \"del_device_attribute device_name \" >mgmt\n" : "", (devt->mgmt_cmd_help) ? devt->mgmt_cmd_help : "", (devt->mgmt_cmd_help) ? "\n" : "", - (devt->add_device_parameters != NULL) ? - "The following parameters available: " : "", - (devt->add_device_parameters != NULL) ? - devt->add_device_parameters : "", + p ? : "", (devt->add_device_parameters != NULL) ? "\n" : "", (devt->devt_optional_attributes != NULL) ? "The following dev handler attributes available: " : "", @@ -5811,6 +5832,8 @@ static ssize_t scst_devt_mgmt_show(struct kobject *kobj, (devt->dev_optional_attributes != NULL) ? devt->dev_optional_attributes : "", (devt->dev_optional_attributes != NULL) ? "\n" : ""); + kfree(p); + return res; } static int scst_process_devt_mgmt_store(char *buffer,