4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
24 * Copyright (c) 2012 Whamcloud, Inc.
25 * Use is subject to license terms.
28 #include "lquota_internal.h"
30 #ifndef _QSD_INTERNAL_H
31 #define _QSD_INTERNAL_H
36 * A QSD instance implements quota enforcement support for a given OSD.
37 * The instance can be created via qsd_init() and then freed with qsd_fini().
38 * This structure gathers all quota parameters and pointers to on-disk indexes
39 * required on quota slave to:
40 * i. acquire/release quota space from the QMT;
41 * ii. allocate this quota space to local requests.
44 /* name of service which created this qsd instance */
45 char qsd_svname[MAX_OBD_NAME];
47 /* pool ID is always 0 for now */
50 /* dt_device associated with this qsd instance */
51 struct dt_device *qsd_dev;
53 /* procfs directory where information related to the underlying slaves
55 cfs_proc_dir_entry_t *qsd_proc;
57 /* on-disk directory where to store index files for this qsd instance */
58 struct dt_object *qsd_root;
60 /* We create 2 quota slave instances:
61 * - one for user quota
62 * - one for group quota
64 * This will have to be revisited if new quota types are added in the
65 * future. For the time being, we can just use an array. */
66 struct qsd_qtype_info *qsd_type_array[MAXQUOTAS];
68 unsigned long qsd_is_md:1, /* managing quota for mdt */
69 qsd_stopping:1; /* qsd_instance is stopping */
73 * Per-type quota information.
74 * Quota slave instance for a specific quota type. The qsd instance has one such
75 * structure for each quota type (i.e. user & group).
77 struct qsd_qtype_info {
78 /* reference count incremented by each user of this structure */
81 /* quota type, either USRQUOTA or GRPQUOTA
82 * immutable after creation. */
85 /* Global index FID to use for this quota type */
86 struct lu_fid qqi_fid;
88 /* back pointer to qsd device
89 * immutable after creation. */
90 struct qsd_instance *qqi_qsd;
92 /* Local index files storing quota settings for this quota type */
93 struct dt_object *qqi_acct_obj; /* accounting object */
94 struct dt_object *qqi_slv_obj; /* slave index copy */
95 struct dt_object *qqi_glb_obj; /* global index copy */
97 /* Current object versions */
98 __u64 qqi_slv_ver; /* slave index version */
99 __u64 qqi_glb_ver; /* global index version */
103 * Helper functions & prototypes
106 /* qqi_getref/putref is used to track users of a qqi structure */
107 static inline void qqi_getref(struct qsd_qtype_info *qqi)
109 cfs_atomic_inc(&qqi->qqi_ref);
112 static inline void qqi_putref(struct qsd_qtype_info *qqi)
114 LASSERT(cfs_atomic_read(&qqi->qqi_ref) > 0);
115 cfs_atomic_dec(&qqi->qqi_ref);
118 #define QSD_RES_TYPE(qsd) ((qsd)->qsd_is_md ? LQUOTA_RES_MD : LQUOTA_RES_DT)
120 /* Common data shared by qsd-level handlers. This is allocated per-thread to
121 * reduce stack consumption. */
122 struct qsd_thread_info {
123 union lquota_rec qti_rec;
124 union lquota_id qti_id;
125 struct lu_fid qti_fid;
126 struct ldlm_res_id qti_resid;
127 struct ldlm_enqueue_info qti_einfo;
128 struct lustre_handle qti_lockh;
130 union ldlm_wire_lvb qti_lvb;
132 struct quota_body qti_body;
133 struct idx_info qti_ii;
135 char qti_buf[MTI_NAME_MAXLEN];
138 extern struct lu_context_key qsd_thread_key;
141 struct qsd_thread_info *qsd_info(const struct lu_env *env)
143 struct qsd_thread_info *info;
145 info = lu_context_key_get(&env->le_ctx, &qsd_thread_key);
151 typedef void (*qsd_req_completion_t) (const struct lu_env *,
152 struct qsd_qtype_info *,
153 struct quota_body *, struct quota_body *,
154 struct lustre_handle *,
155 union ldlm_wire_lvb *, void *, int);
156 int qsd_send_dqacq(const struct lu_env *, struct obd_export *,
157 struct quota_body *, bool, qsd_req_completion_t,
158 struct qsd_qtype_info *, struct lustre_handle *,
159 struct lquota_entry *);
160 int qsd_intent_lock(const struct lu_env *, struct obd_export *,
161 struct quota_body *, bool, int, qsd_req_completion_t,
162 struct qsd_qtype_info *, union ldlm_wire_lvb *, void *);
163 int qsd_fetch_index(const struct lu_env *, struct obd_export *,
164 struct idx_info *, unsigned int, cfs_page_t **, bool *);
166 #endif /* _QSD_INTERNAL_H */