1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2005 Cluster File Systems, Inc.
5 * Author LinSongTao <lincent@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org
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.
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.
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.
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.)
28 # define EXPORT_SYMTAB
30 #define DEBUG_SUBSYSTEM S_MGC
33 # include <linux/module.h>
34 # include <linux/pagemap.h>
35 # include <linux/miscdevice.h>
36 # include <linux/init.h>
38 # include <liblustre.h>
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>
47 #include "mgc_internal.h"
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,
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,
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;
68 /* Search for already existing locks.*/
69 rc = ldlm_lock_match(obd->obd_namespace, 0, &res_id, LDLM_LLOG,
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);
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));
84 if (rep->lock_policy_res1)
85 rc = rep->lock_policy_res1;
87 ptlrpc_req_finished(req);