forked from scality/RestBlockDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrb_sysfs.c
761 lines (628 loc) · 17.9 KB
/
srb_sysfs.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/*
* Copyright (C) 2014 SCALITY SA - http://www.scality.com
*
* This file is part of ScalityRestBlock.
*
* ScalityRestBlock is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ScalityRestBlock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ScalityRestBlock. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/device.h>
#include <linux/blkdev.h>
#include <linux/string.h>
#include "srb.h"
/* Function for parsing params and reading humand readable size format
*
* Returns number of parameters found, and fills up to param_nb parameters.
*/
int parse_params(char *params, const char *delim, char **param_tbl, int param_nb, int max)
{
int i;
int j;
char *tmp;
//printk(KERN_DEBUG "DEBUG: parse_params: params(%d): %s\n", max, params);
j = 0;
for (i = 0; i < max; i++) {
tmp = strsep(¶ms, delim);
if (NULL != tmp && *tmp != '\0') {
if (j < param_nb)
param_tbl[j] = tmp;
j++;
}
}
//printk(KERN_DEBUG "DEBUG: parse_params: params: %s, %s\n", param_tbl[0], param_tbl[1]);
return j;
}
int human_to_bytes(char *size_str, unsigned long long *size)
{
char h;
unsigned long long coef;
int ret;
//printk(KERN_DEBUG "DEBUG: human_to_bytes: buff: %s\n", size_str);
coef = 1;
h = size_str[strlen(size_str) - 1];
/* get human format if any and set coeff */
switch (h) {
case 'G':
coef = GB;
size_str[strlen(size_str) - 1] = '\0';
break;
case 'M':
coef = MB;
size_str[strlen(size_str) - 1] = '\0';
break;
case 'k':
coef = kB;
size_str[strlen(size_str) - 1] = '\0';
break;
default:
coef = 1;
}
/* calculate size */
ret = kstrtoull(size_str, 10, size);
if (ret != 0) {
SRB_LOG_ERR(srb_log, "Invalid volume size %s (%llu) (ret: %d)", size_str, *size, ret);
return -EINVAL;
}
*size = *size * coef;
return 0;
}
/********************************************************************
* /sys/block/srb?/
* srb_debug Sets verbosity
* srb_urls Gets device CDMI url
* srb_name Gets device's on-storage filename
* srb_size Gets device size
*******************************************************************/
static ssize_t attr_debug_store(struct device *dv,
struct device_attribute *attr,
const char *buff, size_t count)
{
struct gendisk *disk = dev_to_disk(dv);
struct srb_device_s *dev = disk->private_data;
char *end;
long new;
int val;
/* XXX: simple_strtol is an obsolete function
* TODO: replace it with kstrtol wich can returns:
* 0 on success, -ERANGE on overflow and -EINVAL on parsing error
*/
new = simple_strtol(buff, &end, 0);
if (end == buff || new > INT_MAX || new < INT_MIN) {
SRB_LOG_WARN(dev->debug.level, "attr_debug_store: Invalid debug value");
return -EINVAL;
}
val = (int) new;
if (val >= 0 && val <= 7) {
dev->debug.level = val;
SRB_LOG_DEBUG(dev->debug.level, "attr_debug_store: Setting Log level to %d for device %s",
val, dev->name);
}
else
SRB_LOG_WARN(dev->debug.level, "attr_debug_store: Invalid debug value (%d) for device %s in sysfs",
val, dev->name);
return count;
}
static ssize_t attr_debug_show(struct device *dv,
struct device_attribute *attr, char *buff)
{
struct gendisk *disk = dev_to_disk(dv);
struct srb_device_s *dev = disk->private_data;
snprintf(buff, PAGE_SIZE, "%d\n", dev->debug.level);
return strlen(buff);
}
static ssize_t attr_urls_show(struct device *dv,
struct device_attribute *attr, char *buff)
{
struct gendisk *disk = dev_to_disk(dv);
struct srb_device_s *dev = disk->private_data;
//snprintf(buff, PAGE_SIZE, "%s\n", dev->thread_cdmi_desc[0].url);
snprintf(buff, PAGE_SIZE, "%s\n", dev->thread_cdmi_desc[0]->url);
return strlen(buff);
}
static ssize_t attr_disk_name_show(struct device *dv,
struct device_attribute *attr, char *buff)
{
struct gendisk *disk = dev_to_disk(dv);
struct srb_device_s *dev = disk->private_data;
//snprintf(buff, PAGE_SIZE, "%s\n", kbasename(dev->thread_cdmi_desc[0].url));
snprintf(buff, PAGE_SIZE, "%s\n", kbasename(dev->thread_cdmi_desc[0]->url));
return strlen(buff);
}
static ssize_t attr_disk_size_show(struct device *dv,
struct device_attribute *attr, char *buff)
{
struct gendisk *disk = dev_to_disk(dv);
struct srb_device_s *dev = disk->private_data;
snprintf(buff, PAGE_SIZE, "%llu\n", dev->disk_size);
return strlen(buff);
}
static DEVICE_ATTR(srb_debug, S_IWUSR | S_IRUGO, &attr_debug_show, &attr_debug_store);
static DEVICE_ATTR(srb_urls, S_IRUGO, &attr_urls_show, NULL);
static DEVICE_ATTR(srb_name, S_IRUGO, &attr_disk_name_show, NULL);
static DEVICE_ATTR(srb_size, S_IRUGO, &attr_disk_size_show, NULL);
/************************************************************************
* /sys/class/srb/
* create Create the volume's file on the storage
* destroy Removes the volume's file on the storage
* attach Attach a volume as a new srb device
* detach Detaches (remove from the system)
* the requested volume (or device)
***********************************************************************/
static struct class *class_srb; /* /sys/class/srb */
static void class_srb_release(struct class *cls)
{
if (cls != NULL)
kfree(cls);
}
static ssize_t class_srb_create_show(struct class *c, struct class_attribute *attr,
char *buf)
{
(void)c;
(void)attr;
snprintf(buf, PAGE_SIZE, "# Usage: echo 'VolumeName size(bytes)' > create\n");
return strlen(buf);
}
static ssize_t class_srb_create_store(struct class *c,
struct class_attribute *attr,
const char *buf, size_t count)
{
ssize_t ret = 0;
//char filename[SRB_URL_SIZE + 1];
//const char *tmp = buf;
unsigned long long size = 0;
size_t len = 0;
char *size_str = NULL;
char *params[2];
const char *delim = " ";
char *tmp_buf;
(void)c;
(void)attr;
SRB_LOG_INFO(srb_log, "Creating volume with params: %s (%lu)", buf, count);
/* TODO: split the buff into two string array with a thread-safe function strtok_r
* - use a temporary buffer
* - properly end string
*/
tmp_buf = NULL;
if (count >= 256) {
SRB_LOG_ERR(srb_log, "Invalid parameter (too long: %lu)", count);
ret = -EINVAL;
goto out;
}
tmp_buf = kmalloc(count + 1, GFP_KERNEL);
if (NULL == tmp_buf) {
SRB_LOG_ERR(srb_log, "Unable to allocate memory for parameters");
ret = -ENOMEM;
goto out;
}
memset(tmp_buf, 0, count + 1);
memcpy(tmp_buf, buf, count);
//printk(KERN_DEBUG "DEBUG: class_srb_create_store: buff (%lu:%lu): '%c':%x", count, sizeof(buf), buf[count - 1], buf[count - 1]);
/* remove CR or LF if any and end string */
if (tmp_buf[count - 1] == '\n' || tmp_buf[count - 1] == '\r')
tmp_buf[count - 1] = 0;
else
tmp_buf[count] = 0;
parse_params(tmp_buf, delim, params, 2, count);
/* sanity check */
len = strlen(params[0]);
if (len >= SRB_URL_SIZE) {
SRB_LOG_ERR(srb_log, "Invalid volume name (too long: %lu)", len);
ret = -EINVAL;
goto out;
}
ret = human_to_bytes(params[1], &size);
if (ret != 0) {
SRB_LOG_ERR(srb_log, "Invalid volume size: %s", params[1]);
goto out;
}
SRB_LOG_INFO(srb_log, "Creating volume %s of size %llu (bytes)", params[0], size);
ret = srb_device_create(params[0], size);
if (ret != 0) {
SRB_LOG_ERR(srb_log, "Failed to create device: %lu", ret);
goto out;
}
ret = count;
out:
if (size_str != NULL)
kfree(size_str);
if (tmp_buf != NULL)
kfree(tmp_buf);
return ret;
}
static ssize_t class_srb_extend_show(struct class *c, struct class_attribute *attr,
char *buf)
{
(void)c;
(void)attr;
snprintf(buf, PAGE_SIZE,
"The new size must be greater than the current size.\n"
"# Usage: echo 'VolumeName size(bytes)' > extend\n");
return strlen(buf);
}
static ssize_t class_srb_extend_store(struct class *c,
struct class_attribute *attr,
const char *buf, size_t count)
{
ssize_t ret = 0;
//char filename[SRB_URL_SIZE + 1];
//const char *tmp = buf;
unsigned long long size = 0;
size_t len = 0;
char *size_str = NULL;
char *params[2];
const char *delim = " ";
char *tmp_buf;
(void)c;
(void)attr;
SRB_LOG_INFO(srb_log, "Extending volume with params: %s (%lu)", buf, count);
tmp_buf = NULL;
if (count >= 256) {
SRB_LOG_ERR(srb_log, "Invalid parameter (too long: %lu)", count);
ret = -EINVAL;
goto out;
}
tmp_buf = kmalloc(count, GFP_KERNEL);
if (NULL == tmp_buf) {
SRB_LOG_ERR(srb_log, "Unable to allocate memory for parameters");
ret = -ENOMEM;
goto out;
}
memset(tmp_buf, 0, count);
memcpy(tmp_buf, buf, count);
/* remove CR or LF if any and end string */
if (tmp_buf[count - 1] == '\n' || tmp_buf[count - 1] == '\r')
tmp_buf[count - 1] = 0;
else
tmp_buf[count] = 0;
parse_params(tmp_buf, delim, params, 2, count);
/* sanity check */
len = strlen(params[0]);
if (len >= SRB_URL_SIZE) {
SRB_LOG_ERR(srb_log, "Invalid volume name (too long: %lu)", len);
ret = -EINVAL;
goto out;
}
ret = human_to_bytes(params[1], &size);
if (ret != 0) {
SRB_LOG_ERR(srb_log, "Invalid volume size: %s", params[1]);
goto out;
}
SRB_LOG_INFO(srb_log, "Extending volume %s of size %llu (bytes)", params[0], size);
ret = srb_device_extend(params[0], size);
if (ret != 0) {
goto out;
}
ret = count;
out:
if (size_str != NULL)
kfree(size_str);
if (tmp_buf != NULL)
kfree(tmp_buf);
return ret;
}
static ssize_t class_srb_destroy_show(struct class *c, struct class_attribute *attr,
char *buf)
{
(void)c;
(void)attr;
snprintf(buf, PAGE_SIZE, "# Usage: echo VolumeName > destroy\n");
return strlen(buf);
}
static ssize_t class_srb_destroy_store(struct class *c,
struct class_attribute *attr,
const char *buf, size_t count)
{
ssize_t ret = 0;
char filename[SRB_URL_SIZE + 1];
(void)c;
(void)attr;
/* Sanity check URL size */
if ((count == 0) || (count >= SRB_URL_SIZE)) {
SRB_LOG_ERR(srb_log, "Invalid parameter (too long: %lu)", count);
ret = -EINVAL;
goto out;
}
memset(filename, 0, count);
memcpy(filename, buf, count);
if (filename[count - 1] == '\n' || filename[count - 1] == '\r')
filename[count - 1] = 0;
else
filename[count] = 0;
SRB_LOG_INFO(srb_log, "Destroying volume '%s'", filename);
ret = srb_device_destroy(filename);
if (ret != 0) {
goto out;
}
ret = count;
out:
return ret;
}
static ssize_t class_srb_attach_show(struct class *c, struct class_attribute *attr,
char *buf)
{
(void)c;
(void)attr;
snprintf(buf, PAGE_SIZE, "# Usage: echo VolumeName DeviceName > attach\n");
return strlen(buf);
}
static ssize_t class_srb_attach_store(struct class *c,
struct class_attribute *attr,
const char *buf, size_t count)
{
int ret;
const char *delim = " ";
char *tmp_buf = NULL;
char *params[2];
const char **filename = (const char **)¶ms[0];
const char **devname = (const char **)¶ms[1];
memset(params, 0, sizeof(params));
tmp_buf = kmalloc(count + 1, GFP_KERNEL);
if (NULL == tmp_buf) {
SRB_LOG_ERR(srb_log, "Unable to allocate memory for parameters");
ret = -ENOMEM;
goto out;
}
memcpy(tmp_buf, buf, count + 1);
/* remove CR or LF if any and end string */
if (tmp_buf[count - 1] == '\n' || tmp_buf[count - 1] == '\r')
tmp_buf[count - 1] = 0;
else
tmp_buf[count] = 0;
ret = parse_params(tmp_buf, delim, params, 2, count);
if (ret != 2) {
SRB_LOG_ERR(srb_log, "Invalid parameters: %i instead of 2",
ret);
ret = -EINVAL;
goto out;
}
/* Sanity check params sizes */
if (NULL == *filename || strlen(*filename) > SRB_URL_SIZE) {
SRB_LOG_ERR(srb_log, "Invalid parameter #1: "
"'%s'(%lu characters)", *filename,
strlen(*filename));
ret = -EINVAL;
goto out;
}
if (NULL == *devname || strlen(*devname) > DISK_NAME_LEN) {
SRB_LOG_ERR(srb_log, "Invalid parameter #2: "
"'%s'(%lu characters)", *devname,
strlen(*devname));
ret = -EINVAL;
goto out;
}
SRB_LOG_INFO(srb_log, "Attaching volume '%s' as device '%s'",
*filename, *devname);
ret = srb_device_attach(*filename, *devname);
if (ret != 0)
goto out;
ret = count;
out:
if (NULL != tmp_buf)
kfree(tmp_buf);
return ret;
}
static ssize_t class_srb_detach_show(struct class *c, struct class_attribute *attr,
char *buf)
{
(void)c;
(void)attr;
snprintf(buf, PAGE_SIZE, "# Usage: echo DeviceName > detach\n");
return strlen(buf);
}
static ssize_t class_srb_detach_store(struct class *c,
struct class_attribute *attr,
const char *buf,
size_t count)
{
int ret = -ENOENT;
char devname[DISK_NAME_LEN + 1];
/* Sanity check device name size */
if ((count == 0) || (count >= sizeof(devname))) {
SRB_LOG_ERR(srb_log, "Invalid parameter (too long: %lu)", count);
return -EINVAL;
}
memcpy(devname, buf, count);
if (devname[count - 1] == '\n')
devname[count - 1] = 0;
else
devname[count] = 0;
SRB_LOG_INFO(srb_log, "Detaching device %s", devname);
ret = srb_device_detach(devname);
if (ret == 0)
return count;
return ret;
}
static ssize_t class_srb_addurl_show(struct class *c, struct class_attribute *attr,
char *buf)
{
(void)c;
(void)attr;
snprintf(buf, PAGE_SIZE, "# Usage: echo server_url1,...,server_urlN > add_urls\n");
return strlen(buf);
}
static ssize_t class_srb_addurl_store(struct class *c,
struct class_attribute *attr,
const char *buf,
size_t count)
{
ssize_t ret = 0;
char url[SRB_URL_SIZE+1];
const char *tmp = buf;
const char *tmpend = tmp;
int errcount = 0;
while (tmp != NULL) {
while (*tmp != 0 && *tmp == ',')
++tmp;
tmpend = strchr(tmp, ',');
if (tmpend != NULL) {
memcpy(url, tmp, (tmpend - tmp));
url[(tmpend - tmp)] = 0;
}
else {
// Strip the ending newline
tmpend = tmp;
while (*tmpend && *tmpend != '\n')
tmpend++;
if ((tmpend - tmp) > SRB_URL_SIZE) {
SRB_LOG_ERR(srb_log, "Url too big: '%s'", tmp);
ret = -EINVAL;
goto end;
}
memcpy(url, tmp, (tmpend - tmp));
url[(tmpend - tmp)] = 0;
tmpend = NULL;
}
url[SRB_URL_SIZE] = 0;
ret = srb_server_add(url);
if (ret < 0)
errcount += 1;
tmp = tmpend;
}
ret = count;
if (errcount > 0) {
SRB_LOG_ERR(srb_log, "Could not add every url to driver.");
ret = -EINVAL;
}
end:
return ret;
}
static ssize_t class_srb_removeurl_show(struct class *c, struct class_attribute *attr,
char *buf)
{
(void)c;
(void)attr;
snprintf(buf, PAGE_SIZE, "# Usage: echo server_url1,...,server_urlN > remove_urls\n");
return strlen(buf);
}
static ssize_t class_srb_removeurl_store(struct class *c,
struct class_attribute *attr,
const char *buf,
size_t count)
{
ssize_t ret = 0;
char url[SRB_URL_SIZE];
const char *tmp = buf;
const char *tmpend = tmp;
while (tmp != NULL)
{
while (*tmp != 0 && *tmp == ',')
++tmp;
tmpend = strchr(tmp, ',');
if (tmpend != NULL)
{
memcpy(url, tmp, (tmpend - tmp));
url[(tmpend - tmp)] = 0;
}
else
{
// Strip the ending newline
tmpend = tmp;
while (*tmpend && *tmpend != '\n')
tmpend++;
if ((tmpend - tmp) > SRB_URL_SIZE)
{
SRB_LOG_ERR(srb_log, "Url too big: '%s'", tmp);
ret = -EINVAL;
goto end;
}
memcpy(url, tmp, (tmpend - tmp));
url[(tmpend - tmp)] = 0;
tmpend = NULL;
}
ret = srb_server_remove(url);
if (ret < 0)
{
goto end;
}
tmp = tmpend;
}
ret = count;
end:
return ret;
}
static ssize_t class_srb_urls_show(struct class *c, struct class_attribute *attr,
char *buf)
{
ssize_t ret = 0;
(void)c;
(void)attr;
ret = srb_servers_dump(buf, PAGE_SIZE);
return ret;
}
static ssize_t class_srb_volumes_show(struct class *c, struct class_attribute *attr,
char *buf)
{
ssize_t ret = 0;
(void)c;
(void)attr;
ret = srb_volumes_dump(buf, PAGE_SIZE);
return ret;
}
void srb_sysfs_device_init(srb_device_t *dev)
{
device_create_file(disk_to_dev(dev->disk), &dev_attr_srb_debug);
device_create_file(disk_to_dev(dev->disk), &dev_attr_srb_urls);
device_create_file(disk_to_dev(dev->disk), &dev_attr_srb_name);
device_create_file(disk_to_dev(dev->disk), &dev_attr_srb_size);
}
static struct class_attribute class_srb_attrs[] = {
__ATTR(attach, 0600, class_srb_attach_show, class_srb_attach_store),
__ATTR(detach, 0600, class_srb_detach_show, class_srb_detach_store),
__ATTR(create, 0600, class_srb_create_show, class_srb_create_store),
__ATTR(extend, 0600, class_srb_extend_show, class_srb_extend_store),
__ATTR(destroy, 0600, class_srb_destroy_show, class_srb_destroy_store),
__ATTR(add_urls, 0600, class_srb_addurl_show, class_srb_addurl_store),
__ATTR(remove_urls, 0600, class_srb_removeurl_show, class_srb_removeurl_store),
__ATTR(urls, 0400, class_srb_urls_show, NULL),
__ATTR(volumes, 0400, class_srb_volumes_show, NULL),
__ATTR_NULL
};
int srb_sysfs_init(void)
{
int ret = 0;
/*
* create control files in sysfs
* /sys/class/srb/...
*/
/* TODO: check for class_create() from device.h
*/
class_srb = kzalloc(sizeof(*class_srb), GFP_KERNEL);
if (!class_srb) {
SRB_LOG_CRIT(srb_log, "Failed to allocate memory for sysfs class registration");
return -ENOMEM;
}
class_srb->name = DEV_NAME;
class_srb->owner = THIS_MODULE;
class_srb->class_release = class_srb_release;
class_srb->class_attrs = class_srb_attrs;
ret = class_register(class_srb);
if (ret) {
if (class_srb != NULL)
kfree(class_srb);
class_srb = NULL;
SRB_LOG_CRIT(srb_log, "Failed to create class srb");
return ret;
}
return 0;
}
void srb_sysfs_cleanup(void)
{
/* TODO: check for class_unregister from device.h
*/
if (class_srb)
class_destroy(class_srb);
class_srb = NULL;
}