configfs.c (78e18063a9696c508dc95581fb8ec1aee539c4ee) configfs.c (72efd25dcf4f6310e9e6fa85620aa443b27c23fe)
1/*
2 * Configfs interface for the NVMe target.
3 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *

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

213
214 if (sscanf(page, "%s\n", port->disc_addr.trsvcid) != 1)
215 return -EINVAL;
216 return count;
217}
218
219CONFIGFS_ATTR(nvmet_, addr_trsvcid);
220
1/*
2 * Configfs interface for the NVMe target.
3 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *

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

213
214 if (sscanf(page, "%s\n", port->disc_addr.trsvcid) != 1)
215 return -EINVAL;
216 return count;
217}
218
219CONFIGFS_ATTR(nvmet_, addr_trsvcid);
220
221static ssize_t nvmet_param_inline_data_size_show(struct config_item *item,
222 char *page)
223{
224 struct nvmet_port *port = to_nvmet_port(item);
225
226 return snprintf(page, PAGE_SIZE, "%d\n", port->inline_data_size);
227}
228
229static ssize_t nvmet_param_inline_data_size_store(struct config_item *item,
230 const char *page, size_t count)
231{
232 struct nvmet_port *port = to_nvmet_port(item);
233 int ret;
234
235 if (port->enabled) {
236 pr_err("Cannot modify inline_data_size while port enabled\n");
237 pr_err("Disable the port before modifying\n");
238 return -EACCES;
239 }
240 ret = kstrtoint(page, 0, &port->inline_data_size);
241 if (ret) {
242 pr_err("Invalid value '%s' for inline_data_size\n", page);
243 return -EINVAL;
244 }
245 return count;
246}
247
248CONFIGFS_ATTR(nvmet_, param_inline_data_size);
249
221static ssize_t nvmet_addr_trtype_show(struct config_item *item,
222 char *page)
223{
224 struct nvmet_port *port = to_nvmet_port(item);
225 int i;
226
227 for (i = 0; i < ARRAY_SIZE(nvmet_transport_names); i++) {
228 if (port->disc_addr.trtype != nvmet_transport_names[i].type)

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

277 return sprintf(page, "%s\n", to_nvmet_ns(item)->device_path);
278}
279
280static ssize_t nvmet_ns_device_path_store(struct config_item *item,
281 const char *page, size_t count)
282{
283 struct nvmet_ns *ns = to_nvmet_ns(item);
284 struct nvmet_subsys *subsys = ns->subsys;
250static ssize_t nvmet_addr_trtype_show(struct config_item *item,
251 char *page)
252{
253 struct nvmet_port *port = to_nvmet_port(item);
254 int i;
255
256 for (i = 0; i < ARRAY_SIZE(nvmet_transport_names); i++) {
257 if (port->disc_addr.trtype != nvmet_transport_names[i].type)

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

306 return sprintf(page, "%s\n", to_nvmet_ns(item)->device_path);
307}
308
309static ssize_t nvmet_ns_device_path_store(struct config_item *item,
310 const char *page, size_t count)
311{
312 struct nvmet_ns *ns = to_nvmet_ns(item);
313 struct nvmet_subsys *subsys = ns->subsys;
285 size_t len;
286 int ret;
287
288 mutex_lock(&subsys->lock);
289 ret = -EBUSY;
290 if (ns->enabled)
291 goto out_unlock;
292
314 int ret;
315
316 mutex_lock(&subsys->lock);
317 ret = -EBUSY;
318 if (ns->enabled)
319 goto out_unlock;
320
293 ret = -EINVAL;
294 len = strcspn(page, "\n");
295 if (!len)
296 goto out_unlock;
297
298 kfree(ns->device_path);
321 kfree(ns->device_path);
322
299 ret = -ENOMEM;
323 ret = -ENOMEM;
300 ns->device_path = kstrndup(page, len, GFP_KERNEL);
324 ns->device_path = kstrndup(page, strcspn(page, "\n"), GFP_KERNEL);
301 if (!ns->device_path)
302 goto out_unlock;
303
304 mutex_unlock(&subsys->lock);
305 return count;
306
307out_unlock:
308 mutex_unlock(&subsys->lock);

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

407 else
408 nvmet_ns_disable(ns);
409
410 return ret ? ret : count;
411}
412
413CONFIGFS_ATTR(nvmet_ns_, enable);
414
325 if (!ns->device_path)
326 goto out_unlock;
327
328 mutex_unlock(&subsys->lock);
329 return count;
330
331out_unlock:
332 mutex_unlock(&subsys->lock);

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

431 else
432 nvmet_ns_disable(ns);
433
434 return ret ? ret : count;
435}
436
437CONFIGFS_ATTR(nvmet_ns_, enable);
438
439static ssize_t nvmet_ns_buffered_io_show(struct config_item *item, char *page)
440{
441 return sprintf(page, "%d\n", to_nvmet_ns(item)->buffered_io);
442}
443
444static ssize_t nvmet_ns_buffered_io_store(struct config_item *item,
445 const char *page, size_t count)
446{
447 struct nvmet_ns *ns = to_nvmet_ns(item);
448 bool val;
449
450 if (strtobool(page, &val))
451 return -EINVAL;
452
453 mutex_lock(&ns->subsys->lock);
454 if (ns->enabled) {
455 pr_err("disable ns before setting buffered_io value.\n");
456 mutex_unlock(&ns->subsys->lock);
457 return -EINVAL;
458 }
459
460 ns->buffered_io = val;
461 mutex_unlock(&ns->subsys->lock);
462 return count;
463}
464
465CONFIGFS_ATTR(nvmet_ns_, buffered_io);
466
415static struct configfs_attribute *nvmet_ns_attrs[] = {
416 &nvmet_ns_attr_device_path,
417 &nvmet_ns_attr_device_nguid,
418 &nvmet_ns_attr_device_uuid,
419 &nvmet_ns_attr_enable,
467static struct configfs_attribute *nvmet_ns_attrs[] = {
468 &nvmet_ns_attr_device_path,
469 &nvmet_ns_attr_device_nguid,
470 &nvmet_ns_attr_device_uuid,
471 &nvmet_ns_attr_enable,
472 &nvmet_ns_attr_buffered_io,
420 NULL,
421};
422
423static void nvmet_ns_release(struct config_item *item)
424{
425 struct nvmet_ns *ns = to_nvmet_ns(item);
426
427 nvmet_ns_free(ns);

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

865
866/*
867 * Ports definitions.
868 */
869static void nvmet_port_release(struct config_item *item)
870{
871 struct nvmet_port *port = to_nvmet_port(item);
872
473 NULL,
474};
475
476static void nvmet_ns_release(struct config_item *item)
477{
478 struct nvmet_ns *ns = to_nvmet_ns(item);
479
480 nvmet_ns_free(ns);

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

918
919/*
920 * Ports definitions.
921 */
922static void nvmet_port_release(struct config_item *item)
923{
924 struct nvmet_port *port = to_nvmet_port(item);
925
926 kfree(port->ana_state);
873 kfree(port);
874}
875
876static struct configfs_attribute *nvmet_port_attrs[] = {
877 &nvmet_attr_addr_adrfam,
878 &nvmet_attr_addr_treq,
879 &nvmet_attr_addr_traddr,
880 &nvmet_attr_addr_trsvcid,
881 &nvmet_attr_addr_trtype,
927 kfree(port);
928}
929
930static struct configfs_attribute *nvmet_port_attrs[] = {
931 &nvmet_attr_addr_adrfam,
932 &nvmet_attr_addr_treq,
933 &nvmet_attr_addr_traddr,
934 &nvmet_attr_addr_trsvcid,
935 &nvmet_attr_addr_trtype,
936 &nvmet_attr_param_inline_data_size,
882 NULL,
883};
884
885static struct configfs_item_operations nvmet_port_item_ops = {
886 .release = nvmet_port_release,
887};
888
889static const struct config_item_type nvmet_port_type = {

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

900
901 if (kstrtou16(name, 0, &portid))
902 return ERR_PTR(-EINVAL);
903
904 port = kzalloc(sizeof(*port), GFP_KERNEL);
905 if (!port)
906 return ERR_PTR(-ENOMEM);
907
937 NULL,
938};
939
940static struct configfs_item_operations nvmet_port_item_ops = {
941 .release = nvmet_port_release,
942};
943
944static const struct config_item_type nvmet_port_type = {

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

955
956 if (kstrtou16(name, 0, &portid))
957 return ERR_PTR(-EINVAL);
958
959 port = kzalloc(sizeof(*port), GFP_KERNEL);
960 if (!port)
961 return ERR_PTR(-ENOMEM);
962
963 port->ana_state = kcalloc(NVMET_MAX_ANAGRPS + 1,
964 sizeof(*port->ana_state), GFP_KERNEL);
965 if (!port->ana_state) {
966 kfree(port);
967 return ERR_PTR(-ENOMEM);
968 }
969
970 port->ana_state[NVMET_DEFAULT_ANA_GRPID] = NVME_ANA_OPTIMIZED;
971
908 INIT_LIST_HEAD(&port->entry);
909 INIT_LIST_HEAD(&port->subsystems);
910 INIT_LIST_HEAD(&port->referrals);
972 INIT_LIST_HEAD(&port->entry);
973 INIT_LIST_HEAD(&port->subsystems);
974 INIT_LIST_HEAD(&port->referrals);
975 port->inline_data_size = -1; /* < 0 == let the transport choose */
911
912 port->disc_addr.portid = cpu_to_le16(portid);
913 config_group_init_type_name(&port->group, name, &nvmet_port_type);
914
915 config_group_init_type_name(&port->subsys_group,
916 "subsystems", &nvmet_port_subsys_type);
917 configfs_add_default_group(&port->subsys_group, &port->group);
918

--- 108 unchanged lines hidden ---
976
977 port->disc_addr.portid = cpu_to_le16(portid);
978 config_group_init_type_name(&port->group, name, &nvmet_port_type);
979
980 config_group_init_type_name(&port->subsys_group,
981 "subsystems", &nvmet_port_subsys_type);
982 configfs_add_default_group(&port->subsys_group, &port->group);
983

--- 108 unchanged lines hidden ---