1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/delay.h>
33#include <linux/timer.h>
34#include <linux/string.h>
35#include <generated/utsrelease.h>
36#include <linux/utsname.h>
37#include <linux/proc_fs.h>
38#include <linux/seq_file.h>
39#include <linux/blkdev.h>
40#include <linux/configfs.h>
41#include <scsi/scsi.h>
42#include <scsi/scsi_device.h>
43#include <scsi/scsi_host.h>
44
45#include <target/target_core_base.h>
46#include <target/target_core_backend.h>
47#include <target/target_core_fabric.h>
48#include <target/target_core_configfs.h>
49#include <target/configfs_macros.h>
50
51#include "target_core_internal.h"
52
53#ifndef INITIAL_JIFFIES
54#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
55#endif
56
57#define NONE "None"
58#define ISPRINT(a) ((a >= ' ') && (a <= '~'))
59
60#define SCSI_LU_INDEX 1
61#define LU_COUNT 1
62
63
64
65
66
67CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev, se_dev_stat_grps);
68#define DEV_STAT_SCSI_DEV_ATTR(_name, _mode) \
69static struct target_stat_scsi_dev_attribute \
70 target_stat_scsi_dev_##_name = \
71 __CONFIGFS_EATTR(_name, _mode, \
72 target_stat_scsi_dev_show_attr_##_name, \
73 target_stat_scsi_dev_store_attr_##_name);
74
75#define DEV_STAT_SCSI_DEV_ATTR_RO(_name) \
76static struct target_stat_scsi_dev_attribute \
77 target_stat_scsi_dev_##_name = \
78 __CONFIGFS_EATTR_RO(_name, \
79 target_stat_scsi_dev_show_attr_##_name);
80
81static ssize_t target_stat_scsi_dev_show_attr_inst(
82 struct se_dev_stat_grps *sgrps, char *page)
83{
84 struct se_subsystem_dev *se_subdev = container_of(sgrps,
85 struct se_subsystem_dev, dev_stat_grps);
86 struct se_hba *hba = se_subdev->se_dev_hba;
87 struct se_device *dev = se_subdev->se_dev_ptr;
88
89 if (!dev)
90 return -ENODEV;
91
92 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
93}
94DEV_STAT_SCSI_DEV_ATTR_RO(inst);
95
96static ssize_t target_stat_scsi_dev_show_attr_indx(
97 struct se_dev_stat_grps *sgrps, char *page)
98{
99 struct se_subsystem_dev *se_subdev = container_of(sgrps,
100 struct se_subsystem_dev, dev_stat_grps);
101 struct se_device *dev = se_subdev->se_dev_ptr;
102
103 if (!dev)
104 return -ENODEV;
105
106 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
107}
108DEV_STAT_SCSI_DEV_ATTR_RO(indx);
109
110static ssize_t target_stat_scsi_dev_show_attr_role(
111 struct se_dev_stat_grps *sgrps, char *page)
112{
113 struct se_subsystem_dev *se_subdev = container_of(sgrps,
114 struct se_subsystem_dev, dev_stat_grps);
115 struct se_device *dev = se_subdev->se_dev_ptr;
116
117 if (!dev)
118 return -ENODEV;
119
120 return snprintf(page, PAGE_SIZE, "Target\n");
121}
122DEV_STAT_SCSI_DEV_ATTR_RO(role);
123
124static ssize_t target_stat_scsi_dev_show_attr_ports(
125 struct se_dev_stat_grps *sgrps, char *page)
126{
127 struct se_subsystem_dev *se_subdev = container_of(sgrps,
128 struct se_subsystem_dev, dev_stat_grps);
129 struct se_device *dev = se_subdev->se_dev_ptr;
130
131 if (!dev)
132 return -ENODEV;
133
134 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_port_count);
135}
136DEV_STAT_SCSI_DEV_ATTR_RO(ports);
137
138CONFIGFS_EATTR_OPS(target_stat_scsi_dev, se_dev_stat_grps, scsi_dev_group);
139
140static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
141 &target_stat_scsi_dev_inst.attr,
142 &target_stat_scsi_dev_indx.attr,
143 &target_stat_scsi_dev_role.attr,
144 &target_stat_scsi_dev_ports.attr,
145 NULL,
146};
147
148static struct configfs_item_operations target_stat_scsi_dev_attrib_ops = {
149 .show_attribute = target_stat_scsi_dev_attr_show,
150 .store_attribute = target_stat_scsi_dev_attr_store,
151};
152
153static struct config_item_type target_stat_scsi_dev_cit = {
154 .ct_item_ops = &target_stat_scsi_dev_attrib_ops,
155 .ct_attrs = target_stat_scsi_dev_attrs,
156 .ct_owner = THIS_MODULE,
157};
158
159
160
161
162
163CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev, se_dev_stat_grps);
164#define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode) \
165static struct target_stat_scsi_tgt_dev_attribute \
166 target_stat_scsi_tgt_dev_##_name = \
167 __CONFIGFS_EATTR(_name, _mode, \
168 target_stat_scsi_tgt_dev_show_attr_##_name, \
169 target_stat_scsi_tgt_dev_store_attr_##_name);
170
171#define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name) \
172static struct target_stat_scsi_tgt_dev_attribute \
173 target_stat_scsi_tgt_dev_##_name = \
174 __CONFIGFS_EATTR_RO(_name, \
175 target_stat_scsi_tgt_dev_show_attr_##_name);
176
177static ssize_t target_stat_scsi_tgt_dev_show_attr_inst(
178 struct se_dev_stat_grps *sgrps, char *page)
179{
180 struct se_subsystem_dev *se_subdev = container_of(sgrps,
181 struct se_subsystem_dev, dev_stat_grps);
182 struct se_hba *hba = se_subdev->se_dev_hba;
183 struct se_device *dev = se_subdev->se_dev_ptr;
184
185 if (!dev)
186 return -ENODEV;
187
188 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
189}
190DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst);
191
192static ssize_t target_stat_scsi_tgt_dev_show_attr_indx(
193 struct se_dev_stat_grps *sgrps, char *page)
194{
195 struct se_subsystem_dev *se_subdev = container_of(sgrps,
196 struct se_subsystem_dev, dev_stat_grps);
197 struct se_device *dev = se_subdev->se_dev_ptr;
198
199 if (!dev)
200 return -ENODEV;
201
202 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
203}
204DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx);
205
206static ssize_t target_stat_scsi_tgt_dev_show_attr_num_lus(
207 struct se_dev_stat_grps *sgrps, char *page)
208{
209 struct se_subsystem_dev *se_subdev = container_of(sgrps,
210 struct se_subsystem_dev, dev_stat_grps);
211 struct se_device *dev = se_subdev->se_dev_ptr;
212
213 if (!dev)
214 return -ENODEV;
215
216 return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
217}
218DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus);
219
220static ssize_t target_stat_scsi_tgt_dev_show_attr_status(
221 struct se_dev_stat_grps *sgrps, char *page)
222{
223 struct se_subsystem_dev *se_subdev = container_of(sgrps,
224 struct se_subsystem_dev, dev_stat_grps);
225 struct se_device *dev = se_subdev->se_dev_ptr;
226 char status[16];
227
228 if (!dev)
229 return -ENODEV;
230
231 switch (dev->dev_status) {
232 case TRANSPORT_DEVICE_ACTIVATED:
233 strcpy(status, "activated");
234 break;
235 case TRANSPORT_DEVICE_DEACTIVATED:
236 strcpy(status, "deactivated");
237 break;
238 case TRANSPORT_DEVICE_SHUTDOWN:
239 strcpy(status, "shutdown");
240 break;
241 case TRANSPORT_DEVICE_OFFLINE_ACTIVATED:
242 case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED:
243 strcpy(status, "offline");
244 break;
245 default:
246 sprintf(status, "unknown(%d)", dev->dev_status);
247 break;
248 }
249
250 return snprintf(page, PAGE_SIZE, "%s\n", status);
251}
252DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status);
253
254static ssize_t target_stat_scsi_tgt_dev_show_attr_non_access_lus(
255 struct se_dev_stat_grps *sgrps, char *page)
256{
257 struct se_subsystem_dev *se_subdev = container_of(sgrps,
258 struct se_subsystem_dev, dev_stat_grps);
259 struct se_device *dev = se_subdev->se_dev_ptr;
260 int non_accessible_lus;
261
262 if (!dev)
263 return -ENODEV;
264
265 switch (dev->dev_status) {
266 case TRANSPORT_DEVICE_ACTIVATED:
267 non_accessible_lus = 0;
268 break;
269 case TRANSPORT_DEVICE_DEACTIVATED:
270 case TRANSPORT_DEVICE_SHUTDOWN:
271 case TRANSPORT_DEVICE_OFFLINE_ACTIVATED:
272 case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED:
273 default:
274 non_accessible_lus = 1;
275 break;
276 }
277
278 return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
279}
280DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus);
281
282static ssize_t target_stat_scsi_tgt_dev_show_attr_resets(
283 struct se_dev_stat_grps *sgrps, char *page)
284{
285 struct se_subsystem_dev *se_subdev = container_of(sgrps,
286 struct se_subsystem_dev, dev_stat_grps);
287 struct se_device *dev = se_subdev->se_dev_ptr;
288
289 if (!dev)
290 return -ENODEV;
291
292 return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
293}
294DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets);
295
296
297CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_dev, se_dev_stat_grps, scsi_tgt_dev_group);
298
299static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
300 &target_stat_scsi_tgt_dev_inst.attr,
301 &target_stat_scsi_tgt_dev_indx.attr,
302 &target_stat_scsi_tgt_dev_num_lus.attr,
303 &target_stat_scsi_tgt_dev_status.attr,
304 &target_stat_scsi_tgt_dev_non_access_lus.attr,
305 &target_stat_scsi_tgt_dev_resets.attr,
306 NULL,
307};
308
309static struct configfs_item_operations target_stat_scsi_tgt_dev_attrib_ops = {
310 .show_attribute = target_stat_scsi_tgt_dev_attr_show,
311 .store_attribute = target_stat_scsi_tgt_dev_attr_store,
312};
313
314static struct config_item_type target_stat_scsi_tgt_dev_cit = {
315 .ct_item_ops = &target_stat_scsi_tgt_dev_attrib_ops,
316 .ct_attrs = target_stat_scsi_tgt_dev_attrs,
317 .ct_owner = THIS_MODULE,
318};
319
320
321
322
323
324CONFIGFS_EATTR_STRUCT(target_stat_scsi_lu, se_dev_stat_grps);
325#define DEV_STAT_SCSI_LU_ATTR(_name, _mode) \
326static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
327 __CONFIGFS_EATTR(_name, _mode, \
328 target_stat_scsi_lu_show_attr_##_name, \
329 target_stat_scsi_lu_store_attr_##_name);
330
331#define DEV_STAT_SCSI_LU_ATTR_RO(_name) \
332static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
333 __CONFIGFS_EATTR_RO(_name, \
334 target_stat_scsi_lu_show_attr_##_name);
335
336static ssize_t target_stat_scsi_lu_show_attr_inst(
337 struct se_dev_stat_grps *sgrps, char *page)
338{
339 struct se_subsystem_dev *se_subdev = container_of(sgrps,
340 struct se_subsystem_dev, dev_stat_grps);
341 struct se_hba *hba = se_subdev->se_dev_hba;
342 struct se_device *dev = se_subdev->se_dev_ptr;
343
344 if (!dev)
345 return -ENODEV;
346
347 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
348}
349DEV_STAT_SCSI_LU_ATTR_RO(inst);
350
351static ssize_t target_stat_scsi_lu_show_attr_dev(
352 struct se_dev_stat_grps *sgrps, char *page)
353{
354 struct se_subsystem_dev *se_subdev = container_of(sgrps,
355 struct se_subsystem_dev, dev_stat_grps);
356 struct se_device *dev = se_subdev->se_dev_ptr;
357
358 if (!dev)
359 return -ENODEV;
360
361 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
362}
363DEV_STAT_SCSI_LU_ATTR_RO(dev);
364
365static ssize_t target_stat_scsi_lu_show_attr_indx(
366 struct se_dev_stat_grps *sgrps, char *page)
367{
368 struct se_subsystem_dev *se_subdev = container_of(sgrps,
369 struct se_subsystem_dev, dev_stat_grps);
370 struct se_device *dev = se_subdev->se_dev_ptr;
371
372 if (!dev)
373 return -ENODEV;
374
375 return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
376}
377DEV_STAT_SCSI_LU_ATTR_RO(indx);
378
379static ssize_t target_stat_scsi_lu_show_attr_lun(
380 struct se_dev_stat_grps *sgrps, char *page)
381{
382 struct se_subsystem_dev *se_subdev = container_of(sgrps,
383 struct se_subsystem_dev, dev_stat_grps);
384 struct se_device *dev = se_subdev->se_dev_ptr;
385
386 if (!dev)
387 return -ENODEV;
388
389 return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
390}
391DEV_STAT_SCSI_LU_ATTR_RO(lun);
392
393static ssize_t target_stat_scsi_lu_show_attr_lu_name(
394 struct se_dev_stat_grps *sgrps, char *page)
395{
396 struct se_subsystem_dev *se_subdev = container_of(sgrps,
397 struct se_subsystem_dev, dev_stat_grps);
398 struct se_device *dev = se_subdev->se_dev_ptr;
399
400 if (!dev)
401 return -ENODEV;
402
403 return snprintf(page, PAGE_SIZE, "%s\n",
404 (strlen(dev->se_sub_dev->t10_wwn.unit_serial)) ?
405 dev->se_sub_dev->t10_wwn.unit_serial : "None");
406}
407DEV_STAT_SCSI_LU_ATTR_RO(lu_name);
408
409static ssize_t target_stat_scsi_lu_show_attr_vend(
410 struct se_dev_stat_grps *sgrps, char *page)
411{
412 struct se_subsystem_dev *se_subdev = container_of(sgrps,
413 struct se_subsystem_dev, dev_stat_grps);
414 struct se_device *dev = se_subdev->se_dev_ptr;
415 int i;
416 char str[sizeof(dev->se_sub_dev->t10_wwn.vendor)+1];
417
418 if (!dev)
419 return -ENODEV;
420
421
422 for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.vendor); i++)
423 str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.vendor[i]) ?
424 dev->se_sub_dev->t10_wwn.vendor[i] : ' ';
425 str[i] = '\0';
426 return snprintf(page, PAGE_SIZE, "%s\n", str);
427}
428DEV_STAT_SCSI_LU_ATTR_RO(vend);
429
430static ssize_t target_stat_scsi_lu_show_attr_prod(
431 struct se_dev_stat_grps *sgrps, char *page)
432{
433 struct se_subsystem_dev *se_subdev = container_of(sgrps,
434 struct se_subsystem_dev, dev_stat_grps);
435 struct se_device *dev = se_subdev->se_dev_ptr;
436 int i;
437 char str[sizeof(dev->se_sub_dev->t10_wwn.model)+1];
438
439 if (!dev)
440 return -ENODEV;
441
442
443 for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.vendor); i++)
444 str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.model[i]) ?
445 dev->se_sub_dev->t10_wwn.model[i] : ' ';
446 str[i] = '\0';
447 return snprintf(page, PAGE_SIZE, "%s\n", str);
448}
449DEV_STAT_SCSI_LU_ATTR_RO(prod);
450
451static ssize_t target_stat_scsi_lu_show_attr_rev(
452 struct se_dev_stat_grps *sgrps, char *page)
453{
454 struct se_subsystem_dev *se_subdev = container_of(sgrps,
455 struct se_subsystem_dev, dev_stat_grps);
456 struct se_device *dev = se_subdev->se_dev_ptr;
457 int i;
458 char str[sizeof(dev->se_sub_dev->t10_wwn.revision)+1];
459
460 if (!dev)
461 return -ENODEV;
462
463
464 for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.revision); i++)
465 str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.revision[i]) ?
466 dev->se_sub_dev->t10_wwn.revision[i] : ' ';
467 str[i] = '\0';
468 return snprintf(page, PAGE_SIZE, "%s\n", str);
469}
470DEV_STAT_SCSI_LU_ATTR_RO(rev);
471
472static ssize_t target_stat_scsi_lu_show_attr_dev_type(
473 struct se_dev_stat_grps *sgrps, char *page)
474{
475 struct se_subsystem_dev *se_subdev = container_of(sgrps,
476 struct se_subsystem_dev, dev_stat_grps);
477 struct se_device *dev = se_subdev->se_dev_ptr;
478
479 if (!dev)
480 return -ENODEV;
481
482
483 return snprintf(page, PAGE_SIZE, "%u\n",
484 dev->transport->get_device_type(dev));
485}
486DEV_STAT_SCSI_LU_ATTR_RO(dev_type);
487
488static ssize_t target_stat_scsi_lu_show_attr_status(
489 struct se_dev_stat_grps *sgrps, char *page)
490{
491 struct se_subsystem_dev *se_subdev = container_of(sgrps,
492 struct se_subsystem_dev, dev_stat_grps);
493 struct se_device *dev = se_subdev->se_dev_ptr;
494
495 if (!dev)
496 return -ENODEV;
497
498
499 return snprintf(page, PAGE_SIZE, "%s\n",
500 (dev->dev_status == TRANSPORT_DEVICE_ACTIVATED) ?
501 "available" : "notavailable");
502}
503DEV_STAT_SCSI_LU_ATTR_RO(status);
504
505static ssize_t target_stat_scsi_lu_show_attr_state_bit(
506 struct se_dev_stat_grps *sgrps, char *page)
507{
508 struct se_subsystem_dev *se_subdev = container_of(sgrps,
509 struct se_subsystem_dev, dev_stat_grps);
510 struct se_device *dev = se_subdev->se_dev_ptr;
511
512 if (!dev)
513 return -ENODEV;
514
515
516 return snprintf(page, PAGE_SIZE, "exposed\n");
517}
518DEV_STAT_SCSI_LU_ATTR_RO(state_bit);
519
520static ssize_t target_stat_scsi_lu_show_attr_num_cmds(
521 struct se_dev_stat_grps *sgrps, char *page)
522{
523 struct se_subsystem_dev *se_subdev = container_of(sgrps,
524 struct se_subsystem_dev, dev_stat_grps);
525 struct se_device *dev = se_subdev->se_dev_ptr;
526
527 if (!dev)
528 return -ENODEV;
529
530
531 return snprintf(page, PAGE_SIZE, "%llu\n",
532 (unsigned long long)dev->num_cmds);
533}
534DEV_STAT_SCSI_LU_ATTR_RO(num_cmds);
535
536static ssize_t target_stat_scsi_lu_show_attr_read_mbytes(
537 struct se_dev_stat_grps *sgrps, char *page)
538{
539 struct se_subsystem_dev *se_subdev = container_of(sgrps,
540 struct se_subsystem_dev, dev_stat_grps);
541 struct se_device *dev = se_subdev->se_dev_ptr;
542
543 if (!dev)
544 return -ENODEV;
545
546
547 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->read_bytes >> 20));
548}
549DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes);
550
551static ssize_t target_stat_scsi_lu_show_attr_write_mbytes(
552 struct se_dev_stat_grps *sgrps, char *page)
553{
554 struct se_subsystem_dev *se_subdev = container_of(sgrps,
555 struct se_subsystem_dev, dev_stat_grps);
556 struct se_device *dev = se_subdev->se_dev_ptr;
557
558 if (!dev)
559 return -ENODEV;
560
561
562 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->write_bytes >> 20));
563}
564DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes);
565
566static ssize_t target_stat_scsi_lu_show_attr_resets(
567 struct se_dev_stat_grps *sgrps, char *page)
568{
569 struct se_subsystem_dev *se_subdev = container_of(sgrps,
570 struct se_subsystem_dev, dev_stat_grps);
571 struct se_device *dev = se_subdev->se_dev_ptr;
572
573 if (!dev)
574 return -ENODEV;
575
576
577 return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
578}
579DEV_STAT_SCSI_LU_ATTR_RO(resets);
580
581static ssize_t target_stat_scsi_lu_show_attr_full_stat(
582 struct se_dev_stat_grps *sgrps, char *page)
583{
584 struct se_subsystem_dev *se_subdev = container_of(sgrps,
585 struct se_subsystem_dev, dev_stat_grps);
586 struct se_device *dev = se_subdev->se_dev_ptr;
587
588 if (!dev)
589 return -ENODEV;
590
591
592 return snprintf(page, PAGE_SIZE, "%u\n", 0);
593}
594DEV_STAT_SCSI_LU_ATTR_RO(full_stat);
595
596static ssize_t target_stat_scsi_lu_show_attr_hs_num_cmds(
597 struct se_dev_stat_grps *sgrps, char *page)
598{
599 struct se_subsystem_dev *se_subdev = container_of(sgrps,
600 struct se_subsystem_dev, dev_stat_grps);
601 struct se_device *dev = se_subdev->se_dev_ptr;
602
603 if (!dev)
604 return -ENODEV;
605
606
607 return snprintf(page, PAGE_SIZE, "%u\n", 0);
608}
609DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds);
610
611static ssize_t target_stat_scsi_lu_show_attr_creation_time(
612 struct se_dev_stat_grps *sgrps, char *page)
613{
614 struct se_subsystem_dev *se_subdev = container_of(sgrps,
615 struct se_subsystem_dev, dev_stat_grps);
616 struct se_device *dev = se_subdev->se_dev_ptr;
617
618 if (!dev)
619 return -ENODEV;
620
621
622 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
623 INITIAL_JIFFIES) * 100 / HZ));
624}
625DEV_STAT_SCSI_LU_ATTR_RO(creation_time);
626
627CONFIGFS_EATTR_OPS(target_stat_scsi_lu, se_dev_stat_grps, scsi_lu_group);
628
629static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
630 &target_stat_scsi_lu_inst.attr,
631 &target_stat_scsi_lu_dev.attr,
632 &target_stat_scsi_lu_indx.attr,
633 &target_stat_scsi_lu_lun.attr,
634 &target_stat_scsi_lu_lu_name.attr,
635 &target_stat_scsi_lu_vend.attr,
636 &target_stat_scsi_lu_prod.attr,
637 &target_stat_scsi_lu_rev.attr,
638 &target_stat_scsi_lu_dev_type.attr,
639 &target_stat_scsi_lu_status.attr,
640 &target_stat_scsi_lu_state_bit.attr,
641 &target_stat_scsi_lu_num_cmds.attr,
642 &target_stat_scsi_lu_read_mbytes.attr,
643 &target_stat_scsi_lu_write_mbytes.attr,
644 &target_stat_scsi_lu_resets.attr,
645 &target_stat_scsi_lu_full_stat.attr,
646 &target_stat_scsi_lu_hs_num_cmds.attr,
647 &target_stat_scsi_lu_creation_time.attr,
648 NULL,
649};
650
651static struct configfs_item_operations target_stat_scsi_lu_attrib_ops = {
652 .show_attribute = target_stat_scsi_lu_attr_show,
653 .store_attribute = target_stat_scsi_lu_attr_store,
654};
655
656static struct config_item_type target_stat_scsi_lu_cit = {
657 .ct_item_ops = &target_stat_scsi_lu_attrib_ops,
658 .ct_attrs = target_stat_scsi_lu_attrs,
659 .ct_owner = THIS_MODULE,
660};
661
662
663
664
665
666void target_stat_setup_dev_default_groups(struct se_subsystem_dev *se_subdev)
667{
668 struct config_group *dev_stat_grp = &se_subdev->dev_stat_grps.stat_group;
669
670 config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_dev_group,
671 "scsi_dev", &target_stat_scsi_dev_cit);
672 config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_tgt_dev_group,
673 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
674 config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_lu_group,
675 "scsi_lu", &target_stat_scsi_lu_cit);
676
677 dev_stat_grp->default_groups[0] = &se_subdev->dev_stat_grps.scsi_dev_group;
678 dev_stat_grp->default_groups[1] = &se_subdev->dev_stat_grps.scsi_tgt_dev_group;
679 dev_stat_grp->default_groups[2] = &se_subdev->dev_stat_grps.scsi_lu_group;
680 dev_stat_grp->default_groups[3] = NULL;
681}
682
683
684
685
686
687CONFIGFS_EATTR_STRUCT(target_stat_scsi_port, se_port_stat_grps);
688#define DEV_STAT_SCSI_PORT_ATTR(_name, _mode) \
689static struct target_stat_scsi_port_attribute \
690 target_stat_scsi_port_##_name = \
691 __CONFIGFS_EATTR(_name, _mode, \
692 target_stat_scsi_port_show_attr_##_name, \
693 target_stat_scsi_port_store_attr_##_name);
694
695#define DEV_STAT_SCSI_PORT_ATTR_RO(_name) \
696static struct target_stat_scsi_port_attribute \
697 target_stat_scsi_port_##_name = \
698 __CONFIGFS_EATTR_RO(_name, \
699 target_stat_scsi_port_show_attr_##_name);
700
701static ssize_t target_stat_scsi_port_show_attr_inst(
702 struct se_port_stat_grps *pgrps, char *page)
703{
704 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
705 struct se_port *sep;
706 struct se_device *dev = lun->lun_se_dev;
707 struct se_hba *hba;
708 ssize_t ret;
709
710 spin_lock(&lun->lun_sep_lock);
711 sep = lun->lun_sep;
712 if (!sep) {
713 spin_unlock(&lun->lun_sep_lock);
714 return -ENODEV;
715 }
716 hba = dev->se_hba;
717 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
718 spin_unlock(&lun->lun_sep_lock);
719 return ret;
720}
721DEV_STAT_SCSI_PORT_ATTR_RO(inst);
722
723static ssize_t target_stat_scsi_port_show_attr_dev(
724 struct se_port_stat_grps *pgrps, char *page)
725{
726 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
727 struct se_port *sep;
728 struct se_device *dev = lun->lun_se_dev;
729 ssize_t ret;
730
731 spin_lock(&lun->lun_sep_lock);
732 sep = lun->lun_sep;
733 if (!sep) {
734 spin_unlock(&lun->lun_sep_lock);
735 return -ENODEV;
736 }
737 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
738 spin_unlock(&lun->lun_sep_lock);
739 return ret;
740}
741DEV_STAT_SCSI_PORT_ATTR_RO(dev);
742
743static ssize_t target_stat_scsi_port_show_attr_indx(
744 struct se_port_stat_grps *pgrps, char *page)
745{
746 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
747 struct se_port *sep;
748 ssize_t ret;
749
750 spin_lock(&lun->lun_sep_lock);
751 sep = lun->lun_sep;
752 if (!sep) {
753 spin_unlock(&lun->lun_sep_lock);
754 return -ENODEV;
755 }
756 ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
757 spin_unlock(&lun->lun_sep_lock);
758 return ret;
759}
760DEV_STAT_SCSI_PORT_ATTR_RO(indx);
761
762static ssize_t target_stat_scsi_port_show_attr_role(
763 struct se_port_stat_grps *pgrps, char *page)
764{
765 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
766 struct se_device *dev = lun->lun_se_dev;
767 struct se_port *sep;
768 ssize_t ret;
769
770 if (!dev)
771 return -ENODEV;
772
773 spin_lock(&lun->lun_sep_lock);
774 sep = lun->lun_sep;
775 if (!sep) {
776 spin_unlock(&lun->lun_sep_lock);
777 return -ENODEV;
778 }
779 ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
780 spin_unlock(&lun->lun_sep_lock);
781 return ret;
782}
783DEV_STAT_SCSI_PORT_ATTR_RO(role);
784
785static ssize_t target_stat_scsi_port_show_attr_busy_count(
786 struct se_port_stat_grps *pgrps, char *page)
787{
788 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
789 struct se_port *sep;
790 ssize_t ret;
791
792 spin_lock(&lun->lun_sep_lock);
793 sep = lun->lun_sep;
794 if (!sep) {
795 spin_unlock(&lun->lun_sep_lock);
796 return -ENODEV;
797 }
798
799 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
800 spin_unlock(&lun->lun_sep_lock);
801 return ret;
802}
803DEV_STAT_SCSI_PORT_ATTR_RO(busy_count);
804
805CONFIGFS_EATTR_OPS(target_stat_scsi_port, se_port_stat_grps, scsi_port_group);
806
807static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
808 &target_stat_scsi_port_inst.attr,
809 &target_stat_scsi_port_dev.attr,
810 &target_stat_scsi_port_indx.attr,
811 &target_stat_scsi_port_role.attr,
812 &target_stat_scsi_port_busy_count.attr,
813 NULL,
814};
815
816static struct configfs_item_operations target_stat_scsi_port_attrib_ops = {
817 .show_attribute = target_stat_scsi_port_attr_show,
818 .store_attribute = target_stat_scsi_port_attr_store,
819};
820
821static struct config_item_type target_stat_scsi_port_cit = {
822 .ct_item_ops = &target_stat_scsi_port_attrib_ops,
823 .ct_attrs = target_stat_scsi_port_attrs,
824 .ct_owner = THIS_MODULE,
825};
826
827
828
829
830CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port, se_port_stat_grps);
831#define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode) \
832static struct target_stat_scsi_tgt_port_attribute \
833 target_stat_scsi_tgt_port_##_name = \
834 __CONFIGFS_EATTR(_name, _mode, \
835 target_stat_scsi_tgt_port_show_attr_##_name, \
836 target_stat_scsi_tgt_port_store_attr_##_name);
837
838#define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name) \
839static struct target_stat_scsi_tgt_port_attribute \
840 target_stat_scsi_tgt_port_##_name = \
841 __CONFIGFS_EATTR_RO(_name, \
842 target_stat_scsi_tgt_port_show_attr_##_name);
843
844static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
845 struct se_port_stat_grps *pgrps, char *page)
846{
847 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
848 struct se_device *dev = lun->lun_se_dev;
849 struct se_port *sep;
850 struct se_hba *hba;
851 ssize_t ret;
852
853 spin_lock(&lun->lun_sep_lock);
854 sep = lun->lun_sep;
855 if (!sep) {
856 spin_unlock(&lun->lun_sep_lock);
857 return -ENODEV;
858 }
859 hba = dev->se_hba;
860 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
861 spin_unlock(&lun->lun_sep_lock);
862 return ret;
863}
864DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst);
865
866static ssize_t target_stat_scsi_tgt_port_show_attr_dev(
867 struct se_port_stat_grps *pgrps, char *page)
868{
869 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
870 struct se_device *dev = lun->lun_se_dev;
871 struct se_port *sep;
872 ssize_t ret;
873
874 spin_lock(&lun->lun_sep_lock);
875 sep = lun->lun_sep;
876 if (!sep) {
877 spin_unlock(&lun->lun_sep_lock);
878 return -ENODEV;
879 }
880 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
881 spin_unlock(&lun->lun_sep_lock);
882 return ret;
883}
884DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev);
885
886static ssize_t target_stat_scsi_tgt_port_show_attr_indx(
887 struct se_port_stat_grps *pgrps, char *page)
888{
889 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
890 struct se_port *sep;
891 ssize_t ret;
892
893 spin_lock(&lun->lun_sep_lock);
894 sep = lun->lun_sep;
895 if (!sep) {
896 spin_unlock(&lun->lun_sep_lock);
897 return -ENODEV;
898 }
899 ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
900 spin_unlock(&lun->lun_sep_lock);
901 return ret;
902}
903DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx);
904
905static ssize_t target_stat_scsi_tgt_port_show_attr_name(
906 struct se_port_stat_grps *pgrps, char *page)
907{
908 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
909 struct se_port *sep;
910 struct se_portal_group *tpg;
911 ssize_t ret;
912
913 spin_lock(&lun->lun_sep_lock);
914 sep = lun->lun_sep;
915 if (!sep) {
916 spin_unlock(&lun->lun_sep_lock);
917 return -ENODEV;
918 }
919 tpg = sep->sep_tpg;
920
921 ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
922 tpg->se_tpg_tfo->get_fabric_name(), sep->sep_index);
923 spin_unlock(&lun->lun_sep_lock);
924 return ret;
925}
926DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name);
927
928static ssize_t target_stat_scsi_tgt_port_show_attr_port_index(
929 struct se_port_stat_grps *pgrps, char *page)
930{
931 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
932 struct se_port *sep;
933 struct se_portal_group *tpg;
934 ssize_t ret;
935
936 spin_lock(&lun->lun_sep_lock);
937 sep = lun->lun_sep;
938 if (!sep) {
939 spin_unlock(&lun->lun_sep_lock);
940 return -ENODEV;
941 }
942 tpg = sep->sep_tpg;
943
944 ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
945 tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
946 tpg->se_tpg_tfo->tpg_get_tag(tpg));
947 spin_unlock(&lun->lun_sep_lock);
948 return ret;
949}
950DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index);
951
952static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds(
953 struct se_port_stat_grps *pgrps, char *page)
954{
955 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
956 struct se_port *sep;
957 ssize_t ret;
958
959 spin_lock(&lun->lun_sep_lock);
960 sep = lun->lun_sep;
961 if (!sep) {
962 spin_unlock(&lun->lun_sep_lock);
963 return -ENODEV;
964 }
965
966 ret = snprintf(page, PAGE_SIZE, "%llu\n", sep->sep_stats.cmd_pdus);
967 spin_unlock(&lun->lun_sep_lock);
968 return ret;
969}
970DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds);
971
972static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes(
973 struct se_port_stat_grps *pgrps, char *page)
974{
975 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
976 struct se_port *sep;
977 ssize_t ret;
978
979 spin_lock(&lun->lun_sep_lock);
980 sep = lun->lun_sep;
981 if (!sep) {
982 spin_unlock(&lun->lun_sep_lock);
983 return -ENODEV;
984 }
985
986 ret = snprintf(page, PAGE_SIZE, "%u\n",
987 (u32)(sep->sep_stats.rx_data_octets >> 20));
988 spin_unlock(&lun->lun_sep_lock);
989 return ret;
990}
991DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes);
992
993static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes(
994 struct se_port_stat_grps *pgrps, char *page)
995{
996 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
997 struct se_port *sep;
998 ssize_t ret;
999
1000 spin_lock(&lun->lun_sep_lock);
1001 sep = lun->lun_sep;
1002 if (!sep) {
1003 spin_unlock(&lun->lun_sep_lock);
1004 return -ENODEV;
1005 }
1006
1007 ret = snprintf(page, PAGE_SIZE, "%u\n",
1008 (u32)(sep->sep_stats.tx_data_octets >> 20));
1009 spin_unlock(&lun->lun_sep_lock);
1010 return ret;
1011}
1012DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes);
1013
1014static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
1015 struct se_port_stat_grps *pgrps, char *page)
1016{
1017 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1018 struct se_port *sep;
1019 ssize_t ret;
1020
1021 spin_lock(&lun->lun_sep_lock);
1022 sep = lun->lun_sep;
1023 if (!sep) {
1024 spin_unlock(&lun->lun_sep_lock);
1025 return -ENODEV;
1026 }
1027
1028
1029 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1030 spin_unlock(&lun->lun_sep_lock);
1031 return ret;
1032}
1033DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds);
1034
1035CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port, se_port_stat_grps,
1036 scsi_tgt_port_group);
1037
1038static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
1039 &target_stat_scsi_tgt_port_inst.attr,
1040 &target_stat_scsi_tgt_port_dev.attr,
1041 &target_stat_scsi_tgt_port_indx.attr,
1042 &target_stat_scsi_tgt_port_name.attr,
1043 &target_stat_scsi_tgt_port_port_index.attr,
1044 &target_stat_scsi_tgt_port_in_cmds.attr,
1045 &target_stat_scsi_tgt_port_write_mbytes.attr,
1046 &target_stat_scsi_tgt_port_read_mbytes.attr,
1047 &target_stat_scsi_tgt_port_hs_in_cmds.attr,
1048 NULL,
1049};
1050
1051static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops = {
1052 .show_attribute = target_stat_scsi_tgt_port_attr_show,
1053 .store_attribute = target_stat_scsi_tgt_port_attr_store,
1054};
1055
1056static struct config_item_type target_stat_scsi_tgt_port_cit = {
1057 .ct_item_ops = &target_stat_scsi_tgt_port_attrib_ops,
1058 .ct_attrs = target_stat_scsi_tgt_port_attrs,
1059 .ct_owner = THIS_MODULE,
1060};
1061
1062
1063
1064
1065
1066CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport, se_port_stat_grps);
1067#define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \
1068static struct target_stat_scsi_transport_attribute \
1069 target_stat_scsi_transport_##_name = \
1070 __CONFIGFS_EATTR(_name, _mode, \
1071 target_stat_scsi_transport_show_attr_##_name, \
1072 target_stat_scsi_transport_store_attr_##_name);
1073
1074#define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \
1075static struct target_stat_scsi_transport_attribute \
1076 target_stat_scsi_transport_##_name = \
1077 __CONFIGFS_EATTR_RO(_name, \
1078 target_stat_scsi_transport_show_attr_##_name);
1079
1080static ssize_t target_stat_scsi_transport_show_attr_inst(
1081 struct se_port_stat_grps *pgrps, char *page)
1082{
1083 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1084 struct se_device *dev = lun->lun_se_dev;
1085 struct se_port *sep;
1086 struct se_hba *hba;
1087 ssize_t ret;
1088
1089 spin_lock(&lun->lun_sep_lock);
1090 sep = lun->lun_sep;
1091 if (!sep) {
1092 spin_unlock(&lun->lun_sep_lock);
1093 return -ENODEV;
1094 }
1095
1096 hba = dev->se_hba;
1097 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
1098 spin_unlock(&lun->lun_sep_lock);
1099 return ret;
1100}
1101DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst);
1102
1103static ssize_t target_stat_scsi_transport_show_attr_device(
1104 struct se_port_stat_grps *pgrps, char *page)
1105{
1106 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1107 struct se_port *sep;
1108 struct se_portal_group *tpg;
1109 ssize_t ret;
1110
1111 spin_lock(&lun->lun_sep_lock);
1112 sep = lun->lun_sep;
1113 if (!sep) {
1114 spin_unlock(&lun->lun_sep_lock);
1115 return -ENODEV;
1116 }
1117 tpg = sep->sep_tpg;
1118
1119 ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
1120 tpg->se_tpg_tfo->get_fabric_name());
1121 spin_unlock(&lun->lun_sep_lock);
1122 return ret;
1123}
1124DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device);
1125
1126static ssize_t target_stat_scsi_transport_show_attr_indx(
1127 struct se_port_stat_grps *pgrps, char *page)
1128{
1129 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1130 struct se_port *sep;
1131 struct se_portal_group *tpg;
1132 ssize_t ret;
1133
1134 spin_lock(&lun->lun_sep_lock);
1135 sep = lun->lun_sep;
1136 if (!sep) {
1137 spin_unlock(&lun->lun_sep_lock);
1138 return -ENODEV;
1139 }
1140 tpg = sep->sep_tpg;
1141 ret = snprintf(page, PAGE_SIZE, "%u\n",
1142 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1143 spin_unlock(&lun->lun_sep_lock);
1144 return ret;
1145}
1146DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx);
1147
1148static ssize_t target_stat_scsi_transport_show_attr_dev_name(
1149 struct se_port_stat_grps *pgrps, char *page)
1150{
1151 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1152 struct se_device *dev = lun->lun_se_dev;
1153 struct se_port *sep;
1154 struct se_portal_group *tpg;
1155 struct t10_wwn *wwn;
1156 ssize_t ret;
1157
1158 spin_lock(&lun->lun_sep_lock);
1159 sep = lun->lun_sep;
1160 if (!sep) {
1161 spin_unlock(&lun->lun_sep_lock);
1162 return -ENODEV;
1163 }
1164 tpg = sep->sep_tpg;
1165 wwn = &dev->se_sub_dev->t10_wwn;
1166
1167 ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
1168 tpg->se_tpg_tfo->tpg_get_wwn(tpg),
1169 (strlen(wwn->unit_serial)) ? wwn->unit_serial :
1170 wwn->vendor);
1171 spin_unlock(&lun->lun_sep_lock);
1172 return ret;
1173}
1174DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name);
1175
1176CONFIGFS_EATTR_OPS(target_stat_scsi_transport, se_port_stat_grps,
1177 scsi_transport_group);
1178
1179static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
1180 &target_stat_scsi_transport_inst.attr,
1181 &target_stat_scsi_transport_device.attr,
1182 &target_stat_scsi_transport_indx.attr,
1183 &target_stat_scsi_transport_dev_name.attr,
1184 NULL,
1185};
1186
1187static struct configfs_item_operations target_stat_scsi_transport_attrib_ops = {
1188 .show_attribute = target_stat_scsi_transport_attr_show,
1189 .store_attribute = target_stat_scsi_transport_attr_store,
1190};
1191
1192static struct config_item_type target_stat_scsi_transport_cit = {
1193 .ct_item_ops = &target_stat_scsi_transport_attrib_ops,
1194 .ct_attrs = target_stat_scsi_transport_attrs,
1195 .ct_owner = THIS_MODULE,
1196};
1197
1198
1199
1200
1201
1202void target_stat_setup_port_default_groups(struct se_lun *lun)
1203{
1204 struct config_group *port_stat_grp = &lun->port_stat_grps.stat_group;
1205
1206 config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
1207 "scsi_port", &target_stat_scsi_port_cit);
1208 config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
1209 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
1210 config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
1211 "scsi_transport", &target_stat_scsi_transport_cit);
1212
1213 port_stat_grp->default_groups[0] = &lun->port_stat_grps.scsi_port_group;
1214 port_stat_grp->default_groups[1] = &lun->port_stat_grps.scsi_tgt_port_group;
1215 port_stat_grp->default_groups[2] = &lun->port_stat_grps.scsi_transport_group;
1216 port_stat_grp->default_groups[3] = NULL;
1217}
1218
1219
1220
1221
1222
1223CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr, se_ml_stat_grps);
1224#define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \
1225static struct target_stat_scsi_auth_intr_attribute \
1226 target_stat_scsi_auth_intr_##_name = \
1227 __CONFIGFS_EATTR(_name, _mode, \
1228 target_stat_scsi_auth_intr_show_attr_##_name, \
1229 target_stat_scsi_auth_intr_store_attr_##_name);
1230
1231#define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \
1232static struct target_stat_scsi_auth_intr_attribute \
1233 target_stat_scsi_auth_intr_##_name = \
1234 __CONFIGFS_EATTR_RO(_name, \
1235 target_stat_scsi_auth_intr_show_attr_##_name);
1236
1237static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
1238 struct se_ml_stat_grps *lgrps, char *page)
1239{
1240 struct se_lun_acl *lacl = container_of(lgrps,
1241 struct se_lun_acl, ml_stat_grps);
1242 struct se_node_acl *nacl = lacl->se_lun_nacl;
1243 struct se_dev_entry *deve;
1244 struct se_portal_group *tpg;
1245 ssize_t ret;
1246
1247 spin_lock_irq(&nacl->device_list_lock);
1248 deve = nacl->device_list[lacl->mapped_lun];
1249 if (!deve->se_lun || !deve->se_lun_acl) {
1250 spin_unlock_irq(&nacl->device_list_lock);
1251 return -ENODEV;
1252 }
1253 tpg = nacl->se_tpg;
1254
1255 ret = snprintf(page, PAGE_SIZE, "%u\n",
1256 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1257 spin_unlock_irq(&nacl->device_list_lock);
1258 return ret;
1259}
1260DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst);
1261
1262static ssize_t target_stat_scsi_auth_intr_show_attr_dev(
1263 struct se_ml_stat_grps *lgrps, char *page)
1264{
1265 struct se_lun_acl *lacl = container_of(lgrps,
1266 struct se_lun_acl, ml_stat_grps);
1267 struct se_node_acl *nacl = lacl->se_lun_nacl;
1268 struct se_dev_entry *deve;
1269 struct se_lun *lun;
1270 ssize_t ret;
1271
1272 spin_lock_irq(&nacl->device_list_lock);
1273 deve = nacl->device_list[lacl->mapped_lun];
1274 if (!deve->se_lun || !deve->se_lun_acl) {
1275 spin_unlock_irq(&nacl->device_list_lock);
1276 return -ENODEV;
1277 }
1278 lun = deve->se_lun;
1279
1280 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1281 spin_unlock_irq(&nacl->device_list_lock);
1282 return ret;
1283}
1284DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev);
1285
1286static ssize_t target_stat_scsi_auth_intr_show_attr_port(
1287 struct se_ml_stat_grps *lgrps, char *page)
1288{
1289 struct se_lun_acl *lacl = container_of(lgrps,
1290 struct se_lun_acl, ml_stat_grps);
1291 struct se_node_acl *nacl = lacl->se_lun_nacl;
1292 struct se_dev_entry *deve;
1293 struct se_portal_group *tpg;
1294 ssize_t ret;
1295
1296 spin_lock_irq(&nacl->device_list_lock);
1297 deve = nacl->device_list[lacl->mapped_lun];
1298 if (!deve->se_lun || !deve->se_lun_acl) {
1299 spin_unlock_irq(&nacl->device_list_lock);
1300 return -ENODEV;
1301 }
1302 tpg = nacl->se_tpg;
1303
1304 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1305 spin_unlock_irq(&nacl->device_list_lock);
1306 return ret;
1307}
1308DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port);
1309
1310static ssize_t target_stat_scsi_auth_intr_show_attr_indx(
1311 struct se_ml_stat_grps *lgrps, char *page)
1312{
1313 struct se_lun_acl *lacl = container_of(lgrps,
1314 struct se_lun_acl, ml_stat_grps);
1315 struct se_node_acl *nacl = lacl->se_lun_nacl;
1316 struct se_dev_entry *deve;
1317 ssize_t ret;
1318
1319 spin_lock_irq(&nacl->device_list_lock);
1320 deve = nacl->device_list[lacl->mapped_lun];
1321 if (!deve->se_lun || !deve->se_lun_acl) {
1322 spin_unlock_irq(&nacl->device_list_lock);
1323 return -ENODEV;
1324 }
1325
1326 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1327 spin_unlock_irq(&nacl->device_list_lock);
1328 return ret;
1329}
1330DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx);
1331
1332static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port(
1333 struct se_ml_stat_grps *lgrps, char *page)
1334{
1335 struct se_lun_acl *lacl = container_of(lgrps,
1336 struct se_lun_acl, ml_stat_grps);
1337 struct se_node_acl *nacl = lacl->se_lun_nacl;
1338 struct se_dev_entry *deve;
1339 ssize_t ret;
1340
1341 spin_lock_irq(&nacl->device_list_lock);
1342 deve = nacl->device_list[lacl->mapped_lun];
1343 if (!deve->se_lun || !deve->se_lun_acl) {
1344 spin_unlock_irq(&nacl->device_list_lock);
1345 return -ENODEV;
1346 }
1347
1348 ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
1349 spin_unlock_irq(&nacl->device_list_lock);
1350 return ret;
1351}
1352DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port);
1353
1354static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name(
1355 struct se_ml_stat_grps *lgrps, char *page)
1356{
1357 struct se_lun_acl *lacl = container_of(lgrps,
1358 struct se_lun_acl, ml_stat_grps);
1359 struct se_node_acl *nacl = lacl->se_lun_nacl;
1360 struct se_dev_entry *deve;
1361 ssize_t ret;
1362
1363 spin_lock_irq(&nacl->device_list_lock);
1364 deve = nacl->device_list[lacl->mapped_lun];
1365 if (!deve->se_lun || !deve->se_lun_acl) {
1366 spin_unlock_irq(&nacl->device_list_lock);
1367 return -ENODEV;
1368 }
1369
1370 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
1371 spin_unlock_irq(&nacl->device_list_lock);
1372 return ret;
1373}
1374DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name);
1375
1376static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx(
1377 struct se_ml_stat_grps *lgrps, char *page)
1378{
1379 struct se_lun_acl *lacl = container_of(lgrps,
1380 struct se_lun_acl, ml_stat_grps);
1381 struct se_node_acl *nacl = lacl->se_lun_nacl;
1382 struct se_dev_entry *deve;
1383 ssize_t ret;
1384
1385 spin_lock_irq(&nacl->device_list_lock);
1386 deve = nacl->device_list[lacl->mapped_lun];
1387 if (!deve->se_lun || !deve->se_lun_acl) {
1388 spin_unlock_irq(&nacl->device_list_lock);
1389 return -ENODEV;
1390 }
1391
1392 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1393 spin_unlock_irq(&nacl->device_list_lock);
1394 return ret;
1395}
1396DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx);
1397
1398static ssize_t target_stat_scsi_auth_intr_show_attr_att_count(
1399 struct se_ml_stat_grps *lgrps, char *page)
1400{
1401 struct se_lun_acl *lacl = container_of(lgrps,
1402 struct se_lun_acl, ml_stat_grps);
1403 struct se_node_acl *nacl = lacl->se_lun_nacl;
1404 struct se_dev_entry *deve;
1405 ssize_t ret;
1406
1407 spin_lock_irq(&nacl->device_list_lock);
1408 deve = nacl->device_list[lacl->mapped_lun];
1409 if (!deve->se_lun || !deve->se_lun_acl) {
1410 spin_unlock_irq(&nacl->device_list_lock);
1411 return -ENODEV;
1412 }
1413
1414 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1415 spin_unlock_irq(&nacl->device_list_lock);
1416 return ret;
1417}
1418DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count);
1419
1420static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds(
1421 struct se_ml_stat_grps *lgrps, char *page)
1422{
1423 struct se_lun_acl *lacl = container_of(lgrps,
1424 struct se_lun_acl, ml_stat_grps);
1425 struct se_node_acl *nacl = lacl->se_lun_nacl;
1426 struct se_dev_entry *deve;
1427 ssize_t ret;
1428
1429 spin_lock_irq(&nacl->device_list_lock);
1430 deve = nacl->device_list[lacl->mapped_lun];
1431 if (!deve->se_lun || !deve->se_lun_acl) {
1432 spin_unlock_irq(&nacl->device_list_lock);
1433 return -ENODEV;
1434 }
1435
1436 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->total_cmds);
1437 spin_unlock_irq(&nacl->device_list_lock);
1438 return ret;
1439}
1440DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds);
1441
1442static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes(
1443 struct se_ml_stat_grps *lgrps, char *page)
1444{
1445 struct se_lun_acl *lacl = container_of(lgrps,
1446 struct se_lun_acl, ml_stat_grps);
1447 struct se_node_acl *nacl = lacl->se_lun_nacl;
1448 struct se_dev_entry *deve;
1449 ssize_t ret;
1450
1451 spin_lock_irq(&nacl->device_list_lock);
1452 deve = nacl->device_list[lacl->mapped_lun];
1453 if (!deve->se_lun || !deve->se_lun_acl) {
1454 spin_unlock_irq(&nacl->device_list_lock);
1455 return -ENODEV;
1456 }
1457
1458 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->read_bytes >> 20));
1459 spin_unlock_irq(&nacl->device_list_lock);
1460 return ret;
1461}
1462DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes);
1463
1464static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes(
1465 struct se_ml_stat_grps *lgrps, char *page)
1466{
1467 struct se_lun_acl *lacl = container_of(lgrps,
1468 struct se_lun_acl, ml_stat_grps);
1469 struct se_node_acl *nacl = lacl->se_lun_nacl;
1470 struct se_dev_entry *deve;
1471 ssize_t ret;
1472
1473 spin_lock_irq(&nacl->device_list_lock);
1474 deve = nacl->device_list[lacl->mapped_lun];
1475 if (!deve->se_lun || !deve->se_lun_acl) {
1476 spin_unlock_irq(&nacl->device_list_lock);
1477 return -ENODEV;
1478 }
1479
1480 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->write_bytes >> 20));
1481 spin_unlock_irq(&nacl->device_list_lock);
1482 return ret;
1483}
1484DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes);
1485
1486static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1487 struct se_ml_stat_grps *lgrps, char *page)
1488{
1489 struct se_lun_acl *lacl = container_of(lgrps,
1490 struct se_lun_acl, ml_stat_grps);
1491 struct se_node_acl *nacl = lacl->se_lun_nacl;
1492 struct se_dev_entry *deve;
1493 ssize_t ret;
1494
1495 spin_lock_irq(&nacl->device_list_lock);
1496 deve = nacl->device_list[lacl->mapped_lun];
1497 if (!deve->se_lun || !deve->se_lun_acl) {
1498 spin_unlock_irq(&nacl->device_list_lock);
1499 return -ENODEV;
1500 }
1501
1502 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1503 spin_unlock_irq(&nacl->device_list_lock);
1504 return ret;
1505}
1506DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds);
1507
1508static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time(
1509 struct se_ml_stat_grps *lgrps, char *page)
1510{
1511 struct se_lun_acl *lacl = container_of(lgrps,
1512 struct se_lun_acl, ml_stat_grps);
1513 struct se_node_acl *nacl = lacl->se_lun_nacl;
1514 struct se_dev_entry *deve;
1515 ssize_t ret;
1516
1517 spin_lock_irq(&nacl->device_list_lock);
1518 deve = nacl->device_list[lacl->mapped_lun];
1519 if (!deve->se_lun || !deve->se_lun_acl) {
1520 spin_unlock_irq(&nacl->device_list_lock);
1521 return -ENODEV;
1522 }
1523
1524 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1525 INITIAL_JIFFIES) * 100 / HZ));
1526 spin_unlock_irq(&nacl->device_list_lock);
1527 return ret;
1528}
1529DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time);
1530
1531static ssize_t target_stat_scsi_auth_intr_show_attr_row_status(
1532 struct se_ml_stat_grps *lgrps, char *page)
1533{
1534 struct se_lun_acl *lacl = container_of(lgrps,
1535 struct se_lun_acl, ml_stat_grps);
1536 struct se_node_acl *nacl = lacl->se_lun_nacl;
1537 struct se_dev_entry *deve;
1538 ssize_t ret;
1539
1540 spin_lock_irq(&nacl->device_list_lock);
1541 deve = nacl->device_list[lacl->mapped_lun];
1542 if (!deve->se_lun || !deve->se_lun_acl) {
1543 spin_unlock_irq(&nacl->device_list_lock);
1544 return -ENODEV;
1545 }
1546
1547 ret = snprintf(page, PAGE_SIZE, "Ready\n");
1548 spin_unlock_irq(&nacl->device_list_lock);
1549 return ret;
1550}
1551DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status);
1552
1553CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr, se_ml_stat_grps,
1554 scsi_auth_intr_group);
1555
1556static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1557 &target_stat_scsi_auth_intr_inst.attr,
1558 &target_stat_scsi_auth_intr_dev.attr,
1559 &target_stat_scsi_auth_intr_port.attr,
1560 &target_stat_scsi_auth_intr_indx.attr,
1561 &target_stat_scsi_auth_intr_dev_or_port.attr,
1562 &target_stat_scsi_auth_intr_intr_name.attr,
1563 &target_stat_scsi_auth_intr_map_indx.attr,
1564 &target_stat_scsi_auth_intr_att_count.attr,
1565 &target_stat_scsi_auth_intr_num_cmds.attr,
1566 &target_stat_scsi_auth_intr_read_mbytes.attr,
1567 &target_stat_scsi_auth_intr_write_mbytes.attr,
1568 &target_stat_scsi_auth_intr_hs_num_cmds.attr,
1569 &target_stat_scsi_auth_intr_creation_time.attr,
1570 &target_stat_scsi_auth_intr_row_status.attr,
1571 NULL,
1572};
1573
1574static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops = {
1575 .show_attribute = target_stat_scsi_auth_intr_attr_show,
1576 .store_attribute = target_stat_scsi_auth_intr_attr_store,
1577};
1578
1579static struct config_item_type target_stat_scsi_auth_intr_cit = {
1580 .ct_item_ops = &target_stat_scsi_auth_intr_attrib_ops,
1581 .ct_attrs = target_stat_scsi_auth_intr_attrs,
1582 .ct_owner = THIS_MODULE,
1583};
1584
1585
1586
1587
1588
1589CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port, se_ml_stat_grps);
1590#define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \
1591static struct target_stat_scsi_att_intr_port_attribute \
1592 target_stat_scsi_att_intr_port_##_name = \
1593 __CONFIGFS_EATTR(_name, _mode, \
1594 target_stat_scsi_att_intr_port_show_attr_##_name, \
1595 target_stat_scsi_att_intr_port_store_attr_##_name);
1596
1597#define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \
1598static struct target_stat_scsi_att_intr_port_attribute \
1599 target_stat_scsi_att_intr_port_##_name = \
1600 __CONFIGFS_EATTR_RO(_name, \
1601 target_stat_scsi_att_intr_port_show_attr_##_name);
1602
1603static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
1604 struct se_ml_stat_grps *lgrps, char *page)
1605{
1606 struct se_lun_acl *lacl = container_of(lgrps,
1607 struct se_lun_acl, ml_stat_grps);
1608 struct se_node_acl *nacl = lacl->se_lun_nacl;
1609 struct se_dev_entry *deve;
1610 struct se_portal_group *tpg;
1611 ssize_t ret;
1612
1613 spin_lock_irq(&nacl->device_list_lock);
1614 deve = nacl->device_list[lacl->mapped_lun];
1615 if (!deve->se_lun || !deve->se_lun_acl) {
1616 spin_unlock_irq(&nacl->device_list_lock);
1617 return -ENODEV;
1618 }
1619 tpg = nacl->se_tpg;
1620
1621 ret = snprintf(page, PAGE_SIZE, "%u\n",
1622 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1623 spin_unlock_irq(&nacl->device_list_lock);
1624 return ret;
1625}
1626DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst);
1627
1628static ssize_t target_stat_scsi_att_intr_port_show_attr_dev(
1629 struct se_ml_stat_grps *lgrps, char *page)
1630{
1631 struct se_lun_acl *lacl = container_of(lgrps,
1632 struct se_lun_acl, ml_stat_grps);
1633 struct se_node_acl *nacl = lacl->se_lun_nacl;
1634 struct se_dev_entry *deve;
1635 struct se_lun *lun;
1636 ssize_t ret;
1637
1638 spin_lock_irq(&nacl->device_list_lock);
1639 deve = nacl->device_list[lacl->mapped_lun];
1640 if (!deve->se_lun || !deve->se_lun_acl) {
1641 spin_unlock_irq(&nacl->device_list_lock);
1642 return -ENODEV;
1643 }
1644 lun = deve->se_lun;
1645
1646 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1647 spin_unlock_irq(&nacl->device_list_lock);
1648 return ret;
1649}
1650DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev);
1651
1652static ssize_t target_stat_scsi_att_intr_port_show_attr_port(
1653 struct se_ml_stat_grps *lgrps, char *page)
1654{
1655 struct se_lun_acl *lacl = container_of(lgrps,
1656 struct se_lun_acl, ml_stat_grps);
1657 struct se_node_acl *nacl = lacl->se_lun_nacl;
1658 struct se_dev_entry *deve;
1659 struct se_portal_group *tpg;
1660 ssize_t ret;
1661
1662 spin_lock_irq(&nacl->device_list_lock);
1663 deve = nacl->device_list[lacl->mapped_lun];
1664 if (!deve->se_lun || !deve->se_lun_acl) {
1665 spin_unlock_irq(&nacl->device_list_lock);
1666 return -ENODEV;
1667 }
1668 tpg = nacl->se_tpg;
1669
1670 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1671 spin_unlock_irq(&nacl->device_list_lock);
1672 return ret;
1673}
1674DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port);
1675
1676static ssize_t target_stat_scsi_att_intr_port_show_attr_indx(
1677 struct se_ml_stat_grps *lgrps, char *page)
1678{
1679 struct se_lun_acl *lacl = container_of(lgrps,
1680 struct se_lun_acl, ml_stat_grps);
1681 struct se_node_acl *nacl = lacl->se_lun_nacl;
1682 struct se_session *se_sess;
1683 struct se_portal_group *tpg;
1684 ssize_t ret;
1685
1686 spin_lock_irq(&nacl->nacl_sess_lock);
1687 se_sess = nacl->nacl_sess;
1688 if (!se_sess) {
1689 spin_unlock_irq(&nacl->nacl_sess_lock);
1690 return -ENODEV;
1691 }
1692
1693 tpg = nacl->se_tpg;
1694
1695 ret = snprintf(page, PAGE_SIZE, "%u\n",
1696 tpg->se_tpg_tfo->sess_get_index(se_sess));
1697 spin_unlock_irq(&nacl->nacl_sess_lock);
1698 return ret;
1699}
1700DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx);
1701
1702static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1703 struct se_ml_stat_grps *lgrps, char *page)
1704{
1705 struct se_lun_acl *lacl = container_of(lgrps,
1706 struct se_lun_acl, ml_stat_grps);
1707 struct se_node_acl *nacl = lacl->se_lun_nacl;
1708 struct se_dev_entry *deve;
1709 ssize_t ret;
1710
1711 spin_lock_irq(&nacl->device_list_lock);
1712 deve = nacl->device_list[lacl->mapped_lun];
1713 if (!deve->se_lun || !deve->se_lun_acl) {
1714 spin_unlock_irq(&nacl->device_list_lock);
1715 return -ENODEV;
1716 }
1717
1718 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1719 spin_unlock_irq(&nacl->device_list_lock);
1720 return ret;
1721}
1722DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx);
1723
1724static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident(
1725 struct se_ml_stat_grps *lgrps, char *page)
1726{
1727 struct se_lun_acl *lacl = container_of(lgrps,
1728 struct se_lun_acl, ml_stat_grps);
1729 struct se_node_acl *nacl = lacl->se_lun_nacl;
1730 struct se_session *se_sess;
1731 struct se_portal_group *tpg;
1732 ssize_t ret;
1733 unsigned char buf[64];
1734
1735 spin_lock_irq(&nacl->nacl_sess_lock);
1736 se_sess = nacl->nacl_sess;
1737 if (!se_sess) {
1738 spin_unlock_irq(&nacl->nacl_sess_lock);
1739 return -ENODEV;
1740 }
1741
1742 tpg = nacl->se_tpg;
1743
1744 memset(buf, 0, 64);
1745 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
1746 tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
1747
1748 ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1749 spin_unlock_irq(&nacl->nacl_sess_lock);
1750 return ret;
1751}
1752DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident);
1753
1754CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port, se_ml_stat_grps,
1755 scsi_att_intr_port_group);
1756
1757static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
1758 &target_stat_scsi_att_intr_port_inst.attr,
1759 &target_stat_scsi_att_intr_port_dev.attr,
1760 &target_stat_scsi_att_intr_port_port.attr,
1761 &target_stat_scsi_att_intr_port_indx.attr,
1762 &target_stat_scsi_att_intr_port_port_auth_indx.attr,
1763 &target_stat_scsi_att_intr_port_port_ident.attr,
1764 NULL,
1765};
1766
1767static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops = {
1768 .show_attribute = target_stat_scsi_att_intr_port_attr_show,
1769 .store_attribute = target_stat_scsi_att_intr_port_attr_store,
1770};
1771
1772static struct config_item_type target_stat_scsi_att_intr_port_cit = {
1773 .ct_item_ops = &target_stat_scsi_att_intr_port_attrib_ops,
1774 .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
1775 .ct_owner = THIS_MODULE,
1776};
1777
1778
1779
1780
1781
1782void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1783{
1784 struct config_group *ml_stat_grp = &lacl->ml_stat_grps.stat_group;
1785
1786 config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
1787 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
1788 config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1789 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
1790
1791 ml_stat_grp->default_groups[0] = &lacl->ml_stat_grps.scsi_auth_intr_group;
1792 ml_stat_grp->default_groups[1] = &lacl->ml_stat_grps.scsi_att_intr_port_group;
1793 ml_stat_grp->default_groups[2] = NULL;
1794}
1795