Skip to content

Commit 2ab4bd8

Browse files
committed
dlm: adopt orphan locks
A process may exit, leaving an orphan lock in the lockspace. This adds the capability for another process to acquire the orphan lock. Acquiring the orphan just moves the lock from the orphan list onto the acquiring process's list of locks. An adopting process must specify the resource name and mode of the lock it wants to adopt. If a matching lock is found, the lock is moved to the caller's 's list of locks, and the lkid of the lock is returned like the lkid of a new lock. If an orphan with a different mode is found, then -EAGAIN is returned. If no orphan lock is found on the resource, then -ENOENT is returned. No async completion is used because the result is immediately available. Also, when orphans are purged, allow a zero nodeid to refer to the local nodeid so the caller does not need to look up the local nodeid. Signed-off-by: David Teigland <teigland@redhat.com>
1 parent 206c5f6 commit 2ab4bd8

4 files changed

Lines changed: 89 additions & 5 deletions

File tree

‎fs/dlm/lock.c‎

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5886,6 +5886,78 @@ int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
58865886
return error;
58875887
}
58885888

5889+
/*
5890+
* The caller asks for an orphan lock on a given resource with a given mode.
5891+
* If a matching lock exists, it's moved to the owner's list of locks and
5892+
* the lkid is returned.
5893+
*/
5894+
5895+
int dlm_user_adopt_orphan(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
5896+
int mode, uint32_t flags, void *name, unsigned int namelen,
5897+
unsigned long timeout_cs, uint32_t *lkid)
5898+
{
5899+
struct dlm_lkb *lkb;
5900+
struct dlm_user_args *ua;
5901+
int found_other_mode = 0;
5902+
int found = 0;
5903+
int rv = 0;
5904+
5905+
mutex_lock(&ls->ls_orphans_mutex);
5906+
list_for_each_entry(lkb, &ls->ls_orphans, lkb_ownqueue) {
5907+
if (lkb->lkb_resource->res_length != namelen)
5908+
continue;
5909+
if (memcmp(lkb->lkb_resource->res_name, name, namelen))
5910+
continue;
5911+
if (lkb->lkb_grmode != mode) {
5912+
found_other_mode = 1;
5913+
continue;
5914+
}
5915+
5916+
found = 1;
5917+
list_del_init(&lkb->lkb_ownqueue);
5918+
lkb->lkb_flags &= ~DLM_IFL_ORPHAN;
5919+
*lkid = lkb->lkb_id;
5920+
break;
5921+
}
5922+
mutex_unlock(&ls->ls_orphans_mutex);
5923+
5924+
if (!found && found_other_mode) {
5925+
rv = -EAGAIN;
5926+
goto out;
5927+
}
5928+
5929+
if (!found) {
5930+
rv = -ENOENT;
5931+
goto out;
5932+
}
5933+
5934+
lkb->lkb_exflags = flags;
5935+
lkb->lkb_ownpid = (int) current->pid;
5936+
5937+
ua = lkb->lkb_ua;
5938+
5939+
ua->proc = ua_tmp->proc;
5940+
ua->xid = ua_tmp->xid;
5941+
ua->castparam = ua_tmp->castparam;
5942+
ua->castaddr = ua_tmp->castaddr;
5943+
ua->bastparam = ua_tmp->bastparam;
5944+
ua->bastaddr = ua_tmp->bastaddr;
5945+
ua->user_lksb = ua_tmp->user_lksb;
5946+
5947+
/*
5948+
* The lkb reference from the ls_orphans list was not
5949+
* removed above, and is now considered the reference
5950+
* for the proc locks list.
5951+
*/
5952+
5953+
spin_lock(&ua->proc->locks_spin);
5954+
list_add_tail(&lkb->lkb_ownqueue, &ua->proc->locks);
5955+
spin_unlock(&ua->proc->locks_spin);
5956+
out:
5957+
kfree(ua_tmp);
5958+
return rv;
5959+
}
5960+
58895961
int dlm_user_unlock(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
58905962
uint32_t flags, uint32_t lkid, char *lvb_in)
58915963
{
@@ -6029,7 +6101,7 @@ static int orphan_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb)
60296101
struct dlm_args args;
60306102
int error;
60316103

6032-
hold_lkb(lkb);
6104+
hold_lkb(lkb); /* reference for the ls_orphans list */
60336105
mutex_lock(&ls->ls_orphans_mutex);
60346106
list_add_tail(&lkb->lkb_ownqueue, &ls->ls_orphans);
60356107
mutex_unlock(&ls->ls_orphans_mutex);
@@ -6217,7 +6289,7 @@ int dlm_user_purge(struct dlm_ls *ls, struct dlm_user_proc *proc,
62176289
{
62186290
int error = 0;
62196291

6220-
if (nodeid != dlm_our_nodeid()) {
6292+
if (nodeid && (nodeid != dlm_our_nodeid())) {
62216293
error = send_purge(ls, nodeid, pid);
62226294
} else {
62236295
dlm_lock_recovery(ls);

‎fs/dlm/lock.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua, int mode,
4949
int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
5050
int mode, uint32_t flags, uint32_t lkid, char *lvb_in,
5151
unsigned long timeout_cs);
52+
int dlm_user_adopt_orphan(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
53+
int mode, uint32_t flags, void *name, unsigned int namelen,
54+
unsigned long timeout_cs, uint32_t *lkid);
5255
int dlm_user_unlock(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
5356
uint32_t flags, uint32_t lkid, char *lvb_in);
5457
int dlm_user_cancel(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,

‎fs/dlm/user.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ static int device_user_lock(struct dlm_user_proc *proc,
238238
{
239239
struct dlm_ls *ls;
240240
struct dlm_user_args *ua;
241+
uint32_t lkid;
241242
int error = -ENOMEM;
242243

243244
ls = dlm_find_lockspace_local(proc->lockspace);
@@ -260,12 +261,20 @@ static int device_user_lock(struct dlm_user_proc *proc,
260261
ua->bastaddr = params->bastaddr;
261262
ua->xid = params->xid;
262263

263-
if (params->flags & DLM_LKF_CONVERT)
264+
if (params->flags & DLM_LKF_CONVERT) {
264265
error = dlm_user_convert(ls, ua,
265266
params->mode, params->flags,
266267
params->lkid, params->lvb,
267268
(unsigned long) params->timeout);
268-
else {
269+
} else if (params->flags & DLM_LKF_ORPHAN) {
270+
error = dlm_user_adopt_orphan(ls, ua,
271+
params->mode, params->flags,
272+
params->name, params->namelen,
273+
(unsigned long) params->timeout,
274+
&lkid);
275+
if (!error)
276+
error = lkid;
277+
} else {
269278
error = dlm_user_request(ls, ua,
270279
params->mode, params->flags,
271280
params->name, params->namelen,

‎include/uapi/linux/dlmconstants.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
*
115115
* DLM_LKF_ORPHAN
116116
*
117-
* not yet implemented
117+
* Acquire an orphan lock.
118118
*
119119
* DLM_LKF_ALTPR
120120
*

0 commit comments

Comments
 (0)