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