1 // SPDX-License-Identifier: GPL-2.0
3 * dcssblk.c -- the S/390 block driver for dcss memory
5 * Authors: Carsten Otte, Stefan Weinhuber, Gerald Schaefer
8 #define KMSG_COMPONENT "dcssblk"
9 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/ctype.h>
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/blkdev.h>
18 #include <linux/completion.h>
19 #include <linux/interrupt.h>
20 #include <linux/pfn_t.h>
21 #include <linux/uio.h>
22 #include <linux/dax.h>
23 #include <asm/extmem.h>
26 #define DCSSBLK_NAME "dcssblk"
27 #define DCSSBLK_MINORS_PER_DISK 1
28 #define DCSSBLK_PARM_LEN 400
29 #define DCSS_BUS_ID_SIZE 20
31 static int dcssblk_open(struct block_device *bdev, fmode_t mode);
32 static void dcssblk_release(struct gendisk *disk, fmode_t mode);
33 static void dcssblk_submit_bio(struct bio *bio);
34 static long dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
35 long nr_pages, enum dax_access_mode mode, void **kaddr,
38 static char dcssblk_segments[DCSSBLK_PARM_LEN] = "\0";
40 static int dcssblk_major;
41 static const struct block_device_operations dcssblk_devops = {
43 .submit_bio = dcssblk_submit_bio,
45 .release = dcssblk_release,
48 static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev,
49 pgoff_t pgoff, size_t nr_pages)
54 rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_ACCESS,
58 memset(kaddr, 0, nr_pages << PAGE_SHIFT);
59 dax_flush(dax_dev, kaddr, nr_pages << PAGE_SHIFT);
63 static const struct dax_operations dcssblk_dax_ops = {
64 .direct_access = dcssblk_dax_direct_access,
65 .zero_page_range = dcssblk_dax_zero_page_range,
68 struct dcssblk_dev_info {
71 char segment_name[DCSS_BUS_ID_SIZE];
77 unsigned char save_pending;
78 unsigned char is_shared;
80 struct list_head seg_list;
81 struct dax_device *dax_dev;
86 char segment_name[DCSS_BUS_ID_SIZE];
92 static ssize_t dcssblk_add_store(struct device * dev, struct device_attribute *attr, const char * buf,
94 static ssize_t dcssblk_remove_store(struct device * dev, struct device_attribute *attr, const char * buf,
97 static DEVICE_ATTR(add, S_IWUSR, NULL, dcssblk_add_store);
98 static DEVICE_ATTR(remove, S_IWUSR, NULL, dcssblk_remove_store);
100 static struct device *dcssblk_root_dev;
102 static LIST_HEAD(dcssblk_devices);
103 static struct rw_semaphore dcssblk_devices_sem;
106 * release function for segment device.
109 dcssblk_release_segment(struct device *dev)
111 struct dcssblk_dev_info *dev_info;
112 struct segment_info *entry, *temp;
114 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
115 list_for_each_entry_safe(entry, temp, &dev_info->seg_list, lh) {
116 list_del(&entry->lh);
120 module_put(THIS_MODULE);
124 * get a minor number. needs to be called with
125 * down_write(&dcssblk_devices_sem) and the
126 * device needs to be enqueued before the semaphore is
130 dcssblk_assign_free_minor(struct dcssblk_dev_info *dev_info)
133 struct dcssblk_dev_info *entry;
135 if (dev_info == NULL)
137 for (minor = 0; minor < (1<<MINORBITS); minor++) {
139 // test if minor available
140 list_for_each_entry(entry, &dcssblk_devices, lh)
141 if (minor == entry->gd->first_minor)
143 if (!found) break; // got unused minor
147 dev_info->gd->first_minor = minor;
152 * get the struct dcssblk_dev_info from dcssblk_devices
153 * for the given name.
154 * down_read(&dcssblk_devices_sem) must be held.
156 static struct dcssblk_dev_info *
157 dcssblk_get_device_by_name(char *name)
159 struct dcssblk_dev_info *entry;
161 list_for_each_entry(entry, &dcssblk_devices, lh) {
162 if (!strcmp(name, entry->segment_name)) {
170 * get the struct segment_info from seg_list
171 * for the given name.
172 * down_read(&dcssblk_devices_sem) must be held.
174 static struct segment_info *
175 dcssblk_get_segment_by_name(char *name)
177 struct dcssblk_dev_info *dev_info;
178 struct segment_info *entry;
180 list_for_each_entry(dev_info, &dcssblk_devices, lh) {
181 list_for_each_entry(entry, &dev_info->seg_list, lh) {
182 if (!strcmp(name, entry->segment_name))
190 * get the highest address of the multi-segment block.
193 dcssblk_find_highest_addr(struct dcssblk_dev_info *dev_info)
195 unsigned long highest_addr;
196 struct segment_info *entry;
199 list_for_each_entry(entry, &dev_info->seg_list, lh) {
200 if (highest_addr < entry->end)
201 highest_addr = entry->end;
207 * get the lowest address of the multi-segment block.
210 dcssblk_find_lowest_addr(struct dcssblk_dev_info *dev_info)
213 unsigned long lowest_addr;
214 struct segment_info *entry;
218 list_for_each_entry(entry, &dev_info->seg_list, lh) {
219 if (set_first == 0) {
220 lowest_addr = entry->start;
223 if (lowest_addr > entry->start)
224 lowest_addr = entry->start;
231 * Check continuity of segments.
234 dcssblk_is_continuous(struct dcssblk_dev_info *dev_info)
237 struct segment_info *sort_list, *entry, temp;
239 if (dev_info->num_of_segments <= 1)
242 sort_list = kcalloc(dev_info->num_of_segments,
243 sizeof(struct segment_info),
245 if (sort_list == NULL)
248 list_for_each_entry(entry, &dev_info->seg_list, lh) {
249 memcpy(&sort_list[i], entry, sizeof(struct segment_info));
254 for (i = 0; i < dev_info->num_of_segments; i++)
255 for (j = 0; j < dev_info->num_of_segments; j++)
256 if (sort_list[j].start > sort_list[i].start) {
257 memcpy(&temp, &sort_list[i],
258 sizeof(struct segment_info));
259 memcpy(&sort_list[i], &sort_list[j],
260 sizeof(struct segment_info));
261 memcpy(&sort_list[j], &temp,
262 sizeof(struct segment_info));
265 /* check continuity */
266 for (i = 0; i < dev_info->num_of_segments - 1; i++) {
267 if ((sort_list[i].end + 1) != sort_list[i+1].start) {
268 pr_err("Adjacent DCSSs %s and %s are not "
269 "contiguous\n", sort_list[i].segment_name,
270 sort_list[i+1].segment_name);
274 /* EN and EW are allowed in a block device */
275 if (sort_list[i].segment_type != sort_list[i+1].segment_type) {
276 if (!(sort_list[i].segment_type & SEGMENT_EXCLUSIVE) ||
277 (sort_list[i].segment_type == SEG_TYPE_ER) ||
278 !(sort_list[i+1].segment_type &
279 SEGMENT_EXCLUSIVE) ||
280 (sort_list[i+1].segment_type == SEG_TYPE_ER)) {
281 pr_err("DCSS %s and DCSS %s have "
282 "incompatible types\n",
283 sort_list[i].segment_name,
284 sort_list[i+1].segment_name);
300 dcssblk_load_segment(char *name, struct segment_info **seg_info)
304 /* already loaded? */
305 down_read(&dcssblk_devices_sem);
306 *seg_info = dcssblk_get_segment_by_name(name);
307 up_read(&dcssblk_devices_sem);
308 if (*seg_info != NULL)
311 /* get a struct segment_info */
312 *seg_info = kzalloc(sizeof(struct segment_info), GFP_KERNEL);
313 if (*seg_info == NULL)
316 strcpy((*seg_info)->segment_name, name);
318 /* load the segment */
319 rc = segment_load(name, SEGMENT_SHARED,
320 &(*seg_info)->start, &(*seg_info)->end);
322 segment_warning(rc, (*seg_info)->segment_name);
325 INIT_LIST_HEAD(&(*seg_info)->lh);
326 (*seg_info)->segment_type = rc;
332 * device attribute for switching shared/nonshared (exclusive)
333 * operation (show + store)
336 dcssblk_shared_show(struct device *dev, struct device_attribute *attr, char *buf)
338 struct dcssblk_dev_info *dev_info;
340 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
341 return sprintf(buf, dev_info->is_shared ? "1\n" : "0\n");
345 dcssblk_shared_store(struct device *dev, struct device_attribute *attr, const char *inbuf, size_t count)
347 struct dcssblk_dev_info *dev_info;
348 struct segment_info *entry, *temp;
351 if ((count > 1) && (inbuf[1] != '\n') && (inbuf[1] != '\0'))
353 down_write(&dcssblk_devices_sem);
354 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
355 if (atomic_read(&dev_info->use_count)) {
359 if (inbuf[0] == '1') {
360 /* reload segments in shared mode */
361 list_for_each_entry(entry, &dev_info->seg_list, lh) {
362 rc = segment_modify_shared(entry->segment_name,
365 BUG_ON(rc == -EINVAL);
370 dev_info->is_shared = 1;
371 switch (dev_info->segment_type) {
375 set_disk_ro(dev_info->gd, 1);
377 } else if (inbuf[0] == '0') {
378 /* reload segments in exclusive mode */
379 if (dev_info->segment_type == SEG_TYPE_SC) {
380 pr_err("DCSS %s is of type SC and cannot be "
381 "loaded as exclusive-writable\n",
382 dev_info->segment_name);
386 list_for_each_entry(entry, &dev_info->seg_list, lh) {
387 rc = segment_modify_shared(entry->segment_name,
390 BUG_ON(rc == -EINVAL);
395 dev_info->is_shared = 0;
396 set_disk_ro(dev_info->gd, 0);
405 pr_err("DCSS device %s is removed after a failed access mode "
406 "change\n", dev_info->segment_name);
408 list_for_each_entry(entry, &dev_info->seg_list, lh) {
410 segment_unload(entry->segment_name);
412 list_del(&dev_info->lh);
414 kill_dax(dev_info->dax_dev);
415 put_dax(dev_info->dax_dev);
416 del_gendisk(dev_info->gd);
417 put_disk(dev_info->gd);
418 up_write(&dcssblk_devices_sem);
420 if (device_remove_file_self(dev, attr)) {
421 device_unregister(dev);
426 up_write(&dcssblk_devices_sem);
429 static DEVICE_ATTR(shared, S_IWUSR | S_IRUSR, dcssblk_shared_show,
430 dcssblk_shared_store);
433 * device attribute for save operation on current copy
434 * of the segment. If the segment is busy, saving will
435 * become pending until it gets released, which can be
436 * undone by storing a non-true value to this entry.
440 dcssblk_save_show(struct device *dev, struct device_attribute *attr, char *buf)
442 struct dcssblk_dev_info *dev_info;
444 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
445 return sprintf(buf, dev_info->save_pending ? "1\n" : "0\n");
449 dcssblk_save_store(struct device *dev, struct device_attribute *attr, const char *inbuf, size_t count)
451 struct dcssblk_dev_info *dev_info;
452 struct segment_info *entry;
454 if ((count > 1) && (inbuf[1] != '\n') && (inbuf[1] != '\0'))
456 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
458 down_write(&dcssblk_devices_sem);
459 if (inbuf[0] == '1') {
460 if (atomic_read(&dev_info->use_count) == 0) {
461 // device is idle => we save immediately
462 pr_info("All DCSSs that map to device %s are "
463 "saved\n", dev_info->segment_name);
464 list_for_each_entry(entry, &dev_info->seg_list, lh) {
465 if (entry->segment_type == SEG_TYPE_EN ||
466 entry->segment_type == SEG_TYPE_SN)
467 pr_warn("DCSS %s is of type SN or EN"
468 " and cannot be saved\n",
469 entry->segment_name);
471 segment_save(entry->segment_name);
474 // device is busy => we save it when it becomes
475 // idle in dcssblk_release
476 pr_info("Device %s is in use, its DCSSs will be "
477 "saved when it becomes idle\n",
478 dev_info->segment_name);
479 dev_info->save_pending = 1;
481 } else if (inbuf[0] == '0') {
482 if (dev_info->save_pending) {
483 // device is busy & the user wants to undo his save
485 dev_info->save_pending = 0;
486 pr_info("A pending save request for device %s "
487 "has been canceled\n",
488 dev_info->segment_name);
491 up_write(&dcssblk_devices_sem);
494 up_write(&dcssblk_devices_sem);
497 static DEVICE_ATTR(save, S_IWUSR | S_IRUSR, dcssblk_save_show,
501 * device attribute for showing all segments in a device
504 dcssblk_seglist_show(struct device *dev, struct device_attribute *attr,
509 struct dcssblk_dev_info *dev_info;
510 struct segment_info *entry;
512 down_read(&dcssblk_devices_sem);
513 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
516 list_for_each_entry(entry, &dev_info->seg_list, lh) {
517 strcpy(&buf[i], entry->segment_name);
518 i += strlen(entry->segment_name);
522 up_read(&dcssblk_devices_sem);
525 static DEVICE_ATTR(seglist, S_IRUSR, dcssblk_seglist_show, NULL);
527 static struct attribute *dcssblk_dev_attrs[] = {
528 &dev_attr_shared.attr,
530 &dev_attr_seglist.attr,
533 static struct attribute_group dcssblk_dev_attr_group = {
534 .attrs = dcssblk_dev_attrs,
536 static const struct attribute_group *dcssblk_dev_attr_groups[] = {
537 &dcssblk_dev_attr_group,
542 * device attribute for adding devices
545 dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
547 int rc, i, j, num_of_segments;
548 struct dcssblk_dev_info *dev_info;
549 struct segment_info *seg_info, *temp;
551 unsigned long seg_byte_size;
555 if (dev != dcssblk_root_dev) {
559 if ((count < 1) || (buf[0] == '\0') || (buf[0] == '\n')) {
564 local_buf = kmalloc(count + 1, GFP_KERNEL);
565 if (local_buf == NULL) {
574 for (i = 0; (i < count && (buf[i] != '\0') && (buf[i] != '\n')); i++) {
575 for (j = i; j < count &&
578 (buf[j] != '\n'); j++) {
579 local_buf[j-i] = toupper(buf[j]);
581 local_buf[j-i] = '\0';
582 if (((j - i) == 0) || ((j - i) > 8)) {
587 rc = dcssblk_load_segment(local_buf, &seg_info);
591 * get a struct dcssblk_dev_info
593 if (num_of_segments == 0) {
594 dev_info = kzalloc(sizeof(struct dcssblk_dev_info),
596 if (dev_info == NULL) {
600 strcpy(dev_info->segment_name, local_buf);
601 dev_info->segment_type = seg_info->segment_type;
602 INIT_LIST_HEAD(&dev_info->seg_list);
604 list_add_tail(&seg_info->lh, &dev_info->seg_list);
608 if ((buf[j] == '\0') || (buf[j] == '\n'))
612 /* no trailing colon at the end of the input */
613 if ((i > 0) && (buf[i-1] == ':')) {
617 strscpy(local_buf, buf, i + 1);
618 dev_info->num_of_segments = num_of_segments;
619 rc = dcssblk_is_continuous(dev_info);
623 dev_info->start = dcssblk_find_lowest_addr(dev_info);
624 dev_info->end = dcssblk_find_highest_addr(dev_info);
626 dev_set_name(&dev_info->dev, "%s", dev_info->segment_name);
627 dev_info->dev.release = dcssblk_release_segment;
628 dev_info->dev.groups = dcssblk_dev_attr_groups;
629 INIT_LIST_HEAD(&dev_info->lh);
630 dev_info->gd = blk_alloc_disk(NUMA_NO_NODE);
631 if (dev_info->gd == NULL) {
635 dev_info->gd->major = dcssblk_major;
636 dev_info->gd->minors = DCSSBLK_MINORS_PER_DISK;
637 dev_info->gd->fops = &dcssblk_devops;
638 dev_info->gd->private_data = dev_info;
639 dev_info->gd->flags |= GENHD_FL_NO_PART;
640 blk_queue_logical_block_size(dev_info->gd->queue, 4096);
641 blk_queue_flag_set(QUEUE_FLAG_DAX, dev_info->gd->queue);
643 seg_byte_size = (dev_info->end - dev_info->start + 1);
644 set_capacity(dev_info->gd, seg_byte_size >> 9); // size in sectors
645 pr_info("Loaded %s with total size %lu bytes and capacity %lu "
646 "sectors\n", local_buf, seg_byte_size, seg_byte_size >> 9);
648 dev_info->save_pending = 0;
649 dev_info->is_shared = 1;
650 dev_info->dev.parent = dcssblk_root_dev;
653 *get minor, add to list
655 down_write(&dcssblk_devices_sem);
656 if (dcssblk_get_segment_by_name(local_buf)) {
660 rc = dcssblk_assign_free_minor(dev_info);
663 sprintf(dev_info->gd->disk_name, "dcssblk%d",
664 dev_info->gd->first_minor);
665 list_add_tail(&dev_info->lh, &dcssblk_devices);
667 if (!try_module_get(THIS_MODULE)) {
672 * register the device
674 rc = device_register(&dev_info->dev);
678 dev_info->dax_dev = alloc_dax(dev_info, &dcssblk_dax_ops);
679 if (IS_ERR(dev_info->dax_dev)) {
680 rc = PTR_ERR(dev_info->dax_dev);
681 dev_info->dax_dev = NULL;
684 set_dax_synchronous(dev_info->dax_dev);
685 rc = dax_add_host(dev_info->dax_dev, dev_info->gd);
689 get_device(&dev_info->dev);
690 rc = device_add_disk(&dev_info->dev, dev_info->gd, NULL);
694 switch (dev_info->segment_type) {
698 set_disk_ro(dev_info->gd,1);
701 set_disk_ro(dev_info->gd,0);
704 up_write(&dcssblk_devices_sem);
709 dax_remove_host(dev_info->gd);
711 put_device(&dev_info->dev);
712 kill_dax(dev_info->dax_dev);
713 put_dax(dev_info->dax_dev);
715 list_del(&dev_info->lh);
716 put_disk(dev_info->gd);
717 list_for_each_entry(seg_info, &dev_info->seg_list, lh) {
718 segment_unload(seg_info->segment_name);
720 put_device(&dev_info->dev);
721 up_write(&dcssblk_devices_sem);
724 list_del(&dev_info->lh);
726 put_disk(dev_info->gd);
727 up_write(&dcssblk_devices_sem);
729 if (dev_info == NULL)
731 list_for_each_entry_safe(seg_info, temp, &dev_info->seg_list, lh) {
732 list_del(&seg_info->lh);
733 segment_unload(seg_info->segment_name);
744 * device attribute for removing devices
747 dcssblk_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
749 struct dcssblk_dev_info *dev_info;
750 struct segment_info *entry;
754 if (dev != dcssblk_root_dev) {
757 local_buf = kmalloc(count + 1, GFP_KERNEL);
758 if (local_buf == NULL) {
764 for (i = 0; (i < count && (*(buf+i)!='\0') && (*(buf+i)!='\n')); i++) {
765 local_buf[i] = toupper(buf[i]);
768 if ((i == 0) || (i > 8)) {
773 down_write(&dcssblk_devices_sem);
774 dev_info = dcssblk_get_device_by_name(local_buf);
775 if (dev_info == NULL) {
776 up_write(&dcssblk_devices_sem);
777 pr_warn("Device %s cannot be removed because it is not a known device\n",
782 if (atomic_read(&dev_info->use_count) != 0) {
783 up_write(&dcssblk_devices_sem);
784 pr_warn("Device %s cannot be removed while it is in use\n",
790 list_del(&dev_info->lh);
791 kill_dax(dev_info->dax_dev);
792 put_dax(dev_info->dax_dev);
793 del_gendisk(dev_info->gd);
794 put_disk(dev_info->gd);
796 /* unload all related segments */
797 list_for_each_entry(entry, &dev_info->seg_list, lh)
798 segment_unload(entry->segment_name);
800 up_write(&dcssblk_devices_sem);
802 device_unregister(&dev_info->dev);
803 put_device(&dev_info->dev);
812 dcssblk_open(struct block_device *bdev, fmode_t mode)
814 struct dcssblk_dev_info *dev_info;
817 dev_info = bdev->bd_disk->private_data;
818 if (NULL == dev_info) {
822 atomic_inc(&dev_info->use_count);
829 dcssblk_release(struct gendisk *disk, fmode_t mode)
831 struct dcssblk_dev_info *dev_info = disk->private_data;
832 struct segment_info *entry;
838 down_write(&dcssblk_devices_sem);
839 if (atomic_dec_and_test(&dev_info->use_count)
840 && (dev_info->save_pending)) {
841 pr_info("Device %s has become idle and is being saved "
842 "now\n", dev_info->segment_name);
843 list_for_each_entry(entry, &dev_info->seg_list, lh) {
844 if (entry->segment_type == SEG_TYPE_EN ||
845 entry->segment_type == SEG_TYPE_SN)
846 pr_warn("DCSS %s is of type SN or EN and cannot"
847 " be saved\n", entry->segment_name);
849 segment_save(entry->segment_name);
851 dev_info->save_pending = 0;
853 up_write(&dcssblk_devices_sem);
857 dcssblk_submit_bio(struct bio *bio)
859 struct dcssblk_dev_info *dev_info;
861 struct bvec_iter iter;
863 unsigned long page_addr;
864 unsigned long source_addr;
865 unsigned long bytes_done;
868 dev_info = bio->bi_bdev->bd_disk->private_data;
869 if (dev_info == NULL)
871 if ((bio->bi_iter.bi_sector & 7) != 0 ||
872 (bio->bi_iter.bi_size & 4095) != 0)
873 /* Request is not page-aligned. */
875 /* verify data transfer direction */
876 if (dev_info->is_shared) {
877 switch (dev_info->segment_type) {
881 /* cannot write to these segments */
882 if (bio_data_dir(bio) == WRITE) {
883 pr_warn("Writing to %s failed because it is a read-only device\n",
884 dev_name(&dev_info->dev));
890 index = (bio->bi_iter.bi_sector >> 3);
891 bio_for_each_segment(bvec, bio, iter) {
892 page_addr = (unsigned long)bvec_virt(&bvec);
893 source_addr = dev_info->start + (index<<12) + bytes_done;
894 if (unlikely((page_addr & 4095) != 0) || (bvec.bv_len & 4095) != 0)
897 if (bio_data_dir(bio) == READ) {
898 memcpy((void*)page_addr, (void*)source_addr,
901 memcpy((void*)source_addr, (void*)page_addr,
904 bytes_done += bvec.bv_len;
913 __dcssblk_direct_access(struct dcssblk_dev_info *dev_info, pgoff_t pgoff,
914 long nr_pages, void **kaddr, pfn_t *pfn)
916 resource_size_t offset = pgoff * PAGE_SIZE;
917 unsigned long dev_sz;
919 dev_sz = dev_info->end - dev_info->start + 1;
921 *kaddr = (void *) dev_info->start + offset;
923 *pfn = __pfn_to_pfn_t(PFN_DOWN(dev_info->start + offset),
924 PFN_DEV|PFN_SPECIAL);
926 return (dev_sz - offset) / PAGE_SIZE;
930 dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
931 long nr_pages, enum dax_access_mode mode, void **kaddr,
934 struct dcssblk_dev_info *dev_info = dax_get_private(dax_dev);
936 return __dcssblk_direct_access(dev_info, pgoff, nr_pages, kaddr, pfn);
940 dcssblk_check_params(void)
943 char buf[DCSSBLK_PARM_LEN + 1];
944 struct dcssblk_dev_info *dev_info;
946 for (i = 0; (i < DCSSBLK_PARM_LEN) && (dcssblk_segments[i] != '\0');
948 for (j = i; (j < DCSSBLK_PARM_LEN) &&
949 (dcssblk_segments[j] != ',') &&
950 (dcssblk_segments[j] != '\0') &&
951 (dcssblk_segments[j] != '('); j++)
953 buf[j-i] = dcssblk_segments[j];
956 rc = dcssblk_add_store(dcssblk_root_dev, NULL, buf, j-i);
957 if ((rc >= 0) && (dcssblk_segments[j] == '(')) {
958 for (k = 0; (buf[k] != ':') && (buf[k] != '\0'); k++)
959 buf[k] = toupper(buf[k]);
961 if (!strncmp(&dcssblk_segments[j], "(local)", 7)) {
962 down_read(&dcssblk_devices_sem);
963 dev_info = dcssblk_get_device_by_name(buf);
964 up_read(&dcssblk_devices_sem);
966 dcssblk_shared_store(&dev_info->dev,
970 while ((dcssblk_segments[j] != ',') &&
971 (dcssblk_segments[j] != '\0'))
975 if (dcssblk_segments[j] == '\0')
982 * The init/exit functions.
987 root_device_unregister(dcssblk_root_dev);
988 unregister_blkdev(dcssblk_major, DCSSBLK_NAME);
996 dcssblk_root_dev = root_device_register("dcssblk");
997 if (IS_ERR(dcssblk_root_dev))
998 return PTR_ERR(dcssblk_root_dev);
999 rc = device_create_file(dcssblk_root_dev, &dev_attr_add);
1002 rc = device_create_file(dcssblk_root_dev, &dev_attr_remove);
1005 rc = register_blkdev(0, DCSSBLK_NAME);
1009 init_rwsem(&dcssblk_devices_sem);
1011 dcssblk_check_params();
1015 root_device_unregister(dcssblk_root_dev);
1020 module_init(dcssblk_init);
1021 module_exit(dcssblk_exit);
1023 module_param_string(segments, dcssblk_segments, DCSSBLK_PARM_LEN, 0444);
1024 MODULE_PARM_DESC(segments, "Name of DCSS segment(s) to be loaded, "
1025 "comma-separated list, names in each set separated "
1026 "by commas are separated by colons, each set contains "
1027 "names of contiguous segments and each name max. 8 chars.\n"
1028 "Adding \"(local)\" to the end of each set equals echoing 0 "
1029 "to /sys/devices/dcssblk/<device name>/shared after loading "
1030 "the contiguous segments - \n"
1031 "e.g. segments=\"mydcss1,mydcss2:mydcss3,mydcss4(local)\"");
1033 MODULE_LICENSE("GPL");