Whamcloud - gitweb
Branch HEAD
[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 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 #define LMV_MAX_TGT_COUNT 128
26
27 #define lmv_init_lock(lmv)   down(&lmv->init_sem);
28 #define lmv_init_unlock(lmv) up(&lmv->init_sem);
29
30 #define LL_IT2STR(it)                                   \
31         ((it) ? ldlm_it2str((it)->it_op) : "0")
32
33 #define MEA_SIZE_LMV(lmv)                               \
34         ((lmv)->desc.ld_tgt_count *                     \
35          sizeof(struct lustre_id) + sizeof(struct mea))
36         
37 struct lmv_inode {
38         struct lustre_id   id;             /* id of dirobj */
39         unsigned long      size;           /* slave size value */
40         int                flags;
41 };
42
43 #define O_FREEING          (1 << 0)
44
45 struct lmv_obj {
46         struct list_head   list;
47         struct semaphore   guard;
48         int                state;          /* object state. */
49         atomic_t           count;          /* ref counter. */
50         struct lustre_id   id;             /* master id of dir */
51         void               *update;        /* bitmap of status (up-to-date) */
52         __u32              hashtype;
53         int                objcount;       /* number of slaves */
54         struct lmv_inode   *objs;          /* array of dirobjs */
55         struct obd_device  *obd;           /* pointer to LMV itself */
56 };
57
58 static inline void
59 lmv_lock_obj(struct lmv_obj *obj)
60 {
61         LASSERT(obj);
62         down(&obj->guard);
63 }
64
65 static inline void
66 lmv_unlock_obj(struct lmv_obj *obj)
67 {
68         LASSERT(obj);
69         up(&obj->guard);
70 }
71
72 void lmv_add_obj(struct lmv_obj *obj);
73 void lmv_del_obj(struct lmv_obj *obj);
74
75 void lmv_put_obj(struct lmv_obj *obj);
76 void lmv_free_obj(struct lmv_obj *obj);
77
78 int lmv_setup_mgr(struct obd_device *obd);
79 void lmv_cleanup_mgr(struct obd_device *obd);
80 int lmv_check_connect(struct obd_device *obd);
81
82 struct lmv_obj *lmv_get_obj(struct lmv_obj *obj);
83
84 struct lmv_obj *lmv_grab_obj(struct obd_device *obd,
85                              struct lustre_id *id);
86
87 struct lmv_obj *lmv_alloc_obj(struct obd_device *obd,
88                               struct lustre_id *id,
89                               struct mea *mea);
90
91 struct lmv_obj *lmv_create_obj(struct obd_export *exp,
92                                struct lustre_id *id,
93                                struct mea *mea);
94
95 int lmv_delete_obj(struct obd_export *exp, struct lustre_id *id);
96
97 int lmv_intent_lock(struct obd_export *, struct lustre_id *, 
98                     const char *, int, void *, int,
99                     struct lustre_id *, struct lookup_intent *, int,
100                     struct ptlrpc_request **, ldlm_blocking_callback);
101
102 int lmv_intent_lookup(struct obd_export *, struct lustre_id *, 
103                       const char *, int, void *, int,
104                       struct lustre_id *, struct lookup_intent *, int,
105                       struct ptlrpc_request **, ldlm_blocking_callback);
106
107 int lmv_intent_getattr(struct obd_export *, struct lustre_id *, 
108                        const char *, int, void *, int,
109                        struct lustre_id *, struct lookup_intent *, int,
110                        struct ptlrpc_request **, ldlm_blocking_callback);
111
112 int lmv_intent_open(struct obd_export *, struct lustre_id *, const char *, 
113                     int, void *, int, struct lustre_id *, struct lookup_intent *, 
114                     int, struct ptlrpc_request **, ldlm_blocking_callback);
115
116 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
117                           struct lustre_id *, struct lookup_intent *, int,
118                           ldlm_blocking_callback cb_blocking);
119
120 int lmv_get_mea_and_update_object(struct obd_export *, struct lustre_id *);
121 int lmv_dirobj_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
122                             void *, int);
123
124 static inline struct mea * 
125 lmv_splitted_dir_body(struct ptlrpc_request *req, int offset)
126 {
127         struct mds_body *body;
128         struct mea *mea;
129
130         LASSERT(req);
131
132         body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body));
133
134         if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
135                 return NULL;
136
137         mea = lustre_msg_buf(req->rq_repmsg, offset + 1,
138                              body->eadatasize);
139         LASSERT(mea);
140
141         if (mea->mea_count == 0)
142                 return NULL;
143         
144         return mea;
145 }
146
147 /* lproc_lmv.c */
148 extern struct file_operations lmv_proc_target_fops;
149
150 #endif
151