Whamcloud - gitweb
c2faf05b842210fb4b4260fadc3f3035aaf31a90
[fs/lustre-release.git] / lustre / mdc / mdc_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 #ifndef MDC_INTERNAL_H
22 #define MDC_INTERNAL_H
23
24 int mdc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
25                struct lov_stripe_md *lsm);
26
27 int mdc_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
28                  struct lov_mds_md *lmm, int lmm_size);
29
30 void mdc_getattr_pack(struct lustre_msg *msg, int offset,
31                       __u64 valid, int flags,
32                       struct mdc_op_data *op_data);
33
34 void mdc_open_pack(struct lustre_msg *msg, int offset,
35                    struct mdc_op_data *op_data, __u32 mode,
36                    __u64 rdev, __u32 flags, const void *lmm,
37                    int lmmlen, void *key, int keylen);
38 void mdc_readdir_pack(struct ptlrpc_request *req, int req_offset,
39                       __u64 offset, __u32 size, struct lustre_id *mdc_id);
40 void mdc_close_pack(struct ptlrpc_request *req, int offset, struct obdo *oa,
41                     __u64 valid, struct obd_client_handle *och);
42
43 struct mdc_open_data {
44         struct obd_client_handle *mod_och;
45         struct ptlrpc_request    *mod_open_req;
46         struct ptlrpc_request    *mod_close_req;
47 };
48
49 struct mdc_rpc_lock {
50         struct semaphore rpcl_sem;
51         struct lookup_intent *rpcl_it;
52 };
53
54 static inline void mdc_init_rpc_lock(struct mdc_rpc_lock *lck)
55 {
56         sema_init(&lck->rpcl_sem, 1);
57         lck->rpcl_it = NULL;
58 }
59
60 static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck, 
61                                     struct lookup_intent *it)
62 {
63         ENTRY;
64         down(&lck->rpcl_sem);
65         if (it) { 
66                 lck->rpcl_it = it;
67         }
68 }
69
70 static inline void mdc_put_rpc_lock(struct mdc_rpc_lock *lck, 
71                                     struct lookup_intent *it)
72 {
73         EXIT;
74         if (it == NULL) {
75                 LASSERT(it == lck->rpcl_it);
76                 up(&lck->rpcl_sem);
77                 return;
78         }
79         if (it) {
80                 LASSERT(it == lck->rpcl_it);
81                 lck->rpcl_it = NULL;
82                 up(&lck->rpcl_sem);
83         }
84 }
85
86 #endif /* MDC_INTERNAL_H */