Whamcloud - gitweb
91042380cb6e18a0925def4134a1885453f8c710
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/mdc/mdc_internal.h
37  *
38  * MDC internal definitions.
39  */
40
41 #include <lustre_mds.h>
42 #ifdef LPROCFS
43 void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars);
44 #else
45 static inline void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars)
46 {
47         memset(lvars, 0, sizeof(*lvars));
48 }
49 #endif
50 void mdc_pack_req_body(struct ptlrpc_request *req, int offset,
51                        __u64 valid, struct ll_fid *fid, int ea_size, int flags);
52 void mdc_pack_rep_body(struct ptlrpc_request *);
53 void mdc_readdir_pack(struct ptlrpc_request *req, int offset, __u64 pg_off,
54                       __u32 size, struct ll_fid *mdc_fid);
55 void mdc_getattr_pack(struct ptlrpc_request *req, int offset, __u64 valid,
56                       int flags, struct mdc_op_data *data);
57 void mdc_setattr_pack(struct ptlrpc_request *req, int offset,
58                       struct mdc_op_data *data,
59                       struct iattr *iattr, void *ea, int ealen,
60                       void *ea2, int ea2len);
61 void mdc_create_pack(struct ptlrpc_request *req, int offset,
62                      struct mdc_op_data *op_data, const void *data, int datalen,
63                      __u32 mode, __u32 uid, __u32 gid, cfs_cap_t cap_effective,
64                      __u64 rdev);
65 void mdc_open_pack(struct ptlrpc_request *req, int offset,
66                    struct mdc_op_data *op_data, __u32 mode, __u64 rdev,
67                    __u32 flags, const void *data, int datalen);
68 void mdc_join_pack(struct ptlrpc_request *req, int offset,
69                    struct mdc_op_data *op_data, __u64 head_size);
70 void mdc_unlink_pack(struct ptlrpc_request *req, int offset,
71                      struct mdc_op_data *data);
72 void mdc_link_pack(struct ptlrpc_request *req, int offset,
73                    struct mdc_op_data *data);
74 void mdc_rename_pack(struct ptlrpc_request *req, int offset,
75                      struct mdc_op_data *data,
76                      const char *old, int oldlen, const char *new, int newlen);
77 void mdc_close_pack(struct ptlrpc_request *req, int offset,
78                     struct mdc_op_data *data,
79                     struct obdo *oa,
80                     __u64 valid, struct obd_client_handle *och);
81 void mdc_exit_request(struct client_obd *cli);
82 void mdc_enter_request(struct client_obd *cli);
83
84 int seq_client_init(struct lu_client_seq *seq,
85                     struct obd_export *exp,
86                     enum lu_cli_type type,
87                     __u64 width,
88                     const char *prefix);
89
90 void seq_client_fini(struct lu_client_seq *seq);
91
92 int mdc_fid_alloc(struct lu_client_seq *seq, struct lu_fid *fid);
93
94 struct mdc_open_data {
95         struct obd_client_handle *mod_och;
96         struct ptlrpc_request    *mod_open_req;
97         struct ptlrpc_request    *mod_close_req;
98 };
99
100 struct mdc_rpc_lock {
101         struct semaphore rpcl_sem;
102         struct lookup_intent *rpcl_it;
103 };
104
105 static inline void mdc_init_rpc_lock(struct mdc_rpc_lock *lck)
106 {
107         sema_init(&lck->rpcl_sem, 1);
108         lck->rpcl_it = NULL;
109 }
110
111 static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck,
112                                     struct lookup_intent *it)
113 {
114         ENTRY;
115         if (!it || (it->it_op != IT_GETATTR && it->it_op != IT_LOOKUP)) {
116                 down(&lck->rpcl_sem);
117                 LASSERT(lck->rpcl_it == NULL);
118                 lck->rpcl_it = it;
119         }
120 }
121
122 static inline void mdc_put_rpc_lock(struct mdc_rpc_lock *lck,
123                                     struct lookup_intent *it)
124 {
125         if (!it || (it->it_op != IT_GETATTR && it->it_op != IT_LOOKUP)) {
126                 LASSERT(it == lck->rpcl_it);
127                 lck->rpcl_it = NULL;
128                 up(&lck->rpcl_sem);
129         }
130         EXIT;
131 }
132
133 static inline int mdc_exp_is_2_0_server(struct obd_export *exp) {
134        LASSERT(exp);
135        return !!(exp->exp_connect_flags & OBD_CONNECT_FID);
136 }
137
138 static inline int mdc_req_is_2_0_server(struct ptlrpc_request *req) {
139        LASSERT(req);
140         return mdc_exp_is_2_0_server(req->rq_export);
141 }