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, 2014, 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 (strlen(enabled) == 0)
89 strcat(enabled, "none");
91 seq_printf(m, "target name: %s\n"
95 "conn to master: %s\n",
96 qsd->qsd_svname, qsd->qsd_pool_id,
97 qsd->qsd_is_md ? "md" : "dt", enabled,
98 qsd->qsd_exp_valid ? "setup" : "not setup yet");
100 if (qsd->qsd_prepared) {
101 memset(enabled, 0, sizeof(enabled));
102 if (qsd->qsd_type_array[USRQUOTA]->qqi_acct_obj != NULL)
103 strcat(enabled, "u");
104 if (qsd->qsd_type_array[GRPQUOTA]->qqi_acct_obj != NULL)
105 strcat(enabled, "g");
106 if (strlen(enabled) == 0)
107 strcat(enabled, "none");
108 seq_printf(m, "space acct: %s\n"
109 "user uptodate: glb[%d],slv[%d],reint[%d]\n"
110 "group uptodate: glb[%d],slv[%d],reint[%d]\n",
112 qsd->qsd_type_array[USRQUOTA]->qqi_glb_uptodate,
113 qsd->qsd_type_array[USRQUOTA]->qqi_slv_uptodate,
114 qsd->qsd_type_array[USRQUOTA]->qqi_reint,
115 qsd->qsd_type_array[GRPQUOTA]->qqi_glb_uptodate,
116 qsd->qsd_type_array[GRPQUOTA]->qqi_slv_uptodate,
117 qsd->qsd_type_array[GRPQUOTA]->qqi_reint);
121 LPROC_SEQ_FOPS_RO(qsd_state);
123 static int qsd_enabled_seq_show(struct seq_file *m, void *data)
125 struct qsd_instance *qsd = m->private;
128 LASSERT(qsd != NULL);
130 memset(enabled, 0, sizeof(enabled));
131 if (qsd_type_enabled(qsd, USRQUOTA))
132 strcat(enabled, "u");
133 if (qsd_type_enabled(qsd, GRPQUOTA))
134 strcat(enabled, "g");
135 if (strlen(enabled) == 0)
136 strcat(enabled, "none");
138 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 __user *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 < LL_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 < LL_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 seq_printf(m, "%d\n", qsd_wait_timeout(qsd));
193 qsd_timeout_seq_write(struct file *file, const char __user *buffer,
194 size_t count, loff_t *off)
196 struct qsd_instance *qsd = ((struct seq_file *)file->private_data)->private;
199 LASSERT(qsd != NULL);
201 rc = lprocfs_str_to_s64(buffer, count, &timeout);
204 if (timeout < 0 || timeout > INT_MAX)
207 qsd->qsd_timeout = timeout;
210 LPROC_SEQ_FOPS(qsd_timeout);
212 static struct lprocfs_vars lprocfs_quota_qsd_vars[] = {
214 .fops = &qsd_state_fops },
216 .fops = &qsd_enabled_fops },
217 { .name = "force_reint",
218 .fops = &qsd_force_reint_fops },
220 .fops = &qsd_timeout_fops },
225 * Callback function invoked by the OSP layer when the connection to the master
228 * \param data - is a pointer to the qsd_instance
230 * \retval - 0 on success, appropriate error on failure
232 static int qsd_conn_callback(void *data)
234 struct qsd_instance *qsd = (struct qsd_instance *)data;
238 /* qsd_exp should now be valid */
239 LASSERT(qsd->qsd_exp);
241 qsd->qsd_ns = class_exp2obd(qsd->qsd_exp)->obd_namespace;
243 write_lock(&qsd->qsd_lock);
244 /* notify that qsd_exp is now valid */
245 qsd->qsd_exp_valid = true;
246 write_unlock(&qsd->qsd_lock);
248 /* Now that the connection to master is setup, we can initiate the
249 * reintegration procedure for quota types which are enabled.
250 * It is worth noting that, if the qsd_instance hasn't been started
251 * already, then we can only complete the first two steps of the
252 * reintegration procedure (i.e. global lock enqueue and slave
253 * index transfer) since the space usage reconciliation (i.e.
254 * step 3) will have to wait for qsd_start() to be called */
255 for (type = USRQUOTA; type < LL_MAXQUOTAS; type++) {
256 struct qsd_qtype_info *qqi = qsd->qsd_type_array[type];
257 wake_up(&qqi->qqi_reint_thread.t_ctl_waitq);
264 * Release qsd_qtype_info structure which contains data associated with a
265 * given quota type. This releases the accounting objects.
266 * It's called on OSD cleanup when the qsd instance is released.
268 * \param env - is the environment passed by the caller
269 * \param qsd - is the qsd instance managing the qsd_qtype_info structure
271 * \param qtype - is the quota type to be shutdown
273 static void qsd_qtype_fini(const struct lu_env *env, struct qsd_instance *qsd,
276 struct qsd_qtype_info *qqi;
280 if (qsd->qsd_type_array[qtype] == NULL)
282 qqi = qsd->qsd_type_array[qtype];
283 qsd->qsd_type_array[qtype] = NULL;
285 /* all deferred work lists should be empty */
286 LASSERT(list_empty(&qqi->qqi_deferred_glb));
287 LASSERT(list_empty(&qqi->qqi_deferred_slv));
289 /* shutdown lquota site */
290 if (qqi->qqi_site != NULL && !IS_ERR(qqi->qqi_site)) {
291 lquota_site_free(env, qqi->qqi_site);
292 qqi->qqi_site = NULL;
295 /* The qqi may still be holding by global locks which are being
296 * canceled asynchronously (LU-4365), see the following steps:
298 * - On server umount, we try to clear all quota locks first by
299 * disconnecting LWP (which will invalidate import and cleanup
300 * all locks on it), however, if quota reint process is holding
301 * the global lock for reintegration at that time, global lock
302 * will fail to be cleared on LWP disconnection.
304 * - Umount process goes on and stops reint process, the global
305 * lock will be dropped on reint process exit, however, the lock
306 * cancel in done in asynchronous way, so the
307 * qsd_glb_blocking_ast() might haven't been called yet when we
310 while (atomic_read(&qqi->qqi_ref) > 1) {
311 CDEBUG(D_QUOTA, "qqi reference count %u, repeat: %d\n",
312 atomic_read(&qqi->qqi_ref), repeat);
314 set_current_state(TASK_INTERRUPTIBLE);
315 schedule_timeout(cfs_time_seconds(1));
318 /* by now, all qqi users should have gone away */
319 LASSERT(atomic_read(&qqi->qqi_ref) == 1);
320 lu_ref_fini(&qqi->qqi_reference);
322 /* release accounting object */
323 if (qqi->qqi_acct_obj != NULL && !IS_ERR(qqi->qqi_acct_obj)) {
324 lu_object_put(env, &qqi->qqi_acct_obj->do_lu);
325 qqi->qqi_acct_obj = NULL;
328 /* release slv index */
329 if (qqi->qqi_slv_obj != NULL && !IS_ERR(qqi->qqi_slv_obj)) {
330 lu_object_put(env, &qqi->qqi_slv_obj->do_lu);
331 qqi->qqi_slv_obj = NULL;
332 qqi->qqi_slv_ver = 0;
335 /* release global index */
336 if (qqi->qqi_glb_obj != NULL && !IS_ERR(qqi->qqi_glb_obj)) {
337 lu_object_put(env, &qqi->qqi_glb_obj->do_lu);
338 qqi->qqi_glb_obj = NULL;
339 qqi->qqi_glb_ver = 0;
347 * Allocate and initialize a qsd_qtype_info structure for quota type \qtype.
348 * This opens the accounting object and initializes the proc file.
349 * It's called on OSD start when the qsd_prepare() is invoked on the qsd
352 * \param env - the environment passed by the caller
353 * \param qsd - is the qsd instance which will be in charge of the new
354 * qsd_qtype_info instance.
355 * \param qtype - is quota type to set up
357 * \retval - 0 on success and qsd->qsd_type_array[qtype] is allocated,
358 * appropriate error on failure
360 static int qsd_qtype_init(const struct lu_env *env, struct qsd_instance *qsd,
363 struct qsd_qtype_info *qqi;
365 struct obd_uuid uuid;
368 LASSERT(qsd->qsd_type_array[qtype] == NULL);
370 /* allocate structure for this quota type */
374 qsd->qsd_type_array[qtype] = qqi;
375 atomic_set(&qqi->qqi_ref, 1); /* referenced from qsd */
377 /* set backpointer and other parameters */
379 qqi->qqi_qtype = qtype;
380 lu_ref_init(&qqi->qqi_reference);
381 lquota_generate_fid(&qqi->qqi_fid, qsd->qsd_pool_id, QSD_RES_TYPE(qsd),
383 qqi->qqi_glb_uptodate = false;
384 qqi->qqi_slv_uptodate = false;
385 qqi->qqi_reint = false;
386 init_waitqueue_head(&qqi->qqi_reint_thread.t_ctl_waitq);
387 thread_set_flags(&qqi->qqi_reint_thread, SVC_STOPPED);
388 INIT_LIST_HEAD(&qqi->qqi_deferred_glb);
389 INIT_LIST_HEAD(&qqi->qqi_deferred_slv);
391 /* open accounting object */
392 LASSERT(qqi->qqi_acct_obj == NULL);
393 qqi->qqi_acct_obj = acct_obj_lookup(env, qsd->qsd_dev, qtype);
394 if (IS_ERR(qqi->qqi_acct_obj)) {
395 CDEBUG(D_QUOTA, "%s: no %s space accounting support rc:%ld\n",
396 qsd->qsd_svname, QTYPE_NAME(qtype),
397 PTR_ERR(qqi->qqi_acct_obj));
398 qqi->qqi_acct_obj = NULL;
399 qsd->qsd_acct_failed = true;
402 /* open global index copy */
403 LASSERT(qqi->qqi_glb_obj == NULL);
404 qqi->qqi_glb_obj = lquota_disk_glb_find_create(env, qsd->qsd_dev,
406 &qqi->qqi_fid, true);
407 if (IS_ERR(qqi->qqi_glb_obj)) {
408 CERROR("%s: can't open global index copy "DFID" %ld\n",
409 qsd->qsd_svname, PFID(&qqi->qqi_fid),
410 PTR_ERR(qqi->qqi_glb_obj));
411 GOTO(out, rc = PTR_ERR(qqi->qqi_glb_obj));
413 qqi->qqi_glb_ver = dt_version_get(env, qqi->qqi_glb_obj);
415 /* open slave index copy */
416 LASSERT(qqi->qqi_slv_obj == NULL);
417 obd_str2uuid(&uuid, qsd->qsd_svname);
418 qqi->qqi_slv_obj = lquota_disk_slv_find_create(env, qsd->qsd_dev,
420 &qqi->qqi_fid, &uuid,
422 if (IS_ERR(qqi->qqi_slv_obj)) {
423 CERROR("%s: can't open slave index copy "DFID" %ld\n",
424 qsd->qsd_svname, PFID(&qqi->qqi_fid),
425 PTR_ERR(qqi->qqi_slv_obj));
426 GOTO(out, rc = PTR_ERR(qqi->qqi_slv_obj));
428 qqi->qqi_slv_ver = dt_version_get(env, qqi->qqi_slv_obj);
431 qqi->qqi_site = lquota_site_alloc(env, qqi, false, qtype, &qsd_lqe_ops);
432 if (IS_ERR(qqi->qqi_site)) {
433 CERROR("%s: can't allocate site "DFID" %ld\n", qsd->qsd_svname,
434 PFID(&qqi->qqi_fid), PTR_ERR(qqi->qqi_site));
435 GOTO(out, rc = PTR_ERR(qqi->qqi_site));
438 /* register proc entry for accounting & global index copy objects */
439 rc = lprocfs_seq_create(qsd->qsd_proc,
440 qtype == USRQUOTA ? "acct_user" : "acct_group",
441 0444, &lprocfs_quota_seq_fops,
444 CERROR("%s: can't add procfs entry for accounting file %d\n",
445 qsd->qsd_svname, rc);
449 rc = lprocfs_seq_create(qsd->qsd_proc,
450 qtype == USRQUOTA ? "limit_user" : "limit_group",
451 0444, &lprocfs_quota_seq_fops,
454 CERROR("%s: can't add procfs entry for global index copy %d\n",
455 qsd->qsd_svname, rc);
461 qsd_qtype_fini(env, qsd, qtype);
466 * Release a qsd_instance. Companion of qsd_init(). This releases all data
467 * structures associated with the quota slave (on-disk objects, lquota entry
469 * This function should be called when the OSD is shutting down.
471 * \param env - is the environment passed by the caller
472 * \param qsd - is the qsd instance to shutdown
474 void qsd_fini(const struct lu_env *env, struct qsd_instance *qsd)
479 if (unlikely(qsd == NULL))
482 CDEBUG(D_QUOTA, "%s: initiating QSD shutdown\n", qsd->qsd_svname);
483 write_lock(&qsd->qsd_lock);
484 qsd->qsd_stopping = true;
485 write_unlock(&qsd->qsd_lock);
487 /* remove qsd proc entry */
488 if (qsd->qsd_proc != NULL) {
489 lprocfs_remove(&qsd->qsd_proc);
490 qsd->qsd_proc = NULL;
493 /* stop the writeback thread */
494 qsd_stop_upd_thread(qsd);
496 /* shutdown the reintegration threads */
497 for (qtype = USRQUOTA; qtype < LL_MAXQUOTAS; qtype++) {
498 if (qsd->qsd_type_array[qtype] == NULL)
500 qsd_stop_reint_thread(qsd->qsd_type_array[qtype]);
503 if (qsd->qsd_ns != NULL) {
507 /* free per-quota type data */
508 for (qtype = USRQUOTA; qtype < LL_MAXQUOTAS; qtype++)
509 qsd_qtype_fini(env, qsd, qtype);
511 /* deregister connection to the quota master */
512 qsd->qsd_exp_valid = false;
513 lustre_deregister_lwp_item(&qsd->qsd_exp);
515 /* release per-filesystem information */
516 if (qsd->qsd_fsinfo != NULL) {
517 mutex_lock(&qsd->qsd_fsinfo->qfs_mutex);
518 /* remove from the list of fsinfo */
519 list_del_init(&qsd->qsd_link);
520 mutex_unlock(&qsd->qsd_fsinfo->qfs_mutex);
521 qsd_put_fsinfo(qsd->qsd_fsinfo);
522 qsd->qsd_fsinfo = NULL;
525 /* release quota root directory */
526 if (qsd->qsd_root != NULL) {
527 lu_object_put(env, &qsd->qsd_root->do_lu);
528 qsd->qsd_root = NULL;
531 /* release reference on dt_device */
532 if (qsd->qsd_dev != NULL) {
533 lu_ref_del(&qsd->qsd_dev->dd_lu_dev.ld_reference, "qsd", qsd);
534 lu_device_put(&qsd->qsd_dev->dd_lu_dev);
538 CDEBUG(D_QUOTA, "%s: QSD shutdown completed\n", qsd->qsd_svname);
542 EXPORT_SYMBOL(qsd_fini);
545 * Create a new qsd_instance to be associated with backend osd device
546 * identified by \dev.
548 * \param env - the environment passed by the caller
549 * \param svname - is the service name of the OSD device creating this instance
550 * \param dev - is the dt_device where to store quota index files
551 * \param osd_proc - is the procfs parent directory where to create procfs file
552 * related to this new qsd instance
554 * \retval - pointer to new qsd_instance associated with dev \dev on success,
555 * appropriate error on failure
557 struct qsd_instance *qsd_init(const struct lu_env *env, char *svname,
558 struct dt_device *dev,
559 struct proc_dir_entry *osd_proc)
561 struct qsd_thread_info *qti = qsd_info(env);
562 struct qsd_instance *qsd;
566 /* only configure qsd for MDT & OST */
567 type = server_name2index(svname, &idx, NULL);
568 if (type != LDD_F_SV_TYPE_MDT && type != LDD_F_SV_TYPE_OST)
571 /* allocate qsd instance */
574 RETURN(ERR_PTR(-ENOMEM));
576 /* generic initializations */
577 rwlock_init(&qsd->qsd_lock);
578 INIT_LIST_HEAD(&qsd->qsd_link);
579 thread_set_flags(&qsd->qsd_upd_thread, SVC_STOPPED);
580 init_waitqueue_head(&qsd->qsd_upd_thread.t_ctl_waitq);
581 INIT_LIST_HEAD(&qsd->qsd_upd_list);
582 spin_lock_init(&qsd->qsd_adjust_lock);
583 INIT_LIST_HEAD(&qsd->qsd_adjust_list);
584 qsd->qsd_prepared = false;
585 qsd->qsd_started = false;
587 /* copy service name */
588 if (strlcpy(qsd->qsd_svname, svname, sizeof(qsd->qsd_svname))
589 >= sizeof(qsd->qsd_svname))
590 GOTO(out, rc = -E2BIG);
592 /* grab reference on osd device */
593 lu_device_get(&dev->dd_lu_dev);
594 lu_ref_add(&dev->dd_lu_dev.ld_reference, "qsd", qsd);
597 /* we only support pool ID 0 (default data or metadata pool) for the
598 * time being. A different pool ID could be assigned to this target via
599 * the configuration log in the future */
600 qsd->qsd_pool_id = 0;
602 /* get fsname from svname */
603 rc = server_name2fsname(svname, qti->qti_buf, NULL);
605 CERROR("%s: fail to extract filesystem name\n", svname);
609 /* look up quota setting for the filesystem the target belongs to */
610 qsd->qsd_fsinfo = qsd_get_fsinfo(qti->qti_buf, 1);
611 if (qsd->qsd_fsinfo == NULL) {
612 CERROR("%s: failed to locate filesystem information\n", svname);
613 GOTO(out, rc = -EINVAL);
616 /* add in the list of lquota_fsinfo */
617 mutex_lock(&qsd->qsd_fsinfo->qfs_mutex);
618 list_add_tail(&qsd->qsd_link, &qsd->qsd_fsinfo->qfs_qsd_list);
619 mutex_unlock(&qsd->qsd_fsinfo->qfs_mutex);
621 /* register procfs directory */
622 qsd->qsd_proc = lprocfs_register(QSD_DIR, osd_proc,
623 lprocfs_quota_qsd_vars, qsd);
624 if (IS_ERR(qsd->qsd_proc)) {
625 rc = PTR_ERR(qsd->qsd_proc);
626 qsd->qsd_proc = NULL;
627 CERROR("%s: fail to create quota slave proc entry (%d)\n",
639 EXPORT_SYMBOL(qsd_init);
642 * Initialize on-disk structures in order to manage quota enforcement for
643 * the target associated with the qsd instance \qsd and starts the reintegration
644 * procedure for each quota type as soon as possible.
645 * The last step of the reintegration will be completed once qsd_start() is
646 * called, at which points the space reconciliation with the master will be
648 * This function must be called when the server stack is fully configured,
649 * typically when ->ldo_prepare is called across the stack.
651 * \param env - the environment passed by the caller
652 * \param qsd - is qsd_instance to prepare
654 * \retval - 0 on success, appropriate error on failure
656 int qsd_prepare(const struct lu_env *env, struct qsd_instance *qsd)
658 struct qsd_thread_info *qti = qsd_info(env);
662 if (unlikely(qsd == NULL))
665 read_lock(&qsd->qsd_lock);
666 if (qsd->qsd_prepared) {
667 CERROR("%s: qsd instance already prepared\n", qsd->qsd_svname);
670 read_unlock(&qsd->qsd_lock);
674 /* Record whether this qsd instance is managing quota enforcement for a
675 * MDT (i.e. inode quota) or OST (block quota) */
676 if (lu_device_is_md(qsd->qsd_dev->dd_lu_dev.ld_site->ls_top_dev)) {
677 qsd->qsd_is_md = true;
678 qsd->qsd_sync_threshold = LQUOTA_LEAST_QUNIT(LQUOTA_RES_MD);
680 qsd->qsd_sync_threshold = LQUOTA_LEAST_QUNIT(LQUOTA_RES_DT);
683 /* look-up on-disk directory for the quota slave */
684 qsd->qsd_root = lquota_disk_dir_find_create(env, qsd->qsd_dev, NULL,
686 if (IS_ERR(qsd->qsd_root)) {
687 rc = PTR_ERR(qsd->qsd_root);
688 qsd->qsd_root = NULL;
689 CERROR("%s: failed to create quota slave root dir (%d)\n",
690 qsd->qsd_svname, rc);
694 /* initialize per-quota type data */
695 for (qtype = USRQUOTA; qtype < LL_MAXQUOTAS; qtype++) {
696 rc = qsd_qtype_init(env, qsd, qtype);
701 /* pools successfully setup, mark the qsd as prepared */
702 write_lock(&qsd->qsd_lock);
703 qsd->qsd_prepared = true;
704 write_unlock(&qsd->qsd_lock);
706 /* start reintegration thread for each type, if required */
707 for (qtype = USRQUOTA; qtype < LL_MAXQUOTAS; qtype++) {
708 struct qsd_qtype_info *qqi = qsd->qsd_type_array[qtype];
710 if (qsd_type_enabled(qsd, qtype) && qsd->qsd_acct_failed) {
711 LCONSOLE_ERROR("%s: can't enable quota enforcement "
712 "since space accounting isn't functional"
713 ". Please run tunefs.lustre --quota on "
714 "an unmounted filesystem if not done "
715 "already\n", qsd->qsd_svname);
719 rc = qsd_start_reint_thread(qqi);
721 CERROR("%s: failed to start reint thread for type %s "
722 "(%d)\n", qsd->qsd_svname, QTYPE_NAME(qtype),
728 /* start writeback thread */
729 rc = qsd_start_upd_thread(qsd);
731 CERROR("%s: failed to start writeback thread (%d)\n",
732 qsd->qsd_svname, rc);
736 /* generate osp name */
737 rc = tgt_name2lwp_name(qsd->qsd_svname, qti->qti_buf,
740 CERROR("%s: failed to generate ospname (%d)\n",
741 qsd->qsd_svname, rc);
745 /* the connection callback will start the reintegration
746 * procedure if quota is enabled */
747 rc = lustre_register_lwp_item(qti->qti_buf, &qsd->qsd_exp,
748 qsd_conn_callback, (void *)qsd);
750 CERROR("%s: fail to get connection to master (%d)\n",
751 qsd->qsd_svname, rc);
757 EXPORT_SYMBOL(qsd_prepare);
760 * Start a qsd instance. This will complete the last step of the reintegration
761 * procedure as soon as possible (provided that the master is reachable).
762 * This should be called when recovery has been completed and quota should now
763 * be enforced on every operations.
765 * \param env - the environment passed by the caller
766 * \param qsd - is the qsd instance associated with the osd device to start
768 int qsd_start(const struct lu_env *env, struct qsd_instance *qsd)
773 if (unlikely(qsd == NULL))
776 write_lock(&qsd->qsd_lock);
777 if (!qsd->qsd_prepared) {
778 CERROR("%s: can't start qsd instance since it wasn't properly "
779 "initialized\n", qsd->qsd_svname);
781 } else if (qsd->qsd_started) {
782 CERROR("%s: qsd instance already started\n", qsd->qsd_svname);
785 /* notify that the qsd_instance is now started */
786 qsd->qsd_started = true;
788 write_unlock(&qsd->qsd_lock);
793 /* Trigger the 3rd step of reintegration: If usage > granted, acquire
794 * up to usage; If usage < granted, release down to usage. */
795 for (type = USRQUOTA; type < LL_MAXQUOTAS; type++) {
796 struct qsd_qtype_info *qqi = qsd->qsd_type_array[type];
797 wake_up(&qqi->qqi_reint_thread.t_ctl_waitq);
802 EXPORT_SYMBOL(qsd_start);
804 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg));
807 * Global initialization performed at module load time
809 int qsd_glb_init(void)
813 rc = lu_kmem_init(qsd_caches);
817 qsd_key_init_generic(&qsd_thread_key, NULL);
818 lu_context_key_register(&qsd_thread_key);
819 lustre_register_quota_process_config(qsd_process_config);
825 * Companion of qsd_glb_init() called at module unload time
827 void qsd_glb_fini(void)
829 lustre_register_quota_process_config(NULL);
830 lu_kmem_fini(qsd_caches);
831 lu_context_key_degister(&qsd_thread_key);