mirror of
https://github.com/joel16/android_kernel_sony_msm8994.git
synced 2024-11-28 06:32:16 +00:00
[DLM] dlm: user locks
This changes the way the dlm handles user locks. The core dlm is now aware of user locks so they can be dealt with more efficiently. There is no more dlm_device module which previously managed its own duplicate copy of every user lock. Signed-off-by: Patrick Caulfield <pcaulfie@redhat.com> Signed-off-by: David Teigland <teigland@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
This commit is contained in:
parent
2eb168ca94
commit
597d0cae0f
@ -10,14 +10,6 @@ config DLM
|
||||
A general purpose distributed lock manager for kernel or userspace
|
||||
applications.
|
||||
|
||||
config DLM_DEVICE
|
||||
tristate "DLM device for userspace access"
|
||||
depends on DLM
|
||||
help
|
||||
This module creates a misc device through which the dlm lockspace
|
||||
and locking functions become available to userspace applications
|
||||
(usually through the libdlm library).
|
||||
|
||||
config DLM_DEBUG
|
||||
bool "DLM debugging"
|
||||
depends on DLM
|
||||
|
@ -1,6 +1,4 @@
|
||||
obj-$(CONFIG_DLM) += dlm.o
|
||||
obj-$(CONFIG_DLM_DEVICE) += dlm_device.o
|
||||
|
||||
dlm-y := ast.o \
|
||||
config.o \
|
||||
dir.o \
|
||||
@ -15,7 +13,7 @@ dlm-y := ast.o \
|
||||
recover.o \
|
||||
recoverd.o \
|
||||
requestqueue.o \
|
||||
user.o \
|
||||
util.o
|
||||
dlm-$(CONFIG_DLM_DEBUG) += debug_fs.o
|
||||
|
||||
dlm_device-y := device.o
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include "dlm_internal.h"
|
||||
#include "lock.h"
|
||||
#include "ast.h"
|
||||
#include "user.h"
|
||||
|
||||
#define WAKE_ASTS 0
|
||||
|
||||
@ -34,6 +34,11 @@ void dlm_del_ast(struct dlm_lkb *lkb)
|
||||
|
||||
void dlm_add_ast(struct dlm_lkb *lkb, int type)
|
||||
{
|
||||
if (lkb->lkb_flags & DLM_IFL_USER) {
|
||||
dlm_user_add_ast(lkb, type);
|
||||
return;
|
||||
}
|
||||
|
||||
spin_lock(&ast_queue_lock);
|
||||
if (!(lkb->lkb_ast_type & (AST_COMP | AST_BAST))) {
|
||||
kref_get(&lkb->lkb_ref);
|
||||
|
1239
fs/dlm/device.c
1239
fs/dlm/device.c
File diff suppressed because it is too large
Load Diff
@ -35,6 +35,7 @@
|
||||
#include <linux/kref.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/jhash.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <asm/semaphore.h>
|
||||
#include <asm/uaccess.h>
|
||||
@ -68,6 +69,7 @@ struct dlm_mhandle;
|
||||
#define log_error(ls, fmt, args...) \
|
||||
printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args)
|
||||
|
||||
#define DLM_LOG_DEBUG
|
||||
#ifdef DLM_LOG_DEBUG
|
||||
#define log_debug(ls, fmt, args...) log_error(ls, fmt, ##args)
|
||||
#else
|
||||
@ -204,6 +206,9 @@ struct dlm_args {
|
||||
|
||||
#define DLM_IFL_MSTCPY 0x00010000
|
||||
#define DLM_IFL_RESEND 0x00020000
|
||||
#define DLM_IFL_DEAD 0x00040000
|
||||
#define DLM_IFL_USER 0x00000001
|
||||
#define DLM_IFL_ORPHAN 0x00000002
|
||||
|
||||
struct dlm_lkb {
|
||||
struct dlm_rsb *lkb_resource; /* the rsb */
|
||||
@ -231,6 +236,7 @@ struct dlm_lkb {
|
||||
struct list_head lkb_rsb_lookup; /* waiting for rsb lookup */
|
||||
struct list_head lkb_wait_reply; /* waiting for remote reply */
|
||||
struct list_head lkb_astqueue; /* need ast to be sent */
|
||||
struct list_head lkb_ownqueue; /* list of locks for a process */
|
||||
|
||||
char *lkb_lvbptr;
|
||||
struct dlm_lksb *lkb_lksb; /* caller's status block */
|
||||
@ -409,6 +415,7 @@ struct rcom_lock {
|
||||
|
||||
struct dlm_ls {
|
||||
struct list_head ls_list; /* list of lockspaces */
|
||||
dlm_lockspace_t *ls_local_handle;
|
||||
uint32_t ls_global_id; /* global unique lockspace ID */
|
||||
uint32_t ls_exflags;
|
||||
int ls_lvblen;
|
||||
@ -444,6 +451,8 @@ struct dlm_ls {
|
||||
wait_queue_head_t ls_uevent_wait; /* user part of join/leave */
|
||||
int ls_uevent_result;
|
||||
|
||||
struct miscdevice ls_device;
|
||||
|
||||
/* recovery related */
|
||||
|
||||
struct timer_list ls_timer;
|
||||
@ -461,6 +470,7 @@ struct dlm_ls {
|
||||
spinlock_t ls_recover_list_lock;
|
||||
int ls_recover_list_count;
|
||||
wait_queue_head_t ls_wait_general;
|
||||
struct mutex ls_clear_proc_locks;
|
||||
|
||||
struct list_head ls_root_list; /* root resources */
|
||||
struct rw_semaphore ls_root_sem; /* protect root_list */
|
||||
@ -475,6 +485,40 @@ struct dlm_ls {
|
||||
#define LSFL_RCOM_READY 3
|
||||
#define LSFL_UEVENT_WAIT 4
|
||||
|
||||
/* much of this is just saving user space pointers associated with the
|
||||
lock that we pass back to the user lib with an ast */
|
||||
|
||||
struct dlm_user_args {
|
||||
struct dlm_user_proc *proc; /* each process that opens the lockspace
|
||||
device has private data
|
||||
(dlm_user_proc) on the struct file,
|
||||
the process's locks point back to it*/
|
||||
struct dlm_lksb lksb;
|
||||
int old_mode;
|
||||
int update_user_lvb;
|
||||
struct dlm_lksb __user *user_lksb;
|
||||
void __user *castparam;
|
||||
void __user *castaddr;
|
||||
void __user *bastparam;
|
||||
void __user *bastaddr;
|
||||
};
|
||||
|
||||
#define DLM_PROC_FLAGS_CLOSING 1
|
||||
#define DLM_PROC_FLAGS_COMPAT 2
|
||||
|
||||
/* locks list is kept so we can remove all a process's locks when it
|
||||
exits (or orphan those that are persistent) */
|
||||
|
||||
struct dlm_user_proc {
|
||||
dlm_lockspace_t *lockspace;
|
||||
unsigned long flags; /* DLM_PROC_FLAGS */
|
||||
struct list_head asts;
|
||||
spinlock_t asts_spin;
|
||||
struct list_head locks;
|
||||
spinlock_t locks_spin;
|
||||
wait_queue_head_t wait;
|
||||
};
|
||||
|
||||
static inline int dlm_locking_stopped(struct dlm_ls *ls)
|
||||
{
|
||||
return !test_bit(LSFL_RUNNING, &ls->ls_flags);
|
||||
|
304
fs/dlm/lock.c
304
fs/dlm/lock.c
@ -55,8 +55,9 @@
|
||||
R: do_xxxx()
|
||||
L: receive_xxxx_reply() <- R: send_xxxx_reply()
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
#include "dlm_internal.h"
|
||||
#include <linux/dlm_device.h>
|
||||
#include "memory.h"
|
||||
#include "lowcomms.h"
|
||||
#include "requestqueue.h"
|
||||
@ -69,6 +70,7 @@
|
||||
#include "rcom.h"
|
||||
#include "recover.h"
|
||||
#include "lvb_table.h"
|
||||
#include "user.h"
|
||||
#include "config.h"
|
||||
|
||||
static int send_request(struct dlm_rsb *r, struct dlm_lkb *lkb);
|
||||
@ -84,6 +86,8 @@ static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb,
|
||||
struct dlm_message *ms);
|
||||
static int receive_extralen(struct dlm_message *ms);
|
||||
|
||||
#define FAKE_USER_AST (void*)0xff00ff00
|
||||
|
||||
/*
|
||||
* Lock compatibilty matrix - thanks Steve
|
||||
* UN = Unlocked state. Not really a state, used as a flag
|
||||
@ -152,7 +156,7 @@ static const int __quecvt_compat_matrix[8][8] = {
|
||||
{0, 0, 0, 0, 0, 0, 0, 0} /* PD */
|
||||
};
|
||||
|
||||
static void dlm_print_lkb(struct dlm_lkb *lkb)
|
||||
void dlm_print_lkb(struct dlm_lkb *lkb)
|
||||
{
|
||||
printk(KERN_ERR "lkb: nodeid %d id %x remid %x exflags %x flags %x\n"
|
||||
" status %d rqmode %d grmode %d wait_type %d ast_type %d\n",
|
||||
@ -291,7 +295,7 @@ static int search_rsb_list(struct list_head *head, char *name, int len,
|
||||
if (len == r->res_length && !memcmp(name, r->res_name, len))
|
||||
goto found;
|
||||
}
|
||||
return -ENOENT;
|
||||
return -EBADR;
|
||||
|
||||
found:
|
||||
if (r->res_nodeid && (flags & R_MASTER))
|
||||
@ -376,7 +380,7 @@ static int find_rsb(struct dlm_ls *ls, char *name, int namelen,
|
||||
if (!error)
|
||||
goto out;
|
||||
|
||||
if (error == -ENOENT && !(flags & R_CREATE))
|
||||
if (error == -EBADR && !(flags & R_CREATE))
|
||||
goto out;
|
||||
|
||||
/* the rsb was found but wasn't a master copy */
|
||||
@ -920,7 +924,7 @@ static void set_lvb_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb,
|
||||
if (!(lkb->lkb_exflags & DLM_LKF_VALBLK))
|
||||
return;
|
||||
|
||||
b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1];
|
||||
b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1];
|
||||
if (b == 1) {
|
||||
int len = receive_extralen(ms);
|
||||
memcpy(lkb->lkb_lvbptr, ms->m_extra, len);
|
||||
@ -963,6 +967,8 @@ static void revert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb)
|
||||
lkb->lkb_rqmode = DLM_LOCK_IV;
|
||||
|
||||
switch (lkb->lkb_status) {
|
||||
case DLM_LKSTS_GRANTED:
|
||||
break;
|
||||
case DLM_LKSTS_CONVERT:
|
||||
move_lkb(r, lkb, DLM_LKSTS_GRANTED);
|
||||
break;
|
||||
@ -1727,6 +1733,11 @@ static int do_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb)
|
||||
return -DLM_EUNLOCK;
|
||||
}
|
||||
|
||||
/* FIXME: if revert_lock() finds that the lkb is granted, we should
|
||||
skip the queue_cast(ECANCEL). It indicates that the request/convert
|
||||
completed (and queued a normal ast) just before the cancel; we don't
|
||||
want to clobber the sb_result for the normal ast with ECANCEL. */
|
||||
|
||||
static int do_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb)
|
||||
{
|
||||
revert_lock(r, lkb);
|
||||
@ -2739,7 +2750,7 @@ static void receive_request_reply(struct dlm_ls *ls, struct dlm_message *ms)
|
||||
confirm_master(r, error);
|
||||
break;
|
||||
|
||||
case -ENOENT:
|
||||
case -EBADR:
|
||||
case -ENOTBLK:
|
||||
/* find_rsb failed to find rsb or rsb wasn't master */
|
||||
r->res_nodeid = -1;
|
||||
@ -3545,3 +3556,284 @@ int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua,
|
||||
int mode, uint32_t flags, void *name, unsigned int namelen,
|
||||
uint32_t parent_lkid)
|
||||
{
|
||||
struct dlm_lkb *lkb;
|
||||
struct dlm_args args;
|
||||
int error;
|
||||
|
||||
lock_recovery(ls);
|
||||
|
||||
error = create_lkb(ls, &lkb);
|
||||
if (error) {
|
||||
kfree(ua);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (flags & DLM_LKF_VALBLK) {
|
||||
ua->lksb.sb_lvbptr = kmalloc(DLM_USER_LVB_LEN, GFP_KERNEL);
|
||||
if (!ua->lksb.sb_lvbptr) {
|
||||
kfree(ua);
|
||||
__put_lkb(ls, lkb);
|
||||
error = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* After ua is attached to lkb it will be freed by free_lkb().
|
||||
When DLM_IFL_USER is set, the dlm knows that this is a userspace
|
||||
lock and that lkb_astparam is the dlm_user_args structure. */
|
||||
|
||||
error = set_lock_args(mode, &ua->lksb, flags, namelen, parent_lkid,
|
||||
FAKE_USER_AST, ua, FAKE_USER_AST, &args);
|
||||
lkb->lkb_flags |= DLM_IFL_USER;
|
||||
ua->old_mode = DLM_LOCK_IV;
|
||||
|
||||
if (error) {
|
||||
__put_lkb(ls, lkb);
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = request_lock(ls, lkb, name, namelen, &args);
|
||||
|
||||
switch (error) {
|
||||
case 0:
|
||||
break;
|
||||
case -EINPROGRESS:
|
||||
error = 0;
|
||||
break;
|
||||
case -EAGAIN:
|
||||
error = 0;
|
||||
/* fall through */
|
||||
default:
|
||||
__put_lkb(ls, lkb);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* add this new lkb to the per-process list of locks */
|
||||
spin_lock(&ua->proc->locks_spin);
|
||||
kref_get(&lkb->lkb_ref);
|
||||
list_add_tail(&lkb->lkb_ownqueue, &ua->proc->locks);
|
||||
spin_unlock(&ua->proc->locks_spin);
|
||||
out:
|
||||
unlock_recovery(ls);
|
||||
return error;
|
||||
}
|
||||
|
||||
int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
|
||||
int mode, uint32_t flags, uint32_t lkid, char *lvb_in)
|
||||
{
|
||||
struct dlm_lkb *lkb;
|
||||
struct dlm_args args;
|
||||
struct dlm_user_args *ua;
|
||||
int error;
|
||||
|
||||
lock_recovery(ls);
|
||||
|
||||
error = find_lkb(ls, lkid, &lkb);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
/* user can change the params on its lock when it converts it, or
|
||||
add an lvb that didn't exist before */
|
||||
|
||||
ua = (struct dlm_user_args *)lkb->lkb_astparam;
|
||||
|
||||
if (flags & DLM_LKF_VALBLK && !ua->lksb.sb_lvbptr) {
|
||||
ua->lksb.sb_lvbptr = kmalloc(DLM_USER_LVB_LEN, GFP_KERNEL);
|
||||
if (!ua->lksb.sb_lvbptr) {
|
||||
error = -ENOMEM;
|
||||
goto out_put;
|
||||
}
|
||||
}
|
||||
if (lvb_in && ua->lksb.sb_lvbptr)
|
||||
memcpy(ua->lksb.sb_lvbptr, lvb_in, DLM_USER_LVB_LEN);
|
||||
|
||||
ua->castparam = ua_tmp->castparam;
|
||||
ua->castaddr = ua_tmp->castaddr;
|
||||
ua->bastparam = ua_tmp->bastparam;
|
||||
ua->bastaddr = ua_tmp->bastaddr;
|
||||
ua->old_mode = lkb->lkb_grmode;
|
||||
|
||||
error = set_lock_args(mode, &ua->lksb, flags, 0, 0, FAKE_USER_AST, ua,
|
||||
FAKE_USER_AST, &args);
|
||||
if (error)
|
||||
goto out_put;
|
||||
|
||||
error = convert_lock(ls, lkb, &args);
|
||||
|
||||
if (error == -EINPROGRESS || error == -EAGAIN)
|
||||
error = 0;
|
||||
out_put:
|
||||
dlm_put_lkb(lkb);
|
||||
out:
|
||||
unlock_recovery(ls);
|
||||
kfree(ua_tmp);
|
||||
return error;
|
||||
}
|
||||
|
||||
int dlm_user_unlock(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
|
||||
uint32_t flags, uint32_t lkid, char *lvb_in)
|
||||
{
|
||||
struct dlm_lkb *lkb;
|
||||
struct dlm_args args;
|
||||
struct dlm_user_args *ua;
|
||||
int error;
|
||||
|
||||
lock_recovery(ls);
|
||||
|
||||
error = find_lkb(ls, lkid, &lkb);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
ua = (struct dlm_user_args *)lkb->lkb_astparam;
|
||||
|
||||
if (lvb_in && ua->lksb.sb_lvbptr)
|
||||
memcpy(ua->lksb.sb_lvbptr, lvb_in, DLM_USER_LVB_LEN);
|
||||
ua->castparam = ua_tmp->castparam;
|
||||
|
||||
error = set_unlock_args(flags, ua, &args);
|
||||
if (error)
|
||||
goto out_put;
|
||||
|
||||
error = unlock_lock(ls, lkb, &args);
|
||||
|
||||
if (error == -DLM_EUNLOCK)
|
||||
error = 0;
|
||||
if (error)
|
||||
goto out_put;
|
||||
|
||||
spin_lock(&ua->proc->locks_spin);
|
||||
list_del(&lkb->lkb_ownqueue);
|
||||
spin_unlock(&ua->proc->locks_spin);
|
||||
|
||||
/* this removes the reference for the proc->locks list added by
|
||||
dlm_user_request */
|
||||
unhold_lkb(lkb);
|
||||
out_put:
|
||||
dlm_put_lkb(lkb);
|
||||
out:
|
||||
unlock_recovery(ls);
|
||||
return error;
|
||||
}
|
||||
|
||||
int dlm_user_cancel(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
|
||||
uint32_t flags, uint32_t lkid)
|
||||
{
|
||||
struct dlm_lkb *lkb;
|
||||
struct dlm_args args;
|
||||
struct dlm_user_args *ua;
|
||||
int error;
|
||||
|
||||
lock_recovery(ls);
|
||||
|
||||
error = find_lkb(ls, lkid, &lkb);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
ua = (struct dlm_user_args *)lkb->lkb_astparam;
|
||||
ua->castparam = ua_tmp->castparam;
|
||||
|
||||
error = set_unlock_args(flags, ua, &args);
|
||||
if (error)
|
||||
goto out_put;
|
||||
|
||||
error = cancel_lock(ls, lkb, &args);
|
||||
|
||||
if (error == -DLM_ECANCEL)
|
||||
error = 0;
|
||||
if (error)
|
||||
goto out_put;
|
||||
|
||||
/* this lkb was removed from the WAITING queue */
|
||||
if (lkb->lkb_grmode == DLM_LOCK_IV) {
|
||||
spin_lock(&ua->proc->locks_spin);
|
||||
list_del(&lkb->lkb_ownqueue);
|
||||
spin_unlock(&ua->proc->locks_spin);
|
||||
unhold_lkb(lkb);
|
||||
}
|
||||
out_put:
|
||||
dlm_put_lkb(lkb);
|
||||
out:
|
||||
unlock_recovery(ls);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int orphan_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb)
|
||||
{
|
||||
struct dlm_user_args *ua = (struct dlm_user_args *)lkb->lkb_astparam;
|
||||
|
||||
if (ua->lksb.sb_lvbptr)
|
||||
kfree(ua->lksb.sb_lvbptr);
|
||||
kfree(ua);
|
||||
lkb->lkb_astparam = (long)NULL;
|
||||
|
||||
/* TODO: propogate to master if needed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The force flag allows the unlock to go ahead even if the lkb isn't granted.
|
||||
Regardless of what rsb queue the lock is on, it's removed and freed. */
|
||||
|
||||
static int unlock_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb)
|
||||
{
|
||||
struct dlm_user_args *ua = (struct dlm_user_args *)lkb->lkb_astparam;
|
||||
struct dlm_args args;
|
||||
int error;
|
||||
|
||||
/* FIXME: we need to handle the case where the lkb is in limbo
|
||||
while the rsb is being looked up, currently we assert in
|
||||
_unlock_lock/is_remote because rsb nodeid is -1. */
|
||||
|
||||
set_unlock_args(DLM_LKF_FORCEUNLOCK, ua, &args);
|
||||
|
||||
error = unlock_lock(ls, lkb, &args);
|
||||
if (error == -DLM_EUNLOCK)
|
||||
error = 0;
|
||||
return error;
|
||||
}
|
||||
|
||||
/* The ls_clear_proc_locks mutex protects against dlm_user_add_asts() which
|
||||
1) references lkb->ua which we free here and 2) adds lkbs to proc->asts,
|
||||
which we clear here. */
|
||||
|
||||
/* proc CLOSING flag is set so no more device_reads should look at proc->asts
|
||||
list, and no more device_writes should add lkb's to proc->locks list; so we
|
||||
shouldn't need to take asts_spin or locks_spin here. this assumes that
|
||||
device reads/writes/closes are serialized -- FIXME: we may need to serialize
|
||||
them ourself. */
|
||||
|
||||
void dlm_clear_proc_locks(struct dlm_ls *ls, struct dlm_user_proc *proc)
|
||||
{
|
||||
struct dlm_lkb *lkb, *safe;
|
||||
|
||||
lock_recovery(ls);
|
||||
mutex_lock(&ls->ls_clear_proc_locks);
|
||||
|
||||
list_for_each_entry_safe(lkb, safe, &proc->locks, lkb_ownqueue) {
|
||||
if (lkb->lkb_ast_type) {
|
||||
list_del(&lkb->lkb_astqueue);
|
||||
unhold_lkb(lkb);
|
||||
}
|
||||
|
||||
list_del(&lkb->lkb_ownqueue);
|
||||
|
||||
if (lkb->lkb_exflags & DLM_LKF_PERSISTENT) {
|
||||
lkb->lkb_flags |= DLM_IFL_ORPHAN;
|
||||
orphan_proc_lock(ls, lkb);
|
||||
} else {
|
||||
lkb->lkb_flags |= DLM_IFL_DEAD;
|
||||
unlock_proc_lock(ls, lkb);
|
||||
}
|
||||
|
||||
/* this removes the reference for the proc->locks list
|
||||
added by dlm_user_request, it may result in the lkb
|
||||
being freed */
|
||||
|
||||
dlm_put_lkb(lkb);
|
||||
}
|
||||
mutex_unlock(&ls->ls_clear_proc_locks);
|
||||
unlock_recovery(ls);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#define __LOCK_DOT_H__
|
||||
|
||||
void dlm_print_rsb(struct dlm_rsb *r);
|
||||
void dlm_print_lkb(struct dlm_lkb *lkb);
|
||||
int dlm_receive_message(struct dlm_header *hd, int nodeid, int recovery);
|
||||
int dlm_modes_compat(int mode1, int mode2);
|
||||
int dlm_find_rsb(struct dlm_ls *ls, char *name, int namelen,
|
||||
@ -31,6 +32,16 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls);
|
||||
int dlm_recover_master_copy(struct dlm_ls *ls, struct dlm_rcom *rc);
|
||||
int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc);
|
||||
|
||||
int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua, int mode,
|
||||
uint32_t flags, void *name, unsigned int namelen, uint32_t parent_lkid);
|
||||
int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
|
||||
int mode, uint32_t flags, uint32_t lkid, char *lvb_in);
|
||||
int dlm_user_unlock(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
|
||||
uint32_t flags, uint32_t lkid, char *lvb_in);
|
||||
int dlm_user_cancel(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
|
||||
uint32_t flags, uint32_t lkid);
|
||||
void dlm_clear_proc_locks(struct dlm_ls *ls, struct dlm_user_proc *proc);
|
||||
|
||||
static inline int is_master(struct dlm_rsb *r)
|
||||
{
|
||||
return !r->res_nodeid;
|
||||
|
@ -270,12 +270,36 @@ struct dlm_ls *dlm_find_lockspace_global(uint32_t id)
|
||||
return ls;
|
||||
}
|
||||
|
||||
struct dlm_ls *dlm_find_lockspace_local(void *id)
|
||||
struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace_t *lockspace)
|
||||
{
|
||||
struct dlm_ls *ls = id;
|
||||
struct dlm_ls *ls;
|
||||
|
||||
spin_lock(&lslist_lock);
|
||||
ls->ls_count++;
|
||||
list_for_each_entry(ls, &lslist, ls_list) {
|
||||
if (ls->ls_local_handle == lockspace) {
|
||||
ls->ls_count++;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
ls = NULL;
|
||||
out:
|
||||
spin_unlock(&lslist_lock);
|
||||
return ls;
|
||||
}
|
||||
|
||||
struct dlm_ls *dlm_find_lockspace_device(int minor)
|
||||
{
|
||||
struct dlm_ls *ls;
|
||||
|
||||
spin_lock(&lslist_lock);
|
||||
list_for_each_entry(ls, &lslist, ls_list) {
|
||||
if (ls->ls_device.minor == minor) {
|
||||
ls->ls_count++;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
ls = NULL;
|
||||
out:
|
||||
spin_unlock(&lslist_lock);
|
||||
return ls;
|
||||
}
|
||||
@ -436,6 +460,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
|
||||
init_rwsem(&ls->ls_in_recovery);
|
||||
INIT_LIST_HEAD(&ls->ls_requestqueue);
|
||||
mutex_init(&ls->ls_requestqueue_mutex);
|
||||
mutex_init(&ls->ls_clear_proc_locks);
|
||||
|
||||
ls->ls_recover_buf = kmalloc(dlm_config.buffer_size, GFP_KERNEL);
|
||||
if (!ls->ls_recover_buf)
|
||||
@ -444,6 +469,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
|
||||
INIT_LIST_HEAD(&ls->ls_recover_list);
|
||||
spin_lock_init(&ls->ls_recover_list_lock);
|
||||
ls->ls_recover_list_count = 0;
|
||||
ls->ls_local_handle = ls;
|
||||
init_waitqueue_head(&ls->ls_wait_general);
|
||||
INIT_LIST_HEAD(&ls->ls_root_list);
|
||||
init_rwsem(&ls->ls_root_sem);
|
||||
|
@ -18,6 +18,7 @@ int dlm_lockspace_init(void);
|
||||
void dlm_lockspace_exit(void);
|
||||
struct dlm_ls *dlm_find_lockspace_global(uint32_t id);
|
||||
struct dlm_ls *dlm_find_lockspace_local(void *id);
|
||||
struct dlm_ls *dlm_find_lockspace_device(int minor);
|
||||
void dlm_put_lockspace(struct dlm_ls *ls);
|
||||
|
||||
#endif /* __LOCKSPACE_DOT_H__ */
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "dlm_internal.h"
|
||||
#include "lockspace.h"
|
||||
#include "lock.h"
|
||||
#include "user.h"
|
||||
#include "memory.h"
|
||||
#include "lowcomms.h"
|
||||
#include "config.h"
|
||||
@ -50,10 +51,16 @@ static int __init init_dlm(void)
|
||||
if (error)
|
||||
goto out_debug;
|
||||
|
||||
error = dlm_user_init();
|
||||
if (error)
|
||||
goto out_lowcomms;
|
||||
|
||||
printk("DLM (built %s %s) installed\n", __DATE__, __TIME__);
|
||||
|
||||
return 0;
|
||||
|
||||
out_lowcomms:
|
||||
dlm_lowcomms_exit();
|
||||
out_debug:
|
||||
dlm_unregister_debugfs();
|
||||
out_config:
|
||||
@ -68,6 +75,7 @@ static int __init init_dlm(void)
|
||||
|
||||
static void __exit exit_dlm(void)
|
||||
{
|
||||
dlm_user_exit();
|
||||
dlm_lowcomms_exit();
|
||||
dlm_config_exit();
|
||||
dlm_memory_exit();
|
||||
|
@ -84,6 +84,15 @@ struct dlm_lkb *allocate_lkb(struct dlm_ls *ls)
|
||||
|
||||
void free_lkb(struct dlm_lkb *lkb)
|
||||
{
|
||||
if (lkb->lkb_flags & DLM_IFL_USER) {
|
||||
struct dlm_user_args *ua;
|
||||
ua = (struct dlm_user_args *)lkb->lkb_astparam;
|
||||
if (ua) {
|
||||
if (ua->lksb.sb_lvbptr)
|
||||
kfree(ua->lksb.sb_lvbptr);
|
||||
kfree(ua);
|
||||
}
|
||||
}
|
||||
kmem_cache_free(lkb_cache, lkb);
|
||||
}
|
||||
|
||||
|
769
fs/dlm/user.c
Normal file
769
fs/dlm/user.c
Normal file
@ -0,0 +1,769 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use,
|
||||
* modify, copy, or redistribute it subject to the terms and conditions
|
||||
* of the GNU General Public License v.2.
|
||||
*/
|
||||
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/wait.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/poll.h>
|
||||
#include <linux/signal.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/dlm.h>
|
||||
#include <linux/dlm_device.h>
|
||||
|
||||
#include "dlm_internal.h"
|
||||
#include "lockspace.h"
|
||||
#include "lock.h"
|
||||
#include "lvb_table.h"
|
||||
|
||||
static const char *name_prefix="dlm";
|
||||
static struct miscdevice ctl_device;
|
||||
static struct file_operations device_fops;
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
|
||||
struct dlm_lock_params32 {
|
||||
__u8 mode;
|
||||
__u8 namelen;
|
||||
__u16 flags;
|
||||
__u32 lkid;
|
||||
__u32 parent;
|
||||
|
||||
__u32 castparam;
|
||||
__u32 castaddr;
|
||||
__u32 bastparam;
|
||||
__u32 bastaddr;
|
||||
__u32 lksb;
|
||||
|
||||
char lvb[DLM_USER_LVB_LEN];
|
||||
char name[0];
|
||||
};
|
||||
|
||||
struct dlm_write_request32 {
|
||||
__u32 version[3];
|
||||
__u8 cmd;
|
||||
__u8 is64bit;
|
||||
__u8 unused[2];
|
||||
|
||||
union {
|
||||
struct dlm_lock_params32 lock;
|
||||
struct dlm_lspace_params lspace;
|
||||
} i;
|
||||
};
|
||||
|
||||
struct dlm_lksb32 {
|
||||
__u32 sb_status;
|
||||
__u32 sb_lkid;
|
||||
__u8 sb_flags;
|
||||
__u32 sb_lvbptr;
|
||||
};
|
||||
|
||||
struct dlm_lock_result32 {
|
||||
__u32 length;
|
||||
__u32 user_astaddr;
|
||||
__u32 user_astparam;
|
||||
__u32 user_lksb;
|
||||
struct dlm_lksb32 lksb;
|
||||
__u8 bast_mode;
|
||||
__u8 unused[3];
|
||||
/* Offsets may be zero if no data is present */
|
||||
__u32 lvb_offset;
|
||||
};
|
||||
|
||||
static void compat_input(struct dlm_write_request *kb,
|
||||
struct dlm_write_request32 *kb32)
|
||||
{
|
||||
kb->version[0] = kb32->version[0];
|
||||
kb->version[1] = kb32->version[1];
|
||||
kb->version[2] = kb32->version[2];
|
||||
|
||||
kb->cmd = kb32->cmd;
|
||||
kb->is64bit = kb32->is64bit;
|
||||
if (kb->cmd == DLM_USER_CREATE_LOCKSPACE ||
|
||||
kb->cmd == DLM_USER_REMOVE_LOCKSPACE) {
|
||||
kb->i.lspace.flags = kb32->i.lspace.flags;
|
||||
kb->i.lspace.minor = kb32->i.lspace.minor;
|
||||
strcpy(kb->i.lspace.name, kb32->i.lspace.name);
|
||||
} else {
|
||||
kb->i.lock.mode = kb32->i.lock.mode;
|
||||
kb->i.lock.namelen = kb32->i.lock.namelen;
|
||||
kb->i.lock.flags = kb32->i.lock.flags;
|
||||
kb->i.lock.lkid = kb32->i.lock.lkid;
|
||||
kb->i.lock.parent = kb32->i.lock.parent;
|
||||
kb->i.lock.castparam = (void *)(long)kb32->i.lock.castparam;
|
||||
kb->i.lock.castaddr = (void *)(long)kb32->i.lock.castaddr;
|
||||
kb->i.lock.bastparam = (void *)(long)kb32->i.lock.bastparam;
|
||||
kb->i.lock.bastaddr = (void *)(long)kb32->i.lock.bastaddr;
|
||||
kb->i.lock.lksb = (void *)(long)kb32->i.lock.lksb;
|
||||
memcpy(kb->i.lock.lvb, kb32->i.lock.lvb, DLM_USER_LVB_LEN);
|
||||
memcpy(kb->i.lock.name, kb32->i.lock.name, kb->i.lock.namelen);
|
||||
}
|
||||
}
|
||||
|
||||
static void compat_output(struct dlm_lock_result *res,
|
||||
struct dlm_lock_result32 *res32)
|
||||
{
|
||||
res32->length = res->length - (sizeof(struct dlm_lock_result) -
|
||||
sizeof(struct dlm_lock_result32));
|
||||
res32->user_astaddr = (__u32)(long)res->user_astaddr;
|
||||
res32->user_astparam = (__u32)(long)res->user_astparam;
|
||||
res32->user_lksb = (__u32)(long)res->user_lksb;
|
||||
res32->bast_mode = res->bast_mode;
|
||||
|
||||
res32->lvb_offset = res->lvb_offset;
|
||||
res32->length = res->length;
|
||||
|
||||
res32->lksb.sb_status = res->lksb.sb_status;
|
||||
res32->lksb.sb_flags = res->lksb.sb_flags;
|
||||
res32->lksb.sb_lkid = res->lksb.sb_lkid;
|
||||
res32->lksb.sb_lvbptr = (__u32)(long)res->lksb.sb_lvbptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void dlm_user_add_ast(struct dlm_lkb *lkb, int type)
|
||||
{
|
||||
struct dlm_ls *ls;
|
||||
struct dlm_user_args *ua;
|
||||
struct dlm_user_proc *proc;
|
||||
|
||||
/* dlm_clear_proc_locks() sets ORPHAN/DEAD flag on each
|
||||
lkb before dealing with it. We need to check this
|
||||
flag before taking ls_clear_proc_locks mutex because if
|
||||
it's set, dlm_clear_proc_locks() holds the mutex. */
|
||||
|
||||
if (lkb->lkb_flags & (DLM_IFL_ORPHAN | DLM_IFL_DEAD)) {
|
||||
/* log_print("user_add_ast skip1 %x", lkb->lkb_flags); */
|
||||
return;
|
||||
}
|
||||
|
||||
ls = lkb->lkb_resource->res_ls;
|
||||
mutex_lock(&ls->ls_clear_proc_locks);
|
||||
|
||||
/* If ORPHAN/DEAD flag is set, it means the process is dead so an ast
|
||||
can't be delivered. For ORPHAN's, dlm_clear_proc_locks() freed
|
||||
lkb->ua so we can't try to use it. */
|
||||
|
||||
if (lkb->lkb_flags & (DLM_IFL_ORPHAN | DLM_IFL_DEAD)) {
|
||||
/* log_print("user_add_ast skip2 %x", lkb->lkb_flags); */
|
||||
goto out;
|
||||
}
|
||||
|
||||
DLM_ASSERT(lkb->lkb_astparam, dlm_print_lkb(lkb););
|
||||
ua = (struct dlm_user_args *)lkb->lkb_astparam;
|
||||
proc = ua->proc;
|
||||
|
||||
if (type == AST_BAST && ua->bastaddr == NULL)
|
||||
goto out;
|
||||
|
||||
spin_lock(&proc->asts_spin);
|
||||
if (!(lkb->lkb_ast_type & (AST_COMP | AST_BAST))) {
|
||||
kref_get(&lkb->lkb_ref);
|
||||
list_add_tail(&lkb->lkb_astqueue, &proc->asts);
|
||||
lkb->lkb_ast_type |= type;
|
||||
wake_up_interruptible(&proc->wait);
|
||||
}
|
||||
|
||||
/* We want to copy the lvb to userspace when the completion
|
||||
ast is read if the status is 0, the lock has an lvb and
|
||||
lvb_ops says we should. We could probably have set_lvb_lock()
|
||||
set update_user_lvb instead and not need old_mode */
|
||||
|
||||
if ((lkb->lkb_ast_type & AST_COMP) &&
|
||||
(lkb->lkb_lksb->sb_status == 0) &&
|
||||
lkb->lkb_lksb->sb_lvbptr &&
|
||||
dlm_lvb_operations[ua->old_mode + 1][lkb->lkb_grmode + 1])
|
||||
ua->update_user_lvb = 1;
|
||||
else
|
||||
ua->update_user_lvb = 0;
|
||||
|
||||
spin_unlock(&proc->asts_spin);
|
||||
out:
|
||||
mutex_unlock(&ls->ls_clear_proc_locks);
|
||||
}
|
||||
|
||||
static int device_user_lock(struct dlm_user_proc *proc,
|
||||
struct dlm_lock_params *params)
|
||||
{
|
||||
struct dlm_ls *ls;
|
||||
struct dlm_user_args *ua;
|
||||
int error = -ENOMEM;
|
||||
|
||||
ls = dlm_find_lockspace_local(proc->lockspace);
|
||||
if (!ls)
|
||||
return -ENOENT;
|
||||
|
||||
if (!params->castaddr || !params->lksb) {
|
||||
error = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ua = kzalloc(sizeof(struct dlm_user_args), GFP_KERNEL);
|
||||
if (!ua)
|
||||
goto out;
|
||||
ua->proc = proc;
|
||||
ua->user_lksb = params->lksb;
|
||||
ua->castparam = params->castparam;
|
||||
ua->castaddr = params->castaddr;
|
||||
ua->bastparam = params->bastparam;
|
||||
ua->bastaddr = params->bastaddr;
|
||||
|
||||
if (params->flags & DLM_LKF_CONVERT)
|
||||
error = dlm_user_convert(ls, ua,
|
||||
params->mode, params->flags,
|
||||
params->lkid, params->lvb);
|
||||
else {
|
||||
error = dlm_user_request(ls, ua,
|
||||
params->mode, params->flags,
|
||||
params->name, params->namelen,
|
||||
params->parent);
|
||||
if (!error)
|
||||
error = ua->lksb.sb_lkid;
|
||||
}
|
||||
out:
|
||||
dlm_put_lockspace(ls);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int device_user_unlock(struct dlm_user_proc *proc,
|
||||
struct dlm_lock_params *params)
|
||||
{
|
||||
struct dlm_ls *ls;
|
||||
struct dlm_user_args *ua;
|
||||
int error = -ENOMEM;
|
||||
|
||||
ls = dlm_find_lockspace_local(proc->lockspace);
|
||||
if (!ls)
|
||||
return -ENOENT;
|
||||
|
||||
ua = kzalloc(sizeof(struct dlm_user_args), GFP_KERNEL);
|
||||
if (!ua)
|
||||
goto out;
|
||||
ua->proc = proc;
|
||||
ua->user_lksb = params->lksb;
|
||||
ua->castparam = params->castparam;
|
||||
ua->castaddr = params->castaddr;
|
||||
|
||||
if (params->flags & DLM_LKF_CANCEL)
|
||||
error = dlm_user_cancel(ls, ua, params->flags, params->lkid);
|
||||
else
|
||||
error = dlm_user_unlock(ls, ua, params->flags, params->lkid,
|
||||
params->lvb);
|
||||
out:
|
||||
dlm_put_lockspace(ls);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int device_create_lockspace(struct dlm_lspace_params *params)
|
||||
{
|
||||
dlm_lockspace_t *lockspace;
|
||||
struct dlm_ls *ls;
|
||||
int error, len;
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EPERM;
|
||||
|
||||
error = dlm_new_lockspace(params->name, strlen(params->name),
|
||||
&lockspace, 0, DLM_USER_LVB_LEN);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
ls = dlm_find_lockspace_local(lockspace);
|
||||
if (!ls)
|
||||
return -ENOENT;
|
||||
|
||||
error = -ENOMEM;
|
||||
len = strlen(params->name) + strlen(name_prefix) + 2;
|
||||
ls->ls_device.name = kzalloc(len, GFP_KERNEL);
|
||||
if (!ls->ls_device.name)
|
||||
goto fail;
|
||||
snprintf((char *)ls->ls_device.name, len, "%s_%s", name_prefix,
|
||||
params->name);
|
||||
ls->ls_device.fops = &device_fops;
|
||||
ls->ls_device.minor = MISC_DYNAMIC_MINOR;
|
||||
|
||||
error = misc_register(&ls->ls_device);
|
||||
if (error) {
|
||||
kfree(ls->ls_device.name);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
error = ls->ls_device.minor;
|
||||
dlm_put_lockspace(ls);
|
||||
return error;
|
||||
|
||||
fail:
|
||||
dlm_put_lockspace(ls);
|
||||
dlm_release_lockspace(lockspace, 0);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int device_remove_lockspace(struct dlm_lspace_params *params)
|
||||
{
|
||||
dlm_lockspace_t *lockspace;
|
||||
struct dlm_ls *ls;
|
||||
int error;
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EPERM;
|
||||
|
||||
ls = dlm_find_lockspace_device(params->minor);
|
||||
if (!ls)
|
||||
return -ENOENT;
|
||||
|
||||
error = misc_deregister(&ls->ls_device);
|
||||
if (error) {
|
||||
dlm_put_lockspace(ls);
|
||||
goto out;
|
||||
}
|
||||
kfree(ls->ls_device.name);
|
||||
|
||||
lockspace = ls->ls_local_handle;
|
||||
|
||||
/* dlm_release_lockspace waits for references to go to zero,
|
||||
so all processes will need to close their device for the ls
|
||||
before the release will procede */
|
||||
|
||||
dlm_put_lockspace(ls);
|
||||
error = dlm_release_lockspace(lockspace, 0);
|
||||
out:
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Check the user's version matches ours */
|
||||
static int check_version(struct dlm_write_request *req)
|
||||
{
|
||||
if (req->version[0] != DLM_DEVICE_VERSION_MAJOR ||
|
||||
(req->version[0] == DLM_DEVICE_VERSION_MAJOR &&
|
||||
req->version[1] > DLM_DEVICE_VERSION_MINOR)) {
|
||||
|
||||
printk(KERN_DEBUG "dlm: process %s (%d) version mismatch "
|
||||
"user (%d.%d.%d) kernel (%d.%d.%d)\n",
|
||||
current->comm,
|
||||
current->pid,
|
||||
req->version[0],
|
||||
req->version[1],
|
||||
req->version[2],
|
||||
DLM_DEVICE_VERSION_MAJOR,
|
||||
DLM_DEVICE_VERSION_MINOR,
|
||||
DLM_DEVICE_VERSION_PATCH);
|
||||
return -EINVAL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* device_write
|
||||
*
|
||||
* device_user_lock
|
||||
* dlm_user_request -> request_lock
|
||||
* dlm_user_convert -> convert_lock
|
||||
*
|
||||
* device_user_unlock
|
||||
* dlm_user_unlock -> unlock_lock
|
||||
* dlm_user_cancel -> cancel_lock
|
||||
*
|
||||
* device_create_lockspace
|
||||
* dlm_new_lockspace
|
||||
*
|
||||
* device_remove_lockspace
|
||||
* dlm_release_lockspace
|
||||
*/
|
||||
|
||||
/* a write to a lockspace device is a lock or unlock request, a write
|
||||
to the control device is to create/remove a lockspace */
|
||||
|
||||
static ssize_t device_write(struct file *file, const char __user *buf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct dlm_user_proc *proc = file->private_data;
|
||||
struct dlm_write_request *kbuf;
|
||||
sigset_t tmpsig, allsigs;
|
||||
int error;
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
if (count < sizeof(struct dlm_write_request32))
|
||||
#else
|
||||
if (count < sizeof(struct dlm_write_request))
|
||||
#endif
|
||||
return -EINVAL;
|
||||
|
||||
kbuf = kmalloc(count, GFP_KERNEL);
|
||||
if (!kbuf)
|
||||
return -ENOMEM;
|
||||
|
||||
if (copy_from_user(kbuf, buf, count)) {
|
||||
error = -EFAULT;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
if (check_version(kbuf)) {
|
||||
error = -EBADE;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
if (!kbuf->is64bit) {
|
||||
struct dlm_write_request32 *k32buf;
|
||||
k32buf = (struct dlm_write_request32 *)kbuf;
|
||||
kbuf = kmalloc(count + (sizeof(struct dlm_write_request) -
|
||||
sizeof(struct dlm_write_request32)), GFP_KERNEL);
|
||||
if (!kbuf)
|
||||
return -ENOMEM;
|
||||
|
||||
if (proc)
|
||||
set_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags);
|
||||
compat_input(kbuf, k32buf);
|
||||
kfree(k32buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* do we really need this? can a write happen after a close? */
|
||||
if ((kbuf->cmd == DLM_USER_LOCK || kbuf->cmd == DLM_USER_UNLOCK) &&
|
||||
test_bit(DLM_PROC_FLAGS_CLOSING, &proc->flags))
|
||||
return -EINVAL;
|
||||
|
||||
sigfillset(&allsigs);
|
||||
sigprocmask(SIG_BLOCK, &allsigs, &tmpsig);
|
||||
|
||||
error = -EINVAL;
|
||||
|
||||
switch (kbuf->cmd)
|
||||
{
|
||||
case DLM_USER_LOCK:
|
||||
if (!proc) {
|
||||
log_print("no locking on control device");
|
||||
goto out_sig;
|
||||
}
|
||||
error = device_user_lock(proc, &kbuf->i.lock);
|
||||
break;
|
||||
|
||||
case DLM_USER_UNLOCK:
|
||||
if (!proc) {
|
||||
log_print("no locking on control device");
|
||||
goto out_sig;
|
||||
}
|
||||
error = device_user_unlock(proc, &kbuf->i.lock);
|
||||
break;
|
||||
|
||||
case DLM_USER_CREATE_LOCKSPACE:
|
||||
if (proc) {
|
||||
log_print("create/remove only on control device");
|
||||
goto out_sig;
|
||||
}
|
||||
error = device_create_lockspace(&kbuf->i.lspace);
|
||||
break;
|
||||
|
||||
case DLM_USER_REMOVE_LOCKSPACE:
|
||||
if (proc) {
|
||||
log_print("create/remove only on control device");
|
||||
goto out_sig;
|
||||
}
|
||||
error = device_remove_lockspace(&kbuf->i.lspace);
|
||||
break;
|
||||
|
||||
default:
|
||||
log_print("Unknown command passed to DLM device : %d\n",
|
||||
kbuf->cmd);
|
||||
}
|
||||
|
||||
out_sig:
|
||||
sigprocmask(SIG_SETMASK, &tmpsig, NULL);
|
||||
recalc_sigpending();
|
||||
out_free:
|
||||
kfree(kbuf);
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Every process that opens the lockspace device has its own "proc" structure
|
||||
hanging off the open file that's used to keep track of locks owned by the
|
||||
process and asts that need to be delivered to the process. */
|
||||
|
||||
static int device_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct dlm_user_proc *proc;
|
||||
struct dlm_ls *ls;
|
||||
|
||||
ls = dlm_find_lockspace_device(iminor(inode));
|
||||
if (!ls)
|
||||
return -ENOENT;
|
||||
|
||||
proc = kzalloc(sizeof(struct dlm_user_proc), GFP_KERNEL);
|
||||
if (!proc) {
|
||||
dlm_put_lockspace(ls);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
proc->lockspace = ls->ls_local_handle;
|
||||
INIT_LIST_HEAD(&proc->asts);
|
||||
INIT_LIST_HEAD(&proc->locks);
|
||||
spin_lock_init(&proc->asts_spin);
|
||||
spin_lock_init(&proc->locks_spin);
|
||||
init_waitqueue_head(&proc->wait);
|
||||
file->private_data = proc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int device_close(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct dlm_user_proc *proc = file->private_data;
|
||||
struct dlm_ls *ls;
|
||||
sigset_t tmpsig, allsigs;
|
||||
|
||||
ls = dlm_find_lockspace_local(proc->lockspace);
|
||||
if (!ls)
|
||||
return -ENOENT;
|
||||
|
||||
sigfillset(&allsigs);
|
||||
sigprocmask(SIG_BLOCK, &allsigs, &tmpsig);
|
||||
|
||||
set_bit(DLM_PROC_FLAGS_CLOSING, &proc->flags);
|
||||
|
||||
dlm_clear_proc_locks(ls, proc);
|
||||
|
||||
/* at this point no more lkb's should exist for this lockspace,
|
||||
so there's no chance of dlm_user_add_ast() being called and
|
||||
looking for lkb->ua->proc */
|
||||
|
||||
kfree(proc);
|
||||
file->private_data = NULL;
|
||||
|
||||
dlm_put_lockspace(ls);
|
||||
dlm_put_lockspace(ls); /* for the find in device_open() */
|
||||
|
||||
/* FIXME: AUTOFREE: if this ls is no longer used do
|
||||
device_remove_lockspace() */
|
||||
|
||||
sigprocmask(SIG_SETMASK, &tmpsig, NULL);
|
||||
recalc_sigpending();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int copy_result_to_user(struct dlm_user_args *ua, int compat, int type,
|
||||
int bmode, char __user *buf, size_t count)
|
||||
{
|
||||
#ifdef CONFIG_COMPAT
|
||||
struct dlm_lock_result32 result32;
|
||||
#endif
|
||||
struct dlm_lock_result result;
|
||||
void *resultptr;
|
||||
int error=0;
|
||||
int len;
|
||||
int struct_len;
|
||||
|
||||
memset(&result, 0, sizeof(struct dlm_lock_result));
|
||||
memcpy(&result.lksb, &ua->lksb, sizeof(struct dlm_lksb));
|
||||
result.user_lksb = ua->user_lksb;
|
||||
|
||||
/* FIXME: dlm1 provides for the user's bastparam/addr to not be updated
|
||||
in a conversion unless the conversion is successful. See code
|
||||
in dlm_user_convert() for updating ua from ua_tmp. OpenVMS, though,
|
||||
notes that a new blocking AST address and parameter are set even if
|
||||
the conversion fails, so maybe we should just do that. */
|
||||
|
||||
if (type == AST_BAST) {
|
||||
result.user_astaddr = ua->bastaddr;
|
||||
result.user_astparam = ua->bastparam;
|
||||
result.bast_mode = bmode;
|
||||
} else {
|
||||
result.user_astaddr = ua->castaddr;
|
||||
result.user_astparam = ua->castparam;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
if (compat)
|
||||
len = sizeof(struct dlm_lock_result32);
|
||||
else
|
||||
#endif
|
||||
len = sizeof(struct dlm_lock_result);
|
||||
struct_len = len;
|
||||
|
||||
/* copy lvb to userspace if there is one, it's been updated, and
|
||||
the user buffer has space for it */
|
||||
|
||||
if (ua->update_user_lvb && ua->lksb.sb_lvbptr &&
|
||||
count >= len + DLM_USER_LVB_LEN) {
|
||||
if (copy_to_user(buf+len, ua->lksb.sb_lvbptr,
|
||||
DLM_USER_LVB_LEN)) {
|
||||
error = -EFAULT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
result.lvb_offset = len;
|
||||
len += DLM_USER_LVB_LEN;
|
||||
}
|
||||
|
||||
result.length = len;
|
||||
resultptr = &result;
|
||||
#ifdef CONFIG_COMPAT
|
||||
if (compat) {
|
||||
compat_output(&result, &result32);
|
||||
resultptr = &result32;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (copy_to_user(buf, resultptr, struct_len))
|
||||
error = -EFAULT;
|
||||
else
|
||||
error = len;
|
||||
out:
|
||||
return error;
|
||||
}
|
||||
|
||||
/* a read returns a single ast described in a struct dlm_lock_result */
|
||||
|
||||
static ssize_t device_read(struct file *file, char __user *buf, size_t count,
|
||||
loff_t *ppos)
|
||||
{
|
||||
struct dlm_user_proc *proc = file->private_data;
|
||||
struct dlm_lkb *lkb;
|
||||
struct dlm_user_args *ua;
|
||||
DECLARE_WAITQUEUE(wait, current);
|
||||
int error, type=0, bmode=0, removed = 0;
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
if (count < sizeof(struct dlm_lock_result32))
|
||||
#else
|
||||
if (count < sizeof(struct dlm_lock_result))
|
||||
#endif
|
||||
return -EINVAL;
|
||||
|
||||
/* do we really need this? can a read happen after a close? */
|
||||
if (test_bit(DLM_PROC_FLAGS_CLOSING, &proc->flags))
|
||||
return -EINVAL;
|
||||
|
||||
spin_lock(&proc->asts_spin);
|
||||
if (list_empty(&proc->asts)) {
|
||||
if (file->f_flags & O_NONBLOCK) {
|
||||
spin_unlock(&proc->asts_spin);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
add_wait_queue(&proc->wait, &wait);
|
||||
|
||||
repeat:
|
||||
set_current_state(TASK_INTERRUPTIBLE);
|
||||
if (list_empty(&proc->asts) && !signal_pending(current)) {
|
||||
spin_unlock(&proc->asts_spin);
|
||||
schedule();
|
||||
spin_lock(&proc->asts_spin);
|
||||
goto repeat;
|
||||
}
|
||||
set_current_state(TASK_RUNNING);
|
||||
remove_wait_queue(&proc->wait, &wait);
|
||||
|
||||
if (signal_pending(current)) {
|
||||
spin_unlock(&proc->asts_spin);
|
||||
return -ERESTARTSYS;
|
||||
}
|
||||
}
|
||||
|
||||
if (list_empty(&proc->asts)) {
|
||||
spin_unlock(&proc->asts_spin);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
/* there may be both completion and blocking asts to return for
|
||||
the lkb, don't remove lkb from asts list unless no asts remain */
|
||||
|
||||
lkb = list_entry(proc->asts.next, struct dlm_lkb, lkb_astqueue);
|
||||
|
||||
if (lkb->lkb_ast_type & AST_COMP) {
|
||||
lkb->lkb_ast_type &= ~AST_COMP;
|
||||
type = AST_COMP;
|
||||
} else if (lkb->lkb_ast_type & AST_BAST) {
|
||||
lkb->lkb_ast_type &= ~AST_BAST;
|
||||
type = AST_BAST;
|
||||
bmode = lkb->lkb_bastmode;
|
||||
}
|
||||
|
||||
if (!lkb->lkb_ast_type) {
|
||||
list_del(&lkb->lkb_astqueue);
|
||||
removed = 1;
|
||||
}
|
||||
spin_unlock(&proc->asts_spin);
|
||||
|
||||
ua = (struct dlm_user_args *)lkb->lkb_astparam;
|
||||
error = copy_result_to_user(ua,
|
||||
test_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags),
|
||||
type, bmode, buf, count);
|
||||
|
||||
/* removes reference for the proc->asts lists added by
|
||||
dlm_user_add_ast() and may result in the lkb being freed */
|
||||
if (removed)
|
||||
dlm_put_lkb(lkb);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static unsigned int device_poll(struct file *file, poll_table *wait)
|
||||
{
|
||||
struct dlm_user_proc *proc = file->private_data;
|
||||
|
||||
poll_wait(file, &proc->wait, wait);
|
||||
|
||||
spin_lock(&proc->asts_spin);
|
||||
if (!list_empty(&proc->asts)) {
|
||||
spin_unlock(&proc->asts_spin);
|
||||
return POLLIN | POLLRDNORM;
|
||||
}
|
||||
spin_unlock(&proc->asts_spin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ctl_device_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
file->private_data = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ctl_device_close(struct inode *inode, struct file *file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct file_operations device_fops = {
|
||||
.open = device_open,
|
||||
.release = device_close,
|
||||
.read = device_read,
|
||||
.write = device_write,
|
||||
.poll = device_poll,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static struct file_operations ctl_device_fops = {
|
||||
.open = ctl_device_open,
|
||||
.release = ctl_device_close,
|
||||
.write = device_write,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
int dlm_user_init(void)
|
||||
{
|
||||
int error;
|
||||
|
||||
ctl_device.name = "dlm-control";
|
||||
ctl_device.fops = &ctl_device_fops;
|
||||
ctl_device.minor = MISC_DYNAMIC_MINOR;
|
||||
|
||||
error = misc_register(&ctl_device);
|
||||
if (error)
|
||||
log_print("misc_register failed for control device");
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void dlm_user_exit(void)
|
||||
{
|
||||
misc_deregister(&ctl_device);
|
||||
}
|
||||
|
16
fs/dlm/user.h
Normal file
16
fs/dlm/user.h
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use,
|
||||
* modify, copy, or redistribute it subject to the terms and conditions
|
||||
* of the GNU General Public License v.2.
|
||||
*/
|
||||
|
||||
#ifndef __USER_DOT_H__
|
||||
#define __USER_DOT_H__
|
||||
|
||||
void dlm_user_add_ast(struct dlm_lkb *lkb, int type);
|
||||
int dlm_user_init(void);
|
||||
void dlm_user_exit(void);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user