[PATCH 01/11] libblock: Use self-contained mutex for nvdisk
Sebastian Huber
sebastian.huber at embedded-brains.de
Tue Feb 6 15:51:19 UTC 2018
Update #2843.
---
cpukit/libblock/src/nvdisk.c | 92 +++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 53 deletions(-)
diff --git a/cpukit/libblock/src/nvdisk.c b/cpukit/libblock/src/nvdisk.c
index 1df0ca2ae4..bb1fc5dbe9 100644
--- a/cpukit/libblock/src/nvdisk.c
+++ b/cpukit/libblock/src/nvdisk.c
@@ -25,9 +25,10 @@
#include <string.h>
#include <inttypes.h>
-#include "rtems/blkdev.h"
-#include "rtems/diskdevs.h"
-#include "rtems/nvdisk.h"
+#include <rtems/blkdev.h>
+#include <rtems/diskdevs.h>
+#include <rtems/nvdisk.h>
+#include <rtems/thread.h>
/**
* @note
@@ -102,7 +103,7 @@ typedef struct rtems_mvdisk
rtems_nvdisk_device_ctl* devices; /**< The NV devices for this disk. */
uint32_t device_count; /**< The number of NV devices. */
uint32_t cs_pages; /**< The num of pages of checksums. */
- rtems_id lock; /**< Mutex for threading protection.*/
+ rtems_mutex lock; /**< Mutex for threading protection.*/
uint32_t info_level; /**< The info trace level. */
} rtems_nvdisk;
@@ -690,7 +691,6 @@ rtems_nvdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
dev_t dev = rtems_disk_get_device_identifier (dd);
rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev);
rtems_blkdev_request* r = argp;
- rtems_status_code sc;
if (minor >= rtems_nvdisk_count)
{
@@ -706,49 +706,42 @@ rtems_nvdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
errno = 0;
- sc = rtems_semaphore_obtain (rtems_nvdisks[minor].lock, RTEMS_WAIT, 0);
- if (sc != RTEMS_SUCCESSFUL)
- errno = EIO;
- else
- {
- errno = 0;
- switch (req)
- {
- case RTEMS_BLKIO_REQUEST:
- switch (r->req)
- {
- case RTEMS_BLKDEV_REQ_READ:
- errno = rtems_nvdisk_read (&rtems_nvdisks[minor], r);
- break;
-
- case RTEMS_BLKDEV_REQ_WRITE:
- errno = rtems_nvdisk_write (&rtems_nvdisks[minor], r);
- break;
-
- default:
- errno = EINVAL;
- break;
- }
- break;
-
- case RTEMS_NVDISK_IOCTL_ERASE_DISK:
- errno = rtems_nvdisk_erase_disk (&rtems_nvdisks[minor]);
- break;
-
- case RTEMS_NVDISK_IOCTL_INFO_LEVEL:
- rtems_nvdisks[minor].info_level = (uintptr_t) argp;
- break;
-
- default:
- rtems_blkdev_ioctl (dd, req, argp);
- break;
- }
+ rtems_mutex_lock (&rtems_nvdisks[minor].lock);
- sc = rtems_semaphore_release (rtems_nvdisks[minor].lock);
- if (sc != RTEMS_SUCCESSFUL)
- errno = EIO;
+ switch (req)
+ {
+ case RTEMS_BLKIO_REQUEST:
+ switch (r->req)
+ {
+ case RTEMS_BLKDEV_REQ_READ:
+ errno = rtems_nvdisk_read (&rtems_nvdisks[minor], r);
+ break;
+
+ case RTEMS_BLKDEV_REQ_WRITE:
+ errno = rtems_nvdisk_write (&rtems_nvdisks[minor], r);
+ break;
+
+ default:
+ errno = EINVAL;
+ break;
+ }
+ break;
+
+ case RTEMS_NVDISK_IOCTL_ERASE_DISK:
+ errno = rtems_nvdisk_erase_disk (&rtems_nvdisks[minor]);
+ break;
+
+ case RTEMS_NVDISK_IOCTL_INFO_LEVEL:
+ rtems_nvdisks[minor].info_level = (uintptr_t) argp;
+ break;
+
+ default:
+ rtems_blkdev_ioctl (dd, req, argp);
+ break;
}
+ rtems_mutex_unlock (&rtems_nvdisks[minor].lock);
+
return errno == 0 ? 0 : -1;
}
@@ -830,14 +823,7 @@ rtems_nvdisk_initialize (rtems_device_major_number major,
return sc;
}
- sc = rtems_semaphore_create (rtems_build_name ('N', 'V', 'D', 'K'), 1,
- RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE |
- RTEMS_INHERIT_PRIORITY, 0, &nvd->lock);
- if (sc != RTEMS_SUCCESSFUL)
- {
- rtems_nvdisk_error ("disk lock create failed");
- return sc;
- }
+ rtems_mutex_init (&nvd->lock, "NV Disk");
}
rtems_nvdisk_count = rtems_nvdisk_configuration_size;
--
2.12.3
More information about the devel
mailing list