Whamcloud - gitweb
new llog_ldlm process and mgc_enqueue
[fs/lustre-release.git] / lustre / mgc / mgc_lock.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001-2005 Cluster File Systems, Inc.
5  *   Author LinSongTao <lincent@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  *  For testing and management it is treated as an obd_device,
23  *  although * it does not export a full OBD method table (the
24  *  requests are coming * in over the wire, so object target modules
25  *  do not have a full * method table.)
26  */
27 #ifndef EXPORT_SYMTAB
28 # define EXPORT_SYMTAB
29 #endif
30 #define DEBUG_SUBSYSTEM S_MGC
31
32 #ifdef __KERNEL__
33 # include <linux/module.h>
34 # include <linux/pagemap.h>
35 # include <linux/miscdevice.h>
36 # include <linux/init.h>
37 #else
38 # include <liblustre.h>
39 #endif
40
41 #include <linux/obd_class.h>
42 #include <linux/lustre_dlm.h>
43 #include <linux/lustre_log.h>
44 #include <linux/lustre_fsfilt.h>
45 #include <linux/lustre_disk.h>
46
47 #include "mgc_internal.h"
48
49 int mgc_enqueue(struct obd_export *exp, int lock_mode, 
50                 struct mgc_op_data *data, struct lustre_handle *lockh,
51                 ldlm_completion_callback cb_completion,
52                 ldlm_blocking_callback cb_blocking,
53                 void *cb_data)
54 {    
55         struct ptlrpc_request *req;
56         struct obd_device *obddev = class_exp2obd(exp);
57         struct ldlm_res_id res_id =
58                 { .name = {data->obj_id, 
59                            data->obj_version} 
60                 };
61         int rc = 0, flags = 0;
62         struct ldlm_reply *dlm_rep;
63         struct ldlm_request *lockreq;
64         unsigned long irqflags;
65         int   reply_buffers = 0;
66         ENTRY;
67
68         /* Search for already existing locks.*/
69         rc = ldlm_lock_match(obd->obd_namespace, 0, &res_id, LDLM_LLOG, 
70                              NULL, mode, lockh);
71         if (rc == 1) 
72                 RETURN(ELDLM_OK);
73
74         rc = ldlm_cli_enqueue(exp, req, obd->obd_namespace, res_id, LDLM_LLOG,
75                               NULL, mode, flags, bl_cb, cp_cb, gl_cb, data,
76                               &lvb, sizeof(lvb), lustre_swab_ost_lvb, lockh);
77
78         if (req != NULL) {
79                 if (rc == ELDLM_LOCK_ABORTED) {
80                         /* swabbed by ldlm_cli_enqueue() */
81                         LASSERT_REPSWABBED(req, 0);
82                         rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep));
83                         LASSERT(rep != NULL);
84                         if (rep->lock_policy_res1)
85                                 rc = rep->lock_policy_res1;
86                 }
87                 ptlrpc_req_finished(req);
88         }
89
90         RETURN(rc);
91 }