configfs.c (94a39d61f80fcd679debda11e1ca02b88d90e67e) configfs.c (013b7ebe5a0d70e2a02fd225174595e79c591b3e)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Configfs interface for the NVMe target.
4 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
5 */
6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7#include <linux/kernel.h>
8#include <linux/module.h>

--- 905 unchanged lines hidden (view full) ---

914 return cnt;
915
916out_unlock:
917 up_write(&nvmet_config_sem);
918 return -EINVAL;
919}
920CONFIGFS_ATTR(nvmet_subsys_, attr_cntlid_max);
921
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Configfs interface for the NVMe target.
4 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
5 */
6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7#include <linux/kernel.h>
8#include <linux/module.h>

--- 905 unchanged lines hidden (view full) ---

914 return cnt;
915
916out_unlock:
917 up_write(&nvmet_config_sem);
918 return -EINVAL;
919}
920CONFIGFS_ATTR(nvmet_subsys_, attr_cntlid_max);
921
922static ssize_t nvmet_subsys_attr_model_show(struct config_item *item,
923 char *page)
924{
925 struct nvmet_subsys *subsys = to_subsys(item);
926 struct nvmet_subsys_model *subsys_model;
927 char *model = NVMET_DEFAULT_CTRL_MODEL;
928 int ret;
929
930 rcu_read_lock();
931 subsys_model = rcu_dereference(subsys->model);
932 if (subsys_model)
933 model = subsys_model->number;
934 ret = snprintf(page, PAGE_SIZE, "%s\n", model);
935 rcu_read_unlock();
936
937 return ret;
938}
939
940/* See Section 1.5 of NVMe 1.4 */
941static bool nvmet_is_ascii(const char c)
942{
943 return c >= 0x20 && c <= 0x7e;
944}
945
946static ssize_t nvmet_subsys_attr_model_store(struct config_item *item,
947 const char *page, size_t count)
948{
949 struct nvmet_subsys *subsys = to_subsys(item);
950 struct nvmet_subsys_model *new_model;
951 char *new_model_number;
952 int pos = 0, len;
953
954 len = strcspn(page, "\n");
955 if (!len)
956 return -EINVAL;
957
958 for (pos = 0; pos < len; pos++) {
959 if (!nvmet_is_ascii(page[pos]))
960 return -EINVAL;
961 }
962
963 new_model_number = kstrndup(page, len, GFP_KERNEL);
964 if (!new_model_number)
965 return -ENOMEM;
966
967 new_model = kzalloc(sizeof(*new_model) + len + 1, GFP_KERNEL);
968 if (!new_model) {
969 kfree(new_model_number);
970 return -ENOMEM;
971 }
972 memcpy(new_model->number, new_model_number, len);
973
974 down_write(&nvmet_config_sem);
975 mutex_lock(&subsys->lock);
976 new_model = rcu_replace_pointer(subsys->model, new_model,
977 mutex_is_locked(&subsys->lock));
978 mutex_unlock(&subsys->lock);
979 up_write(&nvmet_config_sem);
980
981 kfree_rcu(new_model, rcuhead);
982
983 return count;
984}
985CONFIGFS_ATTR(nvmet_subsys_, attr_model);
986
922static struct configfs_attribute *nvmet_subsys_attrs[] = {
923 &nvmet_subsys_attr_attr_allow_any_host,
924 &nvmet_subsys_attr_attr_version,
925 &nvmet_subsys_attr_attr_serial,
926 &nvmet_subsys_attr_attr_cntlid_min,
927 &nvmet_subsys_attr_attr_cntlid_max,
987static struct configfs_attribute *nvmet_subsys_attrs[] = {
988 &nvmet_subsys_attr_attr_allow_any_host,
989 &nvmet_subsys_attr_attr_version,
990 &nvmet_subsys_attr_attr_serial,
991 &nvmet_subsys_attr_attr_cntlid_min,
992 &nvmet_subsys_attr_attr_cntlid_max,
993 &nvmet_subsys_attr_attr_model,
928 NULL,
929};
930
931/*
932 * Subsystem structures & folder operation functions below
933 */
934static void nvmet_subsys_release(struct config_item *item)
935{

--- 463 unchanged lines hidden ---
994 NULL,
995};
996
997/*
998 * Subsystem structures & folder operation functions below
999 */
1000static void nvmet_subsys_release(struct config_item *item)
1001{

--- 463 unchanged lines hidden ---