libblock: Use self-contained mutex for nvdisk

Update #2843.
This commit is contained in:
Sebastian Huber
2018-01-02 16:31:08 +01:00
parent e16111b2cf
commit c8d5bed13c

View File

@@ -25,9 +25,10 @@
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include "rtems/blkdev.h" #include <rtems/blkdev.h>
#include "rtems/diskdevs.h" #include <rtems/diskdevs.h>
#include "rtems/nvdisk.h" #include <rtems/nvdisk.h>
#include <rtems/thread.h>
/** /**
* @note * @note
@@ -102,7 +103,7 @@ typedef struct rtems_mvdisk
rtems_nvdisk_device_ctl* devices; /**< The NV devices for this disk. */ rtems_nvdisk_device_ctl* devices; /**< The NV devices for this disk. */
uint32_t device_count; /**< The number of NV devices. */ uint32_t device_count; /**< The number of NV devices. */
uint32_t cs_pages; /**< The num of pages of checksums. */ 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. */ uint32_t info_level; /**< The info trace level. */
} rtems_nvdisk; } 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); dev_t dev = rtems_disk_get_device_identifier (dd);
rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev); rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev);
rtems_blkdev_request* r = argp; rtems_blkdev_request* r = argp;
rtems_status_code sc;
if (minor >= rtems_nvdisk_count) if (minor >= rtems_nvdisk_count)
{ {
@@ -706,12 +706,8 @@ rtems_nvdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
errno = 0; errno = 0;
sc = rtems_semaphore_obtain (rtems_nvdisks[minor].lock, RTEMS_WAIT, 0); rtems_mutex_lock (&rtems_nvdisks[minor].lock);
if (sc != RTEMS_SUCCESSFUL)
errno = EIO;
else
{
errno = 0;
switch (req) switch (req)
{ {
case RTEMS_BLKIO_REQUEST: case RTEMS_BLKIO_REQUEST:
@@ -744,10 +740,7 @@ rtems_nvdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
break; break;
} }
sc = rtems_semaphore_release (rtems_nvdisks[minor].lock); rtems_mutex_unlock (&rtems_nvdisks[minor].lock);
if (sc != RTEMS_SUCCESSFUL)
errno = EIO;
}
return errno == 0 ? 0 : -1; return errno == 0 ? 0 : -1;
} }
@@ -830,14 +823,7 @@ rtems_nvdisk_initialize (rtems_device_major_number major,
return sc; return sc;
} }
sc = rtems_semaphore_create (rtems_build_name ('N', 'V', 'D', 'K'), 1, rtems_mutex_init (&nvd->lock, "NV Disk");
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_nvdisk_count = rtems_nvdisk_configuration_size; rtems_nvdisk_count = rtems_nvdisk_configuration_size;