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().
53 # define EXPORT_SYMTAB
56 #define DEBUG_SUBSYSTEM S_LQUOTA
58 #include <obd_class.h>
59 #include "qsd_internal.h"
61 struct kmem_cache *upd_kmem;
63 struct lu_kmem_descr qsd_caches[] = {
65 .ckd_cache = &upd_kmem,
66 .ckd_name = "upd_kmem",
67 .ckd_size = sizeof(struct qsd_upd_rec)
74 /* define qsd thread key */
75 LU_KEY_INIT_FINI(qsd, struct qsd_thread_info);
76 LU_CONTEXT_KEY_DEFINE(qsd, LCT_MD_THREAD | LCT_DT_THREAD | LCT_LOCAL);
77 LU_KEY_INIT_GENERIC(qsd);
79 /* some procfs helpers */
80 static int lprocfs_qsd_rd_state(char *page, char **start, off_t off,
81 int count, int *eof, void *data)
83 struct qsd_instance *qsd = (struct qsd_instance *)data;
89 memset(enabled, 0, sizeof(enabled));
90 if (qsd_type_enabled(qsd, USRQUOTA))
92 if (qsd_type_enabled(qsd, GRPQUOTA))
94 if (strlen(enabled) == 0)
95 strcat(enabled, "none");
97 rc = snprintf(page, count,
101 "quota enabled: %s\n"
102 "conn to master: %s\n",
103 qsd->qsd_svname, qsd->qsd_pool_id,
104 qsd->qsd_is_md ? "md" : "dt", enabled,
105 qsd->qsd_exp_valid ? "setup" : "not setup yet");
107 if (qsd->qsd_prepared) {
108 memset(enabled, 0, sizeof(enabled));
109 if (qsd->qsd_type_array[USRQUOTA]->qqi_acct_obj != NULL)
110 strcat(enabled, "u");
111 if (qsd->qsd_type_array[GRPQUOTA]->qqi_acct_obj != NULL)
112 strcat(enabled, "g");
113 if (strlen(enabled) == 0)
114 strcat(enabled, "none");
115 rc += snprintf(page + rc, count - rc,
117 "user uptodate: glb[%d],slv[%d],reint[%d]\n"
118 "group uptodate: glb[%d],slv[%d],reint[%d]\n",
120 qsd->qsd_type_array[USRQUOTA]->qqi_glb_uptodate,
121 qsd->qsd_type_array[USRQUOTA]->qqi_slv_uptodate,
122 qsd->qsd_type_array[USRQUOTA]->qqi_reint,
123 qsd->qsd_type_array[GRPQUOTA]->qqi_glb_uptodate,
124 qsd->qsd_type_array[GRPQUOTA]->qqi_slv_uptodate,
125 qsd->qsd_type_array[GRPQUOTA]->qqi_reint);
130 static int lprocfs_qsd_rd_enabled(char *page, char **start, off_t off,
131 int count, int *eof, void *data)
133 struct qsd_instance *qsd = (struct qsd_instance *)data;
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 (strlen(enabled) == 0)
144 strcat(enabled, "none");
146 return snprintf(page, count, "%s\n", enabled);
149 /* force reintegration procedure to be executed.
150 * Used for test/debugging purpose */
151 static int lprocfs_qsd_wr_force_reint(struct file *file, const char *buffer,
152 unsigned long count, void *data)
154 struct qsd_instance *qsd = (struct qsd_instance *)data;
157 LASSERT(qsd != NULL);
159 write_lock(&qsd->qsd_lock);
160 if (qsd->qsd_stopping) {
161 /* don't mess up with shutdown procedure, it is already
162 * complicated enough */
164 } else if (!qsd->qsd_prepared) {
167 /* mark all indexes as stale */
168 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
169 qsd->qsd_type_array[qtype]->qqi_glb_uptodate = false;
170 qsd->qsd_type_array[qtype]->qqi_slv_uptodate = false;
173 write_unlock(&qsd->qsd_lock);
178 /* kick off reintegration */
179 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
180 rc = qsd_start_reint_thread(qsd->qsd_type_array[qtype]);
184 return rc == 0 ? count : rc;
187 static int lprocfs_qsd_rd_timeout(char *page, char **start, off_t off,
188 int count, int *eof, void *data)
190 struct qsd_instance *qsd = (struct qsd_instance *)data;
191 LASSERT(qsd != NULL);
193 return snprintf(page, count, "%d\n", qsd_wait_timeout(qsd));
196 static int lprocfs_qsd_wr_timeout(struct file *file, const char *buffer,
197 unsigned long count, void *data)
199 struct qsd_instance *qsd = (struct qsd_instance *)data;
201 LASSERT(qsd != NULL);
203 rc = lprocfs_write_helper(buffer, count, &timeout);
209 qsd->qsd_timeout = timeout;
213 static struct lprocfs_vars lprocfs_quota_qsd_vars[] = {
214 { "info", lprocfs_qsd_rd_state, 0, 0},
215 { "enabled", lprocfs_qsd_rd_enabled, 0, 0},
216 { "force_reint", 0, lprocfs_qsd_wr_force_reint, 0},
217 { "timeout", lprocfs_qsd_rd_timeout, lprocfs_qsd_wr_timeout, 0},
222 * Callback function invoked by the OSP layer when the connection to the master
225 * \param data - is a pointer to the qsd_instance
227 * \retval - 0 on success, appropriate error on failure
229 static int qsd_conn_callback(void *data)
231 struct qsd_instance *qsd = (struct qsd_instance *)data;
235 /* qsd_exp should now be valid */
236 LASSERT(qsd->qsd_exp);
238 qsd->qsd_ns = class_exp2obd(qsd->qsd_exp)->obd_namespace;
240 write_lock(&qsd->qsd_lock);
241 /* notify that qsd_exp is now valid */
242 qsd->qsd_exp_valid = true;
243 write_unlock(&qsd->qsd_lock);
245 /* Now that the connection to master is setup, we can initiate the
246 * reintegration procedure for quota types which are enabled.
247 * It is worth noting that, if the qsd_instance hasn't been started
248 * already, then we can only complete the first two steps of the
249 * reintegration procedure (i.e. global lock enqueue and slave
250 * index transfer) since the space usage reconciliation (i.e.
251 * step 3) will have to wait for qsd_start() to be called */
252 for (type = USRQUOTA; type < MAXQUOTAS; type++) {
253 struct qsd_qtype_info *qqi = qsd->qsd_type_array[type];
254 cfs_waitq_signal(&qqi->qqi_reint_thread.t_ctl_waitq);
261 * Release qsd_qtype_info structure which contains data associated with a
262 * given quota type. This releases the accounting objects.
263 * It's called on OSD cleanup when the qsd instance is released.
265 * \param env - is the environment passed by the caller
266 * \param qsd - is the qsd instance managing the qsd_qtype_info structure
268 * \param qtype - is the quota type to be shutdown
270 static void qsd_qtype_fini(const struct lu_env *env, struct qsd_instance *qsd,
273 struct qsd_qtype_info *qqi;
276 if (qsd->qsd_type_array[qtype] == NULL)
278 qqi = qsd->qsd_type_array[qtype];
279 qsd->qsd_type_array[qtype] = NULL;
281 /* all deferred work lists should be empty */
282 LASSERT(cfs_list_empty(&qqi->qqi_deferred_glb));
283 LASSERT(cfs_list_empty(&qqi->qqi_deferred_slv));
285 /* shutdown lquota site */
286 if (qqi->qqi_site != NULL && !IS_ERR(qqi->qqi_site)) {
287 lquota_site_free(env, qqi->qqi_site);
288 qqi->qqi_site = NULL;
291 /* by now, all qqi users should have gone away */
292 LASSERT(cfs_atomic_read(&qqi->qqi_ref) == 1);
293 lu_ref_fini(&qqi->qqi_reference);
295 /* release accounting object */
296 if (qqi->qqi_acct_obj != NULL && !IS_ERR(qqi->qqi_acct_obj)) {
297 lu_object_put(env, &qqi->qqi_acct_obj->do_lu);
298 qqi->qqi_acct_obj = NULL;
301 /* release slv index */
302 if (qqi->qqi_slv_obj != NULL && !IS_ERR(qqi->qqi_slv_obj)) {
303 lu_object_put(env, &qqi->qqi_slv_obj->do_lu);
304 qqi->qqi_slv_obj = NULL;
305 qqi->qqi_slv_ver = 0;
308 /* release global index */
309 if (qqi->qqi_glb_obj != NULL && !IS_ERR(qqi->qqi_glb_obj)) {
310 lu_object_put(env, &qqi->qqi_glb_obj->do_lu);
311 qqi->qqi_glb_obj = NULL;
312 qqi->qqi_glb_ver = 0;
320 * Allocate and initialize a qsd_qtype_info structure for quota type \qtype.
321 * This opens the accounting object and initializes the proc file.
322 * It's called on OSD start when the qsd_prepare() is invoked on the qsd
325 * \param env - the environment passed by the caller
326 * \param qsd - is the qsd instance which will be in charge of the new
327 * qsd_qtype_info instance.
328 * \param qtype - is quota type to set up
330 * \retval - 0 on success and qsd->qsd_type_array[qtype] is allocated,
331 * appropriate error on failure
333 static int qsd_qtype_init(const struct lu_env *env, struct qsd_instance *qsd,
336 struct qsd_qtype_info *qqi;
338 struct obd_uuid uuid;
341 LASSERT(qsd->qsd_type_array[qtype] == NULL);
343 /* allocate structure for this quota type */
347 qsd->qsd_type_array[qtype] = qqi;
348 cfs_atomic_set(&qqi->qqi_ref, 1); /* referenced from qsd */
350 /* set backpointer and other parameters */
352 qqi->qqi_qtype = qtype;
353 lu_ref_init(&qqi->qqi_reference);
354 lquota_generate_fid(&qqi->qqi_fid, qsd->qsd_pool_id, QSD_RES_TYPE(qsd),
356 qqi->qqi_glb_uptodate = false;
357 qqi->qqi_slv_uptodate = false;
358 qqi->qqi_reint = false;
359 cfs_waitq_init(&qqi->qqi_reint_thread.t_ctl_waitq);
360 thread_set_flags(&qqi->qqi_reint_thread, SVC_STOPPED);
361 CFS_INIT_LIST_HEAD(&qqi->qqi_deferred_glb);
362 CFS_INIT_LIST_HEAD(&qqi->qqi_deferred_slv);
364 /* open accounting object */
365 LASSERT(qqi->qqi_acct_obj == NULL);
366 qqi->qqi_acct_obj = acct_obj_lookup(env, qsd->qsd_dev, qtype);
367 if (IS_ERR(qqi->qqi_acct_obj)) {
368 CDEBUG(D_QUOTA, "%s: no %s space accounting support rc:%ld\n",
369 qsd->qsd_svname, QTYPE_NAME(qtype),
370 PTR_ERR(qqi->qqi_acct_obj));
371 qqi->qqi_acct_obj = NULL;
372 qsd->qsd_acct_failed = true;
375 /* open global index copy */
376 LASSERT(qqi->qqi_glb_obj == NULL);
377 qqi->qqi_glb_obj = lquota_disk_glb_find_create(env, qsd->qsd_dev,
379 &qqi->qqi_fid, true);
380 if (IS_ERR(qqi->qqi_glb_obj)) {
381 CERROR("%s: can't open global index copy "DFID" %ld\n",
382 qsd->qsd_svname, PFID(&qqi->qqi_fid),
383 PTR_ERR(qqi->qqi_glb_obj));
384 GOTO(out, rc = PTR_ERR(qqi->qqi_glb_obj));
386 qqi->qqi_glb_ver = dt_version_get(env, qqi->qqi_glb_obj);
388 /* open slave index copy */
389 LASSERT(qqi->qqi_slv_obj == NULL);
390 obd_str2uuid(&uuid, qsd->qsd_svname);
391 qqi->qqi_slv_obj = lquota_disk_slv_find_create(env, qsd->qsd_dev,
393 &qqi->qqi_fid, &uuid,
395 if (IS_ERR(qqi->qqi_slv_obj)) {
396 CERROR("%s: can't open slave index copy "DFID" %ld\n",
397 qsd->qsd_svname, PFID(&qqi->qqi_fid),
398 PTR_ERR(qqi->qqi_slv_obj));
399 GOTO(out, rc = PTR_ERR(qqi->qqi_slv_obj));
401 qqi->qqi_slv_ver = dt_version_get(env, qqi->qqi_slv_obj);
404 qqi->qqi_site = lquota_site_alloc(env, qqi, false, qtype, &qsd_lqe_ops);
405 if (IS_ERR(qqi->qqi_site)) {
406 CERROR("%s: can't allocate site "DFID" %ld\n", qsd->qsd_svname,
407 PFID(&qqi->qqi_fid), PTR_ERR(qqi->qqi_site));
408 GOTO(out, rc = PTR_ERR(qqi->qqi_site));
411 /* register proc entry for accounting & global index copy objects */
412 rc = lprocfs_seq_create(qsd->qsd_proc,
413 qtype == USRQUOTA ? "acct_user" : "acct_group",
414 0444, &lprocfs_quota_seq_fops,
417 CERROR("%s: can't add procfs entry for accounting file %d\n",
418 qsd->qsd_svname, rc);
422 rc = lprocfs_seq_create(qsd->qsd_proc,
423 qtype == USRQUOTA ? "limit_user" : "limit_group",
424 0444, &lprocfs_quota_seq_fops,
427 CERROR("%s: can't add procfs entry for global index copy %d\n",
428 qsd->qsd_svname, rc);
434 qsd_qtype_fini(env, qsd, qtype);
439 * Release a qsd_instance. Companion of qsd_init(). This releases all data
440 * structures associated with the quota slave (on-disk objects, lquota entry
442 * This function should be called when the OSD is shutting down.
444 * \param env - is the environment passed by the caller
445 * \param qsd - is the qsd instance to shutdown
447 void qsd_fini(const struct lu_env *env, struct qsd_instance *qsd)
452 if (unlikely(qsd == NULL))
455 CDEBUG(D_QUOTA, "%s: initiating QSD shutdown\n", qsd->qsd_svname);
456 write_lock(&qsd->qsd_lock);
457 qsd->qsd_stopping = true;
458 write_unlock(&qsd->qsd_lock);
460 /* remove qsd proc entry */
461 if (qsd->qsd_proc != NULL) {
462 lprocfs_remove(&qsd->qsd_proc);
463 qsd->qsd_proc = NULL;
466 /* stop the writeback thread */
467 qsd_stop_upd_thread(qsd);
469 /* shutdown the reintegration threads */
470 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
471 if (qsd->qsd_type_array[qtype] == NULL)
473 qsd_stop_reint_thread(qsd->qsd_type_array[qtype]);
476 if (qsd->qsd_ns != NULL) {
480 /* free per-quota type data */
481 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++)
482 qsd_qtype_fini(env, qsd, qtype);
484 /* deregister connection to the quota master */
485 qsd->qsd_exp_valid = false;
486 lustre_deregister_lwp_item(&qsd->qsd_exp);
488 /* release per-filesystem information */
489 if (qsd->qsd_fsinfo != NULL) {
490 down(&qsd->qsd_fsinfo->qfs_sem);
491 /* remove from the list of fsinfo */
492 cfs_list_del_init(&qsd->qsd_link);
493 up(&qsd->qsd_fsinfo->qfs_sem);
494 qsd_put_fsinfo(qsd->qsd_fsinfo);
495 qsd->qsd_fsinfo = NULL;
498 /* release quota root directory */
499 if (qsd->qsd_root != NULL) {
500 lu_object_put(env, &qsd->qsd_root->do_lu);
501 qsd->qsd_root = NULL;
504 /* release reference on dt_device */
505 if (qsd->qsd_dev != NULL) {
506 lu_ref_del(&qsd->qsd_dev->dd_lu_dev.ld_reference, "qsd", qsd);
507 lu_device_put(&qsd->qsd_dev->dd_lu_dev);
511 CDEBUG(D_QUOTA, "%s: QSD shutdown completed\n", qsd->qsd_svname);
515 EXPORT_SYMBOL(qsd_fini);
518 * Create a new qsd_instance to be associated with backend osd device
519 * identified by \dev.
521 * \param env - the environment passed by the caller
522 * \param svname - is the service name of the OSD device creating this instance
523 * \param dev - is the dt_device where to store quota index files
524 * \param osd_proc - is the procfs parent directory where to create procfs file
525 * related to this new qsd instance
527 * \retval - pointer to new qsd_instance associated with dev \dev on success,
528 * appropriate error on failure
530 struct qsd_instance *qsd_init(const struct lu_env *env, char *svname,
531 struct dt_device *dev,
532 cfs_proc_dir_entry_t *osd_proc)
534 struct qsd_thread_info *qti = qsd_info(env);
535 struct qsd_instance *qsd;
539 /* only configure qsd for MDT & OST */
540 type = server_name2index(svname, &idx, NULL);
541 if (type != LDD_F_SV_TYPE_MDT && type != LDD_F_SV_TYPE_OST)
544 /* allocate qsd instance */
547 RETURN(ERR_PTR(-ENOMEM));
549 /* generic initializations */
550 rwlock_init(&qsd->qsd_lock);
551 CFS_INIT_LIST_HEAD(&qsd->qsd_link);
552 thread_set_flags(&qsd->qsd_upd_thread, SVC_STOPPED);
553 cfs_waitq_init(&qsd->qsd_upd_thread.t_ctl_waitq);
554 CFS_INIT_LIST_HEAD(&qsd->qsd_upd_list);
555 spin_lock_init(&qsd->qsd_adjust_lock);
556 CFS_INIT_LIST_HEAD(&qsd->qsd_adjust_list);
557 qsd->qsd_prepared = false;
558 qsd->qsd_started = false;
560 /* copy service name */
561 if (strlcpy(qsd->qsd_svname, svname, sizeof(qsd->qsd_svname))
562 >= sizeof(qsd->qsd_svname))
563 GOTO(out, rc = -E2BIG);
565 /* grab reference on osd device */
566 lu_device_get(&dev->dd_lu_dev);
567 lu_ref_add(&dev->dd_lu_dev.ld_reference, "qsd", qsd);
570 /* we only support pool ID 0 (default data or metadata pool) for the
571 * time being. A different pool ID could be assigned to this target via
572 * the configuration log in the future */
573 qsd->qsd_pool_id = 0;
575 /* get fsname from svname */
576 rc = server_name2fsname(svname, qti->qti_buf, NULL);
578 CERROR("%s: fail to extract filesystem name\n", svname);
582 /* look up quota setting for the filesystem the target belongs to */
583 qsd->qsd_fsinfo = qsd_get_fsinfo(qti->qti_buf, 1);
584 if (qsd->qsd_fsinfo == NULL) {
585 CERROR("%s: failed to locate filesystem information\n", svname);
586 GOTO(out, rc = -EINVAL);
589 /* add in the list of lquota_fsinfo */
590 down(&qsd->qsd_fsinfo->qfs_sem);
591 list_add_tail(&qsd->qsd_link, &qsd->qsd_fsinfo->qfs_qsd_list);
592 up(&qsd->qsd_fsinfo->qfs_sem);
594 /* register procfs directory */
595 qsd->qsd_proc = lprocfs_register(QSD_DIR, osd_proc,
596 lprocfs_quota_qsd_vars, qsd);
597 if (IS_ERR(qsd->qsd_proc)) {
598 rc = PTR_ERR(qsd->qsd_proc);
599 qsd->qsd_proc = NULL;
600 CERROR("%s: fail to create quota slave proc entry (%d)\n",
612 EXPORT_SYMBOL(qsd_init);
615 * Initialize on-disk structures in order to manage quota enforcement for
616 * the target associated with the qsd instance \qsd and starts the reintegration
617 * procedure for each quota type as soon as possible.
618 * The last step of the reintegration will be completed once qsd_start() is
619 * called, at which points the space reconciliation with the master will be
621 * This function must be called when the server stack is fully configured,
622 * typically when ->ldo_prepare is called across the stack.
624 * \param env - the environment passed by the caller
625 * \param qsd - is qsd_instance to prepare
627 * \retval - 0 on success, appropriate error on failure
629 int qsd_prepare(const struct lu_env *env, struct qsd_instance *qsd)
631 struct qsd_thread_info *qti = qsd_info(env);
635 if (unlikely(qsd == NULL))
638 read_lock(&qsd->qsd_lock);
639 if (qsd->qsd_prepared) {
640 CERROR("%s: qsd instance already prepared\n", qsd->qsd_svname);
643 read_unlock(&qsd->qsd_lock);
647 /* Record whether this qsd instance is managing quota enforcement for a
648 * MDT (i.e. inode quota) or OST (block quota) */
649 if (lu_device_is_md(qsd->qsd_dev->dd_lu_dev.ld_site->ls_top_dev)) {
650 qsd->qsd_is_md = true;
651 qsd->qsd_sync_threshold = LQUOTA_LEAST_QUNIT(LQUOTA_RES_MD);
653 qsd->qsd_sync_threshold = LQUOTA_LEAST_QUNIT(LQUOTA_RES_DT);
656 /* look-up on-disk directory for the quota slave */
657 qsd->qsd_root = lquota_disk_dir_find_create(env, qsd->qsd_dev, NULL,
659 if (IS_ERR(qsd->qsd_root)) {
660 rc = PTR_ERR(qsd->qsd_root);
661 qsd->qsd_root = NULL;
662 CERROR("%s: failed to create quota slave root dir (%d)\n",
663 qsd->qsd_svname, rc);
667 /* initialize per-quota type data */
668 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
669 rc = qsd_qtype_init(env, qsd, qtype);
674 /* pools successfully setup, mark the qsd as prepared */
675 write_lock(&qsd->qsd_lock);
676 qsd->qsd_prepared = true;
677 write_unlock(&qsd->qsd_lock);
679 /* start reintegration thread for each type, if required */
680 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
681 struct qsd_qtype_info *qqi = qsd->qsd_type_array[qtype];
683 if (qsd_type_enabled(qsd, qtype) && qsd->qsd_acct_failed) {
684 LCONSOLE_ERROR("%s: can't enable quota enforcement "
685 "since space accounting isn't functional"
686 ". Please run tunefs.lustre --quota on "
687 "an unmounted filesystem if not done "
688 "already\n", qsd->qsd_svname);
692 rc = qsd_start_reint_thread(qqi);
694 CERROR("%s: failed to start reint thread for type %s "
695 "(%d)\n", qsd->qsd_svname, QTYPE_NAME(qtype),
701 /* start writeback thread */
702 rc = qsd_start_upd_thread(qsd);
704 CERROR("%s: failed to start writeback thread (%d)\n",
705 qsd->qsd_svname, rc);
709 /* generate osp name */
710 rc = tgt_name2lwpname((char *)qsd->qsd_svname, qti->qti_buf);
712 CERROR("%s: failed to generate ospname (%d)\n",
713 qsd->qsd_svname, rc);
717 /* the connection callback will start the reintegration
718 * procedure if quota is enabled */
719 rc = lustre_register_lwp_item(qti->qti_buf, &qsd->qsd_exp,
720 qsd_conn_callback, (void *)qsd);
722 CERROR("%s: fail to get connection to master (%d)\n",
723 qsd->qsd_svname, rc);
729 EXPORT_SYMBOL(qsd_prepare);
732 * Start a qsd instance. This will complete the last step of the reintegration
733 * procedure as soon as possible (provided that the master is reachable).
734 * This should be called when recovery has been completed and quota should now
735 * be enforced on every operations.
737 * \param env - the environment passed by the caller
738 * \param qsd - is the qsd instance associated with the osd device to start
740 int qsd_start(const struct lu_env *env, struct qsd_instance *qsd)
745 if (unlikely(qsd == NULL))
748 write_lock(&qsd->qsd_lock);
749 if (!qsd->qsd_prepared) {
750 CERROR("%s: can't start qsd instance since it wasn't properly "
751 "initialized\n", qsd->qsd_svname);
753 } else if (qsd->qsd_started) {
754 CERROR("%s: qsd instance already started\n", qsd->qsd_svname);
757 /* notify that the qsd_instance is now started */
758 qsd->qsd_started = true;
760 write_unlock(&qsd->qsd_lock);
765 /* Trigger the 3rd step of reintegration: If usage > granted, acquire
766 * up to usage; If usage < granted, release down to usage. */
767 for (type = USRQUOTA; type < MAXQUOTAS; type++) {
768 struct qsd_qtype_info *qqi = qsd->qsd_type_array[type];
769 cfs_waitq_signal(&qqi->qqi_reint_thread.t_ctl_waitq);
774 EXPORT_SYMBOL(qsd_start);
776 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg));
779 * Global initialization performed at module load time
781 int qsd_glb_init(void)
785 rc = lu_kmem_init(qsd_caches);
789 qsd_key_init_generic(&qsd_thread_key, NULL);
790 lu_context_key_register(&qsd_thread_key);
791 lustre_register_quota_process_config(qsd_process_config);
797 * Companion of qsd_glb_init() called at module unload time
799 void qsd_glb_fini(void)
801 lustre_register_quota_process_config(NULL);
802 lu_kmem_fini(qsd_caches);
803 lu_context_key_degister(&qsd_thread_key);