Whamcloud - gitweb
- cleanups on client after Nikita's inspection.
[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
27 #ifndef __KERNEL__
28 /* XXX: dirty hack, needs to be fixed more clever way. */
29 struct qstr {
30         const char *name;
31         size_t      len;
32         unsigned    hashval;
33 };
34 #endif
35
36 #define LMV_MAX_TGT_COUNT 128
37
38 #define lmv_init_lock(lmv)   down(&lmv->init_sem);
39 #define lmv_init_unlock(lmv) up(&lmv->init_sem);
40
41 #define LL_IT2STR(it)                                   \
42         ((it) ? ldlm_it2str((it)->it_op) : "0")
43
44 struct lmv_inode {
45         struct lu_fid      li_fid;        /* id of dirobj */
46         unsigned long      li_size;       /* slave size value */
47         int                li_flags;
48 };
49
50 #define O_FREEING          (1 << 0)
51
52 struct lmv_obj {
53         struct list_head   lo_list;
54         struct semaphore   lo_guard;
55         int                lo_state;      /* object state. */
56         atomic_t           lo_count;      /* ref counter. */
57         struct lu_fid      lo_fid;        /* master id of dir */
58         void              *lo_update;     /* bitmap of status (up-to-date) */
59         __u32              lo_hashtype;
60         int                lo_objcount;   /* number of slaves */
61         struct lmv_inode  *lo_inodes;     /* array of sub-objs */
62         struct obd_device *lo_obd;        /* pointer to LMV itself */
63 };
64
65 int lmv_mgr_setup(struct obd_device *obd);
66 void lmv_mgr_cleanup(struct obd_device *obd);
67
68 static inline void
69 lmv_obj_lock(struct lmv_obj *obj)
70 {
71         LASSERT(obj);
72         down(&obj->lo_guard);
73 }
74
75 static inline void
76 lmv_obj_unlock(struct lmv_obj *obj)
77 {
78         LASSERT(obj);
79         up(&obj->lo_guard);
80 }
81
82 void lmv_obj_add(struct lmv_obj *obj);
83 void lmv_obj_del(struct lmv_obj *obj);
84
85 void lmv_obj_put(struct lmv_obj *obj);
86 void lmv_obj_free(struct lmv_obj *obj);
87
88 struct lmv_obj *lmv_obj_get(struct lmv_obj *obj);
89
90 struct lmv_obj *lmv_obj_grab(struct obd_device *obd,
91                              const struct lu_fid *fid);
92
93 struct lmv_obj *lmv_obj_alloc(struct obd_device *obd,
94                               const struct lu_fid *fid,
95                               struct lmv_stripe_md *mea);
96
97 struct lmv_obj *lmv_obj_create(struct obd_export *exp,
98                                const struct lu_fid *fid,
99                                struct lmv_stripe_md *mea);
100
101 int lmv_obj_delete(struct obd_export *exp,
102                    const struct lu_fid *fid);
103
104 int lmv_check_connect(struct obd_device *obd);
105
106 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
107                     void *lmm, int lmmsize, struct lookup_intent *it,
108                     int flags, struct ptlrpc_request **reqp,
109                     ldlm_blocking_callback cb_blocking,
110                     int extra_lock_flags);
111
112 int lmv_intent_lookup(struct obd_export *, const struct lu_fid *, 
113                       const char *, int, void *, int,
114                       const struct lu_fid *, struct lookup_intent *, int,
115                       struct ptlrpc_request **, ldlm_blocking_callback,
116                       int extra_lock_flags);
117
118 int lmv_intent_getattr(struct obd_export *, const struct lu_fid *, const char *,
119                        int, void *, int, const struct lu_fid *, struct lookup_intent *,
120                        int, struct ptlrpc_request **, ldlm_blocking_callback,
121                        int extra_lock_flags);
122
123 int lmv_intent_open(struct obd_export *, const struct lu_fid *, const char *, 
124                     int, void *, int, const struct lu_fid *, struct lookup_intent *, 
125                     int, struct ptlrpc_request **, ldlm_blocking_callback,
126                     int extra_lock_flags);
127
128 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
129                           const struct lu_fid *, struct lookup_intent *, int,
130                           ldlm_blocking_callback cb_blocking,
131                           int extra_lock_flags);
132
133 int lmv_handle_split(struct obd_export *, const struct lu_fid *);
134 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
135                      void *, int);
136 int lmv_fld_lookup(struct obd_device *obd, const struct lu_fid *fid,
137                    mdsno_t *mds);
138
139 static inline struct lmv_stripe_md * 
140 lmv_get_mea(struct ptlrpc_request *req, int offset)
141 {
142         struct mdt_body *body;
143         struct lmv_stripe_md *mea;
144
145         LASSERT(req);
146
147         body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body));
148
149         if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
150                 return NULL;
151
152         mea = lustre_msg_buf(req->rq_repmsg, offset + 1,
153                              body->eadatasize);
154         LASSERT(mea);
155
156         if (mea->mea_count == 0)
157                 return NULL;
158         
159         return mea;
160 }
161
162 static inline int lmv_get_easize(struct lmv_obd *lmv)
163 {
164         return sizeof(struct lmv_stripe_md) +
165                 lmv->desc.ld_tgt_count *
166                 sizeof(struct lu_fid);
167 }
168
169 /* lproc_lmv.c */
170 extern struct file_operations lmv_proc_target_fops;
171
172 #endif
173