scsi: Remove global unmap config parameters
None of these make sense as global parameters - they're all only configurable per-disk. This is a large simplification and removes the SCSI library's dependency on the config file entirely. Change-Id: I1236158a23fa49e437938c51022b13772e404561 Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/371598 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
8422f88644
commit
c0de8a8b0e
@ -34,61 +34,8 @@
|
||||
|
||||
#include "scsi_internal.h"
|
||||
|
||||
#include "spdk/conf.h"
|
||||
|
||||
#define DEFAULT_MAX_UNMAP_LBA_COUNT 4194304
|
||||
#define DEFAULT_OPTIMAL_UNMAP_GRANULARITY 0
|
||||
#define DEFAULT_UNMAP_GRANULARITY_ALIGNMENT 0
|
||||
#define DEFAULT_UGAVALID 0
|
||||
#define DEFAULT_MAX_WRITE_SAME_LENGTH 512
|
||||
|
||||
struct spdk_scsi_globals g_spdk_scsi;
|
||||
|
||||
static void
|
||||
spdk_set_default_scsi_parameters(void)
|
||||
{
|
||||
g_spdk_scsi.scsi_params.max_unmap_lba_count = DEFAULT_MAX_UNMAP_LBA_COUNT;
|
||||
g_spdk_scsi.scsi_params.optimal_unmap_granularity =
|
||||
DEFAULT_OPTIMAL_UNMAP_GRANULARITY;
|
||||
g_spdk_scsi.scsi_params.unmap_granularity_alignment =
|
||||
DEFAULT_UNMAP_GRANULARITY_ALIGNMENT;
|
||||
g_spdk_scsi.scsi_params.ugavalid = DEFAULT_UGAVALID;
|
||||
g_spdk_scsi.scsi_params.max_write_same_length = DEFAULT_MAX_WRITE_SAME_LENGTH;
|
||||
}
|
||||
|
||||
static int
|
||||
spdk_read_config_scsi_parameters(void)
|
||||
{
|
||||
struct spdk_conf_section *sp;
|
||||
const char *val;
|
||||
|
||||
sp = spdk_conf_find_section(NULL, "Scsi");
|
||||
if (sp == NULL) {
|
||||
spdk_set_default_scsi_parameters();
|
||||
return 0;
|
||||
}
|
||||
|
||||
val = spdk_conf_section_get_val(sp, "MaxUnmapLbaCount");
|
||||
g_spdk_scsi.scsi_params.max_unmap_lba_count = (val == NULL) ?
|
||||
DEFAULT_MAX_UNMAP_LBA_COUNT : strtoul(val, NULL, 10);
|
||||
|
||||
val = spdk_conf_section_get_val(sp, "OptimalUnmapGranularity");
|
||||
g_spdk_scsi.scsi_params.optimal_unmap_granularity = (val == NULL) ?
|
||||
DEFAULT_OPTIMAL_UNMAP_GRANULARITY : strtoul(val, NULL, 10);
|
||||
|
||||
val = spdk_conf_section_get_val(sp, "UnmapGranularityAlignment");
|
||||
g_spdk_scsi.scsi_params.unmap_granularity_alignment = (val == NULL) ?
|
||||
DEFAULT_UNMAP_GRANULARITY_ALIGNMENT : strtoul(val, NULL, 10);
|
||||
|
||||
g_spdk_scsi.scsi_params.ugavalid = spdk_conf_section_get_boolval(sp, "Ugavalid", DEFAULT_UGAVALID);
|
||||
|
||||
val = spdk_conf_section_get_val(sp, "MaxWriteSameLength");
|
||||
g_spdk_scsi.scsi_params.max_write_same_length = (val == NULL) ?
|
||||
DEFAULT_MAX_WRITE_SAME_LENGTH : strtoul(val, NULL, 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_scsi_init(void)
|
||||
{
|
||||
@ -100,12 +47,6 @@ spdk_scsi_init(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = spdk_read_config_scsi_parameters();
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("spdk_scsi_parameters() failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -560,7 +560,8 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
|
||||
* maximum number of LBAs that may be
|
||||
* unmapped by an UNMAP command.
|
||||
*/
|
||||
to_be32(&data[20], g_spdk_scsi.scsi_params.max_unmap_lba_count);
|
||||
/* For now, choose 4MB as the maximum. */
|
||||
to_be32(&data[20], 4194304);
|
||||
|
||||
/*
|
||||
* MAXIMUM UNMAP BLOCK DESCRIPTOR COUNT:
|
||||
@ -574,28 +575,10 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
|
||||
to_be32(&data[24], DEFAULT_MAX_UNMAP_BLOCK_DESCRIPTOR_COUNT);
|
||||
|
||||
/*
|
||||
* OPTIMAL UNMAP GRANULARITY: indicates the
|
||||
* optimal granularity in logical blocks
|
||||
* for unmap request.
|
||||
* The UGAVALID bit is left as 0 which means neither the
|
||||
* OPTIMAL UNMAP GRANULARITY nor the UNMAP GRANULARITY
|
||||
* ALIGNMENT fields are valid.
|
||||
*/
|
||||
to_be32(&data[28], g_spdk_scsi.scsi_params.optimal_unmap_granularity);
|
||||
|
||||
/*
|
||||
* UNMAP GRANULARITY ALIGNMENT: indicates the
|
||||
* LBA of the first logical block to which the
|
||||
* OPTIMAL UNMAP GRANULARITY field applies.
|
||||
*/
|
||||
/* not specified */
|
||||
to_be32(&data[32], g_spdk_scsi.scsi_params.unmap_granularity_alignment);
|
||||
|
||||
/*
|
||||
* UGAVALID(7): bit set to one indicates that
|
||||
* the UNMAP GRANULARITY ALIGNMENT field is
|
||||
* valid.
|
||||
*/
|
||||
/* not specified */
|
||||
if (g_spdk_scsi.scsi_params.ugavalid)
|
||||
data[32] |= 1 << 7;
|
||||
|
||||
/*
|
||||
* MAXIMUM WRITE SAME LENGTH: indicates the
|
||||
@ -603,7 +586,7 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
|
||||
* that the device server allows to be unmapped
|
||||
* or written in a single WRITE SAME command.
|
||||
*/
|
||||
to_be64(&data[36], g_spdk_scsi.scsi_params.max_write_same_length);
|
||||
to_be64(&data[36], 512);
|
||||
|
||||
/* Reserved */
|
||||
/* not specified */
|
||||
|
@ -163,17 +163,8 @@ int spdk_scsi_port_construct(struct spdk_scsi_port *port, uint64_t id,
|
||||
int spdk_bdev_scsi_execute(struct spdk_bdev *bdev, struct spdk_scsi_task *task);
|
||||
int spdk_bdev_scsi_reset(struct spdk_bdev *bdev, struct spdk_scsi_task *task);
|
||||
|
||||
struct spdk_scsi_parameters {
|
||||
uint32_t max_unmap_lba_count;
|
||||
uint32_t optimal_unmap_granularity;
|
||||
uint32_t unmap_granularity_alignment;
|
||||
uint32_t ugavalid;
|
||||
uint64_t max_write_same_length;
|
||||
};
|
||||
|
||||
struct spdk_scsi_globals {
|
||||
pthread_mutex_t mutex;
|
||||
struct spdk_scsi_parameters scsi_params;
|
||||
};
|
||||
|
||||
extern struct spdk_scsi_globals g_spdk_scsi;
|
||||
|
@ -39,286 +39,13 @@
|
||||
|
||||
#include "scsi.c"
|
||||
|
||||
static int
|
||||
null_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
null_clean(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct spdk_conf *
|
||||
spdk_config_init_scsi_params(char *key, char *value)
|
||||
{
|
||||
struct spdk_conf *spdk_config;
|
||||
FILE *f;
|
||||
int fd, rc;
|
||||
char filename[] = "/tmp/scsi_init_ut.XXXXXX";
|
||||
|
||||
/* Create temporary file to hold config */
|
||||
fd = mkstemp(filename);
|
||||
SPDK_CU_ASSERT_FATAL(fd != -1);
|
||||
|
||||
f = fdopen(fd, "wb+");
|
||||
SPDK_CU_ASSERT_FATAL(f != NULL);
|
||||
|
||||
fprintf(f, "[Scsi]\n");
|
||||
fprintf(f, "%s %s\n", key, value);
|
||||
|
||||
fclose(f);
|
||||
|
||||
spdk_config = spdk_conf_allocate();
|
||||
SPDK_CU_ASSERT_FATAL(spdk_config != NULL);
|
||||
|
||||
rc = spdk_conf_read(spdk_config, filename);
|
||||
SPDK_CU_ASSERT_FATAL(rc == 0);
|
||||
|
||||
spdk_conf_set_as_default(spdk_config);
|
||||
|
||||
remove(filename);
|
||||
|
||||
return spdk_config;
|
||||
}
|
||||
|
||||
static void
|
||||
set_default_scsi_params(struct spdk_scsi_parameters *params)
|
||||
scsi_init(void)
|
||||
{
|
||||
memset(params, 0, sizeof(*params));
|
||||
params->max_unmap_lba_count = DEFAULT_MAX_UNMAP_LBA_COUNT;
|
||||
params->optimal_unmap_granularity = DEFAULT_OPTIMAL_UNMAP_GRANULARITY;
|
||||
params->unmap_granularity_alignment = DEFAULT_UNMAP_GRANULARITY_ALIGNMENT;
|
||||
params->ugavalid = DEFAULT_UGAVALID;
|
||||
params->max_write_same_length = DEFAULT_MAX_WRITE_SAME_LENGTH;
|
||||
}
|
||||
|
||||
static void
|
||||
scsi_init_sp_null(void)
|
||||
{
|
||||
struct spdk_conf *config;
|
||||
int rc;
|
||||
|
||||
config = spdk_conf_allocate();
|
||||
SPDK_CU_ASSERT_FATAL(config != NULL);
|
||||
|
||||
spdk_conf_set_as_default(config);
|
||||
|
||||
rc = spdk_scsi_init();
|
||||
|
||||
/* sp = null; set default scsi params */
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
spdk_conf_set_as_default(NULL);
|
||||
|
||||
spdk_conf_free(config);
|
||||
}
|
||||
|
||||
static void
|
||||
scsi_init_set_max_unmap_lba_count_config_param(void)
|
||||
{
|
||||
struct spdk_scsi_parameters params;
|
||||
struct spdk_conf *config;
|
||||
int rc;
|
||||
|
||||
/* set scsi_params.max_unmap_lba_count = 65536 of Scsi section */
|
||||
config = spdk_config_init_scsi_params("MaxUnmapLbaCount", "65536");
|
||||
spdk_conf_set_as_default(config);
|
||||
rc = spdk_scsi_init();
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
/* Assert the scsi_params.max_unmap_lba_count == 65536 and
|
||||
* assert the rest of the params are set to their default values */
|
||||
set_default_scsi_params(¶ms);
|
||||
params.max_unmap_lba_count = 65536;
|
||||
CU_ASSERT(memcmp(&g_spdk_scsi.scsi_params, ¶ms, sizeof(params)) == 0);
|
||||
|
||||
spdk_conf_free(config);
|
||||
}
|
||||
|
||||
static void
|
||||
scsi_init_set_optimal_unmap_granularity_config_param(void)
|
||||
{
|
||||
struct spdk_scsi_parameters params;
|
||||
struct spdk_conf *config;
|
||||
int rc;
|
||||
|
||||
/* set scsi_params.optimal_unmap_granularity = 0
|
||||
* of Scsi section */
|
||||
config = spdk_config_init_scsi_params("OptimalUnmapGranularity", "0");
|
||||
spdk_conf_set_as_default(config);
|
||||
rc = spdk_scsi_init();
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
/* Assert the scsi_params.optimal_unmap_granularity == 0 and
|
||||
* assert the rest of the params are set to their default values */
|
||||
set_default_scsi_params(¶ms);
|
||||
params.optimal_unmap_granularity = 0;
|
||||
CU_ASSERT(memcmp(&g_spdk_scsi.scsi_params, ¶ms, sizeof(params)) == 0);
|
||||
|
||||
spdk_conf_free(config);
|
||||
}
|
||||
|
||||
static void
|
||||
scsi_init_set_unmap_granularity_alignment_config_param(void)
|
||||
{
|
||||
struct spdk_scsi_parameters params;
|
||||
struct spdk_conf *config;
|
||||
int rc;
|
||||
|
||||
/* set scsi_params.unmap_granularity_alignment = 0
|
||||
* of Scsi section */
|
||||
config = spdk_config_init_scsi_params("UnmapGranularityAlignment", "0");
|
||||
spdk_conf_set_as_default(config);
|
||||
rc = spdk_scsi_init();
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
/* Assert the scsi_params.unmap_granularity_alignment == 0 and
|
||||
* assert the rest of the params are set to their default values */
|
||||
set_default_scsi_params(¶ms);
|
||||
params.unmap_granularity_alignment = 0;
|
||||
CU_ASSERT(memcmp(&g_spdk_scsi.scsi_params, ¶ms, sizeof(params)) == 0);
|
||||
|
||||
spdk_conf_free(config);
|
||||
}
|
||||
|
||||
static void
|
||||
scsi_init_ugavalid_yes(void)
|
||||
{
|
||||
struct spdk_scsi_parameters params;
|
||||
struct spdk_conf *config;
|
||||
int rc;
|
||||
|
||||
/* set scsi_params.ugavalid = Yes
|
||||
* of Scsi section */
|
||||
config = spdk_config_init_scsi_params("Ugavalid", "Yes");
|
||||
spdk_conf_set_as_default(config);
|
||||
rc = spdk_scsi_init();
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
/* Assert the scsi_params.ugavalid == 1 and
|
||||
* assert the rest of the params are set to their default values */
|
||||
set_default_scsi_params(¶ms);
|
||||
params.ugavalid = 1;
|
||||
CU_ASSERT(memcmp(&g_spdk_scsi.scsi_params, ¶ms, sizeof(params)) == 0);
|
||||
|
||||
spdk_conf_free(config);
|
||||
}
|
||||
|
||||
static void
|
||||
scsi_init_ugavalid_no(void)
|
||||
{
|
||||
struct spdk_scsi_parameters params;
|
||||
struct spdk_conf *config;
|
||||
int rc;
|
||||
|
||||
/* set scsi_params.ugavalid = No
|
||||
* of Scsi section */
|
||||
config = spdk_config_init_scsi_params("Ugavalid", "No");
|
||||
spdk_conf_set_as_default(config);
|
||||
rc = spdk_scsi_init();
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
/* Assert the scsi_params.ugavalid == 0 and
|
||||
* assert the rest of the params are set to their default values */
|
||||
set_default_scsi_params(¶ms);
|
||||
params.ugavalid = 0;
|
||||
CU_ASSERT(memcmp(&g_spdk_scsi.scsi_params, ¶ms, sizeof(params)) == 0);
|
||||
|
||||
spdk_conf_free(config);
|
||||
}
|
||||
|
||||
static void
|
||||
scsi_init_ugavalid_unknown_value_failure(void)
|
||||
{
|
||||
struct spdk_scsi_parameters params;
|
||||
struct spdk_conf *config;
|
||||
int rc;
|
||||
|
||||
/* set scsi_params.ugavalid = unknown value
|
||||
* of Scsi section */
|
||||
config = spdk_config_init_scsi_params("Ugavalid", "unknown value");
|
||||
spdk_conf_set_as_default(config);
|
||||
rc = spdk_scsi_init();
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
/* Assert the scsi_params.ugavalid == DEFAULT_UGAVALID and
|
||||
* assert the rest of the params are set to their default values */
|
||||
set_default_scsi_params(¶ms);
|
||||
params.ugavalid = DEFAULT_UGAVALID;
|
||||
CU_ASSERT(memcmp(&g_spdk_scsi.scsi_params, ¶ms, sizeof(params)) == 0);
|
||||
|
||||
spdk_conf_free(config);
|
||||
}
|
||||
|
||||
static void
|
||||
scsi_init_max_write_same_length(void)
|
||||
{
|
||||
struct spdk_scsi_parameters params;
|
||||
struct spdk_conf *config;
|
||||
int rc;
|
||||
|
||||
/* set scsi_params.max_write_same_length = 512
|
||||
* of Scsi section */
|
||||
config = spdk_config_init_scsi_params("MaxWriteSameLength", "512");
|
||||
spdk_conf_set_as_default(config);
|
||||
rc = spdk_scsi_init();
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
/* Assert the scsi_params.max_write_same_length == 512 and
|
||||
* assert the rest of the params are set to their default values */
|
||||
set_default_scsi_params(¶ms);
|
||||
params.max_write_same_length = 512;
|
||||
CU_ASSERT(memcmp(&g_spdk_scsi.scsi_params, ¶ms, sizeof(params)) == 0);
|
||||
|
||||
spdk_conf_free(config);
|
||||
}
|
||||
|
||||
static void
|
||||
scsi_init_read_config_scsi_params(void)
|
||||
{
|
||||
struct spdk_scsi_parameters params;
|
||||
struct spdk_conf *config;
|
||||
int rc;
|
||||
|
||||
/* Set null for item's key and value;
|
||||
* set default scsi parameters */
|
||||
config = spdk_config_init_scsi_params("", "");
|
||||
spdk_conf_set_as_default(config);
|
||||
rc = spdk_scsi_init();
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
/* Sets the default values for all the parameters
|
||||
* of the Scsi section and returns success */
|
||||
set_default_scsi_params(¶ms);
|
||||
CU_ASSERT(memcmp(&g_spdk_scsi.scsi_params, ¶ms, sizeof(params)) == 0);
|
||||
|
||||
spdk_conf_free(config);
|
||||
}
|
||||
|
||||
static void
|
||||
scsi_init_success(void)
|
||||
{
|
||||
struct spdk_scsi_parameters params;
|
||||
struct spdk_conf *config;
|
||||
int rc;
|
||||
|
||||
/* Set null for item's key and value;
|
||||
* set default scsi parameters */
|
||||
config = spdk_config_init_scsi_params("", "");
|
||||
spdk_conf_set_as_default(config);
|
||||
rc = spdk_scsi_init();
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
/* Sets the default values for all the parameters
|
||||
* of the Scsi section, initialize th device
|
||||
* and returns success */
|
||||
set_default_scsi_params(¶ms);
|
||||
CU_ASSERT(memcmp(&g_spdk_scsi.scsi_params, ¶ms, sizeof(params)) == 0);
|
||||
|
||||
spdk_conf_free(config);
|
||||
}
|
||||
|
||||
int
|
||||
@ -331,32 +58,15 @@ main(int argc, char **argv)
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
suite = CU_add_suite("scsi_suite", null_init, null_clean);
|
||||
suite = CU_add_suite("scsi_suite", NULL, NULL);
|
||||
if (suite == NULL) {
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
if (
|
||||
CU_add_test(suite, "scsi init - set default scsi params", \
|
||||
scsi_init_sp_null) == NULL
|
||||
|| CU_add_test(suite, "scsi init - set max_unmap_lba_count", \
|
||||
scsi_init_set_max_unmap_lba_count_config_param) == NULL
|
||||
|| CU_add_test(suite, "scsi init - set optimal_unmap_granularity", \
|
||||
scsi_init_set_optimal_unmap_granularity_config_param) == NULL
|
||||
|| CU_add_test(suite, "scsi init - set unmap_granularity_alignment", \
|
||||
scsi_init_set_unmap_granularity_alignment_config_param) == NULL
|
||||
|| CU_add_test(suite, "scsi init - ugavalid value yes", \
|
||||
scsi_init_ugavalid_yes) == NULL
|
||||
|| CU_add_test(suite, "scsi init - ugavalid value no", \
|
||||
scsi_init_ugavalid_no) == NULL
|
||||
|| CU_add_test(suite, "scsi init - ugavalid unknown value", \
|
||||
scsi_init_ugavalid_unknown_value_failure) == NULL
|
||||
|| CU_add_test(suite, "scsi init - set max_write_same_length", \
|
||||
scsi_init_max_write_same_length) == NULL
|
||||
|| CU_add_test(suite, "scsi init - read config scsi parameters", \
|
||||
scsi_init_read_config_scsi_params) == NULL
|
||||
|| CU_add_test(suite, "scsi init - success", scsi_init_success) == NULL
|
||||
CU_add_test(suite, "scsi init", \
|
||||
scsi_init) == NULL
|
||||
) {
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
|
Loading…
Reference in New Issue
Block a user