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, 2016, Intel Corporation.
25 * Use is subject to license terms.
27 * Author: Johann Lombardi <johann.lombardi@intel.com>
28 * Author: Niu Yawei <yawei.niu@intel.com>
32 * Quota Slave Driver (QSD) management.
34 * The quota slave feature is implemented under the form of a library called
35 * QSD. Each OSD device should create a QSD instance via qsd_init() which will
36 * be used to manage quota enforcement for this device. This implies:
37 * - completing the reintegration procedure with the quota master (aka QMT, see
38 * qmt_dev.c) to retrieve the latest quota settings and space distribution.
39 * - managing quota locks in order to be notified of configuration changes.
40 * - acquiring space from the QMT when quota space for a given user/group is
41 * close to exhaustion.
42 * - allocating quota space to service threads for local request processing.
44 * Once the QSD instance created, the OSD device should invoke qsd_start()
45 * when recovery is completed. This notifies the QSD that we are about to
46 * process new requests on which quota should be strictly enforced.
47 * Then, qsd_op_begin/end can be used to reserve/release/pre-acquire quota space
48 * for/after each operation until shutdown where the QSD instance should be
49 * freed via qsd_fini().
52 #define DEBUG_SUBSYSTEM S_LQUOTA
54 #include <obd_class.h>
55 #include "qsd_internal.h"
57 struct kmem_cache *upd_kmem;
59 struct lu_kmem_descr qsd_caches[] = {
61 .ckd_cache = &upd_kmem,
62 .ckd_name = "upd_kmem",
63 .ckd_size = sizeof(struct qsd_upd_rec)
70 /* define qsd thread key */
71 LU_KEY_INIT_FINI(qsd, struct qsd_thread_info);
72 LU_CONTEXT_KEY_DEFINE(qsd, LCT_MD_THREAD | LCT_DT_THREAD | LCT_LOCAL);
73 LU_KEY_INIT_GENERIC(qsd);
75 /* some procfs helpers */
76 static int qsd_state_seq_show(struct seq_file *m, void *data)
78 struct qsd_instance *qsd = m->private;
83 memset(enabled, 0, sizeof(enabled));
84 if (qsd_type_enabled(qsd, USRQUOTA))
86 if (qsd_type_enabled(qsd, GRPQUOTA))
88 if (qsd_type_enabled(qsd, PRJQUOTA))
89 strncat(enabled, "p", 1);
90 if (strlen(enabled) == 0)
91 strcat(enabled, "none");
93 seq_printf(m, "target name: %s\n"
97 "conn to master: %s\n",
98 qsd->qsd_svname, qsd->qsd_pool_id,
99 qsd->qsd_is_md ? "md" : "dt", enabled,
100 qsd->qsd_exp_valid ? "setup" : "not setup yet");
102 if (qsd->qsd_prepared) {
103 memset(enabled, 0, sizeof(enabled));
104 if (qsd->qsd_type_array[USRQUOTA]->qqi_acct_obj != NULL)
105 strcat(enabled, "u");
106 if (qsd->qsd_type_array[GRPQUOTA]->qqi_acct_obj != NULL)
107 strcat(enabled, "g");
108 if (qsd->qsd_type_array[PRJQUOTA]->qqi_acct_obj != NULL)
109 strncat(enabled, "p", 1);
110 if (strlen(enabled) == 0)
111 strcat(enabled, "none");
112 seq_printf(m, "space acct: %s\n"
113 "user uptodate: glb[%d],slv[%d],reint[%d]\n"
114 "group uptodate: glb[%d],slv[%d],reint[%d]\n"
115 "project uptodate: glb[%d],slv[%d],reint[%d]\n",
117 qsd->qsd_type_array[USRQUOTA]->qqi_glb_uptodate,
118 qsd->qsd_type_array[USRQUOTA]->qqi_slv_uptodate,
119 qsd->qsd_type_array[USRQUOTA]->qqi_reint,
120 qsd->qsd_type_array[GRPQUOTA]->qqi_glb_uptodate,
121 qsd->qsd_type_array[GRPQUOTA]->qqi_slv_uptodate,
122 qsd->qsd_type_array[GRPQUOTA]->qqi_reint,
123 qsd->qsd_type_array[PRJQUOTA]->qqi_glb_uptodate,
124 qsd->qsd_type_array[PRJQUOTA]->qqi_slv_uptodate,
125 qsd->qsd_type_array[PRJQUOTA]->qqi_reint);
129 LPROC_SEQ_FOPS_RO(qsd_state);
131 static int qsd_enabled_seq_show(struct seq_file *m, void *data)
133 struct qsd_instance *qsd = m->private;
136 LASSERT(qsd != NULL);
138 memset(enabled, 0, sizeof(enabled));
139 if (qsd_type_enabled(qsd, USRQUOTA))
140 strcat(enabled, "u");
141 if (qsd_type_enabled(qsd, GRPQUOTA))
142 strcat(enabled, "g");
143 if (qsd_type_enabled(qsd, PRJQUOTA))
144 strncat(enabled, "p", 1);
145 if (strlen(enabled) == 0)
146 strcat(enabled, "none");
148 seq_printf(m, "%s\n", enabled);
151 LPROC_SEQ_FOPS_RO(qsd_enabled);
153 /* force reintegration procedure to be executed.
154 * Used for test/debugging purpose */
156 lprocfs_force_reint_seq_write(struct file *file, const char __user *buffer,
157 size_t count, loff_t *off)
159 struct qsd_instance *qsd = ((struct seq_file *)file->private_data)->private;
162 LASSERT(qsd != NULL);
164 write_lock(&qsd->qsd_lock);
165 if (qsd->qsd_stopping) {
166 /* don't mess up with shutdown procedure, it is already
167 * complicated enough */
169 } else if (!qsd->qsd_prepared) {
172 /* mark all indexes as stale */
173 for (qtype = USRQUOTA; qtype < LL_MAXQUOTAS; qtype++) {
174 qsd->qsd_type_array[qtype]->qqi_glb_uptodate = false;
175 qsd->qsd_type_array[qtype]->qqi_slv_uptodate = false;
178 write_unlock(&qsd->qsd_lock);
183 /* kick off reintegration */
184 for (qtype = USRQUOTA; qtype < LL_MAXQUOTAS; qtype++) {
185 rc = qsd_start_reint_thread(qsd->qsd_type_array[qtype]);
189 return rc == 0 ? count : rc;
191 LPROC_SEQ_FOPS_WO_TYPE(qsd, force_reint);
193 static int qsd_timeout_seq_show(struct seq_file *m, void *data)
195 struct qsd_instance *qsd = m->private;
196 LASSERT(qsd != NULL);
198 seq_printf(m, "%d\n", qsd_wait_timeout(qsd));
203 qsd_timeout_seq_write(struct file *file, const char __user *buffer,
204 size_t count, loff_t *off)
206 struct qsd_instance *qsd = ((struct seq_file *)file->private_data)->private;
209 LASSERT(qsd != NULL);
211 rc = lprocfs_str_to_s64(buffer, count, &timeout);
214 if (timeout < 0 || timeout > INT_MAX)
217 qsd->qsd_timeout = timeout;
220 LPROC_SEQ_FOPS(qsd_timeout);
222 static struct lprocfs_vars lprocfs_quota_qsd_vars[] = {
224 .fops = &qsd_state_fops },
226 .fops = &qsd_enabled_fops },
227 { .name = "force_reint",
228 .fops = &qsd_force_reint_fops },
230 .fops = &qsd_timeout_fops },
235 * Callback function invoked by the OSP layer when the connection to the master
238 * \param data - is a pointer to the qsd_instance
240 * \retval - 0 on success, appropriate error on failure
242 static int qsd_conn_callback(void *data)
244 struct qsd_instance *qsd = (struct qsd_instance *)data;
248 /* qsd_exp should now be valid */
249 LASSERT(qsd->qsd_exp);
251 qsd->qsd_ns = class_exp2obd(qsd->qsd_exp)->obd_namespace;
253 write_lock(&qsd->qsd_lock);
254 /* notify that qsd_exp is now valid */
255 qsd->qsd_exp_valid = true;
256 write_unlock(&qsd->qsd_lock);
258 /* Now that the connection to master is setup, we can initiate the
259 * reintegration procedure for quota types which are enabled.
260 * It is worth noting that, if the qsd_instance hasn't been started
261 * already, then we can only complete the first two steps of the
262 * reintegration procedure (i.e. global lock enqueue and slave
263 * index transfer) since the space usage reconciliation (i.e.
264 * step 3) will have to wait for qsd_start() to be called */
265 for (type = USRQUOTA; type < LL_MAXQUOTAS; type++) {
266 struct qsd_qtype_info *qqi = qsd->qsd_type_array[type];
267 wake_up(&qqi->qqi_reint_thread.t_ctl_waitq);
274 * Release qsd_qtype_info structure which contains data associated with a
275 * given quota type. This releases the accounting objects.
276 * It's called on OSD cleanup when the qsd instance is released.
278 * \param env - is the environment passed by the caller
279 * \param qsd - is the qsd instance managing the qsd_qtype_info structure
281 * \param qtype - is the quota type to be shutdown
283 static void qsd_qtype_fini(const struct lu_env *env, struct qsd_instance *qsd,
286 struct qsd_qtype_info *qqi;
290 if (qsd->qsd_type_array[qtype] == NULL)
292 qqi = qsd->qsd_type_array[qtype];
293 qsd->qsd_type_array[qtype] = NULL;
295 /* all deferred work lists should be empty */
296 LASSERT(list_empty(&qqi->qqi_deferred_glb));
297 LASSERT(list_empty(&qqi->qqi_deferred_slv));
299 /* shutdown lquota site */
300 if (qqi->qqi_site != NULL && !IS_ERR(qqi->qqi_site)) {
301 lquota_site_free(env, qqi->qqi_site);
302 qqi->qqi_site = NULL;
305 /* The qqi may still be holding by global locks which are being
306 * canceled asynchronously (LU-4365), see the following steps:
308 * - On server umount, we try to clear all quota locks first by
309 * disconnecting LWP (which will invalidate import and cleanup
310 * all locks on it), however, if quota reint process is holding
311 * the global lock for reintegration at that time, global lock
312 * will fail to be cleared on LWP disconnection.
314 * - Umount process goes on and stops reint process, the global
315 * lock will be dropped on reint process exit, however, the lock
316 * cancel in done in asynchronous way, so the
317 * qsd_glb_blocking_ast() might haven't been called yet when we
320 while (atomic_read(&qqi->qqi_ref) > 1) {
321 CDEBUG(D_QUOTA, "qqi reference count %u, repeat: %d\n",
322 atomic_read(&qqi->qqi_ref), repeat);
324 set_current_state(TASK_INTERRUPTIBLE);
325 schedule_timeout(cfs_time_seconds(1));
328 /* by now, all qqi users should have gone away */
329 LASSERT(atomic_read(&qqi->qqi_ref) == 1);
330 lu_ref_fini(&qqi->qqi_reference);
332 /* release accounting object */
333 if (qqi->qqi_acct_obj != NULL && !IS_ERR(qqi->qqi_acct_obj)) {
334 dt_object_put(env, qqi->qqi_acct_obj);
335 qqi->qqi_acct_obj = NULL;
338 /* release slv index */
339 if (qqi->qqi_slv_obj != NULL && !IS_ERR(qqi->qqi_slv_obj)) {
340 dt_object_put(env, qqi->qqi_slv_obj);
341 qqi->qqi_slv_obj = NULL;
342 qqi->qqi_slv_ver = 0;
345 /* release global index */
346 if (qqi->qqi_glb_obj != NULL && !IS_ERR(qqi->qqi_glb_obj)) {
347 dt_object_put(env, qqi->qqi_glb_obj);
348 qqi->qqi_glb_obj = NULL;
349 qqi->qqi_glb_ver = 0;
356 static const char *qtype2acct_name(int qtype)
364 return "acct_project";
367 LASSERTF(0, "invalid quota type: %d", qtype);
371 static const char *qtype2glb_name(int qtype)
377 return "limit_group";
379 return "limit_project";
382 LASSERTF(0, "invalid quota type: %d", qtype);
387 * Allocate and initialize a qsd_qtype_info structure for quota type \qtype.
388 * This opens the accounting object and initializes the proc file.
389 * It's called on OSD start when the qsd_prepare() is invoked on the qsd
392 * \param env - the environment passed by the caller
393 * \param qsd - is the qsd instance which will be in charge of the new
394 * qsd_qtype_info instance.
395 * \param qtype - is quota type to set up
397 * \retval - 0 on success and qsd->qsd_type_array[qtype] is allocated,
398 * appropriate error on failure
400 static int qsd_qtype_init(const struct lu_env *env, struct qsd_instance *qsd,
403 struct qsd_qtype_info *qqi;
405 struct obd_uuid uuid;
408 LASSERT(qsd->qsd_type_array[qtype] == NULL);
410 /* allocate structure for this quota type */
414 qsd->qsd_type_array[qtype] = qqi;
415 atomic_set(&qqi->qqi_ref, 1); /* referenced from qsd */
417 /* set backpointer and other parameters */
419 qqi->qqi_qtype = qtype;
420 lu_ref_init(&qqi->qqi_reference);
421 qqi->qqi_glb_uptodate = false;
422 qqi->qqi_slv_uptodate = false;
423 qqi->qqi_reint = false;
424 init_waitqueue_head(&qqi->qqi_reint_thread.t_ctl_waitq);
425 thread_set_flags(&qqi->qqi_reint_thread, SVC_STOPPED);
426 INIT_LIST_HEAD(&qqi->qqi_deferred_glb);
427 INIT_LIST_HEAD(&qqi->qqi_deferred_slv);
428 lquota_generate_fid(&qqi->qqi_fid, qsd->qsd_pool_id,
429 QSD_RES_TYPE(qsd), qtype);
431 /* open accounting object */
432 LASSERT(qqi->qqi_acct_obj == NULL);
433 qqi->qqi_acct_obj = acct_obj_lookup(env, qsd->qsd_dev, qtype);
434 if (IS_ERR(qqi->qqi_acct_obj)) {
435 CDEBUG(D_QUOTA, "%s: no %s space accounting support: rc = %ld\n",
436 qsd->qsd_svname, qtype_name(qtype),
437 PTR_ERR(qqi->qqi_acct_obj));
438 qqi->qqi_acct_obj = NULL;
439 qqi->qqi_acct_failed = true;
442 /* open global index copy */
443 LASSERT(qqi->qqi_glb_obj == NULL);
444 qqi->qqi_glb_obj = lquota_disk_glb_find_create(env, qsd->qsd_dev,
446 &qqi->qqi_fid, true);
447 if (IS_ERR(qqi->qqi_glb_obj)) {
448 CERROR("%s: can't open global index copy "DFID" %ld\n",
449 qsd->qsd_svname, PFID(&qqi->qqi_fid),
450 PTR_ERR(qqi->qqi_glb_obj));
451 GOTO(out, rc = PTR_ERR(qqi->qqi_glb_obj));
453 qqi->qqi_glb_ver = dt_version_get(env, qqi->qqi_glb_obj);
455 /* open slave index copy */
456 LASSERT(qqi->qqi_slv_obj == NULL);
457 obd_str2uuid(&uuid, qsd->qsd_svname);
458 qqi->qqi_slv_obj = lquota_disk_slv_find_create(env, qsd->qsd_dev,
460 &qqi->qqi_fid, &uuid,
462 if (IS_ERR(qqi->qqi_slv_obj)) {
463 CERROR("%s: can't open slave index copy "DFID" %ld\n",
464 qsd->qsd_svname, PFID(&qqi->qqi_fid),
465 PTR_ERR(qqi->qqi_slv_obj));
466 GOTO(out, rc = PTR_ERR(qqi->qqi_slv_obj));
468 qqi->qqi_slv_ver = dt_version_get(env, qqi->qqi_slv_obj);
471 qqi->qqi_site = lquota_site_alloc(env, qqi, false, qtype, &qsd_lqe_ops);
472 if (IS_ERR(qqi->qqi_site)) {
473 CERROR("%s: can't allocate site "DFID" %ld\n", qsd->qsd_svname,
474 PFID(&qqi->qqi_fid), PTR_ERR(qqi->qqi_site));
475 GOTO(out, rc = PTR_ERR(qqi->qqi_site));
478 /* register proc entry for accounting & global index copy objects */
479 rc = lprocfs_seq_create(qsd->qsd_proc, qtype2acct_name(qtype),
480 0444, &lprocfs_quota_seq_fops,
483 CERROR("%s: can't add procfs entry for accounting file %d\n",
484 qsd->qsd_svname, rc);
488 rc = lprocfs_seq_create(qsd->qsd_proc, qtype2glb_name(qtype),
489 0444, &lprocfs_quota_seq_fops,
492 CERROR("%s: can't add procfs entry for global index copy %d\n",
493 qsd->qsd_svname, rc);
499 qsd_qtype_fini(env, qsd, qtype);
504 * Release a qsd_instance. Companion of qsd_init(). This releases all data
505 * structures associated with the quota slave (on-disk objects, lquota entry
507 * This function should be called when the OSD is shutting down.
509 * \param env - is the environment passed by the caller
510 * \param qsd - is the qsd instance to shutdown
512 void qsd_fini(const struct lu_env *env, struct qsd_instance *qsd)
517 if (unlikely(qsd == NULL))
520 CDEBUG(D_QUOTA, "%s: initiating QSD shutdown\n", qsd->qsd_svname);
521 write_lock(&qsd->qsd_lock);
522 qsd->qsd_stopping = true;
523 write_unlock(&qsd->qsd_lock);
525 /* remove qsd proc entry */
526 if (qsd->qsd_proc != NULL) {
527 lprocfs_remove(&qsd->qsd_proc);
528 qsd->qsd_proc = NULL;
531 /* stop the writeback thread */
532 qsd_stop_upd_thread(qsd);
534 /* shutdown the reintegration threads */
535 for (qtype = USRQUOTA; qtype < LL_MAXQUOTAS; qtype++) {
536 if (qsd->qsd_type_array[qtype] == NULL)
538 qsd_stop_reint_thread(qsd->qsd_type_array[qtype]);
541 if (qsd->qsd_ns != NULL) {
545 /* free per-quota type data */
546 for (qtype = USRQUOTA; qtype < LL_MAXQUOTAS; qtype++)
547 qsd_qtype_fini(env, qsd, qtype);
550 /* deregister connection to the quota master */
551 qsd->qsd_exp_valid = false;
552 lustre_deregister_lwp_item(&qsd->qsd_exp);
555 /* release per-filesystem information */
556 if (qsd->qsd_fsinfo != NULL) {
557 mutex_lock(&qsd->qsd_fsinfo->qfs_mutex);
558 /* remove from the list of fsinfo */
559 list_del_init(&qsd->qsd_link);
560 mutex_unlock(&qsd->qsd_fsinfo->qfs_mutex);
561 qsd_put_fsinfo(qsd->qsd_fsinfo);
562 qsd->qsd_fsinfo = NULL;
565 /* release quota root directory */
566 if (qsd->qsd_root != NULL) {
567 dt_object_put(env, qsd->qsd_root);
568 qsd->qsd_root = NULL;
571 /* release reference on dt_device */
572 if (qsd->qsd_dev != NULL) {
573 lu_ref_del(&qsd->qsd_dev->dd_lu_dev.ld_reference, "qsd", qsd);
574 lu_device_put(&qsd->qsd_dev->dd_lu_dev);
578 CDEBUG(D_QUOTA, "%s: QSD shutdown completed\n", qsd->qsd_svname);
582 EXPORT_SYMBOL(qsd_fini);
585 * Create a new qsd_instance to be associated with backend osd device
586 * identified by \dev.
588 * \param env - the environment passed by the caller
589 * \param svname - is the service name of the OSD device creating this instance
590 * \param dev - is the dt_device where to store quota index files
591 * \param osd_proc - is the procfs parent directory where to create procfs file
592 * related to this new qsd instance
594 * \retval - pointer to new qsd_instance associated with dev \dev on success,
595 * appropriate error on failure
597 struct qsd_instance *qsd_init(const struct lu_env *env, char *svname,
598 struct dt_device *dev,
599 struct proc_dir_entry *osd_proc)
601 struct qsd_thread_info *qti = qsd_info(env);
602 struct qsd_instance *qsd;
606 /* only configure qsd for MDT & OST */
607 type = server_name2index(svname, &idx, NULL);
608 if (type != LDD_F_SV_TYPE_MDT && type != LDD_F_SV_TYPE_OST)
611 /* allocate qsd instance */
614 RETURN(ERR_PTR(-ENOMEM));
616 /* generic initializations */
617 rwlock_init(&qsd->qsd_lock);
618 INIT_LIST_HEAD(&qsd->qsd_link);
619 thread_set_flags(&qsd->qsd_upd_thread, SVC_STOPPED);
620 init_waitqueue_head(&qsd->qsd_upd_thread.t_ctl_waitq);
621 INIT_LIST_HEAD(&qsd->qsd_upd_list);
622 spin_lock_init(&qsd->qsd_adjust_lock);
623 INIT_LIST_HEAD(&qsd->qsd_adjust_list);
624 qsd->qsd_prepared = false;
625 qsd->qsd_started = false;
627 /* copy service name */
628 if (strlcpy(qsd->qsd_svname, svname, sizeof(qsd->qsd_svname))
629 >= sizeof(qsd->qsd_svname))
630 GOTO(out, rc = -E2BIG);
632 /* grab reference on osd device */
633 lu_device_get(&dev->dd_lu_dev);
634 lu_ref_add(&dev->dd_lu_dev.ld_reference, "qsd", qsd);
637 /* we only support pool ID 0 (default data or metadata pool) for the
638 * time being. A different pool ID could be assigned to this target via
639 * the configuration log in the future */
640 qsd->qsd_pool_id = 0;
642 /* get fsname from svname */
643 rc = server_name2fsname(svname, qti->qti_buf, NULL);
645 CERROR("%s: fail to extract filesystem name\n", svname);
649 /* look up quota setting for the filesystem the target belongs to */
650 qsd->qsd_fsinfo = qsd_get_fsinfo(qti->qti_buf, 1);
651 if (qsd->qsd_fsinfo == NULL) {
652 CERROR("%s: failed to locate filesystem information\n", svname);
653 GOTO(out, rc = -EINVAL);
656 /* add in the list of lquota_fsinfo */
657 mutex_lock(&qsd->qsd_fsinfo->qfs_mutex);
658 list_add_tail(&qsd->qsd_link, &qsd->qsd_fsinfo->qfs_qsd_list);
659 mutex_unlock(&qsd->qsd_fsinfo->qfs_mutex);
661 /* register procfs directory */
662 qsd->qsd_proc = lprocfs_register(QSD_DIR, osd_proc,
663 lprocfs_quota_qsd_vars, qsd);
664 if (IS_ERR(qsd->qsd_proc)) {
665 rc = PTR_ERR(qsd->qsd_proc);
666 qsd->qsd_proc = NULL;
667 CERROR("%s: fail to create quota slave proc entry (%d)\n",
679 EXPORT_SYMBOL(qsd_init);
682 * Initialize on-disk structures in order to manage quota enforcement for
683 * the target associated with the qsd instance \qsd and starts the reintegration
684 * procedure for each quota type as soon as possible.
685 * The last step of the reintegration will be completed once qsd_start() is
686 * called, at which points the space reconciliation with the master will be
688 * This function must be called when the server stack is fully configured,
689 * typically when ->ldo_prepare is called across the stack.
691 * \param env - the environment passed by the caller
692 * \param qsd - is qsd_instance to prepare
694 * \retval - 0 on success, appropriate error on failure
696 int qsd_prepare(const struct lu_env *env, struct qsd_instance *qsd)
698 struct qsd_thread_info *qti = qsd_info(env);
702 if (unlikely(qsd == NULL))
705 read_lock(&qsd->qsd_lock);
706 if (qsd->qsd_prepared) {
707 CERROR("%s: qsd instance already prepared\n", qsd->qsd_svname);
710 read_unlock(&qsd->qsd_lock);
714 /* Record whether this qsd instance is managing quota enforcement for a
715 * MDT (i.e. inode quota) or OST (block quota) */
716 if (lu_device_is_md(qsd->qsd_dev->dd_lu_dev.ld_site->ls_top_dev)) {
717 qsd->qsd_is_md = true;
718 qsd->qsd_sync_threshold = LQUOTA_LEAST_QUNIT(LQUOTA_RES_MD);
720 qsd->qsd_sync_threshold = LQUOTA_LEAST_QUNIT(LQUOTA_RES_DT);
723 /* look-up on-disk directory for the quota slave */
724 qsd->qsd_root = lquota_disk_dir_find_create(env, qsd->qsd_dev, NULL,
726 if (IS_ERR(qsd->qsd_root)) {
727 rc = PTR_ERR(qsd->qsd_root);
728 qsd->qsd_root = NULL;
729 CERROR("%s: failed to create quota slave root dir (%d)\n",
730 qsd->qsd_svname, rc);
734 /* initialize per-quota type data */
735 for (qtype = USRQUOTA; qtype < LL_MAXQUOTAS; qtype++) {
736 rc = qsd_qtype_init(env, qsd, qtype);
741 /* pools successfully setup, mark the qsd as prepared */
742 write_lock(&qsd->qsd_lock);
743 qsd->qsd_prepared = true;
744 write_unlock(&qsd->qsd_lock);
746 if (qsd->qsd_dev->dd_rdonly)
749 /* start reintegration thread for each type, if required */
750 for (qtype = USRQUOTA; qtype < LL_MAXQUOTAS; qtype++) {
751 struct qsd_qtype_info *qqi = qsd->qsd_type_array[qtype];
753 if (qsd_type_enabled(qsd, qtype) &&
754 qqi->qqi_acct_failed) {
755 LCONSOLE_ERROR("%s: can't enable quota enforcement "
756 "since space accounting isn't functional"
757 ". Please run tunefs.lustre --quota on "
758 "an unmounted filesystem if not done "
759 "already\n", qsd->qsd_svname);
763 rc = qsd_start_reint_thread(qqi);
765 CERROR("%s: failed to start reint thread for type %s: rc = %d\n",
766 qsd->qsd_svname, qtype_name(qtype), rc);
771 /* start writeback thread */
772 rc = qsd_start_upd_thread(qsd);
774 CERROR("%s: failed to start writeback thread (%d)\n",
775 qsd->qsd_svname, rc);
779 /* generate osp name */
780 rc = tgt_name2lwp_name(qsd->qsd_svname, qti->qti_buf,
783 CERROR("%s: failed to generate ospname (%d)\n",
784 qsd->qsd_svname, rc);
788 /* the connection callback will start the reintegration
789 * procedure if quota is enabled */
790 rc = lustre_register_lwp_item(qti->qti_buf, &qsd->qsd_exp,
791 qsd_conn_callback, (void *)qsd);
793 CERROR("%s: fail to get connection to master (%d)\n",
794 qsd->qsd_svname, rc);
800 EXPORT_SYMBOL(qsd_prepare);
803 * Start a qsd instance. This will complete the last step of the reintegration
804 * procedure as soon as possible (provided that the master is reachable).
805 * This should be called when recovery has been completed and quota should now
806 * be enforced on every operations.
808 * \param env - the environment passed by the caller
809 * \param qsd - is the qsd instance associated with the osd device to start
811 int qsd_start(const struct lu_env *env, struct qsd_instance *qsd)
816 if (unlikely(qsd == NULL))
819 write_lock(&qsd->qsd_lock);
820 if (!qsd->qsd_prepared) {
821 CERROR("%s: can't start qsd instance since it wasn't properly "
822 "initialized\n", qsd->qsd_svname);
824 } else if (qsd->qsd_started) {
825 CERROR("%s: qsd instance already started\n", qsd->qsd_svname);
828 /* notify that the qsd_instance is now started */
829 qsd->qsd_started = true;
831 write_unlock(&qsd->qsd_lock);
836 /* Trigger the 3rd step of reintegration: If usage > granted, acquire
837 * up to usage; If usage < granted, release down to usage. */
838 for (type = USRQUOTA; type < LL_MAXQUOTAS; type++) {
839 struct qsd_qtype_info *qqi = qsd->qsd_type_array[type];
840 wake_up(&qqi->qqi_reint_thread.t_ctl_waitq);
845 EXPORT_SYMBOL(qsd_start);
847 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg));
850 * Global initialization performed at module load time
852 int qsd_glb_init(void)
856 rc = lu_kmem_init(qsd_caches);
860 qsd_key_init_generic(&qsd_thread_key, NULL);
861 lu_context_key_register(&qsd_thread_key);
862 lustre_register_quota_process_config(qsd_process_config);
868 * Companion of qsd_glb_init() called at module unload time
870 void qsd_glb_fini(void)
872 lustre_register_quota_process_config(NULL);
873 lu_kmem_fini(qsd_caches);
874 lu_context_key_degister(&qsd_thread_key);