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, 2013, 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;
84 memset(enabled, 0, sizeof(enabled));
85 if (qsd_type_enabled(qsd, USRQUOTA))
87 if (qsd_type_enabled(qsd, GRPQUOTA))
89 if (strlen(enabled) == 0)
90 strcat(enabled, "none");
92 rc = seq_printf(m, "target name: %s\n"
96 "conn to master: %s\n",
97 qsd->qsd_svname, qsd->qsd_pool_id,
98 qsd->qsd_is_md ? "md" : "dt", enabled,
99 qsd->qsd_exp_valid ? "setup" : "not setup yet");
101 if (qsd->qsd_prepared) {
102 memset(enabled, 0, sizeof(enabled));
103 if (qsd->qsd_type_array[USRQUOTA]->qqi_acct_obj != NULL)
104 strcat(enabled, "u");
105 if (qsd->qsd_type_array[GRPQUOTA]->qqi_acct_obj != NULL)
106 strcat(enabled, "g");
107 if (strlen(enabled) == 0)
108 strcat(enabled, "none");
109 rc += seq_printf(m, "space acct: %s\n"
110 "user uptodate: glb[%d],slv[%d],reint[%d]\n"
111 "group uptodate: glb[%d],slv[%d],reint[%d]\n",
113 qsd->qsd_type_array[USRQUOTA]->qqi_glb_uptodate,
114 qsd->qsd_type_array[USRQUOTA]->qqi_slv_uptodate,
115 qsd->qsd_type_array[USRQUOTA]->qqi_reint,
116 qsd->qsd_type_array[GRPQUOTA]->qqi_glb_uptodate,
117 qsd->qsd_type_array[GRPQUOTA]->qqi_slv_uptodate,
118 qsd->qsd_type_array[GRPQUOTA]->qqi_reint);
122 LPROC_SEQ_FOPS_RO(qsd_state);
124 static int qsd_enabled_seq_show(struct seq_file *m, void *data)
126 struct qsd_instance *qsd = m->private;
129 LASSERT(qsd != NULL);
131 memset(enabled, 0, sizeof(enabled));
132 if (qsd_type_enabled(qsd, USRQUOTA))
133 strcat(enabled, "u");
134 if (qsd_type_enabled(qsd, GRPQUOTA))
135 strcat(enabled, "g");
136 if (strlen(enabled) == 0)
137 strcat(enabled, "none");
139 return seq_printf(m, "%s\n", enabled);
141 LPROC_SEQ_FOPS_RO(qsd_enabled);
143 /* force reintegration procedure to be executed.
144 * Used for test/debugging purpose */
146 lprocfs_force_reint_seq_write(struct file *file, const char *buffer,
147 size_t count, loff_t *off)
149 struct qsd_instance *qsd = ((struct seq_file *)file->private_data)->private;
152 LASSERT(qsd != NULL);
154 write_lock(&qsd->qsd_lock);
155 if (qsd->qsd_stopping) {
156 /* don't mess up with shutdown procedure, it is already
157 * complicated enough */
159 } else if (!qsd->qsd_prepared) {
162 /* mark all indexes as stale */
163 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
164 qsd->qsd_type_array[qtype]->qqi_glb_uptodate = false;
165 qsd->qsd_type_array[qtype]->qqi_slv_uptodate = false;
168 write_unlock(&qsd->qsd_lock);
173 /* kick off reintegration */
174 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
175 rc = qsd_start_reint_thread(qsd->qsd_type_array[qtype]);
179 return rc == 0 ? count : rc;
181 LPROC_SEQ_FOPS_WO_TYPE(qsd, force_reint);
183 static int qsd_timeout_seq_show(struct seq_file *m, void *data)
185 struct qsd_instance *qsd = m->private;
186 LASSERT(qsd != NULL);
188 return seq_printf(m, "%d\n", qsd_wait_timeout(qsd));
192 qsd_timeout_seq_write(struct file *file, const char *buffer,
193 size_t count, loff_t *off)
195 struct qsd_instance *qsd = ((struct seq_file *)file->private_data)->private;
197 LASSERT(qsd != NULL);
199 rc = lprocfs_write_helper(buffer, count, &timeout);
205 qsd->qsd_timeout = timeout;
208 LPROC_SEQ_FOPS(qsd_timeout);
210 static struct lprocfs_seq_vars lprocfs_quota_qsd_vars[] = {
211 { "info", &qsd_state_fops },
212 { "enabled", &qsd_enabled_fops },
213 { "force_reint", &qsd_force_reint_fops },
214 { "timeout", &qsd_timeout_fops },
219 * Callback function invoked by the OSP layer when the connection to the master
222 * \param data - is a pointer to the qsd_instance
224 * \retval - 0 on success, appropriate error on failure
226 static int qsd_conn_callback(void *data)
228 struct qsd_instance *qsd = (struct qsd_instance *)data;
232 /* qsd_exp should now be valid */
233 LASSERT(qsd->qsd_exp);
235 qsd->qsd_ns = class_exp2obd(qsd->qsd_exp)->obd_namespace;
237 write_lock(&qsd->qsd_lock);
238 /* notify that qsd_exp is now valid */
239 qsd->qsd_exp_valid = true;
240 write_unlock(&qsd->qsd_lock);
242 /* Now that the connection to master is setup, we can initiate the
243 * reintegration procedure for quota types which are enabled.
244 * It is worth noting that, if the qsd_instance hasn't been started
245 * already, then we can only complete the first two steps of the
246 * reintegration procedure (i.e. global lock enqueue and slave
247 * index transfer) since the space usage reconciliation (i.e.
248 * step 3) will have to wait for qsd_start() to be called */
249 for (type = USRQUOTA; type < MAXQUOTAS; type++) {
250 struct qsd_qtype_info *qqi = qsd->qsd_type_array[type];
251 wake_up(&qqi->qqi_reint_thread.t_ctl_waitq);
258 * Release qsd_qtype_info structure which contains data associated with a
259 * given quota type. This releases the accounting objects.
260 * It's called on OSD cleanup when the qsd instance is released.
262 * \param env - is the environment passed by the caller
263 * \param qsd - is the qsd instance managing the qsd_qtype_info structure
265 * \param qtype - is the quota type to be shutdown
267 static void qsd_qtype_fini(const struct lu_env *env, struct qsd_instance *qsd,
270 struct qsd_qtype_info *qqi;
273 if (qsd->qsd_type_array[qtype] == NULL)
275 qqi = qsd->qsd_type_array[qtype];
276 qsd->qsd_type_array[qtype] = NULL;
278 /* all deferred work lists should be empty */
279 LASSERT(cfs_list_empty(&qqi->qqi_deferred_glb));
280 LASSERT(cfs_list_empty(&qqi->qqi_deferred_slv));
282 /* shutdown lquota site */
283 if (qqi->qqi_site != NULL && !IS_ERR(qqi->qqi_site)) {
284 lquota_site_free(env, qqi->qqi_site);
285 qqi->qqi_site = NULL;
288 /* by now, all qqi users should have gone away */
289 LASSERT(cfs_atomic_read(&qqi->qqi_ref) == 1);
290 lu_ref_fini(&qqi->qqi_reference);
292 /* release accounting object */
293 if (qqi->qqi_acct_obj != NULL && !IS_ERR(qqi->qqi_acct_obj)) {
294 lu_object_put(env, &qqi->qqi_acct_obj->do_lu);
295 qqi->qqi_acct_obj = NULL;
298 /* release slv index */
299 if (qqi->qqi_slv_obj != NULL && !IS_ERR(qqi->qqi_slv_obj)) {
300 lu_object_put(env, &qqi->qqi_slv_obj->do_lu);
301 qqi->qqi_slv_obj = NULL;
302 qqi->qqi_slv_ver = 0;
305 /* release global index */
306 if (qqi->qqi_glb_obj != NULL && !IS_ERR(qqi->qqi_glb_obj)) {
307 lu_object_put(env, &qqi->qqi_glb_obj->do_lu);
308 qqi->qqi_glb_obj = NULL;
309 qqi->qqi_glb_ver = 0;
317 * Allocate and initialize a qsd_qtype_info structure for quota type \qtype.
318 * This opens the accounting object and initializes the proc file.
319 * It's called on OSD start when the qsd_prepare() is invoked on the qsd
322 * \param env - the environment passed by the caller
323 * \param qsd - is the qsd instance which will be in charge of the new
324 * qsd_qtype_info instance.
325 * \param qtype - is quota type to set up
327 * \retval - 0 on success and qsd->qsd_type_array[qtype] is allocated,
328 * appropriate error on failure
330 static int qsd_qtype_init(const struct lu_env *env, struct qsd_instance *qsd,
333 struct qsd_qtype_info *qqi;
335 struct obd_uuid uuid;
338 LASSERT(qsd->qsd_type_array[qtype] == NULL);
340 /* allocate structure for this quota type */
344 qsd->qsd_type_array[qtype] = qqi;
345 cfs_atomic_set(&qqi->qqi_ref, 1); /* referenced from qsd */
347 /* set backpointer and other parameters */
349 qqi->qqi_qtype = qtype;
350 lu_ref_init(&qqi->qqi_reference);
351 lquota_generate_fid(&qqi->qqi_fid, qsd->qsd_pool_id, QSD_RES_TYPE(qsd),
353 qqi->qqi_glb_uptodate = false;
354 qqi->qqi_slv_uptodate = false;
355 qqi->qqi_reint = false;
356 init_waitqueue_head(&qqi->qqi_reint_thread.t_ctl_waitq);
357 thread_set_flags(&qqi->qqi_reint_thread, SVC_STOPPED);
358 CFS_INIT_LIST_HEAD(&qqi->qqi_deferred_glb);
359 CFS_INIT_LIST_HEAD(&qqi->qqi_deferred_slv);
361 /* open accounting object */
362 LASSERT(qqi->qqi_acct_obj == NULL);
363 qqi->qqi_acct_obj = acct_obj_lookup(env, qsd->qsd_dev, qtype);
364 if (IS_ERR(qqi->qqi_acct_obj)) {
365 CDEBUG(D_QUOTA, "%s: no %s space accounting support rc:%ld\n",
366 qsd->qsd_svname, QTYPE_NAME(qtype),
367 PTR_ERR(qqi->qqi_acct_obj));
368 qqi->qqi_acct_obj = NULL;
369 qsd->qsd_acct_failed = true;
372 /* open global index copy */
373 LASSERT(qqi->qqi_glb_obj == NULL);
374 qqi->qqi_glb_obj = lquota_disk_glb_find_create(env, qsd->qsd_dev,
376 &qqi->qqi_fid, true);
377 if (IS_ERR(qqi->qqi_glb_obj)) {
378 CERROR("%s: can't open global index copy "DFID" %ld\n",
379 qsd->qsd_svname, PFID(&qqi->qqi_fid),
380 PTR_ERR(qqi->qqi_glb_obj));
381 GOTO(out, rc = PTR_ERR(qqi->qqi_glb_obj));
383 qqi->qqi_glb_ver = dt_version_get(env, qqi->qqi_glb_obj);
385 /* open slave index copy */
386 LASSERT(qqi->qqi_slv_obj == NULL);
387 obd_str2uuid(&uuid, qsd->qsd_svname);
388 qqi->qqi_slv_obj = lquota_disk_slv_find_create(env, qsd->qsd_dev,
390 &qqi->qqi_fid, &uuid,
392 if (IS_ERR(qqi->qqi_slv_obj)) {
393 CERROR("%s: can't open slave index copy "DFID" %ld\n",
394 qsd->qsd_svname, PFID(&qqi->qqi_fid),
395 PTR_ERR(qqi->qqi_slv_obj));
396 GOTO(out, rc = PTR_ERR(qqi->qqi_slv_obj));
398 qqi->qqi_slv_ver = dt_version_get(env, qqi->qqi_slv_obj);
401 qqi->qqi_site = lquota_site_alloc(env, qqi, false, qtype, &qsd_lqe_ops);
402 if (IS_ERR(qqi->qqi_site)) {
403 CERROR("%s: can't allocate site "DFID" %ld\n", qsd->qsd_svname,
404 PFID(&qqi->qqi_fid), PTR_ERR(qqi->qqi_site));
405 GOTO(out, rc = PTR_ERR(qqi->qqi_site));
408 /* register proc entry for accounting & global index copy objects */
409 rc = lprocfs_seq_create(qsd->qsd_proc,
410 qtype == USRQUOTA ? "acct_user" : "acct_group",
411 0444, &lprocfs_quota_seq_fops,
414 CERROR("%s: can't add procfs entry for accounting file %d\n",
415 qsd->qsd_svname, rc);
419 rc = lprocfs_seq_create(qsd->qsd_proc,
420 qtype == USRQUOTA ? "limit_user" : "limit_group",
421 0444, &lprocfs_quota_seq_fops,
424 CERROR("%s: can't add procfs entry for global index copy %d\n",
425 qsd->qsd_svname, rc);
431 qsd_qtype_fini(env, qsd, qtype);
436 * Release a qsd_instance. Companion of qsd_init(). This releases all data
437 * structures associated with the quota slave (on-disk objects, lquota entry
439 * This function should be called when the OSD is shutting down.
441 * \param env - is the environment passed by the caller
442 * \param qsd - is the qsd instance to shutdown
444 void qsd_fini(const struct lu_env *env, struct qsd_instance *qsd)
449 if (unlikely(qsd == NULL))
452 CDEBUG(D_QUOTA, "%s: initiating QSD shutdown\n", qsd->qsd_svname);
453 write_lock(&qsd->qsd_lock);
454 qsd->qsd_stopping = true;
455 write_unlock(&qsd->qsd_lock);
457 /* remove qsd proc entry */
458 if (qsd->qsd_proc != NULL) {
459 lprocfs_remove(&qsd->qsd_proc);
460 qsd->qsd_proc = NULL;
463 /* stop the writeback thread */
464 qsd_stop_upd_thread(qsd);
466 /* shutdown the reintegration threads */
467 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
468 if (qsd->qsd_type_array[qtype] == NULL)
470 qsd_stop_reint_thread(qsd->qsd_type_array[qtype]);
473 if (qsd->qsd_ns != NULL) {
477 /* free per-quota type data */
478 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++)
479 qsd_qtype_fini(env, qsd, qtype);
481 /* deregister connection to the quota master */
482 qsd->qsd_exp_valid = false;
483 lustre_deregister_lwp_item(&qsd->qsd_exp);
485 /* release per-filesystem information */
486 if (qsd->qsd_fsinfo != NULL) {
487 down(&qsd->qsd_fsinfo->qfs_sem);
488 /* remove from the list of fsinfo */
489 cfs_list_del_init(&qsd->qsd_link);
490 up(&qsd->qsd_fsinfo->qfs_sem);
491 qsd_put_fsinfo(qsd->qsd_fsinfo);
492 qsd->qsd_fsinfo = NULL;
495 /* release quota root directory */
496 if (qsd->qsd_root != NULL) {
497 lu_object_put(env, &qsd->qsd_root->do_lu);
498 qsd->qsd_root = NULL;
501 /* release reference on dt_device */
502 if (qsd->qsd_dev != NULL) {
503 lu_ref_del(&qsd->qsd_dev->dd_lu_dev.ld_reference, "qsd", qsd);
504 lu_device_put(&qsd->qsd_dev->dd_lu_dev);
508 CDEBUG(D_QUOTA, "%s: QSD shutdown completed\n", qsd->qsd_svname);
512 EXPORT_SYMBOL(qsd_fini);
515 * Create a new qsd_instance to be associated with backend osd device
516 * identified by \dev.
518 * \param env - the environment passed by the caller
519 * \param svname - is the service name of the OSD device creating this instance
520 * \param dev - is the dt_device where to store quota index files
521 * \param osd_proc - is the procfs parent directory where to create procfs file
522 * related to this new qsd instance
524 * \retval - pointer to new qsd_instance associated with dev \dev on success,
525 * appropriate error on failure
527 struct qsd_instance *qsd_init(const struct lu_env *env, char *svname,
528 struct dt_device *dev,
529 cfs_proc_dir_entry_t *osd_proc)
531 struct qsd_thread_info *qti = qsd_info(env);
532 struct qsd_instance *qsd;
536 /* only configure qsd for MDT & OST */
537 type = server_name2index(svname, &idx, NULL);
538 if (type != LDD_F_SV_TYPE_MDT && type != LDD_F_SV_TYPE_OST)
541 /* allocate qsd instance */
544 RETURN(ERR_PTR(-ENOMEM));
546 /* generic initializations */
547 rwlock_init(&qsd->qsd_lock);
548 CFS_INIT_LIST_HEAD(&qsd->qsd_link);
549 thread_set_flags(&qsd->qsd_upd_thread, SVC_STOPPED);
550 init_waitqueue_head(&qsd->qsd_upd_thread.t_ctl_waitq);
551 CFS_INIT_LIST_HEAD(&qsd->qsd_upd_list);
552 spin_lock_init(&qsd->qsd_adjust_lock);
553 CFS_INIT_LIST_HEAD(&qsd->qsd_adjust_list);
554 qsd->qsd_prepared = false;
555 qsd->qsd_started = false;
557 /* copy service name */
558 if (strlcpy(qsd->qsd_svname, svname, sizeof(qsd->qsd_svname))
559 >= sizeof(qsd->qsd_svname))
560 GOTO(out, rc = -E2BIG);
562 /* grab reference on osd device */
563 lu_device_get(&dev->dd_lu_dev);
564 lu_ref_add(&dev->dd_lu_dev.ld_reference, "qsd", qsd);
567 /* we only support pool ID 0 (default data or metadata pool) for the
568 * time being. A different pool ID could be assigned to this target via
569 * the configuration log in the future */
570 qsd->qsd_pool_id = 0;
572 /* get fsname from svname */
573 rc = server_name2fsname(svname, qti->qti_buf, NULL);
575 CERROR("%s: fail to extract filesystem name\n", svname);
579 /* look up quota setting for the filesystem the target belongs to */
580 qsd->qsd_fsinfo = qsd_get_fsinfo(qti->qti_buf, 1);
581 if (qsd->qsd_fsinfo == NULL) {
582 CERROR("%s: failed to locate filesystem information\n", svname);
583 GOTO(out, rc = -EINVAL);
586 /* add in the list of lquota_fsinfo */
587 down(&qsd->qsd_fsinfo->qfs_sem);
588 list_add_tail(&qsd->qsd_link, &qsd->qsd_fsinfo->qfs_qsd_list);
589 up(&qsd->qsd_fsinfo->qfs_sem);
591 /* register procfs directory */
592 qsd->qsd_proc = lprocfs_seq_register(QSD_DIR, osd_proc,
593 lprocfs_quota_qsd_vars, qsd);
594 if (IS_ERR(qsd->qsd_proc)) {
595 rc = PTR_ERR(qsd->qsd_proc);
596 qsd->qsd_proc = NULL;
597 CERROR("%s: fail to create quota slave proc entry (%d)\n",
609 EXPORT_SYMBOL(qsd_init);
612 * Initialize on-disk structures in order to manage quota enforcement for
613 * the target associated with the qsd instance \qsd and starts the reintegration
614 * procedure for each quota type as soon as possible.
615 * The last step of the reintegration will be completed once qsd_start() is
616 * called, at which points the space reconciliation with the master will be
618 * This function must be called when the server stack is fully configured,
619 * typically when ->ldo_prepare is called across the stack.
621 * \param env - the environment passed by the caller
622 * \param qsd - is qsd_instance to prepare
624 * \retval - 0 on success, appropriate error on failure
626 int qsd_prepare(const struct lu_env *env, struct qsd_instance *qsd)
628 struct qsd_thread_info *qti = qsd_info(env);
632 if (unlikely(qsd == NULL))
635 read_lock(&qsd->qsd_lock);
636 if (qsd->qsd_prepared) {
637 CERROR("%s: qsd instance already prepared\n", qsd->qsd_svname);
640 read_unlock(&qsd->qsd_lock);
644 /* Record whether this qsd instance is managing quota enforcement for a
645 * MDT (i.e. inode quota) or OST (block quota) */
646 if (lu_device_is_md(qsd->qsd_dev->dd_lu_dev.ld_site->ls_top_dev)) {
647 qsd->qsd_is_md = true;
648 qsd->qsd_sync_threshold = LQUOTA_LEAST_QUNIT(LQUOTA_RES_MD);
650 qsd->qsd_sync_threshold = LQUOTA_LEAST_QUNIT(LQUOTA_RES_DT);
653 /* look-up on-disk directory for the quota slave */
654 qsd->qsd_root = lquota_disk_dir_find_create(env, qsd->qsd_dev, NULL,
656 if (IS_ERR(qsd->qsd_root)) {
657 rc = PTR_ERR(qsd->qsd_root);
658 qsd->qsd_root = NULL;
659 CERROR("%s: failed to create quota slave root dir (%d)\n",
660 qsd->qsd_svname, rc);
664 /* initialize per-quota type data */
665 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
666 rc = qsd_qtype_init(env, qsd, qtype);
671 /* pools successfully setup, mark the qsd as prepared */
672 write_lock(&qsd->qsd_lock);
673 qsd->qsd_prepared = true;
674 write_unlock(&qsd->qsd_lock);
676 /* start reintegration thread for each type, if required */
677 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
678 struct qsd_qtype_info *qqi = qsd->qsd_type_array[qtype];
680 if (qsd_type_enabled(qsd, qtype) && qsd->qsd_acct_failed) {
681 LCONSOLE_ERROR("%s: can't enable quota enforcement "
682 "since space accounting isn't functional"
683 ". Please run tunefs.lustre --quota on "
684 "an unmounted filesystem if not done "
685 "already\n", qsd->qsd_svname);
689 rc = qsd_start_reint_thread(qqi);
691 CERROR("%s: failed to start reint thread for type %s "
692 "(%d)\n", qsd->qsd_svname, QTYPE_NAME(qtype),
698 /* start writeback thread */
699 rc = qsd_start_upd_thread(qsd);
701 CERROR("%s: failed to start writeback thread (%d)\n",
702 qsd->qsd_svname, rc);
706 /* generate osp name */
707 rc = tgt_name2lwpname((char *)qsd->qsd_svname, qti->qti_buf);
709 CERROR("%s: failed to generate ospname (%d)\n",
710 qsd->qsd_svname, rc);
714 /* the connection callback will start the reintegration
715 * procedure if quota is enabled */
716 rc = lustre_register_lwp_item(qti->qti_buf, &qsd->qsd_exp,
717 qsd_conn_callback, (void *)qsd);
719 CERROR("%s: fail to get connection to master (%d)\n",
720 qsd->qsd_svname, rc);
726 EXPORT_SYMBOL(qsd_prepare);
729 * Start a qsd instance. This will complete the last step of the reintegration
730 * procedure as soon as possible (provided that the master is reachable).
731 * This should be called when recovery has been completed and quota should now
732 * be enforced on every operations.
734 * \param env - the environment passed by the caller
735 * \param qsd - is the qsd instance associated with the osd device to start
737 int qsd_start(const struct lu_env *env, struct qsd_instance *qsd)
742 if (unlikely(qsd == NULL))
745 write_lock(&qsd->qsd_lock);
746 if (!qsd->qsd_prepared) {
747 CERROR("%s: can't start qsd instance since it wasn't properly "
748 "initialized\n", qsd->qsd_svname);
750 } else if (qsd->qsd_started) {
751 CERROR("%s: qsd instance already started\n", qsd->qsd_svname);
754 /* notify that the qsd_instance is now started */
755 qsd->qsd_started = true;
757 write_unlock(&qsd->qsd_lock);
762 /* Trigger the 3rd step of reintegration: If usage > granted, acquire
763 * up to usage; If usage < granted, release down to usage. */
764 for (type = USRQUOTA; type < MAXQUOTAS; type++) {
765 struct qsd_qtype_info *qqi = qsd->qsd_type_array[type];
766 wake_up(&qqi->qqi_reint_thread.t_ctl_waitq);
771 EXPORT_SYMBOL(qsd_start);
773 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg));
776 * Global initialization performed at module load time
778 int qsd_glb_init(void)
782 rc = lu_kmem_init(qsd_caches);
786 qsd_key_init_generic(&qsd_thread_key, NULL);
787 lu_context_key_register(&qsd_thread_key);
788 lustre_register_quota_process_config(qsd_process_config);
794 * Companion of qsd_glb_init() called at module unload time
796 void qsd_glb_fini(void)
798 lustre_register_quota_process_config(NULL);
799 lu_kmem_fini(qsd_caches);
800 lu_context_key_degister(&qsd_thread_key);