mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 03:09:34 +03:00
Update SPLAT to use kmutex_t for portability
For consistency throughout the code update the SPLAT infrastructure to use the wrapped mutex interfaces. Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
This commit is contained in:
parent
6203295438
commit
0cb3dafccd
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <sys/atomic.h>
|
#include <sys/atomic.h>
|
||||||
#include <sys/thread.h>
|
#include <sys/thread.h>
|
||||||
|
#include <sys/mutex.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include "splat-internal.h"
|
#include "splat-internal.h"
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ typedef enum {
|
|||||||
typedef struct atomic_priv {
|
typedef struct atomic_priv {
|
||||||
unsigned long ap_magic;
|
unsigned long ap_magic;
|
||||||
struct file *ap_file;
|
struct file *ap_file;
|
||||||
struct mutex ap_lock;
|
kmutex_t ap_lock;
|
||||||
wait_queue_head_t ap_waitq;
|
wait_queue_head_t ap_waitq;
|
||||||
volatile uint64_t ap_atomic;
|
volatile uint64_t ap_atomic;
|
||||||
volatile uint64_t ap_atomic_exited;
|
volatile uint64_t ap_atomic_exited;
|
||||||
@ -70,10 +71,10 @@ splat_atomic_work(void *priv)
|
|||||||
ap = (atomic_priv_t *)priv;
|
ap = (atomic_priv_t *)priv;
|
||||||
ASSERT(ap->ap_magic == SPLAT_ATOMIC_TEST_MAGIC);
|
ASSERT(ap->ap_magic == SPLAT_ATOMIC_TEST_MAGIC);
|
||||||
|
|
||||||
mutex_lock(&ap->ap_lock);
|
mutex_enter(&ap->ap_lock);
|
||||||
op = ap->ap_op;
|
op = ap->ap_op;
|
||||||
wake_up(&ap->ap_waitq);
|
wake_up(&ap->ap_waitq);
|
||||||
mutex_unlock(&ap->ap_lock);
|
mutex_exit(&ap->ap_lock);
|
||||||
|
|
||||||
splat_vprint(ap->ap_file, SPLAT_ATOMIC_TEST1_NAME,
|
splat_vprint(ap->ap_file, SPLAT_ATOMIC_TEST1_NAME,
|
||||||
"Thread %d successfully started: %lu/%lu\n", op,
|
"Thread %d successfully started: %lu/%lu\n", op,
|
||||||
@ -143,13 +144,13 @@ splat_atomic_test1(struct file *file, void *arg)
|
|||||||
|
|
||||||
ap.ap_magic = SPLAT_ATOMIC_TEST_MAGIC;
|
ap.ap_magic = SPLAT_ATOMIC_TEST_MAGIC;
|
||||||
ap.ap_file = file;
|
ap.ap_file = file;
|
||||||
mutex_init(&ap.ap_lock);
|
mutex_init(&ap.ap_lock, SPLAT_ATOMIC_TEST1_NAME, NULL, NULL);
|
||||||
init_waitqueue_head(&ap.ap_waitq);
|
init_waitqueue_head(&ap.ap_waitq);
|
||||||
ap.ap_atomic = SPLAT_ATOMIC_INIT_VALUE;
|
ap.ap_atomic = SPLAT_ATOMIC_INIT_VALUE;
|
||||||
ap.ap_atomic_exited = 0;
|
ap.ap_atomic_exited = 0;
|
||||||
|
|
||||||
for (i = 0; i < SPLAT_ATOMIC_COUNT_64; i++) {
|
for (i = 0; i < SPLAT_ATOMIC_COUNT_64; i++) {
|
||||||
mutex_lock(&ap.ap_lock);
|
mutex_enter(&ap.ap_lock);
|
||||||
ap.ap_op = i;
|
ap.ap_op = i;
|
||||||
|
|
||||||
thr = (kthread_t *)thread_create(NULL, 0, splat_atomic_work,
|
thr = (kthread_t *)thread_create(NULL, 0, splat_atomic_work,
|
||||||
@ -157,14 +158,14 @@ splat_atomic_test1(struct file *file, void *arg)
|
|||||||
minclsyspri);
|
minclsyspri);
|
||||||
if (thr == NULL) {
|
if (thr == NULL) {
|
||||||
rc = -ESRCH;
|
rc = -ESRCH;
|
||||||
mutex_unlock(&ap.ap_lock);
|
mutex_exit(&ap.ap_lock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare to wait, the new thread will wake us once it
|
/* Prepare to wait, the new thread will wake us once it
|
||||||
* has made a copy of the unique private passed data */
|
* has made a copy of the unique private passed data */
|
||||||
prepare_to_wait(&ap.ap_waitq, &wait, TASK_UNINTERRUPTIBLE);
|
prepare_to_wait(&ap.ap_waitq, &wait, TASK_UNINTERRUPTIBLE);
|
||||||
mutex_unlock(&ap.ap_lock);
|
mutex_exit(&ap.ap_lock);
|
||||||
schedule();
|
schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +188,8 @@ splat_atomic_test1(struct file *file, void *arg)
|
|||||||
"Success initial and final values match, %lu == %lu\n",
|
"Success initial and final values match, %lu == %lu\n",
|
||||||
(long unsigned)ap.ap_atomic, SPLAT_ATOMIC_INIT_VALUE);
|
(long unsigned)ap.ap_atomic, SPLAT_ATOMIC_INIT_VALUE);
|
||||||
|
|
||||||
|
mutex_destroy(&ap.ap_lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
#include <linux/uaccess.h>
|
#include <linux/uaccess.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/debug.h>
|
#include <sys/debug.h>
|
||||||
|
#include <sys/mutex.h>
|
||||||
#include "splat-internal.h"
|
#include "splat-internal.h"
|
||||||
|
|
||||||
static spl_class *splat_class;
|
static spl_class *splat_class;
|
||||||
@ -71,7 +72,7 @@ splat_open(struct inode *inode, struct file *file)
|
|||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
mutex_init(&info->info_lock);
|
mutex_init(&info->info_lock, SPLAT_NAME, MUTEX_DEFAULT, NULL);
|
||||||
info->info_size = SPLAT_INFO_BUFFER_SIZE;
|
info->info_size = SPLAT_INFO_BUFFER_SIZE;
|
||||||
info->info_buffer = (char *)vmalloc(SPLAT_INFO_BUFFER_SIZE);
|
info->info_buffer = (char *)vmalloc(SPLAT_INFO_BUFFER_SIZE);
|
||||||
if (info->info_buffer == NULL) {
|
if (info->info_buffer == NULL) {
|
||||||
@ -115,10 +116,10 @@ splat_buffer_clear(struct file *file, splat_cfg_t *kcfg, unsigned long arg)
|
|||||||
ASSERT(info);
|
ASSERT(info);
|
||||||
ASSERT(info->info_buffer);
|
ASSERT(info->info_buffer);
|
||||||
|
|
||||||
mutex_lock(&info->info_lock);
|
mutex_enter(&info->info_lock);
|
||||||
memset(info->info_buffer, 0, info->info_size);
|
memset(info->info_buffer, 0, info->info_size);
|
||||||
info->info_head = info->info_buffer;
|
info->info_head = info->info_buffer;
|
||||||
mutex_unlock(&info->info_lock);
|
mutex_exit(&info->info_lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -133,7 +134,7 @@ splat_buffer_size(struct file *file, splat_cfg_t *kcfg, unsigned long arg)
|
|||||||
ASSERT(info);
|
ASSERT(info);
|
||||||
ASSERT(info->info_buffer);
|
ASSERT(info->info_buffer);
|
||||||
|
|
||||||
mutex_lock(&info->info_lock);
|
mutex_enter(&info->info_lock);
|
||||||
if (kcfg->cfg_arg1 > 0) {
|
if (kcfg->cfg_arg1 > 0) {
|
||||||
|
|
||||||
size = kcfg->cfg_arg1;
|
size = kcfg->cfg_arg1;
|
||||||
@ -158,7 +159,7 @@ splat_buffer_size(struct file *file, splat_cfg_t *kcfg, unsigned long arg)
|
|||||||
if (copy_to_user((struct splat_cfg_t __user *)arg, kcfg, sizeof(*kcfg)))
|
if (copy_to_user((struct splat_cfg_t __user *)arg, kcfg, sizeof(*kcfg)))
|
||||||
rc = -EFAULT;
|
rc = -EFAULT;
|
||||||
out:
|
out:
|
||||||
mutex_unlock(&info->info_lock);
|
mutex_exit(&info->info_lock);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -509,7 +510,7 @@ static ssize_t splat_write(struct file *file, const char __user *buf,
|
|||||||
ASSERT(info);
|
ASSERT(info);
|
||||||
ASSERT(info->info_buffer);
|
ASSERT(info->info_buffer);
|
||||||
|
|
||||||
mutex_lock(&info->info_lock);
|
mutex_enter(&info->info_lock);
|
||||||
|
|
||||||
/* Write beyond EOF */
|
/* Write beyond EOF */
|
||||||
if (*ppos >= info->info_size) {
|
if (*ppos >= info->info_size) {
|
||||||
@ -529,7 +530,7 @@ static ssize_t splat_write(struct file *file, const char __user *buf,
|
|||||||
*ppos += count;
|
*ppos += count;
|
||||||
rc = count;
|
rc = count;
|
||||||
out:
|
out:
|
||||||
mutex_unlock(&info->info_lock);
|
mutex_exit(&info->info_lock);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,7 +547,7 @@ static ssize_t splat_read(struct file *file, char __user *buf,
|
|||||||
ASSERT(info);
|
ASSERT(info);
|
||||||
ASSERT(info->info_buffer);
|
ASSERT(info->info_buffer);
|
||||||
|
|
||||||
mutex_lock(&info->info_lock);
|
mutex_enter(&info->info_lock);
|
||||||
|
|
||||||
/* Read beyond EOF */
|
/* Read beyond EOF */
|
||||||
if (*ppos >= info->info_size)
|
if (*ppos >= info->info_size)
|
||||||
@ -564,7 +565,7 @@ static ssize_t splat_read(struct file *file, char __user *buf,
|
|||||||
*ppos += count;
|
*ppos += count;
|
||||||
rc = count;
|
rc = count;
|
||||||
out:
|
out:
|
||||||
mutex_unlock(&info->info_lock);
|
mutex_exit(&info->info_lock);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,7 +581,7 @@ static loff_t splat_seek(struct file *file, loff_t offset, int origin)
|
|||||||
ASSERT(info);
|
ASSERT(info);
|
||||||
ASSERT(info->info_buffer);
|
ASSERT(info->info_buffer);
|
||||||
|
|
||||||
mutex_lock(&info->info_lock);
|
mutex_enter(&info->info_lock);
|
||||||
|
|
||||||
switch (origin) {
|
switch (origin) {
|
||||||
case 0: /* SEEK_SET - No-op just do it */
|
case 0: /* SEEK_SET - No-op just do it */
|
||||||
@ -599,7 +600,7 @@ static loff_t splat_seek(struct file *file, loff_t offset, int origin)
|
|||||||
rc = offset;
|
rc = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&info->info_lock);
|
mutex_exit(&info->info_lock);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "spl-device.h"
|
#include "spl-device.h"
|
||||||
#include "spl-debug.h"
|
#include "spl-debug.h"
|
||||||
#include "splat-ctl.h"
|
#include "splat-ctl.h"
|
||||||
|
#include <sys/mutex.h>
|
||||||
|
|
||||||
#define SPLAT_SUBSYSTEM_INIT(type) \
|
#define SPLAT_SUBSYSTEM_INIT(type) \
|
||||||
({ splat_subsystem_t *_sub_; \
|
({ splat_subsystem_t *_sub_; \
|
||||||
@ -121,7 +122,7 @@ typedef struct splat_subsystem {
|
|||||||
#define SPLAT_INFO_BUFFER_REDZONE 256
|
#define SPLAT_INFO_BUFFER_REDZONE 256
|
||||||
|
|
||||||
typedef struct splat_info {
|
typedef struct splat_info {
|
||||||
struct mutex info_lock;
|
kmutex_t info_lock;
|
||||||
int info_size;
|
int info_size;
|
||||||
char *info_buffer;
|
char *info_buffer;
|
||||||
char *info_head; /* Internal kernel use only */
|
char *info_head; /* Internal kernel use only */
|
||||||
@ -136,7 +137,7 @@ typedef struct splat_info {
|
|||||||
ASSERT(_info_); \
|
ASSERT(_info_); \
|
||||||
ASSERT(_info_->info_buffer); \
|
ASSERT(_info_->info_buffer); \
|
||||||
\
|
\
|
||||||
mutex_lock(&_info_->info_lock); \
|
mutex_enter(&_info_->info_lock); \
|
||||||
\
|
\
|
||||||
/* Don't allow the kernel to start a write in the red zone */ \
|
/* Don't allow the kernel to start a write in the red zone */ \
|
||||||
if ((int)(_info_->info_head - _info_->info_buffer) > \
|
if ((int)(_info_->info_head - _info_->info_buffer) > \
|
||||||
@ -148,7 +149,7 @@ typedef struct splat_info {
|
|||||||
_info_->info_head += _rc_; \
|
_info_->info_head += _rc_; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
mutex_unlock(&_info_->info_lock); \
|
mutex_exit(&_info_->info_lock); \
|
||||||
_rc_; \
|
_rc_; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user