Whamcloud - gitweb
LU-1842 quota: add quota disk operations
[fs/lustre-release.git] / lustre / quota / lquota_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 021110-1307, USA
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2012 Whamcloud, Inc.
25  * Use is subject to license terms.
26  */
27
28 #include <obd.h>
29 #include <lquota.h>
30
31 #ifndef _LQUOTA_INTERNAL_H
32 #define _LQUOTA_INTERNAL_H
33
34 #define QTYPE_NAME(qtype) ((qtype) == USRQUOTA ? "usr" : "grp")
35
36 #define QIF_IFLAGS (QIF_INODES | QIF_ITIME | QIF_ILIMITS)
37 #define QIF_BFLAGS (QIF_SPACE | QIF_BTIME | QIF_BLIMITS)
38
39 /* The biggest filename are the one used for slave index which are in the form
40  * of 0x%x-%s,glb_fid.f_oid,slv_uuid, that's to say:
41  * 2(0x) + 8(f_oid) + 1(-) + 40(UUID_MAX) which means 51 chars + '\0' */
42 #define LQUOTA_NAME_MAX 52
43
44 /* reserved OID in FID_SEQ_QUOTA for local objects */
45 enum lquota_local_oid {
46         LQUOTA_USR_OID          = 1UL, /* slave index copy for user quota */
47         LQUOTA_GRP_OID          = 2UL, /* slave index copy for group quota */
48         /* all OIDs after this are allocated dynamically by the QMT */
49         LQUOTA_GENERATED_OID    = 4096UL,
50 };
51
52 /* Common data shared by quota-level handlers. This is allocated per-thread to
53  * reduce stack consumption */
54 struct lquota_thread_info {
55         union  lquota_rec       qti_rec;
56         struct lu_buf           qti_lb;
57         struct lu_attr          qti_attr;
58         struct dt_object_format qti_dof;
59         struct lustre_mdt_attrs qti_lma;
60         struct lu_fid           qti_fid;
61         char                    qti_buf[LQUOTA_NAME_MAX];
62 };
63
64 #define qti_glb_rec     qti_rec.lqr_glb_rec
65 #define qti_acct_rec    qti_rec.lqr_acct_rec
66 #define qti_slv_rec     qti_rec.lqr_slv_rec
67
68 #define LQUOTA_BUMP_VER 0x1
69 #define LQUOTA_SET_VER  0x2
70
71 extern struct lu_context_key lquota_thread_key;
72
73 /* extract lquota_threa_info context from environment */
74 static inline
75 struct lquota_thread_info *lquota_info(const struct lu_env *env)
76 {
77         struct lquota_thread_info       *info;
78
79         info = lu_context_key_get(&env->le_ctx, &lquota_thread_key);
80         if (info == NULL) {
81                 lu_env_refill((struct lu_env *)env);
82                 info = lu_context_key_get(&env->le_ctx, &lquota_thread_key);
83         }
84         LASSERT(info);
85         return info;
86 }
87
88 /* lquota_lib.c */
89 struct dt_object *acct_obj_lookup(const struct lu_env *, struct dt_device *,
90                                   int);
91 void lquota_generate_fid(struct lu_fid *, int, int, int);
92 int lquota_extract_fid(struct lu_fid *, int *, int *, int *);
93 const struct dt_index_features *glb_idx_feature(struct lu_fid *);
94
95 /* lquota_disk.c */
96 struct dt_object *lquota_disk_dir_find_create(const struct lu_env *,
97                                               struct dt_device *,
98                                               struct dt_object *, const char *);
99 struct dt_object *lquota_disk_glb_find_create(const struct lu_env *,
100                                               struct dt_device *,
101                                               struct dt_object *,
102                                               struct lu_fid *, bool);
103 struct dt_object *lquota_disk_slv_find_create(const struct lu_env *,
104                                               struct dt_device *,
105                                               struct dt_object *,
106                                               struct lu_fid *,
107                                               struct obd_uuid *, bool);
108 typedef int (*lquota_disk_slv_cb_t) (const struct lu_env *, struct lu_fid *,
109                                      char *, struct lu_fid *, void *);
110 int lquota_disk_for_each_slv(const struct lu_env *, struct dt_object *,
111                              struct lu_fid *, lquota_disk_slv_cb_t, void *);
112 struct dt_object *lquota_disk_slv_find(const struct lu_env *,
113                                        struct dt_device *, struct dt_object *,
114                                        struct lu_fid *, struct obd_uuid *);
115 int lquota_disk_read(const struct lu_env *, struct dt_object *,
116                      union lquota_id *, struct dt_rec *);
117 int lquota_disk_declare_write(const struct lu_env *, struct thandle *,
118                               struct dt_object *, union lquota_id *);
119 int lquota_disk_write(const struct lu_env *, struct thandle *,
120                       struct dt_object *, union lquota_id *, struct dt_rec *,
121                       __u32, __u64 *);
122 int lquota_disk_update_ver(const struct lu_env *, struct dt_device *,
123                            struct dt_object *, __u64);
124
125 /* lproc_quota.c */
126 extern struct file_operations lprocfs_quota_seq_fops;
127
128 /* quota_interface.c
129  * old quota module initialization routines, to be removed */
130 int init_lustre_quota(void);
131 void exit_lustre_quota(void);
132
133 #endif /* _LQUOTA_INTERNAL_H */