Whamcloud - gitweb
- possibly (I'm almost sure) fix for FLD lookup err -2. Allocating new seq and setup...
[fs/lustre-release.git] / lustre / lmv / lmv_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002, 2003, 2004, 2005, 2006 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
22 #ifndef _LMV_INTERNAL_H_
23 #define _LMV_INTERNAL_H_
24
25 #include <lustre/lustre_idl.h>
26 #include <obd.h>
27
28 #ifndef __KERNEL__
29 /* XXX: dirty hack, needs to be fixed more clever way. */
30 struct qstr {
31         const char *name;
32         size_t      len;
33         unsigned    hashval;
34 };
35 #endif
36
37 #define LMV_MAX_TGT_COUNT 128
38
39 #define lmv_init_lock(lmv)   down(&lmv->init_sem);
40 #define lmv_init_unlock(lmv) up(&lmv->init_sem);
41
42 #define LL_IT2STR(it)                                   \
43         ((it) ? ldlm_it2str((it)->it_op) : "0")
44
45 struct lmv_inode {
46         struct lu_fid      li_fid;        /* id of dirobj */
47         unsigned long      li_size;       /* slave size value */
48         int                li_flags;
49 };
50
51 #define O_FREEING          (1 << 0)
52
53 struct lmv_obj {
54         struct list_head   lo_list;
55         struct semaphore   lo_guard;
56         int                lo_state;      /* object state. */
57         atomic_t           lo_count;      /* ref counter. */
58         struct lu_fid      lo_fid;        /* master id of dir */
59         void              *lo_update;     /* bitmap of status (up-to-date) */
60         __u32              lo_hashtype;
61         int                lo_objcount;   /* number of slaves */
62         struct lmv_inode  *lo_inodes;     /* array of sub-objs */
63         struct obd_device *lo_obd;        /* pointer to LMV itself */
64 };
65
66 int lmv_obj_setup(struct obd_device *obd);
67 void lmv_obj_cleanup(struct obd_device *obd);
68
69 static inline void
70 lmv_obj_lock(struct lmv_obj *obj)
71 {
72         LASSERT(obj);
73         down(&obj->lo_guard);
74 }
75
76 static inline void
77 lmv_obj_unlock(struct lmv_obj *obj)
78 {
79         LASSERT(obj);
80         up(&obj->lo_guard);
81 }
82
83 void lmv_obj_add(struct lmv_obj *obj);
84 void lmv_obj_del(struct lmv_obj *obj);
85
86 void lmv_obj_put(struct lmv_obj *obj);
87 void lmv_obj_free(struct lmv_obj *obj);
88
89 struct lmv_obj *lmv_obj_get(struct lmv_obj *obj);
90
91 struct lmv_obj *lmv_obj_grab(struct obd_device *obd,
92                              const struct lu_fid *fid);
93
94 struct lmv_obj *lmv_obj_alloc(struct obd_device *obd,
95                               const struct lu_fid *fid,
96                               struct lmv_stripe_md *mea);
97
98 struct lmv_obj *lmv_obj_create(struct obd_export *exp,
99                                const struct lu_fid *fid,
100                                struct lmv_stripe_md *mea);
101
102 int lmv_obj_delete(struct obd_export *exp,
103                    const struct lu_fid *fid);
104
105 int lmv_check_connect(struct obd_device *obd);
106
107 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
108                     void *lmm, int lmmsize, struct lookup_intent *it,
109                     int flags, struct ptlrpc_request **reqp,
110                     ldlm_blocking_callback cb_blocking,
111                     int extra_lock_flags);
112
113 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
114                       void *lmm, int lmmsize, struct lookup_intent *it,
115                       int flags, struct ptlrpc_request **reqp,
116                       ldlm_blocking_callback cb_blocking,
117                       int extra_lock_flags);
118
119 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
120                     void *lmm, int lmmsize, struct lookup_intent *it,
121                     int flags, struct ptlrpc_request **reqp,
122                     ldlm_blocking_callback cb_blocking,
123                     int extra_lock_flags);
124
125 int lmv_intent_getattr(struct obd_export *exp, struct md_op_data *op_data,
126                        void *lmm, int lmmsize, struct lookup_intent *it,
127                        int flags, struct ptlrpc_request **reqp,
128                        ldlm_blocking_callback cb_blocking,
129                        int extra_lock_flags);
130
131 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
132                           const struct lu_fid *, struct lookup_intent *, int,
133                           ldlm_blocking_callback cb_blocking,
134                           int extra_lock_flags);
135
136 int lmv_handle_split(struct obd_export *, const struct lu_fid *);
137 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
138                      void *, int);
139 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid,
140                    mdsno_t *mds);
141 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
142                     mdsno_t mds);
143 int lmv_alloc_fid_for_split(struct obd_device *obd, struct lu_fid *pid,
144                             struct md_op_data *op, struct lu_fid *fid);
145
146 static inline struct lmv_stripe_md * 
147 lmv_get_mea(struct ptlrpc_request *req, int offset)
148 {
149         struct mdt_body *body;
150         struct lmv_stripe_md *mea;
151
152         LASSERT(req);
153
154         body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body));
155
156         if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
157                 return NULL;
158
159         mea = lustre_msg_buf(req->rq_repmsg, offset + 1,
160                              body->eadatasize);
161         LASSERT(mea);
162
163         if (mea->mea_count == 0)
164                 return NULL;
165         
166         return mea;
167 }
168
169 static inline int lmv_get_easize(struct lmv_obd *lmv)
170 {
171         return sizeof(struct lmv_stripe_md) +
172                 lmv->desc.ld_tgt_count *
173                 sizeof(struct lu_fid);
174 }
175
176 static inline struct obd_export *
177 lmv_get_export(struct lmv_obd *lmv, const struct lu_fid *fid)
178 {
179         mdsno_t mds;
180         int rc;
181         
182         rc = lmv_fld_lookup(lmv, fid, &mds);
183         if (rc)
184                 return ERR_PTR(rc);
185
186         return lmv->tgts[mds].ltd_exp;
187 }
188
189 /* lproc_lmv.c */
190 extern struct file_operations lmv_proc_target_fops;
191
192 #endif
193