Whamcloud - gitweb
LU-1526 tests: Handle OFD procfs changes
[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 (c) 2003, 2010, Oracle and/or its affiliates. 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, int ea_size);
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 int 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 void seq_client_flush(struct lu_client_seq *seq);
95
96 struct mdc_open_data {
97         struct obd_client_handle *mod_och;
98         struct ptlrpc_request    *mod_open_req;
99         struct ptlrpc_request    *mod_close_req;
100 };
101
102 struct mdc_rpc_lock {
103         struct semaphore rpcl_sem;
104         struct lookup_intent *rpcl_it;
105 };
106
107 static inline void mdc_init_rpc_lock(struct mdc_rpc_lock *lck)
108 {
109         sema_init(&lck->rpcl_sem, 1);
110         lck->rpcl_it = NULL;
111 }
112
113 static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck,
114                                     struct lookup_intent *it)
115 {
116         ENTRY;
117         if (!it || (it->it_op != IT_GETATTR && it->it_op != IT_LOOKUP)) {
118                 down(&lck->rpcl_sem);
119                 LASSERT(lck->rpcl_it == NULL);
120                 lck->rpcl_it = it;
121         }
122 }
123
124 static inline void mdc_put_rpc_lock(struct mdc_rpc_lock *lck,
125                                     struct lookup_intent *it)
126 {
127         if (!it || (it->it_op != IT_GETATTR && it->it_op != IT_LOOKUP)) {
128                 LASSERT(it == lck->rpcl_it);
129                 lck->rpcl_it = NULL;
130                 up(&lck->rpcl_sem);
131         }
132         EXIT;
133 }
134
135 static inline int mdc_exp_is_2_0_server(struct obd_export *exp) {
136        LASSERT(exp);
137        return !!(exp->exp_connect_flags & OBD_CONNECT_FID);
138 }
139
140 static inline int mdc_req_is_2_0_server(struct ptlrpc_request *req) {
141        LASSERT(req);
142        return mdc_exp_is_2_0_server(req->rq_export);
143 }
144
145 static inline void mdc_update_max_ea_from_body(struct obd_export *exp,
146                                                struct mds_body *body)
147 {
148         if (body->valid & OBD_MD_FLMODEASIZE) {
149                 if (exp->exp_obd->u.cli.cl_max_mds_easize < body->max_mdsize) 
150                         exp->exp_obd->u.cli.cl_max_mds_easize = 
151                                                 body->max_mdsize;
152                 if (exp->exp_obd->u.cli.cl_max_mds_cookiesize < 
153                                                 body->max_cookiesize)
154                         exp->exp_obd->u.cli.cl_max_mds_cookiesize = 
155                                                 body->max_cookiesize;
156         }
157 }