Whamcloud - gitweb
Small fix for getting ACL.
[fs/lustre-release.git] / lustre / include / md_object.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Extention of lu_object.h for metadata objects
5  *
6  *  Copyright (C) 2006 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  */
24
25 #ifndef _LUSTRE_MD_OBJECT_H
26 #define _LUSTRE_MD_OBJECT_H
27
28 /*
29  * Sub-class of lu_object with methods common for "meta-data" objects in MDT
30  * stack.
31  *
32  * Meta-data objects implement namespace operations: you can link, unlink
33  * them, and treat them as directories.
34  *
35  * Examples: mdt, cmm, and mdt are implementations of md interface.
36  */
37
38
39 /*
40  * super-class definitions.
41  */
42 #include <lu_object.h>
43 #include <lvfs.h>
44
45 struct md_device;
46 struct md_device_operations;
47 struct md_object;
48
49
50 typedef enum {
51         UCRED_INVALID   = -1,
52         UCRED_INIT      = 0,
53         UCRED_OLD       = 1,
54         UCRED_NEW       = 2,
55 } ucred_t;
56
57 #define SQUASH_NONE     0x00
58 #define SQUASH_UID      0x01
59 #define SQUASH_GID      0x02
60
61 struct md_ucred {
62         ucred_t                 mu_valid;
63         __u32                   mu_squash;
64         __u32                   mu_o_uid;
65         __u32                   mu_o_gid;
66         __u32                   mu_o_fsuid;
67         __u32                   mu_o_fsgid;
68         __u32                   mu_uid;
69         __u32                   mu_gid;
70         __u32                   mu_fsuid;
71         __u32                   mu_fsgid;
72         __u32                   mu_suppgids[2];
73         __u32                   mu_cap;
74         __u32                   mu_umask;
75         struct group_info      *mu_ginfo;
76         struct mdt_identity    *mu_identity;
77 };
78
79 /* there are at most 4 fid in one operation, see rename */
80 struct md_capainfo {
81         const struct lu_fid    *mc_fid[4];
82         struct lustre_capa     *mc_capa[4];
83 };
84
85 /*
86  * Implemented in mdd/mdd_handler.c.
87  *
88  * XXX should be moved into separate .h/.c together with all md security
89  * related definitions.
90  */
91 struct md_ucred *md_ucred(const struct lu_env *env);
92 struct md_capainfo *md_capainfo(const struct lu_env *env);
93
94 /* metadata attributes */
95 enum ma_valid {
96         MA_INODE   = (1 << 0),
97         MA_LOV     = (1 << 1),
98         MA_COOKIE  = (1 << 2),
99         MA_FLAGS   = (1 << 3),
100         MA_LMV     = (1 << 4),
101         MA_ACL_DEF = (1 << 5)
102 };
103
104 struct md_attr {
105         __u64                   ma_valid;
106         __u64                   ma_need;
107         __u64                   ma_attr_flags;
108         struct lu_attr          ma_attr;
109         struct lov_mds_md      *ma_lmm;
110         int                     ma_lmm_size;
111         struct lmv_stripe_md   *ma_lmv;
112         int                     ma_lmv_size;
113         void                   *ma_acl;
114         int                     ma_acl_size;
115         struct llog_cookie     *ma_cookie;
116         int                     ma_cookie_size;
117 };
118
119 /* additional parameters for create */
120 struct md_create_spec {
121         union {
122                 /* symlink target */
123                 const char               *sp_symname;
124                 /* parent FID for cross-ref mkdir */
125                 const struct lu_fid      *sp_pfid;
126                 /* eadata for regular files */
127                 struct md_spec_reg {
128                         /* lov objs exist already */
129                         const struct lu_fid   *fid;
130                         int no_lov_create;
131                         const void *eadata;
132                         int  eadatalen;
133                 } sp_ea;
134         } u;
135         /* create flag from client: such as MDS_OPEN_CREAT, and others */
136         __u32 sp_cr_flags;
137 };
138
139 /*
140  * Operations implemented for each md object (both directory and leaf).
141  */
142 struct md_object_operations {
143         int (*moo_permission)(const struct lu_env *env,
144                               struct md_object *obj, int mask);
145
146         int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
147                             struct md_attr *attr);
148
149         int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
150                             const struct md_attr *attr);
151
152         int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
153                              struct lu_buf *buf, const char *name);
154
155         int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
156                               struct lu_buf *buf);
157
158         int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
159                              const struct lu_buf *buf, const char *name,
160                              int fl);
161
162         int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
163                              const char *name);
164
165         int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
166                             const struct lu_rdpg *rdpg);
167
168         int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
169                             struct lu_buf *buf);
170
171         /* part of cross-ref operation */
172         int (*moo_object_create)(const struct lu_env *env,
173                                  struct md_object *obj,
174                                  const struct md_create_spec *spec,
175                                  struct md_attr *ma);
176
177         int (*moo_ref_add)(const struct lu_env *env, struct md_object *obj);
178
179         int (*moo_ref_del)(const struct lu_env *env,
180                            struct md_object *obj, struct md_attr *ma);
181
182         int (*moo_open)(const struct lu_env *env,
183                         struct md_object *obj, int flag);
184
185         int (*moo_close)(const struct lu_env *env, struct md_object *obj,
186                          struct md_attr *ma);
187         int (*moo_capa_get)(const struct lu_env *, struct md_object *,
188                             struct lustre_capa *, int renewal);
189 };
190
191 /*
192  * Operations implemented for each directory object.
193  */
194 struct md_dir_operations {
195         int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
196                               const struct lu_fid *fid, struct lu_fid *sfid);
197
198         int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
199                           const char *name, struct lu_fid *fid);
200
201         lu_mode_t (*mdo_lock_mode)(const struct lu_env *env, struct md_object *obj,
202                                    lu_mode_t mode);
203
204         int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
205                           const char *name, struct md_object *child,
206                           struct md_create_spec *spec,
207                           struct md_attr *ma);
208
209         /* This method is used for creating data object for this meta object*/
210         int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
211                                struct md_object *o,
212                                const struct md_create_spec *spec,
213                                struct md_attr *ma);
214
215         int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
216                           struct md_object *tpobj, const struct lu_fid *lf,
217                           const char *sname, struct md_object *tobj,
218                           const char *tname, struct md_attr *ma);
219
220         int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
221                         struct md_object *src_obj, const char *name,
222                         struct md_attr *ma);
223
224         int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
225                           struct md_object *cobj, const char *name,
226                           struct md_attr *ma);
227
228         /* partial ops for cross-ref case */
229         int (*mdo_name_insert)(const struct lu_env *env, struct md_object *obj,
230                                const char *name, const struct lu_fid *fid,
231                                int isdir);
232
233         int (*mdo_name_remove)(const struct lu_env *env, struct md_object *obj,
234                                const char *name, int is_dir);
235
236         int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
237                               struct md_object *tobj, const struct lu_fid *fid,
238                               const char *name, struct md_attr *ma);
239 };
240
241 struct md_device_operations {
242         /* meta-data device related handlers. */
243         int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
244                             struct lu_fid *f);
245
246         int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
247                                int *md_size, int *cookie_size);
248
249         int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
250                           struct kstatfs *sfs);
251
252         int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
253                                   int mode, unsigned long timeout, __u32 alg,
254                                   struct lustre_capa_key *keys);
255
256         int (*mdo_update_capa_key)(const struct lu_env *env,
257                                    struct md_device *m,
258                                    struct lustre_capa_key *key);
259 };
260
261 enum md_upcall_event {
262         /*sync the md layer*/
263         MD_LOV_SYNC = (1 << 0),
264         MD_NO_TRANS = (1 << 1), /* Just for split, no need trans, for replay */
265 };
266
267 struct md_upcall {
268         struct md_device            *mu_upcall_dev;
269         int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
270                          enum md_upcall_event ev);
271 };
272
273 struct md_device {
274         struct lu_device             md_lu_dev;
275         struct md_device_operations *md_ops;
276         struct md_upcall             md_upcall;
277 };
278
279 struct md_object {
280         struct lu_object             mo_lu;
281         struct md_object_operations *mo_ops;
282         struct md_dir_operations    *mo_dir_ops;
283 };
284
285 static inline int lu_device_is_md(const struct lu_device *d)
286 {
287         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
288 }
289
290 static inline struct md_device *lu2md_dev(const struct lu_device *d)
291 {
292         LASSERT(lu_device_is_md(d));
293         return container_of0(d, struct md_device, md_lu_dev);
294 }
295
296 static inline struct lu_device *md2lu_dev(struct md_device *d)
297 {
298         return &d->md_lu_dev;
299 }
300
301 static inline struct md_object *lu2md(const struct lu_object *o)
302 {
303         LASSERT(lu_device_is_md(o->lo_dev));
304         return container_of0(o, struct md_object, mo_lu);
305 }
306
307 static inline struct md_object *md_object_next(const struct md_object *obj)
308 {
309         return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
310 }
311
312 static inline struct md_device *md_obj2dev(const struct md_object *o)
313 {
314         LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
315         return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
316 }
317
318 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
319 {
320         return lu_device_init(&md->md_lu_dev, t);
321 }
322
323 static inline void md_device_fini(struct md_device *md)
324 {
325         lu_device_fini(&md->md_lu_dev);
326 }
327
328 /* md operations */
329 static inline int mo_permission(const struct lu_env *env,
330                                 struct md_object *m,
331                                 int mask)
332 {
333         LASSERT(m->mo_ops->moo_permission);
334         return m->mo_ops->moo_permission(env, m, mask);
335 }
336
337 static inline int mo_attr_get(const struct lu_env *env,
338                               struct md_object *m,
339                               struct md_attr *at)
340 {
341         LASSERT(m->mo_ops->moo_attr_get);
342         return m->mo_ops->moo_attr_get(env, m, at);
343 }
344
345 static inline int mo_readlink(const struct lu_env *env,
346                               struct md_object *m,
347                               struct lu_buf *buf)
348 {
349         LASSERT(m->mo_ops->moo_readlink);
350         return m->mo_ops->moo_readlink(env, m, buf);
351 }
352
353 static inline int mo_attr_set(const struct lu_env *env,
354                               struct md_object *m,
355                               const struct md_attr *at)
356 {
357         LASSERT(m->mo_ops->moo_attr_set);
358         return m->mo_ops->moo_attr_set(env, m, at);
359 }
360
361 static inline int mo_xattr_get(const struct lu_env *env,
362                                struct md_object *m,
363                                struct lu_buf *buf,
364                                const char *name)
365 {
366         LASSERT(m->mo_ops->moo_xattr_get);
367         return m->mo_ops->moo_xattr_get(env, m, buf, name);
368 }
369
370 static inline int mo_xattr_del(const struct lu_env *env,
371                                struct md_object *m,
372                                const char *name)
373 {
374         LASSERT(m->mo_ops->moo_xattr_del);
375         return m->mo_ops->moo_xattr_del(env, m, name);
376 }
377
378 static inline int mo_xattr_set(const struct lu_env *env,
379                                struct md_object *m,
380                                const struct lu_buf *buf,
381                                const char *name,
382                                int flags)
383 {
384         LASSERT(m->mo_ops->moo_xattr_set);
385         return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
386 }
387
388 static inline int mo_xattr_list(const struct lu_env *env,
389                                 struct md_object *m,
390                                 struct lu_buf *buf)
391 {
392         LASSERT(m->mo_ops->moo_xattr_list);
393         return m->mo_ops->moo_xattr_list(env, m, buf);
394 }
395
396 static inline int mo_open(const struct lu_env *env,
397                           struct md_object *m,
398                           int flags)
399 {
400         LASSERT(m->mo_ops->moo_open);
401         return m->mo_ops->moo_open(env, m, flags);
402 }
403
404 static inline int mo_close(const struct lu_env *env,
405                            struct md_object *m,
406                            struct md_attr *ma)
407 {
408         LASSERT(m->mo_ops->moo_close);
409         return m->mo_ops->moo_close(env, m, ma);
410 }
411
412 static inline int mo_readpage(const struct lu_env *env,
413                               struct md_object *m,
414                               const struct lu_rdpg *rdpg)
415 {
416         LASSERT(m->mo_ops->moo_readpage);
417         return m->mo_ops->moo_readpage(env, m, rdpg);
418 }
419
420 static inline int mo_object_create(const struct lu_env *env,
421                                    struct md_object *m,
422                                    const struct md_create_spec *spc,
423                                    struct md_attr *at)
424 {
425         LASSERT(m->mo_ops->moo_object_create);
426         return m->mo_ops->moo_object_create(env, m, spc, at);
427 }
428
429 static inline int mo_ref_add(const struct lu_env *env,
430                              struct md_object *m)
431 {
432         LASSERT(m->mo_ops->moo_ref_add);
433         return m->mo_ops->moo_ref_add(env, m);
434 }
435
436 static inline int mo_ref_del(const struct lu_env *env,
437                              struct md_object *m,
438                              struct md_attr *ma)
439 {
440         LASSERT(m->mo_ops->moo_ref_del);
441         return m->mo_ops->moo_ref_del(env, m, ma);
442 }
443
444 static inline int mo_capa_get(const struct lu_env *env,
445                               struct md_object *m,
446                               struct lustre_capa *c,
447                               int renewal)
448 {
449         LASSERT(m->mo_ops->moo_capa_get);
450         return m->mo_ops->moo_capa_get(env, m, c, renewal);
451 }
452
453 static inline int mdo_lookup(const struct lu_env *env,
454                              struct md_object *p,
455                              const char *name,
456                              struct lu_fid *f)
457 {
458         LASSERT(p->mo_dir_ops->mdo_lookup);
459         return p->mo_dir_ops->mdo_lookup(env, p, name, f);
460 }
461
462 static inline lu_mode_t mdo_lock_mode(const struct lu_env *env,
463                                       struct md_object *mo,
464                                       lu_mode_t lm)
465 {
466         if (mo->mo_dir_ops->mdo_lock_mode == NULL)
467                 return LU_MINMODE;
468         return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
469 }
470
471 static inline int mdo_create(const struct lu_env *env,
472                              struct md_object *p,
473                              const char *child_name,
474                              struct md_object *c,
475                              struct md_create_spec *spc,
476                              struct md_attr *at)
477 {
478         LASSERT(c->mo_dir_ops->mdo_create);
479         return c->mo_dir_ops->mdo_create(env, p, child_name, c, spc, at);
480 }
481
482 static inline int mdo_create_data(const struct lu_env *env,
483                                   struct md_object *p,
484                                   struct md_object *c,
485                                   const struct md_create_spec *spec,
486                                   struct md_attr *ma)
487 {
488         LASSERT(c->mo_dir_ops->mdo_create_data);
489         return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
490 }
491
492 static inline int mdo_rename(const struct lu_env *env,
493                              struct md_object *sp,
494                              struct md_object *tp,
495                              const struct lu_fid *lf,
496                              const char *sname,
497                              struct md_object *t,
498                              const char *tname,
499                              struct md_attr *ma)
500 {
501         LASSERT(tp->mo_dir_ops->mdo_rename);
502         return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, sname, t, tname, ma);
503 }
504
505 static inline int mdo_is_subdir(const struct lu_env *env,
506                                 struct md_object *mo,
507                                 const struct lu_fid *fid,
508                                 struct lu_fid *sfid)
509 {
510         LASSERT(mo->mo_dir_ops->mdo_is_subdir);
511         return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
512 }
513
514 static inline int mdo_link(const struct lu_env *env,
515                            struct md_object *p,
516                            struct md_object *s,
517                            const char *name,
518                            struct md_attr *ma)
519 {
520         LASSERT(s->mo_dir_ops->mdo_link);
521         return s->mo_dir_ops->mdo_link(env, p, s, name, ma);
522 }
523
524 static inline int mdo_unlink(const struct lu_env *env,
525                              struct md_object *p,
526                              struct md_object *c,
527                              const char *name,
528                              struct md_attr *ma)
529 {
530         LASSERT(c->mo_dir_ops->mdo_unlink);
531         return c->mo_dir_ops->mdo_unlink(env, p, c, name, ma);
532 }
533
534 static inline int mdo_name_insert(const struct lu_env *env,
535                                   struct md_object *p,
536                                   const char *name,
537                                   const struct lu_fid *f,
538                                   int isdir)
539 {
540         LASSERT(p->mo_dir_ops->mdo_name_insert);
541         return p->mo_dir_ops->mdo_name_insert(env, p, name, f, isdir);
542 }
543
544 static inline int mdo_name_remove(const struct lu_env *env,
545                                   struct md_object *p,
546                                   const char *name, int is_dir)
547 {
548         LASSERT(p->mo_dir_ops->mdo_name_remove);
549         return p->mo_dir_ops->mdo_name_remove(env, p, name, is_dir);
550 }
551
552 static inline int mdo_rename_tgt(const struct lu_env *env,
553                                  struct md_object *p,
554                                  struct md_object *t,
555                                  const struct lu_fid *lf,
556                                  const char *name,
557                                  struct md_attr *ma)
558 {
559         if (t) {
560                 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
561                 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, name, ma);
562         } else {
563                 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
564                 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, name, ma);
565         }
566 }
567
568 #endif /* _LINUX_MD_OBJECT_H */